Skip to content

Commit 3919270

Browse files
t3dotggclaude
andcommitted
fix(web): stashed prompts now survive switching providers
The prompt stash was bucketed per provider instance and re-applied the stashed model selection on restore, so stashing, switching providers, and restoring silently hid the stash and dragged the old model back. The stash is now one global queue carrying only text + images; restore leaves the current provider/model selection untouched. Legacy v1 payloads are purged at startup. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent b64ae88 commit 3919270

5 files changed

Lines changed: 114 additions & 267 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ import {
5757
useEffectiveComposerModelState,
5858
} from "../../composerDraftStore";
5959
import {
60-
EMPTY_PROMPT_STASH_QUEUE,
61-
MAX_STASH_ENTRIES_PER_QUEUE,
60+
MAX_STASH_ENTRIES,
6261
partitionStashAttachments,
63-
promptStashScopeKey,
6462
usePromptStashStore,
6563
type PromptStashEntry,
6664
} from "../../promptStashStore";
@@ -733,7 +731,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
733731
const clearComposerDraftPromptAndImages = useComposerDraftStore(
734732
(store) => store.clearComposerPromptAndImages,
735733
);
736-
const setComposerDraftModelSelection = useComposerDraftStore((store) => store.setModelSelection);
737734
const syncComposerDraftPersistedAttachments = useComposerDraftStore(
738735
(store) => store.syncPersistedAttachments,
739736
);
@@ -1888,23 +1885,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
18881885
// ------------------------------------------------------------------
18891886
// Prompt stash (⌘S)
18901887
// ------------------------------------------------------------------
1891-
const stashScopeInstanceId = noProviderAvailable ? null : selectedInstanceId;
1892-
const stashScope = promptStashScopeKey(stashScopeInstanceId);
1893-
const stashQueue = usePromptStashStore(
1894-
(state) => state.queuesByScopeKey[stashScope] ?? EMPTY_PROMPT_STASH_QUEUE,
1895-
);
1896-
const stashOtherScopesCount = usePromptStashStore((state) =>
1897-
Object.entries(state.queuesByScopeKey).reduce(
1898-
(total, [key, queue]) => (key === stashScope ? total : total + queue.length),
1899-
0,
1900-
),
1901-
);
1888+
// One global queue. Stashed prompts carry only text + images so they can be
1889+
// restored into any thread or provider — stash, switch, restore is the
1890+
// whole point.
1891+
const stashQueue = usePromptStashStore((state) => state.entries);
19021892
const stashEntryToQueue = usePromptStashStore((state) => state.stashEntry);
19031893
const takeStashEntry = usePromptStashStore((state) => state.takeEntry);
19041894
const finalizeStashEntryImages = usePromptStashStore((state) => state.finalizeEntryImages);
1905-
const stashProviderLabel = noProviderAvailable
1906-
? "No provider"
1907-
: getProviderDisplayName(providerStatuses, selectedProvider);
19081895

