@cldmv/llm-translator 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +11 -7
  2. package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +5 -3
  3. package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
  4. package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +1 -1
  5. package/dist/api/detect.mjs +1 -1
  6. package/dist/api/driver/anthropic/info.mjs +1 -1
  7. package/dist/api/driver/compatible/info.mjs +1 -1
  8. package/dist/api/driver/deepseek/info.mjs +1 -1
  9. package/dist/api/driver/llamacpp/info.mjs +1 -1
  10. package/dist/api/driver/ollama/info.mjs +1 -1
  11. package/dist/api/driver/openai/info.mjs +1 -1
  12. package/dist/api/driver/sglang/info.mjs +1 -1
  13. package/dist/api/driver/vllm/info.mjs +1 -1
  14. package/dist/api/embeddings/send.mjs +2 -0
  15. package/dist/api/events/off.mjs +2 -0
  16. package/dist/api/events/on.mjs +2 -0
  17. package/dist/api/request.mjs +2 -2
  18. package/dist/api/send.mjs +1 -1
  19. package/dist/api/server/plugin.mjs +1 -1
  20. package/dist/index.mjs +1 -1
  21. package/dist/lib/cli.mjs +7 -6
  22. package/dist/lib/config.mjs +1 -1
  23. package/dist/lib/effort.mjs +1 -1
  24. package/dist/lib/events.mjs +4 -0
  25. package/dist/lib/finish.mjs +1 -1
  26. package/dist/lib/record.mjs +3 -0
  27. package/dist/lib/routes.mjs +1 -1
  28. package/dist/lib/sampling.mjs +2 -0
  29. package/dist/lib/settings.mjs +1 -1
  30. package/dist/lib/strict.mjs +2 -0
  31. package/dist/lib/usage.mjs +1 -1
  32. package/dist/lib/warn.mjs +1 -1
  33. package/package.json +1 -1
  34. package/types/src/api/driver/anthropic/info.d.mts +2 -1
  35. package/types/src/api/driver/compatible/info.d.mts +2 -1
  36. package/types/src/api/driver/deepseek/info.d.mts +2 -1
  37. package/types/src/api/driver/llamacpp/info.d.mts +2 -1
  38. package/types/src/api/driver/ollama/info.d.mts +2 -1
  39. package/types/src/api/driver/openai/info.d.mts +2 -1
  40. package/types/src/api/driver/sglang/info.d.mts +2 -1
  41. package/types/src/api/driver/vllm/info.d.mts +2 -1
  42. package/types/src/api/embeddings/send.d.mts +15 -0
  43. package/types/src/api/events/off.d.mts +7 -0
  44. package/types/src/api/events/on.d.mts +8 -0
  45. package/types/src/api/request.d.mts +7 -2
  46. package/types/src/api/send.d.mts +1 -1
  47. package/types/src/api/server/plugin.d.mts +2 -2
  48. package/types/src/index.d.mts +23 -3
  49. package/types/src/lib/effort.d.mts +6 -2
  50. package/types/src/lib/events.d.mts +86 -0
  51. package/types/src/lib/finish.d.mts +10 -3
  52. package/types/src/lib/record.d.mts +36 -0
  53. package/types/src/lib/sampling.d.mts +13 -0
  54. package/types/src/lib/settings.d.mts +15 -0
  55. package/types/src/lib/strict.d.mts +26 -0
  56. package/types/src/lib/usage.d.mts +4 -2
  57. package/types/src/lib/warn.d.mts +12 -23
