ruth is created from a ruth archetype that runs sonnet
This commit is contained in:
parent
aff8cf629d
commit
5233259b3b
5 changed files with 236 additions and 115 deletions
|
|
@ -34,6 +34,14 @@ export interface Prefill {
|
|||
inference: InferenceDraft;
|
||||
}
|
||||
|
||||
/** The listed archetype `ref` names, or `undefined` when the list has none. */
|
||||
export function findArchetype(
|
||||
list: Archetype[],
|
||||
ref: { source: string; name: string },
|
||||
): Archetype | undefined {
|
||||
return list.find((a) => a.source === ref.source && a.name === ref.name);
|
||||
}
|
||||
|
||||
/** The select's value for `a`; unique across sources. */
|
||||
export function archetypeKey(a: Archetype): string {
|
||||
return `${a.source}/${a.name}`;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@
|
|||
// shared `ui/` form kit (`TextField`/`SelectField`/`Button`) rather than
|
||||
// page-scoped input/button chrome — see that kit's own comments for why.
|
||||
//
|
||||
// Permissions: checkboxes from `GET /api/permissions`, on the default set plus
|
||||
// `extraPermissions`; sent only when that differs from the default.
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
// Permissions: checkboxes from `GET /api/permissions`, on the default set or the
|
||||
// picked archetype's; sent only when that differs from the default. A caller can
|
||||
// open the form on an archetype with `initialArchetype`.
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import { Link } from "wouter-preact";
|
||||
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
||||
import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
|
||||
|
|
@ -52,13 +53,13 @@ import { SectionHeading } from "../ui/section-heading/SectionHeading.js";
|
|||
import { useSubmit } from "../ui/submit/useSubmit.js";
|
||||
import { MultiselectFilterOptions } from "../ui/multiselect-filter/MultiselectFilter.js";
|
||||
import {
|
||||
initialSelection,
|
||||
requestInternet,
|
||||
requestPermissions,
|
||||
togglePermission,
|
||||
} from "./CreateAgentPermissions.js";
|
||||
import {
|
||||
archetypeKey,
|
||||
findArchetype,
|
||||
prefill,
|
||||
requestArchetype,
|
||||
type ArchetypeList,
|
||||
|
|
@ -103,12 +104,12 @@ interface PermissionCatalogue {
|
|||
export function CreateAgentForm({
|
||||
onClose,
|
||||
initialName = "",
|
||||
extraPermissions = [],
|
||||
initialArchetype,
|
||||
}: {
|
||||
/** The name field's starting value, for a caller that suggests one. */
|
||||
initialName?: string;
|
||||
/** Permissions checked on top of the default set when the form opens. */
|
||||
extraPermissions?: string[];
|
||||
/** The archetype the form opens on, once the swarm lists it. */
|
||||
initialArchetype?: { source: string; name: string };
|
||||
/** Rendered as the form panel's own close button — this form always
|
||||
* mounts inside a `plain` `Dialog` (see `AgentsPage`), which no longer
|
||||
* floats its own. */
|
||||
|
|
@ -181,7 +182,7 @@ export function CreateAgentForm({
|
|||
}
|
||||
const data = (await r.json()) as PermissionCatalogue;
|
||||
setCatalogue(data);
|
||||
setSelected(initialSelection(data.all, data.default, extraPermissions));
|
||||
setSelected(data.default);
|
||||
})().catch((e: unknown) => setCatalogueError({ detail: String(e) }));
|
||||
}, []);
|
||||
|
||||
|
|
@ -211,6 +212,21 @@ export function CreateAgentForm({
|
|||
setInference(p.inference);
|
||||
}
|
||||
|
||||
// Opens on `initialArchetype` once the list and the permission catalogue are
|
||||
// both in, and only once, so a later pick of "none" stays.
|
||||
const seeded = useRef(false);
|
||||
useEffect(() => {
|
||||
if (seeded.current || !initialArchetype || !archetypes || !catalogue)
|
||||
return;
|
||||
seeded.current = true;
|
||||
const found = findArchetype(archetypes.archetypes, initialArchetype);
|
||||
if (found) pickArchetype(archetypeKey(found));
|
||||
}, [archetypes, catalogue]);
|
||||
const unlisted =
|
||||
initialArchetype !== undefined &&
|
||||
archetypes !== null &&
|
||||
findArchetype(archetypes.archetypes, initialArchetype) === undefined;
|
||||
|
||||
const hiveOptions: SelectOption[] = (hives ?? []).map((h) => ({
|
||||
value: h.name,
|
||||
label: h.name,
|
||||
|
|
@ -252,14 +268,6 @@ export function CreateAgentForm({
|
|||
setName("");
|
||||
setAgentsMd("");
|
||||
pickArchetype("");
|
||||
if (catalogue)
|
||||
setSelected(
|
||||
initialSelection(
|
||||
catalogue.all,
|
||||
catalogue.default,
|
||||
extraPermissions,
|
||||
),
|
||||
);
|
||||
},
|
||||
// The text's own refusal shows beside its box, so go back to it.
|
||||
onError: (problem) => {
|
||||
|
|
@ -376,6 +384,14 @@ export function CreateAgentForm({
|
|||
: "select a hive"
|
||||
}
|
||||
/>
|
||||
{unlisted && initialArchetype && (
|
||||
<Hint tone="warn" class="create-agent-field-error">
|
||||
The swarm does not list the {initialArchetype.name} archetype
|
||||
yet, so this creates a plain agent with the default
|
||||
permissions. The list refreshes every 10 minutes; reopen the
|
||||
form once it has {initialArchetype.name}.
|
||||
</Hint>
|
||||
)}
|
||||
{archetypes && archetypes.archetypes.length > 0 && (
|
||||
<>
|
||||
<ArchetypePicker
|
||||
|
|
|
|||
|
|
@ -23,22 +23,6 @@ export function requestPermissions(
|
|||
return same ? undefined : selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* The form's starting selection: `defaults` plus each of `extra` the
|
||||
* catalogue lists (`all`), so a name the controller does not know is not
|
||||
* sent.
|
||||
*/
|
||||
export function initialSelection(
|
||||
all: string[],
|
||||
defaults: string[],
|
||||
extra: string[],
|
||||
): string[] {
|
||||
return [
|
||||
...defaults,
|
||||
...extra.filter((p) => all.includes(p) && !defaults.includes(p)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The create request's internet field: `unrestricted_internet: true` while
|
||||
* the box is ticked, nothing otherwise, as the server writes `false` for it.
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
// <SetupAssistant> - the start page's first-time helper: a paperclip with a
|
||||
// speech bubble offering to set up an agent. It renders only while the swarm
|
||||
// has no `ruth` (see `ruthIsMissing`), and a click opens the create-agent
|
||||
// form with her name filled in and `manage_root_agent`, `logs` and
|
||||
// `metrics` checked on top of the default permissions (`RUTH_EXTRA_PERMISSIONS`); the form already selects
|
||||
// the only hive. No dismiss: once ruth exists it goes away.
|
||||
// form with her name filled in and the `ruth` archetype picked (`RUTH_ARCHETYPE`),
|
||||
// which fills in her permissions and model; the form already selects the only
|
||||
// hive. No dismiss: once ruth exists it goes away.
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
import { Dialog } from "../ui/dialog/Dialog.js";
|
||||
import {
|
||||
RUTH_EXTRA_PERMISSIONS,
|
||||
ruthIsMissing,
|
||||
} from "../shell/ruth-missing.js";
|
||||
import { RUTH_ARCHETYPE, ruthIsMissing } from "../shell/ruth-missing.js";
|
||||
import { CreateAgentForm } from "./CreateAgentForm.js";
|
||||
import "./SetupAssistant.css";
|
||||
|
||||
|
|
@ -76,7 +73,7 @@ export function SetupAssistant() {
|
|||
>
|
||||
<CreateAgentForm
|
||||
initialName="ruth"
|
||||
extraPermissions={RUTH_EXTRA_PERMISSIONS}
|
||||
initialArchetype={RUTH_ARCHETYPE}
|
||||
onClose={() => setOpen(false)}
|
||||
/>
|
||||
</Dialog>
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ export async function ruthIsMissing(fetchImpl: Fetch): Promise<boolean> {
|
|||
}
|
||||
}
|
||||
|
||||
/** What the setup assistant's create form checks on top of the default set:
|
||||
* ruth recovers the other agents, which takes `manage_root_agent`, and reads
|
||||
* the swarm's logs and metrics, which are off by default. swarm-controller
|
||||
* refuses `logs` and `metrics` (409, naming the hive) for a hive that does
|
||||
* not advertise `tolerant-permissions`; the form shows that error, and
|
||||
* unticking them creates ruth without. */
|
||||
export const RUTH_EXTRA_PERMISSIONS = ["manage_root_agent", "logs", "metrics"];
|
||||
/** The archetype the setup assistant's create form starts on. Its `meta`
|
||||
* gives ruth `manage_root_agent` (she recovers the other agents), `logs` and
|
||||
* `metrics`, and the model. swarm-controller refuses `logs` and `metrics`
|
||||
* (409, naming the hive) for a hive that does not advertise
|
||||
* `tolerant-permissions`; the form shows that error, and unticking them
|
||||
* creates ruth without. */
|
||||
export const RUTH_ARCHETYPE = { source: "hyperhive", name: "ruth" };
|
||||
|
|
|
|||
Loading…
Reference in a new issue