@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
package/dist/env/llm/index.d.ts
DELETED
|
@@ -1,1760 +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
|
-
* LLM Message
|
|
207
|
-
*/
|
|
208
|
-
interface LLMMessage {
|
|
209
|
-
/** 消息角色 */
|
|
210
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
211
|
-
/** 消息内容 */
|
|
212
|
-
content: string;
|
|
213
|
-
/** 工具调用(仅 assistant 角色) */
|
|
214
|
-
toolCalls?: ToolCall[];
|
|
215
|
-
/** 工具调用 ID(仅 tool 角色) */
|
|
216
|
-
toolCallId?: string;
|
|
217
|
-
/** 名称(用于 function 调用) */
|
|
218
|
-
name?: string;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Tool Call (OpenAI format)
|
|
222
|
-
*/
|
|
223
|
-
interface ToolCall {
|
|
224
|
-
/** 工具调用 ID */
|
|
225
|
-
id: string;
|
|
226
|
-
/** 工具名称 */
|
|
227
|
-
name: string;
|
|
228
|
-
/** 工具参数(JSON 字符串) */
|
|
229
|
-
arguments: string;
|
|
230
|
-
/** OpenAI 格式的 function 对象 */
|
|
231
|
-
function?: {
|
|
232
|
-
/** 函数名称 */
|
|
233
|
-
name: string;
|
|
234
|
-
/** 函数参数(JSON 字符串) */
|
|
235
|
-
arguments: string;
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Tool Result
|
|
240
|
-
*/
|
|
241
|
-
interface ToolResult {
|
|
242
|
-
/** 对应的工具调用 ID */
|
|
243
|
-
toolCallId: string;
|
|
244
|
-
/** 工具执行结果 */
|
|
245
|
-
result: string;
|
|
246
|
-
/** 是否为错误 */
|
|
247
|
-
isError?: boolean;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Usage Information
|
|
251
|
-
*/
|
|
252
|
-
interface UsageInfo {
|
|
253
|
-
/** Prompt Token 数 */
|
|
254
|
-
promptTokens: number;
|
|
255
|
-
/** Completion Token 数 */
|
|
256
|
-
completionTokens: number;
|
|
257
|
-
/** 总 Token 数 */
|
|
258
|
-
totalTokens: number;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* LLM Output
|
|
262
|
-
*/
|
|
263
|
-
interface LLMOutput {
|
|
264
|
-
/** 生成的内容 */
|
|
265
|
-
content: string;
|
|
266
|
-
/** 推理/思考内容(支持 reasoning 模型的输出) */
|
|
267
|
-
reasoning?: string;
|
|
268
|
-
/** 完成原因 */
|
|
269
|
-
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "function-call";
|
|
270
|
-
/** 工具调用 */
|
|
271
|
-
toolCalls?: ToolCall[];
|
|
272
|
-
/** Usage 信息 */
|
|
273
|
-
usage?: UsageInfo;
|
|
274
|
-
/** 生成模型 */
|
|
275
|
-
model?: string;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Provider 类型
|
|
279
|
-
*/
|
|
280
|
-
type ProviderType = "openai" | "anthropic" | "google" | "openai-compatible";
|
|
281
|
-
/**
|
|
282
|
-
* Provider 能力配置
|
|
283
|
-
*/
|
|
284
|
-
interface ProviderCapabilities {
|
|
285
|
-
/** 支持推理(CoT) */
|
|
286
|
-
reasoning?: boolean;
|
|
287
|
-
/** 支持工具调用 */
|
|
288
|
-
toolcall?: boolean;
|
|
289
|
-
/** 混合内容字段(用于解析推理内容) */
|
|
290
|
-
interleaved?: {
|
|
291
|
-
/** 字段名 */
|
|
292
|
-
field: string;
|
|
293
|
-
};
|
|
294
|
-
/** 文本内思考标签配置 */
|
|
295
|
-
thinkingInText?: {
|
|
296
|
-
/** 是否启用 */
|
|
297
|
-
enabled?: boolean;
|
|
298
|
-
/** 标签列表 */
|
|
299
|
-
tags?: string[];
|
|
300
|
-
/** 是否从输出中移除标签内容 */
|
|
301
|
-
removeFromOutput?: boolean;
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* 模型限制配置
|
|
306
|
-
*/
|
|
307
|
-
interface ModelLimits {
|
|
308
|
-
/** 上下文窗口大小(Token 数) */
|
|
309
|
-
contextWindow: number;
|
|
310
|
-
/** 压缩阈值(0-1),超过此比例触发上下文压缩 */
|
|
311
|
-
compactionThreshold?: number;
|
|
312
|
-
/** 最大输出 Token 数 */
|
|
313
|
-
maxOutputTokens?: number;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Provider 配置
|
|
317
|
-
*/
|
|
318
|
-
interface ProviderConfig {
|
|
319
|
-
/** Provider 类型 */
|
|
320
|
-
provider: ProviderType | string;
|
|
321
|
-
/** Provider 名称 */
|
|
322
|
-
name?: string;
|
|
323
|
-
/** Provider 描述 */
|
|
324
|
-
description?: string;
|
|
325
|
-
/** API Key */
|
|
326
|
-
apiKey: string;
|
|
327
|
-
/** Base URL(可选,用于代理或兼容 API) */
|
|
328
|
-
baseURL?: string;
|
|
329
|
-
/** 支持的模型列表 */
|
|
330
|
-
models?: string[];
|
|
331
|
-
/** Provider 默认模型 */
|
|
332
|
-
defaultModel?: string;
|
|
333
|
-
/** Provider 默认温度参数 */
|
|
334
|
-
temperature?: number;
|
|
335
|
-
/** Provider 默认最大 Token 数 */
|
|
336
|
-
maxTokens?: number;
|
|
337
|
-
/** Provider 能力配置 */
|
|
338
|
-
capabilities?: ProviderCapabilities;
|
|
339
|
-
/** 模型限制配置(按模型 ID 索引) */
|
|
340
|
-
limits?: Record<string, ModelLimits>;
|
|
341
|
-
/** Provider 特定选项(如 __dangerous__) */
|
|
342
|
-
providerOptions?: Record<string, unknown>;
|
|
343
|
-
/** 其他配置 */
|
|
344
|
-
options?: Record<string, unknown>;
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* LLM Provider 实例(由 AI SDK 创建)
|
|
348
|
-
*/
|
|
349
|
-
interface LLMProvider {
|
|
350
|
-
/** Provider ID */
|
|
351
|
-
id: string;
|
|
352
|
-
/** Provider 实例 */
|
|
353
|
-
provider: unknown;
|
|
354
|
-
/** 支持的模型 */
|
|
355
|
-
models: string[];
|
|
356
|
-
/** Provider 配置 */
|
|
357
|
-
config?: ProviderConfig;
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* 全局默认配置
|
|
361
|
-
*/
|
|
362
|
-
interface LLMDefaultConfig {
|
|
363
|
-
/** 默认温度参数 */
|
|
364
|
-
temperature?: number;
|
|
365
|
-
/** 默认最大 Token 数 */
|
|
366
|
-
maxTokens?: number;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* LLM Config
|
|
370
|
-
*/
|
|
371
|
-
interface LLMConfig {
|
|
372
|
-
/** 全局默认配置 */
|
|
373
|
-
default?: LLMDefaultConfig;
|
|
374
|
-
/** 默认模型 */
|
|
375
|
-
defaultModel?: string;
|
|
376
|
-
/** Provider 配置映射 */
|
|
377
|
-
providers: Record<string, ProviderConfig>;
|
|
378
|
-
/** 默认 Provider */
|
|
379
|
-
defaultProvider: string;
|
|
380
|
-
/** 温度参数(全局覆盖) */
|
|
381
|
-
temperature?: number;
|
|
382
|
-
/** 最大 Token 数(全局覆盖) */
|
|
383
|
-
maxTokens?: number;
|
|
384
|
-
/** Top P(全局覆盖) */
|
|
385
|
-
topP?: number;
|
|
386
|
-
/** 是否流式输出 */
|
|
387
|
-
stream?: boolean;
|
|
388
|
-
/** 其他配置 */
|
|
389
|
-
options?: Record<string, unknown>;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* ProviderCapabilities Zod Schema
|
|
393
|
-
*/
|
|
394
|
-
declare const ProviderCapabilitiesSchema: unknown;
|
|
395
|
-
/**
|
|
396
|
-
* ModelLimits Zod Schema
|
|
397
|
-
*/
|
|
398
|
-
declare const ModelLimitsSchema: unknown;
|
|
399
|
-
/**
|
|
400
|
-
* ProviderConfig Zod Schema
|
|
401
|
-
*/
|
|
402
|
-
declare const ProviderConfigSchema: unknown;
|
|
403
|
-
/**
|
|
404
|
-
* LLMDefaultConfig Zod Schema
|
|
405
|
-
*/
|
|
406
|
-
declare const LLMDefaultConfigSchema: unknown;
|
|
407
|
-
/**
|
|
408
|
-
* LLMConfig Zod Schema
|
|
409
|
-
*/
|
|
410
|
-
declare const LLMConfigSchema: unknown;
|
|
411
|
-
/**
|
|
412
|
-
* LLM Invoke 请求
|
|
413
|
-
*/
|
|
414
|
-
interface LLMInvokeRequest {
|
|
415
|
-
/** 消息列表 */
|
|
416
|
-
messages: LLMMessage[];
|
|
417
|
-
/** Provider ID(可选,默认使用配置的默认 Provider) */
|
|
418
|
-
providerId?: string;
|
|
419
|
-
/** 模型(可选,默认使用配置的默认模型) */
|
|
420
|
-
model?: string;
|
|
421
|
-
/** 工具列表 */
|
|
422
|
-
tools?: ToolInfo[];
|
|
423
|
-
/** 温度参数 */
|
|
424
|
-
temperature?: number;
|
|
425
|
-
/** 最大 Token 数 */
|
|
426
|
-
maxTokens?: number;
|
|
427
|
-
/** Top P */
|
|
428
|
-
topP?: number;
|
|
429
|
-
/** 工具选择策略 */
|
|
430
|
-
toolChoice?: "auto" | "none" | {
|
|
431
|
-
type: "function";
|
|
432
|
-
function: {
|
|
433
|
-
name: string;
|
|
434
|
-
};
|
|
435
|
-
};
|
|
436
|
-
/** 停止序列 */
|
|
437
|
-
stopSequences?: string[];
|
|
438
|
-
/** Abort Signal */
|
|
439
|
-
abortSignal?: AbortSignal;
|
|
440
|
-
/** 调用上下文(用于事件元数据) */
|
|
441
|
-
context?: LLMInvokeContext;
|
|
442
|
-
/** 跳过上下文阈值检查(用于 SummaryAgent 等内部调用,避免循环触发压缩) */
|
|
443
|
-
skipThresholdCheck?: boolean;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* LLM Invoke 结果
|
|
447
|
-
*/
|
|
448
|
-
interface LLMInvokeResult {
|
|
449
|
-
/** LLM 输出 */
|
|
450
|
-
output: LLMOutput;
|
|
451
|
-
/** 使用的 Provider ID */
|
|
452
|
-
providerId: string;
|
|
453
|
-
/** 使用的模型 */
|
|
454
|
-
model: string;
|
|
455
|
-
/** 调用延迟(毫秒) */
|
|
456
|
-
latencyMs: number;
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Stream 事件类型
|
|
460
|
-
*/
|
|
461
|
-
type StreamEventType = "start" | "text" | "reasoning" | "tool-call" | "tool-result" | "finish" | "error";
|
|
462
|
-
/**
|
|
463
|
-
* Stream 事件
|
|
464
|
-
*/
|
|
465
|
-
interface StreamEvent {
|
|
466
|
-
/** 事件类型 */
|
|
467
|
-
type: StreamEventType;
|
|
468
|
-
/** 文本内容(type=text 时) */
|
|
469
|
-
content?: string;
|
|
470
|
-
/** Delta 内容(type=text 时) */
|
|
471
|
-
delta?: string;
|
|
472
|
-
/** 推理内容(type=reasoning 时) */
|
|
473
|
-
reasoning?: string;
|
|
474
|
-
/** 工具调用(type=tool-call 时) */
|
|
475
|
-
toolCall?: {
|
|
476
|
-
id: string;
|
|
477
|
-
name: string;
|
|
478
|
-
arguments: string;
|
|
479
|
-
};
|
|
480
|
-
/** 工具结果(type=tool-result 时) */
|
|
481
|
-
toolResult?: {
|
|
482
|
-
id: string;
|
|
483
|
-
result: string;
|
|
484
|
-
};
|
|
485
|
-
/** 完成原因(type=finish 时) */
|
|
486
|
-
finishReason?: "stop" | "length" | "content-filter" | "tool-calls";
|
|
487
|
-
/** Usage 信息(type=finish 时) */
|
|
488
|
-
usage?: UsageInfo;
|
|
489
|
-
/** 错误信息(type=error 时) */
|
|
490
|
-
error?: string;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Tool Info(用于 LLM 工具调用)
|
|
494
|
-
*/
|
|
495
|
-
interface ToolInfo {
|
|
496
|
-
/** 工具名称 */
|
|
497
|
-
name: string;
|
|
498
|
-
/** 工具描述 */
|
|
499
|
-
description?: string;
|
|
500
|
-
/** 工具参数 Schema */
|
|
501
|
-
parameters: Record<string, unknown>;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* LLM 调用上下文(用于事件元数据)
|
|
505
|
-
*/
|
|
506
|
-
interface LLMInvokeContext {
|
|
507
|
-
/** Session ID */
|
|
508
|
-
sessionId?: string;
|
|
509
|
-
/** Message ID */
|
|
510
|
-
messageId?: string;
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Provider 管理器
|
|
514
|
-
* 负责创建和管理 LLM Provider 实例
|
|
515
|
-
*/
|
|
516
|
-
declare class ProviderManager {
|
|
517
|
-
private providers;
|
|
518
|
-
/**
|
|
519
|
-
* 从配置初始化所有 Provider
|
|
520
|
-
*/
|
|
521
|
-
initialize(config: LLMConfig): Promise<void>;
|
|
522
|
-
/**
|
|
523
|
-
* 获取 Provider
|
|
524
|
-
*/
|
|
525
|
-
getProvider(id: string): LLMProvider | undefined;
|
|
526
|
-
/**
|
|
527
|
-
* 列出所有 Provider
|
|
528
|
-
*/
|
|
529
|
-
listProviders(): LLMProvider[];
|
|
530
|
-
/**
|
|
531
|
-
* 解析 Provider 配置中的环境变量
|
|
532
|
-
*/
|
|
533
|
-
resolveProviderConfig(config: ProviderConfig): Promise<ProviderConfig>;
|
|
534
|
-
/**
|
|
535
|
-
* 解析环境变量
|
|
536
|
-
* 支持 ${VAR} 格式
|
|
537
|
-
*/
|
|
538
|
-
resolveEnvVar(value: string): Promise<string>;
|
|
539
|
-
/**
|
|
540
|
-
* 创建 Provider 实例
|
|
541
|
-
* 注意:实际创建需要根据 Provider 类型调用对应的 AI SDK
|
|
542
|
-
* 这里返回占位实现,真正的 Provider 创建需要 AI SDK 依赖
|
|
543
|
-
*/
|
|
544
|
-
private createProvider;
|
|
545
|
-
/**
|
|
546
|
-
* 根据类型创建实际的 Provider 实例
|
|
547
|
-
* 需要外部传入 AI SDK 的 createProvider
|
|
548
|
-
*/
|
|
549
|
-
createAIProvider(id: string, config: ProviderConfig, createFn: (apiKey: string, baseURL?: string) => unknown): LLMProvider;
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* LLM 消息转换工具
|
|
553
|
-
*/
|
|
554
|
-
declare class LLMTransform {
|
|
555
|
-
/**
|
|
556
|
-
* 标准化消息格式
|
|
557
|
-
* 根据不同 Provider 调整消息格式
|
|
558
|
-
*/
|
|
559
|
-
normalizeMessages(messages: LLMMessage[], providerType: string): LLMMessage[];
|
|
560
|
-
/**
|
|
561
|
-
* 标准化为 OpenAI 格式
|
|
562
|
-
*/
|
|
563
|
-
private normalizeForOpenAI;
|
|
564
|
-
/**
|
|
565
|
-
* 标准化为 Anthropic 格式
|
|
566
|
-
*/
|
|
567
|
-
private normalizeForAnthropic;
|
|
568
|
-
/**
|
|
569
|
-
* 从 ToolInfo 提取 JSON Schema
|
|
570
|
-
*/
|
|
571
|
-
extractToolSchema(tool: ToolInfo): {
|
|
572
|
-
name: string;
|
|
573
|
-
description?: string;
|
|
574
|
-
parameters: Record<string, unknown>;
|
|
575
|
-
};
|
|
576
|
-
/**
|
|
577
|
-
* 将 Zod Schema 转换为 JSON Schema
|
|
578
|
-
* 兼容 Zod v3 和 v4
|
|
579
|
-
*/
|
|
580
|
-
zodToJsonSchema(schema: any): Record<string, unknown>;
|
|
581
|
-
/**
|
|
582
|
-
* 提取 Zod Schema 的结构
|
|
583
|
-
* 兼容 Zod v3 和 v4
|
|
584
|
-
*
|
|
585
|
-
* Zod v3: schema._def.typeName === "ZodObject"
|
|
586
|
-
* Zod v4: schema._def.type === "object"
|
|
587
|
-
*/
|
|
588
|
-
private extractZodSchema;
|
|
589
|
-
/**
|
|
590
|
-
* 格式化工具结果
|
|
591
|
-
*/
|
|
592
|
-
formatToolResult(result: ToolResult): {
|
|
593
|
-
role: "tool";
|
|
594
|
-
tool_call_id: string;
|
|
595
|
-
content: string;
|
|
596
|
-
isError?: boolean;
|
|
597
|
-
};
|
|
598
|
-
/**
|
|
599
|
-
* 解析工具参数
|
|
600
|
-
*/
|
|
601
|
-
parseToolArguments(args: string): Record<string, unknown>;
|
|
602
|
-
/**
|
|
603
|
-
* 序列化工具参数为 JSON 字符串
|
|
604
|
-
*/
|
|
605
|
-
serializeToolArguments(args: Record<string, unknown>): string;
|
|
606
|
-
}
|
|
607
|
-
import { ZodType, ZodTypeDef } from "zod";
|
|
608
|
-
/**
|
|
609
|
-
* Component 状态
|
|
610
|
-
*/
|
|
611
|
-
type ComponentStatus = "created" | "initializing" | "running" | "stopping" | "stopped" | "error";
|
|
612
|
-
/**
|
|
613
|
-
* Component 配置
|
|
614
|
-
*/
|
|
615
|
-
interface ComponentConfig {
|
|
616
|
-
name: string;
|
|
617
|
-
version: string;
|
|
618
|
-
enabled: boolean;
|
|
619
|
-
options?: Record<string, unknown>;
|
|
620
|
-
/**
|
|
621
|
-
* Environment 实例(可选)
|
|
622
|
-
*
|
|
623
|
-
* 推荐在 init 时接收 env 实例,以便:
|
|
624
|
-
* - 通过 env.getComponent() 获取其他组件
|
|
625
|
-
* - 通过 env.pushEnvEvent() 发布事件
|
|
626
|
-
* - 通过 env.handle_query() 处理查询
|
|
627
|
-
*
|
|
628
|
-
* 如果未提供,部分 Component 仍可正常工作(如测试场景)
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* ```typescript
|
|
632
|
-
* async onInit(): Promise<void> {
|
|
633
|
-
* if (this.env) {
|
|
634
|
-
* const configComp = this.env.getComponent("config");
|
|
635
|
-
* }
|
|
636
|
-
* }
|
|
637
|
-
* ```
|
|
638
|
-
*/
|
|
639
|
-
env?: Environment;
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* Component 路径声明
|
|
643
|
-
*/
|
|
644
|
-
interface ComponentPaths {
|
|
645
|
-
base: "config" | "state" | "data" | "cache";
|
|
646
|
-
subPath: string;
|
|
647
|
-
isDirectory: boolean;
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Component Schema(注册配置)
|
|
651
|
-
*/
|
|
652
|
-
interface ComponentSchema {
|
|
653
|
-
/** Component 名称 */
|
|
654
|
-
name: string;
|
|
655
|
-
/** 配置 Schema(Zod) */
|
|
656
|
-
schema: ZodType<unknown, ZodTypeDef, unknown>;
|
|
657
|
-
/** 默认值(从 Schema 提取) */
|
|
658
|
-
defaults: Record<string, unknown>;
|
|
659
|
-
/** 路径声明 */
|
|
660
|
-
paths?: Record<string, ComponentPaths>;
|
|
661
|
-
/** 元信息 */
|
|
662
|
-
metadata?: {
|
|
663
|
-
description?: string;
|
|
664
|
-
version?: string;
|
|
665
|
-
author?: string;
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Component 配置变更事件
|
|
670
|
-
*/
|
|
671
|
-
interface ComponentConfigChangeEvent {
|
|
672
|
-
/** Component 名称 */
|
|
673
|
-
component: string;
|
|
674
|
-
/** 变更的配置键 */
|
|
675
|
-
key: string;
|
|
676
|
-
/** 旧值 */
|
|
677
|
-
oldValue: unknown;
|
|
678
|
-
/** 新值 */
|
|
679
|
-
newValue: unknown;
|
|
680
|
-
/** 是否持久化 */
|
|
681
|
-
persisted: boolean;
|
|
682
|
-
/** 时间戳 */
|
|
683
|
-
timestamp: number;
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Component 配置监听回调
|
|
687
|
-
*/
|
|
688
|
-
type ComponentWatchCallback = (event: ComponentConfigChangeEvent) => void | Promise<void>;
|
|
689
|
-
/**
|
|
690
|
-
* Component 基类接口
|
|
691
|
-
*/
|
|
692
|
-
interface Component {
|
|
693
|
-
/** Component 名称 */
|
|
694
|
-
readonly name: string;
|
|
695
|
-
/** Component 版本 */
|
|
696
|
-
readonly version: string;
|
|
697
|
-
/** 获取状态 */
|
|
698
|
-
getStatus(): ComponentStatus;
|
|
699
|
-
/** 获取配置 */
|
|
700
|
-
getConfig(): ComponentConfig;
|
|
701
|
-
/** 初始化 */
|
|
702
|
-
init(config: ComponentConfig): Promise<void>;
|
|
703
|
-
/** 启动 */
|
|
704
|
-
start(): Promise<void>;
|
|
705
|
-
/** 停止 */
|
|
706
|
-
stop(): Promise<void>;
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Component 基类实现
|
|
710
|
-
*/
|
|
711
|
-
declare abstract class BaseComponent implements Component {
|
|
712
|
-
abstract readonly name: string;
|
|
713
|
-
abstract readonly version: string;
|
|
714
|
-
protected _status: ComponentStatus;
|
|
715
|
-
protected _enabled: boolean;
|
|
716
|
-
protected env: Environment;
|
|
717
|
-
/** Hook 管理器 - 子类初始化时由构造函数设置 */
|
|
718
|
-
readonly hookManager: HookManager;
|
|
719
|
-
constructor();
|
|
720
|
-
getStatus(): ComponentStatus;
|
|
721
|
-
getConfig(): ComponentConfig;
|
|
722
|
-
/**
|
|
723
|
-
* 检查 Environment 是否已初始化
|
|
724
|
-
*/
|
|
725
|
-
protected isEnvInitialized(): boolean;
|
|
726
|
-
protected setStatus(status: ComponentStatus): void;
|
|
727
|
-
/**
|
|
728
|
-
* 获取 Environment 实例
|
|
729
|
-
*/
|
|
730
|
-
protected getEnv(): Environment;
|
|
731
|
-
init(config?: ComponentConfig): Promise<void>;
|
|
732
|
-
start(): Promise<void>;
|
|
733
|
-
stop(): Promise<void>;
|
|
734
|
-
/**
|
|
735
|
-
* 子类可覆盖的钩子方法
|
|
736
|
-
*/
|
|
737
|
-
protected onInit(): Promise<void>;
|
|
738
|
-
protected onStart(): Promise<void>;
|
|
739
|
-
protected onStop(): Promise<void>;
|
|
740
|
-
/**
|
|
741
|
-
* 注册 Hook
|
|
742
|
-
*
|
|
743
|
-
* @param hookPoint Hook 点名称
|
|
744
|
-
* @param hook Hook 实例
|
|
745
|
-
*/
|
|
746
|
-
protected registerHook<T = unknown>(hookPoint: string, hook: Hook<T>): void;
|
|
747
|
-
/**
|
|
748
|
-
* 便捷方法:快速注册 Hook
|
|
749
|
-
*/
|
|
750
|
-
protected addHook<T = unknown>(hookPoint: string, name: string, fn: HookFn<T>, priority?: number): void;
|
|
751
|
-
/**
|
|
752
|
-
* 便捷方法:按名称取消注册 Hook
|
|
753
|
-
*/
|
|
754
|
-
protected removeHook(hookPoint: string, name: string): boolean;
|
|
755
|
-
/**
|
|
756
|
-
* 执行 Hook
|
|
757
|
-
*/
|
|
758
|
-
protected executeHooks<T = unknown>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
|
|
759
|
-
/**
|
|
760
|
-
* 获取 ConfigComponent 实例
|
|
761
|
-
*
|
|
762
|
-
* 子类可使用此方法获取配置组件,支持热更新
|
|
763
|
-
*/
|
|
764
|
-
protected getConfigComponent(): {
|
|
765
|
-
get(key: string): unknown;
|
|
766
|
-
} | undefined;
|
|
767
|
-
/**
|
|
768
|
-
* 动态获取运行时配置值
|
|
769
|
-
*
|
|
770
|
-
* 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
|
|
771
|
-
* 适用于运行时可能变化的配置(如 API Keys、模型参数)
|
|
772
|
-
*
|
|
773
|
-
* @param key 配置键(支持点号分隔的路径,如 "llm.temperature")
|
|
774
|
-
* @param defaultValue 默认值
|
|
775
|
-
* @returns 配置值或默认值
|
|
776
|
-
*
|
|
777
|
-
* @example
|
|
778
|
-
* ```typescript
|
|
779
|
-
* // 获取 LLM 温度配置(可能支持热更新)
|
|
780
|
-
* const temperature = this.getRuntimeConfig("llm.temperature", 0.7);
|
|
781
|
-
*
|
|
782
|
-
* // 获取 API Key
|
|
783
|
-
* const apiKey = this.getRuntimeConfig<string>("llm.providers.openai.apiKey");
|
|
784
|
-
* ```
|
|
785
|
-
*/
|
|
786
|
-
protected getRuntimeConfig<T>(key: string, defaultValue: T): T;
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* @fileoverview Environment types and interfaces
|
|
790
|
-
*
|
|
791
|
-
* 定义 Environment 的核心类型,包括:
|
|
792
|
-
* - Environment 配置
|
|
793
|
-
* - EnvEvent 事件类型
|
|
794
|
-
*/
|
|
795
|
-
/**
|
|
796
|
-
* Environment Config
|
|
797
|
-
*/
|
|
798
|
-
interface EnvironmentConfig {
|
|
799
|
-
/** 环境名称 */
|
|
800
|
-
name: string;
|
|
801
|
-
/** 环境版本 */
|
|
802
|
-
version: string;
|
|
803
|
-
/** 是否启用 */
|
|
804
|
-
enabled: boolean;
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* EnvEvent 元信息
|
|
808
|
-
*/
|
|
809
|
-
interface EnvEventMetadata {
|
|
810
|
-
/** 触发事件的 session ID */
|
|
811
|
-
trigger_session_id?: string;
|
|
812
|
-
/** 触发事件的 agent ID */
|
|
813
|
-
trigger_agent_id?: string;
|
|
814
|
-
/** Agent 名称 */
|
|
815
|
-
trigger_agent_name?: string;
|
|
816
|
-
/** 环境名称 */
|
|
817
|
-
env_name?: string;
|
|
818
|
-
/** 事件来源 */
|
|
819
|
-
source?: string;
|
|
820
|
-
/** 其他元数据 */
|
|
821
|
-
[key: string]: unknown;
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* EnvEvent
|
|
825
|
-
*
|
|
826
|
-
* 统一的事件机制,用于:
|
|
827
|
-
* - Stream 事件(stream.start, stream.text, stream.completed 等)
|
|
828
|
-
* - 工具调用事件(tool.call, tool.result 等)
|
|
829
|
-
* - 会话事件(session.created, session.updated 等)
|
|
830
|
-
* - Agent 事件(agent.thinking, agent.acting 等)
|
|
831
|
-
*/
|
|
832
|
-
interface EnvEvent<T = unknown> {
|
|
833
|
-
/** 事件 ID */
|
|
834
|
-
id: string;
|
|
835
|
-
/** 事件类型 */
|
|
836
|
-
type: string;
|
|
837
|
-
/** 时间戳 */
|
|
838
|
-
timestamp: number;
|
|
839
|
-
/** 元信息 */
|
|
840
|
-
metadata: EnvEventMetadata;
|
|
841
|
-
/** 事件负载 */
|
|
842
|
-
payload: T;
|
|
843
|
-
}
|
|
844
|
-
/**
|
|
845
|
-
* EnvEvent Handler
|
|
846
|
-
*/
|
|
847
|
-
type EnvEventHandler = (event: EnvEvent) => void | Promise<void>;
|
|
848
|
-
/**
|
|
849
|
-
* EnvEvent 创建参数(部分属性,可选)
|
|
850
|
-
*
|
|
851
|
-
* 用于 pushEnvEvent 方法,允许传入部分属性,自动补全必填字段
|
|
852
|
-
*/
|
|
853
|
-
interface EnvEventInput {
|
|
854
|
-
/** 事件类型(必填) */
|
|
855
|
-
type: string;
|
|
856
|
-
/** 事件 ID(可选,自动生成) */
|
|
857
|
-
id?: string;
|
|
858
|
-
/** 时间戳(可选,自动生成) */
|
|
859
|
-
timestamp?: number;
|
|
860
|
-
/** 元信息(可选,自动创建) */
|
|
861
|
-
metadata?: EnvEventMetadata;
|
|
862
|
-
/** 事件负载(可选) */
|
|
863
|
-
payload?: unknown;
|
|
864
|
-
}
|
|
865
|
-
/**
|
|
866
|
-
* Action 类型
|
|
867
|
-
*/
|
|
868
|
-
interface Action {
|
|
869
|
-
/** Action 类型 */
|
|
870
|
-
type: string;
|
|
871
|
-
/** Action 参数 */
|
|
872
|
-
params?: Record<string, unknown>;
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Tool Result
|
|
876
|
-
*/
|
|
877
|
-
interface ToolResult2 {
|
|
878
|
-
/** 是否成功 */
|
|
879
|
-
success: boolean;
|
|
880
|
-
/** 输出内容 */
|
|
881
|
-
output: string | Record<string, unknown>;
|
|
882
|
-
/** 错误信息 */
|
|
883
|
-
error?: string;
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* Context
|
|
887
|
-
*/
|
|
888
|
-
interface Context {
|
|
889
|
-
/** 会话 ID */
|
|
890
|
-
sessionId?: string;
|
|
891
|
-
/** 用户 ID */
|
|
892
|
-
userId?: string;
|
|
893
|
-
/** 工作目录 */
|
|
894
|
-
workdir?: string;
|
|
895
|
-
/** 中断信号 */
|
|
896
|
-
abort?: AbortSignal;
|
|
897
|
-
/** 元数据 */
|
|
898
|
-
metadata?: Record<string, unknown>;
|
|
899
|
-
}
|
|
900
|
-
type AbortSignalType = AbortSignal;
|
|
901
|
-
/**
|
|
902
|
-
* Agent 执行上下文
|
|
903
|
-
*/
|
|
904
|
-
interface AgentContext {
|
|
905
|
-
/** 会话 ID */
|
|
906
|
-
sessionId?: string;
|
|
907
|
-
/** 消息 ID */
|
|
908
|
-
messageId?: string;
|
|
909
|
-
/** 中断信号 */
|
|
910
|
-
abort?: AbortSignalType;
|
|
911
|
-
/** 额外的上下文信息(会添加到 system prompt) */
|
|
912
|
-
additionInfo?: string;
|
|
913
|
-
/** 元数据 */
|
|
914
|
-
metadata?: Record<string, unknown>;
|
|
915
|
-
/** Agent 类型(用于选择 Behavior Spec) */
|
|
916
|
-
agentType?: string;
|
|
917
|
-
/** 使用的模型 */
|
|
918
|
-
model?: string;
|
|
919
|
-
/** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
920
|
-
allowedTools?: string[];
|
|
921
|
-
/** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
922
|
-
deniedTools?: string[];
|
|
923
|
-
/** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
|
|
924
|
-
filterHistory?: boolean;
|
|
925
|
-
}
|
|
926
|
-
import { ZodType as ZodType3, ZodTypeDef as ZodTypeDef2 } from "zod";
|
|
927
|
-
/**
|
|
928
|
-
* ConfigSource 类型
|
|
929
|
-
*/
|
|
930
|
-
type ConfigSourceType = "memory" | "file" | "env" | "remote";
|
|
931
|
-
/**
|
|
932
|
-
* SourceRegistration - Source 注册配置
|
|
933
|
-
*/
|
|
934
|
-
interface SourceRegistration {
|
|
935
|
-
/** Source 类型 */
|
|
936
|
-
type: ConfigSourceType;
|
|
937
|
-
/** 相对路径(file 类型使用,基于 XDG_DATA_HOME) */
|
|
938
|
-
relativePath?: string;
|
|
939
|
-
/** 环境变量前缀(env 类型使用) */
|
|
940
|
-
envPrefix?: string;
|
|
941
|
-
/** 优先级,默认值:memory=0, file=10, env=20 */
|
|
942
|
-
priority?: number;
|
|
943
|
-
/** 是否可选(file 类型使用,文件不存在时不报错) */
|
|
944
|
-
optional?: boolean;
|
|
945
|
-
/** 是否启用文件监听(file 类型使用,默认 true) */
|
|
946
|
-
watch?: boolean;
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* KeyRegistration - 配置 Key 注册
|
|
950
|
-
*/
|
|
951
|
-
interface KeyRegistration {
|
|
952
|
-
/** 配置 Key(支持点号嵌套,如 "llm.provider") */
|
|
953
|
-
key: string;
|
|
954
|
-
/** 优先使用的 Source 列表(按优先级从低到高) */
|
|
955
|
-
sources: ConfigSourceType[];
|
|
956
|
-
/** 自定义优先级(覆盖默认优先级) */
|
|
957
|
-
priority?: number;
|
|
958
|
-
/** 默认值 */
|
|
959
|
-
default?: unknown;
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* ComponentRegistration - Component 注册配置
|
|
963
|
-
*/
|
|
964
|
-
interface ComponentRegistration {
|
|
965
|
-
/** Component 名称 */
|
|
966
|
-
name: string;
|
|
967
|
-
/** 声明需要的 Source */
|
|
968
|
-
sources: SourceRegistration[];
|
|
969
|
-
/** 声明需要的配置 Key */
|
|
970
|
-
keys: KeyRegistration[];
|
|
971
|
-
/** 配置 Schema(用于验证,可选) */
|
|
972
|
-
schema?: ZodType3<unknown, ZodTypeDef2, unknown>;
|
|
973
|
-
/** 默认值 */
|
|
974
|
-
defaults?: Record<string, unknown>;
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* ConfigSource 接口
|
|
978
|
-
*/
|
|
979
|
-
interface ConfigSource {
|
|
980
|
-
readonly name: ConfigSourceType;
|
|
981
|
-
readonly priority: number;
|
|
982
|
-
read(key: string): unknown | undefined;
|
|
983
|
-
write?(key: string, value: unknown): boolean;
|
|
984
|
-
delete?(key: string): boolean;
|
|
985
|
-
list(): Array<{
|
|
986
|
-
key: string;
|
|
987
|
-
value: unknown;
|
|
988
|
-
}>;
|
|
989
|
-
watch?(callback: (event: ConfigChangeEvent) => void): () => void;
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Config 变更事件
|
|
993
|
-
*/
|
|
994
|
-
interface ConfigChangeEvent {
|
|
995
|
-
type: "change" | "add" | "delete";
|
|
996
|
-
key: string;
|
|
997
|
-
oldValue: unknown;
|
|
998
|
-
newValue: unknown;
|
|
999
|
-
source: ConfigSourceType;
|
|
1000
|
-
timestamp: number;
|
|
1001
|
-
}
|
|
1002
|
-
/**
|
|
1003
|
-
* ConfigComponent 配置
|
|
1004
|
-
*/
|
|
1005
|
-
interface ConfigComponentOptions {
|
|
1006
|
-
/** 持久化文件路径 */
|
|
1007
|
-
persistFile?: string;
|
|
1008
|
-
/** 防抖延迟(ms) */
|
|
1009
|
-
debounceMs?: number;
|
|
1010
|
-
/** 最大批量大小 */
|
|
1011
|
-
maxBatchSize?: number;
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* ConfigComponent
|
|
1015
|
-
*/
|
|
1016
|
-
declare class ConfigComponent extends BaseComponent {
|
|
1017
|
-
readonly name = "config";
|
|
1018
|
-
readonly version = "1.0.0";
|
|
1019
|
-
private memorySource;
|
|
1020
|
-
private sources;
|
|
1021
|
-
private componentSchemas;
|
|
1022
|
-
private componentPaths;
|
|
1023
|
-
private watchers;
|
|
1024
|
-
/** Source watch unsubscribe 函数 */
|
|
1025
|
-
private sourceUnwatchFns;
|
|
1026
|
-
private persistQueue;
|
|
1027
|
-
private persistFile?;
|
|
1028
|
-
/** Key 注册表:key -> KeyRegistration */
|
|
1029
|
-
private keyRegistry;
|
|
1030
|
-
/** Component 注册表:name -> ComponentRegistration */
|
|
1031
|
-
private componentRegistrations;
|
|
1032
|
-
/** 协议解析器 */
|
|
1033
|
-
private protocolResolver?;
|
|
1034
|
-
/** XDG_DATA_HOME 缓存(用于测试注入) */
|
|
1035
|
-
private __xdgDataHome?;
|
|
1036
|
-
/** Source 注册配置(延迟创建) */
|
|
1037
|
-
private pendingSources;
|
|
1038
|
-
/** Source 唯一标识缓存:type:relativePath -> true */
|
|
1039
|
-
private sourceKeys;
|
|
1040
|
-
/**
|
|
1041
|
-
* 获取 XDG_DATA_HOME(动态获取,支持运行时覆盖)
|
|
1042
|
-
*/
|
|
1043
|
-
getXdgDataHome(): string;
|
|
1044
|
-
/**
|
|
1045
|
-
* 设置 XDG_DATA_HOME(用于测试)
|
|
1046
|
-
*/
|
|
1047
|
-
setXdgDataHome(path: string): void;
|
|
1048
|
-
constructor(options?: ConfigComponentOptions);
|
|
1049
|
-
/**
|
|
1050
|
-
* 注册 Component Schema
|
|
1051
|
-
*/
|
|
1052
|
-
register(schema: ComponentSchema): void;
|
|
1053
|
-
/**
|
|
1054
|
-
* 注销 Component
|
|
1055
|
-
*/
|
|
1056
|
-
unregister(name: string): boolean;
|
|
1057
|
-
/**
|
|
1058
|
-
* 检查是否已注册
|
|
1059
|
-
*/
|
|
1060
|
-
isRegistered(name: string): boolean;
|
|
1061
|
-
/**
|
|
1062
|
-
* 列出所有注册的 Component
|
|
1063
|
-
*/
|
|
1064
|
-
listComponents(): string[];
|
|
1065
|
-
/**
|
|
1066
|
-
* 获取配置值(支持 xxx.yyy.zzz 嵌套访问)
|
|
1067
|
-
* 支持两种模式:
|
|
1068
|
-
* 1. 完整 key:直接查找,如 "component.key" -> 读取 "component.key"
|
|
1069
|
-
* 2. 嵌套对象:查找 component 对象后从中获取属性,如 "component.nested.deep"
|
|
1070
|
-
* -> 先找 "component.nested",再获取其 "deep" 属性
|
|
1071
|
-
*/
|
|
1072
|
-
get(key: string): unknown;
|
|
1073
|
-
/**
|
|
1074
|
-
* 批量获取
|
|
1075
|
-
*/
|
|
1076
|
-
getMany(keys: string[]): Record<string, unknown>;
|
|
1077
|
-
/**
|
|
1078
|
-
* 设置配置值(内存级别 + 异步持久化)
|
|
1079
|
-
*/
|
|
1080
|
-
set(key: string, value: unknown): Promise<void>;
|
|
1081
|
-
/**
|
|
1082
|
-
* 批量设置
|
|
1083
|
-
*/
|
|
1084
|
-
setMany(config: Record<string, unknown>): Promise<void>;
|
|
1085
|
-
/**
|
|
1086
|
-
* 获取 Component 的路径
|
|
1087
|
-
*/
|
|
1088
|
-
getPath(component: string, subPath?: string): string;
|
|
1089
|
-
/**
|
|
1090
|
-
* 手动持久化
|
|
1091
|
-
*/
|
|
1092
|
-
save(key?: string): Promise<void>;
|
|
1093
|
-
/**
|
|
1094
|
-
* 重置到默认值
|
|
1095
|
-
*/
|
|
1096
|
-
reset(key: string): Promise<void>;
|
|
1097
|
-
/**
|
|
1098
|
-
* 监听配置变更
|
|
1099
|
-
*/
|
|
1100
|
-
watch(pattern: string, callback: ComponentWatchCallback): () => void;
|
|
1101
|
-
/**
|
|
1102
|
-
* 添加配置源
|
|
1103
|
-
*/
|
|
1104
|
-
addSource(source: ConfigSource): void;
|
|
1105
|
-
/**
|
|
1106
|
-
* 获取 Source 唯一标识
|
|
1107
|
-
*/
|
|
1108
|
-
private getSourceKey;
|
|
1109
|
-
/**
|
|
1110
|
-
* 移除配置源
|
|
1111
|
-
*/
|
|
1112
|
-
removeSource(name: ConfigSourceType): boolean;
|
|
1113
|
-
/**
|
|
1114
|
-
* 关闭所有配置源的 watcher(用于优雅退出)
|
|
1115
|
-
*/
|
|
1116
|
-
unwatchAll(): void;
|
|
1117
|
-
/**
|
|
1118
|
-
* 获取配置源列表
|
|
1119
|
-
*/
|
|
1120
|
-
getSources(): ConfigSource[];
|
|
1121
|
-
private getNestedValue;
|
|
1122
|
-
private notifyWatchers;
|
|
1123
|
-
private persistToFile;
|
|
1124
|
-
/**
|
|
1125
|
-
* 注册配置 Source
|
|
1126
|
-
*
|
|
1127
|
-
* Source 会在首次 load() 时被创建
|
|
1128
|
-
*
|
|
1129
|
-
* @example
|
|
1130
|
-
* config.registerSource({ type: "file", relativePath: "llm-config.jsonc" });
|
|
1131
|
-
* config.registerSource({ type: "env", envPrefix: "LLM" });
|
|
1132
|
-
*/
|
|
1133
|
-
registerSource(registration: SourceRegistration): void;
|
|
1134
|
-
/**
|
|
1135
|
-
* 创建 Source 实例
|
|
1136
|
-
*/
|
|
1137
|
-
private createSource;
|
|
1138
|
-
/**
|
|
1139
|
-
* 确保所有待创建的 Source 已被创建
|
|
1140
|
-
*/
|
|
1141
|
-
private ensureSourcesCreated;
|
|
1142
|
-
/**
|
|
1143
|
-
* 注册配置 Key
|
|
1144
|
-
*
|
|
1145
|
-
* @example
|
|
1146
|
-
* config.registerKeys([
|
|
1147
|
-
* { key: "llm.provider", sources: ["file", "memory"], default: "openai" },
|
|
1148
|
-
* { key: "llm.model", sources: ["file"] },
|
|
1149
|
-
* ]);
|
|
1150
|
-
*/
|
|
1151
|
-
registerKeys(keys: KeyRegistration[]): void;
|
|
1152
|
-
/**
|
|
1153
|
-
* 注册 Component(一次性注册 Source 和 Keys)
|
|
1154
|
-
*
|
|
1155
|
-
* @example
|
|
1156
|
-
* config.registerComponent({
|
|
1157
|
-
* name: "llm",
|
|
1158
|
-
* sources: [
|
|
1159
|
-
* { type: "file", relativePath: "llm-config.jsonc" },
|
|
1160
|
-
* { type: "env", envPrefix: "LLM" },
|
|
1161
|
-
* ],
|
|
1162
|
-
* keys: [
|
|
1163
|
-
* { key: "llm.provider", sources: ["file", "env", "memory"] },
|
|
1164
|
-
* ],
|
|
1165
|
-
* });
|
|
1166
|
-
*/
|
|
1167
|
-
registerComponent(registration: ComponentRegistration): void;
|
|
1168
|
-
/**
|
|
1169
|
-
* 按需加载配置
|
|
1170
|
-
*
|
|
1171
|
-
* 从注册的 Source 加载已注册 Keys 的配置值到内存中
|
|
1172
|
-
*
|
|
1173
|
-
* @param componentName - 可选,指定要加载的 Component 名称
|
|
1174
|
-
*
|
|
1175
|
-
* @example
|
|
1176
|
-
* // 加载所有已注册的 Keys
|
|
1177
|
-
* await config.load();
|
|
1178
|
-
*
|
|
1179
|
-
* // 只加载指定 Component 的 Keys
|
|
1180
|
-
* await config.load("llm");
|
|
1181
|
-
*/
|
|
1182
|
-
load(componentName?: string): Promise<void>;
|
|
1183
|
-
/**
|
|
1184
|
-
* 获取已注册的 Source 列表
|
|
1185
|
-
*/
|
|
1186
|
-
getRegisteredSources(): ConfigSource[];
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* 服务配置接口
|
|
1190
|
-
*/
|
|
1191
|
-
interface ServiceConfig {
|
|
1192
|
-
/** 环境配置 */
|
|
1193
|
-
environment?: {
|
|
1194
|
-
name?: string;
|
|
1195
|
-
version?: string;
|
|
1196
|
-
};
|
|
1197
|
-
/** 组件配置映射 */
|
|
1198
|
-
components?: Record<string, ComponentConfigEntry>;
|
|
1199
|
-
}
|
|
1200
|
-
/**
|
|
1201
|
-
* 组件配置项
|
|
1202
|
-
*/
|
|
1203
|
-
interface ComponentConfigEntry {
|
|
1204
|
-
/** 配置文件路径(可选) */
|
|
1205
|
-
configPath?: string;
|
|
1206
|
-
/** 环境变量前缀(可选) */
|
|
1207
|
-
envPrefix?: string;
|
|
1208
|
-
/** 直接配置对象(可选) */
|
|
1209
|
-
config?: Record<string, unknown>;
|
|
1210
|
-
/** 是否启用(可选,默认 true) */
|
|
1211
|
-
enabled?: boolean;
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* 组件初始化选项(由 generateComponentOptions 生成)
|
|
1215
|
-
*/
|
|
1216
|
-
interface GeneratedComponentOptions {
|
|
1217
|
-
/** ConfigComponent 实例 */
|
|
1218
|
-
configComponent: ConfigComponent;
|
|
1219
|
-
/** 配置文件路径 */
|
|
1220
|
-
configPath?: string;
|
|
1221
|
-
/** 环境变量前缀 */
|
|
1222
|
-
envPrefix?: string;
|
|
1223
|
-
/** 直接配置对象 */
|
|
1224
|
-
config?: Record<string, unknown>;
|
|
1225
|
-
/** 允许的其他属性 */
|
|
1226
|
-
[key: string]: unknown;
|
|
1227
|
-
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Environment 接口
|
|
1230
|
-
*
|
|
1231
|
-
* 定义 Agent 运行时的核心能力接口。
|
|
1232
|
-
*/
|
|
1233
|
-
interface Environment {
|
|
1234
|
-
/** 环境名称 */
|
|
1235
|
-
readonly name: string;
|
|
1236
|
-
/** 环境版本 */
|
|
1237
|
-
readonly version: string;
|
|
1238
|
-
/** 获取环境配置 */
|
|
1239
|
-
getConfig(): EnvironmentConfig;
|
|
1240
|
-
/**
|
|
1241
|
-
* 注册组件
|
|
1242
|
-
*/
|
|
1243
|
-
registerComponent(component: Component): void;
|
|
1244
|
-
/**
|
|
1245
|
-
* 注销组件
|
|
1246
|
-
*/
|
|
1247
|
-
unregisterComponent(name: string): void;
|
|
1248
|
-
/**
|
|
1249
|
-
* 获取组件
|
|
1250
|
-
*/
|
|
1251
|
-
getComponent<T extends Component>(name: string): T | undefined;
|
|
1252
|
-
/**
|
|
1253
|
-
* 列出所有组件
|
|
1254
|
-
*/
|
|
1255
|
-
listComponents(): Component[];
|
|
1256
|
-
/**
|
|
1257
|
-
* 处理自然语言查询(核心入口)
|
|
1258
|
-
*
|
|
1259
|
-
* @param query 用户查询文本
|
|
1260
|
-
* @param context 执行上下文(可选)
|
|
1261
|
-
* @returns 完整的文本响应
|
|
1262
|
-
*/
|
|
1263
|
-
handle_query(query: string, context?: AgentContext): Promise<string>;
|
|
1264
|
-
/**
|
|
1265
|
-
* 处理动作
|
|
1266
|
-
*/
|
|
1267
|
-
handle_action(action: Action, context: Context): Promise<ToolResult2>;
|
|
1268
|
-
/**
|
|
1269
|
-
* 订阅 EnvEvent(返回取消订阅函数)
|
|
1270
|
-
*/
|
|
1271
|
-
subscribe(handler: EnvEventHandler): () => void;
|
|
1272
|
-
/**
|
|
1273
|
-
* 订阅指定类型事件
|
|
1274
|
-
*/
|
|
1275
|
-
subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
|
|
1276
|
-
/**
|
|
1277
|
-
* 订阅所有事件(通配符)
|
|
1278
|
-
*/
|
|
1279
|
-
subscribeAll(handler: EnvEventHandler): () => void;
|
|
1280
|
-
/**
|
|
1281
|
-
* 推送事件
|
|
1282
|
-
*
|
|
1283
|
-
* @param event EnvEvent 或 EnvEventInput(部分属性)
|
|
1284
|
-
*/
|
|
1285
|
-
pushEnvEvent(event: EnvEvent | EnvEventInput): void;
|
|
1286
|
-
/**
|
|
1287
|
-
* 从配置文件加载服务配置
|
|
1288
|
-
*
|
|
1289
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
1290
|
-
* @returns 解析后的服务配置对象
|
|
1291
|
-
*/
|
|
1292
|
-
loadServiceConfig(configPath: string): Promise<ServiceConfig>;
|
|
1293
|
-
/**
|
|
1294
|
-
* 生成组件初始化选项
|
|
1295
|
-
*
|
|
1296
|
-
* 根据组件配置项生成可用于初始化的选项对象。
|
|
1297
|
-
*
|
|
1298
|
-
* @param componentName 组件名称
|
|
1299
|
-
* @param configEntry 组件配置项
|
|
1300
|
-
* @returns 生成的组件初始化选项
|
|
1301
|
-
*/
|
|
1302
|
-
generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
|
|
1303
|
-
/**
|
|
1304
|
-
* 注册组件并用配置初始化
|
|
1305
|
-
*
|
|
1306
|
-
* 便捷方法:注册组件并通过 ConfigComponent 初始化。
|
|
1307
|
-
*
|
|
1308
|
-
* @param component 要注册的组件实例
|
|
1309
|
-
* @param configEntry 组件配置项
|
|
1310
|
-
*/
|
|
1311
|
-
registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
|
|
1312
|
-
/**
|
|
1313
|
-
* 从配置文件初始化整个环境
|
|
1314
|
-
*
|
|
1315
|
-
* 加载服务配置,注册并初始化所有配置的组件。
|
|
1316
|
-
*
|
|
1317
|
-
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
1318
|
-
*/
|
|
1319
|
-
initFromConfig(configPath: string): Promise<void>;
|
|
1320
|
-
}
|
|
1321
|
-
/**
|
|
1322
|
-
* Invoke LLM 配置
|
|
1323
|
-
*/
|
|
1324
|
-
interface InvokeConfig {
|
|
1325
|
-
/** 模型标识符(格式: providerId/modelId) */
|
|
1326
|
-
model: string;
|
|
1327
|
-
/** Base URL */
|
|
1328
|
-
baseURL?: string;
|
|
1329
|
-
/** API Key */
|
|
1330
|
-
apiKey: string;
|
|
1331
|
-
/** 额外选项 */
|
|
1332
|
-
options?: {
|
|
1333
|
-
thinkingInText?: {
|
|
1334
|
-
enabled?: boolean;
|
|
1335
|
-
tags?: string[];
|
|
1336
|
-
};
|
|
1337
|
-
};
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* LLM 选项
|
|
1341
|
-
*/
|
|
1342
|
-
interface InvokeOptions {
|
|
1343
|
-
/** 消息列表 */
|
|
1344
|
-
messages: LLMMessage[];
|
|
1345
|
-
/** 工具列表 */
|
|
1346
|
-
tools?: ToolInfo[];
|
|
1347
|
-
/** 模型标识符(可选) */
|
|
1348
|
-
model?: string;
|
|
1349
|
-
/** 温度参数 */
|
|
1350
|
-
temperature?: number;
|
|
1351
|
-
/** 最大 Token 数 */
|
|
1352
|
-
maxTokens?: number;
|
|
1353
|
-
/** Environment 实例(用于发布流式事件,可选) */
|
|
1354
|
-
env?: Environment;
|
|
1355
|
-
/** 上下文信息(用于事件元数据) */
|
|
1356
|
-
context?: {
|
|
1357
|
-
/** Session ID */
|
|
1358
|
-
sessionId?: string;
|
|
1359
|
-
/** Message ID */
|
|
1360
|
-
messageId?: string;
|
|
1361
|
-
};
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* LLM Tool Context - Context for tool calls during LLM invocation
|
|
1365
|
-
*/
|
|
1366
|
-
interface LLMToolContext {
|
|
1367
|
-
/** Abort Signal */
|
|
1368
|
-
abort?: AbortSignal | undefined;
|
|
1369
|
-
/** 额外上下文 */
|
|
1370
|
-
context?: Record<string, unknown>;
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* Usage 信息转换
|
|
1374
|
-
*/
|
|
1375
|
-
interface ConvertedUsageInfo {
|
|
1376
|
-
/** Prompt Token 数 */
|
|
1377
|
-
promptTokens: number;
|
|
1378
|
-
/** Completion Token 数 */
|
|
1379
|
-
completionTokens: number;
|
|
1380
|
-
/** 总 Token 数 */
|
|
1381
|
-
totalTokens: number;
|
|
1382
|
-
}
|
|
1383
|
-
/**
|
|
1384
|
-
* 解析模型字符串
|
|
1385
|
-
* 格式: "providerId/modelId"
|
|
1386
|
-
*/
|
|
1387
|
-
declare function parseModelString(model?: string): {
|
|
1388
|
-
providerId: string;
|
|
1389
|
-
modelId: string;
|
|
1390
|
-
};
|
|
1391
|
-
/**
|
|
1392
|
-
* 核心 LLM 调用函数
|
|
1393
|
-
* 使用 AI SDK 的 streamText
|
|
1394
|
-
*
|
|
1395
|
-
* 流式事件通过 env.pushEnvEvent() 发布
|
|
1396
|
-
*
|
|
1397
|
-
* @param config - Invoke 配置
|
|
1398
|
-
* @param options - LLM 选项
|
|
1399
|
-
* @param ctx - Tool Context
|
|
1400
|
-
* @returns ToolResult
|
|
1401
|
-
*/
|
|
1402
|
-
declare function invoke(config: InvokeConfig, options: InvokeOptions, ctx: LLMToolContext): Promise<ToolResult>;
|
|
1403
|
-
/**
|
|
1404
|
-
* 非流式 LLM 调用
|
|
1405
|
-
*
|
|
1406
|
-
* 使用 AI SDK 的 generateText API,返回完整响应
|
|
1407
|
-
*/
|
|
1408
|
-
declare function invokeNonStream(config: InvokeConfig, options: InvokeOptions, ctx: LLMToolContext): Promise<LLMOutput>;
|
|
1409
|
-
/**
|
|
1410
|
-
* 创建 LLM 配置
|
|
1411
|
-
*/
|
|
1412
|
-
declare function createInvokeConfig(model: string, apiKey: string, baseURL?: string): InvokeConfig;
|
|
1413
|
-
/**
|
|
1414
|
-
* LLM Hook 类型(兼容旧接口)
|
|
1415
|
-
*/
|
|
1416
|
-
type LLMHookType = "before-invoke" | "after-invoke" | "stream";
|
|
1417
|
-
/**
|
|
1418
|
-
* LLM Hook 上下文
|
|
1419
|
-
*/
|
|
1420
|
-
interface LLMHookContext {
|
|
1421
|
-
/** 请求 */
|
|
1422
|
-
request: LLMInvokeRequest;
|
|
1423
|
-
/** Provider ID */
|
|
1424
|
-
providerId: string;
|
|
1425
|
-
/** 模型名称 */
|
|
1426
|
-
model: string;
|
|
1427
|
-
/** 元数据 */
|
|
1428
|
-
metadata?: Record<string, unknown>;
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* Before Invoke Hook
|
|
1432
|
-
* 在 LLM 调用之前执行,可以修改请求
|
|
1433
|
-
*/
|
|
1434
|
-
type LLMBeforeInvokeHook = (context: LLMHookContext) => Promise<void>;
|
|
1435
|
-
/**
|
|
1436
|
-
* After Invoke Hook
|
|
1437
|
-
* 在 LLM 调用之后执行,可以处理结果
|
|
1438
|
-
*/
|
|
1439
|
-
type LLMAfterInvokeHook = (context: LLMHookContext, result: LLMInvokeResult) => Promise<void>;
|
|
1440
|
-
/**
|
|
1441
|
-
* Stream Hook
|
|
1442
|
-
* 在流式调用时处理每个事件
|
|
1443
|
-
*/
|
|
1444
|
-
type LLMStreamHook = (context: LLMHookContext, event: StreamEvent) => Promise<void>;
|
|
1445
|
-
/**
|
|
1446
|
-
* Hook 注册项
|
|
1447
|
-
*/
|
|
1448
|
-
interface LLMHookRegistration {
|
|
1449
|
-
/** Hook 类型 */
|
|
1450
|
-
type: LLMHookType;
|
|
1451
|
-
/** Hook 名称(可选,用于标识) */
|
|
1452
|
-
name?: string;
|
|
1453
|
-
/** Before Invoke Hook */
|
|
1454
|
-
beforeInvoke?: LLMBeforeInvokeHook;
|
|
1455
|
-
/** After Invoke Hook */
|
|
1456
|
-
afterInvoke?: LLMAfterInvokeHook;
|
|
1457
|
-
/** Stream Hook */
|
|
1458
|
-
stream?: LLMStreamHook;
|
|
1459
|
-
}
|
|
1460
|
-
/**
|
|
1461
|
-
* LLMHooks
|
|
1462
|
-
*
|
|
1463
|
-
* 兼容旧接口,内部委托给 globalHookManager
|
|
1464
|
-
*
|
|
1465
|
-
* @deprecated 请直接使用 globalHookManager
|
|
1466
|
-
*/
|
|
1467
|
-
declare class LLMHooks {
|
|
1468
|
-
private hookManager;
|
|
1469
|
-
/**
|
|
1470
|
-
* 注册 Hook
|
|
1471
|
-
*/
|
|
1472
|
-
register(type: LLMHookType, handler: LLMBeforeInvokeHook | LLMAfterInvokeHook | LLMStreamHook, name?: string): void;
|
|
1473
|
-
/**
|
|
1474
|
-
* 取消注册 Hook
|
|
1475
|
-
*/
|
|
1476
|
-
unregister(hook: LLMBeforeInvokeHook | LLMAfterInvokeHook | LLMStreamHook): void;
|
|
1477
|
-
/**
|
|
1478
|
-
* 按名称取消注册 Hook
|
|
1479
|
-
*/
|
|
1480
|
-
unregisterByName(name: string): void;
|
|
1481
|
-
/**
|
|
1482
|
-
* 按类型取消注册所有 Hook
|
|
1483
|
-
*/
|
|
1484
|
-
unregisterByType(type: LLMHookType): void;
|
|
1485
|
-
/**
|
|
1486
|
-
* 清空所有 Hook
|
|
1487
|
-
*/
|
|
1488
|
-
clear(): void;
|
|
1489
|
-
/**
|
|
1490
|
-
* 获取所有 Hook
|
|
1491
|
-
*/
|
|
1492
|
-
getHooks(): LLMHookRegistration[];
|
|
1493
|
-
/**
|
|
1494
|
-
* 按类型获取 Hook
|
|
1495
|
-
*/
|
|
1496
|
-
getHooksByType(type: LLMHookType): LLMHookRegistration[];
|
|
1497
|
-
/**
|
|
1498
|
-
* 执行 Before Invoke Hooks
|
|
1499
|
-
*
|
|
1500
|
-
* @deprecated 请使用 globalHookManager.execute(LLMHookPoints.BEFORE_INVOKE, ...)
|
|
1501
|
-
*/
|
|
1502
|
-
executeBeforeInvoke(context: LLMHookContext): Promise<void>;
|
|
1503
|
-
/**
|
|
1504
|
-
* 执行 After Invoke Hooks
|
|
1505
|
-
*
|
|
1506
|
-
* @deprecated 请使用 globalHookManager.execute(LLMHookPoints.AFTER_INVOKE, ...)
|
|
1507
|
-
*/
|
|
1508
|
-
executeAfterInvoke(context: LLMHookContext, result: LLMInvokeResult): Promise<void>;
|
|
1509
|
-
/**
|
|
1510
|
-
* 执行 Stream Hooks
|
|
1511
|
-
*
|
|
1512
|
-
* @deprecated 请使用 globalHookManager.execute(LLMHookPoints.ON_STREAM, ...)
|
|
1513
|
-
*/
|
|
1514
|
-
executeStream(context: LLMHookContext, event: StreamEvent): Promise<void>;
|
|
1515
|
-
}
|
|
1516
|
-
/**
|
|
1517
|
-
* @fileoverview 统一错误类型体系
|
|
1518
|
-
*
|
|
1519
|
-
* 提供 AgentError, ToolError, LLMError, ComponentError, ContextError 等错误类型
|
|
1520
|
-
* 每个错误包含 code(错误码)和 details(额外信息)
|
|
1521
|
-
*/
|
|
1522
|
-
/**
|
|
1523
|
-
* 错误码枚举
|
|
1524
|
-
*/
|
|
1525
|
-
declare const ErrorCodes: {
|
|
1526
|
-
readonly AGENT_NOT_FOUND: "AGENT_001";
|
|
1527
|
-
readonly AGENT_RUN_FAILED: "AGENT_002";
|
|
1528
|
-
readonly AGENT_TIMEOUT: "AGENT_003";
|
|
1529
|
-
readonly AGENT_CONFIG_INVALID: "AGENT_004";
|
|
1530
|
-
readonly TOOL_NOT_FOUND: "TOOL_001";
|
|
1531
|
-
readonly TOOL_DISABLED: "TOOL_002";
|
|
1532
|
-
readonly TOOL_EXECUTION_FAILED: "TOOL_003";
|
|
1533
|
-
readonly TOOL_VALIDATION_FAILED: "TOOL_004";
|
|
1534
|
-
readonly LLM_PROVIDER_NOT_FOUND: "LLM_001";
|
|
1535
|
-
readonly LLM_INVOCATION_FAILED: "LLM_002";
|
|
1536
|
-
readonly LLM_TIMEOUT: "LLM_003";
|
|
1537
|
-
readonly LLM_CONFIG_INVALID: "LLM_004";
|
|
1538
|
-
readonly COMPONENT_NOT_FOUND: "COMP_001";
|
|
1539
|
-
readonly COMPONENT_INIT_FAILED: "COMP_002";
|
|
1540
|
-
readonly COMPONENT_NOT_RUNNING: "COMP_003";
|
|
1541
|
-
readonly CONFIG_NOT_FOUND: "CONFIG_001";
|
|
1542
|
-
readonly CONFIG_INVALID: "CONFIG_002";
|
|
1543
|
-
readonly CONFIG_SOURCE_ERROR: "CONFIG_003";
|
|
1544
|
-
readonly CONTEXT_THRESHOLD_EXCEEDED: "CTX_001";
|
|
1545
|
-
readonly CONTEXT_COMPACTION_FAILED: "CTX_002";
|
|
1546
|
-
readonly MCP_INIT_FAILED: "MCP_001";
|
|
1547
|
-
readonly MCP_SERVER_ERROR: "MCP_002";
|
|
1548
|
-
readonly MCP_TOOL_ERROR: "MCP_003";
|
|
1549
|
-
};
|
|
1550
|
-
type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
1551
|
-
/**
|
|
1552
|
-
* RoyError 基类
|
|
1553
|
-
*/
|
|
1554
|
-
declare class RoyError extends Error {
|
|
1555
|
-
readonly code: ErrorCode;
|
|
1556
|
-
readonly details?: unknown;
|
|
1557
|
-
constructor(message: string, code: ErrorCode, details?: unknown);
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* LLM Output 结构(用于 ContextError 携带 assistant message)
|
|
1561
|
-
*
|
|
1562
|
-
* 这是简化版本,仅包含保存到 session 所需的最少字段。
|
|
1563
|
-
* 与 llm/types.ts 中的 LLMOutput 不同,那个版本包含完整的 LLM 调用结果。
|
|
1564
|
-
*/
|
|
1565
|
-
interface LLMOutput2 {
|
|
1566
|
-
content?: string;
|
|
1567
|
-
reasoning?: string;
|
|
1568
|
-
toolCalls?: Array<{
|
|
1569
|
-
id: string;
|
|
1570
|
-
function?: {
|
|
1571
|
-
name: string;
|
|
1572
|
-
arguments: string;
|
|
1573
|
-
};
|
|
1574
|
-
name?: string;
|
|
1575
|
-
arguments?: unknown;
|
|
1576
|
-
}>;
|
|
1577
|
-
usage?: {
|
|
1578
|
-
promptTokens: number;
|
|
1579
|
-
completionTokens: number;
|
|
1580
|
-
totalTokens: number;
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Context 相关错误
|
|
1585
|
-
*/
|
|
1586
|
-
declare class ContextError extends RoyError {
|
|
1587
|
-
readonly sessionId?: string | undefined;
|
|
1588
|
-
readonly usage?: {
|
|
1589
|
-
promptTokens: number;
|
|
1590
|
-
completionTokens: number;
|
|
1591
|
-
totalTokens: number;
|
|
1592
|
-
} | undefined;
|
|
1593
|
-
readonly contextWindow?: number | undefined;
|
|
1594
|
-
readonly llmOutput?: LLMOutput2;
|
|
1595
|
-
constructor(message: string, code?: ErrorCode, sessionId?: string | undefined, usage?: {
|
|
1596
|
-
promptTokens: number;
|
|
1597
|
-
completionTokens: number;
|
|
1598
|
-
totalTokens: number;
|
|
1599
|
-
} | undefined, contextWindow?: number | undefined, llmOutput?: LLMOutput2, details?: unknown);
|
|
1600
|
-
}
|
|
1601
|
-
/**
|
|
1602
|
-
* LLMComponent 配置(通过 options.config 传递)
|
|
1603
|
-
*
|
|
1604
|
-
* 配置加载顺序(优先级从低到高):
|
|
1605
|
-
* 1. File - 配置文件(通过 configPath 指定)
|
|
1606
|
-
* 2. Env - 环境变量(通过 envPrefix 配置前缀)
|
|
1607
|
-
* 3. Object - 直接传入的 config 对象(最高优先级)
|
|
1608
|
-
*
|
|
1609
|
-
* 环境变量转换规则:
|
|
1610
|
-
* - 驼峰命名会被转换为下划线分隔的大写形式
|
|
1611
|
-
* - 例如: "llm.defaultModel" + prefix "LLM" -> "LLM_LLM_DEFAULT_MODEL"
|
|
1612
|
-
*/
|
|
1613
|
-
interface LLMComponentOptions {
|
|
1614
|
-
/** ConfigComponent 实例(必填) */
|
|
1615
|
-
configComponent: ConfigComponent;
|
|
1616
|
-
/** 配置文件相对路径(可选,基于 XDG_DATA_HOME) */
|
|
1617
|
-
configPath?: string;
|
|
1618
|
-
/** 环境变量前缀(可选,默认 "LLM") */
|
|
1619
|
-
envPrefix?: string;
|
|
1620
|
-
/** 直接传入的配置对象(可选,优先级最高) */
|
|
1621
|
-
config?: Partial<LLMConfig>;
|
|
1622
|
-
}
|
|
1623
|
-
/**
|
|
1624
|
-
* LLMComponent
|
|
1625
|
-
* 管理 LLM 调用,使用 AI SDK 进行实际调用
|
|
1626
|
-
*
|
|
1627
|
-
* 配置通过 ConfigComponent 实时获取,支持配置热更新
|
|
1628
|
-
*
|
|
1629
|
-
* @example
|
|
1630
|
-
* // 通过 ConfigComponent 加载配置
|
|
1631
|
-
* const configComponent = new ConfigComponent();
|
|
1632
|
-
* configComponent.setXdgDataHome(__dirname);
|
|
1633
|
-
*
|
|
1634
|
-
* const llmComponent = new LLMComponent();
|
|
1635
|
-
* await llmComponent.init({
|
|
1636
|
-
* env, // Environment 实例(必填)
|
|
1637
|
-
* options: {
|
|
1638
|
-
* configComponent, // ConfigComponent 实例
|
|
1639
|
-
* configPath: "config.jsonc" // 配置文件路径
|
|
1640
|
-
* }
|
|
1641
|
-
* });
|
|
1642
|
-
*
|
|
1643
|
-
* // 配置更新后,下次调用会自动获取最新配置
|
|
1644
|
-
* configComponent.set("llm.temperature", 0.5);
|
|
1645
|
-
*/
|
|
1646
|
-
declare class LLMComponent extends BaseComponent {
|
|
1647
|
-
readonly name = "llm";
|
|
1648
|
-
readonly version = "2.0.0";
|
|
1649
|
-
private configComponent?;
|
|
1650
|
-
/** 配置变更 watcher 清理函数 */
|
|
1651
|
-
private configWatcher?;
|
|
1652
|
-
constructor();
|
|
1653
|
-
/**
|
|
1654
|
-
* 初始化组件
|
|
1655
|
-
*
|
|
1656
|
-
* 配置加载优先级(从高到低):
|
|
1657
|
-
* 1. Object - 直接传入的 config 对象
|
|
1658
|
-
* 2. Env - 环境变量(通过 envPrefix 配置前缀)
|
|
1659
|
-
* 3. File - 配置文件(通过 configPath 指定)
|
|
1660
|
-
*/
|
|
1661
|
-
init(config: ComponentConfig): Promise<void>;
|
|
1662
|
-
/**
|
|
1663
|
-
* 注册配置到 ConfigComponent
|
|
1664
|
-
*
|
|
1665
|
-
* 配置加载顺序(优先级从低到高):
|
|
1666
|
-
* 1. FileSource - 从配置文件加载(最低)
|
|
1667
|
-
* 2. EnvSource - 从环境变量加载(中等)
|
|
1668
|
-
* 3. MemorySource - 直接配置对象(最高)
|
|
1669
|
-
*/
|
|
1670
|
-
private registerConfig;
|
|
1671
|
-
/**
|
|
1672
|
-
* 将配置对象展平为点号路径
|
|
1673
|
-
*
|
|
1674
|
-
* @example
|
|
1675
|
-
* flattenConfig({ providers: { openai: { apiKey: "xxx" } } })
|
|
1676
|
-
* -> { "llm.providers.openai.apiKey": "xxx" }
|
|
1677
|
-
*/
|
|
1678
|
-
private flattenConfig;
|
|
1679
|
-
/**
|
|
1680
|
-
* 注册配置热更新监听
|
|
1681
|
-
*/
|
|
1682
|
-
private registerConfigWatcher;
|
|
1683
|
-
/**
|
|
1684
|
-
* 处理配置变更(支持热更新)
|
|
1685
|
-
*/
|
|
1686
|
-
protected onConfigChange(event: {
|
|
1687
|
-
key: string;
|
|
1688
|
-
oldValue?: unknown;
|
|
1689
|
-
newValue?: unknown;
|
|
1690
|
-
}): void;
|
|
1691
|
-
/**
|
|
1692
|
-
* 启动组件
|
|
1693
|
-
*/
|
|
1694
|
-
onStart(): Promise<void>;
|
|
1695
|
-
/**
|
|
1696
|
-
* 停止组件
|
|
1697
|
-
*/
|
|
1698
|
-
onStop(): Promise<void>;
|
|
1699
|
-
/**
|
|
1700
|
-
* 从配置源获取配置值
|
|
1701
|
-
* 优先从 ConfigComponent 获取(支持热更新),否则返回默认值
|
|
1702
|
-
*/
|
|
1703
|
-
private getLLMConfig;
|
|
1704
|
-
/**
|
|
1705
|
-
* 解析请求,构建调用上下文(invoke 和 invokeStream 共享)
|
|
1706
|
-
*/
|
|
1707
|
-
private resolveRequest;
|
|
1708
|
-
/**
|
|
1709
|
-
* 调用 LLM
|
|
1710
|
-
*
|
|
1711
|
-
* 流式事件通过 env.pushEnvEvent() 发布
|
|
1712
|
-
*/
|
|
1713
|
-
invoke(request: LLMInvokeRequest): Promise<LLMInvokeResult>;
|
|
1714
|
-
/**
|
|
1715
|
-
* 获取 Provider API Key
|
|
1716
|
-
*/
|
|
1717
|
-
private getApiKey;
|
|
1718
|
-
/**
|
|
1719
|
-
* 获取 Provider
|
|
1720
|
-
*/
|
|
1721
|
-
getProvider(id: string);
|
|
1722
|
-
/**
|
|
1723
|
-
* 列出所有 Provider
|
|
1724
|
-
*/
|
|
1725
|
-
listProviders();
|
|
1726
|
-
/**
|
|
1727
|
-
* 获取模型的限制配置
|
|
1728
|
-
*
|
|
1729
|
-
* @param providerId - Provider ID
|
|
1730
|
-
* @param modelId - 模型 ID(可选,默认使用 provider 的 defaultModel)
|
|
1731
|
-
* @returns 模型限制配置,如果没有配置则返回 undefined
|
|
1732
|
-
*/
|
|
1733
|
-
getModelLimits(providerId: string, modelId?: string): ModelLimits | undefined;
|
|
1734
|
-
/**
|
|
1735
|
-
* 获取上下文窗口阈值配置
|
|
1736
|
-
*
|
|
1737
|
-
* @param providerId - Provider ID
|
|
1738
|
-
* @param modelId - 模型 ID
|
|
1739
|
-
* @returns 包含 contextWindow 和 thresholdRatio 的对象
|
|
1740
|
-
*/
|
|
1741
|
-
getContextThresholdConfig(providerId: string, modelId?: string): {
|
|
1742
|
-
contextWindow: number;
|
|
1743
|
-
thresholdRatio: number;
|
|
1744
|
-
};
|
|
1745
|
-
/**
|
|
1746
|
-
* 检测上下文阈值是否超过
|
|
1747
|
-
*
|
|
1748
|
-
* @param usage - LLM 使用量信息
|
|
1749
|
-
* @param providerId - Provider ID
|
|
1750
|
-
* @param modelId - 模型 ID
|
|
1751
|
-
* @param sessionId - Session ID(用于错误信息)
|
|
1752
|
-
* @returns 如果超过阈值,返回 ContextError;否则返回 undefined
|
|
1753
|
-
*/
|
|
1754
|
-
checkContextThreshold(usage: {
|
|
1755
|
-
totalTokens: number;
|
|
1756
|
-
promptTokens?: number;
|
|
1757
|
-
completionTokens?: number;
|
|
1758
|
-
} | undefined, providerId: string, modelId: string | undefined, sessionId?: string): ContextError | undefined;
|
|
1759
|
-
}
|
|
1760
|
-
export { parseModelString, invokeNonStream, invoke, createInvokeConfig, UsageInfo, ToolResult, ToolInfo, ToolCall, StreamEvent, ProviderType, ProviderManager, ProviderConfigSchema, ProviderConfig, ProviderCapabilitiesSchema, ModelLimitsSchema, LLMTransform, LLMToolContext, LLMStreamHook, LLMProvider, LLMOutput, LLMMessage, LLMInvokeResult, LLMInvokeRequest, LLMHooks, LLMHookType, LLMHookRegistration, LLMHookContext, LLMDefaultConfigSchema, LLMConfigSchema, LLMConfig, LLMComponentOptions, LLMComponent, LLMBeforeInvokeHook, LLMAfterInvokeHook, InvokeOptions, InvokeConfig, ConvertedUsageInfo };
|