@cldmv/llm-translator 0.12.0 → 0.14.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 -8
- package/dist/api/convert/anthropic/messages/to/bedrock/converse/request.mjs +2 -0
- package/dist/api/convert/anthropic/messages/to/openai/responses/request.mjs +2 -0
- package/dist/api/convert/bedrock/converse/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/bedrock/converse/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/convert/bedrock/converse/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/bedrock/converse/to/openai/chat/stream.mjs +2 -0
- package/dist/api/convert/openai/chat/to/bedrock/converse/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/bedrock/detect.mjs +2 -0
- package/dist/api/driver/bedrock/info.mjs +2 -0
- package/dist/api/driver/bedrock/model/list.mjs +2 -0
- package/dist/api/driver/bedrock/path.mjs +2 -0
- package/dist/api/driver/bedrock/request.mjs +2 -0
- package/dist/api/driver/bedrock/sign.mjs +2 -0
- 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/vertex/auth.mjs +2 -0
- package/dist/api/driver/vertex/detect.mjs +2 -0
- package/dist/api/driver/vertex/error.mjs +2 -0
- package/dist/api/driver/vertex/info.mjs +2 -0
- package/dist/api/driver/vertex/path.mjs +2 -0
- package/dist/api/driver/vertex/request.mjs +2 -0
- package/dist/api/driver/vertex/settings.mjs +2 -0
- package/dist/api/driver/vertex/token/count.mjs +2 -0
- 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/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/bedrock.mjs +2 -0
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/config.mjs +1 -1
- package/dist/lib/converse.mjs +3 -0
- package/dist/lib/document-urls.mjs +2 -0
- package/dist/lib/documents.mjs +4 -4
- package/dist/lib/estimate.mjs +1 -1
- package/dist/lib/eventstream.mjs +2 -0
- package/dist/lib/fetch-url.mjs +2 -0
- package/dist/lib/google-auth.mjs +2 -0
- package/dist/lib/http.mjs +1 -1
- 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/sigv4.mjs +7 -0
- package/dist/lib/vertex.mjs +2 -0
- package/dist/lib/vllm.mjs +2 -2
- package/package.json +1 -1
- package/types/src/api/convert/anthropic/messages/to/bedrock/converse/request.d.mts +14 -0
- package/types/src/api/convert/anthropic/messages/to/openai/responses/request.d.mts +16 -0
- package/types/src/api/convert/bedrock/converse/to/anthropic/messages/response.d.mts +10 -0
- package/types/src/api/convert/bedrock/converse/to/anthropic/messages/stream.d.mts +14 -0
- package/types/src/api/convert/bedrock/converse/to/openai/chat/response.d.mts +10 -0
- package/types/src/api/convert/bedrock/converse/to/openai/chat/stream.d.mts +13 -0
- package/types/src/api/convert/openai/chat/to/bedrock/converse/request.d.mts +11 -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/bedrock/detect.d.mts +9 -0
- package/types/src/api/driver/bedrock/info.d.mts +36 -0
- package/types/src/api/driver/bedrock/model/list.d.mts +11 -0
- package/types/src/api/driver/bedrock/path.d.mts +9 -0
- package/types/src/api/driver/bedrock/request.d.mts +9 -0
- package/types/src/api/driver/bedrock/sign.d.mts +9 -0
- 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/vertex/auth.d.mts +7 -0
- package/types/src/api/driver/vertex/detect.d.mts +8 -0
- package/types/src/api/driver/vertex/error.d.mts +15 -0
- package/types/src/api/driver/vertex/info.d.mts +16 -0
- package/types/src/api/driver/vertex/path.d.mts +7 -0
- package/types/src/api/driver/vertex/request.d.mts +6 -0
- package/types/src/api/driver/vertex/settings.d.mts +23 -0
- package/types/src/api/driver/vertex/token/count.d.mts +7 -0
- 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 +1 -1
- package/types/src/api/status.d.mts +1 -1
- package/types/src/lib/bedrock.d.mts +74 -0
- package/types/src/lib/config.d.mts +35 -5
- package/types/src/lib/converse.d.mts +81 -0
- package/types/src/lib/document-urls.d.mts +55 -0
- package/types/src/lib/estimate.d.mts +1 -1
- package/types/src/lib/eventstream.d.mts +34 -0
- package/types/src/lib/fetch-url.d.mts +64 -0
- package/types/src/lib/google-auth.d.mts +58 -0
- package/types/src/lib/http.d.mts +5 -3
- package/types/src/lib/presets.d.mts +2 -1
- package/types/src/lib/protocol.d.mts +87 -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 +2 -1
- package/types/src/lib/settings.d.mts +19 -2
- package/types/src/lib/sigv4.d.mts +41 -0
- package/types/src/lib/vertex.d.mts +55 -0
- package/types/src/lib/vllm.d.mts +4 -4
package/README.md
CHANGED
|
@@ -17,18 +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.14.0 (November 2026)
|
|
21
21
|
|
|
22
|
-
- **
|
|
23
|
-
- **
|
|
24
|
-
- [View full v0.
|
|
22
|
+
- **Claude on Google Vertex AI and Amazon Bedrock** — new `vertex` and `bedrock` drivers. Vertex AI gets its access tokens from a service account, gcloud's credentials, a token or `getToken`, or the metadata server. Bedrock signs with SigV4 or uses a Bedrock API key, sends Claude through InvokeModel and other models through the new Converse protocol (`api: "converse"`), and decodes AWS's event stream. No new dependencies.
|
|
23
|
+
- **URL documents** — `documentUrls: { allow: [...] }` downloads `document` blocks with a `url` source and converts them like inline PDFs or text. Off by default, with host allow-listing, public-address checks pinned to the connection, re-checked redirects and size, time and count limits.
|
|
24
|
+
- [View full v0.14.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.14.0.md)
|
|
25
25
|
|
|
26
26
|
### Recent Releases
|
|
27
27
|
|
|
28
|
+
- **v0.13.0** (November 2026) — the OpenAI Responses API as a front and as an upstream, and one per-upstream `api` setting that defaults to `auto` ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.13.0.md))
|
|
29
|
+
- **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))
|
|
28
30
|
- **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
31
|
- **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
|
-
- **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
32
|
|
|
33
33
|
📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/llm-translator/tree/master/docs/changelog/) folder.**
|
|
34
34
|
|
|
@@ -88,7 +88,7 @@ import { createTranslator } from "@cldmv/llm-translator";
|
|
|
88
88
|
|
|
89
89
|
const api = await createTranslator({
|
|
90
90
|
front: "anthropic", // the protocol your client speaks
|
|
91
|
-
upstreams: ["http://gpu-box:8000"], // vLLM is detected automatically
|
|
91
|
+
upstreams: ["http://gpu-box:8000"], // vLLM is detected automatically; api defaults to "auto"
|
|
92
92
|
aliases: { "claude-opus-5-5": "qwen3-coder" }
|
|
93
93
|
});
|
|
94
94
|
|
|
@@ -127,7 +127,7 @@ Then point Claude Code at it with `ANTHROPIC_BASE_URL=http://127.0.0.1:8787`. Th
|
|
|
127
127
|
|
|
128
128
|
## 📚 Configuration
|
|
129
129
|
|
|
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: "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.
|
|
131
131
|
|
|
132
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).
|
|
133
133
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var i=(e,r)=>l(e,"name",{value:r,configurable:!0});import{resolve as g}from"../../../../../../../lib/settings.mjs";import{chatBody as p}from"../../../../../../../lib/converse.mjs";import{request as u}from"../../openai/chat/request.mjs";const f={maxTokensField:"max_tokens",thinking:"none",thinkingBudget:!1,effort:!1,topK:!0,prefill:"none",streamUsage:!1,continuousUsage:!1,reasoningRoundTrip:!1};async function y(e,r,s){const t=g(r),{body:a,state:n}=await u(e,{...t,...f},s),o=e.metadata?.sampling,d={...t.sampling,...o!==null&&typeof o=="object"&&!Array.isArray(o)?o:{}};return n.thinking!==null&&n.thinking!=="disabled"&&n.thinkingBudget===void 0&&n.dropped.push("thinking"),{body:p(a,{dropped:n.dropped,sampling:d,thinkingBudget:n.thinkingBudget,marker:t.toolErrors?t.toolErrorMarker:void 0}),state:n}}i(y,"request");export{y as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -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 e=(o,r)=>m(o,"name",{value:r,configurable:!0});import{completion as n}from"../../../../../../../lib/converse.mjs";import{response as p}from"../../../../../openai/chat/to/anthropic/messages/response.mjs";function a(o,r,t){return p(n(o),r,t)}e(a,"response");export{a as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var i=Object.defineProperty;var n=(e,r)=>i(e,"name",{value:r,configurable:!0});import{resolve as m}from"../../../../../../../lib/settings.mjs";import{createChunker as s}from"../../../../../../../lib/converse.mjs";import{messages as f}from"../../../../../../../lib/sse.mjs";import{stream as c}from"../../../../../openai/chat/to/anthropic/messages/stream.mjs";function g(e,r,o){const t=s({reasoningField:m(o).reasoningField});return c((async function*(){for await(const a of f(e))yield*t.event(a.event,a.data);t.finished()&&(yield{data:"[DONE]"})})(),r,o)}n(g,"stream");export{g as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=Object.defineProperty;var r=(e,o)=>m(e,"name",{value:o,configurable:!0});import{resolve as s}from"../../../../../../../lib/settings.mjs";import{completion as d,folded as l}from"../../../../../../../lib/converse.mjs";function u(e,o,n){const i=d(e,{reasoningField:s(n).reasoningField,model:o?.model});return o&&(o.upstreamUsage=l(e.usage)),i}r(u,"response");export{u as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var i=(o,r)=>l(o,"name",{value:r,configurable:!0});import{resolve as c}from"../../../../../../../lib/settings.mjs";import{createChunker as m,folded as u}from"../../../../../../../lib/converse.mjs";import{messages as f}from"../../../../../../../lib/sse.mjs";async function*k(o,r,s){const a=m({model:r?.model,reasoningField:c(s).reasoningField,includeUsage:r?.includeUsage??!0}),d=i((e,n="api_error")=>({data:{error:{message:e,type:n,param:null,code:null}}}),"failure");try{for await(const e of f(o)){const n=a.event(e.event,e.data);r&&a.usage()!==void 0&&(r.upstreamUsage=u(a.usage()));for(const t of n)if(yield{data:t},t.error){yield{data:"[DONE]"};return}}}catch(e){yield d(e.message,e.type??"api_error"),yield{data:"[DONE]"};return}a.finished()||(yield d("Upstream stream ended before completion")),yield{data:"[DONE]"}}i(k,"stream");export{k as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var t=(r,e)=>a(r,"name",{value:e,configurable:!0});import{resolve as m}from"../../../../../../../lib/settings.mjs";import{TranslatorError as n}from"../../../../../../../lib/errors.mjs";import{chatBody as i}from"../../../../../../../lib/converse.mjs";function c(r,e){const o=m(e);if(r===null||typeof r!="object"||!Array.isArray(r.messages))throw new n("messages: Field required",{code:"invalid_request",param:"messages"});const s={front:"openai",model:r.model,stream:r.stream===!0,toolNames:{},toolIds:{},dropped:[],includeUsage:r.stream_options?.include_usage===!0};return{body:i(r,{dropped:s.dropped,sampling:o.sampling,marker:o.toolErrors?o.toolErrorMarker:void 0}),state:s}}t(c,"request");export{c 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
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.defineProperty;var t=(n,o)=>e(n,"name",{value:o,configurable:!0});import{regionOfHost as l}from"../../../lib/bedrock.mjs";function c({endpoint:n}){const o=URL.canParse(n.url)?new URL(n.url).hostname:"",r=l(o);return r===null?null:{host:o,region:r}}t(c,"detect");export{c as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var e=(o,a)=>r(o,"name",{value:a,configurable:!0});function t(){return{name:"bedrock",protocol:"anthropic.messages",protocols:["anthropic.messages","bedrock.converse"],order:33,auth:"bearer",strict:!1,frames:"eventstream",hostSuffixes:[".amazonaws.com",".amazonaws.com.cn"],paths:{}}}e(t,"info");export{t as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=Object.defineProperty;var i=(r,e)=>m(r,"name",{value:e,configurable:!0});import*as s from"../../../../lib/http.mjs";import{authenticate as u}from"../../../../lib/bedrock.mjs";function c(r){const e=new URL(r);return e.hostname=e.hostname.replace(/(^|\.)bedrock-runtime/,"$1bedrock"),`${e.origin}${e.pathname.replace(/\/$/,"")}/foundation-models`}i(c,"listUrl");async function f({endpoint:r,transport:e,signal:n,timeout:d}){let o,l;try{o=c(r.url),l=u(r,{method:"GET",url:o,headers:{accept:"application/json"},body:""})}catch{return null}const a=await s.json(e,o,{method:"GET",headers:l,signal:n,timeout:d});return!a.ok||!Array.isArray(a.body?.modelSummaries)?null:a.body.modelSummaries.filter(t=>typeof t?.modelId=="string"&&(t.outputModalities??["TEXT"]).includes("TEXT")).map(t=>({id:t.modelId,owned_by:t.providerName??"bedrock"}))}i(f,"list");export{f as list};
|
|
2
|
+
//# sourceMappingURL=list.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var s=(e,r)=>t(e,"name",{value:r,configurable:!0});import{TranslatorError as a}from"../../../lib/errors.mjs";import{modelPath as n}from"../../../lib/bedrock.mjs";function c(e,{model:r,stream:o}){if(e==="messages")return`${n(r)}/${o?"invoke-with-response-stream":"invoke"}`;if(e==="converse")return`${n(r)}/${o?"converse-stream":"converse"}`;throw new a(`The bedrock driver has no ${e} call; it serves Anthropic Messages (InvokeModel) and Converse`,{code:"unsupported_endpoint",status:501})}s(c,"path");export{c as path};
|
|
2
|
+
//# sourceMappingURL=path.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var r=(e,o)=>c(e,"name",{value:o,configurable:!0});const n=["model","stream","metadata","service_tier","container","mcp_servers"],a="bedrock-2023-05-31";function d(e,o){const t={...e};for(const s of n)delete t[s];return o?.protocol==="anthropic.messages"?{anthropic_version:a,...t}:t}r(d,"request");export{d as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var a=(t,n)=>c(t,"name",{value:n,configurable:!0});import{authenticate as p}from"../../../lib/bedrock.mjs";const s="application/vnd.amazon.eventstream";function f({endpoint:t,method:n,url:e,headers:i,body:o,stream:r}){return p(t,{method:n,url:e,headers:{...i,accept:r?s:"application/json"},body:JSON.stringify(o)})}a(f,"sign");export{f as sign};
|
|
2
|
+
//# sourceMappingURL=sign.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
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var r=(e,t)=>s(e,"name",{value:t,configurable:!0});import{token as c}from"../../../lib/google-auth.mjs";async function h({endpoint:e,headers:t,transport:a,timeout:i}){const{"x-api-key":_,"anthropic-version":p,...o}=t,n=await c({settings:e.vertex,apiKey:e.apiKey,transport:a,timeout:i});return{...o,authorization:`Bearer ${n}`}}r(h,"auth");export{h as auth};
|
|
2
|
+
//# sourceMappingURL=auth.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=Object.defineProperty;var o=(t,s)=>u(t,"name",{value:s,configurable:!0});import{info as c}from"./info.mjs";function i({endpoint:t}){const s=URL.canParse(t.url)?new URL(t.url).hostname:"",{hosts:e,hostSuffixes:n}=c();return e.includes(s)||n.some(r=>s.endsWith(r))?{host:s}:null}o(i,"detect");export{i as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var o=(e,r)=>n(e,"name",{value:r,configurable:!0});import*as p from"../../../lib/upstream-error.mjs";function m(e,r){const t=Array.isArray(r)?r[0]:r,s=p.parse(t,e),a=typeof t?.error?.status=="string"?t.error.status:s.code;return{error:{message:s.message,type:s.type,param:s.param??null,code:a??e}}}o(m,"error");export{m as error};
|
|
2
|
+
//# sourceMappingURL=error.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.defineProperty;var o=(r,t)=>e(r,"name",{value:t,configurable:!0});import{HOSTS as s}from"../../../lib/vertex.mjs";function p(){return{name:"vertex",protocol:"anthropic.messages",protocols:["anthropic.messages"],order:39,auth:"bearer",strict:!1,hosts:s,hostSuffixes:["-aiplatform.googleapis.com"],paths:{}}}o(p,"info");export{p as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=Object.defineProperty;var i=(o,t)=>u(o,"name",{value:t,configurable:!0});import*as m from"../../../../lib/http.mjs";import{token as l}from"../../../../lib/google-auth.mjs";import{route as f}from"../../../../lib/vertex.mjs";const y=["messages","system","tools","tool_choice","thinking","mcp_servers","context_management"];async function k({endpoint:o,request:t,transport:s,signal:r,timeout:c}){const a={model:t.model};for(const e of y)t[e]!==void 0&&(a[e]=t[e]);try{const e=await l({settings:o.vertex,apiKey:o.apiKey,transport:s,timeout:c,signal:r}),n=await m.json(s,m.join(o.url,f("count",o)),{method:"POST",headers:{"content-type":"application/json",...o.headers,authorization:`Bearer ${e}`},body:a,signal:r,timeout:c});return n.ok&&typeof n.body?.input_tokens=="number"?n.body.input_tokens:null}catch{return null}}i(k,"count");export{k as count};
|
|
2
|
+
//# sourceMappingURL=count.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
|
-
${
|
|
1
|
+
var N=Object.defineProperty;var h=(e,n)=>N(e,"name",{value:n,configurable:!0});import{context as H,self as V}from"../lib/runtime.mjs";import{capture as z}from"../lib/capture.mjs";import{resolve as A}from"../lib/route.mjs";import*as U from"../lib/http.mjs";import{filterChatBody as D}from"../lib/passthrough.mjs";import{addSampling as G}from"../lib/sampling.mjs";import{addConstraint as J}from"../lib/constraint.mjs";import{addCache as Q}from"../lib/cache.mjs";import*as q from"../lib/images.mjs";import*as I from"../lib/tools.mjs";import{LIMITS as W}from"../lib/toolsearch.mjs";import{warn as _}from"../lib/warn.mjs";import{emit as P}from"../lib/events.mjs";import{fit as X,pinBody as Y}from"../lib/effort.mjs";import{relax as Z,strictTools as ee}from"../lib/strict.mjs";import{TranslatorError as te}from"../lib/errors.mjs";import*as ne from"../lib/vllm.mjs";import*as R from"../lib/document-urls.mjs";import{PROTOCOL as O}from"../lib/responses-upstream.mjs";import{CONVERSE as re}from"../lib/protocol.mjs";function ae(e,n){return`${e.driver}:${n}:${URL.canParse(e.url)?new URL(e.url).host:e.url}`}h(ae,"producerOf");async function $e(e,n={}){const a=z(V,H,n.front),u=A(a,e,{endpoint:n.endpoint,wire:n.wire,tokens:n.tokens,advance:n.hold===!0&&n.endpoint===void 0});if(n.hold!==!0)return L(a,e,n,u);u.endpoint.health.inflight++;try{return await L(a,e,n,u)}catch(r){throw u.endpoint.health.inflight--,r}}h($e,"request");function oe(e,n,a,u,r,f){const k=ee(n);if(k.length===0)return n;const m=k.filter(d=>d.problems.length>0);if(m.length>0&&r.unknownFields==="error")throw new te(`tools: ${m[0].name}: schema is outside the strict subset (${m[0].problems.join("; ")})`,{code:"unsupported_content",param:"tools"});const j=Z(n);if(f.retry===!0)return j;const g=h((d,l)=>_(e.config,e.state,d,{kind:l,endpoint:a.name,log:f.log}),"tell");for(const d of m)g(`Upstream ${a.name}: strict tool ${d.name} has a schema outside the strict subset: ${d.problems.join("; ")} (sent without strict)`,"strict");const s=k.filter(d=>d.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(d=>d.name).join(", ")})`,"strict"),j}h(oe,"checkStrict");async function L(e,n,a,u){const{endpoint:r,model:f,unserved:k,convert:m,pool:j,pin:g,protocol:s}=u,d=Object.hasOwn(e.config.efforts,f)?e.config.efforts[f]:void 0;g&&(n=Y(n,g,e.front));const l=e.driver(r),T=e.front==="anthropic"?n.metadata?.prompt_cache_key:void 0;let S=e.front==="anthropic"?n.metadata?.constraint:void 0;e.front==="openai"&&n.constraint!==void 0&&({constraint:S,...n}=n);const $=`${r.name}
|
|
2
|
+
${f}`,C=a.images===!1||e.state.textOnly.has($)&&e.settings(r,s).imageFallback,b=e.settings(r,s),M=a.jsonObject==="instruction"||e.state.jsonInstruction.has($)&&b.jsonObjectFallback,c={...C?{...b,images:!1}:b,...M?{jsonObject:"instruction"}:{},...g?.effort===void 0?{}:{effort:!0}},v=n.stream===!0,y=s==="anthropic.messages"&&m===null&&l.info.protocol!=="anthropic.messages";m&&e.front==="anthropic"&&R.wanted(c)&&(n=await R.resolve(n,{options:c.documentUrls,signal:a.signal,report:h(i=>P(e,{type:"document",...i,endpoint:r.name,model:f,log:a.log}),"report")}));let t,o;m?({body:t,state:o}=await m.request(n,c,{producer:ae(r,s),budget:a.budget,listed:d!==void 0,toolCallIds:l.info.toolCallIds}),o.toolSearch?.capped&&_(e.config,e.state,`Tool search: more than ${W.definitions} tool definitions came back in ToolSearch results for ${r.name}; the rest are not offered.`,{kind:"toolsearch",endpoint:r.name,log:a.log})):y?t=ne.request(n,c):t=e.front==="openai"&&(a.filter??c.passthroughFilter===!0)?D(n,l.info.fields):{...n};const F=e.front==="anthropic"?n.metadata?.sampling:void 0;if(s==="openai.chat"){const i=[];t=G(t,F,c,l.info.fields,i),o&&o.dropped.push(...i.filter(p=>!o.dropped.includes(p)))}else if(!m&&F!==void 0&&t.metadata?.sampling!==void 0){const{sampling:i,...p}=t.metadata;t={...t,metadata:p}}if(s==="openai.chat"){const i=[],p={name:l.info.name,version:r.facts?.version??r.version};t=J(t,S,c,p,i),t=Q(t,{salt:a.cacheSalt,key:T},c,p.name,i),o&&o.dropped.push(...i.filter(K=>!o.dropped.includes(K)))}else{if(o&&!o.dropped.includes("cache_salt")&&(a.cacheSalt??c.cacheSalt)!=null&&o.dropped.push("cache_salt"),o&&!o.dropped.includes("prompt_cache_key")&&(T??c.promptCacheKey)!=null&&o.dropped.push("prompt_cache_key"),!m&&t.metadata?.prompt_cache_key!==void 0){const{prompt_cache_key:i,...p}=t.metadata;t={...t,metadata:p}}if(o&&(S??c.constraint)!=null&&!o.dropped.includes("constraint")&&o.dropped.push("constraint"),!m&&t.metadata?.constraint!==void 0){const{constraint:i,...p}=t.metadata;t={...t,metadata:p}}}if(a.usage===!0&&v&&e.front==="openai"){if(m)o.includeUsage=!0;else if(c.streamUsage){const i=t.stream_options&&typeof t.stream_options=="object"?t.stream_options:{};t.stream_options={...i,include_usage:!0}}}C&&!m&&e.front==="openai"&&(t=q.strip(t)),a.tools===!1&&(t=I.strip(t)),t.model=f,t=oe(e,t,r,l,c,a),d&&s==="openai.chat"&&X(t,d,f,(i,p)=>_(e.config,e.state,i,{type:"effort",endpoint:r.name,model:f,...p,log:a.log})),o?.reasoningMissing&&s!==O&&_(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}),l.request&&!y&&s!==O&&(t=await l.request(t,{endpoint:r,settings:c,levels:d,protocol:s,state:o,warn:h(i=>_(e.config,e.state,i,{kind:"driver",endpoint:r.name,log:a.log}),"warn")})),o?.dropped?.length>0&&a.retry!==!0&&P(e,{type:"dropped",level:"debug",message:`Upstream ${r.name}: dropped ${o.dropped.join(", ")}`,endpoint:r.name,model:f,fields:[...o.dropped],log:a.log});const B=s==="anthropic.messages"?"messages":s===O?"responses":s===re?"converse":"chat",x=await U.pathOf(l,B,r,f,s,v),E=U.join(r.url,x);let w={"content-type":"application/json",accept:v?"text/event-stream":"application/json",...l.info.headers,...m===null&&r.protocol==="anthropic.messages"?a.clientHeaders:void 0,...U.headers(r,l.info.auth,a.headers)};return l.auth&&a.tokens!==!0&&(w=await l.auth({endpoint:r,headers:w,transport:e.state.transport,timeout:e.config.detectTimeout})),l.sign&&(w=await l.sign({endpoint:r,protocol:s,method:"POST",url:E,headers:w,body:t,stream:v})),{upstream:r.name,pool:j.map(i=>i.name),method:"POST",url:E,path:x,headers:w,body:t,state:{v:1,upstream:r.name,front:e.front,native:m===null,protocol:s,messages:y,responses:s===O,model:n.model,stream:v,unserved:k,convert:o},more:u.more,images:{sent:q.carries(t),retry:c.imageFallback&&s==="openai.chat",key:$},tools:{sent:I.carries(t),retry:c.toolFallback&&s==="openai.chat"},json:{sent:o?.jsonSchemaEmulated===!0,retry:c.jsonObjectFallback&&s==="anthropic.messages",key:$}}}h(L,"prepare");export{$e 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,signal:p.signal,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
|