@ai-setting/roy-agent-core 1.5.13-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,1652 +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
|
-
/**
|
|
206
|
-
* @fileoverview Debug Component Types
|
|
207
|
-
*
|
|
208
|
-
* Type definitions for trace parsing, formatting, and debugging utilities.
|
|
209
|
-
*/
|
|
210
|
-
/**
|
|
211
|
-
* Trace action type
|
|
212
|
-
*/
|
|
213
|
-
type TraceAction = "enter" | "quit" | "error";
|
|
214
|
-
/**
|
|
215
|
-
* Log level type
|
|
216
|
-
*/
|
|
217
|
-
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
218
|
-
/**
|
|
219
|
-
* Trace entry representing a single log line with trace info
|
|
220
|
-
*/
|
|
221
|
-
interface TraceEntry {
|
|
222
|
-
/** Unique request/trace identifier */
|
|
223
|
-
traceId: string;
|
|
224
|
-
/** Timestamp of the entry (ISO format) */
|
|
225
|
-
timestamp: string;
|
|
226
|
-
/** Function/method name */
|
|
227
|
-
function: string;
|
|
228
|
-
/** Action type: enter, quit, or error */
|
|
229
|
-
action: TraceAction;
|
|
230
|
-
/** Parameters (for enter action) */
|
|
231
|
-
params?: unknown[];
|
|
232
|
-
/** Result (for quit action) */
|
|
233
|
-
result?: unknown;
|
|
234
|
-
/** Error message (for error action) */
|
|
235
|
-
error?: string;
|
|
236
|
-
/** Calculated duration in milliseconds (for quit action) */
|
|
237
|
-
durationMs?: number;
|
|
238
|
-
/** Span ID (for SQLite spans) */
|
|
239
|
-
spanId?: string;
|
|
240
|
-
/** Parent span ID (for SQLite spans) */
|
|
241
|
-
parentSpanId?: string;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Call tree node for hierarchical trace visualization
|
|
245
|
-
*/
|
|
246
|
-
interface TraceTreeNode {
|
|
247
|
-
/** Unique request/trace identifier */
|
|
248
|
-
traceId: string;
|
|
249
|
-
/** Function/method name */
|
|
250
|
-
function: string;
|
|
251
|
-
/** Start timestamp */
|
|
252
|
-
startTime: string;
|
|
253
|
-
/** End timestamp (for completed nodes) */
|
|
254
|
-
endTime?: string;
|
|
255
|
-
/** Duration in milliseconds */
|
|
256
|
-
durationMs?: number;
|
|
257
|
-
/** Child nodes */
|
|
258
|
-
children: TraceTreeNode[];
|
|
259
|
-
/** Original trace entry (optional for programmatically created nodes) */
|
|
260
|
-
entry?: TraceEntry;
|
|
261
|
-
/** Span ID (for SQLite spans) */
|
|
262
|
-
spanId?: string;
|
|
263
|
-
/** Parent span ID (for SQLite spans) */
|
|
264
|
-
parentSpanId?: string;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Options for parsing logs
|
|
268
|
-
*/
|
|
269
|
-
interface ParserOptions {
|
|
270
|
-
/** Log file path to read */
|
|
271
|
-
logFile?: string;
|
|
272
|
-
/** Filter by trace ID */
|
|
273
|
-
traceId?: string;
|
|
274
|
-
/** Filter by function name (supports partial match) */
|
|
275
|
-
function?: string;
|
|
276
|
-
/** Start time filter (ISO format or relative like "1h") */
|
|
277
|
-
since?: string;
|
|
278
|
-
/** End time filter (ISO format) */
|
|
279
|
-
until?: string;
|
|
280
|
-
/** Log level filter */
|
|
281
|
-
level?: LogLevel;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Options for log discovery
|
|
285
|
-
*/
|
|
286
|
-
interface LogDiscoveryOptions {
|
|
287
|
-
/** Log directory to search */
|
|
288
|
-
logDir?: string;
|
|
289
|
-
/** File pattern to match */
|
|
290
|
-
pattern?: string;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Parsed log line with extracted fields
|
|
294
|
-
*/
|
|
295
|
-
interface ParsedLogLine {
|
|
296
|
-
/** Original log line */
|
|
297
|
-
raw: string;
|
|
298
|
-
/** Timestamp extracted from log */
|
|
299
|
-
timestamp: string;
|
|
300
|
-
/** Log level (INFO, DEBUG, WARN, ERROR) */
|
|
301
|
-
level: string;
|
|
302
|
-
/** Source file/location */
|
|
303
|
-
source: string;
|
|
304
|
-
/** Category (traced:...) */
|
|
305
|
-
category: string;
|
|
306
|
-
/** Action symbol (>>> or <<< or !!!) */
|
|
307
|
-
action: string;
|
|
308
|
-
/** Method/function name */
|
|
309
|
-
method: string;
|
|
310
|
-
/** Action type (enter, quit, error) */
|
|
311
|
-
actionType: TraceAction;
|
|
312
|
-
/** Raw arguments string */
|
|
313
|
-
rawArgs: string;
|
|
314
|
-
/** Request ID extracted from log (if present) */
|
|
315
|
-
requestId: string | null;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Trace ID information summary
|
|
319
|
-
*/
|
|
320
|
-
interface TraceIdInfo {
|
|
321
|
-
/** Trace ID */
|
|
322
|
-
traceId: string;
|
|
323
|
-
/** First occurrence timestamp */
|
|
324
|
-
firstTime: string;
|
|
325
|
-
/** Last occurrence timestamp */
|
|
326
|
-
lastTime?: string;
|
|
327
|
-
/** Number of entries for this trace */
|
|
328
|
-
count: number;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Output format options
|
|
332
|
-
*/
|
|
333
|
-
interface FormatOptions {
|
|
334
|
-
/** Use pretty printing */
|
|
335
|
-
pretty?: boolean;
|
|
336
|
-
/** Maximum depth for recursive objects */
|
|
337
|
-
maxDepth?: number;
|
|
338
|
-
/** Include raw data */
|
|
339
|
-
includeRaw?: boolean;
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Trace summary for list output
|
|
343
|
-
*/
|
|
344
|
-
interface TraceSummary {
|
|
345
|
-
/** List of trace ID info */
|
|
346
|
-
traceIds: TraceIdInfo[];
|
|
347
|
-
/** Total count */
|
|
348
|
-
count: number;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Formats trace entries for human-readable output
|
|
352
|
-
*/
|
|
353
|
-
declare class TraceFormatter {
|
|
354
|
-
/**
|
|
355
|
-
* Format a single trace entry
|
|
356
|
-
*/
|
|
357
|
-
formatEntry(entry: TraceEntry, options?: FormatOptions): string;
|
|
358
|
-
/**
|
|
359
|
-
* Indent all lines after the first one
|
|
360
|
-
*/
|
|
361
|
-
private indentMultilineContent;
|
|
362
|
-
/**
|
|
363
|
-
* Format multiple trace entries
|
|
364
|
-
*/
|
|
365
|
-
formatEntries(entries: TraceEntry[], options?: FormatOptions): string;
|
|
366
|
-
/**
|
|
367
|
-
* Format data with proper indentation for multi-line content
|
|
368
|
-
*/
|
|
369
|
-
private formatData;
|
|
370
|
-
/**
|
|
371
|
-
* Format data with pretty printing and indentation
|
|
372
|
-
*/
|
|
373
|
-
private formatPretty;
|
|
374
|
-
/**
|
|
375
|
-
* Output as JSON
|
|
376
|
-
*/
|
|
377
|
-
toJSON(entries: TraceEntry[]): string;
|
|
378
|
-
/**
|
|
379
|
-
* Generate a summary of trace entries
|
|
380
|
-
*/
|
|
381
|
-
toSummary(entries: TraceEntry[]): string;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Options for tree formatting
|
|
385
|
-
*/
|
|
386
|
-
interface TreeFormatOptions {
|
|
387
|
-
/** Show duration percentage (default: true) */
|
|
388
|
-
showPercent?: boolean;
|
|
389
|
-
/** Show time bar (default: false) */
|
|
390
|
-
showTimeBar?: boolean;
|
|
391
|
-
/** Width of time bar (default: 10) */
|
|
392
|
-
barWidth?: number;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Formats trace call trees for human-readable output
|
|
396
|
-
*/
|
|
397
|
-
declare class TreeFormatter {
|
|
398
|
-
private options;
|
|
399
|
-
constructor(options?: TreeFormatOptions);
|
|
400
|
-
/**
|
|
401
|
-
* Color function based on percentage
|
|
402
|
-
*/
|
|
403
|
-
private colorByPercent;
|
|
404
|
-
/**
|
|
405
|
-
* Format a single trace tree
|
|
406
|
-
*/
|
|
407
|
-
formatTree(node: TraceTreeNode): string;
|
|
408
|
-
/**
|
|
409
|
-
* Format a single node
|
|
410
|
-
*/
|
|
411
|
-
private formatNode;
|
|
412
|
-
/**
|
|
413
|
-
* Recursively format children
|
|
414
|
-
*/
|
|
415
|
-
private formatChildren;
|
|
416
|
-
/**
|
|
417
|
-
* Render a time bar showing relative duration
|
|
418
|
-
*/
|
|
419
|
-
private renderTimeBar;
|
|
420
|
-
/**
|
|
421
|
-
* Format duration in human-readable form
|
|
422
|
-
*/
|
|
423
|
-
private formatDuration;
|
|
424
|
-
/**
|
|
425
|
-
* Format multiple trace trees
|
|
426
|
-
*/
|
|
427
|
-
formatTrees(trees: TraceTreeNode[]): string;
|
|
428
|
-
/**
|
|
429
|
-
* Output as JSON
|
|
430
|
-
*/
|
|
431
|
-
toJSON(trees: TraceTreeNode[]): string;
|
|
432
|
-
/**
|
|
433
|
-
* Generate a summary table of all spans sorted by duration
|
|
434
|
-
*/
|
|
435
|
-
formatSummary(node: TraceTreeNode): string;
|
|
436
|
-
/**
|
|
437
|
-
* Format tree with timeline visualization
|
|
438
|
-
*/
|
|
439
|
-
formatTimeline(node: TraceTreeNode): string;
|
|
440
|
-
/**
|
|
441
|
-
* Build timeline visualization with absolute positioning
|
|
442
|
-
*/
|
|
443
|
-
private buildTimeline;
|
|
444
|
-
}
|
|
445
|
-
interface ReplContext {
|
|
446
|
-
traceId?: string;
|
|
447
|
-
function?: string;
|
|
448
|
-
limit?: number;
|
|
449
|
-
}
|
|
450
|
-
interface ParsedCommand {
|
|
451
|
-
command: string;
|
|
452
|
-
args: Record<string, string>;
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Formats output for REPL interface and provides command parsing
|
|
456
|
-
*/
|
|
457
|
-
declare class ReplFormatter {
|
|
458
|
-
private context;
|
|
459
|
-
private history;
|
|
460
|
-
/**
|
|
461
|
-
* Get welcome message for REPL
|
|
462
|
-
*/
|
|
463
|
-
getWelcomeMessage(): string;
|
|
464
|
-
/**
|
|
465
|
-
* Format prompt with current context
|
|
466
|
-
*/
|
|
467
|
-
formatPrompt(context?: Partial<ReplContext>): string;
|
|
468
|
-
/**
|
|
469
|
-
* Get help text
|
|
470
|
-
*/
|
|
471
|
-
getHelpText(): string;
|
|
472
|
-
/**
|
|
473
|
-
* Format command result
|
|
474
|
-
*/
|
|
475
|
-
formatCommandResult(command: string, data: unknown): string;
|
|
476
|
-
/**
|
|
477
|
-
* Format list command result
|
|
478
|
-
*/
|
|
479
|
-
private formatListResult;
|
|
480
|
-
/**
|
|
481
|
-
* Format trace command result
|
|
482
|
-
*/
|
|
483
|
-
private formatTraceResult;
|
|
484
|
-
/**
|
|
485
|
-
* Format tree command result
|
|
486
|
-
*/
|
|
487
|
-
private formatTreeResult;
|
|
488
|
-
/**
|
|
489
|
-
* Format a single tree node recursively
|
|
490
|
-
*/
|
|
491
|
-
private formatTreeNode;
|
|
492
|
-
/**
|
|
493
|
-
* Format JSON in compact form
|
|
494
|
-
*/
|
|
495
|
-
private formatJsonCompact;
|
|
496
|
-
/**
|
|
497
|
-
* Parse command string
|
|
498
|
-
*/
|
|
499
|
-
parseCommand(input: string): ParsedCommand;
|
|
500
|
-
/**
|
|
501
|
-
* Update context
|
|
502
|
-
*/
|
|
503
|
-
setContext(context: Partial<ReplContext>): void;
|
|
504
|
-
/**
|
|
505
|
-
* Get current context
|
|
506
|
-
*/
|
|
507
|
-
getContext(): ReplContext;
|
|
508
|
-
/**
|
|
509
|
-
* Add to history
|
|
510
|
-
*/
|
|
511
|
-
addToHistory(command: string): void;
|
|
512
|
-
/**
|
|
513
|
-
* Get history
|
|
514
|
-
*/
|
|
515
|
-
getHistory(): string[];
|
|
516
|
-
}
|
|
517
|
-
import { ZodType as ZodType3, ZodTypeDef as ZodTypeDef2 } from "zod";
|
|
518
|
-
/**
|
|
519
|
-
* @fileoverview Environment types and interfaces
|
|
520
|
-
*
|
|
521
|
-
* 定义 Environment 的核心类型,包括:
|
|
522
|
-
* - Environment 配置
|
|
523
|
-
* - EnvEvent 事件类型
|
|
524
|
-
*/
|
|
525
|
-
/**
|
|
526
|
-
* Environment Config
|
|
527
|
-
*/
|
|
528
|
-
interface EnvironmentConfig {
|
|
529
|
-
/** 环境名称 */
|
|
530
|
-
name: string;
|
|
531
|
-
/** 环境版本 */
|
|
532
|
-
version: string;
|
|
533
|
-
/** 是否启用 */
|
|
534
|
-
enabled: boolean;
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* EnvEvent 元信息
|
|
538
|
-
*/
|
|
539
|
-
interface EnvEventMetadata {
|
|
540
|
-
/** 触发事件的 session ID */
|
|
541
|
-
trigger_session_id?: string;
|
|
542
|
-
/** 触发事件的 agent ID */
|
|
543
|
-
trigger_agent_id?: string;
|
|
544
|
-
/** Agent 名称 */
|
|
545
|
-
trigger_agent_name?: string;
|
|
546
|
-
/** 环境名称 */
|
|
547
|
-
env_name?: string;
|
|
548
|
-
/** 事件来源 */
|
|
549
|
-
source?: string;
|
|
550
|
-
/** 其他元数据 */
|
|
551
|
-
[key: string]: unknown;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* EnvEvent
|
|
555
|
-
*
|
|
556
|
-
* 统一的事件机制,用于:
|
|
557
|
-
* - Stream 事件(stream.start, stream.text, stream.completed 等)
|
|
558
|
-
* - 工具调用事件(tool.call, tool.result 等)
|
|
559
|
-
* - 会话事件(session.created, session.updated 等)
|
|
560
|
-
* - Agent 事件(agent.thinking, agent.acting 等)
|
|
561
|
-
*/
|
|
562
|
-
interface EnvEvent<T = unknown> {
|
|
563
|
-
/** 事件 ID */
|
|
564
|
-
id: string;
|
|
565
|
-
/** 事件类型 */
|
|
566
|
-
type: string;
|
|
567
|
-
/** 时间戳 */
|
|
568
|
-
timestamp: number;
|
|
569
|
-
/** 元信息 */
|
|
570
|
-
metadata: EnvEventMetadata;
|
|
571
|
-
/** 事件负载 */
|
|
572
|
-
payload: T;
|
|
573
|
-
}
|
|
574
|
-
/**
|
|
575
|
-
* EnvEvent Handler
|
|
576
|
-
*/
|
|
577
|
-
type EnvEventHandler = (event: EnvEvent) => void | Promise<void>;
|
|
578
|
-
/**
|
|
579
|
-
* EnvEvent 创建参数(部分属性,可选)
|
|
580
|
-
*
|
|
581
|
-
* 用于 pushEnvEvent 方法,允许传入部分属性,自动补全必填字段
|
|
582
|
-
*/
|
|
583
|
-
interface EnvEventInput {
|
|
584
|
-
/** 事件类型(必填) */
|
|
585
|
-
type: string;
|
|
586
|
-
/** 事件 ID(可选,自动生成) */
|
|
587
|
-
id?: string;
|
|
588
|
-
/** 时间戳(可选,自动生成) */
|
|
589
|
-
timestamp?: number;
|
|
590
|
-
/** 元信息(可选,自动创建) */
|
|
591
|
-
metadata?: EnvEventMetadata;
|
|
592
|
-
/** 事件负载(可选) */
|
|
593
|
-
payload?: unknown;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Action 类型
|
|
597
|
-
*/
|
|
598
|
-
interface Action {
|
|
599
|
-
/** Action 类型 */
|
|
600
|
-
type: string;
|
|
601
|
-
/** Action 参数 */
|
|
602
|
-
params?: Record<string, unknown>;
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* Tool Result
|
|
606
|
-
*/
|
|
607
|
-
interface ToolResult {
|
|
608
|
-
/** 是否成功 */
|
|
609
|
-
success: boolean;
|
|
610
|
-
/** 输出内容 */
|
|
611
|
-
output: string | Record<string, unknown>;
|
|
612
|
-
/** 错误信息 */
|
|
613
|
-
error?: string;
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Context
|
|
617
|
-
*/
|
|
618
|
-
interface Context {
|
|
619
|
-
/** 会话 ID */
|
|
620
|
-
sessionId?: string;
|
|
621
|
-
/** 用户 ID */
|
|
622
|
-
userId?: string;
|
|
623
|
-
/** 工作目录 */
|
|
624
|
-
workdir?: string;
|
|
625
|
-
/** 中断信号 */
|
|
626
|
-
abort?: AbortSignal;
|
|
627
|
-
/** 元数据 */
|
|
628
|
-
metadata?: Record<string, unknown>;
|
|
629
|
-
}
|
|
630
|
-
type AbortSignalType = AbortSignal;
|
|
631
|
-
/**
|
|
632
|
-
* Agent 执行上下文
|
|
633
|
-
*/
|
|
634
|
-
interface AgentContext {
|
|
635
|
-
/** 会话 ID */
|
|
636
|
-
sessionId?: string;
|
|
637
|
-
/** 消息 ID */
|
|
638
|
-
messageId?: string;
|
|
639
|
-
/** 中断信号 */
|
|
640
|
-
abort?: AbortSignalType;
|
|
641
|
-
/** 额外的上下文信息(会添加到 system prompt) */
|
|
642
|
-
additionInfo?: string;
|
|
643
|
-
/** 元数据 */
|
|
644
|
-
metadata?: Record<string, unknown>;
|
|
645
|
-
/** Agent 类型(用于选择 Behavior Spec) */
|
|
646
|
-
agentType?: string;
|
|
647
|
-
/** 使用的模型 */
|
|
648
|
-
model?: string;
|
|
649
|
-
/** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
650
|
-
allowedTools?: string[];
|
|
651
|
-
/** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
652
|
-
deniedTools?: string[];
|
|
653
|
-
/** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
|
|
654
|
-
filterHistory?: boolean;
|
|
655
|
-
}
|
|
656
|
-
import { ZodType as ZodType2, ZodTypeDef } from "zod";
|
|
657
|
-
/**
|
|
658
|
-
* ConfigSource 类型
|
|
659
|
-
*/
|
|
660
|
-
type ConfigSourceType = "memory" | "file" | "env" | "remote";
|
|
661
|
-
/**
|
|
662
|
-
* SourceRegistration - Source 注册配置
|
|
663
|
-
*/
|
|
664
|
-
interface SourceRegistration {
|
|
665
|
-
/** Source 类型 */
|
|
666
|
-
type: ConfigSourceType;
|
|
667
|
-
/** 相对路径(file 类型使用,基于 XDG_DATA_HOME) */
|
|
668
|
-
relativePath?: string;
|
|
669
|
-
/** 环境变量前缀(env 类型使用) */
|
|
670
|
-
envPrefix?: string;
|
|
671
|
-
/** 优先级,默认值:memory=0, file=10, env=20 */
|
|
672
|
-
priority?: number;
|
|
673
|
-
/** 是否可选(file 类型使用,文件不存在时不报错) */
|
|
674
|
-
optional?: boolean;
|
|
675
|
-
/** 是否启用文件监听(file 类型使用,默认 true) */
|
|
676
|
-
watch?: boolean;
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* KeyRegistration - 配置 Key 注册
|
|
680
|
-
*/
|
|
681
|
-
interface KeyRegistration {
|
|
682
|
-
/** 配置 Key(支持点号嵌套,如 "llm.provider") */
|
|
683
|
-
key: string;
|
|
684
|
-
/** 优先使用的 Source 列表(按优先级从低到高) */
|
|
685
|
-
sources: ConfigSourceType[];
|
|
686
|
-
/** 自定义优先级(覆盖默认优先级) */
|
|
687
|
-
priority?: number;
|
|
688
|
-
/** 默认值 */
|
|
689
|
-
default?: unknown;
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* ComponentRegistration - Component 注册配置
|
|
693
|
-
*/
|
|
694
|
-
interface ComponentRegistration {
|
|
695
|
-
/** Component 名称 */
|
|
696
|
-
name: string;
|
|
697
|
-
/** 声明需要的 Source */
|
|
698
|
-
sources: SourceRegistration[];
|
|
699
|
-
/** 声明需要的配置 Key */
|
|
700
|
-
keys: KeyRegistration[];
|
|
701
|
-
/** 配置 Schema(用于验证,可选) */
|
|
702
|
-
schema?: ZodType2<unknown, ZodTypeDef, unknown>;
|
|
703
|
-
/** 默认值 */
|
|
704
|
-
defaults?: Record<string, unknown>;
|
|
705
|
-
}
|
|
706
|
-
/**
|
|
707
|
-
* ConfigSource 接口
|
|
708
|
-
*/
|
|
709
|
-
interface ConfigSource {
|
|
710
|
-
readonly name: ConfigSourceType;
|
|
711
|
-
readonly priority: number;
|
|
712
|
-
read(key: string): unknown | undefined;
|
|
713
|
-
write?(key: string, value: unknown): boolean;
|
|
714
|
-
delete?(key: string): boolean;
|
|
715
|
-
list(): Array<{
|
|
716
|
-
key: string;
|
|
717
|
-
value: unknown;
|
|
718
|
-
}>;
|
|
719
|
-
watch?(callback: (event: ConfigChangeEvent) => void): () => void;
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Config 变更事件
|
|
723
|
-
*/
|
|
724
|
-
interface ConfigChangeEvent {
|
|
725
|
-
type: "change" | "add" | "delete";
|
|
726
|
-
key: string;
|
|
727
|
-
oldValue: unknown;
|
|
728
|
-
newValue: unknown;
|
|
729
|
-
source: ConfigSourceType;
|
|
730
|
-
timestamp: number;
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* ConfigComponent 配置
|
|
734
|
-
*/
|
|
735
|
-
interface ConfigComponentOptions {
|
|
736
|
-
/** 持久化文件路径 */
|
|
737
|
-
persistFile?: string;
|
|
738
|
-
/** 防抖延迟(ms) */
|
|
739
|
-
debounceMs?: number;
|
|
740
|
-
/** 最大批量大小 */
|
|
741
|
-
maxBatchSize?: number;
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* ConfigComponent
|
|
745
|
-
*/
|
|
746
|
-
declare class ConfigComponent extends BaseComponent {
|
|
747
|
-
readonly name = "config";
|
|
748
|
-
readonly version = "1.0.0";
|
|
749
|
-
private memorySource;
|
|
750
|
-
private sources;
|
|
751
|
-
private componentSchemas;
|
|
752
|
-
private componentPaths;
|
|
753
|
-
private watchers;
|
|
754
|
-
/** Source watch unsubscribe 函数 */
|
|
755
|
-
private sourceUnwatchFns;
|
|
756
|
-
private persistQueue;
|
|
757
|
-
private persistFile?;
|
|
758
|
-
/** Key 注册表:key -> KeyRegistration */
|
|
759
|
-
private keyRegistry;
|
|
760
|
-
/** Component 注册表:name -> ComponentRegistration */
|
|
761
|
-
private componentRegistrations;
|
|
762
|
-
/** 协议解析器 */
|
|
763
|
-
private protocolResolver?;
|
|
764
|
-
/** XDG_DATA_HOME 缓存(用于测试注入) */
|
|
765
|
-
private __xdgDataHome?;
|
|
766
|
-
/** Source 注册配置(延迟创建) */
|
|
767
|
-
private pendingSources;
|
|
768
|
-
/** Source 唯一标识缓存:type:relativePath -> true */
|
|
769
|
-
private sourceKeys;
|
|
770
|
-
/**
|
|
771
|
-
* 获取 XDG_DATA_HOME(动态获取,支持运行时覆盖)
|
|
772
|
-
*/
|
|
773
|
-
getXdgDataHome(): string;
|
|
774
|
-
/**
|
|
775
|
-
* 设置 XDG_DATA_HOME(用于测试)
|
|
776
|
-
*/
|
|
777
|
-
setXdgDataHome(path: string): void;
|
|
778
|
-
constructor(options?: ConfigComponentOptions);
|
|
779
|
-
/**
|
|
780
|
-
* 注册 Component Schema
|
|
781
|
-
*/
|
|
782
|
-
register(schema: ComponentSchema): void;
|
|
783
|
-
/**
|
|
784
|
-
* 注销 Component
|
|
785
|
-
*/
|
|
786
|
-
unregister(name: string): boolean;
|
|
787
|
-
/**
|
|
788
|
-
* 检查是否已注册
|
|
789
|
-
*/
|
|
790
|
-
isRegistered(name: string): boolean;
|
|
791
|
-
/**
|
|
792
|
-
* 列出所有注册的 Component
|
|
793
|
-
*/
|
|
794
|
-
listComponents(): string[];
|
|
795
|
-
/**
|
|
796
|
-
* 获取配置值(支持 xxx.yyy.zzz 嵌套访问)
|
|
797
|
-
* 支持两种模式:
|
|
798
|
-
* 1. 完整 key:直接查找,如 "component.key" -> 读取 "component.key"
|
|
799
|
-
* 2. 嵌套对象:查找 component 对象后从中获取属性,如 "component.nested.deep"
|
|
800
|
-
* -> 先找 "component.nested",再获取其 "deep" 属性
|
|
801
|
-
*/
|
|
802
|
-
get(key: string): unknown;
|
|
803
|
-
/**
|
|
804
|
-
* 批量获取
|
|
805
|
-
*/
|
|
806
|
-
getMany(keys: string[]): Record<string, unknown>;
|
|
807
|
-
/**
|
|
808
|
-
* 设置配置值(内存级别 + 异步持久化)
|
|
809
|
-
*/
|
|
810
|
-
set(key: string, value: unknown): Promise<void>;
|
|
811
|
-
/**
|
|
812
|
-
* 批量设置
|
|
813
|
-
*/
|
|
814
|
-
setMany(config: Record<string, unknown>): Promise<void>;
|
|
815
|
-
/**
|
|
816
|
-
* 获取 Component 的路径
|
|
817
|
-
*/
|
|
818
|
-
getPath(component: string, subPath?: string): string;
|
|
819
|
-
/**
|
|
820
|
-
* 手动持久化
|
|
821
|
-
*/
|
|
822
|
-
save(key?: string): Promise<void>;
|
|
823
|
-
/**
|
|
824
|
-
* 重置到默认值
|
|
825
|
-
*/
|
|
826
|
-
reset(key: string): Promise<void>;
|
|
827
|
-
/**
|
|
828
|
-
* 监听配置变更
|
|
829
|
-
*/
|
|
830
|
-
watch(pattern: string, callback: ComponentWatchCallback): () => void;
|
|
831
|
-
/**
|
|
832
|
-
* 添加配置源
|
|
833
|
-
*/
|
|
834
|
-
addSource(source: ConfigSource): void;
|
|
835
|
-
/**
|
|
836
|
-
* 获取 Source 唯一标识
|
|
837
|
-
*/
|
|
838
|
-
private getSourceKey;
|
|
839
|
-
/**
|
|
840
|
-
* 移除配置源
|
|
841
|
-
*/
|
|
842
|
-
removeSource(name: ConfigSourceType): boolean;
|
|
843
|
-
/**
|
|
844
|
-
* 关闭所有配置源的 watcher(用于优雅退出)
|
|
845
|
-
*/
|
|
846
|
-
unwatchAll(): void;
|
|
847
|
-
/**
|
|
848
|
-
* 获取配置源列表
|
|
849
|
-
*/
|
|
850
|
-
getSources(): ConfigSource[];
|
|
851
|
-
private getNestedValue;
|
|
852
|
-
private notifyWatchers;
|
|
853
|
-
private persistToFile;
|
|
854
|
-
/**
|
|
855
|
-
* 注册配置 Source
|
|
856
|
-
*
|
|
857
|
-
* Source 会在首次 load() 时被创建
|
|
858
|
-
*
|
|
859
|
-
* @example
|
|
860
|
-
* config.registerSource({ type: "file", relativePath: "llm-config.jsonc" });
|
|
861
|
-
* config.registerSource({ type: "env", envPrefix: "LLM" });
|
|
862
|
-
*/
|
|
863
|
-
registerSource(registration: SourceRegistration): void;
|
|
864
|
-
/**
|
|
865
|
-
* 创建 Source 实例
|
|
866
|
-
*/
|
|
867
|
-
private createSource;
|
|
868
|
-
/**
|
|
869
|
-
* 确保所有待创建的 Source 已被创建
|
|
870
|
-
*/
|
|
871
|
-
private ensureSourcesCreated;
|
|
872
|
-
/**
|
|
873
|
-
* 注册配置 Key
|
|
874
|
-
*
|
|
875
|
-
* @example
|
|
876
|
-
* config.registerKeys([
|
|
877
|
-
* { key: "llm.provider", sources: ["file", "memory"], default: "openai" },
|
|
878
|
-
* { key: "llm.model", sources: ["file"] },
|
|
879
|
-
* ]);
|
|
880
|
-
*/
|
|
881
|
-
registerKeys(keys: KeyRegistration[]): void;
|
|
882
|
-
/**
|
|
883
|
-
* 注册 Component(一次性注册 Source 和 Keys)
|
|
884
|
-
*
|
|
885
|
-
* @example
|
|
886
|
-
* config.registerComponent({
|
|
887
|
-
* name: "llm",
|
|
888
|
-
* sources: [
|
|
889
|
-
* { type: "file", relativePath: "llm-config.jsonc" },
|
|
890
|
-
* { type: "env", envPrefix: "LLM" },
|
|
891
|
-
* ],
|
|
892
|
-
* keys: [
|
|
893
|
-
* { key: "llm.provider", sources: ["file", "env", "memory"] },
|
|
894
|
-
* ],
|
|
895
|
-
* });
|
|
896
|
-
*/
|
|
897
|
-
registerComponent(registration: ComponentRegistration): void;
|
|
898
|
-
/**
|
|
899
|
-
* 按需加载配置
|
|
900
|
-
*
|
|
901
|
-
* 从注册的 Source 加载已注册 Keys 的配置值到内存中
|
|
902
|
-
*
|
|
903
|
-
* @param componentName - 可选,指定要加载的 Component 名称
|
|
904
|
-
*
|
|
905
|
-
* @example
|
|
906
|
-
* // 加载所有已注册的 Keys
|
|
907
|
-
* await config.load();
|
|
908
|
-
*
|
|
909
|
-
* // 只加载指定 Component 的 Keys
|
|
910
|
-
* await config.load("llm");
|
|
911
|
-
*/
|
|
912
|
-
load(componentName?: string): Promise<void>;
|
|
913
|
-
/**
|
|
914
|
-
* 获取已注册的 Source 列表
|
|
915
|
-
*/
|
|
916
|
-
getRegisteredSources(): ConfigSource[];
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* 服务配置接口
|
|
920
|
-
*/
|
|
921
|
-
interface ServiceConfig {
|
|
922
|
-
/** 环境配置 */
|
|
923
|
-
environment?: {
|
|
924
|
-
name?: string;
|
|
925
|
-
version?: string;
|
|
926
|
-
};
|
|
927
|
-
/** 组件配置映射 */
|
|
928
|
-
components?: Record<string, ComponentConfigEntry>;
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* 组件配置项
|
|
932
|
-
*/
|
|
933
|
-
interface ComponentConfigEntry {
|
|
934
|
-
/** 配置文件路径(可选) */
|
|
935
|
-
configPath?: string;
|
|
936
|
-
/** 环境变量前缀(可选) */
|
|
937
|
-
envPrefix?: string;
|
|
938
|
-
/** 直接配置对象(可选) */
|
|
939
|
-
config?: Record<string, unknown>;
|
|
940
|
-
/** 是否启用(可选,默认 true) */
|
|
941
|
-
enabled?: boolean;
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* 组件初始化选项(由 generateComponentOptions 生成)
|
|
945
|
-
*/
|
|
946
|
-
interface GeneratedComponentOptions {
|
|
947
|
-
/** ConfigComponent 实例 */
|
|
948
|
-
configComponent: ConfigComponent;
|
|
949
|
-
/** 配置文件路径 */
|
|
950
|
-
configPath?: string;
|
|
951
|
-
/** 环境变量前缀 */
|
|
952
|
-
envPrefix?: string;
|
|
953
|
-
/** 直接配置对象 */
|
|
954
|
-
config?: Record<string, unknown>;
|
|
955
|
-
/** 允许的其他属性 */
|
|
956
|
-
[key: string]: unknown;
|
|
957
|
-
}
|
|
958
|
-
/**
|
|
959
|
-
* Environment 接口
|
|
960
|
-
*
|
|
961
|
-
* 定义 Agent 运行时的核心能力接口。
|
|
962
|
-
*/
|
|
963
|
-
interface Environment {
|
|
964
|
-
/** 环境名称 */
|
|
965
|
-
readonly name: string;
|
|
966
|
-
/** 环境版本 */
|
|
967
|
-
readonly version: string;
|
|
968
|
-
/** 获取环境配置 */
|
|
969
|
-
getConfig(): EnvironmentConfig;
|
|
970
|
-
/**
|
|
971
|
-
* 注册组件
|
|
972
|
-
*/
|
|
973
|
-
registerComponent(component: Component): void;
|
|
974
|
-
/**
|
|
975
|
-
* 注销组件
|
|
976
|
-
*/
|
|
977
|
-
unregisterComponent(name: string): void;
|
|
978
|
-
/**
|
|
979
|
-
* 获取组件
|
|
980
|
-
*/
|
|
981
|
-
getComponent<T extends Component>(name: string): T | undefined;
|
|
982
|
-
/**
|
|
983
|
-
* 列出所有组件
|
|
984
|
-
*/
|
|
985
|
-
listComponents(): Component[];
|
|
986
|
-
/**
|
|
987
|
-
* 处理自然语言查询(核心入口)
|
|
988
|
-
*
|
|
989
|
-
* @param query 用户查询文本
|
|
990
|
-
* @param context 执行上下文(可选)
|
|
991
|
-
* @returns 完整的文本响应
|
|
992
|
-
*/
|
|
993
|
-
handle_query(query: string, context?: AgentContext): Promise<string>;
|
|
994
|
-
/**
|
|
995
|
-
* 处理动作
|
|
996
|
-
*/
|
|
997
|
-
handle_action(action: Action, context: Context): Promise<ToolResult>;
|
|
998
|
-
/**
|
|
999
|
-
* 订阅 EnvEvent(返回取消订阅函数)
|
|
1000
|
-
*/
|
|
1001
|
-
subscribe(handler: EnvEventHandler): () => void;
|
|
1002
|
-
/**
|
|
1003
|
-
* 订阅指定类型事件
|
|
1004
|
-
*/
|
|
1005
|
-
subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
|
|
1006
|
-
/**
|
|
1007
|
-
* 订阅所有事件(通配符)
|
|
1008
|
-
*/
|
|
1009
|
-
subscribeAll(handler: EnvEventHandler): () => void;
|
|
1010
|
-
/**
|
|
1011
|
-
* 推送事件
|
|
1012
|
-
*
|
|
1013
|
-
* @param event EnvEvent 或 EnvEventInput(部分属性)
|
|
1014
|
-
*/
|
|
1015
|
-
pushEnvEvent(event: EnvEvent | EnvEventInput): void;
|
|
1016
|
-
/**
|
|
1017
|
-
* 从配置文件加载服务配置
|
|
1018
|
-
*
|
|
1019
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
1020
|
-
* @returns 解析后的服务配置对象
|
|
1021
|
-
*/
|
|
1022
|
-
loadServiceConfig(configPath: string): Promise<ServiceConfig>;
|
|
1023
|
-
/**
|
|
1024
|
-
* 生成组件初始化选项
|
|
1025
|
-
*
|
|
1026
|
-
* 根据组件配置项生成可用于初始化的选项对象。
|
|
1027
|
-
*
|
|
1028
|
-
* @param componentName 组件名称
|
|
1029
|
-
* @param configEntry 组件配置项
|
|
1030
|
-
* @returns 生成的组件初始化选项
|
|
1031
|
-
*/
|
|
1032
|
-
generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
|
|
1033
|
-
/**
|
|
1034
|
-
* 注册组件并用配置初始化
|
|
1035
|
-
*
|
|
1036
|
-
* 便捷方法:注册组件并通过 ConfigComponent 初始化。
|
|
1037
|
-
*
|
|
1038
|
-
* @param component 要注册的组件实例
|
|
1039
|
-
* @param configEntry 组件配置项
|
|
1040
|
-
*/
|
|
1041
|
-
registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
|
|
1042
|
-
/**
|
|
1043
|
-
* 从配置文件初始化整个环境
|
|
1044
|
-
*
|
|
1045
|
-
* 加载服务配置,注册并初始化所有配置的组件。
|
|
1046
|
-
*
|
|
1047
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
1048
|
-
*/
|
|
1049
|
-
initFromConfig(configPath: string): Promise<void>;
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* Component 状态
|
|
1053
|
-
*/
|
|
1054
|
-
type ComponentStatus = "created" | "initializing" | "running" | "stopping" | "stopped" | "error";
|
|
1055
|
-
/**
|
|
1056
|
-
* Component 配置
|
|
1057
|
-
*/
|
|
1058
|
-
interface ComponentConfig {
|
|
1059
|
-
name: string;
|
|
1060
|
-
version: string;
|
|
1061
|
-
enabled: boolean;
|
|
1062
|
-
options?: Record<string, unknown>;
|
|
1063
|
-
/**
|
|
1064
|
-
* Environment 实例(可选)
|
|
1065
|
-
*
|
|
1066
|
-
* 推荐在 init 时接收 env 实例,以便:
|
|
1067
|
-
* - 通过 env.getComponent() 获取其他组件
|
|
1068
|
-
* - 通过 env.pushEnvEvent() 发布事件
|
|
1069
|
-
* - 通过 env.handle_query() 处理查询
|
|
1070
|
-
*
|
|
1071
|
-
* 如果未提供,部分 Component 仍可正常工作(如测试场景)
|
|
1072
|
-
*
|
|
1073
|
-
* @example
|
|
1074
|
-
* ```typescript
|
|
1075
|
-
* async onInit(): Promise<void> {
|
|
1076
|
-
* if (this.env) {
|
|
1077
|
-
* const configComp = this.env.getComponent("config");
|
|
1078
|
-
* }
|
|
1079
|
-
* }
|
|
1080
|
-
* ```
|
|
1081
|
-
*/
|
|
1082
|
-
env?: Environment;
|
|
1083
|
-
}
|
|
1084
|
-
/**
|
|
1085
|
-
* Component 路径声明
|
|
1086
|
-
*/
|
|
1087
|
-
interface ComponentPaths {
|
|
1088
|
-
base: "config" | "state" | "data" | "cache";
|
|
1089
|
-
subPath: string;
|
|
1090
|
-
isDirectory: boolean;
|
|
1091
|
-
}
|
|
1092
|
-
/**
|
|
1093
|
-
* Component Schema(注册配置)
|
|
1094
|
-
*/
|
|
1095
|
-
interface ComponentSchema {
|
|
1096
|
-
/** Component 名称 */
|
|
1097
|
-
name: string;
|
|
1098
|
-
/** 配置 Schema(Zod) */
|
|
1099
|
-
schema: ZodType3<unknown, ZodTypeDef2, unknown>;
|
|
1100
|
-
/** 默认值(从 Schema 提取) */
|
|
1101
|
-
defaults: Record<string, unknown>;
|
|
1102
|
-
/** 路径声明 */
|
|
1103
|
-
paths?: Record<string, ComponentPaths>;
|
|
1104
|
-
/** 元信息 */
|
|
1105
|
-
metadata?: {
|
|
1106
|
-
description?: string;
|
|
1107
|
-
version?: string;
|
|
1108
|
-
author?: string;
|
|
1109
|
-
};
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Component 配置变更事件
|
|
1113
|
-
*/
|
|
1114
|
-
interface ComponentConfigChangeEvent {
|
|
1115
|
-
/** Component 名称 */
|
|
1116
|
-
component: string;
|
|
1117
|
-
/** 变更的配置键 */
|
|
1118
|
-
key: string;
|
|
1119
|
-
/** 旧值 */
|
|
1120
|
-
oldValue: unknown;
|
|
1121
|
-
/** 新值 */
|
|
1122
|
-
newValue: unknown;
|
|
1123
|
-
/** 是否持久化 */
|
|
1124
|
-
persisted: boolean;
|
|
1125
|
-
/** 时间戳 */
|
|
1126
|
-
timestamp: number;
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Component 配置监听回调
|
|
1130
|
-
*/
|
|
1131
|
-
type ComponentWatchCallback = (event: ComponentConfigChangeEvent) => void | Promise<void>;
|
|
1132
|
-
/**
|
|
1133
|
-
* Component 基类接口
|
|
1134
|
-
*/
|
|
1135
|
-
interface Component {
|
|
1136
|
-
/** Component 名称 */
|
|
1137
|
-
readonly name: string;
|
|
1138
|
-
/** Component 版本 */
|
|
1139
|
-
readonly version: string;
|
|
1140
|
-
/** 获取状态 */
|
|
1141
|
-
getStatus(): ComponentStatus;
|
|
1142
|
-
/** 获取配置 */
|
|
1143
|
-
getConfig(): ComponentConfig;
|
|
1144
|
-
/** 初始化 */
|
|
1145
|
-
init(config: ComponentConfig): Promise<void>;
|
|
1146
|
-
/** 启动 */
|
|
1147
|
-
start(): Promise<void>;
|
|
1148
|
-
/** 停止 */
|
|
1149
|
-
stop(): Promise<void>;
|
|
1150
|
-
}
|
|
1151
|
-
/**
|
|
1152
|
-
* Component 基类实现
|
|
1153
|
-
*/
|
|
1154
|
-
declare abstract class BaseComponent implements Component {
|
|
1155
|
-
abstract readonly name: string;
|
|
1156
|
-
abstract readonly version: string;
|
|
1157
|
-
protected _status: ComponentStatus;
|
|
1158
|
-
protected _enabled: boolean;
|
|
1159
|
-
protected env: Environment;
|
|
1160
|
-
/** Hook 管理器 - 子类初始化时由构造函数设置 */
|
|
1161
|
-
readonly hookManager: HookManager;
|
|
1162
|
-
constructor();
|
|
1163
|
-
getStatus(): ComponentStatus;
|
|
1164
|
-
getConfig(): ComponentConfig;
|
|
1165
|
-
/**
|
|
1166
|
-
* 检查 Environment 是否已初始化
|
|
1167
|
-
*/
|
|
1168
|
-
protected isEnvInitialized(): boolean;
|
|
1169
|
-
protected setStatus(status: ComponentStatus): void;
|
|
1170
|
-
/**
|
|
1171
|
-
* 获取 Environment 实例
|
|
1172
|
-
*/
|
|
1173
|
-
protected getEnv(): Environment;
|
|
1174
|
-
init(config?: ComponentConfig): Promise<void>;
|
|
1175
|
-
start(): Promise<void>;
|
|
1176
|
-
stop(): Promise<void>;
|
|
1177
|
-
/**
|
|
1178
|
-
* 子类可覆盖的钩子方法
|
|
1179
|
-
*/
|
|
1180
|
-
protected onInit(): Promise<void>;
|
|
1181
|
-
protected onStart(): Promise<void>;
|
|
1182
|
-
protected onStop(): Promise<void>;
|
|
1183
|
-
/**
|
|
1184
|
-
* 注册 Hook
|
|
1185
|
-
*
|
|
1186
|
-
* @param hookPoint Hook 点名称
|
|
1187
|
-
* @param hook Hook 实例
|
|
1188
|
-
*/
|
|
1189
|
-
protected registerHook<T = unknown>(hookPoint: string, hook: Hook<T>): void;
|
|
1190
|
-
/**
|
|
1191
|
-
* 便捷方法:快速注册 Hook
|
|
1192
|
-
*/
|
|
1193
|
-
protected addHook<T = unknown>(hookPoint: string, name: string, fn: HookFn<T>, priority?: number): void;
|
|
1194
|
-
/**
|
|
1195
|
-
* 便捷方法:按名称取消注册 Hook
|
|
1196
|
-
*/
|
|
1197
|
-
protected removeHook(hookPoint: string, name: string): boolean;
|
|
1198
|
-
/**
|
|
1199
|
-
* 执行 Hook
|
|
1200
|
-
*/
|
|
1201
|
-
protected executeHooks<T = unknown>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
|
|
1202
|
-
/**
|
|
1203
|
-
* 获取 ConfigComponent 实例
|
|
1204
|
-
*
|
|
1205
|
-
* 子类可使用此方法获取配置组件,支持热更新
|
|
1206
|
-
*/
|
|
1207
|
-
protected getConfigComponent(): {
|
|
1208
|
-
get(key: string): unknown;
|
|
1209
|
-
} | undefined;
|
|
1210
|
-
/**
|
|
1211
|
-
* 动态获取运行时配置值
|
|
1212
|
-
*
|
|
1213
|
-
* 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
|
|
1214
|
-
* 适用于运行时可能变化的配置(如 API Keys、模型参数)
|
|
1215
|
-
*
|
|
1216
|
-
* @param key 配置键(支持点号分隔的路径,如 "llm.temperature")
|
|
1217
|
-
* @param defaultValue 默认值
|
|
1218
|
-
* @returns 配置值或默认值
|
|
1219
|
-
*
|
|
1220
|
-
* @example
|
|
1221
|
-
* ```typescript
|
|
1222
|
-
* // 获取 LLM 温度配置(可能支持热更新)
|
|
1223
|
-
* const temperature = this.getRuntimeConfig("llm.temperature", 0.7);
|
|
1224
|
-
*
|
|
1225
|
-
* // 获取 API Key
|
|
1226
|
-
* const apiKey = this.getRuntimeConfig<string>("llm.providers.openai.apiKey");
|
|
1227
|
-
* ```
|
|
1228
|
-
*/
|
|
1229
|
-
protected getRuntimeConfig<T>(key: string, defaultValue: T): T;
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Log Reader for reading and parsing log files
|
|
1233
|
-
*/
|
|
1234
|
-
declare class LogReader {
|
|
1235
|
-
private logDir;
|
|
1236
|
-
constructor(options?: {
|
|
1237
|
-
logDir?: string;
|
|
1238
|
-
});
|
|
1239
|
-
/**
|
|
1240
|
-
* Get the full path to a log file
|
|
1241
|
-
*/
|
|
1242
|
-
getLogPath(filename?: string): string;
|
|
1243
|
-
/**
|
|
1244
|
-
* Find log files matching a pattern
|
|
1245
|
-
*
|
|
1246
|
-
* Uses forward slashes for glob patterns to ensure cross-platform compatibility.
|
|
1247
|
-
* The glob library requires forward slashes regardless of OS.
|
|
1248
|
-
*/
|
|
1249
|
-
findLogFiles(pattern?: string): Promise<string[]>;
|
|
1250
|
-
/**
|
|
1251
|
-
* Get default log directory
|
|
1252
|
-
*/
|
|
1253
|
-
getDefaultLogDir(): string;
|
|
1254
|
-
/**
|
|
1255
|
-
* Read lines from a log file with optional filtering
|
|
1256
|
-
*/
|
|
1257
|
-
readLines(filepath: string, options?: ParserOptions): AsyncGenerator<string>;
|
|
1258
|
-
/**
|
|
1259
|
-
* Extract timestamp from a log line
|
|
1260
|
-
*/
|
|
1261
|
-
extractTimestamp(line: string): number | null;
|
|
1262
|
-
/**
|
|
1263
|
-
* Parse time string to timestamp
|
|
1264
|
-
* Supports ISO format and relative time like "1h", "30m"
|
|
1265
|
-
*/
|
|
1266
|
-
parseTime(timeStr: string): number;
|
|
1267
|
-
/**
|
|
1268
|
-
* Read file content directly (for small files)
|
|
1269
|
-
*/
|
|
1270
|
-
readFile(filepath: string): Promise<string>;
|
|
1271
|
-
/**
|
|
1272
|
-
* Check if a log file exists
|
|
1273
|
-
*/
|
|
1274
|
-
exists(filepath: string): boolean;
|
|
1275
|
-
}
|
|
1276
|
-
/**
|
|
1277
|
-
* Span 属性
|
|
1278
|
-
*/
|
|
1279
|
-
interface SpanAttributes {
|
|
1280
|
-
[key: string]: string | number | boolean | undefined | Record<string, unknown>;
|
|
1281
|
-
}
|
|
1282
|
-
/**
|
|
1283
|
-
* Span
|
|
1284
|
-
*/
|
|
1285
|
-
interface Span {
|
|
1286
|
-
traceId: string;
|
|
1287
|
-
spanId: string;
|
|
1288
|
-
parentSpanId?: string;
|
|
1289
|
-
name: string;
|
|
1290
|
-
kind: SpanKind;
|
|
1291
|
-
status: SpanStatus;
|
|
1292
|
-
startTime: number;
|
|
1293
|
-
endTime?: number;
|
|
1294
|
-
attributes: SpanAttributes;
|
|
1295
|
-
result?: unknown;
|
|
1296
|
-
error?: string;
|
|
1297
|
-
children?: Span[];
|
|
1298
|
-
}
|
|
1299
|
-
/**
|
|
1300
|
-
* Span 类型
|
|
1301
|
-
*/
|
|
1302
|
-
declare enum SpanKind {
|
|
1303
|
-
CLIENT = "client",
|
|
1304
|
-
SERVER = "server",
|
|
1305
|
-
INTERNAL = "internal"
|
|
1306
|
-
}
|
|
1307
|
-
/**
|
|
1308
|
-
* Span 状态
|
|
1309
|
-
*/
|
|
1310
|
-
declare enum SpanStatus {
|
|
1311
|
-
OK = "ok",
|
|
1312
|
-
ERROR = "error"
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Trace 信息
|
|
1316
|
-
*/
|
|
1317
|
-
interface TraceInfo {
|
|
1318
|
-
traceId: string;
|
|
1319
|
-
rootSpanName: string;
|
|
1320
|
-
startTime: number;
|
|
1321
|
-
endTime?: number;
|
|
1322
|
-
duration?: number;
|
|
1323
|
-
spanCount: number;
|
|
1324
|
-
status: "ok" | "error" | "mixed";
|
|
1325
|
-
}
|
|
1326
|
-
/**
|
|
1327
|
-
* SpanStorage 接口
|
|
1328
|
-
*/
|
|
1329
|
-
interface SpanStorage {
|
|
1330
|
-
initialize(): Promise<void>;
|
|
1331
|
-
save(span: Span): void;
|
|
1332
|
-
saveBatch(spans: Span[]): void;
|
|
1333
|
-
findByTraceId(traceId: string): Span[];
|
|
1334
|
-
findBySpanId(spanId: string): Span | undefined;
|
|
1335
|
-
listTraces(limit?: number): TraceInfo[];
|
|
1336
|
-
deleteByTraceId(traceId: string): void;
|
|
1337
|
-
close(): void;
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* Options for SpanDbReader
|
|
1341
|
-
*/
|
|
1342
|
-
interface SpanDbReaderOptions {
|
|
1343
|
-
/** Database path (for file-based SQLite) */
|
|
1344
|
-
dbPath?: string;
|
|
1345
|
-
/** Storage instance to use directly */
|
|
1346
|
-
storage?: SpanStorage;
|
|
1347
|
-
}
|
|
1348
|
-
/**
|
|
1349
|
-
* Span Database Reader
|
|
1350
|
-
*
|
|
1351
|
-
* Reads span data from SQLite storage for trace debugging and analysis.
|
|
1352
|
-
*/
|
|
1353
|
-
declare class SpanDbReader {
|
|
1354
|
-
private storage;
|
|
1355
|
-
private dbPath;
|
|
1356
|
-
private sqliteDb;
|
|
1357
|
-
constructor(options?: SpanDbReaderOptions);
|
|
1358
|
-
/**
|
|
1359
|
-
* Initialize the reader with storage
|
|
1360
|
-
*/
|
|
1361
|
-
initialize(): Promise<void>;
|
|
1362
|
-
/**
|
|
1363
|
-
* Initialize SQLite storage directly
|
|
1364
|
-
*/
|
|
1365
|
-
private initSqliteStorage;
|
|
1366
|
-
/**
|
|
1367
|
-
* Get trace entries for a specific traceId
|
|
1368
|
-
*/
|
|
1369
|
-
getTraceEntries(traceId: string): Promise<TraceEntry[]>;
|
|
1370
|
-
/**
|
|
1371
|
-
* List all trace IDs
|
|
1372
|
-
*/
|
|
1373
|
-
listTraceIds(limit?: number): Promise<TraceSummary>;
|
|
1374
|
-
/**
|
|
1375
|
-
* Convert spans to TraceEntry format
|
|
1376
|
-
*
|
|
1377
|
-
* Now properly extracts spanId and parentSpanId for tree building
|
|
1378
|
-
*/
|
|
1379
|
-
private spansToEntries;
|
|
1380
|
-
/**
|
|
1381
|
-
* Convert span attributes to params format
|
|
1382
|
-
*/
|
|
1383
|
-
private attributesToParams;
|
|
1384
|
-
/**
|
|
1385
|
-
* Get the underlying storage
|
|
1386
|
-
*/
|
|
1387
|
-
getStorage(): SpanStorage | null;
|
|
1388
|
-
/**
|
|
1389
|
-
* Close the reader and cleanup resources
|
|
1390
|
-
*/
|
|
1391
|
-
close(): void;
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* Regex Parser for trace log lines
|
|
1395
|
-
*/
|
|
1396
|
-
declare class RegexParser {
|
|
1397
|
-
/**
|
|
1398
|
-
* Parse a single log line
|
|
1399
|
-
*/
|
|
1400
|
-
parseLogLine(line: string): ParsedLogLine | null;
|
|
1401
|
-
/**
|
|
1402
|
-
* Parse arguments from raw args string
|
|
1403
|
-
*/
|
|
1404
|
-
parseArgs(raw: string): unknown | unknown[] | null;
|
|
1405
|
-
/**
|
|
1406
|
-
* Check if a line is a trace line
|
|
1407
|
-
*/
|
|
1408
|
-
isTraceLine(line: string): boolean;
|
|
1409
|
-
/**
|
|
1410
|
-
* Filter lines by log level
|
|
1411
|
-
*/
|
|
1412
|
-
filterByLevel(lines: string[], level?: LogLevel): string[];
|
|
1413
|
-
/**
|
|
1414
|
-
* Filter lines by function name
|
|
1415
|
-
*/
|
|
1416
|
-
filterByFunction(lines: string[], functionName?: string): string[];
|
|
1417
|
-
/**
|
|
1418
|
-
* Extract trace ID from log line
|
|
1419
|
-
* Checks for requestId in two places:
|
|
1420
|
-
* 1. Category field: [source][requestId=req_123]
|
|
1421
|
-
* 2. After method name: [requestId=req_abc]
|
|
1422
|
-
*/
|
|
1423
|
-
extractTraceId(line: string): string | null;
|
|
1424
|
-
/**
|
|
1425
|
-
* Extract trace IDs from multiple lines
|
|
1426
|
-
*/
|
|
1427
|
-
extractTraceIds(lines: string[]): Map<string, string[]>;
|
|
1428
|
-
/**
|
|
1429
|
-
* Parse multiple lines
|
|
1430
|
-
*/
|
|
1431
|
-
parseLines(lines: string[]): ParsedLogLine[];
|
|
1432
|
-
}
|
|
1433
|
-
/**
|
|
1434
|
-
* Paired enter/quit entries
|
|
1435
|
-
*/
|
|
1436
|
-
interface PairedSpan {
|
|
1437
|
-
enter: TraceEntry;
|
|
1438
|
-
quit: TraceEntry;
|
|
1439
|
-
durationMs: number;
|
|
1440
|
-
}
|
|
1441
|
-
/**
|
|
1442
|
-
* Span Builder for constructing trace entries and call trees
|
|
1443
|
-
*/
|
|
1444
|
-
declare class SpanBuilder {
|
|
1445
|
-
private parser;
|
|
1446
|
-
constructor();
|
|
1447
|
-
/**
|
|
1448
|
-
* Build trace entries from parsed log lines
|
|
1449
|
-
*/
|
|
1450
|
-
buildTraceEntries(lines: ParsedLogLine[]): TraceEntry[];
|
|
1451
|
-
/**
|
|
1452
|
-
* Build a single trace entry from a parsed log line
|
|
1453
|
-
*/
|
|
1454
|
-
private buildTraceEntry;
|
|
1455
|
-
/**
|
|
1456
|
-
* Generate a virtual trace ID when no real traceId is present
|
|
1457
|
-
* Uses function name and timestamp to create a pseudo-traceId
|
|
1458
|
-
*/
|
|
1459
|
-
generateVirtualTraceId(functionName: string, timestamp: string): string;
|
|
1460
|
-
/**
|
|
1461
|
-
* Extract trace ID from log line
|
|
1462
|
-
*/
|
|
1463
|
-
private extractTraceId;
|
|
1464
|
-
/**
|
|
1465
|
-
* Calculate duration between enter and quit entries
|
|
1466
|
-
*/
|
|
1467
|
-
calculateDuration(enter: TraceEntry, quit: TraceEntry): number;
|
|
1468
|
-
/**
|
|
1469
|
-
* Pair enter and quit entries
|
|
1470
|
-
*/
|
|
1471
|
-
pairEnterQuit(entries: TraceEntry[]): PairedSpan[];
|
|
1472
|
-
/**
|
|
1473
|
-
* Build a call tree from trace entries using call stack tracking
|
|
1474
|
-
*
|
|
1475
|
-
* Enhanced to support both:
|
|
1476
|
-
* 1. Traditional enter/quit pair-based tree building (from log files)
|
|
1477
|
-
* 2. Parent-child hierarchy-based tree building (from SQLite spans)
|
|
1478
|
-
*/
|
|
1479
|
-
buildCallTree(entries: TraceEntry[]): TraceTreeNode | null;
|
|
1480
|
-
/**
|
|
1481
|
-
* Build call tree from parent-child span hierarchy (for SQLite spans)
|
|
1482
|
-
*/
|
|
1483
|
-
buildCallTreeFromHierarchy(entries: TraceEntry[]): TraceTreeNode | null;
|
|
1484
|
-
/**
|
|
1485
|
-
* Build call tree from traditional enter/quit pairs (for log files)
|
|
1486
|
-
*/
|
|
1487
|
-
buildCallTreeFromPairs(entries: TraceEntry[]): TraceTreeNode | null;
|
|
1488
|
-
/**
|
|
1489
|
-
* Build a tree node from a paired span
|
|
1490
|
-
*/
|
|
1491
|
-
private buildNodeFromPaired;
|
|
1492
|
-
/**
|
|
1493
|
-
* Merge entries from multiple functions into a single call tree
|
|
1494
|
-
*/
|
|
1495
|
-
buildMergedTree(entriesByFunction: Map<string, TraceEntry[]>): TraceTreeNode | null;
|
|
1496
|
-
/**
|
|
1497
|
-
* Get duration summary for entries
|
|
1498
|
-
*/
|
|
1499
|
-
getDurationSummary(entries: TraceEntry[]): Map<string, {
|
|
1500
|
-
count: number;
|
|
1501
|
-
totalMs: number;
|
|
1502
|
-
avgMs: number;
|
|
1503
|
-
}>;
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
* Data source type for trace retrieval
|
|
1507
|
-
*/
|
|
1508
|
-
type TraceDataSource = "log" | "sqlite";
|
|
1509
|
-
/**
|
|
1510
|
-
* Extended parser options with data source support
|
|
1511
|
-
*/
|
|
1512
|
-
interface TraceParserOptions extends ParserOptions {
|
|
1513
|
-
/** Data source type: 'log' (default) or 'sqlite' */
|
|
1514
|
-
source?: TraceDataSource;
|
|
1515
|
-
/** SQLite database path (required when source is 'sqlite') */
|
|
1516
|
-
dbPath?: string;
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* DebugComponent configuration options
|
|
1520
|
-
*/
|
|
1521
|
-
interface DebugComponentOptions {
|
|
1522
|
-
/** Log directory path */
|
|
1523
|
-
logDir?: string;
|
|
1524
|
-
/** Default log file */
|
|
1525
|
-
defaultLogFile?: string;
|
|
1526
|
-
}
|
|
1527
|
-
/**
|
|
1528
|
-
* Debug Component for trace analysis and debugging
|
|
1529
|
-
*/
|
|
1530
|
-
declare class DebugComponent extends BaseComponent {
|
|
1531
|
-
name: string;
|
|
1532
|
-
version: string;
|
|
1533
|
-
private reader;
|
|
1534
|
-
private spanDbReader;
|
|
1535
|
-
private parser;
|
|
1536
|
-
private spanBuilder;
|
|
1537
|
-
private traceFormatter;
|
|
1538
|
-
private treeFormatter;
|
|
1539
|
-
private options;
|
|
1540
|
-
constructor(options?: DebugComponentOptions);
|
|
1541
|
-
/**
|
|
1542
|
-
* Initialize the span database reader
|
|
1543
|
-
*/
|
|
1544
|
-
initSpanDbReader(dbPath?: string): Promise<void>;
|
|
1545
|
-
/**
|
|
1546
|
-
* Get the span database reader
|
|
1547
|
-
*/
|
|
1548
|
-
getSpanDbReader(): SpanDbReader | null;
|
|
1549
|
-
/**
|
|
1550
|
-
* Get trace by ID from live Tracer storage
|
|
1551
|
-
*
|
|
1552
|
-
* This method retrieves traces directly from the Tracer's span storage,
|
|
1553
|
-
* which includes spans from the current session that may not yet be persisted
|
|
1554
|
-
* to log files.
|
|
1555
|
-
*/
|
|
1556
|
-
getLiveTrace(traceId: string): Promise<any | null>;
|
|
1557
|
-
/**
|
|
1558
|
-
* List all available traces from live Tracer storage
|
|
1559
|
-
*/
|
|
1560
|
-
listLiveTraces(limit?: number): Promise<any>;
|
|
1561
|
-
/**
|
|
1562
|
-
* Format a live trace for display
|
|
1563
|
-
*/
|
|
1564
|
-
formatLiveTrace(traceId: string): Promise<string>;
|
|
1565
|
-
/**
|
|
1566
|
-
* Initialize the component
|
|
1567
|
-
*/
|
|
1568
|
-
init(config?: ComponentConfig): Promise<void>;
|
|
1569
|
-
/**
|
|
1570
|
-
* Stop the component
|
|
1571
|
-
*/
|
|
1572
|
-
stop(): Promise<void>;
|
|
1573
|
-
/**
|
|
1574
|
-
* Get traces matching the options
|
|
1575
|
-
*/
|
|
1576
|
-
getTraces(options?: TraceParserOptions): Promise<TraceEntry[]>;
|
|
1577
|
-
/**
|
|
1578
|
-
* Get traces from SQLite database
|
|
1579
|
-
*/
|
|
1580
|
-
private getTracesFromSqlite;
|
|
1581
|
-
/**
|
|
1582
|
-
* List available trace IDs
|
|
1583
|
-
*/
|
|
1584
|
-
listTraceIds(options?: TraceParserOptions & {
|
|
1585
|
-
limit?: number;
|
|
1586
|
-
}): Promise<TraceSummary>;
|
|
1587
|
-
/**
|
|
1588
|
-
* List trace IDs from SQLite database
|
|
1589
|
-
*/
|
|
1590
|
-
private listTraceIdsFromSqlite;
|
|
1591
|
-
/**
|
|
1592
|
-
* Get call tree for a specific trace
|
|
1593
|
-
*/
|
|
1594
|
-
getCallTree(options?: TraceParserOptions): Promise<TraceTreeNode | null>;
|
|
1595
|
-
/**
|
|
1596
|
-
* Get the log reader instance
|
|
1597
|
-
*/
|
|
1598
|
-
getReader(): LogReader;
|
|
1599
|
-
/**
|
|
1600
|
-
* Get the parser instance
|
|
1601
|
-
*/
|
|
1602
|
-
getParser(): RegexParser;
|
|
1603
|
-
/**
|
|
1604
|
-
* Get the span builder instance
|
|
1605
|
-
*/
|
|
1606
|
-
getSpanBuilder(): SpanBuilder;
|
|
1607
|
-
/**
|
|
1608
|
-
* Get the trace formatter instance
|
|
1609
|
-
*/
|
|
1610
|
-
getTraceFormatter(): TraceFormatter;
|
|
1611
|
-
/**
|
|
1612
|
-
* Get the tree formatter instance
|
|
1613
|
-
*/
|
|
1614
|
-
getTreeFormatter(): TreeFormatter;
|
|
1615
|
-
/**
|
|
1616
|
-
* Format traces for display
|
|
1617
|
-
*/
|
|
1618
|
-
formatTraces(entries: TraceEntry[], options?: FormatOptions): string;
|
|
1619
|
-
/**
|
|
1620
|
-
* Format a single trace entry
|
|
1621
|
-
*/
|
|
1622
|
-
formatTraceEntry(entry: TraceEntry, options?: FormatOptions): string;
|
|
1623
|
-
/**
|
|
1624
|
-
* Format traces as JSON
|
|
1625
|
-
*/
|
|
1626
|
-
tracesToJSON(entries: TraceEntry[]): string;
|
|
1627
|
-
/**
|
|
1628
|
-
* Format traces as summary
|
|
1629
|
-
*/
|
|
1630
|
-
tracesToSummary(entries: TraceEntry[]): string;
|
|
1631
|
-
/**
|
|
1632
|
-
* Format call tree for display
|
|
1633
|
-
*/
|
|
1634
|
-
formatTree(node: TraceTreeNode): string;
|
|
1635
|
-
/**
|
|
1636
|
-
* Format multiple call trees
|
|
1637
|
-
*/
|
|
1638
|
-
formatTrees(trees: TraceTreeNode[]): string;
|
|
1639
|
-
/**
|
|
1640
|
-
* Format trees as JSON
|
|
1641
|
-
*/
|
|
1642
|
-
treesToJSON(trees: TraceTreeNode[]): string;
|
|
1643
|
-
/**
|
|
1644
|
-
* Format tree summary (sorted by duration)
|
|
1645
|
-
*/
|
|
1646
|
-
formatTreeSummary(node: TraceTreeNode): string;
|
|
1647
|
-
/**
|
|
1648
|
-
* Format tree with timeline visualization
|
|
1649
|
-
*/
|
|
1650
|
-
formatTreeTimeline(node: TraceTreeNode): string;
|
|
1651
|
-
}
|
|
1652
|
-
export { TreeFormatter, TraceTreeNode, TraceSummary, TraceParserOptions, TraceIdInfo, TraceFormatter, TraceEntry, TraceDataSource, TraceAction, SpanDbReader, SpanBuilder, ReplFormatter, RegexParser, ParserOptions, ParsedLogLine, LogReader, LogLevel, LogDiscoveryOptions, FormatOptions, DebugComponent };
|