/** * Provider failure taxonomy. * * Every driver throws whatever its underlying vendor SDK threw, which * means the runtime cannot tell a 429 from a malformed request from a * dead socket — and therefore cannot decide whether to back off, fail * fast, or compact and retry. Classification is the substrate the retry * policy stands on; without it "add a retry" is unimplementable. * * The union is deliberately small. It answers exactly three questions the * runtime asks: is it worth retrying, should the delay come from the * server, and is this a context problem the turn could recover from by * shedding history. */ export type ProviderErrorCode = /** 429. Back off; honour `retryAfterMs` when the server sent one. */ 'rate_limit' /** 529 / 503 — the model is up but saturated. Back off. */ | 'overloaded' /** Any other 5xx. Back off. */ | 'server_error' /** The request timed out in transit. Retry. */ | 'timeout' /** Socket/DNS/TLS failure before a response. Retry. */ | 'network' /** 401 / 403. A retry cannot help. */ | 'auth' /** 400 and friends. A retry cannot help. */ | 'invalid_request' /** The prompt exceeds the model window. Retrying verbatim cannot help. */ | 'context_length_exceeded' /** The provider refused on safety grounds. */ | 'content_filter' /** 404 — unknown model or endpoint. */ | 'not_found' /** Unclassifiable. Treated as non-retryable. */ | 'unknown'; export interface ProviderErrorInit { readonly code: ProviderErrorCode; readonly message: string; readonly providerId?: string; readonly status?: number; /** Server-directed backoff, derived from a `Retry-After` header. */ readonly retryAfterMs?: number; /** * Override the code's own verdict on retryability. * * Omit and the code decides, which is the normal path. Set it when * something closer to the failure already said so — see * {@link declaredRetryable}. */ readonly retryable?: boolean; readonly cause?: unknown; } /** * A `retryable` flag declared anywhere on the cause chain. * * Retryability was derived solely from namzu's own code set, so a provider * that says outright "this one is safe to retry" was not listened to — * and the code set is a second-hand inference from status and wording that * necessarily lags every new failure shape a vendor invents. Read * duck-typed rather than through an interface, because the flag arrives on * a foreign SDK's error object that namzu does not control. * * The FIRST link that declares one wins: the outermost declaration is the * most recent statement about the failure, made by whichever layer knew * enough to make it. */ export declare function declaredRetryable(err: unknown): boolean | undefined; export declare class ProviderError extends Error { readonly code: ProviderErrorCode; readonly providerId: string | undefined; readonly status: number | undefined; readonly retryAfterMs: number | undefined; readonly retryable: boolean; constructor(init: ProviderErrorInit); } export declare function isProviderError(err: unknown): err is ProviderError; /** * An abort is a control-flow signal, not a provider failure: the turn loop * settles it as `cancelled`. It must never be reclassified or retried. */ export declare function isAbortError(err: unknown): boolean; export declare function classifyProviderError(err: unknown, providerId?: string, now?: number): ProviderError; //# sourceMappingURL=errors.d.ts.map