@cldmv/llm-translator 0.8.0 → 0.10.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 (167) hide show
  1. package/README.md +9 -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 +8 -8
  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/ollama/chat/request.mjs +2 -0
  9. package/dist/api/detect.mjs +1 -1
  10. package/dist/api/driver/azure/detect.mjs +2 -0
  11. package/dist/api/driver/azure/error.mjs +2 -0
  12. package/dist/api/driver/azure/info.mjs +2 -0
  13. package/dist/api/driver/azure/model/list.mjs +2 -0
  14. package/dist/api/driver/azure/path.mjs +2 -0
  15. package/dist/api/driver/azure/request.mjs +2 -0
  16. package/dist/api/driver/azure/settings.mjs +2 -0
  17. package/dist/api/driver/fireworks/detect.mjs +2 -0
  18. package/dist/api/driver/fireworks/info.mjs +2 -0
  19. package/dist/api/driver/fireworks/path.mjs +2 -0
  20. package/dist/api/driver/fireworks/request.mjs +2 -0
  21. package/dist/api/driver/fireworks/settings.mjs +2 -0
  22. package/dist/api/driver/gemini/detect.mjs +2 -0
  23. package/dist/api/driver/gemini/info.mjs +2 -0
  24. package/dist/api/driver/gemini/path.mjs +2 -0
  25. package/dist/api/driver/gemini/request.mjs +2 -0
  26. package/dist/api/driver/gemini/settings.mjs +2 -0
  27. package/dist/api/driver/groq/detect.mjs +2 -0
  28. package/dist/api/driver/groq/info.mjs +2 -0
  29. package/dist/api/driver/groq/path.mjs +2 -0
  30. package/dist/api/driver/groq/request.mjs +2 -0
  31. package/dist/api/driver/groq/settings.mjs +2 -0
  32. package/dist/api/driver/localai/chunk.mjs +2 -0
  33. package/dist/api/driver/localai/detect.mjs +2 -0
  34. package/dist/api/driver/localai/info.mjs +2 -0
  35. package/dist/api/driver/localai/request.mjs +2 -0
  36. package/dist/api/driver/localai/response.mjs +2 -0
  37. package/dist/api/driver/localai/settings.mjs +2 -0
  38. package/dist/api/driver/ollama/info.mjs +1 -1
  39. package/dist/api/driver/ollama/request.mjs +1 -1
  40. package/dist/api/driver/openrouter/chunk.mjs +2 -0
  41. package/dist/api/driver/openrouter/detect.mjs +2 -0
  42. package/dist/api/driver/openrouter/info.mjs +2 -0
  43. package/dist/api/driver/openrouter/path.mjs +2 -0
  44. package/dist/api/driver/openrouter/request.mjs +2 -0
  45. package/dist/api/driver/openrouter/response.mjs +2 -0
  46. package/dist/api/driver/openrouter/settings.mjs +2 -0
  47. package/dist/api/driver/tgi/chunk.mjs +2 -0
  48. package/dist/api/driver/tgi/detect.mjs +2 -0
  49. package/dist/api/driver/tgi/info.mjs +2 -0
  50. package/dist/api/driver/tgi/request.mjs +2 -0
  51. package/dist/api/driver/tgi/response.mjs +2 -0
  52. package/dist/api/driver/tgi/settings.mjs +2 -0
  53. package/dist/api/driver/together/detect.mjs +2 -0
  54. package/dist/api/driver/together/info.mjs +2 -0
  55. package/dist/api/driver/together/request.mjs +2 -0
  56. package/dist/api/driver/together/settings.mjs +2 -0
  57. package/dist/api/driver/vllm/detect.mjs +1 -1
  58. package/dist/api/driver/vllm/info.mjs +1 -1
  59. package/dist/api/driver/vllm/model/list.mjs +1 -1
  60. package/dist/api/driver/xai/detect.mjs +2 -0
  61. package/dist/api/driver/xai/info.mjs +2 -0
  62. package/dist/api/driver/xai/request.mjs +2 -0
  63. package/dist/api/driver/xai/settings.mjs +2 -0
  64. package/dist/api/embeddings/send.mjs +1 -1
  65. package/dist/api/health/check.mjs +2 -0
  66. package/dist/api/model/list.mjs +1 -1
  67. package/dist/api/request.mjs +2 -2
  68. package/dist/api/response.mjs +1 -1
  69. package/dist/api/send.mjs +1 -1
  70. package/dist/api/status.mjs +1 -1
  71. package/dist/api/stream.mjs +1 -1
  72. package/dist/index.mjs +1 -1
  73. package/dist/lib/azure.mjs +2 -0
  74. package/dist/lib/backends.mjs +1 -1
  75. package/dist/lib/capture.mjs +1 -1
  76. package/dist/lib/config.mjs +1 -1
  77. package/dist/lib/health.mjs +2 -0
  78. package/dist/lib/http.mjs +1 -1
  79. package/dist/lib/models.mjs +1 -1
  80. package/dist/lib/ndjson.mjs +4 -0
  81. package/dist/lib/ollama.mjs +3 -0
  82. package/dist/lib/openrouter.mjs +2 -0
  83. package/dist/lib/pool.mjs +1 -1
  84. package/dist/lib/presets.mjs +2 -0
  85. package/dist/lib/route.mjs +1 -1
  86. package/dist/lib/settings.mjs +1 -1
  87. package/dist/lib/tgi.mjs +2 -0
  88. package/dist/lib/vllm.mjs +4 -0
  89. package/package.json +1 -1
  90. package/types/src/api/convert/anthropic/messages/to/ollama/chat/request.d.mts +14 -0
  91. package/types/src/api/convert/ollama/chat/to/anthropic/messages/response.d.mts +10 -0
  92. package/types/src/api/convert/ollama/chat/to/anthropic/messages/stream.d.mts +14 -0
  93. package/types/src/api/convert/ollama/chat/to/openai/chat/response.d.mts +10 -0
  94. package/types/src/api/convert/ollama/chat/to/openai/chat/stream.d.mts +13 -0
  95. package/types/src/api/convert/openai/chat/to/ollama/chat/request.d.mts +12 -0
  96. package/types/src/api/driver/azure/detect.d.mts +8 -0
  97. package/types/src/api/driver/azure/error.d.mts +15 -0
  98. package/types/src/api/driver/azure/info.d.mts +31 -0
  99. package/types/src/api/driver/azure/model/list.d.mts +7 -0
  100. package/types/src/api/driver/azure/path.d.mts +7 -0
  101. package/types/src/api/driver/azure/request.d.mts +8 -0
  102. package/types/src/api/driver/azure/settings.d.mts +23 -0
  103. package/types/src/api/driver/fireworks/detect.d.mts +8 -0
  104. package/types/src/api/driver/fireworks/info.d.mts +13 -0
  105. package/types/src/api/driver/fireworks/path.d.mts +7 -0
  106. package/types/src/api/driver/fireworks/request.d.mts +7 -0
  107. package/types/src/api/driver/fireworks/settings.d.mts +5 -0
  108. package/types/src/api/driver/gemini/detect.d.mts +8 -0
  109. package/types/src/api/driver/gemini/info.d.mts +13 -0
  110. package/types/src/api/driver/gemini/path.d.mts +7 -0
  111. package/types/src/api/driver/gemini/request.d.mts +7 -0
  112. package/types/src/api/driver/gemini/settings.d.mts +5 -0
  113. package/types/src/api/driver/groq/detect.d.mts +8 -0
  114. package/types/src/api/driver/groq/info.d.mts +13 -0
  115. package/types/src/api/driver/groq/path.d.mts +7 -0
  116. package/types/src/api/driver/groq/request.d.mts +7 -0
  117. package/types/src/api/driver/groq/settings.d.mts +5 -0
  118. package/types/src/api/driver/localai/chunk.d.mts +25 -0
  119. package/types/src/api/driver/localai/detect.d.mts +6 -0
  120. package/types/src/api/driver/localai/info.d.mts +33 -0
  121. package/types/src/api/driver/localai/request.d.mts +10 -0
  122. package/types/src/api/driver/localai/response.d.mts +26 -0
  123. package/types/src/api/driver/localai/settings.d.mts +25 -0
  124. package/types/src/api/driver/ollama/info.d.mts +7 -2
  125. package/types/src/api/driver/openrouter/chunk.d.mts +25 -0
  126. package/types/src/api/driver/openrouter/detect.d.mts +26 -0
  127. package/types/src/api/driver/openrouter/info.d.mts +30 -0
  128. package/types/src/api/driver/openrouter/path.d.mts +8 -0
  129. package/types/src/api/driver/openrouter/request.d.mts +10 -0
  130. package/types/src/api/driver/openrouter/response.d.mts +8 -0
  131. package/types/src/api/driver/openrouter/settings.d.mts +26 -0
  132. package/types/src/api/driver/tgi/chunk.d.mts +9 -0
  133. package/types/src/api/driver/tgi/detect.d.mts +6 -0
  134. package/types/src/api/driver/tgi/info.d.mts +33 -0
  135. package/types/src/api/driver/tgi/request.d.mts +9 -0
  136. package/types/src/api/driver/tgi/response.d.mts +9 -0
  137. package/types/src/api/driver/tgi/settings.d.mts +25 -0
  138. package/types/src/api/driver/together/detect.d.mts +8 -0
  139. package/types/src/api/driver/together/info.d.mts +13 -0
  140. package/types/src/api/driver/together/request.d.mts +7 -0
  141. package/types/src/api/driver/together/settings.d.mts +5 -0
  142. package/types/src/api/driver/vllm/detect.d.mts +1 -1
  143. package/types/src/api/driver/vllm/info.d.mts +1 -1
  144. package/types/src/api/driver/vllm/model/list.d.mts +3 -1
  145. package/types/src/api/driver/xai/detect.d.mts +8 -0
  146. package/types/src/api/driver/xai/info.d.mts +13 -0
  147. package/types/src/api/driver/xai/request.d.mts +7 -0
  148. package/types/src/api/driver/xai/settings.d.mts +5 -0
  149. package/types/src/api/endpoint/status.d.mts +5 -2
  150. package/types/src/api/health/check.d.mts +8 -0
  151. package/types/src/api/status.d.mts +1 -1
  152. package/types/src/lib/azure.d.mts +17 -0
  153. package/types/src/lib/backends.d.mts +22 -0
  154. package/types/src/lib/config.d.mts +12 -0
  155. package/types/src/lib/events.d.mts +2 -2
  156. package/types/src/lib/health.d.mts +22 -0
  157. package/types/src/lib/http.d.mts +13 -2
  158. package/types/src/lib/models.d.mts +27 -2
  159. package/types/src/lib/ndjson.d.mts +16 -0
  160. package/types/src/lib/ollama.d.mts +86 -0
  161. package/types/src/lib/openrouter.d.mts +23 -0
  162. package/types/src/lib/pool.d.mts +30 -4
  163. package/types/src/lib/presets.d.mts +98 -0
  164. package/types/src/lib/route.d.mts +1 -1
  165. package/types/src/lib/settings.d.mts +5 -0
  166. package/types/src/lib/tgi.d.mts +33 -0
  167. package/types/src/lib/vllm.d.mts +47 -0
