@zqagent/core 0.1.30 → 0.2.4
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/CONTRIBUTING.md +65 -0
- package/LICENSE +190 -0
- package/README.md +42 -165
- package/README.oss.en.md +161 -0
- package/README.oss.md +165 -0
- package/README.oss.zh-TW.md +165 -0
- package/SECURITY.md +51 -0
- package/dist/{ToolRegistry-BmvPxgMr.d.cts → ToolRegistry-C3pTFiaJ.d.cts} +13 -4
- package/dist/{ToolRegistry-BmvPxgMr.d.ts → ToolRegistry-C3pTFiaJ.d.ts} +13 -4
- package/dist/cli/index.cjs +17799 -2062
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +16729 -985
- package/dist/cli/index.js.map +1 -1
- package/dist/{explore-OI6htHN1.d.cts → explore-D4lCKXbA.d.ts} +160 -19
- package/dist/{explore-Pmhyk4gv.d.ts → explore-Dj1j_GyN.d.cts} +160 -19
- package/dist/index.cjs +3626 -453
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +337 -27
- package/dist/index.d.ts +337 -27
- package/dist/index.js +3617 -452
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +14029 -1482
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +14036 -1482
- package/dist/server/index.js.map +1 -1
- package/dist/tools/ask.cjs +14 -0
- package/dist/tools/ask.cjs.map +1 -1
- package/dist/tools/ask.d.cts +8 -2
- package/dist/tools/ask.d.ts +8 -2
- package/dist/tools/ask.js +13 -0
- package/dist/tools/ask.js.map +1 -1
- package/dist/tools/diff.cjs +59 -30
- package/dist/tools/diff.cjs.map +1 -1
- package/dist/tools/diff.d.cts +1 -1
- package/dist/tools/diff.d.ts +1 -1
- package/dist/tools/diff.js +59 -30
- package/dist/tools/diff.js.map +1 -1
- package/dist/tools/directories.d.cts +1 -1
- package/dist/tools/directories.d.ts +1 -1
- package/dist/tools/explore.cjs +1050 -309
- package/dist/tools/explore.cjs.map +1 -1
- package/dist/tools/explore.d.cts +2 -2
- package/dist/tools/explore.d.ts +2 -2
- package/dist/tools/explore.js +1057 -309
- package/dist/tools/explore.js.map +1 -1
- package/dist/tools/files.cjs +58 -43
- package/dist/tools/files.cjs.map +1 -1
- package/dist/tools/files.d.cts +10 -4
- package/dist/tools/files.d.ts +10 -4
- package/dist/tools/files.js +56 -42
- package/dist/tools/files.js.map +1 -1
- package/dist/tools/git.cjs +816 -63
- package/dist/tools/git.cjs.map +1 -1
- package/dist/tools/git.d.cts +200 -2
- package/dist/tools/git.d.ts +200 -2
- package/dist/tools/git.js +788 -62
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/media.cjs +1191 -0
- package/dist/tools/media.cjs.map +1 -0
- package/dist/tools/media.d.cts +31 -0
- package/dist/tools/media.d.ts +31 -0
- package/dist/tools/media.js +1159 -0
- package/dist/tools/media.js.map +1 -0
- package/dist/tools/plan.d.cts +1 -1
- package/dist/tools/plan.d.ts +1 -1
- package/dist/tools/search.cjs +513 -33
- package/dist/tools/search.cjs.map +1 -1
- package/dist/tools/search.d.cts +12 -1
- package/dist/tools/search.d.ts +12 -1
- package/dist/tools/search.js +508 -33
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/shell.cjs +631 -41
- package/dist/tools/shell.cjs.map +1 -1
- package/dist/tools/shell.d.cts +37 -4
- package/dist/tools/shell.d.ts +37 -4
- package/dist/tools/shell.js +626 -40
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/todo.d.cts +1 -1
- package/dist/tools/todo.d.ts +1 -1
- package/dist/tools/web.cjs +51 -18
- package/dist/tools/web.cjs.map +1 -1
- package/dist/tools/web.d.cts +1 -1
- package/dist/tools/web.d.ts +1 -1
- package/dist/tools/web.js +51 -18
- package/dist/tools/web.js.map +1 -1
- package/package.json +43 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as TokenUsage, b as ToolMetadata, M as Message, c as ToolSchema, R as ReasoningEffort, S as StreamChunk, T as ToolRegistry } from './ToolRegistry-
|
|
1
|
+
import { a as TokenUsage, b as ToolMetadata, M as Message, c as ToolSchema, R as ReasoningEffort, S as StreamChunk, T as ToolRegistry } from './ToolRegistry-C3pTFiaJ.js';
|
|
2
2
|
import { ChatCompletionMessageParam } from 'openai/resources/chat/completions.js';
|
|
3
3
|
import { RequestOptions } from 'openai/core.mjs';
|
|
4
4
|
|
|
@@ -48,7 +48,11 @@ declare enum EventType {
|
|
|
48
48
|
/** LLM 请求发出 — 携带 reqId 用于关联审计日志与后续 delta/error 事件 */
|
|
49
49
|
LLM_REQUEST = "llm_request",
|
|
50
50
|
/** 模型通过 ask_user 工具向用户提问 */
|
|
51
|
-
ASK_USER_QUESTION = "ask_user_question"
|
|
51
|
+
ASK_USER_QUESTION = "ask_user_question",
|
|
52
|
+
/** 会话名已(自动/手动)更新 — data: { name, source } */
|
|
53
|
+
SESSION_NAMED = "session_named",
|
|
54
|
+
/** 瞬时网络错误自动重试 — data: { attempt, max, reason } */
|
|
55
|
+
LLM_RETRY = "llm_retry"
|
|
52
56
|
}
|
|
53
57
|
/** WebSocket 事件 (CLI 模式下通过 async generator 模拟) */
|
|
54
58
|
interface WsEvent {
|
|
@@ -93,6 +97,45 @@ interface EngineErrorInfo {
|
|
|
93
97
|
/** 错误堆栈(异常对象存在时提供,可能缺失) */
|
|
94
98
|
stack?: string;
|
|
95
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* 上下文压缩触发原因
|
|
102
|
+
*
|
|
103
|
+
* - `threshold`:达到触发阈值的预防性压缩
|
|
104
|
+
* - `overflow`:API 报上下文溢出后的强制压缩
|
|
105
|
+
*/
|
|
106
|
+
type CompactionTrigger = "threshold" | "overflow";
|
|
107
|
+
/** 压缩开始时的上下文用量(供 hook / 事件携带,便于展示更多信息) */
|
|
108
|
+
interface CompactionStartInfo {
|
|
109
|
+
/** 触发原因 */
|
|
110
|
+
trigger: CompactionTrigger;
|
|
111
|
+
/** 触发时的上下文 token 用量(优先 API 精确值,否则为估算) */
|
|
112
|
+
tokens: number;
|
|
113
|
+
/** tokens 是否为 chars/4 估算值 */
|
|
114
|
+
estimated: boolean;
|
|
115
|
+
/** 当前模型的上下文窗口(token 数) */
|
|
116
|
+
contextWindow: number;
|
|
117
|
+
/** 触发阈值占窗口的比例(0-1) */
|
|
118
|
+
thresholdPct: number;
|
|
119
|
+
/** 触发阈值(token 数,已计入 capTokens 截断) */
|
|
120
|
+
thresholdTokens: number;
|
|
121
|
+
/** 压缩前发送给模型的消息条数 */
|
|
122
|
+
outboundMessages: number;
|
|
123
|
+
}
|
|
124
|
+
/** 压缩结果信息 */
|
|
125
|
+
interface CompactionDoneInfo {
|
|
126
|
+
/** summarized=LLM 摘要,trimmed=裁剪降级 */
|
|
127
|
+
method: "summarized" | "trimmed";
|
|
128
|
+
/** 压缩前发送给模型的消息条数 */
|
|
129
|
+
messagesBefore: number;
|
|
130
|
+
/** 压缩后发送给模型的消息条数 */
|
|
131
|
+
messagesAfter: number;
|
|
132
|
+
/** 摘要所用模型(method=summarized 时提供) */
|
|
133
|
+
model?: string;
|
|
134
|
+
/** 摘要保留的早期用户消息数 */
|
|
135
|
+
keptUserMessages?: number;
|
|
136
|
+
/** 摘要丢弃的早期用户消息数 */
|
|
137
|
+
droppedUserMessages?: number;
|
|
138
|
+
}
|
|
96
139
|
/**
|
|
97
140
|
* 引擎生命周期钩子
|
|
98
141
|
*
|
|
@@ -119,11 +162,13 @@ interface EngineHook {
|
|
|
119
162
|
onPermissionRequired?(name: string, reason: string): void;
|
|
120
163
|
/** 迭代结束 */
|
|
121
164
|
onIterationEnd?(iteration: number): void;
|
|
122
|
-
/**
|
|
123
|
-
onCompacting?(): void;
|
|
124
|
-
onCompacted?(text: string): void;
|
|
165
|
+
/** 上下文压缩:开始(info 含触发原因与用量)/ 完成(info 含压缩方式与前后条数) */
|
|
166
|
+
onCompacting?(info?: CompactionStartInfo): void;
|
|
167
|
+
onCompacted?(text: string, info?: CompactionDoneInfo): void;
|
|
125
168
|
/** 异常 */
|
|
126
169
|
onError?(error: string, errorType: string, info?: EngineErrorInfo): void;
|
|
170
|
+
/** 瞬时网络错误自动重试(attempt 从 1 开始) */
|
|
171
|
+
onRetry?(attempt: number, max: number, reason: string): void;
|
|
127
172
|
onInterrupted?(iterations: number): void;
|
|
128
173
|
/** 通用兜底:所有未匹配到具体回调的事件都会走这里 */
|
|
129
174
|
onEvent?(type: EventType, data: Record<string, unknown>): void;
|
|
@@ -187,7 +232,7 @@ declare class PermissionEngine {
|
|
|
187
232
|
evaluate(toolName: string, args: Record<string, unknown>, metadata?: ToolMetadata): Decision;
|
|
188
233
|
/** 将工具加入会话白名单 */
|
|
189
234
|
allowToolForSession(toolName: string): void;
|
|
190
|
-
/**
|
|
235
|
+
/** 将命令加入会话白名单(按可执行程序名记录,同类命令后续直接放行) */
|
|
191
236
|
allowCommandForSession(command: string): void;
|
|
192
237
|
/**
|
|
193
238
|
* 检查路径是否在可写根目录下
|
|
@@ -216,6 +261,19 @@ interface StreamOpts {
|
|
|
216
261
|
* DeepSeek 不支持级别控制,自动跳过。
|
|
217
262
|
*/
|
|
218
263
|
reasoningEffort?: ReasoningEffort;
|
|
264
|
+
/**
|
|
265
|
+
* 中止信号(可选)。引擎按下「停止」时 abort,用于掐断在飞的流式请求 ——
|
|
266
|
+
* 仅置引擎内部的取消标志位无法结束已静默挂死的网络流。
|
|
267
|
+
*/
|
|
268
|
+
signal?: AbortSignal;
|
|
269
|
+
/**
|
|
270
|
+
* 内部字段:流空闲看门狗(由 `stream()` 注入,各流路径复用)。
|
|
271
|
+
* 引擎侧无需感知,请勿在 `stream()` 之外构造。
|
|
272
|
+
*/
|
|
273
|
+
idle?: {
|
|
274
|
+
ms: number;
|
|
275
|
+
onIdle: () => void;
|
|
276
|
+
};
|
|
219
277
|
}
|
|
220
278
|
/** LLM Provider 抽象接口 */
|
|
221
279
|
interface ProviderClient {
|
|
@@ -229,7 +287,12 @@ interface ProviderClient {
|
|
|
229
287
|
* @returns 流式 chunk 的异步可迭代对象
|
|
230
288
|
*/
|
|
231
289
|
stream(model: string, messages: Message[], tools: ToolSchema[], opts: StreamOpts): Promise<AsyncIterable<StreamChunk>>;
|
|
232
|
-
chat(model: string, messages: any[], options: RequestOptions, opts: StreamOpts): Promise<string | null>;
|
|
290
|
+
chat(model: string, messages: any[], options: RequestOptions, opts: StreamOpts, params?: ChatParams): Promise<string | null>;
|
|
291
|
+
}
|
|
292
|
+
/** chat 请求的附加参数(用于会话命名等轻量请求,限制输出长度) */
|
|
293
|
+
interface ChatParams {
|
|
294
|
+
/** 最大输出 token 数(Responses → max_output_tokens;Chat → max_tokens / max_completion_tokens) */
|
|
295
|
+
maxTokens?: number;
|
|
233
296
|
}
|
|
234
297
|
/** OpenAI-compatible Provider(Responses API 优先,失败降级 Chat Completions) */
|
|
235
298
|
declare class OpenAIProvider implements ProviderClient {
|
|
@@ -256,15 +319,19 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
256
319
|
*/
|
|
257
320
|
private _resolveMode;
|
|
258
321
|
/**
|
|
259
|
-
*
|
|
322
|
+
* Responses 失败的分类(决定「能不能改走 Chat Completions」以及要不要缓存降级)。
|
|
260
323
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
324
|
+
* @param connectionStage 失败是否发生在连接阶段(首字节之前)。
|
|
325
|
+
* 流内失败(已建立 SSE 后才收到 response.failed)只在**尚未 yield 任何
|
|
326
|
+
* chunk** 时才允许重试,否则会向用户重复输出前半段内容。
|
|
327
|
+
*
|
|
328
|
+
* 返回值:
|
|
329
|
+
* - "endpoint":该端点/模型不支持 Responses → 降级 Chat 并写入缓存
|
|
330
|
+
* - "param":参数或模型不被接受(如阿里兼容模式的 InvalidParameter)
|
|
331
|
+
* → 本次改走 Chat(Chat 的参数集不同,可能可用),但不写缓存
|
|
332
|
+
* - null:鉴权(401)/限流(429)/服务端(5xx)/网络类 → 不降级,原样抛出
|
|
266
333
|
*/
|
|
267
|
-
private
|
|
334
|
+
private _responsesFailureKind;
|
|
268
335
|
/** 识别 DeepSeek 供应商(模型名或 baseURL 含 "deepseek") */
|
|
269
336
|
private _isDeepSeek;
|
|
270
337
|
/**
|
|
@@ -279,9 +346,24 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
279
346
|
* @param opts reqId 等审计信息
|
|
280
347
|
* @returns 模型回复文本;失败返回 null
|
|
281
348
|
*/
|
|
282
|
-
chat(model: string, messages: ChatCompletionMessageParam[], options: RequestOptions, opts: StreamOpts): Promise<string | null>;
|
|
349
|
+
chat(model: string, messages: ChatCompletionMessageParam[], options: RequestOptions, opts: StreamOpts, params?: ChatParams): Promise<string | null>;
|
|
283
350
|
/** 发起流式对话请求,返回包装后的 chunk 迭代器 */
|
|
284
351
|
stream(model: string, messages: Message[], tools: ToolSchema[] | undefined, opts: StreamOpts): Promise<AsyncIterable<StreamChunk>>;
|
|
352
|
+
/**
|
|
353
|
+
* Responses 流 + 流内失败降级。
|
|
354
|
+
*
|
|
355
|
+
* 阿里云百炼(DashScope 兼容模式)等网关在模型/参数不被接受时,
|
|
356
|
+
* **先回 HTTP 200 建流,再下发 `response.failed` 事件**,SDK 不抛错,
|
|
357
|
+
* 因此 `stream()` 里的连接阶段降级判定完全不会触发 —— 用户只看到一句
|
|
358
|
+
* "Responses API 调用失败",且永远不会走 Chat。这里在**尚未 yield 任何
|
|
359
|
+
* chunk 之前**捕获该失败并按 `_responsesFailureKind` 降级重发。
|
|
360
|
+
*
|
|
361
|
+
* 安全边界:一旦已向引擎吐出过任何 chunk(正文/思考/工具调用),绝不重放,
|
|
362
|
+
* 否则用户会看到重复输出 —— 此时原样抛出。
|
|
363
|
+
*/
|
|
364
|
+
private _responsesStream;
|
|
365
|
+
/** Chat Completions 流式路径(默认或 Responses 降级后) */
|
|
366
|
+
private _chatStream;
|
|
285
367
|
/** 将内部 Message 转换为 OpenAI Chat Completions 格式 */
|
|
286
368
|
private _toOpenAIMessages;
|
|
287
369
|
/**
|
|
@@ -325,6 +407,14 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
325
407
|
* 由调用方按请求传入,避免并发请求互相覆盖归档日期。
|
|
326
408
|
*/
|
|
327
409
|
private _appendResponse;
|
|
410
|
+
/**
|
|
411
|
+
* 流空闲看门狗:相邻两个 chunk 之间超过 idleMs 无数据即视为网关静默断供,
|
|
412
|
+
* 先 onIdle() 中止底层请求,再抛错结束迭代。
|
|
413
|
+
*
|
|
414
|
+
* 用 Promise.race 而不只依赖 abort:底层 HTTP 实现未必响应 signal,
|
|
415
|
+
* 此时引擎侧仍能退出等待,不会永久卡在 running 状态。
|
|
416
|
+
*/
|
|
417
|
+
private _withIdleTimeout;
|
|
328
418
|
/**
|
|
329
419
|
* 包装 _wrapStream / _wrapResponsesStream:在流结束时补充响应日志;
|
|
330
420
|
* 异常时补充错误日志。
|
|
@@ -360,6 +450,15 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
360
450
|
* - response.failed → 抛出错误(含响应错误信息)
|
|
361
451
|
*/
|
|
362
452
|
private _wrapResponsesStream;
|
|
453
|
+
/**
|
|
454
|
+
* 从 `response.failed` 事件的 response 对象构造错误。
|
|
455
|
+
*
|
|
456
|
+
* 保留 `error.code` / `error.type` / `request_id`:阿里兼容模式下
|
|
457
|
+
* 典型返回是 `{code:"InvalidParameter", message:"Required parameter(s)
|
|
458
|
+
* missing or invalid", request_id:"..."}`,只有 message 时既无法判断
|
|
459
|
+
* 能否降级,也无从排查。
|
|
460
|
+
*/
|
|
461
|
+
private _responsesFailure;
|
|
363
462
|
/**
|
|
364
463
|
* Responses API 的 usage → 标准化 TokenUsage。
|
|
365
464
|
*
|
|
@@ -414,7 +513,7 @@ interface TurnEngineOpts {
|
|
|
414
513
|
instructions: string;
|
|
415
514
|
/** 生成会话名称的提示词 */
|
|
416
515
|
genSessionNamePrompt?: string;
|
|
417
|
-
/** 单轮最大迭代次数(默认
|
|
516
|
+
/** 单轮最大迭代次数(默认 300) */
|
|
418
517
|
maxIterations?: number;
|
|
419
518
|
/**
|
|
420
519
|
* 推理强度(可选)。透传给 Provider 的 LLM 请求参数
|
|
@@ -427,6 +526,10 @@ interface TurnEngineOpts {
|
|
|
427
526
|
hook?: EngineHook;
|
|
428
527
|
/** 模型上下文窗口大小(token 数)。设置后将覆盖自动检测与默认值 (128K)。 */
|
|
429
528
|
contextWindow?: number;
|
|
529
|
+
/** 压缩触发阈值比例(占窗口比例,默认 0.8) */
|
|
530
|
+
thresholdPct?: number;
|
|
531
|
+
/** 压缩触发阈值绝对上限(token 数;缺省不限制,即按比例用满窗口) */
|
|
532
|
+
capTokens?: number | null;
|
|
430
533
|
}
|
|
431
534
|
/** 核心 Agent 循环 (对齐 Python 版 TurnEngine) */
|
|
432
535
|
declare class TurnEngine {
|
|
@@ -444,11 +547,17 @@ declare class TurnEngine {
|
|
|
444
547
|
/** 引擎生命周期钩子(由外部注入,可选) */
|
|
445
548
|
private _hook;
|
|
446
549
|
private _cancel;
|
|
550
|
+
private _llmAbort;
|
|
551
|
+
private _toolAbort;
|
|
447
552
|
private _steering;
|
|
448
553
|
compactionState: CompactionState | null;
|
|
449
554
|
private _lastContextTokens;
|
|
450
555
|
/** 显式配置的上下文窗口大小(token 数),未设置时为 undefined(走自动检测) */
|
|
451
556
|
private _contextWindow;
|
|
557
|
+
/** 压缩触发阈值比例(默认 0.8) */
|
|
558
|
+
private _thresholdPct;
|
|
559
|
+
/** 压缩触发阈值绝对上限(null = 不限制) */
|
|
560
|
+
private _capTokens;
|
|
452
561
|
private _producedFiles;
|
|
453
562
|
private _turnStartTime;
|
|
454
563
|
private static readonly FILE_WRITE_TOOLS;
|
|
@@ -458,7 +567,10 @@ declare class TurnEngine {
|
|
|
458
567
|
/** 推理强度(透传给 Provider;undefined = 使用模型默认) */
|
|
459
568
|
private _reasoningEffort;
|
|
460
569
|
constructor(opts: TurnEngineOpts);
|
|
461
|
-
/**
|
|
570
|
+
/**
|
|
571
|
+
* 外部中断:置位取消标记 + 掐断在飞的 LLM 请求 + 中止正在执行的工具,
|
|
572
|
+
* 引擎随后按中断收尾
|
|
573
|
+
*/
|
|
462
574
|
requestInterrupt(): void;
|
|
463
575
|
/** 设置审批回调 */
|
|
464
576
|
setApprover(approver: Approver): void;
|
|
@@ -485,6 +597,13 @@ declare class TurnEngine {
|
|
|
485
597
|
genSessionName(): Promise<string | null>;
|
|
486
598
|
/** 从持久化消息历史中重建未完成的 tool_calls */
|
|
487
599
|
private _unansweredTrailingToolCalls;
|
|
600
|
+
/**
|
|
601
|
+
* 中断收尾:保留已流式输出的内容、记一条 interrupted 提示,
|
|
602
|
+
* 产出 INTERRUPTED + TURN_END 事件并结束本轮。
|
|
603
|
+
*
|
|
604
|
+
* 两处调用:流式结束后发现取消标记、以及流被 abort 中断抛错时。
|
|
605
|
+
*/
|
|
606
|
+
private _finishInterrupted;
|
|
488
607
|
/**
|
|
489
608
|
* 核心迭代循环
|
|
490
609
|
*
|
|
@@ -501,6 +620,8 @@ declare class TurnEngine {
|
|
|
501
620
|
* PERMISSION_REQUIRED 事件并调用 approver;被拒/未知工具
|
|
502
621
|
* 直接产出错误结果,不进入执行。
|
|
503
622
|
* B. 分类执行:低风险工具并发执行(Promise.all),其余串行;
|
|
623
|
+
* 交互类工具(ask_user / propose_plan / request_directory)虽然
|
|
624
|
+
* 风险级别为 low,但需要用户逐条作答,一律串行;
|
|
504
625
|
* 每个结果都转成 tool 消息追加到历史并产出 TOOL_FINISHED。
|
|
505
626
|
*/
|
|
506
627
|
private _handleToolCalls;
|
|
@@ -528,8 +649,14 @@ declare class TurnEngine {
|
|
|
528
649
|
* 消息即停止;只有末尾全部是 error 通知才返回 true。
|
|
529
650
|
*/
|
|
530
651
|
private _tailIsRetriableError;
|
|
652
|
+
/** 当前上下文 token 用量:优先采信 API 返回的精确数量,否则用 chars/4 估算 */
|
|
653
|
+
private _compactionTokens;
|
|
531
654
|
/** 检查是否需要压缩(每轮 LLM 调用前) */
|
|
532
655
|
private _compactionDue;
|
|
656
|
+
/** 组装压缩开始时的用量信息(供 hook 与 COMPACTING 事件携带) */
|
|
657
|
+
private _compactionStartInfo;
|
|
658
|
+
/** 组装压缩结果信息(供 hook 与 COMPACTED 事件携带) */
|
|
659
|
+
private _compactionDoneInfo;
|
|
533
660
|
/** 获取当前模型的上下文窗口大小(token 数)。优先级:显式配置 > 自动检测 > 默认值 128K。 */
|
|
534
661
|
private _getContextWindow;
|
|
535
662
|
/** 执行压缩策略(对齐 Python 版 _compact_now) */
|
|
@@ -559,7 +686,7 @@ declare class TurnEngine {
|
|
|
559
686
|
* 构建 Explorer 子引擎 (对齐 Python 版 build_explorer_engine)
|
|
560
687
|
*
|
|
561
688
|
* 只注册只读工具,使用 Plan 模式权限引擎(硬阻断所有写入),
|
|
562
|
-
*
|
|
689
|
+
* 迭代上限默认 30 次(环境变量 EXPLORE_MAX_ITERATIONS 可覆盖)。
|
|
563
690
|
*
|
|
564
691
|
* 可选 readonlyRegistrars:外部可注入"只读工具注册器"(例如沙箱远程工具),
|
|
565
692
|
* 用于把 explore 子代理的执行目标从宿主机工作区切换到远程沙箱。
|
|
@@ -570,6 +697,11 @@ declare function buildExplorerEngine(opts: {
|
|
|
570
697
|
provider: ProviderClient;
|
|
571
698
|
model: string;
|
|
572
699
|
readonlyRegistrars?: (registry: ToolRegistry) => void;
|
|
700
|
+
/**
|
|
701
|
+
* 子引擎生命周期钩子(可选):注入后子代理的执行过程(工具活动、终态)
|
|
702
|
+
* 会回调给调用方渲染(如 CLI 的 SubagentHook);不传则与旧版一致(静默)。
|
|
703
|
+
*/
|
|
704
|
+
hook?: EngineHook;
|
|
573
705
|
}): TurnEngine;
|
|
574
706
|
/**
|
|
575
707
|
* 创建 explore 工具函数
|
|
@@ -582,6 +714,13 @@ declare function makeExploreTool(opts: {
|
|
|
582
714
|
provider: ProviderClient;
|
|
583
715
|
model: string;
|
|
584
716
|
readonlyRegistrars?: (registry: ToolRegistry) => void;
|
|
717
|
+
/**
|
|
718
|
+
* 子引擎钩子工厂(可选):每次 explore 调用生成一个新实例。
|
|
719
|
+
*
|
|
720
|
+
* 用工厂而非共享实例,是因为低风险工具会被并发执行(同一条回复里的多个
|
|
721
|
+
* explore 会同时运行),共享同一个渲染器会互相串状态、输出交错难辨。
|
|
722
|
+
*/
|
|
723
|
+
hookFactory?: () => EngineHook;
|
|
585
724
|
}): (args: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
586
725
|
/** 注册 explore 工具(低风险,无需审批) */
|
|
587
726
|
declare function registerExploreTool(registry: ToolRegistry, opts: {
|
|
@@ -589,6 +728,8 @@ declare function registerExploreTool(registry: ToolRegistry, opts: {
|
|
|
589
728
|
provider: ProviderClient;
|
|
590
729
|
model: string;
|
|
591
730
|
readonlyRegistrars?: (registry: ToolRegistry) => void;
|
|
731
|
+
/** 子引擎钩子工厂(可选):见 makeExploreTool */
|
|
732
|
+
hookFactory?: () => EngineHook;
|
|
592
733
|
}): void;
|
|
593
734
|
|
|
594
|
-
export { ApprovalOutcome as A, type Decision as D, type EngineHook as E, Mode as M, OpenAIProvider as O, type ProviderClient as P, TurnEngine as T, type WsEvent as W,
|
|
735
|
+
export { ApprovalOutcome as A, type CompactionStartInfo as C, type Decision as D, type EngineHook as E, Mode as M, OpenAIProvider as O, type ProviderClient as P, TurnEngine as T, type WsEvent as W, type CompactionDoneInfo as a, EventType as b, type EngineErrorInfo as c, type Approver as d, type CompactionTrigger as e, PermissionEngine as f, type PermissionRequest as g, type TurnEngineOpts as h, buildExplorerEngine as i, makeExploreTool as m, registerExploreTool as r };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as TokenUsage, b as ToolMetadata, M as Message, c as ToolSchema, R as ReasoningEffort, S as StreamChunk, T as ToolRegistry } from './ToolRegistry-
|
|
1
|
+
import { a as TokenUsage, b as ToolMetadata, M as Message, c as ToolSchema, R as ReasoningEffort, S as StreamChunk, T as ToolRegistry } from './ToolRegistry-C3pTFiaJ.cjs';
|
|
2
2
|
import { ChatCompletionMessageParam } from 'openai/resources/chat/completions.js';
|
|
3
3
|
import { RequestOptions } from 'openai/core.mjs';
|
|
4
4
|
|
|
@@ -48,7 +48,11 @@ declare enum EventType {
|
|
|
48
48
|
/** LLM 请求发出 — 携带 reqId 用于关联审计日志与后续 delta/error 事件 */
|
|
49
49
|
LLM_REQUEST = "llm_request",
|
|
50
50
|
/** 模型通过 ask_user 工具向用户提问 */
|
|
51
|
-
ASK_USER_QUESTION = "ask_user_question"
|
|
51
|
+
ASK_USER_QUESTION = "ask_user_question",
|
|
52
|
+
/** 会话名已(自动/手动)更新 — data: { name, source } */
|
|
53
|
+
SESSION_NAMED = "session_named",
|
|
54
|
+
/** 瞬时网络错误自动重试 — data: { attempt, max, reason } */
|
|
55
|
+
LLM_RETRY = "llm_retry"
|
|
52
56
|
}
|
|
53
57
|
/** WebSocket 事件 (CLI 模式下通过 async generator 模拟) */
|
|
54
58
|
interface WsEvent {
|
|
@@ -93,6 +97,45 @@ interface EngineErrorInfo {
|
|
|
93
97
|
/** 错误堆栈(异常对象存在时提供,可能缺失) */
|
|
94
98
|
stack?: string;
|
|
95
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* 上下文压缩触发原因
|
|
102
|
+
*
|
|
103
|
+
* - `threshold`:达到触发阈值的预防性压缩
|
|
104
|
+
* - `overflow`:API 报上下文溢出后的强制压缩
|
|
105
|
+
*/
|
|
106
|
+
type CompactionTrigger = "threshold" | "overflow";
|
|
107
|
+
/** 压缩开始时的上下文用量(供 hook / 事件携带,便于展示更多信息) */
|
|
108
|
+
interface CompactionStartInfo {
|
|
109
|
+
/** 触发原因 */
|
|
110
|
+
trigger: CompactionTrigger;
|
|
111
|
+
/** 触发时的上下文 token 用量(优先 API 精确值,否则为估算) */
|
|
112
|
+
tokens: number;
|
|
113
|
+
/** tokens 是否为 chars/4 估算值 */
|
|
114
|
+
estimated: boolean;
|
|
115
|
+
/** 当前模型的上下文窗口(token 数) */
|
|
116
|
+
contextWindow: number;
|
|
117
|
+
/** 触发阈值占窗口的比例(0-1) */
|
|
118
|
+
thresholdPct: number;
|
|
119
|
+
/** 触发阈值(token 数,已计入 capTokens 截断) */
|
|
120
|
+
thresholdTokens: number;
|
|
121
|
+
/** 压缩前发送给模型的消息条数 */
|
|
122
|
+
outboundMessages: number;
|
|
123
|
+
}
|
|
124
|
+
/** 压缩结果信息 */
|
|
125
|
+
interface CompactionDoneInfo {
|
|
126
|
+
/** summarized=LLM 摘要,trimmed=裁剪降级 */
|
|
127
|
+
method: "summarized" | "trimmed";
|
|
128
|
+
/** 压缩前发送给模型的消息条数 */
|
|
129
|
+
messagesBefore: number;
|
|
130
|
+
/** 压缩后发送给模型的消息条数 */
|
|
131
|
+
messagesAfter: number;
|
|
132
|
+
/** 摘要所用模型(method=summarized 时提供) */
|
|
133
|
+
model?: string;
|
|
134
|
+
/** 摘要保留的早期用户消息数 */
|
|
135
|
+
keptUserMessages?: number;
|
|
136
|
+
/** 摘要丢弃的早期用户消息数 */
|
|
137
|
+
droppedUserMessages?: number;
|
|
138
|
+
}
|
|
96
139
|
/**
|
|
97
140
|
* 引擎生命周期钩子
|
|
98
141
|
*
|
|
@@ -119,11 +162,13 @@ interface EngineHook {
|
|
|
119
162
|
onPermissionRequired?(name: string, reason: string): void;
|
|
120
163
|
/** 迭代结束 */
|
|
121
164
|
onIterationEnd?(iteration: number): void;
|
|
122
|
-
/**
|
|
123
|
-
onCompacting?(): void;
|
|
124
|
-
onCompacted?(text: string): void;
|
|
165
|
+
/** 上下文压缩:开始(info 含触发原因与用量)/ 完成(info 含压缩方式与前后条数) */
|
|
166
|
+
onCompacting?(info?: CompactionStartInfo): void;
|
|
167
|
+
onCompacted?(text: string, info?: CompactionDoneInfo): void;
|
|
125
168
|
/** 异常 */
|
|
126
169
|
onError?(error: string, errorType: string, info?: EngineErrorInfo): void;
|
|
170
|
+
/** 瞬时网络错误自动重试(attempt 从 1 开始) */
|
|
171
|
+
onRetry?(attempt: number, max: number, reason: string): void;
|
|
127
172
|
onInterrupted?(iterations: number): void;
|
|
128
173
|
/** 通用兜底:所有未匹配到具体回调的事件都会走这里 */
|
|
129
174
|
onEvent?(type: EventType, data: Record<string, unknown>): void;
|
|
@@ -187,7 +232,7 @@ declare class PermissionEngine {
|
|
|
187
232
|
evaluate(toolName: string, args: Record<string, unknown>, metadata?: ToolMetadata): Decision;
|
|
188
233
|
/** 将工具加入会话白名单 */
|
|
189
234
|
allowToolForSession(toolName: string): void;
|
|
190
|
-
/**
|
|
235
|
+
/** 将命令加入会话白名单(按可执行程序名记录,同类命令后续直接放行) */
|
|
191
236
|
allowCommandForSession(command: string): void;
|
|
192
237
|
/**
|
|
193
238
|
* 检查路径是否在可写根目录下
|
|
@@ -216,6 +261,19 @@ interface StreamOpts {
|
|
|
216
261
|
* DeepSeek 不支持级别控制,自动跳过。
|
|
217
262
|
*/
|
|
218
263
|
reasoningEffort?: ReasoningEffort;
|
|
264
|
+
/**
|
|
265
|
+
* 中止信号(可选)。引擎按下「停止」时 abort,用于掐断在飞的流式请求 ——
|
|
266
|
+
* 仅置引擎内部的取消标志位无法结束已静默挂死的网络流。
|
|
267
|
+
*/
|
|
268
|
+
signal?: AbortSignal;
|
|
269
|
+
/**
|
|
270
|
+
* 内部字段:流空闲看门狗(由 `stream()` 注入,各流路径复用)。
|
|
271
|
+
* 引擎侧无需感知,请勿在 `stream()` 之外构造。
|
|
272
|
+
*/
|
|
273
|
+
idle?: {
|
|
274
|
+
ms: number;
|
|
275
|
+
onIdle: () => void;
|
|
276
|
+
};
|
|
219
277
|
}
|
|
220
278
|
/** LLM Provider 抽象接口 */
|
|
221
279
|
interface ProviderClient {
|
|
@@ -229,7 +287,12 @@ interface ProviderClient {
|
|
|
229
287
|
* @returns 流式 chunk 的异步可迭代对象
|
|
230
288
|
*/
|
|
231
289
|
stream(model: string, messages: Message[], tools: ToolSchema[], opts: StreamOpts): Promise<AsyncIterable<StreamChunk>>;
|
|
232
|
-
chat(model: string, messages: any[], options: RequestOptions, opts: StreamOpts): Promise<string | null>;
|
|
290
|
+
chat(model: string, messages: any[], options: RequestOptions, opts: StreamOpts, params?: ChatParams): Promise<string | null>;
|
|
291
|
+
}
|
|
292
|
+
/** chat 请求的附加参数(用于会话命名等轻量请求,限制输出长度) */
|
|
293
|
+
interface ChatParams {
|
|
294
|
+
/** 最大输出 token 数(Responses → max_output_tokens;Chat → max_tokens / max_completion_tokens) */
|
|
295
|
+
maxTokens?: number;
|
|
233
296
|
}
|
|
234
297
|
/** OpenAI-compatible Provider(Responses API 优先,失败降级 Chat Completions) */
|
|
235
298
|
declare class OpenAIProvider implements ProviderClient {
|
|
@@ -256,15 +319,19 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
256
319
|
*/
|
|
257
320
|
private _resolveMode;
|
|
258
321
|
/**
|
|
259
|
-
*
|
|
322
|
+
* Responses 失败的分类(决定「能不能改走 Chat Completions」以及要不要缓存降级)。
|
|
260
323
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
324
|
+
* @param connectionStage 失败是否发生在连接阶段(首字节之前)。
|
|
325
|
+
* 流内失败(已建立 SSE 后才收到 response.failed)只在**尚未 yield 任何
|
|
326
|
+
* chunk** 时才允许重试,否则会向用户重复输出前半段内容。
|
|
327
|
+
*
|
|
328
|
+
* 返回值:
|
|
329
|
+
* - "endpoint":该端点/模型不支持 Responses → 降级 Chat 并写入缓存
|
|
330
|
+
* - "param":参数或模型不被接受(如阿里兼容模式的 InvalidParameter)
|
|
331
|
+
* → 本次改走 Chat(Chat 的参数集不同,可能可用),但不写缓存
|
|
332
|
+
* - null:鉴权(401)/限流(429)/服务端(5xx)/网络类 → 不降级,原样抛出
|
|
266
333
|
*/
|
|
267
|
-
private
|
|
334
|
+
private _responsesFailureKind;
|
|
268
335
|
/** 识别 DeepSeek 供应商(模型名或 baseURL 含 "deepseek") */
|
|
269
336
|
private _isDeepSeek;
|
|
270
337
|
/**
|
|
@@ -279,9 +346,24 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
279
346
|
* @param opts reqId 等审计信息
|
|
280
347
|
* @returns 模型回复文本;失败返回 null
|
|
281
348
|
*/
|
|
282
|
-
chat(model: string, messages: ChatCompletionMessageParam[], options: RequestOptions, opts: StreamOpts): Promise<string | null>;
|
|
349
|
+
chat(model: string, messages: ChatCompletionMessageParam[], options: RequestOptions, opts: StreamOpts, params?: ChatParams): Promise<string | null>;
|
|
283
350
|
/** 发起流式对话请求,返回包装后的 chunk 迭代器 */
|
|
284
351
|
stream(model: string, messages: Message[], tools: ToolSchema[] | undefined, opts: StreamOpts): Promise<AsyncIterable<StreamChunk>>;
|
|
352
|
+
/**
|
|
353
|
+
* Responses 流 + 流内失败降级。
|
|
354
|
+
*
|
|
355
|
+
* 阿里云百炼(DashScope 兼容模式)等网关在模型/参数不被接受时,
|
|
356
|
+
* **先回 HTTP 200 建流,再下发 `response.failed` 事件**,SDK 不抛错,
|
|
357
|
+
* 因此 `stream()` 里的连接阶段降级判定完全不会触发 —— 用户只看到一句
|
|
358
|
+
* "Responses API 调用失败",且永远不会走 Chat。这里在**尚未 yield 任何
|
|
359
|
+
* chunk 之前**捕获该失败并按 `_responsesFailureKind` 降级重发。
|
|
360
|
+
*
|
|
361
|
+
* 安全边界:一旦已向引擎吐出过任何 chunk(正文/思考/工具调用),绝不重放,
|
|
362
|
+
* 否则用户会看到重复输出 —— 此时原样抛出。
|
|
363
|
+
*/
|
|
364
|
+
private _responsesStream;
|
|
365
|
+
/** Chat Completions 流式路径(默认或 Responses 降级后) */
|
|
366
|
+
private _chatStream;
|
|
285
367
|
/** 将内部 Message 转换为 OpenAI Chat Completions 格式 */
|
|
286
368
|
private _toOpenAIMessages;
|
|
287
369
|
/**
|
|
@@ -325,6 +407,14 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
325
407
|
* 由调用方按请求传入,避免并发请求互相覆盖归档日期。
|
|
326
408
|
*/
|
|
327
409
|
private _appendResponse;
|
|
410
|
+
/**
|
|
411
|
+
* 流空闲看门狗:相邻两个 chunk 之间超过 idleMs 无数据即视为网关静默断供,
|
|
412
|
+
* 先 onIdle() 中止底层请求,再抛错结束迭代。
|
|
413
|
+
*
|
|
414
|
+
* 用 Promise.race 而不只依赖 abort:底层 HTTP 实现未必响应 signal,
|
|
415
|
+
* 此时引擎侧仍能退出等待,不会永久卡在 running 状态。
|
|
416
|
+
*/
|
|
417
|
+
private _withIdleTimeout;
|
|
328
418
|
/**
|
|
329
419
|
* 包装 _wrapStream / _wrapResponsesStream:在流结束时补充响应日志;
|
|
330
420
|
* 异常时补充错误日志。
|
|
@@ -360,6 +450,15 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
360
450
|
* - response.failed → 抛出错误(含响应错误信息)
|
|
361
451
|
*/
|
|
362
452
|
private _wrapResponsesStream;
|
|
453
|
+
/**
|
|
454
|
+
* 从 `response.failed` 事件的 response 对象构造错误。
|
|
455
|
+
*
|
|
456
|
+
* 保留 `error.code` / `error.type` / `request_id`:阿里兼容模式下
|
|
457
|
+
* 典型返回是 `{code:"InvalidParameter", message:"Required parameter(s)
|
|
458
|
+
* missing or invalid", request_id:"..."}`,只有 message 时既无法判断
|
|
459
|
+
* 能否降级,也无从排查。
|
|
460
|
+
*/
|
|
461
|
+
private _responsesFailure;
|
|
363
462
|
/**
|
|
364
463
|
* Responses API 的 usage → 标准化 TokenUsage。
|
|
365
464
|
*
|
|
@@ -414,7 +513,7 @@ interface TurnEngineOpts {
|
|
|
414
513
|
instructions: string;
|
|
415
514
|
/** 生成会话名称的提示词 */
|
|
416
515
|
genSessionNamePrompt?: string;
|
|
417
|
-
/** 单轮最大迭代次数(默认
|
|
516
|
+
/** 单轮最大迭代次数(默认 300) */
|
|
418
517
|
maxIterations?: number;
|
|
419
518
|
/**
|
|
420
519
|
* 推理强度(可选)。透传给 Provider 的 LLM 请求参数
|
|
@@ -427,6 +526,10 @@ interface TurnEngineOpts {
|
|
|
427
526
|
hook?: EngineHook;
|
|
428
527
|
/** 模型上下文窗口大小(token 数)。设置后将覆盖自动检测与默认值 (128K)。 */
|
|
429
528
|
contextWindow?: number;
|
|
529
|
+
/** 压缩触发阈值比例(占窗口比例,默认 0.8) */
|
|
530
|
+
thresholdPct?: number;
|
|
531
|
+
/** 压缩触发阈值绝对上限(token 数;缺省不限制,即按比例用满窗口) */
|
|
532
|
+
capTokens?: number | null;
|
|
430
533
|
}
|
|
431
534
|
/** 核心 Agent 循环 (对齐 Python 版 TurnEngine) */
|
|
432
535
|
declare class TurnEngine {
|
|
@@ -444,11 +547,17 @@ declare class TurnEngine {
|
|
|
444
547
|
/** 引擎生命周期钩子(由外部注入,可选) */
|
|
445
548
|
private _hook;
|
|
446
549
|
private _cancel;
|
|
550
|
+
private _llmAbort;
|
|
551
|
+
private _toolAbort;
|
|
447
552
|
private _steering;
|
|
448
553
|
compactionState: CompactionState | null;
|
|
449
554
|
private _lastContextTokens;
|
|
450
555
|
/** 显式配置的上下文窗口大小(token 数),未设置时为 undefined(走自动检测) */
|
|
451
556
|
private _contextWindow;
|
|
557
|
+
/** 压缩触发阈值比例(默认 0.8) */
|
|
558
|
+
private _thresholdPct;
|
|
559
|
+
/** 压缩触发阈值绝对上限(null = 不限制) */
|
|
560
|
+
private _capTokens;
|
|
452
561
|
private _producedFiles;
|
|
453
562
|
private _turnStartTime;
|
|
454
563
|
private static readonly FILE_WRITE_TOOLS;
|
|
@@ -458,7 +567,10 @@ declare class TurnEngine {
|
|
|
458
567
|
/** 推理强度(透传给 Provider;undefined = 使用模型默认) */
|
|
459
568
|
private _reasoningEffort;
|
|
460
569
|
constructor(opts: TurnEngineOpts);
|
|
461
|
-
/**
|
|
570
|
+
/**
|
|
571
|
+
* 外部中断:置位取消标记 + 掐断在飞的 LLM 请求 + 中止正在执行的工具,
|
|
572
|
+
* 引擎随后按中断收尾
|
|
573
|
+
*/
|
|
462
574
|
requestInterrupt(): void;
|
|
463
575
|
/** 设置审批回调 */
|
|
464
576
|
setApprover(approver: Approver): void;
|
|
@@ -485,6 +597,13 @@ declare class TurnEngine {
|
|
|
485
597
|
genSessionName(): Promise<string | null>;
|
|
486
598
|
/** 从持久化消息历史中重建未完成的 tool_calls */
|
|
487
599
|
private _unansweredTrailingToolCalls;
|
|
600
|
+
/**
|
|
601
|
+
* 中断收尾:保留已流式输出的内容、记一条 interrupted 提示,
|
|
602
|
+
* 产出 INTERRUPTED + TURN_END 事件并结束本轮。
|
|
603
|
+
*
|
|
604
|
+
* 两处调用:流式结束后发现取消标记、以及流被 abort 中断抛错时。
|
|
605
|
+
*/
|
|
606
|
+
private _finishInterrupted;
|
|
488
607
|
/**
|
|
489
608
|
* 核心迭代循环
|
|
490
609
|
*
|
|
@@ -501,6 +620,8 @@ declare class TurnEngine {
|
|
|
501
620
|
* PERMISSION_REQUIRED 事件并调用 approver;被拒/未知工具
|
|
502
621
|
* 直接产出错误结果,不进入执行。
|
|
503
622
|
* B. 分类执行:低风险工具并发执行(Promise.all),其余串行;
|
|
623
|
+
* 交互类工具(ask_user / propose_plan / request_directory)虽然
|
|
624
|
+
* 风险级别为 low,但需要用户逐条作答,一律串行;
|
|
504
625
|
* 每个结果都转成 tool 消息追加到历史并产出 TOOL_FINISHED。
|
|
505
626
|
*/
|
|
506
627
|
private _handleToolCalls;
|
|
@@ -528,8 +649,14 @@ declare class TurnEngine {
|
|
|
528
649
|
* 消息即停止;只有末尾全部是 error 通知才返回 true。
|
|
529
650
|
*/
|
|
530
651
|
private _tailIsRetriableError;
|
|
652
|
+
/** 当前上下文 token 用量:优先采信 API 返回的精确数量,否则用 chars/4 估算 */
|
|
653
|
+
private _compactionTokens;
|
|
531
654
|
/** 检查是否需要压缩(每轮 LLM 调用前) */
|
|
532
655
|
private _compactionDue;
|
|
656
|
+
/** 组装压缩开始时的用量信息(供 hook 与 COMPACTING 事件携带) */
|
|
657
|
+
private _compactionStartInfo;
|
|
658
|
+
/** 组装压缩结果信息(供 hook 与 COMPACTED 事件携带) */
|
|
659
|
+
private _compactionDoneInfo;
|
|
533
660
|
/** 获取当前模型的上下文窗口大小(token 数)。优先级:显式配置 > 自动检测 > 默认值 128K。 */
|
|
534
661
|
private _getContextWindow;
|
|
535
662
|
/** 执行压缩策略(对齐 Python 版 _compact_now) */
|
|
@@ -559,7 +686,7 @@ declare class TurnEngine {
|
|
|
559
686
|
* 构建 Explorer 子引擎 (对齐 Python 版 build_explorer_engine)
|
|
560
687
|
*
|
|
561
688
|
* 只注册只读工具,使用 Plan 模式权限引擎(硬阻断所有写入),
|
|
562
|
-
*
|
|
689
|
+
* 迭代上限默认 30 次(环境变量 EXPLORE_MAX_ITERATIONS 可覆盖)。
|
|
563
690
|
*
|
|
564
691
|
* 可选 readonlyRegistrars:外部可注入"只读工具注册器"(例如沙箱远程工具),
|
|
565
692
|
* 用于把 explore 子代理的执行目标从宿主机工作区切换到远程沙箱。
|
|
@@ -570,6 +697,11 @@ declare function buildExplorerEngine(opts: {
|
|
|
570
697
|
provider: ProviderClient;
|
|
571
698
|
model: string;
|
|
572
699
|
readonlyRegistrars?: (registry: ToolRegistry) => void;
|
|
700
|
+
/**
|
|
701
|
+
* 子引擎生命周期钩子(可选):注入后子代理的执行过程(工具活动、终态)
|
|
702
|
+
* 会回调给调用方渲染(如 CLI 的 SubagentHook);不传则与旧版一致(静默)。
|
|
703
|
+
*/
|
|
704
|
+
hook?: EngineHook;
|
|
573
705
|
}): TurnEngine;
|
|
574
706
|
/**
|
|
575
707
|
* 创建 explore 工具函数
|
|
@@ -582,6 +714,13 @@ declare function makeExploreTool(opts: {
|
|
|
582
714
|
provider: ProviderClient;
|
|
583
715
|
model: string;
|
|
584
716
|
readonlyRegistrars?: (registry: ToolRegistry) => void;
|
|
717
|
+
/**
|
|
718
|
+
* 子引擎钩子工厂(可选):每次 explore 调用生成一个新实例。
|
|
719
|
+
*
|
|
720
|
+
* 用工厂而非共享实例,是因为低风险工具会被并发执行(同一条回复里的多个
|
|
721
|
+
* explore 会同时运行),共享同一个渲染器会互相串状态、输出交错难辨。
|
|
722
|
+
*/
|
|
723
|
+
hookFactory?: () => EngineHook;
|
|
585
724
|
}): (args: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
586
725
|
/** 注册 explore 工具(低风险,无需审批) */
|
|
587
726
|
declare function registerExploreTool(registry: ToolRegistry, opts: {
|
|
@@ -589,6 +728,8 @@ declare function registerExploreTool(registry: ToolRegistry, opts: {
|
|
|
589
728
|
provider: ProviderClient;
|
|
590
729
|
model: string;
|
|
591
730
|
readonlyRegistrars?: (registry: ToolRegistry) => void;
|
|
731
|
+
/** 子引擎钩子工厂(可选):见 makeExploreTool */
|
|
732
|
+
hookFactory?: () => EngineHook;
|
|
592
733
|
}): void;
|
|
593
734
|
|
|
594
|
-
export { ApprovalOutcome as A, type Decision as D, type EngineHook as E, Mode as M, OpenAIProvider as O, type ProviderClient as P, TurnEngine as T, type WsEvent as W,
|
|
735
|
+
export { ApprovalOutcome as A, type CompactionStartInfo as C, type Decision as D, type EngineHook as E, Mode as M, OpenAIProvider as O, type ProviderClient as P, TurnEngine as T, type WsEvent as W, type CompactionDoneInfo as a, EventType as b, type EngineErrorInfo as c, type Approver as d, type CompactionTrigger as e, PermissionEngine as f, type PermissionRequest as g, type TurnEngineOpts as h, buildExplorerEngine as i, makeExploreTool as m, registerExploreTool as r };
|