@zhushanwen/subagent-engine-sdk 0.9.0 → 0.10.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.
Files changed (43) hide show
  1. package/dist/{chunk-EF2F5YOM.js → chunk-CNCFMPEH.js} +1 -1
  2. package/dist/{chunk-6QE3OODO.js → chunk-HSNDUHFH.js} +1 -1
  3. package/dist/{chunk-VDKR7MLG.js → chunk-JZN76I3S.js} +31 -1
  4. package/dist/{chunk-DIIYVO4O.js → chunk-LM7P7OTA.js} +2 -1
  5. package/dist/{chunk-KADRNFG2.js → chunk-NTOLHLCL.js} +1 -1
  6. package/dist/{chunk-CT3FEBDO.js → chunk-QOFFM5YW.js} +7 -1
  7. package/dist/{contract-types-DqOD58r-.d.cts → contract-types-jSa1g28F.d.cts} +37 -2
  8. package/dist/{contract-types-DqOD58r-.d.ts → contract-types-jSa1g28F.d.ts} +37 -2
  9. package/dist/error-codes-DnFru4L4.d.ts +150 -0
  10. package/dist/error-codes-f-UO4a8D.d.cts +150 -0
  11. package/dist/index.cjs +45 -2
  12. package/dist/index.d.cts +5 -4
  13. package/dist/index.d.ts +5 -4
  14. package/dist/index.js +19 -7
  15. package/dist/journal-io.d.cts +1 -1
  16. package/dist/journal-io.d.ts +1 -1
  17. package/dist/journal-replay.d.cts +1 -1
  18. package/dist/journal-replay.d.ts +1 -1
  19. package/dist/kill-chain.cjs +26 -0
  20. package/dist/kill-chain.d.cts +1 -1
  21. package/dist/kill-chain.d.ts +1 -1
  22. package/dist/kill-chain.js +2 -2
  23. package/dist/{error-codes-CiDwaODz.d.ts → methods-BLxg4ZFr.d.cts} +46 -120
  24. package/dist/{error-codes-C3oVToMr.d.cts → methods-C2zvZqhP.d.ts} +46 -120
  25. package/dist/node-executor.cjs +26 -0
  26. package/dist/node-executor.js +2 -2
  27. package/dist/port-contract.d.cts +11 -1
  28. package/dist/port-contract.d.ts +11 -1
  29. package/dist/protocol/index.cjs +38 -2
  30. package/dist/protocol/index.d.cts +20 -5
  31. package/dist/protocol/index.d.ts +20 -5
  32. package/dist/protocol/index.js +12 -2
  33. package/dist/server/index.cjs +26 -0
  34. package/dist/server/index.d.cts +4 -3
  35. package/dist/server/index.d.ts +4 -3
  36. package/dist/server/index.js +1 -1
  37. package/dist/spawn.cjs +28 -0
  38. package/dist/spawn.js +3 -3
  39. package/dist/zcode-db-paths.cjs +9 -2
  40. package/dist/zcode-db-paths.d.cts +11 -1
  41. package/dist/zcode-db-paths.d.ts +11 -1
  42. package/dist/zcode-db-paths.js +5 -3
  43. package/package.json +1 -1
