@cldmv/llm-translator 0.12.0 → 0.14.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 (150) hide show
  1. package/README.md +8 -8
  2. package/dist/api/convert/anthropic/messages/to/bedrock/converse/request.mjs +2 -0
  3. package/dist/api/convert/anthropic/messages/to/openai/responses/request.mjs +2 -0
  4. package/dist/api/convert/bedrock/converse/to/anthropic/messages/response.mjs +2 -0
  5. package/dist/api/convert/bedrock/converse/to/anthropic/messages/stream.mjs +2 -0
  6. package/dist/api/convert/bedrock/converse/to/openai/chat/response.mjs +2 -0
  7. package/dist/api/convert/bedrock/converse/to/openai/chat/stream.mjs +2 -0
  8. package/dist/api/convert/openai/chat/to/bedrock/converse/request.mjs +2 -0
  9. package/dist/api/convert/openai/chat/to/openai/responses/request.mjs +2 -0
  10. package/dist/api/convert/openai/chat/to/openai/responses/response.mjs +2 -0
  11. package/dist/api/convert/openai/chat/to/openai/responses/stream.mjs +2 -0
  12. package/dist/api/convert/openai/responses/to/anthropic/messages/response.mjs +2 -0
  13. package/dist/api/convert/openai/responses/to/anthropic/messages/stream.mjs +2 -0
  14. package/dist/api/convert/openai/responses/to/openai/chat/request.mjs +6 -0
  15. package/dist/api/convert/openai/responses/to/openai/chat/response.mjs +2 -0
  16. package/dist/api/convert/openai/responses/to/openai/chat/stream.mjs +2 -0
  17. package/dist/api/detect.mjs +1 -1
  18. package/dist/api/driver/anthropic/info.mjs +1 -1
  19. package/dist/api/driver/azure/info.mjs +1 -1
  20. package/dist/api/driver/bedrock/detect.mjs +2 -0
  21. package/dist/api/driver/bedrock/info.mjs +2 -0
  22. package/dist/api/driver/bedrock/model/list.mjs +2 -0
  23. package/dist/api/driver/bedrock/path.mjs +2 -0
  24. package/dist/api/driver/bedrock/request.mjs +2 -0
  25. package/dist/api/driver/bedrock/sign.mjs +2 -0
  26. package/dist/api/driver/compatible/info.mjs +1 -1
  27. package/dist/api/driver/deepseek/info.mjs +1 -1
  28. package/dist/api/driver/llamacpp/info.mjs +1 -1
  29. package/dist/api/driver/lmstudio/info.mjs +1 -1
  30. package/dist/api/driver/localai/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/sglang/info.mjs +1 -1
  37. package/dist/api/driver/tgi/info.mjs +1 -1
  38. package/dist/api/driver/vertex/auth.mjs +2 -0
  39. package/dist/api/driver/vertex/detect.mjs +2 -0
  40. package/dist/api/driver/vertex/error.mjs +2 -0
  41. package/dist/api/driver/vertex/info.mjs +2 -0
  42. package/dist/api/driver/vertex/path.mjs +2 -0
  43. package/dist/api/driver/vertex/request.mjs +2 -0
  44. package/dist/api/driver/vertex/settings.mjs +2 -0
  45. package/dist/api/driver/vertex/token/count.mjs +2 -0
  46. package/dist/api/driver/vllm/info.mjs +1 -1
  47. package/dist/api/request.mjs +2 -2
  48. package/dist/api/response.mjs +1 -1
  49. package/dist/api/route.mjs +1 -1
  50. package/dist/api/send.mjs +1 -1
  51. package/dist/api/server/plugin.mjs +1 -1
  52. package/dist/api/status.mjs +1 -1
  53. package/dist/api/stream.mjs +1 -1
  54. package/dist/api/token/count.mjs +1 -1
  55. package/dist/index.mjs +1 -1
  56. package/dist/lib/bedrock.mjs +2 -0
  57. package/dist/lib/capture.mjs +1 -1
  58. package/dist/lib/config.mjs +1 -1
  59. package/dist/lib/converse.mjs +3 -0
  60. package/dist/lib/document-urls.mjs +2 -0
  61. package/dist/lib/documents.mjs +4 -4
  62. package/dist/lib/estimate.mjs +1 -1
  63. package/dist/lib/eventstream.mjs +2 -0
  64. package/dist/lib/fetch-url.mjs +2 -0
  65. package/dist/lib/google-auth.mjs +2 -0
  66. package/dist/lib/http.mjs +1 -1
  67. package/dist/lib/presets.mjs +1 -1
  68. package/dist/lib/protocol.mjs +2 -0
  69. package/dist/lib/responses-upstream.mjs +13 -0
  70. package/dist/lib/responses.mjs +2 -0
  71. package/dist/lib/route.mjs +1 -1
  72. package/dist/lib/routes.mjs +1 -1
  73. package/dist/lib/settings.mjs +1 -1
  74. package/dist/lib/sigv4.mjs +7 -0
  75. package/dist/lib/vertex.mjs +2 -0
  76. package/dist/lib/vllm.mjs +2 -2
  77. package/package.json +1 -1
  78. package/types/src/api/convert/anthropic/messages/to/bedrock/converse/request.d.mts +14 -0
  79. package/types/src/api/convert/anthropic/messages/to/openai/responses/request.d.mts +16 -0
  80. package/types/src/api/convert/bedrock/converse/to/anthropic/messages/response.d.mts +10 -0
  81. package/types/src/api/convert/bedrock/converse/to/anthropic/messages/stream.d.mts +14 -0
  82. package/types/src/api/convert/bedrock/converse/to/openai/chat/response.d.mts +10 -0
  83. package/types/src/api/convert/bedrock/converse/to/openai/chat/stream.d.mts +13 -0
  84. package/types/src/api/convert/openai/chat/to/bedrock/converse/request.d.mts +11 -0
  85. package/types/src/api/convert/openai/chat/to/openai/responses/request.d.mts +12 -0
  86. package/types/src/api/convert/openai/chat/to/openai/responses/response.d.mts +14 -0
  87. package/types/src/api/convert/openai/chat/to/openai/responses/stream.d.mts +18 -0
  88. package/types/src/api/convert/openai/responses/to/anthropic/messages/response.d.mts +8 -0
  89. package/types/src/api/convert/openai/responses/to/anthropic/messages/stream.d.mts +8 -0
  90. package/types/src/api/convert/openai/responses/to/openai/chat/request.d.mts +17 -0
  91. package/types/src/api/convert/openai/responses/to/openai/chat/response.d.mts +8 -0
  92. package/types/src/api/convert/openai/responses/to/openai/chat/stream.d.mts +10 -0
  93. package/types/src/api/driver/anthropic/info.d.mts +2 -1
  94. package/types/src/api/driver/azure/info.d.mts +2 -1
  95. package/types/src/api/driver/bedrock/detect.d.mts +9 -0
  96. package/types/src/api/driver/bedrock/info.d.mts +36 -0
  97. package/types/src/api/driver/bedrock/model/list.d.mts +11 -0
  98. package/types/src/api/driver/bedrock/path.d.mts +9 -0
  99. package/types/src/api/driver/bedrock/request.d.mts +9 -0
  100. package/types/src/api/driver/bedrock/sign.d.mts +9 -0
  101. package/types/src/api/driver/compatible/info.d.mts +2 -1
  102. package/types/src/api/driver/deepseek/info.d.mts +2 -1
  103. package/types/src/api/driver/fireworks/info.d.mts +2 -1
  104. package/types/src/api/driver/gemini/info.d.mts +2 -1
  105. package/types/src/api/driver/groq/info.d.mts +2 -1
  106. package/types/src/api/driver/llamacpp/info.d.mts +2 -1
  107. package/types/src/api/driver/lmstudio/info.d.mts +2 -1
  108. package/types/src/api/driver/localai/info.d.mts +2 -1
  109. package/types/src/api/driver/mistral/info.d.mts +2 -1
  110. package/types/src/api/driver/ollama/info.d.mts +2 -1
  111. package/types/src/api/driver/ollama/request.d.mts +1 -1
  112. package/types/src/api/driver/openai/info.d.mts +2 -1
  113. package/types/src/api/driver/openrouter/info.d.mts +2 -1
  114. package/types/src/api/driver/sglang/info.d.mts +2 -1
  115. package/types/src/api/driver/tgi/info.d.mts +2 -1
  116. package/types/src/api/driver/together/info.d.mts +2 -1
  117. package/types/src/api/driver/vertex/auth.d.mts +7 -0
  118. package/types/src/api/driver/vertex/detect.d.mts +8 -0
  119. package/types/src/api/driver/vertex/error.d.mts +15 -0
  120. package/types/src/api/driver/vertex/info.d.mts +16 -0
  121. package/types/src/api/driver/vertex/path.d.mts +7 -0
  122. package/types/src/api/driver/vertex/request.d.mts +6 -0
  123. package/types/src/api/driver/vertex/settings.d.mts +23 -0
  124. package/types/src/api/driver/vertex/token/count.d.mts +7 -0
  125. package/types/src/api/driver/vllm/info.d.mts +2 -1
  126. package/types/src/api/driver/xai/info.d.mts +2 -1
  127. package/types/src/api/request.d.mts +3 -2
  128. package/types/src/api/route.d.mts +2 -2
  129. package/types/src/api/send.d.mts +1 -1
  130. package/types/src/api/server/plugin.d.mts +1 -1
  131. package/types/src/api/status.d.mts +1 -1
  132. package/types/src/lib/bedrock.d.mts +74 -0
  133. package/types/src/lib/config.d.mts +35 -5
  134. package/types/src/lib/converse.d.mts +81 -0
  135. package/types/src/lib/document-urls.d.mts +55 -0
  136. package/types/src/lib/estimate.d.mts +1 -1
  137. package/types/src/lib/eventstream.d.mts +34 -0
  138. package/types/src/lib/fetch-url.d.mts +64 -0
  139. package/types/src/lib/google-auth.d.mts +58 -0
  140. package/types/src/lib/http.d.mts +5 -3
  141. package/types/src/lib/presets.d.mts +2 -1
  142. package/types/src/lib/protocol.d.mts +87 -0
  143. package/types/src/lib/responses-upstream.d.mts +58 -0
  144. package/types/src/lib/responses.d.mts +72 -0
  145. package/types/src/lib/route.d.mts +7 -3
  146. package/types/src/lib/routes.d.mts +2 -1
  147. package/types/src/lib/settings.d.mts +19 -2
  148. package/types/src/lib/sigv4.d.mts +41 -0
  149. package/types/src/lib/vertex.d.mts +55 -0
  150. package/types/src/lib/vllm.d.mts +4 -4
