import { StallTimeoutError } from "./errors.js";
import type { StreamSession } from "./session.js";
/**
 * Detects when a stream has stalled (no chunks received within timeout).
 *
 * Uses setTimeout-reset: timer is armed on start() and reset on each chunk.
 * If no chunk arrives within maxIdleTimeMs, fires a StallTimeoutError via waitForStall().
 *
 * Automatically subscribes to session events:
 * - "chunk" resets the timer
 * - "retry" restarts the timer for the new attempt
 * - "session:complete", "session:error", "session:abort" stop the monitor
 *
 * @example
 * ```typescript
 * const monitor = new IdleMonitor({ session, maxIdleTimeMs: 30000 });
 * monitor.start();
 * // Later: await Promise.race([iterator.next(), monitor.waitForStall()])
 * ```
 */
export interface IdleMonitorOptions {
    session: StreamSession;
    maxIdleTimeMs: number;
    onStall?: (error: StallTimeoutError) => void;
}
export declare class IdleMonitor {
    private readonly session;
    private readonly maxIdleTimeMs;
    private readonly onStallCallback?;
    private timer;
    private stallError;
    private stallCallbacks;
    private subscribed;
    constructor(options: IdleMonitorOptions);
    /**
     * Start the idle monitor. Arms the timer and subscribes to session events.
     */
    start(): void;
    /**
     * Stop the idle monitor. Clears the timer.
     *
     * Event subscriptions are intentionally not removed: the IdleMonitor and
     * StreamSession share the same lifecycle (both created per execute() call),
     * so there's no leak. Keeping subscriptions allows the monitor to restart
     * on retry without re-subscribing.
     */
    stop(): void;
    /**
     * Get the stall error if one has been detected.
     */
    getStallError(): StallTimeoutError | null;
    /**
     * Returns a promise that rejects when a stall is detected.
     */
    waitForStall(): Promise<never>;
    private subscribeToEvents;
    private handleChunk;
    private handleRetry;
    private handleSessionEnd;
    private armTimer;
    private fireStall;
}
//# sourceMappingURL=idle-monitor.d.ts.map