19091896
useEffect(() => {
19101897
return () => {
@@ -1930,10 +1917,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
19301917
const restoreStashEntry = useCallback(
19311918
(entry: PromptStashEntry) => {
19321919
// Remove first so a double activation (click + Enter) can't restore twice.
1933-
const { entry: taken, durable } = takeStashEntry(
1934-
promptStashScopeKey(entry.providerInstanceId),
1935-
entry.id,
1936-
);
1920+
const { entry: taken, durable } = takeStashEntry(entry.id);
19371921
if (!taken) return;
19381922
if (!durable) {
19391923
toastManager.add({
@@ -1996,21 +1980,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
19961980
}
19971981
}
19981982

1999-
const restorableSelection =
2000-
entry.modelSelection &&
2001-
providerInstanceEntries.some(
2002-
(candidate) =>
2003-
candidate.instanceId === entry.modelSelection?.instanceId &&
2004-
candidate.enabled &&
2005-
candidate.isAvailable,
2006-
)
2007-
? entry.modelSelection
2008-
: null;
2009-
if (restorableSelection) {
2010-
setComposerDraftModelSelection(composerDraftTarget, restorableSelection, {
2011-
replaceOptions: true,
2012-
});
2013-
}
1983+
// Deliberately no model/provider restore: the stash exists to carry a
1984+
// prompt across threads and providers, so whatever the composer has
1985+
// selected right now stays selected.
20141986

20151987
// Each cause gets its own sentence so "too large" is never blamed for a
20161988
// file that actually failed to decode, or for one the composer simply
@@ -2052,16 +2024,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
20522024
composerDraftTarget,
20532025
composerImagesRef,
20542026
promptRef,
2055-
providerInstanceEntries,
2056-
setComposerDraftModelSelection,
20572027
setComposerDraftPrompt,
20582028
takeStashEntry,
20592029
],
20602030
);
20612031

20622032
const deleteStashEntry = useCallback(
20632033
(entry: PromptStashEntry) => {
2064-
const { durable } = takeStashEntry(promptStashScopeKey(entry.providerInstanceId), entry.id);
2034+
const { durable } = takeStashEntry(entry.id);
20652035
if (!durable) {
20662036
toastManager.add({
20672037
type: "warning",
@@ -2097,7 +2067,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
20972067

20982068
const stashTarget = composerDraftTarget;
20992069
const entryId = randomUUID();
2100-
const scopeKey = promptStashScopeKey(stashScopeInstanceId);
21012070
try {
21022071
// Persist the text-only entry *first*, then clear. Ordering matters in
21032072
// both directions: writing before clearing means a crash or closed tab
@@ -2109,8 +2078,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21092078
createdAt: new Date().toISOString(),
21102079
prompt,
21112080
attachments: [],
2112-
providerInstanceId: stashScopeInstanceId,
2113-
modelSelection: noProviderAvailable ? null : selectedModelSelection,
21142081
droppedImageNames: [],
21152082
unreadableImageNames: [],
21162083
pendingImageCount: images.length,
@@ -2144,7 +2111,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21442111
toastManager.add({
21452112
type: "warning",
21462113
title: "Oldest stashed prompt discarded",
2147-
description: `The ${stashProviderLabel} stash holds ${MAX_STASH_ENTRIES_PER_QUEUE} prompts; the oldest was removed to make room.`,
2114+
description: `The stash holds ${MAX_STASH_ENTRIES} prompts; the oldest was removed to make room.`,
21482115
data: { hideCopyButton: true },
21492116
});
21502117
}
@@ -2176,7 +2143,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21762143
}
21772144
const { kept, droppedNames } = partitionStashAttachments(candidateAttachments);
21782145

2179-
const { attached, durable: imagesDurable } = finalizeStashEntryImages(scopeKey, entryId, {
2146+
const { attached, durable: imagesDurable } = finalizeStashEntryImages(entryId, {
21802147
attachments: kept,
21812148
droppedImageNames: [...oversizedImageNames, ...droppedNames],
21822149
unreadableImageNames,
@@ -2216,13 +2183,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
22162183
composerDraftTarget,
22172184
composerImagesRef,
22182185
finalizeStashEntryImages,
2219-
noProviderAvailable,
22202186
promptRef,
22212187
pulseStashBadge,
2222-
selectedModelSelection,
22232188
stashEntryToQueue,
2224-
stashProviderLabel,
2225-
stashScopeInstanceId,
22262189
]);
22272190

22282191
const toggleStashMenu = useCallback(() => {
@@ -2832,8 +2795,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
28322795
<ComposerCommandMenuLayer anchor={composerMenuAnchor}>
28332796
<ComposerStashMenu
28342797
entries={stashQueue}
2835-
providerLabel={stashProviderLabel}
2836-
otherScopesCount={stashOtherScopesCount}
28372798
onRestore={restoreStashEntry}
28382799
onDelete={deleteStashEntry}
28392800
onClose={() => setIsStashMenuOpen(false)}

‎apps/web/src/components/chat/ComposerStashBadge.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { cn } from "~/lib/utils";
55

66
/**
77
* Bookmark pill perched on the composer's top-right shoulder. Shows the
8-
* current method's stash count and doubles as the click target for opening
9-
* the stash menu.
8+
* stash count and doubles as the click target for opening the stash menu.
109
*
1110
* On save the badge gives one quiet acknowledgement: it lifts to full
1211
* opacity and the count ticks over. `pulseKey` changes per stash, remounting

‎apps/web/src/components/chat/ComposerStashMenu.tsx‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ function stashEntrySnippet(entry: PromptStashEntry): string {
2424
}
2525

2626
/**
27-
* Popover listing the current connection method's stashed prompts.
28-
* Keyboard-first: opened by ⌘S on an empty composer, navigated with
29-
* arrows, restored with Enter, dismissed with Escape. The listener runs
30-
* capture-phase on window so it wins over the Lexical editor's handlers
31-
* while the menu is open.
27+
* Popover listing the stashed prompts. Keyboard-first: opened by ⌘S on an
28+
* empty composer, navigated with arrows, restored with Enter, dismissed
29+
* with Escape. The listener runs capture-phase on window so it wins over
30+
* the Lexical editor's handlers while the menu is open.
3231
*/
3332
export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
3433
entries: ReadonlyArray<PromptStashEntry>;
35-
providerLabel: string;
36-
otherScopesCount: number;
3734
onRestore: (entry: PromptStashEntry) => void;
3835
onDelete: (entry: PromptStashEntry) => void;
3936
onClose: () => void;
@@ -99,12 +96,11 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
9996
<CommandGroup>
10097
<CommandGroupLabel className="flex items-center gap-1.5 px-3 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground/55">
10198
<BookmarkIcon className="size-3" aria-hidden="true" />
102-
Stashed prompts — {props.providerLabel}
99+
Stashed prompts
103100
</CommandGroupLabel>
104101
{entries.length === 0 ? (
105102
<p className="px-3 pb-3 pt-1 text-muted-foreground/70 text-xs">
106-
Nothing stashed for this method yet. Press ⌘S with a prompt in the composer to stash
107-
it.
103+
Nothing stashed yet. Press ⌘S with a prompt in the composer to stash it.
108104
</p>
109105
) : (
110106
entries.map((entry) => (
@@ -173,12 +169,6 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
173169
))
174170
)}
175171
</CommandGroup>
176-
{props.otherScopesCount > 0 ? (
177-
<p className="border-t border-border/50 px-3 py-2 text-[11px] text-muted-foreground/60">
178-
{props.otherScopesCount} more stashed under other connection methods — switch provider
179-
to see them.
180-
</p>
181-
) : null}
182172
</CommandList>
183173
</div>
184174
</Command>

0 commit comments

Comments
 (0)