@zhushanwen/subagent-engine-sdk 0.3.0 → 0.5.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-LKPVN3N6.js → chunk-3IBT7MTB.js} +1 -1
- package/dist/{chunk-WS4WAZVR.js → chunk-F5JZMK74.js} +1 -1
- package/dist/{chunk-TGDMOLZU.js → chunk-TW2FAMAJ.js} +2 -18
- package/dist/{chunk-FJT23P7T.js → chunk-WORT4PG7.js} +1 -1
- package/dist/{contract-types-ByIFoLrY.d.cts → contract-types-Dsvy79r3.d.cts} +18 -15
- package/dist/{contract-types-ByIFoLrY.d.ts → contract-types-Dsvy79r3.d.ts} +18 -15
- package/dist/env.d.cts +8 -1
- package/dist/env.d.ts +8 -1
- package/dist/{error-codes-BUx92qYi.d.ts → error-codes-OvQlqiQw.d.ts} +13 -15
- package/dist/{error-codes-DCiilt_8.d.cts → error-codes-SA5fGtx_.d.cts} +13 -15
- package/dist/index.cjs +3 -21
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -8
- 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/kill-chain.js +2 -2
- package/dist/node-executor.js +2 -2
- package/dist/port-contract.d.cts +11 -10
- package/dist/port-contract.d.ts +11 -10
- package/dist/protocol/index.cjs +3 -21
- package/dist/protocol/index.d.cts +19 -95
- package/dist/protocol/index.d.ts +19 -95
- package/dist/protocol/index.js +2 -6
- package/package.json +1 -1
- package/src/env.ts +8 -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 +22 -19
- package/src/protocol/engine-protocol.ts +9 -8
- package/src/protocol/error-codes.ts +12 -13
- 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,10 +1,14 @@
|
|
|
1
1
|
// src/protocol/reverse-channels.ts
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// 6 反向通道(引擎 → core,帧④,必须应答)载荷与超时二分。设计权威源:
|
|
4
4
|
// 设计 §3.3 方法集表 host/* 行 + impl-plan §2.1「8 反向通道」与「反向请求超时二分」。
|
|
5
5
|
// [H1] chat 域 v1.x 增量曾新增的第 9 通道(轮次相位帧)已随 chat-run 统一退役
|
|
6
|
-
// (docs/
|
|
7
|
-
// 改由 run 应答(agent_settled resolve
|
|
6
|
+
// (docs/architecture/subagent-chat-run-unification.md §3.3 D5,U5 删除)——轮次终态
|
|
7
|
+
// 改由 run 应答(agent_settled resolve)承载。
|
|
8
|
+
// [池抽象降级 2026-09-13] 原 host/poolResolved 通道(第 8 条)随 poolKey 协议面退役
|
|
9
|
+
// 一并删除(两引擎 poolKey 恒 'shared'、journal 落盘路径固定,回调零信息量)。
|
|
10
|
+
// [permission 通道退役 2026-09-13] host/permission 骨架删除(两引擎 permissionMode=
|
|
11
|
+
// native 零 emit、core 零注入——未接线死通道),通道集收敛为 6 个。
|
|
8
12
|
//
|
|
9
13
|
// 应答约定:数据面类回 {ok:true}(REVERSE_REQUEST_TIMEOUT_MS=10s 未答 = 引擎故障 →
|
|
10
14
|
// 杀进程 + 在途 run 失败);人机交互类走 ack 两阶段——先回 {ack:true},结果异步到达
|
|
@@ -15,14 +19,12 @@ import type { ReverseRequestTimeoutClass } from "./engine-protocol.ts";
|
|
|
15
19
|
import type { UiRequest, UiResponse } from "../ui-types.ts";
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
|
-
* 反向通道名联合(恰好
|
|
22
|
+
* 反向通道名联合(恰好 6 个;REVERSE_CHANNELS 常量数组与之同源互证)。
|
|
19
23
|
*/
|
|
20
24
|
export type ReverseChannel =
|
|
21
25
|
| "host/log"
|
|
22
26
|
| "host/askUser"
|
|
23
|
-
| "host/permission"
|
|
24
27
|
| "host/streamDelta"
|
|
25
|
-
| "host/poolResolved"
|
|
26
28
|
| "host/handleReady"
|
|
27
29
|
| "host/childSpawned"
|
|
28
30
|
| "host/childStateChanged";
|
|
@@ -33,9 +35,7 @@ export type ReverseChannel =
|
|
|
33
35
|
export const REVERSE_CHANNELS = [
|
|
34
36
|
"host/log",
|
|
35
37
|
"host/askUser",
|
|
36
|
-
"host/permission",
|
|
37
38
|
"host/streamDelta",
|
|
38
|
-
"host/poolResolved",
|
|
39
39
|
"host/handleReady",
|
|
40
40
|
"host/childSpawned",
|
|
41
41
|
"host/childStateChanged",
|
|
@@ -48,12 +48,10 @@ export const REVERSE_CHANNELS = [
|
|
|
48
48
|
export const REVERSE_CHANNEL_TIMEOUT_CLASS: Record<ReverseChannel, ReverseRequestTimeoutClass> = {
|
|
49
49
|
"host/log": "data-plane",
|
|
50
50
|
"host/streamDelta": "data-plane",
|
|
51
|
-
"host/poolResolved": "data-plane",
|
|
52
51
|
"host/handleReady": "data-plane",
|
|
53
52
|
"host/childSpawned": "data-plane",
|
|
54
53
|
"host/childStateChanged": "data-plane",
|
|
55
54
|
"host/askUser": "interaction",
|
|
56
|
-
"host/permission": "interaction",
|
|
57
55
|
};
|
|
58
56
|
|
|
59
57
|
// ============================================================
|
|
@@ -78,62 +76,25 @@ export interface HostAskUserParams {
|
|
|
78
76
|
/** host/askUser 的最终结果(ack 两阶段第二阶段,异步应答帧②的 result)。 */
|
|
79
77
|
export type HostAskUserResult = UiResponse;
|
|
80
78
|
|
|
81
|
-
/**
|
|
82
|
-
* host/permission:权限询问(引擎请求宿主裁决工具执行)。
|
|
83
|
-
* v1 骨架字段(设计未钉死载荷细节,细化归各引擎提取设计;W2 实装 core 应答端时
|
|
84
|
-
* 若需扩展走 additive 演进)。
|
|
85
|
-
*/
|
|
86
|
-
export interface HostPermissionParams {
|
|
87
|
-
runId: string;
|
|
88
|
-
toolName: string;
|
|
89
|
-
args?: unknown;
|
|
90
|
-
/** 请求方向引擎给出的原因/说明(展示用)。 */
|
|
91
|
-
reason?: string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** host/permission 两阶段结果。 */
|
|
95
|
-
export type HostPermissionResult = { approved: boolean } | { unsupported: true };
|
|
96
|
-
|
|
97
79
|
/**
|
|
98
80
|
* host/streamDelta:UI 实时通道(双通道之一;与 event 通知并行的渲染加速面)。
|
|
99
81
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* v1.x 旧引擎的兼容载荷形态(存量兼容读,现行引擎不写)。
|
|
103
|
-
* 两键互斥(undefined 孪生位防双填),消费侧经 isHostStreamDeltaParams 收窄。
|
|
82
|
+
* 关联键恒为 runId(runId 由 core 在 run 帧分配);[H1] chat 续聊轮经 resume run
|
|
83
|
+
* 复用 runId 关联(原 recordId 关联键随 interact 面退役删除)。
|
|
104
84
|
*/
|
|
105
|
-
export
|
|
106
|
-
| { runId: string; recordId?: undefined; delta: string }
|
|
107
|
-
| { recordId: string; runId?: undefined; delta: string };
|
|
108
|
-
|
|
109
|
-
/** streamDelta 载荷结构判定(关联键互斥 + delta 形状;消费侧共用,防双侧各写一份)。 */
|
|
110
|
-
export function isHostStreamDeltaParams(value: unknown): value is HostStreamDeltaParams {
|
|
111
|
-
if (typeof value !== "object" || value === null) return false;
|
|
112
|
-
const v = value as Record<string, unknown>;
|
|
113
|
-
const hasRunId = typeof v.runId === "string";
|
|
114
|
-
const hasRecordId = typeof v.recordId === "string";
|
|
115
|
-
// 恰一键:无键 / 双键 / 键非 string 都拒
|
|
116
|
-
if (hasRunId === hasRecordId) return false;
|
|
117
|
-
return typeof v.delta === "string";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* host/poolResolved:journal 落盘路径单一权威(契约:必须在首个事件 emit 前调用——
|
|
122
|
-
* 否则 journal 归属错)。载荷 = core onPoolResolved(poolKey) 的 runId 关联形态。
|
|
123
|
-
*/
|
|
124
|
-
export interface HostPoolResolvedParams {
|
|
85
|
+
export interface HostStreamDeltaParams {
|
|
125
86
|
runId: string;
|
|
126
|
-
|
|
87
|
+
delta: string;
|
|
127
88
|
}
|
|
128
89
|
|
|
129
90
|
/**
|
|
130
91
|
* host/handleReady:运行中句柄回填(core onHandleReady 语义:session/create 应答后、
|
|
131
92
|
* 早于 run resolve;AGENTS.md 关键规则 9「重开 session 仍可见」的前提)。
|
|
93
|
+
* [池抽象降级 2026-09-13] 原 poolKey 字段已随协议面 poolKey 退役删除。
|
|
132
94
|
*/
|
|
133
95
|
export interface HostHandleReadyParams {
|
|
134
96
|
runId: string;
|
|
135
97
|
sessionRef: Record<string, string>;
|
|
136
|
-
poolKey: string;
|
|
137
98
|
}
|
|
138
99
|
|
|
139
100
|
/**
|
|
@@ -160,27 +121,3 @@ export interface HostChildStateChangedParams {
|
|
|
160
121
|
exitCode?: number;
|
|
161
122
|
signal?: string;
|
|
162
123
|
}
|
|
163
|
-
|
|
164
|
-
/** 通道 → 载荷类型映射。 */
|
|
165
|
-
export interface ReverseChannelParamsMap {
|
|
166
|
-
"host/log": HostLogParams;
|
|
167
|
-
"host/askUser": HostAskUserParams;
|
|
168
|
-
"host/permission": HostPermissionParams;
|
|
169
|
-
"host/streamDelta": HostStreamDeltaParams;
|
|
170
|
-
"host/poolResolved": HostPoolResolvedParams;
|
|
171
|
-
"host/handleReady": HostHandleReadyParams;
|
|
172
|
-
"host/childSpawned": HostChildSpawnedParams;
|
|
173
|
-
"host/childStateChanged": HostChildStateChangedParams;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** 通道 → 异步/同步结果类型映射(ack 两阶段通道的第二阶段 result)。 */
|
|
177
|
-
export interface ReverseChannelResultMap {
|
|
178
|
-
"host/log": { ok: true };
|
|
179
|
-
"host/askUser": HostAskUserResult;
|
|
180
|
-
"host/permission": HostPermissionResult;
|
|
181
|
-
"host/streamDelta": { ok: true };
|
|
182
|
-
"host/poolResolved": { ok: true };
|
|
183
|
-
"host/handleReady": { ok: true };
|
|
184
|
-
"host/childSpawned": { ok: true };
|
|
185
|
-
"host/childStateChanged": { ok: true };
|
|
186
|
-
}
|
package/src/protocol/schema.ts
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
// 帧校验的目的是行解析器快速拒格式坏帧,不做深校验(深校验成本高于收益,坏载荷
|
|
13
13
|
// 由消费方结构化报错)。
|
|
14
14
|
|
|
15
|
-
import type { ReverseChannel } from "./reverse-channels.ts";
|
|
16
15
|
import { REVERSE_CHANNELS } from "./reverse-channels.ts";
|
|
17
16
|
import { PROTOCOL_METHODS } from "./methods.ts";
|
|
18
17
|
|
|
@@ -151,16 +150,13 @@ export const FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS = [
|
|
|
151
150
|
"secret",
|
|
152
151
|
] as const;
|
|
153
152
|
|
|
154
|
-
/** 反向通道名词表导出(schema enum 与 W2 路由同源)。 */
|
|
155
|
-
export const REVERSE_CHANNEL_NAMES: readonly ReverseChannel[] = REVERSE_CHANNELS;
|
|
156
|
-
|
|
157
153
|
// ============================================================
|
|
158
154
|
// [H1] run 会话形态参数载荷 schema(resume 单键校验权威)
|
|
159
155
|
// ============================================================
|
|
160
156
|
|
|
161
157
|
/**
|
|
162
158
|
* run.params 的会话形态参数载荷 schema(draft-07 深载荷片段)。设计权威源:
|
|
163
|
-
* docs/
|
|
159
|
+
* docs/architecture/subagent-chat-run-unification.md §3.3 D3 + §5 U1/U6 行。
|
|
164
160
|
*
|
|
165
161
|
* [H1 U6 已切换] 键切换单批完成后本 schema 面向唯一键 `resume`(RunResumeParams:
|
|
166
162
|
* recordId + 可选 ResumeAnchor),形状不变。帧级 schema(requestFrameSchema.params)
|
|
@@ -178,11 +174,10 @@ export const runSessionParamsSchema = {
|
|
|
178
174
|
resume: {
|
|
179
175
|
type: "object",
|
|
180
176
|
additionalProperties: false,
|
|
181
|
-
required: ["sessionRef"
|
|
177
|
+
required: ["sessionRef"],
|
|
182
178
|
properties: {
|
|
183
179
|
// ResumeAnchor.sessionRef = Record<string, string>(引擎定位键值对)
|
|
184
180
|
sessionRef: { type: "object", additionalProperties: { type: "string" } },
|
|
185
|
-
poolKey: { type: "string" },
|
|
186
181
|
journalPath: { type: "string" },
|
|
187
182
|
},
|
|
188
183
|
},
|