swarm ui: a lone /word goes without the space completion leaves
This commit is contained in:
parent
299b922039
commit
2f3c9253bf
3 changed files with 27 additions and 1 deletions
|
|
@ -24,6 +24,7 @@ import {
|
||||||
enterSends,
|
enterSends,
|
||||||
matchCommands,
|
matchCommands,
|
||||||
menuQuery,
|
menuQuery,
|
||||||
|
textToSend,
|
||||||
moveSelection,
|
moveSelection,
|
||||||
type AgentCommand,
|
type AgentCommand,
|
||||||
} from "./command-menu.js";
|
} from "./command-menu.js";
|
||||||
|
|
@ -61,7 +62,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) {
|
||||||
: fetch(`${base}/input`, {
|
: fetch(`${base}/input`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: JSON.stringify({ body }),
|
body: JSON.stringify({ body: textToSend(body) }),
|
||||||
}),
|
}),
|
||||||
{ onDone: () => setBody("") },
|
{ onDone: () => setBody("") },
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -108,3 +108,14 @@ export function controlRoute(
|
||||||
commands.some((c) => c.kind === "command" && c.name === "clear");
|
commands.some((c) => c.kind === "command" && c.name === "clear");
|
||||||
return isClear ? "new-session" : null;
|
return isClear ? "new-session" : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The text to send for what the box holds: a lone `/word`, which completion
|
||||||
|
* leaves with a space after it, goes without that space, so a command such as
|
||||||
|
* `/compact` reaches the agent exactly as typed by hand. Any other message goes
|
||||||
|
* as it is.
|
||||||
|
*/
|
||||||
|
export function textToSend(text: string): string {
|
||||||
|
const trimmed = text.trim();
|
||||||
|
return menuQuery(trimmed) === null ? text : trimmed;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
menuQuery,
|
menuQuery,
|
||||||
moveSelection,
|
moveSelection,
|
||||||
splitName,
|
splitName,
|
||||||
|
textToSend,
|
||||||
} from "../src/agent/terminal/command-menu.ts";
|
} from "../src/agent/terminal/command-menu.ts";
|
||||||
|
|
||||||
const cmd = (name, kind = "command", description = "") => ({
|
const cmd = (name, kind = "command", description = "") => ({
|
||||||
|
|
@ -113,3 +114,16 @@ test("without the backend's /clear command, or with a skill of that name, it is
|
||||||
assert.equal(controlRoute("/clear", []), null);
|
assert.equal(controlRoute("/clear", []), null);
|
||||||
assert.equal(controlRoute("/clear", [cmd("clear", "skill")]), null);
|
assert.equal(controlRoute("/clear", [cmd("clear", "skill")]), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a lone slash word goes without the space completion left", () => {
|
||||||
|
assert.equal(textToSend("/compact "), "/compact");
|
||||||
|
assert.equal(textToSend("/compact"), "/compact");
|
||||||
|
assert.equal(textToSend(" /base:pr-review "), "/base:pr-review");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("any other message goes as it is", () => {
|
||||||
|
assert.equal(textToSend("hello "), "hello ");
|
||||||
|
assert.equal(textToSend("/compact now "), "/compact now ");
|
||||||
|
assert.equal(textToSend("fix /etc/hosts"), "fix /etc/hosts");
|
||||||
|
assert.equal(textToSend(" "), " ");
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue