@mininglamp-oss/octo-runtime 1.1.8 → 1.1.9

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 (100) hide show
  1. package/apps/cli/README.md +3 -1
  2. package/apps/cli/dist/build-info.json +2 -2
  3. package/apps/cli/dist/command-tree.js +3 -1
  4. package/apps/cli/dist/output.js +5 -2
  5. package/apps/cli/dist/playboard.js +11 -2
  6. package/dist/public/executor-kernel.d.ts +2 -2
  7. package/dist/public/executor-kernel.js +1 -1
  8. package/dist/public/protocol.d.ts +1 -1
  9. package/dist/public/protocol.js +1 -1
  10. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  11. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  12. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  13. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  14. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  15. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +1 -0
  16. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +200 -106
  17. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/async-questions.d.ts +27 -0
  18. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/async-questions.js +205 -0
  19. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.d.ts +30 -0
  20. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.js +223 -0
  21. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  22. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-V5W6ZTYC.js → chunk-FGFEM7JP.js} +1 -1
  23. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-CFKMMCO6.js → chunk-R3PDZLX5.js} +3 -3
  24. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-LO34KB7D.js → chunk-TSRZVLIG.js} +1 -1
  25. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +2 -2
  26. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +1 -1
  27. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +5 -5
  28. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
  29. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
  30. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  31. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  32. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  33. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/gateway.d.ts +3 -0
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/gateway.js +57 -13
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +3 -2
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +4 -2
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/approval.js +2 -0
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  46. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  47. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +3 -1
  48. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +5 -2
  49. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +11 -2
  50. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -24
  51. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/launchd.d.ts +2 -2
  52. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/launchd.js +12 -11
  53. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  54. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/experience.js +2 -1
  55. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +5 -4
  56. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -4
  57. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +9 -2
  58. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +6 -3
  59. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  60. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.d.ts +30 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js +199 -0
  62. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.js +2 -2
  63. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +1 -0
  64. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +1 -0
  65. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.d.ts +2 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.js +16 -3
  67. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +36 -19
  68. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  69. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +6 -2
  70. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +2 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +14 -0
  72. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +4 -0
  73. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/interaction-card.js +2 -1
  74. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/session-command.d.ts +9 -0
  75. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/session-command.js +71 -0
  76. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
  77. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +14 -0
  78. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
  79. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/{index-B127MhT-.js → index-BVxePruX.js} +1 -1
  80. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
  81. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
  82. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/context-loader.js +1 -1
  83. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
  84. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.d.ts +1 -0
  85. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.js +1 -0
  86. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.d.ts +2 -0
  87. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +4 -1
  88. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +3 -0
  89. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +63 -12
  90. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +110 -5
  91. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +7 -4
  92. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +28 -6
  93. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +2 -0
  94. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.d.ts +9 -0
  95. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.js +84 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.d.ts +1 -1
  97. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.js +11 -5
  98. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  99. package/package.json +27 -27
  100. package/packages/octo-runtime-protocol/schema/protocol.schema.json +156 -4
@@ -1,3 +1,3 @@
1
- <!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Octo Runtime</title> <script type="module" crossorigin src="/assets/index-B127MhT-.js"></script>
1
+ <!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Octo Runtime</title> <script type="module" crossorigin src="/assets/index-BVxePruX.js"></script>
2
2
  <link rel="stylesheet" crossorigin href="/assets/index-CYTpqItx.css">
3
3
  </head><body><div id="root"></div></body></html>
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-extra-webui",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "description": "Local Runtime workbench with canonical SSE presentation",
@@ -23,6 +23,6 @@
23
23
  "porting-map.md"
24
24
  ],
25
25
  "dependencies": {
26
- "@mininglamp-oss/octo-runtime-protocol": "1.1.8"
26
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.9"
27
27
  }
28
28
  }
@@ -108,7 +108,7 @@ export function createContextLoader(callback, settings, owner) {
108
108
  }
109
109
  },
110
110
  async close() {
111
- // 这里等待实际 IO 退出;外层 Extra loader 负责 5 秒宽限,超时后保留失败实例阻止重载。
111
+ // 等待实际 IO 退出;外层 Extra 各阶段共用 4 秒或继承的更早截止,到期保留失败实例阻止重载。
112
112
  stop.abort();
113
113
  await Promise.allSettled([...pending]);
114
114
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-host-sdk",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {
@@ -23,9 +23,9 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.8",
27
- "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.8",
28
- "@mininglamp-oss/octo-runtime-protocol": "1.1.8"
26
+ "@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.9",
27
+ "@mininglamp-oss/octo-runtime-executor-kernel": "1.1.9",
28
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.9"
29
29
  },
30
30
  "types": "./dist/index.d.ts",
