{"version":3,"file":"exceptions.mjs","names":[],"sources":["../../../../src/batteries/llm/chat_common/exceptions.ts"],"sourcesContent":["/**\n * Shared, wire-shape-agnostic exceptions for the on-device LLM batteries.\n *\n * @module @nhtio/adk/batteries/llm/chat_common/exceptions\n *\n * @remarks\n * INTERNAL to the bundled LLM batteries (no public subpath of its own) — re-exported from each\n * on-device battery's public barrel. Holds exceptions that are NOT specific to one battery's wire\n * shape; today, the WebGPU out-of-memory signal that both transformers.js and LiteRT-LM can hit on the\n * ONNX Runtime Web / WebGPU execution provider.\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Raised when the WebGPU execution provider exhausts the device's GPU memory budget during generation.\n *\n * @remarks\n * The ADK stance is **surface, don't impose** — rather than silently capping the caller's context\n * window, the on-device batteries translate ORT-web's cryptic, location-dependent GPU-exhaustion throws\n * (`Failed to allocate memory for buffer mapping`, `device is lost`, `operation does not support\n * unaligned accesses`, …) into THIS single typed error, so an application can `catch` it structurally\n * — `if (isInstanceOf(err, 'E_LLM_GPU_OUT_OF_MEMORY')) …` — instead of string-matching runtime\n * internals, and react however it wants (warn + retry with a smaller window, `recycle()` the adapter to\n * flush the WebGPU buffer freelist, switch to a smaller model, …).\n *\n * Non-fatal: the adapter surfaces it via `ctx.nack(...)` (not a throw), exactly like the generic stream\n * error, so the turn ends cleanly and the application can offer a retry. The matcher behind the\n * translation is `isGpuOutOfMemoryError` in `./gpu_budget`. Printf args:\n * `[providerMessage, contextWindowSummary]` — the raw provider message and a short budget/window note\n * the application can show the user verbatim.\n */\nexport const E_LLM_GPU_OUT_OF_MEMORY = createException<[string, string]>(\n  'E_LLM_GPU_OUT_OF_MEMORY',\n  'on-device WebGPU ran out of GPU memory during generation: %s. %s',\n  'E_LLM_GPU_OUT_OF_MEMORY',\n  507,\n  false\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,0BAA0B,gBACrC,2BACA,oEACA,2BACA,KACA,KACF"}