@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.
Files changed (151) hide show
  1. package/README.md +176 -7
  2. package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +17 -0
  3. package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +2 -0
  4. package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +2 -0
  5. package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +6 -0
  6. package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +2 -0
  7. package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +2 -0
  8. package/dist/api/detect.mjs +2 -0
  9. package/dist/api/driver/anthropic/detect.mjs +2 -0
  10. package/dist/api/driver/anthropic/info.mjs +2 -0
  11. package/dist/api/driver/anthropic/model/list.mjs +2 -0
  12. package/dist/api/driver/anthropic/settings.mjs +2 -0
  13. package/dist/api/driver/anthropic/token/count.mjs +2 -0
  14. package/dist/api/driver/compatible/detect.mjs +2 -0
  15. package/dist/api/driver/compatible/info.mjs +2 -0
  16. package/dist/api/driver/compatible/model/list.mjs +2 -0
  17. package/dist/api/driver/compatible/request.mjs +2 -0
  18. package/dist/api/driver/compatible/settings.mjs +2 -0
  19. package/dist/api/driver/openai/detect.mjs +2 -0
  20. package/dist/api/driver/openai/info.mjs +2 -0
  21. package/dist/api/driver/openai/model/list.mjs +2 -0
  22. package/dist/api/driver/openai/request.mjs +2 -0
  23. package/dist/api/driver/openai/settings.mjs +2 -0
  24. package/dist/api/driver/vllm/detect.mjs +2 -0
  25. package/dist/api/driver/vllm/error.mjs +2 -0
  26. package/dist/api/driver/vllm/info.mjs +2 -0
  27. package/dist/api/driver/vllm/model/list.mjs +2 -0
  28. package/dist/api/driver/vllm/probe.mjs +2 -0
  29. package/dist/api/driver/vllm/request.mjs +2 -0
  30. package/dist/api/driver/vllm/settings.mjs +2 -0
  31. package/dist/api/driver/vllm/token/count.mjs +2 -0
  32. package/dist/api/error/build.mjs +2 -0
  33. package/dist/api/error/error.mjs +2 -0
  34. package/dist/api/model/list.mjs +2 -0
  35. package/dist/api/request.mjs +3 -0
  36. package/dist/api/response.mjs +2 -0
  37. package/dist/api/send.mjs +2 -0
  38. package/dist/api/server/plugin.mjs +2 -0
  39. package/dist/api/server/start.mjs +2 -0
  40. package/dist/api/server/stop.mjs +2 -0
  41. package/dist/api/sse/encode.mjs +4 -0
  42. package/dist/api/sse/parse.mjs +2 -0
  43. package/dist/api/sse/ping.mjs +2 -0
  44. package/dist/api/sse/write.mjs +2 -0
  45. package/dist/api/status.mjs +2 -0
  46. package/dist/api/stream.mjs +2 -0
  47. package/dist/api/token/count.mjs +2 -0
  48. package/dist/bin/llm-translator.mjs +3 -0
  49. package/dist/index.mjs +1 -1
  50. package/dist/lib/arguments.mjs +2 -0
  51. package/dist/lib/capture.mjs +2 -0
  52. package/dist/lib/cli.mjs +29 -0
  53. package/dist/lib/config.mjs +2 -0
  54. package/dist/lib/documents.mjs +12 -0
  55. package/dist/lib/errors.mjs +2 -0
  56. package/dist/lib/estimate.mjs +2 -0
  57. package/dist/lib/finish.mjs +2 -0
  58. package/dist/lib/http.mjs +2 -0
  59. package/dist/lib/ids.mjs +2 -0
  60. package/dist/lib/images.mjs +2 -0
  61. package/dist/lib/models.mjs +2 -0
  62. package/dist/lib/normalize.mjs +2 -0
  63. package/dist/lib/passthrough.mjs +2 -0
  64. package/dist/lib/pdf.mjs +2 -0
  65. package/dist/lib/ping.mjs +2 -0
  66. package/dist/lib/route.mjs +2 -0
  67. package/dist/lib/routes.mjs +2 -0
  68. package/dist/lib/runtime.mjs +2 -0
  69. package/dist/lib/schema.mjs +2 -0
  70. package/dist/lib/settings.mjs +2 -0
  71. package/dist/lib/source.mjs +2 -0
  72. package/dist/lib/sse.mjs +10 -0
  73. package/dist/lib/thinking.mjs +2 -0
  74. package/dist/lib/transport.mjs +2 -0
  75. package/dist/lib/upstream-error.mjs +2 -0
  76. package/dist/lib/warn.mjs +2 -0
  77. package/package.json +30 -5
  78. package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +28 -0
  79. package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +24 -0
  80. package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +29 -0
  81. package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +30 -0
  82. package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +28 -0
  83. package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +38 -0
  84. package/types/src/api/detect.d.mts +21 -0
  85. package/types/src/api/driver/anthropic/detect.d.mts +26 -0
  86. package/types/src/api/driver/anthropic/info.d.mts +30 -0
  87. package/types/src/api/driver/anthropic/model/list.d.mts +20 -0
  88. package/types/src/api/driver/anthropic/settings.d.mts +23 -0
  89. package/types/src/api/driver/anthropic/token/count.d.mts +20 -0
  90. package/types/src/api/driver/compatible/detect.d.mts +23 -0
  91. package/types/src/api/driver/compatible/info.d.mts +29 -0
  92. package/types/src/api/driver/compatible/model/list.d.mts +20 -0
  93. package/types/src/api/driver/compatible/request.d.mts +20 -0
  94. package/types/src/api/driver/compatible/settings.d.mts +23 -0
  95. package/types/src/api/driver/openai/detect.d.mts +26 -0
  96. package/types/src/api/driver/openai/info.d.mts +29 -0
  97. package/types/src/api/driver/openai/model/list.d.mts +20 -0
  98. package/types/src/api/driver/openai/request.d.mts +20 -0
  99. package/types/src/api/driver/openai/settings.d.mts +23 -0
  100. package/types/src/api/driver/vllm/detect.d.mts +20 -0
  101. package/types/src/api/driver/vllm/error.d.mts +28 -0
  102. package/types/src/api/driver/vllm/info.d.mts +29 -0
  103. package/types/src/api/driver/vllm/model/list.d.mts +20 -0
  104. package/types/src/api/driver/vllm/probe.d.mts +39 -0
  105. package/types/src/api/driver/vllm/request.d.mts +22 -0
  106. package/types/src/api/driver/vllm/settings.d.mts +22 -0
  107. package/types/src/api/driver/vllm/token/count.d.mts +20 -0
  108. package/types/src/api/error/build.d.mts +26 -0
  109. package/types/src/api/error/error.d.mts +29 -0
  110. package/types/src/api/model/list.d.mts +21 -0
  111. package/types/src/api/request.d.mts +35 -0
  112. package/types/src/api/response.d.mts +22 -0
  113. package/types/src/api/send.d.mts +32 -0
  114. package/types/src/api/server/plugin.d.mts +24 -0
  115. package/types/src/api/server/start.d.mts +26 -0
  116. package/types/src/api/server/stop.d.mts +19 -0
  117. package/types/src/api/sse/encode.d.mts +26 -0
  118. package/types/src/api/sse/parse.d.mts +24 -0
  119. package/types/src/api/sse/ping.d.mts +30 -0
  120. package/types/src/api/sse/write.d.mts +26 -0
  121. package/types/src/api/status.d.mts +22 -0
  122. package/types/src/api/stream.d.mts +25 -0
  123. package/types/src/api/token/count.d.mts +24 -0
  124. package/types/src/index.d.mts +61 -4
  125. package/types/src/lib/arguments.d.mts +30 -0
  126. package/types/src/lib/capture.d.mts +28 -0
  127. package/types/src/lib/cli.d.mts +49 -0
  128. package/types/src/lib/config.d.mts +65 -0
  129. package/types/src/lib/documents.d.mts +43 -0
  130. package/types/src/lib/errors.d.mts +144 -0
  131. package/types/src/lib/estimate.d.mts +24 -0
  132. package/types/src/lib/finish.d.mts +73 -0
  133. package/types/src/lib/http.d.mts +58 -0
  134. package/types/src/lib/ids.d.mts +55 -0
  135. package/types/src/lib/images.d.mts +39 -0
  136. package/types/src/lib/models.d.mts +25 -0
  137. package/types/src/lib/normalize.d.mts +37 -0
  138. package/types/src/lib/passthrough.d.mts +22 -0
  139. package/types/src/lib/pdf.d.mts +67 -0
  140. package/types/src/lib/ping.d.mts +24 -0
  141. package/types/src/lib/route.d.mts +38 -0
  142. package/types/src/lib/routes.d.mts +22 -0
  143. package/types/src/lib/runtime.d.mts +24 -0
  144. package/types/src/lib/schema.d.mts +22 -0
  145. package/types/src/lib/settings.d.mts +175 -0
  146. package/types/src/lib/source.d.mts +32 -0
  147. package/types/src/lib/sse.d.mts +72 -0
  148. package/types/src/lib/thinking.d.mts +60 -0
  149. package/types/src/lib/transport.d.mts +31 -0
  150. package/types/src/lib/upstream-error.d.mts +57 -0
  151. package/types/src/lib/warn.d.mts +26 -0
