@mininglamp-oss/octo-runtime 1.1.3 → 1.1.5

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 (214) hide show
  1. package/README.md +62 -38
  2. package/apps/cli/README.md +58 -22
  3. package/apps/cli/dist/build-info.json +2 -2
  4. package/apps/cli/dist/cli-entrypoint.d.ts +2 -0
  5. package/apps/cli/dist/cli-entrypoint.js +16 -0
  6. package/apps/cli/dist/command-tree.d.ts +20 -0
  7. package/apps/cli/dist/command-tree.js +402 -0
  8. package/apps/cli/dist/extra-command-config.d.ts +4 -0
  9. package/apps/cli/dist/extra-command-config.js +50 -0
  10. package/apps/cli/dist/extra-commands.d.ts +15 -0
  11. package/apps/cli/dist/extra-commands.js +275 -0
  12. package/apps/cli/dist/extras.js +14 -2
  13. package/apps/cli/dist/global-extras.d.ts +16 -0
  14. package/apps/cli/dist/global-extras.js +201 -0
  15. package/apps/cli/dist/help.d.ts +4 -1
  16. package/apps/cli/dist/help.js +31 -75
  17. package/apps/cli/dist/main.d.ts +2 -0
  18. package/apps/cli/dist/main.js +53 -63
  19. package/apps/cli/dist/manifest.json +53 -3
  20. package/apps/cli/dist/module-manifest.d.ts +1 -1
  21. package/apps/cli/dist/module-manifest.js +3 -2
  22. package/apps/cli/dist/openclaw.js +32 -8
  23. package/apps/cli/dist/output.js +16 -2
  24. package/apps/cli/dist/playboard.d.ts +5 -0
  25. package/apps/cli/dist/playboard.js +41 -13
  26. package/apps/cli/dist/service-control.js +2 -2
  27. package/apps/cli/dist/state.js +48 -19
  28. package/dist/public/channel-gateway-commands.d.ts +1 -0
  29. package/dist/public/channel-gateway-commands.js +1 -0
  30. package/dist/public/channel-wecom-commands.d.ts +1 -0
  31. package/dist/public/channel-wecom-commands.js +1 -0
  32. package/dist/public/dsh.d.ts +2 -0
  33. package/dist/public/dsh.js +1 -0
  34. package/dist/public/executor-kernel.d.ts +1 -1
  35. package/dist/public/executor-kernel.js +1 -1
  36. package/dist/public/extra.d.ts +1 -0
  37. package/dist/public/extra.js +1 -0
  38. package/dist/public/host.d.ts +2 -4
  39. package/dist/public/host.js +1 -2
  40. package/dist/public/webui-commands.d.ts +1 -0
  41. package/dist/public/webui-commands.js +1 -0
  42. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
  43. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
  64. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
  65. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
  67. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
  68. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
  69. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
  70. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  71. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  72. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  73. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  74. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  75. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
  76. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
  77. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  78. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  79. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  80. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
  81. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
  82. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
  83. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
  84. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
  85. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
  86. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
  87. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +6 -0
  88. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +16 -4
  89. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
  90. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
  91. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  92. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
  93. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  94. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  95. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.d.ts +2 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/cli-entrypoint.js +16 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.d.ts +20 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +402 -0
  99. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.d.ts +4 -0
  100. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-command-config.js +50 -0
  101. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.d.ts +15 -0
  102. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extra-commands.js +275 -0
  103. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +14 -2
  104. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.d.ts +16 -0
  105. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/global-extras.js +201 -0
  106. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.d.ts +4 -1
  107. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +31 -75
  108. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
  109. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +53 -63
  110. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +53 -3
  111. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +1 -1
  112. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +3 -2
  113. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
  114. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +16 -2
  115. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
  116. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
  117. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/service-control.js +2 -2
  118. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -19
  119. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +25 -23
  120. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
  121. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
  122. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
  123. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
  124. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
  125. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  126. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
  127. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  128. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
  129. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
  130. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
  131. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
  132. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +152 -21
  133. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
  134. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
  135. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
  136. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  137. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
  138. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +170 -28
  139. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
  140. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.d.ts +4 -0
  141. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/commands.js +124 -0
  142. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +19 -1
  143. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
  144. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
  145. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
  146. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
  147. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
  148. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
  149. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
  150. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
  151. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
  152. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
  153. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
  154. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
  155. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
  156. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
  157. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
  158. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
  159. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
  160. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
  161. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
  162. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
  163. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.d.ts +1 -1
  164. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +4 -3
  165. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
  166. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +44 -13
  167. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.d.ts +7 -0
  168. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +44 -3
  169. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
  170. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
  171. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +18 -12
  172. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +10 -6
  173. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
  174. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
  175. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.d.ts +4 -0
  176. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/commands.js +128 -0
  177. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +9 -5
  178. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.d.ts +3 -0
  179. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/commands.js +51 -0
  180. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
  181. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
  182. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +7 -3
  183. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.d.ts +70 -0
  184. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-commands.js +16 -0
  185. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
  186. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
  187. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -3
  188. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +1 -2
  189. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +8 -4
  190. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
  191. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
  192. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
  193. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  194. package/node_modules/commander/LICENSE +22 -0
  195. package/node_modules/commander/Readme.md +1172 -0
  196. package/node_modules/commander/index.js +21 -0
  197. package/node_modules/commander/lib/argument.js +147 -0
  198. package/node_modules/commander/lib/command.js +2790 -0
  199. package/node_modules/commander/lib/error.js +36 -0
  200. package/node_modules/commander/lib/help.js +731 -0
  201. package/node_modules/commander/lib/option.js +377 -0
  202. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  203. package/node_modules/commander/package-support.json +19 -0
  204. package/node_modules/commander/package.json +64 -0
  205. package/node_modules/commander/typings/index.d.ts +1113 -0
  206. package/package.json +49 -29
  207. package/packages/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
  208. package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
  209. package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
  210. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
  211. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.d.ts +0 -15
  212. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/launch.js +0 -22
  213. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.d.ts +0 -16
  214. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/native.js +0 -160
