@ai-setting/roy-agent-core 1.5.17-beta.1 → 1.5.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/env/index.js +20 -8
  2. package/dist/env/log-trace/index.js +1 -1
  3. package/dist/env/prompt/index.js +1 -1
  4. package/dist/env/workflow/engine/index.js +1 -1
  5. package/dist/env/workflow/index.js +2 -2
  6. package/dist/index.js +6 -7
  7. package/dist/shared/@ai-setting/{roy-agent-core-xq8hhqb8.js → roy-agent-core-4wjywp3c.js} +4 -2
  8. package/dist/shared/@ai-setting/roy-agent-core-8jxva565.js +19 -0
  9. package/dist/shared/@ai-setting/roy-agent-core-avq1x4t7.js +84 -0
  10. package/dist/shared/@ai-setting/{roy-agent-core-gq20wsgv.js → roy-agent-core-ffb9fq4v.js} +23 -2
  11. package/dist/shared/@ai-setting/{roy-agent-core-93zfb3r1.js → roy-agent-core-mrcxzpbg.js} +1 -1
  12. package/dist/shared/@ai-setting/{roy-agent-core-rhmtwnw1.js → roy-agent-core-pw7cv1px.js} +1 -1
  13. package/dist/shared/@ai-setting/{roy-agent-core-gbqcyegm.js → roy-agent-core-rccptwv0.js} +512 -673
  14. package/dist/shared/@ai-setting/{roy-agent-core-wrcy0h6z.js → roy-agent-core-ty94k28r.js} +1 -1
  15. package/package.json +8 -29
  16. package/dist/config/index.d.ts +0 -1250
  17. package/dist/env/agent/index.d.ts +0 -2279
  18. package/dist/env/commands/index.d.ts +0 -1131
  19. package/dist/env/debug/formatters/index.d.ts +0 -236
  20. package/dist/env/debug/index.d.ts +0 -1652
  21. package/dist/env/hook/index.d.ts +0 -279
  22. package/dist/env/index.d.ts +0 -3481
  23. package/dist/env/llm/index.d.ts +0 -1760
  24. package/dist/env/log-trace/index.d.ts +0 -1574
  25. package/dist/env/mcp/index.d.ts +0 -1331
  26. package/dist/env/mcp/tool/index.d.ts +0 -183
  27. package/dist/env/memory/built-in/index.d.ts +0 -232
  28. package/dist/env/memory/index.d.ts +0 -1799
  29. package/dist/env/memory/plugin/index.d.ts +0 -747
  30. package/dist/env/prompt/index.d.ts +0 -1164
  31. package/dist/env/session/index.d.ts +0 -1908
  32. package/dist/env/session/storage/index.d.ts +0 -564
  33. package/dist/env/skill/index.d.ts +0 -1266
  34. package/dist/env/skill/tool/index.d.ts +0 -193
  35. package/dist/env/task/delegate/index.d.ts +0 -1612
  36. package/dist/env/task/events/index.d.ts +0 -171
  37. package/dist/env/task/hooks/index.d.ts +0 -624
  38. package/dist/env/task/index.d.ts +0 -1553
  39. package/dist/env/task/plugins/index.d.ts +0 -466
  40. package/dist/env/task/storage/index.d.ts +0 -241
  41. package/dist/env/task/tools/index.d.ts +0 -1485
  42. package/dist/env/task/tools/operation/index.d.ts +0 -1484
  43. package/dist/env/tool/built-in/index.d.ts +0 -218
  44. package/dist/env/tool/index.d.ts +0 -1396
  45. package/dist/env/workflow/decorators/index.d.ts +0 -2161
  46. package/dist/env/workflow/engine/index.d.ts +0 -3453
  47. package/dist/env/workflow/index.d.ts +0 -3546
  48. package/dist/env/workflow/nodes/index.d.ts +0 -2092
  49. package/dist/env/workflow/service/index.d.ts +0 -227
  50. package/dist/env/workflow/storage/index.d.ts +0 -165
  51. package/dist/env/workflow/tools/index.d.ts +0 -416
  52. package/dist/env/workflow/types/index.d.ts +0 -2255
  53. package/dist/env/workflow/utils/index.d.ts +0 -2031
  54. package/dist/index.d.ts +0 -7858
