import type { Decision } from "../rules.js"; export type DecisionRecord = { decision: Decision; createdAt: number; needsRestore?: boolean; }; export const MAX_SESSION_DECISIONS = 2000; export const DECISION_TTL_MS = 5 * 60 * 1000; export const sessionDecision = new Map(); export const sessionAllowed = new Map(); export const sessionInjected = new Set(); export const sessionChannelId = new Map(); export const sessionAccountId = new Map(); export const sessionTurnHandled = new Set(); export const forceNoReplySessions = new Set(); export const discussionChannelSessions = new Map>(); export function recordDiscussionSession(channelId: string, sessionKey: string): void { if (!channelId || !sessionKey) return; const current = discussionChannelSessions.get(channelId) || new Set(); current.add(sessionKey); discussionChannelSessions.set(channelId, current); } export function getDiscussionSessionKeys(channelId: string): string[] { return [...(discussionChannelSessions.get(channelId) || new Set())]; } export function pruneDecisionMap(now = Date.now()): void { for (const [k, v] of sessionDecision.entries()) { if (now - v.createdAt > DECISION_TTL_MS) sessionDecision.delete(k); } if (sessionDecision.size <= MAX_SESSION_DECISIONS) return; const keys = sessionDecision.keys(); while (sessionDecision.size > MAX_SESSION_DECISIONS) { const k = keys.next(); if (k.done) break; sessionDecision.delete(k.value); } }