maka-agent 0.2.2-dev.92.20261019 → 0.2.2-dev.98.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 (364) hide show
  1. package/LICENSE +7 -7
  2. package/README.md +78 -18
  3. package/README.zh-CN.md +73 -15
  4. package/THIRD_PARTY_NOTICES.txt +12 -12
  5. package/dist/pi-goal.js +13 -0
  6. package/dist/pi-tui-runner.js +44 -1
  7. package/dist/run-command-core.js +111 -70
  8. package/dist/run-session-command.js +91 -15
  9. package/dist/run-turn-outcome.js +2 -33
  10. package/dist/runtime-host-session-channel.js +3 -1
  11. package/dist/runtime-host-session-driver.js +5 -0
  12. package/dist/tui-copy-catalog.js +24 -0
  13. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  14. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
  15. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
  16. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
  17. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
  18. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  19. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  20. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
  21. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  22. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
  23. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  24. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  25. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
  26. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
  27. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
  28. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
  29. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  30. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  31. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
  32. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
  33. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  34. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  35. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
  36. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
  37. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
  38. package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
  39. package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
  40. package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
  41. package/node_modules/@maka/core/dist/event-wait.js +28 -10
  42. package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
  43. package/node_modules/@maka/core/dist/model-catalog.js +19 -1
  44. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
  45. package/node_modules/@maka/core/dist/model-metadata.js +42 -1
  46. package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
  47. package/node_modules/@maka/core/dist/provider-registry.js +16 -2
  48. package/node_modules/@maka/core/dist/runtime-event.js +8 -0
  49. package/node_modules/@maka/core/dist/session-checkin.js +31 -0
  50. package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
  51. package/node_modules/@maka/core/package.json +2 -0
  52. package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
  53. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  54. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
  55. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  56. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
  57. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  58. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  59. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  60. package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
  61. package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
  62. package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  63. package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  64. package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
  65. package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
  66. package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
  67. package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
  68. package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
  69. package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
  70. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
  71. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  72. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  73. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
  74. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  75. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  76. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  77. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  78. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
  79. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  80. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  81. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  82. package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
  83. package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  84. package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  85. package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
  86. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
  87. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
  88. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
  89. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
  90. package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
  91. package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
  92. package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
  93. package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
  94. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  95. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  96. package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
  97. package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
  98. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  99. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  100. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
  101. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  102. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
  103. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
  104. package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  105. package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  106. package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
  107. package/node_modules/@maka/mcp/package.json +1 -1
  108. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +22 -9
  109. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
  110. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +101 -127
  111. package/node_modules/@maka/runtime/dist/event-wait-tool.js +2 -2
  112. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +32 -1
  113. package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
  114. package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
  115. package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
  116. package/node_modules/@maka/runtime/dist/model-history.js +16 -3
  117. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +7 -2
  118. package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
  119. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
  120. package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
  121. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
  122. package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
  123. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
  124. package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
  125. package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
  126. package/node_modules/@maka/runtime/dist/tool-runtime.js +8 -0
  127. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
  128. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
  129. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
  130. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
  131. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
  132. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  133. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  134. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
  135. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  136. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
  137. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  138. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  139. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
  140. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
  141. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
  142. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
  143. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  144. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  145. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
  146. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
  147. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  148. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  149. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
  150. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
  151. package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
  152. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  153. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
  154. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  155. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
  156. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  157. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  158. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  159. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
  160. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
  161. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  162. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  163. package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
  164. package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
  165. package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
  166. package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
  167. package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
  168. package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
  169. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
  170. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  171. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  172. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
  173. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  174. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  175. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  176. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  177. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
  178. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  179. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  180. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  181. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
  182. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  183. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  184. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
  185. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
  186. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
  187. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
  188. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
  189. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
  190. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
  191. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
  192. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
  193. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  194. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  195. package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
  196. package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
  197. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  198. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  199. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
  200. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  201. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
  202. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
  203. package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  204. package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  205. package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
  206. package/node_modules/@maka/runtime/package.json +2 -0
  207. package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
  208. package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
  209. package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +64 -13
  210. package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
  211. package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
  212. package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
  213. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
  214. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
  215. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
  216. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
  217. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
  218. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
  219. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
  220. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +1 -1
  221. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
  222. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
  223. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
  224. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
  225. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +35 -5
  226. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
  227. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
  228. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
  229. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
  230. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +1 -1
  231. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
  232. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
  233. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +87 -23
  234. package/node_modules/@maka/runtime-host/dist/assistant/service.js +49 -5
  235. package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
  236. package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -1
  237. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
  238. package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
  239. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
  240. package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
  241. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
  242. package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +63 -12
  243. package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
  244. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +123 -11
  245. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
  246. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +126 -4
  247. package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +58 -19
  248. package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
  249. package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
  250. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
  251. package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
  252. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
  253. package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
  254. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
  255. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
  256. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
  257. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
  258. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
  259. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
  260. package/node_modules/@maka/storage/dist/execution-stores.js +36 -1
  261. package/node_modules/@maka/storage/dist/local-execution-persistence.js +26 -0
  262. package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
  263. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  264. package/node_modules/@maka/storage/dist/session-bundle-policy.js +86 -16
  265. package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
  266. package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
  267. package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
  268. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
  269. package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
  270. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +31 -0
  271. package/node_modules/@maka/storage/package.json +3 -0
  272. package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
  273. package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
  274. package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
  275. package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
  276. package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
  277. package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
  278. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
  279. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
  280. package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
  281. package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
  282. package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
  283. package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
  284. package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
  285. package/node_modules/@modelcontextprotocol/client/package.json +5 -5
  286. package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
  287. package/node_modules/fast-uri/README.md +8 -0
  288. package/node_modules/fast-uri/index.js +98 -18
  289. package/node_modules/fast-uri/lib/utils.js +52 -0
  290. package/node_modules/fast-uri/package.json +1 -1
  291. package/node_modules/follow-redirects/index.js +10 -1
  292. package/node_modules/follow-redirects/package.json +1 -1
  293. package/node_modules/ip-address/README.md +104 -104
  294. package/node_modules/ip-address/dist/ipv4.js +7 -0
  295. package/node_modules/ip-address/dist/ipv6.js +7 -4
  296. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  297. package/node_modules/ip-address/package.json +2 -1
  298. package/node_modules/undici/README.md +25 -3
  299. package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  300. package/node_modules/undici/docs/docs/api/Client.md +11 -6
  301. package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  302. package/node_modules/undici/docs/docs/api/Errors.md +76 -1
  303. package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  304. package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  305. package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  306. package/node_modules/undici/docs/docs/index.md +12 -12
  307. package/node_modules/undici/docs/docs/type-map.json +66 -66
  308. package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  309. package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  310. package/node_modules/undici/lib/core/connect.js +10 -4
  311. package/node_modules/undici/lib/core/constants.js +12 -1
  312. package/node_modules/undici/lib/core/errors.js +38 -1
  313. package/node_modules/undici/lib/core/request.js +16 -1
  314. package/node_modules/undici/lib/core/symbols.js +2 -0
  315. package/node_modules/undici/lib/core/util.js +26 -1
  316. package/node_modules/undici/lib/dispatcher/agent.js +6 -2
  317. package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  318. package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  319. package/node_modules/undici/lib/dispatcher/client.js +4 -1
  320. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  321. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  322. package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  323. package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  324. package/node_modules/undici/lib/dispatcher/pool.js +11 -8
  325. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  326. package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  327. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  328. package/node_modules/undici/lib/handler/cache-handler.js +153 -15
  329. package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  330. package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  331. package/node_modules/undici/lib/handler/retry-handler.js +44 -11
  332. package/node_modules/undici/lib/interceptor/cache.js +11 -3
  333. package/node_modules/undici/lib/interceptor/decompress.js +22 -9
  334. package/node_modules/undici/lib/interceptor/dns.js +11 -0
  335. package/node_modules/undici/lib/interceptor/response-error.js +72 -28
  336. package/node_modules/undici/lib/milo/LICENSE.md +7 -0
  337. package/node_modules/undici/lib/milo/no-simd.js +1002 -0
  338. package/node_modules/undici/lib/milo/simd.js +1002 -0
  339. package/node_modules/undici/lib/mock/mock-agent.js +11 -0
  340. package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  341. package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  342. package/node_modules/undici/lib/util/cache.js +11 -5
  343. package/node_modules/undici/lib/web/cookies/util.js +19 -2
  344. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  345. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  346. package/node_modules/undici/lib/web/fetch/body.js +47 -38
  347. package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  348. package/node_modules/undici/lib/web/fetch/headers.js +2 -2
  349. package/node_modules/undici/lib/web/fetch/index.js +8 -4
  350. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  351. package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  352. package/node_modules/undici/package.json +9 -7
  353. package/node_modules/zod/package.json +1 -1
  354. package/node_modules/zod/v4/core/compile.cjs +8 -0
  355. package/node_modules/zod/v4/core/compile.js +8 -0
  356. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  357. package/node_modules/zod/v4/core/schemas.js +30 -0
  358. package/node_modules/zod/v4/core/util.cjs +15 -0
  359. package/node_modules/zod/v4/core/util.js +14 -0
  360. package/node_modules/zod/v4/core/versions.cjs +1 -1
  361. package/node_modules/zod/v4/core/versions.js +1 -1
  362. package/package.json +2 -2
  363. package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
  364. package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { AsyncResource } = require('node:async_hooks')