31
31
  "files": [
@@ -1,4 +1,5 @@
1
1
  export type * from "./generated/protocol-types.js";
2
+ export * from "./questions.js";
2
3
  export * from "./context.js";
3
4
  export * from "./model-context.js";
4
5
  export * from "./execution-plan.js";
@@ -1,3 +1,4 @@
1
+ export * from "./questions.js";
1
2
  export * from "./context.js";
2
3
  export * from "./model-context.js";
3
4
  export * from "./execution-plan.js";
@@ -8,6 +8,8 @@ export declare const RUNTIME_RUN_CONTRACT: Readonly<{
8
8
  }>;
9
9
  export declare const CONTEXT_MAX_BYTES = 65536;
10
10
  export declare const CONTEXT_MAX_ITEMS = 32;
11
+ export declare const DEFAULT_RUN_TIMEOUT_MS = 86400000;
12
+ export declare const MAX_RUN_TIMEOUT_MS = 604800000;
11
13
  export declare const APPROVAL_MODES: readonly ApprovalMode[];
12
14
  export declare function assertAgentSource(value: unknown): asserts value is "preset" | "provisioned";
13
15
  export declare function assertApprovalMode(value: unknown): asserts value is ApprovalMode;
@@ -8,6 +8,9 @@ export const RUNTIME_RUN_CONTRACT = Object.freeze({
8
8
  });
9
9
  export const CONTEXT_MAX_BYTES = 65_536;
10
10
  export const CONTEXT_MAX_ITEMS = 32;
11
+ // 整轮预算与首帧/空闲检测独立;七天仍在 Node 单次定时器的安全范围内。
12
+ export const DEFAULT_RUN_TIMEOUT_MS = 86_400_000;
13
+ export const MAX_RUN_TIMEOUT_MS = 604_800_000;
11
14
  export const APPROVAL_MODES = ["ask", "assisted", "full_access"];
12
15
  export function assertAgentSource(value) {
13
16
  if (value !== "preset" && value !== "provisioned")
@@ -430,7 +433,7 @@ function limits(value) {
430
433
  model_idle_warning_ms: 3_600_000,
431
434
  tool_timeout_ms: 86_400_000,
432
435
  tool_wall_timeout_ms: 86_400_000,
433
- run_timeout_ms: 86_400_000,
436
+ run_timeout_ms: MAX_RUN_TIMEOUT_MS,
434
437
  cancel_grace_ms: 60_000
435
438
  };
436
439
  fields(value, [...Object.keys(bounds), "model_idle_policy", "enforcement"]);
@@ -64,6 +64,9 @@ export declare const FAILURE_CATALOG: Readonly<{
64
64
  "OH-SYS-9001": CatalogEntry;
65
65
  }>;
66
66
  export type PublicFailureCode = keyof typeof FAILURE_CATALOG;
67
+ export declare function isCodexLocalFailureReason(value: unknown): value is string;
68
+ /** native 仅允许中央目录的本地失败;不开放任意 params 或 Provider 自报错误提升。 */
69
+ export declare function isCodexLocalFailure(failure: FailureEnvelope): boolean;
67
70
  /** Classify untrusted adapter/provider error data without copying raw messages or secrets into the result. */
68
71
  export declare function classifyFailure(input: unknown, context: FailureClassificationContext): FailureEnvelope;
69
72
  /**
@@ -41,6 +41,44 @@ export const FAILURE_CATALOG = Object.freeze({
41
41
  "OH-PRV-4099": entry("provider_unknown", "模型服务调用失败,暂时无法识别具体原因。", "error.provider.unknown", true, "retry"),
42
42
  "OH-SYS-9001": entry("system_unknown", "系统发生未知错误。", "error.system.unknown", true, "retry")
43
43
  });
44
+ /** Codex 本地审批/发送失败的封闭原因表;与 Provider 原生 RPC 错误分别处理。 */
45
+ const CODEX_LOCAL_FAILURES = Object.freeze({
46
+ APPROVAL_PENDING_LIMIT_EXCEEDED: "OH-ADP-3004",
47
+ CODEX_INTERACTION_PENDING_LIMIT_EXCEEDED: "OH-ADP-3004",
48
+ INTERACTION_PENDING_LIMIT_EXCEEDED: "OH-ADP-3004",
49
+ CODEX_INTERACTION_BYTES_EXCEEDED: "OH-ADP-3004",
50
+ CODEX_STDIN_QUEUE_ITEMS_EXCEEDED: "OH-ADP-3004",
51
+ CODEX_STDIN_QUEUE_BYTES_EXCEEDED: "OH-ADP-3004",
52
+ CODEX_STDIN_WRITE_FAILED: "OH-ADP-3004",
53
+ CODEX_TRANSPORT_FAILED: "OH-ADP-3004",
54
+ CODEX_STDIN_STALLED: "OH-ADP-3013",
55
+ CODEX_STDIN_DELIVERY_TIMEOUT: "OH-ADP-3013",
56
+ INTERACTION_EXPIRED: "OH-ADP-3004",
57
+ APPROVAL_GRANT_SCOPE_UNSUPPORTED: "OH-ADP-3004",
58
+ APPROVAL_OPERATION_UNSUPPORTED: "OH-ADP-3004"
59
+ });
60
+ export function isCodexLocalFailureReason(value) {
61
+ return typeof value === "string" && Object.hasOwn(CODEX_LOCAL_FAILURES, value);
62
+ }
63
+ /** native 仅允许中央目录的本地失败;不开放任意 params 或 Provider 自报错误提升。 */
64
+ export function isCodexLocalFailure(failure) {
65
+ const reason = failure.reasonCode;
66
+ if (!isCodexLocalFailureReason(reason))
67
+ return false;
68
+ const catalog = FAILURE_CATALOG[CODEX_LOCAL_FAILURES[reason]];
69
+ return (failure.source.component === "octo-runtime" &&
70
+ failure.source.adapter === "codex" &&
71
+ failure.code === CODEX_LOCAL_FAILURES[reason] &&
72
+ failure.category === catalog.category &&
73
+ failure.messageKey === catalog.messageKey &&
74
+ failure.retryable === false &&
75
+ failure.action.type === "contact_admin" &&
76
+ failure.action.labelKey === "action.contact_admin" &&
77
+ failure.retryAfterMs === undefined &&
78
+ Object.keys(failure.params).length === 0 &&
79
+ (failure.cause === undefined ||
80
+ (failure.cause.reasonCode === reason && failure.cause.httpStatus === undefined)));
81
+ }
44
82
  /** Classify untrusted adapter/provider error data without copying raw messages or secrets into the result. */
45
83
  export function classifyFailure(input, context) {
46
84
  const evidence = failureEvidence(input);
@@ -61,8 +99,9 @@ export function classifyFailure(input, context) {
61
99
  : undefined;
62
100
  const classification = channelCode
63
101
  ? result(channelCode, evidence.explicitCode)
64
- : classify(evidence, context.defaultDomain);
102
+ : classify(evidence, context.defaultDomain, context.source?.adapter);
65
103
  const catalog = FAILURE_CATALOG[classification.code];
104
+ const codexLocal = context.source?.adapter === "codex" && isCodexLocalFailureReason(classification.reasonCode);
66
105
  return {
67
106
  schemaVersion: 1,
68
107
  code: classification.code,
@@ -70,19 +109,27 @@ export function classifyFailure(input, context) {
70
109
  category: catalog.category,
71
110
  stage: context.stage,
72
111
  messageKey: catalog.messageKey,
73
- params: classification.reasonCode === "CODEX_FINALIZATION_TIMEOUT"
74
- ? {
75
- configParameter: "execution_profile.agent_config.providerOptions.finalizationTimeoutMs"
76
- }
77
- : timeoutConfiguration(classification.code, context.source?.adapter),
78
- retryable: classification.reasonCode === "CODEX_FINALIZATION_TIMEOUT" ? false : catalog.retryable,
112
+ params: codexLocal
113
+ ? {}
114
+ : classification.reasonCode === "CODEX_FINALIZATION_TIMEOUT"
115
+ ? {
116
+ configParameter: "execution_profile.agent_config.providerOptions.finalizationTimeoutMs"
117
+ }
118
+ : timeoutConfiguration(classification.code, context.source?.adapter),
119
+ retryable: codexLocal || classification.reasonCode === "CODEX_FINALIZATION_TIMEOUT"
120
+ ? false
121
+ : catalog.retryable,
79
122
  ...(catalog.retryAfterMs === undefined ? {} : { retryAfterMs: catalog.retryAfterMs }),
80
- action: catalog.action,
123
+ action: codexLocal
124
+ ? { type: "contact_admin", labelKey: "action.contact_admin" }
125
+ : catalog.action,
81
126
  diagnosticId: diagnosticIdForContext(context),
82
127
  source: context.source ?? { component: "octo-runtime" },
83
128
  cause: {
84
129
  reasonCode: classification.reasonCode,
85
- ...(evidence.httpStatus === undefined ? {} : { httpStatus: evidence.httpStatus })
130
+ ...(codexLocal || evidence.httpStatus === undefined
131
+ ? {}
132
+ : { httpStatus: evidence.httpStatus })
86
133
  },
87
134
  occurredAt: context.occurredAt ?? new Date().toISOString()
88
135
  };
@@ -188,7 +235,9 @@ function safeWatchdogEvidence(value) {
188
235
  "retryCount"
189
236
  ]) {
190
237
  const v = input[key];
191
- if (typeof v === "number" && Number.isSafeInteger(v) && v >= 0 && v <= 86_400_000)
238
+ // 时间证据可能超过预算(事件循环延迟);计数仍沿用既有过滤上限。
239
+ const maximum = key.endsWith("Ms") ? Number.MAX_SAFE_INTEGER : 86_400_000;
240
+ if (typeof v === "number" && Number.isSafeInteger(v) && v >= 0 && v <= maximum)
192
241
  result[key] = v;
193
242
  }
194
243
  if (input.activitySupport === "native_progress" || input.activitySupport === "canonical_only")
@@ -211,7 +260,7 @@ function safeTimeoutMs(value) {
211
260
  return typeof value === "number" &&
212
261
  Number.isSafeInteger(value) &&
213
262
  value >= 1 &&
214
- value <= 86_400_000
263
+ value <= Number.MAX_SAFE_INTEGER
215
264
  ? value
216
265
  : undefined;
217
266
  }
@@ -309,9 +358,11 @@ function failureEvidence(input) {
309
358
  visit(input, 0);
310
359
  return { fingerprint: values.join(" ").toLowerCase().slice(0, 12_000), explicitCode, httpStatus };
311
360
  }
312
- function classify(evidence, defaultDomain) {
361
+ function classify(evidence, defaultDomain, adapter) {
313
362
  const text = evidence.fingerprint;
314
363
  const explicit = evidence.explicitCode?.toUpperCase();
364
+ if (adapter === "codex" && isCodexLocalFailureReason(explicit))
365
+ return result(CODEX_LOCAL_FAILURES[explicit], explicit);
315
366
  // ACP 已明确声明失败;meta 仅作诊断,不从其中的状态码或文字猜测其他类别。
316
367
  if (explicit === "ACP_MODEL_REQUEST_FAILED")
317
368
  return result("OH-PRV-4010", explicit);
@@ -52,6 +52,10 @@ export type HostControl = {
52
52
  type: "interaction";
53
53
  requestId: string | number;
54
54
  status: "pending" | "resolved" | "expired" | "invalidated";
55
+ /**
56
+ * Whether an external response is required. Omission means required; false does not imply resolution or completion.
57
+ */
58
+ responseRequired?: boolean;
55
59
  expiresAt?: number;
56
60
  } | {
57
61
  type: "gap";
@@ -63,7 +67,7 @@ export type HostControl = {
63
67
  * This interface was referenced by `OctoRuntimeProtocolSchema`'s JSON-Schema
64
68
  * via the `definition` "RunProtocolErrorCode".
65
69
  */
66
- export type RunProtocolErrorCode = "PROTOCOL_MODE_INVALID" | "PROTOCOL_MODE_UNSUPPORTED" | "EXECUTION_PROTOCOL_MISMATCH" | "EXECUTION_IDENTITY_CONFLICT" | "NATIVE_METHOD_UNSUPPORTED" | "NATIVE_RESPONSE_INVALID" | "INTERACTION_NOT_ACTIVE" | "HOST_EXECUTION_FAILED" | "HOST_ENDED_WITHOUT_TERMINAL" | "PROVIDER_MESSAGE_TOO_LARGE" | "HOST_FRAME_TOO_LARGE" | "STREAM_QUEUE_ITEM_TOO_LARGE" | "STREAM_QUEUE_BYTES_EXCEEDED" | "STREAM_QUEUE_ITEMS_EXCEEDED" | "STREAM_GAP" | "STREAM_EXPIRED" | "REMOTE_NATIVE_UNSUPPORTED" | "HOST_FRAME_INVALID" | "HOST_CONTROL_INVALID" | "HOST_RECEIPT_INVALID" | "PROTOCOL_SUPPORT_INVALID";
70
+ export type RunProtocolErrorCode = "PROTOCOL_MODE_INVALID" | "PROTOCOL_MODE_UNSUPPORTED" | "EXECUTION_PROTOCOL_MISMATCH" | "EXECUTION_IDENTITY_CONFLICT" | "NATIVE_METHOD_UNSUPPORTED" | "NATIVE_RESPONSE_INVALID" | "INTERACTION_NOT_ACTIVE" | "INVALID_QUESTION_RESPONSE" | "ASYNC_ANSWER_REJECTED" | "OPERATION_OUTCOME_UNKNOWN" | "HOST_EXECUTION_FAILED" | "HOST_ENDED_WITHOUT_TERMINAL" | "PROVIDER_MESSAGE_TOO_LARGE" | "HOST_FRAME_TOO_LARGE" | "STREAM_QUEUE_ITEM_TOO_LARGE" | "STREAM_QUEUE_BYTES_EXCEEDED" | "STREAM_QUEUE_ITEMS_EXCEEDED" | "STREAM_GAP" | "STREAM_EXPIRED" | "REMOTE_NATIVE_UNSUPPORTED" | "HOST_FRAME_INVALID" | "HOST_CONTROL_INVALID" | "HOST_RECEIPT_INVALID" | "PROTOCOL_SUPPORT_INVALID";
67
71
  export type ProtocolMode1 = "native" | "canonical";
68
72
  /**
69
73
  * Public, channel-neutral project notification. No runtime context, reasoning, credentials, or tool payloads belong in this envelope.
@@ -220,6 +224,13 @@ export type AgentSource = "preset" | "provisioned";
220
224
  * via the `definition` "McpServers".
221
225
  */
222
226
  export type McpServers = Record<string, McpServer>;
227
+ /**
228
+ * Provider-neutral interaction. Omitted delivery retains synchronous blocking semantics; async questions allow continued work. Only Adapter-owned automatic approvals may omit external responses; this does not imply completion.
229
+ *
230
+ * This interface was referenced by `OctoRuntimeProtocolSchema`'s JSON-Schema
231
+ * via the `definition` "InteractionRequestedPayload".
232
+ */
233
+ export type InteractionRequestedPayload = InteractionRequestedPayload1;
223
234
  /**
224
235
  * Display-only fields permitted by assertApprovalRequest. Values remain inert provider metadata and do not redefine commands, permissions or grant scope.
225
236
  *
@@ -393,6 +404,16 @@ export interface CanonicalEventWire {
393
404
  * via the `definition` "CanonicalEventPayload".
394
405
  */
395
406
  export interface CanonicalEventPayload {
407
+ /**
408
+ * Async questions do not block provider work. Omitted for existing synchronous interactions.
409
+ */
410
+ delivery?: "async";
411
+ /**
412
+ * Message snapshot only; an active interaction.requested authorizes submission.
413
+ *
414
+ * @maxItems 50
415
+ */
416
+ questions?: AsyncUserInputQuestion[];
396
417
  providerSession?: ProviderSession;
397
418
  channel?: MessageChannel;
398
419
  exposure?: MessageExposure;
@@ -428,6 +449,17 @@ export interface CanonicalEventPayload {
428
449
  failure?: FailureEnvelope;
429
450
  [k: string]: unknown;
430
451
  }
452
+ /**
453
+ * This interface was referenced by `OctoRuntimeProtocolSchema`'s JSON-Schema
454
+ * via the `definition` "AsyncUserInputQuestion".
455
+ */
456
+ export interface AsyncUserInputQuestion {
457
+ title: string;
458
+ /**
459
+ * @maxItems 50
460
+ */
461
+ options: string[] | null;
462
+ }
431
463
  /**
432
464
  * Provider-owned session resume data. Core treats sessionId and adapter extension fields as opaque.
433
465
  *
@@ -443,6 +475,10 @@ export interface ProviderSession {
443
475
  * Whether the provider declares that later invocations can resume this session.
444
476
  */
445
477
  resumable?: boolean;
478
+ /**
479
+ * Require the original provider session; adapters must reject rather than start a fresh fallback. Currently implemented by Codex.
480
+ */
481
+ requireResume?: boolean;
446
482
  /**
447
483
  * Continuity outcome for this session update. Compaction applies to the next turn; fresh fallback applies to the current turn.
448
484
  */
@@ -2314,19 +2350,88 @@ export interface AgentConfig {
2314
2350
  [k: string]: unknown;
2315
2351
  }
2316
2352
  /**
2317
- * Provider-neutral request that pauses one active invocation until an interaction response is returned through the Adapter Host.
2353
+ * Non-blocking question batch. IDs are positions scoped to this interaction, not provider-native question IDs.
2318
2354
  *
2319
2355
  * This interface was referenced by `OctoRuntimeProtocolSchema`'s JSON-Schema
2320
- * via the `definition` "InteractionRequestedPayload".
2356
+ * via the `definition` "QuestionRequest".
2357
+ */
2358
+ export interface QuestionRequest {
2359
+ schema: "octo.question-request/v1";
2360
+ messageId: string;
2361
+ /**
2362
+ * @minItems 1
2363
+ * @maxItems 50
2364
+ */
2365
+ questions: [
2366
+ {
2367
+ id: string;
2368
+ title: string;
2369
+ /**
2370
+ * @maxItems 50
2371
+ */
2372
+ options: string[] | null;
2373
+ allowCustom: true;
2374
+ },
2375
+ ...{
2376
+ id: string;
2377
+ title: string;
2378
+ /**
2379
+ * @maxItems 50
2380
+ */
2381
+ options: string[] | null;
2382
+ allowCustom: true;
2383
+ }[]
2384
+ ];
2385
+ }
2386
+ /**
2387
+ * This interface was referenced by `OctoRuntimeProtocolSchema`'s JSON-Schema
2388
+ * via the `definition` "QuestionResponse".
2389
+ */
2390
+ export interface QuestionResponse {
2391
+ schema: "octo.question-response/v1";
2392
+ /**
2393
+ * @minItems 1
2394
+ * @maxItems 50
2395
+ */
2396
+ answers: [
2397
+ {
2398
+ questionId: string;
2399
+ text: string;
2400
+ },
2401
+ ...{
2402
+ questionId: string;
2403
+ text: string;
2404
+ }[]
2405
+ ];
2406
+ }
2407
+ /**
2408
+ * Host-owned supplement state, never stored by Kernel. Submitting or unknown records cannot be replayed.
2409
+ *
2410
+ * This interface was referenced by `OctoRuntimeProtocolSchema`'s JSON-Schema
2411
+ * via the `definition` "AsyncQuestionReplySnapshot".
2321
2412
  */
2322
- export interface InteractionRequestedPayload {
2413
+ export interface AsyncQuestionReplySnapshot {
2414
+ schema: "octo.async-question-reply/v1";
2415
+ ref: KernelRunRef;
2416
+ question: InteractionRequestedPayload;
2417
+ providerSession: ProviderSession;
2418
+ providerEpoch?: number;
2419
+ completed: boolean;
2420
+ phase: "pending" | "submitting" | "answered" | "cancelled" | "invalidated" | "unknown";
2421
+ }
2422
+ export interface InteractionRequestedPayload1 {
2423
+ delivery?: "async";
2323
2424
  executionInstanceId: string;
2324
- expiresAt: string;
2425
+ expiresAt?: string;
2325
2426
  /**
2326
2427
  * Stable invocation-scoped interaction identifier.
2327
2428
  */
2328
2429
  interactionId: string;
2329
2430
  kind: "approval" | "question" | "elicitation";
2431
+ /**
2432
+ * Whether an external response is required. Omission means required; only an Adapter-owned automatic approval may set false.
2433
+ */
2434
+ responseRequired?: boolean;
2330
2435
  /**
2331
2436
  * Display-safe provider request projected for the responding product.
2332
2437
  */
@@ -1,3 +1,5 @@
1
+ export { assertAsyncQuestions, assertQuestionRequest, assertQuestionResponse, questionAnswerText } from "./questions.js";
2
+ export type { AsyncUserInputQuestion, AsyncQuestionReplySnapshot, QuestionRequest, QuestionResponse } from "./generated/protocol-types.js";
1
3
  export { assertJsonByteLimit } from "./json-size.js";
2
4
  export { INVOKE_REQUEST_MAX_BYTES, assertInvokeRequestSize } from "./invoke-size.js";
3
5
  export * from "./stream-limits.js";
@@ -7,10 +9,11 @@ export * from "./invoke-input.js";
7
9
  export * from "./model-context.js";
8
10
  export * from "./execution-plan.js";
9
11
  export { contextHash } from "./context-hash.js";
12
+ export { assertJsonValue } from "./context.js";
10
13
  export type { ToolAuthorization, IssuedToolAuthorization } from "./generated/protocol-types.js";
11
14
  export { PROVIDER_DIAGNOSTIC_MAX_BYTES } from "./experience.js";
12
15
  export { IMAGE_INPUT_LIMITS, IMAGE_INPUT_MIME_TYPES, assertModelInputParts, providerInputParts, hasImageInput, modelPartsFromInput } from "./multimodal.js";
13
- export { APPROVAL_MODES, CONTEXT_SCHEMA, CONTEXT_MAX_BYTES, CONTEXT_MAX_ITEMS, RUNTIME_RUN_CONTRACT, assertAgentSource, assertApprovalMode, assertContextEnvelope, assertContextEnvs, assertMcpServers, assertContextMcp, assertResolvedExecutionPlan, canonicalContext, contextItem, mergeContext } from "./context.js";
16
+ export { APPROVAL_MODES, CONTEXT_SCHEMA, CONTEXT_MAX_BYTES, CONTEXT_MAX_ITEMS, DEFAULT_RUN_TIMEOUT_MS, MAX_RUN_TIMEOUT_MS, RUNTIME_RUN_CONTRACT, assertAgentSource, assertApprovalMode, assertContextEnvelope, assertContextEnvs, assertMcpServers, assertContextMcp, assertResolvedExecutionPlan, canonicalContext, contextItem, mergeContext } from "./context.js";
14
17
  export { RUNTIME_SELECTION_SCHEMA, assertResolvedRuntimeSelection } from "./runtime-selection.js";
15
18
  export { CONTEXT_TYPE_CATALOG, contextTypeDefinition, findContextTypeDefinition } from "./context-catalog.js";
16
19
  export type { ContextTypeDefinition } from "./context-catalog.js";
@@ -18,7 +21,7 @@ export { assertContextConfiguration, resolveContextConfiguration } from "./conte
18
21
  export { assertNotificationMessage } from "./notification.js";
19
22
  import type { ActivityStartedPayload, ActivityUpdatedPayload, ActivityFinishedPayload, PlanUpdatedPayload, ToolProgressPayload, RunNoticePayload, CanonicalEventPayload, ChannelContextAppend, ChannelContextDescriptor, ChannelMessageFact, ChannelScope, ContextSyncResult, InvokeRequestWire, RuntimeLimits, MessageChannel, MessageExposure, InteractionRequestedPayload, InteractionResolvedPayload, ModelStepFinishedPayload, ModelStepStartedPayload, ToolCallCreatePayload, ToolCallDeltaPayload, ToolCallUpdatePayload, FailureEnvelope } from "./generated/protocol-types.js";
20
23
  export type { AgentSource, NotificationMessage, ModelInputPart, ApprovalMode, ApprovalRequest, ApprovalOperation, ApprovalDisplayDetails, ContextItem, ContextInlinePayload, ContextReferencesPayload, ContextInlineEntry, ContextReferenceEntry, ContextEnvelope, ContextConfiguration, ContextPreparationReceipt, RunContextProjection, ContextAdapterPayload, ContextModelPayload, ContextActmodePayload, ExecutionEvidence, ContextReasoningPayload, ContextWorkspacePayload, ContextLimitsPayload, ContextEnvsPayload, ContextRuntimeSelectionPayload, ContextApprovalPolicyPayload, ContextSelectionEntry, ContextResourceEntry, ContextInstructionEntry, ContextInstructionsPayload, ContextContinuityPayload, ResolvedExecutionPlan, ResolvedRuntimeSelection, MessageChannel, MessageExposure, MessageProvenance, ProviderSession, AgentConfig, RuntimeLimits, ActivityInfo, ActivitySubject, ActivityStartedPayload, ActivityUpdatedPayload, ActivityFinishedPayload, PlanUpdatedPayload, ToolProgressPayload, RunNoticePayload, CanonicalEventPayload, InteractionRequestedPayload, InteractionResolvedPayload, ModelStepStartedPayload, ModelStepFinishedPayload, ToolCallCreatePayload, ToolCallDeltaPayload, ToolCallUpdatePayload, FailureAction, FailureSource, FailureCause, FailureEnvelope, ChannelScope, ChannelMessagePart, ChannelMessageSender, ChannelMessageFlags, ChannelMessageFact, ChannelContextAppend, ContextSyncRequest, ContextSyncResult, ChannelContextDescriptor, ContextCommitResult, McpStdioServer, McpStreamableHttpServer, McpServer, McpServers, RunIdentity, InvokeRequestWire } from "./generated/protocol-types.js";
21
- export { FAILURE_CATALOG, classifyFailure, failureMessage, failurePayload, isFailureEnvelope, type FailureClassificationContext, type FailureDomain, type PublicFailureCode } from "./failure.js";
24
+ export { FAILURE_CATALOG, classifyFailure, isCodexLocalFailureReason, isCodexLocalFailure, failureMessage, failurePayload, isFailureEnvelope, type FailureClassificationContext, type FailureDomain, type PublicFailureCode } from "./failure.js";
22
25
  import type { RunIdentity } from "./generated/protocol-types.js";
23
26
  /**
24
27
  * The three terminal states a Run may reach.
@@ -40,10 +43,10 @@ export type TerminalEventType = (typeof TERMINAL_EVENT_TYPES)[number];
40
43
  */
41
44
  export { contextActmode, assertExecutionEvidence } from "./actmode.js";
42
45
  export declare const CANONICAL_EVENT_TYPES: readonly ["session.update", "execution.update", "usage.update", "model_step.started", "model_step.finished", "message.create", "message.delta", "message.update", "tool_call.create", "tool_call.delta", "tool_call.update", "activity.started", "activity.updated", "activity.finished", "plan.updated", "tool_call.progress", "run.notice", "interaction.requested", "interaction.resolved", "run.queued", "run.started", "run.completed", "run.failed", "run.cancelled"];
43
- /** Every provider's native events must collapse into this set, so the Core stays agnostic of the underlying CLI. */
46
+ /** canonical 模式下的统一事件类型;native-only Adapter 无须转换原生事件。 */
44
47
  export type CanonicalEventType = (typeof CANONICAL_EVENT_TYPES)[number];
45
48
  export type CanonicalPayloadFor<TType extends CanonicalEventType> = TType extends "activity.started" ? CanonicalEventPayload & ActivityStartedPayload : TType extends "activity.updated" ? CanonicalEventPayload & ActivityUpdatedPayload : TType extends "activity.finished" ? CanonicalEventPayload & ActivityFinishedPayload : TType extends "plan.updated" ? CanonicalEventPayload & PlanUpdatedPayload : TType extends "tool_call.progress" ? CanonicalEventPayload & ToolProgressPayload : TType extends "run.notice" ? CanonicalEventPayload & RunNoticePayload : TType extends "model_step.started" ? CanonicalEventPayload & ModelStepStartedPayload : TType extends "model_step.finished" ? CanonicalEventPayload & ModelStepFinishedPayload : TType extends "interaction.requested" ? CanonicalEventPayload & InteractionRequestedPayload : TType extends "interaction.resolved" ? CanonicalEventPayload & InteractionResolvedPayload : TType extends "tool_call.create" ? CanonicalEventPayload & ToolCallCreatePayload : TType extends "tool_call.delta" ? CanonicalEventPayload & ToolCallDeltaPayload : TType extends "tool_call.update" ? CanonicalEventPayload & ToolCallUpdatePayload : CanonicalEventPayload;
46
- /** The smallest event unit an adapter emits to the Host; the payload narrows by type for the tool lifecycle. */
49
+ /** Adapter 在 canonical 模式下输出的最小事件单元;工具生命周期的 payload 随类型收窄。 */
47
50
  export type CanonicalEvent<TType extends CanonicalEventType = CanonicalEventType> = TType extends CanonicalEventType ? {
48
51
  protocolVersion: 2;
49
52
  type: TType;
@@ -1,4 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { assertAsyncQuestions, assertQuestionRequest } from "./questions.js";
3
+ export { assertAsyncQuestions, assertQuestionRequest, assertQuestionResponse, questionAnswerText } from "./questions.js";
2
4
  import { assertSessionName } from "./invoke-input.js";
3
5
  export { assertJsonByteLimit } from "./json-size.js";
4
6
  export { INVOKE_REQUEST_MAX_BYTES, assertInvokeRequestSize } from "./invoke-size.js";
@@ -8,17 +10,18 @@ export * from "./invoke-input.js";
8
10
  export * from "./model-context.js";
9
11
  export * from "./execution-plan.js";
10
12
  export { contextHash } from "./context-hash.js";
13
+ export { assertJsonValue } from "./context.js";
11
14
  import { assertExperiencePayload } from "./experience.js";
12
15
  export { PROVIDER_DIAGNOSTIC_MAX_BYTES } from "./experience.js";
13
16
  import { assertModelInputParts, assertImageRecoveryParts, hasImageInput } from "./multimodal.js";
14
17
  export { IMAGE_INPUT_LIMITS, IMAGE_INPUT_MIME_TYPES, assertModelInputParts, providerInputParts, hasImageInput, modelPartsFromInput } from "./multimodal.js";
15
- import { assertAgentSource, assertApprovalMode, assertContextEnvelope, assertContextEnvs, assertJsonValue, contextItem } from "./context.js";
16
- export { APPROVAL_MODES, CONTEXT_SCHEMA, CONTEXT_MAX_BYTES, CONTEXT_MAX_ITEMS, RUNTIME_RUN_CONTRACT, assertAgentSource, assertApprovalMode, assertContextEnvelope, assertContextEnvs, assertMcpServers, assertContextMcp, assertResolvedExecutionPlan, canonicalContext, contextItem, mergeContext } from "./context.js";
18
+ import { assertAgentSource, assertApprovalMode, assertContextEnvelope, assertContextEnvs, assertJsonValue, MAX_RUN_TIMEOUT_MS, contextItem } from "./context.js";
19
+ export { APPROVAL_MODES, CONTEXT_SCHEMA, CONTEXT_MAX_BYTES, CONTEXT_MAX_ITEMS, DEFAULT_RUN_TIMEOUT_MS, MAX_RUN_TIMEOUT_MS, RUNTIME_RUN_CONTRACT, assertAgentSource, assertApprovalMode, assertContextEnvelope, assertContextEnvs, assertMcpServers, assertContextMcp, assertResolvedExecutionPlan, canonicalContext, contextItem, mergeContext } from "./context.js";
17
20
  export { RUNTIME_SELECTION_SCHEMA, assertResolvedRuntimeSelection } from "./runtime-selection.js";
18
21
  export { CONTEXT_TYPE_CATALOG, contextTypeDefinition, findContextTypeDefinition } from "./context-catalog.js";
19
22
  export { assertContextConfiguration, resolveContextConfiguration } from "./context-configuration.js";
20
23
  export { assertNotificationMessage } from "./notification.js";
21
- export { FAILURE_CATALOG, classifyFailure, failureMessage, failurePayload, isFailureEnvelope } from "./failure.js";
24
+ export { FAILURE_CATALOG, classifyFailure, isCodexLocalFailureReason, isCodexLocalFailure, failureMessage, failurePayload, isFailureEnvelope } from "./failure.js";
22
25
  /**
23
26
  * The three terminal states a Run may reach.
24
27
  *
@@ -269,6 +272,15 @@ export function assertCanonicalEvent(event) {
269
272
  if (event.protocolVersion !== PROTOCOL_VERSION)
270
273
  throw new TypeError("canonical protocolVersion must be 2");
271
274
  const payload = isRecord(event.payload) ? event.payload : {};
275
+ if (event.type.startsWith("message.")) {
276
+ if (payload.delivery !== undefined && payload.delivery !== "async")
277
+ throw new TypeError("INVALID_MESSAGE_DELIVERY");
278
+ if (payload.questions !== undefined) {
279
+ if (payload.delivery !== "async")
280
+ throw new TypeError("INVALID_MESSAGE_DELIVERY");
281
+ assertAsyncQuestions(payload.questions);
282
+ }
283
+ }
272
284
  if (event.type === "execution.update")
273
285
  assertExecutionEvidence(payload);
274
286
  assertExperiencePayload(event.type, payload);
@@ -328,10 +340,11 @@ export function assertCanonicalEvent(event) {
328
340
  if (event.type === "interaction.requested") {
329
341
  requireEventString(payload, "interactionId", event.type);
330
342
  requireEventString(payload, "executionInstanceId", event.type);
331
- requireEventString(payload, "expiresAt", event.type);
343
+ if (payload.delivery !== "async" || payload.expiresAt !== undefined)
344
+ requireEventString(payload, "expiresAt", event.type);
332
345
  if (Array.from(String(payload.interactionId)).length > 191 ||
333
346
  Array.from(String(payload.executionInstanceId)).length > 191 ||
334
- !isInteractionTimestamp(payload.expiresAt))
347
+ (payload.expiresAt !== undefined && !isInteractionTimestamp(payload.expiresAt)))
335
348
  throw new TypeError("interaction.requested instance or expiry is invalid");
336
349
  if (payload.kind !== "approval" &&
337
350
  payload.kind !== "question" &&
@@ -340,6 +353,15 @@ export function assertCanonicalEvent(event) {
340
353
  }
341
354
  if (!isRecord(payload.request))
342
355
  throw new TypeError("interaction.requested payload.request must be an object");
356
+ if (payload.delivery !== undefined) {
357
+ if (payload.delivery !== "async" || payload.kind !== "question")
358
+ throw new TypeError("INVALID_INTERACTION_DELIVERY");
359
+ assertQuestionRequest(payload.request);
360
+ }
361
+ if ((Object.hasOwn(payload, "responseRequired") &&
362
+ typeof payload.responseRequired !== "boolean") ||
363
+ (payload.responseRequired === false && payload.kind !== "approval"))
364
+ throw new TypeError("interaction.requested responseRequired is invalid");
343
365
  if (payload.kind === "approval")
344
366
  assertApprovalRequest(payload.request);
345
367
  }
@@ -624,7 +646,7 @@ export function assertRuntimeLimits(value) {
624
646
  modelIdleWarningMs: 3_600_000,
625
647
  toolTimeoutMs: 86_400_000,
626
648
  toolWallTimeoutMs: 86_400_000,
627
- runTimeoutMs: 86_400_000,
649
+ runTimeoutMs: MAX_RUN_TIMEOUT_MS,
628
650
  cancelGraceMs: 60_000
629
651
  };
630
652
  for (const [key, setting] of Object.entries(value)) {
@@ -120,6 +120,8 @@ export function assertInvokeInput(value) {
120
120
  throw new TypeError("providerSession.sessionId must be a non-empty string");
121
121
  if (session.resumable !== undefined && typeof session.resumable !== "boolean")
122
122
  throw new TypeError("providerSession.resumable must be a boolean");
123
+ if (session.requireResume !== undefined && typeof session.requireResume !== "boolean")
124
+ throw new TypeError("providerSession.requireResume must be a boolean");
123
125
  if (session.resumeOutcome !== undefined &&
124
126
  !["new", "resumed", "fresh_fallback", "compacted"].includes(session.resumeOutcome))
125
127
  throw new TypeError("providerSession.resumeOutcome is invalid");
@@ -0,0 +1,9 @@
1
+ import type { AsyncUserInputQuestion, QuestionRequest, QuestionResponse } from "./generated/protocol-types.js";
2
+ /** 校验公开问题快照;不裁剪选项或把损坏的表单降为普通文字。 */
3
+ export declare function assertAsyncQuestions(value: unknown): asserts value is AsyncUserInputQuestion[];
4
+ /** 异步表单由交互事件授权回答;消息快照本身不代表仍有活动轮次。 */
5
+ export declare function assertQuestionRequest(value: unknown): asserts value is QuestionRequest;
6
+ /** 只校验响应形状;题目归属、漏题和排序由持有原始表单的 Adapter 核对。 */
7
+ export declare function assertQuestionResponse(value: unknown): asserts value is QuestionResponse;
8
+ /** 两条补充路径使用同一原题关联;只校验并编码数据,不解析正文或执行模板。 */
9
+ export declare function questionAnswerText(request: QuestionRequest, value: unknown): string;
@@ -0,0 +1,84 @@
1
+ import { assertJsonValue } from "./context.js";
2
+ const invalidResponse = () => Object.assign(new TypeError("INVALID_QUESTION_RESPONSE"), { code: "INVALID_QUESTION_RESPONSE" });
3
+ const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
4
+ const text = (value) => typeof value === "string" && value.trim().length > 0 && Array.from(value).length <= 4096;
5
+ const fields = (value, allowed) => Object.keys(value).every((key) => allowed.includes(key));
6
+ /** 校验公开问题快照;不裁剪选项或把损坏的表单降为普通文字。 */
7
+ export function assertAsyncQuestions(value) {
8
+ assertJsonValue(value);
9
+ if (!Array.isArray(value) ||
10
+ value.length > 50 ||
11
+ value.some((question) => !record(question) ||
12
+ !fields(question, ["title", "options"]) ||
13
+ !text(question.title) ||
14
+ !(question.options === null ||
15
+ (Array.isArray(question.options) &&
16
+ question.options.length <= 50 &&
17
+ question.options.every(text)))))
18
+ throw new TypeError("INVALID_ASYNC_QUESTIONS");
19
+ }
20
+ /** 异步表单由交互事件授权回答;消息快照本身不代表仍有活动轮次。 */
21
+ export function assertQuestionRequest(value) {
22
+ assertJsonValue(value);
23
+ if (!record(value) ||
24
+ !fields(value, ["schema", "messageId", "questions"]) ||
25
+ value.schema !== "octo.question-request/v1" ||
26
+ typeof value.messageId !== "string" ||
27
+ !value.messageId ||
28
+ !Array.isArray(value.questions) ||
29
+ !value.questions.length ||
30
+ value.questions.length > 50)
31
+ throw new TypeError("INVALID_QUESTION_REQUEST");
32
+ for (const [index, q] of value.questions.entries()) {
33
+ if (!record(q) ||
34
+ !fields(q, ["id", "title", "options", "allowCustom"]) ||
35
+ q.id !== `q:${index}` ||
36
+ q.allowCustom !== true)
37
+ throw new TypeError("INVALID_QUESTION_REQUEST");
38
+ assertAsyncQuestions([{ title: q.title, options: q.options }]);
39
+ }
40
+ }
41
+ /** 只校验响应形状;题目归属、漏题和排序由持有原始表单的 Adapter 核对。 */
42
+ export function assertQuestionResponse(value) {
43
+ try {
44
+ assertJsonValue(value);
45
+ }
46
+ catch {
47
+ throw invalidResponse();
48
+ }
49
+ if (!record(value) ||
50
+ !fields(value, ["schema", "answers"]) ||
51
+ value.schema !== "octo.question-response/v1" ||
52
+ !Array.isArray(value.answers) ||
53
+ !value.answers.length ||
54
+ value.answers.length > 50)
55
+ throw invalidResponse();
56
+ const ids = new Set();
57
+ for (const answer of value.answers) {
58
+ if (!record(answer) ||
59
+ !fields(answer, ["questionId", "text"]) ||
60
+ typeof answer.questionId !== "string" ||
61
+ !/^q:(0|[1-9][0-9]?)$/.test(answer.questionId) ||
62
+ ids.has(answer.questionId) ||
63
+ !text(answer.text))
64
+ throw invalidResponse();
65
+ ids.add(answer.questionId);
66
+ }
67
+ }
68
+ /** 两条补充路径使用同一原题关联;只校验并编码数据,不解析正文或执行模板。 */
69
+ export function questionAnswerText(request, value) {
70
+ assertQuestionRequest(request);
71
+ assertQuestionResponse(value);
72
+ if (value.answers.length !== request.questions.length ||
73
+ value.answers.some((answer) => !request.questions.some((q) => q.id === answer.questionId)))
74
+ throw invalidResponse();
75
+ return ("Answer to async user questions:\n" +
76
+ JSON.stringify({
77
+ messageId: request.messageId,
78
+ answers: request.questions.map((q) => ({
79
+ questionId: q.id,
80
+ title: q.title,
81
+ text: value.answers.find((a) => a.questionId === q.id).text
82
+ }))
83
+ }));
84
+ }