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.
- package/LICENSE +7 -7
- package/README.md +78 -18
- package/README.zh-CN.md +73 -15
- package/THIRD_PARTY_NOTICES.txt +12 -12
- package/dist/pi-goal.js +13 -0
- package/dist/pi-tui-runner.js +44 -1
- package/dist/run-command-core.js +111 -70
- package/dist/run-session-command.js +91 -15
- package/dist/run-turn-outcome.js +2 -33
- package/dist/runtime-host-session-channel.js +3 -1
- package/dist/runtime-host-session-driver.js +5 -0
- package/dist/tui-copy-catalog.js +24 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
- package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
- package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
- package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
- package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
- package/node_modules/@maka/core/dist/event-wait.js +28 -10
- package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
- package/node_modules/@maka/core/dist/model-catalog.js +19 -1
- package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
- package/node_modules/@maka/core/dist/model-metadata.js +42 -1
- package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
- package/node_modules/@maka/core/dist/provider-registry.js +16 -2
- package/node_modules/@maka/core/dist/runtime-event.js +8 -0
- package/node_modules/@maka/core/dist/session-checkin.js +31 -0
- package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
- package/node_modules/@maka/core/package.json +2 -0
- package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
- package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
- package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
- package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
- package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
- package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
- package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
- package/node_modules/@maka/mcp/package.json +1 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +22 -9
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +101 -127
- package/node_modules/@maka/runtime/dist/event-wait-tool.js +2 -2
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +32 -1
- package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
- package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
- package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
- package/node_modules/@maka/runtime/dist/model-history.js +16 -3
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +7 -2
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
- package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
- package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
- package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
- package/node_modules/@maka/runtime/dist/tool-runtime.js +8 -0
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
- package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
- package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
- package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
- package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
- package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
- package/node_modules/@maka/runtime/package.json +2 -0
- package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
- package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
- package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +64 -13
- package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
- package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
- package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
- package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +1 -1
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +35 -5
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +1 -1
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +87 -23
- package/node_modules/@maka/runtime-host/dist/assistant/service.js +49 -5
- package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
- package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
- package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +63 -12
- package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +123 -11
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +126 -4
- package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +58 -19
- package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
- package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
- package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
- package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
- package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
- package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
- package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
- package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
- package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
- package/node_modules/@maka/storage/dist/execution-stores.js +36 -1
- package/node_modules/@maka/storage/dist/local-execution-persistence.js +26 -0
- package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +86 -16
- package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
- package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
- package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
- package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +31 -0
- package/node_modules/@maka/storage/package.json +3 -0
- package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
- package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
- package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
- package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
- package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
- package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
- package/node_modules/@modelcontextprotocol/client/package.json +5 -5
- package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
- package/node_modules/fast-uri/README.md +8 -0
- package/node_modules/fast-uri/index.js +98 -18
- package/node_modules/fast-uri/lib/utils.js +52 -0
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/follow-redirects/index.js +10 -1
- package/node_modules/follow-redirects/package.json +1 -1
- package/node_modules/ip-address/README.md +104 -104
- package/node_modules/ip-address/dist/ipv4.js +7 -0
- package/node_modules/ip-address/dist/ipv6.js +7 -4
- package/node_modules/ip-address/dist/v6/constants.js +3 -0
- package/node_modules/ip-address/package.json +2 -1
- package/node_modules/undici/README.md +25 -3
- package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
- package/node_modules/undici/docs/docs/api/Client.md +11 -6
- package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
- package/node_modules/undici/docs/docs/api/Errors.md +76 -1
- package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
- package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
- package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
- package/node_modules/undici/docs/docs/index.md +12 -12
- package/node_modules/undici/docs/docs/type-map.json +66 -66
- package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
- package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
- package/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/undici/lib/core/constants.js +12 -1
- package/node_modules/undici/lib/core/errors.js +38 -1
- package/node_modules/undici/lib/core/request.js +16 -1
- package/node_modules/undici/lib/core/symbols.js +2 -0
- package/node_modules/undici/lib/core/util.js +26 -1
- package/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
- package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
- package/node_modules/undici/lib/dispatcher/client.js +4 -1
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
- package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
- package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
- package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
- package/node_modules/undici/lib/dispatcher/pool.js +11 -8
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
- package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
- package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
- package/node_modules/undici/lib/handler/cache-handler.js +153 -15
- package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
- package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
- package/node_modules/undici/lib/handler/retry-handler.js +44 -11
- package/node_modules/undici/lib/interceptor/cache.js +11 -3
- package/node_modules/undici/lib/interceptor/decompress.js +22 -9
- package/node_modules/undici/lib/interceptor/dns.js +11 -0
- package/node_modules/undici/lib/interceptor/response-error.js +72 -28
- package/node_modules/undici/lib/milo/LICENSE.md +7 -0
- package/node_modules/undici/lib/milo/no-simd.js +1002 -0
- package/node_modules/undici/lib/milo/simd.js +1002 -0
- package/node_modules/undici/lib/mock/mock-agent.js +11 -0
- package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
- package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
- package/node_modules/undici/lib/util/cache.js +11 -5
- package/node_modules/undici/lib/web/cookies/util.js +19 -2
- package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
- package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
- package/node_modules/undici/lib/web/fetch/body.js +47 -38
- package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
- package/node_modules/undici/lib/web/fetch/headers.js +2 -2
- package/node_modules/undici/lib/web/fetch/index.js +8 -4
- package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
- package/node_modules/undici/package.json +9 -7
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +2 -2
- package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
- package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
|
@@ -0,0 +1,1064 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert')
|
|
4
|
+
const util = require('../core/util.js')
|
|
5
|
+
const timers = require('../util/timers.js')
|
|
6
|
+
const {
|
|
7
|
+
HeadersTimeoutError,
|
|
8
|
+
HeadersOverflowError,
|
|
9
|
+
SocketError,
|
|
10
|
+
InformationalError,
|
|
11
|
+
BodyTimeoutError,
|
|
12
|
+
HTTPParserError,
|
|
13
|
+
ResponseContentLengthMismatchError,
|
|
14
|
+
ResponseExceededMaxSizeError
|
|
15
|
+
} = require('../core/errors.js')
|
|
16
|
+
const {
|
|
17
|
+
kUrl,
|
|
18
|
+
kReset,
|
|
19
|
+
kClient,
|
|
20
|
+
kParser,
|
|
21
|
+
kBlocking,
|
|
22
|
+
kRunning,
|
|
23
|
+
kWriting,
|
|
24
|
+
kQueue,
|
|
25
|
+
kKeepAliveDefaultTimeout,
|
|
26
|
+
kRunningIdx,
|
|
27
|
+
kError,
|
|
28
|
+
kPipelining,
|
|
29
|
+
kSocket,
|
|
30
|
+
kKeepAliveTimeoutValue,
|
|
31
|
+
kKeepAliveMaxTimeout,
|
|
32
|
+
kKeepAliveTimeoutThreshold,
|
|
33
|
+
kBodyTimeout,
|
|
34
|
+
kMaxResponseSize,
|
|
35
|
+
kResume,
|
|
36
|
+
kHTTPContext,
|
|
37
|
+
kMaxHeadersSize
|
|
38
|
+
} = require('../core/symbols.js')
|
|
39
|
+
|
|
40
|
+
const FastBuffer = Buffer[Symbol.species]
|
|
41
|
+
const removeAllListeners = util.removeAllListeners
|
|
42
|
+
|
|
43
|
+
const kPausedByHandler = Symbol('kPausedByHandler')
|
|
44
|
+
|
|
45
|
+
const BUFFER_PAGE_SIZE = 4096
|
|
46
|
+
const INITIAL_BUFFER_SIZE = 128 * 1024
|
|
47
|
+
const EMPTY_BUF = Buffer.alloc(0)
|
|
48
|
+
const BODY_KIND_CONTENT_LENGTH = 0
|
|
49
|
+
const EVENT_RANGE_SIZE = 9
|
|
50
|
+
const EVENT_HEADERS_SIZE = 19
|
|
51
|
+
|
|
52
|
+
let miloPackage
|
|
53
|
+
|
|
54
|
+
// We disable wasm SIMD on ppc64 as it seems to be broken on Power 9 architectures.
|
|
55
|
+
let useWasmSIMD = process.arch !== 'ppc64'
|
|
56
|
+
// The Env Variable UNDICI_NO_WASM_SIMD allows explicitly overriding the default behavior.
|
|
57
|
+
if (process.env.UNDICI_NO_WASM_SIMD === '1') {
|
|
58
|
+
useWasmSIMD = false
|
|
59
|
+
} else if (process.env.UNDICI_NO_WASM_SIMD === '0') {
|
|
60
|
+
useWasmSIMD = true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const USE_NATIVE_TIMER = 0
|
|
64
|
+
const USE_FAST_TIMER = 1
|
|
65
|
+
const TIMEOUT_HEADERS = 2 | USE_FAST_TIMER
|
|
66
|
+
const TIMEOUT_BODY = 4 | USE_FAST_TIMER
|
|
67
|
+
const TIMEOUT_KEEP_ALIVE = 8 | USE_NATIVE_TIMER
|
|
68
|
+
|
|
69
|
+
let miloEnabled =
|
|
70
|
+
process.env.UNDICI_USE_MILO === '1' || process.env.UNDICI_USE_MILO === 'true'
|
|
71
|
+
let miloInstance = null
|
|
72
|
+
let currentBuffer = null
|
|
73
|
+
let currentBufferSize = 0
|
|
74
|
+
let currentBufferPtr = null
|
|
75
|
+
let currentBufferRef = null
|
|
76
|
+
|
|
77
|
+
function onParserTimeout (parserWeakRef) {
|
|
78
|
+
const parser = parserWeakRef.deref ? parserWeakRef.deref() : parserWeakRef
|
|
79
|
+
if (!parser) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { socket, timeoutType, client, paused } = parser
|
|
84
|
+
|
|
85
|
+
if (timeoutType === TIMEOUT_HEADERS) {
|
|
86
|
+
if (!socket[kWriting] || socket.writableNeedDrain || client[kRunning] > 1) {
|
|
87
|
+
assert(!paused, 'cannot be paused while waiting for headers')
|
|
88
|
+
util.destroy(socket, new HeadersTimeoutError())
|
|
89
|
+
}
|
|
90
|
+
} else if (timeoutType === TIMEOUT_BODY) {
|
|
91
|
+
if (!paused) {
|
|
92
|
+
util.destroy(socket, new BodyTimeoutError())
|
|
93
|
+
}
|
|
94
|
+
} else if (timeoutType === TIMEOUT_KEEP_ALIVE) {
|
|
95
|
+
assert(client[kRunning] === 0 && client[kKeepAliveTimeoutValue])
|
|
96
|
+
util.destroy(socket, new InformationalError('socket idle timeout'))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getMilo () {
|
|
101
|
+
if (miloInstance) {
|
|
102
|
+
return miloInstance
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Milo modules compile WASM on load; defer loading until the parser is needed.
|
|
106
|
+
if (useWasmSIMD) {
|
|
107
|
+
try {
|
|
108
|
+
miloPackage = require('../milo/simd.js')
|
|
109
|
+
} catch {}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
miloPackage = miloPackage || require('../milo/no-simd.js')
|
|
113
|
+
miloInstance = miloPackage.setup()
|
|
114
|
+
return miloInstance
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
class H1Parser {
|
|
118
|
+
constructor (client, socket) {
|
|
119
|
+
this.milo = getMilo()
|
|
120
|
+
|
|
121
|
+
this.client = client
|
|
122
|
+
this.socket = socket
|
|
123
|
+
this.parser = this.milo.create()
|
|
124
|
+
this.events = new FastBuffer(
|
|
125
|
+
this.milo.memory.buffer,
|
|
126
|
+
this.parser + this.milo.ParserFields.EVENTS,
|
|
127
|
+
4
|
|
128
|
+
).readUInt32LE(0)
|
|
129
|
+
|
|
130
|
+
this.milo.setShouldAutodetect(this.parser, false)
|
|
131
|
+
this.milo.setIsRequest(this.parser, false)
|
|
132
|
+
this.milo.setShouldManageUnconsumed(this.parser, false)
|
|
133
|
+
this.milo.setShouldSuspendAfterHeaders(this.parser, true)
|
|
134
|
+
this.milo.setMaxHeaderLength(this.parser, client[kMaxHeadersSize])
|
|
135
|
+
this.milo.setActiveEvents(
|
|
136
|
+
this.parser,
|
|
137
|
+
this.milo.EVENT_ACTIVE_ON_ERROR |
|
|
138
|
+
this.milo.EVENT_ACTIVE_ON_MESSAGE_COMPLETE |
|
|
139
|
+
this.milo.EVENT_ACTIVE_ON_REASON |
|
|
140
|
+
this.milo.EVENT_ACTIVE_ON_HEADER_NAME |
|
|
141
|
+
this.milo.EVENT_ACTIVE_ON_HEADER_VALUE |
|
|
142
|
+
this.milo.EVENT_ACTIVE_ON_HEADERS |
|
|
143
|
+
this.milo.EVENT_ACTIVE_ON_DATA |
|
|
144
|
+
this.milo.EVENT_ACTIVE_ON_TRAILER_NAME |
|
|
145
|
+
this.milo.EVENT_ACTIVE_ON_TRAILER_VALUE
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
this.timeout = null
|
|
149
|
+
this.timeoutWeakRef = new WeakRef(this)
|
|
150
|
+
this.timeoutValue = null
|
|
151
|
+
this.timeoutType = null
|
|
152
|
+
this.statusCode = 0
|
|
153
|
+
this.statusText = ''
|
|
154
|
+
this.upgrade = false
|
|
155
|
+
this.responseStarted = false
|
|
156
|
+
this.pausedByParser = false
|
|
157
|
+
this.pauseStateIsStart = false
|
|
158
|
+
this.headers = []
|
|
159
|
+
this.trailers = []
|
|
160
|
+
this.headersSize = 0
|
|
161
|
+
this.trailersSize = 0
|
|
162
|
+
this.headersMaxSize = client[kMaxHeadersSize]
|
|
163
|
+
this.shouldKeepAlive = false
|
|
164
|
+
this.paused = false
|
|
165
|
+
this.errored = false
|
|
166
|
+
this.waitingForMoreData = 0
|
|
167
|
+
this.resume = this.resume.bind(this)
|
|
168
|
+
this.bytesRead = 0
|
|
169
|
+
this.keepAlive = ''
|
|
170
|
+
this.connection = ''
|
|
171
|
+
this.contentLength = -1
|
|
172
|
+
this.maxResponseSize = client[kMaxResponseSize]
|
|
173
|
+
this.directBodyRemaining = 0
|
|
174
|
+
this.directBodyCompletePending = false
|
|
175
|
+
this.headersSuspended = false
|
|
176
|
+
this.skipBody = false
|
|
177
|
+
|
|
178
|
+
this[kPausedByHandler] = false
|
|
179
|
+
|
|
180
|
+
if (
|
|
181
|
+
INITIAL_BUFFER_SIZE > currentBufferSize ||
|
|
182
|
+
currentBuffer.buffer !== this.milo.memory.buffer
|
|
183
|
+
) {
|
|
184
|
+
this.ensureBuffers(INITIAL_BUFFER_SIZE)
|
|
185
|
+
} else {
|
|
186
|
+
this.updateBuffers()
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
setTimeout (delay, type) {
|
|
191
|
+
if (
|
|
192
|
+
delay !== this.timeoutValue ||
|
|
193
|
+
(type & USE_FAST_TIMER) ^ (this.timeoutType & USE_FAST_TIMER)
|
|
194
|
+
) {
|
|
195
|
+
if (this.timeout) {
|
|
196
|
+
timers.clearTimeout(this.timeout)
|
|
197
|
+
this.timeout = null
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (delay) {
|
|
201
|
+
if (type & USE_FAST_TIMER) {
|
|
202
|
+
this.timeout = timers.setFastTimeout(
|
|
203
|
+
onParserTimeout,
|
|
204
|
+
delay,
|
|
205
|
+
this.timeoutWeakRef
|
|
206
|
+
)
|
|
207
|
+
} else {
|
|
208
|
+
this.timeout = setTimeout(
|
|
209
|
+
onParserTimeout,
|
|
210
|
+
delay,
|
|
211
|
+
this.timeoutWeakRef
|
|
212
|
+
)
|
|
213
|
+
this.timeout?.unref()
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this.timeoutValue = delay
|
|
218
|
+
} else if (this.timeout?.refresh) {
|
|
219
|
+
this.timeout.refresh()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.timeoutType = type
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
ensureBuffers (size) {
|
|
226
|
+
const { milo } = this
|
|
227
|
+
|
|
228
|
+
if (currentBufferPtr != null) {
|
|
229
|
+
milo.dealloc(currentBufferPtr, currentBufferSize)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Reallocate buffers
|
|
233
|
+
currentBufferSize = Math.ceil(size / BUFFER_PAGE_SIZE) * BUFFER_PAGE_SIZE
|
|
234
|
+
currentBufferPtr = milo.alloc(currentBufferSize)
|
|
235
|
+
currentBuffer = new FastBuffer(
|
|
236
|
+
milo.memory.buffer,
|
|
237
|
+
currentBufferPtr,
|
|
238
|
+
currentBufferSize
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
this.updateBuffers()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
updateBuffers () {
|
|
245
|
+
this.parserFields = new FastBuffer(this.milo.memory.buffer, this.parser)
|
|
246
|
+
this.parserEvents = new FastBuffer(
|
|
247
|
+
this.milo.memory.buffer,
|
|
248
|
+
this.events,
|
|
249
|
+
64 * 1024
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
resume () {
|
|
254
|
+
if (this.socket.destroyed || !this.paused) {
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
this.milo.resume(this.parser)
|
|
259
|
+
|
|
260
|
+
assert(this.timeoutType === TIMEOUT_BODY)
|
|
261
|
+
if (this.timeout?.refresh) {
|
|
262
|
+
this.timeout.refresh()
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
this.paused = false
|
|
266
|
+
if (this.directBodyCompletePending) {
|
|
267
|
+
try {
|
|
268
|
+
this.completeDirectBody()
|
|
269
|
+
} catch (err) {
|
|
270
|
+
util.destroy(this.socket, err)
|
|
271
|
+
return
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (this.paused) {
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.readMore()
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
readMore () {
|
|
283
|
+
if (this.paused || !this.parser) {
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
while (!this.paused && this.parser) {
|
|
288
|
+
if (
|
|
289
|
+
this.waitingForMoreData &&
|
|
290
|
+
this.socket.readableLength <= this.waitingForMoreData
|
|
291
|
+
) {
|
|
292
|
+
break
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
this.waitingForMoreData = 0
|
|
296
|
+
|
|
297
|
+
const chunk = this.socket.read()
|
|
298
|
+
if (chunk === null) {
|
|
299
|
+
break
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (this.execute(chunk) === false) {
|
|
303
|
+
break
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
execute (data) {
|
|
309
|
+
const available = data.length
|
|
310
|
+
assert(!this.paused)
|
|
311
|
+
|
|
312
|
+
const { socket, milo } = this
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
if (this.directBodyRemaining > 0) {
|
|
316
|
+
return this.consumeDirectBody(data)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (currentBuffer.buffer !== milo.memory.buffer) {
|
|
320
|
+
currentBuffer = new FastBuffer(
|
|
321
|
+
milo.memory.buffer,
|
|
322
|
+
currentBufferPtr,
|
|
323
|
+
currentBufferSize
|
|
324
|
+
)
|
|
325
|
+
this.updateBuffers()
|
|
326
|
+
} else if (this.parserEvents.buffer !== milo.memory.buffer) {
|
|
327
|
+
this.updateBuffers()
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
let offset = 0
|
|
331
|
+
let parseLen = available
|
|
332
|
+
const headersEnd = this.statusCode === 0 ? data.indexOf('\r\n\r\n') : -1
|
|
333
|
+
|
|
334
|
+
if (headersEnd !== -1) {
|
|
335
|
+
parseLen = headersEnd + 4
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
for (;;) {
|
|
339
|
+
if (parseLen > currentBufferSize) {
|
|
340
|
+
this.ensureBuffers(parseLen)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const parseData = data.subarray(offset, offset + parseLen)
|
|
344
|
+
currentBuffer.set(parseData)
|
|
345
|
+
currentBufferRef = parseData
|
|
346
|
+
|
|
347
|
+
const consumed = milo.parse(this.parser, currentBufferPtr, parseLen)
|
|
348
|
+
this.drainEvents()
|
|
349
|
+
|
|
350
|
+
const consumedTotal = offset + consumed
|
|
351
|
+
|
|
352
|
+
if (
|
|
353
|
+
this.errored ||
|
|
354
|
+
(consumed === 0 &&
|
|
355
|
+
this.parserFields[milo.ParserFields.ERROR_CODE] !== milo.ERROR_NONE)
|
|
356
|
+
) {
|
|
357
|
+
throw this.createError(data.subarray(consumedTotal))
|
|
358
|
+
} else if (this.upgrade) {
|
|
359
|
+
this.onUpgrade(data.subarray(consumedTotal))
|
|
360
|
+
return false
|
|
361
|
+
} else if (this.directBodyCompletePending) {
|
|
362
|
+
this.completeDirectBody()
|
|
363
|
+
|
|
364
|
+
if (this.paused) {
|
|
365
|
+
return false
|
|
366
|
+
}
|
|
367
|
+
} else if (this.pausedByParser) {
|
|
368
|
+
this.pausedByParser = false
|
|
369
|
+
this.headersSuspended = false
|
|
370
|
+
if (this[kPausedByHandler] && this.pauseStateIsStart) {
|
|
371
|
+
this.pauseStateIsStart = false
|
|
372
|
+
milo.resume(this.parser)
|
|
373
|
+
this[kPausedByHandler] = false
|
|
374
|
+
return false
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
this.pauseStateIsStart = false
|
|
378
|
+
this.paused = true
|
|
379
|
+
socket.unshift(data.subarray(consumedTotal))
|
|
380
|
+
return false
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (this.directBodyRemaining > 0) {
|
|
384
|
+
return this.consumeDirectBody(data.subarray(consumedTotal))
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (consumed < parseLen) {
|
|
388
|
+
const remaining = data.subarray(consumedTotal)
|
|
389
|
+
socket.unshift(remaining)
|
|
390
|
+
this.waitingForMoreData = consumed === 0 ? remaining.length : 0
|
|
391
|
+
return false
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
offset = consumedTotal
|
|
395
|
+
|
|
396
|
+
if (offset >= available) {
|
|
397
|
+
if (this.headersSuspended) {
|
|
398
|
+
this.headersSuspended = false
|
|
399
|
+
parseLen = 0
|
|
400
|
+
continue
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return true
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
this.headersSuspended = false
|
|
407
|
+
parseLen = available - offset
|
|
408
|
+
}
|
|
409
|
+
} catch (err) {
|
|
410
|
+
util.destroy(socket, err)
|
|
411
|
+
return false
|
|
412
|
+
} finally {
|
|
413
|
+
currentBufferRef = null
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
consumeDirectBody (data) {
|
|
418
|
+
const { socket, client, maxResponseSize } = this
|
|
419
|
+
const available = data.length
|
|
420
|
+
const len = Math.min(available, this.directBodyRemaining)
|
|
421
|
+
|
|
422
|
+
if (this.timeout?.refresh) {
|
|
423
|
+
this.timeout.refresh()
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (len > 0) {
|
|
427
|
+
const request = client[kQueue][client[kRunningIdx]]
|
|
428
|
+
assert(request)
|
|
429
|
+
assert(this.timeoutType === TIMEOUT_BODY)
|
|
430
|
+
assert(this.statusCode >= 200)
|
|
431
|
+
|
|
432
|
+
if (maxResponseSize > -1 && this.bytesRead + len > maxResponseSize) {
|
|
433
|
+
throw new ResponseExceededMaxSizeError()
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
this.bytesRead += len
|
|
437
|
+
this.directBodyRemaining -= len
|
|
438
|
+
|
|
439
|
+
if (request.onResponseData(data.subarray(0, len)) === false) {
|
|
440
|
+
this.directBodyCompletePending = this.directBodyRemaining === 0
|
|
441
|
+
this.pauseParser()
|
|
442
|
+
this[kPausedByHandler] = true
|
|
443
|
+
this.pausedByParser = false
|
|
444
|
+
this.paused = true
|
|
445
|
+
|
|
446
|
+
if (len < available) {
|
|
447
|
+
socket.unshift(data.subarray(len))
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return false
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (this.directBodyRemaining === 0) {
|
|
455
|
+
this.completeDirectBody()
|
|
456
|
+
|
|
457
|
+
const remaining = data.subarray(len)
|
|
458
|
+
if (
|
|
459
|
+
this.errored ||
|
|
460
|
+
this.parserFields[this.milo.ParserFields.ERROR_CODE] !==
|
|
461
|
+
this.milo.ERROR_NONE
|
|
462
|
+
) {
|
|
463
|
+
throw this.createError(remaining)
|
|
464
|
+
} else if (this.pausedByParser) {
|
|
465
|
+
this.pausedByParser = false
|
|
466
|
+
this.pauseStateIsStart = false
|
|
467
|
+
this.paused = true
|
|
468
|
+
if (remaining.length > 0) {
|
|
469
|
+
socket.unshift(remaining)
|
|
470
|
+
}
|
|
471
|
+
return false
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (remaining.length > 0) {
|
|
475
|
+
socket.unshift(remaining)
|
|
476
|
+
return false
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return true
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
completeDirectBody () {
|
|
484
|
+
const { milo } = this
|
|
485
|
+
|
|
486
|
+
if (currentBuffer.buffer !== milo.memory.buffer) {
|
|
487
|
+
currentBuffer = new FastBuffer(
|
|
488
|
+
milo.memory.buffer,
|
|
489
|
+
currentBufferPtr,
|
|
490
|
+
currentBufferSize
|
|
491
|
+
)
|
|
492
|
+
this.updateBuffers()
|
|
493
|
+
} else if (this.parserEvents.buffer !== milo.memory.buffer) {
|
|
494
|
+
this.updateBuffers()
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
this.directBodyCompletePending = false
|
|
498
|
+
currentBufferRef = EMPTY_BUF
|
|
499
|
+
|
|
500
|
+
milo.complete(this.parser)
|
|
501
|
+
this.drainEvents()
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
setShouldSkipBody (value) {
|
|
505
|
+
if (this.skipBody !== value) {
|
|
506
|
+
this.skipBody = value
|
|
507
|
+
this.milo.setShouldSkipBody(this.parser, value)
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
finish () {
|
|
512
|
+
if (!this.parser) {
|
|
513
|
+
return null
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (this.directBodyRemaining > 0) {
|
|
517
|
+
return new ResponseContentLengthMismatchError()
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (this.parserEvents.buffer !== this.milo.memory.buffer) {
|
|
521
|
+
this.updateBuffers()
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
this.milo.finish(this.parser)
|
|
525
|
+
this.drainEvents()
|
|
526
|
+
|
|
527
|
+
if (!this.errored) {
|
|
528
|
+
return null
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return this.createError(EMPTY_BUF)
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
createError (data) {
|
|
535
|
+
const { contentLength, bytesRead } = this
|
|
536
|
+
|
|
537
|
+
if (contentLength !== -1 && bytesRead !== contentLength) {
|
|
538
|
+
return new ResponseContentLengthMismatchError()
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const errorCode = this.parserFields[this.milo.ParserFields.ERROR_CODE]
|
|
542
|
+
const errorName = this.milo.Errors[errorCode]
|
|
543
|
+
const errorDescription =
|
|
544
|
+
errorName === 'UNEXPECTED_EOF'
|
|
545
|
+
? 'Invalid EOF state'
|
|
546
|
+
: this.milo.getErrorDescription(this.parser)
|
|
547
|
+
const reason =
|
|
548
|
+
errorName === 'UNEXPECTED_EOF'
|
|
549
|
+
? errorDescription
|
|
550
|
+
: errorDescription
|
|
551
|
+
? `[ERROR_${errorName}] ${errorDescription}`
|
|
552
|
+
: `ERROR_${errorName}`
|
|
553
|
+
return new HTTPParserError(
|
|
554
|
+
`Response does not match the HTTP/1.1 protocol (${reason})`,
|
|
555
|
+
errorName,
|
|
556
|
+
data
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
destroy () {
|
|
561
|
+
if (this.parser) {
|
|
562
|
+
this.milo.destroy(this.parser)
|
|
563
|
+
this.parser = null
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
this.timeout && timers.clearTimeout(this.timeout)
|
|
567
|
+
this.timeout = null
|
|
568
|
+
this.timeoutValue = null
|
|
569
|
+
this.timeoutType = null
|
|
570
|
+
this.paused = false
|
|
571
|
+
this.responseStarted = false
|
|
572
|
+
this.pausedByParser = false
|
|
573
|
+
this.pauseStateIsStart = false
|
|
574
|
+
this.connection = ''
|
|
575
|
+
this.skipBody = false
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
pauseParser (stateIsStart = false) {
|
|
579
|
+
this.milo.pause(this.parser)
|
|
580
|
+
this.pausedByParser = true
|
|
581
|
+
this.pauseStateIsStart = stateIsStart
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
drainEvents () {
|
|
585
|
+
const { socket, client, milo } = this
|
|
586
|
+
let cursor = 0
|
|
587
|
+
|
|
588
|
+
const firstEvent = this.parserEvents[0]
|
|
589
|
+
if (
|
|
590
|
+
firstEvent !== milo.EVENT_END &&
|
|
591
|
+
firstEvent !== milo.EVENT_ERROR &&
|
|
592
|
+
!this.responseStarted
|
|
593
|
+
) {
|
|
594
|
+
this.responseStarted = true
|
|
595
|
+
|
|
596
|
+
if (socket.destroyed) {
|
|
597
|
+
return this.fail(this.milo.ERROR_CALLBACK_ERROR, 'Other side closed')
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const request = client[kQueue][client[kRunningIdx]]
|
|
601
|
+
if (!request) {
|
|
602
|
+
return this.fail(this.milo.ERROR_CALLBACK_ERROR, 'Missing request')
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
request.onResponseStarted()
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
for (;;) {
|
|
609
|
+
const event = this.parserEvents[cursor]
|
|
610
|
+
let eventLen = EVENT_RANGE_SIZE
|
|
611
|
+
switch (event) {
|
|
612
|
+
case milo.EVENT_END:
|
|
613
|
+
return
|
|
614
|
+
case milo.EVENT_ERROR:
|
|
615
|
+
this.errored = true
|
|
616
|
+
return
|
|
617
|
+
case milo.EVENT_MESSAGE_COMPLETE: {
|
|
618
|
+
const {
|
|
619
|
+
client,
|
|
620
|
+
socket,
|
|
621
|
+
statusCode,
|
|
622
|
+
upgrade,
|
|
623
|
+
trailers,
|
|
624
|
+
contentLength,
|
|
625
|
+
bytesRead,
|
|
626
|
+
shouldKeepAlive
|
|
627
|
+
} = this
|
|
628
|
+
|
|
629
|
+
this.responseStarted = false
|
|
630
|
+
|
|
631
|
+
if (socket.destroyed && (!statusCode || shouldKeepAlive)) {
|
|
632
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Other side closed')
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (upgrade) {
|
|
636
|
+
this.pauseParser()
|
|
637
|
+
return
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
assert(statusCode >= 100)
|
|
641
|
+
|
|
642
|
+
const request = client[kQueue][client[kRunningIdx]]
|
|
643
|
+
assert(request)
|
|
644
|
+
|
|
645
|
+
this.statusCode = 0
|
|
646
|
+
this.statusText = ''
|
|
647
|
+
this.bytesRead = 0
|
|
648
|
+
this.contentLength = -1
|
|
649
|
+
this.directBodyRemaining = 0
|
|
650
|
+
this.directBodyCompletePending = false
|
|
651
|
+
this.headersSuspended = false
|
|
652
|
+
this.skipBody = false
|
|
653
|
+
this.keepAlive = ''
|
|
654
|
+
this.connection = ''
|
|
655
|
+
this.trailers = []
|
|
656
|
+
this.trailersSize = 0
|
|
657
|
+
|
|
658
|
+
if (statusCode < 200) {
|
|
659
|
+
break
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (
|
|
663
|
+
request.method !== 'HEAD' &&
|
|
664
|
+
contentLength !== -1 &&
|
|
665
|
+
bytesRead !== contentLength
|
|
666
|
+
) {
|
|
667
|
+
util.destroy(socket, new ResponseContentLengthMismatchError())
|
|
668
|
+
this.pauseParser()
|
|
669
|
+
break
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
request.onResponseEnd(trailers)
|
|
673
|
+
|
|
674
|
+
client[kQueue][client[kRunningIdx]++] = null
|
|
675
|
+
|
|
676
|
+
if (socket[kWriting]) {
|
|
677
|
+
assert(client[kRunning] === 0)
|
|
678
|
+
util.destroy(socket, new InformationalError('reset'))
|
|
679
|
+
this.pauseParser(true)
|
|
680
|
+
} else if (!shouldKeepAlive) {
|
|
681
|
+
util.destroy(socket, new InformationalError('reset'))
|
|
682
|
+
this.pauseParser(true)
|
|
683
|
+
} else if (socket[kReset] && client[kRunning] === 0) {
|
|
684
|
+
util.destroy(socket, new InformationalError('reset'))
|
|
685
|
+
this.pauseParser(true)
|
|
686
|
+
} else if (client[kPipelining] == null || client[kPipelining] === 1) {
|
|
687
|
+
setImmediate(client[kResume])
|
|
688
|
+
} else {
|
|
689
|
+
client[kResume]()
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
break
|
|
693
|
+
}
|
|
694
|
+
case milo.EVENT_REASON: {
|
|
695
|
+
const at = this.parserEvents.readUInt32LE(cursor + 1)
|
|
696
|
+
const len = this.parserEvents.readUInt32LE(cursor + 5)
|
|
697
|
+
this.statusText = new FastBuffer(
|
|
698
|
+
currentBufferRef.buffer,
|
|
699
|
+
currentBufferRef.byteOffset + at,
|
|
700
|
+
len
|
|
701
|
+
).toString()
|
|
702
|
+
break
|
|
703
|
+
}
|
|
704
|
+
case milo.EVENT_HEADER_NAME: {
|
|
705
|
+
const at = this.parserEvents.readUInt32LE(cursor + 1)
|
|
706
|
+
const len = this.parserEvents.readUInt32LE(cursor + 5)
|
|
707
|
+
const data =
|
|
708
|
+
len > 0
|
|
709
|
+
? new FastBuffer(
|
|
710
|
+
currentBufferRef.buffer,
|
|
711
|
+
currentBufferRef.byteOffset + at,
|
|
712
|
+
len
|
|
713
|
+
)
|
|
714
|
+
: EMPTY_BUF
|
|
715
|
+
|
|
716
|
+
this.headers.push(data)
|
|
717
|
+
this.headersSize += len
|
|
718
|
+
if (this.headersSize >= this.headersMaxSize) {
|
|
719
|
+
util.destroy(this.socket, new HeadersOverflowError())
|
|
720
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Headers overflow')
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
break
|
|
724
|
+
}
|
|
725
|
+
case milo.EVENT_HEADER_VALUE: {
|
|
726
|
+
const at = this.parserEvents.readUInt32LE(cursor + 1)
|
|
727
|
+
const len = this.parserEvents.readUInt32LE(cursor + 5)
|
|
728
|
+
const data =
|
|
729
|
+
len > 0
|
|
730
|
+
? new FastBuffer(
|
|
731
|
+
currentBufferRef.buffer,
|
|
732
|
+
currentBufferRef.byteOffset + at,
|
|
733
|
+
len
|
|
734
|
+
)
|
|
735
|
+
: EMPTY_BUF
|
|
736
|
+
const key = this.headers[this.headers.length - 1]
|
|
737
|
+
|
|
738
|
+
this.headers.push(data)
|
|
739
|
+
|
|
740
|
+
if (key.length === 10) {
|
|
741
|
+
const headerName = util.bufferToLowerCasedHeaderName(key)
|
|
742
|
+
if (headerName === 'keep-alive') {
|
|
743
|
+
this.keepAlive += (this.keepAlive.length === 0 ? '' : ',') + data.toString()
|
|
744
|
+
} else if (headerName === 'connection') {
|
|
745
|
+
this.connection += (this.connection.length === 0 ? '' : ',') + data.toString()
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
this.headersSize += len
|
|
750
|
+
if (this.headersSize >= this.headersMaxSize) {
|
|
751
|
+
util.destroy(this.socket, new HeadersOverflowError())
|
|
752
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Headers overflow')
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
break
|
|
756
|
+
}
|
|
757
|
+
case milo.EVENT_HEADERS: {
|
|
758
|
+
eventLen = EVENT_HEADERS_SIZE
|
|
759
|
+
|
|
760
|
+
const statusCode = this.parserEvents.readUInt16LE(cursor + 5)
|
|
761
|
+
const shouldKeepAlive = this.parserEvents[cursor + 7] !== 0
|
|
762
|
+
const shouldUpgrade = this.parserEvents[cursor + 8] !== 0
|
|
763
|
+
const hasTrailers = this.parserEvents[cursor + 9] !== 0
|
|
764
|
+
const bodyKind = this.parserEvents[cursor + 10]
|
|
765
|
+
const contentLength =
|
|
766
|
+
this.parserEvents.readUInt32LE(cursor + 11) +
|
|
767
|
+
this.parserEvents.readUInt32LE(cursor + 15) * 0x100000000
|
|
768
|
+
|
|
769
|
+
const { socket, client, headers, statusText } = this
|
|
770
|
+
|
|
771
|
+
if (socket.destroyed) {
|
|
772
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Other side closed')
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const request = client[kQueue][client[kRunningIdx]]
|
|
776
|
+
if (!request) {
|
|
777
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Missing request')
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
assert(!this.upgrade)
|
|
781
|
+
assert(this.statusCode < 200)
|
|
782
|
+
|
|
783
|
+
if (statusCode === 100) {
|
|
784
|
+
util.destroy(
|
|
785
|
+
socket,
|
|
786
|
+
new SocketError('bad response', util.getSocketInfo(socket))
|
|
787
|
+
)
|
|
788
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Bad response')
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
if (shouldUpgrade && !request.upgrade) {
|
|
792
|
+
util.destroy(
|
|
793
|
+
socket,
|
|
794
|
+
new SocketError('bad upgrade', util.getSocketInfo(socket))
|
|
795
|
+
)
|
|
796
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Bad upgrade')
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
assert(this.timeoutType === TIMEOUT_HEADERS)
|
|
800
|
+
|
|
801
|
+
this.statusCode = statusCode
|
|
802
|
+
this.shouldKeepAlive =
|
|
803
|
+
shouldKeepAlive ||
|
|
804
|
+
(request.method === 'HEAD' &&
|
|
805
|
+
!socket[kReset] &&
|
|
806
|
+
/(?:^|,)[\t ]*keep-alive[\t ]*(?:,|$)/i.test(this.connection) &&
|
|
807
|
+
!/(?:^|,)[\t ]*close[\t ]*(?:,|$)/i.test(this.connection))
|
|
808
|
+
this.contentLength =
|
|
809
|
+
bodyKind === BODY_KIND_CONTENT_LENGTH ? contentLength : -1
|
|
810
|
+
|
|
811
|
+
if (this.statusCode >= 200) {
|
|
812
|
+
const bodyTimeout =
|
|
813
|
+
request.bodyTimeout != null
|
|
814
|
+
? request.bodyTimeout
|
|
815
|
+
: client[kBodyTimeout]
|
|
816
|
+
this.setTimeout(bodyTimeout, TIMEOUT_BODY)
|
|
817
|
+
} else if (this.timeout?.refresh) {
|
|
818
|
+
this.timeout.refresh()
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
if (request.method === 'CONNECT') {
|
|
822
|
+
assert(client[kRunning] === 1)
|
|
823
|
+
milo.setIsConnect(this.parser, true)
|
|
824
|
+
this.upgrade = true
|
|
825
|
+
return
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
if (shouldUpgrade) {
|
|
829
|
+
assert(client[kRunning] === 1)
|
|
830
|
+
this.upgrade = true
|
|
831
|
+
this.pauseParser()
|
|
832
|
+
return
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
this.headers = []
|
|
836
|
+
this.headersSize = 0
|
|
837
|
+
|
|
838
|
+
if (this.shouldKeepAlive && client[kPipelining]) {
|
|
839
|
+
const keepAliveTimeout = this.keepAlive
|
|
840
|
+
? util.parseKeepAliveTimeout(this.keepAlive)
|
|
841
|
+
: null
|
|
842
|
+
|
|
843
|
+
if (keepAliveTimeout != null) {
|
|
844
|
+
const timeout = Math.min(
|
|
845
|
+
keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
|
|
846
|
+
client[kKeepAliveMaxTimeout]
|
|
847
|
+
)
|
|
848
|
+
if (timeout <= 0) {
|
|
849
|
+
socket[kReset] = true
|
|
850
|
+
} else {
|
|
851
|
+
client[kKeepAliveTimeoutValue] = timeout
|
|
852
|
+
}
|
|
853
|
+
} else {
|
|
854
|
+
client[kKeepAliveTimeoutValue] = client[kKeepAliveDefaultTimeout]
|
|
855
|
+
}
|
|
856
|
+
} else {
|
|
857
|
+
socket[kReset] = true
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
const pause =
|
|
861
|
+
request.onResponseStart(
|
|
862
|
+
statusCode,
|
|
863
|
+
headers,
|
|
864
|
+
this.resume,
|
|
865
|
+
statusText
|
|
866
|
+
) === false
|
|
867
|
+
|
|
868
|
+
if (request.aborted) {
|
|
869
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Request aborted')
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
if (request.method === 'HEAD' || statusCode < 200) {
|
|
873
|
+
this.setShouldSkipBody(true)
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
this.headersSuspended = true
|
|
877
|
+
if (
|
|
878
|
+
!pause &&
|
|
879
|
+
request.method !== 'HEAD' &&
|
|
880
|
+
statusCode >= 200 &&
|
|
881
|
+
statusCode !== 204 &&
|
|
882
|
+
statusCode !== 205 &&
|
|
883
|
+
statusCode !== 304 &&
|
|
884
|
+
bodyKind === BODY_KIND_CONTENT_LENGTH &&
|
|
885
|
+
contentLength > 0 &&
|
|
886
|
+
!hasTrailers
|
|
887
|
+
) {
|
|
888
|
+
this.directBodyRemaining = contentLength
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
if (socket[kBlocking]) {
|
|
892
|
+
socket[kBlocking] = false
|
|
893
|
+
client[kResume]()
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
if (pause) {
|
|
897
|
+
this.pauseParser()
|
|
898
|
+
this[kPausedByHandler] = true
|
|
899
|
+
} else if (
|
|
900
|
+
request.method === 'HEAD' ||
|
|
901
|
+
statusCode < 200 ||
|
|
902
|
+
statusCode === 204 ||
|
|
903
|
+
statusCode === 205 ||
|
|
904
|
+
statusCode === 304 ||
|
|
905
|
+
(bodyKind === BODY_KIND_CONTENT_LENGTH && contentLength === 0)
|
|
906
|
+
) {
|
|
907
|
+
this.directBodyCompletePending = true
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
break
|
|
911
|
+
}
|
|
912
|
+
case milo.EVENT_DATA: {
|
|
913
|
+
const at = this.parserEvents.readUInt32LE(cursor + 1)
|
|
914
|
+
const len = this.parserEvents.readUInt32LE(cursor + 5)
|
|
915
|
+
const { client, socket, statusCode, maxResponseSize } = this
|
|
916
|
+
|
|
917
|
+
if (socket.destroyed) {
|
|
918
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Other side closed')
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
const request = client[kQueue][client[kRunningIdx]]
|
|
922
|
+
assert(request)
|
|
923
|
+
assert(this.timeoutType === TIMEOUT_BODY)
|
|
924
|
+
|
|
925
|
+
if (this.timeout?.refresh) {
|
|
926
|
+
this.timeout.refresh()
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
assert(statusCode >= 200)
|
|
930
|
+
|
|
931
|
+
if (maxResponseSize > -1 && this.bytesRead + len > maxResponseSize) {
|
|
932
|
+
util.destroy(socket, new ResponseExceededMaxSizeError())
|
|
933
|
+
return this.fail(
|
|
934
|
+
milo.ERROR_CALLBACK_ERROR,
|
|
935
|
+
'Response size exceeded'
|
|
936
|
+
)
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
this.bytesRead += len
|
|
940
|
+
|
|
941
|
+
const buffer = currentBufferRef
|
|
942
|
+
if (
|
|
943
|
+
request.onResponseData(
|
|
944
|
+
new FastBuffer(buffer.buffer, buffer.byteOffset + at, len)
|
|
945
|
+
) === false
|
|
946
|
+
) {
|
|
947
|
+
this.pauseParser()
|
|
948
|
+
this[kPausedByHandler] = true
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
break
|
|
952
|
+
}
|
|
953
|
+
case milo.EVENT_TRAILER_NAME: {
|
|
954
|
+
const at = this.parserEvents.readUInt32LE(cursor + 1)
|
|
955
|
+
const len = this.parserEvents.readUInt32LE(cursor + 5)
|
|
956
|
+
const data =
|
|
957
|
+
len > 0
|
|
958
|
+
? new FastBuffer(
|
|
959
|
+
currentBufferRef.buffer,
|
|
960
|
+
currentBufferRef.byteOffset + at,
|
|
961
|
+
len
|
|
962
|
+
)
|
|
963
|
+
: EMPTY_BUF
|
|
964
|
+
|
|
965
|
+
this.trailers.push(data)
|
|
966
|
+
|
|
967
|
+
this.trailersSize += len
|
|
968
|
+
if (this.trailersSize >= this.headersMaxSize) {
|
|
969
|
+
util.destroy(this.socket, new HeadersOverflowError())
|
|
970
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Headers overflow')
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
break
|
|
974
|
+
}
|
|
975
|
+
case milo.EVENT_TRAILER_VALUE: {
|
|
976
|
+
const at = this.parserEvents.readUInt32LE(cursor + 1)
|
|
977
|
+
const len = this.parserEvents.readUInt32LE(cursor + 5)
|
|
978
|
+
const data =
|
|
979
|
+
len > 0
|
|
980
|
+
? new FastBuffer(
|
|
981
|
+
currentBufferRef.buffer,
|
|
982
|
+
currentBufferRef.byteOffset + at,
|
|
983
|
+
len
|
|
984
|
+
)
|
|
985
|
+
: EMPTY_BUF
|
|
986
|
+
|
|
987
|
+
this.trailers.push(data)
|
|
988
|
+
|
|
989
|
+
this.trailersSize += len
|
|
990
|
+
if (this.trailersSize >= this.headersMaxSize) {
|
|
991
|
+
util.destroy(this.socket, new HeadersOverflowError())
|
|
992
|
+
return this.fail(milo.ERROR_CALLBACK_ERROR, 'Headers overflow')
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
break
|
|
996
|
+
}
|
|
997
|
+
default:
|
|
998
|
+
return
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
cursor += eventLen
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
fail (code, message) {
|
|
1006
|
+
this.milo.fail(this.parser, code, message)
|
|
1007
|
+
this.errored = true
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
onUpgrade (head) {
|
|
1011
|
+
const { upgrade, client, socket, headers, statusCode } = this
|
|
1012
|
+
|
|
1013
|
+
assert(upgrade)
|
|
1014
|
+
assert(client[kSocket] === socket)
|
|
1015
|
+
assert(!socket.destroyed)
|
|
1016
|
+
assert(!this.paused)
|
|
1017
|
+
|
|
1018
|
+
const request = client[kQueue][client[kRunningIdx]]
|
|
1019
|
+
assert(request)
|
|
1020
|
+
assert(request.upgrade || request.method === 'CONNECT')
|
|
1021
|
+
|
|
1022
|
+
this.statusCode = 0
|
|
1023
|
+
this.statusText = ''
|
|
1024
|
+
this.shouldKeepAlive = false
|
|
1025
|
+
this.headers = []
|
|
1026
|
+
this.headersSize = 0
|
|
1027
|
+
|
|
1028
|
+
socket.unshift(head)
|
|
1029
|
+
socket[kParser].destroy()
|
|
1030
|
+
socket[kParser] = null
|
|
1031
|
+
socket[kClient] = null
|
|
1032
|
+
socket[kError] = null
|
|
1033
|
+
|
|
1034
|
+
removeAllListeners(socket)
|
|
1035
|
+
|
|
1036
|
+
client[kSocket] = null
|
|
1037
|
+
client[kHTTPContext] = null
|
|
1038
|
+
client[kQueue][client[kRunningIdx]++] = null
|
|
1039
|
+
client.emit(
|
|
1040
|
+
'disconnect',
|
|
1041
|
+
client[kUrl],
|
|
1042
|
+
[client],
|
|
1043
|
+
new InformationalError('upgrade')
|
|
1044
|
+
)
|
|
1045
|
+
|
|
1046
|
+
try {
|
|
1047
|
+
request.onRequestUpgrade(statusCode, headers, socket)
|
|
1048
|
+
} catch (err) {
|
|
1049
|
+
util.destroy(socket, err)
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
client[kResume]()
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
function setMiloEnabled (value) {
|
|
1057
|
+
miloEnabled = value
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function getMiloEnabled () {
|
|
1061
|
+
return miloEnabled
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
module.exports = { H1Parser, getMiloEnabled, setMiloEnabled }
|