export { createRequestContext }; export { REQUEST_CONTEXT }; export type { RequestContext, ResponseAbortSource }; import type { AbortError } from '../Abort.js'; declare const REQUEST_CONTEXT: unique symbol; type ResponseAbortSource = { /** Abort the whole telefunc response with Abort semantics. Fires exactly once. */ abort: (abortValue?: unknown) => void; /** Register a callback fired when the response aborts. Fires exactly once. */ onAbort: (cb: (abortError: AbortError) => void) => void; /** Promise rejected with the Abort error once the response aborts. */ errorPromise: Promise; }; /** Internal per-request state. */ type RequestContext = { /** The current Web Request for this telefunc execution. */ request: Request; /** The POST request's AbortSignal. */ abortSignal: AbortSignal; /** AbortSignal that fires when all channels, streams, and pumps are done (same timing as onClose). */ signal: AbortSignal; /** Response-wide abort source used by returned values and response transports. */ responseAbort: ResponseAbortSource; /** Fires when the telefunction throws (or has already thrown) at the top level. */ onTopLevelError: (cb: () => void) => void; /** @internal Called by the framework after executeTelefunction catches a top-level throw. */ markTopLevelError: () => void; /** Register a callback that fires when the request lifecycle ends for any reason * (response sent, stream complete, or client disconnect). Fires exactly once. */ onClose: (cb: () => void) => void; /** Mark the response as complete. Fires onClose callbacks. * Gated by trackPending: if pending items exist, defers until all complete. */ markComplete: () => void; /** Register a pending item (channel, stream pump, inline stream). * Returns a completion callback. markComplete is deferred until all pending items complete. */ trackPending: () => () => void; }; /** Create a RequestContext and wire the abort signal to markComplete. */ declare function createRequestContext(request: Request): RequestContext;