feat(webui): interject via the send button while streaming
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.
This commit is contained in:
1 parent
2750a19601
commit
42b85efa98
2 files changed
+70
-6
No files matched your search
@@ -971,8 +971,8 @@ export function ThreadComposer({
|
|||||||
const [recentSlashCommands, setRecentSlashCommands] = useState<string[]>(() => readSlashRecents());
|
const [recentSlashCommands, setRecentSlashCommands] = useState<string[]>(() => readSlashRecents());
|
||||||
const [queuedPrompts, setQueuedPrompts] = useState<QueuedPrompt[]>([]);
|
const [queuedPrompts, setQueuedPrompts] = useState<QueuedPrompt[]>([]);
|
||||||
const hasTouchPrimaryPointer = useMediaQuery("(hover: none) and (pointer: coarse)");
|
const hasTouchPrimaryPointer = useMediaQuery("(hover: none) and (pointer: coarse)");
|
||||||
// Wider than hasTouchPrimaryPointer on purpose: tablets with a physical
|
// Coarser than hasTouchPrimaryPointer on purpose: tablets with a physical
|
||||||
// keyboard still count as touch for the Enter key behavior below.
|
// keyboard still get the newline-on-Enter behavior.
|
||||||
const hasCoarsePointer = useMediaQuery("(pointer: coarse)");
|
const hasCoarsePointer = useMediaQuery("(pointer: coarse)");
|
||||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
const mentionOverlayRef = useRef<HTMLDivElement>(null);
|
const mentionOverlayRef = useRef<HTMLDivElement>(null);
|
||||||
@@ -2034,11 +2034,14 @@ export function ThreadComposer({
|
|||||||
: undefined;
|
: undefined;
|
||||||
const attachedCliApps = activeCliMentionApps.map(cliAppMentionPayload);
|
const attachedCliApps = activeCliMentionApps.map(cliAppMentionPayload);
|
||||||
const attachedMcpPresets = activeMcpPresetMentions.map(mcpPresetMentionPayload);
|
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 =
|
const options: SendOptions | undefined =
|
||||||
attachedCliApps.length > 0
|
attachedCliApps.length > 0
|
||||||
|| attachedMcpPresets.length > 0
|
|| attachedMcpPresets.length > 0
|
||||||
|| activeSessionMentions.length > 0
|
|| activeSessionMentions.length > 0
|
||||||
|| normalizedQuotedContext
|
|| normalizedQuotedContext
|
||||||
|
|| isStreaming
|
||||||
? {
|
? {
|
||||||
...(attachedCliApps.length > 0 ? { cliApps: attachedCliApps } : {}),
|
...(attachedCliApps.length > 0 ? { cliApps: attachedCliApps } : {}),
|
||||||
...(attachedMcpPresets.length > 0 ? { mcpPresets: attachedMcpPresets } : {}),
|
...(attachedMcpPresets.length > 0 ? { mcpPresets: attachedMcpPresets } : {}),
|
||||||
@@ -2046,6 +2049,7 @@ export function ThreadComposer({
|
|||||||
? { sessionMentions: activeSessionMentions }
|
? { sessionMentions: activeSessionMentions }
|
||||||
: {}),
|
: {}),
|
||||||
...(normalizedQuotedContext ? { quotedContext: normalizedQuotedContext } : {}),
|
...(normalizedQuotedContext ? { quotedContext: normalizedQuotedContext } : {}),
|
||||||
|
...(isStreaming ? { continueActiveTurn: true } : {}),
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
const hasPlainTextCommandPayload =
|
const hasPlainTextCommandPayload =
|
||||||
@@ -2285,7 +2289,12 @@ export function ThreadComposer({
|
|||||||
: voiceRecorder.state === "transcribing"
|
: voiceRecorder.state === "transcribing"
|
||||||
? t("thread.composer.voice.transcribing")
|
? t("thread.composer.voice.transcribing")
|
||||||
: t("thread.composer.voice.hint");
|
: 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 relaxedHeroInput = isHero && images.length === 0 && !isStreaming;
|
||||||
const compactIdle = compactWhenIdle && !compactControls && !isHero && !composerFocused
|
const compactIdle = compactWhenIdle && !compactControls && !isHero && !composerFocused
|
||||||
&& value.length === 0 && images.length === 0 && !inlineError
|
&& value.length === 0 && images.length === 0 && !inlineError
|
||||||
@@ -2705,10 +2714,10 @@ export function ThreadComposer({
|
|||||||
>
|
>
|
||||||
{showStopButton ? (
|
{showStopButton ? (
|
||||||
<Square className={cn("fill-current stroke-current", isHero ? "h-3 w-3" : "h-3.5 w-3.5")} />
|
<Square className={cn("fill-current stroke-current", isHero ? "h-3 w-3" : "h-3.5 w-3.5")} />
|
||||||
) : isStreaming ? (
|
) : canSend || !isStreaming ? (
|
||||||
<Loader2 className={cn(isHero ? "h-4 w-4" : "h-4 w-4", "animate-spin")} />
|
|
||||||
) : (
|
|
||||||
<ArrowUp className={cn(isHero ? "h-4 w-4" : "h-4 w-4")} />
|
<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>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2966,6 +2966,61 @@ describe("ThreadComposer", () => {
|
|||||||
expect(screen.queryByRole("button", { name: "Send message" })).not.toBeInTheDocument();
|
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", () => {
|
it("queues plain guidance while a task is running", () => {
|
||||||
const onSend = vi.fn();
|
const onSend = vi.fn();
|
||||||
render(
|
render(
|
||||||
|
|||||||
Reference in new issue
Block a user