mayura 0.1.0-dev.0 → 1.0.0-rc.2
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/README.md +152 -35
- package/docs/README.md +82 -0
- package/docs/ai-agents.md +73 -0
- package/docs/cli/dev.md +111 -0
- package/docs/cli/init.md +192 -0
- package/docs/cli/operations.md +235 -0
- package/docs/cli/overview.md +129 -0
- package/docs/cli/run.md +182 -0
- package/docs/concepts/agent.md +197 -0
- package/docs/concepts/costs-and-budgets.md +177 -0
- package/docs/concepts/outcomes.md +154 -0
- package/docs/concepts/permissions.md +155 -0
- package/docs/concepts/runtime.md +172 -0
- package/docs/concepts/tools.md +202 -0
- package/docs/concepts/workflows.md +134 -0
- package/docs/guides/approvals-and-human-input.md +278 -0
- package/docs/guides/artifacts.md +123 -0
- package/docs/guides/child-agents.md +158 -0
- package/docs/guides/code-mode.md +233 -0
- package/docs/guides/deployment.md +644 -0
- package/docs/guides/durable-workflows.md +463 -0
- package/docs/guides/guardrails.md +205 -0
- package/docs/guides/helpers.md +176 -0
- package/docs/guides/lifecycle-hooks.md +187 -0
- package/docs/guides/mcp.md +123 -0
- package/docs/guides/memory-and-context.md +293 -0
- package/docs/guides/model-providers.md +371 -0
- package/docs/guides/model-routing.md +138 -0
- package/docs/guides/observability.md +238 -0
- package/docs/guides/operator-console.md +140 -0
- package/docs/guides/react.md +276 -0
- package/docs/guides/sagas-and-loops.md +212 -0
- package/docs/guides/server-and-client.md +559 -0
- package/docs/guides/skills.md +152 -0
- package/docs/guides/storage.md +251 -0
- package/docs/guides/streaming.md +146 -0
- package/docs/guides/terminal.md +166 -0
- package/docs/guides/testing.md +220 -0
- package/docs/guides/vision.md +155 -0
- package/docs/guides/webhooks.md +172 -0
- package/docs/guides/workflow-composition.md +141 -0
- package/docs/guides/workflow-operations.md +269 -0
- package/docs/installation.md +90 -0
- package/docs/introduction.md +74 -0
- package/docs/project/credits.md +78 -0
- package/docs/project/security.md +178 -0
- package/docs/project/support.md +91 -0
- package/docs/project/versioning.md +122 -0
- package/docs/quickstart.md +190 -0
- package/docs/reference/entry-points.md +146 -0
- package/lib/adapter-code-docker/dist/index.d.ts +8 -1
- package/lib/adapter-code-docker/dist/index.d.ts.map +1 -1
- package/lib/adapter-code-docker/dist/index.js +64 -67
- package/lib/adapter-code-docker/dist/index.js.map +1 -1
- package/lib/adapter-code-docker/dist/options.d.ts +15 -0
- package/lib/adapter-code-docker/dist/options.d.ts.map +1 -0
- package/lib/adapter-code-docker/dist/options.js +56 -0
- package/lib/adapter-code-docker/dist/options.js.map +1 -0
- package/lib/adapter-code-docker/image/Dockerfile +4 -2
- package/lib/adapter-code-docker/package.json +1 -1
- package/lib/adapter-code-docker/src/index.ts +63 -65
- package/lib/adapter-code-docker/src/options.ts +51 -0
- package/lib/adapter-code-quickjs/dist/index.d.ts +16 -4
- package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -1
- package/lib/adapter-code-quickjs/dist/index.js +94 -50
- package/lib/adapter-code-quickjs/dist/index.js.map +1 -1
- package/lib/adapter-code-quickjs/dist/worker-command.d.ts +27 -0
- package/lib/adapter-code-quickjs/dist/worker-command.d.ts.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker-command.js +66 -0
- package/lib/adapter-code-quickjs/dist/worker-command.js.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker.js +421 -104
- package/lib/adapter-code-quickjs/dist/worker.js.map +1 -1
- package/lib/adapter-code-quickjs/package.json +1 -1
- package/lib/adapter-code-quickjs/src/index.ts +88 -44
- package/lib/adapter-code-quickjs/src/worker-command.ts +68 -0
- package/lib/adapter-code-quickjs/src/worker.ts +315 -89
- package/lib/adapter-mcp/package.json +1 -1
- package/lib/artifacts/dist/contracts.d.ts +6 -2
- package/lib/artifacts/dist/contracts.d.ts.map +1 -1
- package/lib/artifacts/dist/contracts.js.map +1 -1
- package/lib/artifacts/dist/index.d.ts +1 -0
- package/lib/artifacts/dist/index.d.ts.map +1 -1
- package/lib/artifacts/dist/index.js +1 -0
- package/lib/artifacts/dist/index.js.map +1 -1
- package/lib/artifacts/dist/local-store.d.ts.map +1 -1
- package/lib/artifacts/dist/local-store.js +4 -7
- package/lib/artifacts/dist/local-store.js.map +1 -1
- package/lib/artifacts/dist/media.d.ts +11 -0
- package/lib/artifacts/dist/media.d.ts.map +1 -0
- package/lib/artifacts/dist/media.js +18 -0
- package/lib/artifacts/dist/media.js.map +1 -0
- package/lib/artifacts/package.json +1 -1
- package/lib/artifacts/src/contracts.ts +6 -2
- package/lib/artifacts/src/index.ts +1 -0
- package/lib/artifacts/src/local-store.ts +5 -7
- package/lib/artifacts/src/media.ts +20 -0
- package/lib/cli/dist/agent-guide.d.ts +10 -0
- package/lib/cli/dist/agent-guide.d.ts.map +1 -0
- package/lib/cli/dist/agent-guide.js +48 -0
- package/lib/cli/dist/agent-guide.js.map +1 -0
- package/lib/cli/dist/application.d.ts +24 -0
- package/lib/cli/dist/application.d.ts.map +1 -1
- package/lib/cli/dist/application.js +21 -0
- package/lib/cli/dist/application.js.map +1 -1
- package/lib/cli/dist/bin.js +26 -6
- package/lib/cli/dist/bin.js.map +1 -1
- package/lib/cli/dist/dev.d.ts.map +1 -1
- package/lib/cli/dist/dev.js +7 -1
- package/lib/cli/dist/dev.js.map +1 -1
- package/lib/cli/dist/index.d.ts +3 -3
- package/lib/cli/dist/index.d.ts.map +1 -1
- package/lib/cli/dist/index.js +19 -9
- package/lib/cli/dist/index.js.map +1 -1
- package/lib/cli/dist/interactive.d.ts.map +1 -1
- package/lib/cli/dist/interactive.js +52 -11
- package/lib/cli/dist/interactive.js.map +1 -1
- package/lib/cli/dist/operations.d.ts +25 -2
- package/lib/cli/dist/operations.d.ts.map +1 -1
- package/lib/cli/dist/operations.js +125 -12
- package/lib/cli/dist/operations.js.map +1 -1
- package/lib/cli/dist/output.d.ts.map +1 -1
- package/lib/cli/dist/output.js +3 -0
- package/lib/cli/dist/output.js.map +1 -1
- package/lib/cli/dist/providers.d.ts +34 -4
- package/lib/cli/dist/providers.d.ts.map +1 -1
- package/lib/cli/dist/providers.js +26 -5
- package/lib/cli/dist/providers.js.map +1 -1
- package/lib/cli/package.json +1 -1
- package/lib/cli/src/agent-guide.ts +47 -0
- package/lib/cli/src/application.ts +24 -0
- package/lib/cli/src/bin.ts +22 -5
- package/lib/cli/src/dev.ts +5 -1
- package/lib/cli/src/index.ts +18 -10
- package/lib/cli/src/interactive.ts +44 -12
- package/lib/cli/src/operations.ts +82 -12
- package/lib/cli/src/output.ts +3 -0
- package/lib/cli/src/providers.ts +45 -10
- package/lib/cli/starters/approval-workflow/dot-env.example +11 -0
- package/lib/cli/starters/approval-workflow/package.json +1 -2
- package/lib/cli/starters/approval-workflow/src/config.ts +25 -7
- package/lib/cli/starters/approval-workflow/src/intake.ts +1 -2
- package/lib/cli/starters/approval-workflow/src/model.ts +11 -4
- package/lib/cli/starters/approval-workflow/src/workflow.ts +1 -2
- package/lib/cli/starters/cli-agent/README.md +121 -0
- package/lib/cli/starters/cli-agent/dot-env.example +37 -0
- package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/cli-agent/dot-gitignore +10 -0
- package/lib/cli/starters/cli-agent/mayura.project.json +15 -0
- package/lib/cli/starters/cli-agent/package.json +28 -0
- package/lib/cli/starters/cli-agent/skills/release-notes/SKILL.md +18 -0
- package/lib/cli/starters/cli-agent/skills/release-notes/references/example.md +12 -0
- package/lib/cli/starters/cli-agent/src/assistant.ts +124 -0
- package/lib/cli/starters/cli-agent/src/cli.ts +72 -0
- package/lib/cli/starters/cli-agent/src/config.ts +117 -0
- package/lib/cli/starters/cli-agent/src/model.ts +34 -0
- package/lib/cli/starters/cli-agent/src/workspace.ts +170 -0
- package/lib/cli/starters/cli-agent/test/assistant.test.ts +205 -0
- package/lib/cli/starters/cli-agent/tsconfig.json +20 -0
- package/lib/cli/starters/event-automation/README.md +4 -3
- package/lib/cli/starters/event-automation/dot-env.example +11 -0
- package/lib/cli/starters/event-automation/package.json +1 -2
- package/lib/cli/starters/event-automation/src/config.ts +25 -7
- package/lib/cli/starters/event-automation/src/ingress.ts +3 -5
- package/lib/cli/starters/event-automation/src/model.ts +11 -4
- package/lib/cli/starters/event-automation/src/send-sample.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/main.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/tickets.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker-tools.ts +1 -1
- package/lib/cli/starters/event-automation/src/triage.ts +15 -22
- package/lib/cli/starters/event-automation/src/workflows.ts +1 -1
- package/lib/cli/starters/event-automation/test/automation.test.ts +3 -3
- package/lib/cli/starters/research-team/README.md +2 -2
- package/lib/cli/starters/research-team/dot-env.example +11 -0
- package/lib/cli/starters/research-team/package.json +1 -2
- package/lib/cli/starters/research-team/src/config.ts +25 -7
- package/lib/cli/starters/research-team/src/desk.ts +1 -2
- package/lib/cli/starters/research-team/src/library/index.ts +1 -2
- package/lib/cli/starters/research-team/src/model.ts +11 -4
- package/lib/cli/starters/research-team/src/services.ts +1 -1
- package/lib/cli/starters/research-team/src/team.ts +1 -2
- package/lib/cli/starters/research-team/src/workflow.ts +45 -59
- package/lib/cli/starters/support-agent/dot-env.example +11 -0
- package/lib/cli/starters/support-agent/package.json +1 -2
- package/lib/cli/starters/support-agent/src/assistant.ts +5 -5
- package/lib/cli/starters/support-agent/src/config.ts +25 -7
- package/lib/cli/starters/support-agent/src/guardrails.ts +3 -1
- package/lib/cli/starters/support-agent/src/model.ts +11 -4
- package/lib/cli/starters/support-agent/src/returns.ts +1 -2
- package/lib/cli/starters/support-agent/test/support.test.ts +25 -1
- package/lib/cli/templates/basic-agent.ts +1 -2
- package/lib/cli/templates/capability-policy.ts +1 -2
- package/lib/cli/templates/code-mode-workflow.ts +1 -1
- package/lib/cli/templates/durable-approval.ts +1 -1
- package/lib/cli/templates/parallel-research.ts +1 -2
- package/lib/cli/templates/typed-tool-runner.ts +1 -2
- package/lib/client/dist/forms.d.ts.map +1 -1
- package/lib/client/dist/forms.js +3 -4
- package/lib/client/dist/forms.js.map +1 -1
- package/lib/client/dist/headless.d.ts +3 -1
- package/lib/client/dist/headless.d.ts.map +1 -1
- package/lib/client/dist/headless.js +10 -6
- package/lib/client/dist/headless.js.map +1 -1
- package/lib/client/dist/index.d.ts +95 -6
- package/lib/client/dist/index.d.ts.map +1 -1
- package/lib/client/dist/index.js +397 -124
- package/lib/client/dist/index.js.map +1 -1
- package/lib/client/dist/workflows.d.ts +1 -1
- package/lib/client/dist/workflows.d.ts.map +1 -1
- package/lib/client/dist/workflows.js +7 -6
- package/lib/client/dist/workflows.js.map +1 -1
- package/lib/client/package.json +1 -1
- package/lib/client/src/forms.ts +3 -4
- package/lib/client/src/headless.ts +13 -7
- package/lib/client/src/index.ts +344 -74
- package/lib/client/src/workflows.ts +8 -7
- package/lib/client-react/package.json +1 -1
- package/lib/code-mode/dist/index.d.ts +32 -1
- package/lib/code-mode/dist/index.d.ts.map +1 -1
- package/lib/code-mode/dist/index.js +289 -221
- package/lib/code-mode/dist/index.js.map +1 -1
- package/lib/code-mode/package.json +1 -1
- package/lib/code-mode/src/index.ts +288 -184
- package/lib/code-mode-workflows/package.json +1 -1
- package/lib/context/package.json +1 -1
- package/lib/core/dist/budget.d.ts.map +1 -1
- package/lib/core/dist/budget.js +17 -2
- package/lib/core/dist/budget.js.map +1 -1
- package/lib/core/dist/contracts.d.ts +57 -0
- package/lib/core/dist/contracts.d.ts.map +1 -1
- package/lib/core/dist/contracts.js +36 -0
- package/lib/core/dist/contracts.js.map +1 -1
- package/lib/core/dist/destination.d.ts +12 -0
- package/lib/core/dist/destination.d.ts.map +1 -0
- package/lib/core/dist/destination.js +37 -0
- package/lib/core/dist/destination.js.map +1 -0
- package/lib/core/dist/event-stream.d.ts +1 -1
- package/lib/core/dist/event-stream.d.ts.map +1 -1
- package/lib/core/dist/event-stream.js +7 -0
- package/lib/core/dist/event-stream.js.map +1 -1
- package/lib/core/dist/host.d.ts +3 -0
- package/lib/core/dist/host.d.ts.map +1 -1
- package/lib/core/dist/host.js +3 -0
- package/lib/core/dist/host.js.map +1 -1
- package/lib/core/dist/index.d.ts +2 -0
- package/lib/core/dist/index.d.ts.map +1 -1
- package/lib/core/dist/index.js +2 -0
- package/lib/core/dist/index.js.map +1 -1
- package/lib/core/dist/media.d.ts +98 -0
- package/lib/core/dist/media.d.ts.map +1 -0
- package/lib/core/dist/media.js +227 -0
- package/lib/core/dist/media.js.map +1 -0
- package/lib/core/dist/model-schema.d.ts +37 -0
- package/lib/core/dist/model-schema.d.ts.map +1 -0
- package/lib/core/dist/model-schema.js +154 -0
- package/lib/core/dist/model-schema.js.map +1 -0
- package/lib/core/package.json +1 -1
- package/lib/core/src/budget.ts +17 -2
- package/lib/core/src/contracts.ts +71 -3
- package/lib/core/src/destination.ts +33 -0
- package/lib/core/src/event-stream.ts +5 -1
- package/lib/core/src/host.ts +3 -0
- package/lib/core/src/index.ts +2 -0
- package/lib/core/src/media.ts +228 -0
- package/lib/core/src/model-schema.ts +129 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
- package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
- package/lib/exporter-otlp/dist/signals.js +2 -2
- package/lib/exporter-otlp/dist/signals.js.map +1 -1
- package/lib/exporter-otlp/package.json +1 -1
- package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
- package/lib/exporter-otlp/src/signals.ts +2 -2
- package/lib/guardrails/package.json +1 -1
- package/lib/helpers/package.json +1 -1
- package/lib/memory/dist/index.js +1 -1
- package/lib/memory/dist/index.js.map +1 -1
- package/lib/memory/dist/native.d.ts.map +1 -1
- package/lib/memory/dist/native.js +4 -3
- package/lib/memory/dist/native.js.map +1 -1
- package/lib/memory/package.json +1 -1
- package/lib/memory/src/index.ts +1 -1
- package/lib/memory/src/native.ts +4 -3
- package/lib/memory-remote/package.json +1 -1
- package/lib/observability/package.json +1 -1
- package/lib/provider-anthropic/dist/index.d.ts +36 -3
- package/lib/provider-anthropic/dist/index.d.ts.map +1 -1
- package/lib/provider-anthropic/dist/index.js +128 -78
- package/lib/provider-anthropic/dist/index.js.map +1 -1
- package/lib/provider-anthropic/package.json +1 -1
- package/lib/provider-anthropic/src/index.ts +152 -76
- package/lib/provider-openai/dist/index.d.ts +71 -4
- package/lib/provider-openai/dist/index.d.ts.map +1 -1
- package/lib/provider-openai/dist/index.js +259 -96
- package/lib/provider-openai/dist/index.js.map +1 -1
- package/lib/provider-openai/package.json +1 -1
- package/lib/provider-openai/src/index.ts +282 -84
- package/lib/runtime/dist/agent.d.ts +18 -1
- package/lib/runtime/dist/agent.d.ts.map +1 -1
- package/lib/runtime/dist/agent.js +59 -3
- package/lib/runtime/dist/agent.js.map +1 -1
- package/lib/runtime/dist/composition.d.ts.map +1 -1
- package/lib/runtime/dist/composition.js +2 -1
- package/lib/runtime/dist/composition.js.map +1 -1
- package/lib/runtime/dist/hooks.d.ts +15 -3
- package/lib/runtime/dist/hooks.d.ts.map +1 -1
- package/lib/runtime/dist/hooks.js.map +1 -1
- package/lib/runtime/dist/index.d.ts +1 -1
- package/lib/runtime/dist/index.d.ts.map +1 -1
- package/lib/runtime/dist/index.js.map +1 -1
- package/lib/runtime/dist/response.d.ts +7 -1
- package/lib/runtime/dist/response.d.ts.map +1 -1
- package/lib/runtime/dist/response.js +23 -2
- package/lib/runtime/dist/response.js.map +1 -1
- package/lib/runtime/dist/router.d.ts +10 -3
- package/lib/runtime/dist/router.d.ts.map +1 -1
- package/lib/runtime/dist/router.js +45 -8
- package/lib/runtime/dist/router.js.map +1 -1
- package/lib/runtime/dist/runtime.d.ts +9 -1
- package/lib/runtime/dist/runtime.d.ts.map +1 -1
- package/lib/runtime/dist/runtime.js +50 -22
- package/lib/runtime/dist/runtime.js.map +1 -1
- package/lib/runtime/package.json +1 -1
- package/lib/runtime/src/agent.ts +69 -3
- package/lib/runtime/src/composition.ts +2 -1
- package/lib/runtime/src/hooks.ts +10 -4
- package/lib/runtime/src/index.ts +1 -1
- package/lib/runtime/src/response.ts +20 -2
- package/lib/runtime/src/router.ts +43 -10
- package/lib/runtime/src/runtime.ts +58 -27
- package/lib/sdk/dist/index.d.ts +9 -1
- package/lib/sdk/dist/index.d.ts.map +1 -1
- package/lib/sdk/dist/index.js +9 -1
- package/lib/sdk/dist/index.js.map +1 -1
- package/lib/sdk/package.json +1 -1
- package/lib/sdk/src/index.ts +9 -1
- package/lib/server/dist/index.d.ts +201 -3
- package/lib/server/dist/index.d.ts.map +1 -1
- package/lib/server/dist/index.js +701 -149
- package/lib/server/dist/index.js.map +1 -1
- package/lib/server/dist/inspector-bundle.d.ts +1 -1
- package/lib/server/dist/inspector-bundle.d.ts.map +1 -1
- package/lib/server/dist/inspector-bundle.js +4 -4
- package/lib/server/dist/inspector-bundle.js.map +1 -1
- package/lib/server/package.json +1 -1
- package/lib/server/src/index.ts +611 -135
- package/lib/server/src/inspector-bundle.ts +4 -4
- package/lib/server-node/dist/hardening.d.ts +1 -1
- package/lib/server-node/dist/hardening.d.ts.map +1 -1
- package/lib/server-node/dist/hardening.js +4 -2
- package/lib/server-node/dist/hardening.js.map +1 -1
- package/lib/server-node/dist/index.d.ts +2 -1
- package/lib/server-node/dist/index.d.ts.map +1 -1
- package/lib/server-node/dist/index.js.map +1 -1
- package/lib/server-node/dist/probe.js +2 -2
- package/lib/server-node/dist/probe.js.map +1 -1
- package/lib/server-node/dist/production.d.ts +8 -1
- package/lib/server-node/dist/production.d.ts.map +1 -1
- package/lib/server-node/dist/production.js +15 -2
- package/lib/server-node/dist/production.js.map +1 -1
- package/lib/server-node/package.json +1 -1
- package/lib/server-node/src/hardening.ts +5 -3
- package/lib/server-node/src/index.ts +2 -1
- package/lib/server-node/src/probe.ts +2 -2
- package/lib/server-node/src/production.ts +23 -3
- package/lib/skills/dist/index.d.ts +81 -0
- package/lib/skills/dist/index.d.ts.map +1 -0
- package/lib/skills/dist/index.js +311 -0
- package/lib/skills/dist/index.js.map +1 -0
- package/lib/skills/package.json +5 -0
- package/lib/skills/src/index.ts +260 -0
- package/lib/storage/dist/index.d.ts +1 -1
- package/lib/storage/dist/index.d.ts.map +1 -1
- package/lib/storage/dist/index.js.map +1 -1
- package/lib/storage/package.json +1 -1
- package/lib/storage/src/index.ts +1 -1
- package/lib/storage-contracts/dist/contracts.d.ts +12 -5
- package/lib/storage-contracts/dist/contracts.d.ts.map +1 -1
- package/lib/storage-contracts/dist/contracts.js +24 -6
- package/lib/storage-contracts/dist/contracts.js.map +1 -1
- package/lib/storage-contracts/dist/index.d.ts +2 -0
- package/lib/storage-contracts/dist/index.d.ts.map +1 -1
- package/lib/storage-contracts/dist/index.js +2 -0
- package/lib/storage-contracts/dist/index.js.map +1 -1
- package/lib/storage-contracts/dist/memory-contracts.js +1 -1
- package/lib/storage-contracts/dist/memory-contracts.js.map +1 -1
- package/lib/storage-contracts/dist/run-records.d.ts +100 -0
- package/lib/storage-contracts/dist/run-records.d.ts.map +1 -0
- package/lib/storage-contracts/dist/run-records.js +464 -0
- package/lib/storage-contracts/dist/run-records.js.map +1 -0
- package/lib/storage-contracts/dist/schema-digest.d.ts +17 -0
- package/lib/storage-contracts/dist/schema-digest.d.ts.map +1 -0
- package/lib/storage-contracts/dist/schema-digest.js +94 -0
- package/lib/storage-contracts/dist/schema-digest.js.map +1 -0
- package/lib/storage-contracts/dist/submission-journal.js +1 -1
- package/lib/storage-contracts/dist/submission-journal.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.d.ts +30 -2
- package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.js +57 -5
- package/lib/storage-contracts/dist/workflow-format5.js.map +1 -1
- package/lib/storage-contracts/package.json +1 -1
- package/lib/storage-contracts/src/contracts.ts +29 -5
- package/lib/storage-contracts/src/index.ts +2 -0
- package/lib/storage-contracts/src/memory-contracts.ts +1 -1
- package/lib/storage-contracts/src/run-records.ts +365 -0
- package/lib/storage-contracts/src/schema-digest.ts +71 -0
- package/lib/storage-contracts/src/submission-journal.ts +1 -1
- package/lib/storage-contracts/src/workflow-format5.ts +70 -6
- package/lib/storage-postgres/dist/index.d.ts +1 -1
- package/lib/storage-postgres/dist/index.d.ts.map +1 -1
- package/lib/storage-postgres/dist/index.js.map +1 -1
- package/lib/storage-postgres/dist/postgres.d.ts +15 -0
- package/lib/storage-postgres/dist/postgres.d.ts.map +1 -1
- package/lib/storage-postgres/dist/postgres.js +18 -7
- package/lib/storage-postgres/dist/postgres.js.map +1 -1
- package/lib/storage-postgres/package.json +1 -1
- package/lib/storage-postgres/src/index.ts +1 -1
- package/lib/storage-postgres/src/postgres.ts +34 -8
- package/lib/storage-sql/dist/aggregate-session.js +1 -1
- package/lib/storage-sql/dist/aggregate-session.js.map +1 -1
- package/lib/storage-sql/dist/scheduled-database.js +1 -1
- package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-validation.js +1 -1
- package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -1
- package/lib/storage-sql/package.json +1 -1
- package/lib/storage-sql/src/aggregate-session.ts +1 -1
- package/lib/storage-sql/src/scheduled-database.ts +1 -1
- package/lib/storage-sql/src/workflow-tree-validation.ts +1 -1
- package/lib/storage-sqlite/dist/sqlite-database.js +4 -4
- package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -1
- package/lib/storage-sqlite/dist/sqlite-worker.js +2 -2
- package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -1
- package/lib/storage-sqlite/dist/sqlite.js +1 -1
- package/lib/storage-sqlite/dist/sqlite.js.map +1 -1
- package/lib/storage-sqlite/package.json +1 -1
- package/lib/storage-sqlite/src/sqlite-database.ts +4 -4
- package/lib/storage-sqlite/src/sqlite-worker.ts +2 -2
- package/lib/storage-sqlite/src/sqlite.ts +1 -1
- package/lib/terminal/dist/index.d.ts +92 -0
- package/lib/terminal/dist/index.d.ts.map +1 -0
- package/lib/terminal/dist/index.js +397 -0
- package/lib/terminal/dist/index.js.map +1 -0
- package/lib/terminal/package.json +5 -0
- package/lib/terminal/src/index.ts +273 -0
- package/lib/testing/dist/index.d.ts +44 -1
- package/lib/testing/dist/index.d.ts.map +1 -1
- package/lib/testing/dist/index.js +63 -10
- package/lib/testing/dist/index.js.map +1 -1
- package/lib/testing/package.json +1 -1
- package/lib/testing/src/index.ts +83 -10
- package/lib/tools/dist/index.d.ts +32 -4
- package/lib/tools/dist/index.d.ts.map +1 -1
- package/lib/tools/dist/index.js +64 -11
- package/lib/tools/dist/index.js.map +1 -1
- package/lib/tools/package.json +1 -1
- package/lib/tools/src/index.ts +74 -13
- package/lib/workflows/dist/abandoned.d.ts +15 -0
- package/lib/workflows/dist/abandoned.d.ts.map +1 -0
- package/lib/workflows/dist/abandoned.js +33 -0
- package/lib/workflows/dist/abandoned.js.map +1 -0
- package/lib/workflows/dist/agent-step.d.ts +83 -0
- package/lib/workflows/dist/agent-step.d.ts.map +1 -0
- package/lib/workflows/dist/agent-step.js +161 -0
- package/lib/workflows/dist/agent-step.js.map +1 -0
- package/lib/workflows/dist/children-runtime.js +8 -8
- package/lib/workflows/dist/children-runtime.js.map +1 -1
- package/lib/workflows/dist/composite-fleet.js +2 -2
- package/lib/workflows/dist/composite-fleet.js.map +1 -1
- package/lib/workflows/dist/composite-host.d.ts.map +1 -1
- package/lib/workflows/dist/composite-host.js +26 -2
- package/lib/workflows/dist/composite-host.js.map +1 -1
- package/lib/workflows/dist/hook-relay.js +2 -2
- package/lib/workflows/dist/hook-relay.js.map +1 -1
- package/lib/workflows/dist/index.d.ts +1 -1
- package/lib/workflows/dist/index.d.ts.map +1 -1
- package/lib/workflows/dist/index.js.map +1 -1
- package/lib/workflows/dist/leadership.js +3 -3
- package/lib/workflows/dist/leadership.js.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.d.ts +26 -4
- package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.js +31 -6
- package/lib/workflows/dist/lifecycle-definition.js.map +1 -1
- package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-fleet.js +9 -11
- package/lib/workflows/dist/lifecycle-fleet.js.map +1 -1
- package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-host.js +26 -2
- package/lib/workflows/dist/lifecycle-host.js.map +1 -1
- package/lib/workflows/dist/lifecycle-human-transport.d.ts +22 -2
- package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-human-transport.js +115 -33
- package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.d.ts +62 -1
- package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.js +268 -64
- package/lib/workflows/dist/lifecycle-runtime.js.map +1 -1
- package/lib/workflows/dist/lifecycle.d.ts +6 -4
- package/lib/workflows/dist/lifecycle.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle.js +2 -0
- package/lib/workflows/dist/lifecycle.js.map +1 -1
- package/lib/workflows/dist/loop-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/loop-runtime.js +38 -26
- package/lib/workflows/dist/loop-runtime.js.map +1 -1
- package/lib/workflows/dist/migration.d.ts +1 -1
- package/lib/workflows/dist/migration.d.ts.map +1 -1
- package/lib/workflows/dist/migration.js +3 -3
- package/lib/workflows/dist/migration.js.map +1 -1
- package/lib/workflows/dist/operator-transports.d.ts +24 -2
- package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
- package/lib/workflows/dist/operator-transports.js +49 -3
- package/lib/workflows/dist/operator-transports.js.map +1 -1
- package/lib/workflows/dist/runtime.d.ts.map +1 -1
- package/lib/workflows/dist/runtime.js +34 -22
- package/lib/workflows/dist/runtime.js.map +1 -1
- package/lib/workflows/dist/saga-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/saga-runtime.js +44 -30
- package/lib/workflows/dist/saga-runtime.js.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.js +3 -3
- package/lib/workflows/dist/scheduled-helpers.js.map +1 -1
- package/lib/workflows/dist/storage-failure.d.ts +16 -0
- package/lib/workflows/dist/storage-failure.d.ts.map +1 -0
- package/lib/workflows/dist/storage-failure.js +38 -0
- package/lib/workflows/dist/storage-failure.js.map +1 -0
- package/lib/workflows/dist/sweep-position.d.ts +22 -0
- package/lib/workflows/dist/sweep-position.d.ts.map +1 -0
- package/lib/workflows/dist/sweep-position.js +45 -0
- package/lib/workflows/dist/sweep-position.js.map +1 -0
- package/lib/workflows/dist/traces.js +2 -2
- package/lib/workflows/dist/traces.js.map +1 -1
- package/lib/workflows/dist/worker.d.ts +31 -0
- package/lib/workflows/dist/worker.d.ts.map +1 -1
- package/lib/workflows/dist/worker.js +94 -0
- package/lib/workflows/dist/worker.js.map +1 -1
- package/lib/workflows/package.json +1 -1
- package/lib/workflows/src/abandoned.ts +32 -0
- package/lib/workflows/src/agent-step.ts +199 -0
- package/lib/workflows/src/children-runtime.ts +8 -8
- package/lib/workflows/src/composite-fleet.ts +2 -2
- package/lib/workflows/src/composite-host.ts +21 -3
- package/lib/workflows/src/hook-relay.ts +2 -2
- package/lib/workflows/src/index.ts +2 -1
- package/lib/workflows/src/leadership.ts +3 -3
- package/lib/workflows/src/lifecycle-definition.ts +50 -9
- package/lib/workflows/src/lifecycle-fleet.ts +7 -8
- package/lib/workflows/src/lifecycle-host.ts +21 -5
- package/lib/workflows/src/lifecycle-human-transport.ts +110 -26
- package/lib/workflows/src/lifecycle-runtime.ts +270 -60
- package/lib/workflows/src/lifecycle.ts +7 -0
- package/lib/workflows/src/loop-runtime.ts +34 -25
- package/lib/workflows/src/migration.ts +2 -2
- package/lib/workflows/src/operator-transports.ts +48 -4
- package/lib/workflows/src/runtime.ts +28 -22
- package/lib/workflows/src/saga-runtime.ts +38 -28
- package/lib/workflows/src/scheduled-helpers.ts +3 -3
- package/lib/workflows/src/storage-failure.ts +37 -0
- package/lib/workflows/src/sweep-position.ts +52 -0
- package/lib/workflows/src/traces.ts +2 -2
- package/lib/workflows/src/worker.ts +79 -1
- package/lib/workstream/dist/humans.d.ts +7 -3
- package/lib/workstream/dist/humans.d.ts.map +1 -1
- package/lib/workstream/dist/humans.js +13 -2
- package/lib/workstream/dist/humans.js.map +1 -1
- package/lib/workstream/dist/index.js +2 -2
- package/lib/workstream/dist/index.js.map +1 -1
- package/lib/workstream/dist/timers.js +2 -2
- package/lib/workstream/dist/timers.js.map +1 -1
- package/lib/workstream/dist/webhooks.d.ts +6 -2
- package/lib/workstream/dist/webhooks.d.ts.map +1 -1
- package/lib/workstream/dist/webhooks.js +17 -7
- package/lib/workstream/dist/webhooks.js.map +1 -1
- package/lib/workstream/package.json +1 -1
- package/lib/workstream/src/humans.ts +15 -5
- package/lib/workstream/src/index.ts +2 -2
- package/lib/workstream/src/timers.ts +2 -2
- package/lib/workstream/src/webhooks.ts +21 -8
- package/llms-full.txt +9766 -0
- package/llms.txt +92 -0
- package/package.json +18 -6
|
@@ -9,20 +9,26 @@ export {
|
|
|
9
9
|
type WorkflowLifecycleNode,
|
|
10
10
|
type WorkflowLifecycleOptions,
|
|
11
11
|
type WorkflowLifecycleOutput,
|
|
12
|
+
type WorkflowLifecycleSignalNode,
|
|
12
13
|
type WorkflowLifecycleTimerNode,
|
|
13
14
|
} from './lifecycle-definition.js';
|
|
15
|
+
export { agentStep, type AgentStepFactoryOptions, type AgentStepLimits, type AgentStepOptions } from './agent-step.js';
|
|
16
|
+
export { schemaDigest } from '@mayura/storage-contracts';
|
|
14
17
|
export {
|
|
15
18
|
createWorkflowLifecycleRuntime,
|
|
16
19
|
type WorkflowLifecycleRuntime,
|
|
17
20
|
type WorkflowLifecycleRuntimeOptions,
|
|
21
|
+
type WorkflowLifecyclePolicy,
|
|
18
22
|
type WorkflowLifecycleHumanRequest,
|
|
19
23
|
type WorkflowLifecycleApprovalRequest,
|
|
24
|
+
type WorkflowLifecycleSignalCommand,
|
|
20
25
|
type WorkflowLifecycleSnapshot,
|
|
21
26
|
type WorkflowLifecycleVerifiedActor,
|
|
22
27
|
} from './lifecycle-runtime.js';
|
|
23
28
|
export {
|
|
24
29
|
createWorkflowLifecycleHumanTransport,
|
|
25
30
|
type WorkflowLifecycleHumanRegistration,
|
|
31
|
+
type WorkflowLifecycleHumanRoute,
|
|
26
32
|
type WorkflowLifecycleHumanTransport,
|
|
27
33
|
type WorkflowLifecycleHumanTransportController,
|
|
28
34
|
type WorkflowLifecycleHumanTransportOptions,
|
|
@@ -53,6 +59,7 @@ export type {
|
|
|
53
59
|
WorkflowLifecycleHumanNodeManifest,
|
|
54
60
|
WorkflowLifecycleManifest,
|
|
55
61
|
WorkflowLifecycleManifestNode,
|
|
62
|
+
WorkflowLifecycleSignalNodeManifest,
|
|
56
63
|
WorkflowLifecycleTimerNodeManifest,
|
|
57
64
|
} from '@mayura/storage-contracts';
|
|
58
65
|
export { defineWorkflowMigration, type WorkflowMigration, type MigrationPlan, type MigrationCommand } from './migration.js';
|
|
@@ -3,8 +3,9 @@ import type { WorkflowDrainOptions, WorkflowDrainReport } from './drain.js';
|
|
|
3
3
|
import { StorageError, assertWorkflowLoopStateMatchesManifest, initialWorkflowLoopState, workflowLoopState,
|
|
4
4
|
type StoredRecord, type WorkflowLoopBinding, type WorkflowLoopState, type WorkflowLoopStatus } from '@mayura/storage-contracts';
|
|
5
5
|
import { digest, resolveBinding } from './definition.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { createSubmission, workflowStorageFailure } from './storage-failure.js';
|
|
7
|
+
import { createWorkflowLifecycleRuntime, submitWorkflowLifecycleUnder, unknownWorkflowPolicy, workflowPolicyDigest, workflowPolicySettings,
|
|
8
|
+
type WorkflowLifecycleRuntime, type WorkflowLifecycleRuntimeOptions, type WorkflowLifecycleSnapshot } from './lifecycle-runtime.js';
|
|
8
9
|
import { assertWorkflowLoop, loopManifest, type AnyWorkflowLoop } from './loop-definition.js';
|
|
9
10
|
import { assertMigrationAllowed, assertWorkflowMigration, migrationCommand, migrationEvent, nodeFingerprint, planWorkflowMigration,
|
|
10
11
|
type MigrationBlocker, type MigrationCommand, type WorkflowMigration, type WorkflowMigrationResult } from './migration.js';
|
|
@@ -63,8 +64,7 @@ function loopValue(binding: WorkflowLoopBinding, input: JsonValue, current: Json
|
|
|
63
64
|
async function storage<T>(operation: () => Promise<T>): Promise<T> {
|
|
64
65
|
try { return await operation(); }
|
|
65
66
|
catch (error) {
|
|
66
|
-
|
|
67
|
-
throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow loop storage is unavailable; inspect current state before retrying.');
|
|
67
|
+
throw workflowStorageFailure(error, 'workflow loop run');
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -86,27 +86,32 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
86
86
|
throw new MayuraError('INVALID_CONFIG', 'Workflow loop callback limits are invalid.');
|
|
87
87
|
}
|
|
88
88
|
const lifecycle = createWorkflowLifecycleRuntime(options); const scopeKey = digest('mayura:scope:v1', scope);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
// Index n of `settings` and of `policies` is the same policy the lifecycle runtime knows at index n.
|
|
90
|
+
const settings = workflowPolicySettings(options);
|
|
91
|
+
const policies = settings.map(entry => workflowPolicyDigest('mayura:workflow-loop-policy:v1', scope, entry)); const policy = policies[0]!;
|
|
92
|
+
/** Index of the policy a loop was started with; its later iterations and limits keep that policy. */
|
|
93
|
+
const pinnedIndex = (state: WorkflowLoopState): number => {
|
|
94
|
+
const index = policies.indexOf(state.policy); if (index < 0) throw unknownWorkflowPolicy(); return index;
|
|
95
|
+
};
|
|
92
96
|
let closed = false; let pendingCallbacks = 0;
|
|
93
97
|
const ensureOpen = (): void => { if (closed) throw new MayuraError('CANCELLED', 'Workflow loop runtime is closed.'); };
|
|
94
98
|
const checked = async (schema: AnyWorkflowLoop['input'] | AnyWorkflowLoop['output'], candidate: unknown,
|
|
95
|
-
boundary: 'input' | 'output'): Promise<JsonValue> => {
|
|
99
|
+
boundary: 'input' | 'output', maxBytes = maxOutputBytes): Promise<JsonValue> => {
|
|
96
100
|
if (pendingCallbacks >= maxPendingCallbacks) throw new MayuraError('LIMIT_EXCEEDED', 'Loop callback capacity is full.');
|
|
97
101
|
pendingCallbacks += 1; let released = false; const release = (): void => { if (!released) { released = true; pendingCallbacks -= 1; } };
|
|
98
|
-
const operation = Promise.resolve().then(() => validate(schema, candidate, boundary, { maxBytes
|
|
102
|
+
const operation = Promise.resolve().then(() => validate(schema, candidate, boundary, { maxBytes }));
|
|
99
103
|
void operation.then(release, release); let timer: ReturnType<typeof setTimeout> | undefined;
|
|
100
104
|
try { return jsonValue(await Promise.race([operation, new Promise<never>((_resolve, reject) => {
|
|
101
105
|
timer = setTimeout(() => reject(new MayuraError('TIMEOUT', 'Loop schema validation timed out.')), callbackTimeoutMs);
|
|
102
|
-
})]), { maxBytes
|
|
106
|
+
})]), { maxBytes }); }
|
|
103
107
|
finally { if (timer !== undefined) clearTimeout(timer); }
|
|
104
108
|
};
|
|
105
|
-
|
|
109
|
+
/** `anyPolicy` admits operator controls (pause, resume, cancel, migrate) on a loop whose settings are not listed. */
|
|
110
|
+
const load = async (id: string, anyPolicy = false): Promise<StoredRecord> => {
|
|
106
111
|
ensureOpen(); if (typeof id !== 'string' || !hashPattern.test(id)) throw new MayuraError('INVALID_INPUT', 'A workflow loop run ID is required.');
|
|
107
112
|
const record = await storage(() => store.read(scopeKey, id)); if (!record) throw new MayuraError('NOT_FOUND', 'Workflow loop run was not found in this scope.');
|
|
108
113
|
if (record.scope !== scopeKey || record.id !== id) throw new MayuraError('CONFLICT', 'Stored loop identity does not match its requested scope.');
|
|
109
|
-
if (decoded(record)
|
|
114
|
+
if (!anyPolicy) pinnedIndex(decoded(record)); return record;
|
|
110
115
|
};
|
|
111
116
|
const verify = (definition: AnyWorkflowLoop, record: StoredRecord, state: WorkflowLoopState): void => {
|
|
112
117
|
if (record.definitionHash !== definition.digest || state.definition !== definition.digest) throw new MayuraError('CONFLICT', 'Workflow loop definition does not match persisted state.');
|
|
@@ -116,13 +121,13 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
116
121
|
const save = (record: StoredRecord, state: WorkflowLoopState, type: string, data: JsonObject = {}) =>
|
|
117
122
|
storage(() => store.update({ scope: scopeKey, id: record.id, expectedVersion: record.version,
|
|
118
123
|
state: jsonValue(state) as JsonObject, events: [{ type, data }] }));
|
|
119
|
-
const mutate = async (id: string, transition: (state: WorkflowLoopState) => boolean, type: string, data: JsonObject = {}) => {
|
|
124
|
+
const mutate = async (id: string, transition: (state: WorkflowLoopState) => boolean, type: string, data: JsonObject = {}, anyPolicy = false) => {
|
|
120
125
|
for (let attempt = 0; attempt < 32; attempt++) {
|
|
121
|
-
const record = await load(id); const state = decoded(record); const paused = state.status === 'paused'; if (!transition(state)) return record;
|
|
126
|
+
const record = await load(id, anyPolicy); const state = decoded(record); const paused = state.status === 'paused'; if (!transition(state)) return record;
|
|
122
127
|
// Progress recorded while paused never un-pauses the loop; only a terminal outcome or an explicit resume does.
|
|
123
128
|
if (paused && !terminal.has(state.status) && type !== 'loop.run.resumed') state.status = 'paused';
|
|
124
129
|
try { return await save(record, state, type, data); }
|
|
125
|
-
catch (error) { if (!(error instanceof StorageError) || error.
|
|
130
|
+
catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
126
131
|
}
|
|
127
132
|
throw new MayuraError('CONFLICT', 'Workflow loop contention exceeded the bounded retry limit.');
|
|
128
133
|
};
|
|
@@ -143,7 +148,8 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
143
148
|
if (typeof condition !== 'boolean') throw new MayuraError('INVALID_OUTPUT', 'Loop continuation must resolve to a boolean.'); again = condition; }
|
|
144
149
|
catch { state.status = 'failed'; record = await save(record, state, 'loop.condition.rejected'); return view(record); }
|
|
145
150
|
if (!again) {
|
|
146
|
-
try { state.output = await checked(definition.output, loopValue(definition.result, state.input, state.current), 'output'
|
|
151
|
+
try { state.output = await checked(definition.output, loopValue(definition.result, state.input, state.current), 'output',
|
|
152
|
+
settings[pinnedIndex(state)]!.maxOutputBytes); state.status = 'succeeded'; }
|
|
147
153
|
catch (error) {
|
|
148
154
|
if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;
|
|
149
155
|
state.status = 'failed';
|
|
@@ -158,7 +164,7 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
158
164
|
: loopValue(definition.next, state.input, state.current); }
|
|
159
165
|
catch { state.status = 'failed'; record = await save(record, state, 'loop.input.rejected'); return view(record); }
|
|
160
166
|
let child: WorkflowLifecycleSnapshot;
|
|
161
|
-
try { child = await lifecycle
|
|
167
|
+
try { child = await submitWorkflowLifecycleUnder(lifecycle, pinnedIndex(state), definition.body, { input,
|
|
162
168
|
idempotencyKey: digest('mayura:workflow-loop-child:v1', { loopRunId: id, iteration: state.iteration }) }); }
|
|
163
169
|
catch (error) {
|
|
164
170
|
if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;
|
|
@@ -199,8 +205,8 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
199
205
|
const input = await checked(definition.input, freezeJson(jsonValue(command.input, { maxBytes: maxOutputBytes })), 'input');
|
|
200
206
|
const state = initialWorkflowLoopState(loopManifest(definition), input, definition.digest, policy, options.maxCostMicros);
|
|
201
207
|
const id = digest('mayura:workflow-loop-run-id:v1', { scope: scopeKey, submissionKey: command.idempotencyKey });
|
|
202
|
-
const created = await
|
|
203
|
-
definitionHash: definition.digest, state: jsonValue(state) as JsonObject, events: [{ type: 'loop.run.created', data: {} }] }));
|
|
208
|
+
const created = await createSubmission(() => store.create({ scope: scopeKey, id, idempotencyKey: `loop:${command.idempotencyKey}`,
|
|
209
|
+
definitionHash: definition.digest, state: jsonValue(state) as JsonObject, events: [{ type: 'loop.run.created', data: {} }] }), 'workflow loop run');
|
|
204
210
|
verify(definition, created.record, decoded(created.record)); return view(created.record);
|
|
205
211
|
},
|
|
206
212
|
inspect: async id => view(await load(id)),
|
|
@@ -210,18 +216,20 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
210
216
|
if (state.status === 'paused') return false;
|
|
211
217
|
if (terminal.has(state.status)) throw new MayuraError('CONFLICT', 'A terminal loop cannot be paused.');
|
|
212
218
|
state.status = 'paused'; return true;
|
|
213
|
-
}, 'loop.run.paused')),
|
|
219
|
+
}, 'loop.run.paused', {}, true)),
|
|
214
220
|
resume: async id => view(await mutate(id, state => {
|
|
215
221
|
if (state.status !== 'paused') throw new MayuraError('CONFLICT', 'Only a paused loop can be resumed.');
|
|
216
222
|
state.status = 'running'; return true;
|
|
217
|
-
}, 'loop.run.resumed')),
|
|
223
|
+
}, 'loop.run.resumed', {}, true)),
|
|
218
224
|
migrate: async (migration, command) => {
|
|
219
225
|
ensureOpen(); assertWorkflowMigration(migration); assertWorkflowLoop(migration.from); assertWorkflowLoop(migration.to);
|
|
220
226
|
const { id, actorId, commandId, dryRun = false } = migrationCommand(command);
|
|
221
|
-
|
|
227
|
+
// A reviewed migration is the explicit way to move a loop onto the current settings, whichever it started under.
|
|
228
|
+
const record = await load(id, true); const state = decoded(record); verify(migration.from, record, state);
|
|
222
229
|
const toManifest = loopManifest(migration.to);
|
|
223
230
|
const preconditions: MigrationBlocker[] = [];
|
|
224
231
|
if (state.status !== 'paused') preconditions.push({ node: '*', reason: `The loop is ${state.status}; pause it before migrating.` });
|
|
232
|
+
if (state.spentMicros > options.maxCostMicros) preconditions.push({ node: '*', reason: 'The loop already spent more than the current maxCostMicros.' });
|
|
225
233
|
if (toManifest.maxIterations < state.iteration) preconditions.push({ node: 'control', reason: `The loop already ran ${state.iteration} iterations; the new maxIterations is ${toManifest.maxIterations}.` });
|
|
226
234
|
let activeBody: string | undefined;
|
|
227
235
|
if (state.childRunId !== null) {
|
|
@@ -239,7 +247,8 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
239
247
|
steps: [{ id: 'body', status: state.childRunId !== null ? 'running' : 'pending' }, { id: 'control', status: 'pending' }], preconditions });
|
|
240
248
|
if (dryRun) return freezeJson(jsonValue({ plan })) as unknown as WorkflowMigrationResult<WorkflowLoopSnapshot>;
|
|
241
249
|
assertMigrationAllowed(plan);
|
|
242
|
-
const next: WorkflowLoopState = { ...state, definition: migration.to.digest, maxIterations: toManifest.maxIterations
|
|
250
|
+
const next: WorkflowLoopState = { ...state, definition: migration.to.digest, maxIterations: toManifest.maxIterations,
|
|
251
|
+
policy, maxCostMicros: options.maxCostMicros };
|
|
243
252
|
try { assertWorkflowLoopStateMatchesManifest(workflowLoopState({ id, state: jsonValue(next) as JsonObject }), toManifest); }
|
|
244
253
|
catch { throw new MayuraError('CONFLICT', 'Migration refused: the migrated loop state does not satisfy the new definition.'); }
|
|
245
254
|
if (typeof store.migrate !== 'function') throw new MayuraError('UNSUPPORTED_PROFILE', 'This store cannot migrate in-flight workflow runs.');
|
|
@@ -248,12 +257,12 @@ export function createWorkflowLoopRuntime(options: WorkflowLoopRuntimeOptions):
|
|
|
248
257
|
verify(migration.to, migrated, decoded(migrated));
|
|
249
258
|
return freezeJson(jsonValue({ plan, snapshot: view(migrated) })) as unknown as WorkflowMigrationResult<WorkflowLoopSnapshot>;
|
|
250
259
|
},
|
|
251
|
-
cancel: async id => { let record = await load(id); const state = decoded(record); if (terminal.has(state.status)) return view(record);
|
|
260
|
+
cancel: async id => { let record = await load(id, true); const state = decoded(record); if (terminal.has(state.status)) return view(record);
|
|
252
261
|
const child = state.childRunId ? await lifecycle.cancel(state.childRunId) : undefined;
|
|
253
262
|
record = await mutate(id, current => { if (terminal.has(current.status)) return false;
|
|
254
263
|
if (child && current.childRunId === child.id) account(current, child, false);
|
|
255
264
|
current.status = 'cancelled'; return true;
|
|
256
|
-
}, 'loop.run.cancelled'); return view(record); },
|
|
265
|
+
}, 'loop.run.cancelled', {}, true); return view(record); },
|
|
257
266
|
close: () => { if (!closed) { closed = true; lifecycle.close(); } },
|
|
258
267
|
drain: async options => { const report = await lifecycle.drain(options); closed = true; return report; },
|
|
259
268
|
});
|
|
@@ -36,10 +36,10 @@ export interface WorkflowMigration<F = unknown, T = unknown> {
|
|
|
36
36
|
*/
|
|
37
37
|
export interface MigrationNode { readonly id: string; readonly kind: string; readonly dependsOn: readonly string[]; readonly fingerprint: string; readonly evidence?: string }
|
|
38
38
|
|
|
39
|
-
/** Evidence of a manifest node: the tool a receipt must name, or whether a human request carries a deadline. */
|
|
39
|
+
/** Evidence of a manifest node: the tool a receipt must name, or whether a human request or signal step carries a deadline. */
|
|
40
40
|
export function nodeEvidence(node: { readonly kind: string; readonly tool?: unknown; readonly deadlineAtMs?: unknown }): string | undefined {
|
|
41
41
|
if (node.kind === 'tool' && typeof node.tool === 'string') return `tool:${node.tool}`;
|
|
42
|
-
if (node.kind === 'human') return node.deadlineAtMs === null || node.deadlineAtMs === undefined ?
|
|
42
|
+
if (node.kind === 'human' || node.kind === 'signal') return node.deadlineAtMs === null || node.deadlineAtMs === undefined ? node.kind : `${node.kind}:deadline`;
|
|
43
43
|
return undefined;
|
|
44
44
|
}
|
|
45
45
|
/** The run's current state of one source step, normalized across formats. */
|
|
@@ -114,7 +114,7 @@ export function createWorkflowCommandJournal(options: WorkflowCommandJournalOpti
|
|
|
114
114
|
|
|
115
115
|
/** Structural copies of the agent server's workflow transport records. */
|
|
116
116
|
export type WorkflowOperatorStatus = 'running' | 'waiting' | 'paused' | 'succeeded' | 'failed' | 'blocked' | 'cancelled' | 'outcome_unknown';
|
|
117
|
-
export type WorkflowOperatorNodeKind = 'tool' | 'join' | 'wait' | 'child' | 'human' | 'timer';
|
|
117
|
+
export type WorkflowOperatorNodeKind = 'tool' | 'join' | 'wait' | 'child' | 'human' | 'timer' | 'signal';
|
|
118
118
|
export type WorkflowOperatorStepStatus = 'pending' | 'waiting' | 'approved' | 'dispatching' | 'succeeded' | 'failed' | 'blocked' | 'unknown' | 'skipped' | 'timed_out';
|
|
119
119
|
export interface WorkflowOperatorView {
|
|
120
120
|
readonly format: 3 | 4 | 5; readonly definitionId: string; readonly definitionVersion: string; readonly runId: string; readonly revision: number;
|
|
@@ -152,9 +152,15 @@ export interface WorkflowOperatorTarget {
|
|
|
152
152
|
resume(runId: string): Promise<unknown>;
|
|
153
153
|
cancel(runId: string): Promise<unknown>;
|
|
154
154
|
approve(runId: string, command: { readonly nodeId: string; readonly digest: string; readonly childRunId: string | null; readonly actorId: string }): Promise<unknown>;
|
|
155
|
+
/** Deliver a signal to the run's signal step named `signalName` (lifecycle runs). Targets without signal steps omit it. */
|
|
156
|
+
signal?(runId: string, command: WorkflowOperatorSignal): Promise<unknown>;
|
|
157
|
+
/** Whether the run's signal step named `signalName` already holds the signal `signalId`. */
|
|
158
|
+
signalled?(runId: string, command: Pick<WorkflowOperatorSignal, 'signalName' | 'signalId'>): Promise<boolean>;
|
|
155
159
|
migrate(migration: WorkflowMigration, command: MigrationCommand): Promise<{ readonly plan: MigrationPlan; readonly snapshot?: unknown }>;
|
|
156
160
|
readonly fleet: WorkflowFleetTarget;
|
|
157
161
|
}
|
|
162
|
+
/** A signal as the operator API delivers it: the verified operator is its sender. */
|
|
163
|
+
export interface WorkflowOperatorSignal { readonly signalName: string; readonly signalId: string; readonly value: JsonValue; readonly actorId: string }
|
|
158
164
|
interface Registered { readonly id: string; readonly version: string; readonly digest: string; readonly nodes: readonly { readonly id: string; readonly kind: string; readonly dependsOn?: readonly string[] }[] }
|
|
159
165
|
/** Maps the authenticated operator to the credential the runtime's `verifyHuman` accepts; without it approvals are unavailable. */
|
|
160
166
|
export type WorkflowApprovalCredential = (actorId: string) => unknown;
|
|
@@ -191,6 +197,12 @@ export function lifecycleOperatorTarget(options: { readonly runtime: WorkflowLif
|
|
|
191
197
|
readonly definitions: readonly AnyWorkflowLifecycle[]; readonly approvalCredential?: WorkflowApprovalCredential; readonly name?: string }): WorkflowOperatorTarget {
|
|
192
198
|
const { runtime, store, scope } = options; const definitions = catalog(options.definitions);
|
|
193
199
|
const scopeKey = digest('mayura:scope:v1', { principalId: scope.principalId, projectId: scope.projectId });
|
|
200
|
+
/** The registered definition a run is pinned to; NOT_FOUND when the run is missing or its version is not registered. */
|
|
201
|
+
const pinned = async (runId: string): Promise<AnyWorkflowLifecycle> => {
|
|
202
|
+
const hash = await pinnedDefinitionHash(store, scope, runId); const definition = hash === undefined ? undefined : definitions.get(hash);
|
|
203
|
+
if (!definition) throw new MayuraError('NOT_FOUND', 'The run was not found, or its definition version is not registered with this target.');
|
|
204
|
+
return definition;
|
|
205
|
+
};
|
|
194
206
|
return Object.freeze<WorkflowOperatorTarget>({ name: options.name ?? 'lifecycle',
|
|
195
207
|
async page(after, limit) {
|
|
196
208
|
// Cursor string: `<shard>` or `<shard>.<afterId>` over the 256 index shards.
|
|
@@ -229,6 +241,16 @@ export function lifecycleOperatorTarget(options: { readonly runtime: WorkflowLif
|
|
|
229
241
|
},
|
|
230
242
|
pause: id => runtime.pause(id), resume: id => runtime.resume(id), cancel: id => runtime.cancel(id),
|
|
231
243
|
approve: (id, command) => runtime.approve({ id, nodeId: command.nodeId, digest: command.digest, credential: approval(options.approvalCredential, command.actorId) }),
|
|
244
|
+
async signal(id, command) {
|
|
245
|
+
const definition = await pinned(id);
|
|
246
|
+
return runtime.signal(definition, { id, name: command.signalName, signalId: command.signalId, payload: command.value, actorId: command.actorId });
|
|
247
|
+
},
|
|
248
|
+
async signalled(id, command) {
|
|
249
|
+
const definition = await pinned(id);
|
|
250
|
+
const node = definition.nodes.find(candidate => candidate.kind === 'signal' && candidate.name === command.signalName);
|
|
251
|
+
const step = node ? (await runtime.inspect(id)).steps[node.id] : undefined;
|
|
252
|
+
return step?.kind === 'signal' && step.signalId === command.signalId;
|
|
253
|
+
},
|
|
232
254
|
migrate: (migration, command) => runtime.migrate(migration as never, command),
|
|
233
255
|
fleet: lifecycleFleetTarget(runtime, options.name ?? 'lifecycle'),
|
|
234
256
|
});
|
|
@@ -306,6 +328,8 @@ export interface WorkflowOperatorTransports {
|
|
|
306
328
|
approve(input: ControlInput & { readonly nodeId: string; readonly approvalDigest: string; readonly childRunId: string | null }): Promise<WorkflowOperatorResult>;
|
|
307
329
|
};
|
|
308
330
|
readonly workflowPauses: { pause(input: ControlInput): Promise<WorkflowOperatorResult> };
|
|
331
|
+
/** Signals for lifecycle signal steps. A run whose target has no signal steps answers `not_found`. */
|
|
332
|
+
readonly workflowSignals: { deliver(input: ControlInput & { readonly signalId: string; readonly signalName: string; readonly value: JsonValue }): Promise<WorkflowOperatorResult> };
|
|
309
333
|
readonly workflowResumes: { resume(input: ControlInput): Promise<WorkflowOperatorResult> };
|
|
310
334
|
readonly workflowFleet?: {
|
|
311
335
|
inspect(input: ScopedInput): Promise<WorkflowFleetHoldState>; hold(input: ScopedInput): Promise<WorkflowFleetHoldState>; release(input: ScopedInput): Promise<WorkflowFleetHoldState>;
|
|
@@ -318,7 +342,10 @@ export interface WorkflowOperatorTransports {
|
|
|
318
342
|
| { readonly status: 'refused'; readonly plan: MigrationPlan } | { readonly status: 'conflict' } | { readonly status: 'not_found' }>;
|
|
319
343
|
};
|
|
320
344
|
}
|
|
321
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* Server transports (`workflowIndex`, `workflowViews`, `workflowControls`, `workflowSignals`, `workflowPauses`,
|
|
347
|
+
* `workflowResumes`, and optionally `workflowFleet` and `workflowMigrations`).
|
|
348
|
+
*/
|
|
322
349
|
export function createWorkflowOperatorTransports(options: WorkflowOperatorTransportOptions): WorkflowOperatorTransports {
|
|
323
350
|
const { targets, journal } = options;
|
|
324
351
|
if (!Array.isArray(targets) || targets.length < 1 || targets.length > 16 || new Set(targets.map(target => target.name)).size !== targets.length
|
|
@@ -338,11 +365,14 @@ export function createWorkflowOperatorTransports(options: WorkflowOperatorTransp
|
|
|
338
365
|
const conflicts = (error: unknown): WorkflowCommandOutcome | undefined => isCode(error, 'CONFLICT') ? 'conflict' : isCode(error, 'NOT_FOUND') ? 'not_found' : undefined;
|
|
339
366
|
/** Revision-checked, journaled command. The runtimes guard state themselves; the revision check is the operator's review point. */
|
|
340
367
|
const command = async (input: ControlInput, action: string, request: JsonValue, observe: (view: WorkflowOperatorView) => boolean,
|
|
341
|
-
operate: (target: WorkflowOperatorTarget) => Promise<unknown>): Promise<Result> => {
|
|
368
|
+
operate: (target: WorkflowOperatorTarget) => Promise<unknown>, happened?: () => Promise<boolean>): Promise<Result> => {
|
|
342
369
|
if (!inScope(input)) return { status: 'not_found' };
|
|
343
370
|
const found = await locate(input.runId); if (!found) return { status: 'not_found' };
|
|
344
371
|
const { outcome } = await journal.run({ runId: input.runId, action, commandId: input.commandId, request: { revision: input.revision, request },
|
|
345
|
-
observe: async () => {
|
|
372
|
+
observe: async () => {
|
|
373
|
+
if (happened) return happened();
|
|
374
|
+
const current = await found.target.view(input.runId); return current !== null && observe(current);
|
|
375
|
+
},
|
|
346
376
|
apply: async () => {
|
|
347
377
|
const current = await found.target.view(input.runId); if (!current) return { outcome: 'not_found' };
|
|
348
378
|
if (current.revision !== input.revision) return { outcome: 'conflict' };
|
|
@@ -379,6 +409,20 @@ export function createWorkflowOperatorTransports(options: WorkflowOperatorTransp
|
|
|
379
409
|
target => target.approve(input.runId, { nodeId: input.nodeId, digest: input.approvalDigest, childRunId: input.childRunId, actorId: input.actorId })),
|
|
380
410
|
},
|
|
381
411
|
workflowPauses: { pause: (input: ControlInput) => command(input, 'pause', null, view => view.status === 'paused', target => target.pause(input.runId)) },
|
|
412
|
+
workflowSignals: { deliver: async (input: ControlInput & { readonly signalId: string; readonly signalName: string; readonly value: JsonValue }) => {
|
|
413
|
+
const found = inScope(input) ? await locate(input.runId) : null;
|
|
414
|
+
if (!found?.target.signal || !found.target.signalled) return { status: 'not_found' as const };
|
|
415
|
+
const target = found.target as Required<Pick<WorkflowOperatorTarget, 'signal' | 'signalled'>>;
|
|
416
|
+
const signal: WorkflowOperatorSignal = { signalName: input.signalName, signalId: input.signalId, value: input.value, actorId: input.actorId };
|
|
417
|
+
// Delivery is idempotent on the signal id, so an attempt that died after delivering is recognised, not repeated.
|
|
418
|
+
// A payload the step's schema refuses is answered like any refused command (conflict), not as unavailable storage.
|
|
419
|
+
const deliver = async (): Promise<unknown> => {
|
|
420
|
+
try { return await target.signal(input.runId, signal); }
|
|
421
|
+
catch (error) { if (isCode(error, 'INVALID_INPUT')) throw new MayuraError('CONFLICT', 'The signal payload does not match the step.'); throw error; }
|
|
422
|
+
};
|
|
423
|
+
return command(input, 'signal', { signalName: input.signalName, signalId: input.signalId, value: input.value }, () => false,
|
|
424
|
+
deliver, () => target.signalled(input.runId, signal));
|
|
425
|
+
} },
|
|
382
426
|
workflowResumes: { resume: (input: ControlInput) => command(input, 'resume', null, view => view.status !== 'paused',
|
|
383
427
|
async target => { if ((await target.view(input.runId))?.status === 'paused') await target.resume(input.runId); }) },
|
|
384
428
|
...(options.fleet ? { workflowFleet: fleetTransport(options.fleet, targets.map(target => target.fleet), inScope) } : {}),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Budget, MayuraError, assertPositiveInteger, freezeJson, jsonValue, validate, type ExecutionReceipt, type JsonObject, type JsonValue, type Permissions, type Scope } from '@mayura/core';
|
|
2
2
|
import { invokeTool } from '@mayura/tools';
|
|
3
|
+
import { abandoned, dispatchedAt } from './abandoned.js';
|
|
3
4
|
import { createWorkflowDrainGate, type WorkflowDrainOptions, type WorkflowDrainReport } from './drain.js';
|
|
4
5
|
import { StorageError, assertWorkflowStateMatchesManifest, workflowState, workflowOutputs, mergeWorkflowReceipt,
|
|
5
6
|
type WorkflowFormat2State as State, type WorkflowFormat2Step as Step, type WorkflowFormat2StepStatus as StepStatus,
|
|
@@ -8,6 +9,7 @@ import { assertWorkflow, charged, digest, resolveBinding, type AnyWorkflow, type
|
|
|
8
9
|
import { assertMigrationAllowed, assertWorkflowMigration, migrationCommand, migrationEvent, nodeEvidence, nodeFingerprint, planWorkflowMigration,
|
|
9
10
|
type MigrationBlocker, type MigrationCommand, type WorkflowMigration, type WorkflowMigrationResult } from './migration.js';
|
|
10
11
|
import { scheduledManifest } from './scheduled-helpers.js';
|
|
12
|
+
import { createSubmission, workflowStorageFailure } from './storage-failure.js';
|
|
11
13
|
|
|
12
14
|
export interface WorkflowSnapshot {
|
|
13
15
|
readonly id: string; readonly version: number; readonly status: Status;
|
|
@@ -43,17 +45,7 @@ function stateFrom(record: StoredRecord): State {
|
|
|
43
45
|
/** External storage diagnostics never cross the workflow's public error boundary. */
|
|
44
46
|
async function storageCall<T>(operation: () => Promise<T>): Promise<T> {
|
|
45
47
|
try { return await operation(); }
|
|
46
|
-
catch (error) {
|
|
47
|
-
let conflict = false;
|
|
48
|
-
try {
|
|
49
|
-
if (error instanceof StorageError) {
|
|
50
|
-
const descriptor = Object.getOwnPropertyDescriptor(error, 'code');
|
|
51
|
-
conflict = !!descriptor && 'value' in descriptor && descriptor.value === 'CONFLICT';
|
|
52
|
-
}
|
|
53
|
-
} catch { /* Untrusted exception accessors/proxies do not become error messages. */ }
|
|
54
|
-
if (conflict) throw new StorageError('CONFLICT', 'Workflow storage version changed.');
|
|
55
|
-
throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow storage is unavailable; reconcile uncertain actions before retrying.');
|
|
56
|
-
}
|
|
48
|
+
catch (error) { throw workflowStorageFailure(error, 'workflow run'); }
|
|
57
49
|
}
|
|
58
50
|
function snapshot(record: StoredRecord): WorkflowSnapshot {
|
|
59
51
|
const state = stateFrom(record);
|
|
@@ -107,7 +99,7 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
107
99
|
const record = await load(id, allowClosed); const state = stateFrom(record);
|
|
108
100
|
if (!update(state)) return record;
|
|
109
101
|
try { return await save(record, state, type, data); }
|
|
110
|
-
catch (error) { if (!(error instanceof StorageError) || error.
|
|
102
|
+
catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
111
103
|
}
|
|
112
104
|
throw new MayuraError('CONFLICT', 'Workflow contention exceeded the bounded retry limit.');
|
|
113
105
|
};
|
|
@@ -116,7 +108,21 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
116
108
|
|
|
117
109
|
async function executeNode(id: string, node: WorkflowNode, claimRetries = 0): Promise<void> {
|
|
118
110
|
const record = await load(id); const state = stateFrom(record); const step = state.steps[node.id];
|
|
119
|
-
if (!step || state.policy !== policy || ['paused', 'cancelled'].includes(state.status)
|
|
111
|
+
if (!step || state.policy !== policy || ['paused', 'cancelled'].includes(state.status)) return;
|
|
112
|
+
// A dispatching step that no call in this process owns, past the tool's timeout and a margin, belongs to a process
|
|
113
|
+
// that stopped: settle it as recoverAbandoned would, and never run the effect again.
|
|
114
|
+
if (node.kind === 'tool' && step.status === 'dispatching') {
|
|
115
|
+
if (active.has(`${id}/${node.id}`)) return;
|
|
116
|
+
const dispatchedAtMs = await storageCall(() => dispatchedAt(store, scopeKey, id, 'step.dispatching', node.id));
|
|
117
|
+
if (!abandoned(dispatchedAtMs, node.tool.timeoutMs, Date.now())) return;
|
|
118
|
+
await mutate(id, current => {
|
|
119
|
+
const target = current.steps[node.id];
|
|
120
|
+
if (!target || target.status !== 'dispatching' || ['paused', 'cancelled'].includes(current.status) || active.has(`${id}/${node.id}`)) return false;
|
|
121
|
+
target.status = target.receipt?.execution === 'succeeded' ? 'blocked' : 'unknown'; current.status = 'running'; return true;
|
|
122
|
+
}, 'step.abandoned', { nodeId: node.id });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!['pending', 'approved'].includes(step.status)) return;
|
|
120
126
|
const dependencies = (node.dependsOn ?? []).map(key => state.steps[key]!);
|
|
121
127
|
if (dependencies.some(item => terminalSteps.has(item.status) && item.status !== 'succeeded')) {
|
|
122
128
|
await mutate(id, current => { const next = current.steps[node.id]!; if (!['pending','approved'].includes(next.status)) return false; next.status = 'skipped'; return true; }, 'step.skipped', { nodeId: node.id }); return;
|
|
@@ -124,13 +130,13 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
124
130
|
if (dependencies.some(item => item.status !== 'succeeded')) return;
|
|
125
131
|
if (node.kind === 'join') {
|
|
126
132
|
step.output = dependencies.map(item => item.output); step.status = 'succeeded';
|
|
127
|
-
try { await save(record, state, 'step.completed', { nodeId: node.id }); } catch (error) { if (!(error instanceof StorageError) || error.
|
|
133
|
+
try { await save(record, state, 'step.completed', { nodeId: node.id }); } catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
128
134
|
return;
|
|
129
135
|
}
|
|
130
136
|
const required = [`tool:${node.tool.id}`, ...node.tool.capabilities, ...(node.tool.effects === 'none' ? [] : [`effect:${node.tool.effects}`])];
|
|
131
137
|
if (required.some(grant => !permissions.allow.includes(grant))) {
|
|
132
138
|
step.status = 'blocked';
|
|
133
|
-
try { await save(record, state, 'step.blocked', { nodeId: node.id, code: 'PERMISSION_DENIED' }); } catch (error) { if (!(error instanceof StorageError) || error.
|
|
139
|
+
try { await save(record, state, 'step.blocked', { nodeId: node.id, code: 'PERMISSION_DENIED' }); } catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
134
140
|
return;
|
|
135
141
|
}
|
|
136
142
|
let input: JsonValue;
|
|
@@ -138,7 +144,7 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
138
144
|
catch {
|
|
139
145
|
step.status = 'failed';
|
|
140
146
|
try { await save(record, state, 'step.failed', { nodeId: node.id, code: 'INVALID_INPUT' }); }
|
|
141
|
-
catch (error) { if (!(error instanceof StorageError) || error.
|
|
147
|
+
catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
142
148
|
return;
|
|
143
149
|
}
|
|
144
150
|
const previousExpiry = step.approval?.expiresAt ?? 0;
|
|
@@ -146,13 +152,13 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
146
152
|
const candidateHash = candidate(node, input, id, reviewExpiry);
|
|
147
153
|
if (node.approval && (step.status !== 'approved' || step.approval?.digest !== candidateHash || step.approval.expiresAt <= Date.now())) {
|
|
148
154
|
step.status = 'waiting'; step.approval = { digest: candidateHash, expiresAt: reviewExpiry!, humanId: null }; state.status = 'waiting';
|
|
149
|
-
try { await save(record, state, 'approval.requested', { nodeId: node.id, digest: candidateHash }); } catch (error) { if (!(error instanceof StorageError) || error.
|
|
155
|
+
try { await save(record, state, 'approval.requested', { nodeId: node.id, digest: candidateHash }); } catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
150
156
|
return;
|
|
151
157
|
}
|
|
152
158
|
if (node.tool.costMicros > state.maxCostMicros - state.spentMicros - state.reservedMicros) {
|
|
153
159
|
step.status = 'blocked';
|
|
154
160
|
try { await save(record, state, 'step.blocked', { nodeId: node.id, code: 'BUDGET_EXCEEDED' }); }
|
|
155
|
-
catch (error) { if (!(error instanceof StorageError) || error.
|
|
161
|
+
catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
156
162
|
return;
|
|
157
163
|
}
|
|
158
164
|
step.status = 'dispatching'; step.candidateHash = candidateHash; step.costReserved = node.tool.costMicros;
|
|
@@ -161,7 +167,7 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
161
167
|
catch (error) {
|
|
162
168
|
// Retry the losing claim immediately: waiting for this wave would serialize independent handlers.
|
|
163
169
|
// Every retry reloads permissions/candidate/budget state before crossing the dispatch boundary.
|
|
164
|
-
if (error instanceof StorageError && error.
|
|
170
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT' && claimRetries < 32) return executeNode(id, node, claimRetries + 1);
|
|
165
171
|
throw error;
|
|
166
172
|
}
|
|
167
173
|
const controller = new AbortController(); const activeKey = `${id}/${node.id}`; active.set(activeKey, controller);
|
|
@@ -213,7 +219,7 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
213
219
|
const input = jsonValue(await bounded(() => validate(definition.input, inputSnapshot, 'input'), 30_000), { maxBytes: maxOutputBytes });
|
|
214
220
|
const state = initialState(definition, input, policy, maxCostMicros);
|
|
215
221
|
const id = digest('mayura:run-id:v1', { scope: scopeKey, submissionKey: idempotencyKey });
|
|
216
|
-
const created = await
|
|
222
|
+
const created = await createSubmission(() => store.create({ scope: scopeKey, id, idempotencyKey, definitionHash: definition.digest, state: jsonValue(state) as JsonObject, events: [{ type: 'run.created', data: {} }] }), 'workflow run');
|
|
217
223
|
return snapshot(created.record);
|
|
218
224
|
},
|
|
219
225
|
inspect: async (id: string): Promise<WorkflowSnapshot> => snapshot(await load(id)),
|
|
@@ -241,13 +247,13 @@ export function createWorkflowRuntime(options: WorkflowRuntimeOptions) {
|
|
|
241
247
|
catch { next.status = 'failed'; }
|
|
242
248
|
} else next.status = steps.some(item => item.status === 'unknown') ? 'outcome_unknown' : steps.some(item => item.status === 'blocked') ? 'blocked' : 'failed';
|
|
243
249
|
try { after = await save(after, next, 'run.completed', { status: next.status }); }
|
|
244
|
-
catch (error) { if (!(error instanceof StorageError) || error.
|
|
250
|
+
catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; after = await load(id); }
|
|
245
251
|
return snapshot(after);
|
|
246
252
|
}
|
|
247
253
|
if (after.version === before.version) {
|
|
248
254
|
if (steps.some(item => item.status === 'waiting') && !steps.some(item => item.status === 'dispatching') && next.status !== 'waiting') {
|
|
249
255
|
next.status = 'waiting';
|
|
250
|
-
try { after = await save(after, next, 'run.waiting'); } catch (error) { if (!(error instanceof StorageError) || error.
|
|
256
|
+
try { after = await save(after, next, 'run.waiting'); } catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; after = await load(id); }
|
|
251
257
|
}
|
|
252
258
|
return snapshot(after);
|
|
253
259
|
}
|