@cldmv/llm-translator 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +7 -7
  2. package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +8 -8
  3. package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
  4. package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +1 -1
  5. package/dist/api/driver/azure/detect.mjs +2 -0
  6. package/dist/api/driver/azure/error.mjs +2 -0
  7. package/dist/api/driver/azure/info.mjs +2 -0
  8. package/dist/api/driver/azure/model/list.mjs +2 -0
  9. package/dist/api/driver/azure/path.mjs +2 -0
  10. package/dist/api/driver/azure/request.mjs +2 -0
  11. package/dist/api/driver/azure/settings.mjs +2 -0
  12. package/dist/api/driver/lmstudio/detect.mjs +2 -0
  13. package/dist/api/driver/lmstudio/info.mjs +2 -0
  14. package/dist/api/driver/lmstudio/request.mjs +2 -0
  15. package/dist/api/driver/lmstudio/settings.mjs +2 -0
  16. package/dist/api/driver/localai/chunk.mjs +2 -0
  17. package/dist/api/driver/localai/detect.mjs +2 -0
  18. package/dist/api/driver/localai/info.mjs +2 -0
  19. package/dist/api/driver/localai/request.mjs +2 -0
  20. package/dist/api/driver/localai/response.mjs +2 -0
  21. package/dist/api/driver/localai/settings.mjs +2 -0
  22. package/dist/api/driver/mistral/chunk.mjs +2 -0
  23. package/dist/api/driver/mistral/detect.mjs +2 -0
  24. package/dist/api/driver/mistral/info.mjs +2 -0
  25. package/dist/api/driver/mistral/request.mjs +2 -0
  26. package/dist/api/driver/mistral/response.mjs +2 -0
  27. package/dist/api/driver/mistral/settings.mjs +2 -0
  28. package/dist/api/driver/openrouter/chunk.mjs +2 -0
  29. package/dist/api/driver/openrouter/detect.mjs +2 -0
  30. package/dist/api/driver/openrouter/info.mjs +2 -0
  31. package/dist/api/driver/openrouter/path.mjs +2 -0
  32. package/dist/api/driver/openrouter/request.mjs +2 -0
  33. package/dist/api/driver/openrouter/response.mjs +2 -0
  34. package/dist/api/driver/openrouter/settings.mjs +2 -0
  35. package/dist/api/driver/tgi/chunk.mjs +2 -0
  36. package/dist/api/driver/tgi/detect.mjs +2 -0
  37. package/dist/api/driver/tgi/info.mjs +2 -0
  38. package/dist/api/driver/tgi/request.mjs +2 -0
  39. package/dist/api/driver/tgi/response.mjs +2 -0
  40. package/dist/api/driver/tgi/settings.mjs +2 -0
  41. package/dist/api/driver/vllm/detect.mjs +1 -1
  42. package/dist/api/embeddings/send.mjs +1 -1
  43. package/dist/api/request.mjs +2 -2
  44. package/dist/api/send.mjs +1 -1
  45. package/dist/lib/azure.mjs +2 -0
  46. package/dist/lib/backends.mjs +1 -1
  47. package/dist/lib/capture.mjs +1 -1
  48. package/dist/lib/config.mjs +1 -1
  49. package/dist/lib/fanout.mjs +2 -0
  50. package/dist/lib/finish.mjs +1 -1
  51. package/dist/lib/http.mjs +1 -1
  52. package/dist/lib/models.mjs +1 -1
  53. package/dist/lib/openrouter.mjs +2 -0
  54. package/dist/lib/tgi.mjs +2 -0
  55. package/dist/lib/typed.mjs +2 -0
  56. package/dist/lib/usage.mjs +1 -1
  57. package/package.json +1 -1
  58. package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +1 -1
  59. package/types/src/api/driver/azure/detect.d.mts +8 -0
  60. package/types/src/api/driver/azure/error.d.mts +15 -0
  61. package/types/src/api/driver/azure/info.d.mts +31 -0
  62. package/types/src/api/driver/azure/model/list.d.mts +7 -0
  63. package/types/src/api/driver/azure/path.d.mts +7 -0
  64. package/types/src/api/driver/azure/request.d.mts +8 -0
  65. package/types/src/api/driver/azure/settings.d.mts +23 -0
  66. package/types/src/api/driver/lmstudio/detect.d.mts +6 -0
  67. package/types/src/api/driver/lmstudio/info.d.mts +31 -0
  68. package/types/src/api/driver/lmstudio/request.d.mts +6 -0
  69. package/types/src/api/driver/lmstudio/settings.d.mts +23 -0
  70. package/types/src/api/driver/localai/chunk.d.mts +25 -0
  71. package/types/src/api/driver/localai/detect.d.mts +6 -0
  72. package/types/src/api/driver/localai/info.d.mts +33 -0
  73. package/types/src/api/driver/localai/request.d.mts +10 -0
  74. package/types/src/api/driver/localai/response.d.mts +26 -0
  75. package/types/src/api/driver/localai/settings.d.mts +25 -0
  76. package/types/src/api/driver/mistral/chunk.d.mts +8 -0
  77. package/types/src/api/driver/mistral/detect.d.mts +26 -0
  78. package/types/src/api/driver/mistral/info.d.mts +35 -0
  79. package/types/src/api/driver/mistral/request.d.mts +6 -0
  80. package/types/src/api/driver/mistral/response.d.mts +7 -0
  81. package/types/src/api/driver/mistral/settings.d.mts +24 -0
  82. package/types/src/api/driver/openrouter/chunk.d.mts +25 -0
  83. package/types/src/api/driver/openrouter/detect.d.mts +26 -0
  84. package/types/src/api/driver/openrouter/info.d.mts +30 -0
  85. package/types/src/api/driver/openrouter/path.d.mts +8 -0
  86. package/types/src/api/driver/openrouter/request.d.mts +10 -0
  87. package/types/src/api/driver/openrouter/response.d.mts +8 -0
  88. package/types/src/api/driver/openrouter/settings.d.mts +26 -0
  89. package/types/src/api/driver/tgi/chunk.d.mts +9 -0
  90. package/types/src/api/driver/tgi/detect.d.mts +6 -0
  91. package/types/src/api/driver/tgi/info.d.mts +33 -0
  92. package/types/src/api/driver/tgi/request.d.mts +9 -0
  93. package/types/src/api/driver/tgi/response.d.mts +9 -0
  94. package/types/src/api/driver/tgi/settings.d.mts +25 -0
  95. package/types/src/api/driver/vllm/detect.d.mts +1 -1
  96. package/types/src/api/send.d.mts +7 -0
  97. package/types/src/lib/azure.d.mts +17 -0
  98. package/types/src/lib/backends.d.mts +29 -0
  99. package/types/src/lib/config.d.mts +8 -0
  100. package/types/src/lib/fanout.d.mts +68 -0
  101. package/types/src/lib/finish.d.mts +14 -3
  102. package/types/src/lib/http.d.mts +13 -2
  103. package/types/src/lib/models.d.mts +2 -2
  104. package/types/src/lib/openrouter.d.mts +23 -0
  105. package/types/src/lib/tgi.d.mts +33 -0
  106. package/types/src/lib/typed.d.mts +10 -0
  107. package/types/src/lib/usage.d.mts +20 -0
