/**
 * Request tracker — manages pending JSON-RPC requests with timeouts.
 *
 * Uses SvelteMap for reactive pending request tracking.
 *
 * @module
 */
import { type Deferred, type AsyncStatus } from '@fuzdev/fuz_util/async.js';
import { SvelteMap } from 'svelte/reactivity';
import { type JsonrpcErrorResponse, type JsonrpcRequestId, type JsonrpcResponseOrError } from '../http/jsonrpc.js';
/** ISO datetime string for request creation timestamps. */
type Datetime = string & {
    readonly __brand: 'Datetime';
};
export declare class RequestTrackerItem {
    readonly id: JsonrpcRequestId;
    readonly deferred: Deferred<JsonrpcResponseOrError>;
    readonly created: Datetime;
    status: AsyncStatus;
    timeout: NodeJS.Timeout | undefined;
    constructor(id: JsonrpcRequestId, deferred: Deferred<JsonrpcResponseOrError>, created: Datetime, status: AsyncStatus, timeout: NodeJS.Timeout | undefined);
}
/**
 * Reactive pending-request store with per-request timeouts. Used by transports
 * that don't delegate request/response correlation to a `WebsocketRpcConnection`.
 */
export declare class RequestTracker {
    readonly pending_requests: SvelteMap<JsonrpcRequestId, RequestTrackerItem>;
    readonly request_timeout_ms: number;
    constructor(request_timeout_ms?: number);
    /**
     * Track a new request keyed by `id`.
     *
     * @returns deferred resolved on response, or rejected via the timeout
     * @mutates this - inserts a `RequestTrackerItem` into `pending_requests`
     *   and arms a timeout that auto-rejects after `request_timeout_ms`;
     *   clears any prior timeout for the same id
     */
    track_request(id: JsonrpcRequestId): Deferred<JsonrpcResponseOrError>;
    /**
     * Resolve a pending request with its response.
     *
     * @mutates this - clears the timeout, marks status `'success'`,
     *   resolves the deferred, and removes the entry from `pending_requests`
     */
    resolve_request(id: JsonrpcRequestId, response: JsonrpcResponseOrError): void;
    /**
     * Reject a pending request with `error_message`.
     *
     * @mutates this - clears the timeout, marks status `'failure'`,
     *   rejects the deferred with a `ThrownJsonrpcError`, and removes the
     *   entry from `pending_requests`
     */
    reject_request(id: JsonrpcRequestId, error_message: JsonrpcErrorResponse): void;
    /**
     * Handles an incoming JSON-RPC message. Resolves or rejects the associated request.
     * Ignores notifications and unknown/invalid messages.
     */
    handle_message(message: any): void;
    /**
     * Cancel a pending request without rejecting its deferred — just
     * cleanup. The caller's promise stays unsettled; pair with an external
     * resolution if needed.
     *
     * @mutates this - clears the timeout and removes the entry from `pending_requests`
     */
    cancel_request(id: JsonrpcRequestId): void;
    /**
     * Cancel all pending requests.
     * @param reason - optional reason to include in rejection
     * @mutates this - clears every timeout, marks each status `'failure'`,
     *   rejects each deferred with `internal_error`, and empties `pending_requests`
     */
    cancel_all_requests(reason?: string): void;
}
export {};
//# sourceMappingURL=request_tracker.svelte.d.ts.map