import { type ReadOnlyRequestError } from './request-scope.js'; /** The header a host sets when it mounts a twin under a path (a served World's wire: * `///`), the reverse-proxy convention; with it the host sets * `x-forwarded-host` and `x-forwarded-proto` to where the World is reached. */ export declare const TWIN_PREFIX_HEADER = "x-forwarded-prefix"; /** Where this twin is reached for this request: the request's origin plus the path a host mounted * the twin under. A pack mints every live URL it hands back (an upload target, a file link, a * callback) from this, never from the bare origin, so the URL works behind a served World. */ export declare function twinPublicBase(request: Request): string; /** Where a World shows a hostname its twins answer (a Workers Custom Domain, an R2 public domain): the address a person * opens it at, from the World's sites template. `{host}` stands for the hostname as it is, where the host's names nest * (`http://{host}.--.localhost:`); `{site}` for the hostname as one DNS label, its dots as hyphens, * where one wildcard certificate covers the host's names (`https://{site}----.volterdev.com`). A World that * routes its sites to a browser sends the template on every request it forwards to a twin. */ export declare const TWIN_SITES_HEADER = "x-volter-world-sites"; /** The real host of the page whose hosted-site session owns this request, including a /_host/ request. */ export declare const TWIN_SITE_HEADER = "x-volter-world-site"; /** A hostname as one DNS label: its dots as hyphens (`www.volter.ai` is `www-volter-ai`). */ export declare const siteLabel: (hostname: string) => string; /** The address a sites template gives `hostname`, or null where the template is not one or the name makes no address * (a label over 63 characters). */ export declare function siteUrlOf(template: string, hostname: string, browser?: string): string | null; /** Where a page links a hostname the twin answers: the World's address for it when the World shows sites, else the * hostname itself (reached through the World's proxy, or the vendor). A pack's screen links a site from this, as it * mints its own URLs from twinPublicBase. */ export declare function twinSiteUrl(request: Request, hostname: string): string; /** A URL on the page's vendor: hosted sites keep it on the page's origin, with another of the vendor's hosts under * /_host/. The World checks that target's vendor and applies the page's session; a pack supplies only its own * vendor URLs. Without hosted-site headers (the local proxy or a path-mounted page), the URL is unchanged. */ export declare function twinVendorUrl(request: Request, vendorUrl: string): string; /** A twin's BYTE-STREAM door: a pack whose clients speak a TCP protocol (SMTP, the MySQL wire) serves * it over whatever carries the bytes — a local listener's socket, or a WebSocket to a hosted World. * The pack owns framing and protocol; the host owns the transport. `open` greets through the sink; * `data` hands the connection bytes in arrival order; `settled` resolves when every byte handed so * far has been answered; `close` is the peer going away. A connection whose work can fall behind its bytes (a live * ingest writing segments) says how many bytes wait in `backlog`, and a listener that can pause its transport does so * past a high-water mark until `settled` (serve-http.ts, `serveStream`). */ export type TwinStreamSink = { write(bytes: Uint8Array): void; end(): void; }; export type TwinStreamConnection = { data(chunk: Uint8Array): void; settled(): Promise; close(): void; backlog?(): number; }; export type TwinStream = (sink: TwinStreamSink, peer: string) => TwinStreamConnection; /** The request scopes a pack wrapped in `withRequestScopes` enforces, advertised on its `GET /twin` as * `requestScopes`: `read` — a request carrying `x-volter-read-only: 1` (request-scope.ts) has every * write it attempts refused at the kernel's write seam, whatever operation it names. A World's doors * forward a read-scope request that is not a GET only to a twin that advertises it. */ export declare const TWIN_REQUEST_SCOPES: readonly string[]; /** * THE READ SCOPE for a pack that writes its own fetch (the derived packs, the byte-wire packs): a * request carrying the read-only marker, or an instance mounted read-only, runs with the kernel's * write seam refusing its writes, and a * refused write answers `refuse` (the vendor's own read-only error; a generic 405 without one) — * whatever the handler made of the refusal. `GET /twin` advertises `requestScopes`. Everything else * passes through untouched; the wrapped fetch keeps its own properties (a derived fetch's `owners`). */ export declare function withRequestScopes Promise>(fetch: F, opts?: { readOnly?: boolean; refuse?: (request: Request, error: ReadOnlyRequestError) => Response | Promise; }): F; export type TwinFetchHandlerResult = { status: number; body: unknown; headers?: Record; }; /** The common handler request shape. Extra vendor fields ride `handlerOptions` (static, * per instance) and `extras` (derived per request); handlers ignore keys they don't * declare, so the union is safe to pass wholesale. */ export type TwinFetchHandlerRequest = { method: string; path: string; body: string; headers: Record; readOnly: boolean; occurredAt: string; root?: string; } & Record; export interface TwinFetchAdapterConfig { root?: string; readOnly?: boolean; /** The keyless GET /twin body — a value (stateful packs: statefulTwinManifest(...)) or * a thunk (generative packs build theirs around the scenario engine). */ manifest: unknown | (() => unknown); /** GET /twin/scenario body (thunk) — scenario-carrying packs only. */ scenarioStatus?: () => unknown; /** Per-request vendor extras (header threading: stripe-version, notion-version, …). */ extras?: (request: Request, url: URL) => Record; /** Static per-instance handler options (e.g. rateLimitPerSecond). */ handlerOptions?: Record; /** Extra response headers on every non-door reply (e.g. stripe's request-id, and * postmark's `connection: close` Bun-socket workaround — inert under workerd). */ responseHeaders?: Record; } export declare function createTwinFetchFromHandler(handler: (request: TwinFetchHandlerRequest) => TwinFetchHandlerResult | Promise, config: TwinFetchAdapterConfig): (request: Request) => Promise; /** A twin's answer at a World's place with its cookies kept to the twin: every cookie it sets is scoped to the twin's * base path there (`Path=/` and no Path become `Path=`, which RFC 6265's path-match gives the twin's root * `` and every path under it and no sibling; a path under the vendor's root, `Path=/x`, becomes `/x`), * so one twin's sign-in never reaches a sibling twin served from the same pages origin (architecture, "A page at a * World's place"). A `__Host-` cookie, which a browser takes only at `Path=/`, is left as set. An answer off a place, at * a prefix the World never sends (outside `/[A-Za-z0-9._~/-]*`, which twinPublicBase refuses too), or setting no cookie * is the answer as it is. */ export declare function placedCookies(request: Request, response: Response): Response;