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
|
@@ -5,6 +5,7 @@ import { createWorkflowCompositeFleetRuntime, type WorkflowCompositeCursor, type
|
|
|
5
5
|
type WorkflowCompositeFleetRuntime, type WorkflowCompositeOutcome } from './composite-fleet.js';
|
|
6
6
|
import { assertWorkflowLoop, type AnyWorkflowLoop } from './loop-definition.js';
|
|
7
7
|
import { assertWorkflowSaga, type AnyWorkflowSaga } from './saga-definition.js';
|
|
8
|
+
import { createSweepPosition } from './sweep-position.js';
|
|
8
9
|
|
|
9
10
|
export interface WorkflowCompositeHostOptions extends WorkflowCompositeFleetOptions {
|
|
10
11
|
readonly sagaDefinitions?: readonly AnyWorkflowSaga[]; readonly loopDefinitions?: readonly AnyWorkflowLoop[];
|
|
@@ -41,14 +42,31 @@ export function createWorkflowCompositeHost(options: WorkflowCompositeHostOption
|
|
|
41
42
|
if (backoffMaximum < interval) throw new MayuraError('INVALID_CONFIG', 'maxBackoffMs must be at least intervalMs.');
|
|
42
43
|
const hold = options.hold; if (hold !== undefined && typeof hold?.isHeld !== 'function') throw new MayuraError('INVALID_CONFIG', 'A fleet hold reader requires isHeld().');
|
|
43
44
|
const runtime = createWorkflowCompositeFleetRuntime(options); let cursor: WorkflowCompositeCursor | null = null; let closed = false;
|
|
45
|
+
// The sweep continues where the last process left it, rather than starting over (see sweep-position.ts).
|
|
46
|
+
const position = createSweepPosition<WorkflowCompositeCursor>(options.store, { kind: 'composite', scope: options.scope,
|
|
47
|
+
catalog: [...sagas, ...loops].map(definition => definition.digest) });
|
|
44
48
|
let cycles = 0; let failures = 0; let lastError: ErrorCode | null = null; let lastCycle: WorkflowCompositeHostCycle | null = null;
|
|
45
49
|
let controller: AbortController | undefined; let loop: Promise<void> | undefined; let active: Promise<WorkflowCompositeHostCycle> | undefined;
|
|
46
50
|
const runOnce = (): Promise<WorkflowCompositeHostCycle> => { if (closed) return Promise.reject(new MayuraError('CANCELLED', 'Composite host is closed.')); if (active) return active;
|
|
47
51
|
const operation = (async () => { let pages = 0; let examined = 0; let shardReads = 0; const outcomes: WorkflowCompositeOutcome[] = [];
|
|
48
52
|
const held = hold ? await hold.isHeld() === true : false;
|
|
49
|
-
if (!held)
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
if (!held) {
|
|
54
|
+
const stored = await position.load(); let restored = false;
|
|
55
|
+
if (stored !== null && cursor === null) { cursor = stored; restored = true; }
|
|
56
|
+
do {
|
|
57
|
+
const page = (from: WorkflowCompositeCursor | null) => runtime.runPage({ sagas, loops }, { cursor: from, limit, maxShardReads: reads });
|
|
58
|
+
let report: Awaited<ReturnType<typeof page>>;
|
|
59
|
+
try { report = await page(cursor); } catch (error) {
|
|
60
|
+
// A stored position this host cannot use restarts the sweep instead of failing every cycle.
|
|
61
|
+
if (!restored || !(error instanceof MayuraError) || error.code !== 'INVALID_INPUT') throw error;
|
|
62
|
+
cursor = null; report = await page(cursor);
|
|
63
|
+
}
|
|
64
|
+
restored = false; pages += 1;
|
|
65
|
+
examined += report.page.examined; shardReads += report.page.shardReads; outcomes.push(...report.outcomes); cursor = report.page.nextCursor;
|
|
66
|
+
} while (cursor && pages < pageMaximum);
|
|
67
|
+
await position.save(cursor);
|
|
68
|
+
}
|
|
69
|
+
const completedSweep = !held && cursor === null;
|
|
52
70
|
const result = freezeJson(jsonValue({ pages, examined, shardReads, outcomes, completedSweep, held })) as unknown as WorkflowCompositeHostCycle;
|
|
53
71
|
cycles += 1; failures = 0; lastError = null; lastCycle = result; return result; })();
|
|
54
72
|
active = operation; void operation.finally(() => { if (active === operation) active = undefined; }).catch(() => {}); return operation; };
|
|
@@ -99,7 +99,7 @@ export function createWorkflowHookRelay(options: WorkflowHookRelayOptions): Work
|
|
|
99
99
|
const cursorId = (runId: string): string => digest('mayura:workflow-hook-relay:v1', { relayId, runId });
|
|
100
100
|
const guarded = async <T>(operation: () => Promise<T>): Promise<T> => {
|
|
101
101
|
try { return await operation(); }
|
|
102
|
-
catch (error) { if (error instanceof MayuraError || (error instanceof StorageError && error.
|
|
102
|
+
catch (error) { if (error instanceof MayuraError || (error instanceof StorageError && error.storageCode === 'CONFLICT')) throw error;
|
|
103
103
|
throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow hook relay storage is unavailable.'); }
|
|
104
104
|
};
|
|
105
105
|
const read = async (runId: string): Promise<{ record?: StoredRecord; sequence: number }> => {
|
|
@@ -122,7 +122,7 @@ export function createWorkflowHookRelay(options: WorkflowHookRelayOptions): Work
|
|
|
122
122
|
definitionHash: digest('mayura:workflow-hook-relay-format:v1', {}), state, events: [event] }))).record;
|
|
123
123
|
return { record, sequence };
|
|
124
124
|
} catch (error) {
|
|
125
|
-
if (!(error instanceof StorageError && error.
|
|
125
|
+
if (!(error instanceof StorageError && error.storageCode === 'CONFLICT')) throw error;
|
|
126
126
|
const latest = await read(runId);
|
|
127
127
|
return latest.sequence >= sequence ? latest : advance(runId, latest, sequence);
|
|
128
128
|
}
|
|
@@ -10,7 +10,8 @@ export { createWorkflowFleetControl, compositeFleetTarget, graphFleetTarget, lif
|
|
|
10
10
|
type WorkflowFleetControlOptions, type WorkflowFleetHoldReader, type WorkflowFleetHoldState, type WorkflowFleetSweepCursor,
|
|
11
11
|
type WorkflowFleetSweepOutcome, type WorkflowFleetSweepReport, type WorkflowFleetTarget } from './fleet-control.js';
|
|
12
12
|
export { createWorkflowLeadership, type WorkflowLeadership, type WorkflowLeadershipOptions, type WorkflowLeadershipState } from './leadership.js';
|
|
13
|
-
export { coordinatorUnit, createWorkflowWorker, type WorkflowWorker, type
|
|
13
|
+
export { coordinatorUnit, createWorkflowWorker, type WorkflowWorker, type WorkflowWorkerOnceOptions, type WorkflowWorkerOnceReport,
|
|
14
|
+
type WorkflowWorkerOptions, type WorkflowWorkerStatus,
|
|
14
15
|
type WorkflowWorkerUnit } from './worker.js';
|
|
15
16
|
export { createWorkflowHookRelay, workflowHookStages, type WorkflowHookRelay, type WorkflowHookRelayOptions, type WorkflowHookDelivery, type WorkflowHookEvent, type WorkflowHookStage, type WorkflowHooks, type WorkflowEventSource } from './hook-relay.js';
|
|
16
17
|
export { inventoryWorkflowVersions, assertWorkflowVersionsRetained, compositeVersionTarget, type WorkflowVersionInventory, type WorkflowVersionInventoryOptions, type WorkflowVersionEntry, type WorkflowVersionTarget } from './versions.js';
|
|
@@ -61,7 +61,7 @@ export function createWorkflowLeadership(options: WorkflowLeadershipOptions): Wo
|
|
|
61
61
|
})) as unknown as WorkflowLeadershipState;
|
|
62
62
|
const guarded = async <T>(operation: () => Promise<T>): Promise<T> => {
|
|
63
63
|
try { return await operation(); }
|
|
64
|
-
catch (error) { if (error instanceof MayuraError || (error instanceof StorageError && error.
|
|
64
|
+
catch (error) { if (error instanceof MayuraError || (error instanceof StorageError && error.storageCode === 'CONFLICT')) throw error;
|
|
65
65
|
throw new MayuraError('STORAGE_UNAVAILABLE', 'Leadership storage is unavailable.'); }
|
|
66
66
|
};
|
|
67
67
|
return Object.freeze<WorkflowLeadership>({
|
|
@@ -81,7 +81,7 @@ export function createWorkflowLeadership(options: WorkflowLeadershipOptions): Wo
|
|
|
81
81
|
} else await store.update({ scope, id, expectedVersion: record.version, state: jsonValue(next) as JsonObject, events: [event] });
|
|
82
82
|
confirmed = { fence: next.fence, expiresAtMs: next.expiresAtMs }; return publicState(next, true);
|
|
83
83
|
} catch (error) {
|
|
84
|
-
if (error instanceof StorageError && error.
|
|
84
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT') continue;
|
|
85
85
|
confirmed = null; throw new MayuraError('STORAGE_UNAVAILABLE', 'Leadership lease update could not be confirmed.');
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -94,7 +94,7 @@ export function createWorkflowLeadership(options: WorkflowLeadershipOptions): Wo
|
|
|
94
94
|
if (!record || !lease || lease.holderId !== holderId || lease.fence !== held.fence) return;
|
|
95
95
|
try { await store.update({ scope, id, expectedVersion: record.version, state: jsonValue({ ...lease, expiresAtMs: 0 }) as JsonObject,
|
|
96
96
|
events: [{ type: 'leadership.released', data: { fence: lease.fence } }] }); return; }
|
|
97
|
-
catch (error) { if (!(error instanceof StorageError && error.
|
|
97
|
+
catch (error) { if (!(error instanceof StorageError && error.storageCode === 'CONFLICT')) throw new MayuraError('STORAGE_UNAVAILABLE', 'Leadership release could not be confirmed.'); }
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
100
|
isLeader: () => confirmed !== null && now() < confirmed.expiresAtMs - Math.floor(leaseMs / 3),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertSchema, MayuraError, type InferInput, type InferOutput, type Schema } from '@mayura/core';
|
|
2
|
-
import { workflowLifecycleManifest, type WorkflowLifecycleHumanKind, type WorkflowLifecycleManifest } from '@mayura/storage-contracts';
|
|
2
|
+
import { schemaDigest, workflowLifecycleManifest, type WorkflowLifecycleHumanKind, type WorkflowLifecycleManifest } from '@mayura/storage-contracts';
|
|
3
3
|
import { assertTool, type AnyTool } from '@mayura/tools';
|
|
4
4
|
import { digest, type Binding, type WorkflowNode } from './definition.js';
|
|
5
5
|
|
|
@@ -10,7 +10,11 @@ export interface WorkflowLifecycleHumanNode<S extends Schema = Schema> {
|
|
|
10
10
|
readonly request: {
|
|
11
11
|
readonly kind: WorkflowLifecycleHumanKind;
|
|
12
12
|
readonly schemaId: string;
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* 64-hex SHA-256 of the response contract. Omit it to derive it from `response` when that validator can describe
|
|
15
|
+
* itself as JSON Schema (Zod 4.2 and later can); see `schemaDigest`.
|
|
16
|
+
*/
|
|
17
|
+
readonly schemaDigest?: string;
|
|
14
18
|
readonly prompt: string;
|
|
15
19
|
readonly response: S;
|
|
16
20
|
readonly context?: Binding;
|
|
@@ -28,13 +32,33 @@ export interface WorkflowLifecycleTimerNode {
|
|
|
28
32
|
readonly when?: Binding;
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Waits, without holding a worker, for one signal delivered from outside the run: from code with the runtime's
|
|
37
|
+
* `signal`, or over the operator API (`client.signalWorkflow`, `mayura workflow-signal`). The payload is validated
|
|
38
|
+
* with `payload` and becomes the step's output, which later steps bind to like any step output. Delivery is
|
|
39
|
+
* idempotent on the signal id. A signal that arrives before the step starts is kept and completes the step when it
|
|
40
|
+
* starts. With `deadlineAtMs`, a step that has no signal by then is `timed_out`, and the run fails.
|
|
41
|
+
*/
|
|
42
|
+
export interface WorkflowLifecycleSignalNode<S extends Schema = Schema> {
|
|
43
|
+
readonly kind: 'signal';
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly dependsOn?: readonly string[];
|
|
46
|
+
/** The name senders address, unique among the definition's signal nodes. Default: the node id. */
|
|
47
|
+
readonly name?: string;
|
|
48
|
+
readonly payload: S;
|
|
49
|
+
/** Binding to an absolute Unix epoch millisecond deadline. */
|
|
50
|
+
readonly deadlineAtMs?: Binding;
|
|
51
|
+
readonly when?: Binding;
|
|
52
|
+
}
|
|
53
|
+
|
|
31
54
|
/**
|
|
32
55
|
* A lifecycle node. Any node may declare `when`, a binding over the input or a dependency's output: the node runs
|
|
33
56
|
* only when it resolves to a value other than `null` or `false` (a path that does not resolve counts as `null`).
|
|
34
57
|
* Otherwise the step is `bypassed`: it is never admitted, reserves and costs nothing, and dependents see its output
|
|
35
58
|
* as `null`. A `step` binding must name one of the node's dependencies.
|
|
36
59
|
*/
|
|
37
|
-
export type WorkflowLifecycleNode = (WorkflowNode & { readonly when?: Binding }) | WorkflowLifecycleHumanNode | WorkflowLifecycleTimerNode
|
|
60
|
+
export type WorkflowLifecycleNode = (WorkflowNode & { readonly when?: Binding }) | WorkflowLifecycleHumanNode | WorkflowLifecycleTimerNode
|
|
61
|
+
| WorkflowLifecycleSignalNode;
|
|
38
62
|
|
|
39
63
|
export interface WorkflowLifecycleOptions<I extends Schema, O extends Schema> {
|
|
40
64
|
readonly id: string;
|
|
@@ -76,7 +100,16 @@ export function assertWorkflowLifecycle(definition: AnyWorkflowLifecycle): void
|
|
|
76
100
|
if (!definitions.has(definition)) throw new MayuraError('INVALID_CONFIG', 'Use defineWorkflowLifecycle from this package instance.');
|
|
77
101
|
}
|
|
78
102
|
|
|
79
|
-
/**
|
|
103
|
+
/** The schema digest of a human node that does not give one, derived from its response validator. */
|
|
104
|
+
function derivedDigest(node: WorkflowLifecycleHumanNode): string {
|
|
105
|
+
try { return schemaDigest(node.request.response); }
|
|
106
|
+
catch {
|
|
107
|
+
throw new MayuraError('INVALID_CONFIG', `Human step "${node.id}" has no schemaDigest, and its response validator cannot describe itself as JSON Schema. `
|
|
108
|
+
+ 'Give request.schemaDigest (64 hex characters), for example schemaDigest(jsonSchemaOfYourResponse).');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Build the strict data-only format-5 material; response and payload validators are never persisted. */
|
|
80
113
|
export function lifecycleManifest(
|
|
81
114
|
definition: Pick<AnyWorkflowLifecycle, 'id' | 'version' | 'nodes' | 'result'>,
|
|
82
115
|
): WorkflowLifecycleManifest {
|
|
@@ -95,9 +128,11 @@ export function lifecycleManifest(
|
|
|
95
128
|
};
|
|
96
129
|
if (node.kind === 'join') return { kind: node.kind, id: node.id, dependsOn: node.dependsOn, ...when };
|
|
97
130
|
if (node.kind === 'timer') return { kind: node.kind, id: node.id, dependsOn: node.dependsOn ?? [], fireAtMs: node.fireAtMs, ...when };
|
|
131
|
+
if (node.kind === 'signal') return { kind: node.kind, id: node.id, dependsOn: node.dependsOn ?? [], name: node.name ?? node.id,
|
|
132
|
+
deadlineAtMs: node.deadlineAtMs ?? null, ...when };
|
|
98
133
|
if (node.kind === 'human') return {
|
|
99
134
|
kind: node.kind, id: node.id, dependsOn: node.dependsOn ?? [], requestKind: node.request.kind,
|
|
100
|
-
schemaId: node.request.schemaId, schemaDigest: node.request.schemaDigest, prompt: node.request.prompt,
|
|
135
|
+
schemaId: node.request.schemaId, schemaDigest: node.request.schemaDigest ?? derivedDigest(node), prompt: node.request.prompt,
|
|
101
136
|
context: node.request.context ?? null, subjectDigest: node.request.subjectDigest ?? null,
|
|
102
137
|
deadlineAtMs: node.request.deadlineAtMs ?? null, ...when,
|
|
103
138
|
};
|
|
@@ -105,12 +140,13 @@ export function lifecycleManifest(
|
|
|
105
140
|
}),
|
|
106
141
|
result: definition.result,
|
|
107
142
|
});
|
|
108
|
-
} catch {
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (error instanceof MayuraError && error.code === 'INVALID_CONFIG') throw error;
|
|
109
145
|
throw new MayuraError('INVALID_CONFIG', 'Workflow lifecycle metadata is invalid or exceeds its finite bounds.');
|
|
110
146
|
}
|
|
111
147
|
}
|
|
112
148
|
|
|
113
|
-
/** Define an acyclic format-5 graph with explicit human and
|
|
149
|
+
/** Define an acyclic format-5 graph with explicit human, timer and signal suspension nodes. */
|
|
114
150
|
export function defineWorkflowLifecycle<I extends Schema, O extends Schema>(
|
|
115
151
|
options: WorkflowLifecycleOptions<I, O>,
|
|
116
152
|
): WorkflowLifecycleDefinition<I, O> {
|
|
@@ -119,13 +155,14 @@ export function defineWorkflowLifecycle<I extends Schema, O extends Schema>(
|
|
|
119
155
|
}
|
|
120
156
|
assertSchema(options.input); assertSchema(options.output);
|
|
121
157
|
const tools = new Map<string, Extract<WorkflowLifecycleNode, { readonly kind: 'tool' }>['tool']>();
|
|
122
|
-
const responses = new Map<string, Schema>();
|
|
158
|
+
const responses = new Map<string, Schema>(); const payloads = new Map<string, Schema>();
|
|
123
159
|
for (const node of options.nodes) {
|
|
124
|
-
if (!node || !['tool', 'join', 'human', 'timer'].includes(node.kind)) {
|
|
160
|
+
if (!node || !['tool', 'join', 'human', 'timer', 'signal'].includes(node.kind)) {
|
|
125
161
|
throw new MayuraError('INVALID_CONFIG', 'Unknown workflow lifecycle node kind.');
|
|
126
162
|
}
|
|
127
163
|
if (node.kind === 'tool') { assertTool(node.tool); tools.set(node.id, node.tool); }
|
|
128
164
|
if (node.kind === 'human') { assertSchema(node.request.response); responses.set(node.id, snapshot(node.request.response)); }
|
|
165
|
+
if (node.kind === 'signal') { assertSchema(node.payload); payloads.set(node.id, snapshot(node.payload)); }
|
|
129
166
|
}
|
|
130
167
|
const manifest = lifecycleManifest(options);
|
|
131
168
|
const nodes = Object.freeze(manifest.graph.map(node => {
|
|
@@ -138,6 +175,10 @@ export function defineWorkflowLifecycle<I extends Schema, O extends Schema>(
|
|
|
138
175
|
if (node.kind === 'timer') return Object.freeze({
|
|
139
176
|
kind: node.kind, id: node.id, dependsOn: node.dependsOn, fireAtMs: node.fireAtMs, ...when,
|
|
140
177
|
});
|
|
178
|
+
if (node.kind === 'signal') return Object.freeze({
|
|
179
|
+
kind: node.kind, id: node.id, dependsOn: node.dependsOn, name: node.name, payload: payloads.get(node.id)!,
|
|
180
|
+
...(node.deadlineAtMs === null ? {} : { deadlineAtMs: node.deadlineAtMs }), ...when,
|
|
181
|
+
});
|
|
141
182
|
return Object.freeze({
|
|
142
183
|
kind: node.kind, id: node.id, dependsOn: node.dependsOn, ...when,
|
|
143
184
|
request: Object.freeze({
|
|
@@ -129,13 +129,9 @@ function stateFrom(record: StoredRecord, scope: string, shard: string, maximum:
|
|
|
129
129
|
return { format: 1, shard, entries };
|
|
130
130
|
} catch { throw new MayuraError('CONFLICT', 'Lifecycle fleet index failed integrity validation.'); }
|
|
131
131
|
}
|
|
132
|
+
/** Storage failures are MayuraErrors too (a full queue arrives as LIMIT_EXCEEDED); anything else is unavailable storage. */
|
|
132
133
|
function failure(error: unknown): ErrorCode {
|
|
133
|
-
|
|
134
|
-
if (error instanceof StorageError) {
|
|
135
|
-
if (error.code === 'QUEUE_FULL' || error.code === 'LIMIT_EXCEEDED') return 'LIMIT_EXCEEDED';
|
|
136
|
-
if (['INVALID_INPUT', 'CONFLICT', 'NOT_FOUND'].includes(error.code)) return error.code as 'INVALID_INPUT' | 'CONFLICT' | 'NOT_FOUND';
|
|
137
|
-
}
|
|
138
|
-
return 'STORAGE_UNAVAILABLE';
|
|
134
|
+
return error instanceof MayuraError ? error.code : 'STORAGE_UNAVAILABLE';
|
|
139
135
|
}
|
|
140
136
|
|
|
141
137
|
/** Durable sharded discovery over the base aggregate contract; the caller still owns storage lifecycle and scheduling. */
|
|
@@ -207,7 +203,7 @@ export function createWorkflowLifecycleFleetRuntime(options: WorkflowLifecycleFl
|
|
|
207
203
|
state: jsonValue(current.state) as JsonObject, events: [{ type: terminal.has(snapshot.status) ? 'lifecycle-index.removed' : 'lifecycle-index.updated',
|
|
208
204
|
data: { runId: snapshot.id, version: snapshot.version, status: snapshot.status } }] }); return;
|
|
209
205
|
} catch (error) {
|
|
210
|
-
if (error instanceof StorageError && error.
|
|
206
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT') continue;
|
|
211
207
|
throw new MayuraError('STORAGE_UNAVAILABLE', 'Lifecycle fleet index update could not be confirmed.');
|
|
212
208
|
}
|
|
213
209
|
}
|
|
@@ -240,7 +236,7 @@ export function createWorkflowLifecycleFleetRuntime(options: WorkflowLifecycleFl
|
|
|
240
236
|
await store.update({ scope, id: current.record.id, expectedVersion: current.record.version, state: jsonValue({ format: 1, shard, entries: retained }) as JsonObject,
|
|
241
237
|
events: [{ type: 'lifecycle-settled.recorded', data: { runId: snapshot.id, status: snapshot.status } }] }); return;
|
|
242
238
|
} catch (error) {
|
|
243
|
-
if (error instanceof StorageError && error.
|
|
239
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT') continue;
|
|
244
240
|
throw new MayuraError('STORAGE_UNAVAILABLE', 'Lifecycle settled index update could not be confirmed.');
|
|
245
241
|
}
|
|
246
242
|
}
|
|
@@ -317,6 +313,9 @@ export function createWorkflowLifecycleFleetRuntime(options: WorkflowLifecycleFl
|
|
|
317
313
|
respondVerified: async (definition: AnyWorkflowLifecycle, command: Parameters<WorkflowLifecycleRuntime['respondVerified']>[1]) => {
|
|
318
314
|
const snapshot = await runtime.respondVerified(definition, command); await write(snapshot, definition.digest); return snapshot;
|
|
319
315
|
},
|
|
316
|
+
signal: async (definition: AnyWorkflowLifecycle, command: Parameters<WorkflowLifecycleRuntime['signal']>[1]) => {
|
|
317
|
+
const snapshot = await runtime.signal(definition, command); await write(snapshot, definition.digest); return snapshot;
|
|
318
|
+
},
|
|
320
319
|
pause: async (id: string) => { const snapshot = await runtime.pause(id); await write(snapshot); return snapshot; },
|
|
321
320
|
resume: async (id: string) => { const snapshot = await runtime.resume(id); await write(snapshot); return snapshot; },
|
|
322
321
|
cancel: async (id: string) => { const snapshot = await runtime.cancel(id); await write(snapshot); return snapshot; },
|
|
@@ -2,6 +2,7 @@ import { freezeJson, jsonValue, MayuraError, type ErrorCode } from '@mayura/core
|
|
|
2
2
|
import type { WorkflowFleetHoldReader } from './fleet-control.js';
|
|
3
3
|
import type { WorkflowDrainOptions, WorkflowDrainReport } from './drain.js';
|
|
4
4
|
import { assertWorkflowLifecycle, type AnyWorkflowLifecycle } from './lifecycle-definition.js';
|
|
5
|
+
import { createSweepPosition } from './sweep-position.js';
|
|
5
6
|
import { createWorkflowLifecycleFleetRuntime, type WorkflowLifecycleFleetCursor,
|
|
6
7
|
type WorkflowLifecycleFleetOutcome, type WorkflowLifecycleFleetRuntime,
|
|
7
8
|
type WorkflowLifecycleFleetRuntimeOptions } from './lifecycle-fleet.js';
|
|
@@ -65,6 +66,9 @@ export function createWorkflowLifecycleHost(options: WorkflowLifecycleHostOption
|
|
|
65
66
|
if (maxBackoffMs < intervalMs) throw new MayuraError('INVALID_CONFIG', 'maxBackoffMs must be at least intervalMs.');
|
|
66
67
|
const hold = options.hold; if (hold !== undefined && typeof hold?.isHeld !== 'function') throw new MayuraError('INVALID_CONFIG', 'A fleet hold reader requires isHeld().');
|
|
67
68
|
const runtime = createWorkflowLifecycleFleetRuntime(options); let cursor: WorkflowLifecycleFleetCursor | null = null;
|
|
69
|
+
// The sweep continues where the last process left it, rather than starting over (see sweep-position.ts).
|
|
70
|
+
const position = createSweepPosition<WorkflowLifecycleFleetCursor>(options.store, { kind: 'lifecycle', scope: options.scope,
|
|
71
|
+
catalog: definitions.map(definition => definition.digest) });
|
|
68
72
|
let cycles = 0; let consecutiveFailures = 0; let lastError: ErrorCode | null = null;
|
|
69
73
|
let lastCycle: WorkflowLifecycleHostCycle | null = null; let controller: AbortController | undefined;
|
|
70
74
|
let loop: Promise<void> | undefined; let inFlight: Promise<WorkflowLifecycleHostCycle> | undefined; let closed = false;
|
|
@@ -75,11 +79,23 @@ export function createWorkflowLifecycleHost(options: WorkflowLifecycleHostOption
|
|
|
75
79
|
let pages = 0; let examined = 0; let shardReads = 0; const outcomes: WorkflowLifecycleFleetOutcome[] = [];
|
|
76
80
|
// Fail closed: a hold that cannot be confirmed fails the cycle instead of driving runs.
|
|
77
81
|
const held = hold ? await hold.isHeld() === true : false;
|
|
78
|
-
if (!held)
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
if (!held) {
|
|
83
|
+
const stored = await position.load(); let restored = false;
|
|
84
|
+
if (stored !== null && cursor === null) { cursor = stored; restored = true; }
|
|
85
|
+
do {
|
|
86
|
+
const page = (from: WorkflowLifecycleFleetCursor | null) => runtime.runPage(definitions, { cursor: from, limit: pageLimit, maxShardReads });
|
|
87
|
+
let report: Awaited<ReturnType<typeof page>>;
|
|
88
|
+
try { report = await page(cursor); } catch (error) {
|
|
89
|
+
// A stored position this host cannot use restarts the sweep instead of failing every cycle.
|
|
90
|
+
if (!restored || !(error instanceof MayuraError) || error.code !== 'INVALID_INPUT') throw error;
|
|
91
|
+
cursor = null; report = await page(cursor);
|
|
92
|
+
}
|
|
93
|
+
restored = false;
|
|
94
|
+
pages += 1; examined += report.page.examined; shardReads += report.page.shardReads; outcomes.push(...report.outcomes);
|
|
95
|
+
cursor = report.page.nextCursor;
|
|
96
|
+
} while (cursor && pages < maxPages);
|
|
97
|
+
await position.save(cursor);
|
|
98
|
+
}
|
|
83
99
|
const completedSweep = !held && cursor === null; if (completedSweep) cursor = null;
|
|
84
100
|
const result = freezeJson(jsonValue({ pages, examined, shardReads, outcomes, completedSweep, held })) as unknown as WorkflowLifecycleHostCycle;
|
|
85
101
|
cycles += 1; consecutiveFailures = 0; lastError = null; lastCycle = result; return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { freezeJson, jsonValue, MayuraError, type JsonValue, type Scope } from '@mayura/core';
|
|
2
2
|
import { digest } from './definition.js';
|
|
3
3
|
import { assertWorkflowLifecycle, type AnyWorkflowLifecycle } from './lifecycle-definition.js';
|
|
4
|
+
import type { WorkflowLifecycleFleetCandidate, WorkflowLifecycleFleetRuntime } from './lifecycle-fleet.js';
|
|
4
5
|
import type { WorkflowLifecycleHumanRequest, WorkflowLifecycleRuntime } from './lifecycle-runtime.js';
|
|
5
6
|
|
|
6
7
|
export interface WorkflowLifecycleHumanTransportRecord {
|
|
@@ -34,20 +35,37 @@ export interface WorkflowLifecycleHumanRegistration {
|
|
|
34
35
|
readonly runId: string;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/** A definition whose human requests a durable transport serves, and the agent whose callers may see and answer them. */
|
|
39
|
+
export interface WorkflowLifecycleHumanRoute {
|
|
40
|
+
readonly agentId: string;
|
|
41
|
+
readonly definition: AnyWorkflowLifecycle;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
export interface WorkflowLifecycleHumanTransportController {
|
|
38
45
|
/** Exact three-callback object accepted by @mayura/server. */
|
|
39
46
|
readonly transport: WorkflowLifecycleHumanTransport;
|
|
47
|
+
/** Registration mode only: serve one run's human requests. A durable transport finds them itself and refuses this. */
|
|
40
48
|
register(input: WorkflowLifecycleHumanRegistration): readonly string[];
|
|
41
49
|
unregister(runId: string): void;
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
export interface WorkflowLifecycleHumanTransportOptions {
|
|
45
53
|
readonly scope: Scope;
|
|
54
|
+
/**
|
|
55
|
+
* Durable discovery: the fleet runtime (or host runtime) whose index lists the active runs of `scope`. Pending
|
|
56
|
+
* requests are then found in storage: nothing is registered, and a restart loses nothing. Requires `definitions`.
|
|
57
|
+
*/
|
|
58
|
+
readonly runtime?: WorkflowLifecycleFleetRuntime;
|
|
59
|
+
/** With `runtime`: every definition version whose requests this transport serves (at most 128), each with its agent. */
|
|
60
|
+
readonly definitions?: readonly WorkflowLifecycleHumanRoute[];
|
|
61
|
+
/** Registration mode: the most registered requests (default 512). */
|
|
46
62
|
readonly maxEntries?: number;
|
|
63
|
+
/** The most requests one page reads (default 256). */
|
|
47
64
|
readonly maxExaminedPerPage?: number;
|
|
48
65
|
}
|
|
49
66
|
|
|
50
|
-
interface Entry
|
|
67
|
+
interface Entry { readonly id: string; readonly agentId: string; readonly definition: AnyWorkflowLifecycle; readonly runtime: WorkflowLifecycleRuntime;
|
|
68
|
+
readonly runId: string; readonly nodeId: string }
|
|
51
69
|
const identifier = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/;
|
|
52
70
|
const hashPattern = /^[a-f0-9]{64}$/;
|
|
53
71
|
|
|
@@ -56,8 +74,20 @@ function active(signal: AbortSignal): void {
|
|
|
56
74
|
}
|
|
57
75
|
|
|
58
76
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
77
|
+
* A request's opaque route id. It starts with its run's two-hex index shard, so a durable transport finds a request
|
|
78
|
+
* by reading one shard, and pages in id order shard by shard.
|
|
79
|
+
*/
|
|
80
|
+
function routeId(agentId: string, definitionHash: string, runId: string, nodeId: string): string {
|
|
81
|
+
return runId.slice(0, 2) + digest('mayura:workflow-lifecycle-human-route:v2', { agentId, definitionHash, runId, nodeId }).slice(2);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Serves format-5 human requests to the agent server's `humanRequests` transport (list, inspect, respond).
|
|
86
|
+
*
|
|
87
|
+
* With `runtime` and `definitions` it is durable: requests are discovered from the lifecycle fleet index, so they are
|
|
88
|
+
* listed, read and answered after a restart without registering anything. Without them, each run is registered with
|
|
89
|
+
* `register` and forgotten on restart. Either way, a caller sees a request only in the transport's exact scope and
|
|
90
|
+
* only when its identity lists the request's agent, and an answer is recorded as the verified caller's.
|
|
61
91
|
*/
|
|
62
92
|
export function createWorkflowLifecycleHumanTransport(
|
|
63
93
|
options: WorkflowLifecycleHumanTransportOptions,
|
|
@@ -69,7 +99,23 @@ export function createWorkflowLifecycleHumanTransport(
|
|
|
69
99
|
|| !Number.isSafeInteger(maxExaminedPerPage) || maxExaminedPerPage < 1 || maxExaminedPerPage > 1_024) {
|
|
70
100
|
throw new MayuraError('INVALID_CONFIG', 'Lifecycle human transport limits are invalid.');
|
|
71
101
|
}
|
|
72
|
-
const
|
|
102
|
+
const durable = options.runtime !== undefined || options.definitions !== undefined;
|
|
103
|
+
const routes = new Map<string, WorkflowLifecycleHumanRoute>();
|
|
104
|
+
if (durable) {
|
|
105
|
+
const runtime = options.runtime;
|
|
106
|
+
if (!runtime || runtime.profile !== 'lifecycle-v1' || typeof runtime.scan !== 'function' || !Array.isArray(options.definitions)
|
|
107
|
+
|| options.definitions.length < 1 || options.definitions.length > 128) {
|
|
108
|
+
throw new MayuraError('INVALID_CONFIG', 'A durable human transport needs the lifecycle fleet runtime and 1–128 definitions, each with its agentId.');
|
|
109
|
+
}
|
|
110
|
+
for (const route of options.definitions) {
|
|
111
|
+
assertWorkflowLifecycle(route?.definition);
|
|
112
|
+
if (typeof route.agentId !== 'string' || !identifier.test(route.agentId)) throw new MayuraError('INVALID_CONFIG', 'Each human transport definition needs a valid agentId.');
|
|
113
|
+
if (routes.has(route.definition.digest)) throw new MayuraError('INVALID_CONFIG', 'Human transport definitions must be unique.');
|
|
114
|
+
routes.set(route.definition.digest, Object.freeze({ agentId: route.agentId, definition: route.definition }));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const scopeKey = digest('mayura:scope:v1', scope);
|
|
118
|
+
const registered = new Map<string, Entry>();
|
|
73
119
|
const exactScope = (candidate: Scope): void => {
|
|
74
120
|
if (candidate?.principalId !== scope.principalId || candidate?.projectId !== scope.projectId) {
|
|
75
121
|
throw new MayuraError('PERMISSION_DENIED', 'Lifecycle human transport scope does not match.');
|
|
@@ -79,7 +125,6 @@ export function createWorkflowLifecycleHumanTransport(
|
|
|
79
125
|
if (!Array.isArray(agentIds) || agentIds.length > 256 || agentIds.some(id => !identifier.test(id))
|
|
80
126
|
|| new Set(agentIds).size !== agentIds.length) throw new MayuraError('INVALID_INPUT', 'Lifecycle human transport agent visibility is invalid.');
|
|
81
127
|
};
|
|
82
|
-
const visible = (entry: Entry, agentIds: readonly string[]): boolean => agentIds.includes(entry.agentId);
|
|
83
128
|
const record = (entry: Entry, request: WorkflowLifecycleHumanRequest): WorkflowLifecycleHumanTransportRecord =>
|
|
84
129
|
freezeJson(jsonValue({ id: entry.id, agentId: entry.agentId, kind: request.kind, schemaId: request.schemaId,
|
|
85
130
|
schemaDigest: request.schemaDigest, prompt: request.prompt, digest: request.digest,
|
|
@@ -97,6 +142,54 @@ export function createWorkflowLifecycleHumanTransport(
|
|
|
97
142
|
throw error;
|
|
98
143
|
}
|
|
99
144
|
};
|
|
145
|
+
/** The human requests of the active runs in one index shard, in route id order. */
|
|
146
|
+
const shardEntries = async (shard: number): Promise<Entry[]> => {
|
|
147
|
+
const runtime = options.runtime!; const candidates: WorkflowLifecycleFleetCandidate[] = []; let afterId = '';
|
|
148
|
+
for (let reads = 0; reads < 8; reads++) {
|
|
149
|
+
let page;
|
|
150
|
+
try { page = await runtime.scan({ cursor: { format: 1, scope: scopeKey, shard, afterId }, limit: 128, maxShardReads: 1 }); }
|
|
151
|
+
catch (error) {
|
|
152
|
+
// The fleet runtime refuses a cursor for another scope: the transport and runtime serve different scopes.
|
|
153
|
+
if (error instanceof MayuraError && error.code === 'INVALID_INPUT') throw new MayuraError('INVALID_CONFIG', 'The human transport and its lifecycle runtime serve different scopes.');
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
candidates.push(...page.candidates);
|
|
157
|
+
if (!page.nextCursor || page.nextCursor.shard !== shard) break;
|
|
158
|
+
afterId = page.nextCursor.afterId;
|
|
159
|
+
}
|
|
160
|
+
return candidates.flatMap(candidate => {
|
|
161
|
+
const route = routes.get(candidate.definitionHash); if (!route) return [];
|
|
162
|
+
return route.definition.nodes.filter(node => node.kind === 'human').map(node => Object.freeze({
|
|
163
|
+
id: routeId(route.agentId, candidate.definitionHash, candidate.runId, node.id), agentId: route.agentId, definition: route.definition,
|
|
164
|
+
runtime, runId: candidate.runId, nodeId: node.id }));
|
|
165
|
+
}).sort((left, right) => left.id.localeCompare(right.id));
|
|
166
|
+
};
|
|
167
|
+
const find = async (id: string): Promise<Entry | undefined> => durable
|
|
168
|
+
? (await shardEntries(Number.parseInt(id.slice(0, 2), 16))).find(entry => entry.id === id)
|
|
169
|
+
: registered.get(id);
|
|
170
|
+
const page = async (agentIds: readonly string[], after: string | null, limit: number, signal: AbortSignal): Promise<{ items: WorkflowLifecycleHumanTransportRecord[]; next: string | null }> => {
|
|
171
|
+
const items: WorkflowLifecycleHumanTransportRecord[] = []; let examined = 0; let cursor: string | null = null;
|
|
172
|
+
const visible = (entry: Entry): boolean => agentIds.includes(entry.agentId) && (after === null || entry.id > after);
|
|
173
|
+
if (!durable) {
|
|
174
|
+
const ordered = [...registered.values()].filter(visible).sort((left, right) => left.id.localeCompare(right.id));
|
|
175
|
+
for (const entry of ordered) {
|
|
176
|
+
if (items.length >= limit || examined >= maxExaminedPerPage) break;
|
|
177
|
+
active(signal); examined += 1; cursor = entry.id;
|
|
178
|
+
const item = await requestFor(entry); if (item) items.push(item);
|
|
179
|
+
}
|
|
180
|
+
return { items, next: cursor !== null && ordered.some(entry => entry.id > cursor!) ? cursor : null };
|
|
181
|
+
}
|
|
182
|
+
// Route ids start with their shard, so walking shards in order walks ids in order.
|
|
183
|
+
for (let shard = after === null ? 0 : Number.parseInt(after.slice(0, 2), 16); shard < 256; shard++) {
|
|
184
|
+
active(signal);
|
|
185
|
+
for (const entry of (await shardEntries(shard)).filter(visible)) {
|
|
186
|
+
if (items.length >= limit || examined >= maxExaminedPerPage) return { items, next: cursor };
|
|
187
|
+
active(signal); examined += 1; cursor = entry.id;
|
|
188
|
+
const item = await requestFor(entry); if (item) items.push(item);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { items, next: null };
|
|
192
|
+
};
|
|
100
193
|
const transport = Object.freeze<WorkflowLifecycleHumanTransport>({
|
|
101
194
|
list: async input => {
|
|
102
195
|
exactScope(input.scope); active(input.signal);
|
|
@@ -104,22 +197,14 @@ export function createWorkflowLifecycleHumanTransport(
|
|
|
104
197
|
if ((input.after !== null && !hashPattern.test(input.after)) || !Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 100) {
|
|
105
198
|
throw new MayuraError('INVALID_INPUT', 'Lifecycle human request page is invalid.');
|
|
106
199
|
}
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const items: WorkflowLifecycleHumanTransportRecord[] = []; let examined = 0; let cursor: string | null = null;
|
|
110
|
-
for (const entry of ordered) {
|
|
111
|
-
if (items.length >= input.limit || examined >= maxExaminedPerPage) break;
|
|
112
|
-
active(input.signal); examined += 1; cursor = entry.id;
|
|
113
|
-
const item = await requestFor(entry); if (item) items.push(item);
|
|
114
|
-
}
|
|
115
|
-
const hasMore = cursor !== null && ordered.some(entry => entry.id > cursor!);
|
|
116
|
-
active(input.signal); return freezeJson(jsonValue({ items, next: hasMore ? cursor : null })) as unknown as { readonly items: readonly WorkflowLifecycleHumanTransportRecord[]; readonly next: string | null };
|
|
200
|
+
const result = await page(input.agentIds, input.after, input.limit, input.signal);
|
|
201
|
+
active(input.signal); return freezeJson(jsonValue(result)) as unknown as { readonly items: readonly WorkflowLifecycleHumanTransportRecord[]; readonly next: string | null };
|
|
117
202
|
},
|
|
118
203
|
inspect: async input => {
|
|
119
204
|
exactScope(input.scope); active(input.signal);
|
|
120
205
|
checkedAgents(input.agentIds);
|
|
121
206
|
if (!hashPattern.test(input.id)) throw new MayuraError('INVALID_INPUT', 'Lifecycle human request identity is invalid.');
|
|
122
|
-
const entry =
|
|
207
|
+
const entry = await find(input.id); if (!entry || !input.agentIds.includes(entry.agentId)) return null;
|
|
123
208
|
const item = await requestFor(entry); active(input.signal); return item;
|
|
124
209
|
},
|
|
125
210
|
respond: async input => {
|
|
@@ -129,8 +214,8 @@ export function createWorkflowLifecycleHumanTransport(
|
|
|
129
214
|
|| !identifier.test(input.actorId)) {
|
|
130
215
|
throw new MayuraError('INVALID_INPUT', 'Lifecycle human response identity is invalid.');
|
|
131
216
|
}
|
|
132
|
-
const entry =
|
|
133
|
-
if (!entry || !
|
|
217
|
+
const entry = await find(input.id);
|
|
218
|
+
if (!entry || !input.agentIds.includes(entry.agentId)) throw new MayuraError('NOT_FOUND', 'Lifecycle human request was not found.');
|
|
134
219
|
await entry.runtime.respondVerified(entry.definition, { id: entry.runId, nodeId: entry.nodeId,
|
|
135
220
|
requestDigest: input.requestDigest, commandId: input.commandId,
|
|
136
221
|
actor: { id: input.actorId, projectId: scope.projectId }, value: input.value });
|
|
@@ -142,29 +227,28 @@ export function createWorkflowLifecycleHumanTransport(
|
|
|
142
227
|
return Object.freeze<WorkflowLifecycleHumanTransportController>({
|
|
143
228
|
transport,
|
|
144
229
|
register: input => {
|
|
230
|
+
if (durable) throw new MayuraError('INVALID_CONFIG', 'This human transport finds requests in storage; runs need no registration.');
|
|
145
231
|
assertWorkflowLifecycle(input.definition);
|
|
146
232
|
if (!identifier.test(input.agentId) || !hashPattern.test(input.runId) || input.runtime?.profile !== 'lifecycle-v1') {
|
|
147
233
|
throw new MayuraError('INVALID_INPUT', 'Lifecycle human registration is invalid.');
|
|
148
234
|
}
|
|
149
235
|
const nodes = input.definition.nodes.filter(node => node.kind === 'human');
|
|
150
|
-
const ids = nodes.map(node =>
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const additions = ids.filter(id => !entries.has(id)).length;
|
|
154
|
-
if (entries.size + additions > maxEntries) throw new MayuraError('LIMIT_EXCEEDED', 'Lifecycle human transport registry is full.');
|
|
236
|
+
const ids = nodes.map(node => routeId(input.agentId, input.definition.digest, input.runId, node.id));
|
|
237
|
+
const additions = ids.filter(id => !registered.has(id)).length;
|
|
238
|
+
if (registered.size + additions > maxEntries) throw new MayuraError('LIMIT_EXCEEDED', 'Lifecycle human transport registry is full.');
|
|
155
239
|
for (const [index, node] of nodes.entries()) {
|
|
156
|
-
const id = ids[index]!; const previous =
|
|
240
|
+
const id = ids[index]!; const previous = registered.get(id);
|
|
157
241
|
if (previous && (previous.agentId !== input.agentId || previous.definition !== input.definition
|
|
158
242
|
|| previous.runtime !== input.runtime || previous.runId !== input.runId || previous.nodeId !== node.id)) {
|
|
159
243
|
throw new MayuraError('CONFLICT', 'Lifecycle human route ID collision.');
|
|
160
244
|
}
|
|
161
|
-
|
|
245
|
+
registered.set(id, Object.freeze({ ...input, id, nodeId: node.id }));
|
|
162
246
|
}
|
|
163
247
|
return Object.freeze(ids);
|
|
164
248
|
},
|
|
165
249
|
unregister: runId => {
|
|
166
250
|
if (!hashPattern.test(runId)) throw new MayuraError('INVALID_INPUT', 'Lifecycle run ID is invalid.');
|
|
167
|
-
for (const [id, entry] of
|
|
251
|
+
for (const [id, entry] of registered) if (entry.runId === runId) registered.delete(id);
|
|
168
252
|
},
|
|
169
253
|
});
|
|
170
254
|
}
|