@cldmv/llm-translator 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +8 -7
  2. package/dist/api/convert/anthropic/messages/to/ollama/chat/request.mjs +2 -0
  3. package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +10 -10
  4. package/dist/api/convert/ollama/chat/to/anthropic/messages/response.mjs +2 -0
  5. package/dist/api/convert/ollama/chat/to/anthropic/messages/stream.mjs +2 -0
  6. package/dist/api/convert/ollama/chat/to/openai/chat/response.mjs +2 -0
  7. package/dist/api/convert/ollama/chat/to/openai/chat/stream.mjs +2 -0
  8. package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
  9. package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +1 -1
  10. package/dist/api/convert/openai/chat/to/ollama/chat/request.mjs +2 -0
  11. package/dist/api/detect.mjs +1 -1
  12. package/dist/api/driver/azure/detect.mjs +1 -1
  13. package/dist/api/driver/azure/info.mjs +1 -1
  14. package/dist/api/driver/deepseek/info.mjs +1 -1
  15. package/dist/api/driver/fireworks/detect.mjs +2 -0
  16. package/dist/api/driver/fireworks/info.mjs +2 -0
  17. package/dist/api/driver/fireworks/path.mjs +2 -0
  18. package/dist/api/driver/fireworks/request.mjs +2 -0
  19. package/dist/api/driver/fireworks/settings.mjs +2 -0
  20. package/dist/api/driver/gemini/detect.mjs +2 -0
  21. package/dist/api/driver/gemini/info.mjs +2 -0
  22. package/dist/api/driver/gemini/path.mjs +2 -0
  23. package/dist/api/driver/gemini/request.mjs +2 -0
  24. package/dist/api/driver/gemini/settings.mjs +2 -0
  25. package/dist/api/driver/groq/detect.mjs +2 -0
  26. package/dist/api/driver/groq/info.mjs +2 -0
  27. package/dist/api/driver/groq/path.mjs +2 -0
  28. package/dist/api/driver/groq/request.mjs +2 -0
  29. package/dist/api/driver/groq/settings.mjs +2 -0
  30. package/dist/api/driver/llamacpp/info.mjs +1 -1
  31. package/dist/api/driver/mistral/info.mjs +1 -1
  32. package/dist/api/driver/ollama/info.mjs +1 -1
  33. package/dist/api/driver/ollama/request.mjs +1 -1
  34. package/dist/api/driver/openai/info.mjs +1 -1
  35. package/dist/api/driver/openrouter/info.mjs +1 -1
  36. package/dist/api/driver/together/detect.mjs +2 -0
  37. package/dist/api/driver/together/info.mjs +2 -0
  38. package/dist/api/driver/together/request.mjs +2 -0
  39. package/dist/api/driver/together/settings.mjs +2 -0
  40. package/dist/api/driver/vllm/detect.mjs +1 -1
  41. package/dist/api/driver/vllm/info.mjs +1 -1
  42. package/dist/api/driver/vllm/model/list.mjs +1 -1
  43. package/dist/api/driver/xai/detect.mjs +2 -0
  44. package/dist/api/driver/xai/info.mjs +2 -0
  45. package/dist/api/driver/xai/request.mjs +2 -0
  46. package/dist/api/driver/xai/settings.mjs +2 -0
  47. package/dist/api/embeddings/send.mjs +1 -1
  48. package/dist/api/health/check.mjs +2 -0
  49. package/dist/api/model/list.mjs +1 -1
  50. package/dist/api/request.mjs +2 -2
  51. package/dist/api/response.mjs +1 -1
  52. package/dist/api/send.mjs +1 -1
  53. package/dist/api/status.mjs +1 -1
  54. package/dist/api/stream.mjs +1 -1
  55. package/dist/index.mjs +1 -1
  56. package/dist/lib/cache.mjs +2 -0
  57. package/dist/lib/capture.mjs +1 -1
  58. package/dist/lib/config.mjs +1 -1
  59. package/dist/lib/constraint.mjs +2 -0
  60. package/dist/lib/context.mjs +2 -0
  61. package/dist/lib/health.mjs +2 -0
  62. package/dist/lib/http.mjs +1 -1
  63. package/dist/lib/models.mjs +1 -1
  64. package/dist/lib/ndjson.mjs +4 -0
  65. package/dist/lib/ollama.mjs +3 -0
  66. package/dist/lib/passthrough.mjs +1 -1
  67. package/dist/lib/pool.mjs +1 -1
  68. package/dist/lib/presets.mjs +2 -0
  69. package/dist/lib/route.mjs +1 -1
  70. package/dist/lib/routes.mjs +1 -1
  71. package/dist/lib/settings.mjs +1 -1
  72. package/dist/lib/vllm.mjs +4 -0
  73. package/package.json +1 -1
  74. package/types/src/api/convert/anthropic/messages/to/ollama/chat/request.d.mts +14 -0
  75. package/types/src/api/convert/ollama/chat/to/anthropic/messages/response.d.mts +10 -0
  76. package/types/src/api/convert/ollama/chat/to/anthropic/messages/stream.d.mts +14 -0
  77. package/types/src/api/convert/ollama/chat/to/openai/chat/response.d.mts +10 -0
  78. package/types/src/api/convert/ollama/chat/to/openai/chat/stream.d.mts +13 -0
  79. package/types/src/api/convert/openai/chat/to/ollama/chat/request.d.mts +12 -0
  80. package/types/src/api/detect.d.mts +1 -1
  81. package/types/src/api/driver/azure/info.d.mts +2 -1
  82. package/types/src/api/driver/deepseek/info.d.mts +2 -1
  83. package/types/src/api/driver/fireworks/detect.d.mts +8 -0
  84. package/types/src/api/driver/fireworks/info.d.mts +13 -0
  85. package/types/src/api/driver/fireworks/path.d.mts +7 -0
  86. package/types/src/api/driver/fireworks/request.d.mts +7 -0
  87. package/types/src/api/driver/fireworks/settings.d.mts +5 -0
  88. package/types/src/api/driver/gemini/detect.d.mts +8 -0
  89. package/types/src/api/driver/gemini/info.d.mts +13 -0
  90. package/types/src/api/driver/gemini/path.d.mts +7 -0
  91. package/types/src/api/driver/gemini/request.d.mts +7 -0
  92. package/types/src/api/driver/gemini/settings.d.mts +5 -0
  93. package/types/src/api/driver/groq/detect.d.mts +8 -0
  94. package/types/src/api/driver/groq/info.d.mts +13 -0
  95. package/types/src/api/driver/groq/path.d.mts +7 -0
  96. package/types/src/api/driver/groq/request.d.mts +7 -0
  97. package/types/src/api/driver/groq/settings.d.mts +5 -0
  98. package/types/src/api/driver/mistral/info.d.mts +2 -1
  99. package/types/src/api/driver/ollama/info.d.mts +7 -2
  100. package/types/src/api/driver/openai/info.d.mts +3 -1
  101. package/types/src/api/driver/openrouter/info.d.mts +2 -1
  102. package/types/src/api/driver/together/detect.d.mts +8 -0
  103. package/types/src/api/driver/together/info.d.mts +13 -0
  104. package/types/src/api/driver/together/request.d.mts +7 -0
  105. package/types/src/api/driver/together/settings.d.mts +5 -0
  106. package/types/src/api/driver/vllm/detect.d.mts +1 -1
  107. package/types/src/api/driver/vllm/info.d.mts +1 -1
  108. package/types/src/api/driver/vllm/model/list.d.mts +3 -1
  109. package/types/src/api/driver/xai/detect.d.mts +8 -0
  110. package/types/src/api/driver/xai/info.d.mts +13 -0
  111. package/types/src/api/driver/xai/request.d.mts +7 -0
  112. package/types/src/api/driver/xai/settings.d.mts +5 -0
  113. package/types/src/api/endpoint/status.d.mts +5 -2
  114. package/types/src/api/health/check.d.mts +8 -0
  115. package/types/src/api/request.d.mts +1 -1
  116. package/types/src/api/send.d.mts +1 -1
  117. package/types/src/api/status.d.mts +1 -1
  118. package/types/src/lib/cache.d.mts +30 -0
  119. package/types/src/lib/config.d.mts +4 -0
  120. package/types/src/lib/constraint.d.mts +36 -0
  121. package/types/src/lib/context.d.mts +34 -0
  122. package/types/src/lib/events.d.mts +2 -2
  123. package/types/src/lib/health.d.mts +22 -0
  124. package/types/src/lib/models.d.mts +25 -0
  125. package/types/src/lib/ndjson.d.mts +16 -0
  126. package/types/src/lib/ollama.d.mts +86 -0
  127. package/types/src/lib/pool.d.mts +30 -4
  128. package/types/src/lib/presets.d.mts +99 -0
  129. package/types/src/lib/route.d.mts +1 -1
  130. package/types/src/lib/settings.d.mts +25 -0
  131. package/types/src/lib/vllm.d.mts +47 -0
