@cldmv/llm-translator 0.1.0 → 0.3.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 +182 -7
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +17 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +2 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +6 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/detect.mjs +2 -0
- package/dist/api/driver/anthropic/detect.mjs +2 -0
- package/dist/api/driver/anthropic/info.mjs +2 -0
- package/dist/api/driver/anthropic/model/list.mjs +2 -0
- package/dist/api/driver/anthropic/settings.mjs +2 -0
- package/dist/api/driver/anthropic/token/count.mjs +2 -0
- package/dist/api/driver/compatible/detect.mjs +2 -0
- package/dist/api/driver/compatible/info.mjs +2 -0
- package/dist/api/driver/compatible/model/list.mjs +2 -0
- package/dist/api/driver/compatible/request.mjs +2 -0
- package/dist/api/driver/compatible/settings.mjs +2 -0
- package/dist/api/driver/deepseek/detect.mjs +2 -0
- package/dist/api/driver/deepseek/error.mjs +2 -0
- package/dist/api/driver/deepseek/info.mjs +2 -0
- package/dist/api/driver/deepseek/request.mjs +2 -0
- package/dist/api/driver/deepseek/settings.mjs +2 -0
- package/dist/api/driver/llamacpp/chunk.mjs +2 -0
- package/dist/api/driver/llamacpp/detect.mjs +2 -0
- package/dist/api/driver/llamacpp/flush.mjs +2 -0
- package/dist/api/driver/llamacpp/info.mjs +2 -0
- package/dist/api/driver/llamacpp/request.mjs +2 -0
- package/dist/api/driver/llamacpp/response.mjs +2 -0
- package/dist/api/driver/llamacpp/settings.mjs +2 -0
- package/dist/api/driver/ollama/detect.mjs +2 -0
- package/dist/api/driver/ollama/info.mjs +2 -0
- package/dist/api/driver/ollama/request.mjs +2 -0
- package/dist/api/driver/ollama/settings.mjs +2 -0
- package/dist/api/driver/openai/detect.mjs +2 -0
- package/dist/api/driver/openai/info.mjs +2 -0
- package/dist/api/driver/openai/model/list.mjs +2 -0
- package/dist/api/driver/openai/request.mjs +2 -0
- package/dist/api/driver/openai/settings.mjs +2 -0
- package/dist/api/driver/sglang/detect.mjs +2 -0
- package/dist/api/driver/sglang/info.mjs +2 -0
- package/dist/api/driver/sglang/request.mjs +2 -0
- package/dist/api/driver/sglang/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +2 -0
- package/dist/api/driver/vllm/error.mjs +2 -0
- package/dist/api/driver/vllm/info.mjs +2 -0
- package/dist/api/driver/vllm/model/list.mjs +2 -0
- package/dist/api/driver/vllm/probe.mjs +2 -0
- package/dist/api/driver/vllm/request.mjs +2 -0
- package/dist/api/driver/vllm/settings.mjs +2 -0
- package/dist/api/driver/vllm/token/count.mjs +2 -0
- package/dist/api/endpoint/status.mjs +2 -0
- package/dist/api/error/build.mjs +2 -0
- package/dist/api/error/error.mjs +2 -0
- package/dist/api/model/get.mjs +2 -0
- package/dist/api/model/list.mjs +2 -0
- package/dist/api/request.mjs +3 -0
- package/dist/api/response.mjs +2 -0
- package/dist/api/route.mjs +2 -0
- package/dist/api/send.mjs +2 -0
- package/dist/api/server/plugin.mjs +2 -0
- package/dist/api/server/start.mjs +2 -0
- package/dist/api/server/stop.mjs +2 -0
- package/dist/api/sse/encode.mjs +4 -0
- package/dist/api/sse/parse.mjs +2 -0
- package/dist/api/sse/ping.mjs +2 -0
- package/dist/api/sse/write.mjs +2 -0
- package/dist/api/status.mjs +2 -0
- package/dist/api/stream.mjs +2 -0
- package/dist/api/token/count.mjs +2 -0
- package/dist/bin/llm-translator.mjs +3 -0
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +1 -1
- package/dist/lib/arguments.mjs +2 -0
- package/dist/lib/backends.mjs +2 -0
- package/dist/lib/capture.mjs +2 -0
- package/dist/lib/cli.mjs +29 -0
- package/dist/lib/config.mjs +2 -0
- package/dist/lib/documents.mjs +12 -0
- package/dist/lib/errors.mjs +2 -0
- package/dist/lib/estimate.mjs +2 -0
- package/dist/lib/finish.mjs +2 -0
- package/dist/lib/http.mjs +2 -0
- package/dist/lib/ids.mjs +2 -0
- package/dist/lib/images.mjs +2 -0
- package/dist/lib/models.mjs +2 -0
- package/dist/lib/normalize.mjs +2 -0
- package/dist/lib/passthrough.mjs +2 -0
- package/dist/lib/pdf.mjs +2 -0
- package/dist/lib/ping.mjs +2 -0
- package/dist/lib/pool.mjs +2 -0
- package/dist/lib/route.mjs +2 -0
- package/dist/lib/routes.mjs +2 -0
- package/dist/lib/runtime.mjs +2 -0
- package/dist/lib/schema.mjs +2 -0
- package/dist/lib/settings.mjs +2 -0
- package/dist/lib/source.mjs +2 -0
- package/dist/lib/sse.mjs +10 -0
- package/dist/lib/thinking.mjs +3 -0
- package/dist/lib/tools.mjs +2 -0
- package/dist/lib/toolsearch.mjs +3 -0
- package/dist/lib/transport.mjs +2 -0
- package/dist/lib/upstream-error.mjs +2 -0
- package/dist/lib/usage.mjs +2 -0
- package/dist/lib/warn.mjs +2 -0
- package/package.json +40 -9
- package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +19 -0
- package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +11 -0
- package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +15 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +16 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +14 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +24 -0
- package/types/src/api/detect.d.mts +7 -0
- package/types/src/api/driver/anthropic/detect.d.mts +26 -0
- package/types/src/api/driver/anthropic/info.d.mts +30 -0
- package/types/src/api/driver/anthropic/model/list.d.mts +6 -0
- package/types/src/api/driver/anthropic/settings.d.mts +23 -0
- package/types/src/api/driver/anthropic/token/count.d.mts +6 -0
- package/types/src/api/driver/compatible/detect.d.mts +9 -0
- package/types/src/api/driver/compatible/info.d.mts +12 -0
- package/types/src/api/driver/compatible/model/list.d.mts +6 -0
- package/types/src/api/driver/compatible/request.d.mts +6 -0
- package/types/src/api/driver/compatible/settings.d.mts +23 -0
- package/types/src/api/driver/deepseek/detect.d.mts +26 -0
- package/types/src/api/driver/deepseek/error.d.mts +14 -0
- package/types/src/api/driver/deepseek/info.d.mts +29 -0
- package/types/src/api/driver/deepseek/request.d.mts +8 -0
- package/types/src/api/driver/deepseek/settings.d.mts +25 -0
- package/types/src/api/driver/llamacpp/chunk.d.mts +7 -0
- package/types/src/api/driver/llamacpp/detect.d.mts +6 -0
- package/types/src/api/driver/llamacpp/flush.d.mts +26 -0
- package/types/src/api/driver/llamacpp/info.d.mts +31 -0
- package/types/src/api/driver/llamacpp/request.d.mts +8 -0
- package/types/src/api/driver/llamacpp/response.d.mts +8 -0
- package/types/src/api/driver/llamacpp/settings.d.mts +27 -0
- package/types/src/api/driver/ollama/detect.d.mts +6 -0
- package/types/src/api/driver/ollama/info.d.mts +30 -0
- package/types/src/api/driver/ollama/request.d.mts +8 -0
- package/types/src/api/driver/ollama/settings.d.mts +7 -0
- package/types/src/api/driver/openai/detect.d.mts +26 -0
- package/types/src/api/driver/openai/info.d.mts +29 -0
- package/types/src/api/driver/openai/model/list.d.mts +6 -0
- package/types/src/api/driver/openai/request.d.mts +6 -0
- package/types/src/api/driver/openai/settings.d.mts +23 -0
- package/types/src/api/driver/sglang/detect.d.mts +6 -0
- package/types/src/api/driver/sglang/info.d.mts +31 -0
- package/types/src/api/driver/sglang/request.d.mts +8 -0
- package/types/src/api/driver/sglang/settings.d.mts +24 -0
- package/types/src/api/driver/vllm/detect.d.mts +6 -0
- package/types/src/api/driver/vllm/error.d.mts +14 -0
- package/types/src/api/driver/vllm/info.d.mts +12 -0
- package/types/src/api/driver/vllm/model/list.d.mts +6 -0
- package/types/src/api/driver/vllm/probe.d.mts +25 -0
- package/types/src/api/driver/vllm/request.d.mts +8 -0
- package/types/src/api/driver/vllm/settings.d.mts +8 -0
- package/types/src/api/driver/vllm/token/count.d.mts +6 -0
- package/types/src/api/endpoint/status.d.mts +27 -0
- package/types/src/api/error/build.d.mts +12 -0
- package/types/src/api/error/error.d.mts +15 -0
- package/types/src/api/model/get.d.mts +9 -0
- package/types/src/api/model/list.d.mts +7 -0
- package/types/src/api/request.d.mts +26 -0
- package/types/src/api/response.d.mts +8 -0
- package/types/src/api/route.d.mts +18 -0
- package/types/src/api/send.d.mts +37 -0
- package/types/src/api/server/plugin.d.mts +11 -0
- package/types/src/api/server/start.d.mts +12 -0
- package/types/src/api/server/stop.d.mts +5 -0
- package/types/src/api/sse/encode.d.mts +12 -0
- package/types/src/api/sse/parse.d.mts +10 -0
- package/types/src/api/sse/ping.d.mts +16 -0
- package/types/src/api/sse/write.d.mts +12 -0
- package/types/src/api/status.d.mts +8 -0
- package/types/src/api/stream.d.mts +11 -0
- package/types/src/api/token/count.d.mts +10 -0
- package/types/src/index.d.mts +62 -15
- package/types/src/lib/arguments.d.mts +16 -0
- package/types/src/lib/backends.d.mts +21 -0
- package/types/src/lib/capture.d.mts +14 -0
- package/types/src/lib/cli.d.mts +35 -0
- package/types/src/lib/config.d.mts +51 -0
- package/types/src/lib/documents.d.mts +32 -0
- package/types/src/lib/errors.d.mts +144 -0
- package/types/src/lib/estimate.d.mts +75 -0
- package/types/src/lib/finish.d.mts +73 -0
- package/types/src/lib/http.d.mts +72 -0
- package/types/src/lib/ids.d.mts +46 -0
- package/types/src/lib/images.d.mts +39 -0
- package/types/src/lib/models.d.mts +25 -0
- package/types/src/lib/normalize.d.mts +37 -0
- package/types/src/lib/passthrough.d.mts +16 -0
- package/types/src/lib/pdf.d.mts +53 -0
- package/types/src/lib/ping.d.mts +10 -0
- package/types/src/lib/pool.d.mts +124 -0
- package/types/src/lib/route.d.mts +45 -0
- package/types/src/lib/routes.d.mts +17 -0
- package/types/src/lib/runtime.d.mts +10 -0
- package/types/src/lib/schema.d.mts +8 -0
- package/types/src/lib/settings.d.mts +189 -0
- package/types/src/lib/source.d.mts +32 -0
- package/types/src/lib/sse.d.mts +61 -0
- package/types/src/lib/thinking.d.mts +155 -0
- package/types/src/lib/tools.d.mts +28 -0
- package/types/src/lib/toolsearch.d.mts +91 -0
- package/types/src/lib/transport.d.mts +18 -0
- package/types/src/lib/upstream-error.d.mts +43 -0
- package/types/src/lib/usage.d.mts +91 -0
- package/types/src/lib/warn.d.mts +26 -0
package/README.md
CHANGED
|
@@ -1,17 +1,192 @@
|
|
|
1
1
|
# @cldmv/llm-translator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bidirectional **Anthropic Messages ⇄ OpenAI Chat Completions** translator built on [slothlet](https://github.com/CLDMV/slothlet). It detects the backend behind an upstream (vLLM first, then any OpenAI-compatible server), converts requests, responses and streams in both directions, and ships an optional standalone server and CLI so Claude Code can run against local models.
|
|
4
|
+
|
|
5
|
+
Use it as a library when you want the conversion without any I/O (`request`, `response` and `stream` take plain objects), as a full round trip (`send`), or as a server that speaks the Anthropic or the OpenAI protocol to your clients.
|
|
6
|
+
|
|
7
|
+
> _Point Claude Code at a model running on your own GPU._
|
|
8
|
+
|
|
9
|
+
[![npm version]][npm_version_url] [![npm downloads]][npm_downloads_url] [![GitHub downloads]][github_downloads_url] [![Last commit]][last_commit_url] [![npm last update]][npm_last_update_url] [![coverage]][coverage_url]
|
|
4
10
|
|
|
5
11
|
> [!NOTE]
|
|
6
|
-
>
|
|
12
|
+
> **Status: 0.x.** Validated end to end for Claude Code (print mode) through the translator to vLLM. Other backends, model families and clients are covered by unit tests only and are tracked in the [Real-backend validation epic](https://github.com/CLDMV/llm-translator/issues/62). The API may change between minor versions.
|
|
13
|
+
|
|
14
|
+
[![Contributors]][contributors_url] [![Sponsor shinrai]][sponsor_url]
|
|
15
|
+
|
|
16
|
+
---
|
|
7
17
|
|
|
8
18
|
## ✨ What's New
|
|
9
19
|
|
|
10
|
-
### Latest: v0.
|
|
20
|
+
### Latest: v0.3.0 (November 2026)
|
|
21
|
+
|
|
22
|
+
- **Usage reporting, `route()` and the server `authorize` hook** — every `send()` reply has a `usage` promise (and an `onUsage` callback) with the final token counts; `api.route(body)` says which upstream and model a request would use; `server.start` and `server.plugin` take `authorize(request)` and `onUsage(report, context)` so an app with its own key system can gate and meter requests.
|
|
23
|
+
- **More servers and endpoint pools** — drivers for llama.cpp, Ollama, SGLang and the DeepSeek API, failover and load balancing between upstreams that serve the same model, the `reasoningRoundTrip` and `toolSearch` settings, estimated usage when an upstream sends none, and `GET /v1/models/{id}`. Requires Node.js 24 or newer.
|
|
24
|
+
- [View full v0.3.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.3.0.md)
|
|
25
|
+
|
|
26
|
+
### Recent Releases
|
|
27
|
+
|
|
28
|
+
- **v0.2.0** (October 2026) — the first working translator: six Anthropic Messages and OpenAI Chat Completions converters, backend detection (vLLM, OpenAI, Anthropic, generic), model aliases, the optional Fastify server and the `llm-translator` CLI for Claude Code ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.2.0.md))
|
|
29
|
+
- **v0.1.0** (October 2026) — package scaffold: ESM and CommonJS entry points, tsup build, the `llm-translator-dev` condition with devcheck, tests on `@cldmv/vitest-runner` and the CLDMV v4 CI/release pipeline; the only export was a placeholder ([Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.1.0.md))
|
|
30
|
+
|
|
31
|
+
📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/llm-translator/tree/master/docs/changelog/) folder.**
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 🚀 Key Features
|
|
36
|
+
|
|
37
|
+
### 🔁 **Both Directions**
|
|
38
|
+
|
|
39
|
+
Anthropic clients (Claude Code, the Anthropic SDKs) talk to OpenAI-compatible servers, and OpenAI clients talk to Anthropic upstreams. Requests, responses, streams, tool calls, usage, stop reasons and errors are converted; same-protocol traffic is forwarded without conversion.
|
|
40
|
+
|
|
41
|
+
### 🔎 **Backend Detection**
|
|
42
|
+
|
|
43
|
+
Each upstream is probed once and bound to a driver. The vLLM driver maps the server version to the right settings, checks whether the chat template accepts mid-conversation system messages and whether the model accepts images. See [docs/drivers.md](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md).
|
|
44
|
+
|
|
45
|
+
### 🧠 **Reasoning and Tools**
|
|
46
|
+
|
|
47
|
+
Anthropic `thinking` maps to the server's reasoning request and reasoning comes back as thinking blocks. Tool calls are buffered into whole `tool_use` blocks by default, with an incremental mode available.
|
|
48
|
+
|
|
49
|
+
### 📄 **Images and PDFs**
|
|
50
|
+
|
|
51
|
+
Image blocks are converted, PDFs become per-page text plus page images when the model accepts them, and a text-only model is handled by a startup probe and a one-time retry without images.
|
|
52
|
+
|
|
53
|
+
### 🖥 **Server and CLI**
|
|
54
|
+
|
|
55
|
+
`llm-translator --upstream http://gpu-box:8000` starts a server with API-key protection for non-loopback binds, a client-header allow-list, and in-band error delivery for streams that are already committed. See [docs/server.md](https://github.com/CLDMV/llm-translator/blob/master/docs/server.md).
|
|
56
|
+
|
|
57
|
+
### 🛡 **100% Test Coverage**
|
|
58
|
+
|
|
59
|
+
Lines, statements, functions and branches are all at 100% and enforced on every CI run, with no coverage-ignore pragmas. A harness in `tools/e2e/` drives a real vLLM and a real Claude Code; see [docs/testing.md](https://github.com/CLDMV/llm-translator/blob/master/docs/testing.md).
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 📦 Installation
|
|
64
|
+
|
|
65
|
+
### Requirements
|
|
66
|
+
|
|
67
|
+
- Node.js 24 or newer
|
|
68
|
+
- Developing the package also needs Node.js 24 or newer (`devEngines` enforces it on install and `npm run`)
|
|
69
|
+
- Fastify 5, only for the server and the Fastify plugin (an optional peer dependency)
|
|
70
|
+
|
|
71
|
+
### Install
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install @cldmv/llm-translator
|
|
75
|
+
npm install fastify # only for the server and the Fastify plugin
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🚀 Quick Start
|
|
81
|
+
|
|
82
|
+
### Library
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import { createTranslator } from "@cldmv/llm-translator";
|
|
86
|
+
|
|
87
|
+
const api = await createTranslator({
|
|
88
|
+
front: "anthropic", // the protocol your client speaks
|
|
89
|
+
upstreams: ["http://gpu-box:8000"], // vLLM is detected automatically
|
|
90
|
+
aliases: { "claude-opus-5-5": "qwen3-coder" }
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Pure conversion, no I/O: build the upstream call yourself.
|
|
94
|
+
const call = await api.request({ model: "claude-opus-5-5", max_tokens: 256, messages: [{ role: "user", content: "hi" }] });
|
|
95
|
+
// call.url, call.headers, call.body ...
|
|
96
|
+
// api.response(upstreamJson, call.state) converts a reply back,
|
|
97
|
+
// api.stream(upstreamSseBody, call.state) turns a stream into Anthropic events.
|
|
98
|
+
|
|
99
|
+
// Or let the translator do the full round trip.
|
|
100
|
+
const reply = await api.send({ model: "qwen3-coder", max_tokens: 256, stream: true, messages: [{ role: "user", content: "hi" }] });
|
|
101
|
+
if (reply.stream) for await (const { event, data } of reply.stream) console.log(event, data);
|
|
102
|
+
|
|
103
|
+
// Where would a request go, and what did it cost? (see docs/server.md)
|
|
104
|
+
const { upstream, model } = api.route({ model: "claude-opus-5-5" }); // no I/O
|
|
105
|
+
const { input_tokens, output_tokens, reported, estimated } = await reply.usage; // or send(body, { onUsage }); `estimated` holds the guesses written into the client reply when the upstream sent no usage
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Server and Claude Code
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npx llm-translator --upstream http://gpu-box:8000 --port 8787 --model claude-opus-5-5=qwen3-coder
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
const server = await api.server.start({ port: 8787 });
|
|
116
|
+
console.log(server.url);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Then point Claude Code at it with `ANTHROPIC_BASE_URL=http://127.0.0.1:8787`. The full walkthrough, including the vLLM flags tool calling needs, is in [docs/claude-code.md](https://github.com/CLDMV/llm-translator/blob/master/docs/claude-code.md).
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 📚 Configuration
|
|
124
|
+
|
|
125
|
+
`createTranslator(config)` takes `front`, `upstreams` (URLs or objects with `url`, `apiKey`, `backend`, `models`, `default` and `settings`), `aliases`, 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` and a custom `transport`. The CLI reads the same keys from flags, `LLM_TRANSLATOR_*` environment variables and a JSON file, in that order of precedence.
|
|
126
|
+
|
|
127
|
+
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).
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 📚 Documentation
|
|
132
|
+
|
|
133
|
+
### Reference
|
|
134
|
+
|
|
135
|
+
- [Server and CLI](https://github.com/CLDMV/llm-translator/blob/master/docs/server.md)
|
|
136
|
+
- [Settings](https://github.com/CLDMV/llm-translator/blob/master/docs/settings.md)
|
|
137
|
+
- [Protocol support](https://github.com/CLDMV/llm-translator/blob/master/docs/protocol-support.md)
|
|
138
|
+
- [Drivers, detection and routing](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md)
|
|
139
|
+
|
|
140
|
+
### Guides
|
|
141
|
+
|
|
142
|
+
- [Claude Code against vLLM](https://github.com/CLDMV/llm-translator/blob/master/docs/claude-code.md)
|
|
143
|
+
- [Testing and the real-backend harness](https://github.com/CLDMV/llm-translator/blob/master/docs/testing.md)
|
|
144
|
+
- [Known limitations](https://github.com/CLDMV/llm-translator/blob/master/docs/known-limitations.md)
|
|
145
|
+
- [Feature inventory](https://github.com/CLDMV/llm-translator/blob/master/docs/feature-inventory.md)
|
|
146
|
+
- [Design decisions](https://github.com/CLDMV/llm-translator/blob/master/docs/decisions.md)
|
|
147
|
+
|
|
148
|
+
### Repo
|
|
149
|
+
|
|
150
|
+
[![npm unpacked size]][npm_size_url] [![Repo size]][repo_size_url]
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 🔗 Links
|
|
155
|
+
|
|
156
|
+
- **npm**: [@cldmv/llm-translator](https://www.npmjs.com/package/@cldmv/llm-translator)
|
|
157
|
+
- **GitHub**: [CLDMV/llm-translator](https://github.com/CLDMV/llm-translator)
|
|
158
|
+
- **Issues**: [GitHub Issues](https://github.com/CLDMV/llm-translator/issues)
|
|
159
|
+
- **Releases**: [GitHub Releases](https://github.com/CLDMV/llm-translator/releases)
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 📄 License
|
|
11
164
|
|
|
12
|
-
|
|
13
|
-
- [View full v0.1.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.1.0.md)
|
|
165
|
+
[![GitHub license]][github_license_url] [![npm license]][npm_license_url]
|
|
14
166
|
|
|
15
|
-
|
|
167
|
+
Apache-2.0 © Shinrai / CLDMV
|
|
16
168
|
|
|
17
|
-
[
|
|
169
|
+
[npm version]: https://img.shields.io/npm/v/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
170
|
+
[npm_version_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
171
|
+
[npm downloads]: https://img.shields.io/npm/dm/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
172
|
+
[npm_downloads_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
173
|
+
[github downloads]: https://img.shields.io/github/downloads/CLDMV/llm-translator/total?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
174
|
+
[github_downloads_url]: https://github.com/CLDMV/llm-translator/releases
|
|
175
|
+
[last commit]: https://img.shields.io/github/last-commit/CLDMV/llm-translator?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
176
|
+
[last_commit_url]: https://github.com/CLDMV/llm-translator/commits
|
|
177
|
+
[npm last update]: https://img.shields.io/npm/last-update/%40cldmv%2Fllm-translator?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
178
|
+
[npm_last_update_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
179
|
+
[npm unpacked size]: https://img.shields.io/npm/unpacked-size/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
180
|
+
[npm_size_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
181
|
+
[repo size]: https://img.shields.io/github/repo-size/CLDMV/llm-translator?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
182
|
+
[repo_size_url]: https://github.com/CLDMV/llm-translator
|
|
183
|
+
[github license]: https://img.shields.io/github/license/CLDMV/llm-translator.svg?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
184
|
+
[github_license_url]: https://github.com/CLDMV/llm-translator/blob/HEAD/LICENSE
|
|
185
|
+
[npm license]: https://img.shields.io/npm/l/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
186
|
+
[npm_license_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
187
|
+
[coverage]: https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FCLDMV%2Fllm-translator%2Fbadges%2Fcoverage.json&style=for-the-badge&logo=vitest&logoColor=white
|
|
188
|
+
[coverage_url]: https://github.com/CLDMV/llm-translator/blob/badges/coverage.json
|
|
189
|
+
[contributors]: https://img.shields.io/github/contributors/CLDMV/llm-translator.svg?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
190
|
+
[contributors_url]: https://github.com/CLDMV/llm-translator/graphs/contributors
|
|
191
|
+
[sponsor shinrai]: https://img.shields.io/github/sponsors/shinrai?style=for-the-badge&logo=githubsponsors&logoColor=white&labelColor=EA4AAA&label=Sponsor
|
|
192
|
+
[sponsor_url]: https://github.com/sponsors/shinrai
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var O=Object.defineProperty;var d=(e,t)=>O(e,"name",{value:t,configurable:!0});import{resolve as E}from"../../../../../../../lib/settings.mjs";import{TranslatorError as T}from"../../../../../../../lib/errors.mjs";import{createNameFitter as M}from"../../../../../../../lib/ids.mjs";import{sanitize as B}from"../../../../../../../lib/schema.mjs";import{NOTE as I}from"../../../../../../../lib/images.mjs";import{expand as A}from"../../../../../../../lib/documents.mjs";import{createBudget as L,unsign as z}from"../../../../../../../lib/thinking.mjs";import{plan as C,scan as D}from"../../../../../../../lib/toolsearch.mjs";const P=new Set(["model","messages","system","max_tokens","stream","temperature","top_p","top_k","stop_sequences","tools","tool_choice","thinking","output_config","output_format","context_management"]),W=new Set(["metadata","cache_control","service_tier"]),H=new Set(["mcp_servers","container","inference_geo"]),K="x-anthropic-billing-header:";async function fe(e,t,o){const n=E(t);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new T("messages: Field required",{code:"invalid_request",param:"messages"});const i={front:"anthropic",model:e.model,stream:e.stream===!0,thinking:e.thinking?.type??null,reasoningField:n.reasoningField,toolNames:{},dropped:[]};o?.producer!==void 0&&(i.producer=o.producer);const s=M({max:64,map:i.toolNames});for(const c of e.tools??[])(c.type===void 0||c.type==="custom")&&s(c.name);const m=D(e.messages,new Set((e.tools??[]).map(c=>c.name))),l=C(e.tools??[],m,n,e.tool_choice);i.toolSearch={mode:n.toolSearch,loaded:l.loaded,hidden:l.hidden,stubbed:l.stubbed,capped:m.capped};for(const c of Object.keys(e))if(!(P.has(c)||W.has(c)))if(H.has(c))g(i,c);else{if(n.unknownFields==="error")throw new T(`${c}: Extra inputs are not permitted`,{code:"unsupported_field",param:c});g(i,c)}const r={model:e.model},h=N(e.system,n),k=await R(e.messages,n,i,s,h,U(e.context_management,i),o?.budget??L());r.messages=k.messages,k.prefill&&(r.continue_final_message=!0,r.add_generation_prompt=!1),e.max_tokens!==void 0&&(r[n.maxTokensField]=e.max_tokens),e.temperature!==void 0&&(r.temperature=e.temperature),e.top_p!==void 0&&(r.top_p=e.top_p),e.top_k!==void 0&&(n.topK?r.top_k=e.top_k:g(i,"top_k")),e.stop_sequences?.length>0&&(r.stop=e.stop_sequences),i.stream&&(r.stream=!0,n.streamUsage&&(r.stream_options={include_usage:!0},n.continuousUsage&&(r.stream_options.continuous_usage_stats=!0)));const u=X(l.offer,n,i,s);if(u.length>0){r.tools=u;const c=Y(e.tool_choice,n,i,s);c!==void 0&&(r.tool_choice=c),e.tool_choice?.disable_parallel_tool_use===!0&&n.parallelToolCalls&&(r.parallel_tool_calls=!1)}return Z(e,n,r),b(e,n,i,r),{body:r,state:i}}d(fe,"request");function g(e,t){e.dropped.includes(t)||e.dropped.push(t)}d(g,"drop");function v(e,t,o){if(t.unknownFields==="error")throw new T(`${o}: is not supported by this translator`,{code:"unsupported_content",param:o});g(e,o)}d(v,"unsupported");function N(e,t){return e==null?"":(typeof e=="string"?[{type:"text",text:e}]:e).filter(n=>n.type==="text"&&!(t.stripBillingHeader&&n.text.trimStart().startsWith(K))).map(n=>n.text).join(`
|
|
2
|
+
|
|
3
|
+
`)}d(N,"textOf");function j(e){return typeof e=="string"?[{type:"text",text:e}]:e??[]}d(j,"asBlocks");async function R(e,t,o,n,i,s,m){const l=[],r=[],h=new Map,k=t.inlineSystem==="auto"?"user":t.inlineSystem,u=new Map;if(t.reasoningRoundTrip){for(let a=e.length-1;a>=0;a--)if(e[a].role==="assistant")for(const f of[...j(e[a].content)].reverse())f.type==="thinking"&&u.set(f,await z(f.signature,{producer:o.producer,budget:m}))}const c=d(a=>{const f=l.at(-1);f?.role==="user"?f.parts.push(...a):l.push({role:"user",parts:a})},"pushUser"),w=d(async(a,f)=>{switch(a.type){case"text":return a.text===""?[]:[{type:"text",text:a.text}];case"image":return V(a,t,o);case"document":{const _=[];for(const p of await A(a,{settings:t,toolInputs:h,toolUseId:f}))_.push(...await w(p,f));return _}case"search_result":{const _=(a.content??[]).map(p=>p.text).join(`
|
|
4
|
+
`);return[{type:"text",text:`[Search result: ${a.title??""} (${a.source??""})]
|
|
5
|
+
${_}`}]}case"tool_reference":return t.toolSearch==="native"&&t.deferredTools!=="drop"?[{type:"tool_reference",tool_name:a.tool_name}]:[{type:"text",text:o.toolSearch.loaded.includes(a.tool_name)?`[Tool loaded: ${a.tool_name}]`:`[Tool reference: ${a.tool_name}]`}];default:return v(o,t,`block:${a.type}`),[]}},"toParts");for(const a of e)if(a.role==="system"){const f=N(a.content,t);if(f===""||k==="drop")continue;if(k==="keep")l.push({role:"system",content:f});else if(k==="hoist")r.push(f);else{const _=f.trimStart().startsWith("<system-reminder>")?f:`<system-reminder>
|
|
6
|
+
${f}
|
|
7
|
+
</system-reminder>`;c([{type:"text",text:_}])}}else if(a.role==="user"){const f=[],_=[];for(const y of j(a.content)){if(y.type!=="tool_result"){f.push(...await w(y,null));continue}const S=[];for(const x of j(y.content))S.push(...await w(x,y.tool_use_id));const q=S.filter(x=>x.type==="text").map(x=>x.text),F=S.filter(x=>x.type==="image_url");let $=S.some(x=>x.type==="tool_reference")?S.filter(x=>x.type!=="image_url"):q.join(`
|
|
8
|
+
`);F.length>0&&(_.push({type:"text",text:`Image output of tool call ${y.tool_use_id}:`},...F),$===""&&($="(image output attached in the next message)")),y.is_error===!0&&t.toolErrors&&($=typeof $=="string"?`[error] ${$}`:[{type:"text",text:"[error]"},...$]),l.push({role:"tool",tool_call_id:y.tool_use_id,content:$})}const p=[..._,...f];p.length>0&&c(p)}else if(a.role==="assistant"){const f={role:"assistant",texts:[],parts:[],tool_calls:[]};for(const p of j(a.content))if(p.type==="text")p.text!==""&&f.texts.push(p.text);else if(p.type==="thinking"){const y=u.get(p)??null;y?f.parts.push({restored:y}):p.thinking&&f.parts.push({text:p.thinking})}else p.type==="redacted_thinking"?g(o,"redacted_thinking"):p.type==="tool_use"?(h.set(p.id,p.input),f.tool_calls.push({id:p.id,type:"function",function:{name:n(p.name),arguments:JSON.stringify(p.input??{})}})):v(o,t,`block:${p.type}`);const _=l.at(-1);_?.role==="assistant"?(_.texts.push(...f.texts),_.parts.push(...f.parts),_.tool_calls.push(...f.tool_calls)):l.push(f)}else throw new T(`messages: unsupported role "${a.role}"`,{code:"invalid_request",param:"messages"});return Q(l,t,i,r,s,o)}d(R,"convertMessages");function U(e,t){let o=1/0;for(const n of e?.edits??[])typeof n.type=="string"&&n.type.startsWith("clear_thinking")?n.keep==="all"?o=1/0:o=n.keep?.value??1:g(t,`context_management.${n.type}`);return o}d(U,"thinkingTurnsToKeep");function G(e,t){const o=e.find(r=>r.restored&&(r.restored.reasoning_content!==void 0||r.restored.reasoning!==void 0)),n=o?o.restored.reasoning_content!==void 0?"reasoning_content":"reasoning":t;let i="",s,m=null;for(const r of e){const h=r.restored?r.restored.reasoning_content??r.restored.reasoning:r.text;r.restored?.reasoning_details&&(s=[...s??[],...r.restored.reasoning_details]),h!==void 0&&(i+=(m!==null&&!(m.restored&&r.restored)?`
|
|
9
|
+
|
|
10
|
+
`:"")+h,m=r)}const l={};return i!==""&&(l[n]=i),s&&(l.reasoning_details=s),l}d(G,"reasoningFields");function J(e){return!!(e.reasoning_content||e.reasoning||e.reasoning_details)}d(J,"reasoningSent");function Q(e,t,o,n,i,s){let m=i;for(let u=e.length-1;u>=0;u--)e[u].role!=="assistant"||e[u].parts.length===0||(m>0?m--:e[u].parts=[]);const l=[],r=[o,...n].filter(u=>u!=="").join(`
|
|
11
|
+
|
|
12
|
+
`);r!==""&&l.push({role:"system",content:r});for(const u of e)if(u.role==="user"){const c=u.parts.every(w=>w.type==="text");l.push({role:"user",content:c?u.parts.map(w=>w.text).join(`
|
|
13
|
+
|
|
14
|
+
`):u.parts})}else if(u.role==="assistant"){const c={role:"assistant",content:u.texts.join(`
|
|
15
|
+
|
|
16
|
+
`)};u.parts.length>0&&Object.assign(c,G(u.parts,t.reasoningField)),t.reasoningRoundTrip&&u.tool_calls.length>0&&!J(c)&&(s.reasoningMissing=(s.reasoningMissing??0)+1),u.tool_calls.length>0&&(c.tool_calls=u.tool_calls),l.push(c)}else l.push(u);const h=l.at(-1),k=t.prefill==="continue_final_message"&&h?.role==="assistant"&&!h.tool_calls&&h.content!=="";return{messages:l,prefill:k}}d(Q,"finalize");function V(e,t,o){if(!t.images)return g(o,"image"),[{type:"text",text:I}];const n=e.source;return n.type==="base64"?[{type:"image_url",image_url:{url:`data:${n.media_type};base64,${n.data}`}}]:n.type==="url"?[{type:"image_url",image_url:{url:n.url}}]:(g(o,"image.file"),[{type:"text",text:"[An image supplied as an uploaded file could not be forwarded.]"}])}d(V,"imageParts");function X(e,t,o,n){const i=[];for(const s of e){if(s.type!==void 0&&s.type!=="custom"){g(o,`tool:${s.name}`);continue}if(s.defer_loading===!0&&t.deferredTools==="drop"){g(o,"deferred_tools");continue}const m=s.input_schema??{type:"object",properties:{}},l={name:n(s.name),parameters:t.toolSchema==="sanitize"?B(m):m};s.description!==void 0&&(l.description=s.description),s.strict!==void 0&&(l.strict=s.strict),i.push(s.defer_loading===!0&&t.toolSearch==="native"?{type:"function",function:l,defer_loading:!0}:{type:"function",function:l})}return i}d(X,"convertTools");function Y(e,t,o,n){switch(e?.type){case void 0:return;case"auto":return"auto";case"any":return"required";case"none":return"none";case"tool":return{type:"function",function:{name:n(e.name)}};default:v(o,t,`tool_choice:${e.type}`);return}}d(Y,"convertToolChoice");function Z(e,t,o){const n=e.thinking,i=n?.type;let s;i==="disabled"?(t.thinking==="reasoning_effort"&&(s="none"),t.thinking==="chat_template_kwargs"&&(o.chat_template_kwargs={enable_thinking:!1})):(t.effort&&e.output_config?.effort!==void 0&&(s=e.output_config.effort),i==="enabled"&&(t.thinking==="chat_template_kwargs"&&(o.chat_template_kwargs={enable_thinking:!0},t.thinkingBudget&&n.budget_tokens!==void 0&&e.max_tokens!==void 0&&(o.thinking_token_budget=Math.max(0,Math.min(n.budget_tokens,e.max_tokens-1)))),t.thinking==="reasoning_effort"&&s===void 0&&(s="medium"))),s!==void 0&&(o.reasoning_effort=s)}d(Z,"applyThinking");function b(e,t,o,n){const i=e.output_config?.format??e.output_format;i!==void 0&&(t.responseFormat&&i.type==="json_schema"?n.response_format={type:"json_schema",json_schema:{name:"output",schema:i.schema}}:g(o,"output_config.format"));for(const s of Object.keys(e.output_config??{}))s!=="effort"&&s!=="format"&&g(o,`output_config.${s}`)}d(b,"applyOutputConfig");export{fe as request};
|
|
17
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=Object.defineProperty;var h=(o,e)=>m(o,"name",{value:e,configurable:!0});import{resolve as _}from"../../../../../../../lib/settings.mjs";import{restoreName as x}from"../../../../../../../lib/ids.mjs";import{detailOf as y}from"../../../../../../../lib/thinking.mjs";import{toOpenAIFinish as N,toOpenAIUsage as O}from"../../../../../../../lib/finish.mjs";function A(o,e,d){const c=_(d),g=e?.toolNames??{},s=[],l=[],n=[],r=[];let p=0,f=!1;for(const t of o.content??[]){if(c.reasoningRoundTrip){const u=y(t,p+(f?1:0));u&&r.push(u)}t.type==="text"&&t.text!==""&&(f=!0),t.type==="tool_use"&&p++,t.type==="text"?s.push(t.text):t.type==="thinking"?l.push(t.thinking):t.type==="tool_use"&&n.push({id:t.id,type:"function",function:{name:x(g,t.name),arguments:JSON.stringify(t.input??{})}})}const i={role:"assistant",content:s.length===0&&n.length>0?null:s.join("")};l.length>0&&(i[c.reasoningField]=l.join("")),r.length>0&&(i.reasoning_details=r),n.length>0&&(i.tool_calls=n);const a={index:0,message:i,finish_reason:N(o.stop_reason)};return typeof o.stop_sequence=="string"&&(a.stop_reason=o.stop_sequence),e&&(e.upstreamUsage=o.usage),{id:`chatcmpl-${String(o.id).replace(/^msg_/,"")}`,object:"chat.completion",created:Math.floor(Date.now()/1e3),model:e?.model??o.model,choices:[a],usage:O(o.usage)}}h(A,"response");export{A as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var O=Object.defineProperty;var r=(d,o)=>O(d,"name",{value:o,configurable:!0});import{resolve as N}from"../../../../../../../lib/settings.mjs";import{anthropicToOpenAIType as U,anthropicTypeToStatus as j}from"../../../../../../../lib/errors.mjs";import{completionId as D,restoreName as T}from"../../../../../../../lib/ids.mjs";import{toOpenAIFinish as E,toOpenAIUsage as I}from"../../../../../../../lib/finish.mjs";import{messages as w}from"../../../../../../../lib/sse.mjs";import{detailOf as A}from"../../../../../../../lib/thinking.mjs";async function*R(d,o,k){const u=N(k),x=o?.toolNames??{},b=o?.includeUsage??!0,y=Math.floor(Date.now()/1e3),s=new Map;let c=D(),p=o?.model,a={},g=!1,n=null,_=!1,h=0;const i=r((e,t=null,l={})=>({data:{id:c,object:"chat.completion.chunk",created:y,model:p,choices:[{index:0,delta:e,finish_reason:t,...l}]}}),"chunk"),f=r((e,t)=>({data:{error:{message:t,type:U(e),param:null,code:j(e)}}}),"failure");try{for await(const{data:e}of w(d))if(e.type==="message_start")c=`chatcmpl-${String(e.message.id).replace(/^msg_/,"")}`,p=o?.model??e.message.model,a={...e.message.usage},o&&(o.upstreamUsage=a),yield i({role:"assistant",content:""});else if(e.type==="content_block_start"){const t=e.content_block;if((t.type==="thinking"||t.type==="redacted_thinking")&&(n={type:t.type,data:t.data,thinking:"",signature:"",slot:h+(_?1:0)}),t.type==="tool_use"&&h++,t.type==="tool_use"){s.set(e.index,s.size);const l=T(x,t.name);yield i({tool_calls:[{index:s.get(e.index),id:t.id,type:"function",function:{name:l,arguments:""}}]})}}else if(e.type==="content_block_delta"){const t=e.delta;t.type==="text_delta"?(t.text!==""&&(_=!0),yield i({content:t.text})):t.type==="thinking_delta"?(n&&(n.thinking+=t.thinking),yield i({[u.reasoningField]:t.thinking})):t.type==="signature_delta"?n&&(n.signature+=t.signature):t.type==="input_json_delta"&&s.has(e.index)&&(yield i({tool_calls:[{index:s.get(e.index),function:{arguments:t.partial_json}}]}))}else if(e.type==="content_block_stop"){const t=u.reasoningRoundTrip&&n?A(n,n.slot):null;t&&(yield i({reasoning_details:[t]})),n=null}else if(e.type==="message_delta"){for(const[l,m]of Object.entries(e.usage??{}))m!=null&&(a[l]=m);o&&(o.upstreamUsage=a);const t=typeof e.delta?.stop_sequence=="string"?{stop_reason:e.delta.stop_sequence}:{};yield i({},E(e.delta?.stop_reason),t)}else if(e.type==="message_stop"){g=!0;break}else if(e.type==="error"){yield f(e.error.type,e.error.message),yield{data:"[DONE]"};return}}catch(e){yield f(e.type??"api_error",e.message),yield{data:"[DONE]"};return}if(!g){yield f("api_error","Upstream stream ended before completion"),yield{data:"[DONE]"};return}b&&(yield{data:{id:c,object:"chat.completion.chunk",created:y,model:p,choices:[],usage:I(a)}}),yield{data:"[DONE]"}}r(R,"stream");export{R as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var v=Object.defineProperty;var u=(e,s)=>v(e,"name",{value:s,configurable:!0});import{resolve as T}from"../../../../../../../lib/settings.mjs";import{TranslatorError as x}from"../../../../../../../lib/errors.mjs";import{anthropicToolId as j,createNameFitter as q}from"../../../../../../../lib/ids.mjs";import{parseArguments as A}from"../../../../../../../lib/arguments.mjs";import{sanitize as N}from"../../../../../../../lib/schema.mjs";import{blocksOf as $}from"../../../../../../../lib/thinking.mjs";const F=new Set(["model","messages","max_tokens","max_completion_tokens","temperature","top_p","top_k","stop","stream","stream_options","tools","tool_choice","parallel_tool_calls","reasoning_effort","response_format","user","n"]),I=new Set(["metadata","store","service_tier"]),h=/^data:([^;,]+);base64,(.*)$/s;async function P(e,s){const p=T(s);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new x("messages is a required property",{code:"invalid_request",param:"messages"});if(e.n!==void 0&&e.n!==1)throw new x("n: only a single choice (n = 1) is supported",{code:"unsupported_field",param:"n"});const o={front:"openai",model:e.model,stream:e.stream===!0,includeUsage:e.stream_options?.include_usage===!0,reasoningField:p.reasoningField,toolNames:{},dropped:[]},l=q({max:128,map:o.toolNames});for(const t of Object.keys(e))if(!(F.has(t)||I.has(t))){if(p.unknownFields==="error")throw new x(`${t}: Unrecognized request argument`,{code:"unsupported_field",param:t});g(o,t)}const c=[],a=[],m=u((t,r)=>{const i=a.at(-1);i?.role===t?i.blocks.push(...r):a.push({role:t,blocks:[...r]})},"push");for(const t of e.messages)switch(t.role){case"system":case"developer":{const r=w(t.content);r!==""&&c.push(r);break}case"user":m("user",z(t.content,o));break;case"assistant":{const r=p.reasoningRoundTrip?$(t.reasoning_details):[],i=[],f=w(t.content);f!==""?i.push({type:"text",text:f}):typeof t.refusal=="string"&&t.refusal!==""&&i.push({type:"text",text:t.refusal}),S(t)&&!r.some(d=>d.block.type==="thinking")&&g(o,"reasoning");for(const d of t.tool_calls??[])i.push({type:"tool_use",id:j(d.id),name:l(d.function.name),input:A(d.function.arguments)});const k=M(r,i);k.length>0&&m("assistant",k);break}case"tool":{const r={type:"tool_result",tool_use_id:j(t.tool_call_id),content:w(t.content)},i=a.at(-1);if(i?.role==="user"){const f=i.blocks.findIndex(k=>k.type!=="tool_result");i.blocks.splice(f===-1?i.blocks.length:f,0,r)}else a.push({role:"user",blocks:[r]});break}default:throw new x(`messages: unsupported role "${t.role}"`,{code:"invalid_request",param:"messages"})}const n={model:e.model,max_tokens:e.max_completion_tokens??e.max_tokens??p.defaultMaxTokens};c.length>0&&(n.system=c.join(`
|
|
2
|
+
|
|
3
|
+
`)),n.messages=a.map(t=>({role:t.role,content:t.blocks})),e.temperature!==void 0&&(n.temperature=Math.min(1,e.temperature)),e.top_p!==void 0&&(n.top_p=e.top_p),e.top_k!==void 0&&(n.top_k=e.top_k),e.stop!==void 0&&e.stop!==null&&(n.stop_sequences=[].concat(e.stop)),o.stream&&(n.stream=!0),typeof e.user=="string"&&(n.metadata={user_id:e.user});const b=[];for(const t of e.tools??[]){if(t.type!=="function"){g(o,`tool:${t.type}`);continue}const r=t.function,i=r.parameters??{type:"object",properties:{}},f={name:l(r.name),input_schema:p.toolSchema==="sanitize"?N(i):i};r.description!==void 0&&(f.description=r.description),b.push(f)}if(b.length>0){n.tools=b;let t=D(e.tool_choice,l);e.parallel_tool_calls===!1&&t.type!=="none"&&(t={...t,disable_parallel_tool_use:!0}),(e.tool_choice!==void 0||e.parallel_tool_calls===!1)&&(n.tool_choice=t)}const _=e.reasoning_effort;_==="none"?n.thinking={type:"disabled"}:_!=null&&(n.thinking={type:"adaptive"},n.output_config={effort:_==="minimal"?"low":_});const y=e.response_format;return y?.type==="json_schema"?n.output_config={...n.output_config,format:{type:"json_schema",schema:y.json_schema.schema}}:y?.type==="json_object"&&g(o,"response_format"),{body:n,state:o}}u(P,"request");function g(e,s){e.dropped.includes(s)||e.dropped.push(s)}u(g,"drop");function M(e,s){const p=[...e].sort((a,m)=>a.at-m.at),o=[];let l=0;const c=s.findIndex(a=>a.type==="tool_use");for(const a of p){const m=a.at<=1&&c!==-1?Math.min(a.at,c):a.at;for(;l<Math.min(m,s.length);)o.push(s[l++]);o.push(a.block)}return[...o,...s.slice(l)]}u(M,"interleave");function S(e){return!!(e.reasoning||e.reasoning_content)}u(S,"reasoningPresent");function w(e){return typeof e=="string"?e:(e??[]).filter(s=>s.type==="text").map(s=>s.text).join(`
|
|
4
|
+
|
|
5
|
+
`)}u(w,"plainText");function z(e,s){if(typeof e=="string")return e===""?[]:[{type:"text",text:e}];const p=[];for(const o of e??[])if(o.type==="text")p.push({type:"text",text:o.text});else if(o.type==="image_url"){const l=h.exec(o.image_url.url);p.push({type:"image",source:l?{type:"base64",media_type:l[1],data:l[2]}:{type:"url",url:o.image_url.url}})}else if(o.type==="file"&&typeof o.file?.file_data=="string"&&h.test(o.file.file_data)){const l=h.exec(o.file.file_data);p.push({type:"document",source:{type:"base64",media_type:l[1],data:l[2]}})}else g(s,`content:${o.type}`);return p}u(z,"userBlocks");function D(e,s){return e==="none"?{type:"none"}:e==="required"?{type:"any"}:typeof e=="object"&&e!==null?{type:"tool",name:s(e.function.name)}:{type:"auto"}}u(D,"toolChoice");export{P as request};
|
|
6
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var d=Object.defineProperty;var c=(s,n)=>d(s,"name",{value:n,configurable:!0});import{resolve as h}from"../../../../../../../lib/settings.mjs";import{TranslatorError as y}from"../../../../../../../lib/errors.mjs";import{messageId as _,anthropicToolId as k,restoreName as T}from"../../../../../../../lib/ids.mjs";import{sign as x,reasoningOf as A,reasoningKey as C,detailsText as N,splitThink as O}from"../../../../../../../lib/thinking.mjs";import{isComplete as S,parseArguments as U}from"../../../../../../../lib/arguments.mjs";import{toAnthropicStop as v,toAnthropicUsage as w}from"../../../../../../../lib/finish.mjs";function z(s,n,m){const p=h(m),g=s?.choices?.[0];if(!g)throw new y("Upstream response contained no choices",{code:"invalid_upstream_response",status:502});const e=g.message??{},r=[];let a=A(e),t=typeof e.content=="string"?e.content:"";const o={};if(p.reasoningRoundTrip){const i=C(e);i&&(o[i]=e[i]),Array.isArray(e.reasoning_details)&&e.reasoning_details.length>0&&(o.reasoning_details=e.reasoning_details)}a===""&&p.thinkTags&&({reasoning:a,text:t}=O(t,p.thinkOpen)),a===""&&o.reasoning_details&&(a=N(o.reasoning_details)),(a!==""||o.reasoning_details)&&(r.push({type:"thinking",thinking:a,signature:x(Object.keys(o).length>0?o:void 0,n?.producer)}),t=t.trimStart()),t===""&&typeof e.refusal=="string"&&(t=e.refusal),t!==""&&r.push({type:"text",text:t});const f=n?.toolNames??{},l=e.tool_calls??[];for(const i of l)r.push({type:"tool_use",id:k(i.id),name:T(f,i.function.name),input:U(i.function.arguments)});r.length===0&&r.push({type:"text",text:""});const u=v(g.finish_reason,{hasToolCalls:l.length>0,matchedStop:g.stop_reason,argumentsComplete:l.length===0||S(l.at(-1).function.arguments)});return n&&s.usage&&(n.upstreamUsage=s.usage),{id:_(),type:"message",role:"assistant",model:n?.model??s.model,content:r,...u,usage:w(s.usage)}}c(z,"response");export{z as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var M=Object.defineProperty;var s=(h,r)=>M(h,"name",{value:r,configurable:!0});import{resolve as G}from"../../../../../../../lib/settings.mjs";import{TranslatorError as H,openaiToAnthropicType as L,rewriteContextOverflow as P}from"../../../../../../../lib/errors.mjs";import{isComplete as Q}from"../../../../../../../lib/arguments.mjs";import{messageId as V,anthropicToolId as W,restoreName as X}from"../../../../../../../lib/ids.mjs";import{sign as Y,reasoningOf as Z,reasoningKey as $,detailsText as ee,mergeDetail as te,createThinkSplitter as ne}from"../../../../../../../lib/thinking.mjs";import{toAnthropicStop as ie,toAnthropicUsage as z}from"../../../../../../../lib/finish.mjs";import{messages as oe}from"../../../../../../../lib/sse.mjs";async function*pe(h,r,D){const u=G(D),E=r?.toolNames??{},a=u.thinkTags?ne(u.thinkOpen):null,c=new Map;let _=!1,x=0,n=null,w=null,b=null,S=null,N=!1,O=0,j=!1,v=!1,A=!1;const T=[],l=s((e,t)=>({event:e,data:{type:e,...t}}),"event"),m=s((e,t)=>l("error",{error:{type:e,message:t}}),"fail"),q=s(e=>{const t={};return u.reasoningRoundTrip&&(e.key!==null&&(t[e.key]=e.text),e.details.length>0&&(t.reasoning_details=e.details)),Object.keys(t).length>0?t:void 0},"carried");function*p(){if(n!==null){n.kind==="thinking"?yield l("content_block_delta",{index:n.index,delta:{type:"signature_delta",signature:Y(q(n.carry),r?.producer)}}):n.kind==="tool"&&(n.entry.state="closed",n.entry.sent||(yield l("content_block_delta",{index:n.index,delta:{type:"input_json_delta",partial_json:"{}"}}))),yield l("content_block_stop",{index:n.index}),n=null;for(const e of c.values()){if(e.state!=="pending")continue;e.state="closed";const t=x++,i=e.args.join("");yield l("content_block_start",{index:t,content_block:e.block}),yield l("content_block_delta",{index:t,delta:{type:"input_json_delta",partial_json:i===""?"{}":i}}),yield l("content_block_stop",{index:t})}}}s(p,"close");function*B(){for(const e of C()){if(e.state!=="buffered")continue;yield*y("tool",e.block,e);const t=e.args.join("");t!==""&&(e.sent=!0,yield l("content_block_delta",{index:n.index,delta:{type:"input_json_delta",partial_json:t}})),yield*p()}}s(B,"flushBuffered");function C(){return[...c.entries()].sort((e,t)=>e[0]-t[0]).map(e=>e[1])}s(C,"ordered");function*y(e,t,i){yield*p(),n={kind:e,index:x++,entry:i,carry:{key:null,text:"",details:[]}},yield l("content_block_start",{index:n.index,content_block:t})}s(y,"begin");function*d(e,t,i=null){if(e==="text"&&A&&(t=t.trimStart()),t==="")return;if(A=e==="thinking",n?.kind==="tool"){T.push({kind:e,text:t,key:i});return}n?.kind!==e&&(yield*y(e,e==="text"?{type:"text",text:""}:{type:"thinking",thinking:"",signature:""})),i!==null&&(n.carry.key??=i,n.carry.text+=t);const o=e==="text"?{type:"text_delta",text:t}:{type:"thinking_delta",thinking:t};yield l("content_block_delta",{index:n.index,delta:o})}s(d,"piece");function*U(e){if(n?.kind==="tool"){T.push({kind:"details",items:e});return}n?.kind!=="thinking"&&(yield*y("thinking",{type:"thinking",thinking:"",signature:""}));for(const t of e)te(n.carry.details,t);n.carry.key===null&&(yield*d("thinking",ee(e)))}s(U,"details");function*I(e){yield*d("thinking",e.reasoning),yield*d("text",e.text)}s(I,"pieces");function*F(e){let t=e.index;t===void 0&&(t=e.id===void 0?O:c.size),O=t;let i=c.get(t);if(i===void 0){const k=e.function?.name??"",g={type:"tool_use",id:W(e.id),name:X(E,k),input:{}};a?.pending()&&(v=!0);const f=u.toolStreaming==="buffer"||v;i={state:f?"buffered":"pending",sent:!1,args:[],block:g},c.set(t,i),!f&&n?.kind!=="tool"&&(i.state="open",yield*y("tool",g,i))}let o=e.function?.arguments;o!==null&&typeof o=="object"&&(o=JSON.stringify(o)),!(o==null||o==="")&&(i.args.push(o),i.state==="open"&&(i.sent=!0,yield l("content_block_delta",{index:n.index,delta:{type:"input_json_delta",partial_json:o}})))}s(F,"toolCall");try{for await(const e of oe(h)){if(e.data==="[DONE]"){N=!0;break}const t=e.data;if(t.error){const f=t.error.message??"Upstream error";yield m(L(t.error),P(f)??f);return}_||(_=!0,yield l("message_start",{message:{id:V(),type:"message",role:"assistant",model:r?.model??t.model,content:[],stop_reason:null,stop_sequence:null,usage:z(t.usage)}})),t.usage&&(w=t.usage,r&&(r.upstreamUsage=t.usage));const i=t.choices?.[0];if(!i)continue;const o=i.delta??{},k=Z(o);let g="";k!==""&&!j&&(j=!0,a&&(g=a.release().text)),yield*d("thinking",k,$(o)),yield*d("text",g),u.reasoningRoundTrip&&Array.isArray(o.reasoning_details)&&o.reasoning_details.length>0&&(yield*U(o.reasoning_details)),typeof o.content=="string"&&o.content!==""&&(a&&!j?yield*I(a.push(o.content)):yield*d("text",o.content));for(const f of o.tool_calls??[])yield*F(f);i.finish_reason&&(b=i.finish_reason),typeof i.stop_reason=="string"&&(S=i.stop_reason)}}catch(e){yield e instanceof H?m(e.type,e.message):m("api_error",e.message);return}if(!_||b===null&&!N){yield m("api_error",_?"Upstream stream ended before completion":"Upstream stream ended without data");return}a&&(yield*I(a.end())),yield*B();const R=C().at(-1),J=R===void 0||Q(R.args.join(""));yield*p();for(const e of T)yield*e.kind==="details"?U(e.items):d(e.kind,e.text,e.key);yield*p(),x===0&&(yield*y("text",{type:"text",text:""}),yield*p());const K=ie(b,{hasToolCalls:c.size>0,matchedStop:S,argumentsComplete:J});yield l("message_delta",{delta:K,usage:z(w)}),yield l("message_stop",{})}s(pe,"stream");export{pe as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g=Object.defineProperty;var n=(t,e)=>g(t,"name",{value:e,configurable:!0});import{context as v,self as m}from"../lib/runtime.mjs";import{capture as w}from"../lib/capture.mjs";import{TranslatorError as d}from"../lib/errors.mjs";import{warn as p}from"../lib/warn.mjs";import*as h from"../lib/http.mjs";async function U(t={}){const e=w(m,v),{status:o}=m,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 d(`Driver ${r.name}: info().fields must be an array of field names`,{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=>y(e,r,f,a))),o()}n(U,"detect");async function y(t,e,o,f){let a,r=null;if(e.backend!=="auto"){if(a=t.drivers.find(s=>s.name===e.backend),!a)throw new d(`Unknown backend "${e.backend}" for upstream ${e.name}`,{code:"unknown_backend",status:500});r={version:e.version}}else if(o){const s={endpoint:e,...f,probes:new Map};let i=!1;for(const[c,l]of t.drivers.entries()){if(!i&&l.info.probes?.length>0){i=!0;for(const u of t.drivers.slice(c))for(const b of u.info.probes??[])h.probe(s,b)}if(r=await k(l,s),r){a=l;break}}}if(a||(a=t.drivers.find(s=>s.name==="compatible"),r={reachable:null,models:[]}),e.driver=a.name,e.protocol=a.info.protocol,e.facts=r,e.driverSettings=await a.settings?.(r)??{},e.probed={},o&&e.backend==="auto"&&a.probe){const s=n(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&&p(t.config,t.state,`Upstream ${e.name} (${e.url}) did not answer detection; using the generic OpenAI-compatible driver`)}n(y,"bind");async function k(t,e){try{return await t.detect?.(e)??null}catch{return null}}n(k,"detectWith");export{U as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var e=(s,o)=>a(s,"name",{value:o,configurable:!0});function t(){return{name:"anthropic",protocol:"anthropic.messages",order:20,auth:"x-api-key",headers:{"anthropic-version":"2023-06-01"},paths:{messages:"/v1/messages",models:"/v1/models",count:"/v1/messages/count_tokens"}}}e(t,"info");export{t as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var r=(e,t)=>o(e,"name",{value:t,configurable:!0});import{fetchModels as i}from"../../../../lib/models.mjs";function p(e){return i({...e,auth:"x-api-key",extraHeaders:{"anthropic-version":"2023-06-01"}})}r(p,"list");export{p as list};
|
|
2
|
+
//# sourceMappingURL=list.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var p=Object.defineProperty;var c=(o,t)=>p(o,"name",{value:t,configurable:!0});import*as s from"../../../../lib/http.mjs";const u=["model","messages","system","tools","tool_choice","thinking","mcp_servers","context_management"];async function l({endpoint:o,request:t,transport:a,signal:r,timeout:m}){const i={};for(const e of u)t[e]!==void 0&&(i[e]=t[e]);const n=await s.json(a,s.join(o.url,"/v1/messages/count_tokens"),{method:"POST",headers:{"content-type":"application/json","anthropic-version":"2023-06-01",...s.headers(o,"x-api-key")},body:i,signal:r,timeout:m});return n.ok&&typeof n.body?.input_tokens=="number"?n.body.input_tokens:null}c(l,"count");export{l as count};
|
|
2
|
+
//# sourceMappingURL=count.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var t=(e,o)=>r(e,"name",{value:o,configurable:!0});import*as a from"../../../lib/http.mjs";import{modelsOf as l}from"../../../lib/models.mjs";async function n(e){const o=l(await a.probe(e,"/v1/models"));return{reachable:o!==null,models:(o??[]).map(m=>m.id)}}t(n,"detect");export{n as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var o=(e,t)=>r(e,"name",{value:t,configurable:!0});import{VLLM_FIELDS as a}from"../../../lib/passthrough.mjs";function m(){return{name:"compatible",protocol:"openai.chat",order:100,auth:"bearer",fields:a,paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(m,"info");export{m as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var e=(n,t)=>s(n,"name",{value:t,configurable:!0});function i(){return{thinking:"none",thinkingBudget:!1,effort:!1,topK:!1,prefill:"none",streamUsage:!0,continuousUsage:!1}}e(i,"settings");export{i as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var o=(r,n)=>s(r,"name",{value:n,configurable:!0});import*as a from"../../../lib/upstream-error.mjs";const t="DeepSeek needs the reasoning of earlier turns sent back when tools are used in thinking mode. The conversation no longer carries it (thinking blocks were not replayed or were cleared), so start a new conversation.";function m(r,n){const e=a.parse(n,r);return{error:{message:r===400&&/reasoning_content/i.test(e.message)?`${e.message} ${t}`:e.message,type:e.type,param:e.param??null,code:e.code??r}}}o(m,"error");export{m as error};
|
|
2
|
+
//# sourceMappingURL=error.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var e=(o,t)=>a(o,"name",{value:t,configurable:!0});function n(){return{name:"deepseek",protocol:"openai.chat",order:35,auth:"bearer",paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}e(n,"info");export{n as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var n=(e,r)=>c(e,"name",{value:r,configurable:!0});import{noEmptyTools as l}from"../../../lib/normalize.mjs";const p=["logprobs","top_logprobs"];function u(e){return e.thinking?.type==="disabled"?!1:e.thinking?.type==="enabled"||/reasoner/i.test(String(e.model))}n(u,"thinking");function a(e,r){let o=l(e);if(!u(o))return o;const i=r?.state?.dropped,s=n(t=>{o={...o},delete o[t],Array.isArray(i)&&!i.includes(t)&&i.push(t)},"remove");o.tool_choice!==void 0&&o.tool_choice!=="auto"&&o.tool_choice!=="none"&&s("tool_choice");for(const t of p)o[t]!==void 0&&s(t);return o}n(a,"request");export{a as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var e=(n,s)=>t(n,"name",{value:s,configurable:!0});function a(){return{reasoningField:"reasoning_content",reasoningRoundTrip:!0,maxTokensField:"max_tokens",thinking:"none",thinkingBudget:!1,effort:!1,topK:!1,prefill:"none",responseFormat:!1,images:!1,streamUsage:!0,continuousUsage:!1}}e(a,"settings");export{a as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var f=Object.defineProperty;var s=(t,o)=>f(t,"name",{value:o,configurable:!0});import{callId as d}from"../../../lib/ids.mjs";const c="<think>",a="</think>";function l(t,o){const e=o.thinkLegacy??={reasoning:!1,mode:"start",held:""};if(typeof t.reasoning_content=="string"&&t.reasoning_content!==""&&(e.reasoning=!0),!e.reasoning||e.mode==="plain"||typeof t.content!="string"||t.content==="")return t;let n=e.held+t.content;if(e.held="",e.mode==="start"){const i=n.trimStart();if(i.startsWith(c))e.mode="drop",n=i.slice(c.length);else return i===""||c.startsWith(i)?(e.held=n,{...t,content:""}):(e.mode="plain",{...t,content:n})}const r=n.indexOf(a);return r===-1?(e.held=n.slice(-(a.length-1)),{...t,content:""}):(e.mode="plain",{...t,content:n.slice(r+a.length).trimStart()})}s(l,"legacy");function m(t,o){if(!Array.isArray(t.tool_calls))return t;const e=o.toolIds??={};return{...t,tool_calls:t.tool_calls.map(n=>{const r=n?.index??0;return n?.id||!n?.function?.name||e[r]!==void 0?n:(e[r]=d(),{...n,id:e[r]})})}}s(m,"ids");function h(t,o){const e=t?.choices?.[0]?.delta;if(!o?.state||e===null||typeof e!="object")return t;o.state.thinkLegacy??={reasoning:!1,mode:"start",held:""},o.state.thinkLegacy.base={id:t.id,object:t.object,created:t.created,model:t.model};const n=m(l(e,o.state),o.state);if(n===e)return t;const[r,...i]=t.choices;return{...t,choices:[{...r,delta:n},...i]}}s(h,"chunk");export{h as chunk};
|
|
2
|
+
//# sourceMappingURL=chunk.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var t=(i,e)=>r(i,"name",{value:e,configurable:!0});import*as p from"../../../lib/http.mjs";import{modelsOf as d}from"../../../lib/models.mjs";import{isLlamacppProps as m,objectOf as a}from"../../../lib/backends.mjs";async function c(i){const[e,l]=await Promise.all([p.probe(i,"/props"),p.probe(i,"/v1/models")]),o=a(e),n=d(l)??[];return!m(o)&&!n.some(s=>s.owned_by==="llamacpp")?null:{models:n.map(s=>s.id),build:typeof o.build_info=="string"?o.build_info:void 0,vision:typeof o.modalities?.vision=="boolean"?o.modalities.vision:void 0}}t(c,"detect");export{c as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var h=Object.defineProperty;var n=(t,e)=>h(t,"name",{value:e,configurable:!0});function o(t){const e=t?.state?.thinkLegacy;if(!e||e.mode!=="start"||e.held==="")return[];const s=e.held;return e.held="",[{...e.base,choices:[{index:0,delta:{content:s},finish_reason:null}]}]}n(o,"flush");export{o as flush};
|
|
2
|
+
//# sourceMappingURL=flush.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var p=(e,t)=>a(e,"name",{value:t,configurable:!0});function r(){return{name:"llamacpp",protocol:"openai.chat",order:40,auth:"bearer",probes:["/props"],fields:["top_k","min_p","chat_template_kwargs","repetition_penalty","repeat_penalty","grammar"],paths:{chat:"/v1/chat/completions",models:"/v1/models",props:"/props"}}}p(r,"info");export{r as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var p=Object.defineProperty;var n=(l,t)=>p(l,"name",{value:t,configurable:!0});import{noEmptyTools as r}from"../../../lib/normalize.mjs";function f(l,t){let e=r(l);if(e.tools!==void 0&&e.parallel_tool_calls===void 0&&t?.settings?.parallelToolCalls!==!1&&(e={...e,parallel_tool_calls:!0}),e.repetition_penalty!==void 0&&e.repeat_penalty===void 0){const{repetition_penalty:o,...a}=e;e={...a,repeat_penalty:o}}return e}n(f,"request");export{f as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var i=Object.defineProperty;var s=(e,n)=>i(e,"name",{value:n,configurable:!0});import{callId as a}from"../../../lib/ids.mjs";import{splitThink as c}from"../../../lib/thinking.mjs";function m(e){return Array.isArray(e?.choices)?{...e,choices:e.choices.map(n=>{const t=n?.message;if(!t||typeof t!="object")return n;let r=t;if(typeof t.reasoning_content=="string"&&t.reasoning_content!==""&&typeof t.content=="string"){const o=c(t.content).text;o!==t.content&&(r={...r,content:o})}return Array.isArray(t.tool_calls)&&(r={...r,tool_calls:t.tool_calls.map(o=>o?.id?o:{...o,id:a()})}),r===t?n:{...n,message:r}})}:e}s(m,"response");export{m as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var n=(e,t)=>s(e,"name",{value:t,configurable:!0});function i(e){return{reasoningField:"reasoning_content",maxTokensField:"max_tokens",thinking:"chat_template_kwargs",thinkingBudget:!1,effort:!1,topK:!0,prefill:"none",responseFormat:!0,streamUsage:!0,continuousUsage:!1,images:e?.vision}}n(i,"settings");export{i as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var e=(o,r)=>t(o,"name",{value:r,configurable:!0});import*as i from"../../../lib/http.mjs";import{modelsOf as m}from"../../../lib/models.mjs";async function a(o){const[r,s]=await Promise.all([i.probe(o,"/api/version"),i.probe(o,"/v1/models")]);return typeof r.body?.version!="string"?null:{version:r.body.version,models:(m(s)??[]).map(n=>n.id)}}e(a,"detect");export{a as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var o=(e,a)=>r(e,"name",{value:a,configurable:!0});function t(){return{name:"ollama",protocol:"openai.chat",order:60,auth:"bearer",probes:["/api/version"],paths:{chat:"/v1/chat/completions",models:"/v1/models",version:"/api/version"}}}o(t,"info");export{t as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var d=Object.defineProperty;var l=(s,r)=>d(s,"name",{value:r,configurable:!0});import{noEmptyTools as m}from"../../../lib/normalize.mjs";import{estimate as f}from"../../../lib/estimate.mjs";const p=["tool_choice","n","logit_bias"],h="[An image was omitted because Ollama accepts base64 images only and the translator does not fetch URLs.]";function g(s,r){let t=m(s);const e=r?.state?.dropped;t.tool_choice==="none"&&t.tools!==void 0&&(t={...t},delete t.tools,delete t.parallel_tool_calls,Array.isArray(e)&&!e.includes("tools")&&e.push("tools"));for(const o of p)t[o]!==void 0&&(t={...t},delete t[o],Array.isArray(e)&&!e.includes(o)&&e.push(o));if(Array.isArray(t.messages)){let o=!1;const c=t.messages.map(n=>{if(!Array.isArray(n?.content))return n;const u=n.content.map(i=>i?.type!=="image_url"||String(i.image_url?.url).startsWith("data:")?i:(o=!0,{type:"text",text:h}));return{...n,content:u}});o&&(t={...t,messages:c},Array.isArray(e)&&!e.includes("image_url")&&e.push("image_url"))}const a=r?.settings?.contextWindow??0;return a>0&&f(t)>a&&r?.warn?.(`Upstream ${r.endpoint?.name}: the prompt is estimated at more than ${a} 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.`),t}l(g,"request");export{g as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var e=(n,t)=>o(n,"name",{value:t,configurable:!0});const a=4096;function l(){return{maxTokensField:"max_tokens",thinking:"none",thinkingBudget:!1,effort:!1,topK:!1,prefill:"none",parallelToolCalls:!1,responseFormat:!0,streamUsage:!0,continuousUsage:!1,contextWindow:4096}}e(l,"settings");export{l as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function r(){return{name:"openai",protocol:"openai.chat",order:30,auth:"bearer",paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(r,"info");export{r as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var e=(n,t)=>o(n,"name",{value:t,configurable:!0});function s(){return{maxTokensField:"max_completion_tokens",thinking:"reasoning_effort",thinkingBudget:!1,effort:!0,topK:!1,prefill:"none",deferredTools:"drop",streamUsage:!0,continuousUsage:!1}}e(s,"settings");export{s as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=Object.defineProperty;var t=(r,s)=>m(r,"name",{value:s,configurable:!0});import*as l from"../../../lib/http.mjs";import{modelsOf as d}from"../../../lib/models.mjs";import{isSglangInfo as f,objectOf as p}from"../../../lib/backends.mjs";async function b(r){const[s,a]=await Promise.all([l.probe(r,"/get_server_info"),l.probe(r,"/v1/models")]),e=p(s),i=d(a)??[];if(!f(e)&&!i.some(o=>o.owned_by==="sglang"))return null;const n=t(o=>typeof o=="string"&&o!==""?o:void 0,"text");return{version:n(e.version),models:i.map(o=>o.id),modelPath:n(e.model_path),reasoningParser:n(e.reasoning_parser),toolCallParser:n(e.tool_call_parser)}}t(b,"detect");export{b as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var e=(o,r)=>t(o,"name",{value:r,configurable:!0});function a(){return{name:"sglang",protocol:"openai.chat",order:50,auth:"bearer",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(a,"info");export{a as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var t=(e,n)=>o(e,"name",{value:n,configurable:!0});import{noEmptyTools as s}from"../../../lib/normalize.mjs";function u(e,n){const r=s(e);return n?.endpoint?.facts?.reasoningParser&&r.separate_reasoning===void 0?{...r,separate_reasoning:!0}:r}t(u,"request");export{u as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var e=(t,n)=>o(t,"name",{value:n,configurable:!0});function a(){return{reasoningField:"reasoning_content",maxTokensField:"max_completion_tokens",thinking:"chat_template_kwargs",thinkingBudget:!1,effort:!1,topK:!0,prefill:"none",responseFormat:!0,streamUsage:!0,continuousUsage:!1}}e(a,"settings");export{a as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var y=Object.defineProperty;var d=(s,t)=>y(s,"name",{value:t,configurable:!0});import*as r from"../../../lib/http.mjs";import{isLlamacppProps as g,isSglangInfo as v,objectOf as p}from"../../../lib/backends.mjs";const _=new Set(["sglang","llamacpp"]);async function P({endpoint:s,transport:t,signal:c,timeout:f,probes:b}){const e={endpoint:s,transport:t,signal:c,timeout:f,probes:b},[l,a]=await Promise.all([r.probe(e,"/version"),r.probe(e,"/v1/models")]),i=typeof l.body?.version=="string"?l.body.version:void 0,n=Array.isArray(a.body?.data)?a.body.data:[];if(n.some(o=>_.has(o?.owned_by)))return null;const m=n.some(o=>o?.owned_by==="vllm");if(!i&&!m)return null;if(!m){const[o,u]=await Promise.all([r.probe(e,"/get_server_info"),r.probe(e,"/props")]);if(v(p(o))||g(p(u)))return null}return{version:i,models:n.map(o=>o.id),maxModelLen:n.find(o=>typeof o.max_model_len=="number")?.max_model_len}}d(P,"detect");export{P as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var p=Object.defineProperty;var a=(r,o)=>p(r,"name",{value:o,configurable:!0});import*as m from"../../../lib/upstream-error.mjs";function s(r,o){const e=m.parse(o,r);return{error:{message:e.message,type:e.type,param:e.param??null,code:e.code??r}}}a(s,"error");export{s as error};
|
|
2
|
+
//# sourceMappingURL=error.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var o=(e,t)=>r(e,"name",{value:t,configurable:!0});import{VLLM_FIELDS as n}from"../../../lib/passthrough.mjs";function l(){return{name:"vllm",protocol:"openai.chat",order:10,auth:"bearer",fields:n,paths:{chat:"/v1/chat/completions",models:"/v1/models",tokenize:"/tokenize",version:"/version"}}}o(l,"info");export{l as info};
|
|
2
|
+
//# sourceMappingURL=info.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=Object.defineProperty;var l=(e,o)=>u(e,"name",{value:o,configurable:!0});import*as s from"../../../lib/http.mjs";import{refused as g}from"../../../lib/images.mjs";const f="iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==";async function p({endpoint:e,transport:o,signal:r,timeout:A,facts:c,want:a={}}){const n={},i={"content-type":"application/json",...s.headers(e)},m=c?.models?.[0];if(a.inlineSystem!==!1){const t=await s.json(o,s.join(e.url,"/tokenize"),{method:"POST",headers:i,body:{model:m,messages:[{role:"system",content:"a"},{role:"user",content:"b"},{role:"system",content:"c"},{role:"user",content:"d"}]},signal:r,timeout:A});n.inlineSystem=t.ok?"keep":"user"}if(a.images===!0){const t=await s.json(o,s.join(e.url,"/v1/chat/completions"),{method:"POST",headers:i,body:{model:m,max_tokens:1,messages:[{role:"user",content:[{type:"text",text:"."},{type:"image_url",image_url:{url:`data:image/png;base64,${f}`}}]}]},signal:r,timeout:A});t.ok?n.images=!0:t.status===400&&g(JSON.stringify(t.body))&&(n.images=!1)}return n}l(p,"probe");export{p as probe};
|
|
2
|
+
//# sourceMappingURL=probe.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var e=(t,o)=>n(t,"name",{value:o,configurable:!0});import{noEmptyTools as s}from"../../../lib/normalize.mjs";const f=new Set(["xhigh","max"]);function u(t,o){const r=s(t);return f.has(r.reasoning_effort)&&o?.settings?.effortPassthrough!==!0?{...r,reasoning_effort:"high"}:r}e(u,"request");export{u as request};
|
|
2
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t=Object.defineProperty;var o=(e,r)=>t(e,"name",{value:r,configurable:!0});import{atLeast as n,semver as i}from"../../../lib/normalize.mjs";function a(e={}){return{reasoningField:n(e.version,"0.16.0")?"reasoning":"reasoning_content",thinkingBudget:i(e.version)!==null&&n(e.version,"0.19.0"),effort:n(e.version,"0.22.0"),maxTokensField:"max_completion_tokens",streamUsage:!0,continuousUsage:!0,prefill:"continue_final_message",topK:!0,responseFormat:!0}}o(a,"settings");export{a as settings};
|
|
2
|
+
//# sourceMappingURL=settings.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var s=(t,o)=>l(t,"name",{value:o,configurable:!0});import*as n from"../../../../lib/http.mjs";async function c({endpoint:t,request:o,transport:a,signal:r,timeout:d}){const e=await n.json(a,n.join(t.url,"/tokenize"),{method:"POST",headers:{"content-type":"application/json",...n.headers(t)},body:{model:o.model,messages:o.messages,tools:o.tools,add_generation_prompt:!0},signal:r,timeout:d});return e.ok&&typeof e.body?.count=="number"?e.body.count:null}s(c,"count");export{c as count};
|
|
2
|
+
//# sourceMappingURL=count.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var m=(s,t)=>r(s,"name",{value:t,configurable:!0});import{context as e}from"../../lib/runtime.mjs";import{describe as a}from"../../lib/pool.mjs";function u(){const{config:s,state:t}=e;return{...s.pool,endpoints:t.endpoints.map(o=>({name:o.name,url:o.url,models:o.models??o.facts?.models??[],...a(o)}))}}m(u,"status");export{u as status};
|
|
2
|
+
//# sourceMappingURL=status.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(r,t)=>a(r,"name",{value:t,configurable:!0});import{context as c}from"../../lib/runtime.mjs";import{anthropicToOpenAIType as d}from"../../lib/errors.mjs";import*as m from"../../lib/upstream-error.mjs";function u(r,t,e={}){const n=e.front??c.config.front,p=m.render(n,r,{message:t,type:n==="openai"&&e.type?d(e.type):e.type,code:e.code,param:e.param},{native:!0});return{status:r,headers:{"content-type":"application/json"},body:p.body}}o(u,"build");export{u as build};
|
|
2
|
+
//# sourceMappingURL=build.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var y=Object.defineProperty;var p=(e,i)=>y(e,"name",{value:i,configurable:!0});import{context as v,self as g}from"../../lib/runtime.mjs";import{capture as b}from"../../lib/capture.mjs";import*as u from"../../lib/upstream-error.mjs";import*as l from"../../lib/tools.mjs";const h=["retry-after","x-should-retry"];async function x(e,i,f={},r){const t=b(g,v,r?.front),o=r?t.endpoint(r.upstream):void 0,a=o?t.driver(o):void 0;let s=i;a?.error&&(s=await a.error(e,s,{endpoint:o,state:r}));const n=u.parse(s,e);r?.unserved===!0&&e===404&&(n.message+=` The model "${r.model}" is not served by any configured upstream; map it to a served model with "aliases".`),e===400&&l.refused(n.message)&&(n.message+=` ${l.hint(o?t.settings(o).toolFallback:!1,n.message)}`);const m=u.render(t.front,e,n,{native:r?.native===!0}),c={"content-type":"application/json"};for(const d of h)f[d]!==void 0&&(c[d]=f[d]);return{status:m.status,headers:c,body:m.body}}p(x,"error");export{x as default};
|
|
2
|
+
//# sourceMappingURL=error.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var d=Object.defineProperty;var r=(o,t)=>d(o,"name",{value:t,configurable:!0});import{context as m,self as s}from"../../lib/runtime.mjs";import{TranslatorError as c}from"../../lib/errors.mjs";async function p(o,t={}){const e=t.front??m.config.front,{data:f}=await s.model.list(t),n=f.find(a=>a.id===o);if(n)return n;throw new c(e==="openai"?`The model '${o}' does not exist`:`model: ${o}`,{code:"model_not_found",status:404,param:"model"})}r(p,"get");export{p as get};
|
|
2
|
+
//# sourceMappingURL=get.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var c=Object.defineProperty;var d=(a,t)=>c(a,"name",{value:t,configurable:!0});import{context as r,self as f}from"../../lib/runtime.mjs";import{capture as _}from"../../lib/capture.mjs";async function w(a={}){const t=_(f,r,a.front),s=new Map;await Promise.all(t.state.endpoints.map(async e=>{const o=t.driver(e),m=(o.list?await o.list({endpoint:e,transport:t.state.transport,signal:a.signal,timeout:t.config.detectTimeout}):null)??(e.models??e.facts?.models??[]).map(l=>({id:l}));for(const l of m)s.set(l.id,{...l,upstream:e.name})}));for(const e of Object.keys(t.config.aliases)){const o=s.get(t.config.aliases[e]);s.set(e,{...o,id:e})}const n=[...s.values()];if(t.front==="openai")return{object:"list",data:n.map(e=>({id:e.id,object:"model",created:e.created??0,owned_by:e.owned_by??e.upstream??"llm-translator",...e.max_model_len===void 0?{}:{max_model_len:e.max_model_len}}))};const i=n.map(e=>({type:"model",id:e.id,display_name:e.id,created_at:new Date((e.created??0)*1e3).toISOString(),...e.max_model_len===void 0?{}:{max_input_tokens:e.max_model_len}}));return{data:i,has_more:!1,first_id:i[0]?.id??null,last_id:i.at(-1)?.id??null}}d(w,"list");export{w as list};
|
|
2
|
+
//# sourceMappingURL=list.mjs.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var U=Object.defineProperty;var m=(e,a)=>U(e,"name",{value:a,configurable:!0});import{context as _,self as j}from"../lib/runtime.mjs";import{capture as q}from"../lib/capture.mjs";import{resolve as F}from"../lib/route.mjs";import*as w from"../lib/http.mjs";import{filterChatBody as S}from"../lib/passthrough.mjs";import*as k from"../lib/images.mjs";import*as $ from"../lib/tools.mjs";import{LIMITS as T}from"../lib/toolsearch.mjs";import{warn as u}from"../lib/warn.mjs";function L(e){return`${e.driver}:${e.protocol}:${URL.canParse(e.url)?new URL(e.url).host:e.url}`}m(L,"producerOf");async function H(e,a={}){const o=q(j,_,a.front),n=F(o,e,{endpoint:a.endpoint,advance:a.hold===!0&&a.endpoint===void 0});if(a.hold!==!0)return y(o,e,a,n);n.endpoint.health.inflight++;try{return await y(o,e,a,n)}catch(t){throw n.endpoint.health.inflight--,t}}m(H,"request");async function y(e,a,o,n){const{endpoint:t,model:h,unserved:b,convert:i,pool:x}=n,s=e.driver(t),d=`${t.name}
|
|
2
|
+
${h}`,g=o.images===!1||e.state.textOnly.has(d)&&e.settings(t).imageFallback,l=g?{...e.settings(t),images:!1}:e.settings(t),p=a.stream===!0;let r,f;if(i?({body:r,state:f}=await i.request(a,l,{producer:L(t),budget:o.budget}),f.toolSearch?.capped&&u(e.config,e.state,`Tool search: more than ${T.definitions} tool definitions came back in ToolSearch results for ${t.name}; the rest are not offered.`)):r=e.front==="openai"&&(o.filter??l.passthroughFilter===!0)?S(a,s.info.fields):{...a},o.usage===!0&&p&&e.front==="openai"){if(i)f.includeUsage=!0;else if(l.streamUsage){const c=r.stream_options&&typeof r.stream_options=="object"?r.stream_options:{};r.stream_options={...c,include_usage:!0}}}g&&!i&&e.front==="openai"&&(r=k.strip(r)),o.tools===!1&&(r=$.strip(r)),r.model=h,f?.reasoningMissing&&u(e.config,e.state,`Upstream ${t.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.`),s.request&&(r=await s.request(r,{endpoint:t,settings:l,state:f,warn:m(c=>u(e.config,e.state,c),"warn")}));const v=t.protocol==="openai.chat"?s.info.paths.chat:s.info.paths.messages;return{upstream:t.name,pool:x.map(c=>c.name),method:"POST",url:w.join(t.url,v),path:v,headers:{"content-type":"application/json",accept:p?"text/event-stream":"application/json",...s.info.headers,...i===null&&t.protocol==="anthropic.messages"?o.clientHeaders:void 0,...w.headers(t,s.info.auth,o.headers)},body:r,state:{v:1,upstream:t.name,front:e.front,native:i===null,model:a.model,stream:p,unserved:b,convert:f},images:{sent:k.carries(r),retry:l.imageFallback&&t.protocol==="openai.chat",key:d},tools:{sent:$.carries(r),retry:l.toolFallback&&t.protocol==="openai.chat"}}}m(y,"prepare");export{H as request};
|
|
3
|
+
//# sourceMappingURL=request.mjs.map
|