@@ -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;
@@ -196,7 +199,7 @@ export class ImRuntime {
196
199
  const failure = connectionFailure(error);
197
200
  this.#connectionAbort.abort();
198
201
  this.#error = failure.message;
199
- // Offline startup and later disconnects share recovery; only error semantics decide eligibility.
202
+ // 首次离线与后续断线共用恢复;服务端断开不等于永久拒绝,由传输分类决定资格。
200
203
  const retry = failure.retryable;
201
204
  this.#state = retry ? "retrying" : "failed";
202
205
  this.#log("channel.connection_failed", { state: this.#state, code: failure.message });
@@ -214,12 +217,12 @@ export class ImRuntime {
214
217
  }
215
218
  }
216
219
  #lostConnection(connector, failure) {
217
- this.#log("channel.disconnected", { code: failure.message });
218
220
  this.#error = failure.message;
219
221
  const retry = failure.retryable;
220
222
  this.#state = retry ? "retrying" : "failed";
223
+ this.#log("channel.disconnected", { state: this.#state, code: failure.message });
221
224
  this.#connectionAbort?.abort();
222
- // Reap the old connection before backoff; shutdown and stale callbacks cannot create a second owner.
225
+ // 先回收旧连接再开始退避;关闭和旧回调不能再创建连接,回收失败须单独诊断。
223
226
  this.#disconnecting = connector.close();
224
227
  void this.#disconnecting.then(() => {
225
228
  if (retry)
