@ai-setting/roy-agent-core 1.5.14-test → 1.5.15-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.
- package/package.json +1 -1
- package/dist/config/index.d.ts +0 -1250
- package/dist/config/index.js +0 -32
- package/dist/env/agent/index.d.ts +0 -2279
- package/dist/env/agent/index.js +0 -24
- package/dist/env/commands/index.d.ts +0 -1131
- package/dist/env/commands/index.js +0 -14
- package/dist/env/debug/formatters/index.d.ts +0 -236
- package/dist/env/debug/formatters/index.js +0 -11
- package/dist/env/debug/index.d.ts +0 -1652
- package/dist/env/debug/index.js +0 -26
- package/dist/env/hook/index.d.ts +0 -279
- package/dist/env/hook/index.js +0 -29
- package/dist/env/index.d.ts +0 -3481
- package/dist/env/index.js +0 -82
- package/dist/env/llm/index.d.ts +0 -1760
- package/dist/env/llm/index.js +0 -40
- package/dist/env/log-trace/index.d.ts +0 -1574
- package/dist/env/log-trace/index.js +0 -83
- package/dist/env/mcp/index.d.ts +0 -1331
- package/dist/env/mcp/index.js +0 -39
- package/dist/env/mcp/tool/index.d.ts +0 -183
- package/dist/env/mcp/tool/index.js +0 -14
- package/dist/env/memory/built-in/index.d.ts +0 -232
- package/dist/env/memory/built-in/index.js +0 -11
- package/dist/env/memory/index.d.ts +0 -1799
- package/dist/env/memory/index.js +0 -56
- package/dist/env/memory/plugin/index.d.ts +0 -747
- package/dist/env/memory/plugin/index.js +0 -36
- package/dist/env/prompt/index.d.ts +0 -1164
- package/dist/env/prompt/index.js +0 -20
- package/dist/env/session/index.d.ts +0 -1908
- package/dist/env/session/index.js +0 -25
- package/dist/env/session/storage/index.d.ts +0 -564
- package/dist/env/session/storage/index.js +0 -18
- package/dist/env/skill/index.d.ts +0 -1266
- package/dist/env/skill/index.js +0 -34
- package/dist/env/skill/tool/index.d.ts +0 -193
- package/dist/env/skill/tool/index.js +0 -9
- package/dist/env/task/delegate/index.d.ts +0 -1612
- package/dist/env/task/delegate/index.js +0 -18
- package/dist/env/task/events/index.d.ts +0 -171
- package/dist/env/task/events/index.js +0 -7
- package/dist/env/task/hooks/index.d.ts +0 -624
- package/dist/env/task/hooks/index.js +0 -7
- package/dist/env/task/index.d.ts +0 -1553
- package/dist/env/task/index.js +0 -34
- package/dist/env/task/plugins/index.d.ts +0 -466
- package/dist/env/task/plugins/index.js +0 -23
- package/dist/env/task/storage/index.d.ts +0 -241
- package/dist/env/task/storage/index.js +0 -14
- package/dist/env/task/tools/index.d.ts +0 -1485
- package/dist/env/task/tools/index.js +0 -17
- package/dist/env/task/tools/operation/index.d.ts +0 -1484
- package/dist/env/task/tools/operation/index.js +0 -15
- package/dist/env/tool/built-in/index.d.ts +0 -218
- package/dist/env/tool/built-in/index.js +0 -25
- package/dist/env/tool/index.d.ts +0 -1396
- package/dist/env/tool/index.js +0 -39
- package/dist/env/workflow/decorators/index.d.ts +0 -2161
- package/dist/env/workflow/decorators/index.js +0 -27
- package/dist/env/workflow/engine/index.d.ts +0 -3453
- package/dist/env/workflow/engine/index.js +0 -28
- package/dist/env/workflow/index.d.ts +0 -3546
- package/dist/env/workflow/index.js +0 -136
- package/dist/env/workflow/nodes/index.d.ts +0 -2092
- package/dist/env/workflow/nodes/index.js +0 -19
- package/dist/env/workflow/service/index.d.ts +0 -227
- package/dist/env/workflow/service/index.js +0 -13
- package/dist/env/workflow/storage/index.d.ts +0 -165
- package/dist/env/workflow/storage/index.js +0 -27
- package/dist/env/workflow/tools/index.d.ts +0 -416
- package/dist/env/workflow/tools/index.js +0 -159
- package/dist/env/workflow/types/index.d.ts +0 -2255
- package/dist/env/workflow/types/index.js +0 -98
- package/dist/env/workflow/utils/index.d.ts +0 -2031
- package/dist/env/workflow/utils/index.js +0 -637
- package/dist/index.d.ts +0 -7858
- package/dist/index.js +0 -399
- package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
- package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
- package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
- package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
- package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
- package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
- package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
- package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
- package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
- package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
- package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
- package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
- package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
- package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
- package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
- package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
- package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
- package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
- package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
- package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
- package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
- package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
- package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
- package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
- package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
- package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
- package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
- package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
- package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
- package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
- package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
- package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
- package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
- package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
- package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
- package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
- package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
- package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
- package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
- package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
- package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
- package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
|
@@ -1,1799 +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, ZodType, ZodError } from "zod";
|
|
206
|
-
/**
|
|
207
|
-
* 沙箱配置
|
|
208
|
-
*/
|
|
209
|
-
interface SandboxConfig {
|
|
210
|
-
/** 是否启用沙箱 */
|
|
211
|
-
enabled: boolean;
|
|
212
|
-
/** 沙箱类型 */
|
|
213
|
-
type: "native" | "docker";
|
|
214
|
-
/** 动作过滤 */
|
|
215
|
-
actionFilter?: {
|
|
216
|
-
/** 包含的动作 */
|
|
217
|
-
include?: string[];
|
|
218
|
-
/** 排除的动作 */
|
|
219
|
-
exclude?: string[];
|
|
220
|
-
};
|
|
221
|
-
/** 文件系统限制 */
|
|
222
|
-
filesystem?: {
|
|
223
|
-
/** 允许读取 */
|
|
224
|
-
allowRead?: string[];
|
|
225
|
-
/** 禁止读取 */
|
|
226
|
-
denyRead?: string[];
|
|
227
|
-
/** 允许写入 */
|
|
228
|
-
allowWrite?: string[];
|
|
229
|
-
/** 禁止写入 */
|
|
230
|
-
denyWrite?: string[];
|
|
231
|
-
};
|
|
232
|
-
/** 网络限制 */
|
|
233
|
-
network?: {
|
|
234
|
-
/** 允许的域名 */
|
|
235
|
-
allowedDomains?: string[];
|
|
236
|
-
/** 禁止的域名 */
|
|
237
|
-
deniedDomains?: string[];
|
|
238
|
-
};
|
|
239
|
-
/** Docker 配置 */
|
|
240
|
-
docker?: {
|
|
241
|
-
/** 镜像 */
|
|
242
|
-
image?: string;
|
|
243
|
-
/** 网络模式 */
|
|
244
|
-
networkMode?: "bridge" | "host" | "none";
|
|
245
|
-
/** 卷挂载 */
|
|
246
|
-
volumes?: Record<string, string>;
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* 工具执行上下文
|
|
251
|
-
*/
|
|
252
|
-
interface ToolContext {
|
|
253
|
-
/** 工作目录 */
|
|
254
|
-
workdir?: string;
|
|
255
|
-
/** 用户 ID */
|
|
256
|
-
user_id?: string;
|
|
257
|
-
/** 会话 ID */
|
|
258
|
-
session_id?: string;
|
|
259
|
-
/** 消息 ID */
|
|
260
|
-
message_id?: string;
|
|
261
|
-
/** 中断信号 */
|
|
262
|
-
abort?: AbortSignal;
|
|
263
|
-
/** 额外元数据 */
|
|
264
|
-
metadata?: Record<string, unknown>;
|
|
265
|
-
/** 沙箱配置 */
|
|
266
|
-
sandbox?: SandboxConfig;
|
|
267
|
-
/** 沙箱 Provider */
|
|
268
|
-
sandboxProvider?: unknown | null;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* 工具结果元数据
|
|
272
|
-
*/
|
|
273
|
-
interface ToolResultMetadata {
|
|
274
|
-
/** 执行时间(毫秒) */
|
|
275
|
-
execution_time_ms: number;
|
|
276
|
-
/** 输出大小(字节) */
|
|
277
|
-
output_size?: number;
|
|
278
|
-
/** 标准输出 */
|
|
279
|
-
stdout?: string;
|
|
280
|
-
/** 标准错误 */
|
|
281
|
-
stderr?: string;
|
|
282
|
-
/** 退出码 */
|
|
283
|
-
exit_code?: number;
|
|
284
|
-
/** Token 使用量 */
|
|
285
|
-
usage?: {
|
|
286
|
-
inputTokens: number;
|
|
287
|
-
outputTokens: number;
|
|
288
|
-
totalTokens?: number;
|
|
289
|
-
};
|
|
290
|
-
/** 额外元数据 */
|
|
291
|
-
[key: string]: unknown;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* 工具执行结果
|
|
295
|
-
*/
|
|
296
|
-
interface ToolResult {
|
|
297
|
-
/** 是否成功 */
|
|
298
|
-
success: boolean;
|
|
299
|
-
/** 输出内容 */
|
|
300
|
-
output: string | Record<string, unknown>;
|
|
301
|
-
/** 错误信息 */
|
|
302
|
-
error?: string;
|
|
303
|
-
/** 结果元数据 */
|
|
304
|
-
metadata?: ToolResultMetadata;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* 工具元数据
|
|
308
|
-
*/
|
|
309
|
-
interface ToolMetadata {
|
|
310
|
-
/** 分类 */
|
|
311
|
-
category?: string;
|
|
312
|
-
/** 标签 */
|
|
313
|
-
tags?: string[];
|
|
314
|
-
/** 版本 */
|
|
315
|
-
version?: string;
|
|
316
|
-
/** 作者 */
|
|
317
|
-
author?: string;
|
|
318
|
-
/** 是否实验性 */
|
|
319
|
-
experimental?: boolean;
|
|
320
|
-
/** MCP 工具信息(MCP adapter 使用) */
|
|
321
|
-
mcpTool?: {
|
|
322
|
-
originalName: string;
|
|
323
|
-
originalDescription: string;
|
|
324
|
-
inputSchema?: unknown;
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* 工具沙箱配置
|
|
329
|
-
*/
|
|
330
|
-
interface ToolSandboxConfig {
|
|
331
|
-
/** 是否启用沙箱 */
|
|
332
|
-
enabled: boolean;
|
|
333
|
-
/** 沙箱配置 */
|
|
334
|
-
config?: Partial<SandboxConfig>;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* 工具权限配置
|
|
338
|
-
*/
|
|
339
|
-
interface ToolPermissionConfig {
|
|
340
|
-
/** 是否需要用户确认 */
|
|
341
|
-
requireConfirmation?: boolean;
|
|
342
|
-
/** 权限级别 */
|
|
343
|
-
level?: "safe" | "dangerous" | "critical";
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* 工具信息
|
|
347
|
-
*/
|
|
348
|
-
interface ToolInfo<Parameters extends ZodType = ZodType> {
|
|
349
|
-
/** 工具名称 */
|
|
350
|
-
name: string;
|
|
351
|
-
/** 工具描述 */
|
|
352
|
-
description: string;
|
|
353
|
-
/** 参数 Schema */
|
|
354
|
-
parameters: Parameters;
|
|
355
|
-
/** 初始化函数(可选) */
|
|
356
|
-
init?: (ctx?: ToolContext) => Promise<void>;
|
|
357
|
-
/** 执行函数 */
|
|
358
|
-
execute: (args: z.infer<Parameters>, ctx: ToolContext) => Promise<ToolResult>;
|
|
359
|
-
/** 参数验证错误格式化(可选) */
|
|
360
|
-
formatValidationError?: (error: ZodError) => string;
|
|
361
|
-
/** 沙箱配置 */
|
|
362
|
-
sandbox?: ToolSandboxConfig;
|
|
363
|
-
/** 权限配置 */
|
|
364
|
-
permission?: ToolPermissionConfig;
|
|
365
|
-
/** 工具元数据 */
|
|
366
|
-
metadata?: ToolMetadata;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* 工具类型别名
|
|
370
|
-
*/
|
|
371
|
-
type Tool = ToolInfo;
|
|
372
|
-
import { z as z2 } from "zod";
|
|
373
|
-
/**
|
|
374
|
-
* Memory 来源类型
|
|
375
|
-
* - project: 项目级记忆
|
|
376
|
-
* - global: 全局记忆
|
|
377
|
-
*/
|
|
378
|
-
type MemorySource = "project" | "global";
|
|
379
|
-
/**
|
|
380
|
-
* Memory 路径配置
|
|
381
|
-
*/
|
|
382
|
-
interface MemoryPath {
|
|
383
|
-
/** 来源类型 */
|
|
384
|
-
type: MemorySource;
|
|
385
|
-
/** 绝对路径 */
|
|
386
|
-
path: string;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* MemoryComponent 配置
|
|
390
|
-
*/
|
|
391
|
-
interface MemoryConfig {
|
|
392
|
-
/** 多路径配置 */
|
|
393
|
-
memoryPaths: MemoryPath[];
|
|
394
|
-
/** 是否递归扫描子目录 */
|
|
395
|
-
recursive: boolean;
|
|
396
|
-
/** 是否启用缓存 */
|
|
397
|
-
cacheEnabled: boolean;
|
|
398
|
-
/** 缓存有效期(毫秒) */
|
|
399
|
-
cacheTTL?: number;
|
|
400
|
-
/** 记忆文件名 */
|
|
401
|
-
memoryFile?: string;
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* record_memory 操作模式
|
|
405
|
-
*/
|
|
406
|
-
type RecordMemoryMode = "append" | "prepend" | "overwrite" | "delete";
|
|
407
|
-
/**
|
|
408
|
-
* record_memory 操作结果
|
|
409
|
-
*/
|
|
410
|
-
interface RecordMemoryResult {
|
|
411
|
-
/** 文件路径 */
|
|
412
|
-
path: string;
|
|
413
|
-
/** 操作类型 */
|
|
414
|
-
action: "created" | "append" | "prepend" | "overwrite" | "delete";
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* record_memory 工具参数
|
|
418
|
-
*/
|
|
419
|
-
declare const RecordMemorySchema: unknown;
|
|
420
|
-
type RecordMemoryParams = z2.infer<typeof RecordMemorySchema>;
|
|
421
|
-
/**
|
|
422
|
-
* recall_memory 工具参数
|
|
423
|
-
*/
|
|
424
|
-
declare const RecallMemorySchema: unknown;
|
|
425
|
-
type RecallMemoryParams = z2.infer<typeof RecallMemorySchema>;
|
|
426
|
-
/**
|
|
427
|
-
* record_memory 工具参数
|
|
428
|
-
*/
|
|
429
|
-
declare const RecordMemorySchema2: unknown;
|
|
430
|
-
/**
|
|
431
|
-
* recall_memory 工具参数
|
|
432
|
-
*/
|
|
433
|
-
declare const RecallMemorySchema2: unknown;
|
|
434
|
-
import { ModelMessage } from "ai";
|
|
435
|
-
/**
|
|
436
|
-
* MemoryPlugin configuration
|
|
437
|
-
*/
|
|
438
|
-
interface MemoryPluginConfig {
|
|
439
|
-
/** Enable memory plugin */
|
|
440
|
-
enabled?: boolean;
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Memory task types
|
|
444
|
-
*/
|
|
445
|
-
type MemoryTaskType = "extract_memory";
|
|
446
|
-
/**
|
|
447
|
-
* Memory task
|
|
448
|
-
*/
|
|
449
|
-
interface MemoryTask {
|
|
450
|
-
id: string;
|
|
451
|
-
type: MemoryTaskType;
|
|
452
|
-
payload: unknown;
|
|
453
|
-
timestamp: number;
|
|
454
|
-
priority: number;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Extract memory payload
|
|
458
|
-
*/
|
|
459
|
-
interface ExtractMemoryPayload {
|
|
460
|
-
messages: ModelMessage[];
|
|
461
|
-
sessionId?: string;
|
|
462
|
-
/** Hook context for Memory Agent */
|
|
463
|
-
ctx?: MemoryHookContext;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* SessionMessage 接口
|
|
467
|
-
*/
|
|
468
|
-
interface SessionMessage {
|
|
469
|
-
/** 消息角色 */
|
|
470
|
-
role: "user" | "assistant" | "system" | "tool";
|
|
471
|
-
/** 消息内容 */
|
|
472
|
-
content: string | Array<{
|
|
473
|
-
type: string;
|
|
474
|
-
[key: string]: unknown;
|
|
475
|
-
}>;
|
|
476
|
-
/** 工具调用 ID(仅 tool 角色) */
|
|
477
|
-
toolCallId?: string;
|
|
478
|
-
/** 工具名称(仅 tool 角色) */
|
|
479
|
-
toolName?: string;
|
|
480
|
-
/** 时间戳 */
|
|
481
|
-
timestamp?: number;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Hook context data for agent:after.react
|
|
485
|
-
*/
|
|
486
|
-
interface MemoryHookContext {
|
|
487
|
-
/** Current messages for memory extraction */
|
|
488
|
-
messages: ModelMessage[];
|
|
489
|
-
/** Current session ID */
|
|
490
|
-
sessionId?: string;
|
|
491
|
-
/** Project summaries (populated by project agent) */
|
|
492
|
-
projectSummaries?: unknown[];
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* MemoryManager 配置
|
|
496
|
-
*/
|
|
497
|
-
interface MemoryManagerConfig {
|
|
498
|
-
/** 回调:当需要提取记忆时调用 */
|
|
499
|
-
onExtractMemory?: (payload: ExtractMemoryPayload) => Promise<void>;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* MemoryManager V3 - Simplified
|
|
503
|
-
*
|
|
504
|
-
* 简化的后台异步内存处理,只负责任务队列
|
|
505
|
-
*/
|
|
506
|
-
declare class MemoryManager {
|
|
507
|
-
/** 队列最大容量,防止内存溢出 */
|
|
508
|
-
private static readonly MAX_QUEUE_SIZE;
|
|
509
|
-
private queue;
|
|
510
|
-
private processing;
|
|
511
|
-
private shuttingDown;
|
|
512
|
-
private config;
|
|
513
|
-
private processingPromise;
|
|
514
|
-
private resolveProcessing;
|
|
515
|
-
constructor(config?: MemoryManagerConfig);
|
|
516
|
-
/**
|
|
517
|
-
* 更新配置
|
|
518
|
-
*/
|
|
519
|
-
updateConfig(config: Partial<MemoryManagerConfig>): void;
|
|
520
|
-
/**
|
|
521
|
-
* 入队(非阻塞)
|
|
522
|
-
*/
|
|
523
|
-
enqueue(task: Omit<MemoryTask, "id">): void;
|
|
524
|
-
/**
|
|
525
|
-
* 启动处理循环
|
|
526
|
-
*/
|
|
527
|
-
private startProcessingLoop;
|
|
528
|
-
/**
|
|
529
|
-
* 检查是否有待处理任务
|
|
530
|
-
*/
|
|
531
|
-
hasPendingTasks(): boolean;
|
|
532
|
-
/**
|
|
533
|
-
* 等待处理完成
|
|
534
|
-
*/
|
|
535
|
-
waitForCompletion(): Promise<void>;
|
|
536
|
-
/**
|
|
537
|
-
* 准备关闭
|
|
538
|
-
*/
|
|
539
|
-
prepareShutdown(): void;
|
|
540
|
-
/**
|
|
541
|
-
* 释放资源
|
|
542
|
-
*/
|
|
543
|
-
dispose(): Promise<void>;
|
|
544
|
-
/**
|
|
545
|
-
* 处理单个任务
|
|
546
|
-
*/
|
|
547
|
-
private processTask;
|
|
548
|
-
/**
|
|
549
|
-
* 处理记忆提取
|
|
550
|
-
*/
|
|
551
|
-
private handleExtractMemory;
|
|
552
|
-
}
|
|
553
|
-
import { ModelMessage as ModelMessage2 } from "ai";
|
|
554
|
-
type AbortSignalType = AbortSignal;
|
|
555
|
-
interface ProjectSummary {
|
|
556
|
-
projectPath: string;
|
|
557
|
-
projectName: string;
|
|
558
|
-
lastUpdated: number;
|
|
559
|
-
summary: string;
|
|
560
|
-
shortSummary: string;
|
|
561
|
-
draftCount: number;
|
|
562
|
-
memoryMdPath: string;
|
|
563
|
-
draftsDir: string;
|
|
564
|
-
detailsDir: string;
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Agent 执行上下文
|
|
568
|
-
*/
|
|
569
|
-
interface AgentContext {
|
|
570
|
-
/** 会话 ID */
|
|
571
|
-
sessionId?: string;
|
|
572
|
-
/** 消息 ID */
|
|
573
|
-
messageId?: string;
|
|
574
|
-
/** 中断信号 */
|
|
575
|
-
abort?: AbortSignalType;
|
|
576
|
-
/** 额外的上下文信息(会添加到 system prompt) */
|
|
577
|
-
additionInfo?: string;
|
|
578
|
-
/** 元数据 */
|
|
579
|
-
metadata?: Record<string, unknown>;
|
|
580
|
-
/** Agent 类型(用于选择 Behavior Spec) */
|
|
581
|
-
agentType?: string;
|
|
582
|
-
/** 使用的模型 */
|
|
583
|
-
model?: string;
|
|
584
|
-
/** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
585
|
-
allowedTools?: string[];
|
|
586
|
-
/** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
587
|
-
deniedTools?: string[];
|
|
588
|
-
/** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
|
|
589
|
-
filterHistory?: boolean;
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* 工具调用(内部使用)
|
|
593
|
-
*/
|
|
594
|
-
interface ToolCall2 {
|
|
595
|
-
/** 调用 ID */
|
|
596
|
-
id: string;
|
|
597
|
-
/** 工具名称 */
|
|
598
|
-
name: string;
|
|
599
|
-
/** 调用参数 */
|
|
600
|
-
arguments: Record<string, unknown>;
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* 工具调用结果
|
|
604
|
-
*/
|
|
605
|
-
interface ToolCallResult {
|
|
606
|
-
/** 调用 ID */
|
|
607
|
-
id: string;
|
|
608
|
-
/** 工具名称 */
|
|
609
|
-
name: string;
|
|
610
|
-
/** 调用结果 */
|
|
611
|
-
result: ToolResult;
|
|
612
|
-
/** 是否成功 */
|
|
613
|
-
success: boolean;
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Hook 点枚举(带 component 前缀)
|
|
617
|
-
*/
|
|
618
|
-
type HookPoint = "agent:before.start" | "agent:before.llm" | "agent:after.llm" | "agent:before.tool" | "agent:after.tool" | "agent:on.iteration" | "agent:on.threshold" | "agent:after.complete" | "agent:on.error" | "agent:after.react" | "on.error";
|
|
619
|
-
/**
|
|
620
|
-
* Hook 上下文(Agent 特有版本)
|
|
621
|
-
*
|
|
622
|
-
* 注意:这是 AgentComponent 使用的 HookContext 扩展版本
|
|
623
|
-
* 包含 iteration, maxIterations, messages 等 Agent 特有字段
|
|
624
|
-
*/
|
|
625
|
-
interface HookContext2 {
|
|
626
|
-
/** 当前 LLM 输出(after.llm hook 可用) */
|
|
627
|
-
llmOutput?: AgentLLMOutput;
|
|
628
|
-
/** 当前工具调用(before.tool/after.tool hook 可用) */
|
|
629
|
-
currentToolCall?: ToolCall2;
|
|
630
|
-
/** 工具执行结果(after.tool hook 可用) */
|
|
631
|
-
toolResult?: ToolCallResult;
|
|
632
|
-
/** 阈值信息(on.threshold hook 可用) */
|
|
633
|
-
threshold?: {
|
|
634
|
-
type: "tokens" | "turns" | "iterations" | "custom";
|
|
635
|
-
value: number;
|
|
636
|
-
limit?: number;
|
|
637
|
-
};
|
|
638
|
-
/** 当前错误(on.error hook 可用) */
|
|
639
|
-
error?: Error;
|
|
640
|
-
/** 当前 Agent 实例 */
|
|
641
|
-
agent: AgentInstance;
|
|
642
|
-
/** 当前迭代次数(可修改) */
|
|
643
|
-
iteration: number;
|
|
644
|
-
/** 最大迭代次数限制(before.llm hook 可用) */
|
|
645
|
-
maxIterations: number;
|
|
646
|
-
/** 消息列表(可直接修改) */
|
|
647
|
-
messages: ModelMessage2[];
|
|
648
|
-
/** 可用工具列表(可直接修改) */
|
|
649
|
-
tools: Tool[];
|
|
650
|
-
/** 当前 system prompt(可直接修改) */
|
|
651
|
-
systemPrompt: string;
|
|
652
|
-
/** 额外的上下文信息(可直接修改) */
|
|
653
|
-
additionInfo?: string;
|
|
654
|
-
/** 执行上下文(可直接修改属性) */
|
|
655
|
-
context: AgentContext;
|
|
656
|
-
/** 是否已停止 */
|
|
657
|
-
_stopped?: boolean;
|
|
658
|
-
/** 停止原因 */
|
|
659
|
-
_stopReason?: string;
|
|
660
|
-
/** 待执行的干预动作 */
|
|
661
|
-
_pendingAction?: {
|
|
662
|
-
type: HookActionType2;
|
|
663
|
-
payload?: unknown;
|
|
664
|
-
};
|
|
665
|
-
/** 错误列表 */
|
|
666
|
-
_errors?: Array<{
|
|
667
|
-
plugin: string;
|
|
668
|
-
error: string;
|
|
669
|
-
}>;
|
|
670
|
-
/** Project Memory Agent 生成的摘要列表(由 Project Agent 写入,Global Agent 读取) */
|
|
671
|
-
projectSummaries?: ProjectSummary[];
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Hook 干预动作
|
|
675
|
-
*/
|
|
676
|
-
type HookActionType2 = "stop" | "retry" | "compress" | "extract_memory" | "inject_message" | "skip_tool";
|
|
677
|
-
/**
|
|
678
|
-
* Hook 返回结果
|
|
679
|
-
*/
|
|
680
|
-
interface HookResult2 {
|
|
681
|
-
/** 是否继续执行(false = 停止 Agent) */
|
|
682
|
-
continue: boolean;
|
|
683
|
-
/** 干预动作(可选) */
|
|
684
|
-
action?: {
|
|
685
|
-
type: HookActionType2;
|
|
686
|
-
payload?: unknown;
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Plugin 定义
|
|
691
|
-
*/
|
|
692
|
-
interface Plugin {
|
|
693
|
-
/** Plugin 唯一名称 */
|
|
694
|
-
name: string;
|
|
695
|
-
/** Plugin 版本 */
|
|
696
|
-
version: string;
|
|
697
|
-
/** Plugin 描述 */
|
|
698
|
-
description?: string;
|
|
699
|
-
/** 订阅的 Hook 点及优先级 */
|
|
700
|
-
hooks: Array<{
|
|
701
|
-
point: HookPoint;
|
|
702
|
-
/** 优先级,默认 0,数字越大越先执行 */
|
|
703
|
-
priority?: number;
|
|
704
|
-
}>;
|
|
705
|
-
/** 执行函数 */
|
|
706
|
-
execute: (ctx: HookContext2) => HookResult2 | Promise<HookResult2>;
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Agent 类型
|
|
710
|
-
*/
|
|
711
|
-
type AgentType = "primary" | "sub" | "summary";
|
|
712
|
-
/**
|
|
713
|
-
* Agent 状态
|
|
714
|
-
*/
|
|
715
|
-
type AgentStatus = "idle" | "running" | "paused" | "stopped" | "error";
|
|
716
|
-
/**
|
|
717
|
-
* Agent 实例配置
|
|
718
|
-
*/
|
|
719
|
-
interface AgentInstanceConfig {
|
|
720
|
-
/** Agent 类型 */
|
|
721
|
-
type: AgentType;
|
|
722
|
-
/** Agent 名称 */
|
|
723
|
-
name?: string;
|
|
724
|
-
/** System Prompt */
|
|
725
|
-
systemPrompt?: string;
|
|
726
|
-
/** Behavior Spec ID */
|
|
727
|
-
behaviorSpecId?: string;
|
|
728
|
-
/** 使用的模型 */
|
|
729
|
-
model?: string;
|
|
730
|
-
/** 最大迭代次数 */
|
|
731
|
-
maxIterations?: number;
|
|
732
|
-
/** 最大错误重试次数 */
|
|
733
|
-
maxErrorRetries?: number;
|
|
734
|
-
/** 死循环检测阈值 */
|
|
735
|
-
doomLoopThreshold?: number;
|
|
736
|
-
/** 允许的工具列表 */
|
|
737
|
-
allowedTools?: string[];
|
|
738
|
-
/** 拒绝的工具列表 */
|
|
739
|
-
deniedTools?: string[];
|
|
740
|
-
/** 工具超时(毫秒) */
|
|
741
|
-
toolTimeout?: number;
|
|
742
|
-
/** 工具重试次数 */
|
|
743
|
-
toolRetries?: number;
|
|
744
|
-
/** 是否过滤 history 中的 tool 消息(默认过滤,避免上下文过长) */
|
|
745
|
-
filterHistory?: boolean;
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Agent 实例
|
|
749
|
-
*/
|
|
750
|
-
interface AgentInstance {
|
|
751
|
-
/** Agent 名称 */
|
|
752
|
-
name: string;
|
|
753
|
-
/** Agent 配置 */
|
|
754
|
-
config: Required<AgentInstanceConfig>;
|
|
755
|
-
/** 当前状态 */
|
|
756
|
-
status: AgentStatus;
|
|
757
|
-
/** 注册的 Plugins */
|
|
758
|
-
plugins: Map<string, Plugin>;
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Agent 内部使用的 LLM 输出
|
|
762
|
-
* 独立定义以避免与 LLMOutput 的类型冲突
|
|
763
|
-
*/
|
|
764
|
-
interface AgentLLMOutput {
|
|
765
|
-
/** 生成的内容 */
|
|
766
|
-
content: string;
|
|
767
|
-
/** 完成原因 */
|
|
768
|
-
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "function-call";
|
|
769
|
-
/** 工具调用(兼容格式) */
|
|
770
|
-
toolCalls?: Array<{
|
|
771
|
-
id: string;
|
|
772
|
-
function?: {
|
|
773
|
-
name: string;
|
|
774
|
-
arguments: string;
|
|
775
|
-
};
|
|
776
|
-
name?: string;
|
|
777
|
-
arguments?: string;
|
|
778
|
-
}>;
|
|
779
|
-
/** Usage 信息 */
|
|
780
|
-
usage?: {
|
|
781
|
-
promptTokens: number;
|
|
782
|
-
completionTokens: number;
|
|
783
|
-
totalTokens: number;
|
|
784
|
-
};
|
|
785
|
-
/** 生成模型 */
|
|
786
|
-
model?: string;
|
|
787
|
-
/** 推理内容(思考过程) */
|
|
788
|
-
reasoning?: string;
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* MemoryPlugin - Simplified
|
|
792
|
-
*
|
|
793
|
-
* 简化的记忆插件,不再自动处理。
|
|
794
|
-
*
|
|
795
|
-
* 用户应该使用 `roy memory recall --extract` 命令来手动触发记忆提取。
|
|
796
|
-
*
|
|
797
|
-
* 保留此插件是为了:
|
|
798
|
-
* 1. 保持 API 兼容性
|
|
799
|
-
* 2. 未来可以扩展为可选的自动触发
|
|
800
|
-
*/
|
|
801
|
-
declare class MemoryPlugin {
|
|
802
|
-
private config;
|
|
803
|
-
private disposed;
|
|
804
|
-
private initialized;
|
|
805
|
-
/** 项目 memory 基础目录 */
|
|
806
|
-
private projectBaseDir;
|
|
807
|
-
/** 全局 memory 基础目录 */
|
|
808
|
-
private globalBaseDir;
|
|
809
|
-
/** 当前工作目录(用于推断项目路径) */
|
|
810
|
-
private workDir;
|
|
811
|
-
/** AgentComponent 引用(延迟获取) */
|
|
812
|
-
private agentComponent;
|
|
813
|
-
constructor(baseDir: string, config?: MemoryPluginConfig);
|
|
814
|
-
/**
|
|
815
|
-
* Plugin 名称
|
|
816
|
-
*/
|
|
817
|
-
get name(): string;
|
|
818
|
-
/**
|
|
819
|
-
* 订阅的 Hook 点
|
|
820
|
-
*/
|
|
821
|
-
get hookPoint(): "agent:after.react";
|
|
822
|
-
/**
|
|
823
|
-
* 优先级
|
|
824
|
-
*/
|
|
825
|
-
get priority(): number;
|
|
826
|
-
/**
|
|
827
|
-
* 描述
|
|
828
|
-
*/
|
|
829
|
-
get description(): string;
|
|
830
|
-
/**
|
|
831
|
-
* 获取 Hook 定义
|
|
832
|
-
*/
|
|
833
|
-
get hooks(): unknown;
|
|
834
|
-
/**
|
|
835
|
-
* 初始化
|
|
836
|
-
*/
|
|
837
|
-
initialize(): Promise<void>;
|
|
838
|
-
/**
|
|
839
|
-
* 执行 Hook
|
|
840
|
-
*
|
|
841
|
-
* 简化为空操作。用户应该使用 `roy memory recall --extract` 命令。
|
|
842
|
-
*/
|
|
843
|
-
execute(ctx: HookContext2): Promise<void>;
|
|
844
|
-
/**
|
|
845
|
-
* 准备关闭
|
|
846
|
-
*/
|
|
847
|
-
prepareShutdown(): void;
|
|
848
|
-
/**
|
|
849
|
-
* 检查是否有待处理任务
|
|
850
|
-
*/
|
|
851
|
-
hasPendingTasks(): boolean;
|
|
852
|
-
/**
|
|
853
|
-
* 等待处理完成
|
|
854
|
-
*/
|
|
855
|
-
waitForCompletion(): Promise<void>;
|
|
856
|
-
/**
|
|
857
|
-
* 释放资源
|
|
858
|
-
*/
|
|
859
|
-
dispose(): Promise<void>;
|
|
860
|
-
/**
|
|
861
|
-
* 获取项目 base dir
|
|
862
|
-
*/
|
|
863
|
-
getProjectBaseDir(): string;
|
|
864
|
-
/**
|
|
865
|
-
* 获取全局 base dir
|
|
866
|
-
*/
|
|
867
|
-
getGlobalBaseDir(): string;
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* 创建 MemoryPlugin 实例
|
|
871
|
-
*/
|
|
872
|
-
declare function createMemoryPlugin(baseDir: string, config?: MemoryPluginConfig): MemoryPlugin;
|
|
873
|
-
/**
|
|
874
|
-
* 读取记忆文件
|
|
875
|
-
*
|
|
876
|
-
* @param memoryPaths - 记忆路径列表
|
|
877
|
-
* @returns 记忆内容
|
|
878
|
-
*/
|
|
879
|
-
declare function recallMemory2(memoryPaths: MemoryPath[]): Promise<string>;
|
|
880
|
-
import { ModelMessage as ModelMessage3 } from "ai";
|
|
881
|
-
/**
|
|
882
|
-
* Memory 作用域类型
|
|
883
|
-
*/
|
|
884
|
-
type MemoryScope = "project" | "global";
|
|
885
|
-
/**
|
|
886
|
-
* 项目摘要信息
|
|
887
|
-
*/
|
|
888
|
-
interface ProjectSummary2 {
|
|
889
|
-
/** 项目根目录路径 */
|
|
890
|
-
projectPath: string;
|
|
891
|
-
/** 项目名称 */
|
|
892
|
-
projectName: string;
|
|
893
|
-
/** 最后更新时间戳 */
|
|
894
|
-
lastUpdated: number;
|
|
895
|
-
/** 项目 memory.md 摘要(一段话) */
|
|
896
|
-
summary: string;
|
|
897
|
-
/** 简短摘要(几个词) */
|
|
898
|
-
shortSummary: string;
|
|
899
|
-
/** 项目 memory.md 路径 */
|
|
900
|
-
memoryMdPath: string;
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Memory Agent 输入
|
|
904
|
-
*/
|
|
905
|
-
interface MemoryAgentInput {
|
|
906
|
-
/** 作用域 */
|
|
907
|
-
scope: MemoryScope;
|
|
908
|
-
/** 基础目录(project: .roy/memory, global: ~/.config/roy-agent/memory) */
|
|
909
|
-
baseDir: string;
|
|
910
|
-
/** 当前 memory.md 内容 */
|
|
911
|
-
currentMemoryMd: string;
|
|
912
|
-
/** 当前对话消息 */
|
|
913
|
-
messages: ModelMessage3[];
|
|
914
|
-
/** 项目摘要列表(仅 global scope 使用) */
|
|
915
|
-
projectSummaries?: ProjectSummary2[];
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* Memory Agent 输出结果
|
|
919
|
-
*/
|
|
920
|
-
interface MemoryAgentResult {
|
|
921
|
-
/** 作用域 */
|
|
922
|
-
scope: MemoryScope;
|
|
923
|
-
/** 新的 memory.md 内容(全文) */
|
|
924
|
-
memoryMdContent: string;
|
|
925
|
-
/** 项目摘要(仅 project scope 输出) */
|
|
926
|
-
projectSummary?: ProjectSummary2;
|
|
927
|
-
/** 是否有更新 */
|
|
928
|
-
hasUpdates: boolean;
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* Memory Agent 配置
|
|
932
|
-
*/
|
|
933
|
-
interface MemoryAgentConfig {
|
|
934
|
-
/** Agent 名称 */
|
|
935
|
-
name: string;
|
|
936
|
-
/** System prompt */
|
|
937
|
-
systemPrompt: string;
|
|
938
|
-
/** 最大迭代次数 */
|
|
939
|
-
maxIterations: number;
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Project Memory Agent System Prompt
|
|
943
|
-
*/
|
|
944
|
-
declare const PROJECT_MEMORY_AGENT_PROMPT = "你是项目级 Memory Agent,负责整理和更新当前项目的记忆。\n\n## 你的职责\n\n1. **信息收集**:在提取记忆前,先收集项目上下文信息\n2. **从对话中提取记忆**:分析 messages,提取与项目相关的知识、决策、解决方案\n3. **生成 memory.md**:更新项目记忆索引\n\n## 信息收集步骤(重要!)\n\n在提取记忆之前,请先使用可用工具收集项目上下文:\n\n1. **阅读项目 README**:了解项目概述、功能、使用方法\n - 路径示例:README.md, README.zh-CN.md, docs/README.md\n\n2. **检查设计文档**:了解项目架构和设计决策\n - 路径示例:docs/design.md, docs/ARCHITECTURE.md, docs/superpowers/specs/*.md\n\n3. **查看代码实现**:了解关键模块和实现细节\n - 路径示例:src/**/*.ts, packages/*/src/**/*.ts\n\n4. **回顾现有 memory**:了解已有的项目记忆\n - 路径:当前目录下的 .roy/memory/memory.md\n\n## 输入信息\n\n- 当前项目的 memory.md 内容\n- 当前对话消息\n\n## 输出要求\n\n请以 JSON 格式输出结果,包含以下字段:\n- memoryMdContent: 新的 memory.md 内容\n- projectSummary: 项目摘要(包含 summary, shortSummary 等)\n- hasUpdates: 是否有更新\n\n## 记忆组织原则\n\n- 优先记录具体、可操作的记忆(代码位置、配置项、命令)\n- 避免过于抽象或通用的描述\n- 记录设计决策及其理由";
|
|
945
|
-
/**
|
|
946
|
-
* Global Memory Agent System Prompt
|
|
947
|
-
*/
|
|
948
|
-
declare const GLOBAL_MEMORY_AGENT_PROMPT = "你是全局 Memory Agent,负责整理跨项目的通用记忆。\n\n## 你的职责\n\n1. **聚合项目摘要**:分析 projectSummaries,提取共性知识\n2. **维护全局记忆**:更新全局 memory.md\n3. **维护项目索引**:在 memory.md 中维护项目列表\n4. **提取共性经验**:将项目经验提炼为通用最佳实践\n\n## 输入信息\n\n- 全局 memory.md 内容\n- 当前对话消息\n- 项目摘要列表(projectSummaries)\n\n## 输出要求\n\n请以 JSON 格式输出结果,包含以下字段:\n- memoryMdContent: 新的 memory.md 内容\n- hasUpdates: 是否有更新\n\n## 记忆组织原则\n\n- 关注跨项目共性(工作流、规范、偏好)\n- 项目索引只记录摘要和路径,不复制内容\n- 用户个人偏好(饮食、工作习惯)优先记录";
|
|
949
|
-
/**
|
|
950
|
-
* 创建 Memory Agent 配置
|
|
951
|
-
*/
|
|
952
|
-
declare function createMemoryAgent(scope: MemoryScope): MemoryAgentConfig;
|
|
953
|
-
/**
|
|
954
|
-
* 格式化 Memory Agent 输入为字符串
|
|
955
|
-
*/
|
|
956
|
-
declare function formatMemoryInput(input: MemoryAgentInput): string;
|
|
957
|
-
/**
|
|
958
|
-
* 解析 Memory Agent 输出
|
|
959
|
-
*/
|
|
960
|
-
declare function parseMemoryAgentOutput(output: string, scope: MemoryScope): MemoryAgentResult;
|
|
961
|
-
/**
|
|
962
|
-
* 创建默认的 MemoryAgentResult
|
|
963
|
-
*/
|
|
964
|
-
declare function createEmptyResult(scope: MemoryScope): MemoryAgentResult;
|
|
965
|
-
/**
|
|
966
|
-
* 构建 Project Memory Agent 输入
|
|
967
|
-
*/
|
|
968
|
-
declare function buildProjectInput(params: {
|
|
969
|
-
projectPath: string;
|
|
970
|
-
currentMemoryMd: string;
|
|
971
|
-
messages: ModelMessage3[];
|
|
972
|
-
}): Promise<MemoryAgentInput>;
|
|
973
|
-
/**
|
|
974
|
-
* 构建 Global Memory Agent 输入
|
|
975
|
-
*/
|
|
976
|
-
declare function buildGlobalInput(params: {
|
|
977
|
-
baseDir: string;
|
|
978
|
-
currentMemoryMd: string;
|
|
979
|
-
messages: ModelMessage3[];
|
|
980
|
-
projectSummaries?: ProjectSummary2[];
|
|
981
|
-
}): MemoryAgentInput;
|
|
982
|
-
/**
|
|
983
|
-
* 应用 Memory Agent 结果到文件系统
|
|
984
|
-
*
|
|
985
|
-
* @param result MemoryAgent 结果
|
|
986
|
-
* @param baseDir 基础目录
|
|
987
|
-
*/
|
|
988
|
-
declare function applyMemoryResult(result: MemoryAgentResult, baseDir: string): Promise<void>;
|
|
989
|
-
/**
|
|
990
|
-
* 生成项目摘要
|
|
991
|
-
*/
|
|
992
|
-
declare function generateProjectSummary(params: {
|
|
993
|
-
projectPath: string;
|
|
994
|
-
projectName: string;
|
|
995
|
-
memoryMdContent: string;
|
|
996
|
-
memoryMdPath: string;
|
|
997
|
-
}): ProjectSummary2;
|
|
998
|
-
/**
|
|
999
|
-
* 默认配置
|
|
1000
|
-
*/
|
|
1001
|
-
declare const DEFAULT_MEMORY_CONFIG: MemoryConfig;
|
|
1002
|
-
/**
|
|
1003
|
-
* 优先级映射(后面的优先级更高)
|
|
1004
|
-
*/
|
|
1005
|
-
declare const SOURCE_PRIORITY: Record<string, number>;
|
|
1006
|
-
/**
|
|
1007
|
-
* 获取来源优先级
|
|
1008
|
-
*/
|
|
1009
|
-
declare function getSourcePriority(source: string): number;
|
|
1010
|
-
import { ZodType as ZodType3, ZodTypeDef as ZodTypeDef2 } from "zod";
|
|
1011
|
-
/**
|
|
1012
|
-
* @fileoverview Environment types and interfaces
|
|
1013
|
-
*
|
|
1014
|
-
* 定义 Environment 的核心类型,包括:
|
|
1015
|
-
* - Environment 配置
|
|
1016
|
-
* - EnvEvent 事件类型
|
|
1017
|
-
*/
|
|
1018
|
-
/**
|
|
1019
|
-
* Environment Config
|
|
1020
|
-
*/
|
|
1021
|
-
interface EnvironmentConfig {
|
|
1022
|
-
/** 环境名称 */
|
|
1023
|
-
name: string;
|
|
1024
|
-
/** 环境版本 */
|
|
1025
|
-
version: string;
|
|
1026
|
-
/** 是否启用 */
|
|
1027
|
-
enabled: boolean;
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* EnvEvent 元信息
|
|
1031
|
-
*/
|
|
1032
|
-
interface EnvEventMetadata {
|
|
1033
|
-
/** 触发事件的 session ID */
|
|
1034
|
-
trigger_session_id?: string;
|
|
1035
|
-
/** 触发事件的 agent ID */
|
|
1036
|
-
trigger_agent_id?: string;
|
|
1037
|
-
/** Agent 名称 */
|
|
1038
|
-
trigger_agent_name?: string;
|
|
1039
|
-
/** 环境名称 */
|
|
1040
|
-
env_name?: string;
|
|
1041
|
-
/** 事件来源 */
|
|
1042
|
-
source?: string;
|
|
1043
|
-
/** 其他元数据 */
|
|
1044
|
-
[key: string]: unknown;
|
|
1045
|
-
}
|
|
1046
|
-
/**
|
|
1047
|
-
* EnvEvent
|
|
1048
|
-
*
|
|
1049
|
-
* 统一的事件机制,用于:
|
|
1050
|
-
* - Stream 事件(stream.start, stream.text, stream.completed 等)
|
|
1051
|
-
* - 工具调用事件(tool.call, tool.result 等)
|
|
1052
|
-
* - 会话事件(session.created, session.updated 等)
|
|
1053
|
-
* - Agent 事件(agent.thinking, agent.acting 等)
|
|
1054
|
-
*/
|
|
1055
|
-
interface EnvEvent<T = unknown> {
|
|
1056
|
-
/** 事件 ID */
|
|
1057
|
-
id: string;
|
|
1058
|
-
/** 事件类型 */
|
|
1059
|
-
type: string;
|
|
1060
|
-
/** 时间戳 */
|
|
1061
|
-
timestamp: number;
|
|
1062
|
-
/** 元信息 */
|
|
1063
|
-
metadata: EnvEventMetadata;
|
|
1064
|
-
/** 事件负载 */
|
|
1065
|
-
payload: T;
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* EnvEvent Handler
|
|
1069
|
-
*/
|
|
1070
|
-
type EnvEventHandler = (event: EnvEvent) => void | Promise<void>;
|
|
1071
|
-
/**
|
|
1072
|
-
* EnvEvent 创建参数(部分属性,可选)
|
|
1073
|
-
*
|
|
1074
|
-
* 用于 pushEnvEvent 方法,允许传入部分属性,自动补全必填字段
|
|
1075
|
-
*/
|
|
1076
|
-
interface EnvEventInput {
|
|
1077
|
-
/** 事件类型(必填) */
|
|
1078
|
-
type: string;
|
|
1079
|
-
/** 事件 ID(可选,自动生成) */
|
|
1080
|
-
id?: string;
|
|
1081
|
-
/** 时间戳(可选,自动生成) */
|
|
1082
|
-
timestamp?: number;
|
|
1083
|
-
/** 元信息(可选,自动创建) */
|
|
1084
|
-
metadata?: EnvEventMetadata;
|
|
1085
|
-
/** 事件负载(可选) */
|
|
1086
|
-
payload?: unknown;
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Action 类型
|
|
1090
|
-
*/
|
|
1091
|
-
interface Action {
|
|
1092
|
-
/** Action 类型 */
|
|
1093
|
-
type: string;
|
|
1094
|
-
/** Action 参数 */
|
|
1095
|
-
params?: Record<string, unknown>;
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Tool Result
|
|
1099
|
-
*/
|
|
1100
|
-
interface ToolResult3 {
|
|
1101
|
-
/** 是否成功 */
|
|
1102
|
-
success: boolean;
|
|
1103
|
-
/** 输出内容 */
|
|
1104
|
-
output: string | Record<string, unknown>;
|
|
1105
|
-
/** 错误信息 */
|
|
1106
|
-
error?: string;
|
|
1107
|
-
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Context
|
|
1110
|
-
*/
|
|
1111
|
-
interface Context {
|
|
1112
|
-
/** 会话 ID */
|
|
1113
|
-
sessionId?: string;
|
|
1114
|
-
/** 用户 ID */
|
|
1115
|
-
userId?: string;
|
|
1116
|
-
/** 工作目录 */
|
|
1117
|
-
workdir?: string;
|
|
1118
|
-
/** 中断信号 */
|
|
1119
|
-
abort?: AbortSignal;
|
|
1120
|
-
/** 元数据 */
|
|
1121
|
-
metadata?: Record<string, unknown>;
|
|
1122
|
-
}
|
|
1123
|
-
import { ZodType as ZodType2, ZodTypeDef } from "zod";
|
|
1124
|
-
/**
|
|
1125
|
-
* ConfigSource 类型
|
|
1126
|
-
*/
|
|
1127
|
-
type ConfigSourceType = "memory" | "file" | "env" | "remote";
|
|
1128
|
-
/**
|
|
1129
|
-
* SourceRegistration - Source 注册配置
|
|
1130
|
-
*/
|
|
1131
|
-
interface SourceRegistration {
|
|
1132
|
-
/** Source 类型 */
|
|
1133
|
-
type: ConfigSourceType;
|
|
1134
|
-
/** 相对路径(file 类型使用,基于 XDG_DATA_HOME) */
|
|
1135
|
-
relativePath?: string;
|
|
1136
|
-
/** 环境变量前缀(env 类型使用) */
|
|
1137
|
-
envPrefix?: string;
|
|
1138
|
-
/** 优先级,默认值:memory=0, file=10, env=20 */
|
|
1139
|
-
priority?: number;
|
|
1140
|
-
/** 是否可选(file 类型使用,文件不存在时不报错) */
|
|
1141
|
-
optional?: boolean;
|
|
1142
|
-
/** 是否启用文件监听(file 类型使用,默认 true) */
|
|
1143
|
-
watch?: boolean;
|
|
1144
|
-
}
|
|
1145
|
-
/**
|
|
1146
|
-
* KeyRegistration - 配置 Key 注册
|
|
1147
|
-
*/
|
|
1148
|
-
interface KeyRegistration {
|
|
1149
|
-
/** 配置 Key(支持点号嵌套,如 "llm.provider") */
|
|
1150
|
-
key: string;
|
|
1151
|
-
/** 优先使用的 Source 列表(按优先级从低到高) */
|
|
1152
|
-
sources: ConfigSourceType[];
|
|
1153
|
-
/** 自定义优先级(覆盖默认优先级) */
|
|
1154
|
-
priority?: number;
|
|
1155
|
-
/** 默认值 */
|
|
1156
|
-
default?: unknown;
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* ComponentRegistration - Component 注册配置
|
|
1160
|
-
*/
|
|
1161
|
-
interface ComponentRegistration {
|
|
1162
|
-
/** Component 名称 */
|
|
1163
|
-
name: string;
|
|
1164
|
-
/** 声明需要的 Source */
|
|
1165
|
-
sources: SourceRegistration[];
|
|
1166
|
-
/** 声明需要的配置 Key */
|
|
1167
|
-
keys: KeyRegistration[];
|
|
1168
|
-
/** 配置 Schema(用于验证,可选) */
|
|
1169
|
-
schema?: ZodType2<unknown, ZodTypeDef, unknown>;
|
|
1170
|
-
/** 默认值 */
|
|
1171
|
-
defaults?: Record<string, unknown>;
|
|
1172
|
-
}
|
|
1173
|
-
/**
|
|
1174
|
-
* ConfigSource 接口
|
|
1175
|
-
*/
|
|
1176
|
-
interface ConfigSource {
|
|
1177
|
-
readonly name: ConfigSourceType;
|
|
1178
|
-
readonly priority: number;
|
|
1179
|
-
read(key: string): unknown | undefined;
|
|
1180
|
-
write?(key: string, value: unknown): boolean;
|
|
1181
|
-
delete?(key: string): boolean;
|
|
1182
|
-
list(): Array<{
|
|
1183
|
-
key: string;
|
|
1184
|
-
value: unknown;
|
|
1185
|
-
}>;
|
|
1186
|
-
watch?(callback: (event: ConfigChangeEvent) => void): () => void;
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Config 变更事件
|
|
1190
|
-
*/
|
|
1191
|
-
interface ConfigChangeEvent {
|
|
1192
|
-
type: "change" | "add" | "delete";
|
|
1193
|
-
key: string;
|
|
1194
|
-
oldValue: unknown;
|
|
1195
|
-
newValue: unknown;
|
|
1196
|
-
source: ConfigSourceType;
|
|
1197
|
-
timestamp: number;
|
|
1198
|
-
}
|
|
1199
|
-
/**
|
|
1200
|
-
* ConfigComponent 配置
|
|
1201
|
-
*/
|
|
1202
|
-
interface ConfigComponentOptions {
|
|
1203
|
-
/** 持久化文件路径 */
|
|
1204
|
-
persistFile?: string;
|
|
1205
|
-
/** 防抖延迟(ms) */
|
|
1206
|
-
debounceMs?: number;
|
|
1207
|
-
/** 最大批量大小 */
|
|
1208
|
-
maxBatchSize?: number;
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* ConfigComponent
|
|
1212
|
-
*/
|
|
1213
|
-
declare class ConfigComponent extends BaseComponent {
|
|
1214
|
-
readonly name = "config";
|
|
1215
|
-
readonly version = "1.0.0";
|
|
1216
|
-
private memorySource;
|
|
1217
|
-
private sources;
|
|
1218
|
-
private componentSchemas;
|
|
1219
|
-
private componentPaths;
|
|
1220
|
-
private watchers;
|
|
1221
|
-
/** Source watch unsubscribe 函数 */
|
|
1222
|
-
private sourceUnwatchFns;
|
|
1223
|
-
private persistQueue;
|
|
1224
|
-
private persistFile?;
|
|
1225
|
-
/** Key 注册表:key -> KeyRegistration */
|
|
1226
|
-
private keyRegistry;
|
|
1227
|
-
/** Component 注册表:name -> ComponentRegistration */
|
|
1228
|
-
private componentRegistrations;
|
|
1229
|
-
/** 协议解析器 */
|
|
1230
|
-
private protocolResolver?;
|
|
1231
|
-
/** XDG_DATA_HOME 缓存(用于测试注入) */
|
|
1232
|
-
private __xdgDataHome?;
|
|
1233
|
-
/** Source 注册配置(延迟创建) */
|
|
1234
|
-
private pendingSources;
|
|
1235
|
-
/** Source 唯一标识缓存:type:relativePath -> true */
|
|
1236
|
-
private sourceKeys;
|
|
1237
|
-
/**
|
|
1238
|
-
* 获取 XDG_DATA_HOME(动态获取,支持运行时覆盖)
|
|
1239
|
-
*/
|
|
1240
|
-
getXdgDataHome(): string;
|
|
1241
|
-
/**
|
|
1242
|
-
* 设置 XDG_DATA_HOME(用于测试)
|
|
1243
|
-
*/
|
|
1244
|
-
setXdgDataHome(path: string): void;
|
|
1245
|
-
constructor(options?: ConfigComponentOptions);
|
|
1246
|
-
/**
|
|
1247
|
-
* 注册 Component Schema
|
|
1248
|
-
*/
|
|
1249
|
-
register(schema: ComponentSchema): void;
|
|
1250
|
-
/**
|
|
1251
|
-
* 注销 Component
|
|
1252
|
-
*/
|
|
1253
|
-
unregister(name: string): boolean;
|
|
1254
|
-
/**
|
|
1255
|
-
* 检查是否已注册
|
|
1256
|
-
*/
|
|
1257
|
-
isRegistered(name: string): boolean;
|
|
1258
|
-
/**
|
|
1259
|
-
* 列出所有注册的 Component
|
|
1260
|
-
*/
|
|
1261
|
-
listComponents(): string[];
|
|
1262
|
-
/**
|
|
1263
|
-
* 获取配置值(支持 xxx.yyy.zzz 嵌套访问)
|
|
1264
|
-
* 支持两种模式:
|
|
1265
|
-
* 1. 完整 key:直接查找,如 "component.key" -> 读取 "component.key"
|
|
1266
|
-
* 2. 嵌套对象:查找 component 对象后从中获取属性,如 "component.nested.deep"
|
|
1267
|
-
* -> 先找 "component.nested",再获取其 "deep" 属性
|
|
1268
|
-
*/
|
|
1269
|
-
get(key: string): unknown;
|
|
1270
|
-
/**
|
|
1271
|
-
* 批量获取
|
|
1272
|
-
*/
|
|
1273
|
-
getMany(keys: string[]): Record<string, unknown>;
|
|
1274
|
-
/**
|
|
1275
|
-
* 设置配置值(内存级别 + 异步持久化)
|
|
1276
|
-
*/
|
|
1277
|
-
set(key: string, value: unknown): Promise<void>;
|
|
1278
|
-
/**
|
|
1279
|
-
* 批量设置
|
|
1280
|
-
*/
|
|
1281
|
-
setMany(config: Record<string, unknown>): Promise<void>;
|
|
1282
|
-
/**
|
|
1283
|
-
* 获取 Component 的路径
|
|
1284
|
-
*/
|
|
1285
|
-
getPath(component: string, subPath?: string): string;
|
|
1286
|
-
/**
|
|
1287
|
-
* 手动持久化
|
|
1288
|
-
*/
|
|
1289
|
-
save(key?: string): Promise<void>;
|
|
1290
|
-
/**
|
|
1291
|
-
* 重置到默认值
|
|
1292
|
-
*/
|
|
1293
|
-
reset(key: string): Promise<void>;
|
|
1294
|
-
/**
|
|
1295
|
-
* 监听配置变更
|
|
1296
|
-
*/
|
|
1297
|
-
watch(pattern: string, callback: ComponentWatchCallback): () => void;
|
|
1298
|
-
/**
|
|
1299
|
-
* 添加配置源
|
|
1300
|
-
*/
|
|
1301
|
-
addSource(source: ConfigSource): void;
|
|
1302
|
-
/**
|
|
1303
|
-
* 获取 Source 唯一标识
|
|
1304
|
-
*/
|
|
1305
|
-
private getSourceKey;
|
|
1306
|
-
/**
|
|
1307
|
-
* 移除配置源
|
|
1308
|
-
*/
|
|
1309
|
-
removeSource(name: ConfigSourceType): boolean;
|
|
1310
|
-
/**
|
|
1311
|
-
* 关闭所有配置源的 watcher(用于优雅退出)
|
|
1312
|
-
*/
|
|
1313
|
-
unwatchAll(): void;
|
|
1314
|
-
/**
|
|
1315
|
-
* 获取配置源列表
|
|
1316
|
-
*/
|
|
1317
|
-
getSources(): ConfigSource[];
|
|
1318
|
-
private getNestedValue;
|
|
1319
|
-
private notifyWatchers;
|
|
1320
|
-
private persistToFile;
|
|
1321
|
-
/**
|
|
1322
|
-
* 注册配置 Source
|
|
1323
|
-
*
|
|
1324
|
-
* Source 会在首次 load() 时被创建
|
|
1325
|
-
*
|
|
1326
|
-
* @example
|
|
1327
|
-
* config.registerSource({ type: "file", relativePath: "llm-config.jsonc" });
|
|
1328
|
-
* config.registerSource({ type: "env", envPrefix: "LLM" });
|
|
1329
|
-
*/
|
|
1330
|
-
registerSource(registration: SourceRegistration): void;
|
|
1331
|
-
/**
|
|
1332
|
-
* 创建 Source 实例
|
|
1333
|
-
*/
|
|
1334
|
-
private createSource;
|
|
1335
|
-
/**
|
|
1336
|
-
* 确保所有待创建的 Source 已被创建
|
|
1337
|
-
*/
|
|
1338
|
-
private ensureSourcesCreated;
|
|
1339
|
-
/**
|
|
1340
|
-
* 注册配置 Key
|
|
1341
|
-
*
|
|
1342
|
-
* @example
|
|
1343
|
-
* config.registerKeys([
|
|
1344
|
-
* { key: "llm.provider", sources: ["file", "memory"], default: "openai" },
|
|
1345
|
-
* { key: "llm.model", sources: ["file"] },
|
|
1346
|
-
* ]);
|
|
1347
|
-
*/
|
|
1348
|
-
registerKeys(keys: KeyRegistration[]): void;
|
|
1349
|
-
/**
|
|
1350
|
-
* 注册 Component(一次性注册 Source 和 Keys)
|
|
1351
|
-
*
|
|
1352
|
-
* @example
|
|
1353
|
-
* config.registerComponent({
|
|
1354
|
-
* name: "llm",
|
|
1355
|
-
* sources: [
|
|
1356
|
-
* { type: "file", relativePath: "llm-config.jsonc" },
|
|
1357
|
-
* { type: "env", envPrefix: "LLM" },
|
|
1358
|
-
* ],
|
|
1359
|
-
* keys: [
|
|
1360
|
-
* { key: "llm.provider", sources: ["file", "env", "memory"] },
|
|
1361
|
-
* ],
|
|
1362
|
-
* });
|
|
1363
|
-
*/
|
|
1364
|
-
registerComponent(registration: ComponentRegistration): void;
|
|
1365
|
-
/**
|
|
1366
|
-
* 按需加载配置
|
|
1367
|
-
*
|
|
1368
|
-
* 从注册的 Source 加载已注册 Keys 的配置值到内存中
|
|
1369
|
-
*
|
|
1370
|
-
* @param componentName - 可选,指定要加载的 Component 名称
|
|
1371
|
-
*
|
|
1372
|
-
* @example
|
|
1373
|
-
* // 加载所有已注册的 Keys
|
|
1374
|
-
* await config.load();
|
|
1375
|
-
*
|
|
1376
|
-
* // 只加载指定 Component 的 Keys
|
|
1377
|
-
* await config.load("llm");
|
|
1378
|
-
*/
|
|
1379
|
-
load(componentName?: string): Promise<void>;
|
|
1380
|
-
/**
|
|
1381
|
-
* 获取已注册的 Source 列表
|
|
1382
|
-
*/
|
|
1383
|
-
getRegisteredSources(): ConfigSource[];
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* 服务配置接口
|
|
1387
|
-
*/
|
|
1388
|
-
interface ServiceConfig {
|
|
1389
|
-
/** 环境配置 */
|
|
1390
|
-
environment?: {
|
|
1391
|
-
name?: string;
|
|
1392
|
-
version?: string;
|
|
1393
|
-
};
|
|
1394
|
-
/** 组件配置映射 */
|
|
1395
|
-
components?: Record<string, ComponentConfigEntry>;
|
|
1396
|
-
}
|
|
1397
|
-
/**
|
|
1398
|
-
* 组件配置项
|
|
1399
|
-
*/
|
|
1400
|
-
interface ComponentConfigEntry {
|
|
1401
|
-
/** 配置文件路径(可选) */
|
|
1402
|
-
configPath?: string;
|
|
1403
|
-
/** 环境变量前缀(可选) */
|
|
1404
|
-
envPrefix?: string;
|
|
1405
|
-
/** 直接配置对象(可选) */
|
|
1406
|
-
config?: Record<string, unknown>;
|
|
1407
|
-
/** 是否启用(可选,默认 true) */
|
|
1408
|
-
enabled?: boolean;
|
|
1409
|
-
}
|
|
1410
|
-
/**
|
|
1411
|
-
* 组件初始化选项(由 generateComponentOptions 生成)
|
|
1412
|
-
*/
|
|
1413
|
-
interface GeneratedComponentOptions {
|
|
1414
|
-
/** ConfigComponent 实例 */
|
|
1415
|
-
configComponent: ConfigComponent;
|
|
1416
|
-
/** 配置文件路径 */
|
|
1417
|
-
configPath?: string;
|
|
1418
|
-
/** 环境变量前缀 */
|
|
1419
|
-
envPrefix?: string;
|
|
1420
|
-
/** 直接配置对象 */
|
|
1421
|
-
config?: Record<string, unknown>;
|
|
1422
|
-
/** 允许的其他属性 */
|
|
1423
|
-
[key: string]: unknown;
|
|
1424
|
-
}
|
|
1425
|
-
/**
|
|
1426
|
-
* Environment 接口
|
|
1427
|
-
*
|
|
1428
|
-
* 定义 Agent 运行时的核心能力接口。
|
|
1429
|
-
*/
|
|
1430
|
-
interface Environment {
|
|
1431
|
-
/** 环境名称 */
|
|
1432
|
-
readonly name: string;
|
|
1433
|
-
/** 环境版本 */
|
|
1434
|
-
readonly version: string;
|
|
1435
|
-
/** 获取环境配置 */
|
|
1436
|
-
getConfig(): EnvironmentConfig;
|
|
1437
|
-
/**
|
|
1438
|
-
* 注册组件
|
|
1439
|
-
*/
|
|
1440
|
-
registerComponent(component: Component): void;
|
|
1441
|
-
/**
|
|
1442
|
-
* 注销组件
|
|
1443
|
-
*/
|
|
1444
|
-
unregisterComponent(name: string): void;
|
|
1445
|
-
/**
|
|
1446
|
-
* 获取组件
|
|
1447
|
-
*/
|
|
1448
|
-
getComponent<T extends Component>(name: string): T | undefined;
|
|
1449
|
-
/**
|
|
1450
|
-
* 列出所有组件
|
|
1451
|
-
*/
|
|
1452
|
-
listComponents(): Component[];
|
|
1453
|
-
/**
|
|
1454
|
-
* 处理自然语言查询(核心入口)
|
|
1455
|
-
*
|
|
1456
|
-
* @param query 用户查询文本
|
|
1457
|
-
* @param context 执行上下文(可选)
|
|
1458
|
-
* @returns 完整的文本响应
|
|
1459
|
-
*/
|
|
1460
|
-
handle_query(query: string, context?: AgentContext): Promise<string>;
|
|
1461
|
-
/**
|
|
1462
|
-
* 处理动作
|
|
1463
|
-
*/
|
|
1464
|
-
handle_action(action: Action, context: Context): Promise<ToolResult3>;
|
|
1465
|
-
/**
|
|
1466
|
-
* 订阅 EnvEvent(返回取消订阅函数)
|
|
1467
|
-
*/
|
|
1468
|
-
subscribe(handler: EnvEventHandler): () => void;
|
|
1469
|
-
/**
|
|
1470
|
-
* 订阅指定类型事件
|
|
1471
|
-
*/
|
|
1472
|
-
subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
|
|
1473
|
-
/**
|
|
1474
|
-
* 订阅所有事件(通配符)
|
|
1475
|
-
*/
|
|
1476
|
-
subscribeAll(handler: EnvEventHandler): () => void;
|
|
1477
|
-
/**
|
|
1478
|
-
* 推送事件
|
|
1479
|
-
*
|
|
1480
|
-
* @param event EnvEvent 或 EnvEventInput(部分属性)
|
|
1481
|
-
*/
|
|
1482
|
-
pushEnvEvent(event: EnvEvent | EnvEventInput): void;
|
|
1483
|
-
/**
|
|
1484
|
-
* 从配置文件加载服务配置
|
|
1485
|
-
*
|
|
1486
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
1487
|
-
* @returns 解析后的服务配置对象
|
|
1488
|
-
*/
|
|
1489
|
-
loadServiceConfig(configPath: string): Promise<ServiceConfig>;
|
|
1490
|
-
/**
|
|
1491
|
-
* 生成组件初始化选项
|
|
1492
|
-
*
|
|
1493
|
-
* 根据组件配置项生成可用于初始化的选项对象。
|
|
1494
|
-
*
|
|
1495
|
-
* @param componentName 组件名称
|
|
1496
|
-
* @param configEntry 组件配置项
|
|
1497
|
-
* @returns 生成的组件初始化选项
|
|
1498
|
-
*/
|
|
1499
|
-
generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
|
|
1500
|
-
/**
|
|
1501
|
-
* 注册组件并用配置初始化
|
|
1502
|
-
*
|
|
1503
|
-
* 便捷方法:注册组件并通过 ConfigComponent 初始化。
|
|
1504
|
-
*
|
|
1505
|
-
* @param component 要注册的组件实例
|
|
1506
|
-
* @param configEntry 组件配置项
|
|
1507
|
-
*/
|
|
1508
|
-
registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
|
|
1509
|
-
/**
|
|
1510
|
-
* 从配置文件初始化整个环境
|
|
1511
|
-
*
|
|
1512
|
-
* 加载服务配置,注册并初始化所有配置的组件。
|
|
1513
|
-
*
|
|
1514
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
1515
|
-
*/
|
|
1516
|
-
initFromConfig(configPath: string): Promise<void>;
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Component 状态
|
|
1520
|
-
*/
|
|
1521
|
-
type ComponentStatus = "created" | "initializing" | "running" | "stopping" | "stopped" | "error";
|
|
1522
|
-
/**
|
|
1523
|
-
* Component 配置
|
|
1524
|
-
*/
|
|
1525
|
-
interface ComponentConfig {
|
|
1526
|
-
name: string;
|
|
1527
|
-
version: string;
|
|
1528
|
-
enabled: boolean;
|
|
1529
|
-
options?: Record<string, unknown>;
|
|
1530
|
-
/**
|
|
1531
|
-
* Environment 实例(可选)
|
|
1532
|
-
*
|
|
1533
|
-
* 推荐在 init 时接收 env 实例,以便:
|
|
1534
|
-
* - 通过 env.getComponent() 获取其他组件
|
|
1535
|
-
* - 通过 env.pushEnvEvent() 发布事件
|
|
1536
|
-
* - 通过 env.handle_query() 处理查询
|
|
1537
|
-
*
|
|
1538
|
-
* 如果未提供,部分 Component 仍可正常工作(如测试场景)
|
|
1539
|
-
*
|
|
1540
|
-
* @example
|
|
1541
|
-
* ```typescript
|
|
1542
|
-
* async onInit(): Promise<void> {
|
|
1543
|
-
* if (this.env) {
|
|
1544
|
-
* const configComp = this.env.getComponent("config");
|
|
1545
|
-
* }
|
|
1546
|
-
* }
|
|
1547
|
-
* ```
|
|
1548
|
-
*/
|
|
1549
|
-
env?: Environment;
|
|
1550
|
-
}
|
|
1551
|
-
/**
|
|
1552
|
-
* Component 路径声明
|
|
1553
|
-
*/
|
|
1554
|
-
interface ComponentPaths {
|
|
1555
|
-
base: "config" | "state" | "data" | "cache";
|
|
1556
|
-
subPath: string;
|
|
1557
|
-
isDirectory: boolean;
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* Component Schema(注册配置)
|
|
1561
|
-
*/
|
|
1562
|
-
interface ComponentSchema {
|
|
1563
|
-
/** Component 名称 */
|
|
1564
|
-
name: string;
|
|
1565
|
-
/** 配置 Schema(Zod) */
|
|
1566
|
-
schema: ZodType3<unknown, ZodTypeDef2, unknown>;
|
|
1567
|
-
/** 默认值(从 Schema 提取) */
|
|
1568
|
-
defaults: Record<string, unknown>;
|
|
1569
|
-
/** 路径声明 */
|
|
1570
|
-
paths?: Record<string, ComponentPaths>;
|
|
1571
|
-
/** 元信息 */
|
|
1572
|
-
metadata?: {
|
|
1573
|
-
description?: string;
|
|
1574
|
-
version?: string;
|
|
1575
|
-
author?: string;
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
/**
|
|
1579
|
-
* Component 配置变更事件
|
|
1580
|
-
*/
|
|
1581
|
-
interface ComponentConfigChangeEvent {
|
|
1582
|
-
/** Component 名称 */
|
|
1583
|
-
component: string;
|
|
1584
|
-
/** 变更的配置键 */
|
|
1585
|
-
key: string;
|
|
1586
|
-
/** 旧值 */
|
|
1587
|
-
oldValue: unknown;
|
|
1588
|
-
/** 新值 */
|
|
1589
|
-
newValue: unknown;
|
|
1590
|
-
/** 是否持久化 */
|
|
1591
|
-
persisted: boolean;
|
|
1592
|
-
/** 时间戳 */
|
|
1593
|
-
timestamp: number;
|
|
1594
|
-
}
|
|
1595
|
-
/**
|
|
1596
|
-
* Component 配置监听回调
|
|
1597
|
-
*/
|
|
1598
|
-
type ComponentWatchCallback = (event: ComponentConfigChangeEvent) => void | Promise<void>;
|
|
1599
|
-
/**
|
|
1600
|
-
* Component 基类接口
|
|
1601
|
-
*/
|
|
1602
|
-
interface Component {
|
|
1603
|
-
/** Component 名称 */
|
|
1604
|
-
readonly name: string;
|
|
1605
|
-
/** Component 版本 */
|
|
1606
|
-
readonly version: string;
|
|
1607
|
-
/** 获取状态 */
|
|
1608
|
-
getStatus(): ComponentStatus;
|
|
1609
|
-
/** 获取配置 */
|
|
1610
|
-
getConfig(): ComponentConfig;
|
|
1611
|
-
/** 初始化 */
|
|
1612
|
-
init(config: ComponentConfig): Promise<void>;
|
|
1613
|
-
/** 启动 */
|
|
1614
|
-
start(): Promise<void>;
|
|
1615
|
-
/** 停止 */
|
|
1616
|
-
stop(): Promise<void>;
|
|
1617
|
-
}
|
|
1618
|
-
/**
|
|
1619
|
-
* Component 基类实现
|
|
1620
|
-
*/
|
|
1621
|
-
declare abstract class BaseComponent implements Component {
|
|
1622
|
-
abstract readonly name: string;
|
|
1623
|
-
abstract readonly version: string;
|
|
1624
|
-
protected _status: ComponentStatus;
|
|
1625
|
-
protected _enabled: boolean;
|
|
1626
|
-
protected env: Environment;
|
|
1627
|
-
/** Hook 管理器 - 子类初始化时由构造函数设置 */
|
|
1628
|
-
readonly hookManager: HookManager;
|
|
1629
|
-
constructor();
|
|
1630
|
-
getStatus(): ComponentStatus;
|
|
1631
|
-
getConfig(): ComponentConfig;
|
|
1632
|
-
/**
|
|
1633
|
-
* 检查 Environment 是否已初始化
|
|
1634
|
-
*/
|
|
1635
|
-
protected isEnvInitialized(): boolean;
|
|
1636
|
-
protected setStatus(status: ComponentStatus): void;
|
|
1637
|
-
/**
|
|
1638
|
-
* 获取 Environment 实例
|
|
1639
|
-
*/
|
|
1640
|
-
protected getEnv(): Environment;
|
|
1641
|
-
init(config?: ComponentConfig): Promise<void>;
|
|
1642
|
-
start(): Promise<void>;
|
|
1643
|
-
stop(): Promise<void>;
|
|
1644
|
-
/**
|
|
1645
|
-
* 子类可覆盖的钩子方法
|
|
1646
|
-
*/
|
|
1647
|
-
protected onInit(): Promise<void>;
|
|
1648
|
-
protected onStart(): Promise<void>;
|
|
1649
|
-
protected onStop(): Promise<void>;
|
|
1650
|
-
/**
|
|
1651
|
-
* 注册 Hook
|
|
1652
|
-
*
|
|
1653
|
-
* @param hookPoint Hook 点名称
|
|
1654
|
-
* @param hook Hook 实例
|
|
1655
|
-
*/
|
|
1656
|
-
protected registerHook<T = unknown>(hookPoint: string, hook: Hook<T>): void;
|
|
1657
|
-
/**
|
|
1658
|
-
* 便捷方法:快速注册 Hook
|
|
1659
|
-
*/
|
|
1660
|
-
protected addHook<T = unknown>(hookPoint: string, name: string, fn: HookFn<T>, priority?: number): void;
|
|
1661
|
-
/**
|
|
1662
|
-
* 便捷方法:按名称取消注册 Hook
|
|
1663
|
-
*/
|
|
1664
|
-
protected removeHook(hookPoint: string, name: string): boolean;
|
|
1665
|
-
/**
|
|
1666
|
-
* 执行 Hook
|
|
1667
|
-
*/
|
|
1668
|
-
protected executeHooks<T = unknown>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
|
|
1669
|
-
/**
|
|
1670
|
-
* 获取 ConfigComponent 实例
|
|
1671
|
-
*
|
|
1672
|
-
* 子类可使用此方法获取配置组件,支持热更新
|
|
1673
|
-
*/
|
|
1674
|
-
protected getConfigComponent(): {
|
|
1675
|
-
get(key: string): unknown;
|
|
1676
|
-
} | undefined;
|
|
1677
|
-
/**
|
|
1678
|
-
* 动态获取运行时配置值
|
|
1679
|
-
*
|
|
1680
|
-
* 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
|
|
1681
|
-
* 适用于运行时可能变化的配置(如 API Keys、模型参数)
|
|
1682
|
-
*
|
|
1683
|
-
* @param key 配置键(支持点号分隔的路径,如 "llm.temperature")
|
|
1684
|
-
* @param defaultValue 默认值
|
|
1685
|
-
* @returns 配置值或默认值
|
|
1686
|
-
*
|
|
1687
|
-
* @example
|
|
1688
|
-
* ```typescript
|
|
1689
|
-
* // 获取 LLM 温度配置(可能支持热更新)
|
|
1690
|
-
* const temperature = this.getRuntimeConfig("llm.temperature", 0.7);
|
|
1691
|
-
*
|
|
1692
|
-
* // 获取 API Key
|
|
1693
|
-
* const apiKey = this.getRuntimeConfig<string>("llm.providers.openai.apiKey");
|
|
1694
|
-
* ```
|
|
1695
|
-
*/
|
|
1696
|
-
protected getRuntimeConfig<T>(key: string, defaultValue: T): T;
|
|
1697
|
-
}
|
|
1698
|
-
/**
|
|
1699
|
-
* MemoryComponent 配置选项(通过 options 传递)
|
|
1700
|
-
*/
|
|
1701
|
-
interface MemoryComponentOptions {
|
|
1702
|
-
/** ConfigComponent 实例(必填) */
|
|
1703
|
-
configComponent: ConfigComponent;
|
|
1704
|
-
/** 配置文件相对路径(可选,基于 XDG_DATA_HOME) */
|
|
1705
|
-
configPath?: string;
|
|
1706
|
-
/** 环境变量前缀(可选,默认 "MEMORY") */
|
|
1707
|
-
envPrefix?: string;
|
|
1708
|
-
/** 直接传入的配置对象(可选,优先级最高) */
|
|
1709
|
-
config?: Partial<MemoryConfig>;
|
|
1710
|
-
}
|
|
1711
|
-
/**
|
|
1712
|
-
* MemoryComponent - Simplified
|
|
1713
|
-
*
|
|
1714
|
-
* 简化的记忆管理组件,只负责:
|
|
1715
|
-
* - 管理本地文件系统记忆存储
|
|
1716
|
-
* - 注册记忆操作工具
|
|
1717
|
-
* - 提供目录扫描和缓存
|
|
1718
|
-
*
|
|
1719
|
-
* 复杂功能已移除:
|
|
1720
|
-
* - DraftManager(草稿管理)
|
|
1721
|
-
* - MemoryOrganizer(记忆整理)
|
|
1722
|
-
* - AccessLog(访问日志)
|
|
1723
|
-
*/
|
|
1724
|
-
declare class MemoryComponent extends BaseComponent {
|
|
1725
|
-
name: string;
|
|
1726
|
-
version: string;
|
|
1727
|
-
private config;
|
|
1728
|
-
private toolComponent?;
|
|
1729
|
-
private configComponent?;
|
|
1730
|
-
private cache;
|
|
1731
|
-
/** 配置变更 watcher 清理函数 */
|
|
1732
|
-
private configWatcher?;
|
|
1733
|
-
init(config?: ComponentConfig): Promise<void>;
|
|
1734
|
-
/**
|
|
1735
|
-
* 注册配置到 ConfigComponent
|
|
1736
|
-
*/
|
|
1737
|
-
private registerConfig;
|
|
1738
|
-
/**
|
|
1739
|
-
* 构建最终配置对象
|
|
1740
|
-
*/
|
|
1741
|
-
private buildConfig;
|
|
1742
|
-
/**
|
|
1743
|
-
* 将配置对象展平为点号路径
|
|
1744
|
-
*/
|
|
1745
|
-
private flattenConfig;
|
|
1746
|
-
/**
|
|
1747
|
-
* 注册配置热更新监听
|
|
1748
|
-
*/
|
|
1749
|
-
private registerConfigWatcher;
|
|
1750
|
-
/**
|
|
1751
|
-
* 处理配置变更
|
|
1752
|
-
*/
|
|
1753
|
-
protected onConfigChange(event: {
|
|
1754
|
-
key: string;
|
|
1755
|
-
oldValue?: unknown;
|
|
1756
|
-
newValue?: unknown;
|
|
1757
|
-
}): void;
|
|
1758
|
-
start(): Promise<void>;
|
|
1759
|
-
stop(): Promise<void>;
|
|
1760
|
-
private registerTools;
|
|
1761
|
-
/**
|
|
1762
|
-
* 获取所有配置的 memory 路径
|
|
1763
|
-
*/
|
|
1764
|
-
getMemoryPaths(): MemoryPath[];
|
|
1765
|
-
/**
|
|
1766
|
-
* 更新 memory paths
|
|
1767
|
-
*/
|
|
1768
|
-
updateMemoryPaths(paths: MemoryPath[]): void;
|
|
1769
|
-
/**
|
|
1770
|
-
* 获取记忆文件名
|
|
1771
|
-
*/
|
|
1772
|
-
getMemoryFile(): string;
|
|
1773
|
-
/**
|
|
1774
|
-
* 记录记忆
|
|
1775
|
-
*
|
|
1776
|
-
* @param args.mode 操作模式
|
|
1777
|
-
* @param args.content 记忆内容
|
|
1778
|
-
* @param args.title 标题
|
|
1779
|
-
* @param args.filename 文件名
|
|
1780
|
-
* @param args.scope 作用域 (project/global),用于选择正确的 memory path
|
|
1781
|
-
*/
|
|
1782
|
-
recordMemory(args: {
|
|
1783
|
-
mode: RecordMemoryMode;
|
|
1784
|
-
content?: string;
|
|
1785
|
-
title?: string;
|
|
1786
|
-
filename?: string;
|
|
1787
|
-
scope?: "project" | "global";
|
|
1788
|
-
}): Promise<RecordMemoryResult | null>;
|
|
1789
|
-
/**
|
|
1790
|
-
* 回忆记忆 - 读取所有记忆文件内容
|
|
1791
|
-
*
|
|
1792
|
-
* @param scope 可选:project 或 global,默认读取所有
|
|
1793
|
-
*/
|
|
1794
|
-
recallMemory(scope?: "project" | "global"): Promise<string>;
|
|
1795
|
-
private clearCache;
|
|
1796
|
-
private getCache;
|
|
1797
|
-
private setCache;
|
|
1798
|
-
}
|
|
1799
|
-
export { recallMemory2 as recallMemory, parseMemoryAgentOutput, getSourcePriority, generateProjectSummary, formatMemoryInput, createMemoryPlugin, createMemoryAgent, createEmptyResult, buildProjectInput, buildGlobalInput, applyMemoryResult, SessionMessage, SOURCE_PRIORITY, RecordMemorySchema2 as RecordMemorySchema, RecordMemoryResult, RecordMemoryParams, RecordMemoryMode, RecallMemorySchema2 as RecallMemorySchema, RecallMemoryParams, ProjectSummary2 as ProjectSummary, PROJECT_MEMORY_AGENT_PROMPT, MemoryTaskType, MemoryTask, MemorySource, MemoryScope, MemoryPluginConfig, MemoryPlugin, MemoryPath, MemoryManager, MemoryHookContext, MemoryConfig, MemoryComponentOptions, MemoryComponent, MemoryAgentResult, MemoryAgentInput, MemoryAgentConfig, GLOBAL_MEMORY_AGENT_PROMPT, ExtractMemoryPayload, DEFAULT_MEMORY_CONFIG };
|