/** * Tiny HTTP API that serves widget-shaped JSON for the Cortex dashboard. * Built on `node:http` for the same reasons as the webhook receiver — * small surface, no framework dep, easy to keep aligned with the MCP * tool context. * * Routing model: each URL prefix lives in its own file under `routes/`. * Every route handler has the same shape: `handle(req, res, ctx)` that * returns `true` when the URL was matched (success or 4xx/5xx alike), * `false` to fall through to the next handler. The dispatcher below * iterates the route list; the first to return `true` wins. If none * match, the dispatcher sends 404. * * Want to add an endpoint? Find the right file under `routes/` (or * create a new one — keep one file per URL prefix), then list it in * `ROUTES` below. The single-file dispatcher means you can't forget to * wire a handler — TypeScript will tell you if the import is missing. * * Security posture: binds to `127.0.0.1` by default (see ADR-015). CORS * is enabled only for localhost and chrome-extension origins; production * deployments terminate TLS in front. */ import type { Logger } from "@onenomad/przm-cortex-core"; import type { SourceAdapter } from "@onenomad/przm-cortex-core"; import type { WidgetContext } from "./types.js"; import type { HeartbeatWriter } from "../heartbeat.js"; import type { ReloadResult } from "../hot-reload.js"; import { TaxonomyCache } from "../taxonomy-cache.js"; export interface DashboardApiOptions extends WidgetContext { host?: string; port: number; logger: Logger; /** * Live heartbeat writer. The API exposes its snapshot via * `/api/status` so the dashboard's Status page can render uptime, * memory health, and per-adapter sync state without re-reading the * file from disk. */ heartbeat?: HeartbeatWriter; /** * Live adapter registry so the dashboard can trigger a one-off sync * from the Adapters page. Keyed by adapter id. Omit to disable the * /api/adapters/:id/sync endpoint (returns 503). */ adapters?: Record; /** * Hot-reload hook — rebuild LLM router + adapter registry + * scheduler from the live config file. Write endpoints call this * after a successful mutation so toggles/schedule/wizard saves * take effect without a container restart. */ reload?: () => Promise; /** * Path to the `dashboard.yaml` template. Re-read on every `/api/layout` * request so users can edit and refresh without bouncing the server. * If omitted, `/api/layout` returns the built-in delivery preset. */ layoutPath?: string; /** * Live per-workspace taxonomy cache. When present, the MCP console * uses it to resolve the CURRENTLY active workspace's taxonomy on * every invoke — instead of the process-wide bootstrap taxonomy * that was loaded once at startup. Without this, the console * returns stale projects when the user switches workspaces without * restarting cortex. */ taxonomyCache?: TaxonomyCache; /** * ADR-019 Phase 1 — SQLite cache for the priorities widget. When * provided, requests to `/api/widgets/priorities` are served from * cache on hit, computed on miss with the result written back. * Optional: tests pass `undefined` to exercise the registry without * dragging the cache-sqlite package (and its `node:sqlite` import) * into the vite/vitest transform graph. */ cache?: import("@onenomad/przm-cortex-cache-sqlite").CacheStorage; } export interface DashboardApi { start(): Promise; stop(): Promise; boundPort(): number | undefined; routes(): ReadonlyArray; } export declare function createDashboardApi(opts: DashboardApiOptions): DashboardApi; //# sourceMappingURL=server.d.ts.map