@bastani/atomic 0.9.19-alpha.1 → 0.9.19-alpha.11
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 +206 -0
- package/README.md +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +51 -0
- package/dist/builtin/intercom/README.md +28 -18
- package/dist/builtin/intercom/broker/broker.ts +81 -9
- package/dist/builtin/intercom/broker/client.ts +45 -1
- package/dist/builtin/intercom/broker/framing.ts +5 -2
- package/dist/builtin/intercom/broker/group-membership.ts +4 -2
- package/dist/builtin/intercom/broker/presence-handler.ts +14 -0
- package/dist/builtin/intercom/broker/send-handler.ts +61 -6
- package/dist/builtin/intercom/broker/terminal-questions.ts +29 -0
- package/dist/builtin/intercom/index.bundle.mjs +1120 -783
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/intercom/recipient-purpose.ts +9 -0
- package/dist/builtin/intercom/recoverable-disconnect.ts +2 -3
- package/dist/builtin/intercom/retry-policy.ts +4 -2
- package/dist/builtin/intercom/skills/intercom/SKILL.md +8 -7
- package/dist/builtin/intercom/types.ts +18 -3
- package/dist/builtin/mcp/CHANGELOG.md +6 -0
- package/dist/builtin/mcp/README.md +2 -0
- package/dist/builtin/mcp/index.bundle.mjs +2201 -12000
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/CHANGELOG.md +57 -0
- package/dist/builtin/subagents/README.md +46 -23
- package/dist/builtin/subagents/agents/code-simplifier.md +1 -1
- package/dist/builtin/subagents/agents/codebase-analyzer.md +1 -1
- package/dist/builtin/subagents/agents/codebase-locator.md +2 -2
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +8 -8
- package/dist/builtin/subagents/agents/codebase-pattern-finder.md +2 -2
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +1 -1
- package/dist/builtin/subagents/agents/codebase-research-locator.md +2 -2
- package/dist/builtin/subagents/agents/debugger.md +2 -2
- package/dist/builtin/subagents/agents/worker.md +1 -1
- package/dist/builtin/subagents/package.json +2 -2
- package/dist/builtin/subagents/skills/herdr/LICENSE +201 -0
- package/dist/builtin/subagents/skills/herdr/SKILL.md +202 -0
- package/dist/builtin/subagents/skills/subagent/SKILL.md +41 -35
- package/dist/builtin/subagents/skills/tmux/SKILL.md +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1414 -656
- package/dist/builtin/web-access/CHANGELOG.md +19 -0
- package/dist/builtin/web-access/README.md +31 -24
- package/dist/builtin/web-access/index.bundle.mjs +42723 -26674
- package/dist/builtin/web-access/package.json +3 -2
- package/dist/builtin/workflows/CHANGELOG.md +127 -0
- package/dist/builtin/workflows/README.md +15 -16
- package/dist/builtin/workflows/builtin/adversarial-verification.js +5 -7
- package/dist/builtin/workflows/builtin/{chunk-hqpe2cyx.js → chunk-1jth021m.js} +85 -85
- package/dist/builtin/workflows/builtin/{chunk-7430zyas.js → chunk-2377r57g.js} +5 -3
- package/dist/builtin/workflows/builtin/{chunk-79fjkcvh.js → chunk-31j2gs7h.js} +18 -18
- package/dist/builtin/workflows/builtin/{chunk-wgccch41.js → chunk-6w6cvk6b.js} +16 -16
- package/dist/builtin/workflows/builtin/{chunk-zbekjqew.js → chunk-a2kdsqn8.js} +4 -4
- package/dist/builtin/workflows/builtin/{chunk-ze5x3d1r.js → chunk-fg9esgkj.js} +7 -7
- package/dist/builtin/workflows/builtin/{chunk-n8h4yyew.js → chunk-g0csgs7w.js} +11 -11
- package/dist/builtin/workflows/builtin/{chunk-b0v2xab1.js → chunk-ngkqkzej.js} +221 -23
- package/dist/builtin/workflows/builtin/{chunk-ed4jfn5t.js → chunk-nkrafh9s.js} +61 -61
- package/dist/builtin/workflows/builtin/{chunk-reqr3sr3.js → chunk-wf741bv3.js} +22 -22
- package/dist/builtin/workflows/builtin/{chunk-42s7sw0b.js → chunk-yeee2jrc.js} +19 -19
- package/dist/builtin/workflows/builtin/{chunk-6fqs7c01.js → chunk-z0d03ktm.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-k3w87x8y.js → chunk-z29qbehr.js} +10 -10
- package/dist/builtin/workflows/builtin/classify-and-act.js +5 -6
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -4
- package/dist/builtin/workflows/builtin/generate-and-filter.js +5 -6
- package/dist/builtin/workflows/builtin/goal.js +7 -8
- package/dist/builtin/workflows/builtin/index.js +20 -22
- package/dist/builtin/workflows/builtin/loop-until-done.js +5 -6
- package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +7 -8
- package/dist/builtin/workflows/builtin/steering-context.js +3 -3
- package/dist/builtin/workflows/builtin/tournament.js +5 -7
- package/dist/builtin/workflows/package.json +6 -6
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +27782 -26348
- package/dist/builtin/workflows/src/index.js +1103 -515
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +4 -1
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +1 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +6 -5
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +5 -1
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts +1 -1
- package/dist/core/agent-session-compaction.js +1 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-custom-message-commit.d.ts +1 -1
- package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
- package/dist/core/agent-session-custom-message-commit.js +33 -2
- package/dist/core/agent-session-custom-message-commit.js.map +1 -1
- package/dist/core/agent-session-delivery-forwarding.d.ts +1 -1
- package/dist/core/agent-session-delivery-forwarding.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +5 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-export.d.ts +1 -1
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts +8 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +45 -3
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts +2 -2
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +22 -8
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +21 -8
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js +13 -3
- package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.js +1 -1
- package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts +2 -2
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +105 -18
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-queue-pause.d.ts.map +1 -1
- package/dist/core/agent-session-queue-pause.js +11 -0
- package/dist/core/agent-session-queue-pause.js.map +1 -1
- package/dist/core/agent-session-runtime-auth.d.ts +1 -1
- package/dist/core/agent-session-runtime-auth.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +13 -4
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +27 -4
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +5 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +44 -34
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +1 -1
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tasks.d.ts +14 -0
- package/dist/core/agent-session-tasks.d.ts.map +1 -0
- package/dist/core/agent-session-tasks.js +120 -0
- package/dist/core/agent-session-tasks.js.map +1 -0
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +2 -0
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts +1 -0
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +52 -5
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-transfer.d.ts.map +1 -1
- package/dist/core/agent-session-transfer.js +7 -0
- package/dist/core/agent-session-transfer.js.map +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-tree.js +3 -0
- package/dist/core/agent-session-tree.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +4 -2
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js +2 -0
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +29 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts +1 -1
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extension-session-state.js.map +1 -1
- package/dist/core/extensions/agent-events.d.ts +4 -4
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +10 -2
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +15 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/event-results.d.ts +1 -1
- package/dist/core/extensions/event-results.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts +2 -1
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/event-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +3 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-api.d.ts +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +10 -0
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/loader-core.d.ts +1 -1
- package/dist/core/extensions/loader-core.js.map +1 -1
- package/dist/core/extensions/loader-discovery.d.ts +1 -1
- package/dist/core/extensions/loader-discovery.js.map +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-host-modules.js +5 -2
- package/dist/core/extensions/loader-host-modules.js.map +1 -1
- package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
- package/dist/core/extensions/loader-runtime.js +3 -0
- package/dist/core/extensions/loader-runtime.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +6 -1
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +1 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/message-types.d.ts +1 -1
- package/dist/core/extensions/message-types.js.map +1 -1
- package/dist/core/extensions/reactive-widget.d.ts +6 -0
- package/dist/core/extensions/reactive-widget.d.ts.map +1 -1
- package/dist/core/extensions/reactive-widget.js +7 -1
- package/dist/core/extensions/reactive-widget.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +12 -2
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +49 -4
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner-events.d.ts +1 -1
- package/dist/core/extensions/runner-events.d.ts.map +1 -1
- package/dist/core/extensions/runner-events.js +17 -2
- package/dist/core/extensions/runner-events.js.map +1 -1
- package/dist/core/extensions/runner-shortcuts.d.ts.map +1 -1
- package/dist/core/extensions/runner-shortcuts.js +32 -3
- package/dist/core/extensions/runner-shortcuts.js.map +1 -1
- package/dist/core/extensions/runner-ui.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +17 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +69 -19
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +8 -1
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/tool-types.d.ts +1 -1
- package/dist/core/extensions/tool-types.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +25 -1
- package/dist/core/extensions/ui-types.d.ts.map +1 -1
- package/dist/core/extensions/ui-types.js.map +1 -1
- package/dist/core/extensions/workflow-activity-hub.d.ts +25 -0
- package/dist/core/extensions/workflow-activity-hub.d.ts.map +1 -0
- package/dist/core/extensions/workflow-activity-hub.js +183 -0
- package/dist/core/extensions/workflow-activity-hub.js.map +1 -0
- package/dist/core/extensions/workflow-events.d.ts +118 -0
- package/dist/core/extensions/workflow-events.d.ts.map +1 -0
- package/dist/core/extensions/workflow-events.js +2 -0
- package/dist/core/extensions/workflow-events.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +8 -4
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +97 -11
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybinding-identity.d.ts +4 -0
- package/dist/core/keybinding-identity.d.ts.map +1 -0
- package/dist/core/keybinding-identity.js +10 -0
- package/dist/core/keybinding-identity.js.map +1 -0
- package/dist/core/keybindings.d.ts +37 -2
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +9 -2
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/mandatory-runtime-tools.d.ts +1 -1
- package/dist/core/mandatory-runtime-tools.js.map +1 -1
- package/dist/core/model-fallback-failures.js +2 -2
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +8 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver-defaults.js +1 -1
- package/dist/core/model-resolver-defaults.js.map +1 -1
- package/dist/core/resource-loader-assets.js.map +1 -1
- package/dist/core/resource-loader-core.d.ts +1 -1
- package/dist/core/resource-loader-core.js.map +1 -1
- package/dist/core/resource-loader-internals.d.ts +2 -2
- package/dist/core/resource-loader-internals.js.map +1 -1
- package/dist/core/resource-loader-reload.d.ts +2 -0
- package/dist/core/resource-loader-reload.d.ts.map +1 -1
- package/dist/core/resource-loader-reload.js +231 -191
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/resource-loader-types.d.ts +4 -2
- package/dist/core/resource-loader-types.d.ts.map +1 -1
- package/dist/core/resource-loader-types.js.map +1 -1
- package/dist/core/retry-policy.d.ts +1 -0
- package/dist/core/retry-policy.d.ts.map +1 -1
- package/dist/core/retry-policy.js +2 -1
- package/dist/core/retry-policy.js.map +1 -1
- package/dist/core/sdk-exports.d.ts +3 -3
- package/dist/core/sdk-exports.d.ts.map +1 -1
- package/dist/core/sdk-exports.js +1 -1
- package/dist/core/sdk-exports.js.map +1 -1
- package/dist/core/sdk-types.d.ts +2 -2
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +6 -3
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +25 -8
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-manager-core.d.ts.map +1 -1
- package/dist/core/settings-manager-core.js +10 -4
- package/dist/core/settings-manager-core.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-storage.d.ts +1 -0
- package/dist/core/settings-storage.d.ts.map +1 -1
- package/dist/core/settings-storage.js +18 -0
- package/dist/core/settings-storage.js.map +1 -1
- package/dist/core/settings-types.d.ts +17 -0
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +6 -5
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +5 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/agent-adapter.d.ts +44 -0
- package/dist/core/tasks/agent-adapter.d.ts.map +1 -0
- package/dist/core/tasks/agent-adapter.js +112 -0
- package/dist/core/tasks/agent-adapter.js.map +1 -0
- package/dist/core/tasks/command-output.d.ts +15 -0
- package/dist/core/tasks/command-output.d.ts.map +1 -0
- package/dist/core/tasks/command-output.js +29 -0
- package/dist/core/tasks/command-output.js.map +1 -0
- package/dist/core/tasks/completion-ordering.d.ts +11 -0
- package/dist/core/tasks/completion-ordering.d.ts.map +1 -0
- package/dist/core/tasks/completion-ordering.js +19 -0
- package/dist/core/tasks/completion-ordering.js.map +1 -0
- package/dist/core/tasks/completion.d.ts +36 -0
- package/dist/core/tasks/completion.d.ts.map +1 -0
- package/dist/core/tasks/completion.js +119 -0
- package/dist/core/tasks/completion.js.map +1 -0
- package/dist/core/tasks/contracts.d.ts +404 -0
- package/dist/core/tasks/contracts.d.ts.map +1 -0
- package/dist/core/tasks/contracts.js +2 -0
- package/dist/core/tasks/contracts.js.map +1 -0
- package/dist/core/tasks/execution-scope.d.ts +10 -0
- package/dist/core/tasks/execution-scope.d.ts.map +1 -0
- package/dist/core/tasks/execution-scope.js +27 -0
- package/dist/core/tasks/execution-scope.js.map +1 -0
- package/dist/core/tasks/owner-store.d.ts +53 -0
- package/dist/core/tasks/owner-store.d.ts.map +1 -0
- package/dist/core/tasks/owner-store.js +155 -0
- package/dist/core/tasks/owner-store.js.map +1 -0
- package/dist/core/tasks/pause.d.ts +4 -0
- package/dist/core/tasks/pause.d.ts.map +1 -0
- package/dist/core/tasks/pause.js +49 -0
- package/dist/core/tasks/pause.js.map +1 -0
- package/dist/core/tasks/supervisor.d.ts +123 -0
- package/dist/core/tasks/supervisor.d.ts.map +1 -0
- package/dist/core/tasks/supervisor.js +942 -0
- package/dist/core/tasks/supervisor.js.map +1 -0
- package/dist/core/tasks/transcript.d.ts +23 -0
- package/dist/core/tasks/transcript.d.ts.map +1 -0
- package/dist/core/tasks/transcript.js +74 -0
- package/dist/core/tasks/transcript.js.map +1 -0
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts +2 -2
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.js +8 -4
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/tab-bar.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/tab-bar.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -1
- package/dist/core/tools/bash-pty-native.d.ts +32 -3
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -1
- package/dist/core/tools/bash-pty-native.js +198 -1
- package/dist/core/tools/bash-pty-native.js.map +1 -1
- package/dist/core/tools/bash.d.ts +25 -5
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +100 -10
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +92 -14
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-coordinator.d.ts +255 -0
- package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-coordinator.js +300 -0
- package/dist/core/tools/file-mutation-coordinator.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +14 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +15 -3
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/hashline.d.ts +9 -0
- package/dist/core/tools/hashline.d.ts.map +1 -1
- package/dist/core/tools/hashline.js +12 -1
- package/dist/core/tools/hashline.js.map +1 -1
- package/dist/core/tools/index.d.ts +15 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +79 -12
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/kill.d.ts +17 -0
- package/dist/core/tools/kill.d.ts.map +1 -0
- package/dist/core/tools/kill.js +49 -0
- package/dist/core/tools/kill.js.map +1 -0
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/non-minting-snapshot-store.d.ts +49 -0
- package/dist/core/tools/non-minting-snapshot-store.d.ts.map +1 -0
- package/dist/core/tools/non-minting-snapshot-store.js +64 -0
- package/dist/core/tools/non-minting-snapshot-store.js.map +1 -0
- package/dist/core/tools/powershell.d.ts +100 -34
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +41 -11
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/read-document-extract.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -2
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/resource-selectors.d.ts +1 -1
- package/dist/core/tools/resource-selectors.d.ts.map +1 -1
- package/dist/core/tools/resource-selectors.js +21 -10
- package/dist/core/tools/resource-selectors.js.map +1 -1
- package/dist/core/tools/search.js.map +1 -1
- package/dist/core/tools/todos-render.d.ts +1 -1
- package/dist/core/tools/todos-render.js.map +1 -1
- package/dist/core/tools/write.d.ts +30 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +98 -10
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/workflow-stage-admission.d.ts +24 -0
- package/dist/core/workflow-stage-admission.d.ts.map +1 -1
- package/dist/core/workflow-stage-admission.js +87 -3
- package/dist/core/workflow-stage-admission.js.map +1 -1
- package/dist/extensions/herdr/activity.d.ts +15 -0
- package/dist/extensions/herdr/activity.d.ts.map +1 -0
- package/dist/extensions/herdr/activity.js +24 -0
- package/dist/extensions/herdr/activity.js.map +1 -0
- package/dist/extensions/herdr/environment.d.ts +7 -0
- package/dist/extensions/herdr/environment.d.ts.map +1 -0
- package/dist/extensions/herdr/environment.js +6 -0
- package/dist/extensions/herdr/environment.js.map +1 -0
- package/dist/extensions/herdr/index.d.ts +9 -0
- package/dist/extensions/herdr/index.d.ts.map +1 -0
- package/dist/extensions/herdr/index.js +225 -0
- package/dist/extensions/herdr/index.js.map +1 -0
- package/dist/extensions/herdr/pane-owner.d.ts +30 -0
- package/dist/extensions/herdr/pane-owner.d.ts.map +1 -0
- package/dist/extensions/herdr/pane-owner.js +111 -0
- package/dist/extensions/herdr/pane-owner.js.map +1 -0
- package/dist/extensions/herdr/transport.d.ts +8 -0
- package/dist/extensions/herdr/transport.d.ts.map +1 -0
- package/dist/extensions/herdr/transport.js +28 -0
- package/dist/extensions/herdr/transport.js.map +1 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +2 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/llama/huggingface-ui.d.ts +1 -1
- package/dist/extensions/llama/huggingface-ui.js.map +1 -1
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/index-extensions.d.ts +3 -2
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +14 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +149 -69
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/atomic-banner.d.ts +1 -1
- package/dist/modes/interactive/components/atomic-banner.js.map +1 -1
- package/dist/modes/interactive/components/atomic-working-status.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts +12 -0
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js +44 -0
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.js +43 -8
- package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-editor.d.ts +1 -1
- package/dist/modes/interactive/components/chat-session-host-editor.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts +2 -2
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts +2 -2
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-rendering.js +12 -3
- package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +4 -5
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.js +8 -6
- package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +7 -2
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-state.js +1 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts +1 -1
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.d.ts +8 -3
- package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-utils.d.ts +1 -1
- package/dist/modes/interactive/components/chat-session-host-utils.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-utils.js +2 -0
- package/dist/modes/interactive/components/chat-session-host-utils.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +17 -2
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +100 -3
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts +1 -0
- package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.js +1 -1
- package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector-list.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +12 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/daxnuts.js.map +1 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +7 -6
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +27 -9
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/host-input-form-mount.js.map +1 -1
- package/dist/modes/interactive/components/host-input-form.d.ts +1 -1
- package/dist/modes/interactive/components/host-input-form.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +2 -2
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts +1 -1
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/reserved-bottom-overlay.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/scroll-widget.d.ts +23 -0
- package/dist/modes/interactive/components/scroll-widget.d.ts.map +1 -0
- package/dist/modes/interactive/components/scroll-widget.js +61 -0
- package/dist/modes/interactive/components/scroll-widget.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-header.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-submenus.d.ts +1 -1
- package/dist/modes/interactive/components/settings-selector-submenus.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts +1 -1
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/task-completion-message.d.ts +13 -0
- package/dist/modes/interactive/components/task-completion-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-completion-message.js +65 -0
- package/dist/modes/interactive/components/task-completion-message.js.map +1 -0
- package/dist/modes/interactive/components/task-detail.d.ts +27 -0
- package/dist/modes/interactive/components/task-detail.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-detail.js +107 -0
- package/dist/modes/interactive/components/task-detail.js.map +1 -0
- package/dist/modes/interactive/components/task-inspector.d.ts +50 -0
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-inspector.js +599 -0
- package/dist/modes/interactive/components/task-inspector.js.map +1 -0
- package/dist/modes/interactive/components/task-list.d.ts +18 -0
- package/dist/modes/interactive/components/task-list.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-list.js +59 -0
- package/dist/modes/interactive/components/task-list.js.map +1 -0
- package/dist/modes/interactive/components/task-live-transcript.d.ts +17 -0
- package/dist/modes/interactive/components/task-live-transcript.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-live-transcript.js +41 -0
- package/dist/modes/interactive/components/task-live-transcript.js.map +1 -0
- package/dist/modes/interactive/components/task-navigation.d.ts +38 -0
- package/dist/modes/interactive/components/task-navigation.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-navigation.js +93 -0
- package/dist/modes/interactive/components/task-navigation.js.map +1 -0
- package/dist/modes/interactive/components/task-row.d.ts +34 -0
- package/dist/modes/interactive/components/task-row.d.ts.map +1 -0
- package/dist/modes/interactive/components/task-row.js +165 -0
- package/dist/modes/interactive/components/task-row.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/transcript-follow-indicator.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-component.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-help.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-label-input.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-list.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/working-status.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +8 -2
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +3 -1
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +9 -30
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/interactive-deferred-startup.js +2 -1
- package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-context.js +14 -4
- package/dist/modes/interactive/interactive-extension-context.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-custom-ui.js +52 -4
- package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +11 -3
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-widgets.js +9 -1
- package/dist/modes/interactive/interactive-extension-widgets.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +19 -0
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +7 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +10 -4
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +6 -6
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +3 -2
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +3 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js +4 -1
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +30 -4
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +33 -23
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +1 -0
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +3 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-summarization-retry-events.js +2 -2
- package/dist/modes/interactive/interactive-summarization-retry-events.js.map +1 -1
- package/dist/modes/interactive/interactive-task-projection.d.ts +13 -0
- package/dist/modes/interactive/interactive-task-projection.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-task-projection.js +72 -0
- package/dist/modes/interactive/interactive-task-projection.js.map +1 -0
- package/dist/modes/interactive/interactive-tui.js.map +1 -1
- package/dist/modes/interactive/interactive-windows-subshell.d.ts +17 -0
- package/dist/modes/interactive/interactive-windows-subshell.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-windows-subshell.js +92 -0
- package/dist/modes/interactive/interactive-windows-subshell.js.map +1 -0
- package/dist/modes/interactive/skill-command-autocomplete.d.ts +12 -0
- package/dist/modes/interactive/skill-command-autocomplete.d.ts.map +1 -0
- package/dist/modes/interactive/skill-command-autocomplete.js +69 -0
- package/dist/modes/interactive/skill-command-autocomplete.js.map +1 -0
- package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-class.js +4 -1
- package/dist/modes/interactive/theme/theme-class.js.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts +1 -1
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.d.ts +2 -2
- package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
- package/dist/modes/interactive-engine/create-isolated-runtime.d.ts +1 -1
- package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.d.ts +9 -10
- package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.js +29 -12
- package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts +3 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.js +11 -0
- package/dist/modes/interactive-engine/engine-diagnostic-view.js.map +1 -1
- package/dist/modes/interactive-engine/engine-dialog-host.d.ts +2 -2
- package/dist/modes/interactive-engine/engine-dialog-host.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-dialog-host.js +4 -1
- package/dist/modes/interactive-engine/engine-dialog-host.js.map +1 -1
- package/dist/modes/interactive-engine/engine-project-trust.d.ts +10 -0
- package/dist/modes/interactive-engine/engine-project-trust.d.ts.map +1 -0
- package/dist/modes/interactive-engine/engine-project-trust.js +28 -0
- package/dist/modes/interactive-engine/engine-project-trust.js.map +1 -0
- package/dist/modes/interactive-engine/engine-render-service.d.ts +1 -1
- package/dist/modes/interactive-engine/engine-render-service.js.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +3 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.js +7 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
- package/dist/modes/interactive-engine/input-form-host.d.ts +2 -2
- package/dist/modes/interactive-engine/input-form-host.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-auth.d.ts +1 -1
- package/dist/modes/interactive-engine/isolated-auth.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +5 -2
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +42 -4
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +21 -1
- package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
- package/dist/modes/interactive-engine/protocol.js +53 -2
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/interactive-engine/remote-component.d.ts +2 -2
- package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
- package/dist/modes/interactive-engine/remote-component.js +19 -8
- package/dist/modes/interactive-engine/remote-component.js.map +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.js.map +1 -1
- package/dist/modes/interactive-engine/remote-renderer.d.ts +1 -1
- package/dist/modes/interactive-engine/remote-renderer.js.map +1 -1
- package/dist/modes/interactive-engine/session-picker-host.d.ts +2 -2
- package/dist/modes/interactive-engine/session-picker-host.js.map +1 -1
- package/dist/modes/json-event.d.ts +1 -1
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-bash-request-owners.d.ts +2 -2
- package/dist/modes/rpc/rpc-bash-request-owners.js.map +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +2 -2
- package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-api.js +2 -2
- package/dist/modes/rpc/rpc-client-api.js.map +1 -1
- package/dist/modes/rpc/rpc-client-process.d.ts +2 -0
- package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-process.js +23 -1
- package/dist/modes/rpc/rpc-client-process.js.map +1 -1
- package/dist/modes/rpc/rpc-client-waits.d.ts +1 -1
- package/dist/modes/rpc/rpc-client-waits.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +3 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +40 -3
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts +4 -2
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +12 -4
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-extension-ui.d.ts +1 -1
- package/dist/modes/rpc/rpc-extension-ui.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-extension-ui.js +2 -1
- package/dist/modes/rpc/rpc-extension-ui.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +12 -2
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts +4 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +35 -1
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +17 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/task-ui-bridge.d.ts +9 -0
- package/dist/modes/rpc/task-ui-bridge.d.ts.map +1 -0
- package/dist/modes/rpc/task-ui-bridge.js +146 -0
- package/dist/modes/rpc/task-ui-bridge.js.map +1 -0
- package/dist/self-update-plan.js.map +1 -1
- package/dist/utils/markit.d.ts +2 -0
- package/dist/utils/markit.d.ts.map +1 -1
- package/dist/utils/markit.js +65 -5
- package/dist/utils/markit.js.map +1 -1
- package/docs/background-tasks.md +232 -0
- package/docs/build.md +51 -0
- package/docs/changelog.mdx +8 -8
- package/docs/compaction/reference.md +267 -0
- package/docs/compaction.md +39 -200
- package/docs/computer-use.md +425 -0
- package/docs/containerization.md +9 -5
- package/docs/custom-provider/api-reference.md +145 -0
- package/docs/custom-provider/oauth.md +131 -0
- package/docs/custom-provider/override.md +34 -0
- package/docs/custom-provider/registration.md +163 -0
- package/docs/custom-provider/streaming.md +214 -0
- package/docs/custom-provider.md +43 -607
- package/docs/development.md +68 -30
- package/docs/docs.json +199 -73
- package/docs/environment-variables.md +2 -2
- package/docs/extensions/api-reference.md +1003 -0
- package/docs/extensions/authoring.md +676 -0
- package/docs/extensions/events.md +793 -0
- package/docs/extensions/examples.md +94 -0
- package/docs/extensions/ui.md +470 -0
- package/docs/extensions.md +241 -2623
- package/docs/getting-started/authentication.md +55 -0
- package/docs/getting-started/first-session.md +172 -0
- package/docs/getting-started/installation.md +154 -0
- package/docs/getting-started/project-instructions.md +43 -0
- package/docs/guides/configuration.md +65 -0
- package/docs/guides/intercom.md +24 -0
- package/docs/guides/non-interactive.md +33 -0
- package/docs/guides/subagents.md +24 -0
- package/docs/guides/workflows.md +27 -0
- package/docs/guides.md +41 -0
- package/docs/herdr.md +55 -0
- package/docs/index.md +13 -44
- package/docs/intercom/operations.md +178 -0
- package/docs/intercom/reference.md +150 -0
- package/docs/intercom.md +61 -251
- package/docs/json.md +17 -0
- package/docs/keybindings.md +36 -2
- package/docs/llama-cpp.md +5 -0
- package/docs/models/artificial-analysis-index.md +89 -0
- package/docs/models/evals.md +225 -148
- package/docs/models/model-selection.md +30 -21
- package/docs/models/pareto-efficiency.md +4 -4
- package/docs/models/reference.md +601 -0
- package/docs/models.md +45 -550
- package/docs/packages/authoring.md +88 -0
- package/docs/packages/reference.md +43 -0
- package/docs/packages.md +28 -107
- package/docs/programmatic.md +29 -0
- package/docs/prompt-templates.md +11 -0
- package/docs/providers/reference.md +23 -0
- package/docs/providers.md +59 -62
- package/docs/quickstart.md +45 -239
- package/docs/reference/cli.md +252 -0
- package/docs/reference.md +52 -0
- package/docs/rpc/examples.md +64 -0
- package/docs/rpc/extension-ui.md +198 -0
- package/docs/rpc/protocol.md +1341 -0
- package/docs/rpc.md +109 -1346
- package/docs/sdk/reference.md +1090 -0
- package/docs/sdk.md +64 -756
- package/docs/session-format.md +2 -0
- package/docs/sessions.md +6 -10
- package/docs/settings.md +45 -48
- package/docs/skills/authoring.md +95 -0
- package/docs/skills/reference.md +60 -0
- package/docs/skills.md +37 -117
- package/docs/subagents/authoring.md +37 -0
- package/docs/subagents/reference.md +60 -0
- package/docs/subagents.md +90 -78
- package/docs/terminal-setup.md +1 -1
- package/docs/themes/reference.md +176 -0
- package/docs/themes.md +25 -135
- package/docs/tmux.md +7 -0
- package/docs/tools/edit.md +5 -0
- package/docs/tools.md +67 -1
- package/docs/tui/reference.md +343 -0
- package/docs/tui.md +83 -285
- package/docs/usage.md +31 -210
- package/docs/web-access.md +50 -0
- package/docs/windows.md +6 -5
- package/docs/workflows/api-reference.md +31 -12
- package/docs/workflows/authoring.md +7 -5
- package/docs/workflows/builtins.md +11 -8
- package/docs/workflows/operations.md +103 -38
- package/docs/workflows/reliable-design.md +59 -10
- package/docs/workflows/verification.md +116 -32
- package/docs/workflows.md +7 -3
- package/examples/extensions/gondolin/index.ts +116 -148
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/ssh.ts +56 -34
- package/npm-shrinkwrap.json +798 -678
- package/package.json +11 -11
- /package/dist/builtin/workflows/builtin/{chunk-cg9tmks0.js → chunk-n1910xc4.js} +0 -0
- /package/dist/builtin/workflows/builtin/{chunk-wpckd35c.js → chunk-rc5ec5xx.js} +0 -0
- /package/dist/builtin/workflows/builtin/{chunk-7at6dnkr.js → chunk-tgt0s5e5.js} +0 -0
- /package/dist/builtin/workflows/builtin/{chunk-bfkmzv9h.js → chunk-xtxcq5tj.js} +0 -0
|
@@ -302,7 +302,7 @@ function createSessionScopedSingleton(key, createLocal) {
|
|
|
302
302
|
const live = () => shared.instance ?? instance;
|
|
303
303
|
const current = () => live();
|
|
304
304
|
const adoptWithResult = (scope, options) => {
|
|
305
|
-
const
|
|
305
|
+
const current = live();
|
|
306
306
|
let targetCreated = false;
|
|
307
307
|
const target = sessionScopedExtensionState(scope, key, () => {
|
|
308
308
|
targetCreated = true;
|
|
@@ -311,8 +311,8 @@ function createSessionScopedSingleton(key, createLocal) {
|
|
|
311
311
|
shared.localClaimed = true;
|
|
312
312
|
return shared.local;
|
|
313
313
|
});
|
|
314
|
-
const preservedCurrent = !targetCreated && target !==
|
|
315
|
-
shared.instance = preservedCurrent ?
|
|
314
|
+
const preservedCurrent = !targetCreated && target !== current && options?.preserveCurrentWhenTargetExists?.(current, target) === true;
|
|
315
|
+
shared.instance = preservedCurrent ? current : target;
|
|
316
316
|
instance = shared.instance;
|
|
317
317
|
return { instance: shared.instance, preservedCurrent };
|
|
318
318
|
};
|
|
@@ -569,17 +569,17 @@ function cloneWorkflowExitSnapshotValue(value, seen, stack = new Set) {
|
|
|
569
569
|
return stack.has(objectValue) ? makeWorkflowExitSnapshotInvalidValue("circular object") : previousClone;
|
|
570
570
|
}
|
|
571
571
|
if (Array.isArray(value)) {
|
|
572
|
-
const
|
|
573
|
-
seen.set(objectValue,
|
|
572
|
+
const clone = [];
|
|
573
|
+
seen.set(objectValue, clone);
|
|
574
574
|
stack.add(objectValue);
|
|
575
575
|
try {
|
|
576
576
|
for (let index = 0;index < value.length; index += 1) {
|
|
577
|
-
|
|
577
|
+
clone[index] = cloneWorkflowExitSnapshotValue(value[index], seen, stack);
|
|
578
578
|
}
|
|
579
579
|
} finally {
|
|
580
580
|
stack.delete(objectValue);
|
|
581
581
|
}
|
|
582
|
-
return
|
|
582
|
+
return clone;
|
|
583
583
|
}
|
|
584
584
|
if (!isPlainWorkflowExitSnapshotObject(objectValue)) {
|
|
585
585
|
return makeWorkflowExitSnapshotInvalidValue(workflowSerializableTypeName(value));
|
|
@@ -952,7 +952,7 @@ function buildStagePromptAdapter(id, kind, args, createdAt) {
|
|
|
952
952
|
}
|
|
953
953
|
|
|
954
954
|
// dist/builtin/workflows/src/shared/stage-ui-broker.ts
|
|
955
|
-
import { randomUUID } from "node:crypto";
|
|
955
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
956
956
|
|
|
957
957
|
// dist/builtin/workflows/src/shared/pending-stage-delivery.ts
|
|
958
958
|
var PENDING_STAGE_MESSAGE_LIMIT = 50;
|
|
@@ -963,7 +963,7 @@ function queueStageMessage(messages, input, senderGroup, runGroup, stageIdentity
|
|
|
963
963
|
}
|
|
964
964
|
const messageId = input.message.id;
|
|
965
965
|
const queued = pendingStageMessagesFor(messages, input.runId, input.stageKey, stageIdentity);
|
|
966
|
-
const existing = messages.find((
|
|
966
|
+
const existing = messages.find((entry) => entry.runId === input.runId && entry.id === messageId);
|
|
967
967
|
if (existing !== undefined) {
|
|
968
968
|
if (pendingStageMessageSignature(existing, stageIdentity) !== pendingStageMessageSignature(input, stageIdentity)) {
|
|
969
969
|
return {
|
|
@@ -1013,7 +1013,7 @@ function queueStickyStageMessage(messages, input, senderGroup, runGroup) {
|
|
|
1013
1013
|
return { ok: false, reason: "group_mismatch", runId: input.runId, stageKey: input.targetPath };
|
|
1014
1014
|
}
|
|
1015
1015
|
const messageId = input.message.id;
|
|
1016
|
-
const existing = messages.find((
|
|
1016
|
+
const existing = messages.find((entry) => entry.runId === input.runId && entry.id === messageId);
|
|
1017
1017
|
if (existing !== undefined) {
|
|
1018
1018
|
if (pendingStageMessageSignature(existing) !== pendingStageMessageSignature(input)) {
|
|
1019
1019
|
return {
|
|
@@ -1064,7 +1064,7 @@ function queuedStickyCount(messages, runId, targetPath) {
|
|
|
1064
1064
|
return messages.filter((entry) => entry.runId === runId && entry.sticky === true && entry.targetPath === targetPath && entry.status === "queued").length;
|
|
1065
1065
|
}
|
|
1066
1066
|
function recordPendingStageMessageDeliveries(messages, runId, messageId, records, deliveredAt) {
|
|
1067
|
-
const index = messages.findIndex((
|
|
1067
|
+
const index = messages.findIndex((entry) => entry.runId === runId && entry.id === messageId && entry.sticky === true && entry.status === "queued");
|
|
1068
1068
|
if (index < 0)
|
|
1069
1069
|
return messages;
|
|
1070
1070
|
const entry = messages[index];
|
|
@@ -1507,6 +1507,7 @@ function compactStage(stage) {
|
|
|
1507
1507
|
attemptedModels: _attemptedModels,
|
|
1508
1508
|
modelAttempts: _modelAttempts,
|
|
1509
1509
|
result: _result,
|
|
1510
|
+
structured: _structured,
|
|
1510
1511
|
...metadata
|
|
1511
1512
|
} = stage;
|
|
1512
1513
|
return {
|
|
@@ -1565,6 +1566,173 @@ function deepFreezeGraphValue(value) {
|
|
|
1565
1566
|
}
|
|
1566
1567
|
}
|
|
1567
1568
|
|
|
1569
|
+
// dist/builtin/workflows/src/shared/workflow-observation-runtime.ts
|
|
1570
|
+
import { randomUUID } from "node:crypto";
|
|
1571
|
+
|
|
1572
|
+
// dist/builtin/workflows/src/shared/workflow-activity.ts
|
|
1573
|
+
function workflowActivityNodeKey(runId, nodeId) {
|
|
1574
|
+
return `${runId}:${nodeId}`;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
// dist/builtin/workflows/src/shared/workflow-observation-runtime.ts
|
|
1578
|
+
class WorkflowObservationRuntime {
|
|
1579
|
+
runs;
|
|
1580
|
+
invalidate;
|
|
1581
|
+
liveRunIds = new Set;
|
|
1582
|
+
executingStageIds = new Set;
|
|
1583
|
+
executingToolNodeIds = new Set;
|
|
1584
|
+
stoppingRunIds = new Set;
|
|
1585
|
+
retryingStageIds = new Set;
|
|
1586
|
+
acknowledgedFailureRunIds = new Set;
|
|
1587
|
+
listeners = new Set;
|
|
1588
|
+
replayStageIds = new Set;
|
|
1589
|
+
previous = new Map;
|
|
1590
|
+
recoveryDepth = 0;
|
|
1591
|
+
constructor(runs, invalidate) {
|
|
1592
|
+
this.runs = runs;
|
|
1593
|
+
this.invalidate = invalidate;
|
|
1594
|
+
}
|
|
1595
|
+
get recovering() {
|
|
1596
|
+
return this.recoveryDepth > 0;
|
|
1597
|
+
}
|
|
1598
|
+
startRun(runId) {
|
|
1599
|
+
this.liveRunIds.add(runId);
|
|
1600
|
+
this.stoppingRunIds.delete(runId);
|
|
1601
|
+
}
|
|
1602
|
+
finishRun(runId) {
|
|
1603
|
+
this.liveRunIds.delete(runId);
|
|
1604
|
+
this.stoppingRunIds.delete(runId);
|
|
1605
|
+
for (const ids of [
|
|
1606
|
+
this.executingStageIds,
|
|
1607
|
+
this.executingToolNodeIds,
|
|
1608
|
+
this.retryingStageIds,
|
|
1609
|
+
this.replayStageIds
|
|
1610
|
+
]) {
|
|
1611
|
+
for (const id of ids)
|
|
1612
|
+
if (id.startsWith(`${runId}:`))
|
|
1613
|
+
ids.delete(id);
|
|
1614
|
+
}
|
|
1615
|
+
this.invalidate();
|
|
1616
|
+
}
|
|
1617
|
+
emit(event) {
|
|
1618
|
+
for (const listener of this.listeners) {
|
|
1619
|
+
try {
|
|
1620
|
+
listener(event);
|
|
1621
|
+
} catch {}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
rootRunId(run) {
|
|
1625
|
+
if (run.rootRunId !== undefined)
|
|
1626
|
+
return run.rootRunId;
|
|
1627
|
+
if (run.parentRunId === undefined)
|
|
1628
|
+
return run.id;
|
|
1629
|
+
const parent = this.runs().find((candidate) => candidate.id === run.parentRunId);
|
|
1630
|
+
return parent ? this.rootRunId(parent) : run.parentRunId;
|
|
1631
|
+
}
|
|
1632
|
+
lifecycle(target, attribution = "unknown") {
|
|
1633
|
+
if (this.recovering && !this.liveRunIds.has(target.runId))
|
|
1634
|
+
return;
|
|
1635
|
+
const run = this.runs().find((candidate) => candidate.id === target.runId);
|
|
1636
|
+
if (!run)
|
|
1637
|
+
return;
|
|
1638
|
+
const rootRunId = this.rootRunId(run);
|
|
1639
|
+
const now = Date.now();
|
|
1640
|
+
this.emit({
|
|
1641
|
+
kind: "lifecycle",
|
|
1642
|
+
event: {
|
|
1643
|
+
type: "workflow_lifecycle",
|
|
1644
|
+
eventId: randomUUID(),
|
|
1645
|
+
runId: run.id,
|
|
1646
|
+
rootRunId,
|
|
1647
|
+
occurredAt: now,
|
|
1648
|
+
observedAt: now,
|
|
1649
|
+
target: canonicalTarget(target, rootRunId),
|
|
1650
|
+
attribution,
|
|
1651
|
+
delivery: target.kind === "stage" && this.replayStageIds.has(workflowActivityNodeKey(run.id, target.stageId)) ? "replay" : "live"
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
control(runId, action, attribution = "unknown") {
|
|
1656
|
+
const run = this.runs().find((candidate) => candidate.id === runId);
|
|
1657
|
+
if (!run)
|
|
1658
|
+
return;
|
|
1659
|
+
if ((action === "quit" || action === "kill" || action === "pause") && this.liveRunIds.has(runId))
|
|
1660
|
+
this.stoppingRunIds.add(runId);
|
|
1661
|
+
if (action === "resume")
|
|
1662
|
+
this.stoppingRunIds.delete(runId);
|
|
1663
|
+
this.lifecycle({ kind: "run", runId, status: run.status, action }, attribution);
|
|
1664
|
+
this.invalidate();
|
|
1665
|
+
}
|
|
1666
|
+
heartbeat(runId, scheduledAt, intervalMinutes) {
|
|
1667
|
+
const run = this.runs().find((candidate) => candidate.id === runId);
|
|
1668
|
+
if (run)
|
|
1669
|
+
this.emit({
|
|
1670
|
+
kind: "heartbeat",
|
|
1671
|
+
event: { type: "workflow_heartbeat", runId, rootRunId: this.rootRunId(run), scheduledAt, intervalMinutes }
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
beginRecovery() {
|
|
1675
|
+
this.recoveryDepth++;
|
|
1676
|
+
if (this.recoveryDepth === 1)
|
|
1677
|
+
this.emit({ kind: "availability" });
|
|
1678
|
+
let ended = false;
|
|
1679
|
+
return () => {
|
|
1680
|
+
if (ended)
|
|
1681
|
+
return;
|
|
1682
|
+
ended = true;
|
|
1683
|
+
this.capture();
|
|
1684
|
+
this.recoveryDepth--;
|
|
1685
|
+
if (!this.recovering)
|
|
1686
|
+
this.emit({ kind: "availability" });
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
capture() {
|
|
1690
|
+
const next = new Map;
|
|
1691
|
+
const visit = (key, target, historical = false) => {
|
|
1692
|
+
next.set(key, target);
|
|
1693
|
+
const previous = this.previous.get(key);
|
|
1694
|
+
if (!historical && this.liveRunIds.has(target.runId) && previous?.status !== target.status) {
|
|
1695
|
+
this.lifecycle(previous && previous.kind !== "prompt" && target.kind !== "prompt" ? { ...target, previousStatus: previous.status } : target, this.runs().find((run) => run.id === target.runId)?.origin);
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
for (const run of this.runs()) {
|
|
1699
|
+
const existing = this.previous.has(`run:${run.id}`);
|
|
1700
|
+
visit(`run:${run.id}`, { kind: "run", runId: run.id, status: run.status });
|
|
1701
|
+
for (const stage of run.stages) {
|
|
1702
|
+
visit(`stage:${workflowActivityNodeKey(run.id, stage.id)}`, { kind: "stage", runId: run.id, stageId: stage.id, stageName: stage.name, status: stage.status }, !existing);
|
|
1703
|
+
if (stage.pendingPrompt)
|
|
1704
|
+
visit(`prompt:${stage.pendingPrompt.id}`, {
|
|
1705
|
+
kind: "prompt",
|
|
1706
|
+
runId: run.id,
|
|
1707
|
+
stageId: stage.id,
|
|
1708
|
+
promptId: stage.pendingPrompt.id,
|
|
1709
|
+
status: "opened"
|
|
1710
|
+
}, !existing);
|
|
1711
|
+
}
|
|
1712
|
+
for (const tool of run.toolNodes ?? [])
|
|
1713
|
+
visit(`tool:${workflowActivityNodeKey(run.id, tool.id)}`, { kind: "tool", runId: run.id, toolNodeId: tool.id, toolName: tool.name, status: tool.status }, !existing);
|
|
1714
|
+
if (run.pendingPrompt)
|
|
1715
|
+
visit(`prompt:${run.pendingPrompt.id}`, { kind: "prompt", runId: run.id, promptId: run.pendingPrompt.id, status: "opened" }, !existing);
|
|
1716
|
+
}
|
|
1717
|
+
this.previous = next;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
var workflowObservationRuntimeKey = Symbol.for("atomic-workflows/store-observation-runtime@1");
|
|
1721
|
+
function canonicalTarget(target, rootRunId) {
|
|
1722
|
+
if (target.runId === rootRunId)
|
|
1723
|
+
return target;
|
|
1724
|
+
switch (target.kind) {
|
|
1725
|
+
case "stage":
|
|
1726
|
+
return { ...target, stageId: workflowActivityNodeKey(target.runId, target.stageId) };
|
|
1727
|
+
case "tool":
|
|
1728
|
+
return { ...target, toolNodeId: workflowActivityNodeKey(target.runId, target.toolNodeId) };
|
|
1729
|
+
case "prompt":
|
|
1730
|
+
return target.stageId === undefined ? target : { ...target, stageId: workflowActivityNodeKey(target.runId, target.stageId) };
|
|
1731
|
+
case "run":
|
|
1732
|
+
return target;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1568
1736
|
// dist/builtin/workflows/src/shared/store-internal.ts
|
|
1569
1737
|
var TERMINAL_STATUSES = new Set([
|
|
1570
1738
|
"completed",
|
|
@@ -1667,6 +1835,7 @@ function createStoreState() {
|
|
|
1667
1835
|
function createStoreContext(state = createStoreState()) {
|
|
1668
1836
|
let cachedGraphVersion = -1;
|
|
1669
1837
|
let cachedGraphSnapshot;
|
|
1838
|
+
const observation = new WorkflowObservationRuntime(() => state.runs, bumpAndNotify);
|
|
1670
1839
|
function snapshot() {
|
|
1671
1840
|
return JSON.parse(JSON.stringify({ runs: state.runs, notices: state.notices, version: state.version }));
|
|
1672
1841
|
}
|
|
@@ -1678,6 +1847,7 @@ function createStoreContext(state = createStoreState()) {
|
|
|
1678
1847
|
return cachedGraphSnapshot;
|
|
1679
1848
|
}
|
|
1680
1849
|
function notify() {
|
|
1850
|
+
observation.capture();
|
|
1681
1851
|
for (const fn of state.invalidationListeners) {
|
|
1682
1852
|
try {
|
|
1683
1853
|
fn();
|
|
@@ -1733,6 +1903,7 @@ function createStoreContext(state = createStoreState()) {
|
|
|
1733
1903
|
const prompt = stage.pendingPrompt;
|
|
1734
1904
|
if (!prompt)
|
|
1735
1905
|
return;
|
|
1906
|
+
observation.lifecycle({ kind: "prompt", runId, stageId: stage.id, promptId: prompt.id, status: "cancelled" });
|
|
1736
1907
|
stage.pendingPrompt = undefined;
|
|
1737
1908
|
state.stagePromptDrafts.delete(stagePromptDraftKey(runId, stage.id, prompt.id));
|
|
1738
1909
|
rejectPrompt(prompt.id, reason);
|
|
@@ -1744,6 +1915,7 @@ function createStoreContext(state = createStoreState()) {
|
|
|
1744
1915
|
}
|
|
1745
1916
|
return {
|
|
1746
1917
|
state,
|
|
1918
|
+
observation,
|
|
1747
1919
|
snapshot,
|
|
1748
1920
|
graphSnapshot,
|
|
1749
1921
|
notify,
|
|
@@ -1913,8 +2085,8 @@ function createPendingStageDeliveryStoreMethods(context) {
|
|
|
1913
2085
|
};
|
|
1914
2086
|
}
|
|
1915
2087
|
function resolvePendingStageIdentity(run, stageKey) {
|
|
1916
|
-
const exactIds = run.stages.filter((
|
|
1917
|
-
const candidates = exactIds.length > 0 ? exactIds : run.stages.filter((
|
|
2088
|
+
const exactIds = run.stages.filter((stage) => stage.id === stageKey);
|
|
2089
|
+
const candidates = exactIds.length > 0 ? exactIds : run.stages.filter((stage) => stage.name === stageKey);
|
|
1918
2090
|
if (candidates.length !== 1)
|
|
1919
2091
|
return;
|
|
1920
2092
|
const stage = candidates[0];
|
|
@@ -1953,6 +2125,7 @@ function createPromptStoreMethods(context) {
|
|
|
1953
2125
|
const pending = run.pendingPrompt;
|
|
1954
2126
|
if (!pending || pending.id !== promptId)
|
|
1955
2127
|
return false;
|
|
2128
|
+
context.observation.lifecycle({ kind: "prompt", runId, promptId, status: "answered" });
|
|
1956
2129
|
run.pendingPrompt = undefined;
|
|
1957
2130
|
context.bumpAndNotify();
|
|
1958
2131
|
const entry = state.resolvers.get(promptId);
|
|
@@ -2023,6 +2196,13 @@ function createPromptStoreMethods(context) {
|
|
|
2023
2196
|
state.stagePromptAnswers.delete(context.stagePromptAnswerKey(runId, stageId));
|
|
2024
2197
|
delete stage.promptAnswerState;
|
|
2025
2198
|
}
|
|
2199
|
+
context.observation.lifecycle({
|
|
2200
|
+
kind: "prompt",
|
|
2201
|
+
runId,
|
|
2202
|
+
stageId,
|
|
2203
|
+
promptId,
|
|
2204
|
+
status: options.recordAnswer === false ? "cancelled" : "answered"
|
|
2205
|
+
});
|
|
2026
2206
|
stage.pendingPrompt = undefined;
|
|
2027
2207
|
if (stage.status === "awaiting_input") {
|
|
2028
2208
|
stage.status = "running";
|
|
@@ -2239,6 +2419,7 @@ function createRunStoreMethods(context) {
|
|
|
2239
2419
|
}
|
|
2240
2420
|
const pending = run.pendingPrompt;
|
|
2241
2421
|
if (pending) {
|
|
2422
|
+
context.observation.lifecycle({ kind: "prompt", runId, promptId: pending.id, status: "cancelled" });
|
|
2242
2423
|
run.pendingPrompt = undefined;
|
|
2243
2424
|
context.rejectPrompt(pending.id, `atomic-workflows: run ${runId} ended before prompt resolved`);
|
|
2244
2425
|
}
|
|
@@ -2320,6 +2501,7 @@ function createRunStoreMethods(context) {
|
|
|
2320
2501
|
const run = state.runs[index];
|
|
2321
2502
|
const pending = run.pendingPrompt;
|
|
2322
2503
|
if (pending) {
|
|
2504
|
+
context.observation.lifecycle({ kind: "prompt", runId, promptId: pending.id, status: "cancelled" });
|
|
2323
2505
|
context.rejectPrompt(pending.id, `atomic-workflows: run ${runId} was removed before prompt resolved`);
|
|
2324
2506
|
}
|
|
2325
2507
|
context.rejectAllStagePrompts(runId, run, `atomic-workflows: run ${runId} was removed before prompt resolved`);
|
|
@@ -2480,6 +2662,8 @@ function createToolNodeStoreMethods(context) {
|
|
|
2480
2662
|
return false;
|
|
2481
2663
|
node.status = "running";
|
|
2482
2664
|
node.startedAt = startedAt;
|
|
2665
|
+
if (context.observation.liveRunIds.has(runId))
|
|
2666
|
+
context.observation.executingToolNodeIds.add(workflowActivityNodeKey(runId, nodeId));
|
|
2483
2667
|
context.bumpAndNotify();
|
|
2484
2668
|
return true;
|
|
2485
2669
|
},
|
|
@@ -2487,6 +2671,7 @@ function createToolNodeStoreMethods(context) {
|
|
|
2487
2671
|
const node = context.findRun(runId)?.toolNodes?.find((candidate) => candidate.id === nodeId);
|
|
2488
2672
|
if (node === undefined || node.status === "completed" || node.status === "failed" || node.status === "cached" || node.status === "cancelled")
|
|
2489
2673
|
return false;
|
|
2674
|
+
context.observation.executingToolNodeIds.delete(workflowActivityNodeKey(runId, nodeId));
|
|
2490
2675
|
node.status = update.status;
|
|
2491
2676
|
if (update.endedAt !== undefined)
|
|
2492
2677
|
node.endedAt = update.endedAt;
|
|
@@ -2516,6 +2701,9 @@ function createStageStoreMethods(context) {
|
|
|
2516
2701
|
if (!run.stages.some((s) => s.id === stage.id)) {
|
|
2517
2702
|
run.stages.push(stage);
|
|
2518
2703
|
}
|
|
2704
|
+
if (stage.status === "running" && context.observation.liveRunIds.has(runId)) {
|
|
2705
|
+
context.observation.executingStageIds.add(workflowActivityNodeKey(runId, stage.id));
|
|
2706
|
+
}
|
|
2519
2707
|
context.bumpAndNotify();
|
|
2520
2708
|
},
|
|
2521
2709
|
recordStageWorkflowChildRun(runId, stageId, ref) {
|
|
@@ -2525,8 +2713,12 @@ function createStageStoreMethods(context) {
|
|
|
2525
2713
|
const stage = context.findStage(run, stageId);
|
|
2526
2714
|
if (!stage)
|
|
2527
2715
|
return false;
|
|
2528
|
-
|
|
2716
|
+
const released = context.observation.executingStageIds.delete(workflowActivityNodeKey(runId, stageId));
|
|
2717
|
+
if (stage.workflowChildRun?.runId === ref.runId && stage.workflowChildRun.alias === ref.alias && stage.workflowChildRun.workflow === ref.workflow) {
|
|
2718
|
+
if (released)
|
|
2719
|
+
context.bumpAndNotify();
|
|
2529
2720
|
return false;
|
|
2721
|
+
}
|
|
2530
2722
|
stage.workflowChildRun = { ...ref };
|
|
2531
2723
|
context.bumpAndNotify();
|
|
2532
2724
|
return true;
|
|
@@ -2565,6 +2757,7 @@ function createStageStoreMethods(context) {
|
|
|
2565
2757
|
const existing = context.findStage(run, stage.id);
|
|
2566
2758
|
if (!existing)
|
|
2567
2759
|
return;
|
|
2760
|
+
context.observation.executingStageIds.delete(workflowActivityNodeKey(runId, stage.id));
|
|
2568
2761
|
existing.status = stage.status;
|
|
2569
2762
|
existing.endedAt = stage.endedAt;
|
|
2570
2763
|
if (existing.endedAt !== undefined && existing.pausedAt !== undefined) {
|
|
@@ -2788,6 +2981,7 @@ function createStageStoreMethods(context) {
|
|
|
2788
2981
|
context.bumpAndNotify();
|
|
2789
2982
|
return false;
|
|
2790
2983
|
}
|
|
2984
|
+
context.observation.executingStageIds.delete(workflowActivityNodeKey(runId, stageId));
|
|
2791
2985
|
stage.status = "paused";
|
|
2792
2986
|
stage.pausedAt = nextControlTimestamp(pausedAt, stage.resumedAt);
|
|
2793
2987
|
stage.resumedAt = undefined;
|
|
@@ -2820,6 +3014,8 @@ function createStageStoreMethods(context) {
|
|
|
2820
3014
|
return false;
|
|
2821
3015
|
}
|
|
2822
3016
|
const resumedTs = nextControlTimestamp(resumedAt, stage.pausedAt);
|
|
3017
|
+
if (context.observation.liveRunIds.has(runId))
|
|
3018
|
+
context.observation.executingStageIds.add(workflowActivityNodeKey(runId, stageId));
|
|
2823
3019
|
stage.status = "running";
|
|
2824
3020
|
if (stage.startedAt !== undefined) {
|
|
2825
3021
|
stage.pausedDurationMs = accumulatePausedDurationMs(stage.pausedDurationMs, stage.pausedAt, resumedTs);
|
|
@@ -2842,13 +3038,18 @@ function createStageStoreMethods(context) {
|
|
|
2842
3038
|
// dist/builtin/workflows/src/shared/store-factory.ts
|
|
2843
3039
|
function createStore() {
|
|
2844
3040
|
const context = createStoreContext();
|
|
2845
|
-
|
|
3041
|
+
const created = {
|
|
3042
|
+
[workflowObservationRuntimeKey]: context.observation,
|
|
2846
3043
|
...createRunStoreMethods(context),
|
|
2847
3044
|
...createPendingStageDeliveryStoreMethods(context),
|
|
2848
3045
|
...createStageStoreMethods(context),
|
|
2849
3046
|
...createToolNodeStoreMethods(context),
|
|
2850
3047
|
...createPromptStoreMethods(context)
|
|
2851
3048
|
};
|
|
3049
|
+
return created;
|
|
3050
|
+
}
|
|
3051
|
+
function workflowObservationRuntime(activeStore) {
|
|
3052
|
+
return activeStore[workflowObservationRuntimeKey];
|
|
2852
3053
|
}
|
|
2853
3054
|
var SESSION_KEY2 = "workflows:store:v1";
|
|
2854
3055
|
var singleton2 = createSessionScopedSingleton(SESSION_KEY2, createStore);
|
|
@@ -2858,7 +3059,7 @@ function key(runId, stageId) {
|
|
|
2858
3059
|
return `${runId}\x00${stageId}`;
|
|
2859
3060
|
}
|
|
2860
3061
|
function nextRequestId() {
|
|
2861
|
-
return `stage-ui-${
|
|
3062
|
+
return `stage-ui-${randomUUID2()}`;
|
|
2862
3063
|
}
|
|
2863
3064
|
|
|
2864
3065
|
class StageUiBroker {
|
|
@@ -2955,6 +3156,7 @@ class StageUiBroker {
|
|
|
2955
3156
|
};
|
|
2956
3157
|
}
|
|
2957
3158
|
requestCustomUi(runId, stageId, factory, options, signal) {
|
|
3159
|
+
signal = options?.signal ? signal ? AbortSignal.any([signal, options.signal]) : options.signal : signal;
|
|
2958
3160
|
if (signal?.aborted) {
|
|
2959
3161
|
return Promise.reject(signal.reason ?? new Error("atomic-workflows: stage UI request aborted"));
|
|
2960
3162
|
}
|
|
@@ -3265,8 +3467,8 @@ function normalizeUIContext(adapter) {
|
|
|
3265
3467
|
};
|
|
3266
3468
|
}
|
|
3267
3469
|
function stringField(value, keys) {
|
|
3268
|
-
for (const
|
|
3269
|
-
const candidate = value[
|
|
3470
|
+
for (const key of keys) {
|
|
3471
|
+
const candidate = value[key];
|
|
3270
3472
|
if (typeof candidate === "string" && candidate.length > 0)
|
|
3271
3473
|
return candidate;
|
|
3272
3474
|
}
|
|
@@ -3463,17 +3665,17 @@ function schemaIsRequired(schema) {
|
|
|
3463
3665
|
import { Value as Value2 } from "typebox/value";
|
|
3464
3666
|
function validateInputs(schema, inputs) {
|
|
3465
3667
|
const errors = [];
|
|
3466
|
-
for (const
|
|
3467
|
-
if (!(
|
|
3468
|
-
errors.push({ key
|
|
3668
|
+
for (const key of Object.keys(inputs)) {
|
|
3669
|
+
if (!(key in schema)) {
|
|
3670
|
+
errors.push({ key, reason: "unknown input key (not declared by this workflow)" });
|
|
3469
3671
|
}
|
|
3470
3672
|
}
|
|
3471
|
-
for (const [
|
|
3472
|
-
const value = inputs[
|
|
3673
|
+
for (const [key, def] of Object.entries(schema)) {
|
|
3674
|
+
const value = inputs[key];
|
|
3473
3675
|
let hasTypeError = false;
|
|
3474
3676
|
if (value === undefined) {
|
|
3475
3677
|
if (schemaIsRequired(def)) {
|
|
3476
|
-
errors.push({ key
|
|
3678
|
+
errors.push({ key, reason: "required input is missing" });
|
|
3477
3679
|
}
|
|
3478
3680
|
continue;
|
|
3479
3681
|
}
|
|
@@ -3481,25 +3683,25 @@ function validateInputs(schema, inputs) {
|
|
|
3481
3683
|
switch (kind) {
|
|
3482
3684
|
case "text":
|
|
3483
3685
|
if (typeof value !== "string") {
|
|
3484
|
-
errors.push({ key
|
|
3686
|
+
errors.push({ key, reason: `expected string, got ${workflowSerializableTypeName(value)}` });
|
|
3485
3687
|
hasTypeError = true;
|
|
3486
3688
|
}
|
|
3487
3689
|
break;
|
|
3488
3690
|
case "number":
|
|
3489
3691
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
3490
|
-
errors.push({ key
|
|
3692
|
+
errors.push({ key, reason: `expected finite number, got ${workflowSerializableTypeName(value)}` });
|
|
3491
3693
|
hasTypeError = true;
|
|
3492
3694
|
}
|
|
3493
3695
|
break;
|
|
3494
3696
|
case "integer":
|
|
3495
3697
|
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
3496
|
-
errors.push({ key
|
|
3698
|
+
errors.push({ key, reason: `expected integer, got ${workflowSerializableTypeName(value)}` });
|
|
3497
3699
|
hasTypeError = true;
|
|
3498
3700
|
}
|
|
3499
3701
|
break;
|
|
3500
3702
|
case "boolean":
|
|
3501
3703
|
if (typeof value !== "boolean") {
|
|
3502
|
-
errors.push({ key
|
|
3704
|
+
errors.push({ key, reason: `expected boolean, got ${workflowSerializableTypeName(value)}` });
|
|
3503
3705
|
hasTypeError = true;
|
|
3504
3706
|
}
|
|
3505
3707
|
break;
|
|
@@ -3507,24 +3709,24 @@ function validateInputs(schema, inputs) {
|
|
|
3507
3709
|
const choices = schemaChoices(def) ?? [];
|
|
3508
3710
|
const allowed = choices.join(", ");
|
|
3509
3711
|
if (typeof value !== "string") {
|
|
3510
|
-
errors.push({ key
|
|
3712
|
+
errors.push({ key, reason: `expected one of [${allowed}], got ${workflowSerializableTypeName(value)}` });
|
|
3511
3713
|
hasTypeError = true;
|
|
3512
3714
|
} else if (!choices.includes(value)) {
|
|
3513
|
-
errors.push({ key
|
|
3715
|
+
errors.push({ key, reason: `must be one of [${allowed}]` });
|
|
3514
3716
|
}
|
|
3515
3717
|
break;
|
|
3516
3718
|
}
|
|
3517
3719
|
default:
|
|
3518
3720
|
if (!Value2.Check(def, value)) {
|
|
3519
3721
|
const first = [...Value2.Errors(def, value)][0];
|
|
3520
|
-
errors.push({ key
|
|
3722
|
+
errors.push({ key, reason: first === undefined ? `does not match ${kind} schema` : first.message });
|
|
3521
3723
|
hasTypeError = true;
|
|
3522
3724
|
}
|
|
3523
3725
|
break;
|
|
3524
3726
|
}
|
|
3525
|
-
const serializableError = hasTypeError ? undefined : workflowSerializableValidationError(value, `input "${
|
|
3727
|
+
const serializableError = hasTypeError ? undefined : workflowSerializableValidationError(value, `input "${key}"`);
|
|
3526
3728
|
if (serializableError !== undefined) {
|
|
3527
|
-
errors.push({ key
|
|
3729
|
+
errors.push({ key, reason: serializableError.replace(/^input "[^"]+" /, "") });
|
|
3528
3730
|
}
|
|
3529
3731
|
}
|
|
3530
3732
|
return errors;
|
|
@@ -3533,18 +3735,19 @@ function validateInputs(schema, inputs) {
|
|
|
3533
3735
|
// dist/builtin/workflows/src/runs/foreground/executor-inputs.ts
|
|
3534
3736
|
function resolveInputs(schema, provided) {
|
|
3535
3737
|
const resolved = {};
|
|
3536
|
-
for (const [
|
|
3738
|
+
for (const [key, value] of Object.entries(provided)) {
|
|
3537
3739
|
if (value !== undefined)
|
|
3538
|
-
resolved[
|
|
3740
|
+
resolved[key] = value;
|
|
3539
3741
|
}
|
|
3540
|
-
const
|
|
3541
|
-
|
|
3742
|
+
const ownedInputs = Value3.Clone(resolved);
|
|
3743
|
+
const withDefaults = Value3.Default(Type2.Object(schema, { additionalProperties: true }), ownedInputs);
|
|
3744
|
+
for (const [key, value] of Object.entries(withDefaults)) {
|
|
3542
3745
|
if (value !== undefined)
|
|
3543
|
-
resolved[
|
|
3746
|
+
resolved[key] = value;
|
|
3544
3747
|
}
|
|
3545
|
-
for (const [
|
|
3546
|
-
if (schemaIsRequired(schemaDef) && resolved[
|
|
3547
|
-
throw new TypeError(`atomic-workflows: required input "${
|
|
3748
|
+
for (const [key, schemaDef] of Object.entries(schema)) {
|
|
3749
|
+
if (schemaIsRequired(schemaDef) && resolved[key] === undefined) {
|
|
3750
|
+
throw new TypeError(`atomic-workflows: required input "${key}" not provided`);
|
|
3548
3751
|
}
|
|
3549
3752
|
}
|
|
3550
3753
|
return resolved;
|
|
@@ -3590,12 +3793,12 @@ ${formatValidationErrors(errors)}`);
|
|
|
3590
3793
|
function asRecord(value) {
|
|
3591
3794
|
return value !== null && typeof value === "object" ? value : undefined;
|
|
3592
3795
|
}
|
|
3593
|
-
function field(value,
|
|
3594
|
-
return asRecord(value)?.[
|
|
3796
|
+
function field(value, key) {
|
|
3797
|
+
return asRecord(value)?.[key];
|
|
3595
3798
|
}
|
|
3596
|
-
function safeField(value,
|
|
3799
|
+
function safeField(value, key) {
|
|
3597
3800
|
try {
|
|
3598
|
-
return field(value,
|
|
3801
|
+
return field(value, key);
|
|
3599
3802
|
} catch {
|
|
3600
3803
|
return;
|
|
3601
3804
|
}
|
|
@@ -3625,8 +3828,8 @@ function findProcessFailureError(value, seen, depth) {
|
|
|
3625
3828
|
return value;
|
|
3626
3829
|
if (nonEmptyProcessOutput(safeField(value, "stderr")))
|
|
3627
3830
|
return value;
|
|
3628
|
-
for (const
|
|
3629
|
-
const selected = findProcessFailureError(safeField(value,
|
|
3831
|
+
for (const key of ["cause", "error", "response", "body"]) {
|
|
3832
|
+
const selected = findProcessFailureError(safeField(value, key), seen, depth + 1);
|
|
3630
3833
|
if (selected !== undefined)
|
|
3631
3834
|
return selected;
|
|
3632
3835
|
}
|
|
@@ -3654,8 +3857,8 @@ function selectProcessFailureError(error) {
|
|
|
3654
3857
|
function hasProcessFailureEvidence(error) {
|
|
3655
3858
|
return findProcessFailureError(error, new Set, 0) !== undefined;
|
|
3656
3859
|
}
|
|
3657
|
-
function stringField2(value,
|
|
3658
|
-
const raw = field(value,
|
|
3860
|
+
function stringField2(value, key) {
|
|
3861
|
+
const raw = field(value, key);
|
|
3659
3862
|
return typeof raw === "string" && raw.length > 0 ? raw : undefined;
|
|
3660
3863
|
}
|
|
3661
3864
|
function errorMessage(error) {
|
|
@@ -3837,15 +4040,15 @@ function redactSensitiveText(value) {
|
|
|
3837
4040
|
var TOOL_FAILURE_TEXT_LIMIT_BYTES = 16384;
|
|
3838
4041
|
var TRUNCATION_PREFIX = `[workflow tool output truncated; showing final bytes]
|
|
3839
4042
|
`;
|
|
3840
|
-
function safeField2(error,
|
|
4043
|
+
function safeField2(error, key) {
|
|
3841
4044
|
try {
|
|
3842
|
-
return field(error,
|
|
4045
|
+
return field(error, key);
|
|
3843
4046
|
} catch {
|
|
3844
4047
|
return;
|
|
3845
4048
|
}
|
|
3846
4049
|
}
|
|
3847
|
-
function exposedText(error,
|
|
3848
|
-
const value = safeField2(error,
|
|
4050
|
+
function exposedText(error, key) {
|
|
4051
|
+
const value = safeField2(error, key);
|
|
3849
4052
|
if (typeof value === "string")
|
|
3850
4053
|
return value;
|
|
3851
4054
|
try {
|
|
@@ -3954,7 +4157,7 @@ function canonicalJsonString(value) {
|
|
|
3954
4157
|
return `[${value.map(canonicalJsonString).join(",")}]`;
|
|
3955
4158
|
const object = value;
|
|
3956
4159
|
const keys = Object.keys(object).sort();
|
|
3957
|
-
return `{${keys.map((
|
|
4160
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJsonString(object[key])}`).join(",")}}`;
|
|
3958
4161
|
}
|
|
3959
4162
|
// dist/builtin/workflows/src/durable/backend.ts
|
|
3960
4163
|
function pendingStageMessagesForDurableRun(backend, logicalRunId, rootWorkflowId = logicalRunId) {
|
|
@@ -3993,13 +4196,13 @@ function cloneWorkflowChildReplaySnapshot(snapshot) {
|
|
|
3993
4196
|
}
|
|
3994
4197
|
function workflowChildReplaySnapshot(alias, childResult) {
|
|
3995
4198
|
const outputs = {};
|
|
3996
|
-
for (const [
|
|
4199
|
+
for (const [key, value] of Object.entries(childResult.outputs)) {
|
|
3997
4200
|
if (value === undefined)
|
|
3998
4201
|
continue;
|
|
3999
4202
|
try {
|
|
4000
|
-
outputs[
|
|
4203
|
+
outputs[key] = cloneWorkflowChildValue(value);
|
|
4001
4204
|
} catch (err) {
|
|
4002
|
-
throw new Error(`atomic-workflows: child workflow "${alias}" (${childResult.workflow}) exposed output "${
|
|
4205
|
+
throw new Error(`atomic-workflows: child workflow "${alias}" (${childResult.workflow}) exposed output "${key}" is not serializable for continuation replay: ${workflowChildSerializationMessage(err)}`, { cause: err });
|
|
4003
4206
|
}
|
|
4004
4207
|
}
|
|
4005
4208
|
const exitReason = childResult.exited === true ? childResult.exitReason : undefined;
|
|
@@ -4148,10 +4351,10 @@ function durableStageGroupKey(stage, stages = [stage]) {
|
|
|
4148
4351
|
function groupByDurableStageKey(stages) {
|
|
4149
4352
|
const groups = new Map;
|
|
4150
4353
|
for (const stage of stages) {
|
|
4151
|
-
const
|
|
4152
|
-
const group = groups.get(
|
|
4354
|
+
const key = durableStageGroupKey(stage, stages);
|
|
4355
|
+
const group = groups.get(key) ?? [];
|
|
4153
4356
|
group.push(stage);
|
|
4154
|
-
groups.set(
|
|
4357
|
+
groups.set(key, group);
|
|
4155
4358
|
}
|
|
4156
4359
|
return groups;
|
|
4157
4360
|
}
|
|
@@ -4193,13 +4396,13 @@ function hasCycle(topologies) {
|
|
|
4193
4396
|
function parseWorkflowChildResult(value) {
|
|
4194
4397
|
if (!isOrdinaryObject(value))
|
|
4195
4398
|
return;
|
|
4196
|
-
const
|
|
4399
|
+
const workflow = value.workflow;
|
|
4197
4400
|
const runId = value.runId;
|
|
4198
4401
|
const status = value.status;
|
|
4199
4402
|
const exited = value.exited;
|
|
4200
4403
|
const outputs = value.outputs;
|
|
4201
4404
|
const exitReason = value.exitReason;
|
|
4202
|
-
if (typeof
|
|
4405
|
+
if (typeof workflow !== "string" || typeof runId !== "string" || !isOrdinaryObject(outputs))
|
|
4203
4406
|
return;
|
|
4204
4407
|
if (exited === false) {
|
|
4205
4408
|
if (status !== "completed" || exitReason !== undefined)
|
|
@@ -4628,6 +4831,7 @@ function durableStageCheckpointMetadata(stage, run, sourceOrder) {
|
|
|
4628
4831
|
...stage.sessionFile !== undefined ? { sessionFile: stage.sessionFile } : {},
|
|
4629
4832
|
...stage.durationMs !== undefined ? { durationMs: stage.durationMs } : {},
|
|
4630
4833
|
...stage.model !== undefined ? { model: stage.model } : {},
|
|
4834
|
+
...stage.thinkingLevel !== undefined ? { thinkingLevel: stage.thinkingLevel } : {},
|
|
4631
4835
|
...stage.attemptedModels !== undefined ? { attemptedModels: [...stage.attemptedModels] } : {},
|
|
4632
4836
|
...stage.modelAttempts !== undefined ? { modelAttempts: [...stage.modelAttempts] } : {},
|
|
4633
4837
|
...stage.structured !== undefined ? { structured: stage.structured } : {},
|
|
@@ -4637,7 +4841,7 @@ function durableStageCheckpointMetadata(stage, run, sourceOrder) {
|
|
|
4637
4841
|
}
|
|
4638
4842
|
|
|
4639
4843
|
// dist/builtin/workflows/src/durable/tool-primitive.ts
|
|
4640
|
-
import { runCallback } from "@bastani/atomic";
|
|
4844
|
+
import { collectAgentTasks, runCallback } from "@bastani/atomic";
|
|
4641
4845
|
|
|
4642
4846
|
// dist/builtin/workflows/src/engine/workflow-tool-abort.ts
|
|
4643
4847
|
class WorkflowToolAbortError extends Error {
|
|
@@ -4767,6 +4971,58 @@ function captureCallbackSource(fn) {
|
|
|
4767
4971
|
return;
|
|
4768
4972
|
}
|
|
4769
4973
|
}
|
|
4974
|
+
async function awaitTerminalTask(task) {
|
|
4975
|
+
for (;; ) {
|
|
4976
|
+
const observed = await task.host.waitForTask(task.taskId);
|
|
4977
|
+
if (!observed.ok)
|
|
4978
|
+
throw new Error(`${observed.error.code}: ${observed.error.message}`);
|
|
4979
|
+
if (observed.value.kind === "settled")
|
|
4980
|
+
return observed.value.result;
|
|
4981
|
+
}
|
|
4982
|
+
}
|
|
4983
|
+
function replaceTaskObservations(value, terminal) {
|
|
4984
|
+
if (!value || typeof value !== "object")
|
|
4985
|
+
return value;
|
|
4986
|
+
if (Array.isArray(value)) {
|
|
4987
|
+
const next = value.map((item) => replaceTaskObservations(item, terminal));
|
|
4988
|
+
return next.some((item, index) => item !== value[index]) ? next : value;
|
|
4989
|
+
}
|
|
4990
|
+
const object = value;
|
|
4991
|
+
if (object.kind === "yielded" && typeof object.taskId === "string") {
|
|
4992
|
+
const result = terminal.get(object.taskId);
|
|
4993
|
+
if (result)
|
|
4994
|
+
return { kind: "settled", taskId: object.taskId, result };
|
|
4995
|
+
}
|
|
4996
|
+
let changed = false;
|
|
4997
|
+
const next = {};
|
|
4998
|
+
for (const [key, item] of Object.entries(object)) {
|
|
4999
|
+
next[key] = replaceTaskObservations(item, terminal);
|
|
5000
|
+
changed ||= next[key] !== item;
|
|
5001
|
+
}
|
|
5002
|
+
if (changed && next.details !== object.details && next.details && typeof next.details === "object" && !Array.isArray(next.details) && Array.isArray(object.content)) {
|
|
5003
|
+
const details = next.details;
|
|
5004
|
+
const original = object.details;
|
|
5005
|
+
if (details.taskResponse !== undefined && details.taskResponse !== original.taskResponse) {
|
|
5006
|
+
const before = JSON.stringify(original.taskResponse);
|
|
5007
|
+
next.content = object.content.map((part) => {
|
|
5008
|
+
if (!part || typeof part !== "object" || Array.isArray(part))
|
|
5009
|
+
return part;
|
|
5010
|
+
const content = part;
|
|
5011
|
+
return content.type === "text" && content.text === before ? { ...content, text: JSON.stringify(details.taskResponse) } : part;
|
|
5012
|
+
});
|
|
5013
|
+
}
|
|
5014
|
+
}
|
|
5015
|
+
return changed ? next : value;
|
|
5016
|
+
}
|
|
5017
|
+
function invokeTaskCallback(fn, signal) {
|
|
5018
|
+
return collectAgentTasks(signal, () => fn({ signal }), async (value, tasks) => {
|
|
5019
|
+
if (tasks.length === 0)
|
|
5020
|
+
return value;
|
|
5021
|
+
const terminal = new Map;
|
|
5022
|
+
await Promise.all(tasks.map(async (task) => terminal.set(task.taskId, await awaitTerminalTask(task))));
|
|
5023
|
+
return replaceTaskObservations(value, terminal);
|
|
5024
|
+
});
|
|
5025
|
+
}
|
|
4770
5026
|
function createToolPrimitive(input) {
|
|
4771
5027
|
const ordinals = new Map;
|
|
4772
5028
|
return (name, args, fn, options) => {
|
|
@@ -4883,11 +5139,11 @@ async function executeToolInvocation(input, ordinals, name, args, fn, options, c
|
|
|
4883
5139
|
control.noteCancelled();
|
|
4884
5140
|
else
|
|
4885
5141
|
input.onFailureObserved?.(error, node.id);
|
|
4886
|
-
const
|
|
5142
|
+
const endedAt = Date.now();
|
|
4887
5143
|
input.onNodeEnd?.(node.id, {
|
|
4888
5144
|
status: cancelled ? "cancelled" : "failed",
|
|
4889
|
-
endedAt
|
|
4890
|
-
...node.startedAt !== undefined ? { durationMs: Math.max(0,
|
|
5145
|
+
endedAt,
|
|
5146
|
+
...node.startedAt !== undefined ? { durationMs: Math.max(0, endedAt - node.startedAt) } : {},
|
|
4891
5147
|
error: error instanceof Error ? error.message : String(error)
|
|
4892
5148
|
});
|
|
4893
5149
|
input.onNodeSettle?.(node.id);
|
|
@@ -4942,7 +5198,7 @@ async function executeTimedToolAttempt(toolName, runId, fn, baseSignal, timeoutM
|
|
|
4942
5198
|
const timeoutController = new AbortController;
|
|
4943
5199
|
const attemptSignal = AbortSignal.any([baseSignal, timeoutController.signal]);
|
|
4944
5200
|
return runCallback({ kind: "workflow.ctx_tool", name: toolName, runId }, async () => {
|
|
4945
|
-
const callbackResult = Promise.resolve().then(() => fn
|
|
5201
|
+
const callbackResult = Promise.resolve().then(() => invokeTaskCallback(fn, attemptSignal)).then((value) => ({ kind: "value", value }), (error) => ({ kind: "error", error }));
|
|
4946
5202
|
let cancelDeadline;
|
|
4947
5203
|
let onAbort;
|
|
4948
5204
|
let timeoutError;
|
|
@@ -4997,7 +5253,7 @@ async function executeLiveToolInvocation(live) {
|
|
|
4997
5253
|
try {
|
|
4998
5254
|
const result = await executeWithRetries(() => {
|
|
4999
5255
|
attempts += 1;
|
|
5000
|
-
const callback = options?.timeoutMs === undefined ? runCallback({ kind: "workflow.ctx_tool", name, runId: input.workflowId }, () => fn
|
|
5256
|
+
const callback = options?.timeoutMs === undefined ? runCallback({ kind: "workflow.ctx_tool", name, runId: input.workflowId }, () => invokeTaskCallback(fn, toolSignal)) : executeTimedToolAttempt(name, input.workflowId, fn, toolSignal, options.timeoutMs);
|
|
5001
5257
|
return callback.catch((error) => {
|
|
5002
5258
|
callbackError = error;
|
|
5003
5259
|
throw error;
|
|
@@ -5060,12 +5316,12 @@ async function executeLiveToolInvocation(live) {
|
|
|
5060
5316
|
const callbackFailure = callbackError ?? error;
|
|
5061
5317
|
if (returnFailure && !callbackCompleted && isExplicitCallbackCancellation(callbackFailure)) {
|
|
5062
5318
|
input.onFailureObserved?.(callbackFailure, node.id);
|
|
5063
|
-
const
|
|
5319
|
+
const failure = await recordThrowingToolFailure(input, node, { name, args, ...source !== undefined ? { source } : {}, argsHash, ordinal, startedAt }, callbackFailure, attempts);
|
|
5064
5320
|
input.onNodeEnd?.(node.id, {
|
|
5065
5321
|
status: "failed",
|
|
5066
|
-
endedAt:
|
|
5067
|
-
durationMs: Math.max(0,
|
|
5068
|
-
error:
|
|
5322
|
+
endedAt: failure.failedAt,
|
|
5323
|
+
durationMs: Math.max(0, failure.failedAt - startedAt),
|
|
5324
|
+
error: failure.message
|
|
5069
5325
|
});
|
|
5070
5326
|
input.onNodeSettle?.(node.id);
|
|
5071
5327
|
throw callbackFailure;
|
|
@@ -5123,12 +5379,12 @@ async function executeLiveToolInvocation(live) {
|
|
|
5123
5379
|
}
|
|
5124
5380
|
const reportedFailure = timeoutFailure ? callbackError : error;
|
|
5125
5381
|
input.onFailureObserved?.(reportedFailure, node.id);
|
|
5126
|
-
const
|
|
5382
|
+
const failure = await recordThrowingToolFailure(input, node, { name, args, ...source !== undefined ? { source } : {}, argsHash, ordinal, startedAt }, reportedFailure, attempts);
|
|
5127
5383
|
input.onNodeEnd?.(node.id, {
|
|
5128
5384
|
status: "failed",
|
|
5129
|
-
endedAt:
|
|
5130
|
-
durationMs: Math.max(0,
|
|
5131
|
-
error:
|
|
5385
|
+
endedAt: failure.failedAt,
|
|
5386
|
+
durationMs: Math.max(0, failure.failedAt - startedAt),
|
|
5387
|
+
error: failure.message
|
|
5132
5388
|
});
|
|
5133
5389
|
input.onNodeSettle?.(node.id);
|
|
5134
5390
|
throw reportedFailure;
|
|
@@ -5184,9 +5440,9 @@ var CALLBACK_CANCELLATION_CODES = new Set([
|
|
|
5184
5440
|
"err_cancelled"
|
|
5185
5441
|
]);
|
|
5186
5442
|
var CALLBACK_CANCELLATION_STOP_REASONS = new Set(["aborted", "canceled", "cancelled"]);
|
|
5187
|
-
function safeCancellationField(error,
|
|
5443
|
+
function safeCancellationField(error, key) {
|
|
5188
5444
|
try {
|
|
5189
|
-
return field(error,
|
|
5445
|
+
return field(error, key);
|
|
5190
5446
|
} catch {
|
|
5191
5447
|
return;
|
|
5192
5448
|
}
|
|
@@ -5213,16 +5469,16 @@ function isExplicitCallbackCancellation(error) {
|
|
|
5213
5469
|
return true;
|
|
5214
5470
|
if (!hasProcessFailure && hasCancellationMarker(CALLBACK_CANCELLATION_CODES, safeCancellationField(current.value, "code")))
|
|
5215
5471
|
return true;
|
|
5216
|
-
for (const
|
|
5217
|
-
pending.push({ value: safeCancellationField(current.value,
|
|
5472
|
+
for (const key of ["cause", "error", "response", "body"]) {
|
|
5473
|
+
pending.push({ value: safeCancellationField(current.value, key), depth: current.depth + 1 });
|
|
5218
5474
|
}
|
|
5219
|
-
for (const
|
|
5220
|
-
const entries = safeCancellationField(current.value,
|
|
5475
|
+
for (const key of ["diagnostics", "errors"]) {
|
|
5476
|
+
const entries = safeCancellationField(current.value, key);
|
|
5221
5477
|
if (!Array.isArray(entries))
|
|
5222
5478
|
continue;
|
|
5223
5479
|
for (const entry of entries) {
|
|
5224
5480
|
pending.push({
|
|
5225
|
-
value:
|
|
5481
|
+
value: key === "diagnostics" ? safeCancellationField(entry, "error") ?? entry : entry,
|
|
5226
5482
|
depth: current.depth + 1
|
|
5227
5483
|
});
|
|
5228
5484
|
}
|
|
@@ -5553,6 +5809,7 @@ function completeTaskResult(name, base, checkpoint) {
|
|
|
5553
5809
|
...base.sessionFile !== undefined || checkpoint.sessionFile !== undefined ? { sessionFile: base.sessionFile ?? checkpoint.sessionFile } : {},
|
|
5554
5810
|
...base.artifacts !== undefined || checkpoint.artifacts !== undefined ? { artifacts: [...base.artifacts ?? checkpoint.artifacts ?? []] } : {},
|
|
5555
5811
|
...base.model !== undefined || checkpoint.model !== undefined ? { model: base.model ?? checkpoint.model } : {},
|
|
5812
|
+
...base.thinkingLevel !== undefined || checkpoint.thinkingLevel !== undefined ? { thinkingLevel: base.thinkingLevel ?? checkpoint.thinkingLevel } : {},
|
|
5556
5813
|
...base.attemptedModels !== undefined || checkpoint.attemptedModels !== undefined ? { attemptedModels: [...base.attemptedModels ?? checkpoint.attemptedModels ?? []] } : {},
|
|
5557
5814
|
...base.modelAttempts !== undefined || checkpoint.modelAttempts !== undefined ? { modelAttempts: [...base.modelAttempts ?? checkpoint.modelAttempts ?? []] } : {},
|
|
5558
5815
|
...base.warnings !== undefined || checkpoint.warnings !== undefined ? { warnings: [...base.warnings ?? checkpoint.warnings ?? []] } : {}
|
|
@@ -5653,6 +5910,7 @@ function taskCheckpointMetadata(result) {
|
|
|
5653
5910
|
...result.sessionId !== undefined ? { sessionId: result.sessionId } : {},
|
|
5654
5911
|
...result.sessionFile !== undefined ? { sessionFile: result.sessionFile } : {},
|
|
5655
5912
|
...result.model !== undefined ? { model: result.model } : {},
|
|
5913
|
+
...result.thinkingLevel !== undefined ? { thinkingLevel: result.thinkingLevel } : {},
|
|
5656
5914
|
...result.attemptedModels !== undefined ? { attemptedModels: [...result.attemptedModels] } : {},
|
|
5657
5915
|
...result.modelAttempts !== undefined ? { modelAttempts: [...result.modelAttempts] } : {},
|
|
5658
5916
|
...result.structured !== undefined ? { structured: result.structured } : {},
|
|
@@ -5682,6 +5940,7 @@ function mergeCheckpointHydrationMetadata(replayValueCheckpoint, checkpoints) {
|
|
|
5682
5940
|
...replayValueCheckpoint.sessionId === undefined ? metadataValue(checkpoints, "sessionId") : {},
|
|
5683
5941
|
...replayValueCheckpoint.sessionFile === undefined ? metadataValue(checkpoints, "sessionFile") : {},
|
|
5684
5942
|
...replayValueCheckpoint.model === undefined ? metadataValue(checkpoints, "model") : {},
|
|
5943
|
+
...replayValueCheckpoint.thinkingLevel === undefined ? metadataValue(checkpoints, "thinkingLevel") : {},
|
|
5685
5944
|
...replayValueCheckpoint.attemptedModels === undefined ? metadataValue(checkpoints, "attemptedModels") : {},
|
|
5686
5945
|
...replayValueCheckpoint.modelAttempts === undefined ? metadataValue(checkpoints, "modelAttempts") : {},
|
|
5687
5946
|
...replayValueCheckpoint.structured === undefined ? metadataValue(checkpoints, "structured") : {},
|
|
@@ -5702,11 +5961,11 @@ function preferredHydrationTopology(replayValueCheckpoint, checkpoints) {
|
|
|
5702
5961
|
}
|
|
5703
5962
|
return replayValueCheckpoint.topology === undefined ? metadataValue(checkpoints, "topology") : {};
|
|
5704
5963
|
}
|
|
5705
|
-
function metadataValue(checkpoints,
|
|
5964
|
+
function metadataValue(checkpoints, key) {
|
|
5706
5965
|
for (let index = checkpoints.length - 1;index >= 0; index -= 1) {
|
|
5707
|
-
const value = checkpoints[index]?.[
|
|
5966
|
+
const value = checkpoints[index]?.[key];
|
|
5708
5967
|
if (value !== undefined)
|
|
5709
|
-
return { [
|
|
5968
|
+
return { [key]: value };
|
|
5710
5969
|
}
|
|
5711
5970
|
return {};
|
|
5712
5971
|
}
|
|
@@ -5741,7 +6000,7 @@ function stageMetadataCheckpointId(replayKey, stage) {
|
|
|
5741
6000
|
result: stage.result ?? ""
|
|
5742
6001
|
})}`;
|
|
5743
6002
|
}
|
|
5744
|
-
function recordCachedStageIntoStore(
|
|
6003
|
+
function recordCachedStageIntoStore(store, runId, name, replayKey, output, completedStageReplayKeys, parentIds, checkpoint) {
|
|
5745
6004
|
const now = Date.now();
|
|
5746
6005
|
const sourceStageId = checkpoint?.topology?.run?.runId === runId ? checkpoint.topology.stageId : undefined;
|
|
5747
6006
|
const stageId = sourceStageId ?? cachedStageId(runId, replayKey);
|
|
@@ -5771,22 +6030,23 @@ function recordCachedStageIntoStore(store2, runId, name, replayKey, output, comp
|
|
|
5771
6030
|
...checkpoint?.sessionId !== undefined ? { sessionId: checkpoint.sessionId } : {},
|
|
5772
6031
|
...checkpoint?.sessionFile !== undefined ? { sessionFile: checkpoint.sessionFile } : {},
|
|
5773
6032
|
...checkpoint?.model !== undefined ? { model: checkpoint.model } : {},
|
|
6033
|
+
...checkpoint?.thinkingLevel !== undefined ? { thinkingLevel: checkpoint.thinkingLevel } : {},
|
|
5774
6034
|
...checkpoint?.attemptedModels !== undefined ? { attemptedModels: checkpoint.attemptedModels } : {},
|
|
5775
6035
|
...checkpoint?.modelAttempts !== undefined ? { modelAttempts: checkpoint.modelAttempts } : {},
|
|
5776
6036
|
...checkpoint?.structured !== undefined ? { structured: checkpoint.structured } : {},
|
|
5777
6037
|
...checkpoint?.artifacts !== undefined ? { artifacts: checkpoint.artifacts } : {},
|
|
5778
6038
|
...checkpoint?.warnings !== undefined ? { warnings: checkpoint.warnings } : {}
|
|
5779
6039
|
};
|
|
5780
|
-
|
|
5781
|
-
|
|
6040
|
+
store.recordStageStart(runId, snapshot);
|
|
6041
|
+
store.recordStageEnd(runId, snapshot);
|
|
5782
6042
|
completedStageReplayKeys.set(stageId, replayKey);
|
|
5783
6043
|
}
|
|
5784
|
-
function recordCachedStageWithTracker(
|
|
6044
|
+
function recordCachedStageWithTracker(store, tracker, runId, name, replayKey, checkpoint, completedStageReplayKeys, stageFailFastScope, sourceToReplayedNodeIds) {
|
|
5785
6045
|
const sourceStageId = checkpoint.topology?.run?.runId === runId ? checkpoint.topology.stageId : undefined;
|
|
5786
6046
|
const stageId = sourceStageId ?? cachedStageId(runId, replayKey);
|
|
5787
6047
|
let parentIds = tracker.onSpawn(stageId, name);
|
|
5788
6048
|
const sourceParents = sourceStageId === undefined ? undefined : checkpoint.topology?.parentIds;
|
|
5789
|
-
const run =
|
|
6049
|
+
const run = store.runs().find((candidate) => candidate.id === runId);
|
|
5790
6050
|
const restored = sourceParents?.map((sourceId) => sourceToReplayedNodeIds?.get(sourceId) ?? run?.stages.find((stage) => stage.id === sourceId || stage.replayedFromStageId === sourceId)?.id);
|
|
5791
6051
|
if (restored?.every((id) => id !== undefined)) {
|
|
5792
6052
|
parentIds = restored;
|
|
@@ -5797,7 +6057,7 @@ function recordCachedStageWithTracker(store2, tracker, runId, name, replayKey, c
|
|
|
5797
6057
|
}
|
|
5798
6058
|
if (checkpoint.topology?.run?.runId === runId)
|
|
5799
6059
|
sourceToReplayedNodeIds?.set(checkpoint.topology.stageId, stageId);
|
|
5800
|
-
recordCachedStageIntoStore(
|
|
6060
|
+
recordCachedStageIntoStore(store, runId, name, replayKey, checkpoint.output, completedStageReplayKeys, parentIds, checkpoint);
|
|
5801
6061
|
tracker.onSettle(stageId);
|
|
5802
6062
|
}
|
|
5803
6063
|
function isWorkflowTaskResult(value) {
|
|
@@ -6545,9 +6805,9 @@ function isMemoizedBackendUsable(backend) {
|
|
|
6545
6805
|
return !backend.persistent || dbosLifecycleState() === "ready";
|
|
6546
6806
|
}
|
|
6547
6807
|
function getDurableBackend() {
|
|
6548
|
-
const
|
|
6549
|
-
const memoized =
|
|
6550
|
-
const backend =
|
|
6808
|
+
const owner = getDurableBackendProcessOwner();
|
|
6809
|
+
const memoized = owner.initializedBackend !== undefined && isMemoizedBackendUsable(owner.initializedBackend) ? owner.initializedBackend : undefined;
|
|
6810
|
+
const backend = owner.injectedBackend ?? memoized ?? getReadyDbosBackendSync();
|
|
6551
6811
|
if (backend === undefined)
|
|
6552
6812
|
throw new DbosNotReadyError;
|
|
6553
6813
|
return backend;
|
|
@@ -6580,7 +6840,7 @@ function restoreBudgetState(value) {
|
|
|
6580
6840
|
if (restored !== undefined)
|
|
6581
6841
|
warnings[dimension] = restored;
|
|
6582
6842
|
}
|
|
6583
|
-
const requiredNumbers = (candidate, fields) => isRecord(candidate) && fields.every((
|
|
6843
|
+
const requiredNumbers = (candidate, fields) => isRecord(candidate) && fields.every((field) => numericDuration(candidate[field]) !== undefined);
|
|
6584
6844
|
const accountingValue = value.accounting;
|
|
6585
6845
|
const accounting = isRecord(accountingValue) && requiredNumbers(accountingValue, ["tokens", "cost"]) && requiredNumbers(accountingValue.baseline, ["input", "output", "cacheRead", "cacheWrite", "cost"]) && requiredNumbers(accountingValue.perCounter, ["input", "output", "cacheRead", "cacheWrite"]) ? accountingValue : undefined;
|
|
6586
6846
|
const state = {
|
|
@@ -6812,8 +7072,8 @@ class ScopedDurableBackend {
|
|
|
6812
7072
|
scope
|
|
6813
7073
|
};
|
|
6814
7074
|
}
|
|
6815
|
-
scopeKey(
|
|
6816
|
-
return `${this.scope.scopePrefix}:${
|
|
7075
|
+
scopeKey(key) {
|
|
7076
|
+
return `${this.scope.scopePrefix}:${key}`;
|
|
6817
7077
|
}
|
|
6818
7078
|
remap(checkpoint) {
|
|
6819
7079
|
const workflowId = this.scope.rootWorkflowId;
|
|
@@ -7318,31 +7578,31 @@ function createGitWorktreeSetupCache() {
|
|
|
7318
7578
|
get(options) {
|
|
7319
7579
|
if (disposed)
|
|
7320
7580
|
throw new Error("Git worktree setup cache is already disposed");
|
|
7321
|
-
const
|
|
7322
|
-
const cached = results.get(
|
|
7581
|
+
const key = gitWorktreeSetupCacheKey(options);
|
|
7582
|
+
const cached = results.get(key);
|
|
7323
7583
|
if (cached !== undefined) {
|
|
7324
7584
|
assertCachedGitWorktreeIdentity(cached, options);
|
|
7325
7585
|
return cached.result;
|
|
7326
7586
|
}
|
|
7327
7587
|
const result = setupGitWorktree(options);
|
|
7328
|
-
results.set(
|
|
7588
|
+
results.set(key, { result, identity: captureGitWorktreeIdentity(result) });
|
|
7329
7589
|
return result;
|
|
7330
7590
|
},
|
|
7331
7591
|
dispose() {
|
|
7332
7592
|
if (disposed)
|
|
7333
7593
|
return;
|
|
7334
7594
|
disposed = true;
|
|
7335
|
-
let
|
|
7595
|
+
let firstError;
|
|
7336
7596
|
for (const cached of results.values()) {
|
|
7337
7597
|
try {
|
|
7338
7598
|
cached.identity.generation.dispose();
|
|
7339
7599
|
} catch (error) {
|
|
7340
|
-
|
|
7600
|
+
firstError ??= error instanceof Error ? error : new Error(String(error));
|
|
7341
7601
|
}
|
|
7342
7602
|
}
|
|
7343
7603
|
results.clear();
|
|
7344
|
-
if (
|
|
7345
|
-
throw
|
|
7604
|
+
if (firstError !== undefined)
|
|
7605
|
+
throw firstError;
|
|
7346
7606
|
}
|
|
7347
7607
|
};
|
|
7348
7608
|
}
|
|
@@ -7642,24 +7902,24 @@ function safePatchAgentName(agent) {
|
|
|
7642
7902
|
}
|
|
7643
7903
|
function removeSyntheticPath(worktree, syntheticPath) {
|
|
7644
7904
|
const resolved = path4.resolve(worktree.path, syntheticPath);
|
|
7645
|
-
const
|
|
7646
|
-
if (!
|
|
7905
|
+
const relative = path4.relative(worktree.path, resolved);
|
|
7906
|
+
if (!relative || relative === "." || relative === ".." || relative.startsWith(`..${path4.sep}`) || path4.isAbsolute(relative)) {
|
|
7647
7907
|
return;
|
|
7648
7908
|
}
|
|
7649
|
-
let
|
|
7909
|
+
let stat;
|
|
7650
7910
|
try {
|
|
7651
|
-
|
|
7911
|
+
stat = fs4.lstatSync(resolved);
|
|
7652
7912
|
} catch (error) {
|
|
7653
7913
|
const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
|
|
7654
7914
|
if (code === "ENOENT")
|
|
7655
7915
|
return;
|
|
7656
7916
|
throw error;
|
|
7657
7917
|
}
|
|
7658
|
-
if (
|
|
7918
|
+
if (stat.isSymbolicLink()) {
|
|
7659
7919
|
fs4.unlinkSync(resolved);
|
|
7660
7920
|
return;
|
|
7661
7921
|
}
|
|
7662
|
-
if (
|
|
7922
|
+
if (stat.isDirectory()) {
|
|
7663
7923
|
fs4.rmSync(resolved, { recursive: true, force: true });
|
|
7664
7924
|
return;
|
|
7665
7925
|
}
|
|
@@ -8023,14 +8283,14 @@ function normalizeSyntheticPath(worktreePath, rawPath) {
|
|
|
8023
8283
|
if (path6.isAbsolute(trimmed))
|
|
8024
8284
|
throw new Error(`synthetic path must be relative: ${rawPath}`);
|
|
8025
8285
|
const resolved = path6.resolve(worktreePath, trimmed);
|
|
8026
|
-
const
|
|
8027
|
-
if (!
|
|
8286
|
+
const relative = path6.relative(worktreePath, resolved);
|
|
8287
|
+
if (!relative || relative === ".") {
|
|
8028
8288
|
throw new Error(`synthetic path cannot target the worktree root: ${rawPath}`);
|
|
8029
8289
|
}
|
|
8030
|
-
if (
|
|
8290
|
+
if (relative === ".." || relative.startsWith(`..${path6.sep}`) || path6.isAbsolute(relative)) {
|
|
8031
8291
|
throw new Error(`synthetic path escapes the worktree root: ${rawPath}`);
|
|
8032
8292
|
}
|
|
8033
|
-
return path6.normalize(
|
|
8293
|
+
return path6.normalize(relative);
|
|
8034
8294
|
}
|
|
8035
8295
|
function hasTrackedEntries(worktreePath, relativePath) {
|
|
8036
8296
|
const result = runGit(worktreePath, ["ls-files", "--", relativePath]);
|
|
@@ -8173,15 +8433,15 @@ function cleanupWorktrees(setup) {
|
|
|
8173
8433
|
import { lstatSync as lstatSync4, realpathSync as realpathSync4 } from "node:fs";
|
|
8174
8434
|
import { dirname as dirname6, isAbsolute as isAbsolute5, relative as relative4, resolve as resolve6, sep as sep5 } from "node:path";
|
|
8175
8435
|
function relativePathWithin(root, candidate) {
|
|
8176
|
-
const
|
|
8177
|
-
return
|
|
8436
|
+
const path = relative4(root, candidate);
|
|
8437
|
+
return path === ".." || path.startsWith(`..${sep5}`) || isAbsolute5(path) ? undefined : path;
|
|
8178
8438
|
}
|
|
8179
|
-
function existingRealPath(
|
|
8439
|
+
function existingRealPath(path, description) {
|
|
8180
8440
|
try {
|
|
8181
|
-
return realpathSync4.native(
|
|
8441
|
+
return realpathSync4.native(path);
|
|
8182
8442
|
} catch (error) {
|
|
8183
8443
|
const message = error instanceof Error ? error.message : String(error);
|
|
8184
|
-
throw new Error(`atomic-workflows: cannot resolve ${description} ${
|
|
8444
|
+
throw new Error(`atomic-workflows: cannot resolve ${description} ${path}: ${message}`);
|
|
8185
8445
|
}
|
|
8186
8446
|
}
|
|
8187
8447
|
function resolveWorktreeStageCwd(cwd, setup) {
|
|
@@ -8399,7 +8659,7 @@ function truncateTaskOutput(text, maxOutput) {
|
|
|
8399
8659
|
[workflow output truncated; limits: ${limits.bytes} bytes, ${limits.lines} lines]`;
|
|
8400
8660
|
}
|
|
8401
8661
|
function withoutUndefinedProperties(value) {
|
|
8402
|
-
return Object.fromEntries(Object.entries(value).filter(([,
|
|
8662
|
+
return Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
|
|
8403
8663
|
}
|
|
8404
8664
|
function sharedTaskDefaultsFromOptions(options) {
|
|
8405
8665
|
const {
|
|
@@ -8505,7 +8765,7 @@ async function mapParallelSteps(steps, concurrency, failFast, mapper, onFirstFai
|
|
|
8505
8765
|
if (selectedFailure !== undefined)
|
|
8506
8766
|
throw selectedFailure;
|
|
8507
8767
|
}
|
|
8508
|
-
throw new AggregateError(failures.map((
|
|
8768
|
+
throw new AggregateError(failures.map((failure) => failure.error), `atomic-workflows: ${failures.length} parallel ${failures.length === 1 ? "step" : "steps"} failed`);
|
|
8509
8769
|
}
|
|
8510
8770
|
return results;
|
|
8511
8771
|
}
|
|
@@ -8778,32 +9038,32 @@ function reconcileTerminalRunResult(runId, runSnapshot, activeStore, fallback, o
|
|
|
8778
9038
|
onRunEnd?.(runId, result.status, result.result, result.error, result.exitReason);
|
|
8779
9039
|
return result;
|
|
8780
9040
|
}
|
|
8781
|
-
function applyFailureToStage(stage,
|
|
9041
|
+
function applyFailureToStage(stage, failure) {
|
|
8782
9042
|
stage.status = "failed";
|
|
8783
|
-
stage.error =
|
|
8784
|
-
stage.failureKind =
|
|
8785
|
-
stage.failureCode =
|
|
8786
|
-
stage.failureRecoverability =
|
|
8787
|
-
stage.failureDisposition =
|
|
8788
|
-
stage.retryAfterMs =
|
|
8789
|
-
stage.failureMessage =
|
|
8790
|
-
}
|
|
8791
|
-
function runFailureMetadata(
|
|
9043
|
+
stage.error = failure.userMessage;
|
|
9044
|
+
stage.failureKind = failure.kind;
|
|
9045
|
+
stage.failureCode = failure.code;
|
|
9046
|
+
stage.failureRecoverability = failure.recoverability;
|
|
9047
|
+
stage.failureDisposition = failure.disposition;
|
|
9048
|
+
stage.retryAfterMs = failure.retryAfterMs;
|
|
9049
|
+
stage.failureMessage = failure.message;
|
|
9050
|
+
}
|
|
9051
|
+
function runFailureMetadata(failure, stages) {
|
|
8792
9052
|
const failedStage = stages.find((stage) => stage.status === "failed");
|
|
8793
|
-
const failureKind = failedStage?.failureKind ??
|
|
8794
|
-
const failureCode = failedStage?.failureCode ??
|
|
8795
|
-
const failureRecoverability = failedStage?.failureRecoverability ??
|
|
8796
|
-
const failureDisposition = failedStage?.failureDisposition ??
|
|
8797
|
-
const retryAfterMs = failedStage?.retryAfterMs ??
|
|
9053
|
+
const failureKind = failedStage?.failureKind ?? failure.kind;
|
|
9054
|
+
const failureCode = failedStage?.failureCode ?? failure.code;
|
|
9055
|
+
const failureRecoverability = failedStage?.failureRecoverability ?? failure.recoverability;
|
|
9056
|
+
const failureDisposition = failedStage?.failureDisposition ?? failure.disposition;
|
|
9057
|
+
const retryAfterMs = failedStage?.retryAfterMs ?? failure.retryAfterMs;
|
|
8798
9058
|
return {
|
|
8799
|
-
errorMessage: failedStage?.error ??
|
|
9059
|
+
errorMessage: failedStage?.error ?? failure.userMessage,
|
|
8800
9060
|
failureKind,
|
|
8801
9061
|
...failureCode !== undefined ? { failureCode } : {},
|
|
8802
9062
|
failureRecoverability,
|
|
8803
9063
|
failureDisposition,
|
|
8804
|
-
failureMessage: failedStage?.failureMessage ??
|
|
9064
|
+
failureMessage: failedStage?.failureMessage ?? failure.message,
|
|
8805
9065
|
...failedStage !== undefined ? { failedStageId: failedStage.id } : {},
|
|
8806
|
-
resumable:
|
|
9066
|
+
resumable: failure.resumable,
|
|
8807
9067
|
...retryAfterMs !== undefined ? { retryAfterMs } : {}
|
|
8808
9068
|
};
|
|
8809
9069
|
}
|
|
@@ -8832,17 +9092,17 @@ function runFailureMetadataFromStage(fallbackFailure, stage) {
|
|
|
8832
9092
|
...retryAfterMs !== undefined ? { retryAfterMs } : {}
|
|
8833
9093
|
};
|
|
8834
9094
|
}
|
|
8835
|
-
function runFailureMetadataFromFailure(
|
|
9095
|
+
function runFailureMetadataFromFailure(failure, failedStage) {
|
|
8836
9096
|
return {
|
|
8837
|
-
errorMessage: failedStage?.error ??
|
|
8838
|
-
failureKind:
|
|
8839
|
-
...
|
|
8840
|
-
failureRecoverability:
|
|
8841
|
-
failureDisposition:
|
|
8842
|
-
failureMessage: failedStage?.failureMessage ??
|
|
9097
|
+
errorMessage: failedStage?.error ?? failure.userMessage,
|
|
9098
|
+
failureKind: failure.kind,
|
|
9099
|
+
...failure.code !== undefined ? { failureCode: failure.code } : {},
|
|
9100
|
+
failureRecoverability: failure.recoverability,
|
|
9101
|
+
failureDisposition: failure.disposition,
|
|
9102
|
+
failureMessage: failedStage?.failureMessage ?? failure.message,
|
|
8843
9103
|
...failedStage !== undefined ? { failedStageId: failedStage.id } : {},
|
|
8844
|
-
resumable:
|
|
8845
|
-
...
|
|
9104
|
+
resumable: failure.resumable,
|
|
9105
|
+
...failure.retryAfterMs !== undefined ? { retryAfterMs: failure.retryAfterMs } : {}
|
|
8846
9106
|
};
|
|
8847
9107
|
}
|
|
8848
9108
|
function aggregateInnerFailures(error, classifyFailure) {
|
|
@@ -8856,20 +9116,20 @@ function stageFailureCandidate(stage) {
|
|
|
8856
9116
|
recoverability: stage.failureRecoverability ?? "unknown"
|
|
8857
9117
|
};
|
|
8858
9118
|
}
|
|
8859
|
-
function aggregateFailureCandidate(
|
|
9119
|
+
function aggregateFailureCandidate(failure) {
|
|
8860
9120
|
return {
|
|
8861
9121
|
source: "aggregate",
|
|
8862
|
-
failure
|
|
8863
|
-
disposition:
|
|
8864
|
-
recoverability:
|
|
9122
|
+
failure,
|
|
9123
|
+
disposition: failure.disposition,
|
|
9124
|
+
recoverability: failure.recoverability
|
|
8865
9125
|
};
|
|
8866
9126
|
}
|
|
8867
|
-
function outerFailureCandidate(
|
|
9127
|
+
function outerFailureCandidate(failure) {
|
|
8868
9128
|
return {
|
|
8869
9129
|
source: "outer",
|
|
8870
|
-
failure
|
|
8871
|
-
disposition:
|
|
8872
|
-
recoverability:
|
|
9130
|
+
failure,
|
|
9131
|
+
disposition: failure.disposition,
|
|
9132
|
+
recoverability: failure.recoverability
|
|
8873
9133
|
};
|
|
8874
9134
|
}
|
|
8875
9135
|
function isRecoverableActiveBlockedCandidate(candidate) {
|
|
@@ -8956,24 +9216,24 @@ function stageReplayFields(stage) {
|
|
|
8956
9216
|
};
|
|
8957
9217
|
}
|
|
8958
9218
|
function finalizeKilled(runId, runSnapshot, activeStore, persistence, onRunEnd) {
|
|
8959
|
-
const
|
|
9219
|
+
const errorMessage = "workflow killed";
|
|
8960
9220
|
const metadata = {
|
|
8961
9221
|
failureKind: "cancelled",
|
|
8962
9222
|
failureCode: "cancelled",
|
|
8963
9223
|
failureRecoverability: "non_recoverable",
|
|
8964
9224
|
failureDisposition: "terminal_killed",
|
|
8965
|
-
failureMessage:
|
|
9225
|
+
failureMessage: errorMessage,
|
|
8966
9226
|
resumable: false
|
|
8967
9227
|
};
|
|
8968
|
-
const recorded = activeStore.recordRunEnd(runId, "killed", undefined,
|
|
9228
|
+
const recorded = activeStore.recordRunEnd(runId, "killed", undefined, errorMessage, metadata);
|
|
8969
9229
|
appendRunEndWhenRecorded(persistence, recorded, {
|
|
8970
9230
|
runId,
|
|
8971
9231
|
status: "killed",
|
|
8972
|
-
error:
|
|
9232
|
+
error: errorMessage,
|
|
8973
9233
|
...metadata,
|
|
8974
9234
|
ts: Date.now()
|
|
8975
9235
|
});
|
|
8976
|
-
return reconcileTerminalRunResult(runId, runSnapshot, activeStore, { status: "killed", error:
|
|
9236
|
+
return reconcileTerminalRunResult(runId, runSnapshot, activeStore, { status: "killed", error: errorMessage }, onRunEnd);
|
|
8977
9237
|
}
|
|
8978
9238
|
function finalizeKilledByFailure(runId, runSnapshot, activeStore, persistence, onRunEnd, metadata) {
|
|
8979
9239
|
const recorded = activeStore.recordRunEnd(runId, "killed", undefined, metadata.errorMessage, metadata);
|
|
@@ -9040,32 +9300,32 @@ function recordActiveBlockedFailure(runId, runSnapshot, activeStore, persistence
|
|
|
9040
9300
|
|
|
9041
9301
|
// dist/builtin/workflows/src/runs/foreground/executor-outputs.ts
|
|
9042
9302
|
import { Value as Value5 } from "typebox/value";
|
|
9043
|
-
function hasOwnWorkflowOutput(record,
|
|
9044
|
-
return Object.hasOwn(record,
|
|
9303
|
+
function hasOwnWorkflowOutput(record, key) {
|
|
9304
|
+
return Object.hasOwn(record, key);
|
|
9045
9305
|
}
|
|
9046
9306
|
function assertWorkflowOutputsExplicit(scope, sourceOutput, declarations, missingOutputSuffix = "") {
|
|
9047
|
-
for (const
|
|
9048
|
-
if (!hasOwnWorkflowOutput(declarations,
|
|
9049
|
-
throw new Error(`atomic-workflows: ${scope} returned undeclared output "${
|
|
9307
|
+
for (const key of Object.keys(sourceOutput)) {
|
|
9308
|
+
if (!hasOwnWorkflowOutput(declarations, key)) {
|
|
9309
|
+
throw new Error(`atomic-workflows: ${scope} returned undeclared output "${key}"; declare it in outputs: { "${key}": Type.... } or remove it from the .run() return`);
|
|
9050
9310
|
}
|
|
9051
9311
|
}
|
|
9052
|
-
for (const [
|
|
9053
|
-
if (!(
|
|
9312
|
+
for (const [key, schema] of Object.entries(declarations)) {
|
|
9313
|
+
if (!(key in sourceOutput)) {
|
|
9054
9314
|
if (schemaIsRequired(schema)) {
|
|
9055
|
-
throw new Error(`atomic-workflows: ${scope} missing output "${
|
|
9315
|
+
throw new Error(`atomic-workflows: ${scope} missing output "${key}"${missingOutputSuffix}`);
|
|
9056
9316
|
}
|
|
9057
9317
|
continue;
|
|
9058
9318
|
}
|
|
9059
|
-
const value = sourceOutput[
|
|
9319
|
+
const value = sourceOutput[key];
|
|
9060
9320
|
const kind = schemaFieldKind(schema);
|
|
9061
9321
|
if (!Value5.Check(schema, value)) {
|
|
9062
9322
|
const choices = schemaChoices(schema);
|
|
9063
9323
|
if (kind === "select" && choices !== undefined && typeof value === "string") {
|
|
9064
|
-
throw new Error(`atomic-workflows: ${scope} output "${
|
|
9324
|
+
throw new Error(`atomic-workflows: ${scope} output "${key}" must be one of [${choices.join(", ")}], got ${JSON.stringify(value)}`);
|
|
9065
9325
|
}
|
|
9066
|
-
throw new Error(`atomic-workflows: ${scope} output "${
|
|
9326
|
+
throw new Error(`atomic-workflows: ${scope} output "${key}" expected ${kind}, got ${workflowSerializableTypeName(value)}`);
|
|
9067
9327
|
}
|
|
9068
|
-
const serializableError = workflowSerializableValidationError(value, `${scope} output "${
|
|
9328
|
+
const serializableError = workflowSerializableValidationError(value, `${scope} output "${key}"`);
|
|
9069
9329
|
if (serializableError !== undefined)
|
|
9070
9330
|
throw new Error(`atomic-workflows: ${serializableError}`);
|
|
9071
9331
|
}
|
|
@@ -9098,27 +9358,27 @@ function assertWorkflowExitOutputs(workflowName, result, declaredOutputs) {
|
|
|
9098
9358
|
const declarations = declaredOutputs ?? {};
|
|
9099
9359
|
const sourceOutput = result ?? {};
|
|
9100
9360
|
const scope = `workflow "${workflowName}" ctx.exit()`;
|
|
9101
|
-
for (const
|
|
9102
|
-
if (!hasOwnWorkflowOutput(declarations,
|
|
9103
|
-
throw new Error(`atomic-workflows: ${scope} provided undeclared output "${
|
|
9361
|
+
for (const key of Object.keys(sourceOutput)) {
|
|
9362
|
+
if (!hasOwnWorkflowOutput(declarations, key)) {
|
|
9363
|
+
throw new Error(`atomic-workflows: ${scope} provided undeclared output "${key}"; declare it in outputs: { "${key}": Type.... } or remove it from ctx.exit({ outputs })`);
|
|
9104
9364
|
}
|
|
9105
9365
|
}
|
|
9106
|
-
for (const [
|
|
9107
|
-
if (!(
|
|
9366
|
+
for (const [key, schema] of Object.entries(declarations)) {
|
|
9367
|
+
if (!(key in sourceOutput))
|
|
9108
9368
|
continue;
|
|
9109
|
-
const value = sourceOutput[
|
|
9110
|
-
const invalidSnapshotValue = workflowExitSnapshotInvalidValueMessage(`${scope} output "${
|
|
9369
|
+
const value = sourceOutput[key];
|
|
9370
|
+
const invalidSnapshotValue = workflowExitSnapshotInvalidValueMessage(`${scope} output "${key}"`, value);
|
|
9111
9371
|
if (invalidSnapshotValue !== undefined)
|
|
9112
9372
|
throw new Error(`atomic-workflows: ${invalidSnapshotValue}`);
|
|
9113
9373
|
const kind = schemaFieldKind(schema);
|
|
9114
9374
|
if (!Value5.Check(schema, value)) {
|
|
9115
9375
|
const choices = schemaChoices(schema);
|
|
9116
9376
|
if (kind === "select" && choices !== undefined && typeof value === "string") {
|
|
9117
|
-
throw new Error(`atomic-workflows: ${scope} output "${
|
|
9377
|
+
throw new Error(`atomic-workflows: ${scope} output "${key}" must be one of [${choices.join(", ")}], got ${JSON.stringify(value)}`);
|
|
9118
9378
|
}
|
|
9119
|
-
throw new Error(`atomic-workflows: ${scope} output "${
|
|
9379
|
+
throw new Error(`atomic-workflows: ${scope} output "${key}" expected ${kind}, got ${workflowSerializableTypeName(value)}`);
|
|
9120
9380
|
}
|
|
9121
|
-
const serializableError = workflowSerializableValidationError(value, `${scope} output "${
|
|
9381
|
+
const serializableError = workflowSerializableValidationError(value, `${scope} output "${key}"`);
|
|
9122
9382
|
if (serializableError !== undefined)
|
|
9123
9383
|
throw new Error(`atomic-workflows: ${serializableError}`);
|
|
9124
9384
|
}
|
|
@@ -9127,10 +9387,10 @@ function selectWorkflowOutputs(child, rawOutput) {
|
|
|
9127
9387
|
const declarations = child.outputs ?? {};
|
|
9128
9388
|
const sourceOutput = rawOutput ?? {};
|
|
9129
9389
|
const selected = {};
|
|
9130
|
-
for (const
|
|
9131
|
-
const value = sourceOutput[
|
|
9390
|
+
for (const key of Object.keys(declarations)) {
|
|
9391
|
+
const value = sourceOutput[key];
|
|
9132
9392
|
if (value !== undefined)
|
|
9133
|
-
selected[
|
|
9393
|
+
selected[key] = value;
|
|
9134
9394
|
}
|
|
9135
9395
|
return selected;
|
|
9136
9396
|
}
|
|
@@ -9545,8 +9805,8 @@ function buildPromptNodeUiAdapter(input) {
|
|
|
9545
9805
|
try {
|
|
9546
9806
|
if (mergedSignal.signal.aborted)
|
|
9547
9807
|
throw hilAbortError(mergedSignal.signal);
|
|
9548
|
-
const
|
|
9549
|
-
if (!
|
|
9808
|
+
const accepted = input.activeStore.recordStageAwaitingInput(input.runId, stageId, true, prompt.createdAt);
|
|
9809
|
+
if (!accepted) {
|
|
9550
9810
|
const error = new Error("atomic-workflows: ctx.ui.custom prompt node is unavailable");
|
|
9551
9811
|
stageSnapshot.skippedReason = "prompt-unavailable";
|
|
9552
9812
|
await finalizePromptStage("skipped");
|
|
@@ -9576,15 +9836,15 @@ function buildPromptNodeUiAdapter(input) {
|
|
|
9576
9836
|
mergedSignal.dispose();
|
|
9577
9837
|
}
|
|
9578
9838
|
}
|
|
9579
|
-
const
|
|
9580
|
-
if (!
|
|
9839
|
+
const accepted = input.activeStore.recordStagePendingPrompt(input.runId, stageId, prompt);
|
|
9840
|
+
if (!accepted) {
|
|
9581
9841
|
stageSnapshot.skippedReason = "prompt-unavailable";
|
|
9582
9842
|
await finalizePromptStage("skipped");
|
|
9583
9843
|
return fallbackForPromptDescriptor(descriptor);
|
|
9584
9844
|
}
|
|
9585
9845
|
const waiter = input.activeStore.awaitStagePendingPrompt(input.runId, stageId, prompt.id);
|
|
9586
9846
|
try {
|
|
9587
|
-
const response = await new Promise((
|
|
9847
|
+
const response = await new Promise((resolve, reject) => {
|
|
9588
9848
|
const onAbort = () => {
|
|
9589
9849
|
input.activeStore.resolveStagePendingPrompt(input.runId, stageId, prompt.id, fallbackForPromptDescriptor(descriptor), { recordAnswer: false });
|
|
9590
9850
|
reject(hilAbortError(input.signal));
|
|
@@ -9596,7 +9856,7 @@ function buildPromptNodeUiAdapter(input) {
|
|
|
9596
9856
|
input.signal.addEventListener("abort", onAbort, { once: true });
|
|
9597
9857
|
waiter.then((value) => {
|
|
9598
9858
|
input.signal.removeEventListener("abort", onAbort);
|
|
9599
|
-
|
|
9859
|
+
resolve(value);
|
|
9600
9860
|
}, (err) => {
|
|
9601
9861
|
input.signal.removeEventListener("abort", onAbort);
|
|
9602
9862
|
reject(err);
|
|
@@ -9657,8 +9917,8 @@ function buildPromptNodeUiAdapter(input) {
|
|
|
9657
9917
|
// dist/builtin/workflows/src/runs/foreground/executor-run-finalizers.ts
|
|
9658
9918
|
function createRunFinalizers(input) {
|
|
9659
9919
|
const finalizeWorkflowExitValidationFailure = (err, exitReason) => {
|
|
9660
|
-
const
|
|
9661
|
-
const classifiedMetadata = runFailureMetadata(
|
|
9920
|
+
const failure = input.classifyExecutorFailure(err);
|
|
9921
|
+
const classifiedMetadata = runFailureMetadata(failure, input.runSnapshot.stages);
|
|
9662
9922
|
const metadata = {
|
|
9663
9923
|
...classifiedMetadata,
|
|
9664
9924
|
resumable: false,
|
|
@@ -9723,8 +9983,8 @@ function createRunFinalizers(input) {
|
|
|
9723
9983
|
...signal.reason !== undefined ? { exitReason: signal.reason } : {}
|
|
9724
9984
|
}, input.opts.onRunEnd);
|
|
9725
9985
|
};
|
|
9726
|
-
const finalizeParentWorkflowExitCancellation = async (
|
|
9727
|
-
const parentReason =
|
|
9986
|
+
const finalizeParentWorkflowExitCancellation = async (abortReason) => {
|
|
9987
|
+
const parentReason = abortReason.workflowExitReason;
|
|
9728
9988
|
await input.drainWorkflowExitCleanups(parentReason);
|
|
9729
9989
|
const exitReason = parentWorkflowExitRunReason(parentReason);
|
|
9730
9990
|
const metadata = { resumable: false, exited: true, exitReason };
|
|
@@ -10186,8 +10446,8 @@ class ConcurrencyLimiter {
|
|
|
10186
10446
|
this._running++;
|
|
10187
10447
|
return Promise.resolve();
|
|
10188
10448
|
}
|
|
10189
|
-
return new Promise((
|
|
10190
|
-
this._queue.push(
|
|
10449
|
+
return new Promise((resolve) => {
|
|
10450
|
+
this._queue.push(resolve);
|
|
10191
10451
|
});
|
|
10192
10452
|
}
|
|
10193
10453
|
release() {
|
|
@@ -10208,7 +10468,7 @@ class ConcurrencyLimiter {
|
|
|
10208
10468
|
}
|
|
10209
10469
|
}
|
|
10210
10470
|
function createRunLimiter(defaultConcurrency) {
|
|
10211
|
-
return new ConcurrencyLimiter(defaultConcurrency ??
|
|
10471
|
+
return new ConcurrencyLimiter(defaultConcurrency ?? 3);
|
|
10212
10472
|
}
|
|
10213
10473
|
|
|
10214
10474
|
// dist/builtin/workflows/src/shared/abort.ts
|
|
@@ -10273,11 +10533,11 @@ function createWorkflowExitManager(input) {
|
|
|
10273
10533
|
const trackWorkflowExitCleanup = (operation) => {
|
|
10274
10534
|
if (operation === undefined)
|
|
10275
10535
|
return;
|
|
10276
|
-
let
|
|
10277
|
-
|
|
10278
|
-
workflowExitCleanupPromises.delete(
|
|
10536
|
+
let tracked;
|
|
10537
|
+
tracked = Promise.resolve(operation).catch(() => {}).finally(() => {
|
|
10538
|
+
workflowExitCleanupPromises.delete(tracked);
|
|
10279
10539
|
});
|
|
10280
|
-
workflowExitCleanupPromises.add(
|
|
10540
|
+
workflowExitCleanupPromises.add(tracked);
|
|
10281
10541
|
};
|
|
10282
10542
|
const invokeWorkflowExitCleanup = (cleanup, reason) => {
|
|
10283
10543
|
try {
|
|
@@ -10403,10 +10663,10 @@ function createWorkflowExitManager(input) {
|
|
|
10403
10663
|
};
|
|
10404
10664
|
}
|
|
10405
10665
|
// dist/builtin/workflows/src/engine/primitives/parallel.ts
|
|
10406
|
-
import { randomUUID as
|
|
10666
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
10407
10667
|
|
|
10408
10668
|
// dist/builtin/workflows/src/shared/intercom-group.ts
|
|
10409
|
-
import { randomUUID as
|
|
10669
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
10410
10670
|
var DEFAULT_INTERCOM_GROUP = "default";
|
|
10411
10671
|
function workflowInvocationIntercomGroup(rootRunId) {
|
|
10412
10672
|
return `workflow:${rootRunId}`;
|
|
@@ -10429,22 +10689,22 @@ function resolveStageGroup(stageOptions, workflowGroup) {
|
|
|
10429
10689
|
const group = stageOptions.group;
|
|
10430
10690
|
if (group === undefined)
|
|
10431
10691
|
return workflowGroup;
|
|
10432
|
-
const authored = group === true ?
|
|
10692
|
+
const authored = group === true ? randomUUID3() : group.trim();
|
|
10433
10693
|
if (authored.length === 0)
|
|
10434
10694
|
return;
|
|
10435
10695
|
if (workflowGroup === undefined || authored === DEFAULT_INTERCOM_GROUP)
|
|
10436
10696
|
return authored;
|
|
10437
|
-
const
|
|
10438
|
-
if (authored ===
|
|
10697
|
+
const owner = normalizeGroup(workflowGroup);
|
|
10698
|
+
if (authored === owner || authored.startsWith(`${owner}/`))
|
|
10439
10699
|
return authored;
|
|
10440
|
-
return `${
|
|
10700
|
+
return `${owner}/${authored}`;
|
|
10441
10701
|
}
|
|
10442
10702
|
function workflowInvocationOwnsGroup(workflowGroup, candidate) {
|
|
10443
10703
|
if (workflowGroup === undefined || candidate === undefined)
|
|
10444
10704
|
return false;
|
|
10445
|
-
const
|
|
10705
|
+
const owner = normalizeGroup(workflowGroup);
|
|
10446
10706
|
const group = normalizeGroup(candidate);
|
|
10447
|
-
return group ===
|
|
10707
|
+
return group === owner || group.startsWith(`${owner}/`);
|
|
10448
10708
|
}
|
|
10449
10709
|
function stageHasIntercomAccess(_stageOptions) {
|
|
10450
10710
|
return true;
|
|
@@ -10487,7 +10747,7 @@ function fold_usage(results) {
|
|
|
10487
10747
|
|
|
10488
10748
|
// dist/builtin/workflows/src/shared/budget-meter.ts
|
|
10489
10749
|
var usageFields = ["input", "output", "cacheRead", "cacheWrite", "cost"];
|
|
10490
|
-
var addUsage = (left, right) => Object.fromEntries(usageFields.map((
|
|
10750
|
+
var addUsage = (left, right) => Object.fromEntries(usageFields.map((field) => [field, left[field] + right[field]]));
|
|
10491
10751
|
function foldTreeUsage(tree) {
|
|
10492
10752
|
const run = "run" in tree ? tree.run : tree;
|
|
10493
10753
|
const folded = fold_usage(run.stages.filter((stage) => stage.replayed !== true).map((stage) => ({ stageName: stage.name, text: stage.result ?? "", modelAttempts: stage.modelAttempts })));
|
|
@@ -10499,7 +10759,7 @@ function meter_run(tree, now) {
|
|
|
10499
10759
|
durationMs: elapsedRunMs("run" in tree ? tree.run : tree, now),
|
|
10500
10760
|
tokens: usage.input + usage.output,
|
|
10501
10761
|
cost: usage.cost,
|
|
10502
|
-
perCounter: Object.fromEntries(usageFields.filter((
|
|
10762
|
+
perCounter: Object.fromEntries(usageFields.filter((field) => field !== "cost").map((field) => [field, usage[field]]))
|
|
10503
10763
|
};
|
|
10504
10764
|
}
|
|
10505
10765
|
|
|
@@ -10518,7 +10778,7 @@ class WorkflowBudgetExceededError extends Error {
|
|
|
10518
10778
|
var withFrontier = (report, frontierStage, summary, usage) => Object.assign({ ...report, frontierStage: frontierStage ?? "workflow frontier" }, summary === undefined ? {} : { wrapUpSummary: summary }, usage === undefined ? {} : { wrapUpUsage: usage });
|
|
10519
10779
|
var usageFields2 = ["input", "output", "cacheRead", "cacheWrite", "cost"];
|
|
10520
10780
|
var counterFields = ["input", "output", "cacheRead", "cacheWrite"];
|
|
10521
|
-
var mapFields = (fields, fn = () => 0) => Object.fromEntries(fields.map((
|
|
10781
|
+
var mapFields = (fields, fn = () => 0) => Object.fromEntries(fields.map((field) => [field, fn(field)]));
|
|
10522
10782
|
function createRunBudgetController(input) {
|
|
10523
10783
|
const { run, budget } = input;
|
|
10524
10784
|
const ownEnabled = budget.maxDurationMs > 0 || budget.maxTokens > 0 || budget.maxCost > 0;
|
|
@@ -10529,7 +10789,7 @@ function createRunBudgetController(input) {
|
|
|
10529
10789
|
const previousAccounting = state?.accounting;
|
|
10530
10790
|
const initial = previousAccounting && usageEnabled ? meter_run(input.usageTree?.() ?? { run }, Date.now()) : undefined;
|
|
10531
10791
|
const initialAccounting = initial === undefined ? undefined : { ...initial.perCounter, cost: initial.cost };
|
|
10532
|
-
let baseline = mapFields(usageFields2, (
|
|
10792
|
+
let baseline = mapFields(usageFields2, (field) => initialAccounting?.[field] ?? 0);
|
|
10533
10793
|
let charged = {
|
|
10534
10794
|
baseline,
|
|
10535
10795
|
tokens: previousAccounting?.tokens ?? 0,
|
|
@@ -10547,13 +10807,13 @@ function createRunBudgetController(input) {
|
|
|
10547
10807
|
};
|
|
10548
10808
|
const accountUsage = (meters) => {
|
|
10549
10809
|
const current = { ...meters.perCounter, cost: meters.cost };
|
|
10550
|
-
const delta = mapFields(usageFields2, (
|
|
10551
|
-
baseline = mapFields(usageFields2, (
|
|
10810
|
+
const delta = mapFields(usageFields2, (field) => Math.max(0, current[field] - baseline[field]));
|
|
10811
|
+
baseline = mapFields(usageFields2, (field) => Math.max(baseline[field], current[field]));
|
|
10552
10812
|
charged = {
|
|
10553
10813
|
baseline,
|
|
10554
10814
|
tokens: charged.tokens + delta.input + delta.output,
|
|
10555
10815
|
cost: charged.cost + delta.cost,
|
|
10556
|
-
perCounter: mapFields(counterFields, (
|
|
10816
|
+
perCounter: mapFields(counterFields, (field) => charged.perCounter[field] + delta[field])
|
|
10557
10817
|
};
|
|
10558
10818
|
updateState({ accounting: charged });
|
|
10559
10819
|
return Object.assign(meters, { tokens: charged.tokens, cost: charged.cost, perCounter: charged.perCounter });
|
|
@@ -10630,21 +10890,21 @@ function createRunBudgetController(input) {
|
|
|
10630
10890
|
return { check: ownCheckpoint(frontierStage) };
|
|
10631
10891
|
};
|
|
10632
10892
|
const checkpoint = (frontierStage) => boundaryCheckpoint(frontierStage).check;
|
|
10633
|
-
const finishBoundary = (
|
|
10634
|
-
throw
|
|
10893
|
+
const finishBoundary = (owner, frontierStage) => {
|
|
10894
|
+
throw owner?.finishWrapUp(frontierStage, undefined, undefined, false) ?? finishWrapUp(frontierStage, undefined, undefined, false);
|
|
10635
10895
|
};
|
|
10636
|
-
const deliverBoundary = (
|
|
10637
|
-
|
|
10896
|
+
const deliverBoundary = (owner, frontierStage) => {
|
|
10897
|
+
owner?.deliverWrapUp(frontierStage) ?? deliverWrapUp(frontierStage);
|
|
10638
10898
|
};
|
|
10639
10899
|
const stopAtBoundary = (frontierStage) => {
|
|
10640
10900
|
const resolvedFrontierStage = frontierStage ?? handlers.at(-1)?.frontierStage;
|
|
10641
|
-
const { check, owner
|
|
10901
|
+
const { check, owner } = boundaryCheckpoint(resolvedFrontierStage);
|
|
10642
10902
|
if (check.kind === "wrap_up") {
|
|
10643
|
-
deliverBoundary(
|
|
10644
|
-
finishBoundary(
|
|
10903
|
+
deliverBoundary(owner, resolvedFrontierStage ?? "workflow frontier");
|
|
10904
|
+
finishBoundary(owner, resolvedFrontierStage);
|
|
10645
10905
|
}
|
|
10646
10906
|
if (check.kind === "exhausted")
|
|
10647
|
-
finishBoundary(
|
|
10907
|
+
finishBoundary(owner, resolvedFrontierStage);
|
|
10648
10908
|
};
|
|
10649
10909
|
const rethrowIfSystemOwnedStop = (frontierStage) => {
|
|
10650
10910
|
root?.rethrowIfSystemOwnedStop(frontierStage);
|
|
@@ -10738,11 +10998,11 @@ function createRunBudgetController(input) {
|
|
|
10738
10998
|
function createParallelPrimitive(input) {
|
|
10739
10999
|
return async (steps, options = {}) => {
|
|
10740
11000
|
input.runtime.exit.throwIfWorkflowExitSelected();
|
|
10741
|
-
const
|
|
10742
|
-
const normalizedOptions =
|
|
10743
|
-
const normalizedSteps = steps.map(
|
|
11001
|
+
const normalizeGroup = (value) => value.group === undefined ? value : { ...value, group: normalizeAutoGroupSentinel(value.group) };
|
|
11002
|
+
const normalizedOptions = normalizeGroup(options);
|
|
11003
|
+
const normalizedSteps = steps.map(normalizeGroup);
|
|
10744
11004
|
const needsAutoGroup = normalizedOptions.group === true || normalizedSteps.some((step) => step.group === true);
|
|
10745
|
-
const autoGroup = needsAutoGroup ?
|
|
11005
|
+
const autoGroup = needsAutoGroup ? randomUUID4() : undefined;
|
|
10746
11006
|
const resolveAutoGroup = (value) => value.group === true && autoGroup ? { ...value, group: autoGroup } : value;
|
|
10747
11007
|
const resolvedOptions = resolveAutoGroup(normalizedOptions);
|
|
10748
11008
|
const resolvedSteps = normalizedSteps.map(resolveAutoGroup);
|
|
@@ -10783,9 +11043,9 @@ function createParallelPrimitive(input) {
|
|
|
10783
11043
|
beforeMap: input.runtime.exit.throwIfWorkflowExitSelected,
|
|
10784
11044
|
isControlSignal: (error) => findWorkflowExitSignal(error, input.runtime.exit.exitScope) !== undefined,
|
|
10785
11045
|
selectSettledFailure: (failures) => {
|
|
10786
|
-
if (!everyStepCompleted() || !failures.every((
|
|
11046
|
+
if (!everyStepCompleted() || !failures.every((failure) => failure.error instanceof WorkflowBudgetExceededError))
|
|
10787
11047
|
return;
|
|
10788
|
-
return failures.reduce((selected,
|
|
11048
|
+
return failures.reduce((selected, failure) => failure.index < selected.index ? failure : selected).error;
|
|
10789
11049
|
}
|
|
10790
11050
|
});
|
|
10791
11051
|
};
|
|
@@ -10830,6 +11090,7 @@ function createTaskPrimitive(runtime) {
|
|
|
10830
11090
|
...sessionId !== undefined ? { sessionId } : {},
|
|
10831
11091
|
...stage.sessionFile !== undefined ? { sessionFile: stage.sessionFile } : {},
|
|
10832
11092
|
...stageMeta.model !== undefined ? { model: stageMeta.model } : {},
|
|
11093
|
+
...stageMeta.thinkingLevel !== undefined ? { thinkingLevel: stageMeta.thinkingLevel } : {},
|
|
10833
11094
|
...stageMeta.attemptedModels !== undefined ? { attemptedModels: stageMeta.attemptedModels } : {},
|
|
10834
11095
|
...stageMeta.modelAttempts !== undefined ? { modelAttempts: stageMeta.modelAttempts } : {},
|
|
10835
11096
|
...stageMeta.warnings !== undefined ? { warnings: stageMeta.warnings } : {}
|
|
@@ -11328,8 +11589,8 @@ function structuredRecoverableFailureFromSnapshot(snapshot, failedStageId) {
|
|
|
11328
11589
|
function isRecoverableProviderFailureKind(kind) {
|
|
11329
11590
|
return kind === "auth" || kind === "rate_limit" || kind === "provider";
|
|
11330
11591
|
}
|
|
11331
|
-
function stringResultField(result,
|
|
11332
|
-
const value = result?.[
|
|
11592
|
+
function stringResultField(result, key) {
|
|
11593
|
+
const value = result?.[key];
|
|
11333
11594
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
11334
11595
|
}
|
|
11335
11596
|
|
|
@@ -11347,7 +11608,7 @@ async function finalizeDurableTerminalStatus(input) {
|
|
|
11347
11608
|
if (durableStatus === "failed" || durableStatus === "blocked") {
|
|
11348
11609
|
recordRunTimingCheckpoint(input.durableBackend, input.runSnapshot);
|
|
11349
11610
|
}
|
|
11350
|
-
const
|
|
11611
|
+
const failure = durableStatus === "failed" ? {
|
|
11351
11612
|
...input.runSnapshot.error !== undefined ? { error: input.runSnapshot.error } : {},
|
|
11352
11613
|
...input.runSnapshot.exited === true ? {
|
|
11353
11614
|
exited: true,
|
|
@@ -11359,7 +11620,7 @@ async function finalizeDurableTerminalStatus(input) {
|
|
|
11359
11620
|
...input.runSnapshot.failureDisposition !== undefined ? { failureDisposition: input.runSnapshot.failureDisposition } : {},
|
|
11360
11621
|
...input.runSnapshot.failedToolNodeId !== undefined ? { failedToolNodeId: input.runSnapshot.failedToolNodeId } : {}
|
|
11361
11622
|
} : undefined;
|
|
11362
|
-
input.durableBackend.setWorkflowStatus(input.runId, durableStatus, undefined, input.runSnapshot.resumable,
|
|
11623
|
+
input.durableBackend.setWorkflowStatus(input.runId, durableStatus, undefined, input.runSnapshot.resumable, failure);
|
|
11363
11624
|
}
|
|
11364
11625
|
await input.durableBackend.flush(input.runId);
|
|
11365
11626
|
}
|
|
@@ -11616,17 +11877,17 @@ function childRunIdFromDraft(draft) {
|
|
|
11616
11877
|
}
|
|
11617
11878
|
function boundaryOwner(grouped, childRunId) {
|
|
11618
11879
|
for (const drafts of grouped.values()) {
|
|
11619
|
-
const
|
|
11620
|
-
if (
|
|
11621
|
-
return
|
|
11880
|
+
const owner = drafts.find((draft) => childRunIdFromDraft(draft) === childRunId);
|
|
11881
|
+
if (owner !== undefined)
|
|
11882
|
+
return owner;
|
|
11622
11883
|
}
|
|
11623
11884
|
return;
|
|
11624
11885
|
}
|
|
11625
|
-
function childRunStatus(
|
|
11626
|
-
const child = workflowChildFromDraft(
|
|
11886
|
+
function childRunStatus(owner) {
|
|
11887
|
+
const child = workflowChildFromDraft(owner);
|
|
11627
11888
|
if (child !== undefined)
|
|
11628
11889
|
return child.status;
|
|
11629
|
-
const status =
|
|
11890
|
+
const status = owner.topology?.boundary?.status;
|
|
11630
11891
|
return status === "failed" || status === "skipped" || status === "completed" ? status : "running";
|
|
11631
11892
|
}
|
|
11632
11893
|
function mergeStageGroup(records, allStages, allCheckpoints) {
|
|
@@ -11671,17 +11932,18 @@ function mergeStageDraft(existing, checkpoint, sequence) {
|
|
|
11671
11932
|
...valueOrExisting("endedAt", checkpoint, existing),
|
|
11672
11933
|
...valueOrExisting("durationMs", checkpoint, existing),
|
|
11673
11934
|
...valueOrExisting("model", checkpoint, existing),
|
|
11935
|
+
...valueOrExisting("thinkingLevel", checkpoint, existing),
|
|
11674
11936
|
...valueOrExisting("attemptedModels", checkpoint, existing),
|
|
11675
11937
|
...valueOrExisting("modelAttempts", checkpoint, existing),
|
|
11676
11938
|
...checkpoint.topology !== undefined ? { topology: checkpoint.topology } : existing?.topology !== undefined ? { topology: existing.topology } : {}
|
|
11677
11939
|
};
|
|
11678
11940
|
}
|
|
11679
|
-
function valueOrExisting(
|
|
11680
|
-
const checkpointValue = checkpoint[
|
|
11941
|
+
function valueOrExisting(key, checkpoint, existing) {
|
|
11942
|
+
const checkpointValue = checkpoint[key];
|
|
11681
11943
|
if (checkpointValue !== undefined)
|
|
11682
|
-
return { [
|
|
11683
|
-
const existingValue = existing?.[
|
|
11684
|
-
return existingValue === undefined ? {} : { [
|
|
11944
|
+
return { [key]: checkpointValue };
|
|
11945
|
+
const existingValue = existing?.[key];
|
|
11946
|
+
return existingValue === undefined ? {} : { [key]: existingValue };
|
|
11685
11947
|
}
|
|
11686
11948
|
function workflowChildFromDraft(draft) {
|
|
11687
11949
|
const strict = parseWorkflowChildResult(draft.output);
|
|
@@ -11757,7 +12019,7 @@ function durableNestedRunSnapshots(backend, rootWorkflowId) {
|
|
|
11757
12019
|
const handle = backend.getWorkflow(rootWorkflowId);
|
|
11758
12020
|
if (handle === undefined)
|
|
11759
12021
|
return [];
|
|
11760
|
-
return runSnapshotsFromCheckpoints(backend.listCheckpoints(rootWorkflowId), rootWorkflowId, handle.name, handle.updatedAt, LEGACY_ACTIVE_RECONSTRUCTION).filter((
|
|
12022
|
+
return runSnapshotsFromCheckpoints(backend.listCheckpoints(rootWorkflowId), rootWorkflowId, handle.name, handle.updatedAt, LEGACY_ACTIVE_RECONSTRUCTION).filter((run) => run.id !== rootWorkflowId);
|
|
11761
12023
|
}
|
|
11762
12024
|
function checkpointDrafts(checkpoints) {
|
|
11763
12025
|
const stageByReplayKey = new Map;
|
|
@@ -11766,8 +12028,8 @@ function checkpointDrafts(checkpoints) {
|
|
|
11766
12028
|
checkpoints.forEach((checkpoint, index) => {
|
|
11767
12029
|
const sequence = index + 1;
|
|
11768
12030
|
if (checkpoint.kind === "stage") {
|
|
11769
|
-
const
|
|
11770
|
-
stageByReplayKey.set(checkpoint.replayKey, mergeStageDraft(
|
|
12031
|
+
const existing = stageByReplayKey.get(checkpoint.replayKey);
|
|
12032
|
+
stageByReplayKey.set(checkpoint.replayKey, mergeStageDraft(existing, checkpoint, sequence));
|
|
11771
12033
|
return;
|
|
11772
12034
|
}
|
|
11773
12035
|
if (checkpoint.kind !== "tool" || isReservedRunCheckpointHash(checkpoint.argsHash))
|
|
@@ -11968,29 +12230,29 @@ function runSnapshotsFromCheckpoints(checkpoints, rootRunId, rootRunName, fallba
|
|
|
11968
12230
|
}
|
|
11969
12231
|
const stages = runDrafts.map((draft) => stageSnapshotFromDraft(draft, ids.get(draft.topology.stageId), draft.topology.parentIds.map((parentId) => ids.get(parentId))));
|
|
11970
12232
|
const toolNodes = completedToolNodes(toolCheckpoints, runId, rootRunId, ids, drafts.firstToolSequenceByHash);
|
|
11971
|
-
const
|
|
12233
|
+
const run = runTopologyFor(runDrafts, ownedTools);
|
|
11972
12234
|
const startedAt = Math.min(...stages.map((stage) => stage.startedAt ?? fallbackCompletedAt), ...toolNodes.map((tool) => tool.startedAt ?? tool.endedAt ?? fallbackCompletedAt));
|
|
11973
12235
|
const endedAt = Math.max(...stages.map((stage) => stage.endedAt ?? fallbackCompletedAt), ...toolNodes.map((tool) => tool.endedAt ?? fallbackCompletedAt));
|
|
11974
|
-
const
|
|
11975
|
-
const status =
|
|
12236
|
+
const owner = runId === rootRunId ? undefined : boundaryOwner(grouped, runId);
|
|
12237
|
+
const status = owner === undefined ? "completed" : childRunStatus(owner);
|
|
11976
12238
|
const terminal = status !== "running" && status !== "pending" && status !== "paused" && status !== "blocked";
|
|
11977
|
-
const parentRunId =
|
|
12239
|
+
const parentRunId = run?.parentRunId ?? rootRunId;
|
|
11978
12240
|
const boundarySourceId = grouped.get(parentRunId)?.find((draft) => childRunIdFromDraft(draft) === runId)?.topology?.stageId;
|
|
11979
|
-
const declaredParentStageId =
|
|
12241
|
+
const declaredParentStageId = run?.parentStageId === undefined ? undefined : idMaps.get(parentRunId)?.get(run.parentStageId);
|
|
11980
12242
|
const parentStageId = declaredParentStageId ?? (boundarySourceId === undefined ? undefined : idMaps.get(parentRunId)?.get(boundarySourceId));
|
|
11981
|
-
const ownerChild =
|
|
12243
|
+
const ownerChild = owner === undefined ? undefined : workflowChildFromDraft(owner);
|
|
11982
12244
|
runs.push({
|
|
11983
12245
|
id: runId,
|
|
11984
|
-
name:
|
|
12246
|
+
name: run?.runName ?? rootRunName,
|
|
11985
12247
|
inputs: {},
|
|
11986
12248
|
status,
|
|
11987
12249
|
stages,
|
|
11988
12250
|
toolNodes,
|
|
11989
12251
|
startedAt,
|
|
11990
12252
|
...terminal ? { endedAt, durationMs: Math.max(0, endedAt - startedAt) } : {},
|
|
11991
|
-
...
|
|
12253
|
+
...run?.parentRunId !== undefined ? { parentRunId: run.parentRunId } : {},
|
|
11992
12254
|
...parentStageId !== undefined ? { parentStageId } : {},
|
|
11993
|
-
...
|
|
12255
|
+
...run?.rootRunId !== undefined ? { rootRunId: run.rootRunId } : {},
|
|
11994
12256
|
...ownerChild?.exited === true ? {
|
|
11995
12257
|
result: ownerChild.outputs,
|
|
11996
12258
|
exited: true,
|
|
@@ -12000,13 +12262,13 @@ function runSnapshotsFromCheckpoints(checkpoints, rootRunId, rootRunName, fallba
|
|
|
12000
12262
|
});
|
|
12001
12263
|
emittedRunIds.add(runId);
|
|
12002
12264
|
}
|
|
12003
|
-
for (const { parentRunId, owner
|
|
12265
|
+
for (const { parentRunId, owner, child } of syntheticChildren) {
|
|
12004
12266
|
if (!emittedRunIds.has(parentRunId)) {
|
|
12005
12267
|
if (policy.failClosed)
|
|
12006
12268
|
return [];
|
|
12007
12269
|
continue;
|
|
12008
12270
|
}
|
|
12009
|
-
const topology =
|
|
12271
|
+
const topology = owner.topology;
|
|
12010
12272
|
const boundary = topology.boundary;
|
|
12011
12273
|
const parentStageId = idMaps.get(parentRunId)?.get(topology.stageId);
|
|
12012
12274
|
if (parentStageId === undefined) {
|
|
@@ -12014,8 +12276,8 @@ function runSnapshotsFromCheckpoints(checkpoints, rootRunId, rootRunName, fallba
|
|
|
12014
12276
|
return [];
|
|
12015
12277
|
continue;
|
|
12016
12278
|
}
|
|
12017
|
-
const startedAt =
|
|
12018
|
-
const endedAt =
|
|
12279
|
+
const startedAt = owner.startedAt ?? owner.firstCompletedAt;
|
|
12280
|
+
const endedAt = owner.endedAt ?? owner.firstCompletedAt;
|
|
12019
12281
|
runs.push({
|
|
12020
12282
|
id: child.runId,
|
|
12021
12283
|
name: boundary.child.runName,
|
|
@@ -12067,6 +12329,7 @@ function stageSnapshotFromDraft(draft, id, parentIds) {
|
|
|
12067
12329
|
...draft.sessionId !== undefined ? { sessionId: draft.sessionId } : {},
|
|
12068
12330
|
...draft.sessionFile !== undefined ? { sessionFile: draft.sessionFile } : {},
|
|
12069
12331
|
...draft.model !== undefined ? { model: draft.model } : {},
|
|
12332
|
+
...draft.thinkingLevel !== undefined ? { thinkingLevel: draft.thinkingLevel } : {},
|
|
12070
12333
|
...draft.attemptedModels !== undefined ? { attemptedModels: draft.attemptedModels } : {},
|
|
12071
12334
|
...draft.modelAttempts !== undefined ? { modelAttempts: draft.modelAttempts } : {}
|
|
12072
12335
|
};
|
|
@@ -12123,7 +12386,7 @@ function syntheticCheckpointStage(checkpointCount, completedAt) {
|
|
|
12123
12386
|
// dist/builtin/workflows/src/durable/completed-subtree.ts
|
|
12124
12387
|
function durableCompletedNestedRunSubtree(backend, rootWorkflowId, childRunId) {
|
|
12125
12388
|
const nested = durableNestedRunSnapshots(backend, rootWorkflowId);
|
|
12126
|
-
if (!nested.some((
|
|
12389
|
+
if (!nested.some((run) => run.id === childRunId))
|
|
12127
12390
|
return;
|
|
12128
12391
|
const intentionalExitStatuses = new Map;
|
|
12129
12392
|
for (const checkpoint of backend.listCheckpoints(rootWorkflowId)) {
|
|
@@ -12137,22 +12400,22 @@ function durableCompletedNestedRunSubtree(backend, rootWorkflowId, childRunId) {
|
|
|
12137
12400
|
let priorSize = -1;
|
|
12138
12401
|
while (priorSize !== included.size) {
|
|
12139
12402
|
priorSize = included.size;
|
|
12140
|
-
for (const
|
|
12141
|
-
if (
|
|
12142
|
-
included.add(
|
|
12403
|
+
for (const run of nested) {
|
|
12404
|
+
if (run.parentRunId !== undefined && included.has(run.parentRunId))
|
|
12405
|
+
included.add(run.id);
|
|
12143
12406
|
}
|
|
12144
12407
|
}
|
|
12145
|
-
const subtree = nested.filter((
|
|
12146
|
-
const complete = subtree.length === included.size && subtree.every((
|
|
12408
|
+
const subtree = nested.filter((run) => included.has(run.id));
|
|
12409
|
+
const complete = subtree.length === included.size && subtree.every((run) => isCompleteCachedRun(run, intentionalExitStatuses));
|
|
12147
12410
|
return complete ? subtree : undefined;
|
|
12148
12411
|
}
|
|
12149
|
-
function isCompleteCachedRun(
|
|
12150
|
-
if (
|
|
12412
|
+
function isCompleteCachedRun(run, intentionalExitStatuses) {
|
|
12413
|
+
if (run.endedAt === undefined || !run.stages.every((stage) => isTerminalStage2(stage.status) && stage.endedAt !== undefined)) {
|
|
12151
12414
|
return false;
|
|
12152
12415
|
}
|
|
12153
|
-
if (
|
|
12416
|
+
if (run.status === "completed" || run.exited === true)
|
|
12154
12417
|
return true;
|
|
12155
|
-
return intentionalExitStatuses.get(
|
|
12418
|
+
return intentionalExitStatuses.get(run.id) === run.status;
|
|
12156
12419
|
}
|
|
12157
12420
|
function isTerminalStage2(status) {
|
|
12158
12421
|
return status === "completed" || status === "failed" || status === "skipped";
|
|
@@ -12197,13 +12460,13 @@ function reciprocalWorkflowRootRunId(runById, runId) {
|
|
|
12197
12460
|
}
|
|
12198
12461
|
|
|
12199
12462
|
// dist/builtin/workflows/src/engine/run-durable-topology.ts
|
|
12200
|
-
function durableRunTopology(
|
|
12463
|
+
function durableRunTopology(run) {
|
|
12201
12464
|
return {
|
|
12202
|
-
runId:
|
|
12203
|
-
runName:
|
|
12204
|
-
...
|
|
12205
|
-
...
|
|
12206
|
-
...
|
|
12465
|
+
runId: run.id,
|
|
12466
|
+
runName: run.name,
|
|
12467
|
+
...run.parentRunId !== undefined ? { parentRunId: run.parentRunId } : {},
|
|
12468
|
+
...run.parentStageId !== undefined ? { parentStageId: run.parentStageId } : {},
|
|
12469
|
+
...run.rootRunId !== undefined ? { rootRunId: run.rootRunId } : {}
|
|
12207
12470
|
};
|
|
12208
12471
|
}
|
|
12209
12472
|
function createDurableStageDeps(input) {
|
|
@@ -12278,7 +12541,7 @@ function createDurableCachedStageRecorder(input) {
|
|
|
12278
12541
|
return {
|
|
12279
12542
|
record(name, replayKey, checkpoint, scope) {
|
|
12280
12543
|
const cachedChildRunId = workflowChildRunId(checkpoint);
|
|
12281
|
-
const runById = new Map(input.store.runs().map((
|
|
12544
|
+
const runById = new Map(input.store.runs().map((run) => [run.id, run]));
|
|
12282
12545
|
if (!runById.has(input.run.id))
|
|
12283
12546
|
runById.set(input.run.id, input.run);
|
|
12284
12547
|
const durableRootId = reciprocalWorkflowRootRunId(runById, input.run.id);
|
|
@@ -12294,7 +12557,7 @@ function createDurableCachedStageRecorder(input) {
|
|
|
12294
12557
|
replaySourceOrders.set(replayedStage.id, sourceOrder);
|
|
12295
12558
|
input.run.stages.sort((left, right) => (replaySourceOrders.get(left.id) ?? Number.MAX_SAFE_INTEGER) - (replaySourceOrders.get(right.id) ?? Number.MAX_SAFE_INTEGER));
|
|
12296
12559
|
}
|
|
12297
|
-
const stage = input.store.runs().find((
|
|
12560
|
+
const stage = input.store.runs().find((run) => run.id === input.run.id)?.stages.find((candidate) => candidate.replayKey === replayKey);
|
|
12298
12561
|
if (stage !== undefined) {
|
|
12299
12562
|
input.backend.recordCheckpoint({
|
|
12300
12563
|
kind: "stage",
|
|
@@ -12332,10 +12595,10 @@ function createDurableCachedStageRecorder(input) {
|
|
|
12332
12595
|
};
|
|
12333
12596
|
}
|
|
12334
12597
|
function reconcileCachedDirectChildParentStage(input) {
|
|
12335
|
-
const existingRun = input.store.runs().find((
|
|
12598
|
+
const existingRun = input.store.runs().find((run) => run.id === input.checkpointChildRunId);
|
|
12336
12599
|
if (existingRun === undefined)
|
|
12337
12600
|
return false;
|
|
12338
|
-
const runById = new Map(input.store.runs().map((
|
|
12601
|
+
const runById = new Map(input.store.runs().map((run) => [run.id, run]));
|
|
12339
12602
|
const storedParentRun = runById.get(input.parentRun.id);
|
|
12340
12603
|
if (storedParentRun !== undefined && (storedParentRun.parentRunId !== input.parentRun.parentRunId || storedParentRun.parentStageId !== input.parentRun.parentStageId))
|
|
12341
12604
|
return false;
|
|
@@ -12376,11 +12639,11 @@ function deferStageUntilRunRelease(input) {
|
|
|
12376
12639
|
};
|
|
12377
12640
|
return {
|
|
12378
12641
|
name: input.name,
|
|
12379
|
-
prompt: (...args) => invoke((
|
|
12380
|
-
complete: (...args) => invoke((
|
|
12381
|
-
sendUserMessage: (...args) => invoke((
|
|
12382
|
-
steer: (...args) => invoke((
|
|
12383
|
-
followUp: (...args) => invoke((
|
|
12642
|
+
prompt: (...args) => invoke((stage) => stage.prompt(...args)),
|
|
12643
|
+
complete: (...args) => invoke((stage) => stage.complete(...args)),
|
|
12644
|
+
sendUserMessage: (...args) => invoke((stage) => stage.sendUserMessage(...args)),
|
|
12645
|
+
steer: (...args) => invoke((stage) => stage.steer(...args)),
|
|
12646
|
+
followUp: (...args) => invoke((stage) => stage.followUp(...args)),
|
|
12384
12647
|
subscribe: (...args) => current().subscribe(...args),
|
|
12385
12648
|
get sessionFile() {
|
|
12386
12649
|
return current().sessionFile;
|
|
@@ -12388,9 +12651,9 @@ function deferStageUntilRunRelease(input) {
|
|
|
12388
12651
|
get sessionId() {
|
|
12389
12652
|
return current().sessionId;
|
|
12390
12653
|
},
|
|
12391
|
-
setModel: (...args) => invoke((
|
|
12654
|
+
setModel: (...args) => invoke((stage) => stage.setModel(...args)),
|
|
12392
12655
|
setThinkingLevel: (...args) => current().setThinkingLevel(...args),
|
|
12393
|
-
cycleModel: () => invoke((
|
|
12656
|
+
cycleModel: () => invoke((stage) => stage.cycleModel()),
|
|
12394
12657
|
cycleThinkingLevel: () => current().cycleThinkingLevel(),
|
|
12395
12658
|
get agent() {
|
|
12396
12659
|
return current().agent;
|
|
@@ -12407,10 +12670,10 @@ function deferStageUntilRunRelease(input) {
|
|
|
12407
12670
|
get isStreaming() {
|
|
12408
12671
|
return current().isStreaming;
|
|
12409
12672
|
},
|
|
12410
|
-
navigateTree: (...args) => invoke((
|
|
12411
|
-
compact: () => invoke((
|
|
12673
|
+
navigateTree: (...args) => invoke((stage) => stage.navigateTree(...args)),
|
|
12674
|
+
compact: () => invoke((stage) => stage.compact()),
|
|
12412
12675
|
abortCompaction: () => current().abortCompaction(),
|
|
12413
|
-
abort: () => invoke((
|
|
12676
|
+
abort: () => invoke((stage) => stage.abort())
|
|
12414
12677
|
};
|
|
12415
12678
|
}
|
|
12416
12679
|
|
|
@@ -12494,9 +12757,9 @@ function createRunTerminalEventArbiter(runId) {
|
|
|
12494
12757
|
|
|
12495
12758
|
// dist/builtin/workflows/src/engine/run-terminal-failure.ts
|
|
12496
12759
|
function finalizeTerminalFailure(input) {
|
|
12497
|
-
const { runId, runSnapshot, store
|
|
12760
|
+
const { runId, runSnapshot, store, persistence, metadata, onRunEnd } = input;
|
|
12498
12761
|
const failedToolNode = metadata.failedToolNodeId === undefined ? undefined : runSnapshot.toolNodes?.find((node) => node.id === metadata.failedToolNodeId);
|
|
12499
|
-
const recorded =
|
|
12762
|
+
const recorded = store.recordRunEnd(runId, "failed", undefined, metadata.errorMessage, metadata);
|
|
12500
12763
|
appendRunEndWhenRecorded(persistence, recorded, {
|
|
12501
12764
|
runId,
|
|
12502
12765
|
status: "failed",
|
|
@@ -12515,7 +12778,7 @@ function finalizeTerminalFailure(input) {
|
|
|
12515
12778
|
...runSnapshot.durationMs !== undefined ? { durationMs: runSnapshot.durationMs } : {},
|
|
12516
12779
|
ts: Date.now()
|
|
12517
12780
|
});
|
|
12518
|
-
return reconcileTerminalRunResult(runId, runSnapshot,
|
|
12781
|
+
return reconcileTerminalRunResult(runId, runSnapshot, store, { status: "failed", error: metadata.errorMessage }, onRunEnd);
|
|
12519
12782
|
}
|
|
12520
12783
|
|
|
12521
12784
|
// dist/builtin/workflows/src/engine/run-tool-admission-boundary.ts
|
|
@@ -12653,7 +12916,7 @@ function createAdmittedToolExecutionTracker(options = {}) {
|
|
|
12653
12916
|
const admissions = [];
|
|
12654
12917
|
const failures = [];
|
|
12655
12918
|
const cancellations = [];
|
|
12656
|
-
let
|
|
12919
|
+
let nextAdmissionOrder = 0;
|
|
12657
12920
|
let state = "OPEN";
|
|
12658
12921
|
let closing;
|
|
12659
12922
|
const abandonment = Promise.withResolvers();
|
|
@@ -12662,17 +12925,17 @@ function createAdmittedToolExecutionTracker(options = {}) {
|
|
|
12662
12925
|
const recordFailure = (admission, error, nodeId) => {
|
|
12663
12926
|
if (admission.failure !== undefined)
|
|
12664
12927
|
return;
|
|
12665
|
-
const
|
|
12666
|
-
admission.failure =
|
|
12667
|
-
failures.push(
|
|
12668
|
-
options.onFailureObserved?.(
|
|
12928
|
+
const failure = { admissionOrder: admission.admissionOrder, error, ...nodeId === undefined ? {} : { nodeId } };
|
|
12929
|
+
admission.failure = failure;
|
|
12930
|
+
failures.push(failure);
|
|
12931
|
+
options.onFailureObserved?.(failure);
|
|
12669
12932
|
};
|
|
12670
12933
|
const reportDrainFailure = () => {
|
|
12671
|
-
const
|
|
12672
|
-
if (state !== "DRAINING" ||
|
|
12934
|
+
const failure = failures[0];
|
|
12935
|
+
if (state !== "DRAINING" || failure === undefined || drainFailureReported)
|
|
12673
12936
|
return;
|
|
12674
12937
|
drainFailureReported = true;
|
|
12675
|
-
options.onFailureDuringDrain?.(
|
|
12938
|
+
options.onFailureDuringDrain?.(failure);
|
|
12676
12939
|
};
|
|
12677
12940
|
const drainRecordedFailures = () => Promise.all(admissions.flatMap((admission) => admission.failure !== undefined && admission.observed !== undefined ? [admission.observed] : []));
|
|
12678
12941
|
const closeAtFixedPoint = async () => {
|
|
@@ -12704,7 +12967,7 @@ function createAdmittedToolExecutionTracker(options = {}) {
|
|
|
12704
12967
|
return { accepted: false, error, bindNode() {}, noteCancelled() {} };
|
|
12705
12968
|
}
|
|
12706
12969
|
const admission = {
|
|
12707
|
-
admissionOrder: ++
|
|
12970
|
+
admissionOrder: ++nextAdmissionOrder,
|
|
12708
12971
|
nodeId: undefined,
|
|
12709
12972
|
failure: undefined,
|
|
12710
12973
|
cancelled: false,
|
|
@@ -12764,7 +13027,7 @@ function createAdmittedToolExecutionTracker(options = {}) {
|
|
|
12764
13027
|
return failures[0];
|
|
12765
13028
|
},
|
|
12766
13029
|
uniqueFailureFor(error) {
|
|
12767
|
-
const matching = [...failures, ...cancellations].filter((
|
|
13030
|
+
const matching = [...failures, ...cancellations].filter((failure) => Object.is(failure.error, error));
|
|
12768
13031
|
return matching.length === 1 ? matching[0] : undefined;
|
|
12769
13032
|
}
|
|
12770
13033
|
};
|
|
@@ -12772,8 +13035,8 @@ function createAdmittedToolExecutionTracker(options = {}) {
|
|
|
12772
13035
|
|
|
12773
13036
|
// dist/builtin/workflows/src/engine/run-tool-node-lifecycle.ts
|
|
12774
13037
|
function createToolNodeLifecycle(input) {
|
|
12775
|
-
const { store
|
|
12776
|
-
const ownsCurrentRun = () =>
|
|
13038
|
+
const { store, tracker, run, sourceToContinuationNodeIds } = input;
|
|
13039
|
+
const ownsCurrentRun = () => store.runs().some((candidate) => candidate === run);
|
|
12777
13040
|
const replayedToolNodeIds = new Set;
|
|
12778
13041
|
let pendingFrontier = input.resumeToolNode;
|
|
12779
13042
|
return {
|
|
@@ -12791,11 +13054,11 @@ function createToolNodeLifecycle(input) {
|
|
|
12791
13054
|
const sourceParents = frontier?.parentIds ?? (node.replayed === true && node.topologyState !== "unavailable" ? node.parentIds : undefined);
|
|
12792
13055
|
const restored = sourceParents?.map((sourceId) => sourceToContinuationNodeIds.get(sourceId));
|
|
12793
13056
|
const translated = restored?.every((id) => id !== undefined) ? restored : undefined;
|
|
12794
|
-
if (
|
|
12795
|
-
throw new Error(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for tool "${node.name}" (node "${node.id}") in source run ${
|
|
13057
|
+
if (run.resumedFromRunId !== undefined && sourceParents !== undefined && translated === undefined) {
|
|
13058
|
+
throw new Error(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for tool "${node.name}" (node "${node.id}") in source run ${run.resumedFromRunId}`);
|
|
12796
13059
|
}
|
|
12797
|
-
if (translated !== undefined &&
|
|
12798
|
-
throw new Error(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for tool "${node.name}" (node "${node.id}") in source run ${
|
|
13060
|
+
if (translated !== undefined && run.resumedFromRunId !== undefined && !compatibleReplayedToolParents(tracker, translated, inferredParents, (parentId) => isReplayedContinuationNode(store, run, replayedToolNodeIds, parentId))) {
|
|
13061
|
+
throw new Error(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for tool "${node.name}" (node "${node.id}") in source run ${run.resumedFromRunId}`);
|
|
12799
13062
|
}
|
|
12800
13063
|
const parentIds = translated ?? inferredParents;
|
|
12801
13064
|
tracker.replaceParents(node.id, parentIds);
|
|
@@ -12804,28 +13067,28 @@ function createToolNodeLifecycle(input) {
|
|
|
12804
13067
|
if (node.replayed === true)
|
|
12805
13068
|
replayedToolNodeIds.add(node.id);
|
|
12806
13069
|
if (ownsCurrentRun())
|
|
12807
|
-
|
|
13070
|
+
store.recordToolNodeStart(run.id, node);
|
|
12808
13071
|
if (frontier !== undefined)
|
|
12809
13072
|
pendingFrontier = undefined;
|
|
12810
13073
|
},
|
|
12811
13074
|
onNodeRunning: (nodeId, startedAt) => {
|
|
12812
13075
|
if (ownsCurrentRun())
|
|
12813
|
-
|
|
13076
|
+
store.recordToolNodeRunning(run.id, nodeId, startedAt);
|
|
12814
13077
|
},
|
|
12815
13078
|
onNodeEnd: (nodeId, update) => {
|
|
12816
13079
|
if (ownsCurrentRun())
|
|
12817
|
-
|
|
13080
|
+
store.recordToolNodeEnd(run.id, nodeId, update);
|
|
12818
13081
|
},
|
|
12819
13082
|
onNodeSettle: (nodeId) => {
|
|
12820
13083
|
tracker.onSettle(nodeId);
|
|
12821
13084
|
},
|
|
12822
|
-
runTopology: durableRunTopology(
|
|
13085
|
+
runTopology: durableRunTopology(run)
|
|
12823
13086
|
};
|
|
12824
13087
|
}
|
|
12825
|
-
function isReplayedContinuationNode(
|
|
13088
|
+
function isReplayedContinuationNode(store, run, replayedToolNodeIds, nodeId) {
|
|
12826
13089
|
if (replayedToolNodeIds.has(nodeId))
|
|
12827
13090
|
return true;
|
|
12828
|
-
const live =
|
|
13091
|
+
const live = store.runs().find((candidate) => candidate === run);
|
|
12829
13092
|
return live?.stages.some((stage) => stage.id === nodeId && stage.replayed === true) === true;
|
|
12830
13093
|
}
|
|
12831
13094
|
function compatibleReplayedToolParents(tracker, translated, inferredParents, isReplayedNode) {
|
|
@@ -12842,9 +13105,9 @@ function createTrackedToolPrimitive(input) {
|
|
|
12842
13105
|
onFailureObserved: ({ error, nodeId }) => {
|
|
12843
13106
|
input.terminalEvents.selectFailure(error, nodeId);
|
|
12844
13107
|
},
|
|
12845
|
-
onFailureDuringDrain: (
|
|
13108
|
+
onFailureDuringDrain: (failure) => {
|
|
12846
13109
|
if (input.terminalEvents.winner()?.kind === "failure")
|
|
12847
|
-
input.controller.abort(
|
|
13110
|
+
input.controller.abort(failure.error);
|
|
12848
13111
|
}
|
|
12849
13112
|
});
|
|
12850
13113
|
const lifecycle = createToolNodeLifecycle(input);
|
|
@@ -13167,21 +13430,17 @@ function throwFinalizationError(error) {
|
|
|
13167
13430
|
function createTrackedStageCaller(input) {
|
|
13168
13431
|
const { runtime } = input;
|
|
13169
13432
|
const readinessGateEnabled = runtime.opts.confirmStageReadiness !== undefined || runtime.opts.usePromptNodesForUi === true;
|
|
13170
|
-
const confirmReadiness = async () => {
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
return await askReadinessViaStageBroker(runtime.runId, runtime.stageId, runtime.signal);
|
|
13182
|
-
} catch {
|
|
13183
|
-
return { action: "advance" };
|
|
13184
|
-
}
|
|
13433
|
+
const confirmReadiness = async (signal) => {
|
|
13434
|
+
if (runtime.opts.confirmStageReadiness !== undefined) {
|
|
13435
|
+
const ready = await raceAbort(runtime.opts.confirmStageReadiness({
|
|
13436
|
+
runId: runtime.runId,
|
|
13437
|
+
stageId: runtime.stageId,
|
|
13438
|
+
stageName: runtime.name,
|
|
13439
|
+
signal
|
|
13440
|
+
}), signal);
|
|
13441
|
+
return ready ? { action: "advance" } : { action: "stay" };
|
|
13442
|
+
}
|
|
13443
|
+
return await askReadinessViaStageBroker(runtime.runId, runtime.stageId, signal);
|
|
13185
13444
|
};
|
|
13186
13445
|
const suppressReadinessForCurrentTurn = () => {
|
|
13187
13446
|
runtime.state.askUserQuestionObservedThisTurn = false;
|
|
@@ -13223,7 +13482,7 @@ function createTrackedStageCaller(input) {
|
|
|
13223
13482
|
if (suppressQueuedContinuation)
|
|
13224
13483
|
runtime.state.suppressQueuedUserMessageContinuation = true;
|
|
13225
13484
|
try {
|
|
13226
|
-
result = await runtime.raceStageSessionHeartbeat(raceAbort(runtime.innerCtx.
|
|
13485
|
+
result = await runtime.raceStageSessionHeartbeat(raceAbort(runtime.innerCtx.__continuePrompt(RESUME_CONTINUATION_PROMPT), runtime.signal));
|
|
13227
13486
|
} finally {
|
|
13228
13487
|
if (suppressQueuedContinuation)
|
|
13229
13488
|
runtime.state.suppressQueuedUserMessageContinuation = false;
|
|
@@ -13328,30 +13587,56 @@ function createTrackedStageCaller(input) {
|
|
|
13328
13587
|
let resolveNextTurnEnd = null;
|
|
13329
13588
|
const unsubscribeTurnWatcher = runtime.innerCtx.subscribe((event) => {
|
|
13330
13589
|
if (event.type === "agent_end" && resolveNextTurnEnd) {
|
|
13331
|
-
const
|
|
13590
|
+
const resolve = resolveNextTurnEnd;
|
|
13332
13591
|
resolveNextTurnEnd = null;
|
|
13333
|
-
|
|
13592
|
+
resolve();
|
|
13334
13593
|
}
|
|
13335
13594
|
});
|
|
13336
13595
|
try {
|
|
13337
13596
|
while (runtime.state.askUserQuestionObservedThisTurn || repeatReadinessAfterChatTurn) {
|
|
13338
|
-
|
|
13597
|
+
runtime.signal.throwIfAborted();
|
|
13598
|
+
if (runtime.stageSnapshot.status === "paused" || runtime.stageSnapshot.status === "blocked") {
|
|
13599
|
+
await runtime.scheduler.waitForStageRelease(runtime.stageId, runtime.releaseLiveHandle);
|
|
13600
|
+
continue;
|
|
13601
|
+
}
|
|
13602
|
+
const controller = new AbortController;
|
|
13603
|
+
runtime.state.readinessController = controller;
|
|
13604
|
+
let decision;
|
|
13605
|
+
try {
|
|
13606
|
+
decision = await confirmReadiness(AbortSignal.any([runtime.signal, controller.signal]));
|
|
13607
|
+
if (decision.action === "advance" || decision.message !== undefined) {
|
|
13608
|
+
await runtime.scheduler.waitForStageRelease(runtime.stageId, runtime.releaseLiveHandle);
|
|
13609
|
+
}
|
|
13610
|
+
runtime.signal.throwIfAborted();
|
|
13611
|
+
if (controller.signal.aborted) {
|
|
13612
|
+
await runtime.scheduler.waitForStageRelease(runtime.stageId, runtime.releaseLiveHandle);
|
|
13613
|
+
continue;
|
|
13614
|
+
}
|
|
13615
|
+
} catch (error) {
|
|
13616
|
+
runtime.signal.throwIfAborted();
|
|
13617
|
+
if (controller.signal.aborted) {
|
|
13618
|
+
await runtime.scheduler.waitForStageRelease(runtime.stageId, runtime.releaseLiveHandle);
|
|
13619
|
+
continue;
|
|
13620
|
+
}
|
|
13621
|
+
throw error;
|
|
13622
|
+
}
|
|
13339
13623
|
if (decision.action === "advance")
|
|
13340
13624
|
break;
|
|
13625
|
+
delete runtime.state.readinessController;
|
|
13341
13626
|
if (runtime.signal.aborted)
|
|
13342
13627
|
break;
|
|
13343
13628
|
runtime.state.askUserQuestionObservedThisTurn = false;
|
|
13344
13629
|
runtime.state.chatAnswerObservedThisTurn = false;
|
|
13345
13630
|
if (decision.message !== undefined) {
|
|
13346
|
-
result = await runtime.raceStageSessionHeartbeat(raceAbort(runtime.innerCtx.
|
|
13631
|
+
result = await runtime.raceStageSessionHeartbeat(raceAbort(runtime.innerCtx.__continuePrompt(decision.message), runtime.signal));
|
|
13347
13632
|
if (runtime.budget.enabled && typeof result === "string")
|
|
13348
13633
|
stageResultBeforeBudget = result;
|
|
13349
13634
|
} else {
|
|
13350
13635
|
runtime.state.waitingForStageChatTurn = true;
|
|
13351
13636
|
try {
|
|
13352
|
-
await runtime.raceStageSessionHeartbeat(raceAbort(new Promise((
|
|
13353
|
-
resolveNextTurnEnd =
|
|
13354
|
-
runtime.state.wakeWaitingForStageChatTurn =
|
|
13637
|
+
await runtime.raceStageSessionHeartbeat(raceAbort(new Promise((resolve) => {
|
|
13638
|
+
resolveNextTurnEnd = resolve;
|
|
13639
|
+
runtime.state.wakeWaitingForStageChatTurn = resolve;
|
|
13355
13640
|
}), runtime.signal));
|
|
13356
13641
|
} finally {
|
|
13357
13642
|
runtime.state.wakeWaitingForStageChatTurn = undefined;
|
|
@@ -13391,7 +13676,9 @@ function createTrackedStageCaller(input) {
|
|
|
13391
13676
|
await runtime.budget.deliverWrapUp(runtime.name);
|
|
13392
13677
|
if (afterBudget.kind === "exhausted" && runtime.budget.enabled)
|
|
13393
13678
|
await runtime.budget.stopAtBoundaryAsync(runtime.name);
|
|
13394
|
-
await runtime.innerCtx.__closeGeneration();
|
|
13679
|
+
const finalizedArtifact = await runtime.innerCtx.__closeGeneration();
|
|
13680
|
+
if (typeof result === "string" && finalizedArtifact !== undefined)
|
|
13681
|
+
result = finalizedArtifact;
|
|
13395
13682
|
await runtime.captureStageSessionMeta({ awaitDurable: true });
|
|
13396
13683
|
if (trackStageLifecycle && runtime.stageFailFastScope?.failed === true && runtime.stageFailFastScope.activeStages.has(runtime.stageId)) {
|
|
13397
13684
|
runtime.markSkippedForParallelFailFast();
|
|
@@ -13420,7 +13707,7 @@ function createTrackedStageCaller(input) {
|
|
|
13420
13707
|
const budgetError = err instanceof WorkflowBudgetExceededError ? err : undefined;
|
|
13421
13708
|
if (budgetError !== undefined && trackStageLifecycle && !runtime.state.skippedForParallelFailFast) {
|
|
13422
13709
|
let selectedBudgetError = budgetError;
|
|
13423
|
-
if (runtime.activeStore.runs().find((
|
|
13710
|
+
if (runtime.activeStore.runs().find((run) => run.id === runtime.runId)?.budgetState?.wrapUpCompleted !== true) {
|
|
13424
13711
|
try {
|
|
13425
13712
|
await runtime.budget.deliverWrapUp(runtime.name);
|
|
13426
13713
|
} catch (wrapUpError) {
|
|
@@ -13448,8 +13735,8 @@ function createTrackedStageCaller(input) {
|
|
|
13448
13735
|
};
|
|
13449
13736
|
}
|
|
13450
13737
|
} else if (trackStageLifecycle && !runtime.signal.aborted && !runtime.state.skippedForParallelFailFast) {
|
|
13451
|
-
const
|
|
13452
|
-
applyTerminalStageState = () => applyFailureToStage(runtime.stageSnapshot,
|
|
13738
|
+
const failure = runtime.classifyExecutorFailure(err);
|
|
13739
|
+
applyTerminalStageState = () => applyFailureToStage(runtime.stageSnapshot, failure);
|
|
13453
13740
|
}
|
|
13454
13741
|
throw err;
|
|
13455
13742
|
} finally {
|
|
@@ -13475,12 +13762,20 @@ function createTrackedStageCaller(input) {
|
|
|
13475
13762
|
finalizationError ??= durableCheckpointError;
|
|
13476
13763
|
if (trackStageLifecycle) {
|
|
13477
13764
|
if (durableCheckpointError !== undefined && terminalStateIsSuccess) {
|
|
13478
|
-
const
|
|
13479
|
-
applyTerminalStageState = () => applyFailureToStage(runtime.stageSnapshot,
|
|
13765
|
+
const failure = runtime.classifyExecutorFailure(durableCheckpointError.error);
|
|
13766
|
+
applyTerminalStageState = () => applyFailureToStage(runtime.stageSnapshot, failure);
|
|
13480
13767
|
}
|
|
13481
|
-
if (!runtime.state.stageFinalized)
|
|
13482
|
-
applyTerminalStageState?.();
|
|
13483
13768
|
try {
|
|
13769
|
+
if (terminalStateIsSuccess && runtime.state.readinessController !== undefined) {
|
|
13770
|
+
let pauseVersion;
|
|
13771
|
+
do {
|
|
13772
|
+
pauseVersion = runtime.state.readinessPauseVersion;
|
|
13773
|
+
await runtime.scheduler.waitForStageRelease(runtime.stageId, runtime.releaseLiveHandle);
|
|
13774
|
+
} while (pauseVersion !== runtime.state.readinessPauseVersion);
|
|
13775
|
+
runtime.signal.throwIfAborted();
|
|
13776
|
+
}
|
|
13777
|
+
if (!runtime.state.stageFinalized)
|
|
13778
|
+
applyTerminalStageState?.();
|
|
13484
13779
|
await runtime.finalizeStageSnapshot();
|
|
13485
13780
|
} catch (err) {
|
|
13486
13781
|
finalizationError ??= { thrown: true, error: err };
|
|
@@ -13498,6 +13793,9 @@ function createTrackedStageCaller(input) {
|
|
|
13498
13793
|
input.limiter.release();
|
|
13499
13794
|
if (finalizationError !== undefined)
|
|
13500
13795
|
throwFinalizationError(finalizationError.error);
|
|
13796
|
+
delete runtime.state.readinessController;
|
|
13797
|
+
if (terminalStateIsSuccess && readinessGateEnabled)
|
|
13798
|
+
runtime.signal.throwIfAborted();
|
|
13501
13799
|
}
|
|
13502
13800
|
};
|
|
13503
13801
|
}
|
|
@@ -13734,8 +14032,8 @@ class StageToolExecutionBuffer {
|
|
|
13734
14032
|
// dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts
|
|
13735
14033
|
function createStageControlHandle(runtime) {
|
|
13736
14034
|
const messagePreparation = () => {
|
|
13737
|
-
const
|
|
13738
|
-
if (
|
|
14035
|
+
const meta = runtime.innerCtx.__sessionMeta();
|
|
14036
|
+
if (meta.sessionId !== undefined || meta.sessionFile !== undefined) {
|
|
13739
14037
|
return { beforePreparation: runtime.throwIfStageMutationBlocked };
|
|
13740
14038
|
}
|
|
13741
14039
|
if (runtime.stageSnapshot.sessionFile !== undefined) {
|
|
@@ -13858,15 +14156,29 @@ function createStageControlHandle(runtime) {
|
|
|
13858
14156
|
async pause() {
|
|
13859
14157
|
runtime.throwIfStageMutationBlocked();
|
|
13860
14158
|
const statusBeforePause = runtime.stageSnapshot.status;
|
|
14159
|
+
let readinessPauseVersion;
|
|
14160
|
+
if (runtime.state.readinessController !== undefined) {
|
|
14161
|
+
runtime.scheduler.ensureReleaseBarrier(runtime.stageId);
|
|
14162
|
+
readinessPauseVersion = (runtime.state.readinessPauseVersion ?? 0) + 1;
|
|
14163
|
+
runtime.state.readinessPauseVersion = readinessPauseVersion;
|
|
14164
|
+
}
|
|
13861
14165
|
if (statusBeforePause === "pending" || statusBeforePause === "running" || runtime.innerCtx.isStreaming) {
|
|
13862
|
-
|
|
14166
|
+
try {
|
|
14167
|
+
await runtime.innerCtx.__requestPause();
|
|
14168
|
+
} catch (error) {
|
|
14169
|
+
if (readinessPauseVersion !== undefined && runtime.state.readinessPauseVersion === readinessPauseVersion && runtime.stageSnapshot.status !== "paused" && runtime.stageSnapshot.status !== "blocked" && !runtime.scheduler.hasCascadePauseOwners(runtime.stageId)) {
|
|
14170
|
+
runtime.scheduler.releaseStageBarrier(runtime.stageId);
|
|
14171
|
+
}
|
|
14172
|
+
throw error;
|
|
14173
|
+
}
|
|
13863
14174
|
}
|
|
13864
14175
|
const changed = runtime.activeStore.recordStagePaused(runtime.runId, runtime.stageId);
|
|
13865
14176
|
if (changed) {
|
|
13866
14177
|
runtime.scheduler.ensureReleaseBarrier(runtime.stageId);
|
|
14178
|
+
runtime.state.readinessController?.abort(new Error("atomic-workflows: readiness paused"));
|
|
13867
14179
|
await runtime.scheduler.cascadePauseFrom(runtime.stageId);
|
|
13868
|
-
const
|
|
13869
|
-
const stillActive =
|
|
14180
|
+
const run = runtime.activeStore.runs().find((candidate) => candidate.id === runtime.runId);
|
|
14181
|
+
const stillActive = run?.stages.some((stage) => stage.status === "running" && stage.id !== runtime.stageId) ?? false;
|
|
13870
14182
|
if (!stillActive)
|
|
13871
14183
|
runtime.activeStore.recordRunPaused(runtime.runId);
|
|
13872
14184
|
}
|
|
@@ -13933,6 +14245,7 @@ function createStageControlHandle(runtime) {
|
|
|
13933
14245
|
// dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts
|
|
13934
14246
|
function createReplayStageContext(input) {
|
|
13935
14247
|
const { runId, name, stageId, stageSnapshot, replaySource } = input;
|
|
14248
|
+
workflowObservationRuntime(input.activeStore).replayStageIds.add(workflowActivityNodeKey(runId, stageId));
|
|
13936
14249
|
let replayFinalized = false;
|
|
13937
14250
|
let unregisterWorkflowExitCleanup = () => {};
|
|
13938
14251
|
let stageStartEntryAppended = false;
|
|
@@ -14002,6 +14315,7 @@ function createReplayStageContext(input) {
|
|
|
14002
14315
|
return {
|
|
14003
14316
|
name,
|
|
14004
14317
|
prompt: replayText,
|
|
14318
|
+
__continuePrompt: replayText,
|
|
14005
14319
|
complete: replayText,
|
|
14006
14320
|
sendUserMessage: async () => rejectReplayMutation("send a user message"),
|
|
14007
14321
|
__sendUserMessage: async () => rejectReplayMutation("send a user message"),
|
|
@@ -14026,7 +14340,7 @@ function createReplayStageContext(input) {
|
|
|
14026
14340
|
return replaySource.model;
|
|
14027
14341
|
},
|
|
14028
14342
|
get thinkingLevel() {
|
|
14029
|
-
return;
|
|
14343
|
+
return replaySource.thinkingLevel;
|
|
14030
14344
|
},
|
|
14031
14345
|
get messages() {
|
|
14032
14346
|
return [];
|
|
@@ -14052,6 +14366,7 @@ function createReplayStageContext(input) {
|
|
|
14052
14366
|
__pendingMessageCount: () => 0,
|
|
14053
14367
|
__modelFallbackMeta: () => ({
|
|
14054
14368
|
...replaySource.model !== undefined ? { model: replaySource.model } : {},
|
|
14369
|
+
...replaySource.thinkingLevel !== undefined ? { thinkingLevel: replaySource.thinkingLevel } : {},
|
|
14055
14370
|
...replaySource.attemptedModels !== undefined ? { attemptedModels: replaySource.attemptedModels } : {},
|
|
14056
14371
|
...replaySource.modelAttempts !== undefined ? { modelAttempts: replaySource.modelAttempts } : {}
|
|
14057
14372
|
}),
|
|
@@ -14064,13 +14379,13 @@ function createReplayStageContext(input) {
|
|
|
14064
14379
|
|
|
14065
14380
|
// dist/builtin/workflows/src/durable/run-owner-backend.ts
|
|
14066
14381
|
function durableRootRunIdForRun(runs, runId) {
|
|
14067
|
-
return reciprocalWorkflowRootRunId(new Map(runs.map((
|
|
14382
|
+
return reciprocalWorkflowRootRunId(new Map(runs.map((run) => [run.id, run])), runId);
|
|
14068
14383
|
}
|
|
14069
14384
|
function durableBackendForRun(backend, runs, runId) {
|
|
14070
14385
|
const rootRunId = durableRootRunIdForRun(runs, runId);
|
|
14071
14386
|
if (rootRunId === undefined)
|
|
14072
14387
|
return;
|
|
14073
|
-
const runById = new Map(runs.map((
|
|
14388
|
+
const runById = new Map(runs.map((run) => [run.id, run]));
|
|
14074
14389
|
if (rootRunId === runId)
|
|
14075
14390
|
return backend;
|
|
14076
14391
|
const scopes = [];
|
|
@@ -14093,17 +14408,17 @@ function durableBackendForRun(backend, runs, runId) {
|
|
|
14093
14408
|
}
|
|
14094
14409
|
|
|
14095
14410
|
// dist/builtin/workflows/src/shared/pending-stage-route-capability.ts
|
|
14096
|
-
import { randomUUID as
|
|
14411
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
14097
14412
|
var routeCapabilities = new WeakMap;
|
|
14098
|
-
function workflowPendingStageRouteCapability(
|
|
14099
|
-
let capabilities = routeCapabilities.get(
|
|
14413
|
+
function workflowPendingStageRouteCapability(store, runId) {
|
|
14414
|
+
let capabilities = routeCapabilities.get(store);
|
|
14100
14415
|
if (capabilities === undefined) {
|
|
14101
14416
|
capabilities = new Map;
|
|
14102
|
-
routeCapabilities.set(
|
|
14417
|
+
routeCapabilities.set(store, capabilities);
|
|
14103
14418
|
}
|
|
14104
14419
|
let capability = capabilities.get(runId);
|
|
14105
14420
|
if (capability === undefined) {
|
|
14106
|
-
capability =
|
|
14421
|
+
capability = randomUUID5();
|
|
14107
14422
|
capabilities.set(runId, capability);
|
|
14108
14423
|
}
|
|
14109
14424
|
return capability;
|
|
@@ -14187,7 +14502,7 @@ function parseWorkflowStageTarget(target) {
|
|
|
14187
14502
|
|
|
14188
14503
|
// dist/builtin/workflows/src/shared/pending-stage-status.ts
|
|
14189
14504
|
function workflowBoundaryHops(runs, runId) {
|
|
14190
|
-
const runById = new Map(runs.map((
|
|
14505
|
+
const runById = new Map(runs.map((run) => [run.id, run]));
|
|
14191
14506
|
const hops = [];
|
|
14192
14507
|
let current = runById.get(runId);
|
|
14193
14508
|
while (current !== undefined && current.parentRunId !== undefined) {
|
|
@@ -14246,8 +14561,8 @@ function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageNa
|
|
|
14246
14561
|
let drainPromise;
|
|
14247
14562
|
const pendingReady = () => {
|
|
14248
14563
|
if (readyPromise === undefined) {
|
|
14249
|
-
readyPromise = new Promise((
|
|
14250
|
-
resolveReady =
|
|
14564
|
+
readyPromise = new Promise((resolve, reject) => {
|
|
14565
|
+
resolveReady = resolve;
|
|
14251
14566
|
rejectReady = reject;
|
|
14252
14567
|
});
|
|
14253
14568
|
}
|
|
@@ -14303,7 +14618,7 @@ async function deliverPendingStageMessages(activeStore, runId, stageId, stageNam
|
|
|
14303
14618
|
].map((entry) => entry.id));
|
|
14304
14619
|
const runs = activeStore.runs();
|
|
14305
14620
|
const entries = [
|
|
14306
|
-
...(runs.find((
|
|
14621
|
+
...(runs.find((run) => run.id === runId)?.pendingStageMessages ?? []).map((entry, index) => ({ entry, index })).filter(({ entry }) => candidateIds.has(entry.id) && entry.sticky !== true),
|
|
14307
14622
|
...stickyEntries.map((entry) => ({ entry, index: Number.MAX_SAFE_INTEGER }))
|
|
14308
14623
|
].sort((left, right) => (left.entry.admissionOrder ?? left.index + 1) - (right.entry.admissionOrder ?? right.index + 1) || left.index - right.index).map(({ entry }) => entry);
|
|
14309
14624
|
const rootBackend = getDurableBackend();
|
|
@@ -14347,7 +14662,7 @@ function stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageNam
|
|
|
14347
14662
|
const rootRunId = durableRootRunIdForRun(runs, runId);
|
|
14348
14663
|
if (rootRunId === undefined)
|
|
14349
14664
|
return [];
|
|
14350
|
-
const rootRun = runs.find((
|
|
14665
|
+
const rootRun = runs.find((run) => run.id === rootRunId);
|
|
14351
14666
|
if (rootRun === undefined)
|
|
14352
14667
|
return [];
|
|
14353
14668
|
const hops = workflowBoundaryHops(runs, runId);
|
|
@@ -14365,20 +14680,20 @@ function stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageNam
|
|
|
14365
14680
|
return stageMatchesPathPattern(parsed.segments, hops, [stageId, stageName]);
|
|
14366
14681
|
});
|
|
14367
14682
|
}
|
|
14368
|
-
function claimPendingDelivery(
|
|
14369
|
-
let claims = pendingDeliveryClaims.get(
|
|
14683
|
+
function claimPendingDelivery(store, runId, stageKey, messageId) {
|
|
14684
|
+
let claims = pendingDeliveryClaims.get(store);
|
|
14370
14685
|
if (claims === undefined) {
|
|
14371
14686
|
claims = new Set;
|
|
14372
|
-
pendingDeliveryClaims.set(
|
|
14687
|
+
pendingDeliveryClaims.set(store, claims);
|
|
14373
14688
|
}
|
|
14374
|
-
const
|
|
14375
|
-
if (claims.has(
|
|
14689
|
+
const key = JSON.stringify([runId, stageKey, messageId]);
|
|
14690
|
+
if (claims.has(key))
|
|
14376
14691
|
return;
|
|
14377
|
-
claims.add(
|
|
14692
|
+
claims.add(key);
|
|
14378
14693
|
return () => {
|
|
14379
|
-
claims?.delete(
|
|
14694
|
+
claims?.delete(key);
|
|
14380
14695
|
if (claims?.size === 0)
|
|
14381
|
-
pendingDeliveryClaims.delete(
|
|
14696
|
+
pendingDeliveryClaims.delete(store);
|
|
14382
14697
|
};
|
|
14383
14698
|
}
|
|
14384
14699
|
function toPendingStageSender(entry) {
|
|
@@ -14442,8 +14757,8 @@ class WorkflowModelValidationError extends Error {
|
|
|
14442
14757
|
}
|
|
14443
14758
|
function formatModelValidationError(failures) {
|
|
14444
14759
|
const lines = ["workflows: model validation failed before starting workflow.", "Unavailable or ambiguous models:"];
|
|
14445
|
-
for (const
|
|
14446
|
-
lines.push(`- ${
|
|
14760
|
+
for (const failure of failures) {
|
|
14761
|
+
lines.push(`- ${failure.input} (${failure.reason})`);
|
|
14447
14762
|
}
|
|
14448
14763
|
return lines.join(`
|
|
14449
14764
|
`);
|
|
@@ -14551,10 +14866,10 @@ function buildModelCandidates(input) {
|
|
|
14551
14866
|
failures.push(resolved);
|
|
14552
14867
|
continue;
|
|
14553
14868
|
}
|
|
14554
|
-
const
|
|
14555
|
-
if (seen.has(
|
|
14869
|
+
const key = candidateKey(resolved);
|
|
14870
|
+
if (seen.has(key))
|
|
14556
14871
|
continue;
|
|
14557
|
-
seen.add(
|
|
14872
|
+
seen.add(key);
|
|
14558
14873
|
candidates.push(resolved);
|
|
14559
14874
|
}
|
|
14560
14875
|
if (failures.length > 0)
|
|
@@ -14647,6 +14962,89 @@ class StageDeliveryActivity {
|
|
|
14647
14962
|
}
|
|
14648
14963
|
}
|
|
14649
14964
|
|
|
14965
|
+
// dist/builtin/workflows/src/runs/foreground/stage-runner-artifact-capture.ts
|
|
14966
|
+
class StageArtifactCapture {
|
|
14967
|
+
session;
|
|
14968
|
+
seen = new WeakSet;
|
|
14969
|
+
accepted = [];
|
|
14970
|
+
provisional;
|
|
14971
|
+
receivesMessageEvents = false;
|
|
14972
|
+
closed = false;
|
|
14973
|
+
reset() {
|
|
14974
|
+
this.session = undefined;
|
|
14975
|
+
this.seen = new WeakSet;
|
|
14976
|
+
this.accepted = [];
|
|
14977
|
+
this.provisional = undefined;
|
|
14978
|
+
this.receivesMessageEvents = false;
|
|
14979
|
+
this.closed = false;
|
|
14980
|
+
}
|
|
14981
|
+
beginAttempt(session) {
|
|
14982
|
+
if (this.closed)
|
|
14983
|
+
return;
|
|
14984
|
+
if (this.session === session)
|
|
14985
|
+
this.scan();
|
|
14986
|
+
else {
|
|
14987
|
+
this.session = session;
|
|
14988
|
+
this.receivesMessageEvents = false;
|
|
14989
|
+
this.rememberContext();
|
|
14990
|
+
}
|
|
14991
|
+
this.provisional = [];
|
|
14992
|
+
}
|
|
14993
|
+
settleAttempt(success) {
|
|
14994
|
+
if (this.closed)
|
|
14995
|
+
return;
|
|
14996
|
+
this.scan();
|
|
14997
|
+
if (success)
|
|
14998
|
+
this.accepted.push(...this.provisional ?? []);
|
|
14999
|
+
this.provisional = undefined;
|
|
15000
|
+
}
|
|
15001
|
+
close() {
|
|
15002
|
+
this.scan();
|
|
15003
|
+
this.closed = true;
|
|
15004
|
+
this.session = undefined;
|
|
15005
|
+
this.seen = new WeakSet;
|
|
15006
|
+
this.provisional = undefined;
|
|
15007
|
+
}
|
|
15008
|
+
onEvent(session, event) {
|
|
15009
|
+
if (session !== this.session)
|
|
15010
|
+
return;
|
|
15011
|
+
if (event.type === "message_end") {
|
|
15012
|
+
this.receivesMessageEvents = true;
|
|
15013
|
+
this.capture(event.message);
|
|
15014
|
+
}
|
|
15015
|
+
if (event.type === "compaction_end")
|
|
15016
|
+
this.rememberContext();
|
|
15017
|
+
}
|
|
15018
|
+
messages() {
|
|
15019
|
+
this.scan();
|
|
15020
|
+
return this.accepted;
|
|
15021
|
+
}
|
|
15022
|
+
rememberContext(session = this.session) {
|
|
15023
|
+
if (session !== this.session)
|
|
15024
|
+
return;
|
|
15025
|
+
for (const message of this.session?.messages ?? [])
|
|
15026
|
+
this.seen.add(message);
|
|
15027
|
+
}
|
|
15028
|
+
scan() {
|
|
15029
|
+
if (this.receivesMessageEvents)
|
|
15030
|
+
return;
|
|
15031
|
+
for (const message of this.session?.messages ?? [])
|
|
15032
|
+
this.capture(message);
|
|
15033
|
+
}
|
|
15034
|
+
capture(message) {
|
|
15035
|
+
if (this.seen.has(message))
|
|
15036
|
+
return;
|
|
15037
|
+
this.seen.add(message);
|
|
15038
|
+
if (message.role !== "assistant")
|
|
15039
|
+
return;
|
|
15040
|
+
if (message.stopReason !== "stop" && message.stopReason !== "length")
|
|
15041
|
+
return;
|
|
15042
|
+
if (message.content.some((block) => block.type === "toolCall"))
|
|
15043
|
+
return;
|
|
15044
|
+
(this.provisional ?? this.accepted).push(structuredClone(message));
|
|
15045
|
+
}
|
|
15046
|
+
}
|
|
15047
|
+
|
|
14650
15048
|
// dist/builtin/workflows/src/runs/foreground/stage-runner-candidate.ts
|
|
14651
15049
|
function effectiveCandidateReasoning(candidate, fallback) {
|
|
14652
15050
|
return candidate.reasoningLevel ?? fallback;
|
|
@@ -14852,6 +15250,23 @@ function extractMessageText(message) {
|
|
|
14852
15250
|
}
|
|
14853
15251
|
return "";
|
|
14854
15252
|
}
|
|
15253
|
+
function assistantArtifactTextForGeneration(messages) {
|
|
15254
|
+
const answers = messages.flatMap((message) => {
|
|
15255
|
+
if (message.role !== "assistant")
|
|
15256
|
+
return [];
|
|
15257
|
+
if (message.stopReason !== "stop" && message.stopReason !== "length")
|
|
15258
|
+
return [];
|
|
15259
|
+
if (message.content.some((block) => block.type === "toolCall"))
|
|
15260
|
+
return [];
|
|
15261
|
+
const text = extractMessageText(message);
|
|
15262
|
+
return text.length > 0 ? [text] : [];
|
|
15263
|
+
});
|
|
15264
|
+
return answers.map((text, index) => index === 0 ? text : `
|
|
15265
|
+
|
|
15266
|
+
## Supplement ${index}
|
|
15267
|
+
|
|
15268
|
+
${text}`).join("");
|
|
15269
|
+
}
|
|
14855
15270
|
function lastAssistantTextFromMessages(messages) {
|
|
14856
15271
|
for (let index = messages.length - 1;index >= 0; index -= 1) {
|
|
14857
15272
|
const message = messages[index];
|
|
@@ -14872,7 +15287,7 @@ function structuredOutputTurnDetail(messages, startIndex) {
|
|
|
14872
15287
|
}
|
|
14873
15288
|
return "The model produced no assistant message after the prompt";
|
|
14874
15289
|
}
|
|
14875
|
-
function assistantArtifactTextForToolCall(messages,
|
|
15290
|
+
function assistantArtifactTextForToolCall(messages, toolCallId) {
|
|
14876
15291
|
for (let index = messages.length - 1;index >= 0; index -= 1) {
|
|
14877
15292
|
const message = messages[index];
|
|
14878
15293
|
if (message?.role !== "assistant")
|
|
@@ -14880,7 +15295,7 @@ function assistantArtifactTextForToolCall(messages, toolCallId2) {
|
|
|
14880
15295
|
const { content } = message;
|
|
14881
15296
|
if (!Array.isArray(content))
|
|
14882
15297
|
continue;
|
|
14883
|
-
if (!content.some((block) => block.type === "toolCall" && block.id ===
|
|
15298
|
+
if (!content.some((block) => block.type === "toolCall" && block.id === toolCallId))
|
|
14884
15299
|
continue;
|
|
14885
15300
|
const text = extractMessageText(message);
|
|
14886
15301
|
if (text.trim().length > 0)
|
|
@@ -14955,8 +15370,8 @@ function terminatingToolResultText(messages, terminatingToolCallIds) {
|
|
|
14955
15370
|
if (!message)
|
|
14956
15371
|
continue;
|
|
14957
15372
|
if (message.role === "toolResult") {
|
|
14958
|
-
const
|
|
14959
|
-
if (typeof
|
|
15373
|
+
const toolCallId = message.toolCallId;
|
|
15374
|
+
if (typeof toolCallId !== "string" || !terminatingToolCallIds.has(toolCallId)) {
|
|
14960
15375
|
return;
|
|
14961
15376
|
}
|
|
14962
15377
|
const text = extractMessageText(message).trim();
|
|
@@ -14989,27 +15404,27 @@ function assistantMessage(text) {
|
|
|
14989
15404
|
|
|
14990
15405
|
// dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts
|
|
14991
15406
|
import { SessionManager } from "@bastani/atomic";
|
|
14992
|
-
function workflowSessionOptions(
|
|
15407
|
+
function workflowSessionOptions(meta) {
|
|
14993
15408
|
return {
|
|
14994
15409
|
internal: true,
|
|
14995
|
-
workflow: { runId:
|
|
15410
|
+
workflow: { runId: meta.runId, stageId: meta.stageId, stageName: meta.stageName }
|
|
14996
15411
|
};
|
|
14997
15412
|
}
|
|
14998
|
-
function workflowOrchestrationContext(
|
|
15413
|
+
function workflowOrchestrationContext(meta, stageOptions, pendingStageDelivery) {
|
|
14999
15414
|
const base = {
|
|
15000
15415
|
kind: "workflow-stage",
|
|
15001
|
-
workflowRunId:
|
|
15002
|
-
workflowStageId:
|
|
15003
|
-
workflowStageName:
|
|
15416
|
+
workflowRunId: meta.runId,
|
|
15417
|
+
workflowStageId: meta.stageId,
|
|
15418
|
+
workflowStageName: meta.stageName,
|
|
15004
15419
|
constraints: { disableWorkflowTool: true }
|
|
15005
15420
|
};
|
|
15006
|
-
const intercomGroup = stageHasIntercomAccess(stageOptions) ? resolveStageGroup(stageOptions,
|
|
15421
|
+
const intercomGroup = stageHasIntercomAccess(stageOptions) ? resolveStageGroup(stageOptions, meta.workflowIntercomGroup) : undefined;
|
|
15007
15422
|
const context = intercomGroup ? { ...base, intercomGroup } : base;
|
|
15008
15423
|
return pendingStageDelivery === undefined ? context : { ...context, pendingStageDelivery };
|
|
15009
15424
|
}
|
|
15010
|
-
function stripWorkflowOnlyOptions(options, defaultSessionDir,
|
|
15011
|
-
const classification = workflowSessionOptions(
|
|
15012
|
-
const orchestrationContext = workflowOrchestrationContext(
|
|
15425
|
+
function stripWorkflowOnlyOptions(options, defaultSessionDir, meta, pendingStageDelivery) {
|
|
15426
|
+
const classification = workflowSessionOptions(meta);
|
|
15427
|
+
const orchestrationContext = workflowOrchestrationContext(meta, options, pendingStageDelivery);
|
|
15013
15428
|
if (!options) {
|
|
15014
15429
|
return defaultSessionDir === undefined ? { orchestrationContext } : {
|
|
15015
15430
|
orchestrationContext,
|
|
@@ -15090,7 +15505,8 @@ class StageSessionPause {
|
|
|
15090
15505
|
abortBoundary: Promise.withResolvers(),
|
|
15091
15506
|
runnerOwnedDeliveries: new Set,
|
|
15092
15507
|
confirmed: false,
|
|
15093
|
-
...nativeQueuePause === undefined ? {} : { nativeQueuePause }
|
|
15508
|
+
...nativeQueuePause === undefined ? {} : { nativeQueuePause },
|
|
15509
|
+
...session?.pauseTasks && session.resumeTasks ? { taskControl: session } : {}
|
|
15094
15510
|
};
|
|
15095
15511
|
request.deferred.promise.catch(() => {});
|
|
15096
15512
|
request.abortBoundary.promise.catch(() => {});
|
|
@@ -15098,7 +15514,11 @@ class StageSessionPause {
|
|
|
15098
15514
|
let failed = false;
|
|
15099
15515
|
try {
|
|
15100
15516
|
request.nativeQueuePause?.pauseQueuedMessages();
|
|
15101
|
-
|
|
15517
|
+
const tasks = request.taskControl?.pauseTasks?.();
|
|
15518
|
+
const settled = await Promise.allSettled([tasks, (async () => session?.abort())()]);
|
|
15519
|
+
for (const result of settled)
|
|
15520
|
+
if (result.status === "rejected")
|
|
15521
|
+
throw result.reason;
|
|
15102
15522
|
request.abortBoundary.resolve();
|
|
15103
15523
|
await request.abortBoundary.promise;
|
|
15104
15524
|
request.confirmed = true;
|
|
@@ -15106,6 +15526,7 @@ class StageSessionPause {
|
|
|
15106
15526
|
failed = true;
|
|
15107
15527
|
request.abortBoundary.reject(error);
|
|
15108
15528
|
request.deferred.reject(error);
|
|
15529
|
+
request.taskControl?.resumeTasks?.();
|
|
15109
15530
|
await this.rollbackNativePause(request.nativeQueuePause);
|
|
15110
15531
|
throw error;
|
|
15111
15532
|
} finally {
|
|
@@ -15173,6 +15594,7 @@ class StageSessionPause {
|
|
|
15173
15594
|
if (releaseAdmitted)
|
|
15174
15595
|
return;
|
|
15175
15596
|
beforeRelease?.();
|
|
15597
|
+
request.taskControl?.resumeTasks?.();
|
|
15176
15598
|
releaseAdmitted = true;
|
|
15177
15599
|
};
|
|
15178
15600
|
let releasedQueuedMessages;
|
|
@@ -15227,16 +15649,37 @@ function stageSessionExtensionRunner(current) {
|
|
|
15227
15649
|
}
|
|
15228
15650
|
return;
|
|
15229
15651
|
}
|
|
15652
|
+
var shutdowns = new WeakMap;
|
|
15653
|
+
function shutdownStageSession(current) {
|
|
15654
|
+
if (!current)
|
|
15655
|
+
return Promise.resolve();
|
|
15656
|
+
const existing = shutdowns.get(current);
|
|
15657
|
+
if (existing)
|
|
15658
|
+
return existing;
|
|
15659
|
+
const shutdown = Promise.resolve().then(async () => {
|
|
15660
|
+
const runner = stageSessionExtensionRunner(current);
|
|
15661
|
+
if (runner?.hasHandlers("session_shutdown"))
|
|
15662
|
+
await runner.emit({ type: "session_shutdown", reason: "quit" });
|
|
15663
|
+
});
|
|
15664
|
+
shutdowns.set(current, shutdown);
|
|
15665
|
+
return shutdown;
|
|
15666
|
+
}
|
|
15667
|
+
|
|
15668
|
+
class StageSessionBindingCleanupFailure extends AggregateError {
|
|
15669
|
+
constructor(bindingError, cleanupErrors) {
|
|
15670
|
+
super([bindingError, ...cleanupErrors], "atomic-workflows: failed binding cleanup did not release session ownership", {
|
|
15671
|
+
cause: bindingError
|
|
15672
|
+
});
|
|
15673
|
+
this.name = "StageSessionBindingCleanupFailure";
|
|
15674
|
+
}
|
|
15675
|
+
}
|
|
15230
15676
|
async function disposeStageSession(current) {
|
|
15231
15677
|
if (!current)
|
|
15232
15678
|
return;
|
|
15233
|
-
|
|
15234
|
-
|
|
15235
|
-
|
|
15236
|
-
|
|
15237
|
-
} catch (error) {
|
|
15238
|
-
console.error("atomic-workflows: stage session_shutdown handler failed", error);
|
|
15239
|
-
}
|
|
15679
|
+
try {
|
|
15680
|
+
await shutdownStageSession(current);
|
|
15681
|
+
} catch (error) {
|
|
15682
|
+
console.error("atomic-workflows: stage session_shutdown handler failed", error);
|
|
15240
15683
|
}
|
|
15241
15684
|
await current.dispose();
|
|
15242
15685
|
}
|
|
@@ -15269,6 +15712,9 @@ async function rejectDisposedCreatedSession(result, stageName) {
|
|
|
15269
15712
|
class StageSessionReplacement {
|
|
15270
15713
|
previous;
|
|
15271
15714
|
cleanups = new Set;
|
|
15715
|
+
get retiringSession() {
|
|
15716
|
+
return this.previous;
|
|
15717
|
+
}
|
|
15272
15718
|
retire(session) {
|
|
15273
15719
|
this.previous = session;
|
|
15274
15720
|
}
|
|
@@ -15348,30 +15794,31 @@ async function sendStageUserMessage(activeSession, content, options, beforeDeliv
|
|
|
15348
15794
|
if (activeSession.sendUserMessage !== undefined) {
|
|
15349
15795
|
beforeDelivery?.();
|
|
15350
15796
|
let reportedAction;
|
|
15351
|
-
const
|
|
15352
|
-
|
|
15353
|
-
const
|
|
15797
|
+
const ownership = streaming ? undefined : admission === undefined ? createLocalPromptOwnershipObserver(activeSession, promptStarted) : coordinatedPromptOwnershipObserver(admission.startTurn(activeSession, promptStarted ?? (() => {})));
|
|
15798
|
+
ownership?.arm();
|
|
15799
|
+
const deliveryId = streaming ? undefined : activity?.start();
|
|
15354
15800
|
try {
|
|
15355
15801
|
const delivery = activeSession.sendUserMessage(content, {
|
|
15356
15802
|
...deliverAs === undefined ? {} : { deliverAs },
|
|
15803
|
+
...options?.expandPromptTemplates === undefined ? {} : { expandPromptTemplates: options.expandPromptTemplates },
|
|
15357
15804
|
__workflowDelivery: {
|
|
15358
|
-
promptStarted:
|
|
15359
|
-
delivered(
|
|
15360
|
-
reportedAction =
|
|
15805
|
+
promptStarted: ownership?.observe ?? promptStarted,
|
|
15806
|
+
delivered(action) {
|
|
15807
|
+
reportedAction = action;
|
|
15361
15808
|
}
|
|
15362
15809
|
}
|
|
15363
15810
|
});
|
|
15364
|
-
|
|
15811
|
+
ownership?.observeStreaming();
|
|
15365
15812
|
await delivery;
|
|
15366
15813
|
const action = reportedAction ?? (streaming ? deliverAs ?? "followUp" : "prompt");
|
|
15367
|
-
|
|
15814
|
+
ownership?.settle(action);
|
|
15368
15815
|
return action;
|
|
15369
15816
|
} catch (error) {
|
|
15370
|
-
|
|
15817
|
+
ownership?.settle();
|
|
15371
15818
|
throw error;
|
|
15372
15819
|
} finally {
|
|
15373
|
-
|
|
15374
|
-
activity?.settle(
|
|
15820
|
+
ownership?.dispose();
|
|
15821
|
+
activity?.settle(deliveryId);
|
|
15375
15822
|
}
|
|
15376
15823
|
}
|
|
15377
15824
|
if (typeof content !== "string")
|
|
@@ -15629,6 +16076,8 @@ class StageSessionController {
|
|
|
15629
16076
|
abortReason;
|
|
15630
16077
|
abortReasonGeneration = 0;
|
|
15631
16078
|
sessionPromise;
|
|
16079
|
+
sessionShutdownPromise;
|
|
16080
|
+
bindingCleanupFailure;
|
|
15632
16081
|
reattachSessionFile;
|
|
15633
16082
|
lastPromptStartIndex;
|
|
15634
16083
|
attemptUsageStartIndex;
|
|
@@ -15652,7 +16101,7 @@ class StageSessionController {
|
|
|
15652
16101
|
pendingThinkingLevel;
|
|
15653
16102
|
pendingListeners = new Set;
|
|
15654
16103
|
listenerUnsubscribes = new Map;
|
|
15655
|
-
pauseControl = new StageSessionPause(() => this.session);
|
|
16104
|
+
pauseControl = new StageSessionPause(() => this.session ?? this.replacement.retiringSession);
|
|
15656
16105
|
hasExplicitModelFallbackConfig;
|
|
15657
16106
|
candidatesPromise;
|
|
15658
16107
|
activeCandidateIndex;
|
|
@@ -15671,9 +16120,25 @@ class StageSessionController {
|
|
|
15671
16120
|
pendingCreationResumeMessage;
|
|
15672
16121
|
messageAdmission = new StageMessageAdmission;
|
|
15673
16122
|
deliveryActivity = new StageDeliveryActivity;
|
|
15674
|
-
|
|
16123
|
+
artifactCapture = new StageArtifactCapture;
|
|
16124
|
+
beginOutputGeneration() {
|
|
16125
|
+
this.artifactCapture.reset();
|
|
16126
|
+
}
|
|
16127
|
+
outputGenerationMessages() {
|
|
16128
|
+
return this.artifactCapture.messages();
|
|
16129
|
+
}
|
|
16130
|
+
async navigateTree(...args) {
|
|
16131
|
+
const session = await this.ensureSession();
|
|
16132
|
+
this.artifactCapture.messages();
|
|
16133
|
+
try {
|
|
16134
|
+
return await session.navigateTree(...args);
|
|
16135
|
+
} finally {
|
|
16136
|
+
this.artifactCapture.rememberContext(session);
|
|
16137
|
+
}
|
|
16138
|
+
}
|
|
16139
|
+
constructor(opts, meta, effectiveStageOptions, structuredOutputCapture) {
|
|
15675
16140
|
this.opts = opts;
|
|
15676
|
-
this.meta =
|
|
16141
|
+
this.meta = meta;
|
|
15677
16142
|
this.effectiveStageOptions = effectiveStageOptions;
|
|
15678
16143
|
this.structuredOutputCapture = structuredOutputCapture;
|
|
15679
16144
|
this.hasExplicitModelFallbackConfig = effectiveStageOptions?.model !== undefined || (effectiveStageOptions?.fallbackModels?.length ?? 0) > 0;
|
|
@@ -15729,8 +16194,7 @@ class StageSessionController {
|
|
|
15729
16194
|
this.pendingFallbackWarnings.push(`[fallback] ${candidateLabel(candidate)} failed: ${error}. Retrying with ${candidateLabel(nextCandidate)}.`);
|
|
15730
16195
|
this.modelWarnings.push(...this.pendingFallbackWarnings);
|
|
15731
16196
|
this.pendingFallbackWarnings.length = 0;
|
|
15732
|
-
await this.disposeCurrentSession();
|
|
15733
|
-
this.activeCandidateIndex = index + 1;
|
|
16197
|
+
await this.disposeCurrentSession(index + 1);
|
|
15734
16198
|
this.notifyModelFallbackMetaChange();
|
|
15735
16199
|
return true;
|
|
15736
16200
|
}
|
|
@@ -15758,6 +16222,14 @@ class StageSessionController {
|
|
|
15758
16222
|
this.session?.setThinkingLevel(level);
|
|
15759
16223
|
}
|
|
15760
16224
|
async ensureSession(consumer = "prompt") {
|
|
16225
|
+
if (this.bindingCleanupFailure !== undefined)
|
|
16226
|
+
throw this.bindingCleanupFailure;
|
|
16227
|
+
if (this.sessionShutdownPromise !== undefined) {
|
|
16228
|
+
const generation = this.abortGeneration;
|
|
16229
|
+
await this.sessionShutdownPromise;
|
|
16230
|
+
if (this.disposed || this.opts.signal?.aborted || this.abortGeneration !== generation)
|
|
16231
|
+
throw this.staleCreationReason(generation);
|
|
16232
|
+
}
|
|
15761
16233
|
if (this.disposed)
|
|
15762
16234
|
throw new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
15763
16235
|
if (this.session !== undefined)
|
|
@@ -15772,14 +16244,16 @@ class StageSessionController {
|
|
|
15772
16244
|
};
|
|
15773
16245
|
pending.then(release, () => {
|
|
15774
16246
|
release();
|
|
15775
|
-
if (this.sessionPromise === pending)
|
|
16247
|
+
if (this.sessionPromise === pending) {
|
|
15776
16248
|
this.sessionPromise = undefined;
|
|
16249
|
+
this.activeCandidateIndex = undefined;
|
|
16250
|
+
}
|
|
15777
16251
|
});
|
|
15778
16252
|
}
|
|
15779
16253
|
return this.sessionPromise;
|
|
15780
16254
|
}
|
|
15781
16255
|
async ensureSessionFromFile(sessionFile, consumer = "prompt") {
|
|
15782
|
-
if (!this.sessionPromise && !this.session)
|
|
16256
|
+
if (!this.sessionShutdownPromise && !this.sessionPromise && !this.session)
|
|
15783
16257
|
this.reattachSessionFile = sessionFile;
|
|
15784
16258
|
const session = await this.ensureSession(consumer);
|
|
15785
16259
|
await session.closeWorkflowStageGeneration?.();
|
|
@@ -15796,10 +16270,10 @@ class StageSessionController {
|
|
|
15796
16270
|
const sessionFile = preparation?.sessionFile;
|
|
15797
16271
|
const deliver = async (activity) => {
|
|
15798
16272
|
const activeSession = sessionFile === undefined ? await this.ensureSession("prompt") : await this.ensureSessionFromFile(sessionFile, "prompt");
|
|
15799
|
-
const
|
|
15800
|
-
if (
|
|
16273
|
+
const pausedDelivery = this.pauseControl.deferRunnerOwnedDelivery(() => sendStageUserMessage(activeSession, content, options, beforeDelivery, release, this.messageAdmission, activity));
|
|
16274
|
+
if (pausedDelivery !== undefined) {
|
|
15801
16275
|
release();
|
|
15802
|
-
return
|
|
16276
|
+
return pausedDelivery;
|
|
15803
16277
|
}
|
|
15804
16278
|
return sendStageUserMessage(activeSession, content, options, beforeDelivery, release, this.messageAdmission, activity);
|
|
15805
16279
|
};
|
|
@@ -15821,18 +16295,19 @@ class StageSessionController {
|
|
|
15821
16295
|
const pending = this.activeCreation ?? this.sessionPromise;
|
|
15822
16296
|
const session = pending ? await pending : this.session;
|
|
15823
16297
|
await session?.closeWorkflowStageGeneration?.();
|
|
16298
|
+
this.artifactCapture.close();
|
|
15824
16299
|
}
|
|
15825
16300
|
async promptWithFallback(text, sdkOptions, consumer = "prompt") {
|
|
15826
16301
|
if (!this.hasExplicitModelFallbackConfig) {
|
|
15827
16302
|
try {
|
|
15828
16303
|
const activeSession = await this.ensureSession(consumer);
|
|
15829
|
-
const
|
|
16304
|
+
const resumedText = this.pendingCreationResumeMessage;
|
|
15830
16305
|
this.pendingCreationResumeMessage = undefined;
|
|
15831
16306
|
const value = activeSession.model ?? "default";
|
|
15832
16307
|
const candidate = { id: workflowModelId(value) ?? "default", value };
|
|
15833
16308
|
this.beginAttemptUsage(activeSession);
|
|
15834
16309
|
try {
|
|
15835
|
-
await this.promptWithThrownErrorRetry(activeSession,
|
|
16310
|
+
await this.promptWithThrownErrorRetry(activeSession, resumedText ?? text, sdkOptions);
|
|
15836
16311
|
} catch (error) {
|
|
15837
16312
|
await this.handleCandidateFailure(error, candidate, [candidate], 0);
|
|
15838
16313
|
throw error;
|
|
@@ -15849,10 +16324,12 @@ class StageSessionController {
|
|
|
15849
16324
|
if (candidates.length === 0) {
|
|
15850
16325
|
try {
|
|
15851
16326
|
const activeSession = await this.ensureSession(consumer);
|
|
15852
|
-
const
|
|
16327
|
+
const resumedText = this.pendingCreationResumeMessage;
|
|
15853
16328
|
this.pendingCreationResumeMessage = undefined;
|
|
15854
|
-
await this.promptWithThrownErrorRetry(activeSession,
|
|
16329
|
+
await this.promptWithThrownErrorRetry(activeSession, resumedText ?? text, sdkOptions);
|
|
16330
|
+
this.artifactCapture.settleAttempt(true);
|
|
15855
16331
|
} catch (error) {
|
|
16332
|
+
this.artifactCapture.settleAttempt(false);
|
|
15856
16333
|
if (error instanceof StageSessionCreationCancelled)
|
|
15857
16334
|
return;
|
|
15858
16335
|
throw error;
|
|
@@ -15874,6 +16351,18 @@ class StageSessionController {
|
|
|
15874
16351
|
return;
|
|
15875
16352
|
let index = this.activeCandidateIndex ?? 0;
|
|
15876
16353
|
while (index < candidates.length) {
|
|
16354
|
+
if (this.session === undefined && this.ownedCreationPromise !== undefined) {
|
|
16355
|
+
try {
|
|
16356
|
+
await this.ownedCreationPromise;
|
|
16357
|
+
} catch (error) {
|
|
16358
|
+
if (error instanceof StageSessionCreationCancelled)
|
|
16359
|
+
return;
|
|
16360
|
+
throw error;
|
|
16361
|
+
}
|
|
16362
|
+
index = this.activeCandidateIndex ?? index;
|
|
16363
|
+
promptText = this.pendingCreationResumeMessage ?? promptText;
|
|
16364
|
+
this.pendingCreationResumeMessage = undefined;
|
|
16365
|
+
}
|
|
15877
16366
|
const candidate = candidates[index];
|
|
15878
16367
|
try {
|
|
15879
16368
|
const created = this.session && this.activeCandidateIndex === index ? this.session : await this.createSessionWithThrownErrorRetry(candidate, consumer);
|
|
@@ -15900,10 +16389,10 @@ class StageSessionController {
|
|
|
15900
16389
|
this.recordSuccessfulAttempt(candidate);
|
|
15901
16390
|
return;
|
|
15902
16391
|
} catch (err) {
|
|
15903
|
-
const
|
|
15904
|
-
if (
|
|
16392
|
+
const failure = await this.handleCandidateFailure(err, candidate, candidates, index);
|
|
16393
|
+
if (failure === "handled")
|
|
15905
16394
|
return;
|
|
15906
|
-
if (
|
|
16395
|
+
if (failure === "throw")
|
|
15907
16396
|
throw err;
|
|
15908
16397
|
index += 1;
|
|
15909
16398
|
}
|
|
@@ -15912,8 +16401,10 @@ class StageSessionController {
|
|
|
15912
16401
|
currentModelFallbackMeta() {
|
|
15913
16402
|
const attemptedModels = this.modelAttempts.map((attempt) => attempt.model);
|
|
15914
16403
|
const model = this.selectedModel ?? workflowModelId(this.session?.model);
|
|
16404
|
+
const thinkingLevel = this.session?.thinkingLevel ?? this.pendingThinkingLevel;
|
|
15915
16405
|
return {
|
|
15916
16406
|
...model !== undefined ? { model } : {},
|
|
16407
|
+
...thinkingLevel !== undefined ? { thinkingLevel } : {},
|
|
15917
16408
|
...attemptedModels.length > 0 ? { attemptedModels } : {},
|
|
15918
16409
|
...this.modelAttempts.length > 0 ? { modelAttempts: [...this.modelAttempts] } : {},
|
|
15919
16410
|
...this.modelWarnings.length > 0 ? { warnings: [...this.modelWarnings] } : {}
|
|
@@ -15997,14 +16488,14 @@ class StageSessionController {
|
|
|
15997
16488
|
const { signal } = this.opts;
|
|
15998
16489
|
if (!signal)
|
|
15999
16490
|
return;
|
|
16000
|
-
const
|
|
16491
|
+
const abortReason = () => {
|
|
16001
16492
|
const reason = signal.reason;
|
|
16002
16493
|
if (reason instanceof Error || reason instanceof DOMException || typeof reason === "string")
|
|
16003
16494
|
return reason;
|
|
16004
16495
|
return new DOMException("workflow killed", "AbortError");
|
|
16005
16496
|
};
|
|
16006
16497
|
const onAbort = () => {
|
|
16007
|
-
const reason =
|
|
16498
|
+
const reason = abortReason();
|
|
16008
16499
|
this.markAbort(reason);
|
|
16009
16500
|
this.session?.abort().catch(() => {});
|
|
16010
16501
|
this.pauseControl.reject(reason);
|
|
@@ -16144,6 +16635,7 @@ class StageSessionController {
|
|
|
16144
16635
|
let retainedPrompt;
|
|
16145
16636
|
let terminalScanStartIndex;
|
|
16146
16637
|
while (true) {
|
|
16638
|
+
this.artifactCapture.beginAttempt(activeSession);
|
|
16147
16639
|
const messagesBeforeAttempt = [...activeSession.messages];
|
|
16148
16640
|
try {
|
|
16149
16641
|
if (retryAdmittedPrompt) {
|
|
@@ -16186,6 +16678,7 @@ class StageSessionController {
|
|
|
16186
16678
|
const willRetry = decision !== undefined && !this.disposed && this.opts.signal?.aborted !== true && !this.capturedStructuredOutputForAttempt();
|
|
16187
16679
|
const willContinue = continuationSession !== undefined && admittedMessages;
|
|
16188
16680
|
if (retryableFailure && willRetry) {
|
|
16681
|
+
this.artifactCapture.settleAttempt(false);
|
|
16189
16682
|
retainedPrompt = this.restoreSessionMessages(activeSession, messagesBeforeAttempt, nextText, willContinue) ?? retainedPrompt;
|
|
16190
16683
|
}
|
|
16191
16684
|
if (!willRetry)
|
|
@@ -16261,7 +16754,8 @@ class StageSessionController {
|
|
|
16261
16754
|
return this.createSessionObservingPause(undefined, consumer).catch((error) => this.createInitialSessionWithRetry(undefined, consumer, { error }));
|
|
16262
16755
|
}
|
|
16263
16756
|
const candidates = await this.modelCandidates();
|
|
16264
|
-
const
|
|
16757
|
+
const initialIndex = this.activeCandidateIndex ?? 0;
|
|
16758
|
+
const first = candidates[initialIndex];
|
|
16265
16759
|
if (first === undefined) {
|
|
16266
16760
|
return this.createSessionObservingPause(undefined, consumer).catch((error) => this.createInitialSessionWithRetry(undefined, consumer, { error }));
|
|
16267
16761
|
}
|
|
@@ -16274,9 +16768,9 @@ class StageSessionController {
|
|
|
16274
16768
|
this.resumeCurrentSession = true;
|
|
16275
16769
|
return resumed;
|
|
16276
16770
|
}
|
|
16277
|
-
this.activeCandidateIndex =
|
|
16771
|
+
this.activeCandidateIndex = initialIndex;
|
|
16278
16772
|
this.selectedModel = first.id;
|
|
16279
|
-
return this.createSessionObservingPause(first, consumer).catch((error) => this.createInitialSessionCandidateWalk(candidates, consumer,
|
|
16773
|
+
return this.createSessionObservingPause(first, consumer).catch((error) => this.createInitialSessionCandidateWalk(candidates, consumer, initialIndex, { error }));
|
|
16280
16774
|
}
|
|
16281
16775
|
async createInitialSessionCandidateWalk(candidates, consumer, startIndex, initialFailure) {
|
|
16282
16776
|
let index = startIndex;
|
|
@@ -16352,12 +16846,14 @@ class StageSessionController {
|
|
|
16352
16846
|
while (true) {
|
|
16353
16847
|
try {
|
|
16354
16848
|
if (pendingFailure !== undefined) {
|
|
16355
|
-
const
|
|
16849
|
+
const failure = pendingFailure;
|
|
16356
16850
|
pendingFailure = undefined;
|
|
16357
|
-
throw
|
|
16851
|
+
throw failure.error;
|
|
16358
16852
|
}
|
|
16359
16853
|
return await this.createSessionObservingPause(candidate, consumer);
|
|
16360
16854
|
} catch (error) {
|
|
16855
|
+
if (error instanceof StageSessionBindingCleanupFailure)
|
|
16856
|
+
throw error;
|
|
16361
16857
|
const errorSettingsManager = retrySettingsManagerFromError(error);
|
|
16362
16858
|
if (errorSettingsManager !== undefined)
|
|
16363
16859
|
this.sessionSettingsManager = errorSettingsManager;
|
|
@@ -16391,6 +16887,20 @@ class StageSessionController {
|
|
|
16391
16887
|
}
|
|
16392
16888
|
}
|
|
16393
16889
|
createSession(candidate, consumer, resumeOptions) {
|
|
16890
|
+
if (this.bindingCleanupFailure !== undefined)
|
|
16891
|
+
return Promise.reject(this.bindingCleanupFailure);
|
|
16892
|
+
if (this.sessionShutdownPromise !== undefined) {
|
|
16893
|
+
const generation = this.abortGeneration;
|
|
16894
|
+
return this.sessionShutdownPromise.then(() => {
|
|
16895
|
+
if (this.disposed || this.opts.signal?.aborted || this.abortGeneration !== generation)
|
|
16896
|
+
throw this.staleCreationReason(generation);
|
|
16897
|
+
return this.createSession(candidate, consumer, resumeOptions);
|
|
16898
|
+
});
|
|
16899
|
+
}
|
|
16900
|
+
if (this.activeCreation !== undefined)
|
|
16901
|
+
return this.activeCreation;
|
|
16902
|
+
if (this.session !== undefined)
|
|
16903
|
+
return Promise.resolve(this.session);
|
|
16394
16904
|
const creation = this.createSessionAttempt(candidate, consumer, resumeOptions);
|
|
16395
16905
|
this.activeCreation = creation;
|
|
16396
16906
|
creation.finally(() => {
|
|
@@ -16417,6 +16927,10 @@ class StageSessionController {
|
|
|
16417
16927
|
...this.sharedOrchestrationContext !== undefined ? { orchestrationContext: this.sharedOrchestrationContext } : {}
|
|
16418
16928
|
}) : missingAdapter(consumer);
|
|
16419
16929
|
} catch (error) {
|
|
16930
|
+
if (error instanceof StageSessionBindingCleanupFailure) {
|
|
16931
|
+
this.bindingCleanupFailure = error;
|
|
16932
|
+
throw error;
|
|
16933
|
+
}
|
|
16420
16934
|
if (this.disposed || this.opts.signal?.aborted === true || this.abortGeneration !== startGeneration)
|
|
16421
16935
|
throw this.disposed ? new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`) : this.staleCreationReason(startGeneration);
|
|
16422
16936
|
throw error;
|
|
@@ -16471,6 +16985,7 @@ class StageSessionController {
|
|
|
16471
16985
|
}
|
|
16472
16986
|
this.unsubscribeTerminateWatcher?.();
|
|
16473
16987
|
this.unsubscribeTerminateWatcher = result.session.subscribe((event) => {
|
|
16988
|
+
this.artifactCapture.onEvent(result.session, event);
|
|
16474
16989
|
const terminatingId = terminatingToolCallId(event);
|
|
16475
16990
|
if (terminatingId !== undefined)
|
|
16476
16991
|
this.terminatingToolCallIds.add(terminatingId);
|
|
@@ -16479,12 +16994,16 @@ class StageSessionController {
|
|
|
16479
16994
|
});
|
|
16480
16995
|
return result.session;
|
|
16481
16996
|
}
|
|
16482
|
-
async disposeCurrentSession() {
|
|
16997
|
+
async disposeCurrentSession(nextCandidateIndex) {
|
|
16998
|
+
if (this.sessionShutdownPromise !== undefined)
|
|
16999
|
+
await this.sessionShutdownPromise;
|
|
17000
|
+
const startGeneration = this.abortGeneration;
|
|
16483
17001
|
this.abortThrownErrorRetries(new Error(`atomic-workflows: stage "${this.opts.stageName}" session was replaced`));
|
|
16484
17002
|
const current = this.session;
|
|
16485
17003
|
this.messageAdmission.reset();
|
|
16486
17004
|
this.replacement.retire(current);
|
|
16487
17005
|
this.session = undefined;
|
|
17006
|
+
this.activeCandidateIndex = nextCandidateIndex;
|
|
16488
17007
|
if (this.sessionPromise !== this.ownedCreationPromise)
|
|
16489
17008
|
this.sessionPromise = undefined;
|
|
16490
17009
|
this.sessionSettingsManager = undefined;
|
|
@@ -16495,6 +17014,15 @@ class StageSessionController {
|
|
|
16495
17014
|
this.unsubscribeTerminateWatcher?.();
|
|
16496
17015
|
this.unsubscribeTerminateWatcher = undefined;
|
|
16497
17016
|
this.terminatingToolCallIds.clear();
|
|
17017
|
+
const shutdown = Promise.resolve().then(() => shutdownStageSession(current));
|
|
17018
|
+
this.sessionShutdownPromise = shutdown;
|
|
17019
|
+
shutdown.then(() => {
|
|
17020
|
+
if (this.sessionShutdownPromise === shutdown)
|
|
17021
|
+
this.sessionShutdownPromise = undefined;
|
|
17022
|
+
}, () => {});
|
|
17023
|
+
await shutdown;
|
|
17024
|
+
if (this.disposed || this.opts.signal?.aborted === true || this.abortGeneration !== startGeneration)
|
|
17025
|
+
throw this.staleCreationReason(startGeneration);
|
|
16498
17026
|
}
|
|
16499
17027
|
async promptWithPauseResume(activeSession, initialText, sdkOptions) {
|
|
16500
17028
|
let nextText = initialText;
|
|
@@ -16554,6 +17082,7 @@ class StageSessionController {
|
|
|
16554
17082
|
const { terminalScanStartIndex } = await this.promptWithThrownErrorRetry(resumedSession, text, sdkOptions);
|
|
16555
17083
|
const terminalFailure = latestTerminalAssistantFailureSince(resumedSession.messages, terminalScanStartIndex);
|
|
16556
17084
|
if (terminalFailure === undefined || this.capturedStructuredOutputForAttempt()) {
|
|
17085
|
+
this.artifactCapture.settleAttempt(true);
|
|
16557
17086
|
const usage = this.takeAttemptUsage(resumedSession);
|
|
16558
17087
|
this.modelAttempts.push({
|
|
16559
17088
|
model: resumedLabel,
|
|
@@ -16568,17 +17097,19 @@ class StageSessionController {
|
|
|
16568
17097
|
throw new WorkflowPromptModelFailure(terminalFailure);
|
|
16569
17098
|
} catch (err) {
|
|
16570
17099
|
if (this.capturedStructuredOutputForAttempt() && isRetryableModelFailure(err)) {
|
|
16571
|
-
|
|
17100
|
+
this.artifactCapture.settleAttempt(true);
|
|
17101
|
+
const usage = this.takeAttemptUsage(resumedSession);
|
|
16572
17102
|
this.modelAttempts.push({
|
|
16573
17103
|
model: resumedLabel,
|
|
16574
17104
|
success: true,
|
|
16575
|
-
...
|
|
17105
|
+
...usage === undefined ? {} : { usage }
|
|
16576
17106
|
});
|
|
16577
17107
|
this.pendingFallbackWarnings.length = 0;
|
|
16578
17108
|
this.resumeCurrentSession = true;
|
|
16579
17109
|
this.notifySuccessfulModelFallbackMeta();
|
|
16580
17110
|
return true;
|
|
16581
17111
|
}
|
|
17112
|
+
this.artifactCapture.settleAttempt(false);
|
|
16582
17113
|
const message = errorMessage2(err);
|
|
16583
17114
|
const usage = this.takeAttemptUsage(resumedSession);
|
|
16584
17115
|
this.modelAttempts.push({
|
|
@@ -16601,18 +17132,20 @@ class StageSessionController {
|
|
|
16601
17132
|
throw err;
|
|
16602
17133
|
}
|
|
16603
17134
|
this.pendingFallbackWarnings.push(resumedOverflowNextIndex === undefined ? `[fallback] resume on ${resumedLabel} failed: ${message}. Restarting fallback from ${candidateLabel(candidates[0])}.` : `[fallback] resume on ${resumedLabel} failed: ${message}. Retrying with ${candidateLabel(candidates[resumedOverflowNextIndex])}.`);
|
|
16604
|
-
await this.disposeCurrentSession();
|
|
16605
|
-
this.activeCandidateIndex = resumedOverflowNextIndex;
|
|
17135
|
+
await this.disposeCurrentSession(resumedOverflowNextIndex);
|
|
16606
17136
|
return false;
|
|
16607
17137
|
}
|
|
16608
17138
|
}
|
|
16609
17139
|
async handleCandidateFailure(err, candidate, candidates, index) {
|
|
17140
|
+
if (err instanceof StageSessionBindingCleanupFailure)
|
|
17141
|
+
throw err;
|
|
16610
17142
|
const message = errorMessage2(err);
|
|
16611
17143
|
const terminalStageDelivery = isWorkflowPendingStageDeliveryFailure(err);
|
|
16612
17144
|
if (!terminalStageDelivery && this.capturedStructuredOutputForAttempt() && isRetryableModelFailure(err)) {
|
|
16613
17145
|
this.recordSuccessfulAttempt(candidate);
|
|
16614
17146
|
return "handled";
|
|
16615
17147
|
}
|
|
17148
|
+
this.artifactCapture.settleAttempt(false);
|
|
16616
17149
|
const usage = this.takeAttemptUsage(this.session);
|
|
16617
17150
|
this.modelAttempts.push({
|
|
16618
17151
|
model: candidate.id,
|
|
@@ -16629,13 +17162,14 @@ class StageSessionController {
|
|
|
16629
17162
|
}
|
|
16630
17163
|
const nextCandidate = candidates[index + 1];
|
|
16631
17164
|
this.pendingFallbackWarnings.push(`[fallback] ${candidateLabel(candidate)} failed: ${message}. Retrying with ${candidateLabel(nextCandidate)}.`);
|
|
16632
|
-
await this.disposeCurrentSession();
|
|
17165
|
+
await this.disposeCurrentSession(index + 1);
|
|
16633
17166
|
return "retry";
|
|
16634
17167
|
}
|
|
16635
17168
|
capturedStructuredOutputForAttempt() {
|
|
16636
17169
|
return this.structuredOutputCapture?.called === true && this.opts.signal?.aborted !== true;
|
|
16637
17170
|
}
|
|
16638
17171
|
recordSuccessfulAttempt(candidate) {
|
|
17172
|
+
this.artifactCapture.settleAttempt(true);
|
|
16639
17173
|
const usage = this.takeAttemptUsage(this.session);
|
|
16640
17174
|
this.modelAttempts.push({
|
|
16641
17175
|
model: candidate.id,
|
|
@@ -16843,7 +17377,7 @@ function stageOutputInstruction(outputOptions, hasStructuredOutput = false) {
|
|
|
16843
17377
|
}
|
|
16844
17378
|
return `
|
|
16845
17379
|
|
|
16846
|
-
[This stage's
|
|
17380
|
+
[This stage's completed answers are saved as its artifact and are what later stages read. Return the complete result as ordinary assistant text rather than a pointer to it. Follow-up answers within this stage are appended as numbered supplements, not replacements; state corrections explicitly. Tool-call progress is transcript-only. Files you write yourself are not the artifact.]`;
|
|
16847
17381
|
}
|
|
16848
17382
|
async function finalizePromptOutput(fullOutput, outputOptions, runtimeCwd, runId, messages) {
|
|
16849
17383
|
const outputPath = resolveOutputPath(outputOptions.output, runtimeCwd, outputOptions.cwd);
|
|
@@ -16889,7 +17423,7 @@ function createStageContext2(opts) {
|
|
|
16889
17423
|
const structuredOutputCapture = stageOptions?.schema ? createStructuredOutputCapture() : undefined;
|
|
16890
17424
|
const structuredOutputExecutionCapture = stageOptions?.schema ? {} : undefined;
|
|
16891
17425
|
const effectiveStageOptions = stageOptionsWithStructuredOutput(stageOptions, structuredOutputCapture, structuredOutputExecutionCapture);
|
|
16892
|
-
const
|
|
17426
|
+
const meta = {
|
|
16893
17427
|
runId,
|
|
16894
17428
|
stageId,
|
|
16895
17429
|
stageName,
|
|
@@ -16898,21 +17432,40 @@ function createStageContext2(opts) {
|
|
|
16898
17432
|
stageOptions: effectiveStageOptions,
|
|
16899
17433
|
executionMode
|
|
16900
17434
|
};
|
|
16901
|
-
const controller = new StageSessionController(opts,
|
|
17435
|
+
const controller = new StageSessionController(opts, meta, effectiveStageOptions, structuredOutputCapture);
|
|
16902
17436
|
let lastAssistantText;
|
|
16903
17437
|
let lastFinalizedOutput;
|
|
16904
17438
|
let lastFinalizedMessageCount;
|
|
16905
17439
|
let structuredArtifactFinalized = false;
|
|
16906
17440
|
let adapterMessages = [];
|
|
17441
|
+
let artifactOptions;
|
|
17442
|
+
let artifactClosed = false;
|
|
17443
|
+
let artifactText;
|
|
17444
|
+
let continuing = false;
|
|
17445
|
+
async function exportArtifact() {
|
|
17446
|
+
const text = assistantArtifactTextForGeneration(controller.outputGenerationMessages());
|
|
17447
|
+
if (text !== artifactText || lastFinalizedOutput === undefined) {
|
|
17448
|
+
lastFinalizedOutput = await finalizePromptOutput(text, artifactOptions, runtimeCwd(), runId, controller.currentSession?.messages);
|
|
17449
|
+
artifactText = text;
|
|
17450
|
+
lastAssistantText = lastFinalizedOutput;
|
|
17451
|
+
}
|
|
17452
|
+
return lastFinalizedOutput;
|
|
17453
|
+
}
|
|
16907
17454
|
function runtimeCwd() {
|
|
16908
17455
|
return typeof effectiveStageOptions?.cwd === "string" ? effectiveStageOptions.cwd : process.cwd();
|
|
16909
17456
|
}
|
|
16910
17457
|
function finalizedOutputIsCurrent() {
|
|
16911
|
-
|
|
17458
|
+
if (lastFinalizedOutput === undefined)
|
|
17459
|
+
return false;
|
|
17460
|
+
if (artifactOptions !== undefined || structuredArtifactFinalized)
|
|
17461
|
+
return true;
|
|
17462
|
+
return lastFinalizedMessageCount === undefined || controller.currentSession?.messages.length === lastFinalizedMessageCount;
|
|
16912
17463
|
}
|
|
16913
17464
|
return {
|
|
16914
17465
|
name: stageName,
|
|
16915
17466
|
async prompt(text, options) {
|
|
17467
|
+
if (continuing && artifactOptions)
|
|
17468
|
+
options = { ...options, ...artifactOptions };
|
|
16916
17469
|
const { sdkOptions, outputOptions } = splitPromptOptions(options);
|
|
16917
17470
|
validatePromptOutputOptions(outputOptions);
|
|
16918
17471
|
const hasOutputArtifact = typeof outputOptions.output === "string" && outputOptions.output.length > 0;
|
|
@@ -16920,15 +17473,23 @@ function createStageContext2(opts) {
|
|
|
16920
17473
|
if (structuredOutputCapture?.called) {
|
|
16921
17474
|
throw new Error("atomic-workflows: stage schema supports one prompt() call per stage context because structured_output may be called exactly once. Create a new ctx.stage(...) for each additional schema-backed prompt.");
|
|
16922
17475
|
}
|
|
17476
|
+
if (!continuing) {
|
|
17477
|
+
controller.beginOutputGeneration();
|
|
17478
|
+
artifactOptions = undefined;
|
|
17479
|
+
artifactClosed = false;
|
|
17480
|
+
artifactText = undefined;
|
|
17481
|
+
}
|
|
17482
|
+
if (hasOutputArtifact && !structuredOutputCapture && !adapters.prompt)
|
|
17483
|
+
artifactOptions = outputOptions;
|
|
16923
17484
|
if (adapters.prompt) {
|
|
16924
17485
|
if (structuredOutputCapture) {
|
|
16925
17486
|
throw new Error("atomic-workflows: stage schema requires an AgentSessionAdapter so the structured_output tool can be registered.");
|
|
16926
17487
|
}
|
|
16927
|
-
const
|
|
16928
|
-
if (typeof
|
|
16929
|
-
return
|
|
16930
|
-
adapterMessages = assistantMessage(
|
|
16931
|
-
lastAssistantText = await finalizePromptOutput(
|
|
17488
|
+
const rawText = await runCallback2({ kind: "workflow.stage_adapter", name: `prompt:${stageName}`, runId, stageId }, () => adapters.prompt.prompt(promptText, meta));
|
|
17489
|
+
if (typeof rawText !== "string")
|
|
17490
|
+
return rawText;
|
|
17491
|
+
adapterMessages = assistantMessage(rawText);
|
|
17492
|
+
lastAssistantText = await finalizePromptOutput(rawText, outputOptions, runtimeCwd(), runId, adapterMessages);
|
|
16932
17493
|
lastFinalizedOutput = lastAssistantText;
|
|
16933
17494
|
lastFinalizedMessageCount = controller.currentSession?.messages.length;
|
|
16934
17495
|
return lastAssistantText;
|
|
@@ -16970,17 +17531,28 @@ function createStageContext2(opts) {
|
|
|
16970
17531
|
return executionSnapshot.value;
|
|
16971
17532
|
}
|
|
16972
17533
|
await controller.promptWithFallback(promptText, sdkOptions);
|
|
17534
|
+
if (artifactOptions)
|
|
17535
|
+
return await exportArtifact();
|
|
16973
17536
|
const rawText = controller.lastAssistantText(lastAssistantText) ?? "";
|
|
16974
17537
|
lastAssistantText = await finalizePromptOutput(rawText, outputOptions, runtimeCwd(), runId, controller.currentSession?.messages);
|
|
16975
17538
|
lastFinalizedOutput = lastAssistantText;
|
|
16976
17539
|
lastFinalizedMessageCount = controller.currentSession?.messages.length;
|
|
16977
17540
|
return lastAssistantText;
|
|
16978
17541
|
},
|
|
17542
|
+
async __continuePrompt(text) {
|
|
17543
|
+
continuing = true;
|
|
17544
|
+
try {
|
|
17545
|
+
return await this.prompt(text);
|
|
17546
|
+
} finally {
|
|
17547
|
+
continuing = false;
|
|
17548
|
+
}
|
|
17549
|
+
},
|
|
16979
17550
|
async complete(text, completeOpts) {
|
|
17551
|
+
artifactOptions = undefined;
|
|
16980
17552
|
if (adapters.complete) {
|
|
16981
17553
|
lastFinalizedOutput = undefined;
|
|
16982
17554
|
lastFinalizedMessageCount = undefined;
|
|
16983
|
-
lastAssistantText = await runCallback2({ kind: "workflow.stage_adapter", name: `complete:${stageName}`, runId, stageId }, () => adapters.complete.complete(text, completeOpts,
|
|
17555
|
+
lastAssistantText = await runCallback2({ kind: "workflow.stage_adapter", name: `complete:${stageName}`, runId, stageId }, () => adapters.complete.complete(text, completeOpts, meta));
|
|
16984
17556
|
adapterMessages = assistantMessage(lastAssistantText);
|
|
16985
17557
|
return lastAssistantText;
|
|
16986
17558
|
}
|
|
@@ -17045,7 +17617,7 @@ function createStageContext2(opts) {
|
|
|
17045
17617
|
return controller.currentSession?.isStreaming ?? false;
|
|
17046
17618
|
},
|
|
17047
17619
|
async navigateTree(targetId, options) {
|
|
17048
|
-
return
|
|
17620
|
+
return controller.navigateTree(targetId, options);
|
|
17049
17621
|
},
|
|
17050
17622
|
async compact() {
|
|
17051
17623
|
return (await controller.ensureSession()).compact();
|
|
@@ -17076,6 +17648,11 @@ function createStageContext2(opts) {
|
|
|
17076
17648
|
},
|
|
17077
17649
|
async __closeGeneration() {
|
|
17078
17650
|
await controller.closeGeneration();
|
|
17651
|
+
if (artifactOptions && !artifactClosed) {
|
|
17652
|
+
await exportArtifact();
|
|
17653
|
+
artifactClosed = true;
|
|
17654
|
+
}
|
|
17655
|
+
return artifactOptions ? lastFinalizedOutput : undefined;
|
|
17079
17656
|
},
|
|
17080
17657
|
__sessionMeta() {
|
|
17081
17658
|
return controller.sessionMeta();
|
|
@@ -17110,7 +17687,7 @@ function createStageSessionHeartbeat(checkpoint, intervalMs = STAGE_SESSION_HEAR
|
|
|
17110
17687
|
let timer;
|
|
17111
17688
|
let generation = 0;
|
|
17112
17689
|
let nextDeadline = 0;
|
|
17113
|
-
let
|
|
17690
|
+
let failure;
|
|
17114
17691
|
let inFlight;
|
|
17115
17692
|
let rejectFailure;
|
|
17116
17693
|
const failureSignal = new Promise((_resolve, reject) => {
|
|
@@ -17127,14 +17704,14 @@ function createStageSessionHeartbeat(checkpoint, intervalMs = STAGE_SESSION_HEAR
|
|
|
17127
17704
|
timer = undefined;
|
|
17128
17705
|
};
|
|
17129
17706
|
const fail = (error) => {
|
|
17130
|
-
if (
|
|
17707
|
+
if (failure !== undefined)
|
|
17131
17708
|
return;
|
|
17132
|
-
|
|
17709
|
+
failure = error;
|
|
17133
17710
|
stopScheduling();
|
|
17134
17711
|
rejectFailure(error);
|
|
17135
17712
|
};
|
|
17136
17713
|
const schedule = (scheduledGeneration) => {
|
|
17137
|
-
if (!active ||
|
|
17714
|
+
if (!active || failure !== undefined || scheduledGeneration !== generation)
|
|
17138
17715
|
return;
|
|
17139
17716
|
const delayMs = Math.max(0, nextDeadline - Date.now());
|
|
17140
17717
|
timer = setTimeout(() => {
|
|
@@ -17155,12 +17732,12 @@ function createStageSessionHeartbeat(checkpoint, intervalMs = STAGE_SESSION_HEAR
|
|
|
17155
17732
|
const drain = async () => {
|
|
17156
17733
|
stopScheduling();
|
|
17157
17734
|
await inFlight;
|
|
17158
|
-
if (
|
|
17159
|
-
throw
|
|
17735
|
+
if (failure !== undefined)
|
|
17736
|
+
throw failure;
|
|
17160
17737
|
};
|
|
17161
17738
|
return {
|
|
17162
17739
|
start() {
|
|
17163
|
-
if (active ||
|
|
17740
|
+
if (active || failure !== undefined)
|
|
17164
17741
|
return;
|
|
17165
17742
|
active = true;
|
|
17166
17743
|
generation += 1;
|
|
@@ -17171,8 +17748,8 @@ function createStageSessionHeartbeat(checkpoint, intervalMs = STAGE_SESSION_HEAR
|
|
|
17171
17748
|
drain,
|
|
17172
17749
|
fail,
|
|
17173
17750
|
race(work) {
|
|
17174
|
-
if (
|
|
17175
|
-
return Promise.reject(
|
|
17751
|
+
if (failure !== undefined)
|
|
17752
|
+
return Promise.reject(failure);
|
|
17176
17753
|
return Promise.race([work, failureSignal]);
|
|
17177
17754
|
}
|
|
17178
17755
|
};
|
|
@@ -17232,6 +17809,8 @@ function createWorkflowStageFactory(input) {
|
|
|
17232
17809
|
...replaySource.result !== undefined ? { result: replaySource.result } : {},
|
|
17233
17810
|
...replaySource.sessionId !== undefined ? { sessionId: replaySource.sessionId } : {},
|
|
17234
17811
|
...replaySource.sessionFile !== undefined ? { sessionFile: replaySource.sessionFile } : {},
|
|
17812
|
+
...replaySource.model !== undefined ? { model: replaySource.model } : {},
|
|
17813
|
+
...replaySource.thinkingLevel !== undefined ? { thinkingLevel: replaySource.thinkingLevel } : {},
|
|
17235
17814
|
replayedFromStageId: replaySource.id,
|
|
17236
17815
|
replayed: true
|
|
17237
17816
|
} : {},
|
|
@@ -17253,16 +17832,20 @@ function createWorkflowStageFactory(input) {
|
|
|
17253
17832
|
throwIfWorkflowExitSelected: input.exit.throwIfWorkflowExitSelected
|
|
17254
17833
|
});
|
|
17255
17834
|
}
|
|
17256
|
-
const applyModelFallbackMeta = (
|
|
17257
|
-
if (
|
|
17258
|
-
stageSnapshot.model =
|
|
17259
|
-
if (
|
|
17260
|
-
stageSnapshot.
|
|
17261
|
-
|
|
17262
|
-
stageSnapshot.
|
|
17263
|
-
if (
|
|
17264
|
-
|
|
17265
|
-
|
|
17835
|
+
const applyModelFallbackMeta = (meta) => {
|
|
17836
|
+
if (meta.model !== undefined)
|
|
17837
|
+
stageSnapshot.model = meta.model;
|
|
17838
|
+
if (meta.thinkingLevel !== undefined)
|
|
17839
|
+
stageSnapshot.thinkingLevel = meta.thinkingLevel;
|
|
17840
|
+
else
|
|
17841
|
+
delete stageSnapshot.thinkingLevel;
|
|
17842
|
+
if (meta.attemptedModels !== undefined)
|
|
17843
|
+
stageSnapshot.attemptedModels = meta.attemptedModels;
|
|
17844
|
+
if (meta.modelAttempts !== undefined)
|
|
17845
|
+
stageSnapshot.modelAttempts = meta.modelAttempts;
|
|
17846
|
+
if (meta.warnings !== undefined) {
|
|
17847
|
+
if (meta.warnings.length > 0)
|
|
17848
|
+
stageSnapshot.warnings = meta.warnings;
|
|
17266
17849
|
else
|
|
17267
17850
|
delete stageSnapshot.warnings;
|
|
17268
17851
|
}
|
|
@@ -17290,8 +17873,8 @@ function createWorkflowStageFactory(input) {
|
|
|
17290
17873
|
models: input.opts.models,
|
|
17291
17874
|
executionMode: input.opts.executionMode,
|
|
17292
17875
|
defaultSessionDir: input.opts.defaultSessionDir,
|
|
17293
|
-
onModelFallbackMetaChange(
|
|
17294
|
-
applyModelFallbackMeta(
|
|
17876
|
+
onModelFallbackMetaChange(meta) {
|
|
17877
|
+
applyModelFallbackMeta(meta);
|
|
17295
17878
|
if (stageSnapshot.status === "running")
|
|
17296
17879
|
input.activeStore.recordStageStart(input.runId, stageSnapshot);
|
|
17297
17880
|
},
|
|
@@ -17363,13 +17946,13 @@ function createWorkflowStageFactory(input) {
|
|
|
17363
17946
|
await innerCtx.__dispose();
|
|
17364
17947
|
};
|
|
17365
17948
|
const captureStageSessionMeta = async (checkpointOptions) => {
|
|
17366
|
-
const
|
|
17367
|
-
if (
|
|
17368
|
-
stageSnapshot.sessionId =
|
|
17369
|
-
if (
|
|
17370
|
-
stageSnapshot.sessionFile =
|
|
17371
|
-
if (
|
|
17372
|
-
input.activeStore.recordStageSession(input.runId, stageId,
|
|
17949
|
+
const meta = innerCtx.__sessionMeta();
|
|
17950
|
+
if (meta.sessionId !== undefined)
|
|
17951
|
+
stageSnapshot.sessionId = meta.sessionId;
|
|
17952
|
+
if (meta.sessionFile !== undefined)
|
|
17953
|
+
stageSnapshot.sessionFile = meta.sessionFile;
|
|
17954
|
+
if (meta.sessionId !== undefined || meta.sessionFile !== undefined)
|
|
17955
|
+
input.activeStore.recordStageSession(input.runId, stageId, meta);
|
|
17373
17956
|
const pending = input.opts.onStageSession?.(input.runId, stageSnapshot, checkpointOptions);
|
|
17374
17957
|
if (checkpointOptions?.forceDurable === true || checkpointOptions?.awaitDurable === true) {
|
|
17375
17958
|
await pending;
|
|
@@ -17709,7 +18292,7 @@ class EngineRuntime {
|
|
|
17709
18292
|
// dist/builtin/workflows/src/engine/workflow-activity.ts
|
|
17710
18293
|
import { runCallback as runCallback4 } from "@bastani/atomic";
|
|
17711
18294
|
function nextEventLoopTurn() {
|
|
17712
|
-
return new Promise((
|
|
18295
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
17713
18296
|
}
|
|
17714
18297
|
function runWorkflowDefinitionCallback(name, runId, callback) {
|
|
17715
18298
|
return runCallback4({ kind: "workflow.run", name, runId }, callback);
|
|
@@ -17737,7 +18320,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
17737
18320
|
}
|
|
17738
18321
|
const resolvedInputs = resolveAndValidateInputs(def.inputs, inputs, `workflow "${def.name}"`);
|
|
17739
18322
|
const runId = opts.runId ?? crypto.randomUUID();
|
|
17740
|
-
const declaresBudget = (
|
|
18323
|
+
const declaresBudget = (budget) => (budget?.maxDurationMs ?? 0) > 0 || (budget?.maxTokens ?? 0) > 0 || (budget?.maxCost ?? 0) > 0;
|
|
17741
18324
|
const hasBudgetDeclaration = declaresBudget(opts.budget) || declaresBudget(def.budget) || declaresBudget(opts.config?.budget);
|
|
17742
18325
|
const priorRun = hasBudgetDeclaration && opts.rootBudget === undefined && opts.continuation === undefined && opts.runId !== undefined ? activeStore.runs().find((candidate) => candidate.id === runId) : undefined;
|
|
17743
18326
|
const continuedBudget = opts.continuation?.source.budget ?? priorRun?.budget;
|
|
@@ -17750,14 +18333,17 @@ async function run(def, inputs, opts = {}) {
|
|
|
17750
18333
|
terminalEvents.selectCancellation(ownController.signal.reason);
|
|
17751
18334
|
}, { once: true });
|
|
17752
18335
|
const callerSignal = opts.signal;
|
|
17753
|
-
const onCallerAbort = () =>
|
|
18336
|
+
const onCallerAbort = () => {
|
|
18337
|
+
workflowObservationRuntime(activeStore).control(runId, "kill");
|
|
18338
|
+
ownController.abort(callerSignal?.reason);
|
|
18339
|
+
};
|
|
17754
18340
|
const exit = createWorkflowExitManager({ runId, exitScope, controller: ownController });
|
|
17755
18341
|
const backendView = opts.durableBackend ?? getDurableBackend();
|
|
17756
18342
|
const rootBackend = opts.durableRootBackend ?? backendView;
|
|
17757
18343
|
const durableBackend = opts.durableScope !== undefined ? new ScopedDurableBackend(backendView, opts.durableScope) : backendView;
|
|
17758
18344
|
const inheritedElapsedMs = opts.parentRun === undefined ? inheritedRunElapsedMs({ backend: durableBackend, runId, continuationSource: opts.continuation?.source }) : undefined;
|
|
17759
18345
|
const continuationOrigin = opts.continuation !== undefined ? opts.continuation.source.origin : opts.origin;
|
|
17760
|
-
const snapshotField = (
|
|
18346
|
+
const snapshotField = (field) => resolvedBudget[field] > 0 || opts.budget?.[field] !== undefined || def.budget?.[field] !== undefined ? resolvedBudget[field] : undefined;
|
|
17761
18347
|
const budgetSnapshot = resolvedBudget.maxDurationMs > 0 || resolvedBudget.maxTokens > 0 || resolvedBudget.maxCost > 0 ? {
|
|
17762
18348
|
maxDurationMs: resolvedBudget.maxDurationMs,
|
|
17763
18349
|
...snapshotField("maxTokens") !== undefined ? { maxTokens: snapshotField("maxTokens") } : {},
|
|
@@ -17766,7 +18352,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
17766
18352
|
} : undefined;
|
|
17767
18353
|
const durableAccounting = hasBudgetDeclaration && opts.parentRun === undefined && opts.continuation === undefined && priorRun === undefined ? priorRunAccounting(durableBackend, runId) : undefined;
|
|
17768
18354
|
const continuedBudgetState = opts.continuation?.source.budgetState ?? priorRun?.budgetState ?? (durableAccounting === undefined ? undefined : { accounting: durableAccounting });
|
|
17769
|
-
const sameBudget = budgetSnapshot !== undefined && continuedBudget?.warnAtPercent === budgetSnapshot.warnAtPercent && ["maxDurationMs", "maxTokens", "maxCost"].every((
|
|
18355
|
+
const sameBudget = budgetSnapshot !== undefined && continuedBudget?.warnAtPercent === budgetSnapshot.warnAtPercent && ["maxDurationMs", "maxTokens", "maxCost"].every((field) => (continuedBudget?.[field] ?? 0) === (budgetSnapshot[field] ?? 0));
|
|
17770
18356
|
const continuationBudgetState = continuedBudgetState === undefined || !sameBudget && continuedBudgetState.accounting === undefined ? undefined : sameBudget ? continuedBudgetState : { accounting: continuedBudgetState.accounting };
|
|
17771
18357
|
const continuationSourceRunId = opts.continuation?.source.id;
|
|
17772
18358
|
const persistedPossibleStages = coercePossibleStages(opts.possibleStages) ?? (continuationSourceRunId !== undefined ? coercePossibleStages(rootBackend.getWorkflow(continuationSourceRunId)?.possibleStages) : undefined);
|
|
@@ -17808,9 +18394,9 @@ async function run(def, inputs, opts = {}) {
|
|
|
17808
18394
|
children.push(snapshot);
|
|
17809
18395
|
childrenByParent.set(snapshot.parentRunId, children);
|
|
17810
18396
|
}
|
|
17811
|
-
const build = (
|
|
17812
|
-
const children = (childrenByParent.get(
|
|
17813
|
-
return children.length === 0 ? { run
|
|
18397
|
+
const build = (run) => {
|
|
18398
|
+
const children = (childrenByParent.get(run.id) ?? []).map(build);
|
|
18399
|
+
return children.length === 0 ? { run } : { run, children };
|
|
17814
18400
|
};
|
|
17815
18401
|
return build(snapshots.find((snapshot) => snapshot.id === runSnapshot.id) ?? runSnapshot);
|
|
17816
18402
|
};
|
|
@@ -18005,7 +18591,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
18005
18591
|
};
|
|
18006
18592
|
const taskRunners = createWorkflowTaskRunners({ runtime });
|
|
18007
18593
|
let pendingChildDurableInvocation;
|
|
18008
|
-
const
|
|
18594
|
+
const workflow = createChildWorkflowRunner({
|
|
18009
18595
|
runtime,
|
|
18010
18596
|
resolveWorkflowCwd,
|
|
18011
18597
|
nextWorkflowBoundaryReplayKey,
|
|
@@ -18138,7 +18724,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
18138
18724
|
},
|
|
18139
18725
|
recordCachedStage,
|
|
18140
18726
|
runTopology: durableRunTopology(runSnapshot),
|
|
18141
|
-
workflow
|
|
18727
|
+
workflow
|
|
18142
18728
|
});
|
|
18143
18729
|
const pendingChildWorkflows = new Set;
|
|
18144
18730
|
const durableStage = createDurableStagePrimitive({
|
|
@@ -18251,11 +18837,12 @@ async function run(def, inputs, opts = {}) {
|
|
|
18251
18837
|
});
|
|
18252
18838
|
terminalEvents.register();
|
|
18253
18839
|
try {
|
|
18840
|
+
workflowObservationRuntime(activeStore).startRun(runId);
|
|
18841
|
+
activeStore.recordRunStart(runSnapshot);
|
|
18254
18842
|
if (callerSignal?.aborted)
|
|
18255
18843
|
onCallerAbort();
|
|
18256
18844
|
else
|
|
18257
18845
|
callerSignal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
18258
|
-
activeStore.recordRunStart(runSnapshot);
|
|
18259
18846
|
if (ownsCancellationRegistration)
|
|
18260
18847
|
opts.cancellation?.register(runId, ownController);
|
|
18261
18848
|
opts.onRunStart?.(runSnapshot);
|
|
@@ -18406,15 +18993,15 @@ async function run(def, inputs, opts = {}) {
|
|
|
18406
18993
|
return await finalizers.finalizeParentWorkflowExitCancellation(parentExit);
|
|
18407
18994
|
return finalizeKilled(runId, runSnapshot, activeStore, opts.persistence, opts.onRunEnd);
|
|
18408
18995
|
}
|
|
18409
|
-
const
|
|
18410
|
-
const
|
|
18411
|
-
outerFailure:
|
|
18996
|
+
const failure = classifyExecutorFailure(err);
|
|
18997
|
+
const selectedMetadata = normalizeFailureWinnerMetadata(normalizeStageLessFailureMetadata(selectRunFailureDisposition({
|
|
18998
|
+
outerFailure: failure,
|
|
18412
18999
|
thrownError: err,
|
|
18413
19000
|
stages: runSnapshot.stages,
|
|
18414
19001
|
classifyFailure: classifyExecutorFailure
|
|
18415
19002
|
}), runSnapshot.stages.length));
|
|
18416
|
-
const failedToolNodeId =
|
|
18417
|
-
const metadata = failedToolNodeId === undefined ?
|
|
19003
|
+
const failedToolNodeId = selectedMetadata.failedStageId === undefined && selectedMetadata.failureDisposition !== "terminal_killed" ? catchTerminalEvent?.kind === "failure" && Object.is(catchTerminalEvent.error, err) ? catchTerminalEvent.nodeId ?? observedAdmittedToolFailure?.nodeId : observedAdmittedToolFailure?.nodeId : undefined;
|
|
19004
|
+
const metadata = failedToolNodeId === undefined ? selectedMetadata : { ...selectedMetadata, failedToolNodeId };
|
|
18418
19005
|
if (metadata.failureDisposition === "terminal_killed") {
|
|
18419
19006
|
for (const failedStageId of metadata.failedStageIds)
|
|
18420
19007
|
scheduler.blockKnownNonTerminalDescendants(failedStageId);
|
|
@@ -18443,6 +19030,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
18443
19030
|
});
|
|
18444
19031
|
} finally {
|
|
18445
19032
|
callerSignal?.removeEventListener("abort", onCallerAbort);
|
|
19033
|
+
workflowObservationRuntime(activeStore).finishRun(runId);
|
|
18446
19034
|
runtimeSettled.resolve();
|
|
18447
19035
|
unregisterRunControl();
|
|
18448
19036
|
try {
|
|
@@ -18482,45 +19070,45 @@ var NON_INTERACTIVE_WORKFLOW_POLICY = Object.freeze({
|
|
|
18482
19070
|
allowInputPicker: false
|
|
18483
19071
|
});
|
|
18484
19072
|
// dist/builtin/workflows/src/workflows/registry.ts
|
|
18485
|
-
function makeRegistry(
|
|
19073
|
+
function makeRegistry(store) {
|
|
18486
19074
|
return {
|
|
18487
19075
|
register(definition) {
|
|
18488
|
-
const next = new Map(
|
|
19076
|
+
const next = new Map(store);
|
|
18489
19077
|
next.set(definition.normalizedName, definition);
|
|
18490
19078
|
return makeRegistry(next);
|
|
18491
19079
|
},
|
|
18492
19080
|
merge(other) {
|
|
18493
|
-
const next = new Map(
|
|
19081
|
+
const next = new Map(store);
|
|
18494
19082
|
for (const def of other.all()) {
|
|
18495
19083
|
next.set(def.normalizedName, def);
|
|
18496
19084
|
}
|
|
18497
19085
|
return makeRegistry(next);
|
|
18498
19086
|
},
|
|
18499
19087
|
get(name) {
|
|
18500
|
-
return
|
|
19088
|
+
return store.get(normalizeWorkflowName(name));
|
|
18501
19089
|
},
|
|
18502
19090
|
has(name) {
|
|
18503
|
-
return
|
|
19091
|
+
return store.has(normalizeWorkflowName(name));
|
|
18504
19092
|
},
|
|
18505
19093
|
remove(name) {
|
|
18506
|
-
const
|
|
18507
|
-
if (!
|
|
19094
|
+
const key = normalizeWorkflowName(name);
|
|
19095
|
+
if (!store.has(key))
|
|
18508
19096
|
return this;
|
|
18509
|
-
const next = new Map(
|
|
18510
|
-
next.delete(
|
|
19097
|
+
const next = new Map(store);
|
|
19098
|
+
next.delete(key);
|
|
18511
19099
|
return makeRegistry(next);
|
|
18512
19100
|
},
|
|
18513
19101
|
names() {
|
|
18514
|
-
return [...
|
|
19102
|
+
return [...store.keys()];
|
|
18515
19103
|
},
|
|
18516
19104
|
all() {
|
|
18517
|
-
return [...
|
|
19105
|
+
return [...store.values()];
|
|
18518
19106
|
}
|
|
18519
19107
|
};
|
|
18520
19108
|
}
|
|
18521
19109
|
function createRegistry(initial = []) {
|
|
18522
|
-
const
|
|
18523
|
-
return makeRegistry(
|
|
19110
|
+
const store = new Map(initial.map((d) => [d.normalizedName, d]));
|
|
19111
|
+
return makeRegistry(store);
|
|
18524
19112
|
}
|
|
18525
19113
|
|
|
18526
19114
|
// dist/builtin/workflows/src/sdk-surface.ts
|