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
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Budget, MayuraError, assertPositiveInteger, freezeJson, jsonValue, validate } from '../../core/dist/index.js';
|
|
2
2
|
import { invokeTool } from '../../tools/dist/index.js';
|
|
3
|
+
import { abandoned, dispatchedAt } from './abandoned.js';
|
|
3
4
|
import { createWorkflowDrainGate } from './drain.js';
|
|
4
5
|
import { StorageError, assertWorkflowLifecycleStateMatchesManifest, initialWorkflowLifecycleState, mergeWorkflowReceipt, workflowLifecycleOutputs, workflowLifecycleState } from '../../storage-contracts/dist/index.js';
|
|
5
6
|
import { charged, digest, resolveBinding } from './definition.js';
|
|
6
7
|
import { assertWorkflowLifecycle, lifecycleManifest } from './lifecycle-definition.js';
|
|
8
|
+
import { createSubmission, workflowStorageFailure } from './storage-failure.js';
|
|
7
9
|
import { assertMigrationAllowed, assertWorkflowMigration, migrationCommand, migrationEvent, nodeEvidence, nodeFingerprint, planWorkflowMigration } from './migration.js';
|
|
8
10
|
const finalRunStatuses = new Set(['succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown']);
|
|
9
11
|
const terminalStepStatuses = new Set(['succeeded', 'failed', 'blocked', 'unknown', 'timed_out', 'skipped', 'bypassed']);
|
|
@@ -11,6 +13,7 @@ const terminalStepStatuses = new Set(['succeeded', 'failed', 'blocked', 'unknown
|
|
|
11
13
|
const satisfiedStepStatuses = new Set(['succeeded', 'bypassed']);
|
|
12
14
|
const hashPattern = /^[a-f0-9]{64}$/;
|
|
13
15
|
const nodePattern = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/;
|
|
16
|
+
const signalPattern = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/;
|
|
14
17
|
async function bounded(operation, timeoutMs) {
|
|
15
18
|
let timer;
|
|
16
19
|
try {
|
|
@@ -28,9 +31,7 @@ async function storageCall(operation) {
|
|
|
28
31
|
return await operation();
|
|
29
32
|
}
|
|
30
33
|
catch (error) {
|
|
31
|
-
|
|
32
|
-
throw new StorageError('CONFLICT', 'Workflow lifecycle storage version changed.');
|
|
33
|
-
throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow lifecycle storage is unavailable; reconcile uncertain actions before retrying.');
|
|
34
|
+
throw workflowStorageFailure(error, 'workflow lifecycle run');
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
function stateFrom(record) {
|
|
@@ -59,7 +60,7 @@ function receipt(previous, incoming) {
|
|
|
59
60
|
}
|
|
60
61
|
function nextWake(state) {
|
|
61
62
|
const deadlines = Object.values(state.steps).flatMap(step => step.kind === 'timer' && step.status === 'waiting' && step.fireAtMs !== null
|
|
62
|
-
? [step.fireAtMs] : step.kind === 'human' && step.status === 'waiting' && step.deadlineAtMs !== null
|
|
63
|
+
? [step.fireAtMs] : (step.kind === 'human' || step.kind === 'signal') && step.status === 'waiting' && step.deadlineAtMs !== null
|
|
63
64
|
? [step.deadlineAtMs] : step.kind === 'tool' && step.status === 'waiting' && step.approval !== null ? [step.approval.expiresAt] : []);
|
|
64
65
|
return deadlines.length === 0 ? null : Math.min(...deadlines);
|
|
65
66
|
}
|
|
@@ -79,6 +80,56 @@ function exactDigest(value) {
|
|
|
79
80
|
throw new MayuraError('INVALID_INPUT', 'Correction subject binding must resolve to a SHA-256 digest.');
|
|
80
81
|
return value;
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* @internal The runtime's own settings first, then each previous policy, validated and defaulted alike, so index `n`
|
|
85
|
+
* means the same settings to every runtime built from one options object.
|
|
86
|
+
*/
|
|
87
|
+
export function workflowPolicySettings(options) {
|
|
88
|
+
const previous = options.previousPolicies ?? [];
|
|
89
|
+
if (!Array.isArray(previous) || previous.length > 16)
|
|
90
|
+
throw new MayuraError('INVALID_CONFIG', 'previousPolicies must list at most 16 policies.');
|
|
91
|
+
return Object.freeze([options, ...previous].map(value => {
|
|
92
|
+
if (value === null || typeof value !== 'object')
|
|
93
|
+
throw new MayuraError('INVALID_CONFIG', 'Each previous policy must be an explicit settings object.');
|
|
94
|
+
const policy = value;
|
|
95
|
+
if (typeof policy.policyVersion !== 'string' || policy.policyVersion.length < 1 || policy.policyVersion.length > 128) {
|
|
96
|
+
throw new MayuraError('INVALID_CONFIG', 'Workflow lifecycle policy version is required.');
|
|
97
|
+
}
|
|
98
|
+
if (!Array.isArray(policy.permissions?.allow) || policy.permissions.allow.length > 4_096
|
|
99
|
+
|| policy.permissions.allow.some(grant => typeof grant !== 'string' || grant.length < 1 || grant.length > 256)) {
|
|
100
|
+
throw new MayuraError('INVALID_CONFIG', 'Workflow lifecycle permissions must be bounded explicit grants.');
|
|
101
|
+
}
|
|
102
|
+
if (!Number.isSafeInteger(policy.maxCostMicros) || policy.maxCostMicros < 0)
|
|
103
|
+
throw new MayuraError('INVALID_CONFIG', 'A bounded lifecycle cost is required.');
|
|
104
|
+
const maxOutputBytes = policy.maxOutputBytes ?? 1_048_576;
|
|
105
|
+
const approvalTtlMs = policy.approvalTtlMs ?? 3_600_000;
|
|
106
|
+
assertPositiveInteger(approvalTtlMs, 'approvalTtlMs');
|
|
107
|
+
assertPositiveInteger(maxOutputBytes, 'maxOutputBytes');
|
|
108
|
+
return Object.freeze({ permissions: Object.freeze({ allow: Object.freeze([...policy.permissions.allow]) }),
|
|
109
|
+
policyVersion: policy.policyVersion, maxCostMicros: policy.maxCostMicros, maxOutputBytes, approvalTtlMs });
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
/** @internal The digest a run records for its settings; each runtime kind has its own domain tag. */
|
|
113
|
+
export function workflowPolicyDigest(tag, scope, settings) {
|
|
114
|
+
return digest(tag, { scope, permissions: [...settings.permissions.allow].sort(), policyVersion: settings.policyVersion,
|
|
115
|
+
maxCostMicros: settings.maxCostMicros, maxOutputBytes: settings.maxOutputBytes, approvalTtlMs: settings.approvalTtlMs });
|
|
116
|
+
}
|
|
117
|
+
/** @internal */
|
|
118
|
+
export function unknownWorkflowPolicy() {
|
|
119
|
+
return new MayuraError('CONFLICT', 'This run was started under different runtime settings (permissions, policyVersion or limits). '
|
|
120
|
+
+ 'List those settings in previousPolicies to let it continue, or migrate it.');
|
|
121
|
+
}
|
|
122
|
+
const pinnedSubmissions = new WeakMap();
|
|
123
|
+
/**
|
|
124
|
+
* @internal Submit under the runtime's policy at `policy` (0: current, n: `previousPolicies[n - 1]`), so the later
|
|
125
|
+
* children of a pinned saga or loop keep the parent's settings instead of gaining the current ones.
|
|
126
|
+
*/
|
|
127
|
+
export function submitWorkflowLifecycleUnder(runtime, policy, ...submission) {
|
|
128
|
+
const submit = pinnedSubmissions.get(runtime);
|
|
129
|
+
if (!submit)
|
|
130
|
+
throw new MayuraError('INVALID_CONFIG', 'A genuine workflow lifecycle runtime is required.');
|
|
131
|
+
return submit(policy, ...submission);
|
|
132
|
+
}
|
|
82
133
|
/** Conservative durable lifecycle driver. Waiting nodes never retain a callback, worker, or timer handle. */
|
|
83
134
|
export function createWorkflowLifecycleRuntime(options) {
|
|
84
135
|
const store = options.store;
|
|
@@ -86,20 +137,9 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
86
137
|
if ([scope.principalId, scope.projectId, options.policyVersion].some(value => typeof value !== 'string' || value.length < 1 || value.length > 128)) {
|
|
87
138
|
throw new MayuraError('INVALID_CONFIG', 'Workflow lifecycle scope and policy version are required.');
|
|
88
139
|
}
|
|
89
|
-
|
|
90
|
-
|| options.permissions.allow.some(grant => typeof grant !== 'string' || grant.length < 1 || grant.length > 256)) {
|
|
91
|
-
throw new MayuraError('INVALID_CONFIG', 'Workflow lifecycle permissions must be bounded explicit grants.');
|
|
92
|
-
}
|
|
93
|
-
if (!Number.isSafeInteger(options.maxCostMicros) || options.maxCostMicros < 0)
|
|
94
|
-
throw new MayuraError('INVALID_CONFIG', 'A bounded lifecycle cost is required.');
|
|
95
|
-
const permissions = Object.freeze({ allow: Object.freeze([...options.permissions.allow]) });
|
|
96
|
-
const maxCostMicros = options.maxCostMicros;
|
|
97
|
-
const approvalTtlMs = options.approvalTtlMs ?? 3_600_000;
|
|
98
|
-
const maxOutputBytes = options.maxOutputBytes ?? 1_048_576;
|
|
140
|
+
const settings = workflowPolicySettings(options);
|
|
99
141
|
const callbackTimeoutMs = options.callbackTimeoutMs ?? 30_000;
|
|
100
142
|
const maxPendingCallbacks = options.maxPendingCallbacks ?? 32;
|
|
101
|
-
assertPositiveInteger(approvalTtlMs, 'approvalTtlMs');
|
|
102
|
-
assertPositiveInteger(maxOutputBytes, 'maxOutputBytes');
|
|
103
143
|
assertPositiveInteger(callbackTimeoutMs, 'callbackTimeoutMs');
|
|
104
144
|
assertPositiveInteger(maxPendingCallbacks, 'maxPendingCallbacks');
|
|
105
145
|
if (maxPendingCallbacks > 128)
|
|
@@ -131,8 +171,12 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
131
171
|
return value;
|
|
132
172
|
};
|
|
133
173
|
const scopeKey = digest('mayura:scope:v1', scope);
|
|
134
|
-
const
|
|
135
|
-
|
|
174
|
+
const policies = settings.map(entry => Object.freeze({ ...entry, digest: workflowPolicyDigest('mayura:workflow-lifecycle-policy:v1', scope, entry) }));
|
|
175
|
+
const currentPolicy = policies[0];
|
|
176
|
+
const policy = currentPolicy.digest;
|
|
177
|
+
const maxCostMicros = currentPolicy.maxCostMicros;
|
|
178
|
+
/** The settings a stored run was started with; undefined when they are neither current nor listed. */
|
|
179
|
+
const pinnedTo = (state) => policies.find(entry => entry.digest === state.policy);
|
|
136
180
|
const active = new Map();
|
|
137
181
|
let closed = false;
|
|
138
182
|
const gate = createWorkflowDrainGate();
|
|
@@ -163,7 +207,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
163
207
|
return await save(record, state, type, data);
|
|
164
208
|
}
|
|
165
209
|
catch (error) {
|
|
166
|
-
if (!(error instanceof StorageError) || error.
|
|
210
|
+
if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
|
|
167
211
|
throw error;
|
|
168
212
|
}
|
|
169
213
|
}
|
|
@@ -184,7 +228,8 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
184
228
|
throw new MayuraError('PERMISSION_DENIED', 'Human identity verification failed.');
|
|
185
229
|
}
|
|
186
230
|
};
|
|
187
|
-
|
|
231
|
+
// Bound to the run's own policy, so an approval issued before an upgrade stays valid for the run it was issued to.
|
|
232
|
+
const approvalCandidate = (node, input, runId, expiresAt, policy) => digest('mayura:approval:v1', { runId, nodeId: node.id,
|
|
188
233
|
tool: node.tool.id, toolVersion: node.tool.version, input, policy, expiresAt });
|
|
189
234
|
const schedulable = (state) => state.status !== 'paused' && state.status !== 'cancelled';
|
|
190
235
|
const skip = (step) => {
|
|
@@ -208,13 +253,27 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
208
253
|
step.fireAtMs = null;
|
|
209
254
|
step.firedAtMs = null;
|
|
210
255
|
}
|
|
256
|
+
else if (step.kind === 'signal') {
|
|
257
|
+
step.status = 'skipped';
|
|
258
|
+
clearSignal(step);
|
|
259
|
+
step.deadlineAtMs = null;
|
|
260
|
+
}
|
|
211
261
|
else
|
|
212
262
|
step.status = 'skipped';
|
|
213
263
|
return true;
|
|
214
264
|
};
|
|
265
|
+
// A signal kept for a step that never runs is dropped with it.
|
|
266
|
+
const clearSignal = (step) => {
|
|
267
|
+
step.output = null;
|
|
268
|
+
step.signalId = null;
|
|
269
|
+
step.payloadDigest = null;
|
|
270
|
+
step.receivedAtMs = null;
|
|
271
|
+
};
|
|
215
272
|
const bypass = (step) => {
|
|
216
273
|
if (step.status !== 'pending')
|
|
217
274
|
return false;
|
|
275
|
+
if (step.kind === 'signal')
|
|
276
|
+
clearSignal(step);
|
|
218
277
|
step.status = 'bypassed';
|
|
219
278
|
return true;
|
|
220
279
|
};
|
|
@@ -235,10 +294,33 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
235
294
|
const record = await load(id);
|
|
236
295
|
const state = stateFrom(record);
|
|
237
296
|
const step = state.steps[node.id];
|
|
238
|
-
|
|
297
|
+
// Every limit and grant below comes from the run's own policy, never from the current one.
|
|
298
|
+
const run = pinnedTo(state);
|
|
299
|
+
if (!step || step.kind !== node.kind || !run || !schedulable(state))
|
|
239
300
|
return;
|
|
301
|
+
const { permissions, maxOutputBytes, approvalTtlMs } = run;
|
|
240
302
|
// A pause or cancellation may commit after this read; every scheduling transition rechecks the latest state.
|
|
241
303
|
const advance = (transition, type, data) => mutate(id, current => schedulable(current) && transition(current), type, data);
|
|
304
|
+
// A dispatching step that no call in this process owns may belong to a process that stopped (killed, or frozen
|
|
305
|
+
// past its limit). Once the tool's timeout and a margin have passed since the dispatch, no live process can still
|
|
306
|
+
// settle it, so it is settled as recoverAbandoned would: unknown, or blocked when a receipt shows it succeeded. The
|
|
307
|
+
// effect is never run again.
|
|
308
|
+
if (node.kind === 'tool' && step.kind === 'tool' && step.status === 'dispatching') {
|
|
309
|
+
if (active.has(`${id}/${node.id}`))
|
|
310
|
+
return;
|
|
311
|
+
const dispatchedAtMs = await storageCall(() => dispatchedAt(store, scopeKey, id, 'lifecycle.step.dispatching', node.id));
|
|
312
|
+
if (!abandoned(dispatchedAtMs, node.tool.timeoutMs, now()))
|
|
313
|
+
return;
|
|
314
|
+
await advance(current => {
|
|
315
|
+
const target = current.steps[node.id];
|
|
316
|
+
if (!target || target.kind !== 'tool' || target.status !== 'dispatching' || active.has(`${id}/${node.id}`))
|
|
317
|
+
return false;
|
|
318
|
+
target.status = target.receipt?.execution === 'succeeded' ? 'blocked' : 'unknown';
|
|
319
|
+
current.status = 'running';
|
|
320
|
+
return true;
|
|
321
|
+
}, 'lifecycle.step.abandoned', { nodeId: node.id });
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
242
324
|
const dependencies = (node.dependsOn ?? []).map(key => state.steps[key]);
|
|
243
325
|
if (dependencies.some(item => terminalStepStatuses.has(item.status) && !satisfiedStepStatuses.has(item.status))) {
|
|
244
326
|
await advance(current => skip(current.steps[node.id]), 'lifecycle.step.skipped', { nodeId: node.id });
|
|
@@ -299,6 +381,51 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
299
381
|
}, deadlineAtMs !== null && observedAtMs >= deadlineAtMs ? 'lifecycle.human.timed_out' : 'lifecycle.human.requested', { nodeId: node.id, requestDigest });
|
|
300
382
|
return;
|
|
301
383
|
}
|
|
384
|
+
if (node.kind === 'signal') {
|
|
385
|
+
if (step.kind !== 'signal' || !['pending', 'waiting'].includes(step.status))
|
|
386
|
+
return;
|
|
387
|
+
if (step.status === 'waiting') {
|
|
388
|
+
const observedAtMs = now();
|
|
389
|
+
if (step.deadlineAtMs === null || observedAtMs < step.deadlineAtMs)
|
|
390
|
+
return;
|
|
391
|
+
await advance(current => {
|
|
392
|
+
const target = current.steps[node.id];
|
|
393
|
+
if (!target || target.kind !== 'signal' || target.status !== 'waiting' || target.deadlineAtMs === null || observedAtMs < target.deadlineAtMs)
|
|
394
|
+
return false;
|
|
395
|
+
target.status = 'timed_out';
|
|
396
|
+
current.status = 'running';
|
|
397
|
+
return true;
|
|
398
|
+
}, 'lifecycle.signal.timed_out', { nodeId: node.id, observedAtMs });
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
let deadlineAtMs = null;
|
|
402
|
+
try {
|
|
403
|
+
if (node.deadlineAtMs)
|
|
404
|
+
deadlineAtMs = exactTimestamp(resolveBinding(node.deadlineAtMs, state.input, outputs(state)));
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
await advance(current => skip(current.steps[node.id]), 'lifecycle.signal.invalid', { nodeId: node.id });
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const observedAtMs = now();
|
|
411
|
+
// A signal kept from before the step started counts if it arrived before the deadline.
|
|
412
|
+
const decide = (target) => target.signalId !== null ? (deadlineAtMs === null || target.receivedAtMs < deadlineAtMs ? 'succeeded' : 'timed_out')
|
|
413
|
+
: deadlineAtMs !== null && observedAtMs >= deadlineAtMs ? 'timed_out' : 'waiting';
|
|
414
|
+
const next = decide(step);
|
|
415
|
+
await advance(current => {
|
|
416
|
+
const target = current.steps[node.id];
|
|
417
|
+
// A signal delivered since the read changes the decision: leave it to the next wave.
|
|
418
|
+
if (!target || target.kind !== 'signal' || target.status !== 'pending' || decide(target) !== next)
|
|
419
|
+
return false;
|
|
420
|
+
target.deadlineAtMs = deadlineAtMs;
|
|
421
|
+
target.status = next;
|
|
422
|
+
if (next === 'timed_out')
|
|
423
|
+
clearSignal(target);
|
|
424
|
+
current.status = next === 'waiting' ? 'waiting' : 'running';
|
|
425
|
+
return true;
|
|
426
|
+
}, next === 'succeeded' ? 'lifecycle.signal.received' : `lifecycle.signal.${next}`, { nodeId: node.id });
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
302
429
|
if (node.kind === 'timer') {
|
|
303
430
|
if (step.kind !== 'timer' || !['pending', 'waiting'].includes(step.status))
|
|
304
431
|
return;
|
|
@@ -355,7 +482,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
355
482
|
await save(record, state, 'lifecycle.step.completed', { nodeId: node.id });
|
|
356
483
|
}
|
|
357
484
|
catch (error) {
|
|
358
|
-
if (!(error instanceof StorageError) || error.
|
|
485
|
+
if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
|
|
359
486
|
throw error;
|
|
360
487
|
}
|
|
361
488
|
return;
|
|
@@ -370,7 +497,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
370
497
|
await save(record, state, 'lifecycle.step.blocked', { nodeId: node.id, code: 'PERMISSION_DENIED' });
|
|
371
498
|
}
|
|
372
499
|
catch (error) {
|
|
373
|
-
if (!(error instanceof StorageError) || error.
|
|
500
|
+
if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
|
|
374
501
|
throw error;
|
|
375
502
|
}
|
|
376
503
|
return;
|
|
@@ -385,7 +512,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
385
512
|
await save(record, state, 'lifecycle.step.failed', { nodeId: node.id, code: 'INVALID_INPUT' });
|
|
386
513
|
}
|
|
387
514
|
catch (error) {
|
|
388
|
-
if (!(error instanceof StorageError) || error.
|
|
515
|
+
if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
|
|
389
516
|
throw error;
|
|
390
517
|
}
|
|
391
518
|
return;
|
|
@@ -393,7 +520,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
393
520
|
const observedAtMs = now();
|
|
394
521
|
const previousExpiry = step.approval?.expiresAt ?? 0;
|
|
395
522
|
const reviewExpiry = node.approval ? (previousExpiry > observedAtMs ? previousExpiry : observedAtMs + approvalTtlMs) : null;
|
|
396
|
-
const candidateHash = approvalCandidate(node, input, id, reviewExpiry);
|
|
523
|
+
const candidateHash = approvalCandidate(node, input, id, reviewExpiry, run.digest);
|
|
397
524
|
if (node.approval && (step.status !== 'approved' || step.approval?.digest !== candidateHash || step.approval.expiresAt <= observedAtMs)) {
|
|
398
525
|
step.status = 'waiting';
|
|
399
526
|
step.approval = { digest: candidateHash, expiresAt: reviewExpiry, humanId: null };
|
|
@@ -402,7 +529,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
402
529
|
await save(record, state, 'lifecycle.approval.requested', { nodeId: node.id, digest: candidateHash });
|
|
403
530
|
}
|
|
404
531
|
catch (error) {
|
|
405
|
-
if (!(error instanceof StorageError) || error.
|
|
532
|
+
if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
|
|
406
533
|
throw error;
|
|
407
534
|
}
|
|
408
535
|
return;
|
|
@@ -429,7 +556,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
429
556
|
await save(record, state, 'lifecycle.step.dispatching', { nodeId: node.id, callId: step.callId });
|
|
430
557
|
}
|
|
431
558
|
catch (error) {
|
|
432
|
-
if (error instanceof StorageError && error.
|
|
559
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT' && claimRetries < 32)
|
|
433
560
|
return executeNode(id, definition, node, claimRetries + 1);
|
|
434
561
|
throw error;
|
|
435
562
|
}
|
|
@@ -443,8 +570,8 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
443
570
|
beforeDispatch: async (processed) => {
|
|
444
571
|
const current = stateFrom(await load(id));
|
|
445
572
|
const target = current.steps[node.id];
|
|
446
|
-
if (!target || target.kind !== 'tool' || current.status !== 'running' || current.policy !==
|
|
447
|
-
|| target.status !== 'dispatching' || approvalCandidate(node, processed, id, node.approval ? target.approval.expiresAt : null) !== candidateHash)
|
|
573
|
+
if (!target || target.kind !== 'tool' || current.status !== 'running' || current.policy !== run.digest
|
|
574
|
+
|| target.status !== 'dispatching' || approvalCandidate(node, processed, id, node.approval ? target.approval.expiresAt : null, run.digest) !== candidateHash)
|
|
448
575
|
throw new MayuraError('CONFLICT', 'Lifecycle dispatch candidate is no longer authorized.');
|
|
449
576
|
if (node.approval && target.approval.expiresAt <= now())
|
|
450
577
|
throw new MayuraError('PERMISSION_DENIED', 'Approval expired before dispatch.');
|
|
@@ -511,18 +638,22 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
511
638
|
schemaDigest: node.request.schemaDigest, prompt: node.request.prompt, context, subjectDigest, deadlineAtMs });
|
|
512
639
|
return { requestDigest, deadlineAtMs, context, subjectDigest };
|
|
513
640
|
};
|
|
514
|
-
|
|
641
|
+
function verifyDefinition(definition, record, state, anyPolicy = false) {
|
|
515
642
|
assertWorkflowLifecycle(definition);
|
|
516
|
-
if (record.definitionHash !== definition.digest || state.definition !== definition.digest
|
|
517
|
-
|
|
518
|
-
|
|
643
|
+
if (record.definitionHash !== definition.digest || state.definition !== definition.digest) {
|
|
644
|
+
throw new MayuraError('CONFLICT', 'Lifecycle definition changed; explicit migration/review is required.');
|
|
645
|
+
}
|
|
646
|
+
const run = pinnedTo(state);
|
|
647
|
+
if (run ? state.maxCostMicros !== run.maxCostMicros : !anyPolicy)
|
|
648
|
+
throw unknownWorkflowPolicy();
|
|
519
649
|
try {
|
|
520
650
|
assertWorkflowLifecycleStateMatchesManifest(state, lifecycleManifest(definition));
|
|
521
651
|
}
|
|
522
652
|
catch {
|
|
523
653
|
throw new MayuraError('CONFLICT', 'Stored lifecycle steps do not match the pinned definition.');
|
|
524
654
|
}
|
|
525
|
-
|
|
655
|
+
return run;
|
|
656
|
+
}
|
|
526
657
|
const respondAs = async (definition, command, actor) => {
|
|
527
658
|
ensureOpen();
|
|
528
659
|
assertWorkflowLifecycle(definition);
|
|
@@ -537,14 +668,14 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
537
668
|
if (!node || node.kind !== 'human')
|
|
538
669
|
throw new MayuraError('INVALID_INPUT', 'Human response node is not part of the lifecycle definition.');
|
|
539
670
|
const before = await load(command.id);
|
|
540
|
-
verifyDefinition(definition, before, stateFrom(before));
|
|
541
|
-
const value = jsonValue(await controlled(() => validate(node.request.response, command.value, 'input')), { maxBytes: maxOutputBytes });
|
|
671
|
+
const run = verifyDefinition(definition, before, stateFrom(before));
|
|
672
|
+
const value = jsonValue(await controlled(() => validate(node.request.response, command.value, 'input')), { maxBytes: run.maxOutputBytes });
|
|
542
673
|
const responseDigest = digest('mayura:human-response:v1', { requestDigest: command.requestDigest,
|
|
543
674
|
commandId: command.commandId, actorId: actor.id, value });
|
|
544
675
|
const observedAtMs = now();
|
|
545
676
|
return publicSnapshot(await mutate(command.id, state => {
|
|
546
677
|
const step = state.steps[command.nodeId];
|
|
547
|
-
if (!step || step.kind !== 'human' || state.policy !==
|
|
678
|
+
if (!step || step.kind !== 'human' || state.policy !== run.digest || step.requestDigest !== command.requestDigest) {
|
|
548
679
|
throw new MayuraError('CONFLICT', 'Human request is stale or mismatched.');
|
|
549
680
|
}
|
|
550
681
|
if (step.status === 'succeeded') {
|
|
@@ -565,23 +696,25 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
565
696
|
}, 'lifecycle.human.responded', { nodeId: command.nodeId, requestDigest: command.requestDigest,
|
|
566
697
|
responseDigest, actorId: actor.id }));
|
|
567
698
|
};
|
|
568
|
-
|
|
699
|
+
const submitUnder = async (under, definition, command) => {
|
|
700
|
+
ensureOpen();
|
|
701
|
+
assertWorkflowLifecycle(definition);
|
|
702
|
+
if (typeof command.idempotencyKey !== 'string' || command.idempotencyKey.length < 1 || command.idempotencyKey.length > 128) {
|
|
703
|
+
throw new MayuraError('INVALID_INPUT', 'A bounded lifecycle submission key is required.');
|
|
704
|
+
}
|
|
705
|
+
const inputSnapshot = freezeJson(jsonValue(command.input, { maxBytes: under.maxOutputBytes }));
|
|
706
|
+
const input = jsonValue(await controlled(() => validate(definition.input, inputSnapshot, 'input')), { maxBytes: under.maxOutputBytes });
|
|
707
|
+
const state = initialWorkflowLifecycleState(lifecycleManifest(definition), input, definition.digest, under.digest, under.maxCostMicros);
|
|
708
|
+
const id = digest('mayura:workflow-lifecycle-run-id:v1', { scope: scopeKey, submissionKey: command.idempotencyKey });
|
|
709
|
+
const created = await createSubmission(() => store.create({ scope: scopeKey, id, idempotencyKey: `lifecycle:${command.idempotencyKey}`,
|
|
710
|
+
definitionHash: definition.digest, state: jsonValue(state), events: [{ type: 'lifecycle.run.created', data: {} }] }), 'workflow lifecycle run');
|
|
711
|
+
verifyDefinition(definition, created.record, stateFrom(created.record));
|
|
712
|
+
return publicSnapshot(created.record);
|
|
713
|
+
};
|
|
714
|
+
const runtime = Object.freeze({
|
|
569
715
|
profile: 'lifecycle-v1',
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
assertWorkflowLifecycle(definition);
|
|
573
|
-
if (typeof command.idempotencyKey !== 'string' || command.idempotencyKey.length < 1 || command.idempotencyKey.length > 128) {
|
|
574
|
-
throw new MayuraError('INVALID_INPUT', 'A bounded lifecycle submission key is required.');
|
|
575
|
-
}
|
|
576
|
-
const inputSnapshot = freezeJson(jsonValue(command.input, { maxBytes: maxOutputBytes }));
|
|
577
|
-
const input = jsonValue(await controlled(() => validate(definition.input, inputSnapshot, 'input')), { maxBytes: maxOutputBytes });
|
|
578
|
-
const state = initialWorkflowLifecycleState(lifecycleManifest(definition), input, definition.digest, policy, maxCostMicros);
|
|
579
|
-
const id = digest('mayura:workflow-lifecycle-run-id:v1', { scope: scopeKey, submissionKey: command.idempotencyKey });
|
|
580
|
-
const created = await storageCall(() => store.create({ scope: scopeKey, id, idempotencyKey: `lifecycle:${command.idempotencyKey}`,
|
|
581
|
-
definitionHash: definition.digest, state: jsonValue(state), events: [{ type: 'lifecycle.run.created', data: {} }] }));
|
|
582
|
-
verifyDefinition(definition, created.record, stateFrom(created.record));
|
|
583
|
-
return publicSnapshot(created.record);
|
|
584
|
-
},
|
|
716
|
+
// New runs always use the current settings.
|
|
717
|
+
submit: (definition, command) => submitUnder(currentPolicy, definition, command),
|
|
585
718
|
inspect: async (id) => publicSnapshot(await load(id)),
|
|
586
719
|
humanRequest: async (definition, id, nodeId) => {
|
|
587
720
|
ensureOpen();
|
|
@@ -611,7 +744,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
611
744
|
throw new MayuraError('INVALID_INPUT', 'A lifecycle tool node ID is required.');
|
|
612
745
|
const record = await load(id);
|
|
613
746
|
const state = stateFrom(record);
|
|
614
|
-
verifyDefinition(definition, record, state);
|
|
747
|
+
const run = verifyDefinition(definition, record, state);
|
|
615
748
|
const node = definition.nodes.find(candidate => candidate.id === nodeId);
|
|
616
749
|
const step = state.steps[nodeId];
|
|
617
750
|
if (!node || node.kind !== 'tool' || !step || step.kind !== 'tool')
|
|
@@ -619,8 +752,8 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
619
752
|
if (!node.approval || !step.approval || (step.status !== 'waiting' && step.status !== 'approved'))
|
|
620
753
|
return undefined;
|
|
621
754
|
// Rebuild the input exactly as preparation did; it must reproduce the persisted digest, or the evidence is refused.
|
|
622
|
-
const input = jsonValue(await controlled(() => validate(node.tool.input, resolveBinding(node.input, state.input, outputs(state)), 'input'), node.tool.timeoutMs), { maxBytes: maxOutputBytes });
|
|
623
|
-
if (approvalCandidate(node, input, id, step.approval.expiresAt) !== step.approval.digest) {
|
|
755
|
+
const input = jsonValue(await controlled(() => validate(node.tool.input, resolveBinding(node.input, state.input, outputs(state)), 'input'), node.tool.timeoutMs), { maxBytes: run.maxOutputBytes });
|
|
756
|
+
if (approvalCandidate(node, input, id, step.approval.expiresAt, run.digest) !== step.approval.digest) {
|
|
624
757
|
throw new MayuraError('CONFLICT', 'Persisted approval evidence does not match its definition.');
|
|
625
758
|
}
|
|
626
759
|
return freezeJson(jsonValue({ runId: id, nodeId, status: step.status, toolId: node.tool.id, toolVersion: node.tool.version, input,
|
|
@@ -650,14 +783,14 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
650
783
|
}
|
|
651
784
|
let after = await load(id);
|
|
652
785
|
const next = stateFrom(after);
|
|
653
|
-
verifyDefinition(definition, after, next);
|
|
786
|
+
const run = verifyDefinition(definition, after, next);
|
|
654
787
|
const steps = Object.values(next.steps);
|
|
655
788
|
if (!schedulable(next))
|
|
656
789
|
return publicSnapshot(after);
|
|
657
790
|
if (steps.every(step => terminalStepStatuses.has(step.status))) {
|
|
658
791
|
if (steps.every(step => satisfiedStepStatuses.has(step.status))) {
|
|
659
792
|
try {
|
|
660
|
-
next.output = jsonValue(await controlled(() => validate(definition.output, resolveBinding(definition.result, next.input, outputs(next)), 'output')), { maxBytes: maxOutputBytes });
|
|
793
|
+
next.output = jsonValue(await controlled(() => validate(definition.output, resolveBinding(definition.result, next.input, outputs(next)), 'output')), { maxBytes: run.maxOutputBytes });
|
|
661
794
|
next.status = 'succeeded';
|
|
662
795
|
}
|
|
663
796
|
catch {
|
|
@@ -671,7 +804,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
671
804
|
after = await save(after, next, 'lifecycle.run.completed', { status: next.status });
|
|
672
805
|
}
|
|
673
806
|
catch (error) {
|
|
674
|
-
if (!(error instanceof StorageError) || error.
|
|
807
|
+
if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
|
|
675
808
|
throw error;
|
|
676
809
|
after = await load(id);
|
|
677
810
|
}
|
|
@@ -685,7 +818,7 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
685
818
|
after = await save(after, next, 'lifecycle.run.waiting');
|
|
686
819
|
}
|
|
687
820
|
catch (error) {
|
|
688
|
-
if (!(error instanceof StorageError) || error.
|
|
821
|
+
if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
|
|
689
822
|
throw error;
|
|
690
823
|
after = await load(id);
|
|
691
824
|
}
|
|
@@ -704,7 +837,8 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
704
837
|
const observedAtMs = now();
|
|
705
838
|
return publicSnapshot(await mutate(command.id, state => {
|
|
706
839
|
const step = state.steps[command.nodeId];
|
|
707
|
-
|
|
840
|
+
// The digest binds the run's own policy; a run under an unlisted policy has nothing approvable.
|
|
841
|
+
if (!step || step.kind !== 'tool' || !pinnedTo(state) || !step.approval || step.approval.digest !== command.digest) {
|
|
708
842
|
throw new MayuraError('CONFLICT', 'Approval request is stale, expired or mismatched.');
|
|
709
843
|
}
|
|
710
844
|
if (step.status !== 'waiting' && step.approval.humanId === human.id)
|
|
@@ -728,6 +862,64 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
728
862
|
return respondAs(definition, command, { id: human.id, projectId: human.projectId });
|
|
729
863
|
},
|
|
730
864
|
respondVerified: (definition, command) => respondAs(definition, command, command.actor),
|
|
865
|
+
signal: async (definition, command) => {
|
|
866
|
+
ensureOpen();
|
|
867
|
+
assertWorkflowLifecycle(definition);
|
|
868
|
+
if (!command || typeof command.id !== 'string' || !hashPattern.test(command.id) || typeof command.name !== 'string' || !signalPattern.test(command.name)
|
|
869
|
+
|| typeof command.signalId !== 'string' || !signalPattern.test(command.signalId)
|
|
870
|
+
|| (command.actorId !== undefined && (typeof command.actorId !== 'string' || command.actorId.length < 1 || command.actorId.length > 256))) {
|
|
871
|
+
throw new MayuraError('INVALID_INPUT', 'A signal needs a run id, a signal name and a signal id (1–128 letters, digits, ".", "_", "/" or "-").');
|
|
872
|
+
}
|
|
873
|
+
const node = definition.nodes.find(candidate => candidate.kind === 'signal' && candidate.name === command.name);
|
|
874
|
+
if (!node || node.kind !== 'signal')
|
|
875
|
+
throw new MayuraError('NOT_FOUND', `This workflow has no signal step named "${command.name}".`);
|
|
876
|
+
const before = await load(command.id);
|
|
877
|
+
const run = verifyDefinition(definition, before, stateFrom(before));
|
|
878
|
+
let payload;
|
|
879
|
+
try {
|
|
880
|
+
payload = jsonValue(await controlled(() => validate(node.payload, command.payload, 'input')), { maxBytes: run.maxOutputBytes });
|
|
881
|
+
}
|
|
882
|
+
catch (error) {
|
|
883
|
+
if (error instanceof MayuraError && ['TIMEOUT', 'LIMIT_EXCEEDED'].includes(error.code))
|
|
884
|
+
throw error;
|
|
885
|
+
throw new MayuraError('INVALID_INPUT', `The payload of signal "${command.name}" does not match the step's payload schema.`);
|
|
886
|
+
}
|
|
887
|
+
const payloadDigest = digest('mayura:workflow-signal:v1', { runId: command.id, nodeId: node.id, signalId: command.signalId, payload });
|
|
888
|
+
const receivedAtMs = now();
|
|
889
|
+
return publicSnapshot(await mutate(command.id, state => {
|
|
890
|
+
const step = state.steps[node.id];
|
|
891
|
+
if (!step || step.kind !== 'signal')
|
|
892
|
+
throw new MayuraError('CONFLICT', 'Stored lifecycle steps do not match the pinned definition.');
|
|
893
|
+
if (step.signalId !== null) {
|
|
894
|
+
// Idempotent on the signal id: the same signal again changes nothing.
|
|
895
|
+
if (step.signalId === command.signalId && step.payloadDigest === payloadDigest)
|
|
896
|
+
return false;
|
|
897
|
+
throw new MayuraError('CONFLICT', step.signalId === command.signalId
|
|
898
|
+
? `Signal "${command.signalId}" was already delivered with a different payload.`
|
|
899
|
+
: `Signal step "${node.id}" already received signal "${step.signalId}"; a signal step accepts one signal.`);
|
|
900
|
+
}
|
|
901
|
+
if (finalRunStatuses.has(state.status))
|
|
902
|
+
throw new MayuraError('CONFLICT', `The run is ${state.status}; it no longer accepts signals.`);
|
|
903
|
+
if (step.status !== 'pending' && step.status !== 'waiting') {
|
|
904
|
+
throw new MayuraError('CONFLICT', `Signal step "${node.id}" is ${step.status}; it no longer accepts signals.`);
|
|
905
|
+
}
|
|
906
|
+
if (step.status === 'waiting' && step.deadlineAtMs !== null && receivedAtMs >= step.deadlineAtMs) {
|
|
907
|
+
throw new MayuraError('CONFLICT', `Signal step "${node.id}" passed its deadline; it no longer accepts signals.`);
|
|
908
|
+
}
|
|
909
|
+
step.signalId = command.signalId;
|
|
910
|
+
step.payloadDigest = payloadDigest;
|
|
911
|
+
step.receivedAtMs = receivedAtMs;
|
|
912
|
+
step.output = payload;
|
|
913
|
+
// A step that has not started keeps the signal until it starts.
|
|
914
|
+
if (step.status === 'waiting') {
|
|
915
|
+
step.status = 'succeeded';
|
|
916
|
+
if (state.status !== 'paused')
|
|
917
|
+
state.status = 'running';
|
|
918
|
+
}
|
|
919
|
+
return true;
|
|
920
|
+
}, 'lifecycle.signal.delivered', { nodeId: node.id, signalId: command.signalId, payloadDigest,
|
|
921
|
+
...(command.actorId === undefined ? {} : { actorId: command.actorId }) }));
|
|
922
|
+
},
|
|
731
923
|
pause: async (id) => publicSnapshot(await mutate(id, state => {
|
|
732
924
|
if (state.status === 'paused')
|
|
733
925
|
return false;
|
|
@@ -745,14 +937,17 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
745
937
|
assertWorkflowLifecycle(migration.from);
|
|
746
938
|
assertWorkflowLifecycle(migration.to);
|
|
747
939
|
const { id, actorId, commandId, dryRun = false } = migrationCommand(command);
|
|
940
|
+
// A reviewed migration is the explicit way to move a run onto the current settings, whichever it started under.
|
|
748
941
|
const record = await load(id);
|
|
749
942
|
const state = stateFrom(record);
|
|
750
|
-
verifyDefinition(migration.from, record, state);
|
|
943
|
+
verifyDefinition(migration.from, record, state, true);
|
|
751
944
|
const nodes = (definition) => lifecycleManifest(definition).graph.map(node => ({ id: node.id, kind: node.kind, dependsOn: node.dependsOn, fingerprint: nodeFingerprint(node),
|
|
752
945
|
...(nodeEvidence(node) ? { evidence: nodeEvidence(node) } : {}) }));
|
|
753
946
|
const preconditions = [];
|
|
754
947
|
if (state.status !== 'paused')
|
|
755
948
|
preconditions.push({ node: '*', reason: `The run is ${state.status}; pause it before migrating.` });
|
|
949
|
+
if (state.spentMicros > maxCostMicros)
|
|
950
|
+
preconditions.push({ node: '*', reason: 'The run already spent more than the current maxCostMicros.' });
|
|
756
951
|
const plan = planWorkflowMigration({ migration, format: 'lifecycle-v1', runId: id, fromDigest: migration.from.digest, toDigest: migration.to.digest,
|
|
757
952
|
from: nodes(migration.from), to: nodes(migration.to), steps: Object.entries(state.steps).map(([step, value]) => ({ id: step, status: value.status })), preconditions });
|
|
758
953
|
if (dryRun)
|
|
@@ -763,9 +958,11 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
763
958
|
for (const entry of plan.entries) {
|
|
764
959
|
if (!entry.target)
|
|
765
960
|
continue;
|
|
766
|
-
|
|
961
|
+
const source = entry.source === undefined ? undefined : state.steps[entry.source];
|
|
962
|
+
steps[entry.target] = entry.action === 'keep' || entry.action === 'accept'
|
|
963
|
+
|| (entry.action === 'update' && source?.kind === 'signal' && fresh.steps[entry.target].kind === 'signal') ? source : fresh.steps[entry.target];
|
|
767
964
|
}
|
|
768
|
-
const next = { ...state, definition: migration.to.digest,
|
|
965
|
+
const next = { ...state, definition: migration.to.digest, policy, maxCostMicros,
|
|
769
966
|
steps: Object.fromEntries(migration.to.nodes.map(node => [node.id, steps[node.id]])) };
|
|
770
967
|
// Released holds: only carried tool steps keep reserved cost.
|
|
771
968
|
next.reservedMicros = Object.values(next.steps).reduce((sum, step) => sum + (step.kind === 'tool' ? step.costReserved : 0), 0);
|
|
@@ -827,5 +1024,12 @@ export function createWorkflowLifecycleRuntime(options) {
|
|
|
827
1024
|
drain: options => gate.drain(options, () => { closed = true; for (const controller of active.values())
|
|
828
1025
|
controller.abort(); }),
|
|
829
1026
|
});
|
|
1027
|
+
pinnedSubmissions.set(runtime, (index, definition, command) => {
|
|
1028
|
+
const under = policies[index];
|
|
1029
|
+
if (!Number.isSafeInteger(index) || !under)
|
|
1030
|
+
throw new MayuraError('INVALID_INPUT', 'The requested lifecycle policy is not configured.');
|
|
1031
|
+
return submitUnder(under, definition, command);
|
|
1032
|
+
});
|
|
1033
|
+
return runtime;
|
|
830
1034
|
}
|
|
831
1035
|
//# sourceMappingURL=lifecycle-runtime.js.map
|