From a4bc9990dbd88a1103dc2188a347c0a463e76ecb Mon Sep 17 00:00:00 2001 From: zhi Date: Sun, 1 Mar 2026 09:16:55 +0000 Subject: [PATCH] fix: add sessionAccountId mapping and use in before_message_write - Add sessionAccountId Map to track sessionKey -> accountId - Save accountId in before_model_resolve when resolving accountId - Use sessionChannelId/sessionAccountId fallback in before_message_write --- plugin/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugin/index.ts b/plugin/index.ts index 3fcbc8b..f862ff4 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -27,6 +27,7 @@ const sessionDecision = new Map(); const sessionAllowed = new Map(); // Track if session was allowed to speak (true) or forced no-reply (false) const sessionInjected = new Set(); // Track which sessions have already injected the end marker const sessionChannelId = new Map(); // Track sessionKey -> channelId mapping +const sessionAccountId = new Map(); // Track sessionKey -> accountId mapping const MAX_SESSION_DECISIONS = 2000; const DECISION_TTL_MS = 5 * 60 * 1000; function buildEndMarkerInstruction(endSymbols: string[], isGroupChat: boolean): string { @@ -637,10 +638,13 @@ export default { } // Allowed to speak - record this session as allowed sessionAllowed.set(key, true); - // Also save channelId for this session + // Also save channelId and accountId for this session if (derived.channelId) { sessionChannelId.set(key, derived.channelId); } + if (accountId) { + sessionAccountId.set(key, accountId); + } } } @@ -836,6 +840,14 @@ export default { accountId = String(deliveryContext.accountId); } + // Fallback: get from session mapping + if (!channelId && key) { + channelId = sessionChannelId.get(key); + } + if (!accountId && key) { + accountId = sessionAccountId.get(key); + } + // Fallback: get content from event.message.content if (!content && (event as Record).message) { const msg = (event as Record).message as Record;