3
4
  const { PoolStats } = require('../util/stats.js')
4
5
  const DispatcherBase = require('./dispatcher-base')
5
6
  const FixedQueue = require('./fixed-queue')
@@ -20,6 +21,41 @@ const kGetDispatcher = Symbol('get dispatcher')
20
21
  const kHasDispatcher = Symbol('has dispatcher')
21
22
  const kAddClient = Symbol('add client')
22
23
  const kRemoveClient = Symbol('remove client')
24
+ const kRetireClient = Symbol('retire client')
25
+ const kRetiring = Symbol('retiring clients')
26
+
27
+ // Closes every live client, including clients that have been
28
+ // taken out of rotation but are still finishing their own
29
+ // requests.
30
+ // Requests that wait in the Pool queue are dispatched later from whichever
31
+ // callback drains the queue (another request's connect, drain, ...). Capture
32
+ // the caller's async context so Client#dispatch, and the diagnostics channel
33
+ // events it publishes, still run in it.
34
+ class QueuedRequest extends AsyncResource {
35
+ constructor (opts, handler) {
36
+ super('UNDICI_POOL_QUEUED_REQUEST')
37
+ this.opts = opts
38
+ this.handler = handler
39
+ }
40
+
41
+ dispatch (dispatcher) {
42
+ return this.runInAsyncScope(dispatcher.dispatch, dispatcher, this.opts, this.handler)
43
+ }
44
+ }
45
+
46
+ function closeClients (pool) {
47
+ const closeAll = []
48
+ for (let i = 0; i < pool[kClients].length; i++) {
49
+ const client = pool[kClients][i]
50
+ if (!client.destroyed) {
51
+ closeAll.push(client.close())
52
+ }
53
+ }
54
+ for (const closed of pool[kRetiring].values()) {
55
+ closeAll.push(closed)
56
+ }
57
+ return Promise.all(closeAll)
58
+ }
23
59
 
