Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): preserve queued guidance and command semantics during sends
Xubin Ren4b4b5cfa9fb6
diff --git a/docs/webui.md b/docs/webui.mdindex 1208fa777..68137a054 100644--- a/docs/webui.md+++ b/docs/webui.md@@ -271,6 +271,18 @@ MCP presets, or persisted topics. Topics have short, pronounceable handles suchfrom the menu, or drag it from the sidebar, to attach its structured reference.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 otherpersisted topics with `list_sessions` and send asynchronous messages with`send_session_message`; topic messaging is not limited by workspace scope.diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsxindex 50328540e..60fc27bac 100644--- a/webui/src/components/thread/ThreadComposer.tsx+++ b/webui/src/components/thread/ThreadComposer.tsx@@ -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 && !inlineErrordiff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsxindex 53bd047ad..b53b8fbea 100644--- a/webui/src/tests/thread-composer.test.tsx+++ b/webui/src/tests/thread-composer.test.tsx@@ -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(