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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type Effect, type InferInput, type InferOutput, type Media, type RunHandle, type Schema } from '../../core/dist/index.js';
|
|
2
|
+
import { type AgentDefinition, type RuntimeLimits } from '../../runtime/dist/index.js';
|
|
3
|
+
import { type ToolDefinition, type ToolExecutionContext } from '../../tools/dist/index.js';
|
|
4
|
+
/** The agent's runtime limits. `maxCostMicros` is required: it is the most the step may spend. */
|
|
5
|
+
export type AgentStepLimits = Omit<RuntimeLimits, 'maxCostMicros'> & {
|
|
6
|
+
readonly maxCostMicros: number;
|
|
7
|
+
};
|
|
8
|
+
interface AgentStepCommon<SI extends Schema, SO extends Schema, AI, AO> {
|
|
9
|
+
/** The step tool's id: the workflow's policy grants `tool:<id>`. */
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly version?: string;
|
|
12
|
+
readonly description?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Grants for the agent's own model and tool calls, for example `model:openai.responses` and `tool:tickets.label`.
|
|
15
|
+
* The workflow's grants never widen them: the workflow grants the step, this grants the agent inside it.
|
|
16
|
+
*/
|
|
17
|
+
readonly permissions: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* Limits of the agent's run. `maxCostMicros` is the step's ceiling: the run budget reserves it before the step
|
|
20
|
+
* starts and is charged what the agent actually spent. Use 0 only for a model that costs nothing.
|
|
21
|
+
*/
|
|
22
|
+
readonly limits: AgentStepLimits;
|
|
23
|
+
/** Extra grants the workflow's policy must hold to run the step. */
|
|
24
|
+
readonly capabilities?: readonly string[];
|
|
25
|
+
/** The step's deadline. Default: the agent's `maxDurationMs` (default 60 s) plus 15 s, so the agent's own limit fires first. */
|
|
26
|
+
readonly timeoutMs?: number;
|
|
27
|
+
/** Turn the step's input into the agent's input. Default: the step input is the agent input. */
|
|
28
|
+
readonly prepare?: (input: InferOutput<SI>, context: ToolExecutionContext) => AI | Promise<AI>;
|
|
29
|
+
/**
|
|
30
|
+
* Images or PDFs for the agent to see, found when the step runs: for example read from an artifact store with
|
|
31
|
+
* `mediaFromArtifact`, using a reference in the step's input. The workflow keeps only that JSON input, never media
|
|
32
|
+
* bytes. A failure here is a refusal, like `prepare`.
|
|
33
|
+
*/
|
|
34
|
+
readonly media?: (input: InferOutput<SI>, context: ToolExecutionContext) => readonly Media[] | Promise<readonly Media[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Turn a successful agent output into the step's output, or throw to fail the step (for example after checking the
|
|
37
|
+
* output). Default: the agent output is the step output.
|
|
38
|
+
*/
|
|
39
|
+
readonly finish?: (output: AO, input: InferOutput<SI>, context: ToolExecutionContext) => InferInput<SO> | Promise<InferInput<SO>>;
|
|
40
|
+
/**
|
|
41
|
+
* Called once the agent's run starts, for example to observe or trace it. A returned function is awaited once the
|
|
42
|
+
* run settles. Neither can fail the step: their errors are ignored.
|
|
43
|
+
*/
|
|
44
|
+
readonly onRun?: (run: RunHandle<AO>, context: ToolExecutionContext) => void | (() => void | Promise<void>);
|
|
45
|
+
}
|
|
46
|
+
/** Options for an agent step whose agent is fixed. */
|
|
47
|
+
export interface AgentStepOptions<SI extends Schema, SO extends Schema, AI, AO> extends AgentStepCommon<SI, SO, AI, AO> {
|
|
48
|
+
/** The step's input schema. Default: the agent's input. */
|
|
49
|
+
readonly input?: SI;
|
|
50
|
+
/** The step's output schema. Default: the agent's output. */
|
|
51
|
+
readonly output?: SO;
|
|
52
|
+
}
|
|
53
|
+
/** Options for an agent step that builds its agent for each run, for example with tools bound to that run. */
|
|
54
|
+
export interface AgentStepFactoryOptions<SI extends Schema, SO extends Schema, AI, AO> extends AgentStepCommon<SI, SO, AI, AO> {
|
|
55
|
+
readonly input: SI;
|
|
56
|
+
readonly output: SO;
|
|
57
|
+
/** The strongest effect the built agent's tools may have. A built agent with stronger tools fails the step before it runs. */
|
|
58
|
+
readonly effects: Effect;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* An agent as one workflow step: a tool for a `tool` node of a lifecycle workflow (or any workflow that runs tools).
|
|
62
|
+
*
|
|
63
|
+
* Each time the step runs, it starts an in-process runtime with the run's scope, `permissions` and `limits`, runs the
|
|
64
|
+
* agent, and reports what the agent actually spent, so the run budget is charged the real cost (never less than the
|
|
65
|
+
* agent's known spending, never more than `limits.maxCostMicros`). The agent's outcome decides the step's:
|
|
66
|
+
*
|
|
67
|
+
* - `succeeded`: the step succeeds with the agent's output (or what `finish` returns);
|
|
68
|
+
* - `failed`, `blocked` or `cancelled`: the step fails;
|
|
69
|
+
* - `outcome_unknown`: the step is `unknown`, and the run needs reconciling. Its ceiling stays reserved.
|
|
70
|
+
*
|
|
71
|
+
* Cancelling or timing out the step cancels the agent. If the agent's tools can change things (`write` or `host`
|
|
72
|
+
* effects), an interrupted step is `unknown`, because the agent may have been part-way through an effect.
|
|
73
|
+
* A failure before the agent starts (building it, `prepare`) is a refusal: the step fails and is charged nothing.
|
|
74
|
+
*
|
|
75
|
+
* The workflow's policy must grant `tool:<id>`, each of `capabilities`, and `effect:<kind>` for the strongest effect
|
|
76
|
+
* among the agent's tools. The model loop inside the step is not checkpointed: a crash mid-step leaves the step
|
|
77
|
+
* dispatching until its timeout and a margin pass, when the next pass settles it as unknown (or `recoverAbandoned` does it
|
|
78
|
+
* sooner). The agent is never run again by itself.
|
|
79
|
+
*/
|
|
80
|
+
export declare function agentStep<AI extends Schema, AO extends Schema, SI extends Schema = AI, SO extends Schema = AO>(agent: AgentDefinition<AI, AO>, options: AgentStepOptions<SI, SO, InferInput<AI>, InferOutput<AO>>): ToolDefinition<SI, SO>;
|
|
81
|
+
export declare function agentStep<SI extends Schema, SO extends Schema, AI extends Schema, AO extends Schema>(agent: (input: InferOutput<SI>, context: ToolExecutionContext) => AgentDefinition<AI, AO>, options: AgentStepFactoryOptions<SI, SO, InferInput<AI>, InferOutput<AO>>): ToolDefinition<SI, SO>;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=agent-step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-step.d.ts","sourceRoot":"","sources":["../src/agent-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AACpI,OAAO,EAA8B,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACvG,OAAO,EAAyC,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAEtH,kGAAkG;AAClG,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG;IAAE,QAAQ,CAAC,aAAa,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M,EAAE,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,MAAM,EAClG,KAAK,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,oBAAoB,KAAK,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,EACzF,OAAO,EAAE,uBAAuB,CAAC,EAAE,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,GAAG,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { MayuraError } from '../../core/dist/index.js';
|
|
2
|
+
import { assertAgent, createRuntime } from '../../runtime/dist/index.js';
|
|
3
|
+
import { defineTool, ToolRefusal } from '../../tools/dist/index.js';
|
|
4
|
+
const rank = Object.freeze({ none: 0, read: 1, write: 2, host: 3 });
|
|
5
|
+
const effectsOf = (tools) => tools.reduce((strongest, tool) => rank[tool.effects] > rank[strongest] ? tool.effects : strongest, 'none');
|
|
6
|
+
const identifier = /^[A-Za-z][A-Za-z0-9._/-]{0,127}$/;
|
|
7
|
+
export function agentStep(agent, options) {
|
|
8
|
+
if (!options || typeof options !== 'object' || typeof options.id !== 'string' || !identifier.test(options.id)) {
|
|
9
|
+
throw new MayuraError('INVALID_CONFIG', 'agentStep needs an id: a letter, then up to 127 letters, digits, ".", "_", "/" or "-".');
|
|
10
|
+
}
|
|
11
|
+
const built = typeof agent === 'function';
|
|
12
|
+
if (!built)
|
|
13
|
+
assertAgent(agent);
|
|
14
|
+
else if (!options.input || !options.output || !Object.hasOwn(rank, options.effects ?? '')) {
|
|
15
|
+
throw new MayuraError('INVALID_CONFIG', `agentStep "${options.id}" builds its agent per run, so it needs input and output schemas and the effects of the agent's tools.`);
|
|
16
|
+
}
|
|
17
|
+
const grants = options.permissions;
|
|
18
|
+
if (!Array.isArray(grants) || grants.length > 4_096 || grants.some(grant => typeof grant !== 'string' || grant.length < 1 || grant.length > 384)) {
|
|
19
|
+
throw new MayuraError('INVALID_CONFIG', `agentStep "${options.id}" needs permissions: an array of the grants its agent may use.`);
|
|
20
|
+
}
|
|
21
|
+
const permissions = Object.freeze({ allow: Object.freeze([...grants]) });
|
|
22
|
+
const limits = Object.freeze({ ...options.limits });
|
|
23
|
+
const ceiling = limits.maxCostMicros;
|
|
24
|
+
if (!Number.isSafeInteger(ceiling) || ceiling < 0) {
|
|
25
|
+
throw new MayuraError('INVALID_CONFIG', `agentStep "${options.id}" needs limits.maxCostMicros: the most the step may spend (0 for a free model).`);
|
|
26
|
+
}
|
|
27
|
+
const effects = built ? options.effects : effectsOf(agent.tools);
|
|
28
|
+
// Only an agent that can change something outside the run can leave the step's outcome uncertain.
|
|
29
|
+
const acting = effects === 'write' || effects === 'host';
|
|
30
|
+
// How the step records an uncertain outcome. With a ceiling, the step is declared effect-free and reports the rest
|
|
31
|
+
// of its ceiling as unknown cost, which makes its outcome unknown while a failed agent stays a plain failure. A step
|
|
32
|
+
// that may spend nothing cannot report cost, so an acting agent's step declares the agent's effects instead: an
|
|
33
|
+
// uncertain outcome is then unknown by itself, and a failure is a refusal (it spent nothing).
|
|
34
|
+
const direct = acting && ceiling === 0;
|
|
35
|
+
const capabilities = [...new Set([...(options.capabilities ?? []), ...(effects === 'none' || direct ? [] : [`effect:${effects}`])])];
|
|
36
|
+
const timeoutMs = options.timeoutMs ?? (limits.maxDurationMs ?? 60_000) + 15_000;
|
|
37
|
+
const name = built ? options.id : agent.id;
|
|
38
|
+
return defineTool({
|
|
39
|
+
id: options.id,
|
|
40
|
+
version: options.version ?? (built ? '1' : agent.version),
|
|
41
|
+
description: options.description ?? `Run the ${name} agent as one workflow step.`,
|
|
42
|
+
input: (options.input ?? agent.input),
|
|
43
|
+
output: (options.output ?? agent.output),
|
|
44
|
+
// The step itself only runs the agent: its effects are the agent's, recorded by the agent's own runtime and
|
|
45
|
+
// required as the `effect:<kind>` grant.
|
|
46
|
+
effects: direct ? effects : 'none', capabilities, costMicros: ceiling, timeoutMs,
|
|
47
|
+
execute: async (input, context) => {
|
|
48
|
+
const refuse = (stage) => { throw new ToolRefusal(`The agent step "${options.id}" ${stage}.`); };
|
|
49
|
+
// Until the agent starts, nothing has run or been spent: a failure here is a refusal, charged nothing.
|
|
50
|
+
let definition;
|
|
51
|
+
let agentInput;
|
|
52
|
+
let agentMedia = [];
|
|
53
|
+
try {
|
|
54
|
+
definition = built ? agent(input, context) : agent;
|
|
55
|
+
assertAgent(definition);
|
|
56
|
+
if (rank[effectsOf(definition.tools)] > rank[effects])
|
|
57
|
+
definition = undefined;
|
|
58
|
+
else {
|
|
59
|
+
agentInput = options.prepare ? await options.prepare(input, context) : input;
|
|
60
|
+
if (options.media)
|
|
61
|
+
agentMedia = await options.media(input, context);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
definition = undefined;
|
|
66
|
+
}
|
|
67
|
+
if (!definition)
|
|
68
|
+
return refuse('could not prepare its agent');
|
|
69
|
+
const runtime = createRuntime({ profile: 'ephemeral', scope: context.scope, permissions, limits });
|
|
70
|
+
let run;
|
|
71
|
+
let reported = false;
|
|
72
|
+
const spent = () => {
|
|
73
|
+
if (!run)
|
|
74
|
+
return 0;
|
|
75
|
+
const value = runtime.inspect(run).budget.spentMicros;
|
|
76
|
+
// An overrun beyond safe integers, or beyond the ceiling, is charged the ceiling: the most the step may cost.
|
|
77
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? Math.min(value, ceiling) : ceiling;
|
|
78
|
+
};
|
|
79
|
+
const report = (knownCostMicros, unknownCostMicros) => {
|
|
80
|
+
if (reported)
|
|
81
|
+
return;
|
|
82
|
+
reported = true;
|
|
83
|
+
context.reportUsage({ knownCostMicros, unknownCostMicros });
|
|
84
|
+
};
|
|
85
|
+
// Charge the whole ceiling: what the agent spent so far as known, the rest as unknown. Reported unknown cost is
|
|
86
|
+
// what makes the step's outcome unknown.
|
|
87
|
+
const uncertain = () => { const known = Math.min(spent(), ceiling - 1); report(known, ceiling - known); };
|
|
88
|
+
/** A known failure: charged what the agent spent. */
|
|
89
|
+
const fail = (stage) => {
|
|
90
|
+
if (direct)
|
|
91
|
+
return refuse(stage);
|
|
92
|
+
report(spent(), 0);
|
|
93
|
+
throw new MayuraError('TOOL_FAILED', `The agent step "${options.id}" ${stage}.`);
|
|
94
|
+
};
|
|
95
|
+
const interrupt = () => {
|
|
96
|
+
// Runs synchronously while the step is being cancelled or timed out, before the step's outcome is decided.
|
|
97
|
+
if (acting && !direct && run) {
|
|
98
|
+
try {
|
|
99
|
+
uncertain();
|
|
100
|
+
}
|
|
101
|
+
catch { /* The outcome is then decided without it. */ }
|
|
102
|
+
}
|
|
103
|
+
run?.cancel();
|
|
104
|
+
};
|
|
105
|
+
context.signal.addEventListener('abort', interrupt, { once: true });
|
|
106
|
+
try {
|
|
107
|
+
if (context.signal.aborted)
|
|
108
|
+
return refuse('was cancelled before its agent started');
|
|
109
|
+
let current;
|
|
110
|
+
try {
|
|
111
|
+
current = runtime.submit(definition, { input: agentInput, ...(agentMedia.length > 0 ? { media: agentMedia } : {}) });
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return refuse('could not start its agent');
|
|
115
|
+
}
|
|
116
|
+
run = current;
|
|
117
|
+
let finished = undefined;
|
|
118
|
+
try {
|
|
119
|
+
finished = options.onRun?.(current, context);
|
|
120
|
+
}
|
|
121
|
+
catch { /* Observers never fail the step. */ }
|
|
122
|
+
let outcome;
|
|
123
|
+
try {
|
|
124
|
+
outcome = await current.result();
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
try {
|
|
128
|
+
if (typeof finished === 'function')
|
|
129
|
+
await finished();
|
|
130
|
+
}
|
|
131
|
+
catch { /* Observers never fail the step. */ }
|
|
132
|
+
}
|
|
133
|
+
if (outcome.status === 'outcome_unknown') {
|
|
134
|
+
if (direct)
|
|
135
|
+
throw new MayuraError('OUTCOME_UNKNOWN', `The agent step "${options.id}" has an unknown outcome.`);
|
|
136
|
+
// Returning (rather than throwing) with unknown cost reported is how a tool says its outcome is unknown.
|
|
137
|
+
if (ceiling > 0) {
|
|
138
|
+
uncertain();
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (outcome.status !== 'succeeded')
|
|
143
|
+
return fail(`ended ${outcome.status}`);
|
|
144
|
+
let output;
|
|
145
|
+
try {
|
|
146
|
+
output = options.finish ? await options.finish(outcome.output, input, context) : outcome.output;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return fail('refused its agent\'s output');
|
|
150
|
+
}
|
|
151
|
+
report(spent(), 0);
|
|
152
|
+
return output;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
context.signal.removeEventListener('abort', interrupt);
|
|
156
|
+
await runtime.close();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=agent-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-step.js","sourceRoot":"","sources":["../src/agent-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA2F,MAAM,cAAc,CAAC;AACpI,OAAO,EAAE,WAAW,EAAE,aAAa,EAA4C,MAAM,iBAAiB,CAAC;AACvG,OAAO,EAAE,UAAU,EAAE,WAAW,EAAgE,MAAM,eAAe,CAAC;AA4DtH,MAAM,IAAI,GAAqC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;AACtG,MAAM,SAAS,GAAG,CAAC,KAAyB,EAAU,EAAE,CACtD,KAAK,CAAC,MAAM,CAAS,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI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,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;gBAAC,CAAC;gBACxG,MAAM,CAAC;oBAAC,OAAO,IAAI,CAAC,6BAA6B,CAAC,CAAC;gBAAC,CAAC;gBACrD,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;gBAAC,OAAO,MAAM,CAAC;YACpC,CAAC;oBAAS,CAAC;gBACT,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBACvD,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACxB,CAAC;QACH,CAAC;KACF,CAAY,CAAC;AAChB,CAAC","sourcesContent":["import { MayuraError, type Effect, type InferInput, type InferOutput, type Media, type RunHandle, type Schema } from '@mayura/core';\nimport { assertAgent, createRuntime, type AgentDefinition, type RuntimeLimits } from '@mayura/runtime';\nimport { defineTool, ToolRefusal, type AnyTool, type ToolDefinition, type ToolExecutionContext } from '@mayura/tools';\n\n/** The agent's runtime limits. `maxCostMicros` is required: it is the most the step may spend. */\nexport type AgentStepLimits = Omit<RuntimeLimits, 'maxCostMicros'> & { readonly maxCostMicros: number };\n\ninterface AgentStepCommon<SI extends Schema, SO extends Schema, AI, AO> {\n /** The step tool's id: the workflow's policy grants `tool:<id>`. */\n readonly id: string;\n readonly version?: string;\n readonly description?: string;\n /**\n * Grants for the agent's own model and tool calls, for example `model:openai.responses` and `tool:tickets.label`.\n * The workflow's grants never widen them: the workflow grants the step, this grants the agent inside it.\n */\n readonly permissions: readonly string[];\n /**\n * Limits of the agent's run. `maxCostMicros` is the step's ceiling: the run budget reserves it before the step\n * starts and is charged what the agent actually spent. Use 0 only for a model that costs nothing.\n */\n readonly limits: AgentStepLimits;\n /** Extra grants the workflow's policy must hold to run the step. */\n readonly capabilities?: readonly string[];\n /** The step's deadline. Default: the agent's `maxDurationMs` (default 60 s) plus 15 s, so the agent's own limit fires first. */\n readonly timeoutMs?: number;\n /** Turn the step's input into the agent's input. Default: the step input is the agent input. */\n readonly prepare?: (input: InferOutput<SI>, context: ToolExecutionContext) => AI | Promise<AI>;\n /**\n * Images or PDFs for the agent to see, found when the step runs: for example read from an artifact store with\n * `mediaFromArtifact`, using a reference in the step's input. The workflow keeps only that JSON input, never media\n * bytes. A failure here is a refusal, like `prepare`.\n */\n readonly media?: (input: InferOutput<SI>, context: ToolExecutionContext) => readonly Media[] | Promise<readonly Media[]>;\n /**\n * Turn a successful agent output into the step's output, or throw to fail the step (for example after checking the\n * output). Default: the agent output is the step output.\n */\n readonly finish?: (output: AO, input: InferOutput<SI>, context: ToolExecutionContext) => InferInput<SO> | Promise<InferInput<SO>>;\n /**\n * Called once the agent's run starts, for example to observe or trace it. A returned function is awaited once the\n * run settles. Neither can fail the step: their errors are ignored.\n */\n readonly onRun?: (run: RunHandle<AO>, context: ToolExecutionContext) => void | (() => void | Promise<void>);\n}\n\n/** Options for an agent step whose agent is fixed. */\nexport interface AgentStepOptions<SI extends Schema, SO extends Schema, AI, AO> extends AgentStepCommon<SI, SO, AI, AO> {\n /** The step's input schema. Default: the agent's input. */\n readonly input?: SI;\n /** The step's output schema. Default: the agent's output. */\n readonly output?: SO;\n}\n\n/** Options for an agent step that builds its agent for each run, for example with tools bound to that run. */\nexport interface AgentStepFactoryOptions<SI extends Schema, SO extends Schema, AI, AO> extends AgentStepCommon<SI, SO, AI, AO> {\n readonly input: SI;\n readonly output: SO;\n /** The strongest effect the built agent's tools may have. A built agent with stronger tools fails the step before it runs. */\n readonly effects: Effect;\n}\n\nconst rank: Readonly<Record<Effect, number>> = Object.freeze({ none: 0, read: 1, write: 2, host: 3 });\nconst effectsOf = (tools: readonly AnyTool[]): Effect =>\n tools.reduce<Effect>((strongest, tool) => rank[tool.effects] > rank[strongest] ? tool.effects : strongest, 'none');\nconst identifier = /^[A-Za-z][A-Za-z0-9._/-]{0,127}$/;\n\n/**\n * An agent as one workflow step: a tool for a `tool` node of a lifecycle workflow (or any workflow that runs tools).\n *\n * Each time the step runs, it starts an in-process runtime with the run's scope, `permissions` and `limits`, runs the\n * agent, and reports what the agent actually spent, so the run budget is charged the real cost (never less than the\n * agent's known spending, never more than `limits.maxCostMicros`). The agent's outcome decides the step's:\n *\n * - `succeeded`: the step succeeds with the agent's output (or what `finish` returns);\n * - `failed`, `blocked` or `cancelled`: the step fails;\n * - `outcome_unknown`: the step is `unknown`, and the run needs reconciling. Its ceiling stays reserved.\n *\n * Cancelling or timing out the step cancels the agent. If the agent's tools can change things (`write` or `host`\n * effects), an interrupted step is `unknown`, because the agent may have been part-way through an effect.\n * A failure before the agent starts (building it, `prepare`) is a refusal: the step fails and is charged nothing.\n *\n * The workflow's policy must grant `tool:<id>`, each of `capabilities`, and `effect:<kind>` for the strongest effect\n * among the agent's tools. The model loop inside the step is not checkpointed: a crash mid-step leaves the step\n * dispatching until its timeout and a margin pass, when the next pass settles it as unknown (or `recoverAbandoned` does it\n * sooner). The agent is never run again by itself.\n */\nexport function agentStep<AI extends Schema, AO extends Schema, SI extends Schema = AI, SO extends Schema = AO>(\n agent: AgentDefinition<AI, AO>, options: AgentStepOptions<SI, SO, InferInput<AI>, InferOutput<AO>>): ToolDefinition<SI, SO>;\nexport function agentStep<SI extends Schema, SO extends Schema, AI extends Schema, AO extends Schema>(\n agent: (input: InferOutput<SI>, context: ToolExecutionContext) => AgentDefinition<AI, AO>,\n options: AgentStepFactoryOptions<SI, SO, InferInput<AI>, InferOutput<AO>>): ToolDefinition<SI, SO>;\nexport function agentStep(agent: AgentDefinition | ((input: unknown, context: ToolExecutionContext) => AgentDefinition),\n options: AgentStepOptions<Schema, Schema, unknown, unknown> & { readonly effects?: Effect }): AnyTool {\n if (!options || typeof options !== 'object' || typeof options.id !== 'string' || !identifier.test(options.id)) {\n throw new MayuraError('INVALID_CONFIG', 'agentStep needs an id: a letter, then up to 127 letters, digits, \".\", \"_\", \"/\" or \"-\".');\n }\n const built = typeof agent === 'function';\n if (!built) assertAgent(agent);\n else if (!options.input || !options.output || !Object.hasOwn(rank, options.effects ?? '')) {\n throw new MayuraError('INVALID_CONFIG', `agentStep \"${options.id}\" builds its agent per run, so it needs input and output schemas and the effects of the agent's tools.`);\n }\n const grants: unknown = options.permissions;\n if (!Array.isArray(grants) || grants.length > 4_096 || grants.some(grant => typeof grant !== 'string' || grant.length < 1 || grant.length > 384)) {\n throw new MayuraError('INVALID_CONFIG', `agentStep \"${options.id}\" needs permissions: an array of the grants its agent may use.`);\n }\n const permissions = Object.freeze({ allow: Object.freeze([...grants as string[]]) });\n const limits = Object.freeze({ ...options.limits });\n const ceiling = limits.maxCostMicros;\n if (!Number.isSafeInteger(ceiling) || ceiling < 0) {\n throw new MayuraError('INVALID_CONFIG', `agentStep \"${options.id}\" needs limits.maxCostMicros: the most the step may spend (0 for a free model).`);\n }\n const effects: Effect = built ? options.effects! : effectsOf(agent.tools);\n // Only an agent that can change something outside the run can leave the step's outcome uncertain.\n const acting = effects === 'write' || effects === 'host';\n // How the step records an uncertain outcome. With a ceiling, the step is declared effect-free and reports the rest\n // of its ceiling as unknown cost, which makes its outcome unknown while a failed agent stays a plain failure. A step\n // that may spend nothing cannot report cost, so an acting agent's step declares the agent's effects instead: an\n // uncertain outcome is then unknown by itself, and a failure is a refusal (it spent nothing).\n const direct = acting && ceiling === 0;\n const capabilities = [...new Set([...(options.capabilities ?? []), ...(effects === 'none' || direct ? [] : [`effect:${effects}`])])];\n const timeoutMs = options.timeoutMs ?? (limits.maxDurationMs ?? 60_000) + 15_000;\n const name = built ? options.id : agent.id;\n return defineTool({\n id: options.id,\n version: options.version ?? (built ? '1' : agent.version),\n description: options.description ?? `Run the ${name} agent as one workflow step.`,\n input: (options.input ?? (agent as AgentDefinition).input) as Schema,\n output: (options.output ?? (agent as AgentDefinition).output) as Schema,\n // The step itself only runs the agent: its effects are the agent's, recorded by the agent's own runtime and\n // required as the `effect:<kind>` grant.\n effects: direct ? effects : 'none', capabilities, costMicros: ceiling, timeoutMs,\n execute: async (input, context) => {\n const refuse = (stage: string): never => { throw new ToolRefusal(`The agent step \"${options.id}\" ${stage}.`); };\n // Until the agent starts, nothing has run or been spent: a failure here is a refusal, charged nothing.\n let definition: AgentDefinition | undefined; let agentInput: unknown; let agentMedia: readonly Media[] = [];\n try {\n definition = built ? agent(input, context) : agent;\n assertAgent(definition);\n if (rank[effectsOf(definition.tools)] > rank[effects]) definition = undefined;\n else {\n agentInput = options.prepare ? await options.prepare(input, context) : input;\n if (options.media) agentMedia = await options.media(input, context);\n }\n } catch { definition = undefined; }\n if (!definition) return refuse('could not prepare its agent');\n const runtime = createRuntime({ profile: 'ephemeral', scope: context.scope, permissions, limits });\n let run: RunHandle<unknown> | undefined; let reported = false;\n const spent = (): number => {\n if (!run) return 0;\n const value = runtime.inspect(run).budget.spentMicros;\n // An overrun beyond safe integers, or beyond the ceiling, is charged the ceiling: the most the step may cost.\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? Math.min(value, ceiling) : ceiling;\n };\n const report = (knownCostMicros: number, unknownCostMicros: number): void => {\n if (reported) return; reported = true; context.reportUsage({ knownCostMicros, unknownCostMicros });\n };\n // Charge the whole ceiling: what the agent spent so far as known, the rest as unknown. Reported unknown cost is\n // what makes the step's outcome unknown.\n const uncertain = (): void => { const known = Math.min(spent(), ceiling - 1); report(known, ceiling - known); };\n /** A known failure: charged what the agent spent. */\n const fail = (stage: string): never => {\n if (direct) return refuse(stage);\n report(spent(), 0); throw new MayuraError('TOOL_FAILED', `The agent step \"${options.id}\" ${stage}.`);\n };\n const interrupt = (): void => {\n // Runs synchronously while the step is being cancelled or timed out, before the step's outcome is decided.\n if (acting && !direct && run) { try { uncertain(); } catch { /* The outcome is then decided without it. */ } }\n run?.cancel();\n };\n context.signal.addEventListener('abort', interrupt, { once: true });\n try {\n if (context.signal.aborted) return refuse('was cancelled before its agent started');\n let current: RunHandle<unknown>;\n try { current = runtime.submit(definition, { input: agentInput as never, ...(agentMedia.length > 0 ? { media: agentMedia } : {}) }); }\n catch { return refuse('could not start its agent'); }\n run = current;\n let finished: (() => void | Promise<void>) | void = undefined;\n try { finished = options.onRun?.(current, context); } catch { /* Observers never fail the step. */ }\n let outcome;\n try { outcome = await current.result(); }\n finally { try { if (typeof finished === 'function') await finished(); } catch { /* Observers never fail the step. */ } }\n if (outcome.status === 'outcome_unknown') {\n if (direct) throw new MayuraError('OUTCOME_UNKNOWN', `The agent step \"${options.id}\" has an unknown outcome.`);\n // Returning (rather than throwing) with unknown cost reported is how a tool says its outcome is unknown.\n if (ceiling > 0) { uncertain(); return undefined; }\n }\n if (outcome.status !== 'succeeded') return fail(`ended ${outcome.status}`);\n let output: unknown;\n try { output = options.finish ? await options.finish(outcome.output, input, context) : outcome.output; }\n catch { return fail('refused its agent\\'s output'); }\n report(spent(), 0); return output;\n } finally {\n context.signal.removeEventListener('abort', interrupt);\n await runtime.close();\n }\n },\n }) as AnyTool;\n}\n"]}
|
|
@@ -23,7 +23,7 @@ catch {
|
|
|
23
23
|
function outputs(record) { const state = workflowTreeState(record); return Object.fromEntries(Object.entries(state.steps).filter(([, step]) => step.status === 'succeeded').map(([id, step]) => [id, step.output])); }
|
|
24
24
|
function publicSnapshot(value) { const state = workflowTreeState(value.record); return freezeJson(jsonValue({ id: value.rootId, version: value.record.version, status: state.status, steps: state.steps, output: state.output, budget: value.budget })); }
|
|
25
25
|
function publicChild(record) { const state = workflowTreeState(record); return freezeJson(jsonValue({ id: record.id, version: record.version, status: state.status, steps: state.steps, output: state.output })); }
|
|
26
|
-
function storageFailure(error) { if (error instanceof StorageError && ['CONFLICT', 'NOT_FOUND', 'STALE_CLAIM', 'LIMIT_EXCEEDED'].includes(error.
|
|
26
|
+
function storageFailure(error) { if (error instanceof StorageError && ['CONFLICT', 'NOT_FOUND', 'STALE_CLAIM', 'LIMIT_EXCEEDED'].includes(error.storageCode))
|
|
27
27
|
throw error; throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow-tree storage is unavailable; reconcile uncertain actions before retrying.'); }
|
|
28
28
|
/** Finite format-4 driver for root-local tools and one-level required children. */
|
|
29
29
|
export function createWorkflowTreeRuntime(options) {
|
|
@@ -101,7 +101,7 @@ export function createWorkflowTreeRuntime(options) {
|
|
|
101
101
|
await call(() => api.prepareRootTool({ ...base, expectedVersion: record.version, input: raw }));
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
104
|
-
if (error instanceof StorageError && error.
|
|
104
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT') {
|
|
105
105
|
capacity.logical();
|
|
106
106
|
return undefined;
|
|
107
107
|
}
|
|
@@ -139,7 +139,7 @@ export function createWorkflowTreeRuntime(options) {
|
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
141
|
catch (error) {
|
|
142
|
-
if (!(error instanceof StorageError && error.
|
|
142
|
+
if (!(error instanceof StorageError && error.storageCode === 'CONFLICT'))
|
|
143
143
|
throw error;
|
|
144
144
|
}
|
|
145
145
|
} throw new MayuraError('CONFLICT', 'Root start contention exceeded its bounded retry limit.'); }, onExecutionReceipt: async (receipt) => { const withheld = Object.freeze({ ...receipt, disclosure: 'withheld' }); const currentEvidence = receiptId(claimed.job.jobId, claimed.claim.fence, withheld); evidenceId = currentEvidence; await call(() => api.recordRootToolReceipt({ ...base, fence: claimed.claim.fence, evidenceId: currentEvidence, receipt: withheld })); } });
|
|
@@ -182,7 +182,7 @@ export function createWorkflowTreeRuntime(options) {
|
|
|
182
182
|
await call(() => api.prepareChildTool({ ...base, expectedVersion: record.version, input: raw }));
|
|
183
183
|
}
|
|
184
184
|
catch (error) {
|
|
185
|
-
if (error instanceof StorageError && error.
|
|
185
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT') {
|
|
186
186
|
capacity.logical();
|
|
187
187
|
return undefined;
|
|
188
188
|
}
|
|
@@ -220,7 +220,7 @@ export function createWorkflowTreeRuntime(options) {
|
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
catch (error) {
|
|
223
|
-
if (!(error instanceof StorageError && error.
|
|
223
|
+
if (!(error instanceof StorageError && error.storageCode === 'CONFLICT'))
|
|
224
224
|
throw error;
|
|
225
225
|
}
|
|
226
226
|
} throw new MayuraError('CONFLICT', 'Child start contention exceeded its bounded retry limit.'); }, onExecutionReceipt: async (receipt) => { const withheld = Object.freeze({ ...receipt, disclosure: 'withheld' }); const currentEvidence = receiptId(claimed.job.jobId, claimed.claim.fence, withheld); evidenceId = currentEvidence; await call(() => api.recordChildToolReceipt({ ...base, fence: claimed.claim.fence, evidenceId: currentEvidence, receipt: withheld })); } });
|
|
@@ -469,7 +469,7 @@ export function createWorkflowTreeRuntime(options) {
|
|
|
469
469
|
runUntilSettled(definition, id) { open(); if (gate.draining)
|
|
470
470
|
return Promise.reject(new MayuraError('CANCELLED', 'Workflow-tree runtime is draining.')); supported(definition); access(id); const existing = runs.get(id); if (existing)
|
|
471
471
|
return existing.definition === definition ? existing.operation : Promise.reject(new MayuraError('CONFLICT', 'The active driver uses a different workflow-tree definition.')); if (runs.size >= maxConcurrentRuns)
|
|
472
|
-
return Promise.reject(new MayuraError('LIMIT_EXCEEDED', 'This workflow-tree worker has reached its active-run limit.')); const operation = drive(definition, id).catch(async (error) => { if (error instanceof StorageError && error.
|
|
472
|
+
return Promise.reject(new MayuraError('LIMIT_EXCEEDED', 'This workflow-tree worker has reached its active-run limit.')); const operation = drive(definition, id).catch(async (error) => { if (error instanceof StorageError && error.storageCode === 'CONFLICT') {
|
|
473
473
|
const current = await inspectStored(id);
|
|
474
474
|
if (workflowTreeState(current.record).status === 'paused')
|
|
475
475
|
return publicSnapshot(current);
|
|
@@ -519,7 +519,7 @@ export function createWorkflowTreeRuntime(options) {
|
|
|
519
519
|
return publicSnapshot(await call(() => controls.pauseRoot({ ...access(id), expectedVersion: root.record.version })));
|
|
520
520
|
}
|
|
521
521
|
catch (error) {
|
|
522
|
-
if (!(error instanceof StorageError && error.
|
|
522
|
+
if (!(error instanceof StorageError && error.storageCode === 'CONFLICT'))
|
|
523
523
|
throw error;
|
|
524
524
|
if ((await inspectStored(id)).record.version === root.record.version)
|
|
525
525
|
throw new MayuraError('CONFLICT', 'A workflow tree with a claimed or in-flight effect cannot enter the quiescent paused state.');
|
|
@@ -538,7 +538,7 @@ export function createWorkflowTreeRuntime(options) {
|
|
|
538
538
|
return publicSnapshot(await call(() => controls.resumeRoot({ ...access(id), expectedVersion: root.record.version })));
|
|
539
539
|
}
|
|
540
540
|
catch (error) {
|
|
541
|
-
if (!(error instanceof StorageError && error.
|
|
541
|
+
if (!(error instanceof StorageError && error.storageCode === 'CONFLICT'))
|
|
542
542
|
throw error;
|
|
543
543
|
}
|
|
544
544
|
}
|