@cldmv/llm-translator 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +185 -2
  3. package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +17 -0
  4. package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +2 -0
  5. package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +2 -0
  6. package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +6 -0
  7. package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +2 -0
  8. package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +2 -0
  9. package/dist/api/detect.mjs +2 -0
  10. package/dist/api/driver/anthropic/detect.mjs +2 -0
  11. package/dist/api/driver/anthropic/info.mjs +2 -0
  12. package/dist/api/driver/anthropic/model/list.mjs +2 -0
  13. package/dist/api/driver/anthropic/settings.mjs +2 -0
  14. package/dist/api/driver/anthropic/token/count.mjs +2 -0
  15. package/dist/api/driver/compatible/detect.mjs +2 -0
  16. package/dist/api/driver/compatible/info.mjs +2 -0
  17. package/dist/api/driver/compatible/model/list.mjs +2 -0
  18. package/dist/api/driver/compatible/request.mjs +2 -0
  19. package/dist/api/driver/compatible/settings.mjs +2 -0
  20. package/dist/api/driver/openai/detect.mjs +2 -0
  21. package/dist/api/driver/openai/info.mjs +2 -0
  22. package/dist/api/driver/openai/model/list.mjs +2 -0
  23. package/dist/api/driver/openai/request.mjs +2 -0
  24. package/dist/api/driver/openai/settings.mjs +2 -0
  25. package/dist/api/driver/vllm/detect.mjs +2 -0
  26. package/dist/api/driver/vllm/error.mjs +2 -0
  27. package/dist/api/driver/vllm/info.mjs +2 -0
  28. package/dist/api/driver/vllm/model/list.mjs +2 -0
  29. package/dist/api/driver/vllm/probe.mjs +2 -0
  30. package/dist/api/driver/vllm/request.mjs +2 -0
  31. package/dist/api/driver/vllm/settings.mjs +2 -0
  32. package/dist/api/driver/vllm/token/count.mjs +2 -0
  33. package/dist/api/error/build.mjs +2 -0
  34. package/dist/api/error/error.mjs +2 -0
  35. package/dist/api/model/list.mjs +2 -0
  36. package/dist/api/request.mjs +3 -0
  37. package/dist/api/response.mjs +2 -0
  38. package/dist/api/send.mjs +2 -0
  39. package/dist/api/server/plugin.mjs +2 -0
  40. package/dist/api/server/start.mjs +2 -0
  41. package/dist/api/server/stop.mjs +2 -0
  42. package/dist/api/sse/encode.mjs +4 -0
  43. package/dist/api/sse/parse.mjs +2 -0
  44. package/dist/api/sse/ping.mjs +2 -0
  45. package/dist/api/sse/write.mjs +2 -0
  46. package/dist/api/status.mjs +2 -0
  47. package/dist/api/stream.mjs +2 -0
  48. package/dist/api/token/count.mjs +2 -0
  49. package/dist/bin/llm-translator.mjs +3 -0
  50. package/dist/index.cjs +44 -0
  51. package/dist/index.mjs +2 -0
  52. package/dist/lib/arguments.mjs +2 -0
  53. package/dist/lib/capture.mjs +2 -0
  54. package/dist/lib/cli.mjs +29 -0
  55. package/dist/lib/config.mjs +2 -0
  56. package/dist/lib/documents.mjs +12 -0
  57. package/dist/lib/errors.mjs +2 -0
  58. package/dist/lib/estimate.mjs +2 -0
  59. package/dist/lib/finish.mjs +2 -0
  60. package/dist/lib/http.mjs +2 -0
  61. package/dist/lib/ids.mjs +2 -0
  62. package/dist/lib/images.mjs +2 -0
  63. package/dist/lib/models.mjs +2 -0
  64. package/dist/lib/normalize.mjs +2 -0
  65. package/dist/lib/passthrough.mjs +2 -0
  66. package/dist/lib/pdf.mjs +2 -0
  67. package/dist/lib/ping.mjs +2 -0
  68. package/dist/lib/route.mjs +2 -0
  69. package/dist/lib/routes.mjs +2 -0
  70. package/dist/lib/runtime.mjs +2 -0
  71. package/dist/lib/schema.mjs +2 -0
  72. package/dist/lib/settings.mjs +2 -0
  73. package/dist/lib/source.mjs +2 -0
  74. package/dist/lib/sse.mjs +10 -0
  75. package/dist/lib/thinking.mjs +2 -0
  76. package/dist/lib/transport.mjs +2 -0
  77. package/dist/lib/upstream-error.mjs +2 -0
  78. package/dist/lib/warn.mjs +2 -0
  79. package/package.json +127 -5
  80. package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +28 -0
  81. package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +24 -0
  82. package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +29 -0
  83. package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +30 -0
  84. package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +28 -0
  85. package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +38 -0
  86. package/types/src/api/detect.d.mts +21 -0
  87. package/types/src/api/driver/anthropic/detect.d.mts +26 -0
  88. package/types/src/api/driver/anthropic/info.d.mts +30 -0
  89. package/types/src/api/driver/anthropic/model/list.d.mts +20 -0
  90. package/types/src/api/driver/anthropic/settings.d.mts +23 -0
  91. package/types/src/api/driver/anthropic/token/count.d.mts +20 -0
  92. package/types/src/api/driver/compatible/detect.d.mts +23 -0
  93. package/types/src/api/driver/compatible/info.d.mts +29 -0
  94. package/types/src/api/driver/compatible/model/list.d.mts +20 -0
  95. package/types/src/api/driver/compatible/request.d.mts +20 -0
  96. package/types/src/api/driver/compatible/settings.d.mts +23 -0
  97. package/types/src/api/driver/openai/detect.d.mts +26 -0
  98. package/types/src/api/driver/openai/info.d.mts +29 -0
  99. package/types/src/api/driver/openai/model/list.d.mts +20 -0
  100. package/types/src/api/driver/openai/request.d.mts +20 -0
  101. package/types/src/api/driver/openai/settings.d.mts +23 -0
  102. package/types/src/api/driver/vllm/detect.d.mts +20 -0
  103. package/types/src/api/driver/vllm/error.d.mts +28 -0
  104. package/types/src/api/driver/vllm/info.d.mts +29 -0
  105. package/types/src/api/driver/vllm/model/list.d.mts +20 -0
  106. package/types/src/api/driver/vllm/probe.d.mts +39 -0
  107. package/types/src/api/driver/vllm/request.d.mts +22 -0
  108. package/types/src/api/driver/vllm/settings.d.mts +22 -0
  109. package/types/src/api/driver/vllm/token/count.d.mts +20 -0
  110. package/types/src/api/error/build.d.mts +26 -0
  111. package/types/src/api/error/error.d.mts +29 -0
  112. package/types/src/api/model/list.d.mts +21 -0
  113. package/types/src/api/request.d.mts +35 -0
  114. package/types/src/api/response.d.mts +22 -0
  115. package/types/src/api/send.d.mts +32 -0
  116. package/types/src/api/server/plugin.d.mts +24 -0
  117. package/types/src/api/server/start.d.mts +26 -0
  118. package/types/src/api/server/stop.d.mts +19 -0
  119. package/types/src/api/sse/encode.d.mts +26 -0
  120. package/types/src/api/sse/parse.d.mts +24 -0
  121. package/types/src/api/sse/ping.d.mts +30 -0
  122. package/types/src/api/sse/write.d.mts +26 -0
  123. package/types/src/api/status.d.mts +22 -0
  124. package/types/src/api/stream.d.mts +25 -0
  125. package/types/src/api/token/count.d.mts +24 -0
  126. package/types/src/index.d.mts +76 -0
  127. package/types/src/lib/arguments.d.mts +30 -0
  128. package/types/src/lib/capture.d.mts +28 -0
  129. package/types/src/lib/cli.d.mts +49 -0
  130. package/types/src/lib/config.d.mts +65 -0
  131. package/types/src/lib/documents.d.mts +43 -0
  132. package/types/src/lib/errors.d.mts +144 -0
  133. package/types/src/lib/estimate.d.mts +24 -0
  134. package/types/src/lib/finish.d.mts +73 -0
  135. package/types/src/lib/http.d.mts +58 -0
  136. package/types/src/lib/ids.d.mts +55 -0
  137. package/types/src/lib/images.d.mts +39 -0
  138. package/types/src/lib/models.d.mts +25 -0
  139. package/types/src/lib/normalize.d.mts +37 -0
  140. package/types/src/lib/passthrough.d.mts +22 -0
  141. package/types/src/lib/pdf.d.mts +67 -0
  142. package/types/src/lib/ping.d.mts +24 -0
  143. package/types/src/lib/route.d.mts +38 -0
  144. package/types/src/lib/routes.d.mts +22 -0
  145. package/types/src/lib/runtime.d.mts +24 -0
  146. package/types/src/lib/schema.d.mts +22 -0
  147. package/types/src/lib/settings.d.mts +175 -0
  148. package/types/src/lib/source.d.mts +32 -0
  149. package/types/src/lib/sse.d.mts +72 -0
  150. package/types/src/lib/thinking.d.mts +60 -0
  151. package/types/src/lib/transport.d.mts +31 -0
  152. package/types/src/lib/upstream-error.d.mts +57 -0
  153. package/types/src/lib/warn.d.mts +26 -0
@@ -0,0 +1,22 @@
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
+ /**
16
+ * 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
+ * @param {{version?: string}} [facts] - Detection facts (or the configured version).
18
+ * @returns {any} Partial settings.
19
+ */
20
+ export declare function settings(facts?: {
21
+ version?: string;
22
+ }): any;
@@ -0,0 +1,20 @@
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
+ /**
16
+ * Count the prompt tokens of a converted Chat Completions request with the server's own tokenizer and chat template.
17
+ * @param {any} context - `{ endpoint, request, transport, signal, timeout }`.
18
+ * @returns {Promise<number | null>} Token count, or null when the server did not answer (caller falls back to an estimate).
19
+ */
20
+ export declare function count({ endpoint, request, transport, signal, timeout }: any): Promise<number | null>;
@@ -0,0 +1,26 @@
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
+ /**
16
+ * Build `{ status, headers, body }` in the client protocol.
17
+ * @param {number} status - HTTP status.
18
+ * @param {string} message - Error message.
19
+ * @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
+ * @returns {{status: number, headers: Record<string,string>, body: any}} Client-shaped error reply.
21
+ */
22
+ export declare function build(status: number, message: string, options?: any): {
23
+ status: number;
24
+ headers: Record<string, string>;
25
+ body: any;
26
+ };
@@ -0,0 +1,29 @@
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
+ /**
16
+ * Convert an upstream error reply into `{ status, headers, body }` in the client protocol. Context-window overflows
17
+ * 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.
19
+ * @param {number} status - Upstream HTTP status.
20
+ * @param {*} upstreamBody - Parsed upstream error body (object or text).
21
+ * @param {Record<string,string>} [headers] - Lowercase upstream response headers.
22
+ * @param {any} [state] - The `state` returned by `request` (selects the driver normalizer and native handling).
23
+ * @returns {Promise<{status: number, headers: Record<string,string>, body: any}>} Client-shaped error reply.
24
+ */
25
+ export default function error(status: number, upstreamBody: any, headers?: Record<string, string>, state?: any): Promise<{
26
+ status: number;
27
+ headers: Record<string, string>;
28
+ body: any;
29
+ }>;
@@ -0,0 +1,21 @@
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
+ /**
16
+ * List the models the upstreams serve (live when the driver can, else detection/config data), plus the configured aliases,
17
+ * in the client protocol's list shape (Anthropic `{data:[{type:"model",...}]}` or OpenAI `{object:"list",data:[...]}`).
18
+ * @param {any} [options] - `{ signal, front }`.
19
+ * @returns {Promise<any>} Model list.
20
+ */
21
+ export declare function list(options?: any): Promise<any>;
@@ -0,0 +1,35 @@
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
+ /**
16
+ * Route a client request body (in the configured `front` protocol) to an upstream and convert it to that upstream's
17
+ * protocol. Does no I/O.
18
+ * @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.
21
+ */
22
+ export declare function request(body: any, options?: any): Promise<{
23
+ upstream: string;
24
+ method: string;
25
+ url: string;
26
+ path: string;
27
+ headers: Record<string, string>;
28
+ body: any;
29
+ state: any;
30
+ images: {
31
+ sent: boolean;
32
+ retry: boolean;
33
+ key: string;
34
+ };
35
+ }>;
@@ -0,0 +1,22 @@
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
+ /**
16
+ * Convert an upstream response body to the client protocol (a no-op apart from driver normalization and restoring the
17
+ * client's model name when front and upstream speak the same protocol).
18
+ * @param {any} upstreamBody - Parsed upstream JSON body.
19
+ * @param {any} state - The `state` returned by `request`.
20
+ * @returns {Promise<any>} Response body in the client protocol.
21
+ */
22
+ export declare function response(upstreamBody: any, state: any): Promise<any>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/api/send.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
+ * Send a client request to the routed upstream and return the client-protocol reply.
17
+ * @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, and the pass-through body filter (see `request`).
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.
20
+ */
21
+ export declare function send(body: any, options?: any): Promise<{
22
+ status: number;
23
+ headers: Record<string, string>;
24
+ body: any;
25
+ } | {
26
+ status: number;
27
+ headers: Record<string, string>;
28
+ stream: AsyncIterable<{
29
+ event?: string;
30
+ data: any;
31
+ }>;
32
+ }>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
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
18
+ * `text/event-stream` with keep-alive pings; a client disconnect aborts the upstream request. Register it with
19
+ * `app.register(api.server.plugin, { apiKey })`.
20
+ * @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`.
22
+ * @returns {Promise<void>} Resolves once the routes are registered.
23
+ */
24
+ export declare function plugin(fastify: any, options?: any): Promise<void>;
@@ -0,0 +1,26 @@
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
+ /**
16
+ * 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.
18
+ * @returns {Promise<{url: string, host: string, port: number, app: any, close: () => Promise<void>}>} Running server handle.
19
+ */
20
+ export declare function start(options?: any): Promise<{
21
+ url: string;
22
+ host: string;
23
+ port: number;
24
+ app: any;
25
+ close: () => Promise<void>;
26
+ }>;
@@ -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
+ }>;
@@ -0,0 +1,76 @@
1
+ /**
2
+ *
3
+ * @Project: @cldmv/llm-translator
4
+ * @Filename: /src/index.mjs
5
+ * @Date: 2026-10-24T20:20:01-07:00 (1792898401)
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
+ 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
+ };
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;
@@ -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;