/**
 * Rate Limiter for API calls
 *
 * Implements token bucket algorithm with automatic retry and backoff.
 * Prevents API rate limit errors and provides queue management.
 */
import { EventEmitter } from 'events';
export interface RateLimitConfig {
    requestsPerMinute: number;
    tokensPerMinute: number;
    maxBurst: number;
    maxRetries: number;
    baseRetryDelay: number;
    maxRetryDelay: number;
    maxQueueSize: number;
    queueTimeout: number;
}
export interface RateLimitStatus {
    requestsRemaining: number;
    tokensRemaining: number;
    resetTime: Date;
    queueLength: number;
    isLimited: boolean;
}
export interface QueuedRequest<T> {
    id: string;
    execute: () => Promise<T>;
    resolve: (value: T) => void;
    reject: (error: Error) => void;
    priority: number;
    timestamp: number;
    estimatedTokens: number;
    retries: number;
}
/**
 * Token Bucket Rate Limiter
 */
export declare class RateLimiter extends EventEmitter {
    private config;
    private requestTokens;
    private apiTokens;
    private lastRefill;
    private queue;
    private processing;
    private requestIdCounter;
    constructor(config?: Partial<RateLimitConfig>);
    /**
     * Refill tokens based on elapsed time
     */
    private refillTokens;
    /**
     * Check if request can proceed
     */
    private canProceed;
    /**
     * Consume tokens for a request
     */
    private consumeTokens;
    /**
     * Calculate retry delay with exponential backoff
     */
    private calculateRetryDelay;
    /**
     * Execute a rate-limited request
     */
    execute<T>(fn: () => Promise<T>, options?: {
        priority?: number;
        estimatedTokens?: number;
        skipQueue?: boolean;
    }): Promise<T>;
    /**
     * Execute with retry logic
     */
    private executeWithRetry;
    /**
     * Process queued requests
     */
    private processQueue;
    /**
     * Get current rate limit status
     */
    getStatus(): RateLimitStatus;
    /**
     * Update rate limit from API response headers
     */
    updateFromHeaders(headers: {
        'x-ratelimit-remaining'?: string;
        'x-ratelimit-limit'?: string;
        'x-ratelimit-reset'?: string;
        'retry-after'?: string;
    }): void;
    /**
     * Clear the queue
     */
    clearQueue(): number;
    /**
     * Update configuration
     */
    updateConfig(config: Partial<RateLimitConfig>): void;
    /**
     * Format status for display
     */
    formatStatus(): string;
    private sleep;
    /**
     * Dispose and cleanup resources
     */
    dispose(): void;
}
export declare function getRateLimiter(config?: Partial<RateLimitConfig>): RateLimiter;
export declare function resetRateLimiter(): void;
/**
 * Decorator for rate-limited methods
 */
export declare function rateLimited(estimatedTokens?: number, priority?: number): <T extends (...args: unknown[]) => Promise<unknown>>(_target: unknown, _propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
