maka-agent 0.2.1-dev.91.20261018 → 0.2.2-dev.97.20261024

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 (418) hide show
  1. package/DISCLAIMER-WIP +1 -1
  2. package/LICENSE +15 -11
  3. package/README.md +173 -1
  4. package/README.zh-CN.md +156 -0
  5. package/THIRD_PARTY_NOTICES.txt +12 -12
  6. package/dist/cli-core.js +1 -0
  7. package/dist/pi-goal.js +13 -0
  8. package/dist/pi-tui-runner.js +44 -1
  9. package/dist/run-command-core.js +256 -48
  10. package/dist/run-session-command.js +534 -0
  11. package/dist/run-session-result.js +38 -0
  12. package/dist/run-turn-outcome.js +174 -0
  13. package/dist/runtime-host-cli.js +32 -17
  14. package/dist/runtime-host-run-command.js +53 -165
  15. package/dist/runtime-host-run-mcp.js +3 -0
  16. package/dist/runtime-host-session-channel.js +3 -1
  17. package/dist/runtime-host-session-driver.js +5 -0
  18. package/dist/runtime-host-setup-command.js +114 -7
  19. package/dist/tui-copy-catalog.js +24 -0
  20. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  21. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
  22. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
  23. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
  24. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
  25. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  26. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  27. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
  28. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  29. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
  30. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  31. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  32. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
  33. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
  34. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
  35. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
  36. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  37. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  38. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
  39. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
  40. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  41. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  42. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
  43. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
  44. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
  45. package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
  46. package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
  47. package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
  48. package/node_modules/@maka/core/dist/bot-chat-settings.js +10 -1
  49. package/node_modules/@maka/core/dist/event-wait-delivery.js +67 -0
  50. package/node_modules/@maka/core/dist/event-wait.js +75 -10
  51. package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
  52. package/node_modules/@maka/core/dist/goal.js +54 -2
  53. package/node_modules/@maka/core/dist/model-catalog.js +19 -1
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
  55. package/node_modules/@maka/core/dist/model-metadata.js +42 -1
  56. package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
  57. package/node_modules/@maka/core/dist/provider-registry.js +16 -2
  58. package/node_modules/@maka/core/dist/runtime-event-store.js +0 -1
  59. package/node_modules/@maka/core/dist/runtime-event.js +24 -2
  60. package/node_modules/@maka/core/dist/runtime-invocation.js +10 -0
  61. package/node_modules/@maka/core/dist/session-checkin.js +31 -0
  62. package/node_modules/@maka/core/dist/tool-ledger-scanner.js +1 -9
  63. package/node_modules/@maka/core/dist/tool-recovery-bundle.js +1 -14
  64. package/node_modules/@maka/core/dist/turn-origin.js +14 -2
  65. package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
  66. package/node_modules/@maka/core/package.json +3 -0
  67. package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
  68. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  69. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
  70. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  71. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
  72. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  73. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  74. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  75. package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
  76. package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
  77. package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  78. package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  79. package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
  80. package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
  81. package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
  82. package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
  83. package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
  84. package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
  85. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
  86. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  87. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  88. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
  89. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  90. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  91. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  92. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  93. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
  94. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  95. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  96. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  97. package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
  98. package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  99. package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  100. package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
  101. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
  102. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
  103. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
  104. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
  105. package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
  106. package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
  107. package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
  108. package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
  109. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  110. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  111. package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
  112. package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
  113. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  114. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  115. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
  116. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  117. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
  118. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
  119. package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  120. package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  121. package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
  122. package/node_modules/@maka/mcp/package.json +1 -1
  123. package/node_modules/@maka/runtime/dist/agent-run.js +5 -1
  124. package/node_modules/@maka/runtime/dist/agent-swarm-status-tool.js +0 -1
  125. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +29 -15
  126. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
  127. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +125 -131
  128. package/node_modules/@maka/runtime/dist/bots/bot-registry.js +19 -3
  129. package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +178 -6
  130. package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +163 -9
  131. package/node_modules/@maka/runtime/dist/context-budget-policy.js +9 -2
  132. package/node_modules/@maka/runtime/dist/event-wait-tool.js +69 -0
  133. package/node_modules/@maka/runtime/dist/goal-continuation.js +195 -117
  134. package/node_modules/@maka/runtime/dist/goal-state.js +8 -0
  135. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +34 -4
  136. package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
  137. package/node_modules/@maka/runtime/dist/memory-extraction.js +0 -2
  138. package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
  139. package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
  140. package/node_modules/@maka/runtime/dist/model-history.js +16 -3
  141. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +15 -5
  142. package/node_modules/@maka/runtime/dist/plan-tools.js +0 -3
  143. package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
  144. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
  145. package/node_modules/@maka/runtime/dist/provider-error-classification.js +2 -0
  146. package/node_modules/@maka/runtime/dist/recovery-resolver.js +2 -1
  147. package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
  148. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
  149. package/node_modules/@maka/runtime/dist/sandbox-boundary-path.js +79 -2
  150. package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
  151. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
  152. package/node_modules/@maka/runtime/dist/session-manager.js +5 -1
  153. package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
  154. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -3
  155. package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
  156. package/node_modules/@maka/runtime/dist/tool-runtime.js +11 -2
  157. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
  158. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
  159. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
  160. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
  161. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
  162. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  163. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  164. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
  165. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  166. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
  167. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  168. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  169. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
  170. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
  171. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
  172. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
  173. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  174. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  175. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
  176. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
  177. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  178. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  179. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
  180. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
  181. package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
  182. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  183. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
  184. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  185. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
  186. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  187. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  188. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  189. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
  190. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
  191. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  192. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  193. package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
  194. package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
  195. package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
  196. package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
  197. package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
  198. package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
  199. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
  200. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  201. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  202. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
  203. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  204. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  205. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  206. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  207. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
  208. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  209. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  210. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  211. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
  212. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  213. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  214. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
  215. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
  216. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
  217. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
  218. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
  219. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
  220. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
  221. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
  222. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
  223. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  224. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  225. package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
  226. package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
  227. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  228. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  229. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
  230. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  231. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
  232. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
  233. package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  234. package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  235. package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
  236. package/node_modules/@maka/runtime/package.json +3 -0
  237. package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
  238. package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
  239. package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +92 -22
  240. package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
  241. package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
  242. package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
  243. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
  244. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
  245. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
  246. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
  247. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
  248. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
  249. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
  250. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +203 -71
  251. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/host.js +21 -5
  252. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
  253. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
  254. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
  255. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
  256. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +37 -5
  257. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
  258. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
  259. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
  260. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
  261. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +68 -14
  262. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
  263. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
  264. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +93 -23
  265. package/node_modules/@maka/runtime-host/dist/assistant/service.js +72 -16
  266. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +30 -1
  267. package/node_modules/@maka/runtime-host/dist/client/ssh-operator-activation.js +9 -2
  268. package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
  269. package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -3
  270. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
  271. package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
  272. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
  273. package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
  274. package/node_modules/@maka/runtime-host/dist/server/agent-settings-tools.js +0 -1
  275. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
  276. package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +151 -20
  277. package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
  278. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +127 -11
  279. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
  280. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +11 -0
  281. package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +5 -2
  282. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +343 -53
  283. package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +457 -0
  284. package/node_modules/@maka/runtime-host/dist/server/goal-execution-coordinator.js +23 -6
  285. package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
  286. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +5 -1
  287. package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
  288. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
  289. package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
  290. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +8 -0
  291. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
  292. package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
  293. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
  294. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
  295. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
  296. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
  297. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
  298. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +14 -3
  299. package/node_modules/@maka/storage/dist/agent-run-store.js +10 -0
  300. package/node_modules/@maka/storage/dist/codex-session-adapter.js +20 -3
  301. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
  302. package/node_modules/@maka/storage/dist/event-wait-authority.js +18 -1
  303. package/node_modules/@maka/storage/dist/event-wait-bridge.js +336 -0
  304. package/node_modules/@maka/storage/dist/execution-stores.js +39 -1
  305. package/node_modules/@maka/storage/dist/external-session-images.js +131 -0
  306. package/node_modules/@maka/storage/dist/external-session-importer.js +12 -2
  307. package/node_modules/@maka/storage/dist/goal-authority.js +2 -0
  308. package/node_modules/@maka/storage/dist/local-execution-persistence.js +27 -1
  309. package/node_modules/@maka/storage/dist/operational-state-store.js +1 -1
  310. package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
  311. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  312. package/node_modules/@maka/storage/dist/session-bundle-policy.js +116 -16
  313. package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
  314. package/node_modules/@maka/storage/dist/session-store.js +37 -8
  315. package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
  316. package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
  317. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
  318. package/node_modules/@maka/storage/dist/sqlite-event-wait-authority.js +81 -8
  319. package/node_modules/@maka/storage/dist/sqlite-event-wait-bridge.js +94 -0
  320. package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
  321. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +7 -8
  322. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +38 -162
  323. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +7 -4
  324. package/node_modules/@maka/storage/dist/tool-commit-validation.js +1 -1
  325. package/node_modules/@maka/storage/package.json +4 -0
  326. package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
  327. package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
  328. package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
  329. package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
  330. package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
  331. package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
  332. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
  333. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
  334. package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
  335. package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
  336. package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
  337. package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
  338. package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
  339. package/node_modules/@modelcontextprotocol/client/package.json +5 -5
  340. package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
  341. package/node_modules/fast-uri/README.md +8 -0
  342. package/node_modules/fast-uri/index.js +98 -18
  343. package/node_modules/fast-uri/lib/utils.js +52 -0
  344. package/node_modules/fast-uri/package.json +1 -1
  345. package/node_modules/follow-redirects/index.js +10 -1
  346. package/node_modules/follow-redirects/package.json +1 -1
  347. package/node_modules/ip-address/README.md +104 -104
  348. package/node_modules/ip-address/dist/ipv4.js +7 -0
  349. package/node_modules/ip-address/dist/ipv6.js +7 -4
  350. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  351. package/node_modules/ip-address/package.json +2 -1
  352. package/node_modules/undici/README.md +25 -3
  353. package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  354. package/node_modules/undici/docs/docs/api/Client.md +11 -6
  355. package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  356. package/node_modules/undici/docs/docs/api/Errors.md +76 -1
  357. package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  358. package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  359. package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  360. package/node_modules/undici/docs/docs/index.md +12 -12
  361. package/node_modules/undici/docs/docs/type-map.json +66 -66
  362. package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  363. package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  364. package/node_modules/undici/lib/core/connect.js +10 -4
  365. package/node_modules/undici/lib/core/constants.js +12 -1
  366. package/node_modules/undici/lib/core/errors.js +38 -1
  367. package/node_modules/undici/lib/core/request.js +16 -1
  368. package/node_modules/undici/lib/core/symbols.js +2 -0
  369. package/node_modules/undici/lib/core/util.js +26 -1
  370. package/node_modules/undici/lib/dispatcher/agent.js +6 -2
  371. package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  372. package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  373. package/node_modules/undici/lib/dispatcher/client.js +4 -1
  374. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  375. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  376. package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  377. package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  378. package/node_modules/undici/lib/dispatcher/pool.js +11 -8
  379. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  380. package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  381. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  382. package/node_modules/undici/lib/handler/cache-handler.js +153 -15
  383. package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  384. package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  385. package/node_modules/undici/lib/handler/retry-handler.js +44 -11
  386. package/node_modules/undici/lib/interceptor/cache.js +11 -3
  387. package/node_modules/undici/lib/interceptor/decompress.js +22 -9
  388. package/node_modules/undici/lib/interceptor/dns.js +11 -0
  389. package/node_modules/undici/lib/interceptor/response-error.js +72 -28
  390. package/node_modules/undici/lib/milo/LICENSE.md +7 -0
  391. package/node_modules/undici/lib/milo/no-simd.js +1002 -0
  392. package/node_modules/undici/lib/milo/simd.js +1002 -0
  393. package/node_modules/undici/lib/mock/mock-agent.js +11 -0
  394. package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  395. package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  396. package/node_modules/undici/lib/util/cache.js +11 -5
  397. package/node_modules/undici/lib/web/cookies/util.js +19 -2
  398. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  399. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  400. package/node_modules/undici/lib/web/fetch/body.js +47 -38
  401. package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  402. package/node_modules/undici/lib/web/fetch/headers.js +2 -2
  403. package/node_modules/undici/lib/web/fetch/index.js +8 -4
  404. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  405. package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  406. package/node_modules/undici/package.json +9 -7
  407. package/node_modules/zod/package.json +1 -1
  408. package/node_modules/zod/v4/core/compile.cjs +8 -0
  409. package/node_modules/zod/v4/core/compile.js +8 -0
  410. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  411. package/node_modules/zod/v4/core/schemas.js +30 -0
  412. package/node_modules/zod/v4/core/util.cjs +15 -0
  413. package/node_modules/zod/v4/core/util.js +14 -0
  414. package/node_modules/zod/v4/core/versions.cjs +1 -1
  415. package/node_modules/zod/v4/core/versions.js +1 -1
  416. package/package.json +2 -2
  417. package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
  418. package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
