@cldmv/llm-translator 0.8.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 +6 -6
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +8 -8
- 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/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/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/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/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/package.json +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/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/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/lib/azure.d.mts +17 -0
- package/types/src/lib/backends.d.mts +22 -0
- package/types/src/lib/config.d.mts +8 -0
- 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/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))
|
|
28
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))
|
|
29
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))
|
|
30
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))
|
|
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
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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
package/dist/lib/http.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=Object.defineProperty;var o=(t,e)=>l(t,"name",{value:e,configurable:!0});function y(t,e){return t+e}o(y,"join");async function k(t,e,a,n){return t.path?t.path(e,{endpoint:a,model:n}):t.info.paths[e]??p[e]}o(k,"pathOf");const p={embeddings:"/v1/embeddings",models:"/v1/models"};function m(t){return t==="localhost"||t==="::1"||/^127\./.test(t)}o(m,"isLoopback");function d(t,e="bearer",a){const n={...t.headers};return t.apiKey&&(e==="x-api-key"||e==="api-key"?n[e]=t.apiKey:n.authorization=`Bearer ${t.apiKey}`),{...n,...a}}o(d,"headers");function S({endpoint:t,transport:e,signal:a,timeout:n,probes:i},c,s){const u=s!==void 0&&(s.auth==="x-api-key"||s.auth==="api-key"||s.headers!==void 0),r=u?{auth:s.auth,extra:s.headers}:{},h=o(()=>g(e,y(t.url,c),{method:"GET",headers:d(t,r.auth,r.extra),signal:a,timeout:n}),"run");if(!i)return h();const f=u?JSON.stringify([c,r.auth,r.extra]):c;return i.has(f)||i.set(f,h()),i.get(f)}o(S,"probe");function x(t){const e={};if(!t)return e;if(typeof t.forEach=="function")return t.forEach((a,n)=>{e[n.toLowerCase()]=a}),e;for(const[a,n]of Object.entries(t))e[a.toLowerCase()]=String(n);return e}o(x,"plain");async function g(t,e,a={}){const{timeout:n,signal:i,body:c,...s}=a,u=[];i&&u.push(i),n>0&&u.push(AbortSignal.timeout(n));try{const r=await t(e,{...s,redirect:"error",body:c===void 0?void 0:JSON.stringify(c),signal:u.length>1?AbortSignal.any(u):u[0]}),h=await r.text();let f=null;try{f=JSON.parse(h)}catch{f=h===""?null:h}return{ok:r.ok,status:r.status,body:f,headers:x(r.headers)}}catch(r){return{ok:!1,status:0,body:null,error:r}}}o(g,"json");export{d as headers,m as isLoopback,y as join,g as json,k as pathOf,x as plain,S as probe};
|
|
2
2
|
//# sourceMappingURL=http.mjs.map
|
package/dist/lib/models.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=Object.defineProperty;var t=(r,o)=>l(r,"name",{value:o,configurable:!0});import*as e from"./http.mjs";function u(r){return!r.ok||!Array.isArray(r.body?.data)?null:r.body.data.filter(o=>o&&typeof o.id=="string")}t(u,"modelsOf");async function h({endpoint:r,transport:o,signal:a,timeout:d,auth:n,extraHeaders:s,path:i="/v1/models"}){const f=await e.json(o,e.join(r.url,i),{method:"GET",headers:e.headers(r,n,s),signal:a,timeout:d});return u(f)}t(h,"fetchModels");export{h as fetchModels,u as modelsOf};
|
|
2
2
|
//# sourceMappingURL=models.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var r=(e,t)=>a(e,"name",{value:t,configurable:!0});import{TranslatorError as c}from"./errors.mjs";function n(e){return e!==null&&typeof e=="object"&&typeof e.message=="string"}r(n,"isError");function u(e){return!e||typeof e!="object"?null:Array.isArray(e.choices)&&e.choices.length>0?e.choices.every(t=>n(t?.error))?e.choices[0].error:null:n(e.error)?e.error:null}r(u,"found");function f(e){const t=Number.isInteger(e.code)&&e.code>=400&&e.code<=599?e.code:502,o=typeof e.metadata?.error_type=="string"?e.metadata.error_type:"upstream_error",i=typeof e.metadata?.provider_name=="string"?` (provider ${e.metadata.provider_name})`:"";return new c(`${e.message}${i}`,{code:o,status:t})}r(f,"failure");export{f as failure,u as found};
|
|
2
|
+
//# sourceMappingURL=openrouter.mjs.map
|
package/dist/lib/tgi.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=Object.defineProperty;var u=(n,t)=>f(n,"name",{value:t,configurable:!0});const r=new Set(["eos_token","stop_sequence"]);function o(n,t){if(n===null||typeof n!="object")return n;const e={...n};return e.id===void 0||e.id===null?t!==void 0&&(e.id=String(t)):typeof e.id!="string"&&(e.id=String(e.id)),e.type===void 0&&(e.type="function"),e.function!==null&&typeof e.function=="object"&&(e.function=s(e.function)),e}u(o,"toolCall");function s(n){const{parameters:t,...e}=n,i=e.arguments??t;return i===void 0?e:{...e,arguments:typeof i=="string"?i:JSON.stringify(i)}}u(s,"functionOf");function c(n,t=!1){if(n!=null)return(Array.isArray(n)?n:[n]).map((e,i)=>o(e,t?i:void 0))}u(c,"toolCalls");function p(n,t){return typeof n!="string"?n:r.has(n)||n==="stop"?t?"tool_calls":"stop":n}u(p,"finish");function y(n){if(n===null||typeof n!="object")return n;if(n.type==="json_schema"&&n.value===void 0&&n.json_schema?.schema!==void 0){const{name:t,schema:e}=n.json_schema;return{type:"json_schema",value:t===void 0?{schema:e}:{name:t,schema:e}}}return n.type==="json_object"&&n.value===void 0?{type:"json",value:{type:"object"}}:n}u(y,"grammar");export{p as finish,y as grammar,o as toolCall,c as toolCalls};
|
|
2
|
+
//# sourceMappingURL=tgi.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/llm-translator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Bidirectional Anthropic Messages ⇄ OpenAI Chat Completions translator with backend auto-detection (vLLM and other OpenAI-compatible servers), built on slothlet, with an optional standalone server for running Claude Code against local models.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Match by host name, no network access.
|
|
3
|
+
* @param {any} context - `{ endpoint }`.
|
|
4
|
+
* @returns {{host: string} | null} Facts, or null when the host is not an Azure OpenAI resource.
|
|
5
|
+
*/
|
|
6
|
+
export function detect({ endpoint }: any): {
|
|
7
|
+
host: string;
|
|
8
|
+
} | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize to the nested OpenAI shape. A prompt refused by Azure's content filter (HTTP 400, `error.code: "content_filter"`) keeps its code and
|
|
3
|
+
* `param`, and its message names the categories that were filtered when `innererror.content_filter_result` says so.
|
|
4
|
+
* @param {number} status - HTTP status.
|
|
5
|
+
* @param {*} body - Parsed upstream error body.
|
|
6
|
+
* @returns {{error: {message: string, type: string | undefined, param: *, code: *}}} Nested error body.
|
|
7
|
+
*/
|
|
8
|
+
export function error(status: number, body: any): {
|
|
9
|
+
error: {
|
|
10
|
+
message: string;
|
|
11
|
+
type: string | undefined;
|
|
12
|
+
param: any;
|
|
13
|
+
code: any;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/azure/info.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Azure OpenAI driver: static facts about the hosted Azure OpenAI API.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/azure
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Describe the Azure OpenAI driver. The key goes in the `api-key` header. The real paths come from the `path` leaf, because they depend on the
|
|
21
|
+
* upstream's `apiVersion` and `deployment`; `paths` holds the v1 API paths for a base URL without `/openai`.
|
|
22
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
|
|
23
|
+
*/
|
|
24
|
+
export function info(): {
|
|
25
|
+
name: string;
|
|
26
|
+
protocol: string;
|
|
27
|
+
order: number;
|
|
28
|
+
auth: string;
|
|
29
|
+
strict: boolean;
|
|
30
|
+
paths: Record<string, string>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List the models the Azure OpenAI resource reports (`/openai/v1/models`, or `/openai/models?api-version=...` with the classic URLs). Azure lists
|
|
3
|
+
* base models there, not the resource's deployments, so an upstream that serves deployments should set `models`.
|
|
4
|
+
* @param {any} context - `{ endpoint, transport, signal, timeout }`.
|
|
5
|
+
* @returns {Promise<any[] | null>} Models, or null when unreachable or not a model list.
|
|
6
|
+
*/
|
|
7
|
+
export function list(context: any): Promise<any[] | null>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the path of a call from the upstream's `apiVersion` and `deployment` (see `lib/azure.mjs`).
|
|
3
|
+
* @param {"chat" | "embeddings" | "models"} kind - Which call.
|
|
4
|
+
* @param {any} context - `{ endpoint, model }`.
|
|
5
|
+
* @returns {string} Path with the `api-version` query when the classic URLs are in use.
|
|
6
|
+
*/
|
|
7
|
+
export function path(kind: "chat" | "embeddings" | "models", { endpoint, model }: any): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop tool fields Azure rejects when no tools are present, and send `max_tokens` when the upstream pins an `api-version` older than the one
|
|
3
|
+
* that introduced `max_completion_tokens`. Versions that are not dated (`preview`, `latest`) and the v1 API keep `max_completion_tokens`.
|
|
4
|
+
* @param {any} body - Chat Completions request body.
|
|
5
|
+
* @param {any} [context] - `{ endpoint }`.
|
|
6
|
+
* @returns {any} Normalized body.
|
|
7
|
+
*/
|
|
8
|
+
export function request(body: any, context?: any): any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/azure/settings.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Azure OpenAI driver: translator settings for Azure OpenAI.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/azure
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Settings for Azure OpenAI: the same as the OpenAI API (`max_completion_tokens`, `reasoning_effort`, no `top_k`, no prefill continuation).
|
|
21
|
+
* @returns {any} Partial settings.
|
|
22
|
+
*/
|
|
23
|
+
export function settings(): any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/localai/chunk.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview LocalAI driver: streaming chunk normalizer (Chat Completions chunk).
|
|
17
|
+
* @module @cldmv/llm-translator/driver/localai
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* When the client asked for one tool call at a time, drop the fragments of every call but the first (index 0), see `response`.
|
|
21
|
+
* @param {any} chunk - Parsed `chat.completion.chunk`.
|
|
22
|
+
* @param {any} [ctx] - `{ state }`.
|
|
23
|
+
* @returns {any} Normalized chunk.
|
|
24
|
+
*/
|
|
25
|
+
export function chunk(chunk: any, ctx?: any): any;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Probe an endpoint for LocalAI.
|
|
3
|
+
* @param {any} context - `{ endpoint, transport, signal, timeout, probes }`.
|
|
4
|
+
* @returns {Promise<any | null>} Facts `{ version, models }`, or null when the endpoint is not LocalAI.
|
|
5
|
+
*/
|
|
6
|
+
export function detect(context: any): Promise<any | null>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/localai/info.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview LocalAI driver: static facts about the LocalAI server.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/localai
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Describe the LocalAI driver. It is found through `GET /version` (`{ version: "v3.1.0 (<commit>)" }`) or LocalAI's discovery document at
|
|
21
|
+
* `GET /.well-known/localai.json`. The extra fields are the ones LocalAI's request schema accepts beyond the OpenAI set.
|
|
22
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
23
|
+
*/
|
|
24
|
+
export function info(): {
|
|
25
|
+
name: string;
|
|
26
|
+
protocol: string;
|
|
27
|
+
order: number;
|
|
28
|
+
auth: string;
|
|
29
|
+
strict: boolean;
|
|
30
|
+
probes: string[];
|
|
31
|
+
fields: string[];
|
|
32
|
+
paths: Record<string, string>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop tool fields when there are no tools; rename vLLM's `repetition_penalty` to LocalAI's `repeat_penalty`; and take over
|
|
3
|
+
* `parallel_tool_calls: false`. LocalAI does not read that field: whether a model may call several tools in one turn is its YAML
|
|
4
|
+
* `function.parallel_calls`. When the client asked for one call at a time (the Anthropic front's `disable_parallel_tool_use`), the field
|
|
5
|
+
* is removed and `state.localaiSingleCall` makes the response normalizers keep only the first call.
|
|
6
|
+
* @param {any} body - Chat Completions request body.
|
|
7
|
+
* @param {any} [ctx] - `{ state }`.
|
|
8
|
+
* @returns {any} Normalized body.
|
|
9
|
+
*/
|
|
10
|
+
export function request(body: any, ctx?: any): any;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/localai/response.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview LocalAI driver: response normalizer (Chat Completions body).
|
|
17
|
+
* @module @cldmv/llm-translator/driver/localai
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* When the client asked for one tool call at a time, keep only the first call of each choice: LocalAI decides by model configuration
|
|
21
|
+
* (`function.parallel_calls`) and ignores the request, so a model configured for parallel calls can still return several.
|
|
22
|
+
* @param {any} body - Chat Completions response body.
|
|
23
|
+
* @param {any} [ctx] - `{ state }`.
|
|
24
|
+
* @returns {any} Normalized body.
|
|
25
|
+
*/
|
|
26
|
+
export function response(body: any, ctx?: any): any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/localai/settings.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview LocalAI driver: translator settings for LocalAI servers.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/localai
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Settings for LocalAI: reasoning is sent as `reasoning` (LocalAI's own field; it reads `reasoning_content` too, and so does the
|
|
21
|
+
* translator), `max_tokens` as the output cap, `top_k` and `chat_template_kwargs` are accepted, no prefill continuation, and usage on
|
|
22
|
+
* the last content chunk when `stream_options.include_usage` is set.
|
|
23
|
+
* @returns {any} Partial settings.
|
|
24
|
+
*/
|
|
25
|
+
export function settings(): any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/openrouter/chunk.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview OpenRouter driver: streaming chunk normalizer (Chat Completions chunk).
|
|
17
|
+
* @module @cldmv/llm-translator/driver/openrouter
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Give an error that sits on a choice the top-level `error` the stream converter and OpenRouter's own mid-stream errors use, so the Anthropic
|
|
21
|
+
* front ends the stream with an `error` event carrying the provider's message. A chunk that already has an `error` or no choice error passes unchanged.
|
|
22
|
+
* @param {any} chunk - Parsed `chat.completion.chunk`.
|
|
23
|
+
* @returns {any} Normalized chunk.
|
|
24
|
+
*/
|
|
25
|
+
export function chunk(chunk: any): any;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/openrouter/detect.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview OpenRouter driver: matches the openrouter.ai host.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/openrouter
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Match by host name, no network access.
|
|
21
|
+
* @param {any} context - `{ endpoint }`.
|
|
22
|
+
* @returns {{host: string} | null} Facts, or null when the endpoint is not openrouter.ai.
|
|
23
|
+
*/
|
|
24
|
+
export function detect({ endpoint }: any): {
|
|
25
|
+
host: string;
|
|
26
|
+
} | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/openrouter/info.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview OpenRouter driver: static facts about the hosted OpenRouter API.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/openrouter
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Describe the OpenRouter driver. The API lives under `/api`; the `path` leaf adds it, so `paths` holds the usual `/v1/...` ones.
|
|
21
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
|
|
22
|
+
*/
|
|
23
|
+
export function info(): {
|
|
24
|
+
name: string;
|
|
25
|
+
protocol: string;
|
|
26
|
+
order: number;
|
|
27
|
+
auth: string;
|
|
28
|
+
strict: boolean;
|
|
29
|
+
paths: Record<string, string>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Put the calls under `/api`, so the upstream can be given as `https://openrouter.ai` or `https://openrouter.ai/api` (a trailing `/v1` is removed
|
|
3
|
+
* by the config).
|
|
4
|
+
* @param {"chat" | "embeddings" | "models"} kind - Which call.
|
|
5
|
+
* @param {any} context - `{ endpoint }`.
|
|
6
|
+
* @returns {string} Path starting with `/`.
|
|
7
|
+
*/
|
|
8
|
+
export function path(kind: "chat" | "embeddings" | "models", { endpoint }: any): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop empty tool fields and express the reasoning controls the way OpenRouter takes them: a `reasoning` object with either `effort` or
|
|
3
|
+
* `max_tokens`, never both. A `reasoning` object the client sent itself is kept as it is (its `reasoning_effort` sibling is removed). Otherwise
|
|
4
|
+
* `reasoning_effort` becomes `reasoning: { effort }`, and an Anthropic request that enabled thinking with a `budget_tokens` and no effort
|
|
5
|
+
* becomes `reasoning: { max_tokens }`, capped below the request's `max_tokens`.
|
|
6
|
+
* @param {any} body - Chat Completions request body.
|
|
7
|
+
* @param {any} [context] - `{ state }`; `state.thinkingBudget` is the thinking budget of an Anthropic request.
|
|
8
|
+
* @returns {any} Normalized body.
|
|
9
|
+
*/
|
|
10
|
+
export function request(body: any, context?: any): any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn an error OpenRouter sent with HTTP 200 into an upstream error: `choices[i].error` on every choice, or a top-level `error` and no choices.
|
|
3
|
+
* Any partial text of the failed choice is dropped. A reply with a choice that did not fail passes unchanged.
|
|
4
|
+
* @param {any} body - Parsed `chat.completion`.
|
|
5
|
+
* @returns {any} The body.
|
|
6
|
+
* @throws {import("../../../lib/errors.mjs").TranslatorError} With the error's `message` and its `code` as the HTTP status.
|
|
7
|
+
*/
|
|
8
|
+
export function response(body: any): any;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/openrouter/settings.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview OpenRouter driver: translator settings for the hosted OpenRouter API.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/openrouter
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Settings for openrouter.ai: reasoning comes back in `reasoning` and `reasoning_details`, and `reasoning_details` is sent back unmodified and in
|
|
21
|
+
* order (`reasoningRoundTrip`). Thinking and effort are sent as `reasoning_effort`, which the `request` normalizer turns into OpenRouter's
|
|
22
|
+
* `reasoning` object. `max_tokens` is the output cap, `top_k` is accepted (OpenRouter drops what a model does not support), a trailing assistant
|
|
23
|
+
* message is OpenRouter's own prefill, and usage comes in a final chunk.
|
|
24
|
+
* @returns {any} Partial settings.
|
|
25
|
+
*/
|
|
26
|
+
export function settings(): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Put a streamed TGI chunk into the OpenAI shape: `delta.tool_calls` as one object becomes a list, numeric ids become strings, object
|
|
3
|
+
* `arguments` become a JSON string, an empty id (TGI repeats the field on every fragment) is removed so the fragment continues the open
|
|
4
|
+
* call, and `eos_token` / `stop_sequence` finish reasons become `stop` (or `tool_calls` once the stream carried calls).
|
|
5
|
+
* @param {any} chunk - Parsed `chat.completion.chunk`.
|
|
6
|
+
* @param {any} [ctx] - `{ state }`; remembers whether the stream carried tool calls.
|
|
7
|
+
* @returns {any} Normalized chunk.
|
|
8
|
+
*/
|
|
9
|
+
export function chunk(chunk: any, ctx?: any): any;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Probe an endpoint for Text Generation Inference.
|
|
3
|
+
* @param {any} context - `{ endpoint, transport, signal, timeout, probes }`.
|
|
4
|
+
* @returns {Promise<any | null>} Facts `{ version, model, maxInputTokens, maxTotalTokens }`, or null when the endpoint is not TGI.
|
|
5
|
+
*/
|
|
6
|
+
export function detect(context: any): Promise<any | null>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/tgi/info.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Hugging Face TGI driver: static facts about Text Generation Inference.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/tgi
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Describe the TGI driver. It is found through `GET /info`, TGI's router description. `grammar` is allowed through the OpenAI front's
|
|
21
|
+
* request filter because the request normalizer folds it into `response_format`, the only place the chat endpoint reads a grammar.
|
|
22
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
23
|
+
*/
|
|
24
|
+
export function info(): {
|
|
25
|
+
name: string;
|
|
26
|
+
protocol: string;
|
|
27
|
+
order: number;
|
|
28
|
+
auth: string;
|
|
29
|
+
strict: boolean;
|
|
30
|
+
probes: string[];
|
|
31
|
+
fields: string[];
|
|
32
|
+
paths: Record<string, string>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop tool fields when there are no tools; fold a client's `grammar` into `response_format` (the chat endpoint reads a grammar only
|
|
3
|
+
* there) and rewrite `response_format` into TGI's shape; and drop `response_format` when the request also has tools, which TGI refuses
|
|
4
|
+
* (the tools win, and the drop is recorded in `state.dropped`).
|
|
5
|
+
* @param {any} body - Chat Completions request body.
|
|
6
|
+
* @param {any} [ctx] - `{ state }`.
|
|
7
|
+
* @returns {any} Normalized body.
|
|
8
|
+
*/
|
|
9
|
+
export function request(body: any, ctx?: any): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Put TGI's historic deviations into the OpenAI shape: `tool_calls` as one object becomes a list, numeric tool-call ids become strings,
|
|
3
|
+
* object `arguments` (or `parameters`) become a JSON string, `eos_token` and `stop_sequence` finish reasons become `stop` (or `tool_calls`
|
|
4
|
+
* when the answer holds calls), and the `text_completion` object name becomes `chat.completion`. Current TGI already answers in the
|
|
5
|
+
* standard shape, which passes through unchanged.
|
|
6
|
+
* @param {any} body - Chat Completions response body.
|
|
7
|
+
* @returns {any} Normalized body.
|
|
8
|
+
*/
|
|
9
|
+
export function response(body: any): any;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/tgi/settings.mjs
|
|
5
|
+
* @Date: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Hugging Face TGI driver: translator settings for TGI servers.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/tgi
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Settings for TGI: `max_tokens` as the output cap, no `top_k` (the chat request has none), no prefill continuation, no thinking switch,
|
|
21
|
+
* and `response_format` for structured output (the request normalizer rewrites it into TGI's grammar shape). Usage comes on the last
|
|
22
|
+
* content chunk when `stream_options.include_usage` is set.
|
|
23
|
+
* @returns {any} Partial settings.
|
|
24
|
+
*/
|
|
25
|
+
export function settings(): any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Probe an endpoint for vLLM.
|
|
3
3
|
* @param {any} context - `{ endpoint, transport, signal, timeout, probes }`.
|
|
4
|
-
* @returns {Promise<any | null>} Facts `{ version, models, maxModelLen }`, or null when the endpoint is not vLLM (or is SGLang
|
|
4
|
+
* @returns {Promise<any | null>} Facts `{ version, models, maxModelLen }`, or null when the endpoint is not vLLM (or is LocalAI, SGLang, llama.cpp or TGI, which can also answer `/version`).
|
|
5
5
|
*/
|
|
6
6
|
export function detect({ endpoint, transport, signal, timeout, probes }: any): Promise<any | null>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the path (and query) of an Azure OpenAI call.
|
|
3
|
+
*
|
|
4
|
+
* The v1 API (`<endpoint>/openai/v1/...`, the model named in the body, no `api-version`) is used unless the upstream sets `apiVersion`.
|
|
5
|
+
* With `apiVersion` the classic form is used: `<endpoint>/openai/deployments/<deployment>/chat/completions?api-version=<version>`, where the
|
|
6
|
+
* deployment is the upstream's `deployment` or else the request's model. The model list has no deployment in its path (`/openai/models`).
|
|
7
|
+
* An upstream URL that already ends in `/openai` (a pasted `.../openai/v1` base has its `/v1` removed by the config) is not given a second `/openai`.
|
|
8
|
+
* @param {"chat" | "embeddings" | "models"} kind - Which call.
|
|
9
|
+
* @param {{url: string, apiVersion?: string, deployment?: string}} endpoint - Runtime endpoint.
|
|
10
|
+
* @param {string} [model] - The request's model, the deployment name unless the endpoint sets one.
|
|
11
|
+
* @returns {string} Path starting with `/`, with the `api-version` query for the classic form.
|
|
12
|
+
*/
|
|
13
|
+
export function route(kind: "chat" | "embeddings" | "models", endpoint: {
|
|
14
|
+
url: string;
|
|
15
|
+
apiVersion?: string;
|
|
16
|
+
deployment?: string;
|
|
17
|
+
}, model?: string): string;
|
|
@@ -26,3 +26,25 @@ export function isSglangInfo(body: Record<string, any>): boolean;
|
|
|
26
26
|
* @returns {boolean} True for LM Studio's model listing.
|
|
27
27
|
*/
|
|
28
28
|
export function isLmstudioModels(body: Record<string, any>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Does a `GET /info` reply come from Hugging Face Text Generation Inference? The match is strict so no other server binds: the router
|
|
31
|
+
* names itself `text-generation-router` (Text Embeddings Inference answers `/info` too, as `text-embeddings-router`), and the reply
|
|
32
|
+
* carries a string `model_id` and `version` and a numeric `max_total_tokens` (older releases lack `max_input_tokens`, so it is not required).
|
|
33
|
+
* @param {Record<string, any>} body - Reply object (see `objectOf`).
|
|
34
|
+
* @returns {boolean} True for TGI's `/info`.
|
|
35
|
+
*/
|
|
36
|
+
export function isTgiInfo(body: Record<string, any>): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Does a `GET /version` reply come from LocalAI? It answers `{ version: "<version> (<commit>)" }` (the version, a space, and the build
|
|
39
|
+
* commit in parentheses, which is empty for a source build), where vLLM and SGLang answer a bare version, so the shape names LocalAI.
|
|
40
|
+
* @param {Record<string, any>} body - Reply object (see `objectOf`).
|
|
41
|
+
* @returns {boolean} True for LocalAI's version reply.
|
|
42
|
+
*/
|
|
43
|
+
export function isLocalaiVersion(body: Record<string, any>): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Does a `GET /.well-known/localai.json` reply come from LocalAI? It is LocalAI's discovery document: a string `version` and an
|
|
46
|
+
* `endpoints` map that names the OpenAI routes (`models`, `chat_completions`) by path.
|
|
47
|
+
* @param {Record<string, any>} body - Reply object (see `objectOf`).
|
|
48
|
+
* @returns {boolean} True for LocalAI's discovery document.
|
|
49
|
+
*/
|
|
50
|
+
export function isLocalaiDiscovery(body: Record<string, any>): boolean;
|
|
@@ -28,6 +28,14 @@ export type UpstreamConfig = {
|
|
|
28
28
|
* Extra headers sent to the upstream.
|
|
29
29
|
*/
|
|
30
30
|
headers?: Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Azure OpenAI `api-version`. Set, it selects the classic per-deployment URLs; unset, the v1 API is used.
|
|
33
|
+
*/
|
|
34
|
+
apiVersion?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Azure OpenAI deployment name for the classic URLs. Defaults to the request's model.
|
|
37
|
+
*/
|
|
38
|
+
deployment?: string;
|
|
31
39
|
/**
|
|
32
40
|
* Driver name, or `"auto"` (default) to detect.
|
|
33
41
|
*/
|
package/types/src/lib/http.d.mts
CHANGED
|
@@ -23,6 +23,17 @@
|
|
|
23
23
|
* @returns {string} Absolute URL.
|
|
24
24
|
*/
|
|
25
25
|
export function join(base: string, path: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* The path (with any query) of a call on an upstream. A driver that has a `path(kind, { endpoint, model })` leaf builds it from the endpoint
|
|
28
|
+
* and the model (Azure OpenAI puts the deployment and `api-version` there); otherwise `info().paths[kind]` is used, with the standard
|
|
29
|
+
* OpenAI path for `embeddings` and `models` when the driver does not name one.
|
|
30
|
+
* @param {any} driver - Driver record (`info` and the optional `path` leaf).
|
|
31
|
+
* @param {"chat" | "messages" | "embeddings" | "models"} kind - Which call.
|
|
32
|
+
* @param {any} endpoint - Runtime endpoint.
|
|
33
|
+
* @param {string} [model] - The upstream's model name for the request.
|
|
34
|
+
* @returns {Promise<string>} Path starting with `/`.
|
|
35
|
+
*/
|
|
36
|
+
export function pathOf(driver: any, kind: "chat" | "messages" | "embeddings" | "models", endpoint: any, model?: string): Promise<string>;
|
|
26
37
|
/**
|
|
27
38
|
* Whether a listen address only accepts connections from this machine.
|
|
28
39
|
* @param {string} host - Host or address.
|
|
@@ -32,7 +43,7 @@ export function isLoopback(host: string): boolean;
|
|
|
32
43
|
/**
|
|
33
44
|
* Build the request headers for an upstream call.
|
|
34
45
|
* @param {any} endpoint - Runtime endpoint.
|
|
35
|
-
* @param {string} [auth] - `"bearer"` (default)
|
|
46
|
+
* @param {string} [auth] - `"bearer"` (default), `"x-api-key"` or `"api-key"` (Azure OpenAI).
|
|
36
47
|
* @param {Record<string,string>} [extra] - Extra headers applied last.
|
|
37
48
|
* @returns {Record<string,string>} Header map.
|
|
38
49
|
*/
|
|
@@ -42,7 +53,7 @@ export function headers(endpoint: any, auth?: string, extra?: Record<string, str
|
|
|
42
53
|
* once and every driver that asks for it gets the same result, so a path fetched for one backend (for example `/v1/models`) is
|
|
43
54
|
* not fetched again for the next. Never rejects; treat the result as read-only.
|
|
44
55
|
*
|
|
45
|
-
* Without `driver` the request carries the upstream's bearer key. A driver whose `info()` says `auth: "x-api-key"` or carries
|
|
56
|
+
* Without `driver` the request carries the upstream's bearer key. A driver whose `info()` says `auth: "x-api-key"` or `"api-key"`, or carries
|
|
46
57
|
* `headers` passes its `info()` so the probe is sent the way the driver talks to its own backend; that request is a different
|
|
47
58
|
* request from the bearer one, so it is cached under its own key.
|
|
48
59
|
* @param {any} context - `{ endpoint, transport, signal, timeout, probes? }`.
|
|
@@ -14,10 +14,10 @@ export function modelsOf(result: {
|
|
|
14
14
|
}[] | null;
|
|
15
15
|
/**
|
|
16
16
|
* Fetch and normalize the models an upstream reports.
|
|
17
|
-
* @param {any} context - `{ endpoint, transport, signal, timeout, auth, extraHeaders }`.
|
|
17
|
+
* @param {any} context - `{ endpoint, transport, signal, timeout, auth, extraHeaders, path }`. `path` replaces `/v1/models`.
|
|
18
18
|
* @returns {Promise<{id: string, created?: number, owned_by?: string, max_model_len?: number}[] | null>} Models, or null when the upstream did not answer with a model list.
|
|
19
19
|
*/
|
|
20
|
-
export function fetchModels({ endpoint, transport, signal, timeout, auth, extraHeaders }: any): Promise<{
|
|
20
|
+
export function fetchModels({ endpoint, transport, signal, timeout, auth, extraHeaders, path }: any): Promise<{
|
|
21
21
|
id: string;
|
|
22
22
|
created?: number;
|
|
23
23
|
owned_by?: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error a reply that answered HTTP 200 carries: `choices[i].error` on every choice (the provider failed while generating; the choice's
|
|
3
|
+
* `finish_reason` is `"error"` and any partial text is not used), or a top-level `error` with no choices.
|
|
4
|
+
* @param {any} body - Parsed reply body.
|
|
5
|
+
* @returns {{code: any, message: string, metadata?: any} | null} The error object, or null when the reply has none to report.
|
|
6
|
+
*/
|
|
7
|
+
export function found(body: any): {
|
|
8
|
+
code: any;
|
|
9
|
+
message: string;
|
|
10
|
+
metadata?: any;
|
|
11
|
+
} | null;
|
|
12
|
+
/**
|
|
13
|
+
* The `TranslatorError` for an OpenRouter error object. Its numeric `code` is the HTTP status when it is a client or server error, else 502; the
|
|
14
|
+
* `code` of the error is `metadata.error_type` when OpenRouter gives one, else `upstream_error`.
|
|
15
|
+
* @param {{code?: any, message: string, metadata?: any}} error - Error object.
|
|
16
|
+
* @returns {TranslatorError} Error to throw.
|
|
17
|
+
*/
|
|
18
|
+
export function failure(error: {
|
|
19
|
+
code?: any;
|
|
20
|
+
message: string;
|
|
21
|
+
metadata?: any;
|
|
22
|
+
}): TranslatorError;
|
|
23
|
+
import { TranslatorError } from "./errors.mjs";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One tool call in the OpenAI shape. Historic TGI sent the id as a number, the arguments as an object (under `parameters` in some
|
|
3
|
+
* releases) and omitted `type`; current TGI sends string arguments.
|
|
4
|
+
* @param {any} call - Tool call as TGI sent it.
|
|
5
|
+
* @param {number} [position] - Position in the call list, the id when TGI sent none. Left out for streamed fragments, whose missing id
|
|
6
|
+
* means the fragment continues the open call.
|
|
7
|
+
* @returns {any} Tool call with a string id, `type: "function"` and string `arguments`.
|
|
8
|
+
*/
|
|
9
|
+
export function toolCall(call: any, position?: number): any;
|
|
10
|
+
/**
|
|
11
|
+
* The tool calls of a message or delta as a list: historic TGI sent one object instead of an array.
|
|
12
|
+
* @param {any} value - `tool_calls` as TGI sent it.
|
|
13
|
+
* @param {boolean} [fill] - Give a call without an id its position as the id (whole answers; not streamed fragments).
|
|
14
|
+
* @returns {any[] | undefined} The list, or undefined when there is none.
|
|
15
|
+
*/
|
|
16
|
+
export function toolCalls(value: any, fill?: boolean): any[] | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The OpenAI `finish_reason` for one TGI sent: `eos_token` and `stop_sequence` become `stop`, or `tool_calls` when the answer holds tool calls
|
|
19
|
+
* (historic TGI reported `eos_token` for those).
|
|
20
|
+
* @param {any} reason - `finish_reason` as TGI sent it.
|
|
21
|
+
* @param {boolean} hasToolCalls - Whether the answer holds tool calls.
|
|
22
|
+
* @returns {any} Finish reason.
|
|
23
|
+
*/
|
|
24
|
+
export function finish(reason: any, hasToolCalls: boolean): any;
|
|
25
|
+
/**
|
|
26
|
+
* TGI's grammar as `response_format` takes it: `{ type: "json" | "json_object" | "regex", value }` or `{ type: "json_schema", value: { name?, schema } }`.
|
|
27
|
+
* An OpenAI `json_schema` format (`{ type: "json_schema", json_schema: { name, schema, strict } }`) becomes TGI's `json_schema` with
|
|
28
|
+
* the name and schema; a bare `json_object` has no schema to constrain with, so it asks for any JSON object. Shapes TGI already
|
|
29
|
+
* understands pass through.
|
|
30
|
+
* @param {any} format - A `response_format` (or `grammar`) value.
|
|
31
|
+
* @returns {any} The format in TGI's shape.
|
|
32
|
+
*/
|
|
33
|
+
export function grammar(format: any): any;
|