swarm: /clear starts an agent's next turn on a fresh session
This commit is contained in:
parent
7b62f2c22a
commit
fb9d4b5040
1 changed files with 155 additions and 22 deletions
|
|
@ -4,6 +4,10 @@
|
|||
// sees it as an inbox turn from the logged-in user (the controller takes the
|
||||
// sender from the gateway, not from this request).
|
||||
//
|
||||
// Sending exactly `/clear` is not a message: it POSTs
|
||||
// `/api/agents/{name}/new-session`, which queues a fresh claude session for the
|
||||
// agent's next turn (`controlRoute`).
|
||||
//
|
||||
// While the text is one `/word`, a menu of the agent's commands and skills
|
||||
// opens above the box (`CommandMenu`): the arrow keys move, Tab or Enter take
|
||||
// the selected one into the box, Esc closes it. The list is the agent's own
|
||||
|
|
@ -16,6 +20,7 @@ import { useSubmit } from "../../ui/submit/useSubmit.js";
|
|||
import { CommandMenu } from "./CommandMenu.js";
|
||||
import {
|
||||
completion,
|
||||
controlRoute,
|
||||
enterSends,
|
||||
matchCommands,
|
||||
menuQuery,
|
||||
|
|
@ -47,13 +52,17 @@ export function AgentInputForm({ agentName }: { agentName: string }) {
|
|||
|
||||
function submit(e: Event) {
|
||||
e.preventDefault();
|
||||
const base = `/api/agents/${encodeURIComponent(agentName)}`;
|
||||
const route = controlRoute(body, commands);
|
||||
void run(
|
||||
() =>
|
||||
fetch(`/api/agents/${encodeURIComponent(agentName)}/input`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ body }),
|
||||
}),
|
||||
route
|
||||
? fetch(`${base}/${route}`, { method: "POST" })
|
||||
: fetch(`${base}/input`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ body }),
|
||||
}),
|
||||
{ onDone: () => setBody("") },
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue