baa-conductor


baa-conductor / apps / status-api / src
im_wower  ·  2026-03-25

contracts.ts

 1import type { AutomationMode } from "../../../packages/db/src/index.js";
 2
 3export type StatusSnapshotSource = "conductor-api" | "empty" | "d1";
 4export type StatusApiRouteMethod = "GET";
 5
 6export interface StatusApiEnvironment {
 7  [key: string]: string | undefined;
 8}
 9
10export interface StatusSnapshot {
11  source: StatusSnapshotSource;
12  mode: AutomationMode;
13  leaderId: string | null;
14  leaderHost: string | null;
15  leaseTerm: number | null;
16  leaseExpiresAt: string | null;
17  leaseActive: boolean;
18  queueDepth: number;
19  activeRuns: number;
20  updatedAt: string;
21  observedAt: string;
22}
23
24export interface StatusSnapshotLoader {
25  loadSnapshot(): Promise<StatusSnapshot>;
26}
27
28export interface StatusApiRoute {
29  method: StatusApiRouteMethod;
30  path: string;
31  summary: string;
32  contentType: "application/json" | "text/html" | "text/plain";
33  aliases?: string[];
34}
35
36export interface StatusApiRequest {
37  method: string;
38  path: string;
39}
40
41export interface StatusApiResponse {
42  status: number;
43  headers: Record<string, string>;
44  body: string;
45}
46
47export interface StatusApiHandler {
48  routes: StatusApiRoute[];
49  handle(request: StatusApiRequest): Promise<StatusApiResponse>;
50}
51
52export function createEmptyStatusSnapshot(now: Date = new Date()): StatusSnapshot {
53  const observedAt = now.toISOString();
54
55  return {
56    source: "empty",
57    mode: "paused",
58    leaderId: null,
59    leaderHost: null,
60    leaseTerm: null,
61    leaseExpiresAt: null,
62    leaseActive: false,
63    queueDepth: 0,
64    activeRuns: 0,
65    updatedAt: observedAt,
66    observedAt
67  };
68}