refactor: Directly add new chat session to state upon creation (#62)

This commit is contained in:
Felix
2026-02-12 12:09:14 +08:00
committed by GitHub
Unverified
parent 8ab1b3af36
commit a8e26362b9

View File

@@ -423,8 +423,10 @@ export const useChatStore = create<ChatState>((set, get) => ({
// Generate a new unique session key and switch to it
const prefix = getCanonicalPrefixFromSessions(get().sessions) ?? DEFAULT_CANONICAL_PREFIX;
const newKey = `${prefix}:session-${Date.now()}`;
set({
const newSessionEntry: ChatSession = { key: newKey, displayName: newKey };
set((s) => ({
currentSessionKey: newKey,
sessions: [...s.sessions, newSessionEntry],
messages: [],
streamingText: '',
streamingMessage: null,
@@ -433,9 +435,7 @@ export const useChatStore = create<ChatState>((set, get) => ({
error: null,
pendingFinal: false,
lastUserMessageAt: null,
});
// Reload sessions list to include the new one after first message
get().loadSessions();
}));
},
// ── Load chat history ──