import type { PayloadMiddleware } from "./payload-middleware.js";
export interface WithToolResultSerializationOptions {
    /**
     * Optional registry the middleware adds each pending tool task to,
     * deleting it on completion. Mirrors `params.pendingToolTasks` from
     * the chain — used by the chain to wait for tool deliveries to drain
     * before completing the run.
     */
    pendingTasks?: Set<Promise<void>>;
    /**
     * Optional error notification. Production swallows tool-result
     * delivery errors so one failed delivery doesn't stop the run; this
     * lets callers observe them for diagnostics.
     */
    onError?: (err: unknown) => void;
}
/**
 * Returns a PayloadMiddleware that serializes `tool` kind deliveries.
 * Other kinds pass through unchanged.
 *
 * Each call to the wrapped handler returns IMMEDIATELY with a synthetic
 * "queued" delivery; the actual inner-handler invocation runs on the
 * promise chain. Callers that need to wait for the chain to drain
 * should observe `opts.pendingTasks`.
 *
 * NOTE: this is a deliberate design choice matching production
 * behaviour. Tool result delivery is fire-and-forget from the runner's
 * point of view; the chain semantics are "queue the delivery, don't
 * block the agent loop on it". If a future caller wants synchronous
 * delivery, they should NOT use this middleware.
 */
export declare function withToolResultSerialization(opts?: WithToolResultSerializationOptions): PayloadMiddleware;
/**
 * Test helper: wait for the chain to drain. NOT exported in production
 * paths — only useful when verifying serialization behaviour. Returns a
 * promise that resolves when ALL queued tool deliveries have settled.
 *
 * Implementation: the chain promise itself is the drain condition. We
 * peek at it via the closure by exposing the middleware factory.
 */
export declare function createToolResultSerializationProbe(): {
    middleware: PayloadMiddleware;
    drain: () => Promise<void>;
    pendingCount: () => number;
};
