Watch
0
0
Fork
You've already forked hyperhive
0

let the operator set, replace and remove an agent's backend env from the swarm ui

This commit is contained in:
atlas 2026-10-28 01:33:52 +01:00 • committed by mara
commit 57b04d6c49
3 changed files with 795 additions and 201 deletions

View file

@ -1,5 +1,5 @@
// <LinkAccountMenu> — one "link account" badge that opens a `Dropdown` with
// the three kinds of account an agent can be linked to, in place of one
// the kinds of account and credential an agent can be linked to, in place of one
// badge per kind: three side-by-side badges were wider than the detail
// panel and spilled out of it. Presentational only, same split as
// `WantedMenu`: the caller owns what each selection opens.
@ -8,12 +8,13 @@ import { Badge } from "@hive/shared/badge.js";
import { Dropdown, type DropdownOption } from "@hive/shared/dropdown.js";
import { LinkIcon } from "@hive/shared/icons.js";
export type LinkKind = "matrix" | "forge" | "github";
export type LinkKind = "matrix" | "forge" | "github" | "backend";
const OPTIONS: DropdownOption[] = [
{ value: "matrix", label: "matrix account" },
{ value: "forge", label: "forge account" },
{ value: "github", label: "github account" },
{ value: "backend", label: "API-key environment" },
];
export function LinkAccountMenu({
@ -40,7 +41,7 @@ export function LinkAccountMenu({
disabled={!hasHive}
title={
hasHive
? `link a matrix, forge or github account to ${agent}`
? `link a matrix, forge or github account, or set the API-key environment, for ${agent}`
: "no hive on record for this agent — nothing to link against"
}
/>

View file

@ -18,7 +18,7 @@ import { ConfirmDialog } from "../../ui/confirm-dialog/ConfirmDialog.js";
import { accountKindLabel } from "./account-kind.js";
import "./LinkedAccounts.css";
type AccountKind = "matrix" | "forgejo" | "github";
type AccountKind = "matrix" | "forgejo" | "github" | "backend";
// Mirrors `linked_accounts::LinkedAccount`.
interface LinkedAccount {
@ -38,6 +38,8 @@ function accountUrl(hive: string, agent: string, a: LinkedAccount): string {
return `${base}/forge-accounts/${encodeURIComponent(a.name)}`;
case "github":
return `${base}/github-account`;
case "backend":
return `${base}/backend-env`;
}
}

View file

@ -17,6 +17,7 @@ import { ConfirmDialog } from "../../ui/confirm-dialog/ConfirmDialog.js";
import { Dialog } from "../../ui/dialog/Dialog.js";
import { LinkMatrixAccountForm } from "../../pages/LinkMatrixAccountForm.js";
import { LinkForgeAccountForm } from "../../pages/LinkForgeAccountForm.js";
import { LinkBackendEnvForm } from "../../pages/LinkBackendEnvForm.js";
import { LinkGithubAccountForm } from "../../pages/LinkGithubAccountForm.js";
import type { AgentRow } from "../AgentTypes.js";
import type { LinkKind } from "../detail/LinkAccountMenu.js";
@ -96,6 +97,7 @@ export function useAgentActions(
const [matrixTarget, setMatrixTarget] = useState<AgentRow | null>(null);
const [forgeTarget, setForgeTarget] = useState<AgentRow | null>(null);
const [githubTarget, setGithubTarget] = useState<AgentRow | null>(null);
const [backendTarget, setBackendTarget] = useState<AgentRow | null>(null);
const [linkVersion, setLinkVersion] = useState(0);
const linkClosed = () => setLinkVersion((v) => v + 1);
@ -111,6 +113,10 @@ export function useAgentActions(
setGithubTarget(null);
linkClosed();
};
const closeBackend = () => {
setBackendTarget(null);
linkClosed();
};
// The one PUT every wanted-state selection ends at, whether or not it went
// through a `ConfirmDialog` first: PUT a new `wanted` declaration, track
@ -213,6 +219,20 @@ export function useAgentActions(
/>
) : null}
</Dialog>
<Dialog
open={backendTarget !== null}
onClose={closeBackend}
label="set the API-key environment"
plain
>
{backendTarget?.hive ? (
<LinkBackendEnvForm
hive={backendTarget.hive}
agent={backendTarget.name}
onClose={closeBackend}
/>
) : null}
</Dialog>
<ConfirmDialog
open={confirmTarget !== null}
label={confirmTarget ? CONFIRM_COPY[confirmTarget.state].label : ""}
@ -259,7 +279,8 @@ export function useAgentActions(
openLink: (row, kind) => {
if (kind === "matrix") setMatrixTarget(row);
else if (kind === "forge") setForgeTarget(row);
else setGithubTarget(row);
else if (kind === "github") setGithubTarget(row);
else setBackendTarget(row);
},
dialogs,
};