@zhushanwen/subagent-engine-sdk 0.3.0 → 0.4.0
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/{chunk-TGDMOLZU.js → chunk-TW2FAMAJ.js} +2 -18
- package/dist/{contract-types-ByIFoLrY.d.cts → contract-types-C71Sqq8d.d.cts} +13 -9
- package/dist/{contract-types-ByIFoLrY.d.ts → contract-types-C71Sqq8d.d.ts} +13 -9
- package/dist/{error-codes-BUx92qYi.d.ts → error-codes-CiOO3PMg.d.cts} +3 -4
- package/dist/{error-codes-DCiilt_8.d.cts → error-codes-D5YlWaBx.d.ts} +3 -4
- package/dist/index.cjs +2 -20
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -5
- package/dist/journal-io.d.cts +1 -1
- package/dist/journal-io.d.ts +1 -1
- package/dist/journal-replay.d.cts +1 -1
- package/dist/journal-replay.d.ts +1 -1
- package/dist/kill-chain.d.cts +2 -2
- package/dist/kill-chain.d.ts +2 -2
- package/dist/port-contract.d.cts +11 -10
- package/dist/port-contract.d.ts +11 -10
- package/dist/protocol/index.cjs +2 -20
- package/dist/protocol/index.d.cts +19 -95
- package/dist/protocol/index.d.ts +19 -95
- package/dist/protocol/index.js +1 -5
- package/package.json +1 -1
- package/src/nesting-guard.ts +1 -1
- package/src/paths.ts +1 -1
- package/src/port-contract.ts +10 -9
- package/src/protocol/contract-types.ts +17 -13
- package/src/protocol/engine-protocol.ts +4 -4
- package/src/protocol/frames.ts +1 -3
- package/src/protocol/methods.ts +3 -5
- package/src/protocol/reverse-channels.ts +13 -76
- package/src/protocol/schema.ts +2 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-
|
|
3
|
-
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-
|
|
1
|
+
export { E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from '../error-codes-CiOO3PMg.cjs';
|
|
2
|
+
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-C71Sqq8d.cjs';
|
|
3
|
+
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-C71Sqq8d.cjs';
|
|
4
4
|
import { UiRequest, UiResponse } from '../ui-types.cjs';
|
|
5
5
|
|
|
6
6
|
/** 协议版本(引擎包 manifest `xyz-agent.subagentEngine.protocol` 与 initialize 应答同值)。 */
|
|
@@ -31,16 +31,16 @@ declare const ENGINE_EVENT_COALESCE_ENV = "XYZ_ENGINE_EVENT_COALESCE";
|
|
|
31
31
|
declare const ENGINE_EVENT_COALESCE_DEFAULT = "0";
|
|
32
32
|
/**
|
|
33
33
|
* 反向请求超时二分(帧④注释,R9-2):
|
|
34
|
-
* - 数据面类(host/log / host/streamDelta / host/
|
|
34
|
+
* - 数据面类(host/log / host/streamDelta / host/handleReady /
|
|
35
35
|
* host/childSpawned / host/childStateChanged):10s 未答 = 引擎故障;
|
|
36
|
-
* - 人机交互类(host/askUser
|
|
36
|
+
* - 人机交互类(host/askUser):不设统一超时——core 先回 {ack:true},
|
|
37
37
|
* 结果异步到达;按 ADR-0047「静默 ≠ 卡死」用无进展检测/用户取消,不据此判引擎故障。
|
|
38
38
|
*/
|
|
39
39
|
type ReverseRequestTimeoutClass = "data-plane" | "interaction";
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* 正向方法名联合(恰好 9 个;PROTOCOL_METHODS 常量数组与之同源互证)。
|
|
43
|
-
* [H1] `interact` 成员已随 chat-run 统一退役(docs/
|
|
43
|
+
* [H1] `interact` 成员已随 chat-run 统一退役(docs/architecture/subagent-chat-run-unification.md
|
|
44
44
|
* §3.3 D5:续聊轮统一为「新 run + resume 锚点」,U5 删除)。
|
|
45
45
|
*/
|
|
46
46
|
type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
|
|
@@ -50,8 +50,6 @@ declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel"
|
|
|
50
50
|
* run 上下文(RunContext 字段映射的协议承载,设计 §3.3 RunContext 映射表)。
|
|
51
51
|
*/
|
|
52
52
|
interface RunContextParams {
|
|
53
|
-
/** 隔离池归属(journal 归属错 = 缺失后果)。 */
|
|
54
|
-
poolKey: string;
|
|
55
53
|
/** 任务工作目录(worktree 隔离时 = worktree 路径)。 */
|
|
56
54
|
cwd: string;
|
|
57
55
|
/** 请求模型 ref(未传 = 引擎缺省模型)。 */
|
|
@@ -83,7 +81,7 @@ interface RunContextParams {
|
|
|
83
81
|
sessionDir?: string;
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
|
-
* [H1] run 的 resume 会话形态参数(设计 docs/
|
|
84
|
+
* [H1] run 的 resume 会话形态参数(设计 docs/architecture/subagent-chat-run-unification.md
|
|
87
85
|
* §3.3 D3 + §5 U1/U6 行):原 RunChatParams(v1.x chat 会话形态参数)的泛化改名终态,
|
|
88
86
|
* 载荷同形(recordId + resume 锚点,ResumeAnchor 不变),仅键名从「chat 会话形态」
|
|
89
87
|
* 泛化为「resume 续聊」。
|
|
@@ -208,13 +206,13 @@ interface ProtocolResultMap {
|
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
/**
|
|
211
|
-
* 反向通道名联合(恰好
|
|
209
|
+
* 反向通道名联合(恰好 6 个;REVERSE_CHANNELS 常量数组与之同源互证)。
|
|
212
210
|
*/
|
|
213
|
-
type ReverseChannel = "host/log" | "host/askUser" | "host/
|
|
211
|
+
type ReverseChannel = "host/log" | "host/askUser" | "host/streamDelta" | "host/handleReady" | "host/childSpawned" | "host/childStateChanged";
|
|
214
212
|
/**
|
|
215
213
|
* 通道名全集(运行时顺序化枚举;与 ReverseChannel 的同源关系由测试断言)。
|
|
216
214
|
*/
|
|
217
|
-
declare const REVERSE_CHANNELS: readonly ["host/log", "host/askUser", "host/
|
|
215
|
+
declare const REVERSE_CHANNELS: readonly ["host/log", "host/askUser", "host/streamDelta", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
|
|
218
216
|
/**
|
|
219
217
|
* 超时二分归属(10s 数据面 / 不设统一超时的人机交互面)。实现归 W2 EngineClient;
|
|
220
218
|
* 引擎侧自灭计时(W12)复用同表——已 ack 的 askUser 等待不计入 in-flight(R9-2)。
|
|
@@ -235,59 +233,24 @@ interface HostAskUserParams {
|
|
|
235
233
|
}
|
|
236
234
|
/** host/askUser 的最终结果(ack 两阶段第二阶段,异步应答帧②的 result)。 */
|
|
237
235
|
type HostAskUserResult = UiResponse;
|
|
238
|
-
/**
|
|
239
|
-
* host/permission:权限询问(引擎请求宿主裁决工具执行)。
|
|
240
|
-
* v1 骨架字段(设计未钉死载荷细节,细化归各引擎提取设计;W2 实装 core 应答端时
|
|
241
|
-
* 若需扩展走 additive 演进)。
|
|
242
|
-
*/
|
|
243
|
-
interface HostPermissionParams {
|
|
244
|
-
runId: string;
|
|
245
|
-
toolName: string;
|
|
246
|
-
args?: unknown;
|
|
247
|
-
/** 请求方向引擎给出的原因/说明(展示用)。 */
|
|
248
|
-
reason?: string;
|
|
249
|
-
}
|
|
250
|
-
/** host/permission 两阶段结果。 */
|
|
251
|
-
type HostPermissionResult = {
|
|
252
|
-
approved: boolean;
|
|
253
|
-
} | {
|
|
254
|
-
unsupported: true;
|
|
255
|
-
};
|
|
256
236
|
/**
|
|
257
237
|
* host/streamDelta:UI 实时通道(双通道之一;与 event 通知并行的渲染加速面)。
|
|
258
238
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* v1.x 旧引擎的兼容载荷形态(存量兼容读,现行引擎不写)。
|
|
262
|
-
* 两键互斥(undefined 孪生位防双填),消费侧经 isHostStreamDeltaParams 收窄。
|
|
239
|
+
* 关联键恒为 runId(runId 由 core 在 run 帧分配);[H1] chat 续聊轮经 resume run
|
|
240
|
+
* 复用 runId 关联(原 recordId 关联键随 interact 面退役删除)。
|
|
263
241
|
*/
|
|
264
|
-
|
|
242
|
+
interface HostStreamDeltaParams {
|
|
265
243
|
runId: string;
|
|
266
|
-
recordId?: undefined;
|
|
267
244
|
delta: string;
|
|
268
|
-
} | {
|
|
269
|
-
recordId: string;
|
|
270
|
-
runId?: undefined;
|
|
271
|
-
delta: string;
|
|
272
|
-
};
|
|
273
|
-
/** streamDelta 载荷结构判定(关联键互斥 + delta 形状;消费侧共用,防双侧各写一份)。 */
|
|
274
|
-
declare function isHostStreamDeltaParams(value: unknown): value is HostStreamDeltaParams;
|
|
275
|
-
/**
|
|
276
|
-
* host/poolResolved:journal 落盘路径单一权威(契约:必须在首个事件 emit 前调用——
|
|
277
|
-
* 否则 journal 归属错)。载荷 = core onPoolResolved(poolKey) 的 runId 关联形态。
|
|
278
|
-
*/
|
|
279
|
-
interface HostPoolResolvedParams {
|
|
280
|
-
runId: string;
|
|
281
|
-
poolKey: string;
|
|
282
245
|
}
|
|
283
246
|
/**
|
|
284
247
|
* host/handleReady:运行中句柄回填(core onHandleReady 语义:session/create 应答后、
|
|
285
248
|
* 早于 run resolve;AGENTS.md 关键规则 9「重开 session 仍可见」的前提)。
|
|
249
|
+
* [池抽象降级 2026-09-13] 原 poolKey 字段已随协议面 poolKey 退役删除。
|
|
286
250
|
*/
|
|
287
251
|
interface HostHandleReadyParams {
|
|
288
252
|
runId: string;
|
|
289
253
|
sessionRef: Record<string, string>;
|
|
290
|
-
poolKey: string;
|
|
291
254
|
}
|
|
292
255
|
/**
|
|
293
256
|
* host/childSpawned:引擎内一次性子进程 pid 上报。
|
|
@@ -312,40 +275,6 @@ interface HostChildStateChangedParams {
|
|
|
312
275
|
exitCode?: number;
|
|
313
276
|
signal?: string;
|
|
314
277
|
}
|
|
315
|
-
/** 通道 → 载荷类型映射。 */
|
|
316
|
-
interface ReverseChannelParamsMap {
|
|
317
|
-
"host/log": HostLogParams;
|
|
318
|
-
"host/askUser": HostAskUserParams;
|
|
319
|
-
"host/permission": HostPermissionParams;
|
|
320
|
-
"host/streamDelta": HostStreamDeltaParams;
|
|
321
|
-
"host/poolResolved": HostPoolResolvedParams;
|
|
322
|
-
"host/handleReady": HostHandleReadyParams;
|
|
323
|
-
"host/childSpawned": HostChildSpawnedParams;
|
|
324
|
-
"host/childStateChanged": HostChildStateChangedParams;
|
|
325
|
-
}
|
|
326
|
-
/** 通道 → 异步/同步结果类型映射(ack 两阶段通道的第二阶段 result)。 */
|
|
327
|
-
interface ReverseChannelResultMap {
|
|
328
|
-
"host/log": {
|
|
329
|
-
ok: true;
|
|
330
|
-
};
|
|
331
|
-
"host/askUser": HostAskUserResult;
|
|
332
|
-
"host/permission": HostPermissionResult;
|
|
333
|
-
"host/streamDelta": {
|
|
334
|
-
ok: true;
|
|
335
|
-
};
|
|
336
|
-
"host/poolResolved": {
|
|
337
|
-
ok: true;
|
|
338
|
-
};
|
|
339
|
-
"host/handleReady": {
|
|
340
|
-
ok: true;
|
|
341
|
-
};
|
|
342
|
-
"host/childSpawned": {
|
|
343
|
-
ok: true;
|
|
344
|
-
};
|
|
345
|
-
"host/childStateChanged": {
|
|
346
|
-
ok: true;
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
278
|
|
|
350
279
|
/** 协议错误对象 schema。 */
|
|
351
280
|
declare const protocolErrorSchema: {
|
|
@@ -486,7 +415,7 @@ declare const reverseRequestFrameSchema: {
|
|
|
486
415
|
};
|
|
487
416
|
readonly method: {
|
|
488
417
|
readonly type: "string";
|
|
489
|
-
readonly enum: readonly ["host/log", "host/askUser", "host/
|
|
418
|
+
readonly enum: readonly ["host/log", "host/askUser", "host/streamDelta", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
|
|
490
419
|
};
|
|
491
420
|
readonly params: {};
|
|
492
421
|
};
|
|
@@ -605,7 +534,7 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
|
|
|
605
534
|
};
|
|
606
535
|
readonly method: {
|
|
607
536
|
readonly type: "string";
|
|
608
|
-
readonly enum: readonly ["host/log", "host/askUser", "host/
|
|
537
|
+
readonly enum: readonly ["host/log", "host/askUser", "host/streamDelta", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
|
|
609
538
|
};
|
|
610
539
|
readonly params: {};
|
|
611
540
|
};
|
|
@@ -638,11 +567,9 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
|
|
|
638
567
|
* 不得出现。词表覆盖常见拼写(子串匹配,非精确枚举)。
|
|
639
568
|
*/
|
|
640
569
|
declare const FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS: readonly ["apikey", "api_key", "token", "credential", "password", "secret"];
|
|
641
|
-
/** 反向通道名词表导出(schema enum 与 W2 路由同源)。 */
|
|
642
|
-
declare const REVERSE_CHANNEL_NAMES: readonly ReverseChannel[];
|
|
643
570
|
/**
|
|
644
571
|
* run.params 的会话形态参数载荷 schema(draft-07 深载荷片段)。设计权威源:
|
|
645
|
-
* docs/
|
|
572
|
+
* docs/architecture/subagent-chat-run-unification.md §3.3 D3 + §5 U1/U6 行。
|
|
646
573
|
*
|
|
647
574
|
* [H1 U6 已切换] 键切换单批完成后本 schema 面向唯一键 `resume`(RunResumeParams:
|
|
648
575
|
* recordId + 可选 ResumeAnchor),形状不变。帧级 schema(requestFrameSchema.params)
|
|
@@ -662,7 +589,7 @@ declare const runSessionParamsSchema: {
|
|
|
662
589
|
readonly resume: {
|
|
663
590
|
readonly type: "object";
|
|
664
591
|
readonly additionalProperties: false;
|
|
665
|
-
readonly required: readonly ["sessionRef"
|
|
592
|
+
readonly required: readonly ["sessionRef"];
|
|
666
593
|
readonly properties: {
|
|
667
594
|
readonly sessionRef: {
|
|
668
595
|
readonly type: "object";
|
|
@@ -670,9 +597,6 @@ declare const runSessionParamsSchema: {
|
|
|
670
597
|
readonly type: "string";
|
|
671
598
|
};
|
|
672
599
|
};
|
|
673
|
-
readonly poolKey: {
|
|
674
|
-
readonly type: "string";
|
|
675
|
-
};
|
|
676
600
|
readonly journalPath: {
|
|
677
601
|
readonly type: "string";
|
|
678
602
|
};
|
|
@@ -681,4 +605,4 @@ declare const runSessionParamsSchema: {
|
|
|
681
605
|
};
|
|
682
606
|
};
|
|
683
607
|
|
|
684
|
-
export { AgentCallOpts, AgentOutcome, CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, type CancelParams, type CancelResult, type DisposeParams, type DisposeResult, ENGINE_EVENT_COALESCE_DEFAULT, ENGINE_EVENT_COALESCE_ENV, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, EngineCapabilities, EngineHandleData, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type
|
|
608
|
+
export { AgentCallOpts, AgentOutcome, CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, type CancelParams, type CancelResult, type DisposeParams, type DisposeResult, ENGINE_EVENT_COALESCE_DEFAULT, ENGINE_EVENT_COALESCE_ENV, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, EngineCapabilities, EngineHandleData, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type HostStreamDeltaParams, type InitializeParams, type InitializeResult, type ListModelsParams, type ListModelsResult, ModelCatalogEntry, PROTOCOL_METHODS, type PingParams, type PingResult, type ProbeParams, ProbeReport, type ProtocolMethod, type ProtocolParamsMap, type ProtocolResultMap, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, type ReadParams, ResumeAnchor, type ReverseChannel, type ReverseRequestTimeoutClass, type RunContextParams, type RunParams, type RunResult, type RunResumeParams, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, SessionView, type ValidateModelParams, type ValidateModelResult, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema };
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-
|
|
3
|
-
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-
|
|
1
|
+
export { E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from '../error-codes-D5YlWaBx.js';
|
|
2
|
+
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-C71Sqq8d.js';
|
|
3
|
+
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-C71Sqq8d.js';
|
|
4
4
|
import { UiRequest, UiResponse } from '../ui-types.js';
|
|
5
5
|
|
|
6
6
|
/** 协议版本(引擎包 manifest `xyz-agent.subagentEngine.protocol` 与 initialize 应答同值)。 */
|
|
@@ -31,16 +31,16 @@ declare const ENGINE_EVENT_COALESCE_ENV = "XYZ_ENGINE_EVENT_COALESCE";
|
|
|
31
31
|
declare const ENGINE_EVENT_COALESCE_DEFAULT = "0";
|
|
32
32
|
/**
|
|
33
33
|
* 反向请求超时二分(帧④注释,R9-2):
|
|
34
|
-
* - 数据面类(host/log / host/streamDelta / host/
|
|
34
|
+
* - 数据面类(host/log / host/streamDelta / host/handleReady /
|
|
35
35
|
* host/childSpawned / host/childStateChanged):10s 未答 = 引擎故障;
|
|
36
|
-
* - 人机交互类(host/askUser
|
|
36
|
+
* - 人机交互类(host/askUser):不设统一超时——core 先回 {ack:true},
|
|
37
37
|
* 结果异步到达;按 ADR-0047「静默 ≠ 卡死」用无进展检测/用户取消,不据此判引擎故障。
|
|
38
38
|
*/
|
|
39
39
|
type ReverseRequestTimeoutClass = "data-plane" | "interaction";
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* 正向方法名联合(恰好 9 个;PROTOCOL_METHODS 常量数组与之同源互证)。
|
|
43
|
-
* [H1] `interact` 成员已随 chat-run 统一退役(docs/
|
|
43
|
+
* [H1] `interact` 成员已随 chat-run 统一退役(docs/architecture/subagent-chat-run-unification.md
|
|
44
44
|
* §3.3 D5:续聊轮统一为「新 run + resume 锚点」,U5 删除)。
|
|
45
45
|
*/
|
|
46
46
|
type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
|
|
@@ -50,8 +50,6 @@ declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel"
|
|
|
50
50
|
* run 上下文(RunContext 字段映射的协议承载,设计 §3.3 RunContext 映射表)。
|
|
51
51
|
*/
|
|
52
52
|
interface RunContextParams {
|
|
53
|
-
/** 隔离池归属(journal 归属错 = 缺失后果)。 */
|
|
54
|
-
poolKey: string;
|
|
55
53
|
/** 任务工作目录(worktree 隔离时 = worktree 路径)。 */
|
|
56
54
|
cwd: string;
|
|
57
55
|
/** 请求模型 ref(未传 = 引擎缺省模型)。 */
|
|
@@ -83,7 +81,7 @@ interface RunContextParams {
|
|
|
83
81
|
sessionDir?: string;
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
|
-
* [H1] run 的 resume 会话形态参数(设计 docs/
|
|
84
|
+
* [H1] run 的 resume 会话形态参数(设计 docs/architecture/subagent-chat-run-unification.md
|
|
87
85
|
* §3.3 D3 + §5 U1/U6 行):原 RunChatParams(v1.x chat 会话形态参数)的泛化改名终态,
|
|
88
86
|
* 载荷同形(recordId + resume 锚点,ResumeAnchor 不变),仅键名从「chat 会话形态」
|
|
89
87
|
* 泛化为「resume 续聊」。
|
|
@@ -208,13 +206,13 @@ interface ProtocolResultMap {
|
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
/**
|
|
211
|
-
* 反向通道名联合(恰好
|
|
209
|
+
* 反向通道名联合(恰好 6 个;REVERSE_CHANNELS 常量数组与之同源互证)。
|
|
212
210
|
*/
|
|
213
|
-
type ReverseChannel = "host/log" | "host/askUser" | "host/
|
|
211
|
+
type ReverseChannel = "host/log" | "host/askUser" | "host/streamDelta" | "host/handleReady" | "host/childSpawned" | "host/childStateChanged";
|
|
214
212
|
/**
|
|
215
213
|
* 通道名全集(运行时顺序化枚举;与 ReverseChannel 的同源关系由测试断言)。
|
|
216
214
|
*/
|
|
217
|
-
declare const REVERSE_CHANNELS: readonly ["host/log", "host/askUser", "host/
|
|
215
|
+
declare const REVERSE_CHANNELS: readonly ["host/log", "host/askUser", "host/streamDelta", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
|
|
218
216
|
/**
|
|
219
217
|
* 超时二分归属(10s 数据面 / 不设统一超时的人机交互面)。实现归 W2 EngineClient;
|
|
220
218
|
* 引擎侧自灭计时(W12)复用同表——已 ack 的 askUser 等待不计入 in-flight(R9-2)。
|
|
@@ -235,59 +233,24 @@ interface HostAskUserParams {
|
|
|
235
233
|
}
|
|
236
234
|
/** host/askUser 的最终结果(ack 两阶段第二阶段,异步应答帧②的 result)。 */
|
|
237
235
|
type HostAskUserResult = UiResponse;
|
|
238
|
-
/**
|
|
239
|
-
* host/permission:权限询问(引擎请求宿主裁决工具执行)。
|
|
240
|
-
* v1 骨架字段(设计未钉死载荷细节,细化归各引擎提取设计;W2 实装 core 应答端时
|
|
241
|
-
* 若需扩展走 additive 演进)。
|
|
242
|
-
*/
|
|
243
|
-
interface HostPermissionParams {
|
|
244
|
-
runId: string;
|
|
245
|
-
toolName: string;
|
|
246
|
-
args?: unknown;
|
|
247
|
-
/** 请求方向引擎给出的原因/说明(展示用)。 */
|
|
248
|
-
reason?: string;
|
|
249
|
-
}
|
|
250
|
-
/** host/permission 两阶段结果。 */
|
|
251
|
-
type HostPermissionResult = {
|
|
252
|
-
approved: boolean;
|
|
253
|
-
} | {
|
|
254
|
-
unsupported: true;
|
|
255
|
-
};
|
|
256
236
|
/**
|
|
257
237
|
* host/streamDelta:UI 实时通道(双通道之一;与 event 通知并行的渲染加速面)。
|
|
258
238
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* v1.x 旧引擎的兼容载荷形态(存量兼容读,现行引擎不写)。
|
|
262
|
-
* 两键互斥(undefined 孪生位防双填),消费侧经 isHostStreamDeltaParams 收窄。
|
|
239
|
+
* 关联键恒为 runId(runId 由 core 在 run 帧分配);[H1] chat 续聊轮经 resume run
|
|
240
|
+
* 复用 runId 关联(原 recordId 关联键随 interact 面退役删除)。
|
|
263
241
|
*/
|
|
264
|
-
|
|
242
|
+
interface HostStreamDeltaParams {
|
|
265
243
|
runId: string;
|
|
266
|
-
recordId?: undefined;
|
|
267
244
|
delta: string;
|
|
268
|
-
} | {
|
|
269
|
-
recordId: string;
|
|
270
|
-
runId?: undefined;
|
|
271
|
-
delta: string;
|
|
272
|
-
};
|
|
273
|
-
/** streamDelta 载荷结构判定(关联键互斥 + delta 形状;消费侧共用,防双侧各写一份)。 */
|
|
274
|
-
declare function isHostStreamDeltaParams(value: unknown): value is HostStreamDeltaParams;
|
|
275
|
-
/**
|
|
276
|
-
* host/poolResolved:journal 落盘路径单一权威(契约:必须在首个事件 emit 前调用——
|
|
277
|
-
* 否则 journal 归属错)。载荷 = core onPoolResolved(poolKey) 的 runId 关联形态。
|
|
278
|
-
*/
|
|
279
|
-
interface HostPoolResolvedParams {
|
|
280
|
-
runId: string;
|
|
281
|
-
poolKey: string;
|
|
282
245
|
}
|
|
283
246
|
/**
|
|
284
247
|
* host/handleReady:运行中句柄回填(core onHandleReady 语义:session/create 应答后、
|
|
285
248
|
* 早于 run resolve;AGENTS.md 关键规则 9「重开 session 仍可见」的前提)。
|
|
249
|
+
* [池抽象降级 2026-09-13] 原 poolKey 字段已随协议面 poolKey 退役删除。
|
|
286
250
|
*/
|
|
287
251
|
interface HostHandleReadyParams {
|
|
288
252
|
runId: string;
|
|
289
253
|
sessionRef: Record<string, string>;
|
|
290
|
-
poolKey: string;
|
|
291
254
|
}
|
|
292
255
|
/**
|
|
293
256
|
* host/childSpawned:引擎内一次性子进程 pid 上报。
|
|
@@ -312,40 +275,6 @@ interface HostChildStateChangedParams {
|
|
|
312
275
|
exitCode?: number;
|
|
313
276
|
signal?: string;
|
|
314
277
|
}
|
|
315
|
-
/** 通道 → 载荷类型映射。 */
|
|
316
|
-
interface ReverseChannelParamsMap {
|
|
317
|
-
"host/log": HostLogParams;
|
|
318
|
-
"host/askUser": HostAskUserParams;
|
|
319
|
-
"host/permission": HostPermissionParams;
|
|
320
|
-
"host/streamDelta": HostStreamDeltaParams;
|
|
321
|
-
"host/poolResolved": HostPoolResolvedParams;
|
|
322
|
-
"host/handleReady": HostHandleReadyParams;
|
|
323
|
-
"host/childSpawned": HostChildSpawnedParams;
|
|
324
|
-
"host/childStateChanged": HostChildStateChangedParams;
|
|
325
|
-
}
|
|
326
|
-
/** 通道 → 异步/同步结果类型映射(ack 两阶段通道的第二阶段 result)。 */
|
|
327
|
-
interface ReverseChannelResultMap {
|
|
328
|
-
"host/log": {
|
|
329
|
-
ok: true;
|
|
330
|
-
};
|
|
331
|
-
"host/askUser": HostAskUserResult;
|
|
332
|
-
"host/permission": HostPermissionResult;
|
|
333
|
-
"host/streamDelta": {
|
|
334
|
-
ok: true;
|
|
335
|
-
};
|
|
336
|
-
"host/poolResolved": {
|
|
337
|
-
ok: true;
|
|
338
|
-
};
|
|
339
|
-
"host/handleReady": {
|
|
340
|
-
ok: true;
|
|
341
|
-
};
|
|
342
|
-
"host/childSpawned": {
|
|
343
|
-
ok: true;
|
|
344
|
-
};
|
|
345
|
-
"host/childStateChanged": {
|
|
346
|
-
ok: true;
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
278
|
|
|
350
279
|
/** 协议错误对象 schema。 */
|
|
351
280
|
declare const protocolErrorSchema: {
|
|
@@ -486,7 +415,7 @@ declare const reverseRequestFrameSchema: {
|
|
|
486
415
|
};
|
|
487
416
|
readonly method: {
|
|
488
417
|
readonly type: "string";
|
|
489
|
-
readonly enum: readonly ["host/log", "host/askUser", "host/
|
|
418
|
+
readonly enum: readonly ["host/log", "host/askUser", "host/streamDelta", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
|
|
490
419
|
};
|
|
491
420
|
readonly params: {};
|
|
492
421
|
};
|
|
@@ -605,7 +534,7 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
|
|
|
605
534
|
};
|
|
606
535
|
readonly method: {
|
|
607
536
|
readonly type: "string";
|
|
608
|
-
readonly enum: readonly ["host/log", "host/askUser", "host/
|
|
537
|
+
readonly enum: readonly ["host/log", "host/askUser", "host/streamDelta", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
|
|
609
538
|
};
|
|
610
539
|
readonly params: {};
|
|
611
540
|
};
|
|
@@ -638,11 +567,9 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
|
|
|
638
567
|
* 不得出现。词表覆盖常见拼写(子串匹配,非精确枚举)。
|
|
639
568
|
*/
|
|
640
569
|
declare const FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS: readonly ["apikey", "api_key", "token", "credential", "password", "secret"];
|
|
641
|
-
/** 反向通道名词表导出(schema enum 与 W2 路由同源)。 */
|
|
642
|
-
declare const REVERSE_CHANNEL_NAMES: readonly ReverseChannel[];
|
|
643
570
|
/**
|
|
644
571
|
* run.params 的会话形态参数载荷 schema(draft-07 深载荷片段)。设计权威源:
|
|
645
|
-
* docs/
|
|
572
|
+
* docs/architecture/subagent-chat-run-unification.md §3.3 D3 + §5 U1/U6 行。
|
|
646
573
|
*
|
|
647
574
|
* [H1 U6 已切换] 键切换单批完成后本 schema 面向唯一键 `resume`(RunResumeParams:
|
|
648
575
|
* recordId + 可选 ResumeAnchor),形状不变。帧级 schema(requestFrameSchema.params)
|
|
@@ -662,7 +589,7 @@ declare const runSessionParamsSchema: {
|
|
|
662
589
|
readonly resume: {
|
|
663
590
|
readonly type: "object";
|
|
664
591
|
readonly additionalProperties: false;
|
|
665
|
-
readonly required: readonly ["sessionRef"
|
|
592
|
+
readonly required: readonly ["sessionRef"];
|
|
666
593
|
readonly properties: {
|
|
667
594
|
readonly sessionRef: {
|
|
668
595
|
readonly type: "object";
|
|
@@ -670,9 +597,6 @@ declare const runSessionParamsSchema: {
|
|
|
670
597
|
readonly type: "string";
|
|
671
598
|
};
|
|
672
599
|
};
|
|
673
|
-
readonly poolKey: {
|
|
674
|
-
readonly type: "string";
|
|
675
|
-
};
|
|
676
600
|
readonly journalPath: {
|
|
677
601
|
readonly type: "string";
|
|
678
602
|
};
|
|
@@ -681,4 +605,4 @@ declare const runSessionParamsSchema: {
|
|
|
681
605
|
};
|
|
682
606
|
};
|
|
683
607
|
|
|
684
|
-
export { AgentCallOpts, AgentOutcome, CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, type CancelParams, type CancelResult, type DisposeParams, type DisposeResult, ENGINE_EVENT_COALESCE_DEFAULT, ENGINE_EVENT_COALESCE_ENV, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, EngineCapabilities, EngineHandleData, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type
|
|
608
|
+
export { AgentCallOpts, AgentOutcome, CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, type CancelParams, type CancelResult, type DisposeParams, type DisposeResult, ENGINE_EVENT_COALESCE_DEFAULT, ENGINE_EVENT_COALESCE_ENV, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, EngineCapabilities, EngineHandleData, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type HostStreamDeltaParams, type InitializeParams, type InitializeResult, type ListModelsParams, type ListModelsResult, ModelCatalogEntry, PROTOCOL_METHODS, type PingParams, type PingResult, type ProbeParams, ProbeReport, type ProtocolMethod, type ProtocolParamsMap, type ProtocolResultMap, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, type ReadParams, ResumeAnchor, type ReverseChannel, type ReverseRequestTimeoutClass, type RunContextParams, type RunParams, type RunResult, type RunResumeParams, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, SessionView, type ValidateModelParams, type ValidateModelResult, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema };
|
package/dist/protocol/index.js
CHANGED
|
@@ -3,10 +3,8 @@ import {
|
|
|
3
3
|
FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
|
|
4
4
|
PROTOCOL_METHODS,
|
|
5
5
|
REVERSE_CHANNELS,
|
|
6
|
-
REVERSE_CHANNEL_NAMES,
|
|
7
6
|
REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
8
7
|
errorResponseFrameSchema,
|
|
9
|
-
isHostStreamDeltaParams,
|
|
10
8
|
isNotificationFrame,
|
|
11
9
|
isRequestFrame,
|
|
12
10
|
isResponseFrame,
|
|
@@ -17,7 +15,7 @@ import {
|
|
|
17
15
|
reverseRequestFrameSchema,
|
|
18
16
|
runSessionParamsSchema,
|
|
19
17
|
successResponseFrameSchema
|
|
20
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-TW2FAMAJ.js";
|
|
21
19
|
import {
|
|
22
20
|
CANCEL_SETTLE_GRACE_MS,
|
|
23
21
|
CRASH_REBUILD_BACKOFF_MS,
|
|
@@ -60,7 +58,6 @@ export {
|
|
|
60
58
|
HANDSHAKE_TIMEOUT_MS,
|
|
61
59
|
PROTOCOL_METHODS,
|
|
62
60
|
REVERSE_CHANNELS,
|
|
63
|
-
REVERSE_CHANNEL_NAMES,
|
|
64
61
|
REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
65
62
|
REVERSE_REQUEST_TIMEOUT_MS,
|
|
66
63
|
STDERR_TAIL_CHARS,
|
|
@@ -73,7 +70,6 @@ export {
|
|
|
73
70
|
errorResponseFrameSchema,
|
|
74
71
|
isEngineErrorPassthroughCode,
|
|
75
72
|
isEngineProtocolErrorCode,
|
|
76
|
-
isHostStreamDeltaParams,
|
|
77
73
|
isNotificationFrame,
|
|
78
74
|
isProtocolVersionCompatible,
|
|
79
75
|
isRequestFrame,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/subagent-engine-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Engine-side SDK for the subagent engine protocol: NDJSON stdio contract types, engine primitives (schema emulation, nesting guard, kill chain, journal replay projection, data-dir/paths resolution) — the shared contract root between subagent-core and engine CLI packages (engines import SDK only, never core)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/nesting-guard.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
//
|
|
18
18
|
// [D3-⑤ 嵌套防护合一] 进程内执行嵌套上下文(原 SubagentService.execCtxAls,pi 路径
|
|
19
19
|
// 私有)并入本文件——「嵌套防护」的两层机制(跨进程 env 标记 / 进程内 ALS 深度计数)
|
|
20
|
-
// 单点于公共层。设计权威源:docs/design/
|
|
20
|
+
// 单点于公共层。设计权威源:docs/design/dual-track(已删 git 可追溯)§3.3 D3-⑤
|
|
21
21
|
// + 双轨清单 #10。
|
|
22
22
|
|
|
23
23
|
import { AsyncLocalStorage } from "node:async_hooks";
|
package/src/paths.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { join } from 'node:path';
|
|
|
7
7
|
* 自算池/journal 路径);core 侧引用切换已完成(core execution/engine/paths.ts 为
|
|
8
8
|
* re-export shim,子入口 ./engine/paths 解析路径不变)。
|
|
9
9
|
*
|
|
10
|
-
* 设计权威源:subagent-engine-abstraction.md D5/D6
|
|
10
|
+
* 设计权威源:constraints.json C-ext-15(原 subagent-engine-abstraction.md D5/D6,已删,git 可追溯)。
|
|
11
11
|
*
|
|
12
12
|
* 为什么独立成模块:extension 写侧(journal 落盘 / preparer 池目录)与
|
|
13
13
|
* runtime 校验侧(subagent-extractor 前缀白名单)必须同源推导——
|
package/src/port-contract.ts
CHANGED
|
@@ -63,19 +63,21 @@ export interface EngineStream {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
66
|
+
* journal 固定分组 key(值锚定,**只承载、不透传**):journal 落盘路径
|
|
67
|
+
* `<dataDir>/engines/<engineId>/<本值>/journal-<taskId>.jsonl` 的第二段,两引擎恒
|
|
68
|
+
* 本值(pi / zcode 均无池化实现——pi = PI_CODING_AGENT_DIR 全局一份,zcode = 共享
|
|
69
|
+
* 宿主 HOME)。[池抽象降级 2026-09-13] poolKey 协议面(RunContext/run.params.ctx/
|
|
70
|
+
* host/poolResolved 通道/EngineHandleData)已整体退役,本常量不再跨进程透传,仅
|
|
71
|
+
* 三类消费:① journal 落盘路径构造(core journal-wiring);② 存量 record 兼容
|
|
72
|
+
* (zcode read 旧相对 dbPath 的锚定分支 + 持久化 engineHandle.poolKey 字段——
|
|
73
|
+
* record-store 读侧守卫要求非空,值恒本常量);③ 引擎数据目录布局 SSOT paths.ts
|
|
74
|
+
* 的签名参数。**值逐字不变**(存量 journal 落盘路径与记录含该值分段,改名不改值)。
|
|
72
75
|
*/
|
|
73
76
|
export const SHARED_POOL_KEY = "shared";
|
|
74
77
|
|
|
75
78
|
/** run 的运行期上下文(core RunContext 结构等价镜像;resume? = 会话形态参数,缺省一次性任务)。 */
|
|
76
79
|
export interface RunContext {
|
|
77
80
|
taskId: string;
|
|
78
|
-
poolKey: string;
|
|
79
81
|
signal?: AbortSignal;
|
|
80
82
|
onEvent?: (event: AgentEvent) => void;
|
|
81
83
|
ctxModel?: EngineCtxModel;
|
|
@@ -94,8 +96,7 @@ export interface RunContext {
|
|
|
94
96
|
* [LEGACY] fallback(独立运行/测试形态)。
|
|
95
97
|
*/
|
|
96
98
|
sessionDir?: string;
|
|
97
|
-
|
|
98
|
-
onHandleReady?: (partial: Pick<EngineHandleData, "sessionRef" | "poolKey">) => void;
|
|
99
|
+
onHandleReady?: (partial: Pick<EngineHandleData, "sessionRef">) => void;
|
|
99
100
|
/** 一次性子进程 pid 上报(host/childSpawned 载荷形态;ChildProcess 句柄不跨协议面)。 */
|
|
100
101
|
onChildSpawned?: (child: { pid: number | undefined; killed: boolean }) => void;
|
|
101
102
|
/**
|