@@ -1,2092 +0,0 @@
1
- /**
2
- * @fileoverview Hook 系统统一类型定义
3
- *
4
- * 提供所有 Component 使用的统一 Hook 接口
5
- */
6
- /**
7
- * Hook 执行阶段
8
- */
9
- type HookPhase = "before" | "after" | "error";
10
- /**
11
- * Hook 元信息
12
- */
13
- interface HookMeta {
14
- /** Hook 唯一名称 */
15
- name: string;
16
- /** 执行优先级,默认 0,数值越小越先执行 */
17
- priority?: number;
18
- /** 描述 */
19
- description?: string;
20
- }
21
- /**
22
- * 统一 Hook 上下文
23
- *
24
- * 泛型参数 T 表示该 Component 的上下文数据类型
25
- */
26
- interface HookContext<T = unknown> {
27
- /** 当前组件信息 */
28
- component: {
29
- /** 组件名称 */
30
- name: string;
31
- /** 组件版本 */
32
- version: string;
33
- };
34
- /** 上下文数据(Component 特定) */
35
- data: T;
36
- /** 元数据(可用于传递额外信息) */
37
- metadata: Record<string, unknown>;
38
- /** 执行阶段 */
39
- phase: HookPhase;
40
- /** 关联的 hook 点名称 */
41
- hookPoint: string;
42
- }
43
- /**
44
- * 统一 Hook 接口
45
- *
46
- * 所有 Component 的 Hook 都应实现此接口
47
- */
48
- interface Hook<T = unknown> extends HookMeta {
49
- /** 执行 Hook
50
- * @param ctx 上下文
51
- */
52
- execute(ctx: HookContext<T>): void | Promise<void>;
53
- }
54
- /**
55
- * Hook 函数类型(便捷别名)
56
- */
57
- type HookFn<T = unknown> = (ctx: HookContext<T>) => void | Promise<void>;
58
- /**
59
- * Hook 干预动作类型
60
- */
61
- type HookActionType = "stop" | "retry" | "compress" | "extract_memory" | "inject_message" | "skip_tool" | "custom";
62
- /**
63
- * Hook 干预动作
64
- */
65
- interface HookAction {
66
- /** 动作类型 */
67
- type: HookActionType;
68
- /** 动作参数 */
69
- params?: Record<string, unknown>;
70
- /** 动作描述 */
71
- description?: string;
72
- }
73
- /**
74
- * Hook 执行结果
75
- */
76
- interface HookResult {
77
- /** 是否被停止 */
78
- stopped?: boolean;
79
- /** 干预动作(如果有) */
80
- action?: HookAction;
81
- /** 执行结果数据 */
82
- results?: unknown[];
83
- }
84
- /**
85
- * HookManager 配置
86
- */
87
- interface HookManagerOptions {
88
- /** 组件名称(用于上下文) */
89
- componentName?: string;
90
- /** 组件版本(用于上下文) */
91
- componentVersion?: string;
92
- /** 默认优先级 */
93
- defaultPriority?: number;
94
- }
95
- /**
96
- * HookManager
97
- *
98
- * 统一管理 Component 的 Hook
99
- *
100
- * @example
101
- * ```typescript
102
- * const manager = new HookManager<MyContext>();
103
- *
104
- * // 注册 Hook
105
- * manager.register("before-action", {
106
- * name: "my-hook",
107
- * priority: 10,
108
- * execute: async (ctx) => { /* ... *\/ }
109
- * });
110
- *
111
- * // 执行 Hooks
112
- * await manager.execute("before-action", data);
113
- * ```
114
- */
115
- declare class HookManager<T = unknown> {
116
- private _hooks;
117
- private componentName;
118
- private componentVersion;
119
- private defaultPriority;
120
- constructor(options?: HookManagerOptions);
121
- /**
122
- * 注册 Hook 到指定 hook 点
123
- */
124
- register(hookPoint: string, hook: Hook<T>): void;
125
- /**
126
- * 注册多个 Hook
127
- */
128
- registerMany(hookPoint: string, hooks: Hook<T>[]): void;
129
- /**
130
- * 按名称取消注册 Hook
131
- * @returns 是否成功取消注册
132
- */
133
- unregister(hookPoint: string, name: string): boolean;
134
- /**
135
- * 取消注册所有指定 hook 点的 Hook
136
- */
137
- unregisterAll(hookPoint: string): void;
138
- /**
139
- * 执行指定 hook 点的所有 Hook
140
- */
141
- execute(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
142
- /**
143
- * 执行指定 hook 点的所有 Hook 并收集返回值
144
- */
145
- executeAndCollect<R>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<R[]>;
146
- /**
147
- * 获取指定 hook 点的 Hook 数量
148
- */
149
- count(hookPoint: string): number;
150
- /**
151
- * 清空所有 Hook
152
- */
153
- clear(): void;
154
- /**
155
- * 获取所有已注册的 hook 点
156
- */
157
- getHookPoints(): string[];
158
- /**
159
- * 检查 hook 点是否有任何 Hook
160
- */
161
- hasHooks(hookPoint: string): boolean;
162
- /**
163
- * 设置组件信息
164
- */
165
- setComponentInfo(name: string, version: string): void;
166
- /**
167
- * 获取所有注册的 hooks(只读副本)
168
- */
169
- get hooks(): ReadonlyMap<string, Hook<T>[]>;
170
- /**
171
- * 执行 Hook 并支持干预机制
172
- *
173
- * 如果任何一个 Hook 返回 { stop: true },执行会停止
174
- * Hook 可以通过返回 HookResult 来执行干预动作
175
- *
176
- * @param hookPoint Hook 点
177
- * @param data 数据
178
- * @param metadata 元数据
179
- * @returns 执行结果
180
- */
181
- executeWithIntervention(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<HookResult>;
182
- /**
183
- * 获取或创建 hook 列表
184
- */
185
- private getOrCreateHooks;
186
- /**
187
- * 按优先级排序 Hook
188
- *
189
- * 优先级相同时保持原顺序(稳定排序)
190
- */
191
- private sortHooks;
192
- /**
193
- * 创建 Hook 上下文
194
- */
195
- private createContext;
196
- /**
197
- * 安全执行 Hook(错误隔离)
198
- */
199
- private safeExecute;
200
- /**
201
- * 安全执行 Hook 并返回结果
202
- */
203
- private safeExecuteAndReturn;
204
- }
205
- import { z as z5 } from "zod";
206
- import { z } from "zod";
207
- declare const WorkflowEventSchema: unknown;
208
- type WorkflowEvent = z.infer<typeof WorkflowEventSchema>;
209
- type EventHandler = (event: WorkflowEvent) => void | Promise<void>;
210
- /**
211
- * EventBus for workflow events.
212
- * Custom event bus implementation with support for wildcard subscriptions.
213
- */
214
- declare class EventBus {
215
- private handlers;
216
- private wildcardHandlers;
217
- constructor();
218
- /**
219
- * Subscribe to a specific event type.
220
- * @returns Unsubscribe function
221
- */
222
- on(eventType: string, handler: EventHandler): () => void;
223
- /**
224
- * Subscribe to an event type only once (auto-unsubscribe after first call).
225
- * @returns Unsubscribe function
226
- */
227
- once(eventType: string, handler: EventHandler): () => void;
228
- /**
229
- * Unsubscribe from an event type.
230
- */
231
- off(eventType: string, handler: EventHandler): void;
232
- /**
233
- * Subscribe to all events (wildcard subscription).
234
- * @returns Unsubscribe function
235
- */
236
- onAny(handler: EventHandler): () => void;
237
- /**
238
- * Publish an event to all subscribers.
239
- * Handler errors are caught and do not crash the bus.
240
- *
241
- * @param event - The event to publish
242
- * @param waitForHandlers - If true, waits for all async handlers to complete (default: false)
243
- */
244
- publish(event: WorkflowEvent, waitForHandlers?: boolean): Promise<void>;
245
- /**
246
- * Execute a handler safely, catching any errors.
247
- */
248
- private executeHandler;
249
- /**
250
- * Clear all subscriptions.
251
- */
252
- clear(): void;
253
- /**
254
- * Get statistics about the event bus.
255
- */
256
- getStats(): {
257
- eventTypes: number;
258
- wildcardHandlers: number;
259
- totalHandlers: number;
260
- };
261
- }
262
- import { ZodType as ZodType3, ZodTypeDef as ZodTypeDef2 } from "zod";
263
- /**
264
- * @fileoverview Environment types and interfaces
265
- *
266
- * 定义 Environment 的核心类型,包括:
267
- * - Environment 配置
268
- * - EnvEvent 事件类型
269
- */
270
- /**
271
- * Environment Config
272
- */
273
- interface EnvironmentConfig {
274
- /** 环境名称 */
275
- name: string;
276
- /** 环境版本 */
277
- version: string;
278
- /** 是否启用 */
279
- enabled: boolean;
280
- }
281
- /**
282
- * EnvEvent 元信息
283
- */
284
- interface EnvEventMetadata {
285
- /** 触发事件的 session ID */
286
- trigger_session_id?: string;
287
- /** 触发事件的 agent ID */
288
- trigger_agent_id?: string;
289
- /** Agent 名称 */
290
- trigger_agent_name?: string;
291
- /** 环境名称 */
292
- env_name?: string;
293
- /** 事件来源 */
294
- source?: string;
295
- /** 其他元数据 */
296
- [key: string]: unknown;
297
- }
298
- /**
299
- * EnvEvent
300
- *
301
- * 统一的事件机制,用于:
302
- * - Stream 事件(stream.start, stream.text, stream.completed 等)
303
- * - 工具调用事件(tool.call, tool.result 等)
304
- * - 会话事件(session.created, session.updated 等)
305
- * - Agent 事件(agent.thinking, agent.acting 等)
306
- */
307
- interface EnvEvent<T = unknown> {
308
- /** 事件 ID */
309
- id: string;
310
- /** 事件类型 */
311
- type: string;
312
- /** 时间戳 */
313
- timestamp: number;
314
- /** 元信息 */
315
- metadata: EnvEventMetadata;
316
- /** 事件负载 */
317
- payload: T;
318
- }
319
- /**
320
- * EnvEvent Handler
321
- */
322
- type EnvEventHandler = (event: EnvEvent) => void | Promise<void>;
323
- /**
324
- * EnvEvent 创建参数(部分属性,可选)
325
- *
326
- * 用于 pushEnvEvent 方法,允许传入部分属性,自动补全必填字段
327
- */
328
- interface EnvEventInput {
329
- /** 事件类型(必填) */
330
- type: string;
331
- /** 事件 ID(可选,自动生成) */
332
- id?: string;
333
- /** 时间戳(可选,自动生成) */
334
- timestamp?: number;
335
- /** 元信息(可选,自动创建) */
336
- metadata?: EnvEventMetadata;
337
- /** 事件负载(可选) */
338
- payload?: unknown;
339
- }
340
- /**
341
- * Action 类型
342
- */
343
- interface Action {
344
- /** Action 类型 */
345
- type: string;
346
- /** Action 参数 */
347
- params?: Record<string, unknown>;
348
- }
349
- /**
350
- * Tool Result
351
- */
352
- interface ToolResult {
353
- /** 是否成功 */
354
- success: boolean;
355
- /** 输出内容 */
356
- output: string | Record<string, unknown>;
357
- /** 错误信息 */
358
- error?: string;
359
- }
360
- /**
361
- * Context
362
- */
363
- interface Context {
364
- /** 会话 ID */
365
- sessionId?: string;
366
- /** 用户 ID */
367
- userId?: string;
368
- /** 工作目录 */
369
- workdir?: string;
370
- /** 中断信号 */
371
- abort?: AbortSignal;
372
- /** 元数据 */
373
- metadata?: Record<string, unknown>;
374
- }
375
- type AbortSignalType = AbortSignal;
376
- /**
377
- * Agent 执行上下文
378
- */
379
- interface AgentContext {
380
- /** 会话 ID */
381
- sessionId?: string;
382
- /** 消息 ID */
383
- messageId?: string;
384
- /** 中断信号 */
385
- abort?: AbortSignalType;
386
- /** 额外的上下文信息(会添加到 system prompt) */
387
- additionInfo?: string;
388
- /** 元数据 */
389
- metadata?: Record<string, unknown>;
390
- /** Agent 类型(用于选择 Behavior Spec) */
391
- agentType?: string;
392
- /** 使用的模型 */
393
- model?: string;
394
- /** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
395
- allowedTools?: string[];
396
- /** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
397
- deniedTools?: string[];
398
- /** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
399
- filterHistory?: boolean;
400
- }
401
- import { ZodType as ZodType2, ZodTypeDef } from "zod";
402
- /**
403
- * ConfigSource 类型
404
- */
405
- type ConfigSourceType = "memory" | "file" | "env" | "remote";
406
- /**
407
- * SourceRegistration - Source 注册配置
408
- */
409
- interface SourceRegistration {
410
- /** Source 类型 */
411
- type: ConfigSourceType;
412
- /** 相对路径(file 类型使用,基于 XDG_DATA_HOME) */
413
- relativePath?: string;
414
- /** 环境变量前缀(env 类型使用) */
415
- envPrefix?: string;
416
- /** 优先级,默认值:memory=0, file=10, env=20 */
417
- priority?: number;
418
- /** 是否可选(file 类型使用,文件不存在时不报错) */
419
- optional?: boolean;
420
- /** 是否启用文件监听(file 类型使用,默认 true) */
421
- watch?: boolean;
422
- }
423
- /**
424
- * KeyRegistration - 配置 Key 注册
425
- */
426
- interface KeyRegistration {
427
- /** 配置 Key(支持点号嵌套,如 "llm.provider") */
428
- key: string;
429
- /** 优先使用的 Source 列表(按优先级从低到高) */
430
- sources: ConfigSourceType[];
431
- /** 自定义优先级(覆盖默认优先级) */
432
- priority?: number;
433
- /** 默认值 */
434
- default?: unknown;
435
- }
436
- /**
437
- * ComponentRegistration - Component 注册配置
438
- */
439
- interface ComponentRegistration {
440
- /** Component 名称 */
441
- name: string;
442
- /** 声明需要的 Source */
443
- sources: SourceRegistration[];
444
- /** 声明需要的配置 Key */
445
- keys: KeyRegistration[];
446
- /** 配置 Schema(用于验证,可选) */
447
- schema?: ZodType2<unknown, ZodTypeDef, unknown>;
448
- /** 默认值 */
449
- defaults?: Record<string, unknown>;
450
- }
451
- /**
452
- * ConfigSource 接口
453
- */
454
- interface ConfigSource {
455
- readonly name: ConfigSourceType;
456
- readonly priority: number;
457
- read(key: string): unknown | undefined;
458
- write?(key: string, value: unknown): boolean;
459
- delete?(key: string): boolean;
460
- list(): Array<{
461
- key: string;
462
- value: unknown;
463
- }>;
464
- watch?(callback: (event: ConfigChangeEvent) => void): () => void;
465
- }
466
- /**
467
- * Config 变更事件
468
- */
469
- interface ConfigChangeEvent {
470
- type: "change" | "add" | "delete";
471
- key: string;
472
- oldValue: unknown;
473
- newValue: unknown;
474
- source: ConfigSourceType;
475
- timestamp: number;
476
- }
477
- /**
478
- * ConfigComponent 配置
479
- */
480
- interface ConfigComponentOptions {
481
- /** 持久化文件路径 */
482
- persistFile?: string;
483
- /** 防抖延迟(ms) */
484
- debounceMs?: number;
485
- /** 最大批量大小 */
486
- maxBatchSize?: number;
487
- }
488
- /**
489
- * ConfigComponent
490
- */
491
- declare class ConfigComponent extends BaseComponent {
492
- readonly name = "config";
493
- readonly version = "1.0.0";
494
- private memorySource;
495
- private sources;
496
- private componentSchemas;
497
- private componentPaths;
498
- private watchers;
499
- /** Source watch unsubscribe 函数 */
500
- private sourceUnwatchFns;
501
- private persistQueue;
502
- private persistFile?;
503
- /** Key 注册表:key -> KeyRegistration */
504
- private keyRegistry;
505
- /** Component 注册表:name -> ComponentRegistration */
506
- private componentRegistrations;
507
- /** 协议解析器 */
508
- private protocolResolver?;
509
- /** XDG_DATA_HOME 缓存(用于测试注入) */
510
- private __xdgDataHome?;
511
- /** Source 注册配置(延迟创建) */
512
- private pendingSources;
513
- /** Source 唯一标识缓存:type:relativePath -> true */
514
- private sourceKeys;
515
- /**
516
- * 获取 XDG_DATA_HOME(动态获取,支持运行时覆盖)
517
- */
518
- getXdgDataHome(): string;
519
- /**
520
- * 设置 XDG_DATA_HOME(用于测试)
521
- */
522
- setXdgDataHome(path: string): void;
523
- constructor(options?: ConfigComponentOptions);
524
- /**
525
- * 注册 Component Schema
526
- */
527
- register(schema: ComponentSchema): void;
528
- /**
529
- * 注销 Component
530
- */
531
- unregister(name: string): boolean;
532
- /**
533
- * 检查是否已注册
534
- */
535
- isRegistered(name: string): boolean;
536
- /**
537
- * 列出所有注册的 Component
538
- */
539
- listComponents(): string[];
540
- /**
541
- * 获取配置值(支持 xxx.yyy.zzz 嵌套访问)
542
- * 支持两种模式:
543
- * 1. 完整 key:直接查找,如 "component.key" -> 读取 "component.key"
544
- * 2. 嵌套对象:查找 component 对象后从中获取属性,如 "component.nested.deep"
545
- * -> 先找 "component.nested",再获取其 "deep" 属性
546
- */
547
- get(key: string): unknown;
548
- /**
549
- * 批量获取
550
- */
551
- getMany(keys: string[]): Record<string, unknown>;
552
- /**
553
- * 设置配置值(内存级别 + 异步持久化)
554
- */
555
- set(key: string, value: unknown): Promise<void>;
556
- /**
557
- * 批量设置
558
- */
559
- setMany(config: Record<string, unknown>): Promise<void>;
560
- /**
561
- * 获取 Component 的路径
562
- */
563
- getPath(component: string, subPath?: string): string;
564
- /**
565
- * 手动持久化
566
- */
567
- save(key?: string): Promise<void>;
568
- /**
569
- * 重置到默认值
570
- */
571
- reset(key: string): Promise<void>;
572
- /**
573
- * 监听配置变更
574
- */
575
- watch(pattern: string, callback: ComponentWatchCallback): () => void;
576
- /**
577
- * 添加配置源
578
- */
579
- addSource(source: ConfigSource): void;
580
- /**
581
- * 获取 Source 唯一标识
582
- */
583
- private getSourceKey;
584
- /**
585
- * 移除配置源
586
- */
587
- removeSource(name: ConfigSourceType): boolean;
588
- /**
589
- * 关闭所有配置源的 watcher(用于优雅退出)
590
- */
591
- unwatchAll(): void;
592
- /**
593
- * 获取配置源列表
594
- */
595
- getSources(): ConfigSource[];
596
- private getNestedValue;
597
- private notifyWatchers;
598
- private persistToFile;
599
- /**
600
- * 注册配置 Source
601
- *
602
- * Source 会在首次 load() 时被创建
603
- *
604
- * @example
605
- * config.registerSource({ type: "file", relativePath: "llm-config.jsonc" });
606
- * config.registerSource({ type: "env", envPrefix: "LLM" });
607
- */
608
- registerSource(registration: SourceRegistration): void;
609
- /**
610
- * 创建 Source 实例
611
- */
612
- private createSource;
613
- /**
614
- * 确保所有待创建的 Source 已被创建
615
- */
616
- private ensureSourcesCreated;
617
- /**
618
- * 注册配置 Key
619
- *
620
- * @example
621
- * config.registerKeys([
622
- * { key: "llm.provider", sources: ["file", "memory"], default: "openai" },
623
- * { key: "llm.model", sources: ["file"] },
624
- * ]);
625
- */
626
- registerKeys(keys: KeyRegistration[]): void;
627
- /**
628
- * 注册 Component(一次性注册 Source 和 Keys)
629
- *
630
- * @example
631
- * config.registerComponent({
632
- * name: "llm",
633
- * sources: [
634
- * { type: "file", relativePath: "llm-config.jsonc" },
635
- * { type: "env", envPrefix: "LLM" },
636
- * ],
637
- * keys: [
638
- * { key: "llm.provider", sources: ["file", "env", "memory"] },
639
- * ],
640
- * });
641
- */
642
- registerComponent(registration: ComponentRegistration): void;
643
- /**
644
- * 按需加载配置
645
- *
646
- * 从注册的 Source 加载已注册 Keys 的配置值到内存中
647
- *
648
- * @param componentName - 可选,指定要加载的 Component 名称
649
- *
650
- * @example
651
- * // 加载所有已注册的 Keys
652
- * await config.load();
653
- *
654
- * // 只加载指定 Component 的 Keys
655
- * await config.load("llm");
656
- */
657
- load(componentName?: string): Promise<void>;
658
- /**
659
- * 获取已注册的 Source 列表
660
- */
661
- getRegisteredSources(): ConfigSource[];
662
- }
663
- /**
664
- * 服务配置接口
665
- */
666
- interface ServiceConfig {
667
- /** 环境配置 */
668
- environment?: {
669
- name?: string;
670
- version?: string;
671
- };
672
- /** 组件配置映射 */
673
- components?: Record<string, ComponentConfigEntry>;
674
- }
675
- /**
676
- * 组件配置项
677
- */
678
- interface ComponentConfigEntry {
679
- /** 配置文件路径(可选) */
680
- configPath?: string;
681
- /** 环境变量前缀(可选) */
682
- envPrefix?: string;
683
- /** 直接配置对象(可选) */
684
- config?: Record<string, unknown>;
685
- /** 是否启用(可选,默认 true) */
686
- enabled?: boolean;
687
- }
688
- /**
689
- * 组件初始化选项(由 generateComponentOptions 生成)
690
- */
691
- interface GeneratedComponentOptions {
692
- /** ConfigComponent 实例 */
693
- configComponent: ConfigComponent;
694
- /** 配置文件路径 */
695
- configPath?: string;
696
- /** 环境变量前缀 */
697
- envPrefix?: string;
698
- /** 直接配置对象 */
699
- config?: Record<string, unknown>;
700
- /** 允许的其他属性 */
701
- [key: string]: unknown;
702
- }
703
- /**
704
- * Environment 接口
705
- *
706
- * 定义 Agent 运行时的核心能力接口。
707
- */
708
- interface Environment {
709
- /** 环境名称 */
710
- readonly name: string;
711
- /** 环境版本 */
712
- readonly version: string;
713
- /** 获取环境配置 */
714
- getConfig(): EnvironmentConfig;
715
- /**
716
- * 注册组件
717
- */
718
- registerComponent(component: Component): void;
719
- /**
720
- * 注销组件
721
- */
722
- unregisterComponent(name: string): void;
723
- /**
724
- * 获取组件
725
- */
726
- getComponent<T extends Component>(name: string): T | undefined;
727
- /**
728
- * 列出所有组件
729
- */
730
- listComponents(): Component[];
731
- /**
732
- * 处理自然语言查询(核心入口)
733
- *
734
- * @param query 用户查询文本
735
- * @param context 执行上下文(可选)
736
- * @returns 完整的文本响应
737
- */
738
- handle_query(query: string, context?: AgentContext): Promise<string>;
739
- /**
740
- * 处理动作
741
- */
742
- handle_action(action: Action, context: Context): Promise<ToolResult>;
743
- /**
744
- * 订阅 EnvEvent(返回取消订阅函数)
745
- */
746
- subscribe(handler: EnvEventHandler): () => void;
747
- /**
748
- * 订阅指定类型事件
749
- */
750
- subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
751
- /**
752
- * 订阅所有事件(通配符)
753
- */
754
- subscribeAll(handler: EnvEventHandler): () => void;
755
- /**
756
- * 推送事件
757
- *
758
- * @param event EnvEvent 或 EnvEventInput(部分属性)
759
- */
760
- pushEnvEvent(event: EnvEvent | EnvEventInput): void;
761
- /**
762
- * 从配置文件加载服务配置
763
- *
764
- * @param configPath 配置文件路径(基于 XDG_DATA_HOME)
765
- * @returns 解析后的服务配置对象
766
- */
767
- loadServiceConfig(configPath: string): Promise<ServiceConfig>;
768
- /**
769
- * 生成组件初始化选项
770
- *
771
- * 根据组件配置项生成可用于初始化的选项对象。
772
- *
773
- * @param componentName 组件名称
774
- * @param configEntry 组件配置项
775
- * @returns 生成的组件初始化选项
776
- */
777
- generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
778
- /**
779
- * 注册组件并用配置初始化
780
- *
781
- * 便捷方法:注册组件并通过 ConfigComponent 初始化。
782
- *
783
- * @param component 要注册的组件实例
784
- * @param configEntry 组件配置项
785
- */
786
- registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
787
- /**
788
- * 从配置文件初始化整个环境
789
- *
790
- * 加载服务配置,注册并初始化所有配置的组件。
791
- *
792
- * @param configPath 配置文件路径(基于 XDG_DATA_HOME)
793
- */
794
- initFromConfig(configPath: string): Promise<void>;
795
- }
796
- /**
797
- * Component 状态
798
- */
799
- type ComponentStatus = "created" | "initializing" | "running" | "stopping" | "stopped" | "error";
800
- /**
801
- * Component 配置
802
- */
803
- interface ComponentConfig {
804
- name: string;
805
- version: string;
806
- enabled: boolean;
807
- options?: Record<string, unknown>;
808
- /**
809
- * Environment 实例(可选)
810
- *
811
- * 推荐在 init 时接收 env 实例,以便:
812
- * - 通过 env.getComponent() 获取其他组件
813
- * - 通过 env.pushEnvEvent() 发布事件
814
- * - 通过 env.handle_query() 处理查询
815
- *
816
- * 如果未提供,部分 Component 仍可正常工作(如测试场景)
817
- *
818
- * @example
819
- * ```typescript
820
- * async onInit(): Promise<void> {
821
- * if (this.env) {
822
- * const configComp = this.env.getComponent("config");
823
- * }
824
- * }
825
- * ```
826
- */
827
- env?: Environment;
828
- }
829
- /**
830
- * Component 路径声明
831
- */
832
- interface ComponentPaths {
833
- base: "config" | "state" | "data" | "cache";
834
- subPath: string;
835
- isDirectory: boolean;
836
- }
837
- /**
838
- * Component Schema(注册配置)
839
- */
840
- interface ComponentSchema {
841
- /** Component 名称 */
842
- name: string;
843
- /** 配置 Schema(Zod) */
844
- schema: ZodType3<unknown, ZodTypeDef2, unknown>;
845
- /** 默认值(从 Schema 提取) */
846
- defaults: Record<string, unknown>;
847
- /** 路径声明 */
848
- paths?: Record<string, ComponentPaths>;
849
- /** 元信息 */
850
- metadata?: {
851
- description?: string;
852
- version?: string;
853
- author?: string;
854
- };
855
- }
856
- /**
857
- * Component 配置变更事件
858
- */
859
- interface ComponentConfigChangeEvent {
860
- /** Component 名称 */
861
- component: string;
862
- /** 变更的配置键 */
863
- key: string;
864
- /** 旧值 */
865
- oldValue: unknown;
866
- /** 新值 */
867
- newValue: unknown;
868
- /** 是否持久化 */
869
- persisted: boolean;
870
- /** 时间戳 */
871
- timestamp: number;
872
- }
873
- /**
874
- * Component 配置监听回调
875
- */
876
- type ComponentWatchCallback = (event: ComponentConfigChangeEvent) => void | Promise<void>;
877
- /**
878
- * Component 基类接口
879
- */
880
- interface Component {
881
- /** Component 名称 */
882
- readonly name: string;
883
- /** Component 版本 */
884
- readonly version: string;
885
- /** 获取状态 */
886
- getStatus(): ComponentStatus;
887
- /** 获取配置 */
888
- getConfig(): ComponentConfig;
889
- /** 初始化 */
890
- init(config: ComponentConfig): Promise<void>;
891
- /** 启动 */
892
- start(): Promise<void>;
893
- /** 停止 */
894
- stop(): Promise<void>;
895
- }
896
- /**
897
- * Component 基类实现
898
- */
899
- declare abstract class BaseComponent implements Component {
900
- abstract readonly name: string;
901
- abstract readonly version: string;
902
- protected _status: ComponentStatus;
903
- protected _enabled: boolean;
904
- protected env: Environment;
905
- /** Hook 管理器 - 子类初始化时由构造函数设置 */
906
- readonly hookManager: HookManager;
907
- constructor();
908
- getStatus(): ComponentStatus;
909
- getConfig(): ComponentConfig;
910
- /**
911
- * 检查 Environment 是否已初始化
912
- */
913
- protected isEnvInitialized(): boolean;
914
- protected setStatus(status: ComponentStatus): void;
915
- /**
916
- * 获取 Environment 实例
917
- */
918
- protected getEnv(): Environment;
919
- init(config?: ComponentConfig): Promise<void>;
920
- start(): Promise<void>;
921
- stop(): Promise<void>;
922
- /**
923
- * 子类可覆盖的钩子方法
924
- */
925
- protected onInit(): Promise<void>;
926
- protected onStart(): Promise<void>;
927
- protected onStop(): Promise<void>;
928
- /**
929
- * 注册 Hook
930
- *
931
- * @param hookPoint Hook 点名称
932
- * @param hook Hook 实例
933
- */
934
- protected registerHook<T = unknown>(hookPoint: string, hook: Hook<T>): void;
935
- /**
936
- * 便捷方法:快速注册 Hook
937
- */
938
- protected addHook<T = unknown>(hookPoint: string, name: string, fn: HookFn<T>, priority?: number): void;
939
- /**
940
- * 便捷方法:按名称取消注册 Hook
941
- */
942
- protected removeHook(hookPoint: string, name: string): boolean;
943
- /**
944
- * 执行 Hook
945
- */
946
- protected executeHooks<T = unknown>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
947
- /**
948
- * 获取 ConfigComponent 实例
949
- *
950
- * 子类可使用此方法获取配置组件,支持热更新
951
- */
952
- protected getConfigComponent(): {
953
- get(key: string): unknown;
954
- } | undefined;
955
- /**
956
- * 动态获取运行时配置值
957
- *
958
- * 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
959
- * 适用于运行时可能变化的配置(如 API Keys、模型参数)
960
- *
961
- * @param key 配置键(支持点号分隔的路径,如 "llm.temperature")
962
- * @param defaultValue 默认值
963
- * @returns 配置值或默认值
964
- *
965
- * @example
966
- * ```typescript
967
- * // 获取 LLM 温度配置(可能支持热更新)
968
- * const temperature = this.getRuntimeConfig("llm.temperature", 0.7);
969
- *
970
- * // 获取 API Key
971
- * const apiKey = this.getRuntimeConfig<string>("llm.providers.openai.apiKey");
972
- * ```
973
- */
974
- protected getRuntimeConfig<T>(key: string, defaultValue: T): T;
975
- }
976
- /**
977
- * Checkpoint type
978
- */
979
- type CheckpointType = "compact" | "manual";
980
- /**
981
- * Checkpoint metadata (stored in Session.metadata)
982
- */
983
- interface CheckpointMeta {
984
- id: string;
985
- messageIndex: number;
986
- title: string;
987
- createdAt: number;
988
- type: CheckpointType;
989
- }
990
- /**
991
- * User Intent type - represents a user's intent extracted from conversation
992
- */
993
- type UserIntent = string;
994
- /**
995
- * Recent message for checkpoint
996
- *
997
- * Stores a simplified version of a message for context preservation
998
- */
999
- interface RecentMessage {
1000
- role: string;
1001
- content: string;
1002
- }
1003
- /**
1004
- * Complete checkpoint information (includes generated content)
1005
- */
1006
- interface SessionCheckpoint extends CheckpointMeta {
1007
- summary: string;
1008
- processKeyPoints: string[];
1009
- currentState: string;
1010
- nextSteps: string[];
1011
- messageCountBefore: number;
1012
- metadata?: Record<string, unknown>;
1013
- /** User intents extracted from the conversation */
1014
- userIntents: UserIntent[];
1015
- /**
1016
- * Recent messages preserved from the compacted conversation
1017
- *
1018
- * Contains the last N turns of user query + assistant text response
1019
- * (excluding tool calls and tool results).
1020
- * This allows the checkpoint to serve as a fresh history context.
1021
- *
1022
- * Format: [user, assistant, user, assistant, ...] from most recent
1023
- */
1024
- recentMessages?: RecentMessage[];
1025
- }
1026
- /**
1027
- * Checkpoints metadata in session
1028
- */
1029
- interface SessionCheckpointsMeta {
1030
- latestCheckpointId?: string;
1031
- checkpoints: CheckpointMeta[];
1032
- }
1033
- /**
1034
- * Session entity
1035
- */
1036
- interface Session {
1037
- id: string;
1038
- title: string;
1039
- directory: string;
1040
- parentID?: string;
1041
- createdAt: number;
1042
- updatedAt: number;
1043
- messageCount: number;
1044
- metadata?: SessionMetadata;
1045
- }
1046
- /**
1047
- * Session metadata
1048
- */
1049
- interface SessionMetadata extends Record<string, unknown> {
1050
- /** Total number of messages in the session */
1051
- messageCount?: number;
1052
- checkpoints?: SessionCheckpointsMeta;
1053
- checkpointDetails?: Record<string, SessionCheckpoint>;
1054
- }
1055
- /**
1056
- * Session message
1057
- */
1058
- interface SessionMessage {
1059
- id: string;
1060
- sessionID: string;
1061
- role: Role;
1062
- content: string;
1063
- timestamp: number;
1064
- parts?: MessagePart[];
1065
- /** Whether the message has been archived (compacted) */
1066
- isArchived?: boolean;
1067
- /** Timestamp when the message was archived */
1068
- archivedAt?: number;
1069
- /** Checkpoint ID this message belongs to */
1070
- checkpointId?: string;
1071
- /** Message metadata (includes checkpoint info if this is a checkpoint message) */
1072
- metadata?: MessageMetadata;
1073
- }
1074
- /**
1075
- * Message metadata
1076
- */
1077
- interface MessageMetadata extends Record<string, unknown> {
1078
- /** 消息类型标识,用于过滤和分类 */
1079
- type?: "tool_call" | "tool_result" | "checkpoint" | "user_intent" | "workflow.node.start" | "workflow.node.interrupt" | "workflow.node.end" | "workflow.node.resume";
1080
- isCheckpoint?: boolean;
1081
- checkpointId?: string;
1082
- checkpointMeta?: SessionCheckpoint;
1083
- /** Workflow node ID (for workflow.node.* messages) */
1084
- workflowNodeId?: string;
1085
- /** Workflow node type (for workflow.node.* messages) */
1086
- workflowNodeType?: string;
1087
- /** Agent session ID (for agent nodes in workflow) */
1088
- agentSessionId?: string;
1089
- /** User response (for workflow.node.resume messages) */
1090
- response?: string;
1091
- /** Success flag (for workflow.node.end messages) */
1092
- success?: boolean;
1093
- }
1094
- /**
1095
- * Message role
1096
- */
1097
- type Role = "user" | "assistant" | "system" | "tool" | "workflow.node.start" | "workflow.node.interrupt" | "workflow.node.end" | "workflow.node.resume";
1098
- /**
1099
- * Message part
1100
- */
1101
- type MessagePart = SessionPart;
1102
- /**
1103
- * Text part - plain text content
1104
- */
1105
- interface TextPart {
1106
- type: "text";
1107
- content: string;
1108
- /** If true, this part was generated by the system (e.g., auto-summary) */
1109
- synthetic?: boolean;
1110
- /** If true, this part should be ignored (e.g., replaced by reasoning) */
1111
- ignored?: boolean;
1112
- }
1113
- /**
1114
- * Tool call part - represents a tool invocation
1115
- */
1116
- interface ToolCallPart {
1117
- type: "tool-call";
1118
- /** AI SDK standard field name */
1119
- toolCallId: string;
1120
- toolName: string;
1121
- /** Tool arguments - can be string (JSON) or object */
1122
- arguments: string | Record<string, unknown>;
1123
- state: "pending" | "running";
1124
- }
1125
- /**
1126
- * Tool result part - represents the result of a tool execution
1127
- */
1128
- interface ToolResultPart {
1129
- type: "tool-result";
1130
- toolCallId: string;
1131
- toolName: string;
1132
- output: string;
1133
- error?: string;
1134
- state: "completed" | "error";
1135
- }
1136
- /**
1137
- * Reasoning part - AI thinking/thought content
1138
- */
1139
- interface ReasoningPart {
1140
- type: "reasoning";
1141
- /** Reasoning content */
1142
- content: string;
1143
- /** Reasoning type (for different models) */
1144
- reasoningType?: "core" | "effort" | "summary";
1145
- /** State */
1146
- state?: "thinking" | "completed";
1147
- /** Whether to collapse by default (like AI SDK default) */
1148
- isCollapsed?: boolean;
1149
- /** Metadata */
1150
- metadata?: {
1151
- tokenCount?: number;
1152
- time?: {
1153
- start: number;
1154
- end?: number;
1155
- };
1156
- };
1157
- }
1158
- /**
1159
- * File part - file attachment
1160
- */
1161
- interface FilePart {
1162
- type: "file";
1163
- mime: string;
1164
- url: string;
1165
- filename?: string;
1166
- }
1167
- /**
1168
- * Checkpoint part - compaction checkpoint marker
1169
- *
1170
- * Represents a checkpoint message in the conversation history.
1171
- * This is stored as a user role message with markdown content summarizing
1172
- * the compacted conversation segment.
1173
- */
1174
- interface CheckpointPart {
1175
- type: "checkpoint";
1176
- /** Checkpoint ID reference */
1177
- checkpointId: string;
1178
- /** Markdown content summarizing the checkpoint */
1179
- content: string;
1180
- /** Title of the checkpoint */
1181
- title?: string;
1182
- /** Process key points */
1183
- processKeyPoints?: string[];
1184
- /** Current state description */
1185
- currentState?: string;
1186
- /** Next steps */
1187
- nextSteps?: string[];
1188
- /** Number of messages that were compacted */
1189
- messageCountBefore?: number;
1190
- /** Creation timestamp */
1191
- createdAt?: number;
1192
- }
1193
- /**
1194
- * Union type for all Session Part types
1195
- */
1196
- type SessionPart = TextPart | ToolCallPart | ToolResultPart | ReasoningPart | FilePart | CheckpointPart | WorkflowNodeStartPart | WorkflowNodeInterruptPart | WorkflowNodeEndPart | WorkflowNodeResumePart;
1197
- /**
1198
- * workflow.node.start 消息 part (对应 tool-call)
1199
- */
1200
- interface WorkflowNodeStartPart {
1201
- type: "workflow-node-start";
1202
- nodeId: string;
1203
- nodeType: string;
1204
- input?: unknown;
1205
- startTime: number;
1206
- /** Agent session ID (only for agent nodes) */
1207
- agentSessionId?: string;
1208
- }
1209
- /**
1210
- * workflow.node.interrupt 消息 part
1211
- */
1212
- interface WorkflowNodeInterruptPart {
1213
- type: "workflow-node-interrupt";
1214
- nodeId: string;
1215
- nodeType: string;
1216
- query: string;
1217
- options?: string[];
1218
- timestamp: number;
1219
- /** Agent session ID (only for agent nodes) */
1220
- agentSessionId?: string;
1221
- }
1222
- /**
1223
- * workflow.node.end 消息 part (对应 tool-result)
1224
- */
1225
- interface WorkflowNodeEndPart {
1226
- type: "workflow-node-end";
1227
- nodeId: string;
1228
- nodeType: string;
1229
- output?: unknown;
1230
- error?: string;
1231
- durationMs: number;
1232
- /** Agent session ID (only for agent nodes) */
1233
- agentSessionId?: string;
1234
- }
1235
- /**
1236
- * workflow.node.resume 消息 part
1237
- */
1238
- interface WorkflowNodeResumePart {
1239
- type: "workflow-node-resume";
1240
- nodeId: string;
1241
- response: string;
1242
- timestamp: number;
1243
- /** Agent session ID (only for agent nodes) */
1244
- agentSessionId?: string;
1245
- }
1246
- /**
1247
- * Options for creating a session
1248
- */
1249
- interface CreateSessionOptions {
1250
- /** Custom session ID (optional, will be generated if not provided) */
1251
- id?: string;
1252
- title?: string;
1253
- directory?: string;
1254
- parentID?: string;
1255
- metadata?: Record<string, unknown>;
1256
- hooks?: SessionHooksConfig;
1257
- }
1258
- /**
1259
- * Options for updating a session
1260
- */
1261
- interface UpdateSessionOptions {
1262
- title?: string;
1263
- metadata?: Record<string, unknown>;
1264
- }
1265
- /**
1266
- * Options for listing sessions
1267
- */
1268
- interface ListSessionsOptions {
1269
- filter?: {
1270
- metadata?: Record<string, unknown>;
1271
- startTime?: number;
1272
- endTime?: number;
1273
- };
1274
- sort?: {
1275
- field: "updatedAt" | "createdAt" | "title";
1276
- order: "asc" | "desc";
1277
- };
1278
- offset?: number;
1279
- limit?: number;
1280
- }
1281
- /**
1282
- * Options for adding a message
1283
- */
1284
- interface AddMessageOptions {
1285
- role: Role;
1286
- content: string;
1287
- parts?: MessagePart[];
1288
- metadata?: MessageMetadata;
1289
- }
1290
- /**
1291
- * Options for compact operation
1292
- */
1293
- interface CompactOptions {
1294
- /** User-provided summary hint for checkpoint generation */
1295
- summary?: string;
1296
- /** User-provided process key points hint */
1297
- processKeyPoints?: string[];
1298
- /** User-provided current state hint */
1299
- currentState?: string;
1300
- /** User-provided next steps hint */
1301
- nextSteps?: string[];
1302
- /** Whether this is auto-triggered compact */
1303
- auto?: boolean;
1304
- /**
1305
- * Scenario hint for guiding checkpoint generation
1306
- *
1307
- * A natural language description that provides context about the current scenario.
1308
- * This helps the SummaryAgent generate more relevant checkpoints based on the specific
1309
- * situation. Examples:
1310
- * - "Task execution in progress: implementing feature X, current working directory is /path/to/project"
1311
- * - "Bug investigation: analyzing crash dump, current hypothesis is memory corruption"
1312
- * - "Code review session: reviewing PR #123, focus on security implications"
1313
- *
1314
- * When provided, this will be prepended to the system prompt to guide the checkpoint
1315
- * generation with scenario-specific emphasis.
1316
- */
1317
- scenarioHint?: string;
1318
- }
1319
- /**
1320
- * Result of compact operation
1321
- */
1322
- interface CompactResult {
1323
- checkpoint: SessionCheckpoint;
1324
- deletedMessageCount: number;
1325
- remainingMessageCount: number;
1326
- checkpointCount: number;
1327
- }
1328
- /**
1329
- * Preview of compact operation
1330
- */
1331
- interface CompactPreview {
1332
- messageCountToCompact: number;
1333
- estimatedCheckpointTokens: number;
1334
- wouldTrigger: boolean;
1335
- }
1336
- /**
1337
- * Options for getting session context
1338
- */
1339
- interface GetContextOptions {
1340
- /** Start from specified checkpoint */
1341
- fromCheckpoint?: string;
1342
- /** Start from latest checkpoint (default: true) */
1343
- fromLatestCheckpoint?: boolean;
1344
- /** Read full history (ignore checkpoints) */
1345
- fullHistory?: boolean;
1346
- /** Message limit */
1347
- messageLimit?: number;
1348
- /** Minimum user messages to include (ensures starting from user message boundary) */
1349
- minUserMessages?: number;
1350
- /** Include checkpoint details */
1351
- includeCheckpoints?: boolean;
1352
- }
1353
- /**
1354
- * Result of getting session context
1355
- */
1356
- interface GetContextResult {
1357
- session: Session;
1358
- checkpoints: SessionCheckpoint[];
1359
- startCheckpoint?: SessionCheckpoint;
1360
- messages: SessionMessage[];
1361
- totalMessageCount: number;
1362
- activeMessageCount: number;
1363
- archivedMessageCount: number;
1364
- estimatedTokens: number;
1365
- }
1366
- /**
1367
- * Session hook callback
1368
- */
1369
- type SessionHookCallback = (context?: any) => Promise<void>;
1370
- /**
1371
- * Session hook definition
1372
- */
1373
- interface SessionHook {
1374
- name: string;
1375
- before?: SessionHookCallback;
1376
- after?: SessionHookCallback;
1377
- }
1378
- /**
1379
- * Session hooks configuration
1380
- */
1381
- interface SessionHooksConfig {
1382
- [key: string]: SessionHook[];
1383
- }
1384
- /**
1385
- * Options for searching messages
1386
- */
1387
- interface SearchMessagesOptions {
1388
- /** Search query (supports AND/OR/NOT syntax) */
1389
- query: string;
1390
- /** Limit search to specific session ID */
1391
- sessionId?: string;
1392
- /** Maximum number of results per session */
1393
- limit?: number;
1394
- /** Maximum total results */
1395
- maxResults?: number;
1396
- /** Only search messages before this timestamp */
1397
- beforeTime?: number;
1398
- /** Only search messages after this timestamp */
1399
- afterTime?: number;
1400
- /** Include archived messages */
1401
- includeArchived?: boolean;
1402
- /** Include context (messages before/after matches) */
1403
- includeContext?: boolean;
1404
- /** Number of context lines before/after */
1405
- contextLines?: number;
1406
- }
1407
- /**
1408
- * A single message match
1409
- */
1410
- interface MessageMatch {
1411
- /** Message ID */
1412
- messageId: string;
1413
- /** Session ID */
1414
- sessionId: string;
1415
- /** Message role */
1416
- role: Role;
1417
- /** Message content */
1418
- content: string;
1419
- /** Message timestamp */
1420
- timestamp: number;
1421
- /** Context before the match (if enabled) */
1422
- contextBefore?: string;
1423
- /** Context after the match (if enabled) */
1424
- contextAfter?: string;
1425
- /** Match score (relevance) */
1426
- score?: number;
1427
- }
1428
- /**
1429
- * Search result aggregated by session
1430
- */
1431
- interface SearchResult {
1432
- /** Session ID */
1433
- sessionId: string;
1434
- /** Session title */
1435
- sessionTitle: string;
1436
- /** Session directory */
1437
- sessionDirectory: string;
1438
- /** Session update timestamp */
1439
- updatedAt: number;
1440
- /** Total message count in session */
1441
- messageCount: number;
1442
- /** Matching messages in this session */
1443
- matches: MessageMatch[];
1444
- }
1445
- /**
1446
- * SessionComponent
1447
- *
1448
- * Manages session lifecycle including:
1449
- * - Session CRUD operations
1450
- * - Message management
1451
- * - Active session tracking
1452
- */
1453
- declare class SessionComponent extends BaseComponent {
1454
- readonly name = "session";
1455
- readonly version = "1.1.0";
1456
- private config?;
1457
- private store?;
1458
- private activeSessionId?;
1459
- private hooksConfig;
1460
- /** ConfigComponent 用于配置管理 */
1461
- private configComponent?;
1462
- /** 配置变更 watcher 清理函数 */
1463
- private configWatcher?;
1464
- /** Summary Agent for checkpoint generation [new] */
1465
- private summaryAgent?;
1466
- /** PromptComponent reference for SummaryAgent */
1467
- private promptComponent?;
1468
- /** LLMComponent reference for SummaryAgent */
1469
- private llmComponent?;
1470
- constructor();
1471
- /**
1472
- * Initialize the component
1473
- *
1474
- * 配置加载优先级(从高到低):
1475
- * 1. Object - 直接传入的 config 对象
1476
- * 2. Env - 环境变量(通过 envPrefix 配置前缀)
1477
- * 3. File - 配置文件(通过 configPath 指定)
1478
- */
1479
- init(config?: ComponentConfig): Promise<void>;
1480
- /**
1481
- * 获取默认 session 数据库路径
1482
- */
1483
- private getDefaultSessionDbPath;
1484
- /**
1485
- * 注册配置到 ConfigComponent
1486
- *
1487
- * 配置加载顺序(优先级从低到高):
1488
- * 1. Defaults - 默认值(最低)
1489
- * 2. FileSource - 从配置文件加载
1490
- * 3. EnvSource - 从环境变量加载
1491
- * 4. config 对象 - 直接传入的配置(最高)
1492
- */
1493
- private registerConfig;
1494
- /**
1495
- * 构建最终配置对象
1496
- */
1497
- private buildConfig;
1498
- /**
1499
- * 将配置对象展平为点号路径
1500
- */
1501
- private flattenConfig;
1502
- /**
1503
- * 注册配置热更新监听
1504
- */
1505
- private registerConfigWatcher;
1506
- /**
1507
- * 处理配置变更
1508
- */
1509
- protected onConfigChange(event: {
1510
- key: string;
1511
- oldValue?: unknown;
1512
- newValue?: unknown;
1513
- }): void;
1514
- /**
1515
- * Start the component
1516
- */
1517
- onStart(): Promise<void>;
1518
- /**
1519
- * Stop the component
1520
- */
1521
- onStop(): Promise<void>;
1522
- /**
1523
- * Create a new session
1524
- */
1525
- create(options?: CreateSessionOptions): Promise<Session>;
1526
- /**
1527
- * Get a session by ID
1528
- */
1529
- get(id: string): Promise<Session | undefined>;
1530
- /**
1531
- * Get a session with full context (for Memory Agent)
1532
- */
1533
- getSession(id: string): Promise<{
1534
- sessionId: string;
1535
- title: string;
1536
- messages: any[];
1537
- } | null>;
1538
- /**
1539
- * Search sessions by query (for Memory Agent)
1540
- *
1541
- * Simple implementation: list all sessions and return them for the agent to filter
1542
- */
1543
- searchSessions(query: string, options?: {
1544
- session_id?: string;
1545
- limit?: number;
1546
- }): Promise<Array<{
1547
- sessionId: string;
1548
- title: string;
1549
- preview: string;
1550
- timestamp: number;
1551
- }>>;
1552
- /**
1553
- * List all sessions
1554
- */
1555
- list(options?: ListSessionsOptions): Promise<Session[]>;
1556
- /**
1557
- * Get total session count
1558
- */
1559
- getCount(): Promise<number>;
1560
- /**
1561
- * Update a session
1562
- */
1563
- update(id: string, updates: UpdateSessionOptions): Promise<boolean>;
1564
- /**
1565
- * Delete a session
1566
- */
1567
- delete(id: string): Promise<boolean>;
1568
- /**
1569
- * Get the current active session
1570
- */
1571
- getActiveSession(): Session | undefined;
1572
- /**
1573
- * Get the active session ID
1574
- */
1575
- getActiveSessionId(): string | undefined;
1576
- /**
1577
- * Set the active session
1578
- */
1579
- setActiveSession(id: string): Promise<boolean>;
1580
- /**
1581
- * Add a message to a session
1582
- */
1583
- addMessage(sessionId: string, message: AddMessageOptions): Promise<string | undefined>;
1584
- /**
1585
- * Get messages from a session
1586
- */
1587
- getMessages(sessionId: string, options?: {
1588
- offset?: number;
1589
- limit?: number;
1590
- }): Promise<SessionMessage[]>;
1591
- /**
1592
- * Get message count for a session
1593
- */
1594
- getMessageCount(sessionId: string, includeArchived?: boolean): Promise<number>;
1595
- /**
1596
- * Get indexes of all messages with the specified role
1597
- * @param sessionId - Session ID
1598
- * @param role - Role to filter by (e.g., "user", "assistant")
1599
- * @returns Array of message indexes (0-indexed, in chronological order)
1600
- */
1601
- getMessageIndexes(sessionId: string, role: string): Promise<number[]>;
1602
- private executeBeforeHooks;
1603
- private executeAfterHooks;
1604
- private generateTitle;
1605
- /**
1606
- * Set components for SummaryAgent
1607
- *
1608
- * Call this after initialization if you need compact functionality
1609
- */
1610
- setSummaryComponents(promptComponent: any, llmComponent: any): void;
1611
- /**
1612
- * 初始化 SummaryAgent(如未初始化)
1613
- */
1614
- private ensureSummaryAgent;
1615
- /**
1616
- * 生成场景化压缩提示 (Compact Hint)
1617
- *
1618
- * 两阶段自动压缩的第一阶段:
1619
- * 根据会话历史生成场景化的压缩提示
1620
- *
1621
- * @param sessionId 会话 ID
1622
- * @returns 生成的场景化提示
1623
- */
1624
- generateCompactHint(sessionId: string): Promise<string>;
1625
- /**
1626
- * Compact a session
1627
- *
1628
- * 1. Get messages from latest checkpoint to current
1629
- * 2. Call Summary Agent to generate checkpoint
1630
- * 3. Save checkpoint and archive messages
1631
- *
1632
- * 支持 scenarioHint 参数,用于指导不同场景下的压缩重点提取
1633
- */
1634
- compact(sessionId: string, options?: CompactOptions): Promise<CompactResult>;
1635
- /**
1636
- * Extract recent messages from the conversation for checkpoint context
1637
- *
1638
- * Extracts the last N turns of user query + assistant text response,
1639
- * excluding tool calls and tool results.
1640
- *
1641
- * @param messages - All messages in the conversation
1642
- * @param turnCount - Number of turns to extract (default: 2)
1643
- * @returns Array of recent messages formatted as { role, content }
1644
- */
1645
- private extractRecentMessages;
1646
- /**
1647
- * Preview compact operation
1648
- */
1649
- previewCompact(sessionId: string): Promise<CompactPreview>;
1650
- /**
1651
- * Get all checkpoints for a session
1652
- */
1653
- getCheckpoints(sessionId: string): Promise<SessionCheckpoint[]>;
1654
- /**
1655
- * Get a specific checkpoint
1656
- */
1657
- getCheckpoint(sessionId: string, checkpointId: string): Promise<SessionCheckpoint | undefined>;
1658
- /**
1659
- * Delete a checkpoint and restore archived messages
1660
- */
1661
- deleteCheckpoint(sessionId: string, checkpointId: string): Promise<boolean>;
1662
- /**
1663
- * Get session context
1664
- *
1665
- * Returns messages starting from the latest checkpoint by default
1666
- */
1667
- getContext(sessionId: string, options?: GetContextOptions): Promise<GetContextResult>;
1668
- /**
1669
- * Check if session needs compaction
1670
- */
1671
- shouldCompact(sessionId: string): Promise<boolean>;
1672
- /**
1673
- * Search messages across sessions
1674
- *
1675
- * Searches all messages matching the query, aggregated by session.
1676
- * Supports SQLite FTS5 for fast full-text search.
1677
- */
1678
- searchMessages(options: SearchMessagesOptions): Promise<SearchResult[]>;
1679
- /**
1680
- * Get latest checkpoint from session
1681
- */
1682
- private getLatestCheckpoint;
1683
- /**
1684
- * Create checkpoint message (user role)
1685
- *
1686
- * Generates a markdown-formatted checkpoint summary as a user message,
1687
- * allowing it to appear in the message list and provide context for
1688
- * subsequent LLM calls.
1689
- */
1690
- private createCheckpointMessage;
1691
- }
1692
- /**
1693
- * 节点执行上下文
1694
- *
1695
- * 扩展后包含:
1696
- * - sessionId: Session ID,用于消息持久化
1697
- * - askUser(): 方法,让节点可以请求用户输入
1698
- */
1699
- interface NodeExecutionContext {
1700
- runId: string;
1701
- sessionId: string;
1702
- workflowName: string;
1703
- nodeId: string;
1704
- input: unknown;
1705
- previousOutputs: Map<string, unknown>;
1706
- nodeOutputs: Map<string, unknown>;
1707
- config: Record<string, unknown>;
1708
- debug: boolean;
1709
- eventBus: EventBus;
1710
- workflowHistory?: Array<{
1711
- role: "user" | "assistant" | "tool";
1712
- content: string;
1713
- toolCallId?: string;
1714
- toolName?: string;
1715
- nodeId?: string;
1716
- }>;
1717
- sessionComponent?: SessionComponent;
1718
- agentSessionId?: string;
1719
- workflowInput?: Record<string, unknown>;
1720
- /**
1721
- * 请求用户输入
1722
- *
1723
- * 调用此方法会抛出 AskUserError,引擎捕获后会暂停 workflow
1724
- *
1725
- * @param query - 向用户询问的问题
1726
- * @throws AskUserError - 总是抛出此异常
1727
- */
1728
- askUser(query: string): never;
1729
- }
1730
- interface NodeExecutionResult {
1731
- success?: boolean;
1732
- output?: any;
1733
- error?: string | Error;
1734
- duration?: number;
1735
- durationMs?: number;
1736
- metadata?: Record<string, unknown>;
1737
- }
1738
- declare const NodeDefinitionSchema: unknown;
1739
- type NodeDefinition = z5.infer<typeof NodeDefinitionSchema>;
1740
- /**
1741
- * Node interface - base interface for all workflow nodes
1742
- */
1743
- interface Node {
1744
- /** Node type identifier */
1745
- readonly type: string;
1746
- /** Node unique identifier */
1747
- readonly id: string;
1748
- /** Execute the node with the given context */
1749
- execute(context: NodeExecutionContext): Promise<NodeExecutionResult>;
1750
- }
1751
- /**
1752
- * Tool Registry interface for looking up tools
1753
- * Supports both the full ToolRegistration and simplified Tool interface
1754
- */
1755
- interface ToolRegistry {
1756
- getTool?(name: string): ToolRegistration2 | undefined;
1757
- getToolByName?(name: string): Tool2 | undefined;
1758
- hasTool?(name: string): boolean;
1759
- }
1760
- /**
1761
- * Tool Registration interface (from ToolComponent)
1762
- */
1763
- interface ToolRegistration2 {
1764
- tool: Tool2;
1765
- enabled: boolean;
1766
- source?: string;
1767
- }
1768
- /**
1769
- * Tool interface for execution
1770
- */
1771
- interface Tool2 {
1772
- name: string;
1773
- execute(input: any, context?: any): Promise<any>;
1774
- }
1775
- /**
1776
- * ToolNode executes a registered Tool with the provided input.
1777
- *
1778
- * Input can contain template strings like {{nodeId.output.path}} that will be
1779
- * resolved from previousOutputs.
1780
- */
1781
- declare class ToolNode implements Node {
1782
- private definition;
1783
- private toolRegistry;
1784
- readonly type = "tool";
1785
- readonly id: string;
1786
- constructor(definition: NodeDefinition, toolRegistry: ToolRegistry);
1787
- execute(context: NodeExecutionContext): Promise<NodeExecutionResult>;
1788
- /**
1789
- * Resolve template references in input values.
1790
- * Templates can be in the format:
1791
- * - {{input.key}} - from workflow input
1792
- * - {{nodeId}} - entire previous node output
1793
- * - {{nodeId.path}} - nested path within previous node output
1794
- * - {{nodes.nodeId}} - entire previous node output (alias)
1795
- * - {{nodes.nodeId.path}} - nested path within previous node output
1796
- * - ${nodeId.output} - dollar-style template (same as {{nodeId.output}})
1797
- *
1798
- * Key behavior for template strings:
1799
- * - If the string is a pure template reference (e.g., "{{nodes.fetch}}"),
1800
- * the resolved value is returned as-is (preserving objects/arrays)
1801
- * - If the string contains text + templates (e.g., "Hello {{name}}"),
1802
- * returns a string with interpolated values
1803
- *
1804
- * @param input - The input object that may contain template strings
1805
- * @param previousOutputs - Map of previous node outputs
1806
- * @param workflowInput - The workflow input parameters
1807
- * @returns The input with template references resolved
1808
- */
1809
- private resolveTemplateReferences;
1810
- /**
1811
- * Check if a string is a pure template reference (starts with {{ and ends with }})
1812
- * @param str - String to check
1813
- * @returns The template content if pure, null otherwise
1814
- */
1815
- private extractPureTemplate;
1816
- /**
1817
- * Check if a string is a dollar-style template reference (starts with ${ and ends with })
1818
- * @param str - String to check
1819
- * @returns The template content if pure, null otherwise
1820
- */
1821
- private extractDollarTemplate;
1822
- /**
1823
- * Resolve a pure template reference and return the value as-is.
1824
- * @param templateContent - Content between {{ and }} or ${ and }
1825
- * @param previousOutputs - Map of previous node outputs
1826
- * @param workflowInput - The workflow input parameters
1827
- * @returns The resolved value (may be object, array, or primitive),
1828
- * or the original template string if unresolved
1829
- */
1830
- private resolvePureTemplate;
1831
- /**
1832
- * Resolve template references in a single string (for mixed text + templates).
1833
- * Supports formats:
1834
- * - {{input.key}} - from workflow input
1835
- * - {{nodeId}} - entire previous node output
1836
- * - {{nodeId.path}} - nested path within previous node output
1837
- * - {{nodes.nodeId}} - entire previous node output (alias)
1838
- * - {{nodes.nodeId.path}} - nested path within previous node output
1839
- * - ${nodeId.output} - dollar-style template
1840
- *
1841
- * Note: Returns string because the input contains text around the template.
1842
- * For pure template references, use resolvePureTemplate instead.
1843
- */
1844
- private resolveStringTemplate;
1845
- /**
1846
- * Resolve a value from previous outputs.
1847
- * @param nodeId - The node ID to look up
1848
- * @param path - Optional dot-notation path within the node output
1849
- * @param previousOutputs - Map of previous node outputs
1850
- */
1851
- private resolvePath;
1852
- /**
1853
- * Get a nested value from an object using dot notation.
1854
- * @param obj - The object to traverse
1855
- * @param path - Dot-notation path (e.g., "metadata.task_id")
1856
- */
1857
- private getNestedValue;
1858
- /**
1859
- * Extract the actual output value from wrapper formats.
1860
- * For strings, removes trailing whitespace (especially newlines from bash commands).
1861
- */
1862
- private extractFromWrapper;
1863
- /**
1864
- * Convert a value to string for template interpolation.
1865
- * @param value - The value to convert
1866
- * @param fallback - Fallback string if value is undefined
1867
- */
1868
- private stringifyValue;
1869
- }
1870
- /**
1871
- * Skill Registry interface for looking up skills
1872
- */
1873
- interface SkillRegistry {
1874
- getSkill(name: string): Skill | undefined;
1875
- hasSkill(name: string): boolean;
1876
- }
1877
- /**
1878
- * Skill interface for invocation
1879
- */
1880
- interface Skill {
1881
- name: string;
1882
- invoke(input: any, context: any): Promise<any>;
1883
- }
1884
- /**
1885
- * SkillNode invokes a registered Skill with the provided input.
1886
- *
1887
- * Input can contain template strings like {{nodeId.output.path}} that will be
1888
- * resolved from previousOutputs.
1889
- */
1890
- declare class SkillNode implements Node {
1891
- private definition;
1892
- private skillRegistry;
1893
- readonly type = "skill";
1894
- readonly id: string;
1895
- constructor(definition: NodeDefinition, skillRegistry: SkillRegistry);
1896
- execute(context: NodeExecutionContext): Promise<NodeExecutionResult>;
1897
- /**
1898
- * Resolve template references in input values.
1899
- * Templates can be in the format:
1900
- * - {{input.key}} - from workflow input
1901
- * - {{nodeId}} - entire previous node output
1902
- * - {{nodeId.path}} - nested path within previous node output
1903
- * - {{nodes.nodeId}} - entire previous node output (alias)
1904
- * - {{nodes.nodeId.path}} - nested path within previous node output
1905
- *
1906
- * Key behavior for template strings:
1907
- * - If the string is a pure template reference (e.g., "{{nodes.fetch}}"),
1908
- * the resolved value is returned as-is (preserving objects/arrays)
1909
- * - If the string contains text + templates (e.g., "Hello {{name}}"),
1910
- * returns a string with interpolated values
1911
- *
1912
- * @param input - The input object that may contain template strings
1913
- * @param previousOutputs - Map of previous node outputs
1914
- * @param workflowInput - The workflow input parameters
1915
- * @returns The input with template references resolved
1916
- */
1917
- private resolveTemplateReferences;
1918
- /**
1919
- * Check if a string is a pure template reference (starts with {{ and ends with }})
1920
- * @param str - String to check
1921
- * @returns The template content if pure, null otherwise
1922
- */
1923
- private extractPureTemplate;
1924
- /**
1925
- * Resolve a pure template reference and return the value as-is.
1926
- * @param templateContent - Content between {{ and }}
1927
- * @param previousOutputs - Map of previous node outputs
1928
- * @param workflowInput - The workflow input parameters
1929
- * @returns The resolved value (may be object, array, or primitive),
1930
- * or the original template string if unresolved
1931
- */
1932
- private resolvePureTemplate;
1933
- /**
1934
- * Resolve template references in a single string (for mixed text + templates).
1935
- * Supports formats:
1936
- * - {{input.key}} - from workflow input
1937
- * - {{nodeId}} - entire previous node output
1938
- * - {{nodeId.path}} - nested path within previous node output
1939
- * - {{nodes.nodeId}} - entire previous node output (alias)
1940
- * - {{nodes.nodeId.path}} - nested path within previous node output
1941
- *
1942
- * Note: Returns string because the input contains text around the template.
1943
- * For pure template references, use resolvePureTemplate instead.
1944
- */
1945
- private resolveStringTemplate;
1946
- /**
1947
- * Resolve a value from previous outputs.
1948
- * @param nodeId - The node ID to look up
1949
- * @param path - Optional dot-notation path within the node output
1950
- * @param previousOutputs - Map of previous node outputs
1951
- */
1952
- private resolvePath;
1953
- /**
1954
- * Extract the actual output value from wrapper formats.
1955
- *
1956
- * Handles:
1957
- * - AgentNode format: { result, metadata } -> returns result
1958
- * - DecoratorNode format: { success, output, ... } -> returns output
1959
- * - Other formats: returns value as-is
1960
- *
1961
- * @param value - The value to extract from
1962
- * @returns The extracted value
1963
- */
1964
- private extractFromWrapper;
1965
- /**
1966
- * Get nested value from an object using dot-notation path.
1967
- *
1968
- * Special handling: If the object has an 'input' key and we're looking for a path that doesn't
1969
- * exist at the top level, check inside the 'input' key.
1970
- * This allows {{input.city}} to work when workflowInput is wrapped as {input: {city: "..."}}
1971
- */
1972
- private getNestedValue;
1973
- /**
1974
- * Convert a value to string for template replacement.
1975
- * - If value is undefined, return the original template
1976
- * - If value is a string, return it directly
1977
- * - If value is null, return 'null'
1978
- * - If value is an object or array, serialize to JSON
1979
- *
1980
- * @param value - The value to stringify
1981
- * @param originalTemplate - The original template string (returned if value is undefined)
1982
- * @returns String representation of the value
1983
- */
1984
- private stringifyValue;
1985
- }
1986
- /**
1987
- * WorkflowRunner interface for running sub-workflows
1988
- */
1989
- interface WorkflowRunner {
1990
- /**
1991
- * Run a workflow by name
1992
- * @param workflowName - Name of the workflow to run
1993
- * @param input - Optional input to pass to the workflow
1994
- * @returns Promise resolving to the workflow run result
1995
- */
1996
- run(workflowName: string, input?: any): Promise<WorkflowRunResult>;
1997
- /**
1998
- * Get the status of a workflow run
1999
- * @param runId - The run ID to check
2000
- * @returns Promise resolving to the run result or null if not found
2001
- */
2002
- getRun(runId: string): Promise<WorkflowRunResult | null>;
2003
- }
2004
- /**
2005
- * Result from a workflow run
2006
- */
2007
- interface WorkflowRunResult {
2008
- /** Unique run ID */
2009
- runId: string;
2010
- /** Final status of the run */
2011
- status: "completed" | "failed" | "stopped";
2012
- /** Output from the workflow (if completed) */
2013
- output?: any;
2014
- /** Error message (if failed or stopped) */
2015
- error?: string;
2016
- }
2017
- /**
2018
- * WorkflowNode executes a nested workflow as a node.
2019
- *
2020
- * This allows one workflow to invoke another workflow as a single node,
2021
- * enabling workflow composition and reusability.
2022
- *
2023
- * Features:
2024
- * - Pass input to sub-workflow (with template resolution)
2025
- * - Wait for completion or fire-and-forget
2026
- * - Handle sub-workflow errors
2027
- * - Track execution duration
2028
- */
2029
- declare class WorkflowNode implements Node {
2030
- private workflowRunner;
2031
- readonly type = "workflow";
2032
- readonly id: string;
2033
- private readonly config;
2034
- constructor(definition: NodeDefinition, workflowRunner: WorkflowRunner);
2035
- execute(context: NodeExecutionContext): Promise<NodeExecutionResult>;
2036
- /**
2037
- * Convert Record<string, NodeExecutionResult> to Map<string, any>
2038
- * for compatibility with resolvePath that expects Map format.
2039
- *
2040
- * In the Record format, the value is NodeExecutionResult (with output field).
2041
- * In the Map format, the value is the raw output directly.
2042
- */
2043
- private convertToMap;
2044
- /**
2045
- * Resolve input template references.
2046
- * Templates are in the format {{nodeId.output.path}}
2047
- *
2048
- * @param input - The input object that may contain template strings
2049
- * @param previousOutputs - Map of previous node outputs (value is raw output)
2050
- * @returns The input with template references resolved
2051
- */
2052
- private resolveInput;
2053
- /**
2054
- * Resolve a value that may contain template references.
2055
- */
2056
- private resolveValue;
2057
- /**
2058
- * Resolve template references in a single string.
2059
- * Supports format: {{nodeId.output.path}}
2060
- */
2061
- private resolveStringTemplate;
2062
- /**
2063
- * Resolve a dot-notation path from previous outputs.
2064
- * First segment is the node ID, rest is the path within that node's output.
2065
- */
2066
- private resolvePath;
2067
- /**
2068
- * Extract the actual output value from wrapper formats.
2069
- *
2070
- * Handles:
2071
- * - AgentNode format: { result, metadata } -> returns result
2072
- * - DecoratorNode format: { success, output, ... } -> returns output
2073
- * - Other formats: returns value as-is
2074
- *
2075
- * @param value - The value to extract from
2076
- * @returns The extracted value
2077
- */
2078
- private extractFromWrapper;
2079
- /**
2080
- * Convert a value to string for template replacement.
2081
- * - If value is undefined, return the original template
2082
- * - If value is a string, return it directly
2083
- * - If value is null, return 'null'
2084
- * - If value is an object or array, serialize to JSON
2085
- *
2086
- * @param value - The value to stringify
2087
- * @param originalTemplate - The original template string (returned if value is undefined)
2088
- * @returns String representation of the value
2089
- */
2090
- private stringifyValue;
2091
- }
2092
- export { WorkflowRunner, WorkflowRunResult, WorkflowNode, ToolRegistry, ToolNode, Tool2 as Tool, SkillRegistry, SkillNode, Skill };