@cldmv/llm-translator 0.2.0 → 0.3.1
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.
- package/README.md +12 -6
- package/dist/api/convert/anthropic/messages/to/openai/chat/request.mjs +11 -11
- package/dist/api/convert/anthropic/messages/to/openai/chat/response.mjs +1 -1
- package/dist/api/convert/anthropic/messages/to/openai/chat/stream.mjs +1 -1
- package/dist/api/convert/openai/chat/to/anthropic/messages/request.mjs +3 -3
- package/dist/api/convert/openai/chat/to/anthropic/messages/response.mjs +1 -1
- package/dist/api/convert/openai/chat/to/anthropic/messages/stream.mjs +1 -1
- package/dist/api/detect.mjs +1 -1
- package/dist/api/driver/anthropic/token/count.mjs +1 -1
- package/dist/api/driver/compatible/detect.mjs +1 -1
- package/dist/api/driver/compatible/info.mjs +1 -1
- package/dist/api/driver/deepseek/detect.mjs +2 -0
- package/dist/api/driver/deepseek/error.mjs +2 -0
- package/dist/api/driver/deepseek/info.mjs +2 -0
- package/dist/api/driver/deepseek/request.mjs +2 -0
- package/dist/api/driver/deepseek/settings.mjs +2 -0
- package/dist/api/driver/llamacpp/chunk.mjs +2 -0
- package/dist/api/driver/llamacpp/detect.mjs +2 -0
- package/dist/api/driver/llamacpp/flush.mjs +2 -0
- package/dist/api/driver/llamacpp/info.mjs +2 -0
- package/dist/api/driver/llamacpp/request.mjs +2 -0
- package/dist/api/driver/llamacpp/response.mjs +2 -0
- package/dist/api/driver/llamacpp/settings.mjs +2 -0
- package/dist/api/driver/ollama/detect.mjs +2 -0
- package/dist/api/driver/ollama/info.mjs +2 -0
- package/dist/api/driver/ollama/request.mjs +2 -0
- package/dist/api/driver/ollama/settings.mjs +2 -0
- package/dist/api/driver/sglang/detect.mjs +2 -0
- package/dist/api/driver/sglang/info.mjs +2 -0
- package/dist/api/driver/sglang/request.mjs +2 -0
- package/dist/api/driver/sglang/settings.mjs +2 -0
- package/dist/api/driver/vllm/detect.mjs +1 -1
- package/dist/api/driver/vllm/info.mjs +1 -1
- package/dist/api/endpoint/status.mjs +2 -0
- package/dist/api/error/error.mjs +1 -1
- package/dist/api/model/get.mjs +2 -0
- package/dist/api/request.mjs +2 -2
- package/dist/api/route.mjs +2 -0
- package/dist/api/send.mjs +1 -1
- package/dist/api/server/plugin.mjs +1 -1
- package/dist/api/server/start.mjs +1 -1
- package/dist/api/status.mjs +1 -1
- package/dist/api/stream.mjs +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +1 -1
- package/dist/lib/backends.mjs +2 -0
- package/dist/lib/capture.mjs +1 -1
- package/dist/lib/cli.mjs +1 -1
- package/dist/lib/config.mjs +1 -1
- package/dist/lib/estimate.mjs +1 -1
- package/dist/lib/http.mjs +1 -1
- package/dist/lib/ids.mjs +1 -1
- package/dist/lib/models.mjs +1 -1
- package/dist/lib/passthrough.mjs +1 -1
- package/dist/lib/pool.mjs +2 -0
- package/dist/lib/route.mjs +1 -1
- package/dist/lib/routes.mjs +1 -1
- package/dist/lib/settings.mjs +1 -1
- package/dist/lib/thinking.mjs +2 -1
- package/dist/lib/tools.mjs +2 -0
- package/dist/lib/toolsearch.mjs +3 -0
- package/dist/lib/transport.mjs +1 -1
- package/dist/lib/usage.mjs +2 -0
- package/package.json +17 -7
- package/types/src/api/convert/anthropic/messages/to/openai/chat/request.d.mts +6 -15
- package/types/src/api/convert/anthropic/messages/to/openai/chat/response.d.mts +3 -16
- package/types/src/api/convert/anthropic/messages/to/openai/chat/stream.d.mts +1 -15
- package/types/src/api/convert/openai/chat/to/anthropic/messages/request.d.mts +1 -15
- package/types/src/api/convert/openai/chat/to/anthropic/messages/response.d.mts +3 -17
- package/types/src/api/convert/openai/chat/to/anthropic/messages/stream.d.mts +1 -15
- package/types/src/api/detect.d.mts +1 -15
- package/types/src/api/driver/anthropic/detect.d.mts +1 -1
- package/types/src/api/driver/anthropic/info.d.mts +1 -1
- package/types/src/api/driver/anthropic/model/list.d.mts +1 -15
- package/types/src/api/driver/anthropic/settings.d.mts +1 -1
- package/types/src/api/driver/anthropic/token/count.d.mts +1 -15
- package/types/src/api/driver/compatible/detect.d.mts +2 -16
- package/types/src/api/driver/compatible/info.d.mts +3 -20
- package/types/src/api/driver/compatible/model/list.d.mts +1 -15
- package/types/src/api/driver/compatible/request.d.mts +1 -15
- package/types/src/api/driver/compatible/settings.d.mts +1 -1
- package/types/src/api/driver/deepseek/detect.d.mts +26 -0
- package/types/src/api/driver/deepseek/error.d.mts +14 -0
- package/types/src/api/driver/deepseek/info.d.mts +29 -0
- package/types/src/api/driver/deepseek/request.d.mts +8 -0
- package/types/src/api/driver/deepseek/settings.d.mts +25 -0
- package/types/src/api/driver/llamacpp/chunk.d.mts +7 -0
- package/types/src/api/driver/llamacpp/detect.d.mts +6 -0
- package/types/src/api/driver/llamacpp/flush.d.mts +26 -0
- package/types/src/api/driver/llamacpp/info.d.mts +31 -0
- package/types/src/api/driver/llamacpp/request.d.mts +8 -0
- package/types/src/api/driver/llamacpp/response.d.mts +8 -0
- package/types/src/api/driver/llamacpp/settings.d.mts +27 -0
- package/types/src/api/driver/ollama/detect.d.mts +6 -0
- package/types/src/api/driver/ollama/info.d.mts +30 -0
- package/types/src/api/driver/ollama/request.d.mts +8 -0
- package/types/src/api/driver/ollama/settings.d.mts +7 -0
- package/types/src/api/driver/openai/detect.d.mts +1 -1
- package/types/src/api/driver/openai/info.d.mts +1 -1
- package/types/src/api/driver/openai/model/list.d.mts +1 -15
- package/types/src/api/driver/openai/request.d.mts +1 -15
- package/types/src/api/driver/openai/settings.d.mts +1 -1
- package/types/src/api/driver/sglang/detect.d.mts +6 -0
- package/types/src/api/driver/sglang/info.d.mts +31 -0
- package/types/src/api/driver/sglang/request.d.mts +8 -0
- package/types/src/api/driver/sglang/settings.d.mts +24 -0
- package/types/src/api/driver/vllm/detect.d.mts +3 -17
- package/types/src/api/driver/vllm/error.d.mts +1 -15
- package/types/src/api/driver/vllm/info.d.mts +3 -20
- package/types/src/api/driver/vllm/model/list.d.mts +1 -15
- package/types/src/api/driver/vllm/probe.d.mts +1 -15
- package/types/src/api/driver/vllm/request.d.mts +1 -15
- package/types/src/api/driver/vllm/settings.d.mts +1 -15
- package/types/src/api/driver/vllm/token/count.d.mts +1 -15
- package/types/src/api/endpoint/status.d.mts +27 -0
- package/types/src/api/error/build.d.mts +1 -15
- package/types/src/api/error/error.d.mts +1 -15
- package/types/src/api/model/get.d.mts +9 -0
- package/types/src/api/model/list.d.mts +1 -15
- package/types/src/api/request.d.mts +8 -17
- package/types/src/api/response.d.mts +1 -15
- package/types/src/api/route.d.mts +18 -0
- package/types/src/api/send.d.mts +21 -16
- package/types/src/api/server/plugin.d.mts +6 -19
- package/types/src/api/server/start.d.mts +2 -16
- package/types/src/api/server/stop.d.mts +1 -15
- package/types/src/api/sse/encode.d.mts +1 -15
- package/types/src/api/sse/parse.d.mts +1 -15
- package/types/src/api/sse/ping.d.mts +1 -15
- package/types/src/api/sse/write.d.mts +1 -15
- package/types/src/api/status.d.mts +2 -16
- package/types/src/api/stream.d.mts +1 -15
- package/types/src/api/token/count.d.mts +1 -15
- package/types/src/index.d.mts +24 -34
- package/types/src/lib/arguments.d.mts +2 -16
- package/types/src/lib/backends.d.mts +21 -0
- package/types/src/lib/capture.d.mts +2 -16
- package/types/src/lib/cli.d.mts +12 -26
- package/types/src/lib/config.d.mts +11 -25
- package/types/src/lib/documents.d.mts +16 -27
- package/types/src/lib/errors.d.mts +75 -75
- package/types/src/lib/estimate.d.mts +58 -7
- package/types/src/lib/finish.d.mts +4 -4
- package/types/src/lib/http.d.mts +19 -5
- package/types/src/lib/ids.d.mts +11 -20
- package/types/src/lib/images.d.mts +19 -19
- package/types/src/lib/models.d.mts +13 -13
- package/types/src/lib/normalize.d.mts +3 -3
- package/types/src/lib/passthrough.d.mts +11 -17
- package/types/src/lib/pdf.d.mts +4 -18
- package/types/src/lib/ping.d.mts +1 -15
- package/types/src/lib/pool.d.mts +124 -0
- package/types/src/lib/route.d.mts +31 -24
- package/types/src/lib/routes.d.mts +10 -15
- package/types/src/lib/runtime.d.mts +2 -16
- package/types/src/lib/schema.d.mts +1 -15
- package/types/src/lib/settings.d.mts +68 -54
- package/types/src/lib/source.d.mts +2 -2
- package/types/src/lib/sse.d.mts +21 -32
- package/types/src/lib/thinking.d.mts +117 -22
- package/types/src/lib/tools.d.mts +28 -0
- package/types/src/lib/toolsearch.d.mts +91 -0
- package/types/src/lib/transport.d.mts +3 -16
- package/types/src/lib/upstream-error.d.mts +4 -18
- package/types/src/lib/usage.d.mts +91 -0
- package/types/src/lib/warn.d.mts +1 -1
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* -----
|
|
9
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
2
|
+
* Events for a stream reply committed before the upstream answered: the upstream's stream when it accepted, else its error
|
|
3
|
+
* as a final error event (the HTTP status is already 200, so the error travels in-band).
|
|
4
|
+
* @param {Promise<any>} sending - Pending `send` result.
|
|
5
|
+
* @param {any} api - Captured translator parts.
|
|
6
|
+
* @param {string} [model] - Model the client asked for (used in the early `message_start`).
|
|
7
|
+
* @returns {AsyncGenerator<any>} Client events.
|
|
14
8
|
*/
|
|
9
|
+
export function late(sending: Promise<any>, api: any, model?: string): AsyncGenerator<any>;
|
|
15
10
|
/**
|
|
16
11
|
* Register the routes for one front on a Fastify instance.
|
|
17
12
|
* @param {any} fastify - Fastify instance (usually an encapsulated plugin scope).
|
|
18
|
-
* @param {any} options - `{ apiKey, bodyLimit }`.
|
|
19
|
-
* @param {any} captured - Captured translator parts `{ front, interval, filter, send, count, list, build, encode, write }`; `front` applies to this instance only.
|
|
13
|
+
* @param {any} options - `{ apiKey, bodyLimit, authorize, onUsage }`.
|
|
14
|
+
* @param {any} captured - Captured translator parts `{ front, interval, filter, send, route, count, list, get, build, encode, write }`; `front` applies to this instance only.
|
|
20
15
|
* @returns {void}
|
|
21
16
|
*/
|
|
22
|
-
export
|
|
17
|
+
export function register(fastify: any, options: any, captured: any): void;
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/runtime.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:30:20-07:00 (1792956620)
|
|
6
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
-
* -----
|
|
9
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Per-instance context (`config`, `state`); valid only synchronously inside a leaf call.
|
|
17
3
|
* @type {any}
|
|
18
4
|
*/
|
|
19
|
-
export
|
|
5
|
+
export const context: any;
|
|
20
6
|
/**
|
|
21
7
|
* Proxy over the whole api (`self.convert.…`, `self.driver.…`); valid only synchronously inside a leaf call.
|
|
22
8
|
* @type {any}
|
|
23
9
|
*/
|
|
24
|
-
export
|
|
10
|
+
export const self: any;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/schema.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
6
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
-
* -----
|
|
9
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Return a sanitized deep copy of a JSON Schema: drops `$schema` and numeric bounds at or beyond +-(2^53 - 1)
|
|
17
3
|
* (Claude Code emits `maximum: 9007199254740991` on integers, which strict grammar backends dislike). The input is
|
|
@@ -19,4 +5,4 @@
|
|
|
19
5
|
* @param {unknown} schema - JSON Schema (or any JSON value found inside one).
|
|
20
6
|
* @returns {unknown} Sanitized copy.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function sanitize(schema: unknown): unknown;
|
|
@@ -1,16 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
2
|
+
* Merge settings layers (later layers win, `undefined` values are skipped, `pdf` merges key by key) and validate
|
|
3
|
+
* the enumerated keys. The result is a fresh object; inputs are never mutated.
|
|
4
|
+
* @param {...(Partial<Settings>|null|undefined)} layers - Layers in increasing precedence.
|
|
5
|
+
* @returns {Settings} Resolved settings.
|
|
6
|
+
*/
|
|
7
|
+
export function resolve(...layers: (Partial<Settings> | null | undefined)[]): Settings;
|
|
8
|
+
/**
|
|
9
|
+
* Settings understood by the converters. Every key is optional when passed in; `resolve()` fills the rest.
|
|
10
|
+
* @typedef {object} Settings
|
|
11
|
+
* @property {"auto"|"keep"|"hoist"|"user"|"drop"} inlineSystem - How mid-conversation `role:"system"` messages are handled. `user` folds them into the adjacent user turn as `<system-reminder>` text, `keep` forwards them as system messages, `hoist` appends them to the leading system message, `drop` discards them. `auto` behaves like `user` unless a driver probed the chat template and resolved it.
|
|
12
|
+
* @property {boolean} stripBillingHeader - Remove the `x-anthropic-billing-header` system block.
|
|
13
|
+
* @property {"reasoning"|"reasoning_content"} reasoningField - Field used when SENDING reasoning to an OpenAI-style server (reading accepts both).
|
|
14
|
+
* @property {boolean} thinkTags - Parse a leading `<think>...</think>` in content as reasoning.
|
|
15
|
+
* @property {boolean} thinkOpen - With `thinkTags`: the output starts inside a thought because the chat template opens `<think>` in the generation prompt, so reasoning runs up to the first `</think>`. Without a `</think>` the content is plain text.
|
|
16
|
+
* @property {boolean} reasoningRoundTrip - Carry reasoning the upstream needs back across turns. OpenAI-protocol upstream: the provider's reasoning fields (`reasoning_content`, `reasoning`, `reasoning_details`) travel in the thinking block's `llmt:` signature and are restored on the next request. Anthropic-protocol upstream with an OpenAI client: thinking blocks and their signatures travel as `reasoning_details` items the client replays. Off by default; the DeepSeek driver turns it on.
|
|
17
|
+
* @property {"chat_template_kwargs"|"reasoning_effort"|"none"} thinking - How Anthropic `thinking` is requested from the server.
|
|
18
|
+
* @property {boolean} thinkingBudget - Send `thinking_token_budget` for `thinking.type = "enabled"`.
|
|
19
|
+
* @property {boolean} effort - Map `output_config.effort` to `reasoning_effort`.
|
|
20
|
+
* @property {boolean} images - The model accepts images. When false images are replaced by a text note.
|
|
21
|
+
* @property {boolean} imageFallback - Retry a request once without images when an OpenAI-protocol upstream answers 400 that the model does not accept images, and remember that for the endpoint and model until the process ends.
|
|
22
|
+
* @property {boolean} toolFallback - Retry a request once without tools when an OpenAI-protocol upstream answers 400 that tool parsing is not enabled (vLLM started without `--enable-auto-tool-choice` and `--tool-call-parser`). Off by default: the request then runs without tools, which silently changes what the model can do.
|
|
23
|
+
* @property {"extract"|"note"|"error"} documents - How `document` blocks are handled.
|
|
24
|
+
* @property {((block: object, ctx: object) => Promise<object[]>|object[])|null} documentConverter - Override for `document` conversion; returns Anthropic content blocks.
|
|
25
|
+
* @property {{ pages: boolean, maxPages: number, maxBytes: number, maxImages: number, scale: number }} pdf - PDF handling: render page images, Anthropic-like limits, image budget and render scale.
|
|
26
|
+
* @property {"pass"|"sanitize"} toolSchema - Sanitize tool JSON Schemas (drop `$schema`, remove unbounded integer limits).
|
|
27
|
+
* @property {"forward"|"drop"} deferredTools - Offer `defer_loading` tools as `toolSearch` says, or drop them (and the search tool).
|
|
28
|
+
* @property {"expand"|"inline"|"native"} toolSearch - Claude Code's tool search. `expand` offers a deferred tool once a `tool_reference` (or a `ToolSearch` result) loads it; `inline` offers every deferred tool up front and hides `ToolSearch` (it stays when `DeferredToolPlaceholder` shows Claude Code holds tools whose definitions it did not send; `expand` does the same when the request has no `ToolSearch` at all); `native` passes `defer_loading` and `tool_reference` through to a server that understands them.
|
|
29
|
+
* @property {boolean} toolErrors - Prefix `is_error` tool results with `[error] `.
|
|
30
|
+
* @property {"max_completion_tokens"|"max_tokens"} maxTokensField - Field used for the output cap.
|
|
31
|
+
* @property {boolean} streamUsage - Request `stream_options.include_usage` on streamed requests.
|
|
32
|
+
* @property {boolean} continuousUsage - Also request `stream_options.continuous_usage_stats` (vLLM extension; real OpenAI may reject it).
|
|
33
|
+
* @property {"continue_final_message"|"none"} prefill - Map a trailing assistant message to `continue_final_message`.
|
|
34
|
+
* @property {boolean} topK - Forward `top_k`.
|
|
35
|
+
* @property {boolean} responseFormat - Map `output_config.format` to `response_format`.
|
|
36
|
+
* @property {boolean} parallelToolCalls - Map `disable_parallel_tool_use` to `parallel_tool_calls: false`.
|
|
37
|
+
* @property {"drop"|"error"} unknownFields - Unknown request fields are dropped (and listed in `state.dropped`) or rejected.
|
|
38
|
+
* @property {number} pingInterval - Milliseconds of upstream silence before the SSE writer emits a `ping` (0 disables).
|
|
39
|
+
* @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.
|
|
40
|
+
* @property {boolean} effortPassthrough - vLLM driver: send `xhigh` and `max` reasoning effort unchanged instead of clamping them to `high`.
|
|
41
|
+
* @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.
|
|
42
|
+
* @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.
|
|
43
|
+
* @property {number} defaultMaxTokens - `max_tokens` used when an OpenAI request has none (Anthropic requires one).
|
|
44
|
+
*/
|
|
45
|
+
/** @type {Readonly<Settings>} */
|
|
46
|
+
export const DEFAULTS: Readonly<Settings>;
|
|
47
|
+
/**
|
|
48
|
+
* Settings understood by the converters. Every key is optional when passed in; `resolve()` fills the rest.
|
|
14
49
|
*/
|
|
15
50
|
export type Settings = {
|
|
16
51
|
/**
|
|
@@ -29,6 +64,14 @@ export type Settings = {
|
|
|
29
64
|
* - Parse a leading `<think>...</think>` in content as reasoning.
|
|
30
65
|
*/
|
|
31
66
|
thinkTags: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* - With `thinkTags`: the output starts inside a thought because the chat template opens `<think>` in the generation prompt, so reasoning runs up to the first `</think>`. Without a `</think>` the content is plain text.
|
|
69
|
+
*/
|
|
70
|
+
thinkOpen: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* - Carry reasoning the upstream needs back across turns. OpenAI-protocol upstream: the provider's reasoning fields (`reasoning_content`, `reasoning`, `reasoning_details`) travel in the thinking block's `llmt:` signature and are restored on the next request. Anthropic-protocol upstream with an OpenAI client: thinking blocks and their signatures travel as `reasoning_details` items the client replays. Off by default; the DeepSeek driver turns it on.
|
|
73
|
+
*/
|
|
74
|
+
reasoningRoundTrip: boolean;
|
|
32
75
|
/**
|
|
33
76
|
* - How Anthropic `thinking` is requested from the server.
|
|
34
77
|
*/
|
|
@@ -49,6 +92,10 @@ export type Settings = {
|
|
|
49
92
|
* - Retry a request once without images when an OpenAI-protocol upstream answers 400 that the model does not accept images, and remember that for the endpoint and model until the process ends.
|
|
50
93
|
*/
|
|
51
94
|
imageFallback: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* - Retry a request once without tools when an OpenAI-protocol upstream answers 400 that tool parsing is not enabled (vLLM started without `--enable-auto-tool-choice` and `--tool-call-parser`). Off by default: the request then runs without tools, which silently changes what the model can do.
|
|
97
|
+
*/
|
|
98
|
+
toolFallback: boolean;
|
|
52
99
|
/**
|
|
53
100
|
* - How `document` blocks are handled.
|
|
54
101
|
*/
|
|
@@ -72,9 +119,13 @@ export type Settings = {
|
|
|
72
119
|
*/
|
|
73
120
|
toolSchema: "pass" | "sanitize";
|
|
74
121
|
/**
|
|
75
|
-
* -
|
|
122
|
+
* - Offer `defer_loading` tools as `toolSearch` says, or drop them (and the search tool).
|
|
76
123
|
*/
|
|
77
124
|
deferredTools: "forward" | "drop";
|
|
125
|
+
/**
|
|
126
|
+
* - Claude Code's tool search. `expand` offers a deferred tool once a `tool_reference` (or a `ToolSearch` result) loads it; `inline` offers every deferred tool up front and hides `ToolSearch` (it stays when `DeferredToolPlaceholder` shows Claude Code holds tools whose definitions it did not send; `expand` does the same when the request has no `ToolSearch` at all); `native` passes `defer_loading` and `tool_reference` through to a server that understands them.
|
|
127
|
+
*/
|
|
128
|
+
toolSearch: "expand" | "inline" | "native";
|
|
78
129
|
/**
|
|
79
130
|
* - Prefix `is_error` tool results with `[error] `.
|
|
80
131
|
*/
|
|
@@ -127,49 +178,12 @@ export type Settings = {
|
|
|
127
178
|
* - Restrict bodies forwarded from the OpenAI front to an OpenAI-protocol upstream to standard Chat Completions fields plus documented vLLM extensions. Off in the library; the server turns it on unless set to false.
|
|
128
179
|
*/
|
|
129
180
|
passthroughFilter: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* - 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.
|
|
183
|
+
*/
|
|
184
|
+
contextWindow: number;
|
|
130
185
|
/**
|
|
131
186
|
* - `max_tokens` used when an OpenAI request has none (Anthropic requires one).
|
|
132
187
|
*/
|
|
133
188
|
defaultMaxTokens: number;
|
|
134
189
|
};
|
|
135
|
-
/**
|
|
136
|
-
* Settings understood by the converters. Every key is optional when passed in; `resolve()` fills the rest.
|
|
137
|
-
* @typedef {object} Settings
|
|
138
|
-
* @property {"auto"|"keep"|"hoist"|"user"|"drop"} inlineSystem - How mid-conversation `role:"system"` messages are handled. `user` folds them into the adjacent user turn as `<system-reminder>` text, `keep` forwards them as system messages, `hoist` appends them to the leading system message, `drop` discards them. `auto` behaves like `user` unless a driver probed the chat template and resolved it.
|
|
139
|
-
* @property {boolean} stripBillingHeader - Remove the `x-anthropic-billing-header` system block.
|
|
140
|
-
* @property {"reasoning"|"reasoning_content"} reasoningField - Field used when SENDING reasoning to an OpenAI-style server (reading accepts both).
|
|
141
|
-
* @property {boolean} thinkTags - Parse a leading `<think>...</think>` in content as reasoning.
|
|
142
|
-
* @property {"chat_template_kwargs"|"reasoning_effort"|"none"} thinking - How Anthropic `thinking` is requested from the server.
|
|
143
|
-
* @property {boolean} thinkingBudget - Send `thinking_token_budget` for `thinking.type = "enabled"`.
|
|
144
|
-
* @property {boolean} effort - Map `output_config.effort` to `reasoning_effort`.
|
|
145
|
-
* @property {boolean} images - The model accepts images. When false images are replaced by a text note.
|
|
146
|
-
* @property {boolean} imageFallback - Retry a request once without images when an OpenAI-protocol upstream answers 400 that the model does not accept images, and remember that for the endpoint and model until the process ends.
|
|
147
|
-
* @property {"extract"|"note"|"error"} documents - How `document` blocks are handled.
|
|
148
|
-
* @property {((block: object, ctx: object) => Promise<object[]>|object[])|null} documentConverter - Override for `document` conversion; returns Anthropic content blocks.
|
|
149
|
-
* @property {{ pages: boolean, maxPages: number, maxBytes: number, maxImages: number, scale: number }} pdf - PDF handling: render page images, Anthropic-like limits, image budget and render scale.
|
|
150
|
-
* @property {"pass"|"sanitize"} toolSchema - Sanitize tool JSON Schemas (drop `$schema`, remove unbounded integer limits).
|
|
151
|
-
* @property {"forward"|"drop"} deferredTools - Forward `defer_loading` tools as plain function tools or drop them.
|
|
152
|
-
* @property {boolean} toolErrors - Prefix `is_error` tool results with `[error] `.
|
|
153
|
-
* @property {"max_completion_tokens"|"max_tokens"} maxTokensField - Field used for the output cap.
|
|
154
|
-
* @property {boolean} streamUsage - Request `stream_options.include_usage` on streamed requests.
|
|
155
|
-
* @property {boolean} continuousUsage - Also request `stream_options.continuous_usage_stats` (vLLM extension; real OpenAI may reject it).
|
|
156
|
-
* @property {"continue_final_message"|"none"} prefill - Map a trailing assistant message to `continue_final_message`.
|
|
157
|
-
* @property {boolean} topK - Forward `top_k`.
|
|
158
|
-
* @property {boolean} responseFormat - Map `output_config.format` to `response_format`.
|
|
159
|
-
* @property {boolean} parallelToolCalls - Map `disable_parallel_tool_use` to `parallel_tool_calls: false`.
|
|
160
|
-
* @property {"drop"|"error"} unknownFields - Unknown request fields are dropped (and listed in `state.dropped`) or rejected.
|
|
161
|
-
* @property {number} pingInterval - Milliseconds of upstream silence before the SSE writer emits a `ping` (0 disables).
|
|
162
|
-
* @property {"buffer"|"stream"} toolStreaming - OpenAI to Anthropic streams: `buffer` holds each tool call until its arguments are complete and emits one whole `tool_use` block (text and thinking keep streaming and appear before the block); `stream` forwards argument fragments incrementally and holds text that arrives meanwhile until the tool blocks are done.
|
|
163
|
-
* @property {boolean} effortPassthrough - vLLM driver: send `xhigh` and `max` reasoning effort unchanged instead of clamping them to `high`.
|
|
164
|
-
* @property {boolean} passthroughFilter - Restrict bodies forwarded from the OpenAI front to an OpenAI-protocol upstream to standard Chat Completions fields plus documented vLLM extensions. Off in the library; the server turns it on unless set to false.
|
|
165
|
-
* @property {number} defaultMaxTokens - `max_tokens` used when an OpenAI request has none (Anthropic requires one).
|
|
166
|
-
*/
|
|
167
|
-
/** @type {Readonly<Settings>} */
|
|
168
|
-
export declare const DEFAULTS: Readonly<Settings>;
|
|
169
|
-
/**
|
|
170
|
-
* Merge settings layers (later layers win, `undefined` values are skipped, `pdf` merges key by key) and validate
|
|
171
|
-
* the enumerated keys. The result is a fresh object; inputs are never mutated.
|
|
172
|
-
* @param {...(Partial<Settings>|null|undefined)} layers - Layers in increasing precedence.
|
|
173
|
-
* @returns {Settings} Resolved settings.
|
|
174
|
-
*/
|
|
175
|
-
export declare function resolve(...layers: (Partial<Settings> | null | undefined)[]): Settings;
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
* @param {ReadableStream|AsyncIterable<unknown>|Iterable<unknown>|string|Uint8Array|any} source - Input source.
|
|
23
23
|
* @returns {AsyncGenerator<any, void, undefined>} Raw items in order.
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export function items(source: ReadableStream | AsyncIterable<unknown> | Iterable<unknown> | string | Uint8Array | any): AsyncGenerator<any, void, undefined>;
|
|
26
26
|
/**
|
|
27
27
|
* Iterate a source as decoded text. Strings pass through, `Uint8Array` chunks are decoded as streaming UTF-8
|
|
28
28
|
* (multi-byte characters may span chunks).
|
|
29
29
|
* @param {ReadableStream|AsyncIterable<string|Uint8Array>|Iterable<string|Uint8Array>|string|Uint8Array} source - Input source.
|
|
30
30
|
* @returns {AsyncGenerator<string, void, undefined>} Text chunks.
|
|
31
31
|
*/
|
|
32
|
-
export
|
|
32
|
+
export function text(source: ReadableStream | AsyncIterable<string | Uint8Array> | Iterable<string | Uint8Array> | string | Uint8Array): AsyncGenerator<string, void, undefined>;
|
package/types/src/lib/sse.d.mts
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/sse.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:28:19-07:00 (1792956499)
|
|
6
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
-
* -----
|
|
9
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export type SseEvent = {
|
|
16
|
-
/**
|
|
17
|
-
* - Event name.
|
|
18
|
-
*/
|
|
19
|
-
event?: string;
|
|
20
|
-
/**
|
|
21
|
-
* - Data lines joined with `\n`.
|
|
22
|
-
*/
|
|
23
|
-
data: string;
|
|
24
|
-
/**
|
|
25
|
-
* - Event id (applies to the event it is sent with only).
|
|
26
|
-
*/
|
|
27
|
-
id?: string;
|
|
28
|
-
};
|
|
29
1
|
/**
|
|
30
2
|
* A parsed SSE event.
|
|
31
3
|
* @typedef {object} SseEvent
|
|
@@ -38,7 +10,7 @@ export type SseEvent = {
|
|
|
38
10
|
* `data:` fields and chunk boundaries anywhere (including inside a line or a line terminator).
|
|
39
11
|
* @returns {{ push: (chunk: string) => SseEvent[], flush: () => SseEvent[] }} Parser.
|
|
40
12
|
*/
|
|
41
|
-
export
|
|
13
|
+
export function createParser(): {
|
|
42
14
|
push: (chunk: string) => SseEvent[];
|
|
43
15
|
flush: () => SseEvent[];
|
|
44
16
|
};
|
|
@@ -47,14 +19,14 @@ export declare function createParser(): {
|
|
|
47
19
|
* @param {ReadableStream|AsyncIterable<string|Uint8Array>|Iterable<string|Uint8Array>|string|Uint8Array} source - SSE bytes or text.
|
|
48
20
|
* @returns {AsyncGenerator<SseEvent, void, undefined>} Parsed events.
|
|
49
21
|
*/
|
|
50
|
-
export
|
|
22
|
+
export function parse(source: ReadableStream | AsyncIterable<string | Uint8Array> | Iterable<string | Uint8Array> | string | Uint8Array): AsyncGenerator<SseEvent, void, undefined>;
|
|
51
23
|
/**
|
|
52
24
|
* Encode one event as SSE text. Object `data` is JSON-encoded; string `data` is written as is (multi-line strings
|
|
53
25
|
* become several `data:` lines).
|
|
54
26
|
* @param {{ event?: string, data: unknown, id?: string }} message - Event to encode.
|
|
55
27
|
* @returns {string} SSE frame terminated by a blank line.
|
|
56
28
|
*/
|
|
57
|
-
export
|
|
29
|
+
export function encode({ event, data, id }: {
|
|
58
30
|
event?: string;
|
|
59
31
|
data: unknown;
|
|
60
32
|
id?: string;
|
|
@@ -66,7 +38,24 @@ export declare function encode({ event, data, id }: {
|
|
|
66
38
|
* @param {ReadableStream|AsyncIterable<any>|Iterable<any>|string|Uint8Array} source - Stream input.
|
|
67
39
|
* @returns {AsyncGenerator<{ event?: string, data: any }, void, undefined>} Messages.
|
|
68
40
|
*/
|
|
69
|
-
export
|
|
41
|
+
export function messages(source: ReadableStream | AsyncIterable<any> | Iterable<any> | string | Uint8Array): AsyncGenerator<{
|
|
70
42
|
event?: string;
|
|
71
43
|
data: any;
|
|
72
44
|
}, void, undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* A parsed SSE event.
|
|
47
|
+
*/
|
|
48
|
+
export type SseEvent = {
|
|
49
|
+
/**
|
|
50
|
+
* - Event name.
|
|
51
|
+
*/
|
|
52
|
+
event?: string;
|
|
53
|
+
/**
|
|
54
|
+
* - Data lines joined with `\n`.
|
|
55
|
+
*/
|
|
56
|
+
data: string;
|
|
57
|
+
/**
|
|
58
|
+
* - Event id (applies to the event it is sent with only).
|
|
59
|
+
*/
|
|
60
|
+
id?: string;
|
|
61
|
+
};
|
|
@@ -1,54 +1,142 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Create the signature attached to a thinking block produced from upstream reasoning. It is clearly marked as not coming from Anthropic.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Create the signature attached to a thinking block produced from upstream reasoning. It is clearly marked as not
|
|
17
|
-
* coming from Anthropic.
|
|
4
|
+
* Format: `llmt:` followed by the base64url of a JSON payload `{"v":1}`, or `{"v":1,"p":"<producer>","d":{...}}` when provider reasoning data has to
|
|
5
|
+
* come back with the block. `p` names the driver and protocol that produced the data (so it is restored only for the same producer) and `d` holds
|
|
6
|
+
* one text field (`reasoning_content` or `reasoning`) and/or `reasoning_details`. A payload longer than 512 bytes is deflated and written
|
|
7
|
+
* as `llmt:~` plus base64url, unless that would not shrink it or would exceed the 30:1 inflation ratio {@link unsign} accepts. Data that
|
|
8
|
+
* {@link unsign} would reject (over the size limits, unknown shape) or a result over 256 KiB leaves the plain marker.
|
|
9
|
+
* @param {{ reasoning_content?: string, reasoning?: string, reasoning_details?: object[] }} [data] - Provider reasoning data to carry.
|
|
10
|
+
* @param {string} [producer] - Producer binding, `driver:protocol:host`.
|
|
18
11
|
* @returns {string} Signature string.
|
|
19
12
|
*/
|
|
20
|
-
export
|
|
13
|
+
export function sign(data?: {
|
|
14
|
+
reasoning_content?: string;
|
|
15
|
+
reasoning?: string;
|
|
16
|
+
reasoning_details?: object[];
|
|
17
|
+
}, producer?: string): string;
|
|
21
18
|
/**
|
|
22
19
|
* Whether a signature was produced by {@link sign}.
|
|
23
20
|
* @param {unknown} signature - Signature value.
|
|
24
|
-
* @returns {
|
|
21
|
+
* @returns {signature is string} True for translator-made signatures.
|
|
22
|
+
*/
|
|
23
|
+
export function isOurs(signature: unknown): signature is string;
|
|
24
|
+
/**
|
|
25
|
+
* The limits on decoding signatures within one request, shared by every conversion of it (retries and failover included): how many bytes may be
|
|
26
|
+
* inflated or decoded in total, how many marked signatures may be decoded, and how many decodes may fail before decoding stops for the rest of the
|
|
27
|
+
* request. Bytes are charged before a signature is inflated (the most it could produce) and refunded down to what it did produce, so a signature that
|
|
28
|
+
* fails still costs. Results are cached by producer and signature, so converting the same request again costs nothing. Once the budget is spent the
|
|
29
|
+
* caller falls back to the thinking text.
|
|
30
|
+
* Decodes on one budget run one at a time (each waits for the one before it), so concurrent callers cannot get past the checks together.
|
|
31
|
+
* @returns {{ bytes: number, signatures: number, failures: number, cache: Map<string, any>, queue: Promise<void> }} A fresh budget for one request.
|
|
32
|
+
*/
|
|
33
|
+
export function createBudget(): {
|
|
34
|
+
bytes: number;
|
|
35
|
+
signatures: number;
|
|
36
|
+
failures: number;
|
|
37
|
+
cache: Map<string, any>;
|
|
38
|
+
queue: Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Read the provider reasoning data out of a signature made by {@link sign}. Strict: the signature must carry the mark, be within the size
|
|
42
|
+
* limits and decode to `{"v":1,"p":...,"d":{...}}` with only the known fields, each well formed, and its producer must equal `producer`
|
|
43
|
+
* (a payload with no producer is returned only when none is given). Anything else (a real Anthropic signature, a plain marker, a forged, garbled or
|
|
44
|
+
* foreign one) gives null and the caller falls back to the thinking text. Inflation is bounded while it runs: by 1 MiB per signature, by the rest of
|
|
45
|
+
* the per-request budget, and by a 30:1 ratio of output to compressed input, so a small signature cannot expand into a large allocation; after a few
|
|
46
|
+
* failed decodes the rest of the request is not decoded at all. Calls that share a budget are queued, so they are safe to make concurrently.
|
|
47
|
+
* @param {unknown} signature - Signature value from a thinking block.
|
|
48
|
+
* @param {{ producer?: string, budget?: ReturnType<typeof createBudget> }} [options] - `producer` is the current `driver:protocol:host`; `budget` is shared by all signatures of one request (see {@link createBudget}).
|
|
49
|
+
* @returns {Promise<{ reasoning_content?: string, reasoning?: string, reasoning_details?: object[] } | null>} The data, or null.
|
|
50
|
+
*/
|
|
51
|
+
export function unsign(signature: unknown, { producer, budget }?: {
|
|
52
|
+
producer?: string;
|
|
53
|
+
budget?: ReturnType<typeof createBudget>;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
reasoning_content?: string;
|
|
56
|
+
reasoning?: string;
|
|
57
|
+
reasoning_details?: object[];
|
|
58
|
+
} | null>;
|
|
59
|
+
/**
|
|
60
|
+
* The `reasoning_details` item for an Anthropic thinking block or redacted thinking block, in the form an OpenAI client replays.
|
|
61
|
+
* @param {any} block - Anthropic `thinking` or `redacted_thinking` content block (with its signature or data).
|
|
62
|
+
* @param {number} index - Position among what the OpenAI message shows: 0 before the text (or before the first tool call when there is no text), 1 after the text and before the first tool call, then one more for each tool call. Empty text does not count as text.
|
|
63
|
+
* @returns {object | null} The item, or null for a block that cannot be replayed (no signature or data).
|
|
25
64
|
*/
|
|
26
|
-
export
|
|
65
|
+
export function detailOf(block: any, index: number): object | null;
|
|
66
|
+
/**
|
|
67
|
+
* Anthropic thinking and redacted thinking blocks from the `reasoning_details` an OpenAI client replayed. Strict: only items in this
|
|
68
|
+
* translator's Anthropic format with the expected string fields become blocks, only their known fields are copied, and at most 64 items
|
|
69
|
+
* totalling 1 MiB of text are taken; anything else is ignored.
|
|
70
|
+
* @param {unknown} details - `reasoning_details` of an assistant message.
|
|
71
|
+
* @returns {{ at: number, block: any }[]} Anthropic content blocks with the position (`index`) they had in the original message, which the caller uses to keep thinking in place between the text and the tool calls (possibly empty).
|
|
72
|
+
*/
|
|
73
|
+
export function blocksOf(details: unknown): {
|
|
74
|
+
at: number;
|
|
75
|
+
block: any;
|
|
76
|
+
}[];
|
|
77
|
+
/**
|
|
78
|
+
* Which field of an OpenAI message or delta carries its reasoning text (`reasoning` or the older `reasoning_content`), if any.
|
|
79
|
+
* @param {{ reasoning?: unknown, reasoning_content?: unknown }|undefined} part - Message or delta.
|
|
80
|
+
* @returns {"reasoning"|"reasoning_content"|null} Field name.
|
|
81
|
+
*/
|
|
82
|
+
export function reasoningKey(part: {
|
|
83
|
+
reasoning?: unknown;
|
|
84
|
+
reasoning_content?: unknown;
|
|
85
|
+
} | undefined): "reasoning" | "reasoning_content" | null;
|
|
86
|
+
/**
|
|
87
|
+
* Add a streamed `reasoning_details` fragment to the list being built, so a stream yields the same items as a JSON reply. Fragments with the
|
|
88
|
+
* same `index` and `type` are one item: `text` and `summary` are concatenated and `signature`, `data`, `format` and `id` are taken from the
|
|
89
|
+
* fragment that carries them. A fragment without an `index`, or a new one, is appended; anything that is not an object is skipped.
|
|
90
|
+
* @param {any[]} list - Items so far (mutated).
|
|
91
|
+
* @param {any} fragment - One element of a streamed `reasoning_details` array.
|
|
92
|
+
* @returns {any[]} The same list.
|
|
93
|
+
*/
|
|
94
|
+
export function mergeDetail(list: any[], fragment: any): any[];
|
|
95
|
+
/**
|
|
96
|
+
* Readable text of a `reasoning_details` list (`reasoning.text` and `reasoning.summary` items), for a thinking block whose reasoning
|
|
97
|
+
* arrived only as structured details.
|
|
98
|
+
* @param {unknown} details - `reasoning_details` value.
|
|
99
|
+
* @returns {string} Concatenated text ("" for encrypted-only details).
|
|
100
|
+
*/
|
|
101
|
+
export function detailsText(details: unknown): string;
|
|
27
102
|
/**
|
|
28
103
|
* Reasoning text carried by an OpenAI message or delta (`reasoning` or the older `reasoning_content`).
|
|
29
104
|
* @param {{ reasoning?: unknown, reasoning_content?: unknown }|undefined} part - Message or delta.
|
|
30
105
|
* @returns {string} Reasoning text ("" when absent).
|
|
31
106
|
*/
|
|
32
|
-
export
|
|
107
|
+
export function reasoningOf(part: {
|
|
33
108
|
reasoning?: unknown;
|
|
34
109
|
reasoning_content?: unknown;
|
|
35
110
|
} | undefined): string;
|
|
36
111
|
/**
|
|
37
112
|
* Split a complete content string into reasoning and answer. Only a LEADING `<think>...</think>` is recognised
|
|
38
113
|
* (whitespace before it and after it is ignored); an unterminated `<think>` treats everything as reasoning.
|
|
114
|
+
*
|
|
115
|
+
* With `open` the output is taken to start inside a thought (the chat template already wrote `<think>` into the
|
|
116
|
+
* generation prompt): everything before the first `</think>` is reasoning. When no `</think>` appears the whole
|
|
117
|
+
* content is answer text. A literal leading `<think>` is still honoured.
|
|
39
118
|
* @param {string} content - Full message content.
|
|
119
|
+
* @param {boolean} [open] - The output starts inside a thought.
|
|
40
120
|
* @returns {{ reasoning: string, text: string }} Split result.
|
|
41
121
|
*/
|
|
42
|
-
export
|
|
122
|
+
export function splitThink(content: string, open?: boolean): {
|
|
43
123
|
reasoning: string;
|
|
44
124
|
text: string;
|
|
45
125
|
};
|
|
46
126
|
/**
|
|
47
127
|
* Incremental version of {@link splitThink} for streamed content. Feed content deltas to `push()` and call `end()`
|
|
48
128
|
* once; each call returns `{ reasoning, text }` pieces that are safe to emit now (partial tags are held back).
|
|
49
|
-
*
|
|
129
|
+
*
|
|
130
|
+
* With `open` (see {@link splitThink}) nothing is emitted until the first `</think>` arrives, because only then is it known
|
|
131
|
+
* that the content so far was reasoning; if the stream ends first, everything held is released as answer text.
|
|
132
|
+
* @param {boolean} [open] - The output starts inside a thought.
|
|
133
|
+
*
|
|
134
|
+
* `release()` stops splitting: anything held is returned as text and all later content passes through as text (used once the server
|
|
135
|
+
* sends reasoning in its own field, when content is never split). `pending()` is true while, with `open`, it is not yet known whether
|
|
136
|
+
* the content so far is reasoning.
|
|
137
|
+
* @returns {{ push: (delta: string) => { reasoning: string, text: string }, end: () => { reasoning: string, text: string }, release: () => { reasoning: string, text: string }, pending: () => boolean }} Splitter.
|
|
50
138
|
*/
|
|
51
|
-
export
|
|
139
|
+
export function createThinkSplitter(open?: boolean): {
|
|
52
140
|
push: (delta: string) => {
|
|
53
141
|
reasoning: string;
|
|
54
142
|
text: string;
|
|
@@ -57,4 +145,11 @@ export declare function createThinkSplitter(): {
|
|
|
57
145
|
reasoning: string;
|
|
58
146
|
text: string;
|
|
59
147
|
};
|
|
148
|
+
release: () => {
|
|
149
|
+
reasoning: string;
|
|
150
|
+
text: string;
|
|
151
|
+
};
|
|
152
|
+
pending: () => boolean;
|
|
60
153
|
};
|
|
154
|
+
/** `format` of the `reasoning_details` items that carry an Anthropic thinking block (text with its signature) or redacted thinking (data). */
|
|
155
|
+
export const ANTHROPIC_FORMAT: "anthropic-claude-v1";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hint for a refusal. When `toolFallback` is already on, suggesting it would be wrong (the retry has been spent), so only the restart advice remains.
|
|
3
|
+
* A refusal that names `--jinja` is llama.cpp's and gets its own advice.
|
|
4
|
+
* @param {boolean} toolFallback - Whether the `toolFallback` setting is on for the endpoint.
|
|
5
|
+
* @param {string} [message] - The upstream error message being hinted.
|
|
6
|
+
* @returns {string} Hint text.
|
|
7
|
+
*/
|
|
8
|
+
export function hint(toolFallback: boolean, message?: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Does an upstream error message say the server has no tool parser configured?
|
|
11
|
+
* @param {string} message - Upstream error message.
|
|
12
|
+
* @returns {boolean} True for a known "tool parsing not enabled" wording.
|
|
13
|
+
*/
|
|
14
|
+
export function refused(message: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Does a Chat Completions body carry tools?
|
|
17
|
+
* @param {any} body - Upstream request body.
|
|
18
|
+
* @returns {boolean} True when `tools` is a non-empty array.
|
|
19
|
+
*/
|
|
20
|
+
export function carries(body: any): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Copy a Chat Completions body without `tools`, `tool_choice` and `parallel_tool_calls`.
|
|
23
|
+
* @param {any} body - Upstream request body.
|
|
24
|
+
* @returns {any} New body.
|
|
25
|
+
*/
|
|
26
|
+
export function strip(body: any): any;
|
|
27
|
+
/** Added to the error message the client receives when the upstream refuses tools for want of a tool parser. */
|
|
28
|
+
export const HINT: "The vLLM server was started without tool-call parsing. Restart it with --enable-auto-tool-choice and --tool-call-parser <parser> (the parser depends on the model family), or set the translator setting toolFallback to retry without tools.";
|