@cldmv/llm-translator 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +185 -2
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +17 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +2 -0
- package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +2 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +6 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +2 -0
- package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +2 -0
- package/dist/api/detect.mjs +2 -0
- package/dist/api/driver/anthropic/detect.mjs +2 -0
- package/dist/api/driver/anthropic/info.mjs +2 -0
- package/dist/api/driver/anthropic/model/list.mjs +2 -0
- package/dist/api/driver/anthropic/settings.mjs +2 -0
- package/dist/api/driver/anthropic/token/count.mjs +2 -0
- package/dist/api/driver/compatible/detect.mjs +2 -0
- package/dist/api/driver/compatible/info.mjs +2 -0
- package/dist/api/driver/compatible/model/list.mjs +2 -0
- package/dist/api/driver/compatible/request.mjs +2 -0
- package/dist/api/driver/compatible/settings.mjs +2 -0
- package/dist/api/driver/openai/detect.mjs +2 -0
- package/dist/api/driver/openai/info.mjs +2 -0
- package/dist/api/driver/openai/model/list.mjs +2 -0
- package/dist/api/driver/openai/request.mjs +2 -0
- package/dist/api/driver/openai/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +2 -0
- package/dist/api/driver/vllm/error.mjs +2 -0
- package/dist/api/driver/vllm/info.mjs +2 -0
- package/dist/api/driver/vllm/model/list.mjs +2 -0
- package/dist/api/driver/vllm/probe.mjs +2 -0
- package/dist/api/driver/vllm/request.mjs +2 -0
- package/dist/api/driver/vllm/settings.mjs +2 -0
- package/dist/api/driver/vllm/token/count.mjs +2 -0
- package/dist/api/error/build.mjs +2 -0
- package/dist/api/error/error.mjs +2 -0
- package/dist/api/model/list.mjs +2 -0
- package/dist/api/request.mjs +3 -0
- package/dist/api/response.mjs +2 -0
- package/dist/api/send.mjs +2 -0
- package/dist/api/server/plugin.mjs +2 -0
- package/dist/api/server/start.mjs +2 -0
- package/dist/api/server/stop.mjs +2 -0
- package/dist/api/sse/encode.mjs +4 -0
- package/dist/api/sse/parse.mjs +2 -0
- package/dist/api/sse/ping.mjs +2 -0
- package/dist/api/sse/write.mjs +2 -0
- package/dist/api/status.mjs +2 -0
- package/dist/api/stream.mjs +2 -0
- package/dist/api/token/count.mjs +2 -0
- package/dist/bin/llm-translator.mjs +3 -0
- package/dist/index.cjs +44 -0
- package/dist/index.mjs +2 -0
- package/dist/lib/arguments.mjs +2 -0
- package/dist/lib/capture.mjs +2 -0
- package/dist/lib/cli.mjs +29 -0
- package/dist/lib/config.mjs +2 -0
- package/dist/lib/documents.mjs +12 -0
- package/dist/lib/errors.mjs +2 -0
- package/dist/lib/estimate.mjs +2 -0
- package/dist/lib/finish.mjs +2 -0
- package/dist/lib/http.mjs +2 -0
- package/dist/lib/ids.mjs +2 -0
- package/dist/lib/images.mjs +2 -0
- package/dist/lib/models.mjs +2 -0
- package/dist/lib/normalize.mjs +2 -0
- package/dist/lib/passthrough.mjs +2 -0
- package/dist/lib/pdf.mjs +2 -0
- package/dist/lib/ping.mjs +2 -0
- package/dist/lib/route.mjs +2 -0
- package/dist/lib/routes.mjs +2 -0
- package/dist/lib/runtime.mjs +2 -0
- package/dist/lib/schema.mjs +2 -0
- package/dist/lib/settings.mjs +2 -0
- package/dist/lib/source.mjs +2 -0
- package/dist/lib/sse.mjs +10 -0
- package/dist/lib/thinking.mjs +2 -0
- package/dist/lib/transport.mjs +2 -0
- package/dist/lib/upstream-error.mjs +2 -0
- package/dist/lib/warn.mjs +2 -0
- package/package.json +127 -5
- package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +28 -0
- package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +24 -0
- package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +29 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +30 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +28 -0
- package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +38 -0
- package/types/src/api/detect.d.mts +21 -0
- package/types/src/api/driver/anthropic/detect.d.mts +26 -0
- package/types/src/api/driver/anthropic/info.d.mts +30 -0
- package/types/src/api/driver/anthropic/model/list.d.mts +20 -0
- package/types/src/api/driver/anthropic/settings.d.mts +23 -0
- package/types/src/api/driver/anthropic/token/count.d.mts +20 -0
- package/types/src/api/driver/compatible/detect.d.mts +23 -0
- package/types/src/api/driver/compatible/info.d.mts +29 -0
- package/types/src/api/driver/compatible/model/list.d.mts +20 -0
- package/types/src/api/driver/compatible/request.d.mts +20 -0
- package/types/src/api/driver/compatible/settings.d.mts +23 -0
- package/types/src/api/driver/openai/detect.d.mts +26 -0
- package/types/src/api/driver/openai/info.d.mts +29 -0
- package/types/src/api/driver/openai/model/list.d.mts +20 -0
- package/types/src/api/driver/openai/request.d.mts +20 -0
- package/types/src/api/driver/openai/settings.d.mts +23 -0
- package/types/src/api/driver/vllm/detect.d.mts +20 -0
- package/types/src/api/driver/vllm/error.d.mts +28 -0
- package/types/src/api/driver/vllm/info.d.mts +29 -0
- package/types/src/api/driver/vllm/model/list.d.mts +20 -0
- package/types/src/api/driver/vllm/probe.d.mts +39 -0
- package/types/src/api/driver/vllm/request.d.mts +22 -0
- package/types/src/api/driver/vllm/settings.d.mts +22 -0
- package/types/src/api/driver/vllm/token/count.d.mts +20 -0
- package/types/src/api/error/build.d.mts +26 -0
- package/types/src/api/error/error.d.mts +29 -0
- package/types/src/api/model/list.d.mts +21 -0
- package/types/src/api/request.d.mts +35 -0
- package/types/src/api/response.d.mts +22 -0
- package/types/src/api/send.d.mts +32 -0
- package/types/src/api/server/plugin.d.mts +24 -0
- package/types/src/api/server/start.d.mts +26 -0
- package/types/src/api/server/stop.d.mts +19 -0
- package/types/src/api/sse/encode.d.mts +26 -0
- package/types/src/api/sse/parse.d.mts +24 -0
- package/types/src/api/sse/ping.d.mts +30 -0
- package/types/src/api/sse/write.d.mts +26 -0
- package/types/src/api/status.d.mts +22 -0
- package/types/src/api/stream.d.mts +25 -0
- package/types/src/api/token/count.d.mts +24 -0
- package/types/src/index.d.mts +76 -0
- package/types/src/lib/arguments.d.mts +30 -0
- package/types/src/lib/capture.d.mts +28 -0
- package/types/src/lib/cli.d.mts +49 -0
- package/types/src/lib/config.d.mts +65 -0
- package/types/src/lib/documents.d.mts +43 -0
- package/types/src/lib/errors.d.mts +144 -0
- package/types/src/lib/estimate.d.mts +24 -0
- package/types/src/lib/finish.d.mts +73 -0
- package/types/src/lib/http.d.mts +58 -0
- package/types/src/lib/ids.d.mts +55 -0
- package/types/src/lib/images.d.mts +39 -0
- package/types/src/lib/models.d.mts +25 -0
- package/types/src/lib/normalize.d.mts +37 -0
- package/types/src/lib/passthrough.d.mts +22 -0
- package/types/src/lib/pdf.d.mts +67 -0
- package/types/src/lib/ping.d.mts +24 -0
- package/types/src/lib/route.d.mts +38 -0
- package/types/src/lib/routes.d.mts +22 -0
- package/types/src/lib/runtime.d.mts +24 -0
- package/types/src/lib/schema.d.mts +22 -0
- package/types/src/lib/settings.d.mts +175 -0
- package/types/src/lib/source.d.mts +32 -0
- package/types/src/lib/sse.d.mts +72 -0
- package/types/src/lib/thinking.d.mts +60 -0
- package/types/src/lib/transport.d.mts +31 -0
- package/types/src/lib/upstream-error.d.mts +57 -0
- package/types/src/lib/warn.d.mts +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,186 @@
|
|
|
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]
|
|
10
|
+
|
|
11
|
+
> [!NOTE]
|
|
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
|
+
---
|
|
17
|
+
|
|
18
|
+
## ✨ What's New
|
|
19
|
+
|
|
20
|
+
### Latest: v0.2.0 (October 2026)
|
|
21
|
+
|
|
22
|
+
- **The translator** — six converters between the Anthropic Messages API and OpenAI Chat Completions (requests, responses and streams, both directions), backend detection with `vllm`, `openai`, `anthropic` and generic `compatible` drivers, model aliases and routing, and `createTranslator` with `request`, `response`, `stream`, `send` and `detect`. Text, images, PDFs, tools and reasoning are mapped; whatever has no counterpart is dropped, rejected or replaced by a note, never guessed.
|
|
23
|
+
- **Server and CLI for Claude Code** — an Anthropic or OpenAI front over Fastify (optional peer dependency) and the `llm-translator` command. Slow upstreams are supported: no transport timeouts, and early `message_start` plus keep-alive deltas satisfy Claude Code's stream watchdog during long prefills. Models that refuse images are detected at startup or on the first refusal and retried once without them.
|
|
24
|
+
- [View full v0.2.0 Changelog](https://github.com/CLDMV/llm-translator/blob/master/docs/changelog/v0/v0.2.0.md)
|
|
25
|
+
|
|
26
|
+
### Recent Releases
|
|
27
|
+
|
|
28
|
+
- **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))
|
|
29
|
+
|
|
30
|
+
📚 **For complete version history and detailed release notes, see the [docs/changelog/](https://github.com/CLDMV/llm-translator/tree/master/docs/changelog/) folder.**
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🚀 Key Features
|
|
35
|
+
|
|
36
|
+
### 🔁 **Both Directions**
|
|
37
|
+
|
|
38
|
+
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.
|
|
39
|
+
|
|
40
|
+
### 🔎 **Backend Detection**
|
|
41
|
+
|
|
42
|
+
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).
|
|
43
|
+
|
|
44
|
+
### 🧠 **Reasoning and Tools**
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
### 📄 **Images and PDFs**
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
### 🖥 **Server and CLI**
|
|
53
|
+
|
|
54
|
+
`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).
|
|
55
|
+
|
|
56
|
+
### 🛡 **100% Test Coverage**
|
|
57
|
+
|
|
58
|
+
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).
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 📦 Installation
|
|
63
|
+
|
|
64
|
+
### Requirements
|
|
65
|
+
|
|
66
|
+
- Node.js 22.15 or newer
|
|
67
|
+
- Fastify 5, only for the server and the Fastify plugin (an optional peer dependency)
|
|
68
|
+
|
|
69
|
+
### Install
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm install @cldmv/llm-translator
|
|
73
|
+
npm install fastify # only for the server and the Fastify plugin
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 🚀 Quick Start
|
|
79
|
+
|
|
80
|
+
### Library
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import { createTranslator } from "@cldmv/llm-translator";
|
|
84
|
+
|
|
85
|
+
const api = await createTranslator({
|
|
86
|
+
front: "anthropic", // the protocol your client speaks
|
|
87
|
+
upstreams: ["http://gpu-box:8000"], // vLLM is detected automatically
|
|
88
|
+
aliases: { "claude-opus-5-5": "qwen3-coder" }
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Pure conversion, no I/O: build the upstream call yourself.
|
|
92
|
+
const call = await api.request({ model: "claude-opus-5-5", max_tokens: 256, messages: [{ role: "user", content: "hi" }] });
|
|
93
|
+
// call.url, call.headers, call.body ...
|
|
94
|
+
// api.response(upstreamJson, call.state) converts a reply back,
|
|
95
|
+
// api.stream(upstreamSseBody, call.state) turns a stream into Anthropic events.
|
|
96
|
+
|
|
97
|
+
// Or let the translator do the full round trip.
|
|
98
|
+
const reply = await api.send({ model: "qwen3-coder", max_tokens: 256, stream: true, messages: [{ role: "user", content: "hi" }] });
|
|
99
|
+
if (reply.stream) for await (const { event, data } of reply.stream) console.log(event, data);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Server and Claude Code
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npx llm-translator --upstream http://gpu-box:8000 --port 8787 --model claude-opus-5-5=qwen3-coder
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
const server = await api.server.start({ port: 8787 });
|
|
110
|
+
console.log(server.url);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
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).
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 📚 Configuration
|
|
118
|
+
|
|
119
|
+
`createTranslator(config)` takes `front`, `upstreams` (URLs or objects with `url`, `apiKey`, `backend`, `models`, `default` and `settings`), `aliases`, global `settings`, `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.
|
|
120
|
+
|
|
121
|
+
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).
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 📚 Documentation
|
|
126
|
+
|
|
127
|
+
### Reference
|
|
128
|
+
|
|
129
|
+
- [Server and CLI](https://github.com/CLDMV/llm-translator/blob/master/docs/server.md)
|
|
130
|
+
- [Settings](https://github.com/CLDMV/llm-translator/blob/master/docs/settings.md)
|
|
131
|
+
- [Protocol support](https://github.com/CLDMV/llm-translator/blob/master/docs/protocol-support.md)
|
|
132
|
+
- [Drivers, detection and routing](https://github.com/CLDMV/llm-translator/blob/master/docs/drivers.md)
|
|
133
|
+
|
|
134
|
+
### Guides
|
|
135
|
+
|
|
136
|
+
- [Claude Code against vLLM](https://github.com/CLDMV/llm-translator/blob/master/docs/claude-code.md)
|
|
137
|
+
- [Testing and the real-backend harness](https://github.com/CLDMV/llm-translator/blob/master/docs/testing.md)
|
|
138
|
+
- [Known limitations](https://github.com/CLDMV/llm-translator/blob/master/docs/known-limitations.md)
|
|
139
|
+
- [Feature inventory](https://github.com/CLDMV/llm-translator/blob/master/docs/feature-inventory.md)
|
|
140
|
+
- [Design decisions](https://github.com/CLDMV/llm-translator/blob/master/docs/decisions.md)
|
|
141
|
+
|
|
142
|
+
### Repo
|
|
143
|
+
|
|
144
|
+
[![npm unpacked size]][npm_size_url] [![Repo size]][repo_size_url]
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 🔗 Links
|
|
149
|
+
|
|
150
|
+
- **npm**: [@cldmv/llm-translator](https://www.npmjs.com/package/@cldmv/llm-translator)
|
|
151
|
+
- **GitHub**: [CLDMV/llm-translator](https://github.com/CLDMV/llm-translator)
|
|
152
|
+
- **Issues**: [GitHub Issues](https://github.com/CLDMV/llm-translator/issues)
|
|
153
|
+
- **Releases**: [GitHub Releases](https://github.com/CLDMV/llm-translator/releases)
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 📄 License
|
|
158
|
+
|
|
159
|
+
[![GitHub license]][github_license_url] [![npm license]][npm_license_url]
|
|
160
|
+
|
|
161
|
+
Apache-2.0 © Shinrai / CLDMV
|
|
162
|
+
|
|
163
|
+
[npm version]: https://img.shields.io/npm/v/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
164
|
+
[npm_version_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
165
|
+
[npm downloads]: https://img.shields.io/npm/dm/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
166
|
+
[npm_downloads_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
167
|
+
[github downloads]: https://img.shields.io/github/downloads/CLDMV/llm-translator/total?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
168
|
+
[github_downloads_url]: https://github.com/CLDMV/llm-translator/releases
|
|
169
|
+
[last commit]: https://img.shields.io/github/last-commit/CLDMV/llm-translator?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
170
|
+
[last_commit_url]: https://github.com/CLDMV/llm-translator/commits
|
|
171
|
+
[npm last update]: https://img.shields.io/npm/last-update/%40cldmv%2Fllm-translator?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
172
|
+
[npm_last_update_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
173
|
+
[npm unpacked size]: https://img.shields.io/npm/unpacked-size/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
174
|
+
[npm_size_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
175
|
+
[repo size]: https://img.shields.io/github/repo-size/CLDMV/llm-translator?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
176
|
+
[repo_size_url]: https://github.com/CLDMV/llm-translator
|
|
177
|
+
[github license]: https://img.shields.io/github/license/CLDMV/llm-translator.svg?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
178
|
+
[github_license_url]: https://github.com/CLDMV/llm-translator/blob/HEAD/LICENSE
|
|
179
|
+
[npm license]: https://img.shields.io/npm/l/%40cldmv%2Fllm-translator.svg?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837
|
|
180
|
+
[npm_license_url]: https://www.npmjs.com/package/@cldmv/llm-translator
|
|
181
|
+
[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
|
|
182
|
+
[coverage_url]: https://github.com/CLDMV/llm-translator/blob/badges/coverage.json
|
|
183
|
+
[contributors]: https://img.shields.io/github/contributors/CLDMV/llm-translator.svg?style=for-the-badge&logo=github&logoColor=white&labelColor=181717
|
|
184
|
+
[contributors_url]: https://github.com/CLDMV/llm-translator/graphs/contributors
|
|
185
|
+
[sponsor shinrai]: https://img.shields.io/github/sponsors/shinrai?style=for-the-badge&logo=githubsponsors&logoColor=white&labelColor=EA4AAA&label=Sponsor
|
|
186
|
+
[sponsor_url]: https://github.com/sponsors/shinrai
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var q=Object.defineProperty;var p=(e,s)=>q(e,"name",{value:s,configurable:!0});import{resolve as v}from"../../../../../../../lib/settings.mjs";import{TranslatorError as w}from"../../../../../../../lib/errors.mjs";import{createNameFitter as E}from"../../../../../../../lib/ids.mjs";import{sanitize as O}from"../../../../../../../lib/schema.mjs";import{NOTE as I}from"../../../../../../../lib/images.mjs";import{expand as A}from"../../../../../../../lib/documents.mjs";const B=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"]),L=new Set(["metadata","cache_control","service_tier"]),M=new Set(["mcp_servers","container","inference_geo"]),z="x-anthropic-billing-header:";async function b(e,s){const t=v(s);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new w("messages: Field required",{code:"invalid_request",param:"messages"});const o={front:"anthropic",model:e.model,stream:e.stream===!0,thinking:e.thinking?.type??null,reasoningField:t.reasoningField,toolNames:{},dropped:[]},f=E({max:64,map:o.toolNames});for(const c of Object.keys(e))if(!(B.has(c)||L.has(c)))if(M.has(c))g(o,c);else{if(t.unknownFields==="error")throw new w(`${c}: Extra inputs are not permitted`,{code:"unsupported_field",param:c});g(o,c)}const n={model:e.model},u=F(e.system,t),_=await C(e.messages,t,o,f,u,D(e.context_management,o));n.messages=_.messages,_.prefill&&(n.continue_final_message=!0,n.add_generation_prompt=!1),e.max_tokens!==void 0&&(n[t.maxTokensField]=e.max_tokens),e.temperature!==void 0&&(n.temperature=e.temperature),e.top_p!==void 0&&(n.top_p=e.top_p),e.top_k!==void 0&&(t.topK?n.top_k=e.top_k:g(o,"top_k")),e.stop_sequences?.length>0&&(n.stop=e.stop_sequences),o.stream&&(n.stream=!0,t.streamUsage&&(n.stream_options={include_usage:!0},t.continuousUsage&&(n.stream_options.continuous_usage_stats=!0)));const d=H(e.tools??[],t,o,f);if(d.length>0){n.tools=d;const c=K(e.tool_choice,t,o,f);c!==void 0&&(n.tool_choice=c),e.tool_choice?.disable_parallel_tool_use===!0&&t.parallelToolCalls&&(n.parallel_tool_calls=!1)}return U(e,t,n),G(e,t,o,n),{body:n,state:o}}p(b,"request");function g(e,s){e.dropped.includes(s)||e.dropped.push(s)}p(g,"drop");function j(e,s,t){if(s.unknownFields==="error")throw new w(`${t}: is not supported by this translator`,{code:"unsupported_content",param:t});g(e,t)}p(j,"unsupported");function F(e,s){return e==null?"":(typeof e=="string"?[{type:"text",text:e}]:e).filter(o=>o.type==="text"&&!(s.stripBillingHeader&&o.text.trimStart().startsWith(z))).map(o=>o.text).join(`
|
|
2
|
+
|
|
3
|
+
`)}p(F,"textOf");function T(e){return typeof e=="string"?[{type:"text",text:e}]:e??[]}p(T,"asBlocks");async function C(e,s,t,o,f,n){const u=[],_=[],d=new Map,c=s.inlineSystem==="auto"?"user":s.inlineSystem,a=p(i=>{const r=u.at(-1);r?.role==="user"?r.parts.push(...i):u.push({role:"user",parts:i})},"pushUser"),h=p(async(i,r)=>{switch(i.type){case"text":return i.text===""?[]:[{type:"text",text:i.text}];case"image":return W(i,s,t);case"document":{const m=[];for(const l of await A(i,{settings:s,toolInputs:d,toolUseId:r}))m.push(...await h(l,r));return m}case"search_result":{const m=(i.content??[]).map(l=>l.text).join(`
|
|
4
|
+
`);return[{type:"text",text:`[Search result: ${i.title??""} (${i.source??""})]
|
|
5
|
+
${m}`}]}case"tool_reference":return[{type:"text",text:`[Tool reference: ${i.tool_name}]`}];default:return j(t,s,`block:${i.type}`),[]}},"toParts");for(const i of e)if(i.role==="system"){const r=F(i.content,s);if(r===""||c==="drop")continue;if(c==="keep")u.push({role:"system",content:r});else if(c==="hoist")_.push(r);else{const m=r.trimStart().startsWith("<system-reminder>")?r:`<system-reminder>
|
|
6
|
+
${r}
|
|
7
|
+
</system-reminder>`;a([{type:"text",text:m}])}}else if(i.role==="user"){const r=[],m=[];for(const x of T(i.content)){if(x.type!=="tool_result"){r.push(...await h(x,null));continue}const $=[];for(const k of T(x.content))$.push(...await h(k,x.tool_use_id));const N=$.filter(k=>k.type==="text").map(k=>k.text),S=$.filter(k=>k.type==="image_url");let y=N.join(`
|
|
8
|
+
`);S.length>0&&(m.push({type:"text",text:`Image output of tool call ${x.tool_use_id}:`},...S),y===""&&(y="(image output attached in the next message)")),x.is_error===!0&&s.toolErrors&&(y=`[error] ${y}`),u.push({role:"tool",tool_call_id:x.tool_use_id,content:y})}const l=[...m,...r];l.length>0&&a(l)}else if(i.role==="assistant"){const r={role:"assistant",texts:[],reasoning:[],tool_calls:[]};for(const l of T(i.content))l.type==="text"?l.text!==""&&r.texts.push(l.text):l.type==="thinking"?l.thinking&&r.reasoning.push(l.thinking):l.type==="redacted_thinking"?g(t,"redacted_thinking"):l.type==="tool_use"?(d.set(l.id,l.input),r.tool_calls.push({id:l.id,type:"function",function:{name:o(l.name),arguments:JSON.stringify(l.input??{})}})):j(t,s,`block:${l.type}`);const m=u.at(-1);m?.role==="assistant"?(m.texts.push(...r.texts),m.reasoning.push(...r.reasoning),m.tool_calls.push(...r.tool_calls)):u.push(r)}else throw new w(`messages: unsupported role "${i.role}"`,{code:"invalid_request",param:"messages"});return P(u,s,f,_,n)}p(C,"convertMessages");function D(e,s){let t=1/0;for(const o of e?.edits??[])typeof o.type=="string"&&o.type.startsWith("clear_thinking")?o.keep==="all"?t=1/0:t=o.keep?.value??1:g(s,`context_management.${o.type}`);return t}p(D,"thinkingTurnsToKeep");function P(e,s,t,o,f){let n=f;for(let a=e.length-1;a>=0;a--)e[a].role!=="assistant"||e[a].reasoning.length===0||(n>0?n--:e[a].reasoning=[]);const u=[],_=[t,...o].filter(a=>a!=="").join(`
|
|
9
|
+
|
|
10
|
+
`);_!==""&&u.push({role:"system",content:_});for(const a of e)if(a.role==="user"){const h=a.parts.every(i=>i.type==="text");u.push({role:"user",content:h?a.parts.map(i=>i.text).join(`
|
|
11
|
+
|
|
12
|
+
`):a.parts})}else if(a.role==="assistant"){const h={role:"assistant",content:a.texts.join(`
|
|
13
|
+
|
|
14
|
+
`)};a.reasoning.length>0&&(h[s.reasoningField]=a.reasoning.join(`
|
|
15
|
+
|
|
16
|
+
`)),a.tool_calls.length>0&&(h.tool_calls=a.tool_calls),u.push(h)}else u.push(a);const d=u.at(-1),c=s.prefill==="continue_final_message"&&d?.role==="assistant"&&!d.tool_calls&&d.content!=="";return{messages:u,prefill:c}}p(P,"finalize");function W(e,s,t){if(!s.images)return g(t,"image"),[{type:"text",text:I}];const o=e.source;return o.type==="base64"?[{type:"image_url",image_url:{url:`data:${o.media_type};base64,${o.data}`}}]:o.type==="url"?[{type:"image_url",image_url:{url:o.url}}]:(g(t,"image.file"),[{type:"text",text:"[An image supplied as an uploaded file could not be forwarded.]"}])}p(W,"imageParts");function H(e,s,t,o){const f=[];for(const n of e){if(n.type!==void 0&&n.type!=="custom"){g(t,`tool:${n.name}`);continue}if(n.defer_loading===!0&&s.deferredTools==="drop"){g(t,"deferred_tools");continue}const u=n.input_schema??{type:"object",properties:{}},_={name:o(n.name),parameters:s.toolSchema==="sanitize"?O(u):u};n.description!==void 0&&(_.description=n.description),n.strict!==void 0&&(_.strict=n.strict),f.push({type:"function",function:_})}return f}p(H,"convertTools");function K(e,s,t,o){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:o(e.name)}};default:j(t,s,`tool_choice:${e.type}`);return}}p(K,"convertToolChoice");function U(e,s,t){const o=e.thinking,f=o?.type;let n;f==="disabled"?(s.thinking==="reasoning_effort"&&(n="none"),s.thinking==="chat_template_kwargs"&&(t.chat_template_kwargs={enable_thinking:!1})):(s.effort&&e.output_config?.effort!==void 0&&(n=e.output_config.effort),f==="enabled"&&(s.thinking==="chat_template_kwargs"&&(t.chat_template_kwargs={enable_thinking:!0},s.thinkingBudget&&o.budget_tokens!==void 0&&e.max_tokens!==void 0&&(t.thinking_token_budget=Math.max(0,Math.min(o.budget_tokens,e.max_tokens-1)))),s.thinking==="reasoning_effort"&&n===void 0&&(n="medium"))),n!==void 0&&(t.reasoning_effort=n)}p(U,"applyThinking");function G(e,s,t,o){const f=e.output_config?.format??e.output_format;f!==void 0&&(s.responseFormat&&f.type==="json_schema"?o.response_format={type:"json_schema",json_schema:{name:"output",schema:f.schema}}:g(t,"output_config.format"));for(const n of Object.keys(e.output_config??{}))n!=="effort"&&n!=="format"&&g(t,`output_config.${n}`)}p(G,"applyOutputConfig");export{b as request};
|
|
17
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var h=Object.defineProperty;var r=(o,n)=>h(o,"name",{value:n,configurable:!0});import{resolve as u}from"../../../../../../../lib/settings.mjs";import{restoreName as m}from"../../../../../../../lib/ids.mjs";import{toOpenAIFinish as g,toOpenAIUsage as d}from"../../../../../../../lib/finish.mjs";function j(o,n,p){const a=u(p),f=n?.toolNames??{},i=[],s=[],e=[];for(const t of o.content??[])t.type==="text"?i.push(t.text):t.type==="thinking"?s.push(t.thinking):t.type==="tool_use"&&e.push({id:t.id,type:"function",function:{name:m(f,t.name),arguments:JSON.stringify(t.input??{})}});const c={role:"assistant",content:i.length===0&&e.length>0?null:i.join("")};s.length>0&&(c[a.reasoningField]=s.join("")),e.length>0&&(c.tool_calls=e);const l={index:0,message:c,finish_reason:g(o.stop_reason)};return typeof o.stop_sequence=="string"&&(l.stop_reason=o.stop_sequence),{id:`chatcmpl-${String(o.id).replace(/^msg_/,"")}`,object:"chat.completion",created:Math.floor(Date.now()/1e3),model:n?.model??o.model,choices:[l],usage:d(o.usage)}}r(j,"response");export{j as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var k=Object.defineProperty;var i=(l,o)=>k(l,"name",{value:o,configurable:!0});import{resolve as x}from"../../../../../../../lib/settings.mjs";import{anthropicToOpenAIType as b,anthropicTypeToStatus as O}from"../../../../../../../lib/errors.mjs";import{completionId as N,restoreName as j}from"../../../../../../../lib/ids.mjs";import{toOpenAIFinish as D,toOpenAIUsage as E}from"../../../../../../../lib/finish.mjs";import{messages as I}from"../../../../../../../lib/sse.mjs";async function*F(l,o,u){const g=x(u),_=o?.toolNames??{},h=o?.includeUsage??!0,f=Math.floor(Date.now()/1e3),s=new Map;let r=N(),c=o?.model,d={},y=!1;const n=i((e,t=null,a={})=>({data:{id:r,object:"chat.completion.chunk",created:f,model:c,choices:[{index:0,delta:e,finish_reason:t,...a}]}}),"chunk"),p=i((e,t)=>({data:{error:{message:t,type:b(e),param:null,code:O(e)}}}),"failure");try{for await(const{data:e}of I(l))if(e.type==="message_start")r=`chatcmpl-${String(e.message.id).replace(/^msg_/,"")}`,c=o?.model??e.message.model,d={...e.message.usage},yield n({role:"assistant",content:""});else if(e.type==="content_block_start"){const t=e.content_block;if(t.type==="tool_use"){s.set(e.index,s.size);const a=j(_,t.name);yield n({tool_calls:[{index:s.get(e.index),id:t.id,type:"function",function:{name:a,arguments:""}}]})}}else if(e.type==="content_block_delta"){const t=e.delta;t.type==="text_delta"?yield n({content:t.text}):t.type==="thinking_delta"?yield n({[g.reasoningField]:t.thinking}):t.type==="input_json_delta"&&s.has(e.index)&&(yield n({tool_calls:[{index:s.get(e.index),function:{arguments:t.partial_json}}]}))}else if(e.type==="message_delta"){for(const[a,m]of Object.entries(e.usage??{}))m!=null&&(d[a]=m);const t=typeof e.delta?.stop_sequence=="string"?{stop_reason:e.delta.stop_sequence}:{};yield n({},D(e.delta?.stop_reason),t)}else if(e.type==="message_stop"){y=!0;break}else if(e.type==="error"){yield p(e.error.type,e.error.message),yield{data:"[DONE]"};return}}catch(e){yield p(e.type??"api_error",e.message),yield{data:"[DONE]"};return}if(!y){yield p("api_error","Upstream stream ended before completion"),yield{data:"[DONE]"};return}h&&(yield{data:{id:r,object:"chat.completion.chunk",created:f,model:c,choices:[],usage:E(d)}}),yield{data:"[DONE]"}}i(F,"stream");export{F as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var j=Object.defineProperty;var u=(e,r)=>j(e,"name",{value:r,configurable:!0});import{resolve as q}from"../../../../../../../lib/settings.mjs";import{TranslatorError as _}from"../../../../../../../lib/errors.mjs";import{anthropicToolId as w,createNameFitter as v}from"../../../../../../../lib/ids.mjs";import{parseArguments as A}from"../../../../../../../lib/arguments.mjs";import{sanitize as T}from"../../../../../../../lib/schema.mjs";const N=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"]),$=new Set(["metadata","store","service_tier"]),x=/^data:([^;,]+);base64,(.*)$/s;async function O(e,r){const a=q(r);if(e===null||typeof e!="object"||!Array.isArray(e.messages))throw new _("messages is a required property",{code:"invalid_request",param:"messages"});if(e.n!==void 0&&e.n!==1)throw new _("n: only a single choice (n = 1) is supported",{code:"unsupported_field",param:"n"});const s={front:"openai",model:e.model,stream:e.stream===!0,includeUsage:e.stream_options?.include_usage===!0,reasoningField:a.reasoningField,toolNames:{},dropped:[]},l=v({max:128,map:s.toolNames});for(const t of Object.keys(e))if(!(N.has(t)||$.has(t))){if(a.unknownFields==="error")throw new _(`${t}: Unrecognized request argument`,{code:"unsupported_field",param:t});c(s,t)}const d=[],f=[],y=u((t,o)=>{const i=f.at(-1);i?.role===t?i.blocks.push(...o):f.push({role:t,blocks:[...o]})},"push");for(const t of e.messages)switch(t.role){case"system":case"developer":{const o=b(t.content);o!==""&&d.push(o);break}case"user":y("user",S(t.content,s));break;case"assistant":{const o=[],i=b(t.content);i!==""?o.push({type:"text",text:i}):typeof t.refusal=="string"&&t.refusal!==""&&o.push({type:"text",text:t.refusal}),F(t)&&c(s,"reasoning");for(const p of t.tool_calls??[])o.push({type:"tool_use",id:w(p.id),name:l(p.function.name),input:A(p.function.arguments)});o.length>0&&y("assistant",o);break}case"tool":{const o={type:"tool_result",tool_use_id:w(t.tool_call_id),content:b(t.content)},i=f.at(-1);if(i?.role==="user"){const p=i.blocks.findIndex(h=>h.type!=="tool_result");i.blocks.splice(p===-1?i.blocks.length:p,0,o)}else f.push({role:"user",blocks:[o]});break}default:throw new _(`messages: unsupported role "${t.role}"`,{code:"invalid_request",param:"messages"})}const n={model:e.model,max_tokens:e.max_completion_tokens??e.max_tokens??a.defaultMaxTokens};d.length>0&&(n.system=d.join(`
|
|
2
|
+
|
|
3
|
+
`)),n.messages=f.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)),s.stream&&(n.stream=!0),typeof e.user=="string"&&(n.metadata={user_id:e.user});const g=[];for(const t of e.tools??[]){if(t.type!=="function"){c(s,`tool:${t.type}`);continue}const o=t.function,i=o.parameters??{type:"object",properties:{}},p={name:l(o.name),input_schema:a.toolSchema==="sanitize"?T(i):i};o.description!==void 0&&(p.description=o.description),g.push(p)}if(g.length>0){n.tools=g;let t=z(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 m=e.reasoning_effort;m==="none"?n.thinking={type:"disabled"}:m!=null&&(n.thinking={type:"adaptive"},n.output_config={effort:m==="minimal"?"low":m});const k=e.response_format;return k?.type==="json_schema"?n.output_config={...n.output_config,format:{type:"json_schema",schema:k.json_schema.schema}}:k?.type==="json_object"&&c(s,"response_format"),{body:n,state:s}}u(O,"request");function c(e,r){e.dropped.includes(r)||e.dropped.push(r)}u(c,"drop");function F(e){return!!(e.reasoning||e.reasoning_content)}u(F,"reasoningPresent");function b(e){return typeof e=="string"?e:(e??[]).filter(r=>r.type==="text").map(r=>r.text).join(`
|
|
4
|
+
|
|
5
|
+
`)}u(b,"plainText");function S(e,r){if(typeof e=="string")return e===""?[]:[{type:"text",text:e}];const a=[];for(const s of e??[])if(s.type==="text")a.push({type:"text",text:s.text});else if(s.type==="image_url"){const l=x.exec(s.image_url.url);a.push({type:"image",source:l?{type:"base64",media_type:l[1],data:l[2]}:{type:"url",url:s.image_url.url}})}else if(s.type==="file"&&typeof s.file?.file_data=="string"&&x.test(s.file.file_data)){const l=x.exec(s.file.file_data);a.push({type:"document",source:{type:"base64",media_type:l[1],data:l[2]}})}else c(r,`content:${s.type}`);return a}u(S,"userBlocks");function z(e,r){return e==="none"?{type:"none"}:e==="required"?{type:"any"}:typeof e=="object"&&e!==null?{type:"tool",name:r(e.function.name)}:{type:"auto"}}u(z,"toolChoice");export{O as request};
|
|
6
|
+
//# sourceMappingURL=request.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=Object.defineProperty;var m=(s,n)=>u(s,"name",{value:n,configurable:!0});import{resolve as h}from"../../../../../../../lib/settings.mjs";import{TranslatorError as d}from"../../../../../../../lib/errors.mjs";import{messageId as y,anthropicToolId as _,restoreName as x}from"../../../../../../../lib/ids.mjs";import{sign as T,reasoningOf as k,splitThink as A}from"../../../../../../../lib/thinking.mjs";import{isComplete as C,parseArguments as N}from"../../../../../../../lib/arguments.mjs";import{toAnthropicStop as S,toAnthropicUsage as v}from"../../../../../../../lib/finish.mjs";function q(s,n,l){const c=h(l),r=s?.choices?.[0];if(!r)throw new d("Upstream response contained no choices",{code:"invalid_upstream_response",status:502});const e=r.message??{},o=[];let i=k(e),t=typeof e.content=="string"?e.content:"";i===""&&c.thinkTags&&({reasoning:i,text:t}=A(t)),i!==""&&(o.push({type:"thinking",thinking:i,signature:T()}),t=t.trimStart()),t===""&&typeof e.refusal=="string"&&(t=e.refusal),t!==""&&o.push({type:"text",text:t});const f=n?.toolNames??{},a=e.tool_calls??[];for(const p of a)o.push({type:"tool_use",id:_(p.id),name:x(f,p.function.name),input:N(p.function.arguments)});o.length===0&&o.push({type:"text",text:""});const g=S(r.finish_reason,{hasToolCalls:a.length>0,matchedStop:r.stop_reason,argumentsComplete:a.length===0||C(a.at(-1).function.arguments)});return{id:y(),type:"message",role:"assistant",model:n?.model??s.model,content:o,...g,usage:v(s.usage)}}m(q,"response");export{q as response};
|
|
2
|
+
//# sourceMappingURL=response.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var D=Object.defineProperty;var l=(g,f)=>D(g,"name",{value:f,configurable:!0});import{resolve as J}from"../../../../../../../lib/settings.mjs";import{TranslatorError as M,openaiToAnthropicType as F,rewriteContextOverflow as G}from"../../../../../../../lib/errors.mjs";import{isComplete as H}from"../../../../../../../lib/arguments.mjs";import{messageId as K,anthropicToolId as L,restoreName as P}from"../../../../../../../lib/ids.mjs";import{sign as Q,reasoningOf as R,createThinkSplitter as V}from"../../../../../../../lib/thinking.mjs";import{toAnthropicStop as W,toAnthropicUsage as U}from"../../../../../../../lib/finish.mjs";import{messages as X}from"../../../../../../../lib/sse.mjs";async function*se(g,f,A){const _=J(A),I=f?.toolNames??{},u=_.thinkTags?V():null,r=new Map;let p=!1,x=0,o=null,k=null,h=null,b=null,j=!1,T=0,S=!1;const N=[],s=l((e,t)=>({event:e,data:{type:e,...t}}),"event"),y=l((e,t)=>s("error",{error:{type:e,message:t}}),"fail");function*d(){if(o!==null){o.kind==="thinking"?yield s("content_block_delta",{index:o.index,delta:{type:"signature_delta",signature:Q()}}):o.kind==="tool"&&(o.entry.state="closed",o.entry.sent||(yield s("content_block_delta",{index:o.index,delta:{type:"input_json_delta",partial_json:"{}"}}))),yield s("content_block_stop",{index:o.index}),o=null;for(const e of r.values()){if(e.state!=="pending")continue;e.state="closed";const t=x++,n=e.args.join("");yield s("content_block_start",{index:t,content_block:e.block}),yield s("content_block_delta",{index:t,delta:{type:"input_json_delta",partial_json:n===""?"{}":n}}),yield s("content_block_stop",{index:t})}}}l(d,"close");function*z(){for(const e of v()){if(e.state!=="buffered")continue;yield*m("tool",e.block,e);const t=e.args.join("");t!==""&&(e.sent=!0,yield s("content_block_delta",{index:o.index,delta:{type:"input_json_delta",partial_json:t}})),yield*d()}}l(z,"flushBuffered");function v(){return[...r.entries()].sort((e,t)=>e[0]-t[0]).map(e=>e[1])}l(v,"ordered");function*m(e,t,n){yield*d(),o={kind:e,index:x++,entry:n},yield s("content_block_start",{index:o.index,content_block:t})}l(m,"begin");function*c(e,t){if(e==="text"&&S&&(t=t.trimStart()),t==="")return;if(S=e==="thinking",o?.kind==="tool"){N.push({kind:e,text:t});return}o?.kind!==e&&(yield*m(e,e==="text"?{type:"text",text:""}:{type:"thinking",thinking:"",signature:""}));const n=e==="text"?{type:"text_delta",text:t}:{type:"thinking_delta",thinking:t};yield s("content_block_delta",{index:o.index,delta:n})}l(c,"piece");function*w(e){yield*c("thinking",e.reasoning),yield*c("text",e.text)}l(w,"pieces");function*E(e){let t=e.index;t===void 0&&(t=e.id===void 0?T:r.size),T=t;let n=r.get(t);if(n===void 0){const a=e.function?.name??"",O={type:"tool_use",id:L(e.id),name:P(I,a),input:{}};n={state:_.toolStreaming==="buffer"?"buffered":"pending",sent:!1,args:[],block:O},r.set(t,n),_.toolStreaming!=="buffer"&&o?.kind!=="tool"&&(n.state="open",yield*m("tool",O,n))}let i=e.function?.arguments;i!==null&&typeof i=="object"&&(i=JSON.stringify(i)),!(i==null||i==="")&&(n.args.push(i),n.state==="open"&&(n.sent=!0,yield s("content_block_delta",{index:o.index,delta:{type:"input_json_delta",partial_json:i}})))}l(E,"toolCall");try{for await(const e of X(g)){if(e.data==="[DONE]"){j=!0;break}const t=e.data;if(t.error){const a=t.error.message??"Upstream error";yield y(F(t.error),G(a)??a);return}p||(p=!0,yield s("message_start",{message:{id:K(),type:"message",role:"assistant",model:f?.model??t.model,content:[],stop_reason:null,stop_sequence:null,usage:U(t.usage)}})),t.usage&&(k=t.usage);const n=t.choices?.[0];if(!n)continue;const i=n.delta??{};yield*c("thinking",R(i)),typeof i.content=="string"&&i.content!==""&&(u?yield*w(u.push(i.content)):yield*c("text",i.content));for(const a of i.tool_calls??[])yield*E(a);n.finish_reason&&(h=n.finish_reason),typeof n.stop_reason=="string"&&(b=n.stop_reason)}}catch(e){yield e instanceof M?y(e.type,e.message):y("api_error",e.message);return}if(!p||h===null&&!j){yield y("api_error",p?"Upstream stream ended before completion":"Upstream stream ended without data");return}u&&(yield*w(u.end())),yield*z();const C=v().at(-1),q=C===void 0||H(C.args.join(""));yield*d();for(const e of N)yield*c(e.kind,e.text);yield*d(),x===0&&(yield*m("text",{type:"text",text:""}),yield*d());const B=W(h,{hasToolCalls:r.size>0,matchedStop:b,argumentsComplete:q});yield s("message_delta",{delta:B,usage:U(k)}),yield s("message_stop",{})}l(se,"stream");export{se as stream};
|
|
2
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=Object.defineProperty;var i=(t,e)=>m(t,"name",{value:e,configurable:!0});import{context as u,self as l}from"../lib/runtime.mjs";import{capture as d}from"../lib/capture.mjs";import{TranslatorError as b}from"../lib/errors.mjs";import{warn as g}from"../lib/warn.mjs";async function p(t={}){const e=d(l,u),{status:n}=l,o=t.network!==!1,a={transport:e.state.transport,signal:t.signal,timeout:e.config.detectTimeout};return await Promise.all(e.state.endpoints.map(r=>w(e,r,o,a))),n()}i(p,"detect");async function w(t,e,n,o){let a,r=null;if(e.backend!=="auto"){if(a=t.drivers.find(s=>s.name===e.backend),!a)throw new b(`Unknown backend "${e.backend}" for upstream ${e.name}`,{code:"unknown_backend",status:500});r={version:e.version}}else if(n){for(const s of t.drivers)if(r=await v(s,{endpoint:e,...o}),r){a=s;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={},n&&e.backend==="auto"&&a.probe){const s=i(f=>e.settings[f]!==void 0||t.config.settings[f]!==void 0,"given"),c={inlineSystem:t.settings(e).inlineSystem==="auto",images:!s("images")};(c.inlineSystem||c.images)&&(e.probed=await a.probe({endpoint:e,facts:r,want:c,...o}))}r.reachable===!1&&g(t.config,t.state,`Upstream ${e.name} (${e.url}) did not answer detection; using the generic OpenAI-compatible driver`)}i(w,"bind");async function v(t,e){try{return await t.detect?.(e)??null}catch{return null}}i(v,"detectWith");export{p 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 u=Object.defineProperty;var a=(t,e)=>u(t,"name",{value:e,configurable:!0});import*as s from"../../../../lib/http.mjs";async function d({endpoint:t,request:e,transport:r,signal:i,timeout:p}){const o={...e};delete o.stream,delete o.max_tokens;const n=await s.json(r,s.join(t.url,"/v1/messages/count_tokens"),{method:"POST",headers:{"content-type":"application/json","anthropic-version":"2023-06-01",...s.headers(t,"x-api-key")},body:o,signal:i,timeout:p});return n.ok&&typeof n.body?.input_tokens=="number"?n.body.input_tokens:null}a(d,"count");export{d as count};
|
|
2
|
+
//# sourceMappingURL=count.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var a=(t,e)=>r(t,"name",{value:e,configurable:!0});import{fetchModels as c}from"../../../lib/models.mjs";async function d(t){const e=await c({...t,auth:"bearer"});return{reachable:e!==null,models:(e??[]).map(o=>o.id)}}a(d,"detect");export{d as detect};
|
|
2
|
+
//# sourceMappingURL=detect.mjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function c(){return{name:"compatible",protocol:"openai.chat",order:100,auth:"bearer",paths:{chat:"/v1/chat/completions",models:"/v1/models"}}}o(c,"info");export{c 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 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 y=Object.defineProperty;var a=(e,n)=>y(e,"name",{value:n,configurable:!0});import*as s from"../../../lib/http.mjs";async function f({endpoint:e,transport:n,signal:i,timeout:u}){const d={method:"GET",headers:s.headers(e),signal:i,timeout:u},[l,t]=await Promise.all([s.json(n,s.join(e.url,"/version"),d),s.json(n,s.join(e.url,"/v1/models"),d)]),m=typeof l.body?.version=="string"?l.body.version:void 0,r=Array.isArray(t.body?.data)?t.body.data:[];return!m&&!r.some(o=>o?.owned_by==="vllm")?null:{version:m,models:r.map(o=>o.id),maxModelLen:r.find(o=>typeof o.max_model_len=="number")?.max_model_len}}a(f,"detect");export{f 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 n=Object.defineProperty;var e=(o,t)=>n(o,"name",{value:t,configurable:!0});function a(){return{name:"vllm",protocol:"openai.chat",order:10,auth:"bearer",paths:{chat:"/v1/chat/completions",models:"/v1/models",tokenize:"/tokenize",version:"/version"}}}e(a,"info");export{a 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 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
|