@ai-setting/roy-agent-core 1.5.16-test → 1.5.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/env/index.js +20 -8
- package/dist/env/log-trace/index.js +1 -1
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/workflow/engine/index.js +1 -1
- package/dist/env/workflow/index.js +2 -2
- package/dist/index.js +6 -7
- package/dist/shared/@ai-setting/{roy-agent-core-xq8hhqb8.js → roy-agent-core-4wjywp3c.js} +4 -2
- package/dist/shared/@ai-setting/roy-agent-core-8jxva565.js +19 -0
- package/dist/shared/@ai-setting/roy-agent-core-avq1x4t7.js +84 -0
- package/dist/shared/@ai-setting/{roy-agent-core-gq20wsgv.js → roy-agent-core-ffb9fq4v.js} +23 -2
- package/dist/shared/@ai-setting/{roy-agent-core-93zfb3r1.js → roy-agent-core-mrcxzpbg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rhmtwnw1.js → roy-agent-core-pw7cv1px.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-gbqcyegm.js → roy-agent-core-rccptwv0.js} +512 -673
- package/dist/shared/@ai-setting/{roy-agent-core-wrcy0h6z.js → roy-agent-core-ty94k28r.js} +1 -1
- package/package.json +1 -1
- package/dist/config/index.d.ts +0 -1250
- package/dist/env/agent/index.d.ts +0 -2279
- package/dist/env/commands/index.d.ts +0 -1131
- package/dist/env/debug/formatters/index.d.ts +0 -236
- package/dist/env/debug/index.d.ts +0 -1652
- package/dist/env/hook/index.d.ts +0 -279
- package/dist/env/index.d.ts +0 -3481
- package/dist/env/llm/index.d.ts +0 -1760
- package/dist/env/log-trace/index.d.ts +0 -1574
- package/dist/env/mcp/index.d.ts +0 -1331
- package/dist/env/mcp/tool/index.d.ts +0 -183
- package/dist/env/memory/built-in/index.d.ts +0 -232
- package/dist/env/memory/index.d.ts +0 -1799
- package/dist/env/memory/plugin/index.d.ts +0 -747
- package/dist/env/prompt/index.d.ts +0 -1164
- package/dist/env/session/index.d.ts +0 -1908
- package/dist/env/session/storage/index.d.ts +0 -564
- package/dist/env/skill/index.d.ts +0 -1266
- package/dist/env/skill/tool/index.d.ts +0 -193
- package/dist/env/task/delegate/index.d.ts +0 -1612
- package/dist/env/task/events/index.d.ts +0 -171
- package/dist/env/task/hooks/index.d.ts +0 -624
- package/dist/env/task/index.d.ts +0 -1553
- package/dist/env/task/plugins/index.d.ts +0 -466
- package/dist/env/task/storage/index.d.ts +0 -241
- package/dist/env/task/tools/index.d.ts +0 -1485
- package/dist/env/task/tools/operation/index.d.ts +0 -1484
- package/dist/env/tool/built-in/index.d.ts +0 -218
- package/dist/env/tool/index.d.ts +0 -1396
- package/dist/env/workflow/decorators/index.d.ts +0 -2161
- package/dist/env/workflow/engine/index.d.ts +0 -3453
- package/dist/env/workflow/index.d.ts +0 -3546
- package/dist/env/workflow/nodes/index.d.ts +0 -2092
- package/dist/env/workflow/service/index.d.ts +0 -227
- package/dist/env/workflow/storage/index.d.ts +0 -165
- package/dist/env/workflow/tools/index.d.ts +0 -416
- package/dist/env/workflow/types/index.d.ts +0 -2255
- package/dist/env/workflow/utils/index.d.ts +0 -2031
- package/dist/index.d.ts +0 -7858
|
@@ -1,1612 +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 { ZodType as ZodType3, ZodTypeDef as ZodTypeDef2 } from "zod";
|
|
206
|
-
/**
|
|
207
|
-
* @fileoverview Environment types and interfaces
|
|
208
|
-
*
|
|
209
|
-
* 定义 Environment 的核心类型,包括:
|
|
210
|
-
* - Environment 配置
|
|
211
|
-
* - EnvEvent 事件类型
|
|
212
|
-
*/
|
|
213
|
-
/**
|
|
214
|
-
* Environment Config
|
|
215
|
-
*/
|
|
216
|
-
interface EnvironmentConfig {
|
|
217
|
-
/** 环境名称 */
|
|
218
|
-
name: string;
|
|
219
|
-
/** 环境版本 */
|
|
220
|
-
version: string;
|
|
221
|
-
/** 是否启用 */
|
|
222
|
-
enabled: boolean;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* EnvEvent 元信息
|
|
226
|
-
*/
|
|
227
|
-
interface EnvEventMetadata {
|
|
228
|
-
/** 触发事件的 session ID */
|
|
229
|
-
trigger_session_id?: string;
|
|
230
|
-
/** 触发事件的 agent ID */
|
|
231
|
-
trigger_agent_id?: string;
|
|
232
|
-
/** Agent 名称 */
|
|
233
|
-
trigger_agent_name?: string;
|
|
234
|
-
/** 环境名称 */
|
|
235
|
-
env_name?: string;
|
|
236
|
-
/** 事件来源 */
|
|
237
|
-
source?: string;
|
|
238
|
-
/** 其他元数据 */
|
|
239
|
-
[key: string]: unknown;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* EnvEvent
|
|
243
|
-
*
|
|
244
|
-
* 统一的事件机制,用于:
|
|
245
|
-
* - Stream 事件(stream.start, stream.text, stream.completed 等)
|
|
246
|
-
* - 工具调用事件(tool.call, tool.result 等)
|
|
247
|
-
* - 会话事件(session.created, session.updated 等)
|
|
248
|
-
* - Agent 事件(agent.thinking, agent.acting 等)
|
|
249
|
-
*/
|
|
250
|
-
interface EnvEvent<T = unknown> {
|
|
251
|
-
/** 事件 ID */
|
|
252
|
-
id: string;
|
|
253
|
-
/** 事件类型 */
|
|
254
|
-
type: string;
|
|
255
|
-
/** 时间戳 */
|
|
256
|
-
timestamp: number;
|
|
257
|
-
/** 元信息 */
|
|
258
|
-
metadata: EnvEventMetadata;
|
|
259
|
-
/** 事件负载 */
|
|
260
|
-
payload: T;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* EnvEvent Handler
|
|
264
|
-
*/
|
|
265
|
-
type EnvEventHandler = (event: EnvEvent) => void | Promise<void>;
|
|
266
|
-
/**
|
|
267
|
-
* EnvEvent 创建参数(部分属性,可选)
|
|
268
|
-
*
|
|
269
|
-
* 用于 pushEnvEvent 方法,允许传入部分属性,自动补全必填字段
|
|
270
|
-
*/
|
|
271
|
-
interface EnvEventInput {
|
|
272
|
-
/** 事件类型(必填) */
|
|
273
|
-
type: string;
|
|
274
|
-
/** 事件 ID(可选,自动生成) */
|
|
275
|
-
id?: string;
|
|
276
|
-
/** 时间戳(可选,自动生成) */
|
|
277
|
-
timestamp?: number;
|
|
278
|
-
/** 元信息(可选,自动创建) */
|
|
279
|
-
metadata?: EnvEventMetadata;
|
|
280
|
-
/** 事件负载(可选) */
|
|
281
|
-
payload?: unknown;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Action 类型
|
|
285
|
-
*/
|
|
286
|
-
interface Action {
|
|
287
|
-
/** Action 类型 */
|
|
288
|
-
type: string;
|
|
289
|
-
/** Action 参数 */
|
|
290
|
-
params?: Record<string, unknown>;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Tool Result
|
|
294
|
-
*/
|
|
295
|
-
interface ToolResult {
|
|
296
|
-
/** 是否成功 */
|
|
297
|
-
success: boolean;
|
|
298
|
-
/** 输出内容 */
|
|
299
|
-
output: string | Record<string, unknown>;
|
|
300
|
-
/** 错误信息 */
|
|
301
|
-
error?: string;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Context
|
|
305
|
-
*/
|
|
306
|
-
interface Context {
|
|
307
|
-
/** 会话 ID */
|
|
308
|
-
sessionId?: string;
|
|
309
|
-
/** 用户 ID */
|
|
310
|
-
userId?: string;
|
|
311
|
-
/** 工作目录 */
|
|
312
|
-
workdir?: string;
|
|
313
|
-
/** 中断信号 */
|
|
314
|
-
abort?: AbortSignal;
|
|
315
|
-
/** 元数据 */
|
|
316
|
-
metadata?: Record<string, unknown>;
|
|
317
|
-
}
|
|
318
|
-
import { z as z2, ZodType, ZodError } from "zod";
|
|
319
|
-
/**
|
|
320
|
-
* 沙箱配置
|
|
321
|
-
*/
|
|
322
|
-
interface SandboxConfig {
|
|
323
|
-
/** 是否启用沙箱 */
|
|
324
|
-
enabled: boolean;
|
|
325
|
-
/** 沙箱类型 */
|
|
326
|
-
type: "native" | "docker";
|
|
327
|
-
/** 动作过滤 */
|
|
328
|
-
actionFilter?: {
|
|
329
|
-
/** 包含的动作 */
|
|
330
|
-
include?: string[];
|
|
331
|
-
/** 排除的动作 */
|
|
332
|
-
exclude?: string[];
|
|
333
|
-
};
|
|
334
|
-
/** 文件系统限制 */
|
|
335
|
-
filesystem?: {
|
|
336
|
-
/** 允许读取 */
|
|
337
|
-
allowRead?: string[];
|
|
338
|
-
/** 禁止读取 */
|
|
339
|
-
denyRead?: string[];
|
|
340
|
-
/** 允许写入 */
|
|
341
|
-
allowWrite?: string[];
|
|
342
|
-
/** 禁止写入 */
|
|
343
|
-
denyWrite?: string[];
|
|
344
|
-
};
|
|
345
|
-
/** 网络限制 */
|
|
346
|
-
network?: {
|
|
347
|
-
/** 允许的域名 */
|
|
348
|
-
allowedDomains?: string[];
|
|
349
|
-
/** 禁止的域名 */
|
|
350
|
-
deniedDomains?: string[];
|
|
351
|
-
};
|
|
352
|
-
/** Docker 配置 */
|
|
353
|
-
docker?: {
|
|
354
|
-
/** 镜像 */
|
|
355
|
-
image?: string;
|
|
356
|
-
/** 网络模式 */
|
|
357
|
-
networkMode?: "bridge" | "host" | "none";
|
|
358
|
-
/** 卷挂载 */
|
|
359
|
-
volumes?: Record<string, string>;
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* 工具执行上下文
|
|
364
|
-
*/
|
|
365
|
-
interface ToolContext {
|
|
366
|
-
/** 工作目录 */
|
|
367
|
-
workdir?: string;
|
|
368
|
-
/** 用户 ID */
|
|
369
|
-
user_id?: string;
|
|
370
|
-
/** 会话 ID */
|
|
371
|
-
session_id?: string;
|
|
372
|
-
/** 消息 ID */
|
|
373
|
-
message_id?: string;
|
|
374
|
-
/** 中断信号 */
|
|
375
|
-
abort?: AbortSignal;
|
|
376
|
-
/** 额外元数据 */
|
|
377
|
-
metadata?: Record<string, unknown>;
|
|
378
|
-
/** 沙箱配置 */
|
|
379
|
-
sandbox?: SandboxConfig;
|
|
380
|
-
/** 沙箱 Provider */
|
|
381
|
-
sandboxProvider?: unknown | null;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* 工具结果元数据
|
|
385
|
-
*/
|
|
386
|
-
interface ToolResultMetadata {
|
|
387
|
-
/** 执行时间(毫秒) */
|
|
388
|
-
execution_time_ms: number;
|
|
389
|
-
/** 输出大小(字节) */
|
|
390
|
-
output_size?: number;
|
|
391
|
-
/** 标准输出 */
|
|
392
|
-
stdout?: string;
|
|
393
|
-
/** 标准错误 */
|
|
394
|
-
stderr?: string;
|
|
395
|
-
/** 退出码 */
|
|
396
|
-
exit_code?: number;
|
|
397
|
-
/** Token 使用量 */
|
|
398
|
-
usage?: {
|
|
399
|
-
inputTokens: number;
|
|
400
|
-
outputTokens: number;
|
|
401
|
-
totalTokens?: number;
|
|
402
|
-
};
|
|
403
|
-
/** 额外元数据 */
|
|
404
|
-
[key: string]: unknown;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* 工具执行结果
|
|
408
|
-
*/
|
|
409
|
-
interface ToolResult2 {
|
|
410
|
-
/** 是否成功 */
|
|
411
|
-
success: boolean;
|
|
412
|
-
/** 输出内容 */
|
|
413
|
-
output: string | Record<string, unknown>;
|
|
414
|
-
/** 错误信息 */
|
|
415
|
-
error?: string;
|
|
416
|
-
/** 结果元数据 */
|
|
417
|
-
metadata?: ToolResultMetadata;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* 工具元数据
|
|
421
|
-
*/
|
|
422
|
-
interface ToolMetadata {
|
|
423
|
-
/** 分类 */
|
|
424
|
-
category?: string;
|
|
425
|
-
/** 标签 */
|
|
426
|
-
tags?: string[];
|
|
427
|
-
/** 版本 */
|
|
428
|
-
version?: string;
|
|
429
|
-
/** 作者 */
|
|
430
|
-
author?: string;
|
|
431
|
-
/** 是否实验性 */
|
|
432
|
-
experimental?: boolean;
|
|
433
|
-
/** MCP 工具信息(MCP adapter 使用) */
|
|
434
|
-
mcpTool?: {
|
|
435
|
-
originalName: string;
|
|
436
|
-
originalDescription: string;
|
|
437
|
-
inputSchema?: unknown;
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* 工具沙箱配置
|
|
442
|
-
*/
|
|
443
|
-
interface ToolSandboxConfig {
|
|
444
|
-
/** 是否启用沙箱 */
|
|
445
|
-
enabled: boolean;
|
|
446
|
-
/** 沙箱配置 */
|
|
447
|
-
config?: Partial<SandboxConfig>;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* 工具权限配置
|
|
451
|
-
*/
|
|
452
|
-
interface ToolPermissionConfig {
|
|
453
|
-
/** 是否需要用户确认 */
|
|
454
|
-
requireConfirmation?: boolean;
|
|
455
|
-
/** 权限级别 */
|
|
456
|
-
level?: "safe" | "dangerous" | "critical";
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* 工具信息
|
|
460
|
-
*/
|
|
461
|
-
interface ToolInfo<Parameters extends ZodType = ZodType> {
|
|
462
|
-
/** 工具名称 */
|
|
463
|
-
name: string;
|
|
464
|
-
/** 工具描述 */
|
|
465
|
-
description: string;
|
|
466
|
-
/** 参数 Schema */
|
|
467
|
-
parameters: Parameters;
|
|
468
|
-
/** 初始化函数(可选) */
|
|
469
|
-
init?: (ctx?: ToolContext) => Promise<void>;
|
|
470
|
-
/** 执行函数 */
|
|
471
|
-
execute: (args: z2.infer<Parameters>, ctx: ToolContext) => Promise<ToolResult2>;
|
|
472
|
-
/** 参数验证错误格式化(可选) */
|
|
473
|
-
formatValidationError?: (error: ZodError) => string;
|
|
474
|
-
/** 沙箱配置 */
|
|
475
|
-
sandbox?: ToolSandboxConfig;
|
|
476
|
-
/** 权限配置 */
|
|
477
|
-
permission?: ToolPermissionConfig;
|
|
478
|
-
/** 工具元数据 */
|
|
479
|
-
metadata?: ToolMetadata;
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* 工具类型别名
|
|
483
|
-
*/
|
|
484
|
-
type Tool = ToolInfo;
|
|
485
|
-
type AbortSignalType = AbortSignal;
|
|
486
|
-
/**
|
|
487
|
-
* Agent 执行上下文
|
|
488
|
-
*/
|
|
489
|
-
interface AgentContext {
|
|
490
|
-
/** 会话 ID */
|
|
491
|
-
sessionId?: string;
|
|
492
|
-
/** 消息 ID */
|
|
493
|
-
messageId?: string;
|
|
494
|
-
/** 中断信号 */
|
|
495
|
-
abort?: AbortSignalType;
|
|
496
|
-
/** 额外的上下文信息(会添加到 system prompt) */
|
|
497
|
-
additionInfo?: string;
|
|
498
|
-
/** 元数据 */
|
|
499
|
-
metadata?: Record<string, unknown>;
|
|
500
|
-
/** Agent 类型(用于选择 Behavior Spec) */
|
|
501
|
-
agentType?: string;
|
|
502
|
-
/** 使用的模型 */
|
|
503
|
-
model?: string;
|
|
504
|
-
/** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
505
|
-
allowedTools?: string[];
|
|
506
|
-
/** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
507
|
-
deniedTools?: string[];
|
|
508
|
-
/** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
|
|
509
|
-
filterHistory?: boolean;
|
|
510
|
-
}
|
|
511
|
-
import { ZodType as ZodType2, ZodTypeDef } from "zod";
|
|
512
|
-
/**
|
|
513
|
-
* ConfigSource 类型
|
|
514
|
-
*/
|
|
515
|
-
type ConfigSourceType = "memory" | "file" | "env" | "remote";
|
|
516
|
-
/**
|
|
517
|
-
* SourceRegistration - Source 注册配置
|
|
518
|
-
*/
|
|
519
|
-
interface SourceRegistration {
|
|
520
|
-
/** Source 类型 */
|
|
521
|
-
type: ConfigSourceType;
|
|
522
|
-
/** 相对路径(file 类型使用,基于 XDG_DATA_HOME) */
|
|
523
|
-
relativePath?: string;
|
|
524
|
-
/** 环境变量前缀(env 类型使用) */
|
|
525
|
-
envPrefix?: string;
|
|
526
|
-
/** 优先级,默认值:memory=0, file=10, env=20 */
|
|
527
|
-
priority?: number;
|
|
528
|
-
/** 是否可选(file 类型使用,文件不存在时不报错) */
|
|
529
|
-
optional?: boolean;
|
|
530
|
-
/** 是否启用文件监听(file 类型使用,默认 true) */
|
|
531
|
-
watch?: boolean;
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* KeyRegistration - 配置 Key 注册
|
|
535
|
-
*/
|
|
536
|
-
interface KeyRegistration {
|
|
537
|
-
/** 配置 Key(支持点号嵌套,如 "llm.provider") */
|
|
538
|
-
key: string;
|
|
539
|
-
/** 优先使用的 Source 列表(按优先级从低到高) */
|
|
540
|
-
sources: ConfigSourceType[];
|
|
541
|
-
/** 自定义优先级(覆盖默认优先级) */
|
|
542
|
-
priority?: number;
|
|
543
|
-
/** 默认值 */
|
|
544
|
-
default?: unknown;
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* ComponentRegistration - Component 注册配置
|
|
548
|
-
*/
|
|
549
|
-
interface ComponentRegistration {
|
|
550
|
-
/** Component 名称 */
|
|
551
|
-
name: string;
|
|
552
|
-
/** 声明需要的 Source */
|
|
553
|
-
sources: SourceRegistration[];
|
|
554
|
-
/** 声明需要的配置 Key */
|
|
555
|
-
keys: KeyRegistration[];
|
|
556
|
-
/** 配置 Schema(用于验证,可选) */
|
|
557
|
-
schema?: ZodType2<unknown, ZodTypeDef, unknown>;
|
|
558
|
-
/** 默认值 */
|
|
559
|
-
defaults?: Record<string, unknown>;
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* ConfigSource 接口
|
|
563
|
-
*/
|
|
564
|
-
interface ConfigSource {
|
|
565
|
-
readonly name: ConfigSourceType;
|
|
566
|
-
readonly priority: number;
|
|
567
|
-
read(key: string): unknown | undefined;
|
|
568
|
-
write?(key: string, value: unknown): boolean;
|
|
569
|
-
delete?(key: string): boolean;
|
|
570
|
-
list(): Array<{
|
|
571
|
-
key: string;
|
|
572
|
-
value: unknown;
|
|
573
|
-
}>;
|
|
574
|
-
watch?(callback: (event: ConfigChangeEvent) => void): () => void;
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Config 变更事件
|
|
578
|
-
*/
|
|
579
|
-
interface ConfigChangeEvent {
|
|
580
|
-
type: "change" | "add" | "delete";
|
|
581
|
-
key: string;
|
|
582
|
-
oldValue: unknown;
|
|
583
|
-
newValue: unknown;
|
|
584
|
-
source: ConfigSourceType;
|
|
585
|
-
timestamp: number;
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* ConfigComponent 配置
|
|
589
|
-
*/
|
|
590
|
-
interface ConfigComponentOptions {
|
|
591
|
-
/** 持久化文件路径 */
|
|
592
|
-
persistFile?: string;
|
|
593
|
-
/** 防抖延迟(ms) */
|
|
594
|
-
debounceMs?: number;
|
|
595
|
-
/** 最大批量大小 */
|
|
596
|
-
maxBatchSize?: number;
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* ConfigComponent
|
|
600
|
-
*/
|
|
601
|
-
declare class ConfigComponent extends BaseComponent {
|
|
602
|
-
readonly name = "config";
|
|
603
|
-
readonly version = "1.0.0";
|
|
604
|
-
private memorySource;
|
|
605
|
-
private sources;
|
|
606
|
-
private componentSchemas;
|
|
607
|
-
private componentPaths;
|
|
608
|
-
private watchers;
|
|
609
|
-
/** Source watch unsubscribe 函数 */
|
|
610
|
-
private sourceUnwatchFns;
|
|
611
|
-
private persistQueue;
|
|
612
|
-
private persistFile?;
|
|
613
|
-
/** Key 注册表:key -> KeyRegistration */
|
|
614
|
-
private keyRegistry;
|
|
615
|
-
/** Component 注册表:name -> ComponentRegistration */
|
|
616
|
-
private componentRegistrations;
|
|
617
|
-
/** 协议解析器 */
|
|
618
|
-
private protocolResolver?;
|
|
619
|
-
/** XDG_DATA_HOME 缓存(用于测试注入) */
|
|
620
|
-
private __xdgDataHome?;
|
|
621
|
-
/** Source 注册配置(延迟创建) */
|
|
622
|
-
private pendingSources;
|
|
623
|
-
/** Source 唯一标识缓存:type:relativePath -> true */
|
|
624
|
-
private sourceKeys;
|
|
625
|
-
/**
|
|
626
|
-
* 获取 XDG_DATA_HOME(动态获取,支持运行时覆盖)
|
|
627
|
-
*/
|
|
628
|
-
getXdgDataHome(): string;
|
|
629
|
-
/**
|
|
630
|
-
* 设置 XDG_DATA_HOME(用于测试)
|
|
631
|
-
*/
|
|
632
|
-
setXdgDataHome(path: string): void;
|
|
633
|
-
constructor(options?: ConfigComponentOptions);
|
|
634
|
-
/**
|
|
635
|
-
* 注册 Component Schema
|
|
636
|
-
*/
|
|
637
|
-
register(schema: ComponentSchema): void;
|
|
638
|
-
/**
|
|
639
|
-
* 注销 Component
|
|
640
|
-
*/
|
|
641
|
-
unregister(name: string): boolean;
|
|
642
|
-
/**
|
|
643
|
-
* 检查是否已注册
|
|
644
|
-
*/
|
|
645
|
-
isRegistered(name: string): boolean;
|
|
646
|
-
/**
|
|
647
|
-
* 列出所有注册的 Component
|
|
648
|
-
*/
|
|
649
|
-
listComponents(): string[];
|
|
650
|
-
/**
|
|
651
|
-
* 获取配置值(支持 xxx.yyy.zzz 嵌套访问)
|
|
652
|
-
* 支持两种模式:
|
|
653
|
-
* 1. 完整 key:直接查找,如 "component.key" -> 读取 "component.key"
|
|
654
|
-
* 2. 嵌套对象:查找 component 对象后从中获取属性,如 "component.nested.deep"
|
|
655
|
-
* -> 先找 "component.nested",再获取其 "deep" 属性
|
|
656
|
-
*/
|
|
657
|
-
get(key: string): unknown;
|
|
658
|
-
/**
|
|
659
|
-
* 批量获取
|
|
660
|
-
*/
|
|
661
|
-
getMany(keys: string[]): Record<string, unknown>;
|
|
662
|
-
/**
|
|
663
|
-
* 设置配置值(内存级别 + 异步持久化)
|
|
664
|
-
*/
|
|
665
|
-
set(key: string, value: unknown): Promise<void>;
|
|
666
|
-
/**
|
|
667
|
-
* 批量设置
|
|
668
|
-
*/
|
|
669
|
-
setMany(config: Record<string, unknown>): Promise<void>;
|
|
670
|
-
/**
|
|
671
|
-
* 获取 Component 的路径
|
|
672
|
-
*/
|
|
673
|
-
getPath(component: string, subPath?: string): string;
|
|
674
|
-
/**
|
|
675
|
-
* 手动持久化
|
|
676
|
-
*/
|
|
677
|
-
save(key?: string): Promise<void>;
|
|
678
|
-
/**
|
|
679
|
-
* 重置到默认值
|
|
680
|
-
*/
|
|
681
|
-
reset(key: string): Promise<void>;
|
|
682
|
-
/**
|
|
683
|
-
* 监听配置变更
|
|
684
|
-
*/
|
|
685
|
-
watch(pattern: string, callback: ComponentWatchCallback): () => void;
|
|
686
|
-
/**
|
|
687
|
-
* 添加配置源
|
|
688
|
-
*/
|
|
689
|
-
addSource(source: ConfigSource): void;
|
|
690
|
-
/**
|
|
691
|
-
* 获取 Source 唯一标识
|
|
692
|
-
*/
|
|
693
|
-
private getSourceKey;
|
|
694
|
-
/**
|
|
695
|
-
* 移除配置源
|
|
696
|
-
*/
|
|
697
|
-
removeSource(name: ConfigSourceType): boolean;
|
|
698
|
-
/**
|
|
699
|
-
* 关闭所有配置源的 watcher(用于优雅退出)
|
|
700
|
-
*/
|
|
701
|
-
unwatchAll(): void;
|
|
702
|
-
/**
|
|
703
|
-
* 获取配置源列表
|
|
704
|
-
*/
|
|
705
|
-
getSources(): ConfigSource[];
|
|
706
|
-
private getNestedValue;
|
|
707
|
-
private notifyWatchers;
|
|
708
|
-
private persistToFile;
|
|
709
|
-
/**
|
|
710
|
-
* 注册配置 Source
|
|
711
|
-
*
|
|
712
|
-
* Source 会在首次 load() 时被创建
|
|
713
|
-
*
|
|
714
|
-
* @example
|
|
715
|
-
* config.registerSource({ type: "file", relativePath: "llm-config.jsonc" });
|
|
716
|
-
* config.registerSource({ type: "env", envPrefix: "LLM" });
|
|
717
|
-
*/
|
|
718
|
-
registerSource(registration: SourceRegistration): void;
|
|
719
|
-
/**
|
|
720
|
-
* 创建 Source 实例
|
|
721
|
-
*/
|
|
722
|
-
private createSource;
|
|
723
|
-
/**
|
|
724
|
-
* 确保所有待创建的 Source 已被创建
|
|
725
|
-
*/
|
|
726
|
-
private ensureSourcesCreated;
|
|
727
|
-
/**
|
|
728
|
-
* 注册配置 Key
|
|
729
|
-
*
|
|
730
|
-
* @example
|
|
731
|
-
* config.registerKeys([
|
|
732
|
-
* { key: "llm.provider", sources: ["file", "memory"], default: "openai" },
|
|
733
|
-
* { key: "llm.model", sources: ["file"] },
|
|
734
|
-
* ]);
|
|
735
|
-
*/
|
|
736
|
-
registerKeys(keys: KeyRegistration[]): void;
|
|
737
|
-
/**
|
|
738
|
-
* 注册 Component(一次性注册 Source 和 Keys)
|
|
739
|
-
*
|
|
740
|
-
* @example
|
|
741
|
-
* config.registerComponent({
|
|
742
|
-
* name: "llm",
|
|
743
|
-
* sources: [
|
|
744
|
-
* { type: "file", relativePath: "llm-config.jsonc" },
|
|
745
|
-
* { type: "env", envPrefix: "LLM" },
|
|
746
|
-
* ],
|
|
747
|
-
* keys: [
|
|
748
|
-
* { key: "llm.provider", sources: ["file", "env", "memory"] },
|
|
749
|
-
* ],
|
|
750
|
-
* });
|
|
751
|
-
*/
|
|
752
|
-
registerComponent(registration: ComponentRegistration): void;
|
|
753
|
-
/**
|
|
754
|
-
* 按需加载配置
|
|
755
|
-
*
|
|
756
|
-
* 从注册的 Source 加载已注册 Keys 的配置值到内存中
|
|
757
|
-
*
|
|
758
|
-
* @param componentName - 可选,指定要加载的 Component 名称
|
|
759
|
-
*
|
|
760
|
-
* @example
|
|
761
|
-
* // 加载所有已注册的 Keys
|
|
762
|
-
* await config.load();
|
|
763
|
-
*
|
|
764
|
-
* // 只加载指定 Component 的 Keys
|
|
765
|
-
* await config.load("llm");
|
|
766
|
-
*/
|
|
767
|
-
load(componentName?: string): Promise<void>;
|
|
768
|
-
/**
|
|
769
|
-
* 获取已注册的 Source 列表
|
|
770
|
-
*/
|
|
771
|
-
getRegisteredSources(): ConfigSource[];
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* 服务配置接口
|
|
775
|
-
*/
|
|
776
|
-
interface ServiceConfig {
|
|
777
|
-
/** 环境配置 */
|
|
778
|
-
environment?: {
|
|
779
|
-
name?: string;
|
|
780
|
-
version?: string;
|
|
781
|
-
};
|
|
782
|
-
/** 组件配置映射 */
|
|
783
|
-
components?: Record<string, ComponentConfigEntry>;
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* 组件配置项
|
|
787
|
-
*/
|
|
788
|
-
interface ComponentConfigEntry {
|
|
789
|
-
/** 配置文件路径(可选) */
|
|
790
|
-
configPath?: string;
|
|
791
|
-
/** 环境变量前缀(可选) */
|
|
792
|
-
envPrefix?: string;
|
|
793
|
-
/** 直接配置对象(可选) */
|
|
794
|
-
config?: Record<string, unknown>;
|
|
795
|
-
/** 是否启用(可选,默认 true) */
|
|
796
|
-
enabled?: boolean;
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* 组件初始化选项(由 generateComponentOptions 生成)
|
|
800
|
-
*/
|
|
801
|
-
interface GeneratedComponentOptions {
|
|
802
|
-
/** ConfigComponent 实例 */
|
|
803
|
-
configComponent: ConfigComponent;
|
|
804
|
-
/** 配置文件路径 */
|
|
805
|
-
configPath?: string;
|
|
806
|
-
/** 环境变量前缀 */
|
|
807
|
-
envPrefix?: string;
|
|
808
|
-
/** 直接配置对象 */
|
|
809
|
-
config?: Record<string, unknown>;
|
|
810
|
-
/** 允许的其他属性 */
|
|
811
|
-
[key: string]: unknown;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Environment 接口
|
|
815
|
-
*
|
|
816
|
-
* 定义 Agent 运行时的核心能力接口。
|
|
817
|
-
*/
|
|
818
|
-
interface Environment {
|
|
819
|
-
/** 环境名称 */
|
|
820
|
-
readonly name: string;
|
|
821
|
-
/** 环境版本 */
|
|
822
|
-
readonly version: string;
|
|
823
|
-
/** 获取环境配置 */
|
|
824
|
-
getConfig(): EnvironmentConfig;
|
|
825
|
-
/**
|
|
826
|
-
* 注册组件
|
|
827
|
-
*/
|
|
828
|
-
registerComponent(component: Component): void;
|
|
829
|
-
/**
|
|
830
|
-
* 注销组件
|
|
831
|
-
*/
|
|
832
|
-
unregisterComponent(name: string): void;
|
|
833
|
-
/**
|
|
834
|
-
* 获取组件
|
|
835
|
-
*/
|
|
836
|
-
getComponent<T extends Component>(name: string): T | undefined;
|
|
837
|
-
/**
|
|
838
|
-
* 列出所有组件
|
|
839
|
-
*/
|
|
840
|
-
listComponents(): Component[];
|
|
841
|
-
/**
|
|
842
|
-
* 处理自然语言查询(核心入口)
|
|
843
|
-
*
|
|
844
|
-
* @param query 用户查询文本
|
|
845
|
-
* @param context 执行上下文(可选)
|
|
846
|
-
* @returns 完整的文本响应
|
|
847
|
-
*/
|
|
848
|
-
handle_query(query: string, context?: AgentContext): Promise<string>;
|
|
849
|
-
/**
|
|
850
|
-
* 处理动作
|
|
851
|
-
*/
|
|
852
|
-
handle_action(action: Action, context: Context): Promise<ToolResult>;
|
|
853
|
-
/**
|
|
854
|
-
* 订阅 EnvEvent(返回取消订阅函数)
|
|
855
|
-
*/
|
|
856
|
-
subscribe(handler: EnvEventHandler): () => void;
|
|
857
|
-
/**
|
|
858
|
-
* 订阅指定类型事件
|
|
859
|
-
*/
|
|
860
|
-
subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
|
|
861
|
-
/**
|
|
862
|
-
* 订阅所有事件(通配符)
|
|
863
|
-
*/
|
|
864
|
-
subscribeAll(handler: EnvEventHandler): () => void;
|
|
865
|
-
/**
|
|
866
|
-
* 推送事件
|
|
867
|
-
*
|
|
868
|
-
* @param event EnvEvent 或 EnvEventInput(部分属性)
|
|
869
|
-
*/
|
|
870
|
-
pushEnvEvent(event: EnvEvent | EnvEventInput): void;
|
|
871
|
-
/**
|
|
872
|
-
* 从配置文件加载服务配置
|
|
873
|
-
*
|
|
874
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
875
|
-
* @returns 解析后的服务配置对象
|
|
876
|
-
*/
|
|
877
|
-
loadServiceConfig(configPath: string): Promise<ServiceConfig>;
|
|
878
|
-
/**
|
|
879
|
-
* 生成组件初始化选项
|
|
880
|
-
*
|
|
881
|
-
* 根据组件配置项生成可用于初始化的选项对象。
|
|
882
|
-
*
|
|
883
|
-
* @param componentName 组件名称
|
|
884
|
-
* @param configEntry 组件配置项
|
|
885
|
-
* @returns 生成的组件初始化选项
|
|
886
|
-
*/
|
|
887
|
-
generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
|
|
888
|
-
/**
|
|
889
|
-
* 注册组件并用配置初始化
|
|
890
|
-
*
|
|
891
|
-
* 便捷方法:注册组件并通过 ConfigComponent 初始化。
|
|
892
|
-
*
|
|
893
|
-
* @param component 要注册的组件实例
|
|
894
|
-
* @param configEntry 组件配置项
|
|
895
|
-
*/
|
|
896
|
-
registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
|
|
897
|
-
/**
|
|
898
|
-
* 从配置文件初始化整个环境
|
|
899
|
-
*
|
|
900
|
-
* 加载服务配置,注册并初始化所有配置的组件。
|
|
901
|
-
*
|
|
902
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
903
|
-
*/
|
|
904
|
-
initFromConfig(configPath: string): Promise<void>;
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Component 状态
|
|
908
|
-
*/
|
|
909
|
-
type ComponentStatus = "created" | "initializing" | "running" | "stopping" | "stopped" | "error";
|
|
910
|
-
/**
|
|
911
|
-
* Component 配置
|
|
912
|
-
*/
|
|
913
|
-
interface ComponentConfig {
|
|
914
|
-
name: string;
|
|
915
|
-
version: string;
|
|
916
|
-
enabled: boolean;
|
|
917
|
-
options?: Record<string, unknown>;
|
|
918
|
-
/**
|
|
919
|
-
* Environment 实例(可选)
|
|
920
|
-
*
|
|
921
|
-
* 推荐在 init 时接收 env 实例,以便:
|
|
922
|
-
* - 通过 env.getComponent() 获取其他组件
|
|
923
|
-
* - 通过 env.pushEnvEvent() 发布事件
|
|
924
|
-
* - 通过 env.handle_query() 处理查询
|
|
925
|
-
*
|
|
926
|
-
* 如果未提供,部分 Component 仍可正常工作(如测试场景)
|
|
927
|
-
*
|
|
928
|
-
* @example
|
|
929
|
-
* ```typescript
|
|
930
|
-
* async onInit(): Promise<void> {
|
|
931
|
-
* if (this.env) {
|
|
932
|
-
* const configComp = this.env.getComponent("config");
|
|
933
|
-
* }
|
|
934
|
-
* }
|
|
935
|
-
* ```
|
|
936
|
-
*/
|
|
937
|
-
env?: Environment;
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* Component 路径声明
|
|
941
|
-
*/
|
|
942
|
-
interface ComponentPaths {
|
|
943
|
-
base: "config" | "state" | "data" | "cache";
|
|
944
|
-
subPath: string;
|
|
945
|
-
isDirectory: boolean;
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Component Schema(注册配置)
|
|
949
|
-
*/
|
|
950
|
-
interface ComponentSchema {
|
|
951
|
-
/** Component 名称 */
|
|
952
|
-
name: string;
|
|
953
|
-
/** 配置 Schema(Zod) */
|
|
954
|
-
schema: ZodType3<unknown, ZodTypeDef2, unknown>;
|
|
955
|
-
/** 默认值(从 Schema 提取) */
|
|
956
|
-
defaults: Record<string, unknown>;
|
|
957
|
-
/** 路径声明 */
|
|
958
|
-
paths?: Record<string, ComponentPaths>;
|
|
959
|
-
/** 元信息 */
|
|
960
|
-
metadata?: {
|
|
961
|
-
description?: string;
|
|
962
|
-
version?: string;
|
|
963
|
-
author?: string;
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* Component 配置变更事件
|
|
968
|
-
*/
|
|
969
|
-
interface ComponentConfigChangeEvent {
|
|
970
|
-
/** Component 名称 */
|
|
971
|
-
component: string;
|
|
972
|
-
/** 变更的配置键 */
|
|
973
|
-
key: string;
|
|
974
|
-
/** 旧值 */
|
|
975
|
-
oldValue: unknown;
|
|
976
|
-
/** 新值 */
|
|
977
|
-
newValue: unknown;
|
|
978
|
-
/** 是否持久化 */
|
|
979
|
-
persisted: boolean;
|
|
980
|
-
/** 时间戳 */
|
|
981
|
-
timestamp: number;
|
|
982
|
-
}
|
|
983
|
-
/**
|
|
984
|
-
* Component 配置监听回调
|
|
985
|
-
*/
|
|
986
|
-
type ComponentWatchCallback = (event: ComponentConfigChangeEvent) => void | Promise<void>;
|
|
987
|
-
/**
|
|
988
|
-
* Component 基类接口
|
|
989
|
-
*/
|
|
990
|
-
interface Component {
|
|
991
|
-
/** Component 名称 */
|
|
992
|
-
readonly name: string;
|
|
993
|
-
/** Component 版本 */
|
|
994
|
-
readonly version: string;
|
|
995
|
-
/** 获取状态 */
|
|
996
|
-
getStatus(): ComponentStatus;
|
|
997
|
-
/** 获取配置 */
|
|
998
|
-
getConfig(): ComponentConfig;
|
|
999
|
-
/** 初始化 */
|
|
1000
|
-
init(config: ComponentConfig): Promise<void>;
|
|
1001
|
-
/** 启动 */
|
|
1002
|
-
start(): Promise<void>;
|
|
1003
|
-
/** 停止 */
|
|
1004
|
-
stop(): Promise<void>;
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Component 基类实现
|
|
1008
|
-
*/
|
|
1009
|
-
declare abstract class BaseComponent implements Component {
|
|
1010
|
-
abstract readonly name: string;
|
|
1011
|
-
abstract readonly version: string;
|
|
1012
|
-
protected _status: ComponentStatus;
|
|
1013
|
-
protected _enabled: boolean;
|
|
1014
|
-
protected env: Environment;
|
|
1015
|
-
/** Hook 管理器 - 子类初始化时由构造函数设置 */
|
|
1016
|
-
readonly hookManager: HookManager;
|
|
1017
|
-
constructor();
|
|
1018
|
-
getStatus(): ComponentStatus;
|
|
1019
|
-
getConfig(): ComponentConfig;
|
|
1020
|
-
/**
|
|
1021
|
-
* 检查 Environment 是否已初始化
|
|
1022
|
-
*/
|
|
1023
|
-
protected isEnvInitialized(): boolean;
|
|
1024
|
-
protected setStatus(status: ComponentStatus): void;
|
|
1025
|
-
/**
|
|
1026
|
-
* 获取 Environment 实例
|
|
1027
|
-
*/
|
|
1028
|
-
protected getEnv(): Environment;
|
|
1029
|
-
init(config?: ComponentConfig): Promise<void>;
|
|
1030
|
-
start(): Promise<void>;
|
|
1031
|
-
stop(): Promise<void>;
|
|
1032
|
-
/**
|
|
1033
|
-
* 子类可覆盖的钩子方法
|
|
1034
|
-
*/
|
|
1035
|
-
protected onInit(): Promise<void>;
|
|
1036
|
-
protected onStart(): Promise<void>;
|
|
1037
|
-
protected onStop(): Promise<void>;
|
|
1038
|
-
/**
|
|
1039
|
-
* 注册 Hook
|
|
1040
|
-
*
|
|
1041
|
-
* @param hookPoint Hook 点名称
|
|
1042
|
-
* @param hook Hook 实例
|
|
1043
|
-
*/
|
|
1044
|
-
protected registerHook<T = unknown>(hookPoint: string, hook: Hook<T>): void;
|
|
1045
|
-
/**
|
|
1046
|
-
* 便捷方法:快速注册 Hook
|
|
1047
|
-
*/
|
|
1048
|
-
protected addHook<T = unknown>(hookPoint: string, name: string, fn: HookFn<T>, priority?: number): void;
|
|
1049
|
-
/**
|
|
1050
|
-
* 便捷方法:按名称取消注册 Hook
|
|
1051
|
-
*/
|
|
1052
|
-
protected removeHook(hookPoint: string, name: string): boolean;
|
|
1053
|
-
/**
|
|
1054
|
-
* 执行 Hook
|
|
1055
|
-
*/
|
|
1056
|
-
protected executeHooks<T = unknown>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
|
|
1057
|
-
/**
|
|
1058
|
-
* 获取 ConfigComponent 实例
|
|
1059
|
-
*
|
|
1060
|
-
* 子类可使用此方法获取配置组件,支持热更新
|
|
1061
|
-
*/
|
|
1062
|
-
protected getConfigComponent(): {
|
|
1063
|
-
get(key: string): unknown;
|
|
1064
|
-
} | undefined;
|
|
1065
|
-
/**
|
|
1066
|
-
* 动态获取运行时配置值
|
|
1067
|
-
*
|
|
1068
|
-
* 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
|
|
1069
|
-
* 适用于运行时可能变化的配置(如 API Keys、模型参数)
|
|
1070
|
-
*
|
|
1071
|
-
* @param key 配置键(支持点号分隔的路径,如 "llm.temperature")
|
|
1072
|
-
* @param defaultValue 默认值
|
|
1073
|
-
* @returns 配置值或默认值
|
|
1074
|
-
*
|
|
1075
|
-
* @example
|
|
1076
|
-
* ```typescript
|
|
1077
|
-
* // 获取 LLM 温度配置(可能支持热更新)
|
|
1078
|
-
* const temperature = this.getRuntimeConfig("llm.temperature", 0.7);
|
|
1079
|
-
*
|
|
1080
|
-
* // 获取 API Key
|
|
1081
|
-
* const apiKey = this.getRuntimeConfig<string>("llm.providers.openai.apiKey");
|
|
1082
|
-
* ```
|
|
1083
|
-
*/
|
|
1084
|
-
protected getRuntimeConfig<T>(key: string, defaultValue: T): T;
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* TaskPlugin 配置
|
|
1088
|
-
*/
|
|
1089
|
-
interface TaskPluginConfig {
|
|
1090
|
-
/** 是否启用 */
|
|
1091
|
-
enabled?: boolean;
|
|
1092
|
-
/** 优先级 */
|
|
1093
|
-
priority?: number;
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* TaskPlugin Hook 定义
|
|
1097
|
-
*/
|
|
1098
|
-
interface TaskPluginHook {
|
|
1099
|
-
/** Hook 点 */
|
|
1100
|
-
point: string;
|
|
1101
|
-
/** 优先级(数字越大越先执行)*/
|
|
1102
|
-
priority?: number;
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* TaskPlugin 基类
|
|
1106
|
-
*/
|
|
1107
|
-
declare abstract class TaskPlugin {
|
|
1108
|
-
abstract readonly name: string;
|
|
1109
|
-
abstract readonly hooks: TaskPluginHook[];
|
|
1110
|
-
protected config: TaskPluginConfig;
|
|
1111
|
-
constructor(config?: TaskPluginConfig);
|
|
1112
|
-
/**
|
|
1113
|
-
* 设置依赖组件(可选实现)
|
|
1114
|
-
*/
|
|
1115
|
-
setComponents?(llmComponent: unknown, taskComponent: unknown): void;
|
|
1116
|
-
/**
|
|
1117
|
-
* 获取 Hook 点列表
|
|
1118
|
-
*/
|
|
1119
|
-
getHookPoints(): string[];
|
|
1120
|
-
/**
|
|
1121
|
-
* 获取指定 Hook 点的优先级
|
|
1122
|
-
*/
|
|
1123
|
-
getPriorityForHook(hookPoint: string): number;
|
|
1124
|
-
/**
|
|
1125
|
-
* 检查是否启用
|
|
1126
|
-
*/
|
|
1127
|
-
isEnabled(): boolean;
|
|
1128
|
-
/**
|
|
1129
|
-
* 设置启用状态
|
|
1130
|
-
*/
|
|
1131
|
-
setEnabled(enabled: boolean): void;
|
|
1132
|
-
}
|
|
1133
|
-
import { z as z7 } from "zod";
|
|
1134
|
-
/**
|
|
1135
|
-
* Task status enum
|
|
1136
|
-
*/
|
|
1137
|
-
declare const TaskStatusEnum: unknown;
|
|
1138
|
-
type TaskStatus = z7.infer<typeof TaskStatusEnum>;
|
|
1139
|
-
/**
|
|
1140
|
-
* Task priority enum
|
|
1141
|
-
*/
|
|
1142
|
-
declare const TaskPriorityEnum: unknown;
|
|
1143
|
-
type TaskPriority = z7.infer<typeof TaskPriorityEnum>;
|
|
1144
|
-
/**
|
|
1145
|
-
* Action type for task operations
|
|
1146
|
-
*/
|
|
1147
|
-
declare const ActionTypeEnum: unknown;
|
|
1148
|
-
type ActionType = z7.infer<typeof ActionTypeEnum>;
|
|
1149
|
-
/**
|
|
1150
|
-
* Task entity
|
|
1151
|
-
*/
|
|
1152
|
-
interface Task {
|
|
1153
|
-
id: number;
|
|
1154
|
-
title: string;
|
|
1155
|
-
description: string;
|
|
1156
|
-
status: TaskStatus;
|
|
1157
|
-
priority: TaskPriority;
|
|
1158
|
-
progress: number;
|
|
1159
|
-
current_status: string;
|
|
1160
|
-
goals_and_expected_deliverables: string;
|
|
1161
|
-
parent_task_id?: number;
|
|
1162
|
-
createdAt: string;
|
|
1163
|
-
updatedAt: string;
|
|
1164
|
-
due_date?: string;
|
|
1165
|
-
tags?: string[];
|
|
1166
|
-
/** Project root path for task positioning */
|
|
1167
|
-
project_path: string;
|
|
1168
|
-
/** JSON string with time-space positioning info (worktree, branch, etc.) */
|
|
1169
|
-
context: string;
|
|
1170
|
-
}
|
|
1171
|
-
/**
|
|
1172
|
-
* TaskOperation entity
|
|
1173
|
-
*
|
|
1174
|
-
* 记录任务的操作历史,每个操作关联到一个 sessionId
|
|
1175
|
-
*/
|
|
1176
|
-
interface TaskOperation {
|
|
1177
|
-
id: number;
|
|
1178
|
-
taskId: number;
|
|
1179
|
-
sessionId: string;
|
|
1180
|
-
actionType: ActionType;
|
|
1181
|
-
actionTitle: string;
|
|
1182
|
-
actionDescription: string;
|
|
1183
|
-
timestamp: string;
|
|
1184
|
-
mdPath?: string;
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* TaskTag entity
|
|
1188
|
-
*
|
|
1189
|
-
* Tag 池中的单个 Tag
|
|
1190
|
-
*/
|
|
1191
|
-
interface TaskTag {
|
|
1192
|
-
id: number;
|
|
1193
|
-
name: string;
|
|
1194
|
-
createdAt: string;
|
|
1195
|
-
taskCount: number;
|
|
1196
|
-
}
|
|
1197
|
-
interface CreateTaskOptions {
|
|
1198
|
-
title: string;
|
|
1199
|
-
description?: string;
|
|
1200
|
-
priority?: TaskPriority;
|
|
1201
|
-
parent_task_id?: number;
|
|
1202
|
-
goals_and_expected_deliverables?: string;
|
|
1203
|
-
due_date?: string;
|
|
1204
|
-
tags?: string[];
|
|
1205
|
-
sessionId: string;
|
|
1206
|
-
/** Project root path for task positioning. Use 'unknown' if unknown. */
|
|
1207
|
-
project_path: string;
|
|
1208
|
-
/**
|
|
1209
|
-
* JSON string with time-space positioning info.
|
|
1210
|
-
* - For coding tasks: include worktree_path, branch, type
|
|
1211
|
-
* - For other tasks: use '{}' or '{"type":"unknown"}'
|
|
1212
|
-
* Must be a valid JSON string.
|
|
1213
|
-
*/
|
|
1214
|
-
context: string;
|
|
1215
|
-
}
|
|
1216
|
-
interface UpdateTaskOptions {
|
|
1217
|
-
title?: string;
|
|
1218
|
-
description?: string;
|
|
1219
|
-
status?: TaskStatus;
|
|
1220
|
-
priority?: TaskPriority;
|
|
1221
|
-
progress?: number;
|
|
1222
|
-
current_status?: string;
|
|
1223
|
-
goals_and_expected_deliverables?: string;
|
|
1224
|
-
due_date?: string;
|
|
1225
|
-
tags?: string[];
|
|
1226
|
-
/** 项目路径,标识任务所属的项目 */
|
|
1227
|
-
project_path?: string;
|
|
1228
|
-
/** 任务上下文信息,用于存储额外上下文 */
|
|
1229
|
-
context?: string;
|
|
1230
|
-
}
|
|
1231
|
-
interface ListTasksOptions {
|
|
1232
|
-
status?: TaskStatus;
|
|
1233
|
-
priority?: TaskPriority;
|
|
1234
|
-
parent_task_id?: number;
|
|
1235
|
-
limit?: number;
|
|
1236
|
-
offset?: number;
|
|
1237
|
-
}
|
|
1238
|
-
interface CreateOperationOptions {
|
|
1239
|
-
taskId: number;
|
|
1240
|
-
sessionId: string;
|
|
1241
|
-
actionType: ActionType;
|
|
1242
|
-
actionTitle: string;
|
|
1243
|
-
actionDescription?: string;
|
|
1244
|
-
mdPath?: string;
|
|
1245
|
-
}
|
|
1246
|
-
interface ListOperationsOptions {
|
|
1247
|
-
taskId: number;
|
|
1248
|
-
actionType?: ActionType;
|
|
1249
|
-
limit?: number;
|
|
1250
|
-
offset?: number;
|
|
1251
|
-
}
|
|
1252
|
-
import { z as z8 } from "zod";
|
|
1253
|
-
interface ListTagsOptions {
|
|
1254
|
-
limit?: number;
|
|
1255
|
-
offset?: number;
|
|
1256
|
-
orderBy?: "count" | "name" | "created_at";
|
|
1257
|
-
}
|
|
1258
|
-
interface SearchTagsOptions {
|
|
1259
|
-
query: string;
|
|
1260
|
-
limit?: number;
|
|
1261
|
-
}
|
|
1262
|
-
interface TagService {
|
|
1263
|
-
/**
|
|
1264
|
-
* 创建 Tag(如果已存在则返回现有 Tag)
|
|
1265
|
-
*/
|
|
1266
|
-
createTag(name: string): Promise<TaskTag>;
|
|
1267
|
-
/**
|
|
1268
|
-
* 获取 Tag by ID
|
|
1269
|
-
*/
|
|
1270
|
-
getTag(id: number): Promise<TaskTag | undefined>;
|
|
1271
|
-
/**
|
|
1272
|
-
* 获取 Tag by Name
|
|
1273
|
-
*/
|
|
1274
|
-
getTagByName(name: string): Promise<TaskTag | undefined>;
|
|
1275
|
-
/**
|
|
1276
|
-
* 列出所有 Tag
|
|
1277
|
-
*/
|
|
1278
|
-
listTags(options?: ListTagsOptions): Promise<TaskTag[]>;
|
|
1279
|
-
/**
|
|
1280
|
-
* 搜索 Tag(模糊匹配)
|
|
1281
|
-
*/
|
|
1282
|
-
searchTags(options: SearchTagsOptions): Promise<TaskTag[]>;
|
|
1283
|
-
/**
|
|
1284
|
-
* 删除 Tag(同时删除所有关联)
|
|
1285
|
-
*/
|
|
1286
|
-
deleteTag(id: number): Promise<boolean>;
|
|
1287
|
-
/**
|
|
1288
|
-
* 给 Task 添加 Tags
|
|
1289
|
-
*/
|
|
1290
|
-
addTagsToTask(taskId: number, tagIds: number[]): Promise<void>;
|
|
1291
|
-
/**
|
|
1292
|
-
* 从 Task 移除 Tags
|
|
1293
|
-
*/
|
|
1294
|
-
removeTagsFromTask(taskId: number, tagIds: number[]): Promise<void>;
|
|
1295
|
-
/**
|
|
1296
|
-
* 获取 Task 的所有 Tags
|
|
1297
|
-
*/
|
|
1298
|
-
getTagsForTask(taskId: number): Promise<TaskTag[]>;
|
|
1299
|
-
/**
|
|
1300
|
-
* 根据 Tag 名称获取关联的 Task IDs
|
|
1301
|
-
*/
|
|
1302
|
-
getTaskIdsByTags(tagNames: string[]): Promise<number[]>;
|
|
1303
|
-
/**
|
|
1304
|
-
* 根据关键词列表搜索 Task(检索 tags、description、goals、operations)
|
|
1305
|
-
* 这是新的核心检索方法
|
|
1306
|
-
*/
|
|
1307
|
-
searchTasksByKeywords(keywords: string[], options?: {
|
|
1308
|
-
limit?: number;
|
|
1309
|
-
excludeTaskId?: number;
|
|
1310
|
-
}): Promise<Task[]>;
|
|
1311
|
-
/**
|
|
1312
|
-
* 根据关键词查找类似 Task(排除自身,按相关性排序)
|
|
1313
|
-
* 这是新的核心检索方法
|
|
1314
|
-
*/
|
|
1315
|
-
findSimilarTasksByKeywords(keywords: string[], options?: {
|
|
1316
|
-
limit?: number;
|
|
1317
|
-
excludeTaskId?: number;
|
|
1318
|
-
}): Promise<Task[]>;
|
|
1319
|
-
/**
|
|
1320
|
-
* 同步 Tags 到 Task(根据 tag 名称列表)
|
|
1321
|
-
* - 查找或创建 Tag
|
|
1322
|
-
* - 更新关联关系
|
|
1323
|
-
* - 更新 task.tags JSON 字段
|
|
1324
|
-
*/
|
|
1325
|
-
syncTagsToTask(taskId: number, tagNames: string[]): Promise<void>;
|
|
1326
|
-
/**
|
|
1327
|
-
* 查找类似 Task(基于 Tag 匹配度)- 原始实现,保留兼容
|
|
1328
|
-
* @deprecated 使用 findSimilarTasksByKeywords 代替
|
|
1329
|
-
*/
|
|
1330
|
-
findSimilarTasks(taskId: number, limit?: number): Promise<Task[]>;
|
|
1331
|
-
/**
|
|
1332
|
-
* 根据关键词搜索 Task(标题 + 描述)- 原始实现,保留兼容
|
|
1333
|
-
* @deprecated 使用 searchTasksByKeywords 代替
|
|
1334
|
-
*/
|
|
1335
|
-
searchTasks(query: string, limit?: number): Promise<Task[]>;
|
|
1336
|
-
}
|
|
1337
|
-
declare class TaskComponent extends BaseComponent {
|
|
1338
|
-
name: string;
|
|
1339
|
-
version: string;
|
|
1340
|
-
private store;
|
|
1341
|
-
private config?;
|
|
1342
|
-
private toolComponent?;
|
|
1343
|
-
private backgroundTaskManager?;
|
|
1344
|
-
private configComponent?;
|
|
1345
|
-
private tagService;
|
|
1346
|
-
private plugins;
|
|
1347
|
-
/**
|
|
1348
|
-
* 发布 EnvEvent
|
|
1349
|
-
*/
|
|
1350
|
-
private publishEvent;
|
|
1351
|
-
constructor();
|
|
1352
|
-
/**
|
|
1353
|
-
* Initialize the component
|
|
1354
|
-
*
|
|
1355
|
-
* 配置加载优先级(从高到低):
|
|
1356
|
-
* 1. Object - 直接传入的 config 对象
|
|
1357
|
-
* 2. Env - 环境变量(通过 envPrefix 配置前缀)
|
|
1358
|
-
* 3. File - 配置文件(通过 configPath 指定)
|
|
1359
|
-
*/
|
|
1360
|
-
init(config?: ComponentConfig): Promise<void>;
|
|
1361
|
-
/**
|
|
1362
|
-
* 注册配置到 ConfigComponent
|
|
1363
|
-
*
|
|
1364
|
-
* 配置加载顺序(优先级从低到高):
|
|
1365
|
-
* 1. Defaults - 默认值(最低)
|
|
1366
|
-
* 2. FileSource - 从配置文件加载
|
|
1367
|
-
* 3. EnvSource - 从环境变量加载
|
|
1368
|
-
* 4. config 对象 - 直接传入的配置(最高)
|
|
1369
|
-
*/
|
|
1370
|
-
private registerConfig;
|
|
1371
|
-
/**
|
|
1372
|
-
* 根据配置初始化 store
|
|
1373
|
-
*/
|
|
1374
|
-
private initStore;
|
|
1375
|
-
/**
|
|
1376
|
-
* 将配置对象展平为点号路径
|
|
1377
|
-
*/
|
|
1378
|
-
private flattenConfig;
|
|
1379
|
-
/**
|
|
1380
|
-
* 注册配置热更新监听
|
|
1381
|
-
*/
|
|
1382
|
-
private registerConfigWatcher;
|
|
1383
|
-
/**
|
|
1384
|
-
* 处理配置变更
|
|
1385
|
-
*/
|
|
1386
|
-
protected onConfigChange(event: {
|
|
1387
|
-
key: string;
|
|
1388
|
-
oldValue?: unknown;
|
|
1389
|
-
newValue?: unknown;
|
|
1390
|
-
}): void;
|
|
1391
|
-
/** 配置变更 watcher 清理函数 */
|
|
1392
|
-
private configWatcher?;
|
|
1393
|
-
/**
|
|
1394
|
-
* Start the component - register tools
|
|
1395
|
-
*/
|
|
1396
|
-
start(): Promise<void>;
|
|
1397
|
-
/**
|
|
1398
|
-
* Stop the component
|
|
1399
|
-
*/
|
|
1400
|
-
stop(): Promise<void>;
|
|
1401
|
-
/**
|
|
1402
|
-
* Register task tools to ToolComponent
|
|
1403
|
-
*/
|
|
1404
|
-
private registerTools;
|
|
1405
|
-
/**
|
|
1406
|
-
* 执行 Hook
|
|
1407
|
-
*/
|
|
1408
|
-
private executeHook;
|
|
1409
|
-
/**
|
|
1410
|
-
* Create a new task
|
|
1411
|
-
*/
|
|
1412
|
-
createTask(options: CreateTaskOptions): Promise<Task>;
|
|
1413
|
-
/**
|
|
1414
|
-
* Get task by ID
|
|
1415
|
-
*/
|
|
1416
|
-
getTask(id: number): Promise<Task | undefined>;
|
|
1417
|
-
/**
|
|
1418
|
-
* Get task with operations
|
|
1419
|
-
*/
|
|
1420
|
-
getTaskWithOperations(id: number): Promise<{
|
|
1421
|
-
task: Task;
|
|
1422
|
-
operations: TaskOperation[];
|
|
1423
|
-
} | undefined>;
|
|
1424
|
-
/**
|
|
1425
|
-
* Update task
|
|
1426
|
-
*/
|
|
1427
|
-
updateTask(id: number, options: UpdateTaskOptions): Promise<Task | undefined>;
|
|
1428
|
-
/**
|
|
1429
|
-
* Delete task
|
|
1430
|
-
*/
|
|
1431
|
-
deleteTask(id: number): Promise<boolean>;
|
|
1432
|
-
/**
|
|
1433
|
-
* List tasks
|
|
1434
|
-
*/
|
|
1435
|
-
listTasks(options?: ListTasksOptions): Promise<Task[]>;
|
|
1436
|
-
/**
|
|
1437
|
-
* Complete task
|
|
1438
|
-
*/
|
|
1439
|
-
completeTask(id: number, sessionId: string): Promise<Task | undefined>;
|
|
1440
|
-
/**
|
|
1441
|
-
* Create operation record
|
|
1442
|
-
*/
|
|
1443
|
-
createOperation(options: CreateOperationOptions): Promise<TaskOperation>;
|
|
1444
|
-
/**
|
|
1445
|
-
* Get operation by ID
|
|
1446
|
-
*/
|
|
1447
|
-
getOperation(id: number): Promise<TaskOperation | undefined>;
|
|
1448
|
-
/**
|
|
1449
|
-
* Update operation
|
|
1450
|
-
*/
|
|
1451
|
-
updateOperation(id: number, updates: {
|
|
1452
|
-
actionTitle?: string;
|
|
1453
|
-
actionDescription?: string;
|
|
1454
|
-
}): Promise<TaskOperation | undefined>;
|
|
1455
|
-
/**
|
|
1456
|
-
* Delete operation
|
|
1457
|
-
*/
|
|
1458
|
-
deleteOperation(id: number): Promise<boolean>;
|
|
1459
|
-
/**
|
|
1460
|
-
* List operations for a task
|
|
1461
|
-
*/
|
|
1462
|
-
listOperations(options: ListOperationsOptions): Promise<TaskOperation[]>;
|
|
1463
|
-
/**
|
|
1464
|
-
* 获取 TagService
|
|
1465
|
-
*/
|
|
1466
|
-
getTagService(): TagService;
|
|
1467
|
-
/**
|
|
1468
|
-
* 注册 Plugin
|
|
1469
|
-
*/
|
|
1470
|
-
registerPlugin(plugin: TaskPlugin): void;
|
|
1471
|
-
/**
|
|
1472
|
-
* 注销 Plugin
|
|
1473
|
-
*/
|
|
1474
|
-
unregisterPlugin(name: string): boolean;
|
|
1475
|
-
/**
|
|
1476
|
-
* 获取所有注册的 Plugin
|
|
1477
|
-
*/
|
|
1478
|
-
listPlugins(): TaskPlugin[];
|
|
1479
|
-
}
|
|
1480
|
-
/**
|
|
1481
|
-
* Background Task Event Types
|
|
1482
|
-
* 这些事件由 BackgroundTaskManager 发布,标识为 task.background.*
|
|
1483
|
-
*/
|
|
1484
|
-
declare const BackgroundTaskEventTypes: {
|
|
1485
|
-
readonly STARTED: "task.background.started";
|
|
1486
|
-
readonly PROGRESS: "task.background.progress";
|
|
1487
|
-
readonly COMPLETED: "task.background.completed";
|
|
1488
|
-
readonly FAILED: "task.background.failed";
|
|
1489
|
-
readonly TIMEOUT: "task.background.timeout";
|
|
1490
|
-
readonly STOPPED: "task.background.stopped";
|
|
1491
|
-
};
|
|
1492
|
-
interface BackgroundTaskStartedPayload {
|
|
1493
|
-
backgroundTaskId: string;
|
|
1494
|
-
subSessionId: string;
|
|
1495
|
-
parentSessionId: string;
|
|
1496
|
-
description: string;
|
|
1497
|
-
subagentType: string;
|
|
1498
|
-
associatedTaskId?: number;
|
|
1499
|
-
}
|
|
1500
|
-
interface BackgroundTaskProgressPayload {
|
|
1501
|
-
backgroundTaskId: string;
|
|
1502
|
-
subSessionId: string;
|
|
1503
|
-
parentSessionId: string;
|
|
1504
|
-
status: string;
|
|
1505
|
-
progress?: number;
|
|
1506
|
-
}
|
|
1507
|
-
interface BackgroundTaskCompletedPayload {
|
|
1508
|
-
backgroundTaskId: string;
|
|
1509
|
-
subSessionId: string;
|
|
1510
|
-
parentSessionId: string;
|
|
1511
|
-
status: "completed" | "failed" | "timeout" | "stopped";
|
|
1512
|
-
result?: string;
|
|
1513
|
-
error?: string;
|
|
1514
|
-
executionTimeMs: number;
|
|
1515
|
-
associatedTaskId?: number;
|
|
1516
|
-
}
|
|
1517
|
-
interface SubAgentSpec {
|
|
1518
|
-
id: string;
|
|
1519
|
-
name: string;
|
|
1520
|
-
description: string;
|
|
1521
|
-
mode: "subagent" | "primary" | "all";
|
|
1522
|
-
promptOverride?: string;
|
|
1523
|
-
/** 允许的工具列表(白名单) */
|
|
1524
|
-
allowedTools?: string[];
|
|
1525
|
-
/** 拒绝的工具列表(黑名单) */
|
|
1526
|
-
deniedTools?: string[];
|
|
1527
|
-
}
|
|
1528
|
-
declare const DelegateToolParameters: unknown;
|
|
1529
|
-
type DelegateToolParams = z8.infer<typeof DelegateToolParameters>;
|
|
1530
|
-
interface DelegateToolResult {
|
|
1531
|
-
tool: Tool;
|
|
1532
|
-
backgroundTaskManager: BackgroundTaskManager;
|
|
1533
|
-
}
|
|
1534
|
-
interface BackgroundTask {
|
|
1535
|
-
id: string;
|
|
1536
|
-
subSessionId: string;
|
|
1537
|
-
parentSessionId: string;
|
|
1538
|
-
description: string;
|
|
1539
|
-
subagentType: string;
|
|
1540
|
-
status: "pending" | "running" | "completed" | "failed" | "timeout" | "stopped";
|
|
1541
|
-
createdAt: number;
|
|
1542
|
-
startedAt?: number;
|
|
1543
|
-
completedAt?: number;
|
|
1544
|
-
result?: string;
|
|
1545
|
-
error?: string;
|
|
1546
|
-
progress?: number;
|
|
1547
|
-
progressMessage?: string;
|
|
1548
|
-
abortController?: AbortController;
|
|
1549
|
-
taskId?: number;
|
|
1550
|
-
}
|
|
1551
|
-
interface CreateBackgroundTaskOptions {
|
|
1552
|
-
parentSessionId: string;
|
|
1553
|
-
description: string;
|
|
1554
|
-
prompt: string;
|
|
1555
|
-
subagentType: string;
|
|
1556
|
-
timeout?: number;
|
|
1557
|
-
cleanup?: "delete" | "keep";
|
|
1558
|
-
taskId?: number;
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Background Task Manager (简化版)
|
|
1562
|
-
*
|
|
1563
|
-
* 管理后台任务的创建、执行、状态跟踪
|
|
1564
|
-
* 发布 task.background.* 事件供外部订阅
|
|
1565
|
-
*/
|
|
1566
|
-
declare class BackgroundTaskManager {
|
|
1567
|
-
private env;
|
|
1568
|
-
private tasks;
|
|
1569
|
-
private abortControllers;
|
|
1570
|
-
private progressTimers;
|
|
1571
|
-
constructor(env: any);
|
|
1572
|
-
/**
|
|
1573
|
-
* Get SessionComponent from env
|
|
1574
|
-
*/
|
|
1575
|
-
private getSessionComponent;
|
|
1576
|
-
/**
|
|
1577
|
-
* Publish a task.background.* event
|
|
1578
|
-
*/
|
|
1579
|
-
private publishBackgroundEvent;
|
|
1580
|
-
createTask(options: CreateBackgroundTaskOptions): Promise<{
|
|
1581
|
-
taskId: string;
|
|
1582
|
-
subSessionId: string;
|
|
1583
|
-
}>;
|
|
1584
|
-
private executeTask;
|
|
1585
|
-
/**
|
|
1586
|
-
* Start progress reporter for a task
|
|
1587
|
-
*/
|
|
1588
|
-
private startProgressReporter;
|
|
1589
|
-
/**
|
|
1590
|
-
* Stop progress reporter for a task
|
|
1591
|
-
*/
|
|
1592
|
-
private stopProgressReporter;
|
|
1593
|
-
private executeWithAbort;
|
|
1594
|
-
stopTask(taskId: string): {
|
|
1595
|
-
success: boolean;
|
|
1596
|
-
task?: BackgroundTask;
|
|
1597
|
-
message: string;
|
|
1598
|
-
};
|
|
1599
|
-
getTask(taskId: string): BackgroundTask | undefined;
|
|
1600
|
-
listTasks(): BackgroundTask[];
|
|
1601
|
-
/**
|
|
1602
|
-
* Dispose and cleanup all resources
|
|
1603
|
-
* Call this when shutting down to prevent process from hanging
|
|
1604
|
-
*/
|
|
1605
|
-
dispose(): void;
|
|
1606
|
-
}
|
|
1607
|
-
/**
|
|
1608
|
-
* Create delegate_task tool
|
|
1609
|
-
*/
|
|
1610
|
-
declare function createDelegateTool(taskComponent: TaskComponent): Tool;
|
|
1611
|
-
declare function createStopTool(taskManager: BackgroundTaskManager): Tool;
|
|
1612
|
-
export { createStopTool, createDelegateTool, SubAgentSpec, DelegateToolResult, DelegateToolParams, DelegateToolParameters, BackgroundTaskStartedPayload, BackgroundTaskProgressPayload, BackgroundTaskManager, BackgroundTaskEventTypes, BackgroundTaskCompletedPayload, BackgroundTask };
|