/** * DashboardServer — WebSocket event broadcaster for real-time run monitoring. * * Manages HTTP serving, WebSocket upgrades, client tracking, event broadcasting, * and static file serving for the built React dashboard app. Consumes * LifecycleEvent objects via an EventListener-compatible handler registered * with EventBus.on(). Supports multi-run history and a `/ws/push` producer * endpoint for cross-process event streaming. * */ import type { EventListener, LifecycleEvent } from "../output/events.ts"; /** WebSocket data payload used to distinguish consumer vs producer sockets. */ type WsData = { type: "consumer" | "producer"; }; type ServerLike = { port?: number | undefined; stop(): void; }; type ServerLikeUpgradeTarget = { upgrade(req: Request, opts: { data: WsData; }): boolean; }; type ServerSocketLike = { data: WsData; readyState: number; send(data: string): void; close(): void; }; type ServerLikeWebsocketHandlers = { open(ws: ServerSocketLike): void; message(ws: ServerSocketLike, msg: string | Buffer): void; close(ws: ServerSocketLike): void; }; type ServerLikeOptions = { port: number; hostname: string; fetch: (req: Request, server: ServerLikeUpgradeTarget) => Response | Promise | undefined; websocket: ServerLikeWebsocketHandlers; }; type ServeLike = (opts: ServerLikeOptions) => ServerLike | Promise; /** Testability seam for injecting a custom `serve` implementation. */ export type DashboardServerDeps = { serve: ServeLike; }; /** Configuration options for the dashboard server. */ export type DashboardServerOptions = { /** Port to listen on. Default: 9090. */ port: number; /** Hostname to bind. Default: "127.0.0.1" (localhost only). */ hostname: string; /** * Path to pre-built static files (React app dist/). * Set to null to disable static serving. */ staticDir: string | null; /** Maximum number of completed runs to retain. Default: 10. */ maxHistory: number; }; /** A single recorded run with its events. */ export type RunRecord = { runId: string; events: LifecycleEvent[]; startedAt: string; finishedAt?: string | undefined; }; /** Summary of a run for the /api/runs listing. */ export type RunSummary = { id: string; mode: string; startedAt: string; finishedAt?: string | undefined; hasFailures?: boolean | undefined; }; /** * HTTP + WebSocket server that broadcasts LifecycleEvent objects to connected * browser clients. Register `server.listener` with `EventBus.on()` to stream * run telemetry in real time. * * Supports multi-run history via `/api/runs` and cross-process event push * via `/ws/push`. * * ```ts * const dashboard = new DashboardServer({ port: 9090 }) * await dashboard.start() * const unsubscribe = eventBus.on(dashboard.listener) * ``` */ export declare class DashboardServer { #private; constructor(opts?: Partial, deps?: Partial); /** EventListener-compatible handler. Register with EventBus.on(). */ listener: EventListener; /** Start the HTTP/WebSocket server. Resolves when the server is listening. */ start(): Promise; /** The effective bound port (useful when configured with `port: 0`). */ get port(): number; /** Number of currently connected WebSocket consumer clients. */ get clientCount(): number; /** Number of currently connected WebSocket producer clients. */ get producerCount(): number; /** Completed run history (most recent last). */ get runs(): RunRecord[]; /** The most recently started in-progress run, if any. */ get currentRun(): RunRecord | null; /** Gracefully shut down the server and close all connections. */ shutdown(): Promise; /** * Override point for subclasses to handle additional routes. * Return a Response to handle the request, or null to fall through * to the default routing. */ protected handleExtraRoutes(_url: URL, _req: Request): Response | null; } export {}; //# sourceMappingURL=server.d.ts.map