eve 0.81.0 → 0.82.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 +37 -0
- package/dist/src/channel/channel-address.d.ts +21 -2
- package/dist/src/channel/channel-address.js +1 -1
- package/dist/src/channel/channel-operations.d.ts +32 -1
- package/dist/src/channel/channel-operations.js +1 -1
- package/dist/src/channel/delivery-idempotency.d.ts +4 -0
- package/dist/src/channel/delivery-idempotency.js +1 -0
- package/dist/src/channel/routes.d.ts +6 -0
- package/dist/src/channel/session.d.ts +5 -0
- package/dist/src/channel/session.js +1 -1
- package/dist/src/channel/types.d.ts +14 -11
- package/dist/src/chunks/{use-eve-agent-Bp6nbhfV.js → use-eve-agent-DTu78IAF.js} +36 -0
- package/dist/src/chunks/{use-eve-agent-DLkjJIm3.js → use-eve-agent-DlznYwQk.js} +36 -0
- package/dist/src/cli/dev/command-options.d.ts +1 -0
- package/dist/src/cli/dev/diagnostic-dump.js +1 -1
- package/dist/src/cli/run.d.ts +1 -0
- package/dist/src/cli/run.js +1 -1
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/message-reducer-types.d.ts +7 -3
- package/dist/src/client/message-reducer.js +1 -1
- package/dist/src/client/transcript-reducer.d.ts +6 -3
- package/dist/src/client/transcript-reducer.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +2 -2
- package/dist/src/compiled/@eve/catalog/index.js +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +19 -18
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/load-binding-namespace.d.ts +2 -0
- package/dist/src/compiler/load-binding-namespace.js +1 -1
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/module-lifecycle.d.ts +1 -1
- package/dist/src/compiler/module-lifecycle.js +1 -1
- package/dist/src/compiler/module-map.js +1 -1
- package/dist/src/compiler/normalize-agent-config.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +1 -1
- package/dist/src/compiler/project-sources.d.ts +6 -0
- package/dist/src/compiler/project-sources.js +1 -1
- package/dist/src/context/keys.d.ts +2 -0
- package/dist/src/context/keys.js +1 -1
- package/dist/src/evals/cli/eval-state-directory.d.ts +7 -0
- package/dist/src/evals/cli/eval-state-directory.js +1 -0
- package/dist/src/evals/cli/eval.js +2 -2
- package/dist/src/eve-channel/create-request.d.ts +2 -1
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/eve-channel/request.d.ts +2 -1
- package/dist/src/eve-channel/request.js +1 -2
- package/dist/src/eve-channel/support.d.ts +11 -1
- package/dist/src/eve-channel/support.js +2 -1
- package/dist/src/eve-channel/types.d.ts +25 -0
- package/dist/src/execution/agent-sessions/context.d.ts +2 -13
- package/dist/src/execution/agent-sessions/context.js +1 -1
- package/dist/src/execution/agent-sessions/runtime-overrides.d.ts +5 -0
- package/dist/src/execution/agent-sessions/runtime-overrides.js +1 -0
- package/dist/src/execution/agent-sessions/session.d.ts +2 -2
- package/dist/src/execution/agent-sessions/session.js +1 -1
- package/dist/src/execution/agent-sessions/steps.d.ts +2 -0
- package/dist/src/execution/agent-sessions/steps.js +1 -1
- package/dist/src/execution/coordination-dispatch-shared.d.ts +5 -5
- package/dist/src/execution/coordination-dispatch-step.d.ts +17 -2
- package/dist/src/execution/coordination-dispatch-step.js +1 -1
- package/dist/src/execution/create-session-step.d.ts +5 -2
- package/dist/src/execution/create-session-step.js +1 -1
- package/dist/src/execution/deliver-payloads.js +1 -1
- package/dist/src/execution/durable-session-store.d.ts +0 -1
- package/dist/src/execution/dynamic-connection-recovery.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/effective-agent-config.d.ts +8 -2
- package/dist/src/execution/effective-agent-config.js +1 -1
- package/dist/src/execution/hook-ownership.d.ts +8 -0
- package/dist/src/execution/hook-ownership.js +1 -1
- package/dist/src/execution/install-workflow-deployment-id.d.ts +3 -0
- package/dist/src/execution/install-workflow-deployment-id.js +1 -0
- package/dist/src/execution/legacy-session/turn-workflow.js +1 -1
- package/dist/src/execution/node-step.d.ts +1 -0
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/runtime-context.d.ts +2 -0
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/session/active-turn.js +1 -1
- package/dist/src/execution/session/admission.js +1 -1
- package/dist/src/execution/session/checkpoint-migrations.js +1 -1
- package/dist/src/execution/session/entry-input.d.ts +20 -8
- package/dist/src/execution/session/entry-input.js +1 -1
- package/dist/src/execution/session/entry.js +1 -1
- package/dist/src/execution/session/finalization.js +1 -1
- package/dist/src/execution/session/handoff-steps.d.ts +75 -13
- package/dist/src/execution/session/handoff-steps.js +1 -1
- package/dist/src/execution/session/handoff.d.ts +73 -34
- package/dist/src/execution/session/handoff.js +1 -1
- package/dist/src/execution/session/input-queue.d.ts +5 -1
- package/dist/src/execution/session/input-queue.js +1 -1
- package/dist/src/execution/session/pending-history.d.ts +5 -0
- package/dist/src/execution/session/pending-history.js +1 -0
- package/dist/src/execution/session/pending-turn-state.js +1 -1
- package/dist/src/execution/session/program.d.ts +1 -1
- package/dist/src/execution/session/program.js +1 -1
- package/dist/src/execution/session/run-watch.d.ts +22 -0
- package/dist/src/execution/session/run-watch.js +1 -0
- package/dist/src/execution/session/timeout-control.d.ts +18 -4
- package/dist/src/execution/session/timeout-control.js +1 -1
- package/dist/src/execution/session/timeout.d.ts +1 -2
- package/dist/src/execution/session/timeout.js +1 -1
- package/dist/src/execution/session/turn-event-handler.js +1 -1
- package/dist/src/execution/session/turn-step-result.js +1 -1
- package/dist/src/execution/session/turn-step.js +1 -1
- package/dist/src/execution/session/turn-waiting-step.js +1 -1
- package/dist/src/execution/session/turn.js +1 -1
- package/dist/src/execution/session-inbox/address.d.ts +4 -1
- package/dist/src/execution/session-inbox/end-stranded-session.js +1 -1
- package/dist/src/execution/session-inbox/hook-release.d.ts +9 -2
- package/dist/src/execution/session-inbox/hook-release.js +1 -1
- package/dist/src/execution/session-inbox/inbox.d.ts +66 -6
- package/dist/src/execution/session-inbox/inbox.js +1 -1
- package/dist/src/execution/session-inbox/protocol.js +1 -1
- package/dist/src/execution/session-inbox/resume.d.ts +4 -3
- package/dist/src/execution/session.d.ts +0 -12
- package/dist/src/execution/session.js +2 -2
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/tasks/model-step.js +1 -1
- package/dist/src/execution/tasks/start.d.ts +4 -4
- package/dist/src/execution/tasks/start.js +1 -1
- package/dist/src/execution/tasks/steps.js +1 -1
- package/dist/src/execution/terminate-child-sessions-step.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/tools/workflow/body.d.ts +2 -2
- package/dist/src/execution/workflow-runtime.d.ts +11 -12
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/harness/hitl/approvals.js +1 -1
- package/dist/src/harness/hitl/budget-request.d.ts +12 -6
- package/dist/src/harness/hitl/budget-request.js +1 -1
- package/dist/src/harness/hitl/budget.d.ts +7 -1
- package/dist/src/harness/hitl/budget.js +1 -1
- package/dist/src/harness/hitl/coordinator.js +1 -1
- package/dist/src/harness/hitl/delivery.d.ts +1 -1
- package/dist/src/harness/hitl/delivery.js +1 -1
- package/dist/src/harness/hitl/index.js +1 -1
- package/dist/src/harness/hitl/intake.d.ts +2 -2
- package/dist/src/harness/hitl/intake.js +1 -1
- package/dist/src/harness/messages.d.ts +5 -0
- package/dist/src/harness/messages.js +1 -1
- package/dist/src/harness/model-call/call.d.ts +2 -2
- package/dist/src/harness/model-call/call.js +1 -1
- package/dist/src/harness/model-call/request.d.ts +2 -2
- package/dist/src/harness/session-machine/transitions.d.ts +3 -1
- package/dist/src/harness/session-machine/transitions.js +1 -1
- package/dist/src/harness/step/context.d.ts +3 -0
- package/dist/src/harness/step/context.js +1 -1
- package/dist/src/harness/step/intake.d.ts +5 -2
- package/dist/src/harness/step/intake.js +1 -1
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/harness/turn-tag-state.d.ts +7 -26
- package/dist/src/harness/turn-tag-state.js +1 -1
- package/dist/src/harness/types.d.ts +10 -25
- package/dist/src/instrumentation/content.d.ts +1 -1
- package/dist/src/instrumentation/content.js +1 -1
- package/dist/src/instrumentation/lifecycle.d.ts +4 -2
- package/dist/src/internal/application/build-profile.d.ts +3 -0
- package/dist/src/internal/application/build-profile.js +1 -1
- package/dist/src/internal/application/compiled-artifacts.js +2 -2
- package/dist/src/internal/application/dev-environment.d.ts +13 -0
- package/dist/src/internal/application/dev-environment.js +1 -1
- package/dist/src/internal/application/stamped-package-version.js +1 -1
- package/dist/src/internal/authored-definition/connection.js +1 -1
- package/dist/src/internal/authored-definition/core.js +1 -1
- package/dist/src/internal/authored-module-build-options.d.ts +7 -0
- package/dist/src/internal/authored-module-build-options.js +1 -0
- package/dist/src/internal/authored-module-graph.d.ts +13 -0
- package/dist/src/internal/authored-module-graph.js +1 -0
- package/dist/src/internal/authored-module-loader.d.ts +22 -1
- package/dist/src/internal/authored-module-loader.js +1 -3
- package/dist/src/internal/authored-module.d.ts +7 -0
- package/dist/src/internal/authored-module.js +1 -1
- package/dist/src/internal/authored-package-boundary.js +1 -1
- package/dist/src/internal/bundler/nitro-rolldown.d.ts +5 -1
- package/dist/src/internal/bundler/nitro-rolldown.js +1 -1
- package/dist/src/internal/development-programmatic-source-loader.d.ts +1 -0
- package/dist/src/internal/development-programmatic-source-loader.js +1 -1
- package/dist/src/internal/mcp/skills.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-generation-metadata.js +1 -1
- package/dist/src/internal/nitro/host/build-application.js +1 -1
- package/dist/src/internal/nitro/host/build-deployment-id.d.ts +8 -0
- package/dist/src/internal/nitro/host/build-deployment-id.js +1 -0
- package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
- package/dist/src/internal/nitro/host/dev-server-state.js +1 -1
- package/dist/src/internal/nitro/host/skill-server-assets.js +1 -1
- package/dist/src/internal/nitro/host/stage-build-deployment-id.d.ts +2 -0
- package/dist/src/internal/nitro/host/stage-build-deployment-id.js +1 -0
- package/dist/src/internal/nitro/host/start-production-server.d.ts +1 -0
- package/dist/src/internal/nitro/host/start-production-server.js +3 -3
- package/dist/src/internal/nitro/routes/schedule-task.d.ts +3 -0
- package/dist/src/internal/nitro/routes/schedule-task.js +1 -1
- package/dist/src/internal/programmatic-source-loader.d.ts +1 -0
- package/dist/src/internal/programmatic-source-loader.js +1 -1
- package/dist/src/internal/schedules/disabled.d.ts +2 -0
- package/dist/src/internal/schedules/disabled.js +1 -0
- package/dist/src/internal/workflow/development-world-client.js +1 -1
- package/dist/src/internal/workflow/development-world-server.js +1 -1
- package/dist/src/internal/workflow/local-world-data-directory.d.ts +2 -1
- package/dist/src/internal/workflow/local-world-data-directory.js +1 -1
- package/dist/src/internal/workflow-bundle/builder.js +1 -1
- package/dist/src/protocol/message.d.ts +27 -1
- package/dist/src/protocol/message.js +2 -2
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.d.ts +13 -0
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +2 -2
- package/dist/src/public/channels/chat-sdk/fetch-message.d.ts +10 -0
- package/dist/src/public/channels/chat-sdk/fetch-message.js +1 -0
- package/dist/src/public/channels/chat-sdk/index.d.ts +1 -1
- package/dist/src/public/channels/chat-sdk/messageToUserContent.d.ts +2 -1
- package/dist/src/public/channels/chat-sdk/messageToUserContent.js +1 -1
- package/dist/src/public/channels/chat-sdk/reply-context.d.ts +15 -0
- package/dist/src/public/channels/chat-sdk/reply-context.js +2 -0
- package/dist/src/public/channels/discord/discordChannel.d.ts +3 -0
- package/dist/src/public/channels/discord/discordChannel.js +1 -1
- package/dist/src/public/channels/github/dispatch.js +1 -1
- package/dist/src/public/channels/github/githubChannel.d.ts +3 -0
- package/dist/src/public/channels/imessage-tapbacks.d.ts +74 -0
- package/dist/src/public/channels/imessage-tapbacks.js +1 -0
- package/dist/src/public/channels/index.d.ts +2 -1
- package/dist/src/public/channels/index.js +1 -1
- package/dist/src/public/channels/linear/linearChannel.d.ts +3 -0
- package/dist/src/public/channels/linear/linearChannel.js +1 -1
- package/dist/src/public/channels/linq/inboundContent.d.ts +7 -0
- package/dist/src/public/channels/linq/inboundContent.js +1 -1
- package/dist/src/public/channels/linq/index.d.ts +1 -0
- package/dist/src/public/channels/linq/index.js +1 -1
- package/dist/src/public/channels/linq/linqChannel.d.ts +17 -1
- package/dist/src/public/channels/linq/linqChannel.js +1 -1
- package/dist/src/public/channels/photon/attachments.d.ts +5 -2
- package/dist/src/public/channels/photon/attachments.js +1 -1
- package/dist/src/public/channels/photon/inboundContent.d.ts +7 -0
- package/dist/src/public/channels/photon/inboundContent.js +2 -1
- package/dist/src/public/channels/photon/index.d.ts +1 -0
- package/dist/src/public/channels/photon/index.js +1 -1
- package/dist/src/public/channels/photon/photonIMessageChannel.d.ts +17 -1
- package/dist/src/public/channels/photon/photonIMessageChannel.js +1 -1
- package/dist/src/public/channels/slack/api.d.ts +14 -1
- package/dist/src/public/channels/slack/api.js +1 -1
- package/dist/src/public/channels/slack/model-context.d.ts +7 -0
- package/dist/src/public/channels/slack/model-context.js +1 -1
- package/dist/src/public/channels/slack/reply-delivery.d.ts +5 -0
- package/dist/src/public/channels/slack/reply-delivery.js +1 -1
- package/dist/src/public/channels/slack/slackChannel.d.ts +17 -3
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/teams/teamsChannel.d.ts +3 -0
- package/dist/src/public/channels/teams/teamsChannel.js +1 -1
- package/dist/src/public/channels/telegram/telegramChannel.d.ts +3 -0
- package/dist/src/public/channels/telegram/telegramChannel.js +1 -1
- package/dist/src/public/definitions/agent.d.ts +1 -1
- package/dist/src/public/definitions/channel.d.ts +2 -2
- package/dist/src/public/definitions/channel.js +1 -1
- package/dist/src/public/definitions/hook.d.ts +1 -0
- package/dist/src/public/index.d.ts +1 -1
- package/dist/src/public/tools/index.d.ts +1 -1
- package/dist/src/runtime/agent/resolve-model.d.ts +4 -0
- package/dist/src/runtime/agent/resolve-model.js +1 -1
- package/dist/src/runtime/resolve-agent.js +1 -1
- package/dist/src/runtime/sessions/compiled-agent-cache.js +1 -1
- package/dist/src/runtime/subagents/dynamic-agent-config.d.ts +2 -1
- package/dist/src/runtime/subagents/dynamic-agent-config.js +1 -1
- package/dist/src/runtime/types.d.ts +3 -2
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/agent-definition.d.ts +31 -42
- package/dist/src/shared/gateway-routing.d.ts +20 -0
- package/dist/src/shared/gateway-routing.js +1 -0
- package/dist/src/shared/session-history.d.ts +22 -0
- package/dist/src/shared/session-history.js +1 -0
- package/dist/src/shared/skill-package.js +1 -1
- package/dist/src/subagents/tool.d.ts +1 -3
- package/dist/src/subagents/tool.js +1 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/tools/workflow-definition.d.ts +14 -1
- package/dist/src/tracing/eve/agent-otel-provider.js +1 -1
- package/dist/src/tracing/eve/conversation-context.d.ts +4 -1
- package/dist/src/tracing/eve/conversation-context.js +1 -1
- package/dist/src/tracing/eve/gateway.d.ts +5 -0
- package/dist/src/tracing/eve/gateway.js +1 -1
- package/dist/src/tracing/eve/invoke-tool-span.js +1 -1
- package/dist/src/tracing/eve/operation-input.d.ts +0 -12
- package/dist/src/tracing/eve/operation-input.js +1 -1
- package/dist/src/tracing/eve/otel-registration.js +1 -1
- package/dist/src/tracing/eve/policy.d.ts +1 -1
- package/dist/src/tracing/eve/policy.js +1 -1
- package/dist/src/tracing/eve/session.d.ts +5 -2
- package/dist/src/tracing/eve/session.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/README.md +1 -0
- package/docs/agent-config.md +108 -65
- package/docs/channels/chat-sdk.mdx +10 -3
- package/docs/channels/custom.mdx +38 -6
- package/docs/channels/eve.mdx +73 -0
- package/docs/channels/linq.mdx +51 -0
- package/docs/channels/photon.mdx +68 -2
- package/docs/channels/slack.mdx +6 -2
- package/docs/concepts/built-in-tools.md +1 -1
- package/docs/concepts/execution-model-and-durability.mdx +27 -11
- package/docs/concepts/sessions-runs-and-streaming.md +9 -8
- package/docs/connections/overview.mdx +1 -1
- package/docs/experimental/dynamic-schedules.mdx +186 -0
- package/docs/experimental/meta.json +4 -0
- package/docs/guides/client/streaming.mdx +1 -0
- package/docs/guides/deployment/self-hosting.md +3 -0
- package/docs/guides/hooks.md +21 -1
- package/docs/guides/instrumentation/otel.mdx +20 -0
- package/docs/memory/overview.mdx +2 -1
- package/docs/patterns/dynamic-scheduling.md +3 -1
- package/docs/patterns/meta.json +1 -0
- package/docs/patterns/voice-notes.md +67 -0
- package/docs/reference/cli.md +14 -7
- package/docs/sandbox/index.mdx +2 -0
- package/docs/schedules.mdx +2 -0
- package/docs/subagents/index.mdx +2 -0
- package/docs/tools/overview.mdx +2 -1
- package/docs/tools/tasks-upgrade.md +12 -7
- package/docs/tools/tasks.md +10 -6
- package/docs/tools/workflows.mdx +36 -5
- package/docs/tutorial/connect-a-warehouse.mdx +1 -1
- package/docs/tutorial/run-analysis.mdx +1 -1
- package/package.json +1 -1
- package/dist/src/execution/run-session-limits.d.ts +0 -12
- package/dist/src/execution/run-session-limits.js +0 -1
- package/dist/src/harness/session-usage-limits.d.ts +0 -49
- package/dist/src/harness/session-usage-limits.js +0 -1
- package/dist/src/subagents/token-budget.d.ts +0 -15
- package/dist/src/subagents/token-budget.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChannelInstrumentationProjection,
|
|
1
|
+
import type { ChannelInstrumentationProjection, SessionCapabilities, SessionParent, SessionTraceRoot } from "#channel/types.js";
|
|
2
2
|
import type { LocalDevRequestProvenance } from "#context/keys.js";
|
|
3
3
|
import { type StubScope } from "#tool-stubs/types.js";
|
|
4
4
|
import { type SessionSchedule } from "#context/session-schedule.js";
|
|
@@ -31,8 +31,6 @@ export interface AgentSessionContext {
|
|
|
31
31
|
readonly conversation?: ConversationContext;
|
|
32
32
|
/** Dynamic agents the calling turn selected, by node id. */
|
|
33
33
|
readonly dynamicSelections: DynamicSubagentSelections;
|
|
34
|
-
/** The token budget each session inherits: its share of the caller's remaining quota. */
|
|
35
|
-
readonly limits: RunSessionLimits;
|
|
36
34
|
readonly localDevRequest?: LocalDevRequestProvenance;
|
|
37
35
|
/** The calling session, turn, and tool call, recorded as each session's lineage. */
|
|
38
36
|
readonly parent: SessionParent;
|
|
@@ -52,15 +50,6 @@ export interface AgentSessionSandbox {
|
|
|
52
50
|
readonly state?: SandboxState;
|
|
53
51
|
}
|
|
54
52
|
type CallerDispatch = Pick<PreparedCoordinationDispatch<unknown>, "batch" | "bundle" | "capabilities" | "channelMetadata" | "dynamicSubagentSelections" | "inheritedConversation" | "localDevRequest" | "sandboxSessionId" | "serializedContext" | "session" | "traceRoot" | "workflowAgents">;
|
|
55
|
-
/**
|
|
56
|
-
* The token budget every session a model step's calls open inherits: the
|
|
57
|
-
* caller's remaining quota split evenly across the agent tasks the step
|
|
58
|
-
* starts, local or remote, so those tasks are bounded by the remainder
|
|
59
|
-
* together. Sessions a workflow tool opens with `ctx.agent` get the same
|
|
60
|
-
* share without dividing it further. A call to a running task starts none,
|
|
61
|
-
* so it takes no share.
|
|
62
|
-
*/
|
|
63
|
-
export declare function resolveStepAgentLimits(caller: Pick<PreparedCoordinationDispatch, "plan" | "session">): RunSessionLimits;
|
|
64
53
|
/** Captures the agent session context for one workflow tool call, in the step that admits it. */
|
|
65
|
-
export declare function captureAgentSessionContext(caller: CallerDispatch, callId: string
|
|
54
|
+
export declare function captureAgentSessionContext(caller: CallerDispatch, callId: string): AgentSessionContext;
|
|
66
55
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readSerializedSessionSchedule}from"#context/session-schedule.js";import{STUB_CONTEXT_KEY}from"#tool-stubs/types.js";import{serializeDurableCompiledArtifactsSource}from"#runtime/durable-compiled-artifacts-source.js";import{
|
|
1
|
+
import{readSerializedSessionSchedule}from"#context/session-schedule.js";import{STUB_CONTEXT_KEY}from"#tool-stubs/types.js";import{serializeDurableCompiledArtifactsSource}from"#runtime/durable-compiled-artifacts-source.js";import{resolveToolCallAgentTrace}from"#tracing/eve/agent-invocation-coordinator.js";function captureAgentSessionContext(e,t){let{batch:n,session:r}=e;return{agents:e.workflowAgents,toolStubs:e.serializedContext[STUB_CONTEXT_KEY],bundle:{nodeId:e.bundle.nodeId,source:serializeDurableCompiledArtifactsSource(e.bundle.compiledArtifactsSource)},capabilities:e.capabilities,schedule:readSerializedSessionSchedule(e.serializedContext),channelMetadata:e.channelMetadata,conversation:e.inheritedConversation,dynamicSelections:e.dynamicSubagentSelections,localDevRequest:e.localDevRequest,parent:{callId:t,rootSessionId:r.rootSessionId??r.sessionId,sessionId:r.sessionId,turn:{id:n.event.turnId,sequence:n.event.sequence}},sandbox:{sessionId:e.sandboxSessionId,state:r.sandboxState},traceRoot:e.traceRoot,trace:resolveToolCallAgentTrace({callId:t,conversation:e.inheritedConversation,serializedContext:e.serializedContext,sessionId:r.sessionId,turnId:n.event.turnId})}}export{captureAgentSessionContext};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RunUsageTally } from "#execution/agent-sessions/usage.js";
|
|
2
2
|
import type { WorkflowToolRunContext } from "#execution/tools/workflow/ask.js";
|
|
3
|
-
import type { AgentSession } from "#tools/workflow-definition.js";
|
|
3
|
+
import type { AgentSession, AgentSessionOptions } from "#tools/workflow-definition.js";
|
|
4
4
|
/**
|
|
5
5
|
* Opens `ctx.agent` sessions for a workflow run. A handle's position in the
|
|
6
6
|
* run names its session, so replay reaches the same one, and `close` ends
|
|
@@ -8,5 +8,5 @@ import type { AgentSession } from "#tools/workflow-definition.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function createAgentSessions(run: WorkflowToolRunContext, usage: RunUsageTally): {
|
|
10
10
|
readonly close: () => Promise<void>;
|
|
11
|
-
readonly open: (name: string) => AgentSession;
|
|
11
|
+
readonly open: (name: string, options?: AgentSessionOptions) => AgentSession;
|
|
12
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toErrorMessage}from"#shared/errors.js";import{createHook}from"#compiled/@workflow/core/index.js";import{normalizeRequestedOutputSchema}from"#subagents/invocation.js";import{forwardAgentSessionRequest}from"#execution/agent-sessions/requests.js";import{cancelAgentSessionTurnStep,endAgentSessionsStep,openAgentSessionStep,sendAgentSessionMessageStep}from"#execution/agent-sessions/steps.js";import{disposeHook}from"#execution/hook-ownership.js";import{serializeOutputSchema}from"#tools/schema-emission.js";function createAgentSessions(e,t){let n=[],r=0;return{open:i=>{if(typeof i!=`string`||i.trim()===``)throw TypeError(`ctx.agent() requires a non-empty agent name.`);let
|
|
1
|
+
import{toErrorMessage}from"#shared/errors.js";import{createHook}from"#compiled/@workflow/core/index.js";import{normalizeRequestedOutputSchema}from"#subagents/invocation.js";import{forwardAgentSessionRequest}from"#execution/agent-sessions/requests.js";import{cancelAgentSessionTurnStep,endAgentSessionsStep,openAgentSessionStep,sendAgentSessionMessageStep}from"#execution/agent-sessions/steps.js";import{disposeHook}from"#execution/hook-ownership.js";import{serializeOutputSchema}from"#tools/schema-emission.js";function createAgentSessions(e,t){let n=[],r=0;return{open:(i,a={})=>{if(typeof i!=`string`||i.trim()===``)throw TypeError(`ctx.agent() requires a non-empty agent name.`);let o=`${e.from.runId}:${String(r)}`;return r+=1,new RunAgentSession({key:o,name:i,options:a,run:e,sessions:n,usage:t})},close:async()=>{n.length!==0&&await endAgentSessionsStep({sessions:n})}}}var RunAgentSession=class{#e;#t;#n;#r;#i;#a;#o;#s=[];constructor(e){this.#e=e.key,this.#t=e.name,this.#n=e.options,this.#r=e.run,this.#i=e.sessions,this.#a=e.usage}async send(e,t={}){if(typeof e!=`string`||e.trim()===``)throw TypeError(`ctx.agent("${this.#t}").send() requires a non-empty message.`);let n=normalizeRequestedOutputSchema(serializeOutputSchema(t.outputSchema)),r=this.#c(n!==void 0);try{await this.#d({auth:this.#r.auth,message:e,outputSchema:n,replyTo:r.hook.token})}catch(e){throw this.#s.splice(this.#s.indexOf(r),1),await releaseHook(r.hook),e}return t.signal!==void 0&&this.#p(r,t.signal),{result:()=>r.ended.then(unwrapTurnEnd)}}#c(e){let t=createHook(),settle=()=>{},n={ended:new Promise(e=>{settle=e}),hook:t,settle};return this.#s.push(n),this.#l(t,e).then(e=>this.#u(n,e)),n}async#l(e,t){try{for await(let n of e){if(n.kind!==`runtime-action-result`){await forwardAgentSessionRequest({from:this.#r.from,owner:this.#r.owner,replyTo:e.token,request:n,remote:this.#o===void 0?void 0:await this.#o.then(({address:e})=>e.kind===`remote`?{forwardPrincipal:e.forwardPrincipal,name:e.name,resolverId:e.resolverId,url:e.url,sessionId:e.sessionId}:void 0)});continue}let r=n.results.find(e=>e.kind===`subagent-result`);if(r!==void 0)return r.origin===`child`&&this.#a.record(r.outcome.usageDelta),{kind:`ended`,result:toAgentMessageResult(r,t)}}return{error:Error(`Agent "${this.#t}" stopped reporting before its turn ended.`),kind:`failed`}}catch(e){return{error:e,kind:`failed`}}}async#u(e,t){let n=this.#s.indexOf(e);if(!(n<0))for(let e of this.#s.splice(0,n+1))e.settle(t),await releaseHook(e.hook)}async#d(e){if(this.#o===void 0){this.#o=this.#f(e),await this.#o;return}let t=await this.#o;await sendAgentSessionMessageStep({...e,...t})}async#f(e){let{agentContext:t,from:n}=this.#r;try{let r=await openAgentSessionStep({...e,context:t,key:this.#e,model:this.#n.model,name:this.#t}),i={address:r,context:t,key:this.#e};return this.#i.push(i),await this.#r.owner.send({from:n,kind:`agent-started`,session:r}),i}catch(e){throw this.#o=void 0,e}}#p(e,t){let cancel=()=>{this.#s.includes(e)&&this.#o!==void 0&&this.#o.then(e=>cancelAgentSessionTurnStep(e)).catch(()=>{})};if(t.aborted){cancel();return}t.addEventListener(`abort`,cancel,{once:!0})}};async function releaseHook(e){try{await disposeHook(e)}catch{}}function unwrapTurnEnd(e){if(e.kind===`failed`)throw e.error;return e.result}const NO_REPLY={data:void 0,message:void 0};function failedTurn(e){return{...NO_REPLY,error:{message:toErrorMessage(e)},status:`failed`}}function toAgentMessageResult(e,t){if(e.origin!==`child`)return failedTurn(e.output);let{outcome:n}=e;switch(n.result.kind){case`failed`:return failedTurn(n.result.error);case`cancelled`:return{...NO_REPLY,status:`waiting`};case`succeeded`:{let{output:e}=n.result,r=n.kind===`terminal`?`completed`:`waiting`;return t?{data:e,message:void 0,status:r}:{data:void 0,message:typeof e==`string`?e:void 0,status:r}}}}export{createAgentSessions};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SessionAuth } from "#context/session-context.js";
|
|
2
2
|
import type { AgentSessionContext } from "#execution/agent-sessions/context.js";
|
|
3
3
|
import type { JsonObject } from "#shared/json.js";
|
|
4
|
+
import type { AgentSessionModelSelection } from "#tools/workflow-definition.js";
|
|
4
5
|
/** Where a session a run opened lives, for its later sends, cancels, and end. */
|
|
5
6
|
export type AgentSessionAddress = {
|
|
6
7
|
readonly kind: "local";
|
|
@@ -46,6 +47,7 @@ export interface AgentSessionMessage {
|
|
|
46
47
|
export declare function openAgentSessionStep(input: AgentSessionMessage & {
|
|
47
48
|
readonly context: AgentSessionContext;
|
|
48
49
|
readonly key: string;
|
|
50
|
+
readonly model?: AgentSessionModelSelection;
|
|
49
51
|
readonly name: string;
|
|
50
52
|
}): Promise<AgentSessionAddress>;
|
|
51
53
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger,logError}from"#internal/logging.js";import{sessionInboxHookToken}from"#execution/session-inbox/address.js";import{ContextContainer,contextStorage}from"#context/container.js";import{createEveCallbackRoutePath}from"#protocol/routes.js";import{
|
|
1
|
+
import{createLogger,logError}from"#internal/logging.js";import{SessionStrandedError}from"#channel/session-stranded-error.js";import{sessionInboxHookToken}from"#execution/session-inbox/address.js";import{ContextContainer,contextStorage}from"#context/container.js";import{createEveCallbackRoutePath}from"#protocol/routes.js";import{toErrorMessage}from"#shared/errors.js";import{InvalidRuntimeModelSelectionError,resolveRuntimeModelSelection}from"#runtime/agent/resolve-model.js";import{agentDelegation}from"#tracing/eve/delegation.js";import{createWorkflowRuntime,dispatchWorkflowSessionCommand,resolveContinuation,waitForCommandHookOwner,waitForSessionInbox}from"#execution/workflow-runtime.js";import{resolveDurableCompiledArtifactsSource}from"#runtime/durable-compiled-artifacts-source.js";import{FatalError,getStepMetadata,getWorkflowMetadata}from"#compiled/@workflow/core/index.js";import{createWorkflowCallbackUrl,resolveWorkflowCallbackBaseUrl}from"#execution/workflow-callback-url.js";import{resolveAgentAction,resolveAgentStartTarget}from"#execution/agent-sessions/target.js";import{getCompiledRuntimeAgentBundle}from"#runtime/sessions/compiled-agent-cache.js";import{cancelRemoteAgentTurn,continueRemoteAgentSession,resetRemoteAgentSession,resolveRemoteAgentForAction,startRemoteAgentSession}from"#execution/agent-sessions/remote.js";import{buildSubagentRunInput}from"#subagents/tool.js";import{resolveConversationId}from"#shared/conversation-identity.js";import{stubToolPath}from"#tool-stubs/target.js";const log=createLogger(`execution.agent-sessions`),RUN_FINISHED_REASON=`The workflow run that opened this session finished.`;async function openAgentSessionStep(e){"use step";let{context:t}=e,n=await loadAgentSessionBundle(t),r=resolveAgentAction({bundle:n,callId:t.parent.callId,dynamicSelections:t.dynamicSelections,input:{message:e.message,outputSchema:e.outputSchema,target:e.name}}),i=resolveAgentStartTarget({action:r,bundle:n,dynamicSelections:t.dynamicSelections,isRootSession:t.parent.rootSessionId===t.parent.sessionId});if(e.model!==void 0&&i.kind===`remote`)throw new FatalError(`ctx.agent("${e.name}", { model }) cannot override a remote agent's model. Configure the model on the receiving agent.`);let a=e.model===void 0?void 0:await normalizeRuntimeOverrides(e.name,e.model),o={auth:e.auth,bundle:n,context:t,key:e.key,replyTo:e.replyTo,runtimeOverrides:a};return await agentDelegation.resume({context:t,agentName:r.name},()=>i.kind===`remote`?startRemoteSession({...o,target:i}):startLocalSession({...o,target:i}))}async function normalizeRuntimeOverrides(e,t){try{return{model:(await resolveRuntimeModelSelection({durability:`durable`,selection:t,state:new ContextContainer})).reference}}catch(t){throw t instanceof InvalidRuntimeModelSelectionError?new FatalError(`ctx.agent("${e}", { model }) could not resolve the model selection: ${toErrorMessage(t)}`):t}}async function sendAgentSessionMessageStep(e){"use step";let{address:t,context:n}=e;if(t.kind===`remote`){let r=await resolveSessionRemote(n,t);await continueRemoteAgentSession({auth:e.auth.current,callback:{callId:n.parent.callId,subagentName:t.name,token:e.replyTo,url:createWorkflowCallbackUrl(t.callbackBaseUrl,createEveCallbackRoutePath(e.replyTo))},message:e.message,outputSchema:e.outputSchema,remote:r,sessionId:t.sessionId});return}if((await commandLocalSession({...e,address:t},{auth:e.auth.current,schedule:n.schedule,caller:{callId:n.parent.callId,replyTo:{kind:`hook`,token:e.replyTo},subagentName:t.name},kind:`send`,payload:{message:e.message,outputSchema:e.outputSchema}}).catch(e=>{throw SessionStrandedError.is(e)?Error(`Agent "${t.name}" can no longer receive messages: ${e.message}`,{cause:e}):e})).status!==`accepted`)throw Error(`Agent "${t.name}" can no longer receive messages; its session ended.`)}async function cancelAgentSessionTurnStep(e){"use step";let{address:t}=e;try{if(t.kind===`remote`){let n=await resolveSessionRemote(e.context,t);await cancelRemoteAgentTurn({remote:n,sessionId:t.sessionId});return}await commandLocalSession({...e,address:t},{kind:`cancel`})}catch(e){logError(log,`failed to cancel an agent session turn`,e,{name:t.name,sessionId:t.sessionId})}}async function endAgentSessionsStep(e){"use step";await Promise.all(e.sessions.map(endAgentSession))}async function endAgentSession(e){let{address:t,context:n}=e;try{if(t.kind===`remote`){let e=await resolveSessionRemote(n,t);await resetRemoteAgentSession({reason:RUN_FINISHED_REASON,remote:e,sessionId:t.sessionId});return}await commandLocalSession({...e,address:t},{kind:`reset`,reason:RUN_FINISHED_REASON})}catch(e){logError(log,`failed to end an agent session`,e,{name:t.name,sessionId:t.sessionId})}}async function commandLocalSession(e,t){let{continuationToken:n,sessionId:r}=e.address,i=await dispatchWorkflowSessionCommand({command:t,sessionId:r});if(i.status===`accepted`||i.status===`reset`)return i;let a=await waitForSessionInbox(r)?r:(await resolveContinuation(n))?.sessionId;return a===void 0?i:await dispatchWorkflowSessionCommand({command:t,sessionId:a})}async function startLocalSession(e){let{auth:t,bundle:n,context:r,target:i}=e,{action:a}=i,{childContinuationToken:o,runInput:s}=buildSubagentRunInput({action:a,auth:t.current,capabilities:r.capabilities,schedule:r.schedule,channelMetadata:r.channelMetadata,continuationKey:e.key,graph:n.graph,inheritedConversation:r.conversation,initiatorAuth:t.initiator,parent:createParentContext(r,e.replyTo),sandboxSessionId:r.sandbox.sessionId,selfAgent:i.source.type===`runtime`,session:{continuationToken:e.replyTo,sandboxState:r.sandbox.state,sessionId:r.parent.sessionId},source:i.source}),c=createWorkflowRuntime({agentSessionRuntimeOverrides:e.runtimeOverrides,compiledArtifactsSource:n.compiledArtifactsSource,dynamicSubagentAgentConfig:i.dynamicSubagentAgentConfig,nodeId:a.nodeId}),l=r.toolStubs;l!==void 0&&(l={...l,agentPath:stubToolPath(l,a.name)});let u=(await contextStorage.run(new ContextContainer({localDevRequest:r.localDevRequest}),()=>c.createSession({...s,toolStubs:l}))).sessionId;return getStepMetadata().attempt>1&&({runId:u}=await waitForCommandHookOwner(sessionInboxHookToken(o))),{continuationToken:o,kind:`local`,name:a.name,nodeId:a.nodeId,sessionId:u}}async function startRemoteSession(e){let{auth:t,bundle:n,context:r,target:i}=e,{action:a}=i,o=resolveRemoteAgentForAction({dynamicRemoteAgent:i.dynamicRemoteAgent,nodeId:a.nodeId,registry:n.subagentRegistry.subagentsByNodeId,remoteAgentName:a.remoteAgentName}),s=resolveWorkflowCallbackBaseUrl(getWorkflowMetadata().url),c=await startRemoteAgentSession({action:a,auth:t.current,callbackBaseUrl:s,capabilities:r.capabilities,initiatorAuth:t.initiator,operationId:`agent-session:${e.key}`,originAudience:r.trace.originAudience,parent:createParentContext(r,e.replyTo),remote:o,session:{continuationToken:e.replyTo}});return{callbackBaseUrl:s,kind:`remote`,forwardPrincipal:o.forwardPrincipal,name:a.remoteAgentName,nodeId:a.nodeId,resolverId:i.dynamicRemoteAgent?.credentialsStepId??a.nodeId,sessionId:c.sessionId,url:o.url}}function createParentContext(e,t){return{continuationToken:t,conversationId:e.trace.conversationId??resolveConversationId(e.parent.rootSessionId),lineage:e.parent,originAudience:e.trace.originAudience,traceContext:e.trace.parentTraceContext,traceRoot:e.traceRoot}}async function resolveSessionRemote(e,t){let n=await loadAgentSessionBundle(e),r=e.dynamicSelections[t.nodeId];return{...resolveRemoteAgentForAction({dynamicRemoteAgent:r?.kind===`remote`?r.remoteAgent:void 0,nodeId:t.nodeId,registry:n.subagentRegistry.subagentsByNodeId,remoteAgentName:t.name}),url:t.url}}async function loadAgentSessionBundle(e){return await getCompiledRuntimeAgentBundle({compiledArtifactsSource:resolveDurableCompiledArtifactsSource(e.bundle.source),nodeId:e.bundle.nodeId})}export{cancelAgentSessionTurnStep,endAgentSessionsStep,openAgentSessionStep,sendAgentSessionMessageStep};
|
|
@@ -4,6 +4,7 @@ import { type LocalDevRequestProvenance } from "#context/keys.js";
|
|
|
4
4
|
import { ContextContainer } from "#context/container.js";
|
|
5
5
|
import { type CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
|
|
6
6
|
import type { HarnessSessionBase } from "#harness/types.js";
|
|
7
|
+
import type { TaskStartedStreamEvent } from "#protocol/message.js";
|
|
7
8
|
import type { RuntimeActionResult, RuntimeWorkflowTaskRequest } from "#shared/action-types.js";
|
|
8
9
|
import type { SessionParent, SessionTraceRoot } from "#channel/types.js";
|
|
9
10
|
import { type DurableSessionState, readDurableSession } from "#execution/durable-session-store.js";
|
|
@@ -14,7 +15,6 @@ import type { WorkflowAgentMetadata } from "#tools/workflow-definition.js";
|
|
|
14
15
|
/** Input shared by direct and Workflow-originated owner-side dispatch. */
|
|
15
16
|
export interface CoordinationDispatchInput {
|
|
16
17
|
readonly workflowToolRunOwner: WorkflowToolRunOwner;
|
|
17
|
-
readonly sessionWritable: WritableStream<Uint8Array>;
|
|
18
18
|
readonly serializedContext: Record<string, unknown>;
|
|
19
19
|
readonly sessionState: DurableSessionState;
|
|
20
20
|
}
|
|
@@ -23,6 +23,8 @@ export interface CoordinationDispatchResult {
|
|
|
23
23
|
readonly results: readonly RuntimeActionResult[];
|
|
24
24
|
readonly serializedContext: Record<string, unknown>;
|
|
25
25
|
readonly sessionState: DurableSessionState;
|
|
26
|
+
/** The tasks the dispatch started or sent to, for the step that publishes `task.started`. */
|
|
27
|
+
readonly started: readonly TaskStartedStreamEvent["data"][];
|
|
26
28
|
}
|
|
27
29
|
/** Everything preflight produces before either step's dispatch loop runs. */
|
|
28
30
|
export interface PreparedCoordinationDispatch<PlanEntry = RuntimeWorkflowTaskRequest> {
|
|
@@ -51,10 +53,8 @@ export interface PreparedCoordinationDispatch<PlanEntry = RuntimeWorkflowTaskReq
|
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* Runs every dispatch precondition that may throw — durable reads, context
|
|
54
|
-
* deserialization, handle-store validation, and batch planning — before
|
|
55
|
-
*
|
|
56
|
-
* never leaks the writer lock. Returns undefined when no actions are
|
|
57
|
-
* pending.
|
|
56
|
+
* deserialization, handle-store validation, and batch planning — before any
|
|
57
|
+
* run starts. Returns undefined when no actions are pending.
|
|
58
58
|
*/
|
|
59
59
|
export declare function prepareCoordinationDispatch(input: {
|
|
60
60
|
readonly serializedContext: Record<string, unknown>;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
/** Starts workflow-tool runs for pending coordination. */
|
|
1
|
+
/** Starts workflow-tool runs for pending coordination, then reports the tasks it started. */
|
|
2
2
|
import { type CoordinationDispatchInput, type CoordinationDispatchResult } from "#execution/coordination-dispatch-shared.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type SessionStepState } from "#execution/publish-session-events.js";
|
|
4
|
+
import { type SessionStateTransition, type WithSessionStateDelta } from "#execution/session/state-delta.js";
|
|
5
|
+
import type { TaskStartedStreamEvent } from "#protocol/message.js";
|
|
4
6
|
type CoordinationDispatchStepInput = CoordinationDispatchInput & {
|
|
5
7
|
readonly action: "park";
|
|
6
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Starts the runs of the pending calls and records them on the session. A
|
|
11
|
+
* retry starts its runs again, since a Workflow start has no idempotency key,
|
|
12
|
+
* so this step publishes nothing and commits as soon as the runs are
|
|
13
|
+
* recorded. See {@link publishTaskStartedStep}.
|
|
14
|
+
*/
|
|
7
15
|
export declare function dispatchCoordinationStep(input: CoordinationDispatchStepInput): Promise<WithSessionStateDelta<CoordinationDispatchResult>>;
|
|
16
|
+
/**
|
|
17
|
+
* Publishes `task.started` for the tasks {@link dispatchCoordinationStep}
|
|
18
|
+
* started, before their receipts reach the turn. A retry only publishes again.
|
|
19
|
+
*/
|
|
20
|
+
export declare function publishTaskStartedStep(input: SessionStepState & {
|
|
21
|
+
readonly started: readonly TaskStartedStreamEvent["data"][];
|
|
22
|
+
}): Promise<SessionStateTransition>;
|
|
8
23
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createDurableSessionState}from"#execution/durable-session-store.js";import{prepareCoordinationDispatch}from"#execution/coordination-dispatch-shared.js";import{commitSessionStep}from"#execution/publish-session-events.js";import{withSessionStateDelta}from"#execution/session/state-delta.js";import{startWorkflowTask,startWorkflowToolCallRun}from"#execution/tools/workflow/start.js";import{runEntryToStart,sendToTask,startTaskRun,startsEveryRun}from"#execution/tasks/start.js";import{readTaskTable}from"#execution/tasks/table.js";import{captureAgentSessionContext}from"#execution/agent-sessions/context.js";import{startTask}from"#harness/session-machine/transitions.js";async function dispatchCoordinationStep(e){"use step";return await withSessionStateDelta(e,dispatchCoordination)}async function publishTaskStartedStep(e){"use step";return await withSessionStateDelta(e,({started:e,...t})=>commitSessionStep(t,t=>e.map(e=>startTask(t,e)),{origin:`own`}))}async function dispatchCoordination(e){let t=await prepareCoordinationDispatch({serializedContext:e.serializedContext,sessionState:e.sessionState});if(t===void 0)return{results:[],serializedContext:e.serializedContext,sessionState:e.sessionState,started:[]};let{batch:n,session:r}=t,i=r,a=[],o=[],s=withPrestartedRuns(t.plan.map(i=>({agentContext:captureAgentSessionContext(t,i.callId),auth:{current:t.auth,initiator:t.initiatorAuth},batchEvent:n.event,owner:e.workflowToolRunOwner,parentSession:t.parentSession,session:r,task:i})),readTaskTable(r.state));for(let e of s){let t=await dispatchWorkflowCall({...e,session:i});i=t.session,t.result!==void 0&&a.push(t.result),t.started!==void 0&&o.push(t.started)}return{results:a,serializedContext:e.serializedContext,sessionState:i===r?t.sessionState:createDurableSessionState({session:i}),started:o}}function withPrestartedRuns(e,t){let n=e.map(e=>e.task),r=n.map(e=>runEntryToStart(t,e));return r.filter(e=>e!==void 0).length>1&&startsEveryRun(t,n)?e.map((e,t)=>{let n=r[t];if(n===void 0)return e;let i=startWorkflowToolCallRun(e,n);return i.catch(()=>{}),{...e,prestarted:{entry:n,run:i}}}):e}async function dispatchWorkflowCall(e){let{entry:t}=e.task;switch(t.entryPoint){case`execute`:return await startWorkflowTask(e);case`task`:case`serve`:return await startTaskRun({...e,entry:t});case`receive`:return await sendToTask({...e,taskId:t.taskId})}}export{dispatchCoordinationStep,publishTaskStartedStep};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type DurableCompiledArtifactsSource } from "#runtime/durable-compiled-artifacts-source.js";
|
|
2
2
|
import { type DurableSessionState } from "#execution/durable-session-store.js";
|
|
3
3
|
import type { HarnessModelMessage } from "#harness/messages.js";
|
|
4
|
-
import type { RunSessionLimits } from "#channel/types.js";
|
|
5
4
|
import type { JsonObject } from "#shared/json.js";
|
|
5
|
+
import type { AgentSessionRuntimeOverrides } from "#execution/agent-sessions/runtime-overrides.js";
|
|
6
6
|
import type { DynamicSubagentAgentConfig } from "#runtime/subagents/dynamic-agent-config.js";
|
|
7
|
+
import type { SessionHistoryMessage } from "#shared/session-history.js";
|
|
7
8
|
/**
|
|
8
9
|
* Result returned by {@link createSessionStep}.
|
|
9
10
|
*
|
|
@@ -21,10 +22,12 @@ export interface CreateSessionStepResult {
|
|
|
21
22
|
* the root agent.
|
|
22
23
|
*/
|
|
23
24
|
export declare function createSessionStep(input: {
|
|
25
|
+
readonly agentSessionRuntimeOverrides?: AgentSessionRuntimeOverrides;
|
|
24
26
|
readonly compiledArtifactsSource: DurableCompiledArtifactsSource;
|
|
25
27
|
readonly continuationToken: string;
|
|
26
28
|
readonly dynamicSubagentAgentConfig?: DynamicSubagentAgentConfig;
|
|
27
|
-
|
|
29
|
+
/** History from `create()`, held until the first message's turn adds it. */
|
|
30
|
+
readonly history?: readonly SessionHistoryMessage[];
|
|
28
31
|
readonly outputSchema?: JsonObject;
|
|
29
32
|
readonly nodeId?: string;
|
|
30
33
|
readonly rootSessionId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveDurableCompiledArtifactsSource}from"#runtime/durable-compiled-artifacts-source.js";import{getCompiledRuntimeAgentBundle}from"#runtime/sessions/compiled-agent-cache.js";import{createDurableSessionValues}from"#execution/durable-session-store.js";import{createSession}from"#execution/session.js";import{resolveEffectiveAgentRuntimeFromConfig}from"#execution/effective-agent-config.js";import{
|
|
1
|
+
import{resolveDurableCompiledArtifactsSource}from"#runtime/durable-compiled-artifacts-source.js";import{getCompiledRuntimeAgentBundle}from"#runtime/sessions/compiled-agent-cache.js";import{createDurableSessionValues}from"#execution/durable-session-store.js";import{createSession}from"#execution/session.js";import{resolveEffectiveAgentRuntimeFromConfig}from"#execution/effective-agent-config.js";import{withPendingHistory}from"#execution/session/pending-history.js";async function createSessionStep(e){"use step";let t=await getCompiledRuntimeAgentBundle({compiledArtifactsSource:resolveDurableCompiledArtifactsSource(e.compiledArtifactsSource),nodeId:e.nodeId}),n=resolveEffectiveAgentRuntimeFromConfig(t,e.dynamicSubagentAgentConfig,e.agentSessionRuntimeOverrides),r=createSession({compactionOverrides:{thresholdPercent:n.thresholdPercent},continuationToken:e.continuationToken,outputSchema:e.outputSchema,rootSessionId:e.rootSessionId,sessionId:e.sessionId,turnAgent:n.turnAgent}),i=withPendingHistory(r.state,e.history),{history:a,sessionState:o}=createDurableSessionValues(i===r.state?r:{...r,state:i});return{history:a,state:o}}export{createSessionStep};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{coalesceTurnInputs}from"#harness/messages.js";const COALESCED_DELIVER_FIELDS=[`context`,`inputResponses`,`message`,`outputSchema`];function coalesceDeliverPayloads(e){if(e.length===0)return{};if(e.length===1)return e[0]??{};let t={},n={};for(let r of e){for(let[e,n]of Object.entries(r))n!==void 0&&(t[e]=n);n=coalesceTurnInputs(n,r)}for(let e of COALESCED_DELIVER_FIELDS)delete t[e];return Object.assign(t,n)}export{coalesceDeliverPayloads};
|
|
1
|
+
import{coalesceTurnInputs}from"#harness/messages.js";const COALESCED_DELIVER_FIELDS=[`context`,`history`,`inputResponses`,`message`,`outputSchema`];function coalesceDeliverPayloads(e){if(e.length===0)return{};if(e.length===1)return e[0]??{};let t={},n={};for(let r of e){for(let[e,n]of Object.entries(r))n!==void 0&&(t[e]=n);n=coalesceTurnInputs(n,r)}for(let e of COALESCED_DELIVER_FIELDS)delete t[e];return Object.assign(t,n)}export{coalesceDeliverPayloads};
|
|
@@ -47,7 +47,6 @@ export interface DurableSession {
|
|
|
47
47
|
*/
|
|
48
48
|
readonly rootSessionId?: string;
|
|
49
49
|
readonly continuationToken: string;
|
|
50
|
-
readonly limits?: HarnessSession["limits"];
|
|
51
50
|
readonly outputSchema?: JsonObject;
|
|
52
51
|
readonly state?: SessionStateMap;
|
|
53
52
|
readonly sandboxState?: SandboxState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createErrorId,createLogger}from"#internal/logging.js";import{toErrorMessage}from"#shared/errors.js";import{activeTurnId,turnPosition}from"#harness/session-machine/view.js";import{
|
|
1
|
+
import{createErrorId,createLogger}from"#internal/logging.js";import{toErrorMessage}from"#shared/errors.js";import{activeTurnId,turnPosition}from"#harness/session-machine/view.js";import{fail}from"#harness/session-machine/transitions.js";import{isDynamicConnectionResolutionError}from"#context/dynamic-connection-lifecycle.js";import{applyTransition,sessionView}from"#harness/session-machine/commit.js";const log=createLogger(`turn-step`);async function recoverDynamicConnectionRehydration(e){if(!isDynamicConnectionResolutionError(e.error))return;let t=createErrorId(),n=toErrorMessage(e.error);return log.error(`dynamic connection rehydration failed — parking session`,{error:e.error,errorId:t,sessionId:e.session.sessionId,turnId:activeTurnId(turnPosition(e.projection))}),{next:null,session:{...await applyTransition(e.session,fail(sessionView(e.projection,e.session.state),{code:`EVENT_HANDLER_FAILED`,details:{errorId:t},message:n}),e.emit),outputSchema:void 0},settledTurn:{isError:!0,output:n}}}export{recoverDynamicConnectionRehydration};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{runJsProgram}from"#execution/dynamic-workflow/workflow.js";async function runWorkflowProgramTask(e,t){"use workflow";return runJsProgram(e.js,t,{maxSubagents:e.maxSubagents??0})}runWorkflowProgramTask.workflowId=`workflow//eve@0.
|
|
1
|
+
import{runJsProgram}from"#execution/dynamic-workflow/workflow.js";async function runWorkflowProgramTask(e,t){"use workflow";return runJsProgram(e.js,t,{maxSubagents:e.maxSubagents??0})}runWorkflowProgramTask.workflowId=`workflow//eve@0.82.0//runWorkflowProgramTask`;export{runWorkflowProgramTask};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ContextReader } from "#context/key.js";
|
|
2
2
|
import type { RuntimeTurnAgent } from "#runtime/agent/bootstrap.js";
|
|
3
3
|
import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
|
|
4
|
-
import type { AgentLimitsDefinition } from "#shared/agent-definition.js";
|
|
4
|
+
import type { AgentLimitsDefinition, SessionUsageLimit } from "#shared/agent-definition.js";
|
|
5
|
+
import type { AgentSessionRuntimeOverrides } from "#execution/agent-sessions/runtime-overrides.js";
|
|
5
6
|
import type { DynamicSubagentAgentConfig } from "#runtime/subagents/dynamic-agent-config.js";
|
|
6
7
|
interface EffectiveAgentRuntime {
|
|
7
8
|
readonly limits?: AgentLimitsDefinition;
|
|
@@ -9,5 +10,10 @@ interface EffectiveAgentRuntime {
|
|
|
9
10
|
readonly turnAgent: RuntimeTurnAgent;
|
|
10
11
|
}
|
|
11
12
|
export declare function resolveEffectiveAgentRuntime(bundle: Pick<CompiledBundle, "resolvedAgent" | "turnAgent">, context: ContextReader): EffectiveAgentRuntime;
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The session's `limits.sessionUsage`: the agent's own, else the root agent's.
|
|
15
|
+
* A dynamic subagent config can't carry one, so its sessions run the root's.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveSessionUsageLimit(bundle: Pick<CompiledBundle, "graph" | "resolvedAgent">): SessionUsageLimit | undefined;
|
|
18
|
+
export declare function resolveEffectiveAgentRuntimeFromConfig(bundle: Pick<CompiledBundle, "resolvedAgent" | "turnAgent">, config: DynamicSubagentAgentConfig | undefined, overrides?: AgentSessionRuntimeOverrides): EffectiveAgentRuntime;
|
|
13
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DynamicSubagentAgentConfigKey}from"#context/keys.js";function resolveEffectiveAgentRuntime(e,t){return resolveEffectiveAgentRuntimeFromConfig(e,t.get(DynamicSubagentAgentConfigKey))}function resolveEffectiveAgentRuntimeFromConfig(e,t){if(t===void 0){if(e.turnAgent.configResolver===!0)throw Error(`Dynamic subagent execution requires a selected concrete agent config.`);
|
|
1
|
+
import{AgentSessionRuntimeOverridesKey,DynamicSubagentAgentConfigKey}from"#context/keys.js";import{ROOT_RUNTIME_AGENT_NODE_ID}from"#runtime/graph.js";function resolveEffectiveAgentRuntime(e,t){return resolveEffectiveAgentRuntimeFromConfig(e,t.get(DynamicSubagentAgentConfigKey),t.get(AgentSessionRuntimeOverridesKey))}function resolveSessionUsageLimit(e){return e.resolvedAgent.config?.limits?.sessionUsage??e.graph.nodesByNodeId.get(ROOT_RUNTIME_AGENT_NODE_ID)?.agent.config?.limits?.sessionUsage}function resolveEffectiveAgentRuntimeFromConfig(e,t,n){let r;if(t===void 0){if(e.turnAgent.configResolver===!0)throw Error(`Dynamic subagent execution requires a selected concrete agent config.`);r={limits:e.resolvedAgent.config?.limits,thresholdPercent:e.resolvedAgent.config?.compaction?.thresholdPercent,turnAgent:e.turnAgent}}else{let{compactionModel:n,configResolver:i,dynamicModel:a,model:o,...s}=e.turnAgent;r={limits:t.limits,thresholdPercent:t.compaction?.thresholdPercent,turnAgent:{...s,compactionModel:t.compaction?.model,model:t.model,reasoning:t.reasoning}}}if(n===void 0)return r;let{configResolver:i,dynamicModel:a,model:o,...s}=r.turnAgent;return{...r,turnAgent:{...s,model:n.model}}}export{resolveEffectiveAgentRuntime,resolveEffectiveAgentRuntimeFromConfig,resolveSessionUsageLimit};
|
|
@@ -9,3 +9,11 @@ export declare function isHookConflictError(error: unknown): error is {
|
|
|
9
9
|
readonly name: "HookConflictError";
|
|
10
10
|
readonly token?: unknown;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Another run took the hook's token with `experimental_force`. Matched by name:
|
|
14
|
+
* `HookForceClaimedError.is` lives in a module the workflow bundle cannot load.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isHookForceClaimedError(error: unknown): error is {
|
|
17
|
+
readonly claimedByRunId: string;
|
|
18
|
+
readonly name: "HookForceClaimedError";
|
|
19
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
async function claimHookOwnership(e){let t;try{t=await e.getConflict()}catch(t){return await disposeAndThrow(e,t)}if(t!==null)return await disposeAndThrow(e,createHookConflictError(e.token,t.runId))}async function disposeHook(e){await e.dispose()}async function disposeAndThrow(e,t){try{await disposeHook(e)}catch{}throw t}function isHookConflictError(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`HookConflictError`}function createHookConflictError(e,t){let n=` (run "${t}")`;return Object.assign(Error(`Hook token "${e}" is already in use${n}`),{conflictingRunId:t,name:`HookConflictError`,token:e})}export{claimHookOwnership,disposeHook,isHookConflictError};
|
|
1
|
+
async function claimHookOwnership(e){let t;try{t=await e.getConflict()}catch(t){return await disposeAndThrow(e,t)}if(t!==null)return await disposeAndThrow(e,createHookConflictError(e.token,t.runId))}async function disposeHook(e){await e.dispose()}async function disposeAndThrow(e,t){try{await disposeHook(e)}catch{}throw t}function isHookConflictError(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`HookConflictError`}function isHookForceClaimedError(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`HookForceClaimedError`&&`claimedByRunId`in e&&typeof e.claimedByRunId==`string`}function createHookConflictError(e,t){let n=` (run "${t}")`;return Object.assign(Error(`Hook token "${e}" is already in use${n}`),{conflictingRunId:t,name:`HookConflictError`,token:e})}export{claimHookOwnership,disposeHook,isHookConflictError,isHookForceClaimedError};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const BUILD_DEPLOYMENT_ID_PATTERN=/^eve_[a-f0-9]{32}$/;function installWorkflowDeploymentId(e){BUILD_DEPLOYMENT_ID_PATTERN.test(e)&&(process.env.VERCEL_DEPLOYMENT_ID||process.env.WORKFLOW_DEPLOYMENT_ID||(process.env.WORKFLOW_DEPLOYMENT_ID=e))}export{BUILD_DEPLOYMENT_ID_PATTERN,installWorkflowDeploymentId};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{completeLegacyDriverStep}from"./completion-step.js";import{interruptLegacySessionStep}from"./interrupt-step.js";import{prepareLegacySessionStep}from"./prepare-step.js";import{sessionCommandHookToken}from"#execution/session-inbox/address.js";import{isHookConflictError}from"#execution/hook-ownership.js";import{
|
|
1
|
+
import{completeLegacyDriverStep}from"./completion-step.js";import{interruptLegacySessionStep}from"./interrupt-step.js";import{prepareLegacySessionStep}from"./prepare-step.js";import{sessionCommandHookToken}from"#execution/session-inbox/address.js";import{isHookConflictError}from"#execution/hook-ownership.js";import{sessionHookTokens}from"#execution/session/hook-tokens.js";import{createSessionInbox}from"#execution/session-inbox/inbox.js";import{failSession,runPreparedSession}from"#execution/session/program.js";import{createSessionTimeoutControl}from"#execution/session/timeout-control.js";import{recordSessionOwnerStep}from"#execution/session/handoff-steps.js";async function turnWorkflow(e){"use workflow";let t=await prepareLegacySessionStep(e),{sessionId:n}=t.sessionState;await recordSessionOwnerStep({sessionId:n});let r=createSessionInbox(n);try{await r.claimSessionHook(sessionCommandHookToken(n))}catch(e){if(isHookConflictError(e))return;throw e}let{sessionWritable:i}=t.input,a;try{await r.claimSessionHooks(sessionHookTokens(t)),a=await interruptLegacySessionStep(t)}catch(e){return await r.dispose(),await failSession({error:e,serializedContext:t.serializedContext,sessionId:n,sessionState:t.sessionState,sessionWritable:i})}let o=t.input.delivery?.idempotencyKey;await runPreparedSession({admittedDeliveryKeys:o===void 0?[]:[o],anchor:{kind:`self`,notify:e=>completeLegacyDriverStep({completionToken:t.input.completionToken,history:t.history,result:e,serializedContext:t.serializedContext,sessionState:t.sessionState,sessionWritable:i})},caller:void 0,capabilities:t.input.capabilities,deploymentId:t.deploymentId,history:a.history,start:{input:t.input.delivery===void 0?void 0:{...t.input.delivery,caller:void 0},kind:`turn`},retention:t.input.retention,serializedContext:a.serializedContext,sessionId:n,sessionState:a.sessionState,sessionTimeoutControl:createSessionTimeoutControl({sessionId:n,timeoutMs:t.sessionTimeoutMs}),sessionTimeoutMs:t.sessionTimeoutMs,sessionWritable:i},r)}turnWorkflow.workflowId=`workflow//eve//turnWorkflow`;export{turnWorkflow};
|
|
@@ -50,6 +50,7 @@ interface CreateExecutionNodeStepInput {
|
|
|
50
50
|
readonly titleAttributeWrite?: ToolLoopHarnessConfig["titleAttributeWrite"];
|
|
51
51
|
readonly modelResolutionScope: RuntimeModelResolutionScope;
|
|
52
52
|
readonly node: ResolvedRuntimeAgentNode;
|
|
53
|
+
readonly sessionUsageLimit?: ToolLoopHarnessConfig["sessionUsageLimit"];
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* Builds a harness step for one resolved runtime node using the execution-owned
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger}from"#internal/logging.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{UNSPECIFIED_INPUT_SCHEMA}from"#tools/schema.js";import{createToolExecuteWithAuth}from"#execution/tool-auth.js";import{resolveRuntimeModelReference}from"#runtime/agent/resolve-model.js";import{createPreparedWorkflowToolHarnessDefinition,createWorkflowToolHarnessDefinition}from"#execution/tools/workflow/harness-definition.js";import{isFrameworkTool}from"#tools/provided/framework-tool.js";import{workflowIdForHandling}from"#runtime/subagents/workflow-reference.js";import{dispatchDynamicModelEvent}from"#context/dynamic-model-lifecycle.js";import{preparePersistedStepDynamicToolMetadata}from"#context/dynamic-tool-lifecycle.js";import{createToolLoopHarness}from"#harness/tool-loop.js";import{findRegisteredRuntimeTool}from"#runtime/tools/registry.js";import{WEB_SEARCH_TOOL_NAME,resolveWebSearchActivityLabel}from"#harness/provider-tool-schemas.js";const log=createLogger(`execution.node-step`);function createExecutionNodeStep(e){let t=createRuntimeModelResolver(e.modelResolutionScope),n=e.node.turnAgent.dynamicModel===void 0?void 0:createRuntimeDynamicModelEventDispatcher(e.modelResolutionScope,e.node.turnAgent.dynamicModel,e.abortSignal),r=createNodeHarnessTools({node:e.node}),i=e.instrumentation,a=i?.prepareExecution(),o=createToolLoopHarness({steeringSignal:e.steeringSignal,abortSignal:e.abortSignal,capabilities:e.capabilities,clearOnly:e.clearOnly,compactOnly:e.compactOnly,handleEvent:e.handleEvent,historyProjector:e.historyProjector,historyView:e.historyView,instrumentation:a,prepareApprovalTurn:e.prepareApprovalTurn,signInCompletions:e.signInCompletions,resolveStepDynamicTools:t=>preparePersistedStepDynamicToolMetadata({...t,resolvers:e.node.agent.dynamicToolResolvers??[]}),dispatchDynamicModelEvent:n,resolveModel:t,runtimeIdentity:buildRuntimeIdentity(e.node),tools:r,titleAttributeWrite:e.titleAttributeWrite});return i===void 0?o:async(e,t)=>{try{return await o(e,t)}finally{await i.flush()}}}function buildRuntimeIdentity(e){let t=resolveInstalledPackageInfo(),n={agentId:e.turnAgent.id,agentName:e.agent.config?.name,eveVersion:t.version},r=process.env.VERCEL_GIT_COMMIT_SHA?.trim(),i=process.env.VERCEL_GIT_COMMIT_REF?.trim(),a=process.env.VERCEL_DEPLOYMENT_CREATED_AT?.trim();return r||i||a?{...n,build:{deployedAt:a||void 0,gitBranch:i||void 0,gitSha:r||void 0}}:n}function createRuntimeModelResolver(e){return t=>resolveRuntimeModelReference(t,e)}function createRuntimeDynamicModelEventDispatcher(e,t,n){return r=>dispatchDynamicModelEvent({abortSignal:n,ctx:r.ctx,dynamicModel:t,event:r.event,messages:r.messages,scope:e})}function createNodeHarnessTools(e){let t=new Map;for(let n of e.node.turnAgent.tools){let r=resolveHarnessToolDefinition({node:e.node,tool:n});r!==null&&t.set(n.name,r)}return t}function resolveHarnessToolDefinition(e){let t=findRegisteredRuntimeTool(e.node.toolRegistry,e.tool.name),n=workflowIdForHandling(e.tool.behavior?.handling);return n===void 0?t===null?(log.warn(`declared tool is not registered — omitting from toolset`,{toolName:e.tool.name,nodeId:e.node.nodeId}),null):createRegisteredHarnessToolDefinition({behavior:e.tool.behavior,definition:t.definition,rootOnly:e.tool.rootOnly}):t===null?createPreparedWorkflowToolHarnessDefinition(e.tool):createWorkflowToolHarnessDefinition({executeInput:t.definition.executeInput,definition:createRegisteredHarnessToolDefinition({behavior:e.tool.behavior,definition:t.definition,rootOnly:e.tool.rootOnly}),workflowId:n})}function createRegisteredHarnessToolDefinition(e){let t=e.definition,n=t.execute;return{availableInSubagents:t.availableInSubagents,label:t.label??(t.owner.kind===`framework`&&t.name===WEB_SEARCH_TOOL_NAME?{start:resolveWebSearchActivityLabel}:void 0),approvalKey:t.approvalKey,behavior:e.behavior,deferred:t.deferred,description:t.description,endsTurn:t.endsTurn,executeInput:t.executeInput,execute:resolveAuthoredExecute({rawExecute:n,scope:t.name}),frameworkTool:isFrameworkTool(t)||t.owner.kind===`framework`,inputSchema:t.inputSchema??UNSPECIFIED_INPUT_SCHEMA,name:t.name,approval:t.approval,outputSchema:t.outputSchema,rootOnly:e.rootOnly,toModelOutput:t.toModelOutput}}function resolveAuthoredExecute(e){let{rawExecute:t,scope:n}=e;return t===void 0?void 0:createToolExecuteWithAuth({execute:t,scope:n})}export{buildRuntimeIdentity,createExecutionNodeStep,createNodeHarnessTools};
|
|
1
|
+
import{createLogger}from"#internal/logging.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{UNSPECIFIED_INPUT_SCHEMA}from"#tools/schema.js";import{createToolExecuteWithAuth}from"#execution/tool-auth.js";import{resolveRuntimeModelReference}from"#runtime/agent/resolve-model.js";import{createPreparedWorkflowToolHarnessDefinition,createWorkflowToolHarnessDefinition}from"#execution/tools/workflow/harness-definition.js";import{isFrameworkTool}from"#tools/provided/framework-tool.js";import{workflowIdForHandling}from"#runtime/subagents/workflow-reference.js";import{dispatchDynamicModelEvent}from"#context/dynamic-model-lifecycle.js";import{preparePersistedStepDynamicToolMetadata}from"#context/dynamic-tool-lifecycle.js";import{createToolLoopHarness}from"#harness/tool-loop.js";import{findRegisteredRuntimeTool}from"#runtime/tools/registry.js";import{WEB_SEARCH_TOOL_NAME,resolveWebSearchActivityLabel}from"#harness/provider-tool-schemas.js";const log=createLogger(`execution.node-step`);function createExecutionNodeStep(e){let t=createRuntimeModelResolver(e.modelResolutionScope),n=e.node.turnAgent.dynamicModel===void 0?void 0:createRuntimeDynamicModelEventDispatcher(e.modelResolutionScope,e.node.turnAgent.dynamicModel,e.abortSignal),r=createNodeHarnessTools({node:e.node}),i=e.instrumentation,a=i?.prepareExecution(),o=createToolLoopHarness({steeringSignal:e.steeringSignal,abortSignal:e.abortSignal,capabilities:e.capabilities,clearOnly:e.clearOnly,compactOnly:e.compactOnly,handleEvent:e.handleEvent,historyProjector:e.historyProjector,historyView:e.historyView,instrumentation:a,prepareApprovalTurn:e.prepareApprovalTurn,signInCompletions:e.signInCompletions,resolveStepDynamicTools:t=>preparePersistedStepDynamicToolMetadata({...t,resolvers:e.node.agent.dynamicToolResolvers??[]}),dispatchDynamicModelEvent:n,resolveModel:t,runtimeIdentity:buildRuntimeIdentity(e.node),sessionUsageLimit:e.sessionUsageLimit,tools:r,titleAttributeWrite:e.titleAttributeWrite});return i===void 0?o:async(e,t)=>{try{return await o(e,t)}finally{await i.flush()}}}function buildRuntimeIdentity(e){let t=resolveInstalledPackageInfo(),n={agentId:e.turnAgent.id,agentName:e.agent.config?.name,eveVersion:t.version},r=process.env.VERCEL_GIT_COMMIT_SHA?.trim(),i=process.env.VERCEL_GIT_COMMIT_REF?.trim(),a=process.env.VERCEL_DEPLOYMENT_CREATED_AT?.trim();return r||i||a?{...n,build:{deployedAt:a||void 0,gitBranch:i||void 0,gitSha:r||void 0}}:n}function createRuntimeModelResolver(e){return t=>resolveRuntimeModelReference(t,e)}function createRuntimeDynamicModelEventDispatcher(e,t,n){return r=>dispatchDynamicModelEvent({abortSignal:n,ctx:r.ctx,dynamicModel:t,event:r.event,messages:r.messages,scope:e})}function createNodeHarnessTools(e){let t=new Map;for(let n of e.node.turnAgent.tools){let r=resolveHarnessToolDefinition({node:e.node,tool:n});r!==null&&t.set(n.name,r)}return t}function resolveHarnessToolDefinition(e){let t=findRegisteredRuntimeTool(e.node.toolRegistry,e.tool.name),n=workflowIdForHandling(e.tool.behavior?.handling);return n===void 0?t===null?(log.warn(`declared tool is not registered — omitting from toolset`,{toolName:e.tool.name,nodeId:e.node.nodeId}),null):createRegisteredHarnessToolDefinition({behavior:e.tool.behavior,definition:t.definition,rootOnly:e.tool.rootOnly}):t===null?createPreparedWorkflowToolHarnessDefinition(e.tool):createWorkflowToolHarnessDefinition({executeInput:t.definition.executeInput,definition:createRegisteredHarnessToolDefinition({behavior:e.tool.behavior,definition:t.definition,rootOnly:e.tool.rootOnly}),workflowId:n})}function createRegisteredHarnessToolDefinition(e){let t=e.definition,n=t.execute;return{availableInSubagents:t.availableInSubagents,label:t.label??(t.owner.kind===`framework`&&t.name===WEB_SEARCH_TOOL_NAME?{start:resolveWebSearchActivityLabel}:void 0),approvalKey:t.approvalKey,behavior:e.behavior,deferred:t.deferred,description:t.description,endsTurn:t.endsTurn,executeInput:t.executeInput,execute:resolveAuthoredExecute({rawExecute:n,scope:t.name}),frameworkTool:isFrameworkTool(t)||t.owner.kind===`framework`,inputSchema:t.inputSchema??UNSPECIFIED_INPUT_SCHEMA,name:t.name,approval:t.approval,outputSchema:t.outputSchema,rootOnly:e.rootOnly,toModelOutput:t.toModelOutput}}function resolveAuthoredExecute(e){let{rawExecute:t,scope:n}=e;return t===void 0?void 0:createToolExecuteWithAuth({execute:t,scope:n})}export{buildRuntimeIdentity,createExecutionNodeStep,createNodeHarnessTools};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { RunInput } from "#channel/types.js";
|
|
2
2
|
import { ContextContainer } from "#context/container.js";
|
|
3
3
|
import { type CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
|
|
4
|
+
import type { AgentSessionRuntimeOverrides } from "#execution/agent-sessions/runtime-overrides.js";
|
|
4
5
|
import type { DynamicSubagentAgentConfig } from "#runtime/subagents/dynamic-agent-config.js";
|
|
5
6
|
/**
|
|
6
7
|
* Builds the bootstrap {@link ContextContainer} for one run.
|
|
7
8
|
*/
|
|
8
9
|
export declare function buildRunContext(input: {
|
|
10
|
+
readonly agentSessionRuntimeOverrides?: AgentSessionRuntimeOverrides;
|
|
9
11
|
readonly bundle: CompiledBundle;
|
|
10
12
|
readonly dynamicSubagentAgentConfig?: DynamicSubagentAgentConfig;
|
|
11
13
|
readonly run: RunInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ConversationContextKey}from"#shared/conversation-context.js";import{ContextContainer,contextStorage}from"#context/container.js";import{AuthKey,CapabilitiesKey,ChannelDeliveryKey,ChannelInstrumentationKey,ChannelRequestIdKey,ContinuationHookTokensKey,ContinuationTokenKey,ConversationIdKey,DynamicSubagentAgentConfigKey,InitiatorAuthKey,LegacyRemoteAgentCallerKey,OccurrenceIdKey,ParentSessionKey,ParentTraceContextKey,ScheduleIdKey,ScheduleInstanceKey,SessionCallbackKey,SessionTitleKey,ToolStubsKey,TraceRootKey}from"#context/keys.js";import{BundleKey}from"#runtime/sessions/runtime-context-keys.js";import{resolveInstrumentationEnvironment}from"#internal/application/dev-environment.js";import{readConversationId}from"#shared/conversation-identity.js";import{setChannelContext}from"#execution/channel-context.js";import{deriveSessionTitle}from"#execution/eve-workflow-attributes.js";import{buildConversationContext}from"#channel/conversation-context.js";function buildRunContext(e){let{bundle:t,run:n}=e,r=new ContextContainer,i=n.auth,a=readConversationId(n.conversationId);if(a!==void 0&&r.set(ConversationIdKey,a),r.set(BundleKey,t),setChannelContext(r,n.adapter,{channelName:n.channelName}),r.set(ConversationContextKey,buildConversationContext(n,resolveInstrumentationEnvironment())),n.parent===void 0||n.traceRoot?.kind===`own`){let e=deriveSessionTitle(n.title??n.input.message);e!==void 0&&r.set(SessionTitleKey,e)}if(n.channelMetadata!==void 0){let e=r.get(ChannelInstrumentationKey);r.set(ChannelInstrumentationKey,{channelType:e?.channelType??n.channelMetadata.channelType,kind:e?.kind??n.channelMetadata.kind,metadata:n.channelMetadata.metadata})}n.continuationToken!==void 0&&(r.set(ContinuationTokenKey,n.continuationToken),r.set(ContinuationHookTokensKey,[n.continuationToken]));let o=n.schedule?.occurrenceId??contextStorage.getStore()?.get(OccurrenceIdKey);o!==void 0&&r.set(OccurrenceIdKey,o),r.set(AuthKey,i),n.toolStubs!==void 0&&r.set(ToolStubsKey,n.toolStubs),(n.initiatorAuth!==void 0||n.input.message!==void 0)&&r.set(InitiatorAuthKey,n.initiatorAuth??i),e.dynamicSubagentAgentConfig!==void 0&&r.set(DynamicSubagentAgentConfigKey,e.dynamicSubagentAgentConfig),n.capabilities!==void 0&&r.set(CapabilitiesKey,n.capabilities),n.requestId!==void 0&&r.set(ChannelRequestIdKey,n.requestId);let s=n.schedule?.instance??contextStorage.getStore()?.get(ScheduleInstanceKey);s!==void 0&&r.set(ScheduleInstanceKey,s);let c=n.schedule?.definition??contextStorage.getStore()?.get(ScheduleIdKey);return c!==void 0&&r.set(ScheduleIdKey,c),n.delivery!==void 0&&r.set(ChannelDeliveryKey,n.delivery),n.callback!==void 0&&r.set(SessionCallbackKey,n.callback),n.legacyRemoteAgentCaller!==void 0&&r.set(LegacyRemoteAgentCallerKey,n.legacyRemoteAgentCaller),n.parent!==void 0&&r.set(ParentSessionKey,n.parent),n.traceRoot!==void 0&&r.set(TraceRootKey,n.traceRoot),n.parentTraceContext!==void 0&&r.set(ParentTraceContextKey,n.parentTraceContext),r}export{buildRunContext};
|
|
1
|
+
import{ConversationContextKey}from"#shared/conversation-context.js";import{ContextContainer,contextStorage}from"#context/container.js";import{AgentSessionRuntimeOverridesKey,AuthKey,CapabilitiesKey,ChannelDeliveryKey,ChannelInstrumentationKey,ChannelRequestIdKey,ContinuationHookTokensKey,ContinuationTokenKey,ConversationIdKey,DynamicSubagentAgentConfigKey,InitiatorAuthKey,LegacyRemoteAgentCallerKey,OccurrenceIdKey,ParentSessionKey,ParentTraceContextKey,ScheduleIdKey,ScheduleInstanceKey,SessionCallbackKey,SessionTitleKey,ToolStubsKey,TraceRootKey}from"#context/keys.js";import{BundleKey}from"#runtime/sessions/runtime-context-keys.js";import{resolveInstrumentationEnvironment}from"#internal/application/dev-environment.js";import{readConversationId}from"#shared/conversation-identity.js";import{setChannelContext}from"#execution/channel-context.js";import{deriveSessionTitle}from"#execution/eve-workflow-attributes.js";import{buildConversationContext}from"#channel/conversation-context.js";function buildRunContext(e){let{bundle:t,run:n}=e,r=new ContextContainer,i=n.auth,a=readConversationId(n.conversationId);if(a!==void 0&&r.set(ConversationIdKey,a),r.set(BundleKey,t),setChannelContext(r,n.adapter,{channelName:n.channelName}),r.set(ConversationContextKey,buildConversationContext(n,resolveInstrumentationEnvironment())),n.parent===void 0||n.traceRoot?.kind===`own`){let e=deriveSessionTitle(n.title??n.input.message);e!==void 0&&r.set(SessionTitleKey,e)}if(n.channelMetadata!==void 0){let e=r.get(ChannelInstrumentationKey);r.set(ChannelInstrumentationKey,{channelType:e?.channelType??n.channelMetadata.channelType,kind:e?.kind??n.channelMetadata.kind,metadata:n.channelMetadata.metadata})}n.continuationToken!==void 0&&(r.set(ContinuationTokenKey,n.continuationToken),r.set(ContinuationHookTokensKey,[n.continuationToken]));let o=n.schedule?.occurrenceId??contextStorage.getStore()?.get(OccurrenceIdKey);o!==void 0&&r.set(OccurrenceIdKey,o),r.set(AuthKey,i),n.toolStubs!==void 0&&r.set(ToolStubsKey,n.toolStubs),(n.initiatorAuth!==void 0||n.input.message!==void 0)&&r.set(InitiatorAuthKey,n.initiatorAuth??i),e.dynamicSubagentAgentConfig!==void 0&&r.set(DynamicSubagentAgentConfigKey,e.dynamicSubagentAgentConfig),e.agentSessionRuntimeOverrides!==void 0&&r.set(AgentSessionRuntimeOverridesKey,e.agentSessionRuntimeOverrides),n.capabilities!==void 0&&r.set(CapabilitiesKey,n.capabilities),n.requestId!==void 0&&r.set(ChannelRequestIdKey,n.requestId);let s=n.schedule?.instance??contextStorage.getStore()?.get(ScheduleInstanceKey);s!==void 0&&r.set(ScheduleInstanceKey,s);let c=n.schedule?.definition??contextStorage.getStore()?.get(ScheduleIdKey);return c!==void 0&&r.set(ScheduleIdKey,c),n.delivery!==void 0&&r.set(ChannelDeliveryKey,n.delivery),n.callback!==void 0&&r.set(SessionCallbackKey,n.callback),n.legacyRemoteAgentCaller!==void 0&&r.set(LegacyRemoteAgentCallerKey,n.legacyRemoteAgentCaller),n.parent!==void 0&&r.set(ParentSessionKey,n.parent),n.traceRoot!==void 0&&r.set(TraceRootKey,n.traceRoot),n.parentTraceContext!==void 0&&r.set(ParentTraceContextKey,n.parentTraceContext),r}export{buildRunContext};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{coalesceDeliveries}from"#harness/messages.js";import{activeTurnId,storedProjection,turnPosition}from"#harness/session-machine/view.js";import{readDurableSession}from"#execution/durable-session-read.js";import{TurnCancelledError}from"#harness/turn-cancellation.js";import{mapHeldInputResponsesStep}from"#execution/proxied-deliver-step.js";import{routeDeliverToChildren}from"#execution/route-child-delivery.js";import{admitSessionInboxPayload}from"#execution/session/admission.js";import{isSteeringDelivery,isSteeringMessage}from"#execution/session/input-queue.js";import{routeSelectedDelivery}from"#execution/session/route-selected-delivery.js";import{createTurnControl}from"#execution/session/turn-control.js";import{decodeSessionInboxPayload}from"#execution/session-inbox/protocol.js";import{runMessageBatchBudget}from"#execution/tools/workflow/messages.js";import{isAppliedRunMessage,takeLeadingAppliedRunMessages}from"#execution/session-workflow-tool-run.js";var ActiveTurn=class{admitted=new Set;routedToChildren=new Set;mappedForHeldRequest=new Set;runtimeResults=[];controller;expectedTurnId;input;identity;unsubscribe;unsubscribeDelivery;steeringController;caller;compacted=!1;constructor(e,t,n=createTurnControl()){this.controller=n.cancellation,this.steeringController=n.steering,this.input=e,this.caller=t.caller,this.identity={callerCallId:t.caller?.callId,principal:t.principal},this.expectedTurnId=activeTurnId(turnPosition(storedProjection(readDurableSession(e.cursor.sessionState).state))),this.unsubscribe=e.inbox.onInterrupt(e=>{this.cancelsThisTurn(e)&&this.abort()}),this.unsubscribeDelivery=e.inbox.onDelivery(this.signalSteering)}signalSteering=e=>{let t;try{t=decodeSessionInboxPayload(e)}catch{return}t.kind===`deliver
|
|
1
|
+
import{coalesceDeliveries}from"#harness/messages.js";import{activeTurnId,storedProjection,turnPosition}from"#harness/session-machine/view.js";import{readDurableSession}from"#execution/durable-session-read.js";import{TurnCancelledError}from"#harness/turn-cancellation.js";import{mapHeldInputResponsesStep}from"#execution/proxied-deliver-step.js";import{routeDeliverToChildren}from"#execution/route-child-delivery.js";import{admitSessionInboxPayload}from"#execution/session/admission.js";import{isSteeringDelivery,isSteeringMessage}from"#execution/session/input-queue.js";import{routeSelectedDelivery}from"#execution/session/route-selected-delivery.js";import{createTurnControl}from"#execution/session/turn-control.js";import{decodeSessionInboxPayload}from"#execution/session-inbox/protocol.js";import{runMessageBatchBudget}from"#execution/tools/workflow/messages.js";import{isAppliedRunMessage,takeLeadingAppliedRunMessages}from"#execution/session-workflow-tool-run.js";var ActiveTurn=class{admitted=new Set;routedToChildren=new Set;mappedForHeldRequest=new Set;runtimeResults=[];controller;expectedTurnId;input;identity;unsubscribe;unsubscribeDelivery;steeringController;caller;compacted=!1;constructor(e,t,n=createTurnControl()){this.controller=n.cancellation,this.steeringController=n.steering,this.input=e,this.caller=t.caller,this.identity={callerCallId:t.caller?.callId,principal:t.principal},this.expectedTurnId=activeTurnId(turnPosition(storedProjection(readDurableSession(e.cursor.sessionState).state))),this.unsubscribe=e.inbox.onInterrupt(e=>{this.cancelsThisTurn(e)&&this.abort()}),this.unsubscribeDelivery=e.inbox.onDelivery(this.signalSteering)}signalSteering=e=>{let t;try{t=decodeSessionInboxPayload(e)}catch{return}t.kind===`deliver`&&!this.input.queue.isDuplicate(t)&&isSteeringMessage(t,this.identity)&&!this.input.cursor.sessionState.hasProxyInputRequests&&this.steeringController.abort()};get signal(){return this.controller.signal}dispose(){this.unsubscribe(),this.unsubscribeDelivery()}get steeringSignal(){return this.steeringController.signal}resetSteering(){this.steeringController.signal.aborted&&(this.unsubscribeDelivery(),this.steeringController=new AbortController,this.unsubscribeDelivery=this.input.inbox.onDelivery(this.signalSteering))}async admitBoundary(){let e=this.input.inbox.drain();for(let t of e)await this.admit(t)}async takeSteering(e){let t=[];for(;;){let n=this.input.queue.takeSteering(this.admitted,this.identity,e);if(n===void 0)break;for(let e of n.sequences)this.admitted.delete(e);let r=await routeSelectedDelivery(n,this.input.cursor);if(r.kind===`cancel-turn`){this.abort();break}r.kind===`turn`&&t.push(r.delivery)}if(this.resetSteering(),t.length===0)return;let n=t.length===1?t[0]:coalesceDeliveries(t);return n.caller!==void 0&&(this.caller=n.caller),n}takeBoundaryMessages(e){let t=[],n=[];for(let r of this.runtimeResults){let i=asBoundaryMessage(r);i===void 0||e!==void 0&&i.kind!==e?n.push(r):t.push(i)}return this.runtimeResults.splice(0,this.runtimeResults.length,...n),t}takeAppliedRunMessages(){let e=runMessageBatchBudget(),t=[];for(let n=this.runtimeResults[0];n!==void 0;n=this.runtimeResults[0]){if(n===`cancelled`||n.kind!==`workflow`||!isAppliedRunMessage(n.message)||!e(n.message))return t;t.push(n.message),this.runtimeResults.shift()}return[...t,...takeLeadingAppliedRunMessages(this.input.inbox,e)]}async nextRuntimeEvent(e){for(;;){let t=await this.routeAdmittedToChildren();if(this.signal.aborted)return`cancelled`;if(t)return{kind:`steering`};let n=this.runtimeResults.shift();if(n!==void 0)return n;let r=await this.waitForInboxOrTimer(e);if(r!==void 0)return{callId:r,kind:`timeout`};let i=await this.input.inbox.next();if(i===void 0)throw Error(`Session inbox closed before runtime actions completed.`);if(await this.admit(i))return{kind:`input`}}}async takeInputResponses(e){for(let t of this.admitted){let n=this.input.queue.delivery(t);if(n===void 0)continue;let r=n.payloads.flatMap(e=>e.inputResponses??[]);if(r.length===0)continue;if(!r.some(t=>e.has(t.requestId))){if(this.mappedForHeldRequest.has(t))continue;this.mappedForHeldRequest.add(t);let r=n,i=await this.input.cursor.advance(t=>mapHeldInputResponsesStep({delivery:r,requestIds:[...e],...t}));if(i.delivery===void 0)continue;n=i.delivery}this.admitted.delete(t);let i=isSteeringDelivery(n,this.identity,{heldOnPerson:!0})?void 0:splitAnswers(n);return this.input.queue.replaceDelivery(t,i?.rest),i?.answers??n}}async waitForInboxOrTimer(e){if(e.length===0||this.input.inbox.hasPending())return;let t=this.input.inbox.whenPending().then(()=>void 0);return await Promise.race([t,...e])}cancelsThisTurn(e){return e.kind===`reset`||e.kind===`session-failure`?!0:e.kind===`cancel`?e.turnId===void 0||e.turnId===this.expectedTurnId:!1}async admit(e){let t=await admitSessionInboxPayload(e,this.input);switch(t.kind){case`delivery`:return this.admitted.add(t.admission.sequence),!0;case`runtime-action-result`:return this.runtimeResults.push({kind:`runtime-action-result`,results:t.payload.results}),!1;case`workflow`:return this.runtimeResults.push({kind:`workflow`,message:t.message}),!1;case`cancel`:return this.cancelsThisTurn(e)&&this.abort(),!1;case`consumed`:return e.kind===`authorization-callback`}}async routeAdmittedToChildren(){let e=!1;for(let t of this.admitted){if(this.routedToChildren.has(t))continue;let n=this.input.queue.delivery(t);if(n===void 0){this.admitted.delete(t);continue}this.routedToChildren.add(t);let r=await this.input.cursor.advance(e=>routeDeliverToChildren({delivery:n,...e}));if(r.kind===`cancel-turn`)return this.input.queue.replaceDelivery(t,void 0),this.admitted.delete(t),this.abort(),!1;if(this.input.queue.replaceDelivery(t,r.remainder),r.remainder===void 0){this.admitted.delete(t);continue}isSteeringMessage(r.remainder,this.identity)&&(e=!0)}return e}abort(){this.controller.signal.aborted||this.controller.abort(new TurnCancelledError)}};function asBoundaryMessage(e){if(e!==`cancelled`&&e.kind===`workflow`&&(e.message.from.taskId!==void 0||e.message.kind===`agent-started`))return e.message}function splitAnswers(e){let t=e.payloads.flatMap(e=>e.inputResponses===void 0?[]:[{inputResponses:e.inputResponses}]),n=e.payloads.flatMap(e=>{let{inputResponses:t,...n}=e;return Object.keys(n).length===0?[]:[n]});return{answers:{...e,payloads:t},rest:n.length===0?void 0:{...e,payloads:n}}}export{ActiveTurn};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getWorkflowMetadata}from"#compiled/@workflow/core/index.js";import{isWorkflowMessage}from"#execution/session-inbox/inbox.js";import{SessionInboxPayloadError,decodeSessionInboxPayload}from"#execution/session-inbox/protocol.js";import{reportDroppedWirePayloadStep}from"#execution/report-dropped-wire-payload-step.js";async function admitSessionInboxPayload(e,t){if(e.kind===`session-failure`)throw Error(e.error);if(e.kind===`runtime-action-result`)return{kind:`runtime-action-result`,payload:e};if(isWorkflowMessage(e))return{kind:`workflow`,message:e};if(e.kind===`authorization-callback`)return t.queue.enqueueAuthorization(e.payloads),{kind:`consumed`};if(e.kind===`subagent-input-request`||e.kind===`subagent-authorization-event`)return{kind:`consumed`};let n;try{n=decodeSessionInboxPayload(e)}catch(e){if(!(e instanceof SessionInboxPayloadError))throw e;return await reportDroppedWirePayloadStep({detail:e.message,family:`session-inbox`}),{kind:`consumed`}}switch(n.kind){case`deliver`:
|
|
1
|
+
import{getWorkflowMetadata}from"#compiled/@workflow/core/index.js";import{isWorkflowMessage}from"#execution/session-inbox/inbox.js";import{SessionInboxPayloadError,decodeSessionInboxPayload}from"#execution/session-inbox/protocol.js";import{reportDroppedWirePayloadStep}from"#execution/report-dropped-wire-payload-step.js";async function admitSessionInboxPayload(e,t){if(e.kind===`session-failure`)throw Error(e.error);if(e.kind===`runtime-action-result`)return{kind:`runtime-action-result`,payload:e};if(isWorkflowMessage(e))return{kind:`workflow`,message:e};if(e.kind===`authorization-callback`)return t.queue.enqueueAuthorization(e.payloads),{kind:`consumed`};if(e.kind===`subagent-input-request`||e.kind===`subagent-authorization-event`)return{kind:`consumed`};let n;try{n=decodeSessionInboxPayload(e)}catch(e){if(!(e instanceof SessionInboxPayloadError))throw e;return await reportDroppedWirePayloadStep({detail:e.message,family:`session-inbox`}),{kind:`consumed`}}switch(n.kind){case`deliver`:{let e=t.queue.enqueueDelivery(n);return e===void 0?{kind:`consumed`}:{admission:e,kind:`delivery`}}case`clear`:case`compact`:return t.queue.enqueueControl(n.kind),{kind:`consumed`};case`session-timeout`:return n.ownerRunId===getWorkflowMetadata().workflowRunId&&t.queue.enqueueControl(`expired`),{kind:`consumed`};case`reset`:return t.queue.enqueueControl(`reset`),{kind:`cancel`};case`cancel`:return{kind:`cancel`}}}export{admitSessionInboxPayload};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{initialSessionProjection}from"#protocol/session-projection.js";import{isObject}from"#shared/guards.js";import{getBlockingWorkflowToolRuns}from"#harness/workflow-tool-runs.js";import{SESSION_CHECKPOINT_VERSION}from"#execution/session/handoff.js";import{LEGACY_HITL_STATE_KEYS,upgradeLegacyHitlState}from"#harness/hitl/requests.js";const MIN_SESSION_CHECKPOINT_VERSION=8,CHECKPOINT_UPGRADES={8:e=>{let{mode:t,...n}=e;return{...n,serializedContext:omitKeys(readRecord(n,`serializedContext`),[`eve.mode`])}},9:(e,t)=>{let n=readRecord(e,`sessionState`),r=readRecord(n,`snapshot`),{taskId:i,...a}=readRecord(r,`session`);return{...e,serializedContext:upgradeLegacyCaller(omitKeys(readRecord(e,`serializedContext`),[`eve.activityObserver`,`eve.activityPendingBlockers`,`eve.activityRootTurnId`,`eve.connectionSearchResults`,`eve.internal.backgroundToolExecution`,`eve.runtime.taskDeliveryPolicy`,`eve.turnTaskDelivery`])),sessionState:{...n,snapshot:{...r,session:{...a,history:readArray(a,`history`).map(renameBackgroundTaskMessage),state:upgradeSessionState(a.state,t)}}}}},10:e=>{let t=readRecord(e,`sessionState`),n=readRecord(t,`snapshot`),{history:r,...i}=readRecord(n,`session`);return t.version!==1&&refuse(`durable session version is not 1`),Array.isArray(r)||refuse(`session history is missing`),{...e,history:r,sessionState:{...t,snapshot:{...n,session:i},version:2}}},11:upgradeIdleLifecycle,12:e=>e,13:e=>e,14:e=>{let t=readRecord(e,`sessionState`),n=readRecord(t,`snapshot`),r=readRecord(n,`session`);if(r.state===void 0)return e;let i=upgradeLegacyHitlState(readRecord(r,`state`));return{...e,sessionState:{...t,snapshot:{...n,session:{...r,state:i}}}}}};function migrateSessionCheckpoint(e){if(!isObject(e))return{kind:`incompatible`,detail:`checkpoint is not an object`};let{version:t}=e;if(typeof t!=`number`||!Number.isSafeInteger(t)||t<8||t>SESSION_CHECKPOINT_VERSION)return{kind:`incompatible`,detail:`checkpoint version ${JSON.stringify(t)} is outside the supported range 8-${SESSION_CHECKPOINT_VERSION}`};let n={childRunIdsToStop:[]},r=e;try{for(let e=t;e<SESSION_CHECKPOINT_VERSION;e++){let t=CHECKPOINT_UPGRADES[e];t===void 0&&refuse(`no upgrade from checkpoint version ${e}`),r={...t(r,n),version:e+1}}}catch(e){if(!(e instanceof CheckpointRefusal))throw e;return{kind:`incompatible`,detail:`checkpoint version ${t}: ${e.message}`}}return isCurrentCheckpoint(r)?{kind:`current`,checkpoint:r,childRunIdsToStop:n.childRunIdsToStop}:{kind:`incompatible`,detail:`checkpoint version ${t} is incomplete`}}function upgradeIdleLifecycle(e){let t=readRecord(e,`sessionState`);t.version!==2&&refuse(`durable session version is not 2`);let n=readRecord(t,`snapshot`),r=readRecord(n,`session`),i=r.state===void 0?{}:readRecord(r,`state`),a=i[`eve.harness.emission`]??t.emissionState;(!isObject(a)||typeof a.sessionStarted!=`boolean`||!Number.isSafeInteger(a.sequence)||a.sequence<0||!Number.isSafeInteger(a.stepIndex)||a.stepIndex<0||a.turnId!==``)&&refuse(`lifecycle position is malformed or a turn is still open`),[LEGACY_HITL_STATE_KEYS.signIns,`eve.runtime.pendingInputBatch`,`eve.runtime.pendingCoordinationBatch`,`eve.runtime.deferredStepInput`,`eve.harness.pendingWorkflowInterrupt`].some(e=>i[e]!==void 0)&&refuse(`session holds pending work`);let o=i[`eve.runtime.pendingInputBatches`];o!==void 0&&(!Array.isArray(o)||o.length>0)&&refuse(`session holds pending input`);let s=i[LEGACY_HITL_STATE_KEYS.relays];(t.hasProxyInputRequests!==!1||s!==void 0&&(!isObject(s)||Object.keys(s).length>0))&&refuse(`session holds relayed input`);try{getBlockingWorkflowToolRuns(i).length>0&&refuse(`session holds workflow runs`)}catch(e){if(e instanceof CheckpointRefusal)throw e;refuse(`workflow tool run registry is incompatible`)}let c=i[LEGACY_HITL_STATE_KEYS.approvals];c!==void 0&&(!isObject(c)||!isObject(c.activeCandidates)||Object.keys(c.activeCandidates).length>0)&&refuse(`session holds approval candidates or malformed approval state`);let l=i[`eve.runtime.hitl.approvedTools`]??[];(!Array.isArray(l)||!l.every(e=>typeof e==`string`))&&refuse(`approval grants are malformed`),(i[`eve.harness.turnState`]!==void 0||i[`eve.harness.sessionProjection`]!==void 0)&&refuse(`v11 checkpoint already contains machine state`);let u={...initialSessionProjection(),nextSequence:a.sequence};a.sessionStarted&&(u.started=!0);let d={...omitKeys(i,[`eve.harness.emission`,`eve.runtime.hitl.approvedTools`,`eve.runtime.pendingInputBatches`]),"eve.harness.sessionProjection":u};l.length>0&&(d[`eve.harness.turnState`]={grants:[...l],suspended:[]});let{emissionState:f,...p}=t;return{...e,sessionState:{...p,snapshot:{...n,session:{...r,state:d}}}}}function isCurrentCheckpoint(e){return isObject(e)&&e.version===SESSION_CHECKPOINT_VERSION&&Array.isArray(e.history)&&isObject(e.serializedContext)&&isObject(e.sessionState)}var CheckpointRefusal=class extends Error{};function refuse(e){throw new CheckpointRefusal(e)}function readRecord(e,t){let n=e[t];return isObject(n)||refuse(`${t} is not an object`),n}function readArray(e,t){let n=e[t];return Array.isArray(n)||refuse(`${t} is not an array`),n}function omitKeys(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e)))}function upgradeLegacyCaller(e){let t=e[`eve.sessionCallback`];if(!isObject(t))return e;let{taskId:n,...r}=t;return{...e,"eve.legacyRemoteAgentCaller":typeof n==`string`&&n.length>0?{taskId:n}:{},"eve.sessionCallback":r}}function renameBackgroundTaskMessage(e){return isObject(e)&&e.role===`user`&&e.kind===`execution.background_task`?{...e,kind:`task.result`}:e}function upgradeSessionState(e,t){return isObject(e)?omitKeys(e,[...dropSettledWorkflowToolRuns(e),...stopIdleSubagents(e,t)]):e}function dropSettledWorkflowToolRuns(e){let t=e[`eve.workflowTool`];if(!isObject(t)||t.version!==3)return[];let n=t.runs;return(!Array.isArray(n)||!n.every(e=>isObject(e)&&e.lifetime===`session`&&isObject(e.task)&&e.task.outcome!==void 0))&&refuse(`workflow tool run registry version 3 holds unsettled runs`),[`eve.workflowTool`]}function stopIdleSubagents(e,t){let n=e[`eve.agent.handles`];if(n===void 0)return[];(!isObject(n)||!Array.isArray(n.handles))&&refuse(`subagent handles are malformed`);for(let e of n.handles){(!isObject(e)||e.phase!==`parked`&&e.phase!==`available`)&&refuse(`a subagent session is still working`);let n=e.address;isObject(n)&&(n.kind===`agent/local`||n.kind===`agent/self`)&&typeof n.sessionId==`string`&&n.sessionId.length>0&&t.childRunIdsToStop.push(n.sessionId)}return[`eve.agent.handles`]}export{MIN_SESSION_CHECKPOINT_VERSION,migrateSessionCheckpoint};
|
|
1
|
+
import{initialSessionProjection}from"#protocol/session-projection.js";import{isObject}from"#shared/guards.js";import{DELIVERY_IDEMPOTENCY_WINDOW,MAX_DELIVERY_IDEMPOTENCY_KEY_LENGTH}from"#channel/delivery-idempotency.js";import{getBlockingWorkflowToolRuns}from"#harness/workflow-tool-runs.js";import{SESSION_CHECKPOINT_VERSION}from"#execution/session/handoff.js";import{LEGACY_HITL_STATE_KEYS,upgradeLegacyHitlState}from"#harness/hitl/requests.js";const MIN_SESSION_CHECKPOINT_VERSION=8,CHECKPOINT_UPGRADES={8:e=>{let{mode:t,...n}=e;return{...n,serializedContext:omitKeys(readRecord(n,`serializedContext`),[`eve.mode`])}},9:(e,t)=>{let n=readRecord(e,`sessionState`),r=readRecord(n,`snapshot`),{taskId:i,...a}=readRecord(r,`session`);return{...e,serializedContext:upgradeLegacyCaller(omitKeys(readRecord(e,`serializedContext`),[`eve.activityObserver`,`eve.activityPendingBlockers`,`eve.activityRootTurnId`,`eve.connectionSearchResults`,`eve.internal.backgroundToolExecution`,`eve.runtime.taskDeliveryPolicy`,`eve.turnTaskDelivery`])),sessionState:{...n,snapshot:{...r,session:{...a,history:readArray(a,`history`).map(renameBackgroundTaskMessage),state:upgradeSessionState(a.state,t)}}}}},10:e=>{let t=readRecord(e,`sessionState`),n=readRecord(t,`snapshot`),{history:r,...i}=readRecord(n,`session`);return t.version!==1&&refuse(`durable session version is not 1`),Array.isArray(r)||refuse(`session history is missing`),{...e,history:r,sessionState:{...t,snapshot:{...n,session:i},version:2}}},11:upgradeIdleLifecycle,12:e=>e,13:e=>e,14:e=>{let t=readRecord(e,`sessionState`),n=readRecord(t,`snapshot`),r=readRecord(n,`session`);if(r.state===void 0)return e;let i=upgradeLegacyHitlState(readRecord(r,`state`));return{...e,sessionState:{...t,snapshot:{...n,session:{...r,state:i}}}}},15:e=>({...e,admittedDeliveryKeys:[]})};function migrateSessionCheckpoint(e){if(!isObject(e))return{kind:`incompatible`,detail:`checkpoint is not an object`};let{version:t}=e;if(typeof t!=`number`||!Number.isSafeInteger(t)||t<8||t>SESSION_CHECKPOINT_VERSION)return{kind:`incompatible`,detail:`checkpoint version ${JSON.stringify(t)} is outside the supported range 8-${SESSION_CHECKPOINT_VERSION}`};let n={childRunIdsToStop:[]},r=e;try{for(let e=t;e<SESSION_CHECKPOINT_VERSION;e++){let t=CHECKPOINT_UPGRADES[e];t===void 0&&refuse(`no upgrade from checkpoint version ${e}`),r={...t(r,n),version:e+1}}}catch(e){if(!(e instanceof CheckpointRefusal))throw e;return{kind:`incompatible`,detail:`checkpoint version ${t}: ${e.message}`}}return isCurrentCheckpoint(r)?{kind:`current`,checkpoint:r,childRunIdsToStop:n.childRunIdsToStop}:{kind:`incompatible`,detail:`checkpoint version ${t} is incomplete`}}function upgradeIdleLifecycle(e){let t=readRecord(e,`sessionState`);t.version!==2&&refuse(`durable session version is not 2`);let n=readRecord(t,`snapshot`),r=readRecord(n,`session`),i=r.state===void 0?{}:readRecord(r,`state`),a=i[`eve.harness.emission`]??t.emissionState;(!isObject(a)||typeof a.sessionStarted!=`boolean`||!Number.isSafeInteger(a.sequence)||a.sequence<0||!Number.isSafeInteger(a.stepIndex)||a.stepIndex<0||a.turnId!==``)&&refuse(`lifecycle position is malformed or a turn is still open`),[LEGACY_HITL_STATE_KEYS.signIns,`eve.runtime.pendingInputBatch`,`eve.runtime.pendingCoordinationBatch`,`eve.runtime.deferredStepInput`,`eve.harness.pendingWorkflowInterrupt`].some(e=>i[e]!==void 0)&&refuse(`session holds pending work`);let o=i[`eve.runtime.pendingInputBatches`];o!==void 0&&(!Array.isArray(o)||o.length>0)&&refuse(`session holds pending input`);let s=i[LEGACY_HITL_STATE_KEYS.relays];(t.hasProxyInputRequests!==!1||s!==void 0&&(!isObject(s)||Object.keys(s).length>0))&&refuse(`session holds relayed input`);try{getBlockingWorkflowToolRuns(i).length>0&&refuse(`session holds workflow runs`)}catch(e){if(e instanceof CheckpointRefusal)throw e;refuse(`workflow tool run registry is incompatible`)}let c=i[LEGACY_HITL_STATE_KEYS.approvals];c!==void 0&&(!isObject(c)||!isObject(c.activeCandidates)||Object.keys(c.activeCandidates).length>0)&&refuse(`session holds approval candidates or malformed approval state`);let l=i[`eve.runtime.hitl.approvedTools`]??[];(!Array.isArray(l)||!l.every(e=>typeof e==`string`))&&refuse(`approval grants are malformed`),(i[`eve.harness.turnState`]!==void 0||i[`eve.harness.sessionProjection`]!==void 0)&&refuse(`v11 checkpoint already contains machine state`);let u={...initialSessionProjection(),nextSequence:a.sequence};a.sessionStarted&&(u.started=!0);let d={...omitKeys(i,[`eve.harness.emission`,`eve.runtime.hitl.approvedTools`,`eve.runtime.pendingInputBatches`]),"eve.harness.sessionProjection":u};l.length>0&&(d[`eve.harness.turnState`]={grants:[...l],suspended:[]});let{emissionState:f,...p}=t;return{...e,sessionState:{...p,snapshot:{...n,session:{...r,state:d}}}}}function isCurrentCheckpoint(e){return isObject(e)&&e.version===SESSION_CHECKPOINT_VERSION&&Array.isArray(e.admittedDeliveryKeys)&&e.admittedDeliveryKeys.length<=DELIVERY_IDEMPOTENCY_WINDOW&&e.admittedDeliveryKeys.every(e=>typeof e==`string`&&e.length>0&&e.length<=MAX_DELIVERY_IDEMPOTENCY_KEY_LENGTH)&&Array.isArray(e.history)&&isObject(e.serializedContext)&&isObject(e.sessionState)}var CheckpointRefusal=class extends Error{};function refuse(e){throw new CheckpointRefusal(e)}function readRecord(e,t){let n=e[t];return isObject(n)||refuse(`${t} is not an object`),n}function readArray(e,t){let n=e[t];return Array.isArray(n)||refuse(`${t} is not an array`),n}function omitKeys(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e)))}function upgradeLegacyCaller(e){let t=e[`eve.sessionCallback`];if(!isObject(t))return e;let{taskId:n,...r}=t;return{...e,"eve.legacyRemoteAgentCaller":typeof n==`string`&&n.length>0?{taskId:n}:{},"eve.sessionCallback":r}}function renameBackgroundTaskMessage(e){return isObject(e)&&e.role===`user`&&e.kind===`execution.background_task`?{...e,kind:`task.result`}:e}function upgradeSessionState(e,t){return isObject(e)?omitKeys(e,[...dropSettledWorkflowToolRuns(e),...stopIdleSubagents(e,t)]):e}function dropSettledWorkflowToolRuns(e){let t=e[`eve.workflowTool`];if(!isObject(t)||t.version!==3)return[];let n=t.runs;return(!Array.isArray(n)||!n.every(e=>isObject(e)&&e.lifetime===`session`&&isObject(e.task)&&e.task.outcome!==void 0))&&refuse(`workflow tool run registry version 3 holds unsettled runs`),[`eve.workflowTool`]}function stopIdleSubagents(e,t){let n=e[`eve.agent.handles`];if(n===void 0)return[];(!isObject(n)||!Array.isArray(n.handles))&&refuse(`subagent handles are malformed`);for(let e of n.handles){(!isObject(e)||e.phase!==`parked`&&e.phase!==`available`)&&refuse(`a subagent session is still working`);let n=e.address;isObject(n)&&(n.kind===`agent/local`||n.kind===`agent/self`)&&typeof n.sessionId==`string`&&n.sessionId.length>0&&t.childRunIdsToStop.push(n.sessionId)}return[`eve.agent.handles`]}export{MIN_SESSION_CHECKPOINT_VERSION,migrateSessionCheckpoint};
|
|
@@ -2,20 +2,24 @@ import type { TokenUsage } from "#shared/token-usage.js";
|
|
|
2
2
|
import type { DeliverHookPayload, RunInput, SessionCommand } from "#channel/types.js";
|
|
3
3
|
import type { SessionCheckpoint } from "#execution/session/handoff.js";
|
|
4
4
|
import type { AgentWorkflowRetentionDefinition } from "#shared/agent-definition.js";
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Version 3 sources keep their hooks while the successor starts: it takes
|
|
7
|
+
* them over with forced claims and the source hands over what it accepted
|
|
8
|
+
* meanwhile. Earlier sources released their hooks before starting it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SESSION_HANDOFF_VERSION = 3;
|
|
7
11
|
/**
|
|
8
12
|
* Serializable workflow-entry input. All runtime state travels via
|
|
9
13
|
* `serializedContext`, which is produced by `serializeContext(ctx)`
|
|
10
14
|
* and deserialized at each `"use step"` boundary.
|
|
11
15
|
*/
|
|
12
16
|
export interface InitialWorkflowEntryInput {
|
|
17
|
+
readonly idempotencyKey?: string;
|
|
13
18
|
readonly continuationConflictCommand?: Extract<SessionCommand, {
|
|
14
19
|
readonly kind: "send";
|
|
15
20
|
}>;
|
|
16
21
|
readonly input: RunInput["input"];
|
|
17
22
|
readonly kind: "initial";
|
|
18
|
-
readonly limits?: RunInput["limits"];
|
|
19
23
|
readonly ownerDeploymentId: string;
|
|
20
24
|
readonly retention?: AgentWorkflowRetentionDefinition;
|
|
21
25
|
readonly sessionTimeoutMs?: number | false;
|
|
@@ -34,19 +38,27 @@ export type SessionHandoffStart = {
|
|
|
34
38
|
*/
|
|
35
39
|
readonly reason: "compaction";
|
|
36
40
|
/**
|
|
37
|
-
*
|
|
38
|
-
* first. Without one, the
|
|
41
|
+
* Only sources older than version 3 send one: the lone delivery that
|
|
42
|
+
* arrived before they could move, processed first. Without one, the
|
|
43
|
+
* successor parks until the next input arrives.
|
|
39
44
|
*/
|
|
40
45
|
readonly delivery?: DeliverHookPayload;
|
|
41
|
-
/** Compaction does not extend the session's lifetime. */
|
|
42
|
-
readonly sessionTimeoutDeadline?: Date;
|
|
43
46
|
};
|
|
44
47
|
/** A successor owner started by a previous owner during a handoff. */
|
|
45
48
|
export type HandoffWorkflowEntryInput = SessionHandoffStart & {
|
|
46
49
|
readonly activationToken: string;
|
|
50
|
+
/**
|
|
51
|
+
* Version 3: names this attempt, so a duplicate candidate fences itself out
|
|
52
|
+
* and the source's handover reaches the successor that expects it.
|
|
53
|
+
*/
|
|
54
|
+
readonly attemptKey?: string;
|
|
47
55
|
readonly checkpoint: SessionCheckpoint;
|
|
48
|
-
/** Omitted by version 1 sources
|
|
56
|
+
/** Omitted by version 1 sources. */
|
|
49
57
|
readonly handoffVersion?: number;
|
|
58
|
+
/** Version 3: the source's logical hook set, which the successor takes over. */
|
|
59
|
+
readonly hookTokens?: readonly string[];
|
|
60
|
+
/** Version 3: the source run, whose handover the successor waits for while it lives. */
|
|
61
|
+
readonly sourceRunId?: string;
|
|
50
62
|
readonly kind: "handoff";
|
|
51
63
|
readonly ownerDeploymentId: string;
|
|
52
64
|
readonly sessionWritable: WritableStream<Uint8Array>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const SESSION_HANDOFF_VERSION=
|
|
1
|
+
const SESSION_HANDOFF_VERSION=3;export{SESSION_HANDOFF_VERSION};
|