@mininglamp-oss/octo-runtime 1.1.2 → 1.1.4

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 (140) hide show
  1. package/README.md +1 -1
  2. package/apps/cli/dist/build-info.json +2 -2
  3. package/apps/cli/dist/help.js +5 -1
  4. package/apps/cli/dist/main.js +32 -6
  5. package/apps/cli/dist/manifest.json +5 -0
  6. package/apps/cli/dist/openclaw.js +32 -8
  7. package/apps/cli/dist/output.js +3 -0
  8. package/apps/cli/dist/playboard.d.ts +5 -0
  9. package/apps/cli/dist/playboard.js +41 -13
  10. package/dist/public/dsh.d.ts +2 -0
  11. package/dist/public/dsh.js +1 -0
  12. package/dist/public/executor-kernel.d.ts +1 -1
  13. package/dist/public/executor-kernel.js +1 -1
  14. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
  15. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  16. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
  17. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
  18. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  19. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  20. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  21. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  22. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
  23. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  24. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
  25. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
  26. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
  27. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
  28. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
  29. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
  30. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
  31. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
  32. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
  33. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  64. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  65. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +5 -1
  66. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +32 -6
  67. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +5 -0
  68. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
  69. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +3 -0
  70. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
  72. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -23
  73. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
  74. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
  75. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
  76. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
  77. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
  78. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  79. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
  80. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  81. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
  82. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
  83. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
  84. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
  85. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +181 -27
  86. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
  87. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
  88. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
  89. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  90. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
  91. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +167 -25
  92. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
  93. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +20 -1
  94. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
  95. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
  99. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
  100. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
  101. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
  102. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
  103. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
  104. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
  105. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
  106. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
  107. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
  108. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
  109. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
  110. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
  111. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
  112. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
  113. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
  114. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -1
  115. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
  116. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +49 -17
  117. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
  118. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.d.ts +1 -1
  119. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.js +4 -2
  120. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
  121. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +10 -7
  122. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
  123. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
  124. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
  125. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
  126. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
  127. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
  128. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
  129. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
  130. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
  131. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
  132. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
  133. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
  134. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
  135. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  136. package/package.json +35 -29
  137. package/packages/octo-runtime-extra-channel-gateway/config-schema.json +57 -1
  138. package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
  139. package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
  140. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
@@ -210,7 +210,7 @@
210
210
  },
211
211
  "allowed_sender_ids": {
212
212
  "type": "array",
213
- "description": "可选。允许触发本 Bot 的真实 Octo 发送者 ID 白名单;省略时仅允许服务端注册返回的 owner,显式名单替代默认 owner 名单,空数组拒绝所有发送者。不能使用展示名称代替身份;群/话题仍须满足真实 mention 和平台范围准入。",
213
+ "description": "可选。允许触发本 Bot 的真实 Octo 发送者 ID 白名单;省略时 DM 沿用平台好友准入,群/话题不增加发送者限制。显式非空名单仅允许列出的发送者,owner 不隐式补入,空数组拒绝全部,null 非法。自消息始终拒绝;群/话题仍须满足真实 mention、Space、启停与父群范围准入。",
214
214
  "items": {
215
215
  "type": "string",
216
216
  "minLength": 1,
@@ -231,6 +231,62 @@
231
231
  "description": "允许的群范围 ID(groupNo)。"
232
232
  }
233
233
  },
