@huyooo/ai-chat-core 0.2.13 → 0.2.14

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.ts CHANGED
@@ -1,107 +1,197 @@
1
+ import * as fs from 'fs';
2
+
1
3
  /**
2
- * 模型路由模块
4
+ * 模型注册表
3
5
  *
4
- * 根据模型名称将请求路由到对应的 Provider
6
+ * 核心设计:Protocol + Family 分离
7
+ * - Protocol:负责 API 通信协议(HTTP/SSE/认证)
8
+ * - Family:负责模型行为差异(thinking格式、搜索方式、工具格式)
5
9
  *
6
- * 设计原则:
7
- * 1. 配置驱动:路由规则集中管理,易于扩展
8
- * 2. 优先级机制:高优先级规则先匹配
9
- * 3. 多种匹配模式:支持精确、前缀、包含、正则匹配
10
- */
11
- /** Provider 类型(API 供应商) */
12
- type ProviderType = 'ark' | 'qwen' | 'gemini' | 'openrouter' | 'vercel';
13
- /** 路由规则匹配类型 */
14
- type RouteMatchType = 'exact' | 'prefix' | 'contains' | 'regex';
15
- /** 单条路由规则 */
16
- interface RouteRule {
17
- /** 规则类型 */
18
- type: RouteMatchType;
19
- /** 匹配模式(大小写不敏感) */
20
- pattern: string;
21
- /** 目标 Provider */
22
- provider: ProviderType;
23
- /** 规则优先级(数字越大越优先,默认 0) */
24
- priority: number;
25
- /** 规则描述(调试用) */
26
- description?: string;
10
+ * 这样设计的好处:
11
+ * 1. 同协议不同行为的模型可以复用协议层(如 ARK 上的豆包和 DeepSeek)
12
+ * 2. 新增模型只需配置 family,无需修改 adapter 代码
13
+ * 3. 行为差异集中管理,易于维护
14
+ */
15
+ /** 模型家族 ID */
16
+ type ModelFamilyId = 'doubao' | 'deepseek' | 'qwen' | 'gemini' | 'gpt' | 'claude';
17
+ /** 协议类型 */
18
+ type ProtocolId = 'ark' | 'deepseek' | 'qwen' | 'gemini' | 'openai' | 'anthropic';
19
+ /** Thinking 输出格式 */
20
+ type ThinkingFormat = 'reasoning' | 'thinking_enabled' | 'thought_signature' | 'none';
21
+ /** 搜索实现方式 */
22
+ type SearchStrategy = 'native_web_search' | 'native_enable' | 'google_search' | 'tool_based';
23
+ /** 工具调用格式 */
24
+ type ToolCallFormat = 'responses' | 'openai' | 'gemini';
25
+ /**
26
+ * 模型家族配置
27
+ * 定义同一家族模型的共同行为特征
28
+ */
29
+ interface ModelFamilyConfig {
30
+ /** 家族 ID */
31
+ id: ModelFamilyId;
32
+ /** 显示名称 */
33
+ displayName: string;
34
+ /** 是否支持图片理解 */
35
+ supportsVision: boolean;
36
+ /** 是否支持 thinking */
37
+ supportsThinking: boolean;
38
+ /** Thinking 输出格式 */
39
+ thinkingFormat: ThinkingFormat;
40
+ /** 是否支持原生搜索 */
41
+ supportsNativeSearch: boolean;
42
+ /** 搜索实现方式 */
43
+ searchStrategy: SearchStrategy;
44
+ /** 工具调用格式 */
45
+ toolCallFormat: ToolCallFormat;
46
+ /** 默认最大输出 token */
47
+ defaultMaxTokens?: number;
48
+ /** 是否需要特殊处理(如 Gemini 的 thought_signature) */
49
+ requiresSpecialHandling?: string[];
50
+ }
51
+ /** 豆包家族 */
52
+ declare const DOUBAO_FAMILY: ModelFamilyConfig;
53
+ /** DeepSeek 家族 */
54
+ declare const DEEPSEEK_FAMILY: ModelFamilyConfig;
55
+ /** 通义千问家族 */
56
+ /** Qwen 家族(使用 Tavily 统一搜索) */
57
+ declare const QWEN_FAMILY: ModelFamilyConfig;
58
+ /** Gemini 家族(注意:googleSearch 不能与其他工具同时使用,有工具时走 Tavily) */
59
+ declare const GEMINI_FAMILY: ModelFamilyConfig;
60
+ /** GPT 家族 */
61
+ declare const GPT_FAMILY: ModelFamilyConfig;
62
+ /** Claude 家族(使用 Vercel AI SDK / @ai-sdk/anthropic) */
63
+ declare const CLAUDE_FAMILY: ModelFamilyConfig;
64
+ /** 家族配置映射 */
65
+ declare const MODEL_FAMILIES: Record<ModelFamilyId, ModelFamilyConfig>;
66
+ /**
67
+ * 模型注册项
68
+ */
69
+ interface ModelRegistryEntry {
70
+ /** 模型 ID(API 调用用) */
71
+ id: string;
72
+ /** 显示名称 */
73
+ displayName: string;
74
+ /** 所属家族 */
75
+ family: ModelFamilyId;
76
+ /** 使用的协议 */
77
+ protocol: ProtocolId;
78
+ /** 是否在前端显示 */
79
+ visible?: boolean;
80
+ /** 是否支持图片理解(优先级高于 family.supportsVision) */
81
+ supportsVision?: boolean;
82
+ /** 上下文窗口大小(如 "256K") */
83
+ contextWindow?: string;
84
+ /** 价格信息(数组,分行显示) */
85
+ pricing?: string[];
27
86
  }
87
+ /**
88
+ * 全局模型注册表
89
+ *
90
+ * 每个模型只有一家供应商,无需分组
91
+ */
92
+ declare const MODEL_REGISTRY: ModelRegistryEntry[];
93
+ /**
94
+ * 根据模型 ID 获取注册信息
95
+ */
96
+ declare function getModelEntry(modelId: string): ModelRegistryEntry | undefined;
97
+ /**
98
+ * 根据模型 ID 获取家族配置
99
+ */
100
+ declare function getModelFamily(modelId: string): ModelFamilyConfig | undefined;
101
+ /**
102
+ * 根据模型 ID 获取协议类型
103
+ */
104
+ declare function getModelProtocol(modelId: string): ProtocolId | undefined;
105
+ /**
106
+ * 获取所有可见模型(用于前端显示)
107
+ */
108
+ declare function getVisibleModels(): ModelRegistryEntry[];
109
+ /**
110
+ * 根据家族 ID 获取所有模型
111
+ */
112
+ declare function getModelsByFamily(familyId: ModelFamilyId): ModelRegistryEntry[];
113
+ /**
114
+ * 根据协议获取所有模型
115
+ */
116
+ declare function getModelsByProtocol(protocol: ProtocolId): ModelRegistryEntry[];
117
+ /**
118
+ * 检查模型是否支持 thinking
119
+ */
120
+ declare function modelSupportsThinking(modelId: string): boolean;
121
+ /**
122
+ * 检查模型是否支持原生搜索
123
+ */
124
+ declare function modelSupportsNativeSearch(modelId: string): boolean;
125
+ /**
126
+ * 获取模型的搜索策略
127
+ */
128
+ declare function getModelSearchStrategy(modelId: string): SearchStrategy;
129
+
130
+ /**
131
+ * 模型路由模块
132
+ *
133
+ * 根据模型 ID 查询对应的 Protocol 和 Family 配置
134
+ */
135
+
136
+ /** Provider 类型 = Protocol 类型 */
137
+ type ProviderType = ProtocolId;
28
138
  /** 路由结果 */
29
139
  interface RouteResult {
30
- /** 匹配的 Provider */
140
+ /** Protocol 类型 */
31
141
  provider: ProviderType;
32
- /** 匹配的规则(如果有) */
33
- matchedRule?: RouteRule;
34
- /** 是否使用了默认路由 */
142
+ /** 是否未注册(使用默认 Provider) */
35
143
  isDefault: boolean;
144
+ /** 模型注册信息 */
145
+ registryEntry?: ModelRegistryEntry;
146
+ /** 模型家族配置 */
147
+ familyConfig?: ModelFamilyConfig;
36
148
  }
37
149
  /**
38
- * 将模型路由到对应的 Provider
39
- *
40
- * @param model - 模型名称
41
- * @returns Provider 类型
150
+ * 获取模型的 Provider
42
151
  */
43
152
  declare function routeModelToProvider(model: string): ProviderType;
44
153
  /**
45
- * 将模型路由到对应的 Provider(带详细信息)
46
- *
47
- * @param model - 模型名称
48
- * @returns 路由结果(包含匹配规则信息)
154
+ * 获取模型的完整路由信息
49
155
  */
50
156
  declare function routeModelWithDetails(model: string): RouteResult;
51
- /**
52
- * 获取所有路由规则(调试用)
53
- */
54
- declare function getRouteRules(): readonly RouteRule[];
55
157
  /**
56
158
  * 获取默认 Provider
57
159
  */
58
160
  declare function getDefaultProvider(): ProviderType;
59
161
  /**
60
- * 检查模型是否匹配某个 Provider
61
- *
62
- * @param model - 模型名称
63
- * @param provider - Provider 类型
64
- * @returns 是否匹配
162
+ * 检查模型是否属于指定 Provider
65
163
  */
66
164
  declare function isModelForProvider(model: string, provider: ProviderType): boolean;
67
165
 
68
166
  /**
69
167
  * AI Chat Core 类型定义
70
- *
71
- * 注意:事件类型已迁移到 events.ts
72
168
  */
169
+
73
170
  /** 对话模式 */
74
- type ChatMode = 'agent' | 'plan' | 'ask';
171
+ type ChatMode = 'agent' | 'ask';
75
172
 
76
- /**
77
- * 简化的模型配置
78
- *
79
- * - modelId: 发送给 API 的模型 ID
80
- * - displayName: 前端显示名称
81
- * - group: 分组名称(由后端决定,前端只负责渲染)
82
- */
173
+ /** 模型选项(前端显示用) */
83
174
  interface ModelOption {
84
175
  /** 模型 ID(发送给 API) */
85
176
  modelId: string;
86
177
  /** 显示名称 */
87
178
  displayName: string;
88
- /** 分组名称(由后端决定,前端只负责渲染,必填) */
89
- group: string;
90
- /** 是否来自 OpenRouter(保留用于兼容,后续可能移除) */
91
- isOpenRouter?: boolean;
92
- /** 提供商名称(保留用于兼容,后续可能移除) */
93
- provider?: string;
179
+ /** 是否支持深度思考 */
180
+ supportsThinking: boolean;
181
+ /** 是否支持图片理解 */
182
+ supportsVision: boolean;
183
+ /** 用于模型项 hover 的特性描述(由后端定义,前端只渲染) */
184
+ tooltip?: {
185
+ features?: string[];
186
+ /** 开销信息(数组,分行显示) */
187
+ cost?: string[];
188
+ description?: string;
189
+ };
94
190
  }
95
191
  /**
96
- * 预定义模型列表(从 constants.ts 映射)
97
- *
98
- * 分组信息由后端决定,前端只负责渲染
192
+ * 预定义模型列表
99
193
  */
100
194
  declare const MODELS: ModelOption[];
101
- /** 获取原生模型 */
102
- declare function getNativeModels(): ModelOption[];
103
- /** 获取 OpenRouter 模型 */
104
- declare function getOpenRouterModels(): ModelOption[];
105
195
  /** 根据 modelId 获取模型 */
106
196
  declare function getModelByModelId(modelId: string): ModelOption | undefined;
107
197
  /** 工具批准回调函数 */
@@ -124,6 +214,10 @@ interface AgentConfig {
124
214
  openrouterApiKey?: string;
125
215
  /** OpenRouter API URL */
126
216
  openrouterApiUrl?: string;
217
+ /** Vercel API Key(用于 Vercel AI Gateway 访问 Claude) */
218
+ vercelApiKey?: string;
219
+ /** Tavily API Key(用于统一 Web Search) */
220
+ tavilyApiKey?: string;
127
221
  /** Gemini API Key (用于图片/视频,注意:中国大陆无法直接访问) */
128
222
  geminiApiKey: string;
129
223
  /** 当前工作目录(Current Working Directory) */
@@ -146,11 +240,6 @@ interface AgentConfig {
146
240
  * ```
147
241
  */
148
242
  tools?: ToolConfigItem[];
149
- /**
150
- * plan 模式的系统提示词(可选,有默认值)
151
- * 用于指导 AI 如何制定执行计划
152
- */
153
- planPrompt?: string;
154
243
  /**
155
244
  * 工具批准回调(manual 模式使用)
156
245
  * 返回 true 表示批准执行,false 表示跳过
@@ -196,6 +285,8 @@ interface ChatOptions {
196
285
  * - 'disabled': 强制关闭深度思考
197
286
  */
198
287
  thinkingMode?: ThinkingMode;
288
+ /** 启用的工具名称列表(agent 模式有效,ask 模式强制禁用) */
289
+ enabledTools?: string[];
199
290
  /** 自动运行配置 */
200
291
  autoRunConfig?: AutoRunConfig$1;
201
292
  /** 对话历史(从数据库加载,无状态架构) */
@@ -260,6 +351,7 @@ interface ToolContext {
260
351
  * description: '我的自定义工具',
261
352
  * parameters: { type: 'object', properties: {}, required: [] },
262
353
  * sideEffects: ['filesystem'], // 声明副作用
354
+ * resultType: 'my_result', // 结果类型(用于前端渲染)
263
355
  * execute: async (args, ctx) => '执行结果'
264
356
  * };
265
357
  * ```
@@ -293,6 +385,15 @@ interface Tool {
293
385
  * 注意:如果 execute 返回 ToolResult 带有 sideEffects,会覆盖此静态声明
294
386
  */
295
387
  sideEffects?: SideEffect$1[];
388
+ /**
389
+ * 结果类型(用于前端渲染)
390
+ *
391
+ * 当工具执行成功时,前端会根据此类型生成对应的 ContentPart
392
+ * 例如:resultType: 'weather' 会生成 { type: 'weather', ...result }
393
+ *
394
+ * 如果不指定,工具结果仅显示在 ToolCallPart 的折叠面板中
395
+ */
396
+ resultType?: string;
296
397
  /**
297
398
  * 执行函数
298
399
  *
@@ -305,7 +406,10 @@ interface Tool {
305
406
  /** 工具执行器接口(可由使用方实现,用于自定义命令执行环境) */
306
407
  interface ToolExecutor$1 {
307
408
  /** 执行 Shell 命令 */
308
- executeCommand(command: string, cwd?: string, signal?: AbortSignal): Promise<{
409
+ executeCommand(command: string, cwd?: string, signal?: AbortSignal, hooks?: {
410
+ onStdout?: (chunk: string) => void;
411
+ onStderr?: (chunk: string) => void;
412
+ }): Promise<{
309
413
  success: boolean;
310
414
  output?: string;
311
415
  error?: string;
@@ -406,6 +510,8 @@ interface ChatMessage {
406
510
  name: string;
407
511
  arguments: string;
408
512
  };
513
+ /** Gemini 模型需要的 thought_signature(用于工具调用循环) */
514
+ thought_signature?: string;
409
515
  }>;
410
516
  }
411
517
  /** 火山引擎 Responses API 工具定义 */
@@ -592,6 +698,29 @@ interface ToolCallResultEvent {
592
698
  * 前端可根据此字段处理通知、刷新文件列表等
593
699
  */
594
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;
595
724
  };
596
725
  }
597
726
  /** 工具执行批准请求事件(manual 模式) */
@@ -609,7 +738,7 @@ interface ToolApprovalRequestEvent {
609
738
  };
610
739
  }
611
740
  /** 工具相关事件联合类型 */
612
- type ToolEvent = ToolCallStartEvent | ToolCallResultEvent | ToolApprovalRequestEvent;
741
+ type ToolEvent = ToolCallStartEvent | ToolCallResultEvent | ToolApprovalRequestEvent | ToolCallOutputEvent;
613
742
  /** 文本增量事件 */
614
743
  interface TextDeltaEvent {
615
744
  type: 'text_delta';
@@ -744,7 +873,7 @@ declare function createToolCallStart(id: string, name: string, args: Record<stri
744
873
  /**
745
874
  * 创建工具调用结果事件
746
875
  */
747
- declare function createToolCallResult(id: string, name: string, result: string, success: boolean, startedAt: number, error?: string, sideEffects?: SideEffect[]): ToolCallResultEvent;
876
+ declare function createToolCallResult(id: string, name: string, result: string, success: boolean, startedAt: number, error?: string, sideEffects?: SideEffect[], resultType?: string): ToolCallResultEvent;
748
877
  /**
749
878
  * 创建文本增量事件
750
879
  */
@@ -842,22 +971,22 @@ interface RuntimeConfig {
842
971
  qwenApiUrl: string;
843
972
  openrouterApiKey: string;
844
973
  openrouterApiUrl: string;
974
+ vercelApiKey: string;
975
+ tavilyApiKey: string;
845
976
  geminiApiKey: string;
846
977
  cwd: string;
847
- planPrompt: string;
848
978
  }
849
979
  /**
850
980
  * 混合 Agent 类
851
981
  *
852
982
  * 职责:
853
- * 1. 管理多个 ProviderAdapter
854
- * 2. 路由请求到正确的 Adapter
855
- * 3. 使用 ChatOrchestrator 统一处理工具调用
856
- * 4. 管理对话历史和工具注册
983
+ * 1. 管理 UnifiedAdapter(统一适配器)
984
+ * 2. 使用 ChatOrchestrator 统一处理工具调用
985
+ * 3. 管理工具注册
857
986
  */
858
987
  declare class HybridAgent {
859
988
  private config;
860
- private adapters;
989
+ private adapter;
861
990
  private orchestrator;
862
991
  private geminiClient;
863
992
  private toolExecutor;
@@ -869,19 +998,18 @@ declare class HybridAgent {
869
998
  constructor(config: AgentConfig, toolExecutor?: ToolExecutor$1);
870
999
  /** 异步初始化工具(在第一次 chat 前调用) */
871
1000
  private asyncInit;
872
- /** 初始化所有 Adapter */
873
- private initializeAdapters;
1001
+ /** 获取模型的家族配置 */
1002
+ getModelFamilyConfig(model: string): ModelFamilyConfig | undefined;
874
1003
  /**
875
- * 判断模型提供商
1004
+ * 判断模型提供商(兼容旧接口)
876
1005
  */
877
1006
  private getModelProvider;
878
- /** 获取 Adapter */
879
- private getAdapter;
880
1007
  /**
881
1008
  * 调试:获取模型路由信息
882
1009
  */
883
1010
  getModelRouteInfo(model: string): RouteResult & {
884
1011
  available: boolean;
1012
+ familyConfig?: ModelFamilyConfig;
885
1013
  };
886
1014
  /** 构建系统提示词 */
887
1015
  private buildSystemPrompt;
@@ -893,6 +1021,11 @@ declare class HybridAgent {
893
1021
  private executeTool;
894
1022
  /** 获取工具定义列表 */
895
1023
  private getToolDefinitions;
1024
+ /** 获取所有工具列表(用于设置面板) */
1025
+ getAllTools(): Array<{
1026
+ name: string;
1027
+ description: string;
1028
+ }>;
896
1029
  /**
897
1030
  * 聊天入口
898
1031
  *
@@ -942,6 +1075,8 @@ interface ToolCallRequest {
942
1075
  id: string;
943
1076
  name: string;
944
1077
  arguments: string;
1078
+ /** Gemini 模型需要的 thought_signature(用于工具调用循环) */
1079
+ thought_signature?: string;
945
1080
  }
946
1081
  /** 搜索结果项 */
947
1082
  interface SearchResultItem {
@@ -972,6 +1107,8 @@ interface StandardMessage {
972
1107
  interface AdapterConfig {
973
1108
  apiKey: string;
974
1109
  apiUrl?: string;
1110
+ /** Tavily API Key(用于统一 Web Search) */
1111
+ tavilyApiKey?: string;
975
1112
  }
976
1113
  /** 单次调用选项 */
977
1114
  interface StreamOnceOptions {
@@ -1018,7 +1155,17 @@ interface ProviderAdapter {
1018
1155
  * - string: 简单结果,使用工具的静态 sideEffects
1019
1156
  * - ToolResult: 带动态副作用的结果
1020
1157
  */
1021
- type ToolExecutor = (name: string, args: Record<string, unknown>, signal?: AbortSignal) => Promise<string | ToolResult>;
1158
+ interface ToolExecutionHooks {
1159
+ /** 工具调用 ID(用于把输出归属到具体 tool_call 卡片) */
1160
+ toolCallId: string;
1161
+ /** 工具名称 */
1162
+ toolName: string;
1163
+ /** stdout 增量 */
1164
+ onStdout?: (chunk: string) => void;
1165
+ /** stderr 增量 */
1166
+ onStderr?: (chunk: string) => void;
1167
+ }
1168
+ type ToolExecutor = (name: string, args: Record<string, unknown>, signal?: AbortSignal, hooks?: ToolExecutionHooks) => Promise<string | ToolResult>;
1022
1169
  /** 自动运行配置 */
1023
1170
  interface AutoRunConfig {
1024
1171
  /**
@@ -1086,209 +1233,482 @@ interface OrchestratorOptions {
1086
1233
  }
1087
1234
 
1088
1235
  /**
1089
- * Chat Orchestrator
1236
+ * UnifiedAdapter - 统一适配器
1090
1237
  *
1091
- * 统一处理:
1092
- * 1. 工具调用循环 (while iterations < MAX)
1093
- * 2. 消息历史维护 (assistant + tool 消息)
1094
- * 3. 事件发射 (ChatEvent)
1095
- * 4. 错误处理
1238
+ * 组合 Protocol + FamilyConfig,产出标准 StreamChunk
1096
1239
  *
1097
- * 所有 Provider 通过此类执行,确保行为一致
1240
+ * 设计原则:
1241
+ * 1. Protocol 只负责 HTTP/SSE 通信,产出 RawEvent
1242
+ * 2. UnifiedAdapter 根据 FamilyConfig 将 RawEvent 转换为 StreamChunk
1243
+ * 3. 所有模型都使用同一个 UnifiedAdapter,行为差异由 FamilyConfig 决定
1244
+ * 4. 实现 ProviderAdapter 接口,可与现有 Orchestrator 无缝集成
1098
1245
  */
1099
1246
 
1100
1247
  /**
1101
- * Chat Orchestrator
1102
- *
1103
- * 核心职责:统一处理工具调用循环,所有 Provider 共享相同的逻辑
1248
+ * UnifiedAdapter 配置
1104
1249
  */
1105
- declare class ChatOrchestrator {
1106
- private config;
1107
- constructor(config: OrchestratorConfig);
1250
+ interface UnifiedAdapterConfig {
1251
+ /** ARK API Key(豆包/DeepSeek) */
1252
+ arkApiKey?: string;
1253
+ arkApiUrl?: string;
1254
+ /** Qwen API Key(通义千问) */
1255
+ qwenApiKey?: string;
1256
+ qwenApiUrl?: string;
1257
+ /** Gemini API Key */
1258
+ geminiApiKey?: string;
1259
+ geminiApiUrl?: string;
1260
+ /** OpenRouter API Key */
1261
+ openrouterApiKey?: string;
1262
+ openrouterApiUrl?: string;
1263
+ /** Vercel API Key(用于 Vercel AI Gateway 访问 Claude) */
1264
+ vercelApiKey?: string;
1265
+ }
1266
+ /**
1267
+ * 流式调用选项
1268
+ */
1269
+ interface StreamOptions {
1270
+ /** 模型 ID */
1271
+ model: string;
1272
+ /** 是否启用 thinking */
1273
+ enableThinking?: boolean;
1274
+ /** 是否启用搜索 */
1275
+ enableSearch?: boolean;
1276
+ /** 中断信号 */
1277
+ signal: AbortSignal;
1278
+ }
1279
+ /**
1280
+ * 统一适配器
1281
+ *
1282
+ * 实现 ProviderAdapter 接口,根据模型自动选择 Protocol,并根据 FamilyConfig 转换事件
1283
+ */
1284
+ declare class UnifiedAdapter implements ProviderAdapter {
1285
+ readonly name = "unified";
1286
+ /** 支持的模型列表(从 Registry 获取) */
1287
+ get supportedModels(): string[];
1288
+ private protocols;
1289
+ constructor(config: UnifiedAdapterConfig);
1108
1290
  /**
1109
- * 执行聊天
1291
+ * 检查是否支持指定模型
1292
+ */
1293
+ supportsModel(model: string): boolean;
1294
+ /**
1295
+ * 获取模型的家族配置
1296
+ */
1297
+ getModelFamilyConfig(model: string): ModelFamilyConfig | undefined;
1298
+ /**
1299
+ * 实现 ProviderAdapter.streamOnce 接口
1110
1300
  *
1111
- * @param adapter Provider 适配器
1112
- * @param message 用户消息
1113
- * @param context Orchestrator 上下文
1114
- * @param options 选项
1301
+ * @param messages 标准消息列表
1302
+ * @param tools 工具定义
1303
+ * @param options 调用选项
1304
+ * @returns 标准 StreamChunk 流
1115
1305
  */
1116
- chat(adapter: ProviderAdapter, message: string, context: OrchestratorContext, options: OrchestratorOptions): AsyncGenerator<ChatEvent>;
1306
+ streamOnce(messages: StandardMessage[], tools: SimpleToolDefinition[], options: StreamOnceOptions): AsyncGenerator<StreamChunk>;
1117
1307
  /**
1118
- * 构建标准化消息列表
1308
+ * 流式调用(内部方法)
1119
1309
  */
1120
- private buildMessages;
1310
+ private stream;
1311
+ /**
1312
+ * 将 RawEvent 转换为 StreamChunk
1313
+ *
1314
+ * 根据 FamilyConfig 处理行为差异
1315
+ */
1316
+ private transformEvents;
1121
1317
  }
1122
1318
  /**
1123
- * 创建 Orchestrator 实例
1319
+ * 创建 UnifiedAdapter
1124
1320
  */
1125
- declare function createOrchestrator(config: OrchestratorConfig): ChatOrchestrator;
1321
+ declare function createUnifiedAdapter(config: UnifiedAdapterConfig): UnifiedAdapter;
1126
1322
 
1127
1323
  /**
1128
- * ARK (火山引擎) Adapter
1324
+ * Protocol Layer 类型定义
1129
1325
  *
1130
- * 职责:
1131
- * - 将标准消息转换为 ARK Responses API 格式
1132
- * - 调用 API 并解析响应为标准 StreamChunk
1133
- * - 不处理工具执行和消息历史
1326
+ * Protocol 只负责:
1327
+ * 1. HTTP 请求发送
1328
+ * 2. SSE 流解析
1329
+ * 3. 认证处理
1330
+ *
1331
+ * 不负责:
1332
+ * - thinking 格式转换(由 Family 处理)
1333
+ * - 搜索行为差异(由 Family 处理)
1334
+ * - 工具调用格式差异(由 Family 处理)
1134
1335
  */
1135
1336
 
1136
- /** ARK 支持的模型 */
1137
- declare const ARK_MODELS: string[];
1138
1337
  /**
1139
- * ARK Adapter
1338
+ * Protocol 原始事件类型
1140
1339
  *
1141
- * 使用 Responses API 格式
1340
+ * 这是 Protocol 层产出的"原始"事件,
1341
+ * 后续由 FamilyBehavior 转换为标准 StreamChunk
1342
+ */
1343
+ type RawEventType = 'text_delta' | 'thinking_delta' | 'thinking_done' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_done' | 'search_query' | 'search_result' | 'done' | 'error';
1344
+ /**
1345
+ * 原始工具调用
1142
1346
  */
1143
- declare class ArkAdapter implements ProviderAdapter {
1347
+ interface RawToolCall {
1348
+ id: string;
1349
+ name: string;
1350
+ arguments: string;
1351
+ /** Gemini 需要的 thoughtSignature(用于工具调用循环) */
1352
+ thoughtSignature?: string;
1353
+ }
1354
+ /**
1355
+ * Protocol 消息中的工具调用
1356
+ */
1357
+ interface ProtocolToolCall {
1358
+ id: string;
1359
+ name: string;
1360
+ arguments: string;
1361
+ /** Gemini 需要的 thoughtSignature */
1362
+ thoughtSignature?: string;
1363
+ }
1364
+ /**
1365
+ * 原始搜索结果
1366
+ */
1367
+ interface RawSearchResult {
1368
+ title: string;
1369
+ url: string;
1370
+ snippet: string;
1371
+ }
1372
+ /**
1373
+ * Protocol 原始事件
1374
+ */
1375
+ interface RawEvent {
1376
+ type: RawEventType;
1377
+ delta?: string;
1378
+ toolCall?: Partial<RawToolCall>;
1379
+ searchQuery?: string;
1380
+ searchResults?: RawSearchResult[];
1381
+ finishReason?: 'stop' | 'tool_calls' | 'length' | 'error';
1382
+ error?: string;
1383
+ }
1384
+ /**
1385
+ * Protocol 请求消息(标准化格式)
1386
+ */
1387
+ interface ProtocolMessage {
1388
+ role: 'system' | 'user' | 'assistant' | 'tool';
1389
+ content: string;
1390
+ /** 图片列表(base64 或 URL) */
1391
+ images?: string[];
1392
+ /** 工具调用(assistant 消息) */
1393
+ toolCalls?: ProtocolToolCall[];
1394
+ /** 工具调用 ID(tool 消息) */
1395
+ toolCallId?: string;
1396
+ /** 工具名称(tool 消息,Gemini 需要) */
1397
+ toolName?: string;
1398
+ }
1399
+ /**
1400
+ * Protocol 工具定义(简化格式)
1401
+ */
1402
+ interface ProtocolToolDefinition {
1403
+ name: string;
1404
+ 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
+ };
1417
+ }
1418
+ /**
1419
+ * Protocol 请求选项
1420
+ */
1421
+ interface ProtocolRequestOptions {
1422
+ /** 模型 ID */
1423
+ model: string;
1424
+ /** 模型家族配置 */
1425
+ familyConfig: ModelFamilyConfig;
1426
+ /** 是否启用 thinking */
1427
+ enableThinking: boolean;
1428
+ /** 是否启用搜索 */
1429
+ enableSearch: boolean;
1430
+ /** 中断信号 */
1431
+ signal: AbortSignal;
1432
+ }
1433
+ /**
1434
+ * Protocol 配置
1435
+ */
1436
+ interface ProtocolConfig {
1437
+ apiKey: string;
1438
+ apiUrl?: string;
1439
+ }
1440
+ /**
1441
+ * Protocol 接口
1442
+ *
1443
+ * 只负责 HTTP/SSE 通信,不处理任何业务逻辑
1444
+ */
1445
+ interface Protocol {
1446
+ /** 协议名称 */
1447
+ readonly name: string;
1448
+ /**
1449
+ * 发送请求并返回原始事件流
1450
+ *
1451
+ * @param messages 消息列表
1452
+ * @param tools 工具定义
1453
+ * @param options 请求选项
1454
+ * @returns 原始事件流
1455
+ */
1456
+ stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
1457
+ }
1458
+
1459
+ /**
1460
+ * ARK Protocol(火山引擎 Responses API)
1461
+ *
1462
+ * 只负责:
1463
+ * - HTTP 请求发送
1464
+ * - SSE 流解析
1465
+ * - 原始事件产出
1466
+ */
1467
+
1468
+ /**
1469
+ * ARK Protocol 实现
1470
+ */
1471
+ declare class ArkProtocol implements Protocol {
1144
1472
  readonly name = "ark";
1145
- readonly supportedModels: string[];
1146
1473
  private apiKey;
1147
1474
  private apiUrl;
1148
- constructor(config: AdapterConfig);
1149
- supportsModel(model: string): boolean;
1475
+ constructor(config: ProtocolConfig);
1150
1476
  /**
1151
- * 单次流式调用
1477
+ * 发送请求并返回原始事件流
1152
1478
  */
1153
- streamOnce(messages: StandardMessage[], tools: SimpleToolDefinition[], options: StreamOnceOptions): AsyncGenerator<StreamChunk>;
1479
+ stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
1154
1480
  /**
1155
- * 转换标准消息为 ARK Responses API 格式
1481
+ * 构建请求体
1482
+ */
1483
+ private buildRequestBody;
1484
+ /**
1485
+ * 转换消息格式
1156
1486
  */
1157
1487
  private convertMessages;
1158
1488
  /**
1159
- * 解析 ARK 流式响应
1489
+ * 解析 SSE
1160
1490
  */
1161
- private parseStream;
1491
+ private parseSSE;
1162
1492
  }
1163
1493
  /**
1164
- * 创建 ARK Adapter
1494
+ * 创建 ARK Protocol
1165
1495
  */
1166
- declare function createArkAdapter(config: AdapterConfig): ArkAdapter;
1496
+ declare function createArkProtocol(config: ProtocolConfig): ArkProtocol;
1167
1497
 
1168
1498
  /**
1169
- * OpenRouter Adapter
1499
+ * DeepSeek Protocol(通过火山引擎 ARK API 访问)
1170
1500
  *
1171
- * 职责:
1172
- * - 将标准消息转换为 OpenAI 兼容格式
1173
- * - 调用 API 并解析响应为标准 StreamChunk
1174
- * - 不处理工具执行和消息历史
1501
+ * 特点:
1502
+ * - 支持 reasoning(深度思考)
1503
+ * - 支持 web_search 原生搜索
1504
+ * - 与豆包共用 ARK API,但行为可能有差异
1175
1505
  */
1176
1506
 
1177
- /** OpenRouter 支持的模型 */
1178
- declare const OPENROUTER_MODELS: string[];
1179
1507
  /**
1180
- * OpenRouter Adapter
1508
+ * DeepSeek Protocol 实现
1509
+ */
1510
+ declare class DeepSeekProtocol implements Protocol {
1511
+ readonly name = "deepseek";
1512
+ private apiKey;
1513
+ private apiUrl;
1514
+ constructor(config: ProtocolConfig);
1515
+ stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
1516
+ /**
1517
+ * 构建请求体(DeepSeek 专用)
1518
+ */
1519
+ private buildRequestBody;
1520
+ private convertMessages;
1521
+ /**
1522
+ * 解析 SSE 流(DeepSeek 专用)
1523
+ */
1524
+ private parseSSE;
1525
+ }
1526
+ declare function createDeepSeekProtocol(config: ProtocolConfig): DeepSeekProtocol;
1527
+
1528
+ /**
1529
+ * Qwen Protocol(通义千问 OpenAI 兼容模式 API)
1181
1530
  *
1182
- * 使用 OpenAI 兼容 API 格式
1531
+ * 使用 OpenAI 兼容端点以支持工具调用:
1532
+ * https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
1183
1533
  */
1184
- declare class OpenRouterAdapter implements ProviderAdapter {
1185
- readonly name = "openrouter";
1186
- readonly supportedModels: string[];
1534
+
1535
+ /**
1536
+ * Qwen Protocol 实现(OpenAI 兼容模式)
1537
+ */
1538
+ declare class QwenProtocol implements Protocol {
1539
+ readonly name = "qwen";
1187
1540
  private apiKey;
1188
1541
  private apiUrl;
1189
- constructor(config: AdapterConfig);
1190
- supportsModel(model: string): boolean;
1542
+ constructor(config: ProtocolConfig);
1191
1543
  /**
1192
- * 单次流式调用
1544
+ * 发送请求并返回原始事件流
1193
1545
  */
1194
- streamOnce(messages: StandardMessage[], tools: SimpleToolDefinition[], options: StreamOnceOptions): AsyncGenerator<StreamChunk>;
1546
+ stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
1547
+ /**
1548
+ * 构建请求体(OpenAI 格式)
1549
+ */
1550
+ private buildRequestBody;
1195
1551
  /**
1196
- * 转换标准消息为 OpenAI 格式
1552
+ * 转换消息格式(OpenAI 标准格式)
1197
1553
  */
1198
1554
  private convertMessages;
1199
1555
  /**
1200
- * 解析 OpenAI 兼容流式响应
1556
+ * 解析 SSE 流(OpenAI 格式)
1201
1557
  */
1202
- private parseStream;
1558
+ private parseSSE;
1203
1559
  }
1204
1560
  /**
1205
- * 创建 OpenRouter Adapter
1561
+ * 创建 Qwen Protocol
1206
1562
  */
1207
- declare function createOpenRouterAdapter(config: AdapterConfig): OpenRouterAdapter;
1563
+ declare function createQwenProtocol(config: ProtocolConfig): QwenProtocol;
1208
1564
 
1209
1565
  /**
1210
- * Qwen (通义千问) Adapter
1566
+ * Gemini Protocol(Google Gemini API)
1211
1567
  *
1212
- * 职责:
1213
- * - 将标准消息转换为 DashScope 原生 API 格式
1214
- * - 调用 API 并解析响应为标准 StreamChunk
1215
- * - 不处理工具执行和消息历史
1568
+ * 只负责:
1569
+ * - HTTP 请求发送
1570
+ * - SSE 流解析
1571
+ * - 原始事件产出
1216
1572
  */
1217
1573
 
1218
- /** Qwen 支持的模型 */
1219
- declare const QWEN_MODELS: string[];
1220
1574
  /**
1221
- * Qwen Adapter
1222
- *
1223
- * 使用 DashScope 原生协议
1575
+ * Gemini Protocol 实现
1224
1576
  */
1225
- declare class QwenAdapter implements ProviderAdapter {
1226
- readonly name = "qwen";
1227
- readonly supportedModels: string[];
1577
+ declare class GeminiProtocol implements Protocol {
1578
+ readonly name = "gemini";
1228
1579
  private apiKey;
1229
1580
  private apiUrl;
1230
- constructor(config: AdapterConfig);
1231
- supportsModel(model: string): boolean;
1581
+ constructor(config: ProtocolConfig);
1232
1582
  /**
1233
- * 单次流式调用
1583
+ * 发送请求并返回原始事件流
1234
1584
  */
1235
- streamOnce(messages: StandardMessage[], tools: SimpleToolDefinition[], options: StreamOnceOptions): AsyncGenerator<StreamChunk>;
1585
+ stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
1236
1586
  /**
1237
- * 转换标准消息为 Qwen 格式
1587
+ * 构建请求体
1588
+ */
1589
+ private buildRequestBody;
1590
+ /**
1591
+ * 转换消息格式
1238
1592
  */
1239
1593
  private convertMessages;
1240
1594
  /**
1241
- * 解析 Qwen 流式响应
1595
+ * 解析 SSE
1242
1596
  */
1243
- private parseStream;
1597
+ private parseSSE;
1244
1598
  }
1245
1599
  /**
1246
- * 创建 Qwen Adapter
1600
+ * 创建 Gemini Protocol
1247
1601
  */
1248
- declare function createQwenAdapter(config: AdapterConfig): QwenAdapter;
1602
+ declare function createGeminiProtocol(config: ProtocolConfig): GeminiProtocol;
1249
1603
 
1250
1604
  /**
1251
- * Gemini Adapter
1605
+ * OpenAI Protocol(通过 OpenRouter 访问 OpenAI/GPT 模型)
1252
1606
  *
1253
- * 职责:
1254
- * - 将标准消息转换为 Gemini SDK 格式
1255
- * - 调用 SDK 并解析响应为标准 StreamChunk
1256
- * - 不处理工具执行和消息历史
1607
+ * 特点:
1608
+ * - GPT-5.x 支持 reasoning(思考模式)
1609
+ * - 支持工具调用
1257
1610
  */
1258
1611
 
1259
- /** Gemini 支持的模型 */
1260
- declare const GEMINI_MODELS: string[];
1261
- /** Gemini Adapter 配置 */
1262
- interface GeminiAdapterConfig {
1263
- apiKey: string;
1264
- }
1265
1612
  /**
1266
- * Gemini Adapter
1267
- *
1268
- * 使用 @google/genai SDK
1613
+ * OpenAI Protocol 实现(通过 OpenRouter)
1269
1614
  */
1270
- declare class GeminiAdapter implements ProviderAdapter {
1271
- readonly name = "gemini";
1272
- readonly supportedModels: string[];
1273
- private client;
1615
+ declare class OpenAIProtocol implements Protocol {
1616
+ readonly name = "openai";
1274
1617
  private apiKey;
1275
- constructor(config: GeminiAdapterConfig);
1276
- /** 懒加载客户端 */
1277
- private getClient;
1278
- supportsModel(model: string): boolean;
1618
+ private apiUrl;
1619
+ constructor(config: ProtocolConfig);
1620
+ stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
1279
1621
  /**
1280
- * 单次流式调用
1622
+ * 构建请求体(OpenAI/GPT 专用)
1281
1623
  */
1282
- streamOnce(messages: StandardMessage[], tools: SimpleToolDefinition[], options: StreamOnceOptions): AsyncGenerator<StreamChunk>;
1624
+ private buildRequestBody;
1625
+ private convertMessages;
1283
1626
  /**
1284
- * 转换标准消息为 Gemini 格式
1627
+ * 解析 SSE 流(OpenAI/GPT 专用)
1628
+ */
1629
+ private parseSSE;
1630
+ }
1631
+ declare function createOpenAIProtocol(config: ProtocolConfig): OpenAIProtocol;
1632
+
1633
+ /**
1634
+ * Anthropic Protocol(通过 Vercel AI Gateway)
1635
+ *
1636
+ * 特点:
1637
+ * - 使用 Vercel AI SDK 的 createGateway
1638
+ * - 支持 extended thinking
1639
+ * - 支持工具调用
1640
+ * - 自动处理流式输出
1641
+ *
1642
+ * 参考: https://vercel.com/docs/ai-gateway
1643
+ */
1644
+
1645
+ /**
1646
+ * Anthropic Protocol 实现(通过 Vercel AI Gateway)
1647
+ */
1648
+ declare class AnthropicProtocol implements Protocol {
1649
+ readonly name = "anthropic";
1650
+ private gateway;
1651
+ constructor(config: ProtocolConfig);
1652
+ stream(messages: ProtocolMessage[], tools: ProtocolToolDefinition[], options: ProtocolRequestOptions): AsyncGenerator<RawEvent>;
1653
+ /**
1654
+ * 转换消息格式(ProtocolMessage → AI SDK CoreMessage)
1655
+ * 简化版:主要处理文本消息,工具调用通过历史上下文传递
1285
1656
  */
1286
1657
  private convertMessages;
1658
+ /**
1659
+ * 转换工具格式(ProtocolToolDefinition → AI SDK tools)
1660
+ * 注意:Vercel Gateway 对工具格式有特殊要求,这里使用标准格式
1661
+ */
1662
+ private convertTools;
1663
+ /**
1664
+ * 将 JSON Schema 转换为 Zod Schema
1665
+ */
1666
+ private jsonSchemaToZod;
1667
+ /**
1668
+ * 解析 AI SDK 流式响应
1669
+ */
1670
+ private parseStream;
1671
+ }
1672
+ declare function createAnthropicProtocol(config: ProtocolConfig): AnthropicProtocol;
1673
+
1674
+ /**
1675
+ * Chat Orchestrator
1676
+ *
1677
+ * 统一处理:
1678
+ * 1. 工具调用循环 (while iterations < MAX)
1679
+ * 2. 消息历史维护 (assistant + tool 消息)
1680
+ * 3. 事件发射 (ChatEvent)
1681
+ * 4. 错误处理
1682
+ *
1683
+ * 所有 Provider 通过此类执行,确保行为一致
1684
+ */
1685
+
1686
+ /**
1687
+ * Chat Orchestrator
1688
+ *
1689
+ * 核心职责:统一处理工具调用循环,所有 Provider 共享相同的逻辑
1690
+ */
1691
+ declare class ChatOrchestrator {
1692
+ private config;
1693
+ constructor(config: OrchestratorConfig);
1694
+ /**
1695
+ * 执行聊天
1696
+ *
1697
+ * @param adapter Provider 适配器
1698
+ * @param message 用户消息
1699
+ * @param context Orchestrator 上下文
1700
+ * @param options 选项
1701
+ */
1702
+ chat(adapter: ProviderAdapter, message: string, context: OrchestratorContext, options: OrchestratorOptions): AsyncGenerator<ChatEvent>;
1703
+ /**
1704
+ * 构建标准化消息列表
1705
+ */
1706
+ private buildMessages;
1287
1707
  }
1288
1708
  /**
1289
- * 创建 Gemini Adapter
1709
+ * 创建 Orchestrator 实例
1290
1710
  */
1291
- declare function createGeminiAdapter(config: GeminiAdapterConfig): GeminiAdapter;
1711
+ declare function createOrchestrator(config: OrchestratorConfig): ChatOrchestrator;
1292
1712
 
1293
1713
  declare const DEFAULT_MODEL: string;
1294
1714
 
@@ -1427,4 +1847,56 @@ declare function getDocumentSearchInstance(dataDir?: string, workspace?: string)
1427
1847
  [key: string]: unknown;
1428
1848
  } | null>;
1429
1849
 
1430
- export { ARK_MODELS, type AbortEvent, type AdapterConfig, type AgentConfig, ArkAdapter, type AutoRunConfig$1 as AutoRunConfig, type AutoRunMode, type ChatEvent, type ChatEventType, type ChatMessage, type ChatMode, type ChatOptions, ChatOrchestrator, DEFAULT_MODEL, type DoneEvent, type ErrorCategory, type ErrorDetails, type ErrorEvent, GEMINI_MODELS, GeminiAdapter, HybridAgent, type ImageEvent, MODELS, type MediaEvent, type ModelOption, OPENROUTER_MODELS, OpenRouterAdapter, type OrchestratorConfig, type OrchestratorContext, type OrchestratorOptions, type ToolExecutor as OrchestratorToolExecutor, type ProviderAdapter, type ProviderType, QWEN_MODELS, QwenAdapter, type ResponsesApiTool, type RouteMatchType, type RouteResult, type RouteRule, type RuntimeConfig, type SearchEndEvent, type SearchEvent, type SearchResult, type SearchResultEvent, type SearchResultItem, type SearchStartEvent, type SearchToolsOptions, type SideEffect$1 as SideEffect, type SimpleToolDefinition, type StandardMessage, type StatusEvent, type StepEndEvent, type StepEvent, type StepStartEvent, type StreamChunk, type StreamChunkType, type StreamOnceOptions, type StreamStartEvent, type TextDeltaEvent, type TextEvent, type ThinkingDeltaEvent, type ThinkingEndEvent, type ThinkingEvent, type ThinkingMode, type ThinkingStartEvent, type TokenUsage, type Tool, type ToolCallInfo, type ToolCallRequest, type ToolCallResultEvent, type ToolCallStartEvent, type ToolCallStatus, type ToolConfigItem, type ToolContext, type ToolDefinition, type ToolEvent, type ToolExecutor$1 as ToolExecutor, type ToolPlugin, type ToolResult, type VideoEvent, analyzeImageTool, analyzeVideoTool, createAbort, createApiError, createArkAdapter, createDefaultToolExecutor, createDocumentSearchTools, createDone, createError, createGeminiAdapter, createImage, createOpenRouterAdapter, createOrchestrator, createParseError, createQwenAdapter, createRateLimitError, createSearchEnd, createSearchResult, createSearchStart, createStepEnd, createStepStart, createStreamStart, createTextDelta, createThinkingDelta, createThinkingEnd, createThinkingStart, createTimeoutError, createToolCallResult, createToolCallStart, createToolError, createVideo, executeCommandTool, generateImageTool, getCwdTool, getDefaultProvider, getDocumentSearchInstance, getModelByModelId, getNativeModels, getOpenRouterModels, getPlatformTool, getRouteRules, getWeatherTool, isAbortEvent, isErrorEvent, isMediaEvent, isModelForProvider, isRetryableError, isSearchEvent, isStatusEvent, isStepEvent, isTextEvent, isThinkingEvent, isToolEvent, navigateToDirectoryTool, openConfirmDialogTool, openFilePreviewTool, resolveTools, routeModelToProvider, routeModelWithDetails, showToastTool, tool, tools, uiActionTools };
1850
+ /**
1851
+ * 调试日志工具
1852
+ *
1853
+ * 用法:
1854
+ * - 设置环境变量 AI_CHAT_DEBUG=true 启用调试日志
1855
+ * - 设置环境变量 AI_CHAT_DEBUG_FILE=/path/to/log.jsonl 启用文件输出
1856
+ * - 或者调用 DebugLogger.enable() / DebugLogger.setLogFile()
1857
+ */
1858
+ /**
1859
+ * 调试日志工具
1860
+ */
1861
+ declare const DebugLogger: {
1862
+ /**
1863
+ * 启用/禁用调试日志
1864
+ */
1865
+ enable(enabled?: boolean): void;
1866
+ /**
1867
+ * 检查是否启用
1868
+ */
1869
+ isEnabled(): boolean;
1870
+ /**
1871
+ * 直接设置 fs 模块(用于 Electron 主进程等打包环境)
1872
+ */
1873
+ setFsModule(fs: typeof fs): void;
1874
+ /**
1875
+ * 设置日志文件路径(仅 Node.js 环境有效)
1876
+ * @param path 日志文件路径,null 表示禁用文件输出
1877
+ */
1878
+ setLogFile(path: string | null): void;
1879
+ /**
1880
+ * 获取日志文件路径
1881
+ */
1882
+ getLogFile(): string | null;
1883
+ /**
1884
+ * 立即刷新日志到文件
1885
+ */
1886
+ flush(): void;
1887
+ /**
1888
+ * 创建模块专用的 logger
1889
+ */
1890
+ module(moduleName: string): {
1891
+ debug: (message: string, data?: unknown) => void;
1892
+ info: (message: string, data?: unknown) => void;
1893
+ warn: (message: string, data?: unknown) => void;
1894
+ error: (message: string, data?: unknown) => void;
1895
+ };
1896
+ debug: (module: string, message: string, data?: unknown) => void;
1897
+ info: (module: string, message: string, data?: unknown) => void;
1898
+ warn: (module: string, message: string, data?: unknown) => void;
1899
+ error: (module: string, message: string, data?: unknown) => void;
1900
+ };
1901
+
1902
+ export { type AbortEvent, type AdapterConfig, type AgentConfig, AnthropicProtocol, ArkProtocol, type AutoRunConfig$1 as AutoRunConfig, type AutoRunMode, CLAUDE_FAMILY, type ChatEvent, type ChatEventType, type ChatMessage, type ChatMode, type ChatOptions, ChatOrchestrator, DEEPSEEK_FAMILY, DEFAULT_MODEL, DOUBAO_FAMILY, DebugLogger, DeepSeekProtocol, type DoneEvent, type ErrorCategory, type ErrorDetails, type ErrorEvent, GEMINI_FAMILY, GPT_FAMILY, GeminiProtocol, HybridAgent, type ImageEvent, MODELS, MODEL_FAMILIES, MODEL_REGISTRY, type MediaEvent, 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 SearchEndEvent, type SearchEvent, type SearchResult, type SearchResultEvent, type SearchResultItem, type SearchStartEvent, type SearchStrategy, type SearchToolsOptions, type SideEffect$1 as SideEffect, type SimpleToolDefinition, type StandardMessage, type StatusEvent, type StepEndEvent, type StepEvent, type StepStartEvent, type StreamChunk, type StreamChunkType, type StreamOnceOptions, type StreamOptions, type StreamStartEvent, type TextDeltaEvent, type TextEvent, type ThinkingDeltaEvent, type ThinkingEndEvent, type ThinkingEvent, type ThinkingFormat, type ThinkingMode, type ThinkingStartEvent, type TokenUsage, type Tool, type ToolCallFormat, type ToolCallInfo, type ToolCallRequest, type ToolCallResultEvent, type ToolCallStartEvent, type ToolCallStatus, type ToolConfigItem, type ToolContext, type ToolDefinition, type ToolEvent, type ToolExecutor$1 as ToolExecutor, type ToolPlugin, type ToolResult, UnifiedAdapter, type UnifiedAdapterConfig, type VideoEvent, analyzeImageTool, analyzeVideoTool, createAbort, createAnthropicProtocol, createApiError, createArkProtocol, createDeepSeekProtocol, createDefaultToolExecutor, createDocumentSearchTools, createDone, createError, createGeminiProtocol, createImage, createOpenAIProtocol, createOrchestrator, createParseError, createQwenProtocol, createRateLimitError, createSearchEnd, createSearchResult, createSearchStart, createStepEnd, createStepStart, createStreamStart, createTextDelta, createThinkingDelta, createThinkingEnd, createThinkingStart, createTimeoutError, createToolCallResult, createToolCallStart, createToolError, createUnifiedAdapter, createVideo, executeCommandTool, generateImageTool, getCwdTool, getDefaultProvider, getDocumentSearchInstance, getModelByModelId, getModelEntry, getModelFamily, getModelProtocol, getModelSearchStrategy, getModelsByFamily, getModelsByProtocol, getPlatformTool, getVisibleModels, getWeatherTool, isAbortEvent, isErrorEvent, isMediaEvent, isModelForProvider, isRetryableError, isSearchEvent, isStatusEvent, isStepEvent, isTextEvent, isThinkingEvent, isToolEvent, modelSupportsNativeSearch, modelSupportsThinking, navigateToDirectoryTool, openConfirmDialogTool, openFilePreviewTool, resolveTools, routeModelToProvider, routeModelWithDetails, showToastTool, tool, tools, uiActionTools };