{"version":3,"file":"exceptions.mjs","names":[],"sources":["../../../../src/batteries/llm/anthropic_messages/exceptions.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the Anthropic Messages adapter.\n *\n * @module @nhtio/adk/batteries/llm/anthropic_messages/exceptions\n *\n * @remarks\n * Battery-scoped exception classes for the Anthropic Messages adapter. These exceptions are owned\n * by the battery, not the ADK core, and are minted via `createException` from\n * `@nhtio/adk/factories`. The status codes and fatal split mirror the pure HTTP Ollama battery.\n *\n * Important provenance rule: ADK convention uses status 529 on fatal option and context-overflow\n * exceptions raised by the adapter itself. Anthropic also returns a real upstream HTTP 529\n * `overloaded_error`, which is transient and retriable. An upstream 529 must be classified by\n * provenance as `E_ANTHROPIC_MESSAGES_HTTP_ERROR`, with retry eligibility decided by the retry\n * config. Never route a provider 529 into the fatal same-numbered ADK-side exceptions.\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when resolved Anthropic Messages adapter options fail validation.\n */\nexport const E_INVALID_ANTHROPIC_MESSAGES_OPTIONS = createException<[string]>(\n  'E_INVALID_ANTHROPIC_MESSAGES_OPTIONS',\n  'Invalid Anthropic Messages adapter options: %s',\n  'E_INVALID_ANTHROPIC_MESSAGES_OPTIONS',\n  529,\n  true\n)\n\n/**\n * Thrown when the total token weight of the resolved request exceeds `contextWindow`.\n */\nexport const E_ANTHROPIC_MESSAGES_CONTEXT_OVERFLOW = createException<\n  [number, number, string, string]\n>(\n  'E_ANTHROPIC_MESSAGES_CONTEXT_OVERFLOW',\n  'Anthropic Messages request token weight (%d) exceeds context window (%d) under encoding %s. Per-bucket breakdown: %s',\n  'E_ANTHROPIC_MESSAGES_CONTEXT_OVERFLOW',\n  529,\n  true\n)\n\n/**\n * Thrown when the upstream Messages endpoint returns an API error.\n */\nexport const E_ANTHROPIC_MESSAGES_HTTP_ERROR = createException<[number, string]>(\n  'E_ANTHROPIC_MESSAGES_HTTP_ERROR',\n  'Anthropic Messages HTTP error %d: %s',\n  'E_ANTHROPIC_MESSAGES_HTTP_ERROR',\n  502,\n  false\n)\n\n/**\n * Thrown when a streaming Messages request emits a provider or transport failure mid-stream.\n */\nexport const E_ANTHROPIC_MESSAGES_STREAM_ERROR = createException<[string]>(\n  'E_ANTHROPIC_MESSAGES_STREAM_ERROR',\n  'Anthropic Messages stream error: %s',\n  'E_ANTHROPIC_MESSAGES_STREAM_ERROR',\n  502,\n  false\n)\n\n/**\n * Thrown when the Messages stream goes silent for longer than `streamIdleTimeoutMs`.\n */\nexport const E_ANTHROPIC_MESSAGES_STREAM_STALLED = createException<[number]>(\n  'E_ANTHROPIC_MESSAGES_STREAM_STALLED',\n  'Anthropic Messages stream stalled (no event for %dms)',\n  'E_ANTHROPIC_MESSAGES_STREAM_STALLED',\n  504,\n  false\n)\n\n/**\n * Thrown when the request does not complete before `requestTimeoutMs`.\n */\nexport const E_ANTHROPIC_MESSAGES_REQUEST_TIMEOUT = createException<[number]>(\n  'E_ANTHROPIC_MESSAGES_REQUEST_TIMEOUT',\n  'Anthropic Messages request timed out after %dms',\n  'E_ANTHROPIC_MESSAGES_REQUEST_TIMEOUT',\n  504,\n  false\n)\n\n/**\n * Instantiated for invalid model-emitted tool arguments and persisted as an error `ToolCall`.\n *\n * @remarks\n * The adapter must not throw this exception. It creates the exception, copies the message into a\n * tool-result payload, and persists a failed `ToolCall` so the model can self-correct on the next\n * iteration.\n */\nexport const E_ANTHROPIC_MESSAGES_INVALID_TOOL_CALL_ARGS = createException<[string, string]>(\n  'E_ANTHROPIC_MESSAGES_INVALID_TOOL_CALL_ARGS',\n  'Tool arguments %s. Raw value: %s',\n  'E_ANTHROPIC_MESSAGES_INVALID_TOOL_CALL_ARGS',\n  422,\n  false\n)\n\n/**\n * Raised when an ADK media instance cannot be represented by the Anthropic Messages wire.\n */\nexport const E_ANTHROPIC_MESSAGES_UNSUPPORTED_MEDIA_MODALITY = createException<\n  [string, string, string]\n>(\n  'E_ANTHROPIC_MESSAGES_UNSUPPORTED_MEDIA_MODALITY',\n  'Anthropic Messages supports image and selected document media; media of kind %s (mime=%s, filename=%s) is unsupported. Configure adapter `unsupportedMediaPolicy` to `fallback-stash` or `synthetic-description` to handle this case.',\n  'E_ANTHROPIC_MESSAGES_UNSUPPORTED_MEDIA_MODALITY',\n  422,\n  true\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,uCAAuC,gBAClD,wCACA,kDACA,wCACA,KACA,IACF;;;;AAKA,IAAa,wCAAwC,gBAGnD,yCACA,wHACA,yCACA,KACA,IACF;;;;AAKA,IAAa,kCAAkC,gBAC7C,mCACA,wCACA,mCACA,KACA,KACF;;;;AAKA,IAAa,oCAAoC,gBAC/C,qCACA,uCACA,qCACA,KACA,KACF;;;;AAKA,IAAa,sCAAsC,gBACjD,uCACA,yDACA,uCACA,KACA,KACF;;;;AAKA,IAAa,uCAAuC,gBAClD,wCACA,mDACA,wCACA,KACA,KACF;;;;;;;;;AAUA,IAAa,8CAA8C,gBACzD,+CACA,oCACA,+CACA,KACA,KACF;;;;AAKA,IAAa,kDAAkD,gBAG7D,mDACA,yOACA,mDACA,KACA,IACF"}