@@ -0,0 +1,2 @@
1
+ var A=Object.defineProperty;var u=(t,r)=>A(t,"name",{value:r,configurable:!0});import{TranslatorError as x,openaiError as P}from"./errors.mjs";import{resolve as j}from"./route.mjs";import{combine as E,deliver as O}from"./usage.mjs";const b=128,g={data:"[DONE]"};function U(t,r){if(t.front!=="openai"||!r||typeof r!="object"||Array.isArray(r)||!Number.isInteger(r.n)||r.n<2||j(t,r).convert===null)return 0;if(r.n>b)throw new x(`n: at most ${b} choices`,{code:"invalid_request",param:"n"});return r.n}u(U,"wants");function v(t,r){if(typeof t=="number"&&typeof r=="number")return t+r;if(t&&r&&typeof t=="object"&&typeof r=="object"){const c={...t};for(const a of Object.keys(r))c[a]=a in t?v(t[a],r[a]):r[a];return c}return t??r}u(v,"add");function S(t){const r=t.flatMap((a,f)=>(a.choices??[]).map(l=>({...l,index:f}))),c=t.map(a=>a.usage).reduce((a,f)=>a===void 0?f:v(a,f),void 0);return{...t[0],choices:r,...c===void 0?{}:{usage:c}}}u(S,"join");async function N(t){try{for(;!(await t.next()).done;);}catch{}}u(N,"finished");function D(t,r,c){const a=t.map(s=>s[Symbol.asyncIterator]());let f=!1;const l=u(async()=>{f||(f=!0,r(),await Promise.allSettled(a.map(s=>s.return?.())))},"close"),h=(async function*(){const s=new Map,p=u(o=>s.set(o,a[o].next().then(i=>({index:o,step:i}),i=>({index:o,error:i}))),"arm");a.forEach((o,i)=>p(i));let y,w,m;try{for(;s.size>0;){const{index:o,step:i,error:e}=await Promise.race(s.values());if(s.delete(o),e){c(o),yield{data:P(String(e?.message??e),{type:e?.type??"server_error"})},yield g;return}if(i.done)continue;p(o);const n=i.value?.data;if(n!=="[DONE]"){if(n?.error){c(o),yield i.value,await N(a[o]),yield g;return}if(Array.isArray(n?.choices)&&n.choices.length===0&&n.usage){w=n,m=m===void 0?n.usage:v(m,n.usage);continue}y??=n?.id,yield{...i.value,data:{...n,id:y,choices:n.choices.map(d=>({...d,index:o}))}}}}m!==void 0&&(yield{data:{...w,id:y,choices:[],usage:m}}),yield g}finally{await l()}})();return{[Symbol.asyncIterator](){return this},next:u(()=>h.next(),"next"),async return(s){return await l(),h.return(s)},async throw(s){return await l(),h.throw(s)}}}u(D,"weave");async function q({body:t,count:r,options:c,send:a,warn:f}){const l=new AbortController,h=c.signal?AbortSignal.any([c.signal,l.signal]):l.signal,s=Array.from({length:r},()=>{let e;return{promise:new Promise(d=>{e=d}),resolve:e}});let p=-1;const y=u(e=>{p>=0||(p=e,l.abort())},"trip"),w=Promise.all(s.map(e=>e.promise)).then(e=>{const n=E(e,p);return O(n,c.onUsage,f),n}),m=u(e=>Object.defineProperty(e,"usage",{value:w,enumerable:!1,configurable:!0}),"attach"),o=await Promise.all(s.map((e,n)=>a({...t,n:1},{...c,signal:h,onUsage:e.resolve}).then(d=>(d.status>=400&&y(n),{reply:d}),d=>(y(n),{error:d}))));if(p>=0){await Promise.all(o.map(n=>n.reply?.stream?.return?.())),await w;const e=o[p];if("error"in e)throw e.error;return m(e.reply)}const i=o.map(e=>e.reply);if(t.stream===!0){const e=D(i.map(n=>n.stream),()=>l.abort(),y);return m({status:200,headers:i[0].headers,stream:e})}return await w,m({status:200,headers:i[0].headers,body:S(i.map(e=>e.body))})}u(q,"run");export{b as MAX,v as add,S as join,q as run,U as wants,D as weave};
2
+ //# sourceMappingURL=fanout.mjs.map
@@ -1,2 +1,2 @@
1
- var _=Object.defineProperty;var r=(t,e)=>_(t,"name",{value:e,configurable:!0});const p={abort:{type:"api_error",status:502},aborted:{type:"api_error",status:502},error:{type:"api_error",status:502},insufficient_system_resource:{type:"overloaded_error",status:503}};function l(t){if(typeof t!="string"||!Object.hasOwn(p,t))return null;const{type:e,status:o}=p[t];return{type:e,status:o,code:"upstream_finish_"+t,message:`Upstream ended the response with finish_reason "${t}"`}}r(l,"finishError");function a(t,{hasToolCalls:e,matchedStop:o,argumentsComplete:s=!0,refusal:n}){return e&&(t!=="length"&&t!=="model_length"||s)?{stop_reason:"tool_use",stop_sequence:null}:t==="length"||t==="model_length"?{stop_reason:"max_tokens",stop_sequence:null}:t==="content_filter"?{stop_reason:"refusal",stop_sequence:null,stop_details:{type:"refusal",category:null,explanation:typeof n=="string"&&n!==""?n:null}}:typeof o=="string"&&o!==""?{stop_reason:"stop_sequence",stop_sequence:o}:{stop_reason:"end_turn",stop_sequence:null}}r(a,"toAnthropicStop");function i(t){switch(t){case"max_tokens":return"length";case"tool_use":return"tool_calls";case"refusal":return"content_filter";default:return"stop"}}r(i,"toOpenAIFinish");function k(t){const e=t?.prompt_tokens??0,o=t?.prompt_tokens_details?.cached_tokens??0;return{input_tokens:Math.max(0,e-o),output_tokens:t?.completion_tokens??0,cache_creation_input_tokens:0,cache_read_input_tokens:o}}r(k,"toAnthropicUsage");function d(t){const e=t?.cache_read_input_tokens??0,o=(t?.input_tokens??0)+e+(t?.cache_creation_input_tokens??0),s=t?.output_tokens??0,n={prompt_tokens:o,completion_tokens:s,total_tokens:o+s};return e>0&&(n.prompt_tokens_details={cached_tokens:e}),n}r(d,"toOpenAIUsage");export{l as finishError,a as toAnthropicStop,k as toAnthropicUsage,i as toOpenAIFinish,d as toOpenAIUsage};
1
+ var c=Object.defineProperty;var n=(t,e)=>c(t,"name",{value:e,configurable:!0});const p={abort:{type:"api_error",status:502},aborted:{type:"api_error",status:502},error:{type:"api_error",status:502},insufficient_system_resource:{type:"overloaded_error",status:503}};function i(t){if(typeof t!="string"||!Object.hasOwn(p,t))return null;const{type:e,status:o}=p[t];return{type:e,status:o,code:"upstream_finish_"+t,message:`Upstream ended the response with finish_reason "${t}"`}}n(i,"finishError");const u=["hate","sexual","violence","self_harm"];function f(t){return!t||typeof t!="object"?null:u.some(e=>t[e]?.filtered===!0)?"general_harms":null}n(f,"filterCategory");function k(t,{hasToolCalls:e,matchedStop:o,argumentsComplete:s=!0,refusal:r,category:_=null}){return e&&(t!=="length"&&t!=="model_length"||s)?{stop_reason:"tool_use",stop_sequence:null}:t==="length"||t==="model_length"?{stop_reason:"max_tokens",stop_sequence:null}:t==="content_filter"?{stop_reason:"refusal",stop_sequence:null,stop_details:{type:"refusal",category:_,explanation:typeof r=="string"&&r!==""?r:null}}:typeof o=="string"&&o!==""?{stop_reason:"stop_sequence",stop_sequence:o}:{stop_reason:"end_turn",stop_sequence:null}}n(k,"toAnthropicStop");function m(t){switch(t){case"max_tokens":return"length";case"tool_use":return"tool_calls";case"refusal":return"content_filter";default:return"stop"}}n(m,"toOpenAIFinish");function d(t){const e=t?.prompt_tokens??0,o=t?.prompt_tokens_details?.cached_tokens??0;return{input_tokens:Math.max(0,e-o),output_tokens:t?.completion_tokens??0,cache_creation_input_tokens:0,cache_read_input_tokens:o}}n(d,"toAnthropicUsage");function h(t){const e=t?.cache_read_input_tokens??0,o=(t?.input_tokens??0)+e+(t?.cache_creation_input_tokens??0),s=t?.output_tokens??0,r={prompt_tokens:o,completion_tokens:s,total_tokens:o+s};return e>0&&(r.prompt_tokens_details={cached_tokens:e}),r}n(h,"toOpenAIUsage");export{f as filterCategory,i as finishError,k as toAnthropicStop,d as toAnthropicUsage,m as toOpenAIFinish,h as toOpenAIUsage};
2
2
  //# sourceMappingURL=finish.mjs.map
