@cldmv/llm-translator 0.2.0 → 0.3.1
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 +17 -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,22 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/status.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
|
* Describe the translator's upstreams. Secrets (API keys, headers) are never included.
|
|
17
|
-
* @returns {{front: string, upstreams: any[]}} Front protocol and per-upstream detection results.
|
|
3
|
+
* @returns {{front: string, upstreams: any[]}} Front protocol and per-upstream detection results and health (see `endpoint.status`).
|
|
18
4
|
*/
|
|
19
|
-
export
|
|
5
|
+
export function status(): {
|
|
20
6
|
front: string;
|
|
21
7
|
upstreams: any[];
|
|
22
8
|
};
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/stream.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 SSE stream to client events: Anthropic events (`message_start`, `content_block_*`, ...) for the
|
|
17
3
|
* Anthropic front, Chat Completions chunks followed by `"[DONE]"` for the OpenAI front. Pings are added by the SSE writer.
|
|
@@ -19,7 +5,7 @@
|
|
|
19
5
|
* @param {any} state - The `state` returned by `request`.
|
|
20
6
|
* @returns {AsyncIterable<{event?: string, data: *}>} Client events.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function stream(source: ReadableStream | AsyncIterable<string | Uint8Array> | string, state: any): AsyncIterable<{
|
|
23
9
|
event?: string;
|
|
24
10
|
data: any;
|
|
25
11
|
}>;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/api/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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Count input tokens for a client request. Uses the upstream's own tokenizer when its driver has one (vLLM `/tokenize`,
|
|
17
3
|
* Anthropic `count_tokens`); otherwise a documented estimate of one token per four characters.
|
|
@@ -19,6 +5,6 @@
|
|
|
19
5
|
* @param {any} [options] - `{ signal, front }`.
|
|
20
6
|
* @returns {Promise<{input_tokens: number}>} Anthropic `count_tokens` shaped result.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function count(body: any, options?: any): Promise<{
|
|
23
9
|
input_tokens: number;
|
|
24
10
|
}>;
|
package/types/src/index.d.mts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
2
|
+
* @typedef {object} TranslatorConfig
|
|
3
|
+
* @property {"anthropic" | "openai"} [front] Client protocol the translator speaks (default `"anthropic"`).
|
|
4
|
+
* @property {Array<string | import("./lib/config.mjs").UpstreamConfig>} upstreams Upstream servers: `{ name, url, apiKey, headers, backend, models, default, settings, version }` (or a bare URL).
|
|
5
|
+
* @property {Record<string, string>} [aliases] Client model name to upstream model name.
|
|
6
|
+
* @property {import("./lib/pool.mjs").PoolConfig} [pool] Endpoint pools: `{ strategy, backoff: { base, max }, models }` (see docs/settings.md).
|
|
7
|
+
* @property {Record<string, any>} [settings] Global converter settings (see `lib/settings.mjs`).
|
|
8
|
+
* @property {boolean} [detect] Probe `auto` upstreams at startup (default true).
|
|
9
|
+
* @property {number} [detectTimeout] Probe timeout in ms (default 5000).
|
|
10
|
+
* @property {(url: string, init?: any) => Promise<Response>} [transport] fetch-compatible function used for all upstream calls.
|
|
11
|
+
* @property {boolean} [silent] Suppress warnings.
|
|
12
|
+
* @property {{import?: (url: string) => Promise<any>}} [slothlet] Options forwarded to slothlet (for example `import` for coverage).
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Create a translator: a slothlet api instance (see the README for the leaves) bound to the given upstreams.
|
|
16
|
+
* Endpoints with `backend: "auto"` are probed once before this resolves (set `detect: false` to skip all network access).
|
|
17
|
+
* @param {TranslatorConfig} config - Translator config.
|
|
18
|
+
* @returns {Promise<any>} The translator api (`request`, `response`, `stream`, `send`, `detect`, `status`, `token`, `model`, `error`, `sse`, `server`, `driver`, `convert`, `slothlet`).
|
|
19
|
+
*/
|
|
20
|
+
export function createTranslator(config: TranslatorConfig): Promise<any>;
|
|
21
|
+
export { TranslatorError } from "./lib/errors.mjs";
|
|
22
|
+
export default createTranslator;
|
|
16
23
|
export type TranslatorConfig = {
|
|
17
24
|
/**
|
|
18
25
|
* Client protocol the translator speaks (default `"anthropic"`).
|
|
@@ -26,6 +33,10 @@ export type TranslatorConfig = {
|
|
|
26
33
|
* Client model name to upstream model name.
|
|
27
34
|
*/
|
|
28
35
|
aliases?: Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Endpoint pools: `{ strategy, backoff: { base, max }, models }` (see docs/settings.md).
|
|
38
|
+
*/
|
|
39
|
+
pool?: import("./lib/pool.mjs").PoolConfig;
|
|
29
40
|
/**
|
|
30
41
|
* Global converter settings (see `lib/settings.mjs`).
|
|
31
42
|
*/
|
|
@@ -53,24 +64,3 @@ export type TranslatorConfig = {
|
|
|
53
64
|
import?: (url: string) => Promise<any>;
|
|
54
65
|
};
|
|
55
66
|
};
|
|
56
|
-
/**
|
|
57
|
-
* @typedef {object} TranslatorConfig
|
|
58
|
-
* @property {"anthropic" | "openai"} [front] Client protocol the translator speaks (default `"anthropic"`).
|
|
59
|
-
* @property {Array<string | import("./lib/config.mjs").UpstreamConfig>} upstreams Upstream servers: `{ name, url, apiKey, headers, backend, models, default, settings, version }` (or a bare URL).
|
|
60
|
-
* @property {Record<string, string>} [aliases] Client model name to upstream model name.
|
|
61
|
-
* @property {Record<string, any>} [settings] Global converter settings (see `lib/settings.mjs`).
|
|
62
|
-
* @property {boolean} [detect] Probe `auto` upstreams at startup (default true).
|
|
63
|
-
* @property {number} [detectTimeout] Probe timeout in ms (default 5000).
|
|
64
|
-
* @property {(url: string, init?: any) => Promise<Response>} [transport] fetch-compatible function used for all upstream calls.
|
|
65
|
-
* @property {boolean} [silent] Suppress warnings.
|
|
66
|
-
* @property {{import?: (url: string) => Promise<any>}} [slothlet] Options forwarded to slothlet (for example `import` for coverage).
|
|
67
|
-
*/
|
|
68
|
-
/**
|
|
69
|
-
* Create a translator: a slothlet api instance (see the README for the leaves) bound to the given upstreams.
|
|
70
|
-
* Endpoints with `backend: "auto"` are probed once before this resolves (set `detect: false` to skip all network access).
|
|
71
|
-
* @param {TranslatorConfig} config - Translator config.
|
|
72
|
-
* @returns {Promise<any>} The translator api (`request`, `response`, `stream`, `send`, `detect`, `status`, `token`, `model`, `error`, `sse`, `server`, `driver`, `convert`, `slothlet`).
|
|
73
|
-
*/
|
|
74
|
-
export declare function createTranslator(config: TranslatorConfig): Promise<any>;
|
|
75
|
-
export { TranslatorError };
|
|
76
|
-
export default createTranslator;
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/arguments.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:01-07:00 (1792958341)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Whether tool-call arguments are complete: empty, or a JSON object. Truncated JSON (a `length` stop in the middle
|
|
17
3
|
* of a call) is not.
|
|
18
4
|
* @param {unknown} args - Arguments as received.
|
|
19
5
|
* @returns {boolean} True when the arguments parse (or are empty).
|
|
20
6
|
*/
|
|
21
|
-
export
|
|
7
|
+
export function isComplete(args: unknown): boolean;
|
|
22
8
|
/**
|
|
23
9
|
* Parse OpenAI tool-call `arguments` into the JSON object Anthropic requires for `tool_use.input`. Anything that is
|
|
24
10
|
* not a JSON object (truncated JSON from a `length` stop, a bare array, plain text) is preserved verbatim under
|
|
@@ -27,4 +13,4 @@ export declare function isComplete(args: unknown): boolean;
|
|
|
27
13
|
* @param {unknown} args - JSON string (or already-parsed value) from the upstream.
|
|
28
14
|
* @returns {object} Input object.
|
|
29
15
|
*/
|
|
30
|
-
export
|
|
16
|
+
export function parseArguments(args: unknown): object;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object body, or an empty one.
|
|
3
|
+
* @param {{ok: boolean, body: any}} result - Outcome of a probe.
|
|
4
|
+
* @returns {Record<string, any>} The parsed JSON object when the request succeeded.
|
|
5
|
+
*/
|
|
6
|
+
export function objectOf(result: {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
body: any;
|
|
9
|
+
}): Record<string, any>;
|
|
10
|
+
/**
|
|
11
|
+
* Does a `/props` reply come from `llama-server`?
|
|
12
|
+
* @param {Record<string, any>} body - Reply object (see `objectOf`).
|
|
13
|
+
* @returns {boolean} True when it carries llama-server fields.
|
|
14
|
+
*/
|
|
15
|
+
export function isLlamacppProps(body: Record<string, any>): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Does a `/get_server_info` reply come from SGLang?
|
|
18
|
+
* @param {Record<string, any>} body - Reply object (see `objectOf`).
|
|
19
|
+
* @returns {boolean} True when it names a model or tokenizer path.
|
|
20
|
+
*/
|
|
21
|
+
export function isSglangInfo(body: Record<string, any>): boolean;
|
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/capture.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
|
* Collect the mounted drivers, sorted by `info().order`.
|
|
17
3
|
* @param {any} driverApi - `self.driver`.
|
|
18
4
|
* @returns {any[]} Driver records with captured function references.
|
|
19
5
|
*/
|
|
20
|
-
export
|
|
6
|
+
export function collect(driverApi: any): any[];
|
|
21
7
|
/**
|
|
22
8
|
* Capture config, state, drivers and converters from a leaf's `self` and `context`.
|
|
23
9
|
* @param {any} self - Slothlet `self` proxy.
|
|
@@ -25,4 +11,4 @@ export declare function collect(driverApi: any): any[];
|
|
|
25
11
|
* @param {"anthropic" | "openai"} [frontOverride] - Client protocol for this call (default: the configured front).
|
|
26
12
|
* @returns {any} Captured values and lookup helpers (safe to use after awaits).
|
|
27
13
|
*/
|
|
28
|
-
export
|
|
14
|
+
export function capture(self: any, context: any, frontOverride?: "anthropic" | "openai"): any;
|
package/types/src/lib/cli.d.mts
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/cli.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 the command line.
|
|
17
3
|
* @param {string[]} argv - Arguments without the node and script paths.
|
|
18
4
|
* @returns {any} Parsed values (see `parseArgs`).
|
|
19
5
|
*/
|
|
20
|
-
export
|
|
6
|
+
export function parse(argv: string[]): any;
|
|
21
7
|
/**
|
|
22
8
|
* Merge flags, environment and the config file into `{ translator, server }`.
|
|
23
9
|
* @param {any} values - Parsed flags.
|
|
@@ -25,19 +11,10 @@ export declare function parse(argv: string[]): any;
|
|
|
25
11
|
* @param {any} file - Parsed config file ({} when none).
|
|
26
12
|
* @returns {{translator: any, server: any}} Translator config and server options.
|
|
27
13
|
*/
|
|
28
|
-
export
|
|
14
|
+
export function merge(values: any, env: Record<string, string | undefined>, file: any): {
|
|
29
15
|
translator: any;
|
|
30
16
|
server: any;
|
|
31
17
|
};
|
|
32
|
-
/**
|
|
33
|
-
* Default I/O bindings for `main`.
|
|
34
|
-
* @type {{out: (text: string) => void, err: (text: string) => void, onSignal: (handler: () => void) => void}}
|
|
35
|
-
*/
|
|
36
|
-
export declare const processIo: {
|
|
37
|
-
out: (text: string) => void;
|
|
38
|
-
err: (text: string) => void;
|
|
39
|
-
onSignal: (handler: () => void) => void;
|
|
40
|
-
};
|
|
41
18
|
/**
|
|
42
19
|
* Run the CLI. Resolves with the exit code once the server stopped (after a signal) or startup failed.
|
|
43
20
|
* @param {string[]} argv - Arguments without the node and script paths.
|
|
@@ -46,4 +23,13 @@ export declare const processIo: {
|
|
|
46
23
|
* @param {any} [lib] - Overridable collaborators `{ createTranslator, version }` (loaded lazily when omitted).
|
|
47
24
|
* @returns {Promise<number>} Process exit code.
|
|
48
25
|
*/
|
|
49
|
-
export
|
|
26
|
+
export function main(argv: string[], env?: Record<string, string | undefined>, io?: typeof processIo, lib?: any): Promise<number>;
|
|
27
|
+
/**
|
|
28
|
+
* Default I/O bindings for `main`.
|
|
29
|
+
* @type {{out: (text: string) => void, err: (text: string) => void, onSignal: (handler: () => void) => void}}
|
|
30
|
+
*/
|
|
31
|
+
export const processIo: {
|
|
32
|
+
out: (text: string) => void;
|
|
33
|
+
err: (text: string) => void;
|
|
34
|
+
onSignal: (handler: () => void) => void;
|
|
35
|
+
};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
2
|
+
* Normalize one upstream entry into the runtime endpoint record.
|
|
3
|
+
* @param {string | UpstreamConfig} entry - Upstream URL or config object.
|
|
4
|
+
* @param {number} index - Position in the list.
|
|
5
|
+
* @returns {any} Runtime endpoint.
|
|
6
|
+
*/
|
|
7
|
+
export function endpoint(entry: string | UpstreamConfig, index: number): any;
|
|
8
|
+
/**
|
|
9
|
+
* Validate and normalize the translator config.
|
|
10
|
+
* @param {any} [config] - Raw config passed to `createTranslator`.
|
|
11
|
+
* @returns {any} Normalized config (a fresh any; the input is not mutated).
|
|
14
12
|
*/
|
|
13
|
+
export function normalize(config?: any): any;
|
|
15
14
|
export type UpstreamConfig = {
|
|
16
15
|
/**
|
|
17
16
|
* Display name, defaults to `upstream-<index>`.
|
|
@@ -50,16 +49,3 @@ export type UpstreamConfig = {
|
|
|
50
49
|
*/
|
|
51
50
|
version?: string;
|
|
52
51
|
};
|
|
53
|
-
/**
|
|
54
|
-
* Normalize one upstream entry into the runtime endpoint record.
|
|
55
|
-
* @param {string | UpstreamConfig} entry - Upstream URL or config object.
|
|
56
|
-
* @param {number} index - Position in the list.
|
|
57
|
-
* @returns {any} Runtime endpoint.
|
|
58
|
-
*/
|
|
59
|
-
export declare function endpoint(entry: string | UpstreamConfig, index: number): any;
|
|
60
|
-
/**
|
|
61
|
-
* Validate and normalize the translator config.
|
|
62
|
-
* @param {any} [config] - Raw config passed to `createTranslator`.
|
|
63
|
-
* @returns {any} Normalized config (a fresh any; the input is not mutated).
|
|
64
|
-
*/
|
|
65
|
-
export declare function normalize(config?: any): any;
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
2
|
+
* Context for converting documents.
|
|
3
|
+
* @typedef {object} DocumentContext
|
|
4
|
+
* @property {import("./settings.mjs").Settings} settings - Resolved settings.
|
|
5
|
+
* @property {Map<string, any>} toolInputs - `tool_use` inputs by id, to recover file paths.
|
|
6
|
+
* @property {string|null} toolUseId - Id of the tool call whose result contains the document, if any.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Convert a document block into Anthropic text/image blocks.
|
|
10
|
+
* @param {any} block - Anthropic `document` block.
|
|
11
|
+
* @param {DocumentContext} ctx - Conversion context.
|
|
12
|
+
* @returns {Promise<any[]>} Content blocks (`text` and `image`).
|
|
13
|
+
* @throws {TranslatorError} When `documents` is `"error"` or a PDF violates the size/page limits.
|
|
14
|
+
*/
|
|
15
|
+
export function expand(block: any, ctx: DocumentContext): Promise<any[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Context for converting documents.
|
|
14
18
|
*/
|
|
15
19
|
export type DocumentContext = {
|
|
16
20
|
/**
|
|
@@ -26,18 +30,3 @@ export type DocumentContext = {
|
|
|
26
30
|
*/
|
|
27
31
|
toolUseId: string | null;
|
|
28
32
|
};
|
|
29
|
-
/**
|
|
30
|
-
* Context for converting documents.
|
|
31
|
-
* @typedef {object} DocumentContext
|
|
32
|
-
* @property {import("./settings.mjs").Settings} settings - Resolved settings.
|
|
33
|
-
* @property {Map<string, any>} toolInputs - `tool_use` inputs by id, to recover file paths.
|
|
34
|
-
* @property {string|null} toolUseId - Id of the tool call whose result contains the document, if any.
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* Convert a document block into Anthropic text/image blocks.
|
|
38
|
-
* @param {any} block - Anthropic `document` block.
|
|
39
|
-
* @param {DocumentContext} ctx - Conversion context.
|
|
40
|
-
* @returns {Promise<any[]>} Content blocks (`text` and `image`).
|
|
41
|
-
* @throws {TranslatorError} When `documents` is `"error"` or a PDF violates the size/page limits.
|
|
42
|
-
*/
|
|
43
|
-
export declare function expand(block: any, ctx: DocumentContext): Promise<any[]>;
|
|
@@ -1,95 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/errors.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:29:30-07:00 (1792956570)
|
|
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
|
-
/**
|
|
16
|
-
* @fileoverview Error type shared by every converter, plus helpers that render an error in either wire protocol.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Error raised for requests or upstream replies the translator cannot (or will not) convert. Carries enough
|
|
20
|
-
* information to be rendered as an Anthropic or an OpenAI error body.
|
|
21
|
-
*/
|
|
22
|
-
export declare class TranslatorError extends Error {
|
|
23
|
-
code: string;
|
|
24
|
-
status: number;
|
|
25
|
-
type: string;
|
|
26
|
-
param: string;
|
|
27
|
-
details: unknown;
|
|
28
|
-
/**
|
|
29
|
-
* @param {string} message - Human readable message (sent to the client).
|
|
30
|
-
* @param {object} [options] - Error metadata.
|
|
31
|
-
* @param {string} [options.code] - Stable machine readable code (for example `"unsupported_field"`).
|
|
32
|
-
* @param {number} [options.status] - HTTP status to answer with.
|
|
33
|
-
* @param {string} [options.type] - Anthropic style error type.
|
|
34
|
-
* @param {string|null} [options.param] - Offending request parameter, when known.
|
|
35
|
-
* @param {unknown} [options.details] - Extra data for logs and tests.
|
|
36
|
-
*/
|
|
37
|
-
constructor(message: string, options?: {
|
|
38
|
-
code?: string;
|
|
39
|
-
status?: number;
|
|
40
|
-
type?: string;
|
|
41
|
-
param?: string | null;
|
|
42
|
-
details?: unknown;
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* Render as an Anthropic error body.
|
|
46
|
-
* @returns {{ type: "error", error: { type: string, message: string } }} Anthropic error body.
|
|
47
|
-
*/
|
|
48
|
-
toAnthropic(): {
|
|
49
|
-
type: "error";
|
|
50
|
-
error: {
|
|
51
|
-
type: string;
|
|
52
|
-
message: string;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Render as an OpenAI error body.
|
|
57
|
-
* @returns {{ error: { message: string, type: string, param: string|null, code: string|number|null } }} OpenAI error body.
|
|
58
|
-
*/
|
|
59
|
-
toOpenAI(): {
|
|
60
|
-
error: {
|
|
61
|
-
message: string;
|
|
62
|
-
type: string;
|
|
63
|
-
param: string | null;
|
|
64
|
-
code: string | number | null;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
1
|
/**
|
|
69
2
|
* Anthropic error type for an HTTP status.
|
|
70
3
|
* @param {number} status - HTTP status code.
|
|
71
4
|
* @returns {string} Anthropic error type.
|
|
72
5
|
*/
|
|
73
|
-
export
|
|
6
|
+
export function statusToAnthropicType(status: number): string;
|
|
74
7
|
/**
|
|
75
8
|
* HTTP status for an Anthropic error type.
|
|
76
9
|
* @param {string} type - Anthropic error type.
|
|
77
10
|
* @returns {number} HTTP status code.
|
|
78
11
|
*/
|
|
79
|
-
export
|
|
12
|
+
export function anthropicTypeToStatus(type: string): number;
|
|
80
13
|
/**
|
|
81
14
|
* OpenAI style error type for an Anthropic error type.
|
|
82
15
|
* @param {string} type - Anthropic error type.
|
|
83
16
|
* @returns {string} OpenAI error type.
|
|
84
17
|
*/
|
|
85
|
-
export
|
|
18
|
+
export function anthropicToOpenAIType(type: string): string;
|
|
86
19
|
/**
|
|
87
20
|
* Anthropic error type for an OpenAI style error object (type and/or numeric code and/or HTTP status).
|
|
88
21
|
* @param {{ type?: string|null, code?: string|number|null }} error - OpenAI error object.
|
|
89
22
|
* @param {number} [status] - HTTP status of the reply, when known.
|
|
90
23
|
* @returns {string} Anthropic error type.
|
|
91
24
|
*/
|
|
92
|
-
export
|
|
25
|
+
export function openaiToAnthropicType(error: {
|
|
93
26
|
type?: string | null;
|
|
94
27
|
code?: string | number | null;
|
|
95
28
|
}, status?: number): string;
|
|
@@ -99,7 +32,7 @@ export declare function openaiToAnthropicType(error: {
|
|
|
99
32
|
* @param {string} message - Error message.
|
|
100
33
|
* @returns {{ type: "error", error: { type: string, message: string } }} Anthropic error body.
|
|
101
34
|
*/
|
|
102
|
-
export
|
|
35
|
+
export function anthropicError(type: string, message: string): {
|
|
103
36
|
type: "error";
|
|
104
37
|
error: {
|
|
105
38
|
type: string;
|
|
@@ -112,7 +45,7 @@ export declare function anthropicError(type: string, message: string): {
|
|
|
112
45
|
* @param {{ type?: string, param?: string|null, code?: string|number|null }} [fields] - Optional fields.
|
|
113
46
|
* @returns {{ error: { message: string, type: string, param: string|null, code: string|number|null } }} OpenAI error body.
|
|
114
47
|
*/
|
|
115
|
-
export
|
|
48
|
+
export function openaiError(message: string, { type, param, code }?: {
|
|
116
49
|
type?: string;
|
|
117
50
|
param?: string | null;
|
|
118
51
|
code?: string | number | null;
|
|
@@ -132,13 +65,80 @@ export declare function openaiError(message: string, { type, param, code }?: {
|
|
|
132
65
|
* @param {string} message - Upstream error message.
|
|
133
66
|
* @returns {string|null} Rewritten message, or null when the message is not a context overflow.
|
|
134
67
|
*/
|
|
135
|
-
export
|
|
68
|
+
export function rewriteContextOverflow(message: string): string | null;
|
|
136
69
|
/**
|
|
137
70
|
* Token counts from a context-overflow message.
|
|
138
71
|
* @param {string} message - Upstream error message.
|
|
139
72
|
* @returns {{ prompt: number, max: number }|null} Counts (`prompt` is the requested total, or the prompt size, or `max + 1`), or null when not an overflow.
|
|
140
73
|
*/
|
|
141
|
-
export
|
|
74
|
+
export function contextOverflow(message: string): {
|
|
142
75
|
prompt: number;
|
|
143
76
|
max: number;
|
|
144
77
|
} | null;
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @Project: @cldmv/llm-translator
|
|
81
|
+
* @Filename: /src/lib/errors.mjs
|
|
82
|
+
* @Date: 2026-10-25T12:29:30-07:00 (1792956570)
|
|
83
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
84
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
85
|
+
* -----
|
|
86
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
87
|
+
* @Last modified time: 2026-10-25T13:31:30-07:00 (1792960290)
|
|
88
|
+
* -----
|
|
89
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
90
|
+
*
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* @fileoverview Error type shared by every converter, plus helpers that render an error in either wire protocol.
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* Error raised for requests or upstream replies the translator cannot (or will not) convert. Carries enough
|
|
97
|
+
* information to be rendered as an Anthropic or an OpenAI error body.
|
|
98
|
+
*/
|
|
99
|
+
export class TranslatorError extends Error {
|
|
100
|
+
/**
|
|
101
|
+
* @param {string} message - Human readable message (sent to the client).
|
|
102
|
+
* @param {object} [options] - Error metadata.
|
|
103
|
+
* @param {string} [options.code] - Stable machine readable code (for example `"unsupported_field"`).
|
|
104
|
+
* @param {number} [options.status] - HTTP status to answer with.
|
|
105
|
+
* @param {string} [options.type] - Anthropic style error type.
|
|
106
|
+
* @param {string|null} [options.param] - Offending request parameter, when known.
|
|
107
|
+
* @param {unknown} [options.details] - Extra data for logs and tests.
|
|
108
|
+
*/
|
|
109
|
+
constructor(message: string, options?: {
|
|
110
|
+
code?: string;
|
|
111
|
+
status?: number;
|
|
112
|
+
type?: string;
|
|
113
|
+
param?: string | null;
|
|
114
|
+
details?: unknown;
|
|
115
|
+
});
|
|
116
|
+
code: string;
|
|
117
|
+
status: number;
|
|
118
|
+
type: string;
|
|
119
|
+
param: string;
|
|
120
|
+
details: unknown;
|
|
121
|
+
/**
|
|
122
|
+
* Render as an Anthropic error body.
|
|
123
|
+
* @returns {{ type: "error", error: { type: string, message: string } }} Anthropic error body.
|
|
124
|
+
*/
|
|
125
|
+
toAnthropic(): {
|
|
126
|
+
type: "error";
|
|
127
|
+
error: {
|
|
128
|
+
type: string;
|
|
129
|
+
message: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Render as an OpenAI error body.
|
|
134
|
+
* @returns {{ error: { message: string, type: string, param: string|null, code: string|number|null } }} OpenAI error body.
|
|
135
|
+
*/
|
|
136
|
+
toOpenAI(): {
|
|
137
|
+
error: {
|
|
138
|
+
message: string;
|
|
139
|
+
type: string;
|
|
140
|
+
param: string | null;
|
|
141
|
+
code: string | number | null;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|