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
@@ -55,6 +55,17 @@ class MockAgent extends Dispatcher {
55
55
  }
56
56
  }
57
57
 
58
+ // WebSocket and EventSource read their receive limits from the dispatcher
59
+ // they are given, so report the settings of the agent that makes real
60
+ // connections.
61
+ get webSocketOptions () {
62
+ return this[kAgent].webSocketOptions
63
+ }
64
+
65
+ get eventSourceOptions () {
66
+ return this[kAgent].eventSourceOptions
67
+ }
68
+
58
69
  get (origin) {
59
70
  // Normalize origin to handle URL objects and case-insensitive hostnames
60
71
  const normalizedOrigin = normalizeOrigin(origin)
@@ -4,6 +4,7 @@ const { writeFile, readFile, mkdir } = require('node:fs/promises')
4
4
  const { dirname, resolve } = require('node:path')
5
5
  const { setTimeout, clearTimeout } = require('node:timers')
6
6
  const { InvalidArgumentError, UndiciError } = require('../core/errors')
7
+ const { setHeader } = require('../core/util')
7
8
  const { hashId, isUrlExcludedFactory, normalizeHeaders, createHeaderFilters } = require('./snapshot-utils')
8
9
 
9
10
  /**
@@ -169,7 +170,7 @@ function filterHeadersForMatching (headers, headerFilters, matchOptions = {}) {
169
170
  if (!match.has(headerKey)) continue
170
171
  }
171
172
 
172
- filtered[headerKey] = value
173
+ setHeader(filtered, headerKey, value)
173
174
  }
174
175
 
175
176
  return filtered
@@ -198,7 +199,7 @@ function filterHeadersForStorage (headers, headerFilters, matchOptions = {}) {
198
199
  // Skip if in exclude list (for security)
199
200
  if (excludeSet.has(headerKey)) continue
200
201
 
201
- filtered[headerKey] = value
202
+ setHeader(filtered, headerKey, value)
202
203
  }
203
204
 
204
205
  return filtered
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { InvalidArgumentError } = require('../core/errors')
4
+ const { setHeader } = require('../core/util')
4
5
  const { runtimeFeatures } = require('../util/runtime-features.js')
5
6
 
6
7
  /**
@@ -116,7 +117,7 @@ function normalizeHeaders (headers) {
116
117
  // Convert Buffers to strings if needed
117
118
  const keyStr = Buffer.isBuffer(key) ? key.toString() : key
118
119
  const valueStr = Buffer.isBuffer(value) ? value.toString() : value
119
- normalizedHeaders[keyStr.toLowerCase()] = valueStr
120
+ setHeader(normalizedHeaders, keyStr.toLowerCase(), valueStr)
120
121
  }
121
122
  }
122
123
  return normalizedHeaders
@@ -126,7 +127,7 @@ function normalizeHeaders (headers) {
126
127
  if (headers && typeof headers === 'object') {
127
128
  for (const [key, value] of Object.entries(headers)) {
128
129
  if (key && typeof key === 'string') {
129
- normalizedHeaders[key.toLowerCase()] = Array.isArray(value) ? value.join(', ') : String(value)
130
+ setHeader(normalizedHeaders, key.toLowerCase(), Array.isArray(value) ? value.join(', ') : String(value))
130
131
  }
131
132
  }
132
133
  }
@@ -4,7 +4,8 @@ const {
4
4
  safeHTTPMethods,
5
5
  pathHasQueryOrFragment,
6
6
  hasSafeIterator,
7
- isValidHTTPToken
7
+ isValidHTTPToken,
8
+ setHeader
8
9
  } = require('../core/util')
9
10
 
10
11
  const { serializePathWithQuery } = require('../core/util')
@@ -206,15 +207,20 @@ function makeCacheKey (opts, origin = getRequestOrigin(opts)) {
206
207
 
207
208
  function appendHeader (headers, key, val) {
208
209
  const headerName = key.toLowerCase()
209
- const current = headers[headerName]
210
+ // Reading `headers[headerName]` directly would resolve `__proto__` (and any
211
+ // other inherited name) through the prototype chain rather than report the
212
+ // header as absent.
213
+ const current = Object.hasOwn(headers, headerName)
214
+ ? headers[headerName]
215
+ : undefined
210
216
  const values = Array.isArray(val) ? val : [val]
211
217
 
212
218
  if (current === undefined) {
213
- headers[headerName] = Array.isArray(val) ? val.slice() : val
219
+ setHeader(headers, headerName, Array.isArray(val) ? val.slice() : val)
214
220
  } else if (Array.isArray(current)) {
215
221
  current.push(...values)
216
222
  } else {
217
- headers[headerName] = [current, ...values]
223
+ setHeader(headers, headerName, [current, ...values])
218
224
  }
219
225
  }
220
226
 
@@ -732,7 +738,7 @@ function makeDeduplicationKey (cacheKey, excludeHeaders) {
732
738
  if (excludeHeaders?.has(header.toLowerCase())) {
733
739
  continue
734
740
  }
735
- headers[header] = cacheKey.headers[header]
741
+ setHeader(headers, header, cacheKey.headers[header])
736
742
  }
737
743
  }
738
744
 
@@ -317,8 +317,25 @@ function stringify (cookie) {
317
317
 
318
318
  // A numeric 0 is the Unix epoch, not an absent value -- the same reason the
319
319
  // Max-Age check above tests the type rather than truthiness.
320
- if (cookie.expires != null && cookie.expires.toString() !== 'Invalid Date') {
321
- out.push(`Expires=${toIMFDate(cookie.expires)}`)
320
+ //
321
+ // expires is Date | number, so the "Invalid Date" check only guards the Date
322
+ // form. A number that is not a valid time value (NaN, +/-Infinity, or outside
323
+ // the Date range) would otherwise reach toIMFDate, which splices undefined and
324
+ // NaN into the header value instead of failing.
325
+ if (cookie.expires != null) {
326
+ const expiresMs = cookie.expires instanceof Date
327
+ ? cookie.expires.getTime()
328
+ : cookie.expires
329
+
330
+ // The largest time value a Date can represent, in milliseconds, i.e.
331
+ // 100,000,000 days either side of the epoch (ECMA-262 Date Time Values).
332
+ // Anything within it is safe for toIMFDate to format; anything beyond it
333
+ // produces an invalid Date and must be ignored instead.
334
+ const maxTimeValue = 8640000000000000
335
+
336
+ if (typeof expiresMs === 'number' && Number.isFinite(expiresMs) && Math.abs(expiresMs) <= maxTimeValue) {
337
+ out.push(`Expires=${toIMFDate(cookie.expires)}`)
338
+ }
322
339
  }
323
340
 
324
341
  if (cookie.sameSite) {
@@ -31,6 +31,12 @@ const EVENT = Buffer.from('event')
31
31
  const ID = Buffer.from('id')
32
32
  const RETRY = Buffer.from('retry')
33
33
 
34
+ // Each data field creates a string node, and each unconsumed input chunk keeps
35
+ // a Buffer wrapper. The absolute ceiling protects the large default byte limit.
36
+ const minParserItems = 1024
37
+ const maxParserItems = 131072
38
+ const bytesPerParserItem = 128
39
+
34
40
  function isASCIINumberBytes (buffer, start) {
35
41
  if (start >= buffer.length) {
36
42
  return false
@@ -123,8 +129,13 @@ class EventSourceStream extends Transform {
123
129
  pos = 0
124
130
  lineChunkIndex = 0
125
131
  linePos = 0
126
- eventDataSize = 0
132
+ lineLength = 0
133
+ eventSize = 0
134
+ eventFieldSizes = { data: 0, event: 0, id: 0, retry: 0 }
135
+ dataLineCount = 0
127
136
  maxEventSize
137
+ maxDataLines
138
+ maxBufferedChunks
128
139
 
129
140
  event = {
130
141
  data: undefined,
@@ -149,6 +160,11 @@ class EventSourceStream extends Transform {
149
160
 
150
161
  this.state = options.eventSourceSettings || {}
151
162
  this.maxEventSize = options.maxEventSize ?? defaultMaxEventSize
163
+ const parserItemLimit = this.maxEventSize > 0
164
+ ? Math.min(maxParserItems, Math.max(minParserItems, Math.floor(this.maxEventSize / bytesPerParserItem)))
165
+ : 0
166
+ this.maxDataLines = parserItemLimit
167
+ this.maxBufferedChunks = parserItemLimit
152
168
  if (options.push) {
153
169
  this.push = options.push
154
170
  }
@@ -166,6 +182,14 @@ class EventSourceStream extends Transform {
166
182
  return
167
183
  }
168
184
 
185
+ // A leading line ending can immediately release the currently buffered
186
+ // line, even when it uses the final allowed chunk slot.
187
+ if (this.maxEventSize > 0 &&
188
+ this.chunks.length >= this.maxBufferedChunks &&
189
+ chunk[0] !== LF && chunk[0] !== CR) {
190
+ callback(createMaxEventSizeExceededError())
191
+ return
192
+ }
169
193
  this.chunks.push(chunk)
170
194
 
171
195
  // Strip leading byte-order-mark if we opened the stream and started
@@ -258,12 +282,25 @@ class EventSourceStream extends Transform {
258
282
  continue
259
283
  }
260
284
 
285
+ // readLine() is only called after CR or LF. Reject an unfinished line
286
+ // before it can retain an unbounded number of decoded chunks. The seven
287
+ // extra bytes allow the longest field prefix ("event: " or "retry: ").
288
+ if (this.maxEventSize > 0 && ++this.lineLength > this.maxEventSize + 7) {
289
+ callback(createMaxEventSizeExceededError())
290
+ return
291
+ }
261
292
  this.advanceCursor()
262
293
  }
263
294
 
264
295
  callback()
265
296
  }
266
297
 
298
+ _destroy (error, callback) {
299
+ this.chunks.length = 0
300
+ this.clearEvent()
301
+ super._destroy(error, callback)
302
+ }
303
+
267
304
  /**
268
305
  * @param {Buffer} line
269
306
  * @param {EventSourceStreamEvent} event
@@ -300,12 +337,12 @@ class EventSourceStream extends Transform {
300
337
  }
301
338
 
302
339
  if (isFieldName(line, fieldLength, DATA)) {
303
- const valueBytes = line.length - valueStart
304
- const eventDataSize = this.eventDataSize + (event.data === undefined ? 0 : 1) + valueBytes
305
-
306
- if (this.maxEventSize > 0 && eventDataSize > this.maxEventSize) {
340
+ if (this.maxEventSize > 0 && this.dataLineCount >= this.maxDataLines) {
307
341
  throw createMaxEventSizeExceededError()
308
342
  }
343
+ const valueBytes = line.length - valueStart
344
+ const dataSize = this.eventFieldSizes.data + (event.data === undefined ? 0 : 1) + valueBytes
345
+ this.setEventFieldSize('data', dataSize)
309
346
 
310
347
  const value = line.toString('utf8', valueStart)
311
348
 
@@ -314,12 +351,13 @@ class EventSourceStream extends Transform {
314
351
  } else {
315
352
  event.data += `\n${value}`
316
353
  }
317
- this.eventDataSize = eventDataSize
354
+ this.dataLineCount++
318
355
  return
319
356
  }
320
357
 
321
358
  if (isFieldName(line, fieldLength, RETRY)) {
322
359
  if (isASCIINumberBytes(line, valueStart)) {
360
+ this.setEventFieldSize('retry', line.length - valueStart)
323
361
  event.retry = line.toString('utf8', valueStart)
324
362
  }
325
363
  return
@@ -327,20 +365,29 @@ class EventSourceStream extends Transform {
327
365
 
328
366
  if (isFieldName(line, fieldLength, ID)) {
329
367
  if (isValidLastEventIdBytes(line, valueStart)) {
368
+ this.setEventFieldSize('id', line.length - valueStart)
330
369
  event.id = line.toString('utf8', valueStart)
331
370
  }
332
371
  return
333
372
  }
334
373
 
335
374
  if (isFieldName(line, fieldLength, EVENT)) {
336
- const value = line.toString('utf8', valueStart)
337
-
338
- if (value.length > 0) {
339
- event.event = value
375
+ if (valueStart < line.length) {
376
+ this.setEventFieldSize('event', line.length - valueStart)
377
+ event.event = line.toString('utf8', valueStart)
340
378
  }
341
379
  }
342
380
  }
343
381
 
382
+ setEventFieldSize (field, size) {
383
+ const eventSize = this.eventSize - this.eventFieldSizes[field] + size
384
+ if (this.maxEventSize > 0 && eventSize > this.maxEventSize) {
385
+ throw createMaxEventSizeExceededError()
386
+ }
387
+ this.eventSize = eventSize
388
+ this.eventFieldSizes[field] = size
389
+ }
390
+
344
391
  /**
345
392
  * @param {EventSourceStreamEvent} event
346
393
  */
@@ -371,7 +418,12 @@ class EventSourceStream extends Transform {
371
418
  this.event.event = undefined
372
419
  this.event.id = undefined
373
420
  this.event.retry = undefined
374
- this.eventDataSize = 0
421
+ this.eventSize = 0
422
+ this.dataLineCount = 0
423
+ this.eventFieldSizes.data = 0
424
+ this.eventFieldSizes.event = 0
425
+ this.eventFieldSizes.id = 0
426
+ this.eventFieldSizes.retry = 0
375
427
  }
376
428
 
377
429
  hasPendingEvent () {
@@ -407,14 +459,16 @@ class EventSourceStream extends Transform {
407
459
  syncLineStartToCursor () {
408
460
  this.lineChunkIndex = this.chunkIndex
409
461
  this.linePos = this.pos
462
+ this.lineLength = 0
410
463
  this.dropConsumedChunks()
411
464
  }
412
465
 
413
466
  dropConsumedChunks () {
414
- while (this.lineChunkIndex > 0) {
415
- this.chunks.shift()
416
- this.lineChunkIndex--
417
- this.chunkIndex--
467
+ if (this.lineChunkIndex > 0) {
468
+ const consumed = this.lineChunkIndex
469
+ this.chunks.splice(0, consumed)
470
+ this.lineChunkIndex = 0
471
+ this.chunkIndex -= consumed
418
472
  }
419
473
 
420
474
  if (this.chunkIndex === this.chunks.length) {
@@ -7,6 +7,7 @@ const { EventSourceStream } = require('./eventsource-stream')
7
7
  const { parseMIMEType } = require('../fetch/data-url')
8
8
  const { createFastMessageEvent } = require('../websocket/events')
9
9
  const { isNetworkError } = require('../fetch/response')
10
+ const { cloneRequest } = require('../fetch/request')
10
11
  const { isValidHeaderValue, kEnumerableProperty } = require('../../core/util')
11
12
  const { environmentSettingsObject } = require('../fetch/util')
12
13
  const { createPotentialCORSRequest } = require('./util')
@@ -29,6 +30,14 @@ let experimentalWarned = false
29
30
  */
30
31
  const defaultReconnectionTime = 3000
31
32
 
33
+ /**
34
+ * The largest delay setTimeout supports. Larger values (including Infinity)
35
+ * make Node.js fire the timer after 1 ms instead, which would turn a large
36
+ * reconnection time into a reconnect storm.
37
+ * @type {number}
38
+ */
39
+ const maxReconnectionTime = 2 ** 31 - 1
40
+
32
41
  /**
33
42
  * The readyState attribute represents the state of the connection.
34
43
  * @typedef ReadyState
@@ -222,8 +231,22 @@ class EventSource extends EventTarget {
222
231
 
223
232
  this.#readyState = CONNECTING
224
233
 
234
+ // Fetch a copy of the request so that every connection starts from the
235
+ // original request. Fetch mutates the request it is given (URL list,
236
+ // redirect count, response tainting and, on cross-origin redirects,
237
+ // headers), so reusing it makes reconnects go to the last redirect
238
+ // target and, after 20 redirects in total, fail forever.
239
+ // cloneRequest() shares the URL list, so copy it as well.
240
+ // 301/308 permanent redirects are handled the same as 302/307 temporary
241
+ // redirects. While the original EventSource spec required that permanent
242
+ // redirects be handled, WHATWG removed that requirement and has not
243
+ // yet opted to restore it... therefore all redirects gets handled the
244
+ // same.
245
+ const request = cloneRequest(this.#request)
246
+ request.urlList = [...this.#request.urlList]
247
+
225
248
  const fetchParams = {
226
- request: this.#request,
249
+ request,
227
250
  dispatcher: this.#dispatcher
228
251
  }
229
252
 
@@ -361,7 +384,7 @@ class EventSource extends EventTarget {
361
384
 
362
385
  // 4. Fetch request and process the response obtained in this fashion, if any, as described earlier in this section.
363
386
  this.#connect()
364
- }, this.#state.reconnectionTime)?.unref()
387
+ }, Math.min(this.#state.reconnectionTime, maxReconnectionTime))?.unref()
365
388
  }
366
389
 
367
390
  /**
@@ -39,7 +39,6 @@ const streamRegistry = new FinalizationRegistry((weakRef) => {
39
39
  function extractBody (object, keepalive = false) {
40
40
  // 1. Let stream be null.
41
41
  let stream = null
42
- let controller = null
43
42
 
44
43
  // 2. If object is a ReadableStream object, then set stream to object.
45
44
  if (webidl.is.ReadableStream(object)) {
@@ -52,11 +51,44 @@ function extractBody (object, keepalive = false) {
52
51
  // 4. Otherwise, set stream to a new ReadableStream object, and set
53
52
  // up stream with byte reading support.
54
53
  stream = new ReadableStream({
55
- pull () {},
56
- start (c) {
57
- controller = c
54
+ start () {},
55
+ async pull (controller) {
56
+ // 19.1. Run action.
57
+ const result = action()
58
+
59
+ const iterator = result?.[Symbol.asyncIterator]?.()
60
+ if (iterator == null) {
61
+ // 19.2. Whenever one or more bytes are available and stream is not errored,
62
+ // enqueue the result of creating a Uint8Array from the available bytes into stream.
63
+ if (result?.length && !isErrored(stream)) {
64
+ controller.enqueue(typeof result === 'string' ? textEncoder.encode(result) : new Uint8Array(result))
65
+ }
66
+
67
+ // 19.3. When running action is done, close stream.
68
+ queueMicrotask(() => readableStreamClose(controller))
69
+ return
70
+ }
71
+
72
+ while (true) {
73
+ const { value, done } = await iterator.next()
74
+
75
+ // 19.3. When running action is done, close stream.
76
+ if (done) {
77
+ queueMicrotask(() => readableStreamClose(controller))
78
+ return
79
+ }
80
+
81
+ // 19.2. Whenever one or more bytes are available and stream is not errored,
82
+ // enqueue the result of creating a Uint8Array from the available bytes into stream.
83
+ if (value.length && !isErrored(stream)) {
84
+ controller.enqueue(new Uint8Array(value))
85
+ return
86
+ }
87
+ }
88
+ },
89
+ cancel (reason) {
90
+ return action()[Symbol.asyncIterator]?.().return(reason)
58
91
  },
59
- cancel () {},
60
92
  type: 'bytes'
61
93
  })
62
94
  }
@@ -155,7 +187,7 @@ function extractBody (object, keepalive = false) {
155
187
  // Set source to object.
156
188
  source = object
157
189
 
158
- action = async function * () {
190
+ const parts = (async function * () {
159
191
  for (const part of blobParts) {
160
192
  if (part.stream) {
161
193
  yield * part.stream()
@@ -163,7 +195,8 @@ function extractBody (object, keepalive = false) {
163
195
  yield part
164
196
  }
165
197
  }
166
- }
198
+ })()
199
+ action = () => parts
167
200
 
168
201
  // Set type to `multipart/form-data; boundary=`,
169
202
  // followed by the multipart/form-data boundary string generated
@@ -208,45 +241,21 @@ function extractBody (object, keepalive = false) {
208
241
  }))
209
242
  }
210
243
 
211
- // 11. If source is a byte sequence, then set action to a
244
+ // 18. If source is a byte sequence, then set action to a
212
245
  // step that returns source and length to source’s length.
213
246
  if (typeof source === 'string' || isUint8Array(source)) {
214
- action = () => {
215
- length = typeof source === 'string' ? Buffer.byteLength(source) : source.length
216
- return source
217
- }
247
+ action = () => source
248
+ length = typeof source === 'string' ? Buffer.byteLength(source) : source.length
218
249
  }
219
250
 
220
- // 12. If action is non-null, then run these steps in parallel:
221
- if (action != null) {
222
- ;(async () => {
223
- // 1. Run action.
224
- const result = action()
225
-
226
- // 2. Whenever one or more bytes are available and stream is not errored,
227
- // enqueue the result of creating a Uint8Array from the available bytes into stream.
228
- const iterator = result?.[Symbol.asyncIterator]?.()
229
- if (iterator) {
230
- for await (const bytes of iterator) {
231
- if (isErrored(stream)) break
232
- if (bytes.length) {
233
- controller.enqueue(new Uint8Array(bytes))
234
- }
235
- }
236
- } else if (result?.length && !isErrored(stream)) {
237
- controller.enqueue(typeof result === 'string' ? textEncoder.encode(result) : new Uint8Array(result))
238
- }
239
-
240
- // 3. When running action is done, close stream.
241
- queueMicrotask(() => readableStreamClose(controller))
242
- })()
243
- }
251
+ // 19. If action is non-null, then run these steps in parallel:
252
+ // Note: this is done in the pull method of the stream created above
244
253
 
245
- // 13. Let body be a body whose stream is stream, source is source,
254
+ // 20. Let body be a body whose stream is stream, source is source,
246
255
  // and length is length.
247
256
  const body = { stream, source, length }
248
257
 
249
- // 14. Return (body, type).
258
+ // 21. Return (body, type).
250
259
  return [body, type]
251
260
  }
252
261
 
@@ -261,19 +261,27 @@ function parseContentDispositionAttribute (input, position) {
261
261
  position
262
262
  )
263
263
 
264
- // Check for utf-8'' prefix (case insensitive)
264
+ const charsetSeparator = headerValue.indexOf(0x27)
265
+ const languageSeparator = charsetSeparator === -1
266
+ ? -1
267
+ : headerValue.indexOf(0x27, charsetSeparator + 1)
268
+
269
+ if (charsetSeparator === -1 || languageSeparator === -1) {
270
+ throw parsingError('expected charset and language separators in extended value')
271
+ }
272
+
265
273
  if (
274
+ charsetSeparator !== 5 ||
266
275
  (headerValue[0] !== 0x75 && headerValue[0] !== 0x55) || // u or U
267
276
  (headerValue[1] !== 0x74 && headerValue[1] !== 0x54) || // t or T
268
277
  (headerValue[2] !== 0x66 && headerValue[2] !== 0x46) || // f or F
269
278
  headerValue[3] !== 0x2d || // -
270
279
  headerValue[4] !== 0x38 // 8
271
280
  ) {
272
- throw parsingError('unknown encoding, expected utf-8\'\'')
281
+ throw parsingError('unknown charset, expected utf-8')
273
282
  }
274
283
 
275
- // Skip utf-8'' and decode the rest
276
- value = decodeURIComponent(decoder.decode(headerValue.subarray(7)))
284
+ value = decodeURIComponent(decoder.decode(headerValue.subarray(languageSeparator + 1)))
277
285
  } else if (input[position.position] === 0x22 /* " */) {
278
286
  // Quoted string
279
287
  position.position++ // skip opening quote
@@ -3,7 +3,7 @@
3
3
  'use strict'
4
4
 
5
5
  const { kConstruct } = require('../../core/symbols')
6
- const { kEnumerableProperty } = require('../../core/util')
6
+ const { kEnumerableProperty, setHeader } = require('../../core/util')
7
7
  const {
8
8
  iteratorMixin,
9
9
  isValidHeaderName,
@@ -320,7 +320,7 @@ class HeadersList {
320
320
 
321
321
  if (this.headersMap.size !== 0) {
322
322
  for (const { name, value } of this.headersMap.values()) {
323
- headers[name] = value
323
+ setHeader(headers, name, value)
324
324
  }
325
325
  }
326
326
 
@@ -2280,8 +2280,6 @@ async function httpNetworkFetch (
2280
2280
  appendHeadersListFromResponseHeaders(headersList, headers, rawHeaders)
2281
2281
  const location = headersList.get('location', true)
2282
2282
 
2283
- this.body = new Readable({ read: () => controller.resume() })
2284
-
2285
2283
  const willFollow = location && request.redirect === 'follow' &&
2286
2284
  redirectStatusSet.has(status)
2287
2285
 
@@ -2299,7 +2297,7 @@ async function httpNetworkFetch (
2299
2297
  // CVE fix similar to urllib3 (GHSA-gm62-xv2j-4w53) and curl (CVE-2022-32206).
2300
2298
  const maxContentEncodings = 5
2301
2299
  if (codings.length > maxContentEncodings) {
2302
- reject(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`))
2300
+ controller.abort(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`))
2303
2301
  return
2304
2302
  }
2305
2303
 
@@ -2328,7 +2326,11 @@ async function httpNetworkFetch (
2328
2326
  } else if (coding === 'zstd') {
2329
2327
  decoders.push(zlib.createZstdDecompress({
2330
2328
  flush: zlib.constants.ZSTD_e_continue,
2331
- finishFlush: zlib.constants.ZSTD_e_end
2329
+ finishFlush: zlib.constants.ZSTD_e_end,
2330
+ params: {
2331
+ // https://www.rfc-editor.org/rfc/rfc9659.html#section-3
2332
+ [zlib.constants.ZSTD_d_windowLogMax]: 23
2333
+ }
2332
2334
  }))
2333
2335
  } else {
2334
2336
  decoders.length = 0
@@ -2337,6 +2339,8 @@ async function httpNetworkFetch (
2337
2339
  }
2338
2340
  }
2339
2341
 
2342
+ this.body = new Readable({ read: () => controller.resume() })
2343
+
2340
2344
  const onError = (err) => this.onResponseError(controller, err)
2341
2345
 
2342
2346
  resolve({
@@ -2,6 +2,7 @@
2
2
 
3
3
  const assert = require('node:assert')
4
4
  const { runtimeFeatures } = require('../../util/runtime-features.js')
5
+ const { asciiLowercase } = require('../infra/index.js')
5
6
 
6
7
  /**
7
8
  * @typedef {object} Metadata
@@ -66,14 +67,12 @@ const getSRIHashAlgorithmIndex = /** @type {GetSRIHashAlgorithmIndex} */ (Map.pr
66
67
 
67
68
  /**
68
69
  * @typedef IsValidSRIHashAlgorithm
70
+ * @see https://w3c.github.io/webappsec-subresource-integrity/#valid-sri-hash-algorithm-token
69
71
  * @type {(algorithm: string) => algorithm is SRIHashAlgorithm}
70
72
  * @param {*} algorithm
71
73
  * @returns {algorithm is SRIHashAlgorithm}
72
74
  */
73
-
74
- const isValidSRIHashAlgorithm = /** @type {IsValidSRIHashAlgorithm} */ (
75
- Map.prototype.has.bind(validSRIHashAlgorithmTokenSet)
76
- )
75
+ const isValidSRIHashAlgorithm = (algorithm) => validSRIHashAlgorithmTokenSet.has(asciiLowercase(algorithm))
77
76
 
78
77
  /**
79
78
  * @param {Uint8Array} bytes
@@ -229,7 +228,8 @@ function parseMetadata (metadata) {
229
228
  // 8. Let metadata be the ordered map
230
229
  // «["alg" → algorithm, "val" → base64-value]».
231
230
  const metadata = {
232
- alg: algorithm,
231
+ // Possible spec bug?
232
+ alg: asciiLowercase(algorithm),
233
233
  val: base64Value
234
234
  }
235
235