@cldmv/llm-translator 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/api/convert/anthropic/messages/to/openai/responses/request.mjs +2 -0
- package/dist/api/convert/openai/chat/to/openai/responses/request.mjs +2 -0
- package/dist/api/convert/openai/chat/to/openai/responses/response.mjs +2 -0
- package/dist/api/convert/openai/chat/to/openai/responses/stream.mjs +2 -0
- package/dist/api/convert/openai/responses/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/openai/responses/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/convert/openai/responses/to/openai/chat/request.mjs +6 -0
- package/dist/api/convert/openai/responses/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/openai/responses/to/openai/chat/stream.mjs +2 -0
- package/dist/api/detect.mjs +1 -1
- package/dist/api/driver/anthropic/info.mjs +1 -1
- package/dist/api/driver/azure/info.mjs +1 -1
- package/dist/api/driver/compatible/info.mjs +1 -1
- package/dist/api/driver/deepseek/info.mjs +1 -1
- package/dist/api/driver/llamacpp/info.mjs +1 -1
- package/dist/api/driver/lmstudio/info.mjs +1 -1
- package/dist/api/driver/localai/info.mjs +1 -1
- package/dist/api/driver/mistral/info.mjs +1 -1
- package/dist/api/driver/ollama/info.mjs +1 -1
- package/dist/api/driver/ollama/request.mjs +1 -1
- package/dist/api/driver/openai/info.mjs +1 -1
- package/dist/api/driver/openrouter/info.mjs +1 -1
- package/dist/api/driver/sglang/info.mjs +1 -1
- package/dist/api/driver/tgi/info.mjs +1 -1
- package/dist/api/driver/vllm/info.mjs +1 -1
- package/dist/api/request.mjs +2 -2
- package/dist/api/response.mjs +1 -1
- package/dist/api/route.mjs +1 -1
- package/dist/api/send.mjs +1 -1
- package/dist/api/server/plugin.mjs +1 -1
- package/dist/api/status.mjs +1 -1
- package/dist/api/stream.mjs +1 -1
- package/dist/api/token/count.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/config.mjs +1 -1
- package/dist/lib/estimate.mjs +1 -1
- package/dist/lib/http.mjs +1 -1
- package/dist/lib/presets.mjs +1 -1
- package/dist/lib/protocol.mjs +2 -0
- package/dist/lib/responses-upstream.mjs +13 -0
- package/dist/lib/responses.mjs +2 -0
- package/dist/lib/route.mjs +1 -1
- package/dist/lib/routes.mjs +1 -1
- package/dist/lib/settings.mjs +1 -1
- package/dist/lib/vllm.mjs +2 -2
- package/package.json +1 -1
- package/types/src/api/convert/anthropic/messages/to/openai/responses/request.d.mts +16 -0
- package/types/src/api/convert/openai/chat/to/openai/responses/request.d.mts +12 -0
- package/types/src/api/convert/openai/chat/to/openai/responses/response.d.mts +14 -0
- package/types/src/api/convert/openai/chat/to/openai/responses/stream.d.mts +18 -0
- package/types/src/api/convert/openai/responses/to/anthropic/messages/response.d.mts +8 -0
- package/types/src/api/convert/openai/responses/to/anthropic/messages/stream.d.mts +8 -0
- package/types/src/api/convert/openai/responses/to/openai/chat/request.d.mts +17 -0
- package/types/src/api/convert/openai/responses/to/openai/chat/response.d.mts +8 -0
- package/types/src/api/convert/openai/responses/to/openai/chat/stream.d.mts +10 -0
- package/types/src/api/driver/anthropic/info.d.mts +2 -1
- package/types/src/api/driver/azure/info.d.mts +2 -1
- package/types/src/api/driver/compatible/info.d.mts +2 -1
- package/types/src/api/driver/deepseek/info.d.mts +2 -1
- package/types/src/api/driver/fireworks/info.d.mts +2 -1
- package/types/src/api/driver/gemini/info.d.mts +2 -1
- package/types/src/api/driver/groq/info.d.mts +2 -1
- package/types/src/api/driver/llamacpp/info.d.mts +2 -1
- package/types/src/api/driver/lmstudio/info.d.mts +2 -1
- package/types/src/api/driver/localai/info.d.mts +2 -1
- package/types/src/api/driver/mistral/info.d.mts +2 -1
- package/types/src/api/driver/ollama/info.d.mts +2 -1
- package/types/src/api/driver/ollama/request.d.mts +1 -1
- package/types/src/api/driver/openai/info.d.mts +2 -1
- package/types/src/api/driver/openrouter/info.d.mts +2 -1
- package/types/src/api/driver/sglang/info.d.mts +2 -1
- package/types/src/api/driver/tgi/info.d.mts +2 -1
- package/types/src/api/driver/together/info.d.mts +2 -1
- package/types/src/api/driver/vllm/info.d.mts +2 -1
- package/types/src/api/driver/xai/info.d.mts +2 -1
- package/types/src/api/request.d.mts +3 -2
- package/types/src/api/route.d.mts +2 -2
- package/types/src/api/send.d.mts +1 -1
- package/types/src/api/server/plugin.d.mts +1 -1
- package/types/src/api/status.d.mts +1 -1
- package/types/src/lib/config.d.mts +4 -3
- package/types/src/lib/estimate.d.mts +1 -1
- package/types/src/lib/http.d.mts +4 -3
- package/types/src/lib/presets.d.mts +2 -1
- package/types/src/lib/protocol.d.mts +84 -0
- package/types/src/lib/responses-upstream.d.mts +58 -0
- package/types/src/lib/responses.d.mts +72 -0
- package/types/src/lib/route.d.mts +7 -3
- package/types/src/lib/routes.d.mts +2 -1
- package/types/src/lib/settings.d.mts +7 -2
- package/types/src/lib/vllm.d.mts +4 -4
package/dist/lib/http.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=Object.defineProperty;var r=(t,e)=>l(t,"name",{value:e,configurable:!0});function p(t,e){return t+e}r(p,"join");async function m(t,e,a,n,s){return t.path?t.path(e,{endpoint:a,model:n}):(t.info.native!==void 0&&s===t.info.native.protocol?t.info.native.paths:void 0)?.[e]??t.info.paths[e]??y[e]}r(m,"pathOf");const y={responses:"/v1/responses",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},f,i){const u=i!==void 0&&(i.auth==="x-api-key"||i.auth==="api-key"||i.headers!==void 0),o=u?{auth:i.auth,extra:i.headers}:{},h=r(()=>g(e,p(t.url,f),{method:"GET",headers:d(t,o.auth,o.extra),signal:a,timeout:n}),"run");if(!s)return h();const c=u?JSON.stringify([f,o.auth,o.extra]):f;return s.has(c)||s.set(c,h()),s.get(c)}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:f,...i}=a,u=[];s&&u.push(s),n>0&&u.push(AbortSignal.timeout(n));try{const o=await t(e,{...i,redirect:"error",body:f===void 0?void 0:JSON.stringify(f),signal:u.length>1?AbortSignal.any(u):u[0]}),h=await o.text();let c=null;try{c=JSON.parse(h)}catch{c=h===""?null:h}return{ok:o.ok,status:o.status,body:c,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,p as join,g as json,m as pathOf,x as plain,S as probe};
|
|
2
2
|
//# sourceMappingURL=http.mjs.map
|
package/dist/lib/presets.mjs
CHANGED
|
@@ -1,2 +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],
|
|
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],n={name:e,protocol:"openai.chat",protocols:["openai.chat"],order:t.order,auth:"bearer",strict:!1,hosts:[...t.hosts],paths:{...t.paths}};return t.fields?{...n,fields:[...t.fields]}:n}s(_,"describe");function x(e,t){const n=URL.canParse(t.url)?new URL(t.url).hostname:"";return l[e].hosts.includes(n)?{host:n}:null}s(x,"match");function U(e){return{...l[e].settings}}s(U,"settingsOf");function b(e,t,n){const i=l[e],a=i.root??"";return(n.url.endsWith(a)?"":a)+i.paths[t]}s(b,"route");function y(e,t,n){const i=l[e],a=n?.state?.dropped,g=s(o=>{Array.isArray(a)&&!a.includes(o)&&a.push(o)},"note"),r={...d(t)};for(const o of[...i.drop??[],...i.dropWhen?.(t)??[]])r[o]!==void 0&&(delete r[o],g(o));return i.dropName&&Array.isArray(r.messages)&&r.messages.some(o=>o&&"name"in o)&&(r.messages=r.messages.map(o=>{const u={...o};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
2
|
//# sourceMappingURL=presets.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g=Object.defineProperty;var r=(t,e)=>g(t,"name",{value:e,configurable:!0});const n="anthropic.messages",o="openai.chat",s="openai.responses",i="ollama.chat",O=[n,o,s,i],h=Object.freeze({auto:"auto",[n]:n,messages:n,anthropic:n,claude:n,[o]:o,chat:o,openai:o,chatgpt:o,[s]:s,responses:s,codex:s,[i]:i,native:i,ollama:i});function w(t){return typeof t=="string"&&Object.hasOwn(h,t.toLowerCase())?h[t.toLowerCase()]:void 0}r(w,"canonical");function A(t){const e=[...Array.isArray(t.protocols)?t.protocols:[]];return t.protocol!==void 0&&e.push(t.protocol),t.responses===!0&&e.push(s),t.native?.protocol!==void 0&&e.push(t.native.protocol),[...new Set(e)]}r(A,"supported");function E(t,e){return t==="anthropic"?n:e==="responses"?s:o}r(E,"frontOf");function L({api:t,front:e,info:p,missing:l,usable:a}){const x=A(p),u=r(c=>x.includes(c)&&(a?a(c):!0),"ok");if(t!=="auto")return[u(t)?t:p.protocol];const d=[e,o].filter((c,f,S)=>S.indexOf(c)===f&&u(c)&&!l?.has(c));return d.length>0?d:[p.protocol]}r(L,"candidates");function y(t,e,p){t.missing.has(e)||t.missing.set(e,new Set),t.missing.get(e).add(p)}r(y,"remember");export{h as ALIASES,o as CHAT,O as IDS,n as MESSAGES,i as OLLAMA,s as RESPONSES,L as candidates,w as canonical,E as frontOf,y as remember,A as supported};
|
|
2
|
+
//# sourceMappingURL=protocol.mjs.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var q=Object.defineProperty;var u=(e,o)=>q(e,"name",{value:o,configurable:!0});import{resolve as D}from"./settings.mjs";import{TranslatorError as b}from"./errors.mjs";import{completionId as U}from"./ids.mjs";import{messages as C}from"./sse.mjs";const Y="openai.responses",Z=[404,405,501],E="openai-responses-v1",L=new Set(["model","messages","stream","stream_options","max_tokens","max_completion_tokens","temperature","top_p","tools","tool_choice","parallel_tool_calls","reasoning_effort","response_format","user","n","metadata","store","service_tier","prompt_cache_key","safety_identifier","verbosity"]);function w(e,o){e.dropped.includes(o)||e.dropped.push(o)}u(w,"drop");function F(e){return typeof e=="string"?e:(Array.isArray(e)?e:[]).filter(o=>o?.type==="text").map(o=>o.text).join(`
|
|
2
|
+
|
|
3
|
+
`)}u(F,"plainText");function S(e,o){const n=[];for(const t of e)if(t?.type==="text")n.push({type:"input_text",text:t.text});else if(t?.type==="image_url"){const s=typeof t.image_url=="string"?{url:t.image_url}:t.image_url;n.push({type:"input_image",image_url:s.url,...s.detail===void 0?{}:{detail:s.detail}})}else if(t?.type==="file"&&t.file!==null&&typeof t.file=="object"){const{file_id:s,file_data:i,filename:r}=t.file;n.push({type:"input_file",...s===void 0?{}:{file_id:s},...i===void 0?{}:{file_data:i},...r===void 0?{}:{filename:r}})}else w(o,`content:${t?.type}`);return n}u(S,"inputParts");function P(e,o){if(typeof e=="string")return e;const n=Array.isArray(e)?e:[];return n.every(t=>t?.type==="text")?n.map(t=>t.text).join(`
|
|
4
|
+
`):S(n,o)}u(P,"toolOutput");function z(e){if(!Array.isArray(e.reasoning_details))return[];const o=[];for(const n of e.reasoning_details){if(n?.format!==E||typeof n.data!="string"||n.data==="")continue;const t={type:"reasoning",summary:[],encrypted_content:n.data};typeof n.id=="string"&&n.id!==""&&(t.id=n.id),typeof n.summary=="string"&&n.summary!==""&&(t.summary=[{type:"summary_text",text:n.summary}]),o.push({at:Number.isInteger(n.index)&&n.index>=0?n.index:0,item:t})}return o}u(z,"reasoningItems");function G(e,o,n){const t=[];let s=F(e.content);s===""&&typeof e.refusal=="string"&&(s=e.refusal),s!==""&&t.push({role:"assistant",content:s});for(const l of e.tool_calls??[]){if(l?.type!==void 0&&l.type!=="function"){w(o,`tool_call:${l.type}`);continue}const f=l.function?.arguments;t.push({type:"function_call",call_id:l.id,name:l.function?.name,arguments:typeof f=="string"?f:"{}"})}if(!n)return t;const i=[],r=z(e).sort((l,f)=>l.at-f.at);t.forEach((l,f)=>{for(;r.length>0&&r[0].at<=f;)i.push(r.shift().item);i.push(l)});for(const{item:l}of r)i.push(l);return i}u(G,"assistantItems");function H(e,o,n){const t=[],s=[];for(const i of e)switch(i?.role){case"system":case"developer":{const r=F(i.content);if(r==="")break;t.length===0?s.push(r):t.push({role:"system",content:r});break}case"user":t.push({role:"user",content:typeof i.content=="string"?i.content:S(i.content??[],o)});break;case"assistant":t.push(...G(i,o,n));break;case"tool":t.push({type:"function_call_output",call_id:i.tool_call_id,output:P(i.content,o)});break;default:throw new b(`messages: unsupported role "${i?.role}"`,{code:"invalid_request",param:"messages"})}return{input:t,instructions:s.join(`
|
|
5
|
+
|
|
6
|
+
`)}}u(H,"convertMessages");function I(e,o){const n=[];for(const t of e)if(t?.type==="function"&&t.function){const s=t.function;n.push({type:"function",name:s.name,...s.description===void 0?{}:{description:s.description},parameters:s.parameters??{type:"object",properties:{}},strict:s.strict===!0})}else if(t?.type==="custom"&&t.custom){const{name:s,description:i,format:r}=t.custom;n.push({type:"custom",name:s,...i===void 0?{}:{description:i},...r===void 0?{}:{format:r}})}else w(o,`tool:${t?.type}`);return n}u(I,"convertTools");function B(e,o){if(typeof e=="string")return e;if(e?.type==="function"&&e.function)return{type:"function",name:e.function.name};if(e?.type==="custom"&&e.custom)return{type:"custom",name:e.custom.name};if(e?.type==="allowed_tools"&&e.allowed_tools){const n=I(e.allowed_tools.tools??[],o).map(t=>({type:t.type,name:t.name}));return{type:"allowed_tools",mode:e.allowed_tools.mode,tools:n}}w(o,"tool_choice")}u(B,"convertChoice");function J(e,o,n){const t={},s=e.response_format;if(s!==void 0)if(!o.responseFormat)w(n,"response_format");else if(s.type==="json_schema"&&s.json_schema){const{name:i,schema:r,strict:l,description:f}=s.json_schema;t.format={type:"json_schema",name:i??"output",schema:r,...l===void 0?{}:{strict:l},...f===void 0?{}:{description:f}}}else s.type==="json_object"?t.format={type:"json_object"}:s.type==="text"?t.format={type:"text"}:w(n,"response_format");return e.verbosity!==void 0&&(t.verbosity=e.verbosity),Object.keys(t).length>0?t:void 0}u(J,"textOf");function ee(e,o){const n=D(o);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new b("messages is a required property",{code:"invalid_request",param:"messages"});if(e.n!==void 0&&e.n!==1)throw new b("n: only a single choice (n = 1) is supported",{code:"unsupported_field",param:"n"});const t={front:"openai",model:e.model,stream:e.stream===!0,includeUsage:e.stream_options?.include_usage===!0,reasoningField:n.reasoningField,toolNames:{},toolIds:{},dropped:[]};for(const m of Object.keys(e))if(!L.has(m)){if(n.unknownFields==="error")throw new b(`${m}: Unrecognized request argument`,{code:"unsupported_field",param:m});w(t,m)}const{input:s,instructions:i}=H(e.messages,t,n.reasoningRoundTrip),r={model:e.model,input:s};i!==""&&(r.instructions=i),t.stream&&(r.stream=!0),r.store=!1,n.reasoningRoundTrip&&(r.include=["reasoning.encrypted_content"]);const l=e.max_completion_tokens??e.max_tokens;l!==void 0&&(r.max_output_tokens=l);for(const m of["temperature","top_p","user","metadata","service_tier","prompt_cache_key","safety_identifier"])e[m]!==void 0&&(r[m]=e[m]);const f=I(e.tools??[],t);if(f.length>0){r.tools=f;const m=e.tool_choice===void 0?void 0:B(e.tool_choice,t);m!==void 0&&(r.tool_choice=m),e.parallel_tool_calls!==void 0&&n.parallelToolCalls&&(r.parallel_tool_calls=e.parallel_tool_calls)}typeof e.reasoning_effort=="string"&&(r.reasoning={effort:e.reasoning_effort},e.reasoning_effort!=="none"&&n.reasoningSummary!=="none"&&(r.reasoning.summary=n.reasoningSummary));const x=J(e,n,t);return x&&(r.text=x),{body:r,state:t}}u(ee,"request");function A(e){const o=u((n,t)=>(Array.isArray(n)?n:[]).filter(s=>s?.type===t&&typeof s.text=="string").map(s=>s.text).join(`
|
|
7
|
+
|
|
8
|
+
`),"pick");return o(e.summary,"summary_text")||o(e.content,"reasoning_text")}u(A,"reasoningText");function $(e,o){if(typeof e.encrypted_content!="string"||e.encrypted_content==="")return null;const n={type:"reasoning.encrypted",data:e.encrypted_content,format:E,index:o};typeof e.id=="string"&&e.id!==""&&(n.id=e.id);const t=A(e);return t!==""&&(n.summary=t),n}u($,"detailOf");function M(e){if(e===null||typeof e!="object")return;const o=e.input_tokens??0,n=e.output_tokens??0,t={prompt_tokens:o,completion_tokens:n,total_tokens:e.total_tokens??o+n},s=e.input_tokens_details?.cached_tokens;typeof s=="number"&&(t.prompt_tokens_details={cached_tokens:s});const i=e.output_tokens_details?.reasoning_tokens;return typeof i=="number"&&(t.completion_tokens_details={reasoning_tokens:i}),t}u(M,"usageOf");function R(e,o){if(e.status==="incomplete"){const n=e.incomplete_details?.reason;if(n==="max_output_tokens")return"length";if(n==="content_filter")return"content_filter"}return o?"tool_calls":"stop"}u(R,"finishOf");function N(e){if(e.status==="completed"||e.status==="incomplete")return null;const o=e.error?.message??`Upstream response ended with status "${e.status}"`;return new b(o,{code:"upstream_"+(e.error?.code??"failed"),status:502,type:"api_error"})}u(N,"failureOf");function te(e,o,n){const t=D(n);if(e===null||typeof e!="object"||!Array.isArray(e.output))throw(e?.error?N({status:"failed",error:e.error}):null)??new b("Upstream response contained no output",{code:"invalid_upstream_response",status:502});const s=N(e);if(s)throw s;const i=[],r=[],l=[],f=[],x=[];let m=!1;for(const c of e.output)if(c?.type==="reasoning"){const y=A(c);y!==""&&l.push(y);const j=t.reasoningRoundTrip?$(c,f.length+(m?1:0)):null;j&&x.push(j)}else if(c?.type==="message")for(const y of c.content??[])y?.type==="output_text"&&typeof y.text=="string"?(i.push(y.text),y.text!==""&&(m=!0)):y?.type==="refusal"&&typeof y.refusal=="string"&&r.push(y.refusal);else c?.type==="function_call"&&f.push({id:c.call_id??c.id,type:"function",function:{name:c.name,arguments:typeof c.arguments=="string"?c.arguments:"{}"}});const h={role:"assistant",content:i.length===0&&f.length>0?null:i.join("")};r.length>0&&(h.refusal=r.join("")),l.length>0&&(h[t.reasoningField]=l.join(`
|
|
9
|
+
|
|
10
|
+
`)),x.length>0&&(h.reasoning_details=x),f.length>0&&(h.tool_calls=f);const _=M(e.usage);return o&&_&&(o.upstreamUsage=_),{id:`chatcmpl-${String(e.id??"").replace(/^resp_/,"")||U().slice(9)}`,object:"chat.completion",created:e.created_at??Math.floor(Date.now()/1e3),model:o?.model??e.model,choices:[{index:0,message:h,finish_reason:R(e,f.length>0)}],..._?{usage:_}:{}}}u(te,"response");const T=u((e,o="server_error",n=null)=>({data:{error:{message:e,type:o,param:null,code:n}}}),"failureChunk");async function*ne(e,o,n){const t=D(n),s=o?.includeUsage??!0,i=Math.floor(Date.now()/1e3);let r=U(),l=o?.model;const f=new Map;let x=0,m=!1,h=null;const _=u((a,p=null)=>({data:{id:r,object:"chat.completion.chunk",created:i,model:l,choices:[{index:0,delta:a,finish_reason:p}]}}),"chunk"),c=u(a=>(f.has(a)||f.set(a,{tool:null,streamed:!1,parts:0}),f.get(a)),"entry");function*y(a,p){const g=c(a);g.tool===null&&(g.tool=x++,yield _({tool_calls:[{index:g.tool,id:p.call_id??p.id,type:"function",function:{name:p.name,arguments:""}}]}))}u(y,"start");function*j(a){a!==""&&(m=!0,yield _({content:a}))}u(j,"text");try{for await(const{data:a}of C(e)){if(a==="[DONE]")break;const p=a?.type,g=a?.output_index??0;if(p==="response.created")r=`chatcmpl-${String(a.response?.id??"").replace(/^resp_/,"")||r.slice(9)}`,l=o?.model??a.response?.model,yield _({role:"assistant",content:""});else if(p==="response.output_item.added"&&a.item?.type==="function_call")yield*y(g,a.item);else if(p==="response.output_text.delta")c(g).streamed=!0,yield*j(a.delta??"");else if(p==="response.refusal.delta")c(g).streamed=!0,yield _({refusal:a.delta??""});else if(p==="response.reasoning_summary_part.added"){const d=c(g);d.parts++>0&&(yield _({[t.reasoningField]:`
|
|
11
|
+
|
|
12
|
+
`}))}else if(p==="response.reasoning_summary_text.delta"||p==="response.reasoning_text.delta")c(g).streamed=!0,yield _({[t.reasoningField]:a.delta??""});else if(p==="response.function_call_arguments.delta"){const d=c(g);d.streamed=!0,d.tool!==null&&(yield _({tool_calls:[{index:d.tool,function:{arguments:a.delta??""}}]}))}else if(p==="response.output_item.done"){const d=a.item??{},O=c(g);if(d.type==="reasoning"){!O.streamed&&A(d)!==""&&(yield _({[t.reasoningField]:A(d)}));const k=t.reasoningRoundTrip?$(d,x+(m?1:0)):null;k&&(yield _({reasoning_details:[k]}))}else if(d.type==="message"){if(!O.streamed)for(const k of d.content??[])k?.type==="output_text"?yield*j(k.text??""):k?.type==="refusal"&&(yield _({refusal:k.refusal??""}))}else d.type==="function_call"&&(yield*y(g,d),!O.streamed&&typeof d.arguments=="string"&&d.arguments!==""&&(yield _({tool_calls:[{index:O.tool,function:{arguments:d.arguments}}]})))}else if(p==="response.completed"||p==="response.incomplete"){h=a.response??{};break}else if(p==="response.failed"){const d=N({...a.response,status:"failed"});yield T(d.message,"server_error",d.code),yield{data:"[DONE]"};return}else if(p==="error"){yield T(a.message??"Upstream error","server_error",a.code??null),yield{data:"[DONE]"};return}}}catch(a){yield T(a.message),yield{data:"[DONE]"};return}if(h===null){yield T("Upstream stream ended before completion"),yield{data:"[DONE]"};return}const v=M(h.usage);o&&v&&(o.upstreamUsage=v),yield _({},R(h,x>0)),s&&(yield{data:{id:r,object:"chat.completion.chunk",created:i,model:l,choices:[],...v?{usage:v}:{}}}),yield{data:"[DONE]"}}u(ne,"stream");export{E as FORMAT,Z as MISSING,Y as PROTOCOL,ee as request,te as response,ne as stream,M as usageOf};
|
|
13
|
+
//# sourceMappingURL=responses-upstream.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var n=(t,e)=>s(t,"name",{value:e,configurable:!0});import{randomBytes as u}from"node:crypto";const l="llmt-rs1:",i=64,c=1024*1024;function a(t){return`${t}_${u(12).toString("hex")}`}n(a,"itemId");function f(t){if(!(!Array.isArray(t)||t.length===0))return l+Buffer.from(JSON.stringify(t)).toString("base64url")}n(f,"pack");function d(t){if(typeof t!="string"||!t.startsWith(l)||t.length>c*2)return null;try{const e=JSON.parse(Buffer.from(t.slice(l.length),"base64url").toString("utf8")),o=n(r=>r!==null&&typeof r=="object"&&!Array.isArray(r),"plain");return Array.isArray(e)&&e.length<=i&&e.every(o)?e:null}catch{return null}}n(d,"unpack");function m(t){if(t===null||typeof t!="object")return null;const e=t.prompt_tokens??0,o=t.completion_tokens??0;return{input_tokens:e,input_tokens_details:{cached_tokens:t.prompt_tokens_details?.cached_tokens??0},output_tokens:o,output_tokens_details:{reasoning_tokens:t.completion_tokens_details?.reasoning_tokens??0},total_tokens:t.total_tokens??e+o}}n(m,"usageOf");function k(t){return t==="length"||t==="model_length"?{status:"incomplete",incomplete_details:{reason:"max_output_tokens"}}:t==="content_filter"?{status:"incomplete",incomplete_details:{reason:"content_filter"}}:{status:"completed"}}n(k,"endOf");function g(t,e){return{id:e.id,object:"response",created_at:e.created,status:e.status,error:e.error??null,incomplete_details:e.incomplete_details??null,...t.echo,model:e.model??t.model,output:e.output,usage:e.usage??null}}n(g,"envelope");function y(t){return{code:typeof t?.code=="string"?t.code:"server_error",message:String(t?.message??"Upstream stream failed")}}n(y,"failureOf");export{k as endOf,g as envelope,y as failureOf,a as itemId,f as pack,d as unpack,m as usageOf};
|
|
2
|
+
//# sourceMappingURL=responses.mjs.map
|
package/dist/lib/route.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=Object.defineProperty;var
|
|
1
|
+
var m=Object.defineProperty;var p=(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 w}from"./models.mjs";function h(e,n){return(e.models??e.facts?.models??[]).includes(n)?!0:e.protocol==="anthropic.messages"&&e.models===void 0&&/^claude-/.test(n)}p(h,"serves");function k(e,n,t,o,i=!1){const c=Object.hasOwn(e.aliases,t),r=c?e.aliases[t]:t,s=c&&Object.hasOwn(e.pins,t)?e.pins[t]:void 0,d=n.filter(a=>h(a,r)),l=n.find(a=>a.default)??n[0];if(d.length>0){const a=v(e,o,d,r,i);return{endpoint:a[0],model:r,unserved:!1,pool:a,pin:s}}const u=w(l);return u.length===1?{endpoint:l,model:u[0],unserved:!1,pool:[l],pin:s}:{endpoint:l,model:r,unserved:!0,pool:[l],pin:s}}p(k,"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 o=k(e.config,e.state.endpoints,n.model,e.state,t.advance===!0);if(t.endpoint!==void 0){const s=o.pool.find(l=>l.name===t.endpoint);if(!s)throw new f(`Endpoint ${t.endpoint} no longer serves ${o.model}`,{code:"endpoint_not_in_pool",status:500});const d=e.plan(s,{body:n,wire:t.wire,tokens:t.tokens});return{endpoint:s,model:o.model,requested:n.model,unserved:o.unserved,pin:o.pin,convert:d.convert,protocol:d.protocol,more:d.more,pool:[s]}}const{endpoint:i,pool:c}=o,r=e.plan(i,{body:n,wire:t.wire,tokens:t.tokens});return{endpoint:i,model:o.model,requested:n.model,unserved:o.unserved,pin:o.pin,convert:r.convert,protocol:r.protocol,more:r.more,pool:c}}p(x,"resolve");export{k as pick,x as resolve,h as serves};
|
|
2
2
|
//# sourceMappingURL=route.mjs.map
|
package/dist/lib/routes.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var N=Object.defineProperty;var l=(n,o)=>N(n,"name",{value:o,configurable:!0});import{timingSafeEqual as U}from"node:crypto";import{TranslatorError as A}from"./errors.mjs";import{messageId as z}from"./ids.mjs";import{sign as B}from"./thinking.mjs";import{CONTENT_TYPE as $,recorder as G}from"./metrics.mjs";import{cors as M,rateLimit as W}from"./guard.mjs";const F=64*1024*1024,Y={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"},T=Symbol("stalled"),j=Symbol("gone");async function K(n,o){if(!(o>0))return n;let i;const d=new Promise(p=>{i=setTimeout(p,o,T)});try{return await Promise.race([n,d])}finally{clearTimeout(i)}}l(K,"settle");async function*J(n,o,i,d){let p=!1;try{const a=o.front==="anthropic";a&&(yield{event:"message_start",data:{type:"message_start",message:{id:z(),type:"message",role:"assistant",model:i,content:[],stop_reason:null,stop_sequence:null,usage:{input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0}}}},yield{event:"content_block_start",data:{type:"content_block_start",index:0,content_block:{type:"thinking",thinking:"",signature:""}}});const h=await n,f=l(function*(){yield{event:"content_block_delta",data:{type:"content_block_delta",index:0,delta:{type:"signature_delta",signature:B()}}},yield{event:"content_block_stop",data:{type:"content_block_stop",index:0}}},"closeEarly");if(h.stream){p=!0;let u=null;for await(const g of d?d(h.stream):h.stream){if(!a){yield g;continue}if(g.event!=="message_start"){if(u===null&&g.event==="content_block_start"&&g.data.content_block.type==="thinking"){u=0;continue}u===null&&(yield*f(),u=1),yield u>0&&typeof g.data?.index=="number"?{...g,data:{...g.data,index:g.data.index+u}}:g}}return}a&&(yield*f()),yield*C(o,h.body)}finally{p||n.then(a=>a.stream?.return?.(),()=>{})}}l(J,"late");function*C(n,o){if(n.wire==="responses"){yield{event:"error",data:{type:"error",code:o.error.code,message:o.error.message,param:o.error.param}};return}if(n.front==="anthropic"){yield{event:"error",data:o};return}yield{data:o},yield{data:"[DONE]"}}l(C,"failure");async function L(n,o,i,d,p,a=200,h=Y){n.hijack();const f=n.raw;f.writeHead(a,h);try{await o.write(f,d,{front:o.front,interval:p})}catch(u){if(!i.signal.aborted){const g=u instanceof A;g||(n.log.error(u),o.emit({type:"error",kind:"route",level:"error",message:String(u?.message??u),log:!1}));const{body:y}=o.build(g?u.status:502,g?u.message:"Internal server error",g?{type:u.type,code:u.code}:{});for(const b of C(o,y))f.write(o.encode(b))}}return f.end(),n}l(L,"stream");function I(n,o){const i=Buffer.from(n),d=Buffer.from(o);return i.length===d.length&&U(i,d)}l(I,"same");function P(n){const o=/^Bearer\s+(.+)$/i.exec(n.authorization??"");return n["x-api-key"]||o?.[1]||""}l(P,"keyOf");function Q(n){const o={};for(const[i,d]of Object.entries(n))(i==="anthropic-beta"||i==="anthropic-version"||i.startsWith("x-claude-code-"))&&(o[i]=String(d));return o}l(Q,"forwardable");function V(n){if(n===!0)return{ok:!0,context:void 0};if(n&&typeof n=="object"&&n.ok===!0)return{ok:!0,context:n.context,cacheSalt:n.cacheSalt};const o=n&&typeof n=="object"&&n.ok===!1?n:{};return{ok:!1,status:Number.isInteger(o.status)&&o.status>=400&&o.status<=599?o.status:401,message:typeof o.message=="string"&&o.message!==""?o.message:"unauthorized"}}l(V,"verdictOf");function re(n,o,i){const{front:d,filter:p}=i,a={...i,build:l((e,t,r={})=>i.build(e,t,{...r,front:d}),"build"),send:l((e,t)=>i.send(e,{...t,front:d,filter:p}),"send"),route:l(e=>i.route(e,{front:d}),"route"),count:l((e,t)=>i.count(e,{...t,front:d}),"count"),embed:l((e,t)=>i.embed(e,t),"embed"),list:l(e=>i.list({...e,front:d}),"list"),get:l((e,t)=>i.get(e,{...t,front:d}),"get")},h=[o.apiKey??[]].flat().filter(Boolean),f=o.bodyLimit??F,u=new WeakMap,g=new WeakMap,y=o.metrics===!0?G({front:d,endpoints:i.endpoints}):null,b=l((e,t)=>e.code(t.status).headers(t.headers).send(t.body),"reject");n.setErrorHandler((e,t,r)=>{if(e instanceof A)return b(r,a.build(e.status,e.message,{type:e.type,code:e.code,param:e.param}));const s=e.statusCode??500;return s<500?b(r,a.build(s,e.message)):(t.log.error(e),a.emit({type:"error",kind:"route",level:"error",message:String(e.message),status:s,log:!1}),b(r,a.build(s,"Internal server error")))});const x=M(o.cors),O=W(o.rateLimit);x&&n.addHook("onRequest",async(e,t)=>{for(const[r,s]of Object.entries(x.headers(e.headers.origin)))t.raw.setHeader(r,s)}),y&&n.addHook("onRequest",y.hook),O&&n.addHook("onRequest",async(e,t)=>{if(e.routeOptions.config?.public||e.routeOptions.config?.metrics)return;const r=P(e.headers),s=O.take(r&&h.some(k=>I(r,k))?`key:${r}`:`ip:${e.ip}`);if(s===0)return;const c=a.build(429,"rate limit exceeded",{type:"rate_limit_error"});return t.code(429).headers({...c.headers,"retry-after":String(s)}).send(c.body)}),x&&n.route({method:"OPTIONS",url:"/*",config:{public:!0,metrics:!0},handler:l((e,t)=>{const r=x.preflight(e.headers.origin,e.headers["access-control-request-headers"]);for(const[s,c]of Object.entries(r))t.raw.setHeader(s,c);return t.code(204).send()},"handler")}),n.addHook("onRequest",async(e,t)=>{if(h.length===0||e.routeOptions.config?.public)return;const r=P(e.headers);if(!(r&&h.some(s=>I(r,s))))return b(t,a.build(401,"invalid x-api-key"))}),typeof o.authorize=="function"&&n.addHook("preHandler",async(e,t)=>{if(e.routeOptions.config?.public)return;let r=null;if(e.body&&typeof e.body=="object"&&!Array.isArray(e.body))try{r=a.route(e.body)}catch{}let s;try{s=V(await o.authorize({method:e.method,url:e.url,headers:e.headers,body:e.body,front:a.front,route:r}))}catch(c){e.log.error(c),a.emit({type:"error",kind:"route",level:"error",message:String(c?.message??c),log:!1}),s={ok:!1,status:401,message:"unauthorized"}}if(!s.ok)return b(t,a.build(s.status,s.message));u.set(e,s.context),typeof s.cacheSalt=="string"&&s.cacheSalt!==""&&g.set(e,s.cacheSalt)}),n.route({method:["GET","HEAD"],url:"/",config:{public:!0},handler:l(async(e,t)=>t.send({ok:!0}),"handler")}),n.route({method:["GET","HEAD"],url:"/api/hello",config:{public:!0},handler:l(async(e,t)=>t.send({ok:!0}),"handler")}),y&&n.get("/metrics",{config:{metrics:!0}},async(e,t)=>t.header("content-type",$).send(y.render())),n.get("/v1/models",async(e,t)=>{const r=new AbortController;return t.raw.on("close",()=>r.abort()),a.list({signal:r.signal})}),n.get("/v1/models/*",async(e,t)=>{const r=new AbortController;return t.raw.on("close",()=>r.abort()),a.get(e.params["*"],{signal:r.signal})});const S={...a,wire:"responses"},H=l(async(e,t,r,s)=>{if(t.raw.destroyed)return t;const c=new AbortController;t.raw.on("close",()=>{t.raw.writableFinished||c.abort()});const k=typeof o.onUsage=="function"?w=>o.onUsage(w,u.get(e)):void 0,_=a.interval(r),v=a.send(r,{signal:c.signal,wire:s?"responses":void 0,clientHeaders:Q(e.headers),cacheSalt:g.get(e),onUsage:k,log:e.log});v.catch(()=>{}),y?.attach(e,v);const D=new Promise(w=>c.signal.addEventListener("abort",()=>w(j),{once:!0})),m=await K(Promise.race([v,D]),r?.stream===!0?_:0);if(m===j)return v.then(w=>w.stream?.return?.(),()=>{}),t;const E=s?w=>a.responses.stream(w,s.state,s.settings):void 0;return m===T?L(t,s?S:a,c,J(v,s?S:a,r?.model,E),_):m.stream?L(t,s?S:a,c,E?E(m.stream):m.stream,_,m.status,m.headers):!s||m.status>=400?b(t,m):b(t,{...m,body:await a.responses.response(m.body,s.state,s.settings)})},"converse"),R=a.front==="anthropic"?"/v1/messages":"/v1/chat/completions";if(n.post(R,{bodyLimit:f},(e,t)=>H(e,t,e.body,null)),a.front==="openai"){const e=l(async t=>{const r=a.settings(t.body),{body:s,state:c}=await a.responses.request(t.body,r);return c.dropped.length>0&&a.emit({type:"dropped",level:"debug",message:`Responses request: dropped ${c.dropped.join(", ")}`,fields:[...c.dropped],log:t.log}),{chat:s,via:{state:c,settings:r}}},"converted");n.post("/v1/responses",{bodyLimit:f},async(t,r)=>{const{chat:s,via:c}=await e(t);return H(t,r,s,c)}),n.post("/v1/responses/input_tokens",{bodyLimit:f},async(t,r)=>{const s=new AbortController;r.raw.on("close",()=>s.abort());const{chat:c}=await e(t),{input_tokens:k}=await a.count(c,{signal:s.signal});return r.send({object:"response.input_tokens",input_tokens:k})}),n.post("/v1/embeddings",{bodyLimit:f},async(t,r)=>{const s=new AbortController;r.raw.on("close",()=>{r.raw.writableFinished||s.abort()});const c=typeof o.onUsage=="function"?_=>o.onUsage(_,u.get(t)):void 0,k=a.embed(t.body,{signal:s.signal,onUsage:c,log:t.log});return y?.attach(t,k),b(r,await k)})}a.front==="anthropic"&&n.post("/v1/messages/count_tokens",{bodyLimit:f},async(e,t)=>{const r=new AbortController;return t.raw.on("close",()=>r.abort()),a.count(e.body,{signal:r.signal})})}l(re,"register");export{J as late,re as register};
|
|
2
2
|
//# sourceMappingURL=routes.mjs.map
|
package/dist/lib/settings.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var c=Object.defineProperty;var l=(o,e)=>c(o,"name",{value:e,configurable:!0});import{TranslatorError as n}from"./errors.mjs";import{check as f}from"./constraint.mjs";import{valid as d}from"./cache.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:!0,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({}),constraint:null,cacheSalt:null,promptCacheKey:null,pingInterval:1e4,toolStreaming:"buffer",effortPassthrough:!1,passthroughFilter:!1,nativeMessages:!1,contextWindow:0,defaultMaxTokens:8192}),g={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"]},p=["effortPassthrough","passthroughFilter","imageFallback","toolFallback","jsonObjectFallback","thinkOpen","reasoningRoundTrip","toolErrorInference"];function y(...o){const e={...r,pdf:{...r.pdf},sampling:{...r.sampling}};for(const t of o)if(t)for(const[s
|
|
1
|
+
var c=Object.defineProperty;var l=(o,e)=>c(o,"name",{value:e,configurable:!0});import{TranslatorError as n}from"./errors.mjs";import{check as f}from"./constraint.mjs";import{valid as d}from"./cache.mjs";const r=Object.freeze({inlineSystem:"auto",stripBillingHeader:!0,reasoningField:"reasoning",thinkTags:!0,thinkOpen:!1,reasoningRoundTrip:!1,reasoningSummary:"auto",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:!0,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({}),constraint:null,cacheSalt:null,promptCacheKey:null,pingInterval:1e4,toolStreaming:"buffer",effortPassthrough:!1,passthroughFilter:!1,nativeMessages:!1,contextWindow:0,defaultMaxTokens:8192}),g={inlineSystem:["auto","keep","hoist","user","drop"],reasoningField:["reasoning","reasoning_content"],reasoningSummary:["auto","concise","detailed","none"],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"]},p=["effortPassthrough","passthroughFilter","imageFallback","toolFallback","jsonObjectFallback","thinkOpen","reasoningRoundTrip","toolErrorInference"];function y(...o){const e={...r,pdf:{...r.pdf},sampling:{...r.sampling}};for(const t of o)if(t)for(const[a,s]of Object.entries(t))s!==void 0&&(a==="pdf"?Object.assign(e.pdf,s):a==="sampling"&&s!==null&&typeof s=="object"&&!Array.isArray(s)?Object.assign(e.sampling,s):e[a]=s);for(const[t,a]of Object.entries(g))if(!a.includes(e[t]))throw new n(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected one of ${a.join(", ")})`,{code:"invalid_setting",status:500,details:{key:t,allowed:a}});for(const t of p)if(typeof e[t]!="boolean")throw new n(`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 n(`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 n(`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 n(`Invalid setting sampling: ${JSON.stringify(e.sampling)} (expected an object of field names and values)`,{code:"invalid_setting",status:500,details:{key:"sampling"}});const i=f(e.constraint);if(i!==null)throw new n(`Invalid setting constraint: ${JSON.stringify(e.constraint)} (${i})`,{code:"invalid_setting",status:500,details:{key:"constraint"}});for(const t of["cacheSalt","promptCacheKey"])if(!d(e[t]))throw new n(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected a non-empty string or null)`,{code:"invalid_setting",status:500,details:{key:t}});if(!(Number.isFinite(e.pdf.scale)&&e.pdf.scale>0))throw new n(`Invalid setting pdf.scale: ${JSON.stringify(e.pdf.scale)} (expected a positive number)`,{code:"invalid_setting",status:500,details:{key:"pdf.scale"}});return e}l(y,"resolve");export{r as DEFAULTS,y as resolve};
|
|
2
2
|
//# sourceMappingURL=settings.mjs.map
|
package/dist/lib/vllm.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var c=Object.defineProperty;var
|
|
1
|
+
var c=Object.defineProperty;var s=(t,e)=>c(t,"name",{value:e,configurable:!0});import{atLeast as l,semver as f}from"./normalize.mjs";import{sign as a}from"./thinking.mjs";const y="0.11.1",p="x-anthropic-billing-header:";function A(t){const e=t.facts?.version??t.version;return f(e)!==null&&l(e,y)}s(A,"eligible");function*u(t){for(const e of t)if(Array.isArray(e?.content))for(const r of e.content)yield r,r?.type==="tool_result"&&Array.isArray(r.content)&&(yield*r.content)}s(u,"blocks");function h(t,e){const r=Array.isArray(t.messages)?t.messages:[];if(r.at(-1)?.role==="assistant")return"prefill";const n=[...u(r)];return n.some(o=>o?.type==="document")?"document":e.toolSearch!=="native"&&(Array.isArray(t.tools)&&t.tools.some(i=>i?.defer_loading!==void 0)||n.some(i=>["tool_reference","tool_addition","tool_removal"].includes(i?.type)))?"toolsearch":null}s(h,"unsuited");function d(t,e){return(typeof t=="string"?[{type:"text",text:t}]:t).filter(n=>n?.type==="text"&&typeof n.text=="string").filter(n=>!(e.stripBillingHeader&&n.text.trimStart().startsWith(p))).map(n=>n.text).join(`
|
|
2
2
|
|
|
3
|
-
`)}
|
|
3
|
+
`)}s(d,"systemText");function m(t,e){const r=e.toolErrorMarker;return typeof t.content=="string"?{...t,content:`${r}${t.content}`}:Array.isArray(t.content)?{...t,content:[{type:"text",text:r.trimEnd()},...t.content]}:{...t,content:r.trimEnd()}}s(m,"marked");function v(t,e){const r={...t};if(r.system!==void 0&&r.system!==null){const o=d(r.system,e);o===""?delete r.system:r.system=o}const n=s(o=>o?.type==="tool_result"&&o.is_error===!0,"failed");return e.toolErrors&&Array.isArray(r.messages)&&r.messages.some(o=>Array.isArray(o?.content)&&o.content.some(n))&&(r.messages=r.messages.map(o=>Array.isArray(o?.content)&&o.content.some(n)?{...o,content:o.content.map(i=>n(i)?m(i,e):i)}:o)),r}s(v,"request");function E(t){return Array.isArray(t?.content)?{...t,content:t.content.map(e=>e?.type==="thinking"&&typeof e.signature!="string"?{...e,signature:a()}:e)}:t}s(E,"response");async function*I(t){const e=new Map;for await(const r of t){const n=r.data;n?.type==="content_block_start"&&n.content_block?.type==="thinking"?e.set(n.index,typeof n.content_block.signature=="string"):n?.type==="content_block_delta"&&n.delta?.type==="signature_delta"?e.set(n.index,!0):n?.type==="content_block_stop"&&e.get(n.index)===!1&&(yield{event:"content_block_delta",data:{type:"content_block_delta",index:n.index,delta:{type:"signature_delta",signature:a()}}}),n?.type==="content_block_stop"&&e.delete(n.index),yield r,n?.type==="message_start"&&(yield{event:"ping",data:{type:"ping"}})}}s(I,"stream");export{y as MIN_VERSION,A as eligible,v as request,E as response,I as stream,h as unsuited};
|
|
4
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.13.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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an Anthropic Messages request body into a Responses request body (for an Anthropic-protocol client talking to an upstream on the
|
|
3
|
+
* Responses API). The request goes through the Anthropic to Chat Completions converter first, so tool search, documents, thinking,
|
|
4
|
+
* reasoning round trips and every other conversion apply as they do for Chat Completions, and the result is then written as a Responses
|
|
5
|
+
* body (see `lib/responses-upstream.mjs`). The state is the Chat Completions one, which the reply converters read, with the fields the
|
|
6
|
+
* second step dropped added to `dropped`.
|
|
7
|
+
* @param {any} body - Anthropic `POST /v1/messages` body.
|
|
8
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
9
|
+
* @param {any} [context] - See the Anthropic to Chat Completions converter.
|
|
10
|
+
* @returns {Promise<{ body: any, state: any }>} Responses request body and conversion state.
|
|
11
|
+
* @throws {import("../../../../../../../lib/errors.mjs").TranslatorError} As the Anthropic to Chat Completions converter, and for fields the Responses API lacks when configured to error.
|
|
12
|
+
*/
|
|
13
|
+
export function request(body: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>, context?: any): Promise<{
|
|
14
|
+
body: any;
|
|
15
|
+
state: any;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Chat Completions request body into a Responses request body (for an OpenAI-protocol client talking to an upstream on the
|
|
3
|
+
* Responses API). See `lib/responses-upstream.mjs` for the mapping.
|
|
4
|
+
* @param {any} chatBody - OpenAI `POST /v1/chat/completions` body.
|
|
5
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
6
|
+
* @returns {Promise<{ body: any, state: any }>} Responses request body and conversion state.
|
|
7
|
+
* @throws {import("../../../../../../../lib/errors.mjs").TranslatorError} For malformed requests, `n` above 1 (`send` fans that out instead), unknown roles, or unknown fields when configured to error.
|
|
8
|
+
*/
|
|
9
|
+
export function request(chatBody: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): Promise<{
|
|
10
|
+
body: any;
|
|
11
|
+
state: any;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a (non-streaming) Chat Completions reply into a Responses object.
|
|
3
|
+
*
|
|
4
|
+
* The output holds, in this order, a `reasoning` item (the reply's reasoning text as one summary part, and with `reasoningRoundTrip` its
|
|
5
|
+
* `reasoning_details` as `encrypted_content`), a `message` item with an `output_text` part (or a `refusal` part) and one `function_call`
|
|
6
|
+
* item per tool call. A `length` stop makes the response `incomplete` with reason `max_output_tokens`, a content filter one with reason
|
|
7
|
+
* `content_filter`.
|
|
8
|
+
* @param {any} completion - Chat Completions `chat.completion` object.
|
|
9
|
+
* @param {any} state - State from the request converter (`model`, `echo`).
|
|
10
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
11
|
+
* @returns {any} Responses object.
|
|
12
|
+
* @throws {TranslatorError} When the completion has no choices.
|
|
13
|
+
*/
|
|
14
|
+
export function response(completion: any, state: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Chat Completions chunk stream into Responses events.
|
|
3
|
+
*
|
|
4
|
+
* `source` is SSE text/bytes, an iterable of `{ data }` messages, or bare chunk objects. The result yields `{ event, data }` pairs
|
|
5
|
+
* (`data.type` repeats the event name, `data.sequence_number` counts from 0): `response.created` and `response.in_progress` first, then for each output
|
|
6
|
+
* item `response.output_item.added`, its part and delta events, and `response.output_item.done`, and last `response.completed` (or
|
|
7
|
+
* `response.incomplete` after a length stop or a content filter). Output items come in the order the deltas start them: reasoning
|
|
8
|
+
* (as a summary part), the message text (or refusal) and one function call per tool call index. An `error` chunk, a fatal finish reason or
|
|
9
|
+
* a stream that ends without a finish reason ends with `response.failed`. There is no `[DONE]` sentinel.
|
|
10
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array} source - Chat Completions stream.
|
|
11
|
+
* @param {any} state - State from the request converter (`model`, `echo`).
|
|
12
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
13
|
+
* @returns {AsyncGenerator<{ event: string, data: any }, void, undefined>} Responses events.
|
|
14
|
+
*/
|
|
15
|
+
export function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
16
|
+
event: string;
|
|
17
|
+
data: any;
|
|
18
|
+
}, void, undefined>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a (non-streaming) Responses reply into an Anthropic message: read as a Chat Completions reply first, then converted from there.
|
|
3
|
+
* @param {any} reply - Responses object.
|
|
4
|
+
* @param {any} [state] - State from the request converter.
|
|
5
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
6
|
+
* @returns {any} Anthropic message.
|
|
7
|
+
*/
|
|
8
|
+
export function response(reply: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Responses event stream into Anthropic events: read as Chat Completions chunks first, then converted from there.
|
|
3
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array} source - Responses stream.
|
|
4
|
+
* @param {any} [state] - State from the request converter.
|
|
5
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
6
|
+
* @returns {AsyncGenerator<any, void, undefined>} Anthropic events.
|
|
7
|
+
*/
|
|
8
|
+
export function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<any, void, undefined>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an OpenAI Responses request body into a Chat Completions request body, the pivot every upstream is reached through.
|
|
3
|
+
*
|
|
4
|
+
* The core is stateless: `previous_response_id`, `conversation`, `store: true`, `background: true` and stored prompts are refused, and so are hosted tools,
|
|
5
|
+
* non-function `tool_choice` values and input items other than messages, function calls, function call outputs and reasoning items.
|
|
6
|
+
* `instructions` becomes the first system message. Reasoning items are replayed to the upstream only with `reasoningRoundTrip` (their
|
|
7
|
+
* `encrypted_content` carries the `reasoning_details` the converter put there); otherwise they are dropped. Fields without a mapping are
|
|
8
|
+
* dropped and listed in `state.dropped`, or refused when `unknownFields` is `"error"`.
|
|
9
|
+
* @param {any} body - OpenAI `POST /v1/responses` body.
|
|
10
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
11
|
+
* @returns {{ body: any, state: any }} Chat Completions body and the state the reply converters need (`model`, `stream`, `echo`, `dropped`).
|
|
12
|
+
* @throws {TranslatorError} `invalid_request` for a malformed body, `unsupported_field` for stateful parameters and unmapped fields under `unknownFields: "error"`, `unsupported_tool` and `unsupported_content` for what has no counterpart.
|
|
13
|
+
*/
|
|
14
|
+
export function request(body: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): {
|
|
15
|
+
body: any;
|
|
16
|
+
state: any;
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a (non-streaming) Responses reply into a Chat Completions reply. See `lib/responses-upstream.mjs` for the mapping.
|
|
3
|
+
* @param {any} reply - Responses object.
|
|
4
|
+
* @param {any} [state] - State from the request converter.
|
|
5
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
6
|
+
* @returns {any} Chat completion.
|
|
7
|
+
*/
|
|
8
|
+
export function response(reply: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Responses event stream into Chat Completions chunks followed by `[DONE]`. See `lib/responses-upstream.mjs`.
|
|
3
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array} source - Responses stream.
|
|
4
|
+
* @param {any} [state] - State from the request converter.
|
|
5
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
6
|
+
* @returns {AsyncGenerator<{ data: any|string }, void, undefined>} Chat chunks.
|
|
7
|
+
*/
|
|
8
|
+
export function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
9
|
+
data: any | string;
|
|
10
|
+
}, void, undefined>;
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Describe the Anthropic driver (native Messages API upstream).
|
|
21
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], probes: string[], headers: Record<string,string>, paths: Record<string,string>}} Driver facts.
|
|
21
|
+
* @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, hosts: string[], probes: string[], headers: Record<string,string>, paths: Record<string,string>}} Driver facts.
|
|
22
22
|
*/
|
|
23
23
|
export function info(): {
|
|
24
24
|
name: string;
|
|
25
25
|
protocol: string;
|
|
26
|
+
protocols: string[];
|
|
26
27
|
order: number;
|
|
27
28
|
auth: string;
|
|
28
29
|
strict: boolean;
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
/**
|
|
20
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
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, hostSuffixes: string[], paths: Record<string,string>}} Driver facts.
|
|
22
|
+
* @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, hostSuffixes: string[], paths: Record<string,string>}} Driver facts.
|
|
23
23
|
*/
|
|
24
24
|
export function info(): {
|
|
25
25
|
name: string;
|
|
26
26
|
protocol: string;
|
|
27
|
+
protocols: string[];
|
|
27
28
|
order: number;
|
|
28
29
|
auth: string;
|
|
29
30
|
strict: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Describe the generic OpenAI-compatible driver (matches last, after every specific driver).
|
|
3
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields: string[], paths: Record<string,string>}} Driver facts.
|
|
3
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, protocols: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
4
4
|
*/
|
|
5
5
|
export function info(): {
|
|
6
6
|
name: string;
|
|
@@ -8,6 +8,7 @@ export function info(): {
|
|
|
8
8
|
order: number;
|
|
9
9
|
auth: string;
|
|
10
10
|
strict: boolean;
|
|
11
|
+
protocols: string[];
|
|
11
12
|
fields: string[];
|
|
12
13
|
paths: Record<string, string>;
|
|
13
14
|
};
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Describe the DeepSeek driver.
|
|
21
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], paths: Record<string,string>}} Driver facts.
|
|
21
|
+
* @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, hosts: string[], paths: Record<string,string>}} Driver facts.
|
|
22
22
|
*/
|
|
23
23
|
export function info(): {
|
|
24
24
|
name: string;
|
|
25
25
|
protocol: string;
|
|
26
|
+
protocols: string[];
|
|
26
27
|
order: number;
|
|
27
28
|
auth: string;
|
|
28
29
|
strict: boolean;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Describe the Fireworks AI driver (see `PRESETS.fireworks` in `lib/presets.mjs`).
|
|
3
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
|
|
3
|
+
* @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
|
|
4
4
|
*/
|
|
5
5
|
export function info(): {
|
|
6
6
|
name: string;
|
|
7
7
|
protocol: string;
|
|
8
|
+
protocols: string[];
|
|
8
9
|
order: number;
|
|
9
10
|
auth: string;
|
|
10
11
|
strict: boolean;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Describe the Gemini (OpenAI-compatible endpoint) driver (see `PRESETS.gemini` in `lib/presets.mjs`).
|
|
3
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
|
|
3
|
+
* @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
|
|
4
4
|
*/
|
|
5
5
|
export function info(): {
|
|
6
6
|
name: string;
|
|
7
7
|
protocol: string;
|
|
8
|
+
protocols: string[];
|
|
8
9
|
order: number;
|
|
9
10
|
auth: string;
|
|
10
11
|
strict: boolean;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Describe the Groq driver (see `PRESETS.groq` in `lib/presets.mjs`).
|
|
3
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
|
|
3
|
+
* @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
|
|
4
4
|
*/
|
|
5
5
|
export function info(): {
|
|
6
6
|
name: string;
|
|
7
7
|
protocol: string;
|
|
8
|
+
protocols: string[];
|
|
8
9
|
order: number;
|
|
9
10
|
auth: string;
|
|
10
11
|
strict: boolean;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Describe the llama.cpp driver.
|
|
21
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
21
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, protocols: string[], probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
22
22
|
*/
|
|
23
23
|
export function info(): {
|
|
24
24
|
name: string;
|
|
@@ -26,6 +26,7 @@ export function info(): {
|
|
|
26
26
|
order: number;
|
|
27
27
|
auth: string;
|
|
28
28
|
strict: boolean;
|
|
29
|
+
protocols: string[];
|
|
29
30
|
probes: string[];
|
|
30
31
|
fields: string[];
|
|
31
32
|
paths: Record<string, string>;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Describe the LM Studio driver. It is found through `GET /api/v0/models`, LM Studio's own REST listing.
|
|
21
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], paths: Record<string,string>}} Driver facts.
|
|
21
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, protocols: string[], probes: string[], paths: Record<string,string>}} Driver facts.
|
|
22
22
|
*/
|
|
23
23
|
export function info(): {
|
|
24
24
|
name: string;
|
|
@@ -26,6 +26,7 @@ export function info(): {
|
|
|
26
26
|
order: number;
|
|
27
27
|
auth: string;
|
|
28
28
|
strict: boolean;
|
|
29
|
+
protocols: string[];
|
|
29
30
|
probes: string[];
|
|
30
31
|
paths: Record<string, string>;
|
|
31
32
|
};
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
/**
|
|
20
20
|
* Describe the LocalAI driver. It is found through `GET /version` (`{ version: "v3.1.0 (<commit>)" }`) or LocalAI's discovery document at
|
|
21
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.
|
|
22
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, protocols: string[], probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
23
23
|
*/
|
|
24
24
|
export function info(): {
|
|
25
25
|
name: string;
|
|
@@ -27,6 +27,7 @@ export function info(): {
|
|
|
27
27
|
order: number;
|
|
28
28
|
auth: string;
|
|
29
29
|
strict: boolean;
|
|
30
|
+
protocols: string[];
|
|
30
31
|
probes: string[];
|
|
31
32
|
fields: string[];
|
|
32
33
|
paths: Record<string, string>;
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Describe the Mistral driver. Mistral accepts only 9-character alphanumeric tool-call ids, so the translator rewrites the client's ids.
|
|
21
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], toolCallIds: {alphabet: string, min: number, max: number}, paths: Record<string,string>}} Driver facts.
|
|
21
|
+
* @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, hosts: string[], toolCallIds: {alphabet: string, min: number, max: number}, paths: Record<string,string>}} Driver facts.
|
|
22
22
|
*/
|
|
23
23
|
export function info(): {
|
|
24
24
|
name: string;
|
|
25
25
|
protocol: string;
|
|
26
|
+
protocols: string[];
|
|
26
27
|
order: number;
|
|
27
28
|
auth: string;
|
|
28
29
|
strict: boolean;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
/**
|
|
20
20
|
* Describe the Ollama driver. `protocol` is the OpenAI-compatible `/v1` API; `native` is the mode an upstream selects with `api: "native"`, Ollama's own
|
|
21
21
|
* `/api/chat` (the `ollama.chat` protocol; the model list and embeddings stay on `/v1`).
|
|
22
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], paths: Record<string,string>, native: {protocol: string, paths: Record<string,string>}}} Driver facts.
|
|
22
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, protocols: string[], probes: string[], paths: Record<string,string>, native: {protocol: string, paths: Record<string,string>}}} Driver facts.
|
|
23
23
|
*/
|
|
24
24
|
export function info(): {
|
|
25
25
|
name: string;
|
|
@@ -27,6 +27,7 @@ export function info(): {
|
|
|
27
27
|
order: number;
|
|
28
28
|
auth: string;
|
|
29
29
|
strict: boolean;
|
|
30
|
+
protocols: string[];
|
|
30
31
|
probes: string[];
|
|
31
32
|
paths: Record<string, string>;
|
|
32
33
|
native: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Remove `tool_choice`, `n` and `logit_bias` (recorded in `state.dropped`; with `tool_choice: "none"` the tools are removed too, so a forbidden tool call cannot happen), replace images given by URL with a note, and warn once per
|
|
3
3
|
* upstream when the prompt is estimated to exceed `contextWindow` (Ollama truncates silently).
|
|
4
4
|
* @param {any} body - Chat Completions request body.
|
|
5
|
-
* @param {any} [ctx] - `{ endpoint, settings, state, warn }
|
|
5
|
+
* @param {any} [ctx] - `{ endpoint, settings, state, warn, protocol }` (`protocol` is the one the request goes over).
|
|
6
6
|
* @returns {any} Normalized body.
|
|
7
7
|
*/
|
|
8
8
|
export function request(body: any, ctx?: any): any;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Describe the OpenAI driver.
|
|
21
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
21
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, protocols: string[], hosts: string[], fields: string[], paths: Record<string,string>}} Driver facts.
|
|
22
22
|
*/
|
|
23
23
|
export function info(): {
|
|
24
24
|
name: string;
|
|
@@ -26,6 +26,7 @@ export function info(): {
|
|
|
26
26
|
order: number;
|
|
27
27
|
auth: string;
|
|
28
28
|
strict: boolean;
|
|
29
|
+
protocols: string[];
|
|
29
30
|
hosts: string[];
|
|
30
31
|
fields: string[];
|
|
31
32
|
paths: Record<string, string>;
|