@ai-setting/roy-agent-core 1.5.5 → 1.5.7

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.
Files changed (58) hide show
  1. package/dist/config/index.d.ts +1250 -0
  2. package/dist/env/agent/index.d.ts +2279 -0
  3. package/dist/env/agent/index.js +1 -1
  4. package/dist/env/commands/index.d.ts +1131 -0
  5. package/dist/env/debug/formatters/index.d.ts +236 -0
  6. package/dist/env/debug/index.d.ts +1652 -0
  7. package/dist/env/hook/index.d.ts +279 -0
  8. package/dist/env/index.d.ts +3460 -0
  9. package/dist/env/index.js +8 -8
  10. package/dist/env/llm/index.d.ts +1760 -0
  11. package/dist/env/log-trace/index.d.ts +1574 -0
  12. package/dist/env/mcp/index.d.ts +1331 -0
  13. package/dist/env/mcp/index.js +2 -2
  14. package/dist/env/mcp/tool/index.d.ts +183 -0
  15. package/dist/env/mcp/tool/index.js +1 -1
  16. package/dist/env/memory/built-in/index.d.ts +232 -0
  17. package/dist/env/memory/index.d.ts +1799 -0
  18. package/dist/env/memory/plugin/index.d.ts +747 -0
  19. package/dist/env/prompt/index.d.ts +1164 -0
  20. package/dist/env/session/index.d.ts +1908 -0
  21. package/dist/env/session/storage/index.d.ts +564 -0
  22. package/dist/env/skill/index.d.ts +1266 -0
  23. package/dist/env/skill/tool/index.d.ts +193 -0
  24. package/dist/env/task/delegate/index.d.ts +1622 -0
  25. package/dist/env/task/hooks/index.d.ts +607 -0
  26. package/dist/env/task/index.d.ts +1415 -0
  27. package/dist/env/task/plugins/index.d.ts +462 -0
  28. package/dist/env/task/storage/index.d.ts +224 -0
  29. package/dist/env/task/tools/index.d.ts +1464 -0
  30. package/dist/env/task/tools/operation/index.d.ts +1463 -0
  31. package/dist/env/tool/built-in/index.d.ts +218 -0
  32. package/dist/env/tool/index.d.ts +1396 -0
  33. package/dist/env/workflow/decorators/index.d.ts +2161 -0
  34. package/dist/env/workflow/engine/index.d.ts +3453 -0
  35. package/dist/env/workflow/engine/index.js +4 -4
  36. package/dist/env/workflow/index.d.ts +3546 -0
  37. package/dist/env/workflow/index.js +9 -5
  38. package/dist/env/workflow/nodes/index.d.ts +2092 -0
  39. package/dist/env/workflow/nodes/index.js +1 -1
  40. package/dist/env/workflow/service/index.d.ts +227 -0
  41. package/dist/env/workflow/storage/index.d.ts +165 -0
  42. package/dist/env/workflow/tools/index.d.ts +416 -0
  43. package/dist/env/workflow/types/index.d.ts +2255 -0
  44. package/dist/env/workflow/types/index.js +5 -1
  45. package/dist/env/workflow/utils/index.d.ts +2031 -0
  46. package/dist/index.d.ts +7837 -0
  47. package/dist/index.js +8 -8
  48. package/dist/shared/@ai-setting/{roy-agent-core-nhdrvfp8.js → roy-agent-core-1akcqxj9.js} +49 -3
  49. package/dist/shared/@ai-setting/{roy-agent-core-rzp9kxne.js → roy-agent-core-5x94xmt6.js} +14 -5
  50. package/dist/shared/@ai-setting/{roy-agent-core-pc9g3962.js → roy-agent-core-69jskqjg.js} +41 -66
  51. package/dist/shared/@ai-setting/{roy-agent-core-f0cc2ep9.js → roy-agent-core-b0x5dda6.js} +2 -2
  52. package/dist/shared/@ai-setting/{roy-agent-core-ya8krqzt.js → roy-agent-core-dc497hmk.js} +5 -4
  53. package/dist/shared/@ai-setting/{roy-agent-core-z2t8hse8.js → roy-agent-core-dh9d7a3m.js} +1 -1
  54. package/dist/shared/@ai-setting/{roy-agent-core-qw0ebh1d.js → roy-agent-core-gq20wsgv.js} +49 -17
  55. package/dist/shared/@ai-setting/{roy-agent-core-3agad0d9.js → roy-agent-core-jvatggbb.js} +1 -1
  56. package/dist/shared/@ai-setting/{roy-agent-core-c0jcxnf4.js → roy-agent-core-pjr12nnd.js} +1 -1
  57. package/dist/shared/@ai-setting/{roy-agent-core-kkp3qmc3.js → roy-agent-core-wrcy0h6z.js} +132 -180
  58. package/package.json +4 -2
