refactor(session): centralize thread reset detection

Co-authored-by: Austin Mudd <austinm911@gmail.com>
This commit is contained in:
Peter Steinberger
2026-01-18 06:54:55 +00:00
parent b5ddf08763
commit f86b24c511
6 changed files with 201 additions and 41 deletions

View File

@@ -9,9 +9,9 @@ import {
DEFAULT_RESET_TRIGGERS,
deriveSessionMetaPatch,
evaluateSessionFreshness,
isThreadSessionKey,
type GroupKeyResolution,
loadSessionStore,
resolveThreadFlag,
resolveSessionResetPolicy,
resolveSessionResetType,
resolveGroupSessionKey,
@@ -173,12 +173,13 @@ export async function initSessionState(params: {
const entry = sessionStore[sessionKey];
const previousSessionEntry = resetTriggered && entry ? { ...entry } : undefined;
const now = Date.now();
const isThread =
ctx.MessageThreadId != null ||
Boolean(ctx.ThreadLabel?.trim()) ||
Boolean(ctx.ThreadStarterBody?.trim()) ||
Boolean(ctx.ParentSessionKey?.trim()) ||
isThreadSessionKey(sessionKey);
const isThread = resolveThreadFlag({
sessionKey,
messageThreadId: ctx.MessageThreadId,
threadLabel: ctx.ThreadLabel,
threadStarterBody: ctx.ThreadStarterBody,
parentSessionKey: ctx.ParentSessionKey,
});
const resetType = resolveSessionResetType({ sessionKey, isGroup, isThread });
const resetPolicy = resolveSessionResetPolicy({ sessionCfg, resetType });
const freshEntry = entry