ruth is created from a ruth archetype that runs sonnet
This commit is contained in:
parent
aff8cf629d
commit
5233259b3b
1 changed files with 236 additions and 115 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue