import http from "http"; import type { ExportedItem, ServedExportedItem } from "../types.js"; import { type CheckpointEdit } from "../../runtime/state/checkpointPatch/index.js"; import type { ServedInvocationOutcome, RunUsage } from "../../runtime/invocationUsage.js"; import type { InvocationOptions } from "../../runtime/invocationOptions.js"; import type { Logger } from "../../logger.js"; /** PUBLIC config type (re-exported from `agency-lang/serve`) — kept * byte-compatible with the pre-seam contract: raw `ExportedItem`s and a * `respondToInterrupts` returning `Promise`. Host apps that import * this type keep type-checking. The adapters run on the internal * `ServedHandlerConfig` below; `createServeHandler` builds that from a * discovered module. */ export type HandlerConfig = { exports: ExportedItem[]; logger: Logger; hasInterrupts: (data: unknown) => boolean; respondToInterrupts: (interrupts: unknown[], responses: unknown[]) => Promise; }; /** INTERNAL adapter config: the served contract the HTTP adapter actually runs * on — usage-bearing `ServedExportedItem`s and a `respondToInterrupts` that * returns a `ServedInvocationOutcome`. Not part of the public surface. */ type ServedHandlerConfig = { exports: ServedExportedItem[]; logger: Logger; hasInterrupts: (data: unknown) => boolean; respondToInterrupts: (interrupts: unknown[], responses: unknown[], invocation?: InvocationOptions, edits?: CheckpointEdit[]) => Promise>; /** Whether `/resume` accepts `edits` in its body. Unset means no. */ allowEdits?: boolean; }; export type HttpConfig = ServedHandlerConfig & { port: number; apiKey?: string; /** Interface to bind to. Default "127.0.0.1" (loopback only). */ host?: string; /** * Allowed Host: header values (DNS-rebinding defense). If unset, defaults * are derived from `host`: loopback binds get an allowlist of loopback * names. Non-loopback binds skip Host validation by default (the strict * API key requirement mitigates DNS rebinding there); pass an explicit * array to lock the server down to specific hostnames. */ allowedHosts?: string[]; }; export type RouteResult = { status: number; body: unknown; /** Per-invocation usage for the serve cost seam, present on every * post-execution outcome (success/interrupt/402/failure/cancel) and absent * on pre-execution results (/list, 404, validation 400). Read in-process by * the host (statelog); not part of the standalone HTTP body. */ usage?: RunUsage; /** The run's effective root trace id. Present on the same post-execution * outcomes as `usage` (absent on /list, 404, validation 400). Lets a host * correlate a call to its trace even when it did not pre-supply an id. */ traceId?: string; }; export declare function createHttpHandler(config: ServedHandlerConfig): (method: string, path: string, body: unknown, invocation?: InvocationOptions) => Promise; export declare function startHttpServer(config: HttpConfig): http.Server; export { exitOnShutdownSignal } from "../shutdown.js";