swarm-ui: make agent creation a five-step dialog with a fixed header and footer
The create dialog was one tall form that scrolled as a whole, so its header and button moved out of view. It is now steps you go through in order: identity, instructions (AGENTS.md in a box of its own), permissions, resources and inference, then a summary of what will be sent and what the agent creation queues, where create is. The header, step tabs and footer stay put and only the step's own fields scroll. A refused AGENTS.md text sends the dialog back to its step. The request is unchanged.
This commit is contained in:
parent
f0a80c9812
commit
339da0aebe
7 changed files with 662 additions and 246 deletions
101
frontend/packages/swarm-ui/test/create-agent-steps.test.mjs
Normal file
101
frontend/packages/swarm-ui/test/create-agent-steps.test.mjs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
// The create-agent dialog's steps: order, what gates next, and the summary.
|
||||
// Run by `npm test` with Node's type stripping.
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import {
|
||||
nameProblem,
|
||||
nextStep,
|
||||
previousStep,
|
||||
STEPS,
|
||||
stepProblem,
|
||||
summaryRows,
|
||||
} from "../src/pages/CreateAgentSteps.ts";
|
||||
|
||||
const ready = {
|
||||
name: "ruth",
|
||||
hive: "h1",
|
||||
permissionsReady: true,
|
||||
inferenceProblem: null,
|
||||
};
|
||||
|
||||
test("the steps run in order and stop at both ends", () => {
|
||||
assert.deepEqual(STEPS, [
|
||||
"identity",
|
||||
"instructions",
|
||||
"permissions",
|
||||
"resources",
|
||||
"summary",
|
||||
]);
|
||||
assert.equal(nextStep("identity"), "instructions");
|
||||
assert.equal(nextStep("resources"), "summary");
|
||||
assert.equal(nextStep("summary"), "summary");
|
||||
assert.equal(previousStep("summary"), "resources");
|
||||
assert.equal(previousStep("identity"), "identity");
|
||||
});
|
||||
|
||||
test("a name is 1-63 lowercase letters, digits and hyphens", () => {
|
||||
assert.equal(nameProblem("ruth-2"), null);
|
||||
assert.equal(nameProblem("a".repeat(63)), null);
|
||||
assert.notEqual(nameProblem(""), null);
|
||||
assert.notEqual(nameProblem("a".repeat(64)), null);
|
||||
assert.notEqual(nameProblem("Ruth"), null);
|
||||
assert.notEqual(nameProblem("ru th"), null);
|
||||
});
|
||||
|
||||
test("identity needs a valid name and a hive before next", () => {
|
||||
assert.equal(stepProblem("identity", ready), null);
|
||||
assert.notEqual(stepProblem("identity", { ...ready, name: "" }), null);
|
||||
assert.notEqual(stepProblem("identity", { ...ready, name: "No Way" }), null);
|
||||
assert.equal(stepProblem("identity", { ...ready, hive: "" }), "pick a hive");
|
||||
});
|
||||
|
||||
test("permissions waits for the list, resources for a valid inference", () => {
|
||||
assert.notEqual(
|
||||
stepProblem("permissions", { ...ready, permissionsReady: false }),
|
||||
null,
|
||||
);
|
||||
assert.equal(stepProblem("permissions", ready), null);
|
||||
assert.equal(
|
||||
stepProblem("resources", { ...ready, inferenceProblem: "bad model" }),
|
||||
"bad model",
|
||||
);
|
||||
assert.equal(stepProblem("instructions", { ...ready, name: "" }), null);
|
||||
});
|
||||
|
||||
test("the summary lists what is sent and what stays at its default", () => {
|
||||
const rows = (over) =>
|
||||
Object.fromEntries(
|
||||
summaryRows({
|
||||
name: "ruth",
|
||||
hive: "h1",
|
||||
archetype: undefined,
|
||||
permissions: undefined,
|
||||
caps: {},
|
||||
inference: {},
|
||||
agentsMd: "",
|
||||
...over,
|
||||
}).map((r) => [r.label, r.value]),
|
||||
);
|
||||
const plain = rows({});
|
||||
assert.equal(plain.name, "ruth");
|
||||
assert.equal(plain.archetype, "none: a custom agent");
|
||||
assert.equal(plain.permissions, "the default set");
|
||||
assert.equal(plain["resource caps"], "none set");
|
||||
assert.equal(plain.inference, "none set");
|
||||
assert.equal(plain.instructions, "none");
|
||||
|
||||
const set = rows({
|
||||
archetype: "reviewer",
|
||||
permissions: ["meta", "inbox"],
|
||||
caps: { cpu_quota: "200%", memory_max: "2G" },
|
||||
inference: { model: "opus", subagent_models: ["haiku", "sonnet"] },
|
||||
agentsMd: " Be brief.\n",
|
||||
});
|
||||
assert.equal(set.archetype, "reviewer");
|
||||
assert.equal(set.permissions, "meta, inbox");
|
||||
assert.equal(set["resource caps"], "cpu quota 200%; memory max 2G");
|
||||
assert.equal(set.inference, "model opus; subagent models haiku, sonnet");
|
||||
assert.equal(set.instructions, "AGENTS.md, 2 words");
|
||||
assert.equal(rows({ permissions: [] }).permissions, "none");
|
||||
assert.equal(rows({ agentsMd: "x" }).instructions, "AGENTS.md, 1 word");
|
||||
});
|
||||
Loading…
Reference in a new issue