@cldmv/llm-translator 0.9.0 → 0.11.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 (131) hide show
  1. package/README.md +8 -7
  2. package/dist/api/convert/anthropic/messages/to/ollama/chat/request.mjs +2 -0
  3. package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +10 -10
  4. package/dist/api/convert/ollama/chat/to/anthropic/messages/response.mjs +2 -0
  5. package/dist/api/convert/ollama/chat/to/anthropic/messages/stream.mjs +2 -0
  6. package/dist/api/convert/ollama/chat/to/openai/chat/response.mjs +2 -0
  7. package/dist/api/convert/ollama/chat/to/openai/chat/stream.mjs +2 -0
  8. package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
  9. package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +1 -1
  10. package/dist/api/convert/openai/chat/to/ollama/chat/request.mjs +2 -0
  11. package/dist/api/detect.mjs +1 -1
  12. package/dist/api/driver/azure/detect.mjs +1 -1
  13. package/dist/api/driver/azure/info.mjs +1 -1
  14. package/dist/api/driver/deepseek/info.mjs +1 -1
  15. package/dist/api/driver/fireworks/detect.mjs +2 -0
  16. package/dist/api/driver/fireworks/info.mjs +2 -0
  17. package/dist/api/driver/fireworks/path.mjs +2 -0
  18. package/dist/api/driver/fireworks/request.mjs +2 -0
  19. package/dist/api/driver/fireworks/settings.mjs +2 -0
  20. package/dist/api/driver/gemini/detect.mjs +2 -0
  21. package/dist/api/driver/gemini/info.mjs +2 -0
  22. package/dist/api/driver/gemini/path.mjs +2 -0
  23. package/dist/api/driver/gemini/request.mjs +2 -0
  24. package/dist/api/driver/gemini/settings.mjs +2 -0
  25. package/dist/api/driver/groq/detect.mjs +2 -0
  26. package/dist/api/driver/groq/info.mjs +2 -0
  27. package/dist/api/driver/groq/path.mjs +2 -0
  28. package/dist/api/driver/groq/request.mjs +2 -0
  29. package/dist/api/driver/groq/settings.mjs +2 -0
  30. package/dist/api/driver/llamacpp/info.mjs +1 -1
  31. package/dist/api/driver/mistral/info.mjs +1 -1
  32. package/dist/api/driver/ollama/info.mjs +1 -1
  33. package/dist/api/driver/ollama/request.mjs +1 -1
  34. package/dist/api/driver/openai/info.mjs +1 -1
  35. package/dist/api/driver/openrouter/info.mjs +1 -1
  36. package/dist/api/driver/together/detect.mjs +2 -0
  37. package/dist/api/driver/together/info.mjs +2 -0
  38. package/dist/api/driver/together/request.mjs +2 -0
  39. package/dist/api/driver/together/settings.mjs +2 -0
  40. package/dist/api/driver/vllm/detect.mjs +1 -1
  41. package/dist/api/driver/vllm/info.mjs +1 -1
  42. package/dist/api/driver/vllm/model/list.mjs +1 -1
  43. package/dist/api/driver/xai/detect.mjs +2 -0
  44. package/dist/api/driver/xai/info.mjs +2 -0
  45. package/dist/api/driver/xai/request.mjs +2 -0
  46. package/dist/api/driver/xai/settings.mjs +2 -0
  47. package/dist/api/embeddings/send.mjs +1 -1
  48. package/dist/api/health/check.mjs +2 -0
  49. package/dist/api/model/list.mjs +1 -1
  50. package/dist/api/request.mjs +2 -2
  51. package/dist/api/response.mjs +1 -1
  52. package/dist/api/send.mjs +1 -1
  53. package/dist/api/status.mjs +1 -1
  54. package/dist/api/stream.mjs +1 -1
  55. package/dist/index.mjs +1 -1
  56. package/dist/lib/cache.mjs +2 -0
  57. package/dist/lib/capture.mjs +1 -1
  58. package/dist/lib/config.mjs +1 -1
  59. package/dist/lib/constraint.mjs +2 -0
  60. package/dist/lib/context.mjs +2 -0
  61. package/dist/lib/health.mjs +2 -0
  62. package/dist/lib/http.mjs +1 -1
  63. package/dist/lib/models.mjs +1 -1
  64. package/dist/lib/ndjson.mjs +4 -0
  65. package/dist/lib/ollama.mjs +3 -0
  66. package/dist/lib/passthrough.mjs +1 -1
  67. package/dist/lib/pool.mjs +1 -1
  68. package/dist/lib/presets.mjs +2 -0
  69. package/dist/lib/route.mjs +1 -1
  70. package/dist/lib/routes.mjs +1 -1
  71. package/dist/lib/settings.mjs +1 -1
  72. package/dist/lib/vllm.mjs +4 -0
  73. package/package.json +1 -1
  74. package/types/src/api/convert/anthropic/messages/to/ollama/chat/request.d.mts +14 -0
  75. package/types/src/api/convert/ollama/chat/to/anthropic/messages/response.d.mts +10 -0
  76. package/types/src/api/convert/ollama/chat/to/anthropic/messages/stream.d.mts +14 -0
  77. package/types/src/api/convert/ollama/chat/to/openai/chat/response.d.mts +10 -0
  78. package/types/src/api/convert/ollama/chat/to/openai/chat/stream.d.mts +13 -0
  79. package/types/src/api/convert/openai/chat/to/ollama/chat/request.d.mts +12 -0
  80. package/types/src/api/detect.d.mts +1 -1
  81. package/types/src/api/driver/azure/info.d.mts +2 -1
  82. package/types/src/api/driver/deepseek/info.d.mts +2 -1
  83. package/types/src/api/driver/fireworks/detect.d.mts +8 -0
  84. package/types/src/api/driver/fireworks/info.d.mts +13 -0
  85. package/types/src/api/driver/fireworks/path.d.mts +7 -0
  86. package/types/src/api/driver/fireworks/request.d.mts +7 -0
  87. package/types/src/api/driver/fireworks/settings.d.mts +5 -0
  88. package/types/src/api/driver/gemini/detect.d.mts +8 -0
  89. package/types/src/api/driver/gemini/info.d.mts +13 -0
  90. package/types/src/api/driver/gemini/path.d.mts +7 -0
  91. package/types/src/api/driver/gemini/request.d.mts +7 -0
  92. package/types/src/api/driver/gemini/settings.d.mts +5 -0
  93. package/types/src/api/driver/groq/detect.d.mts +8 -0
  94. package/types/src/api/driver/groq/info.d.mts +13 -0
  95. package/types/src/api/driver/groq/path.d.mts +7 -0
  96. package/types/src/api/driver/groq/request.d.mts +7 -0
  97. package/types/src/api/driver/groq/settings.d.mts +5 -0
  98. package/types/src/api/driver/mistral/info.d.mts +2 -1
  99. package/types/src/api/driver/ollama/info.d.mts +7 -2
  100. package/types/src/api/driver/openai/info.d.mts +3 -1
  101. package/types/src/api/driver/openrouter/info.d.mts +2 -1
  102. package/types/src/api/driver/together/detect.d.mts +8 -0
  103. package/types/src/api/driver/together/info.d.mts +13 -0
  104. package/types/src/api/driver/together/request.d.mts +7 -0
  105. package/types/src/api/driver/together/settings.d.mts +5 -0
  106. package/types/src/api/driver/vllm/detect.d.mts +1 -1
  107. package/types/src/api/driver/vllm/info.d.mts +1 -1
  108. package/types/src/api/driver/vllm/model/list.d.mts +3 -1
  109. package/types/src/api/driver/xai/detect.d.mts +8 -0
  110. package/types/src/api/driver/xai/info.d.mts +13 -0
  111. package/types/src/api/driver/xai/request.d.mts +7 -0
  112. package/types/src/api/driver/xai/settings.d.mts +5 -0
  113. package/types/src/api/endpoint/status.d.mts +5 -2
  114. package/types/src/api/health/check.d.mts +8 -0
  115. package/types/src/api/request.d.mts +1 -1
  116. package/types/src/api/send.d.mts +1 -1
  117. package/types/src/api/status.d.mts +1 -1
  118. package/types/src/lib/cache.d.mts +30 -0
  119. package/types/src/lib/config.d.mts +4 -0
  120. package/types/src/lib/constraint.d.mts +36 -0
  121. package/types/src/lib/context.d.mts +34 -0
  122. package/types/src/lib/events.d.mts +2 -2
  123. package/types/src/lib/health.d.mts +22 -0
  124. package/types/src/lib/models.d.mts +25 -0
  125. package/types/src/lib/ndjson.d.mts +16 -0
  126. package/types/src/lib/ollama.d.mts +86 -0
  127. package/types/src/lib/pool.d.mts +30 -4
  128. package/types/src/lib/presets.d.mts +99 -0
  129. package/types/src/lib/route.d.mts +1 -1
  130. package/types/src/lib/settings.d.mts +25 -0
  131. package/types/src/lib/vllm.d.mts +47 -0