@@ -16,6 +16,12 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ /**
20
+ * One AI SDK turn: request projection, provider steps, retries, tool
21
+ * settlement, steering, terminal events, and per-turn cleanup. Session-level
22
+ * construction and cross-turn routing remain in AiSdkBackend.
23
+ */
24
+ import { EVENT_WAIT_TOOL_NAME, isEventWaitYieldReceipt } from './event-wait-tool.js';
19
25
  import { DEFAULT_TOOL_MODE, isToolMode } from '@maka/core/tool-mode';
20
26
  import { resolveEffectiveOrchestration, } from '@maka/core/orchestration';
21
27
  import { stripUndefinedDeep } from '@maka/core/tool-args-identity';
@@ -39,6 +45,7 @@ import { portableApplyPatchTool } from './apply-patch-profile.js';
39
45
  import { RunTrace } from './run-trace.js';
40
46
  import { REQUEST_SANDBOX_BOUNDARY_TOOL_NAME, SANDBOX_BOUNDARY_DENIED_FOR_TURN, SANDBOX_BOUNDARY_FINALIZATION_PROMPT, requiredSandboxBoundaryToolNames, } from './sandbox-boundary-tool.js';
41
47
  import { buildRuntimeEventModelReplayPlan, appendPriorUnknownToolResponses, buildSteeringEnvelope, collectToolActivityTurnIds, compatibleProviderReasoningReplayEventIds, formatTextWithInlineRefs, inspectPriorUnknownToolOutcomes, steeringMessagesMissingFromBase, steeringModelMessage, } from './model-history.js';
