Files
openchamber/packages/ui/src/sync/session-deletion-cleanup.ts
T
Matt VisnovskyandBohdan Triapitsyn 1d6b15bc04 feat(chat): persist more composer input history with global or session scope; recallable with up/down arrow keys (#3035)
* feat(chat): persist input history

* feat(settings): configure input history scope

* fix(web): keep input history validation packaged

* fix(chat): preserve input history across tabs

* fix(settings): restore prompt history limit

* fix(settings): keep history deletion warning visible

* fix(i18n): restore Turkish Git empty state translations

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
2026-09-05 19:19:03 +03:00

33 lines
2.2 KiB
TypeScript

import { getRuntimeKey } from '@/lib/runtime-switch';
import { clearChatDraft, createChatDraftIdentity } from '@/lib/chatDraftPersistence';
import { createMessageQueueTarget, isServerOwnedMessageQueue, useMessageQueueStore } from '@/stores/messageQueueStore';
import { createInputHistoryIdentity, useInputHistoryStore } from '@/stores/useInputHistoryStore';
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);
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);
}
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);
const inputHistoryIdentity = createInputHistoryIdentity(identity.runtimeKey, identity.directory, identity.sessionId);
if (inputHistoryIdentity) useInputHistoryStore.getState().clearSession(inputHistoryIdentity);
const chatDraftIdentity = createChatDraftIdentity(identity.runtimeKey, identity.directory, identity.sessionId);
if (chatDraftIdentity) clearChatDraft(chatDraftIdentity, true);
};