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
This commit is contained in:
@@ -27,6 +27,7 @@ const sessionDecision = new Map<string, DecisionRecord>();
|
|||||||
const sessionAllowed = new Map<string, boolean>(); // Track if session was allowed to speak (true) or forced no-reply (false)
|
const sessionAllowed = new Map<string, boolean>(); // Track if session was allowed to speak (true) or forced no-reply (false)
|
||||||
const sessionInjected = new Set<string>(); // Track which sessions have already injected the end marker
|
const sessionInjected = new Set<string>(); // Track which sessions have already injected the end marker
|
||||||
const sessionChannelId = new Map<string, string>(); // Track sessionKey -> channelId mapping
|
const sessionChannelId = new Map<string, string>(); // Track sessionKey -> channelId mapping
|
||||||
|
const sessionAccountId = new Map<string, string>(); // Track sessionKey -> accountId mapping
|
||||||
const MAX_SESSION_DECISIONS = 2000;
|
const MAX_SESSION_DECISIONS = 2000;
|
||||||
const DECISION_TTL_MS = 5 * 60 * 1000;
|
const DECISION_TTL_MS = 5 * 60 * 1000;
|
||||||
function buildEndMarkerInstruction(endSymbols: string[], isGroupChat: boolean): string {
|
function buildEndMarkerInstruction(endSymbols: string[], isGroupChat: boolean): string {
|
||||||
@@ -637,10 +638,13 @@ export default {
|
|||||||
}
|
}
|
||||||
// Allowed to speak - record this session as allowed
|
// Allowed to speak - record this session as allowed
|
||||||
sessionAllowed.set(key, true);
|
sessionAllowed.set(key, true);
|
||||||
// Also save channelId for this session
|
// Also save channelId and accountId for this session
|
||||||
if (derived.channelId) {
|
if (derived.channelId) {
|
||||||
sessionChannelId.set(key, derived.channelId);
|
sessionChannelId.set(key, derived.channelId);
|
||||||
}
|
}
|
||||||
|
if (accountId) {
|
||||||
|
sessionAccountId.set(key, accountId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,6 +840,14 @@ export default {
|
|||||||
accountId = String(deliveryContext.accountId);
|
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
|
// Fallback: get content from event.message.content
|
||||||
if (!content && (event as Record<string, unknown>).message) {
|
if (!content && (event as Record<string, unknown>).message) {
|
||||||
const msg = (event as Record<string, unknown>).message as Record<string, unknown>;
|
const msg = (event as Record<string, unknown>).message as Record<string, unknown>;
|
||||||
|
|||||||
Reference in New Issue
Block a user