@@ -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;
@@ -0,0 +1,4 @@
1
+ import { type ExtraCommandExtension } from "@mininglamp-oss/octo-runtime-host-sdk/extra-commands";
2
+ /** 单 Bot 配置命令按 bot_id upsert;省略字段保留,重复调用不会追加相同 Bot。 */
3
+ declare const extension: ExtraCommandExtension;
4
+ export default extension;
@@ -0,0 +1,124 @@
1
+ import { ExtraCommandError, savedConfigResult } from "@mininglamp-oss/octo-runtime-host-sdk/extra-commands";
2
+ import { validateImBots } from "./lifecycle/configuration.js";
3
+ /** 离线业务校验复用运行时 Bot 合同;不认证、不构造 manager 或服务。 */
4
+ function validate(config) {
5
+ try {
6
+ validateImBots(config.bots ?? []);
7
+ const spaces = config.authorized_space_ids;
8
+ if (spaces !== undefined &&
9
+ (!Array.isArray(spaces) || spaces.some((id) => typeof id !== "string" || !id.trim())))
10
+ throw new Error("IM_AUTHORIZED_SPACES_INVALID");
11
+ const settings = config.context_loading;
12
+ if (settings !== undefined) {
13
+ if (!settings ||
14
+ typeof settings !== "object" ||
15
+ Array.isArray(settings) ||
16
+ Object.keys(settings).some((key) => !["timeout_ms", "max_in_flight"].includes(key)))
17
+ throw new Error("IM_CONTEXT_LOADING_CONFIG_INVALID");
18
+ for (const [key, max] of [
19
+ ["timeout_ms", 30000],
20
+ ["max_in_flight", 32]
21
+ ]) {
22
+ const value = settings[key];
23
+ if (value !== undefined &&
24
+ (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > max))
25
+ throw new Error("IM_CONTEXT_LOADING_CONFIG_INVALID");
26
+ }
27
+ }
28
+ }
29
+ catch (error) {
30
+ const hints = {
31
+ IM_BOT_ID_REQUIRED: "Provide a non-empty --bot_id (JSON: bots[].bot_id).",
32
+ IM_ADAPTER_REQUIRED: "Each Bot requires an adapter object; configure maps --adapter_type/--workdir to it.",
33
+ IM_WORKDIR_ABSOLUTE_REQUIRED: "Provide an absolute --workdir for a local adapter.",
34
+ IM_OPENCLAW_WORKDIR_UNSUPPORTED: "OpenClaw uses its own workspace; remove config.bots[].adapter.workdir using extraset.",
35
+ IM_PROVIDER_AGENT_ID_UNSUPPORTED: "--provider_agent_id is supported only by OpenClaw.",
36
+ IM_API_URL_INVALID: "Use a valid endpoint URL without credentials, query or fragment; insecure URLs are loopback-only.",
37
+ IM_BOT_DUPLICATED: "Duplicate Bot identity in bots; keep one entry per endpoint and bot_id.",
38
+ IM_CONFIG_LIST_REQUIRED: "bots must be an array within this Extra's Bot limit.",
39
+ IM_AUTHORIZED_SPACES_INVALID: "authorized_space_ids must contain non-empty strings.",
40
+ IM_CONTEXT_LOADING_CONFIG_INVALID: "context_loading accepts timeout_ms (1..30000) and max_in_flight (1..32)."
41
+ };
42
+ const code = error instanceof Error && Object.hasOwn(hints, error.message)
43
+ ? error.message
44
+ : "EXTRA_CONFIG_INVALID";
45
+ throw new ExtraCommandError(code, hints[code] ??
46
+ "Invalid Bot configuration. Check configure --help and this Extra's configuration schema.");
47
+ }
48
+ }
49
+ /** 单 Bot 配置命令按 bot_id upsert;省略字段保留,重复调用不会追加相同 Bot。 */
50
+ const extension = {
51
+ apiVersion: 1,
52
+ commands: [
53
+ {
54
+ name: "configure",
55
+ description: "Add or update one Bot by bot_id; saves config only",
56
+ options: [
57
+ { name: "bot_id", type: "string", required: true, description: "Platform Bot ID" },
58
+ { name: "api_url", type: "string", required: true, description: "Octo API base URL" },
59
+ {
60
+ name: "adapter_type",
61
+ type: "string",
62
+ description: "Execution adapter type (adapter.adapter_type)"
63
+ },
64
+ { name: "workdir", type: "string", description: "Absolute local execution directory" },
65
+ { name: "model", type: "string", description: "Provider model ID" },
66
+ {
67
+ name: "effort",
68
+ type: "string",
69
+ description: "Reasoning effort: low, medium, high, xhigh"
70
+ },
71
+ { name: "provider_agent_id", type: "string", description: "Existing OpenClaw Agent ID" },
72
+ {
73
+ name: "bf_token",
74
+ type: "string",
75
+ description: "Raw credential (bots[].bf_token); omitted values are preserved"
76
+ }
77
+ ],
78
+ examples: [
79
+ "octo-runtime channel-gateway configure --bot_id assistant --api_url https://im.example.com/api --adapter_type codex --bf_token EXAMPLE_CREDENTIAL"
80
+ ],
81
+ async run(context, input) {
82
+ const snapshot = await context.readConfig();
83
+ validate(snapshot.config);
84
+ const bots = snapshot.config.bots ?? [];
85
+ validateImBots(bots);
86
+ const identityFields = {
87
+ bot_id: input.options["bot_id"],
88
+ api_url: input.options["api_url"]
89
+ };
90
+ // configure 用 bot_id 定位,更新 endpoint 不产生第二个 Bot。
91
+ // 旧 extraset 可能含跨 endpoint 的同名 Bot:保留首项未提供的字段,合并为一项。
92
+ const position = bots.findIndex((bot) => bot.bot_id === identityFields.bot_id);
93
+ const old = position < 0 ? undefined : bots[position];
94
+ const adapter = { ...old?.adapter };
95
+ for (const field of ["adapter_type", "workdir", "model", "effort", "provider_agent_id"]) {
96
+ const value = input.options[field];
97
+ if (typeof value === "string")
98
+ adapter[field] = value;
99
+ }
100
+ if (adapter.effort !== undefined &&
101
+ (typeof adapter.effort !== "string" ||
102
+ !["low", "medium", "high", "xhigh"].includes(adapter.effort)))
103
+ throw new ExtraCommandError("EXTRA_CONFIG_INVALID", "--effort must be low, medium, high or xhigh.");
104
+ const bot = { ...old, ...identityFields, adapter };
105
+ const credential = input.options.bf_token;
106
+ if (typeof credential === "string") {
107
+ if (!credential.trim())
108
+ throw new ExtraCommandError("EXTRA_CONFIG_INVALID", "--bf_token must not be blank.");
109
+ // 与 extraset 的业务字段同名;保存传入原文,省略时保留已有凭据。
110
+ bot.bf_token = credential;
111
+ }
112
+ const nextBots = bots.filter((bot, index) => index === position || bot.bot_id !== identityFields.bot_id);
113
+ if (position < 0)
114
+ nextBots.push(bot);
115
+ else
116
+ nextBots[position] = bot;
117
+ const config = { ...snapshot.config, bots: nextBots };
118
+ validate(config);
119
+ return savedConfigResult(await context.saveConfig(config, snapshot.revision));
120
+ }
121
+ }
122
+ ]
123
+ };
124
+ export default extension;
@@ -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";
@@ -47,6 +48,22 @@ export interface OctoBotConfig extends ImCommonConfig {
47
48
  group_ids?: string[] | null;
48
49
  cards?: boolean;
49
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;
50
67
  }
