/** * @license * Copyright 2026 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { Command } from "commander"; import type { RunRegistry } from "./RunRegistry"; export interface WebRequest { readonly method: string; readonly path: string; readonly query: URLSearchParams; readonly headers: Readonly>; readonly body: string; } export type WebResult = { readonly kind: "json"; readonly status: number; readonly body: unknown; } | { readonly kind: "file"; readonly path: string; readonly contentType: string; } | { readonly kind: "sse"; readonly runId: string; readonly afterSeq: number; }; export interface WebContext { readonly program: Command; readonly registry: RunRegistry; readonly token: string; readonly binaryName: string; /** Host values the server will answer to, lower-cased, without the port. */ readonly allowedHosts: ReadonlySet; /** * When this server process started. Reported by `/api/ping` so a page can * tell a restarted CLI from one that merely paused: the former answers again * but remembers none of the runs the page is showing. */ readonly startedAt: number; } /** * The host a `Host:` header names, without its port. * * An IPv6 literal is bracketed and full of colons, so splitting on the first * one yields `"["` — which matches nothing in the allow-list, and every API * request from `http://[::1]:8787/` was refused with a message naming a host * nobody typed. */ export declare function hostWithoutPort(header: string | undefined): string; export declare function handleWebRequest(request: WebRequest, ctx: WebContext): Promise;