@@ -0,0 +1,19 @@
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
+ /**
16
+ * Close all servers started with `server.start`.
17
+ * @returns {Promise<void>} Resolves when every server has closed.
18
+ */
19
+ export declare function stop(): Promise<void>;
@@ -0,0 +1,26 @@
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
+ /**
16
+ * Encode `{ event?, data, id? }` (object data is JSON-encoded, `"[DONE]"` is written as is) or a keep-alive comment
17
+ * `{ comment }` as an SSE frame.
18
+ * @param {{event?: string, data?: any, id?: string, comment?: string}} message - Event to encode.
19
+ * @returns {string} SSE text ending with a blank line.
20
+ */
21
+ export declare function encode(message: {
22
+ event?: string;
23
+ data?: any;
24
+ id?: string;
25
+ comment?: string;
26
+ }): string;
@@ -0,0 +1,24 @@
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
+ /**
16
+ * Parse SSE text/bytes (or already-parsed events) into `{ event?, data }` messages. `data` is decoded JSON, or the string
17
+ * `"[DONE]"`.
18
+ * @param {ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array} source - SSE input.
19
+ * @returns {AsyncGenerator<{event?: string, data: *}>} Messages.
20
+ */
21
+ export declare function parse(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array): AsyncGenerator<{
22
+ event?: string;
23
+ data: any;
24
+ }>;
@@ -0,0 +1,30 @@
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
+ /**
16
+ * Wrap an event stream so a keep-alive is yielded whenever the source is silent for `interval` ms.
17
+ *
18
+ * Anthropic fronts: Claude Code's idle watchdog ignores `event: ping` (it only counts real stream events) and aborts a
19
+ * stream after 300 seconds without one, so while a content block is open the keep-alive is an empty delta of that
20
+ * block's type (`text_delta`, `thinking_delta` or `input_json_delta` with no content), which every client treats as
21
+ * activity and which changes nothing. With no block open, a plain `event: ping` is used. OpenAI fronts get an SSE
22
+ * comment frame, which every OpenAI client ignores.
23
+ * @param {AsyncIterable<{event?: string, data: *}>} events - Client events.
24
+ * @param {any} [options] - `{ interval, front }`. `interval` defaults to the `pingInterval` setting; `0` disables pings.
25
+ * @returns {AsyncGenerator<any>} Events interleaved with keep-alives.
26
+ */
27
+ export declare function ping(events: AsyncIterable<{
28
+ event?: string;
29
+ data: any;
30
+ }>, options?: any): AsyncGenerator<any>;
@@ -0,0 +1,26 @@
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
+ /**
16
+ * Pump client events into a writable as SSE frames, interleaving keep-alive pings while the source is silent and honoring
17
+ * backpressure. Does not end the writable. Stops early (closing the event source) when the writable closes.
18
+ * @param {import("node:stream").Writable} target - Destination, for example `reply.raw`.
19
+ * @param {AsyncIterable<{event?: string, data: *}>} events - Client events.
20
+ * @param {any} [options] - `{ interval, front }` forwarded to `sse.ping`.
21
+ * @returns {Promise<boolean>} True when every event was written, false when the writable closed first.
22
+ */
23
+ export declare function write(target: import("node:stream").Writable, events: AsyncIterable<{
24
+ event?: string;
25
+ data: any;
26
+ }>, options?: any): Promise<boolean>;
@@ -0,0 +1,22 @@
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
+ /**
16
+ * 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.
18
+ */
19
+ export declare function status(): {
20
+ front: string;
21
+ upstreams: any[];
22
+ };
@@ -0,0 +1,25 @@
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
+ /**
16
+ * Convert an upstream SSE stream to client events: Anthropic events (`message_start`, `content_block_*`, ...) for the
17
+ * Anthropic front, Chat Completions chunks followed by `"[DONE]"` for the OpenAI front. Pings are added by the SSE writer.
18
+ * @param {ReadableStream | AsyncIterable<string | Uint8Array> | string} source - Upstream SSE bytes or text.
19
+ * @param {any} state - The `state` returned by `request`.
20
+ * @returns {AsyncIterable<{event?: string, data: *}>} Client events.
21
+ */
22
+ export declare function stream(source: ReadableStream | AsyncIterable<string | Uint8Array> | string, state: any): AsyncIterable<{
23
+ event?: string;
24
+ data: any;
25
+ }>;
@@ -0,0 +1,24 @@
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
+ /**
16
+ * Count input tokens for a client request. Uses the upstream's own tokenizer when its driver has one (vLLM `/tokenize`,
17
+ * Anthropic `count_tokens`); otherwise a documented estimate of one token per four characters.
18
+ * @param {any} body - Client request body (per `front`).
19
+ * @param {any} [options] - `{ signal, front }`.
20
+ * @returns {Promise<{input_tokens: number}>} Anthropic `count_tokens` shaped result.
21
+ */
22
+ export declare function count(body: any, options?: any): Promise<{
23
+ input_tokens: number;
24
+ }>;
@@ -7,13 +7,70 @@
7
7
  * @Email: <Shinrai@users.noreply.github.com>
