Files
archie/ui/src/bindings/binding-draft.ts
T
sam b9daa01b4b feat(webui): port the dashboard (Phases 3-5)
Every page from the deleted Preact dashboard, rebuilt in Vue 3 + shadcn-vue.
The navigation restructure landed earlier on this branch; this is the surfaces
behind it, and the two are now one app.

Dashboard, Tasks (list and detail), Configuration split six ways, Logs,
Inspector, Mappings, Bindings, Workflows, Skills, Curators, Channels, chat.

Components, not files: docs/prds/dashboard-port-brief.md requires one
component, one job, one file, with shared state in a module beside it. So a
page file composes and holds nothing, and a shape repeated across panes becomes
its own component (LogRow, PageHeader, PanelLoading, WorkflowBar).

Behaviour that had to survive, because each was a fix:

- Live activity's detail is clamped to one line with the payload on the title.
  Unclamped, one row made the dashboard 7,481px tall.
- Each health card takes its own height. Equalising left a mostly-empty box
  taking a quarter of the first screen once setup was done.
- Tasks: `tab`/`attempt` live in the query string and are written with
  router.replace, so a tab click adds no history entry and does not remount.
  The list's deep-link reveal honours prefers-reduced-motion.
- LOG_LEVELS is a wire contract (the server matches that CSV server-side), used
  unchanged by both log panes.
- The chat panel's Phase 5 list: a FAB that is the only toggle, a morph whose
  scale, radius and position interpolate together, no scrim, no close button,
  Escape returning focus to the launcher, Stop only while streaming.
- Unconfigured is not broken. A 501 on /api/version or the log stream renders
  what is true ("Not configured on this deployment") rather than blank, and a
  read-only Configuration says so instead of offering controls that cannot work.

Three things the port decided rather than carried:

- Button gains an `attention` variant and Badge the five status tones, in the
  project's own cva. The pill's dot did not come across: the Badge's shape is
  the affordance, and the same tone now covers a trend indicator.
- The icon module is not ported. Its name-to-glyph lookup is the pattern
  shadcn-vue's rules call out as wrong, so icons come from @lucide/vue at the
  call site. The five bespoke glyphs have no consumer yet and become components
  if a page draws them.
- The theme control left the topbar for /system/appearance, per the approved
  navigation design. ThemeToggle.vue and Placeholder.vue are deleted rather
  than orphaned: every route now resolves to a real page.

Also fixes the bundle freshness check failing on the first build after every
change. ui/dist is committed, so nothing ignores it and Tailwind's content
detection scanned it, making each build an input to the next.
2026-09-20 20:04:55 +10:00

133 lines
3.6 KiB
TypeScript

/**
* The bindings vocabulary: the wire shapes the daemon returns, the draft the
* editor form edits, and the status ramp the list renders. Pure, so it reads
* (and would test) without the page's fetch wiring -- the same split
* binding-editor.jsx had from bindings.jsx in the Preact build.
*/
/**
* A binding as GET /api/bindings returns it. Secret is never returned: the
* daemon strips it from every read, and a blank secret on update is its
* server-side "keep the current one".
*/
export interface Binding {
id: number;
name: string;
matcher?: { source?: string };
mapping_id?: number;
workflow?: string;
/** A pin is a complete owner/repo pair or not a pin at all. */
owner?: string;
repo?: string;
status?: string;
version?: number;
}
/** The fields of GET /api/mappings this page needs. */
export interface MappingOption {
id: number;
name: string;
}
/** One entry of GET /api/workflows' `definitions`. */
export interface WorkflowOption {
id: string;
name: string;
enabled?: boolean;
}
/** The Badge variants a binding status maps onto. */
export type StatusKind = "ok" | "warn" | "idle";
const STATUS_LABELS: Record<string, string> = {
draft: "draft",
pending_approval: "pending approval",
armed: "armed",
};
const STATUS_KINDS: Record<string, StatusKind> = {
draft: "idle",
pending_approval: "warn",
armed: "ok",
};
/** A status the daemon grows later renders as itself in the neutral kind,
* rather than as an unlabelled pill. */
export function statusLabel(status?: string): string {
if (!status) return "unknown";
return STATUS_LABELS[status] ?? status;
}
export function statusKind(status?: string): StatusKind {
return STATUS_KINDS[status ?? ""] ?? "idle";
}
/**
* The editor's field state. mappingId is the select's string value because a
* select's model is its option values; the store's mapping_id is a number.
*/
export interface BindingDraft {
id: number | null;
name: string;
source: string;
mappingId: string;
workflow: string;
owner: string;
repo: string;
secret: string;
}
export function emptyDraft(): BindingDraft {
return {
id: null,
name: "",
source: "",
mappingId: "",
workflow: "",
owner: "",
repo: "",
secret: "",
};
}
export function draftFromBinding(binding: Binding): BindingDraft {
return {
id: binding.id,
name: binding.name,
source: binding.matcher?.source || "",
mappingId: binding.mapping_id ? String(binding.mapping_id) : "",
workflow: binding.workflow || "",
owner: binding.owner || "",
repo: binding.repo || "",
// Deliberately blank: the secret is never sent to the browser, and an
// empty one on update keeps whatever the sender already signs with.
secret: "",
};
}
/** The body POST /api/bindings and PATCH /api/bindings/{id} both accept. A
* blank mapping is 0, which the store rejects -- a binding with no mapping
* could never be dispatched. */
export function bindingPayload(draft: BindingDraft): Record<string, unknown> {
return {
name: draft.name,
matcher: { source: draft.source },
mapping_id: Number(draft.mappingId) || 0,
workflow: draft.workflow,
owner: draft.owner,
repo: draft.repo,
secret: draft.secret,
};
}
/** The repo pin a row shows, or an em dash when the binding takes the
* single-configured-repo default. */
export function repoPin(binding: Binding): string {
return binding.owner && binding.repo ? `${binding.owner}/${binding.repo}` : "—";
}
/** The matcher source a row shows: the path segment senders POST to. */
export function matcherSource(binding: Binding): string {
return binding.matcher?.source || "—";
}