Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: show when an agent's claude login was stored, and delete it

The agent's settings get a claude login row: when the swarm stored the
login, read by the minter from the leaf's metadata, or that none is, with a
delete that removes every version after a confirmation. New minter steps
(status, delete), controller routes (GET claude-login, DELETE
claude-login/stored) and a read and delete grant on the leaf's metadata,
pinned in the module-eval check.
This commit is contained in:
iris 2026-11-09 21:39:17 +01:00 • committed by mara
commit 7dd147adb4

View file

@ -0,0 +1,112 @@
// <AgentClaudeLogin> — the swarm's stored claude login for one agent: when it
// was written (`GET …/claude-login`, read from the secret store's metadata),
// or that none is, and a delete that removes every version of it
// (`DELETE …/claude-login/stored`) after a confirmation.
//
// Its state belongs to one agent: callers key it by agent name.
import { useCallback, useEffect, useState } from "preact/hooks";
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
import { Badge } from "@hive/shared/badge.js";
import { ConfirmDialog } from "../../ui/confirm-dialog/ConfirmDialog.js";
import { Hint } from "../../ui/hint/Hint.js";
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
import { showToast } from "../../ui/toast/toasts.js";
import {
deleteMessage,
deleteStoredLoginPath,
storedAtMs,
storedLoginPath,
type StoredLogin,
} from "../claude-login/StoredLogin.js";
export function AgentClaudeLogin({ agent }: { agent: string }) {
const [login, setLogin] = useState<StoredLogin | null>(null);
const [error, setError] = useState<ProblemDetails | null>(null);
const [confirming, setConfirming] = useState(false);
const [deleting, setDeleting] = useState(false);
const [deleteError, setDeleteError] = useState<ProblemDetails | null>(null);
const load = useCallback(async () => {
try {
const r = await fetch(storedLoginPath(agent));
if (!r.ok) {
setError(await readApiError(r));
return;
}
setLogin((await r.json()) as StoredLogin);
setError(null);
} catch (err) {
setError({ detail: String(err) });
}
}, [agent]);
useEffect(() => {
void load();
}, [load]);
async function confirmDelete() {
setDeleting(true);
setDeleteError(null);
try {
const r = await fetch(deleteStoredLoginPath(agent), { method: "DELETE" });
if (!r.ok) {
setDeleteError(await readApiError(r));
return;
}
setConfirming(false);
showToast(`Stored login for ${agent} deleted.`, "ok");
await load();
} catch (err) {
setDeleteError({ detail: String(err) });
} finally {
setDeleting(false);
}
}
// Shown as text, not a hover title. A login already read stays under a
// failed refetch.
const errorPanel = error ? (
<ApiErrorPanel context="reading the stored login failed" problem={error} />
) : null;
if (login === null) {
return errorPanel ?? <Hint as="span">…</Hint>;
}
const at = storedAtMs(login);
return (
<>
{errorPanel}
{login.stored_at === null ? (
<Hint as="span">none stored</Hint>
) : (
<>
<span title={login.stored_at}>
stored {at === null ? login.stored_at : <RelativeTime epochMs={at} />}
</span>{" "}
<Badge
variant="quiet"
value="delete login"
title={`delete the stored claude login for ${agent}`}
onClick={() => {
setDeleteError(null);
setConfirming(true);
}}
/>
</>
)}
<ConfirmDialog
open={confirming}
label={`delete the stored claude login for ${agent}`}
confirmLabel={deleting ? "deleting…" : "delete login"}
confirmDisabled={deleting}
onCancel={() => setConfirming(false)}
onConfirm={() => void confirmDelete()}
>
<p>{deleteMessage(agent)}</p>
{deleteError ? (
<ApiErrorPanel context="delete failed" problem={deleteError} />
) : null}
</ConfirmDialog>
</>
);
}