mayura 0.1.0-dev.0
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/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +55 -0
- package/lib/adapter-code-docker/dist/index.d.ts +65 -0
- package/lib/adapter-code-docker/dist/index.d.ts.map +1 -0
- package/lib/adapter-code-docker/dist/index.js +228 -0
- package/lib/adapter-code-docker/dist/index.js.map +1 -0
- package/lib/adapter-code-docker/image/Dockerfile +12 -0
- package/lib/adapter-code-docker/package.json +5 -0
- package/lib/adapter-code-docker/src/index.ts +244 -0
- package/lib/adapter-code-quickjs/dist/index.d.ts +40 -0
- package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -0
- package/lib/adapter-code-quickjs/dist/index.js +169 -0
- package/lib/adapter-code-quickjs/dist/index.js.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker.d.ts +2 -0
- package/lib/adapter-code-quickjs/dist/worker.d.ts.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker.js +164 -0
- package/lib/adapter-code-quickjs/dist/worker.js.map +1 -0
- package/lib/adapter-code-quickjs/package.json +5 -0
- package/lib/adapter-code-quickjs/src/index.ts +174 -0
- package/lib/adapter-code-quickjs/src/worker.ts +142 -0
- package/lib/adapter-mcp/dist/index.d.ts +29 -0
- package/lib/adapter-mcp/dist/index.d.ts.map +1 -0
- package/lib/adapter-mcp/dist/index.js +54 -0
- package/lib/adapter-mcp/dist/index.js.map +1 -0
- package/lib/adapter-mcp/package.json +5 -0
- package/lib/adapter-mcp/src/index.ts +82 -0
- package/lib/artifacts/dist/contracts.d.ts +139 -0
- package/lib/artifacts/dist/contracts.d.ts.map +1 -0
- package/lib/artifacts/dist/contracts.js +2 -0
- package/lib/artifacts/dist/contracts.js.map +1 -0
- package/lib/artifacts/dist/index.d.ts +3 -0
- package/lib/artifacts/dist/index.d.ts.map +1 -0
- package/lib/artifacts/dist/index.js +2 -0
- package/lib/artifacts/dist/index.js.map +1 -0
- package/lib/artifacts/dist/local-store.d.ts +3 -0
- package/lib/artifacts/dist/local-store.d.ts.map +1 -0
- package/lib/artifacts/dist/local-store.js +922 -0
- package/lib/artifacts/dist/local-store.js.map +1 -0
- package/lib/artifacts/package.json +5 -0
- package/lib/artifacts/src/contracts.ts +159 -0
- package/lib/artifacts/src/index.ts +26 -0
- package/lib/artifacts/src/local-store.ts +816 -0
- package/lib/cli/dist/application.d.ts +85 -0
- package/lib/cli/dist/application.d.ts.map +1 -0
- package/lib/cli/dist/application.js +116 -0
- package/lib/cli/dist/application.js.map +1 -0
- package/lib/cli/dist/bin.d.ts +3 -0
- package/lib/cli/dist/bin.d.ts.map +1 -0
- package/lib/cli/dist/bin.js +394 -0
- package/lib/cli/dist/bin.js.map +1 -0
- package/lib/cli/dist/dev.d.ts +21 -0
- package/lib/cli/dist/dev.d.ts.map +1 -0
- package/lib/cli/dist/dev.js +205 -0
- package/lib/cli/dist/dev.js.map +1 -0
- package/lib/cli/dist/index.d.ts +72 -0
- package/lib/cli/dist/index.d.ts.map +1 -0
- package/lib/cli/dist/index.js +423 -0
- package/lib/cli/dist/index.js.map +1 -0
- package/lib/cli/dist/interactive.d.ts +19 -0
- package/lib/cli/dist/interactive.d.ts.map +1 -0
- package/lib/cli/dist/interactive.js +163 -0
- package/lib/cli/dist/interactive.js.map +1 -0
- package/lib/cli/dist/operations.d.ts +215 -0
- package/lib/cli/dist/operations.d.ts.map +1 -0
- package/lib/cli/dist/operations.js +580 -0
- package/lib/cli/dist/operations.js.map +1 -0
- package/lib/cli/dist/output.d.ts +29 -0
- package/lib/cli/dist/output.d.ts.map +1 -0
- package/lib/cli/dist/output.js +244 -0
- package/lib/cli/dist/output.js.map +1 -0
- package/lib/cli/dist/providers.d.ts +54 -0
- package/lib/cli/dist/providers.d.ts.map +1 -0
- package/lib/cli/dist/providers.js +96 -0
- package/lib/cli/dist/providers.js.map +1 -0
- package/lib/cli/package.json +5 -0
- package/lib/cli/src/application.ts +109 -0
- package/lib/cli/src/bin.ts +261 -0
- package/lib/cli/src/dev.ts +139 -0
- package/lib/cli/src/index.ts +386 -0
- package/lib/cli/src/interactive.ts +132 -0
- package/lib/cli/src/operations.ts +458 -0
- package/lib/cli/src/output.ts +205 -0
- package/lib/cli/src/providers.ts +102 -0
- package/lib/cli/starters/approval-workflow/Dockerfile +20 -0
- package/lib/cli/starters/approval-workflow/README.md +102 -0
- package/lib/cli/starters/approval-workflow/compose.yaml +33 -0
- package/lib/cli/starters/approval-workflow/dot-dockerignore +7 -0
- package/lib/cli/starters/approval-workflow/dot-env.example +41 -0
- package/lib/cli/starters/approval-workflow/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/approval-workflow/dot-gitignore +10 -0
- package/lib/cli/starters/approval-workflow/mayura.project.json +16 -0
- package/lib/cli/starters/approval-workflow/package.json +30 -0
- package/lib/cli/starters/approval-workflow/src/app.ts +19 -0
- package/lib/cli/starters/approval-workflow/src/auth.ts +68 -0
- package/lib/cli/starters/approval-workflow/src/config.ts +107 -0
- package/lib/cli/starters/approval-workflow/src/dev.ts +59 -0
- package/lib/cli/starters/approval-workflow/src/intake.ts +104 -0
- package/lib/cli/starters/approval-workflow/src/model.ts +33 -0
- package/lib/cli/starters/approval-workflow/src/server.ts +56 -0
- package/lib/cli/starters/approval-workflow/src/services.ts +26 -0
- package/lib/cli/starters/approval-workflow/src/token.ts +6 -0
- package/lib/cli/starters/approval-workflow/src/worker.ts +18 -0
- package/lib/cli/starters/approval-workflow/src/workflow.ts +100 -0
- package/lib/cli/starters/approval-workflow/test/refunds.test.ts +140 -0
- package/lib/cli/starters/approval-workflow/tsconfig.json +20 -0
- package/lib/cli/starters/event-automation/Dockerfile +21 -0
- package/lib/cli/starters/event-automation/README.md +150 -0
- package/lib/cli/starters/event-automation/compose.yaml +41 -0
- package/lib/cli/starters/event-automation/dot-dockerignore +7 -0
- package/lib/cli/starters/event-automation/dot-env.example +51 -0
- package/lib/cli/starters/event-automation/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/event-automation/dot-gitignore +10 -0
- package/lib/cli/starters/event-automation/mayura.project.json +17 -0
- package/lib/cli/starters/event-automation/package.json +32 -0
- package/lib/cli/starters/event-automation/src/app.ts +19 -0
- package/lib/cli/starters/event-automation/src/auth.ts +61 -0
- package/lib/cli/starters/event-automation/src/config.ts +138 -0
- package/lib/cli/starters/event-automation/src/dev.ts +54 -0
- package/lib/cli/starters/event-automation/src/ingress.ts +129 -0
- package/lib/cli/starters/event-automation/src/mcp.ts +139 -0
- package/lib/cli/starters/event-automation/src/model.ts +33 -0
- package/lib/cli/starters/event-automation/src/send-sample.ts +29 -0
- package/lib/cli/starters/event-automation/src/server.ts +58 -0
- package/lib/cli/starters/event-automation/src/services.ts +54 -0
- package/lib/cli/starters/event-automation/src/signing.ts +30 -0
- package/lib/cli/starters/event-automation/src/token.ts +7 -0
- package/lib/cli/starters/event-automation/src/tracker/main.ts +18 -0
- package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +145 -0
- package/lib/cli/starters/event-automation/src/tracker/samples.ts +19 -0
- package/lib/cli/starters/event-automation/src/tracker/tickets.ts +54 -0
- package/lib/cli/starters/event-automation/src/tracker-tools.ts +38 -0
- package/lib/cli/starters/event-automation/src/triage.ts +151 -0
- package/lib/cli/starters/event-automation/src/worker.ts +19 -0
- package/lib/cli/starters/event-automation/src/workflows.ts +57 -0
- package/lib/cli/starters/event-automation/test/automation.test.ts +200 -0
- package/lib/cli/starters/event-automation/tsconfig.json +20 -0
- package/lib/cli/starters/research-team/Dockerfile +22 -0
- package/lib/cli/starters/research-team/README.md +189 -0
- package/lib/cli/starters/research-team/compose.yaml +38 -0
- package/lib/cli/starters/research-team/dot-dockerignore +7 -0
- package/lib/cli/starters/research-team/dot-env.example +49 -0
- package/lib/cli/starters/research-team/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/research-team/dot-gitignore +10 -0
- package/lib/cli/starters/research-team/mayura.project.json +22 -0
- package/lib/cli/starters/research-team/package.json +30 -0
- package/lib/cli/starters/research-team/src/app.ts +19 -0
- package/lib/cli/starters/research-team/src/auth.ts +56 -0
- package/lib/cli/starters/research-team/src/config.ts +170 -0
- package/lib/cli/starters/research-team/src/desk.ts +124 -0
- package/lib/cli/starters/research-team/src/dev.ts +58 -0
- package/lib/cli/starters/research-team/src/library/corpus.ts +76 -0
- package/lib/cli/starters/research-team/src/library/index.ts +109 -0
- package/lib/cli/starters/research-team/src/model.ts +33 -0
- package/lib/cli/starters/research-team/src/server.ts +69 -0
- package/lib/cli/starters/research-team/src/services.ts +48 -0
- package/lib/cli/starters/research-team/src/team.ts +173 -0
- package/lib/cli/starters/research-team/src/telemetry.ts +95 -0
- package/lib/cli/starters/research-team/src/token.ts +6 -0
- package/lib/cli/starters/research-team/src/worker.ts +21 -0
- package/lib/cli/starters/research-team/src/workflow.ts +197 -0
- package/lib/cli/starters/research-team/test/research.test.ts +271 -0
- package/lib/cli/starters/research-team/tsconfig.json +20 -0
- package/lib/cli/starters/support-agent/Dockerfile +21 -0
- package/lib/cli/starters/support-agent/README.md +128 -0
- package/lib/cli/starters/support-agent/compose.yaml +33 -0
- package/lib/cli/starters/support-agent/dot-dockerignore +7 -0
- package/lib/cli/starters/support-agent/dot-env.example +44 -0
- package/lib/cli/starters/support-agent/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/support-agent/dot-gitignore +10 -0
- package/lib/cli/starters/support-agent/mayura.project.json +18 -0
- package/lib/cli/starters/support-agent/package.json +43 -0
- package/lib/cli/starters/support-agent/src/app.ts +19 -0
- package/lib/cli/starters/support-agent/src/assistant.ts +313 -0
- package/lib/cli/starters/support-agent/src/auth.ts +69 -0
- package/lib/cli/starters/support-agent/src/config.ts +120 -0
- package/lib/cli/starters/support-agent/src/dev.ts +115 -0
- package/lib/cli/starters/support-agent/src/guardrails.ts +71 -0
- package/lib/cli/starters/support-agent/src/model.ts +33 -0
- package/lib/cli/starters/support-agent/src/orders.ts +62 -0
- package/lib/cli/starters/support-agent/src/returns.ts +86 -0
- package/lib/cli/starters/support-agent/src/server.ts +72 -0
- package/lib/cli/starters/support-agent/src/services.ts +32 -0
- package/lib/cli/starters/support-agent/src/session.ts +55 -0
- package/lib/cli/starters/support-agent/src/token.ts +9 -0
- package/lib/cli/starters/support-agent/src/worker.ts +19 -0
- package/lib/cli/starters/support-agent/test/support.test.ts +263 -0
- package/lib/cli/starters/support-agent/tsconfig.json +20 -0
- package/lib/cli/starters/support-agent/web/index.html +12 -0
- package/lib/cli/starters/support-agent/web/src/App.tsx +43 -0
- package/lib/cli/starters/support-agent/web/src/components/chat.tsx +161 -0
- package/lib/cli/starters/support-agent/web/src/components/ui/button.tsx +33 -0
- package/lib/cli/starters/support-agent/web/src/components/ui/primitives.tsx +48 -0
- package/lib/cli/starters/support-agent/web/src/env.d.ts +1 -0
- package/lib/cli/starters/support-agent/web/src/lib/api.ts +56 -0
- package/lib/cli/starters/support-agent/web/src/lib/utils.ts +4 -0
- package/lib/cli/starters/support-agent/web/src/main.tsx +6 -0
- package/lib/cli/starters/support-agent/web/src/styles.css +86 -0
- package/lib/cli/starters/support-agent/web/tsconfig.json +9 -0
- package/lib/cli/starters/support-agent/web/vite.config.ts +13 -0
- package/lib/cli/templates/basic-agent.ts +10 -0
- package/lib/cli/templates/capability-policy.ts +18 -0
- package/lib/cli/templates/code-mode-workflow.ts +34 -0
- package/lib/cli/templates/durable-approval.ts +25 -0
- package/lib/cli/templates/guarded-streaming-app.ts +23 -0
- package/lib/cli/templates/native-memory.ts +15 -0
- package/lib/cli/templates/parallel-research.ts +21 -0
- package/lib/cli/templates/typed-tool-runner.ts +15 -0
- package/lib/client/dist/forms.d.ts +77 -0
- package/lib/client/dist/forms.d.ts.map +1 -0
- package/lib/client/dist/forms.js +282 -0
- package/lib/client/dist/forms.js.map +1 -0
- package/lib/client/dist/headless.d.ts +84 -0
- package/lib/client/dist/headless.d.ts.map +1 -0
- package/lib/client/dist/headless.js +376 -0
- package/lib/client/dist/headless.js.map +1 -0
- package/lib/client/dist/index.d.ts +266 -0
- package/lib/client/dist/index.d.ts.map +1 -0
- package/lib/client/dist/index.js +814 -0
- package/lib/client/dist/index.js.map +1 -0
- package/lib/client/dist/workflows.d.ts +128 -0
- package/lib/client/dist/workflows.d.ts.map +1 -0
- package/lib/client/dist/workflows.js +379 -0
- package/lib/client/dist/workflows.js.map +1 -0
- package/lib/client/package.json +5 -0
- package/lib/client/src/forms.ts +215 -0
- package/lib/client/src/headless.ts +265 -0
- package/lib/client/src/index.ts +646 -0
- package/lib/client/src/workflows.ts +307 -0
- package/lib/client-react/dist/components.d.ts +70 -0
- package/lib/client-react/dist/components.d.ts.map +1 -0
- package/lib/client-react/dist/components.js +173 -0
- package/lib/client-react/dist/components.js.map +1 -0
- package/lib/client-react/dist/index.d.ts +29 -0
- package/lib/client-react/dist/index.d.ts.map +1 -0
- package/lib/client-react/dist/index.js +57 -0
- package/lib/client-react/dist/index.js.map +1 -0
- package/lib/client-react/package.json +5 -0
- package/lib/client-react/src/components.ts +183 -0
- package/lib/client-react/src/index.ts +70 -0
- package/lib/code-mode/dist/index.d.ts +142 -0
- package/lib/code-mode/dist/index.d.ts.map +1 -0
- package/lib/code-mode/dist/index.js +498 -0
- package/lib/code-mode/dist/index.js.map +1 -0
- package/lib/code-mode/package.json +5 -0
- package/lib/code-mode/src/index.ts +605 -0
- package/lib/code-mode-workflows/dist/index.d.ts +51 -0
- package/lib/code-mode-workflows/dist/index.d.ts.map +1 -0
- package/lib/code-mode-workflows/dist/index.js +231 -0
- package/lib/code-mode-workflows/dist/index.js.map +1 -0
- package/lib/code-mode-workflows/package.json +5 -0
- package/lib/code-mode-workflows/src/index.ts +259 -0
- package/lib/context/dist/assemble.d.ts +11 -0
- package/lib/context/dist/assemble.d.ts.map +1 -0
- package/lib/context/dist/assemble.js +265 -0
- package/lib/context/dist/assemble.js.map +1 -0
- package/lib/context/dist/cache.d.ts +53 -0
- package/lib/context/dist/cache.d.ts.map +1 -0
- package/lib/context/dist/cache.js +147 -0
- package/lib/context/dist/cache.js.map +1 -0
- package/lib/context/dist/contracts.d.ts +145 -0
- package/lib/context/dist/contracts.d.ts.map +1 -0
- package/lib/context/dist/contracts.js +2 -0
- package/lib/context/dist/contracts.js.map +1 -0
- package/lib/context/dist/index.d.ts +4 -0
- package/lib/context/dist/index.d.ts.map +1 -0
- package/lib/context/dist/index.js +3 -0
- package/lib/context/dist/index.js.map +1 -0
- package/lib/context/package.json +5 -0
- package/lib/context/src/assemble.ts +205 -0
- package/lib/context/src/cache.ts +143 -0
- package/lib/context/src/contracts.ts +124 -0
- package/lib/context/src/index.ts +3 -0
- package/lib/core/dist/budget.d.ts +85 -0
- package/lib/core/dist/budget.d.ts.map +1 -0
- package/lib/core/dist/budget.js +328 -0
- package/lib/core/dist/budget.js.map +1 -0
- package/lib/core/dist/contracts.d.ts +156 -0
- package/lib/core/dist/contracts.d.ts.map +1 -0
- package/lib/core/dist/contracts.js +13 -0
- package/lib/core/dist/contracts.js.map +1 -0
- package/lib/core/dist/errors.d.ts +17 -0
- package/lib/core/dist/errors.d.ts.map +1 -0
- package/lib/core/dist/errors.js +22 -0
- package/lib/core/dist/errors.js.map +1 -0
- package/lib/core/dist/event-stream.d.ts +26 -0
- package/lib/core/dist/event-stream.d.ts.map +1 -0
- package/lib/core/dist/event-stream.js +116 -0
- package/lib/core/dist/event-stream.js.map +1 -0
- package/lib/core/dist/host.d.ts +7 -0
- package/lib/core/dist/host.d.ts.map +1 -0
- package/lib/core/dist/host.js +7 -0
- package/lib/core/dist/host.js.map +1 -0
- package/lib/core/dist/index.d.ts +8 -0
- package/lib/core/dist/index.d.ts.map +1 -0
- package/lib/core/dist/index.js +7 -0
- package/lib/core/dist/index.js.map +1 -0
- package/lib/core/dist/json.d.ts +18 -0
- package/lib/core/dist/json.d.ts.map +1 -0
- package/lib/core/dist/json.js +100 -0
- package/lib/core/dist/json.js.map +1 -0
- package/lib/core/dist/lifecycle.d.ts +45 -0
- package/lib/core/dist/lifecycle.d.ts.map +1 -0
- package/lib/core/dist/lifecycle.js +114 -0
- package/lib/core/dist/lifecycle.js.map +1 -0
- package/lib/core/dist/local-guards.d.ts +4 -0
- package/lib/core/dist/local-guards.d.ts.map +1 -0
- package/lib/core/dist/local-guards.js +47 -0
- package/lib/core/dist/local-guards.js.map +1 -0
- package/lib/core/dist/managed-guards.d.ts +44 -0
- package/lib/core/dist/managed-guards.d.ts.map +1 -0
- package/lib/core/dist/managed-guards.js +146 -0
- package/lib/core/dist/managed-guards.js.map +1 -0
- package/lib/core/dist/schema.d.ts +36 -0
- package/lib/core/dist/schema.d.ts.map +1 -0
- package/lib/core/dist/schema.js +24 -0
- package/lib/core/dist/schema.js.map +1 -0
- package/lib/core/package.json +5 -0
- package/lib/core/src/budget.ts +366 -0
- package/lib/core/src/contracts.ts +107 -0
- package/lib/core/src/errors.ts +33 -0
- package/lib/core/src/event-stream.ts +87 -0
- package/lib/core/src/host.ts +6 -0
- package/lib/core/src/index.ts +7 -0
- package/lib/core/src/json.ts +81 -0
- package/lib/core/src/lifecycle.ts +133 -0
- package/lib/core/src/local-guards.ts +37 -0
- package/lib/core/src/managed-guards.ts +154 -0
- package/lib/core/src/schema.ts +43 -0
- package/lib/exporter-otlp/dist/contracts.d.ts +112 -0
- package/lib/exporter-otlp/dist/contracts.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/contracts.js +2 -0
- package/lib/exporter-otlp/dist/contracts.js.map +1 -0
- package/lib/exporter-otlp/dist/index.d.ts +5 -0
- package/lib/exporter-otlp/dist/index.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/index.js +4 -0
- package/lib/exporter-otlp/dist/index.js.map +1 -0
- package/lib/exporter-otlp/dist/otlp-http-json.d.ts +4 -0
- package/lib/exporter-otlp/dist/otlp-http-json.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js +286 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -0
- package/lib/exporter-otlp/dist/run-traces.d.ts +15 -0
- package/lib/exporter-otlp/dist/run-traces.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/run-traces.js +114 -0
- package/lib/exporter-otlp/dist/run-traces.js.map +1 -0
- package/lib/exporter-otlp/dist/signals.d.ts +4 -0
- package/lib/exporter-otlp/dist/signals.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/signals.js +330 -0
- package/lib/exporter-otlp/dist/signals.js.map +1 -0
- package/lib/exporter-otlp/package.json +5 -0
- package/lib/exporter-otlp/src/contracts.ts +119 -0
- package/lib/exporter-otlp/src/index.ts +23 -0
- package/lib/exporter-otlp/src/otlp-http-json.ts +189 -0
- package/lib/exporter-otlp/src/run-traces.ts +86 -0
- package/lib/exporter-otlp/src/signals.ts +185 -0
- package/lib/guardrails/dist/agent-guard.d.ts +9 -0
- package/lib/guardrails/dist/agent-guard.d.ts.map +1 -0
- package/lib/guardrails/dist/agent-guard.js +23 -0
- package/lib/guardrails/dist/agent-guard.js.map +1 -0
- package/lib/guardrails/dist/auxiliary-helpers.d.ts +63 -0
- package/lib/guardrails/dist/auxiliary-helpers.d.ts.map +1 -0
- package/lib/guardrails/dist/auxiliary-helpers.js +147 -0
- package/lib/guardrails/dist/auxiliary-helpers.js.map +1 -0
- package/lib/guardrails/dist/auxiliary.d.ts +51 -0
- package/lib/guardrails/dist/auxiliary.d.ts.map +1 -0
- package/lib/guardrails/dist/auxiliary.js +230 -0
- package/lib/guardrails/dist/auxiliary.js.map +1 -0
- package/lib/guardrails/dist/batches.d.ts +18 -0
- package/lib/guardrails/dist/batches.d.ts.map +1 -0
- package/lib/guardrails/dist/batches.js +160 -0
- package/lib/guardrails/dist/batches.js.map +1 -0
- package/lib/guardrails/dist/disclosure.d.ts +30 -0
- package/lib/guardrails/dist/disclosure.d.ts.map +1 -0
- package/lib/guardrails/dist/disclosure.js +109 -0
- package/lib/guardrails/dist/disclosure.js.map +1 -0
- package/lib/guardrails/dist/helpers.d.ts +20 -0
- package/lib/guardrails/dist/helpers.d.ts.map +1 -0
- package/lib/guardrails/dist/helpers.js +72 -0
- package/lib/guardrails/dist/helpers.js.map +1 -0
- package/lib/guardrails/dist/index.d.ts +9 -0
- package/lib/guardrails/dist/index.d.ts.map +1 -0
- package/lib/guardrails/dist/index.js +9 -0
- package/lib/guardrails/dist/index.js.map +1 -0
- package/lib/guardrails/dist/managed.d.ts +18 -0
- package/lib/guardrails/dist/managed.d.ts.map +1 -0
- package/lib/guardrails/dist/managed.js +67 -0
- package/lib/guardrails/dist/managed.js.map +1 -0
- package/lib/guardrails/dist/pipeline.d.ts +55 -0
- package/lib/guardrails/dist/pipeline.d.ts.map +1 -0
- package/lib/guardrails/dist/pipeline.js +201 -0
- package/lib/guardrails/dist/pipeline.js.map +1 -0
- package/lib/guardrails/package.json +5 -0
- package/lib/guardrails/src/agent-guard.ts +22 -0
- package/lib/guardrails/src/auxiliary-helpers.ts +146 -0
- package/lib/guardrails/src/auxiliary.ts +202 -0
- package/lib/guardrails/src/batches.ts +130 -0
- package/lib/guardrails/src/disclosure.ts +92 -0
- package/lib/guardrails/src/helpers.ts +67 -0
- package/lib/guardrails/src/index.ts +8 -0
- package/lib/guardrails/src/managed.ts +64 -0
- package/lib/guardrails/src/pipeline.ts +185 -0
- package/lib/helpers/dist/concurrency.d.ts +25 -0
- package/lib/helpers/dist/concurrency.d.ts.map +1 -0
- package/lib/helpers/dist/concurrency.js +106 -0
- package/lib/helpers/dist/concurrency.js.map +1 -0
- package/lib/helpers/dist/configuration.d.ts +42 -0
- package/lib/helpers/dist/configuration.d.ts.map +1 -0
- package/lib/helpers/dist/configuration.js +119 -0
- package/lib/helpers/dist/configuration.js.map +1 -0
- package/lib/helpers/dist/control.d.ts +61 -0
- package/lib/helpers/dist/control.d.ts.map +1 -0
- package/lib/helpers/dist/control.js +220 -0
- package/lib/helpers/dist/control.js.map +1 -0
- package/lib/helpers/dist/credentials.d.ts +42 -0
- package/lib/helpers/dist/credentials.d.ts.map +1 -0
- package/lib/helpers/dist/credentials.js +126 -0
- package/lib/helpers/dist/credentials.js.map +1 -0
- package/lib/helpers/dist/data.d.ts +30 -0
- package/lib/helpers/dist/data.d.ts.map +1 -0
- package/lib/helpers/dist/data.js +90 -0
- package/lib/helpers/dist/data.js.map +1 -0
- package/lib/helpers/dist/index.d.ts +6 -0
- package/lib/helpers/dist/index.d.ts.map +1 -0
- package/lib/helpers/dist/index.js +6 -0
- package/lib/helpers/dist/index.js.map +1 -0
- package/lib/helpers/package.json +5 -0
- package/lib/helpers/src/concurrency.ts +92 -0
- package/lib/helpers/src/configuration.ts +131 -0
- package/lib/helpers/src/control.ts +231 -0
- package/lib/helpers/src/credentials.ts +113 -0
- package/lib/helpers/src/data.ts +105 -0
- package/lib/helpers/src/index.ts +5 -0
- package/lib/memory/dist/contracts.d.ts +146 -0
- package/lib/memory/dist/contracts.d.ts.map +1 -0
- package/lib/memory/dist/contracts.js +2 -0
- package/lib/memory/dist/contracts.js.map +1 -0
- package/lib/memory/dist/index.d.ts +10 -0
- package/lib/memory/dist/index.d.ts.map +1 -0
- package/lib/memory/dist/index.js +316 -0
- package/lib/memory/dist/index.js.map +1 -0
- package/lib/memory/dist/native.d.ts +157 -0
- package/lib/memory/dist/native.d.ts.map +1 -0
- package/lib/memory/dist/native.js +664 -0
- package/lib/memory/dist/native.js.map +1 -0
- package/lib/memory/dist/validation.d.ts +21 -0
- package/lib/memory/dist/validation.d.ts.map +1 -0
- package/lib/memory/dist/validation.js +123 -0
- package/lib/memory/dist/validation.js.map +1 -0
- package/lib/memory/dist/vectors.d.ts +40 -0
- package/lib/memory/dist/vectors.d.ts.map +1 -0
- package/lib/memory/dist/vectors.js +134 -0
- package/lib/memory/dist/vectors.js.map +1 -0
- package/lib/memory/package.json +5 -0
- package/lib/memory/src/contracts.ts +113 -0
- package/lib/memory/src/index.ts +241 -0
- package/lib/memory/src/native.ts +568 -0
- package/lib/memory/src/validation.ts +103 -0
- package/lib/memory/src/vectors.ts +121 -0
- package/lib/memory-remote/dist/index.d.ts +91 -0
- package/lib/memory-remote/dist/index.d.ts.map +1 -0
- package/lib/memory-remote/dist/index.js +434 -0
- package/lib/memory-remote/dist/index.js.map +1 -0
- package/lib/memory-remote/package.json +5 -0
- package/lib/memory-remote/src/index.ts +367 -0
- package/lib/observability/dist/contracts.d.ts +102 -0
- package/lib/observability/dist/contracts.d.ts.map +1 -0
- package/lib/observability/dist/contracts.js +2 -0
- package/lib/observability/dist/contracts.js.map +1 -0
- package/lib/observability/dist/index.d.ts +5 -0
- package/lib/observability/dist/index.d.ts.map +1 -0
- package/lib/observability/dist/index.js +4 -0
- package/lib/observability/dist/index.js.map +1 -0
- package/lib/observability/dist/observer.d.ts +4 -0
- package/lib/observability/dist/observer.d.ts.map +1 -0
- package/lib/observability/dist/observer.js +354 -0
- package/lib/observability/dist/observer.js.map +1 -0
- package/lib/observability/dist/validation.d.ts +6 -0
- package/lib/observability/dist/validation.d.ts.map +1 -0
- package/lib/observability/dist/validation.js +203 -0
- package/lib/observability/dist/validation.js.map +1 -0
- package/lib/observability/package.json +5 -0
- package/lib/observability/src/contracts.ts +85 -0
- package/lib/observability/src/index.ts +4 -0
- package/lib/observability/src/observer.ts +246 -0
- package/lib/observability/src/validation.ts +132 -0
- package/lib/provider-anthropic/dist/index.d.ts +19 -0
- package/lib/provider-anthropic/dist/index.d.ts.map +1 -0
- package/lib/provider-anthropic/dist/index.js +342 -0
- package/lib/provider-anthropic/dist/index.js.map +1 -0
- package/lib/provider-anthropic/package.json +5 -0
- package/lib/provider-anthropic/src/index.ts +317 -0
- package/lib/provider-openai/dist/index.d.ts +77 -0
- package/lib/provider-openai/dist/index.d.ts.map +1 -0
- package/lib/provider-openai/dist/index.js +577 -0
- package/lib/provider-openai/dist/index.js.map +1 -0
- package/lib/provider-openai/package.json +5 -0
- package/lib/provider-openai/src/index.ts +459 -0
- package/lib/runtime/dist/agent.d.ts +63 -0
- package/lib/runtime/dist/agent.d.ts.map +1 -0
- package/lib/runtime/dist/agent.js +134 -0
- package/lib/runtime/dist/agent.js.map +1 -0
- package/lib/runtime/dist/composition.d.ts +21 -0
- package/lib/runtime/dist/composition.d.ts.map +1 -0
- package/lib/runtime/dist/composition.js +54 -0
- package/lib/runtime/dist/composition.js.map +1 -0
- package/lib/runtime/dist/event-buffer.d.ts +18 -0
- package/lib/runtime/dist/event-buffer.d.ts.map +1 -0
- package/lib/runtime/dist/event-buffer.js +66 -0
- package/lib/runtime/dist/event-buffer.js.map +1 -0
- package/lib/runtime/dist/hook-execution.d.ts +40 -0
- package/lib/runtime/dist/hook-execution.d.ts.map +1 -0
- package/lib/runtime/dist/hook-execution.js +186 -0
- package/lib/runtime/dist/hook-execution.js.map +1 -0
- package/lib/runtime/dist/hooks.d.ts +178 -0
- package/lib/runtime/dist/hooks.d.ts.map +1 -0
- package/lib/runtime/dist/hooks.js +120 -0
- package/lib/runtime/dist/hooks.js.map +1 -0
- package/lib/runtime/dist/index.d.ts +6 -0
- package/lib/runtime/dist/index.d.ts.map +1 -0
- package/lib/runtime/dist/index.js +6 -0
- package/lib/runtime/dist/index.js.map +1 -0
- package/lib/runtime/dist/managed-guards.d.ts +27 -0
- package/lib/runtime/dist/managed-guards.d.ts.map +1 -0
- package/lib/runtime/dist/managed-guards.js +183 -0
- package/lib/runtime/dist/managed-guards.js.map +1 -0
- package/lib/runtime/dist/permits.d.ts +9 -0
- package/lib/runtime/dist/permits.d.ts.map +1 -0
- package/lib/runtime/dist/permits.js +77 -0
- package/lib/runtime/dist/permits.js.map +1 -0
- package/lib/runtime/dist/response.d.ts +8 -0
- package/lib/runtime/dist/response.d.ts.map +1 -0
- package/lib/runtime/dist/response.js +83 -0
- package/lib/runtime/dist/response.js.map +1 -0
- package/lib/runtime/dist/router.d.ts +51 -0
- package/lib/runtime/dist/router.d.ts.map +1 -0
- package/lib/runtime/dist/router.js +181 -0
- package/lib/runtime/dist/router.js.map +1 -0
- package/lib/runtime/dist/runtime.d.ts +98 -0
- package/lib/runtime/dist/runtime.d.ts.map +1 -0
- package/lib/runtime/dist/runtime.js +945 -0
- package/lib/runtime/dist/runtime.js.map +1 -0
- package/lib/runtime/dist/stream.d.ts +25 -0
- package/lib/runtime/dist/stream.d.ts.map +1 -0
- package/lib/runtime/dist/stream.js +226 -0
- package/lib/runtime/dist/stream.js.map +1 -0
- package/lib/runtime/package.json +5 -0
- package/lib/runtime/src/agent.ts +167 -0
- package/lib/runtime/src/composition.ts +63 -0
- package/lib/runtime/src/event-buffer.ts +55 -0
- package/lib/runtime/src/hook-execution.ts +188 -0
- package/lib/runtime/src/hooks.ts +227 -0
- package/lib/runtime/src/index.ts +5 -0
- package/lib/runtime/src/managed-guards.ts +176 -0
- package/lib/runtime/src/permits.ts +65 -0
- package/lib/runtime/src/response.ts +68 -0
- package/lib/runtime/src/router.ts +178 -0
- package/lib/runtime/src/runtime.ts +909 -0
- package/lib/runtime/src/stream.ts +130 -0
- package/lib/sdk/dist/index.d.ts +5 -0
- package/lib/sdk/dist/index.d.ts.map +1 -0
- package/lib/sdk/dist/index.js +5 -0
- package/lib/sdk/dist/index.js.map +1 -0
- package/lib/sdk/package.json +5 -0
- package/lib/sdk/src/index.ts +4 -0
- package/lib/server/dist/index.d.ts +343 -0
- package/lib/server/dist/index.d.ts.map +1 -0
- package/lib/server/dist/index.js +1356 -0
- package/lib/server/dist/index.js.map +1 -0
- package/lib/server/dist/inspector-bundle.d.ts +6 -0
- package/lib/server/dist/inspector-bundle.d.ts.map +1 -0
- package/lib/server/dist/inspector-bundle.js +6 -0
- package/lib/server/dist/inspector-bundle.js.map +1 -0
- package/lib/server/dist/inspector.d.ts +3 -0
- package/lib/server/dist/inspector.d.ts.map +1 -0
- package/lib/server/dist/inspector.js +27 -0
- package/lib/server/dist/inspector.js.map +1 -0
- package/lib/server/package.json +5 -0
- package/lib/server/src/index.ts +1033 -0
- package/lib/server/src/inspector-bundle.ts +5 -0
- package/lib/server/src/inspector.ts +27 -0
- package/lib/server-node/dist/hardening.d.ts +19 -0
- package/lib/server-node/dist/hardening.d.ts.map +1 -0
- package/lib/server-node/dist/hardening.js +79 -0
- package/lib/server-node/dist/hardening.js.map +1 -0
- package/lib/server-node/dist/index.d.ts +18 -0
- package/lib/server-node/dist/index.d.ts.map +1 -0
- package/lib/server-node/dist/index.js +53 -0
- package/lib/server-node/dist/index.js.map +1 -0
- package/lib/server-node/dist/probe.d.ts +13 -0
- package/lib/server-node/dist/probe.d.ts.map +1 -0
- package/lib/server-node/dist/probe.js +44 -0
- package/lib/server-node/dist/probe.js.map +1 -0
- package/lib/server-node/dist/production.d.ts +32 -0
- package/lib/server-node/dist/production.d.ts.map +1 -0
- package/lib/server-node/dist/production.js +125 -0
- package/lib/server-node/dist/production.js.map +1 -0
- package/lib/server-node/package.json +5 -0
- package/lib/server-node/src/hardening.ts +79 -0
- package/lib/server-node/src/index.ts +58 -0
- package/lib/server-node/src/probe.ts +36 -0
- package/lib/server-node/src/production.ts +116 -0
- package/lib/storage/dist/index.d.ts +4 -0
- package/lib/storage/dist/index.d.ts.map +1 -0
- package/lib/storage/dist/index.js +5 -0
- package/lib/storage/dist/index.js.map +1 -0
- package/lib/storage/package.json +5 -0
- package/lib/storage/src/index.ts +5 -0
- package/lib/storage-contracts/dist/contracts.d.ts +69 -0
- package/lib/storage-contracts/dist/contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/contracts.js +15 -0
- package/lib/storage-contracts/dist/contracts.js.map +1 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.d.ts +110 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.js +430 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.d.ts +74 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.js +159 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/index.d.ts +18 -0
- package/lib/storage-contracts/dist/index.d.ts.map +1 -0
- package/lib/storage-contracts/dist/index.js +18 -0
- package/lib/storage-contracts/dist/index.js.map +1 -0
- package/lib/storage-contracts/dist/memory-contracts.d.ts +208 -0
- package/lib/storage-contracts/dist/memory-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/memory-contracts.js +350 -0
- package/lib/storage-contracts/dist/memory-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts +171 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.js +2 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/scheduler-contracts.d.ts +133 -0
- package/lib/storage-contracts/dist/scheduler-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/scheduler-contracts.js +2 -0
- package/lib/storage-contracts/dist/scheduler-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/submission-journal.d.ts +21 -0
- package/lib/storage-contracts/dist/submission-journal.d.ts.map +1 -0
- package/lib/storage-contracts/dist/submission-journal.js +51 -0
- package/lib/storage-contracts/dist/submission-journal.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format2.d.ts +54 -0
- package/lib/storage-contracts/dist/workflow-format2.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format2.js +398 -0
- package/lib/storage-contracts/dist/workflow-format2.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format3.d.ts +20 -0
- package/lib/storage-contracts/dist/workflow-format3.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format3.js +309 -0
- package/lib/storage-contracts/dist/workflow-format3.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format4.d.ts +48 -0
- package/lib/storage-contracts/dist/workflow-format4.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format4.js +132 -0
- package/lib/storage-contracts/dist/workflow-format4.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format5.d.ts +94 -0
- package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format5.js +365 -0
- package/lib/storage-contracts/dist/workflow-format5.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts +69 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.js +2 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.d.ts +45 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.js +101 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.d.ts +52 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.js +134 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.d.ts +52 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.js +235 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts +428 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.js +151 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.d.ts +38 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.js +57 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.js.map +1 -0
- package/lib/storage-contracts/package.json +5 -0
- package/lib/storage-contracts/src/contracts.ts +73 -0
- package/lib/storage-contracts/src/durable-budget-contracts.ts +266 -0
- package/lib/storage-contracts/src/execution-wait-contracts.ts +169 -0
- package/lib/storage-contracts/src/index.ts +17 -0
- package/lib/storage-contracts/src/memory-contracts.ts +322 -0
- package/lib/storage-contracts/src/scheduled-workflow-contracts.ts +88 -0
- package/lib/storage-contracts/src/scheduler-contracts.ts +68 -0
- package/lib/storage-contracts/src/submission-journal.ts +50 -0
- package/lib/storage-contracts/src/workflow-format2.ts +288 -0
- package/lib/storage-contracts/src/workflow-format3.ts +201 -0
- package/lib/storage-contracts/src/workflow-format4.ts +96 -0
- package/lib/storage-contracts/src/workflow-format5.ts +375 -0
- package/lib/storage-contracts/src/workflow-graph-contracts.ts +44 -0
- package/lib/storage-contracts/src/workflow-graph-discovery.ts +107 -0
- package/lib/storage-contracts/src/workflow-loop-format1.ts +102 -0
- package/lib/storage-contracts/src/workflow-saga-format1.ts +165 -0
- package/lib/storage-contracts/src/workflow-tree-contracts.ts +191 -0
- package/lib/storage-contracts/src/workflow-tree-discovery.ts +39 -0
- package/lib/storage-postgres/dist/index.d.ts +2 -0
- package/lib/storage-postgres/dist/index.d.ts.map +1 -0
- package/lib/storage-postgres/dist/index.js +2 -0
- package/lib/storage-postgres/dist/index.js.map +1 -0
- package/lib/storage-postgres/dist/postgres.d.ts +8 -0
- package/lib/storage-postgres/dist/postgres.d.ts.map +1 -0
- package/lib/storage-postgres/dist/postgres.js +233 -0
- package/lib/storage-postgres/dist/postgres.js.map +1 -0
- package/lib/storage-postgres/package.json +5 -0
- package/lib/storage-postgres/src/index.ts +1 -0
- package/lib/storage-postgres/src/postgres.ts +222 -0
- package/lib/storage-sql/dist/aggregate-session.d.ts +31 -0
- package/lib/storage-sql/dist/aggregate-session.d.ts.map +1 -0
- package/lib/storage-sql/dist/aggregate-session.js +78 -0
- package/lib/storage-sql/dist/aggregate-session.js.map +1 -0
- package/lib/storage-sql/dist/contracts.d.ts +2 -0
- package/lib/storage-sql/dist/contracts.d.ts.map +1 -0
- package/lib/storage-sql/dist/contracts.js +3 -0
- package/lib/storage-sql/dist/contracts.js.map +1 -0
- package/lib/storage-sql/dist/durable-budget-database.d.ts +33 -0
- package/lib/storage-sql/dist/durable-budget-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/durable-budget-database.js +191 -0
- package/lib/storage-sql/dist/durable-budget-database.js.map +1 -0
- package/lib/storage-sql/dist/durable-budget-state.d.ts +24 -0
- package/lib/storage-sql/dist/durable-budget-state.d.ts.map +1 -0
- package/lib/storage-sql/dist/durable-budget-state.js +211 -0
- package/lib/storage-sql/dist/durable-budget-state.js.map +1 -0
- package/lib/storage-sql/dist/durable-budget-validation.d.ts +5 -0
- package/lib/storage-sql/dist/durable-budget-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/durable-budget-validation.js +22 -0
- package/lib/storage-sql/dist/durable-budget-validation.js.map +1 -0
- package/lib/storage-sql/dist/execution-completions.d.ts +12 -0
- package/lib/storage-sql/dist/execution-completions.d.ts.map +1 -0
- package/lib/storage-sql/dist/execution-completions.js +60 -0
- package/lib/storage-sql/dist/execution-completions.js.map +1 -0
- package/lib/storage-sql/dist/execution-wait-database.d.ts +22 -0
- package/lib/storage-sql/dist/execution-wait-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/execution-wait-database.js +288 -0
- package/lib/storage-sql/dist/execution-wait-database.js.map +1 -0
- package/lib/storage-sql/dist/execution-wait-validation.d.ts +8 -0
- package/lib/storage-sql/dist/execution-wait-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/execution-wait-validation.js +125 -0
- package/lib/storage-sql/dist/execution-wait-validation.js.map +1 -0
- package/lib/storage-sql/dist/host.d.ts +22 -0
- package/lib/storage-sql/dist/host.d.ts.map +1 -0
- package/lib/storage-sql/dist/host.js +21 -0
- package/lib/storage-sql/dist/host.js.map +1 -0
- package/lib/storage-sql/dist/memory-database.d.ts +24 -0
- package/lib/storage-sql/dist/memory-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/memory-database.js +359 -0
- package/lib/storage-sql/dist/memory-database.js.map +1 -0
- package/lib/storage-sql/dist/scheduled-database.d.ts +74 -0
- package/lib/storage-sql/dist/scheduled-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduled-database.js +1152 -0
- package/lib/storage-sql/dist/scheduled-database.js.map +1 -0
- package/lib/storage-sql/dist/scheduled-validation.d.ts +9 -0
- package/lib/storage-sql/dist/scheduled-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduled-validation.js +200 -0
- package/lib/storage-sql/dist/scheduled-validation.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-contracts.d.ts +2 -0
- package/lib/storage-sql/dist/scheduler-contracts.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduler-contracts.js +3 -0
- package/lib/storage-sql/dist/scheduler-contracts.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-database.d.ts +55 -0
- package/lib/storage-sql/dist/scheduler-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduler-database.js +655 -0
- package/lib/storage-sql/dist/scheduler-database.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-validation.d.ts +22 -0
- package/lib/storage-sql/dist/scheduler-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduler-validation.js +201 -0
- package/lib/storage-sql/dist/scheduler-validation.js.map +1 -0
- package/lib/storage-sql/dist/validation.d.ts +14 -0
- package/lib/storage-sql/dist/validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/validation.js +106 -0
- package/lib/storage-sql/dist/validation.js.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.d.ts +7 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.js +55 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.js.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.d.ts +5 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.js +22 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.js.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-database.d.ts +270 -0
- package/lib/storage-sql/dist/workflow-tree-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-database.js +1692 -0
- package/lib/storage-sql/dist/workflow-tree-database.js.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.d.ts +5 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.js +15 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.js.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-validation.d.ts +9 -0
- package/lib/storage-sql/dist/workflow-tree-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-validation.js +576 -0
- package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -0
- package/lib/storage-sql/package.json +5 -0
- package/lib/storage-sql/src/aggregate-session.ts +72 -0
- package/lib/storage-sql/src/contracts.ts +2 -0
- package/lib/storage-sql/src/durable-budget-database.ts +180 -0
- package/lib/storage-sql/src/durable-budget-state.ts +155 -0
- package/lib/storage-sql/src/durable-budget-validation.ts +23 -0
- package/lib/storage-sql/src/execution-completions.ts +58 -0
- package/lib/storage-sql/src/execution-wait-database.ts +219 -0
- package/lib/storage-sql/src/execution-wait-validation.ts +108 -0
- package/lib/storage-sql/src/host.ts +21 -0
- package/lib/storage-sql/src/memory-database.ts +320 -0
- package/lib/storage-sql/src/scheduled-database.ts +811 -0
- package/lib/storage-sql/src/scheduled-validation.ts +89 -0
- package/lib/storage-sql/src/scheduler-contracts.ts +2 -0
- package/lib/storage-sql/src/scheduler-database.ts +475 -0
- package/lib/storage-sql/src/scheduler-validation.ts +112 -0
- package/lib/storage-sql/src/validation.ts +104 -0
- package/lib/storage-sql/src/workflow-graph-discovery-index.ts +60 -0
- package/lib/storage-sql/src/workflow-graph-discovery-validation.ts +21 -0
- package/lib/storage-sql/src/workflow-tree-database.ts +450 -0
- package/lib/storage-sql/src/workflow-tree-discovery-validation.ts +13 -0
- package/lib/storage-sql/src/workflow-tree-validation.ts +166 -0
- package/lib/storage-sqlite/dist/backup.d.ts +24 -0
- package/lib/storage-sqlite/dist/backup.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/backup.js +84 -0
- package/lib/storage-sqlite/dist/backup.js.map +1 -0
- package/lib/storage-sqlite/dist/index.d.ts +4 -0
- package/lib/storage-sqlite/dist/index.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/index.js +4 -0
- package/lib/storage-sqlite/dist/index.js.map +1 -0
- package/lib/storage-sqlite/dist/migrations.d.ts +6 -0
- package/lib/storage-sqlite/dist/migrations.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/migrations.js +50 -0
- package/lib/storage-sqlite/dist/migrations.js.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-database.d.ts +36 -0
- package/lib/storage-sqlite/dist/sqlite-database.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-database.js +179 -0
- package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-worker.d.ts +2 -0
- package/lib/storage-sqlite/dist/sqlite-worker.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-worker.js +95 -0
- package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -0
- package/lib/storage-sqlite/dist/sqlite.d.ts +7 -0
- package/lib/storage-sqlite/dist/sqlite.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/sqlite.js +78 -0
- package/lib/storage-sqlite/dist/sqlite.js.map +1 -0
- package/lib/storage-sqlite/package.json +5 -0
- package/lib/storage-sqlite/src/backup.ts +58 -0
- package/lib/storage-sqlite/src/index.ts +3 -0
- package/lib/storage-sqlite/src/migrations.ts +46 -0
- package/lib/storage-sqlite/src/sqlite-database.ts +172 -0
- package/lib/storage-sqlite/src/sqlite-worker.ts +52 -0
- package/lib/storage-sqlite/src/sqlite.ts +72 -0
- package/lib/testing/dist/index.d.ts +10 -0
- package/lib/testing/dist/index.d.ts.map +1 -0
- package/lib/testing/dist/index.js +24 -0
- package/lib/testing/dist/index.js.map +1 -0
- package/lib/testing/package.json +5 -0
- package/lib/testing/src/index.ts +26 -0
- package/lib/tools/dist/batch.d.ts +71 -0
- package/lib/tools/dist/batch.d.ts.map +1 -0
- package/lib/tools/dist/batch.js +542 -0
- package/lib/tools/dist/batch.js.map +1 -0
- package/lib/tools/dist/budget-binding.d.ts +18 -0
- package/lib/tools/dist/budget-binding.d.ts.map +1 -0
- package/lib/tools/dist/budget-binding.js +65 -0
- package/lib/tools/dist/budget-binding.js.map +1 -0
- package/lib/tools/dist/context.d.ts +17 -0
- package/lib/tools/dist/context.d.ts.map +1 -0
- package/lib/tools/dist/context.js +52 -0
- package/lib/tools/dist/context.js.map +1 -0
- package/lib/tools/dist/host.d.ts +3 -0
- package/lib/tools/dist/host.d.ts.map +1 -0
- package/lib/tools/dist/host.js +3 -0
- package/lib/tools/dist/host.js.map +1 -0
- package/lib/tools/dist/index.d.ts +79 -0
- package/lib/tools/dist/index.d.ts.map +1 -0
- package/lib/tools/dist/index.js +462 -0
- package/lib/tools/dist/index.js.map +1 -0
- package/lib/tools/package.json +5 -0
- package/lib/tools/src/batch.ts +496 -0
- package/lib/tools/src/budget-binding.ts +63 -0
- package/lib/tools/src/context.ts +56 -0
- package/lib/tools/src/host.ts +2 -0
- package/lib/tools/src/index.ts +479 -0
- package/lib/workflows/dist/agents.d.ts +24 -0
- package/lib/workflows/dist/agents.d.ts.map +1 -0
- package/lib/workflows/dist/agents.js +55 -0
- package/lib/workflows/dist/agents.js.map +1 -0
- package/lib/workflows/dist/children-coordinator.d.ts +58 -0
- package/lib/workflows/dist/children-coordinator.d.ts.map +1 -0
- package/lib/workflows/dist/children-coordinator.js +148 -0
- package/lib/workflows/dist/children-coordinator.js.map +1 -0
- package/lib/workflows/dist/children-definition.d.ts +43 -0
- package/lib/workflows/dist/children-definition.d.ts.map +1 -0
- package/lib/workflows/dist/children-definition.js +74 -0
- package/lib/workflows/dist/children-definition.js.map +1 -0
- package/lib/workflows/dist/children-discovery.d.ts +20 -0
- package/lib/workflows/dist/children-discovery.d.ts.map +1 -0
- package/lib/workflows/dist/children-discovery.js +103 -0
- package/lib/workflows/dist/children-discovery.js.map +1 -0
- package/lib/workflows/dist/children-runtime.d.ts +72 -0
- package/lib/workflows/dist/children-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/children-runtime.js +600 -0
- package/lib/workflows/dist/children-runtime.js.map +1 -0
- package/lib/workflows/dist/children.d.ts +9 -0
- package/lib/workflows/dist/children.d.ts.map +1 -0
- package/lib/workflows/dist/children.js +6 -0
- package/lib/workflows/dist/children.js.map +1 -0
- package/lib/workflows/dist/composite-fleet.d.ts +87 -0
- package/lib/workflows/dist/composite-fleet.d.ts.map +1 -0
- package/lib/workflows/dist/composite-fleet.js +259 -0
- package/lib/workflows/dist/composite-fleet.js.map +1 -0
- package/lib/workflows/dist/composite-host.d.ts +45 -0
- package/lib/workflows/dist/composite-host.d.ts.map +1 -0
- package/lib/workflows/dist/composite-host.js +132 -0
- package/lib/workflows/dist/composite-host.js.map +1 -0
- package/lib/workflows/dist/composites.d.ts +4 -0
- package/lib/workflows/dist/composites.d.ts.map +1 -0
- package/lib/workflows/dist/composites.js +3 -0
- package/lib/workflows/dist/composites.js.map +1 -0
- package/lib/workflows/dist/definition.d.ts +61 -0
- package/lib/workflows/dist/definition.d.ts.map +1 -0
- package/lib/workflows/dist/definition.js +112 -0
- package/lib/workflows/dist/definition.js.map +1 -0
- package/lib/workflows/dist/drain.d.ts +21 -0
- package/lib/workflows/dist/drain.d.ts.map +1 -0
- package/lib/workflows/dist/drain.js +53 -0
- package/lib/workflows/dist/drain.js.map +1 -0
- package/lib/workflows/dist/ephemeral.d.ts +24 -0
- package/lib/workflows/dist/ephemeral.d.ts.map +1 -0
- package/lib/workflows/dist/ephemeral.js +122 -0
- package/lib/workflows/dist/ephemeral.js.map +1 -0
- package/lib/workflows/dist/fleet-control.d.ts +129 -0
- package/lib/workflows/dist/fleet-control.d.ts.map +1 -0
- package/lib/workflows/dist/fleet-control.js +356 -0
- package/lib/workflows/dist/fleet-control.js.map +1 -0
- package/lib/workflows/dist/graph-coordinator.d.ts +60 -0
- package/lib/workflows/dist/graph-coordinator.d.ts.map +1 -0
- package/lib/workflows/dist/graph-coordinator.js +266 -0
- package/lib/workflows/dist/graph-coordinator.js.map +1 -0
- package/lib/workflows/dist/graph-definition.d.ts +40 -0
- package/lib/workflows/dist/graph-definition.d.ts.map +1 -0
- package/lib/workflows/dist/graph-definition.js +58 -0
- package/lib/workflows/dist/graph-definition.js.map +1 -0
- package/lib/workflows/dist/graph-discovery.d.ts +27 -0
- package/lib/workflows/dist/graph-discovery.d.ts.map +1 -0
- package/lib/workflows/dist/graph-discovery.js +165 -0
- package/lib/workflows/dist/graph-discovery.js.map +1 -0
- package/lib/workflows/dist/graphs.d.ts +55 -0
- package/lib/workflows/dist/graphs.d.ts.map +1 -0
- package/lib/workflows/dist/graphs.js +10 -0
- package/lib/workflows/dist/graphs.js.map +1 -0
- package/lib/workflows/dist/hook-relay.d.ts +67 -0
- package/lib/workflows/dist/hook-relay.d.ts.map +1 -0
- package/lib/workflows/dist/hook-relay.js +157 -0
- package/lib/workflows/dist/hook-relay.js.map +1 -0
- package/lib/workflows/dist/index.d.ts +16 -0
- package/lib/workflows/dist/index.d.ts.map +1 -0
- package/lib/workflows/dist/index.js +15 -0
- package/lib/workflows/dist/index.js.map +1 -0
- package/lib/workflows/dist/leadership.d.ts +33 -0
- package/lib/workflows/dist/leadership.d.ts.map +1 -0
- package/lib/workflows/dist/leadership.js +109 -0
- package/lib/workflows/dist/leadership.js.map +1 -0
- package/lib/workflows/dist/lifecycle-definition.d.ts +89 -0
- package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-definition.js +137 -0
- package/lib/workflows/dist/lifecycle-definition.js.map +1 -0
- package/lib/workflows/dist/lifecycle-fleet.d.ts +90 -0
- package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-fleet.js +406 -0
- package/lib/workflows/dist/lifecycle-fleet.js.map +1 -0
- package/lib/workflows/dist/lifecycle-host.d.ts +44 -0
- package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-host.js +133 -0
- package/lib/workflows/dist/lifecycle-host.js.map +1 -0
- package/lib/workflows/dist/lifecycle-human-transport.d.ts +67 -0
- package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-human-transport.js +149 -0
- package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -0
- package/lib/workflows/dist/lifecycle-runtime.d.ts +115 -0
- package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-runtime.js +831 -0
- package/lib/workflows/dist/lifecycle-runtime.js.map +1 -0
- package/lib/workflows/dist/lifecycle.d.ts +10 -0
- package/lib/workflows/dist/lifecycle.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle.js +7 -0
- package/lib/workflows/dist/lifecycle.js.map +1 -0
- package/lib/workflows/dist/loop-definition.d.ts +46 -0
- package/lib/workflows/dist/loop-definition.d.ts.map +1 -0
- package/lib/workflows/dist/loop-definition.js +55 -0
- package/lib/workflows/dist/loop-definition.js.map +1 -0
- package/lib/workflows/dist/loop-runtime.d.ts +47 -0
- package/lib/workflows/dist/loop-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/loop-runtime.js +358 -0
- package/lib/workflows/dist/loop-runtime.js.map +1 -0
- package/lib/workflows/dist/loops.d.ts +6 -0
- package/lib/workflows/dist/loops.d.ts.map +1 -0
- package/lib/workflows/dist/loops.js +4 -0
- package/lib/workflows/dist/loops.js.map +1 -0
- package/lib/workflows/dist/migration-service.d.ts +55 -0
- package/lib/workflows/dist/migration-service.d.ts.map +1 -0
- package/lib/workflows/dist/migration-service.js +73 -0
- package/lib/workflows/dist/migration-service.js.map +1 -0
- package/lib/workflows/dist/migration.d.ts +123 -0
- package/lib/workflows/dist/migration.d.ts.map +1 -0
- package/lib/workflows/dist/migration.js +217 -0
- package/lib/workflows/dist/migration.js.map +1 -0
- package/lib/workflows/dist/operator-transports.d.ts +265 -0
- package/lib/workflows/dist/operator-transports.d.ts.map +1 -0
- package/lib/workflows/dist/operator-transports.js +404 -0
- package/lib/workflows/dist/operator-transports.js.map +1 -0
- package/lib/workflows/dist/reconciliation.d.ts +25 -0
- package/lib/workflows/dist/reconciliation.d.ts.map +1 -0
- package/lib/workflows/dist/reconciliation.js +109 -0
- package/lib/workflows/dist/reconciliation.js.map +1 -0
- package/lib/workflows/dist/runtime.d.ts +65 -0
- package/lib/workflows/dist/runtime.d.ts.map +1 -0
- package/lib/workflows/dist/runtime.js +492 -0
- package/lib/workflows/dist/runtime.js.map +1 -0
- package/lib/workflows/dist/saga-definition.d.ts +46 -0
- package/lib/workflows/dist/saga-definition.d.ts.map +1 -0
- package/lib/workflows/dist/saga-definition.js +71 -0
- package/lib/workflows/dist/saga-definition.js.map +1 -0
- package/lib/workflows/dist/saga-runtime.d.ts +51 -0
- package/lib/workflows/dist/saga-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/saga-runtime.js +499 -0
- package/lib/workflows/dist/saga-runtime.js.map +1 -0
- package/lib/workflows/dist/sagas.d.ts +6 -0
- package/lib/workflows/dist/sagas.d.ts.map +1 -0
- package/lib/workflows/dist/sagas.js +4 -0
- package/lib/workflows/dist/sagas.js.map +1 -0
- package/lib/workflows/dist/scheduled-helpers.d.ts +53 -0
- package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -0
- package/lib/workflows/dist/scheduled-helpers.js +230 -0
- package/lib/workflows/dist/scheduled-helpers.js.map +1 -0
- package/lib/workflows/dist/scheduled.d.ts +116 -0
- package/lib/workflows/dist/scheduled.d.ts.map +1 -0
- package/lib/workflows/dist/scheduled.js +781 -0
- package/lib/workflows/dist/scheduled.js.map +1 -0
- package/lib/workflows/dist/traces.d.ts +158 -0
- package/lib/workflows/dist/traces.d.ts.map +1 -0
- package/lib/workflows/dist/traces.js +366 -0
- package/lib/workflows/dist/traces.js.map +1 -0
- package/lib/workflows/dist/versions.d.ts +57 -0
- package/lib/workflows/dist/versions.d.ts.map +1 -0
- package/lib/workflows/dist/versions.js +87 -0
- package/lib/workflows/dist/versions.js.map +1 -0
- package/lib/workflows/dist/worker.d.ts +51 -0
- package/lib/workflows/dist/worker.d.ts.map +1 -0
- package/lib/workflows/dist/worker.js +143 -0
- package/lib/workflows/dist/worker.js.map +1 -0
- package/lib/workflows/package.json +5 -0
- package/lib/workflows/src/agents.ts +65 -0
- package/lib/workflows/src/children-coordinator.ts +50 -0
- package/lib/workflows/src/children-definition.ts +88 -0
- package/lib/workflows/src/children-discovery.ts +32 -0
- package/lib/workflows/src/children-runtime.ts +169 -0
- package/lib/workflows/src/children.ts +12 -0
- package/lib/workflows/src/composite-fleet.ts +155 -0
- package/lib/workflows/src/composite-host.ts +67 -0
- package/lib/workflows/src/composites.ts +6 -0
- package/lib/workflows/src/definition.ts +113 -0
- package/lib/workflows/src/drain.ts +56 -0
- package/lib/workflows/src/ephemeral.ts +124 -0
- package/lib/workflows/src/fleet-control.ts +326 -0
- package/lib/workflows/src/graph-coordinator.ts +223 -0
- package/lib/workflows/src/graph-definition.ts +70 -0
- package/lib/workflows/src/graph-discovery.ts +145 -0
- package/lib/workflows/src/graphs.ts +56 -0
- package/lib/workflows/src/hook-relay.ts +177 -0
- package/lib/workflows/src/index.ts +27 -0
- package/lib/workflows/src/leadership.ts +102 -0
- package/lib/workflows/src/lifecycle-definition.ts +194 -0
- package/lib/workflows/src/lifecycle-fleet.ts +346 -0
- package/lib/workflows/src/lifecycle-host.ts +109 -0
- package/lib/workflows/src/lifecycle-human-transport.ts +170 -0
- package/lib/workflows/src/lifecycle-runtime.ts +673 -0
- package/lib/workflows/src/lifecycle.ts +59 -0
- package/lib/workflows/src/loop-definition.ts +62 -0
- package/lib/workflows/src/loop-runtime.ts +260 -0
- package/lib/workflows/src/loops.ts +7 -0
- package/lib/workflows/src/migration-service.ts +83 -0
- package/lib/workflows/src/migration.ts +242 -0
- package/lib/workflows/src/operator-transports.ts +439 -0
- package/lib/workflows/src/reconciliation.ts +121 -0
- package/lib/workflows/src/runtime.ts +348 -0
- package/lib/workflows/src/saga-definition.ts +104 -0
- package/lib/workflows/src/saga-runtime.ts +406 -0
- package/lib/workflows/src/sagas.ts +24 -0
- package/lib/workflows/src/scheduled-helpers.ts +214 -0
- package/lib/workflows/src/scheduled.ts +707 -0
- package/lib/workflows/src/traces.ts +381 -0
- package/lib/workflows/src/versions.ts +114 -0
- package/lib/workflows/src/worker.ts +115 -0
- package/lib/workstream/dist/executions.d.ts +34 -0
- package/lib/workstream/dist/executions.d.ts.map +1 -0
- package/lib/workstream/dist/executions.js +344 -0
- package/lib/workstream/dist/executions.js.map +1 -0
- package/lib/workstream/dist/humans.d.ts +76 -0
- package/lib/workstream/dist/humans.d.ts.map +1 -0
- package/lib/workstream/dist/humans.js +273 -0
- package/lib/workstream/dist/humans.js.map +1 -0
- package/lib/workstream/dist/index.d.ts +61 -0
- package/lib/workstream/dist/index.d.ts.map +1 -0
- package/lib/workstream/dist/index.js +310 -0
- package/lib/workstream/dist/index.js.map +1 -0
- package/lib/workstream/dist/timers.d.ts +41 -0
- package/lib/workstream/dist/timers.d.ts.map +1 -0
- package/lib/workstream/dist/timers.js +240 -0
- package/lib/workstream/dist/timers.js.map +1 -0
- package/lib/workstream/dist/webhooks.d.ts +69 -0
- package/lib/workstream/dist/webhooks.d.ts.map +1 -0
- package/lib/workstream/dist/webhooks.js +313 -0
- package/lib/workstream/dist/webhooks.js.map +1 -0
- package/lib/workstream/package.json +5 -0
- package/lib/workstream/src/executions.ts +253 -0
- package/lib/workstream/src/humans.ts +323 -0
- package/lib/workstream/src/index.ts +279 -0
- package/lib/workstream/src/timers.ts +212 -0
- package/lib/workstream/src/webhooks.ts +180 -0
- package/package.json +281 -0
|
@@ -0,0 +1,1152 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { jsonValue } from '../../core/dist/index.js';
|
|
3
|
+
import { assertWorkflowStateMatchesManifest, initialWorkflowState, mergeWorkflowReceipt, workflowHashMaterial, workflowManifest, workflowPolicy, workflowResources, workflowState, workflowGraphManifest, workflowGraphState, workflowGraphResources, workflowGraphTargets, initialWorkflowGraphState, assertWorkflowGraphStateMatchesManifest, workflowGraphDiscoveryCommand, workflowGraphDiscoveryPage, } from '../../storage-contracts/dist/index.js';
|
|
4
|
+
import { StorageError } from './contracts.js';
|
|
5
|
+
import { aggregateRecord, createAggregate, initializeOwnership, loadAggregate, lockRunIdentity, lockSql, storageClock, storedInteger, writeAggregate } from './aggregate-session.js';
|
|
6
|
+
import { ResourceBusy, SchedulerDatabase } from './scheduler-database.js';
|
|
7
|
+
import { fields, hash, integer, object } from './scheduler-validation.js';
|
|
8
|
+
import { scheduledCommand } from './scheduled-validation.js';
|
|
9
|
+
import { createCommand, identifier, nextCounter } from './validation.js';
|
|
10
|
+
import { checkCompletion, initializeCompletions, readCompletion } from './execution-completions.js';
|
|
11
|
+
import { initializeWorkflowGraphDiscoveryIndex } from './workflow-graph-discovery-index.js';
|
|
12
|
+
const terminalSteps = new Set(['succeeded', 'failed', 'blocked', 'unknown', 'skipped']);
|
|
13
|
+
const terminalRuns = new Set(['succeeded', 'failed', 'blocked', 'outcome_unknown', 'cancelled']);
|
|
14
|
+
const STALE = Symbol('scheduled-stale');
|
|
15
|
+
const REVIEW_EXPIRED = Symbol('scheduled-review-expired');
|
|
16
|
+
function failed() { throw new StorageError('STORAGE_UNAVAILABLE', 'Stored scheduled workflow failed integrity validation.'); }
|
|
17
|
+
function conflict() { throw new StorageError('CONFLICT', 'Scheduled workflow state or command content changed.'); }
|
|
18
|
+
function limited() { throw new StorageError('LIMIT_EXCEEDED', 'Scheduled workflow history or output limit was reached.'); }
|
|
19
|
+
function digest(domain, value) { return createHash('sha256').update(workflowHashMaterial(domain, value)).digest('hex'); }
|
|
20
|
+
function same(a, b) { return workflowHashMaterial('compare', a) === workflowHashMaterial('compare', b); }
|
|
21
|
+
function graphManifest(manifest) { return 'format' in manifest && manifest.format === 3; }
|
|
22
|
+
function executionSettlement(value, receipt, maximum) {
|
|
23
|
+
const fallback = receipt.execution === 'unknown' ? { knownCostMicros: 0, unknownCostMicros: maximum }
|
|
24
|
+
: receipt.execution === 'not_started' ? { knownCostMicros: 0, unknownCostMicros: 0 }
|
|
25
|
+
: { knownCostMicros: maximum, unknownCostMicros: 0 };
|
|
26
|
+
const result = value ?? fallback;
|
|
27
|
+
if (!Number.isSafeInteger(result.knownCostMicros) || result.knownCostMicros < 0
|
|
28
|
+
|| !Number.isSafeInteger(result.unknownCostMicros) || result.unknownCostMicros < 0
|
|
29
|
+
|| result.knownCostMicros > maximum - result.unknownCostMicros
|
|
30
|
+
|| (receipt.execution !== 'unknown' && result.unknownCostMicros !== 0)
|
|
31
|
+
|| (receipt.execution === 'not_started' && result.knownCostMicros !== 0))
|
|
32
|
+
failed();
|
|
33
|
+
return Object.freeze({ knownCostMicros: result.knownCostMicros, unknownCostMicros: result.unknownCostMicros });
|
|
34
|
+
}
|
|
35
|
+
/** Finite integrated reducer. Every mutation uses its caller-owned connection/transaction. */
|
|
36
|
+
export class ScheduledWorkflowDatabase {
|
|
37
|
+
backend;
|
|
38
|
+
scheduler;
|
|
39
|
+
initialized = false;
|
|
40
|
+
discoveryInitialized = false;
|
|
41
|
+
constructor(backend, scheduler) {
|
|
42
|
+
this.backend = backend;
|
|
43
|
+
this.scheduler = scheduler;
|
|
44
|
+
}
|
|
45
|
+
table(name) { return `${this.backend.prefix}mayura_workflow_${name}`; }
|
|
46
|
+
hashEnrollment(manifest, policy, resources) {
|
|
47
|
+
return { scope: digest('mayura:scope:v1', policy.scope), definition: digest(graphManifest(manifest) ? 'mayura:workflow:v2' : 'mayura:workflow:v1', manifest),
|
|
48
|
+
policy: digest('mayura:policy:v1', policy), resources: digest('mayura:workflow-resources:v1', resources) };
|
|
49
|
+
}
|
|
50
|
+
decode(row, aggregate) {
|
|
51
|
+
try {
|
|
52
|
+
if (![1, 2].includes(Number(row.profile)) || row.scope !== aggregate.scope || row.aggregate_id !== aggregate.id || storedInteger(row.aggregate_version) !== storedInteger(aggregate.version))
|
|
53
|
+
failed();
|
|
54
|
+
const raw = object(JSON.parse(row.data));
|
|
55
|
+
fields(raw, Object.hasOwn(raw, 'lineage') ? ['format', 'manifest', 'policy', 'resources', 'clockFloor', 'commands', 'lineage'] : ['format', 'manifest', 'policy', 'resources', 'clockFloor', 'commands']);
|
|
56
|
+
const lineage = raw['lineage'] === undefined ? undefined : raw['lineage'];
|
|
57
|
+
if (lineage !== undefined && (!Array.isArray(lineage) || lineage.length < 1 || lineage.length > 64 || lineage.some(item => typeof item !== 'string' || !/^[a-f0-9]{64}$/.test(item))))
|
|
58
|
+
failed();
|
|
59
|
+
if (raw['format'] !== Number(row.profile))
|
|
60
|
+
failed();
|
|
61
|
+
integer(raw['clockFloor']);
|
|
62
|
+
const manifest = raw['format'] === 2 ? workflowGraphManifest(raw['manifest']) : workflowManifest(raw['manifest']);
|
|
63
|
+
const policy = workflowPolicy(raw['policy']);
|
|
64
|
+
const resources = graphManifest(manifest) ? workflowGraphResources(raw['resources'], manifest) : workflowResources(raw['resources'], manifest);
|
|
65
|
+
if (!same(manifest, raw['manifest']) || !same(policy, raw['policy']) || !same(resources, raw['resources']))
|
|
66
|
+
failed();
|
|
67
|
+
const hashes = this.hashEnrollment(manifest, policy, resources);
|
|
68
|
+
if (hashes.scope !== aggregate.scope || hashes.definition !== aggregate.definition_hash || hashes.definition !== row.definition_hash || hashes.policy !== row.policy_hash || hashes.resources !== row.resource_hash)
|
|
69
|
+
failed();
|
|
70
|
+
if (!Array.isArray(raw['commands']) || raw['commands'].length > 1024)
|
|
71
|
+
failed();
|
|
72
|
+
const ids = new Set();
|
|
73
|
+
let lastVersion = 0;
|
|
74
|
+
for (const entry of raw['commands']) {
|
|
75
|
+
const command = object(entry);
|
|
76
|
+
fields(command, ['id', 'digest', 'version', 'operation']);
|
|
77
|
+
const id = identifier(command['id'], 'Stored command');
|
|
78
|
+
if (ids.has(id))
|
|
79
|
+
failed();
|
|
80
|
+
ids.add(id);
|
|
81
|
+
hash(command['digest']);
|
|
82
|
+
identifier(command['operation'], 'Stored operation');
|
|
83
|
+
integer(command['version'], 1, storedInteger(aggregate.version));
|
|
84
|
+
if (command['version'] <= lastVersion)
|
|
85
|
+
failed();
|
|
86
|
+
lastVersion = command['version'];
|
|
87
|
+
}
|
|
88
|
+
return { format: raw['format'], manifest, policy, resources, clockFloor: raw['clockFloor'], commands: raw['commands'],
|
|
89
|
+
...(lineage === undefined ? {} : { lineage: lineage }) };
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return failed();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
checkedState(row, owner) {
|
|
96
|
+
try {
|
|
97
|
+
let state;
|
|
98
|
+
if (graphManifest(owner.manifest)) {
|
|
99
|
+
state = workflowGraphState(aggregateRecord(row));
|
|
100
|
+
assertWorkflowGraphStateMatchesManifest(state, owner.manifest);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
state = workflowState(aggregateRecord(row));
|
|
104
|
+
assertWorkflowStateMatchesManifest(state, owner.manifest);
|
|
105
|
+
}
|
|
106
|
+
const hashes = this.hashEnrollment(owner.manifest, owner.policy, owner.resources);
|
|
107
|
+
if (state.definition !== hashes.definition || state.policy !== hashes.policy || state.maxCostMicros !== owner.policy.maxCostMicros)
|
|
108
|
+
failed();
|
|
109
|
+
jsonValue(state.input, { maxBytes: owner.policy.maxOutputBytes });
|
|
110
|
+
jsonValue(state.output, { maxBytes: owner.policy.maxOutputBytes });
|
|
111
|
+
for (const step of Object.values(state.steps))
|
|
112
|
+
jsonValue(step.output, { maxBytes: owner.policy.maxOutputBytes });
|
|
113
|
+
return state;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return failed();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async load(tx, scope, id, policyHash, skip = false, profile) {
|
|
120
|
+
const row = await loadAggregate(tx, this.backend, scope, id, skip);
|
|
121
|
+
if (!row) {
|
|
122
|
+
if (skip)
|
|
123
|
+
return undefined;
|
|
124
|
+
throw new StorageError('NOT_FOUND', 'Workflow was not found in this scope.');
|
|
125
|
+
}
|
|
126
|
+
const ownerRow = (await tx.query(`SELECT * FROM ${this.table('owners')} WHERE scope = ? AND aggregate_id = ?`, [scope, id]))[0];
|
|
127
|
+
if (!ownerRow)
|
|
128
|
+
throw new StorageError('SCHEDULED_WRITER_REQUIRED', 'The run is not enrolled in scheduled execution.');
|
|
129
|
+
if (profile !== undefined && Number(ownerRow.profile) !== profile)
|
|
130
|
+
conflict();
|
|
131
|
+
const owner = this.decode(ownerRow, row);
|
|
132
|
+
if (ownerRow.policy_hash !== policyHash)
|
|
133
|
+
conflict();
|
|
134
|
+
const state = this.checkedState(row, owner);
|
|
135
|
+
// Lock every bounded owned job before touching any resource. Controls can safely visit them in any order afterwards.
|
|
136
|
+
const jobRows = await tx.query(`SELECT job_id FROM ${this.backend.prefix}mayura_scheduler_jobs WHERE scope = ? AND run_id = ? ORDER BY job_id${lockSql(this.backend)}`, [scope, id]);
|
|
137
|
+
// A control command may release several jobs' holds: acquire those rows in one global key order.
|
|
138
|
+
await tx.query(`SELECT resource_key FROM ${this.backend.prefix}mayura_scheduler_resources WHERE scope = ? AND job_id IN (SELECT job_id FROM ${this.backend.prefix}mayura_scheduler_jobs WHERE scope = ? AND run_id = ?) ORDER BY resource_key${lockSql(this.backend)}`, [scope, scope, id]);
|
|
139
|
+
const links = await tx.query(`SELECT node_id, job_id FROM ${this.table('jobs')} WHERE scope = ? AND aggregate_id = ? ORDER BY job_id`, [scope, id]);
|
|
140
|
+
if (links.length > 128 || links.length !== jobRows.length || links.some((link, index) => link.job_id !== jobRows[index]?.job_id))
|
|
141
|
+
failed();
|
|
142
|
+
const events = [];
|
|
143
|
+
const clock = { value: owner.clockFloor };
|
|
144
|
+
const jobs = [];
|
|
145
|
+
const local = this.scheduler.inSession(tx, id, events, undefined, clock);
|
|
146
|
+
for (const link of links) {
|
|
147
|
+
const job = await local.execute('read', { scope, jobId: link.job_id });
|
|
148
|
+
const node = owner.manifest.graph.find(node => node.id === link.node_id);
|
|
149
|
+
const step = state.steps[link.node_id];
|
|
150
|
+
if (!job || !node || node.kind !== 'tool' || !step || job.nodeId !== node.id || job.runId !== id
|
|
151
|
+
|| (job.definitionHash !== row.definition_hash && !owner.lineage?.includes(job.definitionHash)) || job.candidateHash !== step.candidateHash
|
|
152
|
+
|| job.intent['toolId'] !== node.tool || job.intent['callId'] !== `${id}/${step.callId}`
|
|
153
|
+
|| job.intent['policyHash'] !== policyHash || !same(job.resourceKeys, owner.resources[node.id]))
|
|
154
|
+
failed();
|
|
155
|
+
if (job.state === 'succeeded' && (step.status !== 'succeeded' || !same(step.output, job.output) || !same(step.receipt, job.receipt)))
|
|
156
|
+
failed();
|
|
157
|
+
if (['ready', 'leased'].includes(job.state) && !['pending', 'approved'].includes(step.status))
|
|
158
|
+
failed();
|
|
159
|
+
if (job.state === 'started' && step.status !== 'dispatching')
|
|
160
|
+
failed();
|
|
161
|
+
jobs.push(job);
|
|
162
|
+
}
|
|
163
|
+
for (const [nodeId, step] of Object.entries(state.steps))
|
|
164
|
+
if (step.candidateHash !== null && !links.some(link => link.node_id === nodeId))
|
|
165
|
+
failed();
|
|
166
|
+
clock.value = await storageClock(tx, this.backend, clock.value);
|
|
167
|
+
const waits = graphManifest(owner.manifest) ? workflowGraphTargets(owner.manifest, state.input) : {};
|
|
168
|
+
const run = { row, owner, ownerRow, state, jobs, clock, events, waits, facts: {}, targetFacts: new Map() };
|
|
169
|
+
await this.checkWaitProjection(tx, run);
|
|
170
|
+
await this.checkProjection(tx, run);
|
|
171
|
+
await checkCompletion(tx, this.backend, row, policyHash, state.status, false);
|
|
172
|
+
return run;
|
|
173
|
+
}
|
|
174
|
+
/** Parent-owned immutable edges are recomputed from the admitted input, never trusted as a second authority.
|
|
175
|
+
* Only immutable target facts/identity columns are read here; no target workflow lock is acquired.
|
|
176
|
+
*/
|
|
177
|
+
async checkWaitProjection(tx, run) {
|
|
178
|
+
try {
|
|
179
|
+
const rows = await tx.query(`SELECT * FROM ${this.table('wait_targets')} WHERE scope = ? AND aggregate_id = ? LIMIT 129`, [run.row.scope, run.row.id]);
|
|
180
|
+
const expected = Object.entries(run.waits);
|
|
181
|
+
const count = expected.reduce((total, [, targets]) => total + targets.length, 0);
|
|
182
|
+
if (rows.length !== count || count > 128)
|
|
183
|
+
failed();
|
|
184
|
+
const seen = new Set();
|
|
185
|
+
for (const row of rows) {
|
|
186
|
+
const ordinal = storedInteger(row.ordinal);
|
|
187
|
+
const reference = run.waits[row.node_id]?.[ordinal];
|
|
188
|
+
const key = JSON.stringify([row.node_id, ordinal]);
|
|
189
|
+
if (seen.has(key))
|
|
190
|
+
failed();
|
|
191
|
+
seen.add(key);
|
|
192
|
+
if (!reference || row.scope !== run.row.scope || row.aggregate_id !== run.row.id || row.run_id !== reference.runId
|
|
193
|
+
|| row.definition_hash !== reference.definitionHash || row.policy_hash !== reference.policyHash
|
|
194
|
+
|| row.policy_hash !== run.ownerRow.policy_hash || row.run_id === run.row.id)
|
|
195
|
+
failed();
|
|
196
|
+
}
|
|
197
|
+
const facts = {};
|
|
198
|
+
for (const [nodeId, targets] of expected) {
|
|
199
|
+
const observations = [];
|
|
200
|
+
let complete = true;
|
|
201
|
+
for (const reference of targets) {
|
|
202
|
+
const key = JSON.stringify([reference.kind, reference.runId, reference.definitionHash, reference.policyHash]);
|
|
203
|
+
if (!run.targetFacts.has(key)) {
|
|
204
|
+
await this.checkTargetIdentity(tx, run.row.scope, run.row.id, run.ownerRow.policy_hash, reference);
|
|
205
|
+
run.targetFacts.set(key, await readCompletion(tx, this.backend, run.row.scope, reference));
|
|
206
|
+
}
|
|
207
|
+
// Repeated edges retain independent row/order checks above. Only immutable identities
|
|
208
|
+
// and facts share this command-local observation; no target business lock is acquired.
|
|
209
|
+
const fact = run.targetFacts.get(key);
|
|
210
|
+
if (fact)
|
|
211
|
+
observations.push(fact);
|
|
212
|
+
else
|
|
213
|
+
complete = false;
|
|
214
|
+
}
|
|
215
|
+
facts[nodeId] = complete ? observations : undefined;
|
|
216
|
+
const step = run.state.steps[nodeId];
|
|
217
|
+
// A wait can fail only after a complete observation fails output admission.
|
|
218
|
+
// It cannot fabricate terminal failure while any target is still pending.
|
|
219
|
+
if (step?.status === 'failed' && !complete)
|
|
220
|
+
failed();
|
|
221
|
+
if (!step || step.kind !== 'wait' || run.jobs.some(job => job.nodeId === nodeId)
|
|
222
|
+
|| step.receipt !== null || step.approval !== null || step.candidateHash !== null || step.costReserved !== 0)
|
|
223
|
+
failed();
|
|
224
|
+
if (step.status === 'succeeded' && (!complete || !same(step.output, observations)))
|
|
225
|
+
failed();
|
|
226
|
+
}
|
|
227
|
+
run.facts = facts;
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
failed();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** Verify already-existing immutable owner identities without taking target business locks. */
|
|
234
|
+
async checkTargetIdentity(tx, scope, parentId, policyHash, reference) {
|
|
235
|
+
if (reference.runId === parentId || reference.policyHash !== policyHash)
|
|
236
|
+
conflict();
|
|
237
|
+
const row = (await tx.query(`SELECT scope,aggregate_id,profile,definition_hash,policy_hash FROM ${this.table('owners')} WHERE scope = ? AND aggregate_id = ?`, [scope, reference.runId]))[0];
|
|
238
|
+
if (!row || row.scope !== scope || row.aggregate_id !== reference.runId || ![1, 2].includes(Number(row.profile))
|
|
239
|
+
|| row.definition_hash !== reference.definitionHash || row.policy_hash !== policyHash)
|
|
240
|
+
conflict();
|
|
241
|
+
}
|
|
242
|
+
/** Independently derive effect facts and accounting from the attempt ledger, never from aggregate claims. */
|
|
243
|
+
async checkProjection(tx, run) {
|
|
244
|
+
try {
|
|
245
|
+
let spent = 0;
|
|
246
|
+
for (const node of run.owner.manifest.graph) {
|
|
247
|
+
const step = run.state.steps[node.id];
|
|
248
|
+
const job = run.jobs.find(item => item.nodeId === node.id);
|
|
249
|
+
if (!job) {
|
|
250
|
+
if (step.candidateHash !== null || step.receipt !== null || step.costReserved !== 0 || step.status === 'dispatching' || step.status === 'unknown')
|
|
251
|
+
failed();
|
|
252
|
+
if (node.kind === 'tool' && step.status === 'succeeded')
|
|
253
|
+
failed();
|
|
254
|
+
if (node.kind === 'join' && step.status === 'succeeded' && !same(step.output, node.dependsOn.map(id => run.state.steps[id].output)))
|
|
255
|
+
failed();
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (node.kind !== 'tool' || step.candidateHash === null)
|
|
259
|
+
failed();
|
|
260
|
+
const allowed = {
|
|
261
|
+
ready: [node.approval ? 'approved' : 'pending'], leased: [node.approval ? 'approved' : 'pending'],
|
|
262
|
+
started: ['dispatching'], succeeded: ['succeeded'], failed: ['failed'], blocked: ['blocked'],
|
|
263
|
+
cancelled: ['skipped', 'failed', 'blocked'], outcome_unknown: ['unknown'],
|
|
264
|
+
};
|
|
265
|
+
if (!allowed[job.state].includes(step.status) || (node.approval && !step.approval?.humanId))
|
|
266
|
+
failed();
|
|
267
|
+
const accounting = await this.accounting(tx, run, job, node);
|
|
268
|
+
let projected = accounting?.receipt ?? null;
|
|
269
|
+
if (projected && job.state === 'succeeded')
|
|
270
|
+
projected = { ...projected, disclosure: 'released' };
|
|
271
|
+
if (!same(projected, step.receipt))
|
|
272
|
+
failed();
|
|
273
|
+
const expectedReservation = accounting ? accounting.settlement.unknownCostMicros
|
|
274
|
+
: job.startedAtMs === null && ['cancelled', 'blocked'].includes(job.state) ? 0 : node.costMicros;
|
|
275
|
+
if (step.costReserved !== expectedReservation)
|
|
276
|
+
failed();
|
|
277
|
+
if (accounting)
|
|
278
|
+
spent = nextCounter(spent, accounting.settlement.knownCostMicros);
|
|
279
|
+
}
|
|
280
|
+
if (spent !== run.state.spentMicros || (['succeeded', 'failed', 'blocked', 'outcome_unknown'].includes(run.state.status)
|
|
281
|
+
&& Object.values(run.state.steps).some(step => !terminalSteps.has(step.status))))
|
|
282
|
+
failed();
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
failed();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
snapshot(run) {
|
|
289
|
+
return { record: aggregateRecord(run.row), profile: run.owner.format === 1 ? 'scheduled-v1' : 'scheduled-v2', manifestHash: run.ownerRow.definition_hash,
|
|
290
|
+
policyHash: run.ownerRow.policy_hash, resourceHash: run.ownerRow.resource_hash, jobs: run.jobs };
|
|
291
|
+
}
|
|
292
|
+
/** Reconstruct cost facts from immutable attempt evidence; legacy evidence remains conservatively fixed-cost. */
|
|
293
|
+
async accounting(tx, run, job, node) {
|
|
294
|
+
if (job.fence === 0)
|
|
295
|
+
return undefined;
|
|
296
|
+
const evidence = await this.local(tx, run).execute('receipts', { scope: run.row.scope, jobId: job.jobId, fence: job.fence });
|
|
297
|
+
let projected;
|
|
298
|
+
for (const item of evidence)
|
|
299
|
+
if (item.disposition !== 'conflicting') {
|
|
300
|
+
const current = executionSettlement(item.settlement, item.receipt, node.costMicros);
|
|
301
|
+
if (!projected)
|
|
302
|
+
projected = { receipt: mergeWorkflowReceipt(null, item.receipt), settlement: current };
|
|
303
|
+
else {
|
|
304
|
+
const merged = mergeWorkflowReceipt(projected.receipt, item.receipt);
|
|
305
|
+
if (projected.receipt.execution === 'unknown' && item.receipt.execution !== 'unknown')
|
|
306
|
+
projected = { receipt: merged, settlement: current };
|
|
307
|
+
else if (projected.receipt.execution === 'unknown' && item.receipt.execution === 'unknown' && !same(projected.settlement, current)) {
|
|
308
|
+
const refines = (next, before) => next.knownCostMicros >= before.knownCostMicros
|
|
309
|
+
&& next.unknownCostMicros <= before.unknownCostMicros
|
|
310
|
+
&& next.knownCostMicros + next.unknownCostMicros <= before.knownCostMicros + before.unknownCostMicros;
|
|
311
|
+
if (refines(current, projected.settlement))
|
|
312
|
+
projected = { receipt: merged, settlement: current };
|
|
313
|
+
else if (!refines(projected.settlement, current))
|
|
314
|
+
failed();
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
if (!same(projected.settlement, current) && !(projected.receipt.execution !== 'unknown' && item.receipt.execution === 'unknown'))
|
|
318
|
+
failed();
|
|
319
|
+
projected = { receipt: merged, settlement: projected.settlement };
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return projected && Object.freeze({ receipt: projected.receipt, settlement: projected.settlement });
|
|
324
|
+
}
|
|
325
|
+
local(tx, run, jobId, admissionExpiresAt) {
|
|
326
|
+
return this.scheduler.inSession(tx, run.row.id, run.events, jobId, run.clock, admissionExpiresAt);
|
|
327
|
+
}
|
|
328
|
+
replaceJob(run, job) {
|
|
329
|
+
const index = run.jobs.findIndex(item => item.jobId === job.jobId);
|
|
330
|
+
if (index < 0)
|
|
331
|
+
run.jobs.push(job);
|
|
332
|
+
else
|
|
333
|
+
run.jobs[index] = job;
|
|
334
|
+
run.jobs.sort((a, b) => a.jobId < b.jobId ? -1 : a.jobId > b.jobId ? 1 : 0);
|
|
335
|
+
}
|
|
336
|
+
semantic(method, input) {
|
|
337
|
+
const value = { ...input };
|
|
338
|
+
delete value['expectedVersion'];
|
|
339
|
+
if (value['claim']) {
|
|
340
|
+
const token = { ...value['claim'] };
|
|
341
|
+
delete token['leaseUntilMs'];
|
|
342
|
+
value['claim'] = token;
|
|
343
|
+
}
|
|
344
|
+
return digest('mayura:scheduled-command:v1', { operation: method, ...value });
|
|
345
|
+
}
|
|
346
|
+
retry(run, method, input) {
|
|
347
|
+
if (input['commandId'] === undefined)
|
|
348
|
+
return false;
|
|
349
|
+
const previous = run.owner.commands.find(item => item.id === input['commandId']);
|
|
350
|
+
if (!previous)
|
|
351
|
+
return false;
|
|
352
|
+
if (previous.digest !== this.semantic(method, input) || previous.operation !== method)
|
|
353
|
+
conflict();
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
journal(run, method, input) {
|
|
357
|
+
if (input['commandId'] === undefined)
|
|
358
|
+
return;
|
|
359
|
+
if (run.owner.commands.length >= 1024)
|
|
360
|
+
limited();
|
|
361
|
+
run.owner.commands.push({ id: input['commandId'], digest: this.semantic(method, input), version: nextCounter(storedInteger(run.row.version), 1), operation: method });
|
|
362
|
+
}
|
|
363
|
+
async save(tx, run, method, input, event) {
|
|
364
|
+
if (method && input)
|
|
365
|
+
this.journal(run, method, input);
|
|
366
|
+
if (event)
|
|
367
|
+
run.events.push(event);
|
|
368
|
+
if (run.events.length === 0)
|
|
369
|
+
run.events.push({ type: 'workflow.control', data: { operation: method ?? 'projection' } });
|
|
370
|
+
run.owner.clockFloor = run.clock.value;
|
|
371
|
+
const next = jsonValue(run.state);
|
|
372
|
+
this.checkedState({ ...run.row, state: JSON.stringify(next) }, run.owner);
|
|
373
|
+
await this.checkWaitProjection(tx, run);
|
|
374
|
+
await this.checkProjection(tx, run);
|
|
375
|
+
run.row = await writeAggregate(tx, this.backend, run.row, next, run.events, run.clock.value);
|
|
376
|
+
run.ownerRow.aggregate_version = run.row.version;
|
|
377
|
+
run.ownerRow.data = JSON.stringify(object(run.owner));
|
|
378
|
+
await tx.query(`UPDATE ${this.table('owners')} SET aggregate_version = ?, data = ? WHERE scope = ? AND aggregate_id = ?`, [run.row.version, run.ownerRow.data, run.row.scope, run.row.id]);
|
|
379
|
+
await checkCompletion(tx, this.backend, run.row, run.ownerRow.policy_hash, run.state.status, true);
|
|
380
|
+
run.events.length = 0;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Apply a reviewed migration to a locked, paused run. Everything is re-verified here: the caller's plan is advisory.
|
|
384
|
+
* Steps with scheduler history and non-pending waits must be unchanged; other steps may only be carried unchanged
|
|
385
|
+
* or re-enter as fresh pending steps. No other run may depend on this run's identity.
|
|
386
|
+
*/
|
|
387
|
+
async migrateRun(tx, run, input) {
|
|
388
|
+
const refuse = (message) => { throw new StorageError('CONFLICT', `Migration refused: ${message}`); };
|
|
389
|
+
if (run.state.status !== 'paused')
|
|
390
|
+
refuse('the run must be paused.');
|
|
391
|
+
if (run.jobs.some(job => job.state === 'leased' || job.state === 'started'))
|
|
392
|
+
refuse('a job is leased or started.');
|
|
393
|
+
const dependents = await tx.query(`SELECT aggregate_id FROM ${this.table('wait_targets')} WHERE scope = ? AND run_id = ? LIMIT 1`, [run.row.scope, run.row.id]);
|
|
394
|
+
if (dependents.length)
|
|
395
|
+
refuse('another workflow waits on this run.');
|
|
396
|
+
// Execution waits are optional storage; probe the table without failing the transaction when it was never created.
|
|
397
|
+
const waitTable = `${this.backend.prefix}mayura_execution_wait_targets`;
|
|
398
|
+
const present = this.backend.dialect === 'postgres'
|
|
399
|
+
? (await tx.query('SELECT to_regclass(?)::text AS found', [waitTable]))[0]?.found
|
|
400
|
+
: (await tx.query("SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?", [waitTable]))[0]?.name;
|
|
401
|
+
if (present && (await tx.query(`SELECT run_id FROM ${waitTable} WHERE scope = ? AND run_id = ? LIMIT 1`, [run.row.scope, run.row.id])).length)
|
|
402
|
+
refuse('an execution wait targets this run.');
|
|
403
|
+
const manifest = input['manifest'];
|
|
404
|
+
const resources = input['resources'];
|
|
405
|
+
if (graphManifest(manifest) !== graphManifest(run.owner.manifest))
|
|
406
|
+
refuse('the workflow format cannot change.');
|
|
407
|
+
const hashes = this.hashEnrollment(manifest, run.owner.policy, resources);
|
|
408
|
+
if (hashes.definition === run.ownerRow.definition_hash)
|
|
409
|
+
refuse('the definition is unchanged.');
|
|
410
|
+
const previous = run.state;
|
|
411
|
+
const next = input['state'];
|
|
412
|
+
const checked = graphManifest(manifest) ? workflowGraphState({ id: run.row.id, state: next }) : workflowState({ id: run.row.id, state: next });
|
|
413
|
+
if (checked.definition !== hashes.definition || checked.policy !== previous.policy || checked.maxCostMicros !== previous.maxCostMicros || checked.status !== 'paused'
|
|
414
|
+
|| !same(checked.input, previous.input) || checked.spentMicros !== previous.spentMicros || checked.output !== null)
|
|
415
|
+
refuse('only steps and the definition may change.');
|
|
416
|
+
const oldNodes = new Map(run.owner.manifest.graph.map(node => [node.id, node]));
|
|
417
|
+
const newNodes = new Map(manifest.graph.map(node => [node.id, node]));
|
|
418
|
+
for (const [id, step] of Object.entries(checked.steps)) {
|
|
419
|
+
const before = previous.steps[id];
|
|
420
|
+
const jobbed = run.jobs.some(job => job.nodeId === id);
|
|
421
|
+
if (before && same(step, before)) {
|
|
422
|
+
// Carried unchanged: a step with history must also keep its exact node definition and resources.
|
|
423
|
+
if ((jobbed || !['pending', 'skipped'].includes(before.status)) && (!same(oldNodes.get(id), newNodes.get(id)) || !same(run.owner.resources[id] ?? null, resources[id] ?? null))) {
|
|
424
|
+
if (jobbed || before.status === 'waiting' && before.kind === 'wait')
|
|
425
|
+
refuse(`step "${id}" has execution history and its definition changed.`);
|
|
426
|
+
}
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (jobbed)
|
|
430
|
+
refuse(`step "${id}" has scheduler history and cannot change.`);
|
|
431
|
+
if (before && !['pending', 'waiting', 'approved'].includes(before.status))
|
|
432
|
+
refuse(`settled step "${id}" can only be carried unchanged.`);
|
|
433
|
+
if (step.status !== 'pending' || step.receipt !== null || step.approval !== null || step.candidateHash !== null || step.costReserved !== 0)
|
|
434
|
+
refuse(`step "${id}" must re-enter as a fresh pending step.`);
|
|
435
|
+
}
|
|
436
|
+
for (const [id, before] of Object.entries(previous.steps)) {
|
|
437
|
+
if (Object.hasOwn(checked.steps, id))
|
|
438
|
+
continue;
|
|
439
|
+
if (run.jobs.some(job => job.nodeId === id && !['cancelled'].includes(job.state)) || before.status === 'dispatching' || before.status === 'unknown')
|
|
440
|
+
refuse(`step "${id}" has execution history and cannot be removed.`);
|
|
441
|
+
}
|
|
442
|
+
// Waits: started wait nodes keep identical targets; the target rows are re-projected from the new manifest.
|
|
443
|
+
const waits = graphManifest(manifest) ? workflowGraphTargets(manifest, checked.input) : {};
|
|
444
|
+
for (const [nodeId, targets] of Object.entries(run.waits)) {
|
|
445
|
+
const step = previous.steps[nodeId];
|
|
446
|
+
if (step && step.status !== 'pending' && !same(waits[nodeId] ?? null, targets))
|
|
447
|
+
refuse(`wait "${nodeId}" already started and its targets changed.`);
|
|
448
|
+
}
|
|
449
|
+
await tx.query(`DELETE FROM ${this.table('wait_targets')} WHERE scope = ? AND aggregate_id = ?`, [run.row.scope, run.row.id]);
|
|
450
|
+
for (const [nodeId, targets] of Object.entries(waits))
|
|
451
|
+
for (const [ordinal, target] of targets.entries()) {
|
|
452
|
+
await this.checkTargetIdentity(tx, run.row.scope, run.row.id, run.ownerRow.policy_hash, target);
|
|
453
|
+
await tx.query(`INSERT INTO ${this.table('wait_targets')} (scope,aggregate_id,node_id,ordinal,run_id,definition_hash,policy_hash) VALUES (?,?,?,?,?,?,?)`, [run.row.scope, run.row.id, nodeId, ordinal, target.runId, target.definitionHash, target.policyHash]);
|
|
454
|
+
}
|
|
455
|
+
const lineage = [...(run.owner.lineage ?? []), run.ownerRow.definition_hash];
|
|
456
|
+
if (lineage.length > 64)
|
|
457
|
+
limited();
|
|
458
|
+
run.owner = { ...run.owner, manifest, resources, lineage };
|
|
459
|
+
run.state = checked;
|
|
460
|
+
run.waits = waits;
|
|
461
|
+
run.targetFacts = new Map();
|
|
462
|
+
await tx.query(`UPDATE ${this.backend.prefix}mayura_aggregates SET definition_hash = ? WHERE scope = ? AND id = ?`, [hashes.definition, run.row.scope, run.row.id]);
|
|
463
|
+
await tx.query(`UPDATE ${this.table('owners')} SET definition_hash = ?, resource_hash = ? WHERE scope = ? AND aggregate_id = ?`, [hashes.definition, hashes.resources, run.row.scope, run.row.id]);
|
|
464
|
+
run.row = { ...run.row, definition_hash: hashes.definition };
|
|
465
|
+
run.ownerRow = { ...run.ownerRow, definition_hash: hashes.definition, resource_hash: hashes.resources };
|
|
466
|
+
}
|
|
467
|
+
node(run, id) {
|
|
468
|
+
const node = run.owner.manifest.graph.find(node => node.id === id);
|
|
469
|
+
if (!node || node.kind !== 'tool')
|
|
470
|
+
conflict();
|
|
471
|
+
return node;
|
|
472
|
+
}
|
|
473
|
+
/** A paused run schedules nothing; only recording an already-requested approval is admitted. */
|
|
474
|
+
ready(run, node, allowPaused = false) {
|
|
475
|
+
if (terminalRuns.has(run.state.status) || (run.state.status === 'paused' && !allowPaused)
|
|
476
|
+
|| node.dependsOn.some(id => run.state.steps[id]?.status !== 'succeeded'))
|
|
477
|
+
conflict();
|
|
478
|
+
}
|
|
479
|
+
unprepared(run, node, allowPaused = false) {
|
|
480
|
+
this.ready(run, node, allowPaused);
|
|
481
|
+
const step = run.state.steps[node.id];
|
|
482
|
+
if (run.jobs.some(job => job.nodeId === node.id) || !['pending', 'waiting', 'approved'].includes(step.status) || step.receipt || step.costReserved || step.candidateHash)
|
|
483
|
+
conflict();
|
|
484
|
+
return step;
|
|
485
|
+
}
|
|
486
|
+
authorized(run, node) {
|
|
487
|
+
return [`tool:${node.tool}`, ...node.capabilities, ...(node.effects === 'none' ? [] : [`effect:${node.effects}`])].every(grant => run.owner.policy.permissions.includes(grant));
|
|
488
|
+
}
|
|
489
|
+
candidate(run, node, input, expiresAt) {
|
|
490
|
+
try {
|
|
491
|
+
jsonValue(input, { maxBytes: run.owner.policy.maxOutputBytes });
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
throw new StorageError('INVALID_INPUT', 'Candidate input exceeds the pinned workflow limit.');
|
|
495
|
+
}
|
|
496
|
+
return digest('mayura:approval:v1', { runId: run.row.id, nodeId: node.id, tool: node.tool, toolVersion: node.toolVersion, input, policy: run.ownerRow.policy_hash, expiresAt });
|
|
497
|
+
}
|
|
498
|
+
refund(run, step, executed = false) {
|
|
499
|
+
run.state.reservedMicros -= step.costReserved;
|
|
500
|
+
if (executed)
|
|
501
|
+
run.state.spentMicros = nextCounter(run.state.spentMicros, step.costReserved);
|
|
502
|
+
step.costReserved = 0;
|
|
503
|
+
}
|
|
504
|
+
async refreshJob(tx, run, jobId) {
|
|
505
|
+
const job = await this.local(tx, run).execute('read', { scope: run.row.scope, jobId });
|
|
506
|
+
if (!job)
|
|
507
|
+
failed();
|
|
508
|
+
this.replaceJob(run, job);
|
|
509
|
+
return job;
|
|
510
|
+
}
|
|
511
|
+
job(run, input) {
|
|
512
|
+
const token = input['claim'];
|
|
513
|
+
const id = token?.jobId ?? input['jobId'];
|
|
514
|
+
if (token && token.scope !== run.row.scope)
|
|
515
|
+
conflict();
|
|
516
|
+
const job = run.jobs.find(job => job.jobId === id);
|
|
517
|
+
if (!job)
|
|
518
|
+
conflict();
|
|
519
|
+
return job;
|
|
520
|
+
}
|
|
521
|
+
mirrorJob(run, job) {
|
|
522
|
+
const step = run.state.steps[job.nodeId];
|
|
523
|
+
if (job.state === 'outcome_unknown') {
|
|
524
|
+
step.status = 'unknown';
|
|
525
|
+
step.output = null;
|
|
526
|
+
}
|
|
527
|
+
else if (job.state === 'cancelled' && job.startedAtMs === null) {
|
|
528
|
+
if (!terminalSteps.has(step.status))
|
|
529
|
+
step.status = 'skipped';
|
|
530
|
+
this.refund(run, step);
|
|
531
|
+
}
|
|
532
|
+
else if (job.state === 'blocked' && job.startedAtMs === null) {
|
|
533
|
+
step.status = 'blocked';
|
|
534
|
+
this.refund(run, step);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async cancelJob(tx, run, job, commandId) {
|
|
538
|
+
const result = await this.local(tx, run).execute('cancel', { scope: run.row.scope, jobId: job.jobId, commandId });
|
|
539
|
+
this.replaceJob(run, result);
|
|
540
|
+
this.mirrorJob(run, result);
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
expiredReview(run, job) {
|
|
544
|
+
const node = this.node(run, job.nodeId);
|
|
545
|
+
const review = run.state.steps[node.id].approval;
|
|
546
|
+
return node.approval && (!review || review.expiresAt <= run.clock.value);
|
|
547
|
+
}
|
|
548
|
+
/** Leave room for every future receipt, review identity and control counter before releasing output.
|
|
549
|
+
* A full aggregate must never prevent cancellation or settlement of an already-started effect.
|
|
550
|
+
* Control characters deliberately bound JSON escaping for a maximum-size verified human identity.
|
|
551
|
+
*/
|
|
552
|
+
admitsOutput(run, value, nodeId) {
|
|
553
|
+
try {
|
|
554
|
+
const output = jsonValue(value, { maxBytes: run.owner.policy.maxOutputBytes });
|
|
555
|
+
const steps = {};
|
|
556
|
+
for (const node of run.owner.manifest.graph) {
|
|
557
|
+
const step = { ...run.state.steps[node.id], output: node.id === nodeId ? output : run.state.steps[node.id].output };
|
|
558
|
+
if (node.kind === 'tool') {
|
|
559
|
+
step.status = 'dispatching';
|
|
560
|
+
step.candidateHash = 'f'.repeat(64);
|
|
561
|
+
step.costReserved = Number.MAX_SAFE_INTEGER;
|
|
562
|
+
step.receipt = { callId: `${run.row.id}/${step.callId}`, toolId: node.tool, execution: 'not_started', disclosure: 'withheld' };
|
|
563
|
+
step.approval = node.approval ? { digest: 'f'.repeat(64), expiresAt: Number.MAX_SAFE_INTEGER, humanId: '\u0001'.repeat(256) } : null;
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
step.status = 'succeeded';
|
|
567
|
+
// Every unresolved wait must retain room to settle after earlier tool outputs are admitted.
|
|
568
|
+
// Use the longest terminal spelling and safe-counter widths; references are immutable.
|
|
569
|
+
if (node.kind === 'wait' && node.id !== nodeId && step.output === null)
|
|
570
|
+
step.output = jsonValue(run.waits[node.id].map(reference => ({
|
|
571
|
+
reference, outcome: 'outcome_unknown', sourceVersion: Number.MAX_SAFE_INTEGER, sourceEventSequence: Number.MAX_SAFE_INTEGER,
|
|
572
|
+
})));
|
|
573
|
+
}
|
|
574
|
+
steps[node.id] = step;
|
|
575
|
+
}
|
|
576
|
+
// This is a size/depth/node-count projection only, not a persistable execution state.
|
|
577
|
+
jsonValue({ ...run.state, status: 'outcome_unknown', steps, spentMicros: Number.MAX_SAFE_INTEGER, reservedMicros: Number.MAX_SAFE_INTEGER,
|
|
578
|
+
output: nodeId === undefined ? output : run.state.output });
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
catch {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
async blockExpiredReview(tx, run, job) {
|
|
586
|
+
if (job.startedAtMs !== null || !['ready', 'leased'].includes(job.state) || !this.expiredReview(run, job))
|
|
587
|
+
return false;
|
|
588
|
+
await this.cancelJob(tx, run, job, `review-expired:${job.jobId}`);
|
|
589
|
+
run.state.steps[job.nodeId].status = 'blocked';
|
|
590
|
+
run.events.push({ type: 'approval.expired', data: { nodeId: job.nodeId } });
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
async observeReviewExpiry(tx, run, nodeId) {
|
|
594
|
+
const job = run.jobs.find(item => item.nodeId === nodeId);
|
|
595
|
+
if (job)
|
|
596
|
+
await this.blockExpiredReview(tx, run, job);
|
|
597
|
+
if (run.events.length === 0 && run.clock.value > run.owner.clockFloor)
|
|
598
|
+
run.events.push({ type: 'approval.expiry_observed', data: { nodeId } });
|
|
599
|
+
// A rejected approval is not journaled as a successful command. Its monotonic observation is
|
|
600
|
+
// nevertheless durable, so wall-clock rollback cannot make the same expired digest live again.
|
|
601
|
+
if (run.events.length > 0)
|
|
602
|
+
await this.save(tx, run);
|
|
603
|
+
}
|
|
604
|
+
advance(run) {
|
|
605
|
+
if (terminalRuns.has(run.state.status) || run.state.status === 'paused')
|
|
606
|
+
return;
|
|
607
|
+
for (let pass = 0; pass < run.owner.manifest.graph.length; pass++) {
|
|
608
|
+
let changed = false;
|
|
609
|
+
for (const node of run.owner.manifest.graph) {
|
|
610
|
+
const step = run.state.steps[node.id];
|
|
611
|
+
if (!['pending', 'waiting', 'approved'].includes(step.status) || run.jobs.some(job => job.nodeId === node.id))
|
|
612
|
+
continue;
|
|
613
|
+
const dependencies = node.dependsOn.map(id => run.state.steps[id]);
|
|
614
|
+
if (dependencies.some(step => terminalSteps.has(step.status) && step.status !== 'succeeded')) {
|
|
615
|
+
step.status = 'skipped';
|
|
616
|
+
changed = true;
|
|
617
|
+
run.events.push({ type: 'step.skipped', data: { nodeId: node.id } });
|
|
618
|
+
}
|
|
619
|
+
else if (node.kind === 'join' && dependencies.every(step => step.status === 'succeeded')) {
|
|
620
|
+
const output = dependencies.map(step => step.output);
|
|
621
|
+
if (this.admitsOutput(run, output, node.id)) {
|
|
622
|
+
step.output = output;
|
|
623
|
+
step.status = 'succeeded';
|
|
624
|
+
run.events.push({ type: 'step.completed', data: { nodeId: node.id } });
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
step.output = null;
|
|
628
|
+
step.status = 'failed';
|
|
629
|
+
run.events.push({ type: 'step.failed', data: { nodeId: node.id, reason: 'OUTPUT_LIMIT' } });
|
|
630
|
+
}
|
|
631
|
+
changed = true;
|
|
632
|
+
}
|
|
633
|
+
else if (node.kind === 'wait' && dependencies.every(step => step.status === 'succeeded')) {
|
|
634
|
+
const facts = run.facts[node.id];
|
|
635
|
+
if (facts) {
|
|
636
|
+
const output = jsonValue(facts);
|
|
637
|
+
if (this.admitsOutput(run, output, node.id)) {
|
|
638
|
+
step.output = output;
|
|
639
|
+
step.status = 'succeeded';
|
|
640
|
+
run.events.push({ type: 'workflow.wait_resolved', data: { nodeId: node.id } });
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
step.output = null;
|
|
644
|
+
step.status = 'failed';
|
|
645
|
+
run.events.push({ type: 'step.failed', data: { nodeId: node.id, reason: 'OUTPUT_LIMIT' } });
|
|
646
|
+
}
|
|
647
|
+
changed = true;
|
|
648
|
+
}
|
|
649
|
+
else if (step.status === 'pending') {
|
|
650
|
+
step.status = 'waiting';
|
|
651
|
+
changed = true;
|
|
652
|
+
run.events.push({ type: 'workflow.waiting', data: { nodeId: node.id } });
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (!changed)
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
const steps = Object.values(run.state.steps);
|
|
660
|
+
if (steps.every(step => terminalSteps.has(step.status)) && !steps.every(step => step.status === 'succeeded')) {
|
|
661
|
+
run.state.status = steps.some(step => step.status === 'unknown') ? 'outcome_unknown' : steps.some(step => step.status === 'blocked') ? 'blocked' : 'failed';
|
|
662
|
+
}
|
|
663
|
+
else
|
|
664
|
+
run.state.status = steps.some(step => step.status === 'waiting') && !steps.some(step => step.status === 'dispatching') ? 'waiting' : 'running';
|
|
665
|
+
}
|
|
666
|
+
async initialize() {
|
|
667
|
+
if (this.initialized)
|
|
668
|
+
return;
|
|
669
|
+
await this.scheduler.execute('initialize', {});
|
|
670
|
+
await this.backend.transaction(async (tx) => {
|
|
671
|
+
if (this.backend.dialect === 'postgres')
|
|
672
|
+
await tx.query('SELECT pg_advisory_xact_lock(hashtext(?))', [`mayura:scheduled-schema:${this.backend.prefix}`]);
|
|
673
|
+
await initializeOwnership(tx, this.backend);
|
|
674
|
+
await initializeCompletions(tx, this.backend);
|
|
675
|
+
await tx.query(`CREATE TABLE IF NOT EXISTS ${this.table('jobs')} (scope TEXT NOT NULL, aggregate_id TEXT NOT NULL, node_id TEXT NOT NULL, job_id TEXT NOT NULL,
|
|
676
|
+
PRIMARY KEY(scope,aggregate_id,node_id), UNIQUE(scope,job_id), FOREIGN KEY(scope,aggregate_id) REFERENCES ${this.table('owners')}(scope,aggregate_id),
|
|
677
|
+
FOREIGN KEY(scope,job_id) REFERENCES ${this.backend.prefix}mayura_scheduler_jobs(scope,job_id))`);
|
|
678
|
+
await tx.query(`CREATE TABLE IF NOT EXISTS ${this.table('wait_targets')} (
|
|
679
|
+
scope TEXT NOT NULL, aggregate_id TEXT NOT NULL, node_id TEXT NOT NULL, ordinal INTEGER NOT NULL CHECK(ordinal BETWEEN 0 AND 31),
|
|
680
|
+
run_id TEXT NOT NULL, definition_hash TEXT NOT NULL, policy_hash TEXT NOT NULL,
|
|
681
|
+
PRIMARY KEY(scope,aggregate_id,node_id,ordinal), UNIQUE(scope,aggregate_id,node_id,run_id),
|
|
682
|
+
FOREIGN KEY(scope,aggregate_id) REFERENCES ${this.table('owners')}(scope,aggregate_id))`);
|
|
683
|
+
});
|
|
684
|
+
this.initialized = true;
|
|
685
|
+
}
|
|
686
|
+
/** Discovery provisions its index only when explicitly requested, never as an unindexed fallback. */
|
|
687
|
+
async initializeDiscovery() {
|
|
688
|
+
if (this.discoveryInitialized)
|
|
689
|
+
return;
|
|
690
|
+
await this.initialize();
|
|
691
|
+
await this.backend.transaction(async (tx) => {
|
|
692
|
+
if (this.backend.dialect === 'postgres')
|
|
693
|
+
await tx.query('SELECT pg_advisory_xact_lock(hashtext(?))', [`mayura:scheduled-schema:${this.backend.prefix}`]);
|
|
694
|
+
await initializeWorkflowGraphDiscoveryIndex(tx, this.backend);
|
|
695
|
+
});
|
|
696
|
+
this.discoveryInitialized = true;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Finite recovery hints, not a ready queue or execution grant. Selection releases its transaction
|
|
700
|
+
* before each ordinary parent validation; no two parent locks or mutable target locks overlap.
|
|
701
|
+
*/
|
|
702
|
+
async discover(method, value) {
|
|
703
|
+
const input = workflowGraphDiscoveryCommand(method, value);
|
|
704
|
+
if (method === 'initialize')
|
|
705
|
+
return this.initializeDiscovery();
|
|
706
|
+
if (!this.discoveryInitialized)
|
|
707
|
+
throw new StorageError('STORE_NOT_INITIALIZED', 'Initialize workflow graph discovery before use.');
|
|
708
|
+
const command = input;
|
|
709
|
+
try {
|
|
710
|
+
const afterId = command.cursor?.afterId ?? '';
|
|
711
|
+
const collation = this.backend.dialect === 'postgres' ? '"C"' : 'BINARY';
|
|
712
|
+
const rows = await this.backend.transaction(tx => tx.query(`SELECT aggregate_id FROM ${this.table('owners')} WHERE scope = ? AND policy_hash = ? AND profile = 2
|
|
713
|
+
AND aggregate_id COLLATE ${collation} > ? ORDER BY aggregate_id COLLATE ${collation} LIMIT ?`, [command.scope, command.policyHash, afterId, command.limit]));
|
|
714
|
+
if (rows.length > command.limit)
|
|
715
|
+
failed();
|
|
716
|
+
const candidates = [];
|
|
717
|
+
let previous = afterId;
|
|
718
|
+
for (const row of rows) {
|
|
719
|
+
const id = hash(row.aggregate_id);
|
|
720
|
+
if (id <= previous)
|
|
721
|
+
failed();
|
|
722
|
+
previous = id;
|
|
723
|
+
const candidate = await this.backend.transaction(async (tx) => {
|
|
724
|
+
// Do not use SKIP LOCKED: a selected parent is either validated or fails this entire page.
|
|
725
|
+
const run = await this.load(tx, command.scope, id, command.policyHash, false, 2);
|
|
726
|
+
if (!run)
|
|
727
|
+
failed();
|
|
728
|
+
if (run.state.status !== 'running' && run.state.status !== 'waiting' && run.state.status !== 'paused')
|
|
729
|
+
return undefined;
|
|
730
|
+
return { reference: { kind: 'scheduled-workflow', runId: id, definitionHash: run.row.definition_hash, policyHash: command.policyHash },
|
|
731
|
+
version: storedInteger(run.row.version), status: run.state.status };
|
|
732
|
+
});
|
|
733
|
+
if (candidate)
|
|
734
|
+
candidates.push(candidate);
|
|
735
|
+
}
|
|
736
|
+
return workflowGraphDiscoveryPage({ candidates, examined: rows.length, nextCursor: rows.length === command.limit
|
|
737
|
+
? { format: 1, scope: command.scope, policyHash: command.policyHash, afterId: previous } : null }, command);
|
|
738
|
+
}
|
|
739
|
+
catch {
|
|
740
|
+
return failed();
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/** Internal finite maintenance; validates the full enrolled source before publishing old terminal state. */
|
|
744
|
+
async materializeCompletion(scope, reference) {
|
|
745
|
+
if (!this.initialized)
|
|
746
|
+
throw new StorageError('STORE_NOT_INITIALIZED', 'Initialize scheduled workflow storage first.');
|
|
747
|
+
return this.backend.transaction(async (tx) => {
|
|
748
|
+
const run = await this.load(tx, scope, reference.runId, reference.policyHash);
|
|
749
|
+
if (!run)
|
|
750
|
+
throw new StorageError('NOT_FOUND', 'Workflow was not found in this scope.');
|
|
751
|
+
if (run.row.definition_hash !== reference.definitionHash)
|
|
752
|
+
conflict();
|
|
753
|
+
return checkCompletion(tx, this.backend, run.row, reference.policyHash, run.state.status, true);
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
async enroll(tx, row, input, now) {
|
|
757
|
+
const manifest = input['manifest'];
|
|
758
|
+
const policy = input['policy'];
|
|
759
|
+
const resources = input['resources'];
|
|
760
|
+
const hashes = this.hashEnrollment(manifest, policy, resources);
|
|
761
|
+
if (hashes.scope !== row.scope || hashes.definition !== row.definition_hash)
|
|
762
|
+
conflict();
|
|
763
|
+
const existingState = graphManifest(manifest) ? workflowGraphState(aggregateRecord(row)) : workflowState(aggregateRecord(row));
|
|
764
|
+
if (existingState.policy !== hashes.policy || existingState.maxCostMicros !== policy.maxCostMicros)
|
|
765
|
+
conflict();
|
|
766
|
+
const profile = graphManifest(manifest) ? 2 : 1;
|
|
767
|
+
const owner = { format: profile, manifest, policy, resources, clockFloor: now, commands: [] };
|
|
768
|
+
const state = this.checkedState(row, owner);
|
|
769
|
+
if (state.status !== 'running' || state.spentMicros !== 0 || state.reservedMicros !== 0 || state.output !== null || Object.values(state.steps).some(step => step.status !== 'pending' || step.receipt !== null || step.approval !== null || step.candidateHash !== null || step.costReserved !== 0 || step.output !== null))
|
|
770
|
+
conflict();
|
|
771
|
+
if ((await tx.query(`SELECT job_id FROM ${this.backend.prefix}mayura_scheduler_jobs WHERE scope = ? AND run_id = ? LIMIT 1`, [row.scope, row.id])).length)
|
|
772
|
+
conflict();
|
|
773
|
+
const ownerRow = { scope: row.scope, aggregate_id: row.id, profile, aggregate_version: row.version, definition_hash: hashes.definition, policy_hash: hashes.policy, resource_hash: hashes.resources, data: JSON.stringify(object(owner)) };
|
|
774
|
+
await tx.query(`INSERT INTO ${this.table('owners')} (scope,aggregate_id,profile,aggregate_version,definition_hash,policy_hash,resource_hash,data) VALUES (?,?,?,?,?,?,?,?)`, [row.scope, row.id, profile, row.version, hashes.definition, hashes.policy, hashes.resources, ownerRow.data]);
|
|
775
|
+
const waits = graphManifest(manifest) ? workflowGraphTargets(manifest, state.input) : {};
|
|
776
|
+
return { row, owner, ownerRow, state, jobs: [], clock: { value: now }, events: [], waits, facts: {}, targetFacts: new Map() };
|
|
777
|
+
}
|
|
778
|
+
async submit(input, profile) {
|
|
779
|
+
const manifest = input['manifest'];
|
|
780
|
+
const policy = input['policy'];
|
|
781
|
+
const resources = input['resources'];
|
|
782
|
+
const hashes = this.hashEnrollment(manifest, policy, resources);
|
|
783
|
+
const key = input['idempotencyKey'];
|
|
784
|
+
const id = digest('mayura:run-id:v1', { scope: hashes.scope, submissionKey: key });
|
|
785
|
+
jsonValue(input['input'], { maxBytes: policy.maxOutputBytes });
|
|
786
|
+
const state = graphManifest(manifest) ? initialWorkflowGraphState(manifest, input['input'], hashes.definition, hashes.policy, policy.maxCostMicros)
|
|
787
|
+
: initialWorkflowState(manifest, input['input'], hashes.definition, hashes.policy, policy.maxCostMicros);
|
|
788
|
+
const waits = graphManifest(manifest) ? workflowGraphTargets(manifest, state.input) : {};
|
|
789
|
+
// Resolve every edge before parent creation, using independent target-only transactions.
|
|
790
|
+
// No API may attach or mutate graph edges later, so every edge points to an earlier run.
|
|
791
|
+
for (const targets of Object.values(waits))
|
|
792
|
+
for (const target of targets) {
|
|
793
|
+
if (target.runId === id || target.policyHash !== hashes.policy)
|
|
794
|
+
conflict();
|
|
795
|
+
await this.materializeCompletion(hashes.scope, target);
|
|
796
|
+
}
|
|
797
|
+
return this.backend.transaction(async (tx) => {
|
|
798
|
+
await lockRunIdentity(tx, this.backend, hashes.scope, id);
|
|
799
|
+
await loadAggregate(tx, this.backend, hashes.scope, id);
|
|
800
|
+
const now = await storageClock(tx, this.backend);
|
|
801
|
+
const created = await createAggregate(tx, this.backend, createCommand({ scope: hashes.scope, id, idempotencyKey: key, definitionHash: hashes.definition, state: jsonValue(state), events: [{ type: 'run.created', data: {} }] }), now);
|
|
802
|
+
if (!created.created) {
|
|
803
|
+
const run = await this.load(tx, hashes.scope, id, hashes.policy, false, profile);
|
|
804
|
+
if (!run || run.ownerRow.resource_hash !== hashes.resources)
|
|
805
|
+
conflict();
|
|
806
|
+
return { snapshot: this.snapshot(run), created: false };
|
|
807
|
+
}
|
|
808
|
+
const run = await this.enroll(tx, created.row, input, now);
|
|
809
|
+
for (const [nodeId, targets] of Object.entries(waits)) {
|
|
810
|
+
for (const [ordinal, target] of targets.entries()) {
|
|
811
|
+
await this.checkTargetIdentity(tx, hashes.scope, id, hashes.policy, target);
|
|
812
|
+
await tx.query(`INSERT INTO ${this.table('wait_targets')} (scope,aggregate_id,node_id,ordinal,run_id,definition_hash,policy_hash) VALUES (?,?,?,?,?,?,?)`, [hashes.scope, id, nodeId, ordinal, target.runId, target.definitionHash, target.policyHash]);
|
|
813
|
+
}
|
|
814
|
+
run.events.push({ type: 'workflow.wait_registered', data: { nodeId } });
|
|
815
|
+
}
|
|
816
|
+
if (profile === 2 && !this.admitsOutput(run, null))
|
|
817
|
+
throw new StorageError('LIMIT_EXCEEDED', 'Workflow graph cannot retain its bounded future control evidence.');
|
|
818
|
+
await this.save(tx, run, undefined, undefined, { type: 'workflow.enrolled', data: { profile: profile === 1 ? 'scheduled-v1' : 'scheduled-v2' } });
|
|
819
|
+
return { snapshot: this.snapshot(run), created: true };
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
async execute(method, value, profile = 1) {
|
|
823
|
+
const input = scheduledCommand(method, value, profile);
|
|
824
|
+
if (method === 'initialize')
|
|
825
|
+
return this.initialize();
|
|
826
|
+
if (!this.initialized)
|
|
827
|
+
throw new StorageError('STORE_NOT_INITIALIZED', 'Initialize scheduled workflow storage before use.');
|
|
828
|
+
if (method === 'submit')
|
|
829
|
+
return this.submit(input, profile);
|
|
830
|
+
if (method === 'claim')
|
|
831
|
+
return this.claim(input, profile);
|
|
832
|
+
const result = await this.backend.transaction(async (tx) => {
|
|
833
|
+
const scope = input['scope'];
|
|
834
|
+
const id = input['id'];
|
|
835
|
+
const policyHash = input['policyHash'];
|
|
836
|
+
let run;
|
|
837
|
+
if (method === 'attach') {
|
|
838
|
+
await lockRunIdentity(tx, this.backend, scope, id);
|
|
839
|
+
const row = await loadAggregate(tx, this.backend, scope, id);
|
|
840
|
+
if (!row)
|
|
841
|
+
throw new StorageError('NOT_FOUND', 'Workflow was not found in this scope.');
|
|
842
|
+
const exists = (await tx.query(`SELECT aggregate_id FROM ${this.table('owners')} WHERE scope = ? AND aggregate_id = ?`, [scope, id])).length > 0;
|
|
843
|
+
if (exists) {
|
|
844
|
+
const previous = await this.load(tx, scope, id, policyHash, false, profile);
|
|
845
|
+
if (!previous || !this.retry(previous, method, input))
|
|
846
|
+
conflict();
|
|
847
|
+
return this.snapshot(previous);
|
|
848
|
+
}
|
|
849
|
+
if (storedInteger(row.version) !== input['expectedVersion'])
|
|
850
|
+
conflict();
|
|
851
|
+
const hashes = this.hashEnrollment(input['manifest'], input['policy'], input['resources']);
|
|
852
|
+
if (hashes.policy !== policyHash)
|
|
853
|
+
conflict();
|
|
854
|
+
run = await this.enroll(tx, row, input, await storageClock(tx, this.backend));
|
|
855
|
+
await this.save(tx, run, method, input, { type: 'workflow.enrolled', data: { profile: 'scheduled-v1' } });
|
|
856
|
+
return this.snapshot(run);
|
|
857
|
+
}
|
|
858
|
+
run = (await this.load(tx, scope, id, policyHash, false, profile));
|
|
859
|
+
const originalState = JSON.stringify(run.state);
|
|
860
|
+
if (method === 'inspect')
|
|
861
|
+
return this.snapshot(run);
|
|
862
|
+
if (this.retry(run, method, input))
|
|
863
|
+
return method === 'start' ? { status: 'already_started', snapshot: this.snapshot(run) } : this.snapshot(run);
|
|
864
|
+
if (input['expectedVersion'] !== undefined && input['expectedVersion'] !== storedInteger(run.row.version))
|
|
865
|
+
conflict();
|
|
866
|
+
if (method === 'recordReceipt') {
|
|
867
|
+
const job = this.job(run, input);
|
|
868
|
+
const node = this.node(run, job.nodeId);
|
|
869
|
+
const prior = await this.accounting(tx, run, job, node);
|
|
870
|
+
const result = await this.local(tx, run).execute('recordReceipt', { scope, jobId: job.jobId, fence: input['fence'], evidenceId: input['evidenceId'], receipt: input['receipt'],
|
|
871
|
+
...(input['settlement'] === undefined ? {} : { settlement: input['settlement'] }),
|
|
872
|
+
...(input['source'] === undefined ? {} : { source: input['source'] }) });
|
|
873
|
+
if (run.events.length === 0)
|
|
874
|
+
return this.snapshot(run);
|
|
875
|
+
this.replaceJob(run, result.job);
|
|
876
|
+
const step = run.state.steps[job.nodeId];
|
|
877
|
+
const receipt = input['receipt'];
|
|
878
|
+
if (result.disposition !== 'conflicting') {
|
|
879
|
+
step.receipt = mergeWorkflowReceipt(step.receipt, receipt);
|
|
880
|
+
const projected = await this.accounting(tx, run, result.job, node);
|
|
881
|
+
if (!projected)
|
|
882
|
+
failed();
|
|
883
|
+
const priorKnown = prior?.settlement.knownCostMicros ?? 0;
|
|
884
|
+
if (projected.settlement.knownCostMicros < priorKnown)
|
|
885
|
+
failed();
|
|
886
|
+
run.state.spentMicros = nextCounter(run.state.spentMicros, projected.settlement.knownCostMicros - priorKnown);
|
|
887
|
+
run.state.reservedMicros -= step.costReserved;
|
|
888
|
+
step.costReserved = projected.settlement.unknownCostMicros;
|
|
889
|
+
run.state.reservedMicros = nextCounter(run.state.reservedMicros, step.costReserved);
|
|
890
|
+
}
|
|
891
|
+
this.mirrorJob(run, result.job);
|
|
892
|
+
await this.save(tx, run);
|
|
893
|
+
return this.snapshot(run);
|
|
894
|
+
}
|
|
895
|
+
if (method === 'requestApproval' || method === 'approve' || method === 'prepare' || method === 'failNode') {
|
|
896
|
+
const node = this.node(run, input['nodeId']);
|
|
897
|
+
const previous = run.state.steps[node.id];
|
|
898
|
+
const expired = node.approval && previous.approval !== null && previous.approval.expiresAt <= run.clock.value;
|
|
899
|
+
if (expired && method !== 'failNode' && (method !== 'requestApproval' || run.jobs.some(job => job.nodeId === node.id))) {
|
|
900
|
+
await this.observeReviewExpiry(tx, run, node.id);
|
|
901
|
+
return REVIEW_EXPIRED;
|
|
902
|
+
}
|
|
903
|
+
const step = this.unprepared(run, node, method === 'approve');
|
|
904
|
+
if (method === 'requestApproval') {
|
|
905
|
+
if (!node.approval || !this.authorized(run, node))
|
|
906
|
+
conflict();
|
|
907
|
+
if (step.approval && step.approval.expiresAt > run.clock.value && step.approval.digest === this.candidate(run, node, input['input'], step.approval.expiresAt))
|
|
908
|
+
return this.snapshot(run);
|
|
909
|
+
let expiresAt;
|
|
910
|
+
let candidate;
|
|
911
|
+
try {
|
|
912
|
+
expiresAt = nextCounter(run.clock.value, run.owner.policy.approvalTtlMs);
|
|
913
|
+
candidate = this.candidate(run, node, input['input'], expiresAt);
|
|
914
|
+
}
|
|
915
|
+
catch (error) {
|
|
916
|
+
if (!expired)
|
|
917
|
+
throw error;
|
|
918
|
+
await this.observeReviewExpiry(tx, run, node.id);
|
|
919
|
+
return REVIEW_EXPIRED;
|
|
920
|
+
}
|
|
921
|
+
step.approval = { digest: candidate, expiresAt, humanId: null };
|
|
922
|
+
step.status = 'waiting';
|
|
923
|
+
run.state.status = 'waiting';
|
|
924
|
+
}
|
|
925
|
+
else if (method === 'approve') {
|
|
926
|
+
if (!node.approval || step.status !== 'waiting' || !step.approval || step.approval.digest !== input['digest'] || step.approval.expiresAt <= run.clock.value)
|
|
927
|
+
conflict();
|
|
928
|
+
step.approval.humanId = input['humanId'];
|
|
929
|
+
step.status = 'approved';
|
|
930
|
+
if (run.state.status !== 'paused')
|
|
931
|
+
run.state.status = 'running';
|
|
932
|
+
}
|
|
933
|
+
else if (method === 'failNode') {
|
|
934
|
+
step.status = input['outcome'];
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
if (!this.authorized(run, node))
|
|
938
|
+
conflict();
|
|
939
|
+
const expiresAt = node.approval ? step.approval?.expiresAt ?? 0 : null;
|
|
940
|
+
const candidate = this.candidate(run, node, input['input'], expiresAt);
|
|
941
|
+
if (node.approval && (step.status !== 'approved' || !step.approval?.humanId || step.approval.digest !== candidate || step.approval.expiresAt <= run.clock.value))
|
|
942
|
+
conflict();
|
|
943
|
+
if (node.costMicros > run.state.maxCostMicros - run.state.spentMicros - run.state.reservedMicros) {
|
|
944
|
+
step.status = 'blocked';
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
const jobId = digest('mayura:workflow-job:v1', { scope, id, nodeId: node.id });
|
|
948
|
+
const job = (await this.local(tx, run).execute('reserve', { scope, jobId, reservationKey: jobId, runId: id, nodeId: node.id, invocationId: `${id}/${step.callId}`, definitionHash: run.ownerRow.definition_hash, candidateHash: candidate,
|
|
949
|
+
intent: { toolId: node.tool, callId: `${id}/${step.callId}`, policyHash }, resourceKeys: run.owner.resources[node.id], delayMs: 0 })).job;
|
|
950
|
+
await tx.query(`INSERT INTO ${this.table('jobs')} (scope,aggregate_id,node_id,job_id) VALUES (?,?,?,?)`, [scope, id, node.id, jobId]);
|
|
951
|
+
step.candidateHash = candidate;
|
|
952
|
+
step.costReserved = node.costMicros;
|
|
953
|
+
run.state.reservedMicros = nextCounter(run.state.reservedMicros, node.costMicros);
|
|
954
|
+
this.replaceJob(run, job);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
await this.save(tx, run, method, input, { type: method === 'requestApproval' ? 'approval.requested' : method === 'approve' ? 'approval.resolved' : method === 'prepare' ? 'step.prepared' : 'step.failed', data: { nodeId: node.id } });
|
|
958
|
+
return this.snapshot(run);
|
|
959
|
+
}
|
|
960
|
+
if (method === 'start' || method === 'renew' || method === 'complete' || method === 'abandon') {
|
|
961
|
+
const job = this.job(run, input);
|
|
962
|
+
const token = input['claim'];
|
|
963
|
+
const step = run.state.steps[job.nodeId];
|
|
964
|
+
const node = this.node(run, job.nodeId);
|
|
965
|
+
const admissionExpiresAt = node.approval ? step.approval?.expiresAt ?? 0 : undefined;
|
|
966
|
+
if (method !== 'renew' && terminalRuns.has(run.state.status))
|
|
967
|
+
conflict();
|
|
968
|
+
if (await this.blockExpiredReview(tx, run, job)) {
|
|
969
|
+
await this.save(tx, run);
|
|
970
|
+
return STALE;
|
|
971
|
+
}
|
|
972
|
+
try {
|
|
973
|
+
if (method === 'renew') {
|
|
974
|
+
const renewed = await this.local(tx, run, job.jobId, admissionExpiresAt).execute('renew', { claim: token, leaseMs: input['leaseMs'] });
|
|
975
|
+
await this.refreshJob(tx, run, job.jobId);
|
|
976
|
+
await this.save(tx, run);
|
|
977
|
+
return renewed;
|
|
978
|
+
}
|
|
979
|
+
if (method === 'start') {
|
|
980
|
+
if (!this.authorized(run, node) || this.candidate(run, node, input['input'], node.approval ? step.approval?.expiresAt ?? 0 : null) !== step.candidateHash)
|
|
981
|
+
conflict();
|
|
982
|
+
this.ready(run, node);
|
|
983
|
+
if (node.approval && (step.status !== 'approved' && step.status !== 'dispatching' || !step.approval?.humanId || step.approval.expiresAt <= run.clock.value))
|
|
984
|
+
conflict();
|
|
985
|
+
const started = await this.local(tx, run, job.jobId, admissionExpiresAt).execute('start', { claim: token, candidateHash: step.candidateHash });
|
|
986
|
+
this.replaceJob(run, started.job);
|
|
987
|
+
if (started.status === 'already_started')
|
|
988
|
+
return { status: 'already_started', snapshot: this.snapshot(run) };
|
|
989
|
+
step.status = 'dispatching';
|
|
990
|
+
run.state.status = 'running';
|
|
991
|
+
await this.save(tx, run, method, input, { type: 'step.dispatching', data: { nodeId: node.id } });
|
|
992
|
+
return { status: 'started', snapshot: this.snapshot(run) };
|
|
993
|
+
}
|
|
994
|
+
if (method === 'abandon') {
|
|
995
|
+
// A live renewal validates the precise never-started token without manufacturing a start marker.
|
|
996
|
+
if (job.startedAtMs !== null || job.state !== 'leased')
|
|
997
|
+
conflict();
|
|
998
|
+
await this.local(tx, run, job.jobId, admissionExpiresAt).execute('renew', { claim: token, leaseMs: 1000 });
|
|
999
|
+
await this.cancelJob(tx, run, job, digest('mayura:scheduled-internal-command:v1', { operation: 'abandon', commandId: input['commandId'] }));
|
|
1000
|
+
step.status = input['outcome'];
|
|
1001
|
+
}
|
|
1002
|
+
else {
|
|
1003
|
+
if (step.status !== 'dispatching')
|
|
1004
|
+
conflict();
|
|
1005
|
+
const outputAllowed = input['outcome'] !== 'succeeded' || this.admitsOutput(run, input['output'], node.id);
|
|
1006
|
+
const outcome = outputAllowed ? input['outcome'] : 'blocked';
|
|
1007
|
+
const completed = await this.local(tx, run).execute('complete', { claim: token, commandId: input['commandId'], evidenceId: input['evidenceId'], outcome, output: outcome === 'succeeded' ? input['output'] : null });
|
|
1008
|
+
this.replaceJob(run, completed);
|
|
1009
|
+
step.receipt = completed.receipt;
|
|
1010
|
+
step.status = outcome;
|
|
1011
|
+
step.output = completed.output;
|
|
1012
|
+
if (!outputAllowed)
|
|
1013
|
+
run.events.push({ type: 'step.output_blocked', data: { nodeId: node.id, reason: 'OUTPUT_LIMIT' } });
|
|
1014
|
+
if (step.costReserved > 0 && step.receipt && step.receipt.execution !== 'unknown')
|
|
1015
|
+
this.refund(run, step, step.receipt.execution !== 'not_started');
|
|
1016
|
+
}
|
|
1017
|
+
await this.save(tx, run, method, input, { type: 'step.completed', data: { nodeId: node.id, outcome: step.status } });
|
|
1018
|
+
return this.snapshot(run);
|
|
1019
|
+
}
|
|
1020
|
+
catch (error) {
|
|
1021
|
+
if (!(error instanceof StorageError) || error.code !== 'STALE_CLAIM')
|
|
1022
|
+
throw error;
|
|
1023
|
+
await this.blockExpiredReview(tx, run, job);
|
|
1024
|
+
if (run.events.length > 0) {
|
|
1025
|
+
this.mirrorJob(run, await this.refreshJob(tx, run, job.jobId));
|
|
1026
|
+
await this.save(tx, run);
|
|
1027
|
+
}
|
|
1028
|
+
return STALE;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
if (method === 'cancel') {
|
|
1032
|
+
if (!terminalRuns.has(run.state.status)) {
|
|
1033
|
+
run.state.status = 'cancelled';
|
|
1034
|
+
run.state.output = null;
|
|
1035
|
+
for (const job of [...run.jobs])
|
|
1036
|
+
await this.cancelJob(tx, run, job, digest('mayura:scheduled-internal-command:v1', { operation: 'cancel', commandId: input['commandId'] }));
|
|
1037
|
+
for (const [nodeId, step] of Object.entries(run.state.steps))
|
|
1038
|
+
if (!run.jobs.some(job => job.nodeId === nodeId) && !terminalSteps.has(step.status))
|
|
1039
|
+
step.status = 'skipped';
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
else if (method === 'recover') {
|
|
1043
|
+
for (const job of [...run.jobs]) {
|
|
1044
|
+
if (await this.blockExpiredReview(tx, run, job))
|
|
1045
|
+
continue;
|
|
1046
|
+
const recovered = await this.local(tx, run, job.jobId).execute('recover', { scope, limit: 1 });
|
|
1047
|
+
for (const item of recovered) {
|
|
1048
|
+
this.replaceJob(run, item);
|
|
1049
|
+
this.mirrorJob(run, item);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
this.advance(run);
|
|
1053
|
+
}
|
|
1054
|
+
else if (method === 'pause') {
|
|
1055
|
+
if (run.state.status !== 'paused') {
|
|
1056
|
+
if (terminalRuns.has(run.state.status))
|
|
1057
|
+
conflict();
|
|
1058
|
+
// Quiescence: a claimed or started job must settle, be released or be recovered first.
|
|
1059
|
+
if (run.jobs.some(job => job.state === 'leased' || job.state === 'started'))
|
|
1060
|
+
conflict();
|
|
1061
|
+
run.state.status = 'paused';
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
else if (method === 'resume') {
|
|
1065
|
+
if (run.state.status !== 'paused')
|
|
1066
|
+
conflict();
|
|
1067
|
+
run.state.status = 'running';
|
|
1068
|
+
this.advance(run);
|
|
1069
|
+
}
|
|
1070
|
+
else if (method === 'migrate') {
|
|
1071
|
+
await this.migrateRun(tx, run, input);
|
|
1072
|
+
await this.save(tx, run, method, input, { type: 'run.migrated', data: { migrationId: input['migrationId'], from: run.owner.lineage.at(-1), to: run.ownerRow.definition_hash, actorId: input['actorId'], commandId: input['commandId'] } });
|
|
1073
|
+
return this.snapshot(run);
|
|
1074
|
+
}
|
|
1075
|
+
else if (method === 'advance')
|
|
1076
|
+
this.advance(run);
|
|
1077
|
+
else if (method === 'finalize') {
|
|
1078
|
+
if (terminalRuns.has(run.state.status) || run.state.status === 'paused' || Object.values(run.state.steps).some(step => step.status !== 'succeeded') || run.state.reservedMicros !== 0)
|
|
1079
|
+
conflict();
|
|
1080
|
+
if (input['validation'] === 'passed' && this.admitsOutput(run, input['output'])) {
|
|
1081
|
+
run.state.output = input['output'];
|
|
1082
|
+
run.state.status = 'succeeded';
|
|
1083
|
+
}
|
|
1084
|
+
else {
|
|
1085
|
+
run.state.output = null;
|
|
1086
|
+
run.state.status = 'failed';
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
else
|
|
1090
|
+
conflict();
|
|
1091
|
+
// A no-op is not a committed transition, so it consumes neither a version nor a command journal entry.
|
|
1092
|
+
if (run.events.length === 0 && JSON.stringify(run.state) === originalState)
|
|
1093
|
+
return this.snapshot(run);
|
|
1094
|
+
const transition = method === 'cancel' ? 'run.cancelled' : method === 'finalize' ? 'run.completed'
|
|
1095
|
+
: method === 'pause' ? 'run.paused' : method === 'resume' ? 'run.resumed' : 'workflow.advanced';
|
|
1096
|
+
await this.save(tx, run, method, input, { type: transition, data: { status: run.state.status } });
|
|
1097
|
+
return this.snapshot(run);
|
|
1098
|
+
});
|
|
1099
|
+
if (result === STALE)
|
|
1100
|
+
throw new StorageError('STALE_CLAIM', 'Scheduled ownership expired or no longer permits the transition.');
|
|
1101
|
+
// Keep this text in sync with reviewExpiredMessage in @mayura/workflows: the driver recognizes it.
|
|
1102
|
+
if (result === REVIEW_EXPIRED)
|
|
1103
|
+
throw new StorageError('CONFLICT', 'The approval expired; request a new review before admission.');
|
|
1104
|
+
return result;
|
|
1105
|
+
}
|
|
1106
|
+
async claim(input, profile) {
|
|
1107
|
+
const scope = input['scope'];
|
|
1108
|
+
const id = input['id'];
|
|
1109
|
+
const policy = input['policyHash'];
|
|
1110
|
+
const hints = await this.backend.transaction(async (tx) => { const run = await this.load(tx, scope, id, policy, false, profile); return run?.jobs.filter(job => job.state === 'ready').map(job => job.jobId) ?? []; });
|
|
1111
|
+
const results = [];
|
|
1112
|
+
for (const jobId of hints) {
|
|
1113
|
+
if (results.length >= input['limit'])
|
|
1114
|
+
break;
|
|
1115
|
+
try {
|
|
1116
|
+
const result = await this.backend.transaction(async (tx) => {
|
|
1117
|
+
// This is an explicit run request, not a global queue scan: skipping its busy aggregate
|
|
1118
|
+
// can make every cooperating worker return while eligible work is still ready.
|
|
1119
|
+
const run = await this.load(tx, scope, id, policy, false, profile);
|
|
1120
|
+
if (!run || terminalRuns.has(run.state.status) || run.state.status === 'paused')
|
|
1121
|
+
return undefined;
|
|
1122
|
+
const job = run.jobs.find(job => job.jobId === jobId);
|
|
1123
|
+
if (!job || job.state !== 'ready')
|
|
1124
|
+
return undefined;
|
|
1125
|
+
if (await this.blockExpiredReview(tx, run, job)) {
|
|
1126
|
+
await this.save(tx, run);
|
|
1127
|
+
return undefined;
|
|
1128
|
+
}
|
|
1129
|
+
const claims = await this.local(tx, run, jobId).execute('claim', { scope, workerId: input['workerId'], limit: 1, leaseMs: input['leaseMs'] });
|
|
1130
|
+
if (!claims[0])
|
|
1131
|
+
return undefined;
|
|
1132
|
+
this.replaceJob(run, claims[0].job);
|
|
1133
|
+
// Resource acquisition can wait; recheck review expiry using the scheduler's post-lock clock.
|
|
1134
|
+
if (await this.blockExpiredReview(tx, run, claims[0].job)) {
|
|
1135
|
+
await this.save(tx, run);
|
|
1136
|
+
return undefined;
|
|
1137
|
+
}
|
|
1138
|
+
await this.save(tx, run);
|
|
1139
|
+
return claims[0];
|
|
1140
|
+
});
|
|
1141
|
+
if (result)
|
|
1142
|
+
results.push(result);
|
|
1143
|
+
}
|
|
1144
|
+
catch (error) {
|
|
1145
|
+
if (!(error instanceof ResourceBusy))
|
|
1146
|
+
throw error;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
return results;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
//# sourceMappingURL=scheduled-database.js.map
|