@cldmv/llm-translator 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -9
- package/dist/api/convert/anthropic/messages/to/openai/responses/request.mjs +2 -0
- package/dist/api/convert/openai/chat/to/openai/responses/request.mjs +2 -0
- package/dist/api/convert/openai/chat/to/openai/responses/response.mjs +2 -0
- package/dist/api/convert/openai/chat/to/openai/responses/stream.mjs +2 -0
- package/dist/api/convert/openai/responses/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/openai/responses/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/convert/openai/responses/to/openai/chat/request.mjs +6 -0
- package/dist/api/convert/openai/responses/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/openai/responses/to/openai/chat/stream.mjs +2 -0
- package/dist/api/detect.mjs +1 -1
- package/dist/api/driver/anthropic/info.mjs +1 -1
- package/dist/api/driver/azure/info.mjs +1 -1
- package/dist/api/driver/compatible/info.mjs +1 -1
- package/dist/api/driver/deepseek/info.mjs +1 -1
- package/dist/api/driver/llamacpp/info.mjs +1 -1
- package/dist/api/driver/lmstudio/info.mjs +1 -1
- package/dist/api/driver/localai/info.mjs +1 -1
- package/dist/api/driver/mistral/info.mjs +1 -1
- package/dist/api/driver/ollama/info.mjs +1 -1
- package/dist/api/driver/ollama/request.mjs +1 -1
- package/dist/api/driver/openai/info.mjs +1 -1
- package/dist/api/driver/openrouter/info.mjs +1 -1
- package/dist/api/driver/sglang/info.mjs +1 -1
- package/dist/api/driver/tgi/info.mjs +1 -1
- package/dist/api/driver/vllm/info.mjs +1 -1
- package/dist/api/request.mjs +2 -2
- package/dist/api/response.mjs +1 -1
- package/dist/api/route.mjs +1 -1
- package/dist/api/send.mjs +1 -1
- package/dist/api/server/plugin.mjs +1 -1
- package/dist/api/server/start.mjs +1 -1
- package/dist/api/status.mjs +1 -1
- package/dist/api/stream.mjs +1 -1
- package/dist/api/token/count.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/cli.mjs +16 -7
- package/dist/lib/config.mjs +1 -1
- package/dist/lib/estimate.mjs +1 -1
- package/dist/lib/guard.mjs +2 -0
- package/dist/lib/http.mjs +1 -1
- package/dist/lib/metrics.mjs +4 -0
- package/dist/lib/presets.mjs +1 -1
- package/dist/lib/protocol.mjs +2 -0
- package/dist/lib/responses-upstream.mjs +13 -0
- package/dist/lib/responses.mjs +2 -0
- package/dist/lib/route.mjs +1 -1
- package/dist/lib/routes.mjs +1 -1
- package/dist/lib/settings.mjs +1 -1
- package/dist/lib/vllm.mjs +2 -2
- package/package.json +1 -1
- package/types/src/api/convert/anthropic/messages/to/openai/responses/request.d.mts +16 -0
- package/types/src/api/convert/openai/chat/to/openai/responses/request.d.mts +12 -0
- package/types/src/api/convert/openai/chat/to/openai/responses/response.d.mts +14 -0
- package/types/src/api/convert/openai/chat/to/openai/responses/stream.d.mts +18 -0
- package/types/src/api/convert/openai/responses/to/anthropic/messages/response.d.mts +8 -0
- package/types/src/api/convert/openai/responses/to/anthropic/messages/stream.d.mts +8 -0
- package/types/src/api/convert/openai/responses/to/openai/chat/request.d.mts +17 -0
- package/types/src/api/convert/openai/responses/to/openai/chat/response.d.mts +8 -0
- package/types/src/api/convert/openai/responses/to/openai/chat/stream.d.mts +10 -0
- package/types/src/api/driver/anthropic/info.d.mts +2 -1
- package/types/src/api/driver/azure/info.d.mts +2 -1
- package/types/src/api/driver/compatible/info.d.mts +2 -1
- package/types/src/api/driver/deepseek/info.d.mts +2 -1
- package/types/src/api/driver/fireworks/info.d.mts +2 -1
- package/types/src/api/driver/gemini/info.d.mts +2 -1
- package/types/src/api/driver/groq/info.d.mts +2 -1
- package/types/src/api/driver/llamacpp/info.d.mts +2 -1
- package/types/src/api/driver/lmstudio/info.d.mts +2 -1
- package/types/src/api/driver/localai/info.d.mts +2 -1
- package/types/src/api/driver/mistral/info.d.mts +2 -1
- package/types/src/api/driver/ollama/info.d.mts +2 -1
- package/types/src/api/driver/ollama/request.d.mts +1 -1
- package/types/src/api/driver/openai/info.d.mts +2 -1
- package/types/src/api/driver/openrouter/info.d.mts +2 -1
- package/types/src/api/driver/sglang/info.d.mts +2 -1
- package/types/src/api/driver/tgi/info.d.mts +2 -1
- package/types/src/api/driver/together/info.d.mts +2 -1
- package/types/src/api/driver/vllm/info.d.mts +2 -1
- package/types/src/api/driver/xai/info.d.mts +2 -1
- package/types/src/api/request.d.mts +3 -2
- package/types/src/api/route.d.mts +2 -2
- package/types/src/api/send.d.mts +1 -1
- package/types/src/api/server/plugin.d.mts +2 -2
- package/types/src/api/server/start.d.mts +1 -1
- package/types/src/api/status.d.mts +1 -1
- package/types/src/lib/config.d.mts +4 -3
- package/types/src/lib/estimate.d.mts +1 -1
- package/types/src/lib/guard.d.mts +25 -0
- package/types/src/lib/http.d.mts +4 -3
- package/types/src/lib/metrics.d.mts +58 -0
- package/types/src/lib/presets.d.mts +2 -1
- package/types/src/lib/protocol.d.mts +84 -0
- package/types/src/lib/responses-upstream.d.mts +58 -0
- package/types/src/lib/responses.d.mts +72 -0
- package/types/src/lib/route.d.mts +7 -3
- package/types/src/lib/routes.d.mts +3 -2
- package/types/src/lib/settings.d.mts +11 -6
- package/types/src/lib/vllm.d.mts +4 -4
package/README.md
CHANGED
|
@@ -17,19 +17,18 @@ Use it as a library when you want the conversion without any I/O (`request`, `re
|
|
|
17
17
|
|
|
18
18
|
## ✨ What's New
|
|
19
19
|
|
|
20
|
-
### Latest: v0.
|
|
20
|
+
### Latest: v0.13.0 (November 2026)
|
|
21
21
|
|
|
22
|
-
- **
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
- [View full v0.11.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.11.0.md)
|
|
22
|
+
- **OpenAI Responses API, both ways** — clients such as Codex CLI can call `/v1/responses` (stateless), and an upstream can be reached over its own Responses API, with encrypted reasoning carried between turns and a fall back to Chat Completions when the server has no `/v1/responses`.
|
|
23
|
+
- **One `api` setting, `auto` by default** — each upstream picks its protocol with `api` (`messages`/`claude`, `chat`/`chatgpt`, `responses`/`codex`, `native`/`ollama` or `auto`). Under `auto` a request uses the client's own protocol when the server speaks it, so Claude Code → vLLM 0.11.1+ now goes to `/v1/messages` with no setting. Set `api: "chat"` to keep the old Chat Completions default; `nativeMessages` is deprecated.
|
|
24
|
+
- [View full v0.13.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.13.0.md)
|
|
26
25
|
|
|
27
26
|
### Recent Releases
|
|
28
27
|
|
|
28
|
+
- **v0.12.0** (November 2026) — Prometheus `/metrics`, HTTPS, per-key rate limits and CORS for the built-in server, and failed tool results marked by default over Chat Completions ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.12.0.md))
|
|
29
|
+
- **v0.11.0** (November 2026) — native constrained decoding (JSON Schema, regex, choice, grammar), `clear_tool_uses` context edits, `cache_salt` and `prompt_cache_key` hints, and host-first binding for hosted APIs ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.11.0.md))
|
|
29
30
|
- **v0.10.0** (November 2026) — native `/v1/messages` for vLLM, readiness probes and LoRA adapters, Groq, Together, Fireworks, xAI and Gemini drivers, and Ollama's native `/api/chat` ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.10.0.md))
|
|
30
31
|
- **v0.9.0** (November 2026) — Azure OpenAI, OpenRouter, Hugging Face TGI and LocalAI drivers, with Azure's `apiVersion` and `deployment` upstream fields and more startup probes ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.9.0.md))
|
|
31
|
-
- **v0.8.0** (November 2026) — Mistral and LM Studio drivers, an OpenAI client's `n` above 1 answered by parallel requests to Anthropic-protocol upstreams, and `stop_details.category` from content-filter results ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.8.0.md))
|
|
32
|
-
- **v0.7.0** (November 2026) — Anthropic-protocol servers detected by probe on any host, tool-call ids rewritten for strict upstream formats, embeddings usage through `onUsage`, and capture records for every failed-over attempt ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.7.0.md))
|
|
33
32
|
|
|
34
33
|
📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/llm-translator/tree/master/docs/changelog/) folder.**
|
|
35
34
|
|
|
@@ -89,7 +88,7 @@ import { createTranslator } from "@cldmv/llm-translator";
|
|
|
89
88
|
|
|
90
89
|
const api = await createTranslator({
|
|
91
90
|
front: "anthropic", // the protocol your client speaks
|
|
92
|
-
upstreams: ["http://gpu-box:8000"], // vLLM is detected automatically
|
|
91
|
+
upstreams: ["http://gpu-box:8000"], // vLLM is detected automatically; api defaults to "auto"
|
|
93
92
|
aliases: { "claude-opus-5-5": "qwen3-coder" }
|
|
94
93
|
});
|
|
95
94
|
|
|
@@ -128,7 +127,7 @@ Then point Claude Code at it with `ANTHROPIC_BASE_URL=http://127.0.0.1:8787`. Th
|
|
|
128
127
|
|
|
129
128
|
## 📚 Configuration
|
|
130
129
|
|
|
131
|
-
`createTranslator(config)` takes `front`, `upstreams` (URLs or objects with `url`, `apiKey`, `backend`, `models`, `default` and `settings`, plus `apiVersion` and `deployment` for Azure OpenAI, see [docs/drivers.md](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md#azure-openai), and `api: "native"`
|
|
130
|
+
`createTranslator(config)` takes `front`, `upstreams` (URLs or objects with `url`, `apiKey`, `backend`, `models`, `default` and `settings`, plus `apiVersion` and `deployment` for Azure OpenAI, see [docs/drivers.md](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md#azure-openai), and `api`, the protocol to speak to the server: `"auto"` (the default) uses the client's own protocol when the server has it, so an Anthropic client reaches vLLM 0.11.1 and later over `/v1/messages` and a Responses client reaches a server's `/v1/responses`, with a fall back to Chat Completions; `"chat"`, `"messages"`, `"responses"` and `"native"` (Ollama's own `/api/chat`) pick one explicitly, see [docs/drivers.md](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md#choosing-the-protocol-api). The old default was Chat Completions: set `api: "chat"` to keep it), `aliases` (a model name, or `{ model, effort, thinking }` to pin settings), `efforts` (the reasoning levels each model supports, see [docs/settings.md](https://github.com/CLDMV/llm-translator/blob/master/docs/settings.md#effort-levels-and-pinned-aliases-not-converter-settings)), global `settings`, `pool` (failover and load balancing between upstreams that serve the same model, see [docs/server.md](https://github.com/CLDMV/llm-translator/blob/master/docs/server.md#endpoint-pools-failover-and-load-balancing)), `detect`, `logs` (off by default; `true` prints warnings, a path appends JSON lines), `events` and `onEvent` (see [docs/events.md](https://github.com/CLDMV/llm-translator/blob/master/docs/events.md)), `capture` (off by default; a directory or a callback receives redacted request and response records for debugging, see [docs/events.md](https://github.com/CLDMV/llm-translator/blob/master/docs/events.md#capture-for-debugging)) and a custom `transport`. `silent: true` is a deprecated alias for `logs: false`. The CLI reads the same keys from flags, `LLM_TRANSLATOR_*` environment variables and a JSON file, in that order of precedence.
|
|
132
131
|
|
|
133
132
|
Settings tune how the converters map one protocol onto the other (`inlineSystem`, `images`, `imageFallback`, `toolStreaming`, `pingInterval` and more); they are resolved per upstream from defaults, probed values, driver defaults and your overrides. The full table is in [docs/settings.md](https://github.com/CLDMV/llm-translator/blob/master/docs/settings.md).
|
|
134
133
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var d=Object.defineProperty;var r=(o,t)=>d(o,"name",{value:t,configurable:!0});import{request as u}from"../chat/request.mjs";import{request as n}from"../../../../../../../lib/responses-upstream.mjs";async function m(o,t,a){const e=await u(o,t,a),s=n(e.body,t);return e.state.dropped.push(...s.state.dropped.filter(p=>!e.state.dropped.includes(p))),{body:s.body,state:e.state}}r(m,"request");export{m as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=Object.defineProperty;var d=(t,s)=>m(t,"name",{value:s,configurable:!0});import{resolve as g}from"../../../../../../../lib/settings.mjs";import{TranslatorError as y}from"../../../../../../../lib/errors.mjs";import{itemId as o,pack as _,usageOf as h,endOf as x,envelope as v}from"../../../../../../../lib/responses.mjs";import{reasoningOf as w}from"../../../../../../../lib/thinking.mjs";function D(t,s,f){const p=g(f),r=t?.choices?.[0];if(!r)throw new y("Upstream response contained no choices",{code:"invalid_upstream_response",status:502});const e=r.message??{},n=[],a=w(e),i=p.reasoningRoundTrip&&Array.isArray(e.reasoning_details)?_(e.reasoning_details):void 0;(a!==""||i!==void 0)&&n.push({type:"reasoning",id:o("rs"),summary:a===""?[]:[{type:"summary_text",text:a}],...i===void 0?{}:{encrypted_content:i},status:"completed"});const u=typeof e.content=="string"?e.content:"",l=typeof e.refusal=="string"&&e.refusal!==""?e.refusal:null;(u!==""||l!==null)&&n.push({type:"message",id:o("msg"),status:"completed",role:"assistant",content:u!==""?[{type:"output_text",text:u,annotations:[],logprobs:[]}]:[{type:"refusal",refusal:l}]});for(const c of e.tool_calls??[])n.push({type:"function_call",id:o("fc"),call_id:c.id,name:c.function.name,arguments:c.function.arguments??"",status:"completed"});return v(s,{id:o("resp"),model:s.model??t.model,created:t.created??Math.floor(Date.now()/1e3),output:n,usage:h(t.usage),...x(r.finish_reason)})}d(D,"response");export{D as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var U=Object.defineProperty;var l=(v,f)=>U(v,"name",{value:f,configurable:!0});import{resolve as j}from"../../../../../../../lib/settings.mjs";import{finishError as z}from"../../../../../../../lib/finish.mjs";import{itemId as h,pack as F,usageOf as G,endOf as H,envelope as J,failureOf as M}from"../../../../../../../lib/responses.mjs";import{messages as K}from"../../../../../../../lib/sse.mjs";import{mergeDetail as L,reasoningOf as P}from"../../../../../../../lib/thinking.mjs";async function*Z(v,f,R){const T=j(R),B=h("resp"),C=Math.floor(Date.now()/1e3);let A=f.model,I=0,E=null,_=null;const p=[];let o=null,d=null;const c=new Map,i=l((e,t)=>({event:e,data:{type:e,...t,sequence_number:I++}}),"emit"),y=l((e,t={})=>J(f,{id:B,created:C,model:A,status:e,output:p.filter(Boolean),usage:G(E),...t}),"snapshot"),b=l(e=>{const t=p.length;return p.push(null),{index:t,item:e}},"open");function*k(){if(o===null)return;const{index:e,item:t,summary:s,details:a}=o,r=T.reasoningRoundTrip?F(a):void 0,n={...t,summary:s===""?[]:[{type:"summary_text",text:s}],...r===void 0?{}:{encrypted_content:r},status:"completed"};s!==""&&(yield i("response.reasoning_summary_text.done",{item_id:t.id,output_index:e,summary_index:0,text:s}),yield i("response.reasoning_summary_part.done",{item_id:t.id,output_index:e,summary_index:0,part:{type:"summary_text",text:s}})),p[e]=n,yield i("response.output_item.done",{output_index:e,item:n}),o=null}l(k,"closeReasoning");function*w(){if(d===null)return;const{index:e,item:t,kind:s,value:a}=d,r=s==="refusal"?{type:"refusal",refusal:a}:{type:"output_text",text:a,annotations:[],logprobs:[]};s==="refusal"?yield i("response.refusal.done",{item_id:t.id,output_index:e,content_index:0,refusal:a}):yield i("response.output_text.done",{item_id:t.id,output_index:e,content_index:0,text:a,logprobs:[]}),yield i("response.content_part.done",{item_id:t.id,output_index:e,content_index:0,part:r});const n={...t,status:"completed",content:[r]};p[e]=n,yield i("response.output_item.done",{output_index:e,item:n}),d=null}l(w,"closeText");function*N(){for(const e of[...c.values()].sort((t,s)=>t.index-s.index)){yield i("response.function_call_arguments.done",{item_id:e.item.id,output_index:e.index,name:e.item.name,arguments:e.arguments});const t={...e.item,arguments:e.arguments,status:"completed"};p[e.index]=t,yield i("response.output_item.done",{output_index:e.index,item:t})}c.clear()}l(N,"closeCalls");function*x(e){yield i("response.failed",{response:y("failed",{error:e})})}l(x,"fail"),yield i("response.created",{response:y("in_progress",{usage:null})}),yield i("response.in_progress",{response:y("in_progress",{usage:null})});try{for await(const{data:e}of K(v)){if(e==="[DONE]")break;if(e?.error){yield*x(M(e.error));return}A??=e.model,e.usage&&(E=e.usage);const t=e.choices?.[0];if(!t)continue;const s=t.delta??{},a=P(s);if(a!==""||Array.isArray(s.reasoning_details)){if(o===null){const n=b({type:"reasoning",id:h("rs"),summary:[],status:"in_progress"});o={...n,summary:"",details:[]},yield i("response.output_item.added",{output_index:n.index,item:n.item})}for(const n of s.reasoning_details??[])L(o.details,n);a!==""&&(o.summary===""&&(yield i("response.reasoning_summary_part.added",{item_id:o.item.id,output_index:o.index,summary_index:0,part:{type:"summary_text",text:""}})),o.summary+=a,yield i("response.reasoning_summary_text.delta",{item_id:o.item.id,output_index:o.index,summary_index:0,delta:a}))}const r=typeof s.content=="string"&&s.content!==""?"text":s.refusal?"refusal":null;if(r!==null){if(yield*k(),d!==null&&d.kind!==r&&(yield*w()),d===null){const u=b({type:"message",id:h("msg"),status:"in_progress",role:"assistant",content:[]});d={...u,kind:r,value:""},yield i("response.output_item.added",{output_index:u.index,item:u.item}),yield i("response.content_part.added",{item_id:u.item.id,output_index:u.index,content_index:0,part:r==="refusal"?{type:"refusal",refusal:""}:{type:"output_text",text:"",annotations:[],logprobs:[]}})}const n=r==="refusal"?s.refusal:s.content;d.value+=n,r==="refusal"?yield i("response.refusal.delta",{item_id:d.item.id,output_index:d.index,content_index:0,delta:n}):yield i("response.output_text.delta",{item_id:d.item.id,output_index:d.index,content_index:0,delta:n,logprobs:[]})}for(const n of s.tool_calls??[]){const u=n.index??0;if(!c.has(u)){yield*k(),yield*w();const q=b({type:"function_call",id:h("fc"),call_id:n.id??"",name:n.function?.name??"",arguments:"",status:"in_progress"});c.set(u,{...q,arguments:""}),yield i("response.output_item.added",{output_index:q.index,item:q.item})}const m=c.get(u);n.id&&m.item.call_id===""&&(m.item.call_id=n.id),n.function?.name&&m.item.name===""&&(m.item.name=n.function.name);const g=n.function?.arguments;typeof g=="string"&&g!==""&&(m.arguments+=g,yield i("response.function_call_arguments.delta",{item_id:m.item.id,output_index:m.index,delta:g}))}t.finish_reason&&(_=t.finish_reason)}}catch(e){yield*x(M(e));return}const O=z(_);if(O){yield*x({code:O.code,message:O.message});return}if(_===null){yield*x({code:"server_error",message:"Upstream stream ended before completion"});return}yield*k(),yield*w(),yield*N();const D=H(_);yield i(D.status==="completed"?"response.completed":"response.incomplete",{response:y(D.status,D)})}l(Z,"stream");export{Z as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var e=(r,o)=>n(r,"name",{value:o,configurable:!0});import{response as s}from"../../../../chat/to/anthropic/messages/response.mjs";import{response as t}from"../../../../../../../lib/responses-upstream.mjs";function a(r,o,p){return s(t(r,o,p),o,p)}e(a,"response");export{a as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var m=(o,r)=>a(o,"name",{value:r,configurable:!0});import{stream as p}from"../../../../chat/to/anthropic/messages/stream.mjs";import{stream as e}from"../../../../../../../lib/responses-upstream.mjs";function c(o,r,t){return p(e(o,r,t),r,t)}m(c,"stream");export{c as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var q=Object.defineProperty;var l=(e,s)=>q(e,"name",{value:s,configurable:!0});import{resolve as A}from"../../../../../../../lib/settings.mjs";import{TranslatorError as i}from"../../../../../../../lib/errors.mjs";import{unpack as O}from"../../../../../../../lib/responses.mjs";const S=new Set(["model","input","instructions","tools","tool_choice","parallel_tool_calls","text","reasoning","max_output_tokens","temperature","top_p","stream","user","safety_identifier","metadata","service_tier","prompt_cache_key","include","stream_options","store","background","previous_response_id","conversation","prompt","truncation"]),N=["previous_response_id","conversation","prompt"];function R(e,s){const n=A(s);if(e===null||typeof e!="object"||Array.isArray(e))throw new i("The request body must be a JSON object",{code:"invalid_request",param:null});if(typeof e.input!="string"&&!Array.isArray(e.input))throw new i("input is a required property and must be a string or an array of items",{code:"invalid_request",param:"input"});const a={model:e.model,stream:e.stream===!0,dropped:[],echo:{}};for(const t of N)e[t]!==void 0&&e[t]!==null&&x(`${t}: stateful requests are not supported (there is no response store)`,t);e.store===!0&&x("store: responses are not stored; send store: false or omit it","store"),e.background===!0&&x("background: background responses are not supported","background");for(const t of Object.keys(e))S.has(t)||v(a,n,t,`${t}: Unrecognized request argument`);typeof e.truncation=="string"&&e.truncation!=="disabled"&&v(a,n,"truncation",'truncation: only "disabled" is supported');const u=[];typeof e.instructions=="string"&&e.instructions!==""&&u.push({role:"system",content:e.instructions});const h=n.reasoningRoundTrip;let r=null;const y=l(t=>{r!==null&&(r.text!==""&&(t[n.reasoningField]=t[n.reasoningField]?`${t[n.reasoningField]}
|
|
2
|
+
|
|
3
|
+
${r.text}`:r.text),r.details!==null&&(t.reasoning_details=[...t.reasoning_details??[],...r.details]),r=null)},"give"),_=l(()=>{let t=u.at(-1);return t?.role!=="assistant"&&(t={role:"assistant",content:null},u.push(t)),y(t),t},"assistant");(typeof e.input=="string"?[{type:"message",role:"user",content:e.input}]:e.input).forEach((t,d)=>{const p=`input[${d}]`;if(t===null||typeof t!="object"||Array.isArray(t))throw new i(`${p}: an input item must be an object`,{code:"invalid_request",param:p});const g=t.type??(t.role===void 0?void 0:"message");if(g==="message"){const c=T(t,p);c.role==="assistant"?(u.push(c),y(c)):(r=null,u.push(c))}else if(g==="function_call"){const c=_();(c.tool_calls??=[]).push({id:w(t.call_id,`${p}.call_id`),type:"function",function:{name:w(t.name,`${p}.name`),arguments:typeof t.arguments=="string"?t.arguments:"{}"}})}else if(g==="function_call_output")r=null,u.push({role:"tool",tool_call_id:w(t.call_id,`${p}.call_id`),content:J(t.output,p)});else if(g==="reasoning"){const c=(t.summary??[]).filter(m=>typeof m?.text=="string").map(m=>m.text),k=(t.content??[]).filter(m=>typeof m?.text=="string").map(m=>m.text),j=O(t.encrypted_content);h?r={text:(c.length>0?c:k).join(`
|
|
4
|
+
|
|
5
|
+
`),details:j}:a.dropped.includes("reasoning")||a.dropped.push("reasoning")}else throw new i(`${p}: unsupported input item type ${JSON.stringify(g??null)}`,{code:"unsupported_content",param:p})});const o={model:e.model,messages:u};a.stream&&(o.stream=!0,o.stream_options={include_usage:!0}),e.max_output_tokens!==void 0&&e.max_output_tokens!==null&&(o.max_completion_tokens=e.max_output_tokens),e.temperature!==void 0&&e.temperature!==null&&(o.temperature=e.temperature),e.top_p!==void 0&&e.top_p!==null&&(o.top_p=e.top_p),typeof(e.user??e.safety_identifier)=="string"&&(o.user=e.user??e.safety_identifier),e.metadata!==void 0&&e.metadata!==null&&(o.metadata=e.metadata),typeof e.service_tier=="string"&&(o.service_tier=e.service_tier),typeof e.prompt_cache_key=="string"&&(o.prompt_cache_key=e.prompt_cache_key),typeof e.reasoning?.effort=="string"&&(o.reasoning_effort=e.reasoning.effort);const $=(e.tools??[]).map((t,d)=>E(t,`tools[${d}]`));$.length>0&&(o.tools=$,e.tool_choice!==void 0&&e.tool_choice!==null&&(o.tool_choice=F(e.tool_choice)),typeof e.parallel_tool_calls=="boolean"&&(o.parallel_tool_calls=e.parallel_tool_calls));const f=e.text?.format;if(f?.type==="json_object")o.response_format={type:"json_object"};else if(f?.type==="json_schema"){if(typeof f.name!="string"||f.schema===null||typeof f.schema!="object")throw new i("text.format: a json_schema format needs a name and a schema",{code:"invalid_request",param:"text.format"});const{type:t,schema:d,...p}=f;o.response_format={type:"json_schema",json_schema:{...p,schema:d}}}else if(f!==void 0&&f?.type!=="text")throw new i(`text.format: unsupported format type ${JSON.stringify(f?.type??null)}`,{code:"unsupported_field",param:"text.format"});return typeof e.text?.verbosity=="string"&&(o.verbosity=e.text.verbosity),a.echo={instructions:typeof e.instructions=="string"?e.instructions:null,max_output_tokens:e.max_output_tokens??null,parallel_tool_calls:e.parallel_tool_calls??!0,previous_response_id:null,reasoning:{effort:e.reasoning?.effort??null,summary:e.reasoning?.summary??null},store:!1,temperature:e.temperature??null,text:{format:e.text?.format??{type:"text"}},tool_choice:e.tool_choice??"auto",tools:e.tools??[],top_p:e.top_p??null,truncation:"disabled",user:o.user??null,metadata:e.metadata??{}},{body:o,state:a}}l(R,"request");function x(e,s){throw new i(e,{code:"unsupported_field",param:s})}l(x,"refuse");function v(e,s,n,a){s.unknownFields==="error"&&x(a,n),e.dropped.push(n)}l(v,"skip");function w(e,s){if(typeof e!="string"||e==="")throw new i(`${s} is required`,{code:"invalid_request",param:s});return e}l(w,"required");function J(e,s){if(typeof e=="string")return e;if(!Array.isArray(e))throw new i(`${s}.output must be a string or an array of text parts`,{code:"invalid_request",param:`${s}.output`});return e.map(n=>{if(n?.type==="input_text"&&typeof n.text=="string")return n.text;throw new i(`${s}.output: unsupported part type ${JSON.stringify(n?.type??null)}`,{code:"unsupported_content",param:`${s}.output`})}).join("")}l(J,"outputText");function T(e,s){const n=e.role;if(n!=="user"&&n!=="assistant"&&n!=="system"&&n!=="developer")throw new i(`${s}.role: unsupported role ${JSON.stringify(n??null)}`,{code:"invalid_request",param:`${s}.role`});if(typeof e.content=="string")return{role:n,content:e.content};if(!Array.isArray(e.content))throw new i(`${s}.content must be a string or an array of parts`,{code:"invalid_request",param:`${s}.content`});const a=[];let u;if(e.content.forEach((r,y)=>{const _=`${s}.content[${y}]`;if((r?.type==="input_text"||r?.type==="output_text")&&typeof r.text=="string")a.push({type:"text",text:r.text});else if(r?.type==="refusal"&&n==="assistant"&&typeof r.refusal=="string")u=(u??"")+r.refusal;else if(r?.type==="input_image"&&n==="user"){if(typeof r.image_url!="string")throw new i(`${_}: an image must carry image_url (stored files are not supported)`,{code:"unsupported_content",param:_});a.push({type:"image_url",image_url:{url:r.image_url,...typeof r.detail=="string"&&r.detail!=="auto"?{detail:r.detail}:{}}})}else throw new i(`${_}: unsupported content part type ${JSON.stringify(r?.type??null)}`,{code:"unsupported_content",param:_})}),n==="user")return{role:n,content:a};const h=a.map(r=>r.text).join("");return{role:n,content:h===""&&u!==void 0?null:h,...u===void 0?{}:{refusal:u}}}l(T,"messageOf");function E(e,s){if(e?.type!=="function")throw new i(`${s}: unsupported tool type ${JSON.stringify(e?.type??null)} (only function tools are supported)`,{code:"unsupported_tool",param:s});const n={name:w(e.name,`${s}.name`)};return typeof e.description=="string"&&(n.description=e.description),e.parameters!==void 0&&e.parameters!==null&&(n.parameters=e.parameters),typeof e.strict=="boolean"&&(n.strict=e.strict),{type:"function",function:n}}l(E,"toolOf");function F(e){if(e==="auto"||e==="none"||e==="required")return e;if(e?.type==="function"&&typeof e.name=="string")return{type:"function",function:{name:e.name}};throw new i(`tool_choice: unsupported value ${JSON.stringify(e?.type??e)}`,{code:"unsupported_field",param:"tool_choice"})}l(F,"choiceOf");export{R as request};
|
|
6
|
+
//# sourceMappingURL=request.mjs.map
|
package/dist/api/detect.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var y=Object.defineProperty;var o=(t,e)=>y(t,"name",{value:e,configurable:!0});import{context as k,self as h}from"../lib/runtime.mjs";import{capture as $}from"../lib/capture.mjs";import{TranslatorError as u}from"../lib/errors.mjs";import{warn as b}from"../lib/warn.mjs";import{emit as S}from"../lib/events.mjs";import*as U from"../lib/http.mjs";import{validToolIdPolicy as x}from"../lib/ids.mjs";import{supported as d,MESSAGES as A,CHAT as M}from"../lib/protocol.mjs";async function O(t={}){const e=$(h,k),{status:n}=h,f=t.network!==!1;for(const r of e.drivers){const s=r.info.fields;if(s!==void 0&&!(Array.isArray(s)&&s.every(i=>typeof i=="string")))throw new u(`Driver ${r.name}: info().fields must be an array of field names`,{code:"invalid_driver",status:500})}for(const r of e.drivers){const s=r.info.toolCallIds;if(s!==void 0&&!x(s))throw new u(`Driver ${r.name}: info().toolCallIds must be { alphabet, min?, max? } with a character-class alphabet and positive integer bounds`,{code:"invalid_driver",status:500})}const a={transport:e.state.transport,signal:t.signal,timeout:e.config.detectTimeout};return await Promise.all(e.state.endpoints.map(r=>I(e,r,f,a))),n()}o(O,"detect");async function I(t,e,n,f){let a,r=null;if(e.backend!=="auto"){if(a=t.drivers.find(s=>s.name===e.backend),!a)throw new u(`Unknown backend "${e.backend}" for upstream ${e.name}`,{code:"unknown_backend",status:500});r={version:e.version}}else if(n){const s=URL.canParse(e.url)?new URL(e.url).hostname:"",i={endpoint:e,...f,probes:new Map},c=t.drivers.filter(l=>_(l.info,s));for(const l of c)if(r=await p(l,i),r){a=l;break}let v=!1;for(const[l,m]of a?[]:t.drivers.entries()){if(!v&&m.info.probes?.length>0&&!m.info.hosts?.includes(s)){v=!0;for(const g of t.drivers.slice(l))for(const w of g.info.probes??[])U.probe(i,w,g.info)}if(r=await p(m,i),r){a=m;break}}}if(a||(a=t.drivers.find(s=>s.name==="compatible"),r={reachable:null,models:[]}),t.state.missing.delete(e.name),Object.assign(e.health,{ready:null,readyReason:null,checkedAt:null,unsupported:!1}),e.driver=a.name,e.protocol=a.info.protocol,T(t,e,a),e.api!=="auto"&&!d(a.info).includes(e.api)){const s=t.drivers.filter(i=>d(i.info).includes(e.api)).map(i=>i.name);throw new u(`Upstream ${e.name}: api "${e.api}" needs a driver for a server that speaks it (${s.join(", ")}), but the upstream is bound to ${a.name}, which speaks ${d(a.info).join(", ")}; set backend to one of them or change api`,{code:"unsupported_api",status:500})}if(e.facts=r,e.driverSettings=await a.settings?.(r)??{},e.probed={},n&&e.backend==="auto"&&a.probe){const s=o(c=>e.settings[c]!==void 0||t.config.settings[c]!==void 0,"given"),i={inlineSystem:t.settings(e).inlineSystem==="auto",images:!s("images")};(i.inlineSystem||i.images)&&(e.probed=await a.probe({endpoint:e,facts:r,want:i,...f}))}r.reachable===!1?b(t.config,t.state,`Upstream ${e.name} (${e.url}) did not answer detection; using the generic OpenAI-compatible driver`,{type:"detect",kind:"unreachable",endpoint:e.name,url:e.url,driver:a.name}):S({config:t.config,state:t.state},{type:"detect",kind:"driver",level:"info",message:`Upstream ${e.name} (${e.url}): driver ${a.name}`,endpoint:e.name,url:e.url,driver:a.name})}o(I,"bind");function T(t,e,n){if(e.legacy===void 0||n.name!=="vllm")return;const f=o(a=>b(t.config,t.state,a,{type:"detect",kind:"deprecated",endpoint:e.name,setting:"nativeMessages"}),"tell");if(e.apiSet){f(`Upstream ${e.name}: the nativeMessages setting is deprecated and ignored, because api is set; remove it.`);return}e.api=e.legacy===!0?A:e.legacy==="auto"?"auto":M,f(`Upstream ${e.name}: the nativeMessages setting is deprecated; it is read as api: "${e.api}". Set api instead.`)}o(T,"legacy");function _(t,e){return e!==""&&(t.hosts?.includes(e)===!0||t.hostSuffixes?.some(n=>e.endsWith(n))===!0)}o(_,"matchesHost");async function p(t,e){try{return await t.detect?.(e)??null}catch{return null}}o(p,"detectWith");export{O as detect};
|
|
2
2
|
//# sourceMappingURL=detect.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=Object.defineProperty;var s=(e
|
|
1
|
+
var t=Object.defineProperty;var s=(o,e)=>t(o,"name",{value:e,configurable:!0});function a(){return{name:"anthropic",protocol:"anthropic.messages",protocols:["anthropic.messages"],order:38,auth:"x-api-key",strict:!0,hosts:["api.anthropic.com"],probes:["/v1/models"],headers:{"anthropic-version":"2023-06-01"},paths:{messages:"/v1/messages",models:"/v1/models",count:"/v1/messages/count_tokens"}}}s(a,"info");export{a as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i=Object.defineProperty;var e=(o,a)=>i(o,"name",{value:a,configurable:!0});function c(){return{name:"azure",protocol:"openai.chat",protocols:["openai.chat"],order:32,auth:"api-key",strict:!0,hostSuffixes:[".openai.azure.com",".cognitiveservices.azure.com",".services.ai.azure.com"],paths:{chat:"/openai/v1/chat/completions",embeddings:"/openai/v1/embeddings",models:"/openai/v1/models"}}}e(c,"info");export{c as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});import{VLLM_FIELDS as r}from"../../../lib/passthrough.mjs";function c(){return{name:"compatible",protocol:"openai.chat",protocols:["openai.chat","openai.responses"],order:100,auth:"bearer",strict:!1,fields:r,paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(c,"info");export{c as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var a=Object.defineProperty;var e=(o,t)=>a(o,"name",{value:t,configurable:!0});function
|
|
1
|
+
var a=Object.defineProperty;var e=(o,t)=>a(o,"name",{value:t,configurable:!0});function c(){return{name:"deepseek",protocol:"openai.chat",protocols:["openai.chat"],order:35,auth:"bearer",strict:!1,hosts:["api.deepseek.com"],paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}e(c,"info");export{c as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var a=Object.defineProperty;var e=(p
|
|
1
|
+
var a=Object.defineProperty;var e=(o,p)=>a(o,"name",{value:p,configurable:!0});function r(){return{name:"llamacpp",protocol:"openai.chat",protocols:["openai.chat","openai.responses"],order:40,auth:"bearer",strict:!1,probes:["/props"],fields:["top_k","min_p","chat_template_kwargs","repetition_penalty","repeat_penalty","grammar","json_schema"],paths:{chat:"/v1/chat/completions",models:"/v1/models",props:"/props"}}}e(r,"info");export{r as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s=Object.defineProperty;var o=(e,t)=>s(e,"name",{value:t,configurable:!0});function i(){return{name:"lmstudio",protocol:"openai.chat",protocols:["openai.chat","openai.responses"],order:55,auth:"bearer",strict:!1,probes:["/api/v0/models"],paths:{chat:"/v1/chat/completions",models:"/v1/models",listing:"/api/v0/models"}}}o(i,"info");export{i as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var n=Object.defineProperty;var o=(e,a)=>n(e,"name",{value:a,configurable:!0});function r(){return{name:"localai",protocol:"openai.chat",protocols:["openai.chat","openai.responses"],order:52,auth:"bearer",strict:!1,probes:["/version","/.well-known/localai.json"],fields:["top_k","min_p","repeat_penalty","repeat_last_n","ignore_eos","typical_p","chat_template_kwargs","grammar"],paths:{chat:"/v1/chat/completions",models:"/v1/models",version:"/version",discovery:"/.well-known/localai.json"}}}o(r,"info");export{r as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=Object.defineProperty;var a=(t
|
|
1
|
+
var e=Object.defineProperty;var a=(o,t)=>e(o,"name",{value:t,configurable:!0});function r(){return{name:"mistral",protocol:"openai.chat",protocols:["openai.chat"],order:36,auth:"bearer",strict:!1,hosts:["api.mistral.ai"],toolCallIds:{alphabet:"a-zA-Z0-9",min:9,max:9},paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}a(r,"info");export{r as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=Object.defineProperty;var
|
|
1
|
+
var e=Object.defineProperty;var o=(a,t)=>e(a,"name",{value:t,configurable:!0});function p(){return{name:"ollama",protocol:"openai.chat",protocols:["openai.chat","openai.responses","ollama.chat"],order:60,auth:"bearer",strict:!1,probes:["/api/version"],paths:{chat:"/v1/chat/completions",models:"/v1/models",version:"/api/version"},native:{protocol:"ollama.chat",paths:{chat:"/api/chat"}}}}o(p,"info");export{p as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=Object.defineProperty;var a=(o,e)=>m(o,"name",{value:e,configurable:!0});import{noEmptyTools as
|
|
1
|
+
var m=Object.defineProperty;var a=(o,e)=>m(o,"name",{value:e,configurable:!0});import{noEmptyTools as f}from"../../../lib/normalize.mjs";import{estimate as p}from"../../../lib/estimate.mjs";const d=["tool_choice","n","logit_bias"],h="[An image was omitted because Ollama accepts base64 images only and the translator does not fetch URLs.]";function l(o,e){const t=Number.isFinite(o?.options?.num_ctx)?o.options.num_ctx:e?.settings?.contextWindow??0;t>0&&p(o)>t&&e?.warn?.(`Upstream ${e.endpoint?.name}: the prompt is estimated at more than ${t} tokens, which Ollama truncates without an error. Raise num_ctx (OLLAMA_CONTEXT_LENGTH or a Modelfile) and set the upstream's contextWindow setting to match.`)}a(l,"overflow");function y(o,e){if(e?.protocol==="ollama.chat")return l(o,e),o;let t=f(o);const n=e?.state?.dropped;t.tool_choice==="none"&&t.tools!==void 0&&(t={...t},delete t.tools,delete t.parallel_tool_calls,Array.isArray(n)&&!n.includes("tools")&&n.push("tools"));for(const r of d)t[r]!==void 0&&(t={...t},delete t[r],Array.isArray(n)&&!n.includes(r)&&n.push(r));if(Array.isArray(t.messages)){let r=!1;const u=t.messages.map(i=>{if(!Array.isArray(i?.content))return i;const c=i.content.map(s=>s?.type!=="image_url"||String(s.image_url?.url).startsWith("data:")?s:(r=!0,{type:"text",text:h}));return{...i,content:c}});r&&(t={...t,messages:u},Array.isArray(n)&&!n.includes("image_url")&&n.push("image_url"))}return l(t,e),t}a(y,"request");export{y as request};
|
|
2
2
|
//# sourceMappingURL=request.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function
|
|
1
|
+
var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function r(){return{name:"openai",protocol:"openai.chat",protocols:["openai.chat","openai.responses"],order:30,auth:"bearer",strict:!0,hosts:["api.openai.com"],fields:["prompt_cache_key"],paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(r,"info");export{r as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=Object.defineProperty;var o=(e
|
|
1
|
+
var r=Object.defineProperty;var o=(t,e)=>r(t,"name",{value:e,configurable:!0});function n(){return{name:"openrouter",protocol:"openai.chat",protocols:["openai.chat"],order:37,auth:"bearer",strict:!1,hosts:["openrouter.ai"],paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(n,"info");export{n as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=Object.defineProperty;var e=(t
|
|
1
|
+
var r=Object.defineProperty;var e=(o,t)=>r(o,"name",{value:t,configurable:!0});function n(){return{name:"sglang",protocol:"openai.chat",protocols:["openai.chat","openai.responses"],order:50,auth:"bearer",strict:!1,probes:["/get_server_info"],fields:["top_k","min_p","repetition_penalty","chat_template_kwargs","skip_special_tokens","ignore_eos","regex","ebnf","separate_reasoning"],paths:{chat:"/v1/chat/completions",models:"/v1/models",serverInfo:"/get_server_info"}}}e(n,"info");export{n as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=Object.defineProperty;var o=(t,e)=>a(t,"name",{value:e,configurable:!0});function i(){return{name:"tgi",protocol:"openai.chat",protocols:["openai.chat"],order:45,auth:"bearer",strict:!1,probes:["/info"],fields:["grammar"],paths:{chat:"/v1/chat/completions",models:"/v1/models",info:"/info"}}}o(i,"info");export{i as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t=Object.defineProperty;var e=(o,s)=>t(o,"name",{value:s,configurable:!0});import{VLLM_FIELDS as a}from"../../../lib/passthrough.mjs";function i(){return{name:"vllm",protocol:"openai.chat",protocols:["anthropic.messages","openai.chat","openai.responses"],order:10,auth:"bearer",strict:!0,fields:a,paths:{chat:"/v1/chat/completions",messages:"/v1/messages",models:"/v1/models",tokenize:"/tokenize",version:"/version",health:"/health"}}}e(i,"info");export{i as info};
|
|
2
2
|
//# sourceMappingURL=info.mjs.map
|
package/dist/api/request.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
${p}`,
|
|
1
|
+
var R=Object.defineProperty;var h=(e,n)=>R(e,"name",{value:n,configurable:!0});import{context as M,self as B}from"../lib/runtime.mjs";import{capture as K}from"../lib/capture.mjs";import{resolve as H}from"../lib/route.mjs";import*as y from"../lib/http.mjs";import{filterChatBody as N}from"../lib/passthrough.mjs";import{addSampling as z}from"../lib/sampling.mjs";import{addConstraint as A}from"../lib/constraint.mjs";import{addCache as D}from"../lib/cache.mjs";import*as x from"../lib/images.mjs";import*as q from"../lib/tools.mjs";import{LIMITS as G}from"../lib/toolsearch.mjs";import{warn as v}from"../lib/warn.mjs";import{emit as J}from"../lib/events.mjs";import{fit as Q,pinBody as V}from"../lib/effort.mjs";import{relax as W,strictTools as X}from"../lib/strict.mjs";import{TranslatorError as Y}from"../lib/errors.mjs";import*as Z from"../lib/vllm.mjs";import{PROTOCOL as w}from"../lib/responses-upstream.mjs";function ee(e,n){return`${e.driver}:${n}:${URL.canParse(e.url)?new URL(e.url).host:e.url}`}h(ee,"producerOf");async function ke(e,n={}){const a=K(B,M,n.front),u=H(a,e,{endpoint:n.endpoint,wire:n.wire,tokens:n.tokens,advance:n.hold===!0&&n.endpoint===void 0});if(n.hold!==!0)return I(a,e,n,u);u.endpoint.health.inflight++;try{return await I(a,e,n,u)}catch(r){throw u.endpoint.health.inflight--,r}}h(ke,"request");function te(e,n,a,u,r,p){const k=X(n);if(k.length===0)return n;const l=k.filter(c=>c.problems.length>0);if(l.length>0&&r.unknownFields==="error")throw new Y(`tools: ${l[0].name}: schema is outside the strict subset (${l[0].problems.join("; ")})`,{code:"unsupported_content",param:"tools"});const _=W(n);if(p.retry===!0)return _;const g=h((c,f)=>v(e.config,e.state,c,{kind:f,endpoint:a.name,log:p.log}),"tell");for(const c of l)g(`Upstream ${a.name}: strict tool ${c.name} has a schema outside the strict subset: ${c.problems.join("; ")} (sent without strict)`,"strict");const s=k.filter(c=>c.problems.length===0);return u.info.strict!==!0&&s.length>0&&g(`Upstream ${a.name}: the ${u.name} backend does not enforce strict tool use (${s.map(c=>c.name).join(", ")})`,"strict"),_}h(te,"checkStrict");async function I(e,n,a,u){const{endpoint:r,model:p,unserved:k,convert:l,pool:_,pin:g,protocol:s}=u,c=Object.hasOwn(e.config.efforts,p)?e.config.efforts[p]:void 0;g&&(n=V(n,g,e.front));const f=e.driver(r),U=e.front==="anthropic"?n.metadata?.prompt_cache_key:void 0;let $=e.front==="anthropic"?n.metadata?.constraint:void 0;e.front==="openai"&&n.constraint!==void 0&&({constraint:$,...n}=n);const j=`${r.name}
|
|
2
|
+
${p}`,C=a.images===!1||e.state.textOnly.has(j)&&e.settings(r,s).imageFallback,O=e.settings(r,s),E=a.jsonObject==="instruction"||e.state.jsonInstruction.has(j)&&O.jsonObjectFallback,d={...C?{...O,images:!1}:O,...E?{jsonObject:"instruction"}:{},...g?.effort===void 0?{}:{effort:!0}},b=n.stream===!0,S=s==="anthropic.messages"&&l===null&&f.info.protocol!=="anthropic.messages";let t,o;l?({body:t,state:o}=await l.request(n,d,{producer:ee(r,s),budget:a.budget,listed:c!==void 0,toolCallIds:f.info.toolCallIds}),o.toolSearch?.capped&&v(e.config,e.state,`Tool search: more than ${G.definitions} tool definitions came back in ToolSearch results for ${r.name}; the rest are not offered.`,{kind:"toolsearch",endpoint:r.name,log:a.log})):S?t=Z.request(n,d):t=e.front==="openai"&&(a.filter??d.passthroughFilter===!0)?N(n,f.info.fields):{...n};const F=e.front==="anthropic"?n.metadata?.sampling:void 0;if(s==="openai.chat"){const i=[];t=z(t,F,d,f.info.fields,i),o&&o.dropped.push(...i.filter(m=>!o.dropped.includes(m)))}else if(!l&&F!==void 0&&t.metadata?.sampling!==void 0){const{sampling:i,...m}=t.metadata;t={...t,metadata:m}}if(s==="openai.chat"){const i=[],m={name:f.info.name,version:r.facts?.version??r.version};t=A(t,$,d,m,i),t=D(t,{salt:a.cacheSalt,key:U},d,m.name,i),o&&o.dropped.push(...i.filter(P=>!o.dropped.includes(P)))}else{if(o&&!o.dropped.includes("cache_salt")&&(a.cacheSalt??d.cacheSalt)!=null&&o.dropped.push("cache_salt"),o&&!o.dropped.includes("prompt_cache_key")&&(U??d.promptCacheKey)!=null&&o.dropped.push("prompt_cache_key"),!l&&t.metadata?.prompt_cache_key!==void 0){const{prompt_cache_key:i,...m}=t.metadata;t={...t,metadata:m}}if(o&&($??d.constraint)!=null&&!o.dropped.includes("constraint")&&o.dropped.push("constraint"),!l&&t.metadata?.constraint!==void 0){const{constraint:i,...m}=t.metadata;t={...t,metadata:m}}}if(a.usage===!0&&b&&e.front==="openai"){if(l)o.includeUsage=!0;else if(d.streamUsage){const i=t.stream_options&&typeof t.stream_options=="object"?t.stream_options:{};t.stream_options={...i,include_usage:!0}}}C&&!l&&e.front==="openai"&&(t=x.strip(t)),a.tools===!1&&(t=q.strip(t)),t.model=p,t=te(e,t,r,f,d,a),c&&s==="openai.chat"&&Q(t,c,p,(i,m)=>v(e.config,e.state,i,{type:"effort",endpoint:r.name,model:p,...m,log:a.log})),o?.reasoningMissing&&s!==w&&v(e.config,e.state,`Upstream ${r.name}: assistant turns with tool calls have no reasoning to send back (the client dropped its thinking blocks or their signatures), which servers that need it with tools will refuse.`,{kind:"reasoning",endpoint:r.name,log:a.log}),f.request&&!S&&s!==w&&(t=await f.request(t,{endpoint:r,settings:d,levels:c,protocol:s,state:o,warn:h(i=>v(e.config,e.state,i,{kind:"driver",endpoint:r.name,log:a.log}),"warn")})),o?.dropped?.length>0&&a.retry!==!0&&J(e,{type:"dropped",level:"debug",message:`Upstream ${r.name}: dropped ${o.dropped.join(", ")}`,endpoint:r.name,model:p,fields:[...o.dropped],log:a.log});const L=s==="anthropic.messages"?"messages":s===w?"responses":"chat",T=await y.pathOf(f,L,r,p,s);return{upstream:r.name,pool:_.map(i=>i.name),method:"POST",url:y.join(r.url,T),path:T,headers:{"content-type":"application/json",accept:b?"text/event-stream":"application/json",...f.info.headers,...l===null&&r.protocol==="anthropic.messages"?a.clientHeaders:void 0,...y.headers(r,f.info.auth,a.headers)},body:t,state:{v:1,upstream:r.name,front:e.front,native:l===null,protocol:s,messages:S,responses:s===w,model:n.model,stream:b,unserved:k,convert:o},more:u.more,images:{sent:x.carries(t),retry:d.imageFallback&&s==="openai.chat",key:j},tools:{sent:q.carries(t),retry:d.toolFallback&&s==="openai.chat"},json:{sent:o?.jsonSchemaEmulated===!0,retry:d.jsonObjectFallback&&s==="anthropic.messages",key:j}}}h(I,"prepare");export{ke as request};
|
|
3
3
|
//# sourceMappingURL=request.mjs.map
|
package/dist/api/response.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=Object.defineProperty;var
|
|
1
|
+
var m=Object.defineProperty;var s=(i,o)=>m(i,"name",{value:o,configurable:!0});import{context as c,self as t}from"../lib/runtime.mjs";import{capture as d}from"../lib/capture.mjs";import*as f from"../lib/vllm.mjs";import{RESPONSES as l}from"../lib/protocol.mjs";async function x(i,o){const e=d(t,c,o.front),n=e.endpoint(o.upstream),p=e.driver(n);let r=i;return p.response&&e.protocol(n,o)!==l&&(r=await p.response(r,{endpoint:n,settings:e.settings(n,e.protocol(n,o)),state:o})),o.messages&&(r=f.response(r)),o.native?r.model===void 0?r:{...r,model:o.model??r.model}:e.converters(o).response(r,o.convert,e.settings(n,e.protocol(n,o)))}s(x,"response");export{x as response};
|
|
2
2
|
//# sourceMappingURL=response.mjs.map
|
package/dist/api/route.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=Object.defineProperty;var t=(o,e)=>d(o,"name",{value:e,configurable:!0});import{context as f,self as s}from"../lib/runtime.mjs";import{capture as v}from"../lib/capture.mjs";import{resolve as w}from"../lib/route.mjs";function g(o,e={}){const n=v(s,f,e.front),{endpoint:r,model:m,requested:p,unserved:c,convert:i,pool:l,protocol:u}=w(n,o,{wire:e.wire});return{upstream:r.name,model:m,requested:p,protocol:u,backend:r.driver,native:i===null,unserved:c,pool:l.map(a=>a.name)}}t(g,"route");export{g as route};
|
|
2
2
|
//# sourceMappingURL=route.mjs.map
|
package/dist/api/send.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var me=Object.defineProperty;var i=(n,r)=>me(n,"name",{value:r,configurable:!0});import{context as K,self as ee}from"../lib/runtime.mjs";import{TranslatorError as C}from"../lib/errors.mjs";import*as te from"../lib/http.mjs";import*as pe from"../lib/images.mjs";import*as de from"../lib/tools.mjs";import{parse as ae}from"../lib/upstream-error.mjs";import{meter as fe,normalize as ge}from"../lib/usage.mjs";import{capture as he}from"../lib/capture.mjs";import{estimate as ye,bodyLength as we,output as be,patch as ke,stream as Se}from"../lib/estimate.mjs";import{warn as se}from"../lib/warn.mjs";import{start as je}from"../lib/record.mjs";import{emit as re}from"../lib/events.mjs";import{MISSING as ve}from"../lib/responses-upstream.mjs";import{MESSAGES as $e,RESPONSES as _e,remember as Te}from"../lib/protocol.mjs";import*as ne from"../lib/pool.mjs";import{createBudget as xe}from"../lib/thinking.mjs";import*as oe from"../lib/fanout.mjs";import{refresh as Oe}from"../lib/health.mjs";const Ee={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"};async function Ue(n,r={}){const{transport:w,textOnly:d,jsonInstruction:$}=K.state,{request:_,response:T,stream:l,error:g}=ee,p=g.build,{config:u,state:k}=K,h=he(ee,K,r.front),U=n&&typeof n=="object"&&!Array.isArray(n),x={model:null,requested:U&&typeof n.model=="string"?n.model:null,upstream:null,front:r.front??u.front,stream:U&&n.stream===!0},S=fe(x,r.onUsage,(m,N)=>se(u,k,m,{type:"usage",...N,log:r.log})),A=i(m=>Object.defineProperty(m,"usage",{value:S.usage,enumerable:!1,configurable:!0}),"attach");let M=!1;try{const m=oe.wants(h,n);if(m>0){M=!0;const N=i((o,O)=>se(u,k,o,{type:"usage",...O,log:r.log}),"warning");return await oe.run({body:n,count:m,options:r,send:Ue,warn:N})}return A(await Ae({transport:w,textOnly:d,jsonInstruction:$,request:_,response:T,stream:l,error:g,captured:h},n,r,S))}catch(m){if(M)throw m;if(!(m instanceof C))throw r.signal?.aborted||re(h,{type:"error",kind:"exception",level:"error",message:String(m?.message??m),log:r.log}),S.finish(r.signal?.aborted?"aborted":"error"),m;return S.finish("error"),A(p(m.status,m.message,{type:m.type,code:m.code,param:m.param,front:r.front}))}}i(Ue,"send");async function Ae({transport:n,textOnly:r,jsonInstruction:w,request:d,response:$,stream:_,error:T,captured:l},g,p,u){const k={front:p.front,wire:p.wire,headers:p.headers,clientHeaders:p.clientHeaders,filter:p.filter,cacheSalt:p.cacheSalt,usage:!0,budget:xe(),log:p.log},h=i(t=>{re(l,{...t,log:p.log})},"announce"),U=u.meta.front==="openai"&&g?.stream_options?.include_usage!==!0,x=i(t=>{u.meta.model=t.body.model??null,u.meta.upstream=t.upstream,t.state.native?u.source(null):u.source(()=>t.state.convert?.upstreamUsage,ie(t.state))},"note"),S=i(t=>{if(t.state.native)return{input:!1,output:!1};const e=ge(ie(t.state),t.state.convert?.upstreamUsage);return e===null?{input:!0,output:!0}:{input:e.input_tokens===null&&e.cache_read_input_tokens===null&&e.cache_creation_input_tokens===null,output:e.output_tokens===null}},"gaps"),A=i(async t=>{const e=l.endpoint(t.upstream),a=l.driver(e);return(a.count&&!t.state.responses&&!(U&&t.state.stream)?await a.count({endpoint:e,request:t.body,transport:n,signal:p.signal,timeout:l.config.detectTimeout}):null)??ye(t.body)},"input"),M=i(async(t,e)=>{const a=S(t);return!a.input&&!a.output?null:{input_tokens:a.input?await A(t):null,output_tokens:a.output?be(e):null}},"counts"),m=i((t,e,a,s,j)=>(u.finish(j),T(t,e,a,s)),"fail"),N=i(async t=>{let e=t,a=await Q(n,e,p.signal,B());const s=a.status,j=e.state.protocol===$e,ue=e.state.protocol===_e;if(e.more&&(s===404&&j||ve.includes(s)&&ue)){const y=await I(a);if(j&&y?.type==="error")return{upstream:e,result:a,failure:y};Te(l.state,e.upstream,e.state.protocol);const b=j?"messages":"responses",f=j?"Messages API (/v1/messages)":"Responses API (/v1/responses)";return h({type:"fallback",kind:b,level:"warn",message:`Upstream ${e.upstream}: ${f} answered ${s}; sent the request over the next protocol, and will do so for this upstream until the next detection. Set api on this upstream (for example "chat") to skip the first attempt.`,endpoint:e.upstream,model:e.body.model,status:s,reason:String(ae(y,s).message).trim().slice(0,500),action:j?"conversion":"chat"}),e=await d(g,{...k,endpoint:e.upstream,retry:!0}),x(e),{upstream:e,result:await Q(n,e,p.signal,B())}}const ce=s===400&&[e.images,e.tools].some(y=>y.sent&&y.retry),L=(s===400||s===422)&&e.json.sent&&e.json.retry;if(!a.ok&&(ce||L)){const y=await I(a),b=ae(y,s).message,f={};if(s===400&&e.images.sent&&e.images.retry&&pe.refused(b)?(r.add(e.images.key),f.images=!1):s===400&&e.tools.sent&&e.tools.retry&&de.refused(b)?f.tools=!1:L&&(f.jsonObject="instruction"),!("images"in f||"tools"in f||"jsonObject"in f))return{upstream:e,result:a,failure:y};const v={upstream:e,result:a,failure:y};if("images"in f||"tools"in f){const F="images"in f?"images":"tools";h({type:"fallback",kind:F,level:"warn",message:`Upstream ${e.upstream}: ${e.state.model} refused ${F==="images"?"images":"tools"} (${s}: "${String(b).trim().slice(0,500)}"); sent the request again without them.`,endpoint:e.upstream,model:e.body.model,status:s,reason:String(b).trim().slice(0,500),action:F==="images"?"text-only":"without-tools"})}if(e=await d(g,{...k,...f,endpoint:e.upstream,retry:!0}),x(e),a=await Q(n,e,p.signal,B()),L&&"jsonObject"in f){if(!a.ok){try{await a.body?.cancel?.()}catch{}return x(v.upstream),v}w.add(v.upstream.json.key),h({type:"fallback",kind:"json_object",level:"warn",message:`Upstream ${v.upstream.upstream}: ${v.upstream.state.model} rejected the json_object schema emulation (${s}: "${String(b).trim().slice(0,500)}"); sent it as a system instruction instead. Set jsonObject: "instruction" on this upstream to skip the first attempt.`,endpoint:v.upstream.upstream,model:v.upstream.body.model,status:s,reason:String(b).trim().slice(0,500),action:"instruction"})}}return{upstream:e,result:a}},"attempt");await Oe(l,g,p.signal);let o=await d(g,{...k,hold:!0});const O=o.pool;let G=0;const z=O.length>1?l.config.pool:null,B=i(()=>z&&{connectTimeout:z.connectTimeout,headersTimeout:G+1<O.length?z.headersTimeout:0},"limitsNow");let P=l.endpoint(o.upstream);const V=i(()=>P.health.inflight--,"release");let c,E,W=null,X=0;const Y=i(t=>{const e=je(l,{body:g,sent:o,front:u.meta.front,requested:u.meta.requested,headers:t,log:p.log,exchange:W,attempt:X});return W??=e.id,e},"begin"),Z=i(async t=>{const e=Y();if(!e.on)return;if(c===void 0)return e.attempt({error:E.message},t);let a=null;try{a=E??await I(c)}catch{}e.attempt({status:c.status,headers:te.plain(c.headers),body:a},t)},"keep");try{for(;;){const t=P;t.health.requests++,X++,x(o);let e=null;try{({upstream:o,result:c,failure:E}=await N(o)),!c.ok&&c.status>=500&&(e=`HTTP ${c.status}`,h({type:"error",kind:"upstream",level:"error",message:`Upstream ${t.name} answered HTTP ${c.status}`,endpoint:t.name,model:o.body.model,status:c.status}))}catch(s){if(!(s instanceof C)||s.code!=="upstream_unreachable")throw s;e=s.message,c=void 0,E=s,h({type:"error",kind:"transport",level:"error",message:s.message,endpoint:t.name,model:o.body.model})}if(e===null){ne.succeeded(t);break}ne.failed(l.config,t,e);let a=null;for(;a===null&&!p.signal?.aborted&&G+1<O.length;)try{a=await d(g,{...k,endpoint:O[++G],hold:!0})}catch(s){if(!(s instanceof C)||s.code!=="endpoint_not_in_pool")throw s}if(a===null){if(c===void 0)throw await Z(),E;break}await Z(e),h({type:"failover",level:"warn",message:`Upstream ${t.name} failed (${e}); trying ${a.upstream}`,from:t.name,to:a.upstream,model:a.body.model,reason:e});try{await c?.body?.cancel?.()}catch{}V(),P=l.endpoint(a.upstream),o=a}}catch(t){throw V(),t}const le=P;P=null,u.usage.then(()=>le.health.inflight--);const q=te.plain(c.headers),J=Y(q);if(!c.ok){const t=E??await I(c);return J.reply(c.status,q,t),m(c.status,t,q,o.state,"upstream_error")}if(o.state.stream){const t=_(J.raw(c.body),o.state),e=o.state.native?t:Se(u.meta.front,t,{gaps:i(()=>S(o),"gaps"),input:i(()=>A(o),"input"),report:i(a=>u.estimate(a),"report")});return{status:200,headers:Ee,stream:J.events(u.track(e,p.signal,U))}}const R=await I(c);if(J.reply(c.status,q,R),R===null||typeof R!="object")return h({type:"error",kind:"upstream",level:"error",message:`Upstream ${o.upstream} returned a body that is not JSON`,endpoint:o.upstream,model:o.body.model,status:502}),m(502,"The upstream returned a body that is not JSON",q,o.state,"error");const H=await $(R,o.state),D=await M(o,we(u.meta.front,H));return D&&(H.usage=ke(u.meta.front,H.usage,D),u.estimate(D)),u.json(H),u.finish("done"),{status:200,headers:{"content-type":"application/json"},body:H}}i(Ae,"round");function ie(n){return n.front==="anthropic"||n.responses?"openai":"folded"}i(ie,"usageShape");async function Q(n,r,w,d=null){let $,_=!1,T=w;if(d&&d.headersTimeout>0){const l=new AbortController;T=w?AbortSignal.any([w,l.signal]):l.signal,$=setTimeout(()=>{_=!0,l.abort()},d.headersTimeout)}try{return await n(r.url,{method:r.method,headers:r.headers,body:JSON.stringify(r.body),signal:T,redirect:"error",...d&&d.connectTimeout>0?{connectTimeout:d.connectTimeout}:{}})}catch(l){if(w?.aborted)throw l;const g=_?`no response headers within ${d.headersTimeout} ms`:l.message;throw new C(`Could not reach the upstream (${r.upstream}): ${g}`,{code:"upstream_unreachable",status:502,details:{cause:l}})}finally{clearTimeout($)}}i(Q,"call");async function I(n){const r=await n.text();try{return JSON.parse(r)}catch{return r===""?null:r}}i(I,"parse");export{Ue as send};
|
|
2
2
|
//# sourceMappingURL=send.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var k=Object.defineProperty;var n=(o,e)=>k(o,"name",{value:e,configurable:!0});import{context as f,self as s}from"../../lib/runtime.mjs";import{TranslatorError as u}from"../../lib/errors.mjs";import{register as q}from"../../lib/routes.mjs";import{capture as x}from"../../lib/capture.mjs";import{resolve as m}from"../../lib/route.mjs";import{resolve as h}from"../../lib/settings.mjs";import{emit as I}from"../../lib/events.mjs";async function N(o,e={}){const{config:r}=f;if(e.front!==void 0&&e.front!=="anthropic"&&e.front!=="openai")throw new u(`front must be "anthropic" or "openai" (got ${JSON.stringify(e.front)})`,{code:"invalid_config",status:500});for(const t of["authorize","onUsage"])if(e[t]!==void 0&&typeof e[t]!="function")throw new u(`${t} must be a function`,{code:"invalid_config",status:500});if(e.metrics!==void 0&&typeof e.metrics!="boolean")throw new u("metrics must be true or false",{code:"invalid_config",status:500});const{send:v,route:w,token:b,model:d,error:y,sse:l,embeddings:_}=s,g=e.front??r.front,{state:c}=f,{events:a}=c;a.logger=o.log,o.addHook("onClose",async()=>{a.logger===o.log&&(a.logger=null)});const i=x(s,f,g);q(o,e,{front:g,filter:r.settings.passthroughFilter!==!1,interval:n(t=>{try{return i.settings(m(i,t).endpoint).pingInterval}catch{return h(r.settings).pingInterval}},"interval"),settings:n(t=>{try{const p=m(i,t,{wire:"responses"});return i.settings(p.endpoint,p.protocol)}catch{return h(r.settings)}},"settings"),responses:{request:s.convert.openai.responses.to.openai.chat.request,response:s.convert.openai.chat.to.openai.responses.response,stream:s.convert.openai.chat.to.openai.responses.stream},send:v,embed:_.send,route:w,count:b.count,list:d.list,get:d.get,emit:n(t=>I({config:r,state:c},t),"emit"),endpoints:n(()=>c.endpoints,"endpoints"),build:y.build,encode:l.encode,write:l.write})}n(N,"plugin");export{N as plugin};
|
|
2
2
|
//# sourceMappingURL=plugin.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var g=Object.defineProperty;var i=(t,a)=>g(t,"name",{value:a,configurable:!0});import{context as b,self as u}from"../../lib/runtime.mjs";import{TranslatorError as d}from"../../lib/errors.mjs";import{isLoopback as L}from"../../lib/http.mjs";import{tlsOptions as $}from"../../lib/guard.mjs";async function k(t={}){const{state:a}=b,{plugin:h}=u.server,{build:f}=u.error;let c;try{({default:c}=await import("fastify"))}catch(o){throw new d('server.start needs the optional peer dependency "fastify" (npm install fastify)',{code:"fastify_missing",status:500,details:{cause:o}})}const s=await $(t.tls),e=t.host??"127.0.0.1";if(!L(e)&&[t.apiKey??[]].flat().filter(Boolean).length===0&&typeof t.authorize!="function"&&t.allowUnauthenticated!==!0)throw new d(`Refusing to listen on ${e} without an apiKey or an authorize hook: anyone who can reach the port could use the upstream. Set \`apiKey\` (CLI: --api-key) or \`authorize\`, bind to 127.0.0.1, or opt in with \`allowUnauthenticated: true\` (CLI: --allow-unauthenticated).`,{code:"unauthenticated_bind",status:500});const r=c({logger:t.logger??!1,forceCloseConnections:!0,...s?{https:s}:{}});r.setNotFoundHandler((o,m)=>{const{status:y,headers:p,body:w}=f(404,`Not found: ${o.method} ${o.url}`);return m.code(y).headers(p).send(w)}),await r.register(h,{front:t.front,apiKey:t.apiKey,bodyLimit:t.bodyLimit,authorize:t.authorize,onUsage:t.onUsage,metrics:t.metrics,cors:t.cors,rateLimit:t.rateLimit}),await r.listen({host:e,port:t.port??8787});const l=r.server.address().port,n={url:`${s?"https":"http"}://${e.includes(":")?`[${e}]`:e}:${l}`,host:e,port:l,app:r,close:i(async()=>{a.servers.delete(n),await r.close()},"close")};return a.servers.add(n),n}i(k,"start");export{k as start};
|
|
2
2
|
//# sourceMappingURL=start.mjs.map
|
package/dist/api/status.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var e=Object.defineProperty;var l=(s,a)=>e(s,"name",{value:a,configurable:!0});import{context as c}from"../lib/runtime.mjs";import{describe as m}from"../lib/pool.mjs";import{capture as t}from"../lib/capture.mjs";import{self as f}from"../lib/runtime.mjs";import{MESSAGES as u,RESPONSES as p,supported as v}from"../lib/protocol.mjs";function k(){const{config:s,state:a}=c,o=t(f,c);return{front:s.front,upstreams:a.endpoints.map(r=>({name:r.name,url:r.url,backend:r.backend,driver:r.driver,api:r.api,protocols:v(o.driver(r).info),protocol:o.plan(r).protocol,version:r.facts?.version??r.version,models:r.models??r.facts?.models??[],default:r.default,facts:r.facts,probed:r.probed,responses:o.plan(r,{wire:"responses"}).protocol===p,messages:r.driver==="vllm"?o.plan(r,{front:"anthropic"}).protocol===u:null,health:m(r)}))}}l(k,"status");export{k as status};
|
|
2
2
|
//# sourceMappingURL=status.mjs.map
|
package/dist/api/stream.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x=Object.defineProperty;var c=(e,o)=>x(e,"name",{value:o,configurable:!0});import{context as N,self as O}from"../lib/runtime.mjs";import{capture as S}from"../lib/capture.mjs";import{messages as v}from"../lib/sse.mjs";import*as b from"../lib/vllm.mjs";import{RESPONSES as j}from"../lib/protocol.mjs";function u(e,o){return!o||!e||typeof e!="object"?e:e.message&&typeof e.message=="object"&&e.message.model!==void 0?{...e,message:{...e.message,model:o}}:e.model===void 0?e:{...e,model:o}}c(u,"restore");function A(e){return!!e&&Array.isArray(e.choices)&&(e.choices.length===0||e.choices.some(o=>o?.finish_reason))}c(A,"ends");function R(e,o){const s=S(O,N,o.front),r=s.endpoint(o.upstream),l=s.driver(r),a=s.settings(r,s.protocol(r,o)),f=o.native?null:s.converters(o),t=s.protocol(r,o)===j?void 0:l.chunk,m={endpoint:r,settings:a,state:o};async function*d(){for(const n of await l.flush?.(m)??[])yield{data:n}}if(c(d,"flushed"),f&&!t)return f.stream(e,o.convert,a);if(f)return f.stream((async function*(){for await(const n of v(e))n.data!=="[DONE]"&&(yield await t(n.data,m));for await(const n of d())yield n.data})(),o.convert,a);const w=!!(t&&l.flush),p=(async function*(){const n=[];let y=!1;for await(const i of v(e)){if(i.data==="[DONE]"){for await(const E of d())yield{data:u(E.data,o.model)};yield*n.splice(0),y=!0,yield i;continue}const g=t?await t(i.data,m):i.data,h={...i,data:u(g,o.model)};w&&A(g)?n.push(h):yield h}if(!y){for await(const i of d())yield{data:u(i.data,o.model)};yield*n}})();return o.messages?b.stream(p):p}c(R,"stream");export{R as stream};
|
|
2
2
|
//# sourceMappingURL=stream.mjs.map
|
package/dist/api/token/count.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var u=Object.defineProperty;var
|
|
1
|
+
var u=Object.defineProperty;var s=(n,t)=>u(n,"name",{value:t,configurable:!0});import{context as p,self as a}from"../../lib/runtime.mjs";import{capture as m}from"../../lib/capture.mjs";import{estimate as f}from"../../lib/estimate.mjs";async function b(n,t={}){const e=m(a,p,t.front),{request:i}=a,o=await i(n,{front:t.front,tokens:!0}),r=e.endpoint(o.upstream),c=e.driver(r);return{input_tokens:(c.count?await c.count({endpoint:r,request:o.body,transport:e.state.transport,signal:t.signal,timeout:e.config.detectTimeout}):null)??f(o.body)}}s(b,"count");export{b as count};
|
|
2
2
|
//# sourceMappingURL=count.mjs.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var i=Object.defineProperty;var a=(r,e)=>i(r,"name",{value:e,configurable:!0});import{fileURLToPath as d}from"node:url";import p from"@cldmv/slothlet";import{normalize as c}from"./lib/config.mjs";import{load as l}from"./lib/pdf.mjs";import{transport as
|
|
1
|
+
var i=Object.defineProperty;var a=(r,e)=>i(r,"name",{value:e,configurable:!0});import{fileURLToPath as d}from"node:url";import p from"@cldmv/slothlet";import{normalize as c}from"./lib/config.mjs";import{load as l}from"./lib/pdf.mjs";import{transport as m}from"./lib/transport.mjs";import{create as f,open as u}from"./lib/events.mjs";import{warn as s}from"./lib/warn.mjs";async function w(r){const e=c(r),n={endpoints:e.endpoints,transport:e.transport??m,servers:new Set,warned:new Set,events:f(e.onEvent),textOnly:new Set,jsonInstruction:new Set,missing:new Map,cursors:new Map,front:void 0};u(n.events,e.logs);const t=await l();t.errors.canvas&&s(e,n,`@napi-rs/canvas could not be loaded (${t.errors.canvas}); PDFs will be read as text only, without page images`,{type:"detect",kind:"canvas",reason:String(t.errors.canvas)}),t.errors.unpdf&&s(e,n,`unpdf could not be loaded (${t.errors.unpdf}); PDF documents cannot be read and fall back to a note`,{type:"detect",kind:"unpdf",reason:String(t.errors.unpdf)});const o=await p({...r.slothlet,base:d(new URL("./api",import.meta.url)),mode:"eager",context:{config:e,state:n},silent:!0});return await o.detect({network:e.detect}),o}a(w,"createTranslator");import{TranslatorError as D}from"./lib/errors.mjs";var P=w;export{D as TranslatorError,w as createTranslator,P as default};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/lib/capture.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var C=Object.defineProperty;var n=(o,a)=>C(o,"name",{value:a,configurable:!0});import{resolve as A}from"./settings.mjs";import*as E from"./vllm.mjs";import{MESSAGES as h,CHAT as F,RESPONSES as R,OLLAMA as G,candidates as H,frontOf as N}from"./protocol.mjs";function z(o){const a=[];for(const c of Object.keys(o??{})){const e=o[c];typeof e?.info=="function"&&a.push({name:c,info:e.info(),detect:e.detect,settings:e.settings,probe:e.probe,path:e.path,request:e.request,response:e.response,chunk:e.chunk,flush:e.flush,error:e.error,count:e.token?.count,list:e.model?.list})}return a.sort((c,e)=>c.info.order-e.info.order)}n(z,"collect");function J(o,a,c){const{config:e,state:i}=a,p=o.convert.anthropic.messages.to.openai.chat,u=o.convert.openai.chat.to.anthropic.messages,k={anthropic:o.convert.anthropic.messages.to.ollama.chat,openai:o.convert.openai.chat.to.ollama.chat},v={anthropic:o.convert.ollama.chat.to.anthropic.messages,openai:o.convert.ollama.chat.to.openai.chat},s=c??e.front,m=z(o.driver),x=s==="anthropic"?h:F,L=s==="anthropic"?{request:p.request,response:u.response,stream:u.stream}:{request:u.request,response:p.response,stream:p.stream},M={request:k[s].request,response:v[s].response,stream:v[s].stream},g=s==="anthropic"?o.convert.openai.responses.to.anthropic.messages:o.convert.openai.responses.to.openai.chat,P={request:(s==="anthropic"?o.convert.anthropic.messages:o.convert.openai.chat).to.openai.responses.request,response:g.response,stream:g.stream},d=n(t=>t===G?M:t===x?null:t===R?P:L,"convertersFor"),q=n((t,r={})=>{const{info:b}=m.find(f=>f.name===t.driver),l=r.front??s,T=N(l,r.wire),S=r.body!==void 0&&t.driver==="vllm"?A(t.driverSettings,t.probed,e.settings,t.settings):null,j=n(f=>f!==h||b.protocol===h?!0:l!=="anthropic"||r.tokens===!0?!1:t.driver!=="vllm"?!0:S!==null&&E.unsuited(r.body,S)!==null?!1:t.api!=="auto"||E.eligible(t),"usable"),O=H({api:t.api,front:T,info:b,missing:i.missing.get(t.name),usable:j}),y=O[0],w=l===s;return{protocol:y,more:t.api==="auto"&&O.length>1,convert:w?d(y):void 0}},"plan");return{config:e,state:i,front:s,drivers:m,endpoint:n(t=>i.endpoints.find(r=>r.name===t),"endpoint"),protocol:n((t,r)=>r?.protocol??q(t).protocol,"protocol"),plan:q,driver:n(t=>m.find(r=>r.name===t.driver),"driver"),settings:n((t,r)=>A(r===R?{reasoningRoundTrip:!0}:void 0,t.driverSettings,t.probed,e.settings,t.settings),"settings"),converters:n(t=>d(t.protocol),"converters")}}n(J,"capture");export{J as capture,z as collect};
|
|
2
2
|
//# sourceMappingURL=capture.mjs.map
|