@cldmv/llm-translator 0.8.0 → 0.10.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.
- package/README.md +9 -7
- package/dist/api/convert/anthropic/messages/to/ollama/chat/request.mjs +2 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +8 -8
- package/dist/api/convert/ollama/chat/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/ollama/chat/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/convert/ollama/chat/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/ollama/chat/to/openai/chat/stream.mjs +2 -0
- package/dist/api/convert/openai/chat/to/ollama/chat/request.mjs +2 -0
- package/dist/api/detect.mjs +1 -1
- package/dist/api/driver/azure/detect.mjs +2 -0
- package/dist/api/driver/azure/error.mjs +2 -0
- package/dist/api/driver/azure/info.mjs +2 -0
- package/dist/api/driver/azure/model/list.mjs +2 -0
- package/dist/api/driver/azure/path.mjs +2 -0
- package/dist/api/driver/azure/request.mjs +2 -0
- package/dist/api/driver/azure/settings.mjs +2 -0
- package/dist/api/driver/fireworks/detect.mjs +2 -0
- package/dist/api/driver/fireworks/info.mjs +2 -0
- package/dist/api/driver/fireworks/path.mjs +2 -0
- package/dist/api/driver/fireworks/request.mjs +2 -0
- package/dist/api/driver/fireworks/settings.mjs +2 -0
- package/dist/api/driver/gemini/detect.mjs +2 -0
- package/dist/api/driver/gemini/info.mjs +2 -0
- package/dist/api/driver/gemini/path.mjs +2 -0
- package/dist/api/driver/gemini/request.mjs +2 -0
- package/dist/api/driver/gemini/settings.mjs +2 -0
- package/dist/api/driver/groq/detect.mjs +2 -0
- package/dist/api/driver/groq/info.mjs +2 -0
- package/dist/api/driver/groq/path.mjs +2 -0
- package/dist/api/driver/groq/request.mjs +2 -0
- package/dist/api/driver/groq/settings.mjs +2 -0
- package/dist/api/driver/localai/chunk.mjs +2 -0
- package/dist/api/driver/localai/detect.mjs +2 -0
- package/dist/api/driver/localai/info.mjs +2 -0
- package/dist/api/driver/localai/request.mjs +2 -0
- package/dist/api/driver/localai/response.mjs +2 -0
- package/dist/api/driver/localai/settings.mjs +2 -0
- package/dist/api/driver/ollama/info.mjs +1 -1
- package/dist/api/driver/ollama/request.mjs +1 -1
- package/dist/api/driver/openrouter/chunk.mjs +2 -0
- package/dist/api/driver/openrouter/detect.mjs +2 -0
- package/dist/api/driver/openrouter/info.mjs +2 -0
- package/dist/api/driver/openrouter/path.mjs +2 -0
- package/dist/api/driver/openrouter/request.mjs +2 -0
- package/dist/api/driver/openrouter/response.mjs +2 -0
- package/dist/api/driver/openrouter/settings.mjs +2 -0
- package/dist/api/driver/tgi/chunk.mjs +2 -0
- package/dist/api/driver/tgi/detect.mjs +2 -0
- package/dist/api/driver/tgi/info.mjs +2 -0
- package/dist/api/driver/tgi/request.mjs +2 -0
- package/dist/api/driver/tgi/response.mjs +2 -0
- package/dist/api/driver/tgi/settings.mjs +2 -0
- package/dist/api/driver/together/detect.mjs +2 -0
- package/dist/api/driver/together/info.mjs +2 -0
- package/dist/api/driver/together/request.mjs +2 -0
- package/dist/api/driver/together/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +1 -1
- package/dist/api/driver/vllm/info.mjs +1 -1
- package/dist/api/driver/vllm/model/list.mjs +1 -1
- package/dist/api/driver/xai/detect.mjs +2 -0
- package/dist/api/driver/xai/info.mjs +2 -0
- package/dist/api/driver/xai/request.mjs +2 -0
- package/dist/api/driver/xai/settings.mjs +2 -0
- package/dist/api/embeddings/send.mjs +1 -1
- package/dist/api/health/check.mjs +2 -0
- package/dist/api/model/list.mjs +1 -1
- package/dist/api/request.mjs +2 -2
- package/dist/api/response.mjs +1 -1
- package/dist/api/send.mjs +1 -1
- package/dist/api/status.mjs +1 -1
- package/dist/api/stream.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/azure.mjs +2 -0
- package/dist/lib/backends.mjs +1 -1
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/config.mjs +1 -1
- package/dist/lib/health.mjs +2 -0
- package/dist/lib/http.mjs +1 -1
- package/dist/lib/models.mjs +1 -1
- package/dist/lib/ndjson.mjs +4 -0
- package/dist/lib/ollama.mjs +3 -0
- package/dist/lib/openrouter.mjs +2 -0
- package/dist/lib/pool.mjs +1 -1
- package/dist/lib/presets.mjs +2 -0
- package/dist/lib/route.mjs +1 -1
- package/dist/lib/settings.mjs +1 -1
- package/dist/lib/tgi.mjs +2 -0
- package/dist/lib/vllm.mjs +4 -0
- package/package.json +1 -1
- package/types/src/api/convert/anthropic/messages/to/ollama/chat/request.d.mts +14 -0
- package/types/src/api/convert/ollama/chat/to/anthropic/messages/response.d.mts +10 -0
- package/types/src/api/convert/ollama/chat/to/anthropic/messages/stream.d.mts +14 -0
- package/types/src/api/convert/ollama/chat/to/openai/chat/response.d.mts +10 -0
- package/types/src/api/convert/ollama/chat/to/openai/chat/stream.d.mts +13 -0
- package/types/src/api/convert/openai/chat/to/ollama/chat/request.d.mts +12 -0
- package/types/src/api/driver/azure/detect.d.mts +8 -0
- package/types/src/api/driver/azure/error.d.mts +15 -0
- package/types/src/api/driver/azure/info.d.mts +31 -0
- package/types/src/api/driver/azure/model/list.d.mts +7 -0
- package/types/src/api/driver/azure/path.d.mts +7 -0
- package/types/src/api/driver/azure/request.d.mts +8 -0
- package/types/src/api/driver/azure/settings.d.mts +23 -0
- package/types/src/api/driver/fireworks/detect.d.mts +8 -0
- package/types/src/api/driver/fireworks/info.d.mts +13 -0
- package/types/src/api/driver/fireworks/path.d.mts +7 -0
- package/types/src/api/driver/fireworks/request.d.mts +7 -0
- package/types/src/api/driver/fireworks/settings.d.mts +5 -0
- package/types/src/api/driver/gemini/detect.d.mts +8 -0
- package/types/src/api/driver/gemini/info.d.mts +13 -0
- package/types/src/api/driver/gemini/path.d.mts +7 -0
- package/types/src/api/driver/gemini/request.d.mts +7 -0
- package/types/src/api/driver/gemini/settings.d.mts +5 -0
- package/types/src/api/driver/groq/detect.d.mts +8 -0
- package/types/src/api/driver/groq/info.d.mts +13 -0
- package/types/src/api/driver/groq/path.d.mts +7 -0
- package/types/src/api/driver/groq/request.d.mts +7 -0
- package/types/src/api/driver/groq/settings.d.mts +5 -0
- package/types/src/api/driver/localai/chunk.d.mts +25 -0
- package/types/src/api/driver/localai/detect.d.mts +6 -0
- package/types/src/api/driver/localai/info.d.mts +33 -0
- package/types/src/api/driver/localai/request.d.mts +10 -0
- package/types/src/api/driver/localai/response.d.mts +26 -0
- package/types/src/api/driver/localai/settings.d.mts +25 -0
- package/types/src/api/driver/ollama/info.d.mts +7 -2
- package/types/src/api/driver/openrouter/chunk.d.mts +25 -0
- package/types/src/api/driver/openrouter/detect.d.mts +26 -0
- package/types/src/api/driver/openrouter/info.d.mts +30 -0
- package/types/src/api/driver/openrouter/path.d.mts +8 -0
- package/types/src/api/driver/openrouter/request.d.mts +10 -0
- package/types/src/api/driver/openrouter/response.d.mts +8 -0
- package/types/src/api/driver/openrouter/settings.d.mts +26 -0
- package/types/src/api/driver/tgi/chunk.d.mts +9 -0
- package/types/src/api/driver/tgi/detect.d.mts +6 -0
- package/types/src/api/driver/tgi/info.d.mts +33 -0
- package/types/src/api/driver/tgi/request.d.mts +9 -0
- package/types/src/api/driver/tgi/response.d.mts +9 -0
- package/types/src/api/driver/tgi/settings.d.mts +25 -0
- package/types/src/api/driver/together/detect.d.mts +8 -0
- package/types/src/api/driver/together/info.d.mts +13 -0
- package/types/src/api/driver/together/request.d.mts +7 -0
- package/types/src/api/driver/together/settings.d.mts +5 -0
- package/types/src/api/driver/vllm/detect.d.mts +1 -1
- package/types/src/api/driver/vllm/info.d.mts +1 -1
- package/types/src/api/driver/vllm/model/list.d.mts +3 -1
- package/types/src/api/driver/xai/detect.d.mts +8 -0
- package/types/src/api/driver/xai/info.d.mts +13 -0
- package/types/src/api/driver/xai/request.d.mts +7 -0
- package/types/src/api/driver/xai/settings.d.mts +5 -0
- package/types/src/api/endpoint/status.d.mts +5 -2
- package/types/src/api/health/check.d.mts +8 -0
- package/types/src/api/status.d.mts +1 -1
- package/types/src/lib/azure.d.mts +17 -0
- package/types/src/lib/backends.d.mts +22 -0
- package/types/src/lib/config.d.mts +12 -0
- package/types/src/lib/events.d.mts +2 -2
- package/types/src/lib/health.d.mts +22 -0
- package/types/src/lib/http.d.mts +13 -2
- package/types/src/lib/models.d.mts +27 -2
- package/types/src/lib/ndjson.d.mts +16 -0
- package/types/src/lib/ollama.d.mts +86 -0
- package/types/src/lib/openrouter.d.mts +23 -0
- package/types/src/lib/pool.d.mts +30 -4
- package/types/src/lib/presets.d.mts +98 -0
- package/types/src/lib/route.d.mts +1 -1
- package/types/src/lib/settings.d.mts +5 -0
- package/types/src/lib/tgi.d.mts +33 -0
- package/types/src/lib/vllm.d.mts +47 -0
package/README.md
CHANGED
|
@@ -17,18 +17,20 @@ 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.
|
|
20
|
+
### Latest: v0.10.0 (November 2026)
|
|
21
21
|
|
|
22
|
-
- **
|
|
23
|
-
-
|
|
24
|
-
-
|
|
22
|
+
- **Native `/v1/messages` for vLLM** — set `nativeMessages` (`true` or `"auto"`) and Anthropic requests go to vLLM's own endpoint with only normalisation. Prefills, document blocks and deferred tools are still converted, and an upstream without the route falls back to conversion.
|
|
23
|
+
- **Readiness probes and LoRA adapters** — pools check vLLM's `/health` and try ready upstreams first (`pool.healthInterval`, `pool.healthTimeout`, a `health` event, `health.check()`). Adapters are routable and carry `parent` in model lists.
|
|
24
|
+
- **Hosted provider drivers** — Groq, Together, Fireworks, xAI and Gemini are bound by host name, with their token fields, reasoning fields and rejected request fields handled from one table.
|
|
25
|
+
- **Ollama's native `/api/chat`** — set `api: "native"` on an Ollama upstream to use `think`, `options` and `format`, with NDJSON streaming converted for both fronts.
|
|
26
|
+
- [View full v0.10.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.10.0.md)
|
|
25
27
|
|
|
26
28
|
### Recent Releases
|
|
27
29
|
|
|
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))
|
|
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))
|
|
28
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))
|
|
29
33
|
- **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))
|
|
30
|
-
- **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))
|
|
31
|
-
- **v0.4.0** (November 2026) — per-model effort levels and aliases that pin effort and thinking, non-standard finish reasons, a configurable tool-error marker, per-upstream `pingInterval` and a Node.js 22.15 floor ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.4.0.md))
|
|
32
34
|
|
|
33
35
|
📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/llm-translator/tree/master/docs/changelog/) folder.**
|
|
34
36
|
|
|
@@ -127,7 +129,7 @@ Then point Claude Code at it with `ANTHROPIC_BASE_URL=http://127.0.0.1:8787`. Th
|
|
|
127
129
|
|
|
128
130
|
## 📚 Configuration
|
|
129
131
|
|
|
130
|
-
`createTranslator(config)` takes `front`, `upstreams` (URLs or objects with `url`, `apiKey`, `backend`, `models`, `default` and `settings`), `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.
|
|
132
|
+
`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
133
|
|
|
132
134
|
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
135
|
|
|
@@ -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
|
|
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(`
|
|
2
2
|
|
|
3
|
-
`)}
|
|
4
|
-
`);return[{type:"text",text:`[Search result: ${
|
|
5
|
-
${
|
|
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(`
|
|
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
6
|
${l}
|
|
7
|
-
</system-reminder>`;c([{type:"text",text:
|
|
8
|
-
`);
|
|
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)?`
|
|
9
9
|
|
|
10
|
-
`:"")+u,d=a)}const m={};return s!==""&&(m[n]=s),
|
|
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(`
|
|
11
11
|
|
|
12
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(`
|
|
13
13
|
|
|
14
14
|
`):f.parts})}else if(f.role==="assistant"){const h={role:"assistant",content:f.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)&&(
|
|
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};
|
|
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
|
|
@@ -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
|
package/dist/api/detect.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=Object.defineProperty;var o=(t,e)=>h(t,"name",{value:e,configurable:!0});import{context as g,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 j(t={}){const e=w(u,g),{status:l}=u,f=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 m(`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&&!$(s))throw new m(`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=>U(e,a,f,r))),l()}o(j,"detect");async function U(t,e,l,f){let r,a=null;if(e.backend!=="auto"){if(r=t.drivers.find(s=>s.name===e.backend),!r)throw new m(`Unknown backend "${e.backend}" for upstream ${e.name}`,{code:"unknown_backend",status:500});a={version:e.version}}else if(l){const s=URL.canParse(e.url)?new URL(e.url).hostname:"",i={endpoint:e,...f,probes:new Map};let n=!1;for(const[v,c]of t.drivers.entries()){if(!n&&c.info.probes?.length>0&&!c.info.hosts?.includes(s)){n=!0;for(const d of t.drivers.slice(v))for(const b of d.info.probes??[])k.probe(i,b,d.info)}if(a=await x(c,i),a){r=c;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 m(`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={},l&&e.backend==="auto"&&r.probe){const s=o(n=>e.settings[n]!==void 0||t.config.settings[n]!==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,...f}))}a.reachable===!1?p(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}):y({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})}o(U,"bind");async function x(t,e){try{return await t.detect?.(e)??null}catch{return null}}o(x,"detectWith");export{j as detect};
|
|
2
2
|
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +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};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=Object.defineProperty;var n=(r,e)=>f(r,"name",{value:e,configurable:!0});import*as c from"../../../lib/upstream-error.mjs";function p(r){return!r||typeof r!="object"?[]:Object.entries(r).filter(([,e])=>e?.filtered===!0).map(([e,t])=>typeof t.severity=="string"?`${e} (${t.severity})`:e)}n(p,"filtered");function a(r,e){const t=c.parse(e,r);let o=t.message;if(t.code==="content_filter"){const i=p(e?.error?.innererror?.content_filter_result);i.length>0&&(o+=` Filtered categories: ${i.join(", ")}.`)}return{error:{message:o,type:t.type,param:t.param??null,code:t.code??r}}}n(a,"error");export{a as error};
|
|
2
|
+
//# sourceMappingURL=error.mjs.map
|
|
@@ -0,0 +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};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.defineProperty;var t=(o,r)=>e(o,"name",{value:r,configurable:!0});import{fetchModels as i}from"../../../../lib/models.mjs";import{route as p}from"../../../../lib/azure.mjs";function u(o){return i({...o,auth:"api-key",path:p("models",o.endpoint)})}t(u,"list");export{u as list};
|
|
2
|
+
//# sourceMappingURL=list.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=Object.defineProperty;var i=(n,o)=>m(n,"name",{value:o,configurable:!0});import{noEmptyTools as c}from"../../../lib/normalize.mjs";const d="2024-09-01";function u(n,o){const t=c(n),e=o?.endpoint?.apiVersion?.match(/^\d{4}-\d{2}-\d{2}/)?.[0];if(e===void 0||e>=d||t.max_completion_tokens===void 0)return t;const{max_completion_tokens:s,...r}=t;return{...r,max_tokens:s}}i(u,"request");export{u as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var e=(n,t)=>o(n,"name",{value:t,configurable:!0});function s(){return{maxTokensField:"max_completion_tokens",thinking:"reasoning_effort",thinkingBudget:!1,effort:!0,topK:!1,prefill:"none",deferredTools:"drop",streamUsage:!0,continuousUsage:!1}}e(s,"settings");export{s as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var i=Object.defineProperty;var o=(l,e)=>i(l,"name",{value:e,configurable:!0});function d(l,e){return e?.state?.convert?.localaiSingleCall!==!0||!Array.isArray(l?.choices)?l:{...l,choices:l.choices.map(t=>{const a=t?.delta?.tool_calls;if(!Array.isArray(a))return t;const r={...t.delta},s=a.filter(n=>(n?.index??0)===0);return s.length>0?r.tool_calls=s:delete r.tool_calls,{...t,delta:r}})}}o(d,"chunk");export{d as chunk};
|
|
2
|
+
//# sourceMappingURL=chunk.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var v=Object.defineProperty;var n=(o,i)=>v(o,"name",{value:i,configurable:!0});import*as s from"../../../lib/http.mjs";import{modelsOf as d}from"../../../lib/models.mjs";import{isLocalaiDiscovery as p,isLocalaiVersion as l,objectOf as t}from"../../../lib/backends.mjs";async function u(o){const[i,a,c]=await Promise.all([s.probe(o,"/version"),s.probe(o,"/.well-known/localai.json"),s.probe(o,"/v1/models")]),r=t(i),e=t(a);return!l(r)&&!p(e)?null:{version:l(r)?r.version:e.version,models:(d(c)??[]).map(m=>m.id)}}n(u,"detect");export{u as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var e=(o,a)=>t(o,"name",{value:a,configurable:!0});function n(){return{name:"localai",protocol:"openai.chat",order:52,auth:"bearer",strict:!1,probes:["/version","/.well-known/localai.json"],fields:["top_k","min_p","repeat_penalty","repeat_last_n","ignore_eos","typical_p","chat_template_kwargs","grammar"],paths:{chat:"/v1/chat/completions",models:"/v1/models",version:"/version",discovery:"/.well-known/localai.json"}}}e(n,"info");export{n as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var a=(l,t)=>n(l,"name",{value:t,configurable:!0});import{noEmptyTools as o}from"../../../lib/normalize.mjs";function r(l,t){const e={...o(l)};return e.repetition_penalty!==void 0&&(e.repeat_penalty===void 0&&(e.repeat_penalty=e.repetition_penalty),delete e.repetition_penalty),e.parallel_tool_calls===!1&&t?.state&&(t.state.localaiSingleCall=!0,delete e.parallel_tool_calls),e}a(r,"request");export{r as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var l=(r,s)=>t(r,"name",{value:s,configurable:!0});function c(r,s){return s?.state?.convert?.localaiSingleCall!==!0||!Array.isArray(r?.choices)?r:{...r,choices:r.choices.map(e=>{const a=e?.message?.tool_calls;return!Array.isArray(a)||a.length<2?e:{...e,message:{...e.message,tool_calls:a.slice(0,1)}}})}}l(c,"response");export{c as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var e=(t,n)=>s(t,"name",{value:n,configurable:!0});function r(){return{reasoningField:"reasoning",maxTokensField:"max_tokens",thinking:"chat_template_kwargs",thinkingBudget:!1,effort:!1,topK:!0,prefill:"none",responseFormat:!0,streamUsage:!0,continuousUsage:!1}}e(r,"settings");export{r as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
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
|
|
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
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var i=(r,e)=>n(r,"name",{value:e,configurable:!0});function f(r){if(r?.error!==void 0)return r;const e=Array.isArray(r?.choices)?r.choices.find(o=>o?.error)?.error:void 0;return e===void 0?r:{...r,error:e}}i(f,"chunk");export{f as chunk};
|
|
2
|
+
//# sourceMappingURL=chunk.mjs.map
|
|
@@ -0,0 +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};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var d=Object.defineProperty;var n=(e,t)=>d(e,"name",{value:t,configurable:!0});const i={chat:"/v1/chat/completions",embeddings:"/v1/embeddings",models:"/v1/models"};function s(e,{endpoint:t}){return(t.url.endsWith("/api")?"":"/api")+i[e]}n(s,"path");export{s as path};
|
|
2
|
+
//# sourceMappingURL=path.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var i=(t,r)=>a(t,"name",{value:r,configurable:!0});import{noEmptyTools as u}from"../../../lib/normalize.mjs";function g(t,r){const{reasoning_effort:o,...n}=u(t);if(n.reasoning!==void 0&&n.reasoning!==null)return n;const e=r?.state?.thinkingBudget;if(Number.isInteger(e)&&e>0){const s=Number.isInteger(n.max_tokens)?Math.max(1,n.max_tokens-1):e;return{...n,reasoning:{max_tokens:Math.min(e,s)}}}return o===void 0?n:{...n,reasoning:{effort:o}}}i(g,"request");export{g as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var e=(n,t)=>r(n,"name",{value:t,configurable:!0});function o(){return{reasoningField:"reasoning",reasoningRoundTrip:!0,maxTokensField:"max_tokens",thinking:"reasoning_effort",thinkingBudget:!1,effort:!0,topK:!0,prefill:"none",streamUsage:!0,continuousUsage:!1}}e(o,"settings");export{o as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(t,e)=>a(t,"name",{value:e,configurable:!0});import{finish as f,toolCalls as d}from"../../../lib/tgi.mjs";function m(t,e){if(!Array.isArray(t?.choices))return t;const i=e?.state??{};return{...t,choices:t.choices.map(n=>{if(n===null||typeof n!="object")return n;const s={...n},l=d(n.delta?.tool_calls);return l!==void 0&&(i.tgiToolCalls=!0,s.delta={...n.delta,tool_calls:l.map(r=>r?.id===""?u(r):r)}),n.finish_reason!==void 0&&(s.finish_reason=f(n.finish_reason,i.tgiToolCalls===!0)),s})}}o(m,"chunk");function u(t){const e={...t};return delete e.id,e}o(u,"withoutId");export{m as chunk};
|
|
2
|
+
//# sourceMappingURL=chunk.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.defineProperty;var n=(t,o)=>e(t,"name",{value:o,configurable:!0});import*as i from"../../../lib/http.mjs";import{isTgiInfo as r,objectOf as a}from"../../../lib/backends.mjs";async function f(t){const o=a(await i.probe(t,"/info"));return r(o)?{version:o.version,model:o.model_id,maxInputTokens:o.max_input_tokens,maxTotalTokens:o.max_total_tokens}:null}n(f,"detect");export{f as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var o=(e,t)=>r(e,"name",{value:t,configurable:!0});function i(){return{name:"tgi",protocol:"openai.chat",order:45,auth:"bearer",strict:!1,probes:["/info"],fields:["grammar"],paths:{chat:"/v1/chat/completions",models:"/v1/models",info:"/info"}}}o(i,"info");export{i as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var n=(r,o)=>t(r,"name",{value:o,configurable:!0});import{noEmptyTools as m}from"../../../lib/normalize.mjs";import{grammar as f}from"../../../lib/tgi.mjs";function i(r,o){const e={...m(r)};if(e.grammar!==void 0&&(e.response_format===void 0&&(e.response_format=e.grammar),delete e.grammar),e.response_format!==void 0)if(e.tools!==void 0){delete e.response_format;const s=o?.state?.dropped;Array.isArray(s)&&!s.includes("response_format")&&s.push("response_format")}else e.response_format=f(e.response_format);return e}n(i,"request");export{i as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var r=(t,n)=>l(t,"name",{value:n,configurable:!0});import{finish as i,toolCalls as a}from"../../../lib/tgi.mjs";function m(t){if(!Array.isArray(t?.choices))return t;const n={...t,choices:t.choices.map(e=>{if(e===null||typeof e!="object")return e;const s=a(e.message?.tool_calls,!0),o={...e,finish_reason:i(e.finish_reason,s!==void 0&&s.length>0)};return s!==void 0&&(o.message={...e.message,tool_calls:s}),o})};return n.object==="text_completion"&&(n.object="chat.completion"),n}r(m,"response");export{m as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var e=(n,t)=>s(n,"name",{value:t,configurable:!0});function a(){return{maxTokensField:"max_tokens",thinking:"none",thinkingBudget:!1,effort:!1,topK:!1,prefill:"none",responseFormat:!0,streamUsage:!0,continuousUsage:!1}}e(a,"settings");export{a as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
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
|
|
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
|
|
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
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var x=Object.defineProperty;var h=(e,s)=>x(e,"name",{value:s,configurable:!0});import{context as
|
|
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
|
package/dist/api/model/list.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=Object.defineProperty;var n=(t,i)=>m(t,"name",{value:i,configurable:!0});import{context as
|
|
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
|