@cldmv/llm-translator 0.2.0 → 0.3.1
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 +12 -6
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +11 -11
- package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +1 -1
- package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +1 -1
- package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +3 -3
- package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
- package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +1 -1
- package/dist/api/detect.mjs +1 -1
- package/dist/api/driver/anthropic/token/count.mjs +1 -1
- package/dist/api/driver/compatible/detect.mjs +1 -1
- package/dist/api/driver/compatible/info.mjs +1 -1
- package/dist/api/driver/deepseek/detect.mjs +2 -0
- package/dist/api/driver/deepseek/error.mjs +2 -0
- package/dist/api/driver/deepseek/info.mjs +2 -0
- package/dist/api/driver/deepseek/request.mjs +2 -0
- package/dist/api/driver/deepseek/settings.mjs +2 -0
- package/dist/api/driver/llamacpp/chunk.mjs +2 -0
- package/dist/api/driver/llamacpp/detect.mjs +2 -0
- package/dist/api/driver/llamacpp/flush.mjs +2 -0
- package/dist/api/driver/llamacpp/info.mjs +2 -0
- package/dist/api/driver/llamacpp/request.mjs +2 -0
- package/dist/api/driver/llamacpp/response.mjs +2 -0
- package/dist/api/driver/llamacpp/settings.mjs +2 -0
- package/dist/api/driver/ollama/detect.mjs +2 -0
- package/dist/api/driver/ollama/info.mjs +2 -0
- package/dist/api/driver/ollama/request.mjs +2 -0
- package/dist/api/driver/ollama/settings.mjs +2 -0
- package/dist/api/driver/sglang/detect.mjs +2 -0
- package/dist/api/driver/sglang/info.mjs +2 -0
- package/dist/api/driver/sglang/request.mjs +2 -0
- package/dist/api/driver/sglang/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +1 -1
- package/dist/api/driver/vllm/info.mjs +1 -1
- package/dist/api/endpoint/status.mjs +2 -0
- package/dist/api/error/error.mjs +1 -1
- package/dist/api/model/get.mjs +2 -0
- package/dist/api/request.mjs +2 -2
- package/dist/api/route.mjs +2 -0
- package/dist/api/send.mjs +1 -1
- package/dist/api/server/plugin.mjs +1 -1
- package/dist/api/server/start.mjs +1 -1
- package/dist/api/status.mjs +1 -1
- package/dist/api/stream.mjs +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +1 -1
- package/dist/lib/backends.mjs +2 -0
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/cli.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/ids.mjs +1 -1
- package/dist/lib/models.mjs +1 -1
- package/dist/lib/passthrough.mjs +1 -1
- package/dist/lib/pool.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/thinking.mjs +2 -1
- package/dist/lib/tools.mjs +2 -0
- package/dist/lib/toolsearch.mjs +3 -0
- package/dist/lib/transport.mjs +1 -1
- package/dist/lib/usage.mjs +2 -0
- package/package.json +17 -7
- package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +6 -15
- package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +3 -16
- package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +1 -15
- package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +1 -15
- package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +3 -17
- package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +1 -15
- package/types/src/api/detect.d.mts +1 -15
- package/types/src/api/driver/anthropic/detect.d.mts +1 -1
- package/types/src/api/driver/anthropic/info.d.mts +1 -1
- package/types/src/api/driver/anthropic/model/list.d.mts +1 -15
- package/types/src/api/driver/anthropic/settings.d.mts +1 -1
- package/types/src/api/driver/anthropic/token/count.d.mts +1 -15
- package/types/src/api/driver/compatible/detect.d.mts +2 -16
- package/types/src/api/driver/compatible/info.d.mts +3 -20
- package/types/src/api/driver/compatible/model/list.d.mts +1 -15
- package/types/src/api/driver/compatible/request.d.mts +1 -15
- package/types/src/api/driver/compatible/settings.d.mts +1 -1
- package/types/src/api/driver/deepseek/detect.d.mts +26 -0
- package/types/src/api/driver/deepseek/error.d.mts +14 -0
- package/types/src/api/driver/deepseek/info.d.mts +29 -0
- package/types/src/api/driver/deepseek/request.d.mts +8 -0
- package/types/src/api/driver/deepseek/settings.d.mts +25 -0
- package/types/src/api/driver/llamacpp/chunk.d.mts +7 -0
- package/types/src/api/driver/llamacpp/detect.d.mts +6 -0
- package/types/src/api/driver/llamacpp/flush.d.mts +26 -0
- package/types/src/api/driver/llamacpp/info.d.mts +31 -0
- package/types/src/api/driver/llamacpp/request.d.mts +8 -0
- package/types/src/api/driver/llamacpp/response.d.mts +8 -0
- package/types/src/api/driver/llamacpp/settings.d.mts +27 -0
- package/types/src/api/driver/ollama/detect.d.mts +6 -0
- package/types/src/api/driver/ollama/info.d.mts +30 -0
- package/types/src/api/driver/ollama/request.d.mts +8 -0
- package/types/src/api/driver/ollama/settings.d.mts +7 -0
- package/types/src/api/driver/openai/detect.d.mts +1 -1
- package/types/src/api/driver/openai/info.d.mts +1 -1
- package/types/src/api/driver/openai/model/list.d.mts +1 -15
- package/types/src/api/driver/openai/request.d.mts +1 -15
- package/types/src/api/driver/openai/settings.d.mts +1 -1
- package/types/src/api/driver/sglang/detect.d.mts +6 -0
- package/types/src/api/driver/sglang/info.d.mts +31 -0
- package/types/src/api/driver/sglang/request.d.mts +8 -0
- package/types/src/api/driver/sglang/settings.d.mts +24 -0
- package/types/src/api/driver/vllm/detect.d.mts +3 -17
- package/types/src/api/driver/vllm/error.d.mts +1 -15
- package/types/src/api/driver/vllm/info.d.mts +3 -20
- package/types/src/api/driver/vllm/model/list.d.mts +1 -15
- package/types/src/api/driver/vllm/probe.d.mts +1 -15
- package/types/src/api/driver/vllm/request.d.mts +1 -15
- package/types/src/api/driver/vllm/settings.d.mts +1 -15
- package/types/src/api/driver/vllm/token/count.d.mts +1 -15
- package/types/src/api/endpoint/status.d.mts +27 -0
- package/types/src/api/error/build.d.mts +1 -15
- package/types/src/api/error/error.d.mts +1 -15
- package/types/src/api/model/get.d.mts +9 -0
- package/types/src/api/model/list.d.mts +1 -15
- package/types/src/api/request.d.mts +8 -17
- package/types/src/api/response.d.mts +1 -15
- package/types/src/api/route.d.mts +18 -0
- package/types/src/api/send.d.mts +21 -16
- package/types/src/api/server/plugin.d.mts +6 -19
- package/types/src/api/server/start.d.mts +2 -16
- package/types/src/api/server/stop.d.mts +1 -15
- package/types/src/api/sse/encode.d.mts +1 -15
- package/types/src/api/sse/parse.d.mts +1 -15
- package/types/src/api/sse/ping.d.mts +1 -15
- package/types/src/api/sse/write.d.mts +1 -15
- package/types/src/api/status.d.mts +2 -16
- package/types/src/api/stream.d.mts +1 -15
- package/types/src/api/token/count.d.mts +1 -15
- package/types/src/index.d.mts +24 -34
- package/types/src/lib/arguments.d.mts +2 -16
- package/types/src/lib/backends.d.mts +21 -0
- package/types/src/lib/capture.d.mts +2 -16
- package/types/src/lib/cli.d.mts +12 -26
- package/types/src/lib/config.d.mts +11 -25
- package/types/src/lib/documents.d.mts +16 -27
- package/types/src/lib/errors.d.mts +75 -75
- package/types/src/lib/estimate.d.mts +58 -7
- package/types/src/lib/finish.d.mts +4 -4
- package/types/src/lib/http.d.mts +19 -5
- package/types/src/lib/ids.d.mts +11 -20
- package/types/src/lib/images.d.mts +19 -19
- package/types/src/lib/models.d.mts +13 -13
- package/types/src/lib/normalize.d.mts +3 -3
- package/types/src/lib/passthrough.d.mts +11 -17
- package/types/src/lib/pdf.d.mts +4 -18
- package/types/src/lib/ping.d.mts +1 -15
- package/types/src/lib/pool.d.mts +124 -0
- package/types/src/lib/route.d.mts +31 -24
- package/types/src/lib/routes.d.mts +10 -15
- package/types/src/lib/runtime.d.mts +2 -16
- package/types/src/lib/schema.d.mts +1 -15
- package/types/src/lib/settings.d.mts +68 -54
- package/types/src/lib/source.d.mts +2 -2
- package/types/src/lib/sse.d.mts +21 -32
- package/types/src/lib/thinking.d.mts +117 -22
- package/types/src/lib/tools.d.mts +28 -0
- package/types/src/lib/toolsearch.d.mts +91 -0
- package/types/src/lib/transport.d.mts +3 -16
- package/types/src/lib/upstream-error.d.mts +4 -18
- package/types/src/lib/usage.d.mts +91 -0
- package/types/src/lib/warn.d.mts +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=Object.defineProperty;var s=(t,r)=>m(t,"name",{value:r,configurable:!0});import{context as g,self as
|
|
1
|
+
var m=Object.defineProperty;var s=(t,r)=>m(t,"name",{value:r,configurable:!0});import{context as g,self as u}from"../../lib/runtime.mjs";import{TranslatorError as c}from"../../lib/errors.mjs";import{isLoopback as b}from"../../lib/http.mjs";async function L(t={}){const{state:r}=g,{plugin:d}=u.server,{build:h}=u.error;let i;try{({default:i}=await import("fastify"))}catch(o){throw new c('server.start needs the optional peer dependency "fastify" (npm install fastify)',{code:"fastify_missing",status:500,details:{cause:o}})}const e=t.host??"127.0.0.1";if(!b(e)&&[t.apiKey??[]].flat().filter(Boolean).length===0&&typeof t.authorize!="function"&&t.allowUnauthenticated!==!0)throw new c(`Refusing to listen on ${e} without an apiKey or an authorize hook: anyone who can reach the port could use the upstream. Set \`apiKey\` (CLI: --api-key) or \`authorize\`, bind to 127.0.0.1, or opt in with \`allowUnauthenticated: true\` (CLI: --allow-unauthenticated).`,{code:"unauthenticated_bind",status:500});const a=i({logger:t.logger??!1,forceCloseConnections:!0});a.setNotFoundHandler((o,f)=>{const{status:y,headers:p,body:w}=h(404,`Not found: ${o.method} ${o.url}`);return f.code(y).headers(p).send(w)}),await a.register(d,{front:t.front,apiKey:t.apiKey,bodyLimit:t.bodyLimit,authorize:t.authorize,onUsage:t.onUsage}),await a.listen({host:e,port:t.port??8787});const l=a.server.address().port,n={url:`http://${e.includes(":")?`[${e}]`:e}:${l}`,host:e,port:l,app:a,close:s(async()=>{r.servers.delete(n),await a.close()},"close")};return r.servers.add(n),n}s(L,"start");export{L as start};
|
|
2
2
|
//# sourceMappingURL=start.mjs.map
|
package/dist/api/status.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var c=Object.defineProperty;var o=(s,a)=>c(s,"name",{value:a,configurable:!0});import{context as
|
|
1
|
+
var c=Object.defineProperty;var o=(s,a)=>c(s,"name",{value:a,configurable:!0});import{context as e}from"../lib/runtime.mjs";import{describe as t}from"../lib/pool.mjs";function u(){const{config:s,state:a}=e;return{front:s.front,upstreams:a.endpoints.map(r=>({name:r.name,url:r.url,backend:r.backend,driver:r.driver,protocol:r.protocol,version:r.facts?.version??r.version,models:r.models??r.facts?.models??[],default:r.default,facts:r.facts,probed:r.probed,health:t(r)}))}}o(u,"status");export{u as status};
|
|
2
2
|
//# sourceMappingURL=status.mjs.map
|
package/dist/api/stream.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x=Object.defineProperty;var i=(e,o)=>x(e,"name",{value:o,configurable:!0});import{context as b,self as j}from"../lib/runtime.mjs";import{capture as A}from"../lib/capture.mjs";import{messages as p}from"../lib/sse.mjs";function u(e,o){return!o||!e||typeof e!="object"?e:e.message&&typeof e.message=="object"&&e.message.model!==void 0?{...e,message:{...e.message,model:o}}:e.model===void 0?e:{...e,model:o}}i(u,"restore");function B(e){return!!e&&Array.isArray(e.choices)&&(e.choices.length===0||e.choices.some(o=>o?.finish_reason))}i(B,"ends");function k(e,o){const r=A(j,b,o.front),c=r.endpoint(o.upstream),a=r.driver(c),l=r.settings(c),f=r.converters(c),s=a.chunk,d={endpoint:c,settings:l,state:o};async function*m(){for(const n of await a.flush?.(d)??[])yield{data:n}}if(i(m,"flushed"),f&&!s)return f.stream(e,o.convert,l);if(f)return f.stream((async function*(){for await(const n of p(e))n.data!=="[DONE]"&&(yield await s(n.data,d));for await(const n of m())yield n.data})(),o.convert,l);const w=!!(s&&a.flush);return(async function*(){const n=[];let y=!1;for await(const t of p(e)){if(t.data==="[DONE]"){for await(const v of m())yield{data:u(v.data,o.model)};yield*n.splice(0),y=!0,yield t;continue}const h=s?await s(t.data,d):t.data,g={...t,data:u(h,o.model)};w&&B(h)?n.push(g):yield g}if(!y){for await(const t of m())yield{data:u(t.data,o.model)};yield*n}})()}i(k,"stream");export{k as stream};
|
|
2
2
|
//# sourceMappingURL=stream.mjs.map
|
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
8
|
* -----
|
|
9
9
|
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-
|
|
10
|
+
* @Last modified time: 2026-11-01T16:24:44-08:00 (1793579084)
|
|
11
11
|
* -----
|
|
12
12
|
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
13
|
*
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* so this shim re-exports dist/index.mjs instead of tsup bundling a second,
|
|
22
22
|
* independent copy of the library for the CJS format.
|
|
23
23
|
*
|
|
24
|
-
* Node.js versions without require(esm) (before
|
|
24
|
+
* Node.js versions without require(esm) (before 24) would fail with
|
|
25
25
|
* a bare ERR_REQUIRE_ESM, so the check below fails early with a message that
|
|
26
26
|
* says what to do instead.
|
|
27
27
|
*
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
if (!process.features?.require_module) {
|
|
37
37
|
const error = new Error(
|
|
38
|
-
`@cldmv/llm-translator: require() needs Node.js
|
|
38
|
+
`@cldmv/llm-translator: require() needs Node.js >=24.0.0 (this is ${process.version}). On older Node.js, load the package with import() instead.`
|
|
39
39
|
);
|
|
40
40
|
error.code = "ERR_REQUIRE_ESM";
|
|
41
41
|
throw error;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var i=Object.defineProperty;var n=(r,t)=>i(r,"name",{value:t,configurable:!0});import{fileURLToPath as d}from"node:url";import p from"@cldmv/slothlet";import{normalize as l}from"./lib/config.mjs";import{
|
|
1
|
+
var i=Object.defineProperty;var n=(r,t)=>i(r,"name",{value:t,configurable:!0});import{fileURLToPath as d}from"node:url";import p from"@cldmv/slothlet";import{normalize as l}from"./lib/config.mjs";import{load as m}from"./lib/pdf.mjs";import{transport as c}from"./lib/transport.mjs";import{warn as s}from"./lib/warn.mjs";async function f(r){const t=l(r),o={endpoints:t.endpoints,transport:t.transport??c,servers:new Set,warned:new Set,textOnly:new Set,cursors:new Map,front:void 0},e=await m();e.errors.canvas&&s(t,o,`@napi-rs/canvas could not be loaded (${e.errors.canvas}); PDFs will be read as text only, without page images`),e.errors.unpdf&&s(t,o,`unpdf could not be loaded (${e.errors.unpdf}); PDF documents cannot be read and fall back to a note`);const a=await p({...r.slothlet,base:d(new URL("./api",import.meta.url)),mode:"eager",context:{config:t,state:o},silent:!0});return await a.detect({network:t.detect}),a}n(f,"createTranslator");import{TranslatorError as T}from"./lib/errors.mjs";var y=f;export{T as TranslatorError,f as createTranslator,y as default};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.defineProperty;var t=(o,n)=>e(o,"name",{value:n,configurable:!0});const i=["default_generation_settings","total_slots","build_info"];function r(o){return o.ok&&o.body!==null&&typeof o.body=="object"?o.body:{}}t(r,"objectOf");function f(o){return i.some(n=>n in o)}t(f,"isLlamacppProps");function a(o){return typeof o.model_path=="string"||typeof o.tokenizer_path=="string"}t(a,"isSglangInfo");export{f as isLlamacppProps,a as isSglangInfo,r as objectOf};
|
|
2
|
+
//# sourceMappingURL=backends.mjs.map
|
package/dist/lib/capture.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=Object.defineProperty;var n=(o,r)=>m(o,"name",{value:r,configurable:!0});import{resolve as v}from"./settings.mjs";function g(o){const r=[];for(const s of Object.keys(o??{})){const e=o[s];typeof e?.info=="function"&&r.push({name:s,info:e.info(),detect:e.detect,settings:e.settings,probe:e.probe,request:e.request,response:e.response,chunk:e.chunk,flush:e.flush,error:e.error,count:e.token?.count,list:e.model?.list})}return r.sort((s,e)=>s.info.order-e.info.order)}n(g,"collect");function b(o,r,s){const{config:e,state:u}=r,c=o.convert.anthropic.messages.to.openai.chat,i=o.convert.openai.chat.to.anthropic.messages,a=s??e.front,f=g(o.driver),h=a==="anthropic"?"anthropic.messages":"openai.chat",d=a==="anthropic"?{request:c.request,response:i.response,stream:i.stream}:{request:i.request,response:c.response,stream:c.stream};return{config:e,state:u,front:a,drivers:f,endpoint:n(t=>u.endpoints.find(p=>p.name===t),"endpoint"),driver:n(t=>f.find(p=>p.name===t.driver),"driver"),settings:n(t=>v(t.driverSettings,t.probed,e.settings,t.settings),"settings"),converters:n(t=>t.protocol===h?null:d,"converters")}}n(b,"capture");export{b as capture,g as collect};
|
|
2
2
|
//# sourceMappingURL=capture.mjs.map
|
package/dist/lib/cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@ Options:
|
|
|
6
6
|
--front <anthropic|openai> Client protocol to serve (default anthropic)
|
|
7
7
|
--upstream <url> Upstream server base URL (repeatable)
|
|
8
8
|
--upstream-key <key> API key sent to the upstream
|
|
9
|
-
--backend <name> Driver for the upstream (default auto-detect: vllm, compatible, openai, anthropic)
|
|
9
|
+
--backend <name> Driver for the upstream (default auto-detect: vllm, llamacpp, compatible, openai, anthropic)
|
|
10
10
|
--model <alias=target> Model alias (repeatable)
|
|
11
11
|
--host <host> Listen address (default 127.0.0.1)
|
|
12
12
|
--port <port> Listen port (default 8787)
|
package/dist/lib/config.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var o=Object.defineProperty;var s=(t,r)=>o(t,"name",{value:r,configurable:!0});import{TranslatorError as a}from"./errors.mjs";import*as n from"./pool.mjs";function i(t){let r=t.length;for(;t[r-1]==="/";)r--;const e=t.slice(0,r);return e.endsWith("/v1")?e.slice(0,-3):e}s(i,"baseUrl");function l(t,r){const e=typeof t=="string"?{url:t}:t;if(!e||typeof e!="object"||typeof e.url!="string"||e.url==="")throw new a(`upstreams[${r}] needs a "url"`,{code:"INVALID_CONFIG",status:500});return{name:e.name??`upstream-${r}`,url:i(e.url),apiKey:e.apiKey,headers:{...e.headers},backend:e.backend??"auto",models:Array.isArray(e.models)?[...e.models]:void 0,default:e.default===!0,settings:{...e.settings},version:e.version,driver:null,facts:null,driverSettings:{},probed:{},health:n.health()}}s(l,"endpoint");function p(t={}){const r=t.front??"anthropic";if(r!=="anthropic"&&r!=="openai")throw new a(`front must be "anthropic" or "openai" (got ${JSON.stringify(r)})`,{code:"INVALID_CONFIG",status:500});let e=t.upstreams??t.upstream;if(e!==void 0&&!Array.isArray(e)&&(e=[e]),!e||e.length===0)throw new a("at least one upstream is required (config.upstreams)",{code:"INVALID_CONFIG",status:500});return{front:r,endpoints:e.map(l),aliases:{...t.aliases},pool:n.normalize(t.pool),settings:{...t.settings},detect:t.detect!==!1,detectTimeout:t.detectTimeout??5e3,transport:t.transport,silent:t.silent===!0}}s(p,"normalize");export{l as endpoint,p as normalize};
|
|
2
2
|
//# sourceMappingURL=config.mjs.map
|
package/dist/lib/estimate.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var p=Object.defineProperty;var i=(n,s)=>p(n,"name",{value:s,configurable:!0});const m=4,u=i(n=>Math.ceil(n/4),"tokens");function x(n){return u(JSON.stringify([n.system,n.messages,n.tools]).length)}i(x,"estimate");const a=i((...n)=>{let s=0;for(const t of n)typeof t=="string"&&(s+=t.length);return s},"length");function _(n,s){if(n==="anthropic"){if(s?.type==="content_block_start")return a(s.content_block?.name);const o=s?.type==="content_block_delta"?s.delta:null;return a(o?.text,o?.thinking,o?.partial_json)}const t=s?.choices?.[0]?.delta;let e=a(t?.content,t?.reasoning,t?.reasoning_content);for(const o of t?.tool_calls??[])e+=a(o.function?.name,o.function?.arguments);return e}i(_,"eventLength");function y(n,s){let t=0;if(n==="anthropic"){for(const o of s?.content??[])t+=a(o.text,o.thinking,o.name),o.type==="tool_use"&&(t+=JSON.stringify(o.input).length);return t}const e=s?.choices?.[0]?.message;t=a(e?.content,e?.reasoning,e?.reasoning_content);for(const o of e?.tool_calls??[])t+=a(o.function?.name,o.function?.arguments);return t}i(y,"bodyLength");const f=i(n=>Math.max(1,u(n)),"output");function g(n,s,t){const e={...s};return n==="anthropic"?(t.input_tokens!==null&&(e.input_tokens=t.input_tokens),t.output_tokens!==null&&(e.output_tokens=t.output_tokens),e):(t.input_tokens!==null&&(e.prompt_tokens=t.input_tokens),t.output_tokens!==null&&(e.completion_tokens=t.output_tokens),e.total_tokens=(e.prompt_tokens??0)+(e.completion_tokens??0),e)}i(g,"patch");async function*d(n,s,t){let e=0;for await(const o of s){const l=o?.data;e+=_(n,l);const r=(n==="anthropic"?l?.type==="message_delta":Array.isArray(l?.choices)&&l.choices.length===0&&l.usage)?t.gaps():null;if(r&&(r.input||r.output)){const c={input_tokens:r.input?await t.input():null,output_tokens:r.output?f(e):null};t.report(c),yield{...o,data:{...l,usage:g(n,l.usage,c)}}}else yield o}}i(d,"stream");export{m as CHARS_PER_TOKEN,y as bodyLength,x as estimate,_ as eventLength,f as output,g as patch,d as stream,u as tokens};
|
|
2
2
|
//# sourceMappingURL=estimate.mjs.map
|
package/dist/lib/http.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var y=Object.defineProperty;var o=(t,e)=>y(t,"name",{value:e,configurable:!0});function
|
|
1
|
+
var y=Object.defineProperty;var o=(t,e)=>y(t,"name",{value:e,configurable:!0});function d(t,e){return t+e}o(d,"join");function p(t){return t==="localhost"||t==="::1"||/^127\./.test(t)}o(p,"isLoopback");function x(t,e="bearer",n){const r={...t.headers};return t.apiKey&&(e==="x-api-key"?r["x-api-key"]=t.apiKey:r.authorization=`Bearer ${t.apiKey}`),{...r,...n}}o(x,"headers");function b({endpoint:t,transport:e,signal:n,timeout:r,probes:a},i){const f=o(()=>g(e,d(t.url,i),{method:"GET",headers:x(t),signal:n,timeout:r}),"run");return a?(a.has(i)||a.set(i,f()),a.get(i)):f()}o(b,"probe");function k(t){const e={};if(!t)return e;if(typeof t.forEach=="function")return t.forEach((n,r)=>{e[r.toLowerCase()]=n}),e;for(const[n,r]of Object.entries(t))e[n.toLowerCase()]=String(r);return e}o(k,"plain");async function g(t,e,n={}){const{timeout:r,signal:a,body:i,...f}=n,s=[];a&&s.push(a),r>0&&s.push(AbortSignal.timeout(r));try{const u=await t(e,{...f,redirect:"error",body:i===void 0?void 0:JSON.stringify(i),signal:s.length>1?AbortSignal.any(s):s[0]}),c=await u.text();let l=null;try{l=JSON.parse(c)}catch{l=c===""?null:c}return{ok:u.ok,status:u.status,body:l}}catch(u){return{ok:!1,status:0,body:null,error:u}}}o(g,"json");export{x as headers,p as isLoopback,d as join,g as json,k as plain,b as probe};
|
|
2
2
|
//# sourceMappingURL=http.mjs.map
|
package/dist/lib/ids.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var f=Object.defineProperty;var n=(t,r)=>f(t,"name",{value:r,configurable:!0});import{randomBytes as
|
|
1
|
+
var f=Object.defineProperty;var n=(t,r)=>f(t,"name",{value:r,configurable:!0});import{randomBytes as p,createHash as h}from"node:crypto";function i(t=12){return p(t).toString("hex")}n(i,"random");function $(){return`msg_${i()}`}n($,"messageId");function a(){return`toolu_${i()}`}n(a,"toolUseId");function d(){return`chatcmpl-${i()}`}n(d,"completionId");function x(){return`call_${i()}`}n(x,"callId");function O(t){return typeof t!="string"||t===""?a():t.replace(/[^a-zA-Z0-9_-]/g,"_")}n(O,"anthropicToolId");function b({max:t,map:r={}}){const u=new Map(Object.entries(r).map(([e,c])=>[c,e]));return e=>{if(e.length<=t&&/^[a-zA-Z0-9_-]+$/.test(e))return e;if(u.has(e))return u.get(e);const c=e.replace(/[^a-zA-Z0-9_-]/g,"_");let o=c;if(c.length>t||c===""){const s=h("sha256").update(e).digest("hex").slice(0,8);o=`${c.slice(0,t-9)}_${s}`}const l=o;for(let s=2;Object.hasOwn(r,o);s++)o=`${l.slice(0,t-4)}_${s}`;return r[o]=e,u.set(e,o),o}}n(b,"createNameFitter");function I(t,r){return Object.hasOwn(t,r)?t[r]:r}n(I,"restoreName");export{O as anthropicToolId,x as callId,d as completionId,b as createNameFitter,$ as messageId,I as restoreName,a as toolUseId};
|
|
2
2
|
//# sourceMappingURL=ids.mjs.map
|
package/dist/lib/models.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var f=Object.defineProperty;var
|
|
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};
|
|
2
2
|
//# sourceMappingURL=models.mjs.map
|
package/dist/lib/passthrough.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i=Object.defineProperty;var a=(t,o)=>i(t,"name",{value:o,configurable:!0});const p=["model","messages","stream","stream_options","max_tokens","max_completion_tokens","temperature","top_p","n","stop","presence_penalty","frequency_penalty","logit_bias","logprobs","top_logprobs","seed","response_format","tools","tool_choice","parallel_tool_calls","reasoning_effort","user","metadata","store","service_tier"],m=["top_k","min_p","repetition_penalty","length_penalty","min_tokens","stop_token_ids","include_stop_str_in_output","ignore_eos","skip_special_tokens","spaces_between_special_tokens","allowed_token_ids","bad_words","prompt_logprobs","truncate_prompt_tokens","add_generation_prompt","continue_final_message","add_special_tokens","chat_template_kwargs","thinking_token_budget","include_reasoning","structured_outputs"],l=new Set(p),c=new Set(["include_usage","continuous_usage_stats"]);function d(t,o=[]){const s={};for(const[e,n]of Object.entries(t))if(!(!l.has(e)&&!o.includes(e)))if(e==="stream_options"){const _=Object.fromEntries(Object.entries(n??{}).filter(([r])=>c.has(r)));Object.keys(_).length>0&&(s.stream_options=_)}else s[e]=n;return s}a(d,"filterChatBody");export{m as VLLM_FIELDS,d as filterChatBody};
|
|
2
2
|
//# sourceMappingURL=passthrough.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var p=Object.defineProperty;var c=(t,r)=>p(t,"name",{value:r,configurable:!0});import{TranslatorError as g}from"./errors.mjs";const b=Object.freeze(["failover","round_robin","least_busy"]),m=Object.freeze({base:1e3,max:6e4}),d=Object.freeze({connect:1e4,headers:0});function T(){return{failures:0,until:0,inflight:0,requests:0,errors:0,lastError:null,lastFailure:null,lastSuccess:null}}c(T,"health");function S(t={}){const r=c(u=>new g(`pool: ${u}`,{code:"INVALID_CONFIG",status:500}),"bad");if(!t||typeof t!="object"||Array.isArray(t))throw r("must be an object");const e=t.strategy??"failover",s={...t.models};for(const[u,l]of[["strategy",e],...Object.entries(s).map(([n,f])=>[`models.${n}`,f])])if(!b.includes(l))throw r(`${u} must be one of ${b.join(", ")} (got ${JSON.stringify(l)})`);const o=t.backoff?.base??m.base,a=t.backoff?.max??m.max;if(!(Number.isFinite(o)&&o>0)||!(Number.isFinite(a)&&a>=o))throw r("backoff.base must be a positive number of ms and backoff.max at least backoff.base");const h=t.connectTimeout??d.connect,i=t.headersTimeout??d.headers;for(const u of["connectTimeout","headersTimeout"]){const l=u==="connectTimeout"?h:i;if(typeof l!="number"||!(Number.isFinite(l)&&l>=0))throw r(`${u} must be a number of ms, 0 or more (got ${JSON.stringify(l)})`)}return{strategy:e,backoff:{base:o,max:a},connectTimeout:h,headersTimeout:i,models:s}}c(S,"normalize");function F(t,r,e,s,o,a=Date.now()){const h=t.pool.models[s]??t.pool.strategy,i=e.filter(n=>n.health.until<=a),u=e.filter(n=>n.health.until>a).sort((n,f)=>n.health.until-f.health.until);let l=i;if(h==="least_busy")l=[...i].sort((n,f)=>n.health.inflight-f.health.inflight);else if(h==="round_robin"&&i.length>0){const n=r.cursors.get(s)??0;o&&r.cursors.set(s,n+1);const f=n%i.length;l=[...i.slice(f),...i.slice(0,f)]}return[...l,...u]}c(F,"order");function O(t,r,e,s=Date.now()){const o=r.health;o.failures++,o.errors++,o.lastError=e,o.lastFailure=s;const{base:a,max:h}=t.pool.backoff;o.until=s+Math.min(h,a*2**Math.min(o.failures-1,30))}c(O,"failed");function E(t,r=Date.now()){const e=t.health;e.failures=0,e.until=0,e.lastSuccess=r}c(E,"succeeded");function j(t,r=Date.now()){const e=t.health,s=c(a=>a===null?null:new Date(a).toISOString(),"iso"),o=e.until>r;return{healthy:!o,failures:e.failures,retryAt:o?s(e.until):null,inflight:e.inflight,requests:e.requests,errors:e.errors,lastError:e.lastError,lastFailure:s(e.lastFailure),lastSuccess:s(e.lastSuccess)}}c(j,"describe");export{m as BACKOFF,b as STRATEGIES,d as TIMEOUTS,j as describe,O as failed,T as health,S as normalize,F as order,E as succeeded};
|
|
2
|
+
//# sourceMappingURL=pool.mjs.map
|
package/dist/lib/route.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var f=Object.defineProperty;var u=(e,t)=>f(e,"name",{value:t,configurable:!0});import{TranslatorError as c}from"./errors.mjs";import{order as m}from"./pool.mjs";function p(e,t){return(e.models??e.facts?.models??[]).includes(t)?!0:e.protocol==="anthropic.messages"&&e.models===void 0&&/^claude-/.test(t)}u(p,"serves");function v(e,t,o,n,a=!1){const d=Object.hasOwn(e.aliases,o)?e.aliases[o]:o,s=t.filter(l=>p(l,d)),r=t.find(l=>l.default)??t[0];if(s.length>0){const l=m(e,n,s,d,a);return{endpoint:l[0],model:d,unserved:!1,pool:l}}const i=r.models??r.facts?.models??[];return i.length===1?{endpoint:r,model:i[0],unserved:!1,pool:[r]}:{endpoint:r,model:d,unserved:!0,pool:[r]}}u(v,"pick");function k(e,t,o={}){if(!t||typeof t!="object"||Array.isArray(t))throw new c("The request body must be a JSON object",{code:"invalid_body",status:400});const n=v(e.config,e.state.endpoints,t.model,e.state,o.advance===!0);if(o.endpoint!==void 0){const s=n.pool.find(r=>r.name===o.endpoint);if(!s)throw new c(`Endpoint ${o.endpoint} no longer serves ${n.model}`,{code:"endpoint_not_in_pool",status:500});return{endpoint:s,model:n.model,requested:t.model,unserved:n.unserved,convert:e.converters(s),pool:[s]}}const{endpoint:a,pool:d}=n;return{endpoint:a,model:n.model,requested:t.model,unserved:n.unserved,convert:e.converters(a),pool:d}}u(k,"resolve");export{v as pick,k as resolve,p as serves};
|
|
2
2
|
//# sourceMappingURL=route.mjs.map
|
package/dist/lib/routes.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var A=Object.defineProperty;var i=(e,n)=>A(e,"name",{value:n,configurable:!0});import{timingSafeEqual as H}from"node:crypto";import{TranslatorError as _}from"./errors.mjs";import{messageId as O}from"./ids.mjs";import{sign as S}from"./thinking.mjs";const T=64*1024*1024,j={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"},p=Symbol("stalled"),w=Symbol("gone");async function D(e,n){if(!(n>0))return e;let s;const c=new Promise(f=>{s=setTimeout(f,n,p)});try{return await Promise.race([e,c])}finally{clearTimeout(s)}}i(D,"settle");async function*I(e,n,s){let c=!1;try{const f=n.front==="anthropic";f&&(yield{event:"message_start",data:{type:"message_start",message:{id:O(),type:"message",role:"assistant",model:s,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 a=await e,g=i(function*(){yield{event:"content_block_delta",data:{type:"content_block_delta",index:0,delta:{type:"signature_delta",signature:S()}}},yield{event:"content_block_stop",data:{type:"content_block_stop",index:0}}},"closeEarly");if(a.stream){c=!0;let u=null;for await(const l of a.stream){if(!f){yield l;continue}if(l.event!=="message_start"){if(u===null&&l.event==="content_block_start"&&l.data.content_block.type==="thinking"){u=0;continue}u===null&&(yield*g(),u=1),yield u>0&&typeof l.data?.index=="number"?{...l,data:{...l.data,index:l.data.index+u}}:l}}return}f&&(yield*g()),yield*x(n,a.body)}finally{c||e.then(f=>f.stream?.return?.(),()=>{})}}i(I,"late");function*x(e,n){if(e.front==="anthropic"){yield{event:"error",data:n};return}yield{data:n},yield{data:"[DONE]"}}i(x,"failure");async function v(e,n,s,c,f=200,a=j){e.hijack();const g=e.raw;g.writeHead(f,a);try{await n.write(g,c,{front:n.front,interval:n.interval})}catch(u){if(!s.signal.aborted){const l=u instanceof _;l||e.log.error(u);const{body:m}=n.build(l?u.status:502,l?u.message:"Internal server error",l?{type:u.type,code:u.code}:{});for(const k of x(n,m))g.write(n.encode(k))}}return g.end(),e}i(v,"stream");function L(e,n){const s=Buffer.from(e),c=Buffer.from(n);return s.length===c.length&&H(s,c)}i(L,"same");function z(e){const n=/^Bearer\s+(.+)$/i.exec(e.authorization??"");return e["x-api-key"]||n?.[1]||""}i(z,"keyOf");function B(e){const n={};for(const[s,c]of Object.entries(e))(s==="anthropic-beta"||s==="anthropic-version"||s.startsWith("x-claude-code-"))&&(n[s]=String(c));return n}i(B,"forwardable");function C(e){if(e===!0)return{ok:!0,context:void 0};if(e&&typeof e=="object"&&e.ok===!0)return{ok:!0,context:e.context};const n=e&&typeof e=="object"&&e.ok===!1?e:{};return{ok:!1,status:Number.isInteger(n.status)&&n.status>=400&&n.status<=599?n.status:401,message:typeof n.message=="string"&&n.message!==""?n.message:"unauthorized"}}i(C,"verdictOf");function R(e,n,s){const{front:c,filter:f}=s,a={...s,build:i((t,o,r={})=>s.build(t,o,{...r,front:c}),"build"),send:i((t,o)=>s.send(t,{...o,front:c,filter:f}),"send"),route:i(t=>s.route(t,{front:c}),"route"),count:i((t,o)=>s.count(t,{...o,front:c}),"count"),list:i(t=>s.list({...t,front:c}),"list"),get:i((t,o)=>s.get(t,{...o,front:c}),"get")},g=[n.apiKey??[]].flat().filter(Boolean),u=n.bodyLimit??T,l=new WeakMap,m=i((t,o)=>t.code(o.status).headers(o.headers).send(o.body),"reject");e.setErrorHandler((t,o,r)=>{if(t instanceof _)return m(r,a.build(t.status,t.message,{type:t.type,code:t.code,param:t.param}));const d=t.statusCode??500;return d<500?m(r,a.build(d,t.message)):(o.log.error(t),m(r,a.build(d,"Internal server error")))}),e.addHook("onRequest",async(t,o)=>{if(g.length===0||t.routeOptions.config?.public)return;const r=z(t.headers);if(!(r&&g.some(d=>L(r,d))))return m(o,a.build(401,"invalid x-api-key"))}),typeof n.authorize=="function"&&e.addHook("preHandler",async(t,o)=>{if(t.routeOptions.config?.public)return;let r=null;if(t.body&&typeof t.body=="object"&&!Array.isArray(t.body))try{r=a.route(t.body)}catch{}let d;try{d=C(await n.authorize({method:t.method,url:t.url,headers:t.headers,body:t.body,front:a.front,route:r}))}catch(y){t.log.error(y),d={ok:!1,status:401,message:"unauthorized"}}if(!d.ok)return m(o,a.build(d.status,d.message));l.set(t,d.context)}),e.route({method:["GET","HEAD"],url:"/",config:{public:!0},handler:i(async(t,o)=>o.send({ok:!0}),"handler")}),e.route({method:["GET","HEAD"],url:"/api/hello",config:{public:!0},handler:i(async(t,o)=>o.send({ok:!0}),"handler")}),e.get("/v1/models",async(t,o)=>{const r=new AbortController;return o.raw.on("close",()=>r.abort()),a.list({signal:r.signal})}),e.get("/v1/models/*",async(t,o)=>{const r=new AbortController;return o.raw.on("close",()=>r.abort()),a.get(t.params["*"],{signal:r.signal})});const k=a.front==="anthropic"?"/v1/messages":"/v1/chat/completions";e.post(k,{bodyLimit:u},async(t,o)=>{if(o.raw.destroyed)return o;const r=new AbortController;o.raw.on("close",()=>{o.raw.writableFinished||r.abort()});const d=typeof n.onUsage=="function"?h=>n.onUsage(h,l.get(t)):void 0,y=a.send(t.body,{signal:r.signal,clientHeaders:B(t.headers),onUsage:d});y.catch(()=>{});const E=new Promise(h=>r.signal.addEventListener("abort",()=>h(w),{once:!0})),b=await D(Promise.race([y,E]),t.body?.stream===!0?a.interval:0);return b===w?(y.then(h=>h.stream?.return?.(),()=>{}),o):b===p?v(o,a,r,I(y,a,t.body?.model)):b.stream?v(o,a,r,b.stream,b.status,b.headers):m(o,b)}),a.front==="anthropic"&&e.post("/v1/messages/count_tokens",{bodyLimit:u},async(t,o)=>{const r=new AbortController;return o.raw.on("close",()=>r.abort()),a.count(t.body,{signal:r.signal})})}i(R,"register");export{I as late,R as register};
|
|
2
2
|
//# sourceMappingURL=routes.mjs.map
|
package/dist/lib/settings.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var l=Object.defineProperty;var
|
|
1
|
+
var l=Object.defineProperty;var r=(o,e)=>l(o,"name",{value:e,configurable:!0});import{TranslatorError as s}from"./errors.mjs";const i=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",toolErrors:!1,maxTokensField:"max_completion_tokens",streamUsage:!0,continuousUsage:!1,prefill:"continue_final_message",topK:!0,responseFormat:!0,parallelToolCalls:!0,unknownFields:"drop",pingInterval:1e4,toolStreaming:"buffer",effortPassthrough:!1,passthroughFilter:!1,contextWindow:0,defaultMaxTokens:8192}),f={inlineSystem:["auto","keep","hoist","user","drop"],reasoningField:["reasoning","reasoning_content"],thinking:["chat_template_kwargs","reasoning_effort","none"],documents:["extract","note","error"],toolSchema:["pass","sanitize"],deferredTools:["forward","drop"],toolSearch:["expand","inline","native"],maxTokensField:["max_completion_tokens","max_tokens"],prefill:["continue_final_message","none"],unknownFields:["drop","error"],toolStreaming:["buffer","stream"]},d=["effortPassthrough","passthroughFilter","imageFallback","toolFallback","thinkOpen","reasoningRoundTrip"];function p(...o){const e={...i,pdf:{...i.pdf}};for(const t of o)if(t)for(const[n,a]of Object.entries(t))a!==void 0&&(n==="pdf"?Object.assign(e.pdf,a):e[n]=a);for(const[t,n]of Object.entries(f))if(!n.includes(e[t]))throw new s(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected one of ${n.join(", ")})`,{code:"invalid_setting",status:500,details:{key:t,allowed:n}});for(const t of d)if(typeof e[t]!="boolean")throw new s(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected true or false)`,{code:"invalid_setting",status:500,details:{key:t}});if(!(Number.isFinite(e.pdf.scale)&&e.pdf.scale>0))throw new s(`Invalid setting pdf.scale: ${JSON.stringify(e.pdf.scale)} (expected a positive number)`,{code:"invalid_setting",status:500,details:{key:"pdf.scale"}});return e}r(p,"resolve");export{i as DEFAULTS,p as resolve};
|
|
2
2
|
//# sourceMappingURL=settings.mjs.map
|
package/dist/lib/thinking.mjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var M=Object.defineProperty;var o=(t,n)=>M(t,"name",{value:n,configurable:!0});import{deflateRawSync as b,inflateRaw as R}from"node:zlib";import{promisify as X}from"node:util";const j=X(R),p="llmt:",g="<think>",l="</think>",d="~",w=/^[A-Za-z0-9_-]*$/,I=/^[A-Za-z][A-Za-z0-9_]{0,39}$/,N=512,S=256*1024,h=1024*1024,_=512*1024,P=256,U=32,E=5,B=8*1024*1024,W=1024,F=8,O=30,x="anthropic-claude-v1",K=["reasoning_content","reasoning"];function A(){return p+Buffer.from('{"v":1}').toString("base64url")}o(A,"marker");function T(t){if(t===null||typeof t!="object"||Array.isArray(t))return null;try{const n={};for(const e of K)if(t[e]!==void 0){if(typeof t[e]!="string"||t[e].length>_)return null;n[e]=t[e]}if(Object.keys(n).length>1)return null;if(t.reasoning_details!==void 0){const e=m(t.reasoning_details,0);if(!Array.isArray(e)||e.some(r=>r===null||typeof r!="object"||Array.isArray(r)))return null;n.reasoning_details=e}return Object.keys(n).length>0?n:null}catch{return null}}o(T,"validate");function Y(t,n){const e=t===void 0?null:T(t);if(e===null)return A();const r=Buffer.from(JSON.stringify(n===void 0?{v:1,d:e}:{v:1,p:n,d:e}));if(r.length>h)return A();let i=r.toString("base64url");if(r.length>N){const u=b(r);r.length<=O*u.length&&u.length<r.length&&(i=d+u.toString("base64url"))}const f=p+i;return f.length>S?A():f}o(Y,"sign");function L(t){return typeof t=="string"&&t.startsWith(p)}o(L,"isOurs");function m(t,n){if(t===null||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)||typeof t=="string"&&t.length<=_)return t;if(n<E&&Array.isArray(t)&&t.length<=P)return t.map(e=>m(e,n+1));if(n<E&&typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length<=U){const e={};for(const[r,i]of Object.entries(t)){if(!I.test(r))throw new TypeError("key");e[r]=m(i,n+1)}return e}throw new TypeError("value")}o(m,"plain");function z(){return{bytes:B,signatures:W,failures:F,cache:new Map,queue:Promise.resolve()}}o(z,"createBudget");async function Z(t,{producer:n,budget:e=z()}={}){if(!L(t)||t.length>S)return null;const r=e.queue.then(()=>C(t,n,e));return e.queue=r.then(()=>{},()=>{}),r}o(Z,"unsign");async function C(t,n,e){const r=`${n}
|
|
2
|
+
${t}`;if(e.cache.has(r))return e.cache.get(r);if(e.signatures<=0||e.failures<=0)return null;e.signatures--;const i=await D(t,n,e);return i===void 0?(e.failures--,e.cache.set(r,null),null):(e.cache.set(r,i),i)}o(C,"account");async function D(t,n,e){try{let r=t.slice(p.length);const i=r.startsWith(d);if(i&&(r=r.slice(d.length)),!w.test(r))return;const f=Buffer.from(r,"base64url"),u=Math.min(h,e.bytes),a=i?Math.min(u,O*f.length):f.length;if(a<1||a>u)return;e.bytes-=a;const y=i?await j(f,{maxOutputLength:a}):f;e.bytes+=a-y.length;const s=JSON.parse(y.toString("utf8"));return s?.v!==1||s.d===void 0?void 0:s.p!==n?null:T(s.d)??void 0}catch{return}}o(D,"decode");function G(t,n){return t?.type==="thinking"&&typeof t.signature=="string"&&t.signature!==""?{type:"reasoning.text",text:typeof t.thinking=="string"?t.thinking:"",signature:t.signature,format:x,index:n}:t?.type==="redacted_thinking"&&typeof t.data=="string"&&t.data!==""?{type:"reasoning.encrypted",data:t.data,format:x,index:n}:null}o(G,"detailOf");function H(t){const n=o(i=>Number.isInteger(i.index)&&i.index>=0?i.index:0,"position");if(!Array.isArray(t))return[];const e=[];let r=0;for(const i of t.slice(0,64))i===null||typeof i!="object"||i.format!==x||(i.type==="reasoning.text"&&typeof i.text=="string"&&typeof i.signature=="string"&&i.signature!==""?(r+=i.text.length+i.signature.length,r<=h&&e.push({at:n(i),block:{type:"thinking",thinking:i.text,signature:i.signature}})):i.type==="reasoning.encrypted"&&typeof i.data=="string"&&i.data!==""&&(r+=i.data.length,r<=h&&e.push({at:n(i),block:{type:"redacted_thinking",data:i.data}})));return e}o(H,"blocksOf");function V(t){return typeof t?.reasoning=="string"&&t.reasoning!==""?"reasoning":typeof t?.reasoning_content=="string"&&t.reasoning_content!==""?"reasoning_content":null}o(V,"reasoningKey");function v(t,n){if(n===null||typeof n!="object"||Array.isArray(n))return t;const e=n.index===void 0?void 0:t.find(r=>r.index===n.index&&r.type===n.type);if(e===void 0)return t.push({...n}),t;for(const r of["text","summary"])typeof n[r]=="string"&&(e[r]=(typeof e[r]=="string"?e[r]:"")+n[r]);for(const r of["signature","data","format","id"])typeof n[r]=="string"&&n[r]!==""&&(e[r]=n[r]);return t}o(v,"mergeDetail");function tt(t){return Array.isArray(t)?t.map(n=>typeof n?.text=="string"?n.text:typeof n?.summary=="string"?n.summary:"").join(""):""}o(tt,"detailsText");function nt(t){const n=t?.reasoning??t?.reasoning_content;return typeof n=="string"?n:""}o(nt,"reasoningOf");function et(t,n=!1){const e=t.trimStart();if(!e.startsWith(g)){const i=n?t.indexOf(l):-1;return i===-1?{reasoning:"",text:t}:{reasoning:t.slice(0,i),text:t.slice(i+l.length).trimStart()}}const r=e.indexOf(l);return r===-1?{reasoning:e.slice(g.length),text:""}:{reasoning:e.slice(g.length,r),text:e.slice(r+l.length).trimStart()}}o(et,"splitThink");function rt(t=!1){let n="start",e="";const r=o((f,u)=>{let a="",y="",s=e+f;for(e="";;){if(n==="plain"){y+=s;break}if(n==="start"){const c=s.trimStart();if(c===""&&!u){e=s;break}if(c.startsWith(g))n="think",s=c.slice(g.length);else if(!u&&c!==""&&g.startsWith(c)){e=s;break}else n=t?"implicit":"plain"}else if(n==="implicit"){const c=s.indexOf(l);if(c!==-1)a+=s.slice(0,c),s=s.slice(c+l.length),n="after";else if(u){y+=s;break}else{e=s;break}}else if(n==="think"){const c=s.indexOf(l);if(c!==-1){a+=s.slice(0,c),s=s.slice(c+l.length),n="after";continue}const k=u?0:$(s,l);a+=s.slice(0,s.length-k),e=s.slice(s.length-k);break}else{if(s=s.trimStart(),s==="")break;n="plain"}}return{reasoning:a,text:y}},"step");return{push:o(f=>r(f,!1),"push"),end:o(()=>r("",!0),"end"),release:o(()=>{const f=e;return e="",n="plain",{reasoning:"",text:f}},"release"),pending:o(()=>t&&(n==="start"||n==="implicit"),"pending")}}o(rt,"createThinkSplitter");function $(t,n){for(let e=Math.min(t.length,n.length-1);e>0;e--)if(n.startsWith(t.slice(t.length-e)))return e;return 0}o($,"partialSuffix");export{x as ANTHROPIC_FORMAT,H as blocksOf,z as createBudget,rt as createThinkSplitter,G as detailOf,tt as detailsText,L as isOurs,v as mergeDetail,V as reasoningKey,nt as reasoningOf,Y as sign,et as splitThink,Z as unsign};
|
|
2
3
|
//# sourceMappingURL=thinking.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var e=(t,o)=>l(t,"name",{value:o,configurable:!0});const s="The vLLM server was started without tool-call parsing. Restart it with --enable-auto-tool-choice and --tool-call-parser <parser> (the parser depends on the model family)",p=`${s}, or set the translator setting toolFallback to retry without tools.`,n="The llama.cpp server was started without --jinja, which tool calls need. Restart it with --jinja (the model's chat template must support tools)";function u(t,o=""){const r=/--jinja\b/i.test(o)?n:s;return t?`${r}.`:`${r}, or set the translator setting toolFallback to retry without tools.`}e(u,"hint");const i=[/--enable-auto-tool-choice\b/i,/--tool-call-parser\b/i,/--jinja\b/i];function d(t){return i.some(o=>o.test(t))}e(d,"refused");function w(t){return Array.isArray(t?.tools)&&t.tools.length>0}e(w,"carries");function j(t){const{tools:o,tool_choice:r,parallel_tool_calls:c,...a}=t;return a}e(j,"strip");export{p as HINT,w as carries,u as hint,d as refused,j as strip};
|
|
2
|
+
//# sourceMappingURL=tools.mjs.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var T=Object.defineProperty;var f=(n,t)=>T(n,"name",{value:t,configurable:!0});const A="ToolSearch",w="DeferredToolPlaceholder",S=/<function>([\s\S]*?)<\/function>/g,E=/\b(?:clear(?:ed)?|trimmed|removed|truncated|omitted|elided|pruned)\b/i,b=Object.freeze({definitions:512,line:131072,name:256,description:16384,schema:65536});function x(n){return typeof n=="string"?n:Array.isArray(n)?n.filter(t=>t?.type==="text"&&typeof t.text=="string").map(t=>t.text).join(`
|
|
2
|
+
`):""}f(x,"textOf");function L(n){if(n.length>b.line)return null;let t;try{t=JSON.parse(n)}catch{return null}if(!t||typeof t.name!="string"||t.name===""||t.name.length>b.name)return null;const r=t.parameters??{type:"object",properties:{}};if(typeof r!="object"||r===null||Array.isArray(r)||JSON.stringify(r).length>b.schema||r.type!==void 0&&r.type!=="object")return null;const l={name:t.name,input_schema:r.type===void 0?{type:"object",...r}:r};if(typeof t.description=="string"){if(t.description.length>b.description)return null;l.description=t.description}return l}f(L,"definition");function M(n){if(Array.isArray(n)&&n.some(r=>r?.type==="tool_reference"))return!1;const t=x(n).trim();return new RegExp(S.source).test(t)?!1:t===""||t.length<=200&&E.test(t)}f(M,"cleared");function j(n){return typeof n?.query!="string"||!/^\s*select:/i.test(n.query)?[]:n.query.replace(/^\s*select:/i,"").split(/[\s,]+/).filter(t=>t!=="")}f(j,"selected");function R(n,t=new Set){const r=[],l=[],d=[],u=new Map,h=new Map,a=new Map,p=new Map,y=new Set;let g=!1;const _=f(i=>{r.includes(i)||r.push(i)},"add"),m=f(i=>{_(i),l.includes(i)||l.push(i)},"search");for(const i of n)if(Array.isArray(i?.content))for(const e of i.content)e?.type==="tool_use"?a.set(e.id,(a.get(e.id)??0)+1):e?.type==="tool_result"&&!p.has(e.tool_use_id)&&p.set(e.tool_use_id,e);for(const i of n)if(Array.isArray(i?.content)){for(const e of i.content)if(e?.type==="tool_use"){if(a.get(e.id)===1&&h.set(e.id,e.name),_(e.name),d.includes(e.name)||d.push(e.name),p.get(e.id)?.is_error!==!0&&y.add(e.name),e.name===A){const s=a.get(e.id)===1?p.get(e.id):void 0;if(!s||M(s.content))for(const c of j(e.input))m(c)}}else if(e?.type==="tool_result"){for(const s of Array.isArray(e.content)?e.content:[])s?.type==="tool_reference"&&typeof s.tool_name=="string"&&m(s.tool_name);if(h.get(e.tool_use_id)!==A)continue;for(const s of x(e.content).matchAll(S)){const c=L(s[1]);c&&(m(c.name),!(t.has(c.name)||u.has(c.name))&&(u.size>=b.definitions?g=!0:u.set(c.name,c)))}}}return{loaded:r,searched:l,called:d,failed:d.filter(i=>!y.has(i)),defined:u,capped:g}}f(R,"scan");const I="The definition of this tool was trimmed from the conversation; use ToolSearch to see its parameters.";function v(n,t,r,l){const d=f(e=>(e.type===void 0||e.type==="custom")&&e.defer_loading===!0,"deferred");if(!n.some(d))return{offer:n,loaded:[],hidden:[],stubbed:[]};const u=n.some(e=>e.name===w&&d(e)),h=n.filter(e=>d(e)&&e.name!==w),a=new Set([w]);let p=n,y=[],g=[];const _=new Set(n.map(e=>e.name)),m=t.searched.filter(e=>!_.has(e)&&!t.defined.has(e)),i=u||n.some(e=>e.name===A);if(r.deferredTools==="drop")a.add(A);else if(r.toolSearch==="native")a.clear();else if(i&&(g=t.called.filter(e=>m.includes(e)&&!t.failed.includes(e))),r.toolSearch==="inline"||!i){!u&&m.length===0&&a.add(A);const e=[...t.defined.values()].filter(s=>!_.has(s.name));p=[...n,...e],y=[...h,...e].map(s=>s.name)}else{const e=new Set(t.loaded);l?.type==="tool"&&e.add(l.name);const s=[...e].map(o=>h.find(O=>O.name===o)).filter(o=>o!==void 0),c=[...e].filter(o=>!_.has(o)&&t.defined.has(o)).map(o=>t.defined.get(o));!u&&s.length===h.length&&m.length===0&&a.add(A),p=[...n.filter(o=>!d(o)),...s,...c],y=[...s,...c].map(o=>o.name)}return{offer:[...p.filter(e=>!a.has(e.name)),...g.map(e=>({name:e,description:I,input_schema:{type:"object"}}))],loaded:y,hidden:n.filter(e=>a.has(e.name)).map(e=>e.name),stubbed:g}}f(v,"plan");export{b as LIMITS,w as PLACEHOLDER_TOOL,A as SEARCH_TOOL,I as TRIMMED,v as plan,R as scan};
|
|
3
|
+
//# sourceMappingURL=toolsearch.mjs.map
|
package/dist/lib/transport.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var E=Object.defineProperty;var
|
|
1
|
+
var E=Object.defineProperty;var f=(a,t)=>E(a,"name",{value:t,configurable:!0});import v from"node:http";import C from"node:https";import{Readable as L}from"node:stream";const i=new Set([204,205,304]);function S(a,t={},p={http:v,https:C}){const c=new URL(a),h={"accept-encoding":"identity",...t.headers};t.body!==void 0&&(h["content-length"]=String(Buffer.byteLength(t.body)));const{signal:o,redirect:b,connectTimeout:d}=t;return new Promise((y,u)=>{if(o?.aborted)return u(o.reason);const r=(c.protocol==="https:"?p.https:p.http).request(c,{method:t.method??"GET",headers:h,agent:!1},e=>{if(o?.removeEventListener("abort",l),b==="error"&&e.statusCode>=300&&e.statusCode<400&&e.headers.location)return e.destroy(),u(new TypeError(`unexpected redirect to ${e.headers.location}`));const s=new Headers;for(const[m,w]of Object.entries(e.headers))for(const T of[].concat(w))s.append(m,T);const n=i.has(e.statusCode)?null:L.toWeb(e);n===null&&e.resume(),y(new Response(n,{status:e.statusCode,statusText:e.statusMessage,headers:s})),o?.addEventListener("abort",()=>e.destroy(o.reason),{once:!0})}),l=f(()=>r.destroy(o.reason),"onAbort");o?.addEventListener("abort",l,{once:!0}),r.on("error",u),d>0&&r.once("socket",e=>{const s=c.protocol==="https:";if(!s&&!e.connecting)return;const n=setTimeout(()=>r.destroy(new Error(`connect timeout after ${d} ms`)),d);e.once(s?"secureConnect":"connect",()=>clearTimeout(n)),r.once("close",()=>clearTimeout(n))}),r.end(t.body)})}f(S,"transport");export{S as transport};
|
|
2
2
|
//# sourceMappingURL=transport.mjs.map
|
|
@@ -0,0 +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}`))}catch(n){i(`onUsage threw: ${n?.message??n}`)}},"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};
|
|
2
|
+
//# sourceMappingURL=usage.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/llm-translator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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",
|
|
@@ -25,7 +25,14 @@
|
|
|
25
25
|
},
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"engines": {
|
|
28
|
-
"node": ">=
|
|
28
|
+
"node": ">=24.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devEngines": {
|
|
31
|
+
"runtime": {
|
|
32
|
+
"name": "node",
|
|
33
|
+
"version": ">=24.0.0",
|
|
34
|
+
"onFail": "error"
|
|
35
|
+
}
|
|
29
36
|
},
|
|
30
37
|
"main": "./dist/index.cjs",
|
|
31
38
|
"module": "./dist/index.mjs",
|
|
@@ -49,8 +56,7 @@
|
|
|
49
56
|
"files": [
|
|
50
57
|
"dist/",
|
|
51
58
|
"!dist/**/*.map",
|
|
52
|
-
"types/"
|
|
53
|
-
"!types/devcheck.d.mts"
|
|
59
|
+
"types/"
|
|
54
60
|
],
|
|
55
61
|
"repository": {
|
|
56
62
|
"type": "git",
|
|
@@ -82,7 +88,7 @@
|
|
|
82
88
|
"test:watch": "vitest --config .configs/vitest.config.mjs",
|
|
83
89
|
"coverage": "node tests/run-vitest.mjs --coverage-quiet",
|
|
84
90
|
"ci:coverage": "npm run coverage && npm run test:dist",
|
|
85
|
-
"types:build": "tsc -p .configs/tsconfig.json",
|
|
91
|
+
"types:build": "tsc -p .configs/tsconfig.json --noCheck",
|
|
86
92
|
"types:check": "tsc -p .configs/tsconfig.json --noEmit",
|
|
87
93
|
"lint": "eslint --config .configs/eslint.config.mjs .",
|
|
88
94
|
"lint:fix": "eslint --config .configs/eslint.config.mjs . --fix",
|
|
@@ -101,7 +107,7 @@
|
|
|
101
107
|
"dependencies": {
|
|
102
108
|
"@cldmv/slothlet": "^3.22.1",
|
|
103
109
|
"@napi-rs/canvas": "^1.0.13",
|
|
104
|
-
"unpdf": "^1.
|
|
110
|
+
"unpdf": "^2.1.0"
|
|
105
111
|
},
|
|
106
112
|
"devDependencies": {
|
|
107
113
|
"@cldmv/configs": "^1.3.0",
|
|
@@ -122,7 +128,11 @@
|
|
|
122
128
|
"globals": "^17.13.0",
|
|
123
129
|
"prettier": "^3.9.10",
|
|
124
130
|
"tsup": "^9.0.0",
|
|
125
|
-
"typescript": "^
|
|
131
|
+
"typescript": "^6.0.3",
|
|
126
132
|
"vitest": "^5.0.5"
|
|
133
|
+
},
|
|
134
|
+
"overrides": {
|
|
135
|
+
"katex": ">=0.19.1 <1.0.0",
|
|
136
|
+
"minimatch": "^11.0.3"
|
|
127
137
|
}
|
|
128
138
|
}
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/convert/anthropic/messages/to/openai/chat/request.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
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-25T12:58:59-07:00 (1792958339)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert an Anthropic Messages request body into an OpenAI Chat Completions request body.
|
|
17
3
|
*
|
|
@@ -19,10 +5,15 @@
|
|
|
19
5
|
* tool-name map, thinking mode, fields that were dropped).
|
|
20
6
|
* @param {any} body - Anthropic `POST /v1/messages` body.
|
|
21
7
|
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
8
|
+
* @param {{ producer?: string, budget?: ReturnType<typeof createBudget> }} [context] - `producer` is the `driver:protocol:host` the request goes to; signatures that carry provider reasoning data are restored only for the producer that made them. `budget` limits how much signature decoding the request may cost (one is made when absent; `send` passes one for all its attempts).
|
|
22
9
|
* @returns {Promise<{ body: any, state: any }>} OpenAI request body and conversion state.
|
|
23
10
|
* @throws {TranslatorError} For malformed requests, unsupported content when configured to error, or PDF limit violations.
|
|
24
11
|
*/
|
|
25
|
-
export
|
|
12
|
+
export function request(body: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>, context?: {
|
|
13
|
+
producer?: string;
|
|
14
|
+
budget?: ReturnType<typeof createBudget>;
|
|
15
|
+
}): Promise<{
|
|
26
16
|
body: any;
|
|
27
17
|
state: any;
|
|
28
18
|
}>;
|
|
19
|
+
import { createBudget } from "../../../../../../../lib/thinking.mjs";
|
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/convert/anthropic/messages/to/openai/chat/response.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
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-25T12:58:59-07:00 (1792958339)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert an Anthropic message into an OpenAI `chat.completion`. Text blocks are concatenated, `thinking` blocks
|
|
17
3
|
* become the reasoning field named by `reasoningField`, `tool_use` blocks become `tool_calls` (tool names restored
|
|
18
|
-
* through `state.toolNames`), and other block types (server tool results
|
|
4
|
+
* through `state.toolNames`), and other block types (server tool results) are skipped. With `reasoningRoundTrip`, thinking and redacted thinking
|
|
5
|
+
* blocks are also returned as `reasoning_details` items that carry their signatures.
|
|
19
6
|
* @param {any} message - Anthropic message.
|
|
20
7
|
* @param {any} [state] - State from the request converter (original model, tool-name map).
|
|
21
8
|
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
22
9
|
* @returns {any} OpenAI chat completion.
|
|
23
10
|
*/
|
|
24
|
-
export
|
|
11
|
+
export function response(message: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/convert/anthropic/messages/to/openai/chat/stream.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
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-25T12:58:59-07:00 (1792958339)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert an Anthropic Messages event stream into OpenAI `chat.completion.chunk` messages followed by `[DONE]`.
|
|
17
3
|
*
|
|
@@ -24,6 +10,6 @@
|
|
|
24
10
|
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
25
11
|
* @returns {AsyncGenerator<{ data: any|string }, void, undefined>} OpenAI chunks.
|
|
26
12
|
*/
|
|
27
|
-
export
|
|
13
|
+
export function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
28
14
|
data: any | string;
|
|
29
15
|
}, void, undefined>;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/convert/openai/chat/to/anthropic/messages/request.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
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-25T12:58:59-07:00 (1792958339)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert an OpenAI Chat Completions request body into an Anthropic Messages request body (for an OpenAI-protocol
|
|
17
3
|
* client talking to an Anthropic-protocol upstream).
|
|
@@ -24,7 +10,7 @@
|
|
|
24
10
|
* @returns {Promise<{ body: any, state: any }>} Anthropic request body and conversion state.
|
|
25
11
|
* @throws {TranslatorError} For malformed requests, `n` above 1, unknown roles, or unknown fields when configured to error.
|
|
26
12
|
*/
|
|
27
|
-
export
|
|
13
|
+
export function request(chatBody: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): Promise<{
|
|
28
14
|
body: any;
|
|
29
15
|
state: any;
|
|
30
16
|
}>;
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/convert/openai/chat/to/anthropic/messages/response.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
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-25T12:58:59-07:00 (1792958339)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert a (non-streaming) OpenAI chat completion into an Anthropic message.
|
|
17
3
|
*
|
|
18
|
-
* Reasoning (`reasoning`, `reasoning_content`, or a leading `<think>` block when `thinkTags` is on) becomes a
|
|
19
|
-
* `thinking` block with a translator-marked signature. Tool calls become `tool_use` blocks; arguments that are not
|
|
4
|
+
* Reasoning (`reasoning`, `reasoning_content`, or a leading `<think>` block when `thinkTags` is on, or a block closed by `</think>` when `thinkOpen` is also on) becomes a
|
|
5
|
+
* `thinking` block with a translator-marked signature (which carries the provider's reasoning fields when `reasoningRoundTrip` is on). Tool calls become `tool_use` blocks; arguments that are not
|
|
20
6
|
* a JSON object are passed through under `_raw_arguments` so the client reports a tool error the model can recover
|
|
21
7
|
* from.
|
|
22
8
|
* @param {any} completion - OpenAI `chat.completion` object.
|
|
@@ -25,4 +11,4 @@
|
|
|
25
11
|
* @returns {any} Anthropic message.
|
|
26
12
|
* @throws {TranslatorError} When the completion has no choices.
|
|
27
13
|
*/
|
|
28
|
-
export
|
|
14
|
+
export function response(completion: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/convert/openai/chat/to/anthropic/messages/stream.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
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-25T13:31:27-07:00 (1792960287)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert an OpenAI chat-completion stream into Anthropic Messages stream events.
|
|
17
3
|
*
|
|
@@ -32,7 +18,7 @@
|
|
|
32
18
|
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
33
19
|
* @returns {AsyncGenerator<{ event: string, data: any }, void, undefined>} Anthropic events.
|
|
34
20
|
*/
|
|
35
|
-
export
|
|
21
|
+
export function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
36
22
|
event: string;
|
|
37
23
|
data: any;
|
|
38
24
|
}, void, undefined>;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/detect.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:29:36-07:00 (1792956576)
|
|
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-25T12:58:59-07:00 (1792958339)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Bind every endpoint to a driver. `backend: "auto"` endpoints are probed (drivers tried in `info().order`, the generic
|
|
17
3
|
* driver matches last); endpoints with an explicit `backend` skip detection. Call it again to re-probe.
|
|
18
4
|
* @param {any} [options] - `{ network, signal }`. `network: false` skips all probing (auto endpoints fall back to the generic driver).
|
|
19
5
|
* @returns {Promise<any>} The `status()` result.
|
|
20
6
|
*/
|
|
21
|
-
export
|
|
7
|
+
export function detect(options?: any): Promise<any>;
|