{"version":3,"file":"exceptions.mjs","names":[],"sources":["../../../../src/batteries/llm/webllm_chat_completions/exceptions.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for WebLLM Chat Completions adapter failures.\n *\n * @module @nhtio/adk/batteries/llm/webllm_chat_completions/exceptions\n *\n * @remarks\n * Battery-scoped exception classes for the WebLLM Chat Completions adapter. These exceptions\n * are owned by the battery (not the ADK core) and are minted via `createException` from\n * `@nhtio/adk/factories`. Re-exported from the battery's barrel.\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when the resolved adapter options (constructor, executor overrides, or per-dispatch\n * `stash.webLLMChatCompletions`) fail validation against `webLLMChatCompletionsOptionsSchema`.\n */\nexport const E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS = createException<[string]>(\n  'E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS',\n  'Invalid WebLLM Chat Completions adapter options: %s',\n  'E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS',\n  529,\n  true\n)\n\n/**\n * Thrown when the total token weight of the resolved request exceeds `contextWindow`. Only\n * raised when `tokenEncoding` is non-null. Carries `{ total, contextWindow, tokenEncoding,\n * perBucket }` in the message so middleware can target shedding.\n */\nexport const E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW = createException<\n  [number, number, string, string]\n>(\n  'E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW',\n  'WebLLM Chat Completions request token weight (%d) exceeds context window (%d) under encoding %s. Per-bucket breakdown: %s',\n  'E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW',\n  529,\n  true\n)\n\n/**\n * Thrown when the WebLLM engine call or async stream fails. Non-fatal — surfaced via\n * `ctx.nack(...)`.\n */\nexport const E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR = createException<[string]>(\n  'E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR',\n  'WebLLM Chat Completions stream error: %s',\n  'E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR',\n  502,\n  false\n)\n\n/**\n * Raised when a tool-call's `arguments` string emitted by the model is not a JSON object —\n * either non-parseable JSON, or parseable JSON whose root is not an object (e.g. a bare string,\n * number, array, or `null`).\n *\n * @remarks\n * Non-fatal. The adapter does NOT throw this — it instantiates it inside\n * `executeAndPersistToolCall`, pulls `.message` into a {@link @nhtio/adk!Tokenizable}, and persists a\n * `ToolCall` record with `isError: true`. The model sees the formatted message in the next\n * iteration's history and can self-correct. Consumers introspecting persisted error results\n * can match on the `E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS` code substring.\n *\n * Printf args: `[reasonHeadline, rawArgs]`.\n *   - `reasonHeadline` — short reason such as `'are not valid JSON'` or\n *     `'must be a JSON object; received array'`.\n *   - `rawArgs` — the raw `arguments` string the model emitted, echoed back verbatim so\n *     the model can see what it sent.\n */\nexport const E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS = createException<[string, string]>(\n  'E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS',\n  'Tool arguments %s. Raw value: %s',\n  'E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS',\n  422,\n  false\n)\n\n/**\n * Raised when a {@link @nhtio/adk!Media} instance whose modality cannot be natively represented in the\n * WebLLM Chat Completions wire format reaches the adapter under `unsupportedMediaPolicy: 'throw'`.\n *\n * @remarks\n * Today only `kind: 'video'` triggers this — Chat Completions natively supports `image`,\n * `audio`, and `document` content blocks but has no video block. Consumers can opt out of the\n * throw by switching to `'fallback-stash'` or `'synthetic-description'` (see\n * {@link @nhtio/adk/batteries/llm/openai_chat_completions/types!UnsupportedMediaPolicy}).\n *\n * Printf args: `[kind, mimeType, filename]`.\n */\nexport const E_UNSUPPORTED_MEDIA_MODALITY = createException<[string, string, string]>(\n  'E_UNSUPPORTED_MEDIA_MODALITY',\n  'WebLLM Chat Completions does not natively support media of kind %s (mime=%s, filename=%s). Configure adapter `unsupportedMediaPolicy` to `fallback-stash` or `synthetic-description` to handle this case.',\n  'E_UNSUPPORTED_MEDIA_MODALITY',\n  422,\n  true\n)\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,IAAa,4CAA4C,gBACvD,6CACA,uDACA,6CACA,KACA,IACF;;;;;;AAOA,IAAa,6CAA6C,gBAGxD,8CACA,6HACA,8CACA,KACA,IACF;;;;;AAMA,IAAa,yCAAyC,gBACpD,0CACA,4CACA,0CACA,KACA,KACF;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,mDAAmD,gBAC9D,oDACA,oCACA,oDACA,KACA,KACF;;;;;;;;;;;;;AAcA,IAAa,+BAA+B,gBAC1C,gCACA,6MACA,gCACA,KACA,IACF"}