@agentdevjs/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BasicAgent-UBGLABDV.js +12 -0
- package/dist/ExplorerAgent-C62LOUTX.js +12 -0
- package/dist/{chunk-BVF7RUXV.js → chunk-KCCLSQC4.js} +1 -1
- package/dist/chunk-KCCLSQC4.js.map +1 -0
- package/dist/{chunk-KO4DJKM6.js → chunk-OFBE43IS.js} +1 -1
- package/dist/{chunk-KO4DJKM6.js.map → chunk-OFBE43IS.js.map} +1 -1
- package/dist/{chunk-YFSM6IYU.js → chunk-TKVOWEJ2.js} +154 -49
- package/dist/chunk-TKVOWEJ2.js.map +1 -0
- package/dist/{chunk-574NG4UB.js → chunk-U3LWOJ3Q.js} +4 -4
- package/dist/chunk-U3LWOJ3Q.js.map +1 -0
- package/dist/{chunk-UCEIJEM5.js → chunk-V3WM6EII.js} +2 -2
- package/dist/chunk-V3WM6EII.js.map +1 -0
- package/dist/{chunk-TIJV6GJW.js → chunk-YYNP7MZC.js} +4 -3
- package/dist/chunk-YYNP7MZC.js.map +1 -0
- package/dist/features/example-feature/templates/example-tool.render.js.map +1 -1
- package/dist/features/opencode-basic/templates/edit.render.js +1 -1
- package/dist/features/opencode-basic/templates/edit.render.js.map +1 -1
- package/dist/features/opencode-basic/templates/glob.render.js.map +1 -1
- package/dist/features/opencode-basic/templates/grep.render.js.map +1 -1
- package/dist/features/opencode-basic/templates/ls.render.js.map +1 -1
- package/dist/features/opencode-basic/templates/read.render.js +1 -1
- package/dist/features/opencode-basic/templates/read.render.js.map +1 -1
- package/dist/features/opencode-basic/templates/write.render.js +1 -1
- package/dist/features/opencode-basic/templates/write.render.js.map +1 -1
- package/dist/features/skill/templates/skill.render.js.map +1 -1
- package/dist/features/subagent/templates/agent-close.render.js.map +1 -1
- package/dist/features/subagent/templates/agent-list.render.js.map +1 -1
- package/dist/features/subagent/templates/agent-send.render.js.map +1 -1
- package/dist/features/subagent/templates/agent-spawn.render.js.map +1 -1
- package/dist/features/subagent/templates/wait.render.js.map +1 -1
- package/dist/features/todo/templates/task-clear.render.js.map +1 -1
- package/dist/features/todo/templates/task-create.render.js.map +1 -1
- package/dist/features/todo/templates/task-list.render.js.map +1 -1
- package/dist/features/todo/templates/task-update.render.js.map +1 -1
- package/dist/index.d.ts +2276 -2024
- package/dist/index.js +519 -205
- package/dist/index.js.map +1 -1
- package/dist/{notification-5DFBYKKN.js → notification-CASV7QYT.js} +2 -2
- package/dist/{resolver-F5SM2RHQ.js → resolver-4JA7VPYP.js} +2 -2
- package/dist/{session-events-TETMQI45.js → session-events-S7LMJ6MM.js} +2 -2
- package/package.json +55 -55
- package/dist/BasicAgent-RPYJHYCM.js +0 -12
- package/dist/ExplorerAgent-ITTSJRJI.js +0 -12
- package/dist/chunk-574NG4UB.js.map +0 -1
- package/dist/chunk-BVF7RUXV.js.map +0 -1
- package/dist/chunk-TIJV6GJW.js.map +0 -1
- package/dist/chunk-UCEIJEM5.js.map +0 -1
- package/dist/chunk-YFSM6IYU.js.map +0 -1
- /package/dist/{BasicAgent-RPYJHYCM.js.map → BasicAgent-UBGLABDV.js.map} +0 -0
- /package/dist/{ExplorerAgent-ITTSJRJI.js.map → ExplorerAgent-C62LOUTX.js.map} +0 -0
- /package/dist/{notification-5DFBYKKN.js.map → notification-CASV7QYT.js.map} +0 -0
- /package/dist/{resolver-F5SM2RHQ.js.map → resolver-4JA7VPYP.js.map} +0 -0
- /package/dist/{session-events-TETMQI45.js.map → session-events-S7LMJ6MM.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,171 +1,44 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { Diagnostic } from 'vscode-languageserver-types';
|
|
3
3
|
|
|
4
|
-
interface LoggerBindings extends LogContextRef {
|
|
5
|
-
tags?: string[];
|
|
6
|
-
}
|
|
7
|
-
interface Logger {
|
|
8
|
-
trace(message: string, data?: unknown): void;
|
|
9
|
-
debug(message: string, data?: unknown): void;
|
|
10
|
-
info(message: string, data?: unknown): void;
|
|
11
|
-
warn(message: string, data?: unknown): void;
|
|
12
|
-
error(message: string, data?: unknown): void;
|
|
13
|
-
child(options?: LoggerBindings & {
|
|
14
|
-
namespace?: string;
|
|
15
|
-
}): Logger;
|
|
16
|
-
}
|
|
17
|
-
declare function installConsoleBridge(): void;
|
|
18
|
-
declare function runWithLogScope<T>(scope: LogContextRef, fn: () => T): T;
|
|
19
|
-
declare function emitLog(level: LogLevel, message: string, data?: unknown, options?: {
|
|
20
|
-
namespace?: string;
|
|
21
|
-
context?: LogContextRef;
|
|
22
|
-
}): DebugLogEntry;
|
|
23
|
-
declare function createLogger(namespace: string, bindings?: LoggerBindings): Logger;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Capability System - 统一能力控制面(P1:command)
|
|
27
|
-
*
|
|
28
|
-
* Feature 通过 getCapabilities() 声明可被显式调用的命令,注册表提供
|
|
29
|
-
* 平面寻址(`featureName.commandName`)与三动词中的 invoke 语义。
|
|
30
|
-
*
|
|
31
|
-
* 设计裁决(详见 AgentDevClaw docs/adr capability-registry-as-control-plane):
|
|
32
|
-
* - 命令式优先:只有 invoke / query / emit,不存在 bind / reactive / watch。
|
|
33
|
-
* 共享权威状态与跨 feature 事务是负面清单,不做。
|
|
34
|
-
* - entryPoints 是契约约束而非安全边界:声明不含请求入口的 command 被
|
|
35
|
-
* invoke 时返回 entry_point_denied(结构化错误,非静默失败)。绕过
|
|
36
|
-
* 路径(getFeature 直引)依旧存在,这是已知边界而非漏洞。
|
|
37
|
-
* - 进程内语义:args 是普通 JS 值,不为序列化设计。跨进程投递是宿主层
|
|
38
|
-
* 职责,注册表不为其建模。
|
|
39
|
-
* - 注册表是哑的:不做参数校验(schema 服务于消费端渲染表单)、不含
|
|
40
|
-
* 派发策略、不管依赖管理。
|
|
41
|
-
* - 命令超时即失败:超时返回 timeout,但执行体可能仍在进行(Promise
|
|
42
|
-
* 无法取消),不保证中断,只保证调用方不挂死。
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
4
|
/**
|
|
46
|
-
*
|
|
5
|
+
* Continuation Request 类型定义
|
|
47
6
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
7
|
+
* 控制工具(如 checkpoint、rollback)通过 registerContinuationRequest()
|
|
8
|
+
* 登记一个 continuation request,使当前 onCall 在合法边界停止。
|
|
9
|
+
* 宿主(如 CallArbiter)通过 consumeContinuationRequest() 消费该请求,
|
|
10
|
+
* 决定是否在同一个逻辑 envelope 内启动下一个 onCall segment。
|
|
50
11
|
*/
|
|
51
|
-
type CapabilityEntryPoint = 'slash' | 'feature';
|
|
52
12
|
/**
|
|
53
|
-
*
|
|
54
|
-
* (收到 invoke 一律执行 execute);行为差异(表单/pill/toast/触发
|
|
55
|
-
* 时机)由应用层(宿主前端)按 kind 消费。
|
|
13
|
+
* Checkpoint continuation request
|
|
56
14
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
type CapabilityKind = 'invoke' | 'prompt';
|
|
62
|
-
/**
|
|
63
|
-
* Feature 声明的可调用命令
|
|
64
|
-
*/
|
|
65
|
-
interface CapabilityDefinition {
|
|
66
|
-
/** 命令名(标识符),注册表内以 `featureName.commandName` 寻址 */
|
|
67
|
-
name: string;
|
|
68
|
-
/** 命令类型,缺省 'invoke'。框架透传不解释,语义由应用层消费 */
|
|
69
|
-
kind?: CapabilityKind;
|
|
70
|
-
/** 菜单显示标题,缺省用 name */
|
|
71
|
-
title?: string;
|
|
72
|
-
/** 菜单描述 */
|
|
73
|
-
description?: string;
|
|
74
|
-
/**
|
|
75
|
-
* 参数 schema,复用 FeatureManifestSettingProperty 词汇表,
|
|
76
|
-
* 与 feature-setup 配置表单、flow 交互选项共用一套渲染基底。
|
|
77
|
-
*/
|
|
78
|
-
parameters?: Record<string, FeatureManifestSettingProperty>;
|
|
79
|
-
/**
|
|
80
|
-
* 可见入口,缺省 ['feature'](最小暴露)。
|
|
81
|
-
* 进 slash 菜单必须是显式主动行为。
|
|
82
|
-
*/
|
|
83
|
-
entryPoints?: CapabilityEntryPoint[];
|
|
84
|
-
/**
|
|
85
|
-
* 参数当前生效值(配置回显):参数表单打开时优先于 parameters 的
|
|
86
|
-
* default 显示。返回普通对象,键与 parameters 对齐;缺省或抛错
|
|
87
|
-
* 时表单回退 default。读取必须无副作用。
|
|
88
|
-
*/
|
|
89
|
-
readCurrentValues?: () => Record<string, unknown>;
|
|
90
|
-
/** 执行体。抛出的任何错误归一为 execute_failed */
|
|
91
|
-
execute(args: Record<string, unknown>, ctx: CapabilityContext): Promise<unknown>;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 命令执行上下文(进程内)
|
|
15
|
+
* Agent 建立了一个命名检查点,希望继续执行。
|
|
16
|
+
* 宿主应捕获当前 runtime snapshot 并将其与 checkpointId 关联,
|
|
17
|
+
* 然后启动 continuation segment。
|
|
95
18
|
*/
|
|
96
|
-
interface
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
19
|
+
interface CheckpointContinuationRequest {
|
|
20
|
+
kind: 'checkpoint';
|
|
21
|
+
checkpointId: string;
|
|
22
|
+
/** 可选附加元数据(如 Agent 的自由备注) */
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
100
24
|
}
|
|
101
25
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
type CapabilityInvokeResult = {
|
|
109
|
-
ok: true;
|
|
110
|
-
result: unknown;
|
|
111
|
-
} | {
|
|
112
|
-
ok: false;
|
|
113
|
-
code: 'not_found' | 'entry_point_denied' | 'execute_failed' | 'timeout';
|
|
114
|
-
message: string;
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* 清单快照条目(下发宿主 / 前端菜单消费的数据形态,纯数据)
|
|
26
|
+
* Rollback continuation request
|
|
27
|
+
*
|
|
28
|
+
* Agent 希望回退到指定 checkpoint,并携带一个失败分支的摘要。
|
|
29
|
+
* 宿主应恢复到 checkpoint 的 runtime snapshot,
|
|
30
|
+
* 然后以摘要作为 continuation segment 的输入启动新的 onCall。
|
|
118
31
|
*/
|
|
119
|
-
interface
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
kind: CapabilityKind;
|
|
125
|
-
title: string;
|
|
126
|
-
description?: string;
|
|
127
|
-
parameters?: Record<string, FeatureManifestSettingProperty>;
|
|
128
|
-
entryPoints: CapabilityEntryPoint[];
|
|
129
|
-
/** 参数当前生效值(readCurrentValues 收集;读取失败时缺省) */
|
|
130
|
-
currentValues?: Record<string, unknown>;
|
|
32
|
+
interface RollbackContinuationRequest {
|
|
33
|
+
kind: 'rollback';
|
|
34
|
+
checkpointId: string;
|
|
35
|
+
/** Agent 生成的失败分支摘要 */
|
|
36
|
+
summary: string;
|
|
131
37
|
}
|
|
132
38
|
/**
|
|
133
|
-
*
|
|
39
|
+
* 受类型约束的 continuation request
|
|
134
40
|
*/
|
|
135
|
-
|
|
136
|
-
private defs;
|
|
137
|
-
/**
|
|
138
|
-
* 注册 feature 的命令。ref(`feature.name`)重复视为装配错误,直接抛出,
|
|
139
|
-
* 对齐 feature-graph 的报错哲学。
|
|
140
|
-
*/
|
|
141
|
-
register(featureName: string, def: CapabilityDefinition): void;
|
|
142
|
-
has(ref: string): boolean;
|
|
143
|
-
/** ref → 所属 feature 名(dispatchTurnActivations 按 owner 分组派发用) */
|
|
144
|
-
ownerOf(ref: string): string | null;
|
|
145
|
-
/** ref → 命令类型(缺省 'invoke');未注册返回 null */
|
|
146
|
-
kindOf(ref: string): CapabilityKind | null;
|
|
147
|
-
/**
|
|
148
|
-
* 移除指定 feature 的全部命令(幂等)。
|
|
149
|
-
* initSingleFeature 重挂路径先调它,避免热载时误报 duplicate ref。
|
|
150
|
-
*/
|
|
151
|
-
unregisterFeature(featureName: string): void;
|
|
152
|
-
/**
|
|
153
|
-
* 清单快照。传入 entryPoint 时过滤出该入口可见的命令
|
|
154
|
-
* (宿主下发 slash 菜单清单时用 { entryPoint: 'slash' })。
|
|
155
|
-
*/
|
|
156
|
-
list(filter?: {
|
|
157
|
-
entryPoint?: CapabilityEntryPoint;
|
|
158
|
-
}): CapabilitySnapshot[];
|
|
159
|
-
/**
|
|
160
|
-
* 调用命令。entryPoint 必填——调用方声明自己以哪个入口进来,
|
|
161
|
-
* 注册表据此执行 entryPoints 契约检查。
|
|
162
|
-
*/
|
|
163
|
-
invoke(ref: string, opts: {
|
|
164
|
-
args?: Record<string, unknown>;
|
|
165
|
-
entryPoint: CapabilityEntryPoint;
|
|
166
|
-
timeoutMs?: number;
|
|
167
|
-
}, ctx: CapabilityContext): Promise<CapabilityInvokeResult>;
|
|
168
|
-
}
|
|
41
|
+
type CallContinuationRequest = CheckpointContinuationRequest | RollbackContinuationRequest;
|
|
169
42
|
|
|
170
43
|
/**
|
|
171
44
|
* 模板加载器
|
|
@@ -188,7 +61,7 @@ declare class TemplateLoader {
|
|
|
188
61
|
/**
|
|
189
62
|
* 加载模板(同步)
|
|
190
63
|
*/
|
|
191
|
-
loadSync(
|
|
64
|
+
loadSync(_templatePath: string): string;
|
|
192
65
|
/**
|
|
193
66
|
* 解析路径为绝对路径
|
|
194
67
|
* @param templatePath 模板路径
|
|
@@ -219,46 +92,157 @@ declare class TemplateLoader {
|
|
|
219
92
|
}
|
|
220
93
|
|
|
221
94
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
95
|
+
* 数据源注册系统
|
|
96
|
+
*
|
|
97
|
+
* 提供通用的列表数据渲染能力,Feature 可以注册自定义数据源
|
|
98
|
+
* 然后在 TemplateComposer 中使用 `{ dataSourceName: 'template' }` 语法
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // 注册数据源
|
|
103
|
+
* DataSourceRegistry.register({
|
|
104
|
+
* name: 'tasks',
|
|
105
|
+
* getData: async () => [{ id: 1, title: 'Task 1', priority: 'high' }],
|
|
106
|
+
* renderItem: (item, template, ctx) => {
|
|
107
|
+
* return PlaceholderResolver.resolve(template, { ...ctx, ...item });
|
|
108
|
+
* },
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // 在模板中使用
|
|
112
|
+
* composer.add({ tasks: '- {{title}} ({{priority}})' });
|
|
113
|
+
* ```
|
|
224
114
|
*/
|
|
225
115
|
|
|
226
116
|
/**
|
|
227
|
-
*
|
|
117
|
+
* 数据源渲染器接口
|
|
228
118
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
private loader;
|
|
233
|
-
private _dataSourceRegistry?;
|
|
234
|
-
constructor(loader?: TemplateLoader);
|
|
119
|
+
interface DataSourceRenderer<T = any> {
|
|
120
|
+
/** 数据源唯一标识 */
|
|
121
|
+
name: string;
|
|
235
122
|
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
123
|
+
* 获取数据列表
|
|
124
|
+
* @param context 渲染上下文
|
|
125
|
+
* @returns 数据数组(可以是异步的)
|
|
238
126
|
*/
|
|
239
|
-
|
|
127
|
+
getData(context: PlaceholderContext): Promise<T[]> | T[];
|
|
240
128
|
/**
|
|
241
|
-
*
|
|
129
|
+
* 渲染单个数据项
|
|
130
|
+
* @param item 数据项
|
|
131
|
+
* @param template 模板字符串
|
|
132
|
+
* @param context 渲染上下文
|
|
133
|
+
* @returns 渲染后的字符串
|
|
242
134
|
*/
|
|
243
|
-
|
|
135
|
+
renderItem(item: T, template: string, context: PlaceholderContext): string;
|
|
244
136
|
/**
|
|
245
|
-
*
|
|
137
|
+
* 可选:判断是否启用该数据源
|
|
138
|
+
* @param context 渲染上下文
|
|
139
|
+
* @returns 是否启用(默认 true)
|
|
246
140
|
*/
|
|
247
|
-
|
|
141
|
+
isEnabled?(context: PlaceholderContext): boolean;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 数据源注册中心(per-Agent 实例)
|
|
145
|
+
*
|
|
146
|
+
* 历史上此类是 static(进程全局),在共享进程模式下多个 Agent 实例
|
|
147
|
+
* 会互相覆盖数据源。现已改为实例化:每个 Agent 持有独立的注册表,
|
|
148
|
+
* 由 FeatureInitContext.dataSourceRegistry 传递给各 Feature。
|
|
149
|
+
*/
|
|
150
|
+
declare class DataSourceRegistry {
|
|
151
|
+
private sources;
|
|
248
152
|
/**
|
|
249
|
-
*
|
|
153
|
+
* 注册数据源
|
|
250
154
|
*/
|
|
251
|
-
|
|
155
|
+
register(renderer: DataSourceRenderer): void;
|
|
252
156
|
/**
|
|
253
|
-
*
|
|
157
|
+
* 注销数据源
|
|
254
158
|
*/
|
|
255
|
-
|
|
159
|
+
unregister(name: string): boolean;
|
|
256
160
|
/**
|
|
257
|
-
*
|
|
161
|
+
* 获取数据源
|
|
258
162
|
*/
|
|
259
|
-
|
|
163
|
+
get(name: string): DataSourceRenderer | undefined;
|
|
260
164
|
/**
|
|
261
|
-
*
|
|
165
|
+
* 检查数据源是否存在
|
|
166
|
+
*/
|
|
167
|
+
has(name: string): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* 获取所有已注册的数据源名称
|
|
170
|
+
*/
|
|
171
|
+
names(): string[];
|
|
172
|
+
/**
|
|
173
|
+
* 渲染数据源
|
|
174
|
+
* @param name 数据源名称
|
|
175
|
+
* @param template 模板字符串
|
|
176
|
+
* @param context 渲染上下文
|
|
177
|
+
* @returns 渲染后的字符串
|
|
178
|
+
*/
|
|
179
|
+
render(name: string, template: string, context?: PlaceholderContext): Promise<string>;
|
|
180
|
+
/**
|
|
181
|
+
* 清空所有数据源(主要用于测试)
|
|
182
|
+
*/
|
|
183
|
+
clear(): void;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 创建列表渲染器的工厂函数
|
|
187
|
+
* 简化常见数据源的注册
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* DataSourceRegistry.register(createListRenderer({
|
|
192
|
+
* name: 'tasks',
|
|
193
|
+
* getData: (ctx) => ctx.tasks as Task[],
|
|
194
|
+
* // 默认 renderItem 会将 item 合并到 context 中
|
|
195
|
+
* }));
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
declare function createListRenderer<T = any>(config: Omit<DataSourceRenderer<T>, 'renderItem'> & {
|
|
199
|
+
/** 自定义渲染函数(可选) */
|
|
200
|
+
renderItem?: DataSourceRenderer<T>['renderItem'];
|
|
201
|
+
/** 是否合并 item 到 context(默认 true) */
|
|
202
|
+
mergeItem?: boolean;
|
|
203
|
+
}): DataSourceRenderer<T>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 模板组合器
|
|
207
|
+
* 支持流式 API 和灵活拼接
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 模板组合器
|
|
212
|
+
*/
|
|
213
|
+
declare class TemplateComposer {
|
|
214
|
+
private parts;
|
|
215
|
+
private separator;
|
|
216
|
+
private loader;
|
|
217
|
+
private _dataSourceRegistry?;
|
|
218
|
+
constructor(loader?: TemplateLoader);
|
|
219
|
+
/**
|
|
220
|
+
* 设置 Agent 级数据源注册表实例
|
|
221
|
+
* 由 TemplateResolver 在渲染前调用,嵌套 composer 会自动继承。
|
|
222
|
+
*/
|
|
223
|
+
setDataSourceRegistry(registry?: DataSourceRegistry): this;
|
|
224
|
+
/**
|
|
225
|
+
* 添加模板源
|
|
226
|
+
*/
|
|
227
|
+
add(source: TemplateSource | TemplateComposer): this;
|
|
228
|
+
/**
|
|
229
|
+
* 添加模板源(别名)
|
|
230
|
+
*/
|
|
231
|
+
append(source: TemplateSource | TemplateComposer): this;
|
|
232
|
+
/**
|
|
233
|
+
* 在头部插入
|
|
234
|
+
*/
|
|
235
|
+
prepend(source: TemplateSource | TemplateComposer): this;
|
|
236
|
+
/**
|
|
237
|
+
* 添加多个模板源
|
|
238
|
+
*/
|
|
239
|
+
addAll(...sources: (TemplateSource | TemplateComposer)[]): this;
|
|
240
|
+
/**
|
|
241
|
+
* 设置分隔符
|
|
242
|
+
*/
|
|
243
|
+
joinWith(sep: string): this;
|
|
244
|
+
/**
|
|
245
|
+
* 条件添加
|
|
262
246
|
*/
|
|
263
247
|
when(condition: boolean | ((ctx: PlaceholderContext) => boolean), source: TemplateSource | TemplateComposer): this;
|
|
264
248
|
/**
|
|
@@ -302,6 +286,7 @@ declare class TemplateComposer {
|
|
|
302
286
|
/**
|
|
303
287
|
* 提示词模板系统 - 核心类型定义
|
|
304
288
|
*/
|
|
289
|
+
|
|
305
290
|
/**
|
|
306
291
|
* 模板源
|
|
307
292
|
* - string: 硬编码字符串
|
|
@@ -385,2136 +370,2234 @@ declare class TemplateError extends Error {
|
|
|
385
370
|
}
|
|
386
371
|
|
|
387
372
|
/**
|
|
388
|
-
*
|
|
373
|
+
* UsageStats - 用量统计系统
|
|
389
374
|
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
375
|
+
* 职责:
|
|
376
|
+
* - 记录 LLM 调用的 token 用量
|
|
377
|
+
* - 聚合 session/call/step 三级统计
|
|
378
|
+
* - 提供快照序列化和恢复
|
|
379
|
+
* - 格式化用量报告
|
|
392
380
|
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
*
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
381
|
+
* 设计原则:
|
|
382
|
+
* - 框架内置,不是 Feature
|
|
383
|
+
* - 自动收集,不需要手动干预
|
|
384
|
+
* - 快照包含 session 级数据,用于会话恢复
|
|
385
|
+
*/
|
|
386
|
+
/**
|
|
387
|
+
* 统一用量格式(兼容 Anthropic 和 OpenAI)
|
|
388
|
+
*/
|
|
389
|
+
interface UsageInfo {
|
|
390
|
+
/** 输入 token 数 */
|
|
391
|
+
inputTokens: number;
|
|
392
|
+
/** 输出 token 数 */
|
|
393
|
+
outputTokens: number;
|
|
394
|
+
/** 总 token 数 */
|
|
395
|
+
totalTokens: number;
|
|
396
|
+
/** 创建缓存消耗的 token 数 */
|
|
397
|
+
cacheCreationTokens?: number;
|
|
398
|
+
/** 从缓存读取的 token 数 */
|
|
399
|
+
cacheReadTokens?: number;
|
|
400
|
+
/** 推理 token 数(prompt_tokens_details 或 completion_tokens_details) */
|
|
401
|
+
reasoningTokens?: number;
|
|
402
|
+
/** 音频 token 数 */
|
|
403
|
+
audioTokens?: number;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* 单次 LLM 调用的模型归因(轮换 / mid-turn 热切换场景下每次请求可能不同)
|
|
407
|
+
*/
|
|
408
|
+
interface ModelUsageKey {
|
|
409
|
+
/** 模型名(getLLMMeta().modelName) */
|
|
410
|
+
modelName?: string;
|
|
411
|
+
/** preset 名(getLLMMeta().presetName) */
|
|
412
|
+
presetName?: string;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Call 内按模型分段的用量汇总。
|
|
403
416
|
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
* ```
|
|
417
|
+
* 一次 call 内发生模型切换时,用量归因以每次 LLM 请求发出时刻的模型为准;
|
|
418
|
+
* totalUsage 仍是整 call 聚合,分段是它的模型维度拆分。
|
|
407
419
|
*/
|
|
408
|
-
|
|
420
|
+
interface ModelUsageSegment {
|
|
421
|
+
modelName: string;
|
|
422
|
+
presetName: string;
|
|
423
|
+
usage: UsageInfo;
|
|
424
|
+
/** 该模型承担的 LLM 请求数 */
|
|
425
|
+
requests: number;
|
|
426
|
+
/** 该模型命中缓存的请求数 */
|
|
427
|
+
cacheHitRequests: number;
|
|
428
|
+
}
|
|
409
429
|
/**
|
|
410
|
-
*
|
|
430
|
+
* 单次 Call 用量汇总
|
|
411
431
|
*/
|
|
412
|
-
interface
|
|
413
|
-
|
|
414
|
-
|
|
432
|
+
interface CallUsageSummary {
|
|
433
|
+
callIndex: number;
|
|
434
|
+
totalUsage: UsageInfo;
|
|
435
|
+
stepCount: number;
|
|
436
|
+
cacheHitRequests: number;
|
|
437
|
+
startTime: number;
|
|
438
|
+
endTime?: number;
|
|
439
|
+
/** 按模型分段的用量(record 未携带模型归因时为空) */
|
|
440
|
+
modelSegments?: ModelUsageSegment[];
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Session 用量快照(用于序列化)
|
|
444
|
+
*/
|
|
445
|
+
interface UsageStatsSnapshot {
|
|
446
|
+
/** Session 级累计用量 */
|
|
447
|
+
totalUsage: UsageInfo;
|
|
448
|
+
/** 各 Call 的用量汇总 */
|
|
449
|
+
calls: CallUsageSummary[];
|
|
450
|
+
/** 总请求数(LLM 调用次数) */
|
|
451
|
+
totalRequests: number;
|
|
452
|
+
/** 命中缓存的请求数(request-level) */
|
|
453
|
+
totalCacheHitRequests: number;
|
|
454
|
+
/** 最后一次请求的用量(用于显示当前上下文占用) */
|
|
455
|
+
lastRequestUsage?: UsageInfo;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* 用量统计类
|
|
459
|
+
*/
|
|
460
|
+
declare class UsageStats {
|
|
461
|
+
/** Session 级累计用量 */
|
|
462
|
+
private totalUsage;
|
|
463
|
+
/** 当前活跃 Call 的用量记录 */
|
|
464
|
+
private currentCallUsage;
|
|
465
|
+
/** 总 LLM 调用次数 */
|
|
466
|
+
private totalRequests;
|
|
467
|
+
/** 命中缓存的总请求数 */
|
|
468
|
+
private totalCacheHitRequests;
|
|
469
|
+
/** 当前 Call 的 Step 记录(临时,用于聚合) */
|
|
470
|
+
private currentStepRecords;
|
|
471
|
+
/** 最后一次 LLM 调用的用量(用于显示当前上下文占用) */
|
|
472
|
+
private lastRequestUsage;
|
|
415
473
|
/**
|
|
416
|
-
*
|
|
417
|
-
* @param
|
|
418
|
-
* @
|
|
474
|
+
* 记录一次 LLM 调用的用量
|
|
475
|
+
* @param callIndex Call 序号
|
|
476
|
+
* @param step Step 序号
|
|
477
|
+
* @param usage 用量数据
|
|
478
|
+
* @param model 该次请求的模型归因;缺省时不产生分段
|
|
419
479
|
*/
|
|
420
|
-
|
|
480
|
+
record(callIndex: number, step: number, usage: UsageInfo, model?: ModelUsageKey): void;
|
|
421
481
|
/**
|
|
422
|
-
*
|
|
423
|
-
* @param
|
|
424
|
-
* @param template 模板字符串
|
|
425
|
-
* @param context 渲染上下文
|
|
426
|
-
* @returns 渲染后的字符串
|
|
482
|
+
* 标记 Call 结束
|
|
483
|
+
* @param callIndex Call 序号
|
|
427
484
|
*/
|
|
428
|
-
|
|
485
|
+
endCall(callIndex: number): void;
|
|
429
486
|
/**
|
|
430
|
-
*
|
|
431
|
-
* @param context 渲染上下文
|
|
432
|
-
* @returns 是否启用(默认 true)
|
|
487
|
+
* 获取 Session 级累计用量
|
|
433
488
|
*/
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
* 数据源注册中心(per-Agent 实例)
|
|
438
|
-
*
|
|
439
|
-
* 历史上此类是 static(进程全局),在共享进程模式下多个 Agent 实例
|
|
440
|
-
* 会互相覆盖数据源。现已改为实例化:每个 Agent 持有独立的注册表,
|
|
441
|
-
* 由 FeatureInitContext.dataSourceRegistry 传递给各 Feature。
|
|
442
|
-
*/
|
|
443
|
-
declare class DataSourceRegistry {
|
|
444
|
-
private sources;
|
|
489
|
+
getTotalUsage(): UsageInfo;
|
|
490
|
+
/** Call 汇总的深拷贝(totalUsage 与 modelSegments 均独立副本) */
|
|
491
|
+
private cloneCallSummary;
|
|
445
492
|
/**
|
|
446
|
-
*
|
|
493
|
+
* 获取指定 Call 的用量汇总
|
|
494
|
+
* @param callIndex Call 序号
|
|
447
495
|
*/
|
|
448
|
-
|
|
496
|
+
getCallUsage(callIndex: number): CallUsageSummary | undefined;
|
|
449
497
|
/**
|
|
450
|
-
*
|
|
498
|
+
* 获取所有 Call 的用量汇总
|
|
451
499
|
*/
|
|
452
|
-
|
|
500
|
+
getAllCallUsage(): CallUsageSummary[];
|
|
453
501
|
/**
|
|
454
|
-
*
|
|
502
|
+
* 获取总请求次数
|
|
455
503
|
*/
|
|
456
|
-
|
|
504
|
+
getTotalRequests(): number;
|
|
505
|
+
getTotalCacheHitRequests(): number;
|
|
457
506
|
/**
|
|
458
|
-
*
|
|
507
|
+
* 获取最后一次请求的用量(用于显示当前上下文占用)
|
|
459
508
|
*/
|
|
460
|
-
|
|
509
|
+
getLastRequestUsage(): UsageInfo | null;
|
|
461
510
|
/**
|
|
462
|
-
*
|
|
511
|
+
* 获取格式化的用量报告
|
|
463
512
|
*/
|
|
464
|
-
|
|
513
|
+
getReport(): string;
|
|
465
514
|
/**
|
|
466
|
-
*
|
|
467
|
-
* @param name 数据源名称
|
|
468
|
-
* @param template 模板字符串
|
|
469
|
-
* @param context 渲染上下文
|
|
470
|
-
* @returns 渲染后的字符串
|
|
515
|
+
* 创建快照(用于序列化)
|
|
471
516
|
*/
|
|
472
|
-
|
|
517
|
+
toSnapshot(): UsageStatsSnapshot;
|
|
473
518
|
/**
|
|
474
|
-
*
|
|
519
|
+
* 从快照恢复
|
|
475
520
|
*/
|
|
476
|
-
|
|
521
|
+
fromSnapshot(snapshot: UsageStatsSnapshot): void;
|
|
522
|
+
/**
|
|
523
|
+
* 重置统计(谨慎使用)
|
|
524
|
+
*/
|
|
525
|
+
reset(): void;
|
|
477
526
|
}
|
|
527
|
+
|
|
478
528
|
/**
|
|
479
|
-
*
|
|
480
|
-
* 简化常见数据源的注册
|
|
529
|
+
* 上下文查询构建器
|
|
481
530
|
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* DataSourceRegistry.register(createListRenderer({
|
|
485
|
-
* name: 'tasks',
|
|
486
|
-
* getData: (ctx) => ctx.tasks as Task[],
|
|
487
|
-
* // 默认 renderItem 会将 item 合并到 context 中
|
|
488
|
-
* }));
|
|
489
|
-
* ```
|
|
531
|
+
* 提供链式 API 用于过滤和聚合消息
|
|
532
|
+
* 从 ContextFeature 移植到内核,作为 Context 的原生能力
|
|
490
533
|
*/
|
|
491
|
-
declare function createListRenderer<T = any>(config: Omit<DataSourceRenderer<T>, 'renderItem'> & {
|
|
492
|
-
/** 自定义渲染函数(可选) */
|
|
493
|
-
renderItem?: DataSourceRenderer<T>['renderItem'];
|
|
494
|
-
/** 是否合并 item 到 context(默认 true) */
|
|
495
|
-
mergeItem?: boolean;
|
|
496
|
-
}): DataSourceRenderer<T>;
|
|
497
534
|
|
|
498
535
|
/**
|
|
499
|
-
*
|
|
500
|
-
*/
|
|
501
|
-
type ToolContextValue = Record<string, unknown>;
|
|
502
|
-
/**
|
|
503
|
-
* Feature 上下文注入器
|
|
504
|
-
* 返回要注入到 tool.execute() 的额外参数
|
|
505
|
-
*/
|
|
506
|
-
type ContextInjector = (call: ToolCall) => ToolContextValue;
|
|
507
|
-
/**
|
|
508
|
-
* Feature 初始化上下文
|
|
509
|
-
*/
|
|
510
|
-
interface FeatureInitContext {
|
|
511
|
-
/** Agent ID */
|
|
512
|
-
agentId: string;
|
|
513
|
-
/** Agent 配置 */
|
|
514
|
-
config: AgentConfig;
|
|
515
|
-
/** Feature 级结构化日志 */
|
|
516
|
-
logger: Logger;
|
|
517
|
-
/** Feature 特定配置 */
|
|
518
|
-
featureConfig?: unknown;
|
|
519
|
-
/** 获取其他 Feature */
|
|
520
|
-
getFeature<T extends AgentFeature>(name: string): T | undefined;
|
|
521
|
-
/** 注册工具 */
|
|
522
|
-
registerTool(tool: Tool): void;
|
|
523
|
-
/** Agent 级数据源注册表(per-Agent 实例,非进程全局) */
|
|
524
|
-
dataSourceRegistry: DataSourceRegistry;
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Feature 运行时上下文
|
|
528
|
-
*/
|
|
529
|
-
interface FeatureContext {
|
|
530
|
-
agentId: string;
|
|
531
|
-
config: AgentConfig;
|
|
532
|
-
getFeature<T extends AgentFeature>(name: string): T | undefined;
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Feature 快照状态
|
|
536
|
-
*
|
|
537
|
-
* 第一阶段只支持显式白名单状态:
|
|
538
|
-
* - Feature 自己决定要保存什么
|
|
539
|
-
* - 未声明的状态一律不保证恢复
|
|
540
|
-
*/
|
|
541
|
-
type FeatureStateSnapshot = unknown;
|
|
542
|
-
/**
|
|
543
|
-
* 包信息
|
|
544
|
-
*/
|
|
545
|
-
interface PackageInfo {
|
|
546
|
-
/** 包名,如 '@agentdevjs/shell-feature' 或 'agentdev' */
|
|
547
|
-
name: string;
|
|
548
|
-
/** 版本号(可选) */
|
|
549
|
-
version?: string;
|
|
550
|
-
/** 包根目录绝对路径 */
|
|
551
|
-
root: string;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Feature Manifest 配置项
|
|
555
|
-
*
|
|
556
|
-
* 用于声明 Feature 在 Agent Project 级别可配置的静态参数。
|
|
557
|
-
* Claw 等消费端可根据该契约自动渲染表单。
|
|
558
|
-
*/
|
|
559
|
-
interface FeatureManifestSettingProperty {
|
|
560
|
-
type: 'string' | 'number' | 'boolean' | 'select' | 'file' | 'directory' | 'group';
|
|
561
|
-
title: string;
|
|
562
|
-
description?: string;
|
|
563
|
-
default?: unknown;
|
|
564
|
-
options?: Array<{
|
|
565
|
-
label: string;
|
|
566
|
-
value: string | number | boolean;
|
|
567
|
-
}>;
|
|
568
|
-
placeholder?: string;
|
|
569
|
-
/** number 类型下的最小值 */
|
|
570
|
-
min?: number;
|
|
571
|
-
/** number 类型下的最大值 */
|
|
572
|
-
max?: number;
|
|
573
|
-
/** number 类型下的步进值 */
|
|
574
|
-
step?: number;
|
|
575
|
-
/** file 类型下的可接受文件类型,如 '.mp3,.wav' 或 'audio/*' */
|
|
576
|
-
accept?: string | string[];
|
|
577
|
-
/** directory 类型下的最大条目数 */
|
|
578
|
-
maxItems?: number;
|
|
579
|
-
/** type: 'group' 时的嵌套子属性 */
|
|
580
|
-
properties?: Record<string, FeatureManifestSettingProperty>;
|
|
581
|
-
/** 条件可见性:仅当同级指定属性值在 values 中时渲染此字段 */
|
|
582
|
-
showWhen?: {
|
|
583
|
-
property: string;
|
|
584
|
-
values: (string | number | boolean)[];
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
interface FeatureManifestDefinition {
|
|
588
|
-
schemaVersion: 1;
|
|
589
|
-
settings?: {
|
|
590
|
-
properties: Record<string, FeatureManifestSettingProperty>;
|
|
591
|
-
/** 有序分区,用于 UI 分组渲染。省略则平铺全部属性 */
|
|
592
|
-
sections?: Array<{
|
|
593
|
-
id: string;
|
|
594
|
-
title: string;
|
|
595
|
-
description?: string;
|
|
596
|
-
/** 分区内属性 key 的显示顺序 */
|
|
597
|
-
properties: string[];
|
|
598
|
-
}>;
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Agent Feature 接口
|
|
536
|
+
* 上下文查询构建器
|
|
603
537
|
*
|
|
604
|
-
*
|
|
538
|
+
* 提供链式 API 用于过滤和聚合消息
|
|
605
539
|
*/
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
540
|
+
declare class ContextQuery {
|
|
541
|
+
private messages;
|
|
542
|
+
private indexes;
|
|
543
|
+
constructor(messages: EnrichedMessage[], indexes: Map<string, Set<string>>);
|
|
544
|
+
private result;
|
|
609
545
|
/**
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
* 声明位置在类的静态属性上(实例字段无法装配时静态读取):
|
|
613
|
-
* ```typescript
|
|
614
|
-
* class MyFeature implements AgentFeature {
|
|
615
|
-
* name = 'my-feature';
|
|
616
|
-
* static inject = ['storage'];
|
|
617
|
-
* }
|
|
618
|
-
* ```
|
|
619
|
-
* 读取与校验见 feature-graph.ts(readInjectDeclarations / resolveFeatureOrder)。
|
|
546
|
+
* 按角色过滤
|
|
620
547
|
*/
|
|
548
|
+
byRole(...roles: string[]): this;
|
|
621
549
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* 既是调试器展示的源码位置,也是框架自动发现 Feature 自带资源的唯一锚点。
|
|
625
|
-
*
|
|
626
|
-
* 约定:Feature 的所有静态资源放在 source 文件的同级目录下。
|
|
627
|
-
* 框架会自动扫描 `dirname(source)/skills/` 发现内置 skill 并注入系统提示词。
|
|
628
|
-
* 其他资源(图片、模板等)由 Feature 代码通过 import.meta.url 自行解析。
|
|
629
|
-
*
|
|
630
|
-
* 标准写法(由 create-feature 脚手架自动生成):
|
|
631
|
-
* ```typescript
|
|
632
|
-
* readonly source = fileURLToPath(import.meta.url).replace(/\\/g, '/');
|
|
633
|
-
* ```
|
|
550
|
+
* 按标签过滤(可组合)
|
|
634
551
|
*/
|
|
635
|
-
|
|
636
|
-
/** 可选:用于调试器展示的 Feature 描述 */
|
|
637
|
-
readonly description?: string;
|
|
552
|
+
byTag(...tags: MessageTag[]): this;
|
|
638
553
|
/**
|
|
639
|
-
*
|
|
554
|
+
* 按工具名过滤(使用索引加速)
|
|
640
555
|
*/
|
|
641
|
-
|
|
556
|
+
byTool(name: string): this;
|
|
642
557
|
/**
|
|
643
|
-
*
|
|
558
|
+
* 按任务 ID 过滤(使用索引加速)
|
|
644
559
|
*/
|
|
645
|
-
|
|
560
|
+
byTask(taskId: string): this;
|
|
646
561
|
/**
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
* 返回 Feature 所在的包信息(包名、版本、根目录)
|
|
650
|
-
* 用于统一模板路径解析和包管理
|
|
651
|
-
*
|
|
652
|
-
* @returns 包信息,如果 Feature 不属于任何包则返回 null
|
|
653
|
-
*
|
|
654
|
-
* @example
|
|
655
|
-
* ```typescript
|
|
656
|
-
* getPackageInfo(): PackageInfo | null {
|
|
657
|
-
* return {
|
|
658
|
-
* name: '@agentdevjs/shell-feature',
|
|
659
|
-
* version: '1.0.0',
|
|
660
|
-
* root: '/path/to/package/root'
|
|
661
|
-
* };
|
|
662
|
-
* }
|
|
663
|
-
* ```
|
|
562
|
+
* 按子代理 ID 过滤
|
|
664
563
|
*/
|
|
665
|
-
|
|
564
|
+
byAgentId(agentId: string): this;
|
|
666
565
|
/**
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
* 返回 Feature 提供的模板名称列表(不含扩展名)
|
|
670
|
-
* 模板文件必须位于 {packageRoot}/dist/templates/{templateName}.render.js
|
|
671
|
-
*
|
|
672
|
-
* @returns 模板名称数组
|
|
673
|
-
*
|
|
674
|
-
* @example
|
|
675
|
-
* ```typescript
|
|
676
|
-
* getTemplateNames(): string[] {
|
|
677
|
-
* return ['bash', 'trash-delete', 'trash-list'];
|
|
678
|
-
* }
|
|
679
|
-
* ```
|
|
566
|
+
* 按时间起点过滤
|
|
680
567
|
*/
|
|
681
|
-
|
|
568
|
+
since(timestamp: number): this;
|
|
682
569
|
/**
|
|
683
|
-
*
|
|
684
|
-
* 直接返回模板对象,无需文件路径
|
|
685
|
-
*
|
|
686
|
-
* @example
|
|
687
|
-
* ```typescript
|
|
688
|
-
* getRenderTemplates(): Record<string, InlineRenderTemplate> {
|
|
689
|
-
* return {
|
|
690
|
-
* 'bash': {
|
|
691
|
-
* call: (args) => `<div class="bash-command">> ${escapeHtml(args.command)}</div>`,
|
|
692
|
-
* result: (data, success) => success
|
|
693
|
-
* ? `<pre class="bash-output">${escapeHtml(data)}</pre>`
|
|
694
|
-
* : `<div class="tool-error">${escapeHtml(data)}</div>`
|
|
695
|
-
* }
|
|
696
|
-
* };
|
|
697
|
-
* }
|
|
698
|
-
* ```
|
|
570
|
+
* 按轮次范围过滤
|
|
699
571
|
*/
|
|
700
|
-
|
|
572
|
+
inTurns(from: number, to?: number): this;
|
|
701
573
|
/**
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
* 该契约回答“这个 Feature 平时怎么工作”,
|
|
705
|
-
* 与 Flow 节点中的 Mode(什么时候、以什么状态工作)是正交的。
|
|
574
|
+
* content 包含指定文本
|
|
706
575
|
*/
|
|
707
|
-
|
|
576
|
+
containing(text: string): this;
|
|
708
577
|
/**
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
* 命令以 `featureName.commandName` 在注册表内平面寻址,两类消费入口:
|
|
712
|
-
* - 用户命令菜单:宿主下发清单时按 entryPoints 含 'slash' 过滤
|
|
713
|
-
* - 其他 Feature:进程内 invokeCapability,entryPoint 为 'feature';
|
|
714
|
-
* 宿主前端转发的用户触发同样经注册表,entryPoint 为 'slash'。
|
|
715
|
-
* entryPoints 是契约约束(不匹配返回 entry_point_denied),不是安全边界。
|
|
578
|
+
* 最近 N 条
|
|
716
579
|
*/
|
|
717
|
-
|
|
580
|
+
recent(n: number): this;
|
|
718
581
|
/**
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
* 激活通知(capability refs 数组)作为用户输入的结构化元数据随消息
|
|
722
|
-
* 本体流动:新 call 开始时(onCall 第三参)与 busy 排队消息的步边界
|
|
723
|
-
* 注入时(react-loop drain)两个消息落地点,Agent 会按 ref 归属分组
|
|
724
|
-
* 调用对应 feature 的本方法。refs 是完整引用(`featureName.commandName`),
|
|
725
|
-
* feature 只需处理自己前缀的条目。
|
|
726
|
-
*
|
|
727
|
-
* 这是 prompt 型命令(skill 等)的唯一消费口——不解析输入文本,
|
|
728
|
-
* 不维护跨消息的 pending 状态。
|
|
582
|
+
* 执行查询,返回结果数组
|
|
729
583
|
*/
|
|
730
|
-
|
|
731
|
-
context: Context;
|
|
732
|
-
}): Promise<void>;
|
|
584
|
+
exec(): EnrichedMessage[];
|
|
733
585
|
/**
|
|
734
|
-
*
|
|
586
|
+
* 获取第一条
|
|
735
587
|
*/
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* 初始化钩子
|
|
739
|
-
*/
|
|
740
|
-
onInitiate?(ctx: FeatureInitContext): Promise<void>;
|
|
741
|
-
/**
|
|
742
|
-
* 清理钩子
|
|
743
|
-
*/
|
|
744
|
-
onDestroy?(ctx: FeatureContext): Promise<void>;
|
|
745
|
-
/**
|
|
746
|
-
* LLM 变更时调用(可选)
|
|
747
|
-
*
|
|
748
|
-
* Feature 可在此重新绑定对 LLM 的引用、更新阈值等。
|
|
749
|
-
* 该钩子在 Agent.setLLM() 中被同步调用,且仅在 onCall 间隙执行。
|
|
750
|
-
*/
|
|
751
|
-
onLLMSwap?(newLLM: LLMClient, oldLLM: LLMClient): void;
|
|
752
|
-
/**
|
|
753
|
-
* 捕获可回滚的 Feature 状态
|
|
754
|
-
*
|
|
755
|
-
* 仅返回显式声明、可序列化的状态。
|
|
756
|
-
* 未返回的字段不会参与 rollback。
|
|
757
|
-
*/
|
|
758
|
-
captureState?(): FeatureStateSnapshot;
|
|
588
|
+
first(): EnrichedMessage | undefined;
|
|
759
589
|
/**
|
|
760
|
-
*
|
|
590
|
+
* 获取最后一条
|
|
761
591
|
*/
|
|
762
|
-
|
|
592
|
+
last(): EnrichedMessage | undefined;
|
|
763
593
|
/**
|
|
764
|
-
*
|
|
594
|
+
* 计数
|
|
765
595
|
*/
|
|
766
|
-
|
|
596
|
+
count(): number;
|
|
767
597
|
/**
|
|
768
|
-
*
|
|
598
|
+
* 时间跨度统计
|
|
769
599
|
*/
|
|
770
|
-
|
|
600
|
+
timeSpan(): {
|
|
601
|
+
start: number;
|
|
602
|
+
end: number;
|
|
603
|
+
duration: number;
|
|
604
|
+
};
|
|
771
605
|
/**
|
|
772
|
-
*
|
|
606
|
+
* 按工具分组统计
|
|
773
607
|
*/
|
|
774
|
-
|
|
608
|
+
groupByTool(): Record<string, number>;
|
|
775
609
|
}
|
|
776
|
-
/**
|
|
777
|
-
* 从 Feature 的 source 属性获取包信息
|
|
778
|
-
*
|
|
779
|
-
* 通过向上查找 package.json 文件来确定包信息
|
|
780
|
-
* 支持三种场景:
|
|
781
|
-
* 1. 框架内置 Feature:找到 AgentDev 的 package.json
|
|
782
|
-
* 2. 外部 npm 包:找到包的 package.json
|
|
783
|
-
* 3. 用户本地 Feature:找到用户项目的 package.json
|
|
784
|
-
*
|
|
785
|
-
* @param source Feature 的源文件路径(import.meta.url)
|
|
786
|
-
* @returns 包信息,如果找不到 package.json 则返回 null
|
|
787
|
-
*/
|
|
788
|
-
declare function getPackageInfoFromSource(source: string | undefined): PackageInfo | null;
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* 生命周期类型定义
|
|
792
|
-
* 定义 Agent 生命周期钩子相关的类型
|
|
793
|
-
*/
|
|
794
610
|
|
|
795
611
|
/**
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
* - 一个 Call 可能包含多个 Step
|
|
799
|
-
*
|
|
800
|
-
* Step(步骤): ReAct 循环中的单次迭代
|
|
801
|
-
* - 一次 LLM 调用 + 工具执行(如果有)
|
|
802
|
-
* - Step 是 Call 内部的执行单元
|
|
803
|
-
*
|
|
804
|
-
* Turn(轮): 从无工具调用开始,到下一次无工具调用结束的完整对话周期
|
|
805
|
-
* - 可能包含多个 Step
|
|
806
|
-
* - 用于反向钩子决策点
|
|
807
|
-
*/
|
|
808
|
-
/**
|
|
809
|
-
* 核心生命周期枚举
|
|
612
|
+
* 上下文管理器
|
|
613
|
+
* 管理消息数组,提供简单的操作方法
|
|
810
614
|
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
615
|
+
* 内核化能力:
|
|
616
|
+
* - 消息元数据包装(EnrichedMessage)
|
|
617
|
+
* - 内容解析和索引
|
|
618
|
+
* - 查询接口
|
|
813
619
|
*/
|
|
814
|
-
|
|
815
|
-
/** Agent 初始化 */
|
|
816
|
-
AgentInitiate = "AgentInitiate",
|
|
817
|
-
/** Agent 销毁 */
|
|
818
|
-
AgentDestroy = "AgentDestroy",
|
|
819
|
-
/** Call 开始 */
|
|
820
|
-
CallStart = "CallStart",
|
|
821
|
-
/** Call 结束 */
|
|
822
|
-
CallFinish = "CallFinish",
|
|
823
|
-
/** Step 开始 */
|
|
824
|
-
StepStart = "StepStart",
|
|
825
|
-
/** Step 结束 */
|
|
826
|
-
StepFinish = "StepFinish",
|
|
827
|
-
/** 工具使用前 */
|
|
828
|
-
ToolUse = "ToolUse",
|
|
829
|
-
/** 工具使用后 */
|
|
830
|
-
ToolFinished = "ToolFinished",
|
|
831
|
-
/** 工具结果变换(结果写入 context 前,可修改结果) */
|
|
832
|
-
ToolResultTransform = "ToolResultTransform"
|
|
833
|
-
}
|
|
620
|
+
|
|
834
621
|
/**
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
* 用于控制执行流程的三个状态
|
|
622
|
+
* 工具执行结果(用于 addToolMessage)
|
|
838
623
|
*/
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
624
|
+
interface ToolExecResult {
|
|
625
|
+
success: boolean;
|
|
626
|
+
result: string | Record<string, any>;
|
|
627
|
+
error?: string;
|
|
628
|
+
/**
|
|
629
|
+
* 终止标注(ticket 023 / ADR-0005):工具被超时/用户打断终止但仍在 settle
|
|
630
|
+
* 窗口内收尾时,结果以 success: true 返回并携带此字段。
|
|
631
|
+
* reason: 'timeout'(框架统一超时)| 'user'(外部用户中断)。
|
|
632
|
+
*/
|
|
633
|
+
interrupted?: {
|
|
634
|
+
reason: ToolTerminationReason;
|
|
635
|
+
};
|
|
636
|
+
/** 工具返回的图片(注入到 tool 消息,视觉模式下传给 LLM) */
|
|
637
|
+
images?: ImageInput[];
|
|
638
|
+
/** 前端展示数据(不注入 LLM,仅 tool 消息) */
|
|
639
|
+
display?: unknown;
|
|
846
640
|
}
|
|
847
641
|
/**
|
|
848
|
-
*
|
|
849
|
-
*/
|
|
850
|
-
type DecisionResult = Decision | {
|
|
851
|
-
/** 决策动作 */
|
|
852
|
-
action: Decision;
|
|
853
|
-
/** 拒绝原因(用于日志/调试) */
|
|
854
|
-
reason?: string;
|
|
855
|
-
/** 附加元数据 */
|
|
856
|
-
metadata?: Record<string, any>;
|
|
857
|
-
};
|
|
858
|
-
/**
|
|
859
|
-
* 将 DecisionResult 转换为标准 Decision
|
|
860
|
-
*/
|
|
861
|
-
declare function normalizeDecision(result: DecisionResult): Decision;
|
|
862
|
-
/**
|
|
863
|
-
* Agent 初始化上下文
|
|
642
|
+
* 上下文快照类型 - 用于序列化
|
|
864
643
|
*/
|
|
865
|
-
interface
|
|
866
|
-
|
|
867
|
-
|
|
644
|
+
interface ContextSnapshot {
|
|
645
|
+
version: number;
|
|
646
|
+
messages: Message[];
|
|
647
|
+
enrichedMessages?: EnrichedMessage[];
|
|
648
|
+
sequence?: number;
|
|
649
|
+
generation?: number;
|
|
650
|
+
/** 截断归档(tombstone)。旧快照可能没有该字段,加载时视为空归档。 */
|
|
651
|
+
tombstones?: ContextTombstoneEntry[];
|
|
868
652
|
}
|
|
869
653
|
/**
|
|
870
|
-
*
|
|
654
|
+
* Context 边界快照 — 用于增量 rollback。
|
|
655
|
+
*
|
|
656
|
+
* 记录某个时间点两个数组的长度、sequence 和 generation,
|
|
657
|
+
* 截断时只需按长度切片即可恢复到该边界。
|
|
658
|
+
*
|
|
659
|
+
* generation 用于防止 ABA 问题:如果 Context 经历了
|
|
660
|
+
* clear/apply/restore 等非追加 mutation,generation 会递增,
|
|
661
|
+
* 旧 boundary 会被拒绝。
|
|
871
662
|
*/
|
|
872
|
-
interface
|
|
873
|
-
|
|
874
|
-
|
|
663
|
+
interface ContextBoundaryV2 {
|
|
664
|
+
messagesLength: number;
|
|
665
|
+
enrichedMessagesLength: number;
|
|
666
|
+
sequence: number;
|
|
667
|
+
generation: number;
|
|
875
668
|
}
|
|
876
669
|
/**
|
|
877
|
-
*
|
|
670
|
+
* Tombstone 摘要 — 轻量元数据,不含消息内容。
|
|
878
671
|
*/
|
|
879
|
-
interface
|
|
880
|
-
/**
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
|
|
884
|
-
/**
|
|
885
|
-
|
|
886
|
-
/**
|
|
887
|
-
|
|
672
|
+
interface ContextTombstoneSummary {
|
|
673
|
+
/** 单调递增的 tombstone ID(同一 Context 实例内唯一) */
|
|
674
|
+
id: number;
|
|
675
|
+
/** 截断恢复到的边界 */
|
|
676
|
+
boundary: ContextBoundaryV2;
|
|
677
|
+
/** 被截断的消息条数 */
|
|
678
|
+
removedMessageCount: number;
|
|
679
|
+
/** 截断发生时间(ISO 字符串) */
|
|
680
|
+
truncatedAt: string;
|
|
888
681
|
}
|
|
889
682
|
/**
|
|
890
|
-
*
|
|
891
|
-
* 不复用模型厂商的 stop reason,也不推断宿主任务的业务状态。
|
|
892
|
-
*/
|
|
893
|
-
type ExecutionStatus = 'completed' | 'failed' | 'cancelled' | 'continued';
|
|
894
|
-
/**
|
|
895
|
-
* 执行终止的框架级原因。
|
|
683
|
+
* Tombstone 完整条目 — 含被截断的消息内容。
|
|
896
684
|
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
|
|
900
|
-
type ExecutionReason = 'completed' | 'cancelled' | 'limit_reached' | 'continued' | 'error';
|
|
901
|
-
/** 可序列化的错误事实。category 是稳定的机器分类,message 只供展示。 */
|
|
902
|
-
interface ExecutionError {
|
|
903
|
-
category: string;
|
|
904
|
-
message: string;
|
|
905
|
-
code?: string;
|
|
906
|
-
statusCode?: number;
|
|
907
|
-
retryable?: boolean;
|
|
908
|
-
}
|
|
909
|
-
/** 单次模型请求的来源信息;不决定 Call 的终态。 */
|
|
910
|
-
interface ModelRequestOutcome {
|
|
911
|
-
providerStopReason?: string | null;
|
|
912
|
-
}
|
|
913
|
-
/**
|
|
914
|
-
* 一次 Agent Call(而非宿主任务)的结构化终态。
|
|
915
|
-
* 该对象可安全持久化、跨进程传输和用于 JSONL/CLI 消费。
|
|
685
|
+
* rollback 截断不再物理丢失内容:被截尾部进入 tombstone 归档,
|
|
686
|
+
* 可查询(listTombstones / getTombstone),在 Context 仍处于该边界时
|
|
687
|
+
* 可完整恢复(restoreTombstone)。
|
|
916
688
|
*/
|
|
917
|
-
interface
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
response: string;
|
|
921
|
-
steps: number;
|
|
922
|
-
startedAt: number;
|
|
923
|
-
finishedAt: number;
|
|
924
|
-
error?: ExecutionError;
|
|
925
|
-
model?: ModelRequestOutcome;
|
|
689
|
+
interface ContextTombstoneEntry extends ContextTombstoneSummary {
|
|
690
|
+
removedMessages: Message[];
|
|
691
|
+
removedEnrichedMessages: EnrichedMessage[];
|
|
926
692
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
693
|
+
declare class Context {
|
|
694
|
+
private messages;
|
|
695
|
+
private enrichedMessages;
|
|
696
|
+
private indexes;
|
|
697
|
+
private sequence;
|
|
698
|
+
/**
|
|
699
|
+
* Lineage generation,用于检测非追加 mutation。
|
|
700
|
+
*
|
|
701
|
+
* - 纯追加 typed message(addUserMessage 等):不变
|
|
702
|
+
* - rollback 的合法截断(truncateToBoundary):不变
|
|
703
|
+
* - clear / apply:递增
|
|
704
|
+
* - restore:使用 snapshot 携带的 generation,否则递增
|
|
705
|
+
*/
|
|
706
|
+
private generation;
|
|
707
|
+
/**
|
|
708
|
+
* 截断归档(tombstone)。append-only:clear/apply/restore 不清空,
|
|
709
|
+
* 只有 restore(snapshot) 采用快照携带的归档。
|
|
710
|
+
*/
|
|
711
|
+
private tombstones;
|
|
712
|
+
private tombstoneSeq;
|
|
713
|
+
/**
|
|
714
|
+
* 添加一条消息
|
|
715
|
+
*/
|
|
716
|
+
add(message: Message): this;
|
|
717
|
+
/**
|
|
718
|
+
* 添加多条消息
|
|
719
|
+
*/
|
|
720
|
+
addAll(messages: Message[]): this;
|
|
721
|
+
/**
|
|
722
|
+
* 获取所有消息的副本
|
|
723
|
+
*/
|
|
724
|
+
getAll(): Message[];
|
|
725
|
+
/**
|
|
726
|
+
* 获取消息数量
|
|
727
|
+
*/
|
|
728
|
+
get length(): number;
|
|
729
|
+
/**
|
|
730
|
+
* 获取最后一条消息
|
|
731
|
+
*/
|
|
732
|
+
getLast(): Message | undefined;
|
|
733
|
+
/**
|
|
734
|
+
* 清空消息
|
|
735
|
+
*/
|
|
736
|
+
clear(): void;
|
|
737
|
+
/**
|
|
738
|
+
* 应用中间件处理消息
|
|
739
|
+
*/
|
|
740
|
+
apply(middleware: (messages: Message[]) => Message[]): this;
|
|
741
|
+
/**
|
|
742
|
+
* 过滤消息
|
|
743
|
+
*/
|
|
744
|
+
filter(predicate: (msg: Message) => boolean): Message[];
|
|
745
|
+
/**
|
|
746
|
+
* 切片
|
|
747
|
+
*/
|
|
748
|
+
slice(start?: number, end?: number): Message[];
|
|
749
|
+
/**
|
|
750
|
+
* 序列化为快照
|
|
751
|
+
*/
|
|
752
|
+
toJSON(): ContextSnapshot;
|
|
753
|
+
/**
|
|
754
|
+
* 从快照恢复
|
|
755
|
+
*/
|
|
756
|
+
static fromJSON(snapshot: ContextSnapshot): Context;
|
|
757
|
+
/**
|
|
758
|
+
* 用快照原地恢复当前 Context
|
|
759
|
+
*/
|
|
760
|
+
restore(snapshot: ContextSnapshot): this;
|
|
761
|
+
/**
|
|
762
|
+
* 序列化为 JSON 字符串
|
|
763
|
+
*/
|
|
764
|
+
serialize(): string;
|
|
765
|
+
/**
|
|
766
|
+
* 从 JSON 字符串反序列化
|
|
767
|
+
*/
|
|
768
|
+
static deserialize(json: string): Context;
|
|
769
|
+
/**
|
|
770
|
+
* 统一消息入口(内部方法)
|
|
771
|
+
*/
|
|
772
|
+
private addMessage;
|
|
773
|
+
/**
|
|
774
|
+
* 添加用户消息
|
|
775
|
+
*/
|
|
776
|
+
addUserMessage(content: string, turn: number, images?: ImageInput[]): void;
|
|
777
|
+
/**
|
|
778
|
+
* 添加助手响应
|
|
779
|
+
*
|
|
780
|
+
* 框架合成消息(错误/截断说明)可通过 execution 字段附带执行终态元数据。
|
|
781
|
+
*/
|
|
782
|
+
addAssistantMessage(response: LLMResponse & {
|
|
783
|
+
execution?: MessageExecutionMeta;
|
|
784
|
+
}, turn: number): void;
|
|
785
|
+
/**
|
|
786
|
+
* 添加工具结果
|
|
787
|
+
*/
|
|
788
|
+
addToolMessage(call: ToolCall, result: ToolExecResult, turn: number): void;
|
|
789
|
+
/**
|
|
790
|
+
* 添加已经序列化的工具消息。
|
|
791
|
+
*
|
|
792
|
+
* 用于 session/handoff 恢复等边界:原始 tool content 已经是 provider 可重放的
|
|
793
|
+
* 序列化字符串,不应先解析成 ToolExecResult 再重新编码。该入口同时维护
|
|
794
|
+
* messages[] 与 enrichedMessages[],并保留工具返回的图片附件。
|
|
795
|
+
*/
|
|
796
|
+
addSerializedToolMessage(toolCallId: string, content: string, turn: number, images?: ImageInput[], display?: unknown): void;
|
|
797
|
+
/**
|
|
798
|
+
* 添加系统消息
|
|
799
|
+
*/
|
|
800
|
+
addSystemMessage(content: string, turn: number, source?: string, tag?: string): void;
|
|
801
|
+
/**
|
|
802
|
+
* 查询构建器
|
|
803
|
+
*/
|
|
804
|
+
query(): ContextQuery;
|
|
805
|
+
/**
|
|
806
|
+
* 按轮次获取消息
|
|
807
|
+
*/
|
|
808
|
+
getByTurn(turn: number): EnrichedMessage[];
|
|
809
|
+
/**
|
|
810
|
+
* 获取最近 N 条消息
|
|
811
|
+
*/
|
|
812
|
+
getRecent(n: number): EnrichedMessage[];
|
|
813
|
+
/**
|
|
814
|
+
* 获取所有丰富化消息(内部使用)
|
|
815
|
+
*/
|
|
816
|
+
getAllEnriched(): EnrichedMessage[];
|
|
817
|
+
/**
|
|
818
|
+
* 丰富化消息:添加元数据
|
|
819
|
+
*/
|
|
820
|
+
private enrich;
|
|
821
|
+
/**
|
|
822
|
+
* 推断消息标签
|
|
823
|
+
*/
|
|
824
|
+
private inferTags;
|
|
825
|
+
/**
|
|
826
|
+
* 解析 content 提取结构化信息
|
|
827
|
+
*/
|
|
828
|
+
private parseContent;
|
|
829
|
+
/**
|
|
830
|
+
* 更新索引
|
|
831
|
+
*/
|
|
832
|
+
private updateIndexes;
|
|
833
|
+
/**
|
|
834
|
+
* 从 enrichedMessages 重建索引
|
|
835
|
+
*/
|
|
836
|
+
private rebuildIndexes;
|
|
837
|
+
/**
|
|
838
|
+
* 生成唯一 ID
|
|
839
|
+
*/
|
|
840
|
+
private generateId;
|
|
841
|
+
/**
|
|
842
|
+
* 捕获当前 Context 的前缀边界。
|
|
843
|
+
*
|
|
844
|
+
* 返回一个轻量快照,记录两个数组的长度、sequence 和 generation。
|
|
845
|
+
* 后续可传给 truncateToBoundary() 恢复到此边界。
|
|
846
|
+
*
|
|
847
|
+
* generation 不变:纯读取操作。
|
|
848
|
+
*/
|
|
849
|
+
captureBoundary(): ContextBoundaryV2;
|
|
850
|
+
/**
|
|
851
|
+
* 校验 boundary 是否与当前 Context 兼容。
|
|
852
|
+
*
|
|
853
|
+
* @throws 如果 generation 不匹配、长度非法或超出当前数组。
|
|
854
|
+
*/
|
|
855
|
+
private assertBoundaryCompatible;
|
|
856
|
+
/**
|
|
857
|
+
* 将两个数组截断到指定边界。
|
|
858
|
+
*
|
|
859
|
+
* 这是合法的 rollback 操作:generation 保持不变,
|
|
860
|
+
* 截断后同一 lineage 的旧 boundary 仍然可以继续使用。
|
|
861
|
+
*
|
|
862
|
+
* 被截尾部进入 tombstone 归档(不物理丢失):
|
|
863
|
+
* 通过 listTombstones() / getTombstone() 查询,
|
|
864
|
+
* Context 仍处于该边界时可通过 restoreTombstone() 完整恢复。
|
|
865
|
+
*
|
|
866
|
+
* @throws 如果 boundary 与当前 Context 不兼容(generation 不匹配或长度越界)。
|
|
867
|
+
*/
|
|
868
|
+
truncateToBoundary(boundary: ContextBoundaryV2): void;
|
|
869
|
+
/**
|
|
870
|
+
* 列出 tombstone 摘要(不含消息内容)。
|
|
871
|
+
*/
|
|
872
|
+
listTombstones(): ContextTombstoneSummary[];
|
|
873
|
+
/**
|
|
874
|
+
* 按 ID 取回 tombstone 完整内容(深拷贝,修改返回值不影响归档)。
|
|
875
|
+
*/
|
|
876
|
+
getTombstone(id: number): ContextTombstoneEntry | undefined;
|
|
877
|
+
/**
|
|
878
|
+
* 从 tombstone 恢复被截尾部。
|
|
879
|
+
*
|
|
880
|
+
* 仅当 Context 仍精确处于该 tombstone 的边界时允许
|
|
881
|
+
* (generation、两个数组长度、sequence 全部匹配)——此时恢复是
|
|
882
|
+
* 截断的精确逆操作,不破坏 lineage。
|
|
883
|
+
*
|
|
884
|
+
* 恢复后 sequence 续接被截尾部的最大序号,generation 不变。
|
|
885
|
+
*
|
|
886
|
+
* @throws 如果 Context 已离开该边界(例如截断后追加了新消息)。
|
|
887
|
+
* 此时内容仍可通过 getTombstone() 提取,由调用方决定如何重组。
|
|
888
|
+
*/
|
|
889
|
+
restoreTombstone(id: number): void;
|
|
947
890
|
}
|
|
891
|
+
|
|
948
892
|
/**
|
|
949
|
-
*
|
|
893
|
+
* Capability System - 统一能力控制面(P1:command)
|
|
950
894
|
*
|
|
951
|
-
*
|
|
895
|
+
* Feature 通过 getCapabilities() 声明可被显式调用的命令,注册表提供
|
|
896
|
+
* 平面寻址(`featureName.commandName`)与三动词中的 invoke 语义。
|
|
897
|
+
*
|
|
898
|
+
* 设计裁决(详见 AgentDevClaw docs/adr capability-registry-as-control-plane):
|
|
899
|
+
* - 命令式优先:只有 invoke / query / emit,不存在 bind / reactive / watch。
|
|
900
|
+
* 共享权威状态与跨 feature 事务是负面清单,不做。
|
|
901
|
+
* - entryPoints 是契约约束而非安全边界:声明不含请求入口的 command 被
|
|
902
|
+
* invoke 时返回 entry_point_denied(结构化错误,非静默失败)。绕过
|
|
903
|
+
* 路径(getFeature 直引)依旧存在,这是已知边界而非漏洞。
|
|
904
|
+
* - 进程内语义:args 是普通 JS 值,不为序列化设计。跨进程投递是宿主层
|
|
905
|
+
* 职责,注册表不为其建模。
|
|
906
|
+
* - 注册表是哑的:不做参数校验(schema 服务于消费端渲染表单)、不含
|
|
907
|
+
* 派发策略、不管依赖管理。
|
|
908
|
+
* - 命令超时即失败:超时返回 timeout,但执行体可能仍在进行(Promise
|
|
909
|
+
* 无法取消),不保证中断,只保证调用方不挂死。
|
|
952
910
|
*/
|
|
953
|
-
|
|
954
|
-
/** 当前步骤序号(从 0 开始) */
|
|
955
|
-
step: number;
|
|
956
|
-
/** 当前调用序号(用户交互次数,从 0 开始) */
|
|
957
|
-
callIndex: number;
|
|
958
|
-
/** 消息上下文 */
|
|
959
|
-
context: Context;
|
|
960
|
-
/** 原始用户输入 */
|
|
961
|
-
input: string;
|
|
962
|
-
/** Agent 实例(用于访问当前会话中的 Feature、工具和输入状态) */
|
|
963
|
-
agent?: any;
|
|
964
|
-
}
|
|
911
|
+
|
|
965
912
|
/**
|
|
966
|
-
*
|
|
913
|
+
* 能力入口类型
|
|
914
|
+
*
|
|
915
|
+
* - 'slash':出现在用户命令菜单(宿主下发清单时过滤)
|
|
916
|
+
* - 'feature':可被其他 feature(或经宿主转发的等价调用)invoke
|
|
967
917
|
*/
|
|
968
|
-
|
|
969
|
-
/** LLM 响应 */
|
|
970
|
-
llmResponse: LLMResponse;
|
|
971
|
-
/** 执行的工具调用数量 */
|
|
972
|
-
toolCallsCount: number;
|
|
973
|
-
}
|
|
918
|
+
type CapabilityEntryPoint = 'slash' | 'feature';
|
|
974
919
|
/**
|
|
975
|
-
*
|
|
920
|
+
* 命令类型。框架层仅定义形状并透传——两种 kind 在框架眼里同质
|
|
921
|
+
* (收到 invoke 一律执行 execute);行为差异(表单/pill/toast/触发
|
|
922
|
+
* 时机)由应用层(宿主前端)按 kind 消费。
|
|
976
923
|
*
|
|
977
|
-
*
|
|
924
|
+
* - invoke(缺省):选中即执行的触发型命令(配置开关等)
|
|
925
|
+
* - prompt:调用指令以文本形式嵌入输入的命令(skill 等),
|
|
926
|
+
* 应用层负责其呈现与发送时机,feature 在自身生命周期内消费
|
|
978
927
|
*/
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
/**
|
|
985
|
-
|
|
986
|
-
/**
|
|
987
|
-
|
|
988
|
-
/**
|
|
989
|
-
|
|
990
|
-
/**
|
|
991
|
-
|
|
928
|
+
type CapabilityKind = 'invoke' | 'prompt';
|
|
929
|
+
/**
|
|
930
|
+
* Feature 声明的可调用命令
|
|
931
|
+
*/
|
|
932
|
+
interface CapabilityDefinition {
|
|
933
|
+
/** 命令名(标识符),注册表内以 `featureName.commandName` 寻址 */
|
|
934
|
+
name: string;
|
|
935
|
+
/** 命令类型,缺省 'invoke'。框架透传不解释,语义由应用层消费 */
|
|
936
|
+
kind?: CapabilityKind;
|
|
937
|
+
/** 菜单显示标题,缺省用 name */
|
|
938
|
+
title?: string;
|
|
939
|
+
/** 菜单描述 */
|
|
940
|
+
description?: string;
|
|
941
|
+
/**
|
|
942
|
+
* 参数 schema,复用 FeatureManifestSettingProperty 词汇表,
|
|
943
|
+
* 与 feature-setup 配置表单、flow 交互选项共用一套渲染基底。
|
|
944
|
+
*/
|
|
945
|
+
parameters?: Record<string, FeatureManifestSettingProperty>;
|
|
946
|
+
/**
|
|
947
|
+
* 可见入口,缺省 ['feature'](最小暴露)。
|
|
948
|
+
* 进 slash 菜单必须是显式主动行为。
|
|
949
|
+
*/
|
|
950
|
+
entryPoints?: CapabilityEntryPoint[];
|
|
951
|
+
/**
|
|
952
|
+
* 参数当前生效值(配置回显):参数表单打开时优先于 parameters 的
|
|
953
|
+
* default 显示。返回普通对象,键与 parameters 对齐;缺省或抛错
|
|
954
|
+
* 时表单回退 default。读取必须无副作用。
|
|
955
|
+
*/
|
|
956
|
+
readCurrentValues?: () => Record<string, unknown>;
|
|
957
|
+
/** 执行体。抛出的任何错误归一为 execute_failed */
|
|
958
|
+
execute(args: Record<string, unknown>, ctx: CapabilityContext): Promise<unknown>;
|
|
992
959
|
}
|
|
993
960
|
/**
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
* 提供工具执行后的完整结果信息
|
|
961
|
+
* 命令执行上下文(进程内)
|
|
997
962
|
*/
|
|
998
|
-
interface
|
|
999
|
-
|
|
1000
|
-
success: boolean;
|
|
1001
|
-
/** 经过 ToolResultTransform 后、实际写入模型上下文的最终结果。 */
|
|
1002
|
-
delivered?: ToolExecResult;
|
|
1003
|
-
/** 返回数据 */
|
|
1004
|
-
data: unknown;
|
|
1005
|
-
/** 错误信息(如果失败) */
|
|
1006
|
-
error?: string;
|
|
1007
|
-
/** 执行耗时(ms) */
|
|
1008
|
-
duration: number;
|
|
1009
|
-
/** 工具调用 */
|
|
1010
|
-
call: ToolCall;
|
|
1011
|
-
/** 工具定义 */
|
|
1012
|
-
tool: Tool;
|
|
1013
|
-
/** 当前步骤序号 */
|
|
1014
|
-
step: number;
|
|
1015
|
-
/** 用户输入 */
|
|
1016
|
-
input: string;
|
|
1017
|
-
/** 消息上下文 */
|
|
1018
|
-
context: Context;
|
|
1019
|
-
/** 获取其他 Feature */
|
|
963
|
+
interface CapabilityContext {
|
|
964
|
+
agentId: string;
|
|
1020
965
|
getFeature<T extends AgentFeature>(name: string): T | undefined;
|
|
966
|
+
logger: Logger;
|
|
1021
967
|
}
|
|
1022
968
|
/**
|
|
1023
|
-
*
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
* -
|
|
1028
|
-
* - { action: 'allow' }: 允许工具执行(工具级)
|
|
1029
|
-
* - undefined: 默认行为
|
|
969
|
+
* invoke 的结构化结果。错误码是稳定契约:
|
|
970
|
+
* - not_found:ref 未注册
|
|
971
|
+
* - entry_point_denied:该入口不在 entryPoints 中
|
|
972
|
+
* - execute_failed:执行体抛错
|
|
973
|
+
* - timeout:超过时限(执行体不保证被取消)
|
|
1030
974
|
*/
|
|
1031
|
-
type
|
|
1032
|
-
|
|
1033
|
-
|
|
975
|
+
type CapabilityInvokeResult = {
|
|
976
|
+
ok: true;
|
|
977
|
+
result: unknown;
|
|
1034
978
|
} | {
|
|
1035
|
-
|
|
1036
|
-
|
|
979
|
+
ok: false;
|
|
980
|
+
code: 'not_found' | 'entry_point_denied' | 'execute_failed' | 'timeout';
|
|
981
|
+
message: string;
|
|
982
|
+
};
|
|
1037
983
|
/**
|
|
1038
|
-
*
|
|
984
|
+
* 清单快照条目(下发宿主 / 前端菜单消费的数据形态,纯数据)
|
|
1039
985
|
*/
|
|
1040
|
-
|
|
986
|
+
interface CapabilitySnapshot {
|
|
987
|
+
feature: string;
|
|
988
|
+
name: string;
|
|
989
|
+
ref: string;
|
|
990
|
+
/** 命令类型(缺省 'invoke'),透传给应用层消费 */
|
|
991
|
+
kind: CapabilityKind;
|
|
992
|
+
title: string;
|
|
993
|
+
description?: string;
|
|
994
|
+
parameters?: Record<string, FeatureManifestSettingProperty>;
|
|
995
|
+
entryPoints: CapabilityEntryPoint[];
|
|
996
|
+
/** 参数当前生效值(readCurrentValues 收集;读取失败时缺省) */
|
|
997
|
+
currentValues?: Record<string, unknown>;
|
|
998
|
+
}
|
|
1041
999
|
/**
|
|
1042
|
-
*
|
|
1000
|
+
* 能力注册表(per-Agent 实例)
|
|
1043
1001
|
*/
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1002
|
+
declare class CapabilityRegistry {
|
|
1003
|
+
private defs;
|
|
1004
|
+
/**
|
|
1005
|
+
* 注册 feature 的命令。ref(`feature.name`)重复视为装配错误,直接抛出,
|
|
1006
|
+
* 对齐 feature-graph 的报错哲学。
|
|
1007
|
+
*/
|
|
1008
|
+
register(featureName: string, def: CapabilityDefinition): void;
|
|
1009
|
+
has(ref: string): boolean;
|
|
1010
|
+
/** ref → 所属 feature 名(dispatchTurnActivations 按 owner 分组派发用) */
|
|
1011
|
+
ownerOf(ref: string): string | null;
|
|
1012
|
+
/** ref → 命令类型(缺省 'invoke');未注册返回 null */
|
|
1013
|
+
kindOf(ref: string): CapabilityKind | null;
|
|
1014
|
+
/**
|
|
1015
|
+
* 移除指定 feature 的全部命令(幂等)。
|
|
1016
|
+
* initSingleFeature 重挂路径先调它,避免热载时误报 duplicate ref。
|
|
1017
|
+
*/
|
|
1018
|
+
unregisterFeature(featureName: string): void;
|
|
1019
|
+
/**
|
|
1020
|
+
* 清单快照。传入 entryPoint 时过滤出该入口可见的命令
|
|
1021
|
+
* (宿主下发 slash 菜单清单时用 { entryPoint: 'slash' })。
|
|
1022
|
+
*/
|
|
1023
|
+
list(filter?: {
|
|
1024
|
+
entryPoint?: CapabilityEntryPoint;
|
|
1025
|
+
}): CapabilitySnapshot[];
|
|
1026
|
+
/**
|
|
1027
|
+
* 调用命令。entryPoint 必填——调用方声明自己以哪个入口进来,
|
|
1028
|
+
* 注册表据此执行 entryPoints 契约检查。
|
|
1029
|
+
*/
|
|
1030
|
+
invoke(ref: string, opts: {
|
|
1031
|
+
args?: Record<string, unknown>;
|
|
1032
|
+
entryPoint: CapabilityEntryPoint;
|
|
1033
|
+
timeoutMs?: number;
|
|
1034
|
+
}, ctx: CapabilityContext): Promise<CapabilityInvokeResult>;
|
|
1053
1035
|
}
|
|
1036
|
+
|
|
1054
1037
|
/**
|
|
1055
|
-
*
|
|
1038
|
+
* Feature System - 可外挂功能模块接口
|
|
1039
|
+
*
|
|
1040
|
+
* Feature 系统允许将功能(MCP、Skills、子代理等)从 Agent 核心中解耦,
|
|
1041
|
+
* 实现新功能的声明式注册和统一的生命周期管理。
|
|
1056
1042
|
*/
|
|
1057
|
-
|
|
1058
|
-
/** 子代理 ID */
|
|
1059
|
-
agentId: string;
|
|
1060
|
-
/** 子代理类型 */
|
|
1061
|
-
type: string;
|
|
1062
|
-
/** 旧状态 */
|
|
1063
|
-
oldStatus: SubAgentStatus;
|
|
1064
|
-
/** 新状态 */
|
|
1065
|
-
newStatus: SubAgentStatus;
|
|
1066
|
-
/** 执行结果(完成时) */
|
|
1067
|
-
result?: string;
|
|
1068
|
-
/** 错误信息(失败时) */
|
|
1069
|
-
error?: string;
|
|
1070
|
-
}
|
|
1043
|
+
|
|
1071
1044
|
/**
|
|
1072
|
-
*
|
|
1045
|
+
* Feature 上下文值类型
|
|
1073
1046
|
*/
|
|
1074
|
-
|
|
1075
|
-
/** 子代理 ID */
|
|
1076
|
-
agentId: string;
|
|
1077
|
-
/** 子代理类型 */
|
|
1078
|
-
type: string;
|
|
1079
|
-
/** 销毁原因 */
|
|
1080
|
-
reason: 'manual' | 'parent_dispose' | 'error';
|
|
1081
|
-
}
|
|
1047
|
+
type ToolContextValue = Record<string, unknown>;
|
|
1082
1048
|
/**
|
|
1083
|
-
*
|
|
1049
|
+
* Feature 上下文注入器
|
|
1050
|
+
* 返回要注入到 tool.execute() 的额外参数
|
|
1084
1051
|
*/
|
|
1085
|
-
|
|
1086
|
-
/** 中断原因 */
|
|
1087
|
-
reason: 'limit_reached' | 'error' | 'cancelled';
|
|
1088
|
-
/** 当前步骤序号 */
|
|
1089
|
-
step: number;
|
|
1090
|
-
/** 当前消息上下文 */
|
|
1091
|
-
context: Context;
|
|
1092
|
-
}
|
|
1052
|
+
type ContextInjector = (call: ToolCall) => ToolContextValue;
|
|
1093
1053
|
/**
|
|
1094
|
-
*
|
|
1054
|
+
* Feature 初始化上下文
|
|
1095
1055
|
*/
|
|
1096
|
-
interface
|
|
1097
|
-
/**
|
|
1056
|
+
interface FeatureInitContext {
|
|
1057
|
+
/** Agent ID */
|
|
1098
1058
|
agentId: string;
|
|
1099
|
-
/**
|
|
1100
|
-
|
|
1101
|
-
/**
|
|
1102
|
-
|
|
1103
|
-
/**
|
|
1104
|
-
|
|
1059
|
+
/** Agent 配置 */
|
|
1060
|
+
config: AgentConfig;
|
|
1061
|
+
/** Feature 级结构化日志 */
|
|
1062
|
+
logger: Logger;
|
|
1063
|
+
/** Feature 特定配置 */
|
|
1064
|
+
featureConfig?: unknown;
|
|
1065
|
+
/** 获取其他 Feature */
|
|
1066
|
+
getFeature<T extends AgentFeature>(name: string): T | undefined;
|
|
1067
|
+
/** 注册工具 */
|
|
1068
|
+
registerTool(tool: Tool): void;
|
|
1069
|
+
/** Agent 级数据源注册表(per-Agent 实例,非进程全局) */
|
|
1070
|
+
dataSourceRegistry: DataSourceRegistry;
|
|
1105
1071
|
}
|
|
1106
1072
|
/**
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1109
|
-
* 用于在 Step 结束后进行流程控制决策
|
|
1073
|
+
* Feature 运行时上下文
|
|
1110
1074
|
*/
|
|
1111
|
-
interface
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
hasPendingMessages?: boolean;
|
|
1116
|
-
/** 是否调用了 wait 工具 */
|
|
1117
|
-
waitCalled?: boolean;
|
|
1075
|
+
interface FeatureContext {
|
|
1076
|
+
agentId: string;
|
|
1077
|
+
config: AgentConfig;
|
|
1078
|
+
getFeature<T extends AgentFeature>(name: string): T | undefined;
|
|
1118
1079
|
}
|
|
1119
1080
|
/**
|
|
1120
|
-
*
|
|
1081
|
+
* Feature 快照状态
|
|
1121
1082
|
*
|
|
1122
|
-
*
|
|
1083
|
+
* 第一阶段只支持显式白名单状态:
|
|
1084
|
+
* - Feature 自己决定要保存什么
|
|
1085
|
+
* - 未声明的状态一律不保证恢复
|
|
1123
1086
|
*/
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1087
|
+
type FeatureStateSnapshot = unknown;
|
|
1088
|
+
/**
|
|
1089
|
+
* 包信息
|
|
1090
|
+
*/
|
|
1091
|
+
interface PackageInfo {
|
|
1092
|
+
/** 包名,如 '@agentdevjs/shell-feature' 或 'agentdev' */
|
|
1093
|
+
name: string;
|
|
1094
|
+
/** 版本号(可选) */
|
|
1095
|
+
version?: string;
|
|
1096
|
+
/** 包根目录绝对路径 */
|
|
1097
|
+
root: string;
|
|
1127
1098
|
}
|
|
1128
1099
|
/**
|
|
1129
|
-
*
|
|
1100
|
+
* Feature Manifest 配置项
|
|
1130
1101
|
*
|
|
1131
|
-
*
|
|
1132
|
-
*
|
|
1133
|
-
*
|
|
1134
|
-
* 钩子返回 undefined 表示不修改;返回 ToolExecResult 表示用新结果替换。
|
|
1135
|
-
* 多个钩子按注册顺序链式执行,前一个钩子的输出作为后一个钩子的输入。
|
|
1136
|
-
*/
|
|
1137
|
-
interface ToolResultTransformContext {
|
|
1138
|
-
/** 工具名称 */
|
|
1139
|
-
toolName: string;
|
|
1140
|
-
/** 工具调用 */
|
|
1141
|
-
call: ToolCall;
|
|
1142
|
-
/** 当前结果(可能已被前一个变换钩子修改) */
|
|
1143
|
-
result: ToolExecResult;
|
|
1144
|
-
/** 当前步骤序号 */
|
|
1145
|
-
step: number;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
* Continuation Request 类型定义
|
|
1150
|
-
*
|
|
1151
|
-
* 控制工具(如 checkpoint、rollback)通过 registerContinuationRequest()
|
|
1152
|
-
* 登记一个 continuation request,使当前 onCall 在合法边界停止。
|
|
1153
|
-
* 宿主(如 CallArbiter)通过 consumeContinuationRequest() 消费该请求,
|
|
1154
|
-
* 决定是否在同一个逻辑 envelope 内启动下一个 onCall segment。
|
|
1155
|
-
*/
|
|
1156
|
-
/**
|
|
1157
|
-
* Checkpoint continuation request
|
|
1158
|
-
*
|
|
1159
|
-
* Agent 建立了一个命名检查点,希望继续执行。
|
|
1160
|
-
* 宿主应捕获当前 runtime snapshot 并将其与 checkpointId 关联,
|
|
1161
|
-
* 然后启动 continuation segment。
|
|
1102
|
+
* 用于声明 Feature 在 Agent Project 级别可配置的静态参数。
|
|
1103
|
+
* Claw 等消费端可根据该契约自动渲染表单。
|
|
1162
1104
|
*/
|
|
1163
|
-
interface
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1105
|
+
interface FeatureManifestSettingProperty {
|
|
1106
|
+
type: 'string' | 'number' | 'boolean' | 'select' | 'file' | 'directory' | 'group';
|
|
1107
|
+
title: string;
|
|
1108
|
+
description?: string;
|
|
1109
|
+
default?: unknown;
|
|
1110
|
+
options?: Array<{
|
|
1111
|
+
label: string;
|
|
1112
|
+
value: string | number | boolean;
|
|
1113
|
+
}>;
|
|
1114
|
+
placeholder?: string;
|
|
1115
|
+
/** number 类型下的最小值 */
|
|
1116
|
+
min?: number;
|
|
1117
|
+
/** number 类型下的最大值 */
|
|
1118
|
+
max?: number;
|
|
1119
|
+
/** number 类型下的步进值 */
|
|
1120
|
+
step?: number;
|
|
1121
|
+
/** file 类型下的可接受文件类型,如 '.mp3,.wav' 或 'audio/*' */
|
|
1122
|
+
accept?: string | string[];
|
|
1123
|
+
/** directory 类型下的最大条目数 */
|
|
1124
|
+
maxItems?: number;
|
|
1125
|
+
/** type: 'group' 时的嵌套子属性 */
|
|
1126
|
+
properties?: Record<string, FeatureManifestSettingProperty>;
|
|
1127
|
+
/** 条件可见性:仅当同级指定属性值在 values 中时渲染此字段 */
|
|
1128
|
+
showWhen?: {
|
|
1129
|
+
property: string;
|
|
1130
|
+
values: (string | number | boolean)[];
|
|
1131
|
+
};
|
|
1132
|
+
/**
|
|
1133
|
+
* select 类型下的动态选项来源:options 由宿主在渲染时提供(活数据,
|
|
1134
|
+
* 无法静态枚举),options 字段省略。当前定义 'model-presets' =
|
|
1135
|
+
* 宿主模型 preset 清单。静态 options 存在时本字段被忽略。
|
|
1136
|
+
*/
|
|
1137
|
+
dynamicOptions?: 'model-presets';
|
|
1168
1138
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1139
|
+
interface FeatureManifestDefinition {
|
|
1140
|
+
schemaVersion: 1;
|
|
1141
|
+
settings?: {
|
|
1142
|
+
properties: Record<string, FeatureManifestSettingProperty>;
|
|
1143
|
+
/** 有序分区,用于 UI 分组渲染。省略则平铺全部属性 */
|
|
1144
|
+
sections?: Array<{
|
|
1145
|
+
id: string;
|
|
1146
|
+
title: string;
|
|
1147
|
+
description?: string;
|
|
1148
|
+
/** 分区内属性 key 的显示顺序 */
|
|
1149
|
+
properties: string[];
|
|
1150
|
+
}>;
|
|
1151
|
+
};
|
|
1181
1152
|
}
|
|
1182
1153
|
/**
|
|
1183
|
-
*
|
|
1184
|
-
*/
|
|
1185
|
-
type CallContinuationRequest = CheckpointContinuationRequest | RollbackContinuationRequest;
|
|
1186
|
-
|
|
1187
|
-
/**
|
|
1188
|
-
* UsageStats - 用量统计系统
|
|
1189
|
-
*
|
|
1190
|
-
* 职责:
|
|
1191
|
-
* - 记录 LLM 调用的 token 用量
|
|
1192
|
-
* - 聚合 session/call/step 三级统计
|
|
1193
|
-
* - 提供快照序列化和恢复
|
|
1194
|
-
* - 格式化用量报告
|
|
1154
|
+
* Agent Feature 接口
|
|
1195
1155
|
*
|
|
1196
|
-
*
|
|
1197
|
-
* - 框架内置,不是 Feature
|
|
1198
|
-
* - 自动收集,不需要手动干预
|
|
1199
|
-
* - 快照包含 session 级数据,用于会话恢复
|
|
1200
|
-
*/
|
|
1201
|
-
/**
|
|
1202
|
-
* 统一用量格式(兼容 Anthropic 和 OpenAI)
|
|
1203
|
-
*/
|
|
1204
|
-
interface UsageInfo {
|
|
1205
|
-
/** 输入 token 数 */
|
|
1206
|
-
inputTokens: number;
|
|
1207
|
-
/** 输出 token 数 */
|
|
1208
|
-
outputTokens: number;
|
|
1209
|
-
/** 总 token 数 */
|
|
1210
|
-
totalTokens: number;
|
|
1211
|
-
/** 创建缓存消耗的 token 数 */
|
|
1212
|
-
cacheCreationTokens?: number;
|
|
1213
|
-
/** 从缓存读取的 token 数 */
|
|
1214
|
-
cacheReadTokens?: number;
|
|
1215
|
-
/** 推理 token 数(prompt_tokens_details 或 completion_tokens_details) */
|
|
1216
|
-
reasoningTokens?: number;
|
|
1217
|
-
/** 音频 token 数 */
|
|
1218
|
-
audioTokens?: number;
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* 单次 Call 用量汇总
|
|
1222
|
-
*/
|
|
1223
|
-
interface CallUsageSummary {
|
|
1224
|
-
callIndex: number;
|
|
1225
|
-
totalUsage: UsageInfo;
|
|
1226
|
-
stepCount: number;
|
|
1227
|
-
cacheHitRequests: number;
|
|
1228
|
-
startTime: number;
|
|
1229
|
-
endTime?: number;
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Session 用量快照(用于序列化)
|
|
1233
|
-
*/
|
|
1234
|
-
interface UsageStatsSnapshot {
|
|
1235
|
-
/** Session 级累计用量 */
|
|
1236
|
-
totalUsage: UsageInfo;
|
|
1237
|
-
/** 各 Call 的用量汇总 */
|
|
1238
|
-
calls: CallUsageSummary[];
|
|
1239
|
-
/** 总请求数(LLM 调用次数) */
|
|
1240
|
-
totalRequests: number;
|
|
1241
|
-
/** 命中缓存的请求数(request-level) */
|
|
1242
|
-
totalCacheHitRequests: number;
|
|
1243
|
-
/** 最后一次请求的用量(用于显示当前上下文占用) */
|
|
1244
|
-
lastRequestUsage?: UsageInfo;
|
|
1245
|
-
}
|
|
1246
|
-
/**
|
|
1247
|
-
* 用量统计类
|
|
1156
|
+
* 可外挂的功能模块,提供工具和上下文注入
|
|
1248
1157
|
*/
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
|
|
1252
|
-
/** 当前活跃 Call 的用量记录 */
|
|
1253
|
-
private currentCallUsage;
|
|
1254
|
-
/** 总 LLM 调用次数 */
|
|
1255
|
-
private totalRequests;
|
|
1256
|
-
/** 命中缓存的总请求数 */
|
|
1257
|
-
private totalCacheHitRequests;
|
|
1258
|
-
/** 当前 Call 的 Step 记录(临时,用于聚合) */
|
|
1259
|
-
private currentStepRecords;
|
|
1260
|
-
/** 最后一次 LLM 调用的用量(用于显示当前上下文占用) */
|
|
1261
|
-
private lastRequestUsage;
|
|
1262
|
-
/**
|
|
1263
|
-
* 记录一次 LLM 调用的用量
|
|
1264
|
-
* @param callIndex Call 序号
|
|
1265
|
-
* @param step Step 序号
|
|
1266
|
-
* @param usage 用量数据
|
|
1267
|
-
*/
|
|
1268
|
-
record(callIndex: number, step: number, usage: UsageInfo): void;
|
|
1158
|
+
interface AgentFeature {
|
|
1159
|
+
/** Feature 名称 */
|
|
1160
|
+
readonly name: string;
|
|
1269
1161
|
/**
|
|
1270
|
-
*
|
|
1271
|
-
*
|
|
1162
|
+
* 依赖的其他 Feature(装配时拓扑排序,工作项 A3)。
|
|
1163
|
+
*
|
|
1164
|
+
* 声明位置在类的静态属性上(实例字段无法装配时静态读取):
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* class MyFeature implements AgentFeature {
|
|
1167
|
+
* name = 'my-feature';
|
|
1168
|
+
* static inject = ['storage'];
|
|
1169
|
+
* }
|
|
1170
|
+
* ```
|
|
1171
|
+
* 读取与校验见 feature-graph.ts(readInjectDeclarations / resolveFeatureOrder)。
|
|
1272
1172
|
*/
|
|
1273
|
-
endCall(callIndex: number): void;
|
|
1274
1173
|
/**
|
|
1275
|
-
*
|
|
1174
|
+
* Feature 源文件路径(import.meta.url)。
|
|
1175
|
+
*
|
|
1176
|
+
* 既是调试器展示的源码位置,也是框架自动发现 Feature 自带资源的唯一锚点。
|
|
1177
|
+
*
|
|
1178
|
+
* 约定:Feature 的所有静态资源放在 source 文件的同级目录下。
|
|
1179
|
+
* 框架会自动扫描 `dirname(source)/skills/` 发现内置 skill 并注入系统提示词。
|
|
1180
|
+
* 其他资源(图片、模板等)由 Feature 代码通过 import.meta.url 自行解析。
|
|
1181
|
+
*
|
|
1182
|
+
* 标准写法(由 create-feature 脚手架自动生成):
|
|
1183
|
+
* ```typescript
|
|
1184
|
+
* readonly source = fileURLToPath(import.meta.url).replace(/\\/g, '/');
|
|
1185
|
+
* ```
|
|
1276
1186
|
*/
|
|
1277
|
-
|
|
1187
|
+
readonly source?: string;
|
|
1188
|
+
/** 可选:用于调试器展示的 Feature 描述 */
|
|
1189
|
+
readonly description?: string;
|
|
1278
1190
|
/**
|
|
1279
|
-
*
|
|
1280
|
-
* @param callIndex Call 序号
|
|
1191
|
+
* 获取同步工具(已知工具列表)
|
|
1281
1192
|
*/
|
|
1282
|
-
|
|
1193
|
+
getTools?(): Tool[];
|
|
1283
1194
|
/**
|
|
1284
|
-
*
|
|
1195
|
+
* 获取异步工具(需要连接、发现等)
|
|
1285
1196
|
*/
|
|
1286
|
-
|
|
1197
|
+
getAsyncTools?(ctx: FeatureInitContext): Promise<Tool[]>;
|
|
1287
1198
|
/**
|
|
1288
|
-
*
|
|
1199
|
+
* 获取包信息
|
|
1200
|
+
*
|
|
1201
|
+
* 返回 Feature 所在的包信息(包名、版本、根目录)
|
|
1202
|
+
* 用于统一模板路径解析和包管理
|
|
1203
|
+
*
|
|
1204
|
+
* @returns 包信息,如果 Feature 不属于任何包则返回 null
|
|
1205
|
+
*
|
|
1206
|
+
* @example
|
|
1207
|
+
* ```typescript
|
|
1208
|
+
* getPackageInfo(): PackageInfo | null {
|
|
1209
|
+
* return {
|
|
1210
|
+
* name: '@agentdevjs/shell-feature',
|
|
1211
|
+
* version: '1.0.0',
|
|
1212
|
+
* root: '/path/to/package/root'
|
|
1213
|
+
* };
|
|
1214
|
+
* }
|
|
1215
|
+
* ```
|
|
1289
1216
|
*/
|
|
1290
|
-
|
|
1291
|
-
getTotalCacheHitRequests(): number;
|
|
1217
|
+
getPackageInfo?(): PackageInfo | null;
|
|
1292
1218
|
/**
|
|
1293
|
-
*
|
|
1219
|
+
* 获取模板名称列表
|
|
1220
|
+
*
|
|
1221
|
+
* 返回 Feature 提供的模板名称列表(不含扩展名)
|
|
1222
|
+
* 模板文件必须位于 {packageRoot}/dist/templates/{templateName}.render.js
|
|
1223
|
+
*
|
|
1224
|
+
* @returns 模板名称数组
|
|
1225
|
+
*
|
|
1226
|
+
* @example
|
|
1227
|
+
* ```typescript
|
|
1228
|
+
* getTemplateNames(): string[] {
|
|
1229
|
+
* return ['bash', 'trash-delete', 'trash-list'];
|
|
1230
|
+
* }
|
|
1231
|
+
* ```
|
|
1294
1232
|
*/
|
|
1295
|
-
|
|
1233
|
+
getTemplateNames?(): string[];
|
|
1296
1234
|
/**
|
|
1297
|
-
*
|
|
1298
|
-
|
|
1299
|
-
|
|
1235
|
+
* 声明渲染模板(推荐方式)
|
|
1236
|
+
* 直接返回模板对象,无需文件路径
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```typescript
|
|
1240
|
+
* getRenderTemplates(): Record<string, InlineRenderTemplate> {
|
|
1241
|
+
* return {
|
|
1242
|
+
* 'bash': {
|
|
1243
|
+
* call: (args) => `<div class="bash-command">> ${escapeHtml(args.command)}</div>`,
|
|
1244
|
+
* result: (data, success) => success
|
|
1245
|
+
* ? `<pre class="bash-output">${escapeHtml(data)}</pre>`
|
|
1246
|
+
* : `<div class="tool-error">${escapeHtml(data)}</div>`
|
|
1247
|
+
* }
|
|
1248
|
+
* };
|
|
1249
|
+
* }
|
|
1250
|
+
* ```
|
|
1251
|
+
*/
|
|
1252
|
+
getRenderTemplates?(): Record<string, InlineRenderTemplate>;
|
|
1300
1253
|
/**
|
|
1301
|
-
*
|
|
1254
|
+
* 声明 Feature 的项目级静态配置契约(Manifest)
|
|
1255
|
+
*
|
|
1256
|
+
* 该契约回答“这个 Feature 平时怎么工作”,
|
|
1257
|
+
* 与 Flow 节点中的 Mode(什么时候、以什么状态工作)是正交的。
|
|
1302
1258
|
*/
|
|
1303
|
-
|
|
1259
|
+
getFeatureManifest?(): FeatureManifestDefinition | null;
|
|
1304
1260
|
/**
|
|
1305
|
-
*
|
|
1261
|
+
* 声明可调用命令(Capability)
|
|
1262
|
+
*
|
|
1263
|
+
* 命令以 `featureName.commandName` 在注册表内平面寻址,两类消费入口:
|
|
1264
|
+
* - 用户命令菜单:宿主下发清单时按 entryPoints 含 'slash' 过滤
|
|
1265
|
+
* - 其他 Feature:进程内 invokeCapability,entryPoint 为 'feature';
|
|
1266
|
+
* 宿主前端转发的用户触发同样经注册表,entryPoint 为 'slash'。
|
|
1267
|
+
* entryPoints 是契约约束(不匹配返回 entry_point_denied),不是安全边界。
|
|
1306
1268
|
*/
|
|
1307
|
-
|
|
1269
|
+
getCapabilities?(): CapabilityDefinition[];
|
|
1308
1270
|
/**
|
|
1309
|
-
*
|
|
1271
|
+
* 消费"随消息到达的能力激活通知"(可选)。
|
|
1272
|
+
*
|
|
1273
|
+
* 激活通知(capability refs 数组)作为用户输入的结构化元数据随消息
|
|
1274
|
+
* 本体流动:新 call 开始时(onCall 第三参)与 busy 排队消息的步边界
|
|
1275
|
+
* 注入时(react-loop drain)两个消息落地点,Agent 会按 ref 归属分组
|
|
1276
|
+
* 调用对应 feature 的本方法。refs 是完整引用(`featureName.commandName`),
|
|
1277
|
+
* feature 只需处理自己前缀的条目。
|
|
1278
|
+
*
|
|
1279
|
+
* 这是 prompt 型命令(skill 等)的唯一消费口——不解析输入文本,
|
|
1280
|
+
* 不维护跨消息的 pending 状态。
|
|
1310
1281
|
*/
|
|
1311
|
-
|
|
1282
|
+
onCapabilityActivations?(refs: string[], ctx: {
|
|
1283
|
+
context: Context;
|
|
1284
|
+
}): Promise<void>;
|
|
1285
|
+
/**
|
|
1286
|
+
* 声明上下文注入器
|
|
1287
|
+
*/
|
|
1288
|
+
getContextInjectors?(): Map<string | RegExp, ContextInjector>;
|
|
1289
|
+
/**
|
|
1290
|
+
* 初始化钩子
|
|
1291
|
+
*/
|
|
1292
|
+
onInitiate?(ctx: FeatureInitContext): Promise<void>;
|
|
1293
|
+
/**
|
|
1294
|
+
* 清理钩子
|
|
1295
|
+
*/
|
|
1296
|
+
onDestroy?(ctx: FeatureContext): Promise<void>;
|
|
1297
|
+
/**
|
|
1298
|
+
* LLM 变更时调用(可选)
|
|
1299
|
+
*
|
|
1300
|
+
* Feature 可在此重新绑定对 LLM 的引用、更新阈值等。
|
|
1301
|
+
* 该钩子在 Agent.setLLM() 中被同步调用,且仅在 onCall 间隙执行。
|
|
1302
|
+
*/
|
|
1303
|
+
onLLMSwap?(newLLM: LLMClient, oldLLM: LLMClient): void;
|
|
1304
|
+
/**
|
|
1305
|
+
* 捕获可回滚的 Feature 状态
|
|
1306
|
+
*
|
|
1307
|
+
* 仅返回显式声明、可序列化的状态。
|
|
1308
|
+
* 未返回的字段不会参与 rollback。
|
|
1309
|
+
*/
|
|
1310
|
+
captureState?(): FeatureStateSnapshot;
|
|
1311
|
+
/**
|
|
1312
|
+
* 从快照恢复 Feature 状态
|
|
1313
|
+
*/
|
|
1314
|
+
restoreState?(snapshot: FeatureStateSnapshot): void | Promise<void>;
|
|
1315
|
+
/**
|
|
1316
|
+
* rollback 前钩子
|
|
1317
|
+
*/
|
|
1318
|
+
beforeRollback?(snapshot: FeatureStateSnapshot): void | Promise<void>;
|
|
1319
|
+
/**
|
|
1320
|
+
* rollback 后钩子
|
|
1321
|
+
*/
|
|
1322
|
+
afterRollback?(snapshot: FeatureStateSnapshot): void | Promise<void>;
|
|
1323
|
+
/**
|
|
1324
|
+
* 可选:为调试器提供 hook 的人类可读说明
|
|
1325
|
+
*/
|
|
1326
|
+
getHookDescription?(lifecycle: string, methodName: string): string | undefined;
|
|
1312
1327
|
}
|
|
1313
|
-
|
|
1314
|
-
/**
|
|
1315
|
-
* 通知分类
|
|
1316
|
-
* - state: 覆盖式更新(如 LLM 字符计数)
|
|
1317
|
-
* - event: 追加式记录(如工具开始/完成)
|
|
1318
|
-
*/
|
|
1319
|
-
type NotificationCategory = 'state' | 'event';
|
|
1320
1328
|
/**
|
|
1321
|
-
*
|
|
1329
|
+
* 从 Feature 的 source 属性获取包信息
|
|
1330
|
+
*
|
|
1331
|
+
* 通过向上查找 package.json 文件来确定包信息
|
|
1332
|
+
* 支持三种场景:
|
|
1333
|
+
* 1. 框架内置 Feature:找到 AgentDev 的 package.json
|
|
1334
|
+
* 2. 外部 npm 包:找到包的 package.json
|
|
1335
|
+
* 3. 用户本地 Feature:找到用户项目的 package.json
|
|
1336
|
+
*
|
|
1337
|
+
* @param source Feature 的源文件路径(import.meta.url)
|
|
1338
|
+
* @returns 包信息,如果找不到 package.json 则返回 null
|
|
1322
1339
|
*/
|
|
1323
|
-
|
|
1340
|
+
declare function getPackageInfoFromSource(source: string | undefined): PackageInfo | null;
|
|
1341
|
+
|
|
1324
1342
|
/**
|
|
1325
|
-
*
|
|
1343
|
+
* 生命周期类型定义
|
|
1344
|
+
* 定义 Agent 生命周期钩子相关的类型
|
|
1326
1345
|
*/
|
|
1327
|
-
|
|
1328
|
-
type: string;
|
|
1329
|
-
category: NotificationCategory;
|
|
1330
|
-
timestamp: number;
|
|
1331
|
-
data: unknown;
|
|
1332
|
-
}
|
|
1333
|
-
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
1334
|
-
type DebugLogDeliveryReason = 'hub' | 'hub-unavailable' | 'no-agent-context';
|
|
1335
|
-
interface DebugLogDelivery {
|
|
1336
|
-
hub: boolean;
|
|
1337
|
-
console: boolean;
|
|
1338
|
-
reason: DebugLogDeliveryReason;
|
|
1339
|
-
}
|
|
1340
|
-
interface LogContextRef {
|
|
1341
|
-
agentId?: string;
|
|
1342
|
-
agentName?: string;
|
|
1343
|
-
parentAgentId?: string;
|
|
1344
|
-
callIndex?: number;
|
|
1345
|
-
step?: number;
|
|
1346
|
-
toolName?: string;
|
|
1347
|
-
toolCallId?: string;
|
|
1348
|
-
feature?: string;
|
|
1349
|
-
lifecycle?: string;
|
|
1350
|
-
hookMethod?: string;
|
|
1351
|
-
hookKind?: 'forward' | 'observe' | 'guard' | 'transform';
|
|
1352
|
-
sourceFile?: string;
|
|
1353
|
-
sourceLine?: number;
|
|
1354
|
-
tags?: string[];
|
|
1355
|
-
[key: string]: unknown;
|
|
1356
|
-
}
|
|
1357
|
-
interface DebugLogEntry {
|
|
1358
|
-
id: string;
|
|
1359
|
-
timestamp: number;
|
|
1360
|
-
level: LogLevel;
|
|
1361
|
-
message: string;
|
|
1362
|
-
namespace: string;
|
|
1363
|
-
context: LogContextRef;
|
|
1364
|
-
data?: unknown;
|
|
1365
|
-
delivery: DebugLogDelivery;
|
|
1366
|
-
}
|
|
1367
|
-
type RuntimeStage = 'idle' | 'llm_thinking' | 'llm_content' | 'llm_tool_call_building' | 'awaiting_runtime' | 'tool_executing' | 'retry_waiting' | 'retry_requesting' | 'completed' | 'failed' | 'cancelled';
|
|
1346
|
+
|
|
1368
1347
|
/**
|
|
1369
|
-
*
|
|
1348
|
+
* Call(调用): 用户一次完整的输入-输出交互
|
|
1349
|
+
* - 用户输入 → Agent 处理(可能包含多个 ReAct 步骤) → 返回最终输出
|
|
1350
|
+
* - 一个 Call 可能包含多个 Step
|
|
1370
1351
|
*
|
|
1371
|
-
*
|
|
1372
|
-
* -
|
|
1352
|
+
* Step(步骤): ReAct 循环中的单次迭代
|
|
1353
|
+
* - 一次 LLM 调用 + 工具执行(如果有)
|
|
1354
|
+
* - Step 是 Call 内部的执行单元
|
|
1355
|
+
*
|
|
1356
|
+
* Turn(轮): 从无工具调用开始,到下一次无工具调用结束的完整对话周期
|
|
1357
|
+
* - 可能包含多个 Step
|
|
1358
|
+
* - 用于反向钩子决策点
|
|
1373
1359
|
*/
|
|
1374
|
-
type ToolTerminationReason = 'timeout' | 'user';
|
|
1375
|
-
interface AgentRuntimeStateSnapshot {
|
|
1376
|
-
stage: RuntimeStage;
|
|
1377
|
-
callActive: boolean;
|
|
1378
|
-
charCount: number;
|
|
1379
|
-
thinkingChars: number;
|
|
1380
|
-
contentChars: number;
|
|
1381
|
-
toolCallCount: number;
|
|
1382
|
-
activeToolNames: string[];
|
|
1383
|
-
activeToolCount: number;
|
|
1384
|
-
/** LLM 流式期间检测到的工具名称(仅 llm_tool_call_building 阶段有值) */
|
|
1385
|
-
streamToolNames?: string[];
|
|
1386
|
-
callStartedAt?: number;
|
|
1387
|
-
stageStartedAt?: number;
|
|
1388
|
-
retryAttempt?: number;
|
|
1389
|
-
maxRetries?: number;
|
|
1390
|
-
nextRetryDelayMs?: number;
|
|
1391
|
-
lastErrorType?: string | null;
|
|
1392
|
-
lastErrorMessage?: string | null;
|
|
1393
|
-
/** 最近一次已结束 Call 的结构化终态。 */
|
|
1394
|
-
lastOutcome?: CallOutcome | null;
|
|
1395
|
-
updatedAt: number;
|
|
1396
|
-
}
|
|
1397
1360
|
/**
|
|
1398
|
-
*
|
|
1361
|
+
* 核心生命周期枚举
|
|
1399
1362
|
*
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1363
|
+
* 三级结构:Agent 级 > Call 级 > Step 级 > Tool 级
|
|
1364
|
+
* 每个生命周期都有配套的正向钩子(通知)和反向钩子(决策/处理)
|
|
1402
1365
|
*/
|
|
1403
|
-
|
|
1404
|
-
/**
|
|
1405
|
-
|
|
1406
|
-
/**
|
|
1407
|
-
|
|
1408
|
-
/**
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
[key: string]: unknown;
|
|
1366
|
+
declare enum CoreLifecycle {
|
|
1367
|
+
/** Agent 初始化 */
|
|
1368
|
+
AgentInitiate = "AgentInitiate",
|
|
1369
|
+
/** Agent 销毁 */
|
|
1370
|
+
AgentDestroy = "AgentDestroy",
|
|
1371
|
+
/** Call 开始 */
|
|
1372
|
+
CallStart = "CallStart",
|
|
1373
|
+
/** Call 结束 */
|
|
1374
|
+
CallFinish = "CallFinish",
|
|
1375
|
+
/** Step 开始 */
|
|
1376
|
+
StepStart = "StepStart",
|
|
1377
|
+
/** Step 结束 */
|
|
1378
|
+
StepFinish = "StepFinish",
|
|
1379
|
+
/** 工具使用前 */
|
|
1380
|
+
ToolUse = "ToolUse",
|
|
1381
|
+
/** 工具使用后 */
|
|
1382
|
+
ToolFinished = "ToolFinished",
|
|
1383
|
+
/** 工具结果变换(结果写入 context 前,可修改结果) */
|
|
1384
|
+
ToolResultTransform = "ToolResultTransform"
|
|
1423
1385
|
}
|
|
1424
1386
|
/**
|
|
1425
|
-
*
|
|
1387
|
+
* 决策状态(反向钩子返回值)
|
|
1426
1388
|
*
|
|
1427
|
-
*
|
|
1389
|
+
* 用于控制执行流程的三个状态
|
|
1428
1390
|
*/
|
|
1429
|
-
|
|
1391
|
+
declare enum Decision {
|
|
1392
|
+
/** 批准:确认执行,跳过后续决策 */
|
|
1393
|
+
Approve = "approve",
|
|
1394
|
+
/** 拒绝:阻止执行,跳过后续决策 */
|
|
1395
|
+
Deny = "deny",
|
|
1396
|
+
/** 继续:交给下一个决策节点,使用默认行为 */
|
|
1397
|
+
Continue = "continue"
|
|
1398
|
+
}
|
|
1430
1399
|
/**
|
|
1431
|
-
*
|
|
1400
|
+
* 决策结果类型
|
|
1432
1401
|
*/
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
* @param context 执行上下文,包含框架注入的 signal、registerContinuationRequest,
|
|
1442
|
-
* 以及各 Feature 通过 contextInjectors 注入的自定义属性
|
|
1443
|
-
*/
|
|
1444
|
-
execute: (args: Record<string, unknown>, context?: ToolExecutionContext) => Promise<ToolResultValue>;
|
|
1445
|
-
/** 可选:渲染配置 */
|
|
1446
|
-
render?: ToolRenderConfig;
|
|
1447
|
-
/**
|
|
1448
|
-
* 工具执行模式
|
|
1449
|
-
* - 'normal'(默认):普通工具,可与其他工具在同一次 assistant turn 中并行调用
|
|
1450
|
-
* - 'exclusive':独占工具,必须是 assistant turn 中唯一的工具调用
|
|
1451
|
-
*
|
|
1452
|
-
* exclusive 工具适用于控制流工具(如 checkpoint、rollback),
|
|
1453
|
-
* 它们不应与其他工具产生副作用交织。
|
|
1454
|
-
*/
|
|
1455
|
-
executionMode?: 'normal' | 'exclusive';
|
|
1456
|
-
/**
|
|
1457
|
-
* 工具是否可并行执行。
|
|
1458
|
-
*
|
|
1459
|
-
* - true: 该工具可以与同批次中其他 parallelizable 工具并发执行
|
|
1460
|
-
* - false/undefined: 串行执行(默认,向后兼容)
|
|
1461
|
-
*
|
|
1462
|
-
* 约束:
|
|
1463
|
-
* - exclusive 工具忽略此属性(exclusive 总是独占批次)
|
|
1464
|
-
* - 标记为 parallelizable 的工具应是无副作用的只读操作,
|
|
1465
|
-
* 或其副作用不会与同批次其他工具冲突
|
|
1466
|
-
*/
|
|
1467
|
-
parallelizable?: boolean;
|
|
1468
|
-
/**
|
|
1469
|
-
* 超时契约声明(ticket 023 / ADR-0005)。
|
|
1470
|
-
*
|
|
1471
|
-
* 声明后由框架执行器统一计时:超时触发合并 AbortSignal(reason=timeout),
|
|
1472
|
-
* 并给工具一个 settle 窗口优雅收尾;未声明的工具不受框架超时管辖,行为不变。
|
|
1473
|
-
*
|
|
1474
|
-
* - defaultMs: 默认超时(模型未通过 fromArg 参数覆盖时生效)
|
|
1475
|
-
* - maxMs: 生效超时的硬上限,任何来源的超时值都会被 clamp 到 [1, maxMs]
|
|
1476
|
-
* - fromArg: 可选参数名;声明后生效超时取 args[fromArg](数字),再 clamp
|
|
1477
|
-
*/
|
|
1478
|
-
timeout?: {
|
|
1479
|
-
defaultMs: number;
|
|
1480
|
-
maxMs: number;
|
|
1481
|
-
fromArg?: string;
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
interface AgentLogsResponse {
|
|
1485
|
-
scope: 'current' | 'all';
|
|
1486
|
-
selectedAgentId: string | null;
|
|
1487
|
-
total: number;
|
|
1488
|
-
logs: DebugLogEntry[];
|
|
1489
|
-
truncation?: {
|
|
1490
|
-
truncated: boolean;
|
|
1491
|
-
appliedLimit?: number;
|
|
1492
|
-
returnedCount: number;
|
|
1493
|
-
availableCount: number;
|
|
1494
|
-
nextOffset?: number;
|
|
1495
|
-
reason?: string;
|
|
1496
|
-
guidance?: string;
|
|
1497
|
-
};
|
|
1498
|
-
collectionPolicy: {
|
|
1499
|
-
hubConnected: boolean;
|
|
1500
|
-
includesOnlyHubDeliveredLogs: boolean;
|
|
1501
|
-
fallbackBehavior: string;
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
type MessageRole = 'system' | 'user' | 'assistant' | 'tool' | string;
|
|
1402
|
+
type DecisionResult = Decision | {
|
|
1403
|
+
/** 决策动作 */
|
|
1404
|
+
action: Decision;
|
|
1405
|
+
/** 拒绝原因(用于日志/调试) */
|
|
1406
|
+
reason?: string;
|
|
1407
|
+
/** 附加元数据 */
|
|
1408
|
+
metadata?: Record<string, any>;
|
|
1409
|
+
};
|
|
1505
1410
|
/**
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
* 支持两种数据来源:
|
|
1509
|
-
* - `path`:图片已落盘到本地文件,编译 LLM 请求时按需读取为 base64(推荐)
|
|
1510
|
-
* - `base64`:内联 base64 数据(向后兼容旧会话)
|
|
1511
|
-
*
|
|
1512
|
-
* 优先使用 `path`;`base64` 仅作为旧会话兼容或无法落盘时的回退。
|
|
1513
|
-
* - 视觉模式(vision: true):从 path 或 base64 读取图片数据传给 LLM API
|
|
1514
|
-
* - 非视觉模式(vision: false):source 用于生成文字占位符
|
|
1411
|
+
* 将 DecisionResult 转换为标准 Decision
|
|
1515
1412
|
*/
|
|
1516
|
-
|
|
1517
|
-
/** 本地文件绝对路径(推荐方式,避免 session 膨胀) */
|
|
1518
|
-
path?: string;
|
|
1519
|
-
/** Base64 编码的图片数据(不含 data URI 前缀),向后兼容 */
|
|
1520
|
-
base64?: string;
|
|
1521
|
-
/** MIME 类型,如 'image/png'、'image/jpeg' */
|
|
1522
|
-
mediaType?: string;
|
|
1523
|
-
/** 来源描述或原始文件名(用于非视觉模式的文字占位符显示) */
|
|
1524
|
-
source?: string;
|
|
1525
|
-
}
|
|
1526
|
-
interface Message {
|
|
1527
|
-
role: MessageRole;
|
|
1528
|
-
content: string;
|
|
1529
|
-
turn?: number;
|
|
1530
|
-
toolCallId?: string;
|
|
1531
|
-
toolCalls?: ToolCall[];
|
|
1532
|
-
reasoning?: string;
|
|
1533
|
-
thinkingBlocks?: ThinkingBlock[];
|
|
1534
|
-
/** 图片附件(user 消息:用户输入的图片;tool 消息:工具返回的图片),多模态输入 */
|
|
1535
|
-
images?: ImageInput[];
|
|
1536
|
-
/**
|
|
1537
|
-
* 前端展示数据(仅 tool 消息)。
|
|
1538
|
-
*
|
|
1539
|
-
* 当工具使用 withDisplay() 分离返回时,display 携带富数据(如 diff),
|
|
1540
|
-
* 仅供前端渲染,不注入 LLM 上下文。LLM 只看到 content 中的精简文本。
|
|
1541
|
-
*/
|
|
1542
|
-
display?: unknown;
|
|
1543
|
-
/**
|
|
1544
|
-
* 消息来源标记(仅 system 消息使用)。
|
|
1545
|
-
*
|
|
1546
|
-
* - undefined:agent 自身的系统提示词(由 templateResolver 生成),
|
|
1547
|
-
* Anthropic provider 将其放入顶层 system 参数。
|
|
1548
|
-
* - 有值(如 'handoff-seed'、'partial-compact'):Feature 注入的 system 消息,
|
|
1549
|
-
* Anthropic provider 将其包裹为 <reminder> 嵌入最近的 user turn,
|
|
1550
|
-
* 而非混入顶层 system 参数。
|
|
1551
|
-
*/
|
|
1552
|
-
source?: string;
|
|
1553
|
-
/**
|
|
1554
|
-
* 消息语义标签(所有 role 通用)。
|
|
1555
|
-
*
|
|
1556
|
-
* 与 source 的区别:
|
|
1557
|
-
* - source 控制 LLM 编译层行为(顶层 system vs reminder)
|
|
1558
|
-
* - tag 控制上下文管理层行为(trim/compact 时的保留策略)
|
|
1559
|
-
*
|
|
1560
|
-
* undefined = 无标签,向后兼容,行为与当前完全一致。
|
|
1561
|
-
*/
|
|
1562
|
-
tag?: string;
|
|
1563
|
-
/**
|
|
1564
|
-
* LLM 用量信息(仅 assistant 消息有值)。
|
|
1565
|
-
*
|
|
1566
|
-
* 由 LLM provider 在生成响应时返回,表示生成此消息时的上下文 token 开销。
|
|
1567
|
-
* inputTokens 是发送给 LLM 的完整上下文大小(包含所有历史消息),
|
|
1568
|
-
* 不是单条消息的 token 数。
|
|
1569
|
-
*/
|
|
1570
|
-
usage?: MessageUsage;
|
|
1571
|
-
/**
|
|
1572
|
-
* 执行终态元数据(仅 assistant 消息有值)。
|
|
1573
|
-
*
|
|
1574
|
-
* 框架在写入错误/截断等执行结果消息时盖戳。展示端(Web UI / 查看器)
|
|
1575
|
-
* 应依据此字段渲染终态样式,而不是解析 content 文本前缀;该字段随
|
|
1576
|
-
* 会话快照持久化,重渲染后保持稳定。
|
|
1577
|
-
*/
|
|
1578
|
-
execution?: MessageExecutionMeta;
|
|
1579
|
-
}
|
|
1413
|
+
declare function normalizeDecision(result: DecisionResult): Decision;
|
|
1580
1414
|
/**
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1583
|
-
* CallOutcome 的可序列化子集;不重复 response/steps 等会话级信息。
|
|
1415
|
+
* Agent 初始化上下文
|
|
1584
1416
|
*/
|
|
1585
|
-
interface
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
error?: ExecutionError;
|
|
1417
|
+
interface AgentInitiateContext {
|
|
1418
|
+
/** 消息上下文 */
|
|
1419
|
+
context: Context;
|
|
1589
1420
|
}
|
|
1590
1421
|
/**
|
|
1591
|
-
*
|
|
1422
|
+
* Agent 销毁上下文
|
|
1592
1423
|
*/
|
|
1593
|
-
interface
|
|
1594
|
-
/**
|
|
1595
|
-
|
|
1596
|
-
/** LLM 生成的输出 token */
|
|
1597
|
-
outputTokens: number;
|
|
1598
|
-
}
|
|
1599
|
-
interface ThinkingBlock {
|
|
1600
|
-
signature: string;
|
|
1601
|
-
thinking: string;
|
|
1602
|
-
}
|
|
1603
|
-
interface ToolCall {
|
|
1604
|
-
id: string;
|
|
1605
|
-
name: string;
|
|
1606
|
-
arguments: Record<string, any>;
|
|
1607
|
-
}
|
|
1608
|
-
interface LLMResponse {
|
|
1609
|
-
content: string;
|
|
1610
|
-
toolCalls?: ToolCall[];
|
|
1611
|
-
reasoning?: string;
|
|
1612
|
-
thinkingBlocks?: ThinkingBlock[];
|
|
1613
|
-
/** 用量统计(可选) */
|
|
1614
|
-
usage?: UsageInfo;
|
|
1615
|
-
/** 停止原因,由 LLM API 返回(如 end_turn, tool_use, stop 等) */
|
|
1616
|
-
stopReason?: string | null;
|
|
1424
|
+
interface AgentDestroyContext {
|
|
1425
|
+
/** 消息上下文 */
|
|
1426
|
+
context: Context;
|
|
1617
1427
|
}
|
|
1618
1428
|
/**
|
|
1619
|
-
*
|
|
1620
|
-
* 可以是字符串模板或函数模板
|
|
1429
|
+
* Call 开始上下文
|
|
1621
1430
|
*/
|
|
1622
|
-
|
|
1431
|
+
interface CallStartContext {
|
|
1432
|
+
/** 用户输入 */
|
|
1433
|
+
input: string;
|
|
1434
|
+
/** 消息上下文 */
|
|
1435
|
+
context: Context;
|
|
1436
|
+
/** 是否首次调用 */
|
|
1437
|
+
isFirstCall: boolean;
|
|
1438
|
+
/** Agent 实例(用于访问 setUserInput/getUserInput 等 API) */
|
|
1439
|
+
agent?: any;
|
|
1440
|
+
}
|
|
1623
1441
|
/**
|
|
1624
|
-
*
|
|
1442
|
+
* 执行单元的终态。它只表达执行是否完成、失败、取消或移交给后续单元;
|
|
1443
|
+
* 不复用模型厂商的 stop reason,也不推断宿主任务的业务状态。
|
|
1625
1444
|
*/
|
|
1626
|
-
type
|
|
1445
|
+
type ExecutionStatus = 'completed' | 'failed' | 'cancelled' | 'continued';
|
|
1627
1446
|
/**
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1447
|
+
* 执行终止的框架级原因。
|
|
1448
|
+
*
|
|
1449
|
+
* `reason` 描述生命周期语义,错误来源由 `error.category` 表达,避免一个字段
|
|
1450
|
+
* 同时承担供应商协议、框架控制流和宿主业务状态三种含义。
|
|
1630
1451
|
*/
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
result?: string | InlineRenderTemplate;
|
|
1640
|
-
}
|
|
1641
|
-
interface LLMClient {
|
|
1642
|
-
chat(messages: Message[], tools: Tool[], options?: LLMChatOptions): Promise<LLMResponse>;
|
|
1643
|
-
/** 可选:返回当前 LLM 实例使用的模型名(用于调试显示) */
|
|
1644
|
-
readonly modelName?: string;
|
|
1452
|
+
type ExecutionReason = 'completed' | 'cancelled' | 'limit_reached' | 'continued' | 'error';
|
|
1453
|
+
/** 可序列化的错误事实。category 是稳定的机器分类,message 只供展示。 */
|
|
1454
|
+
interface ExecutionError {
|
|
1455
|
+
category: string;
|
|
1456
|
+
message: string;
|
|
1457
|
+
code?: string;
|
|
1458
|
+
statusCode?: number;
|
|
1459
|
+
retryable?: boolean;
|
|
1645
1460
|
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
/** 请求非流式响应(适用于一次性摘要、标题生成等场景) */
|
|
1650
|
-
noStream?: boolean;
|
|
1461
|
+
/** 单次模型请求的来源信息;不决定 Call 的终态。 */
|
|
1462
|
+
interface ModelRequestOutcome {
|
|
1463
|
+
providerStopReason?: string | null;
|
|
1651
1464
|
}
|
|
1652
1465
|
/**
|
|
1653
|
-
*
|
|
1654
|
-
*
|
|
1655
|
-
* 用于 Agent.setLLM() 时传递模型上下文信息,
|
|
1656
|
-
* 供 Feature(如 ContextGuard)根据新模型的 contextLength 调整行为。
|
|
1466
|
+
* 一次 Agent Call(而非宿主任务)的结构化终态。
|
|
1467
|
+
* 该对象可安全持久化、跨进程传输和用于 JSONL/CLI 消费。
|
|
1657
1468
|
*/
|
|
1658
|
-
interface
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
llm: LLMClient;
|
|
1668
|
-
tools?: Tool[];
|
|
1669
|
-
maxTurns?: number;
|
|
1670
|
-
systemMessage?: string | TemplateSource;
|
|
1671
|
-
name?: string;
|
|
1672
|
-
projectRoot?: string;
|
|
1673
|
-
workspaceDir?: string;
|
|
1674
|
-
/**
|
|
1675
|
-
* Feature 配置
|
|
1676
|
-
*
|
|
1677
|
-
* 新的声明式 Feature 注册方式
|
|
1678
|
-
*/
|
|
1679
|
-
features?: {
|
|
1680
|
-
/** 启用的 Feature 列表 */
|
|
1681
|
-
enabled?: string[];
|
|
1682
|
-
/** Feature 特定配置 */
|
|
1683
|
-
[key: string]: unknown;
|
|
1684
|
-
};
|
|
1469
|
+
interface CallOutcome {
|
|
1470
|
+
status: ExecutionStatus;
|
|
1471
|
+
reason: ExecutionReason;
|
|
1472
|
+
response: string;
|
|
1473
|
+
steps: number;
|
|
1474
|
+
startedAt: number;
|
|
1475
|
+
finishedAt: number;
|
|
1476
|
+
error?: ExecutionError;
|
|
1477
|
+
model?: ModelRequestOutcome;
|
|
1685
1478
|
}
|
|
1686
|
-
|
|
1479
|
+
/** @deprecated 使用 CallOutcome.reason。保留旧 hook/API 的类型兼容。 */
|
|
1480
|
+
type CallFinishReason = ExecutionReason;
|
|
1687
1481
|
/**
|
|
1688
|
-
*
|
|
1482
|
+
* Call 结束上下文
|
|
1689
1483
|
*/
|
|
1690
|
-
interface
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1484
|
+
interface CallFinishContext {
|
|
1485
|
+
/** 用户输入 */
|
|
1486
|
+
input: string;
|
|
1487
|
+
/** 消息上下文 */
|
|
1488
|
+
context: Context;
|
|
1489
|
+
/** 最终响应 */
|
|
1490
|
+
response: string;
|
|
1491
|
+
/** 执行的步骤数 */
|
|
1492
|
+
steps: number;
|
|
1493
|
+
/** 是否成功完成 */
|
|
1494
|
+
completed: boolean;
|
|
1495
|
+
/** 结束原因 */
|
|
1496
|
+
finishReason: CallFinishReason;
|
|
1497
|
+
/** 完整的结构化终态 */
|
|
1498
|
+
outcome: CallOutcome;
|
|
1695
1499
|
}
|
|
1696
1500
|
/**
|
|
1697
|
-
*
|
|
1501
|
+
* Step 开始上下文
|
|
1502
|
+
*
|
|
1503
|
+
* Step 是 ReAct 循环中的单次迭代
|
|
1698
1504
|
*/
|
|
1699
|
-
interface
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1505
|
+
interface StepStartContext {
|
|
1506
|
+
/** 当前步骤序号(从 0 开始) */
|
|
1507
|
+
step: number;
|
|
1508
|
+
/** 当前调用序号(用户交互次数,从 0 开始) */
|
|
1509
|
+
callIndex: number;
|
|
1510
|
+
/** 消息上下文 */
|
|
1511
|
+
context: Context;
|
|
1512
|
+
/** 原始用户输入 */
|
|
1513
|
+
input: string;
|
|
1514
|
+
/** Agent 实例(用于访问当前会话中的 Feature、工具和输入状态) */
|
|
1515
|
+
agent?: any;
|
|
1708
1516
|
}
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1517
|
+
/**
|
|
1518
|
+
* Step 结束上下文
|
|
1519
|
+
*/
|
|
1520
|
+
interface StepFinishedContext extends StepStartContext {
|
|
1521
|
+
/** LLM 响应 */
|
|
1522
|
+
llmResponse: LLMResponse;
|
|
1523
|
+
/** 执行的工具调用数量 */
|
|
1524
|
+
toolCallsCount: number;
|
|
1714
1525
|
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1526
|
+
/**
|
|
1527
|
+
* 工具上下文 - onToolUse 钩子的参数
|
|
1528
|
+
*
|
|
1529
|
+
* 提供工具调用时的完整上下文信息
|
|
1530
|
+
*/
|
|
1531
|
+
interface ToolContext {
|
|
1532
|
+
/** 工具调用 */
|
|
1533
|
+
call: ToolCall;
|
|
1534
|
+
/** 工具定义 */
|
|
1535
|
+
tool: Tool;
|
|
1536
|
+
/** 当前步骤序号 */
|
|
1537
|
+
step: number;
|
|
1538
|
+
/** 用户输入 */
|
|
1539
|
+
input: string;
|
|
1540
|
+
/** 消息上下文(可读写) */
|
|
1541
|
+
context: Context;
|
|
1542
|
+
/** 获取其他 Feature */
|
|
1543
|
+
getFeature<T extends AgentFeature>(name: string): T | undefined;
|
|
1728
1544
|
}
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1545
|
+
/**
|
|
1546
|
+
* 工具结果 - onToolFinished 钩子的参数
|
|
1547
|
+
*
|
|
1548
|
+
* 提供工具执行后的完整结果信息
|
|
1549
|
+
*/
|
|
1550
|
+
interface ToolResult {
|
|
1551
|
+
/** 是否成功 */
|
|
1552
|
+
success: boolean;
|
|
1553
|
+
/** 经过 ToolResultTransform 后、实际写入模型上下文的最终结果。 */
|
|
1554
|
+
delivered?: ToolExecResult;
|
|
1555
|
+
/** 返回数据 */
|
|
1556
|
+
data: unknown;
|
|
1557
|
+
/** 错误信息(如果失败) */
|
|
1558
|
+
error?: string;
|
|
1559
|
+
/** 执行耗时(ms) */
|
|
1560
|
+
duration: number;
|
|
1561
|
+
/** 工具调用 */
|
|
1562
|
+
call: ToolCall;
|
|
1563
|
+
/** 工具定义 */
|
|
1564
|
+
tool: Tool;
|
|
1565
|
+
/** 当前步骤序号 */
|
|
1566
|
+
step: number;
|
|
1567
|
+
/** 用户输入 */
|
|
1568
|
+
input: string;
|
|
1569
|
+
/** 消息上下文 */
|
|
1570
|
+
context: Context;
|
|
1571
|
+
/** 获取其他 Feature */
|
|
1572
|
+
getFeature<T extends AgentFeature>(name: string): T | undefined;
|
|
1734
1573
|
}
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1574
|
+
/**
|
|
1575
|
+
* 钩子返回值类型(扩展版)
|
|
1576
|
+
*
|
|
1577
|
+
* 统一的生命周期钩子控制流指令
|
|
1578
|
+
*
|
|
1579
|
+
* - { action: 'block' }: 阻止工具执行(工具级)
|
|
1580
|
+
* - { action: 'allow' }: 允许工具执行(工具级)
|
|
1581
|
+
* - undefined: 默认行为
|
|
1582
|
+
*/
|
|
1583
|
+
type HookResult = {
|
|
1584
|
+
action: 'block';
|
|
1585
|
+
reason?: string;
|
|
1586
|
+
} | {
|
|
1587
|
+
action: 'allow';
|
|
1588
|
+
} | undefined;
|
|
1589
|
+
/**
|
|
1590
|
+
* 子代理状态
|
|
1591
|
+
*/
|
|
1592
|
+
type SubAgentStatus = 'idle' | 'busy' | 'completed' | 'failed' | 'terminated';
|
|
1593
|
+
/**
|
|
1594
|
+
* 子代理创建上下文
|
|
1595
|
+
*/
|
|
1596
|
+
interface SubAgentSpawnContext {
|
|
1597
|
+
/** 子代理 ID */
|
|
1598
|
+
agentId: string;
|
|
1599
|
+
/** 子代理类型 */
|
|
1600
|
+
type: string;
|
|
1601
|
+
/** 初始指令 */
|
|
1602
|
+
instruction: string;
|
|
1603
|
+
/** 子代理实例 */
|
|
1604
|
+
agent: AgentBase;
|
|
1753
1605
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1606
|
+
/**
|
|
1607
|
+
* 子代理状态更新上下文
|
|
1608
|
+
*/
|
|
1609
|
+
interface SubAgentUpdateContext {
|
|
1610
|
+
/** 子代理 ID */
|
|
1611
|
+
agentId: string;
|
|
1612
|
+
/** 子代理类型 */
|
|
1613
|
+
type: string;
|
|
1614
|
+
/** 旧状态 */
|
|
1615
|
+
oldStatus: SubAgentStatus;
|
|
1616
|
+
/** 新状态 */
|
|
1617
|
+
newStatus: SubAgentStatus;
|
|
1618
|
+
/** 执行结果(完成时) */
|
|
1619
|
+
result?: string;
|
|
1620
|
+
/** 错误信息(失败时) */
|
|
1621
|
+
error?: string;
|
|
1768
1622
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
runtime?: AgentRuntimeStateSnapshot;
|
|
1780
|
-
/** 可选:当前使用的模型名(由 agent 实例注入) */
|
|
1781
|
-
modelName?: string;
|
|
1782
|
-
/** 可选:当前使用的预设名(由 agent 实例注入,用于 UI dropdown 高亮) */
|
|
1783
|
-
presetName?: string;
|
|
1784
|
-
/** 可选:当前 LLM 实例的思考强度(由 agent 实例注入,用于 UI 状态同步) */
|
|
1785
|
-
thinkingEffort?: string | null;
|
|
1786
|
-
/** 可选:当前模型的上下文窗口长度(由 agent 实例注入,用于 UI 用量条实时同步) */
|
|
1787
|
-
contextLength?: number;
|
|
1788
|
-
/** 可选:当前模型的压缩阈值百分比(由 agent 实例注入,用于 UI 用量条实时同步) */
|
|
1789
|
-
compressRatio?: number;
|
|
1790
|
-
}
|
|
1791
|
-
interface TodoTaskSnapshot {
|
|
1792
|
-
id: string;
|
|
1793
|
-
subject: string;
|
|
1794
|
-
description: string;
|
|
1795
|
-
status: 'pending' | 'in_progress' | 'completed' | 'deleted';
|
|
1796
|
-
metadata?: Record<string, unknown>;
|
|
1797
|
-
createdAt: number;
|
|
1798
|
-
updatedAt: number;
|
|
1799
|
-
}
|
|
1800
|
-
interface TodoPlanSummary {
|
|
1801
|
-
total: number;
|
|
1802
|
-
pending: number;
|
|
1803
|
-
inProgress: number;
|
|
1804
|
-
completed: number;
|
|
1805
|
-
cancelled: number;
|
|
1806
|
-
}
|
|
1807
|
-
interface TodoPlanSnapshot {
|
|
1808
|
-
feature: 'todo';
|
|
1809
|
-
updatedAt: number;
|
|
1810
|
-
counter: number;
|
|
1811
|
-
tasks: TodoTaskSnapshot[];
|
|
1812
|
-
summary: TodoPlanSummary;
|
|
1813
|
-
/** 中断目标 task ID(由 ControlledTodoFeature 扩展,null = 无中断目标) */
|
|
1814
|
-
interruptTargetId?: string | null;
|
|
1815
|
-
/** 任务未完强制继续开关状态(由 ControlledTodoFeature 扩展,null = 未上报) */
|
|
1816
|
-
forceContinue?: {
|
|
1817
|
-
enabled: boolean;
|
|
1818
|
-
consecutive: number;
|
|
1819
|
-
max: number;
|
|
1820
|
-
} | null;
|
|
1623
|
+
/**
|
|
1624
|
+
* 子代理销毁上下文
|
|
1625
|
+
*/
|
|
1626
|
+
interface SubAgentDestroyContext {
|
|
1627
|
+
/** 子代理 ID */
|
|
1628
|
+
agentId: string;
|
|
1629
|
+
/** 子代理类型 */
|
|
1630
|
+
type: string;
|
|
1631
|
+
/** 销毁原因 */
|
|
1632
|
+
reason: 'manual' | 'parent_dispose' | 'error';
|
|
1821
1633
|
}
|
|
1822
1634
|
/**
|
|
1823
|
-
* Agent
|
|
1635
|
+
* Agent 中断上下文
|
|
1824
1636
|
*/
|
|
1825
|
-
interface
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
projectRoot?: string;
|
|
1833
|
-
currentState: Notification | null;
|
|
1834
|
-
callActive?: boolean;
|
|
1835
|
-
runtimeState?: AgentRuntimeStateSnapshot;
|
|
1836
|
-
events: Notification[];
|
|
1837
|
-
lastEventCount: number;
|
|
1838
|
-
logs: DebugLogEntry[];
|
|
1839
|
-
clientId?: string;
|
|
1840
|
-
_lastMessageSig?: string;
|
|
1841
|
-
hookInspector?: HookInspectorSnapshot;
|
|
1842
|
-
overview?: AgentOverviewSnapshot;
|
|
1843
|
-
todoPlan?: TodoPlanSnapshot;
|
|
1844
|
-
/**
|
|
1845
|
-
* 唯一的活动输入租约。一个 Agent 实例在任意时刻只能由一个输入请求
|
|
1846
|
-
* 消费用户回复;这是跨 reconnect / 多进程路由的归属锚点。
|
|
1847
|
-
*/
|
|
1848
|
-
inputLease?: InputLease;
|
|
1849
|
-
queuedInputs: QueuedInput[];
|
|
1850
|
-
/**
|
|
1851
|
-
* 外部用户回合的接受策略,注册时声明。
|
|
1852
|
-
* 'standard'(默认):接受聊天邮箱排队与输入租约。
|
|
1853
|
-
* 'none':拒绝排队注入;测试沙盒等由宿主进程驱动输入的运行时使用。
|
|
1854
|
-
* 输入租约(interactive input request)不受此策略限制,仍由 feature 控制。
|
|
1855
|
-
*/
|
|
1856
|
-
inputPolicy?: 'standard' | 'none';
|
|
1857
|
-
}
|
|
1858
|
-
interface InputLease {
|
|
1859
|
-
requestId: string;
|
|
1860
|
-
prompt: string;
|
|
1861
|
-
placeholder?: string;
|
|
1862
|
-
initialValue?: string;
|
|
1863
|
-
actions?: UserInputAction[];
|
|
1864
|
-
mode?: UserInputRequestMode;
|
|
1865
|
-
questions?: UserInputQuestion[];
|
|
1866
|
-
timestamp: number;
|
|
1637
|
+
interface AgentInterruptContext {
|
|
1638
|
+
/** 中断原因 */
|
|
1639
|
+
reason: 'limit_reached' | 'error' | 'cancelled';
|
|
1640
|
+
/** 当前步骤序号 */
|
|
1641
|
+
step: number;
|
|
1642
|
+
/** 当前消息上下文 */
|
|
1643
|
+
context: Context;
|
|
1867
1644
|
}
|
|
1868
1645
|
/**
|
|
1869
|
-
*
|
|
1646
|
+
* 子代理中断上下文
|
|
1870
1647
|
*/
|
|
1871
|
-
interface
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
sourceRef?: string;
|
|
1881
|
-
/** 随消息流动的能力激活通知(capability refs,如 skill.grill-me) */
|
|
1882
|
-
capabilityActivations?: string[];
|
|
1648
|
+
interface SubAgentInterruptContext {
|
|
1649
|
+
/** 子代理 ID */
|
|
1650
|
+
agentId: string;
|
|
1651
|
+
/** 子代理类型 */
|
|
1652
|
+
type: string;
|
|
1653
|
+
/** 中断原因 */
|
|
1654
|
+
reason: 'limit_reached' | 'error' | 'cancelled';
|
|
1655
|
+
/** 中断时的结果 */
|
|
1656
|
+
result: string;
|
|
1883
1657
|
}
|
|
1884
1658
|
/**
|
|
1885
|
-
*
|
|
1659
|
+
* Step 结束决策上下文(反向钩子)
|
|
1886
1660
|
*
|
|
1887
|
-
*
|
|
1888
|
-
* 否则进入该已连接 runtime 的会话邮箱,等待下一次兼容的文本输入租约。
|
|
1889
|
-
* 这覆盖新建/恢复会话在输入循环尚未打开的启动窗口,不依赖 callActive。
|
|
1661
|
+
* 用于在 Step 结束后进行流程控制决策
|
|
1890
1662
|
*/
|
|
1891
|
-
interface
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
/**
|
|
1897
|
-
|
|
1663
|
+
interface StepFinishDecisionContext extends StepFinishedContext {
|
|
1664
|
+
/** 是否有活跃的子代理(busy 状态) */
|
|
1665
|
+
hasActiveSubAgents?: boolean;
|
|
1666
|
+
/** 是否有待处理的子代理消息 */
|
|
1667
|
+
hasPendingMessages?: boolean;
|
|
1668
|
+
/** 是否调用了 wait 工具 */
|
|
1669
|
+
waitCalled?: boolean;
|
|
1898
1670
|
}
|
|
1899
|
-
type UserTurnSubmissionResult = {
|
|
1900
|
-
success: true;
|
|
1901
|
-
delivery: 'input';
|
|
1902
|
-
requestId: string;
|
|
1903
|
-
source?: string;
|
|
1904
|
-
sourceRef?: string;
|
|
1905
|
-
} | {
|
|
1906
|
-
success: true;
|
|
1907
|
-
delivery: 'queued';
|
|
1908
|
-
id: string;
|
|
1909
|
-
queueLength: number;
|
|
1910
|
-
source?: string;
|
|
1911
|
-
sourceRef?: string;
|
|
1912
|
-
} | {
|
|
1913
|
-
success: false;
|
|
1914
|
-
code: 'agent_not_found' | 'invalid_input' | 'input_mode_conflict' | 'runtime_not_accepting_input';
|
|
1915
|
-
error: string;
|
|
1916
|
-
pendingMode?: UserInputRequestMode;
|
|
1917
|
-
};
|
|
1918
|
-
/**
|
|
1919
|
-
* DebugHub IPC 消息类型(主进程 → Worker)
|
|
1920
|
-
* 使用 discriminated union 确保类型安全
|
|
1921
|
-
*/
|
|
1922
|
-
type DebugHubIPCMessage = RegisterAgentMsg | UpdateAgentInspectorMsg | UpdateAgentOverviewMsg | UpdateTodoPlanMsg | PushMessagesMsg | RegisterToolsMsg | UnregisterAgentMsg | PushNotificationMsg | RequestInputMsg | InputRequestCancelledMsg | InterruptAgentMsg | StopMsg;
|
|
1923
1671
|
/**
|
|
1924
|
-
*
|
|
1672
|
+
* 工具完成决策上下文(反向钩子)
|
|
1673
|
+
*
|
|
1674
|
+
* 用于在工具执行完成后进行流程控制决策
|
|
1925
1675
|
*/
|
|
1926
|
-
interface
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
name: string;
|
|
1930
|
-
createdAt: number;
|
|
1931
|
-
projectRoot?: string;
|
|
1932
|
-
/**
|
|
1933
|
-
* 模板装载点:Feature 所属包的真实目录根(junction 已解析)。
|
|
1934
|
-
* Agent 侧是唯一知道权威 mount root 的一层(来自 feature.getPackageInfo()),
|
|
1935
|
-
* 注册只传事实,不做 URL 推导;URL 由 viewer-worker 分配。
|
|
1936
|
-
*/
|
|
1937
|
-
templateMounts?: string[];
|
|
1938
|
-
/**
|
|
1939
|
-
* 模板名 → 装载条目。mount 为 templateMounts 数组下标,
|
|
1940
|
-
* rel 为该 mount root 下的相对路径(POSIX 分隔符)。
|
|
1941
|
-
*/
|
|
1942
|
-
templateEntries?: Record<string, {
|
|
1943
|
-
mount: number;
|
|
1944
|
-
rel: string;
|
|
1945
|
-
}>;
|
|
1946
|
-
hookInspector?: HookInspectorSnapshot;
|
|
1947
|
-
overview?: AgentOverviewSnapshot;
|
|
1948
|
-
activeInputRequest?: ActiveInputRequest;
|
|
1949
|
-
inputPolicy?: 'standard' | 'none';
|
|
1950
|
-
}
|
|
1951
|
-
interface UpdateAgentInspectorMsg {
|
|
1952
|
-
type: 'update-agent-inspector';
|
|
1953
|
-
agentId: string;
|
|
1954
|
-
hookInspector: HookInspectorSnapshot;
|
|
1955
|
-
}
|
|
1956
|
-
interface UpdateAgentOverviewMsg {
|
|
1957
|
-
type: 'update-agent-overview';
|
|
1958
|
-
agentId: string;
|
|
1959
|
-
overview: AgentOverviewSnapshot;
|
|
1960
|
-
}
|
|
1961
|
-
interface UpdateTodoPlanMsg {
|
|
1962
|
-
type: 'update-todo-plan';
|
|
1963
|
-
agentId: string;
|
|
1964
|
-
plan: TodoPlanSnapshot;
|
|
1676
|
+
interface ToolFinishedDecisionContext extends ToolResult {
|
|
1677
|
+
/** 刚才执行的工具名称 */
|
|
1678
|
+
toolName: string;
|
|
1965
1679
|
}
|
|
1966
1680
|
/**
|
|
1967
|
-
*
|
|
1681
|
+
* 工具结果变换上下文(反向钩子)
|
|
1682
|
+
*
|
|
1683
|
+
* 在工具执行完成、结果写入 context 之前,允许 Feature 对结果进行变换。
|
|
1684
|
+
* 典型用途:输出截断(OutputGuard)、脱敏、格式清理等。
|
|
1685
|
+
*
|
|
1686
|
+
* 钩子返回 undefined 表示不修改;返回 ToolExecResult 表示用新结果替换。
|
|
1687
|
+
* 多个钩子按注册顺序链式执行,前一个钩子的输出作为后一个钩子的输入。
|
|
1968
1688
|
*/
|
|
1969
|
-
interface
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1689
|
+
interface ToolResultTransformContext {
|
|
1690
|
+
/** 工具名称 */
|
|
1691
|
+
toolName: string;
|
|
1692
|
+
/** 工具调用 */
|
|
1693
|
+
call: ToolCall;
|
|
1694
|
+
/** 当前结果(可能已被前一个变换钩子修改) */
|
|
1695
|
+
result: ToolExecResult;
|
|
1696
|
+
/** 当前步骤序号 */
|
|
1697
|
+
step: number;
|
|
1973
1698
|
}
|
|
1699
|
+
|
|
1974
1700
|
/**
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
agentId: string;
|
|
1980
|
-
tools: Tool[];
|
|
1981
|
-
}
|
|
1701
|
+
* 基础类型定义
|
|
1702
|
+
* 所有类型集中在这里,简单直观
|
|
1703
|
+
*/
|
|
1704
|
+
|
|
1982
1705
|
/**
|
|
1983
|
-
*
|
|
1706
|
+
* 通知分类
|
|
1707
|
+
* - state: 覆盖式更新(如 LLM 字符计数)
|
|
1708
|
+
* - event: 追加式记录(如工具开始/完成)
|
|
1984
1709
|
*/
|
|
1985
|
-
|
|
1986
|
-
requestId: string;
|
|
1987
|
-
prompt: string;
|
|
1988
|
-
placeholder?: string;
|
|
1989
|
-
initialValue?: string;
|
|
1990
|
-
actions?: UserInputAction[];
|
|
1991
|
-
timestamp: number;
|
|
1992
|
-
}
|
|
1710
|
+
type NotificationCategory = 'state' | 'event';
|
|
1993
1711
|
/**
|
|
1994
|
-
*
|
|
1712
|
+
* LLM 生成阶段
|
|
1995
1713
|
*/
|
|
1996
|
-
|
|
1997
|
-
type: 'unregister-agent';
|
|
1998
|
-
agentId: string;
|
|
1999
|
-
}
|
|
2000
|
-
/**
|
|
2001
|
-
* 停止 Worker
|
|
2002
|
-
*/
|
|
2003
|
-
interface StopMsg {
|
|
2004
|
-
type: 'stop';
|
|
2005
|
-
}
|
|
2006
|
-
/**
|
|
2007
|
-
* 推送通知
|
|
2008
|
-
*/
|
|
2009
|
-
interface PushNotificationMsg {
|
|
2010
|
-
type: 'push-notification';
|
|
2011
|
-
agentId: string;
|
|
2012
|
-
notification: Notification;
|
|
2013
|
-
}
|
|
2014
|
-
/**
|
|
2015
|
-
* 请求用户输入
|
|
2016
|
-
*/
|
|
2017
|
-
interface RequestInputMsg {
|
|
2018
|
-
type: 'request-input';
|
|
2019
|
-
agentId: string;
|
|
2020
|
-
requestId: string;
|
|
2021
|
-
prompt: string;
|
|
2022
|
-
timeout?: number;
|
|
2023
|
-
placeholder?: string;
|
|
2024
|
-
initialValue?: string;
|
|
2025
|
-
actions?: UserInputAction[];
|
|
2026
|
-
mode?: UserInputRequestMode;
|
|
2027
|
-
questions?: UserInputQuestion[];
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* 通知 Worker 一个输入请求已被运行时结算/取消(中断、销毁等)。
|
|
2031
|
-
* Worker 持有同名 inputLease 作为 HTTP 投递面;收到后应清除对应租约,
|
|
2032
|
-
* 否则陈旧租约会永久阻塞后续 user-turn(input_mode_conflict)。
|
|
2033
|
-
*/
|
|
2034
|
-
interface InputRequestCancelledMsg {
|
|
2035
|
-
type: 'input-request-cancelled';
|
|
2036
|
-
agentId: string;
|
|
2037
|
-
requestId: string;
|
|
2038
|
-
}
|
|
1714
|
+
type LLMPhase = 'thinking' | 'content' | 'tool_calling';
|
|
2039
1715
|
/**
|
|
2040
|
-
*
|
|
1716
|
+
* 通知基础接口
|
|
2041
1717
|
*/
|
|
2042
|
-
interface
|
|
2043
|
-
type:
|
|
2044
|
-
|
|
2045
|
-
|
|
1718
|
+
interface Notification {
|
|
1719
|
+
type: string;
|
|
1720
|
+
category: NotificationCategory;
|
|
1721
|
+
timestamp: number;
|
|
1722
|
+
data: unknown;
|
|
2046
1723
|
}
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
1724
|
+
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
1725
|
+
type DebugLogDeliveryReason = 'hub' | 'hub-unavailable' | 'no-agent-context';
|
|
1726
|
+
interface DebugLogDelivery {
|
|
1727
|
+
hub: boolean;
|
|
1728
|
+
console: boolean;
|
|
1729
|
+
reason: DebugLogDeliveryReason;
|
|
2053
1730
|
}
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
1731
|
+
interface LogContextRef {
|
|
1732
|
+
agentId?: string;
|
|
1733
|
+
agentName?: string;
|
|
1734
|
+
parentAgentId?: string;
|
|
1735
|
+
callIndex?: number;
|
|
1736
|
+
step?: number;
|
|
1737
|
+
toolName?: string;
|
|
1738
|
+
toolCallId?: string;
|
|
1739
|
+
feature?: string;
|
|
1740
|
+
lifecycle?: string;
|
|
1741
|
+
hookMethod?: string;
|
|
1742
|
+
hookKind?: 'forward' | 'observe' | 'guard' | 'transform';
|
|
1743
|
+
sourceFile?: string;
|
|
1744
|
+
sourceLine?: number;
|
|
1745
|
+
tags?: string[];
|
|
1746
|
+
[key: string]: unknown;
|
|
2067
1747
|
}
|
|
2068
|
-
interface
|
|
1748
|
+
interface DebugLogEntry {
|
|
2069
1749
|
id: string;
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
prompt: string;
|
|
2078
|
-
placeholder?: string;
|
|
2079
|
-
initialValue?: string;
|
|
2080
|
-
actions?: UserInputAction[];
|
|
2081
|
-
mode?: UserInputRequestMode;
|
|
2082
|
-
questions?: UserInputQuestion[];
|
|
2083
|
-
}
|
|
2084
|
-
interface UserInputChoiceAnswer {
|
|
2085
|
-
questionId: string;
|
|
2086
|
-
optionId?: string;
|
|
2087
|
-
customText?: string;
|
|
2088
|
-
/** Supplementary free-text provided alongside the selected option */
|
|
2089
|
-
supplementText?: string;
|
|
2090
|
-
}
|
|
2091
|
-
interface UserInputResponse {
|
|
2092
|
-
kind: 'text' | 'action' | 'choices';
|
|
2093
|
-
text?: string;
|
|
2094
|
-
actionId?: string;
|
|
2095
|
-
choices?: UserInputChoiceAnswer[];
|
|
2096
|
-
payload?: Record<string, unknown>;
|
|
1750
|
+
timestamp: number;
|
|
1751
|
+
level: LogLevel;
|
|
1752
|
+
message: string;
|
|
1753
|
+
namespace: string;
|
|
1754
|
+
context: LogContextRef;
|
|
1755
|
+
data?: unknown;
|
|
1756
|
+
delivery: DebugLogDelivery;
|
|
2097
1757
|
}
|
|
1758
|
+
type RuntimeStage = 'idle' | 'llm_thinking' | 'llm_content' | 'llm_tool_call_building' | 'awaiting_runtime' | 'tool_executing' | 'retry_waiting' | 'retry_requesting' | 'completed' | 'failed' | 'cancelled';
|
|
2098
1759
|
/**
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
* 用于快速分类和过滤消息,一条消息可能有多个标签
|
|
2102
|
-
*/
|
|
2103
|
-
type MessageTag = 'user' | 'system' | 'assistant' | 'tool-call' | 'tool-result' | 'sub-agent' | 'reminder';
|
|
2104
|
-
/**
|
|
2105
|
-
* 解析结果结构
|
|
1760
|
+
* 工具终止原因(ticket 023 / ADR-0005)
|
|
2106
1761
|
*
|
|
2107
|
-
*
|
|
1762
|
+
* - 'timeout':框架统一超时计时触发(Tool 声明 timeout 后生效)
|
|
1763
|
+
* - 'user':外部用户中断(Agent.interrupt() 触发的 abort signal)
|
|
2108
1764
|
*/
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
1765
|
+
type ToolTerminationReason = 'timeout' | 'user';
|
|
1766
|
+
interface AgentRuntimeStateSnapshot {
|
|
1767
|
+
stage: RuntimeStage;
|
|
1768
|
+
callActive: boolean;
|
|
1769
|
+
charCount: number;
|
|
1770
|
+
thinkingChars: number;
|
|
1771
|
+
contentChars: number;
|
|
1772
|
+
toolCallCount: number;
|
|
1773
|
+
activeToolNames: string[];
|
|
1774
|
+
activeToolCount: number;
|
|
1775
|
+
/** LLM 流式期间检测到的工具名称(仅 llm_tool_call_building 阶段有值) */
|
|
1776
|
+
streamToolNames?: string[];
|
|
1777
|
+
callStartedAt?: number;
|
|
1778
|
+
stageStartedAt?: number;
|
|
1779
|
+
retryAttempt?: number;
|
|
1780
|
+
maxRetries?: number;
|
|
1781
|
+
nextRetryDelayMs?: number;
|
|
1782
|
+
lastErrorType?: string | null;
|
|
1783
|
+
lastErrorMessage?: string | null;
|
|
1784
|
+
/** 最近一次已结束 Call 的结构化终态。 */
|
|
1785
|
+
/** 最近一次已结束 Call 的结构化终态。 */
|
|
1786
|
+
lastOutcome?: CallOutcome | null;
|
|
1787
|
+
updatedAt: number;
|
|
2118
1788
|
}
|
|
2119
1789
|
/**
|
|
2120
|
-
*
|
|
1790
|
+
* 工具执行上下文
|
|
2121
1791
|
*
|
|
2122
|
-
*
|
|
2123
|
-
*
|
|
1792
|
+
* 由框架在执行工具时注入。Feature 通过 {@link AgentFeature.getContextInjectors}
|
|
1793
|
+
* 可以扩展额外字段。
|
|
2124
1794
|
*/
|
|
2125
|
-
interface
|
|
2126
|
-
/**
|
|
2127
|
-
|
|
2128
|
-
/**
|
|
2129
|
-
|
|
2130
|
-
/**
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
1795
|
+
interface ToolExecutionContext {
|
|
1796
|
+
/** 中断信号,用于取消工具执行(外部用户中断与框架超时合并后的 signal) */
|
|
1797
|
+
signal?: AbortSignal;
|
|
1798
|
+
/** 当前工具调用的 LLM 生成 call.id(tool.progress 等进度信号配对用) */
|
|
1799
|
+
callId?: string;
|
|
1800
|
+
/**
|
|
1801
|
+
* 查询当前工具执行是否已被终止及终止原因(ticket 023)。
|
|
1802
|
+
*
|
|
1803
|
+
* 返回 null 表示尚未终止;工具可据此在结果中填写模型可读的终止元数据。
|
|
1804
|
+
* reason 不挂在 AbortSignal 上(signal 保持标准形状),统一经此函数查询。
|
|
1805
|
+
*/
|
|
1806
|
+
termination?: () => ToolTerminationReason | null;
|
|
1807
|
+
/** 当前终止 settle 的绝对截止时间(epoch ms);工具用于把内部 drain 纳入同一预算。 */
|
|
1808
|
+
terminationDeadline?: () => number | null;
|
|
1809
|
+
/** 本次调用生效的超时(毫秒,含 args 覆盖后的 clamp 结果);仅声明 timeout 的工具注入(ticket 025 进度显示用) */
|
|
1810
|
+
timeoutMs?: number;
|
|
1811
|
+
/** 注册 continuation request(供 checkpoint/rollback 等控制流工具使用) */
|
|
1812
|
+
registerContinuationRequest?: (request: CallContinuationRequest) => void;
|
|
1813
|
+
/** Feature 通过 contextInjectors 注入的自定义属性 */
|
|
1814
|
+
[key: string]: unknown;
|
|
2142
1815
|
}
|
|
2143
|
-
|
|
2144
|
-
/**
|
|
2145
|
-
* 决策上下文(反向钩子参数)
|
|
2146
|
-
*
|
|
2147
|
-
* 所有决策上下文的联合类型
|
|
2148
|
-
*/
|
|
2149
|
-
type DecisionContext = AgentInitiateContext | AgentDestroyContext | CallStartContext | CallFinishContext | StepStartContext | StepFinishedContext | ToolContext | ToolResult | StepFinishDecisionContext | ToolFinishedDecisionContext | ToolResultTransformContext;
|
|
2150
|
-
/**
|
|
2151
|
-
* 平台检测后的 UDS 路径
|
|
2152
|
-
*/
|
|
2153
|
-
declare function getDefaultUDSPath(): string;
|
|
2154
|
-
|
|
2155
1816
|
/**
|
|
2156
|
-
*
|
|
1817
|
+
* 工具执行返回值类型
|
|
2157
1818
|
*
|
|
2158
|
-
*
|
|
2159
|
-
* 从 ContextFeature 移植到内核,作为 Context 的原生能力
|
|
1819
|
+
* 工具可以返回纯文本或结构化对象。框架会自动序列化非 string 返回值。
|
|
2160
1820
|
*/
|
|
2161
|
-
|
|
1821
|
+
type ToolResultValue = string | Record<string, unknown>;
|
|
2162
1822
|
/**
|
|
2163
|
-
*
|
|
2164
|
-
*
|
|
2165
|
-
* 提供链式 API 用于过滤和聚合消息
|
|
1823
|
+
* 工具定义
|
|
2166
1824
|
*/
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
private result;
|
|
2172
|
-
/**
|
|
2173
|
-
* 按角色过滤
|
|
2174
|
-
*/
|
|
2175
|
-
byRole(...roles: string[]): this;
|
|
1825
|
+
interface Tool {
|
|
1826
|
+
name: string;
|
|
1827
|
+
description: string;
|
|
1828
|
+
parameters?: Record<string, unknown>;
|
|
2176
1829
|
/**
|
|
2177
|
-
*
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
*
|
|
2182
|
-
*/
|
|
2183
|
-
byTool(name: string): this;
|
|
2184
|
-
/**
|
|
2185
|
-
* 按任务 ID 过滤(使用索引加速)
|
|
2186
|
-
*/
|
|
2187
|
-
byTask(taskId: string): this;
|
|
2188
|
-
/**
|
|
2189
|
-
* 按子代理 ID 过滤
|
|
2190
|
-
*/
|
|
2191
|
-
byAgentId(agentId: string): this;
|
|
2192
|
-
/**
|
|
2193
|
-
* 按时间起点过滤
|
|
2194
|
-
*/
|
|
2195
|
-
since(timestamp: number): this;
|
|
2196
|
-
/**
|
|
2197
|
-
* 按轮次范围过滤
|
|
1830
|
+
* 执行工具
|
|
1831
|
+
*
|
|
1832
|
+
* @param args 工具参数(来自 LLM 的 JSON 解析结果)
|
|
1833
|
+
* @param context 执行上下文,包含框架注入的 signal、registerContinuationRequest,
|
|
1834
|
+
* 以及各 Feature 通过 contextInjectors 注入的自定义属性
|
|
2198
1835
|
*/
|
|
2199
|
-
|
|
1836
|
+
execute: (args: Record<string, unknown>, context?: ToolExecutionContext) => Promise<ToolResultValue>;
|
|
1837
|
+
/** 可选:渲染配置 */
|
|
1838
|
+
render?: ToolRenderConfig;
|
|
2200
1839
|
/**
|
|
2201
|
-
*
|
|
1840
|
+
* 工具执行模式
|
|
1841
|
+
* - 'normal'(默认):普通工具,可与其他工具在同一次 assistant turn 中并行调用
|
|
1842
|
+
* - 'exclusive':独占工具,必须是 assistant turn 中唯一的工具调用
|
|
1843
|
+
*
|
|
1844
|
+
* exclusive 工具适用于控制流工具(如 checkpoint、rollback),
|
|
1845
|
+
* 它们不应与其他工具产生副作用交织。
|
|
2202
1846
|
*/
|
|
2203
|
-
|
|
1847
|
+
executionMode?: 'normal' | 'exclusive';
|
|
2204
1848
|
/**
|
|
2205
|
-
*
|
|
1849
|
+
* 工具是否可并行执行。
|
|
1850
|
+
*
|
|
1851
|
+
* - true: 该工具可以与同批次中其他 parallelizable 工具并发执行
|
|
1852
|
+
* - false/undefined: 串行执行(默认,向后兼容)
|
|
1853
|
+
*
|
|
1854
|
+
* 约束:
|
|
1855
|
+
* - exclusive 工具忽略此属性(exclusive 总是独占批次)
|
|
1856
|
+
* - 标记为 parallelizable 的工具应是无副作用的只读操作,
|
|
1857
|
+
* 或其副作用不会与同批次其他工具冲突
|
|
2206
1858
|
*/
|
|
2207
|
-
|
|
1859
|
+
parallelizable?: boolean;
|
|
2208
1860
|
/**
|
|
2209
|
-
*
|
|
1861
|
+
* 超时契约声明(ticket 023 / ADR-0005)。
|
|
1862
|
+
*
|
|
1863
|
+
* 声明后由框架执行器统一计时:超时触发合并 AbortSignal(reason=timeout),
|
|
1864
|
+
* 并给工具一个 settle 窗口优雅收尾;未声明的工具不受框架超时管辖,行为不变。
|
|
1865
|
+
*
|
|
1866
|
+
* - defaultMs: 默认超时(模型未通过 fromArg 参数覆盖时生效)
|
|
1867
|
+
* - maxMs: 生效超时的硬上限,任何来源的超时值都会被 clamp 到 [1, maxMs]
|
|
1868
|
+
* - fromArg: 可选参数名;声明后生效超时取 args[fromArg](数字),再 clamp
|
|
2210
1869
|
*/
|
|
2211
|
-
|
|
1870
|
+
timeout?: {
|
|
1871
|
+
defaultMs: number;
|
|
1872
|
+
maxMs: number;
|
|
1873
|
+
fromArg?: string;
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
interface AgentLogsResponse {
|
|
1877
|
+
scope: 'current' | 'all';
|
|
1878
|
+
selectedAgentId: string | null;
|
|
1879
|
+
total: number;
|
|
1880
|
+
logs: DebugLogEntry[];
|
|
1881
|
+
truncation?: {
|
|
1882
|
+
truncated: boolean;
|
|
1883
|
+
appliedLimit?: number;
|
|
1884
|
+
returnedCount: number;
|
|
1885
|
+
availableCount: number;
|
|
1886
|
+
nextOffset?: number;
|
|
1887
|
+
reason?: string;
|
|
1888
|
+
guidance?: string;
|
|
1889
|
+
};
|
|
1890
|
+
collectionPolicy: {
|
|
1891
|
+
hubConnected: boolean;
|
|
1892
|
+
includesOnlyHubDeliveredLogs: boolean;
|
|
1893
|
+
fallbackBehavior: string;
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
type MessageRole = 'system' | 'user' | 'assistant' | 'tool' | string;
|
|
1897
|
+
/**
|
|
1898
|
+
* 图片输入(多模态支持)
|
|
1899
|
+
*
|
|
1900
|
+
* 支持两种数据来源:
|
|
1901
|
+
* - `path`:图片已落盘到本地文件,编译 LLM 请求时按需读取为 base64(推荐)
|
|
1902
|
+
* - `base64`:内联 base64 数据(向后兼容旧会话)
|
|
1903
|
+
*
|
|
1904
|
+
* 优先使用 `path`;`base64` 仅作为旧会话兼容或无法落盘时的回退。
|
|
1905
|
+
* - 视觉模式(vision: true):从 path 或 base64 读取图片数据传给 LLM API
|
|
1906
|
+
* - 非视觉模式(vision: false):source 用于生成文字占位符
|
|
1907
|
+
*/
|
|
1908
|
+
interface ImageInput {
|
|
1909
|
+
/** 本地文件绝对路径(推荐方式,避免 session 膨胀) */
|
|
1910
|
+
path?: string;
|
|
1911
|
+
/** Base64 编码的图片数据(不含 data URI 前缀),向后兼容 */
|
|
1912
|
+
base64?: string;
|
|
1913
|
+
/** MIME 类型,如 'image/png'、'image/jpeg' */
|
|
1914
|
+
mediaType?: string;
|
|
1915
|
+
/** 来源描述或原始文件名(用于非视觉模式的文字占位符显示) */
|
|
1916
|
+
source?: string;
|
|
1917
|
+
}
|
|
1918
|
+
interface Message {
|
|
1919
|
+
role: MessageRole;
|
|
1920
|
+
content: string;
|
|
1921
|
+
turn?: number;
|
|
1922
|
+
toolCallId?: string;
|
|
1923
|
+
toolCalls?: ToolCall[];
|
|
1924
|
+
reasoning?: string;
|
|
1925
|
+
thinkingBlocks?: ThinkingBlock[];
|
|
1926
|
+
/** 图片附件(user 消息:用户输入的图片;tool 消息:工具返回的图片),多模态输入 */
|
|
1927
|
+
images?: ImageInput[];
|
|
2212
1928
|
/**
|
|
2213
|
-
*
|
|
1929
|
+
* 前端展示数据(仅 tool 消息)。
|
|
1930
|
+
*
|
|
1931
|
+
* 当工具使用 withDisplay() 分离返回时,display 携带富数据(如 diff),
|
|
1932
|
+
* 仅供前端渲染,不注入 LLM 上下文。LLM 只看到 content 中的精简文本。
|
|
2214
1933
|
*/
|
|
2215
|
-
|
|
1934
|
+
display?: unknown;
|
|
2216
1935
|
/**
|
|
2217
|
-
*
|
|
1936
|
+
* 消息来源标记(仅 system 消息使用)。
|
|
1937
|
+
*
|
|
1938
|
+
* - undefined:agent 自身的系统提示词(由 templateResolver 生成),
|
|
1939
|
+
* Anthropic provider 将其放入顶层 system 参数。
|
|
1940
|
+
* - 有值(如 'handoff-seed'、'partial-compact'):Feature 注入的 system 消息,
|
|
1941
|
+
* Anthropic provider 将其包裹为 <reminder> 嵌入最近的 user turn,
|
|
1942
|
+
* 而非混入顶层 system 参数。
|
|
2218
1943
|
*/
|
|
2219
|
-
|
|
1944
|
+
source?: string;
|
|
2220
1945
|
/**
|
|
2221
|
-
*
|
|
1946
|
+
* 消息语义标签(所有 role 通用)。
|
|
1947
|
+
*
|
|
1948
|
+
* 与 source 的区别:
|
|
1949
|
+
* - source 控制 LLM 编译层行为(顶层 system vs reminder)
|
|
1950
|
+
* - tag 控制上下文管理层行为(trim/compact 时的保留策略)
|
|
1951
|
+
*
|
|
1952
|
+
* undefined = 无标签,向后兼容,行为与当前完全一致。
|
|
2222
1953
|
*/
|
|
2223
|
-
|
|
1954
|
+
tag?: string;
|
|
2224
1955
|
/**
|
|
2225
|
-
*
|
|
1956
|
+
* LLM 用量信息(仅 assistant 消息有值)。
|
|
1957
|
+
*
|
|
1958
|
+
* 由 LLM provider 在生成响应时返回,表示生成此消息时的上下文 token 开销。
|
|
1959
|
+
* inputTokens 是发送给 LLM 的完整上下文大小(包含所有历史消息),
|
|
1960
|
+
* 不是单条消息的 token 数。
|
|
2226
1961
|
*/
|
|
2227
|
-
|
|
2228
|
-
start: number;
|
|
2229
|
-
end: number;
|
|
2230
|
-
duration: number;
|
|
2231
|
-
};
|
|
1962
|
+
usage?: MessageUsage;
|
|
2232
1963
|
/**
|
|
2233
|
-
*
|
|
1964
|
+
* 执行终态元数据(仅 assistant 消息有值)。
|
|
1965
|
+
*
|
|
1966
|
+
* 框架在写入错误/截断等执行结果消息时盖戳。展示端(Web UI / 查看器)
|
|
1967
|
+
* 应依据此字段渲染终态样式,而不是解析 content 文本前缀;该字段随
|
|
1968
|
+
* 会话快照持久化,重渲染后保持稳定。
|
|
2234
1969
|
*/
|
|
2235
|
-
|
|
1970
|
+
execution?: MessageExecutionMeta;
|
|
2236
1971
|
}
|
|
2237
|
-
|
|
2238
1972
|
/**
|
|
2239
|
-
*
|
|
2240
|
-
* 管理消息数组,提供简单的操作方法
|
|
1973
|
+
* 消息级执行终态摘要(Message.execution)
|
|
2241
1974
|
*
|
|
2242
|
-
*
|
|
2243
|
-
* - 消息元数据包装(EnrichedMessage)
|
|
2244
|
-
* - 内容解析和索引
|
|
2245
|
-
* - 查询接口
|
|
1975
|
+
* CallOutcome 的可序列化子集;不重复 response/steps 等会话级信息。
|
|
2246
1976
|
*/
|
|
2247
|
-
|
|
1977
|
+
interface MessageExecutionMeta {
|
|
1978
|
+
status: ExecutionStatus;
|
|
1979
|
+
reason: ExecutionReason;
|
|
1980
|
+
error?: ExecutionError;
|
|
1981
|
+
}
|
|
2248
1982
|
/**
|
|
2249
|
-
*
|
|
1983
|
+
* 消息级用量记录(盖戳在 assistant 消息上)
|
|
2250
1984
|
*/
|
|
2251
|
-
interface
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
1985
|
+
interface MessageUsage {
|
|
1986
|
+
/** 生成此消息时,发送给 LLM 的总输入 token(即当时的完整上下文大小) */
|
|
1987
|
+
inputTokens: number;
|
|
1988
|
+
/** LLM 生成的输出 token */
|
|
1989
|
+
outputTokens: number;
|
|
1990
|
+
}
|
|
1991
|
+
interface ThinkingBlock {
|
|
1992
|
+
signature: string;
|
|
1993
|
+
thinking: string;
|
|
1994
|
+
}
|
|
1995
|
+
interface ToolCall {
|
|
1996
|
+
id: string;
|
|
1997
|
+
name: string;
|
|
1998
|
+
arguments: Record<string, any>;
|
|
1999
|
+
}
|
|
2000
|
+
interface LLMResponse {
|
|
2001
|
+
content: string;
|
|
2002
|
+
toolCalls?: ToolCall[];
|
|
2003
|
+
reasoning?: string;
|
|
2004
|
+
thinkingBlocks?: ThinkingBlock[];
|
|
2005
|
+
/** 用量统计(可选) */
|
|
2006
|
+
usage?: UsageInfo;
|
|
2007
|
+
/** 停止原因,由 LLM API 返回(如 end_turn, tool_use, stop 等) */
|
|
2008
|
+
stopReason?: string | null;
|
|
2267
2009
|
}
|
|
2268
2010
|
/**
|
|
2269
|
-
*
|
|
2011
|
+
* 渲染模板项
|
|
2012
|
+
* 可以是字符串模板或函数模板
|
|
2270
2013
|
*/
|
|
2271
|
-
|
|
2272
|
-
version: number;
|
|
2273
|
-
messages: Message[];
|
|
2274
|
-
enrichedMessages?: EnrichedMessage[];
|
|
2275
|
-
sequence?: number;
|
|
2276
|
-
generation?: number;
|
|
2277
|
-
/** 截断归档(tombstone)。旧快照可能没有该字段,加载时视为空归档。 */
|
|
2278
|
-
tombstones?: ContextTombstoneEntry[];
|
|
2279
|
-
}
|
|
2014
|
+
type RenderTemplateItem = string | RenderTemplateFn;
|
|
2280
2015
|
/**
|
|
2281
|
-
*
|
|
2282
|
-
*
|
|
2283
|
-
* 记录某个时间点两个数组的长度、sequence 和 generation,
|
|
2284
|
-
* 截断时只需按长度切片即可恢复到该边界。
|
|
2285
|
-
*
|
|
2286
|
-
* generation 用于防止 ABA 问题:如果 Context 经历了
|
|
2287
|
-
* clear/apply/restore 等非追加 mutation,generation 会递增,
|
|
2288
|
-
* 旧 boundary 会被拒绝。
|
|
2016
|
+
* 渲染模板函数类型
|
|
2289
2017
|
*/
|
|
2290
|
-
|
|
2291
|
-
messagesLength: number;
|
|
2292
|
-
enrichedMessagesLength: number;
|
|
2293
|
-
sequence: number;
|
|
2294
|
-
generation: number;
|
|
2295
|
-
}
|
|
2018
|
+
type RenderTemplateFn = (data: Record<string, any>, success?: boolean) => string;
|
|
2296
2019
|
/**
|
|
2297
|
-
*
|
|
2020
|
+
* 内联渲染模板
|
|
2021
|
+
* 直接定义在工具中的渲染模板(无需引用预设模板)
|
|
2298
2022
|
*/
|
|
2299
|
-
interface
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
/**
|
|
2305
|
-
|
|
2306
|
-
/**
|
|
2307
|
-
|
|
2023
|
+
interface InlineRenderTemplate {
|
|
2024
|
+
call: RenderTemplateItem;
|
|
2025
|
+
result: RenderTemplateItem;
|
|
2026
|
+
}
|
|
2027
|
+
interface ToolRenderConfig {
|
|
2028
|
+
/** 调用时的渲染模板(字符串引用或内联模板) */
|
|
2029
|
+
call?: string | InlineRenderTemplate;
|
|
2030
|
+
/** 结果时的渲染模板(字符串引用或内联模板) */
|
|
2031
|
+
result?: string | InlineRenderTemplate;
|
|
2032
|
+
}
|
|
2033
|
+
interface LLMClient {
|
|
2034
|
+
chat(messages: Message[], tools: Tool[], options?: LLMChatOptions): Promise<LLMResponse>;
|
|
2035
|
+
/** 可选:返回当前 LLM 实例使用的模型名(用于调试显示) */
|
|
2036
|
+
readonly modelName?: string;
|
|
2037
|
+
}
|
|
2038
|
+
interface LLMChatOptions {
|
|
2039
|
+
/** 允许中断正在进行的 LLM 调用 */
|
|
2040
|
+
signal?: AbortSignal;
|
|
2041
|
+
/** 请求非流式响应(适用于一次性摘要、标题生成等场景) */
|
|
2042
|
+
noStream?: boolean;
|
|
2308
2043
|
}
|
|
2309
2044
|
/**
|
|
2310
|
-
*
|
|
2045
|
+
* 可热更新的模型元数据(与 LLMClient 实例解耦)
|
|
2311
2046
|
*
|
|
2312
|
-
*
|
|
2313
|
-
*
|
|
2314
|
-
* 可完整恢复(restoreTombstone)。
|
|
2047
|
+
* 用于 Agent.setLLM() 时传递模型上下文信息,
|
|
2048
|
+
* 供 Feature(如 ContextGuard)根据新模型的 contextLength 调整行为。
|
|
2315
2049
|
*/
|
|
2316
|
-
interface
|
|
2317
|
-
|
|
2318
|
-
|
|
2050
|
+
interface LLMMeta {
|
|
2051
|
+
modelName?: string;
|
|
2052
|
+
contextLength?: number | null;
|
|
2053
|
+
compressRatio?: number;
|
|
2054
|
+
presetName?: string;
|
|
2055
|
+
thinkingEffort?: string | null;
|
|
2056
|
+
/** 模型协议('anthropic' | 'openai' 等),由 resolver 提供时携带,供档位切换等消费方推断协议 */
|
|
2057
|
+
provider?: string;
|
|
2058
|
+
/** 本次切换的发起方标记:'boot' | 'user' | 'feature:<name>' 等,供让位策略区分用户手动切换与 Feature 切换 */
|
|
2059
|
+
source?: string;
|
|
2319
2060
|
}
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2061
|
+
/**
|
|
2062
|
+
* resolver 解析产物:成品 LLM 客户端 + 对齐 LLMMeta 的元数据。
|
|
2063
|
+
* 资产(apiKey / OAuth token / 配置文件)由注入方持有,永不进入本结构。
|
|
2064
|
+
*/
|
|
2065
|
+
interface ResolvedModelPreset {
|
|
2066
|
+
llm: AgentConfig['llm'];
|
|
2067
|
+
meta: LLMMeta;
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* 模型 preset 解析服务契约(应用层注入,core 不提供实现)。
|
|
2071
|
+
*
|
|
2072
|
+
* 框架只编排"怎么换"(resolve → setLLM → 贴标 → 通知);
|
|
2073
|
+
* "有哪些 preset、凭证在哪、客户端怎么造"归应用层。每次调用都应现读
|
|
2074
|
+
* 配置源(不缓存快照),调用方可安全地以任意频率重复调用。
|
|
2075
|
+
*/
|
|
2076
|
+
interface ModelPresetResolver {
|
|
2334
2077
|
/**
|
|
2335
|
-
*
|
|
2336
|
-
*
|
|
2078
|
+
* @param presetName preset 名(应用层命名空间,如 Claw 的 presets.json 条目名)
|
|
2079
|
+
* @param overrides 运行时覆盖;thinkingEffort 为 null 表示清除为厂商默认。
|
|
2080
|
+
* @returns 解析失败(名字不存在 / 凭证缺失)返回 null,不抛错
|
|
2337
2081
|
*/
|
|
2338
|
-
|
|
2339
|
-
|
|
2082
|
+
resolve(presetName: string, overrides?: {
|
|
2083
|
+
thinkingEffort?: string | null;
|
|
2084
|
+
}): ResolvedModelPreset | null;
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
interface AgentConfig {
|
|
2088
|
+
llm: LLMClient;
|
|
2089
|
+
tools?: Tool[];
|
|
2090
|
+
maxTurns?: number;
|
|
2091
|
+
systemMessage?: string | TemplateSource;
|
|
2092
|
+
name?: string;
|
|
2093
|
+
projectRoot?: string;
|
|
2094
|
+
workspaceDir?: string;
|
|
2340
2095
|
/**
|
|
2341
|
-
*
|
|
2096
|
+
* 模型 preset 解析服务(可选注入)。
|
|
2097
|
+
* 注入后 setModel / setThinkingEffort 可用;资产留在注入方,agent 只拿成品客户端。
|
|
2342
2098
|
*/
|
|
2343
|
-
|
|
2099
|
+
modelResolver?: ModelPresetResolver;
|
|
2344
2100
|
/**
|
|
2345
|
-
*
|
|
2101
|
+
* Feature 配置
|
|
2102
|
+
*
|
|
2103
|
+
* 新的声明式 Feature 注册方式
|
|
2346
2104
|
*/
|
|
2347
|
-
|
|
2105
|
+
features?: {
|
|
2106
|
+
/** 启用的 Feature 列表 */
|
|
2107
|
+
enabled?: string[];
|
|
2108
|
+
/** Feature 特定配置 */
|
|
2109
|
+
[key: string]: unknown;
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
type ContextMiddleware = (messages: Message[]) => Message[];
|
|
2113
|
+
/**
|
|
2114
|
+
* Agent 注册信息(Hub 端)
|
|
2115
|
+
*/
|
|
2116
|
+
interface AgentInfo {
|
|
2117
|
+
id: string;
|
|
2118
|
+
name: string;
|
|
2119
|
+
registeredAt: number;
|
|
2120
|
+
projectRoot?: string;
|
|
2121
|
+
}
|
|
2122
|
+
/**
|
|
2123
|
+
* 工具元数据(用于前端渲染)
|
|
2124
|
+
*/
|
|
2125
|
+
interface ToolMetadata {
|
|
2126
|
+
name: string;
|
|
2127
|
+
description: string;
|
|
2128
|
+
render: {
|
|
2129
|
+
call: string | InlineRenderTemplate;
|
|
2130
|
+
result: string | InlineRenderTemplate;
|
|
2131
|
+
inlineCall?: InlineRenderTemplate;
|
|
2132
|
+
inlineResult?: InlineRenderTemplate;
|
|
2133
|
+
};
|
|
2134
|
+
}
|
|
2135
|
+
interface HookSourceLocation {
|
|
2136
|
+
file?: string;
|
|
2137
|
+
line?: number;
|
|
2138
|
+
column?: number;
|
|
2139
|
+
display: string;
|
|
2140
|
+
}
|
|
2141
|
+
interface HookEntryMetadata {
|
|
2142
|
+
order: number;
|
|
2143
|
+
featureName: string;
|
|
2144
|
+
methodName: string;
|
|
2145
|
+
lifecycle: string;
|
|
2146
|
+
/** 三原语(observe / guard / transform),由静态声明或装饰器路径推导 */
|
|
2147
|
+
kind: 'observe' | 'guard' | 'transform';
|
|
2148
|
+
/** guard 角色(policy 先于 advisor 执行)。仅 kind='guard' 条目存在。 */
|
|
2149
|
+
role?: 'policy' | 'advisor';
|
|
2150
|
+
source?: HookSourceLocation;
|
|
2151
|
+
description?: string;
|
|
2152
|
+
/** 是否启用。false 表示被运行时禁用。缺省视为 true(向后兼容)。 */
|
|
2153
|
+
enabled?: boolean;
|
|
2154
|
+
}
|
|
2155
|
+
interface HookLifecycleSnapshot {
|
|
2156
|
+
lifecycle: string;
|
|
2157
|
+
/** 生命周期级三原语汇总:桶内有 guard → guard,有 transform → transform,否则 observe */
|
|
2158
|
+
kind: 'observe' | 'guard' | 'transform';
|
|
2159
|
+
entries: HookEntryMetadata[];
|
|
2160
|
+
}
|
|
2161
|
+
interface FeatureInspectorSnapshot {
|
|
2162
|
+
name: string;
|
|
2163
|
+
enabled: boolean;
|
|
2164
|
+
status: 'enabled' | 'disabled' | 'removed' | 'partial';
|
|
2165
|
+
hookCount: number;
|
|
2166
|
+
toolCount: number;
|
|
2167
|
+
enabledToolCount: number;
|
|
2168
|
+
source?: string;
|
|
2169
|
+
description?: string;
|
|
2170
|
+
tools: Array<{
|
|
2171
|
+
name: string;
|
|
2172
|
+
description: string;
|
|
2173
|
+
state: 'enabled' | 'disabled' | 'removed' | 'superseded';
|
|
2174
|
+
enabled?: boolean;
|
|
2175
|
+
renderCall?: string;
|
|
2176
|
+
renderResult?: string;
|
|
2177
|
+
parameters?: Record<string, unknown>;
|
|
2178
|
+
}>;
|
|
2179
|
+
}
|
|
2180
|
+
interface HookInspectorSnapshot {
|
|
2181
|
+
lifecycleOrder: string[];
|
|
2182
|
+
features: FeatureInspectorSnapshot[];
|
|
2183
|
+
hooks: HookLifecycleSnapshot[];
|
|
2184
|
+
standaloneTools?: Array<{
|
|
2185
|
+
name: string;
|
|
2186
|
+
description: string;
|
|
2187
|
+
state: 'enabled' | 'disabled' | 'removed' | 'superseded';
|
|
2188
|
+
enabled?: boolean;
|
|
2189
|
+
source?: string;
|
|
2190
|
+
renderCall?: string;
|
|
2191
|
+
renderResult?: string;
|
|
2192
|
+
parameters?: Record<string, unknown>;
|
|
2193
|
+
}>;
|
|
2194
|
+
}
|
|
2195
|
+
interface AgentContextMetrics {
|
|
2196
|
+
messageCount: number;
|
|
2197
|
+
charCount: number;
|
|
2198
|
+
toolCallCount: number;
|
|
2199
|
+
turnCount: number;
|
|
2200
|
+
}
|
|
2201
|
+
interface AgentOverviewSnapshot {
|
|
2202
|
+
updatedAt: number;
|
|
2203
|
+
context: AgentContextMetrics;
|
|
2204
|
+
usageStats: UsageStatsSnapshot;
|
|
2205
|
+
runtime?: AgentRuntimeStateSnapshot;
|
|
2206
|
+
/** 可选:当前使用的模型名(由 agent 实例注入) */
|
|
2207
|
+
modelName?: string;
|
|
2208
|
+
/** 可选:当前使用的预设名(由 agent 实例注入,用于 UI dropdown 高亮) */
|
|
2209
|
+
presetName?: string;
|
|
2210
|
+
/** 可选:当前 LLM 实例的思考强度(由 agent 实例注入,用于 UI 状态同步) */
|
|
2211
|
+
thinkingEffort?: string | null;
|
|
2212
|
+
/** 可选:当前模型的上下文窗口长度(由 agent 实例注入,用于 UI 用量条实时同步) */
|
|
2213
|
+
contextLength?: number;
|
|
2214
|
+
/** 可选:当前模型的压缩阈值百分比(由 agent 实例注入,用于 UI 用量条实时同步) */
|
|
2215
|
+
compressRatio?: number;
|
|
2216
|
+
}
|
|
2217
|
+
interface TodoTaskSnapshot {
|
|
2218
|
+
id: string;
|
|
2219
|
+
subject: string;
|
|
2220
|
+
description: string;
|
|
2221
|
+
status: 'pending' | 'in_progress' | 'completed' | 'deleted';
|
|
2222
|
+
metadata?: Record<string, unknown>;
|
|
2223
|
+
createdAt: number;
|
|
2224
|
+
updatedAt: number;
|
|
2225
|
+
}
|
|
2226
|
+
interface TodoPlanSummary {
|
|
2227
|
+
total: number;
|
|
2228
|
+
pending: number;
|
|
2229
|
+
inProgress: number;
|
|
2230
|
+
completed: number;
|
|
2231
|
+
cancelled: number;
|
|
2232
|
+
}
|
|
2233
|
+
interface TodoPlanSnapshot {
|
|
2234
|
+
feature: 'todo';
|
|
2235
|
+
updatedAt: number;
|
|
2236
|
+
counter: number;
|
|
2237
|
+
tasks: TodoTaskSnapshot[];
|
|
2238
|
+
summary: TodoPlanSummary;
|
|
2239
|
+
/** 中断目标 task ID(由 ControlledTodoFeature 扩展,null = 无中断目标) */
|
|
2240
|
+
interruptTargetId?: string | null;
|
|
2241
|
+
/** 任务未完强制继续开关状态(由 ControlledTodoFeature 扩展,null = 未上报) */
|
|
2242
|
+
forceContinue?: {
|
|
2243
|
+
enabled: boolean;
|
|
2244
|
+
consecutive: number;
|
|
2245
|
+
max: number;
|
|
2246
|
+
} | null;
|
|
2247
|
+
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Agent 会话数据(Worker 端)
|
|
2250
|
+
*/
|
|
2251
|
+
interface AgentSession {
|
|
2252
|
+
id: string;
|
|
2253
|
+
name: string;
|
|
2254
|
+
messages: Message[];
|
|
2255
|
+
tools: ToolMetadata[];
|
|
2256
|
+
createdAt: number;
|
|
2257
|
+
lastActive: number;
|
|
2258
|
+
projectRoot?: string;
|
|
2259
|
+
currentState: Notification | null;
|
|
2260
|
+
callActive?: boolean;
|
|
2261
|
+
runtimeState?: AgentRuntimeStateSnapshot;
|
|
2262
|
+
events: Notification[];
|
|
2263
|
+
lastEventCount: number;
|
|
2264
|
+
logs: DebugLogEntry[];
|
|
2265
|
+
clientId?: string;
|
|
2266
|
+
_lastMessageSig?: string;
|
|
2267
|
+
hookInspector?: HookInspectorSnapshot;
|
|
2268
|
+
overview?: AgentOverviewSnapshot;
|
|
2269
|
+
todoPlan?: TodoPlanSnapshot;
|
|
2348
2270
|
/**
|
|
2349
|
-
*
|
|
2271
|
+
* 唯一的活动输入租约。一个 Agent 实例在任意时刻只能由一个输入请求
|
|
2272
|
+
* 消费用户回复;这是跨 reconnect / 多进程路由的归属锚点。
|
|
2350
2273
|
*/
|
|
2351
|
-
|
|
2274
|
+
inputLease?: InputLease;
|
|
2275
|
+
queuedInputs: QueuedInput[];
|
|
2352
2276
|
/**
|
|
2353
|
-
*
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
* 获取最后一条消息
|
|
2358
|
-
*/
|
|
2359
|
-
getLast(): Message | undefined;
|
|
2360
|
-
/**
|
|
2361
|
-
* 清空消息
|
|
2362
|
-
*/
|
|
2363
|
-
clear(): void;
|
|
2364
|
-
/**
|
|
2365
|
-
* 应用中间件处理消息
|
|
2366
|
-
*/
|
|
2367
|
-
apply(middleware: (messages: Message[]) => Message[]): this;
|
|
2368
|
-
/**
|
|
2369
|
-
* 过滤消息
|
|
2370
|
-
*/
|
|
2371
|
-
filter(predicate: (msg: Message) => boolean): Message[];
|
|
2372
|
-
/**
|
|
2373
|
-
* 切片
|
|
2374
|
-
*/
|
|
2375
|
-
slice(start?: number, end?: number): Message[];
|
|
2376
|
-
/**
|
|
2377
|
-
* 序列化为快照
|
|
2378
|
-
*/
|
|
2379
|
-
toJSON(): ContextSnapshot;
|
|
2380
|
-
/**
|
|
2381
|
-
* 从快照恢复
|
|
2382
|
-
*/
|
|
2383
|
-
static fromJSON(snapshot: ContextSnapshot): Context;
|
|
2384
|
-
/**
|
|
2385
|
-
* 用快照原地恢复当前 Context
|
|
2386
|
-
*/
|
|
2387
|
-
restore(snapshot: ContextSnapshot): this;
|
|
2388
|
-
/**
|
|
2389
|
-
* 序列化为 JSON 字符串
|
|
2390
|
-
*/
|
|
2391
|
-
serialize(): string;
|
|
2392
|
-
/**
|
|
2393
|
-
* 从 JSON 字符串反序列化
|
|
2394
|
-
*/
|
|
2395
|
-
static deserialize(json: string): Context;
|
|
2396
|
-
/**
|
|
2397
|
-
* 统一消息入口(内部方法)
|
|
2398
|
-
*/
|
|
2399
|
-
private addMessage;
|
|
2400
|
-
/**
|
|
2401
|
-
* 添加用户消息
|
|
2402
|
-
*/
|
|
2403
|
-
addUserMessage(content: string, turn: number, images?: ImageInput[]): void;
|
|
2404
|
-
/**
|
|
2405
|
-
* 添加助手响应
|
|
2406
|
-
*
|
|
2407
|
-
* 框架合成消息(错误/截断说明)可通过 execution 字段附带执行终态元数据。
|
|
2408
|
-
*/
|
|
2409
|
-
addAssistantMessage(response: LLMResponse & {
|
|
2410
|
-
execution?: MessageExecutionMeta;
|
|
2411
|
-
}, turn: number): void;
|
|
2412
|
-
/**
|
|
2413
|
-
* 添加工具结果
|
|
2414
|
-
*/
|
|
2415
|
-
addToolMessage(call: ToolCall, result: ToolExecResult, turn: number): void;
|
|
2416
|
-
/**
|
|
2417
|
-
* 添加已经序列化的工具消息。
|
|
2418
|
-
*
|
|
2419
|
-
* 用于 session/handoff 恢复等边界:原始 tool content 已经是 provider 可重放的
|
|
2420
|
-
* 序列化字符串,不应先解析成 ToolExecResult 再重新编码。该入口同时维护
|
|
2421
|
-
* messages[] 与 enrichedMessages[],并保留工具返回的图片附件。
|
|
2422
|
-
*/
|
|
2423
|
-
addSerializedToolMessage(toolCallId: string, content: string, turn: number, images?: ImageInput[], display?: unknown): void;
|
|
2424
|
-
/**
|
|
2425
|
-
* 添加系统消息
|
|
2426
|
-
*/
|
|
2427
|
-
addSystemMessage(content: string, turn: number, source?: string, tag?: string): void;
|
|
2428
|
-
/**
|
|
2429
|
-
* 查询构建器
|
|
2430
|
-
*/
|
|
2431
|
-
query(): ContextQuery;
|
|
2432
|
-
/**
|
|
2433
|
-
* 按轮次获取消息
|
|
2434
|
-
*/
|
|
2435
|
-
getByTurn(turn: number): EnrichedMessage[];
|
|
2436
|
-
/**
|
|
2437
|
-
* 获取最近 N 条消息
|
|
2438
|
-
*/
|
|
2439
|
-
getRecent(n: number): EnrichedMessage[];
|
|
2440
|
-
/**
|
|
2441
|
-
* 获取所有丰富化消息(内部使用)
|
|
2442
|
-
*/
|
|
2443
|
-
getAllEnriched(): EnrichedMessage[];
|
|
2444
|
-
/**
|
|
2445
|
-
* 丰富化消息:添加元数据
|
|
2446
|
-
*/
|
|
2447
|
-
private enrich;
|
|
2448
|
-
/**
|
|
2449
|
-
* 推断消息标签
|
|
2450
|
-
*/
|
|
2451
|
-
private inferTags;
|
|
2452
|
-
/**
|
|
2453
|
-
* 解析 content 提取结构化信息
|
|
2454
|
-
*/
|
|
2455
|
-
private parseContent;
|
|
2456
|
-
/**
|
|
2457
|
-
* 更新索引
|
|
2458
|
-
*/
|
|
2459
|
-
private updateIndexes;
|
|
2460
|
-
/**
|
|
2461
|
-
* 从 enrichedMessages 重建索引
|
|
2462
|
-
*/
|
|
2463
|
-
private rebuildIndexes;
|
|
2464
|
-
/**
|
|
2465
|
-
* 生成唯一 ID
|
|
2466
|
-
*/
|
|
2467
|
-
private generateId;
|
|
2468
|
-
/**
|
|
2469
|
-
* 捕获当前 Context 的前缀边界。
|
|
2470
|
-
*
|
|
2471
|
-
* 返回一个轻量快照,记录两个数组的长度、sequence 和 generation。
|
|
2472
|
-
* 后续可传给 truncateToBoundary() 恢复到此边界。
|
|
2473
|
-
*
|
|
2474
|
-
* generation 不变:纯读取操作。
|
|
2475
|
-
*/
|
|
2476
|
-
captureBoundary(): ContextBoundaryV2;
|
|
2477
|
-
/**
|
|
2478
|
-
* 校验 boundary 是否与当前 Context 兼容。
|
|
2479
|
-
*
|
|
2480
|
-
* @throws 如果 generation 不匹配、长度非法或超出当前数组。
|
|
2481
|
-
*/
|
|
2482
|
-
private assertBoundaryCompatible;
|
|
2483
|
-
/**
|
|
2484
|
-
* 将两个数组截断到指定边界。
|
|
2485
|
-
*
|
|
2486
|
-
* 这是合法的 rollback 操作:generation 保持不变,
|
|
2487
|
-
* 截断后同一 lineage 的旧 boundary 仍然可以继续使用。
|
|
2488
|
-
*
|
|
2489
|
-
* 被截尾部进入 tombstone 归档(不物理丢失):
|
|
2490
|
-
* 通过 listTombstones() / getTombstone() 查询,
|
|
2491
|
-
* Context 仍处于该边界时可通过 restoreTombstone() 完整恢复。
|
|
2492
|
-
*
|
|
2493
|
-
* @throws 如果 boundary 与当前 Context 不兼容(generation 不匹配或长度越界)。
|
|
2494
|
-
*/
|
|
2495
|
-
truncateToBoundary(boundary: ContextBoundaryV2): void;
|
|
2496
|
-
/**
|
|
2497
|
-
* 列出 tombstone 摘要(不含消息内容)。
|
|
2277
|
+
* 外部用户回合的接受策略,注册时声明。
|
|
2278
|
+
* 'standard'(默认):接受聊天邮箱排队与输入租约。
|
|
2279
|
+
* 'none':拒绝排队注入;测试沙盒等由宿主进程驱动输入的运行时使用。
|
|
2280
|
+
* 输入租约(interactive input request)不受此策略限制,仍由 feature 控制。
|
|
2498
2281
|
*/
|
|
2499
|
-
|
|
2282
|
+
inputPolicy?: 'standard' | 'none';
|
|
2283
|
+
}
|
|
2284
|
+
interface InputLease {
|
|
2285
|
+
requestId: string;
|
|
2286
|
+
prompt: string;
|
|
2287
|
+
placeholder?: string;
|
|
2288
|
+
initialValue?: string;
|
|
2289
|
+
actions?: UserInputAction[];
|
|
2290
|
+
mode?: UserInputRequestMode;
|
|
2291
|
+
questions?: UserInputQuestion[];
|
|
2292
|
+
timestamp: number;
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* 排队的用户输入
|
|
2296
|
+
*/
|
|
2297
|
+
interface QueuedInput {
|
|
2298
|
+
id: string;
|
|
2299
|
+
text: string;
|
|
2300
|
+
timestamp: number;
|
|
2301
|
+
/** 图片附件(多模态输入) */
|
|
2302
|
+
images?: ImageInput[];
|
|
2303
|
+
/** 稳定的输入来源标识,供宿主诊断和后续路由扩展使用 */
|
|
2304
|
+
source?: string;
|
|
2305
|
+
/** 来源侧事件/请求标识,不承担全局幂等语义 */
|
|
2306
|
+
sourceRef?: string;
|
|
2307
|
+
/** 随消息流动的能力激活通知(capability refs,如 skill.grill-me) */
|
|
2308
|
+
capabilityActivations?: string[];
|
|
2309
|
+
}
|
|
2310
|
+
/**
|
|
2311
|
+
* 一个不绑定具体 input request 的新用户回合。
|
|
2312
|
+
*
|
|
2313
|
+
* ViewerWorker 会原子决定:若存在兼容的文本 input request,则直接响应;
|
|
2314
|
+
* 否则进入该已连接 runtime 的会话邮箱,等待下一次兼容的文本输入租约。
|
|
2315
|
+
* 这覆盖新建/恢复会话在输入循环尚未打开的启动窗口,不依赖 callActive。
|
|
2316
|
+
*/
|
|
2317
|
+
interface UserTurnInput {
|
|
2318
|
+
text: string;
|
|
2319
|
+
images?: ImageInput[];
|
|
2320
|
+
source?: string;
|
|
2321
|
+
sourceRef?: string;
|
|
2322
|
+
/** 随消息流动的能力激活通知(capability refs);经 lease 响应 payload 与排队项原样随行 */
|
|
2323
|
+
capabilityActivations?: string[];
|
|
2324
|
+
}
|
|
2325
|
+
type UserTurnSubmissionResult = {
|
|
2326
|
+
success: true;
|
|
2327
|
+
delivery: 'input';
|
|
2328
|
+
requestId: string;
|
|
2329
|
+
source?: string;
|
|
2330
|
+
sourceRef?: string;
|
|
2331
|
+
} | {
|
|
2332
|
+
success: true;
|
|
2333
|
+
delivery: 'queued';
|
|
2334
|
+
id: string;
|
|
2335
|
+
queueLength: number;
|
|
2336
|
+
source?: string;
|
|
2337
|
+
sourceRef?: string;
|
|
2338
|
+
} | {
|
|
2339
|
+
success: false;
|
|
2340
|
+
code: 'agent_not_found' | 'invalid_input' | 'input_mode_conflict' | 'runtime_not_accepting_input';
|
|
2341
|
+
error: string;
|
|
2342
|
+
pendingMode?: UserInputRequestMode;
|
|
2343
|
+
};
|
|
2344
|
+
/**
|
|
2345
|
+
* DebugHub IPC 消息类型(主进程 → Worker)
|
|
2346
|
+
* 使用 discriminated union 确保类型安全
|
|
2347
|
+
*/
|
|
2348
|
+
type DebugHubIPCMessage = RegisterAgentMsg | UpdateAgentInspectorMsg | UpdateAgentOverviewMsg | UpdateTodoPlanMsg | PushMessagesMsg | RegisterToolsMsg | UnregisterAgentMsg | PushNotificationMsg | RequestInputMsg | InputRequestCancelledMsg | InterruptAgentMsg | StopMsg;
|
|
2349
|
+
/**
|
|
2350
|
+
* 注册新 Agent
|
|
2351
|
+
*/
|
|
2352
|
+
interface RegisterAgentMsg {
|
|
2353
|
+
type: 'register-agent';
|
|
2354
|
+
agentId: string;
|
|
2355
|
+
name: string;
|
|
2356
|
+
createdAt: number;
|
|
2357
|
+
projectRoot?: string;
|
|
2500
2358
|
/**
|
|
2501
|
-
*
|
|
2359
|
+
* 模板装载点:Feature 所属包的真实目录根(junction 已解析)。
|
|
2360
|
+
* Agent 侧是唯一知道权威 mount root 的一层(来自 feature.getPackageInfo()),
|
|
2361
|
+
* 注册只传事实,不做 URL 推导;URL 由 viewer-worker 分配。
|
|
2502
2362
|
*/
|
|
2503
|
-
|
|
2363
|
+
templateMounts?: string[];
|
|
2504
2364
|
/**
|
|
2505
|
-
*
|
|
2506
|
-
*
|
|
2507
|
-
* 仅当 Context 仍精确处于该 tombstone 的边界时允许
|
|
2508
|
-
* (generation、两个数组长度、sequence 全部匹配)——此时恢复是
|
|
2509
|
-
* 截断的精确逆操作,不破坏 lineage。
|
|
2510
|
-
*
|
|
2511
|
-
* 恢复后 sequence 续接被截尾部的最大序号,generation 不变。
|
|
2512
|
-
*
|
|
2513
|
-
* @throws 如果 Context 已离开该边界(例如截断后追加了新消息)。
|
|
2514
|
-
* 此时内容仍可通过 getTombstone() 提取,由调用方决定如何重组。
|
|
2365
|
+
* 模板名 → 装载条目。mount 为 templateMounts 数组下标,
|
|
2366
|
+
* rel 为该 mount root 下的相对路径(POSIX 分隔符)。
|
|
2515
2367
|
*/
|
|
2516
|
-
|
|
2368
|
+
templateEntries?: Record<string, {
|
|
2369
|
+
mount: number;
|
|
2370
|
+
rel: string;
|
|
2371
|
+
}>;
|
|
2372
|
+
hookInspector?: HookInspectorSnapshot;
|
|
2373
|
+
overview?: AgentOverviewSnapshot;
|
|
2374
|
+
activeInputRequest?: ActiveInputRequest;
|
|
2375
|
+
inputPolicy?: 'standard' | 'none';
|
|
2376
|
+
}
|
|
2377
|
+
interface UpdateAgentInspectorMsg {
|
|
2378
|
+
type: 'update-agent-inspector';
|
|
2379
|
+
agentId: string;
|
|
2380
|
+
hookInspector: HookInspectorSnapshot;
|
|
2381
|
+
}
|
|
2382
|
+
interface UpdateAgentOverviewMsg {
|
|
2383
|
+
type: 'update-agent-overview';
|
|
2384
|
+
agentId: string;
|
|
2385
|
+
overview: AgentOverviewSnapshot;
|
|
2386
|
+
}
|
|
2387
|
+
interface UpdateTodoPlanMsg {
|
|
2388
|
+
type: 'update-todo-plan';
|
|
2389
|
+
agentId: string;
|
|
2390
|
+
plan: TodoPlanSnapshot;
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* 推送 Agent 消息
|
|
2394
|
+
*/
|
|
2395
|
+
interface PushMessagesMsg {
|
|
2396
|
+
type: 'push-messages';
|
|
2397
|
+
agentId: string;
|
|
2398
|
+
messages: Message[];
|
|
2399
|
+
}
|
|
2400
|
+
/**
|
|
2401
|
+
* 注册 Agent 工具
|
|
2402
|
+
*/
|
|
2403
|
+
interface RegisterToolsMsg {
|
|
2404
|
+
type: 'register-tools';
|
|
2405
|
+
agentId: string;
|
|
2406
|
+
tools: Tool[];
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* 活跃的输入请求(用于重连后恢复)
|
|
2410
|
+
*/
|
|
2411
|
+
interface ActiveInputRequest {
|
|
2412
|
+
requestId: string;
|
|
2413
|
+
prompt: string;
|
|
2414
|
+
placeholder?: string;
|
|
2415
|
+
initialValue?: string;
|
|
2416
|
+
actions?: UserInputAction[];
|
|
2417
|
+
timestamp: number;
|
|
2418
|
+
}
|
|
2419
|
+
/**
|
|
2420
|
+
* 注销 Agent
|
|
2421
|
+
*/
|
|
2422
|
+
interface UnregisterAgentMsg {
|
|
2423
|
+
type: 'unregister-agent';
|
|
2424
|
+
agentId: string;
|
|
2425
|
+
}
|
|
2426
|
+
/**
|
|
2427
|
+
* 停止 Worker
|
|
2428
|
+
*/
|
|
2429
|
+
interface StopMsg {
|
|
2430
|
+
type: 'stop';
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* 推送通知
|
|
2434
|
+
*/
|
|
2435
|
+
interface PushNotificationMsg {
|
|
2436
|
+
type: 'push-notification';
|
|
2437
|
+
agentId: string;
|
|
2438
|
+
notification: Notification;
|
|
2439
|
+
}
|
|
2440
|
+
/**
|
|
2441
|
+
* 请求用户输入
|
|
2442
|
+
*/
|
|
2443
|
+
interface RequestInputMsg {
|
|
2444
|
+
type: 'request-input';
|
|
2445
|
+
agentId: string;
|
|
2446
|
+
requestId: string;
|
|
2447
|
+
prompt: string;
|
|
2448
|
+
timeout?: number;
|
|
2449
|
+
placeholder?: string;
|
|
2450
|
+
initialValue?: string;
|
|
2451
|
+
actions?: UserInputAction[];
|
|
2452
|
+
mode?: UserInputRequestMode;
|
|
2453
|
+
questions?: UserInputQuestion[];
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* 通知 Worker 一个输入请求已被运行时结算/取消(中断、销毁等)。
|
|
2457
|
+
* Worker 持有同名 inputLease 作为 HTTP 投递面;收到后应清除对应租约,
|
|
2458
|
+
* 否则陈旧租约会永久阻塞后续 user-turn(input_mode_conflict)。
|
|
2459
|
+
*/
|
|
2460
|
+
interface InputRequestCancelledMsg {
|
|
2461
|
+
type: 'input-request-cancelled';
|
|
2462
|
+
agentId: string;
|
|
2463
|
+
requestId: string;
|
|
2464
|
+
}
|
|
2465
|
+
/**
|
|
2466
|
+
* 中断正在运行的 Agent
|
|
2467
|
+
*/
|
|
2468
|
+
interface InterruptAgentMsg {
|
|
2469
|
+
type: 'interrupt-agent';
|
|
2470
|
+
agentId: string;
|
|
2471
|
+
clearQueue?: boolean;
|
|
2472
|
+
}
|
|
2473
|
+
interface UserInputAction {
|
|
2474
|
+
id: string;
|
|
2475
|
+
label: string;
|
|
2476
|
+
kind?: 'rollback' | 'custom';
|
|
2477
|
+
variant?: 'primary' | 'secondary' | 'danger';
|
|
2478
|
+
payload?: Record<string, unknown>;
|
|
2479
|
+
}
|
|
2480
|
+
type UserInputRequestMode = 'text' | 'choices';
|
|
2481
|
+
interface UserInputOption {
|
|
2482
|
+
id: string;
|
|
2483
|
+
label: string;
|
|
2484
|
+
description?: string;
|
|
2485
|
+
/** Whether this option allows supplementary free-text input */
|
|
2486
|
+
allowSupplement?: boolean;
|
|
2487
|
+
/** Whether the supplement text is required (only meaningful when allowSupplement is true) */
|
|
2488
|
+
supplementRequired?: boolean;
|
|
2489
|
+
/** Label shown above the supplement textarea */
|
|
2490
|
+
supplementLabel?: string;
|
|
2491
|
+
/** Placeholder for the supplement textarea */
|
|
2492
|
+
supplementPlaceholder?: string;
|
|
2493
|
+
}
|
|
2494
|
+
interface UserInputQuestion {
|
|
2495
|
+
id: string;
|
|
2496
|
+
question: string;
|
|
2497
|
+
options: UserInputOption[];
|
|
2498
|
+
allowCustom?: boolean;
|
|
2499
|
+
customLabel?: string;
|
|
2500
|
+
customPlaceholder?: string;
|
|
2501
|
+
}
|
|
2502
|
+
interface UserInputRequest {
|
|
2503
|
+
prompt: string;
|
|
2504
|
+
placeholder?: string;
|
|
2505
|
+
initialValue?: string;
|
|
2506
|
+
actions?: UserInputAction[];
|
|
2507
|
+
mode?: UserInputRequestMode;
|
|
2508
|
+
questions?: UserInputQuestion[];
|
|
2509
|
+
}
|
|
2510
|
+
interface UserInputChoiceAnswer {
|
|
2511
|
+
questionId: string;
|
|
2512
|
+
optionId?: string;
|
|
2513
|
+
customText?: string;
|
|
2514
|
+
/** Supplementary free-text provided alongside the selected option */
|
|
2515
|
+
supplementText?: string;
|
|
2516
|
+
}
|
|
2517
|
+
interface UserInputResponse {
|
|
2518
|
+
kind: 'text' | 'action' | 'choices';
|
|
2519
|
+
text?: string;
|
|
2520
|
+
actionId?: string;
|
|
2521
|
+
choices?: UserInputChoiceAnswer[];
|
|
2522
|
+
payload?: Record<string, unknown>;
|
|
2523
|
+
}
|
|
2524
|
+
/**
|
|
2525
|
+
* 消息标签枚举
|
|
2526
|
+
*
|
|
2527
|
+
* 用于快速分类和过滤消息,一条消息可能有多个标签
|
|
2528
|
+
*/
|
|
2529
|
+
type MessageTag = 'user' | 'system' | 'assistant' | 'tool-call' | 'tool-result' | 'sub-agent' | 'reminder';
|
|
2530
|
+
/**
|
|
2531
|
+
* 解析结果结构
|
|
2532
|
+
*
|
|
2533
|
+
* 从消息 content 中提取的结构化信息
|
|
2534
|
+
*/
|
|
2535
|
+
interface ParsedContent {
|
|
2536
|
+
/** 从 content 提取的任务 ID(正则匹配 "taskId":"xxx") */
|
|
2537
|
+
taskIds: string[];
|
|
2538
|
+
/** 从 content 提取的工具调用名称(从 toolCalls 或 content 解析) */
|
|
2539
|
+
toolCalls: string[];
|
|
2540
|
+
/** @ 提及的内容 */
|
|
2541
|
+
mentions: string[];
|
|
2542
|
+
/** 用户可继承扩展更多字段 */
|
|
2543
|
+
[key: string]: any;
|
|
2544
|
+
}
|
|
2545
|
+
/**
|
|
2546
|
+
* 扩展的消息结构
|
|
2547
|
+
*
|
|
2548
|
+
* 在原始 Message 基础上添加元数据
|
|
2549
|
+
* 不破坏现有 Message 类型,保证 LLM 调用兼容性
|
|
2550
|
+
*/
|
|
2551
|
+
interface EnrichedMessage extends Message {
|
|
2552
|
+
/** 唯一标识(用于索引关联) */
|
|
2553
|
+
id: string;
|
|
2554
|
+
/** 消息产生时间戳(毫秒) */
|
|
2555
|
+
timestamp: number;
|
|
2556
|
+
/** 所属 ReAct 循环轮次(从 0 开始) */
|
|
2557
|
+
turn: number;
|
|
2558
|
+
/** 全局消息序号(从 0 开始递增) */
|
|
2559
|
+
sequence: number;
|
|
2560
|
+
/** 来源 Agent ID(子代理消息) */
|
|
2561
|
+
agentId?: string;
|
|
2562
|
+
/** 来源 Feature(如 'todo-feature',仅 reminder 等) */
|
|
2563
|
+
source?: string;
|
|
2564
|
+
/** 消息分类标签(用于快速查询) */
|
|
2565
|
+
tags: MessageTag[];
|
|
2566
|
+
/** 从 content 中提取的结构化信息 */
|
|
2567
|
+
parsed: ParsedContent;
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
/**
|
|
2571
|
+
* 决策上下文(反向钩子参数)
|
|
2572
|
+
*
|
|
2573
|
+
* 所有决策上下文的联合类型
|
|
2574
|
+
*/
|
|
2575
|
+
type DecisionContext = AgentInitiateContext | AgentDestroyContext | CallStartContext | CallFinishContext | StepStartContext | StepFinishedContext | ToolContext | ToolResult | StepFinishDecisionContext | ToolFinishedDecisionContext | ToolResultTransformContext;
|
|
2576
|
+
/**
|
|
2577
|
+
* 平台检测后的 UDS 路径
|
|
2578
|
+
*/
|
|
2579
|
+
declare function getDefaultUDSPath(): string;
|
|
2580
|
+
|
|
2581
|
+
interface LoggerBindings extends LogContextRef {
|
|
2582
|
+
tags?: string[];
|
|
2583
|
+
}
|
|
2584
|
+
interface Logger {
|
|
2585
|
+
trace(message: string, data?: unknown): void;
|
|
2586
|
+
debug(message: string, data?: unknown): void;
|
|
2587
|
+
info(message: string, data?: unknown): void;
|
|
2588
|
+
warn(message: string, data?: unknown): void;
|
|
2589
|
+
error(message: string, data?: unknown): void;
|
|
2590
|
+
child(options?: LoggerBindings & {
|
|
2591
|
+
namespace?: string;
|
|
2592
|
+
}): Logger;
|
|
2517
2593
|
}
|
|
2594
|
+
declare function installConsoleBridge(): void;
|
|
2595
|
+
declare function runWithLogScope<T>(scope: LogContextRef, fn: () => T): T;
|
|
2596
|
+
declare function emitLog(level: LogLevel, message: string, data?: unknown, options?: {
|
|
2597
|
+
namespace?: string;
|
|
2598
|
+
context?: LogContextRef;
|
|
2599
|
+
}): DebugLogEntry;
|
|
2600
|
+
declare function createLogger(namespace: string, bindings?: LoggerBindings): Logger;
|
|
2518
2601
|
|
|
2519
2602
|
/**
|
|
2520
2603
|
* 工具定义
|
|
@@ -3261,6 +3344,8 @@ declare class AgentBase {
|
|
|
3261
3344
|
private _llmMeta;
|
|
3262
3345
|
/** 外部消费者通过 onLLMSwap() 注册的回调 */
|
|
3263
3346
|
private _llmSwapCallbacks;
|
|
3347
|
+
/** 应用层注入的 preset 解析服务(构造时注入;资产留在注入方) */
|
|
3348
|
+
private _modelResolver;
|
|
3264
3349
|
constructor(config: AgentConfig);
|
|
3265
3350
|
observeHookInvocations(observer: HookInvocationObserver): () => void;
|
|
3266
3351
|
/**
|
|
@@ -3390,6 +3475,35 @@ declare class AgentBase {
|
|
|
3390
3475
|
* 获取当前模型元数据(不可变副本)
|
|
3391
3476
|
*/
|
|
3392
3477
|
getLLMMeta(): LLMMeta;
|
|
3478
|
+
/**
|
|
3479
|
+
* 按 preset 名一键切换模型
|
|
3480
|
+
*
|
|
3481
|
+
* 编排:resolver.resolve → setLLM(换实例 / 贴 meta 标 / 通知 Feature / 推 Overview)。
|
|
3482
|
+
* preset 表与凭证由应用层注入的 resolver 提供,本方法只编排流程,因此宿主与
|
|
3483
|
+
* Feature 消费同一入口,切换后的模型状态以 getLLMMeta() 为唯一权威。
|
|
3484
|
+
*
|
|
3485
|
+
* 允许在 onCall 运行期间调用(mid-turn swap),语义同 setLLM。
|
|
3486
|
+
*
|
|
3487
|
+
* @param presetName preset 名
|
|
3488
|
+
* @param opts.thinkingEffort 运行时档位覆盖;null 表示清除为厂商默认
|
|
3489
|
+
* @param opts.source 切换发起方标记('user' / 'feature:<name>' 等),写入 meta 供让位策略区分
|
|
3490
|
+
* @returns false 表示 preset 解析失败(名字不存在 / 凭证缺失),模型未变
|
|
3491
|
+
* @throws 未注入 modelResolver 时抛出 —— 装配缺失应显式失败而非静默
|
|
3492
|
+
*/
|
|
3493
|
+
setModel(presetName: string, opts?: {
|
|
3494
|
+
thinkingEffort?: string | null;
|
|
3495
|
+
source?: string;
|
|
3496
|
+
}): boolean;
|
|
3497
|
+
/**
|
|
3498
|
+
* 仅调整思考档位(不动模型):按当前 presetName 重 resolve。
|
|
3499
|
+
* 档位固化在 LLM 实例构造里,因此调整档位 = 以覆盖档位重造客户端。
|
|
3500
|
+
*
|
|
3501
|
+
* @param effort 档位;null 表示清除为厂商默认
|
|
3502
|
+
* @returns false 表示当前模型无 presetName 可锚定或解析失败
|
|
3503
|
+
*/
|
|
3504
|
+
setThinkingEffort(effort: string | null, opts?: {
|
|
3505
|
+
source?: string;
|
|
3506
|
+
}): boolean;
|
|
3393
3507
|
rollbackToCall(callIndex: number): Promise<{
|
|
3394
3508
|
draftInput: string;
|
|
3395
3509
|
}>;
|
|
@@ -3479,8 +3593,9 @@ declare class AgentBase {
|
|
|
3479
3593
|
* @param callIndex Call 序号
|
|
3480
3594
|
* @param step Step 序号
|
|
3481
3595
|
* @param usage 用量数据
|
|
3596
|
+
* @param model 该次请求的模型归因(缺省不计入分段)
|
|
3482
3597
|
*/
|
|
3483
|
-
recordUsage(callIndex: number, step: number, usage: UsageInfo): void;
|
|
3598
|
+
recordUsage(callIndex: number, step: number, usage: UsageInfo, model?: ModelUsageKey): void;
|
|
3484
3599
|
/**
|
|
3485
3600
|
* 标记 Call 结束
|
|
3486
3601
|
* @param callIndex Call 序号
|
|
@@ -3966,6 +4081,34 @@ declare function resolveModelCallPolicy(config?: {
|
|
|
3966
4081
|
timeoutMs: number | undefined;
|
|
3967
4082
|
};
|
|
3968
4083
|
|
|
4084
|
+
/**
|
|
4085
|
+
* Session Events - 会话事件流
|
|
4086
|
+
*
|
|
4087
|
+
* 职责:
|
|
4088
|
+
* - 定义无头模式(headless)消费的会话事件模型(codex exec 风格)
|
|
4089
|
+
* - 提供进程内订阅 API,消息变更单点发射
|
|
4090
|
+
*
|
|
4091
|
+
* 与通知系统(notification.ts)的分工:
|
|
4092
|
+
* - notification 是 UI 状态信号:节流、轻量、面向 Web UI 进度指示
|
|
4093
|
+
* - session event 是审计数据:不节流、完整、面向无头模式 stdout JSONL
|
|
4094
|
+
*
|
|
4095
|
+
* 事件模型(对齐 codex exec JSONL):
|
|
4096
|
+
* - thread.started 线程(会话)开始
|
|
4097
|
+
* - turn.started 一次用户输入触发的回合开始
|
|
4098
|
+
* - item.started / item.completed 会话条目生命周期
|
|
4099
|
+
* - turn.completed 回合完成(含 token 用量)
|
|
4100
|
+
* - turn.failed 回合失败
|
|
4101
|
+
*
|
|
4102
|
+
* 术语(ADR-0002/Q6,一词不混用):本事件流里的 `thread.started` 的 thread
|
|
4103
|
+
* 指**会话本身**(codex exec 对外 jsonl 审计契约,永不改义);框架的接续链概念
|
|
4104
|
+
* 定名 **WorkThread**(见 `core/workthread/`),一处不混用。
|
|
4105
|
+
*
|
|
4106
|
+
* item 类型:
|
|
4107
|
+
* - agent_message agent 的自然语言回复
|
|
4108
|
+
* - reasoning agent 的思考摘要
|
|
4109
|
+
* - tool_call 工具调用(参数、结果、错误、状态)
|
|
4110
|
+
*/
|
|
4111
|
+
|
|
3969
4112
|
interface SessionItemBase {
|
|
3970
4113
|
/** 条目唯一 ID:tool_call 用 LLM 生成的 call.id,其余用递增 item_N */
|
|
3971
4114
|
id: string;
|
|
@@ -4089,6 +4232,22 @@ interface SkillsOptions {
|
|
|
4089
4232
|
baseDir?: string;
|
|
4090
4233
|
}
|
|
4091
4234
|
|
|
4235
|
+
/**
|
|
4236
|
+
* Skill Feature - Skills 发现和 invoke_skill 工具
|
|
4237
|
+
*
|
|
4238
|
+
* 将 Skills 集成从 Agent 核心中解耦,实现可外挂功能
|
|
4239
|
+
*
|
|
4240
|
+
* @example
|
|
4241
|
+
* ```typescript
|
|
4242
|
+
* // 使用默认路径 .agentdev/skills
|
|
4243
|
+
* agent.use(new SkillFeature());
|
|
4244
|
+
*
|
|
4245
|
+
* // 使用自定义路径
|
|
4246
|
+
* agent.use(new SkillFeature('./custom/skills'));
|
|
4247
|
+
* agent.use(new SkillFeature({ dir: './custom/skills' }));
|
|
4248
|
+
* ```
|
|
4249
|
+
*/
|
|
4250
|
+
|
|
4092
4251
|
/**
|
|
4093
4252
|
* Skill Feature 配置类型
|
|
4094
4253
|
*/
|
|
@@ -4973,7 +5132,7 @@ declare class ExampleFeature implements AgentFeature {
|
|
|
4973
5132
|
afterRollback(snapshot: FeatureStateSnapshot): Promise<void>;
|
|
4974
5133
|
handleCallStart(ctx: CallStartContext): Promise<void>;
|
|
4975
5134
|
validateExampleTool(ctx: ToolContext): Promise<typeof Decision.Continue | typeof Decision.Deny>;
|
|
4976
|
-
handleStepFinish(
|
|
5135
|
+
handleStepFinish(_ctx: StepFinishDecisionContext): Promise<typeof Decision.Continue>;
|
|
4977
5136
|
}
|
|
4978
5137
|
|
|
4979
5138
|
/**
|
|
@@ -5297,6 +5456,8 @@ interface BasicAgentConfig {
|
|
|
5297
5456
|
projectRoot?: string;
|
|
5298
5457
|
/** 工具默认操作的工作目录 */
|
|
5299
5458
|
workspaceDir?: string;
|
|
5459
|
+
/** 模型预设解析器(可选;运行期 setModel / setThinkingEffort 消费,未注入时二者抛错) */
|
|
5460
|
+
modelResolver?: AgentConfig['modelResolver'];
|
|
5300
5461
|
}
|
|
5301
5462
|
/**
|
|
5302
5463
|
* 基础 Agent 类
|
|
@@ -6255,7 +6416,6 @@ declare function declareContinuity<T extends AnyFeatureConstructor>(Base: T, des
|
|
|
6255
6416
|
*/
|
|
6256
6417
|
declare const WorkThreadCommandStatus: Readonly<{
|
|
6257
6418
|
readonly PENDING: "pending";
|
|
6258
|
-
readonly IN_FLIGHT: "in_flight";
|
|
6259
6419
|
readonly DELIVERED: "delivered";
|
|
6260
6420
|
readonly FAILED: "failed";
|
|
6261
6421
|
readonly CANCELLED: "cancelled";
|
|
@@ -6266,6 +6426,9 @@ declare const WorkThreadCommandKind: Readonly<{
|
|
|
6266
6426
|
readonly SYSTEM_CONTINUATION: "system_continuation";
|
|
6267
6427
|
readonly EXTERNAL: "external";
|
|
6268
6428
|
}>;
|
|
6429
|
+
/** 终态指令保留上限(超出按时间裁剪,防止 commands 无限增长) */
|
|
6430
|
+
declare const MAX_RETAINED_TERMINAL_COMMANDS = 200;
|
|
6431
|
+
declare function generateCommandId(): string;
|
|
6269
6432
|
interface WorkThreadCommand {
|
|
6270
6433
|
commandId: string;
|
|
6271
6434
|
threadId: string;
|
|
@@ -6283,7 +6446,46 @@ interface WorkThreadCommand {
|
|
|
6283
6446
|
deliveryRef?: string | null;
|
|
6284
6447
|
/** 随指令流动的能力激活通知(capability refs),投递时随 user-turn 元数据转发 */
|
|
6285
6448
|
capabilityActivations?: string[];
|
|
6449
|
+
/** 随指令流动的图片引用(附件名/路径/URL),投递时转发给 viewer user-turn */
|
|
6450
|
+
images?: string[];
|
|
6286
6451
|
}
|
|
6452
|
+
/**
|
|
6453
|
+
* 构造新指令记录(不修改 thread record)。
|
|
6454
|
+
*/
|
|
6455
|
+
declare function createCommandRecord(opts: {
|
|
6456
|
+
threadId: string;
|
|
6457
|
+
kind?: string;
|
|
6458
|
+
text?: string;
|
|
6459
|
+
source?: string;
|
|
6460
|
+
idempotencyKey?: string;
|
|
6461
|
+
capabilityActivations?: string[];
|
|
6462
|
+
images?: string[];
|
|
6463
|
+
}): WorkThreadCommand;
|
|
6464
|
+
/**
|
|
6465
|
+
* 幂等追加指令。若 idempotencyKey 命中既有的 pending / delivered
|
|
6466
|
+
* 指令,直接返回既有指令(重复提交不产生副作用)。
|
|
6467
|
+
* @returns {{command: WorkThreadCommand, duplicate: boolean}}
|
|
6468
|
+
*/
|
|
6469
|
+
declare function appendCommand(record: {
|
|
6470
|
+
commands?: WorkThreadCommand[];
|
|
6471
|
+
}, command: WorkThreadCommand): {
|
|
6472
|
+
command: WorkThreadCommand;
|
|
6473
|
+
duplicate: boolean;
|
|
6474
|
+
};
|
|
6475
|
+
/** 按 createdAt + commandId 稳定排序的 pending 指令。 */
|
|
6476
|
+
declare function pendingCommands(record: {
|
|
6477
|
+
commands?: WorkThreadCommand[];
|
|
6478
|
+
}): WorkThreadCommand[];
|
|
6479
|
+
declare function findCommand(record: {
|
|
6480
|
+
commands?: WorkThreadCommand[];
|
|
6481
|
+
}, commandId: string): WorkThreadCommand | null;
|
|
6482
|
+
/**
|
|
6483
|
+
* 裁剪终态指令,保留最近 maxRetained 条。pending 永不裁剪。
|
|
6484
|
+
* @returns 是否有被裁掉的(内容变更)
|
|
6485
|
+
*/
|
|
6486
|
+
declare function pruneCommands(record: {
|
|
6487
|
+
commands?: WorkThreadCommand[];
|
|
6488
|
+
}, maxRetained?: number): boolean;
|
|
6287
6489
|
|
|
6288
6490
|
/**
|
|
6289
6491
|
* WorkThreadStore — WorkThread 锚点层持久化存储
|
|
@@ -6398,6 +6600,19 @@ declare class WorkThreadStore {
|
|
|
6398
6600
|
record: WorkThreadRecord;
|
|
6399
6601
|
changed: boolean;
|
|
6400
6602
|
}>;
|
|
6603
|
+
/**
|
|
6604
|
+
* 删除线程记录文件与 index 条目(破坏性生命周期操作的存储原语)。
|
|
6605
|
+
*
|
|
6606
|
+
* 幂等:记录不存在时返回 { removed: false, alreadyAbsent: true }——
|
|
6607
|
+
* 已删除对象视为删除成功,供宿主的级联删除重试收敛。
|
|
6608
|
+
* 走与 create / update 相同的 per-thread 串行锁;index 条目移除走
|
|
6609
|
+
* _indexLock 串行链(与 updateIndexEntry 同链,并发创建 / 更新其它
|
|
6610
|
+
* 线程时双方的 index 快照不会互相覆盖丢失对方的条目)。
|
|
6611
|
+
*/
|
|
6612
|
+
remove(threadId: string): Promise<{
|
|
6613
|
+
removed: boolean;
|
|
6614
|
+
alreadyAbsent: boolean;
|
|
6615
|
+
}>;
|
|
6401
6616
|
}
|
|
6402
6617
|
|
|
6403
6618
|
interface WorkThreadBridgeSubmitTurnParams {
|
|
@@ -6406,6 +6621,7 @@ interface WorkThreadBridgeSubmitTurnParams {
|
|
|
6406
6621
|
source: string;
|
|
6407
6622
|
sourceRef: string;
|
|
6408
6623
|
capabilityActivations?: string[];
|
|
6624
|
+
images?: string[];
|
|
6409
6625
|
}
|
|
6410
6626
|
interface WorkThreadDeliveryOutcome {
|
|
6411
6627
|
accepted: boolean;
|
|
@@ -6449,6 +6665,7 @@ declare class WorkThreadRuntimeBridge implements WorkThreadBridge {
|
|
|
6449
6665
|
commandId?: string;
|
|
6450
6666
|
text?: string;
|
|
6451
6667
|
capabilityActivations?: string[];
|
|
6668
|
+
images?: string[];
|
|
6452
6669
|
};
|
|
6453
6670
|
}): Promise<WorkThreadDeliveryOutcome>;
|
|
6454
6671
|
}
|
|
@@ -6496,12 +6713,28 @@ interface WorkThreadOptions {
|
|
|
6496
6713
|
* index)。框架不内置产品身份词汇:返回值即线程归属;空值 = 身份未知。
|
|
6497
6714
|
*/
|
|
6498
6715
|
identitySource?: (agentId: string, sessionId: string) => Promise<string | null> | string | null;
|
|
6716
|
+
/**
|
|
6717
|
+
* R3:接续恢复指令策略。官方默认为静态文案;宿主可注入替换。
|
|
6718
|
+
* 策略必须是纯同步文本生成——恢复路径禁止叠加 LLM 调用等易碎件。
|
|
6719
|
+
*/
|
|
6720
|
+
continuationPolicy?: WorkThreadContinuationPolicy;
|
|
6721
|
+
}
|
|
6722
|
+
/** 交接移交易上下文(beginSessionHandoff 播种恢复指令时传入策略)。 */
|
|
6723
|
+
interface WorkThreadSuccessionContext {
|
|
6724
|
+
threadId: string;
|
|
6725
|
+
fromSessionId: string;
|
|
6726
|
+
reason: string;
|
|
6727
|
+
}
|
|
6728
|
+
/** R3:接续恢复指令策略接口。compose 必须同步、纯函数。 */
|
|
6729
|
+
interface WorkThreadContinuationPolicy {
|
|
6730
|
+
composeSuccessionInstruction(ctx: WorkThreadSuccessionContext): string;
|
|
6499
6731
|
}
|
|
6500
6732
|
declare class WorkThread {
|
|
6501
6733
|
readonly store: WorkThreadStore;
|
|
6502
6734
|
private readonly _bridge;
|
|
6503
6735
|
private readonly _identitySource?;
|
|
6504
|
-
|
|
6736
|
+
private readonly _continuationPolicy;
|
|
6737
|
+
constructor({ store, bridge, identitySource, continuationPolicy }: WorkThreadOptions);
|
|
6505
6738
|
listThreads(opts?: {
|
|
6506
6739
|
agentId?: string;
|
|
6507
6740
|
}): Promise<unknown[]>;
|
|
@@ -6534,8 +6767,16 @@ declare class WorkThread {
|
|
|
6534
6767
|
*/
|
|
6535
6768
|
isHandoffActive(record: WorkThreadRecord): boolean;
|
|
6536
6769
|
/**
|
|
6537
|
-
*
|
|
6538
|
-
*
|
|
6770
|
+
* 标记线程进入交接:原子写入 pendingSuccession + status=rotating,并在同
|
|
6771
|
+
* 一笔事务内播种接续恢复指令(R3:createdAt 与挡板同拍,早于一切交接期
|
|
6772
|
+
* 积压;幂等键绑移交易 (threadId, fromSessionId),失败恢复重走不会重复)。
|
|
6773
|
+
*
|
|
6774
|
+
* 门禁(按序):
|
|
6775
|
+
* - closed → thread_closed(硬终态)
|
|
6776
|
+
* - hold → thread_held(归档/行政冻结期不开新交接,K9)
|
|
6777
|
+
* - 已有 fresh 交接在办 → handoff_in_progress(并发竞争显式拒绝而非
|
|
6778
|
+
* 幂等刷新续命,R8 跨入口 single-flight 锚点;stale 残卷可覆写重开)
|
|
6779
|
+
* - fromSessionId ≠ 当前 head → head_mismatch
|
|
6539
6780
|
*/
|
|
6540
6781
|
beginSessionHandoff(opts: {
|
|
6541
6782
|
threadId: string;
|
|
@@ -6549,6 +6790,12 @@ declare class WorkThread {
|
|
|
6549
6790
|
/**
|
|
6550
6791
|
* 标记交接失败为接续编排状态 rotation_failed,不折叠成通用执行失败。
|
|
6551
6792
|
* pendingSuccession 保留在盘上,供后续 resume 检查被打断的确切 stage。
|
|
6793
|
+
*
|
|
6794
|
+
* K3 守卫(事务内):失败记录的资格来自「在办移交」本身——
|
|
6795
|
+
* - closed 线程:硬终态,任何迟到失败不得覆写(返回原记录,零写入);
|
|
6796
|
+
* - 无 pendingSuccession(移交已成功推进 / 从未开始):迟到的失败者
|
|
6797
|
+
* 没有立卷资格,no-op 返回。这两条共同保证:只有「挡板仍在」的在办
|
|
6798
|
+
* 移交失败才会落 rotation_failed。
|
|
6552
6799
|
*/
|
|
6553
6800
|
failSessionHandoff(threadId: string, opts?: {
|
|
6554
6801
|
reason?: string;
|
|
@@ -6566,6 +6813,7 @@ declare class WorkThread {
|
|
|
6566
6813
|
source?: string;
|
|
6567
6814
|
idempotencyKey?: string;
|
|
6568
6815
|
capabilityActivations?: string[];
|
|
6816
|
+
images?: string[];
|
|
6569
6817
|
}): Promise<{
|
|
6570
6818
|
command: WorkThreadCommand;
|
|
6571
6819
|
duplicate: boolean;
|
|
@@ -6605,6 +6853,10 @@ declare class WorkThread {
|
|
|
6605
6853
|
/**
|
|
6606
6854
|
* 推进线程 head:headSessionId: fromSessionId → toSessionId。
|
|
6607
6855
|
*
|
|
6856
|
+
* fromSessionId 必填(K23):它是调用方声明的 CAS 期望值——不传即
|
|
6857
|
+
* 「接受任意当前 head」,幽灵任务防串台将被合法绕过。调用方若不知道
|
|
6858
|
+
* 当前 head,应先读线程再用读到的值调用(CLI 的自动填充即此语义)。
|
|
6859
|
+
*
|
|
6608
6860
|
* 关键不变量(与 store 原子写共同保证):任一时刻线程要么明确指向旧 head,
|
|
6609
6861
|
* 要么明确指向新 head;推进与指令状态 / 清挡板在同一次落盘中变更。
|
|
6610
6862
|
*
|
|
@@ -6622,7 +6874,7 @@ declare class WorkThread {
|
|
|
6622
6874
|
advanceHead(opts: {
|
|
6623
6875
|
threadId: string;
|
|
6624
6876
|
toSessionId: string;
|
|
6625
|
-
fromSessionId
|
|
6877
|
+
fromSessionId: string;
|
|
6626
6878
|
expectedRevision?: number;
|
|
6627
6879
|
endKind?: string;
|
|
6628
6880
|
}): Promise<WorkThreadRecord>;
|
|
@@ -6828,4 +7080,4 @@ interface PreflightResult {
|
|
|
6828
7080
|
}
|
|
6829
7081
|
declare function preflightAssembly(features: AgentFeature[]): PreflightResult;
|
|
6830
7082
|
|
|
6831
|
-
export { ANTHROPIC_THINKING_EFFORTS, type APIErrorType, AgentBase as Agent, type AgentConfig, type AgentConfigFile, type AgentDestroyHook, type AgentFeature, type AgentInfo, type AgentInitiateContext, type AgentInitiateHook, type AgentLogsResponse, type AgentOverviewSnapshot, AgentPool, type AgentRuntimeSnapshot, type AgentRuntimeStateSnapshot, type AgentSession, type AgentSessionSnapshot, type AgentdevContinuityDescriptor, BasicAgent, type BasicAgentConfig, CONTINUITY_FIELD_KEY, type CacheStats, type CallContinuationRequest, type CallFinishContext, type CallFinishHook, type CallFinishReason, type CallOutcome, type CallRollbackSnapshot, type CallRollbackSnapshotV2, type CallStartContext, type CallStartHook, type CallUsageSummary, type CapabilityContext, type CapabilityDefinition, type CapabilityEntryPoint, type CapabilityInvokeResult, CapabilityRegistry, type CapabilitySnapshot, type CheckpointContinuationRequest, ClassifiedAPIError, type ConfigProvenanceEntry, type ConfigWarning, type ConnectionErrorDetails, Context, type ContextBoundaryV2, type ContextInjector, type ContextMiddleware, type ContextSnapshot, type ContextTombstoneEntry, type ContextTombstoneSummary, CoreLifecycle, type CustomHeaderEntry, DEFAULT_EXPORT_POLICY, DEFAULT_FIELD_LIMIT, DEFAULT_HARD_LIMIT, DEFAULT_MAX_RETRIES, DEFAULT_MODEL_MAX_RETRIES, DEFAULT_MODEL_TIMEOUT_MS, DataSourceRegistry, type DataSourceRenderer, type DebugCapabilities, DebugHub, type DebugHubIPCMessage, type DebugLogEntry, Decision, type DecisionResult, type EnrichedMessage, ExampleFeature, type ExampleFeatureConfig, type ExampleFeatureRuntimeState, type ExampleFeatureSnapshot, type ExecutionError, type ExecutionReason, type ExecutionStatus, ExplorerAgent, type ExplorerAgentConfig, type SystemContext as ExplorerSystemContext, type FeatureCheckpoint, type FeatureConfig, type FeatureContext, type FeatureInitContext, type FeatureManifestDefinition, type FeatureManifestSettingProperty, type FeatureStateSnapshot, FileHistoryFeature, type FileHistoryFeatureConfig, FileSessionStore, GENERIC_CONTINUITY_PROTOCOL, type GuardRole, HANDOFF_COMPILER_VERSION, HANDOFF_SCHEMA_VERSION, HandoffSeedFeature, type HandoffSeedFeatureConfig, type HandoffSeedMessage, type HandoffSeedPayload, type HandoffSeedSnapshot, type HookDeclaration, type HookDeclarationIssue, type HookDeclarationIssueCode, type HookDeclarations, type HookInspectorSnapshot, type HookKind, type HookResult, HooksRegistry, type ImageInput, type IncrementalCallRollbackSnapshot, type InlineRenderTemplate, type InputLease, type InputRequestCancelledMsg, type LLMChatOptions, type LLMClient, type LLMMeta, type LLMPhase, type LLMResponse, type LLMRetryData, type LegacyCallRollbackSnapshot, type Logger, type LoggerBindings, LspFeature, type LspFeatureConfig, type MCPConfig, type MCPHTTPConfig, type MCPSSEConfig, type MCPServerConfig, type MCPSstdioConfig, type MCPToolMappingConfig, type MCPTransportType, type Message, type MessageExecutionMeta, type MessageRole, type MessageTag, type MessageUsage, type ModelConfig, type ModelRequestOutcome, type NamedCheckpoint, type Notification, OPENAI_THINKING_EFFORTS, OPENCODE_BASIC_CONTINUITY_PROTOCOL, OpencodeBasicFeature, type OutputGuardConfig, OutputGuardFeature, type PackageInfo, type ParsedContent, type PlaceholderContext, PlaceholderResolver, type PreflightAssembly, type PreflightCheck, type PreflightIssue, type PreflightResult, type QueuedInput, RENDER_TEMPLATES, type RenderTemplate, type RequestInputMsg, type ResolvedFeatureConfig, type RollbackContinuationRequest, type RuntimeStage, type RuntimeStateWithoutContext, SYSTEM_RENDER_MAP, type ScanFilesAndSkillsResult, type SessionContinuityEntry, type SessionEvent, type SessionEventListener, type SessionItem, type SessionSeedMessage, type SessionStore, type SessionTransformation, SkillFeature, type SkillFeatureConfig, type SkillMetadata, type SkillsOptions, type SnapshotInfo, type StepFinishDecisionContext, type StepFinishHook, type StepFinishedContext, type StepStartContext, type StepStartHook, SubAgentFeature, type SuccessorSeed, type SummaryExportPolicy, type SummaryPromptOptions, SummaryTransformation, type SummaryTransformationOptions, type SystemContext$1 as SystemContext, TOOL_DISPLAY_NAMES, type TaskStatus, TemplateComposer, TemplateError, TemplateLoader, type TemplateLoaderOptions, type TemplateResult, type TemplateSource, type ThinkingBlock, type ThinkingEffort, TodoFeature, type TodoFeatureConfig, type TodoPlanSnapshot, type TodoTask, type TodoTaskSnapshot, type TodoTaskSummary, type Tool, type ToolCall, type ToolContext, type ToolContextValue, type ToolExecResult, type ToolExecutionContext, type ToolFinishedDecisionContext, type ToolFinishedHook, type ToolMetadata, type ToolProgressData, ToolRegistry, type ToolRenderConfig, type ToolResult, type ToolResultTransformContext, type ToolResultTransformHook, type ToolResultValue, type ToolTerminationReason, type ToolUseHook, type TransformContext, type TransformInput, type TrimExportPolicy, type TrimStats, TrimTranscriptTransformation, type TrimTranscriptTransformationOptions, type TrimTranscriptWithSummaryOptions, TrimTranscriptWithSummaryTransformation, type TrimmedSeedResult, type TruncateOptions, type TruncateResult, type TurnFailure, type TurnUsage, type UsageInfo, UsageStats, type UsageStatsSnapshot, type UserInputAction, UserInputFeature, type UserInputFeatureConfig, type UserInputResponse, type UserTurnInput, type UserTurnSubmissionResult, type WithImagesResult, WorkThread, WorkThreadBoard, type WorkThreadBoardMode, type WorkThreadBoardState, type WorkThreadBoardStatus, type WorkThreadBridge, type WorkThreadChainEntry, type WorkThreadCommand, WorkThreadCommandKind, WorkThreadCommandStatus, type WorkThreadDeliveryOutcome, WorkThreadNotFoundError, type WorkThreadOptions, type WorkThreadPendingSuccession, type WorkThreadRecord, WorkThreadRevisionConflictError, WorkThreadRuntimeBridge, type WorkThreadStartOptions, type WorkThreadStatus, WorkThreadStore, applyTemplate, assistant, buildSummaryPrompt, buildSummarySeedMessage, buildTrimmedSeedMessages, classifyAPIError, classifyAndWrapError, createLLMCharCount, createLLMComplete, createLLMRetry, createListRenderer, createLogger, createMessage, createTool, createToolProgress, declareContinuity, discover, emitLog, emitNotification, emitSessionEvent, extractConnectionErrorDetails, extractErrorCode, generateSummaryText, generateWorkThreadId, getClawRuntimeUrl, getDebugCapabilities, getDefaultSessionStore, getDefaultUDSPath, getPackageInfoFromSource, getRetryDelay, getToolDisplayName, getToolRenderConfig, getToolRenderTemplate, getUserFriendlyMessage, installConsoleBridge, interpolateTemplate, isWithImagesResult, listConfigs, loadConfig, loadConfigSync, loadRenderTemplate, normalizeDecision, normalizeExportPolicy, normalizeSummaryPolicy, parseRetryAfter, preflightAssembly, readContinuityDescriptor, readHookDeclarations, resolveDebugTransportMode, resolveFeatureConfig, resolveModelCallPolicy, runWithLogScope, scanFilesAndSkills, shouldRetry, shrinkArray, sleep, splitFrontmatter, stripCompactAnalysis, stripContinuityField, subscribeSessionEvents, system, toolResult, truncateByLines, truncateHeadTail, truncateJsonNode, truncateOutput, tryJsonTruncate, user, validateHookDeclarations, validatePolicyUniqueness, withDeadline, withImages };
|
|
7083
|
+
export { ANTHROPIC_THINKING_EFFORTS, type APIErrorType, AgentBase as Agent, type AgentConfig, type AgentConfigFile, type AgentDestroyHook, type AgentFeature, type AgentInfo, type AgentInitiateContext, type AgentInitiateHook, type AgentLogsResponse, type AgentOverviewSnapshot, AgentPool, type AgentRuntimeSnapshot, type AgentRuntimeStateSnapshot, type AgentSession, type AgentSessionSnapshot, type AgentdevContinuityDescriptor, BasicAgent, type BasicAgentConfig, CONTINUITY_FIELD_KEY, type CacheStats, type CallContinuationRequest, type CallFinishContext, type CallFinishHook, type CallFinishReason, type CallOutcome, type CallRollbackSnapshot, type CallRollbackSnapshotV2, type CallStartContext, type CallStartHook, type CallUsageSummary, type CapabilityContext, type CapabilityDefinition, type CapabilityEntryPoint, type CapabilityInvokeResult, CapabilityRegistry, type CapabilitySnapshot, type CheckpointContinuationRequest, ClassifiedAPIError, type ConfigProvenanceEntry, type ConfigWarning, type ConnectionErrorDetails, Context, type ContextBoundaryV2, type ContextInjector, type ContextMiddleware, type ContextSnapshot, type ContextTombstoneEntry, type ContextTombstoneSummary, CoreLifecycle, type CustomHeaderEntry, DEFAULT_EXPORT_POLICY, DEFAULT_FIELD_LIMIT, DEFAULT_HARD_LIMIT, DEFAULT_MAX_RETRIES, DEFAULT_MODEL_MAX_RETRIES, DEFAULT_MODEL_TIMEOUT_MS, DataSourceRegistry, type DataSourceRenderer, type DebugCapabilities, DebugHub, type DebugHubIPCMessage, type DebugLogEntry, Decision, type DecisionResult, type EnrichedMessage, ExampleFeature, type ExampleFeatureConfig, type ExampleFeatureRuntimeState, type ExampleFeatureSnapshot, type ExecutionError, type ExecutionReason, type ExecutionStatus, ExplorerAgent, type ExplorerAgentConfig, type SystemContext as ExplorerSystemContext, type FeatureCheckpoint, type FeatureConfig, type FeatureContext, type FeatureInitContext, type FeatureManifestDefinition, type FeatureManifestSettingProperty, type FeatureStateSnapshot, FileHistoryFeature, type FileHistoryFeatureConfig, FileSessionStore, GENERIC_CONTINUITY_PROTOCOL, type GuardRole, HANDOFF_COMPILER_VERSION, HANDOFF_SCHEMA_VERSION, HandoffSeedFeature, type HandoffSeedFeatureConfig, type HandoffSeedMessage, type HandoffSeedPayload, type HandoffSeedSnapshot, type HookDeclaration, type HookDeclarationIssue, type HookDeclarationIssueCode, type HookDeclarations, type HookInspectorSnapshot, type HookKind, type HookResult, HooksRegistry, type ImageInput, type IncrementalCallRollbackSnapshot, type InlineRenderTemplate, type InputLease, type InputRequestCancelledMsg, type LLMChatOptions, type LLMClient, type LLMMeta, type LLMPhase, type LLMResponse, type LLMRetryData, type LegacyCallRollbackSnapshot, type Logger, type LoggerBindings, LspFeature, type LspFeatureConfig, MAX_RETAINED_TERMINAL_COMMANDS, type MCPConfig, type MCPHTTPConfig, type MCPSSEConfig, type MCPServerConfig, type MCPSstdioConfig, type MCPToolMappingConfig, type MCPTransportType, type Message, type MessageExecutionMeta, type MessageRole, type MessageTag, type MessageUsage, type ModelConfig, type ModelPresetResolver, type ModelRequestOutcome, type NamedCheckpoint, type Notification, OPENAI_THINKING_EFFORTS, OPENCODE_BASIC_CONTINUITY_PROTOCOL, OpencodeBasicFeature, type OutputGuardConfig, OutputGuardFeature, type PackageInfo, type ParsedContent, type PlaceholderContext, PlaceholderResolver, type PreflightAssembly, type PreflightCheck, type PreflightIssue, type PreflightResult, type QueuedInput, RENDER_TEMPLATES, type RenderTemplate, type RequestInputMsg, type ResolvedFeatureConfig, type ResolvedModelPreset, type RollbackContinuationRequest, type RuntimeStage, type RuntimeStateWithoutContext, SYSTEM_RENDER_MAP, type ScanFilesAndSkillsResult, type SessionContinuityEntry, type SessionEvent, type SessionEventListener, type SessionItem, type SessionSeedMessage, type SessionStore, type SessionTransformation, SkillFeature, type SkillFeatureConfig, type SkillMetadata, type SkillsOptions, type SnapshotInfo, type StepFinishDecisionContext, type StepFinishHook, type StepFinishedContext, type StepStartContext, type StepStartHook, SubAgentFeature, type SuccessorSeed, type SummaryExportPolicy, type SummaryPromptOptions, SummaryTransformation, type SummaryTransformationOptions, type SystemContext$1 as SystemContext, TOOL_DISPLAY_NAMES, type TaskStatus, TemplateComposer, TemplateError, TemplateLoader, type TemplateLoaderOptions, type TemplateResult, type TemplateSource, type ThinkingBlock, type ThinkingEffort, TodoFeature, type TodoFeatureConfig, type TodoPlanSnapshot, type TodoTask, type TodoTaskSnapshot, type TodoTaskSummary, type Tool, type ToolCall, type ToolContext, type ToolContextValue, type ToolExecResult, type ToolExecutionContext, type ToolFinishedDecisionContext, type ToolFinishedHook, type ToolMetadata, type ToolProgressData, ToolRegistry, type ToolRenderConfig, type ToolResult, type ToolResultTransformContext, type ToolResultTransformHook, type ToolResultValue, type ToolTerminationReason, type ToolUseHook, type TransformContext, type TransformInput, type TrimExportPolicy, type TrimStats, TrimTranscriptTransformation, type TrimTranscriptTransformationOptions, type TrimTranscriptWithSummaryOptions, TrimTranscriptWithSummaryTransformation, type TrimmedSeedResult, type TruncateOptions, type TruncateResult, type TurnFailure, type TurnUsage, type UsageInfo, UsageStats, type UsageStatsSnapshot, type UserInputAction, UserInputFeature, type UserInputFeatureConfig, type UserInputResponse, type UserTurnInput, type UserTurnSubmissionResult, type WithImagesResult, WorkThread, WorkThreadBoard, type WorkThreadBoardMode, type WorkThreadBoardState, type WorkThreadBoardStatus, type WorkThreadBridge, type WorkThreadChainEntry, type WorkThreadCommand, WorkThreadCommandKind, WorkThreadCommandStatus, type WorkThreadDeliveryOutcome, WorkThreadNotFoundError, type WorkThreadOptions, type WorkThreadPendingSuccession, type WorkThreadRecord, WorkThreadRevisionConflictError, WorkThreadRuntimeBridge, type WorkThreadStartOptions, type WorkThreadStatus, WorkThreadStore, appendCommand, applyTemplate, assistant, buildSummaryPrompt, buildSummarySeedMessage, buildTrimmedSeedMessages, classifyAPIError, classifyAndWrapError, createCommandRecord, createLLMCharCount, createLLMComplete, createLLMRetry, createListRenderer, createLogger, createMessage, createTool, createToolProgress, declareContinuity, discover, emitLog, emitNotification, emitSessionEvent, extractConnectionErrorDetails, extractErrorCode, findCommand, generateCommandId, generateSummaryText, generateWorkThreadId, getClawRuntimeUrl, getDebugCapabilities, getDefaultSessionStore, getDefaultUDSPath, getPackageInfoFromSource, getRetryDelay, getToolDisplayName, getToolRenderConfig, getToolRenderTemplate, getUserFriendlyMessage, installConsoleBridge, interpolateTemplate, isWithImagesResult, listConfigs, loadConfig, loadConfigSync, loadRenderTemplate, normalizeDecision, normalizeExportPolicy, normalizeSummaryPolicy, parseRetryAfter, pendingCommands, preflightAssembly, pruneCommands, readContinuityDescriptor, readHookDeclarations, resolveDebugTransportMode, resolveFeatureConfig, resolveModelCallPolicy, runWithLogScope, scanFilesAndSkills, shouldRetry, shrinkArray, sleep, splitFrontmatter, stripCompactAnalysis, stripContinuityField, subscribeSessionEvents, system, toolResult, truncateByLines, truncateHeadTail, truncateJsonNode, truncateOutput, tryJsonTruncate, user, validateHookDeclarations, validatePolicyUniqueness, withDeadline, withImages };
|