package/dist/lib/http.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var h=Object.defineProperty;var s=(t,e)=>h(t,"name",{value:e,configurable:!0});function y(t,e){return t+e}s(y,"join");function k(t){return t==="localhost"||t==="::1"||/^127\./.test(t)}s(k,"isLoopback");function d(t,e="bearer",a){const r={...t.headers};return t.apiKey&&(e==="x-api-key"?r["x-api-key"]=t.apiKey:r.authorization=`Bearer ${t.apiKey}`),{...r,...a}}s(d,"headers");function b({endpoint:t,transport:e,signal:a,timeout:r,probes:u},f,i){const o=i!==void 0&&(i.auth==="x-api-key"||i.headers!==void 0),n=o?{auth:i.auth,extra:i.headers}:{},l=s(()=>p(e,y(t.url,f),{method:"GET",headers:d(t,n.auth,n.extra),signal:a,timeout:r}),"run");if(!u)return l();const c=o?JSON.stringify([f,n.auth,n.extra]):f;return u.has(c)||u.set(c,l()),u.get(c)}s(b,"probe");function x(t){const e={};if(!t)return e;if(typeof t.forEach=="function")return t.forEach((a,r)=>{e[r.toLowerCase()]=a}),e;for(const[a,r]of Object.entries(t))e[a.toLowerCase()]=String(r);return e}s(x,"plain");async function p(t,e,a={}){const{timeout:r,signal:u,body:f,...i}=a,o=[];u&&o.push(u),r>0&&o.push(AbortSignal.timeout(r));try{const n=await t(e,{...i,redirect:"error",body:f===void 0?void 0:JSON.stringify(f),signal:o.length>1?AbortSignal.any(o):o[0]}),l=await n.text();let c=null;try{c=JSON.parse(l)}catch{c=l===""?null:l}return{ok:n.ok,status:n.status,body:c,headers:x(n.headers)}}catch(n){return{ok:!1,status:0,body:null,error:n}}}s(p,"json");export{d as headers,k as isLoopback,y as join,p as json,x as plain,b as probe};
1
+ var l=Object.defineProperty;var o=(t,e)=>l(t,"name",{value:e,configurable:!0});function y(t,e){return t+e}o(y,"join");async function k(t,e,a,n){return t.path?t.path(e,{endpoint:a,model:n}):t.info.paths[e]??p[e]}o(k,"pathOf");const p={embeddings:"/v1/embeddings",models:"/v1/models"};function m(t){return t==="localhost"||t==="::1"||/^127\./.test(t)}o(m,"isLoopback");function d(t,e="bearer",a){const n={...t.headers};return t.apiKey&&(e==="x-api-key"||e==="api-key"?n[e]=t.apiKey:n.authorization=`Bearer ${t.apiKey}`),{...n,...a}}o(d,"headers");function S({endpoint:t,transport:e,signal:a,timeout:n,probes:i},c,s){const u=s!==void 0&&(s.auth==="x-api-key"||s.auth==="api-key"||s.headers!==void 0),r=u?{auth:s.auth,extra:s.headers}:{},h=o(()=>g(e,y(t.url,c),{method:"GET",headers:d(t,r.auth,r.extra),signal:a,timeout:n}),"run");if(!i)return h();const f=u?JSON.stringify([c,r.auth,r.extra]):c;return i.has(f)||i.set(f,h()),i.get(f)}o(S,"probe");function x(t){const e={};if(!t)return e;if(typeof t.forEach=="function")return t.forEach((a,n)=>{e[n.toLowerCase()]=a}),e;for(const[a,n]of Object.entries(t))e[a.toLowerCase()]=String(n);return e}o(x,"plain");async function g(t,e,a={}){const{timeout:n,signal:i,body:c,...s}=a,u=[];i&&u.push(i),n>0&&u.push(AbortSignal.timeout(n));try{const r=await t(e,{...s,redirect:"error",body:c===void 0?void 0:JSON.stringify(c),signal:u.length>1?AbortSignal.any(u):u[0]}),h=await r.text();let f=null;try{f=JSON.parse(h)}catch{f=h===""?null:h}return{ok:r.ok,status:r.status,body:f,headers:x(r.headers)}}catch(r){return{ok:!1,status:0,body:null,error:r}}}o(g,"json");export{d as headers,m as isLoopback,y as join,g as json,k as pathOf,x as plain,S as probe};
2
2
  //# sourceMappingURL=http.mjs.map
