fix(webui): keep queued prompts scoped across session switches

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-08 15:16:54 +08:00
1 parent f47b8f2315
commit 2b6c91472b
2 files changed
+43 -5

No files matched your search

+10 -5
View File
@@ -963,7 +963,7 @@ export function ThreadComposer({
const secondEnterPromptIdRef = useRef<string | null>(null); const secondEnterPromptIdRef = useRef<string | null>(null);
const draggedQueuedPromptIdRef = useRef<string | null>(null); const draggedQueuedPromptIdRef = useRef<string | null>(null);
const previousPendingQueueKeyRef = useRef(pendingQueueKey); const previousPendingQueueKeyRef = useRef(pendingQueueKey);
const wasStreamingRef = useRef(isStreaming); const previousQueueRunRef = useRef({ key: pendingQueueKey, isStreaming });
const skipNextQueuedFlushRef = useRef(false); const skipNextQueuedFlushRef = useRef(false);
const skipQueuedPromptPersistRef = useRef(false); const skipQueuedPromptPersistRef = useRef(false);
const voiceShortcutDownRef = useRef(false); const voiceShortcutDownRef = useRef(false);
@@ -1895,16 +1895,21 @@ export function ThreadComposer({
}, [onSend, queuedPrompts]); }, [onSend, queuedPrompts]);
useEffect(() => { useEffect(() => {
const wasStreaming = wasStreamingRef.current; const previous = previousQueueRunRef.current;
wasStreamingRef.current = isStreaming; previousQueueRunRef.current = { key: pendingQueueKey, isStreaming };
if (!isStreaming) secondEnterPromptIdRef.current = null; if (!isStreaming) secondEnterPromptIdRef.current = null;
if (!wasStreaming || isStreaming || queuedPrompts.length === 0) return; // Switching to an idle session is not completion of the previous session's run.
if (previous.key !== pendingQueueKey) {
skipNextQueuedFlushRef.current = false;
return;
}
if (!previous.isStreaming || isStreaming || queuedPrompts.length === 0) return;
if (skipNextQueuedFlushRef.current) { if (skipNextQueuedFlushRef.current) {
skipNextQueuedFlushRef.current = false; skipNextQueuedFlushRef.current = false;
return; return;
} }
sendNextQueuedPrompt(); sendNextQueuedPrompt();
}, [sendNextQueuedPrompt, isStreaming, queuedPrompts.length]); }, [sendNextQueuedPrompt, isStreaming, pendingQueueKey, queuedPrompts.length]);
const handleStop = useCallback(() => { const handleStop = useCallback(() => {
secondEnterPromptIdRef.current = null; secondEnterPromptIdRef.current = null;
+33
View File
@@ -3053,6 +3053,39 @@ describe("ThreadComposer", () => {
}); });
}); });
it("keeps queued guidance in its session when switching from running to idle", () => {
const sendA = vi.fn();
const sendB = vi.fn();
const view = render(
<ThreadComposer onSend={sendA} isStreaming pendingQueueKey="chat-a" />,
);
fireEvent.change(screen.getByLabelText("Message input"), {
target: { value: "follow-up for A" },
});
fireEvent.keyDown(screen.getByLabelText("Message input"), { key: "Enter" });
expect(screen.getByText("follow-up for A")).toBeInTheDocument();
expect(sendA).not.toHaveBeenCalled();
view.rerender(
<ThreadComposer onSend={sendB} isStreaming={false} pendingQueueKey="chat-b" />,
);
expect(sendB).not.toHaveBeenCalled();
expect(screen.queryByText("follow-up for A")).not.toBeInTheDocument();
view.rerender(
<ThreadComposer onSend={sendA} isStreaming pendingQueueKey="chat-a" />,
);
expect(screen.getByText("follow-up for A")).toBeInTheDocument();
expect(sendA).not.toHaveBeenCalled();
view.rerender(
<ThreadComposer onSend={sendA} isStreaming={false} pendingQueueKey="chat-a" />,
);
expect(sendA).toHaveBeenCalledTimes(1);
expect(sendA).toHaveBeenCalledWith("follow-up for A");
expect(sendB).not.toHaveBeenCalled();
expect(screen.queryByText("follow-up for A")).not.toBeInTheDocument();
});
it("persists queued guidance per chat across remounts", async () => { it("persists queued guidance per chat across remounts", async () => {
const onSend = vi.fn(); const onSend = vi.fn();
const { rerender, unmount } = render( const { rerender, unmount } = render(