@mininglamp-oss/octo-runtime 1.1.9 → 1.1.11

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 (225) hide show
  1. package/README.md +2 -2
  2. package/apps/cli/README.md +1 -1
  3. package/{node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-configuration.d.ts → apps/cli/dist/adapter-configuration.d.ts} +1 -0
  4. package/{node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-configuration.js → apps/cli/dist/adapter-configuration.js} +1 -0
  5. package/apps/cli/dist/adapter-configurations.d.ts +1 -1
  6. package/apps/cli/dist/adapter-configurations.js +1 -1
  7. package/apps/cli/dist/adapters.d.ts +7 -0
  8. package/apps/cli/dist/adapters.js +77 -0
  9. package/apps/cli/dist/build-info.json +2 -2
  10. package/apps/cli/dist/command-tree.js +2 -3
  11. package/apps/cli/dist/extras.js +11 -1
  12. package/apps/cli/dist/help.js +1 -1
  13. package/apps/cli/dist/index.js +18 -1
  14. package/apps/cli/dist/main.d.ts +2 -0
  15. package/apps/cli/dist/main.js +67 -34
  16. package/apps/cli/dist/manifest.json +0 -5
  17. package/apps/cli/dist/module-manifest.js +21 -3
  18. package/apps/cli/dist/output.d.ts +19 -1
  19. package/apps/cli/dist/output.js +180 -33
  20. package/apps/cli/dist/playboard-interrupt.d.ts +6 -0
  21. package/apps/cli/dist/playboard-interrupt.js +86 -0
  22. package/apps/cli/dist/playboard.d.ts +2 -0
  23. package/apps/cli/dist/playboard.js +10 -11
  24. package/apps/cli/dist/state.d.ts +5 -2
  25. package/apps/cli/dist/state.js +48 -13
  26. package/dist/public/codex.d.ts +1 -0
  27. package/dist/public/codex.js +1 -0
  28. package/dist/public/executor-kernel.d.ts +4 -1
  29. package/dist/public/executor-kernel.js +2 -1
  30. package/dist/public/extra.d.ts +1 -1
  31. package/dist/public/host.d.ts +5 -0
  32. package/dist/public/host.js +2 -0
  33. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +20 -0
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +6 -6
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +68 -253
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +11 -6
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +198 -52
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.d.ts +58 -0
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.js +650 -0
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.d.ts +3 -0
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.js +15 -0
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +2 -0
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +5 -0
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.d.ts +25 -0
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +3 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/reasoning.js +1 -2
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.d.ts +1 -1
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.js +12 -30
  64. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  65. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configuration.d.ts +3 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configuration.js +125 -0
  67. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configurations.d.ts +1 -1
  68. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configurations.js +1 -1
  69. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.d.ts +7 -0
  70. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +77 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  72. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +2 -3
  73. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +11 -1
  74. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +1 -1
  75. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/index.js +18 -1
  76. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
  77. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +67 -34
  78. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +0 -5
  79. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +21 -3
  80. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.d.ts +19 -1
  81. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +180 -33
  82. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard-interrupt.d.ts +6 -0
  83. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard-interrupt.js +86 -0
  84. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +2 -0
  85. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +10 -11
  86. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.d.ts +5 -2
  87. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -13
  88. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +23 -24
  89. package/node_modules/@mininglamp-oss/octo-runtime-client/build-info.json +5 -0
  90. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.d.ts +30 -0
  91. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.js +199 -0
  92. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.d.ts +1 -0
  93. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.js +1 -0
  94. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.d.ts +10 -0
  95. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.js +465 -0
  96. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.d.ts +6 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.js +6 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.d.ts +4 -0
  99. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.js +5 -0
  100. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.d.ts +59 -0
  101. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.js +287 -0
  102. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.d.ts +1 -0
  103. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.js +1 -0
  104. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.d.ts +1 -0
  105. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.js +1 -0
  106. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.d.ts +21 -0
  107. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.js +138 -0
  108. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.d.ts +8 -0
  109. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.js +65 -0
  110. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.d.ts +82 -0
  111. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.js +371 -0
  112. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.d.ts +10 -0
  113. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.js +23 -0
  114. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.d.ts +72 -0
  115. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.js +10 -0
  116. package/node_modules/@mininglamp-oss/octo-runtime-client/package.json +54 -0
  117. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-configuration-fixtures.json +1219 -0
  118. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-fixtures.json +5988 -0
  119. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-client.behavior.json +56 -0
  120. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc-fixtures.json +53 -0
  121. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc.schema.json +538 -0
  122. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/native-invoke-fixtures.json +116 -0
  123. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/protocol.schema.json +4525 -0
  124. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/run-protocol-fixtures.json +761 -0
  125. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/runtime-selection-fixtures.json +663 -0
  126. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/session-name-fixtures.json +191 -0
  127. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  128. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +29 -21
  129. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +173 -14
  130. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  131. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.d.ts +1 -30
  132. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js +2 -199
  133. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.d.ts +1 -8
  134. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.js +2 -444
  135. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/endpoint.js +2 -0
  136. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/execution-source.d.ts +17 -0
  137. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/execution-source.js +21 -0
  138. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.d.ts +11 -9
  139. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.js +14 -3
  140. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +5 -7
  141. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +6 -7
  142. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.d.ts +1 -53
  143. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -280
  144. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +14 -13
  145. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +84 -187
  146. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.d.ts +5 -10
  147. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.js +4 -1
  148. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.d.ts +20 -0
  149. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.js +180 -0
  150. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +5 -8
  151. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +75 -45
  152. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.d.ts +9 -2
  153. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +60 -5
  154. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.d.ts +1 -0
  155. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.js +1 -0
  156. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.d.ts +1 -0
  157. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.js +1 -0
  158. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.d.ts +4 -0
  159. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.js +18 -0
  160. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +1 -10
  161. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +2 -23
  162. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.d.ts +2 -72
  163. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.js +2 -10
  164. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +5 -12
  165. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/extra.js +1 -1
  166. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/ports.d.ts +2 -2
  167. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
  168. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/extra.js +1 -1
  169. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/ports.d.ts +2 -2
  170. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
  171. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/index.js +4 -4
  172. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/{index-BVxePruX.js → index-BLMf2Etg.js} +1 -3
  173. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
  174. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
  175. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.d.ts +1 -1
  176. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.js +12 -5
  177. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.d.ts +5 -1
  178. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.js +9 -0
  179. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.d.ts +44 -0
  180. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.js +207 -0
  181. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +23 -3
  182. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.d.ts +27 -4
  183. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.js +133 -25
  184. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.d.ts +10 -3
  185. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.js +18 -4
  186. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.d.ts +5 -6
  187. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +33 -45
  188. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/identity.js +6 -0
  189. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +4 -0
  190. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +3 -0
  191. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +5 -4
  192. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.d.ts +7 -0
  193. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +19 -15
  194. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +3 -1
  195. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +1 -0
  196. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.d.ts +5 -0
  197. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +65 -0
  198. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  199. package/package.json +33 -29
  200. package/packages/octo-runtime-protocol/schema/protocol.schema.json +42 -36
  201. package/apps/cli/dist/worker.js +0 -18
  202. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/app-server.d.ts +0 -63
  203. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/app-server.js +0 -846
  204. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.d.ts +0 -54
  205. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +0 -154
  206. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +0 -15
  207. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/worker.js +0 -18
  208. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.d.ts +0 -16
  209. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.js +0 -59
  210. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.d.ts +0 -6
  211. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.js +0 -88
  212. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.d.ts +0 -1
  213. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.js +0 -2
  214. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.d.ts +0 -42
  215. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.js +0 -292
  216. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.d.ts +0 -64
  217. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.js +0 -674
  218. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runner.d.ts +0 -2
  219. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runner.js +0 -5
  220. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.d.ts +0 -10
  221. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +0 -96
  222. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.d.ts +0 -15
  223. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.js +0 -279
  224. /package/{apps/cli/dist/worker.d.ts → node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.js} +0 -0
  225. /package/node_modules/@mininglamp-oss/{octo-runtime-cli/dist/worker.d.ts → octo-runtime-protocol/dist/adapter-metadata.js} +0 -0