@@ -1,6 +1,6 @@
1
1
  /**
2
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
- * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, fields: string[], paths: Record<string,string>}} Driver facts.
3
+ * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, protocols: string[], fields: string[], paths: Record<string,string>}} Driver facts.
4
4
  */
5
5
  export function info(): {
6
6
  name: string;
@@ -8,6 +8,7 @@ export function info(): {
8
8
  order: number;
9
9
  auth: string;
10
10
  strict: boolean;
11
+ protocols: string[];
11
12
  fields: string[];
12
13
  paths: Record<string, string>;
13
14
  };
@@ -1,10 +1,11 @@
1
1
  /**
2
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.
3
+ * @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, fields?: string[], paths: Record<string,string>}} Driver facts.
4
4
  */
5
5
  export function info(): {
6
6
  name: string;
7
7
  protocol: string;
8
+ protocols: string[];
8
9
  order: number;
9
10
  auth: string;
10
11
  strict: boolean;
@@ -2,8 +2,8 @@
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, `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
- * @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.
5
+ * @param {any} [options] - `{ front, headers, clientHeaders, filter, images, usage, signal }`. `signal` aborts the fetching of `url` documents (the `documentUrls` setting). `front` overrides the configured front for this call, `tokens: true` (used by `token.count`) never picks a native Messages route on a server whose own protocol is another, because the tokenizer reads Chat Completions messages, and sends no credentials (a driver's `auth` leaf is skipped; the count call builds its own headers), `wire: "responses"` says the body is the Chat Completions form of a Responses API request (so the protocol is chosen for a Responses client), `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
+ * @returns {Promise<{upstream: string, method: string, url: string, path: string, headers: Record<string,string>, body: any, state: any, pool: string[], more: boolean, 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); `more` is true when the upstream is `api: "auto"` and has another protocol to fall back to; `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<{
9
9
  upstream: string;
@@ -14,6 +14,7 @@ export function request(body: any, options?: any): Promise<{
14
14
  body: any;
15
15
  state: any;
16
16
  pool: string[];
17
+ more: boolean;
17
18
  images: {
18
19
  sent: boolean;
19
20
  retry: boolean;
@@ -2,8 +2,8 @@
2
2
  * Resolve a client request body to its upstream and model (after aliases and routing) without doing any I/O, for example to
3
3
  * check a model allow-list before `send`. Uses the same routing as `request`.
4
4
  * @param {any} body - Client request body (Anthropic Messages or OpenAI Chat Completions, per `front`).
5
- * @param {any} [options] - `{ front }` overrides the configured front for this call.
6
- * @returns {{upstream: string, model: string, requested: string | undefined, protocol: string, backend: string, native: boolean, unserved: boolean, pool: string[]}} `upstream` is the first endpoint `send` would try right now (the endpoint name), `model` the name sent upstream, `requested` the name the client used, `protocol` the upstream's protocol (`openai.chat` or `anthropic.messages`), `backend` the driver detection chose (`vllm`, `openai`, `anthropic` or `compatible`, the `driver` that `status()` reports), `native` whether the body is forwarded without conversion and `unserved` whether no upstream lists the model and `pool` the names of all endpoints serving the model in the order they would be tried (failover candidates). When several endpoints serve the model this is a snapshot of the current health, in-flight counts and round robin position and it does not move the round robin; `send` decides again and may use another member, so the endpoint that answered is `usage.upstream`.
5
+ * @param {any} [options] - `{ front, wire }`: `front` overrides the configured front for this call, `wire: "responses"` routes the Chat Completions form of a Responses API request.
6
+ * @returns {{upstream: string, model: string, requested: string | undefined, protocol: string, backend: string, native: boolean, unserved: boolean, pool: string[]}} `upstream` is the first endpoint `send` would try right now (the endpoint name), `model` the name sent upstream, `requested` the name the client used, `protocol` the protocol this request goes over (`anthropic.messages`, `openai.chat`, `openai.responses` or `ollama.chat`; see the upstream's `api` setting), `backend` the driver detection chose (`vllm`, `openai`, `anthropic` or `compatible`, the `driver` that `status()` reports), `native` whether the body is forwarded without conversion and `unserved` whether no upstream lists the model and `pool` the names of all endpoints serving the model in the order they would be tried (failover candidates). When several endpoints serve the model this is a snapshot of the current health, in-flight counts and round robin position and it does not move the round robin; `send` decides again and may use another member, so the endpoint that answered is `usage.upstream`.
7
7
  * @throws {TranslatorError} `invalid_body` (400) when the body is not a JSON object.
8
8
  */
9
9
  export function route(body: any, options?: any): {
@@ -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, 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).
28
+ * @param {any} [options] - `{ signal, front, wire, headers, clientHeaders, filter, cacheSalt, onUsage, log }`: abort signal for the upstream call, per-call front, `wire: "responses"` for the Chat Completions form of a Responses API request, 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
  * Fastify plugin. Anthropic front: `POST /v1/messages`, `POST /v1/messages/count_tokens`, `GET /v1/models`, `GET /v1/models/{id}`,
3
- * `GET|HEAD /` and `/api/hello`. OpenAI front: `POST /v1/chat/completions`, `POST /v1/embeddings`, `GET /v1/models`, `GET /v1/models/{id}`, `GET|HEAD /`. Responses stream as
3
+ * `GET|HEAD /` and `/api/hello`. OpenAI front: `POST /v1/chat/completions`, `POST /v1/responses`, `POST /v1/responses/input_tokens`, `POST /v1/embeddings`, `GET /v1/models`, `GET /v1/models/{id}`, `GET|HEAD /`. Responses stream as
4
4
  * `text/event-stream` with keep-alive pings; a client disconnect aborts the upstream request. Register it with
5
5
  * `app.register(api.server.plugin, { apiKey })`. `authorize(request)` (sync or async) runs after `apiKey` and the body parse and decides
6
6
  * with `true` / `{ ok: true, context }` or `false` / `{ ok: false, status, message }`; `onUsage(report, context)` receives each request's usage report. When the Fastify `logger` is enabled, events also go to it as structured lines (`{ event }` plus the message), through the request's logger for events of a request.
@@ -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`). `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.
3
+ * @returns {{front: string, upstreams: any[]}} Front protocol and per-upstream detection results and health (see `endpoint.status`). `api` is the upstream's `api` setting as the canonical id (or `"auto"`) and `protocols` the protocols its driver speaks. `protocol` is the one a request in the configured front's protocol goes over now (under `api: "auto"` that is the first of the client's own protocol and Chat Completions that the server has, so an upstream that answered 404, 405 or 501 to one has moved on until the next detection). `responses` is true while that holds for a Responses API request (a Responses client on an OpenAI front), and `messages` is true while an Anthropic request to a vLLM upstream goes to its native `/v1/messages` (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,74 @@
1
+ /**
2
+ * Does a model id name a Claude model, which InvokeModel serves with the Anthropic Messages body? An application inference profile is an
3
+ * opaque id and so counts as not Claude (Converse serves Claude too); set the upstream's `api` for it.
4
+ * @param {string | undefined} model - Model id, inference profile id or ARN.
5
+ * @returns {boolean} True for a Claude id.
6
+ */
7
+ export function claude(model: string | undefined): boolean;
8
+ /**
9
+ * The region a runtime host name belongs to.
10
+ * @param {string} host - Host name.
11
+ * @returns {string | null} The region, or null when the host is not a Bedrock runtime host.
12
+ */
13
+ export function regionOfHost(host: string): string | null;
14
+ /**
15
+ * The region of an upstream: its `region`, else the one in its URL's host name, else `AWS_REGION`, else `AWS_DEFAULT_REGION`.
16
+ * @param {{region?: string, url?: string}} endpoint - Runtime endpoint (or raw upstream config).
17
+ * @param {Record<string, string | undefined>} [env] - Environment (default `process.env`).
18
+ * @returns {string | null} The region, or null when none is set.
19
+ */
20
+ export function regionOf(endpoint: {
21
+ region?: string;
22
+ url?: string;
23
+ }, env?: Record<string, string | undefined>): string | null;
24
+ /**
25
+ * The default base URL of a region: `https://bedrock-runtime.<region>.amazonaws.com` (`.amazonaws.com.cn` in the China regions).
26
+ * @param {{region?: string}} raw - Raw upstream config without a `url`.
27
+ * @param {Record<string, string | undefined>} [env] - Environment (default `process.env`).
28
+ * @returns {string} Base URL.
29
+ * @throws {TranslatorError} `INVALID_CONFIG` when no region is configured.
30
+ */
31
+ export function defaultUrl(raw: {
32
+ region?: string;
33
+ }, env?: Record<string, string | undefined>): string;
34
+ /**
35
+ * The URL path segment of a model: the id percent-encoded as one segment, because ids and ARNs contain `:` and `/`.
36
+ * @param {string} model - Model id, inference profile id or ARN.
37
+ * @returns {string} Path starting with `/model/`.
38
+ */
39
+ export function modelPath(model: string): string;
40
+ /**
41
+ * How an upstream authenticates, most specific first: the upstream's `apiKey` (a Bedrock API key, sent as a bearer token), its access keys
42
+ * (SigV4), then the environment's `AWS_BEARER_TOKEN_BEDROCK` and `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` / `AWS_SESSION_TOKEN`.
43
+ * @param {any} endpoint - Runtime endpoint (`apiKey`, `accessKeyId`, `secretAccessKey`, `sessionToken`).
44
+ * @param {Record<string, string | undefined>} [env] - Environment (default `process.env`).
45
+ * @returns {{bearer: string} | {keys: {accessKeyId: string, secretAccessKey: string, sessionToken?: string}} | null} The credential, or null when there is none.
46
+ */
47
+ export function credential(endpoint: any, env?: Record<string, string | undefined>): {
48
+ bearer: string;
49
+ } | {
50
+ keys: {
51
+ accessKeyId: string;
52
+ secretAccessKey: string;
53
+ sessionToken?: string;
54
+ };
55
+ } | null;
56
+ /**
57
+ * The headers of an authenticated call: the given ones with `authorization` set. A Bedrock API key gives `Bearer <key>`. Otherwise the call is
58
+ * signed with SigV4 for the service `bedrock` in the upstream's region, which adds `x-amz-date`, `x-amz-security-token` (temporary
59
+ * credentials) and `authorization`; the body must be the exact text that is sent.
60
+ * @param {any} endpoint - Runtime endpoint.
61
+ * @param {{method: string, url: string, headers: Record<string, string>, body: string}} request - The call.
62
+ * @param {{env?: Record<string, string | undefined>, date?: Date}} [options] - `env` is the environment (default `process.env`), `date` the signing time (default now).
63
+ * @returns {Record<string, string>} Headers to send.
64
+ * @throws {TranslatorError} `missing_credentials` (500) when the upstream has no credential, `missing_region` (500) when SigV4 needs a region and there is none.
65
+ */
66
+ export function authenticate(endpoint: any, request: {
67
+ method: string;
68
+ url: string;
69
+ headers: Record<string, string>;
70
+ body: string;
71
+ }, { env, date }?: {
72
+ env?: Record<string, string | undefined>;
73
+ date?: Date;
74
+ }): Record<string, string>;
@@ -2,9 +2,10 @@
2
2
  * Normalize one upstream entry into the runtime endpoint record.
3
3
  * @param {string | UpstreamConfig} entry - Upstream URL or config object.
4
4
  * @param {number} index - Position in the list.
5
+ * @param {any} [globalSettings] - The config's global `settings`.
5
6
  * @returns {any} Runtime endpoint.
6
7
  */
7
- export function endpoint(entry: string | UpstreamConfig, index: number): any;
8
+ export function endpoint(entry: string | UpstreamConfig, index: number, globalSettings?: any): any;
8
9
  /**
9
10
  * Validate and normalize the translator config.
10
11
  * @param {any} [config] - Raw config passed to `createTranslator`.
@@ -17,9 +18,9 @@ export type UpstreamConfig = {
17
18
  */
18
19
  name?: string;
19
20
  /**
20
- * Base URL of the upstream server (`http://host:8000`).
21
+ * Base URL of the upstream server (`http://host:8000`). Required, except for `backend: "bedrock"`, whose default is `https://bedrock-runtime.<region>.amazonaws.com`.
21
22
  */
22
- url: string;
23
+ url?: string;
23
24
  /**
24
25
  * Key sent to the upstream.
25
26
  */
@@ -37,9 +38,38 @@ export type UpstreamConfig = {
37
38
  */
38
39
  deployment?: string;
39
40
  /**
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
+ * Google Vertex AI settings (see docs/drivers.md). `url` may be left out when `backend` is `"vertex"`: it defaults to the region's host.
41
42
  */
42
- api?: "openai" | "native";
43
+ vertex?: {
44
+ project?: string;
45
+ region?: string;
46
+ credentials?: string | object;
47
+ accessToken?: string;
48
+ getToken?: (options: {
49
+ signal?: AbortSignal;
50
+ }) => string | Promise<string>;
51
+ metadataServer?: boolean | string;
52
+ };
53
+ /**
54
+ * Amazon Bedrock: the AWS region SigV4 signs for. Defaults to the region in the URL's host name, then `AWS_REGION`, then `AWS_DEFAULT_REGION`.
55
+ */
56
+ region?: string;
57
+ /**
58
+ * Amazon Bedrock: access key id for SigV4. Defaults to `AWS_ACCESS_KEY_ID`.
59
+ */
60
+ accessKeyId?: string;
61
+ /**
62
+ * Amazon Bedrock: secret access key for SigV4. Defaults to `AWS_SECRET_ACCESS_KEY`.
63
+ */
64
+ secretAccessKey?: string;
65
+ /**
66
+ * Amazon Bedrock: session token of temporary credentials. Defaults to `AWS_SESSION_TOKEN`.
67
+ */
68
+ sessionToken?: string;
69
+ /**
70
+ * Which protocol of the server to speak, `"auto"` by default. Canonical ids are `"anthropic.messages"`, `"openai.chat"`, `"openai.responses"`, `"ollama.chat"` and `"bedrock.converse"`; `"messages"`, `"anthropic"` and `"claude"` mean the first, `"chat"`, `"openai"` and `"chatgpt"` the second, `"responses"` and `"codex"` the third, `"native"` and `"ollama"` the fourth and `"converse"` the last. `"auto"` goes over the client's own protocol when the driver's server speaks it (Chat Completions otherwise) and falls back to the next one when the server answers 404, 405 or 501; an explicit value is always that protocol and never falls back. A protocol the driver does not list fails detection with `unsupported_api`.
71
+ */
72
+ api?: string;
43
73
  /**
44
74
  * Driver name, or `"auto"` (default) to detect.
45
75
  */
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Convert a Chat Completions request body to a Converse body (`messages`, `system`, `inferenceConfig`, `toolConfig` and
3
+ * `additionalModelRequestFields`; the model id and the choice of streaming belong to the URL, so neither is in the body). `max_tokens`,
4
+ * `temperature`, `top_p` and `stop` become `inferenceConfig`, tools become `toolConfig` (`tool_choice` `auto`, `required` and one named function
5
+ * map to `auto`, `any` and `tool`), images are sent as bytes, and `top_k`, the extension sampling fields and a thinking budget go in
6
+ * `additionalModelRequestFields`, which carries a model's own parameters. What Converse has no field for (`response_format`, `n`,
7
+ * `parallel_tool_calls`, `seed`, penalties, images given by URL, reasoning in history, ...) is left out and named in `dropped`.
8
+ * Converse needs a `toolConfig` whenever the history has tool blocks and has no "none" choice, so: a request without tools has its past tool calls
9
+ * and results written as text, and `tool_choice: "none"` with tools sends the `toolConfig` and adds a system instruction not to call tools.
10
+ * @param {any} body - Chat Completions request body.
11
+ * @param {{ dropped?: string[], sampling?: Record<string, any>, thinkingBudget?: number, marker?: string }} [context] - `dropped` collects the names of what was left out; `sampling` are extension fields for `additionalModelRequestFields`; `thinkingBudget` is the token budget of enabled thinking, sent as `thinking: { type: "enabled", budget_tokens }`; `marker` is the text that marks a failed tool result.
12
+ * @returns {any} Converse request body.
13
+ */
14
+ export function chatBody(body: any, context?: {
15
+ dropped?: string[];
16
+ sampling?: Record<string, any>;
17
+ thinkingBudget?: number;
18
+ marker?: string;
19
+ }): any;
20
+ /**
21
+ * Chat Completions `finish_reason` for a Converse `stopReason`: `end_turn` and `stop_sequence` are `stop`, `max_tokens` and
22
+ * `model_context_window_exceeded` are `length`, `tool_use` is `tool_calls`, `content_filtered` and `guardrail_intervened` are `content_filter`,
23
+ * and `malformed_model_output` and `malformed_tool_use` are `error` (a failure, not an answer). A reply that called tools is `tool_calls`.
24
+ * @param {string | undefined} reason - Converse `stopReason`.
25
+ * @param {boolean} calls - Whether the reply carried tool calls.
26
+ * @returns {string} `finish_reason`.
27
+ */
28
+ export function finishOf(reason: string | undefined, calls: boolean): string;
29
+ /**
30
+ * Chat Completions usage from a Converse `usage` object. Converse counts cache reads and writes apart from `inputTokens`; the prompt is all three.
31
+ * @param {any} usage - Converse `usage`.
32
+ * @returns {{prompt_tokens: number, completion_tokens: number, total_tokens: number, prompt_tokens_details?: {cached_tokens: number}} | undefined} Usage, or undefined when there are no counts.
33
+ */
34
+ export function usageOf(usage: any): {
35
+ prompt_tokens: number;
36
+ completion_tokens: number;
37
+ total_tokens: number;
38
+ prompt_tokens_details?: {
39
+ cached_tokens: number;
40
+ };
41
+ } | undefined;
42
+ /**
43
+ * The same counts as Anthropic usage, which is what the OpenAI front's usage report reads from a converted reply (Converse reports them the
44
+ * way Anthropic does: `inputTokens` leaves out the cache).
45
+ * @param {any} usage - Converse `usage`.
46
+ * @returns {{input_tokens: number, output_tokens: number, cache_read_input_tokens: number, cache_creation_input_tokens: number} | undefined} Anthropic usage, or undefined when there are no counts.
47
+ */
48
+ export function folded(usage: any): {
49
+ input_tokens: number;
50
+ output_tokens: number;
51
+ cache_read_input_tokens: number;
52
+ cache_creation_input_tokens: number;
53
+ } | undefined;
54
+ /**
55
+ * Convert a (non-streaming) Converse reply to a Chat Completions `chat.completion`: text blocks are joined into the content, reasoning blocks go
56
+ * in the settings' reasoning field (redacted ones are left out), `toolUse` blocks become tool calls, `stopReason` becomes `finish_reason` and
57
+ * `usage` becomes `usage`.
58
+ * @param {any} reply - Parsed Converse reply.
59
+ * @param {{ reasoningField?: string, model?: string }} [options] - `reasoningField` is where the reasoning goes (default `reasoning`); `model` is the model name on the completion.
60
+ * @returns {any} `chat.completion` object.
61
+ * @throws {TranslatorError} `invalid_upstream_response` (502) when the reply has no message.
62
+ */
63
+ export function completion(reply: any, options?: {
64
+ reasoningField?: string;
65
+ model?: string;
66
+ }): any;
67
+ /**
68
+ * Create the converter of a ConverseStream's events into Chat Completions chunks. One chunker is for one reply: it keeps the completion id
69
+ * (so every chunk carries the same one), the numbering of tool calls and which content block each belongs to.
70
+ * @param {{ model?: string, reasoningField?: string, includeUsage?: boolean }} [options] - `model` is the model name on the chunks; `reasoningField` is where the reasoning goes (default `reasoning`); `includeUsage` (default true) adds the final usage chunk.
71
+ * @returns {{ event: (name: string | undefined, data: any) => any[], finished: () => boolean, usage: () => any }} `event` gives the chunks one event produces (an Anthropic-shaped `error` message gives one `{ error }` chunk), `finished` says whether the reply ended (`messageStop`, or a failure) and `usage` is the Converse `usage` of the `metadata` event.
72
+ */
73
+ export function createChunker(options?: {
74
+ model?: string;
75
+ reasoningField?: string;
76
+ includeUsage?: boolean;
77
+ }): {
78
+ event: (name: string | undefined, data: any) => any[];
79
+ finished: () => boolean;
80
+ usage: () => any;
81
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Validate the `documentUrls` setting and fill in its defaults.
3
+ * @param {any} value - `null` or `false` (fetching is off), or `{ allow, maxBytes?, timeout?, maxRedirects?, maxDocuments?, allowPrivate? }`.
4
+ * @returns {{allow: string[], maxBytes: number, timeout: number, maxRedirects: number, maxDocuments: number, allowPrivate: boolean} | null} The complete setting, or null when fetching is off.
5
+ * @throws {TranslatorError} With code `invalid_setting` for anything else, including an empty or missing `allow`.
6
+ */
7
+ export function normalize(value: any): {
8
+ allow: string[];
9
+ maxBytes: number;
10
+ timeout: number;
11
+ maxRedirects: number;
12
+ maxDocuments: number;
13
+ allowPrivate: boolean;
14
+ } | null;
15
+ /**
16
+ * A URL without its query and fragment, which can carry a signature or a token, for notes and events.
17
+ * @param {string} url - URL.
18
+ * @returns {string} Origin and path, or a placeholder for text that is not a URL.
19
+ */
20
+ export function display(url: string): string;
21
+ /**
22
+ * Whether a request needs this step: fetching is on, and nothing overrides or switches off document conversion.
23
+ * @param {any} settings - Resolved settings.
24
+ * @returns {boolean} True when `url` documents should be fetched.
25
+ */
26
+ export function wanted(settings: any): boolean;
27
+ /**
28
+ * Replace the `url` source of each `document` block (also inside `tool_result` content) with the fetched bytes as a `base64` source, which the
29
+ * ordinary document conversion then reads. A document that could not be fetched gets a `fetch_failed` source carrying a reason that is safe for the
30
+ * client, and the conversion turns it into a note; the request itself goes on. The same URL is fetched once per call, and no more than `maxDocuments`
31
+ * different URLs are fetched (the rest fail with that reason). Nothing is cached between calls. The body is not changed: a copy is returned when
32
+ * anything was replaced.
33
+ * @param {any} body - Anthropic Messages request body.
34
+ * @param {{options: any, report: (event: {kind: string, message: string, [detail: string]: any}) => void, signal?: AbortSignal, fetch?: Function, deps?: any}} spec - The normalized `documentUrls` setting, a function that receives one event per fetch, the caller's abort signal, and replaceable parts for tests (`fetch`, and the `deps` given to it).
35
+ * @returns {Promise<any>} The body.
36
+ */
37
+ export function resolve(body: any, { options, report, signal, fetch, deps }: {
38
+ options: any;
39
+ report: (event: {
40
+ kind: string;
41
+ message: string;
42
+ [detail: string]: any;
43
+ }) => void;
44
+ signal?: AbortSignal;
45
+ fetch?: Function;
46
+ deps?: any;
47
+ }): Promise<any>;
48
+ /** Defaults of the fields of `documentUrls` other than `allow`. */
49
+ export const DEFAULTS: Readonly<{
50
+ maxBytes: number;
51
+ timeout: 30000;
52
+ maxRedirects: 3;
53
+ maxDocuments: 10;
54
+ allowPrivate: false;
55
+ }>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Rough prompt size: one token per four characters of the serialized system prompt, messages and tools.
2
+ * Rough prompt size: one token per four characters of the serialized system prompt, messages (or `input`) and tools.
3
3
  * @param {any} body - Upstream request body.
4
4
  * @returns {number} Estimated tokens.
5
5
  */
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Create an incremental frame parser. A frame may be split across chunks at any byte. The prelude CRC is checked as soon as the first twelve
3
+ * bytes are in, so a stream that is not an event stream fails at once, and the message CRC when the frame is complete.
4
+ * @returns {{ push: (chunk: Uint8Array) => {headers: Record<string, any>, payload: Buffer}[], flush: () => void }} Parser; `push` throws `invalid_stream_data` (502) for a bad length or CRC (when frames before the bad one were read, it returns them and throws on the next `push` or `flush`), `flush` throws when the stream ended inside a frame.
5
+ */
6
+ export function createParser(): {
7
+ push: (chunk: Uint8Array) => {
8
+ headers: Record<string, any>;
9
+ payload: Buffer;
10
+ }[];
11
+ flush: () => void;
12
+ };
13
+ /**
14
+ * Parse an event stream (any `lib/source.mjs` input of bytes) into frames.
15
+ * @param {ReadableStream|AsyncIterable<Uint8Array>|Iterable<Uint8Array>|Uint8Array} source - Event stream bytes.
16
+ * @returns {AsyncGenerator<{headers: Record<string, any>, payload: Buffer}, void, undefined>} Frames.
17
+ */
18
+ export function frames(source: ReadableStream | AsyncIterable<Uint8Array> | Iterable<Uint8Array> | Uint8Array): AsyncGenerator<{
19
+ headers: Record<string, any>;
20
+ payload: Buffer;
21
+ }, void, undefined>;
22
+ /**
23
+ * Convert an event stream to `{ event, data }` messages: the shape SSE parsing gives, so the stream converters read it like a Server-Sent Events stream.
24
+ * - `"invoke"` (`InvokeModelWithResponseStream`): each `chunk` event carries `{ "bytes": "<base64>" }`, which decodes to one Anthropic stream event; the message is that event, named by its `type`. Bedrock's `amazon-bedrock-invocationMetrics` field is removed.
25
+ * - `"converse"` (`ConverseStream`): each event is named by its `:event-type` header (`messageStart`, `contentBlockDelta`, ...) and its payload is the data.
26
+ * An `exception` or `error` frame becomes one Anthropic `error` message (see `failure`), and so does a stream that cannot be read (a bad checksum, a payload that is not JSON, a frame cut short, a failing connection), after which the messages end.
27
+ * @param {ReadableStream|AsyncIterable<Uint8Array>|Iterable<Uint8Array>|Uint8Array} source - Event stream bytes.
28
+ * @param {"invoke" | "converse"} kind - Which API the stream comes from.
29
+ * @returns {AsyncGenerator<{event: string, data: any}, void, undefined>} Messages.
30
+ */
31
+ export function events(source: ReadableStream | AsyncIterable<Uint8Array> | Iterable<Uint8Array> | Uint8Array, kind: "invoke" | "converse"): AsyncGenerator<{
32
+ event: string;
33
+ data: any;
34
+ }, void, undefined>;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The class of range an IP address is in.
3
+ * @param {string} address - IPv4 or IPv6 address (a zone id is ignored).
4
+ * @returns {string | null} `loopback`, `private`, `link-local`, `cgnat`, `unique-local`, `multicast`, `unspecified`, `reserved` or `mapped`; null for a public address; `invalid` when it is not an address.
5
+ */
6
+ export function classify(address: string): string | null;
7
+ /**
8
+ * Whether a host name matches an allow-list pattern: an exact host name, `*.example.com` (any subdomain, not `example.com` itself) or `*` (any host).
9
+ * @param {string} host - Lower-case host name without a trailing dot.
10
+ * @param {string[]} patterns - Allow-list.
11
+ * @returns {boolean} True when one pattern matches.
12
+ */
13
+ export function allowed(host: string, patterns: string[]): boolean;
14
+ /**
15
+ * Resolve a host name to every address it has, the way the connection will.
16
+ * @param {string} host - Host name.
17
+ * @returns {Promise<{address: string, family: number}[]>} Addresses.
18
+ */
19
+ export function lookup(host: string): Promise<{
20
+ address: string;
21
+ family: number;
22
+ }[]>;
23
+ /**
24
+ * Fetch a document.
25
+ * @param {string} input - The URL.
26
+ * @param {{allow: string[], maxBytes: number, timeout: number, maxRedirects: number, allowPrivate?: boolean, signal?: AbortSignal}} options - Limits and rules (see the `documentUrls` setting).
27
+ * @param {{lookup?: (host: string) => Promise<{address: string, family: number}[]>, modules?: {http: any, https: any}}} [deps] - Host name lookup and protocol modules (replaceable for tests).
28
+ * @returns {Promise<{bytes: Buffer, mediaType: string, url: string}>} The body, its media type (`application/pdf` or `text/plain`) and the final URL.
29
+ * @throws {FetchError} For anything that stops the fetch; never any other error.
30
+ */
31
+ export function fetchUrl(input: string, options: {
32
+ allow: string[];
33
+ maxBytes: number;
34
+ timeout: number;
35
+ maxRedirects: number;
36
+ allowPrivate?: boolean;
37
+ signal?: AbortSignal;
38
+ }, deps?: {
39
+ lookup?: (host: string) => Promise<{
40
+ address: string;
41
+ family: number;
42
+ }[]>;
43
+ modules?: {
44
+ http: any;
45
+ https: any;
46
+ };
47
+ }): Promise<{
48
+ bytes: Buffer;
49
+ mediaType: string;
50
+ url: string;
51
+ }>;
52
+ /**
53
+ * Why a fetch failed. `message` is safe to show the client; `detail` is for the server's own log and may name addresses and system errors.
54
+ */
55
+ export class FetchError extends Error {
56
+ /**
57
+ * @param {string} kind - `scheme`, `allow`, `dns`, `address`, `network`, `redirects`, `downgrade`, `status`, `size`, `type`, `encoding` or `timeout`.
58
+ * @param {string} message - What to tell the client.
59
+ * @param {string} [detail] - What to log.
60
+ */
61
+ constructor(kind: string, message: string, detail?: string);
62
+ kind: string;
63
+ detail: string;
64
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Forget every cached token and credential file (used by tests).
3
+ * @returns {void}
4
+ */
5
+ export function reset(): void;
6
+ /**
7
+ * Base64url without padding.
8
+ * @param {string | Buffer} input - Data.
9
+ * @returns {string} Encoded text.
10
+ */
11
+ export function base64url(input: string | Buffer): string;
12
+ /**
13
+ * Build the signed JWT a service account exchanges for an access token (RS256, `node:crypto`).
14
+ * @param {{client_email: string, private_key: string, private_key_id?: string, token_uri?: string}} credentials - A service-account key.
15
+ * @param {{now?: number, scope?: string}} [options] - `now` in ms (default the clock) and the OAuth scope.
16
+ * @returns {string} `header.claims.signature`.
17
+ */
18
+ export function assertion(credentials: {
19
+ client_email: string;
20
+ private_key: string;
21
+ private_key_id?: string;
22
+ token_uri?: string;
23
+ }, { now, scope }?: {
24
+ now?: number;
25
+ scope?: string;
26
+ }): string;
27
+ /**
28
+ * The path of gcloud's application default credentials file (`gcloud auth application-default login`).
29
+ * @param {Record<string, string | undefined>} env - Environment.
30
+ * @param {string} [platform] - `process.platform`.
31
+ * @returns {string} Path.
32
+ */
33
+ export function wellKnown(env: Record<string, string | undefined>, platform?: string): string;
34
+ /**
35
+ * The credentials the settings and environment name, without any network access: the `credentials` setting, then `GOOGLE_APPLICATION_CREDENTIALS`,
36
+ * then gcloud's application default credentials file when it exists.
37
+ * @param {any} settings - The upstream's `vertex` settings.
38
+ * @param {Record<string, string | undefined>} [env] - Environment.
39
+ * @returns {any | null} Credentials, or null when none are configured.
40
+ */
41
+ export function credentials(settings: any, env?: Record<string, string | undefined>): any | null;
42
+ /**
43
+ * Find an access token for Vertex AI. Sources, in order: the `getToken` callback (called on every request, it caches for itself), the `accessToken`
44
+ * setting, the upstream's `apiKey` (as a bearer token), the `credentials` setting, `GOOGLE_ACCESS_TOKEN`, `GOOGLE_APPLICATION_CREDENTIALS`, gcloud's
45
+ * application default credentials file, and last the metadata server when `metadataServer` is set. Tokens fetched from Google are cached until a
46
+ * minute before they expire, and concurrent callers share one refresh.
47
+ * @param {any} spec - `{ settings, apiKey, transport, timeout, signal, env, now }`. `settings` is the upstream's `vertex` object; `transport` is the
48
+ * `fetch`-compatible function the token requests go through.
49
+ * @returns {Promise<string>} Access token.
50
+ * @throws {TranslatorError} With code `upstream_auth` when there is no source or Google refuses.
51
+ */
52
+ export function token({ settings, apiKey, transport, timeout, signal, env, now }: any): Promise<string>;
53
+ /** The OAuth scope Vertex AI needs. */
54
+ export const SCOPE: "https://www.googleapis.com/auth/cloud-platform";
55
+ /** Where Google's token endpoint is, for credentials that do not name one. */
56
+ export const TOKEN_URI: "https://oauth2.googleapis.com/token";
57
+ /** Base URL of the GCE metadata server, used when `metadataServer` is `true`. */
58
+ export const METADATA_URL: "http://metadata.google.internal";
@@ -26,14 +26,16 @@ export function join(base: string, path: string): string;
26
26
  /**
27
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
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.
29
+ * OpenAI path for `responses`, `embeddings` and `models` when the driver does not name one.
30
30
  * @param {any} driver - Driver record (`info` and the optional `path` leaf).
31
- * @param {"chat" | "messages" | "embeddings" | "models"} kind - Which call.
31
+ * @param {"chat" | "messages" | "responses" | "converse" | "embeddings" | "models"} kind - Which call.
32
32
  * @param {any} endpoint - Runtime endpoint.
33
33
  * @param {string} [model] - The upstream's model name for the request.
34
+ * @param {string} [protocol] - The protocol the request goes over.
35
+ * @param {boolean} [stream] - Whether the reply is streamed (Vertex AI and Amazon Bedrock use a different path for it).
34
36
  * @returns {Promise<string>} Path starting with `/`.
35
37
  */
36
- export function pathOf(driver: any, kind: "chat" | "messages" | "embeddings" | "models", endpoint: any, model?: string): Promise<string>;
38
+ export function pathOf(driver: any, kind: "chat" | "messages" | "responses" | "converse" | "embeddings" | "models", endpoint: any, model?: string, protocol?: string, stream?: boolean): Promise<string>;
37
39
  /**
38
40
  * Whether a listen address only accepts connections from this machine.
39
41
  * @param {string} host - Host or address.
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * The driver facts of a preset.
3
3
  * @param {string} name - Preset name.
4
- * @returns {{name: string, protocol: string, order: number, auth: string, strict: boolean, hosts: string[], fields?: string[], paths: Record<string,string>}} Driver facts.
4
+ * @returns {{name: string, protocol: string, protocols: string[], order: number, auth: string, strict: boolean, hosts: string[], fields?: string[], paths: Record<string,string>}} Driver facts.
5
5
  */
6
6
  export function describe(name: string): {
7
7
  name: string;
8
8
  protocol: string;
9
+ protocols: string[];
9
10
  order: number;
10
11
  auth: string;
11
12
  strict: boolean;