@@ -1,76 +1,15 @@
1
- import { A as AgentEvent, d as EngineCapabilities, M as ModelCatalogEntry, b as AgentCallOpts, e as ResumeAnchor, E as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from './contract-types-DqOD58r-.cjs';
2
-
3
- /** 协议错误对象(error 帧载荷与反向请求错误应答共用形态)。 */
4
- interface ProtocolError {
5
- /** 错误码(error-codes.ts 词表 + 其余 engine_* 引擎自报透传)。 */
6
- code: string;
7
- /** 人类可读详情。 */
8
- message: string;
9
- /** 恢复指引:指向具体下一步(命令 / 配置路径 / 升级动作),非安慰性文案。 */
10
- recovery: string;
11
- /** 结构化附参(如 engine_protocol_mismatch 的双方版本)。 */
12
- data?: Record<string, unknown>;
13
- }
14
- interface RequestFrame {
15
- id: number;
16
- method: string;
17
- params: unknown;
18
- }
19
- interface SuccessResponseFrame {
20
- id: number | string;
21
- result: unknown;
22
- }
23
- interface ErrorResponseFrame {
24
- id: number | string;
25
- error: ProtocolError;
26
- }
27
- type ResponseFrame = SuccessResponseFrame | ErrorResponseFrame;
28
- /** event 通知载荷:runId 关联在途 run;seq 单调递增(基线①结构等价断言对象)。 */
29
- interface EventNotificationParams {
30
- runId: string;
31
- seq: number;
32
- event: AgentEvent;
33
- }
34
- interface NotificationFrame {
35
- method: "event";
36
- params: EventNotificationParams;
37
- }
38
- interface ReverseRequestFrame {
39
- id: string;
40
- method: string;
41
- params: unknown;
42
- }
43
- /** 反向请求的应答(core → 引擎,沿 ResponseFrame 通道回传;id = 反向请求 id 原样)。 */
44
- type ReverseResponseResult =
45
- /** 数据面类:处理确认。 */
46
- {
47
- ok: true;
48
- }
49
- /** 人机交互类(askUser)两阶段第一阶段:已受理,结果异步到达(R9-2)。 */
50
- | {
51
- ack: true;
52
- }
53
- /** 未实现或宿主未知的通道(宽容语义③:由 askUser 语境泛化到全通道——宿主对未知 host/* 通道回 unsupported,引擎自行降级)。 */
54
- | {
55
- unsupported: true;
56
- };
57
- /** ① 请求:有数字 id + method + params,且无 result/error(与②应答区分)。 */
58
- declare function isRequestFrame(frame: unknown): frame is RequestFrame;
59
- /** ② 应答:有 id(number|string)且 result/error 二选一。 */
60
- declare function isResponseFrame(frame: unknown): frame is ResponseFrame;
61
- /** ③ 通知:无 id,method === "event",params 含 runId/seq/event。 */
62
- declare function isNotificationFrame(frame: unknown): frame is NotificationFrame;
63
- /** ④ 反向请求:有字符串 id + host/* method + params(与①的区别 = id 形态与 method 前缀)。 */
64
- declare function isReverseRequestFrame(frame: unknown): frame is ReverseRequestFrame;
1
+ import { M as ModelRef, d as EngineCapabilities, f as ModelCatalogEntry, b as AgentCallOpts, e as ResumeAnchor, E as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from './contract-types-jSa1g28F.js';
65
2
 
66
3
  /**
67
- * 正向方法名联合(恰好 9 个;PROTOCOL_METHODS 常量数组与之同源互证)。
4
+ * 正向方法名联合(恰好 10 个;PROTOCOL_METHODS 常量数组与之同源互证)。
68
5
  * [H1] `interact` 成员已随 chat-run 统一退役(docs/architecture/subagent-chat-run-unification.md
69
6
  * §3.3 D5:续聊轮统一为「新 run + resume 锚点」,U5 删除)。
7
+ * [subagent-model-switch] `setModel` 为执行中模型热切换方法(capabilities.setModel
8
+ * 位门控;消费点 = 宿主发送前预检,位不支持不发调用)。
70
9
  */
71
- type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
10
+ type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "read" | "listModels" | "validateModel" | "dispose" | "ping" | "setModel";
72
11
  /** 方法名全集(运行时顺序化枚举;与 ProtocolMethod 的同源关系由测试断言)。 */
73
- declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
12
+ declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping", "setModel"];
74
13
  /**
75
14
  * run 上下文(RunContext 字段映射的协议承载,设计 §3.3 RunContext 映射表)。
76
15
  */
@@ -231,6 +170,43 @@ interface PingParams {
231
170
  interface PingResult {
232
171
  pong: true;
233
172
  }
173
+ /**
174
+ * [subagent-model-switch §7.3] setModel 参数——RunParams 同级的 run 定向方法
175
+ * (params 以 runId 寻址活跃子进程,对照 cancel)。
176
+ *
177
+ * 语义(引擎侧实装义务,权威 = 设计 §7.3):定位活跃子进程 → 转发 pi 原生
178
+ * `set_model` → 读应答 → get_state 回读生效值 → 应答。请求 model 是**目标意图**
179
+ * (pi 部分模型族会静默替换成同族模型),生效值以应答 effectiveModel 为准。
180
+ * 失败经 error 帧,分型值域 = SET_MODEL_ERROR_CODES 三型
181
+ * (engine_model_not_in_snapshot / engine_credential_missing / engine_state_readback_failed);
182
+ * 目标 run 无活跃子进程(定位时 / 命令写入 / 读应答 / 回读四个竞态窗口内退出——
183
+ * 同一处置)按「无活进程」形态应答 = error 帧 `SET_MODEL_NOT_ACTIVE_CODE`
184
+ * (engine_run_not_active,宿主转纯记账路径,§7.5 子进程已退出行)。
185
+ *
186
+ * 无 thinkingLevel 参数(D5 裁决 M1-1):热切档位由 pi set_model 按新模型档位表
187
+ * 联动重设管辖(生效值以应答 effectiveThinkingLevel 为准);用户显式档位经覆盖
188
+ * 记账在下一轮 spawn 由解析链裁决(§6.2 跨轮档位以解析链为准)。未来引擎真支持
189
+ * 档位热切时走 additive 演进(新增可选参数)。
190
+ *
191
+ * 消费链:U2 宿主编排经 EnginePort 调用(capabilities.setModel='native' 预检通过后);
192
+ * U3 pi 引擎实装;U5 run 级聚合逐成员转发复用同一方法。
193
+ */
194
+ interface SetModelParams {
195
+ /** 目标 run 的 id(RunParams.runId 同源——引擎以它定位活跃子进程)。 */
196
+ runId: string;
197
+ /** 目标模型 ref(provider + modelId;宿主编排层负责与 canonical ref 目录互校)。 */
198
+ model: ModelRef;
199
+ }
200
+ /**
201
+ * [subagent-model-switch §7.3] setModel 应答——**回读生效值**(get_state 同源读回,
202
+ * 非命令应答转述;同族替换时 effectiveModel ≠ 请求 model)。
203
+ */
204
+ interface SetModelResult {
205
+ /** 生效模型 ref(pi 子进程活状态读回)。 */
206
+ effectiveModel: ModelRef;
207
+ /** 生效 thinking 档位(pi set_model 联动重设后的实际档位)。 */
208
+ effectiveThinkingLevel: string;
209
+ }
234
210
  /** 方法 → params 类型映射。 */
235
211
  interface ProtocolParamsMap {
236
212
  initialize: InitializeParams;
@@ -242,6 +218,7 @@ interface ProtocolParamsMap {
242
218
  validateModel: ValidateModelParams;
243
219
  dispose: DisposeParams;
244
220
  ping: PingParams;
221
+ setModel: SetModelParams;
245
222
  }
246
223
  /** 方法 → result 类型映射。 */
247
224
  interface ProtocolResultMap {
@@ -254,58 +231,7 @@ interface ProtocolResultMap {
254
231
  validateModel: ValidateModelResult;
255
232
  dispose: DisposeResult;
256
233
  ping: PingResult;
234
+ setModel: SetModelResult;
257
235
  }
258
236
 
259
- /** 协议核心错误码(引擎 error 帧 + core 同步拦截共用的固定词表)。 */
260
- declare const ENGINE_PROTOCOL_ERROR_CODES: readonly ["engine_not_found", "engine_protocol_mismatch", "engine_capability_unsupported", "engine_capability_mismatch", "engine_model_unknown", "engine_model_mismatch", "engine_handshake_timeout", "engine_crashed", "engine_probe_failed"];
261
- type EngineProtocolErrorCode = (typeof ENGINE_PROTOCOL_ERROR_CODES)[number];
262
- /** unknown → 协议错误码收窄(外部输入携带错误码时的运行时 guard;其余 engine_* 走透传)。 */
263
- declare function isEngineProtocolErrorCode(value: unknown): value is EngineProtocolErrorCode;
264
- /** 其余引擎自报错误码的前缀契约(透传面;core 不解释文案)。 */
265
- declare const ENGINE_ERROR_CODE_PREFIX = "engine_";
266
- declare function isEngineErrorPassthroughCode(value: string): boolean;
267
-
268
- /**
269
- * 结构化引擎错误(message 恒为 `<code>: <detail>` 前缀格式——AgentOutcome.error 与
270
- * 协议 error 帧共用的错误码前缀约定);recovery 指向恢复动作。
271
- * toStructured() 产出即协议 ProtocolError 形态(error 帧载荷直用)。
272
- */
273
- declare class EngineSdkError extends Error {
274
- readonly code: string;
275
- readonly recovery: string;
276
- readonly data?: Record<string, unknown>;
277
- constructor(code: string, detail: string, recovery: string, data?: Record<string, unknown>);
278
- /** 协议 error 帧载荷投影。 */
279
- toStructured(): ProtocolError;
280
- }
281
- declare function engineProtocolMismatchError(engineVersion: number): EngineSdkError;
282
- /**
283
- * 引擎 conversation 位拒绝的具名错误([modeless 波2] 语义:无 resume 续聊通道的
284
- * 引擎,message 续聊资格被拒——manifest conversation 能力轴消费;[modeless 波5
285
- * 收尾] core capability-gate 的显式参数分支随派发参数删除退役,本构造器消费方 =
286
- * 引擎侧 resume gate(assertChatConversationSupported)与 message 资格门)。
287
- * 文案契约:错误码 engine_capability_unsupported + 「换引擎续聊 / 修 manifest /
288
- * 升级引擎包」恢复指引,两侧一致防漂移。
289
- */
290
- declare function engineConversationUnsupportedError(engineId: string): EngineSdkError;
291
- /**
292
- * resume 会话形态(run.params.resume——唯一会话形态键)派发前的同步 gate:
293
- * manifest conversation 位 unsupported 即抛 engineConversationUnsupportedError
294
- * ——进程/record 创建前同步拒(A6 方向防御:manifest/实装漂移时引擎侧自拒,
295
- * 与 core capability-gate 同一能力位,防两侧判据漂移)。[modeless 波2] 协议
296
- * task 的 conversation 键已删,本 gate 只对 resume 形态键生效。
297
- */
298
- declare function assertChatConversationSupported(engineId: string, capabilities: Pick<EngineCapabilities, "conversation">): void;
299
- /** stdout 尾部回显上限(engine_timeout / engine_run_failed 的错误规格载体系数)。 */
300
- declare const STDOUT_TAIL_ECHO_CHARS = 2000;
301
- /** engine_timeout 的恢复指引(kill-chain 超时杀链收尾文案)。 */
302
- declare const ENGINE_TIMEOUT_RECOVERY: string;
303
- /**
304
- * engine_timeout 的 outcome.error 文案:含 stdout 尾部 2000 字 + 恢复指引
305
- * (kill-chain synthesizeTimeoutOutcome 消费;与 core errors.ts engineTimeoutDetail 逐字等价)。
306
- */
307
- declare function engineTimeoutDetail(stdoutTail: string): string;
308
- /** schema_emulation_failed 的终报文案(宿主编排层「重试一次仍失败」后消费)。 */
309
- declare function schemaEmulationFailedDetail(error: string, tail: string): string;
310
-
311
- export { type ValidateModelResult as A, assertChatConversationSupported as B, type CancelParams as C, type DisposeParams as D, EngineSdkError as E, engineConversationUnsupportedError as F, engineProtocolMismatchError as G, engineTimeoutDetail as H, type InitializeResult as I, isEngineErrorPassthroughCode as J, isEngineProtocolErrorCode as K, type ListModelsParams as L, isNotificationFrame as M, type NotificationFrame as N, isRequestFrame as O, PROTOCOL_METHODS as P, isResponseFrame as Q, type RunContextParams as R, STDOUT_TAIL_ECHO_CHARS as S, isReverseRequestFrame as T, schemaEmulationFailedDetail as U, type ValidateModelParams as V, type InitializeParams as a, type CancelResult as b, type DisposeResult as c, ENGINE_ERROR_CODE_PREFIX as d, ENGINE_PROTOCOL_ERROR_CODES as e, ENGINE_TIMEOUT_RECOVERY as f, type EngineProtocolErrorCode as g, type ErrorResponseFrame as h, type EventNotificationParams as i, type ListModelsResult as j, type PingParams as k, type PingResult as l, type ProbeParams as m, type ProtocolError as n, type ProtocolMethod as o, type ProtocolParamsMap as p, type ProtocolResultMap as q, type ReadParams as r, type RequestFrame as s, type ResponseFrame as t, type ReverseRequestFrame as u, type ReverseResponseResult as v, type RunParams as w, type RunResult as x, type RunResumeParams as y, type SuccessResponseFrame as z };
237
+ export { type CancelParams as C, type DisposeParams as D, type InitializeResult as I, type ListModelsParams as L, PROTOCOL_METHODS as P, type RunContextParams as R, type SetModelParams as S, type ValidateModelParams as V, type SetModelResult as a, type InitializeParams as b, type CancelResult as c, type DisposeResult as d, type ListModelsResult as e, type PingParams as f, type PingResult as g, type ProbeParams as h, type ProtocolMethod as i, type ProtocolParamsMap as j, type ProtocolResultMap as k, type ReadParams as l, type RunParams as m, type RunResult as n, type RunResumeParams as o, type ValidateModelResult as p };
@@ -30,6 +30,32 @@ module.exports = __toCommonJS(node_executor_exports);
30
30
  var import_node_child_process = require("child_process");
31
31
 
32
32
  // src/protocol/error-codes.ts
33
+ var SET_MODEL_ERROR_CODES = [
34
+ /** 目标模型不在当前进程快照(子进程模型快照冻结于 spawn 时刻——模型本身有效,
35
+ * 下一轮 spawn 现取目录即可用;宿主按「写覆盖意图」处置,设计 §7.2 快照型失败行)。 */
36
+ "engine_model_not_in_snapshot",
37
+ /** 凭据校验失败(子进程 set_model checkAuth 抛错——宿主预检通过后 registry 态漂移
38
+ * 的权威兜底;宿主按校验型失败处置,设计 §7.5 凭据行)。 */
39
+ "engine_credential_missing",
40
+ /** 命令已发出(set_model 可能已执行)但读应答 / get_state 回读无回执、生效值未知
41
+ * (非进程退出情形——退出归无活进程路径;宿主按「写覆盖意图 + 错误应答」处置,
42
+ * 设计 §7.5 回读失败行)。 */
43
+ "engine_state_readback_failed"
44
+ ];
45
+ var SET_MODEL_NOT_ACTIVE_CODE = "engine_run_not_active";
46
+ var ENGINE_PROTOCOL_ERROR_CODES = [
47
+ "engine_not_found",
48
+ "engine_protocol_mismatch",
49
+ "engine_capability_unsupported",
50
+ "engine_capability_mismatch",
51
+ "engine_model_unknown",
52
+ "engine_model_mismatch",
53
+ "engine_handshake_timeout",
54
+ "engine_crashed",
55
+ "engine_probe_failed",
56
+ ...SET_MODEL_ERROR_CODES,
57
+ SET_MODEL_NOT_ACTIVE_CODE
58
+ ];
33
59
  var EngineSdkError = class extends Error {
34
60
  code;
35
61
  recovery;
@@ -4,8 +4,8 @@ import {
4
4
  probeNodeExecutor,
5
5
  resetEngineNodeProbeCache,
6
6
  resolveEngineNodeLaunch
7
- } from "./chunk-KADRNFG2.js";
8
- import "./chunk-VDKR7MLG.js";
7
+ } from "./chunk-NTOLHLCL.js";
8
+ import "./chunk-JZN76I3S.js";
9
9
  import "./chunk-JSBRDJBE.js";
10
10
  export {
11
11
  ENGINE_NODE_ENV,
@@ -1,4 +1,5 @@
1
- import { b as AgentCallOpts, E as EngineHandleData, d as EngineCapabilities, P as ProbeReport, A as AgentEvent, e as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-DqOD58r-.cjs';
1
+ import { b as AgentCallOpts, E as EngineHandleData, d as EngineCapabilities, P as ProbeReport, A as AgentEvent, e as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-jSa1g28F.cjs';
2
+ import { S as SetModelParams, a as SetModelResult } from './methods-BLxg4ZFr.cjs';
2
3
 
3
4
  /**
4
5
  * 引擎进程内全量任务声明 = SDK AgentCallOpts 引擎面子集 + 协议 ctx 还原字段(model/
@@ -125,6 +126,15 @@ interface EnginePort {
125
126
  validateModel?(modelRef: string | undefined): {
126
127
  canonicalRef: string;
127
128
  };
129
+ /**
130
+ * [subagent-model-switch §7.3] 可选面:执行中模型热切换(协议 setModel 正向方法的
131
+ * 进程内承载)。实现引擎须 capabilities.setModel = 'native' 同批声明(位与方法
132
+ * 成对进出——capabilities 注释的消费点登记);server 分发行在位非 native 时回
133
+ * engineSetModelUnsupportedError 结构化错误(契约行为 = 明确错误而非崩)。
134
+ * 实现语义 = 定位活跃子进程 → 命令写入 → 读应答 → 状态回读 → 应答生效值
135
+ * (SetModelResult),竞态窗口处置见设计 §7.3。
136
+ */
137
+ setModel?(params: SetModelParams): Promise<SetModelResult>;
128
138
  dispose?(): Promise<void>;
129
139
  }
130
140
  /** ctx.ctxModel("provider/id" canonical 词形)→ EngineCtxModel。 */
@@ -1,4 +1,5 @@
1
- import { b as AgentCallOpts, E as EngineHandleData, d as EngineCapabilities, P as ProbeReport, A as AgentEvent, e as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-DqOD58r-.js';
1
+ import { b as AgentCallOpts, E as EngineHandleData, d as EngineCapabilities, P as ProbeReport, A as AgentEvent, e as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-jSa1g28F.js';
2
+ import { S as SetModelParams, a as SetModelResult } from './methods-C2zvZqhP.js';
2
3
 
3
4
  /**
4
5
  * 引擎进程内全量任务声明 = SDK AgentCallOpts 引擎面子集 + 协议 ctx 还原字段(model/
@@ -125,6 +126,15 @@ interface EnginePort {
125
126
  validateModel?(modelRef: string | undefined): {
126
127
  canonicalRef: string;
127
128
  };
129
+ /**
130
+ * [subagent-model-switch §7.3] 可选面:执行中模型热切换(协议 setModel 正向方法的
131
+ * 进程内承载)。实现引擎须 capabilities.setModel = 'native' 同批声明(位与方法
132
+ * 成对进出——capabilities 注释的消费点登记);server 分发行在位非 native 时回
133
+ * engineSetModelUnsupportedError 结构化错误(契约行为 = 明确错误而非崩)。
134
+ * 实现语义 = 定位活跃子进程 → 命令写入 → 读应答 → 状态回读 → 应答生效值
135
+ * (SetModelResult),竞态窗口处置见设计 §7.3。
136
+ */
137
+ setModel?(params: SetModelParams): Promise<SetModelResult>;
128
138
  dispose?(): Promise<void>;
129
139
  }
130
140
  /** ctx.ctxModel("provider/id" canonical 词形)→ EngineCtxModel。 */
@@ -34,12 +34,17 @@ __export(protocol_exports, {
34
34
  REVERSE_CHANNELS: () => REVERSE_CHANNELS,
35
35
  REVERSE_CHANNEL_TIMEOUT_CLASS: () => REVERSE_CHANNEL_TIMEOUT_CLASS,
36
36
  REVERSE_REQUEST_TIMEOUT_MS: () => REVERSE_REQUEST_TIMEOUT_MS,
37
+ SET_MODEL_ERROR_CODES: () => SET_MODEL_ERROR_CODES,
38
+ SET_MODEL_NOT_ACTIVE_CODE: () => SET_MODEL_NOT_ACTIVE_CODE,
39
+ SET_MODEL_REQUEST_TIMEOUT_MS: () => SET_MODEL_REQUEST_TIMEOUT_MS,
40
+ SET_MODEL_STAGE_TIMEOUT_MS: () => SET_MODEL_STAGE_TIMEOUT_MS,
37
41
  STDERR_TAIL_CHARS: () => STDERR_TAIL_CHARS,
38
42
  STDOUT_TAIL_ECHO_CHARS: () => STDOUT_TAIL_ECHO_CHARS,
39
43
  SUPPORTED_PROTOCOL_RANGE: () => SUPPORTED_PROTOCOL_RANGE,
40
44
  assertChatConversationSupported: () => assertChatConversationSupported,
41
45
  engineConversationUnsupportedError: () => engineConversationUnsupportedError,
42
46
  engineProtocolMismatchError: () => engineProtocolMismatchError,
47
+ engineSetModelUnsupportedError: () => engineSetModelUnsupportedError,
43
48
  engineTimeoutDetail: () => engineTimeoutDetail,
44
49
  errorResponseFrameSchema: () => errorResponseFrameSchema,
45
50
  isEngineErrorPassthroughCode: () => isEngineErrorPassthroughCode,
@@ -68,6 +73,8 @@ function isProtocolVersionCompatible(version) {
68
73
  var REVERSE_REQUEST_TIMEOUT_MS = 1e4;
69
74
  var HANDSHAKE_TIMEOUT_MS = 1e4;
70
75
  var CANCEL_SETTLE_GRACE_MS = 3e3;
76
+ var SET_MODEL_STAGE_TIMEOUT_MS = 3e3;
77
+ var SET_MODEL_REQUEST_TIMEOUT_MS = 1e4;
71
78
  var STDERR_TAIL_CHARS = 400;
72
79
 
73
80
  // src/protocol/frames.ts
@@ -102,7 +109,8 @@ var PROTOCOL_METHODS = [
102
109
  "listModels",
103
110
  "validateModel",
104
111
  "dispose",
105
- "ping"
112
+ "ping",
113
+ "setModel"
106
114
  ];
107
115
 
108
116
  // src/protocol/reverse-channels.ts
@@ -124,6 +132,19 @@ var REVERSE_CHANNEL_TIMEOUT_CLASS = {
124
132
  };
125
133
 
126
134
  // src/protocol/error-codes.ts
135
+ var SET_MODEL_ERROR_CODES = [
136
+ /** 目标模型不在当前进程快照(子进程模型快照冻结于 spawn 时刻——模型本身有效,
137
+ * 下一轮 spawn 现取目录即可用;宿主按「写覆盖意图」处置,设计 §7.2 快照型失败行)。 */
138
+ "engine_model_not_in_snapshot",
139
+ /** 凭据校验失败(子进程 set_model checkAuth 抛错——宿主预检通过后 registry 态漂移
140
+ * 的权威兜底;宿主按校验型失败处置,设计 §7.5 凭据行)。 */
141
+ "engine_credential_missing",
142
+ /** 命令已发出(set_model 可能已执行)但读应答 / get_state 回读无回执、生效值未知
143
+ * (非进程退出情形——退出归无活进程路径;宿主按「写覆盖意图 + 错误应答」处置,
144
+ * 设计 §7.5 回读失败行)。 */
145
+ "engine_state_readback_failed"
146
+ ];
147
+ var SET_MODEL_NOT_ACTIVE_CODE = "engine_run_not_active";
127
148
  var ENGINE_PROTOCOL_ERROR_CODES = [
128
149
  "engine_not_found",
129
150
  "engine_protocol_mismatch",
@@ -133,7 +154,9 @@ var ENGINE_PROTOCOL_ERROR_CODES = [
133
154
  "engine_model_mismatch",
134
155
  "engine_handshake_timeout",
135
156
  "engine_crashed",
136
- "engine_probe_failed"
157
+ "engine_probe_failed",
158
+ ...SET_MODEL_ERROR_CODES,
159
+ SET_MODEL_NOT_ACTIVE_CODE
137
160
  ];
138
161
  function isEngineProtocolErrorCode(value) {
139
162
  return typeof value === "string" && ENGINE_PROTOCOL_ERROR_CODES.includes(value);
@@ -183,6 +206,14 @@ function assertChatConversationSupported(engineId, capabilities) {
183
206
  throw engineConversationUnsupportedError(engineId);
184
207
  }
185
208
  }
209
+ function engineSetModelUnsupportedError(engineId, declared) {
210
+ return new EngineSdkError(
211
+ "engine_capability_unsupported",
212
+ `engine '${engineId}' does not support hot model switching (capabilities.setModel = ${declared ?? "unsupported (undeclared)"}); the host pre-check (design \xA77.2 step 2) must not dispatch setModel to it`,
213
+ `Route the switch to an engine that declares capabilities.setModel = 'native', or record the override for the next run instead. If this engine actually supports hot switching, fix the manifest capabilities declaration.`,
214
+ { engineId, capability: "setModel", declared: declared ?? "unsupported" }
215
+ );
216
+ }
186
217
  var DETAIL_ECHO_MAX_CHARS = 200;
187
218
  var STDOUT_TAIL_ECHO_CHARS = 2e3;
188
219
  function truncate(text, max) {
@@ -364,12 +395,17 @@ var runSessionParamsSchema = {
364
395
  REVERSE_CHANNELS,
365
396
  REVERSE_CHANNEL_TIMEOUT_CLASS,
366
397
  REVERSE_REQUEST_TIMEOUT_MS,
398
+ SET_MODEL_ERROR_CODES,
399
+ SET_MODEL_NOT_ACTIVE_CODE,
400
+ SET_MODEL_REQUEST_TIMEOUT_MS,
401
+ SET_MODEL_STAGE_TIMEOUT_MS,
367
402
  STDERR_TAIL_CHARS,
368
403
  STDOUT_TAIL_ECHO_CHARS,
369
404
  SUPPORTED_PROTOCOL_RANGE,
370
405
  assertChatConversationSupported,
371
406
  engineConversationUnsupportedError,
372
407
  engineProtocolMismatchError,
408
+ engineSetModelUnsupportedError,
373
409
  engineTimeoutDetail,
374
410
  errorResponseFrameSchema,
375
411
  isEngineErrorPassthroughCode,
@@ -1,6 +1,7 @@
1
- export { C as CancelParams, b as CancelResult, D as DisposeParams, c as DisposeResult, d as ENGINE_ERROR_CODE_PREFIX, e as ENGINE_PROTOCOL_ERROR_CODES, f as ENGINE_TIMEOUT_RECOVERY, g as EngineProtocolErrorCode, E as EngineSdkError, h as ErrorResponseFrame, i as EventNotificationParams, a as InitializeParams, I as InitializeResult, L as ListModelsParams, j as ListModelsResult, N as NotificationFrame, P as PROTOCOL_METHODS, k as PingParams, l as PingResult, m as ProbeParams, n as ProtocolError, o as ProtocolMethod, p as ProtocolParamsMap, q as ProtocolResultMap, r as ReadParams, s as RequestFrame, t as ResponseFrame, u as ReverseRequestFrame, v as ReverseResponseResult, R as RunContextParams, w as RunParams, x as RunResult, y as RunResumeParams, S as STDOUT_TAIL_ECHO_CHARS, z as SuccessResponseFrame, V as ValidateModelParams, A as ValidateModelResult, B as assertChatConversationSupported, F as engineConversationUnsupportedError, G as engineProtocolMismatchError, H as engineTimeoutDetail, J as isEngineErrorPassthroughCode, K as isEngineProtocolErrorCode, M as isNotificationFrame, O as isRequestFrame, Q as isResponseFrame, T as isReverseRequestFrame, U as schemaEmulationFailedDetail } from '../error-codes-C3oVToMr.cjs';
1
+ export { a as ENGINE_ERROR_CODE_PREFIX, b as ENGINE_PROTOCOL_ERROR_CODES, c as ENGINE_TIMEOUT_RECOVERY, d as EngineProtocolErrorCode, E 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 SET_MODEL_ERROR_CODES, j as SET_MODEL_NOT_ACTIVE_CODE, k as STDOUT_TAIL_ECHO_CHARS, l as SetModelErrorCode, m as SuccessResponseFrame, n as assertChatConversationSupported, o as engineConversationUnsupportedError, p as engineProtocolMismatchError, q as engineSetModelUnsupportedError, r as engineTimeoutDetail, s as isEngineErrorPassthroughCode, t as isEngineProtocolErrorCode, u as isNotificationFrame, v as isRequestFrame, w as isResponseFrame, x as isReverseRequestFrame, y as schemaEmulationFailedDetail } from '../error-codes-f-UO4a8D.cjs';
2
+ export { C as CancelParams, c as CancelResult, D as DisposeParams, d as DisposeResult, b as InitializeParams, I as InitializeResult, L as ListModelsParams, e as ListModelsResult, P as PROTOCOL_METHODS, f as PingParams, g as PingResult, h as ProbeParams, i as ProtocolMethod, j as ProtocolParamsMap, k as ProtocolResultMap, l as ReadParams, R as RunContextParams, m as RunParams, n as RunResult, o as RunResumeParams, S as SetModelParams, a as SetModelResult, V as ValidateModelParams, p as ValidateModelResult } from '../methods-BLxg4ZFr.cjs';
2
3
  import { UiRequest, UiResponse } from '../ui-types.cjs';
3
- export { f as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, g as AgentEventTypeName, h as AgentFailureKind, c as AgentOutcome, i as AgentOutcomeUsage, j as AgentUsage, a as AgentUsageTotal, k as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, l as EngineProcessModel, I as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, m as ToolCall, n as ToolCallEntry, o as ToolCallResult, T as Turn, W as WorktreeHandle } from '../contract-types-DqOD58r-.cjs';
4
+ export { g as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, h as AgentEventTypeName, i as AgentFailureKind, c as AgentOutcome, j as AgentOutcomeUsage, k as AgentUsage, a as AgentUsageTotal, l as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, I as InternalToolCall, f as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, n as ToolCall, o as ToolCallEntry, p as ToolCallResult, T as Turn, W as WorktreeHandle } from '../contract-types-jSa1g28F.cjs';
4
5
 
5
6
  /** 协议版本(引擎包 manifest `taiji.subagentEngine.protocol` 与 initialize 应答同值)。 */
6
7
  declare const ENGINE_PROTOCOL_VERSION = 1;
@@ -20,6 +21,20 @@ declare const REVERSE_REQUEST_TIMEOUT_MS = 10000;
20
21
  declare const HANDSHAKE_TIMEOUT_MS = 10000;
21
22
  /** cancel 后引擎收敛终态的窗口(ms);超时 core 走杀链。 */
22
23
  declare const CANCEL_SETTLE_GRACE_MS = 3000;
24
+ /**
25
+ * setModel 引擎侧单阶段控制窗(ms):pi 实现等子进程 `set_model` 应答、等
26
+ * `get_state` 回读各占一窗(设计 subagent-model-switch §7.3——命令与回读全程带
27
+ * 存活检查,超时上限复用现役取消收敛窗量级:控制面单请求 = 秒级)。窗满且进程
28
+ * 仍存活 → `engine_state_readback_failed`;窗满时进程已退出 → 无活进程形态
29
+ * (`SET_MODEL_NOT_ACTIVE_CODE`)——两种处置不可混淆。
30
+ */
31
+ declare const SET_MODEL_STAGE_TIMEOUT_MS = 3000;
32
+ /**
33
+ * setModel 正向方法的宿主侧单请求上界(ms):≥ 引擎侧两阶段最坏时延
34
+ * (2 × SET_MODEL_STAGE_TIMEOUT_MS)+ 协议余量;量级锚 = 数据面单请求
35
+ * REVERSE_REQUEST_TIMEOUT_MS 的 10s 先例(控制面单请求必须秒级有界——宿主不悬挂)。
36
+ */
37
+ declare const SET_MODEL_REQUEST_TIMEOUT_MS = 10000;
23
38
  /** stderr 内存环形缓冲保留的尾部字符数(engine_crashed 帧携带崩溃现场)。 */
24
39
  declare const STDERR_TAIL_CHARS = 400;
25
40
  /**
@@ -138,7 +153,7 @@ declare const requestFrameSchema: {
138
153
  };
139
154
  readonly method: {
140
155
  readonly type: "string";
141
- readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
156
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping", "setModel"];
142
157
  };
143
158
  readonly params: {};
144
159
  };
@@ -260,7 +275,7 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
260
275
  };
261
276
  readonly method: {
262
277
  readonly type: "string";
263
- readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
278
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping", "setModel"];
264
279
  };
265
280
  readonly params: {};
266
281
  };
@@ -431,4 +446,4 @@ declare const runSessionParamsSchema: {
431
446
  };
432
447
  };
433
448
 
434
- export { CANCEL_SETTLE_GRACE_MS, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type HostStreamDeltaParams, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, type ReverseChannel, type ReverseRequestTimeoutClass, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema };
449
+ export { CANCEL_SETTLE_GRACE_MS, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type HostStreamDeltaParams, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, type ReverseChannel, type ReverseRequestTimeoutClass, SET_MODEL_REQUEST_TIMEOUT_MS, SET_MODEL_STAGE_TIMEOUT_MS, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema };
@@ -1,6 +1,7 @@
1
- export { C as CancelParams, b as CancelResult, D as DisposeParams, c as DisposeResult, d as ENGINE_ERROR_CODE_PREFIX, e as ENGINE_PROTOCOL_ERROR_CODES, f as ENGINE_TIMEOUT_RECOVERY, g as EngineProtocolErrorCode, E as EngineSdkError, h as ErrorResponseFrame, i as EventNotificationParams, a as InitializeParams, I as InitializeResult, L as ListModelsParams, j as ListModelsResult, N as NotificationFrame, P as PROTOCOL_METHODS, k as PingParams, l as PingResult, m as ProbeParams, n as ProtocolError, o as ProtocolMethod, p as ProtocolParamsMap, q as ProtocolResultMap, r as ReadParams, s as RequestFrame, t as ResponseFrame, u as ReverseRequestFrame, v as ReverseResponseResult, R as RunContextParams, w as RunParams, x as RunResult, y as RunResumeParams, S as STDOUT_TAIL_ECHO_CHARS, z as SuccessResponseFrame, V as ValidateModelParams, A as ValidateModelResult, B as assertChatConversationSupported, F as engineConversationUnsupportedError, G as engineProtocolMismatchError, H as engineTimeoutDetail, J as isEngineErrorPassthroughCode, K as isEngineProtocolErrorCode, M as isNotificationFrame, O as isRequestFrame, Q as isResponseFrame, T as isReverseRequestFrame, U as schemaEmulationFailedDetail } from '../error-codes-CiDwaODz.js';
1
+ export { a as ENGINE_ERROR_CODE_PREFIX, b as ENGINE_PROTOCOL_ERROR_CODES, c as ENGINE_TIMEOUT_RECOVERY, d as EngineProtocolErrorCode, E 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 SET_MODEL_ERROR_CODES, j as SET_MODEL_NOT_ACTIVE_CODE, k as STDOUT_TAIL_ECHO_CHARS, l as SetModelErrorCode, m as SuccessResponseFrame, n as assertChatConversationSupported, o as engineConversationUnsupportedError, p as engineProtocolMismatchError, q as engineSetModelUnsupportedError, r as engineTimeoutDetail, s as isEngineErrorPassthroughCode, t as isEngineProtocolErrorCode, u as isNotificationFrame, v as isRequestFrame, w as isResponseFrame, x as isReverseRequestFrame, y as schemaEmulationFailedDetail } from '../error-codes-DnFru4L4.js';
2
+ export { C as CancelParams, c as CancelResult, D as DisposeParams, d as DisposeResult, b as InitializeParams, I as InitializeResult, L as ListModelsParams, e as ListModelsResult, P as PROTOCOL_METHODS, f as PingParams, g as PingResult, h as ProbeParams, i as ProtocolMethod, j as ProtocolParamsMap, k as ProtocolResultMap, l as ReadParams, R as RunContextParams, m as RunParams, n as RunResult, o as RunResumeParams, S as SetModelParams, a as SetModelResult, V as ValidateModelParams, p as ValidateModelResult } from '../methods-C2zvZqhP.js';
2
3
  import { UiRequest, UiResponse } from '../ui-types.js';
3
- export { f as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, g as AgentEventTypeName, h as AgentFailureKind, c as AgentOutcome, i as AgentOutcomeUsage, j as AgentUsage, a as AgentUsageTotal, k as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, l as EngineProcessModel, I as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, m as ToolCall, n as ToolCallEntry, o as ToolCallResult, T as Turn, W as WorktreeHandle } from '../contract-types-DqOD58r-.js';
4
+ export { g as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, h as AgentEventTypeName, i as AgentFailureKind, c as AgentOutcome, j as AgentOutcomeUsage, k as AgentUsage, a as AgentUsageTotal, l as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, I as InternalToolCall, f as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, n as ToolCall, o as ToolCallEntry, p as ToolCallResult, T as Turn, W as WorktreeHandle } from '../contract-types-jSa1g28F.js';
4
5
 
5
6
  /** 协议版本(引擎包 manifest `taiji.subagentEngine.protocol` 与 initialize 应答同值)。 */
6
7
  declare const ENGINE_PROTOCOL_VERSION = 1;
@@ -20,6 +21,20 @@ declare const REVERSE_REQUEST_TIMEOUT_MS = 10000;
20
21
  declare const HANDSHAKE_TIMEOUT_MS = 10000;
21
22
  /** cancel 后引擎收敛终态的窗口(ms);超时 core 走杀链。 */
22
23
  declare const CANCEL_SETTLE_GRACE_MS = 3000;
24
+ /**
25
+ * setModel 引擎侧单阶段控制窗(ms):pi 实现等子进程 `set_model` 应答、等
26
+ * `get_state` 回读各占一窗(设计 subagent-model-switch §7.3——命令与回读全程带
27
+ * 存活检查,超时上限复用现役取消收敛窗量级:控制面单请求 = 秒级)。窗满且进程
28
+ * 仍存活 → `engine_state_readback_failed`;窗满时进程已退出 → 无活进程形态
29
+ * (`SET_MODEL_NOT_ACTIVE_CODE`)——两种处置不可混淆。
30
+ */
31
+ declare const SET_MODEL_STAGE_TIMEOUT_MS = 3000;
32
+ /**
33
+ * setModel 正向方法的宿主侧单请求上界(ms):≥ 引擎侧两阶段最坏时延
34
+ * (2 × SET_MODEL_STAGE_TIMEOUT_MS)+ 协议余量;量级锚 = 数据面单请求
35
+ * REVERSE_REQUEST_TIMEOUT_MS 的 10s 先例(控制面单请求必须秒级有界——宿主不悬挂)。
36
+ */
37
+ declare const SET_MODEL_REQUEST_TIMEOUT_MS = 10000;
23
38
  /** stderr 内存环形缓冲保留的尾部字符数(engine_crashed 帧携带崩溃现场)。 */
24
39
  declare const STDERR_TAIL_CHARS = 400;
25
40
  /**
@@ -138,7 +153,7 @@ declare const requestFrameSchema: {
138
153
  };
139
154
  readonly method: {
140
155
  readonly type: "string";
141
- readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
156
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping", "setModel"];
142
157
  };
143
158
  readonly params: {};
144
159
  };
@@ -260,7 +275,7 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
260
275
  };
261
276
  readonly method: {
262
277
  readonly type: "string";
263
- readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
278
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping", "setModel"];
264
279
  };
265
280
  readonly params: {};
266
281
  };
@@ -431,4 +446,4 @@ declare const runSessionParamsSchema: {
431
446
  };
432
447
  };
433
448
 
434
- export { CANCEL_SETTLE_GRACE_MS, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type HostStreamDeltaParams, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, type ReverseChannel, type ReverseRequestTimeoutClass, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema };
449
+ export { CANCEL_SETTLE_GRACE_MS, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type HostStreamDeltaParams, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, type ReverseChannel, type ReverseRequestTimeoutClass, SET_MODEL_REQUEST_TIMEOUT_MS, SET_MODEL_STAGE_TIMEOUT_MS, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema };
@@ -12,7 +12,7 @@ import {
12
12
  reverseRequestFrameSchema,
13
13
  runSessionParamsSchema,
14
14
  successResponseFrameSchema
15
- } from "../chunk-DIIYVO4O.js";
15
+ } from "../chunk-LM7P7OTA.js";
16
16
  import {
17
17
  isNotificationFrame,
18
18
  isRequestFrame,
@@ -28,18 +28,23 @@ import {
28
28
  EngineSdkError,
29
29
  HANDSHAKE_TIMEOUT_MS,
30
30
  REVERSE_REQUEST_TIMEOUT_MS,
31
+ SET_MODEL_ERROR_CODES,
32
+ SET_MODEL_NOT_ACTIVE_CODE,
33
+ SET_MODEL_REQUEST_TIMEOUT_MS,
34
+ SET_MODEL_STAGE_TIMEOUT_MS,
31
35
  STDERR_TAIL_CHARS,
32
36
  STDOUT_TAIL_ECHO_CHARS,
33
37
  SUPPORTED_PROTOCOL_RANGE,
34
38
  assertChatConversationSupported,
35
39
  engineConversationUnsupportedError,
36
40
  engineProtocolMismatchError,
41
+ engineSetModelUnsupportedError,
37
42
  engineTimeoutDetail,
38
43
  isEngineErrorPassthroughCode,
39
44
  isEngineProtocolErrorCode,
40
45
  isProtocolVersionCompatible,
41
46
  schemaEmulationFailedDetail
42
- } from "../chunk-VDKR7MLG.js";
47
+ } from "../chunk-JZN76I3S.js";
43
48
  import "../chunk-JSBRDJBE.js";
44
49
  export {
45
50
  AGENT_EVENT_TYPE_NAMES,
@@ -56,12 +61,17 @@ export {
56
61
  REVERSE_CHANNELS,
57
62
  REVERSE_CHANNEL_TIMEOUT_CLASS,
58
63
  REVERSE_REQUEST_TIMEOUT_MS,
64
+ SET_MODEL_ERROR_CODES,
65
+ SET_MODEL_NOT_ACTIVE_CODE,
66
+ SET_MODEL_REQUEST_TIMEOUT_MS,
67
+ SET_MODEL_STAGE_TIMEOUT_MS,
59
68
  STDERR_TAIL_CHARS,
60
69
  STDOUT_TAIL_ECHO_CHARS,
61
70
  SUPPORTED_PROTOCOL_RANGE,
62
71
  assertChatConversationSupported,
63
72
  engineConversationUnsupportedError,
64
73
  engineProtocolMismatchError,
74
+ engineSetModelUnsupportedError,
65
75
  engineTimeoutDetail,
66
76
  errorResponseFrameSchema,
67
77
  isEngineErrorPassthroughCode,
@@ -51,6 +51,32 @@ function toErrorMessage(e) {
51
51
  var ENGINE_PROTOCOL_VERSION = 1;
52
52
 
53
53
  // src/protocol/error-codes.ts
54
+ var SET_MODEL_ERROR_CODES = [
55
+ /** 目标模型不在当前进程快照(子进程模型快照冻结于 spawn 时刻——模型本身有效,
56
+ * 下一轮 spawn 现取目录即可用;宿主按「写覆盖意图」处置,设计 §7.2 快照型失败行)。 */
57
+ "engine_model_not_in_snapshot",
58
+ /** 凭据校验失败(子进程 set_model checkAuth 抛错——宿主预检通过后 registry 态漂移
59
+ * 的权威兜底;宿主按校验型失败处置,设计 §7.5 凭据行)。 */
60
+ "engine_credential_missing",
61
+ /** 命令已发出(set_model 可能已执行)但读应答 / get_state 回读无回执、生效值未知
62
+ * (非进程退出情形——退出归无活进程路径;宿主按「写覆盖意图 + 错误应答」处置,
63
+ * 设计 §7.5 回读失败行)。 */
64
+ "engine_state_readback_failed"
65
+ ];
66
+ var SET_MODEL_NOT_ACTIVE_CODE = "engine_run_not_active";
67
+ var ENGINE_PROTOCOL_ERROR_CODES = [
68
+ "engine_not_found",
69
+ "engine_protocol_mismatch",
70
+ "engine_capability_unsupported",
71
+ "engine_capability_mismatch",
72
+ "engine_model_unknown",
73
+ "engine_model_mismatch",
74
+ "engine_handshake_timeout",
75
+ "engine_crashed",
76
+ "engine_probe_failed",
77
+ ...SET_MODEL_ERROR_CODES,
78
+ SET_MODEL_NOT_ACTIVE_CODE
79
+ ];
54
80
  var EngineSdkError = class extends Error {
55
81
  code;
56
82
  recovery;
@@ -1,5 +1,6 @@
1
- import { b as AgentCallOpts, A as AgentEvent } from '../contract-types-DqOD58r-.cjs';
2
- import { I as InitializeResult, R as RunContextParams, a as InitializeParams, E as EngineSdkError } from '../error-codes-C3oVToMr.cjs';
1
+ import { b as AgentCallOpts, A as AgentEvent } from '../contract-types-jSa1g28F.cjs';
2
+ import { E as EngineSdkError } from '../error-codes-f-UO4a8D.cjs';
3
+ import { I as InitializeResult, R as RunContextParams, b as InitializeParams } from '../methods-BLxg4ZFr.cjs';
3
4
  import { ReverseRequestClock } from '../spawn.cjs';
4
5
  import 'node:child_process';
5
6
  import '../env.cjs';
@@ -83,7 +84,7 @@ interface FrameLoopContext {
83
84
  result?: unknown;
84
85
  error?: unknown;
85
86
  }): void;
86
- /** 正向请求分发(9 方法表;抛出的错误经 `toError` 转错误帧)。 */
87
+ /** 正向请求分发(引擎装配表;抛出的错误经 `toError` 转错误帧)。 */
87
88
  dispatch(id: number, method: string, params: unknown): unknown;
88
89
  /** 错误 → 错误帧载荷(各引擎的恢复指引文案不同,故由引擎注入)。 */
89
90
  toError(err: unknown): ProtocolErrorPayload;
@@ -1,5 +1,6 @@
1
- import { b as AgentCallOpts, A as AgentEvent } from '../contract-types-DqOD58r-.js';
2
- import { I as InitializeResult, R as RunContextParams, a as InitializeParams, E as EngineSdkError } from '../error-codes-CiDwaODz.js';
1
+ import { b as AgentCallOpts, A as AgentEvent } from '../contract-types-jSa1g28F.js';
2
+ import { E as EngineSdkError } from '../error-codes-DnFru4L4.js';
3
+ import { I as InitializeResult, R as RunContextParams, b as InitializeParams } from '../methods-C2zvZqhP.js';
3
4
  import { ReverseRequestClock } from '../spawn.js';
4
5
  import 'node:child_process';
5
6
  import '../env.js';
@@ -83,7 +84,7 @@ interface FrameLoopContext {
83
84
  result?: unknown;
84
85
  error?: unknown;
85
86
  }): void;
86
- /** 正向请求分发(9 方法表;抛出的错误经 `toError` 转错误帧)。 */
87
+ /** 正向请求分发(引擎装配表;抛出的错误经 `toError` 转错误帧)。 */
87
88
  dispatch(id: number, method: string, params: unknown): unknown;
88
89
  /** 错误 → 错误帧载荷(各引擎的恢复指引文案不同,故由引擎注入)。 */
89
90
  toError(err: unknown): ProtocolErrorPayload;