import type { AddressInfo } from "node:net"; import type { Duplex } from "node:stream"; import { type Gateway } from "../gateway/Gateway.js"; import type { TlsListener } from "./TlsListener.js"; import type { TcpHostRelay } from "../http/TcpHostRelay.js"; /** * The challenge a missing or wrong tenant key is answered with: the scheme * names the header the key travels in, so a 401 says what it wants. */ export declare const TENANT_KEY_CHALLENGE = "AgentSafe-Tenant-Key"; export interface GatewayHttpServerOptions { /** * A bearer token the metrics route requires; open when null, which is the * local default. A hosted gateway's status and metrics answer only this * token, the operator's, and are not there at all without one. */ readonly metricsToken?: string | null; /** * Answers `healthz` and `readyz` for a request whose host no gateway serves: * a platform probes a pod by its address, not by any tenant's name. Without * it such a request is refused with 421 like any other. */ readonly probe?: { readonly ready: () => boolean; }; /** * Terminate TLS here, with the executor's listener (TLS 1.3, or 1.2 with * AEAD ciphers only): the hosted fleet's edge is a layer-4 load balancer * and nothing else. Every response then carries HSTS, this listener's * once, and a relayed upstream's own is dropped. */ readonly tls?: TlsListener | null; /** * The page a host no tenant has answers at `/`, when it is this hostname: * a hosted fleet's apex names its operator. Both are read per request, so * a reload changes them in place; null serves nothing. */ readonly apex?: { readonly hostname: () => string | null; readonly page: () => string | null; }; /** Optional, fixed internal broker transport; independent of HTTP upstream tenancy. */ readonly tcpRelay?: TcpHostRelay; } /** HSTS for a listener that terminates TLS: a year, every subdomain. */ export declare const HSTS = "max-age=31536000; includeSubDomains"; /** * Which gateway answers a request, by the host it was addressed to. One * listener can front many gateways this way, each with its own upstream, * key, tenant and mode: the hosted shape, where every governed endpoint is * a host name and none is a separate implementation. `null` refuses the * host with 421. */ export type GatewaySelector = (hostname: string | null) => Gateway | null; /** * The interception listener. Every request is either the gateway's own * (under `/_agentsafe`), passed through unchanged, or governed: the body is * read in full under the configured bound and handed to the gateway with the * method, path, query and headers, and what comes back is written as it is. * A refusal the listener makes itself is a status and a code, never a * message from the request, with `agentsafe-execution: NOT_FORWARDED`. */ export declare class GatewayHttpServer { private readonly options; private readonly server; private readonly select; constructor(gateway: Gateway | GatewaySelector, options?: GatewayHttpServerOptions); listen(port: number, host: string): Promise; /** * Hands the listener a connection it did not accept itself: the transparent * interceptor's, already terminated where TLS was spoken. The stream is read * as any accepted socket is, and closed with the rest on `close`. */ accept(connection: Duplex): void; /** Presents the current certificate and key to new connections; open ones keep theirs. */ rotateTls(): void; /** Stops accepting, lets requests in flight finish for a grace period, then closes what is left. */ close(graceMs?: number): Promise; private handle; /** The host a request was addressed to, lower-cased and without a port; null when it named none. */ private static hostnameOf; private own; /** * A host no gateway serves: the operator's apex page at `/` when it is the * apex, a probe of the process itself, or 421. */ private unserved; /** The operator's token, or the route is not there (no token) or refused (another one). */ private requireOperator; /** Whether the request presents exactly this bearer token, compared in constant time. */ private static bearerIs; /** The resume token the caller presents, from its header only; null when absent or repeated. */ private static resumeTokenOf; /** The whole body under a bound; declared or streamed, the bound is the bound. */ private static readBody; /** * An acceptance run's endpoints: answered only by a gateway that serves * runs, and only for the operator token, never the tenant's key or an * agent's credential. Every body is JSON; a run's id travels in it, never * in a path a log would keep. */ private acceptance; /** Header names lower-cased, repeated values joined as Node joins them, `set-cookie` aside. */ private static headersOf; private write; private static reply; } //# sourceMappingURL=GatewayHttpServer.d.ts.map