@@ -0,0 +1,1331 @@
1
+ /**
2
+ * @fileoverview Hook 系统统一类型定义
3
+ *
4
+ * 提供所有 Component 使用的统一 Hook 接口
5
+ */
6
+ /**
7
+ * Hook 执行阶段
8
+ */
9
+ type HookPhase = "before" | "after" | "error";
10
+ /**
11
+ * Hook 元信息
12
+ */
13
+ interface HookMeta {
14
+ /** Hook 唯一名称 */
15
+ name: string;
16
+ /** 执行优先级,默认 0,数值越小越先执行 */
17
+ priority?: number;
18
+ /** 描述 */
19
+ description?: string;
20
+ }
21
+ /**
22
+ * 统一 Hook 上下文
23
+ *
24
+ * 泛型参数 T 表示该 Component 的上下文数据类型
25
+ */
26
+ interface HookContext<T = unknown> {
27
+ /** 当前组件信息 */
28
+ component: {
29
+ /** 组件名称 */
30
+ name: string;
31
+ /** 组件版本 */
32
+ version: string;
33
+ };
34
+ /** 上下文数据(Component 特定) */
35
+ data: T;
36
+ /** 元数据(可用于传递额外信息) */
37
+ metadata: Record<string, unknown>;
38
+ /** 执行阶段 */
39
+ phase: HookPhase;
40
+ /** 关联的 hook 点名称 */
41
+ hookPoint: string;
42
+ }
43
+ /**
44
+ * 统一 Hook 接口
45
+ *
46
+ * 所有 Component 的 Hook 都应实现此接口
47
+ */
48
+ interface Hook<T = unknown> extends HookMeta {
49
+ /** 执行 Hook
50
+ * @param ctx 上下文
51
+ */
52
+ execute(ctx: HookContext<T>): void | Promise<void>;
53
+ }
54
+ /**
55
+ * Hook 函数类型(便捷别名)
56
+ */
57
+ type HookFn<T = unknown> = (ctx: HookContext<T>) => void | Promise<void>;
58
+ /**
59
+ * Hook 干预动作类型
60
+ */
61
+ type HookActionType = "stop" | "retry" | "compress" | "extract_memory" | "inject_message" | "skip_tool" | "custom";
62
+ /**
63
+ * Hook 干预动作
64
+ */
65
+ interface HookAction {
66
+ /** 动作类型 */
67
+ type: HookActionType;
68
+ /** 动作参数 */
69
+ params?: Record<string, unknown>;
70
+ /** 动作描述 */
71
+ description?: string;
72
+ }
73
+ /**
74
+ * Hook 执行结果
75
+ */
76
+ interface HookResult {
77
+ /** 是否被停止 */
78
+ stopped?: boolean;
79
+ /** 干预动作(如果有) */
80
+ action?: HookAction;
81
+ /** 执行结果数据 */
82
+ results?: unknown[];
83
+ }
84
+ /**
85
+ * HookManager 配置
86
+ */
87
+ interface HookManagerOptions {
88
+ /** 组件名称(用于上下文) */
89
+ componentName?: string;
90
+ /** 组件版本(用于上下文) */
91
+ componentVersion?: string;
92
+ /** 默认优先级 */
93
+ defaultPriority?: number;
94
+ }
95
+ /**
96
+ * HookManager
97
+ *
98
+ * 统一管理 Component 的 Hook
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const manager = new HookManager<MyContext>();
103
+ *
104
+ * // 注册 Hook
105
+ * manager.register("before-action", {
106
+ * name: "my-hook",
107
+ * priority: 10,
108
+ * execute: async (ctx) => { /* ... *\/ }
109
+ * });
110
+ *
111
+ * // 执行 Hooks
112
+ * await manager.execute("before-action", data);
113
+ * ```
114
+ */
115
+ declare class HookManager<T = unknown> {
116
+ private _hooks;
117
+ private componentName;
118
+ private componentVersion;
119
+ private defaultPriority;
120
+ constructor(options?: HookManagerOptions);
121
+ /**
122
+ * 注册 Hook 到指定 hook 点
123
+ */
124
+ register(hookPoint: string, hook: Hook<T>): void;
125
+ /**
126
+ * 注册多个 Hook
127
+ */
128
+ registerMany(hookPoint: string, hooks: Hook<T>[]): void;
129
+ /**
130
+ * 按名称取消注册 Hook
131
+ * @returns 是否成功取消注册
132
+ */
133
+ unregister(hookPoint: string, name: string): boolean;
134
+ /**
135
+ * 取消注册所有指定 hook 点的 Hook
136
+ */
137
+ unregisterAll(hookPoint: string): void;
138
+ /**
139
+ * 执行指定 hook 点的所有 Hook
140
+ */
141
+ execute(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
142
+ /**
143
+ * 执行指定 hook 点的所有 Hook 并收集返回值
144
+ */
145
+ executeAndCollect<R>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<R[]>;
146
+ /**
147
+ * 获取指定 hook 点的 Hook 数量
148
+ */
149
+ count(hookPoint: string): number;
150
+ /**
151
+ * 清空所有 Hook
152
+ */
153
+ clear(): void;
154
+ /**
155
+ * 获取所有已注册的 hook 点
156
+ */
157
+ getHookPoints(): string[];
158
+ /**
159
+ * 检查 hook 点是否有任何 Hook
160
+ */
161
+ hasHooks(hookPoint: string): boolean;
162
+ /**
163
+ * 设置组件信息
164
+ */
165
+ setComponentInfo(name: string, version: string): void;
166
+ /**
167
+ * 获取所有注册的 hooks(只读副本)
168
+ */
169
+ get hooks(): ReadonlyMap<string, Hook<T>[]>;
170
+ /**
171
+ * 执行 Hook 并支持干预机制
172
+ *
173
+ * 如果任何一个 Hook 返回 { stop: true },执行会停止
174
+ * Hook 可以通过返回 HookResult 来执行干预动作
175
+ *
176
+ * @param hookPoint Hook 点
177
+ * @param data 数据
178
+ * @param metadata 元数据
179
+ * @returns 执行结果
180
+ */
181
+ executeWithIntervention(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<HookResult>;
182
+ /**
183
+ * 获取或创建 hook 列表
184
+ */
185
+ private getOrCreateHooks;
186
+ /**
187
+ * 按优先级排序 Hook
188
+ *
189
+ * 优先级相同时保持原顺序(稳定排序)
190
+ */
191
+ private sortHooks;
192
+ /**
193
+ * 创建 Hook 上下文
194
+ */
195
+ private createContext;
196
+ /**
197
+ * 安全执行 Hook(错误隔离)
198
+ */
199
+ private safeExecute;
200
+ /**
201
+ * 安全执行 Hook 并返回结果
202
+ */
203
+ private safeExecuteAndReturn;
204
+ }
205
+ import { z } from "zod";
206
+ /**
207
+ * Local MCP Server 配置(stdio 传输)
208
+ */
209
+ declare const McpServerLocalConfigSchema: unknown;
210
+ type McpServerLocalConfig = z.infer<typeof McpServerLocalConfigSchema>;
211
+ /**
212
+ * Remote MCP Server 配置(HTTP 传输)
213
+ */
214
+ declare const McpServerRemoteConfigSchema: unknown;
215
+ type McpServerRemoteConfig = z.infer<typeof McpServerRemoteConfigSchema>;
216
+ /**
217
+ * MCP Server 配置(联合类型)
218
+ */
219
+ declare const McpServerConfigSchema: unknown;
220
+ type McpServerConfig = z.infer<typeof McpServerConfigSchema>;
221
+ /**
222
+ * 扫描发现的 MCP 服务器信息
223
+ */
224
+ interface DiscoveredMcpServer {
225
+ /** 服务器名称(目录名) */
226
+ name: string;
227
+ /** 入口脚本路径 */
228
+ entryPath?: string;
229
+ /** 配置文件路径 */
230
+ configPath?: string;
231
+ /** package.json 路径 */
232
+ packagePath?: string;
233
+ /** 目录中的配置 */
234
+ directoryConfig?: Record<string, unknown>;
235
+ /** 解析后的默认命令(兼容不同路径) */
236
+ defaultCommand?: string[];
237
+ }
238
+ /**
239
+ * MCP 服务器状态
240
+ */
241
+ interface McpServerStatus {
242
+ /** 服务器名称 */
243
+ name: string;
244
+ /** 连接状态 */
245
+ status: "connecting" | "connected" | "disconnected" | "error";
246
+ /** 错误信息 */
247
+ error?: string;
248
+ /** 工具数量 */
249
+ toolsCount?: number;
250
+ }
251
+ import { z as z3 } from "zod";
252
+ import { ZodType as ZodType4, ZodTypeDef as ZodTypeDef2 } from "zod";
253
+ import { ZodType as ZodType3, ZodTypeDef } from "zod";
254
+ /**
255
+ * @fileoverview Environment types and interfaces
256
+ *
257
+ * 定义 Environment 的核心类型,包括:
258
+ * - Environment 配置
259
+ * - EnvEvent 事件类型
260
+ */
261
+ /**
262
+ * Environment Config
263
+ */
264
+ interface EnvironmentConfig {
265
+ /** 环境名称 */
266
+ name: string;
267
+ /** 环境版本 */
268
+ version: string;
269
+ /** 是否启用 */
270
+ enabled: boolean;
271
+ }
272
+ /**
273
+ * EnvEvent 元信息
274
+ */
275
+ interface EnvEventMetadata {
276
+ /** 触发事件的 session ID */
277
+ trigger_session_id?: string;
278
+ /** 触发事件的 agent ID */
279
+ trigger_agent_id?: string;
280
+ /** Agent 名称 */
281
+ trigger_agent_name?: string;
282
+ /** 环境名称 */
283
+ env_name?: string;
284
+ /** 事件来源 */
285
+ source?: string;
286
+ /** 其他元数据 */
287
+ [key: string]: unknown;
288
+ }
289
+ /**
290
+ * EnvEvent
291
+ *
292
+ * 统一的事件机制,用于:
293
+ * - Stream 事件(stream.start, stream.text, stream.completed 等)
294
+ * - 工具调用事件(tool.call, tool.result 等)
295
+ * - 会话事件(session.created, session.updated 等)
296
+ * - Agent 事件(agent.thinking, agent.acting 等)
297
+ */
298
+ interface EnvEvent<T = unknown> {
299
+ /** 事件 ID */
300
+ id: string;
301
+ /** 事件类型 */
302
+ type: string;
303
+ /** 时间戳 */
304
+ timestamp: number;
305
+ /** 元信息 */
306
+ metadata: EnvEventMetadata;
307
+ /** 事件负载 */
308
+ payload: T;
309
+ }
310
+ /**
311
+ * EnvEvent Handler
312
+ */
313
+ type EnvEventHandler = (event: EnvEvent) => void | Promise<void>;
314
+ /**
315
+ * EnvEvent 创建参数(部分属性,可选)
316
+ *
317
+ * 用于 pushEnvEvent 方法,允许传入部分属性,自动补全必填字段
318
+ */
319
+ interface EnvEventInput {
320
+ /** 事件类型(必填) */
321
+ type: string;
322
+ /** 事件 ID(可选,自动生成) */
323
+ id?: string;
324
+ /** 时间戳(可选,自动生成) */
325
+ timestamp?: number;
326
+ /** 元信息(可选,自动创建) */
327
+ metadata?: EnvEventMetadata;
328
+ /** 事件负载(可选) */
329
+ payload?: unknown;
330
+ }
331
+ /**
332
+ * Action 类型
333
+ */
334
+ interface Action {
335
+ /** Action 类型 */
336
+ type: string;
337
+ /** Action 参数 */
338
+ params?: Record<string, unknown>;
339
+ }
340
+ /**
341
+ * Tool Result
342
+ */
343
+ interface ToolResult {
344
+ /** 是否成功 */
345
+ success: boolean;
346
+ /** 输出内容 */
347
+ output: string | Record<string, unknown>;
348
+ /** 错误信息 */
349
+ error?: string;
350
+ }
351
+ /**
352
+ * Context
353
+ */
354
+ interface Context {
355
+ /** 会话 ID */
356
+ sessionId?: string;
357
+ /** 用户 ID */
358
+ userId?: string;
359
+ /** 工作目录 */
360
+ workdir?: string;
361
+ /** 中断信号 */
362
+ abort?: AbortSignal;
363
+ /** 元数据 */
364
+ metadata?: Record<string, unknown>;
365
+ }
366
+ import { z as z2, ZodType as ZodType2, ZodError } from "zod";
367
+ /**
368
+ * 沙箱配置
369
+ */
370
+ interface SandboxConfig {
371
+ /** 是否启用沙箱 */
372
+ enabled: boolean;
373
+ /** 沙箱类型 */
374
+ type: "native" | "docker";
375
+ /** 动作过滤 */
376
+ actionFilter?: {
377
+ /** 包含的动作 */
378
+ include?: string[];
379
+ /** 排除的动作 */
380
+ exclude?: string[];
381
+ };
382
+ /** 文件系统限制 */
383
+ filesystem?: {
384
+ /** 允许读取 */
385
+ allowRead?: string[];
386
+ /** 禁止读取 */
387
+ denyRead?: string[];
388
+ /** 允许写入 */
389
+ allowWrite?: string[];
390
+ /** 禁止写入 */
391
+ denyWrite?: string[];
392
+ };
393
+ /** 网络限制 */
394
+ network?: {
395
+ /** 允许的域名 */
396
+ allowedDomains?: string[];
397
+ /** 禁止的域名 */
398
+ deniedDomains?: string[];
399
+ };
400
+ /** Docker 配置 */
401
+ docker?: {
402
+ /** 镜像 */
403
+ image?: string;
404
+ /** 网络模式 */
405
+ networkMode?: "bridge" | "host" | "none";
406
+ /** 卷挂载 */
407
+ volumes?: Record<string, string>;
408
+ };
409
+ }
410
+ /**
411
+ * 工具执行上下文
412
+ */
413
+ interface ToolContext {
414
+ /** 工作目录 */
415
+ workdir?: string;
416
+ /** 用户 ID */
417
+ user_id?: string;
418
+ /** 会话 ID */
419
+ session_id?: string;
420
+ /** 消息 ID */
421
+ message_id?: string;
422
+ /** 中断信号 */
423
+ abort?: AbortSignal;
424
+ /** 额外元数据 */
425
+ metadata?: Record<string, unknown>;
426
+ /** 沙箱配置 */
427
+ sandbox?: SandboxConfig;
428
+ /** 沙箱 Provider */
429
+ sandboxProvider?: unknown | null;
430
+ }
431
+ /**
432
+ * 工具结果元数据
433
+ */
434
+ interface ToolResultMetadata {
435
+ /** 执行时间(毫秒) */
436
+ execution_time_ms: number;
437
+ /** 输出大小(字节) */
438
+ output_size?: number;
439
+ /** 标准输出 */
440
+ stdout?: string;
441
+ /** 标准错误 */
442
+ stderr?: string;
443
+ /** 退出码 */
444
+ exit_code?: number;
445
+ /** Token 使用量 */
446
+ usage?: {
447
+ inputTokens: number;
448
+ outputTokens: number;
449
+ totalTokens?: number;
450
+ };
451
+ /** 额外元数据 */
452
+ [key: string]: unknown;
453
+ }
454
+ /**
455
+ * 工具执行结果
456
+ */
457
+ interface ToolResult2 {
458
+ /** 是否成功 */
459
+ success: boolean;
460
+ /** 输出内容 */
461
+ output: string | Record<string, unknown>;
462
+ /** 错误信息 */
463
+ error?: string;
464
+ /** 结果元数据 */
465
+ metadata?: ToolResultMetadata;
466
+ }
467
+ /**
468
+ * 工具元数据
469
+ */
470
+ interface ToolMetadata {
471
+ /** 分类 */
472
+ category?: string;
473
+ /** 标签 */
474
+ tags?: string[];
475
+ /** 版本 */
476
+ version?: string;
477
+ /** 作者 */
478
+ author?: string;
479
+ /** 是否实验性 */
480
+ experimental?: boolean;
481
+ /** MCP 工具信息(MCP adapter 使用) */
482
+ mcpTool?: {
483
+ originalName: string;
484
+ originalDescription: string;
485
+ inputSchema?: unknown;
486
+ };
487
+ }
488
+ /**
489
+ * 工具沙箱配置
490
+ */
491
+ interface ToolSandboxConfig {
492
+ /** 是否启用沙箱 */
493
+ enabled: boolean;
494
+ /** 沙箱配置 */
495
+ config?: Partial<SandboxConfig>;
496
+ }
497
+ /**
498
+ * 工具权限配置
499
+ */
500
+ interface ToolPermissionConfig {
501
+ /** 是否需要用户确认 */
502
+ requireConfirmation?: boolean;
503
+ /** 权限级别 */
504
+ level?: "safe" | "dangerous" | "critical";
505
+ }
506
+ /**
507
+ * 工具信息
508
+ */
509
+ interface ToolInfo<Parameters extends ZodType2 = ZodType2> {
510
+ /** 工具名称 */
511
+ name: string;
512
+ /** 工具描述 */
513
+ description: string;
514
+ /** 参数 Schema */
515
+ parameters: Parameters;
516
+ /** 初始化函数(可选) */
517
+ init?: (ctx?: ToolContext) => Promise<void>;
518
+ /** 执行函数 */
519
+ execute: (args: z2.infer<Parameters>, ctx: ToolContext) => Promise<ToolResult2>;
520
+ /** 参数验证错误格式化(可选) */
521
+ formatValidationError?: (error: ZodError) => string;
522
+ /** 沙箱配置 */
523
+ sandbox?: ToolSandboxConfig;
524
+ /** 权限配置 */
525
+ permission?: ToolPermissionConfig;
526
+ /** 工具元数据 */
527
+ metadata?: ToolMetadata;
528
+ }
529
+ type AbortSignalType = AbortSignal;
530
+ /**
531
+ * Agent 执行上下文
532
+ */
533
+ interface AgentContext {
534
+ /** 会话 ID */
535
+ sessionId?: string;
536
+ /** 消息 ID */
537
+ messageId?: string;
538
+ /** 中断信号 */
539
+ abort?: AbortSignalType;
540
+ /** 额外的上下文信息(会添加到 system prompt) */
541
+ additionInfo?: string;
542
+ /** 元数据 */
543
+ metadata?: Record<string, unknown>;
544
+ /** Agent 类型(用于选择 Behavior Spec) */
545
+ agentType?: string;
546
+ /** 使用的模型 */
547
+ model?: string;
548
+ /** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
549
+ allowedTools?: string[];
550
+ /** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
551
+ deniedTools?: string[];
552
+ /** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
553
+ filterHistory?: boolean;
554
+ }
555
+ /**
556
+ * 服务配置接口
557
+ */
558
+ interface ServiceConfig {
559
+ /** 环境配置 */
560
+ environment?: {
561
+ name?: string;
562
+ version?: string;
563
+ };
564
+ /** 组件配置映射 */
565
+ components?: Record<string, ComponentConfigEntry>;
566
+ }
567
+ /**
568
+ * 组件配置项
569
+ */
570
+ interface ComponentConfigEntry {
571
+ /** 配置文件路径(可选) */
572
+ configPath?: string;
573
+ /** 环境变量前缀(可选) */
574
+ envPrefix?: string;
575
+ /** 直接配置对象(可选) */
576
+ config?: Record<string, unknown>;
577
+ /** 是否启用(可选,默认 true) */
578
+ enabled?: boolean;
579
+ }
580
+ /**
581
+ * 组件初始化选项(由 generateComponentOptions 生成)
582
+ */
583
+ interface GeneratedComponentOptions {
584
+ /** ConfigComponent 实例 */
585
+ configComponent: ConfigComponent;
586
+ /** 配置文件路径 */
587
+ configPath?: string;
588
+ /** 环境变量前缀 */
589
+ envPrefix?: string;
590
+ /** 直接配置对象 */
591
+ config?: Record<string, unknown>;
592
+ /** 允许的其他属性 */
593
+ [key: string]: unknown;
594
+ }
595
+ /**
596
+ * Environment 接口
597
+ *
598
+ * 定义 Agent 运行时的核心能力接口。
599
+ */
600
+ interface Environment {
601
+ /** 环境名称 */
602
+ readonly name: string;
603
+ /** 环境版本 */
604
+ readonly version: string;
605
+ /** 获取环境配置 */
606
+ getConfig(): EnvironmentConfig;
607
+ /**
608
+ * 注册组件
609
+ */
610
+ registerComponent(component: Component): void;
611
+ /**
612
+ * 注销组件
613
+ */
614
+ unregisterComponent(name: string): void;
615
+ /**
616
+ * 获取组件
617
+ */
618
+ getComponent<T extends Component>(name: string): T | undefined;
619
+ /**
620
+ * 列出所有组件
621
+ */
622
+ listComponents(): Component[];
623
+ /**
624
+ * 处理自然语言查询(核心入口)
625
+ *
626
+ * @param query 用户查询文本
627
+ * @param context 执行上下文(可选)
628
+ * @returns 完整的文本响应
629
+ */
630
+ handle_query(query: string, context?: AgentContext): Promise<string>;
631
+ /**
632
+ * 处理动作
633
+ */
634
+ handle_action(action: Action, context: Context): Promise<ToolResult>;
635
+ /**
636
+ * 订阅 EnvEvent(返回取消订阅函数)
637
+ */
638
+ subscribe(handler: EnvEventHandler): () => void;
639
+ /**
640
+ * 订阅指定类型事件
641
+ */
642
+ subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
643
+ /**
644
+ * 订阅所有事件(通配符)
645
+ */
646
+ subscribeAll(handler: EnvEventHandler): () => void;
647
+ /**
648
+ * 推送事件
649
+ *
650
+ * @param event EnvEvent 或 EnvEventInput(部分属性)
651
+ */
652
+ pushEnvEvent(event: EnvEvent | EnvEventInput): void;
653
+ /**
654
+ * 从配置文件加载服务配置
655
+ *
656
+ * @param configPath 配置文件路径(基于 XDG_DATA_HOME)
657
+ * @returns 解析后的服务配置对象
658
+ */
659
+ loadServiceConfig(configPath: string): Promise<ServiceConfig>;
660
+ /**
661
+ * 生成组件初始化选项
662
+ *
663
+ * 根据组件配置项生成可用于初始化的选项对象。
664
+ *
665
+ * @param componentName 组件名称
666
+ * @param configEntry 组件配置项
667
+ * @returns 生成的组件初始化选项
668
+ */
669
+ generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
670
+ /**
671
+ * 注册组件并用配置初始化
672
+ *
673
+ * 便捷方法:注册组件并通过 ConfigComponent 初始化。
674
+ *
675
+ * @param component 要注册的组件实例
676
+ * @param configEntry 组件配置项
677
+ */
678
+ registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
679
+ /**
680
+ * 从配置文件初始化整个环境
681
+ *
682
+ * 加载服务配置,注册并初始化所有配置的组件。
683
+ *
684
+ * @param configPath 配置文件路径(基于 XDG_DATA_HOME)
685
+ */
686
+ initFromConfig(configPath: string): Promise<void>;
687
+ }
688
+ /**
689
+ * Component 状态
690
+ */
691
+ type ComponentStatus = "created" | "initializing" | "running" | "stopping" | "stopped" | "error";
692
+ /**
693
+ * Component 配置
694
+ */
695
+ interface ComponentConfig {
696
+ name: string;
697
+ version: string;
698
+ enabled: boolean;
699
+ options?: Record<string, unknown>;
700
+ /**
701
+ * Environment 实例(可选)
702
+ *
703
+ * 推荐在 init 时接收 env 实例,以便:
704
+ * - 通过 env.getComponent() 获取其他组件
705
+ * - 通过 env.pushEnvEvent() 发布事件
706
+ * - 通过 env.handle_query() 处理查询
707
+ *
708
+ * 如果未提供,部分 Component 仍可正常工作(如测试场景)
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * async onInit(): Promise<void> {
713
+ * if (this.env) {
714
+ * const configComp = this.env.getComponent("config");
715
+ * }
716
+ * }
717
+ * ```
718
+ */
719
+ env?: Environment;
720
+ }
721
+ /**
722
+ * Component 路径声明
723
+ */
724
+ interface ComponentPaths {
725
+ base: "config" | "state" | "data" | "cache";
726
+ subPath: string;
727
+ isDirectory: boolean;
728
+ }
729
+ /**
730
+ * Component Schema(注册配置)
731
+ */
732
+ interface ComponentSchema {
733
+ /** Component 名称 */
734
+ name: string;
735
+ /** 配置 Schema(Zod) */
736
+ schema: ZodType3<unknown, ZodTypeDef, unknown>;
737
+ /** 默认值(从 Schema 提取) */
738
+ defaults: Record<string, unknown>;
739
+ /** 路径声明 */
740
+ paths?: Record<string, ComponentPaths>;
741
+ /** 元信息 */
742
+ metadata?: {
743
+ description?: string;
744
+ version?: string;
745
+ author?: string;
746
+ };
747
+ }
748
+ /**
749
+ * Component 配置变更事件
750
+ */
751
+ interface ComponentConfigChangeEvent {
752
+ /** Component 名称 */
753
+ component: string;
754
+ /** 变更的配置键 */
755
+ key: string;
756
+ /** 旧值 */
757
+ oldValue: unknown;
758
+ /** 新值 */
759
+ newValue: unknown;
760
+ /** 是否持久化 */
761
+ persisted: boolean;
762
+ /** 时间戳 */
763
+ timestamp: number;
764
+ }
765
+ /**
766
+ * Component 配置监听回调
767
+ */
768
+ type ComponentWatchCallback = (event: ComponentConfigChangeEvent) => void | Promise<void>;
769
+ /**
770
+ * Component 基类接口
771
+ */
772
+ interface Component {
773
+ /** Component 名称 */
774
+ readonly name: string;
775
+ /** Component 版本 */
776
+ readonly version: string;
777
+ /** 获取状态 */
778
+ getStatus(): ComponentStatus;
779
+ /** 获取配置 */
780
+ getConfig(): ComponentConfig;
781
+ /** 初始化 */
782
+ init(config: ComponentConfig): Promise<void>;
783
+ /** 启动 */
784
+ start(): Promise<void>;
785
+ /** 停止 */
786
+ stop(): Promise<void>;
787
+ }
788
+ /**
789
+ * Component 基类实现
790
+ */
791
+ declare abstract class BaseComponent implements Component {
792
+ abstract readonly name: string;
793
+ abstract readonly version: string;
794
+ protected _status: ComponentStatus;
795
+ protected _enabled: boolean;
796
+ protected env: Environment;
797
+ /** Hook 管理器 - 子类初始化时由构造函数设置 */
798
+ readonly hookManager: HookManager;
799
+ constructor();
800
+ getStatus(): ComponentStatus;
801
+ getConfig(): ComponentConfig;
802
+ /**
803
+ * 检查 Environment 是否已初始化
804
+ */
805
+ protected isEnvInitialized(): boolean;
806
+ protected setStatus(status: ComponentStatus): void;
807
+ /**
808
+ * 获取 Environment 实例
809
+ */
810
+ protected getEnv(): Environment;
811
+ init(config?: ComponentConfig): Promise<void>;
812
+ start(): Promise<void>;
813
+ stop(): Promise<void>;
814
+ /**
815
+ * 子类可覆盖的钩子方法
816
+ */
817
+ protected onInit(): Promise<void>;
818
+ protected onStart(): Promise<void>;
819
+ protected onStop(): Promise<void>;
820
+ /**
821
+ * 注册 Hook
822
+ *
823
+ * @param hookPoint Hook 点名称
824
+ * @param hook Hook 实例
825
+ */
826
+ protected registerHook<T = unknown>(hookPoint: string, hook: Hook<T>): void;
827
+ /**
828
+ * 便捷方法:快速注册 Hook
829
+ */
830
+ protected addHook<T = unknown>(hookPoint: string, name: string, fn: HookFn<T>, priority?: number): void;
831
+ /**
832
+ * 便捷方法:按名称取消注册 Hook
833
+ */
834
+ protected removeHook(hookPoint: string, name: string): boolean;
835
+ /**
836
+ * 执行 Hook
837
+ */
838
+ protected executeHooks<T = unknown>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
839
+ /**
840
+ * 获取 ConfigComponent 实例
841
+ *
842
+ * 子类可使用此方法获取配置组件,支持热更新
843
+ */
844
+ protected getConfigComponent(): {
845
+ get(key: string): unknown;
846
+ } | undefined;
847
+ /**
848
+ * 动态获取运行时配置值
849
+ *
850
+ * 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
851
+ * 适用于运行时可能变化的配置(如 API Keys、模型参数)
852
+ *
853
+ * @param key 配置键(支持点号分隔的路径,如 "llm.temperature")
854
+ * @param defaultValue 默认值
855
+ * @returns 配置值或默认值
856
+ *
857
+ * @example
858
+ * ```typescript
859
+ * // 获取 LLM 温度配置(可能支持热更新)
860
+ * const temperature = this.getRuntimeConfig("llm.temperature", 0.7);
861
+ *
862
+ * // 获取 API Key
863
+ * const apiKey = this.getRuntimeConfig<string>("llm.providers.openai.apiKey");
864
+ * ```
865
+ */
866
+ protected getRuntimeConfig<T>(key: string, defaultValue: T): T;
867
+ }
868
+ /**
869
+ * ConfigSource 类型
870
+ */
871
+ type ConfigSourceType = "memory" | "file" | "env" | "remote";
872
+ /**
873
+ * SourceRegistration - Source 注册配置
874
+ */
875
+ interface SourceRegistration {
876
+ /** Source 类型 */
877
+ type: ConfigSourceType;
878
+ /** 相对路径(file 类型使用,基于 XDG_DATA_HOME) */
879
+ relativePath?: string;
880
+ /** 环境变量前缀(env 类型使用) */
881
+ envPrefix?: string;
882
+ /** 优先级,默认值:memory=0, file=10, env=20 */
883
+ priority?: number;
884
+ /** 是否可选(file 类型使用,文件不存在时不报错) */
885
+ optional?: boolean;
886
+ /** 是否启用文件监听(file 类型使用,默认 true) */
887
+ watch?: boolean;
888
+ }
889
+ /**
890
+ * KeyRegistration - 配置 Key 注册
891
+ */
892
+ interface KeyRegistration {
893
+ /** 配置 Key(支持点号嵌套,如 "llm.provider") */
894
+ key: string;
895
+ /** 优先使用的 Source 列表(按优先级从低到高) */
896
+ sources: ConfigSourceType[];
897
+ /** 自定义优先级(覆盖默认优先级) */
898
+ priority?: number;
899
+ /** 默认值 */
900
+ default?: unknown;
901
+ }
902
+ /**
903
+ * ComponentRegistration - Component 注册配置
904
+ */
905
+ interface ComponentRegistration {
906
+ /** Component 名称 */
907
+ name: string;
908
+ /** 声明需要的 Source */
909
+ sources: SourceRegistration[];
910
+ /** 声明需要的配置 Key */
911
+ keys: KeyRegistration[];
912
+ /** 配置 Schema(用于验证,可选) */
913
+ schema?: ZodType4<unknown, ZodTypeDef2, unknown>;
914
+ /** 默认值 */
915
+ defaults?: Record<string, unknown>;
916
+ }
917
+ /**
918
+ * ConfigSource 接口
919
+ */
920
+ interface ConfigSource {
921
+ readonly name: ConfigSourceType;
922
+ readonly priority: number;
923
+ read(key: string): unknown | undefined;
924
+ write?(key: string, value: unknown): boolean;
925
+ delete?(key: string): boolean;
926
+ list(): Array<{
927
+ key: string;
928
+ value: unknown;
929
+ }>;
930
+ watch?(callback: (event: ConfigChangeEvent) => void): () => void;
931
+ }
932
+ /**
933
+ * Config 变更事件
934
+ */
935
+ interface ConfigChangeEvent {
936
+ type: "change" | "add" | "delete";
937
+ key: string;
938
+ oldValue: unknown;
939
+ newValue: unknown;
940
+ source: ConfigSourceType;
941
+ timestamp: number;
942
+ }
943
+ /**
944
+ * ConfigComponent 配置
945
+ */
946
+ interface ConfigComponentOptions {
947
+ /** 持久化文件路径 */
948
+ persistFile?: string;
949
+ /** 防抖延迟(ms) */
950
+ debounceMs?: number;
951
+ /** 最大批量大小 */
952
+ maxBatchSize?: number;
953
+ }
954
+ /**
955
+ * ConfigComponent
956
+ */
957
+ declare class ConfigComponent extends BaseComponent {
958
+ readonly name = "config";
959
+ readonly version = "1.0.0";
960
+ private memorySource;
961
+ private sources;
962
+ private componentSchemas;
963
+ private componentPaths;
964
+ private watchers;
965
+ /** Source watch unsubscribe 函数 */
966
+ private sourceUnwatchFns;
967
+ private persistQueue;
968
+ private persistFile?;
969
+ /** Key 注册表:key -> KeyRegistration */
970
+ private keyRegistry;
971
+ /** Component 注册表:name -> ComponentRegistration */
972
+ private componentRegistrations;
973
+ /** 协议解析器 */
974
+ private protocolResolver?;
975
+ /** XDG_DATA_HOME 缓存(用于测试注入) */
976
+ private __xdgDataHome?;
977
+ /** Source 注册配置(延迟创建) */
978
+ private pendingSources;
979
+ /** Source 唯一标识缓存:type:relativePath -> true */
980
+ private sourceKeys;
981
+ /**
982
+ * 获取 XDG_DATA_HOME(动态获取,支持运行时覆盖)
983
+ */
984
+ getXdgDataHome(): string;
985
+ /**
986
+ * 设置 XDG_DATA_HOME(用于测试)
987
+ */
988
+ setXdgDataHome(path: string): void;
989
+ constructor(options?: ConfigComponentOptions);
990
+ /**
991
+ * 注册 Component Schema
992
+ */
993
+ register(schema: ComponentSchema): void;
994
+ /**
995
+ * 注销 Component
996
+ */
997
+ unregister(name: string): boolean;
998
+ /**
999
+ * 检查是否已注册
1000
+ */
1001
+ isRegistered(name: string): boolean;
1002
+ /**
1003
+ * 列出所有注册的 Component
1004
+ */
1005
+ listComponents(): string[];
1006
+ /**
1007
+ * 获取配置值(支持 xxx.yyy.zzz 嵌套访问)
1008
+ * 支持两种模式:
1009
+ * 1. 完整 key:直接查找,如 "component.key" -> 读取 "component.key"
1010
+ * 2. 嵌套对象:查找 component 对象后从中获取属性,如 "component.nested.deep"
1011
+ * -> 先找 "component.nested",再获取其 "deep" 属性
1012
+ */
1013
+ get(key: string): unknown;
1014
+ /**
1015
+ * 批量获取
1016
+ */
1017
+ getMany(keys: string[]): Record<string, unknown>;
1018
+ /**
1019
+ * 设置配置值(内存级别 + 异步持久化)
1020
+ */
1021
+ set(key: string, value: unknown): Promise<void>;
1022
+ /**
1023
+ * 批量设置
1024
+ */
1025
+ setMany(config: Record<string, unknown>): Promise<void>;
1026
+ /**
1027
+ * 获取 Component 的路径
1028
+ */
1029
+ getPath(component: string, subPath?: string): string;
1030
+ /**
1031
+ * 手动持久化
1032
+ */
1033
+ save(key?: string): Promise<void>;
1034
+ /**
1035
+ * 重置到默认值
1036
+ */
1037
+ reset(key: string): Promise<void>;
1038
+ /**
1039
+ * 监听配置变更
1040
+ */
1041
+ watch(pattern: string, callback: ComponentWatchCallback): () => void;
1042
+ /**
1043
+ * 添加配置源
1044
+ */
1045
+ addSource(source: ConfigSource): void;
1046
+ /**
1047
+ * 获取 Source 唯一标识
1048
+ */
1049
+ private getSourceKey;
1050
+ /**
1051
+ * 移除配置源
1052
+ */
1053
+ removeSource(name: ConfigSourceType): boolean;
1054
+ /**
1055
+ * 关闭所有配置源的 watcher(用于优雅退出)
1056
+ */
1057
+ unwatchAll(): void;
1058
+ /**
1059
+ * 获取配置源列表
1060
+ */
1061
+ getSources(): ConfigSource[];
1062
+ private getNestedValue;
1063
+ private notifyWatchers;
1064
+ private persistToFile;
1065
+ /**
1066
+ * 注册配置 Source
1067
+ *
1068
+ * Source 会在首次 load() 时被创建
1069
+ *
1070
+ * @example
1071
+ * config.registerSource({ type: "file", relativePath: "llm-config.jsonc" });
1072
+ * config.registerSource({ type: "env", envPrefix: "LLM" });
1073
+ */
1074
+ registerSource(registration: SourceRegistration): void;
1075
+ /**
1076
+ * 创建 Source 实例
1077
+ */
1078
+ private createSource;
1079
+ /**
1080
+ * 确保所有待创建的 Source 已被创建
1081
+ */
1082
+ private ensureSourcesCreated;
1083
+ /**
1084
+ * 注册配置 Key
1085
+ *
1086
+ * @example
1087
+ * config.registerKeys([
1088
+ * { key: "llm.provider", sources: ["file", "memory"], default: "openai" },
1089
+ * { key: "llm.model", sources: ["file"] },
1090
+ * ]);
1091
+ */
1092
+ registerKeys(keys: KeyRegistration[]): void;
1093
+ /**
1094
+ * 注册 Component(一次性注册 Source 和 Keys)
1095
+ *
1096
+ * @example
1097
+ * config.registerComponent({
1098
+ * name: "llm",
1099
+ * sources: [
1100
+ * { type: "file", relativePath: "llm-config.jsonc" },
1101
+ * { type: "env", envPrefix: "LLM" },
1102
+ * ],
1103
+ * keys: [
1104
+ * { key: "llm.provider", sources: ["file", "env", "memory"] },
1105
+ * ],
1106
+ * });
1107
+ */
1108
+ registerComponent(registration: ComponentRegistration): void;
1109
+ /**
1110
+ * 按需加载配置
1111
+ *
1112
+ * 从注册的 Source 加载已注册 Keys 的配置值到内存中
1113
+ *
1114
+ * @param componentName - 可选,指定要加载的 Component 名称
1115
+ *
1116
+ * @example
1117
+ * // 加载所有已注册的 Keys
1118
+ * await config.load();
1119
+ *
1120
+ * // 只加载指定 Component 的 Keys
1121
+ * await config.load("llm");
1122
+ */
1123
+ load(componentName?: string): Promise<void>;
1124
+ /**
1125
+ * 获取已注册的 Source 列表
1126
+ */
1127
+ getRegisteredSources(): ConfigSource[];
1128
+ }
1129
+ /**
1130
+ * MCP 路径配置
1131
+ */
1132
+ interface McpPath {
1133
+ /** 来源类型 */
1134
+ type: "user" | "project" | "custom";
1135
+ /** 路径 */
1136
+ path: string;
1137
+ }
1138
+ /**
1139
+ * McpComponent 配置
1140
+ */
1141
+ interface McpComponentConfig {
1142
+ /** 扫描路径列表 */
1143
+ mcpPaths: McpPath[];
1144
+ /** 显式配置的服务器 */
1145
+ servers?: Record<string, z3.infer<typeof McpServerConfigSchema>>;
1146
+ /** 默认超时(毫秒) */
1147
+ timeout?: number;
1148
+ /** 是否启用 */
1149
+ enabled?: boolean;
1150
+ }
1151
+ /**
1152
+ * McpComponentOptions(通过 options 传递)
1153
+ */
1154
+ interface McpComponentOptions {
1155
+ /** ConfigComponent 实例(必填) */
1156
+ configComponent: ConfigComponent;
1157
+ /** 配置文件相对路径 */
1158
+ configPath?: string;
1159
+ /** 环境变量前缀 */
1160
+ envPrefix?: string;
1161
+ /** 直接传入的配置对象(最高优先级) */
1162
+ config?: Partial<McpComponentConfig>;
1163
+ }
1164
+ /**
1165
+ * 默认 MCP 配置
1166
+ */
1167
+ declare const DEFAULT_MCP_CONFIG: McpComponentConfig;
1168
+ /**
1169
+ * 配置 Key 列表(用于 ConfigComponent 注册)
1170
+ */
1171
+ declare const MCP_CONFIG_KEYS: readonly ["mcp.enabled", "mcp.timeout", "mcp.mcpPaths", "mcp.servers"];
1172
+ /**
1173
+ * 获取路径优先级
1174
+ */
1175
+ declare function getMcpPathPriority(type: string): number;
1176
+ /**
1177
+ * McpComponent
1178
+ *
1179
+ * MCP 客户端管理组件
1180
+ *
1181
+ * 功能:
1182
+ * 1. 配置管理(支持 file/env/object 三层配置)
1183
+ * 2. 扫描 MCP 服务器
1184
+ * 3. 连接/断开 MCP 服务器
1185
+ * 4. 注册 MCP tools 到 ToolComponent
1186
+ */
1187
+ declare class McpComponent extends BaseComponent {
1188
+ readonly name = "mcp";
1189
+ readonly version = "1.0.0";
1190
+ private config;
1191
+ private toolComponent?;
1192
+ private configComponent?;
1193
+ private scanner?;
1194
+ private loader?;
1195
+ private serverStatus;
1196
+ private registeredTools;
1197
+ constructor();
1198
+ init(config?: ComponentConfig): Promise<void>;
1199
+ start(): Promise<void>;
1200
+ stop(): Promise<void>;
1201
+ private registerConfig;
1202
+ private flattenConfig;
1203
+ private loadServers;
1204
+ private registerServerTools;
1205
+ /**
1206
+ * 获取服务器状态
1207
+ */
1208
+ getServerStatus(name: string): McpServerStatus | undefined;
1209
+ /**
1210
+ * 列出所有服务器
1211
+ */
1212
+ listServers(): McpServerStatus[];
1213
+ /**
1214
+ * 列出所有 MCP 工具
1215
+ */
1216
+ listTools(): ToolInfo[];
1217
+ /**
1218
+ * 重新加载所有服务器
1219
+ */
1220
+ reload(): Promise<void>;
1221
+ }
1222
+ /**
1223
+ * MCP 服务器扫描器
1224
+ *
1225
+ * 扫描多个路径下的 MCP 服务器子目录
1226
+ */
1227
+ declare class McpScanner {
1228
+ private mcpPaths;
1229
+ private serversMap;
1230
+ constructor(mcpPaths: McpPath[]);
1231
+ /**
1232
+ * 扫描所有 mcpPaths
1233
+ */
1234
+ scan(): Promise<Map<string, DiscoveredMcpServer>>;
1235
+ /**
1236
+ * 扫描单个路径
1237
+ */
1238
+ private scanPath;
1239
+ /**
1240
+ * 发现单个 MCP 服务器
1241
+ */
1242
+ private discoverServer;
1243
+ /**
1244
+ * 查找入口脚本
1245
+ */
1246
+ private findEntryScript;
1247
+ /**
1248
+ * 获取扫描结果
1249
+ */
1250
+ getServers(): Map<string, DiscoveredMcpServer>;
1251
+ }
1252
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
1253
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
1254
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
1255
+ /**
1256
+ * MCP 客户端条目
1257
+ */
1258
+ interface McpClientEntry {
1259
+ name: string;
1260
+ client: Client;
1261
+ transport: StdioClientTransport | StreamableHTTPClientTransport;
1262
+ config: McpServerConfig;
1263
+ }
1264
+ /**
1265
+ * MCP 服务器加载器
1266
+ *
1267
+ * 负责:
1268
+ * 1. 构建默认配置
1269
+ * 2. 合并显式配置
1270
+ * 3. 连接/断开 MCP 服务器
1271
+ */
1272
+ declare class McpLoader {
1273
+ private clients;
1274
+ private defaultTimeout;
1275
+ constructor(defaultTimeout?: number);
1276
+ /**
1277
+ * 构建默认配置(从扫描结果)
1278
+ *
1279
+ * @param server - 扫描发现的 MCP 服务器信息
1280
+ * @returns MCP 服务器配置
1281
+ */
1282
+ buildDefaultConfig(server: DiscoveredMcpServer): McpServerConfig;
1283
+ /**
1284
+ * 合并配置(显式配置覆盖默认配置)
1285
+ */
1286
+ mergeConfig(defaultConfig: McpServerConfig, explicitConfig?: Partial<McpServerConfig>): McpServerConfig;
1287
+ /**
1288
+ * 连接到 MCP 服务器
1289
+ */
1290
+ connect(name: string, config: McpServerConfig): Promise<McpClientEntry>;
1291
+ /**
1292
+ * 断开连接
1293
+ */
1294
+ disconnect(name: string): Promise<void>;
1295
+ /**
1296
+ * 断开所有连接
1297
+ */
1298
+ disconnectAll(): Promise<void>;
1299
+ /**
1300
+ * 获取客户端
1301
+ */
1302
+ getClient(name: string): McpClientEntry | undefined;
1303
+ /**
1304
+ * 获取所有客户端
1305
+ */
1306
+ getAllClients(): Map<string, McpClientEntry>;
1307
+ /**
1308
+ * 检查是否已连接
1309
+ */
1310
+ isConnected(name: string): boolean;
1311
+ }
1312
+ import { z as z4 } from "zod";
1313
+ import { Tool as McpTool } from "@modelcontextprotocol/sdk/types.js";
1314
+ import { Client as Client2 } from "@modelcontextprotocol/sdk/client/index.js";
1315
+ /**
1316
+ * 将 MCP 工具转换为 Environment Tool
1317
+ *
1318
+ * 命名策略: mcp_{serverName}_{toolName}
1319
+ */
1320
+ declare function adaptMcpTool(mcpTool: McpTool, mcpClient: Client2, serverName: string): ToolInfo;
1321
+ /**
1322
+ * 转换 MCP inputSchema 为 Zod schema
1323
+ *
1324
+ * 关键:保留参数描述,让 LLM 知道每个参数的用途
1325
+ */
1326
+ declare function convertInputSchemaToZod(inputSchema: McpTool["inputSchema"]): z4.ZodType<unknown>;
1327
+ /**
1328
+ * 创建 MCP 工具描述
1329
+ */
1330
+ declare function createMcpToolsDescription(tools: ToolInfo[]): string;
1331
+ export { getMcpPathPriority, createMcpToolsDescription, convertInputSchemaToZod, adaptMcpTool, McpServerStatus, McpServerRemoteConfigSchema, McpServerRemoteConfig, McpServerLocalConfigSchema, McpServerLocalConfig, McpServerConfigSchema, McpServerConfig, McpScanner, McpPath, McpLoader, McpComponentOptions, McpComponentConfig, McpComponent, McpClientEntry, MCP_CONFIG_KEYS, DiscoveredMcpServer, DEFAULT_MCP_CONFIG };