@@ -1,2 +1,2 @@
1
- var f=Object.defineProperty;var t=(r,o)=>f(r,"name",{value:o,configurable:!0});import*as e from"./http.mjs";function l(r){return!r.ok||!Array.isArray(r.body?.data)?null:r.body.data.filter(o=>o&&typeof o.id=="string")}t(l,"modelsOf");async function c({endpoint:r,transport:o,signal:a,timeout:d,auth:n,extraHeaders:s}){const i=await e.json(o,e.join(r.url,"/v1/models"),{method:"GET",headers:e.headers(r,n,s),signal:a,timeout:d});return l(i)}t(c,"fetchModels");export{c as fetchModels,l as modelsOf};
1
+ var l=Object.defineProperty;var t=(r,o)=>l(r,"name",{value:o,configurable:!0});import*as e from"./http.mjs";function u(r){return!r.ok||!Array.isArray(r.body?.data)?null:r.body.data.filter(o=>o&&typeof o.id=="string")}t(u,"modelsOf");async function h({endpoint:r,transport:o,signal:a,timeout:d,auth:n,extraHeaders:s,path:i="/v1/models"}){const f=await e.json(o,e.join(r.url,i),{method:"GET",headers:e.headers(r,n,s),signal:a,timeout:d});return u(f)}t(h,"fetchModels");export{h as fetchModels,u as modelsOf};
2
2
  //# sourceMappingURL=models.mjs.map
