// — sets an agent's API key. The key goes to the agent's // backend secrets in the swarm secret store as `ANTHROPIC_API_KEY=` // (`PUT …/backend-secrets`); no route hands it back, so the box starts empty // and a save replaces whatever is stored. The advanced form // (`LinkBackendEnvForm`) is where the rest of the backend environment lives. import { useState } from "preact/hooks"; import { Panel } from "../ui/panel/Panel.js"; import { TextField } from "../ui/text-field/TextField.js"; import { Button } from "../ui/button/Button.js"; import { FormStack } from "../ui/form-stack/FormStack.js"; import { FormResult } from "../ui/submit/FormResult.js"; import { Hint } from "../ui/hint/Hint.js"; import { useSubmit } from "../ui/submit/useSubmit.js"; import { apiKeySecrets, backendSecretsUrl, checkApiKey, } from "../agent/detail/account-api.js"; export function LinkApiKeyForm({ hive, agent, onSaved, onClose, }: { hive: string; agent: string; /** Called after a save, so the row can show the key as stored. */ onSaved?: () => void; onClose?: () => void; }) { const [key, setKey] = useState(""); const { state, submitting, run, fail } = useSubmit(); function save(e: Event) { e.preventDefault(); const problem = checkApiKey(key); if (problem !== null) { fail({ detail: problem }); return; } void run( () => fetch(backendSecretsUrl(hive, agent), { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify({ env: apiKeySecrets(key) }), }), { // The store holds the key; nothing here needs it. onDone: () => { setKey(""); onSaved?.(); }, }, ); } return (

Bills {agent} through the API instead of a Claude login.

Stored in the swarm secret store and never shown again; a save replaces the stored key. The agent loads it at its next restart. ( <> stored the API key for {agent} )} failed="failed to store the API key" />
); }