@cldmv/llm-translator 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/api/convert/anthropic/messages/to/ollama/chat/request.mjs +2 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +8 -8
- package/dist/api/convert/ollama/chat/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/ollama/chat/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/convert/ollama/chat/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/ollama/chat/to/openai/chat/stream.mjs +2 -0
- package/dist/api/convert/openai/chat/to/ollama/chat/request.mjs +2 -0
- package/dist/api/detect.mjs +1 -1
- package/dist/api/driver/azure/detect.mjs +2 -0
- package/dist/api/driver/azure/error.mjs +2 -0
- package/dist/api/driver/azure/info.mjs +2 -0
- package/dist/api/driver/azure/model/list.mjs +2 -0
- package/dist/api/driver/azure/path.mjs +2 -0
- package/dist/api/driver/azure/request.mjs +2 -0
- package/dist/api/driver/azure/settings.mjs +2 -0
- package/dist/api/driver/fireworks/detect.mjs +2 -0
- package/dist/api/driver/fireworks/info.mjs +2 -0
- package/dist/api/driver/fireworks/path.mjs +2 -0
- package/dist/api/driver/fireworks/request.mjs +2 -0
- package/dist/api/driver/fireworks/settings.mjs +2 -0
- package/dist/api/driver/gemini/detect.mjs +2 -0
- package/dist/api/driver/gemini/info.mjs +2 -0
- package/dist/api/driver/gemini/path.mjs +2 -0
- package/dist/api/driver/gemini/request.mjs +2 -0
- package/dist/api/driver/gemini/settings.mjs +2 -0
- package/dist/api/driver/groq/detect.mjs +2 -0
- package/dist/api/driver/groq/info.mjs +2 -0
- package/dist/api/driver/groq/path.mjs +2 -0
- package/dist/api/driver/groq/request.mjs +2 -0
- package/dist/api/driver/groq/settings.mjs +2 -0
- package/dist/api/driver/localai/chunk.mjs +2 -0
- package/dist/api/driver/localai/detect.mjs +2 -0
- package/dist/api/driver/localai/info.mjs +2 -0
- package/dist/api/driver/localai/request.mjs +2 -0
- package/dist/api/driver/localai/response.mjs +2 -0
- package/dist/api/driver/localai/settings.mjs +2 -0
- package/dist/api/driver/ollama/info.mjs +1 -1
- package/dist/api/driver/ollama/request.mjs +1 -1
- package/dist/api/driver/openrouter/chunk.mjs +2 -0
- package/dist/api/driver/openrouter/detect.mjs +2 -0
- package/dist/api/driver/openrouter/info.mjs +2 -0
- package/dist/api/driver/openrouter/path.mjs +2 -0
- package/dist/api/driver/openrouter/request.mjs +2 -0
- package/dist/api/driver/openrouter/response.mjs +2 -0
- package/dist/api/driver/openrouter/settings.mjs +2 -0
- package/dist/api/driver/tgi/chunk.mjs +2 -0
- package/dist/api/driver/tgi/detect.mjs +2 -0
- package/dist/api/driver/tgi/info.mjs +2 -0
- package/dist/api/driver/tgi/request.mjs +2 -0
- package/dist/api/driver/tgi/response.mjs +2 -0
- package/dist/api/driver/tgi/settings.mjs +2 -0
- package/dist/api/driver/together/detect.mjs +2 -0
- package/dist/api/driver/together/info.mjs +2 -0
- package/dist/api/driver/together/request.mjs +2 -0
- package/dist/api/driver/together/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +1 -1
- package/dist/api/driver/vllm/info.mjs +1 -1
- package/dist/api/driver/vllm/model/list.mjs +1 -1
- package/dist/api/driver/xai/detect.mjs +2 -0
- package/dist/api/driver/xai/info.mjs +2 -0
- package/dist/api/driver/xai/request.mjs +2 -0
- package/dist/api/driver/xai/settings.mjs +2 -0
- package/dist/api/embeddings/send.mjs +1 -1
- package/dist/api/health/check.mjs +2 -0
- package/dist/api/model/list.mjs +1 -1
- package/dist/api/request.mjs +2 -2
- package/dist/api/response.mjs +1 -1
- package/dist/api/send.mjs +1 -1
- package/dist/api/status.mjs +1 -1
- package/dist/api/stream.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/azure.mjs +2 -0
- package/dist/lib/backends.mjs +1 -1
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/config.mjs +1 -1
- package/dist/lib/health.mjs +2 -0
- package/dist/lib/http.mjs +1 -1
- package/dist/lib/models.mjs +1 -1
- package/dist/lib/ndjson.mjs +4 -0
- package/dist/lib/ollama.mjs +3 -0
- package/dist/lib/openrouter.mjs +2 -0
- package/dist/lib/pool.mjs +1 -1
- package/dist/lib/presets.mjs +2 -0
- package/dist/lib/route.mjs +1 -1
- package/dist/lib/settings.mjs +1 -1
- package/dist/lib/tgi.mjs +2 -0
- package/dist/lib/vllm.mjs +4 -0
- package/package.json +1 -1
- package/types/src/api/convert/anthropic/messages/to/ollama/chat/request.d.mts +14 -0
- package/types/src/api/convert/ollama/chat/to/anthropic/messages/response.d.mts +10 -0
- package/types/src/api/convert/ollama/chat/to/anthropic/messages/stream.d.mts +14 -0
- package/types/src/api/convert/ollama/chat/to/openai/chat/response.d.mts +10 -0
- package/types/src/api/convert/ollama/chat/to/openai/chat/stream.d.mts +13 -0
- package/types/src/api/convert/openai/chat/to/ollama/chat/request.d.mts +12 -0
- package/types/src/api/driver/azure/detect.d.mts +8 -0
- package/types/src/api/driver/azure/error.d.mts +15 -0
- package/types/src/api/driver/azure/info.d.mts +31 -0
- package/types/src/api/driver/azure/model/list.d.mts +7 -0
- package/types/src/api/driver/azure/path.d.mts +7 -0
- package/types/src/api/driver/azure/request.d.mts +8 -0
- package/types/src/api/driver/azure/settings.d.mts +23 -0
- package/types/src/api/driver/fireworks/detect.d.mts +8 -0
- package/types/src/api/driver/fireworks/info.d.mts +13 -0
- package/types/src/api/driver/fireworks/path.d.mts +7 -0
- package/types/src/api/driver/fireworks/request.d.mts +7 -0
- package/types/src/api/driver/fireworks/settings.d.mts +5 -0
- package/types/src/api/driver/gemini/detect.d.mts +8 -0
- package/types/src/api/driver/gemini/info.d.mts +13 -0
- package/types/src/api/driver/gemini/path.d.mts +7 -0
- package/types/src/api/driver/gemini/request.d.mts +7 -0
- package/types/src/api/driver/gemini/settings.d.mts +5 -0
- package/types/src/api/driver/groq/detect.d.mts +8 -0
- package/types/src/api/driver/groq/info.d.mts +13 -0
- package/types/src/api/driver/groq/path.d.mts +7 -0
- package/types/src/api/driver/groq/request.d.mts +7 -0
- package/types/src/api/driver/groq/settings.d.mts +5 -0
- package/types/src/api/driver/localai/chunk.d.mts +25 -0
- package/types/src/api/driver/localai/detect.d.mts +6 -0
- package/types/src/api/driver/localai/info.d.mts +33 -0
- package/types/src/api/driver/localai/request.d.mts +10 -0
- package/types/src/api/driver/localai/response.d.mts +26 -0
- package/types/src/api/driver/localai/settings.d.mts +25 -0
- package/types/src/api/driver/ollama/info.d.mts +7 -2
- package/types/src/api/driver/openrouter/chunk.d.mts +25 -0
- package/types/src/api/driver/openrouter/detect.d.mts +26 -0
- package/types/src/api/driver/openrouter/info.d.mts +30 -0
- package/types/src/api/driver/openrouter/path.d.mts +8 -0
- package/types/src/api/driver/openrouter/request.d.mts +10 -0
- package/types/src/api/driver/openrouter/response.d.mts +8 -0
- package/types/src/api/driver/openrouter/settings.d.mts +26 -0
- package/types/src/api/driver/tgi/chunk.d.mts +9 -0
- package/types/src/api/driver/tgi/detect.d.mts +6 -0
- package/types/src/api/driver/tgi/info.d.mts +33 -0
- package/types/src/api/driver/tgi/request.d.mts +9 -0
- package/types/src/api/driver/tgi/response.d.mts +9 -0
- package/types/src/api/driver/tgi/settings.d.mts +25 -0
- package/types/src/api/driver/together/detect.d.mts +8 -0
- package/types/src/api/driver/together/info.d.mts +13 -0
- package/types/src/api/driver/together/request.d.mts +7 -0
- package/types/src/api/driver/together/settings.d.mts +5 -0
- package/types/src/api/driver/vllm/detect.d.mts +1 -1
- package/types/src/api/driver/vllm/info.d.mts +1 -1
- package/types/src/api/driver/vllm/model/list.d.mts +3 -1
- package/types/src/api/driver/xai/detect.d.mts +8 -0
- package/types/src/api/driver/xai/info.d.mts +13 -0
- package/types/src/api/driver/xai/request.d.mts +7 -0
- package/types/src/api/driver/xai/settings.d.mts +5 -0
- package/types/src/api/endpoint/status.d.mts +5 -2
- package/types/src/api/health/check.d.mts +8 -0
- package/types/src/api/status.d.mts +1 -1
- package/types/src/lib/azure.d.mts +17 -0
- package/types/src/lib/backends.d.mts +22 -0
- package/types/src/lib/config.d.mts +12 -0
- package/types/src/lib/events.d.mts +2 -2
- package/types/src/lib/health.d.mts +22 -0
- package/types/src/lib/http.d.mts +13 -2
- package/types/src/lib/models.d.mts +27 -2
- package/types/src/lib/ndjson.d.mts +16 -0
- package/types/src/lib/ollama.d.mts +86 -0
- package/types/src/lib/openrouter.d.mts +23 -0
- package/types/src/lib/pool.d.mts +30 -4
- package/types/src/lib/presets.d.mts +98 -0
- package/types/src/lib/route.d.mts +1 -1
- package/types/src/lib/settings.d.mts +5 -0
- package/types/src/lib/tgi.d.mts +33 -0
- package/types/src/lib/vllm.d.mts +47 -0
package/dist/api/request.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
1
|
+
var I=Object.defineProperty;var u=(e,o)=>I(e,"name",{value:o,configurable:!0});import{context as C,self as L}from"../lib/runtime.mjs";import{capture as M}from"../lib/capture.mjs";import{resolve as B}from"../lib/route.mjs";import*as y from"../lib/http.mjs";import{filterChatBody as E}from"../lib/passthrough.mjs";import{addSampling as P}from"../lib/sampling.mjs";import*as _ from"../lib/images.mjs";import*as x from"../lib/tools.mjs";import{LIMITS as R}from"../lib/toolsearch.mjs";import{warn as v}from"../lib/warn.mjs";import{emit as H}from"../lib/events.mjs";import{fit as z,pinBody as A}from"../lib/effort.mjs";import{relax as D,strictTools as G}from"../lib/strict.mjs";import{TranslatorError as J}from"../lib/errors.mjs";import*as K from"../lib/vllm.mjs";function N(e){return`${e.driver}:${e.protocol}:${URL.canParse(e.url)?new URL(e.url).host:e.url}`}u(N,"producerOf");async function ie(e,o={}){const n=M(L,C,o.front),m=B(n,e,{endpoint:o.endpoint,advance:o.hold===!0&&o.endpoint===void 0});if(o.hold!==!0)return T(n,e,o,m);m.endpoint.health.inflight++;try{return await T(n,e,o,m)}catch(t){throw m.endpoint.health.inflight--,t}}u(ie,"request");function Q(e,o,n,m,t,l){const j=G(o);if(j.length===0)return o;const a=j.filter(s=>s.problems.length>0);if(a.length>0&&t.unknownFields==="error")throw new J(`tools: ${a[0].name}: schema is outside the strict subset (${a[0].problems.join("; ")})`,{code:"unsupported_content",param:"tools"});const b=D(o);if(l.retry===!0)return b;const h=u((s,g)=>v(e.config,e.state,s,{kind:g,endpoint:n.name,log:l.log}),"tell");for(const s of a)h(`Upstream ${n.name}: strict tool ${s.name} has a schema outside the strict subset: ${s.problems.join("; ")} (sent without strict)`,"strict");const d=j.filter(s=>s.problems.length===0);return m.info.strict!==!0&&d.length>0&&h(`Upstream ${n.name}: the ${m.name} backend does not enforce strict tool use (${d.map(s=>s.name).join(", ")})`,"strict"),b}u(Q,"checkStrict");async function T(e,o,n,m){const{endpoint:t,model:l,unserved:j,convert:a,pool:b,pin:h}=m,d=Object.hasOwn(e.config.efforts,l)?e.config.efforts[l]:void 0;h&&(o=A(o,h,e.front));const s=e.driver(t),g=`${t.name}
|
|
2
|
+
${l}`,U=n.images===!1||e.state.textOnly.has(g)&&e.settings(t).imageFallback,$=e.settings(t),q=n.jsonObject==="instruction"||e.state.jsonInstruction.has(g)&&$.jsonObjectFallback,c={...U?{...$,images:!1}:$,...q?{jsonObject:"instruction"}:{},...h?.effort===void 0?{}:{effort:!0}},w=o.stream===!0,p=a===null?e.front==="anthropic"?"anthropic.messages":"openai.chat":t.protocol,O=p==="anthropic.messages"&&t.protocol==="openai.chat";let r,i;a?({body:r,state:i}=await a.request(o,c,{producer:N(t),budget:n.budget,listed:d!==void 0,toolCallIds:s.info.toolCallIds}),i.toolSearch?.capped&&v(e.config,e.state,`Tool search: more than ${R.definitions} tool definitions came back in ToolSearch results for ${t.name}; the rest are not offered.`,{kind:"toolsearch",endpoint:t.name,log:n.log})):O?r=K.request(o,c):r=e.front==="openai"&&(n.filter??c.passthroughFilter===!0)?E(o,s.info.fields):{...o};const F=e.front==="anthropic"?o.metadata?.sampling:void 0;if(p==="openai.chat"){const f=[];r=P(r,F,c,s.info.fields,f),i&&i.dropped.push(...f.filter(k=>!i.dropped.includes(k)))}else if(!a&&F!==void 0&&r.metadata?.sampling!==void 0){const{sampling:f,...k}=r.metadata;r={...r,metadata:k}}if(n.usage===!0&&w&&e.front==="openai"){if(a)i.includeUsage=!0;else if(c.streamUsage){const f=r.stream_options&&typeof r.stream_options=="object"?r.stream_options:{};r.stream_options={...f,include_usage:!0}}}U&&!a&&e.front==="openai"&&(r=_.strip(r)),n.tools===!1&&(r=x.strip(r)),r.model=l,r=Q(e,r,t,s,c,n),d&&p==="openai.chat"&&z(r,d,l,(f,k)=>v(e.config,e.state,f,{type:"effort",endpoint:t.name,model:l,...k,log:n.log})),i?.reasoningMissing&&v(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:n.log}),s.request&&!O&&(r=await s.request(r,{endpoint:t,settings:c,levels:d,state:i,warn:u(f=>v(e.config,e.state,f,{kind:"driver",endpoint:t.name,log:n.log}),"warn")})),i?.dropped?.length>0&&n.retry!==!0&&H(e,{type:"dropped",level:"debug",message:`Upstream ${t.name}: dropped ${i.dropped.join(", ")}`,endpoint:t.name,model:l,fields:[...i.dropped],log:n.log});const S=await y.pathOf(s,p==="anthropic.messages"?"messages":"chat",t,l);return{upstream:t.name,pool:b.map(f=>f.name),method:"POST",url:y.join(t.url,S),path:S,headers:{"content-type":"application/json",accept:w?"text/event-stream":"application/json",...s.info.headers,...a===null&&t.protocol==="anthropic.messages"?n.clientHeaders:void 0,...y.headers(t,s.info.auth,n.headers)},body:r,state:{v:1,upstream:t.name,front:e.front,native:a===null,messages:O,model:o.model,stream:w,unserved:j,convert:i},images:{sent:_.carries(r),retry:c.imageFallback&&p==="openai.chat",key:g},tools:{sent:x.carries(r),retry:c.toolFallback&&p==="openai.chat"},json:{sent:i?.jsonSchemaEmulated===!0,retry:c.jsonObjectFallback&&p==="anthropic.messages",key:g}}}u(T,"prepare");export{ie as request};
|
|
3
3
|
//# sourceMappingURL=request.mjs.map
|
package/dist/api/response.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=Object.defineProperty;var t=(s,e)=>m(s,"name",{value:e,configurable:!0});import{context as p,self as d}from"../lib/runtime.mjs";import{capture as c}from"../lib/capture.mjs";import*as f from"../lib/vllm.mjs";async function g(s,e){const o=c(d,p,e.front),r=o.endpoint(e.upstream),i=o.driver(r);let n=s;return i.response&&(n=await i.response(n,{endpoint:r,settings:o.settings(r),state:e})),e.messages&&(n=f.response(n)),e.native?n.model===void 0?n:{...n,model:e.model??n.model}:o.converters(r).response(n,e.convert,o.settings(r))}t(g,"response");export{g as response};
|
|
2
2
|
//# sourceMappingURL=response.mjs.map
|
package/dist/api/send.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var le=Object.defineProperty;var u=(c,r)=>le(c,"name",{value:r,configurable:!0});import{context as K,self as ee}from"../lib/runtime.mjs";import{TranslatorError as z}from"../lib/errors.mjs";import*as te from"../lib/http.mjs";import*as ue from"../lib/images.mjs";import*as ce from"../lib/tools.mjs";import{parse as ae}from"../lib/upstream-error.mjs";import{meter as me,normalize as de}from"../lib/usage.mjs";import{capture as fe}from"../lib/capture.mjs";import{estimate as pe,bodyLength as ge,output as he,patch as ye,stream as we}from"../lib/estimate.mjs";import{warn as se}from"../lib/warn.mjs";import{start as be}from"../lib/record.mjs";import{emit as re}from"../lib/events.mjs";import*as ne from"../lib/pool.mjs";import{createBudget as ke}from"../lib/thinking.mjs";import*as oe from"../lib/fanout.mjs";import{refresh as je}from"../lib/health.mjs";const ve={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"};async function _e(c,r={}){const{transport:w,textOnly:f,jsonInstruction:v}=K.state,{request:_,response:$,stream:o,error:p}=ee,d=p.build,{config:i,state:b}=K,g=fe(ee,K,r.front),U=c&&typeof c=="object"&&!Array.isArray(c),T={model:null,requested:U&&typeof c.model=="string"?c.model:null,upstream:null,front:r.front??i.front,stream:U&&c.stream===!0},k=me(T,r.onUsage,(m,A)=>se(i,b,m,{type:"usage",...A,log:r.log})),q=u(m=>Object.defineProperty(m,"usage",{value:k.usage,enumerable:!1,configurable:!0}),"attach");let J=!1;try{const m=oe.wants(g,c);if(m>0){J=!0;const A=u((n,S)=>se(i,b,n,{type:"usage",...S,log:r.log}),"warning");return await oe.run({body:c,count:m,options:r,send:_e,warn:A})}return q(await $e({transport:w,textOnly:f,jsonInstruction:v,request:_,response:$,stream:o,error:p,captured:g},c,r,k))}catch(m){if(J)throw m;if(!(m instanceof z))throw r.signal?.aborted||re(g,{type:"error",kind:"exception",level:"error",message:String(m?.message??m),log:r.log}),k.finish(r.signal?.aborted?"aborted":"error"),m;return k.finish("error"),q(d(m.status,m.message,{type:m.type,code:m.code,param:m.param,front:r.front}))}}u(_e,"send");async function $e({transport:c,textOnly:r,jsonInstruction:w,request:f,response:v,stream:_,error:$,captured:o},p,d,i){const b={front:d.front,headers:d.headers,clientHeaders:d.clientHeaders,filter:d.filter,usage:!0,budget:ke(),log:d.log},g=u(t=>{re(o,{...t,log:d.log})},"announce"),U=i.meta.front==="openai"&&p?.stream_options?.include_usage!==!0,T=u(t=>{i.meta.model=t.body.model??null,i.meta.upstream=t.upstream,t.state.native?i.source(null):i.source(()=>t.state.convert?.upstreamUsage,t.state.front==="anthropic"?"openai":"folded")},"note"),k=u(t=>{if(t.state.native)return{input:!1,output:!1};const e=de(t.state.front==="anthropic"?"openai":"folded",t.state.convert?.upstreamUsage);return e===null?{input:!0,output:!0}:{input:e.input_tokens===null&&e.cache_read_input_tokens===null&&e.cache_creation_input_tokens===null,output:e.output_tokens===null}},"gaps"),q=u(async t=>{const e=o.endpoint(t.upstream),a=o.driver(e);return(a.count&&!(U&&t.state.stream)?await a.count({endpoint:e,request:t.body,transport:c,signal:d.signal,timeout:o.config.detectTimeout}):null)??pe(t.body)},"input"),J=u(async(t,e)=>{const a=k(t);return!a.input&&!a.output?null:{input_tokens:a.input?await q(t):null,output_tokens:a.output?he(e):null}},"counts"),m=u((t,e,a,s,R)=>(i.finish(R),$(t,e,a,s)),"fail"),A=u(async t=>{let e=t,a=await Q(c,e,d.signal,I());const s=a.status;if(s===404&&e.state.messages){const y=await C(a);return y?.type==="error"?{upstream:e,result:a,failure:y}:(o.state.noMessages.add(e.upstream),g({type:"fallback",kind:"messages",level:"warn",message:`Upstream ${e.upstream}: /v1/messages answered 404; sent the request converted to Chat Completions, and will do so for this upstream until the next detection. Set nativeMessages: false on this upstream to skip the first attempt.`,endpoint:e.upstream,model:e.body.model,status:s,reason:String(ae(y,s).message).trim().slice(0,500),action:"conversion"}),e=await f(p,{...b,endpoint:e.upstream,retry:!0}),T(e),{upstream:e,result:await Q(c,e,d.signal,I())})}const R=s===400&&[e.images,e.tools].some(y=>y.sent&&y.retry),F=(s===400||s===422)&&e.json.sent&&e.json.retry;if(!a.ok&&(R||F)){const y=await C(a),O=ae(y,s).message,h={};if(s===400&&e.images.sent&&e.images.retry&&ue.refused(O)?(r.add(e.images.key),h.images=!1):s===400&&e.tools.sent&&e.tools.retry&&ce.refused(O)?h.tools=!1:F&&(h.jsonObject="instruction"),!("images"in h||"tools"in h||"jsonObject"in h))return{upstream:e,result:a,failure:y};const j={upstream:e,result:a,failure:y};if("images"in h||"tools"in h){const G="images"in h?"images":"tools";g({type:"fallback",kind:G,level:"warn",message:`Upstream ${e.upstream}: ${e.state.model} refused ${G==="images"?"images":"tools"} (${s}: "${String(O).trim().slice(0,500)}"); sent the request again without them.`,endpoint:e.upstream,model:e.body.model,status:s,reason:String(O).trim().slice(0,500),action:G==="images"?"text-only":"without-tools"})}if(e=await f(p,{...b,...h,endpoint:e.upstream,retry:!0}),T(e),a=await Q(c,e,d.signal,I()),F&&"jsonObject"in h){if(!a.ok){try{await a.body?.cancel?.()}catch{}return T(j.upstream),j}w.add(j.upstream.json.key),g({type:"fallback",kind:"json_object",level:"warn",message:`Upstream ${j.upstream.upstream}: ${j.upstream.state.model} rejected the json_object schema emulation (${s}: "${String(O).trim().slice(0,500)}"); sent it as a system instruction instead. Set jsonObject: "instruction" on this upstream to skip the first attempt.`,endpoint:j.upstream.upstream,model:j.upstream.body.model,status:s,reason:String(O).trim().slice(0,500),action:"instruction"})}}return{upstream:e,result:a}},"attempt");await je(o,p,d.signal);let n=await f(p,{...b,hold:!0});const S=n.pool;let B=0;const D=S.length>1?o.config.pool:null,I=u(()=>D&&{connectTimeout:D.connectTimeout,headersTimeout:B+1<S.length?D.headersTimeout:0},"limitsNow");let E=o.endpoint(n.upstream);const V=u(()=>E.health.inflight--,"release");let l,x,W=null,X=0;const Y=u(t=>{const e=be(o,{body:p,sent:n,front:i.meta.front,requested:i.meta.requested,headers:t,log:d.log,exchange:W,attempt:X});return W??=e.id,e},"begin"),Z=u(async t=>{const e=Y();if(!e.on)return;if(l===void 0)return e.attempt({error:x.message},t);let a=null;try{a=x??await C(l)}catch{}e.attempt({status:l.status,headers:te.plain(l.headers),body:a},t)},"keep");try{for(;;){const t=E;t.health.requests++,X++,T(n);let e=null;try{({upstream:n,result:l,failure:x}=await A(n)),!l.ok&&l.status>=500&&(e=`HTTP ${l.status}`,g({type:"error",kind:"upstream",level:"error",message:`Upstream ${t.name} answered HTTP ${l.status}`,endpoint:t.name,model:n.body.model,status:l.status}))}catch(s){if(!(s instanceof z)||s.code!=="upstream_unreachable")throw s;e=s.message,l=void 0,x=s,g({type:"error",kind:"transport",level:"error",message:s.message,endpoint:t.name,model:n.body.model})}if(e===null){ne.succeeded(t);break}ne.failed(o.config,t,e);let a=null;for(;a===null&&!d.signal?.aborted&&B+1<S.length;)try{a=await f(p,{...b,endpoint:S[++B],hold:!0})}catch(s){if(!(s instanceof z)||s.code!=="endpoint_not_in_pool")throw s}if(a===null){if(l===void 0)throw await Z(),x;break}await Z(e),g({type:"failover",level:"warn",message:`Upstream ${t.name} failed (${e}); trying ${a.upstream}`,from:t.name,to:a.upstream,model:a.body.model,reason:e});try{await l?.body?.cancel?.()}catch{}V(),E=o.endpoint(a.upstream),n=a}}catch(t){throw V(),t}const ie=E;E=null,i.usage.then(()=>ie.health.inflight--);const H=te.plain(l.headers),M=Y(H);if(!l.ok){const t=x??await C(l);return M.reply(l.status,H,t),m(l.status,t,H,n.state,"upstream_error")}if(n.state.stream){const t=_(M.raw(l.body),n.state),e=n.state.native?t:we(i.meta.front,t,{gaps:u(()=>k(n),"gaps"),input:u(()=>q(n),"input"),report:u(a=>i.estimate(a),"report")});return{status:200,headers:ve,stream:M.events(i.track(e,d.signal,U))}}const P=await C(l);if(M.reply(l.status,H,P),P===null||typeof P!="object")return g({type:"error",kind:"upstream",level:"error",message:`Upstream ${n.upstream} returned a body that is not JSON`,endpoint:n.upstream,model:n.body.model,status:502}),m(502,"The upstream returned a body that is not JSON",H,n.state,"error");const N=await v(P,n.state),L=await J(n,ge(i.meta.front,N));return L&&(N.usage=ye(i.meta.front,N.usage,L),i.estimate(L)),i.json(N),i.finish("done"),{status:200,headers:{"content-type":"application/json"},body:N}}u($e,"round");async function Q(c,r,w,f=null){let v,_=!1,$=w;if(f&&f.headersTimeout>0){const o=new AbortController;$=w?AbortSignal.any([w,o.signal]):o.signal,v=setTimeout(()=>{_=!0,o.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(o){if(w?.aborted)throw o;const p=_?`no response headers within ${f.headersTimeout} ms`:o.message;throw new z(`Could not reach the upstream (${r.upstream}): ${p}`,{code:"upstream_unreachable",status:502,details:{cause:o}})}finally{clearTimeout(v)}}u(Q,"call");async function C(c){const r=await c.text();try{return JSON.parse(r)}catch{return r===""?null:r}}u(C,"parse");export{_e as send};
|
|
2
2
|
//# sourceMappingURL=send.mjs.map
|
package/dist/api/status.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=Object.defineProperty;var e=(s,a)=>m(s,"name",{value:a,configurable:!0});import{context as t}from"../lib/runtime.mjs";import{describe as l}from"../lib/pool.mjs";import{resolve as o}from"../lib/settings.mjs";import{wants as f}from"../lib/vllm.mjs";function h(){const{config:s,state:a}=t;return{front:s.front,upstreams:a.endpoints.map(r=>({name:r.name,url:r.url,backend:r.backend,driver:r.driver,protocol:r.protocol,version:r.facts?.version??r.version,models:r.models??r.facts?.models??[],default:r.default,facts:r.facts,probed:r.probed,messages:r.driver==="vllm"?f(r,o(r.driverSettings,r.probed,s.settings,r.settings))&&!a.noMessages.has(r.name):null,health:l(r)}))}}e(h,"status");export{h as status};
|
|
2
2
|
//# sourceMappingURL=status.mjs.map
|
package/dist/api/stream.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var b=Object.defineProperty;var i=(e,o)=>b(e,"name",{value:o,configurable:!0});import{context as j,self as A}from"../lib/runtime.mjs";import{capture as B}from"../lib/capture.mjs";import{messages as v}from"../lib/sse.mjs";import*as D from"../lib/vllm.mjs";function u(e,o){return!o||!e||typeof e!="object"?e:e.message&&typeof e.message=="object"&&e.message.model!==void 0?{...e,message:{...e.message,model:o}}:e.model===void 0?e:{...e,model:o}}i(u,"restore");function E(e){return!!e&&Array.isArray(e.choices)&&(e.choices.length===0||e.choices.some(o=>o?.finish_reason))}i(E,"ends");function _(e,o){const r=B(A,j,o.front),c=r.endpoint(o.upstream),a=r.driver(c),l=r.settings(c),f=o.native?null:r.converters(c),t=a.chunk,m={endpoint:c,settings:l,state:o};async function*d(){for(const n of await a.flush?.(m)??[])yield{data:n}}if(i(d,"flushed"),f&&!t)return f.stream(e,o.convert,l);if(f)return f.stream((async function*(){for await(const n of v(e))n.data!=="[DONE]"&&(yield await t(n.data,m));for await(const n of d())yield n.data})(),o.convert,l);const w=!!(t&&a.flush),y=(async function*(){const n=[];let g=!1;for await(const s of v(e)){if(s.data==="[DONE]"){for await(const x of d())yield{data:u(x.data,o.model)};yield*n.splice(0),g=!0,yield s;continue}const h=t?await t(s.data,m):s.data,p={...s,data:u(h,o.model)};w&&E(h)?n.push(p):yield p}if(!g){for await(const s of d())yield{data:u(s.data,o.model)};yield*n}})();return o.messages?D.stream(y):y}i(_,"stream");export{_ as stream};
|
|
2
2
|
//# sourceMappingURL=stream.mjs.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var i=Object.defineProperty;var a=(r,
|
|
1
|
+
var i=Object.defineProperty;var a=(r,e)=>i(r,"name",{value:e,configurable:!0});import{fileURLToPath as d}from"node:url";import p from"@cldmv/slothlet";import{normalize as c}from"./lib/config.mjs";import{load as l}from"./lib/pdf.mjs";import{transport as f}from"./lib/transport.mjs";import{create as m,open as u}from"./lib/events.mjs";import{warn as s}from"./lib/warn.mjs";async function w(r){const e=c(r),n={endpoints:e.endpoints,transport:e.transport??f,servers:new Set,warned:new Set,events:m(e.onEvent),textOnly:new Set,jsonInstruction:new Set,noMessages:new Set,cursors:new Map,front:void 0};u(n.events,e.logs);const t=await l();t.errors.canvas&&s(e,n,`@napi-rs/canvas could not be loaded (${t.errors.canvas}); PDFs will be read as text only, without page images`,{type:"detect",kind:"canvas",reason:String(t.errors.canvas)}),t.errors.unpdf&&s(e,n,`unpdf could not be loaded (${t.errors.unpdf}); PDF documents cannot be read and fall back to a note`,{type:"detect",kind:"unpdf",reason:String(t.errors.unpdf)});const o=await p({...r.slothlet,base:d(new URL("./api",import.meta.url)),mode:"eager",context:{config:e,state:n},silent:!0});return await o.detect({network:e.detect}),o}a(w,"createTranslator");import{TranslatorError as D}from"./lib/errors.mjs";var P=w;export{D as TranslatorError,w as createTranslator,P as default};
|
|
2
2
|
//# sourceMappingURL=index.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
|
|
1
|
+
var b=Object.defineProperty;var s=(o,n)=>b(o,"name",{value:n,configurable:!0});import{resolve as f}from"./settings.mjs";import*as v from"./vllm.mjs";import{PROTOCOL as k}from"./ollama.mjs";function x(o){const n=[];for(const a of Object.keys(o??{})){const t=o[a];typeof t?.info=="function"&&n.push({name:a,info:t.info(),detect:t.detect,settings:t.settings,probe:t.probe,path:t.path,request:t.request,response:t.response,chunk:t.chunk,flush:t.flush,error:t.error,count:t.token?.count,list:t.model?.list})}return n.sort((a,t)=>a.info.order-t.info.order)}s(x,"collect");function w(o,n,a){const{config:t,state:i}=n,p=o.convert.anthropic.messages.to.openai.chat,u=o.convert.openai.chat.to.anthropic.messages,g={anthropic:o.convert.anthropic.messages.to.ollama.chat,openai:o.convert.openai.chat.to.ollama.chat},m={anthropic:o.convert.ollama.chat.to.anthropic.messages,openai:o.convert.ollama.chat.to.openai.chat},r=a??t.front,l=x(o.driver),d=r==="anthropic"?"anthropic.messages":"openai.chat",q=r==="anthropic"?{request:p.request,response:u.response,stream:u.stream}:{request:u.request,response:p.response,stream:p.stream},O={request:g[r].request,response:m[r].response,stream:m[r].stream};return{config:t,state:i,front:r,drivers:l,endpoint:s(e=>i.endpoints.find(c=>c.name===e),"endpoint"),driver:s(e=>l.find(c=>c.name===e.driver),"driver"),settings:s(e=>f(e.driverSettings,e.probed,t.settings,e.settings),"settings"),converters:s((e,c)=>{if(e.protocol===k)return O;if(e.protocol===d)return null;if(r==="anthropic"&&c!==void 0&&e.driver==="vllm"&&!i.noMessages.has(e.name)){const h=f(e.driverSettings,e.probed,t.settings,e.settings);if(v.wants(e,h)&&v.unsuited(c,h)===null)return null}return q},"converters")}}s(w,"capture");export{w as capture,x as collect};
|
|
2
2
|
//# sourceMappingURL=capture.mjs.map
|
package/dist/lib/config.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var i=Object.defineProperty;var a=(t,r)=>i(t,"name",{value:r,configurable:!0});import{TranslatorError as
|
|
1
|
+
var i=Object.defineProperty;var a=(t,r)=>i(t,"name",{value:r,configurable:!0});import{TranslatorError as o}from"./errors.mjs";import*as n from"./pool.mjs";import{valid as p}from"./record.mjs";import{normalizeAliases as u,normalizeEfforts as l}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}a(d,"baseUrl");function f(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});if(e.api!==void 0&&e.api!=="openai"&&e.api!=="native")throw new o(`upstreams[${r}].api must be "openai" or "native" (got ${JSON.stringify(e.api)})`,{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,api:e.api??"openai",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:n.health()}}a(f,"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(!p(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(f),...u(t.aliases),efforts:l(t.efforts),pool:n.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}}a(y,"normalize");export{f as endpoint,y as normalize};
|
|
2
2
|
//# sourceMappingURL=config.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var d=Object.defineProperty;var l=(e,a)=>d(e,"name",{value:a,configurable:!0});import*as i from"./http.mjs";import{emit as u}from"./events.mjs";import{pick as c}from"./route.mjs";async function m(e,a,n,o){const t=a.health,s=await i.json(e.state.transport,i.join(a.url,n.info.paths.health),{method:"GET",headers:i.headers(a,n.info.auth),signal:o,timeout:e.config.pool.healthTimeout});if(o?.aborted)return;const r=t.ready;t.checkedAt=Date.now(),s.ok?(t.ready=!0,t.readyReason=null):s.status===0||s.status>=500?(t.ready=!1,t.readyReason=s.status===0?String(s.error?.message??"no answer"):`HTTP ${s.status}`):(t.ready=null,t.readyReason=null,t.unsupported=!0),t.ready===!1&&r!==!1?u(e,{type:"health",kind:"down",level:"warn",message:`Upstream ${a.name} is not ready (${t.readyReason}); requests go to other endpoints that serve the same model first`,endpoint:a.name,reason:t.readyReason}):t.ready===!0&&r===!1&&u(e,{type:"health",kind:"up",level:"info",message:`Upstream ${a.name} is ready again`,endpoint:a.name})}l(m,"run");async function p(e,a,n={}){const o=Date.now(),{healthInterval:t}=e.config.pool;await Promise.all(a.map(s=>{const r=s.health,f=e.driver(s);if(!f.info.paths?.health)return;if(n.force)r.unsupported=!1;else if(r.unsupported||t<=0)return;const h=Math.max(r.checkedAt??0,r.ready===!1?0:r.lastSuccess??0);if(!(!n.force&&o-h<t))return r.checking??=m(e,s,f,n.signal).finally(()=>{r.checking=null}),r.checking}))}l(p,"probe");async function w(e,a,n){if(e.config.pool.healthInterval<=0||!a||typeof a!="object")return;const{pool:o}=c(e.config,e.state.endpoints,a.model,e.state);o.length>1&&await p(e,o,{signal:n})}l(w,"refresh");export{p as probe,w as refresh};
|
|
2
|
+
//# sourceMappingURL=health.mjs.map
|
package/dist/lib/http.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var h=Object.defineProperty;var
|
|
1
|
+
var h=Object.defineProperty;var r=(t,e)=>h(t,"name",{value:e,configurable:!0});function y(t,e){return t+e}r(y,"join");async function m(t,e,a,n){return t.path?t.path(e,{endpoint:a,model:n}):(t.info.native!==void 0&&a.protocol===t.info.native.protocol?t.info.native.paths:void 0)?.[e]??t.info.paths[e]??p[e]}r(m,"pathOf");const p={embeddings:"/v1/embeddings",models:"/v1/models"};function k(t){return t==="localhost"||t==="::1"||/^127\./.test(t)}r(k,"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}}r(d,"headers");function S({endpoint:t,transport:e,signal:a,timeout:n,probes:s},c,u){const i=u!==void 0&&(u.auth==="x-api-key"||u.auth==="api-key"||u.headers!==void 0),o=i?{auth:u.auth,extra:u.headers}:{},l=r(()=>g(e,y(t.url,c),{method:"GET",headers:d(t,o.auth,o.extra),signal:a,timeout:n}),"run");if(!s)return l();const f=i?JSON.stringify([c,o.auth,o.extra]):c;return s.has(f)||s.set(f,l()),s.get(f)}r(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}r(x,"plain");async function g(t,e,a={}){const{timeout:n,signal:s,body:c,...u}=a,i=[];s&&i.push(s),n>0&&i.push(AbortSignal.timeout(n));try{const o=await t(e,{...u,redirect:"error",body:c===void 0?void 0:JSON.stringify(c),signal:i.length>1?AbortSignal.any(i):i[0]}),l=await o.text();let f=null;try{f=JSON.parse(l)}catch{f=l===""?null:l}return{ok:o.ok,status:o.status,body:f,headers:x(o.headers)}}catch(o){return{ok:!1,status:0,body:null,error:o}}}r(g,"json");export{d as headers,k as isLoopback,y as join,g as json,m 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 c=Object.defineProperty;var r=(t,a)=>c(t,"name",{value:a,configurable:!0});import*as s from"./http.mjs";function l(t){return!t.ok||!Array.isArray(t.body?.data)?null:t.body.data.filter(a=>a&&typeof a.id=="string")}r(l,"modelsOf");function i(t){return t.filter(a=>typeof a?.parent=="string"&&a.parent!=="").map(a=>({id:a.id,parent:a.parent}))}r(i,"adaptersOf");function u(t){const a=new Set((t.facts?.adapters??[]).map(e=>e.id));return(t.models??t.facts?.models??[]).filter(e=>!a.has(e))}r(u,"baseModels");function h(t){const a=new Map((t.facts?.adapters??[]).map(e=>[e.id,e.parent]));return(t.models??t.facts?.models??[]).map(e=>a.has(e)?{id:e,parent:a.get(e)}:{id:e})}r(h,"knownModels");async function x({endpoint:t,transport:a,signal:e,timeout:o,auth:n,extraHeaders:p,path:f="/v1/models"}){const d=await s.json(a,s.join(t.url,f),{method:"GET",headers:s.headers(t,n,p),signal:e,timeout:o});return l(d)}r(x,"fetchModels");export{i as adaptersOf,u as baseModels,x as fetchModels,h as knownModels,l as modelsOf};
|
|
2
2
|
//# sourceMappingURL=models.mjs.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var i=Object.defineProperty;var o=(e,s)=>i(e,"name",{value:s,configurable:!0});import{items as c}from"./source.mjs";import{TranslatorError as d}from"./errors.mjs";function l(e){try{return JSON.parse(e)}catch{throw new d("Upstream sent a stream line that is not valid JSON",{code:"invalid_stream_data",status:502,details:{data:e}})}}o(l,"decode");function f(){let e="";const s=o((r,t)=>{const n=r.replace(/\r$/,"").trim();n!==""&&t.push(l(n))},"lines");return{push(r){const t=[];e+=r;let n=0;for(let a=e.indexOf(`
|
|
2
|
+
`);a!==-1;a=e.indexOf(`
|
|
3
|
+
`,n))s(e.slice(n,a),t),n=a+1;return e=e.slice(n),t},flush(){const r=[];return s(e,r),e="",r}}}o(f,"createParser");async function*h(e){const s=f(),r=new TextDecoder;for await(const t of c(e))typeof t=="string"||t instanceof Uint8Array?yield*s.push(typeof t=="string"?t:r.decode(t,{stream:!0})):yield t;yield*s.push(r.decode()),yield*s.flush()}o(h,"parse");export{f as createParser,h as parse};
|
|
4
|
+
//# sourceMappingURL=ndjson.mjs.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var v=Object.defineProperty;var r=(t,o)=>v(t,"name",{value:o,configurable:!0});import{TranslatorError as F}from"./errors.mjs";import{callId as S,completionId as k}from"./ids.mjs";import{parseArguments as D}from"./arguments.mjs";import{reasoningOf as E}from"./thinking.mjs";const z="ollama.chat",x=["temperature","top_p","top_k","min_p","seed","frequency_penalty","presence_penalty"],L=new Set(["model","messages","stream","tools","tool_choice","max_tokens","max_completion_tokens","stop","response_format","reasoning_effort","chat_template_kwargs","think","options","format","keep_alive",...x,"repetition_penalty"]),M=new Set(["stream_options","user","metadata","store","service_tier"]),T="[An image was omitted because Ollama accepts base64 images only and the translator does not fetch URLs.]",O={none:!1,minimal:"low",low:"low",medium:"medium",high:"high",xhigh:"high",max:"max"};function h(t,o){t.includes(o)||t.push(o)}r(h,"drop");const A=r(t=>t!==null&&typeof t=="object"&&!Array.isArray(t),"isObject");function I(t,o){if(typeof t=="string")return{text:t,images:[]};const n=[],i=[];for(const e of Array.isArray(t)?t:[])if(e?.type==="text"&&typeof e.text=="string")n.push(e.text);else if(e?.type==="image_url"){const a=String(e.image_url?.url??e.image_url??""),c=/^data:[^;,]*;base64,(.*)$/s.exec(a);c?i.push(c[1]):(n.push(T),h(o,"image_url"))}else h(o,`content.${e?.type??"part"}`);return{text:n.join(`
|
|
2
|
+
`),images:i}}r(I,"contentOf");function R(t,o){return t.map(n=>(typeof n.id=="string"&&o.set(n.id,n.function?.name),{type:"function",function:{name:n.function?.name,arguments:D(n.function?.arguments)}}))}r(R,"callsOf");function U(t,o,n){const{text:i,images:e}=I(t?.content,n);if(t?.role==="tool"){const c=o.get(t.tool_call_id)??t.name;return{role:"tool",...typeof c=="string"?{tool_name:c}:{},content:i}}const a={role:t?.role==="developer"?"system":t?.role,content:i};if(e.length>0&&(a.images=e),t?.role==="assistant"){const c=E(t);c!==""&&(a.thinking=c),Array.isArray(t.tool_calls)&&t.tool_calls.length>0&&(a.tool_calls=R(t.tool_calls,o))}return a}r(U,"messageOf");function C(t){if(typeof t.reasoning_effort=="string")return Object.hasOwn(O,t.reasoning_effort)?O[t.reasoning_effort]:t.reasoning_effort;if(t.think!==void 0)return t.think;const o=t.chat_template_kwargs?.enable_thinking;return typeof o=="boolean"?o:void 0}r(C,"thinkOf");function H(t,o){const n={};for(const[e,a]of Object.entries(o))n[e==="repetition_penalty"?"repeat_penalty":e]=a;for(const e of x)t[e]!==void 0&&t[e]!==null&&(n[e]=t[e]);t.repetition_penalty!==void 0&&(n.repeat_penalty=t.repetition_penalty);const i=t.max_completion_tokens??t.max_tokens;return i!=null&&(n.num_predict=i),t.stop!==void 0&&t.stop!==null&&(n.stop=Array.isArray(t.stop)?t.stop:[t.stop]),A(t.options)?{...n,...t.options}:n}r(H,"optionsOf");function $(t){if(t.format!==void 0)return t.format;const o=t.response_format;if(o?.type==="json_object")return"json";if(o?.type==="json_schema"&&A(o.json_schema?.schema))return o.json_schema.schema}r($,"formatOf");function G(t,o={}){const n=o.dropped??[],i=new Map,e={model:t.model,messages:(Array.isArray(t.messages)?t.messages:[]).map(s=>U(s,i,n)),stream:t.stream===!0};Array.isArray(t.tools)&&t.tools.length>0&&t.tool_choice!=="none"?(e.tools=t.tools.map(s=>({type:"function",function:{name:s.function?.name,description:s.function?.description,parameters:s.function?.parameters??{type:"object",properties:{}}}})),t.tool_choice!==void 0&&t.tool_choice!=="auto"&&h(n,"tool_choice")):t.tool_choice==="none"&&Array.isArray(t.tools)&&h(n,"tools");const a=H(t,o.sampling??{});Object.keys(a).length>0&&(e.options=a);const c=$(t);c!==void 0&&(e.format=c);const f=C(t);f!==void 0&&(e.think=f),t.keep_alive!==void 0&&(e.keep_alive=t.keep_alive);for(const s of Object.keys(t))L.has(s)||M.has(s)||s==="n"&&!(t.n>1)||h(n,s);return e}r(G,"chatBody");function j(t,o=0){return(Array.isArray(t)?t:[]).map((n,i)=>{const e=n?.function?.arguments;return{index:o+i,id:typeof n?.id=="string"&&n.id!==""?n.id:S(),type:"function",function:{name:n?.function?.name,arguments:typeof e=="string"?e:JSON.stringify(e??{})}}})}r(j,"callsOfReply");function y(t,o){return o?"tool_calls":t?.done_reason==="length"?"length":"stop"}r(y,"finishOf");function w(t){const o=t?.prompt_eval_count,n=t?.eval_count;if(!Number.isFinite(o)&&!Number.isFinite(n))return;const i=Number.isFinite(o)?o:0,e=Number.isFinite(n)?n:0;return{prompt_tokens:i,completion_tokens:e,total_tokens:i+e}}r(w,"usageOf");function Q(t){return t===void 0?void 0:{input_tokens:t.prompt_tokens,output_tokens:t.completion_tokens}}r(Q,"folded");function N(t){return typeof t?.error=="string"?t.error:null}r(N,"errorOf");function V(t,o={}){const n=N(t);if(n!==null)throw new F(n,{code:"upstream_error",status:502});const i=t?.message??{},e=j(i.tool_calls),a={role:"assistant",content:typeof i.content=="string"?i.content:""};typeof i.thinking=="string"&&i.thinking!==""&&(a[o.reasoningField??"reasoning"]=i.thinking),e.length>0&&(a.tool_calls=e.map(s=>({id:s.id,type:s.type,function:s.function})));const c=w(t),f=Date.parse(t?.created_at);return{id:k(),object:"chat.completion",created:Number.isNaN(f)?Math.floor(Date.now()/1e3):Math.floor(f/1e3),model:t?.model,choices:[{index:0,message:a,finish_reason:y(t,e.length>0)}],...c===void 0?{}:{usage:c}}}r(V,"completion");function W(t={}){const o=k(),n=Math.floor(Date.now()/1e3),i=t.reasoningField??"reasoning";let e=t.model,a=!1,c=0,f=!1,s;const g=r((u,_=null)=>({id:o,object:"chat.completion.chunk",created:n,model:e,choices:[{index:0,delta:u,finish_reason:_}]}),"make");return{line(u){const _=N(u);if(_!==null)return f=!0,[{error:{message:_,type:"api_error",param:null,code:null}}];e=t.model??u?.model??e;const p=[];a||(a=!0,p.push(g({role:"assistant",content:""})));const l=u?.message??{},m={};typeof l.thinking=="string"&&l.thinking!==""&&(m[i]=l.thinking),typeof l.content=="string"&&l.content!==""&&(m.content=l.content);const d=j(l.tool_calls,c);return d.length>0&&(c+=d.length,m.tool_calls=d),Object.keys(m).length>0&&p.push(g(m)),u?.done===!0&&(f=!0,s=w(u),p.push(g({},y(u,c>0))),t.includeUsage!==!1&&s!==void 0&&p.push({id:o,object:"chat.completion.chunk",created:n,model:e,choices:[],usage:s})),p},finished:r(()=>f,"finished"),usage:r(()=>s,"usage")}}r(W,"createChunker");export{z as PROTOCOL,j as callsOfReply,G as chatBody,V as completion,W as createChunker,N as errorOf,y as finishOf,Q as folded,w as usageOf};
|
|
3
|
+
//# sourceMappingURL=ollama.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/pool.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var k=Object.defineProperty;var i=(t,r)=>k(t,"name",{value:r,configurable:!0});import{TranslatorError as S}from"./errors.mjs";const d=Object.freeze(["failover","round_robin","least_busy"]),m=Object.freeze({base:1e3,max:6e4}),y=Object.freeze({connect:1e4,headers:0}),p=Object.freeze({interval:1e4,timeout:2e3});function F(){return{failures:0,until:0,inflight:0,requests:0,errors:0,lastError:null,lastFailure:null,lastSuccess:null,ready:null,checkedAt:null,readyReason:null,unsupported:!1,checking:null}}i(F,"health");function j(t={}){const r=i(a=>new S(`pool: ${a}`,{code:"INVALID_CONFIG",status:500}),"bad");if(!t||typeof t!="object"||Array.isArray(t))throw r("must be an object");const e=t.strategy??"failover",s={...t.models};for(const[a,f]of[["strategy",e],...Object.entries(s).map(([x,O])=>[`models.${x}`,O])])if(!d.includes(f))throw r(`${a} must be one of ${d.join(", ")} (got ${JSON.stringify(f)})`);const o=t.backoff?.base??m.base,l=t.backoff?.max??m.max;if(!(Number.isFinite(o)&&o>0)||!(Number.isFinite(l)&&l>=o))throw r("backoff.base must be a positive number of ms and backoff.max at least backoff.base");const u=t.connectTimeout??y.connect,c=t.headersTimeout??y.headers,b=t.healthInterval??p.interval,h=t.healthTimeout??p.timeout,n={connectTimeout:u,headersTimeout:c,healthInterval:b,healthTimeout:h};for(const a of Object.keys(n)){const f=n[a];if(typeof f!="number"||!(Number.isFinite(f)&&f>=0))throw r(`${a} must be a number of ms, 0 or more (got ${JSON.stringify(f)})`)}return{strategy:e,backoff:{base:o,max:l},connectTimeout:u,headersTimeout:c,healthInterval:b,healthTimeout:h,models:s}}i(j,"normalize");function g(t,r){return t.health.until<=r&&t.health.ready!==!1}i(g,"available");function A(t,r,e,s,o,l=Date.now()){const u=t.pool.models[s]??t.pool.strategy,c=e.filter(n=>g(n,l)),b=e.filter(n=>!g(n,l)).sort((n,a)=>n.health.until-a.health.until);let h=c;if(u==="least_busy")h=[...c].sort((n,a)=>n.health.inflight-a.health.inflight);else if(u==="round_robin"&&c.length>0){const n=r.cursors.get(s)??0;o&&r.cursors.set(s,n+1);const a=n%c.length;h=[...c.slice(a),...c.slice(0,a)]}return[...h,...b]}i(A,"order");function E(t,r,e,s=Date.now()){const o=r.health;o.failures++,o.errors++,o.lastError=e,o.lastFailure=s;const{base:l,max:u}=t.pool.backoff;o.until=s+Math.min(u,l*2**Math.min(o.failures-1,30))}i(E,"failed");function I(t,r=Date.now()){const e=t.health;e.failures=0,e.until=0,e.lastSuccess=r,e.ready===!1&&(e.ready=!0)}i(I,"succeeded");function N(t,r=Date.now()){const e=t.health,s=i(l=>l===null?null:new Date(l).toISOString(),"iso"),o=e.until>r;return{healthy:!o&&e.ready!==!1,ready:e.ready,readyReason:e.ready===!1?e.readyReason:null,checkedAt:s(e.checkedAt),failures:e.failures,retryAt:o?s(e.until):null,inflight:e.inflight,requests:e.requests,errors:e.errors,lastError:e.lastError,lastFailure:s(e.lastFailure),lastSuccess:s(e.lastSuccess)}}i(N,"describe");export{m as BACKOFF,p as PROBES,d as STRATEGIES,y as TIMEOUTS,N as describe,E as failed,F as health,j as normalize,A as order,I as succeeded};
|
|
2
2
|
//# sourceMappingURL=pool.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=Object.defineProperty;var s=(e,t)=>f(e,"name",{value:t,configurable:!0});import{noEmptyTools as d}from"./normalize.mjs";const p={chat:"/v1/chat/completions",embeddings:"/v1/embeddings",models:"/v1/models"},c={chat:"/chat/completions",embeddings:"/embeddings",models:"/models"};function m(e){return/^grok-(3-mini|4|code)/.test(String(e))&&!/non-reasoning/.test(String(e))}s(m,"grokReasons");const l=Object.freeze({groq:{order:21,hosts:["api.groq.com"],root:"/openai",paths:p,settings:{reasoningField:"reasoning",maxTokensField:"max_completion_tokens",thinking:"none",thinkingBudget:!1,effort:!0,topK:!1,prefill:"none",streamUsage:!0,continuousUsage:!1},drop:["logprobs","top_logprobs","logit_bias"],dropName:!0},together:{order:22,hosts:["api.together.ai","api.together.xyz","us-api.together.ai"],paths:p,fields:["top_k","min_p","repetition_penalty"],settings:{reasoningField:"reasoning",reasoningRoundTrip:!0,maxTokensField:"max_tokens",thinking:"none",thinkingBudget:!1,effort:!0,topK:!0,prefill:"none",parallelToolCalls:!1,streamUsage:!1,continuousUsage:!1}},fireworks:{order:23,hosts:["api.fireworks.ai"],root:"/inference",paths:p,fields:["top_k","min_p","repetition_penalty"],settings:{reasoningField:"reasoning_content",reasoningRoundTrip:!0,maxTokensField:"max_tokens",thinking:"reasoning_effort",thinkingBudget:!1,effort:!0,topK:!0,prefill:"none",streamUsage:!0,continuousUsage:!1}},xai:{order:24,hosts:["api.x.ai"],paths:p,settings:{reasoningField:"reasoning_content",maxTokensField:"max_completion_tokens",thinking:"none",thinkingBudget:!1,effort:!0,topK:!1,prefill:"none",streamUsage:!0,continuousUsage:!1},dropWhen:s(e=>m(e.model)?["stop","presence_penalty","frequency_penalty"]:[],"dropWhen")},gemini:{order:25,hosts:["generativelanguage.googleapis.com"],root:"/v1beta/openai",paths:c,settings:{maxTokensField:"max_tokens",thinking:"none",thinkingBudget:!1,effort:!0,topK:!1,prefill:"none",streamUsage:!0,continuousUsage:!1}}});function _(e){const t=l[e],o={name:e,protocol:"openai.chat",order:t.order,auth:"bearer",strict:!1,paths:{...t.paths}};return t.fields?{...o,fields:[...t.fields]}:o}s(_,"describe");function x(e,t){const o=URL.canParse(t.url)?new URL(t.url).hostname:"";return l[e].hosts.includes(o)?{host:o}:null}s(x,"match");function U(e){return{...l[e].settings}}s(U,"settingsOf");function b(e,t,o){const i=l[e],a=i.root??"";return(o.url.endsWith(a)?"":a)+i.paths[t]}s(b,"route");function y(e,t,o){const i=l[e],a=o?.state?.dropped,g=s(n=>{Array.isArray(a)&&!a.includes(n)&&a.push(n)},"note"),r={...d(t)};for(const n of[...i.drop??[],...i.dropWhen?.(t)??[]])r[n]!==void 0&&(delete r[n],g(n));return i.dropName&&Array.isArray(r.messages)&&r.messages.some(n=>n&&"name"in n)&&(r.messages=r.messages.map(n=>{const u={...n};return delete u.name,u}),g("messages[].name")),r}s(y,"trim");export{l as PRESETS,_ as describe,x as match,b as route,U as settingsOf,y as trim};
|
|
2
|
+
//# sourceMappingURL=presets.mjs.map
|
package/dist/lib/route.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=Object.defineProperty;var u=(e,n)=>m(e,"name",{value:n,configurable:!0});import{TranslatorError as f}from"./errors.mjs";import{order as v}from"./pool.mjs";function
|
|
1
|
+
var m=Object.defineProperty;var u=(e,n)=>m(e,"name",{value:n,configurable:!0});import{TranslatorError as f}from"./errors.mjs";import{order as v}from"./pool.mjs";import{baseModels as h}from"./models.mjs";function w(e,n){return(e.models??e.facts?.models??[]).includes(n)?!0:e.protocol==="anthropic.messages"&&e.models===void 0&&/^claude-/.test(n)}u(w,"serves");function O(e,n,t,r,l=!1){const a=Object.hasOwn(e.aliases,t),o=a?e.aliases[t]:t,d=a&&Object.hasOwn(e.pins,t)?e.pins[t]:void 0,c=n.filter(s=>w(s,o)),i=n.find(s=>s.default)??n[0];if(c.length>0){const s=v(e,r,c,o,l);return{endpoint:s[0],model:o,unserved:!1,pool:s,pin:d}}const p=h(i);return p.length===1?{endpoint:i,model:p[0],unserved:!1,pool:[i],pin:d}:{endpoint:i,model:o,unserved:!0,pool:[i],pin:d}}u(O,"pick");function x(e,n,t={}){if(!n||typeof n!="object"||Array.isArray(n))throw new f("The request body must be a JSON object",{code:"invalid_body",status:400});const r=O(e.config,e.state.endpoints,n.model,e.state,t.advance===!0);if(t.endpoint!==void 0){const o=r.pool.find(d=>d.name===t.endpoint);if(!o)throw new f(`Endpoint ${t.endpoint} no longer serves ${r.model}`,{code:"endpoint_not_in_pool",status:500});return{endpoint:o,model:r.model,requested:n.model,unserved:r.unserved,pin:r.pin,convert:e.converters(o,n),pool:[o]}}const{endpoint:l,pool:a}=r;return{endpoint:l,model:r.model,requested:n.model,unserved:r.unserved,pin:r.pin,convert:e.converters(l,n),pool:a}}u(x,"resolve");export{O as pick,x as resolve,w as serves};
|
|
2
2
|
//# sourceMappingURL=route.mjs.map
|
package/dist/lib/settings.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var l=Object.defineProperty;var i=(
|
|
1
|
+
var l=Object.defineProperty;var i=(o,e)=>l(o,"name",{value:e,configurable:!0});import{TranslatorError as a}from"./errors.mjs";const r=Object.freeze({inlineSystem:"auto",stripBillingHeader:!0,reasoningField:"reasoning",thinkTags:!0,thinkOpen:!1,reasoningRoundTrip:!1,thinking:"chat_template_kwargs",thinkingBudget:!1,effort:!1,images:!0,imageFallback:!0,toolFallback:!1,documents:"extract",documentConverter:null,pdf:Object.freeze({pages:!0,maxPages:100,maxBytes:32*1024*1024,maxImages:20,scale:1.5}),toolSchema:"pass",deferredTools:"forward",toolSearch:"expand",jsonObject:"schema",jsonObjectFallback:!0,toolErrors:!1,toolErrorMarker:"[error] ",toolErrorInference:!1,maxTokensField:"max_completion_tokens",streamUsage:!0,continuousUsage:!1,prefill:"continue_final_message",topK:!0,responseFormat:!0,parallelToolCalls:!0,unknownFields:"drop",sampling:Object.freeze({}),pingInterval:1e4,toolStreaming:"buffer",effortPassthrough:!1,passthroughFilter:!1,nativeMessages:!1,contextWindow:0,defaultMaxTokens:8192}),f={inlineSystem:["auto","keep","hoist","user","drop"],reasoningField:["reasoning","reasoning_content"],thinking:["chat_template_kwargs","reasoning_effort","none"],documents:["extract","note","error"],toolSchema:["pass","sanitize"],deferredTools:["forward","drop"],toolSearch:["expand","inline","native"],jsonObject:["schema","instruction","drop"],maxTokensField:["max_completion_tokens","max_tokens"],prefill:["continue_final_message","none"],unknownFields:["drop","error"],toolStreaming:["buffer","stream"]},d=["effortPassthrough","passthroughFilter","imageFallback","toolFallback","jsonObjectFallback","thinkOpen","reasoningRoundTrip","toolErrorInference"];function p(...o){const e={...r,pdf:{...r.pdf},sampling:{...r.sampling}};for(const t of o)if(t)for(const[n,s]of Object.entries(t))s!==void 0&&(n==="pdf"?Object.assign(e.pdf,s):n==="sampling"&&s!==null&&typeof s=="object"&&!Array.isArray(s)?Object.assign(e.sampling,s):e[n]=s);for(const[t,n]of Object.entries(f))if(!n.includes(e[t]))throw new a(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected one of ${n.join(", ")})`,{code:"invalid_setting",status:500,details:{key:t,allowed:n}});for(const t of d)if(typeof e[t]!="boolean")throw new a(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected true or false)`,{code:"invalid_setting",status:500,details:{key:t}});if(e.nativeMessages!==!0&&e.nativeMessages!==!1&&e.nativeMessages!=="auto")throw new a(`Invalid setting nativeMessages: ${JSON.stringify(e.nativeMessages)} (expected true, false or "auto")`,{code:"invalid_setting",status:500,details:{key:"nativeMessages"}});if(typeof e.toolErrorMarker!="string"||e.toolErrorMarker.trim()==="")throw new a(`Invalid setting toolErrorMarker: ${JSON.stringify(e.toolErrorMarker)} (expected a non-empty string)`,{code:"invalid_setting",status:500,details:{key:"toolErrorMarker"}});if(e.sampling===null||typeof e.sampling!="object"||Array.isArray(e.sampling))throw new a(`Invalid setting sampling: ${JSON.stringify(e.sampling)} (expected an object of field names and values)`,{code:"invalid_setting",status:500,details:{key:"sampling"}});if(!(Number.isFinite(e.pdf.scale)&&e.pdf.scale>0))throw new a(`Invalid setting pdf.scale: ${JSON.stringify(e.pdf.scale)} (expected a positive number)`,{code:"invalid_setting",status:500,details:{key:"pdf.scale"}});return e}i(p,"resolve");export{r as DEFAULTS,p as resolve};
|
|
2
2
|
//# sourceMappingURL=settings.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
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var c=Object.defineProperty;var s=(t,r)=>c(t,"name",{value:r,configurable:!0});import{atLeast as f,semver as l}from"./normalize.mjs";import{sign as a}from"./thinking.mjs";const u="0.11.1",y="x-anthropic-billing-header:";function A(t,r){if(t.driver!=="vllm"||r.nativeMessages===!1)return!1;if(r.nativeMessages===!0)return!0;const n=t.facts?.version??t.version;return l(n)!==null&&f(n,u)}s(A,"wants");function*p(t){for(const r of t)if(Array.isArray(r?.content))for(const n of r.content)yield n,n?.type==="tool_result"&&Array.isArray(n.content)&&(yield*n.content)}s(p,"blocks");function v(t,r){const n=Array.isArray(t.messages)?t.messages:[];if(n.at(-1)?.role==="assistant")return"prefill";const e=[...p(n)];return e.some(o=>o?.type==="document")?"document":r.toolSearch!=="native"&&(Array.isArray(t.tools)&&t.tools.some(i=>i?.defer_loading!==void 0)||e.some(i=>["tool_reference","tool_addition","tool_removal"].includes(i?.type)))?"toolsearch":null}s(v,"unsuited");function d(t,r){return(typeof t=="string"?[{type:"text",text:t}]:t).filter(e=>e?.type==="text"&&typeof e.text=="string").filter(e=>!(r.stripBillingHeader&&e.text.trimStart().startsWith(y))).map(e=>e.text).join(`
|
|
2
|
+
|
|
3
|
+
`)}s(d,"systemText");function m(t,r){const n=r.toolErrorMarker;return typeof t.content=="string"?{...t,content:`${n}${t.content}`}:Array.isArray(t.content)?{...t,content:[{type:"text",text:n.trimEnd()},...t.content]}:{...t,content:n.trimEnd()}}s(m,"marked");function h(t,r){const n={...t};if(n.system!==void 0&&n.system!==null){const e=d(n.system,r);e===""?delete n.system:n.system=e}return r.toolErrors&&Array.isArray(n.messages)&&(n.messages=n.messages.map(e=>Array.isArray(e?.content)?{...e,content:e.content.map(o=>o?.type==="tool_result"&&o.is_error===!0?m(o,r):o)}:e)),n}s(h,"request");function E(t){return Array.isArray(t?.content)?{...t,content:t.content.map(r=>r?.type==="thinking"&&typeof r.signature!="string"?{...r,signature:a()}:r)}:t}s(E,"response");async function*M(t){const r=new Map;for await(const n of t){const e=n.data;e?.type==="content_block_start"&&e.content_block?.type==="thinking"?r.set(e.index,typeof e.content_block.signature=="string"):e?.type==="content_block_delta"&&e.delta?.type==="signature_delta"?r.set(e.index,!0):e?.type==="content_block_stop"&&r.get(e.index)===!1&&(yield{event:"content_block_delta",data:{type:"content_block_delta",index:e.index,delta:{type:"signature_delta",signature:a()}}}),e?.type==="content_block_stop"&&r.delete(e.index),yield n,e?.type==="message_start"&&(yield{event:"ping",data:{type:"ping"}})}}s(M,"stream");export{u as MIN_VERSION,h as request,E as response,M as stream,v as unsuited,A as wants};
|
|
4
|
+
//# sourceMappingURL=vllm.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/llm-translator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an Anthropic Messages request to an Ollama `/api/chat` body. The Anthropic conversion to Chat Completions does the work (system, tool
|
|
3
|
+
* blocks, images, tool names, dropped fields); `chatBody` then puts the result in Ollama's shape: tool arguments as objects, tool results by tool
|
|
4
|
+
* name, `images` as base64, the sampling fields and `max_tokens` in `options`, `thinking` and `output_config.effort` as `think`, and
|
|
5
|
+
* `output_config.format` as `format`. The upstream's `sampling` setting and `metadata.sampling` become further `options`.
|
|
6
|
+
* @param {any} body - Anthropic request body.
|
|
7
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
8
|
+
* @param {any} [context] - `{ producer, budget, listed, toolCallIds }`, as for the Chat Completions conversion.
|
|
9
|
+
* @returns {Promise<{body: any, state: any}>} The Ollama body and the conversion state the response converters read.
|
|
10
|
+
*/
|
|
11
|
+
export function request(body: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>, context?: any): Promise<{
|
|
12
|
+
body: any;
|
|
13
|
+
state: any;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an Ollama reply to an Anthropic message: the reply is read as a Chat Completions `chat.completion` (thinking, tool calls with generated
|
|
3
|
+
* ids, `done_reason` as `finish_reason`, the evaluation counts as `usage`) and the Chat Completions conversion builds the message.
|
|
4
|
+
* @param {any} reply - Parsed Ollama reply.
|
|
5
|
+
* @param {any} [state] - State from the request converter.
|
|
6
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
7
|
+
* @returns {any} Anthropic message.
|
|
8
|
+
* @throws {import("../../../../../../../lib/errors.mjs").TranslatorError} When the reply is an error.
|
|
9
|
+
*/
|
|
10
|
+
export function response(reply: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an Ollama stream (one JSON object per line, possibly split anywhere across chunks) to Anthropic events. The lines become Chat
|
|
3
|
+
* Completions chunks (one id for the reply, tool calls whole with generated ids, the final line as the finish and usage chunks) and the Chat
|
|
4
|
+
* Completions conversion writes the events. A line that is not JSON, an `{ error }` line and a stream that ends before its final line each
|
|
5
|
+
* end the stream with an `error` event.
|
|
6
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array} source - Ollama NDJSON bytes or text.
|
|
7
|
+
* @param {any} [state] - State from the request converter.
|
|
8
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
9
|
+
* @returns {AsyncGenerator<{ event: string, data: any }, void, undefined>} Anthropic events.
|
|
10
|
+
*/
|
|
11
|
+
export function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
12
|
+
event: string;
|
|
13
|
+
data: any;
|
|
14
|
+
}, void, undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an Ollama reply to a Chat Completions `chat.completion` (see `completion`). The model name is the one the client asked for, and the
|
|
3
|
+
* counts are kept on the state for the usage report.
|
|
4
|
+
* @param {any} reply - Parsed Ollama reply.
|
|
5
|
+
* @param {any} [state] - State from the request converter.
|
|
6
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
7
|
+
* @returns {any} `chat.completion` object.
|
|
8
|
+
* @throws {import("../../../../../../../lib/errors.mjs").TranslatorError} When the reply is an error.
|
|
9
|
+
*/
|
|
10
|
+
export function response(reply: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an Ollama stream (one JSON object per line, possibly split anywhere across chunks) to Chat Completions chunks followed by `[DONE]`.
|
|
3
|
+
* Every chunk carries one completion id, tool calls come whole with generated ids, and the final line gives the finish chunk and, unless
|
|
4
|
+
* `state.includeUsage` is false, a usage chunk. A line that is not JSON, an `{ error }` line and a stream that ends before its final line
|
|
5
|
+
* each become an `{ error }` chunk followed by `[DONE]`.
|
|
6
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array} source - Ollama NDJSON bytes or text.
|
|
7
|
+
* @param {any} [state] - State from the request converter (model, `includeUsage`).
|
|
8
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
9
|
+
* @returns {AsyncGenerator<{ data: any|string }, void, undefined>} Chat Completions chunks.
|
|
10
|
+
*/
|
|
11
|
+
export function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
12
|
+
data: any | string;
|
|
13
|
+
}, void, undefined>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Chat Completions request to an Ollama `/api/chat` body (see `chatBody`). A client may also send Ollama's own `think`, `options`,
|
|
3
|
+
* `format` and `keep_alive`; they are used as sent. The upstream's `sampling` setting fills in `options` fields the request does not name.
|
|
4
|
+
* @param {any} body - Chat Completions request body.
|
|
5
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
6
|
+
* @returns {{body: any, state: any}} The Ollama body and the conversion state the response converters read.
|
|
7
|
+
* @throws {TranslatorError} `invalid_request` when `messages` is missing.
|
|
8
|
+
*/
|
|
9
|
+
export function request(body: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): {
|
|
10
|
+
body: any;
|
|
11
|
+
state: any;
|
|
12
|
+
};
|
|
@@ -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;
|