{"version":3,"file":"exceptions.mjs","names":[],"sources":["../../../../src/batteries/llm/openai_responses/exceptions.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the OpenAI Responses adapter.\n *\n * @module @nhtio/adk/batteries/llm/openai_responses/exceptions\n *\n * @remarks\n * Battery-scoped exception classes for the OpenAI Responses adapter. These exceptions are owned by\n * the battery (not the ADK core) and are minted via `createException` from `@nhtio/adk/factories`.\n * Re-exported from the battery's barrel. The status codes and fatal split mirror the sibling\n * `openai_chat_completions` and `anthropic_messages` batteries.\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.openaiResponses`) fail validation against `openAIResponsesOptionsSchema`.\n */\nexport const E_INVALID_OPENAI_RESPONSES_OPTIONS = createException<[string]>(\n  'E_INVALID_OPENAI_RESPONSES_OPTIONS',\n  'Invalid OpenAI Responses adapter options: %s',\n  'E_INVALID_OPENAI_RESPONSES_OPTIONS',\n  529,\n  true\n)\n\n/**\n * Thrown when the total token weight of the resolved request exceeds `contextWindow`. Only raised\n * when `tokenEncoding` is non-null. Carries `{ total, contextWindow, tokenEncoding, perBucket }` in\n * the message so middleware can target shedding.\n */\nexport const E_OPENAI_RESPONSES_CONTEXT_OVERFLOW = createException<\n  [number, number, string, string]\n>(\n  'E_OPENAI_RESPONSES_CONTEXT_OVERFLOW',\n  'OpenAI Responses request token weight (%d) exceeds context window (%d) under encoding %s. Per-bucket breakdown: %s',\n  'E_OPENAI_RESPONSES_CONTEXT_OVERFLOW',\n  529,\n  true\n)\n\n/**\n * Thrown when the upstream Responses endpoint returns a non-2xx response. Non-fatal — surfaced via\n * `ctx.nack(...)` so middleware can decide retry / fail.\n */\nexport const E_OPENAI_RESPONSES_HTTP_ERROR = createException<[number, string]>(\n  'E_OPENAI_RESPONSES_HTTP_ERROR',\n  'OpenAI Responses HTTP error %d: %s',\n  'E_OPENAI_RESPONSES_HTTP_ERROR',\n  502,\n  false\n)\n\n/**\n * Thrown when the SSE stream emits a malformed chunk, the transport throws mid-stream, or an\n * explicit upstream `response.failed` / `error` terminal event arrives.\n *\n * @remarks\n * NOT thrown when the stream reaches EOF without ever observing a terminal event. The Responses\n * SSE stream has no `[DONE]` sentinel, so a truncated-looking stream is indistinguishable from a\n * short one: the adapter warn-logs (`kind: 'sse-eof-without-terminal-event'`) and drains whatever\n * it accumulated, rather than discarding a usable partial turn.\n */\nexport const E_OPENAI_RESPONSES_STREAM_ERROR = createException<[string]>(\n  'E_OPENAI_RESPONSES_STREAM_ERROR',\n  'OpenAI Responses stream error: %s',\n  'E_OPENAI_RESPONSES_STREAM_ERROR',\n  502,\n  false\n)\n\n/**\n * Thrown when the SSE stream goes silent for longer than `streamIdleTimeoutMs`. Non-fatal —\n * surfaced via `ctx.nack(...)` with partial-state details so middleware can recover.\n */\nexport const E_OPENAI_RESPONSES_STREAM_STALLED = createException<[number]>(\n  'E_OPENAI_RESPONSES_STREAM_STALLED',\n  'OpenAI Responses stream stalled (no chunk for %dms)',\n  'E_OPENAI_RESPONSES_STREAM_STALLED',\n  504,\n  false\n)\n\n/**\n * Thrown when the initial request handshake (TCP connect, TLS, response headers) does not complete\n * before `requestTimeoutMs`. Non-fatal — surfaced via `ctx.nack(...)`. Eligible for retry on the\n * same footing as a retriable 5xx.\n */\nexport const E_OPENAI_RESPONSES_REQUEST_TIMEOUT = createException<[number]>(\n  'E_OPENAI_RESPONSES_REQUEST_TIMEOUT',\n  'OpenAI Responses request timed out after %dms (before response headers)',\n  'E_OPENAI_RESPONSES_REQUEST_TIMEOUT',\n  504,\n  false\n)\n\n/**\n * Raised when a tool-call's `arguments` string emitted by the model is not a JSON object — either\n * non-parseable JSON, or parseable JSON whose root is not an object (e.g. a bare string, number,\n * 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 can\n * match on the `E_OPENAI_RESPONSES_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 the model\n *     can see what it sent.\n */\nexport const E_OPENAI_RESPONSES_INVALID_TOOL_CALL_ARGS = createException<[string, string]>(\n  'E_OPENAI_RESPONSES_INVALID_TOOL_CALL_ARGS',\n  'Tool arguments %s. Raw value: %s',\n  'E_OPENAI_RESPONSES_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\n * the OpenAI Responses wire format reaches the adapter under `unsupportedMediaPolicy: 'throw'`.\n *\n * @remarks\n * Today `audio` and `video` trigger this — the Responses input-content union has no audio member\n * (confirmed against the `openai` SDK's own type definitions) and no video member either. Consumers\n * can opt out of the throw by switching to `'fallback-stash'` or `'synthetic-description'` (see\n * {@link @nhtio/adk/batteries/llm/openai_responses/types!UnsupportedMediaPolicy}).\n *\n * Printf args: `[kind, mimeType, filename]`.\n */\nexport const E_OPENAI_RESPONSES_UNSUPPORTED_MEDIA_MODALITY = createException<\n  [string, string, string]\n>(\n  'E_OPENAI_RESPONSES_UNSUPPORTED_MEDIA_MODALITY',\n  'OpenAI Responses 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_OPENAI_RESPONSES_UNSUPPORTED_MEDIA_MODALITY',\n  422,\n  true\n)\n\n/**\n * Thrown when the upstream Responses API rejects the request because a replayed `reasoning` item\n * violates the undocumented reasoning/output-item pairing constraint (`openai/openai-node#1791`) —\n * detected by matching the upstream error body against known phrases (e.g. \"of type 'reasoning'\n * was provided without\" / \"Items are not persisted when store is set to false\").\n *\n * @remarks\n * Non-fatal — surfaced via `ctx.nack(...)`. Names the offending item and suggests\n * `reasoningReplay: 'off'` as a mitigation, rather than surfacing a generic HTTP error.\n *\n * Printf args: `[itemId, upstreamMessage]`.\n */\nexport const E_OPENAI_RESPONSES_REASONING_REPLAY_REJECTED = createException<[string, string]>(\n  'E_OPENAI_RESPONSES_REASONING_REPLAY_REJECTED',\n  'OpenAI Responses rejected a replayed reasoning item (%s): %s. Consider setting reasoningReplay to \"off\".',\n  'E_OPENAI_RESPONSES_REASONING_REPLAY_REJECTED',\n  422,\n  false\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,IAAa,qCAAqC,gBAChD,sCACA,gDACA,sCACA,KACA,IACF;;;;;;AAOA,IAAa,sCAAsC,gBAGjD,uCACA,sHACA,uCACA,KACA,IACF;;;;;AAMA,IAAa,gCAAgC,gBAC3C,iCACA,sCACA,iCACA,KACA,KACF;;;;;;;;;;;AAYA,IAAa,kCAAkC,gBAC7C,mCACA,qCACA,mCACA,KACA,KACF;;;;;AAMA,IAAa,oCAAoC,gBAC/C,qCACA,uDACA,qCACA,KACA,KACF;;;;;;AAOA,IAAa,qCAAqC,gBAChD,sCACA,2EACA,sCACA,KACA,KACF;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,4CAA4C,gBACvD,6CACA,oCACA,6CACA,KACA,KACF;;;;;;;;;;;;;AAcA,IAAa,gDAAgD,gBAG3D,iDACA,sMACA,iDACA,KACA,IACF;;;;;;;;;;;;;AAcA,IAAa,+CAA+C,gBAC1D,gDACA,8GACA,gDACA,KACA,KACF"}