The board and graph controls of the agents view share one toolbar that sits at the end of the controls row, so the filters keep the start and the view switches line up across widths. E2E at 1920, 1366 and 390 in Chromium and Firefox. 🎯 Fix: 95 % 💥 Break: 3 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % 🏆 Score: 92 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
152 lines
6.4 KiB
JavaScript
152 lines
6.4 KiB
JavaScript
async function act(action, label, payload) {
|
|
ui.busy = true;
|
|
const result = await sendJson(`/api/board/${action}`, payload);
|
|
ui.busy = false;
|
|
if (result.data && result.data.runs) {
|
|
toast(`${label}: ${result.data.ok ? "done" : "failed"}`, runLines(result.data), result.data.ok);
|
|
} else {
|
|
toast(`${label}: failed`, [`${result.status} ${result.text}`.trim()], false);
|
|
}
|
|
await load();
|
|
return result.ok && result.data && result.data.ok;
|
|
}
|
|
|
|
const actionOf = (action) => ACTIONS.find(([id]) => id === action);
|
|
|
|
const nightAgents = () => [...new Map(state.claims.filter((claim) => claim.agent && claim.agent !== HUMAN && claim.session !== "-").map((claim) => [claim.session, claim.agent]))]
|
|
.sort(([one, a], [two, b]) => a.localeCompare(b) || one.localeCompare(two));
|
|
|
|
async function confirmAct(action, agents) {
|
|
const [, label, question] = actionOf(action);
|
|
const names = new Map(nightAgents());
|
|
if (!window.confirm(agents.length ? question.replace("all agents", agents.map((sid) => names.get(sid) || sid).join(", ")) : question)) {
|
|
return;
|
|
}
|
|
const chosen = agents.length ? {agents} : {};
|
|
const signed = await signedProof("/api/board/sign", {action, ...chosen}, label);
|
|
if (signed) {
|
|
await act(action, label, {proof: signed.proof, ...chosen});
|
|
}
|
|
}
|
|
|
|
function choice(name, options, picked) {
|
|
return h("div", {class: "classes", role: "radiogroup", "aria-label": "Class"}, options.map(([id, label]) => h("label", {class: "check"},
|
|
h("input", {type: "radio", name, value: id, checked: id === picked}), label)));
|
|
}
|
|
|
|
const picked = (group) => group.querySelector("input:checked").value;
|
|
|
|
function actionButton(action, cls, name, agents) {
|
|
const [, label, , hint] = actionOf(action);
|
|
return h("button", {type: "button", class: cls, ...named(label, hint), on: {click: () => confirmAct(action, agents())}}, name ? icon(name) : null, label);
|
|
}
|
|
|
|
function nightChosen() {
|
|
const agents = nightAgents().map(([sid]) => sid);
|
|
const on = agents.filter((sid) => !ui.nightOff.has(sid));
|
|
return on.length === agents.length ? [] : on;
|
|
}
|
|
|
|
function syncPicks(toolbar) {
|
|
const boxes = [...toolbar.picks.querySelectorAll("input[data-session]")];
|
|
boxes.forEach((box) => {
|
|
box.checked = !ui.nightOff.has(box.dataset.session);
|
|
});
|
|
toolbar.picks.querySelector("input[data-all]").checked = boxes.every((box) => box.checked);
|
|
const none = boxes.length > 0 && boxes.every((box) => !box.checked);
|
|
toolbar.nightButtons.forEach((button) => {
|
|
button.disabled = none;
|
|
});
|
|
}
|
|
|
|
function pickAgents(toolbar, sids, on) {
|
|
sids.forEach((sid) => (on ? ui.nightOff.delete(sid) : ui.nightOff.add(sid)));
|
|
syncPicks(toolbar);
|
|
}
|
|
|
|
function drawPicks(toolbar) {
|
|
const agents = nightAgents();
|
|
const box = (label, attrs, sids) => h("label", {class: "check"}, h("input", {type: "checkbox", ...attrs, on: {change: (event) => pickAgents(toolbar, sids, event.target.checked)}}), label);
|
|
toolbar.picks.replaceChildren(box("All", {"data-all": true}, agents.map(([sid]) => sid)), ...agents.map(([sid, name]) => box(name, {"data-session": sid}, [sid])));
|
|
syncPicks(toolbar);
|
|
}
|
|
|
|
let spotDom = null;
|
|
|
|
function openSpot(open) {
|
|
ui.spot = open;
|
|
spotDom.panel.hidden = !open;
|
|
spotDom.toggle.setAttribute("aria-expanded", String(open));
|
|
window.requestAnimationFrame(refresh3d);
|
|
if (open) {
|
|
spotDom.speak.text.focus();
|
|
}
|
|
}
|
|
|
|
function radioSpot() {
|
|
const {bar, speak, grid} = radioBody(true);
|
|
const panel = h("section", {class: "card radio-spot", id: "radio-spot", "data-panel": "radio", "aria-label": "Radio", hidden: !ui.spot}, bar.root, grid);
|
|
const toggle = document.getElementById("radio-open");
|
|
toggle.setAttribute("aria-expanded", String(ui.spot));
|
|
toggle.addEventListener("click", () => openSpot(!ui.spot));
|
|
document.getElementById("spot-host").replaceChildren(panel);
|
|
spotDom = {panel, toggle, speak};
|
|
}
|
|
|
|
function openRadio() {
|
|
openSpot(true);
|
|
}
|
|
|
|
function drawSpot() {
|
|
drawBars();
|
|
drawSpeak();
|
|
}
|
|
|
|
function agentsToolbar() {
|
|
const mode = h("span", {});
|
|
const picks = h("div", {class: "night-picks", role: "group", "aria-label": "Agents"});
|
|
const nightButtons = ACTIONS.slice(1).map(([id]) => actionButton(id, "btn small", null, nightChosen));
|
|
const night = h("details", {class: "menu"}, h("summary", named("Day/Night"), icon("bi-moon-stars"), caret()), h("div", {class: "menu-box end"}, mode, picks,
|
|
h("div", {class: "actions"}, nightButtons)));
|
|
const bar = h("div", {class: "toolbar", role: "toolbar", "aria-label": "Controls"}, iconBtn("bi-sort-down", "Priority", "btn small", openAgentOrder, "Priority: agent order in the hierarchy"), night, statusMenu());
|
|
return {bar, mode, picks, nightButtons, agents: ""};
|
|
}
|
|
|
|
function lookBox(id, label, on, run) {
|
|
const state = Object.hasOwn(PRESENCE, id) ? {class: "check presence", "data-state": id, "data-tone": PRESENCE[id][2]} : {class: "check"};
|
|
return h("label", state, h("input", {type: "checkbox", checked: on, "data-look": id, on: {change: (event) => run(event.target.checked)}}), state["data-state"] ? icon(PRESENCE[id][1], "glyph") : null, label);
|
|
}
|
|
|
|
function setLook(change) {
|
|
change();
|
|
keep(STORE.status, {hidden: [...look.hidden], faces: look.faces});
|
|
render(false);
|
|
drawAgent();
|
|
}
|
|
|
|
function statusMenu() {
|
|
return h("details", {class: "menu"}, h("summary", named("Status", "Status: which agent states show their symbol, and faces in 3D"), icon("bi-activity"), caret()),
|
|
h("div", {class: "menu-box end"}, h("h3", {}, "Agent states"),
|
|
Object.entries(PRESENCE).map(([id, [label]]) => lookBox(id, label, !look.hidden.has(id), (on) => setLook(() => (on ? look.hidden.delete(id) : look.hidden.add(id))))),
|
|
h("h3", {}, "3D"),
|
|
lookBox("faces", "Faces in 3D", look.faces, (on) => setLook(() => {
|
|
look.faces = on;
|
|
}))));
|
|
}
|
|
|
|
function drawToolbar() {
|
|
drawSpot();
|
|
const toolbar = graphDom && graphDom.toolbar;
|
|
if (!toolbar) {
|
|
return;
|
|
}
|
|
const [mode, tone] = NIGHT[state.night] || [state.night, "neutral"];
|
|
const alone = Object.values(state.night_parts).filter((part) => part !== "day").length;
|
|
toolbar.mode.replaceChildren(pill(mode, tone), alone ? pill(`${alone} alone`, "warn") : null);
|
|
const agents = JSON.stringify(nightAgents());
|
|
if (agents !== toolbar.agents) {
|
|
toolbar.agents = agents;
|
|
drawPicks(toolbar);
|
|
}
|
|
}
|