@codehz/ai 0.9.0 → 0.9.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/dist/index.d.mts +189 -26
- package/dist/index.mjs +262 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* KnownAdapterKind 覆盖内置 adapter;
|
|
6
6
|
* AdapterKind 额外接受任意 string,便于自定义 backend 扩展(无需改库联合类型)。
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
/** 内置 adapter kind 列表。 */
|
|
9
|
+
declare const KNOWN_ADAPTER_KINDS: readonly ["chat-completions", "delta-completions", "messages", "responses", "ollama", "gemini", "mock"];
|
|
10
|
+
/** 内置 adapter kind 的字面量联合。 */
|
|
9
11
|
type KnownAdapterKind = (typeof KNOWN_ADAPTER_KINDS)[number];
|
|
10
|
-
/** 内置 kind 自动补全 + 自定义 string
|
|
12
|
+
/** 内置 kind 自动补全 + 自定义 string 扩展。 */
|
|
11
13
|
type AdapterKind = KnownAdapterKind | (string & {});
|
|
12
14
|
//#endregion
|
|
13
15
|
//#region src/types/content.d.ts
|
|
@@ -16,15 +18,21 @@ type AdapterKind = KnownAdapterKind | (string & {});
|
|
|
16
18
|
*
|
|
17
19
|
* 覆盖文本、JSON、图片、二进制引用和后端私有内容。
|
|
18
20
|
*/
|
|
21
|
+
/** 文本内容块;用于 instructions、消息内容和流增量。 */
|
|
19
22
|
type TextContentBlock = {
|
|
20
23
|
type: "text";
|
|
21
24
|
text: string;
|
|
22
25
|
};
|
|
26
|
+
/** JSON 内容块;`json` 保留调用方提供的任意 JSON 兼容值。 */
|
|
23
27
|
type JsonContentBlock = {
|
|
24
28
|
type: "json";
|
|
25
29
|
json: unknown;
|
|
26
30
|
};
|
|
31
|
+
/** 可作为请求 instructions 的内容块联合。 */
|
|
27
32
|
type InstructionBlock = TextContentBlock | JsonContentBlock;
|
|
33
|
+
/**
|
|
34
|
+
* 统一内容块:文本、JSON、图片、二进制引用或 provider 专有 opaque 数据。
|
|
35
|
+
*/
|
|
28
36
|
type ContentBlock = InstructionBlock | {
|
|
29
37
|
type: "image";
|
|
30
38
|
imageUrl: string;
|
|
@@ -37,6 +45,7 @@ type ContentBlock = InstructionBlock | {
|
|
|
37
45
|
};
|
|
38
46
|
//#endregion
|
|
39
47
|
//#region src/types/items.d.ts
|
|
48
|
+
/** URL 网页引用及其在原文中的可选位置。 */
|
|
40
49
|
type UrlCitation = {
|
|
41
50
|
type: "url";
|
|
42
51
|
url: string;
|
|
@@ -44,6 +53,7 @@ type UrlCitation = {
|
|
|
44
53
|
startIndex?: number;
|
|
45
54
|
endIndex?: number;
|
|
46
55
|
};
|
|
56
|
+
/** Provider 容器文件引用及其可选文件名和位置。 */
|
|
47
57
|
type ContainerFileCitation = {
|
|
48
58
|
type: "container_file";
|
|
49
59
|
containerId: string;
|
|
@@ -52,7 +62,9 @@ type ContainerFileCitation = {
|
|
|
52
62
|
startIndex?: number;
|
|
53
63
|
endIndex?: number;
|
|
54
64
|
};
|
|
65
|
+
/** 统一引用联合。 */
|
|
55
66
|
type Citation = UrlCitation | ContainerFileCitation;
|
|
67
|
+
/** 文本或多模态消息 item。 */
|
|
56
68
|
type MessageItem = {
|
|
57
69
|
type: "message";
|
|
58
70
|
id?: string;
|
|
@@ -60,18 +72,21 @@ type MessageItem = {
|
|
|
60
72
|
content: ContentBlock[];
|
|
61
73
|
citations?: Citation[];
|
|
62
74
|
};
|
|
75
|
+
/** 模型 reasoning/thinking 内容及其可见性。 */
|
|
63
76
|
type ReasoningItem = {
|
|
64
77
|
type: "reasoning";
|
|
65
78
|
id?: string;
|
|
66
79
|
visibility: "full" | "summary" | "redacted" | "opaque";
|
|
67
80
|
content: ContentBlock[];
|
|
68
81
|
};
|
|
82
|
+
/** 模型请求客户端工具调用。 */
|
|
69
83
|
type ToolCallItem = {
|
|
70
84
|
type: "tool_call";
|
|
71
85
|
id: string;
|
|
72
86
|
name: string;
|
|
73
87
|
argumentsText: string;
|
|
74
88
|
};
|
|
89
|
+
/** 客户端工具调用结果。 */
|
|
75
90
|
type ToolResultItem = {
|
|
76
91
|
type: "tool_result";
|
|
77
92
|
callId: string;
|
|
@@ -79,6 +94,7 @@ type ToolResultItem = {
|
|
|
79
94
|
outcome: "success" | "error" | "rejected";
|
|
80
95
|
content: ContentBlock[];
|
|
81
96
|
};
|
|
97
|
+
/** Provider 专有状态或 wire replay 数据。 */
|
|
82
98
|
type OpaqueItem = {
|
|
83
99
|
type: "opaque";
|
|
84
100
|
id?: string;
|
|
@@ -86,7 +102,7 @@ type OpaqueItem = {
|
|
|
86
102
|
purpose: "replay" | "provider_state" | "unknown";
|
|
87
103
|
payload: unknown;
|
|
88
104
|
};
|
|
89
|
-
/** Provider
|
|
105
|
+
/** Provider 托管工具调用(调用方不执行)。 */
|
|
90
106
|
type ServerToolCallItem = {
|
|
91
107
|
type: "server_tool_call";
|
|
92
108
|
id: string;
|
|
@@ -97,7 +113,7 @@ type ServerToolCallItem = {
|
|
|
97
113
|
serverLabel?: string;
|
|
98
114
|
providerPayload?: unknown;
|
|
99
115
|
};
|
|
100
|
-
/** Provider
|
|
116
|
+
/** Provider 托管工具结果。 */
|
|
101
117
|
type ServerToolResultItem = {
|
|
102
118
|
type: "server_tool_result";
|
|
103
119
|
id?: string;
|
|
@@ -107,7 +123,7 @@ type ServerToolResultItem = {
|
|
|
107
123
|
content: ContentBlock[];
|
|
108
124
|
providerPayload?: unknown;
|
|
109
125
|
};
|
|
110
|
-
/** MCP
|
|
126
|
+
/** MCP 等远端工具发现列表。 */
|
|
111
127
|
type ServerToolDiscoveryItem = {
|
|
112
128
|
type: "server_tool_discovery";
|
|
113
129
|
id: string;
|
|
@@ -120,21 +136,24 @@ type ServerToolDiscoveryItem = {
|
|
|
120
136
|
}>;
|
|
121
137
|
providerPayload?: unknown;
|
|
122
138
|
};
|
|
123
|
-
/** 可出现在请求 input 中的 item
|
|
139
|
+
/** 可出现在请求 input 中的 item 类型。 */
|
|
124
140
|
type InputItem = MessageItem | ReasoningItem | ToolCallItem | ToolResultItem | OpaqueItem | ServerToolCallItem | ServerToolResultItem | ServerToolDiscoveryItem;
|
|
125
|
-
/** 可出现在响应 output 中的 item 类型(不含客户端 ToolResultItem
|
|
141
|
+
/** 可出现在响应 output 中的 item 类型(不含客户端 ToolResultItem)。 */
|
|
126
142
|
type OutputItem = MessageItem | ReasoningItem | ToolCallItem | OpaqueItem | ServerToolCallItem | ServerToolResultItem | ServerToolDiscoveryItem;
|
|
127
|
-
/** replay 材料的类型等价于 InputItem */
|
|
143
|
+
/** replay 材料的类型等价于 InputItem。 */
|
|
128
144
|
type ReplayItem = InputItem;
|
|
129
145
|
//#endregion
|
|
130
146
|
//#region src/types/cache.d.ts
|
|
131
147
|
/** Request-level portable prompt cache controls and provider extensions. */
|
|
148
|
+
/** Prompt cache 的跨 provider 策略。 */
|
|
132
149
|
type PromptCacheMode = "off" | "auto" | "explicit";
|
|
150
|
+
/** 请求级 prompt cache 控制和路由提示。 */
|
|
133
151
|
type PromptCacheSettings = {
|
|
134
152
|
/** Cache strategy; when omitted, the adapter/provider decides. */mode?: PromptCacheMode; /** Session or tenant routing hint; providers may ignore it. */
|
|
135
153
|
key?: string; /** Provider-specific retention hint. */
|
|
136
154
|
ttl?: "short" | "long" | string;
|
|
137
155
|
};
|
|
156
|
+
/** Provider-specific prompt cache extensions. */
|
|
138
157
|
type ProviderCacheOptions = {
|
|
139
158
|
responses?: {
|
|
140
159
|
promptCacheKey?: string;
|
|
@@ -156,6 +175,7 @@ type ProviderCacheOptions = {
|
|
|
156
175
|
keepAlive?: string | number;
|
|
157
176
|
};
|
|
158
177
|
};
|
|
178
|
+
/** Response metadata describing the effective cache behavior. */
|
|
159
179
|
type PromptCacheMetadata = {
|
|
160
180
|
requestedMode: PromptCacheMode;
|
|
161
181
|
appliedMode: "off" | "implicit" | "explicit" | "unsupported";
|
|
@@ -164,15 +184,18 @@ type PromptCacheMetadata = {
|
|
|
164
184
|
};
|
|
165
185
|
//#endregion
|
|
166
186
|
//#region src/types/request.d.ts
|
|
187
|
+
/** 客户端工具声明;`inputSchema` 使用 JSON Schema 对象。 */
|
|
167
188
|
type ToolDefinition = {
|
|
168
189
|
name: string;
|
|
169
190
|
description?: string;
|
|
170
191
|
inputSchema: Record<string, unknown>;
|
|
171
192
|
};
|
|
193
|
+
/** 客户端工具选择策略。 */
|
|
172
194
|
type ToolChoice = "auto" | "none" | {
|
|
173
195
|
type: "tool";
|
|
174
196
|
name: string;
|
|
175
197
|
};
|
|
198
|
+
/** Web 搜索的近似用户位置。 */
|
|
176
199
|
type WebSearchUserLocation = {
|
|
177
200
|
type: "approximate";
|
|
178
201
|
country?: string;
|
|
@@ -180,6 +203,7 @@ type WebSearchUserLocation = {
|
|
|
180
203
|
region?: string;
|
|
181
204
|
timezone?: string;
|
|
182
205
|
};
|
|
206
|
+
/** Provider 托管的 Web 搜索工具配置。 */
|
|
183
207
|
type WebSearchServerTool = {
|
|
184
208
|
type: "web_search";
|
|
185
209
|
allowedDomains?: string[];
|
|
@@ -187,6 +211,7 @@ type WebSearchServerTool = {
|
|
|
187
211
|
userLocation?: WebSearchUserLocation;
|
|
188
212
|
searchContextSize?: "low" | "medium" | "high";
|
|
189
213
|
};
|
|
214
|
+
/** Provider 托管的代码执行工具配置。 */
|
|
190
215
|
type CodeExecutionServerTool = {
|
|
191
216
|
type: "code_execution";
|
|
192
217
|
container?: {
|
|
@@ -195,28 +220,31 @@ type CodeExecutionServerTool = {
|
|
|
195
220
|
fileIds?: string[];
|
|
196
221
|
};
|
|
197
222
|
};
|
|
223
|
+
/** MCP 远端工具服务配置。authorization 仅用于当前请求。 */
|
|
198
224
|
type McpServerTool = {
|
|
199
225
|
type: "mcp";
|
|
200
226
|
serverLabel: string;
|
|
201
227
|
serverUrl: string;
|
|
202
228
|
serverDescription?: string; /** 每请求由调用方提供;不得写入日志或 opaque 回放。 */
|
|
203
229
|
authorization?: string;
|
|
204
|
-
allowedTools?: string[]; /** 首版仅支持 never */
|
|
230
|
+
allowedTools?: string[]; /** 首版仅支持 never。 */
|
|
205
231
|
requireApproval: "never";
|
|
206
232
|
};
|
|
207
|
-
/** Provider 托管执行的工具声明(不进客户端 tool loop
|
|
233
|
+
/** Provider 托管执行的工具声明(不进客户端 tool loop)。 */
|
|
208
234
|
type ServerToolDefinition = WebSearchServerTool | CodeExecutionServerTool | McpServerTool;
|
|
235
|
+
/** 控制 usage、billing 和 provider metadata 的返回策略。 */
|
|
209
236
|
type IncludeSettings = {
|
|
210
237
|
usage?: "off" | "best_effort" | "required";
|
|
211
238
|
billing?: "off" | "best_effort" | "required";
|
|
212
239
|
providerMetadata?: "off" | "best_effort";
|
|
213
240
|
};
|
|
214
|
-
/** Portable reasoning
|
|
241
|
+
/** Portable reasoning/thinking effort;由各 adapter 映射到 provider 字段。 */
|
|
215
242
|
type ReasoningLevel = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
216
243
|
/** 可移植 reasoning level 枚举(单源;validation / provider 共用)。 */
|
|
217
244
|
declare const REASONING_LEVELS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
218
245
|
/** 用于校验任意字符串 membership;值域与 REASONING_LEVELS 一致。 */
|
|
219
246
|
declare const REASONING_LEVEL_SET: ReadonlySet<string>;
|
|
247
|
+
/** 统一 AI 请求;`input` 为当前请求携带的规范化历史和用户输入。 */
|
|
220
248
|
type AIRequest = {
|
|
221
249
|
instructions?: string | InstructionBlock[];
|
|
222
250
|
input: InputItem[];
|
|
@@ -247,6 +275,7 @@ type AIRequest = {
|
|
|
247
275
|
*
|
|
248
276
|
* runtime.errors 与 events 均从此导出,避免手工双表漂移。
|
|
249
277
|
*/
|
|
278
|
+
/** 标准 warning 代码常量;事件和响应均可携带这些代码。 */
|
|
250
279
|
declare const WarningCode: {
|
|
251
280
|
/** replay fidelity 低于预期 */readonly REPLAY_FIDELITY_LOW: "REPLAY_FIDELITY_LOW"; /** usage 字段缺失 */
|
|
252
281
|
readonly USAGE_MISSING: "USAGE_MISSING"; /** billing 字段缺失 */
|
|
@@ -335,6 +364,7 @@ type AIResponse = {
|
|
|
335
364
|
};
|
|
336
365
|
//#endregion
|
|
337
366
|
//#region src/types/events.d.ts
|
|
367
|
+
/** 所有流事件共享的顺序、时间和后端信息。 */
|
|
338
368
|
type StreamEventBase = {
|
|
339
369
|
type: string;
|
|
340
370
|
responseId?: string;
|
|
@@ -345,21 +375,25 @@ type StreamEventBase = {
|
|
|
345
375
|
isSynthetic: boolean;
|
|
346
376
|
};
|
|
347
377
|
};
|
|
378
|
+
/** 响应开始事件。 */
|
|
348
379
|
type ResponseStartedEvent = StreamEventBase & {
|
|
349
380
|
type: "response.started";
|
|
350
381
|
model: string;
|
|
351
382
|
};
|
|
383
|
+
/** 非致命响应 warning 事件。 */
|
|
352
384
|
type ResponseWarningEvent = StreamEventBase & {
|
|
353
385
|
type: "response.warning";
|
|
354
386
|
message: string;
|
|
355
387
|
code?: WarningCodeValue;
|
|
356
388
|
};
|
|
389
|
+
/** 流中的 usage、billing 或 provider 辅助信息事件。 */
|
|
357
390
|
type ResponseAuxiliaryEvent = StreamEventBase & {
|
|
358
391
|
type: "response.auxiliary";
|
|
359
392
|
usage?: Usage;
|
|
360
393
|
billing?: BillingInfo;
|
|
361
394
|
auxiliary?: Partial<AuxiliaryInfo>;
|
|
362
395
|
};
|
|
396
|
+
/** 响应完成事件;包含 replay 和完成元数据。 */
|
|
363
397
|
type ResponseCompletedEvent = StreamEventBase & {
|
|
364
398
|
type: "response.completed";
|
|
365
399
|
replay: ReplayItem[];
|
|
@@ -371,6 +405,7 @@ type ResponseCompletedEvent = StreamEventBase & {
|
|
|
371
405
|
opaqueOutput?: OpaqueItem[];
|
|
372
406
|
trace?: Partial<BackendTrace>;
|
|
373
407
|
};
|
|
408
|
+
/** 消息 item 开始事件。 */
|
|
374
409
|
type MessageStartedEvent = StreamEventBase & {
|
|
375
410
|
type: "message.started";
|
|
376
411
|
item: {
|
|
@@ -378,16 +413,19 @@ type MessageStartedEvent = StreamEventBase & {
|
|
|
378
413
|
role: "assistant";
|
|
379
414
|
};
|
|
380
415
|
};
|
|
416
|
+
/** 消息内容增量事件。 */
|
|
381
417
|
type MessageDeltaEvent = StreamEventBase & {
|
|
382
418
|
type: "message.delta";
|
|
383
419
|
itemId: string;
|
|
384
420
|
delta: ContentBlock;
|
|
385
421
|
};
|
|
422
|
+
/** 消息 item 完成事件。 */
|
|
386
423
|
type MessageCompletedEvent = StreamEventBase & {
|
|
387
424
|
type: "message.completed";
|
|
388
425
|
itemId: string;
|
|
389
426
|
citations?: Citation[];
|
|
390
427
|
};
|
|
428
|
+
/** reasoning item 开始事件。 */
|
|
391
429
|
type ReasoningStartedEvent = StreamEventBase & {
|
|
392
430
|
type: "reasoning.started";
|
|
393
431
|
item: {
|
|
@@ -395,15 +433,18 @@ type ReasoningStartedEvent = StreamEventBase & {
|
|
|
395
433
|
visibility: "full" | "summary" | "redacted" | "opaque";
|
|
396
434
|
};
|
|
397
435
|
};
|
|
436
|
+
/** reasoning 内容增量事件。 */
|
|
398
437
|
type ReasoningDeltaEvent = StreamEventBase & {
|
|
399
438
|
type: "reasoning.delta";
|
|
400
439
|
itemId: string;
|
|
401
440
|
delta: ContentBlock;
|
|
402
441
|
};
|
|
442
|
+
/** reasoning item 完成事件。 */
|
|
403
443
|
type ReasoningCompletedEvent = StreamEventBase & {
|
|
404
444
|
type: "reasoning.completed";
|
|
405
445
|
itemId: string;
|
|
406
446
|
};
|
|
447
|
+
/** 客户端工具调用开始事件。 */
|
|
407
448
|
type ToolCallStartedEvent = StreamEventBase & {
|
|
408
449
|
type: "tool_call.started";
|
|
409
450
|
item: {
|
|
@@ -411,6 +452,7 @@ type ToolCallStartedEvent = StreamEventBase & {
|
|
|
411
452
|
name: string;
|
|
412
453
|
};
|
|
413
454
|
};
|
|
455
|
+
/** 客户端工具调用参数增量事件。 */
|
|
414
456
|
type ToolCallDeltaEvent = StreamEventBase & {
|
|
415
457
|
type: "tool_call.delta";
|
|
416
458
|
itemId: string;
|
|
@@ -418,10 +460,12 @@ type ToolCallDeltaEvent = StreamEventBase & {
|
|
|
418
460
|
argumentsText?: string;
|
|
419
461
|
};
|
|
420
462
|
};
|
|
463
|
+
/** 客户端工具调用完成事件。 */
|
|
421
464
|
type ToolCallCompletedEvent = StreamEventBase & {
|
|
422
465
|
type: "tool_call.completed";
|
|
423
466
|
itemId: string;
|
|
424
467
|
};
|
|
468
|
+
/** Provider 托管工具调用开始事件。 */
|
|
425
469
|
type ServerToolStartedEvent = StreamEventBase & {
|
|
426
470
|
type: "server_tool.started";
|
|
427
471
|
item: {
|
|
@@ -431,6 +475,7 @@ type ServerToolStartedEvent = StreamEventBase & {
|
|
|
431
475
|
serverLabel?: string;
|
|
432
476
|
};
|
|
433
477
|
};
|
|
478
|
+
/** Provider 托管工具调用参数增量事件。 */
|
|
434
479
|
type ServerToolDeltaEvent = StreamEventBase & {
|
|
435
480
|
type: "server_tool.delta";
|
|
436
481
|
itemId: string;
|
|
@@ -438,46 +483,54 @@ type ServerToolDeltaEvent = StreamEventBase & {
|
|
|
438
483
|
argumentsText?: string;
|
|
439
484
|
};
|
|
440
485
|
};
|
|
486
|
+
/** Provider 托管工具调用完成事件。 */
|
|
441
487
|
type ServerToolCompletedEvent = StreamEventBase & {
|
|
442
488
|
type: "server_tool.completed";
|
|
443
489
|
itemId: string;
|
|
444
490
|
status?: "completed" | "failed";
|
|
445
491
|
providerPayload?: unknown;
|
|
446
492
|
};
|
|
493
|
+
/** Provider 托管工具结果完成事件。 */
|
|
447
494
|
type ServerToolResultCompletedEvent = StreamEventBase & {
|
|
448
495
|
type: "server_tool_result.completed";
|
|
449
496
|
item: ServerToolResultItem;
|
|
450
497
|
};
|
|
498
|
+
/** Provider 托管工具发现列表完成事件。 */
|
|
451
499
|
type ServerToolDiscoveryCompletedEvent = StreamEventBase & {
|
|
452
500
|
type: "server_tool_discovery.completed";
|
|
453
501
|
item: ServerToolDiscoveryItem;
|
|
454
502
|
};
|
|
503
|
+
/** 所有规范化流事件的联合类型。 */
|
|
455
504
|
type AIStreamEvent = ResponseStartedEvent | ResponseWarningEvent | ResponseAuxiliaryEvent | MessageStartedEvent | MessageDeltaEvent | MessageCompletedEvent | ReasoningStartedEvent | ReasoningDeltaEvent | ReasoningCompletedEvent | ToolCallStartedEvent | ToolCallDeltaEvent | ToolCallCompletedEvent | ServerToolStartedEvent | ServerToolDeltaEvent | ServerToolCompletedEvent | ServerToolResultCompletedEvent | ServerToolDiscoveryCompletedEvent | ResponseCompletedEvent;
|
|
456
505
|
//#endregion
|
|
457
506
|
//#region src/types/adapter.d.ts
|
|
458
|
-
/** HTTP fetch
|
|
507
|
+
/** HTTP fetch 函数签名,用于注入自定义请求实现(测试/代理)。 */
|
|
459
508
|
type FetchFn = (url: string, init: RequestInit) => Promise<Response>;
|
|
509
|
+
/** 经过模型选择和默认值合并后的请求。 */
|
|
460
510
|
type NormalizedRequest = AIRequest & {
|
|
461
511
|
model: string;
|
|
462
512
|
requestId: string;
|
|
463
513
|
};
|
|
514
|
+
/** AI 后端适配器必须实现的统一流式协议。 */
|
|
464
515
|
interface BackendAdapter {
|
|
465
516
|
readonly kind: AdapterKind;
|
|
466
517
|
readonly isSyntheticStream: boolean;
|
|
467
518
|
stream(request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
|
|
468
519
|
}
|
|
520
|
+
/** createAIClient 的配置。 */
|
|
469
521
|
type CreateAIClientOptions = {
|
|
470
522
|
adapter: BackendAdapter;
|
|
471
523
|
model: string;
|
|
472
524
|
defaults?: Partial<AIRequest>; /** 全局默认 AbortSignal,当 request.signal 未设置时生效。 */
|
|
473
525
|
signal?: AbortSignal;
|
|
474
526
|
};
|
|
527
|
+
/** 面向调用方的统一 AI 客户端。 */
|
|
475
528
|
interface AIClient {
|
|
476
529
|
stream(request: AIRequest): AsyncIterable<AIStreamEvent>;
|
|
477
530
|
}
|
|
478
531
|
//#endregion
|
|
479
532
|
//#region src/types/compress.d.ts
|
|
480
|
-
/** 显式上下文压缩请求(独立于 stream
|
|
533
|
+
/** 显式上下文压缩请求(独立于 stream)。 */
|
|
481
534
|
type CompressRequest = {
|
|
482
535
|
model: string;
|
|
483
536
|
input: InputItem[];
|
|
@@ -485,21 +538,22 @@ type CompressRequest = {
|
|
|
485
538
|
include?: IncludeSettings; /** AbortSignal 用于打断压缩请求。 */
|
|
486
539
|
signal?: AbortSignal;
|
|
487
540
|
};
|
|
488
|
-
/**
|
|
541
|
+
/** 压缩结果;调用方用 replay 替换旧 transcript,而不是追加全文。 */
|
|
489
542
|
type CompressResult = {
|
|
490
543
|
replay: ReplayItem[];
|
|
491
544
|
usage?: Usage;
|
|
492
545
|
auxiliary?: AuxiliaryInfo;
|
|
493
546
|
rawResponseId?: string;
|
|
494
547
|
};
|
|
495
|
-
/** Adapter
|
|
548
|
+
/** Adapter 可选的原生上下文压缩能力。 */
|
|
496
549
|
interface ContextCompressCapable {
|
|
497
550
|
compress(request: CompressRequest): Promise<CompressResult>;
|
|
498
551
|
}
|
|
499
|
-
/** 探测 adapter
|
|
552
|
+
/** 探测 adapter 是否实现上下文压缩能力。 */
|
|
500
553
|
declare function supportsContextCompress(adapter: BackendAdapter): adapter is BackendAdapter & ContextCompressCapable;
|
|
501
554
|
//#endregion
|
|
502
555
|
//#region src/runtime/client.d.ts
|
|
556
|
+
/** 创建统一 AI 客户端;请求级字段覆盖 defaults,signal 可在客户端级设置。 */
|
|
503
557
|
declare function createAIClient(options: CreateAIClientOptions): AIClient;
|
|
504
558
|
//#endregion
|
|
505
559
|
//#region src/runtime/errors.d.ts
|
|
@@ -508,7 +562,9 @@ declare function createAIClient(options: CreateAIClientOptions): AIClient;
|
|
|
508
562
|
* ValidationIssue.code 可更细,不强制全部列入此处;以作为 AIError.code 传入的码为主。
|
|
509
563
|
*/
|
|
510
564
|
type KnownErrorCode = "INPUT_EMPTY" | "TEMPERATURE_OUT_OF_RANGE" | "MAX_OUTPUT_TOKENS_INVALID" | "TOOL_CHOICE_NO_TOOLS" | "TOOL_CHOICE_UNKNOWN_TOOL" | "TOOL_CALL_ARGUMENTS_INVALID" | "PROVIDER_ERROR" | "AUTH_ERROR" | "STREAM_ERROR" | "STREAM_PROTOCOL_ERROR" | "MAPPING_ERROR" | "STREAM_INCOMPLETE" | "LOOKUP_FAILED" | "LOOKUP_TIMEOUT" | "INVALID_OPAQUE_REPLAY" | "UNSUPPORTED_CONTENT_BLOCK" | "UNSUPPORTED_SERVER_TOOL" | "UNSUPPORTED_REASONING_LEVEL" | "UNSUPPORTED_COMPRESS" | "MOCK_CONCURRENT_STREAM" | "MOCK_COMPRESS_NOT_CONFIGURED" | "MOCK_EXPECTATION_FAILED" | "MOCK_STREAM_CONFIG_INVALID" | "MOCK_OPAQUE_OUTPUT" | "MOCK_MESSAGE_ID_MISSING" | "MOCK_REASONING_ID_MISSING";
|
|
565
|
+
/** 错误码;内置错误码之外允许 provider 或扩展使用字符串。 */
|
|
511
566
|
type ErrorCode = KnownErrorCode | (string & {});
|
|
567
|
+
/** 所有运行时错误的基类。 */
|
|
512
568
|
declare class AIError extends Error {
|
|
513
569
|
readonly code: ErrorCode;
|
|
514
570
|
readonly name: string;
|
|
@@ -571,22 +627,29 @@ declare class AIRecoverableError extends AIError {
|
|
|
571
627
|
}
|
|
572
628
|
//#endregion
|
|
573
629
|
//#region src/stream/collect-stream.d.ts
|
|
630
|
+
/** 消费完整个事件流并聚合为 AIResponse;适用于不需要逐事件处理的调用方。 */
|
|
574
631
|
declare function collectStream(stream: AsyncIterable<AIStreamEvent>): Promise<AIResponse>;
|
|
575
632
|
//#endregion
|
|
576
633
|
//#region src/canonical/stop-reason.d.ts
|
|
634
|
+
/** 将 provider stop/finish reason 映射为规范化 StopReason。 */
|
|
577
635
|
declare function mapStopReason(providerReason: string): StopReason;
|
|
636
|
+
/** 根据 thinking 和 redacted 标记推断 reasoning 可见性。 */
|
|
578
637
|
declare function mapReasoningVisibility(hasThinking: boolean, hasRedacted: boolean): ReasoningItem["visibility"];
|
|
579
638
|
//#endregion
|
|
580
639
|
//#region src/canonical/content.d.ts
|
|
640
|
+
/** 创建文本内容块。 */
|
|
581
641
|
declare function textBlock(text: string): ContentBlock & {
|
|
582
642
|
type: "text";
|
|
583
643
|
};
|
|
644
|
+
/** 创建 JSON 内容块。 */
|
|
584
645
|
declare function jsonBlock(json: unknown): ContentBlock & {
|
|
585
646
|
type: "json";
|
|
586
647
|
};
|
|
648
|
+
/** 创建图片内容块;imageUrl 可为 URL 或 data URL。 */
|
|
587
649
|
declare function imageBlock(imageUrl: string): ContentBlock & {
|
|
588
650
|
type: "image";
|
|
589
651
|
};
|
|
652
|
+
/** 创建 provider 专有 opaque 内容块。 */
|
|
590
653
|
declare function opaqueBlock(payload: unknown): ContentBlock & {
|
|
591
654
|
type: "opaque";
|
|
592
655
|
};
|
|
@@ -606,13 +669,21 @@ declare function contentBlocksToText(blocks: ContentBlock[]): string;
|
|
|
606
669
|
declare function coalesceContentBlocks(blocks: readonly ContentBlock[]): ContentBlock[];
|
|
607
670
|
//#endregion
|
|
608
671
|
//#region src/canonical/items.d.ts
|
|
672
|
+
/** 创建消息 item;可用 overrides 补充 id、role 和 citations。 */
|
|
609
673
|
declare function messageItem(content: ContentBlock[], overrides?: Partial<Omit<MessageItem, "type" | "content">>): MessageItem;
|
|
674
|
+
/** 创建 reasoning item。 */
|
|
610
675
|
declare function reasoningItem(content: ContentBlock[], visibility?: ReasoningItem["visibility"], id?: string): ReasoningItem;
|
|
676
|
+
/** 创建客户端工具调用 item。 */
|
|
611
677
|
declare function toolCallItem(id: string, name: string, argumentsText: string): ToolCallItem;
|
|
678
|
+
/** 创建客户端工具结果 item。 */
|
|
612
679
|
declare function toolResultItem(callId: string, toolName: string, outcome: ToolResultItem["outcome"], content: ContentBlock[]): ToolResultItem;
|
|
680
|
+
/** 创建 opaque item,通常用于 provider replay。 */
|
|
613
681
|
declare function opaqueItem(source: OpaqueItem["source"], purpose: OpaqueItem["purpose"], payload: unknown, id?: string): OpaqueItem;
|
|
682
|
+
/** 创建 provider 托管工具调用 item。 */
|
|
614
683
|
declare function serverToolCallItem(id: string, tool: ServerToolCallItem["tool"], overrides?: Partial<Omit<ServerToolCallItem, "type" | "id" | "tool">>): ServerToolCallItem;
|
|
684
|
+
/** 创建 provider 托管工具结果 item。 */
|
|
615
685
|
declare function serverToolResultItem(callId: string, tool: string, outcome: ServerToolResultItem["outcome"], content: ContentBlock[], overrides?: Partial<Omit<ServerToolResultItem, "type" | "callId" | "tool" | "outcome" | "content">>): ServerToolResultItem;
|
|
686
|
+
/** 创建 MCP 等 provider 托管工具发现 item。 */
|
|
616
687
|
declare function serverToolDiscoveryItem(id: string, serverLabel: string, tools: ServerToolDiscoveryItem["tools"], overrides?: Partial<Omit<ServerToolDiscoveryItem, "type" | "id" | "tool" | "serverLabel" | "tools">>): ServerToolDiscoveryItem;
|
|
617
688
|
//#endregion
|
|
618
689
|
//#region src/canonical/replay.d.ts
|
|
@@ -621,10 +692,12 @@ declare function serverToolDiscoveryItem(id: string, serverLabel: string, tools:
|
|
|
621
692
|
* 简单场景下 replay 与 output 一致。
|
|
622
693
|
* 复杂场景(需要 opaque continuation)由 adapter 自行扩展。
|
|
623
694
|
*/
|
|
695
|
+
/** 从 output items 构建 replay;opaque continuation 可由 adapter 额外扩展。 */
|
|
624
696
|
declare function replayFromOutput(output: readonly OutputItem[]): ReplayItem[];
|
|
625
697
|
/**
|
|
626
698
|
* 从 OutputItem 数组中提取所有 message 类型 item 的文本内容。
|
|
627
699
|
*/
|
|
700
|
+
/** 从 output 中提取所有消息 item 的文本内容。 */
|
|
628
701
|
declare function extractText(output: OutputItem[]): string;
|
|
629
702
|
//#endregion
|
|
630
703
|
//#region src/stream/event-factory.d.ts
|
|
@@ -910,6 +983,7 @@ declare abstract class HttpAdapterBase extends AdapterBase {
|
|
|
910
983
|
type ResponsesAdapterOptions = HttpAdapterOptions & {
|
|
911
984
|
apiKey: string;
|
|
912
985
|
};
|
|
986
|
+
/** OpenAI Responses API 的流式请求体。 */
|
|
913
987
|
type ResponsesAPIRequest = {
|
|
914
988
|
model: string;
|
|
915
989
|
input: ResponsesInputItem[];
|
|
@@ -933,12 +1007,13 @@ type ResponsesAPIRequest = {
|
|
|
933
1007
|
};
|
|
934
1008
|
stream: true;
|
|
935
1009
|
};
|
|
936
|
-
/**
|
|
1010
|
+
/** Responses API 的消息输入 item。 */
|
|
937
1011
|
type ResponsesEasyMessage = {
|
|
938
1012
|
type: "message";
|
|
939
1013
|
role: "user" | "assistant" | "system" | "developer";
|
|
940
1014
|
content: string | ResponsesInputContentPart[];
|
|
941
1015
|
};
|
|
1016
|
+
/** Responses API 的输入内容 part。 */
|
|
942
1017
|
type ResponsesInputContentPart = {
|
|
943
1018
|
type: "input_text";
|
|
944
1019
|
text: string;
|
|
@@ -952,7 +1027,7 @@ type ResponsesInputContentPart = {
|
|
|
952
1027
|
file_id?: string;
|
|
953
1028
|
filename?: string;
|
|
954
1029
|
};
|
|
955
|
-
/**
|
|
1030
|
+
/** Responses API 的客户端 function call item。 */
|
|
956
1031
|
type ResponsesFunctionCall = {
|
|
957
1032
|
type: "function_call";
|
|
958
1033
|
call_id: string;
|
|
@@ -961,6 +1036,7 @@ type ResponsesFunctionCall = {
|
|
|
961
1036
|
id?: string;
|
|
962
1037
|
status?: "in_progress" | "completed" | "incomplete";
|
|
963
1038
|
};
|
|
1039
|
+
/** Responses API 的 function call 结果 item。 */
|
|
964
1040
|
type ResponsesFunctionCallOutput = {
|
|
965
1041
|
type: "function_call_output";
|
|
966
1042
|
call_id: string;
|
|
@@ -1003,7 +1079,9 @@ type ResponsesWirePassthroughItem = {
|
|
|
1003
1079
|
type: string;
|
|
1004
1080
|
[key: string]: unknown;
|
|
1005
1081
|
};
|
|
1082
|
+
/** Responses API 可接受的输入 item 联合。 */
|
|
1006
1083
|
type ResponsesInputItem = ResponsesEasyMessage | ResponsesFunctionCall | ResponsesFunctionCallOutput | ResponsesReasoningInput | ResponsesItemReference | ResponsesCompactionInput | ResponsesWirePassthroughItem;
|
|
1084
|
+
/** Responses API 的客户端 function 工具。 */
|
|
1007
1085
|
type ResponsesFunctionTool = {
|
|
1008
1086
|
type: "function";
|
|
1009
1087
|
name: string;
|
|
@@ -1011,6 +1089,7 @@ type ResponsesFunctionTool = {
|
|
|
1011
1089
|
parameters: Record<string, unknown>;
|
|
1012
1090
|
strict?: boolean | null;
|
|
1013
1091
|
};
|
|
1092
|
+
/** Responses API 的 Web Search 工具。 */
|
|
1014
1093
|
type ResponsesWebSearchTool = {
|
|
1015
1094
|
type: "web_search";
|
|
1016
1095
|
filters?: {
|
|
@@ -1026,6 +1105,7 @@ type ResponsesWebSearchTool = {
|
|
|
1026
1105
|
};
|
|
1027
1106
|
search_context_size?: "low" | "medium" | "high";
|
|
1028
1107
|
};
|
|
1108
|
+
/** Responses API 的代码解释器工具。 */
|
|
1029
1109
|
type ResponsesCodeInterpreterTool = {
|
|
1030
1110
|
type: "code_interpreter";
|
|
1031
1111
|
container: string | {
|
|
@@ -1034,6 +1114,7 @@ type ResponsesCodeInterpreterTool = {
|
|
|
1034
1114
|
file_ids?: string[];
|
|
1035
1115
|
};
|
|
1036
1116
|
};
|
|
1117
|
+
/** Responses API 的 MCP 工具。 */
|
|
1037
1118
|
type ResponsesMcpTool = {
|
|
1038
1119
|
type: "mcp";
|
|
1039
1120
|
server_label: string;
|
|
@@ -1043,10 +1124,11 @@ type ResponsesMcpTool = {
|
|
|
1043
1124
|
allowed_tools?: string[];
|
|
1044
1125
|
require_approval: "never";
|
|
1045
1126
|
};
|
|
1046
|
-
/** Responses API
|
|
1127
|
+
/** Responses API 的工具联合。 */
|
|
1047
1128
|
type ResponsesTool = ResponsesFunctionTool | ResponsesWebSearchTool | ResponsesCodeInterpreterTool | ResponsesMcpTool;
|
|
1048
1129
|
//#endregion
|
|
1049
1130
|
//#region src/adapters/responses/adapter.d.ts
|
|
1131
|
+
/** OpenAI Responses API 适配器;支持原生流式响应和上下文压缩。 */
|
|
1050
1132
|
declare class ResponsesAdapter extends HttpAdapterBase implements ContextCompressCapable {
|
|
1051
1133
|
readonly kind: "responses";
|
|
1052
1134
|
readonly isSyntheticStream = false;
|
|
@@ -1061,11 +1143,12 @@ declare class ResponsesAdapter extends HttpAdapterBase implements ContextCompres
|
|
|
1061
1143
|
}
|
|
1062
1144
|
//#endregion
|
|
1063
1145
|
//#region src/adapters/messages/types.d.ts
|
|
1064
|
-
/** apiKey
|
|
1146
|
+
/** Anthropic Messages adapter 配置;apiKey 必填,apiVersion 默认 2023-06-01。 */
|
|
1065
1147
|
type MessagesAdapterOptions = HttpAdapterOptions & {
|
|
1066
1148
|
apiKey: string; /** Anthropic API 版本头,默认 2023-06-01 */
|
|
1067
1149
|
apiVersion?: string;
|
|
1068
1150
|
};
|
|
1151
|
+
/** Anthropic Messages API 的流式请求体。 */
|
|
1069
1152
|
type MessagesAPIRequest = {
|
|
1070
1153
|
model: string;
|
|
1071
1154
|
max_tokens: number;
|
|
@@ -1087,11 +1170,14 @@ type MessagesAPIRequest = {
|
|
|
1087
1170
|
};
|
|
1088
1171
|
stream: true;
|
|
1089
1172
|
};
|
|
1173
|
+
/** Anthropic Messages API 消息。 */
|
|
1090
1174
|
type MessagesAPIMessage = {
|
|
1091
1175
|
role: "user" | "assistant";
|
|
1092
1176
|
content: string | MessagesAPIContentBlock[];
|
|
1093
1177
|
};
|
|
1178
|
+
/** Anthropic 支持的图片媒体类型。 */
|
|
1094
1179
|
type MessagesAPIImageMediaType = "image/jpeg" | "image/png" | "image/gif" | "image/webp";
|
|
1180
|
+
/** Anthropic 图片内容来源。 */
|
|
1095
1181
|
type MessagesAPIImageSource = {
|
|
1096
1182
|
type: "base64";
|
|
1097
1183
|
media_type: MessagesAPIImageMediaType;
|
|
@@ -1100,10 +1186,12 @@ type MessagesAPIImageSource = {
|
|
|
1100
1186
|
type: "url";
|
|
1101
1187
|
url: string;
|
|
1102
1188
|
};
|
|
1189
|
+
/** Anthropic prompt cache 控制。 */
|
|
1103
1190
|
type MessagesCacheControl = {
|
|
1104
1191
|
type: "ephemeral";
|
|
1105
1192
|
ttl?: "5m" | "1h";
|
|
1106
1193
|
};
|
|
1194
|
+
/** Anthropic 消息内容 block。 */
|
|
1107
1195
|
type MessagesAPIContentBlock = {
|
|
1108
1196
|
type: "text";
|
|
1109
1197
|
text: string;
|
|
@@ -1134,6 +1222,7 @@ type MessagesAPIContentBlock = {
|
|
|
1134
1222
|
is_error?: boolean;
|
|
1135
1223
|
cache_control?: MessagesCacheControl;
|
|
1136
1224
|
};
|
|
1225
|
+
/** Anthropic 客户端工具声明。 */
|
|
1137
1226
|
type MessagesAPITool = {
|
|
1138
1227
|
name: string;
|
|
1139
1228
|
description?: string;
|
|
@@ -1142,6 +1231,7 @@ type MessagesAPITool = {
|
|
|
1142
1231
|
};
|
|
1143
1232
|
//#endregion
|
|
1144
1233
|
//#region src/adapters/messages/adapter.d.ts
|
|
1234
|
+
/** Anthropic Messages API 适配器。 */
|
|
1145
1235
|
declare class MessagesAdapter extends HttpAdapterBase {
|
|
1146
1236
|
readonly kind: "messages";
|
|
1147
1237
|
readonly isSyntheticStream = false;
|
|
@@ -1152,10 +1242,11 @@ declare class MessagesAdapter extends HttpAdapterBase {
|
|
|
1152
1242
|
}
|
|
1153
1243
|
//#endregion
|
|
1154
1244
|
//#region src/adapters/chat-completions/types.d.ts
|
|
1155
|
-
/**
|
|
1245
|
+
/** OpenAI Chat Completions adapter 配置;apiKey 必填。 */
|
|
1156
1246
|
type ChatCompletionsAdapterOptions = HttpAdapterOptions & {
|
|
1157
1247
|
apiKey: string;
|
|
1158
1248
|
};
|
|
1249
|
+
/** OpenAI Chat Completions API 的流式请求体。 */
|
|
1159
1250
|
type ChatRequest = {
|
|
1160
1251
|
model: string;
|
|
1161
1252
|
messages: ChatMessage[];
|
|
@@ -1175,10 +1266,12 @@ type ChatRequest = {
|
|
|
1175
1266
|
stream: true;
|
|
1176
1267
|
n: 1;
|
|
1177
1268
|
};
|
|
1269
|
+
/** Chat Completions 文本内容 part。 */
|
|
1178
1270
|
type ChatTextPart = {
|
|
1179
1271
|
type: "text";
|
|
1180
1272
|
text: string;
|
|
1181
1273
|
};
|
|
1274
|
+
/** Chat Completions 图片内容 part。 */
|
|
1182
1275
|
type ChatImagePart = {
|
|
1183
1276
|
type: "image_url";
|
|
1184
1277
|
image_url: {
|
|
@@ -1186,7 +1279,9 @@ type ChatImagePart = {
|
|
|
1186
1279
|
detail?: "auto" | "low" | "high";
|
|
1187
1280
|
};
|
|
1188
1281
|
};
|
|
1282
|
+
/** Chat Completions 内容 part 联合。 */
|
|
1189
1283
|
type ChatContentPart = ChatTextPart | ChatImagePart;
|
|
1284
|
+
/** Chat Completions 消息。 */
|
|
1190
1285
|
type ChatMessage = {
|
|
1191
1286
|
role: "system" | "user" | "assistant" | "tool";
|
|
1192
1287
|
content: string | null | ChatContentPart[];
|
|
@@ -1195,6 +1290,7 @@ type ChatMessage = {
|
|
|
1195
1290
|
name?: string;
|
|
1196
1291
|
[key: string]: unknown;
|
|
1197
1292
|
};
|
|
1293
|
+
/** Chat Completions 工具调用。 */
|
|
1198
1294
|
type ChatToolCall = {
|
|
1199
1295
|
id: string;
|
|
1200
1296
|
type: "function";
|
|
@@ -1203,6 +1299,7 @@ type ChatToolCall = {
|
|
|
1203
1299
|
arguments: string;
|
|
1204
1300
|
};
|
|
1205
1301
|
};
|
|
1302
|
+
/** Chat Completions 客户端工具。 */
|
|
1206
1303
|
type ChatTool = {
|
|
1207
1304
|
type: "function";
|
|
1208
1305
|
function: {
|
|
@@ -1213,6 +1310,7 @@ type ChatTool = {
|
|
|
1213
1310
|
};
|
|
1214
1311
|
//#endregion
|
|
1215
1312
|
//#region src/adapters/chat-completions/adapter.d.ts
|
|
1313
|
+
/** OpenAI Chat Completions API 适配器。 */
|
|
1216
1314
|
declare class ChatCompletionsAdapter extends HttpAdapterBase {
|
|
1217
1315
|
readonly kind: "chat-completions";
|
|
1218
1316
|
readonly isSyntheticStream = false;
|
|
@@ -1221,11 +1319,39 @@ declare class ChatCompletionsAdapter extends HttpAdapterBase {
|
|
|
1221
1319
|
protected runStream(providerRequest: ChatRequest, factory: EventFactory, request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
|
|
1222
1320
|
}
|
|
1223
1321
|
//#endregion
|
|
1322
|
+
//#region src/adapters/delta-completions/types.d.ts
|
|
1323
|
+
/** 残缺 chat/completions 兼容适配器;必须显式 baseUrl,避免误打 OpenAI。 */
|
|
1324
|
+
type DeltaCompletionsAdapterOptions = HttpAdapterOptions & {
|
|
1325
|
+
baseUrl: string;
|
|
1326
|
+
};
|
|
1327
|
+
/** 出站请求:仅文本 messages + stream。不发送 n / tools / reasoning。 */
|
|
1328
|
+
type DeltaChatRequest = {
|
|
1329
|
+
model: string;
|
|
1330
|
+
messages: DeltaChatMessage[];
|
|
1331
|
+
stream: true;
|
|
1332
|
+
temperature?: number;
|
|
1333
|
+
max_tokens?: number;
|
|
1334
|
+
};
|
|
1335
|
+
/** 仅文本 chat 消息。 */
|
|
1336
|
+
type DeltaChatMessage = {
|
|
1337
|
+
role: "system" | "user" | "assistant";
|
|
1338
|
+
content: string;
|
|
1339
|
+
};
|
|
1340
|
+
//#endregion
|
|
1341
|
+
//#region src/adapters/delta-completions/adapter.d.ts
|
|
1342
|
+
/** 残缺 chat/completions SSE 适配器。 */
|
|
1343
|
+
declare class DeltaCompletionsAdapter extends HttpAdapterBase {
|
|
1344
|
+
readonly kind: "delta-completions";
|
|
1345
|
+
readonly isSyntheticStream = false;
|
|
1346
|
+
constructor(options: DeltaCompletionsAdapterOptions);
|
|
1347
|
+
protected buildRequest(request: NormalizedRequest): DeltaChatRequest;
|
|
1348
|
+
protected runStream(providerRequest: DeltaChatRequest, factory: EventFactory, request: NormalizedRequest): AsyncIterable<AIStreamEvent>;
|
|
1349
|
+
}
|
|
1350
|
+
//#endregion
|
|
1224
1351
|
//#region src/adapters/ollama/types.d.ts
|
|
1225
|
-
/**
|
|
1226
|
-
* apiKey 可选(代理鉴权);默认 baseUrl http://localhost:11434
|
|
1227
|
-
*/
|
|
1352
|
+
/** Ollama adapter 配置;apiKey 可选,默认连接本地服务。 */
|
|
1228
1353
|
type OllamaAdapterOptions = HttpAdapterOptions;
|
|
1354
|
+
/** Ollama Chat API 的流式请求体。 */
|
|
1229
1355
|
type OllamaChatRequest = {
|
|
1230
1356
|
model: string;
|
|
1231
1357
|
messages: OllamaMessage[];
|
|
@@ -1239,18 +1365,21 @@ type OllamaChatRequest = {
|
|
|
1239
1365
|
[key: string]: unknown;
|
|
1240
1366
|
};
|
|
1241
1367
|
};
|
|
1368
|
+
/** Ollama 消息。 */
|
|
1242
1369
|
type OllamaMessage = {
|
|
1243
1370
|
role: "system" | "user" | "assistant" | "tool";
|
|
1244
1371
|
content: string;
|
|
1245
1372
|
images?: string[];
|
|
1246
1373
|
tool_calls?: OllamaToolCall[];
|
|
1247
1374
|
};
|
|
1375
|
+
/** Ollama 工具调用。 */
|
|
1248
1376
|
type OllamaToolCall = {
|
|
1249
1377
|
function: {
|
|
1250
1378
|
name: string;
|
|
1251
1379
|
arguments: Record<string, unknown>;
|
|
1252
1380
|
};
|
|
1253
1381
|
};
|
|
1382
|
+
/** Ollama 客户端工具。 */
|
|
1254
1383
|
type OllamaTool = {
|
|
1255
1384
|
type: "function";
|
|
1256
1385
|
function: {
|
|
@@ -1261,6 +1390,7 @@ type OllamaTool = {
|
|
|
1261
1390
|
};
|
|
1262
1391
|
//#endregion
|
|
1263
1392
|
//#region src/adapters/ollama/adapter.d.ts
|
|
1393
|
+
/** Ollama Chat API 适配器。 */
|
|
1264
1394
|
declare class OllamaAdapter extends HttpAdapterBase {
|
|
1265
1395
|
readonly kind: "ollama";
|
|
1266
1396
|
readonly isSyntheticStream = false;
|
|
@@ -1270,10 +1400,11 @@ declare class OllamaAdapter extends HttpAdapterBase {
|
|
|
1270
1400
|
}
|
|
1271
1401
|
//#endregion
|
|
1272
1402
|
//#region src/adapters/gemini/types.d.ts
|
|
1273
|
-
/**
|
|
1403
|
+
/** Gemini adapter 配置;apiKey 必填。 */
|
|
1274
1404
|
type GeminiAdapterOptions = HttpAdapterOptions & {
|
|
1275
1405
|
apiKey: string;
|
|
1276
1406
|
};
|
|
1407
|
+
/** Gemini 内容 part。 */
|
|
1277
1408
|
type GeminiPart = {
|
|
1278
1409
|
text?: string;
|
|
1279
1410
|
thought?: boolean;
|
|
@@ -1294,22 +1425,27 @@ type GeminiPart = {
|
|
|
1294
1425
|
};
|
|
1295
1426
|
[key: string]: unknown;
|
|
1296
1427
|
};
|
|
1428
|
+
/** Gemini 对话内容。 */
|
|
1297
1429
|
type GeminiContent = {
|
|
1298
1430
|
role: "user" | "model";
|
|
1299
1431
|
parts: GeminiPart[];
|
|
1300
1432
|
};
|
|
1433
|
+
/** Gemini function declaration。 */
|
|
1301
1434
|
type GeminiFunctionDeclaration = {
|
|
1302
1435
|
name: string;
|
|
1303
1436
|
description?: string;
|
|
1304
1437
|
parameters: Record<string, unknown>;
|
|
1305
1438
|
};
|
|
1439
|
+
/** Gemini 工具容器。 */
|
|
1306
1440
|
type GeminiTool = {
|
|
1307
1441
|
functionDeclarations: GeminiFunctionDeclaration[];
|
|
1308
1442
|
};
|
|
1443
|
+
/** Gemini function calling 配置。 */
|
|
1309
1444
|
type GeminiFunctionCallingConfig = {
|
|
1310
1445
|
mode: "AUTO" | "ANY" | "NONE";
|
|
1311
1446
|
allowedFunctionNames?: string[];
|
|
1312
1447
|
};
|
|
1448
|
+
/** Gemini generateContent 请求体。 */
|
|
1313
1449
|
type GeminiGenerateContentRequest = {
|
|
1314
1450
|
contents: GeminiContent[];
|
|
1315
1451
|
cachedContent?: string;
|
|
@@ -1335,6 +1471,7 @@ type GeminiGenerateContentRequest = {
|
|
|
1335
1471
|
};
|
|
1336
1472
|
//#endregion
|
|
1337
1473
|
//#region src/adapters/gemini/adapter.d.ts
|
|
1474
|
+
/** Google Gemini generateContent API 适配器。 */
|
|
1338
1475
|
declare class GeminiAdapter extends HttpAdapterBase {
|
|
1339
1476
|
readonly kind: "gemini";
|
|
1340
1477
|
readonly isSyntheticStream = false;
|
|
@@ -1344,6 +1481,7 @@ declare class GeminiAdapter extends HttpAdapterBase {
|
|
|
1344
1481
|
}
|
|
1345
1482
|
//#endregion
|
|
1346
1483
|
//#region src/adapters/mock/types.d.ts
|
|
1484
|
+
/** Mock handler 对单个输入 item 的匹配条件。 */
|
|
1347
1485
|
type MockInputExpectation = {
|
|
1348
1486
|
type: InputItem["type"];
|
|
1349
1487
|
id?: string;
|
|
@@ -1363,6 +1501,7 @@ type MockInputExpectation = {
|
|
|
1363
1501
|
}>["purpose"];
|
|
1364
1502
|
textIncludes?: string;
|
|
1365
1503
|
};
|
|
1504
|
+
/** Mock 请求整体的断言条件。 */
|
|
1366
1505
|
type MockRequestExpectation = {
|
|
1367
1506
|
minItems?: number;
|
|
1368
1507
|
maxItems?: number;
|
|
@@ -1374,12 +1513,14 @@ type MockRequestExpectation = {
|
|
|
1374
1513
|
toolChoice?: "ignore" | "present" | "absent";
|
|
1375
1514
|
items?: MockInputExpectation[];
|
|
1376
1515
|
};
|
|
1516
|
+
/** Mock adapter 记录的一轮请求历史。 */
|
|
1377
1517
|
type MockHistoryRecord = {
|
|
1378
1518
|
turnIndex: number;
|
|
1379
1519
|
requestId: string;
|
|
1380
1520
|
replay: ReplayItem[];
|
|
1381
1521
|
toolCalls: ToolCallItem[];
|
|
1382
1522
|
};
|
|
1523
|
+
/** Mock handler 可读取的当前回合上下文。 */
|
|
1383
1524
|
type MockHandlerContext = {
|
|
1384
1525
|
turnIndex: number;
|
|
1385
1526
|
previousReplay: ReplayItem[];
|
|
@@ -1388,17 +1529,20 @@ type MockHandlerContext = {
|
|
|
1388
1529
|
signal?: AbortSignal; /** 当前请求的 portable reasoningLevel(若设置)。 */
|
|
1389
1530
|
reasoningLevel?: ReasoningLevel;
|
|
1390
1531
|
};
|
|
1532
|
+
/** 在 Mock 流中发出 warning。 */
|
|
1391
1533
|
type MockWarningStep = {
|
|
1392
1534
|
type: "warning";
|
|
1393
1535
|
message: string;
|
|
1394
1536
|
code?: string;
|
|
1395
1537
|
};
|
|
1538
|
+
/** 在 Mock 流中发出辅助响应信息。 */
|
|
1396
1539
|
type MockAuxiliaryStep = {
|
|
1397
1540
|
type: "auxiliary";
|
|
1398
1541
|
usage?: Usage;
|
|
1399
1542
|
billing?: BillingInfo;
|
|
1400
1543
|
auxiliary?: Partial<AuxiliaryInfo>;
|
|
1401
1544
|
};
|
|
1545
|
+
/** Mock 文本/参数增量的切分和延迟配置。 */
|
|
1402
1546
|
type MockTextStreamOptions = {
|
|
1403
1547
|
/**
|
|
1404
1548
|
* 每秒吐出的字符数。未设置时仍会按 chunk 拆分,但不会额外等待。
|
|
@@ -1413,6 +1557,7 @@ type MockTextStreamOptions = {
|
|
|
1413
1557
|
*/
|
|
1414
1558
|
initialDelayMs?: number;
|
|
1415
1559
|
};
|
|
1560
|
+
/** 在 Mock 流中发出消息 item。 */
|
|
1416
1561
|
type MockMessageStep = {
|
|
1417
1562
|
type: "message";
|
|
1418
1563
|
id?: string;
|
|
@@ -1420,6 +1565,7 @@ type MockMessageStep = {
|
|
|
1420
1565
|
citations?: Citation[];
|
|
1421
1566
|
stream?: MockTextStreamOptions | false;
|
|
1422
1567
|
};
|
|
1568
|
+
/** 在 Mock 流中发出 provider 托管工具调用。 */
|
|
1423
1569
|
type MockServerToolCallStep = {
|
|
1424
1570
|
type: "server_tool_call";
|
|
1425
1571
|
id: string;
|
|
@@ -1432,14 +1578,17 @@ type MockServerToolCallStep = {
|
|
|
1432
1578
|
streamArguments?: boolean;
|
|
1433
1579
|
stream?: MockTextStreamOptions | false;
|
|
1434
1580
|
};
|
|
1581
|
+
/** 在 Mock 流中发出 provider 托管工具结果。 */
|
|
1435
1582
|
type MockServerToolResultStep = {
|
|
1436
1583
|
type: "server_tool_result";
|
|
1437
1584
|
item: ServerToolResultItem;
|
|
1438
1585
|
};
|
|
1586
|
+
/** 在 Mock 流中发出 provider 工具发现列表。 */
|
|
1439
1587
|
type MockServerToolDiscoveryStep = {
|
|
1440
1588
|
type: "server_tool_discovery";
|
|
1441
1589
|
item: ServerToolDiscoveryItem;
|
|
1442
1590
|
};
|
|
1591
|
+
/** 在 Mock 流中发出 reasoning item。 */
|
|
1443
1592
|
type MockReasoningStep = {
|
|
1444
1593
|
type: "reasoning";
|
|
1445
1594
|
id?: string;
|
|
@@ -1449,6 +1598,7 @@ type MockReasoningStep = {
|
|
|
1449
1598
|
content: string | ContentBlock[];
|
|
1450
1599
|
stream?: MockTextStreamOptions | false;
|
|
1451
1600
|
};
|
|
1601
|
+
/** 在 Mock 流中发出客户端工具调用。 */
|
|
1452
1602
|
type MockToolCallStep = {
|
|
1453
1603
|
type: "tool_call";
|
|
1454
1604
|
id: string;
|
|
@@ -1457,6 +1607,7 @@ type MockToolCallStep = {
|
|
|
1457
1607
|
streamArguments?: boolean;
|
|
1458
1608
|
stream?: MockTextStreamOptions | false;
|
|
1459
1609
|
};
|
|
1610
|
+
/** 在 Mock 流中直接发出完整 output item。 */
|
|
1460
1611
|
type MockOutputStep = {
|
|
1461
1612
|
type: "output";
|
|
1462
1613
|
item: Extract<OutputItem, {
|
|
@@ -1464,6 +1615,7 @@ type MockOutputStep = {
|
|
|
1464
1615
|
}>;
|
|
1465
1616
|
stream?: MockTextStreamOptions | false;
|
|
1466
1617
|
};
|
|
1618
|
+
/** 在 Mock 流中完成当前响应并提供完成元数据。 */
|
|
1467
1619
|
type MockCompleteStep = {
|
|
1468
1620
|
type: "complete";
|
|
1469
1621
|
stopReason?: StopReason;
|
|
@@ -1475,6 +1627,7 @@ type MockCompleteStep = {
|
|
|
1475
1627
|
rawResponseId?: string;
|
|
1476
1628
|
warnings?: StreamWarning[];
|
|
1477
1629
|
};
|
|
1630
|
+
/** 在 Mock 流中发出可恢复错误。 */
|
|
1478
1631
|
type MockErrorStep = {
|
|
1479
1632
|
type: "error";
|
|
1480
1633
|
message: string;
|
|
@@ -1482,19 +1635,26 @@ type MockErrorStep = {
|
|
|
1482
1635
|
stopReason?: StopReason;
|
|
1483
1636
|
providerMetadata?: Record<string, unknown>;
|
|
1484
1637
|
};
|
|
1638
|
+
/** 在 Mock 流中模拟中断。 */
|
|
1485
1639
|
type MockInterruptStep = {
|
|
1486
1640
|
type: "interrupt";
|
|
1487
1641
|
};
|
|
1642
|
+
/** 在 Mock 流中抛出异常。 */
|
|
1488
1643
|
type MockThrowStep = {
|
|
1489
1644
|
type: "throw";
|
|
1490
1645
|
error: string | Error;
|
|
1491
1646
|
};
|
|
1647
|
+
/** Mock handler 可发出的所有步骤。 */
|
|
1492
1648
|
type MockStep = MockWarningStep | MockAuxiliaryStep | MockMessageStep | MockReasoningStep | MockToolCallStep | MockServerToolCallStep | MockServerToolResultStep | MockServerToolDiscoveryStep | MockOutputStep | MockCompleteStep | MockErrorStep | MockInterruptStep | MockThrowStep;
|
|
1649
|
+
/** 按规范化请求和上下文生成 Mock 流步骤。 */
|
|
1493
1650
|
type MockHandler = (request: NormalizedRequest, context: MockHandlerContext) => AsyncIterable<MockStep>;
|
|
1651
|
+
/** 可同步或异步消费的 Mock 步骤来源。 */
|
|
1494
1652
|
type MockHandlerSource = Iterable<MockStep> | AsyncIterable<MockStep>;
|
|
1653
|
+
/** 可返回同步/异步步骤来源的 Mock handler。 */
|
|
1495
1654
|
type MockStaticHandler = (request: NormalizedRequest, context: MockHandlerContext) => MockHandlerSource | Promise<MockHandlerSource>;
|
|
1496
1655
|
/** Mock compress 夹具;未配置时 compress() 抛 MOCK_COMPRESS_NOT_CONFIGURED */
|
|
1497
1656
|
type MockCompressHandler = (request: CompressRequest) => CompressResult | Promise<CompressResult>;
|
|
1657
|
+
/** Mock adapter 的构造选项。 */
|
|
1498
1658
|
type MockAdapterOptions = {
|
|
1499
1659
|
handler: MockHandler;
|
|
1500
1660
|
providerMetadata?: Record<string, unknown>; /** 可选:实现 ContextCompressCapable 供 compress 契约测试 */
|
|
@@ -1508,6 +1668,7 @@ type MockProviderRequest = {
|
|
|
1508
1668
|
};
|
|
1509
1669
|
//#endregion
|
|
1510
1670
|
//#region src/adapters/mock/adapter.d.ts
|
|
1671
|
+
/** 用于测试和本地场景的确定性模拟适配器。 */
|
|
1511
1672
|
declare class MockAdapter extends AdapterBase implements ContextCompressCapable {
|
|
1512
1673
|
readonly kind: "mock";
|
|
1513
1674
|
readonly isSyntheticStream = true;
|
|
@@ -1532,10 +1693,12 @@ declare class MockAdapter extends AdapterBase implements ContextCompressCapable
|
|
|
1532
1693
|
}
|
|
1533
1694
|
//#endregion
|
|
1534
1695
|
//#region src/adapters/mock/expectations.d.ts
|
|
1696
|
+
/** 按 MockRequestExpectation 校验规范化请求;失败时抛出断言错误。 */
|
|
1535
1697
|
declare function assertMockRequest(request: NormalizedRequest, expectation: MockRequestExpectation, context: MockHandlerContext): void;
|
|
1536
1698
|
//#endregion
|
|
1537
1699
|
//#region src/adapters/mock/streaming.d.ts
|
|
1700
|
+
/** 为静态 Mock handler 添加可配置的文本/参数流式切分。 */
|
|
1538
1701
|
declare function withMockStreaming(handler: MockStaticHandler, options: MockTextStreamOptions): MockHandler;
|
|
1539
1702
|
//#endregion
|
|
1540
|
-
export { type AIClient, AIError, AIMappingError, AIProviderError, AIRecoverableError, type AIRequest, AIRequestError, type AIResponse, AIStreamError, type AIStreamEvent, type AdapterKind, type AuxiliaryInfo, type BackendAdapter, type BackendTrace, type BillingInfo, ChatCompletionsAdapter, type ChatCompletionsAdapterOptions, type Citation, type CodeExecutionServerTool, type CompressRequest, type CompressResult, type ContainerFileCitation, type ContentBlock, type ContextCompressCapable, type CreateAIClientOptions, type ErrorCode, type FetchFn, GeminiAdapter, type GeminiAdapterOptions, type IncludeSettings, type InputItem, type InstructionBlock, type JsonContentBlock, KNOWN_ADAPTER_KINDS, type KnownAdapterKind, type KnownErrorCode, type KnownWarningCode, type McpServerTool, type MessageCompletedEvent, type MessageDeltaEvent, type MessageItem, type MessageStartedEvent, MessagesAdapter, type MessagesAdapterOptions, MockAdapter, type MockAdapterOptions, type MockAuxiliaryStep, type MockCompleteStep, type MockCompressHandler, type MockErrorStep, type MockHandler, type MockHandlerContext, type MockHistoryRecord, type MockInputExpectation, type MockInterruptStep, type MockMessageStep, type MockOutputStep, type MockReasoningStep, type MockRequestExpectation, type MockServerToolCallStep, type MockServerToolDiscoveryStep, type MockServerToolResultStep, type MockStaticHandler, type MockStep, type MockTextStreamOptions, type MockThrowStep, type MockToolCallStep, type MockWarningStep, type NormalizedRequest, OllamaAdapter, type OllamaAdapterOptions, type OpaqueItem, type OutputItem, type PromptCacheMetadata, type PromptCacheMode, type PromptCacheSettings, type ProviderCacheOptions, REASONING_LEVELS, REASONING_LEVEL_SET, type ReasoningCompletedEvent, type ReasoningDeltaEvent, type ReasoningItem, type ReasoningLevel, type ReasoningStartedEvent, type ReplayItem, type ResponseAuxiliaryEvent, type ResponseCompletedEvent, type ResponseStartedEvent, type ResponseWarningEvent, ResponsesAdapter, type ResponsesAdapterOptions, type ServerToolCallItem, type ServerToolCompletedEvent, type ServerToolDefinition, type ServerToolDeltaEvent, type ServerToolDiscoveryCompletedEvent, type ServerToolDiscoveryItem, type ServerToolResultCompletedEvent, type ServerToolResultItem, type ServerToolStartedEvent, type StopReason, type StreamEventBase, type StreamWarning, type TextContentBlock, type ToolCallCompletedEvent, type ToolCallDeltaEvent, type ToolCallItem, type ToolCallStartedEvent, type ToolChoice, type ToolDefinition, type ToolResultItem, type UrlCitation, type Usage, WarningCode, type WarningCodeName, type WarningCodeValue, type WebSearchServerTool, type WebSearchUserLocation, assertMockRequest, blockToText, coalesceContentBlocks, collectStream, contentBlocksToText, createAIClient, extractText, imageBlock, jsonBlock, mapReasoningVisibility, mapStopReason, messageItem, opaqueBlock, opaqueItem, reasoningItem, replayFromOutput, serverToolCallItem, serverToolDiscoveryItem, serverToolResultItem, streamWarningKey, supportsContextCompress, textBlock, toolCallItem, toolResultItem, withMockStreaming };
|
|
1703
|
+
export { type AIClient, AIError, AIMappingError, AIProviderError, AIRecoverableError, type AIRequest, AIRequestError, type AIResponse, AIStreamError, type AIStreamEvent, type AdapterKind, type AuxiliaryInfo, type BackendAdapter, type BackendTrace, type BillingInfo, ChatCompletionsAdapter, type ChatCompletionsAdapterOptions, type Citation, type CodeExecutionServerTool, type CompressRequest, type CompressResult, type ContainerFileCitation, type ContentBlock, type ContextCompressCapable, type CreateAIClientOptions, DeltaCompletionsAdapter, type DeltaCompletionsAdapterOptions, type ErrorCode, type FetchFn, GeminiAdapter, type GeminiAdapterOptions, type IncludeSettings, type InputItem, type InstructionBlock, type JsonContentBlock, KNOWN_ADAPTER_KINDS, type KnownAdapterKind, type KnownErrorCode, type KnownWarningCode, type McpServerTool, type MessageCompletedEvent, type MessageDeltaEvent, type MessageItem, type MessageStartedEvent, MessagesAdapter, type MessagesAdapterOptions, MockAdapter, type MockAdapterOptions, type MockAuxiliaryStep, type MockCompleteStep, type MockCompressHandler, type MockErrorStep, type MockHandler, type MockHandlerContext, type MockHistoryRecord, type MockInputExpectation, type MockInterruptStep, type MockMessageStep, type MockOutputStep, type MockReasoningStep, type MockRequestExpectation, type MockServerToolCallStep, type MockServerToolDiscoveryStep, type MockServerToolResultStep, type MockStaticHandler, type MockStep, type MockTextStreamOptions, type MockThrowStep, type MockToolCallStep, type MockWarningStep, type NormalizedRequest, OllamaAdapter, type OllamaAdapterOptions, type OpaqueItem, type OutputItem, type PromptCacheMetadata, type PromptCacheMode, type PromptCacheSettings, type ProviderCacheOptions, REASONING_LEVELS, REASONING_LEVEL_SET, type ReasoningCompletedEvent, type ReasoningDeltaEvent, type ReasoningItem, type ReasoningLevel, type ReasoningStartedEvent, type ReplayItem, type ResponseAuxiliaryEvent, type ResponseCompletedEvent, type ResponseStartedEvent, type ResponseWarningEvent, ResponsesAdapter, type ResponsesAdapterOptions, type ServerToolCallItem, type ServerToolCompletedEvent, type ServerToolDefinition, type ServerToolDeltaEvent, type ServerToolDiscoveryCompletedEvent, type ServerToolDiscoveryItem, type ServerToolResultCompletedEvent, type ServerToolResultItem, type ServerToolStartedEvent, type StopReason, type StreamEventBase, type StreamWarning, type TextContentBlock, type ToolCallCompletedEvent, type ToolCallDeltaEvent, type ToolCallItem, type ToolCallStartedEvent, type ToolChoice, type ToolDefinition, type ToolResultItem, type UrlCitation, type Usage, WarningCode, type WarningCodeName, type WarningCodeValue, type WebSearchServerTool, type WebSearchUserLocation, assertMockRequest, blockToText, coalesceContentBlocks, collectStream, contentBlocksToText, createAIClient, extractText, imageBlock, jsonBlock, mapReasoningVisibility, mapStopReason, messageItem, opaqueBlock, opaqueItem, reasoningItem, replayFromOutput, serverToolCallItem, serverToolDiscoveryItem, serverToolResultItem, streamWarningKey, supportsContextCompress, textBlock, toolCallItem, toolResultItem, withMockStreaming };
|
|
1541
1704
|
//# sourceMappingURL=index.d.mts.map
|