import type { CapturedRequest } from '../provider/schema.ts'; import { BodyStore } from './eviction.ts'; /** The slice of CDP `Network.requestWillBeSent` the engine reads. Kept * structural — not devtools-protocol's full event type — so a transport * pinned to a different devtools-protocol version still satisfies it. */ export interface RequestWillBeSentLike { requestId: string; request: { method: string; url: string; headers: Record; postData?: string; }; } /** The slice of CDP `Network.responseReceived` the engine reads. */ export interface ResponseReceivedLike { requestId: string; response: { status: number; mimeType: string; encodedDataLength: number; headers: Record; }; } /** Drop HTTP/2 pseudo-headers (`:authority`, `:method`, `:path`, `:scheme`, * `:status`) from a CDP header map. Chrome emits them on HTTP/2 requests, * but they're a transport-layer abstraction with no place in our domain: * the URL already carries authority/path/scheme, the request object carries * method, and Node's `fetch` (undici) throws on any header starting with * `:`. Stripping at capture time keeps every downstream consumer * (`get_request`, draft, replay, proof) clean by construction. */ export declare function stripPseudoHeaders(headers: Record): Record; /** True when the URL's path names a static asset (by file extension; query and * hash are ignored, so `chunk.js?v=1` still counts). The capture engine drops * these up front — they never carry JSON/HTML a recipe matches. */ export declare function isStaticAsset(url: string): boolean; /** True when a response Content-Type is a static asset (scripts/styles/fonts/ * images/media). Parameters (`; charset=…`) and case are ignored. */ export declare function isStaticAssetMime(mimeType: string | undefined): boolean; export interface CaptureSession { captureId: string; requests: Map; bodies: BodyStore; stop: () => Promise; } /** Public knobs a transport accepts; mapped into `CaptureEngineOptions`. */ export interface StartCaptureOptions { maxBodyBytes?: number; } export interface CaptureEngineOptions { maxBodyBytes?: number; /** Fetch a finished response body. Transport-specific: the agent calls * `Network.getResponseBody` on the page binding, the app routes the * command through its Popcorn session. */ fetchBody: (requestId: string) => Promise<{ body: string; base64Encoded: boolean; }>; } /** The engine state plus the handlers a transport drives. A transport feeds * raw CDP events into these and exposes `captureId`/`requests`/`bodies` to * its caller. */ export interface CaptureEngine { captureId: string; requests: Map; bodies: BodyStore; onRequestWillBeSent: (p: RequestWillBeSentLike) => void; mergeRequestHeaders: (requestId: string, extra: Record) => void; onResponseReceived: (p: ResponseReceivedLike) => void; mergeResponseHeaders: (requestId: string, extra: Record) => void; onLoadingFinished: (requestId: string) => Promise; } export declare function createCaptureEngine(opts: CaptureEngineOptions): CaptureEngine;