22 lines
786 B
TypeScript
22 lines
786 B
TypeScript
// 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;
|
|
}
|
|
}
|