48
+ import { changedRuntimeContexts } from './runtime-context.js';
42
49
  import { toolSchemaCharsForDiagnostics, requestCompositionToolSchemas, stableHash, toolCatalogHash, } from './request-shape.js';
43
50
  import { toolAvailabilityHash } from './tool-availability.js';
44
51
  import { hasFinalizedReasoning } from './ai-sdk-message-projection.js';
@@ -383,8 +390,8 @@ export class AiSdkTurn {
383
390
  abortController = new AbortController();
384
391
  activeTools;
385
392
  aborted = false;
386
- loopStopRequested = false;
387
- loopStopReason;
393
+ stopRequested = false;
394
+ turnYield;
388
395
  handoffPaused = false;
389
396
  watchdog = null;
390
397
  runTrace = null;
@@ -424,8 +431,8 @@ export class AiSdkTurn {
424
431
  await this.toolRuntime.endTurn(this.aborted ? 'aborted' : 'completed');
425
432
  }
426
433
  requestStop(reason, mode) {
434
+ this.stopRequested = true;
427
435
  if (mode === 'after_step') {
428
- this.loopStopRequested = true;
429
436
  this.runTrace?.abortRequested(reason);
430
437
  return;
431
438
  }
@@ -433,6 +440,9 @@ export class AiSdkTurn {
433
440
  this.abortController.abort();
434
441
  this.runTrace?.abortRequested(reason);
435
442
  }
443
+ get loopStopReason() {
444
+ return this.stopRequested ? 'user_stop' : this.turnYield;
445
+ }
436
446
  async endAbortedTools() {
437
447
  await this.toolRuntime.endTurn('aborted');
438
448
  }
@@ -1086,6 +1096,24 @@ export class AiSdkTurn {
1086
1096
  ? currentTurnMessages
1087
1097
  : [...priorReplay.messages, ...currentTurnMessages];
1088
1098
  };
1099
+ const appendRuntimeContexts = async (history, contexts) => {
1100
+ const additions = changedRuntimeContexts(contexts, history).map((context) => ({
1101
+ context,
1102
+ id: this.deps.newId(),
1103
+ }));
1104
+ for (const { context, id } of additions) {
1105
+ queue.push({ type: 'runtime_context', id, turnId, ts: this.deps.now(), ...context });
1106
+ }
1107
+ if (additions.length === 0)
1108
+ return history;
1109
+ // Persist before dispatch; retries reuse the same snapshot. Context
1110
+ // removed by compaction is refreshed after that fold, not lost in it.
1111
+ await queue.waitUntilConsumedThroughCurrent();
1112
+ return [
1113
+ ...history,
1114
+ ...additions.map(({ context, id }) => this.deps.messageProjection.materializeRuntimeContext(context, id)),
1115
+ ];
1116
+ };
1089
1117
  // Tool Availability describes the provider-visible (active) subset. A
1090
1118
  // group loaded this turn expands that subset on later requests, so the
1091
1119
  // terminal trace is refined against the final active set below.
@@ -1120,7 +1148,7 @@ export class AiSdkTurn {
1120
1148
  let finishFeedback;
1121
1149
  let result;
1122
1150
  let providerOutcome;
1123
- let finishReason = 'stop';
1151
+ let terminalStopReason;
1124
1152
  let terminalProviderError;
1125
1153
  agentLoop: for (;;) {
1126
1154
  ({ plan, providerTools, modelTools, nestedTools } = snapshotStepTools());
@@ -1182,7 +1210,6 @@ export class AiSdkTurn {
1182
1210
  activeTools,
1183
1211
  };
1184
1212
  };
1185
- const dynamicContextMessages = (resolvedSystemPrompt.contexts ?? []).map(({ text }) => ({ role: 'user', content: text }));
1186
1213
  const shaped = requestProjection
1187
1214
  ? await requestProjection({
1188
1215
  completedSteps: completedProviderSteps,
@@ -1214,9 +1241,10 @@ export class AiSdkTurn {
1214
1241
  })
1215
1242
  : undefined;
1216
1243
  providerRequestTracker?.setStep(runtimeSteps, requestCompositionId);
1217
- let attemptMessages = projectedMessages;
1244
+ let attemptMessages = await appendRuntimeContexts(projectedMessages, resolvedSystemPrompt.contexts ?? []);
1218
1245
  let overflowRecoveryMaxOutputTokens;
1219
1246
  let providerAttempt = 0;
1247
+ let pendingRetryReason;
1220
1248
  const returnedToolCalls = [];
1221
1249
  const providerToolInputs = new Map();
1222
1250
  let providerStepUsage;
@@ -1237,8 +1265,7 @@ export class AiSdkTurn {
1237
1265
  let attemptSawReplayBarrier = false;
1238
1266
  const attemptHasNoObservableOutput = () => !attemptSawVisibleContent && !attemptSawToolActivity && !attemptSawReplayBarrier;
1239
1267
  const attemptCanReplay = () => !attemptSawToolActivity && !attemptSawReplayBarrier;
1240
- // Request-only facts must survive history replacement and overflow recovery.
1241
- const dispatchMessages = [...attemptMessages, ...dynamicContextMessages];
1268
+ const dispatchMessages = attemptMessages;
1242
1269
  this.memorySourceMessages = dispatchMessages;
1243
1270
  this.memorySourceEventMessagePositions =
1244
1271
  this.deps.messageProjection.memoryEventMessagePositions(dispatchMessages);
@@ -1261,6 +1288,24 @@ export class AiSdkTurn {
1261
1288
  // rebuilt in place by overflow recovery, and the boundary it folded
1262
1289
  // under must travel with that rebuild, not with the step.
1263
1290
  const historyCompactBoundary = requestHistoryCompactBoundary();
1291
+ // Stop can arrive during handoff, retry backoff, or overflow recovery.
1292
+ if (this.loopStopReason) {
1293
+ terminalStopReason = this.loopStopReason;
1294
+ break agentLoop;
1295
+ }
1296
+ if (pendingRetryReason) {
1297
+ queue.push({
1298
+ type: 'provider_retry',
1299
+ id: this.deps.newId(),
1300
+ turnId,
1301
+ ts: this.deps.now(),
1302
+ phase: 'started',
1303
+ attempt: providerAttempt,
1304
+ maxAttempts: MAX_PROVIDER_ATTEMPTS_PER_STEP,
1305
+ reason: pendingRetryReason,
1306
+ });
1307
+ pendingRetryReason = undefined;
1308
+ }
1264
1309
  result = await this.deps.modelAdapter.startStream({
1265
1310
  model,
1266
1311
  messages: dispatchMessages,
@@ -1590,7 +1635,7 @@ export class AiSdkTurn {
1590
1635
  !attemptSawToolInput &&
1591
1636
  returnedToolCalls.length === 0))
1592
1637
  sawUnusableStepUsage = true;
1593
- if (this.loopStopRequested) {
1638
+ if (this.loopStopReason) {
1594
1639
  terminalProviderError = failure;
1595
1640
  terminalProviderErrorReason =
1596
1641
  lastCompletedStepHadToolResult && failure.kind === 'timeout'
@@ -1627,7 +1672,7 @@ export class AiSdkTurn {
1627
1672
  })
1628
1673
  : undefined;
1629
1674
  if (recovered) {
1630
- attemptMessages = recovered.messages;
1675
+ attemptMessages = await appendRuntimeContexts(recovered.messages, resolvedSystemPrompt.contexts ?? []);
1631
1676
  overflowRecoveryMaxOutputTokens = Math.min(this.deps.modelAdapter.maxOutputTokens() ?? CONTEXT_RECOVERY_MAX_OUTPUT_TOKENS, CONTEXT_RECOVERY_MAX_OUTPUT_TOKENS);
1632
1677
  continue;
1633
1678
  }
@@ -1710,16 +1755,7 @@ export class AiSdkTurn {
1710
1755
  reason,
1711
1756
  });
1712
1757
  await this.deps.providerRetrySleep(delayMs, turnAbortController.signal);
1713
- queue.push({
1714
- type: 'provider_retry',
1715
- id: this.deps.newId(),
1716
- turnId,
1717
- ts: this.deps.now(),
1718
- phase: 'started',
1719
- attempt: nextAttempt,
1720
- maxAttempts,
1721
- reason,
1722
- });
1758
+ pendingRetryReason = reason;
1723
1759
  continue;
1724
1760
  }
1725
1761
  // Unrecoverable (not context-length, this step's attempt spent,
@@ -1746,7 +1782,7 @@ export class AiSdkTurn {
1746
1782
  const providerStepId = currentStepMessageId;
1747
1783
  if (providerOutcome.kind !== 'completed')
1748
1784
  throw providerOutcome.failure;
1749
- finishReason = providerOutcome.finishReason;
1785
+ const finishReason = providerOutcome.finishReason;
1750
1786
  await queue.waitUntilConsumedThroughCurrent();
1751
1787
  let toolRequestedFinish = false;
1752
1788
  if (returnedToolCalls.length > 0) {
@@ -1761,6 +1797,12 @@ export class AiSdkTurn {
1761
1797
  await loadDurableTurnEvents();
1762
1798
  }
1763
1799
  const toolsByName = new Map(providerTools.map((tool) => [tool.name, tool]));
1800
+ // A wait controls the lifetime of the whole Turn. Refuse the entire
1801
+ // mixed step before dispatch, rather than letting the first call win
1802
+ // the ordinary exclusive-step gate and leaving a registered orphan.
1803
+ const mixedEventWait = returnedToolCalls.length > 1 &&
1804
+ toolsByName.has(EVENT_WAIT_TOOL_NAME) &&
1805
+ returnedToolCalls.some((call) => call.toolName === EVENT_WAIT_TOOL_NAME);
1764
1806
  const settlementOutcomes = await Promise.allSettled(returnedToolCalls.map(async (toolCall) => {
1765
1807
  if (toolCall.providerExecuted) {
1766
1808
  throw new Error(`Provider-executed tool call "${toolCall.toolName}" is outside the main-agent tool loop`);
@@ -1771,18 +1813,20 @@ export class AiSdkTurn {
1771
1813
  if (deniedBoundaryRequest) {
1772
1814
  toolRuntime.forceSandboxBoundaryFinalization();
1773
1815
  }
1774
- const blockedToolCall = sandboxBoundaryFinalizationStep || deniedBoundaryRequest;
1816
+ const blockedToolCall = mixedEventWait || sandboxBoundaryFinalizationStep || deniedBoundaryRequest;
1775
1817
  const requestedTool = blockedToolCall
1776
1818
  ? undefined
1777
1819
  : toolsByName.get(toolCall.toolName);
1778
1820
  const tool = requestedTool ?? toolsByName.get(INVALID_TOOL_NAME);
1779
1821
  if (!tool)
1780
1822
  throw new Error('Runtime invalid-tool fallback is unavailable');
1781
- const unavailableError = sandboxBoundaryFinalizationStep
1782
- ? 'Sandbox boundary finalization does not permit tool execution.'
1783
- : deniedBoundaryRequest
1784
- ? SANDBOX_BOUNDARY_DENIED_FOR_TURN
1785
- : 'returned tool is unavailable';
1823
+ const unavailableError = mixedEventWait
1824
+ ? 'WaitForEvent requires a step containing exactly one tool call. No tools in this mixed step ran.'
1825
+ : sandboxBoundaryFinalizationStep
1826
+ ? 'Sandbox boundary finalization does not permit tool execution.'
1827
+ : deniedBoundaryRequest
1828
+ ? SANDBOX_BOUNDARY_DENIED_FOR_TURN
1829
+ : 'returned tool is unavailable';
1786
1830
  return await toolRuntime.settleToolCall({
1787
1831
  tool,
1788
1832
  turnId,
@@ -1826,6 +1870,11 @@ export class AiSdkTurn {
1826
1870
  definition.finishTurnOnSuccess &&
1827
1871
  !settlement.providerError)
1828
1872
  toolRequestedFinish = true;
1873
+ if (returnedToolCalls.length === 1 &&
1874
+ !settlement.providerError &&
1875
+ isEventWaitYieldReceipt(settlement.result)) {
1876
+ this.turnYield = 'event_wait';
1877
+ }
1829
1878
  if (isPlanToolResult(settlement.result)) {
1830
1879
  this.handlePlanToolResult(settlement.result, queue);
1831
1880
  }
@@ -1839,9 +1888,7 @@ export class AiSdkTurn {
1839
1888
  // an entire completed batch across the next provider request.
1840
1889
  settlementOutcomes.length = 0;
1841
1890
  await queue.waitUntilConsumedThroughCurrent();
1842
- const continuationWillRun = (maxSteps === undefined || runtimeSteps < maxSteps) &&
1843
- !this.loopStopRequested &&
1844
- !this.aborted;
1891
+ const continuationWillRun = (maxSteps === undefined || runtimeSteps < maxSteps) && !this.loopStopReason;
1845
1892
  if (continuationWillRun && providerOutcome.continuation === 'pending') {
1846
1893
  const persistedProjection = await loadDurableTurnProjection();
1847
1894
  const responseMessages = persistedOpenAiResponsesStepMessages(attemptMessages, persistedProjection, returnedToolCalls.map((toolCall) => toolCall.toolCallId));
@@ -1858,119 +1905,72 @@ export class AiSdkTurn {
1858
1905
  ...(providerStepUsage ? { usage: providerStepUsage } : {}),
1859
1906
  });
1860
1907
  lastCompletedStepHadToolResult = returnedToolCalls.length > 0;
1861
- // Finish only after the tool result is durably consumed. The Host can
1862
- // veto completion (for example, new Inbox input raced with Sleep).
1863
- if (toolRequestedFinish && !this.aborted && !this.loopStopRequested) {
1864
- const decision = await this.deps.backend.beforeTurnFinish?.({
1865
- sessionId: this.deps.backend.sessionId,
1866
- turnId,
1867
- signal: turnAbortController.signal,
1868
- });
1869
- if (!decision || decision.allow) {
1870
- finishReason = 'stop';
1871
- this.deps.modelAdapter.clearContinuation(this.turnId);
1872
- break agentLoop;
1873
- }
1874
- finishFeedback = decision.feedback;
1875
- }
1876
1908
  const stepLimitReached = maxSteps !== undefined && runtimeSteps >= maxSteps;
1877
1909
  if (sandboxBoundaryFinalizationStep ||
1878
1910
  (stepLimitReached &&
1879
1911
  (toolRuntime.shouldFinalizeSandboxBoundary() ||
1880
1912
  toolRuntime.hasSandboxBoundaryDenial()))) {
1881
- this.loopStopReason = 'permission_handoff';
1882
- this.loopStopRequested = true;
1883
- }
1884
- const mayTakeAnotherStep = !stepLimitReached && !this.loopStopRequested && !this.aborted;
1885
- if (returnedToolCalls.length > 0 && mayTakeAnotherStep) {
1886
- if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
1887
- this.handoffPaused = true;
1888
- break agentLoop;
1889
- }
1890
- if (this.aborted || this.loopStopRequested)
1891
- break agentLoop;
1892
- currentStepMessageId = this.deps.newId();
1893
- continue agentLoop;
1913
+ this.turnYield = 'permission_handoff';
1894
1914
  }
1915
+ let finishCandidateReason = returnedToolCalls.length > 0 && !toolRequestedFinish
1916
+ ? undefined
1917
+ : toolRequestedFinish
1918
+ ? 'end_turn'
1919
+ : this.deps.modelAdapter.mapFinishReason(finishReason);
1895
1920
  // Enforce Host prerequisites locally: some providers reject required
1896
1921
  // tool_choice in thinking mode. Never silently complete without the
1897
1922
  // receipt; replay the draft and per-step reminder for bounded repair.
1898
1923
  if (returnedToolCalls.length === 0 &&
1899
1924
  resolvedSystemPrompt.requireToolCall &&
1900
- !this.loopStopRequested &&
1901
- !this.aborted) {
1902
- if (!mayTakeAnotherStep ||
1925
+ !this.loopStopReason) {
1926
+ if (stepLimitReached ||
1903
1927
  !this.deps.backend.loadTurnRuntimeEvents ||
1904
1928
  ++missingPrerequisiteAttempts > 2) {
1905
1929
  throw new Error('Required turn prerequisite was not recorded; cannot complete this response.');
1906
1930
  }
1907
- await queue.waitUntilConsumedThroughCurrent();
1908
- if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
1909
- this.handoffPaused = true;
1910
- break agentLoop;
1911
- }
1912
- if (this.aborted || this.loopStopRequested)
1913
- break agentLoop;
1914
- currentStepMessageId = this.deps.newId();
1915
- continue agentLoop;
1931
+ finishCandidateReason = undefined;
1916
1932
  }
1917
- // Continuing the turn needs the durable current-run reader, for the
1918
- // same reason the tool-call edge above demands it: the next request
1919
- // has to carry the assistant output this step just produced, and only
1920
- // the ledger projection has it. The no-reader fallback at the top of
1921
- // the loop appends steering alone, which would ask the model to
1922
- // redirect work it cannot see. Without a reader this edge is skipped
1923
- // rather than throwing — the turn still completes and the Host folds
1924
- // the message into the next Turn, which is today's behaviour.
1925
- if (mayTakeAnotherStep && this.deps.backend.loadTurnRuntimeEvents) {
1926
- // Last chance for a steer that landed after this turn's final
1927
- // tool-call boundary — including the only boundary a tool-free
1928
- // turn has, which precedes the model's first token. Without it the
1929
- // message is never pulled at all, and whether Steer works would
1930
- // depend on the model happening to call a tool afterwards (#3529).
1931
- // A step-limited turn deliberately skips this: its budget is spent,
1932
- // and the Host folds the message into the next Turn instead.
1933
+ // The Host carries steering left unconsumed here into the next Turn.
1934
+ if (finishCandidateReason !== undefined &&
1935
+ !toolRequestedFinish &&
1936
+ !stepLimitReached &&
1937
+ !this.loopStopReason &&
1938
+ this.deps.backend.loadTurnRuntimeEvents) {
1933
1939
  const injectedBefore = this.injectedSteeringMessages.length;
1934
1940
  await this.drainSteeringInto(input, queue);
1935
- // Re-read the stop flags: the drain awaits a durable push, so an
1936
- // `after_step` stop or an abort can land while it is in flight, and
1937
- // `mayTakeAnotherStep` is stale by now. Stop wins — the message is
1938
- // already durable, so the Host folds it into the next Turn.
1939
- if (this.injectedSteeringMessages.length > injectedBefore &&
1940
- !this.loopStopRequested &&
1941
- !this.aborted) {
1942
- await queue.waitUntilConsumedThroughCurrent();
1943
- if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
1944
- this.handoffPaused = true;
1945
- break agentLoop;
1946
- }
1947
- if (this.aborted || this.loopStopRequested)
1948
- break agentLoop;
1949
- currentStepMessageId = this.deps.newId();
1950
- continue agentLoop;
1951
- }
1941
+ if (this.injectedSteeringMessages.length > injectedBefore)
1942
+ finishCandidateReason = undefined;
1952
1943
  }
1953
- if (mayTakeAnotherStep &&
1954
- returnedToolCalls.length === 0 &&
1955
- this.deps.backend.beforeTurnFinish &&
1956
- this.deps.backend.loadTurnRuntimeEvents &&
1957
- this.deps.modelAdapter.mapFinishReason(finishReason) === 'end_turn') {
1958
- const decision = await this.deps.backend.beforeTurnFinish({
1944
+ // Finishing needs Host approval even when no continuation is possible.
1945
+ if (finishCandidateReason === 'end_turn' && !this.loopStopReason) {
1946
+ const finishDecision = await this.deps.backend.beforeTurnFinish?.({
1959
1947
  sessionId: this.deps.backend.sessionId,
1960
1948
  turnId,
1961
1949
  signal: turnAbortController.signal,
1962
1950
  });
1963
- if (!decision.allow && !this.aborted && !this.loopStopRequested) {
1964
- if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
1965
- this.handoffPaused = true;
1966
- break agentLoop;
1967
- }
1968
- finishFeedback = decision.feedback;
1969
- currentStepMessageId = this.deps.newId();
1970
- continue agentLoop;
1951
+ if (finishDecision && !finishDecision.allow) {
1952
+ finishFeedback = finishDecision.feedback;
1953
+ finishCandidateReason = undefined;
1971
1954
  }
1955
+ else if (toolRequestedFinish) {
1956
+ this.deps.modelAdapter.clearContinuation(this.turnId);
1957
+ }
1958
+ }
1959
+ terminalStopReason =
1960
+ this.loopStopReason ??
1961
+ finishCandidateReason ??
1962
+ (stepLimitReached ? 'step_limit' : undefined);
1963
+ if (terminalStopReason)
1964
+ break agentLoop;
1965
+ if (!this.deps.backend.loadTurnRuntimeEvents) {
1966
+ throw new Error('durable current-run reader is required for turn continuation');
1972
1967
  }
1973
- break agentLoop;
1968
+ await queue.waitUntilConsumedThroughCurrent();
1969
+ if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
1970
+ this.handoffPaused = true;
1971
+ break agentLoop;
1972
+ }
1973
+ currentStepMessageId = this.deps.newId();
1974
1974
  }
1975
1975
  // Refine Tool Availability against the final active set. Deferred
1976
1976
  // loading may add tools, while boundary convergence may remove them;
@@ -1986,7 +1986,7 @@ export class AiSdkTurn {
1986
1986
  // silently drop prior requests. An unusable sample in ANY request fails
1987
1987
  // the whole record closed (#972).
1988
1988
  try {
1989
- const attemptTotalUsage = providerOutcome.usage;
1989
+ const attemptTotalUsage = providerOutcome?.usage;
1990
1990
  tokenUsage = sawUnusableStepUsage ? undefined : (completedStepUsage ?? attemptTotalUsage);
1991
1991
  if (tokenUsage) {
1992
1992
  tokenUsageCostUsd = this.deps.providerTelemetry.normalizedUsageCostUsd(tokenUsage);
@@ -2090,10 +2090,9 @@ export class AiSdkTurn {
2090
2090
  // seals the drained stream; no complete/abort event ends the logical Turn.
2091
2091
  if (this.handoffPaused)
2092
2092
  return;
2093
- const stopReason = this.loopStopReason ??
2094
- (maxSteps !== undefined && finishReason === 'tool-calls'
2095
- ? 'step_limit'
2096
- : this.mapFinishReason(finishReason));
2093
+ const stopReason = this.loopStopReason ?? terminalStopReason;
2094
+ if (!stopReason)
2095
+ throw new Error('Turn ended without a terminal decision');
2097
2096
  trace.modelStreamCompleted(stopReason);
2098
2097
  const completeEvent = {
2099
2098
  type: 'complete',
@@ -2261,7 +2260,7 @@ export class AiSdkTurn {
2261
2260
  })),
2262
2261
  isFatalToolError: isRuntimeCommitBoundaryError,
2263
2262
  callTool: async (name, input, signal) => {
2264
- if (this.loopStopRequested)
2263
+ if (this.loopStopReason)
2265
2264
  throw new Error('The turn has yielded; no further tools may run.');
2266
2265
  const tool = snapshot.get(name);
2267
2266
  if (!tool)
@@ -2323,8 +2322,7 @@ export class AiSdkTurn {
2323
2322
  revision: proposal.revision,
2324
2323
  storeVersion: result.storeVersion,
2325
2324
  });
2326
- this.loopStopReason = 'plan_handoff';
2327
- this.loopStopRequested = true;
2325
+ this.turnYield = 'plan_handoff';
2328
2326
  return;
2329
2327
  }
2330
2328
  const traceType = result.kind;
@@ -2345,11 +2343,7 @@ export class AiSdkTurn {
2345
2343
  liveOperatorCount: result.liveOperatorCount,
2346
2344
  reason: result.reason,
2347
2345
  });
2348
- this.loopStopReason = 'graph_yield';
2349
- this.loopStopRequested = true;
2350
- }
2351
- mapFinishReason(reason) {
2352
- return this.deps.modelAdapter.mapFinishReason(reason);
2346
+ this.turnYield = 'graph_yield';
2353
2347
  }
2354
2348
  makeErrorEvent(turnId, err, reasonOverride) {
2355
2349
  return this.deps.modelAdapter.makeErrorEvent(turnId, err, reasonOverride);
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { resolveBotMessageHandling, } from '@maka/core/bot-chat-settings';
19
20
  import { generalizedErrorMessage } from '@maka/core/redaction';
20
21
  import { BOT_PROVIDERS } from '@maka/core/settings';
21
22
  import { DingTalkBotBridge } from './dingtalk-bridge.js';
@@ -69,7 +70,19 @@ export class BotRegistry {
69
70
  const bridge = this.bridges.get(platform);
70
71
  if (!bridge || typeof bridge.sendTypingIndicator !== 'function')
71
72
  return false;
72
- return bridge.sendTypingIndicator(chatId);
73
+ return bridge.sendTypingIndicator(chatId).catch(() => false);
74
+ }
75
+ async cancelTypingIndicator(platform, chatId) {
76
+ const bridge = this.bridges.get(platform);
77
+ if (!bridge?.cancelTypingIndicator)
78
+ return false;
79
+ return bridge.cancelTypingIndicator(chatId).catch(() => false);
80
+ }
81
+ async getMessageReadStatus(platform, messageId, userId) {
82
+ const bridge = this.bridges.get(platform);
83
+ return ((await bridge
84
+ ?.getMessageReadStatus?.(messageId, userId)
85
+ .catch(() => ({ state: 'unknown' }))) ?? { state: 'unknown' });
73
86
  }
74
87
  async stopAll() {
75
88
  const next = this.applyQueue.then(() => this.stopAllNow(), () => this.stopAllNow());
@@ -77,7 +90,10 @@ export class BotRegistry {
77
90
  return next;
78
91
  }
79
92
  async applySettingsNow(settings) {
80
- await Promise.all(BOT_PROVIDERS.map((provider) => this.reconcileOne(provider, settings.channels[provider])));
93
+ await Promise.all(BOT_PROVIDERS.map((provider) => this.reconcileOne(provider, {
94
+ ...settings.channels[provider],
95
+ messageHandling: resolveBotMessageHandling(settings, provider),
96
+ })));
81
97
  }
82
98
  async stopAllNow() {
83
99
  await Promise.all([...this.bridges.values()].map((bridge) => bridge.stop().catch(() => { })));
@@ -116,7 +132,7 @@ export class BotRegistry {
116
132
  }
117
133
  this.statuses.delete(platform);
118
134
  const bridge = platform === 'wechat'
119
- ? new WechatBridge(settings)
135
+ ? new WechatBridge(settings, this.deps.wechatContextDirectory)
120
136
  : platform === 'wecom'
121
137
  ? new WeComBotBridge(settings)
122
138
  : platform === 'feishu'