@cldmv/llm-translator 0.7.0 → 0.9.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 +7 -7
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +8 -8
- package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
- package/dist/api/convert/openai/chat/to/anthropic/messages/stream.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/lmstudio/detect.mjs +2 -0
- package/dist/api/driver/lmstudio/info.mjs +2 -0
- package/dist/api/driver/lmstudio/request.mjs +2 -0
- package/dist/api/driver/lmstudio/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/mistral/chunk.mjs +2 -0
- package/dist/api/driver/mistral/detect.mjs +2 -0
- package/dist/api/driver/mistral/info.mjs +2 -0
- package/dist/api/driver/mistral/request.mjs +2 -0
- package/dist/api/driver/mistral/response.mjs +2 -0
- package/dist/api/driver/mistral/settings.mjs +2 -0
- 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/vllm/detect.mjs +1 -1
- package/dist/api/embeddings/send.mjs +1 -1
- package/dist/api/request.mjs +2 -2
- package/dist/api/send.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/fanout.mjs +2 -0
- package/dist/lib/finish.mjs +1 -1
- package/dist/lib/http.mjs +1 -1
- package/dist/lib/models.mjs +1 -1
- package/dist/lib/openrouter.mjs +2 -0
- package/dist/lib/tgi.mjs +2 -0
- package/dist/lib/typed.mjs +2 -0
- package/dist/lib/usage.mjs +1 -1
- package/package.json +1 -1
- package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +1 -1
- 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/lmstudio/detect.d.mts +6 -0
- package/types/src/api/driver/lmstudio/info.d.mts +31 -0
- package/types/src/api/driver/lmstudio/request.d.mts +6 -0
- package/types/src/api/driver/lmstudio/settings.d.mts +23 -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/mistral/chunk.d.mts +8 -0
- package/types/src/api/driver/mistral/detect.d.mts +26 -0
- package/types/src/api/driver/mistral/info.d.mts +35 -0
- package/types/src/api/driver/mistral/request.d.mts +6 -0
- package/types/src/api/driver/mistral/response.d.mts +7 -0
- package/types/src/api/driver/mistral/settings.d.mts +24 -0
- 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/vllm/detect.d.mts +1 -1
- package/types/src/api/send.d.mts +7 -0
- package/types/src/lib/azure.d.mts +17 -0
- package/types/src/lib/backends.d.mts +29 -0
- package/types/src/lib/config.d.mts +8 -0
- package/types/src/lib/fanout.d.mts +68 -0
- package/types/src/lib/finish.d.mts +14 -3
- package/types/src/lib/http.d.mts +13 -2
- package/types/src/lib/models.d.mts +2 -2
- package/types/src/lib/openrouter.d.mts +23 -0
- package/types/src/lib/tgi.d.mts +33 -0
- package/types/src/lib/typed.d.mts +10 -0
- package/types/src/lib/usage.d.mts +20 -0
package/README.md
CHANGED
|
@@ -17,18 +17,18 @@ 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.9.0 (November 2026)
|
|
21
21
|
|
|
22
|
-
- **
|
|
23
|
-
- **
|
|
24
|
-
- [View full v0.
|
|
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)
|
|
25
25
|
|
|
26
26
|
### Recent Releases
|
|
27
27
|
|
|
28
|
+
- **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
|
+
- **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))
|
|
28
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))
|
|
29
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))
|
|
30
|
-
- **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))
|
|
31
|
-
- **v0.3.1** (November 2026) — patched the dev-only `minimatch` and `katex` lint dependencies and corrected the v0.3.0 issue links; no runtime changes ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.3.1.md))
|
|
32
32
|
|
|
33
33
|
📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/llm-translator/tree/master/docs/changelog/) folder.**
|
|
34
34
|
|
|
@@ -127,7 +127,7 @@ Then point Claude Code at it with `ANTHROPIC_BASE_URL=http://127.0.0.1:8787`. Th
|
|
|
127
127
|
|
|
128
128
|
## 📚 Configuration
|
|
129
129
|
|
|
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.
|
|
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
131
|
|
|
132
132
|
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
133
|
|
|
@@ -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
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _=Object.defineProperty;var
|
|
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};
|
|
2
2
|
//# sourceMappingURL=response.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
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};
|
|
2
2
|
//# sourceMappingURL=stream.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 a=(o,e)=>i(o,"name",{value:e,configurable:!0});import*as r from"../../../lib/http.mjs";import{isLmstudioModels as s,objectOf as m}from"../../../lib/backends.mjs";async function p(o){const e=m(await r.probe(o,"/api/v0/models"));if(!s(e))return null;const d=e.data.filter(t=>t.type!=="embeddings");return{models:d.map(t=>t.id),loaded:d.filter(t=>t.state==="loaded").map(t=>t.id)}}a(p,"detect");export{p as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function i(){return{name:"lmstudio",protocol:"openai.chat",order:55,auth:"bearer",strict:!1,probes:["/api/v0/models"],paths:{chat:"/v1/chat/completions",models:"/v1/models",listing:"/api/v0/models"}}}o(i,"info");export{i as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var e=(n,t)=>s(n,"name",{value:t,configurable:!0});function i(){return{thinking:"none",thinkingBudget:!1,effort:!1,topK:!1,prefill:"none",streamUsage:!0,continuousUsage:!1}}e(i,"settings");export{i 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
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var i=(t,n)=>r(t,"name",{value:n,configurable:!0});import{flatten as s}from"../../../lib/typed.mjs";function l(t){const n=s(t?.choices?.[0]?.delta?.content);if(!n)return t;const[e,...c]=t.choices,o={...e.delta,content:n.text};return n.thinking!==""&&(o.reasoning_content=n.thinking),{...t,choices:[{...e,delta:o},...c]}}i(l,"chunk");export{l as chunk};
|
|
2
|
+
//# sourceMappingURL=chunk.mjs.map
|
|
@@ -0,0 +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};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var d=(o,e)=>n(o,"name",{value:e,configurable:!0});import{noEmptyTools as t}from"../../../lib/normalize.mjs";function s(o){const e={...t(o)};return e.seed!==void 0&&(e.random_seed===void 0&&(e.random_seed=e.seed),delete e.seed),e.tool_choice==="required"&&(e.tool_choice="any"),e}d(s,"request");export{s as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var i=Object.defineProperty;var s=(n,t)=>i(n,"name",{value:t,configurable:!0});import{flatten as a}from"../../../lib/typed.mjs";function f(n){return Array.isArray(n?.choices)?{...n,choices:n.choices.map(t=>{const e=a(t?.message?.content);if(!e)return t;const r={...t.message,content:e.text};return e.thinking!==""&&(r.reasoning_content=e.thinking),{...t,message:r}})}:n}s(f,"response");export{f 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 i(){return{reasoningField:"reasoning_content",maxTokensField:"max_tokens",thinking:"none",thinkingBudget:!1,effort:!1,topK:!1,prefill:"none",streamUsage:!0,continuousUsage:!1}}e(i,"settings");export{i as settings};
|
|
2
|
+
//# sourceMappingURL=settings.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 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};
|
|
2
2
|
//# sourceMappingURL=detect.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 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};
|
|
2
2
|
//# sourceMappingURL=send.mjs.map
|
package/dist/api/request.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var T=Object.defineProperty;var p=(e,n)=>T(e,"name",{value:n,configurable:!0});import{context as I,self as q}from"../lib/runtime.mjs";import{capture as C}from"../lib/capture.mjs";import{resolve as L}from"../lib/route.mjs";import*as
|
|
2
|
-
${
|
|
1
|
+
var T=Object.defineProperty;var p=(e,n)=>T(e,"name",{value:n,configurable:!0});import{context as I,self as q}from"../lib/runtime.mjs";import{capture as C}from"../lib/capture.mjs";import{resolve as L}from"../lib/route.mjs";import*as w from"../lib/http.mjs";import{filterChatBody as B}from"../lib/passthrough.mjs";import{addSampling as E}from"../lib/sampling.mjs";import*as F from"../lib/images.mjs";import*as S from"../lib/tools.mjs";import{LIMITS as M}from"../lib/toolsearch.mjs";import{warn as b}from"../lib/warn.mjs";import{emit as P}from"../lib/events.mjs";import{fit as R,pinBody as H}from"../lib/effort.mjs";import{relax as z,strictTools as A}from"../lib/strict.mjs";import{TranslatorError as D}from"../lib/errors.mjs";function G(e){return`${e.driver}:${e.protocol}:${URL.canParse(e.url)?new URL(e.url).host:e.url}`}p(G,"producerOf");async function ne(e,n={}){const r=C(q,I,n.front),c=L(r,e,{endpoint:n.endpoint,advance:n.hold===!0&&n.endpoint===void 0});if(n.hold!==!0)return _(r,e,n,c);c.endpoint.health.inflight++;try{return await _(r,e,n,c)}catch(t){throw c.endpoint.health.inflight--,t}}p(ne,"request");function J(e,n,r,c,t,l){const g=A(n);if(g.length===0)return n;const i=g.filter(a=>a.problems.length>0);if(i.length>0&&t.unknownFields==="error")throw new D(`tools: ${i[0].name}: schema is outside the strict subset (${i[0].problems.join("; ")})`,{code:"unsupported_content",param:"tools"});const k=z(n);if(l.retry===!0)return k;const u=p((a,h)=>b(e.config,e.state,a,{kind:h,endpoint:r.name,log:l.log}),"tell");for(const a of i)u(`Upstream ${r.name}: strict tool ${a.name} has a schema outside the strict subset: ${a.problems.join("; ")} (sent without strict)`,"strict");const d=g.filter(a=>a.problems.length===0);return c.info.strict!==!0&&d.length>0&&u(`Upstream ${r.name}: the ${c.name} backend does not enforce strict tool use (${d.map(a=>a.name).join(", ")})`,"strict"),k}p(J,"checkStrict");async function _(e,n,r,c){const{endpoint:t,model:l,unserved:g,convert:i,pool:k,pin:u}=c,d=Object.hasOwn(e.config.efforts,l)?e.config.efforts[l]:void 0;u&&(n=H(n,u,e.front));const a=e.driver(t),h=`${t.name}
|
|
2
|
+
${l}`,O=r.images===!1||e.state.textOnly.has(h)&&e.settings(t).imageFallback,$=e.settings(t),x=r.jsonObject==="instruction"||e.state.jsonInstruction.has(h)&&$.jsonObjectFallback,m={...O?{...$,images:!1}:$,...x?{jsonObject:"instruction"}:{},...u?.effort===void 0?{}:{effort:!0}},v=n.stream===!0;let o,s;i?({body:o,state:s}=await i.request(n,m,{producer:G(t),budget:r.budget,listed:d!==void 0,toolCallIds:a.info.toolCallIds}),s.toolSearch?.capped&&b(e.config,e.state,`Tool search: more than ${M.definitions} tool definitions came back in ToolSearch results for ${t.name}; the rest are not offered.`,{kind:"toolsearch",endpoint:t.name,log:r.log})):o=e.front==="openai"&&(r.filter??m.passthroughFilter===!0)?B(n,a.info.fields):{...n};const y=e.front==="anthropic"?n.metadata?.sampling:void 0;if(t.protocol==="openai.chat"){const f=[];o=E(o,y,m,a.info.fields,f),s&&s.dropped.push(...f.filter(j=>!s.dropped.includes(j)))}else if(!i&&y!==void 0&&o.metadata?.sampling!==void 0){const{sampling:f,...j}=o.metadata;o={...o,metadata:j}}if(r.usage===!0&&v&&e.front==="openai"){if(i)s.includeUsage=!0;else if(m.streamUsage){const f=o.stream_options&&typeof o.stream_options=="object"?o.stream_options:{};o.stream_options={...f,include_usage:!0}}}O&&!i&&e.front==="openai"&&(o=F.strip(o)),r.tools===!1&&(o=S.strip(o)),o.model=l,o=J(e,o,t,a,m,r),d&&t.protocol==="openai.chat"&&R(o,d,l,(f,j)=>b(e.config,e.state,f,{type:"effort",endpoint:t.name,model:l,...j,log:r.log})),s?.reasoningMissing&&b(e.config,e.state,`Upstream ${t.name}: assistant turns with tool calls have no reasoning to send back (the client dropped its thinking blocks or their signatures), which servers that need it with tools will refuse.`,{kind:"reasoning",endpoint:t.name,log:r.log}),a.request&&(o=await a.request(o,{endpoint:t,settings:m,levels:d,state:s,warn:p(f=>b(e.config,e.state,f,{kind:"driver",endpoint:t.name,log:r.log}),"warn")})),s?.dropped?.length>0&&r.retry!==!0&&P(e,{type:"dropped",level:"debug",message:`Upstream ${t.name}: dropped ${s.dropped.join(", ")}`,endpoint:t.name,model:l,fields:[...s.dropped],log:r.log});const U=await w.pathOf(a,t.protocol==="openai.chat"?"chat":"messages",t,l);return{upstream:t.name,pool:k.map(f=>f.name),method:"POST",url:w.join(t.url,U),path:U,headers:{"content-type":"application/json",accept:v?"text/event-stream":"application/json",...a.info.headers,...i===null&&t.protocol==="anthropic.messages"?r.clientHeaders:void 0,...w.headers(t,a.info.auth,r.headers)},body:o,state:{v:1,upstream:t.name,front:e.front,native:i===null,model:n.model,stream:v,unserved:g,convert:s},images:{sent:F.carries(o),retry:m.imageFallback&&t.protocol==="openai.chat",key:h},tools:{sent:S.carries(o),retry:m.toolFallback&&t.protocol==="openai.chat"},json:{sent:s?.jsonSchemaEmulated===!0,retry:m.jsonObjectFallback&&t.protocol==="anthropic.messages",key:h}}}p(_,"prepare");export{ne as request};
|
|
3
3
|
//# sourceMappingURL=request.mjs.map
|
package/dist/api/send.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var it=Object.defineProperty;var u=(c,r)=>it(c,"name",{value:r,configurable:!0});import{context as G,self as Z}from"../lib/runtime.mjs";import{TranslatorError as z}from"../lib/errors.mjs";import*as tt from"../lib/http.mjs";import*as ut from"../lib/images.mjs";import*as lt from"../lib/tools.mjs";import{parse as ct}from"../lib/upstream-error.mjs";import{meter as mt,normalize as dt}from"../lib/usage.mjs";import{capture as ft}from"../lib/capture.mjs";import{estimate as pt,bodyLength as gt,output as ht,patch as yt,stream as wt}from"../lib/estimate.mjs";import{warn as et}from"../lib/warn.mjs";import{start as bt}from"../lib/record.mjs";import{emit as at}from"../lib/events.mjs";import*as rt from"../lib/pool.mjs";import{createBudget as kt}from"../lib/thinking.mjs";import*as nt from"../lib/fanout.mjs";const jt={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"};async function _t(c,r={}){const{transport:y,textOnly:f,jsonInstruction:k}=G.state,{request:j,response:_,stream:m,error:g}=Z,d=g.build,{config:o,state:T}=G,h=ft(Z,G,r.front),O=c&&typeof c=="object"&&!Array.isArray(c),U={model:null,requested:O&&typeof c.model=="string"?c.model:null,upstream:null,front:r.front??o.front,stream:O&&c.stream===!0},w=mt(U,r.onUsage,(l,A)=>et(o,T,l,{type:"usage",...A,log:r.log})),q=u(l=>Object.defineProperty(l,"usage",{value:w.usage,enumerable:!1,configurable:!0}),"attach");let J=!1;try{const l=nt.wants(h,c);if(l>0){J=!0;const A=u((s,$)=>et(o,T,s,{type:"usage",...$,log:r.log}),"warning");return await nt.run({body:c,count:l,options:r,send:_t,warn:A})}return q(await Tt({transport:y,textOnly:f,jsonInstruction:k,request:j,response:_,stream:m,error:g,captured:h},c,r,w))}catch(l){if(J)throw l;if(!(l instanceof z))throw r.signal?.aborted||at(h,{type:"error",kind:"exception",level:"error",message:String(l?.message??l),log:r.log}),w.finish(r.signal?.aborted?"aborted":"error"),l;return w.finish("error"),q(d(l.status,l.message,{type:l.type,code:l.code,param:l.param,front:r.front}))}}u(_t,"send");async function Tt({transport:c,textOnly:r,jsonInstruction:y,request:f,response:k,stream:j,error:_,captured:m},g,d,o){const T={front:d.front,headers:d.headers,clientHeaders:d.clientHeaders,filter:d.filter,usage:!0,budget:kt(),log:d.log},h=u(e=>{at(m,{...e,log:d.log})},"announce"),O=o.meta.front==="openai"&&g?.stream_options?.include_usage!==!0,U=u(e=>{o.meta.model=e.body.model??null,o.meta.upstream=e.upstream,e.state.native?o.source(null):o.source(()=>e.state.convert?.upstreamUsage,e.state.front==="anthropic"?"openai":"folded")},"note"),w=u(e=>{if(e.state.native)return{input:!1,output:!1};const t=dt(e.state.front==="anthropic"?"openai":"folded",e.state.convert?.upstreamUsage);return t===null?{input:!0,output:!0}:{input:t.input_tokens===null&&t.cache_read_input_tokens===null&&t.cache_creation_input_tokens===null,output:t.output_tokens===null}},"gaps"),q=u(async e=>{const t=m.endpoint(e.upstream),a=m.driver(t);return(a.count&&!(O&&e.state.stream)?await a.count({endpoint:t,request:e.body,transport:c,signal:d.signal,timeout:m.config.detectTimeout}):null)??pt(e.body)},"input"),J=u(async(e,t)=>{const a=w(e);return!a.input&&!a.output?null:{input_tokens:a.input?await q(e):null,output_tokens:a.output?ht(t):null}},"counts"),l=u((e,t,a,n,M)=>(o.finish(M),_(e,t,a,n)),"fail"),A=u(async e=>{let t=e,a=await st(c,t,d.signal,K());const n=a.status,M=n===400&&[t.images,t.tools].some(x=>x.sent&&x.retry),R=(n===400||n===422)&&t.json.sent&&t.json.retry;if(!a.ok&&(M||R)){const x=await B(a),S=ct(x,n).message,p={};if(n===400&&t.images.sent&&t.images.retry&&ut.refused(S)?(r.add(t.images.key),p.images=!1):n===400&&t.tools.sent&&t.tools.retry&<.refused(S)?p.tools=!1:R&&(p.jsonObject="instruction"),!("images"in p||"tools"in p||"jsonObject"in p))return{upstream:t,result:a,failure:x};const b={upstream:t,result:a,failure:x};if("images"in p||"tools"in p){const F="images"in p?"images":"tools";h({type:"fallback",kind:F,level:"warn",message:`Upstream ${t.upstream}: ${t.state.model} refused ${F==="images"?"images":"tools"} (${n}: "${String(S).trim().slice(0,500)}"); sent the request again without them.`,endpoint:t.upstream,model:t.body.model,status:n,reason:String(S).trim().slice(0,500),action:F==="images"?"text-only":"without-tools"})}if(t=await f(g,{...T,...p,endpoint:t.upstream,retry:!0}),U(t),a=await st(c,t,d.signal,K()),R&&"jsonObject"in p){if(!a.ok){try{await a.body?.cancel?.()}catch{}return U(b.upstream),b}y.add(b.upstream.json.key),h({type:"fallback",kind:"json_object",level:"warn",message:`Upstream ${b.upstream.upstream}: ${b.upstream.state.model} rejected the json_object schema emulation (${n}: "${String(S).trim().slice(0,500)}"); sent it as a system instruction instead. Set jsonObject: "instruction" on this upstream to skip the first attempt.`,endpoint:b.upstream.upstream,model:b.upstream.body.model,status:n,reason:String(S).trim().slice(0,500),action:"instruction"})}}return{upstream:t,result:a}},"attempt");let s=await f(g,{...T,hold:!0});const $=s.pool;let D=0;const I=$.length>1?m.config.pool:null,K=u(()=>I&&{connectTimeout:I.connectTimeout,headersTimeout:D+1<$.length?I.headersTimeout:0},"limitsNow");let E=m.endpoint(s.upstream);const Q=u(()=>E.health.inflight--,"release");let i,v,V=null,W=0;const X=u(e=>{const t=bt(m,{body:g,sent:s,front:o.meta.front,requested:o.meta.requested,headers:e,log:d.log,exchange:V,attempt:W});return V??=t.id,t},"begin"),Y=u(async e=>{const t=X();if(!t.on)return;if(i===void 0)return t.attempt({error:v.message},e);let a=null;try{a=v??await B(i)}catch{}t.attempt({status:i.status,headers:tt.plain(i.headers),body:a},e)},"keep");try{for(;;){const e=E;e.health.requests++,W++,U(s);let t=null;try{({upstream:s,result:i,failure:v}=await A(s)),!i.ok&&i.status>=500&&(t=`HTTP ${i.status}`,h({type:"error",kind:"upstream",level:"error",message:`Upstream ${e.name} answered HTTP ${i.status}`,endpoint:e.name,model:s.body.model,status:i.status}))}catch(n){if(!(n instanceof z)||n.code!=="upstream_unreachable")throw n;t=n.message,i=void 0,v=n,h({type:"error",kind:"transport",level:"error",message:n.message,endpoint:e.name,model:s.body.model})}if(t===null){rt.succeeded(e);break}rt.failed(m.config,e,t);let a=null;for(;a===null&&!d.signal?.aborted&&D+1<$.length;)try{a=await f(g,{...T,endpoint:$[++D],hold:!0})}catch(n){if(!(n instanceof z)||n.code!=="endpoint_not_in_pool")throw n}if(a===null){if(i===void 0)throw await Y(),v;break}await Y(t),h({type:"failover",level:"warn",message:`Upstream ${e.name} failed (${t}); trying ${a.upstream}`,from:e.name,to:a.upstream,model:a.body.model,reason:t});try{await i?.body?.cancel?.()}catch{}Q(),E=m.endpoint(a.upstream),s=a}}catch(e){throw Q(),e}const ot=E;E=null,o.usage.then(()=>ot.health.inflight--);const H=tt.plain(i.headers),P=X(H);if(!i.ok){const e=v??await B(i);return P.reply(i.status,H,e),l(i.status,e,H,s.state,"upstream_error")}if(s.state.stream){const e=j(P.raw(i.body),s.state),t=s.state.native?e:wt(o.meta.front,e,{gaps:u(()=>w(s),"gaps"),input:u(()=>q(s),"input"),report:u(a=>o.estimate(a),"report")});return{status:200,headers:jt,stream:P.events(o.track(t,d.signal,O))}}const C=await B(i);if(P.reply(i.status,H,C),C===null||typeof C!="object")return h({type:"error",kind:"upstream",level:"error",message:`Upstream ${s.upstream} returned a body that is not JSON`,endpoint:s.upstream,model:s.body.model,status:502}),l(502,"The upstream returned a body that is not JSON",H,s.state,"error");const N=await k(C,s.state),L=await J(s,gt(o.meta.front,N));return L&&(N.usage=yt(o.meta.front,N.usage,L),o.estimate(L)),o.json(N),o.finish("done"),{status:200,headers:{"content-type":"application/json"},body:N}}u(Tt,"round");async function st(c,r,y,f=null){let k,j=!1,_=y;if(f&&f.headersTimeout>0){const m=new AbortController;_=y?AbortSignal.any([y,m.signal]):m.signal,k=setTimeout(()=>{j=!0,m.abort()},f.headersTimeout)}try{return await c(r.url,{method:r.method,headers:r.headers,body:JSON.stringify(r.body),signal:_,redirect:"error",...f&&f.connectTimeout>0?{connectTimeout:f.connectTimeout}:{}})}catch(m){if(y?.aborted)throw m;const g=j?`no response headers within ${f.headersTimeout} ms`:m.message;throw new z(`Could not reach the upstream (${r.upstream}): ${g}`,{code:"upstream_unreachable",status:502,details:{cause:m}})}finally{clearTimeout(k)}}u(st,"call");async function B(c){const r=await c.text();try{return JSON.parse(r)}catch{return r===""?null:r}}u(B,"parse");export{_t as send};
|
|
2
2
|
//# sourceMappingURL=send.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var i=(o,e)=>c(o,"name",{value:e,configurable:!0});const d={chat:"chat/completions",embeddings:"embeddings",models:"models"};function $(o,e,r){const n=e.url.endsWith("/openai")?"":"/openai",t=d[o];if(e.apiVersion===void 0)return`${n}/v1/${t}`;const s=`?api-version=${encodeURIComponent(e.apiVersion)}`;return o==="models"?`${n}/${t}${s}`:`${n}/deployments/${encodeURIComponent(e.deployment??r??"")}/${t}${s}`}i($,"route");export{$ as route};
|
|
2
|
+
//# sourceMappingURL=azure.mjs.map
|
package/dist/lib/backends.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var n=Object.defineProperty;var o=(t,e)=>n(t,"name",{value:e,configurable:!0});const i=["default_generation_settings","total_slots","build_info"];function p(t){return t.ok&&t.body!==null&&typeof t.body=="object"?t.body:{}}o(p,"objectOf");function a(t){return i.some(e=>e in t)}o(a,"isLlamacppProps");function f(t){return typeof t.model_path=="string"||typeof t.tokenizer_path=="string"}o(f,"isSglangInfo");const r=["llm","vlm","embeddings"];function l(t){return t.object!=="list"||!Array.isArray(t.data)||t.data.length===0?!1:t.data.every(e=>e?.object==="model"&&typeof e.id=="string"&&typeof e.arch=="string"&&typeof e.compatibility_type=="string"&&typeof e.state=="string"&&r.includes(e.type))}o(l,"isLmstudioModels");function c(t){return t.router==="text-generation-router"&&typeof t.model_id=="string"&&typeof t.version=="string"&&typeof t.max_total_tokens=="number"}o(c,"isTgiInfo");function u(t){return typeof t.version=="string"&&/^\S* \([0-9a-f]*\)$/i.test(t.version)}o(u,"isLocalaiVersion");function g(t){return typeof t.version=="string"&&t.endpoints!==null&&typeof t.endpoints=="object"&&t.endpoints.models==="/v1/models"&&t.endpoints.chat_completions==="/v1/chat/completions"}o(g,"isLocalaiDiscovery");export{a as isLlamacppProps,l as isLmstudioModels,g as isLocalaiDiscovery,u as isLocalaiVersion,f as isSglangInfo,c as isTgiInfo,p as objectOf};
|
|
2
2
|
//# sourceMappingURL=backends.mjs.map
|
package/dist/lib/capture.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=Object.defineProperty;var n=(o,r)=>m(o,"name",{value:r,configurable:!0});import{resolve as v}from"./settings.mjs";function g(o){const r=[];for(const s of Object.keys(o??{})){const e=o[s];typeof e?.info=="function"&&r.push({name:s,info:e.info(),detect:e.detect,settings:e.settings,probe:e.probe,request:e.request,response:e.response,chunk:e.chunk,flush:e.flush,error:e.error,count:e.token?.count,list:e.model?.list})}return r.sort((s,e)=>s.info.order-e.info.order)}n(g,"collect");function b(o,r,s){const{config:e,state:u}=r,c=o.convert.anthropic.messages.to.openai.chat,i=o.convert.openai.chat.to.anthropic.messages,a=s??e.front,f=g(o.driver),h=a==="anthropic"?"anthropic.messages":"openai.chat",d=a==="anthropic"?{request:c.request,response:i.response,stream:i.stream}:{request:i.request,response:c.response,stream:c.stream};return{config:e,state:u,front:a,drivers:f,endpoint:n(t=>u.endpoints.find(p=>p.name===t),"endpoint"),driver:n(t=>f.find(p=>p.name===t.driver),"driver"),settings:n(t=>v(t.driverSettings,t.probed,e.settings,t.settings),"settings"),converters:n(t=>t.protocol===h?null:d,"converters")}}n(b,"capture");export{b as capture,g as collect};
|
|
1
|
+
var m=Object.defineProperty;var n=(o,r)=>m(o,"name",{value:r,configurable:!0});import{resolve as v}from"./settings.mjs";function g(o){const r=[];for(const s of Object.keys(o??{})){const e=o[s];typeof e?.info=="function"&&r.push({name:s,info:e.info(),detect:e.detect,settings:e.settings,probe:e.probe,path:e.path,request:e.request,response:e.response,chunk:e.chunk,flush:e.flush,error:e.error,count:e.token?.count,list:e.model?.list})}return r.sort((s,e)=>s.info.order-e.info.order)}n(g,"collect");function b(o,r,s){const{config:e,state:u}=r,c=o.convert.anthropic.messages.to.openai.chat,i=o.convert.openai.chat.to.anthropic.messages,a=s??e.front,f=g(o.driver),h=a==="anthropic"?"anthropic.messages":"openai.chat",d=a==="anthropic"?{request:c.request,response:i.response,stream:i.stream}:{request:i.request,response:c.response,stream:c.stream};return{config:e,state:u,front:a,drivers:f,endpoint:n(t=>u.endpoints.find(p=>p.name===t),"endpoint"),driver:n(t=>f.find(p=>p.name===t.driver),"driver"),settings:n(t=>v(t.driverSettings,t.probed,e.settings,t.settings),"settings"),converters:n(t=>t.protocol===h?null:d,"converters")}}n(b,"capture");export{b as capture,g as collect};
|
|
2
2
|
//# sourceMappingURL=capture.mjs.map
|
package/dist/lib/config.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var i=Object.defineProperty;var
|
|
1
|
+
var i=Object.defineProperty;var n=(t,r)=>i(t,"name",{value:r,configurable:!0});import{TranslatorError as o}from"./errors.mjs";import*as a from"./pool.mjs";import{valid as u}from"./record.mjs";import{normalizeAliases as l,normalizeEfforts as p}from"./effort.mjs";function d(t){let r=t.length;for(;t[r-1]==="/";)r--;const e=t.slice(0,r);return e.endsWith("/v1")?e.slice(0,-3):e}n(d,"baseUrl");function m(t,r){const e=typeof t=="string"?{url:t}:t;if(!e||typeof e!="object"||typeof e.url!="string"||e.url==="")throw new o(`upstreams[${r}] needs a "url"`,{code:"INVALID_CONFIG",status:500});for(const s of["apiVersion","deployment"])if(e[s]!==void 0&&(typeof e[s]!="string"||e[s]===""))throw new o(`upstreams[${r}].${s} must be a non-empty string`,{code:"INVALID_CONFIG",status:500});return{name:e.name??`upstream-${r}`,url:d(e.url),apiKey:e.apiKey,headers:{...e.headers},apiVersion:e.apiVersion,deployment:e.deployment,backend:e.backend??"auto",models:Array.isArray(e.models)?[...e.models]:void 0,default:e.default===!0,settings:{...e.settings},version:e.version,driver:null,facts:null,driverSettings:{},probed:{},health:a.health()}}n(m,"endpoint");function y(t={}){const r=t.front??"anthropic";if(r!=="anthropic"&&r!=="openai")throw new o(`front must be "anthropic" or "openai" (got ${JSON.stringify(r)})`,{code:"INVALID_CONFIG",status:500});let e=t.upstreams??t.upstream;if(e!==void 0&&!Array.isArray(e)&&(e=[e]),!e||e.length===0)throw new o("at least one upstream is required (config.upstreams)",{code:"INVALID_CONFIG",status:500});const s=t.logs??!1;if(typeof s!="boolean"&&(typeof s!="string"||s===""))throw new o("logs must be true, false or a file path (got "+JSON.stringify(s)+")",{code:"INVALID_CONFIG",status:500});if(t.onEvent!==void 0&&typeof t.onEvent!="function")throw new o("onEvent must be a function",{code:"INVALID_CONFIG",status:500});if(!u(t.capture))throw new o("capture must be false, a directory path or a function (got "+JSON.stringify(t.capture)+")",{code:"INVALID_CONFIG",status:500});return{front:r,endpoints:e.map(m),...l(t.aliases),efforts:p(t.efforts),pool:a.normalize(t.pool),settings:{...t.settings},detect:t.detect!==!1,detectTimeout:t.detectTimeout??5e3,transport:t.transport,logs:s,capture:t.capture||!1,events:t.events!==!1,onEvent:t.onEvent}}n(y,"normalize");export{m as endpoint,y as normalize};
|
|
2
2
|
//# sourceMappingURL=config.mjs.map
|