eve 0.37.0 → 0.38.0
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/CHANGELOG.md +32 -0
- package/dist/src/channel/routes.d.ts +13 -3
- package/dist/src/channel/routes.js +1 -1
- package/dist/src/channel/session-callback.js +1 -1
- package/dist/src/channel/session.d.ts +2 -1
- package/dist/src/channel/session.js +1 -1
- package/dist/src/channel/types.d.ts +41 -0
- package/dist/src/chunks/{use-eve-agent-COmP-H8R.js → use-eve-agent-BbSsu99c.js} +79 -32
- package/dist/src/chunks/{use-eve-agent-CnppTEFk.js → use-eve-agent-Dt8Y5QtW.js} +78 -31
- package/dist/src/cli/acp/command.d.ts +2 -1
- package/dist/src/cli/acp/command.js +2 -2
- package/dist/src/cli/application-command.d.ts +8 -0
- package/dist/src/cli/application-command.js +1 -0
- package/dist/src/cli/application-root.d.ts +8 -0
- package/dist/src/cli/application-root.js +1 -0
- package/dist/src/cli/commands/build.d.ts +2 -1
- package/dist/src/cli/commands/build.js +1 -1
- package/dist/src/cli/commands/init-git.js +1 -1
- package/dist/src/cli/commands/init-recovery.d.ts +3 -0
- package/dist/src/cli/commands/init-recovery.js +3 -0
- package/dist/src/cli/commands/init-repl.js +1 -1
- package/dist/src/cli/commands/init-target.d.ts +21 -0
- package/dist/src/cli/commands/init-target.js +1 -0
- package/dist/src/cli/commands/init.js +1 -1
- package/dist/src/cli/commands/register-integration-commands.d.ts +2 -1
- package/dist/src/cli/commands/register-integration-commands.js +1 -1
- package/dist/src/cli/commands/register-project-commands.d.ts +2 -1
- package/dist/src/cli/commands/register-project-commands.js +1 -1
- package/dist/src/cli/commands/register-registry-commands.d.ts +2 -1
- package/dist/src/cli/commands/register-registry-commands.js +4 -1
- package/dist/src/cli/commands/registry-recovery.d.ts +14 -0
- package/dist/src/cli/commands/registry-recovery.js +1 -0
- package/dist/src/cli/commands/registry.d.ts +2 -5
- package/dist/src/cli/commands/registry.js +1 -1
- package/dist/src/cli/dev/diagnostic-dump.js +1 -1
- package/dist/src/cli/dev/environment.js +1 -1
- package/dist/src/cli/dev/tui/runner.d.ts +8 -0
- package/dist/src/cli/dev/tui/runner.js +1 -1
- package/dist/src/cli/dev/tui/subagent-pump.d.ts +27 -22
- package/dist/src/cli/dev/tui/subagent-pump.js +1 -1
- package/dist/src/cli/dev/tui/terminal-renderer.d.ts +16 -0
- package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
- package/dist/src/cli/dev/tui/tool-presentation.js +1 -1
- package/dist/src/cli/invoke/command.d.ts +3 -2
- package/dist/src/cli/invoke/command.js +1 -1
- package/dist/src/cli/run.d.ts +3 -2
- package/dist/src/cli/run.js +3 -3
- package/dist/src/client/eve-agent-store.d.ts +15 -3
- package/dist/src/client/eve-agent-store.js +2 -2
- package/dist/src/client/message-response.d.ts +10 -2
- package/dist/src/client/message-response.js +1 -1
- package/dist/src/client/open-stream.d.ts +2 -0
- package/dist/src/client/open-stream.js +1 -1
- package/dist/src/client/session.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +5 -1
- package/dist/src/compiled/@ai-sdk/otel/index.js +3 -3
- package/dist/src/compiled/@chat-adapter/slack/index.js +25 -25
- package/dist/src/compiled/@modelcontextprotocol/server/LICENSE +216 -0
- package/dist/src/compiled/@modelcontextprotocol/server/index.d.ts +98 -0
- package/dist/src/compiled/@modelcontextprotocol/server/index.js +80 -0
- package/dist/src/compiled/@opentelemetry/api/index.js +1 -1
- package/dist/src/compiled/@opentelemetry/otlp-transformer/index.js +1 -1
- package/dist/src/compiled/@photon-ai/chat-adapter-imessage/index.js +61 -61
- package/dist/src/compiled/@vercel/oidc/index.js +14 -14
- package/dist/src/compiled/@vercel/otel/index.js +1 -1
- package/dist/src/compiled/@vercel/sandbox/index.js +1 -1
- package/dist/src/compiled/@workflow/core/index.js +1 -1
- package/dist/src/compiled/@workflow/core/private.js +1 -1
- package/dist/src/compiled/@workflow/core/runtime.js +2 -2
- package/dist/src/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/errors/index.js +1 -1
- package/dist/src/compiled/@workflow/world-local/index.js +5 -5
- package/dist/src/compiled/@workflow/world-vercel/index.js +13 -13
- package/dist/src/compiled/_chunks/workflow/{attribute-changes-BoH7JsWp.js → attribute-changes-DZtQkszH.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/chunk-5MU5Z6L3-B_3nkJFi.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{chunk-NWCAEW5Y-Oxw40oRR.js → chunk-NWCAEW5Y-BgbcH0OK.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{dist-DlFv0aHY.js → dist-CPlyFOVo.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{dist-tJoQXAF6.js → dist-DpYyXbJv.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{dist-CRTn4Sg8.js → dist-xQXN70ED.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/esm-seIr7a6j.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{frames-CTpeJYEQ.js → frames-BBs-9k1d.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/{functions-CeeNvKsq.js → functions-DAYiHNti.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{getMachineId-bsd-WEBNKY2R-CEYkx6Nv.js → getMachineId-bsd-WEBNKY2R-BTaxrQ52.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{getMachineId-darwin-LT47KAXP-DPwWlhif.js → getMachineId-darwin-LT47KAXP-DhYmwE_R.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{getMachineId-linux-LTVQO6VW-DAFXHwZp.js → getMachineId-linux-LTVQO6VW-Dru_L5ru.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{getMachineId-unsupported-UKWBA27G-BZKOI8mG.js → getMachineId-unsupported-UKWBA27G-DGfoqVW1.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{getMachineId-win-NLJKOPY6-r7_CJB5o.js → getMachineId-win-NLJKOPY6-CLM98q4X.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{private-tvMBynnC.js → private-UQtz8ZcW.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{resume-hook-BPQHjeY5.js → resume-hook-CYtSorp6.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{rolldown-runtime-DaDcL9Zw.js → rolldown-runtime-8V8biNmG.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{run-DQ5dOyjm.js → run-Cjo0A3NO.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{signal-exit-C8vsI6zj.js → signal-exit-o3IPQwwv.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/sleep-C1P0OWBm.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{token-DHD-q-fS.js → token-DGzfw-Vb.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{token-DtCUEpJs.js → token-DNbxVpeq.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/token-util-BneBe0g5.js +27 -0
- package/dist/src/compiled/_chunks/workflow/{token-util-Ldar52H7.js → token-util-DjMgNdXS.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{undici-CUIybhQ2.js → undici-BBG5cZTy.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{wait-until-DK2lnH6U.js → wait-until-CT1ve8qB.js} +3 -3
- package/dist/src/compiled/_chunks/workflow/{wrapper-CMGju7QA.js → wrapper-CQNxP9mU.js} +3 -3
- package/dist/src/compiled/_chunks/workflow/{ws-transport-Csi6Cydc.js → ws-transport-beXxD0s_.js} +1 -1
- package/dist/src/compiled/env-runner/node-worker.js +1 -1
- package/dist/src/compiled/jose/index.js +1 -1
- package/dist/src/compiled/shadcn-registry/index.js +403 -403
- package/dist/src/compiler/artifacts.js +1 -1
- package/dist/src/compiler/compile-agent.js +2 -2
- package/dist/src/compiler/extension-compatibility.d.ts +20 -10
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/normalize-agent-config.js +1 -1
- package/dist/src/compiler/normalize-extension.d.ts +8 -5
- package/dist/src/compiler/normalize-extension.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +1 -1
- package/dist/src/compiler/normalize-subagent.d.ts +1 -1
- package/dist/src/compiler/normalize-subagent.js +1 -1
- package/dist/src/context/serialized-dynamic-model-selection.d.ts +2 -0
- package/dist/src/context/serialized-dynamic-model-selection.js +1 -0
- package/dist/src/discover/discover-agent.js +1 -1
- package/dist/src/discover/extensions.d.ts +0 -6
- package/dist/src/discover/extensions.js +1 -1
- package/dist/src/evals/cli/eval.d.ts +1 -1
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/execution/agent-handle-dispatch.d.ts +15 -1
- package/dist/src/execution/agent-handle-dispatch.js +1 -1
- package/dist/src/execution/cancel-descendant-turns-step.js +1 -1
- package/dist/src/execution/delegated-parent-notification.d.ts +17 -0
- package/dist/src/execution/delegated-parent-notification.js +1 -1
- package/dist/src/execution/deliver-payloads.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-shared.d.ts +155 -0
- package/dist/src/execution/dispatch-runtime-actions-shared.js +1 -0
- package/dist/src/execution/dispatch-runtime-actions-step.d.ts +18 -14
- package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.d.ts +7 -2
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -1
- package/dist/src/execution/effective-output-schema.d.ts +21 -0
- package/dist/src/execution/effective-output-schema.js +1 -0
- package/dist/src/execution/eve-workflow-attributes.d.ts +2 -0
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/parked-delivery-wait.d.ts +8 -12
- package/dist/src/execution/parked-delivery-wait.js +1 -1
- package/dist/src/execution/{route-proxied-deliver-step.d.ts → proxied-deliver-step.d.ts} +7 -4
- package/dist/src/execution/proxied-deliver-step.js +1 -0
- package/dist/src/execution/remote-agent-dispatch.d.ts +32 -0
- package/dist/src/execution/remote-agent-dispatch.js +1 -1
- package/dist/src/execution/remote-agent-route-url.d.ts +2 -0
- package/dist/src/execution/remote-agent-route-url.js +1 -0
- package/dist/src/execution/route-child-delivery.d.ts +2 -1
- package/dist/src/execution/route-child-delivery.js +1 -1
- package/dist/src/execution/sandbox/bindings/docker-templates.js +1 -1
- package/dist/src/execution/sandbox/bindings/just-bash.js +1 -1
- package/dist/src/execution/sandbox/bindings/microsandbox-templates.js +1 -1
- package/dist/src/execution/sandbox/prewarm.js +1 -1
- package/dist/src/execution/session-callback-step.d.ts +11 -0
- package/dist/src/execution/session-callback-step.js +1 -1
- package/dist/src/execution/session-command-wire.js +1 -1
- package/dist/src/execution/session-state-cursor.d.ts +25 -0
- package/dist/src/execution/session-state-cursor.js +1 -0
- package/dist/src/execution/settle-cancelled-turn-step.d.ts +2 -0
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/subagent-event-proxy-step.d.ts +15 -0
- package/dist/src/execution/subagent-event-proxy-step.js +1 -1
- package/dist/src/execution/subagent-hitl-proxy.d.ts +14 -7
- package/dist/src/execution/subagent-hitl-proxy.js +1 -1
- package/dist/src/execution/subagent-start-local.d.ts +29 -0
- package/dist/src/execution/subagent-start-local.js +1 -0
- package/dist/src/execution/subagent-start-remote.d.ts +23 -0
- package/dist/src/execution/subagent-start-remote.js +1 -0
- package/dist/src/execution/task-event-callback.d.ts +13 -0
- package/dist/src/execution/task-event-callback.js +1 -0
- package/dist/src/execution/task-input-capability.d.ts +4 -0
- package/dist/src/execution/task-input-capability.js +1 -0
- package/dist/src/execution/tasks/child/steps.d.ts +46 -0
- package/dist/src/execution/tasks/child/steps.js +1 -0
- package/dist/src/execution/tasks/child/workflow.d.ts +31 -0
- package/dist/src/execution/tasks/child/workflow.js +1 -0
- package/dist/src/execution/tasks/parent/agent-identity.d.ts +13 -0
- package/dist/src/execution/tasks/parent/agent-identity.js +1 -0
- package/dist/src/execution/tasks/parent/agent-views.d.ts +6 -0
- package/dist/src/execution/tasks/parent/agent-views.js +1 -0
- package/dist/src/execution/tasks/parent/continuation-dispatch.d.ts +37 -0
- package/dist/src/execution/tasks/parent/continuation-dispatch.js +1 -0
- package/dist/src/execution/tasks/parent/control-shared.d.ts +36 -0
- package/dist/src/execution/tasks/parent/control-shared.js +1 -0
- package/dist/src/execution/tasks/parent/delegate.d.ts +70 -0
- package/dist/src/execution/tasks/parent/delegate.js +1 -0
- package/dist/src/execution/tasks/parent/dispatch-task-step.d.ts +19 -0
- package/dist/src/execution/tasks/parent/dispatch-task-step.js +1 -0
- package/dist/src/execution/tasks/parent/dispatch.d.ts +33 -0
- package/dist/src/execution/tasks/parent/dispatch.js +1 -0
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.d.ts +29 -0
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.js +1 -0
- package/dist/src/execution/tasks/parent/run-parent.d.ts +72 -0
- package/dist/src/execution/tasks/parent/run-parent.js +1 -0
- package/dist/src/execution/tasks/parent/send.d.ts +25 -0
- package/dist/src/execution/tasks/parent/send.js +1 -0
- package/dist/src/execution/tasks/workflow-target.d.ts +2 -0
- package/dist/src/execution/tasks/workflow-target.js +1 -0
- package/dist/src/execution/terminate-child-sessions-step.d.ts +1 -0
- package/dist/src/execution/terminate-child-sessions-step.js +1 -1
- package/dist/src/execution/turn-control-receiver.d.ts +10 -0
- package/dist/src/execution/turn-control-receiver.js +1 -1
- package/dist/src/execution/turn-dispatch.d.ts +2 -0
- package/dist/src/execution/turn-dispatch.js +1 -1
- package/dist/src/execution/turn-execution-cursor.d.ts +2 -8
- package/dist/src/execution/turn-execution-cursor.js +1 -1
- package/dist/src/execution/turn-workflow.js +1 -1
- package/dist/src/execution/workflow-callback-url.d.ts +5 -0
- package/dist/src/execution/workflow-callback-url.js +1 -1
- package/dist/src/execution/workflow-entry.js +1 -1
- package/dist/src/execution/workflow-runtime.d.ts +9 -0
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/execution/workflow-steps.d.ts +7 -21
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/harness/advertised-tools.js +1 -1
- package/dist/src/harness/authorization.js +1 -1
- package/dist/src/harness/execute-tool.d.ts +7 -0
- package/dist/src/harness/handles/prompt.d.ts +12 -0
- package/dist/src/harness/handles/prompt.js +2 -1
- package/dist/src/harness/handles/query.js +1 -1
- package/dist/src/harness/handles/store.d.ts +9 -2
- package/dist/src/harness/handles/store.js +1 -1
- package/dist/src/harness/handles/transitions.d.ts +10 -1
- package/dist/src/harness/handles/transitions.js +1 -1
- package/dist/src/harness/instrumentation/providers.js +1 -1
- package/dist/src/harness/instrumentation/runtime-context.d.ts +2 -0
- package/dist/src/harness/instrumentation/runtime-context.js +1 -1
- package/dist/src/harness/instrumentation/runtime.d.ts +3 -1
- package/dist/src/harness/proxy-input-requests.d.ts +21 -4
- package/dist/src/harness/proxy-input-requests.js +1 -1
- package/dist/src/harness/runtime-actions.d.ts +2 -0
- package/dist/src/harness/runtime-actions.js +1 -1
- package/dist/src/harness/session-limit-enforcement.js +1 -1
- package/dist/src/harness/tool-loop.js +2 -2
- package/dist/src/harness/workflow-runtime-action-state.js +1 -1
- package/dist/src/internal/application/cache-metadata.js +1 -1
- package/dist/src/internal/application/compiled-artifacts.js +2 -2
- package/dist/src/internal/application/optional-package-install.js +1 -1
- package/dist/src/internal/application/output-publication-lock.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/application/paths.js +1 -1
- package/dist/src/internal/application/tsconfig-dependencies.js +1 -1
- package/dist/src/internal/authored-definition/core.js +1 -1
- package/dist/src/internal/authored-module-evaluation-error.js +4 -4
- package/dist/src/internal/authored-module-loader.js +3 -3
- package/dist/src/internal/authored-package-boundary.js +1 -1
- package/dist/src/internal/authored-relative-extension-resolver.js +1 -1
- package/dist/src/internal/bundler/extension-scope-plugin.js +1 -1
- package/dist/src/internal/bundler/nitro-rolldown.js +1 -1
- package/dist/src/internal/instrumentation-layout.js +1 -1
- package/dist/src/internal/invocation/agent-invocation.d.ts +54 -0
- package/dist/src/internal/invocation/agent-invocation.js +1 -0
- package/dist/src/internal/invocation/attributes.d.ts +2 -0
- package/dist/src/internal/invocation/attributes.js +1 -0
- package/dist/src/internal/invocation/metadata.d.ts +9 -0
- package/dist/src/internal/invocation/metadata.js +1 -0
- package/dist/src/internal/invocation/workflow-execution.d.ts +32 -0
- package/dist/src/internal/invocation/workflow-execution.js +1 -0
- package/dist/src/internal/materialized-authored-modules.js +1 -1
- package/dist/src/internal/mcp/http-security.d.ts +12 -0
- package/dist/src/internal/mcp/http-security.js +1 -0
- package/dist/src/internal/mcp/protected-resource.d.ts +9 -0
- package/dist/src/internal/mcp/protected-resource.js +1 -0
- package/dist/src/internal/mcp/streamable-http-server.d.ts +51 -0
- package/dist/src/internal/mcp/streamable-http-server.js +1 -0
- package/dist/src/internal/nitro/dev-runtime-artifacts-retention.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-copy.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-local-roots.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot.js +1 -1
- package/dist/src/internal/nitro/host/application-route-registry.d.ts +88 -0
- package/dist/src/internal/nitro/host/application-route-registry.js +1 -0
- package/dist/src/internal/nitro/host/build-application.js +1 -1
- package/dist/src/internal/nitro/host/build-extension.js +1 -1
- package/dist/src/internal/nitro/host/build-vercel-agent-summary.js +1 -1
- package/dist/src/internal/nitro/host/channel-routes.d.ts +4 -11
- package/dist/src/internal/nitro/host/channel-routes.js +3 -3
- package/dist/src/internal/nitro/host/configure-nitro-routes.js +3 -3
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/dev-authored-source-watcher.js +1 -1
- package/dist/src/internal/nitro/host/dev-runner.js +1 -1
- package/dist/src/internal/nitro/host/dev-workspace-extensions.js +1 -1
- package/dist/src/internal/nitro/host/extension-capability-requirements.js +1 -1
- package/dist/src/internal/nitro/host/local-tracing-runtime-plugin.js +1 -1
- package/dist/src/internal/nitro/host/nitro-bundler-config.js +1 -1
- package/dist/src/internal/nitro/host/start-development-server.js +2 -2
- package/dist/src/internal/nitro/host/start-production-server.js +2 -2
- package/dist/src/internal/nitro/host/vercel-build-output-config.js +1 -1
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/channel-route-context.d.ts +14 -0
- package/dist/src/internal/nitro/routes/channel-route-context.js +1 -1
- package/dist/src/internal/nitro/routes/runtime-stack.d.ts +2 -0
- package/dist/src/internal/nitro/routes/runtime-stack.js +1 -1
- package/dist/src/internal/process/pnpm.js +1 -1
- package/dist/src/internal/vercel-agent-summary.d.ts +1 -1
- package/dist/src/internal/workflow/development-world-client.js +1 -1
- package/dist/src/internal/workflow/development-world-server.js +1 -1
- package/dist/src/internal/workflow-bundle/builder-support.d.ts +12 -8
- package/dist/src/internal/workflow-bundle/builder-support.js +8 -7
- package/dist/src/internal/workflow-bundle/builder.d.ts +1 -1
- package/dist/src/internal/workflow-bundle/builder.js +2 -3
- package/dist/src/internal/workflow-bundle/workflow-builders.js +1 -1
- package/dist/src/protocol/message.d.ts +28 -0
- package/dist/src/protocol/message.js +2 -2
- package/dist/src/protocol/routes.d.ts +14 -0
- package/dist/src/protocol/routes.js +1 -1
- package/dist/src/public/channels/auth.d.ts +36 -0
- package/dist/src/public/channels/auth.js +1 -1
- package/dist/src/public/channels/discord/discordChannel.d.ts +2 -0
- package/dist/src/public/channels/discord/discordChannel.js +1 -1
- package/dist/src/public/channels/eve.d.ts +2 -0
- package/dist/src/public/channels/eve.js +1 -1
- package/dist/src/public/channels/github/dispatch.js +1 -1
- package/dist/src/public/channels/github/githubChannel.d.ts +2 -0
- package/dist/src/public/channels/linear/linearChannel.d.ts +2 -0
- package/dist/src/public/channels/linear/linearChannel.js +1 -1
- package/dist/src/public/channels/mcp.d.ts +19 -0
- package/dist/src/public/channels/mcp.js +1 -0
- package/dist/src/public/channels/photon/photonIMessageChannel.d.ts +2 -0
- package/dist/src/public/channels/photon/photonIMessageChannel.js +1 -1
- package/dist/src/public/channels/slack/slackChannel.d.ts +3 -1
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/teams/teamsChannel.d.ts +2 -0
- package/dist/src/public/channels/teams/teamsChannel.js +1 -1
- package/dist/src/public/channels/telegram/telegramChannel.d.ts +2 -0
- package/dist/src/public/channels/telegram/telegramChannel.js +1 -1
- package/dist/src/public/channels/twilio/twilioChannel.d.ts +2 -0
- package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
- package/dist/src/public/definitions/channel.d.ts +2 -2
- package/dist/src/public/definitions/channel.js +1 -1
- package/dist/src/public/instrumentation/index.d.ts +9 -3
- package/dist/src/public/next/server.js +1 -1
- package/dist/src/public/nuxt/dev-server.js +1 -1
- package/dist/src/public/sveltekit/dev-server.js +1 -1
- package/dist/src/react/use-eve-agent.d.ts +4 -4
- package/dist/src/react/use-eve-agent.js +1 -1
- package/dist/src/runtime/actions/types.d.ts +9 -0
- package/dist/src/runtime/actions/types.js +1 -1
- package/dist/src/runtime/agent/bootstrap.js +1 -1
- package/dist/src/runtime/connections/authorization-complete-page.js +70 -28
- package/dist/src/runtime/framework-channels/index.js +1 -1
- package/dist/src/runtime/framework-tools/index.js +1 -1
- package/dist/src/runtime/framework-tools/tasks.d.ts +95 -0
- package/dist/src/runtime/framework-tools/tasks.js +1 -0
- package/dist/src/runtime/prompt/compose.d.ts +1 -0
- package/dist/src/runtime/prompt/compose.js +1 -1
- package/dist/src/runtime/resolve-agent-graph.js +1 -1
- package/dist/src/runtime/resolve-agent.js +1 -1
- package/dist/src/runtime/session-callback-route.js +1 -1
- package/dist/src/runtime/task-input-response-route.d.ts +5 -0
- package/dist/src/runtime/task-input-response-route.js +1 -0
- package/dist/src/services/inspect-application.js +1 -1
- package/dist/src/setup/primitives/pm/pnpm.js +2 -2
- package/dist/src/setup/primitives/run-vercel.js +1 -1
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/extension.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
- package/dist/src/setup/scaffold/create/web-template.js +8 -86
- package/dist/src/setup/scaffold/version-tokens.js +1 -1
- package/dist/src/setup/scaffold/workspace-root.js +1 -1
- package/dist/src/shared/agent-definition.d.ts +7 -0
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.d.ts +3 -3
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tasks/json.d.ts +88 -0
- package/dist/src/tasks/json.js +1 -0
- package/dist/src/tasks/session-index.d.ts +48 -0
- package/dist/src/tasks/session-index.js +1 -0
- package/dist/src/tasks/task-id.d.ts +34 -0
- package/dist/src/tasks/task-id.js +1 -0
- package/dist/src/tasks/transitions.d.ts +23 -0
- package/dist/src/tasks/transitions.js +1 -0
- package/dist/src/tasks/types.d.ts +295 -0
- package/dist/src/tasks/types.js +1 -0
- package/dist/src/tasks/wire.d.ts +26 -0
- package/dist/src/tasks/wire.js +1 -0
- package/dist/src/tracing/install-instrumentation-runtime.d.ts +2 -1
- package/dist/src/tracing/install-instrumentation-runtime.js +1 -1
- package/dist/src/tracing/otel-declaration.d.ts +32 -3
- package/dist/src/tracing/otel-declaration.js +1 -1
- package/dist/src/tracing/otel-registration.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.d.ts +3 -3
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/channels/custom.mdx +1 -1
- package/docs/channels/discord.mdx +1 -1
- package/docs/channels/eve.mdx +15 -2
- package/docs/channels/github.mdx +1 -1
- package/docs/channels/linear.mdx +1 -1
- package/docs/channels/overview.mdx +1 -1
- package/docs/channels/photon.mdx +1 -1
- package/docs/channels/slack.mdx +1 -1
- package/docs/channels/teams.mdx +1 -1
- package/docs/channels/telegram.mdx +1 -1
- package/docs/channels/twilio.mdx +1 -1
- package/docs/extensions.md +10 -6
- package/docs/guides/client/streaming.mdx +7 -6
- package/docs/guides/frontend/overview.mdx +10 -8
- package/docs/guides/frontend/use-eve-agent-svelte.mdx +10 -10
- package/docs/guides/frontend/use-eve-agent-vue.mdx +10 -10
- package/docs/install-integrations.mdx +4 -0
- package/docs/reference/cli.md +1 -1
- package/docs/schedules.mdx +2 -2
- package/docs/tools/human-in-the-loop.md +3 -1
- package/package.json +7 -1
- package/dist/src/compiled/_chunks/workflow/chunk-5MU5Z6L3-CaJgXkVg.js +0 -1
- package/dist/src/compiled/_chunks/workflow/sleep-CzdoBiqy.js +0 -1
- package/dist/src/compiled/_chunks/workflow/src-Cj3P1ChQ.js +0 -1
- package/dist/src/compiled/_chunks/workflow/token-util-DNwIAn_u.js +0 -27
- package/dist/src/execution/route-proxied-deliver-step.js +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DispatchOutcome, type RuntimeAgentHandleAction, type RuntimeSession } from "#execution/agent-handle-dispatch.js";
|
|
2
|
+
import { settleDelegatedDispatch, type DelegatedTask } from "#execution/tasks/parent/delegate.js";
|
|
3
|
+
import { describeTaskAgent } from "#execution/tasks/parent/agent-identity.js";
|
|
4
|
+
import type { RuntimeSubagentDispatchFailure } from "#runtime/actions/types.js";
|
|
5
|
+
export type PersistedContinuationTask = Awaited<ReturnType<typeof settleDelegatedDispatch>>;
|
|
6
|
+
/** Describes task identity from the stored address when continuing an agent. */
|
|
7
|
+
export declare function describeTaskDispatch(input: {
|
|
8
|
+
readonly action: RuntimeAgentHandleAction;
|
|
9
|
+
readonly agentId: string | undefined;
|
|
10
|
+
readonly parentSessionId: string;
|
|
11
|
+
readonly parentTurnId: string;
|
|
12
|
+
readonly session: RuntimeSession;
|
|
13
|
+
}): ReturnType<typeof describeTaskAgent>;
|
|
14
|
+
export declare function checkTaskContinuationAvailability(input: {
|
|
15
|
+
readonly action: RuntimeAgentHandleAction;
|
|
16
|
+
readonly agentId: string;
|
|
17
|
+
readonly parentStepIndex: number;
|
|
18
|
+
readonly parentTurnId: string;
|
|
19
|
+
readonly session: RuntimeSession;
|
|
20
|
+
}): Promise<RuntimeSubagentDispatchFailure | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Persists the task's ownership and routing entry in the parent session's
|
|
23
|
+
* `eve.tasks` index and creates its parked tool-call receipt before dispatch.
|
|
24
|
+
*/
|
|
25
|
+
export declare function persistContinuationTaskInParentSession(input: {
|
|
26
|
+
readonly action: RuntimeAgentHandleAction;
|
|
27
|
+
readonly agentId: string;
|
|
28
|
+
readonly delegated: DelegatedTask;
|
|
29
|
+
readonly session: RuntimeSession;
|
|
30
|
+
}): Promise<PersistedContinuationTask | undefined>;
|
|
31
|
+
export declare function settleTaskDispatchError(input: {
|
|
32
|
+
readonly delegated: DelegatedTask;
|
|
33
|
+
readonly outcome: Extract<DispatchOutcome, {
|
|
34
|
+
readonly kind: "error";
|
|
35
|
+
}>;
|
|
36
|
+
readonly persisted: PersistedContinuationTask | undefined;
|
|
37
|
+
}): Promise<RuntimeSubagentDispatchFailure>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{AGENT_BUSY}from"#harness/agent-handle-errors.js";import{createAgentErrorResult}from"#execution/agent-handle-dispatch.js";import{findActiveTaskForAgent,findTaskAgentAddress}from"#execution/tasks/parent/control-shared.js";import{failDelegatedDispatch,rejectDelegatedDispatch,settleDelegatedDispatch}from"#execution/tasks/parent/delegate.js";import{describeTaskAgent}from"#execution/tasks/parent/agent-identity.js";function describeTaskDispatch(e){let t=describeTaskAgent(e),n=e.agentId===void 0?void 0:findTaskAgentAddress(e.session,e.agentId);return n===void 0?t:{...t,mode:n.address.kind===`agent/remote`?`remote`:`local`}}async function checkTaskContinuationAvailability(r){let i=await findActiveTaskForAgent(r.session,r.agentId,r.parentTurnId,r.parentStepIndex);return i===void 0?void 0:createAgentErrorResult({action:r.action,code:AGENT_BUSY,message:`Agent "${r.agentId}" is busy with task "${i.view.taskId}" (${i.view.status}).`})}async function persistContinuationTaskInParentSession(e){let t=findTaskAgentAddress(e.session,e.agentId);if(t!==void 0)return settleDelegatedDispatch({callId:e.action.callId,session:e.session,subagentName:t.identity.name,task:e.delegated})}async function settleTaskDispatchError(e){return e.persisted!==void 0&&e.outcome.deliveryAmbiguous===!0||await(e.persisted===void 0?rejectDelegatedDispatch:failDelegatedDispatch)({error:e.outcome.result.output,task:e.delegated}),e.persisted===void 0?e.outcome.result:{...e.outcome.result,output:attachTaskId(e.outcome.result.output,e.delegated.taskId)}}function attachTaskId(e,t){return typeof e==`object`&&e&&!Array.isArray(e)?{...e,taskId:t}:{error:e,taskId:t}}export{checkTaskContinuationAvailability,describeTaskDispatch,persistContinuationTaskInParentSession,settleTaskDispatchError};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RuntimeSession } from "#execution/agent-handle-dispatch.js";
|
|
2
|
+
import { type AgentHandle } from "#harness/handles/store.js";
|
|
3
|
+
import type { RuntimeActionResult, RuntimeToolCallActionRequest } from "#runtime/actions/types.js";
|
|
4
|
+
import { type SessionTaskIndexEntry } from "#tasks/session-index.js";
|
|
5
|
+
import type { TaskView } from "#tasks/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Result and lookup helpers shared by the task-control executors
|
|
8
|
+
* (`task_peek`/`task_cancel` in the dispatch module,
|
|
9
|
+
* `task_send` in its own).
|
|
10
|
+
*/
|
|
11
|
+
/** Resolves owned index entries, or the ids this session does not own. */
|
|
12
|
+
export declare function lookupTaskEntries(session: RuntimeSession, taskIds: readonly string[]): {
|
|
13
|
+
readonly entries: SessionTaskIndexEntry[];
|
|
14
|
+
readonly kind: "found";
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "unknown";
|
|
17
|
+
readonly unknown: string[];
|
|
18
|
+
};
|
|
19
|
+
/** Reads the latest view of every entry, defaulting to `working`. */
|
|
20
|
+
export declare function readTaskViews(entries: readonly SessionTaskIndexEntry[]): Promise<TaskView[]>;
|
|
21
|
+
export declare function readTaskView(entry: SessionTaskIndexEntry): Promise<TaskView>;
|
|
22
|
+
/** Finds the persistent address record for one task-owned agent. */
|
|
23
|
+
export declare function findTaskAgentAddress(session: RuntimeSession, agentId: string): Extract<AgentHandle, {
|
|
24
|
+
phase: "addressed";
|
|
25
|
+
}> | undefined;
|
|
26
|
+
/** Returns the one nonterminal task owning an agent, if any. */
|
|
27
|
+
export declare function findActiveTaskForAgent(session: RuntimeSession, agentId: string, parentTurnId?: string, parentStepIndex?: number): Promise<{
|
|
28
|
+
readonly entry: SessionTaskIndexEntry;
|
|
29
|
+
readonly view: TaskView;
|
|
30
|
+
} | undefined>;
|
|
31
|
+
/** One successful task-control result carrying full task views. */
|
|
32
|
+
export declare function createTaskViewsResult(action: RuntimeToolCallActionRequest, views: readonly TaskView[]): RuntimeActionResult;
|
|
33
|
+
/** One task-control error the model can act on. */
|
|
34
|
+
export declare function createTaskControlError(action: RuntimeToolCallActionRequest, message: string): RuntimeActionResult;
|
|
35
|
+
/** The ownership error for ids outside this session's task index. */
|
|
36
|
+
export declare function createUnknownTasksError(action: RuntimeToolCallActionRequest, unknown: readonly string[]): RuntimeActionResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getAgentHandleStore}from"#harness/handles/store.js";import{readLatestTaskView}from"#execution/tasks/parent/run-parent.js";import{findSessionTaskEntry,getSessionTaskIndex}from"#tasks/session-index.js";import{isTaskWorkflowTargetGone}from"#execution/tasks/workflow-target.js";import{taskViewsToJson}from"#tasks/json.js";function lookupTaskEntries(e,t){let r=[],i=[];for(let a of t){let t=findSessionTaskEntry(e.state,a);t===void 0?i.push(a):r.push(t)}return i.length>0?{kind:`unknown`,unknown:i}:{entries:r,kind:`found`}}async function readTaskViews(e){return Promise.all(e.map(readTaskView))}async function readTaskView(e){try{return await readLatestTaskView({taskRunId:e.taskRunId})??createPendingTaskView(e)}catch(t){if(isTaskWorkflowTargetGone(t)&&e.terminalView!==void 0)return e.terminalView;throw t}}function createPendingTaskView(e){return{metadata:e.metadata,status:`working`,taskId:e.taskId}}function findTaskAgentAddress(t,n){return(getAgentHandleStore(t.state)?.handles??[]).find(e=>e.phase===`addressed`&&e.identity.id===n)}async function findActiveTaskForAgent(e,t,n,i){let a=getSessionTaskIndex(e.state).filter(e=>e.metadata.agentId===t),o=await readTaskViews(a);return a.flatMap((e,t)=>{let r=o[t];return r!==void 0&&(e.createdByTurnId===n&&e.createdByStepIndex===i||r.status===`working`||r.status===`input_required`)?[{entry:e,view:r}]:[]})[0]}function createTaskViewsResult(e,t){return{callId:e.callId,kind:`tool-result`,output:taskViewsToJson(t),toolName:e.toolName}}function createTaskControlError(e,t){return{callId:e.callId,isError:!0,kind:`tool-result`,output:{message:t},toolName:e.toolName}}function createUnknownTasksError(e,t){return createTaskControlError(e,`Unknown task ids: ${t.join(`, `)}. Tasks belong to the session that created them.`)}export{createTaskControlError,createTaskViewsResult,createUnknownTasksError,findActiveTaskForAgent,findTaskAgentAddress,lookupTaskEntries,readTaskView,readTaskViews};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation policy for the subagent dispatch path: derives task identity,
|
|
3
|
+
* builds metadata and the parked-tool-call receipt, records the session
|
|
4
|
+
* index, and defines failure semantics for an unacknowledged dispatch.
|
|
5
|
+
* Task-run transport (start/command/view) lives in `run-parent.ts`, which
|
|
6
|
+
* this module composes and which other non-delegation callers share.
|
|
7
|
+
*/
|
|
8
|
+
import type { RuntimeSession } from "#execution/agent-handle-dispatch.js";
|
|
9
|
+
import type { RuntimeSubagentChildResult } from "#runtime/actions/types.js";
|
|
10
|
+
import type { JsonValue } from "#shared/json.js";
|
|
11
|
+
import { type TaskMetadata } from "#tasks/types.js";
|
|
12
|
+
/** A prepared delegated task: identity plus its started durable run. */
|
|
13
|
+
export interface DelegatedTask {
|
|
14
|
+
readonly taskInboxToken: string;
|
|
15
|
+
readonly createdByStepIndex?: number;
|
|
16
|
+
readonly createdByTurnId: string;
|
|
17
|
+
readonly metadata: TaskMetadata;
|
|
18
|
+
readonly operationId: string;
|
|
19
|
+
readonly taskId: string;
|
|
20
|
+
readonly taskRunId: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates the durable task record for one delegated subagent call,
|
|
24
|
+
* before the child dispatch side effect. The task must exist first so
|
|
25
|
+
* a fast child always finds a live command hook; a duplicate replay
|
|
26
|
+
* re-derives the same token and the loser exits on the hook claim.
|
|
27
|
+
*/
|
|
28
|
+
export declare function beginDelegatedTask(input: {
|
|
29
|
+
readonly agentId: string;
|
|
30
|
+
readonly callId: string;
|
|
31
|
+
readonly mode: "local" | "remote";
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly parentSessionId: string;
|
|
34
|
+
readonly parentStepIndex?: number;
|
|
35
|
+
readonly parentTurnId: string;
|
|
36
|
+
readonly session: RuntimeSession;
|
|
37
|
+
}): Promise<DelegatedTask>;
|
|
38
|
+
/**
|
|
39
|
+
* Settles a delegated dispatch that acknowledged a child: persists the task
|
|
40
|
+
* in the session index and returns the receipt that resolves the originating
|
|
41
|
+
* tool call. Agent identity and routing remain in the persistent address
|
|
42
|
+
* record; task state owns execution availability.
|
|
43
|
+
*/
|
|
44
|
+
export declare function settleDelegatedDispatch(input: {
|
|
45
|
+
readonly callId: string;
|
|
46
|
+
readonly session: RuntimeSession;
|
|
47
|
+
readonly subagentName: string;
|
|
48
|
+
readonly task: DelegatedTask;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
readonly receipt: RuntimeSubagentChildResult;
|
|
51
|
+
readonly session: RuntimeSession;
|
|
52
|
+
}>;
|
|
53
|
+
/** Releases task events only after the parent session index committed. */
|
|
54
|
+
export declare function acknowledgeDelegatedTasksStep(input: {
|
|
55
|
+
readonly tasks: readonly {
|
|
56
|
+
readonly taskInboxToken: string;
|
|
57
|
+
readonly taskId: string;
|
|
58
|
+
readonly taskRunId: string;
|
|
59
|
+
}[];
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
/** Fails an indexed task whose child dispatch was definitively rejected. */
|
|
62
|
+
export declare function failDelegatedDispatch(input: {
|
|
63
|
+
readonly error: JsonValue;
|
|
64
|
+
readonly task: DelegatedTask;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
/** Silently terminates a task whose child dispatch failed before parent indexing. */
|
|
67
|
+
export declare function rejectDelegatedDispatch(input: {
|
|
68
|
+
readonly error: JsonValue;
|
|
69
|
+
readonly task: DelegatedTask;
|
|
70
|
+
}): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{sessionCommandHookToken}from"#execution/session-command-token.js";import{deriveAgentOperationId}from"#harness/handles/operation-id.js";import{deriveTaskId,deriveTaskInboxToken}from"#tasks/task-id.js";import{readLatestTaskView,sendTaskCommand,sendTaskCommandToOwner,startTaskRun,waitForTaskCommandOwner}from"#execution/tasks/parent/run-parent.js";import{recordSessionTask}from"#tasks/session-index.js";import{isTerminalTaskStatus}from"#tasks/types.js";async function beginDelegatedTask(n){let r=deriveTaskId({callId:n.callId,parentSessionId:n.parentSessionId,parentTurnId:n.parentTurnId}),i=deriveTaskInboxToken({parentContinuationToken:n.session.continuationToken,taskId:r}),a=deriveAgentOperationId({callId:n.callId,parentSessionId:n.parentSessionId,parentTurnId:n.parentTurnId}),o={agentId:n.agentId,kind:`subagent`,mode:n.mode,name:n.name};await startTaskRun({taskInboxToken:i,initialView:{metadata:o,status:`working`,taskId:r},parentContinuationToken:sessionCommandHookToken(n.session.sessionId)});let s=await waitForTaskCommandOwner({taskInboxToken:i});return{taskInboxToken:i,createdByStepIndex:n.parentStepIndex??0,createdByTurnId:n.parentTurnId,metadata:o,operationId:a,taskId:r,taskRunId:s.runId}}async function settleDelegatedDispatch(e){let t={agentId:e.task.metadata.agentId,status:`working`,taskId:e.task.taskId};return{receipt:{backgroundTask:{status:t.status,taskId:t.taskId},callId:e.callId,kind:`subagent-result`,origin:`child`,outcome:{kind:`parked`,result:{kind:`succeeded`,output:`Delegated as background task ${e.task.taskId} (working).`},usageDelta:{cacheReadTokens:0,cacheWriteTokens:0,inputTokens:0,outputTokens:0}},output:t,subagentName:e.subagentName},session:recordSessionTask(e.session,{taskInboxToken:e.task.taskInboxToken,createdByStepIndex:e.task.createdByStepIndex,createdByTurnId:e.task.createdByTurnId,metadata:e.task.metadata,operationId:e.task.operationId,taskId:e.task.taskId,taskRunId:e.task.taskRunId})}}async function acknowledgeDelegatedTasksStep(e){"use step";for(let t of e.tasks){if(await sendTaskCommandToOwner({command:{kind:`ready`},taskInboxToken:t.taskInboxToken,retryUnreachable:{attempts:20,delayMs:250}})!==void 0)continue;let e=await readLatestTaskView({taskRunId:t.taskRunId});if(!(e!==void 0&&isTerminalTaskStatus(e.status)))throw Error(`Task run "${t.taskId}" did not accept its readiness command.`)}}async function failDelegatedDispatch(e){await sendTaskCommand({command:{data:e.error,kind:`fail`},taskInboxToken:e.task.taskInboxToken,retryUnreachable:{attempts:20,delayMs:250}})}async function rejectDelegatedDispatch(e){await sendTaskCommand({command:{data:e.error,kind:`reject-dispatch`},taskInboxToken:e.task.taskInboxToken,retryUnreachable:{attempts:20,delayMs:250}})}export{acknowledgeDelegatedTasksStep,beginDelegatedTask,failDelegatedDispatch,rejectDelegatedDispatch,settleDelegatedDispatch};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task-mode sibling of `dispatchRuntimeActionsStep`, selected by the turn
|
|
3
|
+
* workflow when the agent enables `experimental.tasks`.
|
|
4
|
+
*
|
|
5
|
+
* Same plan → dispatch → emit skeleton, but every delegation is wrapped in
|
|
6
|
+
* the durable task lifecycle: the task record and its inbox token
|
|
7
|
+
* exist *before* the child dispatch side effect (`beginDelegatedTask`),
|
|
8
|
+
* continuations pass the availability check and enter the parent session's
|
|
9
|
+
* task index first, and the task settles against the dispatch outcome.
|
|
10
|
+
* Children report through their task's inbox token rather than the
|
|
11
|
+
* parent turn inbox, and every start dispatches a conversation-mode
|
|
12
|
+
* (persistent) child so the background task stays resumable.
|
|
13
|
+
*
|
|
14
|
+
* Task-control calls (`task_peek` / `task_cancel` / `task_send`) execute
|
|
15
|
+
* inline in this step, which holds the session ownership index and world
|
|
16
|
+
* access they need.
|
|
17
|
+
*/
|
|
18
|
+
import { type RuntimeActionDispatchInput, type RuntimeActionDispatchResult } from "#execution/dispatch-runtime-actions-shared.js";
|
|
19
|
+
export declare function dispatchTaskStep(input: RuntimeActionDispatchInput): Promise<RuntimeActionDispatchResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createDurableSessionState}from"#execution/durable-session-store.js";import{dispatchToTaskAgentAddress}from"#execution/agent-handle-dispatch.js";import{executeTaskControlAction}from"#execution/tasks/parent/dispatch.js";import{createAgentContinuationBundle}from"#execution/agent-continuation-bundle.js";import{emitSubagentCalled,prepareRuntimeActionDispatch,startSubagent}from"#execution/dispatch-runtime-actions-shared.js";import{beginDelegatedTask,settleDelegatedDispatch}from"#execution/tasks/parent/delegate.js";import{checkTaskContinuationAvailability,describeTaskDispatch,persistContinuationTaskInParentSession,settleTaskDispatchError}from"#execution/tasks/parent/continuation-dispatch.js";async function dispatchTaskStep(r){"use step";let i=await prepareRuntimeActionDispatch({serializedContext:r.serializedContext,sessionState:r.sessionState,taskControls:!0});if(i===void 0)return{results:[],sessionState:r.sessionState,pendingTasks:[]};let{batch:a,bundle:o,session:s}=i,c=r.parentWritable.getWriter(),l=s,u=[],d=[];try{for(let e of i.plan){if(e.kind===`reject`){u.push(e.result);continue}if(e.kind===`task-control`){let t=await executeTaskControlAction({action:e.action,bundle:o,parentStepIndex:a.event.stepIndex,parentTurnId:a.event.turnId,session:l});l=t.session,t.pendingTask!==void 0&&d.push(t.pendingTask),u.push(t.result);continue}if(e.kind===`resume`){let t=await checkTaskContinuationAvailability({action:e.action,agentId:e.agentId,parentStepIndex:a.event.stepIndex,parentTurnId:a.event.turnId,session:l});if(t!==void 0){u.push(t);continue}}let n=await beginDelegatedTask({...describeTaskDispatch({action:e.kind===`resume`?e.action:e.target.action,agentId:e.kind===`resume`?e.agentId:void 0,parentSessionId:s.sessionId,parentTurnId:a.event.turnId,session:l}),parentSessionId:s.sessionId,parentStepIndex:a.event.stepIndex,parentTurnId:a.event.turnId,session:l}),f;e.kind===`resume`&&(f=await persistContinuationTaskInParentSession({action:e.action,agentId:e.agentId,delegated:n,session:l}),l=f?.session??l);let p;switch(e.kind){case`resume`:p=await dispatchToTaskAgentAddress({action:e.action,agentId:e.agentId,bundle:createAgentContinuationBundle({action:e.action,bundle:o,dynamicRemoteAgent:e.dynamicRemoteAgent}),currentSession:l,parentToken:n.taskInboxToken});break;case`start`:p=await startSubagent({auth:i.auth,batchEvent:a.event,bundle:o,callbackBaseUrl:r.callbackBaseUrl,capabilities:i.capabilities,channelMetadata:i.channelMetadata,currentSession:l,fanoutSize:i.fanoutSize,initiatorAuth:i.initiatorAuth,parentContinuationToken:n.taskInboxToken,parentTraceContext:i.parentTraceContext,persistentSessions:!0,serializedContext:i.serializedContext,session:s,taskOwned:!0,target:e.target});break}if(l=p.session,p.kind===`error`){u.push(await settleTaskDispatchError({delegated:n,outcome:p,persisted:f})),f!==void 0&&d.push(n);continue}if(f!==void 0)u.push(f.receipt);else{let e=await settleDelegatedDispatch({callId:p.callId,session:l,subagentName:p.toolName,task:n});l=e.session,u.push(e.receipt)}d.push(n),await emitSubagentCalled({adapter:i.adapter,adapterCtx:i.adapterCtx,batchEvent:a.event,entry:e,outcome:p,sessionId:s.sessionId,writer:c})}}finally{c.releaseLock()}return{results:u,sessionState:l===s?r.sessionState:createDurableSessionState({session:l}),pendingTasks:d}}export{dispatchTaskStep};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RuntimeSession } from "#execution/agent-handle-dispatch.js";
|
|
2
|
+
import type { DelegatedTask } from "#execution/tasks/parent/delegate.js";
|
|
3
|
+
import type { RuntimeActionRequest, RuntimeActionResult, RuntimeToolCallActionRequest } from "#runtime/actions/types.js";
|
|
4
|
+
import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
|
|
5
|
+
import type { SessionTaskIndexEntry } from "#tasks/session-index.js";
|
|
6
|
+
import { type TaskView } from "#tasks/types.js";
|
|
7
|
+
/** True for `task_peek` / `task_cancel` / `task_send` calls. */
|
|
8
|
+
export declare function isTaskControlAction(action: RuntimeActionRequest): action is RuntimeToolCallActionRequest;
|
|
9
|
+
/**
|
|
10
|
+
* Executes one task-control call inside the dispatch step, which holds
|
|
11
|
+
* the durable session state (ownership index) and world access the
|
|
12
|
+
* tools need.
|
|
13
|
+
*
|
|
14
|
+
* Returns the (possibly updated) session: `task_send` follow-ups record
|
|
15
|
+
* new tasks and settle the continued agent handle.
|
|
16
|
+
*/
|
|
17
|
+
export declare function executeTaskControlAction(input: {
|
|
18
|
+
readonly action: RuntimeToolCallActionRequest;
|
|
19
|
+
readonly bundle: CompiledBundle;
|
|
20
|
+
readonly parentStepIndex?: number;
|
|
21
|
+
readonly parentTurnId: string;
|
|
22
|
+
readonly session: RuntimeSession;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
readonly result: RuntimeActionResult;
|
|
25
|
+
readonly session: RuntimeSession;
|
|
26
|
+
readonly pendingTask?: DelegatedTask;
|
|
27
|
+
}>;
|
|
28
|
+
/** Commits task cancellation, then propagates it to the addressed executor. */
|
|
29
|
+
export declare function cancelOwnedTask(input: {
|
|
30
|
+
readonly bundle: CompiledBundle;
|
|
31
|
+
readonly entry: SessionTaskIndexEntry;
|
|
32
|
+
readonly session: RuntimeSession;
|
|
33
|
+
}): Promise<TaskView>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createLogger,logError}from"#internal/logging.js";import{cancelRemoteAgentTurn,resolveRemoteAgentForAction}from"#execution/remote-agent-dispatch.js";import{requestWorkflowTurnCancellation}from"#execution/workflow-runtime.js";import{TASK_CANCEL_TOOL_NAME,TASK_CONTROL_TOOL_NAMES,TASK_PEEK_TOOL_NAME,TASK_SEND_TOOL_NAME}from"#runtime/framework-tools/tasks.js";import{sendTaskCommand}from"#execution/tasks/parent/run-parent.js";import{isTerminalTaskStatus}from"#tasks/types.js";import{createTaskControlError,createTaskViewsResult,createUnknownTasksError,findTaskAgentAddress,lookupTaskEntries,readTaskView,readTaskViews}from"#execution/tasks/parent/control-shared.js";import{executeTaskSend}from"#execution/tasks/parent/send.js";const log=createLogger(`execution.tasks.dispatch`);function isTaskControlAction(e){return e.kind===`tool-call`&&TASK_CONTROL_TOOL_NAMES.has(e.toolName)}async function executeTaskControlAction(e){let{action:t,session:n}=e;if(t.toolName===TASK_SEND_TOOL_NAME)return executeTaskSend(e);let r=readTaskIds(t.input);if(r===void 0||r.length===0)return{result:createTaskControlError(t,"Provide a non-empty `taskIds` array."),session:n};let i=lookupTaskEntries(n,r);if(i.kind===`unknown`)return{result:createUnknownTasksError(t,i.unknown),session:n};let o=i.entries;switch(t.toolName){case TASK_PEEK_TOOL_NAME:return{result:createTaskViewsResult(t,await readTaskViews(o)),session:n};case TASK_CANCEL_TOOL_NAME:{let r=[];for(let t of o)r.push(await cancelOwnedTask({bundle:e.bundle,entry:t,session:n}));return{result:createTaskViewsResult(t,r),session:n}}default:return{result:createTaskControlError(t,`Unsupported task control "${t.toolName}".`),session:n}}}async function cancelOwnedTask(e){let{entry:t}=e,n=await sendTaskCommand({command:{kind:`cancel`},taskInboxToken:t.taskInboxToken}),r=await readTaskView(t);for(let e=0;e<10&&!isTerminalTaskStatus(r.status);e+=1)await new Promise(e=>setTimeout(e,250)),r=await readTaskView(t);if(!isTerminalTaskStatus(r.status))throw Error(`Task "${t.taskId}" did not commit cancellation before timeout.`);let i=r;return i.status===`cancelled`&&n===`delivered`&&await propagateTaskCancel({bundle:e.bundle,session:e.session,view:i}),i}async function propagateTaskCancel(e){let a=findTaskAgentAddress(e.session,e.view.metadata.agentId);if(a===void 0)return;let o=a.address.sessionId,s=e.view.executor?.childTurnId;if(!(e.view.executor?.childSessionId!==void 0&&e.view.executor.childSessionId!==o))try{if(a.address.kind===`agent/remote`){let t=resolveRemoteAgentForAction({nodeId:a.identity.nodeId,remoteAgentName:a.identity.name,registry:e.bundle.subagentRegistry.subagentsByNodeId}),i={remote:{...t,url:a.address.url},sessionId:o,taskId:e.view.taskId};s!==void 0&&(i.turnId=s),(await cancelRemoteAgentTurn(i)).status===`no_active_turn`&&await cancelRemoteAgentTurn({remote:{...t,url:a.address.url},sessionId:o,taskId:e.view.taskId});return}let t={sessionId:o,taskId:e.view.taskId};s!==void 0&&(t.turnId=s),(await requestWorkflowTurnCancellation(t)).status===`no_active_turn`&&await requestWorkflowTurnCancellation({sessionId:o,taskId:e.view.taskId})}catch(n){logError(log,`task cancel propagation failed; the child may run to completion`,n,{childSessionId:o,taskId:e.view.taskId})}}function readTaskIds(e){let t=e.taskIds;if(Array.isArray(t))return t.filter(e=>typeof e==`string`&&e.trim()!==``)}export{cancelOwnedTask,executeTaskControlAction,isTaskControlAction};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SubagentInputRequestHookPayload } from "#channel/types.js";
|
|
2
|
+
import type { SubagentAuthorizationEventHookPayload } from "#channel/types.js";
|
|
3
|
+
import { type DurableSessionState } from "#execution/durable-session-store.js";
|
|
4
|
+
import { type TaskView } from "#tasks/types.js";
|
|
5
|
+
/** Validates and durably records one task-owned child HITL route batch. */
|
|
6
|
+
export declare function recordTaskInputRequestStep(input: {
|
|
7
|
+
readonly hookPayload: SubagentInputRequestHookPayload;
|
|
8
|
+
readonly serializedContext: Record<string, unknown>;
|
|
9
|
+
readonly sessionState: DurableSessionState;
|
|
10
|
+
readonly taskId: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
readonly accepted: false;
|
|
13
|
+
readonly sessionState: DurableSessionState;
|
|
14
|
+
} | {
|
|
15
|
+
readonly accepted: true;
|
|
16
|
+
readonly hookPayload: SubagentInputRequestHookPayload;
|
|
17
|
+
readonly sessionState: DurableSessionState;
|
|
18
|
+
}>;
|
|
19
|
+
/** Validates that one task authorization event came from its owned child address. */
|
|
20
|
+
export declare function acceptTaskAuthorizationEventStep(input: {
|
|
21
|
+
readonly hookPayload: SubagentAuthorizationEventHookPayload;
|
|
22
|
+
readonly sessionState: DurableSessionState;
|
|
23
|
+
readonly taskId: string;
|
|
24
|
+
}): Promise<boolean>;
|
|
25
|
+
/** Caches terminal task views before their workflow runs can expire. */
|
|
26
|
+
export declare function recordTerminalTaskViewsStep(input: {
|
|
27
|
+
readonly sessionState: DurableSessionState;
|
|
28
|
+
readonly views: readonly TaskView[];
|
|
29
|
+
}): Promise<DurableSessionState>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createEveTaskInputRoutePath}from"#protocol/routes.js";import{isInputRequest}from"#runtime/input/types.js";import{getAgentHandleStore}from"#harness/handles/store.js";import{removeTaskAgentAddressFromState}from"#harness/handles/transitions.js";import{createRemoteTaskInputCallbackUrl}from"#execution/workflow-callback-url.js";import{readDurableSession}from"#execution/durable-session-store.js";import{createTaskInputRequestId,toProxyInputRequestEntries,upsertProxyInputRequestState}from"#harness/proxy-input-requests.js";import{readLatestTaskView}from"#execution/tasks/parent/run-parent.js";import{cacheTerminalTaskView,findSessionTaskEntry}from"#tasks/session-index.js";import{isTerminalTaskStatus}from"#tasks/types.js";import{createTaskInputCapabilityToken}from"#execution/task-input-capability.js";async function recordTaskInputRequestStep(r){"use step";let a=await readDurableSession(r.sessionState),o=findSessionTaskEntry(a.state,r.taskId),s=(getAgentHandleStore(a.state)?.handles??[]).find(e=>e.phase===`addressed`&&e.identity.id===o?.metadata.agentId);if(o===void 0||s?.phase!==`addressed`||s.address.sessionId!==r.hookPayload.childSessionId)return{accepted:!1,sessionState:r.sessionState};let c=await readLatestTaskView({taskRunId:o.taskRunId}),l=r.hookPayload.event.requests.map(e=>e.requestId),u=c?.inputRequests?.map(e=>typeof e==`object`&&e&&!Array.isArray(e)?Reflect.get(e,`requestId`):void 0)??[];if(c?.status!==`input_required`||!r.hookPayload.event.requests.every(isInputRequest)||c.metadata.mode!==(s.address.kind===`agent/remote`?`remote`:`local`)||c.metadata.agentId!==o.metadata.agentId||c.executor?.childSessionId!==r.hookPayload.childSessionId||new Set(l).size!==l.length||l.length!==u.length||l.some((e,t)=>e!==u[t]))return{accepted:!1,sessionState:r.sessionState};let d=namespaceTaskInputRequests(r.hookPayload,r.taskId),f=toProxyInputRequestEntries(d,r.taskId).map(([e,t],n)=>{let i=r.hookPayload.event.requests[n].requestId;return[e,{...t,childRequestId:i}]});if(s.address.kind===`agent/remote`){let t=createRemoteTaskInputCallbackUrl(s.address.url,createEveTaskInputRoutePath(createTaskInputCapabilityToken(r.hookPayload.childContinuationToken)));f=f.map(([e,n])=>[e,{...n,childResponseUrl:t}])}let p=upsertProxyInputRequestState({entries:f,forChildContinuationToken:r.hookPayload.childContinuationToken,state:a.state});return{accepted:!0,hookPayload:d,sessionState:{...r.sessionState,hasProxyInputRequests:!0,snapshot:{session:{...a,state:p},version:r.sessionState.version}}}}function namespaceTaskInputRequests(e,t){return{...e,event:{...e.event,requests:e.event.requests.map(e=>({...e,requestId:createTaskInputRequestId(t,e.requestId)}))}}}async function acceptTaskAuthorizationEventStep(e){"use step";let t=await readDurableSession(e.sessionState),r=findSessionTaskEntry(t.state,e.taskId);if(r===void 0)return!1;let i=(getAgentHandleStore(t.state)?.handles??[]).find(e=>e.phase===`addressed`&&e.identity.id===r.metadata.agentId);if(i?.phase!==`addressed`||i.address.sessionId!==e.hookPayload.childSessionId)return!1;let a=await readLatestTaskView({taskRunId:r.taskRunId});return a!==void 0&&!isTerminalTaskStatus(a.status)&&a.executor?.childSessionId===e.hookPayload.childSessionId&&a.metadata.agentId===r.metadata.agentId}async function recordTerminalTaskViewsStep(e){"use step";let t=await readDurableSession(e.sessionState),n=t.state;for(let t of e.views)n=cacheTerminalTaskView(n,t),t.executor?.lifecycle===`terminal`&&(n=removeTaskAgentAddressFromState(n,t.metadata.agentId));return n===t.state?e.sessionState:{...e.sessionState,snapshot:{session:{...t,state:n},version:e.sessionState.version}}}export{acceptTaskAuthorizationEventStep,recordTaskInputRequestStep,recordTerminalTaskViewsStep};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { TaskRunWorkflowInput } from "#execution/tasks/child/workflow.js";
|
|
2
|
+
import { type TaskCommand, type TaskRunInboundPayload, type TaskView } from "#tasks/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Node-side controls for durable task runs — the generic transport layer.
|
|
5
|
+
* This module only speaks `TaskCommand`/`TaskView`; it knows nothing about
|
|
6
|
+
* subagents, receipts, or the session index. Caller-specific policy (e.g.
|
|
7
|
+
* subagent delegation in `delegate.ts`) composes these primitives.
|
|
8
|
+
*
|
|
9
|
+
* Every export must be called from inside a `"use step"` body; none of
|
|
10
|
+
* these are steps themselves so dispatch and tool steps can compose them
|
|
11
|
+
* inside one durable boundary.
|
|
12
|
+
*/
|
|
13
|
+
/** Starts the durable run owning one task's lifecycle. */
|
|
14
|
+
export declare function startTaskRun(input: TaskRunWorkflowInput): Promise<void>;
|
|
15
|
+
/** Resolves the task run that won ownership of one replay-stable command token. */
|
|
16
|
+
export declare function waitForTaskCommandOwner(input: {
|
|
17
|
+
readonly taskInboxToken: string;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
readonly runId: string;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Submits one command to a task run.
|
|
23
|
+
*
|
|
24
|
+
* `unreachable` means the hook is not resumable — either the run
|
|
25
|
+
* already finished and disposed it (the task is terminal; read the
|
|
26
|
+
* final view) or, right after creation, the freshly started run has
|
|
27
|
+
* not registered it yet. Senders racing that startup window pass
|
|
28
|
+
* `retryUnreachable`; senders addressing an established task treat
|
|
29
|
+
* `unreachable` as the terminal signal.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sendTaskCommand(input: {
|
|
32
|
+
readonly command: TaskCommand;
|
|
33
|
+
readonly taskInboxToken: string;
|
|
34
|
+
readonly retryUnreachable?: {
|
|
35
|
+
readonly attempts: number;
|
|
36
|
+
readonly delayMs: number;
|
|
37
|
+
};
|
|
38
|
+
}): Promise<"delivered" | "unreachable">;
|
|
39
|
+
/** Delivers one command and returns the accepting task workflow's run id. */
|
|
40
|
+
export declare function sendTaskCommandToOwner(input: {
|
|
41
|
+
readonly command: TaskCommand;
|
|
42
|
+
readonly taskInboxToken: string;
|
|
43
|
+
readonly retryUnreachable?: {
|
|
44
|
+
readonly attempts: number;
|
|
45
|
+
readonly delayMs: number;
|
|
46
|
+
};
|
|
47
|
+
}): Promise<{
|
|
48
|
+
readonly runId: string;
|
|
49
|
+
} | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Hands one non-command inbound payload to a task run.
|
|
52
|
+
*
|
|
53
|
+
* Used for payloads the run must act on before it may record them —
|
|
54
|
+
* today only answered input batches, which it forwards to the child
|
|
55
|
+
* first. `unreachable` means the task already finished and disposed its
|
|
56
|
+
* hook, so the payload is stale by definition.
|
|
57
|
+
*/
|
|
58
|
+
export declare function sendTaskInboundPayload(input: {
|
|
59
|
+
readonly taskInboxToken: string;
|
|
60
|
+
readonly payload: TaskRunInboundPayload;
|
|
61
|
+
}): Promise<"delivered" | "unreachable">;
|
|
62
|
+
/**
|
|
63
|
+
* Reads the latest view a task run has published, or `undefined`
|
|
64
|
+
* when the run has not committed its first view yet (the caller
|
|
65
|
+
* already holds the creation receipt, which is `working`).
|
|
66
|
+
*
|
|
67
|
+
* Views are trusted without re-validation: the task run is the
|
|
68
|
+
* single writer and every write passed the transition function.
|
|
69
|
+
*/
|
|
70
|
+
export declare function readLatestTaskView(input: {
|
|
71
|
+
readonly taskRunId: string;
|
|
72
|
+
}): Promise<TaskView | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{startWorkflowPreferLatest,taskRunWorkflowReference,waitForCommandHookOwner}from"#execution/workflow-runtime.js";import{getRun,resumeHook}from"#internal/workflow/runtime.js";import{isTaskWorkflowTargetGone}from"#execution/tasks/workflow-target.js";import{TASK_VIEW_STREAM_NAMESPACE}from"#tasks/types.js";const TASK_VIEW_READ_TIMEOUT_MS=1e4;async function startTaskRun(n){await startWorkflowPreferLatest(taskRunWorkflowReference,[n])}async function waitForTaskCommandOwner(e){return await waitForCommandHookOwner(e.taskInboxToken)}async function sendTaskCommand(e){return await sendTaskCommandToOwner(e)===void 0?`unreachable`:`delivered`}async function sendTaskCommandToOwner(e){let t={command:e.command,kind:`task-command`},n=Math.max(1,e.retryUnreachable?.attempts??1);for(let r=0;;r+=1)try{let n=await resumeHook(e.taskInboxToken,t);if(typeof n!=`object`||!n||!(`runId`in n)||typeof n.runId!=`string`)throw Error(`Task inbox hook "${e.taskInboxToken}" returned no owner run id.`);return{runId:n.runId}}catch(t){if(!isTaskWorkflowTargetGone(t))throw t;if(r+1>=n)return;await new Promise(t=>setTimeout(t,e.retryUnreachable?.delayMs??250))}}async function sendTaskInboundPayload(e){try{return await resumeHook(e.taskInboxToken,e.payload),`delivered`}catch(e){if(!isTaskWorkflowTargetGone(e))throw e;return`unreachable`}}async function readLatestTaskView(e){let t=getRun(e.taskRunId).getReadable({namespace:TASK_VIEW_STREAM_NAMESPACE,startIndex:-1}),n=await t.getTailIndex(),i=t.getReader();try{return n<0?void 0:await readWithTimeout(i,`latest task view`)}finally{await i.cancel(`eve task view read complete`).catch(()=>{}),i.releaseLock()}}async function readWithTimeout(e,t){let n;try{let r=await Promise.race([e.read().then(e=>({kind:`read`,read:e})),new Promise(e=>{n=setTimeout(()=>e({kind:`timeout`}),TASK_VIEW_READ_TIMEOUT_MS)})]);if(r.kind===`timeout`)throw Error(`Timed out reading ${t} after ${TASK_VIEW_READ_TIMEOUT_MS}ms.`);return r.read.done?void 0:r.read.value}finally{n!==void 0&&clearTimeout(n)}}export{readLatestTaskView,sendTaskCommand,sendTaskCommandToOwner,sendTaskInboundPayload,startTaskRun,waitForTaskCommandOwner};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RuntimeSession } from "#execution/agent-handle-dispatch.js";
|
|
2
|
+
import { type DelegatedTask } from "#execution/tasks/parent/delegate.js";
|
|
3
|
+
import type { RuntimeActionResult, RuntimeToolCallActionRequest } from "#runtime/actions/types.js";
|
|
4
|
+
import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
|
|
5
|
+
/**
|
|
6
|
+
* Routes one `task_send`:
|
|
7
|
+
*
|
|
8
|
+
* - `working` tasks are busy — the send surfaces `AGENT_BUSY` instead
|
|
9
|
+
* of queueing (settled decision; queueing is the reversible follow-up);
|
|
10
|
+
* - `input_required` tasks reject model-authored sends; clients answer
|
|
11
|
+
* them through the parent channel's direct HITL route;
|
|
12
|
+
* - terminal tasks accept a `message` follow-up, which starts a new
|
|
13
|
+
* task bound to the same child session and returns its receipt.
|
|
14
|
+
*/
|
|
15
|
+
export declare function executeTaskSend(input: {
|
|
16
|
+
readonly action: RuntimeToolCallActionRequest;
|
|
17
|
+
readonly bundle: CompiledBundle;
|
|
18
|
+
readonly parentStepIndex?: number;
|
|
19
|
+
readonly parentTurnId: string;
|
|
20
|
+
readonly session: RuntimeSession;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
readonly result: RuntimeActionResult;
|
|
23
|
+
readonly session: RuntimeSession;
|
|
24
|
+
readonly pendingTask?: DelegatedTask;
|
|
25
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{AGENT_BUSY,AGENT_UNREACHABLE}from"#harness/agent-handle-errors.js";import{dispatchToTaskAgentAddress}from"#execution/agent-handle-dispatch.js";import{findSessionTaskEntry}from"#tasks/session-index.js";import{createTaskControlError,createUnknownTasksError,findActiveTaskForAgent,findTaskAgentAddress,readTaskView}from"#execution/tasks/parent/control-shared.js";import{beginDelegatedTask,failDelegatedDispatch,settleDelegatedDispatch}from"#execution/tasks/parent/delegate.js";async function executeTaskSend(t){let{action:n,session:a}=t,o=readTaskSendInput(n.input);if(o.kind===`invalid`)return{result:createTaskControlError(n,o.message),session:a};let c=findSessionTaskEntry(a.state,o.taskId);if(c===void 0)return{result:createUnknownTasksError(n,[o.taskId]),session:a};let l=await readTaskView(c);return l.status===`working`?{result:createTaskControlError(n,`${AGENT_BUSY}: task "${l.taskId}" is still working. Let it finish, or cancel it first.`),session:a}:l.status===`input_required`?{result:createTaskControlError(n,`Task "${l.taskId}" is waiting on input; the human must answer through the parent channel.`),session:a}:followUpTerminalTask({action:n,bundle:t.bundle,message:o.message,parentStepIndex:t.parentStepIndex,parentTurnId:t.parentTurnId,session:a,view:l})}async function followUpTerminalTask(r){let{action:i,view:s}=r,u=await findActiveTaskForAgent(r.session,s.metadata.agentId,r.parentTurnId,r.parentStepIndex);if(u!==void 0)return{result:createTaskControlError(i,`${AGENT_BUSY}: agent "${s.metadata.agentId}" is busy with task "${u.view.taskId}" (${u.view.status}).`),session:r.session};let d=findTaskAgentAddress(r.session,s.metadata.agentId);if(d===void 0)return{result:createTaskControlError(i,`${AGENT_UNREACHABLE}: task "${s.taskId}"'s agent is no longer addressable.`),session:r.session};let f=d.address.kind===`agent/remote`?{callId:i.callId,description:``,input:{message:r.message},kind:`remote-agent-call`,name:d.identity.name,nodeId:d.identity.nodeId,remoteAgentName:d.identity.name}:{callId:i.callId,description:``,input:{message:r.message},kind:`subagent-call`,name:d.identity.name,nodeId:d.identity.nodeId,subagentName:d.identity.name},p=await beginDelegatedTask({agentId:d.identity.id,callId:i.callId,mode:d.address.kind===`agent/remote`?`remote`:`local`,name:d.identity.name,parentSessionId:r.session.sessionId,parentStepIndex:r.parentStepIndex,parentTurnId:r.parentTurnId,session:r.session}),m=await settleDelegatedDispatch({callId:i.callId,session:r.session,subagentName:d.identity.name,task:p}),h=await dispatchToTaskAgentAddress({action:f,agentId:d.identity.id,bundle:r.bundle,currentSession:m.session,parentToken:p.taskInboxToken});return h.kind===`error`?(h.deliveryAmbiguous!==!0&&await failDelegatedDispatch({error:h.result.output,task:p}),{result:{callId:i.callId,isError:!0,kind:`tool-result`,output:{error:h.result.output,taskId:p.taskId},toolName:i.toolName},session:h.session,pendingTask:p}):{result:{callId:i.callId,kind:`tool-result`,output:{agentId:p.metadata.agentId,status:`working`,taskId:p.taskId},toolName:i.toolName},session:h.session,pendingTask:p}}function readTaskSendInput(e){let t=typeof e.taskId==`string`&&e.taskId.trim()!==``?e.taskId:void 0;if(t===void 0)return{kind:`invalid`,message:"Provide the `taskId` from a task receipt."};let n=typeof e.message==`string`&&e.message.trim()!==``?e.message:void 0;return n===void 0?{kind:`invalid`,message:"Provide a non-empty `message`."}:{kind:`send`,message:n,taskId:t}}export{executeTaskSend};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{walkCauseChain}from"#shared/errors.js";import{EntityConflictError,HookNotFoundError,RunExpiredError,WorkflowRunNotFoundError}from"#compiled/@workflow/errors/index.js";function isTaskWorkflowTargetGone(e){for(let t of walkCauseChain(e))if(HookNotFoundError.is(t)||WorkflowRunNotFoundError.is(t)||RunExpiredError.is(t)||EntityConflictError.is(t))return!0;return!1}export{isTaskWorkflowTargetGone};
|
|
@@ -11,5 +11,6 @@ import { type DurableSessionState } from "#execution/durable-session-store.js";
|
|
|
11
11
|
* remote-termination protocol exists.
|
|
12
12
|
*/
|
|
13
13
|
export declare function terminateChildSessionsStep(input: {
|
|
14
|
+
readonly serializedContext?: Record<string, unknown>;
|
|
14
15
|
readonly sessionState: DurableSessionState;
|
|
15
16
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger,logError}from"#internal/logging.js";import{readDurableSession}from"#execution/durable-session-store.js";import{
|
|
1
|
+
import{createLogger,logError}from"#internal/logging.js";import{BundleKey}from"#runtime/sessions/runtime-context-keys.js";import{getAgentHandleStore}from"#harness/handles/store.js";import{deserializeContext}from"#context/serialize.js";import{readDurableSession}from"#execution/durable-session-store.js";import{hydrateDurableSession}from"#execution/session.js";import{resolveEffectiveAgentRuntime}from"#execution/effective-agent-config.js";import{cancelRun,getWorld}from"#internal/workflow/runtime.js";import{cancelOwnedTask}from"#execution/tasks/parent/dispatch.js";import{getSessionTaskIndex}from"#tasks/session-index.js";const log=createLogger(`execution.terminate-child-sessions`);async function terminateChildSessionsStep(e){"use step";let s;try{s=await readDurableSession(e.sessionState)}catch(n){logError(log,`failed to read child sessions for termination`,n,{parentSessionId:e.sessionState.sessionId});return}let c=readSessionTaskIndex(s.state,s.sessionId);if(c.length>0){if(e.serializedContext===void 0)throw Error(`Task finalization requires serialized runtime context.`);let r=await deserializeContext(e.serializedContext),i=r.require(BundleKey),a=resolveEffectiveAgentRuntime(i,r),o=hydrateDurableSession({durable:s,turnAgent:a.turnAgent});for(let e of c)try{await cancelOwnedTask({bundle:i,entry:e,session:o})}catch(n){logError(log,`failed to cancel task during parent finalization`,n,{parentSessionId:s.sessionId,taskId:e.taskId})}}let l=(getAgentHandleStore(s.state)?.handles??[]).filter(isLocalChildHandle);if(l.length!==0)for(let e of l){if(e.phase===`starting`){log.debug(`skipping starting child without a session id`,{agentId:e.identity.id,kind:e.target.kind,parentSessionId:s.sessionId});continue}try{await cancelRun(await getWorld(),e.address.sessionId,{cancelReason:`Parent session ended`})}catch(n){logError(log,`failed to terminate child session`,n,{agentId:e.identity.id,childSessionId:e.address.sessionId,kind:e.address.kind,parentSessionId:s.sessionId})}}}function isLocalChildHandle(e){let t=e.phase===`starting`?e.target.kind:e.address.kind;return t===`agent/local`||t===`agent/self`}function readSessionTaskIndex(e,n){try{return getSessionTaskIndex(e)}catch(e){return logError(log,`failed to read the task index during parent finalization`,e,{parentSessionId:n}),[]}}export{terminateChildSessionsStep};
|
|
@@ -9,11 +9,17 @@ export declare class TurnControlReceiver {
|
|
|
9
9
|
private readonly commandInbox;
|
|
10
10
|
private readonly control;
|
|
11
11
|
private readonly controlIterator;
|
|
12
|
+
private readonly expectedTurnId;
|
|
13
|
+
private readonly cancelledTaskIds;
|
|
14
|
+
private readonly seenTaskDeliveries;
|
|
12
15
|
private pendingControl;
|
|
13
16
|
constructor(input: {
|
|
14
17
|
readonly bufferedDeliveries: DeliverHookPayload[];
|
|
15
18
|
readonly bufferedSessionControls: Array<"clear" | "compact" | "expired" | "reset">;
|
|
19
|
+
readonly cancelledTaskIds?: Set<string>;
|
|
16
20
|
readonly commandInbox: SessionCommandInbox;
|
|
21
|
+
readonly expectedTurnId: string;
|
|
22
|
+
readonly seenTaskDeliveries?: Set<string>;
|
|
17
23
|
readonly token: string;
|
|
18
24
|
});
|
|
19
25
|
/** Token passed to the turn workflow so it can publish control messages. */
|
|
@@ -38,4 +44,8 @@ export declare class TurnControlReceiver {
|
|
|
38
44
|
* accepted by the turn and ahead of deliveries that arrived later.
|
|
39
45
|
*/
|
|
40
46
|
private awaitForwardedDelivery;
|
|
47
|
+
private acceptTaskDelivery;
|
|
48
|
+
private discardTaskDeliveries;
|
|
49
|
+
private originatesFromCancelledTask;
|
|
50
|
+
private shouldDiscard;
|
|
41
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sendCommandToDelivery}from"#execution/session-command-wire.js";import{createHook}from"#compiled/@workflow/core/index.js";import{closeHookIterator,disposeHook}from"#execution/hook-ownership.js";import{turnCancellationHookToken}from"#execution/turn-cancellation-token.js";import{forwardTurnCancellationStep}from"#execution/forward-turn-cancellation-step.js";import{forwardTurnDeliveryStep}from"#execution/forward-turn-delivery-step.js";import{rebuildSerializableError}from"#execution/workflow-errors.js";var TurnControlReceiver=class{bufferedDeliveries;bufferedSessionControls;commandInbox;control;controlIterator;pendingControl=null;constructor(e){this.bufferedDeliveries=e.bufferedDeliveries,this.bufferedSessionControls=e.bufferedSessionControls,this.commandInbox=e.commandInbox,this.control=createHook({token:e.token}),this.controlIterator=this.control[Symbol.asyncIterator]()}get token(){return this.control.token}async dispose(){await closeHookIterator(this.controlIterator),await disposeHook(this.control)}async waitForAction(){for(;;){let e=await this.nextControlOrCommand();if(e.kind===`command`){let t=await this.handleSessionCommand(e.command);if(t!==void 0)return t;continue}let t=e.payload,n=this.readTerminalControl(t);if(n!==void 0)return n;if(t.kind===`turn-delivery-request`){let e=await this.serviceDeliveryRequest(t);if(e!==void 0)return e}}}async handleSessionCommand(t){if(t.kind===`deliver`){await this.bufferDelivery(t);return}if(t.kind===`send`){await this.bufferDelivery(sendCommandToDelivery(t));return}if(t.kind===`clear`||t.kind===`compact`){this.bufferedSessionControls.push(t.kind);return}if(t.kind===`session-timeout`){this.bufferedSessionControls.push(`expired`);return}if(t.kind!==`runtime-action-result`){if(t.kind===`cancel`){await forwardTurnCancellationStep({payload:
|
|
1
|
+
import{sendCommandToDelivery}from"#execution/session-command-wire.js";import{createHook}from"#compiled/@workflow/core/index.js";import{closeHookIterator,disposeHook}from"#execution/hook-ownership.js";import{turnCancellationHookToken}from"#execution/turn-cancellation-token.js";import{forwardTurnCancellationStep}from"#execution/forward-turn-cancellation-step.js";import{forwardTurnDeliveryStep}from"#execution/forward-turn-delivery-step.js";import{rebuildSerializableError}from"#execution/workflow-errors.js";var TurnControlReceiver=class{bufferedDeliveries;bufferedSessionControls;commandInbox;control;controlIterator;expectedTurnId;cancelledTaskIds;seenTaskDeliveries;pendingControl=null;constructor(e){this.bufferedDeliveries=e.bufferedDeliveries,this.bufferedSessionControls=e.bufferedSessionControls,this.cancelledTaskIds=e.cancelledTaskIds??new Set,this.commandInbox=e.commandInbox,this.seenTaskDeliveries=e.seenTaskDeliveries??new Set,this.control=createHook({token:e.token}),this.controlIterator=this.control[Symbol.asyncIterator](),this.expectedTurnId=e.expectedTurnId}get token(){return this.control.token}async dispose(){await closeHookIterator(this.controlIterator),await disposeHook(this.control)}async waitForAction(){for(;;){let e=await this.nextControlOrCommand();if(e.kind===`command`){let t=await this.handleSessionCommand(e.command);if(t!==void 0)return t;continue}let t=e.payload,n=this.readTerminalControl(t);if(n!==void 0)return n;if(t.kind===`turn-delivery-request`){let e=await this.serviceDeliveryRequest(t);if(e!==void 0)return e}}}async handleSessionCommand(t){if(t.kind===`deliver`){if(!this.acceptTaskDelivery(t))return;await this.bufferDelivery(t);return}if(t.kind===`send`){if(!this.acceptTaskDelivery(t))return;await this.bufferDelivery(sendCommandToDelivery(t));return}if(t.kind===`clear`||t.kind===`compact`){this.bufferedSessionControls.push(t.kind);return}if(t.kind===`session-timeout`){this.bufferedSessionControls.push(`expired`);return}if(t.kind!==`runtime-action-result`){if(t.kind===`cancel`){t.taskId!==void 0&&this.discardTaskDeliveries(t.taskId);let e=t.taskId!==void 0&&t.turnId!==void 0&&t.turnId!==this.expectedTurnId?void 0:t.turnId;await forwardTurnCancellationStep({payload:e===void 0?{}:{turnId:e},token:turnCancellationHookToken(this.control.token)});return}if(t.kind===`reset`){await forwardTurnCancellationStep({payload:{},token:turnCancellationHookToken(this.control.token)}),this.bufferedSessionControls.push(`reset`);return}return unsupportedSessionCommand(t)}}async bufferDelivery(e){this.bufferedDeliveries.push(e),!(e.turnPolicy!==`steer`||!deliveryHasMessage(e))&&await forwardTurnCancellationStep({payload:{},token:turnCancellationHookToken(this.control.token)})}bufferTurnDeliveries(e){e.bufferedDeliveries!==void 0&&this.bufferedDeliveries.unshift(...e.bufferedDeliveries.filter(e=>!this.shouldDiscard(e)))}consumeControl(){this.pendingControl=null}getControlPromise(){return this.pendingControl??=this.controlIterator.next(),this.pendingControl}async nextControlOrCommand(){let e=await Promise.race([this.getControlPromise().then(e=>({kind:`control`,value:e})),this.commandInbox.next().then(e=>({kind:`command`,value:e}))]);if(e.kind===`command`){if(e.value.done)throw Error(`Session command inbox closed before the active turn settled.`);return this.commandInbox.consumeNext(),{command:e.value.value,kind:`command`}}if(this.consumeControl(),e.value.done)throw Error(`Turn control hook closed before delivering a result.`);let t=e.value.value;if(t.kind===`turn-error`)throw rebuildSerializableError(t.error);return t.kind===`turn-continuation-token`?(await this.commandInbox.rekeyContinuation(t.continuationToken),await this.nextControlOrCommand()):{kind:`control`,payload:t}}readTerminalControl(e){if(e.kind===`turn-error`)throw rebuildSerializableError(e.error);if(e.kind===`turn-result`)return this.bufferTurnDeliveries(e),e.action}async serviceDeliveryRequest(t){await this.commandInbox.rekeyContinuation(t.continuationToken);let n=this.takeInputResponseDelivery();for(;n===void 0;){let r=await Promise.race([this.getControlPromise().then(e=>({kind:`control`,value:e})),this.commandInbox.next().then(e=>({kind:`command`,value:e}))]);if(r.kind===`control`){if(this.consumeControl(),r.value.done)throw Error(`Turn control hook closed during a delivery request.`);if(r.value.value.kind===`turn-continuation-token`){await this.commandInbox.rekeyContinuation(r.value.value.continuationToken);continue}let e=this.readTerminalControl(r.value.value);if(e!==void 0)return e;if(r.value.value.kind===`turn-delivery-cancelled`&&r.value.value.requestId===t.requestId)return;continue}if(r.value.done)throw Error(`Session command inbox closed during a turn delivery request.`);if(this.commandInbox.consumeNext(),r.value.value.kind===`deliver`){if(!this.acceptTaskDelivery(r.value.value))continue;deliveryHasMessage(r.value.value)?await this.bufferDelivery(r.value.value):n=r.value.value;continue}if(r.value.value.kind===`send`){if(!this.acceptTaskDelivery(r.value.value))continue;let t=sendCommandToDelivery(r.value.value);deliveryHasMessage(t)?await this.bufferDelivery(t):n=t;continue}let i=await this.handleSessionCommand(r.value.value);if(i!==void 0)return i}try{await forwardTurnDeliveryStep({inboxToken:t.inboxToken,payload:{delivery:n,kind:`driver-delivery`,requestId:t.requestId}})}catch(e){if(!(e instanceof Error&&e.name===`HookNotFoundError`))throw e}return await this.awaitForwardedDelivery(t.requestId,n)}takeInputResponseDelivery(){let e=this.bufferedDeliveries.findIndex(e=>!deliveryHasMessage(e));if(e!==-1)return this.bufferedDeliveries.splice(e,1)[0]}async awaitForwardedDelivery(e,t){for(;;){let n=await this.nextControlOrCommand();if(n.kind===`command`){let e=await this.handleSessionCommand(n.command);if(e!==void 0)return this.shouldDiscard(t)||this.bufferedDeliveries.unshift(t),e;continue}let r=n.payload;if(r.kind===`turn-delivery-accepted`){if(r.requestId===e)return;continue}if(r.kind===`turn-delivery-cancelled`&&r.requestId===e){this.shouldDiscard(t)||this.bufferedDeliveries.unshift(t);return}r.kind===`turn-result`&&(this.shouldDiscard(t)||this.bufferedDeliveries.unshift(t));let i=this.readTerminalControl(r);if(i!==void 0)return i}}acceptTaskDelivery(e){let t=e.taskDeliveryId??e.caller?.taskId;return t===void 0?!0:this.originatesFromCancelledTask(t)||this.seenTaskDeliveries.has(t)?!1:(this.seenTaskDeliveries.add(t),!0)}discardTaskDeliveries(e){this.cancelledTaskIds.add(e);let t=this.bufferedDeliveries.filter(e=>!this.shouldDiscard(e));this.bufferedDeliveries.splice(0,this.bufferedDeliveries.length,...t)}originatesFromCancelledTask(e){return[...this.cancelledTaskIds].some(t=>deliveryOriginatesFromTask(e,t))}shouldDiscard(e){let t=e.taskDeliveryId??e.caller?.taskId;return t!==void 0&&this.originatesFromCancelledTask(t)}};function deliveryOriginatesFromTask(e,t){return e===t||e.startsWith(`${t}:`)}function deliveryHasMessage(e){return e.payloads.some(e=>e.message!==void 0)}function unsupportedSessionCommand(e){throw Error(`Unsupported session command: ${JSON.stringify(e)}`)}export{TurnControlReceiver};
|
|
@@ -21,11 +21,13 @@ export declare function dispatchAndAwaitTurn(input: {
|
|
|
21
21
|
readonly bufferedDeliveries: DeliverHookPayload[];
|
|
22
22
|
readonly bufferedSessionControls: Array<"clear" | "compact" | "expired" | "reset">;
|
|
23
23
|
readonly capabilities?: SessionCapabilities;
|
|
24
|
+
readonly cancelledTaskIds?: Set<string>;
|
|
24
25
|
readonly controlToken: string;
|
|
25
26
|
readonly delivery: HookPayload;
|
|
26
27
|
readonly commandInbox: SessionCommandInbox;
|
|
27
28
|
readonly mode: RunMode;
|
|
28
29
|
readonly parentWritable: WritableStream<Uint8Array>;
|
|
29
30
|
readonly serializedContext: Record<string, unknown>;
|
|
31
|
+
readonly seenTaskDeliveries?: Set<string>;
|
|
30
32
|
readonly sessionState: DurableSessionState;
|
|
31
33
|
}): Promise<DispatchedTurn>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dispatchTurnStep}from"#execution/dispatch-turn-step.js";import{TurnControlReceiver}from"#execution/turn-control-receiver.js";async function dispatchAndAwaitTurn(t){let n=new TurnControlReceiver({bufferedDeliveries:t.bufferedDeliveries,bufferedSessionControls:t.bufferedSessionControls,commandInbox:t.commandInbox,token:t.controlToken});try{return await dispatchTurnStep({capabilities:t.capabilities,completionToken:n.token,delivery:t.delivery,mode:t.mode,parentWritable:t.parentWritable,serializedContext:t.serializedContext,sessionState:t.sessionState}),{action:await n.waitForAction(),dispose:()=>n.dispose()}}catch(e){throw await n.dispose(),e}}export{dispatchAndAwaitTurn};
|
|
1
|
+
import{activeTurnId}from"#harness/active-turn-id.js";import{dispatchTurnStep}from"#execution/dispatch-turn-step.js";import{TurnControlReceiver}from"#execution/turn-control-receiver.js";async function dispatchAndAwaitTurn(t){let n=new TurnControlReceiver({bufferedDeliveries:t.bufferedDeliveries,bufferedSessionControls:t.bufferedSessionControls,cancelledTaskIds:t.cancelledTaskIds,commandInbox:t.commandInbox,expectedTurnId:activeTurnId(t.sessionState.emissionState),seenTaskDeliveries:t.seenTaskDeliveries??new Set,token:t.controlToken});try{return await dispatchTurnStep({capabilities:t.capabilities,completionToken:n.token,delivery:t.delivery,mode:t.mode,parentWritable:t.parentWritable,serializedContext:t.serializedContext,sessionState:t.sessionState}),{action:await n.waitForAction(),dispose:()=>n.dispose()}}catch(e){throw await n.dispose(),e}}export{dispatchAndAwaitTurn};
|
|
@@ -2,6 +2,7 @@ import type { DeliverHookPayload } from "#channel/types.js";
|
|
|
2
2
|
import type { TurnControlPayload } from "#execution/turn-control-protocol.js";
|
|
3
3
|
import type { DurableSessionState } from "#execution/durable-session-store.js";
|
|
4
4
|
import type { TurnStepInput, TurnStepPayload } from "#execution/durable-session-migrations/turn-workflow.js";
|
|
5
|
+
import { SessionStateCursor } from "#execution/session-state-cursor.js";
|
|
5
6
|
import type { SettledTurn } from "#harness/types.js";
|
|
6
7
|
import type { TokenUsage } from "#shared/token-usage.js";
|
|
7
8
|
interface TurnTransition {
|
|
@@ -22,11 +23,9 @@ type TurnTerminalAction = {
|
|
|
22
23
|
readonly settled?: SettledTurn;
|
|
23
24
|
};
|
|
24
25
|
/** Owns the mutable durable state cursor for one active turn workflow. */
|
|
25
|
-
export declare class TurnExecutionCursor {
|
|
26
|
+
export declare class TurnExecutionCursor extends SessionStateCursor {
|
|
26
27
|
readonly controlToken: string;
|
|
27
28
|
readonly parentWritable: WritableStream<Uint8Array>;
|
|
28
|
-
private currentSerializedContext;
|
|
29
|
-
private currentSessionState;
|
|
30
29
|
private lastReportedContinuationToken;
|
|
31
30
|
constructor(input: {
|
|
32
31
|
readonly controlToken: string;
|
|
@@ -34,10 +33,6 @@ export declare class TurnExecutionCursor {
|
|
|
34
33
|
readonly serializedContext: Record<string, unknown>;
|
|
35
34
|
readonly sessionState: DurableSessionState;
|
|
36
35
|
});
|
|
37
|
-
/** Latest serialized runtime context adopted by the active turn. */
|
|
38
|
-
get serializedContext(): Record<string, unknown>;
|
|
39
|
-
/** Latest durable session state adopted by the active turn. */
|
|
40
|
-
get sessionState(): DurableSessionState;
|
|
41
36
|
/** Adopts a state transition and reports any continuation-token change once. */
|
|
42
37
|
adopt(transition: TurnTransition): Promise<void>;
|
|
43
38
|
/** Builds the next atomic turn-step input from the cursor's current state. */
|
|
@@ -50,6 +45,5 @@ export declare class TurnExecutionCursor {
|
|
|
50
45
|
finish(transition: TurnTransition, action: TurnTerminalAction, bufferedDeliveries: readonly DeliverHookPayload[]): Promise<void>;
|
|
51
46
|
/** Sends one control payload to the session driver. */
|
|
52
47
|
send(payload: TurnControlPayload): Promise<void>;
|
|
53
|
-
private setState;
|
|
54
48
|
}
|
|
55
49
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sendTurnControlStep}from"#execution/turn-control-protocol.js";var TurnExecutionCursor=class{controlToken;parentWritable;
|
|
1
|
+
import{sendTurnControlStep}from"#execution/turn-control-protocol.js";import{SessionStateCursor}from"#execution/session-state-cursor.js";var TurnExecutionCursor=class extends SessionStateCursor{controlToken;parentWritable;lastReportedContinuationToken;constructor(e){super({serializedContext:e.serializedContext,sessionState:e.sessionState}),this.controlToken=e.controlToken,this.lastReportedContinuationToken=e.sessionState.continuationToken,this.parentWritable=e.parentWritable}async adopt(e){this.adoptState(e);let t=e.sessionState.continuationToken;t===``||t===this.lastReportedContinuationToken||(this.lastReportedContinuationToken=t,await this.send({continuationToken:t,kind:`turn-continuation-token`}))}createStepInput(e,t){return{abortSignal:t,input:e,parentWritable:this.parentWritable,serializedContext:this.serializedContext,sessionState:this.sessionState}}async finish(e,t,n){this.adoptState(e),await this.send({action:{...t,serializedContext:this.serializedContext,sessionState:this.sessionState},bufferedDeliveries:n.length===0?void 0:[...n],kind:`turn-result`})}async send(t){await sendTurnControlStep({controlToken:this.controlToken,payload:t})}};export{TurnExecutionCursor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveWorkflowCallbackBaseUrl}from"#execution/workflow-callback-url.js";import{
|
|
1
|
+
import{resolveWorkflowCallbackBaseUrl}from"#execution/workflow-callback-url.js";import{migrateTurnWorkflowInput}from"#execution/durable-session-migrations/turn-workflow.js";import{dispatchRuntimeActionsStep}from"#execution/dispatch-runtime-actions-step.js";import{dispatchTaskStep}from"#execution/tasks/parent/dispatch-task-step.js";import{routeDeliverToChildren}from"#execution/route-child-delivery.js";import{runProxySubagentEventStep}from"#execution/subagent-event-proxy-step.js";import{createHook,getWorkflowMetadata,sleep}from"#compiled/@workflow/core/index.js";import{claimHookOwnership,disposeHook,isHookConflictError}from"#execution/hook-ownership.js";import{activeTurnId}from"#harness/active-turn-id.js";import{acknowledgeDelegatedTasksStep}from"#execution/tasks/parent/delegate.js";import{normalizeSerializableError}from"#execution/workflow-errors.js";import{sendTurnControlStep}from"#execution/turn-control-protocol.js";import{isInboxSubagentResultFromRunningHandle}from"#harness/handles/query.js";import{preserveSerializedSessionDynamicModelSelection}from"#context/serialized-dynamic-model-selection.js";import{cancelDescendantTurnsStep}from"#execution/cancel-descendant-turns-step.js";import{dispatchWorkflowRuntimeActionsStep}from"#execution/dispatch-workflow-runtime-actions-step.js";import{createTurnCancellationControl}from"#execution/turn-cancellation-control.js";import{TurnExecutionCursor}from"#execution/turn-execution-cursor.js";import{turnStep}from"#execution/workflow-steps.js";import{getRuntimeActionResultKey}from"#runtime/actions/keys.js";import{resolveRuntimeActionResultsForKeys}from"#runtime/actions/results.js";const TASK_MODE_WAIT_ERROR_MESSAGE="Task mode cannot wait for follow-up input (`next: null`).";async function turnWorkflow(e){"use workflow";let n=migrateTurnWorkflowInput(e);return n.driverCapabilities?.turnInbox===!0?runTurnOwnedWorkflow(n):runLegacyTurnWorkflow(n)}async function runTurnOwnedWorkflow(t){let i=createHook({token:`${t.completionToken}:inbox`}),a=i[Symbol.asyncIterator](),c=new TurnExecutionCursor({controlToken:t.completionToken,parentWritable:t.stepInput.parentWritable,serializedContext:t.stepInput.serializedContext,sessionState:t.stepInput.sessionState}),m=0,nextDeliveryRequestId=()=>`${i.token}:delivery:${String(m++)}`,h=[],g=t.stepInput.input,_=!1,v;try{try{await claimHookOwnership(i),_=!0}catch(e){if(isHookConflictError(e))return;throw e}for(t.driverCapabilities?.cancelledTurnSettle===!0&&(v=await createTurnCancellationControl({controlToken:t.completionToken,expectedTurnId:activeTurnId(t.stepInput.sessionState.emissionState)}));;){let o=await turnStep(c.createStepInput(g,v?.signal)),l=o.action===`dispatch-workflow-runtime-actions`||o.action===`park`?o.pendingRuntimeActionKeys:void 0;if(o.action===`cancelled`){await c.adopt(o),await finishCancelledTurn({bufferedDeliveries:h,cancellation:v,cursor:c});return}if(v?.signal.aborted===!0&&l===void 0){await c.adopt({serializedContext:preserveSerializedSessionDynamicModelSelection(c.serializedContext,o.serializedContext),sessionState:c.sessionState}),await finishCancelledTurn({bufferedDeliveries:h,cancellation:v,cursor:c});return}if(o.sleepDurationMs!==void 0&&await waitForTurnSleep(o.sleepDurationMs,v)===`cancel`){await finishCancelledTurn({bufferedDeliveries:h,cancellation:v,cursor:c});return}if(o.action===`done`){await v?.dispose(),await c.finish(o,{kind:`done`,output:o.output??``,isError:o.isError,usage:o.usage,usageDelta:o.usageDelta},h);return}if(l!==void 0){await c.adopt(o);let t=o.action===`park`&&o.tasksEnabled,u;u=o.action===`dispatch-workflow-runtime-actions`?dispatchWorkflowRuntimeActionsStep:t?dispatchTaskStep:dispatchRuntimeActionsStep;let d=await u({callbackBaseUrl:resolveWorkflowCallbackBaseUrl(getWorkflowMetadata().url),parentContinuationToken:i.token,parentWritable:c.parentWritable,serializedContext:c.serializedContext,sessionState:c.sessionState}),f=d.results.length===0?void 0:Date.now();await c.adopt(d),await acknowledgeDelegatedTasksStep({tasks:d.pendingTasks});let p=await waitForRuntimeActionResults({bufferedDeliveries:h,cancellation:v,cursor:c,inboxToken:i.token,initialAcceptedAtMs:f,initialResults:d.results,iterator:a,nextDeliveryRequestId,pendingActionKeys:l});if(p===`cancelled`){g=void 0;continue}if(p===`cancel-turn`){await finishCancelledTurn({bufferedDeliveries:h,cancellation:v,cursor:c});return}g={kind:`runtime-action-result`,...p};continue}if(o.action===`park`){if(!(o.hasPendingAuthorization||o.hasPendingInputBatch&&t.capabilities?.requestInput===!0||t.mode===`conversation`))throw Error(TASK_MODE_WAIT_ERROR_MESSAGE);await v?.dispose(),await c.finish(o,{authorizationAttemptIds:o.authorizationAttemptIds,authorizationNames:o.authorizationNames,kind:`park`,settled:o.settled},h);return}await c.adopt(o),g=void 0}}catch(e){throw await c.send({error:normalizeSerializableError(e),kind:`turn-error`}),e}finally{v!==void 0&&await v.dispose(),_&&await disposeHook(i)}}async function finishCancelledTurn(e){await cancelDescendantTurnsStep({serializedContext:e.cursor.serializedContext,sessionState:e.cursor.sessionState}),await e.cancellation?.dispose(),await e.cursor.finish({sessionState:e.cursor.sessionState},{cancelled:!0,kind:`park`},e.bufferedDeliveries)}async function waitForTurnSleep(e,t){if(t?.signal.aborted===!0)return`cancel`;let n=sleep(e).then(()=>`slept`);return t===void 0?n:Promise.race([n,t.requested])}async function waitForRuntimeActionResults(e){let t,n=[...e.initialResults],r=new Map;if(e.initialAcceptedAtMs!==void 0)for(let t of e.initialResults)r.set(getRuntimeActionResultKey(t),e.initialAcceptedAtMs);for(;;){let o=resolveRuntimeActionResultsForKeys({pendingKeys:e.pendingActionKeys,results:n});if(o!==void 0)return t!==void 0&&await e.cursor.send({kind:`turn-delivery-cancelled`,requestId:t}),{acceptedAtMsByCallId:Object.fromEntries(o.map(e=>[e.callId,r.get(getRuntimeActionResultKey(e))])),results:o};e.cursor.sessionState.hasProxyInputRequests&&t===void 0&&(t=e.nextDeliveryRequestId(),await e.cursor.send({continuationToken:e.cursor.sessionState.continuationToken,inboxToken:e.inboxToken,kind:`turn-delivery-request`,requestId:t}));let s=e.iterator.next();s.catch(()=>{});let c=await(e.cancellation===void 0?s:Promise.race([s,e.cancellation.requested]));if(c===`cancel`)return t!==void 0&&await e.cursor.send({kind:`turn-delivery-cancelled`,requestId:t}),`cancelled`;if(c.done)throw Error(`Turn inbox closed before runtime actions completed.`);let l=c.value;if(l.kind===`runtime-action-result`){let t=e.cursor.sessionState.snapshot?.session.state,i=l.results.filter(e=>isInboxSubagentResultFromRunningHandle(t,e));if(i.length>0){let e=Date.now();n.push(...i);for(let t of i)r.set(getRuntimeActionResultKey(t),e)}continue}if(l.kind===`subagent-input-request`||l.kind===`subagent-authorization-event`){let t=await runProxySubagentEventStep({hookPayload:l,parentWritable:e.cursor.parentWritable,serializedContext:e.cursor.serializedContext,sessionState:e.cursor.sessionState});await e.cursor.adopt(t);continue}if(l.kind===`driver-delivery`&&l.requestId===t){await e.cursor.send({kind:`turn-delivery-accepted`,requestId:l.requestId}),t=void 0;let n=await routeDeliverToChildren({delivery:l.delivery,parentWritable:e.cursor.parentWritable,serializedContext:e.cursor.serializedContext,sessionState:e.cursor.sessionState});if(await e.cursor.adopt({serializedContext:n.serializedContext??e.cursor.serializedContext,sessionState:n.sessionState??e.cursor.sessionState}),n.kind===`cancel-turn`)return n.kind;n.remainder!==void 0&&e.bufferedDeliveries.push(n.remainder)}}}async function runLegacyTurnWorkflow(e){let t=e.stepInput;try{for(;;){let n=await turnStep(t);if(n.action!==`cancelled`&&n.sleepDurationMs!==void 0&&await sleep(n.sleepDurationMs),n.action===`done`){await sendTurnControlStep({controlToken:e.completionToken,payload:{action:{kind:`done`,output:n.output??``,isError:n.isError,serializedContext:n.serializedContext,sessionState:n.sessionState,usage:n.usage,usageDelta:n.usageDelta},kind:`turn-result`}});return}if(n.action===`dispatch-workflow-runtime-actions`){await sendTurnControlStep({controlToken:e.completionToken,payload:{action:{kind:`dispatch-workflow-runtime-actions`,pendingActionKeys:n.pendingRuntimeActionKeys,serializedContext:n.serializedContext,sessionState:n.sessionState},kind:`turn-result`}});return}if(n.action===`park`){let t=n.pendingRuntimeActionKeys;if(!(t!==void 0||n.hasPendingAuthorization||n.hasPendingInputBatch&&e.capabilities?.requestInput===!0||e.mode===`conversation`))throw Error(TASK_MODE_WAIT_ERROR_MESSAGE);let r=t===void 0?{kind:`park`,serializedContext:n.serializedContext,sessionState:n.sessionState,authorizationAttemptIds:n.authorizationAttemptIds,authorizationNames:n.authorizationNames,settled:n.settled}:{kind:`dispatch-runtime-actions`,pendingActionKeys:t,serializedContext:n.serializedContext,sessionState:n.sessionState};await sendTurnControlStep({controlToken:e.completionToken,payload:{action:r,kind:`turn-result`}});return}t={input:void 0,parentWritable:t.parentWritable,serializedContext:n.serializedContext,sessionState:n.sessionState}}}catch(t){throw await sendTurnControlStep({controlToken:e.completionToken,payload:{error:normalizeSerializableError(t),kind:`turn-error`}}),t}}export{turnWorkflow};
|