@zpi-dev/agent-sdk 0.0.0-stage → 0.1.60
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/NOTICE +1206 -0
- package/README.md +54 -2
- package/dist/chunk-4WFFCN2C.js +29607 -0
- package/dist/chunk-4WFFCN2C.js.map +1 -0
- package/dist/chunk-AR5RMMMN.js +24353 -0
- package/dist/chunk-AR5RMMMN.js.map +1 -0
- package/dist/chunk-RAZL7ZAW.js +13451 -0
- package/dist/chunk-RAZL7ZAW.js.map +1 -0
- package/dist/chunk-TUOZKHGN.js +21 -0
- package/dist/chunk-TUOZKHGN.js.map +1 -0
- package/dist/chunk-YBW5XDR7.js +48 -0
- package/dist/chunk-YBW5XDR7.js.map +1 -0
- package/dist/host.d.ts +1 -0
- package/dist/host.js +34 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/node-WXHENNL2.js +21 -0
- package/dist/node-WXHENNL2.js.map +1 -0
- package/dist/node-XSTAMDFW.js +2225 -0
- package/dist/node-XSTAMDFW.js.map +1 -0
- package/dist/src-7WDJXP5P.js +128 -0
- package/dist/src-7WDJXP5P.js.map +1 -0
- package/dist/types/agent/src/agent-loop.d.ts +3 -0
- package/dist/types/agent/src/agent.d.ts +21 -0
- package/dist/types/agent/src/index.d.ts +3 -0
- package/dist/types/agent/src/streaming-tool-coordinator.d.ts +10 -0
- package/dist/types/agent/src/tool-execution.d.ts +9 -0
- package/dist/types/agent/src/types.d.ts +144 -0
- package/dist/types/agent-sdk/src/hooks.d.ts +12 -0
- package/dist/types/agent-sdk/src/host.d.ts +4 -0
- package/dist/types/agent-sdk/src/index.d.ts +4 -0
- package/dist/types/agent-sdk/src/messages.d.ts +12 -0
- package/dist/types/agent-sdk/src/permissions.d.ts +10 -0
- package/dist/types/agent-sdk/src/query-result.d.ts +7 -0
- package/dist/types/agent-sdk/src/query.d.ts +6 -0
- package/dist/types/agent-sdk/src/resources.d.ts +16 -0
- package/dist/types/agent-sdk/src/runtime.d.ts +7 -0
- package/dist/types/agent-sdk/src/sessions.d.ts +48 -0
- package/dist/types/agent-sdk/src/tasks.d.ts +8 -0
- package/dist/types/agent-sdk/src/tools.d.ts +5 -0
- package/dist/types/agent-sdk/src/types.d.ts +428 -0
- package/dist/types/ai/src/api/anthropic-messages.d.ts +70 -0
- package/dist/types/ai/src/api/constrained-sampling.d.ts +5 -0
- package/dist/types/ai/src/api/github-copilot-headers.d.ts +7 -0
- package/dist/types/ai/src/api/openai-completions.d.ts +10 -0
- package/dist/types/ai/src/api/openai-responses.d.ts +5 -0
- package/dist/types/ai/src/api/responses-cache.d.ts +6 -0
- package/dist/types/ai/src/api/responses-events.d.ts +3 -0
- package/dist/types/ai/src/api/responses-session.d.ts +56 -0
- package/dist/types/ai/src/api/simple-options.d.ts +14 -0
- package/dist/types/ai/src/api/transform-messages.d.ts +3 -0
- package/dist/types/ai/src/auth/openai-chatgpt.d.ts +32 -0
- package/dist/types/ai/src/index.d.ts +20 -0
- package/dist/types/ai/src/providers/discovery.d.ts +14 -0
- package/dist/types/ai/src/providers/registry.d.ts +155 -0
- package/dist/types/ai/src/stream.d.ts +5 -0
- package/dist/types/ai/src/types.d.ts +394 -0
- package/dist/types/ai/src/utils/abort.d.ts +2 -0
- package/dist/types/ai/src/utils/context-breakdown.d.ts +3 -0
- package/dist/types/ai/src/utils/cost.d.ts +2 -0
- package/dist/types/ai/src/utils/diagnostics.d.ts +16 -0
- package/dist/types/ai/src/utils/error-body.d.ts +24 -0
- package/dist/types/ai/src/utils/estimate.d.ts +16 -0
- package/dist/types/ai/src/utils/event-stream.d.ts +15 -0
- package/dist/types/ai/src/utils/guard-model-stream.d.ts +3 -0
- package/dist/types/ai/src/utils/headers.d.ts +1 -0
- package/dist/types/ai/src/utils/json-parse.d.ts +7 -0
- package/dist/types/ai/src/utils/media-policy.d.ts +68 -0
- package/dist/types/ai/src/utils/model-performance.d.ts +23 -0
- package/dist/types/ai/src/utils/model-retry.d.ts +3 -0
- package/dist/types/ai/src/utils/option-map/compiler.d.ts +2 -0
- package/dist/types/ai/src/utils/option-map/evaluator.d.ts +3 -0
- package/dist/types/ai/src/utils/option-map/parser.d.ts +40 -0
- package/dist/types/ai/src/utils/option-map/tokenizer.d.ts +8 -0
- package/dist/types/ai/src/utils/option-map/types.d.ts +15 -0
- package/dist/types/ai/src/utils/overflow.d.ts +68 -0
- package/dist/types/ai/src/utils/provider-cache.d.ts +11 -0
- package/dist/types/ai/src/utils/provider-env.d.ts +2 -0
- package/dist/types/ai/src/utils/provider-retry.d.ts +17 -0
- package/dist/types/ai/src/utils/reasoning.d.ts +14 -0
- package/dist/types/ai/src/utils/redact-error.d.ts +2 -0
- package/dist/types/ai/src/utils/retry.d.ts +62 -0
- package/dist/types/ai/src/utils/sanitize-unicode.d.ts +21 -0
- package/dist/types/ai/src/utils/stream-idle-timeout.d.ts +36 -0
- package/dist/types/ai/src/utils/text.d.ts +9 -0
- package/dist/types/ai/src/utils/transcript.d.ts +41 -0
- package/dist/types/coding-agent/src/core/agent-session.d.ts +174 -0
- package/dist/types/coding-agent/src/core/commands.d.ts +19 -0
- package/dist/types/coding-agent/src/core/compaction-utils.d.ts +37 -0
- package/dist/types/coding-agent/src/core/compaction.d.ts +139 -0
- package/dist/types/coding-agent/src/core/file-rewind.d.ts +24 -0
- package/dist/types/coding-agent/src/core/fs.d.ts +1 -0
- package/dist/types/coding-agent/src/core/http-idle-timeout.d.ts +2 -0
- package/dist/types/coding-agent/src/core/image-limits.d.ts +19 -0
- package/dist/types/coding-agent/src/core/images.d.ts +18 -0
- package/dist/types/coding-agent/src/core/input.d.ts +3 -0
- package/dist/types/coding-agent/src/core/markdown-code.d.ts +7 -0
- package/dist/types/coding-agent/src/core/markdown.d.ts +13 -0
- package/dist/types/coding-agent/src/core/mentions.d.ts +12 -0
- package/dist/types/coding-agent/src/core/microcompact.d.ts +40 -0
- package/dist/types/coding-agent/src/core/model-performance.d.ts +57 -0
- package/dist/types/coding-agent/src/core/model-runtime.d.ts +51 -0
- package/dist/types/coding-agent/src/core/read-file-bounded.d.ts +2 -0
- package/dist/types/coding-agent/src/core/record-validation.d.ts +6 -0
- package/dist/types/coding-agent/src/core/resources.d.ts +51 -0
- package/dist/types/coding-agent/src/core/sdk.d.ts +50 -0
- package/dist/types/coding-agent/src/core/session-manager.d.ts +137 -0
- package/dist/types/coding-agent/src/core/session-state.d.ts +14 -0
- package/dist/types/coding-agent/src/core/settings-manager.d.ts +41 -0
- package/dist/types/coding-agent/src/core/streaming-tool-journal.d.ts +17 -0
- package/dist/types/coding-agent/src/core/system-prompt.d.ts +25 -0
- package/dist/types/coding-agent/src/core/tools/file-change.d.ts +21 -0
- package/dist/types/coding-agent/src/core/tools/index.d.ts +20 -0
- package/dist/types/coding-agent/src/core/tools/pi/bash.d.ts +185 -0
- package/dist/types/coding-agent/src/core/tools/pi/edit-diff.d.ts +84 -0
- package/dist/types/coding-agent/src/core/tools/pi/edit.d.ts +69 -0
- package/dist/types/coding-agent/src/core/tools/pi/file-mutation-queue.d.ts +5 -0
- package/dist/types/coding-agent/src/core/tools/pi/file-read-state.d.ts +12 -0
- package/dist/types/coding-agent/src/core/tools/pi/output-accumulator.d.ts +68 -0
- package/dist/types/coding-agent/src/core/tools/pi/path-utils.d.ts +7 -0
- package/dist/types/coding-agent/src/core/tools/pi/read.d.ts +63 -0
- package/dist/types/coding-agent/src/core/tools/pi/text-range-reader.d.ts +22 -0
- package/dist/types/coding-agent/src/core/tools/pi/tool-definition-wrapper.d.ts +4 -0
- package/dist/types/coding-agent/src/core/tools/pi/truncate.d.ts +60 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/bmp-source.d.ts +2 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/child-process.d.ts +13 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/image-budget.d.ts +16 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/image-process.d.ts +18 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/image-resize-core.d.ts +26 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/image-resize.d.ts +3 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/image-source.d.ts +11 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/mime.d.ts +3 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/paths.d.ts +16 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/read-file.d.ts +2 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/shell.d.ts +18 -0
- package/dist/types/coding-agent/src/core/tools/pi/utils/text.d.ts +5 -0
- package/dist/types/coding-agent/src/core/tools/pi/write.d.ts +44 -0
- package/dist/types/coding-agent/src/core/transcript-store.d.ts +71 -0
- package/dist/types/coding-agent/src/core/types.d.ts +60 -0
- package/dist/types/coding-agent/src/index.d.ts +42 -0
- package/dist/types/coding-agent/src/plugins/assembly.d.ts +37 -0
- package/dist/types/coding-agent/src/plugins/hooks.d.ts +82 -0
- package/dist/types/coding-agent/src/plugins/resources.d.ts +4 -0
- package/dist/types/coding-agent/src/plugins/session-hooks.d.ts +26 -0
- package/dist/types/coding-agent/src/plugins/types.d.ts +40 -0
- package/dist/types/plugin-compat/src/command-hooks.d.ts +184 -0
- package/dist/types/plugin-compat/src/index.d.ts +11 -0
- package/package.json +53 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProviderApi } from "../types.js";
|
|
2
|
+
import type { DiscoveredModel, ProviderPresetId } from "./registry.js";
|
|
3
|
+
export interface ModelDiscoveryInput {
|
|
4
|
+
preset?: ProviderPresetId;
|
|
5
|
+
api?: ProviderApi;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ModelDiscoveryResult {
|
|
10
|
+
models: DiscoveredModel[];
|
|
11
|
+
source: "remote" | "catalog";
|
|
12
|
+
warning?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function fetchProviderModels(input: ModelDiscoveryInput, fetcher?: typeof fetch): Promise<ModelDiscoveryResult>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { Model, ModelCompat, ProviderApi } from "../types.js";
|
|
2
|
+
export interface DiscoveredModel {
|
|
3
|
+
id: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
input?: ("text" | "image" | "video" | "pdf")[];
|
|
6
|
+
reasoning?: boolean;
|
|
7
|
+
contextWindow?: number;
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
compat?: ModelCompat;
|
|
10
|
+
thinkingLevelMap?: Model["thinkingLevelMap"];
|
|
11
|
+
defaultThinkingLevel?: Model["defaultThinkingLevel"];
|
|
12
|
+
availability?: "listed" | "unverified";
|
|
13
|
+
samplingParams?: Model["samplingParams"];
|
|
14
|
+
metadataSource?: "remote" | "catalog" | "defaults";
|
|
15
|
+
}
|
|
16
|
+
export declare const providerPresets: readonly [{
|
|
17
|
+
readonly id: "openai-chatgpt";
|
|
18
|
+
readonly name: "OpenAI(ChatGPT)";
|
|
19
|
+
readonly family: "openai";
|
|
20
|
+
readonly baseUrl: "https://api.openai.com/v1";
|
|
21
|
+
readonly envKeys: readonly [];
|
|
22
|
+
readonly catalog: "openai-chatgpt";
|
|
23
|
+
}, {
|
|
24
|
+
readonly id: "openai-api";
|
|
25
|
+
readonly name: "OpenAI(API)";
|
|
26
|
+
readonly family: "openai";
|
|
27
|
+
readonly baseUrl: "https://api.openai.com/v1";
|
|
28
|
+
readonly envKeys: readonly ["OPENAI_API_KEY"];
|
|
29
|
+
readonly catalog: "openai-chatgpt";
|
|
30
|
+
}, {
|
|
31
|
+
readonly id: "deepseek";
|
|
32
|
+
readonly name: "DeepSeek";
|
|
33
|
+
readonly family: "deepseek";
|
|
34
|
+
readonly baseUrl: "https://api.deepseek.com";
|
|
35
|
+
readonly envKeys: readonly ["DEEPSEEK_API_KEY"];
|
|
36
|
+
readonly catalog: "deepseek";
|
|
37
|
+
}, {
|
|
38
|
+
readonly id: "zhipu-coding";
|
|
39
|
+
readonly name: "智谱(Coding Plan)";
|
|
40
|
+
readonly family: "zhipu";
|
|
41
|
+
readonly baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4";
|
|
42
|
+
readonly envKeys: readonly ["ZHIPU_API_KEY", "ZHIPU_CODING_API_KEY", "ZAI_CODING_CN_API_KEY"];
|
|
43
|
+
readonly catalog: "zai-coding-cn";
|
|
44
|
+
}, {
|
|
45
|
+
readonly id: "zhipu-api";
|
|
46
|
+
readonly name: "智谱(API)";
|
|
47
|
+
readonly family: "zhipu";
|
|
48
|
+
readonly baseUrl: "https://open.bigmodel.cn/api/paas/v4";
|
|
49
|
+
readonly envKeys: readonly ["ZHIPU_PAYGO_API_KEY", "ZHIPU_STANDARD_API_KEY"];
|
|
50
|
+
readonly catalog: "zai";
|
|
51
|
+
}, {
|
|
52
|
+
readonly id: "minimax-coding";
|
|
53
|
+
readonly name: "MiniMax(Coding Plan)";
|
|
54
|
+
readonly family: "minimax";
|
|
55
|
+
readonly baseUrl: "https://api.minimax.cn/v1";
|
|
56
|
+
readonly envKeys: readonly ["MINIMAX_API_KEY"];
|
|
57
|
+
readonly catalog: "minimax-cn";
|
|
58
|
+
}, {
|
|
59
|
+
readonly id: "minimax-api";
|
|
60
|
+
readonly name: "MiniMax(API)";
|
|
61
|
+
readonly family: "minimax";
|
|
62
|
+
readonly baseUrl: "https://api.minimax.cn/v1";
|
|
63
|
+
readonly envKeys: readonly ["MINIMAX_PAYGO_API_KEY"];
|
|
64
|
+
readonly catalog: "minimax-cn";
|
|
65
|
+
}, {
|
|
66
|
+
readonly id: "mimo-coding";
|
|
67
|
+
readonly name: "MiMo(Token Plan)";
|
|
68
|
+
readonly family: "mimo";
|
|
69
|
+
readonly baseUrl: "https://token-plan-cn.xiaomimimo.com/v1";
|
|
70
|
+
readonly envKeys: readonly ["MIMO_API_KEY", "XIAOMI_TOKEN_PLAN_CN_API_KEY"];
|
|
71
|
+
readonly catalog: "xiaomi-token-plan-cn";
|
|
72
|
+
}, {
|
|
73
|
+
readonly id: "mimo-api";
|
|
74
|
+
readonly name: "MiMo(API)";
|
|
75
|
+
readonly family: "mimo";
|
|
76
|
+
readonly baseUrl: "https://api.xiaomimimo.com/v1";
|
|
77
|
+
readonly envKeys: readonly ["MIMO_PAYGO_API_KEY", "XIAOMI_API_KEY"];
|
|
78
|
+
readonly catalog: "xiaomi";
|
|
79
|
+
}];
|
|
80
|
+
export type ProviderPresetId = (typeof providerPresets)[number]["id"];
|
|
81
|
+
export declare function getProviderPreset(id: string): {
|
|
82
|
+
readonly id: "openai-chatgpt";
|
|
83
|
+
readonly name: "OpenAI(ChatGPT)";
|
|
84
|
+
readonly family: "openai";
|
|
85
|
+
readonly baseUrl: "https://api.openai.com/v1";
|
|
86
|
+
readonly envKeys: readonly [];
|
|
87
|
+
readonly catalog: "openai-chatgpt";
|
|
88
|
+
} | {
|
|
89
|
+
readonly id: "openai-api";
|
|
90
|
+
readonly name: "OpenAI(API)";
|
|
91
|
+
readonly family: "openai";
|
|
92
|
+
readonly baseUrl: "https://api.openai.com/v1";
|
|
93
|
+
readonly envKeys: readonly ["OPENAI_API_KEY"];
|
|
94
|
+
readonly catalog: "openai-chatgpt";
|
|
95
|
+
} | {
|
|
96
|
+
readonly id: "deepseek";
|
|
97
|
+
readonly name: "DeepSeek";
|
|
98
|
+
readonly family: "deepseek";
|
|
99
|
+
readonly baseUrl: "https://api.deepseek.com";
|
|
100
|
+
readonly envKeys: readonly ["DEEPSEEK_API_KEY"];
|
|
101
|
+
readonly catalog: "deepseek";
|
|
102
|
+
} | {
|
|
103
|
+
readonly id: "zhipu-coding";
|
|
104
|
+
readonly name: "智谱(Coding Plan)";
|
|
105
|
+
readonly family: "zhipu";
|
|
106
|
+
readonly baseUrl: "https://open.bigmodel.cn/api/coding/paas/v4";
|
|
107
|
+
readonly envKeys: readonly ["ZHIPU_API_KEY", "ZHIPU_CODING_API_KEY", "ZAI_CODING_CN_API_KEY"];
|
|
108
|
+
readonly catalog: "zai-coding-cn";
|
|
109
|
+
} | {
|
|
110
|
+
readonly id: "zhipu-api";
|
|
111
|
+
readonly name: "智谱(API)";
|
|
112
|
+
readonly family: "zhipu";
|
|
113
|
+
readonly baseUrl: "https://open.bigmodel.cn/api/paas/v4";
|
|
114
|
+
readonly envKeys: readonly ["ZHIPU_PAYGO_API_KEY", "ZHIPU_STANDARD_API_KEY"];
|
|
115
|
+
readonly catalog: "zai";
|
|
116
|
+
} | {
|
|
117
|
+
readonly id: "minimax-coding";
|
|
118
|
+
readonly name: "MiniMax(Coding Plan)";
|
|
119
|
+
readonly family: "minimax";
|
|
120
|
+
readonly baseUrl: "https://api.minimax.cn/v1";
|
|
121
|
+
readonly envKeys: readonly ["MINIMAX_API_KEY"];
|
|
122
|
+
readonly catalog: "minimax-cn";
|
|
123
|
+
} | {
|
|
124
|
+
readonly id: "minimax-api";
|
|
125
|
+
readonly name: "MiniMax(API)";
|
|
126
|
+
readonly family: "minimax";
|
|
127
|
+
readonly baseUrl: "https://api.minimax.cn/v1";
|
|
128
|
+
readonly envKeys: readonly ["MINIMAX_PAYGO_API_KEY"];
|
|
129
|
+
readonly catalog: "minimax-cn";
|
|
130
|
+
} | {
|
|
131
|
+
readonly id: "mimo-coding";
|
|
132
|
+
readonly name: "MiMo(Token Plan)";
|
|
133
|
+
readonly family: "mimo";
|
|
134
|
+
readonly baseUrl: "https://token-plan-cn.xiaomimimo.com/v1";
|
|
135
|
+
readonly envKeys: readonly ["MIMO_API_KEY", "XIAOMI_TOKEN_PLAN_CN_API_KEY"];
|
|
136
|
+
readonly catalog: "xiaomi-token-plan-cn";
|
|
137
|
+
} | {
|
|
138
|
+
readonly id: "mimo-api";
|
|
139
|
+
readonly name: "MiMo(API)";
|
|
140
|
+
readonly family: "mimo";
|
|
141
|
+
readonly baseUrl: "https://api.xiaomimimo.com/v1";
|
|
142
|
+
readonly envKeys: readonly ["MIMO_PAYGO_API_KEY", "XIAOMI_API_KEY"];
|
|
143
|
+
readonly catalog: "xiaomi";
|
|
144
|
+
} | undefined;
|
|
145
|
+
export declare function presetModels(id: string, api?: ProviderApi): DiscoveredModel[];
|
|
146
|
+
export declare function usesChatGPTAuth(preset?: string): boolean;
|
|
147
|
+
export declare function isLegacyOpenAIModel(id: string): boolean;
|
|
148
|
+
export declare function providerApis(preset?: string): readonly ProviderApi[];
|
|
149
|
+
export declare function providerApi(preset?: string, api?: ProviderApi): ProviderApi;
|
|
150
|
+
export declare function providerBaseUrl(preset: string, api?: ProviderApi): string;
|
|
151
|
+
export declare function discoverProviderCredentials(env: Record<string, string | undefined>): {
|
|
152
|
+
preset: "deepseek" | "mimo-api" | "mimo-coding" | "minimax-api" | "minimax-coding" | "openai-api" | "openai-chatgpt" | "zhipu-api" | "zhipu-coding";
|
|
153
|
+
envKey: "DEEPSEEK_API_KEY" | "MIMO_API_KEY" | "MIMO_PAYGO_API_KEY" | "MINIMAX_API_KEY" | "MINIMAX_PAYGO_API_KEY" | "OPENAI_API_KEY" | "XIAOMI_API_KEY" | "XIAOMI_TOKEN_PLAN_CN_API_KEY" | "ZAI_CODING_CN_API_KEY" | "ZHIPU_API_KEY" | "ZHIPU_CODING_API_KEY" | "ZHIPU_PAYGO_API_KEY" | "ZHIPU_STANDARD_API_KEY";
|
|
154
|
+
apiKey: string;
|
|
155
|
+
}[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Model, SimpleStreamOptions, TranscriptContext } from "./types.js";
|
|
2
|
+
/** Provider and wire-protocol selection stays inside zpi-ai. Credentials resolve for every request. */
|
|
3
|
+
export declare function streamSimple(model: Model, context: TranscriptContext, options?: SimpleStreamOptions & {
|
|
4
|
+
getApiKey?: (rejectedApiKey?: string) => Promise<string>;
|
|
5
|
+
}): import("./types.js").AssistantMessageEventStream;
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import type { TSchema } from "typebox";
|
|
2
|
+
import type { AssistantMessageEventStream } from "./utils/event-stream.js";
|
|
3
|
+
export type { AssistantMessageEventStream } from "./utils/event-stream.js";
|
|
4
|
+
export type ProviderApi = "anthropic-messages" | "openai-completions" | "openai-responses";
|
|
5
|
+
export type Api = ProviderApi | (string & {});
|
|
6
|
+
export type CacheRetention = "none" | "short" | "long";
|
|
7
|
+
export type ProviderEnv = Record<string, string>;
|
|
8
|
+
export type ProviderHeaders = Record<string, string | null>;
|
|
9
|
+
export interface ThinkingBudgets {
|
|
10
|
+
minimal?: number;
|
|
11
|
+
low?: number;
|
|
12
|
+
medium?: number;
|
|
13
|
+
high?: number;
|
|
14
|
+
}
|
|
15
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | JsonObject;
|
|
16
|
+
export type JsonObject = {
|
|
17
|
+
[key: string]: JsonValue;
|
|
18
|
+
};
|
|
19
|
+
export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | (string & {});
|
|
20
|
+
export interface ReasoningConfig {
|
|
21
|
+
levels: string[];
|
|
22
|
+
map: string;
|
|
23
|
+
}
|
|
24
|
+
export interface OpenAICompletionsCompat {
|
|
25
|
+
thinkingFormat?: "deepseek" | "zai";
|
|
26
|
+
structuredOutput?: "prompt" | "json_object" | "json_schema";
|
|
27
|
+
maxTokensField?: "max_tokens" | "max_completion_tokens";
|
|
28
|
+
supportsDeveloperRole?: boolean;
|
|
29
|
+
supportsReasoningEffort?: boolean;
|
|
30
|
+
supportsUsageInStreaming?: boolean;
|
|
31
|
+
requiresReasoningContentOnAssistantMessages?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare const openAICompletionsCompatKeys: readonly ["thinkingFormat", "structuredOutput", "maxTokensField", "supportsDeveloperRole", "supportsReasoningEffort", "supportsUsageInStreaming", "requiresReasoningContentOnAssistantMessages"];
|
|
34
|
+
/** Compatibility settings for Anthropic Messages-compatible APIs. */
|
|
35
|
+
export interface AnthropicMessagesCompat {
|
|
36
|
+
/**
|
|
37
|
+
* Whether the provider accepts per-tool `eager_input_streaming`.
|
|
38
|
+
* When false, the Anthropic provider omits `tools[].eager_input_streaming`
|
|
39
|
+
* and sends the legacy `fine-grained-tool-streaming-2025-05-14` beta header
|
|
40
|
+
* for tool-enabled requests.
|
|
41
|
+
* Default: true.
|
|
42
|
+
*/
|
|
43
|
+
supportsEagerToolInputStreaming?: boolean;
|
|
44
|
+
/** Whether the provider supports Anthropic long cache retention (`cache_control.ttl: "1h"`). Default: true. */
|
|
45
|
+
supportsLongCacheRetention?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to send the `x-session-affinity` header from `options.sessionId`
|
|
48
|
+
* when caching is enabled. Required for providers like Fireworks that use
|
|
49
|
+
* session affinity for prompt cache routing (requests to the same replica
|
|
50
|
+
* maximize cache hits).
|
|
51
|
+
* Default: false.
|
|
52
|
+
*/
|
|
53
|
+
sendSessionAffinityHeaders?: boolean;
|
|
54
|
+
/** Session-affinity format. `"openrouter"` sends `x-session-id`; when unset, sends `x-session-affinity`. */
|
|
55
|
+
sessionAffinityFormat?: "openrouter";
|
|
56
|
+
/**
|
|
57
|
+
* Whether the provider supports Anthropic-style `cache_control` markers on
|
|
58
|
+
* tool definitions. When false, `cache_control` is omitted from tool params.
|
|
59
|
+
* Some Anthropic-compatible providers (e.g., Fireworks) do not support this
|
|
60
|
+
* field on tools and may reject or ignore it.
|
|
61
|
+
* Default: true.
|
|
62
|
+
*/
|
|
63
|
+
supportsCacheControlOnTools?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the model accepts the Anthropic `temperature` request field.
|
|
66
|
+
* Claude Opus 4.7+ rejects non-default temperature values.
|
|
67
|
+
* Default: true.
|
|
68
|
+
*/
|
|
69
|
+
supportsTemperature?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether to force adaptive thinking (`thinking.type: "adaptive"` plus
|
|
72
|
+
* `output_config.effort`) regardless of the model id. Built-in models that
|
|
73
|
+
* require adaptive thinking set this in generated metadata. Custom
|
|
74
|
+
* Anthropic-compatible providers can set this to `true` for any model whose
|
|
75
|
+
* upstream requires the adaptive format. Set to `false` to
|
|
76
|
+
* opt out on overridden built-in models.
|
|
77
|
+
* Default: false.
|
|
78
|
+
*/
|
|
79
|
+
forceAdaptiveThinking?: boolean;
|
|
80
|
+
/** Whether to replay empty thinking signatures as `signature: ""` instead of converting thinking to text. Default: false. */
|
|
81
|
+
allowEmptySignature?: boolean;
|
|
82
|
+
/** Whether the provider supports Anthropic strict tool schemas. Default: false; generated Anthropic models enable it explicitly. */
|
|
83
|
+
supportsStrictTools?: boolean;
|
|
84
|
+
/** Whether the exact model transport supports effort-only system messages and thinking binding controls. Default: false. */
|
|
85
|
+
supportsMidConvoEffort?: boolean;
|
|
86
|
+
/** Whether the exact model accepts system-role messages inside the conversation. When false, later system messages are folded into the top-level system prompt. Default: false. */
|
|
87
|
+
supportsMidConvoSystemMessages?: boolean;
|
|
88
|
+
/** Whether the exact model accepts mid-conversation `tool_addition` and `tool_removal` blocks. Requires `supportsMidConvoSystemMessages`. Default: false. */
|
|
89
|
+
supportsMidConvoToolChanges?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Models Anthropic accepts in `fallbacks` for server-side refusal fallback,
|
|
92
|
+
* with local pricing metadata for returned fallback responses. When absent or
|
|
93
|
+
* empty, callers must omit `fallbacks`; Anthropic rejects the field for models
|
|
94
|
+
* with no permitted fallback targets.
|
|
95
|
+
*/
|
|
96
|
+
allowedFallbackModels?: AnthropicAllowedFallbackModel[];
|
|
97
|
+
}
|
|
98
|
+
export interface AnthropicAllowedFallbackModel {
|
|
99
|
+
provider: string;
|
|
100
|
+
model: string;
|
|
101
|
+
cost: Model["cost"];
|
|
102
|
+
}
|
|
103
|
+
export type ModelCompat = OpenAICompletionsCompat & AnthropicMessagesCompat;
|
|
104
|
+
export declare const anthropicMessagesCompatKeys: readonly ["supportsEagerToolInputStreaming", "supportsLongCacheRetention", "sendSessionAffinityHeaders", "sessionAffinityFormat", "supportsCacheControlOnTools", "supportsTemperature", "forceAdaptiveThinking", "allowEmptySignature", "supportsStrictTools", "supportsMidConvoEffort", "supportsMidConvoSystemMessages", "supportsMidConvoToolChanges", "allowedFallbackModels"];
|
|
105
|
+
export interface Model<TApi extends Api = Api> {
|
|
106
|
+
id: string;
|
|
107
|
+
name: string;
|
|
108
|
+
api: TApi;
|
|
109
|
+
provider: string;
|
|
110
|
+
baseUrl: string;
|
|
111
|
+
auth?: "chatgpt";
|
|
112
|
+
input: ("text" | "image")[];
|
|
113
|
+
reasoning: boolean;
|
|
114
|
+
cost: {
|
|
115
|
+
input: number;
|
|
116
|
+
output: number;
|
|
117
|
+
cacheRead: number;
|
|
118
|
+
cacheWrite: number;
|
|
119
|
+
tiers?: {
|
|
120
|
+
inputTokensAbove: number;
|
|
121
|
+
input: number;
|
|
122
|
+
output: number;
|
|
123
|
+
cacheRead: number;
|
|
124
|
+
cacheWrite: number;
|
|
125
|
+
}[];
|
|
126
|
+
};
|
|
127
|
+
contextWindow: number;
|
|
128
|
+
maxTokens: number;
|
|
129
|
+
headers?: Record<string, string>;
|
|
130
|
+
compat?: ModelCompat;
|
|
131
|
+
thinkingLevelMap?: Partial<Record<"off" | ThinkingLevel, string | JsonObject | null>>;
|
|
132
|
+
reasoningConfig?: ReasoningConfig;
|
|
133
|
+
defaultThinkingLevel?: "off" | ThinkingLevel;
|
|
134
|
+
samplingParams?: Record<string, unknown>;
|
|
135
|
+
}
|
|
136
|
+
export interface TextContent {
|
|
137
|
+
type: "text";
|
|
138
|
+
text: string;
|
|
139
|
+
textSignature?: string;
|
|
140
|
+
phase?: "commentary" | "partial_answer" | "final_answer";
|
|
141
|
+
}
|
|
142
|
+
export interface ThinkingContent {
|
|
143
|
+
type: "thinking";
|
|
144
|
+
thinking: string;
|
|
145
|
+
thinkingSignature?: string;
|
|
146
|
+
redacted?: boolean;
|
|
147
|
+
}
|
|
148
|
+
export interface ImageContent {
|
|
149
|
+
name?: string;
|
|
150
|
+
type: "image";
|
|
151
|
+
data: string;
|
|
152
|
+
mimeType: string;
|
|
153
|
+
}
|
|
154
|
+
export interface ToolCall {
|
|
155
|
+
type: "toolCall";
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
arguments: JsonObject;
|
|
159
|
+
thoughtSignature?: string;
|
|
160
|
+
namespace?: string;
|
|
161
|
+
}
|
|
162
|
+
export interface Tool<TParameters extends TSchema = TSchema> {
|
|
163
|
+
name: string;
|
|
164
|
+
description: string;
|
|
165
|
+
parameters: TParameters;
|
|
166
|
+
constrainedSampling?: {
|
|
167
|
+
type: "json_schema";
|
|
168
|
+
strict: "prefer" | "require";
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export interface CacheControl {
|
|
172
|
+
type: "ephemeral";
|
|
173
|
+
}
|
|
174
|
+
export interface SystemMessage {
|
|
175
|
+
cacheControl?: CacheControl;
|
|
176
|
+
role: "system";
|
|
177
|
+
content: string | TextContent[];
|
|
178
|
+
timestamp: number;
|
|
179
|
+
sections?: Record<string, string | null>;
|
|
180
|
+
toolsAdded?: Tool[];
|
|
181
|
+
toolsRemoved?: {
|
|
182
|
+
name: string;
|
|
183
|
+
}[];
|
|
184
|
+
}
|
|
185
|
+
export interface ImageAttachment {
|
|
186
|
+
id: string;
|
|
187
|
+
name: string;
|
|
188
|
+
mimeType: string;
|
|
189
|
+
width: number;
|
|
190
|
+
height: number;
|
|
191
|
+
size: number;
|
|
192
|
+
warning?: string;
|
|
193
|
+
}
|
|
194
|
+
export interface FileAttachment {
|
|
195
|
+
id: string;
|
|
196
|
+
name: string;
|
|
197
|
+
mimeType: string;
|
|
198
|
+
size: number;
|
|
199
|
+
path: string;
|
|
200
|
+
}
|
|
201
|
+
export type Attachment = ImageAttachment | FileAttachment;
|
|
202
|
+
export interface UserGuide {
|
|
203
|
+
text: string;
|
|
204
|
+
fileReferences: string[];
|
|
205
|
+
attachments: Attachment[];
|
|
206
|
+
}
|
|
207
|
+
export interface UserMessage {
|
|
208
|
+
/** Stable identity for queued input; never sent as provider message content. */
|
|
209
|
+
inputId?: string;
|
|
210
|
+
/** Display-only provenance for a real user input accepted inside an existing run. */
|
|
211
|
+
userGuide?: UserGuide;
|
|
212
|
+
cacheControl?: CacheControl;
|
|
213
|
+
synthetic?: boolean;
|
|
214
|
+
role: "user";
|
|
215
|
+
content: string | (TextContent | ImageContent)[];
|
|
216
|
+
timestamp: number;
|
|
217
|
+
}
|
|
218
|
+
export interface Usage {
|
|
219
|
+
input: number;
|
|
220
|
+
/** Total generated tokens, including reasoning; `reasoning` is a breakdown, not an addition. */
|
|
221
|
+
output: number;
|
|
222
|
+
cacheRead: number;
|
|
223
|
+
cacheWrite: number;
|
|
224
|
+
cacheWrite1h?: number;
|
|
225
|
+
reasoning?: number;
|
|
226
|
+
totalTokens: number;
|
|
227
|
+
cost: {
|
|
228
|
+
input: number;
|
|
229
|
+
output: number;
|
|
230
|
+
cacheRead: number;
|
|
231
|
+
cacheWrite: number;
|
|
232
|
+
total: number;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
|
|
236
|
+
export interface ContextBreakdownItem {
|
|
237
|
+
source: "messages" | "system_tools" | "system_prompt" | "skills" | "other";
|
|
238
|
+
chars: number;
|
|
239
|
+
}
|
|
240
|
+
export interface AssistantMessage {
|
|
241
|
+
cacheControl?: CacheControl;
|
|
242
|
+
role: "assistant";
|
|
243
|
+
content: (TextContent | ThinkingContent | ToolCall)[];
|
|
244
|
+
api: Api;
|
|
245
|
+
provider: string;
|
|
246
|
+
model: string;
|
|
247
|
+
responseModel?: string;
|
|
248
|
+
responseId?: string;
|
|
249
|
+
providerThinkingLevel?: string;
|
|
250
|
+
thinkingLevel?: "off" | ThinkingLevel;
|
|
251
|
+
usage: Usage;
|
|
252
|
+
usageAvailable?: boolean;
|
|
253
|
+
cacheUsageAvailable?: boolean;
|
|
254
|
+
contextBreakdown?: ContextBreakdownItem[];
|
|
255
|
+
stopReason: StopReason;
|
|
256
|
+
errorMessage?: string;
|
|
257
|
+
errorDetails?: ModelFailure;
|
|
258
|
+
rawStopReason?: string;
|
|
259
|
+
diagnostics?: import("./utils/diagnostics.js").AssistantMessageDiagnostic[];
|
|
260
|
+
endTurn?: boolean;
|
|
261
|
+
timestamp: number;
|
|
262
|
+
}
|
|
263
|
+
export interface ModelFailure {
|
|
264
|
+
/** Undefined when structured facts cannot classify the failure. */
|
|
265
|
+
retryable?: boolean;
|
|
266
|
+
code?: string;
|
|
267
|
+
idleMs?: number;
|
|
268
|
+
timeoutMs?: number;
|
|
269
|
+
status?: number;
|
|
270
|
+
retryAfterMs?: number;
|
|
271
|
+
}
|
|
272
|
+
export interface ModelRetryStatus {
|
|
273
|
+
/** Defaults to automatic recovery when omitted by a provider. */
|
|
274
|
+
origin?: "manual" | "auto";
|
|
275
|
+
attempt: number;
|
|
276
|
+
maxRetries: number;
|
|
277
|
+
retryDelayMs: number;
|
|
278
|
+
errorStatus: number | null;
|
|
279
|
+
}
|
|
280
|
+
export interface ModelWaitStatus {
|
|
281
|
+
phase: "first_response" | "stream";
|
|
282
|
+
startedAt: number;
|
|
283
|
+
}
|
|
284
|
+
export interface ToolResultMessage {
|
|
285
|
+
cacheControl?: CacheControl;
|
|
286
|
+
role: "toolResult";
|
|
287
|
+
toolCallId: string;
|
|
288
|
+
toolName: string;
|
|
289
|
+
content: (TextContent | ImageContent)[];
|
|
290
|
+
details?: JsonValue;
|
|
291
|
+
isError: boolean;
|
|
292
|
+
timestamp: number;
|
|
293
|
+
}
|
|
294
|
+
export type Message = SystemMessage | UserMessage | AssistantMessage | ToolResultMessage;
|
|
295
|
+
export interface Context {
|
|
296
|
+
systemPrompt?: string;
|
|
297
|
+
messages: Message[];
|
|
298
|
+
tools?: Tool[];
|
|
299
|
+
}
|
|
300
|
+
declare const transcriptBrand: unique symbol;
|
|
301
|
+
export type TranscriptContext = {
|
|
302
|
+
messages: Message[];
|
|
303
|
+
readonly [transcriptBrand]: true;
|
|
304
|
+
};
|
|
305
|
+
/** A provider-reported token count paired with its own content interval, never wall-clock elapsed time. */
|
|
306
|
+
export interface ModelPerformanceSample {
|
|
307
|
+
requestMs?: number;
|
|
308
|
+
ttftMs?: number;
|
|
309
|
+
outputTokens?: number;
|
|
310
|
+
generationMs?: number;
|
|
311
|
+
}
|
|
312
|
+
export interface StreamOptions {
|
|
313
|
+
/** Request-local media omission statistics; omitted when the request fits. Never sent to the provider. */
|
|
314
|
+
onMediaProjection?: (stats: import("./utils/media-policy.js").MediaBudgetStats) => void;
|
|
315
|
+
/** Move the tail cache breakpoint before the final request-local prompt on protocols with explicit boundaries. */
|
|
316
|
+
skipCacheWrite?: boolean;
|
|
317
|
+
/** Transient measurements from actual provider attempts; an empty sample starts a fresh attempt. */
|
|
318
|
+
onPerformance?: (sample: ModelPerformanceSample) => void;
|
|
319
|
+
/** Best available provider retention. Legacy OpenAI automatic caching cannot be disabled with "none". */
|
|
320
|
+
cacheRetention?: CacheRetention;
|
|
321
|
+
metadata?: Record<string, unknown>;
|
|
322
|
+
env?: ProviderEnv;
|
|
323
|
+
signal?: AbortSignal;
|
|
324
|
+
sessionId?: string;
|
|
325
|
+
apiKey?: string;
|
|
326
|
+
/** Optional conversation-owned Responses connection; dispose it with the conversation. */
|
|
327
|
+
responsesSession?: import("./api/responses-session.js").ResponsesSession;
|
|
328
|
+
/** Prepare request state with generate:false; never performs model generation or HTTP fallback. */
|
|
329
|
+
responsesWarmup?: boolean;
|
|
330
|
+
fetch?: typeof globalThis.fetch;
|
|
331
|
+
headers?: Record<string, string | null>;
|
|
332
|
+
temperature?: number;
|
|
333
|
+
maxTokens?: number;
|
|
334
|
+
timeoutMs?: number;
|
|
335
|
+
/** First meaningful model event deadline; defaults to 120s, <= 0 disables it. */
|
|
336
|
+
streamFirstResponseTimeoutMs?: number;
|
|
337
|
+
/** Model-event idle deadline after output starts; defaults to 300s, <= 0 disables it. */
|
|
338
|
+
streamIdleTimeoutMs?: number;
|
|
339
|
+
/** Absolute recovery deadline, independent of model-event activity. */
|
|
340
|
+
streamDeadlineMs?: number;
|
|
341
|
+
/** Retry this request without cancelling the enclosing agent turn. */
|
|
342
|
+
retrySignal?: AbortSignal;
|
|
343
|
+
/** Transient waiting state; emitted only after 15s without a meaningful model event. */
|
|
344
|
+
onModelWait?: (status: ModelWaitStatus | null) => void;
|
|
345
|
+
maxRetries?: number;
|
|
346
|
+
maxRetryDelayMs?: number;
|
|
347
|
+
onRetry?: (status: ModelRetryStatus | null) => void;
|
|
348
|
+
samplingParams?: Record<string, unknown>;
|
|
349
|
+
onPayload?: (payload: unknown, model: Model) => unknown | undefined | Promise<unknown | undefined>;
|
|
350
|
+
onResponse?: (response: {
|
|
351
|
+
status: number;
|
|
352
|
+
headers: Record<string, string>;
|
|
353
|
+
}, model: Model) => void | Promise<void>;
|
|
354
|
+
}
|
|
355
|
+
export interface SimpleStreamOptions extends StreamOptions {
|
|
356
|
+
reasoning?: "off" | ThinkingLevel;
|
|
357
|
+
thinkingBudgets?: ThinkingBudgets;
|
|
358
|
+
toolChoice?: "auto" | "none";
|
|
359
|
+
}
|
|
360
|
+
export type StreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = StreamOptions> = (model: Model<TApi>, context: TranscriptContext, options?: TOptions) => AssistantMessageEventStream;
|
|
361
|
+
export type AssistantMessageEvent = {
|
|
362
|
+
type: "start";
|
|
363
|
+
partial: AssistantMessage;
|
|
364
|
+
} | {
|
|
365
|
+
type: "reset";
|
|
366
|
+
partial: AssistantMessage;
|
|
367
|
+
} | {
|
|
368
|
+
type: "text_start" | "thinking_start" | "toolcall_start";
|
|
369
|
+
contentIndex: number;
|
|
370
|
+
partial: AssistantMessage;
|
|
371
|
+
} | {
|
|
372
|
+
type: "text_delta" | "thinking_delta" | "toolcall_delta";
|
|
373
|
+
contentIndex: number;
|
|
374
|
+
delta: string;
|
|
375
|
+
partial: AssistantMessage;
|
|
376
|
+
} | {
|
|
377
|
+
type: "text_end" | "thinking_end";
|
|
378
|
+
contentIndex: number;
|
|
379
|
+
content: string;
|
|
380
|
+
partial: AssistantMessage;
|
|
381
|
+
} | {
|
|
382
|
+
type: "toolcall_end";
|
|
383
|
+
contentIndex: number;
|
|
384
|
+
toolCall: ToolCall;
|
|
385
|
+
partial: AssistantMessage;
|
|
386
|
+
} | {
|
|
387
|
+
type: "done";
|
|
388
|
+
reason: "stop" | "length" | "toolUse";
|
|
389
|
+
message: AssistantMessage;
|
|
390
|
+
} | {
|
|
391
|
+
type: "error";
|
|
392
|
+
reason: "error" | "aborted";
|
|
393
|
+
error: AssistantMessage;
|
|
394
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonObject } from "../types.js";
|
|
2
|
+
export interface DiagnosticErrorInfo {
|
|
3
|
+
name?: string;
|
|
4
|
+
message: string;
|
|
5
|
+
stack?: string;
|
|
6
|
+
code?: string | number;
|
|
7
|
+
}
|
|
8
|
+
export interface AssistantMessageDiagnostic {
|
|
9
|
+
type: string;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
error?: DiagnosticErrorInfo;
|
|
12
|
+
details?: JsonObject;
|
|
13
|
+
}
|
|
14
|
+
export declare function appendAssistantMessageDiagnostic<T extends {
|
|
15
|
+
diagnostics?: AssistantMessageDiagnostic[];
|
|
16
|
+
}>(message: T, diagnostic: AssistantMessageDiagnostic): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const MAX_PROVIDER_ERROR_BODY_CHARS = 4000;
|
|
2
|
+
export interface NormalizedProviderError {
|
|
3
|
+
/** HTTP status code, when one could be extracted from the SDK error object. */
|
|
4
|
+
status?: number;
|
|
5
|
+
/** Raw HTTP body reason, already trimmed and truncated to the cap. */
|
|
6
|
+
body?: string;
|
|
7
|
+
/** `error.message`, or `safeJsonStringify(error)` for a non-`Error` throw. */
|
|
8
|
+
message: string;
|
|
9
|
+
/** True when `message` already contains the body (no separate body to add). */
|
|
10
|
+
messageCarriesBody: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function normalizeProviderError(error: unknown): NormalizedProviderError;
|
|
13
|
+
/**
|
|
14
|
+
* Compose a display string from a normalized error. When the message already
|
|
15
|
+
* carries the body (Anthropic / `@google/genai` happy path) or no body/status
|
|
16
|
+
* was extracted, the message is returned unchanged. Otherwise the status and
|
|
17
|
+
* body are surfaced, with an optional provider prefix.
|
|
18
|
+
*
|
|
19
|
+
* - no prefix: `"<status>: <body>"`
|
|
20
|
+
* - prefix: `"<prefix> (<status>): <body>"`
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatProviderError(norm: NormalizedProviderError, prefix?: string): string;
|
|
23
|
+
export declare function truncateErrorText(text: string, maxChars: number): string;
|
|
24
|
+
export declare function safeJsonStringify(value: unknown): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ImageContent, Message, TextContent, TranscriptContext, Usage } from "../types.js";
|
|
2
|
+
export interface ContextUsageEstimate {
|
|
3
|
+
/** Estimated total context tokens. */
|
|
4
|
+
tokens: number;
|
|
5
|
+
/** Tokens reported by the most recent applicable assistant usage block. */
|
|
6
|
+
usageTokens: number;
|
|
7
|
+
/** Estimated tokens after the most recent applicable assistant usage block. */
|
|
8
|
+
trailingTokens: number;
|
|
9
|
+
/** Index of the applicable message that provided usage, or null when none exists. */
|
|
10
|
+
lastUsageIndex: number | null;
|
|
11
|
+
}
|
|
12
|
+
export declare function calculateContextTokens(usage: Usage): number;
|
|
13
|
+
export declare function estimateTextTokens(text: string): number;
|
|
14
|
+
export declare function estimateTextAndImageContentTokens(content: string | Array<TextContent | ImageContent>): number;
|
|
15
|
+
export declare function estimateMessageTokens(message: Message): number;
|
|
16
|
+
export declare function estimateContextTokens(context: TranscriptContext | readonly Message[]): ContextUsageEstimate;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AssistantMessage, AssistantMessageEvent } from "../types.js";
|
|
2
|
+
/** Single-consumer protocol stream. The final result is independent of iteration. */
|
|
3
|
+
export declare class AssistantMessageEventStream implements AsyncIterable<AssistantMessageEvent> {
|
|
4
|
+
private queue;
|
|
5
|
+
private head;
|
|
6
|
+
private waiter?;
|
|
7
|
+
private ended;
|
|
8
|
+
private resolveResult;
|
|
9
|
+
private finalResult;
|
|
10
|
+
push(event: AssistantMessageEvent): void;
|
|
11
|
+
end(result?: AssistantMessage): void;
|
|
12
|
+
result(): Promise<AssistantMessage>;
|
|
13
|
+
[Symbol.asyncIterator](): AsyncIterator<AssistantMessageEvent>;
|
|
14
|
+
}
|
|
15
|
+
export declare function createAssistantMessageEventStream(): AssistantMessageEventStream;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AssistantMessageEventStream, Model, SimpleStreamOptions } from "../types.js";
|
|
2
|
+
/** ZCode's iterator watchdog adapted to ZPI's model-event boundary, including custom providers. */
|
|
3
|
+
export declare function guardModelStream(model: Model, create: (options: SimpleStreamOptions) => AssistantMessageEventStream | Promise<AssistantMessageEventStream>, options?: SimpleStreamOptions): AssistantMessageEventStream;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function headersToRecord(headers: Headers): Record<string, string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repairs malformed JSON string literals by:
|
|
3
|
+
* - escaping raw control characters inside strings
|
|
4
|
+
* - doubling backslashes before invalid escape characters
|
|
5
|
+
*/
|
|
6
|
+
export declare function repairJson(json: string): string;
|
|
7
|
+
export declare function parseJsonWithRepair<T>(json: string): T;
|