Files
archie/ui/src/lib/nav.ts
T
sam 02720c8e81 feat(controlplane): runtime administration over the State Store's gRPC server
The Web UI and messaging channels now read and write Archie's runtime
settings through one versioned, audited control-plane API hosted on the
State Store's existing gRPC server: catalog, query, command, watch. Each
feature owns its resource, validation and commands; storage only writes
versions and audit records.

Workflows move with it. Definitions become portable YAML compiled through
a closed, typed step registry and stored as a control-plane resource, so
the yaegi interpretation paths (internal/gate, wfeval, wfextract,
gateeval, gateextract, skillbuild) are deleted rather than carried.

The UI process reads definitions as data: the JSON projection lives in
internal/domain/workflow/task so a dashboard decodes the stored
collection without linking the workflow engine, which cmd/archie-ui's
deletion gate forbids. Shipped definitions ride the catalog descriptor
rather than a bespoke REST route, keeping the API to its four operations.

archie-messaging gains -state-store-target/-state-store-token and reads
channel settings from the database, failing closed when the State Store
is unreachable: the database is authoritative for those settings.
2026-09-21 08:17:42 +10:00

109 lines
3.1 KiB
TypeScript

import { routes } from "@/router";
export interface NavEntry {
path: string;
label: string;
description: string;
section?: string;
dividerBefore?: string;
soon?: boolean;
}
export interface NavLink {
kind: "link";
entry: NavEntry;
}
export interface NavGroup {
kind: "group";
label: string;
items: NavEntry[];
}
export type NavNode = NavLink | NavGroup;
interface RouteMeta {
label?: string;
description?: string;
section?: string;
nav?: boolean;
navPath?: string;
soon?: boolean;
}
const table = routes as Array<{ path: string; meta?: RouteMeta }>;
// The group owns the context, so the items inside it are named for what they
// are rather than what they belong to. Order is the reading order of the menu.
interface GroupSpec {
label: string;
paths: string[];
dividerBefore?: { path: string; label: string };
}
const groups: GroupSpec[] = [
{ label: "Work", paths: ["/tasks", "/workflows", "/channels", "/logs"] },
{ label: "Agent", paths: ["/skills", "/curators"] },
{ label: "Events", paths: ["/captures", "/mappings", "/bindings"] },
{
label: "System",
paths: [
"/system/status",
"/system/appearance",
"/system/tasks",
"/system/models",
"/system/repos",
"/system/identities",
"/system/advanced",
],
dividerBefore: { path: "/system/tasks", label: "Settings" },
},
];
function entryFor(path: string): NavEntry {
const route = table.find((r) => r.path === path);
if (!route) throw new Error(`nav references ${path}, which is not a route`);
return {
path,
label: route.meta?.label ?? path,
description: route.meta?.description ?? "",
section: route.meta?.section,
soon: route.meta?.soon,
};
}
/**
* navTree returns the bar, with routes the serving composition cannot back
* removed. A group whose every child is hidden is dropped; a group left with
* one child stays a group, so the bar has the same shape on every deployment.
*/
export function navTree(hidden: string[] = []): NavNode[] {
const visible = (e: NavEntry) => !hidden.includes(e.path);
const nodes: NavNode[] = [{ kind: "link", entry: entryFor("/") }];
for (const group of groups) {
const items = group.paths.map(entryFor).filter(visible);
const divided = items.map((item) => ({
...item,
dividerBefore: item.path === group.dividerBefore?.path ? group.dividerBefore.label : undefined,
}));
if (divided.length > 0) nodes.push({ kind: "group", label: group.label, items: divided });
}
return nodes;
}
/** navEntries flattens the tree to the destinations it can reach. */
export function navEntries(hidden: string[] = []): NavEntry[] {
return navTree(hidden).flatMap((node) => (node.kind === "link" ? [node.entry] : node.items));
}
/**
* activeNavPath maps the current route onto the nav entry that should read as
* current, so /tasks/42 keeps Tasks lit rather than lighting nothing.
*/
export function activeNavPath(path: string): string {
const route = table.find((r) => r.path === path);
const navPath = route?.meta?.navPath;
if (typeof navPath === "string") return navPath;
return path;
}