import type { IncomingMessage, ServerResponse } from "node:http"; import type { PinnedDirectory } from "./observer.js"; import type { LibraryHistory } from "./observer-library.js"; import { buildServeSecurityHeaders, hostAllowed, parsePublicOrigin, type ServeMode } from "./serve-http.js"; import type { ExposureErrorCode } from "./serve-exposure.js"; import { verifyRun } from "./run.js"; export declare const SERVE_SCHEMA = "humanish.serve-result.v1"; export { buildServeSecurityHeaders, hostAllowed, parsePublicOrigin }; export type { ServeMode }; export type ServeErrorCode = "HUMANISH_INVALID_PORT" | "HUMANISH_SERVE_PORT_IN_USE" | "HUMANISH_SERVE_TUNNEL_NOT_FOUND" | "HUMANISH_SERVE_TUNNEL_START_FAILED" | "HUMANISH_RUN_NOT_FOUND" | "HUMANISH_SERVE_RUN_NOT_SHAREABLE" | ExposureErrorCode; export interface ServeResult { schema: typeof SERVE_SCHEMA; ok: boolean; cwd: string; mode: ServeMode; safe: boolean; host: "127.0.0.1"; port?: number; url?: string; publicUrl?: string; tunnel?: { provider: "ngrok"; url: string; }; oauth?: { provider: "google"; allowEmails: string[]; allowDomains: string[]; }; runsListed: number; shareReadyCount?: number; entryRunId?: string; opened?: boolean; openCommand?: string; warnings: string[]; error?: { code: ServeErrorCode; message: string; }; } export interface ServeControlPlane { startRun?(request: { labId: string; dryRun: boolean; }): Promise<{ accepted: boolean; runId?: string; }>; } export interface ShareSafetyAdmission { admit(runId: string): Promise; } export declare function createShareSafetyAdmission(cwd: string, options?: { verifyImpl?: typeof verifyRun; ttlMs?: number; now?: () => number; }): ShareSafetyAdmission; export interface ServeRequestHandlerOptions { proofRoot: PinnedDirectory; safe: boolean; admit: (runId: string) => Promise; hostAllowlist: ReadonlySet; entryRunId?: string; renderLibrary: (history: LibraryHistory) => string; controlPlane?: ServeControlPlane; } export declare function createServeRequestHandler(options: ServeRequestHandlerOptions): (request: IncomingMessage, response: ServerResponse) => Promise; export interface ServeLibraryOptions { port: number; safe: boolean; expose: boolean; edgeAuthed: boolean; publicOrigin?: string; entryRunId?: string; controlPlane?: ServeControlPlane; verifyImpl?: typeof verifyRun; now?: () => number; } export interface ServeLibraryServer { url: string; port: number; mode: ServeMode; runsListed: number; shareReadyCount?: number; entryRunId?: string; addPublicOrigin(origin: string): void; close(): Promise; } export type ServeLibraryStart = { ok: true; server: ServeLibraryServer; } | { ok: false; error: { code: ServeErrorCode; message: string; }; }; export declare function serveObserverLibrary(cwdInput: string, options: ServeLibraryOptions): Promise;