@cldmv/llm-translator 0.1.0 → 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/README.md +176 -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/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.mjs +1 -1
- 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 +30 -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 +61 -4
- 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
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/lib/settings.mjs
|
|
5
|
+
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-25T13:31:30-07:00 (1792960290)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export type Settings = {
|
|
16
|
+
/**
|
|
17
|
+
* - How mid-conversation `role:"system"` messages are handled. `user` folds them into the adjacent user turn as `<system-reminder>` text, `keep` forwards them as system messages, `hoist` appends them to the leading system message, `drop` discards them. `auto` behaves like `user` unless a driver probed the chat template and resolved it.
|
|
18
|
+
*/
|
|
19
|
+
inlineSystem: "auto" | "keep" | "hoist" | "user" | "drop";
|
|
20
|
+
/**
|
|
21
|
+
* - Remove the `x-anthropic-billing-header` system block.
|
|
22
|
+
*/
|
|
23
|
+
stripBillingHeader: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* - Field used when SENDING reasoning to an OpenAI-style server (reading accepts both).
|
|
26
|
+
*/
|
|
27
|
+
reasoningField: "reasoning" | "reasoning_content";
|
|
28
|
+
/**
|
|
29
|
+
* - Parse a leading `<think>...</think>` in content as reasoning.
|
|
30
|
+
*/
|
|
31
|
+
thinkTags: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* - How Anthropic `thinking` is requested from the server.
|
|
34
|
+
*/
|
|
35
|
+
thinking: "chat_template_kwargs" | "reasoning_effort" | "none";
|
|
36
|
+
/**
|
|
37
|
+
* - Send `thinking_token_budget` for `thinking.type = "enabled"`.
|
|
38
|
+
*/
|
|
39
|
+
thinkingBudget: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* - Map `output_config.effort` to `reasoning_effort`.
|
|
42
|
+
*/
|
|
43
|
+
effort: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* - The model accepts images. When false images are replaced by a text note.
|
|
46
|
+
*/
|
|
47
|
+
images: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* - Retry a request once without images when an OpenAI-protocol upstream answers 400 that the model does not accept images, and remember that for the endpoint and model until the process ends.
|
|
50
|
+
*/
|
|
51
|
+
imageFallback: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* - How `document` blocks are handled.
|
|
54
|
+
*/
|
|
55
|
+
documents: "extract" | "note" | "error";
|
|
56
|
+
/**
|
|
57
|
+
* - Override for `document` conversion; returns Anthropic content blocks.
|
|
58
|
+
*/
|
|
59
|
+
documentConverter: ((block: object, ctx: object) => Promise<object[]> | object[]) | null;
|
|
60
|
+
/**
|
|
61
|
+
* - PDF handling: render page images, Anthropic-like limits, image budget and render scale.
|
|
62
|
+
*/
|
|
63
|
+
pdf: {
|
|
64
|
+
pages: boolean;
|
|
65
|
+
maxPages: number;
|
|
66
|
+
maxBytes: number;
|
|
67
|
+
maxImages: number;
|
|
68
|
+
scale: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* - Sanitize tool JSON Schemas (drop `$schema`, remove unbounded integer limits).
|
|
72
|
+
*/
|
|
73
|
+
toolSchema: "pass" | "sanitize";
|
|
74
|
+
/**
|
|
75
|
+
* - Forward `defer_loading` tools as plain function tools or drop them.
|
|
76
|
+
*/
|
|
77
|
+
deferredTools: "forward" | "drop";
|
|
78
|
+
/**
|
|
79
|
+
* - Prefix `is_error` tool results with `[error] `.
|
|
80
|
+
*/
|
|
81
|
+
toolErrors: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* - Field used for the output cap.
|
|
84
|
+
*/
|
|
85
|
+
maxTokensField: "max_completion_tokens" | "max_tokens";
|
|
86
|
+
/**
|
|
87
|
+
* - Request `stream_options.include_usage` on streamed requests.
|
|
88
|
+
*/
|
|
89
|
+
streamUsage: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* - Also request `stream_options.continuous_usage_stats` (vLLM extension; real OpenAI may reject it).
|
|
92
|
+
*/
|
|
93
|
+
continuousUsage: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* - Map a trailing assistant message to `continue_final_message`.
|
|
96
|
+
*/
|
|
97
|
+
prefill: "continue_final_message" | "none";
|
|
98
|
+
/**
|
|
99
|
+
* - Forward `top_k`.
|
|
100
|
+
*/
|
|
101
|
+
topK: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* - Map `output_config.format` to `response_format`.
|
|
104
|
+
*/
|
|
105
|
+
responseFormat: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* - Map `disable_parallel_tool_use` to `parallel_tool_calls: false`.
|
|
108
|
+
*/
|
|
109
|
+
parallelToolCalls: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* - Unknown request fields are dropped (and listed in `state.dropped`) or rejected.
|
|
112
|
+
*/
|
|
113
|
+
unknownFields: "drop" | "error";
|
|
114
|
+
/**
|
|
115
|
+
* - Milliseconds of upstream silence before the SSE writer emits a `ping` (0 disables).
|
|
116
|
+
*/
|
|
117
|
+
pingInterval: number;
|
|
118
|
+
/**
|
|
119
|
+
* - OpenAI to Anthropic streams: `buffer` holds each tool call until its arguments are complete and emits one whole `tool_use` block (text and thinking keep streaming and appear before the block); `stream` forwards argument fragments incrementally and holds text that arrives meanwhile until the tool blocks are done.
|
|
120
|
+
*/
|
|
121
|
+
toolStreaming: "buffer" | "stream";
|
|
122
|
+
/**
|
|
123
|
+
* - vLLM driver: send `xhigh` and `max` reasoning effort unchanged instead of clamping them to `high`.
|
|
124
|
+
*/
|
|
125
|
+
effortPassthrough: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* - Restrict bodies forwarded from the OpenAI front to an OpenAI-protocol upstream to standard Chat Completions fields plus documented vLLM extensions. Off in the library; the server turns it on unless set to false.
|
|
128
|
+
*/
|
|
129
|
+
passthroughFilter: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* - `max_tokens` used when an OpenAI request has none (Anthropic requires one).
|
|
132
|
+
*/
|
|
133
|
+
defaultMaxTokens: number;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Settings understood by the converters. Every key is optional when passed in; `resolve()` fills the rest.
|
|
137
|
+
* @typedef {object} Settings
|
|
138
|
+
* @property {"auto"|"keep"|"hoist"|"user"|"drop"} inlineSystem - How mid-conversation `role:"system"` messages are handled. `user` folds them into the adjacent user turn as `<system-reminder>` text, `keep` forwards them as system messages, `hoist` appends them to the leading system message, `drop` discards them. `auto` behaves like `user` unless a driver probed the chat template and resolved it.
|
|
139
|
+
* @property {boolean} stripBillingHeader - Remove the `x-anthropic-billing-header` system block.
|
|
140
|
+
* @property {"reasoning"|"reasoning_content"} reasoningField - Field used when SENDING reasoning to an OpenAI-style server (reading accepts both).
|
|
141
|
+
* @property {boolean} thinkTags - Parse a leading `<think>...</think>` in content as reasoning.
|
|
142
|
+
* @property {"chat_template_kwargs"|"reasoning_effort"|"none"} thinking - How Anthropic `thinking` is requested from the server.
|
|
143
|
+
* @property {boolean} thinkingBudget - Send `thinking_token_budget` for `thinking.type = "enabled"`.
|
|
144
|
+
* @property {boolean} effort - Map `output_config.effort` to `reasoning_effort`.
|
|
145
|
+
* @property {boolean} images - The model accepts images. When false images are replaced by a text note.
|
|
146
|
+
* @property {boolean} imageFallback - Retry a request once without images when an OpenAI-protocol upstream answers 400 that the model does not accept images, and remember that for the endpoint and model until the process ends.
|
|
147
|
+
* @property {"extract"|"note"|"error"} documents - How `document` blocks are handled.
|
|
148
|
+
* @property {((block: object, ctx: object) => Promise<object[]>|object[])|null} documentConverter - Override for `document` conversion; returns Anthropic content blocks.
|
|
149
|
+
* @property {{ pages: boolean, maxPages: number, maxBytes: number, maxImages: number, scale: number }} pdf - PDF handling: render page images, Anthropic-like limits, image budget and render scale.
|
|
150
|
+
* @property {"pass"|"sanitize"} toolSchema - Sanitize tool JSON Schemas (drop `$schema`, remove unbounded integer limits).
|
|
151
|
+
* @property {"forward"|"drop"} deferredTools - Forward `defer_loading` tools as plain function tools or drop them.
|
|
152
|
+
* @property {boolean} toolErrors - Prefix `is_error` tool results with `[error] `.
|
|
153
|
+
* @property {"max_completion_tokens"|"max_tokens"} maxTokensField - Field used for the output cap.
|
|
154
|
+
* @property {boolean} streamUsage - Request `stream_options.include_usage` on streamed requests.
|
|
155
|
+
* @property {boolean} continuousUsage - Also request `stream_options.continuous_usage_stats` (vLLM extension; real OpenAI may reject it).
|
|
156
|
+
* @property {"continue_final_message"|"none"} prefill - Map a trailing assistant message to `continue_final_message`.
|
|
157
|
+
* @property {boolean} topK - Forward `top_k`.
|
|
158
|
+
* @property {boolean} responseFormat - Map `output_config.format` to `response_format`.
|
|
159
|
+
* @property {boolean} parallelToolCalls - Map `disable_parallel_tool_use` to `parallel_tool_calls: false`.
|
|
160
|
+
* @property {"drop"|"error"} unknownFields - Unknown request fields are dropped (and listed in `state.dropped`) or rejected.
|
|
161
|
+
* @property {number} pingInterval - Milliseconds of upstream silence before the SSE writer emits a `ping` (0 disables).
|
|
162
|
+
* @property {"buffer"|"stream"} toolStreaming - OpenAI to Anthropic streams: `buffer` holds each tool call until its arguments are complete and emits one whole `tool_use` block (text and thinking keep streaming and appear before the block); `stream` forwards argument fragments incrementally and holds text that arrives meanwhile until the tool blocks are done.
|
|
163
|
+
* @property {boolean} effortPassthrough - vLLM driver: send `xhigh` and `max` reasoning effort unchanged instead of clamping them to `high`.
|
|
164
|
+
* @property {boolean} passthroughFilter - Restrict bodies forwarded from the OpenAI front to an OpenAI-protocol upstream to standard Chat Completions fields plus documented vLLM extensions. Off in the library; the server turns it on unless set to false.
|
|
165
|
+
* @property {number} defaultMaxTokens - `max_tokens` used when an OpenAI request has none (Anthropic requires one).
|
|
166
|
+
*/
|
|
167
|
+
/** @type {Readonly<Settings>} */
|
|
168
|
+
export declare const DEFAULTS: Readonly<Settings>;
|
|
169
|
+
/**
|
|
170
|
+
* Merge settings layers (later layers win, `undefined` values are skipped, `pdf` merges key by key) and validate
|
|
171
|
+
* the enumerated keys. The result is a fresh object; inputs are never mutated.
|
|
172
|
+
* @param {...(Partial<Settings>|null|undefined)} layers - Layers in increasing precedence.
|
|
173
|
+
* @returns {Settings} Resolved settings.
|
|
174
|
+
*/
|
|
175
|
+
export declare function resolve(...layers: (Partial<Settings> | null | undefined)[]): Settings;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/lib/source.mjs
|
|
5
|
+
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Normalize the many shapes a streaming body can arrive in.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Iterate any supported source as raw items: a `ReadableStream`, an async iterable, an iterable, or a single
|
|
20
|
+
* string / `Uint8Array` / object. Closing the returned iterator (early `break`, `return()`, a throw) cancels the
|
|
21
|
+
* underlying stream or iterator so aborts propagate upstream.
|
|
22
|
+
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array|any} source - Input source.
|
|
23
|
+
* @returns {AsyncGenerator<any, void, undefined>} Raw items in order.
|
|
24
|
+
*/
|
|
25
|
+
export declare function items(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array | any): AsyncGenerator<any, void, undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Iterate a source as decoded text. Strings pass through, `Uint8Array` chunks are decoded as streaming UTF-8
|
|
28
|
+
* (multi-byte characters may span chunks).
|
|
29
|
+
* @param {ReadableStream|AsyncIterable<string|Uint8Array>|Iterable<string|Uint8Array>|string|Uint8Array} source - Input source.
|
|
30
|
+
* @returns {AsyncGenerator<string, void, undefined>} Text chunks.
|
|
31
|
+
*/
|
|
32
|
+
export declare function text(source: ReadableStream | AsyncIterable<string | Uint8Array> | Iterable<string | Uint8Array> | string | Uint8Array): AsyncGenerator<string, void, undefined>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/lib/sse.mjs
|
|
5
|
+
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export type SseEvent = {
|
|
16
|
+
/**
|
|
17
|
+
* - Event name.
|
|
18
|
+
*/
|
|
19
|
+
event?: string;
|
|
20
|
+
/**
|
|
21
|
+
* - Data lines joined with `\n`.
|
|
22
|
+
*/
|
|
23
|
+
data: string;
|
|
24
|
+
/**
|
|
25
|
+
* - Event id (applies to the event it is sent with only).
|
|
26
|
+
*/
|
|
27
|
+
id?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A parsed SSE event.
|
|
31
|
+
* @typedef {object} SseEvent
|
|
32
|
+
* @property {string} [event] - Event name.
|
|
33
|
+
* @property {string} data - Data lines joined with `\n`.
|
|
34
|
+
* @property {string} [id] - Event id (applies to the event it is sent with only).
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Create an incremental SSE parser. Handles `\n`, `\r\n` and `\r` line endings, comments, a leading BOM, multi-line
|
|
38
|
+
* `data:` fields and chunk boundaries anywhere (including inside a line or a line terminator).
|
|
39
|
+
* @returns {{ push: (chunk: string) => SseEvent[], flush: () => SseEvent[] }} Parser.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createParser(): {
|
|
42
|
+
push: (chunk: string) => SseEvent[];
|
|
43
|
+
flush: () => SseEvent[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Parse SSE text (any `lib/source.mjs` input) into events.
|
|
47
|
+
* @param {ReadableStream|AsyncIterable<string|Uint8Array>|Iterable<string|Uint8Array>|string|Uint8Array} source - SSE bytes or text.
|
|
48
|
+
* @returns {AsyncGenerator<SseEvent, void, undefined>} Parsed events.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parse(source: ReadableStream | AsyncIterable<string | Uint8Array> | Iterable<string | Uint8Array> | string | Uint8Array): AsyncGenerator<SseEvent, void, undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Encode one event as SSE text. Object `data` is JSON-encoded; string `data` is written as is (multi-line strings
|
|
53
|
+
* become several `data:` lines).
|
|
54
|
+
* @param {{ event?: string, data: unknown, id?: string }} message - Event to encode.
|
|
55
|
+
* @returns {string} SSE frame terminated by a blank line.
|
|
56
|
+
*/
|
|
57
|
+
export declare function encode({ event, data, id }: {
|
|
58
|
+
event?: string;
|
|
59
|
+
data: unknown;
|
|
60
|
+
id?: string;
|
|
61
|
+
}): string;
|
|
62
|
+
/**
|
|
63
|
+
* Normalize a stream input into `{ event, data }` messages whose `data` is parsed JSON (or the literal string
|
|
64
|
+
* `"[DONE]"`). Accepts SSE text/bytes, already-parsed `{ event, data }` pairs, or bare payload objects (OpenAI
|
|
65
|
+
* chunks, Anthropic event payloads). A bare payload object that has a `type` becomes `event: <type>`.
|
|
66
|
+
* @param {ReadableStream|AsyncIterable<any>|Iterable<any>|string|Uint8Array} source - Stream input.
|
|
67
|
+
* @returns {AsyncGenerator<{ event?: string, data: any }, void, undefined>} Messages.
|
|
68
|
+
*/
|
|
69
|
+
export declare function messages(source: ReadableStream | AsyncIterable<any> | Iterable<any> | string | Uint8Array): AsyncGenerator<{
|
|
70
|
+
event?: string;
|
|
71
|
+
data: any;
|
|
72
|
+
}, void, undefined>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/lib/thinking.mjs
|
|
5
|
+
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Create the signature attached to a thinking block produced from upstream reasoning. It is clearly marked as not
|
|
17
|
+
* coming from Anthropic.
|
|
18
|
+
* @returns {string} Signature string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sign(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a signature was produced by {@link sign}.
|
|
23
|
+
* @param {unknown} signature - Signature value.
|
|
24
|
+
* @returns {boolean} True for translator-made signatures.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isOurs(signature: unknown): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Reasoning text carried by an OpenAI message or delta (`reasoning` or the older `reasoning_content`).
|
|
29
|
+
* @param {{ reasoning?: unknown, reasoning_content?: unknown }|undefined} part - Message or delta.
|
|
30
|
+
* @returns {string} Reasoning text ("" when absent).
|
|
31
|
+
*/
|
|
32
|
+
export declare function reasoningOf(part: {
|
|
33
|
+
reasoning?: unknown;
|
|
34
|
+
reasoning_content?: unknown;
|
|
35
|
+
} | undefined): string;
|
|
36
|
+
/**
|
|
37
|
+
* Split a complete content string into reasoning and answer. Only a LEADING `<think>...</think>` is recognised
|
|
38
|
+
* (whitespace before it and after it is ignored); an unterminated `<think>` treats everything as reasoning.
|
|
39
|
+
* @param {string} content - Full message content.
|
|
40
|
+
* @returns {{ reasoning: string, text: string }} Split result.
|
|
41
|
+
*/
|
|
42
|
+
export declare function splitThink(content: string): {
|
|
43
|
+
reasoning: string;
|
|
44
|
+
text: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Incremental version of {@link splitThink} for streamed content. Feed content deltas to `push()` and call `end()`
|
|
48
|
+
* once; each call returns `{ reasoning, text }` pieces that are safe to emit now (partial tags are held back).
|
|
49
|
+
* @returns {{ push: (delta: string) => { reasoning: string, text: string }, end: () => { reasoning: string, text: string } }} Splitter.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createThinkSplitter(): {
|
|
52
|
+
push: (delta: string) => {
|
|
53
|
+
reasoning: string;
|
|
54
|
+
text: string;
|
|
55
|
+
};
|
|
56
|
+
end: () => {
|
|
57
|
+
reasoning: string;
|
|
58
|
+
text: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/lib/transport.mjs
|
|
5
|
+
* @Date: 2026-10-25T21:38:02-07:00 (1792989482)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-26T15:38:58-07:00 (1793054338)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* `fetch`-style request.
|
|
17
|
+
* @param {string|URL} url - Absolute http(s) URL.
|
|
18
|
+
* @param {{ method?: string, headers?: Record<string, string>, body?: string|Uint8Array, signal?: AbortSignal, redirect?: string }} [init] - Request options.
|
|
19
|
+
* @param {{ http: any, https: any }} [modules] - Protocol modules (overridable for tests).
|
|
20
|
+
* @returns {Promise<Response>} Response whose `body` is a web `ReadableStream`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function transport(url: string | URL, init?: {
|
|
23
|
+
method?: string;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
body?: string | Uint8Array;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
redirect?: string;
|
|
28
|
+
}, modules?: {
|
|
29
|
+
http: any;
|
|
30
|
+
https: any;
|
|
31
|
+
}): Promise<Response>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/lib/upstream-error.mjs
|
|
5
|
+
* @Date: 2026-10-25T12:29:36-07:00 (1792956576)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Anthropic error type for an HTTP status.
|
|
17
|
+
* @param {number} status - HTTP status.
|
|
18
|
+
* @returns {string} Anthropic `error.type`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function anthropicType(status: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* OpenAI error type for an HTTP status.
|
|
23
|
+
* @param {number} status - HTTP status.
|
|
24
|
+
* @returns {string} OpenAI `error.type`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function openaiType(status: number): string;
|
|
27
|
+
/**
|
|
28
|
+
* Pull `{ message, type, code, param }` out of any known upstream error body shape: nested OpenAI/vLLM
|
|
29
|
+
* (`{error:{message,type,param,code}}`), flat old vLLM (`{message,type,param,code}`), Anthropic
|
|
30
|
+
* (`{type:"error",error:{type,message}}`), `{error:"text"}`, a bare string, or nothing.
|
|
31
|
+
* @param {*} body - Parsed upstream body.
|
|
32
|
+
* @param {number} status - HTTP status, used for the fallback message.
|
|
33
|
+
* @returns {{message: string, type?: string, code?: *, param?: *}} Normalized error.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parse(body: any, status: number): {
|
|
36
|
+
message: string;
|
|
37
|
+
type?: string;
|
|
38
|
+
code?: any;
|
|
39
|
+
param?: any;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Render an error body in the client protocol.
|
|
43
|
+
* @param {"anthropic" | "openai"} front - Client protocol.
|
|
44
|
+
* @param {number} status - HTTP status.
|
|
45
|
+
* @param {{message: string, type?: string, code?: *, param?: *}} info - Normalized error.
|
|
46
|
+
* @param {any} [options] - `{ native: boolean }`: keep the upstream `type` when it is already valid for this protocol.
|
|
47
|
+
* @returns {{status: number, body: any}} Status and body in the client shape.
|
|
48
|
+
*/
|
|
49
|
+
export declare function render(front: "anthropic" | "openai", status: number, info: {
|
|
50
|
+
message: string;
|
|
51
|
+
type?: string;
|
|
52
|
+
code?: any;
|
|
53
|
+
param?: any;
|
|
54
|
+
}, options?: any): {
|
|
55
|
+
status: number;
|
|
56
|
+
body: any;
|
|
57
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @Project: @cldmv/llm-translator
|
|
4
|
+
* @Filename: /src/lib/warn.mjs
|
|
5
|
+
* @Date: 2026-10-25T12:29:36-07:00 (1792956576)
|
|
6
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
+
* -----
|
|
9
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
+
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
+
* -----
|
|
12
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview One-time warnings.
|
|
17
|
+
* @module @cldmv/llm-translator/lib/warn
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Print a warning once per translator unless `silent` is set.
|
|
21
|
+
* @param {any} config - Normalized config (`silent`).
|
|
22
|
+
* @param {any} state - Translator state (`warned` set).
|
|
23
|
+
* @param {string} message - Warning text.
|
|
24
|
+
* @returns {boolean} True when the warning was printed.
|
|
25
|
+
*/
|
|
26
|
+
export declare function warn(config: any, state: any, message: string): boolean;
|