From 42b85efa9847ccb9a6dcddddfe9537b2e9770043 Mon Sep 17 00:00:00 2001 From: moran Date: Thu, 3 Sep 2026 05:11:20 +0000 Subject: [PATCH] feat(webui): interject via the send button while streaming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While a turn is streaming, the primary action button stays Stop only while the composer is empty. Once the user types, the send affordance takes over (ChatGPT-style): tapping Send stops the running turn for the agent and immediately delivers the new message with continueActiveTurn semantics — the same backend contract the queued-guidance flush uses. This restores 插嘴 (interjection) on touch devices, where Enter now inserts a newline instead of queueing guidance (the queue-guidance flow stays available on precision-pointer devices via Enter, and the queued prompt stack still sends already-queued prompts anywhere). submit() now carries continueActiveTurn while streaming; the button icon switches to the send arrow in that state. --- .../src/components/thread/ThreadComposer.tsx | 21 +++++-- webui/src/tests/thread-composer.test.tsx | 55 +++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsx index b5c484c6d..50328540e 100644 --- a/webui/src/components/thread/ThreadComposer.tsx +++ b/webui/src/components/thread/ThreadComposer.tsx @@ -971,8 +971,8 @@ export function ThreadComposer({ const [recentSlashCommands, setRecentSlashCommands] = useState(() => readSlashRecents()); const [queuedPrompts, setQueuedPrompts] = useState([]); const hasTouchPrimaryPointer = useMediaQuery("(hover: none) and (pointer: coarse)"); - // Wider than hasTouchPrimaryPointer on purpose: tablets with a physical - // keyboard still count as touch for the Enter key behavior below. + // Coarser than hasTouchPrimaryPointer on purpose: tablets with a physical + // keyboard still get the newline-on-Enter behavior. const hasCoarsePointer = useMediaQuery("(pointer: coarse)"); const textareaRef = useRef(null); const mentionOverlayRef = useRef(null); @@ -2034,11 +2034,14 @@ 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 } : {}), @@ -2046,6 +2049,7 @@ export function ThreadComposer({ ? { sessionMentions: activeSessionMentions } : {}), ...(normalizedQuotedContext ? { quotedContext: normalizedQuotedContext } : {}), + ...(isStreaming ? { continueActiveTurn: true } : {}), } : undefined; const hasPlainTextCommandPayload = @@ -2285,7 +2289,12 @@ export function ThreadComposer({ : voiceRecorder.state === "transcribing" ? t("thread.composer.voice.transcribing") : t("thread.composer.voice.hint"); - const showStopButton = isStreaming && !!onStop; + // 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; const relaxedHeroInput = isHero && images.length === 0 && !isStreaming; const compactIdle = compactWhenIdle && !compactControls && !isHero && !composerFocused && value.length === 0 && images.length === 0 && !inlineError @@ -2705,10 +2714,10 @@ export function ThreadComposer({ > {showStopButton ? ( - ) : isStreaming ? ( - - ) : ( + ) : canSend || !isStreaming ? ( + ) : ( + )} diff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsx index 90f8dcdb7..53bd047ad 100644 --- a/webui/src/tests/thread-composer.test.tsx +++ b/webui/src/tests/thread-composer.test.tsx @@ -2966,6 +2966,61 @@ describe("ThreadComposer", () => { expect(screen.queryByRole("button", { name: "Send message" })).not.toBeInTheDocument(); }); + it("switches the primary action from Stop to Send while streaming once the user types", () => { + const onSend = vi.fn(); + const onStop = vi.fn(); + render( + , + ); + + expect(screen.getByRole("button", { name: "Stop response" })).toBeInTheDocument(); + + const input = screen.getByLabelText("Message input"); + fireEvent.change(input, { target: { value: "one more thing: " } }); + + expect(screen.queryByRole("button", { name: "Stop response" })).not.toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "Send message" })); + + expect(onStop).not.toHaveBeenCalled(); + expect(onSend).toHaveBeenCalledWith("one more thing:", undefined, { + continueActiveTurn: true, + }); + }); + + it("interjects with the send button on coarse-pointer devices while streaming", () => { + stubCoarsePointer(); + const onSend = vi.fn(); + render( + , + ); + + const input = screen.getByLabelText("Message input"); + fireEvent.change(input, { target: { value: "hold on, actually…" } }); + const keyEvent = createEvent.keyDown(input, { key: "Enter" }); + fireEvent(input, keyEvent); + + // Enter inserts a newline on touch; the send button is the interject path. + expect(keyEvent.defaultPrevented).toBe(false); + expect(onSend).not.toHaveBeenCalled(); + expect(screen.getByRole("button", { name: "Send message" })).toBeInTheDocument(); + + fireEvent.click(screen.getByRole("button", { name: "Send message" })); + + expect(onSend).toHaveBeenCalledWith("hold on, actually…", undefined, { + continueActiveTurn: true, + }); + }); + it("queues plain guidance while a task is running", () => { const onSend = vi.fn(); render(