package/README.md CHANGED
@@ -17,18 +17,19 @@ Use it as a library when you want the conversion without any I/O (`request`, `re
17
17
 
18
18
  ## ✨ What's New
19
19
 
20
- ### Latest: v0.9.0 (November 2026)
20
+ ### Latest: v0.11.0 (November 2026)
21
21
 
22
- - **Azure OpenAI and OpenRouter drivers** — Azure gets `api-key` auth and either the v1 API or the classic deployment URLs (set `apiVersion`, and `deployment` if it isn't the model name), with filtered categories named on content-filter errors. OpenRouter keeps `reasoning_details` round-tripping in order, turns errors returned inside a 200 into real errors, and maps effort and thinking budgets to its `reasoning` object.
23
- - **Hugging Face TGI and LocalAI drivers** — both are detected by probe. TGI's old reply quirks (a lone `tool_calls` object, numeric ids, object arguments, `eos_token`) are normalised and structured output goes out as its grammar. LocalAI's reasoning is read, and `disable_parallel_tool_use` is honoured even though LocalAI sets parallel calls per model.
24
- - [View full v0.9.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.9.0.md)
22
+ - **Constrained decoding** — a neutral `constraint` (JSON Schema, regex, choice list or grammar) is turned into each backend's native field: vLLM `structured_outputs` (or `guided_*` before 0.11.0), SGLang `regex` and `ebnf`, llama.cpp `grammar` and `json_schema`, and TGI's grammar. A kind a backend can't enforce is dropped and recorded, or rejected.
23
+ - **`clear_tool_uses` context edits** — `context_management` edits are applied locally before an OpenAI-protocol upstream sees the conversation, and the reply reports them in `applied_edits`.
24
+ - **Prompt-cache hints** — `cache_salt` (set by the server, vLLM only) and `prompt_cache_key` (OpenAI only) are mapped, with docs on what is and isn't cached. Hosted APIs such as `api.openai.com` now bind by host name before any driver probes them.
25
+ - [View full v0.11.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.11.0.md)
25
26
 
26
27
  ### Recent Releases
27
28
 
29
+ - **v0.10.0** (November 2026) — native `/v1/messages` for vLLM, readiness probes and LoRA adapters, Groq, Together, Fireworks, xAI and Gemini drivers, and Ollama's native `/api/chat` ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.10.0.md))
30
+ - **v0.9.0** (November 2026) — Azure OpenAI, OpenRouter, Hugging Face TGI and LocalAI drivers, with Azure's `apiVersion` and `deployment` upstream fields and more startup probes ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.9.0.md))
28
31
  - **v0.8.0** (November 2026) — Mistral and LM Studio drivers, an OpenAI client's `n` above 1 answered by parallel requests to Anthropic-protocol upstreams, and `stop_details.category` from content-filter results ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.8.0.md))
29
32
  - **v0.7.0** (November 2026) — Anthropic-protocol servers detected by probe on any host, tool-call ids rewritten for strict upstream formats, embeddings usage through `onUsage`, and capture records for every failed-over attempt ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.7.0.md))
30
- - **v0.6.0** (November 2026) — `POST /v1/embeddings` pass-through, sampling extensions per upstream and per request, `strict` tool use end to end with a schema check, and the `capture` option for debugging ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.6.0.md))
31
- - **v0.5.0** (November 2026) — everything the library logs is available as events, logging is opt-in through `logs`, `json_object` reaches Anthropic upstreams as a schema with a fallback, and refusals carry `stop_details` ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.5.0.md))
32
33
 
33
34
  📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/llm-translator/tree/master/docs/changelog/) folder.**
34
35
 
@@ -127,7 +128,7 @@ Then point Claude Code at it with `ANTHROPIC_BASE_URL=http://127.0.0.1:8787`. Th
127
128
 
128
129
  ## 📚 Configuration
129
130
 
130
- `createTranslator(config)` takes `front`, `upstreams` (URLs or objects with `url`, `apiKey`, `backend`, `models`, `default` and `settings`, plus `apiVersion` and `deployment` for Azure OpenAI, see [docs/drivers.md](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md#azure-openai)), `aliases` (a model name, or `{ model, effort, thinking }` to pin settings), `efforts` (the reasoning levels each model supports, see [docs/settings.md](https://github.com/CLDMV/llm-translator/blob/master/docs/settings.md#effort-levels-and-pinned-aliases-not-converter-settings)), global `settings`, `pool` (failover and load balancing between upstreams that serve the same model, see [docs/server.md](https://github.com/CLDMV/llm-translator/blob/master/docs/server.md#endpoint-pools-failover-and-load-balancing)), `detect`, `logs` (off by default; `true` prints warnings, a path appends JSON lines), `events` and `onEvent` (see [docs/events.md](https://github.com/CLDMV/llm-translator/blob/master/docs/events.md)), `capture` (off by default; a directory or a callback receives redacted request and response records for debugging, see [docs/events.md](https://github.com/CLDMV/llm-translator/blob/master/docs/events.md#capture-for-debugging)) and a custom `transport`. `silent: true` is a deprecated alias for `logs: false`. The CLI reads the same keys from flags, `LLM_TRANSLATOR_*` environment variables and a JSON file, in that order of precedence.
131
+ `createTranslator(config)` takes `front`, `upstreams` (URLs or objects with `url`, `apiKey`, `backend`, `models`, `default` and `settings`, plus `apiVersion` and `deployment` for Azure OpenAI, see [docs/drivers.md](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md#azure-openai), and `api: "native"` for Ollama's own `/api/chat`, see [docs/drivers.md](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md#native-apichat-mode)), `aliases` (a model name, or `{ model, effort, thinking }` to pin settings), `efforts` (the reasoning levels each model supports, see [docs/settings.md](https://github.com/CLDMV/llm-translator/blob/master/docs/settings.md#effort-levels-and-pinned-aliases-not-converter-settings)), global `settings`, `pool` (failover and load balancing between upstreams that serve the same model, see [docs/server.md](https://github.com/CLDMV/llm-translator/blob/master/docs/server.md#endpoint-pools-failover-and-load-balancing)), `detect`, `logs` (off by default; `true` prints warnings, a path appends JSON lines), `events` and `onEvent` (see [docs/events.md](https://github.com/CLDMV/llm-translator/blob/master/docs/events.md)), `capture` (off by default; a directory or a callback receives redacted request and response records for debugging, see [docs/events.md](https://github.com/CLDMV/llm-translator/blob/master/docs/events.md#capture-for-debugging)) and a custom `transport`. `silent: true` is a deprecated alias for `logs: false`. The CLI reads the same keys from flags, `LLM_TRANSLATOR_*` environment variables and a JSON file, in that order of precedence.
131
132
 
132
133
  Settings tune how the converters map one protocol onto the other (`inlineSystem`, `images`, `imageFallback`, `toolStreaming`, `pingInterval` and more); they are resolved per upstream from defaults, probed values, driver defaults and your overrides. The full table is in [docs/settings.md](https://github.com/CLDMV/llm-translator/blob/master/docs/settings.md).
133
134
 
@@ -0,0 +1,2 @@
1
+ var p=Object.defineProperty;var n=(e,a)=>p(e,"name",{value:a,configurable:!0});import{resolve as m}from"../../../../../../../lib/settings.mjs";import{chatBody as c}from"../../../../../../../lib/ollama.mjs";import{request as f}from"../../openai/chat/request.mjs";const d={maxTokensField:"max_tokens",thinking:"chat_template_kwargs",thinkingBudget:!1,effort:!0,topK:!0,prefill:"none",streamUsage:!1,continuousUsage:!1,parallelToolCalls:!1,reasoningRoundTrip:!1,reasoningField:"reasoning_content",responseFormat:!0};async function y(e,a,r){const o=m(a),{body:l,state:s}=await f(e,{...o,...d},r),t=e.metadata?.sampling,i={...o.sampling,...t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}};return{body:c(l,{dropped:s.dropped,sampling:i}),state:s}}n(y,"request");export{y as request};
2
+ //# sourceMappingURL=request.mjs.map
@@ -1,17 +1,17 @@
1
- var M=Object.defineProperty;var g=(e,t)=>M(e,"name",{value:t,configurable:!0});import{resolve as O}from"../../../../../../../lib/settings.mjs";import{TranslatorError as j}from"../../../../../../../lib/errors.mjs";import{createIdFitter as q,createNameFitter as B}from"../../../../../../../lib/ids.mjs";import{sanitize as C}from"../../../../../../../lib/schema.mjs";import{NOTE as A}from"../../../../../../../lib/images.mjs";import{expand as L}from"../../../../../../../lib/documents.mjs";import{createBudget as z,unsign as D}from"../../../../../../../lib/thinking.mjs";import{plan as P,scan as W}from"../../../../../../../lib/toolsearch.mjs";const H=new Set(["model","messages","system","max_tokens","stream","temperature","top_p","top_k","stop_sequences","tools","tool_choice","thinking","output_config","output_format","context_management"]),K=new Set(["metadata","cache_control","service_tier"]),R=new Set(["mcp_servers","container","inference_geo"]),U="x-anthropic-billing-header:";async function pe(e,t,o){const n=O(t);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new j("messages: Field required",{code:"invalid_request",param:"messages"});const s={front:"anthropic",model:e.model,stream:e.stream===!0,thinking:e.thinking?.type??null,reasoningField:n.reasoningField,toolNames:{},toolIds:{},dropped:[]};e.thinking?.type==="enabled"&&Number.isInteger(e.thinking.budget_tokens)&&e.output_config?.effort===void 0&&(s.thinkingBudget=e.thinking.budget_tokens),o?.producer!==void 0&&(s.producer=o.producer);const i=B({max:64,map:s.toolNames}),d=o?.toolCallIds?q({policy:o.toolCallIds,ids:G(e.messages),map:s.toolIds}):c=>c;for(const c of e.tools??[])(c.type===void 0||c.type==="custom")&&i(c.name);const m=W(e.messages,new Set((e.tools??[]).map(c=>c.name))),a=P(e.tools??[],m,n,e.tool_choice);s.toolSearch={mode:n.toolSearch,loaded:a.loaded,hidden:a.hidden,stubbed:a.stubbed,capped:m.capped};for(const c of Object.keys(e))if(!(H.has(c)||K.has(c)))if(R.has(c))x(s,c);else{if(n.unknownFields==="error")throw new j(`${c}: Extra inputs are not permitted`,{code:"unsupported_field",param:c});x(s,c)}const u={model:e.model},$=E(e.system,n),f=await J(e.messages,n,s,i,d,$,Q(e.context_management,s),o?.budget??z());u.messages=f.messages,f.prefill&&(u.continue_final_message=!0,u.add_generation_prompt=!1),e.max_tokens!==void 0&&(u[n.maxTokensField]=e.max_tokens),e.temperature!==void 0&&(u.temperature=e.temperature),e.top_p!==void 0&&(u.top_p=e.top_p),e.top_k!==void 0&&(n.topK?u.top_k=e.top_k:x(s,"top_k")),e.stop_sequences?.length>0&&(u.stop=e.stop_sequences),s.stream&&(u.stream=!0,n.streamUsage&&(u.stream_options={include_usage:!0},n.continuousUsage&&(u.stream_options.continuous_usage_stats=!0)));const h=b(a.offer,n,s,i);if(h.length>0){u.tools=h;const c=ee(e.tool_choice,n,s,i);c!==void 0&&(u.tool_choice=c),e.tool_choice?.disable_parallel_tool_use===!0&&n.parallelToolCalls&&(u.parallel_tool_calls=!1)}return te(e,n,u,o?.listed===!0),ne(e,n,s,u),{body:u,state:s}}g(pe,"request");function x(e,t){e.dropped.includes(t)||e.dropped.push(t)}g(x,"drop");function F(e,t,o){if(t.unknownFields==="error")throw new j(`${o}: is not supported by this translator`,{code:"unsupported_content",param:o});x(e,o)}g(F,"unsupported");function E(e,t){return e==null?"":(typeof e=="string"?[{type:"text",text:e}]:e).filter(n=>n.type==="text"&&!(t.stripBillingHeader&&n.text.trimStart().startsWith(U))).map(n=>n.text).join(`
1
+ var O=Object.defineProperty;var d=(e,n)=>O(e,"name",{value:n,configurable:!0});import{resolve as q}from"../../../../../../../lib/settings.mjs";import{TranslatorError as j}from"../../../../../../../lib/errors.mjs";import{createIdFitter as B,createNameFitter as C}from"../../../../../../../lib/ids.mjs";import{sanitize as A}from"../../../../../../../lib/schema.mjs";import{NOTE as L}from"../../../../../../../lib/images.mjs";import{expand as U}from"../../../../../../../lib/documents.mjs";import{createBudget as W,unsign as z}from"../../../../../../../lib/thinking.mjs";import{clearToolUses as D,valid as P}from"../../../../../../../lib/context.mjs";import{plan as H,scan as K}from"../../../../../../../lib/toolsearch.mjs";const R=new Set(["model","messages","system","max_tokens","stream","temperature","top_p","top_k","stop_sequences","tools","tool_choice","thinking","output_config","output_format","context_management"]),G=new Set(["metadata","cache_control","service_tier"]),J=new Set(["mcp_servers","container","inference_geo"]),Q="x-anthropic-billing-header:";async function he(e,n,o){const t=q(n);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new j("messages: Field required",{code:"invalid_request",param:"messages"});const s={front:"anthropic",model:e.model,stream:e.stream===!0,thinking:e.thinking?.type??null,reasoningField:t.reasoningField,toolNames:{},toolIds:{},dropped:[]};e.thinking?.type==="enabled"&&Number.isInteger(e.thinking.budget_tokens)&&e.output_config?.effort===void 0&&(s.thinkingBudget=e.thinking.budget_tokens),o?.producer!==void 0&&(s.producer=o.producer);const i=C({max:64,map:s.toolNames}),m=o?.toolCallIds?B({policy:o.toolCallIds,ids:V(e.messages),map:s.toolIds}):c=>c;for(const c of e.tools??[])(c.type===void 0||c.type==="custom")&&i(c.name);const g=K(e.messages,new Set((e.tools??[]).map(c=>c.name))),a=H(e.tools??[],g,t,e.tool_choice);s.toolSearch={mode:t.toolSearch,loaded:a.loaded,hidden:a.hidden,stubbed:a.stubbed,capped:g.capped};for(const c of Object.keys(e))if(!(R.has(c)||G.has(c)))if(J.has(c))h(s,c);else{if(t.unknownFields==="error")throw new j(`${c}: Extra inputs are not permitted`,{code:"unsupported_field",param:c});h(s,c)}const l={model:e.model},$=I(e.system,t),u=await X(e.messages,t,s,i,m,$,Y(e.context_management,s),o?.budget??W());l.messages=u.messages,u.prefill&&(l.continue_final_message=!0,l.add_generation_prompt=!1),e.max_tokens!==void 0&&(l[t.maxTokensField]=e.max_tokens),e.temperature!==void 0&&(l.temperature=e.temperature),e.top_p!==void 0&&(l.top_p=e.top_p),e.top_k!==void 0&&(t.topK?l.top_k=e.top_k:h(s,"top_k")),e.stop_sequences?.length>0&&(l.stop=e.stop_sequences),s.stream&&(l.stream=!0,t.streamUsage&&(l.stream_options={include_usage:!0},t.continuousUsage&&(l.stream_options.continuous_usage_stats=!0)));const x=oe(a.offer,t,s,i);if(x.length>0){l.tools=x;const c=se(e.tool_choice,t,s,i);c!==void 0&&(l.tool_choice=c),e.tool_choice?.disable_parallel_tool_use===!0&&t.parallelToolCalls&&(l.parallel_tool_calls=!1)}return Z(e.context_management,l,s),ie(e,t,l,o?.listed===!0),re(e,t,s,l),{body:l,state:s}}d(he,"request");function h(e,n){e.dropped.includes(n)||e.dropped.push(n)}d(h,"drop");function v(e,n,o){if(n.unknownFields==="error")throw new j(`${o}: is not supported by this translator`,{code:"unsupported_content",param:o});h(e,o)}d(v,"unsupported");function I(e,n){return e==null?"":(typeof e=="string"?[{type:"text",text:e}]:e).filter(t=>t.type==="text"&&!(n.stripBillingHeader&&t.text.trimStart().startsWith(Q))).map(t=>t.text).join(`
2
2
 
3
- `)}g(E,"textOf");function T(e){return typeof e=="string"?[{type:"text",text:e}]:e??[]}g(T,"asBlocks");function G(e){const t=[];for(const o of e)for(const n of T(o.content))n.type==="tool_use"?t.push(n.id):n.type==="tool_result"&&t.push(n.tool_use_id);return t}g(G,"idsOf");async function J(e,t,o,n,s,i,d,m){const a=[],u=[],$=new Map,f=t.inlineSystem==="auto"?"user":t.inlineSystem,h=new Map;if(t.reasoningRoundTrip){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant")for(const l of[...T(e[r].content)].reverse())l.type==="thinking"&&h.set(l,await D(l.signature,{producer:o.producer,budget:m}))}const c=g(r=>{const l=a.at(-1);l?.role==="user"?l.parts.push(...r):a.push({role:"user",parts:r})},"pushUser"),v=g(async(r,l)=>{switch(r.type){case"text":return r.text===""?[]:[{type:"text",text:r.text}];case"image":return Z(r,t,o);case"document":{const _=[];for(const p of await L(r,{settings:t,toolInputs:$,toolUseId:l}))_.push(...await v(p,l));return _}case"search_result":{const _=(r.content??[]).map(p=>p.text).join(`
3
+ `)}d(I,"textOf");function S(e){return typeof e=="string"?[{type:"text",text:e}]:e??[]}d(S,"asBlocks");function V(e){const n=[];for(const o of e)for(const t of S(o.content))t.type==="tool_use"?n.push(t.id):t.type==="tool_result"&&n.push(t.tool_use_id);return n}d(V,"idsOf");async function X(e,n,o,t,s,i,m,g){const a=[],l=[],$=new Map,u=n.inlineSystem==="auto"?"user":n.inlineSystem,x=new Map;if(n.reasoningRoundTrip){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant")for(const f of[...S(e[r].content)].reverse())f.type==="thinking"&&x.set(f,await z(f.signature,{producer:o.producer,budget:g}))}const c=d(r=>{const f=a.at(-1);f?.role==="user"?f.parts.push(...r):a.push({role:"user",parts:r})},"pushUser"),E=d(async(r,f)=>{switch(r.type){case"text":return r.text===""?[]:[{type:"text",text:r.text}];case"image":return ne(r,n,o);case"document":{const _=[];for(const p of await U(r,{settings:n,toolInputs:$,toolUseId:f}))_.push(...await E(p,f));return _}case"search_result":{const _=(r.content??[]).map(p=>p.text).join(`
4
4
  `);return[{type:"text",text:`[Search result: ${r.title??""} (${r.source??""})]
5
- ${_}`}]}case"tool_reference":return t.toolSearch==="native"&&t.deferredTools!=="drop"?[{type:"tool_reference",tool_name:r.tool_name}]:[{type:"text",text:o.toolSearch.loaded.includes(r.tool_name)?`[Tool loaded: ${r.tool_name}]`:`[Tool reference: ${r.tool_name}]`}];default:return F(o,t,`block:${r.type}`),[]}},"toParts");for(const r of e)if(r.role==="system"){const l=E(r.content,t);if(l===""||f==="drop")continue;if(f==="keep")a.push({role:"system",content:l});else if(f==="hoist")u.push(l);else{const _=l.trimStart().startsWith("<system-reminder>")?l:`<system-reminder>
6
- ${l}
7
- </system-reminder>`;c([{type:"text",text:_}])}}else if(r.role==="user"){const l=[],_=[];for(const y of T(r.content)){if(y.type!=="tool_result"){l.push(...await v(y,null));continue}const S=[];for(const k of T(y.content))S.push(...await v(k,y.tool_use_id));const N=S.filter(k=>k.type==="text").map(k=>k.text),I=S.filter(k=>k.type==="image_url");let w=S.some(k=>k.type==="tool_reference")?S.filter(k=>k.type!=="image_url"):N.join(`
8
- `);I.length>0&&(_.push({type:"text",text:`Image output of tool call ${s(y.tool_use_id)}:`},...I),w===""&&(w="(image output attached in the next message)")),y.is_error===!0&&t.toolErrors&&(w=typeof w=="string"?`${t.toolErrorMarker}${w}`:[{type:"text",text:t.toolErrorMarker.trimEnd()},...w]),a.push({role:"tool",tool_call_id:s(y.tool_use_id),content:w})}const p=[..._,...l];p.length>0&&c(p)}else if(r.role==="assistant"){const l={role:"assistant",texts:[],parts:[],tool_calls:[]};for(const p of T(r.content))if(p.type==="text")p.text!==""&&l.texts.push(p.text);else if(p.type==="thinking"){const y=h.get(p)??null;y?l.parts.push({restored:y}):p.thinking&&l.parts.push({text:p.thinking})}else p.type==="redacted_thinking"?x(o,"redacted_thinking"):p.type==="tool_use"?($.set(p.id,p.input),l.tool_calls.push({id:s(p.id),type:"function",function:{name:n(p.name),arguments:JSON.stringify(p.input??{})}})):F(o,t,`block:${p.type}`);const _=a.at(-1);_?.role==="assistant"?(_.texts.push(...l.texts),_.parts.push(...l.parts),_.tool_calls.push(...l.tool_calls)):a.push(l)}else throw new j(`messages: unsupported role "${r.role}"`,{code:"invalid_request",param:"messages"});return Y(a,t,i,u,d,o)}g(J,"convertMessages");function Q(e,t){let o=1/0;for(const n of e?.edits??[])typeof n.type=="string"&&n.type.startsWith("clear_thinking")?n.keep==="all"?o=1/0:o=n.keep?.value??1:x(t,`context_management.${n.type}`);return o}g(Q,"thinkingTurnsToKeep");function V(e,t){const o=e.find(a=>a.restored&&(a.restored.reasoning_content!==void 0||a.restored.reasoning!==void 0)),n=o?o.restored.reasoning_content!==void 0?"reasoning_content":"reasoning":t;let s="",i,d=null;for(const a of e){const u=a.restored?a.restored.reasoning_content??a.restored.reasoning:a.text;a.restored?.reasoning_details&&(i=[...i??[],...a.restored.reasoning_details]),u!==void 0&&(s+=(d!==null&&!(d.restored&&a.restored)?`
5
+ ${_}`}]}case"tool_reference":return n.toolSearch==="native"&&n.deferredTools!=="drop"?[{type:"tool_reference",tool_name:r.tool_name}]:[{type:"text",text:o.toolSearch.loaded.includes(r.tool_name)?`[Tool loaded: ${r.tool_name}]`:`[Tool reference: ${r.tool_name}]`}];default:return v(o,n,`block:${r.type}`),[]}},"toParts");for(const r of e)if(r.role==="system"){const f=I(r.content,n);if(f===""||u==="drop")continue;if(u==="keep")a.push({role:"system",content:f});else if(u==="hoist")l.push(f);else{const _=f.trimStart().startsWith("<system-reminder>")?f:`<system-reminder>
6
+ ${f}
7
+ </system-reminder>`;c([{type:"text",text:_}])}}else if(r.role==="user"){const f=[],_=[];for(const y of S(r.content)){if(y.type!=="tool_result"){f.push(...await E(y,null));continue}const T=[];for(const k of S(y.content))T.push(...await E(k,y.tool_use_id));const M=T.filter(k=>k.type==="text").map(k=>k.text),F=T.filter(k=>k.type==="image_url");let w=T.some(k=>k.type==="tool_reference")?T.filter(k=>k.type!=="image_url"):M.join(`
8
+ `);F.length>0&&(_.push({type:"text",text:`Image output of tool call ${s(y.tool_use_id)}:`},...F),w===""&&(w="(image output attached in the next message)")),y.is_error===!0&&n.toolErrors&&(w=typeof w=="string"?`${n.toolErrorMarker}${w}`:[{type:"text",text:n.toolErrorMarker.trimEnd()},...w]),a.push({role:"tool",tool_call_id:s(y.tool_use_id),content:w})}const p=[..._,...f];p.length>0&&c(p)}else if(r.role==="assistant"){const f={role:"assistant",texts:[],parts:[],tool_calls:[]};for(const p of S(r.content))if(p.type==="text")p.text!==""&&f.texts.push(p.text);else if(p.type==="thinking"){const y=x.get(p)??null;y?f.parts.push({restored:y}):p.thinking&&f.parts.push({text:p.thinking})}else p.type==="redacted_thinking"?h(o,"redacted_thinking"):p.type==="tool_use"?($.set(p.id,p.input),f.tool_calls.push({id:s(p.id),type:"function",function:{name:t(p.name),arguments:JSON.stringify(p.input??{})}})):v(o,n,`block:${p.type}`);const _=a.at(-1);_?.role==="assistant"?(_.texts.push(...f.texts),_.parts.push(...f.parts),_.tool_calls.push(...f.tool_calls)):a.push(f)}else throw new j(`messages: unsupported role "${r.role}"`,{code:"invalid_request",param:"messages"});return te(a,n,i,l,m,o)}d(X,"convertMessages");function Y(e,n){let o=1/0;for(const t of e?.edits??[])typeof t.type=="string"&&t.type.startsWith("clear_thinking")?t.keep==="all"?o=1/0:o=t.keep?.value??1:N(t)||h(n,`context_management.${t.type}`);return o}d(Y,"thinkingTurnsToKeep");function N(e){return typeof e.type=="string"&&e.type.startsWith("clear_tool_uses")}d(N,"isClearToolUses");function Z(e,n,o){for(const t of e?.edits??[]){if(!N(t))continue;if(!P(t)){h(o,`context_management.${t.type}`);continue}o.appliedEdits??=[];const s=D(t,n,o.toolNames);s&&o.appliedEdits.push(s)}}d(Z,"applyContextEdits");function b(e,n){const o=e.find(a=>a.restored&&(a.restored.reasoning_content!==void 0||a.restored.reasoning!==void 0)),t=o?o.restored.reasoning_content!==void 0?"reasoning_content":"reasoning":n;let s="",i,m=null;for(const a of e){const l=a.restored?a.restored.reasoning_content??a.restored.reasoning:a.text;a.restored?.reasoning_details&&(i=[...i??[],...a.restored.reasoning_details]),l!==void 0&&(s+=(m!==null&&!(m.restored&&a.restored)?`
9
9
 
10
- `:"")+u,d=a)}const m={};return s!==""&&(m[n]=s),i&&(m.reasoning_details=i),m}g(V,"reasoningFields");function X(e){return!!(e.reasoning_content||e.reasoning||e.reasoning_details)}g(X,"reasoningSent");function Y(e,t,o,n,s,i){let d=s;for(let f=e.length-1;f>=0;f--)e[f].role!=="assistant"||e[f].parts.length===0||(d>0?d--:e[f].parts=[]);const m=[],a=[o,...n].filter(f=>f!=="").join(`
10
+ `:"")+l,m=a)}const g={};return s!==""&&(g[t]=s),i&&(g.reasoning_details=i),g}d(b,"reasoningFields");function ee(e){return!!(e.reasoning_content||e.reasoning||e.reasoning_details)}d(ee,"reasoningSent");function te(e,n,o,t,s,i){let m=s;for(let u=e.length-1;u>=0;u--)e[u].role!=="assistant"||e[u].parts.length===0||(m>0?m--:e[u].parts=[]);const g=[],a=[o,...t].filter(u=>u!=="").join(`
11
11
 
12
- `);a!==""&&m.push({role:"system",content:a});for(const f of e)if(f.role==="user"){const h=f.parts.every(c=>c.type==="text");m.push({role:"user",content:h?f.parts.map(c=>c.text).join(`
12
+ `);a!==""&&g.push({role:"system",content:a});for(const u of e)if(u.role==="user"){const x=u.parts.every(c=>c.type==="text");g.push({role:"user",content:x?u.parts.map(c=>c.text).join(`
13
13
 
14
- `):f.parts})}else if(f.role==="assistant"){const h={role:"assistant",content:f.texts.join(`
14
+ `):u.parts})}else if(u.role==="assistant"){const x={role:"assistant",content:u.texts.join(`
15
15
 
16
- `)};f.parts.length>0&&Object.assign(h,V(f.parts,t.reasoningField)),t.reasoningRoundTrip&&f.tool_calls.length>0&&!X(h)&&(i.reasoningMissing=(i.reasoningMissing??0)+1),f.tool_calls.length>0&&(h.tool_calls=f.tool_calls),m.push(h)}else m.push(f);const u=m.at(-1),$=t.prefill==="continue_final_message"&&u?.role==="assistant"&&!u.tool_calls&&u.content!=="";return{messages:m,prefill:$}}g(Y,"finalize");function Z(e,t,o){if(!t.images)return x(o,"image"),[{type:"text",text:A}];const n=e.source;return n.type==="base64"?[{type:"image_url",image_url:{url:`data:${n.media_type};base64,${n.data}`}}]:n.type==="url"?[{type:"image_url",image_url:{url:n.url}}]:(x(o,"image.file"),[{type:"text",text:"[An image supplied as an uploaded file could not be forwarded.]"}])}g(Z,"imageParts");function b(e,t,o,n){const s=[];for(const i of e){if(i.type!==void 0&&i.type!=="custom"){x(o,`tool:${i.name}`);continue}if(i.defer_loading===!0&&t.deferredTools==="drop"){x(o,"deferred_tools");continue}const d=i.input_schema??{type:"object",properties:{}},m={name:n(i.name),parameters:t.toolSchema==="sanitize"?C(d):d};i.description!==void 0&&(m.description=i.description),i.strict!==void 0&&(m.strict=i.strict),s.push(i.defer_loading===!0&&t.toolSearch==="native"?{type:"function",function:m,defer_loading:!0}:{type:"function",function:m})}return s}g(b,"convertTools");function ee(e,t,o,n){switch(e?.type){case void 0:return;case"auto":return"auto";case"any":return"required";case"none":return"none";case"tool":return{type:"function",function:{name:n(e.name)}};default:F(o,t,`tool_choice:${e.type}`);return}}g(ee,"convertToolChoice");function te(e,t,o,n){const s=e.thinking,i=s?.type;let d;i==="disabled"?(t.thinking==="reasoning_effort"&&(d="none"),t.thinking==="chat_template_kwargs"&&(o.chat_template_kwargs={enable_thinking:!1})):(t.effort&&e.output_config?.effort!==void 0&&(d=e.output_config.effort),i==="enabled"&&(t.thinking==="chat_template_kwargs"&&(o.chat_template_kwargs={enable_thinking:!0},t.thinkingBudget&&s.budget_tokens!==void 0&&e.max_tokens!==void 0&&(o.thinking_token_budget=Math.max(0,Math.min(s.budget_tokens,e.max_tokens-1)))),t.thinking==="reasoning_effort"&&d===void 0&&!n&&(d="medium"))),d!==void 0&&(o.reasoning_effort=d)}g(te,"applyThinking");function ne(e,t,o,n){const s=e.output_config?.format??e.output_format;s!==void 0&&(t.responseFormat&&s.type==="json_schema"?n.response_format={type:"json_schema",json_schema:{name:"output",schema:s.schema}}:x(o,"output_config.format"));for(const i of Object.keys(e.output_config??{}))i!=="effort"&&i!=="format"&&x(o,`output_config.${i}`)}g(ne,"applyOutputConfig");export{pe as request};
16
+ `)};u.parts.length>0&&Object.assign(x,b(u.parts,n.reasoningField)),n.reasoningRoundTrip&&u.tool_calls.length>0&&!ee(x)&&(i.reasoningMissing=(i.reasoningMissing??0)+1),u.tool_calls.length>0&&(x.tool_calls=u.tool_calls),g.push(x)}else g.push(u);const l=g.at(-1),$=n.prefill==="continue_final_message"&&l?.role==="assistant"&&!l.tool_calls&&l.content!=="";return{messages:g,prefill:$}}d(te,"finalize");function ne(e,n,o){if(!n.images)return h(o,"image"),[{type:"text",text:L}];const t=e.source;return t.type==="base64"?[{type:"image_url",image_url:{url:`data:${t.media_type};base64,${t.data}`}}]:t.type==="url"?[{type:"image_url",image_url:{url:t.url}}]:(h(o,"image.file"),[{type:"text",text:"[An image supplied as an uploaded file could not be forwarded.]"}])}d(ne,"imageParts");function oe(e,n,o,t){const s=[];for(const i of e){if(i.type!==void 0&&i.type!=="custom"){h(o,`tool:${i.name}`);continue}if(i.defer_loading===!0&&n.deferredTools==="drop"){h(o,"deferred_tools");continue}const m=i.input_schema??{type:"object",properties:{}},g={name:t(i.name),parameters:n.toolSchema==="sanitize"?A(m):m};i.description!==void 0&&(g.description=i.description),i.strict!==void 0&&(g.strict=i.strict),s.push(i.defer_loading===!0&&n.toolSearch==="native"?{type:"function",function:g,defer_loading:!0}:{type:"function",function:g})}return s}d(oe,"convertTools");function se(e,n,o,t){switch(e?.type){case void 0:return;case"auto":return"auto";case"any":return"required";case"none":return"none";case"tool":return{type:"function",function:{name:t(e.name)}};default:v(o,n,`tool_choice:${e.type}`);return}}d(se,"convertToolChoice");function ie(e,n,o,t){const s=e.thinking,i=s?.type;let m;i==="disabled"?(n.thinking==="reasoning_effort"&&(m="none"),n.thinking==="chat_template_kwargs"&&(o.chat_template_kwargs={enable_thinking:!1})):(n.effort&&e.output_config?.effort!==void 0&&(m=e.output_config.effort),i==="enabled"&&(n.thinking==="chat_template_kwargs"&&(o.chat_template_kwargs={enable_thinking:!0},n.thinkingBudget&&s.budget_tokens!==void 0&&e.max_tokens!==void 0&&(o.thinking_token_budget=Math.max(0,Math.min(s.budget_tokens,e.max_tokens-1)))),n.thinking==="reasoning_effort"&&m===void 0&&!t&&(m="medium"))),m!==void 0&&(o.reasoning_effort=m)}d(ie,"applyThinking");function re(e,n,o,t){const s=e.output_config?.format??e.output_format;s!==void 0&&(n.responseFormat&&s.type==="json_schema"?t.response_format={type:"json_schema",json_schema:{name:"output",schema:s.schema}}:h(o,"output_config.format"));for(const i of Object.keys(e.output_config??{}))i!=="effort"&&i!=="format"&&h(o,`output_config.${i}`)}d(re,"applyOutputConfig");export{he as request};
17
17
  //# sourceMappingURL=request.mjs.map
@@ -0,0 +1,2 @@
1
+ var m=Object.defineProperty;var e=(o,r)=>m(o,"name",{value:r,configurable:!0});import{completion as n}from"../../../../../../../lib/ollama.mjs";import{response as p}from"../../../../../openai/chat/to/anthropic/messages/response.mjs";function a(o,r,t){return p(n(o),r,t)}e(a,"response");export{a as response};
2
+ //# sourceMappingURL=response.mjs.map
@@ -0,0 +1,2 @@
1
+ var a=Object.defineProperty;var o=(r,t)=>a(r,"name",{value:t,configurable:!0});import{createChunker as f}from"../../../../../../../lib/ollama.mjs";import{parse as m}from"../../../../../../../lib/ndjson.mjs";import{stream as s}from"../../../../../openai/chat/to/anthropic/messages/stream.mjs";function h(r,t,i){const e=f();return s((async function*(){for await(const n of m(r))yield*e.line(n);e.finished()&&(yield{data:"[DONE]"})})(),t,i)}o(h,"stream");export{h as stream};
2
+ //# sourceMappingURL=stream.mjs.map
@@ -0,0 +1,2 @@
1
+ var d=Object.defineProperty;var r=(e,o)=>d(e,"name",{value:o,configurable:!0});import{resolve as m}from"../../../../../../../lib/settings.mjs";import{completion as l,folded as f}from"../../../../../../../lib/ollama.mjs";function g(e,o,i){const n=l(e,{reasoningField:m(i).reasoningField});return o&&(o.upstreamUsage=f(n.usage)),o?.model===void 0?n:{...n,model:o.model}}r(g,"response");export{g as response};
2
+ //# sourceMappingURL=response.mjs.map
@@ -0,0 +1,2 @@
1
+ var s=Object.defineProperty;var n=(a,e)=>s(a,"name",{value:e,configurable:!0});import{resolve as c}from"../../../../../../../lib/settings.mjs";import{createChunker as u,folded as f}from"../../../../../../../lib/ollama.mjs";import{parse as m}from"../../../../../../../lib/ndjson.mjs";async function*k(a,e,t){const o=u({model:e?.model,reasoningField:c(t).reasoningField,includeUsage:e?.includeUsage??!0}),d=n((r,i="api_error")=>({data:{error:{message:r,type:i,param:null,code:null}}}),"failure");try{for await(const r of m(a)){const i=o.line(r);e&&o.usage()!==void 0&&(e.upstreamUsage=f(o.usage()));for(const l of i)if(yield{data:l},l.error){yield{data:"[DONE]"};return}}}catch(r){yield d(r.message,r.type??"api_error"),yield{data:"[DONE]"};return}o.finished()||(yield d("Upstream stream ended before completion")),yield{data:"[DONE]"}}n(k,"stream");export{k as stream};
2
+ //# sourceMappingURL=stream.mjs.map
@@ -1,2 +1,2 @@
1
- var _=Object.defineProperty;var p=(o,t)=>_(o,"name",{value:t,configurable:!0});import{resolve as k}from"../../../../../../../lib/settings.mjs";import{TranslatorError as u}from"../../../../../../../lib/errors.mjs";import{messageId as T,anthropicToolId as x,restoreName as A}from"../../../../../../../lib/ids.mjs";import{sign as w,reasoningOf as C,reasoningKey as I,detailsText as N,splitThink as O}from"../../../../../../../lib/thinking.mjs";import{isComplete as S,parseArguments as U}from"../../../../../../../lib/arguments.mjs";import{filterCategory as v,finishError as E,toAnthropicStop as b,toAnthropicUsage as j}from"../../../../../../../lib/finish.mjs";function G(o,t,m){const c=k(m),i=o?.choices?.[0];if(!i)throw new u("Upstream response contained no choices",{code:"invalid_upstream_response",status:502});const g=E(i.finish_reason);if(g)throw new u(g.message,{code:g.code,status:g.status,type:g.type});const e=i.message??{},a=[];let l=C(e),s=typeof e.content=="string"?e.content:"";const n={};if(c.reasoningRoundTrip){const r=I(e);r&&(n[r]=e[r]),Array.isArray(e.reasoning_details)&&e.reasoning_details.length>0&&(n.reasoning_details=e.reasoning_details)}l===""&&c.thinkTags&&({reasoning:l,text:s}=O(s,c.thinkOpen)),l===""&&n.reasoning_details&&(l=N(n.reasoning_details)),(l!==""||n.reasoning_details)&&(a.push({type:"thinking",thinking:l,signature:w(Object.keys(n).length>0?n:void 0,t?.producer)}),s=s.trimStart()),s===""&&typeof e.refusal=="string"&&(s=e.refusal),s!==""&&a.push({type:"text",text:s});const d=t?.toolNames??{},h=t?.toolIds??{},f=e.tool_calls??[];for(const r of f)a.push({type:"tool_use",id:x(r.id,h),name:A(d,r.function.name),input:U(r.function.arguments)});a.length===0&&a.push({type:"text",text:""});const y=b(i.finish_reason,{hasToolCalls:f.length>0,matchedStop:i.stop_reason,refusal:e.refusal,category:v(i.content_filter_results),argumentsComplete:f.length===0||S(f.at(-1).function.arguments)});return t&&o.usage&&(t.upstreamUsage=o.usage),{id:T(),type:"message",role:"assistant",model:t?.model??o.model,content:a,...y,usage:j(o.usage)}}p(G,"response");export{G as response};
1
+ var y=Object.defineProperty;var f=(n,t)=>y(n,"name",{value:t,configurable:!0});import{resolve as k}from"../../../../../../../lib/settings.mjs";import{TranslatorError as d}from"../../../../../../../lib/errors.mjs";import{messageId as x,anthropicToolId as T,restoreName as A}from"../../../../../../../lib/ids.mjs";import{sign as w,reasoningOf as C,reasoningKey as E,detailsText as I,splitThink as N}from"../../../../../../../lib/thinking.mjs";import{isComplete as O,parseArguments as S}from"../../../../../../../lib/arguments.mjs";import{filterCategory as U,finishError as v,toAnthropicStop as b,toAnthropicUsage as j}from"../../../../../../../lib/finish.mjs";function G(n,t,m){const c=k(m),r=n?.choices?.[0];if(!r)throw new d("Upstream response contained no choices",{code:"invalid_upstream_response",status:502});const p=v(r.finish_reason);if(p)throw new d(p.message,{code:p.code,status:p.status,type:p.type});const e=r.message??{},a=[];let l=C(e),s=typeof e.content=="string"?e.content:"";const o={};if(c.reasoningRoundTrip){const i=E(e);i&&(o[i]=e[i]),Array.isArray(e.reasoning_details)&&e.reasoning_details.length>0&&(o.reasoning_details=e.reasoning_details)}l===""&&c.thinkTags&&({reasoning:l,text:s}=N(s,c.thinkOpen)),l===""&&o.reasoning_details&&(l=I(o.reasoning_details)),(l!==""||o.reasoning_details)&&(a.push({type:"thinking",thinking:l,signature:w(Object.keys(o).length>0?o:void 0,t?.producer)}),s=s.trimStart()),s===""&&typeof e.refusal=="string"&&(s=e.refusal),s!==""&&a.push({type:"text",text:s});const u=t?.toolNames??{},h=t?.toolIds??{},g=e.tool_calls??[];for(const i of g)a.push({type:"tool_use",id:T(i.id,h),name:A(u,i.function.name),input:S(i.function.arguments)});a.length===0&&a.push({type:"text",text:""});const _=b(r.finish_reason,{hasToolCalls:g.length>0,matchedStop:r.stop_reason,refusal:e.refusal,category:U(r.content_filter_results),argumentsComplete:g.length===0||O(g.at(-1).function.arguments)});return t&&n.usage&&(t.upstreamUsage=n.usage),{id:x(),type:"message",role:"assistant",model:t?.model??n.model,content:a,..._,usage:j(n.usage),...t?.appliedEdits?{context_management:{applied_edits:t.appliedEdits}}:{}}}f(G,"response");export{G as response};
2
2
  //# sourceMappingURL=response.mjs.map
@@ -1,2 +1,2 @@
1
- var Q=Object.defineProperty;var s=(b,r)=>Q(b,"name",{value:r,configurable:!0});import{resolve as V}from"../../../../../../../lib/settings.mjs";import{TranslatorError as W,openaiToAnthropicType as X,rewriteContextOverflow as Y}from"../../../../../../../lib/errors.mjs";import{isComplete as Z}from"../../../../../../../lib/arguments.mjs";import{messageId as $,anthropicToolId as ee,restoreName as te}from"../../../../../../../lib/ids.mjs";import{sign as ne,reasoningOf as ie,reasoningKey as oe,detailsText as le,mergeDetail as se,createThinkSplitter as re}from"../../../../../../../lib/thinking.mjs";import{filterCategory as ae,finishError as de,toAnthropicStop as fe,toAnthropicUsage as B}from"../../../../../../../lib/finish.mjs";import{messages as ce}from"../../../../../../../lib/sse.mjs";async function*xe(b,r,F){const u=V(F),J=r?.toolNames??{},K=r?.toolIds??{},d=u.thinkTags?re(u.thinkOpen):null,c=new Map;let m=!1,j=0,i=null,N=null,k=null,O=null,h="",T=null,v=!1,A=!1,I=0,w=!1,U=!1,E=!1;const S=[],l=s((e,t)=>({event:e,data:{type:e,...t}}),"event"),p=s((e,t)=>l("error",{error:{type:e,message:t}}),"fail"),M=s(e=>{const t={};return u.reasoningRoundTrip&&(e.key!==null&&(t[e.key]=e.text),e.details.length>0&&(t.reasoning_details=e.details)),Object.keys(t).length>0?t:void 0},"carried");function*y(){if(i!==null){i.kind==="thinking"?yield l("content_block_delta",{index:i.index,delta:{type:"signature_delta",signature:ne(M(i.carry),r?.producer)}}):i.kind==="tool"&&(i.entry.state="closed",i.entry.sent||(yield l("content_block_delta",{index:i.index,delta:{type:"input_json_delta",partial_json:"{}"}}))),yield l("content_block_stop",{index:i.index}),i=null;for(const e of c.values()){if(e.state!=="pending")continue;e.state="closed";const t=j++,n=e.args.join("");yield l("content_block_start",{index:t,content_block:e.block}),yield l("content_block_delta",{index:t,delta:{type:"input_json_delta",partial_json:n===""?"{}":n}}),yield l("content_block_stop",{index:t})}}}s(y,"close");function*G(){for(const e of R()){if(e.state!=="buffered")continue;yield*g("tool",e.block,e);const t=e.args.join("");t!==""&&(e.sent=!0,yield l("content_block_delta",{index:i.index,delta:{type:"input_json_delta",partial_json:t}})),yield*y()}}s(G,"flushBuffered");function R(){return[...c.entries()].sort((e,t)=>e[0]-t[0]).map(e=>e[1])}s(R,"ordered");function*g(e,t,n){yield*y(),i={kind:e,index:j++,entry:n,carry:{key:null,text:"",details:[]}},yield l("content_block_start",{index:i.index,content_block:t})}s(g,"begin");function*a(e,t,n=null){if(e==="text"&&E&&(t=t.trimStart()),t==="")return;if(E=e==="thinking",e==="text"&&(v=!0),i?.kind==="tool"){S.push({kind:e,text:t,key:n});return}i?.kind!==e&&(yield*g(e,e==="text"?{type:"text",text:""}:{type:"thinking",thinking:"",signature:""})),n!==null&&(i.carry.key??=n,i.carry.text+=t);const o=e==="text"?{type:"text_delta",text:t}:{type:"thinking_delta",thinking:t};yield l("content_block_delta",{index:i.index,delta:o})}s(a,"piece");function*z(e){if(i?.kind==="tool"){S.push({kind:"details",items:e});return}i?.kind!=="thinking"&&(yield*g("thinking",{type:"thinking",thinking:"",signature:""}));for(const t of e)se(i.carry.details,t);i.carry.key===null&&(yield*a("thinking",le(e)))}s(z,"details");function*D(e){yield*a("thinking",e.reasoning),yield*a("text",e.text)}s(D,"pieces");function*H(e){let t=e.index;t===void 0&&(t=e.id===void 0||e.id===null?I:c.size),I=t;let n=c.get(t);if(n===void 0){const x=e.function?.name??"",_={type:"tool_use",id:ee(e.id,K),name:te(J,x),input:{}};d?.pending()&&(U=!0);const f=u.toolStreaming==="buffer"||U;n={state:f?"buffered":"pending",sent:!1,args:[],block:_},c.set(t,n),!f&&i?.kind!=="tool"&&(n.state="open",yield*g("tool",_,n))}let o=e.function?.arguments;o!==null&&typeof o=="object"&&(o=JSON.stringify(o)),!(o==null||o==="")&&(n.args.push(o),n.state==="open"&&(n.sent=!0,yield l("content_block_delta",{index:i.index,delta:{type:"input_json_delta",partial_json:o}})))}s(H,"toolCall");try{for await(const e of ce(b)){if(e.data==="[DONE]"){A=!0;break}const t=e.data;if(t.error){const f=t.error.message??"Upstream error";yield p(X(t.error),Y(f)??f);return}m||(m=!0,yield l("message_start",{message:{id:$(),type:"message",role:"assistant",model:r?.model??t.model,content:[],stop_reason:null,stop_sequence:null,usage:B(t.usage)}})),t.usage&&(N=t.usage,r&&(r.upstreamUsage=t.usage));const n=t.choices?.[0];if(!n)continue;const o=n.delta??{},x=ie(o);let _="";x!==""&&!w&&(w=!0,d&&(_=d.release().text)),yield*a("thinking",x,oe(o)),yield*a("text",_),u.reasoningRoundTrip&&Array.isArray(o.reasoning_details)&&o.reasoning_details.length>0&&(yield*z(o.reasoning_details)),typeof o.content=="string"&&o.content!==""&&(d&&!w?yield*D(d.push(o.content)):yield*a("text",o.content)),typeof o.refusal=="string"&&(h+=o.refusal),T=ae(n.content_filter_results)??T;for(const f of o.tool_calls??[])yield*H(f);n.finish_reason&&(k=n.finish_reason),typeof n.stop_reason=="string"&&(O=n.stop_reason)}}catch(e){yield e instanceof W?p(e.type,e.message):p("api_error",e.message);return}if(!m||k===null&&!A){yield p("api_error",m?"Upstream stream ended before completion":"Upstream stream ended without data");return}const C=de(k);if(C){yield p(C.type,C.message);return}d&&(yield*D(d.end())),yield*G();const q=R().at(-1),L=q===void 0||Z(q.args.join(""));yield*y();for(const e of S)yield*e.kind==="details"?z(e.items):a(e.kind,e.text,e.key);!v&&h!==""&&(yield*a("text",h)),yield*y(),j===0&&(yield*g("text",{type:"text",text:""}),yield*y());const P=fe(k,{hasToolCalls:c.size>0,matchedStop:O,argumentsComplete:L,refusal:h,category:T});yield l("message_delta",{delta:P,usage:B(N)}),yield l("message_stop",{})}s(xe,"stream");export{xe as stream};
1
+ var V=Object.defineProperty;var s=(b,r)=>V(b,"name",{value:r,configurable:!0});import{resolve as W}from"../../../../../../../lib/settings.mjs";import{TranslatorError as X,openaiToAnthropicType as Y,rewriteContextOverflow as Z}from"../../../../../../../lib/errors.mjs";import{isComplete as $}from"../../../../../../../lib/arguments.mjs";import{messageId as ee,anthropicToolId as te,restoreName as ne}from"../../../../../../../lib/ids.mjs";import{sign as ie,reasoningOf as oe,reasoningKey as le,detailsText as se,mergeDetail as re,createThinkSplitter as ae}from"../../../../../../../lib/thinking.mjs";import{filterCategory as de,finishError as fe,toAnthropicStop as ce,toAnthropicUsage as B}from"../../../../../../../lib/finish.mjs";import{messages as ue}from"../../../../../../../lib/sse.mjs";async function*be(b,r,F){const u=W(F),J=r?.toolNames??{},K=r?.toolIds??{},d=u.thinkTags?ae(u.thinkOpen):null,c=new Map;let m=!1,j=0,i=null,N=null,k=null,O=null,h="",T=null,v=!1,A=!1,E=0,w=!1,I=!1,U=!1;const S=[],l=s((e,t)=>({event:e,data:{type:e,...t}}),"event"),p=s((e,t)=>l("error",{error:{type:e,message:t}}),"fail"),M=s(e=>{const t={};return u.reasoningRoundTrip&&(e.key!==null&&(t[e.key]=e.text),e.details.length>0&&(t.reasoning_details=e.details)),Object.keys(t).length>0?t:void 0},"carried");function*y(){if(i!==null){i.kind==="thinking"?yield l("content_block_delta",{index:i.index,delta:{type:"signature_delta",signature:ie(M(i.carry),r?.producer)}}):i.kind==="tool"&&(i.entry.state="closed",i.entry.sent||(yield l("content_block_delta",{index:i.index,delta:{type:"input_json_delta",partial_json:"{}"}}))),yield l("content_block_stop",{index:i.index}),i=null;for(const e of c.values()){if(e.state!=="pending")continue;e.state="closed";const t=j++,n=e.args.join("");yield l("content_block_start",{index:t,content_block:e.block}),yield l("content_block_delta",{index:t,delta:{type:"input_json_delta",partial_json:n===""?"{}":n}}),yield l("content_block_stop",{index:t})}}}s(y,"close");function*G(){for(const e of R()){if(e.state!=="buffered")continue;yield*g("tool",e.block,e);const t=e.args.join("");t!==""&&(e.sent=!0,yield l("content_block_delta",{index:i.index,delta:{type:"input_json_delta",partial_json:t}})),yield*y()}}s(G,"flushBuffered");function R(){return[...c.entries()].sort((e,t)=>e[0]-t[0]).map(e=>e[1])}s(R,"ordered");function*g(e,t,n){yield*y(),i={kind:e,index:j++,entry:n,carry:{key:null,text:"",details:[]}},yield l("content_block_start",{index:i.index,content_block:t})}s(g,"begin");function*a(e,t,n=null){if(e==="text"&&U&&(t=t.trimStart()),t==="")return;if(U=e==="thinking",e==="text"&&(v=!0),i?.kind==="tool"){S.push({kind:e,text:t,key:n});return}i?.kind!==e&&(yield*g(e,e==="text"?{type:"text",text:""}:{type:"thinking",thinking:"",signature:""})),n!==null&&(i.carry.key??=n,i.carry.text+=t);const o=e==="text"?{type:"text_delta",text:t}:{type:"thinking_delta",thinking:t};yield l("content_block_delta",{index:i.index,delta:o})}s(a,"piece");function*z(e){if(i?.kind==="tool"){S.push({kind:"details",items:e});return}i?.kind!=="thinking"&&(yield*g("thinking",{type:"thinking",thinking:"",signature:""}));for(const t of e)re(i.carry.details,t);i.carry.key===null&&(yield*a("thinking",se(e)))}s(z,"details");function*D(e){yield*a("thinking",e.reasoning),yield*a("text",e.text)}s(D,"pieces");function*H(e){let t=e.index;t===void 0&&(t=e.id===void 0||e.id===null?E:c.size),E=t;let n=c.get(t);if(n===void 0){const x=e.function?.name??"",_={type:"tool_use",id:te(e.id,K),name:ne(J,x),input:{}};d?.pending()&&(I=!0);const f=u.toolStreaming==="buffer"||I;n={state:f?"buffered":"pending",sent:!1,args:[],block:_},c.set(t,n),!f&&i?.kind!=="tool"&&(n.state="open",yield*g("tool",_,n))}let o=e.function?.arguments;o!==null&&typeof o=="object"&&(o=JSON.stringify(o)),!(o==null||o==="")&&(n.args.push(o),n.state==="open"&&(n.sent=!0,yield l("content_block_delta",{index:i.index,delta:{type:"input_json_delta",partial_json:o}})))}s(H,"toolCall");try{for await(const e of ue(b)){if(e.data==="[DONE]"){A=!0;break}const t=e.data;if(t.error){const f=t.error.message??"Upstream error";yield p(Y(t.error),Z(f)??f);return}m||(m=!0,yield l("message_start",{message:{id:ee(),type:"message",role:"assistant",model:r?.model??t.model,content:[],stop_reason:null,stop_sequence:null,usage:B(t.usage)}})),t.usage&&(N=t.usage,r&&(r.upstreamUsage=t.usage));const n=t.choices?.[0];if(!n)continue;const o=n.delta??{},x=oe(o);let _="";x!==""&&!w&&(w=!0,d&&(_=d.release().text)),yield*a("thinking",x,le(o)),yield*a("text",_),u.reasoningRoundTrip&&Array.isArray(o.reasoning_details)&&o.reasoning_details.length>0&&(yield*z(o.reasoning_details)),typeof o.content=="string"&&o.content!==""&&(d&&!w?yield*D(d.push(o.content)):yield*a("text",o.content)),typeof o.refusal=="string"&&(h+=o.refusal),T=de(n.content_filter_results)??T;for(const f of o.tool_calls??[])yield*H(f);n.finish_reason&&(k=n.finish_reason),typeof n.stop_reason=="string"&&(O=n.stop_reason)}}catch(e){yield e instanceof X?p(e.type,e.message):p("api_error",e.message);return}if(!m||k===null&&!A){yield p("api_error",m?"Upstream stream ended before completion":"Upstream stream ended without data");return}const C=fe(k);if(C){yield p(C.type,C.message);return}d&&(yield*D(d.end())),yield*G();const q=R().at(-1),L=q===void 0||$(q.args.join(""));yield*y();for(const e of S)yield*e.kind==="details"?z(e.items):a(e.kind,e.text,e.key);!v&&h!==""&&(yield*a("text",h)),yield*y(),j===0&&(yield*g("text",{type:"text",text:""}),yield*y());const P=ce(k,{hasToolCalls:c.size>0,matchedStop:O,argumentsComplete:L,refusal:h,category:T}),Q=r?.appliedEdits?{context_management:{applied_edits:r.appliedEdits}}:{};yield l("message_delta",{delta:P,usage:B(N),...Q}),yield l("message_stop",{})}s(be,"stream");export{be as stream};
2
2
  //# sourceMappingURL=stream.mjs.map
@@ -0,0 +1,2 @@
1
+ var a=Object.defineProperty;var o=(e,r)=>a(e,"name",{value:r,configurable:!0});import{resolve as m}from"../../../../../../../lib/settings.mjs";import{TranslatorError as i}from"../../../../../../../lib/errors.mjs";import{chatBody as n}from"../../../../../../../lib/ollama.mjs";function c(e,r){const t=m(r);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new i("messages: Field required",{code:"invalid_request",param:"messages"});const s={front:"openai",model:e.model,stream:e.stream===!0,toolNames:{},toolIds:{},dropped:[],includeUsage:e.stream_options?.include_usage===!0};return{body:n(e,{dropped:s.dropped,sampling:t.sampling}),state:s}}o(c,"request");export{c as request};
2
+ //# sourceMappingURL=request.mjs.map
@@ -1,2 +1,2 @@
1
- var g=Object.defineProperty;var o=(r,e)=>g(r,"name",{value:e,configurable:!0});import{context as h,self as u}from"../lib/runtime.mjs";import{capture as w}from"../lib/capture.mjs";import{TranslatorError as m}from"../lib/errors.mjs";import{warn as p}from"../lib/warn.mjs";import{emit as y}from"../lib/events.mjs";import*as k from"../lib/http.mjs";import{validToolIdPolicy as $}from"../lib/ids.mjs";async function D(r={}){const e=w(u,h),{status:f}=u,l=r.network!==!1;for(const t of e.drivers){const s=t.info.fields;if(s!==void 0&&!(Array.isArray(s)&&s.every(i=>typeof i=="string")))throw new m(`Driver ${t.name}: info().fields must be an array of field names`,{code:"invalid_driver",status:500})}for(const t of e.drivers){const s=t.info.toolCallIds;if(s!==void 0&&!$(s))throw new m(`Driver ${t.name}: info().toolCallIds must be { alphabet, min?, max? } with a character-class alphabet and positive integer bounds`,{code:"invalid_driver",status:500})}const a={transport:e.state.transport,signal:r.signal,timeout:e.config.detectTimeout};return await Promise.all(e.state.endpoints.map(t=>x(e,t,l,a))),f()}o(D,"detect");async function x(r,e,f,l){let a,t=null;if(e.backend!=="auto"){if(a=r.drivers.find(s=>s.name===e.backend),!a)throw new m(`Unknown backend "${e.backend}" for upstream ${e.name}`,{code:"unknown_backend",status:500});t={version:e.version}}else if(f){const s=URL.canParse(e.url)?new URL(e.url).hostname:"",i={endpoint:e,...l,probes:new Map};let n=!1;for(const[v,c]of r.drivers.entries()){if(!n&&c.info.probes?.length>0&&!c.info.hosts?.includes(s)){n=!0;for(const d of r.drivers.slice(v))for(const b of d.info.probes??[])k.probe(i,b,d.info)}if(t=await U(c,i),t){a=c;break}}}if(a||(a=r.drivers.find(s=>s.name==="compatible"),t={reachable:null,models:[]}),e.driver=a.name,e.protocol=a.info.protocol,e.facts=t,e.driverSettings=await a.settings?.(t)??{},e.probed={},f&&e.backend==="auto"&&a.probe){const s=o(n=>e.settings[n]!==void 0||r.config.settings[n]!==void 0,"given"),i={inlineSystem:r.settings(e).inlineSystem==="auto",images:!s("images")};(i.inlineSystem||i.images)&&(e.probed=await a.probe({endpoint:e,facts:t,want:i,...l}))}t.reachable===!1?p(r.config,r.state,`Upstream ${e.name} (${e.url}) did not answer detection; using the generic OpenAI-compatible driver`,{type:"detect",kind:"unreachable",endpoint:e.name,url:e.url,driver:a.name}):y({config:r.config,state:r.state},{type:"detect",kind:"driver",level:"info",message:`Upstream ${e.name} (${e.url}): driver ${a.name}`,endpoint:e.name,url:e.url,driver:a.name})}o(x,"bind");async function U(r,e){try{return await r.detect?.(e)??null}catch{return null}}o(U,"detectWith");export{D as detect};
1
+ var w=Object.defineProperty;var f=(t,e)=>w(t,"name",{value:e,configurable:!0});import{context as p,self as b}from"../lib/runtime.mjs";import{capture as y}from"../lib/capture.mjs";import{TranslatorError as d}from"../lib/errors.mjs";import{warn as k}from"../lib/warn.mjs";import{emit as $}from"../lib/events.mjs";import*as x from"../lib/http.mjs";import{validToolIdPolicy as U}from"../lib/ids.mjs";async function D(t={}){const e=y(b,p),{status:n}=b,l=t.network!==!1;for(const a of e.drivers){const s=a.info.fields;if(s!==void 0&&!(Array.isArray(s)&&s.every(i=>typeof i=="string")))throw new d(`Driver ${a.name}: info().fields must be an array of field names`,{code:"invalid_driver",status:500})}for(const a of e.drivers){const s=a.info.toolCallIds;if(s!==void 0&&!U(s))throw new d(`Driver ${a.name}: info().toolCallIds must be { alphabet, min?, max? } with a character-class alphabet and positive integer bounds`,{code:"invalid_driver",status:500})}const r={transport:e.state.transport,signal:t.signal,timeout:e.config.detectTimeout};return await Promise.all(e.state.endpoints.map(a=>A(e,a,l,r))),n()}f(D,"detect");async function A(t,e,n,l){let r,a=null;if(e.backend!=="auto"){if(r=t.drivers.find(s=>s.name===e.backend),!r)throw new d(`Unknown backend "${e.backend}" for upstream ${e.name}`,{code:"unknown_backend",status:500});a={version:e.version}}else if(n){const s=URL.canParse(e.url)?new URL(e.url).hostname:"",i={endpoint:e,...l,probes:new Map},c=t.drivers.filter(o=>I(o.info,s));for(const o of c)if(a=await h(o,i),a){r=o;break}let u=!1;for(const[o,m]of r?[]:t.drivers.entries()){if(!u&&m.info.probes?.length>0&&!m.info.hosts?.includes(s)){u=!0;for(const v of t.drivers.slice(o))for(const g of v.info.probes??[])x.probe(i,g,v.info)}if(a=await h(m,i),a){r=m;break}}}if(r||(r=t.drivers.find(s=>s.name==="compatible"),a={reachable:null,models:[]}),t.state.noMessages.delete(e.name),Object.assign(e.health,{ready:null,readyReason:null,checkedAt:null,unsupported:!1}),e.driver=r.name,e.protocol=r.info.protocol,e.api==="native"){if(!r.info.native){const s=t.drivers.filter(i=>i.info.native).map(i=>i.name);throw new d(`Upstream ${e.name}: api "native" needs a driver with a native API (${s.join(", ")}), but the upstream is bound to ${r.name}; set backend to one of them`,{code:"unsupported_api",status:500})}e.protocol=r.info.native.protocol}if(e.facts=a,e.driverSettings=await r.settings?.(a)??{},e.probed={},n&&e.backend==="auto"&&r.probe){const s=f(c=>e.settings[c]!==void 0||t.config.settings[c]!==void 0,"given"),i={inlineSystem:t.settings(e).inlineSystem==="auto",images:!s("images")};(i.inlineSystem||i.images)&&(e.probed=await r.probe({endpoint:e,facts:a,want:i,...l}))}a.reachable===!1?k(t.config,t.state,`Upstream ${e.name} (${e.url}) did not answer detection; using the generic OpenAI-compatible driver`,{type:"detect",kind:"unreachable",endpoint:e.name,url:e.url,driver:r.name}):$({config:t.config,state:t.state},{type:"detect",kind:"driver",level:"info",message:`Upstream ${e.name} (${e.url}): driver ${r.name}`,endpoint:e.name,url:e.url,driver:r.name})}f(A,"bind");function I(t,e){return e!==""&&(t.hosts?.includes(e)===!0||t.hostSuffixes?.some(n=>e.endsWith(n))===!0)}f(I,"matchesHost");async function h(t,e){try{return await t.detect?.(e)??null}catch{return null}}f(h,"detectWith");export{D as detect};
2
2
  //# sourceMappingURL=detect.mjs.map
@@ -1,2 +1,2 @@
1
- var s=Object.defineProperty;var o=(e,c)=>s(e,"name",{value:c,configurable:!0});const n=[".openai.azure.com",".cognitiveservices.azure.com",".services.ai.azure.com"];function a({endpoint:e}){const c=URL.canParse(e.url)?new URL(e.url).hostname:"";return n.some(r=>c.endsWith(r))?{host:c}:null}o(a,"detect");export{a as detect};
1
+ var r=Object.defineProperty;var o=(t,e)=>r(t,"name",{value:e,configurable:!0});import{info as s}from"./info.mjs";function c({endpoint:t}){const e=URL.canParse(t.url)?new URL(t.url).hostname:"";return s().hostSuffixes.some(n=>e.endsWith(n))?{host:e}:null}o(c,"detect");export{c as detect};
2
2
  //# sourceMappingURL=detect.mjs.map
@@ -1,2 +1,2 @@
1
- var a=Object.defineProperty;var e=(o,t)=>a(o,"name",{value:t,configurable:!0});function i(){return{name:"azure",protocol:"openai.chat",order:32,auth:"api-key",strict:!0,paths:{chat:"/openai/v1/chat/completions",embeddings:"/openai/v1/embeddings",models:"/openai/v1/models"}}}e(i,"info");export{i as info};
1
+ var a=Object.defineProperty;var e=(o,i)=>a(o,"name",{value:i,configurable:!0});function n(){return{name:"azure",protocol:"openai.chat",order:32,auth:"api-key",strict:!0,hostSuffixes:[".openai.azure.com",".cognitiveservices.azure.com",".services.ai.azure.com"],paths:{chat:"/openai/v1/chat/completions",embeddings:"/openai/v1/embeddings",models:"/openai/v1/models"}}}e(n,"info");export{n as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -1,2 +1,2 @@
1
- var a=Object.defineProperty;var e=(o,t)=>a(o,"name",{value:t,configurable:!0});function c(){return{name:"deepseek",protocol:"openai.chat",order:35,auth:"bearer",strict:!1,paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}e(c,"info");export{c as info};
1
+ var a=Object.defineProperty;var e=(o,t)=>a(o,"name",{value:t,configurable:!0});function r(){return{name:"deepseek",protocol:"openai.chat",order:35,auth:"bearer",strict:!1,hosts:["api.deepseek.com"],paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}e(r,"info");export{r as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -0,0 +1,2 @@
1
+ var o=Object.defineProperty;var t=(r,e)=>o(r,"name",{value:e,configurable:!0});import{match as c}from"../../../lib/presets.mjs";function m({endpoint:r}){return c("fireworks",r)}t(m,"detect");export{m as detect};
2
+ //# sourceMappingURL=detect.mjs.map
@@ -0,0 +1,2 @@
1
+ var i=Object.defineProperty;var r=(o,e)=>i(o,"name",{value:e,configurable:!0});import{describe as f}from"../../../lib/presets.mjs";function c(){return f("fireworks")}r(c,"info");export{c as info};
2
+ //# sourceMappingURL=info.mjs.map
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var t=(r,o)=>e(r,"name",{value:o,configurable:!0});import{route as f}from"../../../lib/presets.mjs";function p(r,{endpoint:o}){return f("fireworks",r,o)}t(p,"path");export{p as path};
2
+ //# sourceMappingURL=path.mjs.map
@@ -0,0 +1,2 @@
1
+ var o=Object.defineProperty;var e=(r,t)=>o(r,"name",{value:t,configurable:!0});import{trim as i}from"../../../lib/presets.mjs";function n(r,t){return i("fireworks",r,t)}e(n,"request");export{n as request};
2
+ //# sourceMappingURL=request.mjs.map
@@ -0,0 +1,2 @@
1
+ var i=Object.defineProperty;var t=(r,e)=>i(r,"name",{value:e,configurable:!0});import{settingsOf as n}from"../../../lib/presets.mjs";function f(){return n("fireworks")}t(f,"settings");export{f as settings};
2
+ //# sourceMappingURL=settings.mjs.map
@@ -0,0 +1,2 @@
1
+ var i=Object.defineProperty;var e=(t,r)=>i(t,"name",{value:r,configurable:!0});import{match as m}from"../../../lib/presets.mjs";function c({endpoint:t}){return m("gemini",t)}e(c,"detect");export{c as detect};
2
+ //# sourceMappingURL=detect.mjs.map
@@ -0,0 +1,2 @@
1
+ var n=Object.defineProperty;var i=(r,e)=>n(r,"name",{value:e,configurable:!0});import{describe as o}from"../../../lib/presets.mjs";function m(){return o("gemini")}i(m,"info");export{m as info};
2
+ //# sourceMappingURL=info.mjs.map
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var o=(r,t)=>e(r,"name",{value:t,configurable:!0});import{route as i}from"../../../lib/presets.mjs";function p(r,{endpoint:t}){return i("gemini",r,t)}o(p,"path");export{p as path};
2
+ //# sourceMappingURL=path.mjs.map
@@ -0,0 +1,2 @@
1
+ var i=Object.defineProperty;var e=(r,t)=>i(r,"name",{value:t,configurable:!0});import{trim as m}from"../../../lib/presets.mjs";function u(r,t){return m("gemini",r,t)}e(u,"request");export{u as request};
2
+ //# sourceMappingURL=request.mjs.map
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var t=(i,n)=>e(i,"name",{value:n,configurable:!0});import{settingsOf as r}from"../../../lib/presets.mjs";function f(){return r("gemini")}t(f,"settings");export{f as settings};
2
+ //# sourceMappingURL=settings.mjs.map
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var r=(t,o)=>e(t,"name",{value:o,configurable:!0});import{match as c}from"../../../lib/presets.mjs";function f({endpoint:t}){return c("groq",t)}r(f,"detect");export{f as detect};
2
+ //# sourceMappingURL=detect.mjs.map
@@ -0,0 +1,2 @@
1
+ var i=Object.defineProperty;var r=(o,e)=>i(o,"name",{value:e,configurable:!0});import{describe as n}from"../../../lib/presets.mjs";function c(){return n("groq")}r(c,"info");export{c as info};
2
+ //# sourceMappingURL=info.mjs.map
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var t=(r,o)=>e(r,"name",{value:o,configurable:!0});import{route as n}from"../../../lib/presets.mjs";function f(r,{endpoint:o}){return n("groq",r,o)}t(f,"path");export{f as path};
2
+ //# sourceMappingURL=path.mjs.map
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var o=(r,t)=>e(r,"name",{value:t,configurable:!0});import{trim as i}from"../../../lib/presets.mjs";function u(r,t){return i("groq",r,t)}o(u,"request");export{u as request};
2
+ //# sourceMappingURL=request.mjs.map
@@ -0,0 +1,2 @@
1
+ var o=Object.defineProperty;var t=(r,n)=>o(r,"name",{value:n,configurable:!0});import{settingsOf as e}from"../../../lib/presets.mjs";function f(){return e("groq")}t(f,"settings");export{f as settings};
2
+ //# sourceMappingURL=settings.mjs.map
@@ -1,2 +1,2 @@
1
- var a=Object.defineProperty;var e=(p,t)=>a(p,"name",{value:t,configurable:!0});function r(){return{name:"llamacpp",protocol:"openai.chat",order:40,auth:"bearer",strict:!1,probes:["/props"],fields:["top_k","min_p","chat_template_kwargs","repetition_penalty","repeat_penalty","grammar"],paths:{chat:"/v1/chat/completions",models:"/v1/models",props:"/props"}}}e(r,"info");export{r as info};
1
+ var a=Object.defineProperty;var e=(p,t)=>a(p,"name",{value:t,configurable:!0});function r(){return{name:"llamacpp",protocol:"openai.chat",order:40,auth:"bearer",strict:!1,probes:["/props"],fields:["top_k","min_p","chat_template_kwargs","repetition_penalty","repeat_penalty","grammar","json_schema"],paths:{chat:"/v1/chat/completions",models:"/v1/models",props:"/props"}}}e(r,"info");export{r as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -1,2 +1,2 @@
1
- var e=Object.defineProperty;var a=(t,o)=>e(t,"name",{value:o,configurable:!0});function r(){return{name:"mistral",protocol:"openai.chat",order:36,auth:"bearer",strict:!1,toolCallIds:{alphabet:"a-zA-Z0-9",min:9,max:9},paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}a(r,"info");export{r as info};
1
+ var e=Object.defineProperty;var a=(t,o)=>e(t,"name",{value:o,configurable:!0});function r(){return{name:"mistral",protocol:"openai.chat",order:36,auth:"bearer",strict:!1,hosts:["api.mistral.ai"],toolCallIds:{alphabet:"a-zA-Z0-9",min:9,max:9},paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}a(r,"info");export{r as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -1,2 +1,2 @@
1
- var r=Object.defineProperty;var o=(e,a)=>r(e,"name",{value:a,configurable:!0});function i(){return{name:"ollama",protocol:"openai.chat",order:60,auth:"bearer",strict:!1,probes:["/api/version"],paths:{chat:"/v1/chat/completions",models:"/v1/models",version:"/api/version"}}}o(i,"info");export{i as info};
1
+ var e=Object.defineProperty;var a=(o,t)=>e(o,"name",{value:t,configurable:!0});function i(){return{name:"ollama",protocol:"openai.chat",order:60,auth:"bearer",strict:!1,probes:["/api/version"],paths:{chat:"/v1/chat/completions",models:"/v1/models",version:"/api/version"},native:{protocol:"ollama.chat",paths:{chat:"/api/chat"}}}}a(i,"info");export{i as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -1,2 +1,2 @@
1
- var d=Object.defineProperty;var l=(s,r)=>d(s,"name",{value:r,configurable:!0});import{noEmptyTools as m}from"../../../lib/normalize.mjs";import{estimate as f}from"../../../lib/estimate.mjs";const p=["tool_choice","n","logit_bias"],h="[An image was omitted because Ollama accepts base64 images only and the translator does not fetch URLs.]";function g(s,r){let t=m(s);const e=r?.state?.dropped;t.tool_choice==="none"&&t.tools!==void 0&&(t={...t},delete t.tools,delete t.parallel_tool_calls,Array.isArray(e)&&!e.includes("tools")&&e.push("tools"));for(const o of p)t[o]!==void 0&&(t={...t},delete t[o],Array.isArray(e)&&!e.includes(o)&&e.push(o));if(Array.isArray(t.messages)){let o=!1;const c=t.messages.map(n=>{if(!Array.isArray(n?.content))return n;const u=n.content.map(i=>i?.type!=="image_url"||String(i.image_url?.url).startsWith("data:")?i:(o=!0,{type:"text",text:h}));return{...n,content:u}});o&&(t={...t,messages:c},Array.isArray(e)&&!e.includes("image_url")&&e.push("image_url"))}const a=r?.settings?.contextWindow??0;return a>0&&f(t)>a&&r?.warn?.(`Upstream ${r.endpoint?.name}: the prompt is estimated at more than ${a} tokens, which Ollama truncates without an error. Raise num_ctx (OLLAMA_CONTEXT_LENGTH or a Modelfile) and set the upstream's contextWindow setting to match.`),t}l(g,"request");export{g as request};
1
+ var m=Object.defineProperty;var a=(o,e)=>m(o,"name",{value:e,configurable:!0});import{noEmptyTools as p}from"../../../lib/normalize.mjs";import{estimate as d}from"../../../lib/estimate.mjs";const f=["tool_choice","n","logit_bias"],h="[An image was omitted because Ollama accepts base64 images only and the translator does not fetch URLs.]";function l(o,e){const t=Number.isFinite(o?.options?.num_ctx)?o.options.num_ctx:e?.settings?.contextWindow??0;t>0&&d(o)>t&&e?.warn?.(`Upstream ${e.endpoint?.name}: the prompt is estimated at more than ${t} tokens, which Ollama truncates without an error. Raise num_ctx (OLLAMA_CONTEXT_LENGTH or a Modelfile) and set the upstream's contextWindow setting to match.`)}a(l,"overflow");function y(o,e){if(e?.endpoint?.protocol==="ollama.chat")return l(o,e),o;let t=p(o);const n=e?.state?.dropped;t.tool_choice==="none"&&t.tools!==void 0&&(t={...t},delete t.tools,delete t.parallel_tool_calls,Array.isArray(n)&&!n.includes("tools")&&n.push("tools"));for(const r of f)t[r]!==void 0&&(t={...t},delete t[r],Array.isArray(n)&&!n.includes(r)&&n.push(r));if(Array.isArray(t.messages)){let r=!1;const u=t.messages.map(i=>{if(!Array.isArray(i?.content))return i;const c=i.content.map(s=>s?.type!=="image_url"||String(s.image_url?.url).startsWith("data:")?s:(r=!0,{type:"text",text:h}));return{...i,content:c}});r&&(t={...t,messages:u},Array.isArray(n)&&!n.includes("image_url")&&n.push("image_url"))}return l(t,e),t}a(y,"request");export{y as request};
2
2
  //# sourceMappingURL=request.mjs.map
@@ -1,2 +1,2 @@
1
- var r=Object.defineProperty;var o=(t,e)=>r(t,"name",{value:e,configurable:!0});function n(){return{name:"openai",protocol:"openai.chat",order:30,auth:"bearer",strict:!0,paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(n,"info");export{n as info};
1
+ var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function c(){return{name:"openai",protocol:"openai.chat",order:30,auth:"bearer",strict:!0,hosts:["api.openai.com"],fields:["prompt_cache_key"],paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(c,"info");export{c as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -1,2 +1,2 @@
1
- var r=Object.defineProperty;var o=(e,t)=>r(e,"name",{value:t,configurable:!0});function n(){return{name:"openrouter",protocol:"openai.chat",order:37,auth:"bearer",strict:!1,paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(n,"info");export{n as info};
1
+ var r=Object.defineProperty;var o=(e,t)=>r(e,"name",{value:t,configurable:!0});function n(){return{name:"openrouter",protocol:"openai.chat",order:37,auth:"bearer",strict:!1,hosts:["openrouter.ai"],paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(n,"info");export{n as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -0,0 +1,2 @@
1
+ var o=Object.defineProperty;var e=(t,r)=>o(t,"name",{value:r,configurable:!0});import{match as c}from"../../../lib/presets.mjs";function f({endpoint:t}){return c("together",t)}e(f,"detect");export{f as detect};
2
+ //# sourceMappingURL=detect.mjs.map
@@ -0,0 +1,2 @@
1
+ var t=Object.defineProperty;var r=(e,o)=>t(e,"name",{value:o,configurable:!0});import{describe as i}from"../../../lib/presets.mjs";function c(){return i("together")}r(c,"info");export{c as info};
2
+ //# sourceMappingURL=info.mjs.map
@@ -0,0 +1,2 @@
1
+ var o=Object.defineProperty;var e=(r,t)=>o(r,"name",{value:t,configurable:!0});import{trim as i}from"../../../lib/presets.mjs";function u(r,t){return i("together",r,t)}e(u,"request");export{u as request};
2
+ //# sourceMappingURL=request.mjs.map
@@ -0,0 +1,2 @@
1
+ var n=Object.defineProperty;var t=(e,r)=>n(e,"name",{value:r,configurable:!0});import{settingsOf as o}from"../../../lib/presets.mjs";function f(){return o("together")}t(f,"settings");export{f as settings};
2
+ //# sourceMappingURL=settings.mjs.map
@@ -1,2 +1,2 @@
1
- var g=Object.defineProperty;var p=(t,l)=>g(t,"name",{value:l,configurable:!0});import*as n from"../../../lib/http.mjs";import{isLlamacppProps as v,isLocalaiVersion as _,isSglangInfo as w,isTgiInfo as x,objectOf as s}from"../../../lib/backends.mjs";const L=new Set(["sglang","llamacpp"]);async function S({endpoint:t,transport:l,signal:f,timeout:c,probes:u}){const e={endpoint:t,transport:l,signal:f,timeout:c,probes:u},[i,a]=await Promise.all([n.probe(e,"/version"),n.probe(e,"/v1/models")]);if(_(s(i)))return null;const m=typeof i.body?.version=="string"?i.body.version:void 0,r=Array.isArray(a.body?.data)?a.body.data:[];if(r.some(o=>L.has(o?.owned_by)))return null;const d=r.some(o=>o?.owned_by==="vllm");if(!m&&!d)return null;if(!d){const[o,b,y]=await Promise.all([n.probe(e,"/get_server_info"),n.probe(e,"/props"),n.probe(e,"/info")]);if(w(s(o))||v(s(b))||x(s(y)))return null}return{version:m,models:r.map(o=>o.id),maxModelLen:r.find(o=>typeof o.max_model_len=="number")?.max_model_len}}p(S,"detect");export{S as detect};
1
+ var g=Object.defineProperty;var d=(t,a)=>g(t,"name",{value:a,configurable:!0});import*as r from"../../../lib/http.mjs";import{adaptersOf as v}from"../../../lib/models.mjs";import{isLlamacppProps as _,isLocalaiVersion as w,isSglangInfo as x,isTgiInfo as L,objectOf as s}from"../../../lib/backends.mjs";const O=new Set(["sglang","llamacpp"]);async function h({endpoint:t,transport:a,signal:f,timeout:c,probes:u}){const e={endpoint:t,transport:a,signal:f,timeout:c,probes:u},[l,i]=await Promise.all([r.probe(e,"/version"),r.probe(e,"/v1/models")]);if(w(s(l)))return null;const m=typeof l.body?.version=="string"?l.body.version:void 0,n=Array.isArray(i.body?.data)?i.body.data:[];if(n.some(o=>O.has(o?.owned_by)))return null;const p=n.some(o=>o?.owned_by==="vllm");if(!m&&!p)return null;if(!p){const[o,b,y]=await Promise.all([r.probe(e,"/get_server_info"),r.probe(e,"/props"),r.probe(e,"/info")]);if(x(s(o))||_(s(b))||L(s(y)))return null}return{version:m,models:n.map(o=>o.id),adapters:v(n),maxModelLen:n.find(o=>typeof o.max_model_len=="number")?.max_model_len}}d(h,"detect");export{h as detect};
2
2
  //# sourceMappingURL=detect.mjs.map
@@ -1,2 +1,2 @@
1
- var r=Object.defineProperty;var e=(o,t)=>r(o,"name",{value:t,configurable:!0});import{VLLM_FIELDS as i}from"../../../lib/passthrough.mjs";function s(){return{name:"vllm",protocol:"openai.chat",order:10,auth:"bearer",strict:!0,fields:i,paths:{chat:"/v1/chat/completions",models:"/v1/models",tokenize:"/tokenize",version:"/version"}}}e(s,"info");export{s as info};
1
+ var r=Object.defineProperty;var e=(o,t)=>r(o,"name",{value:t,configurable:!0});import{VLLM_FIELDS as s}from"../../../lib/passthrough.mjs";function n(){return{name:"vllm",protocol:"openai.chat",order:10,auth:"bearer",strict:!0,fields:s,paths:{chat:"/v1/chat/completions",messages:"/v1/messages",models:"/v1/models",tokenize:"/tokenize",version:"/version",health:"/health"}}}e(n,"info");export{n as info};
2
2
  //# sourceMappingURL=info.mjs.map
@@ -1,2 +1,2 @@
1
- var o=Object.defineProperty;var t=(r,e)=>o(r,"name",{value:e,configurable:!0});import{fetchModels as f}from"../../../../lib/models.mjs";function u(r){return f({...r,auth:"bearer"})}t(u,"list");export{u as list};
1
+ var r=Object.defineProperty;var e=(a,t)=>r(a,"name",{value:t,configurable:!0});import{adaptersOf as f,fetchModels as n}from"../../../../lib/models.mjs";async function i(a){const t=await n({...a,auth:"bearer"}),{endpoint:s}=a;return t!==null&&s.facts&&(s.facts={...s.facts,models:t.map(o=>o.id),adapters:f(t)}),t}e(i,"list");export{i as list};
2
2
  //# sourceMappingURL=list.mjs.map
@@ -0,0 +1,2 @@
1
+ var o=Object.defineProperty;var r=(t,e)=>o(t,"name",{value:e,configurable:!0});import{match as c}from"../../../lib/presets.mjs";function n({endpoint:t}){return c("xai",t)}r(n,"detect");export{n as detect};
2
+ //# sourceMappingURL=detect.mjs.map
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var r=(i,o)=>e(i,"name",{value:o,configurable:!0});import{describe as n}from"../../../lib/presets.mjs";function c(){return n("xai")}r(c,"info");export{c as info};
2
+ //# sourceMappingURL=info.mjs.map
@@ -0,0 +1,2 @@
1
+ var i=Object.defineProperty;var e=(r,t)=>i(r,"name",{value:t,configurable:!0});import{trim as o}from"../../../lib/presets.mjs";function u(r,t){return o("xai",r,t)}e(u,"request");export{u as request};
2
+ //# sourceMappingURL=request.mjs.map
@@ -0,0 +1,2 @@
1
+ var r=Object.defineProperty;var t=(i,n)=>r(i,"name",{value:n,configurable:!0});import{settingsOf as e}from"../../../lib/presets.mjs";function f(){return e("xai")}t(f,"settings");export{f as settings};
2
+ //# sourceMappingURL=settings.mjs.map
@@ -1,2 +1,2 @@
1
- var x=Object.defineProperty;var h=(e,s)=>x(e,"name",{value:s,configurable:!0});import{context as w,self as q}from"../../lib/runtime.mjs";import{capture as S}from"../../lib/capture.mjs";import{resolve as H,serves as J}from"../../lib/route.mjs";import*as g from"../../lib/http.mjs";import*as O from"../../lib/pool.mjs";import{emit as N}from"../../lib/events.mjs";import{meter as U}from"../../lib/usage.mjs";import{warn as C}from"../../lib/warn.mjs";import{start as I}from"../../lib/record.mjs";async function L(e,s={}){const{transport:$}=w.state,{error:b}=q,a=S(q,w,"openai"),A=e&&typeof e=="object"&&!Array.isArray(e),l=U({model:null,requested:A&&typeof e.model=="string"?e.model:null,upstream:null,front:"openai",stream:!1},s.onUsage,(o,t)=>C(a.config,a.state,o,{type:"usage",...t,log:s.log})),c=h((o,t)=>(l.finish(t),Object.defineProperty(o,"usage",{value:l.usage,enumerable:!1,configurable:!0})),"end"),n=h((o,t,i={})=>c(b.build(o,t,{...i,front:"openai"}),o===499?"aborted":"error"),"fail");if(!e||typeof e!="object"||Array.isArray(e))return n(400,"The request body must be a JSON object",{code:"invalid_body"});if(typeof e.model!="string"||e.model==="")return n(400,"model is required",{code:"invalid_body",param:"model"});const P=Object.hasOwn(a.config.aliases,e.model)?a.config.aliases[e.model]:e.model;if(!a.state.endpoints.some(o=>J(o,P)))return n(404,`The model "${e.model}" is not served by any configured upstream.`,{code:"model_not_found",param:"model"});const d=H(a,e,{advance:!0}),f=d.pool.filter(o=>o.protocol==="openai.chat");if(f.length===0)return n(400,`The model "${e.model}" is served by an Anthropic-protocol upstream, which has no embeddings API.`,{code:"embeddings_unsupported",param:"model"});const j={...e,model:d.model};l.meta.model=d.model;let m,v=null;for(let o=0;o<f.length;o++){const t=f[o];l.meta.upstream=t.name;const i=a.driver(t);t.health.inflight++,t.health.requests++;const T=g.join(t.url,await g.pathOf(i,"embeddings",t,d.model)),_={"content-type":"application/json",accept:"application/json",...i.info.headers,...g.headers(t,i.info.auth,s.headers)},y=I(a,{body:e,sent:{upstream:t.name,url:T,headers:_,body:j,state:{stream:!1}},front:"openai",requested:l.meta.requested,log:s.log,exchange:v,attempt:o+1});v??=y.id;let r;try{r=await g.json($,T,{method:"POST",headers:_,body:j,signal:s.signal})}finally{t.health.inflight--}if(s.signal?.aborted)return n(499,"The request was aborted",{code:"aborted"});const u=r.status===0;if(!u&&r.status<500)return O.succeeded(t),y.reply(r.status,r.headers,r.body),r.ok?r.body===null||typeof r.body!="object"?n(502,"The upstream returned a body that is not JSON",{code:"bad_gateway"}):(l.json(r.body),c({status:200,headers:{"content-type":"application/json"},body:r.body},"done")):c(b(r.status,r.body,{},{front:"openai",upstream:t.name,native:!0,model:e.model}),"upstream_error");const p=u?`Could not reach the upstream (${t.name}): ${r.error?.message}`:`HTTP ${r.status}`;O.failed(a.config,t,p);const k=u?{error:p}:{status:r.status,headers:r.headers,body:r.body};y.attempt(k,o+1<f.length?p:void 0),N(a,{type:"error",kind:u?"transport":"upstream",level:"error",message:u?p:`Upstream ${t.name} answered HTTP ${r.status}`,endpoint:t.name,model:d.model,log:s.log}),m={endpoint:t,result:r,reason:p}}return m.result.status===0?n(502,m.reason,{code:"upstream_unreachable"}):c(b(m.result.status,m.result.body,{},{front:"openai",upstream:m.endpoint.name,native:!0,model:e.model}),"upstream_error")}h(L,"send");export{L as send};
1
+ var x=Object.defineProperty;var h=(e,s)=>x(e,"name",{value:s,configurable:!0});import{context as _,self as q}from"../../lib/runtime.mjs";import{capture as S}from"../../lib/capture.mjs";import{resolve as H,serves as J}from"../../lib/route.mjs";import*as g from"../../lib/http.mjs";import*as O from"../../lib/pool.mjs";import{emit as N}from"../../lib/events.mjs";import{refresh as U}from"../../lib/health.mjs";import{meter as C}from"../../lib/usage.mjs";import{warn as I}from"../../lib/warn.mjs";import{start as M}from"../../lib/record.mjs";async function R(e,s={}){const{transport:$}=_.state,{error:b}=q,a=S(q,_,"openai"),A=e&&typeof e=="object"&&!Array.isArray(e),l=C({model:null,requested:A&&typeof e.model=="string"?e.model:null,upstream:null,front:"openai",stream:!1},s.onUsage,(o,t)=>I(a.config,a.state,o,{type:"usage",...t,log:s.log})),c=h((o,t)=>(l.finish(t),Object.defineProperty(o,"usage",{value:l.usage,enumerable:!1,configurable:!0})),"end"),n=h((o,t,i={})=>c(b.build(o,t,{...i,front:"openai"}),o===499?"aborted":"error"),"fail");if(!e||typeof e!="object"||Array.isArray(e))return n(400,"The request body must be a JSON object",{code:"invalid_body"});if(typeof e.model!="string"||e.model==="")return n(400,"model is required",{code:"invalid_body",param:"model"});const P=Object.hasOwn(a.config.aliases,e.model)?a.config.aliases[e.model]:e.model;if(!a.state.endpoints.some(o=>J(o,P)))return n(404,`The model "${e.model}" is not served by any configured upstream.`,{code:"model_not_found",param:"model"});await U(a,e,s.signal);const d=H(a,e,{advance:!0}),f=d.pool.filter(o=>o.protocol!=="anthropic.messages");if(f.length===0)return n(400,`The model "${e.model}" is served by an Anthropic-protocol upstream, which has no embeddings API.`,{code:"embeddings_unsupported",param:"model"});const j={...e,model:d.model};l.meta.model=d.model;let m,v=null;for(let o=0;o<f.length;o++){const t=f[o];l.meta.upstream=t.name;const i=a.driver(t);t.health.inflight++,t.health.requests++;const T=g.join(t.url,await g.pathOf(i,"embeddings",t,d.model)),w={"content-type":"application/json",accept:"application/json",...i.info.headers,...g.headers(t,i.info.auth,s.headers)},y=M(a,{body:e,sent:{upstream:t.name,url:T,headers:w,body:j,state:{stream:!1}},front:"openai",requested:l.meta.requested,log:s.log,exchange:v,attempt:o+1});v??=y.id;let r;try{r=await g.json($,T,{method:"POST",headers:w,body:j,signal:s.signal})}finally{t.health.inflight--}if(s.signal?.aborted)return n(499,"The request was aborted",{code:"aborted"});const u=r.status===0;if(!u&&r.status<500)return O.succeeded(t),y.reply(r.status,r.headers,r.body),r.ok?r.body===null||typeof r.body!="object"?n(502,"The upstream returned a body that is not JSON",{code:"bad_gateway"}):(l.json(r.body),c({status:200,headers:{"content-type":"application/json"},body:r.body},"done")):c(b(r.status,r.body,{},{front:"openai",upstream:t.name,native:!0,model:e.model}),"upstream_error");const p=u?`Could not reach the upstream (${t.name}): ${r.error?.message}`:`HTTP ${r.status}`;O.failed(a.config,t,p);const k=u?{error:p}:{status:r.status,headers:r.headers,body:r.body};y.attempt(k,o+1<f.length?p:void 0),N(a,{type:"error",kind:u?"transport":"upstream",level:"error",message:u?p:`Upstream ${t.name} answered HTTP ${r.status}`,endpoint:t.name,model:d.model,log:s.log}),m={endpoint:t,result:r,reason:p}}return m.result.status===0?n(502,m.reason,{code:"upstream_unreachable"}):c(b(m.result.status,m.result.body,{},{front:"openai",upstream:m.endpoint.name,native:!0,model:e.model}),"upstream_error")}h(R,"send");export{R as send};
2
2
  //# sourceMappingURL=send.mjs.map
@@ -0,0 +1,2 @@
1
+ var n=Object.defineProperty;var r=(o,t)=>n(o,"name",{value:t,configurable:!0});import{context as c,self as e}from"../../lib/runtime.mjs";import{capture as i}from"../../lib/capture.mjs";import{probe as s}from"../../lib/health.mjs";async function u(o={}){const t=i(e,c);return await s(t,t.state.endpoints,{signal:o.signal,force:!0}),e.endpoint.status()}r(u,"check");export{u as check};
2
+ //# sourceMappingURL=check.mjs.map
@@ -1,2 +1,2 @@
1
- var m=Object.defineProperty;var n=(t,i)=>m(t,"name",{value:i,configurable:!0});import{context as c,self as u}from"../../lib/runtime.mjs";import{capture as _}from"../../lib/capture.mjs";import{defaultOf as p,nearest as g}from"../../lib/effort.mjs";async function b(t={}){const i=_(u,c,t.front),o=new Map;await Promise.all(i.state.endpoints.map(async e=>{const s=i.driver(e),r=(s.list?await s.list({endpoint:e,transport:i.state.transport,signal:t.signal,timeout:i.config.detectTimeout}):null)??(e.models??e.facts?.models??[]).map(l=>({id:l}));for(const l of r)o.set(l.id,{...l,upstream:e.name})}));for(const e of Object.keys(i.config.aliases)){const s=o.get(i.config.aliases[e]);o.set(e,{...s,id:e,alias_of:i.config.aliases[e]})}const f=[...o.values()].map(e=>({...e,...v(i.config,e)}));if(i.front==="openai")return{object:"list",data:f.map(e=>({id:e.id,object:"model",created:e.created??0,owned_by:e.owned_by??e.upstream??"llm-translator",...e.max_model_len===void 0?{}:{max_model_len:e.max_model_len},...d(e)}))};const a=f.map(e=>({type:"model",id:e.id,display_name:e.id,created_at:new Date((e.created??0)*1e3).toISOString(),...e.max_model_len===void 0?{}:{max_input_tokens:e.max_model_len},...d(e)}));return{data:a,has_more:!1,first_id:a[0]?.id??null,last_id:a.at(-1)?.id??null}}n(b,"list");function v(t,i){const o=i.alias_of??i.id,f=Object.hasOwn(t.efforts,o)?t.efforts[o]:void 0,a=i.alias_of!==void 0&&Object.hasOwn(t.pins,i.id)?t.pins[i.id]:{},e={};return a.thinking!==void 0&&(e.thinking=a.thinking),a.thinking===!1||(a.effort!==void 0?(e.effort=f?g(f.levels,a.effort):a.effort,e.levels=[e.effort],e.default_effort=e.effort):f&&(e.levels=f.levels,e.default_effort=p(f))),e}n(v,"levelsOf");function d(t){return{...t.alias_of===void 0?{}:{alias_of:t.alias_of},...t.levels===void 0?{}:{efforts:t.levels,default_effort:t.default_effort},...t.effort===void 0?{}:{effort:t.effort},...t.thinking===void 0?{}:{thinking:t.thinking}}}n(d,"extras");export{b as list};
1
+ var m=Object.defineProperty;var n=(t,i)=>m(t,"name",{value:i,configurable:!0});import{context as u,self as c}from"../../lib/runtime.mjs";import{capture as _}from"../../lib/capture.mjs";import{defaultOf as p,nearest as g}from"../../lib/effort.mjs";import{knownModels as v}from"../../lib/models.mjs";async function M(t={}){const i=_(c,u,t.front),o=new Map;await Promise.all(i.state.endpoints.map(async e=>{const s=i.driver(e),r=(s.list?await s.list({endpoint:e,transport:i.state.transport,signal:t.signal,timeout:i.config.detectTimeout}):null)??v(e);for(const l of r)o.set(l.id,{...l,upstream:e.name})}));for(const e of Object.keys(i.config.aliases)){const s=o.get(i.config.aliases[e]);o.set(e,{...s,id:e,alias_of:i.config.aliases[e]})}const f=[...o.values()].map(e=>({...e,...h(i.config,e)}));if(i.front==="openai")return{object:"list",data:f.map(e=>({id:e.id,object:"model",created:e.created??0,owned_by:e.owned_by??e.upstream??"llm-translator",...e.max_model_len===void 0?{}:{max_model_len:e.max_model_len},...d(e)}))};const a=f.map(e=>({type:"model",id:e.id,display_name:e.id,created_at:new Date((e.created??0)*1e3).toISOString(),...e.max_model_len===void 0?{}:{max_input_tokens:e.max_model_len},...d(e)}));return{data:a,has_more:!1,first_id:a[0]?.id??null,last_id:a.at(-1)?.id??null}}n(M,"list");function h(t,i){const o=i.alias_of??i.id,f=Object.hasOwn(t.efforts,o)?t.efforts[o]:void 0,a=i.alias_of!==void 0&&Object.hasOwn(t.pins,i.id)?t.pins[i.id]:{},e={};return a.thinking!==void 0&&(e.thinking=a.thinking),a.thinking===!1||(a.effort!==void 0?(e.effort=f?g(f.levels,a.effort):a.effort,e.levels=[e.effort],e.default_effort=e.effort):f&&(e.levels=f.levels,e.default_effort=p(f))),e}n(h,"levelsOf");function d(t){return{...typeof t.parent=="string"&&t.parent!==""?{parent:t.parent}:{},...t.alias_of===void 0?{}:{alias_of:t.alias_of},...t.levels===void 0?{}:{efforts:t.levels,default_effort:t.default_effort},...t.effort===void 0?{}:{effort:t.effort},...t.thinking===void 0?{}:{thinking:t.thinking}}}n(d,"extras");export{M as list};
2
2
  //# sourceMappingURL=list.mjs.map