fix(webui): preserve queued guidance and command semantics during sends

This commit is contained in:
Xubin Ren committed 2026-10-04 10:16:56 +08:00
1 parent 42b85efa98
commit 4b4b5cfa9f
3 files changed
+55 -12

No files matched your search

+5 -12
View File
@@ -2034,14 +2034,11 @@ export function ThreadComposer({
: undefined;
const attachedCliApps = activeCliMentionApps.map(cliAppMentionPayload);
const attachedMcpPresets = activeMcpPresetMentions.map(mcpPresetMentionPayload);
// While streaming, sending carries continueActiveTurn so the new message
// interjects instead of waiting for the running turn to finish.
const options: SendOptions | undefined =
attachedCliApps.length > 0
|| attachedMcpPresets.length > 0
|| activeSessionMentions.length > 0
|| normalizedQuotedContext
|| isStreaming
? {
...(attachedCliApps.length > 0 ? { cliApps: attachedCliApps } : {}),
...(attachedMcpPresets.length > 0 ? { mcpPresets: attachedMcpPresets } : {}),
@@ -2049,7 +2046,6 @@ export function ThreadComposer({
? { sessionMentions: activeSessionMentions }
: {}),
...(normalizedQuotedContext ? { quotedContext: normalizedQuotedContext } : {}),
...(isStreaming ? { continueActiveTurn: true } : {}),
}
: undefined;
const hasPlainTextCommandPayload =
@@ -2081,7 +2077,8 @@ export function ThreadComposer({
if (draftKey && draftStore && draftStore.get(draftKey) !== submittedDraft) return;
if (draftKey) draftStore?.delete(draftKey);
if (hasTouchPrimaryPointer) textareaRef.current?.blur();
setQueuedPrompts([]);
// Sending new guidance must not discard other messages still waiting.
if (!isStreaming || finalizeActiveTurn) setQueuedPrompts([]);
// Bubble owns the data URL copy; safe to revoke every staged blob
// preview here without affecting the rendered message.
clear();
@@ -2097,7 +2094,7 @@ export function ThreadComposer({
sideChannel: true,
...(finalizeActiveTurn ? { finalizeActiveTurn } : {}),
}
: options,
: isStreaming ? { ...options, continueActiveTurn: true } : options,
);
if (result instanceof Promise) {
setSendPending(true);
@@ -2289,12 +2286,8 @@ export function ThreadComposer({
: voiceRecorder.state === "transcribing"
? t("thread.composer.voice.transcribing")
: t("thread.composer.voice.hint");
// While streaming, the primary action is Stop only while the composer is
// empty. Once the user types, the send affordance takes over (like ChatGPT):
// tapping send interjects instead of waiting — this keeps the flow working
// on touch devices where Enter now inserts a newline instead of queueing
// guidance.
const showStopButton = isStreaming && !!onStop && !hasComposerContent;
// Touch users need an explicit send action; keep Stop while sending is unavailable.
const showStopButton = isStreaming && !!onStop && !canSend;
const relaxedHeroInput = isHero && images.length === 0 && !isStreaming;
const compactIdle = compactWhenIdle && !compactControls && !isHero && !composerFocused
&& value.length === 0 && images.length === 0 && !inlineError
+38
View File
@@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { ThreadComposer } from "@/components/thread/ThreadComposer";
import { ComposerDraftStore } from "@/lib/composer-draft";
import { encodeImage } from "@/lib/imageEncode";
import { SESSION_DRAG_TYPE } from "@/lib/session-drag";
import type { ChatSummary, CliAppInfo, McpPresetInfo, SlashCommand } from "@/lib/types";
@@ -3021,6 +3022,43 @@ describe("ThreadComposer", () => {
});
});
it("preserves waiting guidance when the send button submits a newer draft", () => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} onStop={vi.fn()} isStreaming />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: "waiting guidance" } });
fireEvent.keyDown(input, { key: "Enter" });
fireEvent.change(input, { target: { value: "send this now" } });
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
expect(onSend).toHaveBeenCalledWith("send this now", undefined, { continueActiveTurn: true });
expect(screen.getByText("waiting guidance")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Send now" }));
expect(onSend).toHaveBeenLastCalledWith("waiting guidance", undefined, { continueActiveTurn: true });
});
it("does not mark side-channel commands as guidance during an active turn", () => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} onStop={vi.fn()} isStreaming slashCommands={COMMANDS} />);
fireEvent.change(screen.getByLabelText("Message input"), { target: { value: "/history 5" } });
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
expect(onSend).toHaveBeenCalledWith("/history 5", undefined, { sideChannel: true });
});
it("keeps Stop available while a draft attachment is encoding", () => {
vi.mocked(encodeImage).mockReturnValueOnce(new Promise(() => {}));
const onStop = vi.fn();
const { container } = render(<ThreadComposer onSend={vi.fn()} onStop={onStop} isStreaming />);
fireEvent.change(screen.getByLabelText("Message input"), { target: { value: "unfinished draft" } });
fireEvent.change(container.querySelector('input[type="file"]')!, {
target: { files: [new File(["image"], "photo.png", { type: "image/png" })] },
});
fireEvent.click(screen.getByRole("button", { name: "Stop response" }));
expect(onStop).toHaveBeenCalledOnce();
expect(screen.getByLabelText("Message input")).toHaveValue("unfinished draft");
});
it("queues plain guidance while a task is running", () => {
const onSend = vi.fn();
render(