import { routes } from "@/router"; import { hiddenRoutes, type CapabilitySections } from "./capabilities"; import { buildNav, flattenRoutes, type NavNode, type NavRouteNode, type NavSpec, } from "./nav-tree"; export type { NavEntry, NavGroup, NavLink, NavNode } from "./nav-tree"; const table = flattenRoutes(routes as NavRouteNode[]); // Primary destinations: work, the organisation that owns it, and the instance // it runs on. Personal security and preferences live in the account menu. const specs: NavSpec[] = [ { kind: "link", path: "/" }, { kind: "link", path: "/tasks" }, { kind: "link", path: "/workflows" }, { kind: "link", path: "/events" }, { kind: "link", path: "/org" }, { kind: "link", path: "/settings" }, ]; // The Organisation sidebar, grouped by what is being configured. Every page // here is an organisation-owned resource. const orgSpecs: NavSpec[] = [ { kind: "link", path: "/org", label: "Overview" }, { kind: "group", label: "Organisation", sections: [ { label: "People & access", paths: ["/org/members", "/org/agents", "/org/workspaces", "/org/policies"], }, { label: "Connections & models", paths: ["/org/connections", "/org/repositories", "/org/credential-bindings", "/org/models", "/org/soul"], }, { label: "Automation", paths: ["/org/schedules", "/org/playbooks"], }, ], }, ]; // The Instance sidebar: infrastructure and instance limits an administrator // controls. Organisation resources are not listed here. const settings: NavSpec = { kind: "group", label: "Instance", sections: [ { label: "Models & prompts", paths: [ "/settings/models", "/settings/skills", "/settings/curators", "/settings/scheduling-policy", ], }, { label: "Connections & channels", paths: [ "/settings/channels", "/settings/tools", "/settings/extensions", "/settings/plugins", "/settings/secret-engines", ], }, { label: "Runtime", paths: [ "/settings/task-execution", "/settings/container-runtime", "/settings/agent-profiles", "/settings/harness", "/settings/status", ], }, { paths: ["/settings/authentication", "/settings/appearance", "/settings/history"] }, ], }; // Reached from the Dashboard's Logs button and the account menu, and by // Jump to, but not from the bar. const unlisted = ["/logs", "/account"]; /** hiddenPaths lists the routes this composition cannot back. */ export function hiddenPaths(sections: CapabilitySections | null): string[] { return hiddenRoutes(sections, table); } export function navTree(hidden: string[] = []): NavNode[] { return buildNav(table, specs, hidden).tree; } /** navEntries lists every destination Jump to can reach. */ export function navEntries(hidden: string[] = []) { return buildNav(table, [...specs, ...orgSpecs, settings], hidden, unlisted) .jumpTargets; } /** orgNav is the Organisation sidebar; its first section labels its items. */ export function orgNav(hidden: string[] = []) { return buildNav(table, orgSpecs, hidden).jumpTargets; } /** settingsNav is the Instance sidebar; each section labels its first item. */ export function settingsNav(hidden: string[] = []) { const nodes = buildNav(table, [settings], hidden).tree; const group = nodes.find((node) => node.kind === "group"); return group?.kind === "group" ? group.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; }