@cldmv/llm-translator 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +11 -11
- package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +1 -1
- package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +1 -1
- package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +3 -3
- package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
- package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +1 -1
- package/dist/api/detect.mjs +1 -1
- package/dist/api/driver/anthropic/token/count.mjs +1 -1
- package/dist/api/driver/compatible/detect.mjs +1 -1
- package/dist/api/driver/compatible/info.mjs +1 -1
- package/dist/api/driver/deepseek/detect.mjs +2 -0
- package/dist/api/driver/deepseek/error.mjs +2 -0
- package/dist/api/driver/deepseek/info.mjs +2 -0
- package/dist/api/driver/deepseek/request.mjs +2 -0
- package/dist/api/driver/deepseek/settings.mjs +2 -0
- package/dist/api/driver/llamacpp/chunk.mjs +2 -0
- package/dist/api/driver/llamacpp/detect.mjs +2 -0
- package/dist/api/driver/llamacpp/flush.mjs +2 -0
- package/dist/api/driver/llamacpp/info.mjs +2 -0
- package/dist/api/driver/llamacpp/request.mjs +2 -0
- package/dist/api/driver/llamacpp/response.mjs +2 -0
- package/dist/api/driver/llamacpp/settings.mjs +2 -0
- package/dist/api/driver/ollama/detect.mjs +2 -0
- package/dist/api/driver/ollama/info.mjs +2 -0
- package/dist/api/driver/ollama/request.mjs +2 -0
- package/dist/api/driver/ollama/settings.mjs +2 -0
- package/dist/api/driver/sglang/detect.mjs +2 -0
- package/dist/api/driver/sglang/info.mjs +2 -0
- package/dist/api/driver/sglang/request.mjs +2 -0
- package/dist/api/driver/sglang/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +1 -1
- package/dist/api/driver/vllm/info.mjs +1 -1
- package/dist/api/endpoint/status.mjs +2 -0
- package/dist/api/error/error.mjs +1 -1
- package/dist/api/model/get.mjs +2 -0
- package/dist/api/request.mjs +2 -2
- package/dist/api/route.mjs +2 -0
- package/dist/api/send.mjs +1 -1
- package/dist/api/server/plugin.mjs +1 -1
- package/dist/api/server/start.mjs +1 -1
- package/dist/api/status.mjs +1 -1
- package/dist/api/stream.mjs +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +1 -1
- package/dist/lib/backends.mjs +2 -0
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/cli.mjs +1 -1
- package/dist/lib/config.mjs +1 -1
- package/dist/lib/estimate.mjs +1 -1
- package/dist/lib/http.mjs +1 -1
- package/dist/lib/ids.mjs +1 -1
- package/dist/lib/models.mjs +1 -1
- package/dist/lib/passthrough.mjs +1 -1
- package/dist/lib/pool.mjs +2 -0
- package/dist/lib/route.mjs +1 -1
- package/dist/lib/routes.mjs +1 -1
- package/dist/lib/settings.mjs +1 -1
- package/dist/lib/thinking.mjs +2 -1
- package/dist/lib/tools.mjs +2 -0
- package/dist/lib/toolsearch.mjs +3 -0
- package/dist/lib/transport.mjs +1 -1
- package/dist/lib/usage.mjs +2 -0
- package/package.json +13 -7
- package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +6 -15
- package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +3 -16
- package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +1 -15
- package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +1 -15
- package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +3 -17
- package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +1 -15
- package/types/src/api/detect.d.mts +1 -15
- package/types/src/api/driver/anthropic/detect.d.mts +1 -1
- package/types/src/api/driver/anthropic/info.d.mts +1 -1
- package/types/src/api/driver/anthropic/model/list.d.mts +1 -15
- package/types/src/api/driver/anthropic/settings.d.mts +1 -1
- package/types/src/api/driver/anthropic/token/count.d.mts +1 -15
- package/types/src/api/driver/compatible/detect.d.mts +2 -16
- package/types/src/api/driver/compatible/info.d.mts +3 -20
- package/types/src/api/driver/compatible/model/list.d.mts +1 -15
- package/types/src/api/driver/compatible/request.d.mts +1 -15
- package/types/src/api/driver/compatible/settings.d.mts +1 -1
- package/types/src/api/driver/deepseek/detect.d.mts +26 -0
- package/types/src/api/driver/deepseek/error.d.mts +14 -0
- package/types/src/api/driver/deepseek/info.d.mts +29 -0
- package/types/src/api/driver/deepseek/request.d.mts +8 -0
- package/types/src/api/driver/deepseek/settings.d.mts +25 -0
- package/types/src/api/driver/llamacpp/chunk.d.mts +7 -0
- package/types/src/api/driver/llamacpp/detect.d.mts +6 -0
- package/types/src/api/driver/llamacpp/flush.d.mts +26 -0
- package/types/src/api/driver/llamacpp/info.d.mts +31 -0
- package/types/src/api/driver/llamacpp/request.d.mts +8 -0
- package/types/src/api/driver/llamacpp/response.d.mts +8 -0
- package/types/src/api/driver/llamacpp/settings.d.mts +27 -0
- package/types/src/api/driver/ollama/detect.d.mts +6 -0
- package/types/src/api/driver/ollama/info.d.mts +30 -0
- package/types/src/api/driver/ollama/request.d.mts +8 -0
- package/types/src/api/driver/ollama/settings.d.mts +7 -0
- package/types/src/api/driver/openai/detect.d.mts +1 -1
- package/types/src/api/driver/openai/info.d.mts +1 -1
- package/types/src/api/driver/openai/model/list.d.mts +1 -15
- package/types/src/api/driver/openai/request.d.mts +1 -15
- package/types/src/api/driver/openai/settings.d.mts +1 -1
- package/types/src/api/driver/sglang/detect.d.mts +6 -0
- package/types/src/api/driver/sglang/info.d.mts +31 -0
- package/types/src/api/driver/sglang/request.d.mts +8 -0
- package/types/src/api/driver/sglang/settings.d.mts +24 -0
- package/types/src/api/driver/vllm/detect.d.mts +3 -17
- package/types/src/api/driver/vllm/error.d.mts +1 -15
- package/types/src/api/driver/vllm/info.d.mts +3 -20
- package/types/src/api/driver/vllm/model/list.d.mts +1 -15
- package/types/src/api/driver/vllm/probe.d.mts +1 -15
- package/types/src/api/driver/vllm/request.d.mts +1 -15
- package/types/src/api/driver/vllm/settings.d.mts +1 -15
- package/types/src/api/driver/vllm/token/count.d.mts +1 -15
- package/types/src/api/endpoint/status.d.mts +27 -0
- package/types/src/api/error/build.d.mts +1 -15
- package/types/src/api/error/error.d.mts +1 -15
- package/types/src/api/model/get.d.mts +9 -0
- package/types/src/api/model/list.d.mts +1 -15
- package/types/src/api/request.d.mts +8 -17
- package/types/src/api/response.d.mts +1 -15
- package/types/src/api/route.d.mts +18 -0
- package/types/src/api/send.d.mts +21 -16
- package/types/src/api/server/plugin.d.mts +6 -19
- package/types/src/api/server/start.d.mts +2 -16
- package/types/src/api/server/stop.d.mts +1 -15
- package/types/src/api/sse/encode.d.mts +1 -15
- package/types/src/api/sse/parse.d.mts +1 -15
- package/types/src/api/sse/ping.d.mts +1 -15
- package/types/src/api/sse/write.d.mts +1 -15
- package/types/src/api/status.d.mts +2 -16
- package/types/src/api/stream.d.mts +1 -15
- package/types/src/api/token/count.d.mts +1 -15
- package/types/src/index.d.mts +24 -34
- package/types/src/lib/arguments.d.mts +2 -16
- package/types/src/lib/backends.d.mts +21 -0
- package/types/src/lib/capture.d.mts +2 -16
- package/types/src/lib/cli.d.mts +12 -26
- package/types/src/lib/config.d.mts +11 -25
- package/types/src/lib/documents.d.mts +16 -27
- package/types/src/lib/errors.d.mts +75 -75
- package/types/src/lib/estimate.d.mts +58 -7
- package/types/src/lib/finish.d.mts +4 -4
- package/types/src/lib/http.d.mts +19 -5
- package/types/src/lib/ids.d.mts +11 -20
- package/types/src/lib/images.d.mts +19 -19
- package/types/src/lib/models.d.mts +13 -13
- package/types/src/lib/normalize.d.mts +3 -3
- package/types/src/lib/passthrough.d.mts +11 -17
- package/types/src/lib/pdf.d.mts +4 -18
- package/types/src/lib/ping.d.mts +1 -15
- package/types/src/lib/pool.d.mts +124 -0
- package/types/src/lib/route.d.mts +31 -24
- package/types/src/lib/routes.d.mts +10 -15
- package/types/src/lib/runtime.d.mts +2 -16
- package/types/src/lib/schema.d.mts +1 -15
- package/types/src/lib/settings.d.mts +68 -54
- package/types/src/lib/source.d.mts +2 -2
- package/types/src/lib/sse.d.mts +21 -32
- package/types/src/lib/thinking.d.mts +117 -22
- package/types/src/lib/tools.d.mts +28 -0
- package/types/src/lib/toolsearch.d.mts +91 -0
- package/types/src/lib/transport.d.mts +3 -16
- package/types/src/lib/upstream-error.d.mts +4 -18
- package/types/src/lib/usage.d.mts +91 -0
- package/types/src/lib/warn.d.mts +1 -1
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/driver/vllm/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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Normalize old flat (`{message,type,code}`) and nested vLLM error bodies to the nested OpenAI shape.
|
|
17
3
|
* @param {number} status - HTTP status.
|
|
18
4
|
* @param {*} body - Parsed upstream error body.
|
|
19
5
|
* @returns {{error: {message: string, type: string | undefined, param: *, code: *}}} Nested error body.
|
|
20
6
|
*/
|
|
21
|
-
export
|
|
7
|
+
export function error(status: number, body: any): {
|
|
22
8
|
error: {
|
|
23
9
|
message: string;
|
|
24
10
|
type: string | undefined;
|
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/driver/vllm/info.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* @fileoverview vLLM driver: static facts about the backend.
|
|
17
|
-
* @module @cldmv/llm-translator/driver/vllm
|
|
18
|
-
*/
|
|
19
1
|
/**
|
|
20
2
|
* Describe the vLLM driver.
|
|
21
|
-
* @returns {{name: string, protocol: string, order: number, auth: string, paths: Record<string,string>}} Driver facts.
|
|
3
|
+
* @returns {{name: string, protocol: string, order: number, auth: string, fields: string[], paths: Record<string,string>}} Driver facts.
|
|
22
4
|
*/
|
|
23
|
-
export
|
|
5
|
+
export function info(): {
|
|
24
6
|
name: string;
|
|
25
7
|
protocol: string;
|
|
26
8
|
order: number;
|
|
27
9
|
auth: string;
|
|
10
|
+
fields: string[];
|
|
28
11
|
paths: Record<string, string>;
|
|
29
12
|
};
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/driver/vllm/model/list.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* List the models the vLLM server serves (including `max_model_len`).
|
|
17
3
|
* @param {any} context - `{ endpoint, transport, signal, timeout }`.
|
|
18
4
|
* @returns {Promise<any[] | null>} Models, or null when unreachable.
|
|
19
5
|
*/
|
|
20
|
-
export
|
|
6
|
+
export function list(context: any): Promise<any[] | null>;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/driver/vllm/probe.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Probe a vLLM server for facts that need a request.
|
|
17
3
|
*
|
|
@@ -23,7 +9,7 @@
|
|
|
23
9
|
* @param {{ endpoint: any, transport: Function, signal?: AbortSignal, timeout?: number, facts?: any, want?: { inlineSystem?: boolean, images?: boolean } }} context - Probe context. `want` selects the checks (`inlineSystem` defaults to on, `images` to off).
|
|
24
10
|
* @returns {Promise<{ inlineSystem?: "keep"|"user", images?: boolean }>} Probed settings.
|
|
25
11
|
*/
|
|
26
|
-
export
|
|
12
|
+
export function probe({ endpoint, transport, signal, timeout, facts, want }: {
|
|
27
13
|
endpoint: any;
|
|
28
14
|
transport: Function;
|
|
29
15
|
signal?: AbortSignal;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/driver/vllm/request.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Drop tool fields vLLM rejects when no tools are present, and clamp `reasoning_effort` to what vLLM accepts
|
|
17
3
|
* (`xhigh` and `max` become `high`) unless the `effortPassthrough` setting is on.
|
|
@@ -19,4 +5,4 @@
|
|
|
19
5
|
* @param {any} [ctx] - `{ settings }`.
|
|
20
6
|
* @returns {any} Normalized body.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function request(body: any, ctx?: any): any;
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/driver/vllm/settings.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Settings for a vLLM server. An unknown version is treated as the latest release, except `thinkingBudget`, which needs a known version of 0.19.0 or later.
|
|
17
3
|
* @param {{version?: string}} [facts] - Detection facts (or the configured version).
|
|
18
4
|
* @returns {any} Partial settings.
|
|
19
5
|
*/
|
|
20
|
-
export
|
|
6
|
+
export function settings(facts?: {
|
|
21
7
|
version?: string;
|
|
22
8
|
}): any;
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/driver/vllm/token/count.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Count the prompt tokens of a converted Chat Completions request with the server's own tokenizer and chat template.
|
|
17
3
|
* @param {any} context - `{ endpoint, request, transport, signal, timeout }`.
|
|
18
4
|
* @returns {Promise<number | null>} Token count, or null when the server did not answer (caller falls back to an estimate).
|
|
19
5
|
*/
|
|
20
|
-
export
|
|
6
|
+
export function count({ endpoint, request, transport, signal, timeout }: any): Promise<number | null>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health of every endpoint, for status output. An endpoint is unhealthy while it is backing off after a connection error or a 5xx; it is still
|
|
3
|
+
* tried when nothing healthy serves the model. Secrets are never included.
|
|
4
|
+
* @returns {{strategy: string, backoff: {base: number, max: number}, models: Record<string, string>, endpoints: {name: string, url: string, models: string[], healthy: boolean, failures: number, retryAt: string | null, inflight: number, requests: number, errors: number, lastError: string | null, lastFailure: string | null, lastSuccess: string | null}[]}} The pool config and one record per endpoint (`inflight` counts requests whose reply has not finished, `requests` and `errors` count attempts since start).
|
|
5
|
+
*/
|
|
6
|
+
export function status(): {
|
|
7
|
+
strategy: string;
|
|
8
|
+
backoff: {
|
|
9
|
+
base: number;
|
|
10
|
+
max: number;
|
|
11
|
+
};
|
|
12
|
+
models: Record<string, string>;
|
|
13
|
+
endpoints: {
|
|
14
|
+
name: string;
|
|
15
|
+
url: string;
|
|
16
|
+
models: string[];
|
|
17
|
+
healthy: boolean;
|
|
18
|
+
failures: number;
|
|
19
|
+
retryAt: string | null;
|
|
20
|
+
inflight: number;
|
|
21
|
+
requests: number;
|
|
22
|
+
errors: number;
|
|
23
|
+
lastError: string | null;
|
|
24
|
+
lastFailure: string | null;
|
|
25
|
+
lastSuccess: string | null;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/error/build.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Build `{ status, headers, body }` in the client protocol.
|
|
17
3
|
* @param {number} status - HTTP status.
|
|
@@ -19,7 +5,7 @@
|
|
|
19
5
|
* @param {any} [options] - `{ type, code, param, front }` overrides; `type` is an Anthropic error type (mapped for the OpenAI front) and `front` defaults to the configured front.
|
|
20
6
|
* @returns {{status: number, headers: Record<string,string>, body: any}} Client-shaped error reply.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function build(status: number, message: string, options?: any): {
|
|
23
9
|
status: number;
|
|
24
10
|
headers: Record<string, string>;
|
|
25
11
|
body: any;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/error/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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert an upstream error reply into `{ status, headers, body }` in the client protocol. Context-window overflows
|
|
17
3
|
* become Anthropic's "prompt is too long: N tokens > MAX maximum" (which triggers Claude Code's compaction); status codes
|
|
18
|
-
* map 1:1; `retry-after` is kept.
|
|
4
|
+
* map 1:1; `retry-after` is kept. A 400 that says the server has no tool parser (vLLM without `--enable-auto-tool-choice` and `--tool-call-parser`) gets a hint naming the missing flags.
|
|
19
5
|
* @param {number} status - Upstream HTTP status.
|
|
20
6
|
* @param {*} upstreamBody - Parsed upstream error body (object or text).
|
|
21
7
|
* @param {Record<string,string>} [headers] - Lowercase upstream response headers.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieve one entry of the model list (`model.list`) by id, in the client protocol's model shape (Anthropic `{type:"model",...}` or
|
|
3
|
+
* OpenAI `{object:"model",...}`). Aliases are found like served models.
|
|
4
|
+
* @param {string} id - Model id as the client sends it.
|
|
5
|
+
* @param {any} [options] - `{ signal, front }`.
|
|
6
|
+
* @returns {Promise<any>} Model object.
|
|
7
|
+
* @throws {TranslatorError} `model_not_found` (HTTP 404) when no upstream serves the id and it is not an alias.
|
|
8
|
+
*/
|
|
9
|
+
export function get(id: string, options?: any): Promise<any>;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/model/list.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* List the models the upstreams serve (live when the driver can, else detection/config data), plus the configured aliases,
|
|
17
3
|
* in the client protocol's list shape (Anthropic `{data:[{type:"model",...}]}` or OpenAI `{object:"list",data:[...]}`).
|
|
18
4
|
* @param {any} [options] - `{ signal, front }`.
|
|
19
5
|
* @returns {Promise<any>} Model list.
|
|
20
6
|
*/
|
|
21
|
-
export
|
|
7
|
+
export function list(options?: any): Promise<any>;
|
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/request.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:00-07:00 (1792958340)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Route a client request body (in the configured `front` protocol) to an upstream and convert it to that upstream's
|
|
17
3
|
* protocol. Does no I/O.
|
|
18
4
|
* @param {any} body - Client request body (Anthropic Messages or OpenAI Chat Completions, per `front`).
|
|
19
|
-
* @param {any} [options] - `{ front, headers, clientHeaders, filter, images }`. `front` overrides the configured front for this call, `headers` are extra upstream headers, `clientHeaders` are client headers forwarded only to a native Anthropic upstream, `filter` restricts a forwarded OpenAI body to known fields (default: the `passthroughFilter` setting, off), `images: false` sends the request without images (used by the image fallback).
|
|
20
|
-
* @returns {Promise<{upstream: string, method: string, url: string, path: string, headers: Record<string,string>, body: any, state: any, images: {sent: boolean, retry: boolean, key: string}}>} The upstream request and the state `response`/`stream`/`error` need. `images` tells `send` whether the body carries images, whether a refusal may be retried without them and the key under which a refusal is remembered.
|
|
5
|
+
* @param {any} [options] - `{ front, headers, clientHeaders, filter, images, usage }`. `front` overrides the configured front for this call, `headers` are extra upstream headers, `clientHeaders` are client headers forwarded only to a native Anthropic upstream, `filter` restricts a forwarded OpenAI body to known fields (default: the `passthroughFilter` setting, off), `images: false` sends the request without images (used by the image fallback), `endpoint` sends to that member of the model's pool (used for failover; default: the first in the pool's order), `hold: true` (used by `send`) advances a round robin and takes the chosen endpoint's in-flight slot, which the caller then releases, `tools: false` sends the request without tools (used by the tool fallback), `usage: true` (used by `send`) makes a streaming OpenAI-front request always ask the upstream for its final usage chunk, `budget` (from `createBudget`, one per `send` for all its attempts) limits the cost of decoding reasoning signatures.
|
|
6
|
+
* @returns {Promise<{upstream: string, method: string, url: string, path: string, headers: Record<string,string>, body: any, state: any, pool: string[], images: {sent: boolean, retry: boolean, key: string}, tools: {sent: boolean, retry: boolean}}>} The upstream request and the state `response`/`stream`/`error` need. `pool` lists the names of the endpoints serving the model in the order they are tried (`upstream` is the first); `images` tells `send` whether the body carries images, whether a refusal may be retried without them and the key under which a refusal is remembered; `tools` tells it whether the body carries tools and whether a tool-parser refusal may be retried without them.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function request(body: any, options?: any): Promise<{
|
|
23
9
|
upstream: string;
|
|
24
10
|
method: string;
|
|
25
11
|
url: string;
|
|
@@ -27,9 +13,14 @@ export declare function request(body: any, options?: any): Promise<{
|
|
|
27
13
|
headers: Record<string, string>;
|
|
28
14
|
body: any;
|
|
29
15
|
state: any;
|
|
16
|
+
pool: string[];
|
|
30
17
|
images: {
|
|
31
18
|
sent: boolean;
|
|
32
19
|
retry: boolean;
|
|
33
20
|
key: string;
|
|
34
21
|
};
|
|
22
|
+
tools: {
|
|
23
|
+
sent: boolean;
|
|
24
|
+
retry: boolean;
|
|
25
|
+
};
|
|
35
26
|
}>;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/response.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Convert an upstream response body to the client protocol (a no-op apart from driver normalization and restoring the
|
|
17
3
|
* client's model name when front and upstream speak the same protocol).
|
|
@@ -19,4 +5,4 @@
|
|
|
19
5
|
* @param {any} state - The `state` returned by `request`.
|
|
20
6
|
* @returns {Promise<any>} Response body in the client protocol.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function response(upstreamBody: any, state: any): Promise<any>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a client request body to its upstream and model (after aliases and routing) without doing any I/O, for example to
|
|
3
|
+
* check a model allow-list before `send`. Uses the same routing as `request`.
|
|
4
|
+
* @param {any} body - Client request body (Anthropic Messages or OpenAI Chat Completions, per `front`).
|
|
5
|
+
* @param {any} [options] - `{ front }` overrides the configured front for this call.
|
|
6
|
+
* @returns {{upstream: string, model: string, requested: string | undefined, protocol: string, backend: string, native: boolean, unserved: boolean, pool: string[]}} `upstream` is the first endpoint `send` would try right now (the endpoint name), `model` the name sent upstream, `requested` the name the client used, `protocol` the upstream's protocol (`openai.chat` or `anthropic.messages`), `backend` the driver detection chose (`vllm`, `openai`, `anthropic` or `compatible`, the `driver` that `status()` reports), `native` whether the body is forwarded without conversion and `unserved` whether no upstream lists the model and `pool` the names of all endpoints serving the model in the order they would be tried (failover candidates). When several endpoints serve the model this is a snapshot of the current health, in-flight counts and round robin position and it does not move the round robin; `send` decides again and may use another member, so the endpoint that answered is `usage.upstream`.
|
|
7
|
+
* @throws {TranslatorError} `invalid_body` (400) when the body is not a JSON object.
|
|
8
|
+
*/
|
|
9
|
+
export function route(body: any, options?: any): {
|
|
10
|
+
upstream: string;
|
|
11
|
+
model: string;
|
|
12
|
+
requested: string | undefined;
|
|
13
|
+
protocol: string;
|
|
14
|
+
backend: string;
|
|
15
|
+
native: boolean;
|
|
16
|
+
unserved: boolean;
|
|
17
|
+
pool: string[];
|
|
18
|
+
};
|
package/types/src/api/send.d.mts
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Send a client request to the routed upstream and return the client-protocol reply.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @Last modified time: 2026-10-25T12:59:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
4
|
+
* Every reply, including error replies, carries a non-enumerable `usage` property: a `Promise` of the usage report that never rejects.
|
|
5
|
+
* For JSON and error replies it is already settled. For a stream reply it settles when the stream ends, throws or is returned early
|
|
6
|
+
* (`break` or `return()`); a stream nobody iterates never settles. `onUsage` is called with the same report exactly once, also when
|
|
7
|
+
* `send` throws (for example when the caller aborted). The report is `{ input_tokens, output_tokens, cache_read_input_tokens,
|
|
8
|
+
* cache_creation_input_tokens, reported, complete, reason, model, requested, upstream, front, stream }`: token fields are numbers or
|
|
9
|
+
* `null` (never 0 for unknown), `reported` is false when the upstream carried no usage, `complete` is true only for a reply that finished
|
|
10
|
+
* normally and `reason` is `"done"`, `"aborted"`, `"error"` or `"upstream_error"`. A stream that ends early reports the usage seen so far.
|
|
13
11
|
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
12
|
+
* When a converted reply's upstream did not report a side of the usage (input or output; all zero counts as not reported), the
|
|
13
|
+
* client-protocol reply carries an estimate for that side instead of zero: the server tokenizer's count when the driver has one (not
|
|
14
|
+
* for an OpenAI-front stream whose usage the client will not see), else one token per four characters (what `token.count` uses) for the
|
|
15
|
+
* input, and one token per four characters of generated text for the output. Real sides are left alone. The report never presents
|
|
16
|
+
* estimates as real counts: its token fields keep only what the upstream reported and the estimates are in
|
|
17
|
+
* `estimated: { input_tokens, output_tokens }` (null for a side that was reported, and null altogether when nothing was estimated).
|
|
18
|
+
* On the Anthropic front a stream carries them in the final `message_delta`, because `message_start` is sent before the output is known.
|
|
19
|
+
* Replies passed through without conversion are never altered.
|
|
17
20
|
* @param {any} body - Client request body (per `front`).
|
|
18
|
-
* @param {any} [options] - `{ signal, front, headers, clientHeaders, filter }`: abort signal for the upstream call, per-call front, extra upstream headers, client headers forwarded to a native Anthropic upstream,
|
|
19
|
-
* @returns {Promise<{status: number, headers: Record<string,string>, body: any} | {status: number, headers: Record<string,string>, stream: AsyncIterable<{event?: string, data: *}>}>} A JSON reply, or a stream reply when the client asked for streaming and the upstream accepted.
|
|
21
|
+
* @param {any} [options] - `{ signal, front, headers, clientHeaders, filter, onUsage }`: abort signal for the upstream call, per-call front, extra upstream headers, client headers forwarded to a native Anthropic upstream, the pass-through body filter (see `request`) and the usage callback (an exception in it is reported as a warning and never breaks the reply).
|
|
22
|
+
* @returns {Promise<{status: number, headers: Record<string,string>, body: any, usage: Promise<any>} | {status: number, headers: Record<string,string>, stream: AsyncIterable<{event?: string, data: *}>, usage: Promise<any>}>} A JSON reply, or a stream reply when the client asked for streaming and the upstream accepted.
|
|
20
23
|
*/
|
|
21
|
-
export
|
|
24
|
+
export function send(body: any, options?: any): Promise<{
|
|
22
25
|
status: number;
|
|
23
26
|
headers: Record<string, string>;
|
|
24
27
|
body: any;
|
|
28
|
+
usage: Promise<any>;
|
|
25
29
|
} | {
|
|
26
30
|
status: number;
|
|
27
31
|
headers: Record<string, string>;
|
|
@@ -29,4 +33,5 @@ export declare function send(body: any, options?: any): Promise<{
|
|
|
29
33
|
event?: string;
|
|
30
34
|
data: any;
|
|
31
35
|
}>;
|
|
36
|
+
usage: Promise<any>;
|
|
32
37
|
}>;
|
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @Filename: /src/api/server/plugin.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Fastify plugin. Anthropic front: `POST /v1/messages`, `POST /v1/messages/count_tokens`, `GET /v1/models`, `GET|HEAD /`
|
|
17
|
-
* and `/api/hello`. OpenAI front: `POST /v1/chat/completions`, `GET /v1/models`, `GET|HEAD /`. Responses stream as
|
|
2
|
+
* Fastify plugin. Anthropic front: `POST /v1/messages`, `POST /v1/messages/count_tokens`, `GET /v1/models`, `GET /v1/models/{id}`,
|
|
3
|
+
* `GET|HEAD /` and `/api/hello`. OpenAI front: `POST /v1/chat/completions`, `GET /v1/models`, `GET /v1/models/{id}`, `GET|HEAD /`. Responses stream as
|
|
18
4
|
* `text/event-stream` with keep-alive pings; a client disconnect aborts the upstream request. Register it with
|
|
19
|
-
* `app.register(api.server.plugin, { apiKey })`.
|
|
5
|
+
* `app.register(api.server.plugin, { apiKey })`. `authorize(request)` (sync or async) runs after `apiKey` and the body parse and decides
|
|
6
|
+
* with `true` / `{ ok: true, context }` or `false` / `{ ok: false, status, message }`; `onUsage(report, context)` receives each request's usage report.
|
|
20
7
|
* @param {any} fastify - Fastify instance.
|
|
21
|
-
* @param {any} [options] - `{ front, apiKey, bodyLimit }`. `front` sets the protocol this plugin instance serves (default: the translator's front, other plugin instances and `api.send` are unaffected); `apiKey` (string or array) is required from clients. Forwarded OpenAI bodies are restricted to known fields unless the `passthroughFilter` setting is `false`.
|
|
8
|
+
* @param {any} [options] - `{ front, apiKey, bodyLimit, authorize, onUsage }`. `authorize(request)` and `onUsage(report, context)` are described above. `front` sets the protocol this plugin instance serves (default: the translator's front, other plugin instances and `api.send` are unaffected); `apiKey` (string or array) is required from clients. Forwarded OpenAI bodies are restricted to known fields unless the `passthroughFilter` setting is `false`.
|
|
22
9
|
* @returns {Promise<void>} Resolves once the routes are registered.
|
|
23
10
|
*/
|
|
24
|
-
export
|
|
11
|
+
export function plugin(fastify: any, options?: any): Promise<void>;
|
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/server/start.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-25T14:00:49-07:00 (1792962049)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Start an HTTP server in front of the translator. Fastify is an optional peer dependency and is imported here.
|
|
17
|
-
* @param {any} [options] - `{ host = "127.0.0.1", port = 8787, front, apiKey, bodyLimit, logger, allowUnauthenticated }`. Listening on a non-loopback address without an `apiKey` is refused unless `allowUnauthenticated` is true.
|
|
3
|
+
* @param {any} [options] - `{ host = "127.0.0.1", port = 8787, front, apiKey, bodyLimit, logger, allowUnauthenticated, authorize, onUsage }`. `authorize(request)` and `onUsage(report, context)` are described at `server.plugin`. Listening on a non-loopback address without an `apiKey` or an `authorize` hook is refused unless `allowUnauthenticated` is true.
|
|
18
4
|
* @returns {Promise<{url: string, host: string, port: number, app: any, close: () => Promise<void>}>} Running server handle.
|
|
19
5
|
*/
|
|
20
|
-
export
|
|
6
|
+
export function start(options?: any): Promise<{
|
|
21
7
|
url: string;
|
|
22
8
|
host: string;
|
|
23
9
|
port: number;
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/server/stop.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Close all servers started with `server.start`.
|
|
17
3
|
* @returns {Promise<void>} Resolves when every server has closed.
|
|
18
4
|
*/
|
|
19
|
-
export
|
|
5
|
+
export function stop(): Promise<void>;
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/sse/encode.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Encode `{ event?, data, id? }` (object data is JSON-encoded, `"[DONE]"` is written as is) or a keep-alive comment
|
|
17
3
|
* `{ comment }` as an SSE frame.
|
|
18
4
|
* @param {{event?: string, data?: any, id?: string, comment?: string}} message - Event to encode.
|
|
19
5
|
* @returns {string} SSE text ending with a blank line.
|
|
20
6
|
*/
|
|
21
|
-
export
|
|
7
|
+
export function encode(message: {
|
|
22
8
|
event?: string;
|
|
23
9
|
data?: any;
|
|
24
10
|
id?: string;
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/sse/parse.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Parse SSE text/bytes (or already-parsed events) into `{ event?, data }` messages. `data` is decoded JSON, or the string
|
|
17
3
|
* `"[DONE]"`.
|
|
18
4
|
* @param {ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array} source - SSE input.
|
|
19
5
|
* @returns {AsyncGenerator<{event?: string, data: *}>} Messages.
|
|
20
6
|
*/
|
|
21
|
-
export
|
|
7
|
+
export function parse(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array): AsyncGenerator<{
|
|
22
8
|
event?: string;
|
|
23
9
|
data: any;
|
|
24
10
|
}>;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/sse/ping.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Wrap an event stream so a keep-alive is yielded whenever the source is silent for `interval` ms.
|
|
17
3
|
*
|
|
@@ -24,7 +10,7 @@
|
|
|
24
10
|
* @param {any} [options] - `{ interval, front }`. `interval` defaults to the `pingInterval` setting; `0` disables pings.
|
|
25
11
|
* @returns {AsyncGenerator<any>} Events interleaved with keep-alives.
|
|
26
12
|
*/
|
|
27
|
-
export
|
|
13
|
+
export function ping(events: AsyncIterable<{
|
|
28
14
|
event?: string;
|
|
29
15
|
data: any;
|
|
30
16
|
}>, options?: any): AsyncGenerator<any>;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/sse/write.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Pump client events into a writable as SSE frames, interleaving keep-alive pings while the source is silent and honoring
|
|
17
3
|
* backpressure. Does not end the writable. Stops early (closing the event source) when the writable closes.
|
|
@@ -20,7 +6,7 @@
|
|
|
20
6
|
* @param {any} [options] - `{ interval, front }` forwarded to `sse.ping`.
|
|
21
7
|
* @returns {Promise<boolean>} True when every event was written, false when the writable closed first.
|
|
22
8
|
*/
|
|
23
|
-
export
|
|
9
|
+
export function write(target: import("node:stream").Writable, events: AsyncIterable<{
|
|
24
10
|
event?: string;
|
|
25
11
|
data: any;
|
|
26
12
|
}>, options?: any): Promise<boolean>;
|