@@ -18,7 +18,7 @@
18
18
  */
19
19
  /**
20
20
  * Describe the DeepSeek driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
@@ -26,5 +26,6 @@ export function info(): {
26
26
  order: number;
27
27
  auth: string;
28
28
  strict: boolean;
29
+ hosts: string[];
29
30
  paths: Record<string, string>;
30
31
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Match by host name, no network access.
3
+ * @param {any} context - `{ endpoint }`.
4
+ * @returns {{host: string} | null} Facts, or null when the endpoint is not Fireworks AI's.
5
+ */
6
+ export function detect({ endpoint }: any): {
7
+ host: string;
8
+ } | null;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describe the Fireworks AI driver (see `PRESETS.fireworks` in `lib/presets.mjs`).
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
4
+ */
5
+ export function info(): {
6
+ name: string;
7
+ protocol: string;
8
+ order: number;
9
+ auth: string;
10
+ strict: boolean;
11
+ fields?: string[];
12
+ paths: Record<string, string>;
13
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Put the calls under the provider's path root, unless the upstream URL already ends in it.
3
+ * @param {"chat" | "embeddings" | "models"} kind - Which call.
4
+ * @param {any} context - `{ endpoint }`.
5
+ * @returns {string} Path starting with `/`.
6
+ */
7
+ export function path(kind: "chat" | "embeddings" | "models", { endpoint }: any): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Drop tool fields when there are no tools, and the fields Fireworks AI rejects (each recorded in `state.dropped`).
3
+ * @param {any} body - Chat Completions request body.
4
+ * @param {any} [context] - `{ state }`.
5
+ * @returns {any} Normalized body.
6
+ */
7
+ export function request(body: any, context?: any): any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Settings for Fireworks AI: token field, reasoning field and controls, sampling fields and streaming usage as the provider documents them (see `PRESETS.fireworks` in `lib/presets.mjs`).
3
+ * @returns {any} Partial settings.
4
+ */
5
+ export function settings(): any;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Match by host name, no network access.
3
+ * @param {any} context - `{ endpoint }`.
4
+ * @returns {{host: string} | null} Facts, or null when the endpoint is not Gemini (OpenAI-compatible endpoint)'s.
5
+ */
6
+ export function detect({ endpoint }: any): {
7
+ host: string;
8
+ } | null;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describe the Gemini (OpenAI-compatible endpoint) driver (see `PRESETS.gemini` in `lib/presets.mjs`).
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
4
+ */
5
+ export function info(): {
6
+ name: string;
7
+ protocol: string;
8
+ order: number;
9
+ auth: string;
10
+ strict: boolean;
11
+ fields?: string[];
12
+ paths: Record<string, string>;
13
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Put the calls under the provider's path root, unless the upstream URL already ends in it.
3
+ * @param {"chat" | "embeddings" | "models"} kind - Which call.
4
+ * @param {any} context - `{ endpoint }`.
5
+ * @returns {string} Path starting with `/`.
6
+ */
7
+ export function path(kind: "chat" | "embeddings" | "models", { endpoint }: any): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Drop tool fields when there are no tools, and the fields Gemini (OpenAI-compatible endpoint) rejects (each recorded in `state.dropped`).
3
+ * @param {any} body - Chat Completions request body.
4
+ * @param {any} [context] - `{ state }`.
5
+ * @returns {any} Normalized body.
6
+ */
7
+ export function request(body: any, context?: any): any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Settings for Gemini (OpenAI-compatible endpoint): token field, reasoning field and controls, sampling fields and streaming usage as the provider documents them (see `PRESETS.gemini` in `lib/presets.mjs`).
3
+ * @returns {any} Partial settings.
4
+ */
5
+ export function settings(): any;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Match by host name, no network access.
3
+ * @param {any} context - `{ endpoint }`.
4
+ * @returns {{host: string} | null} Facts, or null when the endpoint is not Groq's.
5
+ */
6
+ export function detect({ endpoint }: any): {
7
+ host: string;
8
+ } | null;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describe the Groq driver (see `PRESETS.groq` in `lib/presets.mjs`).
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
4
+ */
5
+ export function info(): {
6
+ name: string;
7
+ protocol: string;
8
+ order: number;
9
+ auth: string;
10
+ strict: boolean;
11
+ fields?: string[];
12
+ paths: Record<string, string>;
13
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Put the calls under the provider's path root, unless the upstream URL already ends in it.
3
+ * @param {"chat" | "embeddings" | "models"} kind - Which call.
4
+ * @param {any} context - `{ endpoint }`.
5
+ * @returns {string} Path starting with `/`.
6
+ */
7
+ export function path(kind: "chat" | "embeddings" | "models", { endpoint }: any): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Drop tool fields when there are no tools, and the fields Groq rejects (each recorded in `state.dropped`).
3
+ * @param {any} body - Chat Completions request body.
4
+ * @param {any} [context] - `{ state }`.
5
+ * @returns {any} Normalized body.
6
+ */
7
+ export function request(body: any, context?: any): any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Settings for Groq: token field, reasoning field and controls, sampling fields and streaming usage as the provider documents them (see `PRESETS.groq` in `lib/presets.mjs`).
3
+ * @returns {any} Partial settings.
4
+ */
5
+ export function settings(): any;
@@ -18,7 +18,7 @@
18
18
  */
19
19
  /**
20
20
  * Describe the Mistral driver. Mistral accepts only 9-character alphanumeric tool-call ids, so the translator rewrites the client's ids.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, toolCallIds: {alphabet: string, min: number, max: number}, paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], toolCallIds: {alphabet: string, min: number, max: number}, paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
@@ -26,6 +26,7 @@ export function info(): {
26
26
  order: number;
27
27
  auth: string;
28
28
  strict: boolean;
29
+ hosts: string[];
29
30
  toolCallIds: {
30
31
  alphabet: string;
31
32
  min: number;
@@ -17,8 +17,9 @@
17
17
  * @module @cldmv/llm-translator/driver/ollama
18
18
  */
19
19
  /**
20
- * Describe the Ollama driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], paths: Record<string,string>}} Driver facts.
20
+ * Describe the Ollama driver. `protocol` is the OpenAI-compatible `/v1` API; `native` is the mode an upstream selects with `api: "native"`, Ollama's own
21
+ * `/api/chat` (the `ollama.chat` protocol; the model list and embeddings stay on `/v1`).
22
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, probes: string[], paths: Record<string,string>, native: {protocol: string, paths: Record<string,string>}}} Driver facts.
22
23
  */
23
24
  export function info(): {
24
25
  name: string;
@@ -28,4 +29,8 @@ export function info(): {
28
29
  strict: boolean;
29
30
  probes: string[];
30
31
  paths: Record<string, string>;
32
+ native: {
33
+ protocol: string;
34
+ paths: Record<string, string>;
35
+ };
31
36
  };
@@ -18,7 +18,7 @@
18
18
  */
19
19
  /**
20
20
  * Describe the OpenAI driver.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], fields: string[], paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
@@ -26,5 +26,7 @@ export function info(): {
26
26
  order: number;
27
27
  auth: string;
28
28
  strict: boolean;
29
+ hosts: string[];
30
+ fields: string[];
29
31
  paths: Record<string, string>;
30
32
  };
@@ -18,7 +18,7 @@
18
18
  */
19
19
  /**
20
20
  * Describe the OpenRouter driver. The API lives under `/api`; the `path` leaf adds it, so `paths` holds the usual `/v1/...` ones.
21
- * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, paths: Record<string,string>}} Driver facts.
21
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], paths: Record<string,string>}} Driver facts.
22
22
  */
23
23
  export function info(): {
24
24
  name: string;
@@ -26,5 +26,6 @@ export function info(): {
26
26
  order: number;
27
27
  auth: string;
28
28
  strict: boolean;
29
+ hosts: string[];
29
30
  paths: Record<string, string>;
30
31
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Match by host name, no network access.
3
+ * @param {any} context - `{ endpoint }`.
4
+ * @returns {{host: string} | null} Facts, or null when the endpoint is not Together AI's.
5
+ */
6
+ export function detect({ endpoint }: any): {
7
+ host: string;
8
+ } | null;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describe the Together AI driver (see `PRESETS.together` in `lib/presets.mjs`).
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
4
+ */
5
+ export function info(): {
6
+ name: string;
7
+ protocol: string;
8
+ order: number;
9
+ auth: string;
10
+ strict: boolean;
11
+ fields?: string[];
12
+ paths: Record<string, string>;
13
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Drop tool fields when there are no tools, and the fields Together AI rejects (each recorded in `state.dropped`).
3
+ * @param {any} body - Chat Completions request body.
4
+ * @param {any} [context] - `{ state }`.
5
+ * @returns {any} Normalized body.
6
+ */
7
+ export function request(body: any, context?: any): any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Settings for Together AI: token field, reasoning field and controls, sampling fields and streaming usage as the provider documents them (see `PRESETS.together` in `lib/presets.mjs`).
3
+ * @returns {any} Partial settings.
4
+ */
5
+ export function settings(): any;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Probe an endpoint for vLLM.
3
3
  * @param {any} context - `{ endpoint, transport, signal, timeout, probes }`.
4
- * @returns {Promise<any | null>} Facts `{ version, models, maxModelLen }`, or null when the endpoint is not vLLM (or is LocalAI, SGLang, llama.cpp or TGI, which can also answer `/version`).
4
+ * @returns {Promise<any | null>} Facts `{ version, models, adapters, maxModelLen }` (`models` lists the base models and the LoRA adapters, `adapters` the adapters alone as `{ id, parent }`, taken from the entries whose `parent` names the base model), or null when the endpoint is not vLLM (or is LocalAI, SGLang, llama.cpp or TGI, which can also answer `/version`).
5
5
  */
6
6
  export function detect({ endpoint, transport, signal, timeout, probes }: any): Promise<any | null>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Describe the vLLM driver.
2
+ * Describe the vLLM driver. `paths.health` (`GET /health`: 200 when the engine is up, 503 once it is dead; outside the API-key guard) is what `lib/health` probes before routing a request to a pool.
3
3
  * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields: string[], paths: Record<string,string>}} Driver facts.
4
4
  */
5
5
  export function info(): {
@@ -1,5 +1,7 @@
1
1
  /**
2
- * List the models the vLLM server serves (including `max_model_len`).
2
+ * List the models the vLLM server serves (including `max_model_len`, and `parent` on a LoRA adapter). What the server answers is also what the
3
+ * upstream serves from now on: adapters loaded at runtime (`/v1/load_lora_adapter`) become routable, and unloaded ones stop being. An upstream
4
+ * with a configured `models` list keeps that list.
3
5
  * @param {any} context - `{ endpoint, transport, signal, timeout }`.
4
6
  * @returns {Promise<any[] | null>} Models, or null when unreachable.
5
7
  */
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Match by host name, no network access.
3
+ * @param {any} context - `{ endpoint }`.
4
+ * @returns {{host: string} | null} Facts, or null when the endpoint is not xAI's.
5
+ */
6
+ export function detect({ endpoint }: any): {
7
+ host: string;
8
+ } | null;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describe the xAI driver (see `PRESETS.xai` in `lib/presets.mjs`).
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
4
+ */
5
+ export function info(): {
6
+ name: string;
7
+ protocol: string;
8
+ order: number;
9
+ auth: string;
10
+ strict: boolean;
11
+ fields?: string[];
12
+ paths: Record<string, string>;
13
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Drop tool fields when there are no tools, and the fields xAI rejects (each recorded in `state.dropped`).
3
+ * @param {any} body - Chat Completions request body.
4
+ * @param {any} [context] - `{ state }`.
5
+ * @returns {any} Normalized body.
6
+ */
7
+ export function request(body: any, context?: any): any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Settings for xAI: token field, reasoning field and controls, sampling fields and streaming usage as the provider documents them (see `PRESETS.xai` in `lib/presets.mjs`).
3
+ * @returns {any} Partial settings.
4
+ */
5
+ export function settings(): any;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Health of every endpoint, for status output. An endpoint is unhealthy while it is backing off after a connection error or a 5xx; it is still
2
+ * Health of every endpoint, for status output. An endpoint is unhealthy while it is backing off after a connection error or a 5xx, or while its last readiness probe (`GET /health` for vLLM, see `health.check`) said it is not ready; it is still
3
3
  * tried when nothing healthy serves the model. Secrets are never included.
4
- * @returns {{strategy: string, backoff: {base: number, max: number}, models: Record<string, string>, endpoints: {name: string, url: string, models: string[], healthy: boolean, failures: number, retryAt: string | null, inflight: number, requests: number, errors: number, lastError: string | null, lastFailure: string | null, lastSuccess: string | null}[]}} The pool config and one record per endpoint (`inflight` counts requests whose reply has not finished, `requests` and `errors` count attempts since start).
4
+ * @returns {{strategy: string, backoff: {base: number, max: number}, models: Record<string, string>, endpoints: {name: string, url: string, models: string[], healthy: boolean, ready: boolean | null, readyReason: string | null, checkedAt: string | null, failures: number, retryAt: string | null, inflight: number, requests: number, errors: number, lastError: string | null, lastFailure: string | null, lastSuccess: string | null}[]}} The pool config and one record per endpoint (`inflight` counts requests whose reply has not finished, `requests` and `errors` count attempts since start).
5
5
  */
6
6
  export function status(): {
7
7
  strategy: string;
@@ -15,6 +15,9 @@ export function status(): {
15
15
  url: string;
16
16
  models: string[];
17
17
  healthy: boolean;
18
+ ready: boolean | null;
19
+ readyReason: string | null;
20
+ checkedAt: string | null;
18
21
  failures: number;
19
22
  retryAt: string | null;
20
23
  inflight: number;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Probe every upstream whose driver names a health path (vLLM: `GET /health`) right away, whatever `pool.healthInterval` says, and return the
3
+ * pool status. `send` already does this before it routes a request to a model that has more than one endpoint; call this to refresh the
4
+ * `ready` field of `endpoint.status()` and `status()` for a lone upstream, or on a schedule of your own.
5
+ * @param {any} [options] - `{ signal }`.
6
+ * @returns {Promise<any>} The `endpoint.status()` result.
7
+ */
8
+ export function check(options?: any): Promise<any>;
@@ -2,7 +2,7 @@
2
2
  * Route a client request body (in the configured `front` protocol) to an upstream and convert it to that upstream's
3
3
  * protocol. Does no I/O.
4
4
  * @param {any} body - Client request body (Anthropic Messages or OpenAI Chat Completions, per `front`).
5
- * @param {any} [options] - `{ front, headers, clientHeaders, filter, images, usage }`. `front` overrides the configured front for this call, `headers` are extra upstream headers, `clientHeaders` are client headers forwarded only to a native Anthropic upstream, `filter` restricts a forwarded OpenAI body to known fields (default: the `passthroughFilter` setting, off), `images: false` sends the request without images (used by the image fallback), `endpoint` sends to that member of the model's pool (used for failover; default: the first in the pool's order), `hold: true` (used by `send`) advances a round robin and takes the chosen endpoint's in-flight slot, which the caller then releases, `jsonObject: "instruction"` sends a `json_object` response format as a system instruction (used by the JSON fallback, and applied by itself once a refusal is remembered for the endpoint and model), `tools: false` sends the request without tools (used by the tool fallback), `usage: true` (used by `send`) makes a streaming OpenAI-front request always ask the upstream for its final usage chunk, `retry: true` (used by `send` for the same request sent again) keeps the `dropped` event from repeating, `log` is the logger events of this request also go to (used by the server), `budget` (from `createBudget`, one per `send` for all its attempts) limits the cost of decoding reasoning signatures.
5
+ * @param {any} [options] - `{ front, headers, clientHeaders, filter, images, usage }`. `front` overrides the configured front for this call, `headers` are extra upstream headers, `clientHeaders` are client headers forwarded only to a native Anthropic upstream, `filter` restricts a forwarded OpenAI body to known fields (default: the `passthroughFilter` setting, off), `images: false` sends the request without images (used by the image fallback), `endpoint` sends to that member of the model's pool (used for failover; default: the first in the pool's order), `hold: true` (used by `send`) advances a round robin and takes the chosen endpoint's in-flight slot, which the caller then releases, `jsonObject: "instruction"` sends a `json_object` response format as a system instruction (used by the JSON fallback, and applied by itself once a refusal is remembered for the endpoint and model), `tools: false` sends the request without tools (used by the tool fallback), `usage: true` (used by `send`) makes a streaming OpenAI-front request always ask the upstream for its final usage chunk, `cacheSalt` (a trusted per-call vLLM `cache_salt`, which replaces the upstream's `cacheSalt` setting), `retry: true` (used by `send` for the same request sent again) keeps the `dropped` event from repeating, `log` is the logger events of this request also go to (used by the server), `budget` (from `createBudget`, one per `send` for all its attempts) limits the cost of decoding reasoning signatures.
6
6
  * @returns {Promise<{upstream: string, method: string, url: string, path: string, headers: Record<string,string>, body: any, state: any, pool: string[], images: {sent: boolean, retry: boolean, key: string}, tools: {sent: boolean, retry: boolean}, json: {sent: boolean, retry: boolean, key: string}}>} The upstream request and the state `response`/`stream`/`error` need. `pool` lists the names of the endpoints serving the model in the order they are tried (`upstream` is the first); `images` tells `send` whether the body carries images, whether a refusal may be retried without them and the key under which a refusal is remembered; `tools` tells it whether the body carries tools and whether a tool-parser refusal may be retried without them; `json` tells it whether the body carries the schema emulation of `json_object`, whether a refusal may be retried with the instruction and the key under which a refusal is remembered.
7
7
  */
8
8
  export function request(body: any, options?: any): Promise<{
@@ -25,7 +25,7 @@
25
25
  * a stream has started, an error chunk and `[DONE]`. Aborting the caller's signal aborts every branch. An OpenAI-protocol upstream
26
26
  * receives `n` unchanged and answers it itself.
27
27
  * @param {any} body - Client request body (per `front`).
28
- * @param {any} [options] - `{ signal, front, headers, clientHeaders, filter, onUsage, log }`: abort signal for the upstream call, per-call front, extra upstream headers, client headers forwarded to a native Anthropic upstream, the pass-through body filter (see `request`) and the usage callback (an exception in it is reported as a `usage` event and never breaks the reply) and the logger this request's events also go to (used by the server).
28
+ * @param {any} [options] - `{ signal, front, headers, clientHeaders, filter, cacheSalt, onUsage, log }`: abort signal for the upstream call, per-call front, extra upstream headers, client headers forwarded to a native Anthropic upstream, the pass-through body filter (see `request`) and the usage callback (an exception in it is reported as a `usage` event and never breaks the reply) and the logger this request's events also go to (used by the server).
29
29
  * @returns {Promise<{status: number, headers: Record<string,string>, body: any, usage: Promise<any>} | {status: number, headers: Record<string,string>, stream: AsyncIterable<{event?: string, data: *}>, usage: Promise<any>}>} A JSON reply, or a stream reply when the client asked for streaming and the upstream accepted.
30
30
  */
31
31
  export function send(body: any, options?: any): Promise<{
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Describe the translator's upstreams. Secrets (API keys, headers) are never included.
3
- * @returns {{front: string, upstreams: any[]}} Front protocol and per-upstream detection results and health (see `endpoint.status`).
3
+ * @returns {{front: string, upstreams: any[]}} Front protocol and per-upstream detection results and health (see `endpoint.status`). `messages` is true while an Anthropic-front request to a vLLM upstream goes to its native `/v1/messages` (the `nativeMessages` setting; a request it cannot take is still converted), false when it is converted, and null for any other driver.
4
4
  */
5
5
  export function status(): {
6
6
  front: string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Is a salt or key value usable?
3
+ * @param {any} value - Setting or request value.
4
+ * @returns {boolean} True for a non-empty string, or an absent value.
5
+ */
6
+ export function valid(value: any): boolean;
7
+ /**
8
+ * Add the cache hints to an OpenAI-protocol body.
9
+ *
10
+ * - `cache_salt` comes only from trusted places: the `cacheSalt` call option (the server passes the `authorize` hook's `cacheSalt`) or the upstream's `cacheSalt` setting,
11
+ * in that order. It always replaces a `cache_salt` the body carries, so a client cannot choose its own tenant. A backend without the feature
12
+ * follows `unknownFields`: dropped (listed in `dropped`) or rejected.
13
+ * - `prompt_cache_key` comes from the client (`metadata.prompt_cache_key` on the Anthropic front; the OpenAI front's own field is kept) or the upstream's `promptCacheKey` setting. A
14
+ * key the body already carries wins over the setting.
15
+ * @param {any} body - Converted or forwarded Chat Completions body.
16
+ * @param {{ salt?: any, key?: any }} asked - The call's `cacheSalt` option and the request's prompt cache key.
17
+ * @param {any} settings - Resolved settings (`cacheSalt`, `promptCacheKey`, `unknownFields`).
18
+ * @param {string} driver - Driver name of the upstream.
19
+ * @param {string[]} [dropped] - Receives the names that were left out.
20
+ * @returns {any} The body, with the fields added (a copy when anything was added).
21
+ * @throws {TranslatorError} `invalid_request` for a malformed salt or key; `unsupported_field` when the backend lacks the feature and `unknownFields` is `"error"`.
22
+ */
23
+ export function addCache(body: any, asked: {
24
+ salt?: any;
25
+ key?: any;
26
+ }, settings: any, driver: string, dropped?: string[]): any;
27
+ /** Drivers whose servers take `cache_salt` (vLLM's per-tenant prefix-cache isolation). */
28
+ export const SALT_DRIVERS: string[];
29
+ /** Drivers whose servers take `prompt_cache_key` (OpenAI's cache routing hint). */
30
+ export const KEY_DRIVERS: string[];
@@ -36,6 +36,10 @@ export type UpstreamConfig = {
36
36
  * Azure OpenAI deployment name for the classic URLs. Defaults to the request's model.
37
37
  */
38
38
  deployment?: string;
39
+ /**
40
+ * Which API of the server to use: `"openai"` (default) is the OpenAI-compatible one, `"native"` the server's own chat API, for a driver that has one (Ollama's `/api/chat`).
41
+ */
42
+ api?: "openai" | "native";
39
43
  /**
40
44
  * Driver name, or `"auto"` (default) to detect.
41
45
  */
@@ -0,0 +1,36 @@
1
+ /**
2
+ * What is wrong with a constraint value, if anything.
3
+ * @param {any} value - A `constraint` setting or request value.
4
+ * @returns {string | null} A message, or null when the value is a valid constraint (or absent).
5
+ */
6
+ export function check(value: any): string | null;
7
+ /**
8
+ * The fields to add to a Chat Completions body for one constraint, or null when the backend cannot enforce that kind.
9
+ * @param {string} driver - Driver name.
10
+ * @param {string | undefined} version - Server version (vLLM), when known.
11
+ * @param {string} kind - One of {@link KINDS}.
12
+ * @param {any} value - The constraint's value.
13
+ * @returns {Record<string, any> | null} Body fields, or null when unsupported.
14
+ */
15
+ export function fields(driver: string, version: string | undefined, kind: string, value: any): Record<string, any> | null;
16
+ /**
17
+ * Add a constraint to an OpenAI-protocol body in the backend's own fields. The request's constraint (`constraint` on the OpenAI front,
18
+ * `metadata.constraint` on the Anthropic front) replaces the upstream's `constraint` setting. A body that already carries the native field
19
+ * keeps it. vLLM applies a constraint to the whole generation, so with tools on offer the constraint is dropped and recorded (the tools win).
20
+ * A kind the backend cannot enforce follows `unknownFields`: dropped (listed in `dropped`) or rejected.
21
+ * @param {any} body - Converted or forwarded Chat Completions body.
22
+ * @param {any} asked - The request's constraint, if any.
23
+ * @param {any} settings - Resolved settings (`constraint`, `unknownFields`).
24
+ * @param {{ name: string, version?: string }} target - The upstream's driver name and server version.
25
+ * @param {string[]} [dropped] - Receives `constraint` names that were left out.
26
+ * @returns {any} The body, with the fields added (a copy when anything was added).
27
+ * @throws {TranslatorError} `invalid_request` for a malformed request constraint; `unsupported_field` when the backend cannot enforce the kind and `unknownFields` is `"error"`.
28
+ */
29
+ export function addConstraint(body: any, asked: any, settings: any, target: {
30
+ name: string;
31
+ version?: string;
32
+ }, dropped?: string[]): any;
33
+ /** The constraint kinds a client can ask for. */
34
+ export const KINDS: string[];
35
+ /** First vLLM release whose Chat Completions endpoint takes `structured_outputs`; older releases take `guided_json`, `guided_regex`, `guided_choice` and `guided_grammar`. */
36
+ export const STRUCTURED_OUTPUTS_VERSION: "0.11.0";
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Whether an edit's parameters are all usable. Anything else cannot be honoured and the edit is dropped.
3
+ * @param {any} edit - A `clear_tool_uses` edit.
4
+ * @returns {boolean} True when every present parameter has its documented shape.
5
+ */
6
+ export function valid(edit: any): boolean;
7
+ /**
8
+ * Clear the results (and optionally the inputs) of the oldest tool uses of a converted conversation, as Anthropic's
9
+ * `clear_tool_uses_20250919` edit does. Messages are changed in place.
10
+ *
11
+ * Tool uses are counted in conversation order across every assistant turn. The edit applies when the trigger is exceeded (default: more
12
+ * than 100000 estimated input tokens). The most recent `keep` tool uses (default 3, whatever tool they are) are never cleared, nor are
13
+ * uses of a tool named in `exclude_tools`. The rest, oldest first, have their result replaced by a placeholder (and, with
14
+ * `clear_tool_inputs`, their arguments by `{}`). When fewer than `clear_at_least` input tokens would be freed nothing changes. Input
15
+ * tokens are estimated at one per four characters (`lib/estimate`), for the trigger and for the amount cleared.
16
+ * @param {any} edit - A valid `clear_tool_uses` edit (see `valid`).
17
+ * @param {{ messages: any[], tools?: any[] }} body - Converted OpenAI body; its messages are edited.
18
+ * @param {Record<string, string>} toolNames - `fitted -> original` tool names, to match `exclude_tools`.
19
+ * @returns {{ type: string, cleared_tool_uses: number, cleared_input_tokens: number } | null} The applied edit, or null when nothing was cleared.
20
+ */
21
+ export function clearToolUses(edit: any, body: {
22
+ messages: any[];
23
+ tools?: any[];
24
+ }, toolNames: Record<string, string>): {
25
+ type: string;
26
+ cleared_tool_uses: number;
27
+ cleared_input_tokens: number;
28
+ } | null;
29
+ /** Input tokens above which an edit with no `trigger` applies. */
30
+ export const DEFAULT_TRIGGER: 100000;
31
+ /** Recent tool uses an edit with no `keep` leaves alone. */
32
+ export const DEFAULT_KEEP: 3;
33
+ /** What a cleared tool result says. */
34
+ export const PLACEHOLDER: "[Tool result cleared to save context]";
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @typedef {object} TranslatorEvent
3
- * @property {string} type Specific event name (`fallback`, `failover`, `effort`, `dropped`, `detect`, `usage`, `warning`, `error` or `log`).
3
+ * @property {string} type Specific event name (`fallback`, `failover`, `health`, `effort`, `dropped`, `detect`, `usage`, `warning`, `error` or `log`).
4
4
  * @property {string} [kind] Sub-kind within the type (for example `json_object` for a `fallback`).
5
5
  * @property {"debug" | "info" | "warn" | "error"} level Severity.
6
6
  * @property {string} message Human readable text.
@@ -64,7 +64,7 @@ export function emit({ config, state }: {
64
64
  }): TranslatorEvent;
65
65
  export type TranslatorEvent = {
66
66
  /**
67
- * Specific event name (`fallback`, `failover`, `effort`, `dropped`, `detect`, `usage`, `warning`, `error` or `log`).
67
+ * Specific event name (`fallback`, `failover`, `health`, `effort`, `dropped`, `detect`, `usage`, `warning`, `error` or `log`).
68
68
  */
69
69
  type: string;
70
70
  /**
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Probe the endpoints that name a health path and whose last verdict is older than `pool.healthInterval` (all of them with `force`). A request
3
+ * that was answered counts as a verdict too, so an endpoint that is serving is not probed. Probes run in parallel, and requests that arrive
4
+ * while one is running share it.
5
+ * @param {any} c - Captured translator parts (`lib/capture`).
6
+ * @param {any[]} endpoints - Runtime endpoints.
7
+ * @param {{ signal?: AbortSignal, force?: boolean }} [options] - `force` probes regardless of the interval and of an earlier "no such path" answer.
8
+ * @returns {Promise<void>} Resolves when every probe has finished.
9
+ */
10
+ export function probe(c: any, endpoints: any[], options?: {
11
+ signal?: AbortSignal;
12
+ force?: boolean;
13
+ }): Promise<void>;
14
+ /**
15
+ * Refresh the readiness of the endpoints a request could go to, before it is routed. Only a model with more than one endpoint is probed: a
16
+ * lone endpoint is tried whatever it reports, so asking would only add a round trip.
17
+ * @param {any} c - Captured translator parts (`lib/capture`).
18
+ * @param {any} body - Client request body (only its `model` is read; anything that is not an object is left for `request` to reject).
19
+ * @param {AbortSignal | undefined} signal - The caller's abort signal.
20
+ * @returns {Promise<void>} Resolves when the pool's probes have finished.
21
+ */
22
+ export function refresh(c: any, body: any, signal: AbortSignal | undefined): Promise<void>;
@@ -12,6 +12,31 @@ export function modelsOf(result: {
12
12
  owned_by?: string;
13
13
  max_model_len?: number;
14
14
  }[] | null;
15
+ /**
16
+ * The LoRA adapters in a `/v1/models` list: vLLM lists each one as a model whose `parent` is the base model it adapts (`--lora-modules`, or
17
+ * `/v1/load_lora_adapter` when `VLLM_ALLOW_RUNTIME_LORA_UPDATING` is on); base models have no `parent`.
18
+ * @param {any[]} models - Entries of the model list.
19
+ * @returns {{id: string, parent: string}[]} The adapters.
20
+ */
21
+ export function adaptersOf(models: any[]): {
22
+ id: string;
23
+ parent: string;
24
+ }[];
25
+ /**
26
+ * The model ids an endpoint serves that are not LoRA adapters (all of them for a driver that detects none).
27
+ * @param {any} endpoint - Runtime endpoint.
28
+ * @returns {string[]} Configured or detected model ids, adapters left out.
29
+ */
30
+ export function baseModels(endpoint: any): string[];
31
+ /**
32
+ * The entries a model list shows for an endpoint when the server was not asked: its configured or detected ids, an adapter with its `parent`.
33
+ * @param {any} endpoint - Runtime endpoint.
34
+ * @returns {{id: string, parent?: string}[]} Entries.
35
+ */
36
+ export function knownModels(endpoint: any): {
37
+ id: string;
38
+ parent?: string;
39
+ }[];
15
40
  /**
16
41
  * Fetch and normalize the models an upstream reports.
17
42
  * @param {any} context - `{ endpoint, transport, signal, timeout, auth, extraHeaders, path }`. `path` replaces `/v1/models`.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Create an incremental NDJSON parser. A line may be split across chunks at any byte; the part after the last newline is held until the next
3
+ * chunk (or `flush`) completes it. Handles `\n` and `\r\n`, and skips blank lines.
4
+ * @returns {{ push: (chunk: string) => any[], flush: () => any[] }} Parser.
5
+ */
6
+ export function createParser(): {
7
+ push: (chunk: string) => any[];
8
+ flush: () => any[];
9
+ };
10
+ /**
11
+ * Parse NDJSON text (any `lib/source.mjs` input) into objects. Parsed objects in the source pass through, so a stream that was already
12
+ * decoded can be fed in again.
13
+ * @param {ReadableStream|AsyncIterable<string|Uint8Array|object>|Iterable<string|Uint8Array|object>|string|Uint8Array} source - NDJSON bytes or text.
14
+ * @returns {AsyncGenerator<any, void, undefined>} One object per line.
15
+ */
16
+ export function parse(source: ReadableStream | AsyncIterable<string | Uint8Array | object> | Iterable<string | Uint8Array | object> | string | Uint8Array): AsyncGenerator<any, void, undefined>;