@@ -1,2 +1,2 @@
1
- var l=Object.defineProperty;var s=(n,e)=>l(n,"name",{value:e,configurable:!0});import{TranslatorError as r}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,toolErrorMarker:"[error] ",toolErrorInference:!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","toolErrorInference"];function p(...n){const e={...i,pdf:{...i.pdf}};for(const t of n)if(t)for(const[o,a]of Object.entries(t))a!==void 0&&(o==="pdf"?Object.assign(e.pdf,a):e[o]=a);for(const[t,o]of Object.entries(f))if(!o.includes(e[t]))throw new r(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected one of ${o.join(", ")})`,{code:"invalid_setting",status:500,details:{key:t,allowed:o}});for(const t of d)if(typeof e[t]!="boolean")throw new r(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected true or false)`,{code:"invalid_setting",status:500,details:{key:t}});if(typeof e.toolErrorMarker!="string"||e.toolErrorMarker.trim()==="")throw new r(`Invalid setting toolErrorMarker: ${JSON.stringify(e.toolErrorMarker)} (expected a non-empty string)`,{code:"invalid_setting",status:500,details:{key:"toolErrorMarker"}});if(!(Number.isFinite(e.pdf.scale)&&e.pdf.scale>0))throw new r(`Invalid setting pdf.scale: ${JSON.stringify(e.pdf.scale)} (expected a positive number)`,{code:"invalid_setting",status:500,details:{key:"pdf.scale"}});return e}s(p,"resolve");export{i as DEFAULTS,p as resolve};
1
+ var l=Object.defineProperty;var i=(a,e)=>l(a,"name",{value:e,configurable:!0});import{TranslatorError as r}from"./errors.mjs";const s=Object.freeze({inlineSystem:"auto",stripBillingHeader:!0,reasoningField:"reasoning",thinkTags:!0,thinkOpen:!1,reasoningRoundTrip:!1,thinking:"chat_template_kwargs",thinkingBudget:!1,effort:!1,images:!0,imageFallback:!0,toolFallback:!1,documents:"extract",documentConverter:null,pdf:Object.freeze({pages:!0,maxPages:100,maxBytes:32*1024*1024,maxImages:20,scale:1.5}),toolSchema:"pass",deferredTools:"forward",toolSearch:"expand",jsonObject:"schema",jsonObjectFallback:!0,toolErrors:!1,toolErrorMarker:"[error] ",toolErrorInference:!1,maxTokensField:"max_completion_tokens",streamUsage:!0,continuousUsage:!1,prefill:"continue_final_message",topK:!0,responseFormat:!0,parallelToolCalls:!0,unknownFields:"drop",sampling:Object.freeze({}),pingInterval:1e4,toolStreaming:"buffer",effortPassthrough:!1,passthroughFilter:!1,contextWindow:0,defaultMaxTokens:8192}),f={inlineSystem:["auto","keep","hoist","user","drop"],reasoningField:["reasoning","reasoning_content"],thinking:["chat_template_kwargs","reasoning_effort","none"],documents:["extract","note","error"],toolSchema:["pass","sanitize"],deferredTools:["forward","drop"],toolSearch:["expand","inline","native"],jsonObject:["schema","instruction","drop"],maxTokensField:["max_completion_tokens","max_tokens"],prefill:["continue_final_message","none"],unknownFields:["drop","error"],toolStreaming:["buffer","stream"]},c=["effortPassthrough","passthroughFilter","imageFallback","toolFallback","jsonObjectFallback","thinkOpen","reasoningRoundTrip","toolErrorInference"];function p(...a){const e={...s,pdf:{...s.pdf},sampling:{...s.sampling}};for(const t of a)if(t)for(const[n,o]of Object.entries(t))o!==void 0&&(n==="pdf"?Object.assign(e.pdf,o):n==="sampling"&&o!==null&&typeof o=="object"&&!Array.isArray(o)?Object.assign(e.sampling,o):e[n]=o);for(const[t,n]of Object.entries(f))if(!n.includes(e[t]))throw new r(`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 c)if(typeof e[t]!="boolean")throw new r(`Invalid setting ${t}: ${JSON.stringify(e[t])} (expected true or false)`,{code:"invalid_setting",status:500,details:{key:t}});if(typeof e.toolErrorMarker!="string"||e.toolErrorMarker.trim()==="")throw new r(`Invalid setting toolErrorMarker: ${JSON.stringify(e.toolErrorMarker)} (expected a non-empty string)`,{code:"invalid_setting",status:500,details:{key:"toolErrorMarker"}});if(e.sampling===null||typeof e.sampling!="object"||Array.isArray(e.sampling))throw new r(`Invalid setting sampling: ${JSON.stringify(e.sampling)} (expected an object of field names and values)`,{code:"invalid_setting",status:500,details:{key:"sampling"}});if(!(Number.isFinite(e.pdf.scale)&&e.pdf.scale>0))throw new r(`Invalid setting pdf.scale: ${JSON.stringify(e.pdf.scale)} (expected a positive number)`,{code:"invalid_setting",status:500,details:{key:"pdf.scale"}});return e}i(p,"resolve");export{s as DEFAULTS,p as resolve};
2
2
  //# sourceMappingURL=settings.mjs.map
@@ -0,0 +1,2 @@
1
+ var l=Object.defineProperty;var p=(r,n)=>l(r,"name",{value:n,configurable:!0});const a=["allOf","not","if","then","else","dependentRequired","dependentSchemas","patternProperties","propertyNames","unevaluatedProperties","contains","minProperties","maxProperties","uniqueItems"],y=["items","additionalProperties"],d=["anyOf","oneOf","prefixItems"],$=["properties","$defs","definitions"];function f(r,n="$",i=[]){if(r===null||typeof r!="object"||Array.isArray(r))return i;const t=r.properties!==null&&typeof r.properties=="object"?Object.keys(r.properties):[];if(r.type==="object"||t.length>0){r.additionalProperties!==!1&&i.push(`${n}: object without additionalProperties: false`);const e=Array.isArray(r.required)?r.required:[],o=t.filter(s=>!e.includes(s));o.length>0&&i.push(`${n}: properties not in required: ${o.join(", ")}`)}for(const e of a)e in r&&i.push(`${n}: unsupported keyword ${e}`);for(const e of y)f(r[e],`${n}.${e}`,i);for(const e of d)Array.isArray(r[e])&&r[e].forEach((o,s)=>f(o,`${n}.${e}[${s}]`,i));for(const e of $){const o=r[e];if(!(o===null||typeof o!="object"))for(const[s,u]of Object.entries(o))f(u,`${n}.${e}.${s}`,i)}return i}p(f,"problems");function P(r){const n=[];for(const i of Array.isArray(r?.tools)?r.tools:[]){const t=i?.function??i;t?.strict===!0&&n.push({name:String(t.name),problems:f(t.parameters??t.input_schema)})}return n}p(P,"strictTools");function j(r){if(!Array.isArray(r?.tools))return r;let n=!1;const i=r.tools.map(t=>{const e=t?.function??t;if(e?.strict!==!0||f(e.parameters??e.input_schema).length===0)return t;if(n=!0,t.function){const{strict:u,...c}=t.function;return{...t,function:c}}const{strict:o,...s}=t;return s});return n?{...r,tools:i}:r}p(j,"relax");export{f as problems,j as relax,P as strictTools};
2
+ //# sourceMappingURL=strict.mjs.map
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty;var f=(t,o)=>v(t,"name",{value:o,configurable:!0});const m=["input_tokens","output_tokens","cache_read_input_tokens","cache_creation_input_tokens"],l=f(t=>Number.isFinite(t)?t:null,"count");function E(t,o){if(!o||typeof o!="object")return null;let i;if(t==="openai"){const r=l(o.prompt_tokens),a=l(o.prompt_tokens_details?.cached_tokens);i={input_tokens:r===null?null:Math.max(0,r-(a??0)),output_tokens:l(o.completion_tokens),cache_read_input_tokens:a,cache_creation_input_tokens:null}}else if(t==="folded"){const r=l(o.input_tokens);i={input_tokens:r===null?null:r+(l(o.cache_creation_input_tokens)??0),output_tokens:l(o.output_tokens),cache_read_input_tokens:l(o.cache_read_input_tokens)||null,cache_creation_input_tokens:null}}else i=Object.fromEntries(m.map(r=>[r,l(o[r])]));return m.every(r=>!i[r])?null:i}f(E,"normalize");function I(t){return!!t&&typeof t=="object"&&Array.isArray(t.choices)&&t.choices.length===0&&!!t.usage}f(I,"usageChunk");function P(t,o,i){const r=Object.fromEntries(m.map(e=>[e,null]));let a=!1,y=null,d=!1,b=!1,h=!1,p=null,w="openai",j;const g=new Promise(e=>{j=e}),k=f((e,u=t.front)=>{const c=E(u,e);if(c){a=!0;for(const n of m)c[n]!==null&&c[n]!==void 0&&(r[n]=c[n])}},"take"),_=f(e=>{if(d)return;d=!0,p&&k(p(),w);const u=e==="done"&&b?"error":e,c={...r,reported:a,estimated:y,complete:u==="done",reason:u,...t};j(c);try{Promise.resolve(o?.(c)).catch(n=>i(`onUsage rejected: ${n?.message??n}`))}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};
1
+ var v=Object.defineProperty;var f=(t,o)=>v(t,"name",{value:o,configurable:!0});const m=["input_tokens","output_tokens","cache_read_input_tokens","cache_creation_input_tokens"],l=f(t=>Number.isFinite(t)?t:null,"count");function E(t,o){if(!o||typeof o!="object")return null;let i;if(t==="openai"){const r=l(o.prompt_tokens),a=l(o.prompt_tokens_details?.cached_tokens);i={input_tokens:r===null?null:Math.max(0,r-(a??0)),output_tokens:l(o.completion_tokens),cache_read_input_tokens:a,cache_creation_input_tokens:null}}else if(t==="folded"){const r=l(o.input_tokens);i={input_tokens:r===null?null:r+(l(o.cache_creation_input_tokens)??0),output_tokens:l(o.output_tokens),cache_read_input_tokens:l(o.cache_read_input_tokens)||null,cache_creation_input_tokens:null}}else i=Object.fromEntries(m.map(r=>[r,l(o[r])]));return m.every(r=>!i[r])?null:i}f(E,"normalize");function I(t){return!!t&&typeof t=="object"&&Array.isArray(t.choices)&&t.choices.length===0&&!!t.usage}f(I,"usageChunk");function P(t,o,i){const r=Object.fromEntries(m.map(e=>[e,null]));let a=!1,y=null,d=!1,b=!1,h=!1,p=null,w="openai",j;const g=new Promise(e=>{j=e}),k=f((e,u=t.front)=>{const c=E(u,e);if(c){a=!0;for(const n of m)c[n]!==null&&c[n]!==void 0&&(r[n]=c[n])}},"take"),_=f(e=>{if(d)return;d=!0,p&&k(p(),w);const u=e==="done"&&b?"error":e,c={...r,reported:a,estimated:y,complete:u==="done",reason:u,...t};j(c);try{Promise.resolve(o?.(c)).catch(n=>i(`onUsage rejected: ${n?.message??n}`,{kind:"rejected"}))}catch(n){i(`onUsage threw: ${n?.message??n}`,{kind:"threw"})}},"finish");return{meta:t,usage:g,json(e){h=!0,p||k(e?.usage)},source(e,u="openai"){p=e,w=u},event(e){e==="[DONE]"&&(h=!0),!(!e||typeof e!="object")&&((e.type==="error"||t.front==="openai"&&e.error)&&(b=!0),t.front==="anthropic"?(e.type==="message_stop"&&(h=!0),p||k(e.type==="message_start"?e.message?.usage:e.usage)):p||k(e.usage))},finish:_,estimate(e){y=e},track(e,u,c=!1){const n=e[Symbol.asyncIterator](),x=this;return{[Symbol.asyncIterator](){return this},async next(){try{for(;;){const s=await n.next();if(s.done)_(h?"done":"error");else if(x.event(s.value?.data),c&&I(s.value?.data))continue;return s}}catch(s){throw _(u?.aborted?"aborted":"error"),s}},async return(s){return _("aborted"),n.return?n.return(s):{done:!0,value:s}},async throw(s){if(_("error"),n.throw)return n.throw(s);throw s}}}}}f(P,"meter");export{P as meter,E as normalize};
2
2
  //# sourceMappingURL=usage.mjs.map
package/dist/lib/warn.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var t=Object.defineProperty;var l=(n,r)=>t(n,"name",{value:r,configurable:!0});function d(n,r,a){return n.silent||r.warned.has(a)?!1:(r.warned.add(a),console.warn(`[llm-translator] ${a}`),!0)}l(d,"warn");export{d as warn};
1
+ var o=Object.defineProperty;var e=(n,r)=>o(n,"name",{value:r,configurable:!0});import{emit as a}from"./events.mjs";function w(n,r,t,i={}){a({config:n,state:r},{type:"warning",...i,level:"warn",message:t})}e(w,"warn");export{w as warn};
2
2
  //# sourceMappingURL=warn.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/llm-translator",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Bidirectional Anthropic Messages ⇄ OpenAI Chat Completions translator with backend auto-detection (vLLM and other OpenAI-compatible servers), built on slothlet, with an optional standalone server for running Claude Code against local models.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -18,13 +18,14 @@
18
18
  */
19
19
  /**
20
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.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, headers: Record<string,string>, paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
25
25
  protocol: string;
26
26
  order: number;
27
27
  auth: string;
28
+ strict: boolean;
28
29
  headers: Record<string, string>;
29
30
  paths: Record<string, string>;
30
31
  };
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * Describe the generic OpenAI-compatible driver (matches last, after every specific driver).
3
- * @returns {{name: string, protocol: string, order: number, auth: string, fields: string[], paths: Record<string,string>}} Driver facts.
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields: string[], paths: Record<string,string>}} Driver facts.
4
4
  */
5
5
  export function info(): {
6
6
  name: string;
7
7
  protocol: string;
8
8
  order: number;
9
9
  auth: string;
10
+ strict: boolean;
10
11
  fields: string[];
11
12
  paths: Record<string, string>;
12
13
  };
@@ -18,12 +18,13 @@
18
18
  */
19
19
  /**
20
20
  * Describe the DeepSeek driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
25
25
  protocol: string;
26
26
  order: number;
27
27
  auth: string;
28
+ strict: boolean;
28
29
  paths: Record<string, string>;
29
30
  };
@@ -18,13 +18,14 @@
18
18
  */
19
19
  /**
20
20
  * Describe the llama.cpp driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
25
25
  protocol: string;
26
26
  order: number;
27
27
  auth: string;
28
+ strict: boolean;
28
29
  probes: string[];
29
30
  fields: string[];
30
31
  paths: Record<string, string>;
@@ -18,13 +18,14 @@
18
18
  */
19
19
  /**
20
20
  * Describe the Ollama driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, probes: string[], paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
25
25
  protocol: string;
26
26
  order: number;
27
27
  auth: string;
28
+ strict: boolean;
28
29
  probes: string[];
29
30
  paths: Record<string, string>;
30
31
  };
@@ -18,12 +18,13 @@
18
18
  */
19
19
  /**
20
20
  * Describe the OpenAI driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
25
25
  protocol: string;
26
26
  order: number;
27
27
  auth: string;
28
+ strict: boolean;
28
29
  paths: Record<string, string>;
29
30
  };
@@ -18,13 +18,14 @@
18
18
  */
19
19
  /**
20
20
  * Describe the SGLang driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], fields: string[], paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
25
25
  protocol: string;
26
26
  order: number;
27
27
  auth: string;
28
+ strict: boolean;
28
29
  probes: string[];
29
30
  fields: string[];
30
31
  paths: Record<string, string>;
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * Describe the vLLM driver.
3
- * @returns {{name: string, protocol: string, order: number, auth: string, fields: string[], paths: Record<string,string>}} Driver facts.
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields: string[], paths: Record<string,string>}} Driver facts.
4
4
  */
5
5
  export function info(): {
6
6
  name: string;
7
7
  protocol: string;
8
8
  order: number;
9
9
  auth: string;
10
+ strict: boolean;
10
11
  fields: string[];
11
12
  paths: Record<string, string>;
12
13
  };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Forward `POST /v1/embeddings` to an OpenAI-protocol upstream that lists the model. The body and the reply pass through unchanged
3
+ * apart from `model`, which is the upstream's name for it (after `aliases`). The model is routed like a chat model: aliases, then the
4
+ * pool of endpoints serving it, which fails over on a connection error or a 5xx. Errors are replies in the OpenAI error shape (the
5
+ * return value, not a throw): `400` for a body that is not an object or has no `model`, `404` when no upstream serves the model and `400`
6
+ * (`embeddings_unsupported`) when the model is served only by Anthropic-protocol upstreams, which have no embeddings API, and `499` (`aborted`) when `signal` aborts.
7
+ * @param {any} body - OpenAI embeddings request body (`{ model, input, ... }`).
8
+ * @param {any} [options] - `{ signal, headers, log }`: abort signal for the upstream call, extra upstream headers and the logger events of this request also go to (used by the server).
9
+ * @returns {Promise<{status: number, headers: Record<string,string>, body: any}>} The upstream's JSON reply, or an OpenAI-shaped error reply.
10
+ */
11
+ export function send(body: any, options?: any): Promise<{
12
+ status: number;
13
+ headers: Record<string, string>;
14
+ body: any;
15
+ }>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Remove a listener added with `events.on`. A listener that is not subscribed is ignored.
3
+ * @param {string} name - Event name or `"*"`.
4
+ * @param {Function} fn - The listener passed to `events.on`.
5
+ * @returns {void}
6
+ */
7
+ export function off(name: string, fn: Function): void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Subscribe to an event (see docs/events.md for the catalogue). `"*"` receives every occurrence once. The listener only observes: an
3
+ * exception or a rejection is contained and reported once through logging.
4
+ * @param {string} name - Event name (`log`, `warning`, `error`, `fallback`, `failover`, `effort`, `dropped`, `detect`, `usage`) or `"*"`.
5
+ * @param {(event: import("../../lib/events.mjs").TranslatorEvent) => any} fn - Listener.
6
+ * @returns {() => void} Function that removes the listener.
7
+ */
8
+ export function on(name: string, fn: (event: import("../../lib/events.mjs").TranslatorEvent) => any): () => void;
@@ -2,8 +2,8 @@
2
2
  * Route a client request body (in the configured `front` protocol) to an upstream and convert it to that upstream's
3
3
  * protocol. Does no I/O.
4
4
  * @param {any} body - Client request body (Anthropic Messages or OpenAI Chat Completions, per `front`).
5
- * @param {any} [options] - `{ front, headers, clientHeaders, filter, images, usage }`. `front` overrides the configured front for this call, `headers` are extra upstream headers, `clientHeaders` are client headers forwarded only to a native Anthropic upstream, `filter` restricts a forwarded OpenAI body to known fields (default: the `passthroughFilter` setting, off), `images: false` sends the request without images (used by the image fallback), `endpoint` sends to that member of the model's pool (used for failover; default: the first in the pool's order), `hold: true` (used by `send`) advances a round robin and takes the chosen endpoint's in-flight slot, which the caller then releases, `tools: false` sends the request without tools (used by the tool fallback), `usage: true` (used by `send`) makes a streaming OpenAI-front request always ask the upstream for its final usage chunk, `budget` (from `createBudget`, one per `send` for all its attempts) limits the cost of decoding reasoning signatures.
6
- * @returns {Promise<{upstream: string, method: string, url: string, path: string, headers: Record<string,string>, body: any, state: any, pool: string[], images: {sent: boolean, retry: boolean, key: string}, tools: {sent: boolean, retry: boolean}}>} The upstream request and the state `response`/`stream`/`error` need. `pool` lists the names of the endpoints serving the model in the order they are tried (`upstream` is the first); `images` tells `send` whether the body carries images, whether a refusal may be retried without them and the key under which a refusal is remembered; `tools` tells it whether the body carries tools and whether a tool-parser refusal may be retried without them.
5
+ * @param {any} [options] - `{ front, headers, clientHeaders, filter, images, usage }`. `front` overrides the configured front for this call, `headers` are extra upstream headers, `clientHeaders` are client headers forwarded only to a native Anthropic upstream, `filter` restricts a forwarded OpenAI body to known fields (default: the `passthroughFilter` setting, off), `images: false` sends the request without images (used by the image fallback), `endpoint` sends to that member of the model's pool (used for failover; default: the first in the pool's order), `hold: true` (used by `send`) advances a round robin and takes the chosen endpoint's in-flight slot, which the caller then releases, `jsonObject: "instruction"` sends a `json_object` response format as a system instruction (used by the JSON fallback, and applied by itself once a refusal is remembered for the endpoint and model), `tools: false` sends the request without tools (used by the tool fallback), `usage: true` (used by `send`) makes a streaming OpenAI-front request always ask the upstream for its final usage chunk, `retry: true` (used by `send` for the same request sent again) keeps the `dropped` event from repeating, `log` is the logger events of this request also go to (used by the server), `budget` (from `createBudget`, one per `send` for all its attempts) limits the cost of decoding reasoning signatures.
6
+ * @returns {Promise<{upstream: string, method: string, url: string, path: string, headers: Record<string,string>, body: any, state: any, pool: string[], images: {sent: boolean, retry: boolean, key: string}, tools: {sent: boolean, retry: boolean}, json: {sent: boolean, retry: boolean, key: string}}>} The upstream request and the state `response`/`stream`/`error` need. `pool` lists the names of the endpoints serving the model in the order they are tried (`upstream` is the first); `images` tells `send` whether the body carries images, whether a refusal may be retried without them and the key under which a refusal is remembered; `tools` tells it whether the body carries tools and whether a tool-parser refusal may be retried without them; `json` tells it whether the body carries the schema emulation of `json_object`, whether a refusal may be retried with the instruction and the key under which a refusal is remembered.
7
7
  */
8
8
  export function request(body: any, options?: any): Promise<{
9
9
  upstream: string;
@@ -23,4 +23,9 @@ export function request(body: any, options?: any): Promise<{
23
23
  sent: boolean;
24
24
  retry: boolean;
25
25
  };
26
+ json: {
27
+ sent: boolean;
28
+ retry: boolean;
29
+ key: string;
30
+ };
26
31
  }>;
@@ -18,7 +18,7 @@
18
18
  * On the Anthropic front a stream carries them in the final `message_delta`, because `message_start` is sent before the output is known.
19
19
  * Replies passed through without conversion are never altered.
20
20
  * @param {any} body - Client request body (per `front`).
21
- * @param {any} [options] - `{ signal, front, headers, clientHeaders, filter, onUsage }`: abort signal for the upstream call, per-call front, extra upstream headers, client headers forwarded to a native Anthropic upstream, the pass-through body filter (see `request`) and the usage callback (an exception in it is reported as a warning and never breaks the reply).
21
+ * @param {any} [options] - `{ signal, front, headers, clientHeaders, filter, onUsage, log }`: abort signal for the upstream call, per-call front, extra upstream headers, client headers forwarded to a native Anthropic upstream, the pass-through body filter (see `request`) and the usage callback (an exception in it is reported as a `usage` event and never breaks the reply) and the logger this request's events also go to (used by the server).
22
22
  * @returns {Promise<{status: number, headers: Record<string,string>, body: any, usage: Promise<any>} | {status: number, headers: Record<string,string>, stream: AsyncIterable<{event?: string, data: *}>, usage: Promise<any>}>} A JSON reply, or a stream reply when the client asked for streaming and the upstream accepted.
23
23
  */
24
24
  export function send(body: any, options?: any): Promise<{
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Fastify plugin. Anthropic front: `POST /v1/messages`, `POST /v1/messages/count_tokens`, `GET /v1/models`, `GET /v1/models/{id}`,
3
- * `GET|HEAD /` and `/api/hello`. OpenAI front: `POST /v1/chat/completions`, `GET /v1/models`, `GET /v1/models/{id}`, `GET|HEAD /`. Responses stream as
3
+ * `GET|HEAD /` and `/api/hello`. OpenAI front: `POST /v1/chat/completions`, `POST /v1/embeddings`, `GET /v1/models`, `GET /v1/models/{id}`, `GET|HEAD /`. Responses stream as
4
4
  * `text/event-stream` with keep-alive pings; a client disconnect aborts the upstream request. Register it with
5
5
  * `app.register(api.server.plugin, { apiKey })`. `authorize(request)` (sync or async) runs after `apiKey` and the body parse and decides
6
- * with `true` / `{ ok: true, context }` or `false` / `{ ok: false, status, message }`; `onUsage(report, context)` receives each request's usage report.
6
+ * with `true` / `{ ok: true, context }` or `false` / `{ ok: false, status, message }`; `onUsage(report, context)` receives each request's usage report. When the Fastify `logger` is enabled, events also go to it as structured lines (`{ event }` plus the message), through the request's logger for events of a request.
7
7
  * @param {any} fastify - Fastify instance.
8
8
  * @param {any} [options] - `{ front, apiKey, bodyLimit, authorize, onUsage }`. `authorize(request)` and `onUsage(report, context)` are described above. `front` sets the protocol this plugin instance serves (default: the translator's front, other plugin instances and `api.send` are unaffected); `apiKey` (string or array) is required from clients. Forwarded OpenAI bodies are restricted to known fields unless the `passthroughFilter` setting is `false`.
9
9
  * @returns {Promise<void>} Resolves once the routes are registered.
@@ -9,14 +9,18 @@
9
9
  * @property {boolean} [detect] Probe `auto` upstreams at startup (default true).
10
10
  * @property {number} [detectTimeout] Probe timeout in ms (default 5000).
11
11
  * @property {(url: string, init?: any) => Promise<Response>} [transport] fetch-compatible function used for all upstream calls.
12
- * @property {boolean} [silent] Suppress warnings.
12
+ * @property {boolean | string} [logs] Logging (default `false`: no console output, no file). `true` prints warnings and errors on the console, once per message; a path appends every event as a JSON line to that file (relative paths resolve against `process.cwd()`, a missing directory is created, a file that cannot be opened is reported once on the console and logging stays off).
13
+ * @property {false | string | ((record: object) => any)} [capture] Request and response capture for debugging (default `false`: off). A directory path writes one JSON file per exchange (`<ms>-<id>.json`, the directory is created); a function is called with each record. A record is `{ time, id, front, requested, model, endpoint, stream, client: { body }, upstream: { url, headers, body }, response }`; credential headers (names containing key, token, secret, auth, cookie or password) are replaced by `[redacted]`. A failing sink is reported once as a warning and never affects the reply (see docs/events.md).
14
+ * @property {boolean} [events] Emit events (default `true`); `false` turns emitting off. Logging does not depend on it.
15
+ * @property {(event: import("./lib/events.mjs").TranslatorEvent) => any} [onEvent] Callback for every event, registered before startup so it also sees startup events (see docs/events.md).
16
+ * @property {boolean} [silent] Deprecated alias for `logs: false` (the default); `logs` wins when both are given.
13
17
  * @property {{import?: (url: string) => Promise<any>}} [slothlet] Options forwarded to slothlet (for example `import` for coverage).
14
18
  */
15
19
  /**
16
20
  * Create a translator: a slothlet api instance (see the README for the leaves) bound to the given upstreams.
17
21
  * Endpoints with `backend: "auto"` are probed once before this resolves (set `detect: false` to skip all network access).
18
22
  * @param {TranslatorConfig} config - Translator config.
19
- * @returns {Promise<any>} The translator api (`request`, `response`, `stream`, `send`, `detect`, `status`, `token`, `model`, `error`, `sse`, `server`, `driver`, `convert`, `slothlet`).
23
+ * @returns {Promise<any>} The translator api (`request`, `response`, `stream`, `send`, `detect`, `status`, `token`, `model`, `error`, `events`, `sse`, `server`, `driver`, `convert`, `slothlet`).
20
24
  */
21
25
  export function createTranslator(config: TranslatorConfig): Promise<any>;
22
26
  export { TranslatorError } from "./lib/errors.mjs";
@@ -66,7 +70,23 @@ export type TranslatorConfig = {
66
70
  */
67
71
  transport?: (url: string, init?: any) => Promise<Response>;
68
72
  /**
69
- * Suppress warnings.
73
+ * Logging (default `false`: no console output, no file). `true` prints warnings and errors on the console, once per message; a path appends every event as a JSON line to that file (relative paths resolve against `process.cwd()`, a missing directory is created, a file that cannot be opened is reported once on the console and logging stays off).
74
+ */
75
+ logs?: boolean | string;
76
+ /**
77
+ * Request and response capture for debugging (default `false`: off). A directory path writes one JSON file per exchange (`<ms>-<id>.json`, the directory is created); a function is called with each record. A record is `{ time, id, front, requested, model, endpoint, stream, client: { body }, upstream: { url, headers, body }, response }`; credential headers (names containing key, token, secret, auth, cookie or password) are replaced by `[redacted]`. A failing sink is reported once as a warning and never affects the reply (see docs/events.md).
78
+ */
79
+ capture?: false | string | ((record: object) => any);
80
+ /**
81
+ * Emit events (default `true`); `false` turns emitting off. Logging does not depend on it.
82
+ */
83
+ events?: boolean;
84
+ /**
85
+ * Callback for every event, registered before startup so it also sees startup events (see docs/events.md).
86
+ */
87
+ onEvent?: (event: import("./lib/events.mjs").TranslatorEvent) => any;
88
+ /**
89
+ * Deprecated alias for `logs: false` (the default); `logs` wins when both are given.
70
90
  */
71
91
  silent?: boolean;
72
92
  /**
@@ -48,9 +48,13 @@ export function pinBody(body: any, pin: {
48
48
  * @param {any} body - Upstream body (mutated).
49
49
  * @param {EffortConfig} entry - Model's effort config.
50
50
  * @param {string} model - Model name, for the message.
51
- * @param {(message: string) => void} warn - Warning sink.
51
+ * @param {(message: string, details: {requested: string, used: string, levels: string[]}) => void} warn - Receives the message and the snapped levels.
52
52
  */
53
- export function fit(body: any, entry: EffortConfig, model: string, warn: (message: string) => void): void;
53
+ export function fit(body: any, entry: EffortConfig, model: string, warn: (message: string, details: {
54
+ requested: string;
55
+ used: string;
56
+ levels: string[];
57
+ }) => void): void;
54
58
  /** The effort levels a model can be configured with, lowest to highest. `none` is not one: it switches reasoning off and is never snapped. */
55
59
  export const LEVELS: readonly string[];
56
60
  export type EffortConfig = {
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @typedef {object} TranslatorEvent
3
+ * @property {string} type Specific event name (`fallback`, `failover`, `effort`, `dropped`, `detect`, `usage`, `warning`, `error` or `log`).
4
+ * @property {string} [kind] Sub-kind within the type (for example `json_object` for a `fallback`).
5
+ * @property {"debug" | "info" | "warn" | "error"} level Severity.
6
+ * @property {string} message Human readable text.
7
+ * @property {number} time Milliseconds since the epoch.
8
+ */
9
+ /**
10
+ * The state the emitter keeps in `state`: listeners by event name, the log sink, and the server's logger once one is registered.
11
+ * @param {((event: TranslatorEvent) => any) | undefined} [onEvent] - Config callback, registered for every event.
12
+ * @returns {{listeners: Map<string, Set<Function>>, sink: {console: boolean, file: string | null}, logger: any}} Emitter state.
13
+ */
14
+ export function create(onEvent?: ((event: TranslatorEvent) => any) | undefined): {
15
+ listeners: Map<string, Set<Function>>;
16
+ sink: {
17
+ console: boolean;
18
+ file: string | null;
19
+ };
20
+ logger: any;
21
+ };
22
+ /**
23
+ * Configure where logging goes: nothing, the console, or a JSON lines file. A file that cannot be opened is reported once on
24
+ * the console and logging stays off; this never throws.
25
+ * @param {any} emitter - Emitter state from {@link create}.
26
+ * @param {boolean | string} logs - Normalized `logs` option.
27
+ * @returns {void}
28
+ */
29
+ export function open(emitter: any, logs: boolean | string): void;
30
+ /**
31
+ * Subscribe to an event.
32
+ * @param {any} emitter - Emitter state.
33
+ * @param {string} name - Event name, or `"*"` for every event.
34
+ * @param {(event: TranslatorEvent) => any} fn - Listener.
35
+ * @returns {() => void} Unsubscribe function.
36
+ */
37
+ export function on(emitter: any, name: string, fn: (event: TranslatorEvent) => any): () => void;
38
+ /**
39
+ * Remove a listener (a listener that is not subscribed is ignored).
40
+ * @param {any} emitter - Emitter state.
41
+ * @param {string} name - Event name.
42
+ * @param {Function} fn - Listener passed to {@link on}.
43
+ * @returns {void}
44
+ */
45
+ export function off(emitter: any, name: string, fn: Function): void;
46
+ /**
47
+ * Emit one occurrence. The specific event fires first, then the general ones that fit (`warning` for level `warn`, `error` for level
48
+ * `error`, always `log`), then `"*"`; all with the same payload. Listeners only observe. Logging is fed from here too, and does not
49
+ * depend on `events`.
50
+ * @param {{config: any, state: any}} ctx - Translator `{ config, state }`.
51
+ * @param {{type: string, kind?: string, level?: "debug" | "info" | "warn" | "error", message: string, log?: any, [detail: string]: any}} spec - What happened: `type`, optional `kind`, `level` (default `info`), `message`, further details, and `log` (see {@link write}; not part of the payload).
52
+ * @returns {TranslatorEvent} The payload.
53
+ */
54
+ export function emit({ config, state }: {
55
+ config: any;
56
+ state: any;
57
+ }, spec: {
58
+ type: string;
59
+ kind?: string;
60
+ level?: "debug" | "info" | "warn" | "error";
61
+ message: string;
62
+ log?: any;
63
+ [detail: string]: any;
64
+ }): TranslatorEvent;
65
+ export type TranslatorEvent = {
66
+ /**
67
+ * Specific event name (`fallback`, `failover`, `effort`, `dropped`, `detect`, `usage`, `warning`, `error` or `log`).
68
+ */
69
+ type: string;
70
+ /**
71
+ * Sub-kind within the type (for example `json_object` for a `fallback`).
72
+ */
73
+ kind?: string;
74
+ /**
75
+ * Severity.
76
+ */
77
+ level: "debug" | "info" | "warn" | "error";
78
+ /**
79
+ * Human readable text.
80
+ */
81
+ message: string;
82
+ /**
83
+ * Milliseconds since the epoch.
84
+ */
85
+ time: number;
86
+ };
@@ -14,16 +14,23 @@ export function finishError(finishReason: string | null | undefined): {
14
14
  * Anthropic stop reason (and stop sequence) for an OpenAI choice.
15
15
  * `model_length` is `max_tokens`; `eos`, `eos_token` and any other unknown value are `end_turn`. Fatal values are handled by {@link finishError} before this.
16
16
  * @param {string|null|undefined} finishReason - OpenAI `finish_reason`.
17
- * @param {{ hasToolCalls: boolean, matchedStop?: unknown, argumentsComplete?: boolean }} info - Whether tool calls were produced, vLLM's `stop_reason` (a string for a matched stop string), and whether the last tool call's arguments are complete. A `length` stop with incomplete arguments is `max_tokens`, not `tool_use`.
18
- * @returns {{ stop_reason: string, stop_sequence: string|null }} Anthropic stop fields.
17
+ * A `content_filter` stop also carries `stop_details` (`{ type: "refusal", category: null, explanation }`), the explanation being the upstream's refusal text when it sent one. No other stop reason has the field.
18
+ * @param {{ hasToolCalls: boolean, matchedStop?: unknown, argumentsComplete?: boolean, refusal?: unknown }} info - Whether tool calls were produced, vLLM's `stop_reason` (a string for a matched stop string), whether the last tool call's arguments are complete, and the upstream's refusal text. A `length` stop with incomplete arguments is `max_tokens`, not `tool_use`.
19
+ * @returns {{ stop_reason: string, stop_sequence: string|null, stop_details?: { type: string, category: string|null, explanation: string|null } }} Anthropic stop fields.
19
20
  */
20
- export function toAnthropicStop(finishReason: string | null | undefined, { hasToolCalls, matchedStop, argumentsComplete }: {
21
+ export function toAnthropicStop(finishReason: string | null | undefined, { hasToolCalls, matchedStop, argumentsComplete, refusal }: {
21
22
  hasToolCalls: boolean;
22
23
  matchedStop?: unknown;
23
24
  argumentsComplete?: boolean;
25
+ refusal?: unknown;
24
26
  }): {
25
27
  stop_reason: string;
26
28
  stop_sequence: string | null;
29
+ stop_details?: {
30
+ type: string;
31
+ category: string | null;
32
+ explanation: string | null;
33
+ };
27
34
  };
28
35
  /**
29
36
  * OpenAI `finish_reason` for an Anthropic stop reason.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copy a header map with the value of every credential header replaced. A header is a credential when its name contains `key`,
3
+ * `token`, `secret`, `auth`, `cookie` or `password` (this covers `authorization`, `proxy-authorization`, `x-api-key`, `api-key`).
4
+ * @param {Record<string, any> | undefined} headers - Header map.
5
+ * @returns {Record<string, any>} Copy with lowercase names.
6
+ */
7
+ export function redact(headers: Record<string, any> | undefined): Record<string, any>;
8
+ /**
9
+ * Validate the `capture` option.
10
+ * @param {any} value - Raw option.
11
+ * @returns {boolean} True when the value is `false`/`undefined`, a non-empty directory path or a function.
12
+ */
13
+ export function valid(value: any): boolean;
14
+ /**
15
+ * Begin the record of one exchange. With `capture` unset this returns a stand-in that does nothing.
16
+ * @param {{config: any, state: any}} ctx - Translator `{ config, state }`.
17
+ * @param {{body: any, sent: any, front: string, requested: string | null, headers?: Record<string, string>, log?: any}} exchange - Client body, the upstream request (result of `request`), front and the logger of the request.
18
+ * @returns {{raw: (source: any) => any, events: (source: any) => any, reply: (status: number, headers: Record<string, string>, body: any) => void}} Recorder: `raw` taps the upstream stream bytes, `events` taps the client events and writes the record when the stream ends, `reply` writes the record of a non-stream reply.
19
+ */
20
+ export function start({ config, state }: {
21
+ config: any;
22
+ state: any;
23
+ }, exchange: {
24
+ body: any;
25
+ sent: any;
26
+ front: string;
27
+ requested: string | null;
28
+ headers?: Record<string, string>;
29
+ log?: any;
30
+ }): {
31
+ raw: (source: any) => any;
32
+ events: (source: any) => any;
33
+ reply: (status: number, headers: Record<string, string>, body: any) => void;
34
+ };
35
+ /** Most characters of a stream kept per exchange, for the raw upstream text and for the client events each. */
36
+ export const STREAM_LIMIT: 1000000;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Sampling fields to add to an OpenAI-protocol request: the `sampling` setting for the upstream, overridden by `metadata.sampling` of an
3
+ * Anthropic request. Fields the body already carries are kept. A field the upstream's driver does not accept follows `unknownFields`:
4
+ * dropped (listed in `dropped`) or rejected. Names are the canonical vLLM ones; a driver such as llama.cpp renames them in its `request`.
5
+ * @param {any} body - Converted or forwarded Chat Completions body.
6
+ * @param {any} extras - `metadata.sampling` of the client request (ignored unless a plain object).
7
+ * @param {any} settings - Resolved settings (`sampling`, `unknownFields`).
8
+ * @param {string[]} [fields] - Extension fields the upstream's driver accepts.
9
+ * @param {string[]} [dropped] - Receives the names that were left out.
10
+ * @returns {any} The body, with the fields added (a copy when anything was added).
11
+ * @throws {TranslatorError} When a field is not accepted and `unknownFields` is `"error"`.
12
+ */
13
+ export function addSampling(body: any, extras: any, settings: any, fields?: string[], dropped?: string[]): any;
@@ -26,6 +26,8 @@ export function resolve(...layers: (Partial<Settings> | null | undefined)[]): Se
26
26
  * @property {"pass"|"sanitize"} toolSchema - Sanitize tool JSON Schemas (drop `$schema`, remove unbounded integer limits).
27
27
  * @property {"forward"|"drop"} deferredTools - Offer `defer_loading` tools as `toolSearch` says, or drop them (and the search tool).
28
28
  * @property {"expand"|"inline"|"native"} toolSearch - Claude Code's tool search. `expand` offers a deferred tool once a `tool_reference` (or a `ToolSearch` result) loads it; `inline` offers every deferred tool up front and hides `ToolSearch` (it stays when `DeferredToolPlaceholder` shows Claude Code holds tools whose definitions it did not send; `expand` does the same when the request has no `ToolSearch` at all); `native` passes `defer_loading` and `tool_reference` through to a server that understands them.
29
+ * @property {"schema"|"instruction"|"drop"} jsonObject - OpenAI to Anthropic: how `response_format: json_object` is sent. `schema` sends `output_config.format` with the permissive schema `{ "type": "object" }`, `instruction` appends a short system instruction asking for one JSON object, `drop` omits it and records the drop.
30
+ * @property {boolean} jsonObjectFallback - Retry a request once with `jsonObject: "instruction"` when an Anthropic-protocol upstream answers 400 or 422 to the schema `jsonObject: "schema"` sent. The endpoint and model are remembered until the process ends only when the retry succeeds.
29
31
  * @property {boolean} toolErrors - Prefix `is_error` tool results with `toolErrorMarker`. Off by default for every driver.
30
32
  * @property {string} toolErrorMarker - Text that marks a failed tool result when `toolErrors` is on, and the text `toolErrorInference` looks for. Must contain a non-whitespace character.
31
33
  * @property {boolean} toolErrorInference - OpenAI to Anthropic: a `tool` message whose text starts with `toolErrorMarker` becomes a `tool_result` with `is_error: true`, with the marker removed from the text.
@@ -37,6 +39,7 @@ export function resolve(...layers: (Partial<Settings> | null | undefined)[]): Se
37
39
  * @property {boolean} responseFormat - Map `output_config.format` to `response_format`.
38
40
  * @property {boolean} parallelToolCalls - Map `disable_parallel_tool_use` to `parallel_tool_calls: false`.
39
41
  * @property {"drop"|"error"} unknownFields - Unknown request fields are dropped (and listed in `state.dropped`) or rejected.
42
+ * @property {Record<string, any>} sampling - Sampling extension fields (`min_p`, `repetition_penalty`, `seed`, ...) added to requests for an OpenAI-protocol upstream when the request does not carry them, merged key by key. A request may set them itself (OpenAI front, or `metadata.sampling` on the Anthropic front). A field the upstream's driver does not accept follows `unknownFields`.
40
43
  * @property {number} pingInterval - Milliseconds of upstream silence before the SSE writer emits a `ping` (0 disables).
41
44
  * @property {"buffer"|"stream"} toolStreaming - OpenAI to Anthropic streams: `buffer` holds each tool call until its arguments are complete and emits one whole `tool_use` block (text and thinking keep streaming and appear before the block); `stream` forwards argument fragments incrementally and holds text that arrives meanwhile until the tool blocks are done.
42
45
  * @property {boolean} effortPassthrough - vLLM driver: send `xhigh` and `max` reasoning effort unchanged instead of clamping them to `high`.
@@ -128,6 +131,14 @@ export type Settings = {
128
131
  * - Claude Code's tool search. `expand` offers a deferred tool once a `tool_reference` (or a `ToolSearch` result) loads it; `inline` offers every deferred tool up front and hides `ToolSearch` (it stays when `DeferredToolPlaceholder` shows Claude Code holds tools whose definitions it did not send; `expand` does the same when the request has no `ToolSearch` at all); `native` passes `defer_loading` and `tool_reference` through to a server that understands them.
129
132
  */
130
133
  toolSearch: "expand" | "inline" | "native";
134
+ /**
135
+ * - OpenAI to Anthropic: how `response_format: json_object` is sent. `schema` sends `output_config.format` with the permissive schema `{ "type": "object" }`, `instruction` appends a short system instruction asking for one JSON object, `drop` omits it and records the drop.
136
+ */
137
+ jsonObject: "schema" | "instruction" | "drop";
138
+ /**
139
+ * - Retry a request once with `jsonObject: "instruction"` when an Anthropic-protocol upstream answers 400 or 422 to the schema `jsonObject: "schema"` sent. The endpoint and model are remembered until the process ends only when the retry succeeds.
140
+ */
141
+ jsonObjectFallback: boolean;
131
142
  /**
132
143
  * - Prefix `is_error` tool results with `toolErrorMarker`. Off by default for every driver.
133
144
  */
@@ -172,6 +183,10 @@ export type Settings = {
172
183
  * - Unknown request fields are dropped (and listed in `state.dropped`) or rejected.
173
184
  */
174
185
  unknownFields: "drop" | "error";
186
+ /**
187
+ * - Sampling extension fields (`min_p`, `repetition_penalty`, `seed`, ...) added to requests for an OpenAI-protocol upstream when the request does not carry them, merged key by key. A request may set them itself (OpenAI front, or `metadata.sampling` on the Anthropic front). A field the upstream's driver does not accept follows `unknownFields`.
188
+ */
189
+ sampling: Record<string, any>;
175
190
  /**
176
191
  * - Milliseconds of upstream silence before the SSE writer emits a `ping` (0 disables).
177
192
  */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Walk a schema and list what falls outside the strict subset: an object schema must say `additionalProperties: false` and list every
3
+ * property in `required`, and the keywords in `UNSUPPORTED` are not allowed anywhere.
4
+ * @param {any} schema - A tool's JSON Schema.
5
+ * @param {string} [at] - Path of `schema` within the tool's schema.
6
+ * @param {string[]} [out] - Problems found so far.
7
+ * @returns {string[]} One line per problem, each starting with its path (`$` is the schema's root).
8
+ */
9
+ export function problems(schema: any, at?: string, out?: string[]): string[];
10
+ /**
11
+ * The tools of an upstream body that ask for strict use, with the problems of their schemas. Reads both wire shapes: Chat Completions
12
+ * (`function.strict`, `function.parameters`) and Anthropic Messages (`strict`, `input_schema`).
13
+ * @param {any} body - Upstream request body.
14
+ * @returns {{name: string, problems: string[]}[]} Strict tools in request order.
15
+ */
16
+ export function strictTools(body: any): {
17
+ name: string;
18
+ problems: string[];
19
+ }[];
20
+ /**
21
+ * Send the tools whose schema is outside the strict subset without `strict` (the key is removed, not set to false). Reads both wire shapes
22
+ * like `strictTools`. Nothing in `body` is modified: tools that change are rebuilt, and the body is copied only when one did.
23
+ * @param {any} body - Upstream request body.
24
+ * @returns {any} `body` itself when every strict tool conforms, otherwise a copy with the rebuilt `tools`.
25
+ */
26
+ export function relax(body: any): any;
@@ -10,7 +10,7 @@ export function normalize(protocol: "anthropic" | "openai" | "folded", usage: an
10
10
  * Create the meter for one request.
11
11
  * @param {{front: "anthropic" | "openai", requested: string | null, model: string | null, upstream: string | null, stream: boolean}} meta - Request facts; `model` and `upstream` may be filled in later.
12
12
  * @param {((report: UsageReport) => any) | undefined} onUsage - Caller's callback.
13
- * @param {(message: string) => void} warn - Receives a message when `onUsage` throws or rejects.
13
+ * @param {(message: string, details: {kind: "threw" | "rejected"}) => void} warn - Receives a message when `onUsage` throws or rejects.
14
14
  * @returns {{meta: any, usage: Promise<UsageReport>, json: (body: any) => void, event: (data: any) => void, finish: (reason: UsageReport["reason"]) => void, estimate: (counts: {input_tokens: number | null, output_tokens: number | null}) => void, source: (read: (() => any) | null, protocol?: "openai" | "folded") => void, track: (source: AsyncIterable<any>, signal?: AbortSignal, hide?: boolean) => any}} Meter.
15
15
  */
16
16
  export function meter(meta: {
@@ -19,7 +19,9 @@ export function meter(meta: {
19
19
  model: string | null;
20
20
  upstream: string | null;
21
21
  stream: boolean;
22
- }, onUsage: ((report: UsageReport) => any) | undefined, warn: (message: string) => void): {
22
+ }, onUsage: ((report: UsageReport) => any) | undefined, warn: (message: string, details: {
23
+ kind: "threw" | "rejected";
24
+ }) => void): {
23
25
  meta: any;
24
26
  usage: Promise<UsageReport>;
25
27
  json: (body: any) => void;