import { A as AgentSDKError } from '../errors-CmVvczxZ.js';
import { E as ErrorCode } from '../errors-C-so0M4t.js';

/**
 * @witqq/agent-sdk/chat/errors
 *
 * Flat error taxonomy with unified ErrorCode enum, ChatError class,
 * pattern-matching classifier, retry strategies with exponential backoff.
 * Extends the existing AgentSDKError from @witqq/agent-sdk.
 */

/** Options for constructing a ChatError */
interface ChatErrorOptions {
    /** Machine-readable error code */
    code: ErrorCode;
    /** Whether this error is retryable (default: false) */
    retryable?: boolean;
    /** Retry delay hint in milliseconds */
    retryAfter?: number;
    /** Original cause, if wrapping another error */
    cause?: unknown;
}
/** Unified error class for all chat SDK errors */
declare class ChatError extends AgentSDKError {
    readonly code: ErrorCode;
    readonly retryable: boolean;
    readonly retryAfter?: number;
    readonly timestamp: string;
    constructor(message: string, options: ChatErrorOptions);
}
/**
 * Classify an unknown thrown value into a ChatError with the appropriate code.
 * Pattern-matches against common error shapes:
 * - Already a ChatError → returned as-is
 * - Fetch/network errors (ECONNREFUSED, ETIMEDOUT, etc.)
 * - HTTP status codes (401→AUTH_INVALID, 429→RATE_LIMIT, 5xx→PROVIDER_ERROR)
 * - Timeout patterns
 * - Zod validation errors
 * - Context overflow patterns
 * - Unknown → wrapped as ChatError with PROVIDER_ERROR
 *
 * @param error - The thrown value to classify
 * @returns ChatError with appropriate error code and retryable flag
 */
declare function classifyError(error: unknown): ChatError;
/** Strategy for computing retry delays */
interface RetryStrategy {
    /** Return delay in ms for the given attempt (0-based), or null to stop */
    nextDelay(attempt: number, error: ChatError): number | null;
}
/** Options for ExponentialBackoffStrategy */
interface ExponentialBackoffOptions {
    /** Base delay in ms (default: 1000) */
    baseMs?: number;
    /** Maximum delay in ms (default: 30000) */
    maxMs?: number;
    /** Maximum number of attempts (default: 3) */
    maxAttempts?: number;
    /** Jitter factor 0–1 (default: 0.1) */
    jitter?: number;
}
/** Exponential backoff with optional jitter */
declare class ExponentialBackoffStrategy implements RetryStrategy {
    private readonly baseMs;
    private readonly maxMs;
    private readonly maxAttempts;
    private readonly jitter;
    constructor(options?: ExponentialBackoffOptions);
    nextDelay(attempt: number, error: ChatError): number | null;
}
/** Options for withRetry execution */
interface RetryOptions {
    /** Abort signal to cancel retries */
    signal?: AbortSignal;
    /** Called before each retry with the error and delay */
    onRetry?: (error: ChatError, attempt: number, delayMs: number) => void;
}
/**
 * Execute an async function with automatic retries using the provided strategy.
 * Respects ChatError.retryable and ChatError.retryAfter.
 * Classifies non-ChatError errors before deciding on retry.
 *
 * @param fn - Async function to execute
 * @param strategy - Retry strategy providing delay calculations
 * @param options - Optional abort signal and retry callback
 * @returns Result of fn on success
 * @throws ChatError when all retries exhausted or error is non-retryable
 */
declare function withRetry<T>(fn: () => Promise<T>, strategy: RetryStrategy, options?: RetryOptions): Promise<T>;
/**
 * Type guard: check if an error is retryable
 * @param error - The error to check
 * @returns True if error is a retryable ChatError
 */
declare function isRetryable(error: unknown): boolean;

export { ChatError, type ChatErrorOptions, ErrorCode, type ExponentialBackoffOptions, ExponentialBackoffStrategy, type RetryOptions, type RetryStrategy, classifyError, isRetryable, withRetry };
