import * as http from "node:http"; import { type ChildProcess } from "node:child_process"; import type { Router } from "./router.js"; export declare const STDOUT_BUFFER_CAP: number; export type JobEvent = "progress" | "done"; export interface SpawnJob { id: string; meta: TMeta; proc: ChildProcess; stdoutBuffer: string; stderrBuffer: string; exitCode: number | null; done: boolean; subscribers: Set<(event: JobEvent, data: unknown) => void>; pastEvents: Array<{ event: JobEvent; data: unknown; }>; } export interface StartSpawnJobOptions { command: string; args: string[]; meta: TMeta; timeoutMs: number; jobs: Map>; } export declare function isLocalhost(req: http.IncomingMessage): boolean; export declare function trimRing(buf: string, cap: number): string; /** * Spawn `command` with `args`, wire stdout/stderr to per-line "progress" * events, register the job in `jobs`, and emit "done" on exit / error / * timeout. Returns the registered job synchronously so the HTTP handler * can reply with `{ jobId }` immediately. */ export declare function startSpawnJob(opts: StartSpawnJobOptions): SpawnJob; /** * Mount `GET /:jobId/stream` on `router`. The handler enforces the * localhost gate, replays buffered events, then subscribes the SSE response * to live "progress"/"done" events until disconnect. */ export declare function mountSpawnStreamRoute(router: Router, prefix: string, jobs: Map>): void;