swarm-ui: start page setup assistant offers to create ruth
This commit is contained in:
parent
89efda5ea2
commit
8bf53f7ed9
7 changed files with 208 additions and 15 deletions
22
frontend/packages/swarm-ui/src/shell/ruth-missing.ts
Normal file
22
frontend/packages/swarm-ui/src/shell/ruth-missing.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Whether the swarm has no agent named `ruth`, from `GET /api/agents/status`.
|
||||
// The start page's setup assistant shows only then. It is a nudge, so
|
||||
// anything short of a clear "ruth is not in the roster" answers `false`: a
|
||||
// failed request or an unreadable list must not tell the operator to set
|
||||
// up an agent that may already exist.
|
||||
|
||||
type Fetch = (url: string) => Promise<{
|
||||
ok: boolean;
|
||||
json: () => Promise<unknown>;
|
||||
}>;
|
||||
|
||||
export async function ruthIsMissing(fetchImpl: Fetch): Promise<boolean> {
|
||||
try {
|
||||
const r = await fetchImpl("/api/agents/status");
|
||||
if (!r.ok) return false;
|
||||
const rows = await r.json();
|
||||
if (!Array.isArray(rows)) return false;
|
||||
return !rows.some((row) => (row as { name?: unknown }).name === "ruth");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue