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