maka-agent 0.2.2-dev.92.20261019 → 0.2.2-dev.97.20261024
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -16,6 +16,7 @@ const { failWebsocketConnection } = require('./connection')
|
|
|
16
16
|
const { WebsocketFrameSend } = require('./frame')
|
|
17
17
|
const { PerMessageDeflate } = require('./permessage-deflate')
|
|
18
18
|
const { MessageSizeExceededError } = require('../../core/errors')
|
|
19
|
+
const { defaultWebSocketMaxFragments, defaultWebSocketMaxPayloadSize } = require('../../core/constants')
|
|
19
20
|
|
|
20
21
|
// This code was influenced by ws released under the MIT license.
|
|
21
22
|
// Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
|
@@ -48,18 +49,25 @@ class ByteParser extends Writable {
|
|
|
48
49
|
/**
|
|
49
50
|
* @param {import('./websocket').Handler} handler
|
|
50
51
|
* @param {Map<string, string>|null} extensions
|
|
51
|
-
* @param {{ maxPayloadSize?: number }} [options]
|
|
52
|
+
* @param {{ maxFragments?: number, maxPayloadSize?: number }} [options]
|
|
53
|
+
* A missing value uses the default limit; `0` disables the limit.
|
|
52
54
|
*/
|
|
53
55
|
constructor (handler, extensions, options = {}) {
|
|
54
56
|
super()
|
|
55
57
|
|
|
56
58
|
this.#handler = handler
|
|
57
59
|
this.#extensions = extensions == null ? new Map() : extensions
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
// Options come from the dispatcher's `webSocketOptions`, which only
|
|
61
|
+
// DispatcherBase provides. Fall back to the defaults rather than to no
|
|
62
|
+
// limit, so RetryAgent, MockAgent or a custom dispatcher can't turn off
|
|
63
|
+
// the payload and decompression limits by accident.
|
|
64
|
+
this.#maxFragments = options.maxFragments ?? defaultWebSocketMaxFragments
|
|
65
|
+
this.#maxPayloadSize = options.maxPayloadSize ?? defaultWebSocketMaxPayloadSize
|
|
60
66
|
|
|
61
67
|
if (this.#extensions.has('permessage-deflate')) {
|
|
62
|
-
this.#extensions.set('permessage-deflate', new PerMessageDeflate(extensions,
|
|
68
|
+
this.#extensions.set('permessage-deflate', new PerMessageDeflate(extensions, {
|
|
69
|
+
maxPayloadSize: this.#maxPayloadSize
|
|
70
|
+
}))
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
|
|
@@ -244,6 +252,19 @@ class ByteParser extends Writable {
|
|
|
244
252
|
if (isControlFrame(this.#info.opcode)) {
|
|
245
253
|
this.#loop = this.parseControlFrame(body)
|
|
246
254
|
this.#state = parserStates.INFO
|
|
255
|
+
|
|
256
|
+
// If the automatic PONG/CLOSE reply filled the socket's write buffer,
|
|
257
|
+
// stop parsing and resume on drain so a PING flood cannot grow the
|
|
258
|
+
// outbound queue without bound.
|
|
259
|
+
if (this.#loop && this.#handler.socket.writableNeedDrain) {
|
|
260
|
+
this.#loop = false
|
|
261
|
+
this.#handler.socket.once('drain', () => {
|
|
262
|
+
if (this.destroyed) return
|
|
263
|
+
this.#loop = true
|
|
264
|
+
this.run(callback)
|
|
265
|
+
})
|
|
266
|
+
return
|
|
267
|
+
}
|
|
247
268
|
} else {
|
|
248
269
|
if (!this.#info.compressed) {
|
|
249
270
|
if (!this.writeFragments(body)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "undici",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.12.3",
|
|
4
4
|
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
|
5
5
|
"homepage": "https://undici.nodejs.org",
|
|
6
6
|
"bugs": {
|
|
@@ -63,13 +63,15 @@
|
|
|
63
63
|
"types": "index.d.ts",
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build:node": "esbuild index-fetch.js --bundle --platform=node --outfile=undici-fetch.js --define:esbuildDetection=1 --keep-names && node scripts/strip-comments.js",
|
|
66
|
-
"build:
|
|
66
|
+
"build:milo": "node build/milo.js",
|
|
67
|
+
"build:llhttp": "node build/llhttp.js --docker",
|
|
68
|
+
"build:wasm": "node build/llhttp.js --docker",
|
|
67
69
|
"generate-pem": "node scripts/generate-pem.js",
|
|
68
70
|
"lint": "eslint --cache",
|
|
69
71
|
"lint:fix": "eslint --fix --cache",
|
|
70
72
|
"test": "npm run test:javascript && cross-env NODE_V8_COVERAGE= npm run test:typescript",
|
|
71
73
|
"test:javascript": "npm run test:javascript:no-jest && npm run test:jest",
|
|
72
|
-
"test:javascript:no-jest": "npm run generate-pem && npm run test:unit && npm run test:fetch && npm run test:node-fetch && npm run test:infra && npm run test:cache && npm run test:cache-interceptor && npm run test:interceptors && npm run test:cookies && npm run test:eventsource && npm run test:subresource-integrity && npm run test:
|
|
74
|
+
"test:javascript:no-jest": "npm run generate-pem && npm run test:unit && npm run test:fetch && npm run test:node-fetch && npm run test:infra && npm run test:cache && npm run test:cache-interceptor && npm run test:interceptors && npm run test:cookies && npm run test:eventsource && npm run test:subresource-integrity && npm run test:websocket && npm run test:node-test && npm run test:cache-tests",
|
|
73
75
|
"test:javascript:without-intl": "npm run test:javascript:no-jest",
|
|
74
76
|
"test:busboy": "borp --timeout 180000 -p \"test/busboy/*.js\"",
|
|
75
77
|
"test:cache": "borp --timeout 180000 -p \"test/cache/*.js\"",
|
|
@@ -97,7 +99,7 @@
|
|
|
97
99
|
"test:websocket:autobahn": "node test/autobahn/client.js",
|
|
98
100
|
"test:websocket:autobahn:report": "node test/autobahn/report.js",
|
|
99
101
|
"test:wpt:setup": "node test/web-platform-tests/wpt-runner.mjs setup",
|
|
100
|
-
"test:wpt": "npm run test:wpt:setup && node test/web-platform-tests/wpt-runner.mjs run /fetch /mimesniff /xhr /websockets /eventsource",
|
|
102
|
+
"test:wpt": "npm run test:wpt:setup && node test/web-platform-tests/wpt-runner.mjs run /fetch /mimesniff /xhr /websockets /eventsource /service-workers",
|
|
101
103
|
"test:cache-tests": "node test/cache-interceptor/cache-tests.mjs --ci",
|
|
102
104
|
"coverage": "npm run coverage:clean && cross-env NODE_V8_COVERAGE=./coverage/tmp npm run test:javascript && npm run coverage:report",
|
|
103
105
|
"coverage:ci": "npm run coverage:clean && cross-env NODE_V8_COVERAGE=./coverage/tmp npm run test:javascript && npm run coverage:report:ci",
|
|
@@ -109,7 +111,7 @@
|
|
|
109
111
|
"prepare": "husky && node ./scripts/platform-shell.js"
|
|
110
112
|
},
|
|
111
113
|
"devDependencies": {
|
|
112
|
-
"@fastify/busboy": "3.2.
|
|
114
|
+
"@fastify/busboy": "3.2.3",
|
|
113
115
|
"@matteo.collina/tspl": "^0.2.0",
|
|
114
116
|
"@metcoder95/https-pem": "^1.0.0",
|
|
115
117
|
"@sinonjs/fake-timers": "^12.0.0",
|
|
@@ -120,12 +122,12 @@
|
|
|
120
122
|
"cross-env": "^10.0.0",
|
|
121
123
|
"dns-packet": "^5.4.0",
|
|
122
124
|
"esbuild": "^0.28.0",
|
|
123
|
-
"eslint": "^
|
|
125
|
+
"eslint": "^10.12.0",
|
|
124
126
|
"fast-check": "^4.1.1",
|
|
125
127
|
"husky": "^9.0.7",
|
|
126
128
|
"jest": "^30.0.5",
|
|
127
129
|
"jsondiffpatch": "^0.7.3",
|
|
128
|
-
"neostandard": "^0.
|
|
130
|
+
"neostandard": "^0.14.0",
|
|
129
131
|
"node-forge": "^1.3.1",
|
|
130
132
|
"proxy": "^4.0.0",
|
|
131
133
|
"tsd": "^0.33.0",
|
|
@@ -884,10 +884,10 @@ export class AiSdkCompaction {
|
|
|
884
884
|
/**
|
|
885
885
|
* Reactive overflow recovery (issue #882 PR 2): the second line of defense.
|
|
886
886
|
* When a provider rejects a request with a context-length error, fold the
|
|
887
|
-
* durable turn ledger and resend
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
887
|
+
* durable turn ledger and resend. Each step may omit historical images once,
|
|
888
|
+
* then fold once; a rejection after the fold is terminal. A step the
|
|
889
|
+
* provider has since accepted earns a fresh recovery sequence. Returns the
|
|
890
|
+
* compacted messages to resend,
|
|
891
891
|
* or undefined when recovery is impossible or already spent, in which case
|
|
892
892
|
* the caller surfaces the real provider error rather than a fabricated
|
|
893
893
|
* success or a locally synthesized verdict (the provider — not the runtime —
|
|
@@ -897,12 +897,14 @@ export class AiSdkCompaction {
|
|
|
897
897
|
*/
|
|
898
898
|
async recoverFromOverflowError(input) {
|
|
899
899
|
const state = input.midTurnState;
|
|
900
|
-
if (!state || state.stepShaping.has('fold')
|
|
900
|
+
if (!state || state.stepShaping.has('fold')) {
|
|
901
901
|
return undefined;
|
|
902
902
|
}
|
|
903
903
|
const eligibleImages = collectHistoricalImageToolResults(state.priorContentEvents);
|
|
904
|
-
const imageOmission =
|
|
905
|
-
|
|
904
|
+
const imageOmission = state.stepShaping.has('omit_images')
|
|
905
|
+
? undefined
|
|
906
|
+
: omitHistoricalImageToolResults(input.currentMessages, eligibleImages);
|
|
907
|
+
if (imageOmission && imageOmission.omittedParts > 0) {
|
|
906
908
|
state.stepShaping.add('omit_images');
|
|
907
909
|
for (const toolCallId of imageOmission.omittedToolCallIds) {
|
|
908
910
|
const image = eligibleImages.get(toolCallId);
|
|
@@ -912,6 +914,15 @@ export class AiSdkCompaction {
|
|
|
912
914
|
if (image)
|
|
913
915
|
state.omittedImageToolResults.set(toolCallId, image);
|
|
914
916
|
}
|
|
917
|
+
input.onDiagnosticPatch(compactionDecisionDiagnosticPatch({
|
|
918
|
+
stage: 'activeStep',
|
|
919
|
+
sourceKind: 'providerMessages',
|
|
920
|
+
decision: 'replaced',
|
|
921
|
+
phase: state.compactionPhase(input.stepNumber),
|
|
922
|
+
boundaryKind: 'imageOmission',
|
|
923
|
+
coverage: { toolCallIds: [...imageOmission.omittedToolCallIds] },
|
|
924
|
+
reason: 'overflow',
|
|
925
|
+
}));
|
|
915
926
|
state.baselineTokens = undefined;
|
|
916
927
|
return { messages: imageOmission.messages };
|
|
917
928
|
}
|
|
@@ -962,7 +973,9 @@ export class AiSdkCompaction {
|
|
|
962
973
|
// The fold replaced the request; the baseline described the rejected one.
|
|
963
974
|
state.stepShaping.add('fold');
|
|
964
975
|
state.baselineTokens = undefined;
|
|
965
|
-
return {
|
|
976
|
+
return {
|
|
977
|
+
messages: projectHistoricalImageOmissions(outcome.replacementMessages, state.omittedImageToolResults) ?? outcome.replacementMessages,
|
|
978
|
+
};
|
|
966
979
|
}
|
|
967
980
|
}
|
|
968
981
|
function projectHistoricalImageOmissions(messages, omittedImageToolResults) {
|
|
@@ -1048,7 +1061,7 @@ export class MidTurnCapacityCompactState {
|
|
|
1048
1061
|
/**
|
|
1049
1062
|
* What has reshaped the request since the last one a provider accepted. The
|
|
1050
1063
|
* turn clears it at that acceptance; overflow recovery reads it so a request
|
|
1051
|
-
*
|
|
1064
|
+
* is folded at most once, after an optional image omission.
|
|
1052
1065
|
*/
|
|
1053
1066
|
stepShaping = new Set();
|
|
1054
1067
|
/**
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
import { MAX_PROVIDER_IMAGE_REQUEST_BYTES, PROVIDER_IMAGE_BUDGET_EXCEEDED_MESSAGE, } from '@maka/core/attachments';
|
|
20
20
|
import { applyPatchReplayFactText, normalizeApplyPatchReplayInput, } from './apply-patch-profile.js';
|
|
21
21
|
import { durableProjectionToToolResultOutput } from './durable-tool-result-projection.js';
|
|
22
|
+
import { runtimeContextMessage } from './runtime-context.js';
|
|
22
23
|
import { historyCompactCheckpointToModelMessage, isProviderHistoryCompactCheckpoint, } from './history-compact-checkpoint.js';
|
|
23
|
-
import { admitProviderReasoningReplayItems, buildRuntimeEventReplayTimeline, formatTextWithInlineRefs, steeringProviderOptions, } from './model-history.js';
|
|
24
|
+
import { admitProviderReasoningReplayItems, buildRuntimeEventReplayTimeline, formatTextWithInlineRefs, steeringProviderOptions, runtimeContextProviderOptions, } from './model-history.js';
|
|
24
25
|
import { openAiChatReasoningFieldFromProviderOptions } from './openai-chat-reasoning-transport.js';
|
|
25
26
|
import { decodePlaintextResponsesReasoningState, replayPlaintextResponsesProviderOptions, } from './responses-reasoning-state.js';
|
|
26
27
|
import { toolResultOutput } from './tool-result-output.js';
|
|
@@ -464,6 +465,11 @@ export class AiSdkMessageProjection {
|
|
|
464
465
|
messages.push(message);
|
|
465
466
|
this.memoryReplayMessageEvents.set(message, [...new Set(eventIds)]);
|
|
466
467
|
}
|
|
468
|
+
materializeRuntimeContext(context, eventId) {
|
|
469
|
+
const message = runtimeContextMessage(context);
|
|
470
|
+
this.memoryReplayMessageEvents.set(message, [eventId]);
|
|
471
|
+
return message;
|
|
472
|
+
}
|
|
467
473
|
memoryEventMessagePositions(messages) {
|
|
468
474
|
const positions = {};
|
|
469
475
|
for (const [position, message] of messages.entries()) {
|
|
@@ -492,6 +498,9 @@ export class AiSdkMessageProjection {
|
|
|
492
498
|
return {
|
|
493
499
|
role: 'user',
|
|
494
500
|
content,
|
|
501
|
+
...(item.runtimeContextName !== undefined
|
|
502
|
+
? { providerOptions: runtimeContextProviderOptions(item.runtimeContextName) }
|
|
503
|
+
: {}),
|
|
495
504
|
};
|
|
496
505
|
}
|
|
497
506
|
return {
|
|
@@ -45,6 +45,7 @@ import { portableApplyPatchTool } from './apply-patch-profile.js';
|
|
|
45
45
|
import { RunTrace } from './run-trace.js';
|
|
46
46
|
import { REQUEST_SANDBOX_BOUNDARY_TOOL_NAME, SANDBOX_BOUNDARY_DENIED_FOR_TURN, SANDBOX_BOUNDARY_FINALIZATION_PROMPT, requiredSandboxBoundaryToolNames, } from './sandbox-boundary-tool.js';
|
|
47
47
|
import { buildRuntimeEventModelReplayPlan, appendPriorUnknownToolResponses, buildSteeringEnvelope, collectToolActivityTurnIds, compatibleProviderReasoningReplayEventIds, formatTextWithInlineRefs, inspectPriorUnknownToolOutcomes, steeringMessagesMissingFromBase, steeringModelMessage, } from './model-history.js';
|
|
48
|
+
import { changedRuntimeContexts } from './runtime-context.js';
|
|
48
49
|
import { toolSchemaCharsForDiagnostics, requestCompositionToolSchemas, stableHash, toolCatalogHash, } from './request-shape.js';
|
|
49
50
|
import { toolAvailabilityHash } from './tool-availability.js';
|
|
50
51
|
import { hasFinalizedReasoning } from './ai-sdk-message-projection.js';
|
|
@@ -389,8 +390,8 @@ export class AiSdkTurn {
|
|
|
389
390
|
abortController = new AbortController();
|
|
390
391
|
activeTools;
|
|
391
392
|
aborted = false;
|
|
392
|
-
|
|
393
|
-
|
|
393
|
+
stopRequested = false;
|
|
394
|
+
turnYield;
|
|
394
395
|
handoffPaused = false;
|
|
395
396
|
watchdog = null;
|
|
396
397
|
runTrace = null;
|
|
@@ -430,8 +431,8 @@ export class AiSdkTurn {
|
|
|
430
431
|
await this.toolRuntime.endTurn(this.aborted ? 'aborted' : 'completed');
|
|
431
432
|
}
|
|
432
433
|
requestStop(reason, mode) {
|
|
434
|
+
this.stopRequested = true;
|
|
433
435
|
if (mode === 'after_step') {
|
|
434
|
-
this.loopStopRequested = true;
|
|
435
436
|
this.runTrace?.abortRequested(reason);
|
|
436
437
|
return;
|
|
437
438
|
}
|
|
@@ -439,6 +440,9 @@ export class AiSdkTurn {
|
|
|
439
440
|
this.abortController.abort();
|
|
440
441
|
this.runTrace?.abortRequested(reason);
|
|
441
442
|
}
|
|
443
|
+
get loopStopReason() {
|
|
444
|
+
return this.stopRequested ? 'user_stop' : this.turnYield;
|
|
445
|
+
}
|
|
442
446
|
async endAbortedTools() {
|
|
443
447
|
await this.toolRuntime.endTurn('aborted');
|
|
444
448
|
}
|
|
@@ -1092,6 +1096,24 @@ export class AiSdkTurn {
|
|
|
1092
1096
|
? currentTurnMessages
|
|
1093
1097
|
: [...priorReplay.messages, ...currentTurnMessages];
|
|
1094
1098
|
};
|
|
1099
|
+
const appendRuntimeContexts = async (history, contexts) => {
|
|
1100
|
+
const additions = changedRuntimeContexts(contexts, history).map((context) => ({
|
|
1101
|
+
context,
|
|
1102
|
+
id: this.deps.newId(),
|
|
1103
|
+
}));
|
|
1104
|
+
for (const { context, id } of additions) {
|
|
1105
|
+
queue.push({ type: 'runtime_context', id, turnId, ts: this.deps.now(), ...context });
|
|
1106
|
+
}
|
|
1107
|
+
if (additions.length === 0)
|
|
1108
|
+
return history;
|
|
1109
|
+
// Persist before dispatch; retries reuse the same snapshot. Context
|
|
1110
|
+
// removed by compaction is refreshed after that fold, not lost in it.
|
|
1111
|
+
await queue.waitUntilConsumedThroughCurrent();
|
|
1112
|
+
return [
|
|
1113
|
+
...history,
|
|
1114
|
+
...additions.map(({ context, id }) => this.deps.messageProjection.materializeRuntimeContext(context, id)),
|
|
1115
|
+
];
|
|
1116
|
+
};
|
|
1095
1117
|
// Tool Availability describes the provider-visible (active) subset. A
|
|
1096
1118
|
// group loaded this turn expands that subset on later requests, so the
|
|
1097
1119
|
// terminal trace is refined against the final active set below.
|
|
@@ -1126,7 +1148,7 @@ export class AiSdkTurn {
|
|
|
1126
1148
|
let finishFeedback;
|
|
1127
1149
|
let result;
|
|
1128
1150
|
let providerOutcome;
|
|
1129
|
-
let
|
|
1151
|
+
let terminalStopReason;
|
|
1130
1152
|
let terminalProviderError;
|
|
1131
1153
|
agentLoop: for (;;) {
|
|
1132
1154
|
({ plan, providerTools, modelTools, nestedTools } = snapshotStepTools());
|
|
@@ -1188,7 +1210,6 @@ export class AiSdkTurn {
|
|
|
1188
1210
|
activeTools,
|
|
1189
1211
|
};
|
|
1190
1212
|
};
|
|
1191
|
-
const dynamicContextMessages = (resolvedSystemPrompt.contexts ?? []).map(({ text }) => ({ role: 'user', content: text }));
|
|
1192
1213
|
const shaped = requestProjection
|
|
1193
1214
|
? await requestProjection({
|
|
1194
1215
|
completedSteps: completedProviderSteps,
|
|
@@ -1220,9 +1241,10 @@ export class AiSdkTurn {
|
|
|
1220
1241
|
})
|
|
1221
1242
|
: undefined;
|
|
1222
1243
|
providerRequestTracker?.setStep(runtimeSteps, requestCompositionId);
|
|
1223
|
-
let attemptMessages = projectedMessages;
|
|
1244
|
+
let attemptMessages = await appendRuntimeContexts(projectedMessages, resolvedSystemPrompt.contexts ?? []);
|
|
1224
1245
|
let overflowRecoveryMaxOutputTokens;
|
|
1225
1246
|
let providerAttempt = 0;
|
|
1247
|
+
let pendingRetryReason;
|
|
1226
1248
|
const returnedToolCalls = [];
|
|
1227
1249
|
const providerToolInputs = new Map();
|
|
1228
1250
|
let providerStepUsage;
|
|
@@ -1243,8 +1265,7 @@ export class AiSdkTurn {
|
|
|
1243
1265
|
let attemptSawReplayBarrier = false;
|
|
1244
1266
|
const attemptHasNoObservableOutput = () => !attemptSawVisibleContent && !attemptSawToolActivity && !attemptSawReplayBarrier;
|
|
1245
1267
|
const attemptCanReplay = () => !attemptSawToolActivity && !attemptSawReplayBarrier;
|
|
1246
|
-
|
|
1247
|
-
const dispatchMessages = [...attemptMessages, ...dynamicContextMessages];
|
|
1268
|
+
const dispatchMessages = attemptMessages;
|
|
1248
1269
|
this.memorySourceMessages = dispatchMessages;
|
|
1249
1270
|
this.memorySourceEventMessagePositions =
|
|
1250
1271
|
this.deps.messageProjection.memoryEventMessagePositions(dispatchMessages);
|
|
@@ -1267,6 +1288,24 @@ export class AiSdkTurn {
|
|
|
1267
1288
|
// rebuilt in place by overflow recovery, and the boundary it folded
|
|
1268
1289
|
// under must travel with that rebuild, not with the step.
|
|
1269
1290
|
const historyCompactBoundary = requestHistoryCompactBoundary();
|
|
1291
|
+
// Stop can arrive during handoff, retry backoff, or overflow recovery.
|
|
1292
|
+
if (this.loopStopReason) {
|
|
1293
|
+
terminalStopReason = this.loopStopReason;
|
|
1294
|
+
break agentLoop;
|
|
1295
|
+
}
|
|
1296
|
+
if (pendingRetryReason) {
|
|
1297
|
+
queue.push({
|
|
1298
|
+
type: 'provider_retry',
|
|
1299
|
+
id: this.deps.newId(),
|
|
1300
|
+
turnId,
|
|
1301
|
+
ts: this.deps.now(),
|
|
1302
|
+
phase: 'started',
|
|
1303
|
+
attempt: providerAttempt,
|
|
1304
|
+
maxAttempts: MAX_PROVIDER_ATTEMPTS_PER_STEP,
|
|
1305
|
+
reason: pendingRetryReason,
|
|
1306
|
+
});
|
|
1307
|
+
pendingRetryReason = undefined;
|
|
1308
|
+
}
|
|
1270
1309
|
result = await this.deps.modelAdapter.startStream({
|
|
1271
1310
|
model,
|
|
1272
1311
|
messages: dispatchMessages,
|
|
@@ -1596,7 +1635,7 @@ export class AiSdkTurn {
|
|
|
1596
1635
|
!attemptSawToolInput &&
|
|
1597
1636
|
returnedToolCalls.length === 0))
|
|
1598
1637
|
sawUnusableStepUsage = true;
|
|
1599
|
-
if (this.
|
|
1638
|
+
if (this.loopStopReason) {
|
|
1600
1639
|
terminalProviderError = failure;
|
|
1601
1640
|
terminalProviderErrorReason =
|
|
1602
1641
|
lastCompletedStepHadToolResult && failure.kind === 'timeout'
|
|
@@ -1633,7 +1672,7 @@ export class AiSdkTurn {
|
|
|
1633
1672
|
})
|
|
1634
1673
|
: undefined;
|
|
1635
1674
|
if (recovered) {
|
|
1636
|
-
attemptMessages = recovered.messages;
|
|
1675
|
+
attemptMessages = await appendRuntimeContexts(recovered.messages, resolvedSystemPrompt.contexts ?? []);
|
|
1637
1676
|
overflowRecoveryMaxOutputTokens = Math.min(this.deps.modelAdapter.maxOutputTokens() ?? CONTEXT_RECOVERY_MAX_OUTPUT_TOKENS, CONTEXT_RECOVERY_MAX_OUTPUT_TOKENS);
|
|
1638
1677
|
continue;
|
|
1639
1678
|
}
|
|
@@ -1716,16 +1755,7 @@ export class AiSdkTurn {
|
|
|
1716
1755
|
reason,
|
|
1717
1756
|
});
|
|
1718
1757
|
await this.deps.providerRetrySleep(delayMs, turnAbortController.signal);
|
|
1719
|
-
|
|
1720
|
-
type: 'provider_retry',
|
|
1721
|
-
id: this.deps.newId(),
|
|
1722
|
-
turnId,
|
|
1723
|
-
ts: this.deps.now(),
|
|
1724
|
-
phase: 'started',
|
|
1725
|
-
attempt: nextAttempt,
|
|
1726
|
-
maxAttempts,
|
|
1727
|
-
reason,
|
|
1728
|
-
});
|
|
1758
|
+
pendingRetryReason = reason;
|
|
1729
1759
|
continue;
|
|
1730
1760
|
}
|
|
1731
1761
|
// Unrecoverable (not context-length, this step's attempt spent,
|
|
@@ -1752,7 +1782,7 @@ export class AiSdkTurn {
|
|
|
1752
1782
|
const providerStepId = currentStepMessageId;
|
|
1753
1783
|
if (providerOutcome.kind !== 'completed')
|
|
1754
1784
|
throw providerOutcome.failure;
|
|
1755
|
-
finishReason = providerOutcome.finishReason;
|
|
1785
|
+
const finishReason = providerOutcome.finishReason;
|
|
1756
1786
|
await queue.waitUntilConsumedThroughCurrent();
|
|
1757
1787
|
let toolRequestedFinish = false;
|
|
1758
1788
|
if (returnedToolCalls.length > 0) {
|
|
@@ -1843,8 +1873,7 @@ export class AiSdkTurn {
|
|
|
1843
1873
|
if (returnedToolCalls.length === 1 &&
|
|
1844
1874
|
!settlement.providerError &&
|
|
1845
1875
|
isEventWaitYieldReceipt(settlement.result)) {
|
|
1846
|
-
this.
|
|
1847
|
-
this.loopStopRequested = true;
|
|
1876
|
+
this.turnYield = 'event_wait';
|
|
1848
1877
|
}
|
|
1849
1878
|
if (isPlanToolResult(settlement.result)) {
|
|
1850
1879
|
this.handlePlanToolResult(settlement.result, queue);
|
|
@@ -1859,9 +1888,7 @@ export class AiSdkTurn {
|
|
|
1859
1888
|
// an entire completed batch across the next provider request.
|
|
1860
1889
|
settlementOutcomes.length = 0;
|
|
1861
1890
|
await queue.waitUntilConsumedThroughCurrent();
|
|
1862
|
-
const continuationWillRun = (maxSteps === undefined || runtimeSteps < maxSteps) &&
|
|
1863
|
-
!this.loopStopRequested &&
|
|
1864
|
-
!this.aborted;
|
|
1891
|
+
const continuationWillRun = (maxSteps === undefined || runtimeSteps < maxSteps) && !this.loopStopReason;
|
|
1865
1892
|
if (continuationWillRun && providerOutcome.continuation === 'pending') {
|
|
1866
1893
|
const persistedProjection = await loadDurableTurnProjection();
|
|
1867
1894
|
const responseMessages = persistedOpenAiResponsesStepMessages(attemptMessages, persistedProjection, returnedToolCalls.map((toolCall) => toolCall.toolCallId));
|
|
@@ -1878,119 +1905,72 @@ export class AiSdkTurn {
|
|
|
1878
1905
|
...(providerStepUsage ? { usage: providerStepUsage } : {}),
|
|
1879
1906
|
});
|
|
1880
1907
|
lastCompletedStepHadToolResult = returnedToolCalls.length > 0;
|
|
1881
|
-
// Finish only after the tool result is durably consumed. The Host can
|
|
1882
|
-
// veto completion (for example, new Inbox input raced with Sleep).
|
|
1883
|
-
if (toolRequestedFinish && !this.aborted && !this.loopStopRequested) {
|
|
1884
|
-
const decision = await this.deps.backend.beforeTurnFinish?.({
|
|
1885
|
-
sessionId: this.deps.backend.sessionId,
|
|
1886
|
-
turnId,
|
|
1887
|
-
signal: turnAbortController.signal,
|
|
1888
|
-
});
|
|
1889
|
-
if (!decision || decision.allow) {
|
|
1890
|
-
finishReason = 'stop';
|
|
1891
|
-
this.deps.modelAdapter.clearContinuation(this.turnId);
|
|
1892
|
-
break agentLoop;
|
|
1893
|
-
}
|
|
1894
|
-
finishFeedback = decision.feedback;
|
|
1895
|
-
}
|
|
1896
1908
|
const stepLimitReached = maxSteps !== undefined && runtimeSteps >= maxSteps;
|
|
1897
1909
|
if (sandboxBoundaryFinalizationStep ||
|
|
1898
1910
|
(stepLimitReached &&
|
|
1899
1911
|
(toolRuntime.shouldFinalizeSandboxBoundary() ||
|
|
1900
1912
|
toolRuntime.hasSandboxBoundaryDenial()))) {
|
|
1901
|
-
this.
|
|
1902
|
-
this.loopStopRequested = true;
|
|
1903
|
-
}
|
|
1904
|
-
const mayTakeAnotherStep = !stepLimitReached && !this.loopStopRequested && !this.aborted;
|
|
1905
|
-
if (returnedToolCalls.length > 0 && mayTakeAnotherStep) {
|
|
1906
|
-
if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
|
|
1907
|
-
this.handoffPaused = true;
|
|
1908
|
-
break agentLoop;
|
|
1909
|
-
}
|
|
1910
|
-
if (this.aborted || this.loopStopRequested)
|
|
1911
|
-
break agentLoop;
|
|
1912
|
-
currentStepMessageId = this.deps.newId();
|
|
1913
|
-
continue agentLoop;
|
|
1913
|
+
this.turnYield = 'permission_handoff';
|
|
1914
1914
|
}
|
|
1915
|
+
let finishCandidateReason = returnedToolCalls.length > 0 && !toolRequestedFinish
|
|
1916
|
+
? undefined
|
|
1917
|
+
: toolRequestedFinish
|
|
1918
|
+
? 'end_turn'
|
|
1919
|
+
: this.deps.modelAdapter.mapFinishReason(finishReason);
|
|
1915
1920
|
// Enforce Host prerequisites locally: some providers reject required
|
|
1916
1921
|
// tool_choice in thinking mode. Never silently complete without the
|
|
1917
1922
|
// receipt; replay the draft and per-step reminder for bounded repair.
|
|
1918
1923
|
if (returnedToolCalls.length === 0 &&
|
|
1919
1924
|
resolvedSystemPrompt.requireToolCall &&
|
|
1920
|
-
!this.
|
|
1921
|
-
|
|
1922
|
-
if (!mayTakeAnotherStep ||
|
|
1925
|
+
!this.loopStopReason) {
|
|
1926
|
+
if (stepLimitReached ||
|
|
1923
1927
|
!this.deps.backend.loadTurnRuntimeEvents ||
|
|
1924
1928
|
++missingPrerequisiteAttempts > 2) {
|
|
1925
1929
|
throw new Error('Required turn prerequisite was not recorded; cannot complete this response.');
|
|
1926
1930
|
}
|
|
1927
|
-
|
|
1928
|
-
if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
|
|
1929
|
-
this.handoffPaused = true;
|
|
1930
|
-
break agentLoop;
|
|
1931
|
-
}
|
|
1932
|
-
if (this.aborted || this.loopStopRequested)
|
|
1933
|
-
break agentLoop;
|
|
1934
|
-
currentStepMessageId = this.deps.newId();
|
|
1935
|
-
continue agentLoop;
|
|
1931
|
+
finishCandidateReason = undefined;
|
|
1936
1932
|
}
|
|
1937
|
-
//
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
// rather than throwing — the turn still completes and the Host folds
|
|
1944
|
-
// the message into the next Turn, which is today's behaviour.
|
|
1945
|
-
if (mayTakeAnotherStep && this.deps.backend.loadTurnRuntimeEvents) {
|
|
1946
|
-
// Last chance for a steer that landed after this turn's final
|
|
1947
|
-
// tool-call boundary — including the only boundary a tool-free
|
|
1948
|
-
// turn has, which precedes the model's first token. Without it the
|
|
1949
|
-
// message is never pulled at all, and whether Steer works would
|
|
1950
|
-
// depend on the model happening to call a tool afterwards (#3529).
|
|
1951
|
-
// A step-limited turn deliberately skips this: its budget is spent,
|
|
1952
|
-
// and the Host folds the message into the next Turn instead.
|
|
1933
|
+
// The Host carries steering left unconsumed here into the next Turn.
|
|
1934
|
+
if (finishCandidateReason !== undefined &&
|
|
1935
|
+
!toolRequestedFinish &&
|
|
1936
|
+
!stepLimitReached &&
|
|
1937
|
+
!this.loopStopReason &&
|
|
1938
|
+
this.deps.backend.loadTurnRuntimeEvents) {
|
|
1953
1939
|
const injectedBefore = this.injectedSteeringMessages.length;
|
|
1954
1940
|
await this.drainSteeringInto(input, queue);
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
// `mayTakeAnotherStep` is stale by now. Stop wins — the message is
|
|
1958
|
-
// already durable, so the Host folds it into the next Turn.
|
|
1959
|
-
if (this.injectedSteeringMessages.length > injectedBefore &&
|
|
1960
|
-
!this.loopStopRequested &&
|
|
1961
|
-
!this.aborted) {
|
|
1962
|
-
await queue.waitUntilConsumedThroughCurrent();
|
|
1963
|
-
if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
|
|
1964
|
-
this.handoffPaused = true;
|
|
1965
|
-
break agentLoop;
|
|
1966
|
-
}
|
|
1967
|
-
if (this.aborted || this.loopStopRequested)
|
|
1968
|
-
break agentLoop;
|
|
1969
|
-
currentStepMessageId = this.deps.newId();
|
|
1970
|
-
continue agentLoop;
|
|
1971
|
-
}
|
|
1941
|
+
if (this.injectedSteeringMessages.length > injectedBefore)
|
|
1942
|
+
finishCandidateReason = undefined;
|
|
1972
1943
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
this.deps.backend.beforeTurnFinish
|
|
1976
|
-
this.deps.backend.loadTurnRuntimeEvents &&
|
|
1977
|
-
this.deps.modelAdapter.mapFinishReason(finishReason) === 'end_turn') {
|
|
1978
|
-
const decision = await this.deps.backend.beforeTurnFinish({
|
|
1944
|
+
// Finishing needs Host approval even when no continuation is possible.
|
|
1945
|
+
if (finishCandidateReason === 'end_turn' && !this.loopStopReason) {
|
|
1946
|
+
const finishDecision = await this.deps.backend.beforeTurnFinish?.({
|
|
1979
1947
|
sessionId: this.deps.backend.sessionId,
|
|
1980
1948
|
turnId,
|
|
1981
1949
|
signal: turnAbortController.signal,
|
|
1982
1950
|
});
|
|
1983
|
-
if (
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
break agentLoop;
|
|
1987
|
-
}
|
|
1988
|
-
finishFeedback = decision.feedback;
|
|
1989
|
-
currentStepMessageId = this.deps.newId();
|
|
1990
|
-
continue agentLoop;
|
|
1951
|
+
if (finishDecision && !finishDecision.allow) {
|
|
1952
|
+
finishFeedback = finishDecision.feedback;
|
|
1953
|
+
finishCandidateReason = undefined;
|
|
1991
1954
|
}
|
|
1955
|
+
else if (toolRequestedFinish) {
|
|
1956
|
+
this.deps.modelAdapter.clearContinuation(this.turnId);
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
terminalStopReason =
|
|
1960
|
+
this.loopStopReason ??
|
|
1961
|
+
finishCandidateReason ??
|
|
1962
|
+
(stepLimitReached ? 'step_limit' : undefined);
|
|
1963
|
+
if (terminalStopReason)
|
|
1964
|
+
break agentLoop;
|
|
1965
|
+
if (!this.deps.backend.loadTurnRuntimeEvents) {
|
|
1966
|
+
throw new Error('durable current-run reader is required for turn continuation');
|
|
1992
1967
|
}
|
|
1993
|
-
|
|
1968
|
+
await queue.waitUntilConsumedThroughCurrent();
|
|
1969
|
+
if ((await input.handoffBoundary?.(turnAbortController.signal, maxSteps === undefined ? null : maxSteps - runtimeSteps)) === 'pause') {
|
|
1970
|
+
this.handoffPaused = true;
|
|
1971
|
+
break agentLoop;
|
|
1972
|
+
}
|
|
1973
|
+
currentStepMessageId = this.deps.newId();
|
|
1994
1974
|
}
|
|
1995
1975
|
// Refine Tool Availability against the final active set. Deferred
|
|
1996
1976
|
// loading may add tools, while boundary convergence may remove them;
|
|
@@ -2006,7 +1986,7 @@ export class AiSdkTurn {
|
|
|
2006
1986
|
// silently drop prior requests. An unusable sample in ANY request fails
|
|
2007
1987
|
// the whole record closed (#972).
|
|
2008
1988
|
try {
|
|
2009
|
-
const attemptTotalUsage = providerOutcome
|
|
1989
|
+
const attemptTotalUsage = providerOutcome?.usage;
|
|
2010
1990
|
tokenUsage = sawUnusableStepUsage ? undefined : (completedStepUsage ?? attemptTotalUsage);
|
|
2011
1991
|
if (tokenUsage) {
|
|
2012
1992
|
tokenUsageCostUsd = this.deps.providerTelemetry.normalizedUsageCostUsd(tokenUsage);
|
|
@@ -2110,10 +2090,9 @@ export class AiSdkTurn {
|
|
|
2110
2090
|
// seals the drained stream; no complete/abort event ends the logical Turn.
|
|
2111
2091
|
if (this.handoffPaused)
|
|
2112
2092
|
return;
|
|
2113
|
-
const stopReason = this.loopStopReason ??
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
: this.mapFinishReason(finishReason));
|
|
2093
|
+
const stopReason = this.loopStopReason ?? terminalStopReason;
|
|
2094
|
+
if (!stopReason)
|
|
2095
|
+
throw new Error('Turn ended without a terminal decision');
|
|
2117
2096
|
trace.modelStreamCompleted(stopReason);
|
|
2118
2097
|
const completeEvent = {
|
|
2119
2098
|
type: 'complete',
|
|
@@ -2281,7 +2260,7 @@ export class AiSdkTurn {
|
|
|
2281
2260
|
})),
|
|
2282
2261
|
isFatalToolError: isRuntimeCommitBoundaryError,
|
|
2283
2262
|
callTool: async (name, input, signal) => {
|
|
2284
|
-
if (this.
|
|
2263
|
+
if (this.loopStopReason)
|
|
2285
2264
|
throw new Error('The turn has yielded; no further tools may run.');
|
|
2286
2265
|
const tool = snapshot.get(name);
|
|
2287
2266
|
if (!tool)
|
|
@@ -2343,8 +2322,7 @@ export class AiSdkTurn {
|
|
|
2343
2322
|
revision: proposal.revision,
|
|
2344
2323
|
storeVersion: result.storeVersion,
|
|
2345
2324
|
});
|
|
2346
|
-
this.
|
|
2347
|
-
this.loopStopRequested = true;
|
|
2325
|
+
this.turnYield = 'plan_handoff';
|
|
2348
2326
|
return;
|
|
2349
2327
|
}
|
|
2350
2328
|
const traceType = result.kind;
|
|
@@ -2365,11 +2343,7 @@ export class AiSdkTurn {
|
|
|
2365
2343
|
liveOperatorCount: result.liveOperatorCount,
|
|
2366
2344
|
reason: result.reason,
|
|
2367
2345
|
});
|
|
2368
|
-
this.
|
|
2369
|
-
this.loopStopRequested = true;
|
|
2370
|
-
}
|
|
2371
|
-
mapFinishReason(reason) {
|
|
2372
|
-
return this.deps.modelAdapter.mapFinishReason(reason);
|
|
2346
|
+
this.turnYield = 'graph_yield';
|
|
2373
2347
|
}
|
|
2374
2348
|
makeErrorEvent(turnId, err, reasonOverride) {
|
|
2375
2349
|
return this.deps.modelAdapter.makeErrorEvent(turnId, err, reasonOverride);
|