/**
 * Base Provider - Abstract LLM Provider Implementation
 *
 * Provides common functionality for LLM providers:
 * - Retry logic with exponential backoff
 * - Rate limit handling
 * - Transient error recovery
 * - Message conversion utilities
 * - Usage tracking
 *
 * Usage:
 * ```typescript
 * class MyProvider extends BaseProvider {
 *   readonly id = 'my-provider';
 *
 *   protected async doGenerate(messages, tools): Promise<ProviderResponse> {
 *     // Provider-specific implementation
 *   }
 *
 *   protected async doGenerateStream(messages, tools): AsyncIterable<StreamChunk> {
 *     // Provider-specific implementation
 *   }
 * }
 * ```
 */
import type { ConversationMessage, LLMProvider, ProviderResponse, ProviderToolDefinition, ProviderUsage, StreamChunk, ProviderModelInfo } from '../core/types.js';
/** Patterns that indicate transient/retryable errors */
export declare const TRANSIENT_ERROR_PATTERNS: readonly ["premature close", "premature end", "unexpected end", "aborted", "fetcherror", "invalid response body", "gunzip", "decompress", "econnreset", "econnrefused", "epipe", "socket hang up", "network", "timeout", "500", "502", "503", "504", "overloaded"];
/** Default retry configuration */
export declare const DEFAULT_RETRY_CONFIG: {
    readonly maxRetries: 3;
    readonly initialDelayMs: 1000;
    readonly maxDelayMs: 30000;
    readonly backoffMultiplier: 2;
};
/** Default rate limit configuration */
export declare const DEFAULT_RATE_LIMIT_CONFIG: {
    readonly maxRetries: 4;
    readonly initialDelayMs: 1500;
    readonly minDelayMs: 750;
    readonly maxDelayMs: 40000;
};
export interface RetryConfig {
    maxRetries: number;
    initialDelayMs: number;
    maxDelayMs: number;
    backoffMultiplier: number;
}
export interface RateLimitConfig {
    maxRetries: number;
    initialDelayMs: number;
    minDelayMs: number;
    maxDelayMs: number;
}
export interface BaseProviderOptions {
    model: string;
    maxTokens?: number;
    temperature?: number;
    retryConfig?: Partial<RetryConfig>;
    rateLimitConfig?: Partial<RateLimitConfig>;
}
/**
 * Check if an error is transient and can be retried
 */
export declare function isTransientError(error: unknown): boolean;
/**
 * Check if an error is a rate limit error
 */
export declare function isRateLimitError(error: unknown): boolean;
/**
 * Check if an error is an authentication error
 */
export declare function isAuthError(error: unknown): boolean;
/**
 * Sleep for a given duration
 */
export declare function sleep(ms: number): Promise<void>;
/**
 * Calculate exponential backoff delay
 */
export declare function calculateBackoffDelay(attempt: number, config: RetryConfig): number;
/**
 * Execute an operation with retry logic
 */
export declare function withRetry<T>(operation: () => Promise<T>, options?: {
    config?: Partial<RetryConfig>;
    shouldRetry?: (error: unknown) => boolean;
    onRetry?: (error: unknown, attempt: number, delay: number) => void;
}): Promise<T>;
/**
 * Extract system message from conversation
 */
export declare function extractSystemMessage(messages: ConversationMessage[]): {
    system: string | null;
    rest: ConversationMessage[];
};
/**
 * Merge consecutive messages from the same role
 */
export declare function mergeConsecutiveMessages(messages: ConversationMessage[]): ConversationMessage[];
/**
 * Create an empty usage object
 */
export declare function emptyUsage(): ProviderUsage;
/**
 * Merge usage objects
 */
export declare function mergeUsage(a: ProviderUsage, b: ProviderUsage): ProviderUsage;
/**
 * Abstract base class for LLM providers
 *
 * Implements common functionality like retry logic and error handling.
 * Subclasses must implement the abstract methods for provider-specific behavior.
 */
export declare abstract class BaseProvider implements LLMProvider {
    abstract readonly id: string;
    readonly model: string;
    protected readonly maxTokens: number;
    protected readonly temperature: number;
    protected readonly retryConfig: RetryConfig;
    protected readonly rateLimitConfig: RateLimitConfig;
    constructor(options: BaseProviderOptions);
    /**
     * Generate a response (implemented by subclass)
     */
    generate(messages: ConversationMessage[], tools: ProviderToolDefinition[]): Promise<ProviderResponse>;
    /**
     * Generate a streaming response (implemented by subclass)
     */
    generateStream(messages: ConversationMessage[], tools: ProviderToolDefinition[]): AsyncIterableIterator<StreamChunk>;
    /**
     * Get available models (optional, implemented by subclass)
     */
    getModels(): Promise<ProviderModelInfo[]>;
    /**
     * Provider-specific generate implementation
     */
    protected abstract doGenerate(messages: ConversationMessage[], tools: ProviderToolDefinition[]): Promise<ProviderResponse>;
    /**
     * Provider-specific stream implementation
     */
    protected abstract doGenerateStream(messages: ConversationMessage[], tools: ProviderToolDefinition[]): AsyncIterable<StreamChunk>;
    /**
     * Called when a retry is about to happen
     */
    protected onRetry(_error: unknown, _attempt: number, _delay: number): void;
}
//# sourceMappingURL=baseProvider.d.ts.map