234
+ "artifact_delivery": {
235
+ "type": "object",
236
+ "additionalProperties": true,
237
+ "description": "workflow 固定产物交付,执行前通过 Context 明示。省略为 channel:成功 final 显式引用的本地文件上传为 IM 附件,普通链接同时保留正文下载链接并发送原生文件卡,图片内嵌展示;tools 保留 Agent 主动工具交付。不扫描目录或自动发布在线文档。",
238
+ "properties": {
239
+ "mode": {
240
+ "type": "string",
241
+ "enum": ["channel", "tools"],
242
+ "default": "channel",
243
+ "description": "省略启用渠道固定交付;tools 关闭 Gateway 自动上传,保留普通工具调用。"
244
+ },
245
+ "allowed_roots": {
246
+ "type": "array",
247
+ "maxItems": 32,
248
+ "description": "宿主授权的绝对产物目录;省略使用当前本地 Agent 工作区,空列表拒绝全部文件。realpath 后检查包含关系,拒绝 symlink 逃逸;远程 Provider 路径始终不可读。",
249
+ "items": {
250
+ "type": "string",
251
+ "pattern": "^(?:/|[A-Za-z]:[\\\\/]|\\\\\\\\[^\\\\/]+[\\\\/][^\\\\/]+)"
252
+ }
253
+ },
254
+ "allowed_mime_types": {
255
+ "type": "array",
256
+ "maxItems": 32,
257
+ "description": "可选精确 MIME 类型列表;省略不增加类型限制,空列表拒绝所有类型。服务端实际策略仍可拒绝;未知扩展使用 application/octet-stream。",
258
+ "items": { "type": "string", "pattern": "^[\\w.+-]+/[\\w.+-]+$" }
259
+ },
260
+ "max_file_bytes": {
261
+ "type": "integer",
262
+ "minimum": 1,
263
+ "maximum": 20971520,
264
+ "default": 20971520,
265
+ "description": "单个文件上限(字节),宿主可收紧。"
266
+ },
267
+ "max_total_bytes": {
268
+ "type": "integer",
269
+ "minimum": 1,
270
+ "maximum": 52428800,
271
+ "default": 52428800,
272
+ "description": "一次最终回复的文件总字节预算,失败上传也占预算。"
273
+ },
274
+ "max_files": {
275
+ "type": "integer",
276
+ "minimum": 1,
277
+ "maximum": 16,
278
+ "default": 16,
279
+ "description": "一次最终回复最多尝试的不同 realpath 文件数量。"
280
+ },
281
+ "timeout_ms": {
282
+ "type": "integer",
283
+ "minimum": 1,
284
+ "maximum": 30000,
285
+ "default": 30000,
286
+ "description": "整次产物准备的上传时间预算;取消、reset 和关闭可提前结束。"
287
+ }
288
+ }
289
+ },
234
290
  "cards": {
235
291
  "type": "boolean",
236
292
  "default": true,
@@ -4,7 +4,7 @@ import { shutdownDeadline, withinShutdown } from "@mininglamp-oss/octo-runtime-h
4
4
  * 管理会话、排队、取消和交互归属;平台协议交给 connector,领域业务交给发起方。
5
5
  */
6
6
  import { randomUUID } from "node:crypto";
7
- import { assertModelInputParts, failurePayload } from "@mininglamp-oss/octo-runtime-protocol";
7
+ import { assertModelInputParts, failurePayload, failureMessage } from "@mininglamp-oss/octo-runtime-protocol";
8
8
  import { ImImageInputError } from "../transport/image-input.js";
9
9
  import { performance } from "node:perf_hooks";
10
10
  import { imBotIdentity, validateImConfig } from "../lifecycle/configuration.js";
@@ -23,6 +23,7 @@ export class ImRuntime {
23
23
  dependencies;
24
24
  #processEpoch = randomUUID();
25
25
  #preparing = new Map();
26
+ #finalDeliveries = new Map();
26
27
  config;
27
28
  #connector;
28
29
  #delivery;
@@ -37,6 +38,7 @@ export class ImRuntime {
37
38
  #draining = false;
38
39
  #ownerStopped;
39
40
  #drainErrors = [];
41
+ #finishIncomplete;
40
42
  #state = "stopped";
41
43
  #reconnect;
42
44
  #connecting;
@@ -47,6 +49,7 @@ export class ImRuntime {
47
49
  #error;
48
50
  #working = 0;
49
51
  #busyNotifications = new Map();
52
+ #failureNotifications = new Map();
50
53
  #busyNotifiedAt = new Map();
51
54
  #retry = 0;
52
55
  #disconnecting;
@@ -263,10 +266,11 @@ export class ImRuntime {
263
266
  this.#reconnect = setTimeout(wake, Math.min(delayMs, 2_147_483_647));
264
267
  this.#reconnect.unref();
265
268
  }
266
- #diagnostic(code, runId) {
269
+ #diagnostic(code, runId, data = {}) {
267
270
  try {
268
271
  this.dependencies.log?.("warn", "channel.diagnostic", {
269
272
  code,
273
+ ...data,
270
274
  endpoint_id: imBotIdentity(this.config),
271
275
  ...(runId ? { run_id: runId } : {})
272
276
  });
@@ -394,11 +398,23 @@ export class ImRuntime {
394
398
  return;
395
399
  }
396
400
  let session;
401
+ // 只有 read 的同步失败属于执行前存储故障,排队、控制及后续保存不进入此分类。
397
402
  try {
398
403
  session = this.#session(key);
404
+ }
405
+ catch {
406
+ const failure = failurePayload({ code: "IM_SESSION_STORE_FAILED" }, {
407
+ stage: "channel_session_read",
408
+ defaultDomain: "runtime"
409
+ }).failure;
410
+ void this.#notifyFailure(message, failure).finally(() => this.#seen.delete(dedupe));
411
+ return;
412
+ }
413
+ try {
399
414
  if (command === "/reset" || command === "/new") {
400
415
  try {
401
416
  const binding = this.#sessionStore.reset(key, message.messageId);
417
+ this.#finalDeliveries.get(key)?.abort();
402
418
  this.#tasks.get(key)?.task.stopRetries();
403
419
  session.id = binding.id;
404
420
  session.generation = binding.generation;
@@ -420,10 +436,12 @@ export class ImRuntime {
420
436
  // 控制命令绕过普通消息队列,否则 stop 会排在待取消的长任务之后。
421
437
  const preparation = this.#preparing.get(key);
422
438
  preparation?.abort();
439
+ const delivery = this.#finalDeliveries.get(key);
440
+ delivery?.abort();
423
441
  const invocationId = session.activeInvocationId;
424
442
  void (async () => {
425
443
  const task = this.#tasks.get(key)?.task;
426
- const cancelled = preparation
444
+ const cancelled = preparation || delivery
427
445
  ? true
428
446
  : task
429
447
  ? await task.cancel()
@@ -439,7 +457,7 @@ export class ImRuntime {
439
457
  }
440
458
  catch {
441
459
  this.#seen.delete(dedupe);
442
- this.#diagnostic("IM_SESSION_STORE_FAILED");
460
+ this.#diagnostic("IM_INBOUND_PROCESSING_FAILED");
443
461
  }
444
462
  finally {
445
463
  if (session)
@@ -511,7 +529,9 @@ export class ImRuntime {
511
529
  const previous = this.#sessionStore.occurrence(key, id);
512
530
  if (previous) {
513
531
  void this.#reply(message, previous.text === message.text
514
- ? "该消息已经提交,请查看原执行结果。"
532
+ ? previous.notSubmittedFailure
533
+ ? `原消息尚未提交,请修复故障后重新发送。\n错误码:${previous.notSubmittedFailure.code}\n诊断编号:${previous.notSubmittedFailure.diagnosticId}`
534
+ : "该消息已经提交,请查看原执行结果。"
515
535
  : "消息身份冲突,请重新发送。", `duplicate:${id}`);
516
536
  return false;
517
537
  }
@@ -599,12 +619,64 @@ export class ImRuntime {
599
619
  });
600
620
  this.#busyNotifications.set(key, notification);
601
621
  }
602
- async #reply(message, text, effectKey, requireDelivered = false, final = false, allowUnknownNotice = true) {
622
+ /** 独立错误展示不复用已坏的 presentation;共享有界投递,迟到失败不触发再次执行或递归通知。 */
623
+ #notifyFailure(message, failure, identity, retry = false) {
624
+ const data = {
625
+ code: failure.code,
626
+ reason_code: failure.reasonCode,
627
+ diagnostic_id: failure.diagnosticId,
628
+ stage: failure.stage,
629
+ failure_component: failure.source.component,
630
+ occurred_at: failure.occurredAt,
631
+ ...(failure.source.adapter ? { adapter_type: failure.source.adapter } : {}),
632
+ ...(identity ? { invocation_id: identity.invocationId, session_id: identity.sessionId } : {})
633
+ };
634
+ this.#diagnostic(failure.reasonCode, identity?.runId, data);
635
+ if (this.#failureNotifications.size >= 64 || this.#closed || !this.#delivery)
636
+ return Promise.resolve();
637
+ const until = shutdownDeadline(this.dependencies.signal);
638
+ const effect = `failure:${message.messageId}:${failure.diagnosticId}`;
639
+ const text = `${retry ? "本次重试未提交,之前的执行记录仍须核查。" : failureMessage(failure.code)}\n错误码:${failure.code}\n诊断编号:${failure.diagnosticId}`;
640
+ const event = {
641
+ protocolVersion: 2,
642
+ type: "run.failed",
643
+ payload: { code: failure.reasonCode, message: text, failure }
644
+ };
645
+ const delivery = this.#delivery;
646
+ const options = { transient: true, obsolete: () => this.#closed || performance.now() >= until };
647
+ const secondary = (code) => {
648
+ this.#diagnostic(code, identity?.runId, {
649
+ ...data,
650
+ code,
651
+ reason_code: code,
652
+ primary_code: failure.code
653
+ });
654
+ if (this.#draining)
655
+ this.#drainErrors.push(new Error(code));
656
+ };
657
+ const send = async (operation, key) => {
658
+ const receipt = await delivery.deliver(key, operation, options);
659
+ if (receipt.state !== "delivered")
660
+ secondary(receipt.code ?? "IM_DELIVERY_FAILED");
661
+ };
662
+ const notification = withinShutdown(Promise.allSettled([
663
+ ...(message.replyFailure ? [send(() => message.replyFailure(event, effect), effect)] : []),
664
+ send(() => message.reply(text, `${effect}:text`), `${effect}:text`)
665
+ ]), until, "IM_DELIVERY_UNKNOWN")
666
+ .then(() => undefined)
667
+ .catch(() => secondary("IM_DELIVERY_UNKNOWN"))
668
+ .finally(() => this.#failureNotifications.delete(failure.diagnosticId));
669
+ this.#failureNotifications.set(failure.diagnosticId, notification);
670
+ return notification;
671
+ }
672
+ async #reply(message, text, effectKey, requireDelivered = false, final = false, allowUnknownNotice = true, finalOptions) {
603
673
  if (this.#closed || this.#signal.aborted || !this.#delivery)
604
674
  return;
605
675
  const receipt = await this.#delivery.deliver(effectKey, () => final && message.replyFinal
606
- ? message.replyFinal(text, effectKey)
607
- : message.reply(text, effectKey));
676
+ ? message.replyFinal(text, effectKey, finalOptions)
677
+ : message.reply(text, effectKey), { obsolete: finalOptions ? () => finalOptions.obsolete() : undefined });
678
+ if (finalOptions?.obsolete())
679
+ return;
608
680
  if (receipt.state !== "delivered") {
609
681
  if (this.#draining)
610
682
  this.#drainErrors.push(new Error(receipt.code ?? "IM_DELIVERY_FAILED"));
@@ -868,10 +940,15 @@ export class ImRuntime {
868
940
  });
869
941
  const controls = this.#runControls(message, key, request.invocationId);
870
942
  let presentation;
943
+ let executionStarted = false;
944
+ let presentationFailed = false;
945
+ let localFailure;
946
+ const delivery = new AbortController();
871
947
  try {
872
948
  presentation = message.beginPresentation?.(rootRunId, (code) => this.#diagnostic(code, rootRunId), controls);
873
949
  presentation?.update(snapshot());
874
950
  session.activeInvocationId = request.invocationId;
951
+ executionStarted = true;
875
952
  for await (const event of task.events()) {
876
953
  if (this.#closed || this.#signal.aborted)
877
954
  break;
@@ -925,7 +1002,8 @@ export class ImRuntime {
925
1002
  const interaction = event.payload;
926
1003
  let cardShown = false;
927
1004
  try {
928
- cardShown = (await presentation?.interaction?.(interaction)) ?? false;
1005
+ cardShown =
1006
+ !presentationFailed && ((await presentation?.interaction?.(interaction)) ?? false);
929
1007
  }
930
1008
  catch {
931
1009
  this.#diagnostic("IM_INTERACTION_CARD_FAILED", request.runId);
@@ -940,12 +1018,13 @@ export class ImRuntime {
940
1018
  ? `/approve ${interaction.interactionId} 或 /decline ${interaction.interactionId}`
941
1019
  : `/respond ${interaction.interactionId} ${interaction.kind === "elicitation" ? "<JSON>" : "<回答>"}`;
942
1020
  if (!cardShown)
943
- await this.#reply(message, `${summary?.slice(0, 1000) ?? "执行需要你的确认或输入。"}\n${Array.isArray(interaction.request.questions) ? JSON.stringify(interaction.request.questions).slice(0, 8000) + "\n请按问题 ID 提交 JSON 答案。\n" : ""}${instruction}`, `interaction:${interaction.interactionId}`);
1021
+ await this.#reply(message, `${summary?.slice(0, 1000) ?? "执行需要你的确认或输入。"}\n${Array.isArray(interaction.request.questions) ? JSON.stringify(interaction.request.questions).slice(0, 8000) + "\n请按问题 ID 提交 JSON 答案。\n" : ""}${instruction}`, `interaction:${interaction.interactionId}`, true);
944
1022
  }
945
1023
  if (event.type === "interaction.resolved") {
946
1024
  this.#interactions.delete(event.payload.interactionId);
947
1025
  try {
948
- await presentation?.resolveInteraction?.(event.payload.interactionId, event.payload.status);
1026
+ if (!presentationFailed)
1027
+ await presentation?.resolveInteraction?.(event.payload.interactionId, event.payload.status);
949
1028
  }
950
1029
  catch {
951
1030
  this.#diagnostic("IM_INTERACTION_CARD_FAILED", request.runId);
@@ -953,13 +1032,37 @@ export class ImRuntime {
953
1032
  }
954
1033
  projector.accept(event);
955
1034
  controls.failed = projector.snapshot().terminal === "failed";
956
- presentation?.update(snapshot());
1035
+ if (!presentationFailed) {
1036
+ try {
1037
+ presentation?.update(snapshot());
1038
+ }
1039
+ catch {
1040
+ presentationFailed = true;
1041
+ this.#finalizationFailed("IM_PRESENTATION_FAILED", request.runId);
1042
+ // 展示故障不关闭原迭代器;请求停止后仍由同一消费者确认真实终态。
1043
+ if (!projector.snapshot().terminal)
1044
+ void task
1045
+ .cancelExecution("IM presentation failed")
1046
+ .catch(() => this.#diagnostic("IM_CANCEL_FAILED", request.runId));
1047
+ }
1048
+ }
957
1049
  }
958
1050
  if (!projector.snapshot().terminal)
959
1051
  throw new Error("IM_RUN_WITHOUT_TERMINAL");
960
1052
  }
961
1053
  catch {
962
- if (!projector.snapshot().terminal) {
1054
+ if (!executionStarted || task.notSubmittedFailure) {
1055
+ localFailure =
1056
+ task.notSubmittedFailure ??
1057
+ failurePayload({ code: "IM_PRESENTATION_INITIALIZATION_FAILED" }, {
1058
+ stage: "channel_presentation_initialize",
1059
+ defaultDomain: "runtime",
1060
+ runId: request.runId
1061
+ }).failure;
1062
+ controls.failed = false;
1063
+ await this.#notifyFailure(message, localFailure, request, task.attempts.length > 1);
1064
+ }
1065
+ else {
963
1066
  if (this.#draining)
964
1067
  this.#drainErrors.push(new Error("IM_EXECUTION_RESULT_UNKNOWN"));
965
1068
  // 流断开无法证明执行失败;尽力取消并提示核查,不自动重跑潜在的业务副作用。
@@ -967,10 +1070,18 @@ export class ImRuntime {
967
1070
  .cancelInvocation(request.invocationId, "IM execution stream failed")
968
1071
  .catch(() => undefined);
969
1072
  this.#diagnostic("IM_EXECUTION_RESULT_UNKNOWN", request.runId);
970
- presentation?.update({ ...snapshot(), resultUnknown: true });
1073
+ // 原源流即使在终态后失败,也不能被展示层的终态掩盖。
1074
+ controls.failed = false;
1075
+ projector = new ImRunProjector(rootRunId, message.conversationKind === "direct");
1076
+ if (!presentationFailed) {
1077
+ try {
1078
+ presentation?.update({ ...snapshot(), resultUnknown: true });
1079
+ }
1080
+ catch {
1081
+ this.#finalizationFailed("IM_PRESENTATION_FAILED", request.runId);
1082
+ }
1083
+ }
971
1084
  }
972
- else if (this.#draining)
973
- this.#drainErrors.push(new Error("IM_RUN_FINALIZATION_FAILED"));
974
1085
  }
975
1086
  finally {
976
1087
  if (rulesEnabled)
@@ -996,8 +1107,11 @@ export class ImRuntime {
996
1107
  run_id: rootRunId,
997
1108
  invocation_id: request.invocationId,
998
1109
  session_id: request.sessionId,
999
- status: projector.snapshot().terminal ?? "unknown"
1110
+ status: localFailure ? "not_submitted" : (projector.snapshot().terminal ?? "unknown")
1000
1111
  });
1112
+ // 移除执行身份前移交收尾/产物投递的取消权;finish 等待期间的 stop 不能落入空窗。
1113
+ if (!localFailure)
1114
+ this.#finalDeliveries.set(key, delivery);
1001
1115
  this.#tasks.delete(key);
1002
1116
  try {
1003
1117
  // 长任务结束后重新开始终态去重窗口,保留有界尝试身份,避免立即重复执行。
@@ -1008,7 +1122,11 @@ export class ImRuntime {
1008
1122
  sessionId: request.sessionId,
1009
1123
  runId: rootRunId,
1010
1124
  snapshot: saved,
1011
- attempts: task.attempts.map((attempt) => ({ ...attempt }))
1125
+ attempts: task.attempts.map((attempt) => ({ ...attempt })),
1126
+ ...(localFailure &&
1127
+ task.attempts.every((attempt) => attempt.outcome === "not_submitted")
1128
+ ? { notSubmittedFailure: localFailure }
1129
+ : {})
1012
1130
  });
1013
1131
  }
1014
1132
  catch {
@@ -1020,17 +1138,38 @@ export class ImRuntime {
1020
1138
  this.#interactions.delete(id);
1021
1139
  try {
1022
1140
  if (!this.#closed)
1023
- await presentation?.finish();
1141
+ await withinShutdown(Promise.resolve().then(() => presentation?.finish()), shutdownDeadline(this.dependencies.signal), "IM_PRESENTATION_FINISH_INCOMPLETE");
1024
1142
  }
1025
- catch {
1143
+ catch (error) {
1144
+ // 截止只结束等待,不能证明尚未完成的展示资源已经释放。
1145
+ if (error instanceof Error && error.message === "IM_PRESENTATION_FINISH_INCOMPLETE")
1146
+ this.#finishIncomplete ??= error;
1026
1147
  this.#finalizationFailed("IM_PRESENTATION_FAILED", request.runId);
1027
1148
  }
1028
1149
  }
1029
- if (this.#closed || this.#signal.aborted)
1030
- return;
1031
- const { text, allowMention } = projector.finalReply;
1032
- // 最终文本拥有独立投递身份,即使进度卡投递失败,也必须尝试回复用户。
1033
- await this.#reply(message, text, `final:${rootRunId}`, false, allowMention, projector.snapshot().terminal !== "cancelled");
1150
+ try {
1151
+ if (localFailure || this.#closed || this.#signal.aborted || delivery.signal.aborted)
1152
+ return;
1153
+ const { text, allowMention } = projector.finalReply;
1154
+ const obsolete = () => {
1155
+ const binding = this.#sessionStore.read(key);
1156
+ return (binding?.id !== request.sessionId || binding.generation !== request.sessionGeneration);
1157
+ };
1158
+ // reset 不取消原模型执行,但旧代次的结果不能启动上传或继续最终消息重试。
1159
+ if (allowMention && obsolete())
1160
+ return;
1161
+ const deliverySignal = AbortSignal.any([this.#signal, delivery.signal]);
1162
+ // 最终文本拥有独立投递身份,即使进度卡投递失败,也必须尝试回复用户。
1163
+ await this.#reply(message, text, `final:${rootRunId}`, false, allowMention, projector.snapshot().terminal !== "cancelled", {
1164
+ artifacts: prepared.artifacts,
1165
+ signal: deliverySignal,
1166
+ obsolete: () => deliverySignal.aborted || (allowMention && obsolete())
1167
+ });
1168
+ }
1169
+ finally {
1170
+ if (this.#finalDeliveries.get(key) === delivery)
1171
+ this.#finalDeliveries.delete(key);
1172
+ }
1034
1173
  }
1035
1174
  #saveBinding(key, session) {
1036
1175
  if (this.#closed)
@@ -1104,11 +1243,14 @@ export class ImRuntime {
1104
1243
  attempt(() => this.#connector?.close()),
1105
1244
  attempt(() => this.#connecting),
1106
1245
  attempt(() => this.#disconnecting),
1246
+ ...[...this.#failureNotifications.values()].map((notification) => attempt(() => notification)),
1107
1247
  ...[...this.#busyNotifications.values()].map((notification) => attempt(() => notification))
1108
1248
  ]);
1109
1249
  if (!this.dependencies.sessions)
1110
1250
  await attempt(() => this.#sessionStore.close?.());
1111
1251
  errors.push(...this.#drainErrors);
1252
+ if (this.#finishIncomplete)
1253
+ errors.push(this.#finishIncomplete);
1112
1254
  if (errors.length)
1113
1255
  throw new AggregateError(errors, "IM_DISPOSE_FAILED");
1114
1256
  this.#sessions.clear();
@@ -1,5 +1,5 @@
1
1
  import type { ImInvocationInput } from "../execution/dispatcher.js";
2
- import type { ProviderSession } from "@mininglamp-oss/octo-runtime-protocol";
2
+ import type { FailureEnvelope, ProviderSession } from "@mininglamp-oss/octo-runtime-protocol";
3
3
  import type { ImTaskAttempt } from "../contracts.js";
4
4
  import type { ImGapMetadata, ImGapTurnToken } from "./context-gap.js";
5
5
  import type { ImRulesContext } from "./rules-context.js";
@@ -9,6 +9,8 @@ export interface ImSessionOccurrence {
9
9
  runId: string;
10
10
  snapshot?: ImInvocationInput;
11
11
  attempts?: ImTaskAttempt[];
12
+ /** 仅整轮没有已执行或未知尝试时保存;旧记录缺省不推测执行事实。 */
13
+ notSubmittedFailure?: FailureEnvelope;
12
14
  }
13
15
  export interface ImSessionBinding {
14
16
  id?: string;
@@ -4,6 +4,7 @@
4
4
  import type { ApprovalMode, ContextEnvelope, ContextItem, CanonicalEvent, InteractionResponse, InteractionRequestedPayload, InvokeEnvironment, ModelInputPart, ProviderSession } from "@mininglamp-oss/octo-runtime-protocol";
5
5
  import type { RunPresentation } from "./presentation/run-projector.js";
6
6
  import type { ImGapPlan, ImGapTurnToken } from "./application/context-gap.js";
7
+ import type { ImArtifactPolicy } from "./delivery/artifact-policy.js";
7
8
  export interface ImPositionObservation {
8
9
  conversationId: string;
9
10
  conversationKind: "group" | "thread";
@@ -35,6 +36,7 @@ export interface ImCommonConfig {
35
36
  initial_delay_ms?: number;
36
37
  max_delay_ms?: number;
37
38
  };
39
+ /** 省略沿用平台消息准入;显式名单限制所有频道,空数组拒绝全部发送者。 */
38
40
  allowed_sender_ids?: string[];
39
41
  }
40
42
  export interface OctoBotConfig extends ImCommonConfig {
@@ -46,6 +48,22 @@ export interface OctoBotConfig extends ImCommonConfig {
46
48
  group_ids?: string[] | null;
47
49
  cards?: boolean;
48
50
  typing?: boolean;
51
+ /** 渠道固定产物交付;由宿主配置,模型 Context 不能扩大文件访问范围。 */
52
+ artifact_delivery?: {
53
+ mode?: "channel" | "tools";
54
+ allowed_roots?: string[];
55
+ allowed_mime_types?: string[];
56
+ max_file_bytes?: number;
57
+ max_total_bytes?: number;
58
+ max_files?: number;
59
+ timeout_ms?: number;
60
+ };
61
+ }
62
+ /** 成功 final 的冻结投递合同;signal 归当前交付所有,不能复用已终态的模型 signal。 */
63
+ export interface ImFinalReplyOptions {
64
+ artifacts: ImArtifactPolicy;
65
+ signal: AbortSignal;
66
+ obsolete(): boolean;
49
67
  }
50
68
  export type ImBotConfig = OctoBotConfig;
51
69
  /** Authenticated scope, resolved from octo-auth rather than caller configuration. */
@@ -68,7 +86,7 @@ export interface ImInboundMessage {
68
86
  text: string;
69
87
  buildInputs?(signal: AbortSignal): Promise<ModelInputPart[]>;
70
88
  reply(text: string, effectKey?: string): Promise<void>;
71
- replyFinal?(text: string, effectKey: string): Promise<void>;
89
+ replyFinal?(text: string, effectKey: string, options?: ImFinalReplyOptions): Promise<void>;
72
90
  replyFailure?(event: CanonicalEvent, effectKey: string): Promise<void>;
73
91
  replyDeliveryUnknown?(event: CanonicalEvent, effectKey: string, replyEffectKey: string, signal: AbortSignal): Promise<void>;
74
92
  isReplyDelivered?(effectKey: string): boolean;
@@ -98,6 +116,7 @@ export interface ImRunControls {
98
116
  export interface ImTaskAttempt {
99
117
  runId: string;
100
118
  invocationId: string;
119
+ /** not_submitted 是本次调用事实,不是 Provider 执行终态或整轮未执行的证明。 */
101
120
  outcome: string;
102
121
  failureCode?: string;
103
122
  diagnosticId?: string;
@@ -0,0 +1,23 @@
1
+ import type { ContextEnvelope, ContextItem } from "@mininglamp-oss/octo-runtime-protocol";
2
+ import type { OctoBotConfig } from "../contracts.js";
3
+ export interface ImArtifactPolicy {
4
+ mode: "channel" | "tools";
5
+ workspace?: string;
6
+ local: boolean;
7
+ roots: string[];
8
+ mimeTypes?: string[];
9
+ maxFileBytes: number;
10
+ maxTotalBytes: number;
11
+ maxFiles: number;
12
+ timeoutMs: number;
13
+ }
14
+ export declare const ARTIFACT_LIMITS: {
15
+ readonly max_file_bytes: number;
16
+ readonly max_total_bytes: number;
17
+ readonly max_files: 16;
18
+ readonly timeout_ms: 30000;
19
+ };
20
+ /** 从可信配置及实际执行目录派生合同;远程 preset 的同名主机路径永不成为可读产物。 */
21
+ export declare function artifactPolicy(config: OctoBotConfig, context: ContextEnvelope, local: boolean): ImArtifactPolicy;
22
+ /** 在执行前向模型明示两种行为;这里只传递约定,不接受模型改写后的访问授权。 */
23
+ export declare function artifactContext(policy: ImArtifactPolicy): ContextItem;
@@ -0,0 +1,43 @@
1
+ export const ARTIFACT_LIMITS = {
2
+ max_file_bytes: 20 * 1024 * 1024,
3
+ max_total_bytes: 50 * 1024 * 1024,
4
+ max_files: 16,
5
+ timeout_ms: 30_000
6
+ };
7
+ /** 从可信配置及实际执行目录派生合同;远程 preset 的同名主机路径永不成为可读产物。 */
8
+ export function artifactPolicy(config, context, local) {
9
+ const options = config.artifact_delivery;
10
+ const workspace = context.items.find((item) => item.namespace === "octo.execution" && item.name === "workspace")?.payload.path;
11
+ return {
12
+ mode: options?.mode ?? "channel",
13
+ ...(typeof workspace === "string" ? { workspace } : {}),
14
+ local,
15
+ roots: [...(options?.allowed_roots ?? (typeof workspace === "string" ? [workspace] : []))],
16
+ ...(options?.allowed_mime_types ? { mimeTypes: [...options.allowed_mime_types] } : {}),
17
+ maxFileBytes: options?.max_file_bytes ?? ARTIFACT_LIMITS.max_file_bytes,
18
+ maxTotalBytes: options?.max_total_bytes ?? ARTIFACT_LIMITS.max_total_bytes,
19
+ maxFiles: options?.max_files ?? ARTIFACT_LIMITS.max_files,
20
+ timeoutMs: options?.timeout_ms ?? ARTIFACT_LIMITS.timeout_ms
21
+ };
22
+ }
23
+ /** 在执行前向模型明示两种行为;这里只传递约定,不接受模型改写后的访问授权。 */
24
+ export function artifactContext(policy) {
25
+ return {
26
+ namespace: "extra.im",
27
+ name: "artifact-delivery",
28
+ guidance: policy.mode === "channel"
29
+ ? "This channel delivers generated local output files referenced in your successful final reply. Create outputs in the effective workspace and use Markdown links or images (including reference style). Gateway's deterministic delivery workflow uploads accessible, policy-allowed files as IM attachments, rewrites their targets and sends native file cards for ordinary file links alongside this same final reply. Display image outputs inline with ![alt](path); a plain download link alone is not image delivery. Images alone do not add file cards. Offer a separate image download link only when requested. This workflow does not publish HTML, create online documents, grant document permissions or save to Drive. Explicit user requests to upload, publish, collaborate on an online document or perform another business action still use your normal tool calls; preserve their returned remote URLs. Do not send a duplicate final reply with a messaging tool. Code, quoted examples, and directory contents are not collected. Remote provider files cannot be retrieved by Gateway."
30
+ : "This channel does not automatically upload output files. Use normal tool calls when the task requires file delivery and return recipient-accessible URLs. Do not present runtime-local paths as downloadable attachments. Do not send a duplicate final reply with a messaging tool.",
31
+ payload: {
32
+ mode: policy.mode,
33
+ localWorkspaceAccessible: policy.local,
34
+ ...(policy.workspace ? { workspace: policy.workspace } : {}),
35
+ allowedRoots: policy.roots,
36
+ ...(policy.mimeTypes ? { allowedMimeTypes: policy.mimeTypes } : {}),
37
+ maxFileBytes: policy.maxFileBytes,
38
+ maxTotalBytes: policy.maxTotalBytes,
39
+ maxFiles: policy.maxFiles,
40
+ timeoutMs: policy.timeoutMs
41
+ }
42
+ };
43
+ }
@@ -0,0 +1,15 @@
1
+ import type { ImArtifactPolicy } from "./artifact-policy.js";
2
+ export type ArtifactUpload = (bytes: Uint8Array, filename: string, mime: string, signal: AbortSignal) => Promise<string>;
3
+ /** 已核验并上传的文件元数据;不向发送层暴露本机路径。 */
4
+ export interface ArtifactFile {
5
+ url: string;
6
+ name: string;
7
+ size: number;
8
+ extension: string;
9
+ }
10
+ export interface PreparedArtifacts {
11
+ text: string;
12
+ files: ArtifactFile[];
13
+ }
14
+ /** 只交付成功 final 的显式引用;失败不改变生成终态,缓存由 transport 的 final effect 闭包持有。 */
15
+ export declare function prepareArtifacts(text: string, policy: ImArtifactPolicy, ownerSignal: AbortSignal, upload: ArtifactUpload): Promise<PreparedArtifacts>;