51
68
  export type ImBotConfig = OctoBotConfig;
52
69
  /** Authenticated scope, resolved from octo-auth rather than caller configuration. */
@@ -69,7 +86,7 @@ export interface ImInboundMessage {
69
86
  text: string;
70
87
  buildInputs?(signal: AbortSignal): Promise<ModelInputPart[]>;
71
88
  reply(text: string, effectKey?: string): Promise<void>;
72
- replyFinal?(text: string, effectKey: string): Promise<void>;
89
+ replyFinal?(text: string, effectKey: string, options?: ImFinalReplyOptions): Promise<void>;
73
90
  replyFailure?(event: CanonicalEvent, effectKey: string): Promise<void>;
74
91
  replyDeliveryUnknown?(event: CanonicalEvent, effectKey: string, replyEffectKey: string, signal: AbortSignal): Promise<void>;
75
92
  isReplyDelivered?(effectKey: string): boolean;
@@ -99,6 +116,7 @@ export interface ImRunControls {
99
116
  export interface ImTaskAttempt {
100
117
  runId: string;
101
118
  invocationId: string;
119
+ /** not_submitted 是本次调用事实,不是 Provider 执行终态或整轮未执行的证明。 */
102
120
  outcome: string;
103
121
  failureCode?: string;
104
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
+ }