import type { ProviderErrorBody } from '@wrongstack/core/types'; import { ProviderError } from '@wrongstack/core/types'; /** * Provider HTTP error bodies come in three or four shapes depending on * vendor. Rather than dump the raw JSON into the error message (which is * what was shipped to the user log before this module existed), we parse * out the fields we care about — `type`, `message`, `requestId` — and put * them on `ProviderError.body` for `describe()` and downstream rendering. * * The function is intentionally tolerant: anything we can't parse falls * back to a truncated raw string, never throws. */ export declare function parseProviderHttpError(providerId: string, status: number, rawText: string, headers?: HeadersLike): ProviderError; /** * Redact credentials from the free-text fields of a parsed provider error. * `retryAfterMs` and `rawLength` are numeric metadata and pass through; `type` * is a vendor category, but it is provider-controlled text like the rest, so * it goes through the scrubber too. */ export declare function scrubProviderErrorBody(body: ProviderErrorBody): ProviderErrorBody; /** Structural subset of the Fetch `Headers` interface, easy to fake in tests. */ export interface HeadersLike { get(name: string): string | null; } /** * Parse a Retry-After hint from HTTP response headers into milliseconds. * * Handles the three shapes seen in the wild: * - `retry-after-ms: 1500` — milliseconds (Anthropic, some OpenAI-compatibles) * - `retry-after: 12` — delta-seconds (RFC 9110) * - `retry-after: Wed, 21 Oct 2026 07:28:00 GMT` — HTTP-date * * Returns `undefined` for missing/unparseable/non-positive values so callers * fall through to their exponential backoff schedule. */ export declare function retryAfterMsFromHeaders(headers?: HeadersLike): number | undefined; export declare function parseProviderErrorBody(rawText: string): ProviderErrorBody; /** * Extract a retry-after duration from the provider's error body message text. * Called when no HTTP Retry-After header was present. Many providers, * particularly in the Chinese ecosystem (Z.AI, MiniMax, Moonshot), embed * the reset time in the JSON body message instead of sending a standard * `retry-after` header. * * Handles three patterns: * - "Your limit will reset at YYYY-MM-DD HH:mm:ss" — absolute date-time * - "Usage limit reached for X hour(s)" — relative duration from hours * - "retry after X seconds" / "retry_after X" — relative seconds * * Returns `undefined` when no well-formed hint is found so callers fall * through to their exponential backoff schedule. Never throws. */ export declare function retryAfterMsFromBody(body: ProviderErrorBody): number | undefined; //# sourceMappingURL=error-parse.d.ts.map