/** * Serialized rate limiter for API request pacing. * * Uses a shared `nextAllowedAt` timestamp to serialize admission across * concurrent workers. When a rate limit (429) is received, the next * allowed time is pushed forward, and all workers wait their turn. * * Design influences: * - .NET TokenBucketRateLimiter (serialized acquisition, RetryAfter metadata) * - nginx upstream peer tracking (fail_timeout, gradual recovery) */ export interface RateLimiterStats { /** Total number of rate limit events recorded. */ totalLimitHits: number; /** Total time workers have spent waiting (ms). */ totalWaitMs: number; /** Whether the limiter is currently throttling. */ throttled: boolean; /** Current minimum delay between requests (ms). 0 = not throttled. */ currentDelayMs: number; } export interface RateLimiterOptions { /** Initial delay in ms after the first rate limit (default: 5000). */ initialDelayMs?: number; /** Maximum delay in ms between requests (default: 30000). */ maxDelayMs?: number; /** Backoff multiplier on repeated rate limits (default: 2). */ backoffFactor?: number; /** Time in ms without a rate limit before delay starts to decay (default: 60000). */ recoveryMs?: number; } export declare class SerializedRateLimiter { private nextAllowedAt; private currentDelayMs; private lastRateLimitAt; private lastDecayAt; private waitLock; private _totalLimitHits; private _totalWaitMs; private readonly initialDelayMs; private readonly maxDelayMs; private readonly backoffFactor; private readonly recoveryMs; constructor(options?: RateLimiterOptions); /** * Record a rate limit event. Extends the next allowed request time * and increases the inter-request delay. */ onRateLimit(): void; /** * Record a successful request. Gradually reduces the delay based on * time elapsed since the last rate limit event (not since the last * scheduled request). */ onSuccess(): void; /** * Wait until this worker is allowed to proceed. Workers are serialized: * each caller waits for the previous to complete, then sets the next * slot before releasing. */ wait(): Promise; /** Get current limiter statistics. */ get stats(): RateLimiterStats; } //# sourceMappingURL=rate-limiter.d.ts.map