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
@@ -306,6 +306,22 @@ class BalancedPoolMissingUpstreamError extends UndiciError {
306
306
  }
307
307
  }
308
308
 
309
+ const kWebAssemblyNotSupportedError = Symbol.for('undici.error.ERR_WEBASSEMBLY_NOT_SUPPORTED')
310
+ class WebAssemblyNotSupportedError extends Error {
311
+ constructor (message) {
312
+ super(message || 'WebAssembly is not supported in this environment, but is required for HTTP/1 parsing')
313
+ this.code = 'ERR_WEBASSEMBLY_NOT_SUPPORTED'
314
+ }
315
+
316
+ static [Symbol.hasInstance] (instance) {
317
+ return instance && instance[kWebAssemblyNotSupportedError] === true
318
+ }
319
+
320
+ get [kWebAssemblyNotSupportedError] () {
321
+ return true
322
+ }
323
+ }
324
+
309
325
  const kHTTPParserError = Symbol.for('undici.error.UND_ERR_HTTP_PARSER')
310
326
  class HTTPParserError extends Error {
311
327
  constructor (message, code, data) {
@@ -365,13 +381,14 @@ class RequestRetryError extends UndiciError {
365
381
 
366
382
  const kResponseError = Symbol.for('undici.error.UND_ERR_RESPONSE')
367
383
  class ResponseError extends UndiciError {
368
- constructor (message, code, { headers, body }) {
384
+ constructor (message, code, { headers, body, bodyTruncated = false }) {
369
385
  super(message)
370
386
  this.name = 'ResponseError'
371
387
  this.message = message || 'Response error'
372
388
  this.code = 'UND_ERR_RESPONSE'
373
389
  this.statusCode = code
374
390
  this.body = body
391
+ this.bodyTruncated = bodyTruncated
375
392
  this.headers = headers
376
393
  }
377
394
 
@@ -422,6 +439,24 @@ class ProxyConnectionError extends UndiciError {
422
439
  }
423
440
  }
424
441
 
442
+ const kMaxRedirectsError = Symbol.for('undici.error.UND_ERR_REDIRECT_MAX')
443
+ class MaxRedirectsError extends UndiciError {
444
+ constructor (message) {
445
+ super(message)
446
+ this.name = 'MaxRedirectsError'
447
+ this.message = message || 'max redirects'
448
+ this.code = 'UND_ERR_REDIRECT_MAX'
449
+ }
450
+
451
+ static [Symbol.hasInstance] (instance) {
452
+ return instance && instance[kMaxRedirectsError] === true
453
+ }
454
+
455
+ get [kMaxRedirectsError] () {
456
+ return true
457
+ }
458
+ }
459
+
425
460
  const kMaxOriginsReachedError = Symbol.for('undici.error.UND_ERR_MAX_ORIGINS_REACHED')
426
461
  class MaxOriginsReachedError extends UndiciError {
427
462
  constructor (message) {
@@ -469,6 +504,7 @@ class MessageSizeExceededError extends UndiciError {
469
504
 
470
505
  module.exports = {
471
506
  AbortError,
507
+ WebAssemblyNotSupportedError,
472
508
  HTTPParserError,
473
509
  UndiciError,
474
510
  HeadersTimeoutError,
@@ -492,6 +528,7 @@ module.exports = {
492
528
  SecureProxyConnectionError,
493
529
  ProxyConnectionError,
494
530
  MaxOriginsReachedError,
531
+ MaxRedirectsError,
495
532
  Socks5ProxyError,
496
533
  MessageSizeExceededError
497
534
  }
@@ -206,7 +206,12 @@ class Request {
206
206
  this.body = body.byteLength ? Buffer.from(body) : null
207
207
  } else if (typeof body === 'string') {
208
208
  this.body = body.length ? Buffer.from(body) : null
209
- } else if (isFormDataLike(body) || isIterable(body) || isBlobLike(body)) {
209
+ } else if (isFormDataLike(body)) {
210
+ if (!isUndiciFormData(body)) {
211
+ throw new InvalidArgumentError('body must be a FormData created by this undici package instance; FormData from other sources, such as the built-in FormData provided by Node.js, is not supported')
212
+ }
213
+ this.body = body
214
+ } else if (isIterable(body) || isBlobLike(body)) {
210
215
  this.body = body
211
216
  } else {
212
217
  throw new InvalidArgumentError('body must be a string, a Buffer, a Readable stream, an iterable, or an async iterable')
@@ -564,4 +569,14 @@ function processHeader (request, key, val) {
564
569
  }
565
570
  }
566
571
 
572
+ let isFormData
573
+
574
+ function isUndiciFormData (body) {
575
+ if (isFormData === undefined) {
576
+ require('../web/fetch/formdata')
577
+ isFormData = require('../web/webidl').webidl.is.FormData
578
+ }
579
+ return isFormData(body)
580
+ }
581
+
567
582
  module.exports = Request
@@ -6,6 +6,7 @@ module.exports = {
6
6
  kDispatch: Symbol('dispatch'),
7
7
  kUrl: Symbol('url'),
8
8
  kRequestOrigin: Symbol('request origin'),
9
+ kRedirectCacheControl: Symbol('redirect cache control'),
9
10
  kOriginless: Symbol('originless'),
10
11
  kWriting: Symbol('writing'),
11
12
  kResuming: Symbol('resuming'),
@@ -72,6 +73,7 @@ module.exports = {
72
73
  kRemoteSettings: Symbol('http2session remote settings'),
73
74
  kHTTP2Stream: Symbol('http2session client stream'),
74
75
  kPingInterval: Symbol('ping interval'),
76
+ kUseMilo: Symbol('use milo'),
75
77
  kNoProxyAgent: Symbol('no proxy agent'),
76
78
  kHttpProxyAgent: Symbol('http proxy agent'),
77
79
  kHttpsProxyAgent: Symbol('https proxy agent'),
@@ -387,7 +387,7 @@ function destroy (stream, err) {
387
387
  }
388
388
  }
389
389
 
390
- const KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)/
390
+ const KEEPALIVE_TIMEOUT_EXPR = /(?:^|,)[\t ]*timeout=(\d+)/i
391
391
  /**
392
392
  * @param {string} val
393
393
  * @returns {number | null}
@@ -417,6 +417,30 @@ function bufferToLowerCasedHeaderName (value) {
417
417
  return tree.lookup(value) ?? value.toString('latin1').toLowerCase()
418
418
  }
419
419
 
420
+ /**
421
+ * Writes a header onto a plain object without going through the
422
+ * `Object.prototype` `__proto__` setter. Plain assignment there drops a string
423
+ * value and, when the value is an array, replaces the object's prototype
424
+ * instead of storing anything. Every other name is a normal assignment.
425
+ *
426
+ * @param {Record<string, string | string[]>} obj Accumulator to write onto
427
+ * @param {string} key Header name
428
+ * @param {string | string[]} value Header value
429
+ * @returns {void}
430
+ */
431
+ function setHeader (obj, key, value) {
432
+ if (key === '__proto__') {
433
+ Object.defineProperty(obj, key, {
434
+ value,
435
+ enumerable: true,
436
+ configurable: true,
437
+ writable: true
438
+ })
439
+ } else {
440
+ obj[key] = value
441
+ }
442
+ }
443
+
420
444
  /**
421
445
  * @param {(Buffer | string)[]} headers
422
446
  * @param {Record<string, string | string[]>} [obj]
@@ -984,6 +1008,7 @@ module.exports = {
984
1008
  toRawHeaders,
985
1009
  encodeRawHeaders,
986
1010
  parseHeaders,
1011
+ setHeader,
987
1012
  parseKeepAliveTimeout,
988
1013
  destroy,
989
1014
  bodyLength,
@@ -22,7 +22,7 @@ function defaultFactory (origin, opts) {
22
22
  }
23
23
 
24
24
  class Agent extends DispatcherBase {
25
- constructor ({ factory = defaultFactory, maxOrigins = Infinity, connect, ...options } = {}) {
25
+ constructor ({ factory = defaultFactory, maxOrigins = Infinity, connect, tls, ...options } = {}) {
26
26
  if (typeof factory !== 'function') {
27
27
  throw new InvalidArgumentError('factory must be a function.')
28
28
  }
@@ -41,7 +41,11 @@ class Agent extends DispatcherBase {
41
41
  connect = { ...connect }
42
42
  }
43
43
 
44
- this[kOptions] = { ...util.deepClone(options), maxOrigins, connect }
44
+ if (tls && typeof tls !== 'function') {
45
+ tls = { ...tls }
46
+ }
47
+
48
+ this[kOptions] = { ...util.deepClone(options), maxOrigins, connect, tls }
45
49
  this[kFactory] = factory
46
50
  this[kClients] = new Map()
47
51
  this[kOrigins] = new Set()
@@ -17,6 +17,7 @@ const {
17
17
  InformationalError,
18
18
  BodyTimeoutError,
19
19
  HTTPParserError,
20
+ WebAssemblyNotSupportedError,
20
21
  ResponseExceededMaxSizeError
21
22
  } = require('../core/errors.js')
22
23
  const {
@@ -51,10 +52,15 @@ const {
51
52
  kOnError,
52
53
  kResume,
53
54
  kHTTPContext,
54
- kClosed
55
+ kClosed,
56
+ kUseMilo
55
57
  } = require('../core/symbols.js')
56
58
 
57
59
  const constants = require('../llhttp/constants.js')
60
+ // Node.js core bundles only llhttp; experimental Milo remains available in npm builds.
61
+ const { H1Parser, getMiloEnabled } = typeof esbuildDetection === 'undefined'
62
+ ? require('./parser-h1.js')
63
+ : {}
58
64
  const EMPTY_BUF = Buffer.alloc(0)
59
65
  const FastBuffer = Buffer[Symbol.species]
60
66
  const removeAllListeners = util.removeAllListeners
@@ -66,6 +72,11 @@ const kTypeOfService = Symbol('kTypeOfService')
66
72
  let extractBody
67
73
 
68
74
  function lazyllhttp () {
75
+ // Check only when HTTP/1 needs the parser, so other APIs remain usable without WASM.
76
+ if (typeof WebAssembly === 'undefined') {
77
+ throw new WebAssemblyNotSupportedError()
78
+ }
79
+
69
80
  const llhttpWasmData = process.env.JEST_WORKER_ID ? require('../llhttp/llhttp-wasm.js') : undefined
70
81
 
71
82
  let mod
@@ -88,8 +99,7 @@ function lazyllhttp () {
88
99
  if (useWasmSIMD) {
89
100
  try {
90
101
  mod = new WebAssembly.Module(require('../llhttp/llhttp_simd-wasm.js'))
91
- } catch {
92
- }
102
+ } catch {}
93
103
  }
94
104
 
95
105
  if (!mod) {
@@ -126,7 +136,7 @@ function lazyllhttp () {
126
136
  * @param {number} p
127
137
  * @returns {number}
128
138
  */
129
- wasm_on_message_begin: (p) => {
139
+ wasm_on_message_begin: p => {
130
140
  assert(currentParser.ptr === p)
131
141
  return currentParser.onMessageBegin()
132
142
  },
@@ -178,11 +188,10 @@ function lazyllhttp () {
178
188
  * @param {number} p
179
189
  * @returns {number}
180
190
  */
181
- wasm_on_message_complete: (p) => {
191
+ wasm_on_message_complete: p => {
182
192
  assert(currentParser.ptr === p)
183
193
  return currentParser.onMessageComplete()
184
194
  }
185
-
186
195
  }
187
196
  })
188
197
  }
@@ -215,10 +224,10 @@ const TIMEOUT_KEEP_ALIVE = 8 | USE_NATIVE_TIMER
215
224
 
216
225
  class Parser {
217
226
  /**
218
- * @param {import('./client.js')} client
219
- * @param {import('net').Socket} socket
220
- * @param {*} llhttp
221
- */
227
+ * @param {import('./client.js')} client
228
+ * @param {import('net').Socket} socket
229
+ * @param {*} llhttp
230
+ */
222
231
  constructor (client, socket, { exports }) {
223
232
  this.llhttp = exports
224
233
  this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE)
@@ -245,7 +254,8 @@ class Parser {
245
254
 
246
255
  this.keepAlive = ''
247
256
  this.contentLength = -1
248
- this.connectionKeepAlive = false
257
+ this.hasTransferEncoding = false
258
+ this.connection = ''
249
259
  this.maxResponseSize = client[kMaxResponseSize]
250
260
  }
251
261
 
@@ -253,10 +263,7 @@ class Parser {
253
263
  // If the existing timer and the new timer are of different timer type
254
264
  // (fast or native) or have different delay, we need to clear the existing
255
265
  // timer and set a new one.
256
- if (
257
- delay !== this.timeoutValue ||
258
- (type & USE_FAST_TIMER) ^ (this.timeoutType & USE_FAST_TIMER)
259
- ) {
266
+ if (delay !== this.timeoutValue || (type & USE_FAST_TIMER) ^ (this.timeoutType & USE_FAST_TIMER)) {
260
267
  // If a timeout is already set, clear it with clearTimeout of the fast
261
268
  // timer implementation, as it can clear fast and native timers.
262
269
  if (this.timeout) {
@@ -441,9 +448,7 @@ class Parser {
441
448
  if (ptr) {
442
449
  const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0)
443
450
  message =
444
- 'Response does not match the HTTP/1.1 protocol (' +
445
- Buffer.from(llhttp.memory.buffer, ptr, len).toString() +
446
- ')'
451
+ 'Response does not match the HTTP/1.1 protocol (' + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ')'
447
452
  }
448
453
 
449
454
  return new HTTPParserError(message, constants.ERROR[ret], data)
@@ -521,6 +526,7 @@ class Parser {
521
526
  */
522
527
  onHeaderValue (buf) {
523
528
  let len = this.headers.length
529
+ const isContinuation = (len & 1) === 0
524
530
 
525
531
  if ((len & 1) === 1) {
526
532
  this.headers.push(buf)
@@ -533,19 +539,19 @@ class Parser {
533
539
  if (key.length === 10) {
534
540
  const headerName = util.bufferToLowerCasedHeaderName(key)
535
541
  if (headerName === 'keep-alive') {
536
- this.keepAlive += buf.toString()
542
+ this.keepAlive += (isContinuation || this.keepAlive.length === 0 ? '' : ',') + buf.toString()
537
543
  } else if (headerName === 'connection') {
538
- this.connectionKeepAlive =
539
- this.headers[len - 1].length === 10 &&
540
- util.bufferToLowerCasedHeaderName(this.headers[len - 1]) === 'keep-alive'
544
+ this.connection += (isContinuation || this.connection.length === 0 ? '' : ',') + buf.toString()
541
545
  }
542
546
  } else if (key.length === 14 && util.bufferToLowerCasedHeaderName(key) === 'content-length') {
543
547
  if (this.contentLength === -1) {
544
548
  this.contentLength = 0
545
549
  }
546
550
  for (let i = 0; i < buf.length; i++) {
547
- this.contentLength = (this.contentLength * 10) + (buf[i] - 0x30)
551
+ this.contentLength = this.contentLength * 10 + (buf[i] - 0x30)
548
552
  }
553
+ } else if (key.length === 17 && util.bufferToLowerCasedHeaderName(key) === 'transfer-encoding') {
554
+ this.hasTransferEncoding = true
549
555
  }
550
556
 
551
557
  this.trackHeader(buf.length)
@@ -652,16 +658,27 @@ class Parser {
652
658
  assert(this.timeoutType === TIMEOUT_HEADERS)
653
659
 
654
660
  this.statusCode = statusCode
655
- this.shouldKeepAlive = (
661
+ this.shouldKeepAlive =
656
662
  shouldKeepAlive ||
657
663
  // Override llhttp value which does not allow keepAlive for HEAD.
658
- (request.method === 'HEAD' && !socket[kReset] && this.connectionKeepAlive)
659
- )
664
+ (request.method === 'HEAD' && !socket[kReset] &&
665
+ /(?:^|,)[\t ]*keep-alive[\t ]*(?:,|$)/i.test(this.connection) &&
666
+ !/(?:^|,)[\t ]*close[\t ]*(?:,|$)/i.test(this.connection))
667
+
668
+ // Responses to HEAD and 204/304 responses never carry content
669
+ if (request.method === 'HEAD' || statusCode === 204 || statusCode === 304) {
670
+ // A non-zero Content-Length or Transfer-Encoding on a 204/304 means the
671
+ // server may also have sent content inappropriately, which would then be
672
+ // parsed as the next response on this connection. Accept it, but do not
673
+ // reuse the connection. HEAD requests are fine tho.
674
+ if (request.method !== 'HEAD' && (this.contentLength > 0 || this.hasTransferEncoding)) {
675
+ this.shouldKeepAlive = false
676
+ }
677
+ this.contentLength = -1
678
+ }
660
679
 
661
680
  if (this.statusCode >= 200) {
662
- const bodyTimeout = request.bodyTimeout != null
663
- ? request.bodyTimeout
664
- : client[kBodyTimeout]
681
+ const bodyTimeout = request.bodyTimeout != null ? request.bodyTimeout : client[kBodyTimeout]
665
682
  this.setTimeout(bodyTimeout, TIMEOUT_BODY)
666
683
  } else if (this.timeout) {
667
684
  if (this.timeout.refresh) {
@@ -689,10 +706,7 @@ class Parser {
689
706
  const keepAliveTimeout = this.keepAlive ? util.parseKeepAliveTimeout(this.keepAlive) : null
690
707
 
691
708
  if (keepAliveTimeout != null) {
692
- const timeout = Math.min(
693
- keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
694
- client[kKeepAliveMaxTimeout]
695
- )
709
+ const timeout = Math.min(keepAliveTimeout - client[kKeepAliveTimeoutThreshold], client[kKeepAliveMaxTimeout])
696
710
  if (timeout <= 0) {
697
711
  socket[kReset] = true
698
712
  } else {
@@ -789,8 +803,9 @@ class Parser {
789
803
  this.statusText = ''
790
804
  this.bytesRead = 0
791
805
  this.contentLength = -1
806
+ this.hasTransferEncoding = false
792
807
  this.keepAlive = ''
793
- this.connectionKeepAlive = false
808
+ this.connection = ''
794
809
 
795
810
  this.headers = []
796
811
  this.headersSize = 0
@@ -799,7 +814,7 @@ class Parser {
799
814
  return 0
800
815
  }
801
816
 
802
- if (request.method !== 'HEAD' && contentLength !== -1 && bytesRead !== contentLength) {
817
+ if (contentLength !== -1 && bytesRead !== contentLength) {
803
818
  util.destroy(socket, new ResponseContentLengthMismatchError())
804
819
  return -1
805
820
  }
@@ -887,7 +902,9 @@ function connectH1 (client, socket) {
887
902
  socket[kIdleSocketValidation] = 0
888
903
  socket[kIdleSocketValidationTimeout] = null
889
904
  socket[kSocketUsed] = false
890
- socket[kParser] = new Parser(client, socket, llhttpInstance)
905
+ socket[kParser] = typeof esbuildDetection === 'undefined' && (client[kUseMilo] ?? getMiloEnabled())
906
+ ? new H1Parser(client, socket)
907
+ : new Parser(client, socket, llhttpInstance)
891
908
 
892
909
  util.addListener(socket, 'error', onHttpSocketError)
893
910
  util.addListener(socket, 'readable', onHttpSocketReadable)
@@ -948,8 +965,11 @@ function connectH1 (client, socket) {
948
965
  return true
949
966
  }
950
967
 
951
- if (client[kRunning] > 0 && util.bodyLength(request.body) !== 0 &&
952
- (util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))) {
968
+ if (
969
+ client[kRunning] > 0 &&
970
+ util.bodyLength(request.body) !== 0 &&
971
+ (util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))
972
+ ) {
953
973
  // Request with stream or iterator body can error while other requests
954
974
  // are inflight and indirectly error those as well.
955
975
  // Ensure this doesn't happen by waiting for inflight
@@ -968,8 +988,6 @@ function connectH1 (client, socket) {
968
988
  }
969
989
 
970
990
  function onHttpSocketError (err) {
971
- assert(err.code !== 'ERR_TLS_CERT_ALTNAME_INVALID')
972
-
973
991
  const parser = this[kParser]
974
992
 
975
993
  // On Mac OS, we get an ECONNRESET even if there is a full body to be forwarded
@@ -1137,9 +1155,7 @@ function resumeH1 (client) {
1137
1155
  } else if (client[kRunning] > 0 && socket[kParser].statusCode < 200) {
1138
1156
  if (socket[kParser].timeoutType !== TIMEOUT_HEADERS) {
1139
1157
  const request = client[kQueue][client[kRunningIdx]]
1140
- const headersTimeout = request.headersTimeout != null
1141
- ? request.headersTimeout
1142
- : client[kHeadersTimeout]
1158
+ const headersTimeout = request.headersTimeout != null ? request.headersTimeout : client[kHeadersTimeout]
1143
1159
  socket[kParser].setTimeout(headersTimeout, TIMEOUT_HEADERS)
1144
1160
  }
1145
1161
  }
@@ -1196,14 +1212,13 @@ function writeH1 (client, request) {
1196
1212
  // servers and corrupt connection state. Do not
1197
1213
  // re-use the connection for further requests.
1198
1214
 
1199
- const expectsPayload = (
1215
+ const expectsPayload =
1200
1216
  method === 'PUT' ||
1201
1217
  method === 'POST' ||
1202
1218
  method === 'PATCH' ||
1203
1219
  method === 'QUERY' ||
1204
1220
  method === 'PROPFIND' ||
1205
1221
  method === 'PROPPATCH'
1206
- )
1207
1222
 
1208
1223
  if (util.isFormDataLike(body)) {
1209
1224
  if (!extractBody) {
@@ -1252,7 +1267,12 @@ function writeH1 (client, request) {
1252
1267
 
1253
1268
  // https://github.com/nodejs/undici/issues/2046
1254
1269
  // A user agent may send a Content-Length header with 0 value, this should be allowed.
1255
- if (shouldSendContentLength(method) && contentLength > 0 && request.contentLength !== null && request.contentLength !== contentLength) {
1270
+ if (
1271
+ shouldSendContentLength(method) &&
1272
+ contentLength > 0 &&
1273
+ request.contentLength !== null &&
1274
+ request.contentLength !== contentLength
1275
+ ) {
1256
1276
  if (client[kStrictContentLength]) {
1257
1277
  util.errorRequest(client, request, new RequestContentLengthMismatchError())
1258
1278
  return false
@@ -1268,7 +1288,7 @@ function writeH1 (client, request) {
1268
1288
  * @param {Error} [err]
1269
1289
  * @returns {void}
1270
1290
  */
1271
- const abort = (err) => {
1291
+ const abort = err => {
1272
1292
  if (request.aborted || request.completed) {
1273
1293
  return
1274
1294
  }
@@ -1453,14 +1473,9 @@ function writeStream (abort, body, client, request, socket, contentLength, heade
1453
1473
 
1454
1474
  assert(socket.destroyed || (socket[kWriting] && client[kRunning] <= 1))
1455
1475
 
1456
- socket
1457
- .off('drain', onDrain)
1458
- .off('error', onFinished)
1476
+ socket.off('drain', onDrain).off('error', onFinished)
1459
1477
 
1460
- body
1461
- .removeListener('data', onData)
1462
- .removeListener('end', onFinished)
1463
- .removeListener('close', onClose)
1478
+ body.removeListener('data', onData).removeListener('end', onFinished).removeListener('close', onClose)
1464
1479
 
1465
1480
  if (!err) {
1466
1481
  try {
@@ -1479,19 +1494,13 @@ function writeStream (abort, body, client, request, socket, contentLength, heade
1479
1494
  }
1480
1495
  }
1481
1496
 
1482
- body
1483
- .on('data', onData)
1484
- .on('end', onFinished)
1485
- .on('error', onFinished)
1486
- .on('close', onClose)
1497
+ body.on('data', onData).on('end', onFinished).on('error', onFinished).on('close', onClose)
1487
1498
 
1488
1499
  if (body.resume) {
1489
1500
  body.resume()
1490
1501
  }
1491
1502
 
1492
- socket
1493
- .on('drain', onDrain)
1494
- .on('error', onFinished)
1503
+ socket.on('drain', onDrain).on('error', onFinished)
1495
1504
 
1496
1505
  if (body.errorEmitted ?? body.errored) {
1497
1506
  setImmediate(onFinished, body.errored)
@@ -1612,19 +1621,18 @@ async function writeIterable (abort, body, client, request, socket, contentLengt
1612
1621
  }
1613
1622
  }
1614
1623
 
1615
- const waitForDrain = () => new Promise((resolve, reject) => {
1616
- assert(callback === null)
1624
+ const waitForDrain = () =>
1625
+ new Promise((resolve, reject) => {
1626
+ assert(callback === null)
1617
1627
 
1618
- if (socket[kError]) {
1619
- reject(socket[kError])
1620
- } else {
1621
- callback = resolve
1622
- }
1623
- })
1628
+ if (socket[kError]) {
1629
+ reject(socket[kError])
1630
+ } else {
1631
+ callback = resolve
1632
+ }
1633
+ })
1624
1634
 
1625
- socket
1626
- .on('close', onDrain)
1627
- .on('drain', onDrain)
1635
+ socket.on('close', onDrain).on('drain', onDrain)
1628
1636
 
1629
1637
  const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header })
1630
1638
  try {
@@ -1643,9 +1651,7 @@ async function writeIterable (abort, body, client, request, socket, contentLengt
1643
1651
  } catch (err) {
1644
1652
  writer.destroy(err)
1645
1653
  } finally {
1646
- socket
1647
- .off('close', onDrain)
1648
- .off('drain', onDrain)
1654
+ socket.off('close', onDrain).off('drain', onDrain)
1649
1655
  }
1650
1656
  }
1651
1657
 
@@ -1670,10 +1676,27 @@ class AsyncWriter {
1670
1676
  this.expectsPayload = expectsPayload
1671
1677
  this.header = header
1672
1678
  this.abort = abort
1679
+ this.lengthMismatch = false
1673
1680
 
1674
1681
  socket[kWriting] = true
1675
1682
  }
1676
1683
 
1684
+ /**
1685
+ * The body doesn't match the declared content-length and strictContentLength
1686
+ * is off. Warn once, and mark the socket so it isn't reused: on the wire this
1687
+ * request's body no longer ends where the server expects, so anything sent
1688
+ * after it on the same connection would be misread.
1689
+ * @returns {void}
1690
+ */
1691
+ onLengthMismatch () {
1692
+ this.socket[kReset] = true
1693
+
1694
+ if (!this.lengthMismatch) {
1695
+ this.lengthMismatch = true
1696
+ process.emitWarning(new RequestContentLengthMismatchError())
1697
+ }
1698
+ }
1699
+
1677
1700
  /**
1678
1701
  * @param {string|Uint8Array} chunk
1679
1702
  * @returns
@@ -1689,7 +1712,7 @@ class AsyncWriter {
1689
1712
  return false
1690
1713
  }
1691
1714
 
1692
- const len = chunk instanceof Uint8Array ? chunk.byteLength : Buffer.byteLength(chunk)
1715
+ let len = chunk instanceof Uint8Array ? chunk.byteLength : Buffer.byteLength(chunk)
1693
1716
  if (!len) {
1694
1717
  return true
1695
1718
  }
@@ -1700,7 +1723,17 @@ class AsyncWriter {
1700
1723
  throw new RequestContentLengthMismatchError()
1701
1724
  }
1702
1725
 
1703
- process.emitWarning(new RequestContentLengthMismatchError())
1726
+ this.onLengthMismatch()
1727
+
1728
+ // Never write past the declared content-length. The server treats any
1729
+ // extra bytes as the start of the next request, so a body could inject
1730
+ // a request of its own (request smuggling).
1731
+ const remaining = contentLength - bytesWritten
1732
+ if (remaining === 0) {
1733
+ return true
1734
+ }
1735
+ chunk = (typeof chunk === 'string' ? Buffer.from(chunk) : chunk).subarray(0, remaining)
1736
+ len = remaining
1704
1737
  }
1705
1738
 
1706
1739
  socket.cork()
@@ -1775,9 +1808,12 @@ class AsyncWriter {
1775
1808
  if (contentLength !== null && bytesWritten !== contentLength) {
1776
1809
  if (client[kStrictContentLength]) {
1777
1810
  throw new RequestContentLengthMismatchError()
1778
- } else {
1779
- process.emitWarning(new RequestContentLengthMismatchError())
1780
1811
  }
1812
+
1813
+ // The body is shorter than declared, so the server is still waiting for
1814
+ // the rest. Don't let the next request's bytes on this connection be
1815
+ // read as the missing part of this body.
1816
+ this.onLengthMismatch()
1781
1817
  }
1782
1818
 
1783
1819
  if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {