@cldmv/llm-translator 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -7
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +17 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +2 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +6 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/detect.mjs +2 -0
- package/dist/api/driver/anthropic/detect.mjs +2 -0
- package/dist/api/driver/anthropic/info.mjs +2 -0
- package/dist/api/driver/anthropic/model/list.mjs +2 -0
- package/dist/api/driver/anthropic/settings.mjs +2 -0
- package/dist/api/driver/anthropic/token/count.mjs +2 -0
- package/dist/api/driver/compatible/detect.mjs +2 -0
- package/dist/api/driver/compatible/info.mjs +2 -0
- package/dist/api/driver/compatible/model/list.mjs +2 -0
- package/dist/api/driver/compatible/request.mjs +2 -0
- package/dist/api/driver/compatible/settings.mjs +2 -0
- package/dist/api/driver/openai/detect.mjs +2 -0
- package/dist/api/driver/openai/info.mjs +2 -0
- package/dist/api/driver/openai/model/list.mjs +2 -0
- package/dist/api/driver/openai/request.mjs +2 -0
- package/dist/api/driver/openai/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +2 -0
- package/dist/api/driver/vllm/error.mjs +2 -0
- package/dist/api/driver/vllm/info.mjs +2 -0
- package/dist/api/driver/vllm/model/list.mjs +2 -0
- package/dist/api/driver/vllm/probe.mjs +2 -0
- package/dist/api/driver/vllm/request.mjs +2 -0
- package/dist/api/driver/vllm/settings.mjs +2 -0
- package/dist/api/driver/vllm/token/count.mjs +2 -0
- package/dist/api/error/build.mjs +2 -0
- package/dist/api/error/error.mjs +2 -0
- package/dist/api/model/list.mjs +2 -0
- package/dist/api/request.mjs +3 -0
- package/dist/api/response.mjs +2 -0
- package/dist/api/send.mjs +2 -0
- package/dist/api/server/plugin.mjs +2 -0
- package/dist/api/server/start.mjs +2 -0
- package/dist/api/server/stop.mjs +2 -0
- package/dist/api/sse/encode.mjs +4 -0
- package/dist/api/sse/parse.mjs +2 -0
- package/dist/api/sse/ping.mjs +2 -0
- package/dist/api/sse/write.mjs +2 -0
- package/dist/api/status.mjs +2 -0
- package/dist/api/stream.mjs +2 -0
- package/dist/api/token/count.mjs +2 -0
- package/dist/bin/llm-translator.mjs +3 -0
- package/dist/index.mjs +1 -1
- package/dist/lib/arguments.mjs +2 -0
- package/dist/lib/capture.mjs +2 -0
- package/dist/lib/cli.mjs +29 -0
- package/dist/lib/config.mjs +2 -0
- package/dist/lib/documents.mjs +12 -0
- package/dist/lib/errors.mjs +2 -0
- package/dist/lib/estimate.mjs +2 -0
- package/dist/lib/finish.mjs +2 -0
- package/dist/lib/http.mjs +2 -0
- package/dist/lib/ids.mjs +2 -0
- package/dist/lib/images.mjs +2 -0
- package/dist/lib/models.mjs +2 -0
- package/dist/lib/normalize.mjs +2 -0
- package/dist/lib/passthrough.mjs +2 -0
- package/dist/lib/pdf.mjs +2 -0
- package/dist/lib/ping.mjs +2 -0
- package/dist/lib/route.mjs +2 -0
- package/dist/lib/routes.mjs +2 -0
- package/dist/lib/runtime.mjs +2 -0
- package/dist/lib/schema.mjs +2 -0
- package/dist/lib/settings.mjs +2 -0
- package/dist/lib/source.mjs +2 -0
- package/dist/lib/sse.mjs +10 -0
- package/dist/lib/thinking.mjs +2 -0
- package/dist/lib/transport.mjs +2 -0
- package/dist/lib/upstream-error.mjs +2 -0
- package/dist/lib/warn.mjs +2 -0
- package/package.json +30 -5
- package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +28 -0
- package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +24 -0
- package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +29 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +30 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +28 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +38 -0
- package/types/src/api/detect.d.mts +21 -0
- package/types/src/api/driver/anthropic/detect.d.mts +26 -0
- package/types/src/api/driver/anthropic/info.d.mts +30 -0
- package/types/src/api/driver/anthropic/model/list.d.mts +20 -0
- package/types/src/api/driver/anthropic/settings.d.mts +23 -0
- package/types/src/api/driver/anthropic/token/count.d.mts +20 -0
- package/types/src/api/driver/compatible/detect.d.mts +23 -0
- package/types/src/api/driver/compatible/info.d.mts +29 -0
- package/types/src/api/driver/compatible/model/list.d.mts +20 -0
- package/types/src/api/driver/compatible/request.d.mts +20 -0
- package/types/src/api/driver/compatible/settings.d.mts +23 -0
- package/types/src/api/driver/openai/detect.d.mts +26 -0
- package/types/src/api/driver/openai/info.d.mts +29 -0
- package/types/src/api/driver/openai/model/list.d.mts +20 -0
- package/types/src/api/driver/openai/request.d.mts +20 -0
- package/types/src/api/driver/openai/settings.d.mts +23 -0
- package/types/src/api/driver/vllm/detect.d.mts +20 -0
- package/types/src/api/driver/vllm/error.d.mts +28 -0
- package/types/src/api/driver/vllm/info.d.mts +29 -0
- package/types/src/api/driver/vllm/model/list.d.mts +20 -0
- package/types/src/api/driver/vllm/probe.d.mts +39 -0
- package/types/src/api/driver/vllm/request.d.mts +22 -0
- package/types/src/api/driver/vllm/settings.d.mts +22 -0
- package/types/src/api/driver/vllm/token/count.d.mts +20 -0
- package/types/src/api/error/build.d.mts +26 -0
- package/types/src/api/error/error.d.mts +29 -0
- package/types/src/api/model/list.d.mts +21 -0
- package/types/src/api/request.d.mts +35 -0
- package/types/src/api/response.d.mts +22 -0
- package/types/src/api/send.d.mts +32 -0
- package/types/src/api/server/plugin.d.mts +24 -0
- package/types/src/api/server/start.d.mts +26 -0
- package/types/src/api/server/stop.d.mts +19 -0
- package/types/src/api/sse/encode.d.mts +26 -0
- package/types/src/api/sse/parse.d.mts +24 -0
- package/types/src/api/sse/ping.d.mts +30 -0
- package/types/src/api/sse/write.d.mts +26 -0
- package/types/src/api/status.d.mts +22 -0
- package/types/src/api/stream.d.mts +25 -0
- package/types/src/api/token/count.d.mts +24 -0
- package/types/src/index.d.mts +61 -4
- package/types/src/lib/arguments.d.mts +30 -0
- package/types/src/lib/capture.d.mts +28 -0
- package/types/src/lib/cli.d.mts +49 -0
- package/types/src/lib/config.d.mts +65 -0
- package/types/src/lib/documents.d.mts +43 -0
- package/types/src/lib/errors.d.mts +144 -0
- package/types/src/lib/estimate.d.mts +24 -0
- package/types/src/lib/finish.d.mts +73 -0
- package/types/src/lib/http.d.mts +58 -0
- package/types/src/lib/ids.d.mts +55 -0
- package/types/src/lib/images.d.mts +39 -0
- package/types/src/lib/models.d.mts +25 -0
- package/types/src/lib/normalize.d.mts +37 -0
- package/types/src/lib/passthrough.d.mts +22 -0
- package/types/src/lib/pdf.d.mts +67 -0
- package/types/src/lib/ping.d.mts +24 -0
- package/types/src/lib/route.d.mts +38 -0
- package/types/src/lib/routes.d.mts +22 -0
- package/types/src/lib/runtime.d.mts +24 -0
- package/types/src/lib/schema.d.mts +22 -0
- package/types/src/lib/settings.d.mts +175 -0
- package/types/src/lib/source.d.mts +32 -0
- package/types/src/lib/sse.d.mts +72 -0
- package/types/src/lib/thinking.d.mts +60 -0
- package/types/src/lib/transport.d.mts +31 -0
- package/types/src/lib/upstream-error.d.mts +57 -0
- package/types/src/lib/warn.d.mts +26 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var w=Object.defineProperty;var p=(e,n)=>w(e,"name",{value:n,configurable:!0});import{TranslatorError as y}from"./errors.mjs";import*as f from"./pdf.mjs";const _=new Set(["pdf_unreadable","pdf_unavailable"]);async function E(e,n){const{settings:a}=n;if(a.documentConverter)return await a.documentConverter(e,n);if(a.documents==="error")throw new y("Document content blocks are not supported by this translator configuration",{code:"unsupported_document",param:"messages"});const o=v(e,n);if(a.documents==="note")return[c(o,"document conversion is disabled",n)];const t=e.source??{};return t.type==="text"?[g(e,t.data)]:t.type==="content"?typeof t.content=="string"?[{type:"text",text:t.content}]:t.content:t.type==="base64"&&t.media_type==="application/pdf"?await b(e,Buffer.from(t.data,"base64"),o,n):t.type==="base64"&&t.media_type==="text/plain"?[g(e,Buffer.from(t.data,"base64").toString("utf8"))]:t.type==="url"?[c(o,"documents referenced by URL cannot be fetched by the translator",n)]:[c(o,`document sources of type ${t.type}${t.media_type?` (${t.media_type})`:""} are not supported`,n)]}p(E,"expand");async function b(e,n,a,o){const{settings:t}=o;let s;try{s=await f.extract(n,t.pdf)}catch(r){if(r instanceof y&&_.has(r.code))return[c(a,r.message,o)];throw r}const m=e.title??s.title,l=`${m?`Document "${m}"`:"Document"} (${s.pageCount} page${s.pageCount===1?"":"s"})`;if(!(t.images&&t.pdf.pages&&f.available().canvas)){const r=s.pages.map((u,x)=>`--- Page ${x+1} ---
|
|
2
|
+
${u}`);return[{type:"text",text:`${l}
|
|
3
|
+
|
|
4
|
+
${r.join(`
|
|
5
|
+
|
|
6
|
+
`)}`}]}const $=Math.min(s.pageCount,t.pdf.maxImages);let i;try{i=await f.render(n,Array.from({length:$},(r,u)=>u+1),t.pdf)}catch{i=[]}const d=[{type:"text",text:l}];return s.pages.forEach((r,u)=>{d.push({type:"text",text:`--- Page ${u+1} ---
|
|
7
|
+
${r}`}),u<i.length&&d.push({type:"image",source:{type:"base64",...i[u]}})}),d}p(b,"expandPdf");function g(e,n){const a=e.title?` title="${e.title}"`:"",o=e.context?`${e.context}
|
|
8
|
+
|
|
9
|
+
`:"";return{type:"text",text:`<document${a}>
|
|
10
|
+
${o}${n}
|
|
11
|
+
</document>`}}p(g,"wrap");function v(e,n){return e.title??h(n)??"(unnamed)"}p(v,"nameOf");function h(e){return(e.toolUseId===null?void 0:e.toolInputs.get(e.toolUseId))?.file_path??null}p(h,"pathOf");function c(e,n,a){const o=h(a),t=o?` To read it, run \`pdftotext -layout ${o} -\` with the shell tool.`:"";return{type:"text",text:`[The document "${e}" could not be read by this model. ${n.replace(/\.$/,"")}.${t}]`}}p(c,"note");export{E as expand};
|
|
12
|
+
//# sourceMappingURL=documents.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var p=Object.defineProperty;var o=(r,e)=>p(r,"name",{value:e,configurable:!0});class q extends Error{static{o(this,"TranslatorError")}constructor(e,t={}){super(e);const{code:n="translator_error",status:s=400,type:u=i(s),param:a=null,details:c}=t;this.name="TranslatorError",this.code=n,this.status=s,this.type=u,this.param=a,this.details=c}toAnthropic(){return l(this.type,this.message)}toOpenAI(){return d(this.message,{type:_(this.type),param:this.param,code:this.code})}}function i(r){switch(r){case 400:return"invalid_request_error";case 401:return"authentication_error";case 403:return"permission_error";case 404:return"not_found_error";case 413:return"request_too_large";case 429:return"rate_limit_error";case 503:case 529:return"overloaded_error";default:return"api_error"}}o(i,"statusToAnthropicType");function v(r){switch(r){case"invalid_request_error":return 400;case"authentication_error":return 401;case"permission_error":return 403;case"not_found_error":return 404;case"request_too_large":return 413;case"rate_limit_error":return 429;case"overloaded_error":return 529;default:return 500}}o(v,"anthropicTypeToStatus");function _(r){switch(r){case"invalid_request_error":case"not_found_error":case"request_too_large":return"invalid_request_error";case"authentication_error":return"authentication_error";case"permission_error":return"permission_error";case"rate_limit_error":return"rate_limit_error";default:return"server_error"}}o(_,"anthropicToOpenAIType");function N(r,e){if(typeof e=="number")return i(e);const t=Number(r.code);if(Number.isInteger(t)&&t>=400)return i(t);switch(r.type){case"invalid_request_error":case"BadRequestError":return"invalid_request_error";case"authentication_error":return"authentication_error";case"rate_limit_error":return"rate_limit_error";default:return"api_error"}}o(N,"openaiToAnthropicType");function l(r,e){return{type:"error",error:{type:r,message:e}}}o(l,"anthropicError");function d(r,{type:e="server_error",param:t=null,code:n=null}={}){return{error:{message:r,type:e,param:t,code:n}}}o(d,"openaiError");const m=/(?:maximum context length is|context length is only) (\d+) tokens/i,h=/you requested (\d+) tokens/i,x=/you passed (\d+) input tokens and requested (\d+) output tokens/i,f=/(?:prompt contains|request has|your request contains) (\d+) (?:input )?tokens/i,T=/(\d+) in the messages/i;function O(r){const e=y(r);return e===null?null:`prompt is too long: ${e.prompt} tokens > ${e.max} maximum`}o(O,"rewriteContextOverflow");function y(r){if(typeof r!="string")return null;const e=m.exec(r);if(!e)return null;const t=Number(e[1]),n=x.exec(r);if(n)return{prompt:Number(n[1])+Number(n[2]),max:t};const s=h.exec(r)??f.exec(r)??T.exec(r);return{prompt:s?Number(s[1]):t+1,max:t}}o(y,"contextOverflow");export{q as TranslatorError,l as anthropicError,_ as anthropicToOpenAIType,v as anthropicTypeToStatus,y as contextOverflow,d as openaiError,N as openaiToAnthropicType,O as rewriteContextOverflow,i as statusToAnthropicType};
|
|
2
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var _=Object.defineProperty;var o=(t,e)=>_(t,"name",{value:e,configurable:!0});function p(t,{hasToolCalls:e,matchedStop:n,argumentsComplete:s=!0}){return e&&(t!=="length"||s)?{stop_reason:"tool_use",stop_sequence:null}:t==="length"?{stop_reason:"max_tokens",stop_sequence:null}:t==="content_filter"?{stop_reason:"refusal",stop_sequence:null}:typeof n=="string"&&n!==""?{stop_reason:"stop_sequence",stop_sequence:n}:{stop_reason:"end_turn",stop_sequence:null}}o(p,"toAnthropicStop");function u(t){switch(t){case"max_tokens":return"length";case"tool_use":return"tool_calls";case"refusal":return"content_filter";default:return"stop"}}o(u,"toOpenAIFinish");function l(t){const e=t?.prompt_tokens??0,n=t?.prompt_tokens_details?.cached_tokens??0;return{input_tokens:Math.max(0,e-n),output_tokens:t?.completion_tokens??0,cache_creation_input_tokens:0,cache_read_input_tokens:n}}o(l,"toAnthropicUsage");function i(t){const e=t?.cache_read_input_tokens??0,n=(t?.input_tokens??0)+e+(t?.cache_creation_input_tokens??0),s=t?.output_tokens??0,r={prompt_tokens:n,completion_tokens:s,total_tokens:n+s};return e>0&&(r.prompt_tokens_details={cached_tokens:e}),r}o(i,"toOpenAIUsage");export{p as toAnthropicStop,l as toAnthropicUsage,u as toOpenAIFinish,i as toOpenAIUsage};
|
|
2
|
+
//# sourceMappingURL=finish.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var y=Object.defineProperty;var o=(t,e)=>y(t,"name",{value:e,configurable:!0});function b(t,e){return t+e}o(b,"join");function d(t){return t==="localhost"||t==="::1"||/^127\./.test(t)}o(d,"isLoopback");function h(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(h,"headers");function x(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(x,"plain");async function g(t,e,n={}){const{timeout:r,signal:c,body:f,...l}=n,a=[];c&&a.push(c),r>0&&a.push(AbortSignal.timeout(r));try{const i=await t(e,{...l,redirect:"error",body:f===void 0?void 0:JSON.stringify(f),signal:a.length>1?AbortSignal.any(a):a[0]}),s=await i.text();let u=null;try{u=JSON.parse(s)}catch{u=s===""?null:s}return{ok:i.ok,status:i.status,body:u}}catch(i){return{ok:!1,status:0,body:null,error:i}}}o(g,"json");export{h as headers,d as isLoopback,b as join,g as json,x as plain};
|
|
2
|
+
//# sourceMappingURL=http.mjs.map
|
package/dist/lib/ids.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=Object.defineProperty;var n=(t,r)=>f(t,"name",{value:r,configurable:!0});import{randomBytes as h,createHash as p}from"node:crypto";function u(t=12){return h(t).toString("hex")}n(u,"random");function $(){return`msg_${u()}`}n($,"messageId");function g(){return`toolu_${u()}`}n(g,"toolUseId");function d(){return`chatcmpl-${u()}`}n(d,"completionId");function O(t){return typeof t!="string"||t===""?g():t.replace(/[^a-zA-Z0-9_-]/g,"_")}n(O,"anthropicToolId");function b({max:t,map:r={}}){const i=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(i.has(e))return i.get(e);const c=e.replace(/[^a-zA-Z0-9_-]/g,"_");let o=c;if(c.length>t||c===""){const s=p("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,i.set(e,o),o}}n(b,"createNameFitter");function x(t,r){return Object.hasOwn(t,r)?t[r]:r}n(x,"restoreName");export{O as anthropicToolId,d as completionId,b as createNameFitter,$ as messageId,x as restoreName,g as toolUseId};
|
|
2
|
+
//# sourceMappingURL=ids.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var i=(t,e)=>s(t,"name",{value:e,configurable:!0});const r="[An image was omitted because this model does not accept images.]",a=[/\bnot a multimodal\b/i,/\bat most 0 images?\b/i,/\bimage_url is only supported\b/i,/\b(?:does not|doesn't|do not|cannot|can't|not) (?:support|accept|handle)\b[^.]{0,30}\bimages?\b/i,/\bimages?(?: input| inputs| content)? (?:is|are) not (?:supported|enabled|accepted)\b/i,/\bimage input (?:is )?not (?:supported|enabled)\b/i];function c(t){return a.some(e=>e.test(t))}i(c,"refused");function u(t){return(t?.messages??[]).some(e=>Array.isArray(e?.content)&&e.content.some(n=>n?.type==="image_url"))}i(u,"carries");function m(t){const e=(t.messages??[]).map(n=>Array.isArray(n?.content)&&n.content.some(o=>o?.type==="image_url")?{...n,content:n.content.map(o=>o?.type==="image_url"?{type:"text",text:r}:o)}:n);return{...t,messages:e}}i(m,"strip");export{r as NOTE,u as carries,c as refused,m as strip};
|
|
2
|
+
//# sourceMappingURL=images.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=Object.defineProperty;var s=(r,t)=>f(r,"name",{value:t,configurable:!0});import*as a from"./http.mjs";async function h({endpoint:r,transport:t,signal:d,timeout:i,auth:l,extraHeaders:n}){const o=await a.json(t,a.join(r.url,"/v1/models"),{method:"GET",headers:a.headers(r,l,n),signal:d,timeout:i});return!o.ok||!Array.isArray(o.body?.data)?null:o.body.data.filter(e=>e&&typeof e.id=="string")}s(h,"fetchModels");export{h as fetchModels};
|
|
2
|
+
//# sourceMappingURL=models.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var n=(t,e)=>s(t,"name",{value:e,configurable:!0});function i(t){if(Array.isArray(t.tools)&&t.tools.length>0)return t;const e={...t};return delete e.tools,delete e.tool_choice,delete e.parallel_tool_calls,e}n(i,"noEmptyTools");function u(t){const e=/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(String(t??""));return e?[Number(e[1]),Number(e[2]??0),Number(e[3]??0)]:null}n(u,"semver");function a(t,e){const o=u(t);if(!o)return!0;const l=u(e);for(let r=0;r<3;r++)if(o[r]!==l[r])return o[r]>l[r];return!0}n(a,"atLeast");export{a as atLeast,i as noEmptyTools,u as semver};
|
|
2
|
+
//# sourceMappingURL=normalize.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var _=(t,e)=>r(t,"name",{value:e,configurable:!0});const i=["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"],p=["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([...i,...p]),c=new Set(["include_usage","continuous_usage_stats"]);function m(t){const e={};for(const[o,s]of Object.entries(t))if(l.has(o))if(o==="stream_options"){const n=Object.fromEntries(Object.entries(s??{}).filter(([a])=>c.has(a)));Object.keys(n).length>0&&(e.stream_options=n)}else e[o]=s;return e}_(m,"filterChatBody");export{m as filterChatBody};
|
|
2
|
+
//# sourceMappingURL=passthrough.mjs.map
|
package/dist/lib/pdf.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=Object.defineProperty;var r=(t,e)=>f(t,"name",{value:e,configurable:!0});import{TranslatorError as u}from"./errors.mjs";let n=null,l=null,i=!1;async function g(t=e=>import(e)){const e={};n=null,l=null;try{n=await t("unpdf")}catch(a){e.unpdf=a.message}try{l=await t("@napi-rs/canvas")}catch(a){e.canvas=a.message}return i=!0,{unpdf:n!==null,canvas:l!==null,errors:e}}r(g,"load");function x(){return{unpdf:n!==null,canvas:l!==null}}r(x,"available");async function y(){if(i||await g(),n===null)throw new u("PDF support is unavailable: the unpdf library could not be loaded",{code:"pdf_unavailable",status:501})}r(y,"ensure");async function c(t,e){if(await y(),t.length>e.maxBytes)throw new u(`PDF is too large: ${t.length} bytes exceeds the ${e.maxBytes} byte maximum`,{code:"pdf_too_large",status:413,type:"request_too_large"});let a;try{a=await n.getDocumentProxy(new Uint8Array(t))}catch(o){throw new u(`The PDF could not be read: ${o.message}`,{code:"pdf_unreadable",status:400,details:{name:o.name}})}if(a.numPages>e.maxPages)throw await a.loadingTask.destroy(),new u(`A maximum of ${e.maxPages} PDF pages may be provided (this document has ${a.numPages})`,{code:"pdf_too_many_pages",status:400});return a}r(c,"open");async function h(t,e){const a=await c(t,e);try{const{text:o}=await n.extractText(a,{mergePages:!1}),{info:s}=await n.getMeta(a);return{pageCount:a.numPages,title:typeof s?.Title=="string"&&s.Title!==""?s.Title:null,pages:o}}finally{await a.loadingTask.destroy()}}r(h,"extract");async function v(t,e,a){const o=await c(t,a);try{if(l===null)throw new u("PDF page rendering is unavailable: @napi-rs/canvas could not be loaded",{code:"pdf_unavailable",status:501});const s=[];for(const d of e){const p=await n.renderPageAsImage(o,d,{canvasImport:r(async()=>l,"canvasImport"),scale:a.scale});s.push({media_type:"image/png",data:Buffer.from(p).toString("base64")})}return s}finally{await o.loadingTask.destroy()}}r(v,"render");export{x as available,h as extract,g as load,v as render};
|
|
2
|
+
//# sourceMappingURL=pdf.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var y=Object.defineProperty;var r=(n,i)=>y(n,"name",{value:i,configurable:!0});const s=Symbol("tick");async function*m(n,i,o){const l=n[Symbol.asyncIterator]();let t=null;try{for(;;){t??=l.next();let e;if(i>0){let c;const a=new Promise(u=>{c=setTimeout(u,i,s)});if(e=await Promise.race([t,a]),clearTimeout(c),e===s){yield typeof o=="function"?o():o;continue}}else e=await t;if(t=null,e.done)return;yield e.value}}finally{t?.catch(()=>{}),Promise.resolve(l.return?.()).catch(()=>{})}}r(m,"withPings");export{m as withPings};
|
|
2
|
+
//# sourceMappingURL=ping.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=Object.defineProperty;var a=(e,s)=>u(e,"name",{value:s,configurable:!0});function d(e,s){return(e.models??e.facts?.models??[]).includes(s)?!0:e.protocol==="anthropic.messages"&&e.models===void 0&&/^claude-/.test(s)}a(d,"serves");function i(e,s,t){const r=Object.hasOwn(e.aliases,t)?e.aliases[t]:t,c=s.find(l=>d(l,r)),n=s.find(l=>l.default)??s[0];if(c)return{endpoint:c,model:r,unserved:!1};const o=n.models??n.facts?.models??[];return o.length===1?{endpoint:n,model:o[0],unserved:!1}:{endpoint:n,model:r,unserved:!0}}a(i,"pick");export{i as pick,d as serves};
|
|
2
|
+
//# sourceMappingURL=route.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var E=Object.defineProperty;var l=(n,o)=>E(n,"name",{value:o,configurable:!0});import{timingSafeEqual as x}from"node:crypto";import{TranslatorError as h}from"./errors.mjs";import{messageId as S}from"./ids.mjs";import{sign as A}from"./thinking.mjs";const H=64*1024*1024,T={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"},y=Symbol("stalled"),_=Symbol("gone");async function D(n,o){if(!(o>0))return n;let r;const c=new Promise(f=>{r=setTimeout(f,o,y)});try{return await Promise.race([n,c])}finally{clearTimeout(r)}}l(D,"settle");async function*L(n,o,r){const c=o.front==="anthropic";c&&(yield{event:"message_start",data:{type:"message_start",message:{id:S(),type:"message",role:"assistant",model:r,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 f=await n,i=l(function*(){yield{event:"content_block_delta",data:{type:"content_block_delta",index:0,delta:{type:"signature_delta",signature:A()}}},yield{event:"content_block_stop",data:{type:"content_block_stop",index:0}}},"closeEarly");if(f.stream){let u=null;for await(const a of f.stream){if(!c){yield a;continue}if(a.event!=="message_start"){if(u===null&&a.event==="content_block_start"&&a.data.content_block.type==="thinking"){u=0;continue}u===null&&(yield*i(),u=1),yield u>0&&typeof a.data?.index=="number"?{...a,data:{...a.data,index:a.data.index+u}}:a}}return}c&&(yield*i()),yield*k(o,f.body)}l(L,"late");function*k(n,o){if(n.front==="anthropic"){yield{event:"error",data:o};return}yield{data:o},yield{data:"[DONE]"}}l(k,"failure");async function v(n,o,r,c,f=200,i=T){n.hijack();const u=n.raw;u.writeHead(f,i);try{await o.write(u,c,{front:o.front,interval:o.interval})}catch(a){if(!r.signal.aborted){const d=a instanceof h;d||n.log.error(a);const{body:b}=o.build(d?a.status:502,d?a.message:"Internal server error",d?{type:a.type,code:a.code}:{});for(const t of k(o,b))u.write(o.encode(t))}}return u.end(),n}l(v,"stream");function O(n,o){const r=Buffer.from(n),c=Buffer.from(o);return r.length===c.length&&x(r,c)}l(O,"same");function B(n){const o=/^Bearer\s+(.+)$/i.exec(n.authorization??"");return n["x-api-key"]||o?.[1]||""}l(B,"keyOf");function I(n){const o={};for(const[r,c]of Object.entries(n))(r==="anthropic-beta"||r==="anthropic-version"||r.startsWith("x-claude-code-"))&&(o[r]=String(c));return o}l(I,"forwardable");function N(n,o,r){const{front:c,filter:f}=r,i={...r,build:l((t,e,s={})=>r.build(t,e,{...s,front:c}),"build"),send:l((t,e)=>r.send(t,{...e,front:c,filter:f}),"send"),count:l((t,e)=>r.count(t,{...e,front:c}),"count"),list:l(t=>r.list({...t,front:c}),"list")},u=[o.apiKey??[]].flat().filter(Boolean),a=o.bodyLimit??H,d=l((t,e)=>t.code(e.status).headers(e.headers).send(e.body),"reject");n.setErrorHandler((t,e,s)=>{if(t instanceof h)return d(s,i.build(t.status,t.message,{type:t.type,code:t.code,param:t.param}));const m=t.statusCode??500;return m<500?d(s,i.build(m,t.message)):(e.log.error(t),d(s,i.build(m,"Internal server error")))}),n.addHook("onRequest",async(t,e)=>{if(u.length===0||t.routeOptions.config?.public)return;const s=B(t.headers);if(!(s&&u.some(m=>O(s,m))))return d(e,i.build(401,"invalid x-api-key"))}),n.route({method:["GET","HEAD"],url:"/",config:{public:!0},handler:l(async(t,e)=>e.send({ok:!0}),"handler")}),n.route({method:["GET","HEAD"],url:"/api/hello",config:{public:!0},handler:l(async(t,e)=>e.send({ok:!0}),"handler")}),n.get("/v1/models",async(t,e)=>{const s=new AbortController;return e.raw.on("close",()=>s.abort()),i.list({signal:s.signal})});const b=i.front==="anthropic"?"/v1/messages":"/v1/chat/completions";n.post(b,{bodyLimit:a},async(t,e)=>{if(e.raw.destroyed)return e;const s=new AbortController;e.raw.on("close",()=>{e.raw.writableFinished||s.abort()});const m=i.send(t.body,{signal:s.signal,clientHeaders:I(t.headers)});m.catch(()=>{});const w=new Promise(p=>s.signal.addEventListener("abort",()=>p(_),{once:!0})),g=await D(Promise.race([m,w]),t.body?.stream===!0?i.interval:0);return g===_?e:g===y?v(e,i,s,L(m,i,t.body?.model)):g.stream?v(e,i,s,g.stream,g.status,g.headers):d(e,g)}),i.front==="anthropic"&&n.post("/v1/messages/count_tokens",{bodyLimit:a},async(t,e)=>{const s=new AbortController;return e.raw.on("close",()=>s.abort()),i.count(t.body,{signal:s.signal})})}l(N,"register");export{N as register};
|
|
2
|
+
//# sourceMappingURL=routes.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var u=(i,n)=>o(i,"name",{value:n,configurable:!0});const f=Number.MAX_SAFE_INTEGER,m=["maximum","minimum","exclusiveMaximum","exclusiveMinimum"];function r(i){if(Array.isArray(i))return i.map(r);if(i===null||typeof i!="object")return i;const n={};for(const[t,e]of Object.entries(i))t!=="$schema"&&(m.includes(t)&&typeof e=="number"&&Math.abs(e)>=f||(n[t]=r(e)));return n}u(r,"sanitize");export{r as sanitize};
|
|
2
|
+
//# sourceMappingURL=schema.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var s=(n,t)=>l(n,"name",{value:t,configurable:!0});import{TranslatorError as a}from"./errors.mjs";const i=Object.freeze({inlineSystem:"auto",stripBillingHeader:!0,reasoningField:"reasoning",thinkTags:!0,thinking:"chat_template_kwargs",thinkingBudget:!1,effort:!1,images:!0,imageFallback:!0,documents:"extract",documentConverter:null,pdf:Object.freeze({pages:!0,maxPages:100,maxBytes:32*1024*1024,maxImages:20,scale:1.5}),toolSchema:"pass",deferredTools:"forward",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,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"],maxTokensField:["max_completion_tokens","max_tokens"],prefill:["continue_final_message","none"],unknownFields:["drop","error"],toolStreaming:["buffer","stream"]},d=["effortPassthrough","passthroughFilter","imageFallback"];function g(...n){const t={...i,pdf:{...i.pdf}};for(const e of n)if(e)for(const[o,r]of Object.entries(e))r!==void 0&&(o==="pdf"?Object.assign(t.pdf,r):t[o]=r);for(const[e,o]of Object.entries(f))if(!o.includes(t[e]))throw new a(`Invalid setting ${e}: ${JSON.stringify(t[e])} (expected one of ${o.join(", ")})`,{code:"invalid_setting",status:500,details:{key:e,allowed:o}});for(const e of d)if(typeof t[e]!="boolean")throw new a(`Invalid setting ${e}: ${JSON.stringify(t[e])} (expected true or false)`,{code:"invalid_setting",status:500,details:{key:e}});return t}s(g,"resolve");export{i as DEFAULTS,g as resolve};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});async function*f(e){if(typeof e?.getReader=="function"){const t=e.getReader();try{for(;;){const{done:i,value:n}=await t.read();if(i)return;yield n}}finally{await t.cancel().catch(()=>{})}}else if(typeof e?.[Symbol.asyncIterator]=="function")yield*e;else if(typeof e!="string"&&typeof e?.[Symbol.iterator]=="function"&&!(e instanceof Uint8Array))for(const t of e)yield t;else yield e}o(f,"items");async function*d(e){const t=new TextDecoder;for await(const n of f(e))yield typeof n=="string"?n:t.decode(n,{stream:!0});const i=t.decode();i&&(yield i)}o(d,"text");export{f as items,d as text};
|
|
2
|
+
//# sourceMappingURL=source.mjs.map
|
package/dist/lib/sse.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var g=Object.defineProperty;var c=(e,n)=>g(e,"name",{value:n,configurable:!0});import{items as h}from"./source.mjs";import{TranslatorError as v}from"./errors.mjs";function y(){let e="",n=!0,r,t,a=[];const l=c(i=>{if(a.length>0){const f={data:a.join(`
|
|
2
|
+
`)};r!==void 0&&(f.event=r),t!==void 0&&(f.id=t),i.push(f)}r=void 0,t=void 0,a=[]},"dispatch"),p=c((i,f)=>{if(i==="")return l(f);if(i.startsWith(":"))return;const d=i.indexOf(":"),s=d===-1?i:i.slice(0,d);let o=d===-1?"":i.slice(d+1);o.startsWith(" ")&&(o=o.slice(1)),s==="data"?a.push(o):s==="event"?r=o:s==="id"&&(t=o)},"line");return{push(i){const f=[];e+=i,n&&e.length>0&&(n=!1,e.charCodeAt(0)===65279&&(e=e.slice(1)));let d=0;for(let s=0;s<e.length;s++){const o=e[s];if(!(o!==`
|
|
3
|
+
`&&o!=="\r")){if(o==="\r"&&s===e.length-1)break;p(e.slice(d,s),f),o==="\r"&&e[s+1]===`
|
|
4
|
+
`&&s++,d=s+1}}return e=e.slice(d),f},flush(){const i=[];return e.length>0&&(p(e.replace(/\r$/,""),i),e=""),l(i),i}}}c(y,"createParser");async function*S(e){const n=y(),r=new TextDecoder;for await(const t of h(e)){const a=typeof t=="string"?t:r.decode(t,{stream:!0});yield*n.push(a)}yield*n.push(r.decode()),yield*n.flush()}c(S,"parse");function $({event:e,data:n,id:r}){let t="";e!==void 0&&(t+=`event: ${e}
|
|
5
|
+
`),r!==void 0&&(t+=`id: ${r}
|
|
6
|
+
`);const a=typeof n=="string"?n:JSON.stringify(n);for(const l of a.split(`
|
|
7
|
+
`))t+=`data: ${l}
|
|
8
|
+
`;return`${t}
|
|
9
|
+
`}c($,"encode");async function*E(e){const n=y(),r=new TextDecoder;for await(const t of h(e))if(typeof t=="string"||t instanceof Uint8Array){const a=typeof t=="string"?t:r.decode(t,{stream:!0});for(const l of n.push(a))yield u(l)}else"data"in t?yield typeof t.data=="string"?u(t):t:yield t.type===void 0?{data:t}:{event:t.type,data:t};for(const t of[...n.push(r.decode()),...n.flush()])yield u(t)}c(E,"messages");function u(e){if(e.data==="[DONE]")return e;try{return{...e,data:JSON.parse(e.data)}}catch{throw new v("Upstream sent an SSE event whose data is not valid JSON",{code:"invalid_stream_data",status:502,details:{data:e.data}})}}c(u,"decodeEvent");export{y as createParser,$ as encode,E as messages,S as parse};
|
|
10
|
+
//# sourceMappingURL=sse.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var p=Object.defineProperty;var i=(t,e)=>p(t,"name",{value:e,configurable:!0});const g="llmt:",l="<think>",o="</think>";function x(){return g+Buffer.from(JSON.stringify({v:1})).toString("base64url")}i(x,"sign");function d(t){return typeof t=="string"&&t.startsWith(g)}i(d,"isOurs");function S(t){const e=t?.reasoning??t?.reasoning_content;return typeof e=="string"?e:""}i(S,"reasoningOf");function O(t){const e=t.trimStart();if(!e.startsWith(l))return{reasoning:"",text:t};const r=e.indexOf(o);return r===-1?{reasoning:e.slice(l.length),text:""}:{reasoning:e.slice(l.length,r),text:e.slice(r+o.length).trimStart()}}i(O,"splitThink");function b(){let t="start",e="";const r=i((a,f)=>{let c="",h="",n=e+a;for(e="";;){if(t==="plain"){h+=n;break}if(t==="start"){const s=n.trimStart();if(s===""&&!f){e=n;break}if(s.startsWith(l))t="think",n=s.slice(l.length);else if(!f&&s!==""&&l.startsWith(s)){e=n;break}else t="plain"}else if(t==="think"){const s=n.indexOf(o);if(s!==-1){c+=n.slice(0,s),n=n.slice(s+o.length),t="after";continue}const u=f?0:k(n,o);c+=n.slice(0,n.length-u),e=n.slice(n.length-u);break}else{if(n=n.trimStart(),n==="")break;t="plain"}}return{reasoning:c,text:h}},"step");return{push:i(a=>r(a,!1),"push"),end:i(()=>r("",!0),"end")}}i(b,"createThinkSplitter");function k(t,e){for(let r=Math.min(t.length,e.length-1);r>0;r--)if(e.startsWith(t.slice(t.length-r)))return r;return 0}i(k,"partialSuffix");export{b as createThinkSplitter,d as isOurs,S as reasoningOf,x as sign,O as splitThink};
|
|
2
|
+
//# sourceMappingURL=thinking.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var E=Object.defineProperty;var d=(o,t)=>E(o,"name",{value:t,configurable:!0});import L from"node:http";import C from"node:https";import{Readable as x}from"node:stream";const O=new Set([204,205,304]);function m(o,t={},n={http:L,https:C}){const u=new URL(o),p={"accept-encoding":"identity",...t.headers};t.body!==void 0&&(p["content-length"]=String(Buffer.byteLength(t.body)));const{signal:r,redirect:b}=t;return new Promise((l,s)=>{if(r?.aborted)return s(r.reason);const a=(u.protocol==="https:"?n.https:n.http).request(u,{method:t.method??"GET",headers:p,agent:!1},e=>{if(r?.removeEventListener("abort",c),b==="error"&&e.statusCode>=300&&e.statusCode<400&&e.headers.location)return e.destroy(),s(new TypeError(`unexpected redirect to ${e.headers.location}`));const f=new Headers;for(const[y,w]of Object.entries(e.headers))for(const v of[].concat(w))f.append(y,v);const h=O.has(e.statusCode)?null:x.toWeb(e);h===null&&e.resume(),l(new Response(h,{status:e.statusCode,statusText:e.statusMessage,headers:f})),r?.addEventListener("abort",()=>e.destroy(r.reason),{once:!0})}),c=d(()=>a.destroy(r.reason),"onAbort");r?.addEventListener("abort",c,{once:!0}),a.on("error",s),a.end(t.body)})}d(m,"transport");export{m as transport};
|
|
2
|
+
//# sourceMappingURL=transport.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var i=(e,t)=>a(e,"name",{value:t,configurable:!0});import{contextOverflow as c,rewriteContextOverflow as u,statusToAnthropicType as f}from"./errors.mjs";function m(e){if(typeof e=="string"&&e!=="")return e;if(!Array.isArray(e))return;const t=e.map(r=>r?.msg).filter(r=>typeof r=="string"&&r!=="");return t.length>0?t.join("; "):void 0}i(m,"detail");function g(e){const t=f(e);return t==="api_error"&&e<500?"invalid_request_error":t}i(g,"anthropicType");function y(e){return e===401?"authentication_error":e===403?"permission_denied_error":e===404?"not_found_error":e===429?"rate_limit_error":e>=500?"server_error":"invalid_request_error"}i(y,"openaiType");function l(e,t){const r=`upstream returned HTTP ${t}`;if(typeof e=="string")return{message:e||r};if(!e||typeof e!="object")return{message:r};const o=e.error;if(typeof o=="string")return{message:o};const n=o&&typeof o=="object"?o:e;return{message:typeof n.message=="string"&&n.message!==""?n.message:m(e.detail)??r,type:typeof n.type=="string"?n.type:void 0,code:n.code,param:n.param}}i(l,"parse");function x(e,t,r,o={}){if(e==="anthropic"){const s=u(r.message);if(s!==null)return{status:400,body:{type:"error",error:{type:"invalid_request_error",message:s}}};const p=o.native&&r.type?r.type:g(t);return{status:t,body:{type:"error",error:{type:p,message:r.message}}}}const n=o.native&&r.type?r.type:y(t);return{status:t,body:{error:{message:r.message,type:n,param:r.param??null,code:c(r.message)?"context_length_exceeded":r.code??null}}}}i(x,"render");export{g as anthropicType,y as openaiType,l as parse,x as render};
|
|
2
|
+
//# sourceMappingURL=upstream-error.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/llm-translator",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
7
7
|
"author": {
|
|
@@ -25,11 +25,14 @@
|
|
|
25
25
|
},
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"engines": {
|
|
28
|
-
"node": ">=
|
|
28
|
+
"node": ">=22.15.0"
|
|
29
29
|
},
|
|
30
30
|
"main": "./dist/index.cjs",
|
|
31
31
|
"module": "./dist/index.mjs",
|
|
32
32
|
"types": "./types/src/index.d.mts",
|
|
33
|
+
"bin": {
|
|
34
|
+
"llm-translator": "./dist/bin/llm-translator.mjs"
|
|
35
|
+
},
|
|
33
36
|
"exports": {
|
|
34
37
|
".": {
|
|
35
38
|
"llm-translator-dev": {
|
|
@@ -59,8 +62,15 @@
|
|
|
59
62
|
"homepage": "https://github.com/CLDMV/llm-translator#readme",
|
|
60
63
|
"keywords": [
|
|
61
64
|
"llm",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
65
|
+
"anthropic",
|
|
66
|
+
"openai",
|
|
67
|
+
"claude-code",
|
|
68
|
+
"vllm",
|
|
69
|
+
"chat-completions",
|
|
70
|
+
"messages-api",
|
|
71
|
+
"translator",
|
|
72
|
+
"proxy",
|
|
73
|
+
"slothlet"
|
|
64
74
|
],
|
|
65
75
|
"scripts": {
|
|
66
76
|
"build": "tsup",
|
|
@@ -80,12 +90,26 @@
|
|
|
80
90
|
"format:check": "prettier --config .configs/.prettierrc --check .",
|
|
81
91
|
"fix:headers": "fix-headers --config .configs/fix-headers.json"
|
|
82
92
|
},
|
|
93
|
+
"peerDependencies": {
|
|
94
|
+
"fastify": "^5.12.7"
|
|
95
|
+
},
|
|
96
|
+
"peerDependenciesMeta": {
|
|
97
|
+
"fastify": {
|
|
98
|
+
"optional": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"dependencies": {
|
|
102
|
+
"@cldmv/slothlet": "^3.22.1",
|
|
103
|
+
"@napi-rs/canvas": "^1.0.13",
|
|
104
|
+
"unpdf": "^1.9.1"
|
|
105
|
+
},
|
|
83
106
|
"devDependencies": {
|
|
84
107
|
"@cldmv/configs": "^1.3.0",
|
|
85
108
|
"@cldmv/eslint-plugin-jsonv": "^1.0.17",
|
|
86
109
|
"@cldmv/fix-headers": "^2.2.2",
|
|
87
110
|
"@cldmv/jsonv": "^1.1.5",
|
|
88
111
|
"@cldmv/prettier-plugin-jsonv": "^1.1.4",
|
|
112
|
+
"@cldmv/slothlet-types": "^3.22.1",
|
|
89
113
|
"@cldmv/vitest-runner": "^1.5.4",
|
|
90
114
|
"@eslint/css": "^2.0.1",
|
|
91
115
|
"@eslint/js": "^10.0.1",
|
|
@@ -94,6 +118,7 @@
|
|
|
94
118
|
"@types/node": "^26.6.5",
|
|
95
119
|
"@vitest/coverage-v8": "^5.0.5",
|
|
96
120
|
"eslint": "^10.13.0",
|
|
121
|
+
"fastify": "^5.12.7",
|
|
97
122
|
"globals": "^17.13.0",
|
|
98
123
|
"prettier": "^3.9.10",
|
|
99
124
|
"tsup": "^9.0.0",
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Convert an Anthropic Messages request body into an OpenAI Chat Completions request body.
|
|
17
|
+
*
|
|
18
|
+
* Returns the converted body plus a JSON-serializable `state` the response/stream converters need (original model,
|
|
19
|
+
* tool-name map, thinking mode, fields that were dropped).
|
|
20
|
+
* @param {any} body - Anthropic `POST /v1/messages` body.
|
|
21
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
22
|
+
* @returns {Promise<{ body: any, state: any }>} OpenAI request body and conversion state.
|
|
23
|
+
* @throws {TranslatorError} For malformed requests, unsupported content when configured to error, or PDF limit violations.
|
|
24
|
+
*/
|
|
25
|
+
export declare function request(body: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): Promise<{
|
|
26
|
+
body: any;
|
|
27
|
+
state: any;
|
|
28
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Convert an Anthropic message into an OpenAI `chat.completion`. Text blocks are concatenated, `thinking` blocks
|
|
17
|
+
* 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, redacted thinking) are skipped.
|
|
19
|
+
* @param {any} message - Anthropic message.
|
|
20
|
+
* @param {any} [state] - State from the request converter (original model, tool-name map).
|
|
21
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
22
|
+
* @returns {any} OpenAI chat completion.
|
|
23
|
+
*/
|
|
24
|
+
export declare function response(message: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Convert an Anthropic Messages event stream into OpenAI `chat.completion.chunk` messages followed by `[DONE]`.
|
|
17
|
+
*
|
|
18
|
+
* `source` is SSE text/bytes, an iterable of `{ event, data }` pairs, or an iterable of bare event payloads. The
|
|
19
|
+
* result yields `{ data }` messages (chunk objects, then the string `"[DONE]"`); encode them with `lib/sse.mjs`.
|
|
20
|
+
* Usage is emitted as a final `choices: []` chunk when `state.includeUsage` is not false. An Anthropic `error`
|
|
21
|
+
* event, or a stream that ends before `message_stop`, becomes a `{ error }` chunk followed by `[DONE]`.
|
|
22
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array} source - Anthropic stream.
|
|
23
|
+
* @param {any} [state] - State from the request converter (model, `includeUsage`, tool-name map).
|
|
24
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
25
|
+
* @returns {AsyncGenerator<{ data: any|string }, void, undefined>} OpenAI chunks.
|
|
26
|
+
*/
|
|
27
|
+
export declare function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
28
|
+
data: any | string;
|
|
29
|
+
}, void, undefined>;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Convert an OpenAI Chat Completions request body into an Anthropic Messages request body (for an OpenAI-protocol
|
|
17
|
+
* client talking to an Anthropic-protocol upstream).
|
|
18
|
+
*
|
|
19
|
+
* `system` and `developer` messages are hoisted into the top-level `system`; assistant reasoning is not forwarded
|
|
20
|
+
* (real Anthropic rejects thinking blocks without its own signatures); consecutive same-role turns are merged and
|
|
21
|
+
* tool results are grouped into one user turn with the results first, as Anthropic requires.
|
|
22
|
+
* @param {any} chatBody - OpenAI `POST /v1/chat/completions` body.
|
|
23
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
24
|
+
* @returns {Promise<{ body: any, state: any }>} Anthropic request body and conversion state.
|
|
25
|
+
* @throws {TranslatorError} For malformed requests, `n` above 1, unknown roles, or unknown fields when configured to error.
|
|
26
|
+
*/
|
|
27
|
+
export declare function request(chatBody: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): Promise<{
|
|
28
|
+
body: any;
|
|
29
|
+
state: any;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Convert a (non-streaming) OpenAI chat completion into an Anthropic message.
|
|
17
|
+
*
|
|
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
|
|
20
|
+
* a JSON object are passed through under `_raw_arguments` so the client reports a tool error the model can recover
|
|
21
|
+
* from.
|
|
22
|
+
* @param {any} completion - OpenAI `chat.completion` object.
|
|
23
|
+
* @param {any} [state] - State from the request converter (original model, tool-name map).
|
|
24
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
25
|
+
* @returns {any} Anthropic message.
|
|
26
|
+
* @throws {TranslatorError} When the completion has no choices.
|
|
27
|
+
*/
|
|
28
|
+
export declare function response(completion: any, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): any;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Convert an OpenAI chat-completion stream into Anthropic Messages stream events.
|
|
17
|
+
*
|
|
18
|
+
* `source` is SSE text/bytes (string, `Uint8Array`, `ReadableStream`, async or sync iterable of either) or an
|
|
19
|
+
* iterable of already-parsed chunk objects. Handles reasoning (`reasoning`, `reasoning_content`, leading
|
|
20
|
+
* `<think>`), the three vLLM tool-call delta shapes (id+name first then argument fragments, name and arguments
|
|
21
|
+
* together, whole call at once), usage-only final chunks, `[DONE]`, mid-stream `{"error":...}` objects (answered
|
|
22
|
+
* with an Anthropic `error` event) and closing the iterator early (the upstream source is closed too). Pings are
|
|
23
|
+
* the SSE writer's job, not this converter's.
|
|
24
|
+
*
|
|
25
|
+
* Tool calls follow `settings.toolStreaming`. `buffer` (default) holds every call until the stream finishes and then emits
|
|
26
|
+
* each one, in index order, as a single complete `tool_use` block (start, one `input_json_delta`, stop); text and
|
|
27
|
+
* thinking stream immediately, so they appear before the tool blocks and no argument fragment can arrive too late.
|
|
28
|
+
* `stream` forwards argument fragments incrementally; calls that start while a tool block is streaming are buffered and
|
|
29
|
+
* emitted whole when it closes, and text that arrives meanwhile is held until the tool blocks are done.
|
|
30
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array} source - OpenAI stream.
|
|
31
|
+
* @param {any} [state] - State from the request converter (original model, tool-name map).
|
|
32
|
+
* @param {Partial<import("../../../../../../../lib/settings.mjs").Settings>} [settings] - Translator settings.
|
|
33
|
+
* @returns {AsyncGenerator<{ event: string, data: any }, void, undefined>} Anthropic events.
|
|
34
|
+
*/
|
|
35
|
+
export declare function stream(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array, state?: any, settings?: Partial<import("../../../../../../../lib/settings.mjs").Settings>): AsyncGenerator<{
|
|
36
|
+
event: string;
|
|
37
|
+
data: any;
|
|
38
|
+
}, void, undefined>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Bind every endpoint to a driver. `backend: "auto"` endpoints are probed (drivers tried in `info().order`, the generic
|
|
17
|
+
* driver matches last); endpoints with an explicit `backend` skip detection. Call it again to re-probe.
|
|
18
|
+
* @param {any} [options] - `{ network, signal }`. `network: false` skips all probing (auto endpoints fall back to the generic driver).
|
|
19
|
+
* @returns {Promise<any>} The `status()` result.
|
|
20
|
+
*/
|
|
21
|
+
export declare function detect(options?: any): Promise<any>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/anthropic/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
|
+
/**
|
|
16
|
+
* @fileoverview Anthropic driver: matches the api.anthropic.com host.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/anthropic
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Match by host name, no network access. Other Anthropic-compatible servers are selected with `backend: "anthropic"`.
|
|
21
|
+
* @param {any} context - `{ endpoint }`.
|
|
22
|
+
* @returns {{host: string} | null} Facts, or null when the endpoint is not api.anthropic.com.
|
|
23
|
+
*/
|
|
24
|
+
export declare 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/anthropic/info.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
|
+
/**
|
|
16
|
+
* @fileoverview Anthropic driver: static facts about the backend.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/anthropic
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Describe the Anthropic driver (native Messages API upstream).
|
|
21
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, headers: Record<string,string>, paths: Record<string,string>}} Driver facts.
|
|
22
|
+
*/
|
|
23
|
+
export declare function info(): {
|
|
24
|
+
name: string;
|
|
25
|
+
protocol: string;
|
|
26
|
+
order: number;
|
|
27
|
+
auth: string;
|
|
28
|
+
headers: Record<string, string>;
|
|
29
|
+
paths: Record<string, string>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/anthropic/model/list.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
|
+
/**
|
|
16
|
+
* List the models the Anthropic API reports.
|
|
17
|
+
* @param {any} context - `{ endpoint, transport, signal, timeout }`.
|
|
18
|
+
* @returns {Promise<any[] | null>} Models, or null when unreachable.
|
|
19
|
+
*/
|
|
20
|
+
export declare function list(context: any): Promise<any[] | null>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/anthropic/settings.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
|
+
/**
|
|
16
|
+
* @fileoverview Anthropic driver: translator settings.
|
|
17
|
+
* @module @cldmv/llm-translator/driver/anthropic
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The Messages API needs no special settings; the converters use the library defaults.
|
|
21
|
+
* @returns {any} Partial settings (empty).
|
|
22
|
+
*/
|
|
23
|
+
export declare function settings(): any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/anthropic/token/count.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
|
+
/**
|
|
16
|
+
* Count tokens with the Anthropic API.
|
|
17
|
+
* @param {any} context - `{ endpoint, request, transport, signal, timeout }`.
|
|
18
|
+
* @returns {Promise<number | null>} Token count, or null when the API did not answer.
|
|
19
|
+
*/
|
|
20
|
+
export declare function count({ endpoint, request, transport, signal, timeout }: any): Promise<number | null>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/api/driver/compatible/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
|
+
/**
|
|
16
|
+
* Probe `/v1/models` for reachability and the served model ids. Never returns null: this driver is the fallback.
|
|
17
|
+
* @param {any} context - `{ endpoint, transport, signal, timeout }`.
|
|
18
|
+
* @returns {Promise<{reachable: boolean, models: string[]}>} Facts.
|
|
19
|
+
*/
|
|
20
|
+
export declare function detect(context: any): Promise<{
|
|
21
|
+
reachable: boolean;
|
|
22
|
+
models: string[];
|
|
23
|
+
}>;
|