8
8
  * -----
9
9
  * @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
10
- * @Last modified time: 2026-10-24T21:34:45-07:00 (1792902885)
10
+ * @Last modified time: 2026-10-25T12:59:01-07:00 (1792958341)
11
11
  * -----
12
12
  * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
13
  *
14
14
  */
15
+ import { TranslatorError } from "./lib/errors.mjs";
16
+ export type TranslatorConfig = {
17
+ /**
18
+ * Client protocol the translator speaks (default `"anthropic"`).
19
+ */
20
+ front?: "anthropic" | "openai";
21
+ /**
22
+ * Upstream servers: `{ name, url, apiKey, headers, backend, models, default, settings, version }` (or a bare URL).
23
+ */
24
+ upstreams: Array<string | import("./lib/config.mjs").UpstreamConfig>;
25
+ /**
26
+ * Client model name to upstream model name.
27
+ */
28
+ aliases?: Record<string, string>;
29
+ /**
30
+ * Global converter settings (see `lib/settings.mjs`).
31
+ */
32
+ settings?: Record<string, any>;
33
+ /**
34
+ * Probe `auto` upstreams at startup (default true).
35
+ */
36
+ detect?: boolean;
37
+ /**
38
+ * Probe timeout in ms (default 5000).
39
+ */
40
+ detectTimeout?: number;
41
+ /**
42
+ * fetch-compatible function used for all upstream calls.
43
+ */
44
+ transport?: (url: string, init?: any) => Promise<Response>;
45
+ /**
46
+ * Suppress warnings.
47
+ */
48
+ silent?: boolean;
49
+ /**
50
+ * Options forwarded to slothlet (for example `import` for coverage).
51
+ */
52
+ slothlet?: {
53
+ import?: (url: string) => Promise<any>;
54
+ };
55
+ };
15
56
  /**
16
- * The package name.
17
- * @type {string}
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).
18
67
  */
