Open History to see the last commit
1/**
2 * Transient signal store for "auto-submit on next mount".
3 *
4 * The splash composer (NoActiveThreadState) sets this flag for a draft when
5 * the user submits, so the freshly-routed ChatView can fire onSend itself
6 * instead of leaving the prompt sitting in the composer for the user to
7 * press Enter again.
8 *
9 * Pure in-memory — never persisted. Reload should not trigger a phantom
10 * submit, and the signal is one-shot (consumed exactly once).
11 */
12import { create } from "zustand";
13
14interface PendingAutoSubmitStoreState {
15 pendingDraftIds: ReadonlySet<string>;
16 /** Mark a draft for auto-submit on the next ChatView mount. */
17 request: (draftId: string) => void;
18 /** Consume + clear the flag. Returns true iff one was pending. */
19 consume: (draftId: string) => boolean;
20}
21
22const EMPTY_SET: ReadonlySet<string> = new Set();
23
24export const usePendingAutoSubmitStore = create<PendingAutoSubmitStoreState>((set, get) => ({
25 pendingDraftIds: EMPTY_SET,
26
27 request: (draftId) => {
28 set((state) => {
29 const next = new Set(state.pendingDraftIds);
30 next.add(draftId);
31 return { pendingDraftIds: next };
32 });
33 },
34
35 consume: (draftId) => {
36 const current = get().pendingDraftIds;
37 if (!current.has(draftId)) return false;
38 const next = new Set(current);
39 next.delete(draftId);
40 set({ pendingDraftIds: next });
41 return true;
42 },
43}));