@@ -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>;
@@ -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,17 @@
1
+ /**
2
+ * Build the path (and query) of an Azure OpenAI call.
3
+ *
4
+ * The v1 API (`<endpoint>/openai/v1/...`, the model named in the body, no `api-version`) is used unless the upstream sets `apiVersion`.
5
+ * With `apiVersion` the classic form is used: `<endpoint>/openai/deployments/<deployment>/chat/completions?api-version=<version>`, where the
6
+ * deployment is the upstream's `deployment` or else the request's model. The model list has no deployment in its path (`/openai/models`).
7
+ * An upstream URL that already ends in `/openai` (a pasted `.../openai/v1` base has its `/v1` removed by the config) is not given a second `/openai`.
8
+ * @param {"chat" | "embeddings" | "models"} kind - Which call.
9
+ * @param {{url: string, apiVersion?: string, deployment?: string}} endpoint - Runtime endpoint.
10
+ * @param {string} [model] - The request's model, the deployment name unless the endpoint sets one.
11
+ * @returns {string} Path starting with `/`, with the `api-version` query for the classic form.
12
+ */
13
+ export function route(kind: "chat" | "embeddings" | "models", endpoint: {
14
+ url: string;
15
+ apiVersion?: string;
16
+ deployment?: string;
17
+ }, model?: string): string;
@@ -26,3 +26,25 @@ export function isSglangInfo(body: Record<string, any>): boolean;
26
26
  * @returns {boolean} True for LM Studio's model listing.
