Skip to content

Your lightweight open-source personal agent.

feat(webui): interject via the send button while streaming

moran42b85efa9847
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<string[]>(() => readSlashRecents());
const [queuedPrompts, setQueuedPrompts] = useState<QueuedPrompt[]>([]);
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<HTMLTextAreaElement>(null);
const mentionOverlayRef = useRef<HTMLDivElement>(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 ? (
<Square className={cn("fill-current stroke-current", isHero ? "h-3 w-3" : "h-3.5 w-3.5")} />
- ) : isStreaming ? (
- <Loader2 className={cn(isHero ? "h-4 w-4" : "h-4 w-4", "animate-spin")} />
- ) : (
+ ) : canSend || !isStreaming ? (
<ArrowUp className={cn(isHero ? "h-4 w-4" : "h-4 w-4")} />
+ ) : (
+ <Loader2 className={cn(isHero ? "h-4 w-4" : "h-4 w-4", "animate-spin")} />
)}
</Button>
</div>
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(
+ <ThreadComposer
+ onSend={onSend}
+ onStop={onStop}
+ isStreaming
+ placeholder="Type your message..."
+ />,
+ );
+
+ 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(
+ <ThreadComposer
+ onSend={onSend}
+ onStop={vi.fn()}
+ isStreaming
+ placeholder="Type your message..."
+ />,
+ );
+
+ 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(