@ai-setting/roy-agent-core 1.5.15-test → 1.5.16-test

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 (141) hide show
  1. package/dist/config/index.d.ts +1250 -0
  2. package/dist/config/index.js +32 -0
  3. package/dist/env/agent/index.d.ts +2279 -0
  4. package/dist/env/agent/index.js +24 -0
  5. package/dist/env/commands/index.d.ts +1131 -0
  6. package/dist/env/commands/index.js +14 -0
  7. package/dist/env/debug/formatters/index.d.ts +236 -0
  8. package/dist/env/debug/formatters/index.js +11 -0
  9. package/dist/env/debug/index.d.ts +1652 -0
  10. package/dist/env/debug/index.js +26 -0
  11. package/dist/env/hook/index.d.ts +279 -0
  12. package/dist/env/hook/index.js +29 -0
  13. package/dist/env/index.d.ts +3481 -0
  14. package/dist/env/index.js +82 -0
  15. package/dist/env/llm/index.d.ts +1760 -0
  16. package/dist/env/llm/index.js +40 -0
  17. package/dist/env/log-trace/index.d.ts +1574 -0
  18. package/dist/env/log-trace/index.js +83 -0
  19. package/dist/env/mcp/index.d.ts +1331 -0
  20. package/dist/env/mcp/index.js +39 -0
  21. package/dist/env/mcp/tool/index.d.ts +183 -0
  22. package/dist/env/mcp/tool/index.js +14 -0
  23. package/dist/env/memory/built-in/index.d.ts +232 -0
  24. package/dist/env/memory/built-in/index.js +11 -0
  25. package/dist/env/memory/index.d.ts +1799 -0
  26. package/dist/env/memory/index.js +56 -0
  27. package/dist/env/memory/plugin/index.d.ts +747 -0
  28. package/dist/env/memory/plugin/index.js +36 -0
  29. package/dist/env/prompt/index.d.ts +1164 -0
  30. package/dist/env/prompt/index.js +20 -0
  31. package/dist/env/session/index.d.ts +1908 -0
  32. package/dist/env/session/index.js +25 -0
  33. package/dist/env/session/storage/index.d.ts +564 -0
  34. package/dist/env/session/storage/index.js +18 -0
  35. package/dist/env/skill/index.d.ts +1266 -0
  36. package/dist/env/skill/index.js +34 -0
  37. package/dist/env/skill/tool/index.d.ts +193 -0
  38. package/dist/env/skill/tool/index.js +9 -0
  39. package/dist/env/task/delegate/index.d.ts +1612 -0
  40. package/dist/env/task/delegate/index.js +18 -0
  41. package/dist/env/task/events/index.d.ts +171 -0
  42. package/dist/env/task/events/index.js +7 -0
  43. package/dist/env/task/hooks/index.d.ts +624 -0
  44. package/dist/env/task/hooks/index.js +7 -0
  45. package/dist/env/task/index.d.ts +1553 -0
  46. package/dist/env/task/index.js +34 -0
  47. package/dist/env/task/plugins/index.d.ts +466 -0
  48. package/dist/env/task/plugins/index.js +23 -0
  49. package/dist/env/task/storage/index.d.ts +241 -0
  50. package/dist/env/task/storage/index.js +14 -0
  51. package/dist/env/task/tools/index.d.ts +1485 -0
  52. package/dist/env/task/tools/index.js +17 -0
  53. package/dist/env/task/tools/operation/index.d.ts +1484 -0
  54. package/dist/env/task/tools/operation/index.js +15 -0
  55. package/dist/env/tool/built-in/index.d.ts +218 -0
  56. package/dist/env/tool/built-in/index.js +25 -0
  57. package/dist/env/tool/index.d.ts +1396 -0
  58. package/dist/env/tool/index.js +39 -0
  59. package/dist/env/workflow/decorators/index.d.ts +2161 -0
  60. package/dist/env/workflow/decorators/index.js +27 -0
  61. package/dist/env/workflow/engine/index.d.ts +3453 -0
  62. package/dist/env/workflow/engine/index.js +28 -0
  63. package/dist/env/workflow/index.d.ts +3546 -0
  64. package/dist/env/workflow/index.js +136 -0
  65. package/dist/env/workflow/nodes/index.d.ts +2092 -0
  66. package/dist/env/workflow/nodes/index.js +19 -0
  67. package/dist/env/workflow/service/index.d.ts +227 -0
  68. package/dist/env/workflow/service/index.js +13 -0
  69. package/dist/env/workflow/storage/index.d.ts +165 -0
  70. package/dist/env/workflow/storage/index.js +27 -0
  71. package/dist/env/workflow/tools/index.d.ts +416 -0
  72. package/dist/env/workflow/tools/index.js +159 -0
  73. package/dist/env/workflow/types/index.d.ts +2255 -0
  74. package/dist/env/workflow/types/index.js +98 -0
  75. package/dist/env/workflow/utils/index.d.ts +2031 -0
  76. package/dist/env/workflow/utils/index.js +637 -0
  77. package/dist/index.d.ts +7858 -0
  78. package/dist/index.js +399 -0
  79. package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +258 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +36 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +349 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +117 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +11 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +393 -0
  85. package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +200 -0
  86. package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +299 -0
  87. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +206 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +393 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +350 -0
  90. package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +180 -0
  91. package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +408 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +284 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +762 -0
  94. package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +10 -0
  95. package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +14 -0
  96. package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +922 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +15 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +1130 -0
  99. package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +14 -0
  100. package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +653 -0
  101. package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +93 -0
  102. package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +872 -0
  103. package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +11 -0
  104. package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +64 -0
  105. package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +378 -0
  106. package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +492 -0
  107. package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +52 -0
  108. package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +171 -0
  109. package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +862 -0
  110. package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +1387 -0
  111. package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +208 -0
  112. package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +139 -0
  113. package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +534 -0
  114. package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +204 -0
  115. package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +603 -0
  116. package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +97 -0
  117. package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +587 -0
  118. package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +176 -0
  119. package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +60 -0
  120. package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +442 -0
  121. package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +57 -0
  122. package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +66 -0
  123. package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +10 -0
  124. package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +267 -0
  125. package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +584 -0
  126. package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +102 -0
  127. package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +549 -0
  128. package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +15 -0
  129. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +213 -0
  130. package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +812 -0
  131. package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +1316 -0
  132. package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +1205 -0
  133. package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +328 -0
  134. package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +20 -0
  135. package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +2098 -0
  136. package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +419 -0
  137. package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +368 -0
  138. package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +377 -0
  139. package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +172 -0
  140. package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +103 -0
  141. package/package.json +1 -1
