@zhushanwen/subagent-engine-sdk 0.9.0 → 0.10.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.
Files changed (38) 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/{contract-types-DqOD58r-.d.cts → contract-types-jSa1g28F.d.cts} +37 -2
  7. package/dist/{contract-types-DqOD58r-.d.ts → contract-types-jSa1g28F.d.ts} +37 -2
  8. package/dist/error-codes-DnFru4L4.d.ts +150 -0
  9. package/dist/error-codes-f-UO4a8D.d.cts +150 -0
  10. package/dist/index.cjs +38 -2
  11. package/dist/index.d.cts +4 -3
  12. package/dist/index.d.ts +4 -3
  13. package/dist/index.js +15 -5
  14. package/dist/journal-io.d.cts +1 -1
  15. package/dist/journal-io.d.ts +1 -1
  16. package/dist/journal-replay.d.cts +1 -1
  17. package/dist/journal-replay.d.ts +1 -1
  18. package/dist/kill-chain.cjs +26 -0
  19. package/dist/kill-chain.d.cts +1 -1
  20. package/dist/kill-chain.d.ts +1 -1
  21. package/dist/kill-chain.js +2 -2
  22. package/dist/{error-codes-CiDwaODz.d.ts → methods-BLxg4ZFr.d.cts} +46 -120
  23. package/dist/{error-codes-C3oVToMr.d.cts → methods-C2zvZqhP.d.ts} +46 -120
  24. package/dist/node-executor.cjs +26 -0
  25. package/dist/node-executor.js +2 -2
  26. package/dist/port-contract.d.cts +11 -1
  27. package/dist/port-contract.d.ts +11 -1
  28. package/dist/protocol/index.cjs +38 -2
  29. package/dist/protocol/index.d.cts +20 -5
  30. package/dist/protocol/index.d.ts +20 -5
  31. package/dist/protocol/index.js +12 -2
  32. package/dist/server/index.cjs +26 -0
  33. package/dist/server/index.d.cts +4 -3
  34. package/dist/server/index.d.ts +4 -3
  35. package/dist/server/index.js +1 -1
  36. package/dist/spawn.cjs +28 -0
  37. package/dist/spawn.js +3 -3
  38. package/package.json +1 -1
@@ -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;
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  ENGINE_PROTOCOL_VERSION,
10
10
  EngineSdkError
11
- } from "../chunk-VDKR7MLG.js";
11
+ } from "../chunk-JZN76I3S.js";
12
12
  import "../chunk-JSBRDJBE.js";
13
13
 
14
14
  // src/server/index.ts
package/dist/spawn.cjs CHANGED
@@ -98,6 +98,34 @@ function toErrorMessage(e) {
98
98
  return String(e);
99
99
  }
100
100
 
101
+ // src/protocol/error-codes.ts
102
+ var SET_MODEL_ERROR_CODES = [
103
+ /** 目标模型不在当前进程快照(子进程模型快照冻结于 spawn 时刻——模型本身有效,
104
+ * 下一轮 spawn 现取目录即可用;宿主按「写覆盖意图」处置,设计 §7.2 快照型失败行)。 */
105
+ "engine_model_not_in_snapshot",
106
+ /** 凭据校验失败(子进程 set_model checkAuth 抛错——宿主预检通过后 registry 态漂移
107
+ * 的权威兜底;宿主按校验型失败处置,设计 §7.5 凭据行)。 */
108
+ "engine_credential_missing",
109
+ /** 命令已发出(set_model 可能已执行)但读应答 / get_state 回读无回执、生效值未知
110
+ * (非进程退出情形——退出归无活进程路径;宿主按「写覆盖意图 + 错误应答」处置,
111
+ * 设计 §7.5 回读失败行)。 */
112
+ "engine_state_readback_failed"
113
+ ];
114
+ var SET_MODEL_NOT_ACTIVE_CODE = "engine_run_not_active";
115
+ var ENGINE_PROTOCOL_ERROR_CODES = [
116
+ "engine_not_found",
117
+ "engine_protocol_mismatch",
118
+ "engine_capability_unsupported",
119
+ "engine_capability_mismatch",
120
+ "engine_model_unknown",
121
+ "engine_model_mismatch",
122
+ "engine_handshake_timeout",
123
+ "engine_crashed",
124
+ "engine_probe_failed",
125
+ ...SET_MODEL_ERROR_CODES,
126
+ SET_MODEL_NOT_ACTIVE_CODE
127
+ ];
128
+
101
129
  // src/kill-chain.ts
102
130
  var logger = getLogger("subagents");
103
131
  var MS_PER_SECOND = 1e3;
package/dist/spawn.js CHANGED
@@ -5,10 +5,10 @@ import {
5
5
  armEngineSelfDestruct,
6
6
  pumpNdjsonLines,
7
7
  spawnEngineChild
8
- } from "./chunk-6QE3OODO.js";
9
- import "./chunk-EF2F5YOM.js";
8
+ } from "./chunk-HSNDUHFH.js";
9
+ import "./chunk-CNCFMPEH.js";
10
10
  import "./chunk-PYO3YR7W.js";
11
- import "./chunk-VDKR7MLG.js";
11
+ import "./chunk-JZN76I3S.js";
12
12
  import "./chunk-NXNNXGTY.js";
13
13
  import "./chunk-JSBRDJBE.js";
14
14
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/subagent-engine-sdk",
3
- "version": "0.9.0",
3
+ "version": "0.10.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",