@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find what the conversation has already loaded: tools named by `tool_reference` blocks, tools the assistant has called, tools a `ToolSearch`
|
|
3
|
+
* call selected by name (`select:A,B`, so a result that was cleared from a trimmed history does not unload them), and tools defined in
|
|
4
|
+
* `<function>` lines of `ToolSearch` results. Only `ToolSearch` results are read, and none for a `tool_use` id that appears on more than one
|
|
5
|
+
* call, so no other tool's output can add a tool. A definition that exists only in a result that history trimming removed is gone with it:
|
|
6
|
+
* the name stays in `loaded`, and `plan` copes with the missing definition.
|
|
7
|
+
* @param {any[]} messages - Anthropic messages.
|
|
8
|
+
* @param {Set<string>} [known] - Names of the tools the request lists; their definitions are not kept (the listed one wins) and do not count against the cap.
|
|
9
|
+
* @returns {{loaded: string[], searched: string[], called: string[], failed: string[], defined: Map<string, any>, capped: boolean}} Loaded names in order of first appearance, the names tool search itself loaded (selected, referenced or defined by a result; calling a tool is not evidence), names the assistant called, those of them whose every call came back as an error, the definitions found in results and whether `LIMITS.definitions` turned one away.
|
|
10
|
+
*/
|
|
11
|
+
export function scan(messages: any[], known?: Set<string>): {
|
|
12
|
+
loaded: string[];
|
|
13
|
+
searched: string[];
|
|
14
|
+
called: string[];
|
|
15
|
+
failed: string[];
|
|
16
|
+
defined: Map<string, any>;
|
|
17
|
+
capped: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Decide which tools a request offers.
|
|
21
|
+
*
|
|
22
|
+
* - `expand`: tools without `defer_loading` in request order, then the deferred tools the conversation has loaded (or `tool_choice` names), in
|
|
23
|
+
* the order they were first loaded, so the list only ever grows at its end. `ToolSearch` is offered while there is something left to load.
|
|
24
|
+
* - `inline`: every tool except the placeholder, in request order, then the tools a `ToolSearch` result defined in text; `ToolSearch` is offered only when the placeholder shows that Claude Code holds
|
|
25
|
+
* tools whose definitions it did not send. `expand` behaves like `inline` when the request has neither a `ToolSearch` nor the placeholder.
|
|
26
|
+
* - `native`: every tool as sent; the server is expected to understand `defer_loading` and `tool_reference`.
|
|
27
|
+
*
|
|
28
|
+
* A tool a `ToolSearch` result defined in text and that the request does not list is offered after the others (`expand` only).
|
|
29
|
+
* `deferredTools: "drop"` leaves the deferred tools to the caller to drop and hides `ToolSearch`, which would have nothing to load.
|
|
30
|
+
* @param {any[]} tools - Anthropic tools of the request.
|
|
31
|
+
* @param {{loaded: string[], searched: string[], called: string[], failed: string[], defined: Map<string, any>}} found - Result of `scan`.
|
|
32
|
+
* @param {{toolSearch: "expand" | "inline" | "native", deferredTools: "forward" | "drop"}} s - Settings.
|
|
33
|
+
* @param {any} [choice] - The request's `tool_choice`.
|
|
34
|
+
* A tool tool search loaded (selected, referenced or defined by a result) whose definition is no longer anywhere (its `ToolSearch` result was trimmed) keeps `ToolSearch` offered so the
|
|
35
|
+
* model can search again, and one the assistant already called is offered with an empty object schema (`TRIMMED`) so its calls in the history
|
|
36
|
+
* still map to a tool.
|
|
37
|
+
* @returns {{offer: any[], loaded: string[], hidden: string[], stubbed: string[]}} Tools to convert, names of the deferred tools that are loaded, the names left out on purpose and the names of tools offered with a placeholder schema.
|
|
38
|
+
*/
|
|
39
|
+
export function plan(tools: any[], found: {
|
|
40
|
+
loaded: string[];
|
|
41
|
+
searched: string[];
|
|
42
|
+
called: string[];
|
|
43
|
+
failed: string[];
|
|
44
|
+
defined: Map<string, any>;
|
|
45
|
+
}, s: {
|
|
46
|
+
toolSearch: "expand" | "inline" | "native";
|
|
47
|
+
deferredTools: "forward" | "drop";
|
|
48
|
+
}, choice?: any): {
|
|
49
|
+
offer: any[];
|
|
50
|
+
loaded: string[];
|
|
51
|
+
hidden: string[];
|
|
52
|
+
stubbed: string[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @Project: @cldmv/llm-translator
|
|
57
|
+
* @Filename: /src/lib/toolsearch.mjs
|
|
58
|
+
* @Date: 2026-10-26T06:00:20-07:00 (1793019620)
|
|
59
|
+
* @Author: Nate Corcoran <CLDMV>
|
|
60
|
+
* @Email: <Shinrai@users.noreply.github.com>
|
|
61
|
+
* -----
|
|
62
|
+
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
63
|
+
* @Last modified time: 2026-10-26T15:38:55-07:00 (1793054335)
|
|
64
|
+
* -----
|
|
65
|
+
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* @fileoverview Claude Code's tool search: which tools a request offers when some are deferred.
|
|
70
|
+
*
|
|
71
|
+
* Claude Code marks tools it does not want to send up front with `defer_loading: true`, lists their names in a system reminder, and
|
|
72
|
+
* gives the model a client tool, `ToolSearch`, whose result names the tools to load: as `tool_reference` blocks, and as `<function>`
|
|
73
|
+
* JSON lines in the result text. A reserved `DeferredToolPlaceholder` tool (also deferred, "never call this tool") keeps the feature
|
|
74
|
+
* active. Anthropic's API expands the references into real tool definitions; an OpenAI-style server cannot, so the translator does it
|
|
75
|
+
* by changing the tools list of the next request.
|
|
76
|
+
* @module @cldmv/llm-translator/lib/toolsearch
|
|
77
|
+
*/
|
|
78
|
+
/** The client tool the model calls to load deferred tools. */
|
|
79
|
+
export const SEARCH_TOOL: "ToolSearch";
|
|
80
|
+
/** The reserved deferred tool that is never offered. */
|
|
81
|
+
export const PLACEHOLDER_TOOL: "DeferredToolPlaceholder";
|
|
82
|
+
/** Limits on definitions read from `ToolSearch` result text, which the model's tools list is built from: count in a conversation (only definitions of tools the request does not list count), characters per definition, name, description and serialized schema. */
|
|
83
|
+
export const LIMITS: Readonly<{
|
|
84
|
+
definitions: 512;
|
|
85
|
+
line: 131072;
|
|
86
|
+
name: 256;
|
|
87
|
+
description: 16384;
|
|
88
|
+
schema: 65536;
|
|
89
|
+
}>;
|
|
90
|
+
/** Description of a tool whose definition was trimmed from the conversation. */
|
|
91
|
+
export const TRIMMED: "The definition of this tool was trimmed from the conversation; use ToolSearch to see its parameters.";
|
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/transport.mjs
|
|
5
|
-
* @Date: 2026-10-25T21:38:02-07:00 (1792989482)
|
|
6
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
-
* -----
|
|
9
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-10-26T15:38:58-07:00 (1793054338)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* `fetch`-style request.
|
|
17
3
|
* @param {string|URL} url - Absolute http(s) URL.
|
|
18
|
-
* @param {{ method?: string, headers?: Record<string, string>, body?: string|Uint8Array, signal?: AbortSignal, redirect?: string }} [init] - Request options.
|
|
4
|
+
* @param {{ method?: string, headers?: Record<string, string>, body?: string|Uint8Array, signal?: AbortSignal, redirect?: string, connectTimeout?: number }} [init] - Request options.
|
|
19
5
|
* @param {{ http: any, https: any }} [modules] - Protocol modules (overridable for tests).
|
|
20
6
|
* @returns {Promise<Response>} Response whose `body` is a web `ReadableStream`.
|
|
21
7
|
*/
|
|
22
|
-
export
|
|
8
|
+
export function transport(url: string | URL, init?: {
|
|
23
9
|
method?: string;
|
|
24
10
|
headers?: Record<string, string>;
|
|
25
11
|
body?: string | Uint8Array;
|
|
26
12
|
signal?: AbortSignal;
|
|
27
13
|
redirect?: string;
|
|
14
|
+
connectTimeout?: number;
|
|
28
15
|
}, modules?: {
|
|
29
16
|
http: any;
|
|
30
17
|
https: any;
|
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @Project: @cldmv/llm-translator
|
|
4
|
-
* @Filename: /src/lib/upstream-error.mjs
|
|
5
|
-
* @Date: 2026-10-25T12:29:36-07:00 (1792956576)
|
|
6
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
-
* -----
|
|
9
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-10-25T12:59:02-07:00 (1792958342)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
1
|
/**
|
|
16
2
|
* Anthropic error type for an HTTP status.
|
|
17
3
|
* @param {number} status - HTTP status.
|
|
18
4
|
* @returns {string} Anthropic `error.type`.
|
|
19
5
|
*/
|
|
20
|
-
export
|
|
6
|
+
export function anthropicType(status: number): string;
|
|
21
7
|
/**
|
|
22
8
|
* OpenAI error type for an HTTP status.
|
|
23
9
|
* @param {number} status - HTTP status.
|
|
24
10
|
* @returns {string} OpenAI `error.type`.
|
|
25
11
|
*/
|
|
26
|
-
export
|
|
12
|
+
export function openaiType(status: number): string;
|
|
27
13
|
/**
|
|
28
14
|
* Pull `{ message, type, code, param }` out of any known upstream error body shape: nested OpenAI/vLLM
|
|
29
15
|
* (`{error:{message,type,param,code}}`), flat old vLLM (`{message,type,param,code}`), Anthropic
|
|
@@ -32,7 +18,7 @@ export declare function openaiType(status: number): string;
|
|
|
32
18
|
* @param {number} status - HTTP status, used for the fallback message.
|
|
33
19
|
* @returns {{message: string, type?: string, code?: *, param?: *}} Normalized error.
|
|
34
20
|
*/
|
|
35
|
-
export
|
|
21
|
+
export function parse(body: any, status: number): {
|
|
36
22
|
message: string;
|
|
37
23
|
type?: string;
|
|
38
24
|
code?: any;
|
|
@@ -46,7 +32,7 @@ export declare function parse(body: any, status: number): {
|
|
|
46
32
|
* @param {any} [options] - `{ native: boolean }`: keep the upstream `type` when it is already valid for this protocol.
|
|
47
33
|
* @returns {{status: number, body: any}} Status and body in the client shape.
|
|
48
34
|
*/
|
|
49
|
-
export
|
|
35
|
+
export function render(front: "anthropic" | "openai", status: number, info: {
|
|
50
36
|
message: string;
|
|
51
37
|
type?: string;
|
|
52
38
|
code?: any;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a usage object. Fields the source did not carry stay null: unknown is never reported as 0.
|
|
3
|
+
* @param {"anthropic" | "openai" | "folded"} protocol - Shape of `usage`: Anthropic (`input_tokens`, ...), OpenAI (`prompt_tokens`, ...) or `folded` (Anthropic, reported the way the OpenAI front does).
|
|
4
|
+
* @param {any} usage - A `usage` object.
|
|
5
|
+
* @returns {Record<string, number | null> | null} Normalized counts, or null when there is no usage (an absent object, or all zeros, which a
|
|
6
|
+
* converter writes when the upstream reported nothing and no real reply has).
|
|
7
|
+
*/
|
|
8
|
+
export function normalize(protocol: "anthropic" | "openai" | "folded", usage: any): Record<string, number | null> | null;
|
|
9
|
+
/**
|
|
10
|
+
* Create the meter for one request.
|
|
11
|
+
* @param {{front: "anthropic" | "openai", requested: string | null, model: string | null, upstream: string | null, stream: boolean}} meta - Request facts; `model` and `upstream` may be filled in later.
|
|
12
|
+
* @param {((report: UsageReport) => any) | undefined} onUsage - Caller's callback.
|
|
13
|
+
* @param {(message: string) => void} warn - Receives a message when `onUsage` throws or rejects.
|
|
14
|
+
* @returns {{meta: any, usage: Promise<UsageReport>, json: (body: any) => void, event: (data: any) => void, finish: (reason: UsageReport["reason"]) => void, estimate: (counts: {input_tokens: number | null, output_tokens: number | null}) => void, source: (read: (() => any) | null, protocol?: "openai" | "folded") => void, track: (source: AsyncIterable<any>, signal?: AbortSignal, hide?: boolean) => any}} Meter.
|
|
15
|
+
*/
|
|
16
|
+
export function meter(meta: {
|
|
17
|
+
front: "anthropic" | "openai";
|
|
18
|
+
requested: string | null;
|
|
19
|
+
model: string | null;
|
|
20
|
+
upstream: string | null;
|
|
21
|
+
stream: boolean;
|
|
22
|
+
}, onUsage: ((report: UsageReport) => any) | undefined, warn: (message: string) => void): {
|
|
23
|
+
meta: any;
|
|
24
|
+
usage: Promise<UsageReport>;
|
|
25
|
+
json: (body: any) => void;
|
|
26
|
+
event: (data: any) => void;
|
|
27
|
+
finish: (reason: UsageReport["reason"]) => void;
|
|
28
|
+
estimate: (counts: {
|
|
29
|
+
input_tokens: number | null;
|
|
30
|
+
output_tokens: number | null;
|
|
31
|
+
}) => void;
|
|
32
|
+
source: (read: (() => any) | null, protocol?: "openai" | "folded") => void;
|
|
33
|
+
track: (source: AsyncIterable<any>, signal?: AbortSignal, hide?: boolean) => any;
|
|
34
|
+
};
|
|
35
|
+
export type UsageReport = {
|
|
36
|
+
/**
|
|
37
|
+
* - Prompt tokens that were not served from cache, or null when unknown.
|
|
38
|
+
*/
|
|
39
|
+
input_tokens: number | null;
|
|
40
|
+
/**
|
|
41
|
+
* - Completion tokens, or null when unknown.
|
|
42
|
+
*/
|
|
43
|
+
output_tokens: number | null;
|
|
44
|
+
/**
|
|
45
|
+
* - Prompt tokens served from cache, or null when unknown.
|
|
46
|
+
*/
|
|
47
|
+
cache_read_input_tokens: number | null;
|
|
48
|
+
/**
|
|
49
|
+
* - Prompt tokens written to cache, or null when unknown.
|
|
50
|
+
*/
|
|
51
|
+
cache_creation_input_tokens: number | null;
|
|
52
|
+
/**
|
|
53
|
+
* - True when the reply carried usage; false means every token field is null.
|
|
54
|
+
*/
|
|
55
|
+
reported: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* - The estimates written into the client reply for the sides the upstream did not report (a side the upstream did report is null here); null when nothing was estimated (the upstream reported both sides, a pass-through reply, a reply that failed first). Never mixed into the token fields.
|
|
58
|
+
*/
|
|
59
|
+
estimated: {
|
|
60
|
+
input_tokens: number | null;
|
|
61
|
+
output_tokens: number | null;
|
|
62
|
+
} | null;
|
|
63
|
+
/**
|
|
64
|
+
* - True only when the reply finished normally.
|
|
65
|
+
*/
|
|
66
|
+
complete: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* - Why the report was produced.
|
|
69
|
+
*/
|
|
70
|
+
reason: "done" | "aborted" | "error" | "upstream_error";
|
|
71
|
+
/**
|
|
72
|
+
* - Model name sent upstream.
|
|
73
|
+
*/
|
|
74
|
+
model: string | null;
|
|
75
|
+
/**
|
|
76
|
+
* - Model the client asked for.
|
|
77
|
+
*/
|
|
78
|
+
requested: string | null;
|
|
79
|
+
/**
|
|
80
|
+
* - Upstream endpoint name.
|
|
81
|
+
*/
|
|
82
|
+
upstream: string | null;
|
|
83
|
+
/**
|
|
84
|
+
* - Client protocol.
|
|
85
|
+
*/
|
|
86
|
+
front: "anthropic" | "openai";
|
|
87
|
+
/**
|
|
88
|
+
* - Whether the client asked for a stream.
|
|
89
|
+
*/
|
|
90
|
+
stream: boolean;
|
|
91
|
+
};
|
package/types/src/lib/warn.d.mts
CHANGED
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
* @param {string} message - Warning text.
|
|
24
24
|
* @returns {boolean} True when the warning was printed.
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export function warn(config: any, state: any, message: string): boolean;
|