@@ -0,0 +1,1250 @@
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 { ZodType as ZodType3, ZodTypeDef as ZodTypeDef2 } from "zod";
206
+ import { ZodType as ZodType2, ZodTypeDef } from "zod";
207
+ /**
208
+ * @fileoverview Environment types and interfaces
209
+ *
210
+ * 定义 Environment 的核心类型,包括:
211
+ * - Environment 配置
212
+ * - EnvEvent 事件类型
213
+ */
214
+ /**
215
+ * Environment Config
216
+ */
217
+ interface EnvironmentConfig {
218
+ /** 环境名称 */
219
+ name: string;
220
+ /** 环境版本 */
221
+ version: string;
222
+ /** 是否启用 */
223
+ enabled: boolean;
224
+ }
225
+ /**
226
+ * EnvEvent 元信息
227
+ */
228
+ interface EnvEventMetadata {
229
+ /** 触发事件的 session ID */
230
+ trigger_session_id?: string;
231
+ /** 触发事件的 agent ID */
232
+ trigger_agent_id?: string;
233
+ /** Agent 名称 */
234
+ trigger_agent_name?: string;
235
+ /** 环境名称 */
236
+ env_name?: string;
237
+ /** 事件来源 */
238
+ source?: string;
239
+ /** 其他元数据 */
240
+ [key: string]: unknown;
241
+ }
242
+ /**
243
+ * EnvEvent
244
+ *
245
+ * 统一的事件机制,用于:
246
+ * - Stream 事件(stream.start, stream.text, stream.completed 等)
247
+ * - 工具调用事件(tool.call, tool.result 等)
248
+ * - 会话事件(session.created, session.updated 等)
249
+ * - Agent 事件(agent.thinking, agent.acting 等)
250
+ */
251
+ interface EnvEvent<T = unknown> {
252
+ /** 事件 ID */
253
+ id: string;
254
+ /** 事件类型 */
255
+ type: string;
256
+ /** 时间戳 */
257
+ timestamp: number;
258
+ /** 元信息 */
259
+ metadata: EnvEventMetadata;
260
+ /** 事件负载 */
261
+ payload: T;
262
+ }
263
+ /**
264
+ * EnvEvent Handler
265
+ */
266
+ type EnvEventHandler = (event: EnvEvent) => void | Promise<void>;
267
+ /**
268
+ * EnvEvent 创建参数(部分属性,可选)
269
+ *
270
+ * 用于 pushEnvEvent 方法,允许传入部分属性,自动补全必填字段
271
+ */
272
+ interface EnvEventInput {
273
+ /** 事件类型(必填) */
274
+ type: string;
275
+ /** 事件 ID(可选,自动生成) */
276
+ id?: string;
277
+ /** 时间戳(可选,自动生成) */
278
+ timestamp?: number;
279
+ /** 元信息(可选,自动创建) */
280
+ metadata?: EnvEventMetadata;
281
+ /** 事件负载(可选) */
282
+ payload?: unknown;
283
+ }
284
+ /**
285
+ * Action 类型
286
+ */
287
+ interface Action {
288
+ /** Action 类型 */
289
+ type: string;
290
+ /** Action 参数 */
291
+ params?: Record<string, unknown>;
292
+ }
293
+ /**
294
+ * Tool Result
295
+ */
296
+ interface ToolResult {
297
+ /** 是否成功 */
298
+ success: boolean;
299
+ /** 输出内容 */
300
+ output: string | Record<string, unknown>;
301
+ /** 错误信息 */
302
+ error?: string;
303
+ }
304
+ /**
305
+ * Context
306
+ */
307
+ interface Context {
308
+ /** 会话 ID */
309
+ sessionId?: string;
310
+ /** 用户 ID */
311
+ userId?: string;
312
+ /** 工作目录 */
313
+ workdir?: string;
314
+ /** 中断信号 */
315
+ abort?: AbortSignal;
316
+ /** 元数据 */
317
+ metadata?: Record<string, unknown>;
318
+ }
319
+ type AbortSignalType = AbortSignal;
320
+ /**
321
+ * Agent 执行上下文
322
+ */
323
+ interface AgentContext {
324
+ /** 会话 ID */
325
+ sessionId?: string;
326
+ /** 消息 ID */
327
+ messageId?: string;
328
+ /** 中断信号 */
329
+ abort?: AbortSignalType;
330
+ /** 额外的上下文信息(会添加到 system prompt) */
331
+ additionInfo?: string;
332
+ /** 元数据 */
333
+ metadata?: Record<string, unknown>;
334
+ /** Agent 类型(用于选择 Behavior Spec) */
335
+ agentType?: string;
336
+ /** 使用的模型 */
337
+ model?: string;
338
+ /** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
339
+ allowedTools?: string[];
340
+ /** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
341
+ deniedTools?: string[];
342
+ /** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
343
+ filterHistory?: boolean;
344
+ }
345
+ /**
346
+ * 服务配置接口
347
+ */
348
+ interface ServiceConfig {
349
+ /** 环境配置 */
350
+ environment?: {
351
+ name?: string;
352
+ version?: string;
353
+ };
354
+ /** 组件配置映射 */
355
+ components?: Record<string, ComponentConfigEntry>;
356
+ }
357
+ /**
358
+ * 组件配置项
359
+ */
360
+ interface ComponentConfigEntry {
361
+ /** 配置文件路径(可选) */
362
+ configPath?: string;
363
+ /** 环境变量前缀(可选) */
364
+ envPrefix?: string;
365
+ /** 直接配置对象(可选) */
366
+ config?: Record<string, unknown>;
367
+ /** 是否启用(可选,默认 true) */
368
+ enabled?: boolean;
369
+ }
370
+ /**
371
+ * 组件初始化选项(由 generateComponentOptions 生成)
372
+ */
373
+ interface GeneratedComponentOptions {
374
+ /** ConfigComponent 实例 */
375
+ configComponent: ConfigComponent;
376
+ /** 配置文件路径 */
377
+ configPath?: string;
378
+ /** 环境变量前缀 */
379
+ envPrefix?: string;
380
+ /** 直接配置对象 */
381
+ config?: Record<string, unknown>;
382
+ /** 允许的其他属性 */
383
+ [key: string]: unknown;
384
+ }
385
+ /**
386
+ * Environment 接口
387
+ *
388
+ * 定义 Agent 运行时的核心能力接口。
389
+ */
390
+ interface Environment {
391
+ /** 环境名称 */
392
+ readonly name: string;
393
+ /** 环境版本 */
394
+ readonly version: string;
395
+ /** 获取环境配置 */
396
+ getConfig(): EnvironmentConfig;
397
+ /**
398
+ * 注册组件
399
+ */
400
+ registerComponent(component: Component): void;
401
+ /**
402
+ * 注销组件
403
+ */
404
+ unregisterComponent(name: string): void;
405
+ /**
406
+ * 获取组件
407
+ */
408
+ getComponent<T extends Component>(name: string): T | undefined;
409
+ /**
410
+ * 列出所有组件
411
+ */
412
+ listComponents(): Component[];
413
+ /**
414
+ * 处理自然语言查询(核心入口)
415
+ *
416
+ * @param query 用户查询文本
417
+ * @param context 执行上下文(可选)
418
+ * @returns 完整的文本响应
419
+ */
420
+ handle_query(query: string, context?: AgentContext): Promise<string>;
421
+ /**
422
+ * 处理动作
423
+ */
424
+ handle_action(action: Action, context: Context): Promise<ToolResult>;
425
+ /**
426
+ * 订阅 EnvEvent(返回取消订阅函数)
427
+ */
428
+ subscribe(handler: EnvEventHandler): () => void;
429
+ /**
430
+ * 订阅指定类型事件
431
+ */
432
+ subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
433
+ /**
434
+ * 订阅所有事件(通配符)
435
+ */
436
+ subscribeAll(handler: EnvEventHandler): () => void;
437
+ /**
438
+ * 推送事件
439
+ *
440
+ * @param event EnvEvent 或 EnvEventInput(部分属性)
441
+ */
442
+ pushEnvEvent(event: EnvEvent | EnvEventInput): void;
443
+ /**
444
+ * 从配置文件加载服务配置
445
+ *
446
+ * @param configPath 配置文件路径(基于 XDG_DATA_HOME)
447
+ * @returns 解析后的服务配置对象
448
+ */
449
+ loadServiceConfig(configPath: string): Promise<ServiceConfig>;
450
+ /**
451
+ * 生成组件初始化选项
452
+ *
453
+ * 根据组件配置项生成可用于初始化的选项对象。
454
+ *
455
+ * @param componentName 组件名称
456
+ * @param configEntry 组件配置项
457
+ * @returns 生成的组件初始化选项
458
+ */
459
+ generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
460
+ /**
461
+ * 注册组件并用配置初始化
462
+ *
463
+ * 便捷方法:注册组件并通过 ConfigComponent 初始化。
464
+ *
465
+ * @param component 要注册的组件实例
466
+ * @param configEntry 组件配置项
467
+ */
468
+ registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
469
+ /**
470
+ * 从配置文件初始化整个环境
471
+ *
472
+ * 加载服务配置,注册并初始化所有配置的组件。
473
+ *
474
+ * @param configPath 配置文件路径(基于 XDG_DATA_HOME)
475
+ */
476
+ initFromConfig(configPath: string): Promise<void>;
477
+ }
478
+ /**
479
+ * Component 状态
480
+ */
481
+ type ComponentStatus = "created" | "initializing" | "running" | "stopping" | "stopped" | "error";
482
+ /**
483
+ * Component 配置
484
+ */
485
+ interface ComponentConfig {
486
+ name: string;
487
+ version: string;
488
+ enabled: boolean;
489
+ options?: Record<string, unknown>;
490
+ /**
491
+ * Environment 实例(可选)
492
+ *
493
+ * 推荐在 init 时接收 env 实例,以便:
494
+ * - 通过 env.getComponent() 获取其他组件
495
+ * - 通过 env.pushEnvEvent() 发布事件
496
+ * - 通过 env.handle_query() 处理查询
497
+ *
498
+ * 如果未提供,部分 Component 仍可正常工作(如测试场景)
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * async onInit(): Promise<void> {
503
+ * if (this.env) {
504
+ * const configComp = this.env.getComponent("config");
505
+ * }
506
+ * }
507
+ * ```
508
+ */
509
+ env?: Environment;
510
+ }
511
+ /**
512
+ * Component 路径声明
513
+ */
514
+ interface ComponentPaths {
515
+ base: "config" | "state" | "data" | "cache";
516
+ subPath: string;
517
+ isDirectory: boolean;
518
+ }
519
+ /**
520
+ * Component Schema(注册配置)
521
+ */
522
+ interface ComponentSchema {
523
+ /** Component 名称 */
524
+ name: string;
525
+ /** 配置 Schema(Zod) */
526
+ schema: ZodType2<unknown, ZodTypeDef, unknown>;
527
+ /** 默认值(从 Schema 提取) */
528
+ defaults: Record<string, unknown>;
529
+ /** 路径声明 */
530
+ paths?: Record<string, ComponentPaths>;
531
+ /** 元信息 */
532
+ metadata?: {
533
+ description?: string;
534
+ version?: string;
535
+ author?: string;
536
+ };
537
+ }
538
+ /**
539
+ * Component 配置变更事件
540
+ */
541
+ interface ComponentConfigChangeEvent {
542
+ /** Component 名称 */
543
+ component: string;
544
+ /** 变更的配置键 */
545
+ key: string;
546
+ /** 旧值 */
547
+ oldValue: unknown;
548
+ /** 新值 */
549
+ newValue: unknown;
550
+ /** 是否持久化 */
551
+ persisted: boolean;
552
+ /** 时间戳 */
553
+ timestamp: number;
554
+ }
555
+ /**
556
+ * Component 配置监听回调
557
+ */
558
+ type ComponentWatchCallback = (event: ComponentConfigChangeEvent) => void | Promise<void>;
559
+ /**
560
+ * Component 基类接口
561
+ */
562
+ interface Component {
563
+ /** Component 名称 */
564
+ readonly name: string;
565
+ /** Component 版本 */
566
+ readonly version: string;
567
+ /** 获取状态 */
568
+ getStatus(): ComponentStatus;
569
+ /** 获取配置 */
570
+ getConfig(): ComponentConfig;
571
+ /** 初始化 */
572
+ init(config: ComponentConfig): Promise<void>;
573
+ /** 启动 */
574
+ start(): Promise<void>;
575
+ /** 停止 */
576
+ stop(): Promise<void>;
577
+ }
578
+ /**
579
+ * Component 基类实现
580
+ */
581
+ declare abstract class BaseComponent implements Component {
582
+ abstract readonly name: string;
583
+ abstract readonly version: string;
584
+ protected _status: ComponentStatus;
585
+ protected _enabled: boolean;
586
+ protected env: Environment;
587
+ /** Hook 管理器 - 子类初始化时由构造函数设置 */
588
+ readonly hookManager: HookManager;
589
+ constructor();
590
+ getStatus(): ComponentStatus;
591
+ getConfig(): ComponentConfig;
592
+ /**
593
+ * 检查 Environment 是否已初始化
594
+ */
595
+ protected isEnvInitialized(): boolean;
596
+ protected setStatus(status: ComponentStatus): void;
597
+ /**
598
+ * 获取 Environment 实例
599
+ */
600
+ protected getEnv(): Environment;
601
+ init(config?: ComponentConfig): Promise<void>;
602
+ start(): Promise<void>;
603
+ stop(): Promise<void>;
604
+ /**
605
+ * 子类可覆盖的钩子方法
606
+ */
607
+ protected onInit(): Promise<void>;
608
+ protected onStart(): Promise<void>;
609
+ protected onStop(): Promise<void>;
610
+ /**
611
+ * 注册 Hook
612
+ *
613
+ * @param hookPoint Hook 点名称
614
+ * @param hook Hook 实例
615
+ */
616
+ protected registerHook<T = unknown>(hookPoint: string, hook: Hook<T>): void;
617
+ /**
618
+ * 便捷方法:快速注册 Hook
619
+ */
620
+ protected addHook<T = unknown>(hookPoint: string, name: string, fn: HookFn<T>, priority?: number): void;
621
+ /**
622
+ * 便捷方法:按名称取消注册 Hook
623
+ */
624
+ protected removeHook(hookPoint: string, name: string): boolean;
625
+ /**
626
+ * 执行 Hook
627
+ */
628
+ protected executeHooks<T = unknown>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
629
+ /**
630
+ * 获取 ConfigComponent 实例
631
+ *
632
+ * 子类可使用此方法获取配置组件,支持热更新
633
+ */
634
+ protected getConfigComponent(): {
635
+ get(key: string): unknown;
636
+ } | undefined;
637
+ /**
638
+ * 动态获取运行时配置值
639
+ *
640
+ * 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
641
+ * 适用于运行时可能变化的配置(如 API Keys、模型参数)
642
+ *
643
+ * @param key 配置键(支持点号分隔的路径,如 "llm.temperature")
644
+ * @param defaultValue 默认值
645
+ * @returns 配置值或默认值
646
+ *
647
+ * @example
648
+ * ```typescript
649
+ * // 获取 LLM 温度配置(可能支持热更新)
650
+ * const temperature = this.getRuntimeConfig("llm.temperature", 0.7);
651
+ *
652
+ * // 获取 API Key
653
+ * const apiKey = this.getRuntimeConfig<string>("llm.providers.openai.apiKey");
654
+ * ```
655
+ */
656
+ protected getRuntimeConfig<T>(key: string, defaultValue: T): T;
657
+ }
658
+ /**
659
+ * ConfigSource 类型
660
+ */
661
+ type ConfigSourceType = "memory" | "file" | "env" | "remote";
662
+ /**
663
+ * SourceRegistration - Source 注册配置
664
+ */
665
+ interface SourceRegistration {
666
+ /** Source 类型 */
667
+ type: ConfigSourceType;
668
+ /** 相对路径(file 类型使用,基于 XDG_DATA_HOME) */
669
+ relativePath?: string;
670
+ /** 环境变量前缀(env 类型使用) */
671
+ envPrefix?: string;
672
+ /** 优先级,默认值:memory=0, file=10, env=20 */
673
+ priority?: number;
674
+ /** 是否可选(file 类型使用,文件不存在时不报错) */
675
+ optional?: boolean;
676
+ /** 是否启用文件监听(file 类型使用,默认 true) */
677
+ watch?: boolean;
678
+ }
679
+ /**
680
+ * KeyRegistration - 配置 Key 注册
681
+ */
682
+ interface KeyRegistration {
683
+ /** 配置 Key(支持点号嵌套,如 "llm.provider") */
684
+ key: string;
685
+ /** 优先使用的 Source 列表(按优先级从低到高) */
686
+ sources: ConfigSourceType[];
687
+ /** 自定义优先级(覆盖默认优先级) */
688
+ priority?: number;
689
+ /** 默认值 */
690
+ default?: unknown;
691
+ }
692
+ /**
693
+ * ComponentRegistration - Component 注册配置
694
+ */
695
+ interface ComponentRegistration {
696
+ /** Component 名称 */
697
+ name: string;
698
+ /** 声明需要的 Source */
699
+ sources: SourceRegistration[];
700
+ /** 声明需要的配置 Key */
701
+ keys: KeyRegistration[];
702
+ /** 配置 Schema(用于验证,可选) */
703
+ schema?: ZodType3<unknown, ZodTypeDef2, unknown>;
704
+ /** 默认值 */
705
+ defaults?: Record<string, unknown>;
706
+ }
707
+ /**
708
+ * 配置源不存在错误
709
+ */
710
+ declare class ConfigSourceNotFoundError extends Error {
711
+ constructor(sourceType: string, path?: string);
712
+ }
713
+ /**
714
+ * 配置文件不存在错误
715
+ */
716
+ declare class ConfigFileNotFoundError extends Error {
717
+ constructor(filePath: string);
718
+ }
719
+ /**
720
+ * ConfigSource 接口
721
+ */
722
+ interface ConfigSource {
723
+ readonly name: ConfigSourceType;
724
+ readonly priority: number;
725
+ read(key: string): unknown | undefined;
726
+ write?(key: string, value: unknown): boolean;
727
+ delete?(key: string): boolean;
728
+ list(): Array<{
729
+ key: string;
730
+ value: unknown;
731
+ }>;
732
+ watch?(callback: (event: ConfigChangeEvent) => void): () => void;
733
+ }
734
+ /**
735
+ * Config 变更事件
736
+ */
737
+ interface ConfigChangeEvent {
738
+ type: "change" | "add" | "delete";
739
+ key: string;
740
+ oldValue: unknown;
741
+ newValue: unknown;
742
+ source: ConfigSourceType;
743
+ timestamp: number;
744
+ }
745
+ /**
746
+ * MemorySource 实现
747
+ */
748
+ declare class MemorySource implements ConfigSource {
749
+ readonly name: ConfigSourceType;
750
+ readonly priority = 0;
751
+ private store;
752
+ private watchers;
753
+ read(key: string): unknown | undefined;
754
+ write(key: string, value: unknown): boolean;
755
+ delete(key: string): boolean;
756
+ list(): Array<{
757
+ key: string;
758
+ value: unknown;
759
+ }>;
760
+ watch(callback: (event: ConfigChangeEvent) => void): () => void;
761
+ private notifyWatchers;
762
+ }
763
+ /**
764
+ * ConfigComponent 配置
765
+ */
766
+ interface ConfigComponentOptions {
767
+ /** 持久化文件路径 */
768
+ persistFile?: string;
769
+ /** 防抖延迟(ms) */
770
+ debounceMs?: number;
771
+ /** 最大批量大小 */
772
+ maxBatchSize?: number;
773
+ }
774
+ /**
775
+ * ConfigComponent
776
+ */
777
+ declare class ConfigComponent extends BaseComponent {
778
+ readonly name = "config";
779
+ readonly version = "1.0.0";
780
+ private memorySource;
781
+ private sources;
782
+ private componentSchemas;
783
+ private componentPaths;
784
+ private watchers;
785
+ /** Source watch unsubscribe 函数 */
786
+ private sourceUnwatchFns;
787
+ private persistQueue;
788
+ private persistFile?;
789
+ /** Key 注册表:key -> KeyRegistration */
790
+ private keyRegistry;
791
+ /** Component 注册表:name -> ComponentRegistration */
792
+ private componentRegistrations;
793
+ /** 协议解析器 */
794
+ private protocolResolver?;
795
+ /** XDG_DATA_HOME 缓存(用于测试注入) */
796
+ private __xdgDataHome?;
797
+ /** Source 注册配置(延迟创建) */
798
+ private pendingSources;
799
+ /** Source 唯一标识缓存:type:relativePath -> true */
800
+ private sourceKeys;
801
+ /**
802
+ * 获取 XDG_DATA_HOME(动态获取,支持运行时覆盖)
803
+ */
804
+ getXdgDataHome(): string;
805
+ /**
806
+ * 设置 XDG_DATA_HOME(用于测试)
807
+ */
808
+ setXdgDataHome(path: string): void;
809
+ constructor(options?: ConfigComponentOptions);
810
+ /**
811
+ * 注册 Component Schema
812
+ */
813
+ register(schema: ComponentSchema): void;
814
+ /**
815
+ * 注销 Component
816
+ */
817
+ unregister(name: string): boolean;
818
+ /**
819
+ * 检查是否已注册
820
+ */
821
+ isRegistered(name: string): boolean;
822
+ /**
823
+ * 列出所有注册的 Component
824
+ */
825
+ listComponents(): string[];
826
+ /**
827
+ * 获取配置值(支持 xxx.yyy.zzz 嵌套访问)
828
+ * 支持两种模式:
829
+ * 1. 完整 key:直接查找,如 "component.key" -> 读取 "component.key"
830
+ * 2. 嵌套对象:查找 component 对象后从中获取属性,如 "component.nested.deep"
831
+ * -> 先找 "component.nested",再获取其 "deep" 属性
832
+ */
833
+ get(key: string): unknown;
834
+ /**
835
+ * 批量获取
836
+ */
837
+ getMany(keys: string[]): Record<string, unknown>;
838
+ /**
839
+ * 设置配置值(内存级别 + 异步持久化)
840
+ */
841
+ set(key: string, value: unknown): Promise<void>;
842
+ /**
843
+ * 批量设置
844
+ */
845
+ setMany(config: Record<string, unknown>): Promise<void>;
846
+ /**
847
+ * 获取 Component 的路径
848
+ */
849
+ getPath(component: string, subPath?: string): string;
850
+ /**
851
+ * 手动持久化
852
+ */
853
+ save(key?: string): Promise<void>;
854
+ /**
855
+ * 重置到默认值
856
+ */
857
+ reset(key: string): Promise<void>;
858
+ /**
859
+ * 监听配置变更
860
+ */
861
+ watch(pattern: string, callback: ComponentWatchCallback): () => void;
862
+ /**
863
+ * 添加配置源
864
+ */
865
+ addSource(source: ConfigSource): void;
866
+ /**
867
+ * 获取 Source 唯一标识
868
+ */
869
+ private getSourceKey;
870
+ /**
871
+ * 移除配置源
872
+ */
873
+ removeSource(name: ConfigSourceType): boolean;
874
+ /**
875
+ * 关闭所有配置源的 watcher(用于优雅退出)
876
+ */
877
+ unwatchAll(): void;
878
+ /**
879
+ * 获取配置源列表
880
+ */
881
+ getSources(): ConfigSource[];
882
+ private getNestedValue;
883
+ private notifyWatchers;
884
+ private persistToFile;
885
+ /**
886
+ * 注册配置 Source
887
+ *
888
+ * Source 会在首次 load() 时被创建
889
+ *
890
+ * @example
891
+ * config.registerSource({ type: "file", relativePath: "llm-config.jsonc" });
892
+ * config.registerSource({ type: "env", envPrefix: "LLM" });
893
+ */
894
+ registerSource(registration: SourceRegistration): void;
895
+ /**
896
+ * 创建 Source 实例
897
+ */
898
+ private createSource;
899
+ /**
900
+ * 确保所有待创建的 Source 已被创建
901
+ */
902
+ private ensureSourcesCreated;
903
+ /**
904
+ * 注册配置 Key
905
+ *
906
+ * @example
907
+ * config.registerKeys([
908
+ * { key: "llm.provider", sources: ["file", "memory"], default: "openai" },
909
+ * { key: "llm.model", sources: ["file"] },
910
+ * ]);
911
+ */
912
+ registerKeys(keys: KeyRegistration[]): void;
913
+ /**
914
+ * 注册 Component(一次性注册 Source 和 Keys)
915
+ *
916
+ * @example
917
+ * config.registerComponent({
918
+ * name: "llm",
919
+ * sources: [
920
+ * { type: "file", relativePath: "llm-config.jsonc" },
921
+ * { type: "env", envPrefix: "LLM" },
922
+ * ],
923
+ * keys: [
924
+ * { key: "llm.provider", sources: ["file", "env", "memory"] },
925
+ * ],
926
+ * });
927
+ */
928
+ registerComponent(registration: ComponentRegistration): void;
929
+ /**
930
+ * 按需加载配置
931
+ *
932
+ * 从注册的 Source 加载已注册 Keys 的配置值到内存中
933
+ *
934
+ * @param componentName - 可选,指定要加载的 Component 名称
935
+ *
936
+ * @example
937
+ * // 加载所有已注册的 Keys
938
+ * await config.load();
939
+ *
940
+ * // 只加载指定 Component 的 Keys
941
+ * await config.load("llm");
942
+ */
943
+ load(componentName?: string): Promise<void>;
944
+ /**
945
+ * 获取已注册的 Source 列表
946
+ */
947
+ getRegisteredSources(): ConfigSource[];
948
+ }
949
+ /**
950
+ * Protocol Resolver
951
+ *
952
+ * Resolves configuration references using protocols:
953
+ * - file:// - Read from files, relative paths based on XDG_DATA_HOME
954
+ * - env:// - Read from environment variables
955
+ *
956
+ * Syntax: ${protocol://path#key}
957
+ */
958
+ type ProtocolType = "file" | "env";
959
+ /**
960
+ * Protocol reference structure
961
+ */
962
+ interface ProtocolRef {
963
+ protocol: ProtocolType;
964
+ path: string;
965
+ key: string;
966
+ defaultValue?: string;
967
+ raw: string;
968
+ }
969
+ /**
970
+ * Resolve result
971
+ */
972
+ interface ResolveResult {
973
+ value: unknown;
974
+ source: ProtocolType;
975
+ }
976
+ /**
977
+ * ProtocolResolver 配置
978
+ */
979
+ interface ProtocolResolverOptions {
980
+ /** XDG 数据目录,默认 ~/.local/share */
981
+ xdgDataHome?: string;
982
+ /** 文件读取函数(用于测试注入) */
983
+ readFileFn?: (path: string) => string;
984
+ }
985
+ /**
986
+ * 协议解析器
987
+ *
988
+ * 解析配置中的协议引用,支持:
989
+ * - ${file://path#key} - 从文件读取(相对路径基于 XDG_DATA_HOME)
990
+ * - ${env://varName} - 从环境变量读取
991
+ */
992
+ declare class ProtocolResolver {
993
+ private _xdgDataHome;
994
+ private readFileFn;
995
+ constructor(options?: ProtocolResolverOptions);
996
+ /**
997
+ * 获取当前的 XDG_DATA_HOME
998
+ */
999
+ get xdgDataHome(): string;
1000
+ /**
1001
+ * 设置 XDG_DATA_HOME(用于运行时更新)
1002
+ */
1003
+ set xdgDataHome(value: string);
1004
+ /**
1005
+ * 获取默认 XDG_DATA_HOME
1006
+ */
1007
+ static getDefaultXDGDataHome(): string;
1008
+ /**
1009
+ * 解析协议引用
1010
+ * 支持默认值语法: ${protocol://path#key:-default}
1011
+ */
1012
+ parse(ref: string): ProtocolRef | null;
1013
+ /**
1014
+ * 检查是否是协议引用
1015
+ */
1016
+ isProtocolRef(value: string): boolean;
1017
+ /**
1018
+ * 解析并获取协议引用的值
1019
+ *
1020
+ * @returns 解析结果,包含值和来源;解析失败时返回 null
1021
+ */
1022
+ resolve(ref: string): ResolveResult | null;
1023
+ /**
1024
+ * 解析文件引用
1025
+ */
1026
+ private resolveFileRef;
1027
+ /**
1028
+ * 解析并获取协议引用的值
1029
+ * 返回 null 表示解析失败(如协议不支持、文件不存在等)
1030
+ */
1031
+ private resolveInternal;
1032
+ /**
1033
+ * 解析路径(处理相对路径)
1034
+ */
1035
+ private resolvePath;
1036
+ /**
1037
+ * 获取嵌套值
1038
+ */
1039
+ private getNestedValue;
1040
+ }
1041
+ /**
1042
+ * FileSource 配置
1043
+ */
1044
+ interface FileSourceOptions {
1045
+ /** 文件路径 */
1046
+ filePath: string;
1047
+ /** 写入防抖延迟(ms),默认 100ms */
1048
+ debounceMs?: number;
1049
+ /** 协议解析器(可选),用于解析 file://, env:// 协议 */
1050
+ resolver?: ProtocolResolver;
1051
+ /** 是否可选,文件不存在时不报错(默认 false) */
1052
+ optional?: boolean;
1053
+ /** 是否启用文件监听(默认 true) */
1054
+ watch?: boolean;
1055
+ }
1056
+ /**
1057
+ * 文件配置源
1058
+ *
1059
+ * 从 JSON 文件读取/写入配置,支持:
1060
+ * - 点号访问嵌套值(user.profile.name)
1061
+ * - 文件监听
1062
+ * - 异步批量写入
1063
+ * - 协议引用解析 (file://, env://)
1064
+ */
1065
+ declare class FileSource implements ConfigSource {
1066
+ readonly name: ConfigSourceType;
1067
+ readonly priority = 10;
1068
+ private filePath;
1069
+ private data;
1070
+ private watchers;
1071
+ private watcherHandle?;
1072
+ private debounceMs;
1073
+ private pendingWrite?;
1074
+ private lastFileContent;
1075
+ private resolver?;
1076
+ private optional;
1077
+ private watchEnabled;
1078
+ constructor(options: FileSourceOptions | string, resolver?: ProtocolResolver);
1079
+ /**
1080
+ * 同步初始化:加载文件内容
1081
+ */
1082
+ private initSync;
1083
+ /**
1084
+ * 异步初始化
1085
+ */
1086
+ private ensureInit;
1087
+ /**
1088
+ * 获取嵌套值
1089
+ */
1090
+ private getNestedValue;
1091
+ /**
1092
+ * 设置嵌套值
1093
+ */
1094
+ private setNestedValue;
1095
+ /**
1096
+ * 删除嵌套值
1097
+ */
1098
+ private deleteNestedValue;
1099
+ /**
1100
+ * 扁平化嵌套对象为点号路径
1101
+ */
1102
+ private flattenObject;
1103
+ read(key: string): unknown | undefined;
1104
+ readAsync(key: string): Promise<unknown | undefined>;
1105
+ write(key: string, value: unknown): boolean;
1106
+ private scheduleWrite;
1107
+ private persistToFile;
1108
+ delete(key: string): boolean;
1109
+ list(): Array<{
1110
+ key: string;
1111
+ value: unknown;
1112
+ }>;
1113
+ listAsync(): Promise<Array<{
1114
+ key: string;
1115
+ value: unknown;
1116
+ }>>;
1117
+ watch(callback: (event: ConfigChangeEvent) => void): () => void;
1118
+ private ensureWatch;
1119
+ private stopWatch;
1120
+ private reloadFromFile;
1121
+ private notifyWatchers;
1122
+ refresh(): Promise<void>;
1123
+ close(): Promise<void>;
1124
+ }
1125
+ /**
1126
+ * EnvSource 配置
1127
+ */
1128
+ interface EnvSourceOptions {
1129
+ /** 环境变量前缀 */
1130
+ prefix?: string;
1131
+ /** 值转换函数 */
1132
+ transform?: (value: string, key: string) => unknown;
1133
+ /** 轮询间隔(ms),用于检测环境变量变化 */
1134
+ pollInterval?: number;
1135
+ /** 优先级 */
1136
+ priority?: number;
1137
+ /** 是否启用监听(轮询),默认 true */
1138
+ watch?: boolean;
1139
+ }
1140
+ /**
1141
+ * 环境变量配置源
1142
+ *
1143
+ * 从 process.env 读取配置,支持:
1144
+ * - 前缀过滤
1145
+ * - 值转换
1146
+ * - 环境变量监听(轮询)
1147
+ */
1148
+ declare class EnvSource implements ConfigSource {
1149
+ readonly name: ConfigSourceType;
1150
+ readonly priority = 20;
1151
+ private prefix;
1152
+ private transform?;
1153
+ private pollInterval?;
1154
+ private watchers;
1155
+ private pollTimer?;
1156
+ private lastValues;
1157
+ private watchEnabled;
1158
+ constructor(options?: EnvSourceOptions);
1159
+ /**
1160
+ * 获取环境变量名(带前缀)
1161
+ * 将点号路径转换为下划线分隔的大写形式
1162
+ * 例如: "llm.provider" + prefix "LLM" -> "LLM_LLM_PROVIDER"
1163
+ * 例如: "DEBUG" + prefix "MY_APP_" -> "MY_APP_DEBUG"
1164
+ * 例如: "llm.defaultModel" + prefix "LLM" -> "LLM_LLM_DEFAULT_MODEL"
1165
+ */
1166
+ private getEnvKey;
1167
+ /**
1168
+ * 移除前缀获取内部 key
1169
+ * 注意:保持原始格式(大小写),仅移除前缀
1170
+ */
1171
+ private getInternalKey;
1172
+ /**
1173
+ * 读取环境变量
1174
+ */
1175
+ read(key: string): unknown;
1176
+ /**
1177
+ * 写入环境变量
1178
+ */
1179
+ write(key: string, value: unknown): boolean;
1180
+ /**
1181
+ * 删除环境变量
1182
+ */
1183
+ delete(key: string): boolean;
1184
+ /**
1185
+ * 列出所有环境变量
1186
+ */
1187
+ list(): Array<{
1188
+ key: string;
1189
+ value: unknown;
1190
+ }>;
1191
+ /**
1192
+ * 监听环境变量变化
1193
+ */
1194
+ watch(callback: (event: ConfigChangeEvent) => void): () => void;
1195
+ private ensurePolling;
1196
+ private stopPolling;
1197
+ private recordCurrentValues;
1198
+ private checkForChanges;
1199
+ private transformValue;
1200
+ private notifyWatchers;
1201
+ /**
1202
+ * 关闭并清理资源
1203
+ */
1204
+ close(): void;
1205
+ }
1206
+ /**
1207
+ * Parse JSONC (JSON with Comments) content
1208
+ * Supports single-line comments (//) and multi-line comments
1209
+ *
1210
+ * @param content - JSONC content string
1211
+ * @returns Parsed JSON object
1212
+ */
1213
+ declare function parseJSONC(content: string): Record<string, unknown>;
1214
+ /**
1215
+ * Substitute environment variables in a value
1216
+ * Supports ${VAR} and ${VAR:-default} syntax
1217
+ *
1218
+ * @param value - Value to substitute (string, object, array, or primitive)
1219
+ * @returns Value with environment variables substituted
1220
+ */
1221
+ declare function substituteEnvVars(value: unknown): unknown;
1222
+ /**
1223
+ * Parse JSONC content and substitute environment variables
1224
+ *
1225
+ * @param content - JSONC content string
1226
+ * @returns Parsed JSON object with env vars substituted
1227
+ */
1228
+ declare function parseJSONCWithEnv(content: string): Record<string, unknown>;
1229
+ /**
1230
+ * Substitute protocol references in a value using the provided resolver
1231
+ *
1232
+ * Supports:
1233
+ * - ${file://path#key} - Read from file
1234
+ * - ${env://varName} - Read from environment variable
1235
+ * - All above with default values: ${protocol://...:-default}
1236
+ *
1237
+ * @param value - Value to substitute (string, object, array, or primitive)
1238
+ * @param resolver - ProtocolResolver instance
1239
+ * @returns Value with protocol references substituted
1240
+ */
1241
+ declare function substituteProtocolRefs(value: unknown, resolver: ProtocolResolver): unknown;
1242
+ /**
1243
+ * Parse JSONC content and substitute protocol references
1244
+ *
1245
+ * @param content - JSONC content string
1246
+ * @param resolver - ProtocolResolver instance
1247
+ * @returns Parsed JSON object with protocol refs substituted
1248
+ */
1249
+ declare function parseJSONCWithProtocols(content: string, resolver: ProtocolResolver): Record<string, unknown>;
1250
+ export { substituteProtocolRefs, substituteEnvVars, parseJSONCWithProtocols, parseJSONCWithEnv, parseJSONC, SourceRegistration, MemorySource, KeyRegistration, FileSourceOptions, FileSource, EnvSourceOptions, EnvSource, ConfigSourceType, ConfigSourceNotFoundError, ConfigSource, ConfigFileNotFoundError, ConfigComponentOptions, ConfigComponent, ConfigChangeEvent, ComponentRegistration };