/**
 * Copyright: (c) Myia SAS 2026.
 * This file and its contents are licensed under the AGPLv3 License.
 * Please see the LICENSE file at the root of this repository
 */
import type { Request as PwRequest } from 'playwright';
import type { NetworkRecord, NetworkSource } from '../../domain/trace-event-recorder/model/network-trace-schema';
export interface PendingRecord extends NetworkRecord {
    /** Internal — the Playwright Request the coalescer keyed on. */
    __request: PwRequest;
}
export declare class NetworkCoalescer {
    private readonly idsByRequest;
    private readonly pending;
    private nextId;
    /** Test-only escape hatch. */
    size(): number;
    has(request: PwRequest): boolean;
    /**
     * Resolve (and assign on first use) the per-test id we attribute
     * to this request. Stable across every event Playwright fires for
     * the same Request instance.
     */
    idFor(request: PwRequest): string;
    /**
     * Register a new (non-redirect) request. The seed `NetworkRecord`
     * carries everything that is known at issue time. The session
     * fills in `t` / `statementSeq` / step path / page url before
     * calling — keeping the coalescer free of clock/recorder deps.
     */
    begin(seed: PendingRecord): void;
    /**
     * Apply a partial update keyed by the request's `requestId`. Used
     * by the session as `response` / `requestfinished` /
     * `requestfailed` events arrive. Silently ignores updates for
     * unknown ids — happens when `urlFilter` dropped the request at
     * `request` time but a later event still fires.
     */
    update(requestId: string, patch: Partial<NetworkRecord>): void;
    /**
     * Mark an exchange as complete and pop it out for emission. The
     * caller writes the record to disk and decides what to do with
     * any buffered body. Returns `undefined` for unknown ids.
     */
    finalize(requestId: string): NetworkRecord | undefined;
    /**
     * At teardown: emit anything still pending so the trace file
     * reflects requests that never finished (e.g. a fetch that
     * outlived the test and was cancelled by `context.close()`).
     * Empties the map.
     */
    drain(): NetworkRecord[];
}
export declare function deriveSource(request: PwRequest, contextSource: NetworkSource): NetworkSource;
