/**
 * RetryHandler - Automatic retry logic with exponential backoff and credential/provider fallback.
 *
 * Handles retryable errors (overloaded, rate limit, server errors) by:
 * 1. Trying alternate credentials for the same provider
 * 2. Falling back to other providers via FallbackResolver
 * 3. Exponential backoff with configurable max retries
 *
 * Context overflow errors are NOT handled here (see compaction).
 */
import type { Agent } from "@nerf/pi-agent-core";
import type { AssistantMessage, Model } from "@nerf/pi-ai";
import type { FallbackResolver } from "./fallback-resolver.js";
import type { ModelRegistry } from "./model-registry.js";
import type { SettingsManager } from "./settings-manager.js";
import type { AgentSessionEvent } from "./agent-session.js";
/** Dependencies injected from AgentSession into RetryHandler */
export interface RetryHandlerDeps {
    readonly agent: Agent;
    readonly settingsManager: SettingsManager;
    readonly modelRegistry: ModelRegistry;
    readonly fallbackResolver: FallbackResolver;
    getModel: () => Model<any> | undefined;
    getSessionId: () => string;
    emit: (event: AgentSessionEvent) => void;
    /** Called when the retry handler switches to a fallback model */
    onModelChange: (model: Model<any>) => void;
}
export declare class RetryHandler {
    private readonly _deps;
    private _retryAbortController;
    private _retryAttempt;
    private _retryPromise;
    private _retryResolve;
    constructor(_deps: RetryHandlerDeps);
    /** Current retry attempt (0 if not retrying) */
    get retryAttempt(): number;
    /** Whether auto-retry is currently in progress */
    get isRetrying(): boolean;
    /** Whether auto-retry is enabled */
    get autoRetryEnabled(): boolean;
    /** Toggle auto-retry setting */
    setAutoRetryEnabled(enabled: boolean): void;
    /**
     * Create a retry promise synchronously for agent_end events.
     * Must be called synchronously from the agent event handler before
     * any async processing, so that waitForRetry() doesn't miss in-flight retries.
     */
    createRetryPromiseForAgentEnd(messages: Array<{
        role: string;
    } & Record<string, any>>): void;
    /**
     * Handle a successful assistant response by resetting retry state.
     * Call this when an assistant message completes without error.
     */
    handleSuccessfulResponse(): void;
    /**
     * Check if an error is retryable (overloaded, rate limit, server errors).
     * Context overflow errors are NOT retryable (handled by compaction instead).
     */
    isRetryableError(message: AssistantMessage): boolean;
    /**
     * Handle retryable errors with exponential backoff.
     * When multiple credentials are available, marks the failing credential
     * as backed off and retries immediately with the next one.
     * @returns true if retry was initiated, false if max retries exceeded or disabled
     */
    handleRetryableError(message: AssistantMessage): Promise<boolean>;
    /** Cancel in-progress retry */
    abortRetry(): void;
    /**
     * Wait for any in-progress retry to complete.
     * Returns immediately if no retry is in progress.
     */
    waitForRetry(): Promise<void>;
    /** Resolve the pending retry promise */
    resolveRetry(): void;
    private _resolveRetry;
    private _findLastAssistantInMessages;
    /**
     * Classify an error message into a usage-limit error type for credential backoff.
     */
    private _classifyErrorType;
    /** Remove the last assistant error message from agent state */
    private _removeLastAssistantError;
}
//# sourceMappingURL=retry-handler.d.ts.map