Skip to content

Your lightweight open-source personal agent.

fix(webui): queue slash-prefixed chat text during responses

Xubin Ren5cf629963d42
diff --git a/docs/chat-commands.md b/docs/chat-commands.md
index 82c539513..232c8980b 100644
--- a/docs/chat-commands.md
+++ b/docs/chat-commands.md
@@ -39,6 +39,9 @@ Other text goes to the agent unchanged. This includes `/tmp`,
also go to the agent; the gateway no longer returns a spelling suggestion.
Use `/help` or the command menu to find a command.
+In the WebUI, Enter queues ordinary text while a response is running. Paths
+follow the same rule. Registered commands still go to the gateway immediately.
+
A path can have the same name as a command. For example, `/new` starts a new
conversation. To discuss that directory, write `/new/` or `Look at /new`.
Chat platforms can apply their own command rules before a message reaches the gateway.
diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsx
index 737ef2d65..b48345eca 100644
--- a/webui/src/components/thread/ThreadComposer.tsx
+++ b/webui/src/components/thread/ThreadComposer.tsx
@@ -124,6 +124,7 @@ import {
import { sessionHandleColor } from "@/lib/session-handle";
import { requestSkillsRefresh } from "@/lib/skill-events";
import {
+ isRegisteredSlashCommand,
isSideChannelLifecycle,
slashCommandLifecycle,
} from "@/lib/slash-command";
@@ -1199,7 +1200,7 @@ export function ThreadComposer({
&& !encoding
&& !hasErrors
&& hasComposerContent
- && !value.trimStart().startsWith("/");
+ && !isRegisteredSlashCommand(value, slashCommands);
const slashQuery = useMemo(() => {
if (interactionDisabled || slashMenuDismissed || !value.startsWith("/")) return null;
diff --git a/webui/src/lib/slash-command.ts b/webui/src/lib/slash-command.ts
index 48fc7577a..f473df8dc 100644
--- a/webui/src/lib/slash-command.ts
+++ b/webui/src/lib/slash-command.ts
@@ -14,6 +14,13 @@ function slashCommandArgs(content: string, commandName: string): string {
return content.slice(commandName.length).trim();
}
+export function isRegisteredSlashCommand(content: string, slashCommands: SlashCommand[]): boolean {
+ // Argument validation belongs to the gateway. Even invalid commands must not
+ // wait behind the active response; paths and unknown names are ordinary text.
+ const name = slashCommandName(content.trim()).replace(/@[A-Za-z0-9_]+$/, "").toLowerCase();
+ return slashCommands.some((item) => item.command === name);
+}
+
export function matchingSlashCommand(
content: string,
slashCommands: SlashCommand[],
diff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsx
index dc24dacec..1b3dc3bea 100644
--- a/webui/src/tests/thread-composer.test.tsx
+++ b/webui/src/tests/thread-composer.test.tsx
@@ -3207,6 +3207,43 @@ describe("ThreadComposer", () => {
expect(screen.queryByText("keep the UI minimal")).not.toBeInTheDocument();
});
+ it.each(["/tmp", "/home/user/project", "/stop/config.json", "/neaw"])(
+ "queues ordinary slash-prefixed text %s until the response finishes",
+ (content) => {
+ const onSend = vi.fn();
+ const composer = (isStreaming: boolean) => (
+ <ThreadComposer onSend={onSend} isStreaming={isStreaming} slashCommands={COMMANDS} />
+ );
+ const { rerender } = render(composer(true));
+ const input = screen.getByLabelText("Message input");
+ fireEvent.change(input, { target: { value: content } });
+ fireEvent.keyDown(input, { key: "Enter" });
+
+ expect(onSend).not.toHaveBeenCalled();
+ expect(screen.getByRole("group", { name: "Waiting to send" })).toHaveTextContent(content);
+
+ rerender(composer(false));
+
+ expect(onSend).toHaveBeenCalledTimes(1);
+ expect(onSend).toHaveBeenCalledWith(content);
+ expect(screen.queryByRole("group", { name: "Waiting to send" })).not.toBeInTheDocument();
+ },
+ );
+
+ it.each(["/history 5", "/stop now", "/STOP@nanobot now"])(
+ "sends registered command %s to the gateway without queuing it",
+ (content) => {
+ const onSend = vi.fn();
+ render(<ThreadComposer onSend={onSend} isStreaming slashCommands={COMMANDS} />);
+ fireEvent.change(screen.getByLabelText("Message input"), { target: { value: content } });
+ fireEvent.keyDown(screen.getByLabelText("Message input"), { key: "Enter" });
+
+ expect(onSend).toHaveBeenCalledTimes(1);
+ expect(onSend.mock.calls[0][0]).toBe(content);
+ expect(screen.queryByRole("group", { name: "Waiting to send" })).not.toBeInTheDocument();
+ },
+ );
+
it("guides queued guidance when Enter is pressed again", () => {
const onSend = vi.fn();
render(