/** * @module RetryManager * * Reusable retry logic for AI provider nodes handling HTTP 429 rate limiting. * Distinct from WorkflowExecutor's step-level RetryConfig — this is scoped * specifically to AiRateLimitPolicy and 429 responses, with Retry-After * header support. */ import type { AiRateLimitPolicy } from '@cognipipe/types'; /** * A function that may throw a RateLimitError-shaped object on 429. * Node authors wrap their fetch call in a function matching this signature. */ export interface RateLimitAwareError extends Error { /** Present when the failure was an HTTP 429 response. */ status?: number; /** The raw Retry-After header value, if the provider sent one. */ retryAfterHeader?: string; } /** * Parses a Retry-After header value into a delay in milliseconds. * Supports both formats per RFC 9110 §10.2.3: * - delay-seconds: "120" → 120_000ms * - HTTP-date (IMF-fixdate): "Wed, 21 Oct 2026 07:28:00 GMT" → computed from now * * Note: HTTP-date has no sub-second precision, so a delay derived from it is * only accurate to the nearest second. * * @returns The delay in milliseconds, or null if the header is malformed * (caller should fall back to the policy's own backoff schedule). */ export declare function parseRetryAfter(headerValue: string): number | null; /** * Namespace object exposing {@link RetryManager.execute} — the sole entry * point for AiRateLimitPolicy-driven HTTP 429 retry handling. */ export declare const RetryManager: { /** * Executes `fn`, retrying on HTTP 429 per `policy`. * Non-429 errors are NOT retried — they propagate immediately. * * `policy.respectRetryAfter` defaults to `true` when omitted, matching * {@link AiRateLimitPolicy}'s documented default — only an explicit * `false` disables honouring the provider's Retry-After header. * * @param fn - The operation to execute (e.g. a fetch call wrapped to throw * a RateLimitAwareError with `status: 429` on rate limit responses). * @param policy - The AiRateLimitPolicy governing retry behaviour. * @throws {CogniPipeError} STEP_EXECUTION_FAILED after policy.maxRetries * exhausted, or the original non-429 error if fn throws something else. * * @example * ```typescript * const result = await RetryManager.execute( * () => callProviderApi(), * { maxRetries: 3, initialDelayMs: 1000, respectRetryAfter: true }, * ); * ``` */ execute(fn: () => Promise, policy: AiRateLimitPolicy): Promise; }; //# sourceMappingURL=RetryManager.d.ts.map