refactor(chat): modify newSession logic to avoid resetting old sessio… (#185)

This commit is contained in:
Haze
2026-02-26 15:23:59 +08:00
committed by GitHub
Unverified
parent 7b16b6af14
commit 45932a95c3

View File

@@ -1010,19 +1010,10 @@ export const useChatStore = create<ChatState>((set, get) => ({
// ── New session ──
newSession: () => {
const { currentSessionKey } = get();
// Notify the gateway that the old session is ending so the session-memory
// hook can persist conversation memories to memory/YYYY-MM-DD-<slug>.md.
if (currentSessionKey) {
void window.electron.ipcRenderer.invoke(
'gateway:rpc',
'sessions.reset',
{ key: currentSessionKey, reason: 'new' },
).catch(() => { /* fire-and-forget */ });
}
// Generate a new unique session key and switch to it
// Generate a new unique session key and switch to it.
// NOTE: We intentionally do NOT call sessions.reset on the old session.
// sessions.reset archives (renames) the session JSONL file, making old
// conversation history inaccessible when the user switches back to it.
const prefix = getCanonicalPrefixFromSessions(get().sessions) ?? DEFAULT_CANONICAL_PREFIX;
const newKey = `${prefix}:session-${Date.now()}`;
const newSessionEntry: ChatSession = { key: newKey, displayName: newKey };