Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: turn an archetype agent into a custom one from its detail

This commit is contained in:
atlas 2026-11-01 12:08:38 +01:00 • committed by mara
commit 83bb47d134

View file

@ -71,6 +71,7 @@ export interface AgentActions {
selectOffline: (row: AgentRow) => void;
selectPaused: (row: AgentRow) => void;
requestDestroy: (row: AgentRow) => void;
requestCustom: (row: AgentRow) => void;
openLink: (row: AgentRow, kind: LinkKind) => void;
/** The confirm and link dialogs; render once, anywhere. */
dialogs: ComponentChildren;
@ -94,6 +95,7 @@ export function useAgentActions(
row: AgentRow;
state: "offline" | "paused";
} | null>(null);
const [customTarget, setCustomTarget] = useState<AgentRow | null>(null);
const [matrixTarget, setMatrixTarget] = useState<AgentRow | null>(null);
const [forgeTarget, setForgeTarget] = useState<AgentRow | null>(null);
const [githubTarget, setGithubTarget] = useState<AgentRow | null>(null);
@ -172,6 +174,38 @@ export function useAgentActions(
await declareState(row, "destroyed");
}
// The conversion is queued as a job graph; the roster shows the agent as
// custom once it has run, so a success needs no handling here.
async function turnIntoCustom(row: AgentRow) {
setCustomTarget(null);
setPendingAgents((prev) => new Set(prev).add(row.name));
setActionErrors((prev) => {
const next = new Map(prev);
next.delete(row.name);
return next;
});
try {
const res = await fetch(
`/api/agents/${encodeURIComponent(row.name)}/custom`,
{ method: "POST" },
);
if (!res.ok) {
const problem = await readApiError(res);
setActionErrors((prev) => new Map(prev).set(row.name, problem));
}
} catch (e: unknown) {
setActionErrors((prev) =>
new Map(prev).set(row.name, { detail: String(e) }),
);
} finally {
setPendingAgents((prev) => {
const next = new Set(prev);
next.delete(row.name);
return next;
});
}
}
const dialogs = (
<>
<Dialog
@ -248,6 +282,22 @@ export function useAgentActions(
? CONFIRM_COPY[confirmTarget.state].message(confirmTarget.row.name)
: null}
</ConfirmDialog>
<ConfirmDialog
open={customTarget !== null}
label="turn into custom"
onCancel={() => setCustomTarget(null)}
onConfirm={() => customTarget && void turnIntoCustom(customTarget)}
confirmLabel="turn into custom"
>
{customTarget ? (
<p>
Turn <strong>{customTarget.name}</strong> into a custom agent? It
gets its own config repo, which imports the archetype it runs today,
and is rebuilt from that repo. Keeping the config current is then up
to the repo's owner. This is not reversible from here.
</p>
) : null}
</ConfirmDialog>
<ConfirmDialog
open={destroyTarget !== null}
label="destroy agent"
@ -276,6 +326,7 @@ export function useAgentActions(
selectOffline: (row) => setConfirmTarget({ row, state: "offline" }),
selectPaused: (row) => setConfirmTarget({ row, state: "paused" }),
requestDestroy: setDestroyTarget,
requestCustom: setCustomTarget,
openLink: (row, kind) => {
if (kind === "matrix") setMatrixTarget(row);
else if (kind === "forge") setForgeTarget(row);