@huyooo/ai-chat-core 0.2.19 → 0.2.21
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/events.d.ts +452 -0
- package/dist/events.js +1 -0
- package/dist/index.d.ts +202 -550
- package/dist/index.js +1 -1
- package/package.json +23 -4
- package/src/agent.ts +399 -0
- package/src/constants.ts +125 -0
- package/src/events.ts +797 -0
- package/src/index.ts +309 -0
- package/src/internal/update-plan.ts +2 -0
- package/src/internal/web-search.ts +78 -0
- package/src/mcp/client-manager.ts +301 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/types.ts +43 -0
- package/src/providers/context-compressor.ts +149 -0
- package/src/providers/index.ts +120 -0
- package/src/providers/model-registry.ts +320 -0
- package/src/providers/orchestrator.ts +761 -0
- package/src/providers/protocols/anthropic.ts +406 -0
- package/src/providers/protocols/ark.ts +362 -0
- package/src/providers/protocols/deepseek.ts +344 -0
- package/src/providers/protocols/error-utils.ts +74 -0
- package/src/providers/protocols/gemini.ts +350 -0
- package/src/providers/protocols/index.ts +36 -0
- package/src/providers/protocols/openai.ts +420 -0
- package/src/providers/protocols/qwen.ts +326 -0
- package/src/providers/protocols/types.ts +189 -0
- package/src/providers/types.ts +272 -0
- package/src/providers/unified-adapter.ts +367 -0
- package/src/router.ts +72 -0
- package/src/test-utils/mock-sse.ts +32 -0
- package/src/tools.ts +162 -0
- package/src/types.ts +531 -0
- package/src/utils.ts +86 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,43 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ChatEvent } from './events.js';
|
|
2
|
+
export { AbortEvent, CHAT_EVENT_TYPES, ChatEventType, DoneEvent, ErrorCategory, ErrorDetails, ErrorEvent, PlanStep, PlanStepStatus, SearchEndEvent, SearchEvent, SearchResult, SearchResultEvent, SearchStartEvent, StatusEvent, StepEndEvent, StepEvent, StepStartEvent, TextDeltaEvent, TextEvent, ThinkingDeltaEvent, ThinkingEndEvent, ThinkingEvent, ThinkingStartEvent, TokenUsage, ToolApprovalRequestEvent, ToolCallInfo, ToolCallOutputEvent, ToolCallRequestEvent, ToolCallResultEvent, ToolCallStartEvent, ToolCallStatus, ToolEvent, createAbort, createApiError, createDone, createError, createParseError, createRateLimitError, createSearchEnd, createSearchResult, createSearchStart, createStepEnd, createStepStart, createTextDelta, createThinkingDelta, createThinkingEnd, createThinkingStart, createTimeoutError, createToolCallOutput, createToolCallRequest, createToolCallResult, createToolCallStart, createToolError, isAbortEvent, isErrorEvent, isRetryableError, isSearchEvent, isStatusEvent, isStepEvent, isTextEvent, isThinkingEvent, isToolEvent } from './events.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* MCP (Model Context Protocol) 相关类型定义
|
|
6
|
+
*
|
|
7
|
+
* 支持两种传输方式:
|
|
8
|
+
* - stdio: 启动本地子进程,通过 stdin/stdout 通信(操作本地文件、命令、应用)
|
|
9
|
+
* - sse: 连接远程 HTTP 服务器(调用远程 API/服务)
|
|
10
|
+
*/
|
|
11
|
+
/** MCP Server 配置 */
|
|
12
|
+
interface McpServerConfig {
|
|
13
|
+
/** 服务器唯一标识(用于日志和工具命名空间) */
|
|
14
|
+
name: string;
|
|
15
|
+
/** 传输方式 */
|
|
16
|
+
transport: 'stdio' | 'sse';
|
|
17
|
+
/** stdio 模式:启动命令(如 "npx", "python3", "/usr/local/bin/my-server") */
|
|
18
|
+
command?: string;
|
|
19
|
+
/** stdio 模式:命令参数 */
|
|
20
|
+
args?: string[];
|
|
21
|
+
/** stdio 模式:环境变量 */
|
|
22
|
+
env?: Record<string, string>;
|
|
23
|
+
/** stdio 模式:工作目录 */
|
|
24
|
+
cwd?: string;
|
|
25
|
+
/** sse 模式:服务器 URL */
|
|
26
|
+
url?: string;
|
|
27
|
+
}
|
|
28
|
+
/** MCP 连接状态 */
|
|
29
|
+
type McpConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
30
|
+
/** 单个 MCP 连接信息 */
|
|
31
|
+
interface McpConnectionInfo {
|
|
32
|
+
/** 服务器名称 */
|
|
33
|
+
name: string;
|
|
34
|
+
/** 连接状态 */
|
|
35
|
+
status: McpConnectionStatus;
|
|
36
|
+
/** 提供的工具数量 */
|
|
37
|
+
toolCount: number;
|
|
38
|
+
/** 错误信息(status === 'error' 时) */
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
2
41
|
|
|
3
42
|
/**
|
|
4
43
|
* 模型注册表
|
|
@@ -18,8 +57,12 @@ type ModelFamilyId = 'doubao' | 'deepseek' | 'qwen' | 'gemini' | 'gpt' | 'claude
|
|
|
18
57
|
type ProtocolId = 'ark' | 'deepseek' | 'qwen' | 'gemini' | 'openai' | 'anthropic';
|
|
19
58
|
/** Thinking 输出格式 */
|
|
20
59
|
type ThinkingFormat = 'reasoning' | 'thinking_enabled' | 'thought_signature' | 'none';
|
|
21
|
-
/**
|
|
22
|
-
|
|
60
|
+
/**
|
|
61
|
+
* 搜索实现方式(谁提供搜索、行为是否由我们统一)
|
|
62
|
+
* - provider_native:厂商原生,协议层各自实现(ARK type:web_search / Gemini googleSearch 等),行为各异
|
|
63
|
+
* - tavily:我们注入 Tavily web_search 工具,行为一致(GPT/Claude/Qwen/Gemini 有工具时)
|
|
64
|
+
*/
|
|
65
|
+
type SearchStrategy = 'provider_native' | 'tavily';
|
|
23
66
|
/** 工具调用格式 */
|
|
24
67
|
type ToolCallFormat = 'responses' | 'openai' | 'gemini';
|
|
25
68
|
/**
|
|
@@ -48,9 +91,9 @@ interface ModelFamilyConfig {
|
|
|
48
91
|
/** 是否需要特殊处理(如 Gemini 的 thought_signature) */
|
|
49
92
|
requiresSpecialHandling?: string[];
|
|
50
93
|
}
|
|
51
|
-
/**
|
|
94
|
+
/** 豆包家族(联网搜索统一走 web_search_ai/Tavily,与其它模型事件与数据格式一致) */
|
|
52
95
|
declare const DOUBAO_FAMILY: ModelFamilyConfig;
|
|
53
|
-
/** DeepSeek
|
|
96
|
+
/** DeepSeek 家族(联网搜索统一走 web_search_ai/Tavily,与其它模型事件与数据格式一致) */
|
|
54
97
|
declare const DEEPSEEK_FAMILY: ModelFamilyConfig;
|
|
55
98
|
/** 通义千问家族 */
|
|
56
99
|
/** Qwen 家族(使用 Tavily 统一搜索) */
|
|
@@ -250,6 +293,21 @@ interface AgentConfig {
|
|
|
250
293
|
* 每次检查工具批准时调用,获取最新配置
|
|
251
294
|
*/
|
|
252
295
|
getAutoRunConfig?: () => Promise<AutoRunConfig$1 | undefined>;
|
|
296
|
+
/**
|
|
297
|
+
* MCP Server 配置列表
|
|
298
|
+
*
|
|
299
|
+
* 初始化时自动连接所有 MCP Server,发现工具并注册到 Agent。
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* mcpServers: [
|
|
304
|
+
* { name: 'filesystem', transport: 'stdio', command: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', '/Users/me'] },
|
|
305
|
+
* { name: 'github', transport: 'stdio', command: 'npx', args: ['-y', '@modelcontextprotocol/server-github'], env: { GITHUB_TOKEN: '...' } },
|
|
306
|
+
* { name: 'remote-db', transport: 'sse', url: 'http://localhost:3001/mcp' },
|
|
307
|
+
* ]
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
mcpServers?: McpServerConfig[];
|
|
253
311
|
}
|
|
254
312
|
/** 深度思考模式 */
|
|
255
313
|
type ThinkingMode = 'enabled' | 'disabled';
|
|
@@ -269,6 +327,20 @@ interface ChatHistoryMessage {
|
|
|
269
327
|
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
270
328
|
content: string;
|
|
271
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* 用户工具定义(透传模式)
|
|
332
|
+
*
|
|
333
|
+
* 只包含 schema,不包含 execute 函数
|
|
334
|
+
* 由客户端执行,服务端透传 tool_call_request 事件
|
|
335
|
+
*/
|
|
336
|
+
interface UserToolDefinition {
|
|
337
|
+
/** 工具名称 */
|
|
338
|
+
name: string;
|
|
339
|
+
/** 工具描述(供 AI 理解) */
|
|
340
|
+
description: string;
|
|
341
|
+
/** 参数定义(JSON Schema,支持嵌套) */
|
|
342
|
+
parameters: JsonSchemaObject;
|
|
343
|
+
}
|
|
272
344
|
/** 聊天配置(每次聊天可变的选项) */
|
|
273
345
|
interface ChatOptions {
|
|
274
346
|
/** 对话模式 */
|
|
@@ -291,6 +363,31 @@ interface ChatOptions {
|
|
|
291
363
|
autoRunConfig?: AutoRunConfig$1;
|
|
292
364
|
/** 对话历史(从数据库加载,无状态架构) */
|
|
293
365
|
history?: ChatHistoryMessage[];
|
|
366
|
+
/**
|
|
367
|
+
* 用户自定义工具(透传模式)
|
|
368
|
+
*
|
|
369
|
+
* 这些工具不在服务端执行,而是:
|
|
370
|
+
* 1. 传递给 AI 模型
|
|
371
|
+
* 2. AI 返回 tool_call 时,发送 tool_call_request 事件给客户端
|
|
372
|
+
* 3. 客户端执行后,发新请求继续对话
|
|
373
|
+
*/
|
|
374
|
+
userTools?: UserToolDefinition[];
|
|
375
|
+
/**
|
|
376
|
+
* 上次请求的计划快照(可选,仅用于断点续传)
|
|
377
|
+
*
|
|
378
|
+
* 正常流程不需要传:AI 会在单次请求内自主创建和管理计划。
|
|
379
|
+
*
|
|
380
|
+
* 仅在请求被中断后需要恢复时使用:
|
|
381
|
+
* - 客户端工具透传模式(请求中断,等客户端执行后重新发请求)
|
|
382
|
+
* - 用户 abort 后想继续
|
|
383
|
+
*/
|
|
384
|
+
/**
|
|
385
|
+
* Skills 内容(启用的 Skills 的 content 数组,由前端/服务端拼好传入)
|
|
386
|
+
*
|
|
387
|
+
* 自动注入到 system prompt 的【用户指令】段落。
|
|
388
|
+
* 前端合并「默认启用的 skills + @ 手动选的 skills」后传入。
|
|
389
|
+
*/
|
|
390
|
+
skillContents?: string[];
|
|
294
391
|
}
|
|
295
392
|
/**
|
|
296
393
|
* 副作用定义(参考 REST API 规范)
|
|
@@ -305,7 +402,7 @@ interface ChatOptions {
|
|
|
305
402
|
* // 失败
|
|
306
403
|
* { type: 'notification', success: false, message: 'API 超时' }
|
|
307
404
|
*/
|
|
308
|
-
interface SideEffect
|
|
405
|
+
interface SideEffect {
|
|
309
406
|
/** 副作用类型 */
|
|
310
407
|
type: string;
|
|
311
408
|
/** 是否成功 */
|
|
@@ -324,7 +421,7 @@ interface ToolResult {
|
|
|
324
421
|
/** 执行结果(字符串) */
|
|
325
422
|
result: string;
|
|
326
423
|
/** 动态副作用(覆盖静态声明) */
|
|
327
|
-
sideEffects?: SideEffect
|
|
424
|
+
sideEffects?: SideEffect[];
|
|
328
425
|
}
|
|
329
426
|
/** 工具执行上下文 */
|
|
330
427
|
interface ToolContext {
|
|
@@ -341,6 +438,23 @@ interface ToolContext {
|
|
|
341
438
|
/** 中断信号(用于取消长时间操作) */
|
|
342
439
|
signal?: AbortSignal;
|
|
343
440
|
}
|
|
441
|
+
/** JSON Schema 属性定义(支持嵌套,符合 JSON Schema 规范) */
|
|
442
|
+
interface JsonSchemaProperty {
|
|
443
|
+
type?: string;
|
|
444
|
+
description?: string;
|
|
445
|
+
enum?: unknown[];
|
|
446
|
+
items?: JsonSchemaProperty;
|
|
447
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
448
|
+
required?: string[];
|
|
449
|
+
default?: unknown;
|
|
450
|
+
}
|
|
451
|
+
/** JSON Schema 对象类型(工具参数的根类型) */
|
|
452
|
+
interface JsonSchemaObject {
|
|
453
|
+
type: 'object';
|
|
454
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
455
|
+
required?: string[];
|
|
456
|
+
description?: string;
|
|
457
|
+
}
|
|
344
458
|
/**
|
|
345
459
|
* 工具接口(用户可实现此接口创建自定义工具)
|
|
346
460
|
*
|
|
@@ -361,19 +475,8 @@ interface Tool {
|
|
|
361
475
|
name: string;
|
|
362
476
|
/** 工具描述(供 AI 理解) */
|
|
363
477
|
description: string;
|
|
364
|
-
/** 参数定义(JSON Schema
|
|
365
|
-
parameters:
|
|
366
|
-
type: 'object';
|
|
367
|
-
properties: Record<string, {
|
|
368
|
-
type: string;
|
|
369
|
-
description: string;
|
|
370
|
-
enum?: string[];
|
|
371
|
-
items?: {
|
|
372
|
-
type: string;
|
|
373
|
-
};
|
|
374
|
-
}>;
|
|
375
|
-
required: string[];
|
|
376
|
-
};
|
|
478
|
+
/** 参数定义(JSON Schema,支持嵌套对象和数组) */
|
|
479
|
+
parameters: JsonSchemaObject;
|
|
377
480
|
/**
|
|
378
481
|
* 静态副作用声明(可选)
|
|
379
482
|
*
|
|
@@ -384,7 +487,7 @@ interface Tool {
|
|
|
384
487
|
*
|
|
385
488
|
* 注意:如果 execute 返回 ToolResult 带有 sideEffects,会覆盖此静态声明
|
|
386
489
|
*/
|
|
387
|
-
sideEffects?: SideEffect
|
|
490
|
+
sideEffects?: SideEffect[];
|
|
388
491
|
/**
|
|
389
492
|
* 结果类型(用于前端渲染)
|
|
390
493
|
*
|
|
@@ -467,11 +570,14 @@ declare function tools(ts: Tool[]): ToolPlugin;
|
|
|
467
570
|
* ]
|
|
468
571
|
* ```
|
|
469
572
|
*/
|
|
470
|
-
type ToolConfigItem = ToolPlugin | Promise<ToolPlugin>;
|
|
573
|
+
type ToolConfigItem = Tool | ToolPlugin | Promise<Tool | ToolPlugin>;
|
|
471
574
|
/**
|
|
472
575
|
* 解析工具配置,统一转换为 Tool[]
|
|
473
576
|
*
|
|
474
|
-
*
|
|
577
|
+
* 支持三种形式:
|
|
578
|
+
* - Tool: 单个工具(直接使用)
|
|
579
|
+
* - ToolPlugin: 工具插件(展开 .tools 数组)
|
|
580
|
+
* - Promise<Tool | ToolPlugin>: 异步工具/插件
|
|
475
581
|
*/
|
|
476
582
|
declare function resolveTools(items: ToolConfigItem[]): Promise<Tool[]>;
|
|
477
583
|
/** 工具定义(OpenAI 格式,内部使用) */
|
|
@@ -480,18 +586,7 @@ interface ToolDefinition {
|
|
|
480
586
|
function: {
|
|
481
587
|
name: string;
|
|
482
588
|
description: string;
|
|
483
|
-
parameters:
|
|
484
|
-
type: 'object';
|
|
485
|
-
properties: Record<string, {
|
|
486
|
-
type: string;
|
|
487
|
-
description: string;
|
|
488
|
-
enum?: string[];
|
|
489
|
-
items?: {
|
|
490
|
-
type: string;
|
|
491
|
-
};
|
|
492
|
-
}>;
|
|
493
|
-
required: string[];
|
|
494
|
-
};
|
|
589
|
+
parameters: JsonSchemaObject;
|
|
495
590
|
};
|
|
496
591
|
}
|
|
497
592
|
/** 聊天消息(内部格式) */
|
|
@@ -525,444 +620,6 @@ interface ResponsesApiTool {
|
|
|
525
620
|
sources?: string[];
|
|
526
621
|
}
|
|
527
622
|
|
|
528
|
-
/**
|
|
529
|
-
* AI Chat 事件系统
|
|
530
|
-
*
|
|
531
|
-
* 模块化的事件类型定义,用于 Agent 与前端之间的通信。
|
|
532
|
-
*
|
|
533
|
-
* 设计原则:
|
|
534
|
-
* 1. 每种事件类型有明确的数据结构
|
|
535
|
-
* 2. 事件分组便于管理和扩展
|
|
536
|
-
* 3. 类型安全,避免 unknown
|
|
537
|
-
* 4. 统一的时间追踪(开始/结束/耗时)
|
|
538
|
-
*/
|
|
539
|
-
/** 搜索结果项 */
|
|
540
|
-
interface SearchResult {
|
|
541
|
-
title: string;
|
|
542
|
-
url: string;
|
|
543
|
-
snippet: string;
|
|
544
|
-
}
|
|
545
|
-
/** 工具调用状态 */
|
|
546
|
-
type ToolCallStatus = 'pending' | 'running' | 'success' | 'error';
|
|
547
|
-
/** 工具调用信息(用于前端状态管理) */
|
|
548
|
-
interface ToolCallInfo {
|
|
549
|
-
id: string;
|
|
550
|
-
name: string;
|
|
551
|
-
args: Record<string, unknown>;
|
|
552
|
-
status: ToolCallStatus;
|
|
553
|
-
result?: string;
|
|
554
|
-
error?: string;
|
|
555
|
-
startedAt?: number;
|
|
556
|
-
duration?: number;
|
|
557
|
-
}
|
|
558
|
-
/** Token 使用统计 */
|
|
559
|
-
interface TokenUsage {
|
|
560
|
-
promptTokens: number;
|
|
561
|
-
completionTokens: number;
|
|
562
|
-
totalTokens: number;
|
|
563
|
-
/** 思考 token 数(如果有) */
|
|
564
|
-
reasoningTokens?: number;
|
|
565
|
-
/** 缓存命中 token 数(如果有) */
|
|
566
|
-
cachedTokens?: number;
|
|
567
|
-
}
|
|
568
|
-
/** 错误类别 - 参考 AI SDK 设计 */
|
|
569
|
-
type ErrorCategory = 'api' | 'rate_limit' | 'validation' | 'tool' | 'timeout' | 'abort' | 'parse' | 'unknown';
|
|
570
|
-
/** 错误详情 - 结构化错误信息 */
|
|
571
|
-
interface ErrorDetails {
|
|
572
|
-
/** 错误分类 */
|
|
573
|
-
category: ErrorCategory;
|
|
574
|
-
/** 人类可读的错误信息 */
|
|
575
|
-
message: string;
|
|
576
|
-
/** 错误代码(如 'RATE_LIMIT', 'NETWORK_ERROR') */
|
|
577
|
-
code?: string;
|
|
578
|
-
/** HTTP 状态码(如果适用) */
|
|
579
|
-
statusCode?: number;
|
|
580
|
-
/** HTTP 状态文本 */
|
|
581
|
-
statusText?: string;
|
|
582
|
-
/** 是否可重试 */
|
|
583
|
-
retryable?: boolean;
|
|
584
|
-
/** 重试等待时间(秒) */
|
|
585
|
-
retryAfter?: number;
|
|
586
|
-
/** 原始错误信息(用于调试) */
|
|
587
|
-
cause?: string;
|
|
588
|
-
/** 错误发生的上下文(如模型名、工具名) */
|
|
589
|
-
context?: string;
|
|
590
|
-
}
|
|
591
|
-
/** 思考开始事件 */
|
|
592
|
-
interface ThinkingStartEvent {
|
|
593
|
-
type: 'thinking_start';
|
|
594
|
-
data: {
|
|
595
|
-
/** 开始时间戳(毫秒) */
|
|
596
|
-
startedAt: number;
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
/** 思考内容增量事件 */
|
|
600
|
-
interface ThinkingDeltaEvent {
|
|
601
|
-
type: 'thinking_delta';
|
|
602
|
-
data: {
|
|
603
|
-
/** 增量内容 */
|
|
604
|
-
content: string;
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
/** 思考结束事件 */
|
|
608
|
-
interface ThinkingEndEvent {
|
|
609
|
-
type: 'thinking_end';
|
|
610
|
-
data: {
|
|
611
|
-
/** 结束时间戳(毫秒) */
|
|
612
|
-
endedAt: number;
|
|
613
|
-
/** 思考耗时(毫秒) */
|
|
614
|
-
duration: number;
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
/** 思考相关事件联合类型 */
|
|
618
|
-
type ThinkingEvent = ThinkingStartEvent | ThinkingDeltaEvent | ThinkingEndEvent;
|
|
619
|
-
/** 搜索开始事件 */
|
|
620
|
-
interface SearchStartEvent {
|
|
621
|
-
type: 'search_start';
|
|
622
|
-
data: {
|
|
623
|
-
/** 搜索查询词 */
|
|
624
|
-
query: string;
|
|
625
|
-
/** 开始时间戳(毫秒) */
|
|
626
|
-
startedAt: number;
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
/** 搜索结果事件(成功完成) */
|
|
630
|
-
interface SearchResultEvent {
|
|
631
|
-
type: 'search_result';
|
|
632
|
-
data: {
|
|
633
|
-
/** 搜索结果列表 */
|
|
634
|
-
results: SearchResult[];
|
|
635
|
-
/** 结束时间戳(毫秒) */
|
|
636
|
-
endedAt: number;
|
|
637
|
-
/** 搜索耗时(毫秒) */
|
|
638
|
-
duration: number;
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
/** 搜索结束事件(失败或取消) */
|
|
642
|
-
interface SearchEndEvent {
|
|
643
|
-
type: 'search_end';
|
|
644
|
-
data: {
|
|
645
|
-
/** 是否成功 */
|
|
646
|
-
success: boolean;
|
|
647
|
-
/** 错误信息(失败时) */
|
|
648
|
-
error?: string;
|
|
649
|
-
/** 结束时间戳(毫秒) */
|
|
650
|
-
endedAt: number;
|
|
651
|
-
/** 搜索耗时(毫秒) */
|
|
652
|
-
duration: number;
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
/** 搜索相关事件联合类型 */
|
|
656
|
-
type SearchEvent = SearchStartEvent | SearchResultEvent | SearchEndEvent;
|
|
657
|
-
/** 工具调用开始事件 */
|
|
658
|
-
interface ToolCallStartEvent {
|
|
659
|
-
type: 'tool_call_start';
|
|
660
|
-
data: {
|
|
661
|
-
/** 工具调用 ID */
|
|
662
|
-
id: string;
|
|
663
|
-
/** 工具名称 */
|
|
664
|
-
name: string;
|
|
665
|
-
/** 工具参数 */
|
|
666
|
-
args: Record<string, unknown>;
|
|
667
|
-
/** 开始时间戳(毫秒) */
|
|
668
|
-
startedAt: number;
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
/** 副作用定义(从 types.ts 复制,避免循环依赖) */
|
|
672
|
-
interface SideEffect {
|
|
673
|
-
type: string;
|
|
674
|
-
success: boolean;
|
|
675
|
-
data?: unknown;
|
|
676
|
-
message?: string;
|
|
677
|
-
}
|
|
678
|
-
/** 工具调用结果事件 */
|
|
679
|
-
interface ToolCallResultEvent {
|
|
680
|
-
type: 'tool_call_result';
|
|
681
|
-
data: {
|
|
682
|
-
/** 工具调用 ID */
|
|
683
|
-
id: string;
|
|
684
|
-
/** 工具名称 */
|
|
685
|
-
name: string;
|
|
686
|
-
/** 执行结果 */
|
|
687
|
-
result: string;
|
|
688
|
-
/** 是否成功 */
|
|
689
|
-
success: boolean;
|
|
690
|
-
/** 错误信息(失败时) */
|
|
691
|
-
error?: string;
|
|
692
|
-
/** 结束时间戳(毫秒) */
|
|
693
|
-
endedAt: number;
|
|
694
|
-
/** 执行耗时(毫秒) */
|
|
695
|
-
duration: number;
|
|
696
|
-
/**
|
|
697
|
-
* 工具副作用
|
|
698
|
-
* 前端可根据此字段处理通知、刷新文件列表等
|
|
699
|
-
*/
|
|
700
|
-
sideEffects?: SideEffect[];
|
|
701
|
-
/**
|
|
702
|
-
* 结果类型(用于前端渲染)
|
|
703
|
-
*
|
|
704
|
-
* 当工具定义了 resultType 且执行成功时,前端会根据此类型生成对应的 ContentPart
|
|
705
|
-
* 例如:resultType: 'weather' 会生成 { type: 'weather', ...result }
|
|
706
|
-
*/
|
|
707
|
-
resultType?: string;
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
/** 工具输出增量事件(用于 stdout/stderr 流式展示) */
|
|
711
|
-
interface ToolCallOutputEvent {
|
|
712
|
-
type: 'tool_call_output';
|
|
713
|
-
data: {
|
|
714
|
-
/** 工具调用 ID */
|
|
715
|
-
id: string;
|
|
716
|
-
/** 工具名称 */
|
|
717
|
-
name: string;
|
|
718
|
-
/** 输出流类型 */
|
|
719
|
-
stream: 'stdout' | 'stderr';
|
|
720
|
-
/** 输出增量内容 */
|
|
721
|
-
chunk: string;
|
|
722
|
-
/** 时间戳 */
|
|
723
|
-
at: number;
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
/** 工具执行批准请求事件(manual 模式) */
|
|
727
|
-
interface ToolApprovalRequestEvent {
|
|
728
|
-
type: 'tool_approval_request';
|
|
729
|
-
data: {
|
|
730
|
-
/** 工具调用 ID */
|
|
731
|
-
id: string;
|
|
732
|
-
/** 工具名称 */
|
|
733
|
-
name: string;
|
|
734
|
-
/** 工具参数 */
|
|
735
|
-
args: Record<string, unknown>;
|
|
736
|
-
/** 请求时间戳 */
|
|
737
|
-
requestedAt: number;
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
/** 工具相关事件联合类型 */
|
|
741
|
-
type ToolEvent = ToolCallStartEvent | ToolCallResultEvent | ToolApprovalRequestEvent | ToolCallOutputEvent;
|
|
742
|
-
/** 文本增量事件 */
|
|
743
|
-
interface TextDeltaEvent {
|
|
744
|
-
type: 'text_delta';
|
|
745
|
-
data: {
|
|
746
|
-
/** 增量文本 */
|
|
747
|
-
content: string;
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
/** 文本相关事件联合类型 */
|
|
751
|
-
type TextEvent = TextDeltaEvent;
|
|
752
|
-
/** 图片事件 */
|
|
753
|
-
interface ImageEvent {
|
|
754
|
-
type: 'image';
|
|
755
|
-
data: {
|
|
756
|
-
/** 图片路径 */
|
|
757
|
-
path?: string;
|
|
758
|
-
/** Base64 编码 */
|
|
759
|
-
base64?: string;
|
|
760
|
-
/** MIME 类型 */
|
|
761
|
-
mimeType?: string;
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
/** 视频事件 */
|
|
765
|
-
interface VideoEvent {
|
|
766
|
-
type: 'video';
|
|
767
|
-
data: {
|
|
768
|
-
/** 视频路径 */
|
|
769
|
-
path: string;
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
/** 媒体相关事件联合类型 */
|
|
773
|
-
type MediaEvent = ImageEvent | VideoEvent;
|
|
774
|
-
/** 流开始事件 */
|
|
775
|
-
interface StreamStartEvent {
|
|
776
|
-
type: 'stream_start';
|
|
777
|
-
data: {
|
|
778
|
-
/** 请求 ID */
|
|
779
|
-
requestId?: string;
|
|
780
|
-
/** 使用的模型 */
|
|
781
|
-
model: string;
|
|
782
|
-
/** 开始时间戳 */
|
|
783
|
-
startedAt: number;
|
|
784
|
-
};
|
|
785
|
-
}
|
|
786
|
-
/** 完成事件 */
|
|
787
|
-
interface DoneEvent {
|
|
788
|
-
type: 'done';
|
|
789
|
-
data: {
|
|
790
|
-
/** 完整的最终文本 */
|
|
791
|
-
text: string;
|
|
792
|
-
/** Token 使用统计 */
|
|
793
|
-
usage?: TokenUsage;
|
|
794
|
-
/** 总耗时(毫秒) */
|
|
795
|
-
duration?: number;
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
/** 错误事件 - 结构化错误信息 */
|
|
799
|
-
interface ErrorEvent {
|
|
800
|
-
type: 'error';
|
|
801
|
-
data: ErrorDetails;
|
|
802
|
-
}
|
|
803
|
-
/** 中止事件 - 用户主动取消 */
|
|
804
|
-
interface AbortEvent {
|
|
805
|
-
type: 'abort';
|
|
806
|
-
data: {
|
|
807
|
-
/** 中止原因 */
|
|
808
|
-
reason?: string;
|
|
809
|
-
/** 中止时间戳 */
|
|
810
|
-
abortedAt: number;
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
/** 状态相关事件联合类型 */
|
|
814
|
-
type StatusEvent = StreamStartEvent | DoneEvent | ErrorEvent | AbortEvent;
|
|
815
|
-
/** 步骤开始事件 */
|
|
816
|
-
interface StepStartEvent {
|
|
817
|
-
type: 'step_start';
|
|
818
|
-
data: {
|
|
819
|
-
/** 步骤编号(从 1 开始) */
|
|
820
|
-
stepNumber: number;
|
|
821
|
-
/** 步骤描述(可选) */
|
|
822
|
-
description?: string;
|
|
823
|
-
/** 开始时间戳 */
|
|
824
|
-
startedAt: number;
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
/** 步骤结束事件 */
|
|
828
|
-
interface StepEndEvent {
|
|
829
|
-
type: 'step_end';
|
|
830
|
-
data: {
|
|
831
|
-
/** 步骤编号 */
|
|
832
|
-
stepNumber: number;
|
|
833
|
-
/** 结束时间戳 */
|
|
834
|
-
endedAt: number;
|
|
835
|
-
/** 耗时(毫秒) */
|
|
836
|
-
duration: number;
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
/** 步骤相关事件联合类型 */
|
|
840
|
-
type StepEvent = StepStartEvent | StepEndEvent;
|
|
841
|
-
/** 所有事件类型 */
|
|
842
|
-
type ChatEvent = ThinkingEvent | SearchEvent | ToolEvent | TextEvent | MediaEvent | StatusEvent | StepEvent;
|
|
843
|
-
/** 事件类型字符串 */
|
|
844
|
-
type ChatEventType = ChatEvent['type'];
|
|
845
|
-
/**
|
|
846
|
-
* 创建思考开始事件
|
|
847
|
-
*/
|
|
848
|
-
declare function createThinkingStart(): ThinkingStartEvent;
|
|
849
|
-
/**
|
|
850
|
-
* 创建思考增量事件
|
|
851
|
-
*/
|
|
852
|
-
declare function createThinkingDelta(content: string): ThinkingDeltaEvent;
|
|
853
|
-
/**
|
|
854
|
-
* 创建思考结束事件
|
|
855
|
-
*/
|
|
856
|
-
declare function createThinkingEnd(startedAt: number): ThinkingEndEvent;
|
|
857
|
-
/**
|
|
858
|
-
* 创建搜索开始事件
|
|
859
|
-
*/
|
|
860
|
-
declare function createSearchStart(query: string): SearchStartEvent;
|
|
861
|
-
/**
|
|
862
|
-
* 创建搜索结果事件(成功)
|
|
863
|
-
*/
|
|
864
|
-
declare function createSearchResult(results: SearchResult[], startedAt: number): SearchResultEvent;
|
|
865
|
-
/**
|
|
866
|
-
* 创建搜索结束事件(失败或取消)
|
|
867
|
-
*/
|
|
868
|
-
declare function createSearchEnd(success: boolean, startedAt: number, error?: string): SearchEndEvent;
|
|
869
|
-
/**
|
|
870
|
-
* 创建工具调用开始事件
|
|
871
|
-
*/
|
|
872
|
-
declare function createToolCallStart(id: string, name: string, args: Record<string, unknown>): ToolCallStartEvent;
|
|
873
|
-
/**
|
|
874
|
-
* 创建工具调用结果事件
|
|
875
|
-
*/
|
|
876
|
-
declare function createToolCallResult(id: string, name: string, result: string, success: boolean, startedAt: number, error?: string, sideEffects?: SideEffect[], resultType?: string): ToolCallResultEvent;
|
|
877
|
-
/**
|
|
878
|
-
* 创建文本增量事件
|
|
879
|
-
*/
|
|
880
|
-
declare function createTextDelta(content: string): TextDeltaEvent;
|
|
881
|
-
/**
|
|
882
|
-
* 创建流开始事件
|
|
883
|
-
*/
|
|
884
|
-
declare function createStreamStart(model: string, requestId?: string): StreamStartEvent;
|
|
885
|
-
/**
|
|
886
|
-
* 创建完成事件
|
|
887
|
-
*/
|
|
888
|
-
declare function createDone(text: string, usage?: TokenUsage, duration?: number): DoneEvent;
|
|
889
|
-
/**
|
|
890
|
-
* 创建错误事件(完整版)
|
|
891
|
-
*/
|
|
892
|
-
declare function createError(details: ErrorDetails): ErrorEvent;
|
|
893
|
-
/**
|
|
894
|
-
* 创建 API 错误事件
|
|
895
|
-
*/
|
|
896
|
-
declare function createApiError(message: string, options?: {
|
|
897
|
-
code?: string;
|
|
898
|
-
statusCode?: number;
|
|
899
|
-
statusText?: string;
|
|
900
|
-
retryable?: boolean;
|
|
901
|
-
retryAfter?: number;
|
|
902
|
-
cause?: string;
|
|
903
|
-
context?: string;
|
|
904
|
-
}): ErrorEvent;
|
|
905
|
-
/**
|
|
906
|
-
* 创建速率限制错误事件
|
|
907
|
-
*/
|
|
908
|
-
declare function createRateLimitError(message: string, retryAfter?: number, context?: string): ErrorEvent;
|
|
909
|
-
/**
|
|
910
|
-
* 创建工具错误事件
|
|
911
|
-
*/
|
|
912
|
-
declare function createToolError(message: string, toolName: string, cause?: string): ErrorEvent;
|
|
913
|
-
/**
|
|
914
|
-
* 创建超时错误事件
|
|
915
|
-
*/
|
|
916
|
-
declare function createTimeoutError(message: string, context?: string): ErrorEvent;
|
|
917
|
-
/**
|
|
918
|
-
* 创建解析错误事件
|
|
919
|
-
*/
|
|
920
|
-
declare function createParseError(message: string, cause?: string): ErrorEvent;
|
|
921
|
-
/**
|
|
922
|
-
* 创建中止事件
|
|
923
|
-
*/
|
|
924
|
-
declare function createAbort(reason?: string): AbortEvent;
|
|
925
|
-
/**
|
|
926
|
-
* 创建步骤开始事件
|
|
927
|
-
*/
|
|
928
|
-
declare function createStepStart(stepNumber: number, description?: string): StepStartEvent;
|
|
929
|
-
/**
|
|
930
|
-
* 创建步骤结束事件
|
|
931
|
-
*/
|
|
932
|
-
declare function createStepEnd(stepNumber: number, startedAt: number): StepEndEvent;
|
|
933
|
-
/**
|
|
934
|
-
* 创建图片事件
|
|
935
|
-
*/
|
|
936
|
-
declare function createImage(options: {
|
|
937
|
-
path?: string;
|
|
938
|
-
base64?: string;
|
|
939
|
-
mimeType?: string;
|
|
940
|
-
}): ImageEvent;
|
|
941
|
-
/**
|
|
942
|
-
* 创建视频事件
|
|
943
|
-
*/
|
|
944
|
-
declare function createVideo(path: string): VideoEvent;
|
|
945
|
-
/** 检查是否为思考事件 */
|
|
946
|
-
declare function isThinkingEvent(event: ChatEvent): event is ThinkingEvent;
|
|
947
|
-
/** 检查是否为搜索事件 */
|
|
948
|
-
declare function isSearchEvent(event: ChatEvent): event is SearchEvent;
|
|
949
|
-
/** 检查是否为工具事件 */
|
|
950
|
-
declare function isToolEvent(event: ChatEvent): event is ToolEvent;
|
|
951
|
-
/** 检查是否为文本事件 */
|
|
952
|
-
declare function isTextEvent(event: ChatEvent): event is TextEvent;
|
|
953
|
-
/** 检查是否为媒体事件 */
|
|
954
|
-
declare function isMediaEvent(event: ChatEvent): event is MediaEvent;
|
|
955
|
-
/** 检查是否为状态事件 */
|
|
956
|
-
declare function isStatusEvent(event: ChatEvent): event is StatusEvent;
|
|
957
|
-
/** 检查是否为错误事件 */
|
|
958
|
-
declare function isErrorEvent(event: ChatEvent): event is ErrorEvent;
|
|
959
|
-
/** 检查是否为中止事件 */
|
|
960
|
-
declare function isAbortEvent(event: ChatEvent): event is AbortEvent;
|
|
961
|
-
/** 检查是否为步骤事件 */
|
|
962
|
-
declare function isStepEvent(event: ChatEvent): event is StepEvent;
|
|
963
|
-
/** 检查错误是否可重试 */
|
|
964
|
-
declare function isRetryableError(event: ChatEvent): boolean;
|
|
965
|
-
|
|
966
623
|
/** 运行时配置(API Keys 和 URLs) */
|
|
967
624
|
interface RuntimeConfig {
|
|
968
625
|
arkApiKey: string;
|
|
@@ -995,6 +652,10 @@ declare class HybridAgent {
|
|
|
995
652
|
private tools;
|
|
996
653
|
/** 工具配置(用于异步初始化) */
|
|
997
654
|
private toolConfig;
|
|
655
|
+
/** MCP 客户端管理器 */
|
|
656
|
+
private mcpManager;
|
|
657
|
+
/** MCP 服务器配置 */
|
|
658
|
+
private mcpConfigs;
|
|
998
659
|
constructor(config: AgentConfig, toolExecutor?: ToolExecutor$1);
|
|
999
660
|
/** 异步初始化工具(在第一次 chat 前调用) */
|
|
1000
661
|
private asyncInit;
|
|
@@ -1040,6 +701,14 @@ declare class HybridAgent {
|
|
|
1040
701
|
getConfig(): RuntimeConfig;
|
|
1041
702
|
/** 获取所有支持的模型 */
|
|
1042
703
|
getSupportedModels(): ModelOption[];
|
|
704
|
+
/** 获取 MCP 连接状态 */
|
|
705
|
+
getMcpConnections(): McpConnectionInfo[];
|
|
706
|
+
/**
|
|
707
|
+
* 销毁 Agent(优雅关闭所有 MCP 连接)
|
|
708
|
+
*
|
|
709
|
+
* 桌面客户端退出时应调用此方法。
|
|
710
|
+
*/
|
|
711
|
+
destroy(): Promise<void>;
|
|
1043
712
|
}
|
|
1044
713
|
|
|
1045
714
|
/**
|
|
@@ -1051,22 +720,10 @@ declare class HybridAgent {
|
|
|
1051
720
|
* 3. 所有 Adapter 返回标准化的 StreamChunk
|
|
1052
721
|
*/
|
|
1053
722
|
|
|
1054
|
-
/** 简化的工具定义(供 Adapter 使用) */
|
|
1055
723
|
interface SimpleToolDefinition {
|
|
1056
724
|
name: string;
|
|
1057
725
|
description: string;
|
|
1058
|
-
parameters:
|
|
1059
|
-
type: 'object';
|
|
1060
|
-
properties: Record<string, {
|
|
1061
|
-
type: string;
|
|
1062
|
-
description: string;
|
|
1063
|
-
enum?: string[];
|
|
1064
|
-
items?: {
|
|
1065
|
-
type: string;
|
|
1066
|
-
};
|
|
1067
|
-
}>;
|
|
1068
|
-
required: string[];
|
|
1069
|
-
};
|
|
726
|
+
parameters: JsonSchemaObject;
|
|
1070
727
|
}
|
|
1071
728
|
/** 流式响应块类型 */
|
|
1072
729
|
type StreamChunkType = 'text' | 'thinking' | 'thinking_done' | 'tool_call' | 'search_result' | 'done' | 'error';
|
|
@@ -1085,6 +742,14 @@ interface SearchResultItem {
|
|
|
1085
742
|
snippet: string;
|
|
1086
743
|
}
|
|
1087
744
|
/** 流式响应块 - 所有 Adapter 必须返回此格式 */
|
|
745
|
+
/** Token 使用统计 */
|
|
746
|
+
interface StreamTokenUsage {
|
|
747
|
+
promptTokens?: number;
|
|
748
|
+
completionTokens?: number;
|
|
749
|
+
totalTokens?: number;
|
|
750
|
+
reasoningTokens?: number;
|
|
751
|
+
cachedTokens?: number;
|
|
752
|
+
}
|
|
1088
753
|
interface StreamChunk {
|
|
1089
754
|
type: StreamChunkType;
|
|
1090
755
|
text?: string;
|
|
@@ -1092,6 +757,8 @@ interface StreamChunk {
|
|
|
1092
757
|
toolCall?: ToolCallRequest;
|
|
1093
758
|
searchResults?: SearchResultItem[];
|
|
1094
759
|
finishReason?: 'stop' | 'tool_calls' | 'length' | 'error';
|
|
760
|
+
/** Token 使用统计(done 事件携带) */
|
|
761
|
+
usage?: StreamTokenUsage;
|
|
1095
762
|
error?: string;
|
|
1096
763
|
}
|
|
1097
764
|
/** 标准化消息 - Orchestrator 内部使用 */
|
|
@@ -1206,6 +873,15 @@ interface OrchestratorConfig {
|
|
|
1206
873
|
* 返回 true 表示批准执行,false 表示跳过
|
|
1207
874
|
*/
|
|
1208
875
|
onToolApprovalRequest?: ToolApprovalCallback;
|
|
876
|
+
/**
|
|
877
|
+
* 客户端工具名称集合(透传模式)
|
|
878
|
+
*
|
|
879
|
+
* 这些工具不在服务端执行,而是:
|
|
880
|
+
* 1. 发送 tool_call_request 事件给客户端
|
|
881
|
+
* 2. 结束本轮对话
|
|
882
|
+
* 3. 客户端执行后,发新请求继续对话
|
|
883
|
+
*/
|
|
884
|
+
clientToolNames?: Set<string>;
|
|
1209
885
|
}
|
|
1210
886
|
/** Orchestrator 上下文 */
|
|
1211
887
|
interface OrchestratorContext {
|
|
@@ -1219,6 +895,12 @@ interface OrchestratorContext {
|
|
|
1219
895
|
signal: AbortSignal;
|
|
1220
896
|
/** 图片列表 */
|
|
1221
897
|
images?: string[];
|
|
898
|
+
/**
|
|
899
|
+
* 客户端工具名称集合(透传模式)
|
|
900
|
+
*
|
|
901
|
+
* 这些工具不在服务端执行,而是发送 tool_call_request 事件给客户端
|
|
902
|
+
*/
|
|
903
|
+
clientToolNames?: Set<string>;
|
|
1222
904
|
}
|
|
1223
905
|
/** Orchestrator 选项 */
|
|
1224
906
|
interface OrchestratorOptions {
|
|
@@ -1372,6 +1054,14 @@ interface RawSearchResult {
|
|
|
1372
1054
|
/**
|
|
1373
1055
|
* Protocol 原始事件
|
|
1374
1056
|
*/
|
|
1057
|
+
/** Token 使用统计(Protocol 层) */
|
|
1058
|
+
interface RawTokenUsage {
|
|
1059
|
+
promptTokens?: number;
|
|
1060
|
+
completionTokens?: number;
|
|
1061
|
+
totalTokens?: number;
|
|
1062
|
+
reasoningTokens?: number;
|
|
1063
|
+
cachedTokens?: number;
|
|
1064
|
+
}
|
|
1375
1065
|
interface RawEvent {
|
|
1376
1066
|
type: RawEventType;
|
|
1377
1067
|
delta?: string;
|
|
@@ -1379,6 +1069,8 @@ interface RawEvent {
|
|
|
1379
1069
|
searchQuery?: string;
|
|
1380
1070
|
searchResults?: RawSearchResult[];
|
|
1381
1071
|
finishReason?: 'stop' | 'tool_calls' | 'length' | 'error';
|
|
1072
|
+
/** Token 使用统计(done 事件携带) */
|
|
1073
|
+
usage?: RawTokenUsage;
|
|
1382
1074
|
error?: string;
|
|
1383
1075
|
}
|
|
1384
1076
|
/**
|
|
@@ -1396,24 +1088,11 @@ interface ProtocolMessage {
|
|
|
1396
1088
|
/** 工具名称(tool 消息,Gemini 需要) */
|
|
1397
1089
|
toolName?: string;
|
|
1398
1090
|
}
|
|
1399
|
-
|
|
1400
|
-
* Protocol 工具定义(简化格式)
|
|
1401
|
-
*/
|
|
1091
|
+
|
|
1402
1092
|
interface ProtocolToolDefinition {
|
|
1403
1093
|
name: string;
|
|
1404
1094
|
description: string;
|
|
1405
|
-
parameters:
|
|
1406
|
-
type: 'object';
|
|
1407
|
-
properties: Record<string, {
|
|
1408
|
-
type: string;
|
|
1409
|
-
description: string;
|
|
1410
|
-
enum?: string[];
|
|
1411
|
-
items?: {
|
|
1412
|
-
type: string;
|
|
1413
|
-
};
|
|
1414
|
-
}>;
|
|
1415
|
-
required: string[];
|
|
1416
|
-
};
|
|
1095
|
+
parameters: JsonSchemaObject;
|
|
1417
1096
|
}
|
|
1418
1097
|
/**
|
|
1419
1098
|
* Protocol 请求选项
|
|
@@ -1727,53 +1406,26 @@ declare function createDefaultToolExecutor(defaultCwd?: string): ToolExecutor$1;
|
|
|
1727
1406
|
/**
|
|
1728
1407
|
* 调试日志工具
|
|
1729
1408
|
*
|
|
1730
|
-
*
|
|
1731
|
-
*
|
|
1732
|
-
*
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
*/
|
|
1738
|
-
|
|
1739
|
-
/**
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
/**
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
/**
|
|
1752
|
-
* 设置日志文件路径(仅 Node.js 环境有效)
|
|
1753
|
-
* @param path 日志文件路径,null 表示禁用文件输出
|
|
1754
|
-
*/
|
|
1755
|
-
setLogFile(path: string | null): void;
|
|
1756
|
-
/**
|
|
1757
|
-
* 获取日志文件路径
|
|
1758
|
-
*/
|
|
1759
|
-
getLogFile(): string | null;
|
|
1760
|
-
/**
|
|
1761
|
-
* 立即刷新日志到文件
|
|
1762
|
-
*/
|
|
1763
|
-
flush(): void;
|
|
1764
|
-
/**
|
|
1765
|
-
* 创建模块专用的 logger
|
|
1766
|
-
*/
|
|
1767
|
-
module(moduleName: string): {
|
|
1768
|
-
debug: (message: string, data?: unknown) => void;
|
|
1769
|
-
info: (message: string, data?: unknown) => void;
|
|
1770
|
-
warn: (message: string, data?: unknown) => void;
|
|
1771
|
-
error: (message: string, data?: unknown) => void;
|
|
1772
|
-
};
|
|
1773
|
-
debug: (module: string, message: string, data?: unknown) => void;
|
|
1774
|
-
info: (module: string, message: string, data?: unknown) => void;
|
|
1775
|
-
warn: (module: string, message: string, data?: unknown) => void;
|
|
1776
|
-
error: (module: string, message: string, data?: unknown) => void;
|
|
1777
|
-
};
|
|
1409
|
+
* 通过 DebugLogger.enable(true) 全局开启,
|
|
1410
|
+
* 通过 DebugLogger.setLogFile(path) 同时写入 JSONL 文件,
|
|
1411
|
+
* 各模块通过 DebugLogger.module('Name') 创建带前缀的 logger。
|
|
1412
|
+
*/
|
|
1413
|
+
declare class DebugLogger {
|
|
1414
|
+
private prefix;
|
|
1415
|
+
private constructor();
|
|
1416
|
+
/** 全局启停调试日志 */
|
|
1417
|
+
static enable(value: boolean): void;
|
|
1418
|
+
/** 查询是否已启用 */
|
|
1419
|
+
static isEnabled(): boolean;
|
|
1420
|
+
/** 设置日志文件路径(JSONL 格式,追加写入) */
|
|
1421
|
+
static setLogFile(filePath: string): void;
|
|
1422
|
+
/** 创建模块专用 logger */
|
|
1423
|
+
static module(name: string): DebugLogger;
|
|
1424
|
+
debug(...args: unknown[]): void;
|
|
1425
|
+
info(...args: unknown[]): void;
|
|
1426
|
+
warn(...args: unknown[]): void;
|
|
1427
|
+
error(...args: unknown[]): void;
|
|
1428
|
+
private writeToFile;
|
|
1429
|
+
}
|
|
1778
1430
|
|
|
1779
|
-
export { type
|
|
1431
|
+
export { type AdapterConfig, type AgentConfig, AnthropicProtocol, ArkProtocol, type AutoRunConfig$1 as AutoRunConfig, type AutoRunMode, CLAUDE_FAMILY, ChatEvent, type ChatMessage, type ChatMode, type ChatOptions, ChatOrchestrator, DEEPSEEK_FAMILY, DEFAULT_MODEL, DOUBAO_FAMILY, DebugLogger, DeepSeekProtocol, GEMINI_FAMILY, GPT_FAMILY, GeminiProtocol, HybridAgent, MODELS, MODEL_FAMILIES, MODEL_REGISTRY, type McpConnectionInfo, type McpConnectionStatus, type McpServerConfig, type ModelFamilyConfig, type ModelFamilyId, type ModelOption, type ModelRegistryEntry, OpenAIProtocol, type OrchestratorConfig, type OrchestratorContext, type OrchestratorOptions, type ToolExecutor as OrchestratorToolExecutor, type Protocol, type ProtocolConfig, type ProtocolId, type ProtocolMessage, type ProtocolToolCall, type ProtocolToolDefinition, type ProviderAdapter, type ProviderType, QWEN_FAMILY, QwenProtocol, type RawEvent, type RawEventType, type RawSearchResult, type RawToolCall, type ResponsesApiTool, type RouteResult, type RuntimeConfig, type SearchResultItem, type SearchStrategy, type SideEffect, type SimpleToolDefinition, type StandardMessage, type StreamChunk, type StreamChunkType, type StreamOnceOptions, type StreamOptions, type ThinkingFormat, type ThinkingMode, type Tool, type ToolCallFormat, type ToolCallRequest, type ToolConfigItem, type ToolContext, type ToolDefinition, type ToolExecutor$1 as ToolExecutor, type ToolPlugin, type ToolResult, UnifiedAdapter, type UnifiedAdapterConfig, type UserToolDefinition, createAnthropicProtocol, createArkProtocol, createDeepSeekProtocol, createDefaultToolExecutor, createGeminiProtocol, createOpenAIProtocol, createOrchestrator, createQwenProtocol, createUnifiedAdapter, getDefaultProvider, getModelByModelId, getModelEntry, getModelFamily, getModelProtocol, getModelSearchStrategy, getModelsByFamily, getModelsByProtocol, getVisibleModels, isModelForProvider, modelSupportsNativeSearch, modelSupportsThinking, resolveTools, routeModelToProvider, routeModelWithDetails, tool, tools };
|