@@ -0,0 +1,2 @@
1
+ var a=Object.defineProperty;var r=(e,t)=>a(e,"name",{value:t,configurable:!0});import{TranslatorError as c}from"./errors.mjs";function n(e){return e!==null&&typeof e=="object"&&typeof e.message=="string"}r(n,"isError");function u(e){return!e||typeof e!="object"?null:Array.isArray(e.choices)&&e.choices.length>0?e.choices.every(t=>n(t?.error))?e.choices[0].error:null:n(e.error)?e.error:null}r(u,"found");function f(e){const t=Number.isInteger(e.code)&&e.code>=400&&e.code<=599?e.code:502,o=typeof e.metadata?.error_type=="string"?e.metadata.error_type:"upstream_error",i=typeof e.metadata?.provider_name=="string"?` (provider ${e.metadata.provider_name})`:"";return new c(`${e.message}${i}`,{code:o,status:t})}r(f,"failure");export{f as failure,u as found};
2
+ //# sourceMappingURL=openrouter.mjs.map
@@ -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,2 @@
1
+ var o=Object.defineProperty;var e=(t,n)=>o(t,"name",{value:n,configurable:!0});function r(t){return typeof t=="string"?t:Array.isArray(t)?t.map(r).join(""):typeof t?.text=="string"?t.text:""}e(r,"join");function y(t){if(!Array.isArray(t))return null;let n="",f="";for(const i of t)i?.type==="text"?n+=r(i):i?.type==="thinking"&&(f+=r(i.thinking));return{text:n,thinking:f}}e(y,"flatten");export{y as flatten};
2
+ //# sourceMappingURL=typed.mjs.map
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty;var f=(t,o)=>v(t,"name",{value:o,configurable:!0});const m=["input_tokens","output_tokens","cache_read_input_tokens","cache_creation_input_tokens"],l=f(t=>Number.isFinite(t)?t:null,"count");function E(t,o){if(!o||typeof o!="object")return null;let i;if(t==="openai"){const r=l(o.prompt_tokens),a=l(o.prompt_tokens_details?.cached_tokens);i={input_tokens:r===null?null:Math.max(0,r-(a??0)),output_tokens:l(o.completion_tokens),cache_read_input_tokens:a,cache_creation_input_tokens:null}}else if(t==="folded"){const r=l(o.input_tokens);i={input_tokens:r===null?null:r+(l(o.cache_creation_input_tokens)??0),output_tokens:l(o.output_tokens),cache_read_input_tokens:l(o.cache_read_input_tokens)||null,cache_creation_input_tokens:null}}else i=Object.fromEntries(m.map(r=>[r,l(o[r])]));return m.every(r=>!i[r])?null:i}f(E,"normalize");function I(t){return!!t&&typeof t=="object"&&Array.isArray(t.choices)&&t.choices.length===0&&!!t.usage}f(I,"usageChunk");function P(t,o,i){const r=Object.fromEntries(m.map(e=>[e,null]));let a=!1,y=null,d=!1,b=!1,h=!1,p=null,w="openai",j;const g=new Promise(e=>{j=e}),k=f((e,u=t.front)=>{const c=E(u,e);if(c){a=!0;for(const n of m)c[n]!==null&&c[n]!==void 0&&(r[n]=c[n])}},"take"),_=f(e=>{if(d)return;d=!0,p&&k(p(),w);const u=e==="done"&&b?"error":e,c={...r,reported:a,estimated:y,complete:u==="done",reason:u,...t};j(c);try{Promise.resolve(o?.(c)).catch(n=>i(`onUsage rejected: ${n?.message??n}`,{kind:"rejected"}))}catch(n){i(`onUsage threw: ${n?.message??n}`,{kind:"threw"})}},"finish");return{meta:t,usage:g,json(e){h=!0,p||k(e?.usage)},source(e,u="openai"){p=e,w=u},event(e){e==="[DONE]"&&(h=!0),!(!e||typeof e!="object")&&((e.type==="error"||t.front==="openai"&&e.error)&&(b=!0),t.front==="anthropic"?(e.type==="message_stop"&&(h=!0),p||k(e.type==="message_start"?e.message?.usage:e.usage)):p||k(e.usage))},finish:_,estimate(e){y=e},track(e,u,c=!1){const n=e[Symbol.asyncIterator](),x=this;return{[Symbol.asyncIterator](){return this},async next(){try{for(;;){const s=await n.next();if(s.done)_(h?"done":"error");else if(x.event(s.value?.data),c&&I(s.value?.data))continue;return s}}catch(s){throw _(u?.aborted?"aborted":"error"),s}},async return(s){return _("aborted"),n.return?n.return(s):{done:!0,value:s}},async throw(s){if(_("error"),n.throw)return n.throw(s);throw s}}}}}f(P,"meter");export{P as meter,E as normalize};
1
+ var E=Object.defineProperty;var c=(e,s)=>E(e,"name",{value:s,configurable:!0});const m=["input_tokens","output_tokens","cache_read_input_tokens","cache_creation_input_tokens"],f=c(e=>Number.isFinite(e)?e:null,"count");function B(e,s){if(!s||typeof s!="object")return null;let o;if(e==="openai"){const n=f(s.prompt_tokens),r=f(s.prompt_tokens_details?.cached_tokens);o={input_tokens:n===null?null:Math.max(0,n-(r??0)),output_tokens:f(s.completion_tokens),cache_read_input_tokens:r,cache_creation_input_tokens:null}}else if(e==="folded"){const n=f(s.input_tokens);o={input_tokens:n===null?null:n+(f(s.cache_creation_input_tokens)??0),output_tokens:f(s.output_tokens),cache_read_input_tokens:f(s.cache_read_input_tokens)||null,cache_creation_input_tokens:null}}else o=Object.fromEntries(m.map(n=>[n,f(s[n])]));return m.every(n=>!o[n])?null:o}c(B,"normalize");function I(e){return!!e&&typeof e=="object"&&Array.isArray(e.choices)&&e.choices.length===0&&!!e.usage}c(I,"usageChunk");function O(e,s,o){try{Promise.resolve(s?.(e)).catch(n=>o(`onUsage rejected: ${n?.message??n}`,{kind:"rejected"}))}catch(n){o(`onUsage threw: ${n?.message??n}`,{kind:"threw"})}}c(O,"deliver");const y=c(e=>{const s=e.filter(o=>o!=null);return s.length===0?null:s.reduce((o,n)=>o+n,0)},"total");function S(e,s=-1){const o={...e[0]};for(const r of m)o[r]=y(e.map(d=>d[r]));o.reported=e.some(r=>r.reported);const n=e.map(r=>r.estimated).filter(Boolean);return o.estimated=n.length===0?null:{input_tokens:y(n.map(r=>r.input_tokens)),output_tokens:y(n.map(r=>r.output_tokens))},o.complete=e.every(r=>r.complete),o.reason=(e[s]??e.find(r=>r.reason!=="done")??e[0]).reason,o.model=e.find(r=>r.model)?.model??null,o.upstream=e.find(r=>r.upstream)?.upstream??null,o}c(S,"combine");function A(e,s,o){const n=Object.fromEntries(m.map(t=>[t,null]));let r=!1,d=null,b=!1,w=!1,h=!1,p=null,g="openai",j;const x=new Promise(t=>{j=t}),k=c((t,a=e.front)=>{const l=B(a,t);if(l){r=!0;for(const i of m)l[i]!==null&&l[i]!==void 0&&(n[i]=l[i])}},"take"),_=c(t=>{if(b)return;b=!0,p&&k(p(),g);const a=t==="done"&&w?"error":t,l={...n,reported:r,estimated:d,complete:a==="done",reason:a,...e};j(l),O(l,s,o)},"finish");return{meta:e,usage:x,json(t){h=!0,p||k(t?.usage)},source(t,a="openai"){p=t,g=a},event(t){t==="[DONE]"&&(h=!0),!(!t||typeof t!="object")&&((t.type==="error"||e.front==="openai"&&t.error)&&(w=!0),e.front==="anthropic"?(t.type==="message_stop"&&(h=!0),p||k(t.type==="message_start"?t.message?.usage:t.usage)):p||k(t.usage))},finish:_,estimate(t){d=t},track(t,a,l=!1){const i=t[Symbol.asyncIterator](),v=this;return{[Symbol.asyncIterator](){return this},async next(){try{for(;;){const u=await i.next();if(u.done)_(h?"done":"error");else if(v.event(u.value?.data),l&&I(u.value?.data))continue;return u}}catch(u){throw _(a?.aborted?"aborted":"error"),u}},async return(u){return _("aborted"),i.return?i.return(u):{done:!0,value:u}},async throw(u){if(_("error"),i.throw)return i.throw(u);throw u}}}}}c(A,"meter");export{S as combine,O as deliver,A as meter,B as normalize};
2
2
  //# sourceMappingURL=usage.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/llm-translator",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Bidirectional Anthropic Messages ⇄ OpenAI Chat Completions translator with backend auto-detection (vLLM and other OpenAI-compatible servers), built on slothlet, with an optional standalone server for running Claude Code against local models.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -9,7 +9,7 @@
