fix(webui): preserve queued guidance and command semantics during sends
This commit is contained in:
1 parent
42b85efa98
commit
4b4b5cfa9f
3 files changed
+55
-12
No files matched your search
@@ -271,6 +271,18 @@ MCP presets, or persisted topics. Topics have short, pronounceable handles such
|
|||||||
from the menu, or drag it from the sidebar, to attach its structured reference.
|
from the menu, or drag it from the sidebar, to attach its structured reference.
|
||||||
Typing the same text without selecting it remains plain text.
|
Typing the same text without selecting it remains plain text.
|
||||||
|
|
||||||
|
On touch-primary phones and tablets, **Enter** inserts a newline; tap the send
|
||||||
|
arrow to submit. This also applies when a coarse-pointer tablet has a hardware
|
||||||
|
keyboard attached. On desktop, **Enter** sends and **Shift+Enter** adds a newline.
|
||||||
|
An open slash-command or mention menu takes precedence: Enter selects its item.
|
||||||
|
|
||||||
|
While a response is running, the send arrow delivers a ready draft as guidance
|
||||||
|
for the active turn; it does not issue a stop command. Other messages already
|
||||||
|
waiting in the queue stay there. On desktop, Enter queues guidance and a second
|
||||||
|
Enter with an empty input sends that queued message immediately. Queued messages
|
||||||
|
also have a **Send now** action. The primary button shows **Stop** when there is
|
||||||
|
no sendable draft; clear the draft or use `/stop` to stop instead of sending it.
|
||||||
|
|
||||||
The agent can inspect an attached topic with `read_session`. It can discover other
|
The agent can inspect an attached topic with `read_session`. It can discover other
|
||||||
persisted topics with `list_sessions` and send asynchronous messages with
|
persisted topics with `list_sessions` and send asynchronous messages with
|
||||||
`send_session_message`; topic messaging is not limited by workspace scope.
|
`send_session_message`; topic messaging is not limited by workspace scope.
|
||||||
|
|||||||
@@ -2034,14 +2034,11 @@ 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 } : {}),
|
||||||
@@ -2049,7 +2046,6 @@ export function ThreadComposer({
|
|||||||
? { sessionMentions: activeSessionMentions }
|
? { sessionMentions: activeSessionMentions }
|
||||||
: {}),
|
: {}),
|
||||||
...(normalizedQuotedContext ? { quotedContext: normalizedQuotedContext } : {}),
|
...(normalizedQuotedContext ? { quotedContext: normalizedQuotedContext } : {}),
|
||||||
...(isStreaming ? { continueActiveTurn: true } : {}),
|
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
const hasPlainTextCommandPayload =
|
const hasPlainTextCommandPayload =
|
||||||
@@ -2081,7 +2077,8 @@ export function ThreadComposer({
|
|||||||
if (draftKey && draftStore && draftStore.get(draftKey) !== submittedDraft) return;
|
if (draftKey && draftStore && draftStore.get(draftKey) !== submittedDraft) return;
|
||||||
if (draftKey) draftStore?.delete(draftKey);
|
if (draftKey) draftStore?.delete(draftKey);
|
||||||
if (hasTouchPrimaryPointer) textareaRef.current?.blur();
|
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
|
// Bubble owns the data URL copy; safe to revoke every staged blob
|
||||||
// preview here without affecting the rendered message.
|
// preview here without affecting the rendered message.
|
||||||
clear();
|
clear();
|
||||||
@@ -2097,7 +2094,7 @@ export function ThreadComposer({
|
|||||||
sideChannel: true,
|
sideChannel: true,
|
||||||
...(finalizeActiveTurn ? { finalizeActiveTurn } : {}),
|
...(finalizeActiveTurn ? { finalizeActiveTurn } : {}),
|
||||||
}
|
}
|
||||||
: options,
|
: isStreaming ? { ...options, continueActiveTurn: true } : options,
|
||||||
);
|
);
|
||||||
if (result instanceof Promise) {
|
if (result instanceof Promise) {
|
||||||
setSendPending(true);
|
setSendPending(true);
|
||||||
@@ -2289,12 +2286,8 @@ 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");
|
||||||
// While streaming, the primary action is Stop only while the composer is
|
// Touch users need an explicit send action; keep Stop while sending is unavailable.
|
||||||
// empty. Once the user types, the send affordance takes over (like ChatGPT):
|
const showStopButton = isStreaming && !!onStop && !canSend;
|
||||||
// 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
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
|||||||
|
|
||||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||||
import { ComposerDraftStore } from "@/lib/composer-draft";
|
import { ComposerDraftStore } from "@/lib/composer-draft";
|
||||||
|
import { encodeImage } from "@/lib/imageEncode";
|
||||||
import { SESSION_DRAG_TYPE } from "@/lib/session-drag";
|
import { SESSION_DRAG_TYPE } from "@/lib/session-drag";
|
||||||
import type { ChatSummary, CliAppInfo, McpPresetInfo, SlashCommand } from "@/lib/types";
|
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", () => {
|
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