19
- export declare const name: string;
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;
@@ -0,0 +1,30 @@
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
+ /**
16
+ * Whether tool-call arguments are complete: empty, or a JSON object. Truncated JSON (a `length` stop in the middle
17
+ * of a call) is not.
18
+ * @param {unknown} args - Arguments as received.
19
+ * @returns {boolean} True when the arguments parse (or are empty).
20
+ */
21
+ export declare function isComplete(args: unknown): boolean;
22
+ /**
23
+ * Parse OpenAI tool-call `arguments` into the JSON object Anthropic requires for `tool_use.input`. Anything that is
24
+ * not a JSON object (truncated JSON from a `length` stop, a bare array, plain text) is preserved verbatim under
25
+ * `_raw_arguments`, so the client's own input validation reports an error the model can recover from instead of the
26
+ * translator silently inventing arguments.
27
+ * @param {unknown} args - JSON string (or already-parsed value) from the upstream.
28
+ * @returns {object} Input object.
29
+ */
30
+ export declare function parseArguments(args: unknown): object;
@@ -0,0 +1,28 @@
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
+ /**
16
+ * Collect the mounted drivers, sorted by `info().order`.
17
+ * @param {any} driverApi - `self.driver`.
18
+ * @returns {any[]} Driver records with captured function references.
19
+ */
20
+ export declare function collect(driverApi: any): any[];
21
+ /**
22
+ * Capture config, state, drivers and converters from a leaf's `self` and `context`.
23
+ * @param {any} self - Slothlet `self` proxy.
24
+ * @param {any} context - Slothlet `context` proxy (`config`, `state`).
25
+ * @param {"anthropic" | "openai"} [frontOverride] - Client protocol for this call (default: the configured front).
26
+ * @returns {any} Captured values and lookup helpers (safe to use after awaits).
27
+ */
28
+ export declare function capture(self: any, context: any, frontOverride?: "anthropic" | "openai"): any;
@@ -0,0 +1,49 @@
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
+ /**
16
+ * Parse the command line.
17
+ * @param {string[]} argv - Arguments without the node and script paths.
18
+ * @returns {any} Parsed values (see `parseArgs`).
19
+ */
20
+ export declare function parse(argv: string[]): any;
21
+ /**
22
+ * Merge flags, environment and the config file into `{ translator, server }`.
23
+ * @param {any} values - Parsed flags.
24
+ * @param {Record<string,string | undefined>} env - Environment.
25
+ * @param {any} file - Parsed config file ({} when none).
26
+ * @returns {{translator: any, server: any}} Translator config and server options.
27
+ */
28
+ export declare function merge(values: any, env: Record<string, string | undefined>, file: any): {
29
+ translator: any;
30
+ server: any;
31
+ };
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
+ /**
42
+ * Run the CLI. Resolves with the exit code once the server stopped (after a signal) or startup failed.
43
+ * @param {string[]} argv - Arguments without the node and script paths.
44
+ * @param {Record<string,string | undefined>} [env] - Environment.
45
+ * @param {typeof processIo} [io] - Output and signal bindings.
46
+ * @param {any} [lib] - Overridable collaborators `{ createTranslator, version }` (loaded lazily when omitted).
47
+ * @returns {Promise<number>} Process exit code.
48
+ */
49
+ export declare function main(argv: string[], env?: Record<string, string | undefined>, io?: typeof processIo, lib?: any): Promise<number>;
@@ -0,0 +1,65 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/lib/config.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:05:38-07:00 (1792962338)
11
+ * -----
12
+ * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
13
+ *
14
+ */
15
+ export type UpstreamConfig = {
16
+ /**
17
+ * Display name, defaults to `upstream-<index>`.
18
+ */
19
+ name?: string;
20
+ /**
21
+ * Base URL of the upstream server (`http://host:8000`).
22
+ */
23
+ url: string;
24
+ /**
25
+ * Key sent to the upstream.
26
+ */
27
+ apiKey?: string;
28
+ /**
29
+ * Extra headers sent to the upstream.
30
+ */
31
+ headers?: Record<string, string>;
32
+ /**
33
+ * Driver name, or `"auto"` (default) to detect.
34
+ */
35
+ backend?: string;
36
+ /**
37
+ * Models this upstream serves (routing).
38
+ */
39
+ models?: string[];
40
+ /**
41
+ * Marks the fallback upstream.
42
+ */
43
+ default?: boolean;
44
+ /**
45
+ * Settings overrides for this upstream.
46
+ */
47
+ settings?: object;
48
+ /**
49
+ * Server version (skips nothing, but feeds version-mapped driver settings).
50
+ */
51
+ version?: string;
52
+ };
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;
@@ -0,0 +1,43 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/lib/documents.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
+ export type DocumentContext = {
16
+ /**
17
+ * - Resolved settings.
18
+ */
19
+ settings: import("./settings.mjs").Settings;
20
+ /**
21
+ * - `tool_use` inputs by id, to recover file paths.
22
+ */
23
+ toolInputs: Map<string, any>;
24
+ /**
25
+ * - Id of the tool call whose result contains the document, if any.
26
+ */
27
+ toolUseId: string | null;
28
+ };
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[]>;
@@ -0,0 +1,144 @@
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
+ /**
69
+ * Anthropic error type for an HTTP status.
70
+ * @param {number} status - HTTP status code.
71
+ * @returns {string} Anthropic error type.
72
+ */
73
+ export declare function statusToAnthropicType(status: number): string;
74
+ /**
75
+ * HTTP status for an Anthropic error type.
76
+ * @param {string} type - Anthropic error type.
77
+ * @returns {number} HTTP status code.
78
+ */
79
+ export declare function anthropicTypeToStatus(type: string): number;
80
+ /**
81
+ * OpenAI style error type for an Anthropic error type.
82
+ * @param {string} type - Anthropic error type.
83
+ * @returns {string} OpenAI error type.
84
+ */
85
+ export declare function anthropicToOpenAIType(type: string): string;
86
+ /**
87
+ * Anthropic error type for an OpenAI style error object (type and/or numeric code and/or HTTP status).
88
+ * @param {{ type?: string|null, code?: string|number|null }} error - OpenAI error object.
89
+ * @param {number} [status] - HTTP status of the reply, when known.
90
+ * @returns {string} Anthropic error type.
91
+ */
92
+ export declare function openaiToAnthropicType(error: {
93
+ type?: string | null;
94
+ code?: string | number | null;
95
+ }, status?: number): string;
96
+ /**
97
+ * Build an Anthropic error body.
98
+ * @param {string} type - Anthropic error type.
99
+ * @param {string} message - Error message.
100
+ * @returns {{ type: "error", error: { type: string, message: string } }} Anthropic error body.
101
+ */
102
+ export declare function anthropicError(type: string, message: string): {
103
+ type: "error";
104
+ error: {
105
+ type: string;
106
+ message: string;
107
+ };
108
+ };
109
+ /**
110
+ * Build an OpenAI error body.
111
+ * @param {string} message - Error message.
112
+ * @param {{ type?: string, param?: string|null, code?: string|number|null }} [fields] - Optional fields.
113
+ * @returns {{ error: { message: string, type: string, param: string|null, code: string|number|null } }} OpenAI error body.
114
+ */
115
+ export declare function openaiError(message: string, { type, param, code }?: {
116
+ type?: string;
117
+ param?: string | null;
118
+ code?: string | number | null;
119
+ }): {
120
+ error: {
121
+ message: string;
122
+ type: string;
123
+ param: string | null;
124
+ code: string | number | null;
125
+ };
126
+ };
127
+ /**
128
+ * Detect an OpenAI/vLLM "context length exceeded" message and rewrite it in Anthropic's wording
129
+ * (`prompt is too long: <n> tokens > <max> maximum`), which Claude Code recognises and answers with
130
+ * auto-compaction. `n` is the total the request asked for (prompt plus requested completion) when the message
131
+ * reports it, otherwise the prompt size, and `max + 1` when the message gives no size, so `n` always exceeds the maximum.
132
+ * @param {string} message - Upstream error message.
133
+ * @returns {string|null} Rewritten message, or null when the message is not a context overflow.
134
+ */
135
+ export declare function rewriteContextOverflow(message: string): string | null;
136
+ /**
137
+ * Token counts from a context-overflow message.
138
+ * @param {string} message - Upstream error message.
139
+ * @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
+ */
141
+ export declare function contextOverflow(message: string): {
142
+ prompt: number;
143
+ max: number;
144
+ } | null;
@@ -0,0 +1,24 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/lib/estimate.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
+ * @fileoverview Prompt size estimate for upstreams that cannot count tokens.
17
+ * @module @cldmv/llm-translator/lib/estimate
18
+ */
19
+ /**
20
+ * Rough prompt size: one token per four characters of the serialized system prompt, messages and tools.
21
+ * @param {any} body - Upstream request body.
22
+ * @returns {number} Estimated tokens.
23
+ */
24
+ export declare function estimate(body: any): number;