24
60
  class PoolBase extends DispatcherBase {
25
61
  [kQueue] = new FixedQueue();
@@ -28,6 +64,10 @@ class PoolBase extends DispatcherBase {
28
64
 
29
65
  [kClients] = [];
30
66
 
67
+ // Clients removed from kClients that have not finished closing,
68
+ // mapped to a promise that settles once they have.
69
+ [kRetiring] = new Map();
70
+
31
71
  [kNeedDrain] = false;
32
72
 
33
73
  [kOnDrain] (client, origin, targets) {
@@ -46,12 +86,21 @@ class PoolBase extends DispatcherBase {
46
86
  break
47
87
  }
48
88
  this[kQueued]--
49
- needDrain = !client.dispatch(item.opts, item.handler)
89
+ needDrain = !item.dispatch(client)
50
90
  }
51
91
 
52
92
  client[kNeedDrain] = needDrain
53
93
  if (needDrain) {
54
94
  this[kOnClientBusy](client)
95
+
96
+ // This client is full but requests are still queued, e.g. an h2
97
+ // client that has just released everything queued while ALPN was
98
+ // negotiated and hit maxConcurrentStreams. Hand the rest to other
99
+ // clients, creating new ones up to the connection limit, instead of
100
+ // leaving them for this client to drain one batch at a time.
101
+ if (!queue.isEmpty()) {
102
+ return this[kDrainQueue](origin, targets)
103
+ }
55
104
  }
56
105
 
57
106
  if (!needDrain && this[kNeedDrain]) {
@@ -60,15 +109,7 @@ class PoolBase extends DispatcherBase {
60
109
  }
61
110
 
62
111
  if (this[kClosedResolve] && queue.isEmpty()) {
63
- const closeAll = []
64
- for (let i = 0; i < this[kClients].length; i++) {
65
- const client = this[kClients][i]
66
- if (!client.destroyed) {
67
- closeAll.push(client.close())
68
- }
69
- }
70
- return Promise.all(closeAll)
71
- .then(this[kClosedResolve])
112
+ return closeClients(this).then(this[kClosedResolve])
72
113
  }
73
114
  }
74
115
 
@@ -90,7 +131,7 @@ class PoolBase extends DispatcherBase {
90
131
  const item = queue.shift()
91
132
  this[kQueued]--
92
133
 
93
- if (!dispatcher.dispatch(item.opts, item.handler)) {
134
+ if (!item.dispatch(dispatcher)) {
94
135
  dispatcher[kNeedDrain] = true
95
136
  this[kOnClientBusy](dispatcher)
96
137
  hasDispatcher = this[kHasDispatcher]()
@@ -106,15 +147,7 @@ class PoolBase extends DispatcherBase {
106
147
  }
107
148
 
108
149
  if (this[kClosedResolve] && queue.isEmpty()) {
109
- const closeAll = []
110
- for (let i = 0; i < this[kClients].length; i++) {
111
- const client = this[kClients][i]
112
- if (!client.destroyed) {
113
- closeAll.push(client.close())
114
- }
115
- }
116
- return Promise.all(closeAll)
117
- .then(this[kClosedResolve])
150
+ return closeClients(this).then(this[kClosedResolve])
118
151
  }
119
152
  }
120
153
 
@@ -180,14 +213,7 @@ class PoolBase extends DispatcherBase {
180
213
 
181
214
  [kClose] () {
182
215
  if (this[kQueue].isEmpty()) {
183
- const closeAll = []
184
- for (let i = 0; i < this[kClients].length; i++) {
185
- const client = this[kClients][i]
186
- if (!client.destroyed) {
187
- closeAll.push(client.close())
188
- }
189
- }
190
- return Promise.all(closeAll)
216
+ return closeClients(this)
191
217
  } else {
192
218
  return new Promise((resolve) => {
193
219
  this[kClosedResolve] = resolve
@@ -208,6 +234,9 @@ class PoolBase extends DispatcherBase {
208
234
  for (let i = 0; i < this[kClients].length; i++) {
209
235
  destroyAll[i] = this[kClients][i].destroy(err)
210
236
  }
237
+ for (const client of this[kRetiring].keys()) {
238
+ destroyAll.push(client.destroy(err))
239
+ }
211
240
  return Promise.all(destroyAll)
212
241
  }
213
242
 
@@ -216,7 +245,7 @@ class PoolBase extends DispatcherBase {
216
245
 
217
246
  if (!dispatcher) {
218
247
  this[kNeedDrain] = true
219
- this[kQueue].push({ opts, handler })
248
+ this[kQueue].push(new QueuedRequest(opts, handler))
220
249
  this[kQueued]++
221
250
  } else if (!dispatcher.dispatch(opts, handler)) {
222
251
  dispatcher[kNeedDrain] = true
@@ -263,13 +292,37 @@ class PoolBase extends DispatcherBase {
263
292
  return this
264
293
  }
265
294
 
266
- [kRemoveClient] (client) {
295
+ // Takes a client out of rotation. A closed client no longer takes requests
296
+ // from the pool queue (see kOnDrain), but it finishes the requests it
297
+ // already has. Until it has, pool.close() waits for it and pool.destroy()
298
+ // destroys it.
299
+ [kRetireClient] (client) {
267
300
  const idx = this[kClients].indexOf(client)
268
301
  if (idx !== -1) {
269
302
  this[kClients].splice(idx, 1)
270
303
  }
271
304
 
272
- client.close(() => {})
305
+ if (client.destroyed || this[kRetiring].has(client)) {
306
+ return
307
+ }
308
+
309
+ // Use the callback form: custom dispatchers from `factory` are not
310
+ // required to return a promise, and may call back synchronously.
311
+ let done = false
312
+ let resolveClosed
313
+ const closed = new Promise((resolve) => { resolveClosed = resolve })
314
+ this[kRetiring].set(client, closed)
315
+ client.close(() => {
316
+ if (!done) {
317
+ done = true
318
+ this[kRetiring].delete(client)
319
+ resolveClosed()
320
+ }
321
+ })
322
+ }
323
+
324
+ [kRemoveClient] (client) {
325
+ this[kRetireClient](client)
273
326
 
274
327
  this[kNeedDrain] = !this[kClients].some(dispatcher => (
275
328
  !dispatcher[kNeedDrain] &&
@@ -285,6 +338,7 @@ module.exports = {
285
338
  kNeedDrain,
286
339
  kAddClient,
287
340
  kRemoveClient,
341
+ kRetireClient,
288
342
  kDrainQueue,
289
343
  kOnClientBusy,
290
344
  kOnClientDrain,
@@ -10,14 +10,15 @@ const {
10
10
  kOnClientDrain,
11
11
  kGetDispatcher,
12
12
  kHasDispatcher,
13
- kRemoveClient
13
+ kRemoveClient,
14
+ kRetireClient
14
15
  } = require('./pool-base')
15
16
  const Client = require('./client')
16
17
  const {
17
18
  InvalidArgumentError
18
19
  } = require('../core/errors')
19
20
  const util = require('../core/util')
20
- const { kConnecting, kHTTPContext, kUrl } = require('../core/symbols')
21
+ const { kConnecting, kHTTPContext, kUrl, kQueued } = require('../core/symbols')
21
22
  const buildConnector = require('../core/connect')
22
23
 
23
24
  const kOptions = Symbol('options')
@@ -144,15 +145,17 @@ class Pool extends PoolBase {
144
145
  resumeQueued = true
145
146
  }
146
147
 
147
- // Do not use kRemoveClient here, as it will close the client,
148
- // but the client cannot be closed in this state.
149
- const idx = this[kClients].indexOf(target)
150
- if (idx !== -1) {
151
- this[kClients].splice(idx, 1)
148
+ // Retire (close) the client rather than only dropping it from
149
+ // kClients: otherwise its drain listener keeps pulling requests from
150
+ // the pool queue onto a client that pool.destroy() can't reach.
151
+ if (this[kClients].includes(target)) {
152
+ this[kRetireClient](target)
152
153
  }
153
154
  }
154
155
 
155
- if (resumeQueued) {
156
+ // The retired client no longer drains the pool queue, so hand any
157
+ // queued requests to another (possibly new) client.
158
+ if (resumeQueued || this[kQueued] > 0) {
156
159
  this[kDrainQueue](origin, targets.slice(1))
157
160
  }
158
161
  })
@@ -83,11 +83,10 @@ class Http1ProxyWrapper extends DispatcherBase {
83
83
 
84
84
  opts.path = origin + path
85
85
 
86
- if (!('host' in headers) && !('Host' in headers)) {
87
- const { host } = new URL(origin)
88
- headers.host = host
89
- }
90
86
  opts.headers = { ...this[kProxyHeaders], ...headers }
87
+ if (!hasHostHeader(headers)) {
88
+ opts.headers.host = new URL(origin).host
89
+ }
91
90
 
92
91
  // Pin the SNI/cert hostname to the proxy. Without this the underlying
93
92
  // Client would derive it from the (rewritten) Host header, which points
@@ -276,12 +275,14 @@ class ProxyAgent extends DispatcherBase {
276
275
  }
277
276
 
278
277
  dispatch (opts, handler) {
279
- const headers = buildHeaders(opts.headers)
278
+ let headers = buildHeaders(opts.headers)
280
279
  throwIfProxyAuthIsSent(headers)
281
280
 
282
- if (headers && !('host' in headers) && !('Host' in headers)) {
283
- const { host } = new URL(opts.origin)
284
- headers.host = host
281
+ if (headers && !hasHostHeader(headers)) {
282
+ if (headers === opts.headers) {
283
+ headers = { ...headers }
284
+ }
285
+ headers.host = new URL(opts.origin).host
285
286
  }
286
287
 
287
288
  return this[kAgent].dispatch(
@@ -401,6 +402,15 @@ function isProxyAuthorizationHeader (key) {
401
402
  return key.length === proxyAuthorization.length && key.toLowerCase() === proxyAuthorization
402
403
  }
403
404
 
405
+ function hasHostHeader (headers) {
406
+ for (const key in headers) {
407
+ if (key.length === 4 && key.toLowerCase() === 'host') {
408
+ return true
409
+ }
410
+ }
411
+ return false
412
+ }
413
+
404
414
  function throwProxyAuthError () {
405
415
  throw new InvalidArgumentError('Proxy-Authorization should be sent in ProxyAgent constructor')
406
416
  }
@@ -26,6 +26,16 @@ class RetryAgent extends Dispatcher {
26
26
  return this.#agent.dispatch(opts, retry)
27
27
  }
28
28
 
29
+ // WebSocket and EventSource read their receive limits from the dispatcher
30
+ // they are given, so report the wrapped agent's settings rather than none.
31
+ get webSocketOptions () {
32
+ return this.#agent.webSocketOptions
33
+ }
34
+
35
+ get eventSourceOptions () {
36
+ return this.#agent.eventSourceOptions
37
+ }
38
+
29
39
  close () {
30
40
  return this.#agent.close()
31
41
  }
@@ -7,14 +7,16 @@ const {
7
7
  kAddClient,
8
8
  kGetDispatcher,
9
9
  kHasDispatcher,
10
- kRemoveClient
10
+ kRemoveClient,
11
+ kRetireClient,
12
+ kDrainQueue
11
13
  } = require('./pool-base')
12
14
  const Client = require('./client')
13
15
  const {
14
16
  InvalidArgumentError
15
17
  } = require('../core/errors')
16
18
  const util = require('../core/util')
17
- const { kUrl } = require('../core/symbols')
19
+ const { kUrl, kQueued } = require('../core/symbols')
18
20
  const buildConnector = require('../core/connect')
19
21
 
20
22
  const kOptions = Symbol('options')
@@ -82,12 +84,20 @@ class RoundRobinPool extends PoolBase {
82
84
  })
83
85
 
84
86
  this.on('connectionError', (origin, targets, error) => {
87
+ // Retire (close) the client rather than only dropping it from
88
+ // kClients: otherwise its drain listener keeps pulling requests from
89
+ // the pool queue onto a client that pool.destroy() can't reach.
85
90
  for (const target of targets) {
86
- const idx = this[kClients].indexOf(target)
87
- if (idx !== -1) {
88
- this[kClients].splice(idx, 1)
91
+ if (this[kClients].includes(target)) {
92
+ this[kRetireClient](target)
89
93
  }
90
94
  }
95
+
96
+ // The retired client no longer drains the pool queue, so hand any
97
+ // queued requests to another (possibly new) client.
98
+ if (this[kQueued] > 0) {
99
+ this[kDrainQueue](origin, targets.slice(1))
100
+ }
91
101
  })
92
102
  }
93
103
 
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const util = require('../core/util')
4
+ const { kRedirectCacheControl } = require('../core/symbols')
4
5
  const {
5
6
  parseCacheControlHeader,
6
7
  hasInvalidCacheControlDirective,
@@ -13,6 +14,63 @@ const { parseHttpDate } = require('../util/date.js')
13
14
 
14
15
  function noop () {}
15
16
 
17
+ class CacheController {
18
+ #blocked = false
19
+ #downstreamPaused = false
20
+
21
+ constructor (target) {
22
+ this.target = target
23
+ }
24
+
25
+ block () {
26
+ this.#blocked = true
27
+ }
28
+
29
+ release () {
30
+ this.#blocked = false
31
+ if (!this.#downstreamPaused) {
32
+ this.target.resume()
33
+ }
34
+ }
35
+
36
+ pause () {
37
+ this.#downstreamPaused = true
38
+ this.target.pause()
39
+ }
40
+
41
+ resume () {
42
+ this.#downstreamPaused = false
43
+ if (!this.#blocked) {
44
+ this.target.resume()
45
+ }
46
+ }
47
+
48
+ abort (reason) {
49
+ this.target.abort(reason)
50
+ }
51
+
52
+ get paused () { return this.#downstreamPaused }
53
+ get aborted () { return this.target.aborted }
54
+ get reason () { return this.target.reason }
55
+ get rawHeaders () { return this.target.rawHeaders }
56
+ set rawHeaders (value) { this.target.rawHeaders = value }
57
+ get rawTrailers () { return this.target.rawTrailers }
58
+ set rawTrailers (value) { this.target.rawTrailers = value }
59
+ }
60
+
61
+ /**
62
+ * @param {string | URL} a
63
+ * @param {string | URL} b
64
+ * @returns {boolean}
65
+ */
66
+ function sameOrigin (a, b) {
67
+ try {
68
+ return new URL(String(a)).origin === new URL(String(b)).origin
69
+ } catch {
70
+ return String(a) === String(b)
71
+ }
72
+ }
73
+
16
74
  // Status codes that we can use some heuristics on to cache
17
75
  const HEURISTICALLY_CACHEABLE_STATUS_CODES = [
18
76
  200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414, 501
@@ -149,11 +207,24 @@ class CacheHandler {
149
207
  */
150
208
  #handler
151
209
 
210
+ /**
211
+ * @type {CacheController | undefined}
212
+ */
213
+ #downstreamController
214
+
152
215
  /**
153
216
  * @type {import('node:stream').Writable | undefined}
154
217
  */
155
218
  #writeStream
156
219
 
220
+ /**
221
+ * The URLs visited while following redirects, shared by reference from the
222
+ * redirect handler through the request context. Carries the suppressed hops'
223
+ * cache-control under {@link kRedirectCacheControl}.
224
+ * @type {URL[] | undefined}
225
+ */
226
+ #history
227
+
157
228
  /**
158
229
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheHandlerOptions} opts
159
230
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} cacheKey
@@ -170,7 +241,15 @@ class CacheHandler {
170
241
  onRequestStart (controller, context) {
171
242
  this.#writeStream?.destroy()
172
243
  this.#writeStream = undefined
173
- this.#handler.onRequestStart?.(controller, context)
244
+ this.#downstreamController = new CacheController(controller)
245
+ // The redirect handler threads the list of visited URLs through the
246
+ // handler-chain context. Keep a reference to it (it is mutated as redirects
247
+ // are followed) so onResponseStart can tell which request actually produced
248
+ // the response. Unlike the request options object, this reference is not
249
+ // broken by an interceptor that copies the options between the cache and
250
+ // the redirect.
251
+ this.#history = context?.history
252
+ this.#handler.onRequestStart?.(this.#downstreamController, context)
174
253
  }
175
254
 
176
255
  onBodySent (chunk) {
@@ -181,8 +260,8 @@ class CacheHandler {
181
260
  this.#handler.onRequestSent?.()
182
261
  }
183
262
 
184
- onRequestUpgrade (controller, statusCode, headers, socket) {
185
- this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
263
+ onRequestUpgrade (_controller, statusCode, headers, socket) {
264
+ this.#handler.onRequestUpgrade?.(this.#downstreamController, statusCode, headers, socket)
186
265
  }
187
266
 
188
267
  /**
@@ -199,7 +278,7 @@ class CacheHandler {
199
278
  ) {
200
279
  const downstreamOnHeaders = () =>
201
280
  this.#handler.onResponseStart?.(
202
- controller,
281
+ this.#downstreamController,
203
282
  statusCode,
204
283
  resHeaders,
205
284
  statusMessage
@@ -217,6 +296,35 @@ class CacheHandler {
217
296
  return downstreamOnHeaders()
218
297
  }
219
298
 
299
+ // A cross-origin redirect can change the origin that actually produced the
300
+ // final response. Keying that response on the original (trusted) origin
301
+ // would let a redirect target control an entry for a URL the application
302
+ // trusts. The final request is the last URL in the redirect history; only
303
+ // cache when its origin still matches the cache key origin.
304
+ if (this.#history && this.#history.length > 0) {
305
+ const finalUrl = this.#history[this.#history.length - 1]
306
+ if (!sameOrigin(finalUrl.origin, this.#cacheKey.origin)) {
307
+ return downstreamOnHeaders()
308
+ }
309
+ }
310
+
311
+ // A redirect hop that is not forwarded can still carry a restrictive
312
+ // storage policy (for example `no-store`, or `private` for a shared cache).
313
+ // Honor it, otherwise a redirect that must not be stored could be laundered
314
+ // into a cacheable final response under the original key.
315
+ const redirectCacheControl = this.#history?.[kRedirectCacheControl]
316
+ if (redirectCacheControl) {
317
+ for (const hopCacheControl of redirectCacheControl) {
318
+ const hopDirectives = hopCacheControl ? parseCacheControlHeader(hopCacheControl) : {}
319
+ if (
320
+ hopDirectives['no-store'] === true ||
321
+ (this.#cacheType === 'shared' && hopDirectives.private === true)
322
+ ) {
323
+ return downstreamOnHeaders()
324
+ }
325
+ }
326
+ }
327
+
220
328
  const cacheControlHeader = resHeaders['cache-control']
221
329
  const cacheControlDirectives = cacheControlHeader ? parseCacheControlHeader(cacheControlHeader) : {}
222
330
 
@@ -323,10 +431,21 @@ class CacheHandler {
323
431
  // Not modified, re-use the cached value
324
432
  // https://www.rfc-editor.org/rfc/rfc9111.html#name-handling-304-not-modified
325
433
  if (statusCode === 304) {
434
+ let done = false
435
+ const finish304 = () => {
436
+ if (done) {
437
+ return
438
+ }
439
+ done = true
440
+ this.#downstreamController.release()
441
+ }
442
+
326
443
  const handle304 = (cachedValue) => {
327
444
  if (!cachedValue) {
328
445
  // Do not create a new cache entry, as a 304 won't have a body - so cannot be cached.
329
- return downstreamOnHeaders()
446
+ downstreamOnHeaders()
447
+ finish304()
448
+ return
330
449
  }
331
450
 
332
451
  // Re-use the cached value: statuscode, statusmessage, headers and body
@@ -341,6 +460,7 @@ class CacheHandler {
341
460
  this.#writeStream = this.#store.createWriteStream(this.#cacheKey, value)
342
461
 
343
462
  if (!this.#writeStream || !cachedValue?.body) {
463
+ finish304()
344
464
  return
345
465
  }
346
466
 
@@ -348,20 +468,26 @@ class CacheHandler {
348
468
  const bodyIterator = cachedValue.body.values()
349
469
 
350
470
  const streamCachedBody = () => {
471
+ if (done) {
472
+ return
473
+ }
351
474
  for (const chunk of bodyIterator) {
352
- const full = this.#writeStream.write(chunk) === false
353
- this.#handler.onResponseData?.(controller, chunk)
475
+ const full = this.#writeStream?.write(chunk) === false
476
+ this.#handler.onResponseData?.(this.#downstreamController, chunk)
354
477
  // when stream is full stop writing until we get a 'drain' event
355
478
  if (full) {
356
- break
479
+ return
357
480
  }
358
481
  }
482
+ finish304()
359
483
  }
360
484
 
361
485
  this.#writeStream
362
486
  .on('error', function () {
363
487
  handler.#writeStream = undefined
364
488
  handler.#store.delete(handler.#cacheKey)
489
+ // Keep replaying downstream without the store
490
+ streamCachedBody()
365
491
  })
366
492
  .on('drain', () => {
367
493
  streamCachedBody()
@@ -369,6 +495,8 @@ class CacheHandler {
369
495
  .on('close', function () {
370
496
  if (handler.#writeStream === this) {
371
497
  handler.#writeStream = undefined
498
+ // Keep replaying downstream without the store
499
+ streamCachedBody()
372
500
  }
373
501
  })
374
502
 
@@ -377,15 +505,17 @@ class CacheHandler {
377
505
  // Readable stream body (e.g. from async/remote cache stores)
378
506
  cachedValue.body
379
507
  .on('data', (chunk) => {
380
- this.#writeStream.write(chunk)
381
- this.#handler.onResponseData?.(controller, chunk)
508
+ this.#writeStream?.write(chunk)
509
+ this.#handler.onResponseData?.(this.#downstreamController, chunk)
382
510
  })
383
511
  .on('end', () => {
384
- this.#writeStream.end()
512
+ this.#writeStream?.end()
513
+ finish304()
385
514
  })
386
515
  .on('error', () => {
387
516
  this.#writeStream = undefined
388
517
  this.#store.delete(this.#cacheKey)
518
+ finish304()
389
519
  })
390
520
 
391
521
  this.#writeStream
@@ -398,6 +528,8 @@ class CacheHandler {
398
528
  handler.#writeStream = undefined
399
529
  }
400
530
  })
531
+ } else {
532
+ finish304()
401
533
  }
402
534
  }
403
535
 
@@ -405,8 +537,14 @@ class CacheHandler {
405
537
  * @type {import('../../types/cache-interceptor.d.ts').default.CacheValue}
406
538
  */
407
539
  const result = this.#store.get(this.#cacheKey)
540
+ // A 304 ends before the cached body is replayed. Keep the origin
541
+ // response paused until replay is complete.
542
+ this.#downstreamController.block()
543
+ controller.pause()
408
544
  if (result && typeof result.then === 'function') {
409
- result.then(handle304)
545
+ result.then(handle304, () => handle304(undefined)).catch((err) => {
546
+ controller.abort(err)
547
+ })
410
548
  } else {
411
549
  handle304(result)
412
550
  }
@@ -449,18 +587,18 @@ class CacheHandler {
449
587
  controller.pause()
450
588
  }
451
589
 
452
- this.#handler.onResponseData?.(controller, chunk)
590
+ this.#handler.onResponseData?.(this.#downstreamController, chunk)
453
591
  }
454
592
 
455
593
  onResponseEnd (controller, trailers) {
456
594
  this.#writeStream?.end()
457
- this.#handler.onResponseEnd?.(controller, trailers)
595
+ this.#handler.onResponseEnd?.(this.#downstreamController, trailers)
458
596
  }
459
597
 
460
598
  onResponseError (controller, err) {
461
599
  this.#writeStream?.destroy(err)
462
600
  this.#writeStream = undefined
463
- this.#handler.onResponseError?.(controller, err)
601
+ this.#handler.onResponseError?.(this.#downstreamController, err)
464
602
  }
465
603
  }
466
604