/** * SDK error → ADK classification for the Anthropic Messages battery. * * @remarks * Extracted so the dispatch path (`adapter.ts`) and the token-count path (`count_tokens.ts`) share * ONE classifier. They previously carried byte-identical private copies, which meant a fix to one * silently left the other wrong — exactly what happened with the statusless-`APIError` bug this * module's {@link AnthropicMessagesErrorStatusResolver} seam addresses. * * @module @nhtio/adk/batteries/llm/anthropic_messages/error_translation */ import type { AnthropicMessagesErrorStatusResolver } from "./types"; /** * Body-text marker identifying an Anthropic context-overflow rejection. * * @remarks * Context overflow arrives as a 400 `BadRequestError` and is detected from body TEXT, not status — * the status alone cannot distinguish it from any other bad request. */ export declare const CONTEXT_OVERFLOW_PHRASE = "prompt is too long"; /** * The outcome of classifying an SDK error. */ export type AnthropicErrorClassification = { kind: 'abort'; } | { kind: 'timeout'; } | { kind: 'context-overflow'; message: string; } | { kind: 'retriable'; status: number; message: string; } | { kind: 'fatal'; status: number; message: string; }; /** * Classify an error thrown by the Anthropic SDK into an ADK disposition. * * @remarks * Ordering is deliberate. Abort and timeout are checked first because they are control-flow * outcomes rather than failures. `APIConnectionError` is retriable at status `0` — a transport * fault has no HTTP status and never will, and that branch establishes the convention that a * statusless error can still be retriable. * * For an `APIError`, the consumer's `resolveErrorStatus` hook (when configured) runs BEFORE both * the context-overflow check and retriable classification, so a recovered status participates in * every downstream decision and is what gets reported — a recovered `529` surfaces as `529`, not * `0`. Without a resolver the behaviour is unchanged from before the hook existed: a statusless * `APIError` coerces to `0`, matches no retriable status, and is fatal. * * @param err - The thrown value. * @param retriableStatuses - Status codes configured as retriable. * @param opts - Optional status resolver and warning sink. * @returns The classification. */ export declare const translateAnthropicError: (err: unknown, retriableStatuses: ReadonlyArray, opts?: { resolveErrorStatus?: AnthropicMessagesErrorStatusResolver; warn?: (msg: string) => void; }) => AnthropicErrorClassification;