eve 0.69.0 → 0.70.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 +36 -0
- package/dist/src/acp/adapter.js +1 -1
- package/dist/src/channel/task-card.d.ts +3 -3
- package/dist/src/channel/task-card.js +1 -1
- package/dist/src/channel/types.d.ts +18 -0
- package/dist/src/chunks/{use-eve-agent-Dab2MnT2.js → use-eve-agent-CJQeE7-t.js} +1873 -1236
- package/dist/src/chunks/{use-eve-agent-D_5129A9.js → use-eve-agent-DdemtY6C.js} +1874 -1234
- package/dist/src/cli/dev/command.js +1 -1
- package/dist/src/cli/dev/console-records-preload.d.ts +1 -0
- package/dist/src/cli/dev/console-records-preload.js +1 -0
- package/dist/src/cli/dev/console-records.d.ts +17 -0
- package/dist/src/cli/dev/console-records.js +3 -0
- package/dist/src/cli/dev/diagnostic-sink.d.ts +1 -0
- package/dist/src/cli/dev/local-server-process.js +1 -1
- package/dist/src/cli/dev/tui/blocks.d.ts +2 -1
- package/dist/src/cli/dev/tui/blocks.js +3 -3
- package/dist/src/cli/dev/tui/conversation-view.d.ts +54 -0
- package/dist/src/cli/dev/tui/conversation-view.js +1 -0
- package/dist/src/cli/dev/tui/flow-drawer.d.ts +5 -2
- package/dist/src/cli/dev/tui/flow-drawer.js +1 -1
- package/dist/src/cli/dev/tui/log-display-mode.d.ts +4 -10
- package/dist/src/cli/dev/tui/log-display-mode.js +1 -1
- package/dist/src/cli/dev/tui/message-queue.d.ts +7 -63
- package/dist/src/cli/dev/tui/message-queue.js +3 -1
- package/dist/src/cli/dev/tui/prompt-commands.js +1 -1
- package/dist/src/cli/dev/tui/question-panel.d.ts +3 -1
- package/dist/src/cli/dev/tui/question-panel.js +1 -1
- package/dist/src/cli/dev/tui/runner.d.ts +56 -193
- package/dist/src/cli/dev/tui/runner.js +3 -3
- package/dist/src/cli/dev/tui/task-activity.d.ts +11 -7
- package/dist/src/cli/dev/tui/task-activity.js +1 -1
- package/dist/src/cli/dev/tui/terminal-renderer.d.ts +15 -37
- package/dist/src/cli/dev/tui/terminal-renderer.js +10 -13
- package/dist/src/cli/dev/tui/terminal-tool-part.d.ts +2 -0
- package/dist/src/cli/dev/tui/terminal-tool-part.js +1 -0
- package/dist/src/cli/dev/tui/test/fake-eve-server.d.ts +34 -0
- package/dist/src/cli/dev/tui/test/fake-eve-server.js +1 -0
- package/dist/src/cli/dev/tui/test/index.d.ts +1 -0
- package/dist/src/cli/dev/tui/test/index.js +1 -1
- package/dist/src/cli/dev/tui/tool-block-groups.js +1 -1
- package/dist/src/cli/dev/tui/tool-presentation.d.ts +1 -0
- package/dist/src/cli/dev/tui/tool-presentation.js +1 -1
- package/dist/src/cli/dev/tui/tool-rows.d.ts +1 -0
- package/dist/src/cli/dev/tui/tool-rows.js +2 -2
- package/dist/src/cli/dev/tui/transcript-parts.d.ts +73 -0
- package/dist/src/cli/dev/tui/transcript-parts.js +3 -0
- package/dist/src/cli/dev/tui/transcript.d.ts +47 -0
- package/dist/src/cli/dev/tui/transcript.js +1 -0
- package/dist/src/cli/dev/tui/tui.js +1 -1
- package/dist/src/cli/dev/tui/turn-clock.d.ts +11 -26
- package/dist/src/cli/dev/tui/turn-clock.js +1 -1
- package/dist/src/cli/dev/tui/types.d.ts +2 -4
- package/dist/src/cli/dev/ui-options.js +1 -1
- package/dist/src/client/agent-stream-follower.d.ts +26 -0
- package/dist/src/client/agent-stream-follower.js +1 -0
- package/dist/src/client/authorization-message-parts.js +1 -1
- package/dist/src/client/conversation-client.d.ts +40 -0
- package/dist/src/client/conversation-client.js +1 -0
- package/dist/src/client/conversation-reducer.d.ts +29 -0
- package/dist/src/client/conversation-reducer.js +1 -0
- package/dist/src/client/conversation-state.d.ts +110 -0
- package/dist/src/client/conversation-state.js +1 -0
- package/dist/src/client/eve-agent-projection.d.ts +24 -7
- package/dist/src/client/eve-agent-projection.js +1 -1
- package/dist/src/client/eve-agent-store-helpers.d.ts +21 -2
- package/dist/src/client/eve-agent-store-helpers.js +2 -2
- package/dist/src/client/eve-agent-store-state.d.ts +15 -3
- package/dist/src/client/eve-agent-store.d.ts +10 -1
- package/dist/src/client/eve-agent-store.js +1 -1
- package/dist/src/client/index.d.ts +4 -1
- package/dist/src/client/index.js +1 -1
- package/dist/src/client/message-reducer-primitives.d.ts +1 -2
- package/dist/src/client/message-reducer-primitives.js +1 -1
- package/dist/src/client/message-reducer-types.d.ts +9 -2
- package/dist/src/client/message-reducer.js +1 -1
- package/dist/src/client/message-response.js +1 -1
- package/dist/src/client/message-run-parts.d.ts +10 -6
- package/dist/src/client/message-run-parts.js +1 -1
- package/dist/src/client/optimistic-message-submissions.d.ts +6 -4
- package/dist/src/client/optimistic-message-submissions.js +1 -1
- package/dist/src/client/reducer.d.ts +5 -1
- package/dist/src/client/session-turn-dispatch.d.ts +15 -0
- package/dist/src/client/session-turn-dispatch.js +1 -0
- package/dist/src/client/session-utils.d.ts +27 -10
- package/dist/src/client/session-utils.js +1 -1
- package/dist/src/client/session.js +1 -1
- package/dist/src/client/types.d.ts +2 -1
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +18 -18
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/load-binding-namespace.js +1 -1
- package/dist/src/context/keys.d.ts +5 -2
- package/dist/src/context/keys.js +1 -1
- package/dist/src/context/provider.d.ts +5 -9
- package/dist/src/context/run-step.d.ts +4 -4
- package/dist/src/context/run-step.js +1 -1
- package/dist/src/evals/runner/derive-run-facts.js +1 -1
- package/dist/src/evals/runner/execute-task.js +1 -1
- package/dist/src/evals/session.js +2 -2
- package/dist/src/evals/types.d.ts +16 -0
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/execution/agent-sessions/context.d.ts +4 -2
- package/dist/src/execution/agent-sessions/context.js +1 -1
- package/dist/src/execution/agent-sessions/steps.js +1 -1
- package/dist/src/execution/cancelled-model-call-batch.js +1 -1
- package/dist/src/execution/coordination-dispatch-shared.d.ts +6 -4
- package/dist/src/execution/coordination-dispatch-shared.js +1 -1
- package/dist/src/execution/create-session-step.d.ts +4 -2
- package/dist/src/execution/create-session-step.js +1 -1
- package/dist/src/execution/durable-session-store.d.ts +10 -4
- package/dist/src/execution/durable-session-store.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/legacy-session/completion-step.d.ts +2 -0
- package/dist/src/execution/legacy-session/completion-step.js +1 -1
- package/dist/src/execution/legacy-session/interrupt-step.js +1 -1
- package/dist/src/execution/legacy-session/prepare-step.d.ts +1 -0
- package/dist/src/execution/legacy-session/prepare-step.js +1 -1
- package/dist/src/execution/legacy-session/snapshot.d.ts +8 -4
- package/dist/src/execution/legacy-session/snapshot.js +1 -1
- package/dist/src/execution/legacy-session/turn-workflow.js +1 -1
- package/dist/src/execution/proxied-deliver-step.js +1 -1
- package/dist/src/execution/publish-session-events.d.ts +27 -7
- package/dist/src/execution/publish-session-events.js +1 -1
- package/dist/src/execution/reconcile-session-continuation-token.d.ts +2 -2
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/session/active-turn.d.ts +97 -0
- package/dist/src/execution/session/active-turn.js +1 -0
- package/dist/src/execution/session/entry.js +1 -1
- package/dist/src/execution/session/finalization.js +1 -1
- package/dist/src/execution/session/handoff.d.ts +5 -3
- package/dist/src/execution/session/handoff.js +1 -1
- package/dist/src/execution/session/input-queue.d.ts +19 -13
- package/dist/src/execution/session/input-queue.js +1 -1
- package/dist/src/execution/session/next-input.d.ts +2 -10
- package/dist/src/execution/session/next-input.js +1 -1
- package/dist/src/execution/session/program.d.ts +2 -0
- package/dist/src/execution/session/program.js +1 -1
- package/dist/src/execution/session/state-cursor.d.ts +22 -16
- package/dist/src/execution/session/state-cursor.js +1 -1
- package/dist/src/execution/session/state-delta.d.ts +8 -1
- package/dist/src/execution/session/state-delta.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-types.d.ts +13 -4
- 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.d.ts +8 -1
- package/dist/src/execution/session/turn.js +1 -1
- package/dist/src/execution/session.d.ts +5 -5
- package/dist/src/execution/session.js +2 -2
- package/dist/src/execution/settle-cancelled-turn-step.d.ts +5 -4
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/tasks/start.d.ts +2 -2
- package/dist/src/execution/tasks/task-id-input.d.ts +1 -1
- package/dist/src/execution/tasks/task-id-input.js +1 -1
- package/dist/src/execution/terminal-session-completion-step.d.ts +2 -0
- package/dist/src/execution/terminal-session-completion-step.js +1 -1
- package/dist/src/execution/terminal-session-failure-step.d.ts +2 -0
- package/dist/src/execution/terminal-session-failure-step.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/tools/connection-target.d.ts +5 -0
- package/dist/src/execution/tools/connection-target.js +1 -1
- package/dist/src/execution/tools/connection-tools.js +2 -2
- package/dist/src/execution/tools/workflow/start.d.ts +3 -3
- package/dist/src/harness/authorization.d.ts +15 -2
- package/dist/src/harness/authorization.js +1 -1
- package/dist/src/harness/cancelled-turn-emission.d.ts +2 -1
- package/dist/src/harness/cancelled-turn-emission.js +1 -1
- package/dist/src/harness/coordination.d.ts +5 -3
- package/dist/src/harness/emission.d.ts +5 -2
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/held-requests.d.ts +18 -0
- package/dist/src/harness/held-requests.js +1 -0
- package/dist/src/harness/hitl/approval-input-requests.d.ts +16 -0
- package/dist/src/harness/hitl/approval-input-requests.js +1 -1
- package/dist/src/harness/input-extraction.js +1 -1
- package/dist/src/harness/input-requests.d.ts +0 -4
- package/dist/src/harness/input-requests.js +1 -1
- package/dist/src/harness/model-call-error.js +1 -1
- package/dist/src/harness/proxy-input-requests.d.ts +4 -4
- package/dist/src/harness/session-limit-enforcement.js +1 -1
- package/dist/src/harness/stale-input-responses.js +1 -1
- package/dist/src/harness/tool-loop.js +2 -2
- package/dist/src/harness/turn-tag-state.d.ts +2 -0
- package/dist/src/harness/turn-tag-state.js +1 -1
- package/dist/src/harness/types.d.ts +23 -11
- package/dist/src/instrumentation/channel-delivery.d.ts +1 -0
- package/dist/src/instrumentation/channel-delivery.js +1 -1
- package/dist/src/instrumentation/lifecycle.d.ts +4 -0
- package/dist/src/instrumentation/memory.d.ts +2 -0
- package/dist/src/instrumentation/memory.js +1 -1
- package/dist/src/instrumentation/native-events.d.ts +1 -0
- package/dist/src/instrumentation/native-events.js +1 -1
- package/dist/src/instrumentation/runtime.d.ts +4 -3
- package/dist/src/instrumentation/runtime.js +1 -1
- package/dist/src/instrumentation/session-init.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-module-loader.d.ts +14 -6
- package/dist/src/internal/authored-module-loader.js +1 -1
- package/dist/src/internal/authored-package-boundary.d.ts +1 -1
- package/dist/src/internal/authored-package-boundary.js +1 -1
- package/dist/src/internal/bundler/extension-mount-plugin.js +1 -1
- package/dist/src/internal/workflow-bundle/dynamic-remote-agent-transform.js +1 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.d.ts +27 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.js +1 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-transform.js +2 -2
- package/dist/src/protocol/message.d.ts +41 -3
- package/dist/src/protocol/message.js +2 -2
- package/dist/src/public/channels/slack/action-status.d.ts +2 -2
- package/dist/src/public/channels/slack/action-status.js +1 -1
- package/dist/src/public/channels/slack/approval-cards.d.ts +15 -0
- package/dist/src/public/channels/slack/approval-cards.js +2 -0
- package/dist/src/public/channels/slack/auth.d.ts +2 -0
- package/dist/src/public/channels/slack/auth.js +1 -1
- package/dist/src/public/channels/slack/connections.d.ts +15 -11
- package/dist/src/public/channels/slack/connections.js +1 -1
- package/dist/src/public/channels/slack/defaults.d.ts +1 -15
- package/dist/src/public/channels/slack/defaults.js +3 -4
- package/dist/src/public/channels/slack/hitl.js +1 -1
- package/dist/src/public/channels/slack/inbound.d.ts +10 -2
- package/dist/src/public/channels/slack/inbound.js +1 -1
- package/dist/src/public/channels/slack/index.d.ts +2 -0
- package/dist/src/public/channels/slack/index.js +1 -1
- package/dist/src/public/channels/slack/input-response.js +1 -1
- package/dist/src/public/channels/slack/interaction-cards.js +1 -1
- package/dist/src/public/channels/slack/interactions.js +1 -1
- package/dist/src/public/channels/slack/limits.d.ts +5 -3
- package/dist/src/public/channels/slack/private-approval-delivery.js +1 -1
- package/dist/src/public/channels/slack/renderers.d.ts +1 -1
- package/dist/src/public/channels/slack/renderers.js +1 -1
- package/dist/src/public/channels/slack/reply-delivery.d.ts +72 -0
- package/dist/src/public/channels/slack/reply-delivery.js +1 -0
- package/dist/src/public/channels/slack/sign-in-cancel.d.ts +20 -0
- package/dist/src/public/channels/slack/sign-in-cancel.js +1 -0
- package/dist/src/public/channels/slack/slackChannel.d.ts +15 -0
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/slack/task-card.js +1 -1
- package/dist/src/public/channels/teams/defaults.d.ts +1 -1
- package/dist/src/public/channels/teams/defaults.js +2 -2
- package/dist/src/public/definitions/channel.d.ts +1 -0
- package/dist/src/public/definitions/channel.js +1 -1
- package/dist/src/public/next/index.js +1 -1
- package/dist/src/public/next/server.d.ts +2 -0
- package/dist/src/public/next/server.js +1 -2
- package/dist/src/public/nuxt/module.d.ts +6 -0
- package/dist/src/public/nuxt/module.js +1 -1
- package/dist/src/react/index.d.ts +3 -0
- package/dist/src/react/index.js +1 -1
- package/dist/src/react/use-eve-agent.d.ts +7 -5
- package/dist/src/react/use-eve-agent.js +1 -1
- package/dist/src/runtime/connections/scoped-authorization.d.ts +2 -0
- package/dist/src/runtime/connections/scoped-authorization.js +1 -1
- package/dist/src/setup/boxes/deploy-project.js +1 -1
- package/dist/src/setup/integrations/web/setup.js +6 -2
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/scaffold/create/web-template.d.ts +2 -2
- package/dist/src/setup/scaffold/create/web-template.js +28 -9
- package/dist/src/setup/vercel-project-framework.js +1 -1
- package/dist/src/shared/display-name.d.ts +15 -0
- package/dist/src/shared/display-name.js +1 -0
- package/dist/src/shared/framework-eve-server.d.ts +43 -0
- package/dist/src/shared/framework-eve-server.js +2 -0
- package/dist/src/shared/token-usage.d.ts +2 -0
- package/dist/src/shared/token-usage.js +1 -1
- package/dist/src/shared/trace-root.d.ts +8 -0
- package/dist/src/shared/trace-root.js +1 -0
- package/dist/src/subagents/hitl-proxy.d.ts +3 -3
- package/dist/src/subagents/hitl-proxy.js +1 -1
- package/dist/src/subagents/invocation.d.ts +3 -1
- package/dist/src/subagents/tool.js +1 -1
- package/dist/src/svelte/index.d.ts +3 -0
- package/dist/src/svelte/index.js +2 -2
- package/dist/src/svelte/use-eve-agent.d.ts +7 -4
- 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/load-skill.js +1 -1
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/tracing/agent-action-instrumentation.js +1 -1
- package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
- package/dist/src/tracing/agent-memory-instrumentation.js +1 -1
- package/dist/src/tracing/agent-otel-attributes.d.ts +6 -0
- package/dist/src/tracing/agent-otel-attributes.js +1 -1
- package/dist/src/tracing/agent-otel-provider.js +2 -2
- package/dist/src/tracing/agent-otel-runtime-context.d.ts +1 -1
- package/dist/src/tracing/agent-otel-runtime-context.js +1 -1
- package/dist/src/tracing/agent-otel-session-context.js +1 -1
- package/dist/src/tracing/agent-span-contract.js +1 -1
- package/dist/src/tracing/agent-tool-instrumentation.js +1 -1
- package/dist/src/tracing/agent-trace-context-codec.d.ts +4 -0
- package/dist/src/tracing/agent-trace-context-codec.js +1 -1
- package/dist/src/tracing/agent-trace-span-processor.js +1 -1
- package/dist/src/tracing/agent-trace-state.d.ts +3 -0
- package/dist/src/tracing/conversation-context.d.ts +10 -0
- package/dist/src/tracing/conversation-context.js +1 -1
- package/dist/src/tracing/otel-registration.js +1 -1
- package/dist/src/vue/index.d.ts +3 -0
- package/dist/src/vue/index.js +2 -2
- package/dist/src/vue/use-eve-agent.d.ts +7 -3
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/channels/slack.mdx +60 -13
- package/docs/concepts/built-in-tools.md +3 -2
- package/docs/concepts/sessions-runs-and-streaming.md +4 -4
- package/docs/connections/overview.mdx +9 -3
- package/docs/evals/reporters.mdx +4 -0
- package/docs/extensions.md +11 -0
- package/docs/guides/client/streaming.mdx +7 -6
- package/docs/guides/deployment/vercel.mdx +2 -1
- package/docs/guides/dev-tui.md +15 -15
- package/docs/guides/dynamic-capabilities.md +1 -1
- package/docs/guides/frontend/nuxt.mdx +24 -4
- package/docs/guides/frontend/overview.mdx +44 -38
- package/docs/guides/frontend/use-eve-agent-svelte.mdx +4 -10
- package/docs/guides/frontend/use-eve-agent-vue.mdx +4 -10
- package/docs/guides/instrumentation/otel.mdx +24 -6
- package/docs/guides/remote-agents.md +26 -8
- package/docs/reference/cli.md +4 -4
- package/docs/tools/human-in-the-loop.md +4 -4
- package/docs/tools/overview.mdx +1 -1
- package/docs/tools/tasks.md +8 -8
- package/package.json +1 -1
- package/dist/src/cli/dev/tui/steering-stream.d.ts +0 -15
- package/dist/src/cli/dev/tui/steering-stream.js +0 -1
- package/dist/src/cli/dev/tui/subagent-pump.d.ts +0 -134
- package/dist/src/cli/dev/tui/subagent-pump.js +0 -1
- package/dist/src/public/nuxt/dev-server.d.ts +0 -25
- package/dist/src/public/nuxt/dev-server.js +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type HarnessEmissionState } from "#harness/emission.js";
|
|
2
2
|
import type { HarnessModelMessage } from "#harness/messages.js";
|
|
3
|
-
import type { HarnessSession, SessionStateMap } from "#harness/types.js";
|
|
3
|
+
import type { HarnessSession, HarnessSessionBase, SessionStateMap } from "#harness/types.js";
|
|
4
4
|
import type { SandboxState } from "#sandbox/state.js";
|
|
5
5
|
import type { JsonObject } from "#shared/json.js";
|
|
6
6
|
/** Explicit checkpoint contract shared by deployment handoffs. */
|
|
7
|
-
export declare const DURABLE_SESSION_VERSION =
|
|
7
|
+
export declare const DURABLE_SESSION_VERSION = 2;
|
|
8
8
|
/**
|
|
9
9
|
* Serializable handle to a durable session.
|
|
10
10
|
*
|
|
@@ -35,6 +35,8 @@ export interface DurableSessionState {
|
|
|
35
35
|
* `agent.compactionModelReference`, and the `compaction` thresholds —
|
|
36
36
|
* those are rebuilt every turn from `bundle.turnAgent` by
|
|
37
37
|
* {@link import("#execution/session.js").hydrateDurableSession}.
|
|
38
|
+
* Omits `history` too: the session workflow carries it as its own value, so
|
|
39
|
+
* only the steps that read or change it receive it as input.
|
|
38
40
|
* `agent.system` is the last applied prompt snapshot. Before each model step,
|
|
39
41
|
* the execution layer replaces it from the current deployment's
|
|
40
42
|
* `bundle.turnAgent`.
|
|
@@ -49,7 +51,6 @@ export interface DurableSession {
|
|
|
49
51
|
*/
|
|
50
52
|
readonly rootSessionId?: string;
|
|
51
53
|
readonly continuationToken: string;
|
|
52
|
-
readonly history: HarnessModelMessage[];
|
|
53
54
|
readonly limits?: HarnessSession["limits"];
|
|
54
55
|
readonly outputSchema?: JsonObject;
|
|
55
56
|
readonly state?: SessionStateMap;
|
|
@@ -73,8 +74,13 @@ export declare function readDurableSession(state: DurableSessionState): DurableS
|
|
|
73
74
|
* snapshot embedded in the Workflow step result.
|
|
74
75
|
*/
|
|
75
76
|
export declare function createDurableSessionState(input: {
|
|
76
|
-
readonly session:
|
|
77
|
+
readonly session: HarnessSessionBase;
|
|
77
78
|
}): DurableSessionState;
|
|
79
|
+
/** The session state and history a step that ran with the history leaves. */
|
|
80
|
+
export declare function createDurableSessionValues(session: HarnessSession): {
|
|
81
|
+
readonly history: HarnessModelMessage[];
|
|
82
|
+
readonly sessionState: DurableSessionState;
|
|
83
|
+
};
|
|
78
84
|
/** Replaces session program memory and refreshes its workflow projections. */
|
|
79
85
|
export declare function replaceDurableSessionSnapshot(input: {
|
|
80
86
|
readonly session: DurableSession;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getHarnessEmissionState}from"#harness/emission.js";import{projectToDurableSession}from"#execution/session.js";import{hasProxyInputRequests}from"#harness/proxy-input-requests.js";const DURABLE_SESSION_VERSION=
|
|
1
|
+
import{getHarnessEmissionState}from"#harness/emission.js";import{projectToDurableSession}from"#execution/session.js";import{hasProxyInputRequests}from"#harness/proxy-input-requests.js";const DURABLE_SESSION_VERSION=2;function readDurableSession(e){if(e.version!==2||e.snapshot?.session===void 0)throw Error(`Unsupported session checkpoint. Start a new session on this deployment.`);return e.snapshot.session}function createDurableSessionState(e){return projectDurableSessionState(projectToDurableSession(e.session))}function createDurableSessionValues(e){return{history:e.history,sessionState:createDurableSessionState({session:e})}}function replaceDurableSessionSnapshot(e){return{...e.state,...projectDurableSessionState(e.session)}}function projectDurableSessionState(e){return{continuationToken:e.continuationToken,emissionState:getHarnessEmissionState(e.state),hasProxyInputRequests:hasProxyInputRequests(e.state),sessionId:e.sessionId,version:2,snapshot:{session:e}}}export{DURABLE_SESSION_VERSION,createDurableSessionState,createDurableSessionValues,readDurableSession,replaceDurableSessionSnapshot};
|
|
@@ -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.70.0//runWorkflowProgramTask`;export{runWorkflowProgramTask};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { DurableSessionState } from "#execution/durable-session-store.js";
|
|
2
|
+
import type { HarnessModelMessage } from "#harness/messages.js";
|
|
2
3
|
import type { WorkflowEntryResult } from "#execution/session/entry-input.js";
|
|
3
4
|
/** The old driver owns final notifications for the dispatch that became this session. */
|
|
4
5
|
export declare function completeLegacyDriverStep(input: {
|
|
5
6
|
readonly completionToken: string;
|
|
7
|
+
readonly history: HarnessModelMessage[];
|
|
6
8
|
readonly result: WorkflowEntryResult;
|
|
7
9
|
readonly serializedContext: Record<string, unknown>;
|
|
8
10
|
readonly sessionState: DurableSessionState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HookNotFoundError}from"#compiled/@workflow/errors/index.js";import{resumeHook}from"#internal/workflow/runtime.js";async function completeLegacyDriverStep(e){"use step";let t=e.sessionWritable.getWriter();try{await t.close()}finally{t.releaseLock()}try{await resumeHook(e.completionToken,{kind:`turn-result`,action:{kind:`done`,...e.result,serializedContext:e.serializedContext,sessionState:{...e.sessionState,snapshot:{version:1,session:e.sessionState.snapshot.session}}}})}catch(e){if(!HookNotFoundError.is(e))throw e}}export{completeLegacyDriverStep};
|
|
1
|
+
import{HookNotFoundError}from"#compiled/@workflow/errors/index.js";import{resumeHook}from"#internal/workflow/runtime.js";async function completeLegacyDriverStep(e){"use step";let t=e.sessionWritable.getWriter();try{await t.close()}finally{t.releaseLock()}try{await resumeHook(e.completionToken,{kind:`turn-result`,action:{kind:`done`,...e.result,serializedContext:e.serializedContext,sessionState:{...e.sessionState,snapshot:{version:1,session:{...e.sessionState.snapshot.session,history:e.history}}}}})}catch(e){if(!HookNotFoundError.is(e))throw e}}export{completeLegacyDriverStep};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger,logError}from"#internal/logging.js";import{isObject}from"#shared/guards.js";import{walkCauseChain}from"#shared/errors.js";import{EntityConflictError,RunExpiredError,WorkflowRunNotFoundError}from"#compiled/@workflow/errors/index.js";import{cancelRun,getWorld}from"#internal/workflow/runtime.js";import{terminateChildSessionsStep}from"#execution/terminate-child-sessions-step.js";import{settleCancelledTurn}from"#execution/settle-cancelled-turn-step.js";async function interruptLegacySessionStep(e){"use step";let
|
|
1
|
+
import{createLogger,logError}from"#internal/logging.js";import{isObject}from"#shared/guards.js";import{walkCauseChain}from"#shared/errors.js";import{EntityConflictError,RunExpiredError,WorkflowRunNotFoundError}from"#compiled/@workflow/errors/index.js";import{cancelRun,getWorld}from"#internal/workflow/runtime.js";import{terminateChildSessionsStep}from"#execution/terminate-child-sessions-step.js";import{settleCancelledTurn}from"#execution/settle-cancelled-turn-step.js";async function interruptLegacySessionStep(e){"use step";let{history:t,...n}=e.originalSession,r={...e.sessionState,snapshot:{session:n}};try{await terminateChildSessionsStep({sessionState:r})}catch(e){logError(createLogger(`execution.legacy-session`),`could not cooperatively stop legacy children`,e)}let i=await getWorld(),a=e.originalSession.state,o=new Set,s=a?.[`eve.runtime.workflowToolRuns`];if(Array.isArray(s))for(let e of s)isObject(e)&&typeof e.runId==`string`&&o.add(e.runId);let c=a?.[`eve.agent.handles`];if(isObject(c)&&Array.isArray(c.handles))for(let e of c.handles)isObject(e)&&isObject(e.address)&&(e.address.kind===`agent/local`||e.address.kind===`agent/self`)&&typeof e.address.sessionId==`string`&&o.add(e.address.sessionId);let l=a?.[`eve.tasks`];if(isObject(l)&&Array.isArray(l.tasks))for(let e of l.tasks)isObject(e)&&typeof e.taskRunId==`string`&&o.add(e.taskRunId);for(let t of o)if(t&&t!==e.sessionState.sessionId)try{await cancelRun(i,t,{cancelReason:`Session upgraded`})}catch(e){if(![...walkCauseChain(e)].some(e=>EntityConflictError.is(e)||RunExpiredError.is(e)||WorkflowRunNotFoundError.is(e)))throw e}return e.input.inputCommitted||e.sessionState.emissionState.turnId===``?{history:e.history,sessionState:e.sessionState,serializedContext:e.serializedContext}:await settleCancelledTurn({history:e.history,reportUsage:!1,sessionWritable:e.input.sessionWritable,serializedContext:e.serializedContext,sessionState:e.sessionState})}export{interruptLegacySessionStep};
|
|
@@ -13,6 +13,7 @@ export declare function prepareLegacySessionStep(rawInput: unknown): Promise<{
|
|
|
13
13
|
inputCommitted: boolean;
|
|
14
14
|
retention: "default" | 0 | undefined;
|
|
15
15
|
};
|
|
16
|
+
history: import("../../harness/messages.ts").HarnessModelMessage[];
|
|
16
17
|
originalSession: import("./snapshot.js").LegacySession;
|
|
17
18
|
sessionState: import("../durable-session-store.ts").DurableSessionState;
|
|
18
19
|
serializedContext: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readLegacyTurnInput}from"./input.js";import{importConversation,readLegacySnapshot}from"./snapshot.js";import{isObject}from"#shared/guards.js";import{SESSION_INBOX_CONTEXT_KEY}from"#execution/session-inbox/address.js";import{getWorld,resolveRunEncryptionKey}from"#internal/workflow/runtime.js";import{hydrateWorkflowArguments}from"#compiled/@workflow/core/serialization.js";import{DEFAULT_SESSION_TIMEOUT_MS}from"#execution/session/timeout.js";async function prepareLegacySessionStep(e){"use step";let t=readLegacyTurnInput(e),n=readLegacySnapshot(t.sessionState),r=importConversation(n),
|
|
1
|
+
import{readLegacyTurnInput}from"./input.js";import{importConversation,readLegacySnapshot}from"./snapshot.js";import{isObject}from"#shared/guards.js";import{SESSION_INBOX_CONTEXT_KEY}from"#execution/session-inbox/address.js";import{getWorld,resolveRunEncryptionKey}from"#internal/workflow/runtime.js";import{hydrateWorkflowArguments}from"#compiled/@workflow/core/serialization.js";import{DEFAULT_SESSION_TIMEOUT_MS}from"#execution/session/timeout.js";async function prepareLegacySessionStep(e){"use step";let t=readLegacyTurnInput(e),n=readLegacySnapshot(t.sessionState),{history:r,sessionState:i}=importConversation(n),a=await getWorld(),o=await a.runs.get(i.sessionId),s=await hydrateWorkflowArguments(o.input,o.runId,await resolveRunEncryptionKey(a,o)),c=Array.isArray(s)&&isObject(s[0])?s[0]:void 0;if(c===void 0)throw Error(`Cannot read the original session timeout.`);let l=c.sessionTimeoutMs;if(l!==void 0&&l!==!1&&(typeof l!=`number`||!Number.isFinite(l)||l<0))throw Error(`Invalid original session timeout.`);let u=l??DEFAULT_SESSION_TIMEOUT_MS,d={...t.serializedContext,"eve.sessionId":i.sessionId,[SESSION_INBOX_CONTEXT_KEY]:{sessionId:i.sessionId}};delete d[`eve.sessionCallback`];let f=d[`eve.channel`];return isObject(f)&&f.kind===`subagent`&&isObject(f.state)&&(d[`eve.channel`]={...f,state:{...f.state,parentContinuationToken:``}}),{input:{...t,retention:t.retention??c.retention},history:r,originalSession:n,sessionState:i,serializedContext:d,sessionTimeoutMs:u,deploymentId:process.env.VERCEL_DEPLOYMENT_ID?.trim()||await a.getDeploymentId()}}export{prepareLegacySessionStep};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ModelMessage } from "ai";
|
|
2
|
-
import type
|
|
3
|
-
|
|
2
|
+
import { type DurableSession, type DurableSessionState } from "#execution/durable-session-store.js";
|
|
3
|
+
import type { HarnessModelMessage } from "#harness/messages.js";
|
|
4
|
+
export type LegacySession = DurableSession & {
|
|
4
5
|
readonly history: ModelMessage[];
|
|
5
6
|
};
|
|
6
7
|
/** Reads the driver's embedded snapshot; every supported driver carries one. */
|
|
@@ -8,5 +9,8 @@ export declare function readLegacySnapshot(state: Record<string, unknown> & {
|
|
|
8
9
|
sessionId: string;
|
|
9
10
|
}): LegacySession;
|
|
10
11
|
/** Keep committed conversation data, but no pre-cutover execution registries. */
|
|
11
|
-
export declare function importConversation(session: LegacySession):
|
|
12
|
-
|
|
12
|
+
export declare function importConversation(session: LegacySession): {
|
|
13
|
+
readonly history: HarnessModelMessage[];
|
|
14
|
+
readonly sessionState: DurableSessionState;
|
|
15
|
+
};
|
|
16
|
+
export declare function normalizeHistory(messages: readonly ModelMessage[]): HarnessModelMessage[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject}from"#shared/guards.js";import{isUserMessageKind,validateHarnessModelMessages}from"#harness/messages.js";import{getHarnessEmissionState}from"#harness/emission.js";const PRESERVED_FRAMEWORK_STATE=new Set([`eve.harness.emission`,`eve.harness.turnUsage`,`eve.harness.reportedSessionUsage`,`eve.harness.sessionRuntimeTokenLimit`]);function readLegacySnapshot(e){let t=e.snapshot;if(!isObject(t)||t.version!==1||!isObject(t.session)||t.session.sessionId!==e.sessionId||!Array.isArray(t.session.history))throw Error(`Unsupported legacy session snapshot.`);return t.session}function importConversation(e){let
|
|
1
|
+
import{isObject}from"#shared/guards.js";import{isUserMessageKind,validateHarnessModelMessages}from"#harness/messages.js";import{getHarnessEmissionState}from"#harness/emission.js";import{DURABLE_SESSION_VERSION}from"#execution/durable-session-store.js";const PRESERVED_FRAMEWORK_STATE=new Set([`eve.harness.emission`,`eve.harness.turnUsage`,`eve.harness.reportedSessionUsage`,`eve.harness.sessionRuntimeTokenLimit`]);function readLegacySnapshot(e){let t=e.snapshot;if(!isObject(t)||t.version!==1||!isObject(t.session)||t.session.sessionId!==e.sessionId||!Array.isArray(t.session.history))throw Error(`Unsupported legacy session snapshot.`);return t.session}function importConversation(e){let{history:t,...n}=e,r=Object.fromEntries(Object.entries(e.state??{}).filter(([e])=>!e.startsWith(`eve.`)||PRESERVED_FRAMEWORK_STATE.has(e)));return{history:normalizeHistory(t),sessionState:{version:DURABLE_SESSION_VERSION,sessionId:e.sessionId,continuationToken:e.continuationToken,hasProxyInputRequests:!1,emissionState:getHarnessEmissionState(r),snapshot:{session:{...n,state:r}}}}}function normalizeHistory(e){let t=[],n=new Map,settle=()=>{n.size!==0&&(t.push({role:`tool`,content:[...n].map(([e,t])=>({type:`tool-result`,toolCallId:e,toolName:t,output:{type:`error-text`,value:`Interrupted by the session upgrade. Start this work again if it is still needed.`}}))}),n.clear())};for(let r of e){let e=r;if(e.role===`assistant`&&Array.isArray(e.content))e={...e,content:e.content.filter(e=>e.type!==`tool-approval-request`)};else if(e.role===`tool`&&(e={...e,content:e.content.filter(e=>e.type!==`tool-approval-response`)},e.content.length===0))continue;if(e.role!==`tool`&&settle(),e.role===`assistant`&&Array.isArray(e.content))for(let t of e.content)t.type===`tool-call`&&n.set(t.toolCallId,t.toolName);if(e.role===`tool`)for(let t of e.content)t.type===`tool-result`&&n.delete(t.toolCallId);let i=e.kind;t.push(e.role===`user`&&!isUserMessageKind(i)?{...e,kind:`user`}:e)}return settle(),validateHarnessModelMessages(t)}export{importConversation,normalizeHistory,readLegacySnapshot};
|
|
@@ -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{sessionTimeoutDeadline}from"#execution/session/timeout.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";async function turnWorkflow(e){"use workflow";let t=await prepareLegacySessionStep(e),{sessionId:n}=t.sessionState,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})}await runPreparedSession({anchor:{kind:`self`,notify:e=>completeLegacyDriverStep({completionToken:t.input.completionToken,result:e,serializedContext:t.serializedContext,sessionState:t.sessionState,sessionWritable:i})},caller:void 0,capabilities:t.input.capabilities,deploymentId:t.deploymentId,initialInput:t.input.delivery===void 0?void 0:{...t.input.delivery,caller:void 0},awaitFirstMessage:!1,retention:t.input.retention,serializedContext:a.serializedContext,sessionId:n,sessionState:a.sessionState,sessionTimeoutMs:t.sessionTimeoutMs,sessionTimeoutDeadline:sessionTimeoutDeadline(t.sessionTimeoutMs,Date.now()),sessionWritable:i},r)}turnWorkflow.workflowId=`workflow//eve//turnWorkflow`;export{turnWorkflow};
|
|
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{sessionTimeoutDeadline}from"#execution/session/timeout.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";async function turnWorkflow(e){"use workflow";let t=await prepareLegacySessionStep(e),{sessionId:n}=t.sessionState,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})}await runPreparedSession({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,initialInput:t.input.delivery===void 0?void 0:{...t.input.delivery,caller:void 0},awaitFirstMessage:!1,retention:t.input.retention,serializedContext:a.serializedContext,sessionId:n,sessionState:a.sessionState,sessionTimeoutMs:t.sessionTimeoutMs,sessionTimeoutDeadline:sessionTimeoutDeadline(t.sessionTimeoutMs,Date.now()),sessionWritable:i},r)}turnWorkflow.workflowId=`workflow//eve//turnWorkflow`;export{turnWorkflow};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createInputResolvedEvent}from"#protocol/message.js";import{BundleKey}from"#runtime/sessions/runtime-context-keys.js";import{resolveRemoteAgentStreamHeaders,respondToRemoteAgentSession}from"#execution/agent-sessions/remote.js";import{readDurableSession,replaceDurableSessionSnapshot}from"#execution/durable-session-store.js";import{deserializeContext}from"#context/serialize.js";import{resumeSessionInbox}from"#execution/session-inbox/resume.js";import{relaySessionEvents}from"#execution/publish-session-events.js";import{withSessionStateDelta}from"#execution/session/state-delta.js";import{retireProxyInputRequests}from"#harness/proxy-input-requests.js";import{coalesceDeliverPayloads}from"#execution/deliver-payloads.js";import{hasDelegatedSessionContext}from"#execution/delegated-session-context.js";import{routeDeliverPayload}from"#subagents/hitl-proxy.js";import{sendWorkflowAskAnswers,toToolInputResponseResponder}from"#execution/tools/workflow/answer.js";async function routeProxiedDeliverStep(e){"use step";return await withSessionStateDelta(e,routeProxiedDeliver)}async function routeProxiedDeliver(e){let
|
|
1
|
+
import{AuthKey}from"#context/keys.js";import{createInputResolvedEvent}from"#protocol/message.js";import{BundleKey,ChannelKey}from"#runtime/sessions/runtime-context-keys.js";import{resolveRemoteAgentStreamHeaders,respondToRemoteAgentSession}from"#execution/agent-sessions/remote.js";import{readDurableSession,replaceDurableSessionSnapshot}from"#execution/durable-session-store.js";import{deserializeContext,serializeContext}from"#context/serialize.js";import{resumeSessionInbox}from"#execution/session-inbox/resume.js";import{buildAdapterContext}from"#channel/adapter-context.js";import{relaySessionEvents}from"#execution/publish-session-events.js";import{withSessionStateDelta}from"#execution/session/state-delta.js";import{getProxyInputRequests,retireProxyInputRequests}from"#harness/proxy-input-requests.js";import{coalesceDeliverPayloads}from"#execution/deliver-payloads.js";import{hasDelegatedSessionContext}from"#execution/delegated-session-context.js";import{setChannelContext}from"#execution/channel-context.js";import{routeDeliverPayload}from"#subagents/hitl-proxy.js";import{sendWorkflowAskAnswers,toToolInputResponseResponder}from"#execution/tools/workflow/answer.js";async function routeProxiedDeliverStep(e){"use step";return await withSessionStateDelta(e,routeProxiedDeliver)}async function routeProxiedDeliver(e){let{delivery:t,serializedContext:n}=await deliverChannelInputResponses(e),r=readDurableSession(e.sessionState),i=new Map,a=new Map,o,s=!hasDelegatedSessionContext(n)&&t.caller===void 0,c=new Set;for(let[e,n]of t.payloads.entries()){let l=routeDeliverPayload({allowRoute:e=>!c.has(e),payload:n,resolveMessage:s,state:r.state});o??=l.parentAction,l.forSelf!==void 0&&i.set(e,l.forSelf);for(let[n,r]of l.forChildren.entries()){if(r.workflowAsk!==void 0)for(let{requestId:e}of r.resolved.resolutions)c.add(e);let i=JSON.stringify([r.childContinuationToken,r.childSessionInbox?.sessionId??``,r.remote?.sessionId??``,r.resolved.event.sequence,r.resolved.event.stepIndex,r.resolved.event.turnId,r.inputSource??null]),o=a.get(i)??{workflowAsk:r.workflowAsk,remote:r.remote,childContinuationToken:r.childContinuationToken,childSessionInbox:r.childSessionInbox,event:r.resolved.event,metadata:[],payloads:[],resolutions:new Map},s=o.payloads.length;o.payloads.push(r.payload);for(let e of r.resolved.resolutions)o.resolutions.has(e.requestId)||o.resolutions.set(e.requestId,e);if(l.forSelf===void 0&&n===0)for(let n of t.deliveryMetadata??[])n.payloadIndex===e&&o.metadata.push({...n,payloadIndex:s});a.set(i,o)}}let l=!1,u=[];for(let e of a.values()){if(e.workflowAsk!==void 0){let n=coalesceDeliverPayloads(e.payloads).inputResponses??[];await sendWorkflowAskAnswers(e.workflowAsk,n,toToolInputResponseResponder(t.auth))}else{let r={...t,deliveryMetadata:e.metadata.length===0?void 0:e.metadata,payloads:e.payloads},i=e.remote;if(i!==void 0){let r=await deserializeContext(n),a=await resolveRemoteAgentStreamHeaders({bundle:r.require(BundleKey),name:i.name,resolverId:i.resolverId,url:i.url});await respondToRemoteAgentSession({remote:i,headers:a,auth:t.auth,responses:coalesceDeliverPayloads(e.payloads).inputResponses??[]})}else await resumeSessionInbox(e.childSessionInbox??e.childContinuationToken,r)}e.resolutions.size>0&&u.push(createInputResolvedEvent({resolutions:[...e.resolutions.values()],...e.event})),r=retireProxyInputRequests(r,[...e.resolutions.keys()]),l=!0}let d=await relaySessionEvents({serializedContext:n,sessionState:l?replaceDurableSessionSnapshot({session:r,state:e.sessionState}):e.sessionState,sessionWritable:e.sessionWritable},u);if(o!==void 0)return{...d,...o};let f=[...i].sort(([e],[t])=>e-t),p=f.flatMap(([e],n)=>(t.deliveryMetadata??[]).filter(t=>t.payloadIndex===e).map(e=>({...e,payloadIndex:n}))),m=f.length===0?void 0:{...t,deliveryMetadata:p.length===0?void 0:p,payloads:f.map(([,e])=>e)};return{...d,kind:`continue`,remainder:m}}async function deliverChannelInputResponses(e){let t=getProxyInputRequests(readDurableSession(e.sessionState).state),routable=e=>t.has(e.requestId);if(!e.delivery.payloads.some(e=>e.inputResponses?.some(e=>!routable(e))===!0))return e;let n=await deserializeContext(e.serializedContext),r=n.require(ChannelKey);if(r.deliver===void 0)return e;e.delivery.auth!==void 0&&n.set(AuthKey,e.delivery.auth??null);let i=buildAdapterContext(r,n),a=!1,o=[];for(let t of e.delivery.payloads){if(t.inputResponses===void 0){o.push(t);continue}let e=[];for(let n of t.inputResponses){if(routable(n)){e.push(n);continue}let o=(await r.deliver({...t,inputResponses:[n],message:void 0},i))?.inputResponses?.filter(routable)??[];a||=o.length>0,e.push(...o.length>0?o:[n])}o.push({...t,inputResponses:e})}if(!a)return e;let s=await deserializeContext(e.serializedContext);return setChannelContext(s,{...r,state:{...i.state}}),{delivery:{...e.delivery,payloads:o},serializedContext:serializeContext(s)}}export{routeProxiedDeliverStep};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ChannelAdapterContext } from "#channel/adapter.js";
|
|
2
2
|
import { type ContextContainer } from "#context/container.js";
|
|
3
3
|
import { type DurableSession, type DurableSessionState } from "#execution/durable-session-store.js";
|
|
4
|
-
import
|
|
4
|
+
import { type HarnessModelMessage } from "#harness/messages.js";
|
|
5
|
+
import type { HandleEventFn, HarnessSession, HarnessSessionBase } from "#harness/types.js";
|
|
5
6
|
import { type MessageStreamEvent, type UnstampedMessageStreamEvent } from "#protocol/message.js";
|
|
6
7
|
/**
|
|
7
8
|
* Whose event a session publishes. Every event reaches the channel adapter, the
|
|
@@ -22,6 +23,10 @@ export interface SessionStepState {
|
|
|
22
23
|
readonly sessionState: DurableSessionState;
|
|
23
24
|
readonly sessionWritable: WritableStream<Uint8Array>;
|
|
24
25
|
}
|
|
26
|
+
/** A {@link SessionStepState} with the conversation history, for a step that reads or changes it. */
|
|
27
|
+
export interface SessionHistoryStepState extends SessionStepState {
|
|
28
|
+
readonly history: HarnessModelMessage[];
|
|
29
|
+
}
|
|
25
30
|
/** The context and session state a publication leaves behind. */
|
|
26
31
|
export interface PublishedSessionEvents {
|
|
27
32
|
readonly serializedContext: Record<string, unknown>;
|
|
@@ -41,29 +46,44 @@ export interface RestoredSessionStep {
|
|
|
41
46
|
readonly durableSession: DurableSession;
|
|
42
47
|
readonly sessionWritable: WritableStream<Uint8Array>;
|
|
43
48
|
}
|
|
49
|
+
/** A {@link RestoredSessionStep} with the history, so its publication sees a whole session. */
|
|
50
|
+
export interface RestoredSessionHistoryStep extends RestoredSessionStep {
|
|
51
|
+
readonly history: HarnessModelMessage[];
|
|
52
|
+
}
|
|
44
53
|
export declare function restoreSessionStep(step: SessionStepState): Promise<RestoredSessionStep>;
|
|
45
|
-
/**
|
|
46
|
-
|
|
54
|
+
/**
|
|
55
|
+
* What a session step publishes, and how it changes the session the
|
|
56
|
+
* publication leaves. `S` is a {@link HarnessSession} only for a step
|
|
57
|
+
* restored with its history.
|
|
58
|
+
*/
|
|
59
|
+
export interface SessionStepPublication<T, R, S extends HarnessSessionBase = HarnessSessionBase> {
|
|
47
60
|
readonly origin: SessionEventOrigin;
|
|
48
61
|
/** Where a relayed input batch came from; the channel adapter and its forwarding see it. */
|
|
49
62
|
readonly inputSource?: string;
|
|
50
63
|
/** Emits the step's events in the session's context scope. */
|
|
51
|
-
publish(emit: HandleEventFn, session:
|
|
64
|
+
publish(emit: HandleEventFn, session: S): Promise<T>;
|
|
52
65
|
/**
|
|
53
66
|
* Changes the step makes to the session once the scope has committed it,
|
|
54
67
|
* before its continuation token is reconciled.
|
|
55
68
|
*/
|
|
56
|
-
updateSession?(session:
|
|
69
|
+
updateSession?(session: S, published: T): SessionUpdate<R, S>;
|
|
57
70
|
}
|
|
58
71
|
/** The session a step keeps, and anything it derived while changing it. */
|
|
59
|
-
export interface SessionUpdate<R> {
|
|
60
|
-
readonly session:
|
|
72
|
+
export interface SessionUpdate<R, S extends HarnessSessionBase = HarnessSessionBase> {
|
|
73
|
+
readonly session: S;
|
|
61
74
|
readonly result?: R;
|
|
62
75
|
}
|
|
63
76
|
/**
|
|
64
77
|
* Publishes from a step that owns the session. Returns the context and session
|
|
65
78
|
* state to adopt, and the result of `updateSession`. `step.ctx` is updated in place.
|
|
79
|
+
* The history is published and returned only when the step was restored with it.
|
|
66
80
|
*/
|
|
81
|
+
export declare function publishFromSessionStep<T, R = undefined>(step: RestoredSessionHistoryStep, publication: SessionStepPublication<T, R, HarnessSession>): Promise<{
|
|
82
|
+
readonly published: PublishedSessionEvents & {
|
|
83
|
+
readonly history: HarnessModelMessage[];
|
|
84
|
+
};
|
|
85
|
+
readonly result: R | undefined;
|
|
86
|
+
}>;
|
|
67
87
|
export declare function publishFromSessionStep<T, R = undefined>(step: RestoredSessionStep, publication: SessionStepPublication<T, R>): Promise<{
|
|
68
88
|
readonly published: PublishedSessionEvents;
|
|
69
89
|
readonly result: R | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger}from"#internal/logging.js";import{callAdapterEventHandler}from"#channel/adapter.js";import{contextStorage}from"#context/container.js";import{ParentSessionKey,TurnDeliveryIdsKey}from"#context/keys.js";import{encodeMessageStreamEvent,stampMessageStreamEvent}from"#protocol/message.js";import{BundleKey,ChannelKey}from"#runtime/sessions/runtime-context-keys.js";import{getHarnessEmissionState}from"#harness/emission.js";import{createDurableSessionState,readDurableSession}from"#execution/durable-session-store.js";import{deserializeContext,serializeContext}from"#context/serialize.js";import{buildAdapterContext}from"#channel/adapter-context.js";import{activeTurnId}from"#harness/active-turn-id.js";import{hydrateDurableSession}from"#execution/session.js";import{resolveEffectiveAgentRuntime}from"#execution/effective-agent-config.js";import{
|
|
1
|
+
import{createLogger}from"#internal/logging.js";import{callAdapterEventHandler}from"#channel/adapter.js";import{contextStorage}from"#context/container.js";import{ParentSessionKey,TurnDeliveryIdsKey}from"#context/keys.js";import{encodeMessageStreamEvent,stampMessageStreamEvent}from"#protocol/message.js";import{BundleKey,ChannelKey}from"#runtime/sessions/runtime-context-keys.js";import{validateHarnessModelMessages}from"#harness/messages.js";import{getHarnessEmissionState}from"#harness/emission.js";import{createDurableSessionState,readDurableSession}from"#execution/durable-session-store.js";import{deserializeContext,serializeContext}from"#context/serialize.js";import{buildAdapterContext}from"#channel/adapter-context.js";import{activeTurnId}from"#harness/active-turn-id.js";import{hydrateDurableSession}from"#execution/session.js";import{resolveEffectiveAgentRuntime}from"#execution/effective-agent-config.js";import{setChannelContext}from"#execution/channel-context.js";import{dispatchStreamEventHooks}from"#context/hook-lifecycle.js";import{withContextScope}from"#context/run-step.js";import{forwardSessionInput}from"#execution/forward-session-input.js";import{reconcileSessionContinuationToken}from"#execution/reconcile-session-continuation-token.js";import{bindSessionInstrumentation}from"#instrumentation/runtime.js";const log=createLogger(`execution.publish-session-events`);async function publishSessionEvents(e,t){return await publishEventsFromStep(e,`own`,t)}async function relaySessionEvents(e,t){return await publishEventsFromStep(e,`relayed`,t)}async function publishEventsFromStep(e,t,n){if(n.length===0)return{serializedContext:e.serializedContext,sessionState:e.sessionState};let{published:r}=await publishFromSessionStep(await restoreSessionStep(e),{origin:t,async publish(e){for(let t of n)await e(t)}});return r}async function restoreSessionStep(e){return{ctx:await deserializeContext(e.serializedContext),durableSession:readDurableSession(e.sessionState),sessionWritable:e.sessionWritable}}async function publishFromSessionStep(e,t){let{ctx:n}=e,r=await publishInSessionScope(e,t),i=t.updateSession?.(r.session,r.result)??{session:r.session},a=reconcileSessionContinuationToken(n,i.session);return{published:{serializedContext:serializeContext(n),sessionState:createDurableSessionState({session:a}),...`history`in a&&{history:a.history}},result:i.result}}async function publishInSessionScope(e,t){let{ctx:n}=e,r=resolveEffectiveAgentRuntime(n.require(BundleKey),n),i=hydrateDurableSession({compactionOverrides:{thresholdPercent:r.thresholdPercent},durable:e.durableSession,turnAgent:r.turnAgent}),a=e.history===void 0?i:{...i,history:validateHarnessModelMessages(e.history)},o=t.origin===`own`?bindSessionInstrumentation({agentName:r.turnAgent.id,ctx:n,rootSessionId:a.rootSessionId??a.sessionId,sessionId:a.sessionId}):void 0,s=openSessionEventPublisher({ctx:n,inputSource:t.inputSource,origin:t.origin,sessionWritable:e.sessionWritable});try{return await withContextScope(n,a,async n=>{let r=o?.createHandleEvent({handleEvent:s.publish,turnId:activeTurnId(getHarnessEmissionState(e.durableSession.state))})??s.publish;return{result:await t.publish(r,n),session:n}})}finally{await o?.flush(),s.writer.release()}}function openSessionEventPublisher(e){let{ctx:t,origin:n}=e,r=createSessionEventDispatcher(e),i=openSessionEventWriter({deliveryIds:()=>n===`own`?t.get(TurnDeliveryIdsKey):void 0,sessionWritable:e.sessionWritable}),emit=async e=>await i.write(await r.deliver(e));return{dispatcher:r,writer:i,emit,async publish(e){await r.runHooks(await emit(e))}}}function createSessionEventDispatcher(e){let{ctx:t,inputSource:n}=e,r=t.require(ChannelKey),i=buildAdapterContext(r,t);return{adapterCtx:i,async deliver(e){let a=await forwardSessionInput(t,e,n)?e:await callAdapterEventHandler(r,e,n===void 0?i:{...i,inputSource:n});return setChannelContext(t,{...r,state:{...i.state}}),a},async runHooks(e,n){await dispatchStreamEventHooks({cancelTurn:n,ctx:t,event:e,registry:t.require(BundleKey).hookRegistry})}}}function openSessionEventWriter(e){let t=e.sessionWritable.getWriter(),n=!1,release=()=>{n||(n=!0,t.releaseLock())};return{async write(n){let r=stampMessageStreamEvent(n,e.deliveryIds());return await t.write(encodeMessageStreamEvent(r)),r},close:async()=>{await t.close(),release()},release}}async function publishTerminalSessionEvent(e){let t=e.serializedContext[`eve.sessionId`]??``,n={errorId:e.errorId,sessionId:t},{type:r}=e.event,i,a;try{i=await deserializeContext(e.serializedContext),a=openSessionEventPublisher({ctx:i,origin:`own`,sessionWritable:e.sessionWritable})}catch(t){log.error(`failed to restore context for terminal ${r} event`,{...n,error:t}),await writeUnroutedSessionEvent(e.sessionWritable,e.event).catch(e=>log.error(`failed to write terminal ${r} event`,{...n,error:e}));return}let publish=async e=>{await a.emit(e)},o;try{o=bindSessionInstrumentation({agentName:i.require(BundleKey).turnAgent.id,ctx:i,rootSessionId:i.get(ParentSessionKey)?.rootSessionId??t,sessionId:t})}catch(e){log.error(`failed to bind instrumentation for terminal ${r} event`,{...n,error:e})}let s=o?.createHandleEvent({handleEvent:publish,turnId:e.turnId})??publish;try{await contextStorage.run(i,()=>s(e.event))}catch(e){log.error(`failed to publish terminal ${r} event`,{...n,error:e})}finally{a.writer.release();try{await o?.flush()}catch(e){log.error(`failed to flush instrumentation after terminal ${r} event`,{...n,error:e})}}}async function writeUnroutedSessionEvent(e,t){let n=openSessionEventWriter({deliveryIds:()=>void 0,sessionWritable:e});try{await n.write(t)}finally{n.release()}}export{openSessionEventPublisher,publishFromSessionStep,publishSessionEvents,publishTerminalSessionEvent,relaySessionEvents,restoreSessionStep};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ContextAccessor } from "#context/key.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { HarnessSessionBase } from "#harness/types.js";
|
|
3
3
|
/** Re-stamps a session after a channel handler selects a new current continuation address. */
|
|
4
|
-
export declare function reconcileSessionContinuationToken(ctx: ContextAccessor, session:
|
|
4
|
+
export declare function reconcileSessionContinuationToken<S extends HarnessSessionBase>(ctx: ContextAccessor, session: S): S;
|
|
@@ -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,ParentSessionKey,ParentTraceContextKey,ScheduleIdKey,SessionCallbackKey,SessionTitleKey}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){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])),r.set(AuthKey,i),(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 o=contextStorage.getStore()?.get(ScheduleIdKey);return o!==void 0&&r.set(ScheduleIdKey,o),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.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{AuthKey,CapabilitiesKey,ChannelDeliveryKey,ChannelInstrumentationKey,ChannelRequestIdKey,ContinuationHookTokensKey,ContinuationTokenKey,ConversationIdKey,DynamicSubagentAgentConfigKey,InitiatorAuthKey,LegacyRemoteAgentCallerKey,ParentSessionKey,ParentTraceContextKey,ScheduleIdKey,SessionCallbackKey,SessionTitleKey,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])),r.set(AuthKey,i),(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 o=contextStorage.getStore()?.get(ScheduleIdKey);return o!==void 0&&r.set(ScheduleIdKey,o),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};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { DeliverHookPayload, TurnCaller } from "#channel/types.js";
|
|
2
|
+
import { type SteeringOptions } from "#execution/session/input-queue.js";
|
|
3
|
+
import type { SessionExecutionInput } from "#execution/session/turn.js";
|
|
4
|
+
import type { WorkflowToolRunMessage } from "#execution/tools/workflow/messages.js";
|
|
5
|
+
import type { RuntimeActionResult } from "#shared/action-types.js";
|
|
6
|
+
export type RuntimeEvent = {
|
|
7
|
+
readonly kind: "runtime-action-result";
|
|
8
|
+
readonly results: readonly RuntimeActionResult[];
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "workflow";
|
|
11
|
+
readonly message: WorkflowToolRunMessage;
|
|
12
|
+
}
|
|
13
|
+
/** A steering message that answered no pending request arrived during the wait. */
|
|
14
|
+
| {
|
|
15
|
+
readonly kind: "steering";
|
|
16
|
+
}
|
|
17
|
+
/** A `task_wait` call's timeout passed. */
|
|
18
|
+
| {
|
|
19
|
+
readonly kind: "timeout";
|
|
20
|
+
readonly callId: string;
|
|
21
|
+
}
|
|
22
|
+
/** A delivery or sign-in callback was admitted; a held request may be answered. */
|
|
23
|
+
| {
|
|
24
|
+
readonly kind: "input";
|
|
25
|
+
} | "cancelled";
|
|
26
|
+
/**
|
|
27
|
+
* Admission policy, cancellation, and steering for one active turn.
|
|
28
|
+
* Deliveries admitted while a model step runs stay in the shared queue until
|
|
29
|
+
* the turn reaches a committed boundary; a runtime-action wait routes them
|
|
30
|
+
* eagerly so a proxied child can receive the answer it is blocked on.
|
|
31
|
+
*
|
|
32
|
+
* The pump signals cancellation and eligible steering immediately. Cancellation
|
|
33
|
+
* aborts the turn; steering only interrupts generation before assistant output
|
|
34
|
+
* or local tool execution. Both retain ordered admission at the next boundary.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ActiveTurn {
|
|
37
|
+
private readonly admitted;
|
|
38
|
+
private readonly routedToChildren;
|
|
39
|
+
private readonly runtimeResults;
|
|
40
|
+
private readonly controller;
|
|
41
|
+
private readonly expectedTurnId;
|
|
42
|
+
private readonly input;
|
|
43
|
+
/** Who alone steers the turn: its principal, or its delegated caller. */
|
|
44
|
+
private readonly identity;
|
|
45
|
+
private readonly unsubscribe;
|
|
46
|
+
private unsubscribeDelivery;
|
|
47
|
+
private steeringController;
|
|
48
|
+
/** The delegated caller of the latest message the turn read. */
|
|
49
|
+
caller: TurnCaller | undefined;
|
|
50
|
+
constructor(input: SessionExecutionInput, owner: {
|
|
51
|
+
readonly caller: TurnCaller | undefined;
|
|
52
|
+
readonly principal: string;
|
|
53
|
+
});
|
|
54
|
+
private readonly signalSteering;
|
|
55
|
+
get signal(): AbortSignal;
|
|
56
|
+
dispose(): void;
|
|
57
|
+
get steeringSignal(): AbortSignal;
|
|
58
|
+
private resetSteering;
|
|
59
|
+
/** Admits everything the pump accepted while the last step ran. */
|
|
60
|
+
admitBoundary(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Steering admitted during this turn, routed to children first and coalesced.
|
|
63
|
+
* The next step reads it as input, so its signal must not interrupt that
|
|
64
|
+
* step; only deliveries still unread re-signal the next generation.
|
|
65
|
+
*/
|
|
66
|
+
takeSteering(options?: SteeringOptions): Promise<DeliverHookPayload | undefined>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the admitted run messages the session applies at once instead of
|
|
69
|
+
* in a runtime wait, or only those of `kind`.
|
|
70
|
+
*/
|
|
71
|
+
takeBoundaryMessages(kind?: "agent-started"): WorkflowToolRunMessage[];
|
|
72
|
+
/**
|
|
73
|
+
* Next runtime result, workflow message, steering, or timeout, admitting
|
|
74
|
+
* inbox traffic while waiting. Deliveries admitted before the wait began are
|
|
75
|
+
* routed first, so a message that arrived as the calls started still steers.
|
|
76
|
+
* `timers` are durable sleeps raced against the inbox.
|
|
77
|
+
*/
|
|
78
|
+
nextRuntimeEvent(timers: readonly Promise<string>[]): Promise<RuntimeEvent>;
|
|
79
|
+
/**
|
|
80
|
+
* Takes one admitted delivery that answers a pending input request, from any
|
|
81
|
+
* responder: an approver need not be the turn's own person. Returns
|
|
82
|
+
* `undefined` when no admitted delivery answers one.
|
|
83
|
+
*/
|
|
84
|
+
takeInputResponses(requestIds: ReadonlySet<string>): DeliverHookPayload | undefined;
|
|
85
|
+
/** Resolves with the id of the call whose timer won, or `undefined` once inbox input is ready. */
|
|
86
|
+
private waitForInboxOrTimer;
|
|
87
|
+
private cancelsThisTurn;
|
|
88
|
+
/** Admits one payload; returns whether it was a delivery or sign-in callback. */
|
|
89
|
+
private admit;
|
|
90
|
+
/**
|
|
91
|
+
* During a runtime wait, descendant-bound answers cannot wait for the
|
|
92
|
+
* boundary. Returns whether a newly routed delivery still steers: it
|
|
93
|
+
* answered nothing, so its message is for the model.
|
|
94
|
+
*/
|
|
95
|
+
private routeAdmittedToChildren;
|
|
96
|
+
private abort;
|
|
97
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{coalesceDeliveries}from"#harness/messages.js";import{activeTurnId}from"#harness/active-turn-id.js";import{routeDeliverToChildren}from"#execution/route-child-delivery.js";import{admitSessionInboxPayload}from"#execution/session/admission.js";import{isSteeringMessage}from"#execution/session/input-queue.js";import{routeSelectedDelivery}from"#execution/session/route-selected-delivery.js";import{decodeSessionInboxPayload}from"#execution/session-inbox/protocol.js";import{TurnCancelledError}from"#harness/turn-cancellation.js";var ActiveTurn=class{admitted=new Set;routedToChildren=new Set;runtimeResults=[];controller=new AbortController;expectedTurnId;input;identity;unsubscribe;unsubscribeDelivery;steeringController=new AbortController;caller;constructor(e,t){this.input=e,this.caller=t.caller,this.identity={callerCallId:t.caller?.callId,principal:t.principal},this.expectedTurnId=activeTurnId(e.cursor.sessionState.emissionState),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`&&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}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`}}}takeInputResponses(e){for(let t of this.admitted){let n=this.input.queue.delivery(t);if(n!==void 0&&n.payloads.some(t=>t.inputResponses?.some(t=>e.has(t.requestId))))return this.admitted.delete(t),this.input.queue.replaceDelivery(t,void 0),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`?!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}export{ActiveTurn};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{attachClientContext,readClientContext}from"#internal/client-context.js";import{SESSION_INBOX_CONTEXT_KEY,sessionCommandHookToken}from"#execution/session-inbox/address.js";import{getWorkflowMetadata,getWritable}from"#compiled/@workflow/core/index.js";import{isHookConflictError}from"#execution/hook-ownership.js";import{DEFAULT_SESSION_TIMEOUT_MS,sessionTimeoutDeadline}from"#execution/session/timeout.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{hasDelegatedSessionContext}from"#execution/delegated-session-context.js";import{readChannelRequestId,readRootSessionId}from"#execution/eve-workflow-attributes.js";import{resolveInitialTurnCallerStep}from"#subagents/parent-notification.js";import{normalizeSerializableError}from"#execution/workflow-errors.js";import{createSessionStep}from"#execution/create-session-step.js";import{settleContinuationConflictStep}from"#execution/continuation-conflict-step.js";import{signalSessionOwnerActivationStep,validateSessionCheckpointStep}from"#execution/session/handoff-steps.js";async function workflowEntry(e){"use workflow";let t=e.kind===`initial`?await bootInitialOwner(e,getWorkflowMetadata().workflowRunId):await bootHandoffOwner(e);return t===void 0?{output:``}:{output:(await runPreparedSession(t.session,t.inbox)).output}}function stampSessionIdentity(e,t){return{...e,"eve.sessionId":t,[SESSION_INBOX_CONTEXT_KEY]:{sessionId:t}}}async function bootInitialOwner(e,t){let n=stampSessionIdentity(e.serializedContext,t),r=getWritable(),i=createSessionInbox(t),{workflowStartedAt:a}=getWorkflowMetadata(),o=e.sessionTimeoutMs??DEFAULT_SESSION_TIMEOUT_MS,s=n[`eve.continuationToken`]||``,c=n[`eve.bundle`];try{let[l,u,d]=await Promise.allSettled([createSessionStep({compiledArtifactsSource:c.source,continuationToken:s,dynamicSubagentAgentConfig:n[`eve.dynamicSubagentAgentConfig`],inheritedLimits:e.limits,nodeId:c.nodeId,outputSchema:e.input.outputSchema,rootSessionId:readRootSessionId(n),sessionId:t}),i.claimSessionHook(sessionCommandHookToken(t)),s===``?Promise.resolve():i.claimSessionHook(s)]);if(l.status===`rejected`)throw l.reason;if(u.status===`rejected`)throw u.reason;if(d.status===`rejected`){if(!isHookConflictError(d.reason))throw d.reason;e.continuationConflictCommand!==void 0&&await settleContinuationConflictStep({command:e.continuationConflictCommand,continuationToken:s}),await i.dispose();return}return{inbox:i,session:{anchor:{kind:`self`},caller:hasDelegatedSessionContext(n)?await resolveInitialTurnCallerStep({serializedContext:n}):void 0,capabilities:n[`eve.capabilities`],deploymentId:e.ownerDeploymentId,initialInput:createInitialDelivery(e,n),awaitFirstMessage:e.input.message===void 0,retention:e.retention,serializedContext:n,sessionId:t,sessionState:l.value.state,sessionTimeoutMs:o,sessionTimeoutDeadline:sessionTimeoutDeadline(o,a.getTime()),sessionWritable:r}}}catch(e){return await i.dispose(),await failSession({error:e,serializedContext:n,sessionId:t,sessionState:void 0,sessionWritable:r})}}async function bootHandoffOwner(e){let{checkpoint:t,sessionId:n}=e,r=stampSessionIdentity(t.serializedContext,n),i=createSessionInbox(n);try{let n=await validateSessionCheckpointStep({checkpoint:t});if(n.kind===`incompatible`){let t=await i.release();await signalSessionOwnerActivationStep({activation:{kind:`incompatible`,payloads:t,reason:n.reason},token:e.activationToken});return}await i.claimSessionHooks(sessionHookTokens({serializedContext:r,sessionState:t.sessionState})),await signalSessionOwnerActivationStep({activation:{kind:`active`},token:e.activationToken})}catch(t){let n=await i.release();await signalSessionOwnerActivationStep({activation:{error:normalizeSerializableError(t),kind:`failed`,payloads:n},token:e.activationToken});return}return{inbox:i,session:{anchor:{kind:`successor`},caller:e.delivery.caller,capabilities:t.capabilities,deploymentId:e.ownerDeploymentId,initialInput:e.delivery,awaitFirstMessage:!1,retention:t.retention,serializedContext:r,sessionId:n,sessionState:t.sessionState,sessionTimeoutMs:t.sessionTimeoutMs,sessionTimeoutDeadline:sessionTimeoutDeadline(t.sessionTimeoutMs,Date.now()),sessionWritable:e.sessionWritable}}}function createInitialDelivery(e,t){if(e.input.message!==void 0)return{deliveryMetadata:t[`eve.channelDelivery`]===void 0?void 0:[{...t[`eve.channelDelivery`],payloadIndex:0}],kind:`deliver`,payloads:[attachClientContext({message:e.input.message,context:e.input.context,outputSchema:e.input.outputSchema,state:e.input.state},readClientContext(e.input))],requestId:readChannelRequestId(t)}}workflowEntry.workflowId=`workflow//eve//workflowEntry`;export{workflowEntry};
|
|
1
|
+
import{attachClientContext,readClientContext}from"#internal/client-context.js";import{SESSION_INBOX_CONTEXT_KEY,sessionCommandHookToken}from"#execution/session-inbox/address.js";import{getWorkflowMetadata,getWritable}from"#compiled/@workflow/core/index.js";import{isHookConflictError}from"#execution/hook-ownership.js";import{DEFAULT_SESSION_TIMEOUT_MS,sessionTimeoutDeadline}from"#execution/session/timeout.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{hasDelegatedSessionContext}from"#execution/delegated-session-context.js";import{readChannelRequestId,readRootSessionId}from"#execution/eve-workflow-attributes.js";import{resolveInitialTurnCallerStep}from"#subagents/parent-notification.js";import{normalizeSerializableError}from"#execution/workflow-errors.js";import{createSessionStep}from"#execution/create-session-step.js";import{settleContinuationConflictStep}from"#execution/continuation-conflict-step.js";import{signalSessionOwnerActivationStep,validateSessionCheckpointStep}from"#execution/session/handoff-steps.js";async function workflowEntry(e){"use workflow";let t=e.kind===`initial`?await bootInitialOwner(e,getWorkflowMetadata().workflowRunId):await bootHandoffOwner(e);return t===void 0?{output:``}:{output:(await runPreparedSession(t.session,t.inbox)).output}}function stampSessionIdentity(e,t){return{...e,"eve.sessionId":t,[SESSION_INBOX_CONTEXT_KEY]:{sessionId:t}}}async function bootInitialOwner(e,t){let n=stampSessionIdentity(e.serializedContext,t),r=getWritable(),i=createSessionInbox(t),{workflowStartedAt:a}=getWorkflowMetadata(),o=e.sessionTimeoutMs??DEFAULT_SESSION_TIMEOUT_MS,s=n[`eve.continuationToken`]||``,c=n[`eve.bundle`];try{let[l,u,d]=await Promise.allSettled([createSessionStep({compiledArtifactsSource:c.source,continuationToken:s,dynamicSubagentAgentConfig:n[`eve.dynamicSubagentAgentConfig`],inheritedLimits:e.limits,nodeId:c.nodeId,outputSchema:e.input.outputSchema,rootSessionId:readRootSessionId(n),sessionId:t}),i.claimSessionHook(sessionCommandHookToken(t)),s===``?Promise.resolve():i.claimSessionHook(s)]);if(l.status===`rejected`)throw l.reason;if(u.status===`rejected`)throw u.reason;if(d.status===`rejected`){if(!isHookConflictError(d.reason))throw d.reason;e.continuationConflictCommand!==void 0&&await settleContinuationConflictStep({command:e.continuationConflictCommand,continuationToken:s}),await i.dispose();return}return{inbox:i,session:{anchor:{kind:`self`},caller:hasDelegatedSessionContext(n)?await resolveInitialTurnCallerStep({serializedContext:n}):void 0,capabilities:n[`eve.capabilities`],deploymentId:e.ownerDeploymentId,history:l.value.history,initialInput:createInitialDelivery(e,n),awaitFirstMessage:e.input.message===void 0,retention:e.retention,serializedContext:n,sessionId:t,sessionState:l.value.state,sessionTimeoutMs:o,sessionTimeoutDeadline:sessionTimeoutDeadline(o,a.getTime()),sessionWritable:r}}}catch(e){return await i.dispose(),await failSession({error:e,serializedContext:n,sessionId:t,sessionState:void 0,sessionWritable:r})}}async function bootHandoffOwner(e){let{checkpoint:t,sessionId:n}=e,r=stampSessionIdentity(t.serializedContext,n),i=createSessionInbox(n);try{let n=await validateSessionCheckpointStep({checkpoint:t});if(n.kind===`incompatible`){let t=await i.release();await signalSessionOwnerActivationStep({activation:{kind:`incompatible`,payloads:t,reason:n.reason},token:e.activationToken});return}await i.claimSessionHooks(sessionHookTokens({serializedContext:r,sessionState:t.sessionState})),await signalSessionOwnerActivationStep({activation:{kind:`active`},token:e.activationToken})}catch(t){let n=await i.release();await signalSessionOwnerActivationStep({activation:{error:normalizeSerializableError(t),kind:`failed`,payloads:n},token:e.activationToken});return}return{inbox:i,session:{anchor:{kind:`successor`},caller:e.delivery.caller,capabilities:t.capabilities,deploymentId:e.ownerDeploymentId,history:t.history,initialInput:e.delivery,awaitFirstMessage:!1,retention:t.retention,serializedContext:r,sessionId:n,sessionState:t.sessionState,sessionTimeoutMs:t.sessionTimeoutMs,sessionTimeoutDeadline:sessionTimeoutDeadline(t.sessionTimeoutMs,Date.now()),sessionWritable:e.sessionWritable}}}function createInitialDelivery(e,t){if(e.input.message!==void 0)return{deliveryMetadata:t[`eve.channelDelivery`]===void 0?void 0:[{...t[`eve.channelDelivery`],payloadIndex:0}],kind:`deliver`,payloads:[attachClientContext({message:e.input.message,context:e.input.context,outputSchema:e.input.outputSchema,state:e.input.state},readClientContext(e.input))],requestId:readChannelRequestId(t)}}workflowEntry.workflowId=`workflow//eve//workflowEntry`;export{workflowEntry};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getSessionUsage,takeSessionUsageDelta}from"#harness/turn-tag-state.js";import{terminateChildSessionsStep}from"#execution/terminate-child-sessions-step.js";import{notifyTurnCallerStep}from"#subagents/parent-notification.js";import{normalizeSerializableError}from"#execution/workflow-errors.js";import{emitTerminalSessionCompletionStep}from"#execution/terminal-session-completion-step.js";import{emitTerminalSessionFailureStep}from"#execution/terminal-session-failure-step.js";async function finalizeSession(e,t){let{serializedContext:n,sessionState:r}=t.cursor;r!==void 0&&await terminateChildSessionsStep({sessionState:r});let i=r?.snapshot.session,a=i===void 0?void 0:getSessionUsage(i);e.kind===`expired`?await emitTerminalSessionCompletionStep({sessionWritable:t.sessionWritable,serializedContext:n,usage:a}):e.kind===`failed`&&await emitTerminalSessionFailureStep({error:normalizeSerializableError(e.error),sessionWritable:t.sessionWritable,serializedContext:n,turnId:e.turnId,usage:a});let o=settledResult(e,t);if(t.caller!==void 0){let e={output:o.output,usage:o.turnUsage};o.isError&&(e.isError=!0),await notifyTurnCallerStep({caller:t.caller,lifecycle:`terminal`,sessionId:r?.sessionId??n[`eve.sessionId`],settled:e})}return e.kind===`done`?{isError:e.action.isError,output:e.action.output,usage:e.action.usage,usageDelta:e.action.usageDelta}:{isError:o.isError,output:o.output,usage:o.sessionUsage,usageDelta:o.turnUsage}}function settledResult(e,t){let n=t.cursor.sessionState?.snapshot.session,r=n===void 0||t.caller===void 0?{}:{sessionUsage:getSessionUsage(n),turnUsage:takeSessionUsageDelta(n).delta};switch(e.kind){case`done`:return{isError:e.action.isError===!0,output:e.action.output,sessionUsage:e.action.usage,turnUsage:e.action.usageDelta};case`expired`:return t.caller===void 0?{isError:!1,output:``}:{isError:!0,output:`The session ended before the delegated task completed.`,...r};case`failed`:return{isError:!0,output:normalizeSerializableError(e.error),...r}}}export{finalizeSession};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SessionCapabilities } from "#channel/types.js";
|
|
2
2
|
import type { DurableSessionState } from "#execution/durable-session-store.js";
|
|
3
|
+
import type { HarnessModelMessage } from "#harness/messages.js";
|
|
3
4
|
import type { SessionInboxHandle, SessionInboxPayload } from "#execution/session-inbox/inbox.js";
|
|
4
5
|
import type { TurnSelection } from "#execution/session/input-queue.js";
|
|
5
6
|
import type { WorkflowEntryResult } from "#execution/session/entry-input.js";
|
|
@@ -11,11 +12,12 @@ import type { AgentWorkflowRetentionDefinition } from "#shared/agent-definition.
|
|
|
11
12
|
* Mount-owned state requires a new version so older readers reject it rather
|
|
12
13
|
* than dropping unrecognized state keys during reverse handoff.
|
|
13
14
|
*/
|
|
14
|
-
export declare const SESSION_CHECKPOINT_VERSION =
|
|
15
|
+
export declare const SESSION_CHECKPOINT_VERSION = 11;
|
|
15
16
|
/** Everything a successor needs to continue an idle session. Hooks are derived from the state. */
|
|
16
17
|
export interface SessionCheckpoint {
|
|
17
18
|
readonly version: typeof SESSION_CHECKPOINT_VERSION;
|
|
18
19
|
readonly capabilities?: SessionCapabilities;
|
|
20
|
+
readonly history: HarnessModelMessage[];
|
|
19
21
|
readonly retention?: AgentWorkflowRetentionDefinition;
|
|
20
22
|
readonly serializedContext: Record<string, unknown>;
|
|
21
23
|
readonly sessionState: DurableSessionState;
|
|
@@ -41,7 +43,7 @@ type SessionTransferOutcome = {
|
|
|
41
43
|
readonly reason: "same-deployment" | "missing-deployment" | "not-idle" | "busy" | "accepted-during-release" | "activation-failed" | "checkpoint-incompatible" | "known-incompatible";
|
|
42
44
|
};
|
|
43
45
|
interface SessionHandoffInput {
|
|
44
|
-
readonly checkpoint: Omit<SessionCheckpoint, "serializedContext" | "sessionState" | "version">;
|
|
46
|
+
readonly checkpoint: Omit<SessionCheckpoint, "history" | "serializedContext" | "sessionState" | "version">;
|
|
45
47
|
readonly deploymentId: string;
|
|
46
48
|
readonly inbox: SessionInboxHandle;
|
|
47
49
|
readonly isInitialOwner: boolean;
|
|
@@ -70,7 +72,7 @@ export declare class SessionHandoff {
|
|
|
70
72
|
* outcome states whether the successor activated or this owner retained the
|
|
71
73
|
* session. Candidate failures recover locally rather than escaping.
|
|
72
74
|
*/
|
|
73
|
-
tryTransfer(selection: TurnSelection, state: Pick<SessionCheckpoint, "serializedContext" | "sessionState">): Promise<SessionTransferOutcome>;
|
|
75
|
+
tryTransfer(selection: TurnSelection, state: Pick<SessionCheckpoint, "history" | "serializedContext" | "sessionState">): Promise<SessionTransferOutcome>;
|
|
74
76
|
/** After a transfer, the original run parks until the final owner reports the session result. */
|
|
75
77
|
awaitAnchoredResult(): Promise<WorkflowEntryResult>;
|
|
76
78
|
disposeAnchor(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sessionHandoffMarkerToken}from"#execution/session-inbox/address.js";import{startSessionOwnerStep}from"#execution/workflow-runtime.js";import{createHook,getWorkflowMetadata}from"#compiled/@workflow/core/index.js";import{claimHookOwnership,disposeHook}from"#execution/hook-ownership.js";import{sessionHookTokens}from"#execution/session/hook-tokens.js";import{isSessionIdleForHandoffStep}from"#execution/session/handoff-steps.js";import{readAcceptedDeploymentId}from"#execution/session/accepted-deployment.js";const SESSION_CHECKPOINT_VERSION=
|
|
1
|
+
import{sessionHandoffMarkerToken}from"#execution/session-inbox/address.js";import{startSessionOwnerStep}from"#execution/workflow-runtime.js";import{createHook,getWorkflowMetadata}from"#compiled/@workflow/core/index.js";import{claimHookOwnership,disposeHook}from"#execution/hook-ownership.js";import{sessionHookTokens}from"#execution/session/hook-tokens.js";import{isSessionIdleForHandoffStep}from"#execution/session/handoff-steps.js";import{readAcceptedDeploymentId}from"#execution/session/accepted-deployment.js";const SESSION_CHECKPOINT_VERSION=11;function sessionAnchorToken(e){return`${e}:anchor`}var SessionHandoff=class{input;anchor;incompatibleTargetDeploymentIds=new Set;constructor(e){this.input=e}async tryTransfer(e,t){let{deploymentId:n,inbox:r}=this.input,i=readAcceptedDeploymentId(e.delivery);if(i===void 0)return{kind:`retained`,reason:`missing-deployment`};if(i===n)return{kind:`retained`,reason:`same-deployment`};if(this.incompatibleTargetDeploymentIds.has(i))return{kind:`retained`,reason:`known-incompatible`};if(!e.handoffEligible)return{kind:`retained`,reason:`busy`};if(!await isSessionIdleForHandoffStep({sessionState:t.sessionState}))return{kind:`retained`,reason:`not-idle`};let a={...this.input.checkpoint,...t,version:11},o=sessionHookTokens(t);await this.ensureAnchor();let s=o.map(e=>createHook({token:sessionHandoffMarkerToken(e)}));await Promise.all(s.map(e=>claimHookOwnership(e)));try{let t=await r.release();if(t.length>0)return await this.recover(o,t),{kind:`retained`,reason:`accepted-during-release`};let n=[];try{let t=await this.startAndActivate(a,e.delivery,i);if(t.kind===`active`)return{kind:`transferred`};if(t.kind===`incompatible`)return this.incompatibleTargetDeploymentIds.add(i),await this.recover(o,t.payloads),{kind:`retained`,reason:`checkpoint-incompatible`};n=t.payloads}catch{}return await this.recover(o,n),{kind:`retained`,reason:`activation-failed`}}finally{await Promise.all(s.map(e=>disposeHook(e)))}}async awaitAnchoredResult(){if(this.anchor===void 0)throw Error(`Session anchor was never claimed.`);try{return await this.anchor}finally{await this.disposeAnchor()}}async disposeAnchor(){if(this.anchor===void 0)return;let e=this.anchor;this.anchor=void 0,await disposeHook(e)}async startAndActivate(e,t,n){let r=createHook({token:`${getWorkflowMetadata().workflowRunId}:handoff`});await claimHookOwnership(r);try{return await startSessionOwnerStep({activationToken:r.token,anchorRunId:this.input.sessionId,checkpoint:e,delivery:t,targetDeploymentId:n}),await r}finally{await disposeHook(r)}}async recover(e,t){await this.input.inbox.claimSessionHooks(e),this.input.inbox.restore(t)}async ensureAnchor(){this.input.isInitialOwner&&this.anchor===void 0&&(this.anchor=createHook({token:sessionAnchorToken(this.input.sessionId)}),await claimHookOwnership(this.anchor))}};export{SESSION_CHECKPOINT_VERSION,SessionHandoff,sessionAnchorToken};
|
|
@@ -19,9 +19,6 @@ export interface TurnSelection {
|
|
|
19
19
|
export type SessionInputSelection = TurnSelection | {
|
|
20
20
|
readonly control: SessionControl;
|
|
21
21
|
readonly kind: "control";
|
|
22
|
-
} | {
|
|
23
|
-
readonly kind: "authorization-resume";
|
|
24
|
-
readonly payloads: readonly DeliverPayload[];
|
|
25
22
|
};
|
|
26
23
|
/**
|
|
27
24
|
* Ordered, admitted session input. Entries are private; callers receive typed
|
|
@@ -36,21 +33,22 @@ export declare class SessionInputQueue {
|
|
|
36
33
|
enqueueControl(control: SessionControl): void;
|
|
37
34
|
/** Keeps one payload per authorization attempt; a repeated callback for the same attempt is dropped. */
|
|
38
35
|
enqueueAuthorization(payloads: readonly DeliverPayload[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Removes and returns the queued callbacks for `attemptIds` once every one
|
|
38
|
+
* has arrived, so a turn holding several sign-ins resumes when all are done.
|
|
39
|
+
*/
|
|
40
|
+
takeAuthorizations(attemptIds: ReadonlySet<string>): DeliverPayload[] | undefined;
|
|
39
41
|
delivery(sequence: number): DeliverHookPayload | undefined;
|
|
40
42
|
replaceDelivery(sequence: number, delivery: DeliverHookPayload | undefined): void;
|
|
41
|
-
takeSteering(admitted: ReadonlySet<number>, turn: SteeringTurn): TurnSelection | undefined;
|
|
43
|
+
takeSteering(admitted: ReadonlySet<number>, turn: SteeringTurn, options?: SteeringOptions): TurnSelection | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Takes the next turn or control. Sign-ins end with the turn that raised
|
|
46
|
+
* them, so a callback still queued between turns is stale and dropped.
|
|
47
|
+
*/
|
|
42
48
|
takeNext(options?: {
|
|
43
|
-
/**
|
|
44
|
-
* Attempt ids of the open authorization challenge. Callbacks for other
|
|
45
|
-
* attempts are stale and dropped; once every expected attempt has
|
|
46
|
-
* reported, the collected payloads resume the challenge ahead of
|
|
47
|
-
* ordinary input.
|
|
48
|
-
*/
|
|
49
|
-
readonly expectedAttemptIds?: ReadonlySet<string>;
|
|
50
49
|
/** Sequence of a delivery admitted while nothing else was pending. */
|
|
51
50
|
readonly freshSequence?: number;
|
|
52
51
|
}): SessionInputSelection | undefined;
|
|
53
|
-
private takeSelectionAt;
|
|
54
52
|
/**
|
|
55
53
|
* Consecutive deliveries of one authenticated principal and one delegated
|
|
56
54
|
* call share a turn, as they would steer it. Claims may change between
|
|
@@ -65,11 +63,19 @@ export interface SteeringTurn {
|
|
|
65
63
|
readonly callerCallId: string | undefined;
|
|
66
64
|
readonly principal: string;
|
|
67
65
|
}
|
|
66
|
+
export interface SteeringOptions {
|
|
67
|
+
/**
|
|
68
|
+
* The turn waits on its own person for a sign-in or approval. Their message
|
|
69
|
+
* steers even with `turnPolicy: "queue"`: queued, it would wait for a turn
|
|
70
|
+
* that cannot end until they act.
|
|
71
|
+
*/
|
|
72
|
+
readonly heldOnPerson?: boolean;
|
|
73
|
+
}
|
|
68
74
|
/**
|
|
69
75
|
* Only the turn's own principal steers it; another principal's message waits
|
|
70
76
|
* for the turn to end. A delivery without auth acts as the session's current
|
|
71
77
|
* identity, which is the turn's.
|
|
72
78
|
*/
|
|
73
|
-
export declare function isSteeringDelivery(delivery: DeliverHookPayload, turn: SteeringTurn): boolean;
|
|
79
|
+
export declare function isSteeringDelivery(delivery: DeliverHookPayload, turn: SteeringTurn, options?: SteeringOptions): boolean;
|
|
74
80
|
/** A steering delivery with a message for the model, not only answers to requests. */
|
|
75
81
|
export declare function isSteeringMessage(delivery: DeliverHookPayload, turn: SteeringTurn): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{coalesceDeliveries}from"#harness/messages.js";import{ANONYMOUS_PRINCIPAL,principalOf}from"#execution/session/principal.js";var SessionInputQueue=class{entries=[];nextSequence=0;get pendingCount(){return this.entries.length}enqueueDelivery(e){let t={delivery:e,sequence:this.nextSequence++};return this.entries.push({...t,kind:`delivery`}),t}enqueueControl(e){this.entries.push({control:e,kind:`control`,sequence:this.nextSequence++})}enqueueAuthorization(e){for(let t of e){let e=authorizationAttemptId(t);e!==void 0&&(this.entries.some(t=>t.kind===`authorization`&&t.attemptId===e)||this.entries.push({attemptId:e,kind:`authorization`,payload:t,sequence:this.nextSequence++}))}}delivery(e){return this.entries.find(t=>t.kind===`delivery`&&t.sequence===e)?.delivery}replaceDelivery(e,t){let n=this.entries.findIndex(t=>t.kind===`delivery`&&t.sequence===e);if(!(n<0)){if(t===void 0){this.entries.splice(n,1);return}this.entries[n]={delivery:t,kind:`delivery`,sequence:e}}}takeSteering(e,t){let
|
|
1
|
+
import{coalesceDeliveries}from"#harness/messages.js";import{ANONYMOUS_PRINCIPAL,principalOf}from"#execution/session/principal.js";var SessionInputQueue=class{entries=[];nextSequence=0;get pendingCount(){return this.entries.length}enqueueDelivery(e){let t={delivery:e,sequence:this.nextSequence++};return this.entries.push({...t,kind:`delivery`}),t}enqueueControl(e){this.entries.push({control:e,kind:`control`,sequence:this.nextSequence++})}enqueueAuthorization(e){for(let t of e){let e=authorizationAttemptId(t);e!==void 0&&(this.entries.some(t=>t.kind===`authorization`&&t.attemptId===e)||this.entries.push({attemptId:e,kind:`authorization`,payload:t,sequence:this.nextSequence++}))}}takeAuthorizations(e){let t=this.entries.filter(t=>t.kind===`authorization`&&e.has(t.attemptId));if(!(t.length===0||new Set(t.map(e=>e.attemptId)).size<e.size))return this.retain(e=>!t.includes(e)),t.map(e=>e.payload)}delivery(e){return this.entries.find(t=>t.kind===`delivery`&&t.sequence===e)?.delivery}replaceDelivery(e,t){let n=this.entries.findIndex(t=>t.kind===`delivery`&&t.sequence===e);if(!(n<0)){if(t===void 0){this.entries.splice(n,1);return}this.entries[n]={delivery:t,kind:`delivery`,sequence:e}}}takeSteering(e,t,n){let r=this.entries.filter(r=>r.kind===`delivery`&&e.has(r.sequence)&&isSteeringDelivery(r.delivery,t,n));if(r.length!==0)return this.retain(e=>e.kind!==`delivery`||!r.includes(e)),{delivery:combine(r),handoffEligible:!1,kind:`turn`,sequences:r.map(({sequence:e})=>e)}}takeNext(e){this.retain(e=>e.kind!==`authorization`);let t=this.entries.shift();if(t===void 0)return;if(t.kind===`control`)return{control:t.control,kind:`control`};let n=[t,...this.takeFollowingDeliveriesFrom(t)],r=n.map(({sequence:e})=>e),i=combine(n);return{delivery:i,handoffEligible:r.length===1&&r[0]===e?.freshSequence&&i.caller===void 0&&this.entries.length===0,kind:`turn`,sequences:r}}takeFollowingDeliveriesFrom(e){let t=principalOf(e.delivery.auth),n=[],r=e.delivery.caller?.callId;for(;;){let e=this.entries[0];if(e?.kind!==`delivery`||t===ANONYMOUS_PRINCIPAL||principalOf(e.delivery.auth)!==t||r!==void 0&&e.delivery.caller!==void 0&&e.delivery.caller.callId!==r)break;n.push(e),this.entries.shift(),r??=e.delivery.caller?.callId}return n}retain(e){let t=this.entries.filter(e);this.entries.splice(0,this.entries.length,...t)}};function isSteeringDelivery(e,t,n){return(n?.heldOnPerson===!0||(e.turnPolicy??`steer`)===`steer`)&&(e.caller===void 0||e.caller.callId===t.callerCallId)&&(e.auth===void 0||principalOf(e.auth)===t.principal)}function isSteeringMessage(e,t){return isSteeringDelivery(e,t)&&e.payloads.some(e=>e.message!==void 0&&e.inputResponses===void 0)}function combine(e){return e.length===1?e[0].delivery:coalesceDeliveries(e.map(({delivery:e})=>e))}function authorizationAttemptId(e){let t=e.authorizationCallback;return typeof t?.attemptId==`string`?t.attemptId:void 0}export{SessionInputQueue,isSteeringDelivery,isSteeringMessage};
|