27
27
  */
28
28
  export function isLmstudioModels(body: Record<string, any>): boolean;
29
+ /**
30
+ * Does a `GET /info` reply come from Hugging Face Text Generation Inference? The match is strict so no other server binds: the router
31
+ * names itself `text-generation-router` (Text Embeddings Inference answers `/info` too, as `text-embeddings-router`), and the reply
32
+ * carries a string `model_id` and `version` and a numeric `max_total_tokens` (older releases lack `max_input_tokens`, so it is not required).
33
+ * @param {Record<string, any>} body - Reply object (see `objectOf`).
34
+ * @returns {boolean} True for TGI's `/info`.
35
+ */
36
+ export function isTgiInfo(body: Record<string, any>): boolean;
37
+ /**
38
+ * Does a `GET /version` reply come from LocalAI? It answers `{ version: "<version> (<commit>)" }` (the version, a space, and the build
39
+ * commit in parentheses, which is empty for a source build), where vLLM and SGLang answer a bare version, so the shape names LocalAI.
40
+ * @param {Record<string, any>} body - Reply object (see `objectOf`).
41
+ * @returns {boolean} True for LocalAI's version reply.
42
+ */
43
+ export function isLocalaiVersion(body: Record<string, any>): boolean;
44
+ /**
45
+ * Does a `GET /.well-known/localai.json` reply come from LocalAI? It is LocalAI's discovery document: a string `version` and an
46
+ * `endpoints` map that names the OpenAI routes (`models`, `chat_completions`) by path.
47
+ * @param {Record<string, any>} body - Reply object (see `objectOf`).
48
+ * @returns {boolean} True for LocalAI's discovery document.
49
+ */
50
+ export function isLocalaiDiscovery(body: Record<string, any>): boolean;
@@ -28,6 +28,18 @@ export type UpstreamConfig = {
28
28
  * Extra headers sent to the upstream.
29
29
  */
30
30
  headers?: Record<string, string>;
31
+ /**
32
+ * Azure OpenAI `api-version`. Set, it selects the classic per-deployment URLs; unset, the v1 API is used.
33
+ */
34
+ apiVersion?: string;
35
+ /**
36
+ * Azure OpenAI deployment name for the classic URLs. Defaults to the request's model.
37
+ */
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";
31
43
  /**
32
44
  * Driver name, or `"auto"` (default) to detect.
33
45
  */
@@ -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>;
@@ -23,6 +23,17 @@
23
23
  * @returns {string} Absolute URL.
24
24
  */
25
25
  export function join(base: string, path: string): string;
26
+ /**
27
+ * The path (with any query) of a call on an upstream. A driver that has a `path(kind, { endpoint, model })` leaf builds it from the endpoint
28
+ * and the model (Azure OpenAI puts the deployment and `api-version` there); otherwise `info().paths[kind]` is used, with the standard
29
+ * OpenAI path for `embeddings` and `models` when the driver does not name one.
30
+ * @param {any} driver - Driver record (`info` and the optional `path` leaf).
31
+ * @param {"chat" | "messages" | "embeddings" | "models"} kind - Which call.
32
+ * @param {any} endpoint - Runtime endpoint.
33
+ * @param {string} [model] - The upstream's model name for the request.
34
+ * @returns {Promise<string>} Path starting with `/`.
35
+ */
36
+ export function pathOf(driver: any, kind: "chat" | "messages" | "embeddings" | "models", endpoint: any, model?: string): Promise<string>;
26
37
  /**
27
38
  * Whether a listen address only accepts connections from this machine.
28
39
  * @param {string} host - Host or address.
@@ -32,7 +43,7 @@ export function isLoopback(host: string): boolean;
32
43
  /**
33
44
  * Build the request headers for an upstream call.
34
45
  * @param {any} endpoint - Runtime endpoint.
35
- * @param {string} [auth] - `"bearer"` (default) or `"x-api-key"`.
46
+ * @param {string} [auth] - `"bearer"` (default), `"x-api-key"` or `"api-key"` (Azure OpenAI).
36
47
  * @param {Record<string,string>} [extra] - Extra headers applied last.
37
48
  * @returns {Record<string,string>} Header map.
38
49
  */
@@ -42,7 +53,7 @@ export function headers(endpoint: any, auth?: string, extra?: Record<string, str
42
53
  * once and every driver that asks for it gets the same result, so a path fetched for one backend (for example `/v1/models`) is
43
54
  * not fetched again for the next. Never rejects; treat the result as read-only.
44
55
  *
45
- * Without `driver` the request carries the upstream's bearer key. A driver whose `info()` says `auth: "x-api-key"` or carries
56
+ * Without `driver` the request carries the upstream's bearer key. A driver whose `info()` says `auth: "x-api-key"` or `"api-key"`, or carries
46
57
  * `headers` passes its `info()` so the probe is sent the way the driver talks to its own backend; that request is a different
47
58
  * request from the bearer one, so it is cached under its own key.
48
59
  * @param {any} context - `{ endpoint, transport, signal, timeout, probes? }`.
@@ -12,12 +12,37 @@ 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
- * @param {any} context - `{ endpoint, transport, signal, timeout, auth, extraHeaders }`.
42
+ * @param {any} context - `{ endpoint, transport, signal, timeout, auth, extraHeaders, path }`. `path` replaces `/v1/models`.
18
43
  * @returns {Promise<{id: string, created?: number, owned_by?: string, max_model_len?: number}[] | null>} Models, or null when the upstream did not answer with a model list.
19
44
  */
20
- export function fetchModels({ endpoint, transport, signal, timeout, auth, extraHeaders }: any): Promise<{
45
+ export function fetchModels({ endpoint, transport, signal, timeout, auth, extraHeaders, path }: any): Promise<{
21
46
  id: string;
22
47
  created?: number;
23
48
  owned_by?: string;
@@ -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>;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Convert a Chat Completions request body to an Ollama `/api/chat` body. Ollama streams unless told not to, so `stream` is always set. Tool
3
+ * arguments become objects, tool results name their tool, images go in `images` as base64, `max_tokens` becomes `options.num_predict`, the
4
+ * sampling fields go in `options`, `response_format` becomes `format` and the effort or thinking switch becomes `think`. What Ollama has no
5
+ * field for (`tool_choice` other than `auto`, `n`, `logit_bias`, `logprobs`, images given by URL, ...) is left out and named in `dropped`;
6
+ * `tool_choice: "none"` also removes the tools, so a call the client forbade cannot happen.
7
+ * @param {any} body - Chat Completions request body.
8
+ * @param {{ dropped?: string[], sampling?: Record<string, any> }} [context] - `dropped` collects the names of what was left out; `sampling` are extension sampling fields for `options`.
9
+ * @returns {any} Ollama request body.
10
+ */
11
+ export function chatBody(body: any, context?: {
12
+ dropped?: string[];
13
+ sampling?: Record<string, any>;
14
+ }): any;
15
+ /**
16
+ * The tool calls of an Ollama reply as Chat Completions calls. Ollama sends no id (and an object for `arguments`), so each call gets one
17
+ * here, unless the server sent its own.
18
+ * @param {any[] | undefined} calls - `message.tool_calls`.
19
+ * @param {number} [first] - Index of the first call (a stream numbers calls across chunks).
20
+ * @returns {any[]} Calls with `index`, `id`, `type` and `function` (`arguments` as JSON text).
21
+ */
22
+ export function callsOfReply(calls: any[] | undefined, first?: number): any[];
23
+ /**
24
+ * Chat Completions `finish_reason` for a finished Ollama reply: `tool_calls` when the model called tools, `length` when it ran out of tokens, else `stop`
25
+ * (also for the `load` and `unload` reasons of a request that generated nothing).
26
+ * @param {any} reply - Ollama reply or final stream line.
27
+ * @param {boolean} calls - Whether the reply carried tool calls.
28
+ * @returns {string} `finish_reason`.
29
+ */
30
+ export function finishOf(reply: any, calls: boolean): string;
31
+ /**
32
+ * Chat Completions usage from the counters of a finished Ollama reply.
33
+ * @param {any} reply - Ollama reply or final stream line.
34
+ * @returns {{prompt_tokens: number, completion_tokens: number, total_tokens: number} | undefined} Usage, or undefined when the reply has no counters.
35
+ */
36
+ export function usageOf(reply: any): {
37
+ prompt_tokens: number;
38
+ completion_tokens: number;
39
+ total_tokens: number;
40
+ } | undefined;
41
+ /**
42
+ * The same counts as Anthropic usage, which is what the OpenAI front's usage report reads from a converted reply.
43
+ * @param {{prompt_tokens: number, completion_tokens: number} | undefined} usage - Chat Completions usage.
44
+ * @returns {{input_tokens: number, output_tokens: number} | undefined} Anthropic usage.
45
+ */
46
+ export function folded(usage: {
47
+ prompt_tokens: number;
48
+ completion_tokens: number;
49
+ } | undefined): {
50
+ input_tokens: number;
51
+ output_tokens: number;
52
+ } | undefined;
53
+ /**
54
+ * The error an Ollama reply carries in `error` (also sent with HTTP 200 in a stream).
55
+ * @param {any} reply - Ollama reply or stream line.
56
+ * @returns {string | null} The message, or null when the reply has none.
57
+ */
58
+ export function errorOf(reply: any): string | null;
59
+ /**
60
+ * Convert a (non-streaming) Ollama `/api/chat` reply to a Chat Completions `chat.completion`: the thinking goes in the settings' reasoning
61
+ * field, the tool calls get ids, `done_reason` becomes `finish_reason` and the evaluation counts become `usage`.
62
+ * @param {any} reply - Parsed Ollama reply.
63
+ * @param {{ reasoningField?: string }} [options] - `reasoningField` is where the thinking goes (default `reasoning`).
64
+ * @returns {any} `chat.completion` object.
65
+ * @throws {TranslatorError} `upstream_error` (502) when the reply is an error.
66
+ */
67
+ export function completion(reply: any, options?: {
68
+ reasoningField?: string;
69
+ }): any;
70
+ /**
71
+ * Create the converter of an Ollama stream's lines into Chat Completions chunks. One chunker is for one reply: it keeps the completion id (so every
72
+ * chunk carries the same one), the tool-call numbering across lines and whether any tool was called.
73
+ * @param {{ model?: string, reasoningField?: string, includeUsage?: boolean }} [options] - `model` overrides the model name on the chunks; `reasoningField` is where the thinking goes (default `reasoning`); `includeUsage` (default true) adds the final usage chunk.
74
+ * @returns {{ line: (line: any) => any[], finished: () => boolean, usage: () => any }} `line` gives the chunks one line produces (an error line gives one `{ error }` chunk), `finished` says whether the final line was seen and `usage` is the Chat Completions usage of it.
75
+ */
76
+ export function createChunker(options?: {
77
+ model?: string;
78
+ reasoningField?: string;
79
+ includeUsage?: boolean;
80
+ }): {
81
+ line: (line: any) => any[];
82
+ finished: () => boolean;
83
+ usage: () => any;
84
+ };
85
+ /** Protocol name of an endpoint that talks to Ollama's native chat API. */
86
+ export const PROTOCOL: "ollama.chat";
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The error a reply that answered HTTP 200 carries: `choices[i].error` on every choice (the provider failed while generating; the choice's
3
+ * `finish_reason` is `"error"` and any partial text is not used), or a top-level `error` with no choices.
4
+ * @param {any} body - Parsed reply body.
5
+ * @returns {{code: any, message: string, metadata?: any} | null} The error object, or null when the reply has none to report.
6
+ */
7
+ export function found(body: any): {
8
+ code: any;
9
+ message: string;
10
+ metadata?: any;
11
+ } | null;
12
+ /**
13
+ * The `TranslatorError` for an OpenRouter error object. Its numeric `code` is the HTTP status when it is a client or server error, else 502; the
14
+ * `code` of the error is `metadata.error_type` when OpenRouter gives one, else `upstream_error`.
15
+ * @param {{code?: any, message: string, metadata?: any}} error - Error object.
16
+ * @returns {TranslatorError} Error to throw.
17
+ */
18
+ export function failure(error: {
19
+ code?: any;
20
+ message: string;
21
+ metadata?: any;
22
+ }): TranslatorError;
23
+ import { TranslatorError } from "./errors.mjs";
@@ -5,11 +5,14 @@
5
5
  * @property {{base?: number, max?: number}} [backoff] Backoff in ms for a failing endpoint (defaults `1000` and `60000`).
6
6
  * @property {number} [connectTimeout] Milliseconds to wait for the TCP connection of a request to an endpoint with pool mates (default `10000`, `0` disables). Needs the default transport.
7
7
  * @property {number} [headersTimeout] Milliseconds to wait for the response headers of such a request (default `0`, off). Once the headers have arrived nothing caps the body.
8
+ * @property {number} [healthInterval] Milliseconds a readiness probe result (see `lib/health`) is trusted before the next request that has pool mates probes again (default `10000`, `0` turns probing off). Only drivers that name a health path (vLLM: `/health`) are probed.
9
+ * @property {number} [healthTimeout] Milliseconds a readiness probe may take before the endpoint counts as not ready (default `2000`).
8
10
  * @property {Record<string, "failover" | "round_robin" | "least_busy">} [models] Strategy per model, keyed by the model name after aliases.
9
11
  */
10
12
  /**
11
13
  * Fresh health record for an endpoint.
12
- * @returns {{failures: number, until: number, inflight: number, requests: number, errors: number, lastError: string | null, lastFailure: number | null, lastSuccess: number | null}} Record.
14
+ * `ready` is the result of the last readiness probe: `true`, `false`, or `null` when none has run (or the server has no health path); `checkedAt` is when it ran, `unsupported` is set once the server answered the probe with a 4xx (no such path), and `checking` holds a probe in flight so concurrent requests share it.
15
+ * @returns {{failures: number, until: number, inflight: number, requests: number, errors: number, lastError: string | null, lastFailure: number | null, lastSuccess: number | null, ready: boolean | null, checkedAt: number | null, readyReason: string | null, unsupported: boolean, checking: Promise<void> | null}} Record.
13
16
  */
14
17
  export function health(): {
15
18
  failures: number;
@@ -20,11 +23,16 @@ export function health(): {
20
23
  lastError: string | null;
21
24
  lastFailure: number | null;
22
25
  lastSuccess: number | null;
26
+ ready: boolean | null;
27
+ checkedAt: number | null;
28
+ readyReason: string | null;
29
+ unsupported: boolean;
30
+ checking: Promise<void> | null;
23
31
  };
24
32
  /**
25
33
  * Validate and normalize the `pool` config.
26
34
  * @param {PoolConfig | undefined} raw - Raw config.
27
- * @returns {{strategy: string, backoff: {base: number, max: number}, connectTimeout: number, headersTimeout: number, models: Record<string, string>}} Normalized config.
35
+ * @returns {{strategy: string, backoff: {base: number, max: number}, connectTimeout: number, headersTimeout: number, healthInterval: number, healthTimeout: number, models: Record<string, string>}} Normalized config.
28
36
  * @throws {TranslatorError} `INVALID_CONFIG` for an unknown strategy, a bad backoff or a bad timeout.
29
37
  */
30
38
  export function normalize(raw?: PoolConfig | undefined): {
@@ -35,11 +43,13 @@ export function normalize(raw?: PoolConfig | undefined): {
35
43
  };
36
44
  connectTimeout: number;
37
45
  headersTimeout: number;
46
+ healthInterval: number;
47
+ healthTimeout: number;
38
48
  models: Record<string, string>;
39
49
  };
40
50
  /**
41
51
  * Order the endpoints that serve a model into the sequence in which they are tried: healthy endpoints first, arranged by the model's
42
- * strategy, then the unhealthy ones, soonest to recover first. Every endpoint is included, so an all-unhealthy pool is still tried.
52
+ * strategy, then the unhealthy ones (backing off after a failure, or not ready), soonest to recover first. Every endpoint is included, so an all-unhealthy pool is still tried.
43
53
  * @param {any} config - Normalized config (`pool`).
44
54
  * @param {any} state - Translator state (`cursors`).
45
55
  * @param {any[]} list - Endpoints serving the model, in configuration order.
@@ -69,10 +79,13 @@ export function succeeded(endpoint: any, now?: number): void;
69
79
  * Health of an endpoint as status output shows it.
70
80
  * @param {any} endpoint - Runtime endpoint.
71
81
  * @param {number} [now] - Current time in ms.
72
- * @returns {{healthy: boolean, failures: number, retryAt: string | null, inflight: number, requests: number, errors: number, lastError: string | null, lastFailure: string | null, lastSuccess: string | null}} Health report (times are ISO strings).
82
+ * @returns {{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}} Health report (times are ISO strings). `healthy` is false while the endpoint backs off after a failure or its last readiness probe said it is not ready; `ready` is that probe's verdict (null when none ran), `readyReason` why it failed.
73
83
  */
74
84
  export function describe(endpoint: any, now?: number): {
75
85
  healthy: boolean;
86
+ ready: boolean | null;
87
+ readyReason: string | null;
88
+ checkedAt: string | null;
76
89
  failures: number;
77
90
  retryAt: string | null;
78
91
  inflight: number;
@@ -94,6 +107,11 @@ export const TIMEOUTS: Readonly<{
94
107
  connect: 10000;
95
108
  headers: 0;
96
109
  }>;
110
+ /** Default readiness probing: how long a result is trusted (ms, 0 turns probing off) and how long a probe may take (ms). */
111
+ export const PROBES: Readonly<{
112
+ interval: 10000;
113
+ timeout: 2000;
114
+ }>;
97
115
  /**
98
116
  * Pool config as the translator accepts it.
99
117
  */
@@ -117,6 +135,14 @@ export type PoolConfig = {
117
135
  * Milliseconds to wait for the response headers of such a request (default `0`, off). Once the headers have arrived nothing caps the body.
118
136
  */
119
137
  headersTimeout?: number;
138
+ /**
139
+ * Milliseconds a readiness probe result (see `lib/health`) is trusted before the next request that has pool mates probes again (default `10000`, `0` turns probing off). Only drivers that name a health path (vLLM: `/health`) are probed.
140
+ */
141
+ healthInterval?: number;
142
+ /**
143
+ * Milliseconds a readiness probe may take before the endpoint counts as not ready (default `2000`).
144
+ */
145
+ healthTimeout?: number;
120
146
  /**
121
147
  * Strategy per model, keyed by the model name after aliases.
122
148
  */
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The driver facts of a preset.
3
+ * @param {string} name - Preset name.
4
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
5
+ */
6
+ export function describe(name: string): {
7
+ name: string;
8
+ protocol: string;
9
+ order: number;
10
+ auth: string;
11
+ strict: boolean;
12
+ fields?: string[];
13
+ paths: Record<string, string>;
14
+ };
15
+ /**
16
+ * Match an endpoint by host name, no network access.
17
+ * @param {string} name - Preset name.
18
+ * @param {any} endpoint - Runtime endpoint.
19
+ * @returns {{host: string} | null} Facts, or null when the host is not the provider's.
20
+ */
21
+ export function match(name: string, endpoint: any): {
22
+ host: string;
23
+ } | null;
24
+ /**
25
+ * The settings of a preset (a copy).
26
+ * @param {string} name - Preset name.
27
+ * @returns {any} Partial settings.
28
+ */
29
+ export function settingsOf(name: string): any;
30
+ /**
31
+ * Put the provider's path root in front of a call path unless the upstream URL already ends in it, so `https://api.groq.com`,
32
+ * `https://api.groq.com/openai` and `https://api.groq.com/openai/v1` (the config removes the `/v1`) all reach the same URL.
33
+ * @param {string} name - Preset name.
34
+ * @param {"chat" | "embeddings" | "models"} kind - Which call.
35
+ * @param {any} endpoint - Runtime endpoint.
36
+ * @returns {string} Path starting with `/`.
37
+ */
38
+ export function route(name: string, kind: "chat" | "embeddings" | "models", endpoint: any): string;
39
+ /**
40
+ * Normalize a Chat Completions body for a preset: drop empty tool fields and the fields the provider rejects (each recorded in `state.dropped`).
41
+ * @param {string} name - Preset name.
42
+ * @param {any} body - Chat Completions request body.
43
+ * @param {any} [context] - `{ state }`.
44
+ * @returns {any} Normalized body.
45
+ */
46
+ export function trim(name: string, body: any, context?: any): any;
47
+ /**
48
+ * @typedef {object} Preset
49
+ * @property {number} order - Detection order (host drivers sit ahead of the probing ones).
50
+ * @property {string[]} hosts - Host names the provider answers on.
51
+ * @property {string} [root] - Path in front of the call paths (`/openai`), added unless the upstream URL already ends in it.
52
+ * @property {Record<string, string>} paths - Call paths under the root.
53
+ * @property {any} settings - Translator settings of the provider.
54
+ * @property {string[]} [fields] - Extra request fields the OpenAI front's `passthroughFilter` lets through (`info().fields`).
55
+ * @property {string[]} [drop] - Request fields the provider rejects.
56
+ * @property {(body: any) => string[]} [dropWhen] - Fields the provider rejects for this request (by model).
57
+ * @property {boolean} [dropName] - Remove `name` from messages.
58
+ */
59
+ /** @type {Readonly<Record<string, Preset>>} */
60
+ export const PRESETS: Readonly<Record<string, Preset>>;
61
+ export type Preset = {
62
+ /**
63
+ * - Detection order (host drivers sit ahead of the probing ones).
64
+ */
65
+ order: number;
66
+ /**
67
+ * - Host names the provider answers on.
68
+ */
69
+ hosts: string[];
70
+ /**
71
+ * - Path in front of the call paths (`/openai`), added unless the upstream URL already ends in it.
72
+ */
73
+ root?: string;
74
+ /**
75
+ * - Call paths under the root.
76
+ */
77
+ paths: Record<string, string>;
78
+ /**
79
+ * - Translator settings of the provider.
80
+ */
81
+ settings: any;
82
+ /**
83
+ * - Extra request fields the OpenAI front's `passthroughFilter` lets through (`info().fields`).
84
+ */
85
+ fields?: string[];
86
+ /**
87
+ * - Request fields the provider rejects.
88
+ */
89
+ drop?: string[];
90
+ /**
91
+ * - Fields the provider rejects for this request (by model).
92
+ */
93
+ dropWhen?: (body: any) => string[];
94
+ /**
95
+ * - Remove `name` from messages.
96
+ */
97
+ dropName?: boolean;
98
+ };
@@ -15,7 +15,7 @@ export function serves(endpoint: any, model: string): boolean;
15
15
  * @param {boolean} [advance] - Move the round robin cursor (false to only look).
16
16
  * @returns {{endpoint: any, model: string | undefined, unserved: boolean, pool: any[], pin: {effort?: string, thinking?: boolean} | undefined}} Chosen endpoint, the model name to send upstream, whether
17
17
  * no endpoint serves the model and the endpoints to try in order (the chosen one first). When nothing serves it and the fallback endpoint knows
18
- * exactly one model, that model is sent instead.
18
+ * exactly one base model (adapters aside), that model is sent instead.
19
19
  */
20
20
  export function pick(config: any, endpoints: any[], model: string | undefined, state: any, advance?: boolean): {
21
21
  endpoint: any;
@@ -44,6 +44,7 @@ export function resolve(...layers: (Partial<Settings> | null | undefined)[]): Se
44
44
  * @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.
45
45
  * @property {boolean} effortPassthrough - vLLM driver: send `xhigh` and `max` reasoning effort unchanged instead of clamping them to `high`.
46
46
  * @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.
47
+ * @property {boolean | "auto"} nativeMessages - vLLM driver: send an Anthropic-front request to vLLM's own `/v1/messages` (vLLM 0.11.1 and later) with only normalisation, instead of converting it to Chat Completions. `false` (default) always converts, `true` always uses the native endpoint, `"auto"` uses it when the detected or configured version is 0.11.1 or later. A request the endpoint cannot take (a trailing assistant message, `document` blocks, deferred tools unless `toolSearch` is `native`) is converted, and so is every request once the server answers 404 to `/v1/messages`. The OpenAI front is never affected.
47
48
  * @property {number} contextWindow - Prompt size in tokens the upstream truncates at, or 0 when unknown. Drivers whose server silently truncates (Ollama) warn once when a request is estimated to exceed it.
48
49
  * @property {number} defaultMaxTokens - `max_tokens` used when an OpenAI request has none (Anthropic requires one).
49
50
  */
@@ -203,6 +204,10 @@ export type Settings = {
203
204
  * - 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.
204
205
  */
205
206
  passthroughFilter: boolean;
207
+ /**
208
+ * - vLLM driver: send an Anthropic-front request to vLLM's own `/v1/messages` (vLLM 0.11.1 and later) with only normalisation, instead of converting it to Chat Completions. `false` (default) always converts, `true` always uses the native endpoint, `"auto"` uses it when the detected or configured version is 0.11.1 or later. A request the endpoint cannot take (a trailing assistant message, `document` blocks, deferred tools unless `toolSearch` is `native`) is converted, and so is every request once the server answers 404 to `/v1/messages`. The OpenAI front is never affected.
209
+ */
210
+ nativeMessages: boolean | "auto";
206
211
  /**
207
212
  * - Prompt size in tokens the upstream truncates at, or 0 when unknown. Drivers whose server silently truncates (Ollama) warn once when a request is estimated to exceed it.
208
213
  */
@@ -0,0 +1,33 @@
1
+ /**
2
+ * One tool call in the OpenAI shape. Historic TGI sent the id as a number, the arguments as an object (under `parameters` in some
3
+ * releases) and omitted `type`; current TGI sends string arguments.
4
+ * @param {any} call - Tool call as TGI sent it.
5
+ * @param {number} [position] - Position in the call list, the id when TGI sent none. Left out for streamed fragments, whose missing id
6
+ * means the fragment continues the open call.
7
+ * @returns {any} Tool call with a string id, `type: "function"` and string `arguments`.
8
+ */
9
+ export function toolCall(call: any, position?: number): any;
10
+ /**
11
+ * The tool calls of a message or delta as a list: historic TGI sent one object instead of an array.
12
+ * @param {any} value - `tool_calls` as TGI sent it.
13
+ * @param {boolean} [fill] - Give a call without an id its position as the id (whole answers; not streamed fragments).
14
+ * @returns {any[] | undefined} The list, or undefined when there is none.
15
+ */
16
+ export function toolCalls(value: any, fill?: boolean): any[] | undefined;
17
+ /**
18
+ * The OpenAI `finish_reason` for one TGI sent: `eos_token` and `stop_sequence` become `stop`, or `tool_calls` when the answer holds tool calls
19
+ * (historic TGI reported `eos_token` for those).
20
+ * @param {any} reason - `finish_reason` as TGI sent it.
21
+ * @param {boolean} hasToolCalls - Whether the answer holds tool calls.
22
+ * @returns {any} Finish reason.
23
+ */
24
+ export function finish(reason: any, hasToolCalls: boolean): any;
25
+ /**
26
+ * TGI's grammar as `response_format` takes it: `{ type: "json" | "json_object" | "regex", value }` or `{ type: "json_schema", value: { name?, schema } }`.
27
+ * An OpenAI `json_schema` format (`{ type: "json_schema", json_schema: { name, schema, strict } }`) becomes TGI's `json_schema` with
28
+ * the name and schema; a bare `json_object` has no schema to constrain with, so it asks for any JSON object. Shapes TGI already
29
+ * understands pass through.
30
+ * @param {any} format - A `response_format` (or `grammar`) value.
31
+ * @returns {any} The format in TGI's shape.
32
+ */
33
+ export function grammar(format: any): any;