9
9
  * @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
10
10
  * @param {{ toolCallIds?: { alphabet: string, min?: number, max?: number } }} [context] - `toolCallIds` is the driver's tool-call id policy: ids that do not satisfy it are rewritten (and recorded in `state.toolIds` for the way back).
11
11
  * @returns {Promise<{ body: any, state: any }>} Anthropic request body and conversion state.
12
- * @throws {TranslatorError} For malformed requests, `n` above 1, unknown roles, or unknown fields when configured to error.
12
+ * @throws {TranslatorError} For malformed requests, `n` above 1 (`send` fans that out instead), unknown roles, or unknown fields when configured to error.
13
13
  */
14
14
  export function request(chatBody: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>, context?: {
15
15
  toolCallIds?: {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Match by host name, no network access.
3
+ * @param {any} context - `{ endpoint }`.
4
+ * @returns {{host: string} | null} Facts, or null when the host is not an Azure OpenAI resource.
5
+ */
6
+ export function detect({ endpoint }: any): {
7
+ host: string;
8
+ } | null;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Normalize to the nested OpenAI shape. A prompt refused by Azure's content filter (HTTP 400, `error.code: "content_filter"`) keeps its code and
3
+ * `param`, and its message names the categories that were filtered when `innererror.content_filter_result` says so.
4
+ * @param {number} status - HTTP status.
5
+ * @param {*} body - Parsed upstream error body.
6
+ * @returns {{error: {message: string, type: string | undefined, param: *, code: *}}} Nested error body.
7
+ */
8
+ export function error(status: number, body: any): {
9
+ error: {
10
+ message: string;
11
+ type: string | undefined;
12
+ param: any;
13
+ code: any;
14
+ };
15
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/azure/info.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview Azure OpenAI driver: static facts about the hosted Azure OpenAI API.
17
+ * @module @cldmv/llm-translator/driver/azure
18
+ */
19
+ /**
20
+ * Describe the Azure OpenAI driver. The key goes in the `api-key` header. The real paths come from the `path` leaf, because they depend on the
21
+ * upstream's `apiVersion` and `deployment`; `paths` holds the v1 API paths for a base URL without `/openai`.
22
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
23
+ */
24
+ export function info(): {
25
+ name: string;
26
+ protocol: string;
27
+ order: number;
28
+ auth: string;
29
+ strict: boolean;
30
+ paths: Record<string, string>;
31
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * List the models the Azure OpenAI resource reports (`/openai/v1/models`, or `/openai/models?api-version=...` with the classic URLs). Azure lists
3
+ * base models there, not the resource's deployments, so an upstream that serves deployments should set `models`.
4
+ * @param {any} context - `{ endpoint, transport, signal, timeout }`.
5
+ * @returns {Promise<any[] | null>} Models, or null when unreachable or not a model list.
6
+ */
7
+ export function list(context: any): Promise<any[] | null>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Build the path of a call from the upstream's `apiVersion` and `deployment` (see `lib/azure.mjs`).
3
+ * @param {"chat" | "embeddings" | "models"} kind - Which call.
4
+ * @param {any} context - `{ endpoint, model }`.
5
+ * @returns {string} Path with the `api-version` query when the classic URLs are in use.
6
+ */
7
+ export function path(kind: "chat" | "embeddings" | "models", { endpoint, model }: any): string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Drop tool fields Azure rejects when no tools are present, and send `max_tokens` when the upstream pins an `api-version` older than the one
3
+ * that introduced `max_completion_tokens`. Versions that are not dated (`preview`, `latest`) and the v1 API keep `max_completion_tokens`.
4
+ * @param {any} body - Chat Completions request body.
5
+ * @param {any} [context] - `{ endpoint }`.
6
+ * @returns {any} Normalized body.
7
+ */
8
+ export function request(body: any, context?: any): any;
@@ -0,0 +1,23 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/azure/settings.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview Azure OpenAI driver: translator settings for Azure OpenAI.
17
+ * @module @cldmv/llm-translator/driver/azure
18
+ */
19
+ /**
20
+ * Settings for Azure OpenAI: the same as the OpenAI API (`max_completion_tokens`, `reasoning_effort`, no `top_k`, no prefill continuation).
21
+ * @returns {any} Partial settings.
22
+ */
23
+ export function settings(): any;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Probe an endpoint for LM Studio.
3
+ * @param {any} context - `{ endpoint, transport, signal, timeout, probes }`.
4
+ * @returns {Promise<any | null>} Facts `{ models, loaded }` (ids of chat models, and of those currently loaded), or null when the endpoint is not LM Studio.
5
+ */
6
+ export function detect(context: any): Promise<any | null>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/lmstudio/info.mjs
5
+ * @Date: 2026-10-31T14:00:00-07:00 (1793480400)
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-10-31T14:00:00-07:00 (1793480400)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview LM Studio driver: static facts about the LM Studio local server.
17
+ * @module @cldmv/llm-translator/driver/lmstudio
18
+ */
19
+ /**
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.
22
+ */
23
+ export function info(): {
24
+ name: string;
25
+ protocol: string;
26
+ order: number;
27
+ auth: string;
28
+ strict: boolean;
29
+ probes: string[];
30
+ paths: Record<string, string>;
31
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Drop tool fields when there are no tools.
3
+ * @param {any} body - Chat Completions request body.
4
+ * @returns {any} Normalized body.
5
+ */
6
+ export function request(body: any): any;
@@ -0,0 +1,23 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/lmstudio/settings.mjs
5
+ * @Date: 2026-10-31T14:00:00-07:00 (1793480400)
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-10-31T14:00:00-07:00 (1793480400)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview LM Studio driver: translator settings for the LM Studio local server.
17
+ * @module @cldmv/llm-translator/driver/lmstudio
18
+ */
19
+ /**
20
+ * Settings for LM Studio: the conservative generic set (no `top_k`, no prefill, no thinking switch) with usage on the last content chunk.
21
+ * @returns {any} Partial settings.
22
+ */
23
+ export function settings(): any;
@@ -0,0 +1,25 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/localai/chunk.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview LocalAI driver: streaming chunk normalizer (Chat Completions chunk).
17
+ * @module @cldmv/llm-translator/driver/localai
18
+ */
19
+ /**
20
+ * When the client asked for one tool call at a time, drop the fragments of every call but the first (index 0), see `response`.
21
+ * @param {any} chunk - Parsed `chat.completion.chunk`.
22
+ * @param {any} [ctx] - `{ state }`.
23
+ * @returns {any} Normalized chunk.
24
+ */
25
+ export function chunk(chunk: any, ctx?: any): any;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Probe an endpoint for LocalAI.
3
+ * @param {any} context - `{ endpoint, transport, signal, timeout, probes }`.
4
+ * @returns {Promise<any | null>} Facts `{ version, models }`, or null when the endpoint is not LocalAI.
5
+ */
6
+ export function detect(context: any): Promise<any | null>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/localai/info.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview LocalAI driver: static facts about the LocalAI server.
17
+ * @module @cldmv/llm-translator/driver/localai
18
+ */
19
+ /**
20
+ * Describe the LocalAI driver. It is found through `GET /version` (`{ version: "v3.1.0 (<commit>)" }`) or LocalAI's discovery document at
21
+ * `GET /.well-known/localai.json`. The extra fields are the ones LocalAI's request schema accepts beyond the OpenAI set.
22
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
23
+ */
24
+ export function info(): {
25
+ name: string;
26
+ protocol: string;
27
+ order: number;
28
+ auth: string;
29
+ strict: boolean;
30
+ probes: string[];
31
+ fields: string[];
32
+ paths: Record<string, string>;
33
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Drop tool fields when there are no tools; rename vLLM's `repetition_penalty` to LocalAI's `repeat_penalty`; and take over
3
+ * `parallel_tool_calls: false`. LocalAI does not read that field: whether a model may call several tools in one turn is its YAML
4
+ * `function.parallel_calls`. When the client asked for one call at a time (the Anthropic front's `disable_parallel_tool_use`), the field
5
+ * is removed and `state.localaiSingleCall` makes the response normalizers keep only the first call.
6
+ * @param {any} body - Chat Completions request body.
7
+ * @param {any} [ctx] - `{ state }`.
8
+ * @returns {any} Normalized body.
9
+ */
10
+ export function request(body: any, ctx?: any): any;
@@ -0,0 +1,26 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/localai/response.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview LocalAI driver: response normalizer (Chat Completions body).
17
+ * @module @cldmv/llm-translator/driver/localai
18
+ */
19
+ /**
20
+ * When the client asked for one tool call at a time, keep only the first call of each choice: LocalAI decides by model configuration
21
+ * (`function.parallel_calls`) and ignores the request, so a model configured for parallel calls can still return several.
22
+ * @param {any} body - Chat Completions response body.
23
+ * @param {any} [ctx] - `{ state }`.
24
+ * @returns {any} Normalized body.
25
+ */
26
+ export function response(body: any, ctx?: any): any;
@@ -0,0 +1,25 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/localai/settings.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview LocalAI driver: translator settings for LocalAI servers.
17
+ * @module @cldmv/llm-translator/driver/localai
18
+ */
19
+ /**
20
+ * Settings for LocalAI: reasoning is sent as `reasoning` (LocalAI's own field; it reads `reasoning_content` too, and so does the
21
+ * translator), `max_tokens` as the output cap, `top_k` and `chat_template_kwargs` are accepted, no prefill continuation, and usage on
22
+ * the last content chunk when `stream_options.include_usage` is set.
23
+ * @returns {any} Partial settings.
24
+ */
25
+ export function settings(): any;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Flatten typed content chunks in a streamed delta. While a reasoning model thinks, `delta.content` is a list holding a `thinking` chunk; the
3
+ * switch to the answer is a list with the closing `thinking` chunk and the first `text` chunk; the answer then streams as a plain string.
4
+ * The thinking goes to `reasoning_content` and the text to `content`.
5
+ * @param {any} chunk - Parsed `chat.completion.chunk`.
6
+ * @returns {any} Normalized chunk.
7
+ */
8
+ export function chunk(chunk: any): any;
@@ -0,0 +1,26 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/mistral/detect.mjs
5
+ * @Date: 2026-10-31T14:00:00-07:00 (1793480400)
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-10-31T14:00:00-07:00 (1793480400)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview Mistral driver: matches the api.mistral.ai host.
17
+ * @module @cldmv/llm-translator/driver/mistral
18
+ */
19
+ /**
20
+ * Match by host name, no network access.
21
+ * @param {any} context - `{ endpoint }`.
22
+ * @returns {{host: string} | null} Facts, or null when the endpoint is not api.mistral.ai.
23
+ */
24
+ export function detect({ endpoint }: any): {
25
+ host: string;
26
+ } | null;
@@ -0,0 +1,35 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/mistral/info.mjs
5
+ * @Date: 2026-10-31T14:00:00-07:00 (1793480400)
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-10-31T14:00:00-07:00 (1793480400)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview Mistral driver: static facts about the hosted Mistral API.
17
+ * @module @cldmv/llm-translator/driver/mistral
18
+ */
19
+ /**
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, toolCallIds: {alphabet: string, min: number, max: number}, paths: Record<string,string>}} Driver facts.
22
+ */
23
+ export function info(): {
24
+ name: string;
25
+ protocol: string;
26
+ order: number;
27
+ auth: string;
28
+ strict: boolean;
29
+ toolCallIds: {
30
+ alphabet: string;
31
+ min: number;
32
+ max: number;
33
+ };
34
+ paths: Record<string, string>;
35
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Drop tool fields when there are no tools, send `seed` as `random_seed` and `tool_choice: "required"` as `"any"` (Mistral's spelling).
3
+ * @param {any} body - Chat Completions request body.
4
+ * @returns {any} Normalized body.
5
+ */
6
+ export function request(body: any): any;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Flatten typed content chunks: a reasoning model answers with `content` as a list of `text` and `thinking` chunks. The text becomes the
3
+ * string `content` and the thinking becomes `reasoning_content`.
4
+ * @param {any} body - Chat Completions response body.
5
+ * @returns {any} Normalized body.
6
+ */
7
+ export function response(body: any): any;
@@ -0,0 +1,24 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/mistral/settings.mjs
5
+ * @Date: 2026-10-31T14:00:00-07:00 (1793480400)
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-10-31T14:00:00-07:00 (1793480400)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview Mistral driver: translator settings for the hosted Mistral API.
17
+ * @module @cldmv/llm-translator/driver/mistral
18
+ */
19
+ /**
20
+ * Settings for api.mistral.ai: reasoning is read from typed content chunks (flattened by the response normalizers into `reasoning_content`),
21
+ * no `top_k`, no prefill continuation, and usage on the last content chunk. Reasoning depth is chosen by the model, so no thinking switch is sent.
22
+ * @returns {any} Partial settings.
23
+ */
24
+ export function settings(): any;
@@ -0,0 +1,25 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/openrouter/chunk.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview OpenRouter driver: streaming chunk normalizer (Chat Completions chunk).
17
+ * @module @cldmv/llm-translator/driver/openrouter
18
+ */
19
+ /**
20
+ * Give an error that sits on a choice the top-level `error` the stream converter and OpenRouter's own mid-stream errors use, so the Anthropic
21
+ * front ends the stream with an `error` event carrying the provider's message. A chunk that already has an `error` or no choice error passes unchanged.
22
+ * @param {any} chunk - Parsed `chat.completion.chunk`.
23
+ * @returns {any} Normalized chunk.
24
+ */
25
+ export function chunk(chunk: any): any;
@@ -0,0 +1,26 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/openrouter/detect.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview OpenRouter driver: matches the openrouter.ai host.
17
+ * @module @cldmv/llm-translator/driver/openrouter
18
+ */
19
+ /**
20
+ * Match by host name, no network access.
21
+ * @param {any} context - `{ endpoint }`.
22
+ * @returns {{host: string} | null} Facts, or null when the endpoint is not openrouter.ai.
23
+ */
24
+ export function detect({ endpoint }: any): {
25
+ host: string;
26
+ } | null;
@@ -0,0 +1,30 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/driver/openrouter/info.mjs
5
+ * @Date: 2026-11-13T09:00:00-08:00 (1794589200)
6
+ * @Author: Nate Corcoran <CLDMV>
7
+ * @Email: <Shinrai@users.noreply.github.com>
8
+ * -----
9
+ * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
+ * @Last modified time: 2026-11-13T09:00:00-08:00 (1794589200)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ /**
16
+ * @fileoverview OpenRouter driver: static facts about the hosted OpenRouter API.
17
+ * @module @cldmv/llm-translator/driver/openrouter
18
+ */
19
+ /**
20
+ * Describe the OpenRouter driver. The API lives under `/api`; the `path` leaf adds it, so `paths` holds the usual `/v1/...` ones.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
22
+ */
23
+ export function info(): {
24
+ name: string;
25
+ protocol: string;
26
+ order: number;
27
+ auth: string;
28
+ strict: boolean;
29
+ paths: Record<string, string>;
30
+ };