import { IncomingMessage, ServerResponse } from 'node:http'; /** * HTTP delivery primitives for the app-UI shell — `GET /apps/:appId/ui` and * `GET /apps/:appId/ui/assets/:file` on the daemon (http-server.ts), and the * same shapes under `agentproto app serve` (cli/src/app-serve.ts). One * module so both hosts negotiate, validate and cache identically: * * - `accept-encoding` negotiation (`br` preferred, then `gzip`, else * identity) with `vary: accept-encoding` on every response. * - A strong `etag` (sha256 of the exact bytes served) answered with 304 * on a matching `if-none-match`. * - An LRU of encoded representations keyed by a caller-chosen key and * invalidated by a caller-chosen stamp (path + mtime + size for files), * so neither the digest nor the compression reruns until the file * changes. * * Deliberately scoped to the shell: SSE, MCP and every API route keep their * own framing and never go through here. */ type ContentCoding = "br" | "gzip" | "identity"; /** Pick the response coding from an `accept-encoding` header: `br` when * acceptable, then `gzip`, else identity. q-values are honoured only as * acceptable (`q>0`) vs refused (`q=0`) — the preference order is ours, not * the client's. A `*` entry covers codings the header doesn't name. */ declare function negotiateContentEncoding(header: string | string[] | undefined): ContentCoding; /** Strong entity tag over `body` (sha256, base64url). `variant`, when set, * is appended so two representations of the same bytes that carry * different response headers (e.g. with/without frame headers) never * validate each other's cache entry. */ declare function strongEtag(body: Buffer | string, variant?: string): string; /** `if-none-match` evaluation (RFC 9110 §13.1.2): `*` or any listed tag * equal to `etag` under weak comparison. */ declare function ifNoneMatchHits(header: string | string[] | undefined, etag: string): boolean; /** Content types the app-UI routes serve, by lowercase extension. */ declare const APP_UI_MIME_BY_EXT: Readonly>; /** Content type for an extension (with or without the leading dot). */ declare function appUiContentType(ext: string): string; /** Whether a content type is worth compressing — text-ish only; woff2/png * and friends are already compressed. */ declare function isCompressibleContentType(contentType: string): boolean; /** `:file` segment of the assets route: a flat name from `[A-Za-z0-9._-]`, * not starting with `.` (so no `.`/`..`, no dotfiles), no separators. */ declare function isValidAppUiAssetName(file: string): boolean; /** Assets route cache policy — Vite emits content-hashed file names. */ declare const IMMUTABLE_CACHE_CONTROL = "public, max-age=31536000, immutable"; /** One servable body, its strong etag, and its encodings (computed lazily, * memoized — a representation that is never requested as gzip never pays * for it). */ interface EncodedRepresentation { readonly etag: string; readonly compressible: boolean; body(coding: ContentCoding): Buffer; } declare function createEncodedRepresentation(identity: Buffer, opts: { compressible: boolean; etag?: string; }): EncodedRepresentation; /** Small LRU of representations. `stamp` is whatever identifies the source * version (e.g. `${mtimeMs}:${size}`); a stamp mismatch rebuilds. Bounded * because some keys fold in request-derived input (the injected base URL). */ interface RepresentationCache { get(key: string, stamp: string, build: () => Promise | EncodedRepresentation): Promise; readonly size: number; } declare function createRepresentationCache(maxEntries?: number): RepresentationCache; /** Write `rep` to `res` with `headers` (content-type, cache-control, frame * headers — whatever the route decided), adding `etag`, `vary: * accept-encoding`, `content-encoding` and `content-length`. A matching * `if-none-match` answers 304 with the same headers and no body, so a * revalidation refreshes the stored headers exactly as a 200 would. */ declare function sendRepresentation(req: IncomingMessage, res: ServerResponse, rep: EncodedRepresentation, headers: Record): void; export { APP_UI_MIME_BY_EXT, type ContentCoding, type EncodedRepresentation, IMMUTABLE_CACHE_CONTROL, type RepresentationCache, appUiContentType, createEncodedRepresentation, createRepresentationCache, ifNoneMatchHits, isCompressibleContentType, isValidAppUiAssetName, negotiateContentEncoding, sendRepresentation, strongEtag };