eve 0.50.0 → 0.51.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 +18 -0
- package/dist/src/acp/adapter.js +1 -1
- package/dist/src/channel/types.d.ts +12 -19
- package/dist/src/chunks/{use-eve-agent-DUMU6dap.js → use-eve-agent-B4xN7-fK.js} +4 -4
- package/dist/src/chunks/{use-eve-agent-B5I-k6Ek.js → use-eve-agent-C3vUG5g2.js} +4 -4
- package/dist/src/cli/acp/command.d.ts +1 -1
- package/dist/src/cli/acp/command.js +2 -2
- package/dist/src/cli/agent-command.d.ts +5 -0
- package/dist/src/cli/agent-command.js +1 -0
- package/dist/src/cli/application-command.d.ts +2 -0
- package/dist/src/cli/commands/build.d.ts +1 -1
- package/dist/src/cli/commands/build.js +1 -1
- package/dist/src/cli/commands/deploy.d.ts +2 -0
- package/dist/src/cli/commands/deploy.js +1 -1
- package/dist/src/cli/commands/init-agent-workspace.d.ts +14 -0
- package/dist/src/cli/commands/init-agent-workspace.js +1 -0
- package/dist/src/cli/commands/init-repl.js +1 -1
- package/dist/src/cli/commands/init.d.ts +2 -13
- package/dist/src/cli/commands/init.js +1 -1
- package/dist/src/cli/commands/integration-connect.js +1 -1
- package/dist/src/cli/commands/link.d.ts +2 -0
- package/dist/src/cli/commands/link.js +1 -1
- package/dist/src/cli/commands/preconditions.d.ts +15 -0
- package/dist/src/cli/commands/preconditions.js +1 -1
- package/dist/src/cli/commands/register-integration-commands.d.ts +1 -1
- package/dist/src/cli/commands/register-integration-commands.js +1 -1
- package/dist/src/cli/commands/register-registry-commands.js +2 -2
- package/dist/src/cli/commands/registry.js +1 -1
- package/dist/src/cli/dev/environment.d.ts +1 -1
- package/dist/src/cli/dev/environment.js +1 -1
- package/dist/src/cli/dev/local-server-process.js +1 -1
- package/dist/src/cli/dev/tui/runner.js +1 -1
- package/dist/src/cli/invoke/command.d.ts +1 -1
- package/dist/src/cli/invoke/command.js +1 -1
- package/dist/src/cli/option-parsers.d.ts +1 -0
- package/dist/src/cli/option-parsers.js +1 -1
- package/dist/src/cli/run.js +3 -3
- package/dist/src/client/agent-info-schema.d.ts +0 -1
- package/dist/src/client/agent-info-schema.js +1 -1
- package/dist/src/client/message-action-parts.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +18 -18
- 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-manifest-helpers.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +1 -1
- package/dist/src/context/build-dynamic-tools.js +1 -1
- package/dist/src/context/dynamic-subagent-lifecycle.js +1 -1
- package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
- package/dist/src/context/dynamic-tool-metadata.d.ts +1 -0
- package/dist/src/context/keys.d.ts +0 -3
- package/dist/src/context/keys.js +1 -1
- package/dist/src/discover/project.js +1 -1
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/evals/mock-model.js +1 -1
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/execution/activity-work-id.js +1 -1
- package/dist/src/execution/cancel-descendant-turns-step.js +1 -1
- package/dist/src/execution/channel-context.js +1 -1
- package/dist/src/execution/coordination-dispatch-shared.d.ts +103 -0
- package/dist/src/execution/coordination-dispatch-shared.js +1 -0
- package/dist/src/execution/coordination-dispatch-step.d.ts +7 -0
- package/dist/src/execution/coordination-dispatch-step.js +1 -0
- package/dist/src/execution/create-session-step.d.ts +1 -2
- package/dist/src/execution/create-session-step.js +1 -1
- package/dist/src/execution/deliver-payloads.js +1 -1
- package/dist/src/execution/dispatch-action-failures.d.ts +5 -5
- package/dist/src/execution/dispatch-action-failures.js +1 -1
- package/dist/src/execution/dispatch-start-operation.d.ts +1 -1
- package/dist/src/execution/dispatch-start-operation.js +1 -1
- package/dist/src/execution/durable-session-store.d.ts +1 -1
- package/dist/src/execution/eve-workflow-attributes.d.ts +1 -1
- package/dist/src/execution/inline-turn.js +1 -1
- package/dist/src/execution/next-driver-action.d.ts +7 -10
- package/dist/src/execution/node-step.d.ts +1 -2
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/pending-turn-state.d.ts +1 -2
- package/dist/src/execution/pending-turn-state.js +1 -1
- package/dist/src/execution/proxied-deliver-step.js +1 -1
- package/dist/src/execution/route-child-delivery.js +1 -1
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/session-command-inbox.d.ts +2 -3
- package/dist/src/execution/session.d.ts +1 -1
- package/dist/src/execution/session.js +2 -2
- package/dist/src/execution/settle-cancelled-turn-step.d.ts +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/stable-workflow-names.d.ts +1 -1
- package/dist/src/execution/stable-workflow-names.js +1 -1
- package/dist/src/execution/task-event-callback.js +1 -1
- package/dist/src/execution/tasks/child/steps.d.ts +18 -18
- package/dist/src/execution/tasks/child/steps.js +1 -1
- package/dist/src/execution/tasks/child/update-step.d.ts +6 -0
- package/dist/src/execution/tasks/child/update-step.js +1 -0
- package/dist/src/execution/tasks/child/update.d.ts +7 -10
- package/dist/src/execution/tasks/child/update.js +1 -1
- package/dist/src/execution/tasks/child/workflow.d.ts +21 -29
- package/dist/src/execution/tasks/child/workflow.js +1 -1
- package/dist/src/execution/tasks/parent/control-shared.d.ts +6 -17
- package/dist/src/execution/tasks/parent/control-shared.js +1 -1
- package/dist/src/execution/tasks/parent/delegate.d.ts +15 -50
- package/dist/src/execution/tasks/parent/delegate.js +1 -1
- package/dist/src/execution/tasks/parent/dispatch.d.ts +19 -34
- package/dist/src/execution/tasks/parent/dispatch.js +1 -1
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.d.ts +5 -15
- package/dist/src/execution/tasks/parent/hitl-proxy-steps.js +1 -1
- package/dist/src/execution/tasks/parent/run-parent.d.ts +2 -2
- package/dist/src/execution/tasks/parent/task-cancel.d.ts +11 -0
- package/dist/src/execution/tasks/parent/task-cancel.js +1 -0
- package/dist/src/execution/tasks/parent/tool-execution.d.ts +2 -3
- package/dist/src/execution/tasks/parent/tool-execution.js +1 -1
- package/dist/src/execution/terminate-child-sessions-step.js +1 -1
- package/dist/src/execution/tools/subagent/accept-event-step.d.ts +7 -0
- package/dist/src/execution/tools/subagent/accept-event-step.js +1 -0
- package/dist/src/execution/tools/subagent/emit-called-step.d.ts +9 -0
- package/dist/src/execution/tools/subagent/emit-called-step.js +1 -0
- package/dist/src/execution/tools/subagent/invoke-agent.d.ts +51 -0
- package/dist/src/execution/tools/subagent/invoke-agent.js +1 -0
- package/dist/src/execution/tools/subagent/invoke-preparation.d.ts +37 -0
- package/dist/src/execution/tools/subagent/invoke-preparation.js +1 -0
- package/dist/src/execution/tools/subagent/invoke-step.d.ts +55 -0
- package/dist/src/execution/tools/subagent/invoke-step.js +1 -0
- package/dist/src/execution/tools/subagent/receipt-identity.d.ts +11 -0
- package/dist/src/execution/tools/subagent/receipt-identity.js +1 -0
- package/dist/src/execution/{dispatch-runtime-actions-start.d.ts → tools/subagent/start.d.ts} +17 -5
- package/dist/src/execution/tools/subagent/start.js +1 -0
- package/dist/src/execution/tools/subagent/task-agent-requests.d.ts +24 -0
- package/dist/src/execution/tools/subagent/task-agent-requests.js +1 -0
- package/dist/src/execution/tools/subagent/task-cancel.d.ts +10 -0
- package/dist/src/execution/tools/subagent/task-cancel.js +1 -0
- package/dist/src/execution/tools/tasks.d.ts +10 -0
- package/dist/src/execution/tools/tasks.js +1 -0
- package/dist/src/execution/{tool-run → tools/workflow}/answer.d.ts +1 -1
- package/dist/src/execution/tools/workflow/answer.js +1 -0
- package/dist/src/execution/tools/workflow/ask.d.ts +22 -0
- package/dist/src/execution/tools/workflow/ask.js +1 -0
- package/dist/src/execution/tools/workflow/background.d.ts +18 -0
- package/dist/src/execution/tools/workflow/background.js +1 -0
- package/dist/src/execution/tools/workflow/body.d.ts +25 -0
- package/dist/src/execution/tools/workflow/body.js +1 -0
- package/dist/src/execution/tools/workflow/cancel.d.ts +11 -0
- package/dist/src/execution/tools/workflow/cancel.js +1 -0
- package/dist/src/execution/tools/workflow/emit-workflow-tool-run-report-step.d.ts +7 -0
- package/dist/src/execution/tools/workflow/emit-workflow-tool-run-report-step.js +1 -0
- package/dist/src/execution/tools/workflow/messages.d.ts +88 -0
- package/dist/src/execution/tools/workflow/messages.js +1 -0
- package/dist/src/execution/tools/workflow/owner-inbox.d.ts +13 -0
- package/dist/src/execution/tools/workflow/owner-inbox.js +1 -0
- package/dist/src/execution/tools/workflow/owner.d.ts +13 -0
- package/dist/src/execution/tools/workflow/owner.js +1 -0
- package/dist/src/execution/tools/workflow/run-control.d.ts +18 -0
- package/dist/src/execution/tools/workflow/run-control.js +1 -0
- package/dist/src/execution/tools/workflow/start.d.ts +33 -0
- package/dist/src/execution/tools/workflow/start.js +1 -0
- package/dist/src/execution/tools/workflow/types.d.ts +26 -0
- package/dist/src/execution/tools/workflow/types.js +1 -0
- package/dist/src/execution/tools/workflow/workflow.d.ts +3 -0
- package/dist/src/execution/tools/workflow/workflow.js +1 -0
- package/dist/src/execution/turn-workflow-tool-run.d.ts +16 -0
- package/dist/src/execution/turn-workflow-tool-run.js +1 -0
- package/dist/src/execution/turn-workflow.js +1 -1
- package/dist/src/execution/wire/session-inbox-contract.d.ts +2 -2
- package/dist/src/execution/wire/session-inbox-contract.js +1 -1
- package/dist/src/execution/wire/session-inbox-encoder.d.ts +6 -2
- package/dist/src/execution/wire/session-inbox-encoder.js +1 -1
- package/dist/src/execution/wire/session-inbox-wire.d.ts +3 -3
- package/dist/src/execution/wire/session-inbox-wire.js +1 -1
- package/dist/src/execution/wire/session-inbox-wire.v1.js +1 -1
- package/dist/src/execution/wire/session-inbox-wire.v4.d.ts +267 -0
- package/dist/src/execution/wire/session-inbox-wire.v4.js +1 -0
- package/dist/src/execution/wire/session-inbox-wire.v4.migration.d.ts +3 -0
- package/dist/src/execution/wire/session-inbox-wire.v4.migration.js +1 -0
- package/dist/src/execution/workflow-entry-finalization.d.ts +6 -0
- package/dist/src/execution/workflow-entry-finalization.js +1 -1
- package/dist/src/execution/workflow-entry.d.ts +2 -1
- package/dist/src/execution/workflow-entry.js +1 -1
- package/dist/src/execution/workflow-runtime.d.ts +1 -1
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/framework/sources/registry.js +1 -1
- package/dist/src/harness/advertised-tools.d.ts +1 -7
- package/dist/src/harness/advertised-tools.js +1 -1
- package/dist/src/harness/background-tools.d.ts +8 -2
- package/dist/src/harness/{runtime-actions.d.ts → coordination.d.ts} +40 -27
- package/dist/src/harness/coordination.js +1 -0
- package/dist/src/harness/emission.d.ts +9 -2
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/execute-tool.d.ts +52 -0
- package/dist/src/harness/hitl/session-limit-input-requests.js +1 -1
- package/dist/src/harness/input-requests.js +1 -1
- package/dist/src/harness/proxy-input-requests.d.ts +6 -2
- package/dist/src/harness/stale-input-responses.js +1 -1
- package/dist/src/harness/step-hooks.d.ts +1 -2
- package/dist/src/harness/step-hooks.js +1 -1
- package/dist/src/harness/tool-call-action.js +1 -1
- package/dist/src/harness/tool-call-input-errors.js +1 -1
- package/dist/src/harness/tool-loop.js +2 -2
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/turn-tag-state.d.ts +3 -1
- package/dist/src/harness/types.d.ts +4 -7
- package/dist/src/harness/workflow-interrupt-state.js +1 -1
- package/dist/src/harness/workflow-lifecycle.d.ts +10 -0
- package/dist/src/harness/workflow-lifecycle.js +1 -1
- package/dist/src/harness/workflow-sandbox.d.ts +1 -1
- package/dist/src/harness/workflow-sandbox.js +2 -2
- package/dist/src/harness/workflow-subagent-limit.d.ts +7 -7
- package/dist/src/harness/workflow-subagent-limit.js +1 -1
- package/dist/src/harness/workflow-task-state.d.ts +9 -0
- package/dist/src/harness/workflow-task-state.js +1 -0
- package/dist/src/harness/workflow-tool-runs.d.ts +27 -0
- package/dist/src/harness/workflow-tool-runs.js +1 -0
- package/dist/src/instrumentation/native-events.js +1 -1
- package/dist/src/instrumentation/parent-lineage.js +1 -1
- package/dist/src/internal/agent-name.d.ts +4 -0
- package/dist/src/internal/agent-name.js +1 -0
- package/dist/src/internal/agent-workspace.d.ts +15 -0
- package/dist/src/internal/agent-workspace.js +1 -0
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-definition/core.js +1 -1
- package/dist/src/internal/nitro/host/build-application.js +1 -1
- package/dist/src/internal/nitro/host/start-development-server.js +1 -1
- package/dist/src/internal/nitro/host/start-production-server.js +3 -3
- package/dist/src/internal/nitro/routes/runtime-stack.js +1 -1
- package/dist/src/internal/project-context.d.ts +26 -0
- package/dist/src/internal/project-context.js +1 -0
- package/dist/src/internal/vercel/assemble-eve-services.d.ts +17 -0
- package/dist/src/internal/vercel/assemble-eve-services.js +1 -0
- package/dist/src/internal/vercel/build-agent-workspace.d.ts +3 -0
- package/dist/src/internal/vercel/build-agent-workspace.js +1 -0
- package/dist/src/internal/vercel/build-command.d.ts +4 -0
- package/dist/src/internal/vercel/build-command.js +1 -0
- package/dist/src/internal/vercel/eve-service-contribution.d.ts +27 -0
- package/dist/src/internal/vercel/eve-service-contribution.js +1 -0
- package/dist/src/internal/vercel/vercel-service-config-operations.d.ts +18 -0
- package/dist/src/internal/vercel/vercel-service-config-operations.js +1 -0
- package/dist/src/internal/vercel/vercel-service-name.d.ts +6 -0
- package/dist/src/internal/vercel/vercel-service-name.js +1 -0
- package/dist/src/internal/vercel/vercel-services-config.d.ts +53 -0
- package/dist/src/internal/vercel/vercel-services-config.js +1 -0
- package/dist/src/internal/workflow-bundle/builder.js +1 -1
- package/dist/src/internal/workflow-bundle/workflow-builders.js +1 -1
- package/dist/src/protocol/message.d.ts +2 -0
- package/dist/src/protocol/message.js +1 -1
- package/dist/src/public/channels/slack/action-status.js +1 -1
- package/dist/src/public/memory/file/backends/vercel-blob.js +1 -1
- package/dist/src/public/next/index.js +1 -1
- package/dist/src/public/next/vercel-output-config.js +1 -1
- package/dist/src/public/workflow/index.d.ts +3 -1
- package/dist/src/public/workflow/index.js +1 -1
- package/dist/src/runtime/actions/results.d.ts +3 -3
- package/dist/src/runtime/actions/results.js +1 -1
- package/dist/src/runtime/agent/bootstrap-model-utils.js +1 -1
- package/dist/src/runtime/agent/bootstrap.d.ts +1 -0
- package/dist/src/runtime/agent/bootstrap.js +1 -1
- package/dist/src/runtime/agent/mock-model-adapter.js +1 -1
- package/dist/src/runtime/channels/registry.js +1 -1
- package/dist/src/runtime/prompt/compose.d.ts +0 -1
- 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/sessions/turn.d.ts +16 -1
- package/dist/src/runtime/subagents/registry.js +1 -1
- package/dist/src/runtime/subagents/workflow-reference.d.ts +5 -0
- package/dist/src/runtime/subagents/workflow-reference.js +1 -0
- package/dist/src/runtime/subagents/workflow.d.ts +8 -0
- package/dist/src/runtime/subagents/workflow.js +1 -0
- package/dist/src/runtime/tools/registry.js +1 -1
- package/dist/src/setup/integrations/discord/setup.js +1 -1
- package/dist/src/setup/integrations/file-memory/vercel.js +1 -1
- package/dist/src/setup/integrations/linear/setup.js +1 -1
- package/dist/src/setup/integrations/linq/setup.js +3 -3
- package/dist/src/setup/integrations/shopify/setup.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/scaffold/update/channels.d.ts +4 -12
- package/dist/src/setup/scaffold/update/channels.js +1 -1
- package/dist/src/shared/action-types.d.ts +74 -14
- package/dist/src/shared/action-types.js +1 -1
- package/dist/src/shared/json.js +1 -1
- package/dist/src/shared/workflow-sandbox.d.ts +1 -1
- package/dist/src/{execution/subagent-adapter-state.d.ts → subagents/adapter-state.d.ts} +2 -0
- package/dist/src/{execution/subagent-adapter-state.js → subagents/adapter-state.js} +1 -1
- package/dist/src/subagents/adapter.js +1 -0
- package/dist/src/{harness → subagents}/agent-handle-errors.d.ts +6 -0
- package/dist/src/subagents/agent-handle-errors.js +1 -0
- package/dist/src/subagents/callback-route.js +1 -0
- package/dist/src/subagents/callback-step.js +1 -0
- package/dist/src/{execution/agent-continuation-bundle.d.ts → subagents/continuation-bundle.d.ts} +1 -1
- package/dist/src/subagents/continuation-bundle.js +1 -0
- package/dist/src/{execution/subagent-event-proxy-step.d.ts → subagents/event-proxy-step.d.ts} +2 -8
- package/dist/src/subagents/event-proxy-step.js +1 -0
- package/dist/src/subagents/handle-dispatch.d.ts +54 -0
- package/dist/src/subagents/handle-dispatch.js +1 -0
- package/dist/src/{harness → subagents}/handles/prompt.d.ts +4 -4
- package/dist/src/{harness → subagents}/handles/prompt.js +1 -1
- package/dist/src/{harness → subagents}/handles/query.d.ts +8 -2
- package/dist/src/subagents/handles/query.js +1 -0
- package/dist/src/subagents/handles/rebase.d.ts +4 -0
- package/dist/src/subagents/handles/rebase.js +1 -0
- package/dist/src/{harness → subagents}/handles/store.d.ts +90 -15
- package/dist/src/subagents/handles/store.js +1 -0
- package/dist/src/subagents/handles/transitions.d.ts +103 -0
- package/dist/src/subagents/handles/transitions.js +1 -0
- package/dist/src/{execution/delegated-parent-notification.d.ts → subagents/parent-notification.d.ts} +1 -7
- package/dist/src/subagents/parent-notification.js +1 -0
- package/dist/src/subagents/parent-result.js +1 -0
- package/dist/src/{execution/remote-agent-dispatch.d.ts → subagents/remote-dispatch.d.ts} +3 -2
- package/dist/src/subagents/remote-dispatch.js +1 -0
- package/dist/src/{execution/subagent-start-local.d.ts → subagents/start-local.d.ts} +5 -6
- package/dist/src/subagents/start-local.js +1 -0
- package/dist/src/{execution/subagent-start-remote.d.ts → subagents/start-remote.d.ts} +5 -5
- package/dist/src/subagents/start-remote.js +1 -0
- package/dist/src/{execution/subagent-tool.d.ts → subagents/tool.d.ts} +5 -3
- package/dist/src/subagents/tool.js +1 -0
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tasks/json.js +1 -1
- package/dist/src/tasks/session-index.d.ts +2 -3
- package/dist/src/tasks/session-index.js +1 -1
- package/dist/src/tasks/task-id.d.ts +3 -4
- package/dist/src/tasks/task-id.js +1 -1
- package/dist/src/tasks/transitions.d.ts +3 -47
- package/dist/src/tasks/transitions.js +1 -1
- package/dist/src/tasks/types.d.ts +69 -247
- package/dist/src/tasks/types.js +1 -1
- package/dist/src/tools/dynamic.d.ts +3 -1
- package/dist/src/tools/framework/agent.d.ts +18 -2
- package/dist/src/tools/framework/agent.js +1 -1
- package/dist/src/tools/framework/task-cancel.d.ts +2 -6
- package/dist/src/tools/framework/task-contract.d.ts +44 -65
- package/dist/src/tools/framework/task-contract.js +1 -1
- package/dist/src/tools/framework/task-update.d.ts +1 -0
- package/dist/src/tools/framework/task-update.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/concepts/built-in-tools.md +9 -90
- package/docs/concepts/context-control.md +2 -2
- package/docs/concepts/execution-model-and-durability.mdx +1 -1
- package/docs/concepts/sessions-runs-and-streaming.md +3 -3
- package/docs/guides/deployment/vercel.mdx +20 -2
- package/docs/guides/dynamic-capabilities.md +2 -2
- package/docs/guides/frontend/overview.mdx +1 -1
- package/docs/guides/instrumentation-providers.md +242 -0
- package/docs/guides/instrumentation.md +2 -0
- package/docs/guides/meta.json +1 -0
- package/docs/guides/remote-agents.md +8 -9
- package/docs/reference/cli.md +5 -2
- package/docs/sandbox.mdx +2 -0
- package/docs/subagents/index.mdx +9 -8
- package/docs/tools/overview.mdx +11 -10
- package/docs/tools/workflows.mdx +52 -18
- package/package.json +1 -1
- package/dist/src/execution/agent-continuation-bundle.js +0 -1
- package/dist/src/execution/agent-handle-dispatch.d.ts +0 -79
- package/dist/src/execution/agent-handle-dispatch.js +0 -1
- package/dist/src/execution/delegated-parent-notification.js +0 -1
- package/dist/src/execution/delegated-parent-result.js +0 -1
- package/dist/src/execution/delegation-tool.d.ts +0 -10
- package/dist/src/execution/delegation-tool.js +0 -1
- package/dist/src/execution/dispatch-runtime-actions-shared.d.ts +0 -165
- package/dist/src/execution/dispatch-runtime-actions-shared.js +0 -1
- package/dist/src/execution/dispatch-runtime-actions-start.js +0 -1
- package/dist/src/execution/dispatch-runtime-actions-step.d.ts +0 -18
- package/dist/src/execution/dispatch-runtime-actions-step.js +0 -1
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.d.ts +0 -18
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +0 -1
- package/dist/src/execution/finalize-terminal-session.d.ts +0 -17
- package/dist/src/execution/finalize-terminal-session.js +0 -1
- package/dist/src/execution/prepared-agent-action.d.ts +0 -7
- package/dist/src/execution/prepared-agent-action.js +0 -1
- package/dist/src/execution/remote-agent-dispatch.js +0 -1
- package/dist/src/execution/session-callback-route.js +0 -1
- package/dist/src/execution/session-callback-step.js +0 -1
- package/dist/src/execution/subagent-adapter.js +0 -1
- package/dist/src/execution/subagent-event-proxy-step.js +0 -1
- package/dist/src/execution/subagent-start-local.js +0 -1
- package/dist/src/execution/subagent-start-remote.js +0 -1
- package/dist/src/execution/subagent-tool.js +0 -1
- package/dist/src/execution/tasks/child/instructions.d.ts +0 -3
- package/dist/src/execution/tasks/child/instructions.js +0 -1
- package/dist/src/execution/tasks/parent/agent-identity.d.ts +0 -13
- package/dist/src/execution/tasks/parent/agent-identity.js +0 -1
- package/dist/src/execution/tasks/parent/agent-views.d.ts +0 -7
- package/dist/src/execution/tasks/parent/agent-views.js +0 -1
- package/dist/src/execution/tasks/parent/continuation-dispatch.d.ts +0 -43
- package/dist/src/execution/tasks/parent/continuation-dispatch.js +0 -1
- package/dist/src/execution/tasks/parent/dispatch-task-step.d.ts +0 -19
- package/dist/src/execution/tasks/parent/dispatch-task-step.js +0 -1
- package/dist/src/execution/tool-run/answer.js +0 -1
- package/dist/src/execution/tool-run/background.d.ts +0 -14
- package/dist/src/execution/tool-run/background.js +0 -1
- package/dist/src/execution/tool-run/cancel.d.ts +0 -7
- package/dist/src/execution/tool-run/cancel.js +0 -1
- package/dist/src/execution/tool-run/dispatch.d.ts +0 -24
- package/dist/src/execution/tool-run/dispatch.js +0 -1
- package/dist/src/execution/tool-run/emit-run-report-step.d.ts +0 -7
- package/dist/src/execution/tool-run/emit-run-report-step.js +0 -1
- package/dist/src/execution/tool-run/messages.d.ts +0 -70
- package/dist/src/execution/tool-run/messages.js +0 -1
- package/dist/src/execution/tool-run/owner-inbox.d.ts +0 -11
- package/dist/src/execution/tool-run/owner-inbox.js +0 -1
- package/dist/src/execution/tool-run/owner.d.ts +0 -13
- package/dist/src/execution/tool-run/owner.js +0 -1
- package/dist/src/execution/tool-run/run-control.d.ts +0 -18
- package/dist/src/execution/tool-run/run-control.js +0 -1
- package/dist/src/execution/tool-run/start.d.ts +0 -11
- package/dist/src/execution/tool-run/start.js +0 -1
- package/dist/src/execution/tool-run/types.d.ts +0 -21
- package/dist/src/execution/tool-run/types.js +0 -1
- package/dist/src/execution/tool-run/workflow.d.ts +0 -9
- package/dist/src/execution/tool-run/workflow.js +0 -1
- package/dist/src/execution/tools/subagent/local.d.ts +0 -40
- package/dist/src/execution/tools/subagent/local.js +0 -1
- package/dist/src/execution/tools/subagent/remote.d.ts +0 -26
- package/dist/src/execution/tools/subagent/remote.js +0 -1
- package/dist/src/harness/agent-handle-errors.js +0 -1
- package/dist/src/harness/handles/query.js +0 -1
- package/dist/src/harness/handles/store.js +0 -1
- package/dist/src/harness/handles/transitions.d.ts +0 -167
- package/dist/src/harness/handles/transitions.js +0 -1
- package/dist/src/harness/runtime-actions.js +0 -1
- package/dist/src/harness/subagent-depth.d.ts +0 -10
- package/dist/src/harness/subagent-depth.js +0 -1
- package/dist/src/harness/tool-runs.d.ts +0 -21
- package/dist/src/harness/tool-runs.js +0 -1
- package/dist/src/harness/workflow-runtime-action-state.d.ts +0 -9
- package/dist/src/harness/workflow-runtime-action-state.js +0 -1
- package/dist/src/runtime/actions/keys.d.ts +0 -14
- package/dist/src/runtime/actions/keys.js +0 -1
- package/dist/src/tasks/wire.d.ts +0 -25
- package/dist/src/tasks/wire.js +0 -1
- /package/dist/src/execution/{tool-run → tools/workflow}/owner-channels.d.ts +0 -0
- /package/dist/src/execution/{tool-run → tools/workflow}/owner-channels.js +0 -0
- /package/dist/src/execution/{tool-run → tools/workflow}/resume-hook-step.d.ts +0 -0
- /package/dist/src/execution/{tool-run → tools/workflow}/resume-hook-step.js +0 -0
- /package/dist/src/{execution/subagent-adapter.d.ts → subagents/adapter.d.ts} +0 -0
- /package/dist/src/{execution/session-callback-route.d.ts → subagents/callback-route.d.ts} +0 -0
- /package/dist/src/{execution/session-callback-step.d.ts → subagents/callback-step.d.ts} +0 -0
- /package/dist/src/{harness → subagents}/handles/operation-id.d.ts +0 -0
- /package/dist/src/{harness → subagents}/handles/operation-id.js +0 -0
- /package/dist/src/{harness → subagents}/handles/state-key.d.ts +0 -0
- /package/dist/src/{harness → subagents}/handles/state-key.js +0 -0
- /package/dist/src/{execution/subagent-hitl-proxy.d.ts → subagents/hitl-proxy.d.ts} +0 -0
- /package/dist/src/{execution/subagent-hitl-proxy.js → subagents/hitl-proxy.js} +0 -0
- /package/dist/src/{execution/subagent-invocation.d.ts → subagents/invocation.d.ts} +0 -0
- /package/dist/src/{execution/subagent-invocation.js → subagents/invocation.js} +0 -0
- /package/dist/src/{execution/delegated-parent-result.d.ts → subagents/parent-result.d.ts} +0 -0
- /package/dist/src/{execution/remote-agent-route-url.d.ts → subagents/remote-route-url.d.ts} +0 -0
- /package/dist/src/{execution/remote-agent-route-url.js → subagents/remote-route-url.js} +0 -0
- /package/dist/src/{harness/subagent-token-budget.d.ts → subagents/token-budget.d.ts} +0 -0
- /package/dist/src/{harness/subagent-token-budget.js → subagents/token-budget.js} +0 -0
|
@@ -80,21 +80,13 @@ export type AgentAddress = {
|
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* Outside tasks mode, the store owns the full nonterminal lifecycle:
|
|
83
|
+
* Parent-turn-owned lifecycle: `starting → running → parked ↔ running`.
|
|
86
84
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* - `parked` — the child is idle and resumable; only this phase is
|
|
91
|
-
* model-visible.
|
|
92
|
-
*
|
|
93
|
-
* A terminal child has no legacy handle: settlement deletes it. Tasks mode
|
|
94
|
-
* instead keeps an `addressed` record whose availability is derived from the
|
|
95
|
-
* tasks bound to its persistent child session.
|
|
85
|
+
* `starting` owns a start intent before the child has an address, `running`
|
|
86
|
+
* owns one outstanding child turn, and `parked` retains an idle, resumable
|
|
87
|
+
* child. A terminal child or dead dispatch leaves this union entirely.
|
|
96
88
|
*/
|
|
97
|
-
export type
|
|
89
|
+
export type TurnOwnedAgentHandle = {
|
|
98
90
|
readonly phase: "starting";
|
|
99
91
|
readonly identity: AgentIdentity;
|
|
100
92
|
readonly operation: StartOperation;
|
|
@@ -109,18 +101,93 @@ export type AgentHandle = {
|
|
|
109
101
|
readonly identity: AgentIdentity;
|
|
110
102
|
readonly address: AgentAddress;
|
|
111
103
|
readonly lastStatus: string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Workflow-owner lifecycle: `reserved → claimed → available ↔ claimed`.
|
|
107
|
+
*
|
|
108
|
+
* `reserved` leases a fresh identity before start, `claimed` leases an
|
|
109
|
+
* addressed child turn to one task or workflow-tool run, and `available`
|
|
110
|
+
* retains the idle address between invocations. A terminal child leaves this
|
|
111
|
+
* union entirely.
|
|
112
|
+
*/
|
|
113
|
+
export type TaskOwnedAgentHandle = {
|
|
114
|
+
/** Fresh identity leased to one owner before the child's address is confirmed. */
|
|
115
|
+
readonly phase: "reserved";
|
|
116
|
+
readonly identity: AgentIdentity;
|
|
117
|
+
readonly operationId: string;
|
|
118
|
+
readonly callId?: string;
|
|
119
|
+
readonly ownerId: string;
|
|
120
|
+
} | {
|
|
121
|
+
/** Addressed child turn leased until its owner releases it. */
|
|
122
|
+
readonly phase: "claimed";
|
|
123
|
+
readonly identity: AgentIdentity;
|
|
124
|
+
readonly operationId: string;
|
|
125
|
+
readonly callId?: string;
|
|
126
|
+
readonly address: AgentAddress;
|
|
127
|
+
readonly ownerId: string;
|
|
112
128
|
} | {
|
|
113
|
-
/**
|
|
114
|
-
readonly phase: "
|
|
129
|
+
/** Idle addressed child with no owner lease, ready for a later invocation to claim. */
|
|
130
|
+
readonly phase: "available";
|
|
115
131
|
readonly identity: AgentIdentity;
|
|
116
132
|
readonly address: AgentAddress;
|
|
117
133
|
};
|
|
134
|
+
/**
|
|
135
|
+
* Durable ownership record for one delegated child.
|
|
136
|
+
*
|
|
137
|
+
* The two execution policies share an identity namespace and serialized store,
|
|
138
|
+
* but their lifecycle states and transitions are disjoint. A terminal child has
|
|
139
|
+
* no handle: settlement deletes it.
|
|
140
|
+
*/
|
|
141
|
+
export type AgentHandle = TurnOwnedAgentHandle | TaskOwnedAgentHandle;
|
|
118
142
|
/** Lifecycle phase of a delegated agent handle. */
|
|
119
143
|
export type AgentHandlePhase = AgentHandle["phase"];
|
|
120
144
|
/** Session-state collection of delegated agent handles. */
|
|
121
145
|
export interface AgentHandleStore {
|
|
122
146
|
readonly handles: readonly AgentHandle[];
|
|
123
147
|
}
|
|
148
|
+
export declare const EMPTY_AGENT_HANDLE_STORE: AgentHandleStore;
|
|
149
|
+
/** One serialized owner-lease mutation against the shared agent handle store. */
|
|
150
|
+
export type AgentHandleStoreCommand = {
|
|
151
|
+
readonly kind: "read";
|
|
152
|
+
} | {
|
|
153
|
+
readonly identity: AgentIdentity;
|
|
154
|
+
readonly kind: "reserve";
|
|
155
|
+
readonly operationId: string;
|
|
156
|
+
readonly callId?: string;
|
|
157
|
+
readonly ownerId: string;
|
|
158
|
+
} | {
|
|
159
|
+
readonly address: AgentAddress;
|
|
160
|
+
readonly kind: "confirm";
|
|
161
|
+
readonly operationId: string;
|
|
162
|
+
readonly ownerId: string;
|
|
163
|
+
} | {
|
|
164
|
+
readonly agentId: string;
|
|
165
|
+
readonly expectedTarget: "local" | "remote";
|
|
166
|
+
readonly callId?: string;
|
|
167
|
+
readonly invokedName: string;
|
|
168
|
+
readonly kind: "claim";
|
|
169
|
+
readonly operationId: string;
|
|
170
|
+
readonly ownerId: string;
|
|
171
|
+
} | {
|
|
172
|
+
readonly agentId: string;
|
|
173
|
+
readonly kind: "remove";
|
|
174
|
+
readonly ownerId: string;
|
|
175
|
+
} | {
|
|
176
|
+
readonly kind: "release-owner";
|
|
177
|
+
readonly ownerId: string;
|
|
178
|
+
};
|
|
179
|
+
export type AgentHandleStoreCommandResult = {
|
|
180
|
+
readonly kind: "ready";
|
|
181
|
+
readonly handle?: TaskOwnedAgentHandle;
|
|
182
|
+
} | {
|
|
183
|
+
readonly kind: "busy";
|
|
184
|
+
readonly handle: AgentHandle;
|
|
185
|
+
} | {
|
|
186
|
+
readonly kind: "mismatch";
|
|
187
|
+
readonly handle: AgentHandle;
|
|
188
|
+
} | {
|
|
189
|
+
readonly kind: "unknown";
|
|
190
|
+
};
|
|
124
191
|
/** Derives the model-visible agent id from the first start operation. */
|
|
125
192
|
export declare function deriveAgentId(name: string, startOperationId: string): string;
|
|
126
193
|
/** Collapses whitespace and truncates output into a handle status line. */
|
|
@@ -132,6 +199,8 @@ export declare function formatAgentStatus(output: unknown): string;
|
|
|
132
199
|
* driver-side reader (`query.ts`) trust stored values without revalidating.
|
|
133
200
|
*/
|
|
134
201
|
export declare function assertPersistableAgentHandleStore(store: AgentHandleStore): AgentHandleStore;
|
|
202
|
+
/** Parses one complete command before the session inbox routes it to the handle store. */
|
|
203
|
+
export declare function parseAgentHandleStoreCommand(value: unknown): AgentHandleStoreCommand | undefined;
|
|
135
204
|
/**
|
|
136
205
|
* Reads and validates the agent handle store from session state.
|
|
137
206
|
*
|
|
@@ -140,3 +209,9 @@ export declare function assertPersistableAgentHandleStore(store: AgentHandleStor
|
|
|
140
209
|
* transition silently replace every delegated child's delivery coordinates.
|
|
141
210
|
*/
|
|
142
211
|
export declare function getAgentHandleStore(state: SessionStateMap | undefined): AgentHandleStore | undefined;
|
|
212
|
+
/** Writes the validated agent handle store under its single session-state key. */
|
|
213
|
+
export declare function setAgentHandleStore(state: SessionStateMap | undefined, store: AgentHandleStore): SessionStateMap;
|
|
214
|
+
/** Writes a validated handle list to a session-shaped value. */
|
|
215
|
+
export declare function writeHandles<Session extends {
|
|
216
|
+
readonly state?: SessionStateMap;
|
|
217
|
+
}>(session: Session, handles: readonly AgentHandle[]): Session;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{AGENT_HANDLES_STATE_KEY}from"./state-key.js";import{z}from"#compiled/zod/index.js";const EMPTY_AGENT_HANDLE_STORE={handles:[]},nonEmptyString=z.string().min(1),identitySchema=z.strictObject({id:nonEmptyString,name:nonEmptyString,nodeId:nonEmptyString}),startOperationSchema=z.strictObject({callId:nonEmptyString,id:nonEmptyString,kind:z.literal(`start`),parentTurnId:nonEmptyString}),continueOperationSchema=z.strictObject({callId:nonEmptyString,id:nonEmptyString,kind:z.literal(`continue`),parentTurnId:nonEmptyString,previousStatus:z.string().max(120)}),startTargetSchema=z.discriminatedUnion(`kind`,[z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/local`)}),z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/self`)}),z.strictObject({callbackBaseUrl:z.url(),credentialResolver:z.strictObject({resolverId:nonEmptyString.optional()}).optional(),kind:z.literal(`agent/remote`),url:z.url()})]),addressSchema=z.discriminatedUnion(`kind`,[z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/local`),sessionId:nonEmptyString}),z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/self`),sessionId:nonEmptyString}),z.strictObject({callbackBaseUrl:z.url(),credentialResolver:z.strictObject({resolverId:nonEmptyString.optional()}).optional(),kind:z.literal(`agent/remote`),sessionId:nonEmptyString,url:z.url()})]),agentHandleStoreCommandSchema=z.discriminatedUnion(`kind`,[z.strictObject({kind:z.literal(`read`)}),z.strictObject({identity:identitySchema,callId:nonEmptyString.optional(),kind:z.literal(`reserve`),operationId:nonEmptyString,ownerId:nonEmptyString}),z.strictObject({address:addressSchema,kind:z.literal(`confirm`),operationId:nonEmptyString,ownerId:nonEmptyString}),z.strictObject({agentId:nonEmptyString,callId:nonEmptyString.optional(),expectedTarget:z.enum([`local`,`remote`]),invokedName:nonEmptyString,kind:z.literal(`claim`),operationId:nonEmptyString,ownerId:nonEmptyString}),z.strictObject({agentId:nonEmptyString,kind:z.literal(`remove`),ownerId:nonEmptyString}),z.strictObject({kind:z.literal(`release-owner`),ownerId:nonEmptyString})]),turnOwnedAgentHandleSchema=z.discriminatedUnion(`phase`,[z.strictObject({identity:identitySchema,operation:startOperationSchema,phase:z.literal(`starting`),target:startTargetSchema}),z.strictObject({address:addressSchema,identity:identitySchema,operation:z.discriminatedUnion(`kind`,[startOperationSchema,continueOperationSchema]),phase:z.literal(`running`)}),z.strictObject({address:addressSchema,identity:identitySchema,lastStatus:z.string().max(120),phase:z.literal(`parked`)})]),taskOwnedAgentHandleSchema=z.discriminatedUnion(`phase`,[z.strictObject({callId:nonEmptyString.optional(),identity:identitySchema,operationId:nonEmptyString,phase:z.literal(`reserved`),ownerId:nonEmptyString}),z.strictObject({address:addressSchema,callId:nonEmptyString.optional(),identity:identitySchema,operationId:nonEmptyString,phase:z.literal(`claimed`),ownerId:nonEmptyString}),z.strictObject({address:addressSchema,identity:identitySchema,phase:z.literal(`available`)})]),agentHandleSchema=z.union([turnOwnedAgentHandleSchema,taskOwnedAgentHandleSchema]),agentHandleStoreSchema=z.strictObject({handles:z.array(agentHandleSchema)}).refine(e=>new Set(e.handles.map(e=>e.identity.id)).size===e.handles.length,{message:`Agent handle ids must be unique.`});function deriveAgentId(e,t){return`ag_${e}:${t.slice(0,12)}`}function formatAgentStatus(e){return(typeof e==`string`?e:JSON.stringify(e)??``).replaceAll(/\s+/g,` `).trim().slice(0,120)}function assertPersistableAgentHandleStore(e){let t=agentHandleStoreSchema.safeParse(e);if(!t.success)throw Error(`Refusing to persist a corrupt agent handle store: ${t.error.message}`);return t.data}function parseAgentHandleStoreCommand(e){let t=agentHandleStoreCommandSchema.safeParse(e);return t.success?t.data:void 0}function getAgentHandleStore(t){let n=t?.[AGENT_HANDLES_STATE_KEY];if(n===void 0)return;let r=agentHandleStoreSchema.safeParse(n);if(!r.success)throw Error(`Corrupt agent handle store under session state key "${AGENT_HANDLES_STATE_KEY}": ${r.error.message}`);return r.data}function setAgentHandleStore(t,n){return{...t,[AGENT_HANDLES_STATE_KEY]:assertPersistableAgentHandleStore(n)}}function writeHandles(e,t){return{...e,state:setAgentHandleStore(e.state,{handles:t})}}export{AGENT_HANDLES_STATE_KEY,EMPTY_AGENT_HANDLE_STORE,assertPersistableAgentHandleStore,deriveAgentId,formatAgentStatus,getAgentHandleStore,parseAgentHandleStoreCommand,setAgentHandleStore,writeHandles};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type AgentAddress, type AgentHandleStore, type AgentHandleStoreCommand, type AgentHandleStoreCommandResult, type AgentIdentity, type StartOperation, type TurnOwnedAgentHandle } from "#subagents/handles/store.js";
|
|
2
|
+
import type { HarnessSession, SessionStateMap } from "#harness/types.js";
|
|
3
|
+
import type { AgentTurnOutcome } from "#shared/agent-turn-outcome.js";
|
|
4
|
+
/**
|
|
5
|
+
* Records intent to start a fresh child. Must be applied to the step's
|
|
6
|
+
* working snapshot before the start side effect runs, so the returned state
|
|
7
|
+
* owns any child the step may have created.
|
|
8
|
+
*
|
|
9
|
+
* The guarantee is intra-step, not exactly-once: the prepared handle
|
|
10
|
+
* durably commits only when the enclosing dispatch step's result commits.
|
|
11
|
+
* A crash between an accepted start and that commit replays the step from
|
|
12
|
+
* the pre-step snapshot and re-runs the side effect.
|
|
13
|
+
*
|
|
14
|
+
* Throws when the identity or operation already exists: fresh starts mint
|
|
15
|
+
* a new identity, so a collision means corrupted derivation, not a replay.
|
|
16
|
+
*/
|
|
17
|
+
export declare function prepareAgentStart(session: HarnessSession, input: {
|
|
18
|
+
readonly identity: AgentIdentity;
|
|
19
|
+
readonly operation: StartOperation;
|
|
20
|
+
readonly target: AgentStartTargetInput;
|
|
21
|
+
}): HarnessSession;
|
|
22
|
+
type AgentStartTargetInput = Extract<TurnOwnedAgentHandle, {
|
|
23
|
+
phase: "starting";
|
|
24
|
+
}>["target"];
|
|
25
|
+
/**
|
|
26
|
+
* Confirms a started child: `starting` becomes `running` with the child's
|
|
27
|
+
* confirmed address. Throws when no starting handle carries the operation,
|
|
28
|
+
* because confirming an unprepared start means ownership was never
|
|
29
|
+
* committed. Re-confirming an already-running handle with the same
|
|
30
|
+
* operation and address is a replay no-op.
|
|
31
|
+
*/
|
|
32
|
+
export declare function confirmAgentStarted(session: HarnessSession, input: {
|
|
33
|
+
readonly operationId: string;
|
|
34
|
+
readonly address: AgentAddress;
|
|
35
|
+
}): HarnessSession;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves a dispatch that definitively failed.
|
|
38
|
+
*
|
|
39
|
+
* - A dead start or dead continuation deletes the handle: there is no
|
|
40
|
+
* child left to own.
|
|
41
|
+
* - A retryable continuation failure restores `parked` with the status the
|
|
42
|
+
* handle showed before the delivery, so the model may retry the same
|
|
43
|
+
* `agentId` later.
|
|
44
|
+
*
|
|
45
|
+
* Unknown operations are a no-op: the failure raced a settlement that
|
|
46
|
+
* already resolved the handle.
|
|
47
|
+
*/
|
|
48
|
+
export declare function rejectAgentEffect(session: HarnessSession, input: {
|
|
49
|
+
readonly operationId: string;
|
|
50
|
+
readonly disposition: "dead" | "retryable";
|
|
51
|
+
}): HarnessSession;
|
|
52
|
+
/**
|
|
53
|
+
* Parks every running child when the parent abandons a cancelled turn.
|
|
54
|
+
*
|
|
55
|
+
* Cancellation requests each running descendant's cancellation and then
|
|
56
|
+
* tears down the turn inbox — the only hook a child settlement can
|
|
57
|
+
* resume — so no later settlement can move these handles. Without this
|
|
58
|
+
* transition they would stay `running` forever: invisible to the model,
|
|
59
|
+
* unresumable, and retried by every future cancellation.
|
|
60
|
+
*
|
|
61
|
+
* A cancelled child settles its own turn as a park, so `parked` with
|
|
62
|
+
* `"(cancelled)"` mirrors {@link settleAgentTurn}'s cancelled outcome. If
|
|
63
|
+
* the child instead died, a later continuation attempt discovers the dead
|
|
64
|
+
* session and {@link rejectAgentEffect} deletes the handle.
|
|
65
|
+
*/
|
|
66
|
+
export declare function abandonRunningAgentTurns(session: HarnessSession): HarnessSession;
|
|
67
|
+
/** Result of applying a settled child turn to the store. */
|
|
68
|
+
export type SettleAgentTurnResult = {
|
|
69
|
+
readonly kind: "settled";
|
|
70
|
+
readonly session: HarnessSession;
|
|
71
|
+
} | {
|
|
72
|
+
readonly kind: "ignored";
|
|
73
|
+
readonly reason: "unknown-operation";
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Applies one settled child turn: `running` becomes `parked` for a parked
|
|
77
|
+
* outcome or is deleted for a terminal outcome.
|
|
78
|
+
*
|
|
79
|
+
* The settlement must carry the operation currently recorded on the
|
|
80
|
+
* running handle; anything else is ignored so a stale delivery can never
|
|
81
|
+
* move a newer turn.
|
|
82
|
+
*/
|
|
83
|
+
export declare function settleAgentTurn(session: HarnessSession, input: {
|
|
84
|
+
readonly operationId: string;
|
|
85
|
+
readonly outcome: AgentTurnOutcome;
|
|
86
|
+
}): SettleAgentTurnResult;
|
|
87
|
+
/** Applies one atomic owner lease command to the shared agent handle store. */
|
|
88
|
+
export declare function applyAgentHandleStoreCommand(store: AgentHandleStore, command: AgentHandleStoreCommand): {
|
|
89
|
+
readonly result: AgentHandleStoreCommandResult;
|
|
90
|
+
readonly store: AgentHandleStore;
|
|
91
|
+
};
|
|
92
|
+
/** Parks child turns still owned by workflow runs when their parent turn is cancelled. */
|
|
93
|
+
export declare function abandonAgentInvocationOwners<Session extends {
|
|
94
|
+
readonly state?: SessionStateMap;
|
|
95
|
+
}>(session: Session, ownerIds: ReadonlySet<string>): Session;
|
|
96
|
+
/** Applies one owner-scoped handle transition to a harness session. */
|
|
97
|
+
export declare function applyTaskAgentHandleCommand<Session extends {
|
|
98
|
+
readonly state?: SessionStateMap;
|
|
99
|
+
}>(session: Session, command: AgentHandleStoreCommand): {
|
|
100
|
+
readonly result: AgentHandleStoreCommandResult;
|
|
101
|
+
readonly session: Session;
|
|
102
|
+
};
|
|
103
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EMPTY_AGENT_HANDLE_STORE,formatAgentStatus,getAgentHandleStore,writeHandles}from"#subagents/handles/store.js";function prepareAgentStart(e,t){let i=getAgentHandleStore(e.state)?.handles??[];if(i.some(e=>e.identity.id===t.identity.id))throw Error(`Agent handle "${t.identity.id}" already exists.`);return writeHandles(e,[...i,{identity:t.identity,operation:t.operation,phase:`starting`,target:t.target}])}function findActiveHandle(e,t){return e.find(e=>(e.phase===`starting`||e.phase===`running`)&&e.operation.id===t)}function confirmAgentStarted(e,t){let i=getAgentHandleStore(e.state)?.handles??[],a=findActiveHandle(i,t.operationId);if(a===void 0)throw Error(`No prepared agent handle for operation "${t.operationId}".`);return a.phase===`running`?e:writeHandles(e,i.map(e=>e===a?{address:t.address,identity:a.identity,operation:a.operation,phase:`running`}:e))}function rejectAgentEffect(e,t){let i=getAgentHandleStore(e.state)?.handles??[],a=findActiveHandle(i,t.operationId);if(a===void 0)return e;if(t.disposition===`retryable`&&a.phase===`running`){let{operation:t}=a;if(t.kind===`continue`)return writeHandles(e,i.map(e=>e===a?{address:a.address,identity:a.identity,lastStatus:t.previousStatus,phase:`parked`}:e))}return writeHandles(e,i.filter(e=>e!==a))}function abandonRunningAgentTurns(e){let t=getAgentHandleStore(e.state)?.handles??[];return t.some(e=>e.phase===`running`)?writeHandles(e,t.map(e=>e.phase===`running`?{address:e.address,identity:e.identity,lastStatus:`(cancelled)`,phase:`parked`}:e)):e}function settleAgentTurn(e,i){let a=getAgentHandleStore(e.state)?.handles??[],o=a.find(e=>e.phase===`running`&&e.operation.id===i.operationId);if(o===void 0||o.phase!==`running`)return{kind:`ignored`,reason:`unknown-operation`};if(i.outcome.kind===`terminal`)return{kind:`settled`,session:writeHandles(e,a.filter(e=>e!==o))};let{result:s}=i.outcome,c=s.kind===`succeeded`?formatAgentStatus(s.output):s.kind===`failed`?formatAgentStatus(s.error):`(cancelled)`;return{kind:`settled`,session:writeHandles(e,a.map(e=>e===o?{address:o.address,identity:o.identity,lastStatus:c,phase:`parked`}:e))}}function applyAgentHandleStoreCommand(e,t){switch(t.kind){case`read`:return{result:{kind:`ready`},store:e};case`reserve`:{let n=e.handles.find(e=>e.identity.id===t.identity.id);if(n!==void 0)return(n.phase===`reserved`||n.phase===`claimed`)&&n.operationId===t.operationId&&n.ownerId===t.ownerId?{result:{handle:n,kind:`ready`},store:e}:{result:{handle:n,kind:`busy`},store:e};let r={callId:t.callId,identity:t.identity,operationId:t.operationId,phase:`reserved`,ownerId:t.ownerId};return{result:{handle:r,kind:`ready`},store:{handles:[...e.handles,r]}}}case`confirm`:{let n=e.handles.find(e=>(e.phase===`claimed`||e.phase===`reserved`)&&e.operationId===t.operationId&&e.ownerId===t.ownerId);return n===void 0?{result:{kind:`unknown`},store:e}:n.phase===`claimed`?{result:{handle:n,kind:`ready`},store:e}:replaceHandle(e,n,{address:t.address,callId:n.callId,identity:n.identity,operationId:n.operationId,phase:`claimed`,ownerId:n.ownerId})}case`claim`:{let n=e.handles.find(e=>e.identity.id===t.agentId);return n===void 0?{result:{kind:`unknown`},store:e}:n.phase===`starting`||n.phase===`running`||n.identity.name!==t.invokedName||n.phase!==`reserved`&&n.address.kind===`agent/remote`!=(t.expectedTarget===`remote`)?{result:{handle:n,kind:`mismatch`},store:e}:n.phase===`claimed`?n.operationId===t.operationId&&n.ownerId===t.ownerId?{result:{handle:n,kind:`ready`},store:e}:{result:{handle:n,kind:`busy`},store:e}:n.phase===`reserved`?{result:{handle:n,kind:`busy`},store:e}:replaceHandle(e,n,{address:n.address,callId:t.callId,identity:n.identity,operationId:t.operationId,phase:`claimed`,ownerId:t.ownerId})}case`remove`:{let n=e.handles.find(e=>e.identity.id===t.agentId);return n===void 0?{result:{kind:`ready`},store:e}:n.phase===`claimed`&&n.ownerId!==t.ownerId?{result:{handle:n,kind:`busy`},store:e}:{result:{kind:`ready`},store:{handles:e.handles.filter(e=>e!==n)}}}case`release-owner`:{let n=e.handles.flatMap(e=>e.phase===`reserved`&&e.ownerId===t.ownerId?[]:e.phase!==`claimed`||e.ownerId!==t.ownerId?[e]:[{address:e.address,identity:e.identity,phase:`available`}]);return{result:{kind:`ready`},store:handlesEqual(e.handles,n)?e:{handles:n}}}}}function abandonAgentInvocationOwners(e,t){let i=getAgentHandleStore(e.state)?.handles??[],a=i.flatMap(e=>e.phase===`reserved`&&t.has(e.ownerId)?[]:e.phase!==`claimed`||!t.has(e.ownerId)?[e]:[{address:e.address,identity:e.identity,lastStatus:`(cancelled)`,phase:`parked`}]);return handlesEqual(i,a)?e:writeHandles(e,a)}function applyTaskAgentHandleCommand(t,i){let a=getAgentHandleStore(t.state)??EMPTY_AGENT_HANDLE_STORE,o=applyAgentHandleStoreCommand(a,i);return{result:o.result,session:o.store===a?t:writeHandles(t,o.store.handles)}}function replaceHandle(e,t,n){return{result:{handle:n,kind:`ready`},store:{handles:e.handles.map(e=>e===t?n:e)}}}function handlesEqual(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}export{abandonAgentInvocationOwners,abandonRunningAgentTurns,applyAgentHandleStoreCommand,applyTaskAgentHandleCommand,confirmAgentStarted,prepareAgentStart,rejectAgentEffect,settleAgentTurn};
|
package/dist/src/{execution/delegated-parent-notification.d.ts → subagents/parent-notification.d.ts}
RENAMED
|
@@ -41,18 +41,12 @@ export declare function notifyTurnCallerStep(input: {
|
|
|
41
41
|
readonly sessionId: string;
|
|
42
42
|
readonly settled: SettledTurnNotification;
|
|
43
43
|
}): Promise<void>;
|
|
44
|
-
/** Settles a
|
|
44
|
+
/** Settles a workflow-owned caller after the child turn is cooperatively cancelled. */
|
|
45
45
|
export declare function notifyCancelledTaskCallerStep(input: {
|
|
46
46
|
readonly caller: TurnCaller | undefined;
|
|
47
47
|
readonly sessionId: string;
|
|
48
48
|
readonly usage?: TokenUsage;
|
|
49
49
|
}): Promise<void>;
|
|
50
|
-
/** Binds a durable task to the exact child turn before execution starts. */
|
|
51
|
-
export declare function notifyTaskTurnStartedStep(input: {
|
|
52
|
-
readonly caller: TurnCaller | undefined;
|
|
53
|
-
readonly childSessionId: string;
|
|
54
|
-
readonly childTurnId: string;
|
|
55
|
-
}): Promise<void>;
|
|
56
50
|
/** Resolves the caller that created a delegated conversation session. */
|
|
57
51
|
export declare function resolveInitialTurnCallerStep(input: {
|
|
58
52
|
readonly serializedContext: Record<string, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createLogger}from"#internal/logging.js";import{ActivityObserverKey,SessionCallbackKey}from"#context/keys.js";import{toErrorMessage}from"#shared/errors.js";import{parseJsonValue}from"#shared/json.js";import{ChannelKey}from"#runtime/sessions/runtime-context-keys.js";import{parseSessionCallback}from"#channel/session-callback.js";import{resumeHook}from"#internal/workflow/runtime.js";import{deserializeContext}from"#context/serialize.js";import{HookNotFoundError}from"#compiled/@workflow/errors/index.js";import{SUBAGENT_EXECUTION_FAILED}from"#subagents/agent-handle-errors.js";import{postSessionCallbackRequest}from"#execution/session-callback-request.js";import{SUBAGENT_ADAPTER_KIND,isSubagentAdapterState}from"#subagents/adapter-state.js";import{readTaskIdFromInboxToken}from"#tasks/task-inbox-token.js";const log=createLogger(`execution.delegated-parent-notification`);async function notifyDelegatedParentStep(e){"use step";if(e.result===void 0)return;let t=(await deserializeContext(e.serializedContext)).get(ChannelKey);if(t?.kind!==SUBAGENT_ADAPTER_KIND)return;let n=String(t.state?.parentContinuationToken??``);n!==``&&await resumeHook(n,{kind:`runtime-action-result`,results:[e.usage===void 0?e.result:{...e.result,outcome:{...e.result.outcome,usageDelta:e.usage},usage:e.usage}]})}const ZERO_TOKEN_USAGE={cacheReadTokens:0,cacheWriteTokens:0,inputTokens:0,outputTokens:0};async function notifyTurnCallerStep(e){"use step";if(e.caller===void 0)return;let t=createSettledTurnResult({caller:e.caller,lifecycle:e.lifecycle,sessionId:e.sessionId,settled:e.settled});if(e.caller.replyTo.kind===`callback`){await postSettledTurnCallback({result:t,sessionId:e.sessionId,url:e.caller.replyTo.url});return}await resumeSettledTurnHook(e.caller.replyTo.token,t)}async function notifyCancelledTaskCallerStep(e){"use step";if(e.caller===void 0)return;let t=e.usage??ZERO_TOKEN_USAGE,n={code:SUBAGENT_EXECUTION_FAILED,message:`The agent invocation was cancelled.`},r={callId:e.caller.callId,isError:!0,kind:`subagent-result`,origin:`child`,outcome:{kind:`parked`,result:{kind:`cancelled`},usageDelta:t},output:n,subagentName:e.caller.subagentName},i=e.usage===void 0?r:{...r,usage:e.usage};if(e.caller.replyTo.kind===`callback`){await postSettledTurnCallback({result:i,sessionId:e.sessionId,url:e.caller.replyTo.url});return}await resumeSettledTurnHook(e.caller.replyTo.token,i)}function createSettledTurnResult(e){let t=e.settled.usage??ZERO_TOKEN_USAGE;if(e.settled.isError===!0){let n={code:SUBAGENT_EXECUTION_FAILED,message:toErrorMessage(e.settled.output)};return{callId:e.caller.callId,isError:!0,kind:`subagent-result`,origin:`child`,outcome:{kind:e.lifecycle,result:{error:n,kind:`failed`},usageDelta:t},output:n,subagentName:e.caller.subagentName}}let n=parseJsonValue(e.settled.output),a={callId:e.caller.callId,kind:`subagent-result`,origin:`child`,outcome:{kind:e.lifecycle,result:{kind:`succeeded`,output:n},usageDelta:t},output:n,subagentName:e.caller.subagentName};return e.settled.usage===void 0?a:{...a,usage:e.settled.usage}}async function resolveInitialTurnCallerStep(e){"use step";let t=e.serializedContext[SessionCallbackKey.name];if(t!==void 0){let e=parseSessionCallback(t);if(!e.ok)throw Error(`Serialized session callback is invalid.`,{cause:e.cause});return{callId:e.callback.callId,replyTo:{kind:`callback`,token:e.callback.token,url:e.callback.url},subagentName:e.callback.subagentName,taskId:e.callback.taskId??readTaskIdFromInboxToken(e.callback.token)}}let r=(await deserializeContext(e.serializedContext)).get(ChannelKey);if(!(r?.kind!==SUBAGENT_ADAPTER_KIND||!isSubagentAdapterState(r.state)))return{callId:r.state.callId,replyTo:{kind:`hook`,token:r.state.parentContinuationToken},subagentName:r.state.subagentName,taskId:r.state.taskId??readTaskIdFromInboxToken(r.state.parentContinuationToken)}}async function bindTurnCallerContextStep(e){"use step";let r=e.caller;if(r===void 0)return e.serializedContext;let i=r.activityObserver===void 0?e.serializedContext:{...e.serializedContext,[ActivityObserverKey.name]:r.activityObserver};if(r.replyTo.kind===`callback`){let e={callId:r.callId,subagentName:r.subagentName,token:r.replyTo.token,url:r.replyTo.url};return{...i,[SessionCallbackKey.name]:r.taskId===void 0?e:{...e,taskId:r.taskId}}}let o=i[ChannelKey.name];if(typeof o!=`object`||!o||Reflect.get(o,`kind`)!==SUBAGENT_ADAPTER_KIND||!isSubagentAdapterState(Reflect.get(o,`state`)))throw Error(`Delegated local turn is missing its subagent adapter binding.`);let{taskId:s,...c}=Reflect.get(o,`state`),l={...c,callId:r.callId,parentContinuationToken:r.replyTo.token,subagentName:r.subagentName};return r.taskId!==void 0&&(l.taskId=r.taskId),{...i,[ChannelKey.name]:{...o,state:l}}}async function postSettledTurnCallback(e){let{sessionId:t}=e;if(e.result.isError===!0){await postCallbackPayload({payload:{callId:e.result.callId,error:e.result.output,kind:`turn.failed`,outcome:e.result.outcome,sessionId:t,subagentName:e.result.subagentName},url:e.url});return}await postCallbackPayload({payload:{callId:e.result.callId,kind:`turn.completed`,outcome:e.result.outcome,output:e.result.output,sessionId:t,subagentName:e.result.subagentName},url:e.url})}async function postCallbackPayload(e){let t=await postSessionCallbackRequest({body:e.payload,url:e.url});if(!t.ok)throw Error(`Turn callback failed with HTTP ${t.status}.`)}async function resumeSettledTurnHook(e,t){try{await resumeHook(e,{kind:`runtime-action-result`,results:[t]})}catch(n){if(!HookNotFoundError.is(n))throw n;log.warn(`turn caller hook no longer exists`,{callId:t.callId,callerToken:e})}}export{bindTurnCallerContextStep,notifyCancelledTaskCallerStep,notifyDelegatedParentStep,notifyTurnCallerStep,resolveInitialTurnCallerStep};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{toErrorMessage}from"#shared/errors.js";import{CHANNEL_CONTEXT_KEY_NAME}from"#context/key-names.js";import{SUBAGENT_EXECUTION_FAILED}from"#subagents/agent-handle-errors.js";import{SUBAGENT_ADAPTER_KIND}from"#subagents/adapter-state.js";const ZERO_TOKEN_USAGE={cacheReadTokens:0,cacheWriteTokens:0,inputTokens:0,outputTokens:0};function createDelegatedSubagentSuccessResult(e,n){let i=e[CHANNEL_CONTEXT_KEY_NAME];if(i?.kind===SUBAGENT_ADAPTER_KIND)return{callId:String(i.state?.callId??``),kind:`subagent-result`,origin:`child`,outcome:{kind:`terminal`,result:{kind:`succeeded`,output:n},usageDelta:ZERO_TOKEN_USAGE},output:n,subagentName:String(i.state?.subagentName??``)}}function createDelegatedSubagentErrorResult(t,r){let i=createDelegatedSubagentSuccessResult(t,``);if(i===void 0)return;let a={code:SUBAGENT_EXECUTION_FAILED,message:toErrorMessage(r)};return{...i,isError:!0,outcome:{kind:`terminal`,result:{error:a,kind:`failed`},usageDelta:ZERO_TOKEN_USAGE},output:a}}export{createDelegatedSubagentErrorResult,createDelegatedSubagentSuccessResult};
|
|
@@ -2,7 +2,7 @@ import { type ResetResponse } from "#protocol/reset-session.js";
|
|
|
2
2
|
import type { ActivityObserverConfig, CancelTurnResult, SessionAuthContext, SessionTraceContext } from "#channel/types.js";
|
|
3
3
|
import type { ChannelAudience } from "#shared/channel-audience.js";
|
|
4
4
|
import type { HarnessSession } from "#harness/types.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { RuntimeRemoteAgentDispatchRequest } from "#shared/action-types.js";
|
|
6
6
|
import type { RuntimeSubagentRegistry } from "#runtime/subagents/registry.js";
|
|
7
7
|
import type { DynamicRemoteAgentConfig } from "#runtime/subagents/dynamic-remote-agent-config.js";
|
|
8
8
|
import type { CompiledRuntimeAgentBundle } from "#runtime/sessions/compiled-agent-cache.js";
|
|
@@ -12,7 +12,7 @@ type RemoteAgentSessionCoordinates = {
|
|
|
12
12
|
readonly sessionId: string;
|
|
13
13
|
};
|
|
14
14
|
export declare function startRemoteAgentSession(input: {
|
|
15
|
-
readonly action:
|
|
15
|
+
readonly action: RuntimeRemoteAgentDispatchRequest;
|
|
16
16
|
/** The dispatching turn's session principal, forwarded when `remote.forwardPrincipal` is set. */
|
|
17
17
|
readonly auth?: SessionAuthContext | null;
|
|
18
18
|
readonly callbackBaseUrl: string | undefined;
|
|
@@ -30,6 +30,7 @@ export declare function startRemoteAgentSession(input: {
|
|
|
30
30
|
readonly parentTraceContext?: SessionTraceContext;
|
|
31
31
|
readonly remote: ResolvedRuntimeRemoteAgentNode;
|
|
32
32
|
readonly session: HarnessSession;
|
|
33
|
+
readonly taskId?: string;
|
|
33
34
|
}): Promise<RemoteAgentSessionCoordinates>;
|
|
34
35
|
/** Continues one remote-agent session by its immutable session ID. */
|
|
35
36
|
export declare function continueRemoteAgentSession(input: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z}from"#compiled/zod/index.js";import{createEveCallbackRoutePath,createEveSessionCancelRoutePath,createEveSessionResetRoutePath,createEveSessionRoutePath}from"#protocol/routes.js";import{expectFunction,expectObjectRecord}from"#internal/authored-module.js";import{CancelTurnResponseSchema}from"#protocol/cancel-turn.js";import{ResetResponseSchema}from"#protocol/reset-session.js";import{formatTraceparent}from"#protocol/traceparent.js";import{writeForwardedAudienceBaggage}from"#protocol/baggage.js";import{decisionToTraceContentCeiling}from"#shared/forwarded-trace-policy.js";import{createWorkflowCallbackUrl}from"#execution/workflow-callback-url.js";import{readTaskIdFromInboxToken}from"#tasks/task-inbox-token.js";import{formatSubagentInput,normalizeRequestedOutputSchema}from"#subagents/invocation.js";import{AgentHandleError}from"#protocol/agent-handle-error.js";import{createRemoteAgentRouteUrl}from"#subagents/remote-route-url.js";const CreateSessionResponseSchema=z.object({ok:z.literal(!0),sessionId:z.string().min(1),status:z.literal(`accepted`)});var RemoteAgentCancelRequestError=class extends Error{retryable;constructor(e,t){super(e),this.name=`RemoteAgentCancelRequestError`,this.retryable=t.retryable}};async function startRemoteAgentSession(e){let n=e.callbackToken??e.session.continuationToken;if(!n)throw Error(`Cannot dispatch remote agent without a parent continuation token.`);if(!e.callbackBaseUrl)throw Error(`Cannot dispatch remote agent without a callback base URL.`);let r=buildForwardedPrincipalField(e),i={capabilities:{},callback:{callId:e.action.callId,subagentName:e.action.remoteAgentName,taskId:e.taskId??readTaskIdFromInboxToken(n),token:n,url:createWorkflowCallbackUrl(e.callbackBaseUrl,createEveCallbackRoutePath(n))},message:formatRemoteAgentCallInputMessage({action:e.action,remote:e.remote}),mode:`conversation`,outputSchema:normalizeRequestedOutputSchema(e.action.input.outputSchema)??e.remote.outputSchema};e.activityObserver!==void 0&&(i.activityObserver=e.activityObserver),r!==void 0&&(i.forwardedPrincipal=r),e.operationId!==void 0&&(i.operationId=e.operationId);let a=await resolveRemoteAgentRequestHeaders(e.remote),o=formatTraceparent(e.parentTraceContext);o!==void 0&&setHeader(a,`traceparent`,o),setHeader(a,`baggage`,writeForwardedAudienceBaggage(readHeader(a,`baggage`),buildForwardedTraceAssertion({forwardedPrincipal:r,originAudience:e.originAudience,parentTraceContext:e.parentTraceContext,traceparent:o})));let s=await fetch(createRemoteAgentSessionUrl(e.remote),{body:JSON.stringify(i),headers:{"content-type":`application/json`,...a},method:`POST`});if(!s.ok)throw Error(`Remote agent "${e.action.remoteAgentName}" create-session request failed with HTTP ${s.status}.`);let c;try{c=await s.json()}catch{throw Error(`Remote agent "${e.action.remoteAgentName}" create-session response was not valid JSON.`)}let l=CreateSessionResponseSchema.safeParse(c);if(!l.success)throw Error(`Remote agent "${e.action.remoteAgentName}" create-session response was invalid.`);return{sessionId:l.data.sessionId}}function buildForwardedTraceAssertion(e){let t=decisionToTraceContentCeiling(e.parentTraceContext?.decision);if(!(e.forwardedPrincipal===void 0||e.parentTraceContext===void 0||(e.parentTraceContext.traceFlags&1)!=1||e.traceparent===void 0||t===void 0))return{ceiling:t,originAudience:e.originAudience??`unknown`}}async function continueRemoteAgentSession(e){let t=buildForwardedPrincipalField(e),n={activityObserver:e.activityObserver,callback:e.callback,message:e.message,outputSchema:e.outputSchema};t!==void 0&&(n.forwardedPrincipal=t);let r=await fetch(createRemoteAgentContinueUrl(e.remote,e.sessionId),{body:JSON.stringify(n),headers:{"content-type":`application/json`,...await resolveRemoteAgentRequestHeaders(e.remote)},method:`POST`});if(!r.ok){let n=await readRemoteAgentErrorCode(r),i=r.status===404||n===AgentHandleError.SessionNotResumable.code,a=r.status===400&&t!==void 0?` The receiver may support forwarded principals only on session creation; upgrade it before retrying.`:``;throw new RemoteAgentContinueRequestError(`Remote agent "${e.remote.name}" continue-session request failed${i?` permanently`:``} with HTTP ${r.status}.${a}`,{deliveryAmbiguous:isAmbiguousRemoteContinueStatus(r.status),retryable:!i})}}var RemoteAgentContinueRequestError=class extends Error{deliveryAmbiguous;retryable;constructor(e,t){super(e),this.name=`RemoteAgentContinueRequestError`,this.deliveryAmbiguous=t.deliveryAmbiguous,this.retryable=t.retryable}};function isRetryableRemoteAgentContinueError(e){return!(e instanceof RemoteAgentContinueRequestError)||e.retryable}function isAmbiguousRemoteAgentContinueError(e){return!(e instanceof RemoteAgentContinueRequestError)||e.deliveryAmbiguous}function isAmbiguousRemoteContinueStatus(e){return e===408||e===425||e>=500}async function readRemoteAgentErrorCode(e){let t;try{t=await e.json()}catch{return}if(typeof t!=`object`||!t)return;let n=Reflect.get(t,`code`);return typeof n==`string`?n:void 0}function buildForwardedPrincipalField(e){if(e.remote.forwardPrincipal!==!0||e.auth===null||e.auth===void 0)return;let t={current:e.auth};return e.initiatorAuth!==null&&e.initiatorAuth!==void 0&&(t.initiator=e.initiatorAuth),t}async function cancelRemoteAgentTurn(e){let t=e.headers??await resolveRemoteAgentRequestHeaders(e.remote),n=await fetch(createRemoteAgentCancelTurnUrl(e.remote,e.sessionId),{body:e.turnId===void 0&&e.taskId===void 0?void 0:JSON.stringify({taskId:e.taskId,turnId:e.turnId}),headers:t,method:`POST`});if(!n.ok)throw new RemoteAgentCancelRequestError(`Remote agent "${e.remote.name}" cancel-turn request failed with HTTP ${n.status}.`,{retryable:isRetryableRemoteCancelStatus(n.status)});let r;try{r=await n.json()}catch{throw new RemoteAgentCancelRequestError(`Remote agent "${e.remote.name}" cancel-turn response was not valid JSON.`,{retryable:!1})}let i=CancelTurnResponseSchema.safeParse(r);if(!i.success||i.data.status===`accepted`&&i.data.sessionId!==e.sessionId)throw new RemoteAgentCancelRequestError(`Remote agent "${e.remote.name}" cancel-turn response was invalid.`,{retryable:!1});return i.data.status===`accepted`?{sessionId:i.data.sessionId,status:`accepted`}:{status:`no_active_turn`}}function readHeader(e,t){let n=Object.keys(e).find(e=>e.toLowerCase()===t);return n===void 0?void 0:e[n]}function setHeader(e,t,n){for(let n of Object.keys(e))n.toLowerCase()===t&&delete e[n];n!==void 0&&(e[t]=n)}async function resetRemoteAgentSession(e){let t=e.headers??await resolveRemoteAgentRequestHeaders(e.remote),n=await fetch(createRemoteAgentRouteUrl(e.remote.url,createEveSessionResetRoutePath(e.sessionId)),{body:JSON.stringify({reason:`Parent session ended`}),headers:{"content-type":`application/json`,...t},method:`POST`});if(!n.ok)throw Error(`Remote agent "${e.remote.name}" reset-session request failed with HTTP ${n.status}.`);let i=ResetResponseSchema.safeParse(await n.json());if(!i.success||i.data.status===`reset`&&i.data.previousSessionId!==e.sessionId)throw Error(`Remote agent "${e.remote.name}" reset-session response was invalid.`);return i.data}function isRetryableRemoteAgentCancelError(e){return!(e instanceof RemoteAgentCancelRequestError)||e.retryable}function resolveRemoteAgentForAction(e){let t=e.registry.get(e.nodeId)?.definition;if(e.dynamicRemoteAgent!==void 0){if(t===void 0)throw Error(`Missing remote agent "${e.remoteAgentName}" in runtime registry.`);let n=resolveDynamicRemoteAgentCredentials(e.dynamicRemoteAgent),r=e.dynamicRemoteAgent,i={description:r.description,kind:`remote`,logicalPath:t.logicalPath,name:e.remoteAgentName,nodeId:e.nodeId,outputSchema:r.outputSchema,path:r.path,sourceId:t.sourceId,sourceKind:`module`,url:r.url};return r.forwardPrincipal!==void 0&&(i.forwardPrincipal=r.forwardPrincipal),n.auth!==void 0&&(i.auth=n.auth),n.headers!==void 0&&(i.headers=n.headers),i}if(t?.kind!==`remote`)throw Error(`Missing remote agent "${e.remoteAgentName}" in runtime registry.`);return t}async function resolveRemoteAgentStreamHeaders(e){if(e.resolverId===void 0)return{};let t=new Set([e.bundle.graph.root,...e.bundle.graph.nodesByNodeId.values()]);for(let n of t){let t=n.subagentRegistry.subagentsByNodeId.get(e.resolverId)?.definition;if(t!==void 0){if(t.kind!==`remote`||t.name!==e.name||t.url!==e.url)throw Error(`Remote child stream resolver does not match the authored remote agent.`);return await resolveRemoteAgentRequestHeaders(t)}}return await resolveRemoteAgentRequestHeaders(resolveDynamicRemoteAgentCredentials({credentialsStepId:e.resolverId,description:``,path:``,url:e.url}))}function resolveDynamicRemoteAgentCredentials(e){if(e.credentialsStepId===void 0)return{};let t=getStepRegistry().get(e.credentialsStepId);if(t===void 0)throw Error(`Dynamic remote subagent credentials function "${e.credentialsStepId}" is not registered.`);let n=expectObjectRecord(t(),`Dynamic remote subagent credentials are invalid.`),r={};return n.auth!==void 0&&(r.auth=expectFunction(n.auth,`Dynamic remote subagent auth is invalid.`)),n.headers!==void 0&&(r.headers=resolveDynamicRemoteAgentHeaders(n.headers)),r}function resolveDynamicRemoteAgentHeaders(e){if(typeof e==`function`)return e;let t=expectObjectRecord(e,`Dynamic remote subagent headers are invalid.`);for(let e of Object.values(t))if(typeof e!=`string`)throw Error(`Dynamic remote subagent headers are invalid.`);return t}function getStepRegistry(){let e=Symbol.for(`@workflow/core//registeredSteps`),t=globalThis,n=t[e];return n===void 0&&(n=new Map,t[e]=n),n}function createRemoteAgentSessionUrl(e){return createRemoteAgentRouteUrl(e.url,e.path)}function createRemoteAgentCancelTurnUrl(e,t){return createRemoteAgentRouteUrl(e.url,createEveSessionCancelRoutePath(t))}function createRemoteAgentContinueUrl(e,t){return createRemoteAgentRouteUrl(e.url,createEveSessionRoutePath(t))}function isRetryableRemoteCancelStatus(e){return e===408||e===425||e===429||e>=500}async function resolveRemoteAgentRequestHeaders(e){let t={};return e.headers!==void 0&&Object.assign(t,typeof e.headers==`function`?await e.headers():e.headers),e.auth!==void 0&&Object.assign(t,(await e.auth()).headers),t}function formatRemoteAgentCallInputMessage(e){let t=typeof e.action.input.message==`string`?e.action.input.message:``;return formatSubagentInput({description:e.remote.description,message:t,name:e.action.remoteAgentName,type:`remote`}).message}export{RemoteAgentContinueRequestError,cancelRemoteAgentTurn,continueRemoteAgentSession,isAmbiguousRemoteAgentContinueError,isRetryableRemoteAgentCancelError,isRetryableRemoteAgentContinueError,resetRemoteAgentSession,resolveRemoteAgentForAction,resolveRemoteAgentStreamHeaders,startRemoteAgentSession};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { DispatchOutcome, RuntimeSession } from "#
|
|
1
|
+
import type { DispatchOutcome, RuntimeSession } from "#subagents/handle-dispatch.js";
|
|
2
2
|
import type { LocalDevRequestProvenance } from "#context/keys.js";
|
|
3
|
-
import { buildSubagentRunInput, type SubagentInputSource } from "#
|
|
3
|
+
import { buildSubagentRunInput, type SubagentInputSource } from "#subagents/tool.js";
|
|
4
4
|
import { createWorkflowRuntime } from "#execution/workflow-runtime.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { RuntimeSubagentDispatchRequest } from "#shared/action-types.js";
|
|
6
6
|
import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
|
|
7
7
|
type DynamicSubagentAgentConfig = Parameters<typeof createWorkflowRuntime>[0]["dynamicSubagentAgentConfig"];
|
|
8
8
|
/** Starts one local subagent after dispatch planning has selected its target. */
|
|
9
9
|
export declare function startLocalSubagent(input: {
|
|
10
|
-
readonly action:
|
|
10
|
+
readonly action: RuntimeSubagentDispatchRequest;
|
|
11
11
|
readonly auth: Parameters<typeof buildSubagentRunInput>[0]["auth"];
|
|
12
12
|
readonly batchEvent: {
|
|
13
13
|
readonly sequence: number;
|
|
@@ -25,9 +25,8 @@ export declare function startLocalSubagent(input: {
|
|
|
25
25
|
readonly parentTraceContext: Parameters<typeof buildSubagentRunInput>[0]["parentTraceContext"];
|
|
26
26
|
readonly activityObserver?: Parameters<typeof buildSubagentRunInput>[0]["activityObserver"];
|
|
27
27
|
readonly sandboxSessionId: string;
|
|
28
|
-
readonly selfAgent: boolean;
|
|
29
28
|
readonly session: RuntimeSession;
|
|
30
29
|
readonly source: SubagentInputSource;
|
|
31
|
-
readonly
|
|
30
|
+
readonly taskId?: string;
|
|
32
31
|
}): Promise<DispatchOutcome>;
|
|
33
32
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createLogger,logError}from"#internal/logging.js";import{ContextContainer,contextStorage}from"#context/container.js";import{toErrorMessage}from"#shared/errors.js";import{createWorkflowRuntime,waitForCommandHookOwner}from"#execution/workflow-runtime.js";import{buildSubagentRunInput}from"#subagents/tool.js";import{SUBAGENT_START_FAILED}from"#subagents/agent-handle-errors.js";const log=createLogger(`execution.subagent-start-local`);async function startLocalSubagent(e){let{action:n,source:r}=e,i=createWorkflowRuntime({compiledArtifactsSource:e.bundle.compiledArtifactsSource,dynamicSubagentAgentConfig:e.dynamicSubagentAgentConfig,nodeId:n.nodeId}),{childContinuationToken:a,runInput:o}=buildSubagentRunInput({action:n,auth:e.auth,batchEvent:e.batchEvent,capabilities:e.capabilities,channelMetadata:e.channelMetadata,fanoutSize:e.fanoutSize,initiatorAuth:e.initiatorAuth,graph:e.bundle.graph,parentContinuationToken:e.parentContinuationToken,parentTraceContext:e.parentTraceContext,activityObserver:e.activityObserver,sandboxSessionId:e.sandboxSessionId,session:e.session,selfAgent:r.type===`runtime`,source:r,taskId:e.taskId}),s=r.type===`runtime`?`agent/self`:`agent/local`,c;try{await contextStorage.run(new ContextContainer({localDevRequest:e.localDevRequest}),()=>i.createSession(o)),c=(await waitForCommandHookOwner(a)).runId}catch(t){return logError(log,`local subagent start failed`,t,{callId:n.callId,nodeId:n.nodeId,subagentName:n.subagentName}),{kind:`error`,result:{callId:n.callId,isError:!0,kind:`subagent-result`,origin:`dispatch`,output:{code:SUBAGENT_START_FAILED,message:toErrorMessage(t)},subagentName:n.subagentName},session:e.currentSession}}return{address:{continuationToken:a,kind:s,sessionId:c},callId:n.callId,kind:`called`,name:n.name,session:e.currentSession,toolName:n.subagentName}}export{startLocalSubagent};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { DispatchOutcome, RuntimeSession } from "#
|
|
2
|
-
import { resolveRemoteAgentForAction, startRemoteAgentSession } from "#
|
|
3
|
-
import type {
|
|
1
|
+
import type { DispatchOutcome, RuntimeSession } from "#subagents/handle-dispatch.js";
|
|
2
|
+
import { resolveRemoteAgentForAction, startRemoteAgentSession } from "#subagents/remote-dispatch.js";
|
|
3
|
+
import type { RuntimeRemoteAgentDispatchRequest } from "#shared/action-types.js";
|
|
4
4
|
import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
|
|
5
5
|
import type { ChannelAudience } from "#shared/channel-audience.js";
|
|
6
6
|
/** Starts one remote subagent after dispatch planning has selected its target. */
|
|
7
7
|
export declare function startRemoteSubagent(input: {
|
|
8
|
-
readonly action:
|
|
8
|
+
readonly action: RuntimeRemoteAgentDispatchRequest;
|
|
9
9
|
readonly auth: Parameters<typeof startRemoteAgentSession>[0]["auth"];
|
|
10
10
|
readonly batchEvent: {
|
|
11
11
|
readonly sequence: number;
|
|
@@ -21,5 +21,5 @@ export declare function startRemoteSubagent(input: {
|
|
|
21
21
|
readonly parentTraceContext: Parameters<typeof startRemoteAgentSession>[0]["parentTraceContext"];
|
|
22
22
|
readonly activityObserver?: Parameters<typeof startRemoteAgentSession>[0]["activityObserver"];
|
|
23
23
|
readonly session: RuntimeSession;
|
|
24
|
-
readonly
|
|
24
|
+
readonly taskId?: string;
|
|
25
25
|
}): Promise<DispatchOutcome>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createLogger,logError}from"#internal/logging.js";import{resolveRemoteAgentForAction,startRemoteAgentSession}from"#subagents/remote-dispatch.js";import{createRemoteAgentStartFailureResult}from"#execution/dispatch-action-failures.js";import{mintStartOperation}from"#execution/dispatch-start-operation.js";import{deriveChildActivityObserverConfig}from"#execution/activity-work.js";const log=createLogger(`execution.subagent-start-remote`);async function startRemoteSubagent(e){let{action:r}=e,i=deriveChildActivityObserverConfig({activityObserver:e.activityObserver,callId:r.callId,kind:`remote-agent`,name:r.remoteAgentName,parentSessionId:e.session.sessionId,parentTurnId:e.batchEvent.turnId}),a,o;try{if(e.callbackBaseUrl===void 0)throw Error(`Cannot dispatch remote agent without a callback base URL.`);a=e.callbackBaseUrl,o=resolveRemoteAgentForAction({dynamicRemoteAgent:e.dynamicRemoteAgent,nodeId:r.nodeId,remoteAgentName:r.remoteAgentName,registry:e.bundle.subagentRegistry.subagentsByNodeId})}catch(n){return logError(log,`remote agent start failed`,n,{remoteAgentName:r.remoteAgentName,nodeId:r.nodeId,callId:r.callId}),{kind:`error`,result:createRemoteAgentStartFailureResult({action:r,error:n}),session:e.currentSession}}let{operation:s}=mintStartOperation({callId:r.callId,name:r.remoteAgentName,nodeId:r.nodeId,parentSessionId:e.session.sessionId,parentTurnId:e.batchEvent.turnId}),c={resolverId:e.dynamicRemoteAgent===void 0?r.nodeId:e.dynamicRemoteAgent.credentialsStepId};try{let t=await startRemoteAgentSession({action:r,auth:e.auth,callbackBaseUrl:a,callbackToken:e.parentContinuationToken,originAudience:e.originAudience,initiatorAuth:e.initiatorAuth,operationId:s.id,parentTraceContext:e.parentTraceContext,activityObserver:i,remote:o,session:e.session,taskId:e.taskId});return{address:{callbackBaseUrl:a,credentialResolver:c,kind:`agent/remote`,sessionId:t.sessionId,url:o.url},callId:r.callId,kind:`called`,name:r.name,session:e.currentSession,toolName:r.remoteAgentName}}catch(n){return logError(log,`remote agent start failed`,n,{remoteAgentName:r.remoteAgentName,nodeId:r.nodeId,callId:r.callId}),{kind:`error`,result:createRemoteAgentStartFailureResult({action:r,error:n}),session:e.currentSession}}}export{startRemoteSubagent};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ActivityObserverConfig, ChannelInstrumentationProjection, RunInput, SessionAuthContext, SessionCapabilities, SessionTraceContext } from "#channel/types.js";
|
|
2
2
|
import type { HarnessSession } from "#harness/types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RuntimeSubagentDispatchRequest } from "#shared/action-types.js";
|
|
4
4
|
import type { JsonObject } from "#shared/json.js";
|
|
5
5
|
/**
|
|
6
|
-
* Pending
|
|
6
|
+
* Pending task batch event metadata needed for child run lineage.
|
|
7
7
|
*/
|
|
8
8
|
interface BatchEventMetadata {
|
|
9
9
|
readonly sequence: number;
|
|
@@ -47,7 +47,7 @@ export interface SubagentSandboxGraph {
|
|
|
47
47
|
* Builds the {@link RunInput} for one delegated subagent child run.
|
|
48
48
|
*/
|
|
49
49
|
export declare function buildSubagentRunInput(input: {
|
|
50
|
-
readonly action:
|
|
50
|
+
readonly action: RuntimeSubagentDispatchRequest;
|
|
51
51
|
readonly auth: SessionAuthContext | null;
|
|
52
52
|
readonly batchEvent: BatchEventMetadata;
|
|
53
53
|
/**
|
|
@@ -79,5 +79,7 @@ export declare function buildSubagentRunInput(input: {
|
|
|
79
79
|
readonly activityObserver?: ActivityObserverConfig;
|
|
80
80
|
readonly session: HarnessSession;
|
|
81
81
|
readonly source: SubagentInputSource;
|
|
82
|
+
/** Owning task when this child starts from a background workflow tool. */
|
|
83
|
+
readonly taskId?: string;
|
|
82
84
|
}): SubagentRunInputBuild;
|
|
83
85
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mintSubagentContinuationToken}from"#execution/session.js";import{SUBAGENT_ADAPTER_KIND}from"#subagents/adapter-state.js";import{formatSubagentInput,normalizeRequestedOutputSchema}from"#subagents/invocation.js";import{resolveRemainingSessionTokenLimits}from"#subagents/token-budget.js";function buildSubagentRunInput(n){let{action:r,auth:i,batchEvent:a,capabilities:o,channelMetadata:s,initiatorAuth:c,session:l,source:u}=n,d=mintSubagentContinuationToken(`${l.sessionId}:${r.callId}`),f=l.rootSessionId??l.sessionId,p=resolveRemainingSessionTokenLimits(l,n.fanoutSize),m=normalizeRequestedOutputSchema(r.input.outputSchema),h={callId:r.callId,parentContinuationToken:n.parentContinuationToken??l.continuationToken,parentSessionId:l.sessionId,subagentName:r.subagentName};n.taskId!==void 0&&(h.taskId=n.taskId),(n.graph?.nodesByNodeId.get(r.nodeId)?.sandboxRegistry.sandbox?.definition.inheritsParent===!0||n.selfAgent)&&(l.sandboxState!==void 0&&(h.parentSandboxState=l.sandboxState),h.sandboxSessionId=n.sandboxSessionId??l.sessionId);let g={adapter:{kind:SUBAGENT_ADAPTER_KIND,state:h},auth:i,capabilities:o,channelMetadata:s,continuationToken:d,initiatorAuth:c,input:{message:formatSubagentCallInputMessage({action:r,source:u}),outputSchema:m??u.outputSchema},limits:p,mode:`conversation`,parent:{callId:r.callId,rootSessionId:f,sessionId:l.sessionId,turn:{id:a.turnId,sequence:a.sequence}},parentTraceContext:n.parentTraceContext,activityObserver:n.activityObserver};return n.taskId!==void 0&&(g.taskId=n.taskId),{childContinuationToken:d,runInput:g}}function formatSubagentCallInputMessage(e){let{message:t}=e.action.input;switch(e.source.type){case`local`:return formatSubagentInput({description:e.source.description,message:t,name:e.action.subagentName,type:`local`}).message;case`runtime`:return formatSubagentInput({message:t,name:e.action.subagentName,type:`runtime`}).message;default:return e.source}}export{buildSubagentRunInput};
|
package/dist/src/svelte/index.js
CHANGED
package/dist/src/tasks/json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{TASK_VIEW_JSON_SCHEMA}from"#tools/framework/task-contract.js";function taskViewToJson(t){return TASK_VIEW_JSON_SCHEMA.parse(t)}function taskViewsToJson(e){return{tasks:e.map(e=>taskViewToJson(e))}}export{taskViewToJson,taskViewsToJson};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HarnessSession, SessionStateMap } from "#harness/types.js";
|
|
2
2
|
import type { TaskExecutorBinding } from "#tools/task.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type TaskMetadata, type TaskView } from "#tasks/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Session-state key for the parent's live-task index.
|
|
6
6
|
*
|
|
@@ -29,8 +29,7 @@ export interface SessionTaskIndexEntry {
|
|
|
29
29
|
readonly createdByStepIndex?: number;
|
|
30
30
|
readonly createdByTurnId: string;
|
|
31
31
|
readonly executor?: TaskExecutorBinding;
|
|
32
|
-
readonly metadata:
|
|
33
|
-
readonly operationId?: string;
|
|
32
|
+
readonly metadata: TaskMetadata;
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
35
|
* Reads and validates the task index from session state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z}from"#compiled/zod/index.js";import{sameTaskMetadata}from"#tasks/types.js";const SESSION_TASKS_STATE_KEY=`eve.tasks`,taskMetadataSchema=z.
|
|
1
|
+
import{z}from"#compiled/zod/index.js";import{sameTaskMetadata}from"#tasks/types.js";const SESSION_TASKS_STATE_KEY=`eve.tasks`,taskMetadataSchema=z.looseObject({kind:z.string().min(1),name:z.string().min(1)}),taskViewBaseShape={executor:z.strictObject({binding:z.strictObject({data:z.record(z.string(),z.custom()),kind:z.string().min(1)}).optional()}).optional(),metadata:taskMetadataSchema,taskId:z.string().min(1),usage:z.strictObject({cacheReadTokens:z.number().nonnegative(),cacheWriteTokens:z.number().nonnegative(),inputTokens:z.number().nonnegative(),outputTokens:z.number().nonnegative()}).optional()},taskViewSchema=z.discriminatedUnion(`status`,[z.strictObject({...taskViewBaseShape,lastOutput:z.strictObject({data:z.custom(),type:z.literal(`result`)}),status:z.literal(`completed`)}),z.strictObject({...taskViewBaseShape,lastOutput:z.strictObject({data:z.custom(),type:z.literal(`error`)}),status:z.literal(`failed`)}),z.strictObject({...taskViewBaseShape,status:z.literal(`cancelled`)})]),sessionTaskIndexEntrySchema=z.strictObject({taskInboxToken:z.string().min(1),createdByStepIndex:z.number().int().nonnegative().optional(),createdByTurnId:z.string().min(1),executor:z.strictObject({data:z.record(z.string(),z.custom()),kind:z.string().min(1)}).optional(),metadata:taskMetadataSchema,taskId:z.string().min(1),taskRunId:z.string().min(1),terminalView:taskViewSchema.optional()}),sessionTaskIndexSchema=z.strictObject({tasks:z.array(sessionTaskIndexEntrySchema),version:z.literal(2)}).refine(e=>new Set(e.tasks.map(e=>e.taskId)).size===e.tasks.length,{message:`Task ids must be unique.`}).refine(e=>e.tasks.every(e=>e.terminalView===void 0||e.terminalView.taskId===e.taskId&&sameTaskMetadata(e.terminalView.metadata,e.metadata)),{message:`Cached terminal views must match their task index entry.`});function getSessionTaskIndex(e){let t=e?.[SESSION_TASKS_STATE_KEY];if(t===void 0)return[];let n=typeof t==`object`&&t?Reflect.get(t,`version`):void 0;if(n!==2)throw Error(`Unsupported task index version ${JSON.stringify(n)} under session state key "${SESSION_TASKS_STATE_KEY}"; expected version 2.`);let r=sessionTaskIndexSchema.safeParse(t);if(!r.success)throw Error(`Corrupt task index under session state key "${SESSION_TASKS_STATE_KEY}": ${r.error.message}`);return r.data.tasks}function cacheTerminalTaskView(e,n){if(!isValidTerminalView(n))throw Error(`Cannot cache invalid terminal task "${n.taskId}".`);let r=getSessionTaskIndex(e),i=r.findIndex(e=>e.taskId===n.taskId);if(i<0)return e;if(!sameTaskMetadata(r[i].metadata,n.metadata))throw Error(`Task view metadata does not match index entry "${n.taskId}".`);let a=[...r];return a[i]={...a[i],terminalView:n},{...e,[SESSION_TASKS_STATE_KEY]:{tasks:a,version:2}}}function isValidTerminalView(e){if(e.inputRequests!==void 0)return!1;switch(e.status){case`completed`:return e.lastOutput?.type===`result`;case`failed`:return e.lastOutput?.type===`error`;case`cancelled`:return e.lastOutput===void 0;case`working`:return!1}}function findSessionTaskEntry(e,t){return getSessionTaskIndex(e).find(e=>e.taskId===t)}function recordSessionTask(e,t){let n=[...getSessionTaskIndex(e.state).filter(e=>e.taskId!==t.taskId),t];return{...e,state:{...e.state,[SESSION_TASKS_STATE_KEY]:{tasks:n,version:2}}}}export{SESSION_TASKS_STATE_KEY,cacheTerminalTaskView,findSessionTaskEntry,getSessionTaskIndex,recordSessionTask};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Derives the stable task id for one originating
|
|
2
|
+
* Derives the stable task id for one originating background call.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* for the same call yields the same task without new machinery, and a
|
|
4
|
+
* Uses `hash(parentSessionId, parentTurnId, callId)` so replayed creation
|
|
5
|
+
* for the same call yields the same task, and a
|
|
7
6
|
* task can never be confused with a child session id or continuation
|
|
8
7
|
* token.
|
|
9
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash}from"node:crypto";
|
|
1
|
+
import{createHash}from"node:crypto";function deriveTaskId(e){return`task_${createHash(`sha256`).update(`${e.parentSessionId}\0${e.parentTurnId}\0${e.callId}`).digest(`hex`).slice(0,24)}`}function deriveTaskInboxToken(e){return`task:${e.taskId}:${createHash(`sha256`).update(`${e.taskId}\0${e.parentContinuationToken}`).digest(`hex`).slice(0,32)}`}export{deriveTaskId,deriveTaskInboxToken};
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
* Action taken on one command applied to a task view.
|
|
4
|
-
*
|
|
5
|
-
* - `accepted`: the view changed; the new view must be appended.
|
|
6
|
-
* - `noop`: the command is recognized and benign (idempotent cancel,
|
|
7
|
-
* stale answer); nothing changed and nothing is appended.
|
|
8
|
-
* - `rejected`: the command is invalid for the current status; the
|
|
9
|
-
* reason is diagnostic only.
|
|
10
|
-
*/
|
|
11
|
-
type TaskTransitionResult = {
|
|
1
|
+
import { type TaskCommand, type TaskView } from "#tasks/types.js";
|
|
2
|
+
export type TaskTransitionResult = {
|
|
12
3
|
readonly action: "accepted";
|
|
13
4
|
readonly view: TaskView;
|
|
14
5
|
} | {
|
|
@@ -19,40 +10,5 @@ type TaskTransitionResult = {
|
|
|
19
10
|
readonly view: TaskView;
|
|
20
11
|
readonly reason: string;
|
|
21
12
|
};
|
|
22
|
-
/**
|
|
23
|
-
* Pure transition function for the task lifecycle:
|
|
24
|
-
*
|
|
25
|
-
* ```text
|
|
26
|
-
* working <-> input_required
|
|
27
|
-
* | |
|
|
28
|
-
* +-----> completed
|
|
29
|
-
* +-----> failed
|
|
30
|
-
* +-----> cancelled
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* Terminal states are final: a late child result can never revive a
|
|
34
|
-
* cancelled task, and repeated cancellation is idempotent. The durable
|
|
35
|
-
* task run is the only caller that persists accepted views, which is
|
|
36
|
-
* what serializes competing completion, cancellation, and input
|
|
37
|
-
* transitions.
|
|
38
|
-
*
|
|
39
|
-
* Orthogonal to the status, the view carries private executor state
|
|
40
|
-
* (`TaskExecutorState`) with its own lifecycle. These commands move
|
|
41
|
-
* executor fields, never the status above:
|
|
42
|
-
*
|
|
43
|
-
* ```text
|
|
44
|
-
* binding: unset --bind-------> bound (replay noop, conflict rejected)
|
|
45
|
-
* address: unset --start-turn-> session pinned (turn id updated per delivery)
|
|
46
|
-
* verdict: unset --complete/fail/cancel/settle-executor-> parked | terminal
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* - `bind` writes the executor binding exactly once: replaying the
|
|
50
|
-
* same binding is a noop, a different one is rejected.
|
|
51
|
-
* - `start-turn` records the child session/turn ids used to address
|
|
52
|
-
* the executor, rejecting a child-session mismatch.
|
|
53
|
-
* - Terminal commands and a late `settle-executor` record the child's
|
|
54
|
-
* lifecycle verdict: `parked` means the child session survived and
|
|
55
|
-
* can take another delivery, `terminal` means it ended with the turn.
|
|
56
|
-
*/
|
|
13
|
+
/** Pure, executor-neutral transition function for one durable task. */
|
|
57
14
|
export declare function applyTaskTransition(view: TaskView, command: TaskCommand): TaskTransitionResult;
|
|
58
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsonValuesEqual}from"#shared/json.js";import{isTerminalTaskStatus,readTaskInputRequestId}from"#tasks/types.js";function terminalView(e,t,n){let r
|
|
1
|
+
import{jsonValuesEqual}from"#shared/json.js";import{isTerminalTaskStatus,readTaskInputRequestId}from"#tasks/types.js";function terminalView(e,t,n){let r=`usage`in t?t.usage:void 0,i={executor:e.executor,metadata:e.metadata,taskId:e.taskId};switch(r!==void 0&&(i.usage=r),n.status){case`completed`:return{...i,lastOutput:n.lastOutput,status:`completed`};case`failed`:return{...i,lastOutput:n.lastOutput,status:`failed`};case`cancelled`:return{...i,status:`cancelled`}}}function applyTaskTransition(r,i){if(i.kind===`bind`){let t=r.executor?.binding;return t!==void 0&&t.kind===i.executor.kind&&jsonValuesEqual(t.data,i.executor.data)?{action:`noop`,view:r}:t===void 0?{action:`accepted`,view:{...r,executor:{...r.executor,binding:i.executor}}}:{action:`rejected`,reason:`Task "${r.taskId}" already has an executor binding.`,view:r}}if(isTerminalTaskStatus(r.status))return i.kind===`cancel`&&r.status===`cancelled`?{action:`noop`,view:r}:{action:`rejected`,reason:`Task "${r.taskId}" is already ${r.status}; "${i.kind}" cannot change a terminal task.`,view:r};switch(i.kind){case`complete`:return{action:`accepted`,view:terminalView(r,i,{lastOutput:{data:i.data,type:`result`},status:`completed`})};case`fail`:case`reject-dispatch`:return{action:`accepted`,view:terminalView(r,i,{lastOutput:{data:i.data,type:`error`},status:`failed`})};case`cancel`:return{action:`accepted`,view:terminalView(r,i,{status:`cancelled`})};case`require-input`:return isValidInputRequestBatch(i.inputRequests)?{action:`accepted`,view:{inputRequests:i.inputRequests,executor:r.executor,metadata:r.metadata,status:`input_required`,taskId:r.taskId}}:{action:`rejected`,reason:`Task "${r.taskId}" received an invalid input request batch.`,view:r};case`ready`:return{action:`accepted`,view:r};case`answered`:{if(r.status!==`input_required`)return{action:`noop`,view:r};let e=new Set(i.requestIds),t=r.inputRequests.filter(t=>{let r=readTaskInputRequestId(t);return r===void 0||!e.has(r)});return t.length===r.inputRequests.length?{action:`noop`,view:r}:t.length>0?{action:`accepted`,view:{...r,inputRequests:t}}:{action:`accepted`,view:{executor:r.executor,metadata:r.metadata,status:`working`,taskId:r.taskId}}}}}function isValidInputRequestBatch(e){if(e.length===0)return!1;let t=e.map(readTaskInputRequestId);return t.every(e=>e!==void 0&&e.length>0)&&new Set(t).size===t.length}export{applyTaskTransition};
|