2026-07-21 20:52:20 +03:00
|
|
|
import { getRuntimeKey } from '@/lib/runtime-switch';
|
|
|
|
|
import { clearChatDraft, createChatDraftIdentity } from '@/lib/chatDraftPersistence';
|
2026-09-04 14:08:08 +03:00
|
|
|
import { createMessageQueueTarget, isServerOwnedMessageQueue, useMessageQueueStore } from '@/stores/messageQueueStore';
|
2026-09-05 10:19:03 -06:00
|
|
|
import { createInputHistoryIdentity, useInputHistoryStore } from '@/stores/useInputHistoryStore';
|
2026-07-21 20:52:20 +03:00
|
|
|
import { useSessionFoldersStore } from '@/stores/useSessionFoldersStore';
|
|
|
|
|
import { useTodosPersistStore } from '@/stores/useTodosPersistStore';
|
|
|
|
|
import { useInlineCommentDraftStore } from '@/stores/useInlineCommentDraftStore';
|
|
|
|
|
import { useSessionPinnedStore } from '@/stores/useSessionPinnedStore';
|
|
|
|
|
|
|
|
|
|
export const cleanupPersistedSessionState = (identity: {
|
|
|
|
|
runtimeKey: string;
|
|
|
|
|
directory: string;
|
|
|
|
|
sessionId: string;
|
|
|
|
|
}): void => {
|
|
|
|
|
if (identity.runtimeKey !== getRuntimeKey() || !identity.directory || identity.directory === 'global' || !identity.sessionId) return;
|
|
|
|
|
|
|
|
|
|
const queueTarget = createMessageQueueTarget(identity.sessionId, identity.directory, identity.runtimeKey);
|
2026-09-04 14:08:08 +03:00
|
|
|
if (queueTarget) {
|
|
|
|
|
// A server-owned queue drops the deleted session itself; only the local
|
|
|
|
|
// projection needs to go. VS Code owns its queue and clears it here.
|
|
|
|
|
if (isServerOwnedMessageQueue()) useMessageQueueStore.getState().forgetQueue(queueTarget);
|
|
|
|
|
else useMessageQueueStore.getState().clearQueue(queueTarget);
|
|
|
|
|
}
|
2026-07-21 20:52:20 +03:00
|
|
|
useTodosPersistStore.getState().clearSessionTodos(identity.runtimeKey, identity.directory, identity.sessionId);
|
|
|
|
|
useSessionFoldersStore.getState().removeSessionEverywhere(identity.runtimeKey, identity.sessionId);
|
|
|
|
|
useInlineCommentDraftStore.getState().clearSessionDrafts(identity.runtimeKey, identity.directory, identity.sessionId);
|
|
|
|
|
useSessionPinnedStore.getState().clearPinnedSession(identity.runtimeKey, identity.directory, identity.sessionId);
|
2026-09-05 10:19:03 -06:00
|
|
|
const inputHistoryIdentity = createInputHistoryIdentity(identity.runtimeKey, identity.directory, identity.sessionId);
|
|
|
|
|
if (inputHistoryIdentity) useInputHistoryStore.getState().clearSession(inputHistoryIdentity);
|
2026-07-21 20:52:20 +03:00
|
|
|
const chatDraftIdentity = createChatDraftIdentity(identity.runtimeKey, identity.directory, identity.sessionId);
|
|
|
|
|
if (chatDraftIdentity) clearChatDraft(chatDraftIdentity, true);
|
|
|
|
|
};
|