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
|
@@ -3,8 +3,9 @@ import type { WorkflowDrainOptions, WorkflowDrainReport } from './drain.js';
|
|
|
3
3
|
import { StorageError, assertWorkflowSagaStateMatchesManifest, initialWorkflowSagaState, workflowSagaState,
|
|
4
4
|
type StoredRecord, type WorkflowSagaState, type WorkflowSagaStatus, type WorkflowSagaStepState } from '@mayura/storage-contracts';
|
|
5
5
|
import { digest, resolveBinding } from './definition.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { createSubmission, workflowStorageFailure } from './storage-failure.js';
|
|
7
|
+
import { createWorkflowLifecycleRuntime, submitWorkflowLifecycleUnder, unknownWorkflowPolicy, workflowPolicyDigest, workflowPolicySettings,
|
|
8
|
+
type WorkflowLifecycleRuntime, type WorkflowLifecycleRuntimeOptions, type WorkflowLifecycleSnapshot } from './lifecycle-runtime.js';
|
|
8
9
|
import { assertWorkflowSaga, sagaManifest, type AnyWorkflowSaga, type WorkflowSagaStep } from './saga-definition.js';
|
|
9
10
|
import { assertMigrationAllowed, assertWorkflowMigration, migrationCommand, migrationEvent, nodeFingerprint, planWorkflowMigration,
|
|
10
11
|
type MigrationBlocker, type MigrationCommand, type WorkflowMigration, type WorkflowMigrationResult } from './migration.js';
|
|
@@ -52,8 +53,7 @@ const terminalChild = (snapshot: WorkflowLifecycleSnapshot): boolean =>
|
|
|
52
53
|
async function storageCall<T>(operation: () => Promise<T>): Promise<T> {
|
|
53
54
|
try { return await operation(); }
|
|
54
55
|
catch (error) {
|
|
55
|
-
|
|
56
|
-
throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow saga storage is unavailable; inspect current state before retrying.');
|
|
56
|
+
throw workflowStorageFailure(error, 'workflow saga run');
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -109,40 +109,47 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
109
109
|
}
|
|
110
110
|
const lifecycle = createWorkflowLifecycleRuntime(options);
|
|
111
111
|
const scopeKey = digest('mayura:scope:v1', scope);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
// Index n of `settings` and of `policies` is the same policy the lifecycle runtime knows at index n.
|
|
113
|
+
const settings = workflowPolicySettings(options);
|
|
114
|
+
const policies = settings.map(entry => workflowPolicyDigest('mayura:workflow-saga-policy:v1', scope, entry));
|
|
115
|
+
const policy = policies[0]!;
|
|
116
|
+
/** Index of the policy a saga was started with; its later children and limits keep that policy. */
|
|
117
|
+
const pinnedIndex = (state: WorkflowSagaState): number => {
|
|
118
|
+
const index = policies.indexOf(state.policy); if (index < 0) throw unknownWorkflowPolicy(); return index;
|
|
119
|
+
};
|
|
115
120
|
let closed = false;
|
|
116
121
|
const ensureOpen = (): void => { if (closed) throw new MayuraError('CANCELLED', 'Workflow saga runtime is closed.'); };
|
|
117
122
|
let pendingCallbacks = 0;
|
|
118
123
|
const boundedValidate = async (schema: AnyWorkflowSaga['input'] | AnyWorkflowSaga['output'], value: unknown,
|
|
119
|
-
boundary: 'input' | 'output'): Promise<JsonValue> => {
|
|
124
|
+
boundary: 'input' | 'output', maxBytes = maxOutputBytes): Promise<JsonValue> => {
|
|
120
125
|
if (pendingCallbacks >= maxPendingCallbacks) throw new MayuraError('LIMIT_EXCEEDED', 'Saga callback capacity is full.');
|
|
121
126
|
pendingCallbacks += 1; let released = false;
|
|
122
127
|
const release = (): void => { if (!released) { released = true; pendingCallbacks -= 1; } };
|
|
123
|
-
const validation = Promise.resolve().then(() => validate(schema, value, boundary, { maxBytes
|
|
128
|
+
const validation = Promise.resolve().then(() => validate(schema, value, boundary, { maxBytes }));
|
|
124
129
|
void validation.then(release, release);
|
|
125
130
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
126
131
|
try {
|
|
127
132
|
const checked = await Promise.race([validation,
|
|
128
133
|
new Promise<never>((_resolve, reject) => { timer = setTimeout(() => reject(new MayuraError('TIMEOUT', 'Saga schema validation timed out.')), callbackTimeoutMs); })]);
|
|
129
|
-
return jsonValue(checked, { maxBytes
|
|
134
|
+
return jsonValue(checked, { maxBytes });
|
|
130
135
|
} finally { if (timer !== undefined) clearTimeout(timer); }
|
|
131
136
|
};
|
|
132
|
-
|
|
137
|
+
/** `anyPolicy` admits operator controls (pause, resume, cancel, migrate) on a saga whose settings are not listed. */
|
|
138
|
+
const load = async (id: string, anyPolicy = false): Promise<StoredRecord> => {
|
|
133
139
|
ensureOpen();
|
|
134
140
|
if (typeof id !== 'string' || !hashPattern.test(id)) throw new MayuraError('INVALID_INPUT', 'A workflow saga run ID is required.');
|
|
135
141
|
const record = await storageCall(() => store.read(scopeKey, id));
|
|
136
142
|
if (!record) throw new MayuraError('NOT_FOUND', 'Workflow saga run was not found in this scope.');
|
|
137
143
|
if (record.scope !== scopeKey || record.id !== id) throw new MayuraError('CONFLICT', 'Stored saga identity does not match its requested scope.');
|
|
138
144
|
const state = decoded(record);
|
|
139
|
-
if (
|
|
145
|
+
if (!anyPolicy) pinnedIndex(state);
|
|
140
146
|
return record;
|
|
141
147
|
};
|
|
142
|
-
const verify = (definition: AnyWorkflowSaga, record: StoredRecord, state: WorkflowSagaState): void => {
|
|
143
|
-
if (record.definitionHash !== definition.digest || state.definition !== definition.digest
|
|
144
|
-
throw new MayuraError('CONFLICT', 'Workflow saga definition
|
|
148
|
+
const verify = (definition: AnyWorkflowSaga, record: StoredRecord, state: WorkflowSagaState, anyPolicy = false): void => {
|
|
149
|
+
if (record.definitionHash !== definition.digest || state.definition !== definition.digest) {
|
|
150
|
+
throw new MayuraError('CONFLICT', 'Workflow saga definition does not match persisted state.');
|
|
145
151
|
}
|
|
152
|
+
if (!anyPolicy) pinnedIndex(state);
|
|
146
153
|
try { assertWorkflowSagaStateMatchesManifest(state, sagaManifest(definition)); }
|
|
147
154
|
catch { throw new MayuraError('CONFLICT', 'Workflow saga state does not match its persisted definition.'); }
|
|
148
155
|
};
|
|
@@ -150,14 +157,14 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
150
157
|
storageCall(() => store.update({ scope: scopeKey, id: record.id, expectedVersion: record.version,
|
|
151
158
|
state: jsonValue(state) as JsonObject, events: [{ type, data }] }));
|
|
152
159
|
const mutate = async (id: string, transition: (state: WorkflowSagaState) => boolean, type: string,
|
|
153
|
-
data: JsonObject = {}): Promise<StoredRecord> => {
|
|
160
|
+
data: JsonObject = {}, anyPolicy = false): Promise<StoredRecord> => {
|
|
154
161
|
for (let attempt = 0; attempt < 32; attempt++) {
|
|
155
|
-
const record = await load(id); const state = decoded(record); const paused = state.status === 'paused';
|
|
162
|
+
const record = await load(id, anyPolicy); const state = decoded(record); const paused = state.status === 'paused';
|
|
156
163
|
if (!transition(state)) return record;
|
|
157
164
|
// Progress recorded while paused (a child settling) never un-pauses the saga; only a terminal outcome replaces it.
|
|
158
165
|
if (paused && !terminalSagaStatuses.has(state.status) && type !== 'saga.run.resumed') state.status = 'paused';
|
|
159
166
|
try { return await save(record, state, type, data); }
|
|
160
|
-
catch (error) { if (!(error instanceof StorageError) || error.
|
|
167
|
+
catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }
|
|
161
168
|
}
|
|
162
169
|
throw new MayuraError('CONFLICT', 'Workflow saga contention exceeded the bounded retry limit.');
|
|
163
170
|
};
|
|
@@ -177,7 +184,7 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
177
184
|
const workflow = phase === 'forward' ? step.forward : step.compensation!.workflow;
|
|
178
185
|
const binding = phase === 'forward' ? step.input : step.compensation!.input;
|
|
179
186
|
const input = resolveBinding(binding, state.input, outputs(state));
|
|
180
|
-
return lifecycle
|
|
187
|
+
return submitWorkflowLifecycleUnder(lifecycle, pinnedIndex(state), workflow, { input, idempotencyKey: childKey(runId, step.id, phase) });
|
|
181
188
|
};
|
|
182
189
|
|
|
183
190
|
const run = async (definition: AnyWorkflowSaga, id: string): Promise<WorkflowSagaSnapshot> => {
|
|
@@ -190,7 +197,7 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
190
197
|
if (!step) {
|
|
191
198
|
let output: JsonValue;
|
|
192
199
|
try { output = await boundedValidate(definition.output,
|
|
193
|
-
resolveBinding(definition.result, state.input, outputs(state)), 'output'); }
|
|
200
|
+
resolveBinding(definition.result, state.input, outputs(state)), 'output', settings[pinnedIndex(state)]!.maxOutputBytes); }
|
|
194
201
|
catch (error) {
|
|
195
202
|
if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;
|
|
196
203
|
state.status = 'compensating'; state.cursor = definition.steps.length;
|
|
@@ -318,9 +325,9 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
318
325
|
const input = await boundedValidate(definition.input, raw, 'input');
|
|
319
326
|
const state = initialWorkflowSagaState(sagaManifest(definition), input, definition.digest, policy, options.maxCostMicros);
|
|
320
327
|
const id = digest('mayura:workflow-saga-run-id:v1', { scope: scopeKey, submissionKey: command.idempotencyKey });
|
|
321
|
-
const created = await
|
|
328
|
+
const created = await createSubmission(() => store.create({ scope: scopeKey, id,
|
|
322
329
|
idempotencyKey: `saga:${command.idempotencyKey}`, definitionHash: definition.digest,
|
|
323
|
-
state: jsonValue(state) as JsonObject, events: [{ type: 'saga.run.created', data: {} }] }));
|
|
330
|
+
state: jsonValue(state) as JsonObject, events: [{ type: 'saga.run.created', data: {} }] }), 'workflow saga run');
|
|
324
331
|
verify(definition, created.record, decoded(created.record)); return snapshot(created.record);
|
|
325
332
|
},
|
|
326
333
|
inspect: async id => snapshot(await load(id)),
|
|
@@ -330,18 +337,20 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
330
337
|
if (state.status === 'paused') return false;
|
|
331
338
|
if (terminalSagaStatuses.has(state.status)) throw new MayuraError('CONFLICT', 'A terminal saga cannot be paused.');
|
|
332
339
|
state.status = 'paused'; return true;
|
|
333
|
-
}, 'saga.run.paused')),
|
|
340
|
+
}, 'saga.run.paused', {}, true)),
|
|
334
341
|
resume: async id => snapshot(await mutate(id, state => {
|
|
335
342
|
if (state.status !== 'paused') throw new MayuraError('CONFLICT', 'Only a paused saga can be resumed.');
|
|
336
343
|
const compensating = Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status));
|
|
337
344
|
state.status = compensating ? 'compensating' : 'running'; return true;
|
|
338
|
-
}, 'saga.run.resumed')),
|
|
345
|
+
}, 'saga.run.resumed', {}, true)),
|
|
339
346
|
migrate: async (migration, command) => {
|
|
340
347
|
ensureOpen(); assertWorkflowMigration(migration); assertWorkflowSaga(migration.from); assertWorkflowSaga(migration.to);
|
|
341
348
|
const { id, actorId, commandId, dryRun = false } = migrationCommand(command);
|
|
342
|
-
|
|
349
|
+
// A reviewed migration is the explicit way to move a saga onto the current settings, whichever it started under.
|
|
350
|
+
const record = await load(id, true); const state = decoded(record); verify(migration.from, record, state, true);
|
|
343
351
|
const preconditions: MigrationBlocker[] = [];
|
|
344
352
|
if (state.status !== 'paused') preconditions.push({ node: '*', reason: `The saga is ${state.status}; pause it before migrating.` });
|
|
353
|
+
if (state.spentMicros > options.maxCostMicros) preconditions.push({ node: '*', reason: 'The saga already spent more than the current maxCostMicros.' });
|
|
345
354
|
if (Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status))) {
|
|
346
355
|
preconditions.push({ node: '*', reason: 'The saga is compensating; only a saga in its forward phase can migrate.' });
|
|
347
356
|
}
|
|
@@ -371,7 +380,8 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
371
380
|
for (const entry of plan.entries) if (entry.target) carried[entry.target] = entry.action === 'keep' || entry.action === 'accept' ? state.steps[entry.source!]! : fresh.steps[entry.target]!;
|
|
372
381
|
const steps = Object.fromEntries(toManifest.steps.map(step => [step.id, carried[step.id]!]));
|
|
373
382
|
const cursor = toManifest.steps.findIndex(step => steps[step.id]!.status !== 'succeeded');
|
|
374
|
-
const next: WorkflowSagaState = { ...state, definition: migration.to.digest,
|
|
383
|
+
const next: WorkflowSagaState = { ...state, definition: migration.to.digest, policy, maxCostMicros: options.maxCostMicros,
|
|
384
|
+
steps, cursor: cursor < 0 ? toManifest.steps.length : cursor,
|
|
375
385
|
spentMicros: Object.values(steps).reduce((sum, step) => sum + step.forwardSpentMicros + step.compensationSpentMicros, 0) };
|
|
376
386
|
try { assertWorkflowSagaStateMatchesManifest(workflowSagaState({ id, state: jsonValue(next) as JsonObject }), toManifest); }
|
|
377
387
|
catch { throw new MayuraError('CONFLICT', 'Migration refused: the migrated saga state does not satisfy the new definition.'); }
|
|
@@ -382,7 +392,7 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
382
392
|
return freezeJson(jsonValue({ plan, snapshot: snapshot(migrated) })) as unknown as WorkflowMigrationResult<WorkflowSagaSnapshot>;
|
|
383
393
|
},
|
|
384
394
|
cancel: async id => {
|
|
385
|
-
let record = await load(id); const state = decoded(record);
|
|
395
|
+
let record = await load(id, true); const state = decoded(record);
|
|
386
396
|
if (terminalSagaStatuses.has(state.status)) return snapshot(record);
|
|
387
397
|
const activeEntry = Object.entries(state.steps).find(([, step]) => step.status === 'forward_waiting' || step.status === 'compensation_waiting');
|
|
388
398
|
const active = activeEntry?.[1]; const activeStepId = activeEntry?.[0];
|
|
@@ -397,7 +407,7 @@ export function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions):
|
|
|
397
407
|
if (linked === child.id) recordChild(current, activeStepId, phase, child);
|
|
398
408
|
}
|
|
399
409
|
current.status = 'cancelled'; return true;
|
|
400
|
-
}, 'saga.run.cancelled');
|
|
410
|
+
}, 'saga.run.cancelled', {}, true);
|
|
401
411
|
return snapshot(record);
|
|
402
412
|
},
|
|
403
413
|
close: () => { if (!closed) { closed = true; lifecycle.close(); } },
|
|
@@ -31,13 +31,13 @@ const storageCodes = new Set<StorageErrorCode>(['INVALID_INPUT', 'CONFLICT', 'NO
|
|
|
31
31
|
/** Preserve only stable storage codes; never copy adapter messages or inspect exception getters. */
|
|
32
32
|
/** Fixed storage answer when an approval expired before admission: final for that call, and a new review is needed. */
|
|
33
33
|
export const reviewExpiredMessage = 'The approval expired; request a new review before admission.';
|
|
34
|
-
export const isReviewExpired = (error: unknown): boolean => error instanceof StorageError && error.
|
|
34
|
+
export const isReviewExpired = (error: unknown): boolean => error instanceof StorageError && error.storageCode === 'CONFLICT' && error.message === reviewExpiredMessage;
|
|
35
35
|
export async function scheduledStorage<T>(operation: () => Promise<T>, timeoutMs = 10_000, signal?: AbortSignal): Promise<T> {
|
|
36
36
|
try { return await scheduledCallback(operation, timeoutMs, signal ?? new AbortController().signal); }
|
|
37
37
|
catch (error) {
|
|
38
38
|
let code: StorageErrorCode = 'STORAGE_UNAVAILABLE'; let refusal: string | undefined;
|
|
39
39
|
try {
|
|
40
|
-
const own = error instanceof StorageError ? Object.getOwnPropertyDescriptor(error, '
|
|
40
|
+
const own = error instanceof StorageError ? Object.getOwnPropertyDescriptor(error, 'storageCode') : undefined;
|
|
41
41
|
if (own && 'value' in own && storageCodes.has(own.value as StorageErrorCode)) code = own.value as StorageErrorCode;
|
|
42
42
|
// A migration refusal is fixed storage text plus step ids; it is the reviewer's answer, so it is kept verbatim.
|
|
43
43
|
const message = error instanceof StorageError ? Object.getOwnPropertyDescriptor(error, 'message') : undefined;
|
|
@@ -49,7 +49,7 @@ export async function scheduledStorage<T>(operation: () => Promise<T>, timeoutMs
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export function isStorageCode(error: unknown, code: StorageErrorCode): boolean {
|
|
52
|
-
return error instanceof StorageError && error.
|
|
52
|
+
return error instanceof StorageError && error.storageCode === code;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/** One bounded callback window. Late results/rejections are handled without further admission. */
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MayuraError } from '@mayura/core';
|
|
2
|
+
import { StorageError } from '@mayura/storage-contracts';
|
|
3
|
+
|
|
4
|
+
/** Storage conditions whose own message already tells a developer what to do. */
|
|
5
|
+
const actionable = new Set(['STORE_CLOSED', 'STORE_NOT_INITIALIZED', 'QUEUE_FULL']);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal A storage failure as a workflow runtime reports it. A write that lost a race stays a `CONFLICT`
|
|
9
|
+
* `StorageError` (the runtimes retry on it); a closed, uninitialized or saturated store keeps the store's error, whose
|
|
10
|
+
* message says what to do; anything else is `STORAGE_UNAVAILABLE`, and the caller must inspect the run before
|
|
11
|
+
* retrying, because the write may or may not have happened. Adapter messages of unknown errors are never reflected.
|
|
12
|
+
*/
|
|
13
|
+
export function workflowStorageFailure(error: unknown, subject: string): MayuraError {
|
|
14
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT') {
|
|
15
|
+
return new StorageError('CONFLICT', `The ${subject} changed while this operation ran (another worker or request updated it). Read it again and retry.`);
|
|
16
|
+
}
|
|
17
|
+
if (error instanceof StorageError && actionable.has(error.storageCode)) return error;
|
|
18
|
+
return new MayuraError('STORAGE_UNAVAILABLE', `The ${subject} store could not confirm this operation. Inspect the run before retrying; an action may already have happened.`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal A submission whose idempotency key already names a run with different content: the input, the definition
|
|
23
|
+
* version or the runtime settings differ. Resubmitting the identical request returns the existing run.
|
|
24
|
+
*/
|
|
25
|
+
export function resubmissionConflict(): MayuraError {
|
|
26
|
+
return new MayuraError('CONFLICT', 'This idempotency key was already used to start a run with different input, definition version or runtime settings. '
|
|
27
|
+
+ 'Resubmit exactly the same request to get that run, or use a new idempotency key.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @internal Run a submission's `create`, reporting a reused idempotency key as `resubmissionConflict`. */
|
|
31
|
+
export async function createSubmission<T>(operation: () => Promise<T>, subject: string): Promise<T> {
|
|
32
|
+
try { return await operation(); }
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof StorageError && error.storageCode === 'CONFLICT') throw resubmissionConflict();
|
|
35
|
+
throw workflowStorageFailure(error, subject);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsonValue, type JsonObject, type JsonValue, type Scope } from '@mayura/core';
|
|
2
|
+
import type { AggregateStore, StoredRecord } from '@mayura/storage-contracts';
|
|
3
|
+
import { digest } from './definition.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where a host's sweep stands, kept in storage, so that a new process (a restarted worker, or the next run of a one-shot
|
|
7
|
+
* worker) continues the sweep instead of starting it over. Without it, a sweep that never finishes within one process
|
|
8
|
+
* would keep revisiting the same runs and never reach the rest.
|
|
9
|
+
*
|
|
10
|
+
* Best effort: a position that cannot be read or written only costs a restart from the beginning, never correctness,
|
|
11
|
+
* because every run transition is decided on the run's own record.
|
|
12
|
+
*/
|
|
13
|
+
export interface SweepPosition<C> {
|
|
14
|
+
/** The stored position, once per process (the first call only); `null` when there is none or it cannot be read. */
|
|
15
|
+
load(): Promise<C | null>;
|
|
16
|
+
/** Store the position if it changed. Failures are ignored. */
|
|
17
|
+
save(position: C | null): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createSweepPosition<C>(store: AggregateStore, options: {
|
|
21
|
+
readonly kind: 'lifecycle' | 'composite'; readonly scope: Scope; readonly catalog: readonly string[];
|
|
22
|
+
}): SweepPosition<C> {
|
|
23
|
+
const scope = digest('mayura:scope:v1', { principalId: options.scope.principalId, projectId: options.scope.projectId });
|
|
24
|
+
const id = digest('mayura:workflow-sweep-position:v1', { scope, kind: options.kind, catalog: [...options.catalog].sort() });
|
|
25
|
+
const definitionHash = digest('mayura:workflow-sweep-position-format:v1', {});
|
|
26
|
+
let loaded = false; let record: StoredRecord | undefined; let stored: string | undefined;
|
|
27
|
+
const state = (position: C | null): JsonObject => jsonValue({ format: 1, position: position as unknown as JsonValue }) as JsonObject;
|
|
28
|
+
return Object.freeze<SweepPosition<C>>({
|
|
29
|
+
async load() {
|
|
30
|
+
if (loaded) return null; loaded = true;
|
|
31
|
+
try {
|
|
32
|
+
record = await store.read(scope, id);
|
|
33
|
+
const value = record?.state['format'] === 1 ? record.state['position'] : null;
|
|
34
|
+
stored = JSON.stringify(value ?? null);
|
|
35
|
+
return (value ?? null) as C | null;
|
|
36
|
+
} catch { record = undefined; return null; }
|
|
37
|
+
},
|
|
38
|
+
async save(position) {
|
|
39
|
+
const text = JSON.stringify(position);
|
|
40
|
+
if (text === stored) return;
|
|
41
|
+
try {
|
|
42
|
+
record ??= await store.read(scope, id);
|
|
43
|
+
record = record ? await store.update({ scope, id, expectedVersion: record.version, state: state(position), events: [] })
|
|
44
|
+
: (await store.create({ scope, id, idempotencyKey: id, definitionHash, state: state(position), events: [] })).record;
|
|
45
|
+
stored = text;
|
|
46
|
+
} catch {
|
|
47
|
+
// Another host wrote it first, or storage failed: forget the version and read it again on the next save.
|
|
48
|
+
record = undefined; stored = undefined;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -246,7 +246,7 @@ export function createWorkflowTraceExport(options: WorkflowTraceExportOptions):
|
|
|
246
246
|
const markerId = (runId: string): string => digest('mayura:workflow-trace-export:v1', { exportId, runId });
|
|
247
247
|
const guarded = async <T>(operation: () => Promise<T>): Promise<T> => {
|
|
248
248
|
try { return await operation(); }
|
|
249
|
-
catch (error) { if (error instanceof MayuraError || (error instanceof StorageError && error.
|
|
249
|
+
catch (error) { if (error instanceof MayuraError || (error instanceof StorageError && error.storageCode === 'CONFLICT')) throw error;
|
|
250
250
|
throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow trace export storage is unavailable.'); }
|
|
251
251
|
};
|
|
252
252
|
const corrupt = (): never => { throw new MayuraError('STORAGE_UNAVAILABLE', 'Stored workflow trace export state failed integrity validation.'); };
|
|
@@ -269,7 +269,7 @@ export function createWorkflowTraceExport(options: WorkflowTraceExportOptions):
|
|
|
269
269
|
try {
|
|
270
270
|
if (record) { await guarded(() => store.update({ scope, id, expectedVersion: record.version, state, events: [{ type, data: {} }] })); return; }
|
|
271
271
|
if ((await guarded(() => store.create({ scope, id, idempotencyKey: id, definitionHash: formatHash, state, events: [{ type, data: {} }] }))).created) return;
|
|
272
|
-
} catch (error) { if (!(error instanceof StorageError && error.
|
|
272
|
+
} catch (error) { if (!(error instanceof StorageError && error.storageCode === 'CONFLICT')) throw error; }
|
|
273
273
|
}
|
|
274
274
|
throw new MayuraError('CONFLICT', 'Workflow trace export contention exceeded its bounded retry limit.');
|
|
275
275
|
};
|
|
@@ -7,6 +7,12 @@ export interface WorkflowWorkerUnit {
|
|
|
7
7
|
start(): void;
|
|
8
8
|
stop(): Promise<void>;
|
|
9
9
|
drain(options?: WorkflowDrainOptions): Promise<WorkflowDrainReport>;
|
|
10
|
+
/**
|
|
11
|
+
* One bounded pass over due work, then return; what `WorkflowWorker.runOnce` calls. `completedSweep` is true once the
|
|
12
|
+
* pass reached the end of the unit's work, and `held` while a fleet hold stops it from driving anything. Hosts and
|
|
13
|
+
* `coordinatorUnit` have it.
|
|
14
|
+
*/
|
|
15
|
+
runOnce?(): Promise<{ readonly completedSweep: boolean; readonly held?: boolean }>;
|
|
10
16
|
}
|
|
11
17
|
export interface WorkflowWorkerStatus {
|
|
12
18
|
readonly running: boolean; readonly leader: boolean; readonly fence: number; readonly unitsActive: boolean;
|
|
@@ -20,6 +26,28 @@ export interface WorkflowWorker {
|
|
|
20
26
|
isReady(): boolean;
|
|
21
27
|
/** Stop renewing, drain every unit within one deadline, then release the lease so a standby takes over at once. */
|
|
22
28
|
drain(options?: WorkflowDrainOptions): Promise<WorkflowDrainReport>;
|
|
29
|
+
/**
|
|
30
|
+
* Advance everything that is due once, then return: for a scheduled job or function instead of a process that keeps
|
|
31
|
+
* running. Takes the lease once (a standby returns at once, having done nothing), runs each unit's passes until every
|
|
32
|
+
* unit has completed a sweep or the budget runs out, renewing the lease between passes, then releases it. A pass that
|
|
33
|
+
* has started finishes, so leave room in the budget for your longest tool. Not while the worker is started.
|
|
34
|
+
*/
|
|
35
|
+
runOnce(options?: WorkflowWorkerOnceOptions): Promise<WorkflowWorkerOnceReport>;
|
|
36
|
+
}
|
|
37
|
+
export interface WorkflowWorkerOnceOptions {
|
|
38
|
+
/** Stop starting passes after this long. Default 60,000 ms; 1,000 to 3,600,000. */
|
|
39
|
+
readonly budgetMs?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface WorkflowWorkerOnceReport {
|
|
42
|
+
/** False when another replica holds the lease: this call advanced nothing. */
|
|
43
|
+
readonly leader: boolean;
|
|
44
|
+
/** Every unit completed a sweep within the budget. When false, run it more often or give it a larger budget. */
|
|
45
|
+
readonly completedSweep: boolean;
|
|
46
|
+
/** A fleet hold stopped a unit from driving runs. */
|
|
47
|
+
readonly held: boolean;
|
|
48
|
+
readonly passes: number;
|
|
49
|
+
/** The error code of each pass that failed. */
|
|
50
|
+
readonly failures: readonly ErrorCode[];
|
|
23
51
|
}
|
|
24
52
|
export interface WorkflowWorkerOptions {
|
|
25
53
|
readonly units: readonly WorkflowWorkerUnit[];
|
|
@@ -59,9 +87,46 @@ export function createWorkflowWorker(options: WorkflowWorkerOptions): WorkflowWo
|
|
|
59
87
|
leader = false; lastError = error instanceof MayuraError ? error.code : 'STORAGE_UNAVAILABLE'; await deactivate();
|
|
60
88
|
}
|
|
61
89
|
};
|
|
90
|
+
let once = false;
|
|
91
|
+
const runOnce = async (onceOptions: WorkflowWorkerOnceOptions = {}): Promise<WorkflowWorkerOnceReport> => {
|
|
92
|
+
const budgetMs = onceOptions.budgetMs ?? 60_000;
|
|
93
|
+
if (!Number.isSafeInteger(budgetMs) || budgetMs < 1_000 || budgetMs > 3_600_000) throw new MayuraError('INVALID_CONFIG', 'budgetMs must be 1000–3600000.');
|
|
94
|
+
if (units.some(unit => typeof unit.runOnce !== 'function')) throw new MayuraError('INVALID_CONFIG', 'A one-shot worker needs units with runOnce: hosts, or coordinators through coordinatorUnit.');
|
|
95
|
+
if (running || draining || once) throw new MayuraError('CONFLICT', 'The worker is already running.');
|
|
96
|
+
once = true; const deadline = now() + budgetMs; const failures: ErrorCode[] = []; let passes = 0; let held = false; let completed = false;
|
|
97
|
+
const report = (isLeader: boolean): WorkflowWorkerOnceReport =>
|
|
98
|
+
freezeJson(jsonValue({ leader: isLeader, completedSweep: completed, held, passes, failures })) as unknown as WorkflowWorkerOnceReport;
|
|
99
|
+
try {
|
|
100
|
+
if (leadership) {
|
|
101
|
+
const state = await leadership.acquire(); leader = state.leader; fence = state.fence; lastConfirmedAtMs = now();
|
|
102
|
+
if (!state.leader) return report(false);
|
|
103
|
+
}
|
|
104
|
+
const pending = new Set(units); let renewedAtMs = now();
|
|
105
|
+
while (pending.size > 0 && now() < deadline) {
|
|
106
|
+
for (const unit of [...pending]) {
|
|
107
|
+
if (now() >= deadline) break;
|
|
108
|
+
try {
|
|
109
|
+
const cycle = await unit.runOnce!(); passes += 1;
|
|
110
|
+
if (cycle.held) { held = true; pending.delete(unit); } else if (cycle.completedSweep) pending.delete(unit);
|
|
111
|
+
} catch (error) { passes += 1; failures.push(error instanceof MayuraError ? error.code : 'STORAGE_UNAVAILABLE'); pending.delete(unit); }
|
|
112
|
+
}
|
|
113
|
+
// Keep the lease between passes; stop at once if it was lost, rather than risk two leaders.
|
|
114
|
+
if (leadership && pending.size > 0 && now() - renewedAtMs >= interval) {
|
|
115
|
+
const state = await leadership.acquire(); renewedAtMs = now(); lastConfirmedAtMs = renewedAtMs; fence = state.fence;
|
|
116
|
+
if (!state.leader) { leader = false; break; }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
completed = pending.size === 0 && !held && failures.length === 0;
|
|
120
|
+
return report(true);
|
|
121
|
+
} finally {
|
|
122
|
+
if (leadership && leader) { try { await leadership.release(); } catch { /* The lease expires on its own. */ } }
|
|
123
|
+
leader = false; once = false;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
62
126
|
return Object.freeze<WorkflowWorker>({
|
|
127
|
+
runOnce,
|
|
63
128
|
start() {
|
|
64
|
-
if (draining) throw new MayuraError('CANCELLED', 'The worker is draining.'); if (running) return;
|
|
129
|
+
if (draining) throw new MayuraError('CANCELLED', 'The worker is draining.'); if (once) throw new MayuraError('CONFLICT', 'The worker is running once.'); if (running) return;
|
|
65
130
|
running = true; controller = new AbortController(); const signal = controller.signal;
|
|
66
131
|
loop = (async () => { while (!signal.aborted) { await tick(); await sleep(interval, signal); } })();
|
|
67
132
|
},
|
|
@@ -111,5 +176,18 @@ export function coordinatorUnit(coordinator: {
|
|
|
111
176
|
},
|
|
112
177
|
stop,
|
|
113
178
|
async drain(options) { await stop(); return coordinator.drain(options); },
|
|
179
|
+
async runOnce() {
|
|
180
|
+
if (loop) throw new MayuraError('CONFLICT', 'The coordinator unit is running.');
|
|
181
|
+
// Page through one sweep, up to 256 pages; a failed page ends the pass and the next pass starts over.
|
|
182
|
+
let pages = 0;
|
|
183
|
+
do {
|
|
184
|
+
try {
|
|
185
|
+
const report = await coordinator.runPage({ cursor: cursor as never, limit });
|
|
186
|
+
cursor = report.status === 'completed' ? report.nextCursor ?? null : report.retryCursor ?? null;
|
|
187
|
+
} catch (error) { cursor = null; throw error; }
|
|
188
|
+
pages += 1;
|
|
189
|
+
} while (cursor !== null && pages < 256);
|
|
190
|
+
return { completedSweep: cursor === null };
|
|
191
|
+
},
|
|
114
192
|
});
|
|
115
193
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { type InferInput, type InferOutput, type JsonValue, type Schema, type Scope } from '../../core/dist/index.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type AggregateStore } from '../../storage-contracts/dist/index.js';
|
|
3
|
+
export { schemaDigest } from '../../storage-contracts/dist/index.js';
|
|
3
4
|
export type HumanRequestKind = 'information' | 'correction' | 'plan_selection';
|
|
4
5
|
export interface HumanRequestDefinition<S extends Schema = Schema> {
|
|
5
6
|
readonly id: string;
|
|
6
7
|
readonly kind: HumanRequestKind;
|
|
7
8
|
/** Stable application-owned name for the response schema. */
|
|
8
9
|
readonly schemaId: string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* SHA-256 of the pinned schema artifact or application schema contract. Omit it to derive it from `response` when
|
|
12
|
+
* that validator can describe itself as JSON Schema (Zod 4.2 and later can); see `schemaDigest`.
|
|
13
|
+
*/
|
|
14
|
+
readonly schemaDigest?: string;
|
|
11
15
|
readonly prompt: string;
|
|
12
16
|
readonly response: S;
|
|
13
17
|
readonly context?: JsonValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"humans.d.ts","sourceRoot":"","sources":["../src/humans.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAAE,KAAK,WAAW,EAAmB,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAC5F,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"humans.d.ts","sourceRoot":"","sources":["../src/humans.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { assertSchema, freezeJson, jsonValue, MayuraError, validate, } from '../../core/dist/index.js';
|
|
2
|
+
import { schemaDigest } from '../../storage-contracts/dist/index.js';
|
|
3
|
+
export { schemaDigest } from '../../storage-contracts/dist/index.js';
|
|
2
4
|
import { createWorkStream } from './index.js';
|
|
3
5
|
const REQUEST_BYTES = 3_584;
|
|
4
6
|
const RESPONSE_BYTES = 3_584;
|
|
@@ -74,7 +76,16 @@ async function captured(definition) {
|
|
|
74
76
|
identifier(definition.schemaId, 'Schema ID');
|
|
75
77
|
if (!['information', 'correction', 'plan_selection'].includes(definition.kind))
|
|
76
78
|
invalid('Human request kind is invalid.');
|
|
77
|
-
|
|
79
|
+
let pinned = definition.schemaDigest;
|
|
80
|
+
if (pinned === undefined) {
|
|
81
|
+
try {
|
|
82
|
+
pinned = schemaDigest(definition.response);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
invalid('Human request has no schemaDigest, and its response validator cannot describe itself as JSON Schema. Give schemaDigest (64 hex characters).');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
digest(pinned, 'Schema digest');
|
|
78
89
|
if (typeof definition.prompt !== 'string' || definition.prompt.length < 1 || new TextEncoder().encode(definition.prompt).length > 1_024)
|
|
79
90
|
invalid('Human request prompt must contain 1–1024 UTF-8 bytes.');
|
|
80
91
|
if (definition.subjectDigest !== undefined)
|
|
@@ -86,7 +97,7 @@ async function captured(definition) {
|
|
|
86
97
|
if (definition.deadlineAtMs !== undefined)
|
|
87
98
|
timestamp(definition.deadlineAtMs);
|
|
88
99
|
const material = jsonValue({ format: 1, id: definition.id, kind: definition.kind, schemaId: definition.schemaId,
|
|
89
|
-
schemaDigest:
|
|
100
|
+
schemaDigest: pinned, prompt: definition.prompt,
|
|
90
101
|
...(definition.context === undefined ? {} : { context: definition.context }),
|
|
91
102
|
...(definition.subjectDigest === undefined ? {} : { subjectDigest: definition.subjectDigest }),
|
|
92
103
|
...(definition.deadlineAtMs === undefined ? {} : { deadlineAtMs: definition.deadlineAtMs }),
|