fix(webui): queue slash-prefixed chat text during responses
This commit is contained in:
1 parent
7e00d6a944
commit
5cf629963d
4 files changed
+49
-1
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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[],
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user