Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b0c0ad7be | ||
|
|
8060e91939 | ||
|
|
2f2b4aa9e2 | ||
|
|
214d7000d3 |
9 changed files with 216 additions and 18 deletions
|
|
@ -71,7 +71,9 @@ badge for a paused agent, and the tokens in its context and billed. The row
|
||||||
reads "no report yet" until the first report arrives, and for an agent that's
|
reads "no report yet" until the first report arrives, and for an agent that's
|
||||||
offline. The agent sends a report when its state changes and once a minute. If
|
offline. The agent sends a report when its state changes and once a minute. If
|
||||||
the browser gives up on the stream, a **reconnect** badge opens it again. The
|
the browser gives up on the stream, a **reconnect** badge opens it again. The
|
||||||
terminal's own tab keeps these badges, with the model, beside the connection badge.
|
terminal's own tab keeps these badges, with the model and the effort, beside the
|
||||||
|
connection badge; the turn-state badge says how long the agent has been in that
|
||||||
|
state.
|
||||||
|
|
||||||
On a terminal's own page (`/agents/<name>/terminal`, or a subagent's) the
|
On a terminal's own page (`/agents/<name>/terminal`, or a subagent's) the
|
||||||
header has an **N running subagents** badge. It opens a list of the agent's
|
header has an **N running subagents** badge. It opens a list of the agent's
|
||||||
|
|
@ -97,6 +99,10 @@ you flip it. It also hides the **components** tab, a page for developers, which
|
||||||
still answers at `/components`. The browser keeps the choice for the swarm UI, apart from the
|
still answers at `/components`. The browser keeps the choice for the swarm UI, apart from the
|
||||||
per-agent pages'.
|
per-agent pages'.
|
||||||
|
|
||||||
|
The menu also has an **expand tool output** toggle. It opens tool-output rows
|
||||||
|
expanded; rows already on screen keep their state, and rows that arrive after
|
||||||
|
you flip it follow it.
|
||||||
|
|
||||||
A terminal's own tab takes the agent's icon as its browser-tab icon, so tabs of
|
A terminal's own tab takes the agent's icon as its browser-tab icon, so tabs of
|
||||||
different agents tell apart. A subagent's tab shows its agent's icon. An agent
|
different agents tell apart. A subagent's tab shows its agent's icon. An agent
|
||||||
with no icon keeps the hyperhive mark.
|
with no icon keeps the hyperhive mark.
|
||||||
|
|
@ -354,7 +360,11 @@ box. **send** hands the text to the agent's harness, and the agent takes it as
|
||||||
an inbox message from your authelia username. **sent** means the harness was
|
an inbox message from your authelia username. **sent** means the harness was
|
||||||
listening and holds the message. If the harness isn't running, or isn't
|
listening and holds the message. If the harness isn't running, or isn't
|
||||||
connected to the swarm queue, the box shows an error and the agent gets nothing.
|
connected to the swarm queue, the box shows an error and the agent gets nothing.
|
||||||
Subagents have no message box.
|
While the agent is in a turn, a **cancel turn** badge appears among the state
|
||||||
|
badges over the terminal, in its own tab. It asks the agent's harness to stop
|
||||||
|
the turn, then shows whether one was running ("turn cancelled" or "nothing was
|
||||||
|
running"); a failure shows "cancel failed" with the reason on hover, and a click
|
||||||
|
tries again. Subagents have no message box and no cancel badge.
|
||||||
|
|
||||||
The message doesn't go through the agent's hive, so the hive dashboard's
|
The message doesn't go through the agent's hive, so the hive dashboard's
|
||||||
message history doesn't list it. The agent's answer shows in its terminal; an
|
message history doesn't list it. The agent's answer shows in its terminal; an
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { useApplyMotionOverride } from "@hive/shared/motion-apply.js";
|
||||||
import { Header } from "./components/Header.js";
|
import { Header } from "./components/Header.js";
|
||||||
import { MetaNav } from "./components/MetaNav.js";
|
import { MetaNav } from "./components/MetaNav.js";
|
||||||
import { AgentUserMenu } from "./components/AgentUserMenu.js";
|
import { AgentUserMenu } from "./components/AgentUserMenu.js";
|
||||||
import { ExpandDetailsSetting } from "./components/ExpandDetailsSetting.js";
|
import { ExpandDetailsSetting } from "@hive/shared/expand-details-setting.js";
|
||||||
import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js";
|
import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js";
|
||||||
import { StatusChips } from "./components/StatusChips.js";
|
import { StatusChips } from "./components/StatusChips.js";
|
||||||
import { LiveStream, type LiveStreamHandle } from "./components/LiveStream.js";
|
import { LiveStream, type LiveStreamHandle } from "./components/LiveStream.js";
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@
|
||||||
"./motion-apply.js": "./src/settings/motion-apply.ts",
|
"./motion-apply.js": "./src/settings/motion-apply.ts",
|
||||||
"./settings-menu.js": "./src/settings/SettingsMenu.tsx",
|
"./settings-menu.js": "./src/settings/SettingsMenu.tsx",
|
||||||
"./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx",
|
"./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx",
|
||||||
|
"./expand-details-setting.js": "./src/settings/ExpandDetailsSetting.tsx",
|
||||||
"./settings-menu.css": "./src/settings/SettingsMenu.css",
|
"./settings-menu.css": "./src/settings/SettingsMenu.css",
|
||||||
"./user-menu.js": "./src/user-menu/UserMenu.tsx",
|
"./user-menu.js": "./src/user-menu/UserMenu.tsx",
|
||||||
"./user-menu.css": "./src/user-menu/UserMenu.css"
|
"./user-menu.css": "./src/user-menu/UserMenu.css"
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,10 @@
|
||||||
// Agent-terminal-only settings-menu row: "expand tool output panels".
|
// Settings-menu row: "expand tool output". Rendered as a `<SettingsMenu>`
|
||||||
// Rendered as a `<SettingsMenu>` child (`@hive/shared/settings-menu.js`)
|
// child (`./SettingsMenu.js`) by each page that has a terminal, the per-agent
|
||||||
// rather than a prop on that shared component — `SettingsMenu` is also
|
// page and the swarm UI, rather than as a prop on the menu: the caller owns its
|
||||||
// used by swarm-ui, which has no terminal to apply this to, and a prior
|
// row, and the menu stays free of options only some pages use. Both read the
|
||||||
// attempt to gate it behind a boolean prop (`showExpandDetails`) on the
|
// same preference (`../prefs.js`), which `../terminal/Row.tsx` follows live.
|
||||||
// shared component drew mara's review: "you cannot just add it like
|
|
||||||
// this - if we have more and more options there in different places we
|
|
||||||
// will keep accumulating cruft in the shared component." This file owns
|
|
||||||
// its own state/storage entirely; `SettingsMenu` just renders it as a
|
|
||||||
// child, no different from any other consumer's markup.
|
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import {
|
import { getExpandDetailsPref, setExpandDetailsPref } from "../prefs.js";
|
||||||
getExpandDetailsPref,
|
|
||||||
setExpandDetailsPref,
|
|
||||||
} from "@hive/shared/prefs.js";
|
|
||||||
|
|
||||||
export function ExpandDetailsSetting() {
|
export function ExpandDetailsSetting() {
|
||||||
// Plain localStorage read, not a hook-managed override like
|
// Plain localStorage read, not a hook-managed override like
|
||||||
|
|
@ -46,7 +46,9 @@ import {
|
||||||
useSwarmAgentStateStream,
|
useSwarmAgentStateStream,
|
||||||
type TokenUsage,
|
type TokenUsage,
|
||||||
} from "./useSwarmAgentStateStream.js";
|
} from "./useSwarmAgentStateStream.js";
|
||||||
|
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
|
||||||
import { AgentInputForm } from "./AgentInputForm.js";
|
import { AgentInputForm } from "./AgentInputForm.js";
|
||||||
|
import { CancelTurnBadge } from "./CancelTurnBadge.js";
|
||||||
import "./AgentTermPreview.css";
|
import "./AgentTermPreview.css";
|
||||||
|
|
||||||
const NEAR_BOTTOM_PX = 48;
|
const NEAR_BOTTOM_PX = 48;
|
||||||
|
|
@ -145,7 +147,13 @@ export function StateBadges({
|
||||||
<>
|
<>
|
||||||
<Badge
|
<Badge
|
||||||
tone={TURN_STATE_TONE[header.turn_state] ?? "neutral"}
|
tone={TURN_STATE_TONE[header.turn_state] ?? "neutral"}
|
||||||
value={header.turn_state}
|
value={
|
||||||
|
<>
|
||||||
|
{header.turn_state} (
|
||||||
|
<RelativeTime epochMs={Date.parse(header.turn_state_since)} />)
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
title="how long the agent has been in this state"
|
||||||
/>
|
/>
|
||||||
{/* Only the non-boring case gets a badge — a healthy running
|
{/* Only the non-boring case gets a badge — a healthy running
|
||||||
agent (`agent_state: "up"`) doesn't need one for the
|
agent (`agent_state: "up"`) doesn't need one for the
|
||||||
|
|
@ -168,6 +176,13 @@ export function StateBadges({
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{withModel && (
|
||||||
|
<Badge
|
||||||
|
label="effort"
|
||||||
|
value={header.effort}
|
||||||
|
title={`set by: ${header.effort_source}`}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{ctx !== null && (
|
{ctx !== null && (
|
||||||
<Badge
|
<Badge
|
||||||
label="ctx"
|
label="ctx"
|
||||||
|
|
@ -263,6 +278,12 @@ export function AgentTermPreview({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{header && <StateBadges header={header} ctx={ctx} cost={cost} />}
|
{header && <StateBadges header={header} ctx={ctx} cost={cost} />}
|
||||||
|
{header && subagent === undefined && (
|
||||||
|
<CancelTurnBadge
|
||||||
|
agentName={agentName}
|
||||||
|
turnState={header.turn_state}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!fullHeight && (
|
{!fullHeight && (
|
||||||
<Badge
|
<Badge
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
// <CancelTurnBadge> — "cancel turn" among the state badges over the terminal.
|
||||||
|
// Shown only while the agent is in a turn (`canCancel`). POSTs
|
||||||
|
// `/api/agents/{name}/cancel`; the answer says whether a turn was running, and
|
||||||
|
// the badge shows that (or the failure) in place of its label, so a cancel is
|
||||||
|
// never silently a no-op. The answer clears when the next turn starts
|
||||||
|
// (`statusOnTurnChange`), so every turn can be cancelled; a failure can also be
|
||||||
|
// retried by clicking it.
|
||||||
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
|
import { Badge } from "@hive/shared/badge.js";
|
||||||
|
import { readApiError } from "@hive/shared/api-error.js";
|
||||||
|
import {
|
||||||
|
canCancel,
|
||||||
|
cancelNote,
|
||||||
|
cancelPath,
|
||||||
|
statusOnTurnChange,
|
||||||
|
} from "./cancel.js";
|
||||||
|
|
||||||
|
type CancelState =
|
||||||
|
| { status: "idle" }
|
||||||
|
| { status: "cancelling" }
|
||||||
|
| { status: "done"; acted: boolean }
|
||||||
|
| { status: "error"; detail: string };
|
||||||
|
|
||||||
|
export function CancelTurnBadge({
|
||||||
|
agentName,
|
||||||
|
turnState,
|
||||||
|
}: {
|
||||||
|
agentName: string;
|
||||||
|
turnState: string;
|
||||||
|
}) {
|
||||||
|
const [state, setState] = useState<CancelState>({ status: "idle" });
|
||||||
|
const prevTurn = useRef<string | undefined>(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const next = statusOnTurnChange(state.status, prevTurn.current, turnState);
|
||||||
|
prevTurn.current = turnState;
|
||||||
|
if (next !== state.status) setState({ status: next } as CancelState);
|
||||||
|
}, [turnState]);
|
||||||
|
|
||||||
|
async function cancel() {
|
||||||
|
setState({ status: "cancelling" });
|
||||||
|
try {
|
||||||
|
const r = await fetch(cancelPath(agentName), { method: "POST" });
|
||||||
|
if (!r.ok) {
|
||||||
|
const p = await readApiError(r);
|
||||||
|
setState({
|
||||||
|
status: "error",
|
||||||
|
detail: p.detail ?? p.title ?? `status ${p.status ?? r.status}`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { acted } = (await r.json()) as { acted: boolean };
|
||||||
|
setState({ status: "done", acted });
|
||||||
|
} catch (err) {
|
||||||
|
setState({ status: "error", detail: String(err) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.status === "done") {
|
||||||
|
return <Badge value={cancelNote(state.acted)} />;
|
||||||
|
}
|
||||||
|
if (state.status === "error") {
|
||||||
|
return (
|
||||||
|
<Badge
|
||||||
|
tone="negative"
|
||||||
|
value="cancel failed"
|
||||||
|
title={state.detail}
|
||||||
|
onClick={cancel}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!canCancel(turnState)) return null;
|
||||||
|
return (
|
||||||
|
<Badge
|
||||||
|
tone="warning"
|
||||||
|
value={state.status === "cancelling" ? "cancelling…" : "cancel turn"}
|
||||||
|
title="stop the agent's current turn"
|
||||||
|
onClick={state.status === "cancelling" ? undefined : cancel}
|
||||||
|
disabled={state.status === "cancelling"}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
41
frontend/packages/swarm-ui/src/agent/terminal/cancel.ts
Normal file
41
frontend/packages/swarm-ui/src/agent/terminal/cancel.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
// What the terminal page decides about cancelling a turn, without a DOM. The
|
||||||
|
// controller answers `POST /api/agents/{name}/cancel` with whether a turn was
|
||||||
|
// running and was stopped (`acted`), so a cancel is never silently a no-op.
|
||||||
|
|
||||||
|
/** Whether to offer the cancel button: while the agent is in a turn. */
|
||||||
|
export function canCancel(turnState: string | undefined): boolean {
|
||||||
|
return turnState === "thinking";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The path a cancel is sent to. */
|
||||||
|
export function cancelPath(agentName: string): string {
|
||||||
|
return `/api/agents/${encodeURIComponent(agentName)}/cancel`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What to tell the operator once the agent has answered. */
|
||||||
|
export function cancelNote(acted: boolean): string {
|
||||||
|
return acted ? "turn cancelled" : "nothing was running";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What the cancel badge is showing. */
|
||||||
|
export type CancelStatus = "idle" | "cancelling" | "done" | "error";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The badge's status once the agent's turn state moves from `prev` to `now`.
|
||||||
|
* The answer ("turn cancelled") stays up after the turn it stopped ends, and
|
||||||
|
* clears when the next turn starts, so that turn can be cancelled too. A
|
||||||
|
* failure clears as soon as its turn ends: with no turn running, there is
|
||||||
|
* nothing left to retry.
|
||||||
|
*/
|
||||||
|
export function statusOnTurnChange(
|
||||||
|
status: CancelStatus,
|
||||||
|
prev: string | undefined,
|
||||||
|
now: string | undefined,
|
||||||
|
): CancelStatus {
|
||||||
|
if (status === "cancelling") return status;
|
||||||
|
const wasIn = canCancel(prev);
|
||||||
|
const isIn = canCancel(now);
|
||||||
|
if (isIn && !wasIn) return "idle";
|
||||||
|
if (!isIn && wasIn && status === "error") return "idle";
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
@ -34,6 +34,7 @@ import { UserMenu } from "./UserMenu.js";
|
||||||
import { useHideDebug } from "./useHideDebug.js";
|
import { useHideDebug } from "./useHideDebug.js";
|
||||||
import { SettingsMenu } from "@hive/shared/settings-menu.js";
|
import { SettingsMenu } from "@hive/shared/settings-menu.js";
|
||||||
import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js";
|
import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js";
|
||||||
|
import { ExpandDetailsSetting } from "@hive/shared/expand-details-setting.js";
|
||||||
import { useApplyThemeOverride } from "@hive/shared/theme-apply.js";
|
import { useApplyThemeOverride } from "@hive/shared/theme-apply.js";
|
||||||
import { useApplyMotionOverride } from "@hive/shared/motion-apply.js";
|
import { useApplyMotionOverride } from "@hive/shared/motion-apply.js";
|
||||||
import { isFullBleedRoute, visibleNavItems } from "./routes.js";
|
import { isFullBleedRoute, visibleNavItems } from "./routes.js";
|
||||||
|
|
@ -422,6 +423,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
|
||||||
<div class="shell-header-actions">
|
<div class="shell-header-actions">
|
||||||
<SettingsMenu themeKey={THEME_KEY} motionKey={MOTION_KEY}>
|
<SettingsMenu themeKey={THEME_KEY} motionKey={MOTION_KEY}>
|
||||||
<HideDebugSetting />
|
<HideDebugSetting />
|
||||||
|
<ExpandDetailsSetting />
|
||||||
</SettingsMenu>
|
</SettingsMenu>
|
||||||
<LinksMenu />
|
<LinksMenu />
|
||||||
<UserMenu />
|
<UserMenu />
|
||||||
|
|
|
||||||
49
frontend/packages/swarm-ui/test/cancel.test.mjs
Normal file
49
frontend/packages/swarm-ui/test/cancel.test.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
// What the terminal page decides about cancelling a turn. Run by `npm test`.
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { test } from "node:test";
|
||||||
|
import {
|
||||||
|
canCancel,
|
||||||
|
cancelNote,
|
||||||
|
cancelPath,
|
||||||
|
statusOnTurnChange,
|
||||||
|
} from "../src/agent/terminal/cancel.ts";
|
||||||
|
|
||||||
|
test("cancel is offered while the agent is in a turn, and only then", () => {
|
||||||
|
assert.equal(canCancel("thinking"), true);
|
||||||
|
assert.equal(canCancel("idle"), false);
|
||||||
|
assert.equal(canCancel("compacting"), false);
|
||||||
|
assert.equal(canCancel(undefined), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the cancel path names the agent, escaped", () => {
|
||||||
|
assert.equal(cancelPath("iris"), "/api/agents/iris/cancel");
|
||||||
|
assert.equal(cancelPath("a/b"), "/api/agents/a%2Fb/cancel");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the note says whether a turn was stopped", () => {
|
||||||
|
assert.equal(cancelNote(true), "turn cancelled");
|
||||||
|
assert.equal(cancelNote(false), "nothing was running");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the answer stays after its turn ends and clears when the next starts", () => {
|
||||||
|
assert.equal(statusOnTurnChange("done", "thinking", "idle"), "done");
|
||||||
|
assert.equal(statusOnTurnChange("done", "idle", "idle"), "done");
|
||||||
|
assert.equal(statusOnTurnChange("done", "idle", "thinking"), "idle");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a failure clears when its turn ends, or a new one starts", () => {
|
||||||
|
assert.equal(statusOnTurnChange("error", "thinking", "thinking"), "error");
|
||||||
|
assert.equal(statusOnTurnChange("error", "thinking", "idle"), "idle");
|
||||||
|
assert.equal(statusOnTurnChange("error", "idle", "thinking"), "idle");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a cancel in flight is left alone", () => {
|
||||||
|
assert.equal(
|
||||||
|
statusOnTurnChange("cancelling", "thinking", "idle"),
|
||||||
|
"cancelling",
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
statusOnTurnChange("cancelling", "idle", "thinking"),
|
||||||
|
"cancelling",
|
||||||
|
);
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue