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