Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: restructure the agent card into status, terminal, subagents and settings, with badge controls for internet, permissions and allowed domains

This commit is contained in:
iris 2026-11-03 23:47:44 +01:00 • committed by mara
commit 5e23734667

View file

@ -24,6 +24,7 @@ import { 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 { BadgePopover } from "../../ui/badge-popover/BadgePopover.js";
import { Button } from "../../ui/button/Button.js";
import { CheckboxField } from "../../ui/checkbox-field/CheckboxField.js";
import { Dialog } from "../../ui/dialog/Dialog.js";
@ -31,10 +32,11 @@ import { Panel } from "../../ui/panel/Panel.js";
import { TextField } from "../../ui/text-field/TextField.js";
import {
ALLOWED_DOMAINS_URL,
allowedSummary,
entriesFor,
entryBody,
entryGroups,
type AllowedDomain,
type EntryGroup,
} from "./allowed-domains.js";
import "./AgentLimits.css";
@ -42,6 +44,24 @@ interface Listing {
entries: AllowedDomain[];
}
// What each source's badge says, and what its list holds.
const GROUP_LABEL: Record<EntryGroup["source"], string> = {
"swarm-wide": "swarm-wide",
own: "this agent",
automatic: "automatic",
};
function groupHelp(source: EntryGroup["source"], agent: string): string {
switch (source) {
case "swarm-wide":
return "Names every agent in the swarm may reach through its hive's proxy.";
case "own":
return `Names only ${agent} may reach through its hive's proxy. Remove one to stop allowing it.`;
case "automatic":
return `Kept from ${agent}'s backend environment or a linked account; change or unlink that to change them.`;
}
}
export function AllowedDomains({ agent }: { agent: string }) {
const [entries, setEntries] = useState<AllowedDomain[] | null>(null);
const [error, setError] = useState<ProblemDetails | null>(null);
@ -116,40 +136,38 @@ export function AllowedDomains({ agent }: { agent: string }) {
return (
<div class="ui-agent-limits">
{errorPanel}
<Badge label="allowed domains" value={allowedSummary(shown)} />
{shown.length > 0 ? (
<ul class="ui-agent-limits-list">
{shown.map((e) => (
<li key={`${e.agent ?? "*"}/${e.domain}/${e.derived === true}`}>
<Badge
label={
e.derived === true
? "automatic"
: e.agent === undefined
? "swarm-wide"
: agent
}
value={e.domain}
title={
e.derived === true
? "kept from this agent's backend environment or a linked account; change or unlink that to change it"
: undefined
}
/>{" "}
{e.derived === true ? null : (
<Badge
variant="quiet"
value="remove"
title={`stop allowing ${e.domain} for ${
e.agent === undefined ? "every agent" : agent
}`}
onClick={() => void remove(e)}
/>
)}
</li>
))}
</ul>
{shown.length === 0 ? (
<Badge label="allowed domains" value="none added" />
) : null}
{entryGroups(shown).map((g) => (
<BadgePopover
key={g.source}
label={GROUP_LABEL[g.source]}
value={g.entries.length}
title={groupHelp(g.source, agent)}
popoverLabel={`${agent} allowed domains, ${GROUP_LABEL[g.source]}`}
>
<p class="ui-badge-popover-help">{groupHelp(g.source, agent)}</p>
<ul class="ui-badge-popover-list">
{g.entries.map((e) => (
<li key={`${e.agent ?? "*"}/${e.domain}`}>
<Badge value={e.domain} />{" "}
{e.derived === true ? null : (
<Badge
variant="quiet"
value="remove"
title={`stop allowing ${e.domain} for ${
e.agent === undefined ? "every agent" : agent
}`}
disabled={busy}
onClick={() => void remove(e)}
/>
)}
</li>
))}
</ul>
</BadgePopover>
))}
<Badge
variant="quiet"
value="add"