agentdev 0.1.0

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.
@@ -0,0 +1,3836 @@
1
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
+ import { IncomingMessage, ServerResponse } from 'http';
3
+
4
+ /**
5
+ * 上下文查询构建器
6
+ *
7
+ * 提供链式 API 用于过滤和聚合消息
8
+ * 从 ContextFeature 移植到内核,作为 Context 的原生能力
9
+ */
10
+
11
+ /**
12
+ * 上下文查询构建器
13
+ *
14
+ * 提供链式 API 用于过滤和聚合消息
15
+ */
16
+ declare class ContextQuery {
17
+ private messages;
18
+ private indexes;
19
+ constructor(messages: EnrichedMessage[], indexes: Map<string, Set<string>>);
20
+ private result;
21
+ /**
22
+ * 按角色过滤
23
+ */
24
+ byRole(...roles: string[]): this;
25
+ /**
26
+ * 按标签过滤(可组合)
27
+ */
28
+ byTag(...tags: MessageTag[]): this;
29
+ /**
30
+ * 按工具名过滤(使用索引加速)
31
+ */
32
+ byTool(name: string): this;
33
+ /**
34
+ * 按任务 ID 过滤(使用索引加速)
35
+ */
36
+ byTask(taskId: string): this;
37
+ /**
38
+ * 按子代理 ID 过滤
39
+ */
40
+ byAgentId(agentId: string): this;
41
+ /**
42
+ * 按时间起点过滤
43
+ */
44
+ since(timestamp: number): this;
45
+ /**
46
+ * 按轮次范围过滤
47
+ */
48
+ inTurns(from: number, to?: number): this;
49
+ /**
50
+ * content 包含指定文本
51
+ */
52
+ containing(text: string): this;
53
+ /**
54
+ * 最近 N 条
55
+ */
56
+ recent(n: number): this;
57
+ /**
58
+ * 执行查询,返回结果数组
59
+ */
60
+ exec(): EnrichedMessage[];
61
+ /**
62
+ * 获取第一条
63
+ */
64
+ first(): EnrichedMessage | undefined;
65
+ /**
66
+ * 获取最后一条
67
+ */
68
+ last(): EnrichedMessage | undefined;
69
+ /**
70
+ * 计数
71
+ */
72
+ count(): number;
73
+ /**
74
+ * 时间跨度统计
75
+ */
76
+ timeSpan(): {
77
+ start: number;
78
+ end: number;
79
+ duration: number;
80
+ };
81
+ /**
82
+ * 按工具分组统计
83
+ */
84
+ groupByTool(): Record<string, number>;
85
+ }
86
+
87
+ /**
88
+ * 上下文管理器
89
+ * 管理消息数组,提供简单的操作方法
90
+ *
91
+ * 内核化能力:
92
+ * - 消息元数据包装(EnrichedMessage)
93
+ * - 内容解析和索引
94
+ * - 查询接口
95
+ */
96
+
97
+ /**
98
+ * 工具执行结果(用于 addToolMessage)
99
+ */
100
+ interface ToolExecResult {
101
+ success: boolean;
102
+ result: string | Record<string, any>;
103
+ error?: string;
104
+ }
105
+ /**
106
+ * 上下文快照类型 - 用于序列化
107
+ */
108
+ interface ContextSnapshot {
109
+ version: number;
110
+ messages: Message[];
111
+ enrichedMessages?: EnrichedMessage[];
112
+ sequence?: number;
113
+ }
114
+ declare class Context {
115
+ private messages;
116
+ private enrichedMessages;
117
+ private indexes;
118
+ private sequence;
119
+ /**
120
+ * 添加一条消息
121
+ */
122
+ add(message: Message): this;
123
+ /**
124
+ * 添加多条消息
125
+ */
126
+ addAll(messages: Message[]): this;
127
+ /**
128
+ * 获取所有消息的副本
129
+ */
130
+ getAll(): Message[];
131
+ /**
132
+ * 获取消息数量
133
+ */
134
+ get length(): number;
135
+ /**
136
+ * 获取最后一条消息
137
+ */
138
+ getLast(): Message | undefined;
139
+ /**
140
+ * 清空消息
141
+ */
142
+ clear(): void;
143
+ /**
144
+ * 应用中间件处理消息
145
+ */
146
+ apply(middleware: (messages: Message[]) => Message[]): this;
147
+ /**
148
+ * 过滤消息
149
+ */
150
+ filter(predicate: (msg: Message) => boolean): Message[];
151
+ /**
152
+ * 切片
153
+ */
154
+ slice(start?: number, end?: number): Message[];
155
+ /**
156
+ * 序列化为快照
157
+ */
158
+ toJSON(): ContextSnapshot;
159
+ /**
160
+ * 从快照恢复
161
+ */
162
+ static fromJSON(snapshot: ContextSnapshot): Context;
163
+ /**
164
+ * 用快照原地恢复当前 Context
165
+ */
166
+ restore(snapshot: ContextSnapshot): this;
167
+ /**
168
+ * 序列化为 JSON 字符串
169
+ */
170
+ serialize(): string;
171
+ /**
172
+ * 从 JSON 字符串反序列化
173
+ */
174
+ static deserialize(json: string): Context;
175
+ /**
176
+ * 统一消息入口(内部方法)
177
+ */
178
+ private addMessage;
179
+ /**
180
+ * 添加用户消息
181
+ */
182
+ addUserMessage(content: string, turn: number): void;
183
+ /**
184
+ * 添加助手响应
185
+ */
186
+ addAssistantMessage(response: LLMResponse, turn: number): void;
187
+ /**
188
+ * 添加工具结果
189
+ */
190
+ addToolMessage(call: ToolCall, result: ToolExecResult, turn: number): void;
191
+ /**
192
+ * 添加系统消息
193
+ */
194
+ addSystemMessage(content: string, turn: number, source?: string): void;
195
+ /**
196
+ * 查询构建器
197
+ */
198
+ query(): ContextQuery;
199
+ /**
200
+ * 按轮次获取消息
201
+ */
202
+ getByTurn(turn: number): EnrichedMessage[];
203
+ /**
204
+ * 获取最近 N 条消息
205
+ */
206
+ getRecent(n: number): EnrichedMessage[];
207
+ /**
208
+ * 获取所有丰富化消息(内部使用)
209
+ */
210
+ getAllEnriched(): EnrichedMessage[];
211
+ /**
212
+ * 丰富化消息:添加元数据
213
+ */
214
+ private enrich;
215
+ /**
216
+ * 推断消息标签
217
+ */
218
+ private inferTags;
219
+ /**
220
+ * 解析 content 提取结构化信息
221
+ */
222
+ private parseContent;
223
+ /**
224
+ * 更新索引
225
+ */
226
+ private updateIndexes;
227
+ /**
228
+ * 从 enrichedMessages 重建索引
229
+ */
230
+ private rebuildIndexes;
231
+ /**
232
+ * 生成唯一 ID
233
+ */
234
+ private generateId;
235
+ }
236
+
237
+ /**
238
+ * 生命周期类型定义
239
+ * 定义 Agent 生命周期钩子相关的类型
240
+ */
241
+
242
+ /**
243
+ * 决策状态(反向钩子返回值)
244
+ *
245
+ * 用于控制执行流程的三个状态
246
+ */
247
+ declare enum Decision {
248
+ /** 批准:确认执行,跳过后续决策 */
249
+ Approve = "approve",
250
+ /** 拒绝:阻止执行,跳过后续决策 */
251
+ Deny = "deny",
252
+ /** 继续:交给下一个决策节点,使用默认行为 */
253
+ Continue = "continue"
254
+ }
255
+ /**
256
+ * 决策结果类型
257
+ */
258
+ type DecisionResult = Decision | {
259
+ /** 决策动作 */
260
+ action: Decision;
261
+ /** 拒绝原因(用于日志/调试) */
262
+ reason?: string;
263
+ /** 附加元数据 */
264
+ metadata?: Record<string, any>;
265
+ };
266
+ /**
267
+ * Agent 初始化上下文
268
+ */
269
+ interface AgentInitiateContext {
270
+ /** 消息上下文 */
271
+ context: Context;
272
+ }
273
+ /**
274
+ * Agent 销毁上下文
275
+ */
276
+ interface AgentDestroyContext {
277
+ /** 消息上下文 */
278
+ context: Context;
279
+ }
280
+ /**
281
+ * Call 开始上下文
282
+ */
283
+ interface CallStartContext {
284
+ /** 用户输入 */
285
+ input: string;
286
+ /** 消息上下文 */
287
+ context: Context;
288
+ /** 是否首次调用 */
289
+ isFirstCall: boolean;
290
+ /** Agent 实例(用于访问 setUserInput/getUserInput 等 API) */
291
+ agent?: any;
292
+ }
293
+ /**
294
+ * Call 结束上下文
295
+ */
296
+ interface CallFinishContext {
297
+ /** 用户输入 */
298
+ input: string;
299
+ /** 消息上下文 */
300
+ context: Context;
301
+ /** 最终响应 */
302
+ response: string;
303
+ /** 执行的步骤数 */
304
+ steps: number;
305
+ /** 是否成功完成 */
306
+ completed: boolean;
307
+ }
308
+ /**
309
+ * Step 开始上下文
310
+ *
311
+ * Step 是 ReAct 循环中的单次迭代
312
+ */
313
+ interface StepStartContext {
314
+ /** 当前步骤序号(从 0 开始) */
315
+ step: number;
316
+ /** 当前调用序号(用户交互次数,从 0 开始) */
317
+ callIndex: number;
318
+ /** 消息上下文 */
319
+ context: Context;
320
+ /** 原始用户输入 */
321
+ input: string;
322
+ }
323
+ /**
324
+ * Step 结束上下文
325
+ */
326
+ interface StepFinishedContext extends StepStartContext {
327
+ /** LLM 响应 */
328
+ llmResponse: LLMResponse;
329
+ /** 执行的工具调用数量 */
330
+ toolCallsCount: number;
331
+ }
332
+ /**
333
+ * 工具上下文 - onToolUse 钩子的参数
334
+ *
335
+ * 提供工具调用时的完整上下文信息
336
+ */
337
+ interface ToolContext {
338
+ /** 工具调用 */
339
+ call: ToolCall;
340
+ /** 工具定义 */
341
+ tool: Tool;
342
+ /** 当前步骤序号 */
343
+ step: number;
344
+ /** 用户输入 */
345
+ input: string;
346
+ /** 消息上下文(可读写) */
347
+ context: Context;
348
+ }
349
+ /**
350
+ * 工具结果 - onToolFinished 钩子的参数
351
+ *
352
+ * 提供工具执行后的完整结果信息
353
+ */
354
+ interface ToolResult {
355
+ /** 是否成功 */
356
+ success: boolean;
357
+ /** 返回数据 */
358
+ data: unknown;
359
+ /** 错误信息(如果失败) */
360
+ error?: string;
361
+ /** 执行耗时(ms) */
362
+ duration: number;
363
+ /** 工具调用 */
364
+ call: ToolCall;
365
+ /** 工具定义 */
366
+ tool: Tool;
367
+ /** 当前步骤序号 */
368
+ step: number;
369
+ /** 用户输入 */
370
+ input: string;
371
+ /** 消息上下文 */
372
+ context: Context;
373
+ }
374
+ /**
375
+ * 钩子返回值类型(扩展版)
376
+ *
377
+ * 统一的生命周期钩子控制流指令
378
+ *
379
+ * - { action: 'block' }: 阻止工具执行(工具级)
380
+ * - { action: 'allow' }: 允许工具执行(工具级)
381
+ * - undefined: 默认行为
382
+ */
383
+ type HookResult = {
384
+ action: 'block';
385
+ reason?: string;
386
+ } | {
387
+ action: 'allow';
388
+ } | undefined;
389
+ /**
390
+ * 子代理状态
391
+ */
392
+ type SubAgentStatus = 'idle' | 'busy' | 'completed' | 'failed' | 'terminated';
393
+ /**
394
+ * 子代理创建上下文
395
+ */
396
+ interface SubAgentSpawnContext {
397
+ /** 子代理 ID */
398
+ agentId: string;
399
+ /** 子代理类型 */
400
+ type: string;
401
+ /** 初始指令 */
402
+ instruction: string;
403
+ /** 子代理实例 */
404
+ agent: AgentBase;
405
+ }
406
+ /**
407
+ * 子代理状态更新上下文
408
+ */
409
+ interface SubAgentUpdateContext {
410
+ /** 子代理 ID */
411
+ agentId: string;
412
+ /** 子代理类型 */
413
+ type: string;
414
+ /** 旧状态 */
415
+ oldStatus: SubAgentStatus;
416
+ /** 新状态 */
417
+ newStatus: SubAgentStatus;
418
+ /** 执行结果(完成时) */
419
+ result?: string;
420
+ /** 错误信息(失败时) */
421
+ error?: string;
422
+ }
423
+ /**
424
+ * 子代理销毁上下文
425
+ */
426
+ interface SubAgentDestroyContext {
427
+ /** 子代理 ID */
428
+ agentId: string;
429
+ /** 子代理类型 */
430
+ type: string;
431
+ /** 销毁原因 */
432
+ reason: 'manual' | 'parent_dispose' | 'error';
433
+ }
434
+ /**
435
+ * Agent 中断上下文
436
+ */
437
+ interface AgentInterruptContext {
438
+ /** 中断原因 */
439
+ reason: 'max_steps_reached' | 'error' | 'cancelled';
440
+ /** 当前步骤序号 */
441
+ step: number;
442
+ /** 当前消息上下文 */
443
+ context: Context;
444
+ }
445
+ /**
446
+ * 子代理中断上下文
447
+ */
448
+ interface SubAgentInterruptContext {
449
+ /** 子代理 ID */
450
+ agentId: string;
451
+ /** 子代理类型 */
452
+ type: string;
453
+ /** 中断原因 */
454
+ reason: 'max_steps_reached' | 'error' | 'cancelled';
455
+ /** 中断时的结果 */
456
+ result: string;
457
+ }
458
+ /**
459
+ * Step 结束决策上下文(反向钩子)
460
+ *
461
+ * 用于在 Step 结束后进行流程控制决策
462
+ */
463
+ interface StepFinishDecisionContext extends StepFinishedContext {
464
+ /** 是否有活跃的子代理(busy 状态) */
465
+ hasActiveSubAgents?: boolean;
466
+ /** 是否有待处理的子代理消息 */
467
+ hasPendingMessages?: boolean;
468
+ /** 是否调用了 wait 工具 */
469
+ waitCalled?: boolean;
470
+ }
471
+ /**
472
+ * 工具完成决策上下文(反向钩子)
473
+ *
474
+ * 用于在工具执行完成后进行流程控制决策
475
+ */
476
+ interface ToolFinishedDecisionContext extends ToolResult {
477
+ /** 刚才执行的工具名称 */
478
+ toolName: string;
479
+ }
480
+
481
+ /**
482
+ * 模板加载器
483
+ * 从文件系统读取和缓存模板文件
484
+ */
485
+
486
+ /**
487
+ * 模板加载器
488
+ */
489
+ declare class TemplateLoader {
490
+ private cache;
491
+ private searchDirs;
492
+ private enabled;
493
+ private stats;
494
+ constructor(options?: TemplateLoaderOptions);
495
+ /**
496
+ * 加载模板(异步)
497
+ */
498
+ load(templatePath: string): Promise<string>;
499
+ /**
500
+ * 加载模板(同步)
501
+ */
502
+ loadSync(templatePath: string): string;
503
+ /**
504
+ * 解析路径为绝对路径
505
+ * @param templatePath 模板路径
506
+ * @returns 解析后的绝对路径
507
+ * @throws TemplateError 如果文件格式不支持
508
+ */
509
+ resolvePath(templatePath: string): string;
510
+ /**
511
+ * 清除缓存
512
+ */
513
+ clearCache(pattern?: string): void;
514
+ /**
515
+ * 批量加载
516
+ */
517
+ loadMultiple(paths: string[]): Promise<Map<string, string>>;
518
+ /**
519
+ * 获取缓存统计
520
+ */
521
+ getStats(): CacheStats;
522
+ /**
523
+ * 检查是否是绝对路径
524
+ */
525
+ private isAbsolute;
526
+ /**
527
+ * 简单检查文件是否存在(同步,不进行实际IO)
528
+ */
529
+ private fileExists;
530
+ }
531
+
532
+ /**
533
+ * 模板组合器
534
+ * 支持流式 API 和灵活拼接
535
+ */
536
+
537
+ /**
538
+ * 模板组合器
539
+ */
540
+ declare class TemplateComposer {
541
+ private parts;
542
+ private separator;
543
+ private loader;
544
+ constructor(loader?: TemplateLoader);
545
+ /**
546
+ * 添加模板源
547
+ */
548
+ add(source: TemplateSource | TemplateComposer): this;
549
+ /**
550
+ * 添加模板源(别名)
551
+ */
552
+ append(source: TemplateSource | TemplateComposer): this;
553
+ /**
554
+ * 在头部插入
555
+ */
556
+ prepend(source: TemplateSource | TemplateComposer): this;
557
+ /**
558
+ * 添加多个模板源
559
+ */
560
+ addAll(...sources: (TemplateSource | TemplateComposer)[]): this;
561
+ /**
562
+ * 设置分隔符
563
+ */
564
+ joinWith(sep: string): this;
565
+ /**
566
+ * 条件添加
567
+ */
568
+ when(condition: boolean | ((ctx: PlaceholderContext) => boolean), source: TemplateSource | TemplateComposer): this;
569
+ /**
570
+ * 条件分支(三目运算语法糖)
571
+ */
572
+ either(condition: boolean | ((ctx: PlaceholderContext) => boolean), trueSource: TemplateSource | TemplateComposer, falseSource?: TemplateSource | TemplateComposer): this;
573
+ /**
574
+ * 嵌套子组合器
575
+ */
576
+ nest(composer: TemplateComposer): this;
577
+ /**
578
+ * 条件嵌套
579
+ */
580
+ nestIf(condition: boolean | ((ctx: PlaceholderContext) => boolean), composer: TemplateComposer): this;
581
+ /**
582
+ * 清空所有模板
583
+ */
584
+ clear(): this;
585
+ /**
586
+ * 获取当前模板数量
587
+ */
588
+ get size(): number;
589
+ /**
590
+ * 获取所有模板源
591
+ */
592
+ getSources(): TemplateSource[];
593
+ /**
594
+ * 渲染最终模板
595
+ */
596
+ render(context?: PlaceholderContext): Promise<TemplateResult>;
597
+ /**
598
+ * 渲染单个片段
599
+ */
600
+ private renderPart;
601
+ /**
602
+ * 转换为 TemplatePart
603
+ */
604
+ private toPart;
605
+ }
606
+
607
+ /**
608
+ * 提示词模板系统 - 核心类型定义
609
+ */
610
+ /**
611
+ * 模板源
612
+ * - string: 硬编码字符串
613
+ * - { file: string }: 文件路径
614
+ * - [dataSourceName: string]: 数据源名称(如 skills, tasks 等)
615
+ * - TemplateComposer: 组合模板
616
+ *
617
+ * @example
618
+ * ```typescript
619
+ * // 静态字符串
620
+ * 'Hello {{name}}'
621
+ *
622
+ * // 文件
623
+ * { file: 'prompts/system.md' }
624
+ *
625
+ * // 数据源(列表渲染)
626
+ * { skills: '- **{{name}}**: {{description}}' }
627
+ * { tasks: '- [{{title}}](#{{id}}) ({{priority}})' }
628
+ *
629
+ * // 条件渲染
630
+ * { conditional: { part: { file: 'advanced.md' }, condition: (ctx) => ctx.advanced } }
631
+ * ```
632
+ */
633
+ type TemplateSource = string | {
634
+ file: string;
635
+ } | {
636
+ conditional: ConditionalSource;
637
+ } | {
638
+ [dataSourceName: string]: string;
639
+ } | TemplateComposer;
640
+ /**
641
+ * 条件源配置
642
+ */
643
+ interface ConditionalSource {
644
+ /** 条件模板源 */
645
+ part: TemplateSource;
646
+ /** 条件函数(true 时渲染) */
647
+ condition: (context: PlaceholderContext) => boolean;
648
+ }
649
+ /**
650
+ * 占位符上下文 - 变量替换的键值对
651
+ * 支持原始类型和复杂对象(用于数据源渲染)
652
+ */
653
+ type PlaceholderContext = Record<string, string | number | boolean | undefined | object>;
654
+ /**
655
+ * 模板渲染结果
656
+ */
657
+ interface TemplateResult {
658
+ /** 渲染后的内容 */
659
+ content: string;
660
+ /** 使用的源文件列表(用于调试) */
661
+ sources: string[];
662
+ }
663
+ /**
664
+ * 模板加载器配置
665
+ */
666
+ interface TemplateLoaderOptions {
667
+ /** 缓存启用状态,默认 true */
668
+ cacheEnabled?: boolean;
669
+ /** 模板搜索目录(相对于项目根目录) */
670
+ searchDirs?: string[];
671
+ /** 项目根目录(自动检测) */
672
+ projectRoot?: string;
673
+ }
674
+ /**
675
+ * 缓存统计
676
+ */
677
+ interface CacheStats {
678
+ size: number;
679
+ hits: number;
680
+ misses: number;
681
+ hitRate: number;
682
+ }
683
+ /**
684
+ * 模板相关错误
685
+ */
686
+ declare class TemplateError extends Error {
687
+ code: 'FILE_NOT_FOUND' | 'INVALID_PATH' | 'READ_ERROR' | 'UNSUPPORTED_FORMAT';
688
+ path?: string | undefined;
689
+ constructor(message: string, code: 'FILE_NOT_FOUND' | 'INVALID_PATH' | 'READ_ERROR' | 'UNSUPPORTED_FORMAT', path?: string | undefined);
690
+ }
691
+
692
+ /**
693
+ * UsageStats - 用量统计系统
694
+ *
695
+ * 职责:
696
+ * - 记录 LLM 调用的 token 用量
697
+ * - 聚合 session/call/step 三级统计
698
+ * - 提供快照序列化和恢复
699
+ * - 格式化用量报告
700
+ *
701
+ * 设计原则:
702
+ * - 框架内置,不是 Feature
703
+ * - 自动收集,不需要手动干预
704
+ * - 快照包含 session 级数据,用于会话恢复
705
+ */
706
+ /**
707
+ * 统一用量格式(兼容 Anthropic 和 OpenAI)
708
+ */
709
+ interface UsageInfo$1 {
710
+ /** 输入 token 数 */
711
+ inputTokens: number;
712
+ /** 输出 token 数 */
713
+ outputTokens: number;
714
+ /** 总 token 数 */
715
+ totalTokens: number;
716
+ /** 创建缓存消耗的 token 数 */
717
+ cacheCreationTokens?: number;
718
+ /** 从缓存读取的 token 数 */
719
+ cacheReadTokens?: number;
720
+ /** 推理 token 数(prompt_tokens_details 或 completion_tokens_details) */
721
+ reasoningTokens?: number;
722
+ /** 音频 token 数 */
723
+ audioTokens?: number;
724
+ }
725
+ /**
726
+ * 单次 Call 用量汇总
727
+ */
728
+ interface CallUsageSummary {
729
+ callIndex: number;
730
+ totalUsage: UsageInfo$1;
731
+ stepCount: number;
732
+ cacheHitRequests: number;
733
+ startTime: number;
734
+ endTime?: number;
735
+ }
736
+ /**
737
+ * Session 用量快照(用于序列化)
738
+ */
739
+ interface UsageStatsSnapshot {
740
+ /** Session 级累计用量 */
741
+ totalUsage: UsageInfo$1;
742
+ /** 各 Call 的用量汇总 */
743
+ calls: CallUsageSummary[];
744
+ /** 总请求数(LLM 调用次数) */
745
+ totalRequests: number;
746
+ /** 命中缓存的请求数(request-level) */
747
+ totalCacheHitRequests: number;
748
+ }
749
+ /**
750
+ * 用量统计类
751
+ */
752
+ declare class UsageStats {
753
+ /** Session 级累计用量 */
754
+ private totalUsage;
755
+ /** 当前活跃 Call 的用量记录 */
756
+ private currentCallUsage;
757
+ /** 总 LLM 调用次数 */
758
+ private totalRequests;
759
+ /** 命中缓存的总请求数 */
760
+ private totalCacheHitRequests;
761
+ /** 当前 Call 的 Step 记录(临时,用于聚合) */
762
+ private currentStepRecords;
763
+ /**
764
+ * 记录一次 LLM 调用的用量
765
+ * @param callIndex Call 序号
766
+ * @param step Step 序号
767
+ * @param usage 用量数据
768
+ */
769
+ record(callIndex: number, step: number, usage: UsageInfo$1): void;
770
+ /**
771
+ * 标记 Call 结束
772
+ * @param callIndex Call 序号
773
+ */
774
+ endCall(callIndex: number): void;
775
+ /**
776
+ * 获取 Session 级累计用量
777
+ */
778
+ getTotalUsage(): UsageInfo$1;
779
+ /**
780
+ * 获取指定 Call 的用量汇总
781
+ * @param callIndex Call 序号
782
+ */
783
+ getCallUsage(callIndex: number): CallUsageSummary | undefined;
784
+ /**
785
+ * 获取所有 Call 的用量汇总
786
+ */
787
+ getAllCallUsage(): CallUsageSummary[];
788
+ /**
789
+ * 获取总请求次数
790
+ */
791
+ getTotalRequests(): number;
792
+ getTotalCacheHitRequests(): number;
793
+ /**
794
+ * 获取格式化的用量报告
795
+ */
796
+ getReport(): string;
797
+ /**
798
+ * 创建快照(用于序列化)
799
+ */
800
+ toSnapshot(): UsageStatsSnapshot;
801
+ /**
802
+ * 从快照恢复
803
+ */
804
+ fromSnapshot(snapshot: UsageStatsSnapshot): void;
805
+ /**
806
+ * 重置统计(谨慎使用)
807
+ */
808
+ reset(): void;
809
+ }
810
+
811
+ /**
812
+ * 基础类型定义
813
+ * 所有类型集中在这里,简单直观
814
+ */
815
+ /**
816
+ * 通知分类
817
+ * - state: 覆盖式更新(如 LLM 字符计数)
818
+ * - event: 追加式记录(如工具开始/完成)
819
+ */
820
+ type NotificationCategory = 'state' | 'event';
821
+ /**
822
+ * 通知基础接口
823
+ */
824
+ interface Notification {
825
+ type: string;
826
+ category: NotificationCategory;
827
+ timestamp: number;
828
+ data: unknown;
829
+ }
830
+ type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
831
+ type DebugLogDeliveryReason = 'hub' | 'hub-unavailable' | 'no-agent-context';
832
+ interface DebugLogDelivery {
833
+ hub: boolean;
834
+ console: boolean;
835
+ reason: DebugLogDeliveryReason;
836
+ }
837
+ interface LogContextRef {
838
+ agentId?: string;
839
+ agentName?: string;
840
+ parentAgentId?: string;
841
+ callIndex?: number;
842
+ step?: number;
843
+ toolName?: string;
844
+ toolCallId?: string;
845
+ feature?: string;
846
+ lifecycle?: string;
847
+ hookMethod?: string;
848
+ hookKind?: 'forward' | 'reverse';
849
+ sourceFile?: string;
850
+ sourceLine?: number;
851
+ tags?: string[];
852
+ [key: string]: unknown;
853
+ }
854
+ interface DebugLogEntry {
855
+ id: string;
856
+ timestamp: number;
857
+ level: LogLevel;
858
+ message: string;
859
+ namespace: string;
860
+ context: LogContextRef;
861
+ data?: unknown;
862
+ delivery: DebugLogDelivery;
863
+ }
864
+ type MessageRole = 'system' | 'user' | 'assistant' | 'tool' | string;
865
+ interface Message {
866
+ role: MessageRole;
867
+ content: string;
868
+ turn?: number;
869
+ toolCallId?: string;
870
+ toolCalls?: ToolCall[];
871
+ reasoning?: string;
872
+ thinkingBlocks?: ThinkingBlock[];
873
+ }
874
+ interface ThinkingBlock {
875
+ signature: string;
876
+ thinking: string;
877
+ }
878
+ interface ToolCall {
879
+ id: string;
880
+ name: string;
881
+ arguments: Record<string, any>;
882
+ }
883
+ /**
884
+ * 统一用量格式(兼容 Anthropic 和 OpenAI)
885
+ */
886
+ interface UsageInfo {
887
+ /** 输入 token 数 */
888
+ inputTokens: number;
889
+ /** 输出 token 数 */
890
+ outputTokens: number;
891
+ /** 总 token 数 */
892
+ totalTokens: number;
893
+ /** 创建缓存消耗的 token 数 */
894
+ cacheCreationTokens?: number;
895
+ /** 从缓存读取的 token 数 */
896
+ cacheReadTokens?: number;
897
+ /** 推理 token 数 */
898
+ reasoningTokens?: number;
899
+ /** 音频 token 数 */
900
+ audioTokens?: number;
901
+ }
902
+ interface LLMResponse {
903
+ content: string;
904
+ toolCalls?: ToolCall[];
905
+ reasoning?: string;
906
+ thinkingBlocks?: ThinkingBlock[];
907
+ /** 用量统计(可选) */
908
+ usage?: UsageInfo;
909
+ }
910
+ /**
911
+ * 渲染模板项
912
+ * 可以是字符串模板或函数模板
913
+ */
914
+ type RenderTemplateItem = string | RenderTemplateFn;
915
+ /**
916
+ * 渲染模板函数类型
917
+ */
918
+ type RenderTemplateFn = (data: Record<string, any>, success?: boolean) => string;
919
+ /**
920
+ * 内联渲染模板
921
+ * 直接定义在工具中的渲染模板(无需引用预设模板)
922
+ */
923
+ interface InlineRenderTemplate {
924
+ call: RenderTemplateItem;
925
+ result: RenderTemplateItem;
926
+ }
927
+ interface ToolRenderConfig {
928
+ /** 调用时的渲染模板(字符串引用或内联模板) */
929
+ call?: string | InlineRenderTemplate;
930
+ /** 结果时的渲染模板(字符串引用或内联模板) */
931
+ result?: string | InlineRenderTemplate;
932
+ }
933
+ interface Tool {
934
+ name: string;
935
+ description: string;
936
+ parameters?: Record<string, any>;
937
+ execute: (args: any, context?: any) => Promise<any>;
938
+ /** 可选:渲染配置 */
939
+ render?: ToolRenderConfig;
940
+ }
941
+ interface LLMClient {
942
+ chat(messages: Message[], tools: Tool[]): Promise<LLMResponse>;
943
+ }
944
+
945
+ interface AgentConfig {
946
+ llm: LLMClient;
947
+ tools?: Tool[];
948
+ maxTurns?: number;
949
+ systemMessage?: string | TemplateSource;
950
+ name?: string;
951
+ /**
952
+ * Feature 配置
953
+ *
954
+ * 新的声明式 Feature 注册方式
955
+ */
956
+ features?: {
957
+ /** 启用的 Feature 列表 */
958
+ enabled?: string[];
959
+ /** Feature 特定配置 */
960
+ [key: string]: unknown;
961
+ };
962
+ }
963
+ type ContextMiddleware = (messages: Message[]) => Message[];
964
+ /**
965
+ * Agent 注册信息(Hub 端)
966
+ */
967
+ interface AgentInfo {
968
+ id: string;
969
+ name: string;
970
+ registeredAt: number;
971
+ }
972
+ /**
973
+ * 工具元数据(用于前端渲染)
974
+ */
975
+ interface ToolMetadata {
976
+ name: string;
977
+ description: string;
978
+ render: {
979
+ call: string | InlineRenderTemplate;
980
+ result: string | InlineRenderTemplate;
981
+ inlineCall?: InlineRenderTemplate;
982
+ inlineResult?: InlineRenderTemplate;
983
+ };
984
+ }
985
+ interface HookSourceLocation {
986
+ file?: string;
987
+ line?: number;
988
+ column?: number;
989
+ display: string;
990
+ }
991
+ interface HookEntryMetadata {
992
+ order: number;
993
+ featureName: string;
994
+ methodName: string;
995
+ lifecycle: string;
996
+ kind: 'decision' | 'notify';
997
+ source?: HookSourceLocation;
998
+ description?: string;
999
+ }
1000
+ interface HookLifecycleSnapshot {
1001
+ lifecycle: string;
1002
+ kind: 'decision' | 'notify';
1003
+ entries: HookEntryMetadata[];
1004
+ }
1005
+ interface FeatureInspectorSnapshot {
1006
+ name: string;
1007
+ enabled: boolean;
1008
+ status: 'enabled' | 'disabled' | 'partial';
1009
+ hookCount: number;
1010
+ toolCount: number;
1011
+ enabledToolCount: number;
1012
+ source?: string;
1013
+ description?: string;
1014
+ tools: Array<{
1015
+ name: string;
1016
+ description: string;
1017
+ enabled: boolean;
1018
+ renderCall?: string;
1019
+ renderResult?: string;
1020
+ }>;
1021
+ }
1022
+ interface HookInspectorSnapshot {
1023
+ lifecycleOrder: string[];
1024
+ features: FeatureInspectorSnapshot[];
1025
+ hooks: HookLifecycleSnapshot[];
1026
+ }
1027
+ interface AgentContextMetrics {
1028
+ messageCount: number;
1029
+ charCount: number;
1030
+ toolCallCount: number;
1031
+ turnCount: number;
1032
+ }
1033
+ interface AgentOverviewSnapshot {
1034
+ updatedAt: number;
1035
+ context: AgentContextMetrics;
1036
+ usageStats: UsageStatsSnapshot;
1037
+ }
1038
+ /**
1039
+ * Agent 会话数据(Worker 端)
1040
+ */
1041
+ interface AgentSession {
1042
+ id: string;
1043
+ name: string;
1044
+ messages: Message[];
1045
+ tools: ToolMetadata[];
1046
+ createdAt: number;
1047
+ lastActive: number;
1048
+ projectRoot?: string;
1049
+ currentState: Notification | null;
1050
+ events: Notification[];
1051
+ lastEventCount: number;
1052
+ logs: DebugLogEntry[];
1053
+ clientId?: string;
1054
+ _lastMessageSig?: string;
1055
+ hookInspector?: HookInspectorSnapshot;
1056
+ overview?: AgentOverviewSnapshot;
1057
+ }
1058
+ /**
1059
+ * DebugHub IPC 消息类型(主进程 → Worker)
1060
+ * 使用 discriminated union 确保类型安全
1061
+ */
1062
+ type DebugHubIPCMessage = RegisterAgentMsg | UpdateAgentInspectorMsg | UpdateAgentOverviewMsg | PushMessagesMsg | RegisterToolsMsg | SetCurrentAgentMsg | UnregisterAgentMsg | PushNotificationMsg | RequestInputMsg | StopMsg;
1063
+ /**
1064
+ * 注册新 Agent
1065
+ */
1066
+ interface RegisterAgentMsg {
1067
+ type: 'register-agent';
1068
+ agentId: string;
1069
+ name: string;
1070
+ createdAt: number;
1071
+ projectRoot?: string;
1072
+ featureTemplates?: Record<string, string>;
1073
+ hookInspector?: HookInspectorSnapshot;
1074
+ overview?: AgentOverviewSnapshot;
1075
+ activeInputRequest?: ActiveInputRequest;
1076
+ }
1077
+ interface UpdateAgentInspectorMsg {
1078
+ type: 'update-agent-inspector';
1079
+ agentId: string;
1080
+ hookInspector: HookInspectorSnapshot;
1081
+ }
1082
+ interface UpdateAgentOverviewMsg {
1083
+ type: 'update-agent-overview';
1084
+ agentId: string;
1085
+ overview: AgentOverviewSnapshot;
1086
+ }
1087
+ /**
1088
+ * 推送 Agent 消息
1089
+ */
1090
+ interface PushMessagesMsg {
1091
+ type: 'push-messages';
1092
+ agentId: string;
1093
+ messages: Message[];
1094
+ }
1095
+ /**
1096
+ * 注册 Agent 工具
1097
+ */
1098
+ interface RegisterToolsMsg {
1099
+ type: 'register-tools';
1100
+ agentId: string;
1101
+ tools: Tool[];
1102
+ }
1103
+ /**
1104
+ * 切换当前选中的 Agent
1105
+ */
1106
+ interface SetCurrentAgentMsg {
1107
+ type: 'set-current-agent';
1108
+ agentId: string;
1109
+ }
1110
+ /**
1111
+ * 活跃的输入请求(用于重连后恢复)
1112
+ */
1113
+ interface ActiveInputRequest {
1114
+ requestId: string;
1115
+ prompt: string;
1116
+ placeholder?: string;
1117
+ initialValue?: string;
1118
+ actions?: UserInputAction[];
1119
+ timestamp: number;
1120
+ }
1121
+ /**
1122
+ * 注销 Agent
1123
+ */
1124
+ interface UnregisterAgentMsg {
1125
+ type: 'unregister-agent';
1126
+ agentId: string;
1127
+ }
1128
+ /**
1129
+ * 停止 Worker
1130
+ */
1131
+ interface StopMsg {
1132
+ type: 'stop';
1133
+ }
1134
+ /**
1135
+ * 推送通知
1136
+ */
1137
+ interface PushNotificationMsg {
1138
+ type: 'push-notification';
1139
+ agentId: string;
1140
+ notification: Notification;
1141
+ }
1142
+ /**
1143
+ * 请求用户输入
1144
+ */
1145
+ interface RequestInputMsg {
1146
+ type: 'request-input';
1147
+ agentId: string;
1148
+ requestId: string;
1149
+ prompt: string;
1150
+ timeout?: number;
1151
+ placeholder?: string;
1152
+ initialValue?: string;
1153
+ actions?: UserInputAction[];
1154
+ }
1155
+ interface UserInputAction {
1156
+ id: string;
1157
+ label: string;
1158
+ kind?: 'rollback' | 'custom';
1159
+ variant?: 'primary' | 'secondary' | 'danger';
1160
+ payload?: Record<string, unknown>;
1161
+ }
1162
+ interface UserInputRequest {
1163
+ prompt: string;
1164
+ placeholder?: string;
1165
+ initialValue?: string;
1166
+ actions?: UserInputAction[];
1167
+ }
1168
+ interface UserInputResponse {
1169
+ kind: 'text' | 'action';
1170
+ text?: string;
1171
+ actionId?: string;
1172
+ payload?: Record<string, unknown>;
1173
+ }
1174
+ /**
1175
+ * 消息标签枚举
1176
+ *
1177
+ * 用于快速分类和过滤消息,一条消息可能有多个标签
1178
+ */
1179
+ type MessageTag = 'user' | 'system' | 'assistant' | 'tool-call' | 'tool-result' | 'sub-agent' | 'reminder';
1180
+ /**
1181
+ * 解析结果结构
1182
+ *
1183
+ * 从消息 content 中提取的结构化信息
1184
+ */
1185
+ interface ParsedContent {
1186
+ /** 从 content 提取的任务 ID(正则匹配 "taskId":"xxx") */
1187
+ taskIds: string[];
1188
+ /** 从 content 提取的工具调用名称(从 toolCalls 或 content 解析) */
1189
+ toolCalls: string[];
1190
+ /** @ 提及的内容 */
1191
+ mentions: string[];
1192
+ /** 用户可继承扩展更多字段 */
1193
+ [key: string]: any;
1194
+ }
1195
+ /**
1196
+ * 扩展的消息结构
1197
+ *
1198
+ * 在原始 Message 基础上添加元数据
1199
+ * 不破坏现有 Message 类型,保证 LLM 调用兼容性
1200
+ */
1201
+ interface EnrichedMessage extends Message {
1202
+ /** 唯一标识(用于索引关联) */
1203
+ id: string;
1204
+ /** 消息产生时间戳(毫秒) */
1205
+ timestamp: number;
1206
+ /** 所属 ReAct 循环轮次(从 0 开始) */
1207
+ turn: number;
1208
+ /** 全局消息序号(从 0 开始递增) */
1209
+ sequence: number;
1210
+ /** 来源 Agent ID(子代理消息) */
1211
+ agentId?: string;
1212
+ /** 来源 Feature(如 'todo-feature',仅 reminder 等) */
1213
+ source?: string;
1214
+ /** 消息分类标签(用于快速查询) */
1215
+ tags: MessageTag[];
1216
+ /** 从 content 中提取的结构化信息 */
1217
+ parsed: ParsedContent;
1218
+ }
1219
+
1220
+ /**
1221
+ * 平台检测后的 UDS 路径
1222
+ */
1223
+ declare function getDefaultUDSPath(): string;
1224
+
1225
+ interface LoggerBindings extends LogContextRef {
1226
+ tags?: string[];
1227
+ }
1228
+ interface Logger {
1229
+ trace(message: string, data?: unknown): void;
1230
+ debug(message: string, data?: unknown): void;
1231
+ info(message: string, data?: unknown): void;
1232
+ warn(message: string, data?: unknown): void;
1233
+ error(message: string, data?: unknown): void;
1234
+ child(options?: LoggerBindings & {
1235
+ namespace?: string;
1236
+ }): Logger;
1237
+ }
1238
+
1239
+ /**
1240
+ * Feature 上下文值类型
1241
+ */
1242
+ type ToolContextValue = Record<string, unknown>;
1243
+ /**
1244
+ * Feature 上下文注入器
1245
+ * 返回要注入到 tool.execute() 的额外参数
1246
+ */
1247
+ type ContextInjector = (call: ToolCall) => ToolContextValue;
1248
+ /**
1249
+ * Feature 运行时上下文
1250
+ */
1251
+ interface FeatureContext {
1252
+ agentId: string;
1253
+ config: AgentConfig;
1254
+ }
1255
+ /**
1256
+ * Feature 快照状态
1257
+ *
1258
+ * 第一阶段只支持显式白名单状态:
1259
+ * - Feature 自己决定要保存什么
1260
+ * - 未声明的状态一律不保证恢复
1261
+ */
1262
+ type FeatureStateSnapshot = unknown;
1263
+ /**
1264
+ * 包信息
1265
+ */
1266
+ interface PackageInfo {
1267
+ /** 包名,如 '@agentdev/shell-feature' 或 'agentdev' */
1268
+ name: string;
1269
+ /** 版本号(可选) */
1270
+ version?: string;
1271
+ /** 包根目录绝对路径 */
1272
+ root: string;
1273
+ }
1274
+ /**
1275
+ * Feature 初始化上下文
1276
+ */
1277
+ interface FeatureInitContext {
1278
+ /** Agent ID */
1279
+ agentId: string;
1280
+ /** Agent 配置 */
1281
+ config: AgentConfig;
1282
+ /** Feature 级结构化日志 */
1283
+ logger: Logger;
1284
+ /** Feature 特定配置 */
1285
+ featureConfig?: unknown;
1286
+ /** 获取其他 Feature */
1287
+ getFeature<T extends AgentFeature>(name: string): T | undefined;
1288
+ /** 注册工具 */
1289
+ registerTool(tool: Tool): void;
1290
+ }
1291
+ /**
1292
+ * Feature 初始化上下文
1293
+ */
1294
+ interface FeatureInitContext {
1295
+ /** Agent ID */
1296
+ agentId: string;
1297
+ /** Agent 配置 */
1298
+ config: AgentConfig;
1299
+ /** Feature 级结构化日志 */
1300
+ logger: Logger;
1301
+ /** Feature 特定配置 */
1302
+ featureConfig?: unknown;
1303
+ /** 获取其他 Feature */
1304
+ getFeature<T extends AgentFeature>(name: string): T | undefined;
1305
+ /** 注册工具 */
1306
+ registerTool(tool: Tool): void;
1307
+ }
1308
+ /**
1309
+ * Agent Feature 接口
1310
+ *
1311
+ * 可外挂的功能模块,提供工具和上下文注入
1312
+ */
1313
+ interface AgentFeature {
1314
+ /** Feature 名称 */
1315
+ readonly name: string;
1316
+ /** 依赖的其他 Feature */
1317
+ readonly dependencies?: string[];
1318
+ /** 可选:用于调试器展示的源码位置 */
1319
+ readonly source?: string;
1320
+ /** 可选:用于调试器展示的 Feature 描述 */
1321
+ readonly description?: string;
1322
+ /**
1323
+ * 获取同步工具(已知工具列表)
1324
+ */
1325
+ getTools?(): Tool[];
1326
+ /**
1327
+ * 获取异步工具(需要连接、发现等)
1328
+ */
1329
+ getAsyncTools?(ctx: FeatureInitContext): Promise<Tool[]>;
1330
+ /**
1331
+ * 获取包信息
1332
+ *
1333
+ * 返回 Feature 所在的包信息(包名、版本、根目录)
1334
+ * 用于统一模板路径解析和包管理
1335
+ *
1336
+ * @returns 包信息,如果 Feature 不属于任何包则返回 null
1337
+ *
1338
+ * @example
1339
+ * ```typescript
1340
+ * getPackageInfo(): PackageInfo | null {
1341
+ * return {
1342
+ * name: '@agentdev/shell-feature',
1343
+ * version: '1.0.0',
1344
+ * root: '/path/to/package/root'
1345
+ * };
1346
+ * }
1347
+ * ```
1348
+ */
1349
+ getPackageInfo?(): PackageInfo | null;
1350
+ /**
1351
+ * 获取模板名称列表
1352
+ *
1353
+ * 返回 Feature 提供的模板名称列表(不含扩展名)
1354
+ * 模板文件必须位于 {packageRoot}/dist/templates/{templateName}.render.js
1355
+ *
1356
+ * @returns 模板名称数组
1357
+ *
1358
+ * @example
1359
+ * ```typescript
1360
+ * getTemplateNames(): string[] {
1361
+ * return ['bash', 'trash-delete', 'trash-list'];
1362
+ * }
1363
+ * ```
1364
+ */
1365
+ getTemplateNames?(): string[];
1366
+ /**
1367
+ * 声明渲染模板(推荐方式)
1368
+ * 直接返回模板对象,无需文件路径
1369
+ *
1370
+ * @example
1371
+ * ```typescript
1372
+ * getRenderTemplates(): Record<string, InlineRenderTemplate> {
1373
+ * return {
1374
+ * 'bash': {
1375
+ * call: (args) => `<div class="bash-command">> ${escapeHtml(args.command)}</div>`,
1376
+ * result: (data, success) => success
1377
+ * ? `<pre class="bash-output">${escapeHtml(data)}</pre>`
1378
+ * : `<div class="tool-error">${escapeHtml(data)}</div>`
1379
+ * }
1380
+ * };
1381
+ * }
1382
+ * ```
1383
+ */
1384
+ getRenderTemplates?(): Record<string, InlineRenderTemplate>;
1385
+ /**
1386
+ * 声明上下文注入器
1387
+ */
1388
+ getContextInjectors?(): Map<string | RegExp, ContextInjector>;
1389
+ /**
1390
+ * 初始化钩子
1391
+ */
1392
+ onInitiate?(ctx: FeatureInitContext): Promise<void>;
1393
+ /**
1394
+ * 清理钩子
1395
+ */
1396
+ onDestroy?(ctx: FeatureContext): Promise<void>;
1397
+ /**
1398
+ * 捕获可回滚的 Feature 状态
1399
+ *
1400
+ * 仅返回显式声明、可序列化的状态。
1401
+ * 未返回的字段不会参与 rollback。
1402
+ */
1403
+ captureState?(): FeatureStateSnapshot;
1404
+ /**
1405
+ * 从快照恢复 Feature 状态
1406
+ */
1407
+ restoreState?(snapshot: FeatureStateSnapshot): void | Promise<void>;
1408
+ /**
1409
+ * rollback 前钩子
1410
+ */
1411
+ beforeRollback?(snapshot: FeatureStateSnapshot): void | Promise<void>;
1412
+ /**
1413
+ * rollback 后钩子
1414
+ */
1415
+ afterRollback?(snapshot: FeatureStateSnapshot): void | Promise<void>;
1416
+ /**
1417
+ * 可选:为调试器提供 hook 的人类可读说明
1418
+ */
1419
+ getHookDescription?(lifecycle: string, methodName: string): string | undefined;
1420
+ }
1421
+ /**
1422
+ * 从 Feature 的 source 属性获取包信息
1423
+ *
1424
+ * 通过向上查找 package.json 文件来确定包信息
1425
+ * 支持三种场景:
1426
+ * 1. 框架内置 Feature:找到 AgentDev 的 package.json
1427
+ * 2. 外部 npm 包:找到包的 package.json
1428
+ * 3. 用户本地 Feature:找到用户项目的 package.json
1429
+ *
1430
+ * @param source Feature 的源文件路径(import.meta.url)
1431
+ * @returns 包信息,如果找不到 package.json 则返回 null
1432
+ */
1433
+ declare function getPackageInfoFromSource(source: string | undefined): PackageInfo | null;
1434
+
1435
+ /**
1436
+ * 工具定义
1437
+ * 简单的工具创建函数
1438
+ */
1439
+
1440
+ /**
1441
+ * 渲染配置扩展类型
1442
+ * 支持字符串(模板名称)或配置对象
1443
+ */
1444
+ type ToolRenderInput = ToolRenderConfig | string;
1445
+ /**
1446
+ * 创建一个工具
1447
+ * @param config 工具配置
1448
+ * @param sourceFile 可选:调用此函数的源文件路径(用于自动查找渲染文件)
1449
+ */
1450
+ declare function createTool(config: {
1451
+ name: string;
1452
+ description: string;
1453
+ parameters?: Record<string, any>;
1454
+ execute: (args: any, context?: any) => Promise<any>;
1455
+ render?: ToolRenderInput;
1456
+ }, sourceFile?: string): Tool;
1457
+ /**
1458
+ * 工具注册表 - 管理多个工具
1459
+ */
1460
+ declare class ToolRegistry {
1461
+ private tools;
1462
+ private enabled;
1463
+ private pendingDisabled;
1464
+ private sources;
1465
+ /**
1466
+ * 注册工具(默认启用,记录来源)
1467
+ */
1468
+ register(tool: Tool, source?: string): this;
1469
+ /**
1470
+ * 禁用工具
1471
+ */
1472
+ disable(name: string): boolean;
1473
+ /**
1474
+ * 启用工具
1475
+ */
1476
+ enable(name: string): boolean;
1477
+ /**
1478
+ * 检查工具是否启用
1479
+ */
1480
+ isEnabled(name: string): boolean;
1481
+ /**
1482
+ * 获取工具来源(调试用)
1483
+ */
1484
+ getSource(name: string): string | undefined;
1485
+ /**
1486
+ * 获取工具条目(调试快照用)
1487
+ */
1488
+ getEntries(): Array<{
1489
+ tool: Tool;
1490
+ enabled: boolean;
1491
+ source?: string;
1492
+ }>;
1493
+ /**
1494
+ * 获取工具
1495
+ */
1496
+ get(name: string): Tool | undefined;
1497
+ /**
1498
+ * 获取所有工具(只返回启用的)
1499
+ */
1500
+ getAll(): Tool[];
1501
+ /**
1502
+ * 检查工具是否存在
1503
+ */
1504
+ has(name: string): boolean;
1505
+ /**
1506
+ * 获取工具的渲染配置
1507
+ */
1508
+ getRenderConfig(name: string): ToolRenderConfig | undefined;
1509
+ }
1510
+
1511
+ type DebugTransportMode = 'viewer-worker' | 'claw';
1512
+ declare function resolveDebugTransportMode(): DebugTransportMode;
1513
+ declare function getClawRuntimeUrl(): string;
1514
+
1515
+ interface DebugCapabilities {
1516
+ transportMode: DebugTransportMode;
1517
+ interactiveInput: boolean;
1518
+ runtimeUrl: string | null;
1519
+ viewerCompatibleApi: boolean;
1520
+ debuggerMcpMetadata: boolean;
1521
+ }
1522
+ declare function getDebugCapabilities(): DebugCapabilities;
1523
+
1524
+ /**
1525
+ * DebugHub - 全局多 Agent 调试中心
1526
+ *
1527
+ * 职责:
1528
+ * - 管理所有 Agent 的注册和注销
1529
+ * - 连接到独立的 Viewer Worker UDS 服务器
1530
+ * - 路由 Agent 消息到 Worker
1531
+ *
1532
+ * 设计原则:
1533
+ * - 单例模式,全局唯一
1534
+ * - 轻量:只做路由,不存储消息
1535
+ * - 直观:API 简单明了
1536
+ */
1537
+
1538
+ type Agent = any;
1539
+ declare class DebugHub {
1540
+ private static instance;
1541
+ private readonly transportMode;
1542
+ private readonly clawClient?;
1543
+ private agents;
1544
+ private currentAgentId;
1545
+ private nextId;
1546
+ private readonly processId;
1547
+ private pendingInputRequests;
1548
+ private activeInputRequests;
1549
+ private udsClient?;
1550
+ private udsPath;
1551
+ private workerPort;
1552
+ private clientReady;
1553
+ private registrationLock;
1554
+ private messageQueue;
1555
+ private reconnectTimer?;
1556
+ private reconnectAttempts;
1557
+ private readonly MAX_RECONNECT_ATTEMPTS;
1558
+ private readonly RECONNECT_DELAY;
1559
+ private agentFeatureTemplates;
1560
+ private constructor();
1561
+ static getInstance(): DebugHub;
1562
+ /**
1563
+ * 启动调试服务器
1564
+ * @param port HTTP 端口(默认 2026,仅用于显示)
1565
+ * @param openBrowser 是否自动打开浏览器(默认 true,已废弃参数)
1566
+ */
1567
+ start(port?: number, openBrowser?: boolean): Promise<void>;
1568
+ /**
1569
+ * 自动启动 ViewerWorker 进程
1570
+ */
1571
+ private openBrowser;
1572
+ private viewerWorkerProcess?;
1573
+ private spawnViewerWorker;
1574
+ /**
1575
+ * 停止调试服务器
1576
+ */
1577
+ stop(): void;
1578
+ /**
1579
+ * 手动重连(可选)
1580
+ * 如果已经连接,则不执行任何操作
1581
+ */
1582
+ reconnect(): Promise<void>;
1583
+ /**
1584
+ * 注册 Agent
1585
+ * @param agent Agent 实例
1586
+ * @param name 显示名称(可选,默认使用类名)
1587
+ * @param featureTemplates Feature 模板路径映射(可选)
1588
+ * @returns 分配的 agentId
1589
+ */
1590
+ registerAgent(agent: Agent, name?: string, featureTemplates?: Record<string, string>, hookInspector?: HookInspectorSnapshot, overview?: AgentOverviewSnapshot): string;
1591
+ /**
1592
+ * 注销 Agent
1593
+ * @param agentId Agent ID
1594
+ */
1595
+ unregisterAgent(agentId: string): void;
1596
+ /**
1597
+ * 切换当前选中的 Agent
1598
+ * @param agentId Agent ID
1599
+ * @returns 是否成功
1600
+ */
1601
+ selectAgent(agentId: string): boolean;
1602
+ /**
1603
+ * 推送 Agent 消息
1604
+ * @param agentId Agent ID
1605
+ * @param messages 消息数组
1606
+ */
1607
+ pushMessages(agentId: string, messages: Message[]): void;
1608
+ /**
1609
+ * 注册 Agent 工具
1610
+ * @param agentId Agent ID
1611
+ * @param tools 工具数组
1612
+ */
1613
+ registerAgentTools(agentId: string, tools: Tool[]): void;
1614
+ updateAgentInspector(agentId: string, hookInspector: HookInspectorSnapshot): void;
1615
+ updateAgentOverview(agentId: string, overview: AgentOverviewSnapshot): void;
1616
+ /**
1617
+ * 获取所有已注册的 Agent 信息
1618
+ */
1619
+ getAgentList(): AgentInfo[];
1620
+ /**
1621
+ * 获取当前选中的 Agent ID
1622
+ */
1623
+ getCurrentAgentId(): string | null;
1624
+ getTransportMode(): 'viewer-worker' | 'claw';
1625
+ getCapabilities(): DebugCapabilities;
1626
+ /**
1627
+ * 根据 Agent 实例获取其 ID
1628
+ */
1629
+ getAgentId(agent: Agent): string | undefined;
1630
+ /**
1631
+ * 获取 Worker 端口
1632
+ */
1633
+ getPort(): number | null;
1634
+ /**
1635
+ * 检查是否已连接到 ViewerWorker
1636
+ */
1637
+ isConnected(): boolean;
1638
+ /**
1639
+ * 推送通知
1640
+ * @param agentId Agent ID
1641
+ * @param notification 通知对象
1642
+ */
1643
+ pushNotification(agentId: string, notification: Notification): void;
1644
+ /**
1645
+ * 请求用户输入
1646
+ * @param agentId Agent ID
1647
+ * @param prompt 提示信息
1648
+ * @param timeout 超时时间(毫秒),默认 Infinity(无限等待)
1649
+ * @returns Promise<string> 用户输入内容
1650
+ */
1651
+ requestUserInput(agentId: string, prompt: string, timeout?: number): Promise<string>;
1652
+ requestUserInputEvent(agentId: string, request: UserInputRequest, timeout?: number): Promise<UserInputResponse>;
1653
+ /**
1654
+ * 连接到 UDS 服务器
1655
+ */
1656
+ private connectToWorker;
1657
+ /**
1658
+ * 处理来自 Worker 的消息
1659
+ */
1660
+ private handleWorkerMessage;
1661
+ /**
1662
+ * 重新注册所有 Agent(重连后调用)
1663
+ * 确保 ViewerWorker 能够恢复所有 Agent 的注册信息
1664
+ */
1665
+ private reregisterAllAgents;
1666
+ /**
1667
+ * 安排重连(指数退避)
1668
+ */
1669
+ private scheduleReconnect;
1670
+ /**
1671
+ * 通过 UDS 发送消息
1672
+ */
1673
+ private sendViaUDS;
1674
+ /**
1675
+ * 发送消息到 Worker
1676
+ */
1677
+ private sendToWorker;
1678
+ }
1679
+
1680
+ interface FeatureCheckpoint {
1681
+ featureName: string;
1682
+ snapshot: FeatureStateSnapshot;
1683
+ }
1684
+
1685
+ interface AgentRuntimeSnapshot {
1686
+ initialized: boolean;
1687
+ callIndex: number;
1688
+ context?: ContextSnapshot;
1689
+ featureStates: FeatureCheckpoint[];
1690
+ usageStats?: UsageStatsSnapshot;
1691
+ }
1692
+ interface CallRollbackSnapshot {
1693
+ callIndex: number;
1694
+ draftInput: string;
1695
+ runtime: AgentRuntimeSnapshot;
1696
+ }
1697
+ interface AgentSessionSnapshot {
1698
+ version: number;
1699
+ sessionId: string;
1700
+ savedAt: number;
1701
+ agentType: string;
1702
+ runtime: AgentRuntimeSnapshot;
1703
+ rollbackHistory: CallRollbackSnapshot[];
1704
+ }
1705
+ interface SessionStore {
1706
+ save(sessionId: string, snapshot: AgentSessionSnapshot): Promise<string>;
1707
+ load(sessionId: string): Promise<AgentSessionSnapshot>;
1708
+ list(): Promise<string[]>;
1709
+ delete(sessionId: string): Promise<void>;
1710
+ }
1711
+ declare class FileSessionStore implements SessionStore {
1712
+ private readonly baseDir;
1713
+ constructor(baseDir?: string);
1714
+ save(sessionId: string, snapshot: AgentSessionSnapshot): Promise<string>;
1715
+ load(sessionId: string): Promise<AgentSessionSnapshot>;
1716
+ list(): Promise<string[]>;
1717
+ delete(sessionId: string): Promise<void>;
1718
+ private resolvePath;
1719
+ }
1720
+ declare function getDefaultSessionStore(): SessionStore;
1721
+
1722
+ /**
1723
+ * 钩子错误处理策略
1724
+ */
1725
+ declare enum HookErrorHandling {
1726
+ /** 静默失败:记录警告,不中断主流程 */
1727
+ Silent = "silent",
1728
+ /** 传播异常:中断整个 onCall 流程 */
1729
+ Propagate = "propagate",
1730
+ /** 记录后传播:先记录日志再抛出 */
1731
+ Logged = "logged"
1732
+ }
1733
+
1734
+ type CallRollbackCheckpoint = CallRollbackSnapshot;
1735
+ declare class AgentBase {
1736
+ protected readonly logger: Logger;
1737
+ protected llm: AgentConfig['llm'];
1738
+ protected tools: ToolRegistry;
1739
+ protected maxTurns: number;
1740
+ protected systemMessage?: string | TemplateSource;
1741
+ protected config: AgentConfig;
1742
+ protected templateLoader: TemplateLoader;
1743
+ protected persistentContext?: Context;
1744
+ protected debugHub?: DebugHub;
1745
+ protected agentId?: string;
1746
+ protected debugEnabled: boolean;
1747
+ protected _agentId?: string;
1748
+ protected _parentPool?: any;
1749
+ private features;
1750
+ private contextInjectors;
1751
+ private featureToolsReady;
1752
+ private hooksRegistry;
1753
+ protected _initialized: boolean;
1754
+ protected _currentCallInput?: string;
1755
+ protected _currentStep: number;
1756
+ protected _callIndex: number;
1757
+ protected _callStartTimes: Map<number, number>;
1758
+ protected _callCheckpoints: CallRollbackCheckpoint[];
1759
+ protected usageStats: UsageStats;
1760
+ private _pendingInput;
1761
+ private templateResolver?;
1762
+ private toolExecutor?;
1763
+ private reactRunner?;
1764
+ constructor(config: AgentConfig);
1765
+ /**
1766
+ * 获取钩子的错误处理策略(可被子类覆盖)
1767
+ */
1768
+ getHookErrorHandling(hookName: string): HookErrorHandling;
1769
+ /**
1770
+ * 设置待注入的用户输入
1771
+ *
1772
+ * Feature 可以在 CallStart 钩子中调用此方法来修改即将注入到上下文的输入内容
1773
+ * 典型用法:处理斜杠命令,去除命令前缀后更新输入
1774
+ *
1775
+ * @param input 新的输入内容
1776
+ */
1777
+ setUserInput(input: string): void;
1778
+ /**
1779
+ * 获取当前待注入的用户输入
1780
+ *
1781
+ * Feature 可以在 CallStart 钩子中调用此方法来获取当前输入缓存
1782
+ * 用于链式处理或条件判断
1783
+ *
1784
+ * @returns 当前输入缓存,如果未设置则返回空字符串
1785
+ */
1786
+ getUserInput(): string;
1787
+ /**
1788
+ * 唯一的公开入口 - 执行 Agent
1789
+ */
1790
+ onCall(input: string): Promise<string>;
1791
+ /**
1792
+ * 启用可视化查看器
1793
+ */
1794
+ withViewer(name?: string, port?: number, openBrowser?: boolean): Promise<this>;
1795
+ /**
1796
+ * 设置上下文
1797
+ */
1798
+ withContext(context: Context): this;
1799
+ /**
1800
+ * 从快照加载上下文
1801
+ */
1802
+ load(snapshot: ContextSnapshot): this;
1803
+ /**
1804
+ * 保存上下文为快照
1805
+ */
1806
+ save(): ContextSnapshot | undefined;
1807
+ /**
1808
+ * 生成当前会话快照
1809
+ */
1810
+ createSessionSnapshot(sessionId: string): Promise<AgentSessionSnapshot>;
1811
+ /**
1812
+ * 从会话快照恢复
1813
+ */
1814
+ restoreSessionSnapshot(snapshot: AgentSessionSnapshot): Promise<this>;
1815
+ rollbackToCall(callIndex: number): Promise<{
1816
+ draftInput: string;
1817
+ }>;
1818
+ /**
1819
+ * 保存会话到持久化存储
1820
+ */
1821
+ saveSession(sessionId: string, store?: SessionStore): Promise<string>;
1822
+ /**
1823
+ * 从持久化存储加载会话
1824
+ */
1825
+ loadSession(sessionId: string, store?: SessionStore): Promise<this>;
1826
+ /**
1827
+ * 重置上下文
1828
+ */
1829
+ reset(): this;
1830
+ /**
1831
+ * 设置系统提示词模板
1832
+ */
1833
+ setSystemPrompt(prompt: string | TemplateSource): this;
1834
+ /**
1835
+ * 设置占位符上下文变量
1836
+ */
1837
+ setSystemContext(context: PlaceholderContext): this;
1838
+ /**
1839
+ * 获取上下文(用于调试,向后兼容)
1840
+ */
1841
+ getContext(): Context;
1842
+ /**
1843
+ * 获取工具列表(向后兼容)
1844
+ */
1845
+ getTools(): ToolRegistry;
1846
+ /**
1847
+ * 获取用量统计
1848
+ */
1849
+ getUsage(): UsageStats;
1850
+ /**
1851
+ * 记录一次 LLM 调用的用量
1852
+ * @param callIndex Call 序号
1853
+ * @param step Step 序号
1854
+ * @param usage 用量数据
1855
+ */
1856
+ recordUsage(callIndex: number, step: number, usage: UsageInfo): void;
1857
+ /**
1858
+ * 标记 Call 结束
1859
+ * @param callIndex Call 序号
1860
+ */
1861
+ endCallUsage(callIndex: number): void;
1862
+ /**
1863
+ * 子代理向父代理回传消息
1864
+ */
1865
+ protected reportToParent(message: string): Promise<void>;
1866
+ /**
1867
+ * 创建 Agent 实例(子类可覆盖)
1868
+ */
1869
+ createAgentByType(type: string): Promise<AgentBase>;
1870
+ /**
1871
+ * 清理资源
1872
+ */
1873
+ dispose(): Promise<void>;
1874
+ /**
1875
+ * 使用 Feature(链式调用)
1876
+ */
1877
+ use(feature: AgentFeature): this;
1878
+ /**
1879
+ * 启用 Feature 的所有工具
1880
+ *
1881
+ * @example
1882
+ * agent.enable('mcp') // 启用 MCP 工具
1883
+ */
1884
+ enable(featureName: string): this;
1885
+ /**
1886
+ * 禁用 Feature 的所有工具
1887
+ *
1888
+ * @example
1889
+ * agent.disable('mcp') // 禁用 MCP 工具
1890
+ */
1891
+ disable(featureName: string): this;
1892
+ /**
1893
+ * 检查 Feature 是否启用
1894
+ *
1895
+ * @example
1896
+ * if (agent.isEnabled('mcp')) { ... }
1897
+ */
1898
+ isEnabled(featureName: string): boolean;
1899
+ /**
1900
+ * 确保 Feature 工具已注册
1901
+ */
1902
+ private ensureFeatureTools;
1903
+ /**
1904
+ * 解析相对路径(处理 ./ 和 ../)
1905
+ * @param baseDir 基础目录
1906
+ * @param relativePath 相对路径
1907
+ * @returns 绝对路径
1908
+ */
1909
+ private resolveRelativePath;
1910
+ /**
1911
+ * 确保执行器已初始化(延迟初始化)
1912
+ */
1913
+ private ensureExecutorsInitialized;
1914
+ /**
1915
+ * 推送到 DebugHub
1916
+ */
1917
+ private pushToDebug;
1918
+ private pushOverviewSnapshot;
1919
+ private captureRuntimeSnapshot;
1920
+ private restoreRuntimeSnapshot;
1921
+ private commitCallCheckpoint;
1922
+ private normalizeSessionSnapshot;
1923
+ private syncRegisteredToolsToDebug;
1924
+ private pushInspectorSnapshot;
1925
+ private buildOverviewSnapshot;
1926
+ private buildHookInspectorSnapshot;
1927
+ protected onInitiate(_ctx: AgentInitiateContext): Promise<void>;
1928
+ protected onDestroy(_ctx: AgentDestroyContext): Promise<void>;
1929
+ protected onCallStart(_ctx: CallStartContext): Promise<void>;
1930
+ protected onCallFinish(_ctx: CallFinishContext): Promise<void>;
1931
+ protected onStepStart(_ctx: StepStartContext): Promise<void>;
1932
+ /**
1933
+ * Step 结束钩子(扩展支持流控制)
1934
+ *
1935
+ * @returns
1936
+ * - undefined: 默认行为
1937
+ * - { action: 'continue' }: 继续下一步
1938
+ * - { action: 'end' }: 强制结束循环
1939
+ */
1940
+ protected onStepFinished(_ctx: StepFinishedContext): Promise<HookResult | undefined>;
1941
+ protected onToolUse(_ctx: ToolContext): Promise<HookResult | undefined>;
1942
+ /**
1943
+ * 工具执行完成钩子
1944
+ */
1945
+ protected onToolFinished(_result: ToolResult): Promise<void>;
1946
+ onSubAgentSpawn(_ctx: SubAgentSpawnContext): Promise<void>;
1947
+ onSubAgentUpdate(_ctx: SubAgentUpdateContext): Promise<void>;
1948
+ onSubAgentDestroy(_ctx: SubAgentDestroyContext): Promise<void>;
1949
+ onSubAgentInterrupt(_ctx: SubAgentInterruptContext): Promise<void>;
1950
+ protected onInterrupt(ctx: AgentInterruptContext): Promise<string>;
1951
+ }
1952
+
1953
+ /**
1954
+ * MCP stdio 传输配置
1955
+ */
1956
+ interface MCPSstdioConfig {
1957
+ /** 传输类型 */
1958
+ transport: 'stdio';
1959
+ /** 启动命令 */
1960
+ command: string;
1961
+ /** 命令参数 */
1962
+ args: string[];
1963
+ /** 环境变量 (可选) */
1964
+ env?: Record<string, string>;
1965
+ /** 工作目录 (可选) */
1966
+ cwd?: string;
1967
+ }
1968
+ /**
1969
+ * MCP HTTP 传输配置
1970
+ */
1971
+ interface MCPHTTPConfig {
1972
+ /** 传输类型 */
1973
+ transport: 'http';
1974
+ /** 服务器 URL */
1975
+ url: string;
1976
+ /** HTTP 请求头 (可选) */
1977
+ headers?: Record<string, string>;
1978
+ /** 超时时间 (毫秒,默认 30000) */
1979
+ timeout?: number;
1980
+ /** 重连次数 (默认 3) */
1981
+ retryCount?: number;
1982
+ }
1983
+ /**
1984
+ * MCP SSE 传输配置
1985
+ */
1986
+ interface MCPSSEConfig {
1987
+ /** 传输类型 */
1988
+ transport: 'sse';
1989
+ /** 服务器 URL */
1990
+ url: string;
1991
+ /** HTTP 请求头 (可选) */
1992
+ headers?: Record<string, string>;
1993
+ /** 重连次数 (默认 3) */
1994
+ retryCount?: number;
1995
+ }
1996
+ /**
1997
+ * MCP 服务器配置
1998
+ */
1999
+ type MCPServerConfig = MCPSstdioConfig | MCPHTTPConfig | MCPSSEConfig;
2000
+ /**
2001
+ * MCP 工具映射配置
2002
+ */
2003
+ interface MCPToolMappingConfig {
2004
+ /** 渲染模板覆盖 */
2005
+ render?: {
2006
+ call?: string;
2007
+ result?: string;
2008
+ };
2009
+ /** 工具注解覆盖 */
2010
+ annotations?: {
2011
+ /** 是否需要用户批准 */
2012
+ requiresApproval?: boolean;
2013
+ /** 是否为只读工具 */
2014
+ readOnly?: boolean;
2015
+ /** 是否为破坏性操作 */
2016
+ destructive?: boolean;
2017
+ };
2018
+ /** 是否禁用该工具 */
2019
+ disabled?: boolean;
2020
+ }
2021
+ /**
2022
+ * MCP 主配置
2023
+ */
2024
+ interface MCPConfig {
2025
+ /** 是否启用 MCP (默认 true) */
2026
+ enabled?: boolean;
2027
+ /** MCP 服务器配置 */
2028
+ servers: Record<string, MCPServerConfig>;
2029
+ /** 旧格式兼容 */
2030
+ mcpServers?: Record<string, MCPServerConfig>;
2031
+ /** 工具级别配置映射 */
2032
+ toolMapping?: Record<string, MCPToolMappingConfig>;
2033
+ /** 全局超时 (毫秒) */
2034
+ timeout?: number;
2035
+ /** 是否启用工具缓存 */
2036
+ enableCache?: boolean;
2037
+ }
2038
+ /**
2039
+ * MCP 连接状态
2040
+ */
2041
+ declare const enum MCPConnectionState {
2042
+ /** 未连接 */
2043
+ Disconnected = "disconnected",
2044
+ /** 连接中 */
2045
+ Connecting = "connecting",
2046
+ /** 已连接 */
2047
+ Connected = "connected",
2048
+ /** 连接错误 */
2049
+ Error = "error"
2050
+ }
2051
+ /**
2052
+ * MCP 连接信息
2053
+ */
2054
+ interface MCPConnectionInfo {
2055
+ /** 服务器名称 */
2056
+ name: string;
2057
+ /** 连接状态 */
2058
+ state: MCPConnectionState;
2059
+ /** 连接时间 */
2060
+ connectedAt?: number;
2061
+ /** 最后错误 */
2062
+ lastError?: string;
2063
+ /** 工具数量 */
2064
+ toolCount: number;
2065
+ }
2066
+ /**
2067
+ * MCP 工具调用结果
2068
+ */
2069
+ interface MCPToolResult {
2070
+ /** 是否成功 */
2071
+ success: boolean;
2072
+ /** 结果内容 */
2073
+ content?: string;
2074
+ /** 结构化数据 (如果可用) */
2075
+ structuredContent?: any;
2076
+ /** 错误信息 */
2077
+ error?: string;
2078
+ /** MCP 服务器名称 */
2079
+ server: string;
2080
+ /** 调用耗时 (毫秒) */
2081
+ duration: number;
2082
+ /** 图像数据 (如果有) */
2083
+ images?: Array<{
2084
+ data: string;
2085
+ mimeType: string;
2086
+ }>;
2087
+ /** 资源数据 (如果有) */
2088
+ resources?: Array<{
2089
+ uri: string;
2090
+ mimeType: string;
2091
+ text?: string;
2092
+ }>;
2093
+ }
2094
+ /**
2095
+ * MCP 统计信息
2096
+ */
2097
+ interface MCPStatistics {
2098
+ /** 总调用次数 */
2099
+ totalCalls: number;
2100
+ /** 成功调用次数 */
2101
+ successfulCalls: number;
2102
+ /** 失败调用次数 */
2103
+ failedCalls: number;
2104
+ /** 平均耗时 (毫秒) */
2105
+ averageDuration: number;
2106
+ /** 按服务器统计 */
2107
+ byServer: Record<string, {
2108
+ totalCalls: number;
2109
+ successfulCalls: number;
2110
+ failedCalls: number;
2111
+ averageDuration: number;
2112
+ }>;
2113
+ }
2114
+ /**
2115
+ * MCP 客户端配置
2116
+ */
2117
+ interface MCPClientConfig {
2118
+ /** 配置文件路径 */
2119
+ configPath?: string;
2120
+ /** 是否自动重连 */
2121
+ autoReconnect?: boolean;
2122
+ /** 重连间隔 (毫秒) */
2123
+ reconnectInterval?: number;
2124
+ /** 最大重连次数 */
2125
+ maxReconnectAttempts?: number;
2126
+ /** 日志级别 */
2127
+ logLevel?: 'silent' | 'error' | 'warn' | 'info' | 'debug';
2128
+ }
2129
+
2130
+ declare class MCPConnectionManager {
2131
+ private connections;
2132
+ private reconnectTimers;
2133
+ private readonly logger;
2134
+ /**
2135
+ * 连接到 MCP 服务器
2136
+ */
2137
+ connectServer(name: string, config: MCPServerConfig): Promise<Client | any>;
2138
+ /**
2139
+ * 连接到 stdio MCP 服务器
2140
+ */
2141
+ private connectStdio;
2142
+ /**
2143
+ * 连接到 HTTP MCP 服务器
2144
+ */
2145
+ private connectSSE;
2146
+ /**
2147
+ * 连接到 HTTP MCP 服务器
2148
+ */
2149
+ private connectHTTP;
2150
+ /**
2151
+ * 断开服务器连接
2152
+ */
2153
+ disconnectServer(name: string): Promise<void>;
2154
+ /**
2155
+ * 断开所有连接
2156
+ */
2157
+ disconnectAll(): Promise<void>;
2158
+ /**
2159
+ * 列出服务器的所有工具
2160
+ */
2161
+ listTools(name: string): Promise<Array<{
2162
+ name: string;
2163
+ description?: string;
2164
+ inputSchema?: any;
2165
+ }>>;
2166
+ callTool(name: string, serverName: string, args: Record<string, unknown>): Promise<{
2167
+ content: any[];
2168
+ isError?: boolean;
2169
+ }>;
2170
+ getConnectionInfo(name: string): MCPConnectionInfo | undefined;
2171
+ /**
2172
+ * 获取所有连接信息
2173
+ */
2174
+ getAllConnections(): MCPConnectionInfo[];
2175
+ /**
2176
+ * 检查连接状态
2177
+ */
2178
+ isConnected(name: string): boolean;
2179
+ /**
2180
+ * 获取服务器实例
2181
+ */
2182
+ getServer(name: string): Client | any | undefined;
2183
+ /**
2184
+ * 安排重连
2185
+ */
2186
+ private scheduleReconnect;
2187
+ /**
2188
+ * 日志输出
2189
+ */
2190
+ private log;
2191
+ private handleProcessOutput;
2192
+ private handleDirectResponse;
2193
+ private sendDirectRequest;
2194
+ private normalizeToolCallResponse;
2195
+ private rejectAllPendingRequests;
2196
+ dispose(): Promise<void>;
2197
+ }
2198
+
2199
+ /**
2200
+ * MCP Feature - MCP 服务器连接和工具注册
2201
+ *
2202
+ * 将 MCP 集成从 Agent 核心中解耦,实现可外挂功能
2203
+ *
2204
+ * @example
2205
+ * ```typescript
2206
+ * // 自动扫描 .agentdev/mcps/*.json
2207
+ * agent.use(new MCPFeature());
2208
+ *
2209
+ * // 从配置文件加载(默认路径 .agentdev/mcps)
2210
+ * agent.use(new MCPFeature('github'));
2211
+ *
2212
+ * // 从指定路径加载配置
2213
+ * agent.use(new MCPFeature('./path/to/mcps/github'));
2214
+ *
2215
+ * // 直接传入配置对象
2216
+ * agent.use(new MCPFeature({ servers: { ... } }));
2217
+ * ```
2218
+ */
2219
+
2220
+ /**
2221
+ * MCP Feature 配置类型
2222
+ */
2223
+ type MCPFeatureInput = MCPConfig | string;
2224
+ interface MCPFeatureOptions {
2225
+ excludeServers?: string[];
2226
+ }
2227
+ /**
2228
+ * MCP Feature 实现
2229
+ */
2230
+ declare class MCPFeature implements AgentFeature {
2231
+ readonly name = "mcp";
2232
+ readonly dependencies: string[];
2233
+ readonly source: string;
2234
+ readonly description = "\u8FDE\u63A5 MCP \u670D\u52A1\u5668\u5E76\u628A\u53D1\u73B0\u5230\u7684\u8FDC\u7A0B\u80FD\u529B\u6302\u8F7D\u6210\u6807\u51C6\u5DE5\u5177\u3002";
2235
+ private readonly manager;
2236
+ private clients;
2237
+ private config?;
2238
+ private mcpContext?;
2239
+ /**
2240
+ * 缓存包信息
2241
+ */
2242
+ private _packageInfo;
2243
+ /**
2244
+ * 获取包信息(统一打包方案)
2245
+ */
2246
+ getPackageInfo(): PackageInfo | null;
2247
+ /**
2248
+ * 获取模板名称列表(统一打包方案)
2249
+ */
2250
+ getTemplateNames(): string[];
2251
+ constructor(input?: MCPFeatureInput, options?: MCPFeatureOptions);
2252
+ /**
2253
+ * 获取同步工具(无)
2254
+ */
2255
+ getTools(): Tool[];
2256
+ /**
2257
+ * 获取异步工具(需要连接 MCP 服务器)
2258
+ */
2259
+ getAsyncTools(_ctx: FeatureInitContext): Promise<Tool[]>;
2260
+ /**
2261
+ * 声明上下文注入器
2262
+ * 为所有 MCP 工具注入 _mcpContext
2263
+ */
2264
+ getContextInjectors(): Map<string | RegExp, ContextInjector>;
2265
+ /**
2266
+ * 清理钩子
2267
+ */
2268
+ onDestroy(): Promise<void>;
2269
+ /**
2270
+ * 设置 MCP 上下文(运行时注入)
2271
+ */
2272
+ setMCPContext(context: Record<string, unknown>): void;
2273
+ /**
2274
+ * 获取连接管理器(供外部使用)
2275
+ */
2276
+ getConnectionManager(): MCPConnectionManager | undefined;
2277
+ }
2278
+
2279
+ /**
2280
+ * Agent Skills 类型定义
2281
+ */
2282
+ /**
2283
+ * Skill 元数据
2284
+ */
2285
+ interface SkillMetadata {
2286
+ /** Skill 名称 */
2287
+ name: string;
2288
+ /** Skill 描述 */
2289
+ description: string;
2290
+ /** SKILL.md 完整路径 */
2291
+ path: string;
2292
+ }
2293
+ /**
2294
+ * Skills 加载器配置
2295
+ */
2296
+ interface SkillsOptions {
2297
+ /** skills 目录,默认 cwd/.agentdev/skills */
2298
+ dir?: string;
2299
+ }
2300
+
2301
+ /**
2302
+ * Skill Feature - Skills 发现和 invoke_skill 工具
2303
+ *
2304
+ * 将 Skills 集成从 Agent 核心中解耦,实现可外挂功能
2305
+ *
2306
+ * @example
2307
+ * ```typescript
2308
+ * // 使用默认路径 .agentdev/skills
2309
+ * agent.use(new SkillFeature());
2310
+ *
2311
+ * // 使用自定义路径
2312
+ * agent.use(new SkillFeature('./custom/skills'));
2313
+ * agent.use(new SkillFeature({ dir: './custom/skills' }));
2314
+ * ```
2315
+ */
2316
+
2317
+ /**
2318
+ * Skill Feature 配置类型
2319
+ */
2320
+ interface SkillFeatureConfig extends SkillsOptions {
2321
+ /** Skills 目录路径 */
2322
+ dir?: string;
2323
+ }
2324
+ /**
2325
+ * Skill Feature 输入类型
2326
+ */
2327
+ type SkillFeatureInput = SkillFeatureConfig | string | undefined;
2328
+ /**
2329
+ * Skill Feature 实现
2330
+ */
2331
+ declare class SkillFeature implements AgentFeature {
2332
+ readonly name = "skill";
2333
+ readonly dependencies: string[];
2334
+ readonly source: string;
2335
+ readonly description = "\u53D1\u73B0\u672C\u5730 skills\uFF0C\u5E76\u63D0\u4F9B invoke_skill \u5DE5\u5177\u4E0E\u6280\u80FD\u6570\u636E\u6E90\u3002";
2336
+ private skillsDir?;
2337
+ private skills;
2338
+ /**
2339
+ * 缓存包信息
2340
+ */
2341
+ private _packageInfo;
2342
+ /**
2343
+ * 获取包信息(统一打包方案)
2344
+ */
2345
+ getPackageInfo(): PackageInfo | null;
2346
+ /**
2347
+ * 获取模板名称列表(统一打包方案)
2348
+ */
2349
+ getTemplateNames(): string[];
2350
+ constructor(input?: SkillFeatureInput);
2351
+ /**
2352
+ * 获取同步工具(invoke_skill)
2353
+ */
2354
+ getTools(): Tool[];
2355
+ /**
2356
+ * 声明上下文注入器
2357
+ * 为 invoke_skill 工具注入 _context.skills
2358
+ */
2359
+ getContextInjectors(): Map<string | RegExp, ContextInjector>;
2360
+ /**
2361
+ * 初始化钩子
2362
+ * 执行 Skills 发现并注册数据源
2363
+ */
2364
+ onInitiate(ctx: FeatureInitContext): Promise<void>;
2365
+ /**
2366
+ * 获取已加载的 Skills
2367
+ */
2368
+ getSkills(): SkillMetadata[];
2369
+ /**
2370
+ * 设置 Skills 目录
2371
+ */
2372
+ setSkillsDir(dir: string): void;
2373
+ }
2374
+
2375
+ /**
2376
+ * 反向钩子装饰器
2377
+ *
2378
+ * 使用装饰器标记反向钩子方法,提供编译时和运行时类型检查
2379
+ */
2380
+
2381
+ /**
2382
+ * Call 开始装饰器
2383
+ *
2384
+ * 标记在 Call 开始时执行的方法
2385
+ * 返回 void(仅做处理,不控制流程)
2386
+ */
2387
+ declare const CallStart: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2388
+
2389
+ /**
2390
+ * AgentPool - 子代理管理核心
2391
+ * 管理父代理创建的所有子代理实例
2392
+ */
2393
+
2394
+ /**
2395
+ * 子代理实例信息
2396
+ */
2397
+ interface SubAgentInstance {
2398
+ id: string;
2399
+ type: string;
2400
+ agent: AgentBase;
2401
+ status: SubAgentStatus;
2402
+ initialInstruction: string;
2403
+ createdAt: number;
2404
+ completedAt?: number;
2405
+ result?: string;
2406
+ error?: string;
2407
+ }
2408
+ /**
2409
+ * Agent 创建函数类型(异步)
2410
+ */
2411
+ type AgentFactory = (type: string) => AgentBase | Promise<AgentBase>;
2412
+ /**
2413
+ * AgentPool - 子代理管理核心
2414
+ * 管理父代理创建的所有子代理实例
2415
+ */
2416
+ declare class AgentPool {
2417
+ private _instances;
2418
+ private _counters;
2419
+ private _parent;
2420
+ /** 待回传消息队列:agentId -> messages[] */
2421
+ private _pendingMessages;
2422
+ /** 消息就绪解析器:key -> resolver function */
2423
+ private _messageResolvers;
2424
+ constructor(parent: AgentBase);
2425
+ /**
2426
+ * 创建子代理(不自动执行,等待 sendTo 激活)
2427
+ */
2428
+ spawn(type: string, createAgentFn: AgentFactory): Promise<string>;
2429
+ /**
2430
+ * 获取实例信息
2431
+ */
2432
+ get(id: string): SubAgentInstance | undefined;
2433
+ /**
2434
+ * 列出所有实例
2435
+ */
2436
+ list(filter?: SubAgentStatus): SubAgentInstance[];
2437
+ /**
2438
+ * 向子代理发送消息(非阻塞)
2439
+ */
2440
+ sendTo(id: string, message: string): Promise<void>;
2441
+ /**
2442
+ * 关闭子代理
2443
+ */
2444
+ close(id: string, reason?: string): Promise<void>;
2445
+ /**
2446
+ * 子代理回传消息到父代理
2447
+ * @param agentId 子代理 ID
2448
+ * @param message 消息内容
2449
+ */
2450
+ report(agentId: string, message: string): Promise<void>;
2451
+ /**
2452
+ * 等待任意子代理的消息
2453
+ * @returns { agentId, message }
2454
+ */
2455
+ waitForMessage(): Promise<{
2456
+ agentId: string;
2457
+ message: string;
2458
+ }>;
2459
+ /**
2460
+ * 检查是否有活跃的子代理或待处理的消息
2461
+ *
2462
+ * 注意:先检查消息队列,避免竞态条件
2463
+ */
2464
+ hasActiveAgents(): boolean;
2465
+ /**
2466
+ * 检查是否有待处理的子代理消息
2467
+ */
2468
+ hasPendingMessages(): boolean;
2469
+ /**
2470
+ * 处理子代理中断
2471
+ * @param agentId 子代理 ID
2472
+ * @param reason 中断原因
2473
+ * @param result 中断时的结果
2474
+ */
2475
+ handleInterrupt(agentId: string, reason: 'max_steps_reached' | 'error' | 'cancelled', result: string): Promise<void>;
2476
+ /**
2477
+ * 关闭所有子代理
2478
+ */
2479
+ shutdown(): Promise<void>;
2480
+ getRuntimeSnapshot(): {
2481
+ counters: Array<[string, number]>;
2482
+ instances: Array<{
2483
+ id: string;
2484
+ type: string;
2485
+ status: SubAgentStatus;
2486
+ }>;
2487
+ pendingMessages: Array<[string, string[]]>;
2488
+ };
2489
+ restoreRuntimeSnapshot(snapshot: {
2490
+ counters?: Array<[string, number]>;
2491
+ }): Promise<void>;
2492
+ private _onComplete;
2493
+ private _onError;
2494
+ }
2495
+
2496
+ /**
2497
+ * 子代理 Feature
2498
+ *
2499
+ * 提供子代理创建、管理、消息回传等完整能力
2500
+ *
2501
+ * 重构说明:
2502
+ * - 使用装饰器实现反向钩子
2503
+ * - @ToolFinished: 处理 wait 工具完成后的等待逻辑
2504
+ * - @StepFinish: 处理无工具调用时的子代理等待逻辑
2505
+ */
2506
+ declare class SubAgentFeature implements AgentFeature {
2507
+ readonly name = "subagent";
2508
+ readonly dependencies: string[];
2509
+ readonly source: string;
2510
+ readonly description = "\u63D0\u4F9B\u5B50\u4EE3\u7406\u521B\u5EFA\u3001\u7B49\u5F85\u4E0E\u6D88\u606F\u56DE\u4F20\u80FD\u529B\uFF0C\u8BA9\u4E3B\u5FAA\u73AF\u53EF\u4EE5\u534F\u540C\u591A\u4E2A\u4EE3\u7406\u5DE5\u4F5C\u3002";
2511
+ private agentPool?;
2512
+ private parentAgent?;
2513
+ private toolFactory?;
2514
+ /**
2515
+ * 缓存包信息
2516
+ */
2517
+ private _packageInfo;
2518
+ /**
2519
+ * 获取包信息(统一打包方案)
2520
+ */
2521
+ getPackageInfo(): PackageInfo | null;
2522
+ /**
2523
+ * 获取模板名称列表(统一打包方案)
2524
+ */
2525
+ getTemplateNames(): string[];
2526
+ constructor();
2527
+ /**
2528
+ * 获取 AgentPool(供外部访问)
2529
+ */
2530
+ get pool(): AgentPool | undefined;
2531
+ /**
2532
+ * 初始化钩子
2533
+ */
2534
+ onInitiate(_ctx: FeatureInitContext): Promise<void>;
2535
+ /**
2536
+ * 设置父代理引用(由 Agent 在 use() 时调用)
2537
+ */
2538
+ _setParentAgent(agent: AgentBase): void;
2539
+ /**
2540
+ * 获取同步工具
2541
+ */
2542
+ getTools(): Tool[];
2543
+ getContextInjectors(): Map<string | RegExp, ContextInjector>;
2544
+ getHookDescription(lifecycle: string, methodName: string): string | undefined;
2545
+ /**
2546
+ * 处理 wait 工具
2547
+ *
2548
+ * 触发时机:wait 工具执行完成后
2549
+ * 处理逻辑:
2550
+ * 1. 检测刚才执行的工具是否是 wait
2551
+ * 2. 如果不是,直接返回(不处理)
2552
+ * 3. 如果是,检查是否有 busy 状态的子代理
2553
+ * 4. 如果有,调用 agentPool.waitForMessage() 阻塞等待(await 阻塞主循环)
2554
+ * 5. 消息插入到主代理 context
2555
+ *
2556
+ * 注意:这是纯通知钩子(void),流程控制通过 await 阻塞实现
2557
+ */
2558
+ handleWaitTool(ctx: ToolFinishedDecisionContext): Promise<void>;
2559
+ /**
2560
+ * 处理无工具调用时的子代理等待
2561
+ *
2562
+ * 触发时机:Step 结束时
2563
+ * 处理逻辑:
2564
+ * 1. 检查是否有 busy 状态的子代理
2565
+ * 2. 如果没有,返回 Continue(正常结束)
2566
+ * 3. 如果有,调用 agentPool.waitForMessage() 阻塞等待
2567
+ * 4. 消息插入到主代理 context
2568
+ * 5. 返回 Approve(重启 ReAct 循环)
2569
+ */
2570
+ handleNoToolCalls(ctx: StepFinishDecisionContext): Promise<DecisionResult>;
2571
+ onDestroy(): Promise<void>;
2572
+ captureState(): FeatureStateSnapshot;
2573
+ restoreState(snapshot: FeatureStateSnapshot): Promise<void>;
2574
+ }
2575
+
2576
+ /**
2577
+ * Todo Feature 类型定义
2578
+ */
2579
+ /**
2580
+ * 任务状态
2581
+ */
2582
+ type TaskStatus = 'pending' | 'in_progress' | 'completed' | 'deleted';
2583
+ /**
2584
+ * 任务数据结构
2585
+ */
2586
+ interface TodoTask {
2587
+ /** 任务 ID */
2588
+ id: string;
2589
+ /** 任务标题(祈使句) */
2590
+ subject: string;
2591
+ /** 详细描述 */
2592
+ description: string;
2593
+ /** 进行时形式(用于进度显示) */
2594
+ activeForm: string;
2595
+ /** 任务状态 */
2596
+ status: TaskStatus;
2597
+ /** 负责人(Agent ID) */
2598
+ owner?: string;
2599
+ /** 此任务阻塞的其他任务 ID */
2600
+ blocks: string[];
2601
+ /** 阻塞此任务的其他任务 ID */
2602
+ blockedBy: string[];
2603
+ /** 元数据 */
2604
+ metadata?: Record<string, unknown>;
2605
+ /** 创建时间 */
2606
+ createdAt: number;
2607
+ /** 更新时间 */
2608
+ updatedAt: number;
2609
+ }
2610
+ /**
2611
+ * 任务更新参数
2612
+ */
2613
+ interface TodoTaskUpdate {
2614
+ status?: TaskStatus;
2615
+ subject?: string;
2616
+ description?: string;
2617
+ activeForm?: string;
2618
+ owner?: string;
2619
+ metadata?: Record<string, unknown>;
2620
+ addBlocks?: string[];
2621
+ addBlockedBy?: string[];
2622
+ }
2623
+ /**
2624
+ * 任务列表摘要
2625
+ */
2626
+ interface TodoTaskSummary {
2627
+ id: string;
2628
+ subject: string;
2629
+ status: TaskStatus;
2630
+ owner?: string;
2631
+ blockedBy: string[];
2632
+ }
2633
+ /**
2634
+ * TodoFeature 配置
2635
+ */
2636
+ interface TodoFeatureConfig {
2637
+ /** Reminder 模板文件路径 */
2638
+ reminderTemplate?: string;
2639
+ /** 有待执行任务时的提醒间隔(默认:3 轮) */
2640
+ reminderThresholdWithTasks?: number;
2641
+ /** 无待执行任务时的提醒间隔(默认:6 轮) */
2642
+ reminderThresholdWithoutTasks?: number;
2643
+ }
2644
+
2645
+ /**
2646
+ * Todo Feature - 任务列表管理功能模块
2647
+ *
2648
+ * 提供任务创建、查询、更新等能力,用于跟踪复杂任务的进度
2649
+ * 内置智能提醒功能,自动跟踪工具使用并在合适时机注入提醒
2650
+ *
2651
+ * 重构说明:
2652
+ * - 使用反向钩子装饰器实现提醒逻辑
2653
+ * - 不再需要在 Agent 中重写 onStepStart/onStepFinished
2654
+ */
2655
+
2656
+ /**
2657
+ * TodoFeature 实现
2658
+ *
2659
+ * 提供任务管理和智能提醒功能
2660
+ * 使用反向钩子自动处理提醒逻辑,无需在 Agent 中重写钩子方法
2661
+ */
2662
+ declare class TodoFeature implements AgentFeature {
2663
+ readonly name = "todo";
2664
+ readonly source: string;
2665
+ readonly description = "\u7EF4\u62A4\u4EFB\u52A1\u6E05\u5355\uFF0C\u5E76\u5728\u5408\u9002\u7684\u5FAA\u73AF\u65F6\u673A\u81EA\u52A8\u63D0\u9192\u6A21\u578B\u66F4\u65B0 todo \u72B6\u6001\u3002";
2666
+ private tasks;
2667
+ private counter;
2668
+ private config;
2669
+ private reminderContent;
2670
+ private consecutiveNoTodoTurns;
2671
+ private reminderInjected;
2672
+ private toolFactory?;
2673
+ private _packageInfo;
2674
+ constructor(config?: TodoFeatureConfig);
2675
+ /**
2676
+ * 获取包信息(统一打包方案)
2677
+ */
2678
+ getPackageInfo(): PackageInfo | null;
2679
+ /**
2680
+ * 获取模板名称列表(统一打包方案)
2681
+ */
2682
+ getTemplateNames(): string[];
2683
+ getTools(): Tool[];
2684
+ onInitiate(_ctx: FeatureInitContext): Promise<void>;
2685
+ onDestroy(_ctx: FeatureContext): Promise<void>;
2686
+ captureState(): FeatureStateSnapshot;
2687
+ restoreState(snapshot: FeatureStateSnapshot): void;
2688
+ getHookDescription(lifecycle: string, methodName: string): string | undefined;
2689
+ /**
2690
+ * Step 开始时检查是否需要注入 reminder
2691
+ *
2692
+ * 触发时机:每轮 ReAct 迭代开始时
2693
+ * 处理逻辑:
2694
+ * 1. 检查连续未使用 todo 工具的轮次
2695
+ * 2. 达到阈值时注入 reminder 系统消息
2696
+ * 3. 防止重复注入
2697
+ */
2698
+ checkAndInjectReminder(ctx: StepStartContext): Promise<void>;
2699
+ /**
2700
+ * Step 结束时记录是否使用了 todo 工具
2701
+ *
2702
+ * 触发时机:每轮 ReAct 迭代结束时
2703
+ * 处理逻辑:
2704
+ * 1. 检查本轮是否使用了 todo 工具
2705
+ * 2. 使用了则重置计数器,未使用则计数器+1
2706
+ * 3. 返回 Continue 使用默认行为
2707
+ */
2708
+ recordToolUsage(ctx: StepFinishDecisionContext): Promise<DecisionResult>;
2709
+ /**
2710
+ * 设置 reminder 内容
2711
+ */
2712
+ setReminderContent(content: string): void;
2713
+ /**
2714
+ * 获取当前的提醒阈值(根据任务状态动态调整)
2715
+ */
2716
+ private getCurrentThreshold;
2717
+ /**
2718
+ * 创建任务
2719
+ */
2720
+ createTask(subject: string, description: string, activeForm: string, options?: {
2721
+ owner?: string;
2722
+ metadata?: Record<string, unknown>;
2723
+ }): TodoTask;
2724
+ /**
2725
+ * 获取任务详情
2726
+ */
2727
+ getTask(taskId: string): TodoTask | undefined;
2728
+ /**
2729
+ * 列出所有任务摘要
2730
+ */
2731
+ listTasks(filter?: {
2732
+ status?: TaskStatus;
2733
+ }): TodoTaskSummary[];
2734
+ /**
2735
+ * 更新任务
2736
+ */
2737
+ updateTask(taskId: string, updates: TodoTaskUpdate): TodoTask | undefined;
2738
+ /**
2739
+ * 清空所有任务
2740
+ */
2741
+ clearTasks(): void;
2742
+ /** 判断是否是 todo 工具 */
2743
+ private isTodoTool;
2744
+ /** 获取默认 reminder 内容 */
2745
+ private getDefaultReminder;
2746
+ }
2747
+
2748
+ /**
2749
+ * UserInputFeature - 通过调试界面获取用户输入
2750
+ *
2751
+ * 功能:
2752
+ * - 提供 get_user_input 工具,允许 LLM 请求用户输入
2753
+ * - 通过 DebugHub 的 UDS 通道与 ViewerWorker 通信
2754
+ * - 前端显示输入框,用户提交后返回给 Agent
2755
+ */
2756
+
2757
+ interface UserInputFeatureConfig {
2758
+ /** 默认超时时间(毫秒),默认无限等待 */
2759
+ timeout?: number;
2760
+ }
2761
+ declare class UserInputFeature implements AgentFeature {
2762
+ readonly name = "user-input";
2763
+ readonly dependencies: string[];
2764
+ readonly source: string;
2765
+ readonly description = "\u5141\u8BB8 Agent \u901A\u8FC7\u8C03\u8BD5\u754C\u9762\u5411\u7528\u6237\u53D1\u8D77\u8F93\u5165\u8BF7\u6C42\u5E76\u7B49\u5F85\u56DE\u590D\u3002";
2766
+ private defaultTimeout;
2767
+ private nextDraftInput;
2768
+ /**
2769
+ * 缓存包信息
2770
+ */
2771
+ private _packageInfo;
2772
+ /**
2773
+ * 获取包信息(统一打包方案)
2774
+ */
2775
+ getPackageInfo(): PackageInfo | null;
2776
+ /**
2777
+ * 获取模板名称列表(统一打包方案)
2778
+ * 注意:UserInputFeature 没有渲染模板
2779
+ */
2780
+ getTemplateNames(): string[];
2781
+ constructor(config?: UserInputFeatureConfig);
2782
+ setNextDraftInput(input: string): void;
2783
+ /**
2784
+ * 请求用户输入(核心方法)
2785
+ */
2786
+ requestUserInput(prompt: string, timeout?: number): Promise<string>;
2787
+ requestUserInputEvent(request: UserInputRequest, timeout?: number): Promise<UserInputResponse>;
2788
+ /**
2789
+ * 获取用户输入(公开接口,供主循环直接调用)
2790
+ * @param prompt 提示信息
2791
+ * @param timeout 超时时间(毫秒)
2792
+ * @returns 用户输入内容
2793
+ */
2794
+ getUserInput(prompt?: string, timeout?: number): Promise<string>;
2795
+ getUserInputEvent(prompt?: string, timeout?: number, actions?: UserInputAction[]): Promise<UserInputResponse>;
2796
+ getTools(): Tool[];
2797
+ onInitiate(_ctx: FeatureInitContext): Promise<void>;
2798
+ onDestroy(_ctx: FeatureContext): Promise<void>;
2799
+ }
2800
+
2801
+ /**
2802
+ * OpencodeBasic Feature - 基础文件操作工具集
2803
+ */
2804
+ declare class OpencodeBasicFeature implements AgentFeature {
2805
+ readonly name = "opencode-basic";
2806
+ readonly dependencies: string[];
2807
+ readonly source: string;
2808
+ readonly description = "\u63D0\u4F9B\u8BFB\u5199\u6587\u4EF6\u3001\u7F16\u8F91\u3001\u5217\u76EE\u5F55\u3001glob \u548C grep \u7B49\u57FA\u7840\u5DE5\u7A0B\u5316\u5DE5\u5177\u3002\u5305\u542B\"\u5148\u8BFB\u540E\u5199\"\u5B89\u5168\u4FDD\u62A4\u673A\u5236\u3002";
2809
+ /**
2810
+ * 存储已读取文件的路径(绝对路径)
2811
+ * 在整个 Session 生命周期中保持,用于验证 write 操作
2812
+ */
2813
+ private readFiles;
2814
+ /**
2815
+ * 缓存包信息
2816
+ */
2817
+ private _packageInfo;
2818
+ /**
2819
+ * 获取包信息(统一打包方案)
2820
+ */
2821
+ getPackageInfo(): PackageInfo | null;
2822
+ /**
2823
+ * 获取模板名称列表(统一打包方案)
2824
+ */
2825
+ getTemplateNames(): string[];
2826
+ /**
2827
+ * Logger 实例,用于记录结构化日志
2828
+ */
2829
+ private logger;
2830
+ /**
2831
+ * Feature 初始化时清空读取历史
2832
+ */
2833
+ onInitiate(ctx: FeatureInitContext): Promise<void>;
2834
+ captureState(): FeatureStateSnapshot;
2835
+ restoreState(snapshot: FeatureStateSnapshot): void;
2836
+ /**
2837
+ * 工具使用前拦截器
2838
+ * - 记录 read 操作的文件路径
2839
+ * - 验证 write 操作是否已先读取
2840
+ */
2841
+ validateWriteOperation(ctx: ToolContext): Promise<DecisionResult>;
2842
+ /**
2843
+ * 获取所有工具
2844
+ */
2845
+ getTools(): Tool[];
2846
+ }
2847
+
2848
+ interface ExampleFeatureConfig {
2849
+ enabledByDefault?: boolean;
2850
+ notePrefix?: string;
2851
+ }
2852
+ interface ExampleFeatureRuntimeState {
2853
+ enabled: boolean;
2854
+ counter: number;
2855
+ lastInput: string;
2856
+ notes: string[];
2857
+ }
2858
+ interface ExampleFeatureSnapshot {
2859
+ enabled: boolean;
2860
+ counter: number;
2861
+ lastInput: string;
2862
+ notes: string[];
2863
+ }
2864
+
2865
+ declare class ExampleFeature implements AgentFeature {
2866
+ readonly name = "example-feature";
2867
+ readonly dependencies: string[];
2868
+ readonly source: string;
2869
+ readonly description = "\u793A\u8303\u7528 Feature \u9AA8\u67B6\uFF1A\u5C55\u793A\u5DE5\u5177\u3001\u6A21\u677F\u3001\u4E0A\u4E0B\u6587\u6CE8\u5165\u3001\u56DE\u6EDA\u5FEB\u7167\u548C\u53CD\u5411\u94A9\u5B50\u7684\u6807\u51C6\u5199\u6CD5\u3002";
2870
+ private readonly config;
2871
+ private readonly runtime;
2872
+ private logger?;
2873
+ private _packageInfo;
2874
+ constructor(config?: ExampleFeatureConfig);
2875
+ /**
2876
+ * 公开 API 只保留“其他 Feature 真会读取的东西”。
2877
+ * 不要把整个 runtime 对象直接暴露出去。
2878
+ */
2879
+ isEnabled(): boolean;
2880
+ getCounter(): number;
2881
+ listNotes(): string[];
2882
+ /**
2883
+ * 内部 helper 比直接在装饰器和工具里散改字段更容易维护。
2884
+ * 如果 Feature 很简单,也可以不抽这些方法。
2885
+ */
2886
+ private appendNote;
2887
+ private setEnabled;
2888
+ private buildReminder;
2889
+ getTools(): Tool[];
2890
+ /**
2891
+ * 获取包信息(统一打包方案)
2892
+ */
2893
+ getPackageInfo(): PackageInfo | null;
2894
+ /**
2895
+ * 获取模板名称列表(统一打包方案)
2896
+ */
2897
+ getTemplateNames(): string[];
2898
+ getContextInjectors(): Map<string | RegExp, ContextInjector>;
2899
+ onInitiate(ctx: FeatureInitContext): Promise<void>;
2900
+ onDestroy(_ctx: FeatureContext): Promise<void>;
2901
+ captureState(): FeatureStateSnapshot;
2902
+ restoreState(snapshot: FeatureStateSnapshot): void;
2903
+ beforeRollback(snapshot: FeatureStateSnapshot): Promise<void>;
2904
+ afterRollback(snapshot: FeatureStateSnapshot): Promise<void>;
2905
+ handleCallStart(ctx: CallStartContext): Promise<void>;
2906
+ validateExampleTool(ctx: ToolContext): Promise<typeof Decision.Continue | typeof Decision.Deny>;
2907
+ handleStepFinish(ctx: StepFinishDecisionContext): Promise<typeof Decision.Continue>;
2908
+ }
2909
+
2910
+ /**
2911
+ * 配置加载
2912
+ * 从 config 目录读取 JSON 配置文件
2913
+ *
2914
+ * 提供两种方式:
2915
+ * - loadConfig() - 异步加载(用于特殊场景)
2916
+ * - loadConfigSync() - 同步加载(推荐,用于 Agent 构造)
2917
+ */
2918
+ /**
2919
+ * 统一配置类型
2920
+ * 字段允许冗余,各 LLM 实现只取自己需要的
2921
+ */
2922
+ interface ModelConfig {
2923
+ provider: 'openai' | 'anthropic' | string;
2924
+ apiKey: string;
2925
+ model: string;
2926
+ baseUrl?: string;
2927
+ maxTokens?: number;
2928
+ thinkingBudgetTokens?: number;
2929
+ thinkingKeepTurns?: number;
2930
+ providerOptions?: Record<string, unknown>;
2931
+ region?: string;
2932
+ projectId?: string;
2933
+ }
2934
+ interface AgentConfigFile {
2935
+ defaultModel: ModelConfig;
2936
+ agent: {
2937
+ maxTurns: number;
2938
+ temperature: number;
2939
+ };
2940
+ }
2941
+ /**
2942
+ * 读取配置文件(异步版本)
2943
+ * @param name 配置文件名(不含路径和扩展名),默认 'default'
2944
+ */
2945
+ declare function loadConfig(name?: string): Promise<AgentConfigFile>;
2946
+ /**
2947
+ * 读取配置文件(同步版本,推荐用于 Agent 构造)
2948
+ * @param name 配置文件名(不含路径和扩展名),默认 'default'
2949
+ */
2950
+ declare function loadConfigSync(name?: string): AgentConfigFile;
2951
+ /**
2952
+ * 列出所有可用的配置文件
2953
+ */
2954
+ declare function listConfigs(): Promise<string[]>;
2955
+
2956
+ /**
2957
+ * BasicAgent - 基础 Agent 类
2958
+ *
2959
+ * 集成了常用 Feature 和系统环境信息
2960
+ * 适用于大多数 Agent 场景
2961
+ *
2962
+ * 默认自动加载配置文件,开箱即用
2963
+ */
2964
+
2965
+ /**
2966
+ * 系统环境信息上下文
2967
+ */
2968
+ interface SystemContext$1 {
2969
+ /** 当前工作目录 */
2970
+ SYSTEM_WORKING_DIR: string;
2971
+ /** 是否是 Git 仓库 */
2972
+ SYSTEM_IS_GIT_REPOSITORY: boolean;
2973
+ /** 操作系统平台 */
2974
+ SYSTEM_PLATFORM: NodeJS.Platform;
2975
+ /** 当前日期 (YYYY-MM-DD) */
2976
+ SYSTEM_DATE: string;
2977
+ /** 当前使用的模型名称 */
2978
+ SYSTEM_CURRENT_MODEL: string;
2979
+ /** 索引签名,允许作为 PlaceholderContext 使用 */
2980
+ [key: string]: any;
2981
+ }
2982
+ /**
2983
+ * BasicAgent 配置选项
2984
+ *
2985
+ * 所有参数都是可选的,默认会自动同步加载配置文件
2986
+ */
2987
+ interface BasicAgentConfig {
2988
+ /** LLM 客户端(可选,不传则自动同步加载配置创建) */
2989
+ llm?: LLMClient;
2990
+ /** 配置文件名(可选,默认 'default') */
2991
+ configName?: string;
2992
+ /** Agent 显示名称(可选) */
2993
+ name?: string;
2994
+ /** 系统提示词(可选,后续可通过 setPrompt() 设置) */
2995
+ systemMessage?: string;
2996
+ /** MCP 配置:传字符串时加载指定配置;传 false 时禁用自动加载;不传时若 .agentdev/mcps 存在则自动加载全部 */
2997
+ mcpServer?: string | false;
2998
+ /** MCP 运行时上下文(可选,如 GitHub Token) */
2999
+ mcpContext?: Record<string, unknown>;
3000
+ /** 自动扫描 MCP 时排除的 serverId 列表 */
3001
+ excludeMcpServers?: string[];
3002
+ /** 自定义工具集(可选,默认使用 Feature 提供的工具) */
3003
+ tools?: Tool[];
3004
+ /** Skills 目录(可选,默认使用 .agentdev/skills) */
3005
+ skillsDir?: string;
3006
+ }
3007
+ /**
3008
+ * 基础 Agent 类
3009
+ *
3010
+ * 集成常用 Feature 和系统环境信息,开箱即用
3011
+ * 构造函数不传任何参数时,会自动同步加载配置文件创建 LLM
3012
+ */
3013
+ declare class BasicAgent extends AgentBase {
3014
+ protected _systemContext: SystemContext$1;
3015
+ protected _mcpServer?: string | false;
3016
+ protected _mcpContext?: Record<string, unknown>;
3017
+ protected _config?: AgentConfigFile;
3018
+ protected _skillsDir?: string;
3019
+ protected _mcpFeature?: MCPFeature;
3020
+ /**
3021
+ * 构造函数
3022
+ *
3023
+ * @param config 基础配置(全部可选,不传则使用默认配置)
3024
+ */
3025
+ constructor(config?: BasicAgentConfig);
3026
+ /**
3027
+ * 获取系统环境信息
3028
+ */
3029
+ getSystemContext(): SystemContext$1;
3030
+ /**
3031
+ * 获取 MCP 服务器配置
3032
+ */
3033
+ getMcpServer(): string | false | undefined;
3034
+ /**
3035
+ * 获取 MCP 上下文
3036
+ */
3037
+ getMcpContext(): Record<string, unknown> | undefined;
3038
+ }
3039
+
3040
+ /**
3041
+ * ExplorerAgent - 代码探索者 Agent
3042
+ *
3043
+ * 专注于代码库探索和理解的轻量级 Agent
3044
+ * 仅配备 read、list、bash 三个核心工具
3045
+ * 适用于代码审查、结构分析、文档生成等场景
3046
+ */
3047
+
3048
+ /**
3049
+ * 系统环境信息上下文
3050
+ */
3051
+ interface SystemContext {
3052
+ /** 当前工作目录 */
3053
+ SYSTEM_WORKING_DIR: string;
3054
+ /** 是否是 Git 仓库 */
3055
+ SYSTEM_IS_GIT_REPOSITORY: boolean;
3056
+ /** 操作系统平台 */
3057
+ SYSTEM_PLATFORM: NodeJS.Platform;
3058
+ /** 当前日期 (YYYY-MM-DD) */
3059
+ SYSTEM_DATE: string;
3060
+ /** 当前使用的模型名称 */
3061
+ SYSTEM_CURRENT_MODEL: string;
3062
+ /** 索引签名,允许作为 PlaceholderContext 使用 */
3063
+ [key: string]: any;
3064
+ }
3065
+ /**
3066
+ * ExplorerAgent 配置选项
3067
+ *
3068
+ * 所有参数都是可选的,默认会自动同步加载配置文件
3069
+ */
3070
+ interface ExplorerAgentConfig {
3071
+ /** LLM 客户端(可选,不传则自动同步加载配置创建) */
3072
+ llm?: LLMClient;
3073
+ /** 配置文件名(可选,默认 'default') */
3074
+ configName?: string;
3075
+ /** Agent 显示名称(可选) */
3076
+ name?: string;
3077
+ /** 系统提示词(可选,默认使用 explorer.md) */
3078
+ systemMessage?: string;
3079
+ /** Skills 目录(可选,默认使用 .agentdev/skills) */
3080
+ skillsDir?: string;
3081
+ }
3082
+ /**
3083
+ * 代码探索者 Agent
3084
+ *
3085
+ * 轻量级代码探索 Agent,专注于:
3086
+ * - 代码库结构分析
3087
+ * - 代码审查和理解
3088
+ * - 文档生成
3089
+ * - 依赖关系梳理
3090
+ *
3091
+ * 构造函数不传任何参数时,会自动同步加载配置文件创建 LLM
3092
+ */
3093
+ declare class ExplorerAgent extends AgentBase {
3094
+ protected _systemContext: SystemContext;
3095
+ protected _config?: AgentConfigFile;
3096
+ protected _skillsDir?: string;
3097
+ /**
3098
+ * 构造函数
3099
+ *
3100
+ * @param config 探索者配置(全部可选,不传则使用默认配置)
3101
+ */
3102
+ constructor(config?: ExplorerAgentConfig);
3103
+ /**
3104
+ * Agent 初始化钩子
3105
+ * 配置系统提示词,禁用写入和编辑工具(只读模式)
3106
+ */
3107
+ protected onInitiate(): Promise<void>;
3108
+ /**
3109
+ * 获取系统环境信息
3110
+ */
3111
+ getSystemContext(): SystemContext;
3112
+ }
3113
+
3114
+ /**
3115
+ * 消息创建工具
3116
+ * 简单的工厂函数,直观易懂
3117
+ */
3118
+
3119
+ /**
3120
+ * 创建消息
3121
+ */
3122
+ declare function createMessage(role: MessageRole, content: string, toolCalls?: ToolCall[], reasoning?: string): Message;
3123
+ /**
3124
+ * 创建系统消息
3125
+ */
3126
+ declare function system(content: string): Message;
3127
+ /**
3128
+ * 创建用户消息
3129
+ */
3130
+ declare function user(content: string): Message;
3131
+ /**
3132
+ * 创建助手消息
3133
+ */
3134
+ declare function assistant(content: string, toolCalls?: ToolCall[], reasoning?: string): Message;
3135
+ /**
3136
+ * 创建工具返回消息
3137
+ */
3138
+ declare function toolResult(toolCallId: string, content: string): Message;
3139
+
3140
+ type AnthropicTextBlock = {
3141
+ type: 'text';
3142
+ text: string;
3143
+ cache_control?: {
3144
+ type: 'ephemeral';
3145
+ };
3146
+ };
3147
+ type AnthropicThinkingBlock = {
3148
+ type: 'thinking';
3149
+ thinking: string;
3150
+ signature: string;
3151
+ };
3152
+ type AnthropicToolResultBlock = {
3153
+ type: 'tool_result';
3154
+ tool_use_id: string;
3155
+ content: string;
3156
+ is_error?: boolean;
3157
+ };
3158
+ type AnthropicToolUseBlock = {
3159
+ type: 'tool_use';
3160
+ id: string;
3161
+ name: string;
3162
+ input?: unknown;
3163
+ };
3164
+ type AnthropicContentBlock = AnthropicTextBlock | AnthropicThinkingBlock | AnthropicToolResultBlock | AnthropicToolUseBlock;
3165
+ interface AnthropicRequestMessage {
3166
+ role: 'user' | 'assistant';
3167
+ content: string | AnthropicContentBlock[];
3168
+ }
3169
+ interface AnthropicToolDef {
3170
+ name: string;
3171
+ description: string;
3172
+ input_schema: Record<string, unknown>;
3173
+ }
3174
+ interface CompiledAnthropicRequest {
3175
+ system?: AnthropicTextBlock[];
3176
+ messages: AnthropicRequestMessage[];
3177
+ tools?: AnthropicToolDef[];
3178
+ }
3179
+ declare class AnthropicLLM implements LLMClient {
3180
+ private readonly apiKey;
3181
+ private readonly modelName;
3182
+ private readonly baseUrl;
3183
+ private readonly maxTokens;
3184
+ private readonly thinkingBudgetTokens?;
3185
+ private readonly thinkingKeepTurns;
3186
+ constructor(apiKey: string, modelName?: string, baseUrl?: string, maxTokens?: number, thinkingBudgetTokens?: number | undefined, thinkingKeepTurns?: number);
3187
+ chat(messages: Message[], tools: Tool[]): Promise<LLMResponse>;
3188
+ }
3189
+ declare function compileContextForAnthropic(messages: Message[], tools: Tool[]): CompiledAnthropicRequest;
3190
+ declare function createAnthropicLLM(config: AgentConfigFile): AnthropicLLM;
3191
+ declare function createAnthropicLLM(modelConfig: ModelConfig): AnthropicLLM;
3192
+ declare function createAnthropicLLM(apiKey: string, modelName: string, baseUrl?: string): AnthropicLLM;
3193
+
3194
+ /**
3195
+ * OpenAI LLM 适配器
3196
+ * 实现 LLMClient 接口
3197
+ */
3198
+
3199
+ declare class OpenAILLM implements LLMClient {
3200
+ private client;
3201
+ private modelName;
3202
+ private maxTokens?;
3203
+ private providerOptions?;
3204
+ constructor(apiKey: string, modelName?: string, baseUrl?: string, maxTokens?: number, providerOptions?: Record<string, unknown>);
3205
+ /**
3206
+ * 聊天 - 核心方法(内部使用流式处理)
3207
+ */
3208
+ chat(messages: Message[], tools: Tool[]): Promise<LLMResponse>;
3209
+ }
3210
+
3211
+ /**
3212
+ * 从配置创建 OpenAI LLM 实例
3213
+ *
3214
+ * @example
3215
+ * // 方式1:传入配置文件对象(推荐)
3216
+ * const llm = createOpenAILLM(config);
3217
+ *
3218
+ * @example
3219
+ * // 方式2:传入模型配置
3220
+ * const llm = createOpenAILLM(config.defaultModel);
3221
+ *
3222
+ * @example
3223
+ * // 方式3:单独传参
3224
+ * const llm = createOpenAILLM(apiKey, 'gpt-4o', baseUrl);
3225
+ *
3226
+ * @example
3227
+ * // 方式4:自定义配置
3228
+ * const llm = createOpenAILLM({ apiKey: 'xxx', model: 'gpt-4o' });
3229
+ */
3230
+ declare function createOpenAILLM(config: AgentConfigFile): OpenAILLM;
3231
+ declare function createOpenAILLM(modelConfig: ModelConfig): OpenAILLM;
3232
+ declare function createOpenAILLM(apiKey: string, modelName: string, baseUrl?: string): OpenAILLM;
3233
+
3234
+ declare function createLLM(config: AgentConfigFile): LLMClient;
3235
+ declare function createLLM(modelConfig: ModelConfig): LLMClient;
3236
+ declare function createLLM(apiKey: string, modelName: string, provider?: string, baseUrl?: string): LLMClient;
3237
+
3238
+ /**
3239
+ * Viewer Worker - 在独立进程中运行 HTTP 服务器
3240
+ * 支持多 Agent 调试,共享单端口
3241
+ * 支持通过 UDS(Unix Domain Socket)或 Windows Named Pipe 接收来自多进程的连接
3242
+ */
3243
+
3244
+ declare class ViewerWorker {
3245
+ private port;
3246
+ private openBrowser;
3247
+ private server;
3248
+ private udsPath;
3249
+ private udsServer?;
3250
+ private udsClients;
3251
+ private agentSessions;
3252
+ private currentAgentId;
3253
+ private featureTemplateMap;
3254
+ private readonly debuggerMcp;
3255
+ private readonly MAX_MESSAGES;
3256
+ private readonly MAX_BYTES;
3257
+ private readonly MAX_LOGS;
3258
+ constructor(port: number, openBrowser?: boolean, udsPath?: string);
3259
+ start(): Promise<void>;
3260
+ /**
3261
+ * 停止服务器
3262
+ */
3263
+ stop(): Promise<void>;
3264
+ /**
3265
+ * 启动 UDS 服务器
3266
+ */
3267
+ private startUDSServer;
3268
+ /**
3269
+ * 处理 UDS 消息(复用现有处理方法)
3270
+ */
3271
+ private handleUDSMessage;
3272
+ private handleRequest;
3273
+ /**
3274
+ * 主页 - 带多 Agent 切换器
3275
+ */
3276
+ private handleIndex;
3277
+ /**
3278
+ * API 端点路由
3279
+ */
3280
+ private handleAPI;
3281
+ /**
3282
+ * GET /api/agents - 获取所有 Agent
3283
+ */
3284
+ private handleGetAgents;
3285
+ /**
3286
+ * GET /api/agents/current - 获取当前 Agent
3287
+ */
3288
+ private handleGetCurrentAgent;
3289
+ /**
3290
+ * PUT /api/agents/current - 切换当前 Agent
3291
+ */
3292
+ handleSetCurrentAgentHttp(req: IncomingMessage, res: ServerResponse): void;
3293
+ /**
3294
+ * GET /api/templates/feature - 获取 Feature 模板映射
3295
+ */
3296
+ handleGetFeatureTemplates(req: IncomingMessage, res: ServerResponse): void;
3297
+ /**
3298
+ * 将模板文件路径转换为 HTTP URL
3299
+ * 支持多种来源:
3300
+ * 1. 独立 npm 包 node_modules/@scope/package/dist/templates/xxx.render.js
3301
+ * 2. npm 包 node_modules/agentdev/dist/features/xxx/templates/xxx.render.js
3302
+ * 3. npm workspace 符号链接(路径是真实物理路径,但需要转换为 node_modules 路径)
3303
+ * 4. 项目内 dist/features/xxx/templates/xxx.render.js
3304
+ * 5. 项目内 src/features/xxx/templates/xxx.render.ts
3305
+ * 6. 用户自定义路径
3306
+ */
3307
+ private templatePathToUrl;
3308
+ /**
3309
+ * 解析 npm workspace 符号链接
3310
+ * 当 Feature 来自 npm workspace 时,import.meta.url 返回的是符号链接的真实物理路径
3311
+ * 需要检查 node_modules 目录中的符号链接来确定包名
3312
+ */
3313
+ private npmWorkspaceCache;
3314
+ private resolveNpmWorkspacePackage;
3315
+ /**
3316
+ * GET /api/agents/:id/messages - 获取指定 Agent 的消息
3317
+ */
3318
+ private handleGetAgentMessages;
3319
+ /**
3320
+ * GET /api/agents/:id/tools - 获取指定 Agent 的工具
3321
+ */
3322
+ private handleGetAgentTools;
3323
+ private handleGetAgentHooks;
3324
+ private handleGetAgentOverview;
3325
+ /**
3326
+ * GET /api/agents/:id/notification - 获取指定 Agent 的通知状态
3327
+ */
3328
+ private handleGetAgentNotification;
3329
+ private handleGetLogs;
3330
+ private handleGetMCPInfo;
3331
+ /**
3332
+ * GET /api/agents/:id/connection - 获取指定 Agent 的真实连接状态
3333
+ */
3334
+ private handleGetAgentConnection;
3335
+ /**
3336
+ * DELETE /api/agents/:id - 删除已断开的 Agent 会话
3337
+ */
3338
+ private handleDeleteAgent;
3339
+ /**
3340
+ * 获取输入请求列表
3341
+ */
3342
+ private handleGetInputRequests;
3343
+ /**
3344
+ * 提交用户输入
3345
+ */
3346
+ private handlePostInput;
3347
+ /**
3348
+ * 获取或创建会话
3349
+ */
3350
+ getOrCreateSession(agentId: string, name: string): AgentSession;
3351
+ /**
3352
+ * 更新会话活跃时间
3353
+ */
3354
+ updateSessionActivity(agentId: string): void;
3355
+ private isSessionConnected;
3356
+ /**
3357
+ * 应用内存限制
3358
+ */
3359
+ enforceMemoryLimits(session: AgentSession): void;
3360
+ /**
3361
+ * 处理注册 Agent
3362
+ */
3363
+ handleRegisterAgent(msg: any, clientId?: string): void;
3364
+ handleUpdateAgentInspector(msg: any): void;
3365
+ handleUpdateAgentOverview(msg: {
3366
+ agentId: string;
3367
+ overview: AgentOverviewSnapshot;
3368
+ }): void;
3369
+ /**
3370
+ * 清空 Feature 模板映射(当 Agent 断开连接时调用)
3371
+ */
3372
+ private clearFeatureTemplates;
3373
+ /**
3374
+ * 处理推送消息(带去重优化)
3375
+ *
3376
+ * 只有在消息真正变化时才更新会话并触发前端更新
3377
+ */
3378
+ handlePushMessages(msg: any): void;
3379
+ private createEmptyOverview;
3380
+ /**
3381
+ * 检查消息是否发生变化
3382
+ */
3383
+ private hasMessagesChanged;
3384
+ /**
3385
+ * 获取最后一条消息的签名(用于变化检测)
3386
+ *
3387
+ * 使用消息的 role、content 和 toolCalls 生成签名
3388
+ */
3389
+ private getLastMessageSignature;
3390
+ /**
3391
+ * 处理注册工具
3392
+ */
3393
+ handleRegisterTools(msg: any): void;
3394
+ /**
3395
+ * 处理切换当前 Agent(IPC 消息)
3396
+ */
3397
+ handleSetCurrentAgent(msg: any): void;
3398
+ /**
3399
+ * 处理注销 Agent
3400
+ */
3401
+ handleUnregisterAgent(msg: any): void;
3402
+ /**
3403
+ * 处理停止
3404
+ */
3405
+ handleStop(): void;
3406
+ /**
3407
+ * 处理推送通知
3408
+ */
3409
+ handlePushNotification(msg: any): void;
3410
+ private normalizeLogEntry;
3411
+ private withSessionLogContext;
3412
+ private parseNumberParam;
3413
+ private listAgentSummaries;
3414
+ private getAgentDetails;
3415
+ private queryLogs;
3416
+ private handleMCP;
3417
+ /**
3418
+ * 处理用户输入请求
3419
+ */
3420
+ handleRequestInput(msg: any): void;
3421
+ /**
3422
+ * 处理静态工具渲染文件
3423
+ * 直接返回已编译的 .js 文件内容
3424
+ * 路径规则:/tools/{category}/{filename}.js → dist/tools/{category}/{filename}.render.js
3425
+ *
3426
+ * 支持从多个位置查找:
3427
+ * 1. 项目根目录 dist/tools/
3428
+ * 2. npm 包 node_modules/agentdev/dist/tools/
3429
+ */
3430
+ handleStaticToolFile(req: IncomingMessage, res: ServerResponse, url: string): void;
3431
+ /**
3432
+ * 尝试从多个路径读取文件
3433
+ */
3434
+ private tryReadFile;
3435
+ /**
3436
+ * 处理统一的 Feature 模板路由(新格式)
3437
+ * URL 格式: /template/{packageName}/{templateName}.render.js
3438
+ *
3439
+ * 统一支持三种来源:
3440
+ * 1. 框架内置 Feature:/template/agentdev/visual/capture.render.js
3441
+ * 映射到: node_modules/agentdev/dist/features/visual/templates/capture.render.js
3442
+ * 或: dist/features/visual/templates/capture.render.js(开发模式)
3443
+ *
3444
+ * 2. 外部 npm 包:/template/@agentdev/shell-feature/bash.render.js
3445
+ * 映射到: node_modules/@agentdev/shell-feature/dist/templates/bash.render.js
3446
+ *
3447
+ * 3. 用户本地 Feature:/template/my-project/visual/capture.render.js
3448
+ * 映射到: dist/templates/capture.render.js
3449
+ * 或: dist/features/visual/templates/capture.render.js
3450
+ */
3451
+ handleUnifiedTemplate(req: IncomingMessage, res: ServerResponse, url: string): void;
3452
+ /**
3453
+ * 处理 Feature 渲染模板文件
3454
+ * 解析路径: /features/shell/trash-delete.render.js
3455
+ *
3456
+ * 支持从多个位置查找:
3457
+ * 1. 项目根目录 dist/features/{feature}/templates/
3458
+ * 2. 项目根目录 src/features/{feature}/templates/
3459
+ * 3. npm 包 node_modules/agentdev/dist/features/{feature}/templates/
3460
+ *
3461
+ * 支持扩展名映射:
3462
+ * - .js → 同时尝试 .js 和 .ts
3463
+ */
3464
+ handleFeatureTemplate(req: IncomingMessage, res: ServerResponse, url: string): void;
3465
+ /**
3466
+ * 处理 npm 包中的 Feature 模板
3467
+ * 支持两种路径格式:
3468
+ * 1. 独立包: /npm/@agentdev/shell-feature/templates/bash.render.js
3469
+ * 映射到: node_modules/@agentdev/shell-feature/dist/templates/bash.render.js
3470
+ * 2. 框架包: /npm/agentdev/features/shell/bash.render.js
3471
+ * 映射到: node_modules/agentdev/dist/features/shell/templates/bash.render.js
3472
+ */
3473
+ handleNpmFeatureTemplate(req: IncomingMessage, res: ServerResponse, url: string): void;
3474
+ private getHtml;
3475
+ }
3476
+
3477
+ /**
3478
+ * 占位符解析器
3479
+ * 使用正则表达式实现占位符替换
3480
+ */
3481
+
3482
+ /**
3483
+ * 占位符解析器
3484
+ */
3485
+ declare class PlaceholderResolver {
3486
+ private static PATTERNS;
3487
+ /**
3488
+ * 解析模板中的占位符
3489
+ * @param template 模板内容
3490
+ * @param context 变量上下文
3491
+ * @returns 解析后的内容
3492
+ */
3493
+ static resolve(template: string, context?: PlaceholderContext): string;
3494
+ /**
3495
+ * 处理循环渲染 {{#each}}...{{/each}}
3496
+ * 格式:{{#each}}arrayName
3497
+ * ...template...
3498
+ * {{/each}}
3499
+ * 在循环内可使用数组元素的字段(如 {{name}}, {{description}})或 {{this}} 引用整个对象
3500
+ */
3501
+ private static processEach;
3502
+ /**
3503
+ * 处理条件渲染 {{#if}}...{{/if}}
3504
+ * 条件格式:{{#if}}varName{{/if}} - 只有当 varName 为真时才显示内容
3505
+ */
3506
+ private static processConditionals;
3507
+ /**
3508
+ * 获取嵌套对象的值
3509
+ * 支持点号分隔的路径,如 "user.name"
3510
+ */
3511
+ private static getNestedValue;
3512
+ /**
3513
+ * 获取模板中使用的变量列表
3514
+ */
3515
+ static extractVariables(template: string): string[];
3516
+ /**
3517
+ * 验证上下文是否包含所需变量
3518
+ * @returns 缺失的变量数组
3519
+ */
3520
+ static validate(template: string, context: PlaceholderContext): string[];
3521
+ }
3522
+
3523
+ /**
3524
+ * 数据源注册系统
3525
+ *
3526
+ * 提供通用的列表数据渲染能力,Feature 可以注册自定义数据源
3527
+ * 然后在 TemplateComposer 中使用 `{ dataSourceName: 'template' }` 语法
3528
+ *
3529
+ * @example
3530
+ * ```typescript
3531
+ * // 注册数据源
3532
+ * DataSourceRegistry.register({
3533
+ * name: 'tasks',
3534
+ * getData: async () => [{ id: 1, title: 'Task 1', priority: 'high' }],
3535
+ * renderItem: (item, template, ctx) => {
3536
+ * return PlaceholderResolver.resolve(template, { ...ctx, ...item });
3537
+ * },
3538
+ * });
3539
+ *
3540
+ * // 在模板中使用
3541
+ * composer.add({ tasks: '- {{title}} ({{priority}})' });
3542
+ * ```
3543
+ */
3544
+
3545
+ /**
3546
+ * 数据源渲染器接口
3547
+ */
3548
+ interface DataSourceRenderer<T = any> {
3549
+ /** 数据源唯一标识 */
3550
+ name: string;
3551
+ /**
3552
+ * 获取数据列表
3553
+ * @param context 渲染上下文
3554
+ * @returns 数据数组(可以是异步的)
3555
+ */
3556
+ getData(context: PlaceholderContext): Promise<T[]> | T[];
3557
+ /**
3558
+ * 渲染单个数据项
3559
+ * @param item 数据项
3560
+ * @param template 模板字符串
3561
+ * @param context 渲染上下文
3562
+ * @returns 渲染后的字符串
3563
+ */
3564
+ renderItem(item: T, template: string, context: PlaceholderContext): string;
3565
+ /**
3566
+ * 可选:判断是否启用该数据源
3567
+ * @param context 渲染上下文
3568
+ * @returns 是否启用(默认 true)
3569
+ */
3570
+ isEnabled?(context: PlaceholderContext): boolean;
3571
+ }
3572
+ /**
3573
+ * 数据源注册中心
3574
+ */
3575
+ declare class DataSourceRegistry {
3576
+ private static sources;
3577
+ /**
3578
+ * 注册数据源
3579
+ */
3580
+ static register(renderer: DataSourceRenderer): void;
3581
+ /**
3582
+ * 注销数据源
3583
+ */
3584
+ static unregister(name: string): boolean;
3585
+ /**
3586
+ * 获取数据源
3587
+ */
3588
+ static get(name: string): DataSourceRenderer | undefined;
3589
+ /**
3590
+ * 检查数据源是否存在
3591
+ */
3592
+ static has(name: string): boolean;
3593
+ /**
3594
+ * 获取所有已注册的数据源名称
3595
+ */
3596
+ static names(): string[];
3597
+ /**
3598
+ * 渲染数据源
3599
+ * @param name 数据源名称
3600
+ * @param template 模板字符串
3601
+ * @param context 渲染上下文
3602
+ * @returns 渲染后的字符串
3603
+ */
3604
+ static render(name: string, template: string, context?: PlaceholderContext): Promise<string>;
3605
+ /**
3606
+ * 清空所有数据源(主要用于测试)
3607
+ */
3608
+ static clear(): void;
3609
+ }
3610
+ /**
3611
+ * 创建列表渲染器的工厂函数
3612
+ * 简化常见数据源的注册
3613
+ *
3614
+ * @example
3615
+ * ```typescript
3616
+ * DataSourceRegistry.register(createListRenderer({
3617
+ * name: 'tasks',
3618
+ * getData: (ctx) => ctx.tasks as Task[],
3619
+ * // 默认 renderItem 会将 item 合并到 context 中
3620
+ * }));
3621
+ * ```
3622
+ */
3623
+ declare function createListRenderer<T = any>(config: Omit<DataSourceRenderer<T>, 'renderItem'> & {
3624
+ /** 自定义渲染函数(可选) */
3625
+ renderItem?: DataSourceRenderer<T>['renderItem'];
3626
+ /** 是否合并 item 到 context(默认 true) */
3627
+ mergeItem?: boolean;
3628
+ }): DataSourceRenderer<T>;
3629
+
3630
+ /**
3631
+ * Agent Skills 加载器
3632
+ * 扫描目录,解析 SKILL.md 文件
3633
+ */
3634
+
3635
+ /**
3636
+ * 发现并加载指定目录下的所有 skills
3637
+ * @param options Skills 配置选项
3638
+ * @returns Skill 元数据列表
3639
+ */
3640
+ declare function discover(options?: SkillsOptions): Promise<SkillMetadata[]>;
3641
+
3642
+ /**
3643
+ * MCP Tool Adapter - 适配器模式实现
3644
+ *
3645
+ * 将 MCP 工具适配为现有 Tool 接口,保持架构一致性
3646
+ */
3647
+
3648
+ /**
3649
+ * 注册工具的简化接口
3650
+ * 用于适配器包装
3651
+ */
3652
+ interface RegisteredToolLike {
3653
+ name: string;
3654
+ description?: string;
3655
+ inputSchema?: any;
3656
+ outputSchema?: any;
3657
+ annotations?: any;
3658
+ handler?: (args: any, context?: any) => Promise<any> | any;
3659
+ enabled?: boolean;
3660
+ }
3661
+ /**
3662
+ * MCP 工具适配器配置
3663
+ */
3664
+ interface MCPToolAdapterConfig {
3665
+ /** MCP 服务器名称 */
3666
+ serverName: string;
3667
+ /** 是否为只读工具 */
3668
+ readOnly?: boolean;
3669
+ /** 渲染模板覆盖 */
3670
+ render?: {
3671
+ call?: string;
3672
+ result?: string;
3673
+ };
3674
+ }
3675
+ /**
3676
+ * MCP 工具适配器
3677
+ *
3678
+ * 将 MCP RegisteredTool 适配为 Agent 的 Tool 接口
3679
+ * 负责格式转换和生命周期管理
3680
+ */
3681
+ declare class MCPToolAdapter implements Tool {
3682
+ private registeredTool;
3683
+ private config;
3684
+ readonly name: string;
3685
+ readonly description: string;
3686
+ readonly parameters?: Record<string, any>;
3687
+ readonly render?: {
3688
+ call?: string;
3689
+ result?: string;
3690
+ };
3691
+ constructor(registeredTool: RegisteredToolLike, config: MCPToolAdapterConfig);
3692
+ /**
3693
+ * 执行 MCP 工具
3694
+ */
3695
+ execute(args: any, context?: any): Promise<any>;
3696
+ /**
3697
+ * 格式化 MCP 工具结果
3698
+ */
3699
+ private formatResult;
3700
+ /**
3701
+ * 格式化错误
3702
+ */
3703
+ private formatError;
3704
+ /**
3705
+ * 从 RegisteredToolLike 提取参数定义
3706
+ *
3707
+ * MCP 工具的 inputSchema 已经是 JSON Schema 格式
3708
+ * 直接返回,不需要转换
3709
+ */
3710
+ private extractParameters;
3711
+ }
3712
+ /**
3713
+ * 批量创建 MCP 工具适配器
3714
+ */
3715
+ declare function createMCPToolAdapters(registeredTools: RegisteredToolLike[], serverName: string, config?: Omit<MCPToolAdapterConfig, 'serverName'>): Tool[];
3716
+
3717
+ interface MCPDiscoveredTool {
3718
+ name: string;
3719
+ description?: string;
3720
+ inputSchema?: any;
3721
+ }
3722
+ interface MCPToolCreationOptions {
3723
+ name?: string;
3724
+ description?: string;
3725
+ render?: MCPToolAdapterConfig['render'];
3726
+ transformArgs?: (args: Record<string, unknown>, context?: any) => Record<string, unknown>;
3727
+ }
3728
+ interface MCPToolDiscoveryOptions {
3729
+ filter?: (tool: MCPDiscoveredTool) => boolean;
3730
+ mapName?: (tool: MCPDiscoveredTool) => string;
3731
+ render?: MCPToolAdapterConfig['render'];
3732
+ transformArgs?: MCPToolCreationOptions['transformArgs'];
3733
+ }
3734
+ interface MCPDiscoveredToolSet {
3735
+ client: MCPClient;
3736
+ tools: Tool[];
3737
+ }
3738
+ declare function createDefaultMCPToolName(serverId: string, toolName: string): string;
3739
+ declare class MCPClient {
3740
+ readonly serverId: string;
3741
+ private readonly config;
3742
+ private readonly manager;
3743
+ private connected;
3744
+ constructor(serverId: string, config: MCPServerConfig, manager?: MCPConnectionManager);
3745
+ connect(): Promise<void>;
3746
+ listTools(): Promise<MCPDiscoveredTool[]>;
3747
+ callTool(name: string, args: Record<string, unknown>): Promise<any>;
3748
+ getConnectionManager(): MCPConnectionManager;
3749
+ dispose(): Promise<void>;
3750
+ }
3751
+ declare function createMCPTool(client: MCPClient, tool: MCPDiscoveredTool, options?: MCPToolCreationOptions): Tool;
3752
+ declare function createMCPToolsFromClient(client: MCPClient, options?: MCPToolDiscoveryOptions): Promise<Tool[]>;
3753
+ declare function discoverMCPTools(serverId: string, config: MCPServerConfig, options?: MCPToolDiscoveryOptions, manager?: MCPConnectionManager): Promise<MCPDiscoveredToolSet>;
3754
+
3755
+ interface LoadAllMCPConfigsOptions {
3756
+ excludeServers?: string[];
3757
+ }
3758
+ declare function getDefaultMCPConfigDir(rootDir?: string): string;
3759
+ declare function loadMCPConfigFromInput(input: string, rootDir?: string): MCPConfig | undefined;
3760
+ declare function loadAllMCPConfigs(rootDir?: string, options?: LoadAllMCPConfigsOptions): MCPConfig | undefined;
3761
+
3762
+ interface MCPToolPatch {
3763
+ enabled?: boolean;
3764
+ name?: string;
3765
+ description?: string;
3766
+ render?: MCPToolAdapterConfig['render'];
3767
+ transformArgs?: MCPToolCreationOptions['transformArgs'];
3768
+ }
3769
+ interface MCPToolManagementOptions {
3770
+ include?: string[];
3771
+ exclude?: string[];
3772
+ disable?: string[];
3773
+ rename?: Record<string, string>;
3774
+ describe?: Record<string, string>;
3775
+ render?: MCPToolAdapterConfig['render'];
3776
+ toolRender?: Record<string, MCPToolAdapterConfig['render']>;
3777
+ mapName?: (tool: MCPDiscoveredTool, client: MCPClient) => string;
3778
+ transformArgs?: MCPToolCreationOptions['transformArgs'];
3779
+ transform?: (tool: MCPDiscoveredTool, client: MCPClient) => MCPToolPatch | false | null | undefined;
3780
+ }
3781
+ interface MCPConfigMountOptions {
3782
+ manager?: MCPConnectionManager;
3783
+ clients?: Map<string, MCPClient>;
3784
+ getServerOptions?: (serverId: string, serverConfig: MCPServerConfig) => MCPToolManagementOptions | undefined;
3785
+ onError?: (serverId: string, error: unknown) => void;
3786
+ }
3787
+ interface MCPMountedToolSet {
3788
+ client: MCPClient;
3789
+ tools: Tool[];
3790
+ }
3791
+ interface MCPMountedConfigResult {
3792
+ tools: Tool[];
3793
+ clients: Map<string, MCPClient>;
3794
+ }
3795
+ declare function createManagedMCPToolsFromClient(client: MCPClient, options?: MCPToolManagementOptions): Promise<Tool[]>;
3796
+ declare function discoverManagedMCPTools(serverId: string, config: MCPServerConfig, options?: MCPToolManagementOptions, manager?: MCPConnectionManager): Promise<MCPMountedToolSet>;
3797
+ declare function mountMCPToolsFromConfig(config: MCPConfig, options?: MCPConfigMountOptions): Promise<MCPMountedConfigResult>;
3798
+
3799
+ /**
3800
+ * MCP 工具渲染模板
3801
+ *
3802
+ * 定义 MCP 工具在 DebugHub 中的显示样式
3803
+ */
3804
+ /**
3805
+ * MCP 工具渲染模板
3806
+ */
3807
+ declare const MCP_RENDER_TEMPLATES: {
3808
+ /**
3809
+ * MCP 工具调用显示
3810
+ */
3811
+ readonly 'mcp-tool': {
3812
+ readonly call: (args: any) => string;
3813
+ readonly result: (data: any, success?: boolean) => string;
3814
+ };
3815
+ /**
3816
+ * MCP 结果 (简化版)
3817
+ */
3818
+ readonly 'mcp-result': {
3819
+ readonly call: () => string;
3820
+ readonly result: (data: any, success?: boolean) => string;
3821
+ };
3822
+ };
3823
+ /**
3824
+ * 获取 MCP 渲染模板
3825
+ */
3826
+ declare function getMCPRenderTemplate(toolName: string): string;
3827
+ /**
3828
+ * 渲染 MCP 工具调用
3829
+ */
3830
+ declare function renderMCPToolCall(serverName: string, toolName: string, args: Record<string, any>): string;
3831
+ /**
3832
+ * 渲染 MCP 工具结果
3833
+ */
3834
+ declare function renderMCPToolResult(result: any, success?: boolean): string;
3835
+
3836
+ export { AgentBase as Agent, type AgentConfig, type AgentConfigFile, type AgentFeature, type AgentInfo, type AgentInitiateContext, AgentPool, type AgentSession, type AgentSessionSnapshot, AnthropicLLM, BasicAgent, type BasicAgentConfig, type CacheStats, CallStart, type CallStartContext, Context, type ContextInjector, type ContextMiddleware, DataSourceRegistry, type DataSourceRenderer, type DebugCapabilities, DebugHub, type DebugHubIPCMessage, ExampleFeature, type ExampleFeatureConfig, type ExampleFeatureRuntimeState, type ExampleFeatureSnapshot, ExplorerAgent, type ExplorerAgentConfig, type SystemContext as ExplorerSystemContext, type FeatureContext, type FeatureInitContext, type FeatureStateSnapshot, FileSessionStore, type HookResult, type InlineRenderTemplate, type LLMClient, type LLMResponse, type LoadAllMCPConfigsOptions, MCPClient, type MCPClientConfig, type MCPConfig, type MCPConfigMountOptions, type MCPConnectionInfo, MCPConnectionManager, MCPConnectionState, type MCPDiscoveredTool, type MCPDiscoveredToolSet, MCPFeature, type MCPFeatureOptions, type MCPHTTPConfig, type MCPMountedConfigResult, type MCPMountedToolSet, type MCPSSEConfig, type MCPServerConfig, type MCPSstdioConfig, type MCPStatistics, MCPToolAdapter, type MCPToolAdapterConfig, type MCPToolCreationOptions, type MCPToolDiscoveryOptions, type MCPToolManagementOptions, type MCPToolPatch, type MCPToolResult, MCP_RENDER_TEMPLATES, type Message, type MessageRole, type ModelConfig, OpenAILLM, OpencodeBasicFeature, type PackageInfo, type PlaceholderContext, PlaceholderResolver, type SessionStore, SkillFeature, type SkillFeatureConfig, type SkillMetadata, type SkillsOptions, SubAgentFeature, type SystemContext$1 as SystemContext, type TaskStatus, TemplateComposer, TemplateError, TemplateLoader, type TemplateLoaderOptions, type TemplateResult, type TemplateSource, TodoFeature, type TodoFeatureConfig, type TodoTask, type TodoTaskSummary, type Tool, type ToolCall, type ToolContext, type ToolContextValue, type ToolMetadata, ToolRegistry, type ToolRenderConfig, type ToolResult, UserInputFeature, type UserInputFeatureConfig, ViewerWorker, assistant, compileContextForAnthropic, createAnthropicLLM, createDefaultMCPToolName, createLLM, createListRenderer, createMCPTool, createMCPToolAdapters, createMCPToolsFromClient, createManagedMCPToolsFromClient, createMessage, createOpenAILLM, createTool, discover, discoverMCPTools, discoverManagedMCPTools, getClawRuntimeUrl, getDebugCapabilities, getDefaultMCPConfigDir, getDefaultSessionStore, getDefaultUDSPath, getMCPRenderTemplate, getPackageInfoFromSource, listConfigs, loadAllMCPConfigs, loadConfig, loadConfigSync, loadMCPConfigFromInput, mountMCPToolsFromConfig, renderMCPToolCall, renderMCPToolResult, resolveDebugTransportMode, system, toolResult, user };