@@ -0,0 +1,199 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { assertCanonicalEvent, assertHostFrame, assertHostFrameIdentity, assertHostRunReceipt, assertInvokeInput, assertJsonValue, assertQuestionRequest, assertQuestionResponse, questionAnswerText } from "@mininglamp-oss/octo-runtime-protocol";
3
+ import { KernelError } from "./types.js";
4
+ /**
5
+ * 宿主持有的一份旁路问题控制者,不拥有 Kernel 或数据库。
6
+ * 活动时 steer,确认正常完成后复用 invoke;宿主须串行管理同会话、
7
+ * 保存提交状态并消费新 Run 尾流。新流返回不代表 Provider 接纳。
8
+ */
9
+ export class AsyncQuestionReply {
10
+ client;
11
+ continuation;
12
+ environment;
13
+ #snapshot;
14
+ constructor(client, snapshot, continuation, environment) {
15
+ this.client = client;
16
+ this.continuation = continuation;
17
+ this.environment = environment;
18
+ assertJsonValue(snapshot);
19
+ if (snapshot.schema !== "octo.async-question-reply/v1" ||
20
+ !["pending", "submitting", "answered", "cancelled", "invalidated", "unknown"].includes(snapshot.phase) ||
21
+ typeof snapshot.completed !== "boolean" ||
22
+ snapshot.ref.protocol_mode !== "canonical" ||
23
+ snapshot.ref.protocol !== "codex.app-server" ||
24
+ snapshot.question.delivery !== "async" ||
25
+ snapshot.question.kind !== "question" ||
26
+ snapshot.question.executionInstanceId !== snapshot.ref.invocation_id ||
27
+ !snapshot.providerSession.sessionId ||
28
+ snapshot.providerSession.resumable === false)
29
+ throw new KernelError("INVALID_ASYNC_QUESTION_SNAPSHOT");
30
+ const { kernel_instance_id, ...receipt } = snapshot.ref;
31
+ if (!kernel_instance_id)
32
+ throw new KernelError("INVALID_ASYNC_QUESTION_SNAPSHOT");
33
+ assertHostRunReceipt(receipt);
34
+ assertCanonicalEvent({
35
+ protocolVersion: 2,
36
+ type: "interaction.requested",
37
+ payload: snapshot.question
38
+ });
39
+ assertQuestionRequest(snapshot.question.request);
40
+ this.#snapshot = structuredClone(snapshot);
41
+ }
42
+ /** 独立 JSON 副本供宿主保存;恢复 submitting/unknown 不会再次投递。 */
43
+ snapshot() {
44
+ return structuredClone(this.#snapshot);
45
+ }
46
+ /** 只接受原源流事实;消息 final 或查不到 Run 不能证明正常完成。 */
47
+ observe(frame) {
48
+ assertHostFrame(frame);
49
+ const { kernel_instance_id: _instance, ...receipt } = this.#snapshot.ref;
50
+ void _instance;
51
+ assertHostFrameIdentity(frame, receipt);
52
+ if (frame.kind === "control" && frame.control.type === "state") {
53
+ if (frame.control.state === "completed")
54
+ this.#snapshot.completed = true;
55
+ else if (["failed", "cancelled", "lost"].includes(frame.control.state))
56
+ this.#snapshot.phase = "invalidated";
57
+ }
58
+ if (frame.kind === "canonical" &&
59
+ frame.event.type === "interaction.resolved" &&
60
+ frame.event.payload.interactionId === this.#snapshot.question.interactionId) {
61
+ const payload = frame.event.payload;
62
+ this.#snapshot.phase =
63
+ payload.reasonCode === "provider_accepted"
64
+ ? "answered"
65
+ : payload.reasonCode === "submission_outcome_unknown"
66
+ ? "unknown"
67
+ : "invalidated";
68
+ }
69
+ }
70
+ /** 关闭旁路,不中断模型;原活动交互同步关闭,未知响应不重试。 */
71
+ async cancel() {
72
+ this.#assertPending();
73
+ this.#snapshot.phase = "cancelled";
74
+ if (!this.#snapshot.completed) {
75
+ try {
76
+ await this.client.respond(this.#snapshot.ref, {
77
+ interactionId: this.#snapshot.question.interactionId,
78
+ outcome: "cancelled"
79
+ });
80
+ }
81
+ catch (error) {
82
+ if (!(error instanceof KernelError) || error.code !== "INTERACTION_NOT_ACTIVE")
83
+ throw error;
84
+ }
85
+ }
86
+ }
87
+ /** 整批一次。steer 等待 Provider ACK;new_run 必须消费返回流,沿原 invoke 管理执行。 */
88
+ async respond(value) {
89
+ this.#assertPending();
90
+ const original = this.#snapshot;
91
+ assertQuestionRequest(original.question.request);
92
+ const answer = structuredClone(value);
93
+ assertQuestionResponse(answer);
94
+ const text = questionAnswerText(original.question.request, answer);
95
+ const next = structuredClone(this.continuation());
96
+ assertInvokeInput(next);
97
+ // 现有会话由宿主显式提供,旧题不能跨 reset 或 Provider binding 改投。
98
+ if (next.sessionId !== original.ref.agent_session_id ||
99
+ (next.sessionGeneration ?? 0) !== original.ref.session_generation ||
100
+ next.providerSession?.sessionId !== original.providerSession.sessionId ||
101
+ next.providerSession?.resumable === false ||
102
+ next.providerEpoch !== original.providerEpoch)
103
+ throw new KernelError("ASYNC_QUESTION_SESSION_STALE");
104
+ original.phase = "submitting";
105
+ let attempted = false;
106
+ try {
107
+ if (!original.completed) {
108
+ const current = await this.client.get(original.ref, original.ref.kernel_instance_id);
109
+ if (current.terminal)
110
+ this.observe(current.terminal);
111
+ if (this.snapshot().phase === "invalidated")
112
+ throw new KernelError("INTERACTION_NOT_ACTIVE");
113
+ }
114
+ if (!original.completed) {
115
+ attempted = true;
116
+ try {
117
+ this.#assertNotExpired();
118
+ await this.client.respond(original.ref, {
119
+ interactionId: original.question.interactionId,
120
+ outcome: "answered",
121
+ value: answer
122
+ });
123
+ original.phase = "answered";
124
+ return { route: "steer", acceptance: "provider_accepted" };
125
+ }
126
+ catch (error) {
127
+ if (!(error instanceof KernelError) ||
128
+ !["INTERACTION_NOT_ACTIVE", "ASYNC_ANSWER_REJECTED"].includes(error.code))
129
+ throw error;
130
+ // 仅明确未接纳才可在正常终态之后续跑;ACK 丢失和写后失联绝不进入此分支。
131
+ attempted = false;
132
+ const current = await this.client.get(original.ref, original.ref.kernel_instance_id);
133
+ if (current.terminal)
134
+ this.observe(current.terminal);
135
+ if (!original.completed) {
136
+ original.phase = "invalidated";
137
+ throw error;
138
+ }
139
+ }
140
+ }
141
+ const input = {
142
+ ...next,
143
+ runId: randomUUID(),
144
+ invocationId: randomUUID(),
145
+ protocol_mode: "canonical",
146
+ continuityMode: "continue",
147
+ inputs: [{ type: "text", text }],
148
+ prompt: text,
149
+ modelInput: text,
150
+ providerSession: { ...original.providerSession, requireResume: true },
151
+ freshFallbackModelInput: text,
152
+ freshFallbackModelInputParts: [{ type: "text", text }]
153
+ };
154
+ const client = this.client, environment = this.environment;
155
+ const beforeInvoke = () => {
156
+ this.#assertNotExpired();
157
+ const currentInput = this.continuation();
158
+ if (currentInput.sessionId !== input.sessionId ||
159
+ (currentInput.sessionGeneration ?? 0) !== original.ref.session_generation ||
160
+ currentInput.providerSession?.sessionId !== original.providerSession.sessionId ||
161
+ currentInput.providerEpoch !== original.providerEpoch)
162
+ throw new KernelError("ASYNC_QUESTION_SESSION_STALE");
163
+ };
164
+ const events = (async function* () {
165
+ try {
166
+ beforeInvoke();
167
+ for await (const event of client.invoke(input, environment)) {
168
+ if (event.type === "session.update" &&
169
+ event.payload.providerSession?.sessionId === original.providerSession.sessionId &&
170
+ event.payload.providerSession.resumeOutcome === "resumed")
171
+ original.phase = "answered";
172
+ yield event;
173
+ }
174
+ }
175
+ finally {
176
+ if (original.phase === "submitting")
177
+ original.phase = "unknown";
178
+ }
179
+ })();
180
+ return { route: "new_run", input: structuredClone(input), events };
181
+ }
182
+ catch (error) {
183
+ if (original.phase === "submitting")
184
+ original.phase = attempted ? "unknown" : "pending";
185
+ throw error;
186
+ }
187
+ }
188
+ #assertPending() {
189
+ const snapshot = this.#snapshot;
190
+ if (snapshot.phase !== "pending")
191
+ throw new KernelError("INTERACTION_NOT_ACTIVE");
192
+ this.#assertNotExpired();
193
+ }
194
+ #assertNotExpired() {
195
+ const expiresAt = this.#snapshot.question.expiresAt;
196
+ if (expiresAt !== undefined && Date.parse(expiresAt) <= Date.now())
197
+ throw new KernelError("INTERACTION_NOT_ACTIVE");
198
+ }
199
+ }
@@ -0,0 +1 @@
1
+ export * from "@mininglamp-oss/octo-runtime-protocol/browser";
@@ -0,0 +1 @@
1
+ export * from "@mininglamp-oss/octo-runtime-protocol/browser";
@@ -0,0 +1,10 @@
1
+ import { type KernelClient } from "./types.js";
2
+ /**
3
+ * 连接本机 socket/Windows Pipe,返回不拥有 Kernel 进程的客户端。
4
+ * 独立应用显式连接已有服务;原生 SDK 服务宿主使用 kernel.client。
5
+ * Kernel/Extra 服务内部也复用本函数构造 RPC 客户端,不要求 SDK 调用方额外 attach。
6
+ * invoke 提供登记、取消和尾流观察;关闭连接或迭代器不会隐式取消已接纳 Run。
7
+ */
8
+ export declare function attachKernel(options: {
9
+ endpoint: string;
10
+ }): KernelClient;
@@ -0,0 +1,465 @@
1
+ import net from "node:net";
2
+ import { assertIpcEndpoint } from "./runtime-path.js";
3
+ import { randomUUID } from "node:crypto";
4
+ import { assertHostFrame, assertHostFrameIdentity, assertHostRunReceipt, assertKernelStatus, createInputInvoke, identifyInvokeInput, isHostTerminal, HOST_RPC_MAX_LINE_BYTES, INVOKE_REQUEST_MAX_BYTES } from "@mininglamp-oss/octo-runtime-protocol";
5
+ import { KernelError } from "./types.js";
6
+ import { InvocationRegistry } from "./invocation-lifecycle.js";
7
+ import { markSubmissionRejected } from "./submission-error.js";
8
+ /**
9
+ * 连接本机 socket/Windows Pipe,返回不拥有 Kernel 进程的客户端。
10
+ * 独立应用显式连接已有服务;原生 SDK 服务宿主使用 kernel.client。
11
+ * Kernel/Extra 服务内部也复用本函数构造 RPC 客户端,不要求 SDK 调用方额外 attach。
12
+ * invoke 提供登记、取消和尾流观察;关闭连接或迭代器不会隐式取消已接纳 Run。
13
+ */
14
+ export function attachKernel(options) {
15
+ const endpoint = options.endpoint;
16
+ assertIpcEndpoint(endpoint);
17
+ const sockets = new Set();
18
+ let closed = false;
19
+ const open = async (signal, timeout = 5000) => {
20
+ if (closed)
21
+ throw new KernelError("CLIENT_CLOSED");
22
+ if (sockets.size >= 32)
23
+ throw new KernelError("CLIENT_CAPACITY_EXHAUSTED");
24
+ signal?.throwIfAborted();
25
+ const socket = net.createConnection(endpoint);
26
+ sockets.add(socket);
27
+ socket.once("close", () => sockets.delete(socket));
28
+ socket.on("error", () => { });
29
+ const abort = () => socket.destroy(new KernelError("SUBSCRIPTION_ABORTED"));
30
+ signal?.addEventListener("abort", abort, { once: true });
31
+ socket.once("close", () => signal?.removeEventListener("abort", abort));
32
+ await new Promise((resolve, reject) => {
33
+ const finish = (error) => {
34
+ clearTimeout(timer);
35
+ socket.off("connect", connected);
36
+ socket.off("error", failed);
37
+ socket.off("close", disconnected);
38
+ if (error)
39
+ reject(error);
40
+ else
41
+ resolve();
42
+ };
43
+ const connected = () => finish();
44
+ const failed = (error) => finish(error);
45
+ const disconnected = () => finish(new KernelError(closed ? "CLIENT_CLOSED" : "CONNECTION_CLOSED"));
46
+ const timer = setTimeout(() => {
47
+ socket.destroy();
48
+ finish(new KernelError("KERNEL_UNAVAILABLE"));
49
+ }, Math.min(5000, timeout));
50
+ socket.once("connect", connected);
51
+ socket.once("error", failed);
52
+ socket.once("close", disconnected);
53
+ }).catch(() => {
54
+ socket.destroy();
55
+ throw new KernelError(closed ? "CLIENT_CLOSED" : "KERNEL_UNAVAILABLE");
56
+ });
57
+ return socket;
58
+ };
59
+ const exchange = async (method, params = {}, timeout = 5000, signal, beforeSend, sent) => {
60
+ const until = Date.now() + timeout;
61
+ const socket = await open(signal, timeout);
62
+ const timer = setTimeout(() => socket.destroy(new KernelError("KERNEL_TIMEOUT")), Math.max(1, until - Date.now()));
63
+ const id = randomUUID();
64
+ try {
65
+ signal?.throwIfAborted();
66
+ beforeSend?.();
67
+ send(socket, id, method, params);
68
+ sent?.();
69
+ for await (const value of lines(socket))
70
+ return response(value, id);
71
+ throw new KernelError(closed ? "CLIENT_CLOSED" : "CONNECTION_CLOSED");
72
+ }
73
+ catch (error) {
74
+ if (closed)
75
+ throw new KernelError("CLIENT_CLOSED");
76
+ throw error;
77
+ }
78
+ finally {
79
+ clearTimeout(timer);
80
+ socket.destroy();
81
+ }
82
+ };
83
+ const query = async (key, expectedInstance, deadline = Date.now() + 5000, signal) => {
84
+ const info = (await exchange("agent_run.get", {
85
+ key: lookupForKey(key),
86
+ kernel_instance_id: expectedInstance
87
+ }, remaining(deadline), signal));
88
+ assertHostRunReceipt(receiptFor(info.ref));
89
+ if (expectedInstance !== undefined && info.ref.kernel_instance_id !== expectedInstance)
90
+ throw new KernelError("KERNEL_INSTANCE_CHANGED");
91
+ if (!sameLookup(info.ref, key))
92
+ throw new KernelError("RUN_IDENTITY_MISMATCH");
93
+ if (info.terminal) {
94
+ assertHostFrame(info.terminal);
95
+ assertHostFrameIdentity(info.terminal, receiptFor(info.ref));
96
+ if (!isHostTerminal(info.terminal))
97
+ throw new KernelError("HOST_FRAME_INVALID");
98
+ }
99
+ registry.reconcile(info.ref, info.terminal);
100
+ return info;
101
+ };
102
+ const cancel = async (ref, reason, deadline = Date.now() + 5000, signal) => {
103
+ try {
104
+ const result = (await exchange("agent_run.cancel", { ref, reason }, remaining(deadline), signal));
105
+ if (typeof result?.accepted !== "boolean")
106
+ throw new KernelError("OPERATION_OUTCOME_UNKNOWN");
107
+ return result;
108
+ }
109
+ catch (error) {
110
+ if (error instanceof KernelError &&
111
+ !["CONNECTION_CLOSED", "KERNEL_TIMEOUT", "SUBSCRIPTION_ABORTED"].includes(error.code))
112
+ throw error;
113
+ throw new KernelError("OPERATION_OUTCOME_UNKNOWN");
114
+ }
115
+ };
116
+ const registry = new InvocationRegistry({ get: query, cancel });
117
+ const control = async (method, params) => {
118
+ try {
119
+ await exchange(method, params);
120
+ }
121
+ catch (error) {
122
+ if (error instanceof KernelError &&
123
+ !["CONNECTION_CLOSED", "KERNEL_TIMEOUT"].includes(error.code))
124
+ throw error;
125
+ throw new KernelError("OPERATION_OUTCOME_UNKNOWN");
126
+ }
127
+ };
128
+ const client = {
129
+ topology: "kernel-ipc",
130
+ ownership: "attached",
131
+ invocations: registry,
132
+ invoke: createInputInvoke(async function* (input, environment = {}) {
133
+ if (closed)
134
+ throw new KernelError("CLIENT_CLOSED");
135
+ environment.signal?.throwIfAborted();
136
+ const request = identifyInvokeInput(input);
137
+ const record = registry.begin(lookupFor(request));
138
+ // signal 属于执行控制,不传给 subscribe:取消后仍须读到 Provider 会话更新与真实终态。
139
+ const abort = () => {
140
+ void registry.cancel(record, "caller_aborted").catch(() => undefined);
141
+ };
142
+ environment.signal?.addEventListener("abort", abort, { once: true });
143
+ try {
144
+ let ref;
145
+ try {
146
+ ref = (await submit(request, environment, record)).ref;
147
+ registry.accepted(record, ref);
148
+ }
149
+ catch (error) {
150
+ registry.rejected(record, error);
151
+ throw error;
152
+ }
153
+ // 终态会释放登记,但 yield 后的业务持久化/投递仍由消费者负责,owner 不能据此提前 close。
154
+ let terminal = false;
155
+ for await (const frame of client.subscribe(ref)) {
156
+ terminal = isHostTerminal(frame);
157
+ if (request.protocol_mode === "canonical" &&
158
+ frame.kind === "control" &&
159
+ frame.control.type === "error") {
160
+ const snapshot = await query(ref, ref.kernel_instance_id).catch(() => undefined);
161
+ if (snapshot?.terminal?.kind === "control" &&
162
+ snapshot.terminal.control.type === "state" &&
163
+ snapshot.terminal.control.state === "lost")
164
+ throw new KernelError("RUN_OUTCOME_UNKNOWN");
165
+ }
166
+ yield frame;
167
+ if (terminal &&
168
+ frame.kind === "control" &&
169
+ frame.control.type === "state" &&
170
+ frame.control.state === "lost")
171
+ throw new KernelError("RUN_OUTCOME_UNKNOWN");
172
+ }
173
+ if (!terminal)
174
+ throw new KernelError("HOST_ENDED_WITHOUT_TERMINAL");
175
+ // 调用观察绑定首次控制结果;后续显式 Stop 成功不能抹去原来的 ACK 未知或失败。
176
+ if (record.firstCancelTask)
177
+ await record.firstCancelTask;
178
+ }
179
+ catch (error) {
180
+ registry.interrupted(record, error);
181
+ throw error;
182
+ }
183
+ finally {
184
+ environment.signal?.removeEventListener("abort", abort);
185
+ registry.interrupted(record);
186
+ }
187
+ }),
188
+ cancelInvocation: async (id, reason) => registry.cancel(registry.active(id), reason, { explicit: true }),
189
+ respondInteraction: async (id, response) => client.respond(registry.ref(id), response),
190
+ respondNativeInteraction: async (id, response) => client.respondNative(registry.ref(id), response),
191
+ status: async () => {
192
+ const value = (await exchange("status"));
193
+ if (!value || typeof value !== "object" || typeof value.ipc_version !== "number")
194
+ throw new KernelError("INVALID_RESPONSE");
195
+ // 包版本不参与 wire 兼容判断;submit 复用此既有查询,拒绝后不会发起执行。
196
+ if (value.ipc_version !== 1)
197
+ throw new KernelError("KERNEL_IPC_VERSION_UNSUPPORTED");
198
+ try {
199
+ // 与服务端/doctor 共用快照白名单;仍保持客户端的受控错误与版本拒绝顺序。
200
+ assertKernelStatus(value);
201
+ }
202
+ catch {
203
+ throw new KernelError("INVALID_RESPONSE");
204
+ }
205
+ return value;
206
+ },
207
+ list: async () => (await exchange("adapter.list")),
208
+ get: query,
209
+ submit: (input, environment) => submit(input, environment),
210
+ async *subscribe(ref, afterSeq = 0, signal) {
211
+ // 断线仅续读同一实例、同一流的连续序号;不能把恢复观察变成再次执行 Provider。
212
+ let after = afterSeq;
213
+ let repair = 0;
214
+ let repairUntil;
215
+ while (true) {
216
+ signal?.throwIfAborted();
217
+ if (closed)
218
+ throw new KernelError("CLIENT_CLOSED");
219
+ let socket;
220
+ let timer;
221
+ try {
222
+ if (repairUntil !== undefined && Date.now() >= repairUntil)
223
+ throw new KernelError("KERNEL_UNAVAILABLE");
224
+ socket = await open(signal, repairUntil === undefined ? 5000 : Math.max(1, repairUntil - Date.now()));
225
+ const current = socket;
226
+ timer = setTimeout(() => current.destroy(new KernelError("KERNEL_TIMEOUT")), repairUntil === undefined ? 5000 : Math.max(1, Math.min(5000, repairUntil - Date.now())));
227
+ const id = randomUUID();
228
+ send(socket, id, "agent_run.subscribe", { ref, after_seq: after });
229
+ let acknowledged = false;
230
+ let terminalAt;
231
+ for await (const value of lines(socket)) {
232
+ if (!acknowledged) {
233
+ const info = response(value, id);
234
+ if (info.ref.kernel_instance_id !== ref.kernel_instance_id)
235
+ throw new KernelError("KERNEL_INSTANCE_CHANGED");
236
+ assertHostRunReceipt(receiptFor(info.ref));
237
+ if (!sameLookup(info.ref, ref) ||
238
+ info.ref.stream_id !== ref.stream_id ||
239
+ info.ref.protocol !== ref.protocol)
240
+ throw new KernelError("RUN_IDENTITY_MISMATCH");
241
+ acknowledged = true;
242
+ clearTimeout(timer);
243
+ if (info.terminal) {
244
+ assertHostFrame(info.terminal);
245
+ assertHostFrameIdentity(info.terminal, receiptFor(ref));
246
+ if (!isHostTerminal(info.terminal))
247
+ throw new KernelError("HOST_FRAME_INVALID");
248
+ registry.reconcile(info.ref, info.terminal);
249
+ terminalAt = info.latest_seq;
250
+ }
251
+ if (terminalAt !== undefined && after >= terminalAt)
252
+ return;
253
+ continue;
254
+ }
255
+ const notification = value;
256
+ if (notification.method === "agent_run.stream_error")
257
+ throw new KernelError(notification.params?.code ?? "STREAM_FAILED");
258
+ if (notification.method !== "agent_run.event" ||
259
+ notification.params?.kernel_instance_id !== ref.kernel_instance_id)
260
+ throw new KernelError("HOST_FRAME_INVALID");
261
+ const frame = notification.params.event;
262
+ assertHostFrame(frame);
263
+ assertHostFrameIdentity(frame, receiptFor(ref));
264
+ if (frame.seq !== after + 1 || notification.params.seq !== frame.seq)
265
+ throw new KernelError("STREAM_GAP");
266
+ after = frame.seq;
267
+ registry.observe(ref, frame);
268
+ yield frame;
269
+ if (isHostTerminal(frame))
270
+ return;
271
+ }
272
+ throw new KernelError("CONNECTION_CLOSED");
273
+ }
274
+ catch (error) {
275
+ if (closed)
276
+ throw new KernelError("CLIENT_CLOSED");
277
+ signal?.throwIfAborted();
278
+ if (!(error instanceof KernelError) &&
279
+ error instanceof Error &&
280
+ "code" in error &&
281
+ typeof error.code === "string")
282
+ throw new KernelError(error.code);
283
+ if (error instanceof KernelError &&
284
+ !["CONNECTION_CLOSED", "KERNEL_UNAVAILABLE", "KERNEL_TIMEOUT"].includes(error.code))
285
+ throw error;
286
+ if (repair >= 3)
287
+ throw new KernelError("KERNEL_UNAVAILABLE");
288
+ repairUntil ??= Date.now() + 10_000;
289
+ if (Date.now() >= repairUntil)
290
+ throw new KernelError("KERNEL_UNAVAILABLE");
291
+ await new Promise((resolve) => setTimeout(resolve, [100, 250, 500][repair++]));
292
+ }
293
+ finally {
294
+ clearTimeout(timer);
295
+ socket?.destroy();
296
+ }
297
+ }
298
+ },
299
+ cancel,
300
+ respond: (ref, response) => control("agent_run.respond", { ref, response }),
301
+ respondNative: (ref, response) => control("agent_run.native.respond", { ref, response }),
302
+ close() {
303
+ closed = true;
304
+ registry.close();
305
+ for (const socket of sockets)
306
+ socket.destroy();
307
+ }
308
+ };
309
+ async function submit(input, environment = {}, record) {
310
+ if (closed)
311
+ throw new KernelError("CLIENT_CLOSED");
312
+ environment.signal?.throwIfAborted();
313
+ if (environment.streamLimits !== undefined)
314
+ throw new KernelError("KERNEL_STREAM_LIMITS_UNSUPPORTED");
315
+ const request = identifyInvokeInput(input);
316
+ const requestLine = JSON.stringify({
317
+ jsonrpc: "2.0",
318
+ id: "0".repeat(36),
319
+ method: "agent_run.invoke",
320
+ params: { input: request, executionEnvOverrides: environment.executionEnvOverrides }
321
+ });
322
+ if (Buffer.byteLength(requestLine) + 1 > INVOKE_REQUEST_MAX_BYTES)
323
+ throw new KernelError("INVOKE_REQUEST_TOO_LARGE");
324
+ const instance = (await client.status()).kernel_instance_id;
325
+ environment.signal?.throwIfAborted();
326
+ if (record)
327
+ record.instance = instance;
328
+ let ref;
329
+ let submitted = false;
330
+ try {
331
+ const result = (await exchange("agent_run.invoke", {
332
+ input: request,
333
+ executionEnvOverrides: environment.executionEnvOverrides,
334
+ kernel_instance_id: instance
335
+ }, 30_000,
336
+ // 请求发出后中断等待会让接纳结果不明;先取得/查询 ACK,再按原身份请求取消。
337
+ undefined, () => {
338
+ environment.signal?.throwIfAborted();
339
+ if (record)
340
+ registry.assertSubmission();
341
+ }, () => {
342
+ submitted = true;
343
+ if (record)
344
+ record.submitted = true;
345
+ }));
346
+ assertHostRunReceipt(result.receipt);
347
+ if (result.kernel_instance_id !== instance)
348
+ throw new KernelError("KERNEL_INSTANCE_CHANGED");
349
+ ref = { ...result.receipt, kernel_instance_id: result.kernel_instance_id };
350
+ if (!sameLookup(ref, lookupFor(request)))
351
+ throw new KernelError("RUN_IDENTITY_MISMATCH");
352
+ }
353
+ catch (error) {
354
+ if (!submitted)
355
+ throw error;
356
+ markSubmissionRejected(error, instance);
357
+ if (error instanceof KernelError &&
358
+ !["KERNEL_TIMEOUT", "CONNECTION_CLOSED"].includes(error.code))
359
+ throw error;
360
+ // ACK 丢失后只按原身份查询,不重新提交,避免创建第二次执行。
361
+ const key = lookupFor(request);
362
+ let recovered;
363
+ const until = Date.now() + 10_000;
364
+ for (const delay of [100, 250, 500]) {
365
+ await new Promise((resolve) => setTimeout(resolve, delay));
366
+ if (Date.now() >= until)
367
+ break;
368
+ try {
369
+ recovered = (await query(key, instance, Math.min(until, Date.now() + 5000))).ref;
370
+ break;
371
+ }
372
+ catch (queryError) {
373
+ if (queryError instanceof KernelError &&
374
+ ["KERNEL_INSTANCE_CHANGED", "RUN_IDENTITY_MISMATCH"].includes(queryError.code))
375
+ throw queryError;
376
+ }
377
+ }
378
+ if (!recovered)
379
+ throw new KernelError("ACCEPTANCE_UNKNOWN");
380
+ ref = recovered;
381
+ }
382
+ if (!record && environment.signal?.aborted)
383
+ await client.cancel(ref, "caller_aborted");
384
+ return { ref };
385
+ }
386
+ return client;
387
+ }
388
+ function remaining(deadline) {
389
+ const timeout = deadline - Date.now();
390
+ if (timeout <= 0)
391
+ throw new KernelError("KERNEL_TIMEOUT");
392
+ return timeout;
393
+ }
394
+ function receiptFor(ref) {
395
+ const { kernel_instance_id: _instance, ...receipt } = ref;
396
+ void _instance;
397
+ return receipt;
398
+ }
399
+ function lookupForKey(key) {
400
+ return {
401
+ run_id: key.run_id,
402
+ invocation_id: key.invocation_id,
403
+ agent_session_id: key.agent_session_id,
404
+ session_generation: key.session_generation,
405
+ protocol_mode: key.protocol_mode
406
+ };
407
+ }
408
+ function sameLookup(left, right) {
409
+ return (left.run_id === right.run_id &&
410
+ left.invocation_id === right.invocation_id &&
411
+ left.agent_session_id === right.agent_session_id &&
412
+ left.session_generation === right.session_generation &&
413
+ left.protocol_mode === right.protocol_mode);
414
+ }
415
+ function lookupFor(input) {
416
+ return {
417
+ run_id: input.runId,
418
+ invocation_id: input.invocationId,
419
+ agent_session_id: input.sessionId,
420
+ session_generation: input.sessionGeneration ?? 0,
421
+ protocol_mode: input.protocol_mode ?? "native"
422
+ };
423
+ }
424
+ function send(socket, id, method, params) {
425
+ const line = `${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`;
426
+ if (Buffer.byteLength(line) > INVOKE_REQUEST_MAX_BYTES)
427
+ throw new KernelError("INVOKE_REQUEST_TOO_LARGE");
428
+ socket.write(line);
429
+ }
430
+ function response(value, id) {
431
+ const reply = value;
432
+ if (reply.id !== id)
433
+ throw new KernelError("INVALID_RESPONSE");
434
+ if (reply.error)
435
+ throw new KernelError(typeof reply.error.data?.code === "string" ? reply.error.data.code : "KERNEL_REQUEST_FAILED", reply.error.data);
436
+ return reply.result;
437
+ }
438
+ async function* lines(socket) {
439
+ let pending = Buffer.alloc(0);
440
+ try {
441
+ for await (const chunk of socket) {
442
+ const bytes = chunk;
443
+ pending = pending.length ? Buffer.concat([pending, bytes]) : bytes;
444
+ let offset;
445
+ while ((offset = pending.indexOf(10)) >= 0) {
446
+ if (offset > HOST_RPC_MAX_LINE_BYTES)
447
+ throw new KernelError("HOST_FRAME_TOO_LARGE");
448
+ const line = pending.subarray(0, offset);
449
+ pending = pending.subarray(offset + 1);
450
+ yield JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(line));
451
+ }
452
+ if (pending.length > HOST_RPC_MAX_LINE_BYTES)
453
+ throw new KernelError("HOST_FRAME_TOO_LARGE");
454
+ }
455
+ if (pending.length)
456
+ throw new KernelError("CONNECTION_CLOSED");
457
+ }
458
+ catch (error) {
459
+ if (error instanceof KernelError)
460
+ throw error;
461
+ if (error instanceof Error && /^[A-Z][A-Z0-9_]+$/.test(error.message))
462
+ throw new KernelError(error.message);
463
+ throw new KernelError("CONNECTION_CLOSED");
464
+ }
465
+ }