swarm-ui: cancel turn is a badge over the terminal, not a button by send
This commit is contained in:
parent
214d7000d3
commit
2f2b4aa9e2
1 changed files with 84 additions and 44 deletions
|
|
@ -8,25 +8,15 @@ import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
|||
import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
|
||||
import { TextField } from "../../ui/text-field/TextField.js";
|
||||
import { Button } from "../../ui/button/Button.js";
|
||||
import { canCancel, cancelNote, cancelPath } from "./cancel.js";
|
||||
import "./AgentInputForm.css";
|
||||
|
||||
type SubmitState =
|
||||
| { status: "idle" }
|
||||
| { status: "submitting" }
|
||||
| { status: "sent" }
|
||||
| { status: "cancelled"; acted: boolean }
|
||||
| { status: "error"; problem: ProblemDetails };
|
||||
|
||||
export function AgentInputForm({
|
||||
agentName,
|
||||
turnState,
|
||||
}: {
|
||||
agentName: string;
|
||||
// The agent's turn state when the page has it; the cancel button shows only
|
||||
// while the agent is in a turn.
|
||||
turnState?: string;
|
||||
}) {
|
||||
export function AgentInputForm({ agentName }: { agentName: string }) {
|
||||
const [body, setBody] = useState("");
|
||||
const [result, setResult] = useState<SubmitState>({ status: "idle" });
|
||||
|
||||
|
|
@ -53,21 +43,6 @@ export function AgentInputForm({
|
|||
}
|
||||
}
|
||||
|
||||
async function cancel() {
|
||||
setResult({ status: "submitting" });
|
||||
try {
|
||||
const r = await fetch(cancelPath(agentName), { method: "POST" });
|
||||
if (!r.ok) {
|
||||
setResult({ status: "error", problem: await readApiError(r) });
|
||||
return;
|
||||
}
|
||||
const { acted } = (await r.json()) as { acted: boolean };
|
||||
setResult({ status: "cancelled", acted });
|
||||
} catch (err) {
|
||||
setResult({ status: "error", problem: { detail: String(err) } });
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="ui-agent-input">
|
||||
<form class="ui-agent-input-form" onSubmit={submit}>
|
||||
|
|
@ -85,20 +60,8 @@ export function AgentInputForm({
|
|||
>
|
||||
{result.status === "submitting" ? "sending…" : "send"}
|
||||
</Button>
|
||||
{canCancel(turnState) && (
|
||||
<Button
|
||||
type="button"
|
||||
onClick={cancel}
|
||||
disabled={result.status === "submitting"}
|
||||
>
|
||||
cancel turn
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
{result.status === "sent" && <p class="ui-agent-input-sent">sent</p>}
|
||||
{result.status === "cancelled" && (
|
||||
<p class="ui-agent-input-sent">{cancelNote(result.acted)}</p>
|
||||
)}
|
||||
{result.status === "error" && (
|
||||
<ApiErrorPanel context="failed to send" problem={result.problem} />
|
||||
)}
|
||||
|
|
|
|||
Loading…
Reference in a new issue