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,7 @@ const DEFAULT_MAX_BUFFER_SIZE = 5 * 1024 * 1024
16
16
  * @property {number} bufferedBytes
17
17
  * @property {object | null} pendingTrailers
18
18
  * @property {boolean} done
19
+ * @property {boolean} [pendingStart] onRequestStart deferred until the primary request's context is known
19
20
  */
20
21
 
21
22
  /**
@@ -30,6 +31,20 @@ class DeduplicationHandler {
30
31
  */
31
32
  #primaryHandler
32
33
 
34
+ /**
35
+ * Whether the primary request has started (onRequestStart received). Until
36
+ * then the request context is unknown and cannot be given to waiting handlers.
37
+ * @type {boolean}
38
+ */
39
+ #requestStarted = false
40
+
41
+ /**
42
+ * The primary request context, replayed to waiting handlers so they observe
43
+ * the same redirect history as the primary.
44
+ * @type {any}
45
+ */
46
+ #context = null
47
+
33
48
  /**
34
49
  * @type {WaitingHandler[]}
35
50
  */
@@ -112,20 +127,30 @@ class DeduplicationHandler {
112
127
  const waitingController = waitingHandler.controller
113
128
 
114
129
  try {
115
- handler.onRequestStart?.(waitingController, null)
130
+ if (this.#requestStarted) {
131
+ // The primary request has started, so its context (including the
132
+ // redirect history) is known and can be delivered immediately.
133
+ handler.onRequestStart?.(waitingController, this.#context)
116
134
 
117
- if (waitingController.aborted) {
118
- waitingHandler.done = true
119
- return true
120
- }
135
+ if (waitingController.aborted) {
136
+ waitingHandler.done = true
137
+ return true
138
+ }
121
139
 
122
- if (this.#responseStarted) {
123
- handler.onResponseStart?.(
124
- waitingController,
125
- this.#statusCode,
126
- this.#headers,
127
- this.#statusMessage
128
- )
140
+ if (this.#responseStarted) {
141
+ handler.onResponseStart?.(
142
+ waitingController,
143
+ this.#statusCode,
144
+ this.#headers,
145
+ this.#statusMessage
146
+ )
147
+ }
148
+ } else {
149
+ // The primary request has not started yet. Defer onRequestStart until
150
+ // its context is known, so the waiting handler observes the same
151
+ // redirect history as the primary (a cache handler relies on it to
152
+ // reject cross-origin redirect responses).
153
+ waitingHandler.pendingStart = true
129
154
  }
130
155
  } catch {
131
156
  // Ignore errors from waiting handlers
@@ -146,6 +171,24 @@ class DeduplicationHandler {
146
171
  */
147
172
  onRequestStart (controller, context) {
148
173
  this.#controller = controller
174
+ if (!this.#requestStarted) {
175
+ this.#requestStarted = true
176
+ this.#context = context
177
+ // Deliver the now-known context to handlers that joined before the
178
+ // primary request started.
179
+ for (const waitingHandler of this.#waitingHandlers) {
180
+ if (waitingHandler.pendingStart && !waitingHandler.done && !waitingHandler.controller.aborted) {
181
+ waitingHandler.pendingStart = false
182
+ try {
183
+ waitingHandler.handler.onRequestStart?.(waitingHandler.controller, context)
184
+ } catch {
185
+ // Ignore errors from waiting handlers
186
+ waitingHandler.done = true
187
+ }
188
+ }
189
+ }
190
+ this.#pruneDoneWaitingHandlers()
191
+ }
149
192
  this.#primaryHandler.onRequestStart?.(controller, context)
150
193
  }
151
194
 
@@ -251,40 +294,41 @@ class DeduplicationHandler {
251
294
  return
252
295
  }
253
296
 
254
- // Remove the entry before callbacks can synchronously dispatch a retry.
255
- this.#cleanup()
256
- this.#primaryHandler.onResponseEnd?.(controller, trailers)
257
- // A throwing end callback must still be handled by onResponseError.
258
297
  this.#completed = true
298
+ // Remove the completed request before callbacks can redispatch into this
299
+ // interceptor. Cleanup must not depend on downstream handlers succeeding.
300
+ this.#cleanup()
259
301
 
260
- for (const waitingHandler of this.#waitingHandlers) {
261
- if (waitingHandler.done || waitingHandler.controller.aborted) {
262
- waitingHandler.done = true
263
- continue
264
- }
302
+ try {
303
+ this.#primaryHandler.onResponseEnd?.(controller, trailers)
304
+ } catch (err) {
305
+ // Completion callbacks may throw to initiate a retry. The transport's
306
+ // error callback would be ignored now that this handler is completed.
307
+ this.#primaryHandler.onResponseError?.(controller, err)
308
+ } finally {
309
+ for (const waitingHandler of this.#waitingHandlers) {
310
+ if (waitingHandler.done || waitingHandler.controller.aborted) {
311
+ waitingHandler.done = true
312
+ continue
313
+ }
265
314
 
266
- this.#flushWaitingHandler(waitingHandler)
315
+ this.#flushWaitingHandler(waitingHandler)
267
316
 
268
- if (waitingHandler.done || waitingHandler.controller.aborted) {
269
- waitingHandler.done = true
270
- continue
271
- }
317
+ if (waitingHandler.done || waitingHandler.controller.aborted) {
318
+ waitingHandler.done = true
319
+ continue
320
+ }
272
321
 
273
- if (waitingHandler.controller.paused) {
274
- waitingHandler.pendingTrailers = trailers
275
- continue
276
- }
322
+ if (waitingHandler.controller.paused) {
323
+ waitingHandler.pendingTrailers = trailers
324
+ continue
325
+ }
277
326
 
278
- try {
279
- waitingHandler.handler.onResponseEnd?.(waitingHandler.controller, trailers)
280
- } catch (err) {
281
- this.#errorWaitingHandler(waitingHandler, err)
327
+ this.#endWaitingHandler(waitingHandler, trailers)
282
328
  }
283
329
 
284
- waitingHandler.done = true
330
+ this.#pruneDoneWaitingHandlers()
285
331
  }
286
-
287
- this.#pruneDoneWaitingHandlers()
288
332
  }
289
333
 
290
334
  /**
@@ -300,13 +344,15 @@ class DeduplicationHandler {
300
344
  this.#completed = true
301
345
  this.#cleanup()
302
346
 
303
- this.#primaryHandler.onResponseError?.(controller, err)
347
+ try {
348
+ this.#primaryHandler.onResponseError?.(controller, err)
349
+ } finally {
350
+ for (const waitingHandler of this.#waitingHandlers) {
351
+ this.#errorWaitingHandler(waitingHandler, err)
352
+ }
304
353
 
305
- for (const waitingHandler of this.#waitingHandlers) {
306
- this.#errorWaitingHandler(waitingHandler, err)
354
+ this.#waitingHandlers = []
307
355
  }
308
-
309
- this.#waitingHandlers = []
310
356
  }
311
357
 
312
358
  #cleanup () {
@@ -327,7 +373,8 @@ class DeduplicationHandler {
327
373
  bufferedChunks: [],
328
374
  bufferedBytes: 0,
329
375
  pendingTrailers: null,
330
- done: false
376
+ done: false,
377
+ pendingStart: false
331
378
  }
332
379
 
333
380
  const state = {
@@ -352,14 +399,7 @@ class DeduplicationHandler {
352
399
  !state.paused &&
353
400
  !state.aborted
354
401
  ) {
355
- try {
356
- waitingHandler.handler.onResponseEnd?.(waitingHandler.controller, waitingHandler.pendingTrailers)
357
- } catch (err) {
358
- this.#errorWaitingHandler(waitingHandler, err)
359
- }
360
-
361
- waitingHandler.pendingTrailers = null
362
- waitingHandler.done = true
402
+ this.#endWaitingHandler(waitingHandler, waitingHandler.pendingTrailers)
363
403
  }
364
404
 
365
405
  this.#pruneDoneWaitingHandlers()
@@ -448,6 +488,27 @@ class DeduplicationHandler {
448
488
  }
449
489
  }
450
490
 
491
+ /**
492
+ * @param {WaitingHandler} waitingHandler
493
+ * @param {object} trailers
494
+ */
495
+ #endWaitingHandler (waitingHandler, trailers) {
496
+ waitingHandler.done = true
497
+ waitingHandler.pendingTrailers = null
498
+
499
+ try {
500
+ waitingHandler.handler.onResponseEnd?.(waitingHandler.controller, trailers)
501
+ } catch (err) {
502
+ // This is a response failure, not a consumer abort. Aborting the waiting
503
+ // controller here would prevent downstream handlers from retrying.
504
+ try {
505
+ waitingHandler.handler.onResponseError?.(waitingHandler.controller, err)
506
+ } catch {
507
+ // An error callback must not prevent other waiting handlers completing.
508
+ }
509
+ }
510
+ }
511
+
451
512
  /**
452
513
  * @param {WaitingHandler} waitingHandler
453
514
  * @param {Error} err
@@ -2,8 +2,8 @@
2
2
 
3
3
  const util = require('../core/util')
4
4
  const assert = require('node:assert')
5
- const { InvalidArgumentError } = require('../core/errors')
6
- const { kRequestOrigin } = require('../core/symbols')
5
+ const { InvalidArgumentError, MaxRedirectsError } = require('../core/errors')
6
+ const { kRequestOrigin, kRedirectCacheControl } = require('../core/symbols')
7
7
 
8
8
  const redirectableStatusCodes = [300, 301, 302, 303, 307, 308]
9
9
 
@@ -38,6 +38,15 @@ class RedirectHandler {
38
38
  this.maxRedirections = maxRedirections
39
39
  this.handler = handler
40
40
  this.history = []
41
+ // `cache-control` of each intermediate (suppressed) redirect hop. An outer
42
+ // cache uses it to preserve a hop's storage policy (e.g. `no-store`) that
43
+ // would otherwise be lost because the hop's response is not forwarded. It
44
+ // travels as a non-enumerable property of the history array so it reaches
45
+ // the cache without becoming part of the public request/response context.
46
+ Object.defineProperty(this.history, kRedirectCacheControl, {
47
+ value: [],
48
+ enumerable: false
49
+ })
41
50
  }
42
51
 
43
52
  onRequestStart (controller, context) {
@@ -62,10 +71,6 @@ class RedirectHandler {
62
71
  return
63
72
  }
64
73
 
65
- if (this.opts.throwOnMaxRedirect && this.history.length >= this.maxRedirections) {
66
- throw new Error('max redirects')
67
- }
68
-
69
74
  let removeContentHeaders = statusCode === 303
70
75
 
71
76
  // https://tools.ietf.org/html/rfc7231#section-6.4.2
@@ -91,9 +96,19 @@ class RedirectHandler {
91
96
  this.opts.body = null
92
97
  }
93
98
 
94
- this.location = this.history.length >= this.maxRedirections || util.isDisturbed(this.opts.body) || redirectableStatusCodes.indexOf(statusCode) === -1
99
+ this.location = util.isDisturbed(this.opts.body) || redirectableStatusCodes.indexOf(statusCode) === -1
95
100
  ? null
96
- : headers.location
101
+ : headers.location || null
102
+
103
+ // Only a redirect that would otherwise be followed counts against the
104
+ // limit. The final response after exactly maxRedirections redirects, or a
105
+ // 3xx without a Location header, is delivered as usual.
106
+ if (this.location && this.history.length >= this.maxRedirections) {
107
+ if (this.opts.throwOnMaxRedirect) {
108
+ throw new MaxRedirectsError()
109
+ }
110
+ this.location = null
111
+ }
97
112
 
98
113
  const requestOrigin = this.opts[kRequestOrigin] === undefined
99
114
  ? this.opts.origin
@@ -108,6 +123,11 @@ class RedirectHandler {
108
123
  return
109
124
  }
110
125
 
126
+ // This hop's response is suppressed (only its Location is used). Record its
127
+ // cache-control so an outer cache can honor a restrictive policy that would
128
+ // otherwise be lost when the final response is stored.
129
+ this.history[kRedirectCacheControl].push(headers['cache-control'])
130
+
111
131
  const baseUrl = requestOrigin
112
132
  ? new URL(this.opts.path, requestOrigin)
113
133
  : undefined
@@ -4,6 +4,7 @@ const assert = require('node:assert')
4
4
  const { kRetryHandlerDefaultRetry } = require('../core/symbols')
5
5
  const { RequestRetryError, RequestAbortedError } = require('../core/errors')
6
6
  const {
7
+ hasSafeIterator,
7
8
  isDisturbed,
8
9
  parseRangeHeader,
9
10
  wrapRequestBody
@@ -554,19 +555,9 @@ class RetryHandler {
554
555
 
555
556
  retry () {
556
557
  if (this.start !== 0) {
557
- const headers = { range: `bytes=${this.start}-${this.end ?? ''}` }
558
-
559
- // Weak etag check - weak etags will make comparison algorithms never match
560
- if (this.etag != null) {
561
- headers['if-match'] = this.etag
562
- }
563
-
564
558
  this.opts = {
565
559
  ...this.opts,
566
- headers: {
567
- ...this.opts.headers,
568
- ...headers
569
- }
560
+ headers: buildResumeHeaders(this.opts.headers, `bytes=${this.start}-${this.end ?? ''}`, this.etag)
570
561
  }
571
562
  }
572
563
 
@@ -650,4 +641,46 @@ class RetryHandler {
650
641
  }
651
642
  }
652
643
 
644
+ function isReplacedHeader (key, etag) {
645
+ const name = key.toLowerCase()
646
+ return name === 'range' || (etag != null && name === 'if-match')
647
+ }
648
+
649
+ function buildResumeHeaders (headers, range, etag) {
650
+ if (Array.isArray(headers) || (headers && typeof headers === 'object' && hasSafeIterator(headers))) {
651
+ const ret = []
652
+ if (Array.isArray(headers)) {
653
+ for (let i = 0; i < headers.length; i += 2) {
654
+ if (!isReplacedHeader(headers[i], etag)) {
655
+ ret.push(headers[i], headers[i + 1])
656
+ }
657
+ }
658
+ } else {
659
+ for (const [key, value] of headers) {
660
+ if (!isReplacedHeader(key, etag)) {
661
+ ret.push(key, value)
662
+ }
663
+ }
664
+ }
665
+ ret.push('range', range)
666
+ // Weak etag check - weak etags will make comparison algorithms never match
667
+ if (etag != null) {
668
+ ret.push('if-match', etag)
669
+ }
670
+ return ret
671
+ }
672
+
673
+ const ret = {}
674
+ for (const key in headers) {
675
+ if (Object.hasOwn(headers, key) && !isReplacedHeader(key, etag)) {
676
+ ret[key] = headers[key]
677
+ }
678
+ }
679
+ ret.range = range
680
+ if (etag != null) {
681
+ ret['if-match'] = etag
682
+ }
683
+ return ret
684
+ }
685
+
653
686
  module.exports = RetryHandler
@@ -210,7 +210,10 @@ function makeRevalidationHeaders (opts, result) {
210
210
  */
211
211
  function isStale (result, cacheControlDirectives, cacheType) {
212
212
  const now = Date.now()
213
- if (now > result.staleAt) {
213
+ // A zero freshness lifetime (e.g. max-age=0 with a validator) is never fresh,
214
+ // even when reused within the same millisecond or after a clock step back.
215
+ // https://www.rfc-editor.org/rfc/rfc9111.html#section-4.2
216
+ if (now > result.staleAt || result.staleAt <= result.cachedAt) {
214
217
  // Response is stale
215
218
  if (!staleResponseRequiresRevalidation(result, cacheType) && cacheControlDirectives?.['max-stale']) {
216
219
  // There's a threshold where we can serve stale responses, let's see if
@@ -331,6 +334,7 @@ function sendCachedValue (handler, opts, result, age, context, isStale) {
331
334
  assert(!stream.readableDidRead, 'stream should not be readableDidRead')
332
335
 
333
336
  let aborted = false
337
+ let abortReason = null
334
338
 
335
339
  const controller = {
336
340
  rawHeaders: [],
@@ -348,11 +352,15 @@ function sendCachedValue (handler, opts, result, age, context, isStale) {
348
352
  return aborted
349
353
  },
350
354
  get reason () {
351
- return stream.errored
355
+ return abortReason
352
356
  },
353
357
  abort (reason) {
358
+ if (aborted) {
359
+ return
360
+ }
354
361
  aborted = true
355
- stream.destroy(reason ?? new AbortError())
362
+ abortReason = reason ?? new AbortError()
363
+ stream.destroy(abortReason)
356
364
  }
357
365
  }
358
366
 
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { createInflate, createGunzip, createBrotliDecompress, createZstdDecompress } = require('node:zlib')
3
+ const { createInflate, createGunzip, createBrotliDecompress, createZstdDecompress, constants } = require('node:zlib')
4
4
  const { pipeline, Transform: TransformStream } = require('node:stream')
5
5
  const { InvalidArgumentError, ResponseExceededMaxSizeError } = require('../core/errors')
6
6
  const DecoratorHandler = require('../handler/decorator-handler')
@@ -63,6 +63,10 @@ class DecompressController {
63
63
  }
64
64
  }
65
65
 
66
+ // `compress` and `x-compress` are deliberately absent. RFC 9110 section
67
+ // 8.4.1.1 defines them as the UNIX compress (LZW) format, which zlib cannot
68
+ // read, so inflating them turns a readable response into a Z_DATA_ERROR.
69
+ // fetch() leaves them alone, and so does this interceptor.
66
70
  /** @type {Record<string, () => DecompressorStream>} */
67
71
  const supportedEncodings = {
68
72
  __proto__: null,
@@ -70,9 +74,8 @@ const supportedEncodings = {
70
74
  'x-gzip': createGunzip,
71
75
  br: createBrotliDecompress,
72
76
  deflate: createInflate,
73
- compress: createInflate,
74
- 'x-compress': createInflate,
75
- zstd: createZstdDecompress
77
+ // https://www.rfc-editor.org/rfc/rfc9659.html#section-3
78
+ zstd: createZstdDecompress.bind(null, { params: { [constants.ZSTD_d_windowLogMax]: 23 } })
76
79
  }
77
80
 
78
81
  const defaultSkipStatusCodes = /** @type {const} */ ([204, 304])
@@ -220,9 +223,14 @@ class DecompressHandler extends DecoratorHandler {
220
223
  this.#decompressedSize = decompressedSize
221
224
  }
222
225
 
223
- const result = super.onResponseData(this.#controller, chunk)
224
- if (result === false && !this.#controller.paused) {
225
- this.#controller.pause()
226
+ try {
227
+ const result = super.onResponseData(this.#controller, chunk)
228
+ if (result === false && !this.#controller.paused) {
229
+ this.#controller.pause()
230
+ }
231
+ } catch (err) {
232
+ this.#fail(err)
233
+ return
226
234
  }
227
235
  }
228
236
  } while (this.#drainRequested && !this.#terminated && !this.#controller.paused)
@@ -239,9 +247,14 @@ class DecompressHandler extends DecoratorHandler {
239
247
  return
240
248
  }
241
249
 
242
- this.#terminated = true
243
250
  this.#cleanupDecompressors()
244
- super.onResponseEnd(this.#controller, this.#trailers)
251
+ try {
252
+ super.onResponseEnd(this.#controller, this.#trailers)
253
+ } catch (err) {
254
+ this.#fail(err)
255
+ return
256
+ }
257
+ this.#terminated = true
245
258
  }
246
259
 
247
260
  #onDecompressionEnd () {
@@ -190,6 +190,16 @@ class DNSInstance {
190
190
  newOpts.affinity
191
191
  )
192
192
 
193
+ // The lookup succeeded, but nothing it returned is usable here: with
194
+ // dualStack disabled and an affinity set, records of the other family
195
+ // cannot be picked. Running the lookup again would return the same
196
+ // records, so report it the way an empty result is reported.
197
+ if (ip == null) {
198
+ this.storage.delete(origin.hostname)
199
+ cb(new InformationalError('No DNS entries found'))
200
+ return
201
+ }
202
+
193
203
  let port
194
204
  if (typeof ip.port === 'number') {
195
205
  port = `:${ip.port}`
@@ -346,6 +356,7 @@ class DNSInstance {
346
356
  // We delete expired records
347
357
  // It is possible that they have different TTL, so we manage them individually
348
358
  family.ips.splice(position, 1)
359
+ return this.pickFamily(origin, ipFamily)
349
360
  }
350
361
 
351
362
  return ip
@@ -2,7 +2,9 @@
2
2
 
3
3
  // const { parseHeaders } = require('../core/util')
4
4
  const DecoratorHandler = require('../handler/decorator-handler')
5
- const { ResponseError } = require('../core/errors')
5
+ const { InvalidArgumentError, ResponseError } = require('../core/errors')
6
+
7
+ const defaultMaxSize = 1024 * 1024
6
8
 
7
9
  class ResponseErrorHandler extends DecoratorHandler {
8
10
  #statusCode
@@ -10,9 +12,13 @@ class ResponseErrorHandler extends DecoratorHandler {
10
12
  #decoder
11
13
  #headers
12
14
  #body
15
+ #bodySize
16
+ #bodyTruncated
17
+ #maxSize
13
18
 
14
- constructor (_opts, { handler }) {
19
+ constructor ({ maxSize }, { handler }) {
15
20
  super(handler)
21
+ this.#maxSize = maxSize
16
22
  }
17
23
 
18
24
  #checkContentType (contentType) {
@@ -25,6 +31,8 @@ class ResponseErrorHandler extends DecoratorHandler {
25
31
  this.#decoder = null
26
32
  this.#headers = null
27
33
  this.#body = ''
34
+ this.#bodySize = 0
35
+ this.#bodyTruncated = false
28
36
 
29
37
  return super.onRequestStart(controller, context)
30
38
  }
@@ -43,39 +51,69 @@ class ResponseErrorHandler extends DecoratorHandler {
43
51
  }
44
52
  }
45
53
 
54
+ #createResponseError () {
55
+ this.#body += this.#decoder?.decode(undefined, { stream: false }) ?? ''
56
+ this.#decoder = null
57
+
58
+ if (!this.#bodyTruncated && this.#checkContentType('application/json')) {
59
+ try {
60
+ this.#body = JSON.parse(this.#body)
61
+ } catch {
62
+ // Do nothing...
63
+ }
64
+ }
65
+
66
+ let err
67
+ const stackTraceLimit = Error.stackTraceLimit
68
+ Error.stackTraceLimit = 0
69
+ try {
70
+ err = new ResponseError('Response Error', this.#statusCode, {
71
+ body: this.#body,
72
+ bodyTruncated: this.#bodyTruncated,
73
+ headers: this.#headers
74
+ })
75
+ } finally {
76
+ Error.stackTraceLimit = stackTraceLimit
77
+ }
78
+
79
+ return err
80
+ }
81
+
46
82
  onResponseData (controller, chunk) {
47
83
  if (this.#statusCode < 400) {
48
84
  return super.onResponseData(controller, chunk)
49
85
  }
50
86
 
51
- this.#body += this.#decoder?.decode(chunk, { stream: true }) ?? ''
87
+ if (this.#decoder == null) {
88
+ return
89
+ }
90
+
91
+ if (this.#maxSize === 0) {
92
+ this.#body += this.#decoder.decode(chunk, { stream: true })
93
+ return
94
+ }
95
+
96
+ const remaining = this.#maxSize - this.#bodySize
97
+
98
+ if (chunk.length <= remaining) {
99
+ this.#bodySize += chunk.length
100
+ this.#body += this.#decoder.decode(chunk, { stream: true })
101
+ return
102
+ }
103
+
104
+ if (remaining > 0) {
105
+ this.#body += this.#decoder.decode(chunk.subarray(0, remaining), { stream: true })
106
+ this.#bodySize = this.#maxSize
107
+ }
108
+
109
+ this.#bodyTruncated = true
110
+ this.#body += this.#decoder.decode(undefined, { stream: false })
111
+ this.#decoder = null
52
112
  }
53
113
 
54
114
  onResponseEnd (controller, trailers) {
55
115
  if (this.#statusCode >= 400) {
56
- this.#body += this.#decoder?.decode(undefined, { stream: false }) ?? ''
57
-
58
- if (this.#checkContentType('application/json')) {
59
- try {
60
- this.#body = JSON.parse(this.#body)
61
- } catch {
62
- // Do nothing...
63
- }
64
- }
65
-
66
- let err
67
- const stackTraceLimit = Error.stackTraceLimit
68
- Error.stackTraceLimit = 0
69
- try {
70
- err = new ResponseError('Response Error', this.#statusCode, {
71
- body: this.#body,
72
- headers: this.#headers
73
- })
74
- } finally {
75
- Error.stackTraceLimit = stackTraceLimit
76
- }
77
-
78
- super.onResponseError(controller, err)
116
+ super.onResponseError(controller, this.#createResponseError())
79
117
  } else {
80
118
  super.onResponseEnd(controller, trailers)
81
119
  }
@@ -86,10 +124,16 @@ class ResponseErrorHandler extends DecoratorHandler {
86
124
  }
87
125
  }
88
126
 
89
- module.exports = () => {
127
+ module.exports = (opts = {}) => {
128
+ const { maxSize = defaultMaxSize } = opts
129
+
130
+ if (!Number.isSafeInteger(maxSize) || maxSize < 0) {
131
+ throw new InvalidArgumentError('maxSize must be a non-negative integer')
132
+ }
133
+
90
134
  return (dispatch) => {
91
135
  return function Intercept (opts, handler) {
92
- return dispatch(opts, new ResponseErrorHandler(opts, { handler }))
136
+ return dispatch(opts, new ResponseErrorHandler({ maxSize }, { handler }))
93
137
  }
94
138
  }
95
139
  }
@@ -0,0 +1,7 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2023, and above Paolo Insogna, NearForm and other contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.