mayura 0.1.0-dev.0 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -35
- package/docs/README.md +82 -0
- package/docs/ai-agents.md +73 -0
- package/docs/cli/dev.md +111 -0
- package/docs/cli/init.md +192 -0
- package/docs/cli/operations.md +235 -0
- package/docs/cli/overview.md +129 -0
- package/docs/cli/run.md +182 -0
- package/docs/concepts/agent.md +197 -0
- package/docs/concepts/costs-and-budgets.md +177 -0
- package/docs/concepts/outcomes.md +154 -0
- package/docs/concepts/permissions.md +155 -0
- package/docs/concepts/runtime.md +172 -0
- package/docs/concepts/tools.md +202 -0
- package/docs/concepts/workflows.md +134 -0
- package/docs/guides/approvals-and-human-input.md +278 -0
- package/docs/guides/artifacts.md +123 -0
- package/docs/guides/child-agents.md +158 -0
- package/docs/guides/code-mode.md +233 -0
- package/docs/guides/deployment.md +644 -0
- package/docs/guides/durable-workflows.md +463 -0
- package/docs/guides/guardrails.md +205 -0
- package/docs/guides/helpers.md +176 -0
- package/docs/guides/lifecycle-hooks.md +187 -0
- package/docs/guides/mcp.md +123 -0
- package/docs/guides/memory-and-context.md +293 -0
- package/docs/guides/model-providers.md +371 -0
- package/docs/guides/model-routing.md +138 -0
- package/docs/guides/observability.md +238 -0
- package/docs/guides/operator-console.md +140 -0
- package/docs/guides/react.md +276 -0
- package/docs/guides/sagas-and-loops.md +212 -0
- package/docs/guides/server-and-client.md +559 -0
- package/docs/guides/skills.md +152 -0
- package/docs/guides/storage.md +251 -0
- package/docs/guides/streaming.md +146 -0
- package/docs/guides/terminal.md +166 -0
- package/docs/guides/testing.md +220 -0
- package/docs/guides/vision.md +155 -0
- package/docs/guides/webhooks.md +172 -0
- package/docs/guides/workflow-composition.md +141 -0
- package/docs/guides/workflow-operations.md +269 -0
- package/docs/installation.md +90 -0
- package/docs/introduction.md +74 -0
- package/docs/project/credits.md +78 -0
- package/docs/project/security.md +178 -0
- package/docs/project/support.md +91 -0
- package/docs/project/versioning.md +122 -0
- package/docs/quickstart.md +190 -0
- package/docs/reference/entry-points.md +146 -0
- package/lib/adapter-code-docker/dist/index.d.ts +8 -1
- package/lib/adapter-code-docker/dist/index.d.ts.map +1 -1
- package/lib/adapter-code-docker/dist/index.js +64 -67
- package/lib/adapter-code-docker/dist/index.js.map +1 -1
- package/lib/adapter-code-docker/dist/options.d.ts +15 -0
- package/lib/adapter-code-docker/dist/options.d.ts.map +1 -0
- package/lib/adapter-code-docker/dist/options.js +56 -0
- package/lib/adapter-code-docker/dist/options.js.map +1 -0
- package/lib/adapter-code-docker/image/Dockerfile +4 -2
- package/lib/adapter-code-docker/package.json +1 -1
- package/lib/adapter-code-docker/src/index.ts +63 -65
- package/lib/adapter-code-docker/src/options.ts +51 -0
- package/lib/adapter-code-quickjs/dist/index.d.ts +16 -4
- package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -1
- package/lib/adapter-code-quickjs/dist/index.js +94 -50
- package/lib/adapter-code-quickjs/dist/index.js.map +1 -1
- package/lib/adapter-code-quickjs/dist/worker-command.d.ts +27 -0
- package/lib/adapter-code-quickjs/dist/worker-command.d.ts.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker-command.js +66 -0
- package/lib/adapter-code-quickjs/dist/worker-command.js.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker.js +421 -104
- package/lib/adapter-code-quickjs/dist/worker.js.map +1 -1
- package/lib/adapter-code-quickjs/package.json +1 -1
- package/lib/adapter-code-quickjs/src/index.ts +88 -44
- package/lib/adapter-code-quickjs/src/worker-command.ts +68 -0
- package/lib/adapter-code-quickjs/src/worker.ts +315 -89
- package/lib/adapter-mcp/package.json +1 -1
- package/lib/artifacts/dist/contracts.d.ts +6 -2
- package/lib/artifacts/dist/contracts.d.ts.map +1 -1
- package/lib/artifacts/dist/contracts.js.map +1 -1
- package/lib/artifacts/dist/index.d.ts +1 -0
- package/lib/artifacts/dist/index.d.ts.map +1 -1
- package/lib/artifacts/dist/index.js +1 -0
- package/lib/artifacts/dist/index.js.map +1 -1
- package/lib/artifacts/dist/local-store.d.ts.map +1 -1
- package/lib/artifacts/dist/local-store.js +4 -7
- package/lib/artifacts/dist/local-store.js.map +1 -1
- package/lib/artifacts/dist/media.d.ts +11 -0
- package/lib/artifacts/dist/media.d.ts.map +1 -0
- package/lib/artifacts/dist/media.js +18 -0
- package/lib/artifacts/dist/media.js.map +1 -0
- package/lib/artifacts/package.json +1 -1
- package/lib/artifacts/src/contracts.ts +6 -2
- package/lib/artifacts/src/index.ts +1 -0
- package/lib/artifacts/src/local-store.ts +5 -7
- package/lib/artifacts/src/media.ts +20 -0
- package/lib/cli/dist/agent-guide.d.ts +10 -0
- package/lib/cli/dist/agent-guide.d.ts.map +1 -0
- package/lib/cli/dist/agent-guide.js +48 -0
- package/lib/cli/dist/agent-guide.js.map +1 -0
- package/lib/cli/dist/application.d.ts +24 -0
- package/lib/cli/dist/application.d.ts.map +1 -1
- package/lib/cli/dist/application.js +21 -0
- package/lib/cli/dist/application.js.map +1 -1
- package/lib/cli/dist/bin.js +26 -6
- package/lib/cli/dist/bin.js.map +1 -1
- package/lib/cli/dist/dev.d.ts.map +1 -1
- package/lib/cli/dist/dev.js +7 -1
- package/lib/cli/dist/dev.js.map +1 -1
- package/lib/cli/dist/index.d.ts +3 -3
- package/lib/cli/dist/index.d.ts.map +1 -1
- package/lib/cli/dist/index.js +19 -9
- package/lib/cli/dist/index.js.map +1 -1
- package/lib/cli/dist/interactive.d.ts.map +1 -1
- package/lib/cli/dist/interactive.js +52 -11
- package/lib/cli/dist/interactive.js.map +1 -1
- package/lib/cli/dist/operations.d.ts +25 -2
- package/lib/cli/dist/operations.d.ts.map +1 -1
- package/lib/cli/dist/operations.js +125 -12
- package/lib/cli/dist/operations.js.map +1 -1
- package/lib/cli/dist/output.d.ts.map +1 -1
- package/lib/cli/dist/output.js +3 -0
- package/lib/cli/dist/output.js.map +1 -1
- package/lib/cli/dist/providers.d.ts +34 -4
- package/lib/cli/dist/providers.d.ts.map +1 -1
- package/lib/cli/dist/providers.js +26 -5
- package/lib/cli/dist/providers.js.map +1 -1
- package/lib/cli/package.json +1 -1
- package/lib/cli/src/agent-guide.ts +47 -0
- package/lib/cli/src/application.ts +24 -0
- package/lib/cli/src/bin.ts +22 -5
- package/lib/cli/src/dev.ts +5 -1
- package/lib/cli/src/index.ts +18 -10
- package/lib/cli/src/interactive.ts +44 -12
- package/lib/cli/src/operations.ts +82 -12
- package/lib/cli/src/output.ts +3 -0
- package/lib/cli/src/providers.ts +45 -10
- package/lib/cli/starters/approval-workflow/dot-env.example +11 -0
- package/lib/cli/starters/approval-workflow/package.json +1 -2
- package/lib/cli/starters/approval-workflow/src/config.ts +25 -7
- package/lib/cli/starters/approval-workflow/src/intake.ts +1 -2
- package/lib/cli/starters/approval-workflow/src/model.ts +11 -4
- package/lib/cli/starters/approval-workflow/src/workflow.ts +1 -2
- package/lib/cli/starters/cli-agent/README.md +121 -0
- package/lib/cli/starters/cli-agent/dot-env.example +37 -0
- package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/cli-agent/dot-gitignore +10 -0
- package/lib/cli/starters/cli-agent/mayura.project.json +15 -0
- package/lib/cli/starters/cli-agent/package.json +28 -0
- package/lib/cli/starters/cli-agent/skills/release-notes/SKILL.md +18 -0
- package/lib/cli/starters/cli-agent/skills/release-notes/references/example.md +12 -0
- package/lib/cli/starters/cli-agent/src/assistant.ts +124 -0
- package/lib/cli/starters/cli-agent/src/cli.ts +72 -0
- package/lib/cli/starters/cli-agent/src/config.ts +117 -0
- package/lib/cli/starters/cli-agent/src/model.ts +34 -0
- package/lib/cli/starters/cli-agent/src/workspace.ts +170 -0
- package/lib/cli/starters/cli-agent/test/assistant.test.ts +205 -0
- package/lib/cli/starters/cli-agent/tsconfig.json +20 -0
- package/lib/cli/starters/event-automation/README.md +4 -3
- package/lib/cli/starters/event-automation/dot-env.example +11 -0
- package/lib/cli/starters/event-automation/package.json +1 -2
- package/lib/cli/starters/event-automation/src/config.ts +25 -7
- package/lib/cli/starters/event-automation/src/ingress.ts +3 -5
- package/lib/cli/starters/event-automation/src/model.ts +11 -4
- package/lib/cli/starters/event-automation/src/send-sample.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/main.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/tickets.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker-tools.ts +1 -1
- package/lib/cli/starters/event-automation/src/triage.ts +15 -22
- package/lib/cli/starters/event-automation/src/workflows.ts +1 -1
- package/lib/cli/starters/event-automation/test/automation.test.ts +3 -3
- package/lib/cli/starters/research-team/README.md +2 -2
- package/lib/cli/starters/research-team/dot-env.example +11 -0
- package/lib/cli/starters/research-team/package.json +1 -2
- package/lib/cli/starters/research-team/src/config.ts +25 -7
- package/lib/cli/starters/research-team/src/desk.ts +1 -2
- package/lib/cli/starters/research-team/src/library/index.ts +1 -2
- package/lib/cli/starters/research-team/src/model.ts +11 -4
- package/lib/cli/starters/research-team/src/services.ts +1 -1
- package/lib/cli/starters/research-team/src/team.ts +1 -2
- package/lib/cli/starters/research-team/src/workflow.ts +45 -59
- package/lib/cli/starters/support-agent/dot-env.example +11 -0
- package/lib/cli/starters/support-agent/package.json +1 -2
- package/lib/cli/starters/support-agent/src/assistant.ts +5 -5
- package/lib/cli/starters/support-agent/src/config.ts +25 -7
- package/lib/cli/starters/support-agent/src/guardrails.ts +3 -1
- package/lib/cli/starters/support-agent/src/model.ts +11 -4
- package/lib/cli/starters/support-agent/src/returns.ts +1 -2
- package/lib/cli/starters/support-agent/test/support.test.ts +25 -1
- package/lib/cli/templates/basic-agent.ts +1 -2
- package/lib/cli/templates/capability-policy.ts +1 -2
- package/lib/cli/templates/code-mode-workflow.ts +1 -1
- package/lib/cli/templates/durable-approval.ts +1 -1
- package/lib/cli/templates/parallel-research.ts +1 -2
- package/lib/cli/templates/typed-tool-runner.ts +1 -2
- package/lib/client/dist/forms.d.ts.map +1 -1
- package/lib/client/dist/forms.js +3 -4
- package/lib/client/dist/forms.js.map +1 -1
- package/lib/client/dist/headless.d.ts +3 -1
- package/lib/client/dist/headless.d.ts.map +1 -1
- package/lib/client/dist/headless.js +10 -6
- package/lib/client/dist/headless.js.map +1 -1
- package/lib/client/dist/index.d.ts +95 -6
- package/lib/client/dist/index.d.ts.map +1 -1
- package/lib/client/dist/index.js +397 -124
- package/lib/client/dist/index.js.map +1 -1
- package/lib/client/dist/workflows.d.ts +1 -1
- package/lib/client/dist/workflows.d.ts.map +1 -1
- package/lib/client/dist/workflows.js +7 -6
- package/lib/client/dist/workflows.js.map +1 -1
- package/lib/client/package.json +1 -1
- package/lib/client/src/forms.ts +3 -4
- package/lib/client/src/headless.ts +13 -7
- package/lib/client/src/index.ts +344 -74
- package/lib/client/src/workflows.ts +8 -7
- package/lib/client-react/package.json +1 -1
- package/lib/code-mode/dist/index.d.ts +32 -1
- package/lib/code-mode/dist/index.d.ts.map +1 -1
- package/lib/code-mode/dist/index.js +289 -221
- package/lib/code-mode/dist/index.js.map +1 -1
- package/lib/code-mode/package.json +1 -1
- package/lib/code-mode/src/index.ts +288 -184
- package/lib/code-mode-workflows/package.json +1 -1
- package/lib/context/package.json +1 -1
- package/lib/core/dist/budget.d.ts.map +1 -1
- package/lib/core/dist/budget.js +17 -2
- package/lib/core/dist/budget.js.map +1 -1
- package/lib/core/dist/contracts.d.ts +57 -0
- package/lib/core/dist/contracts.d.ts.map +1 -1
- package/lib/core/dist/contracts.js +36 -0
- package/lib/core/dist/contracts.js.map +1 -1
- package/lib/core/dist/destination.d.ts +12 -0
- package/lib/core/dist/destination.d.ts.map +1 -0
- package/lib/core/dist/destination.js +37 -0
- package/lib/core/dist/destination.js.map +1 -0
- package/lib/core/dist/event-stream.d.ts +1 -1
- package/lib/core/dist/event-stream.d.ts.map +1 -1
- package/lib/core/dist/event-stream.js +7 -0
- package/lib/core/dist/event-stream.js.map +1 -1
- package/lib/core/dist/host.d.ts +3 -0
- package/lib/core/dist/host.d.ts.map +1 -1
- package/lib/core/dist/host.js +3 -0
- package/lib/core/dist/host.js.map +1 -1
- package/lib/core/dist/index.d.ts +2 -0
- package/lib/core/dist/index.d.ts.map +1 -1
- package/lib/core/dist/index.js +2 -0
- package/lib/core/dist/index.js.map +1 -1
- package/lib/core/dist/media.d.ts +98 -0
- package/lib/core/dist/media.d.ts.map +1 -0
- package/lib/core/dist/media.js +227 -0
- package/lib/core/dist/media.js.map +1 -0
- package/lib/core/dist/model-schema.d.ts +37 -0
- package/lib/core/dist/model-schema.d.ts.map +1 -0
- package/lib/core/dist/model-schema.js +154 -0
- package/lib/core/dist/model-schema.js.map +1 -0
- package/lib/core/package.json +1 -1
- package/lib/core/src/budget.ts +17 -2
- package/lib/core/src/contracts.ts +71 -3
- package/lib/core/src/destination.ts +33 -0
- package/lib/core/src/event-stream.ts +5 -1
- package/lib/core/src/host.ts +3 -0
- package/lib/core/src/index.ts +2 -0
- package/lib/core/src/media.ts +228 -0
- package/lib/core/src/model-schema.ts +129 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
- package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
- package/lib/exporter-otlp/dist/signals.js +2 -2
- package/lib/exporter-otlp/dist/signals.js.map +1 -1
- package/lib/exporter-otlp/package.json +1 -1
- package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
- package/lib/exporter-otlp/src/signals.ts +2 -2
- package/lib/guardrails/package.json +1 -1
- package/lib/helpers/package.json +1 -1
- package/lib/memory/dist/index.js +1 -1
- package/lib/memory/dist/index.js.map +1 -1
- package/lib/memory/dist/native.d.ts.map +1 -1
- package/lib/memory/dist/native.js +4 -3
- package/lib/memory/dist/native.js.map +1 -1
- package/lib/memory/package.json +1 -1
- package/lib/memory/src/index.ts +1 -1
- package/lib/memory/src/native.ts +4 -3
- package/lib/memory-remote/package.json +1 -1
- package/lib/observability/package.json +1 -1
- package/lib/provider-anthropic/dist/index.d.ts +36 -3
- package/lib/provider-anthropic/dist/index.d.ts.map +1 -1
- package/lib/provider-anthropic/dist/index.js +128 -78
- package/lib/provider-anthropic/dist/index.js.map +1 -1
- package/lib/provider-anthropic/package.json +1 -1
- package/lib/provider-anthropic/src/index.ts +152 -76
- package/lib/provider-openai/dist/index.d.ts +71 -4
- package/lib/provider-openai/dist/index.d.ts.map +1 -1
- package/lib/provider-openai/dist/index.js +259 -96
- package/lib/provider-openai/dist/index.js.map +1 -1
- package/lib/provider-openai/package.json +1 -1
- package/lib/provider-openai/src/index.ts +282 -84
- package/lib/runtime/dist/agent.d.ts +18 -1
- package/lib/runtime/dist/agent.d.ts.map +1 -1
- package/lib/runtime/dist/agent.js +59 -3
- package/lib/runtime/dist/agent.js.map +1 -1
- package/lib/runtime/dist/composition.d.ts.map +1 -1
- package/lib/runtime/dist/composition.js +2 -1
- package/lib/runtime/dist/composition.js.map +1 -1
- package/lib/runtime/dist/hooks.d.ts +15 -3
- package/lib/runtime/dist/hooks.d.ts.map +1 -1
- package/lib/runtime/dist/hooks.js.map +1 -1
- package/lib/runtime/dist/index.d.ts +1 -1
- package/lib/runtime/dist/index.d.ts.map +1 -1
- package/lib/runtime/dist/index.js.map +1 -1
- package/lib/runtime/dist/response.d.ts +7 -1
- package/lib/runtime/dist/response.d.ts.map +1 -1
- package/lib/runtime/dist/response.js +23 -2
- package/lib/runtime/dist/response.js.map +1 -1
- package/lib/runtime/dist/router.d.ts +10 -3
- package/lib/runtime/dist/router.d.ts.map +1 -1
- package/lib/runtime/dist/router.js +45 -8
- package/lib/runtime/dist/router.js.map +1 -1
- package/lib/runtime/dist/runtime.d.ts +9 -1
- package/lib/runtime/dist/runtime.d.ts.map +1 -1
- package/lib/runtime/dist/runtime.js +50 -22
- package/lib/runtime/dist/runtime.js.map +1 -1
- package/lib/runtime/package.json +1 -1
- package/lib/runtime/src/agent.ts +69 -3
- package/lib/runtime/src/composition.ts +2 -1
- package/lib/runtime/src/hooks.ts +10 -4
- package/lib/runtime/src/index.ts +1 -1
- package/lib/runtime/src/response.ts +20 -2
- package/lib/runtime/src/router.ts +43 -10
- package/lib/runtime/src/runtime.ts +58 -27
- package/lib/sdk/dist/index.d.ts +9 -1
- package/lib/sdk/dist/index.d.ts.map +1 -1
- package/lib/sdk/dist/index.js +9 -1
- package/lib/sdk/dist/index.js.map +1 -1
- package/lib/sdk/package.json +1 -1
- package/lib/sdk/src/index.ts +9 -1
- package/lib/server/dist/index.d.ts +201 -3
- package/lib/server/dist/index.d.ts.map +1 -1
- package/lib/server/dist/index.js +701 -149
- package/lib/server/dist/index.js.map +1 -1
- package/lib/server/dist/inspector-bundle.d.ts +1 -1
- package/lib/server/dist/inspector-bundle.d.ts.map +1 -1
- package/lib/server/dist/inspector-bundle.js +4 -4
- package/lib/server/dist/inspector-bundle.js.map +1 -1
- package/lib/server/package.json +1 -1
- package/lib/server/src/index.ts +611 -135
- package/lib/server/src/inspector-bundle.ts +4 -4
- package/lib/server-node/dist/hardening.d.ts +1 -1
- package/lib/server-node/dist/hardening.d.ts.map +1 -1
- package/lib/server-node/dist/hardening.js +4 -2
- package/lib/server-node/dist/hardening.js.map +1 -1
- package/lib/server-node/dist/index.d.ts +2 -1
- package/lib/server-node/dist/index.d.ts.map +1 -1
- package/lib/server-node/dist/index.js.map +1 -1
- package/lib/server-node/dist/probe.js +2 -2
- package/lib/server-node/dist/probe.js.map +1 -1
- package/lib/server-node/dist/production.d.ts +8 -1
- package/lib/server-node/dist/production.d.ts.map +1 -1
- package/lib/server-node/dist/production.js +15 -2
- package/lib/server-node/dist/production.js.map +1 -1
- package/lib/server-node/package.json +1 -1
- package/lib/server-node/src/hardening.ts +5 -3
- package/lib/server-node/src/index.ts +2 -1
- package/lib/server-node/src/probe.ts +2 -2
- package/lib/server-node/src/production.ts +23 -3
- package/lib/skills/dist/index.d.ts +81 -0
- package/lib/skills/dist/index.d.ts.map +1 -0
- package/lib/skills/dist/index.js +311 -0
- package/lib/skills/dist/index.js.map +1 -0
- package/lib/skills/package.json +5 -0
- package/lib/skills/src/index.ts +260 -0
- package/lib/storage/dist/index.d.ts +1 -1
- package/lib/storage/dist/index.d.ts.map +1 -1
- package/lib/storage/dist/index.js.map +1 -1
- package/lib/storage/package.json +1 -1
- package/lib/storage/src/index.ts +1 -1
- package/lib/storage-contracts/dist/contracts.d.ts +12 -5
- package/lib/storage-contracts/dist/contracts.d.ts.map +1 -1
- package/lib/storage-contracts/dist/contracts.js +24 -6
- package/lib/storage-contracts/dist/contracts.js.map +1 -1
- package/lib/storage-contracts/dist/index.d.ts +2 -0
- package/lib/storage-contracts/dist/index.d.ts.map +1 -1
- package/lib/storage-contracts/dist/index.js +2 -0
- package/lib/storage-contracts/dist/index.js.map +1 -1
- package/lib/storage-contracts/dist/memory-contracts.js +1 -1
- package/lib/storage-contracts/dist/memory-contracts.js.map +1 -1
- package/lib/storage-contracts/dist/run-records.d.ts +100 -0
- package/lib/storage-contracts/dist/run-records.d.ts.map +1 -0
- package/lib/storage-contracts/dist/run-records.js +464 -0
- package/lib/storage-contracts/dist/run-records.js.map +1 -0
- package/lib/storage-contracts/dist/schema-digest.d.ts +17 -0
- package/lib/storage-contracts/dist/schema-digest.d.ts.map +1 -0
- package/lib/storage-contracts/dist/schema-digest.js +94 -0
- package/lib/storage-contracts/dist/schema-digest.js.map +1 -0
- package/lib/storage-contracts/dist/submission-journal.js +1 -1
- package/lib/storage-contracts/dist/submission-journal.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.d.ts +30 -2
- package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.js +57 -5
- package/lib/storage-contracts/dist/workflow-format5.js.map +1 -1
- package/lib/storage-contracts/package.json +1 -1
- package/lib/storage-contracts/src/contracts.ts +29 -5
- package/lib/storage-contracts/src/index.ts +2 -0
- package/lib/storage-contracts/src/memory-contracts.ts +1 -1
- package/lib/storage-contracts/src/run-records.ts +365 -0
- package/lib/storage-contracts/src/schema-digest.ts +71 -0
- package/lib/storage-contracts/src/submission-journal.ts +1 -1
- package/lib/storage-contracts/src/workflow-format5.ts +70 -6
- package/lib/storage-postgres/dist/index.d.ts +1 -1
- package/lib/storage-postgres/dist/index.d.ts.map +1 -1
- package/lib/storage-postgres/dist/index.js.map +1 -1
- package/lib/storage-postgres/dist/postgres.d.ts +15 -0
- package/lib/storage-postgres/dist/postgres.d.ts.map +1 -1
- package/lib/storage-postgres/dist/postgres.js +18 -7
- package/lib/storage-postgres/dist/postgres.js.map +1 -1
- package/lib/storage-postgres/package.json +1 -1
- package/lib/storage-postgres/src/index.ts +1 -1
- package/lib/storage-postgres/src/postgres.ts +34 -8
- package/lib/storage-sql/dist/aggregate-session.js +1 -1
- package/lib/storage-sql/dist/aggregate-session.js.map +1 -1
- package/lib/storage-sql/dist/scheduled-database.js +1 -1
- package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-validation.js +1 -1
- package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -1
- package/lib/storage-sql/package.json +1 -1
- package/lib/storage-sql/src/aggregate-session.ts +1 -1
- package/lib/storage-sql/src/scheduled-database.ts +1 -1
- package/lib/storage-sql/src/workflow-tree-validation.ts +1 -1
- package/lib/storage-sqlite/dist/sqlite-database.js +4 -4
- package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -1
- package/lib/storage-sqlite/dist/sqlite-worker.js +2 -2
- package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -1
- package/lib/storage-sqlite/dist/sqlite.js +1 -1
- package/lib/storage-sqlite/dist/sqlite.js.map +1 -1
- package/lib/storage-sqlite/package.json +1 -1
- package/lib/storage-sqlite/src/sqlite-database.ts +4 -4
- package/lib/storage-sqlite/src/sqlite-worker.ts +2 -2
- package/lib/storage-sqlite/src/sqlite.ts +1 -1
- package/lib/terminal/dist/index.d.ts +92 -0
- package/lib/terminal/dist/index.d.ts.map +1 -0
- package/lib/terminal/dist/index.js +397 -0
- package/lib/terminal/dist/index.js.map +1 -0
- package/lib/terminal/package.json +5 -0
- package/lib/terminal/src/index.ts +273 -0
- package/lib/testing/dist/index.d.ts +44 -1
- package/lib/testing/dist/index.d.ts.map +1 -1
- package/lib/testing/dist/index.js +63 -10
- package/lib/testing/dist/index.js.map +1 -1
- package/lib/testing/package.json +1 -1
- package/lib/testing/src/index.ts +83 -10
- package/lib/tools/dist/index.d.ts +32 -4
- package/lib/tools/dist/index.d.ts.map +1 -1
- package/lib/tools/dist/index.js +64 -11
- package/lib/tools/dist/index.js.map +1 -1
- package/lib/tools/package.json +1 -1
- package/lib/tools/src/index.ts +74 -13
- package/lib/workflows/dist/abandoned.d.ts +15 -0
- package/lib/workflows/dist/abandoned.d.ts.map +1 -0
- package/lib/workflows/dist/abandoned.js +33 -0
- package/lib/workflows/dist/abandoned.js.map +1 -0
- package/lib/workflows/dist/agent-step.d.ts +83 -0
- package/lib/workflows/dist/agent-step.d.ts.map +1 -0
- package/lib/workflows/dist/agent-step.js +161 -0
- package/lib/workflows/dist/agent-step.js.map +1 -0
- package/lib/workflows/dist/children-runtime.js +8 -8
- package/lib/workflows/dist/children-runtime.js.map +1 -1
- package/lib/workflows/dist/composite-fleet.js +2 -2
- package/lib/workflows/dist/composite-fleet.js.map +1 -1
- package/lib/workflows/dist/composite-host.d.ts.map +1 -1
- package/lib/workflows/dist/composite-host.js +26 -2
- package/lib/workflows/dist/composite-host.js.map +1 -1
- package/lib/workflows/dist/hook-relay.js +2 -2
- package/lib/workflows/dist/hook-relay.js.map +1 -1
- package/lib/workflows/dist/index.d.ts +1 -1
- package/lib/workflows/dist/index.d.ts.map +1 -1
- package/lib/workflows/dist/index.js.map +1 -1
- package/lib/workflows/dist/leadership.js +3 -3
- package/lib/workflows/dist/leadership.js.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.d.ts +26 -4
- package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.js +31 -6
- package/lib/workflows/dist/lifecycle-definition.js.map +1 -1
- package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-fleet.js +9 -11
- package/lib/workflows/dist/lifecycle-fleet.js.map +1 -1
- package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-host.js +26 -2
- package/lib/workflows/dist/lifecycle-host.js.map +1 -1
- package/lib/workflows/dist/lifecycle-human-transport.d.ts +22 -2
- package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-human-transport.js +115 -33
- package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.d.ts +62 -1
- package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.js +268 -64
- package/lib/workflows/dist/lifecycle-runtime.js.map +1 -1
- package/lib/workflows/dist/lifecycle.d.ts +6 -4
- package/lib/workflows/dist/lifecycle.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle.js +2 -0
- package/lib/workflows/dist/lifecycle.js.map +1 -1
- package/lib/workflows/dist/loop-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/loop-runtime.js +38 -26
- package/lib/workflows/dist/loop-runtime.js.map +1 -1
- package/lib/workflows/dist/migration.d.ts +1 -1
- package/lib/workflows/dist/migration.d.ts.map +1 -1
- package/lib/workflows/dist/migration.js +3 -3
- package/lib/workflows/dist/migration.js.map +1 -1
- package/lib/workflows/dist/operator-transports.d.ts +24 -2
- package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
- package/lib/workflows/dist/operator-transports.js +49 -3
- package/lib/workflows/dist/operator-transports.js.map +1 -1
- package/lib/workflows/dist/runtime.d.ts.map +1 -1
- package/lib/workflows/dist/runtime.js +34 -22
- package/lib/workflows/dist/runtime.js.map +1 -1
- package/lib/workflows/dist/saga-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/saga-runtime.js +44 -30
- package/lib/workflows/dist/saga-runtime.js.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.js +3 -3
- package/lib/workflows/dist/scheduled-helpers.js.map +1 -1
- package/lib/workflows/dist/storage-failure.d.ts +16 -0
- package/lib/workflows/dist/storage-failure.d.ts.map +1 -0
- package/lib/workflows/dist/storage-failure.js +38 -0
- package/lib/workflows/dist/storage-failure.js.map +1 -0
- package/lib/workflows/dist/sweep-position.d.ts +22 -0
- package/lib/workflows/dist/sweep-position.d.ts.map +1 -0
- package/lib/workflows/dist/sweep-position.js +45 -0
- package/lib/workflows/dist/sweep-position.js.map +1 -0
- package/lib/workflows/dist/traces.js +2 -2
- package/lib/workflows/dist/traces.js.map +1 -1
- package/lib/workflows/dist/worker.d.ts +31 -0
- package/lib/workflows/dist/worker.d.ts.map +1 -1
- package/lib/workflows/dist/worker.js +94 -0
- package/lib/workflows/dist/worker.js.map +1 -1
- package/lib/workflows/package.json +1 -1
- package/lib/workflows/src/abandoned.ts +32 -0
- package/lib/workflows/src/agent-step.ts +199 -0
- package/lib/workflows/src/children-runtime.ts +8 -8
- package/lib/workflows/src/composite-fleet.ts +2 -2
- package/lib/workflows/src/composite-host.ts +21 -3
- package/lib/workflows/src/hook-relay.ts +2 -2
- package/lib/workflows/src/index.ts +2 -1
- package/lib/workflows/src/leadership.ts +3 -3
- package/lib/workflows/src/lifecycle-definition.ts +50 -9
- package/lib/workflows/src/lifecycle-fleet.ts +7 -8
- package/lib/workflows/src/lifecycle-host.ts +21 -5
- package/lib/workflows/src/lifecycle-human-transport.ts +110 -26
- package/lib/workflows/src/lifecycle-runtime.ts +270 -60
- package/lib/workflows/src/lifecycle.ts +7 -0
- package/lib/workflows/src/loop-runtime.ts +34 -25
- package/lib/workflows/src/migration.ts +2 -2
- package/lib/workflows/src/operator-transports.ts +48 -4
- package/lib/workflows/src/runtime.ts +28 -22
- package/lib/workflows/src/saga-runtime.ts +38 -28
- package/lib/workflows/src/scheduled-helpers.ts +3 -3
- package/lib/workflows/src/storage-failure.ts +37 -0
- package/lib/workflows/src/sweep-position.ts +52 -0
- package/lib/workflows/src/traces.ts +2 -2
- package/lib/workflows/src/worker.ts +79 -1
- package/lib/workstream/dist/humans.d.ts +7 -3
- package/lib/workstream/dist/humans.d.ts.map +1 -1
- package/lib/workstream/dist/humans.js +13 -2
- package/lib/workstream/dist/humans.js.map +1 -1
- package/lib/workstream/dist/index.js +2 -2
- package/lib/workstream/dist/index.js.map +1 -1
- package/lib/workstream/dist/timers.js +2 -2
- package/lib/workstream/dist/timers.js.map +1 -1
- package/lib/workstream/dist/webhooks.d.ts +6 -2
- package/lib/workstream/dist/webhooks.d.ts.map +1 -1
- package/lib/workstream/dist/webhooks.js +17 -7
- package/lib/workstream/dist/webhooks.js.map +1 -1
- package/lib/workstream/package.json +1 -1
- package/lib/workstream/src/humans.ts +15 -5
- package/lib/workstream/src/index.ts +2 -2
- package/lib/workstream/src/timers.ts +2 -2
- package/lib/workstream/src/webhooks.ts +21 -8
- package/llms-full.txt +9766 -0
- package/llms.txt +92 -0
- package/package.json +18 -6
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Deployment"
|
|
3
|
+
description: "Run a Mayura app in production: on containers, Kubernetes, managed platforms, virtual machines, serverless functions or inside an app you already run."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
A production Mayura app is one compiled application module run in three roles from the same build:
|
|
7
|
+
|
|
8
|
+
- `mayura migrate` prepares storage, once per release, before anything new serves traffic.
|
|
9
|
+
- `mayura serve` runs the HTTP server: your agents' API, the operator API and, if you enable it, the
|
|
10
|
+
[operator console](operator-console.md).
|
|
11
|
+
- `mayura worker` advances durable workflows: timers, retries, human waits and scheduled work. Run as many replicas as
|
|
12
|
+
you like; one leader works at a time and a standby takes over if it dies.
|
|
13
|
+
|
|
14
|
+
All of them share one PostgreSQL database. The CLI owns the process lifecycle (signals, probes for workers, drain and
|
|
15
|
+
shutdown); your module owns everything else. Every starter project (see [mayura init](../cli/init.md)) ships this
|
|
16
|
+
setup ready to run, with a `Dockerfile` and `compose.yaml`.
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
clients ──HTTPS──▶ TLS proxy ──HTTP──▶ mayura serve (1..n) ──┐
|
|
20
|
+
├──▶ PostgreSQL
|
|
21
|
+
mayura worker (1..n) ──┘
|
|
22
|
+
mayura migrate (once per release)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Choose a target
|
|
26
|
+
|
|
27
|
+
Every target runs the same three commands from the same build, against the same PostgreSQL database. They differ
|
|
28
|
+
only in how the processes are started and kept running. Mayura needs Node.js 22 or 24 (see
|
|
29
|
+
[Supported platforms](../project/support.md)).
|
|
30
|
+
|
|
31
|
+
| Target | Server | Worker | Migration |
|
|
32
|
+
|---|---|---|---|
|
|
33
|
+
| [Containers](#containers): Docker, Compose | a `serve` container | a `worker` container | a one-shot container |
|
|
34
|
+
| [Kubernetes](#kubernetes) | a Deployment and a Service | a Deployment | a Job before each rollout |
|
|
35
|
+
| [Managed containers](#managed-container-platforms): ECS on Fargate, Cloud Run, Azure Container Apps, Fly.io | a service | an always-on service | a one-off task or job |
|
|
36
|
+
| [Process platforms](#platforms-with-process-types): Render, Railway, Heroku | a web process | a worker process | the release or pre-deploy command |
|
|
37
|
+
| [Virtual machines](#virtual-machines) | a systemd service | a systemd service | a step in your deploy script |
|
|
38
|
+
| [Inside an existing app](#inside-an-existing-nodejs-app) | your framework's `/v1/*` route | `mayura worker` | `mayura migrate` |
|
|
39
|
+
| [Serverless functions](#serverless-functions): Vercel; AWS Lambda and Cloud Run (experimental) | a request-bound function | a scheduled one-shot function or job | a step in your pipeline |
|
|
40
|
+
|
|
41
|
+
On every target except serverless functions, two rules hold. The worker keeps running: a platform that scales it to
|
|
42
|
+
zero, or stops its CPU between requests, stops your workflows too. And the server keeps working after it responds,
|
|
43
|
+
because agent runs continue in the process that accepted them, so it needs CPU between requests as well. Serverless
|
|
44
|
+
functions work the other way: runs finish inside their request and workflows advance on a schedule; see
|
|
45
|
+
[Serverless functions](#serverless-functions). Edge runtimes are planned for 1.1.
|
|
46
|
+
|
|
47
|
+
## The application module
|
|
48
|
+
|
|
49
|
+
The module's default export says how to start each role. This one serves an agent and the workflow operator API,
|
|
50
|
+
runs a workflow worker, and reads all of its configuration from the environment:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
54
|
+
import { hostname } from 'node:os';
|
|
55
|
+
import { defineMayuraApplication } from 'mayura/cli';
|
|
56
|
+
import { listenProductionServer, type ServerIdentity } from 'mayura/server-node';
|
|
57
|
+
import { createAggregateRunRecords } from 'mayura/storage-contracts';
|
|
58
|
+
import { createPostgresStore } from 'mayura/storage-postgres';
|
|
59
|
+
import { createWorkflowCommandJournal, createWorkflowFleetControl, createWorkflowLeadership, createWorkflowOperatorTransports,
|
|
60
|
+
createWorkflowWorker, lifecycleOperatorTarget } from 'mayura/workflows';
|
|
61
|
+
import { createWorkflowLifecycleFleetRuntime, createWorkflowLifecycleHost } from 'mayura/workflows/lifecycle';
|
|
62
|
+
import { assistant } from './assistant.js'; // your agent
|
|
63
|
+
import { definitions } from './workflows.js'; // every workflow definition version that still has runs
|
|
64
|
+
|
|
65
|
+
function env(name: string): string {
|
|
66
|
+
const value = process.env[name];
|
|
67
|
+
if (!value) throw new Error(`${name} is required.`);
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const scope = { principalId: 'orders-service', projectId: 'orders' };
|
|
72
|
+
const store = createPostgresStore({ connectionString: env('DATABASE_URL') });
|
|
73
|
+
const fleet = createWorkflowFleetControl({ store, scope });
|
|
74
|
+
const workflowOptions = { store, scope, permissions: { allow: ['tool:orders.refund'] }, policyVersion: '1', maxCostMicros: 0 };
|
|
75
|
+
let initialized: Promise<void> | undefined;
|
|
76
|
+
const ready = () => (initialized ??= store.initialize());
|
|
77
|
+
|
|
78
|
+
// Operators get 64-hex tokens; configuration holds only their SHA-256 digests.
|
|
79
|
+
const operatorDigests = env('MAYURA_OPERATOR_TOKEN_SHA256').split(',');
|
|
80
|
+
async function authenticate({ token }: { readonly token: string }): Promise<ServerIdentity | null> {
|
|
81
|
+
if (!/^[a-f0-9]{64}$/.test(token)) return null;
|
|
82
|
+
const supplied = createHash('sha256').update(token).digest();
|
|
83
|
+
let matched = false; // compare against every digest, so timing does not reveal which one matched
|
|
84
|
+
for (const digest of operatorDigests) matched = timingSafeEqual(supplied, Buffer.from(digest, 'hex')) || matched;
|
|
85
|
+
if (!matched) return null;
|
|
86
|
+
return { scope, agentIds: [assistant.id], expiresAtMs: Date.now() + 60_000,
|
|
87
|
+
capabilities: ['runs:read', 'operations:read', 'workflows:read', 'workflows:control'] };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default defineMayuraApplication({
|
|
91
|
+
async server() {
|
|
92
|
+
await ready();
|
|
93
|
+
const runtime = createWorkflowLifecycleFleetRuntime(workflowOptions);
|
|
94
|
+
const operator = createWorkflowOperatorTransports({ store, scope, fleet, journal: createWorkflowCommandJournal({ store, scope }),
|
|
95
|
+
targets: [lifecycleOperatorTarget({ runtime, store, scope, definitions })] });
|
|
96
|
+
return listenProductionServer({
|
|
97
|
+
agents: [{ agent: assistant, permissions: { allow: ['model:openai.responses'] }, limits: { maxCostMicros: 200_000 } }],
|
|
98
|
+
authenticate,
|
|
99
|
+
// Every server replica can read, stream and cancel every agent run, and claims submission keys durably.
|
|
100
|
+
runRecords: createAggregateRunRecords(store),
|
|
101
|
+
inspector: true,
|
|
102
|
+
...operator,
|
|
103
|
+
publicOrigin: env('MAYURA_PUBLIC_ORIGIN'),
|
|
104
|
+
hostname: process.env['MAYURA_BIND'] ?? '0.0.0.0',
|
|
105
|
+
port: Number(process.env['PORT'] ?? 8080),
|
|
106
|
+
tls: { terminatedBy: 'proxy' },
|
|
107
|
+
readiness: async () => { await store.read('readiness', 'probe'); return true; },
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
async worker() {
|
|
111
|
+
await ready();
|
|
112
|
+
const host = createWorkflowLifecycleHost({ ...workflowOptions, definitions, hold: fleet });
|
|
113
|
+
const leadership = createWorkflowLeadership({ store, scope, role: 'workflows',
|
|
114
|
+
holderId: process.env['MAYURA_WORKER_ID'] ?? `${hostname()}-${process.pid}` });
|
|
115
|
+
return createWorkflowWorker({ units: [host], leadership });
|
|
116
|
+
},
|
|
117
|
+
// Storage schema version 1 is the baseline. Later releases add explicit migrations here.
|
|
118
|
+
async migrate() { await ready(); return { schemaVersion: 1 }; },
|
|
119
|
+
async shutdown() { await store.close(); },
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- `server()` returns a running server with `isAccepting()` and `close()`; `listenProductionServer` gives you one.
|
|
124
|
+
- `worker()` returns a worker with `start()`, `isReady()` and `drain()`; `createWorkflowWorker` gives you one. Don't
|
|
125
|
+
start it yourself: the CLI calls `start()`.
|
|
126
|
+
- `migrate()` returns any JSON report, which the CLI prints.
|
|
127
|
+
- `shutdown()` runs after the server has closed or the worker has drained. Close storage here.
|
|
128
|
+
|
|
129
|
+
The module must be a compiled `.js` or `.mjs` file. Real apps usually split it into files as the starters do
|
|
130
|
+
(`config.ts`, `services.ts`, `server.ts`, `worker.ts`, `app.ts`). For your app's own user authentication, see
|
|
131
|
+
[Server and client](server-and-client.md).
|
|
132
|
+
|
|
133
|
+
## Run the three commands
|
|
134
|
+
|
|
135
|
+
After building (`tsc`), run them from the project directory:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
mayura migrate --app dist/app.js
|
|
139
|
+
mayura serve --app dist/app.js
|
|
140
|
+
mayura worker --app dist/app.js --probe-host 0.0.0.0 --probe-port 9090
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Run `migrate` to completion before starting new servers and workers. Run the server and the worker as separate
|
|
144
|
+
processes (or containers); both read the same environment. See [CLI: serve, worker and migrate](../cli/run.md) for
|
|
145
|
+
every flag.
|
|
146
|
+
|
|
147
|
+
## Containers
|
|
148
|
+
|
|
149
|
+
The starters' `Dockerfile` builds once and runs any role; the command picks which. It compiles in one stage, keeps
|
|
150
|
+
only production dependencies, and runs as an unprivileged user:
|
|
151
|
+
|
|
152
|
+
```dockerfile
|
|
153
|
+
FROM node:24.14.1-alpine AS build
|
|
154
|
+
WORKDIR /app
|
|
155
|
+
COPY package.json package-lock.json* ./
|
|
156
|
+
RUN npm install --no-audit --no-fund
|
|
157
|
+
COPY tsconfig.json ./
|
|
158
|
+
COPY src ./src
|
|
159
|
+
RUN npx tsc -p tsconfig.json && npm prune --omit=dev
|
|
160
|
+
|
|
161
|
+
FROM node:24.14.1-alpine
|
|
162
|
+
WORKDIR /app
|
|
163
|
+
COPY --from=build --chown=65532:65532 /app/package.json ./
|
|
164
|
+
COPY --from=build --chown=65532:65532 /app/node_modules ./node_modules
|
|
165
|
+
COPY --from=build --chown=65532:65532 /app/dist ./dist
|
|
166
|
+
USER 65532:65532
|
|
167
|
+
ENV NODE_ENV=production
|
|
168
|
+
EXPOSE 8080 9090
|
|
169
|
+
ENTRYPOINT ["node", "node_modules/mayura/lib/cli/dist/bin.js"]
|
|
170
|
+
CMD ["serve", "--app", "dist/app.js"]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The entry point is the `mayura` CLI inside the installed package. The starters also pin the base image by digest,
|
|
174
|
+
and their `.dockerignore` keeps `.env`, local data and SQLite files out of the image.
|
|
175
|
+
|
|
176
|
+
Their `compose.yaml` is a production-shaped local stack: PostgreSQL, a one-shot migration, the server and a worker.
|
|
177
|
+
|
|
178
|
+
```yaml
|
|
179
|
+
services:
|
|
180
|
+
postgres:
|
|
181
|
+
image: postgres:17
|
|
182
|
+
environment: { POSTGRES_USER: app, POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}", POSTGRES_DB: app }
|
|
183
|
+
volumes: [postgres-data:/var/lib/postgresql/data]
|
|
184
|
+
healthcheck: { test: ["CMD-SHELL", "pg_isready -U app -d app"], interval: 2s, timeout: 5s, retries: 30 }
|
|
185
|
+
migrate:
|
|
186
|
+
build: .
|
|
187
|
+
command: ["migrate", "--app", "dist/app.js"]
|
|
188
|
+
env_file: .env
|
|
189
|
+
environment: { DATABASE_URL: "postgres://app:${POSTGRES_PASSWORD}@postgres:5432/app" }
|
|
190
|
+
depends_on: { postgres: { condition: service_healthy } }
|
|
191
|
+
server:
|
|
192
|
+
build: .
|
|
193
|
+
command: ["serve", "--app", "dist/app.js"]
|
|
194
|
+
env_file: .env
|
|
195
|
+
environment: { DATABASE_URL: "postgres://app:${POSTGRES_PASSWORD}@postgres:5432/app" }
|
|
196
|
+
ports: ["8080:8080"]
|
|
197
|
+
depends_on: { migrate: { condition: service_completed_successfully } }
|
|
198
|
+
healthcheck: { test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8080/readyz').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"], interval: 5s, timeout: 5s, retries: 30 }
|
|
199
|
+
worker:
|
|
200
|
+
build: .
|
|
201
|
+
command: ["worker", "--app", "dist/app.js", "--probe-host", "0.0.0.0", "--probe-port", "9090"]
|
|
202
|
+
env_file: .env
|
|
203
|
+
environment: { DATABASE_URL: "postgres://app:${POSTGRES_PASSWORD}@postgres:5432/app" }
|
|
204
|
+
depends_on: { migrate: { condition: service_completed_successfully } }
|
|
205
|
+
healthcheck: { test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:9090/readyz').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"], interval: 5s, timeout: 5s, retries: 30 }
|
|
206
|
+
volumes:
|
|
207
|
+
postgres-data:
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
cp .env.example .env
|
|
212
|
+
docker compose up --build
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The server speaks plain HTTP on port 8080. Put your TLS proxy or load balancer in front of it, forwarding the
|
|
216
|
+
original `Host` header of the public origin. If the proxy rewrites `Host`, pass its addresses as `trustedProxies` and
|
|
217
|
+
have it set `X-Forwarded-Host` (see [Server and client](server-and-client.md#hosting-on-node)).
|
|
218
|
+
|
|
219
|
+
## Kubernetes
|
|
220
|
+
|
|
221
|
+
Build the image as in [Containers](#containers) and run it three ways. The arguments go to the image's entry point,
|
|
222
|
+
the `mayura` CLI. Keep configuration in a Secret (here `agents-env`) and terminate TLS at your ingress, which must pass
|
|
223
|
+
the original `Host` header through.
|
|
224
|
+
|
|
225
|
+
```yaml
|
|
226
|
+
apiVersion: batch/v1
|
|
227
|
+
kind: Job
|
|
228
|
+
metadata: { name: agents-migrate-v42 } # one Job per release, run to completion before the rollout
|
|
229
|
+
spec:
|
|
230
|
+
backoffLimit: 0
|
|
231
|
+
template:
|
|
232
|
+
spec:
|
|
233
|
+
restartPolicy: Never
|
|
234
|
+
containers:
|
|
235
|
+
- name: migrate
|
|
236
|
+
image: registry.example.com/agents:v42
|
|
237
|
+
args: ["migrate", "--app", "dist/app.js"]
|
|
238
|
+
envFrom: [{ secretRef: { name: agents-env } }]
|
|
239
|
+
---
|
|
240
|
+
apiVersion: apps/v1
|
|
241
|
+
kind: Deployment
|
|
242
|
+
metadata: { name: agents-server }
|
|
243
|
+
spec:
|
|
244
|
+
replicas: 2
|
|
245
|
+
selector: { matchLabels: { app: agents-server } }
|
|
246
|
+
template:
|
|
247
|
+
metadata: { labels: { app: agents-server } }
|
|
248
|
+
spec:
|
|
249
|
+
terminationGracePeriodSeconds: 45
|
|
250
|
+
containers:
|
|
251
|
+
- name: server
|
|
252
|
+
image: registry.example.com/agents:v42
|
|
253
|
+
args: ["serve", "--app", "dist/app.js"]
|
|
254
|
+
envFrom: [{ secretRef: { name: agents-env } }]
|
|
255
|
+
ports: [{ containerPort: 8080 }]
|
|
256
|
+
readinessProbe: { httpGet: { path: /readyz, port: 8080 }, periodSeconds: 5 }
|
|
257
|
+
livenessProbe: { httpGet: { path: /livez, port: 8080 }, periodSeconds: 10 }
|
|
258
|
+
---
|
|
259
|
+
apiVersion: v1
|
|
260
|
+
kind: Service
|
|
261
|
+
metadata: { name: agents-server }
|
|
262
|
+
spec:
|
|
263
|
+
selector: { app: agents-server }
|
|
264
|
+
ports: [{ port: 80, targetPort: 8080 }]
|
|
265
|
+
---
|
|
266
|
+
apiVersion: apps/v1
|
|
267
|
+
kind: Deployment
|
|
268
|
+
metadata: { name: agents-worker }
|
|
269
|
+
spec:
|
|
270
|
+
replicas: 2
|
|
271
|
+
selector: { matchLabels: { app: agents-worker } }
|
|
272
|
+
template:
|
|
273
|
+
metadata: { labels: { app: agents-worker } }
|
|
274
|
+
spec:
|
|
275
|
+
terminationGracePeriodSeconds: 45
|
|
276
|
+
containers:
|
|
277
|
+
- name: worker
|
|
278
|
+
image: registry.example.com/agents:v42
|
|
279
|
+
args: ["worker", "--app", "dist/app.js", "--probe-host", "0.0.0.0", "--probe-port", "9090"]
|
|
280
|
+
envFrom: [{ secretRef: { name: agents-env } }]
|
|
281
|
+
env: [{ name: MAYURA_WORKER_ID, valueFrom: { fieldRef: { fieldPath: metadata.name } } }]
|
|
282
|
+
readinessProbe: { httpGet: { path: /readyz, port: 9090 }, periodSeconds: 5 }
|
|
283
|
+
livenessProbe: { httpGet: { path: /livez, port: 9090 }, periodSeconds: 10 }
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
- `terminationGracePeriodSeconds` is longer than the server's `shutdownGraceMs` and the worker's `--drain-timeout-ms`
|
|
287
|
+
(30 seconds each by default), so a rollout drains instead of cutting work off.
|
|
288
|
+
- Each worker replica needs its own `MAYURA_WORKER_ID` for its leadership lease; the pod name is a good one. One
|
|
289
|
+
replica leads and the rest stand by.
|
|
290
|
+
- Run the migration Job to completion before updating the Deployments, for example from your CI with
|
|
291
|
+
`kubectl wait --for=condition=complete job/agents-migrate-v42`, or as a Helm pre-upgrade hook.
|
|
292
|
+
|
|
293
|
+
## Managed container platforms
|
|
294
|
+
|
|
295
|
+
The same image runs on any platform that runs containers. On each, create a service for the server, an always-on
|
|
296
|
+
service for the worker, and a one-off job for the migration, all with the same environment.
|
|
297
|
+
|
|
298
|
+
- **AWS ECS on Fargate.** Two services from one task definition, overriding the command: `serve --app dist/app.js`
|
|
299
|
+
behind an Application Load Balancer that checks `/readyz` on port 8080, and `worker --app dist/app.js` with no load
|
|
300
|
+
balancer. Run the migration as a one-off task (`aws ecs run-task` with the `migrate` command) before updating the
|
|
301
|
+
services, and set the container's `stopTimeout` above 30 seconds.
|
|
302
|
+
- **Google Cloud Run.** Deploy the server as a service on port 8080 with `/readyz` as its startup and readiness
|
|
303
|
+
check, and the migration as a Cloud Run job. Cloud Run's defaults scale to zero and stop the CPU between requests,
|
|
304
|
+
which pauses agent runs and workflows, so give both the server and the worker CPU that is always allocated and at
|
|
305
|
+
least one minimum instance.
|
|
306
|
+
- **Azure Container Apps.** A container app for the server with ingress on port 8080 and health probes on `/livez`
|
|
307
|
+
and `/readyz`, a second container app for the worker with no ingress and at least one replica, and a Container Apps
|
|
308
|
+
job for the migration.
|
|
309
|
+
- **Fly.io.** One app with two process groups, the migration as the release command, and machines that are never
|
|
310
|
+
stopped automatically:
|
|
311
|
+
|
|
312
|
+
```toml
|
|
313
|
+
[processes]
|
|
314
|
+
app = "serve --app dist/app.js"
|
|
315
|
+
worker = "worker --app dist/app.js"
|
|
316
|
+
|
|
317
|
+
[deploy]
|
|
318
|
+
release_command = "migrate --app dist/app.js"
|
|
319
|
+
|
|
320
|
+
[http_service]
|
|
321
|
+
internal_port = 8080
|
|
322
|
+
processes = ["app"]
|
|
323
|
+
auto_stop_machines = "off"
|
|
324
|
+
min_machines_running = 1
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Wherever you run, put TLS in front of the server and keep its `publicOrigin` equal to the public URL (see
|
|
328
|
+
[Production server settings](#production-server-settings)).
|
|
329
|
+
|
|
330
|
+
## Platforms with process types
|
|
331
|
+
|
|
332
|
+
Platforms that run processes from your repository need three commands and nothing else. On Heroku, a `Procfile`:
|
|
333
|
+
|
|
334
|
+
```text
|
|
335
|
+
release: npx mayura migrate --app dist/app.js
|
|
336
|
+
web: npx mayura serve --app dist/app.js
|
|
337
|
+
worker: npx mayura worker --app dist/app.js
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
On Render and Railway, create a web service and a background worker from the same repository with the `web` and
|
|
341
|
+
`worker` commands above, and set the migration as the pre-deploy command. The server listens on the platform's
|
|
342
|
+
`PORT` (the example module reads it), the platform terminates TLS, and the build step compiles your TypeScript. Keep
|
|
343
|
+
at least one instance of each running.
|
|
344
|
+
|
|
345
|
+
## Virtual machines
|
|
346
|
+
|
|
347
|
+
On a server of your own, run the two long-lived roles as systemd services and the migration from your deploy script.
|
|
348
|
+
Put a TLS proxy such as Caddy or nginx in front of port 8080.
|
|
349
|
+
|
|
350
|
+
```ini
|
|
351
|
+
# /etc/systemd/system/agents-server.service
|
|
352
|
+
[Unit]
|
|
353
|
+
Description=Agents server
|
|
354
|
+
After=network-online.target
|
|
355
|
+
Wants=network-online.target
|
|
356
|
+
|
|
357
|
+
[Service]
|
|
358
|
+
User=agents
|
|
359
|
+
WorkingDirectory=/srv/agents
|
|
360
|
+
EnvironmentFile=/etc/agents/env
|
|
361
|
+
ExecStart=/usr/bin/node node_modules/mayura/lib/cli/dist/bin.js serve --app dist/app.js
|
|
362
|
+
Restart=on-failure
|
|
363
|
+
TimeoutStopSec=45
|
|
364
|
+
|
|
365
|
+
[Install]
|
|
366
|
+
WantedBy=multi-user.target
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
The worker's unit is the same with `worker --app dist/app.js` in `ExecStart`. systemd stops services with `SIGTERM`,
|
|
370
|
+
which starts the graceful stop, and `TimeoutStopSec` gives it time to drain. To deploy, install and build the new
|
|
371
|
+
release, run `mayura migrate --app dist/app.js`, then restart both services. Keep `/etc/agents/env` readable only by
|
|
372
|
+
the service user.
|
|
373
|
+
|
|
374
|
+
## Inside an existing Node.js app
|
|
375
|
+
|
|
376
|
+
If you already run a Node.js server, mount Mayura's API in it instead of running `mayura serve`.
|
|
377
|
+
`createAgentServer` from `mayura/server` returns a standard `fetch(request)` handler; send every request whose path
|
|
378
|
+
starts with `/v1/` to it and serve your own routes as usual. Set `mounted: true`, so the handler trusts only the path
|
|
379
|
+
and query your framework routed to it, never the `Host` header (see
|
|
380
|
+
[Server and client](server-and-client.md#mounting-the-handler-yourself)).
|
|
381
|
+
|
|
382
|
+
A Next.js route handler, for an app that runs on a Node.js server with `next start`:
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
// app/v1/[...path]/route.ts
|
|
386
|
+
import { createAgentServer } from 'mayura/server';
|
|
387
|
+
|
|
388
|
+
const api = createAgentServer({ publicOrigin: 'https://agents.example.com', mounted: true, agents, authenticate });
|
|
389
|
+
|
|
390
|
+
export const runtime = 'nodejs';
|
|
391
|
+
export const dynamic = 'force-dynamic';
|
|
392
|
+
export const GET = (request: Request) => api.fetch(request);
|
|
393
|
+
export const POST = (request: Request) => api.fetch(request);
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
In Hono it is `app.all('/v1/*', context => api.fetch(context.req.raw))`, and any framework that gives you a web
|
|
397
|
+
`Request` works the same way. The API stays at `/v1/` on your public origin, where `mayura/client` expects it. The
|
|
398
|
+
repository's `examples/embedded-handler.mjs` runs this end to end.
|
|
399
|
+
|
|
400
|
+
Durable workflows still need `mayura worker`, and storage still needs `mayura migrate`: give your module `worker()`
|
|
401
|
+
and `migrate()` and run those two commands next to your app.
|
|
402
|
+
|
|
403
|
+
## Serverless functions
|
|
404
|
+
|
|
405
|
+
Vercel Functions, AWS Lambda and Google Cloud Run can run Mayura as functions: short-lived instances that handle
|
|
406
|
+
requests and may be frozen or stopped as soon as they respond.
|
|
407
|
+
|
|
408
|
+
- **Vercel Functions are tested on Vercel**: request-bound runs, workflows advanced by one-shot invocations, and a
|
|
409
|
+
function stopped at its time limit in the middle of a step, then recovered, all on PostgreSQL through a pooled
|
|
410
|
+
connection.
|
|
411
|
+
- **Experimental: AWS Lambda, Google Cloud Run, Vercel Cron and the Next.js route files below.** They follow the same
|
|
412
|
+
rules and pass the same local tests, which run every invocation as a process stopped as soon as it answers, but have
|
|
413
|
+
not yet run on those platforms. Their setup may change in any release.
|
|
414
|
+
|
|
415
|
+
Four settings make functions safe:
|
|
416
|
+
|
|
417
|
+
- **Runs finish inside their request.** Mount the API with `runExecution: 'request'` and `runRecords` (see
|
|
418
|
+
[Request-bound runs](server-and-client.md#request-bound-runs)): each run finishes before its response, and any
|
|
419
|
+
instance can read it afterwards. Keep each agent's `limits.maxDurationMs`, plus the server's `requestTimeoutMs`,
|
|
420
|
+
under the function's time limit. Work that takes longer belongs in a durable workflow.
|
|
421
|
+
- **Workflows advance on a schedule.** A scheduled invocation calls `worker.runOnce({ budgetMs })` every minute; it
|
|
422
|
+
advances everything that is due and returns (see [Run once](../cli/run.md#run-once)). Keep the budget under the
|
|
423
|
+
function's time limit by at least your longest tool's `timeoutMs`. A step cut off by a timeout or a crash is settled
|
|
424
|
+
as unknown by a later invocation, and never run twice.
|
|
425
|
+
- **Small connection pools.** Every instance opens its own pool, so use `pool: { max: 1 }` and your provider's pooled
|
|
426
|
+
connection string (see [Storage](storage.md#postgresql)).
|
|
427
|
+
- **Migrations from your pipeline.** Run `mayura migrate` from CI before you release new functions.
|
|
428
|
+
|
|
429
|
+
One module holds all of it; each platform's entry points below only call into it:
|
|
430
|
+
|
|
431
|
+
```ts
|
|
432
|
+
// src/mayura.ts
|
|
433
|
+
import { createAgentServer } from 'mayura/server';
|
|
434
|
+
import { createAggregateRunRecords } from 'mayura/storage-contracts';
|
|
435
|
+
import { createPostgresStore } from 'mayura/storage-postgres';
|
|
436
|
+
import { createWorkflowLeadership, createWorkflowWorker } from 'mayura/workflows';
|
|
437
|
+
import { createWorkflowLifecycleHost } from 'mayura/workflows/lifecycle';
|
|
438
|
+
|
|
439
|
+
const store = createPostgresStore({ connectionString: process.env['DATABASE_URL']!, pool: { max: 1 } });
|
|
440
|
+
const ready = store.initialize();
|
|
441
|
+
|
|
442
|
+
const api = createAgentServer({
|
|
443
|
+
publicOrigin: 'https://agents.example.com', mounted: true, agents, authenticate,
|
|
444
|
+
runRecords: createAggregateRunRecords(store),
|
|
445
|
+
runExecution: 'request',
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
/** Answer one request to Mayura's API. */
|
|
449
|
+
export async function handle(request: Request): Promise<Response> {
|
|
450
|
+
await ready;
|
|
451
|
+
return api.fetch(request);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** Advance every workflow that is due, then return: for the scheduled invocation. */
|
|
455
|
+
export async function advanceWorkflows() {
|
|
456
|
+
await ready;
|
|
457
|
+
const host = createWorkflowLifecycleHost({ store, scope, definitions, permissions, policyVersion: '1', maxCostMicros });
|
|
458
|
+
const leadership = createWorkflowLeadership({ store, scope, role: 'workflows', holderId: crypto.randomUUID() });
|
|
459
|
+
return createWorkflowWorker({ units: [host], leadership }).runOnce({ budgetMs: 50_000 });
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Vercel
|
|
464
|
+
|
|
465
|
+
A route for the API and a cron route for workflows, in a Next.js app on the Node.js runtime. The tested setup used plain
|
|
466
|
+
Vercel Functions (`api/*.js` files exporting `GET` and `POST`) that call the same two functions; the Next.js route
|
|
467
|
+
files and Vercel Cron are experimental.
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
// app/v1/[...path]/route.ts
|
|
471
|
+
import { handle } from '@/src/mayura';
|
|
472
|
+
|
|
473
|
+
export const runtime = 'nodejs';
|
|
474
|
+
export const maxDuration = 300; // seconds: above maxDurationMs plus requestTimeoutMs
|
|
475
|
+
export const GET = handle;
|
|
476
|
+
export const POST = handle;
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
```ts
|
|
480
|
+
// app/api/advance-workflows/route.ts
|
|
481
|
+
import { advanceWorkflows } from '@/src/mayura';
|
|
482
|
+
|
|
483
|
+
export const runtime = 'nodejs';
|
|
484
|
+
export const maxDuration = 60;
|
|
485
|
+
|
|
486
|
+
export async function GET(request: Request): Promise<Response> {
|
|
487
|
+
// Vercel sends your project's CRON_SECRET with every cron invocation; refuse anything else.
|
|
488
|
+
if (request.headers.get('authorization') !== `Bearer ${process.env['CRON_SECRET']}`) return new Response('Unauthorized', { status: 401 });
|
|
489
|
+
return Response.json(await advanceWorkflows());
|
|
490
|
+
}
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
```json
|
|
494
|
+
{ "crons": [{ "path": "/api/advance-workflows", "schedule": "* * * * *" }] }
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
The last block is `vercel.json`. Set `CRON_SECRET` in the project's environment variables. How often cron jobs may run
|
|
498
|
+
depends on your Vercel plan.
|
|
499
|
+
|
|
500
|
+
### AWS Lambda (experimental)
|
|
501
|
+
|
|
502
|
+
One function answers the API through a function URL; a second one, invoked every minute by EventBridge Scheduler,
|
|
503
|
+
advances workflows. Give the second a timeout above its budget, such as 60 seconds.
|
|
504
|
+
|
|
505
|
+
```ts
|
|
506
|
+
// api.ts: the handler of a Lambda function with a function URL
|
|
507
|
+
import type { APIGatewayProxyEventV2 } from 'aws-lambda';
|
|
508
|
+
import { handle } from './mayura.js';
|
|
509
|
+
|
|
510
|
+
export async function handler(event: APIGatewayProxyEventV2) {
|
|
511
|
+
const query = event.rawQueryString ? `?${event.rawQueryString}` : '';
|
|
512
|
+
const body = event.body === undefined ? undefined : event.isBase64Encoded ? Buffer.from(event.body, 'base64') : event.body;
|
|
513
|
+
const response = await handle(new Request(`https://${event.requestContext.domainName}${event.rawPath}${query}`,
|
|
514
|
+
{ method: event.requestContext.http.method, headers: event.headers as Record<string, string>, body }));
|
|
515
|
+
return { statusCode: response.status, headers: Object.fromEntries(response.headers), body: await response.text() };
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
```ts
|
|
520
|
+
// workflows.ts: the handler EventBridge Scheduler invokes every minute
|
|
521
|
+
import { advanceWorkflows } from './mayura.js';
|
|
522
|
+
|
|
523
|
+
export const handler = () => advanceWorkflows();
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
A buffered Lambda response delivers event streams only when they end; runs are request-bound, so `run.result()` is
|
|
527
|
+
ready as soon as the submission returns.
|
|
528
|
+
|
|
529
|
+
### Google Cloud Run (experimental)
|
|
530
|
+
|
|
531
|
+
Deploy the server as a service with request-based billing, where the CPU runs only during requests, and set
|
|
532
|
+
`runExecution: 'request'` as above; your module's `server()` can pass it to `listenProductionServer`. Advance workflows
|
|
533
|
+
with a Cloud Run job that runs `mayura worker --app dist/app.js --once --budget-ms 50000`, executed every minute by
|
|
534
|
+
Cloud Scheduler, and run `mayura migrate` as another job before each release. With instance-based billing, where the
|
|
535
|
+
CPU is always allocated, the [managed container](#managed-container-platforms) setup works as it is.
|
|
536
|
+
|
|
537
|
+
## Edge runtimes
|
|
538
|
+
|
|
539
|
+
Cloudflare Workers, Deno and Bun are not supported yet; support is planned for Mayura 1.1. The browser-safe
|
|
540
|
+
`mayura/client` already works anywhere `fetch` does, so an app on an edge runtime can call a Mayura server that runs on
|
|
541
|
+
one of the targets above.
|
|
542
|
+
|
|
543
|
+
## Environment and secrets
|
|
544
|
+
|
|
545
|
+
Mayura itself reads no environment variables. Your module decides what it reads, and nothing is discovered
|
|
546
|
+
implicitly: no config files, no default credentials. The starters use these names:
|
|
547
|
+
|
|
548
|
+
| Variable | Used for |
|
|
549
|
+
| --- | --- |
|
|
550
|
+
| `MAYURA_ENV` | `production` turns on the production server and the checks below. |
|
|
551
|
+
| `MAYURA_PUBLIC_ORIGIN` | The exact `https://` origin clients use. Required in production. |
|
|
552
|
+
| `PORT`, `MAYURA_BIND` | Where the server listens (default `8080` on `0.0.0.0`). |
|
|
553
|
+
| `MAYURA_ALLOWED_ORIGINS` | Comma-separated browser origins allowed to call the API. |
|
|
554
|
+
| `DATABASE_URL` | PostgreSQL. Without it the starters fall back to a local SQLite file. |
|
|
555
|
+
| `MAYURA_OPERATOR_TOKEN_SHA256` | Comma-separated SHA-256 digests of operator tokens. Several digests let you rotate. |
|
|
556
|
+
| `MAYURA_SESSION_SECRET` | The key that signs user sessions (support-agent starter). Same value on every replica. |
|
|
557
|
+
| `OPENAI_API_KEY`, `ANTHROPIC_API_KEY` | Model provider keys, plus price and cost-limit settings. |
|
|
558
|
+
| `MAYURA_WORKER_ID` | A stable name for the worker's leadership lease. Defaults to host name and process id. |
|
|
559
|
+
|
|
560
|
+
Validate configuration once at startup and fail fast. The starters do this with `validatedEnvironment` from
|
|
561
|
+
`mayura/helpers` and a Zod schema, and refuse to start in production without a public origin or operator token
|
|
562
|
+
digests. Keep secrets in your platform's secret store, never in the image, and never ship a server secret
|
|
563
|
+
or provider key to a browser. Each starter has `npm run token`, which prints a new token and the digest to configure.
|
|
564
|
+
|
|
565
|
+
## Probes
|
|
566
|
+
|
|
567
|
+
| Process | Endpoint | Answers 200 when |
|
|
568
|
+
| --- | --- | --- |
|
|
569
|
+
| Server | `GET /livez` | The process is up and not shutting down. |
|
|
570
|
+
| Server | `GET /readyz` | The server is accepting traffic and your `readiness` callback returned `true` within 2 seconds. |
|
|
571
|
+
| Worker | `GET /livez` on `--probe-port` | The worker is not stopping. |
|
|
572
|
+
| Worker | `GET /readyz` on `--probe-port` | The worker has started, is not draining, and has reached storage recently. |
|
|
573
|
+
|
|
574
|
+
Probes need no token, return only a status word, and skip the server's `Host` check, so orchestrators can call pods
|
|
575
|
+
directly. Worker probes are off unless you pass `--probe-port`; `--probe-host` defaults to `127.0.0.1`, so use
|
|
576
|
+
`0.0.0.0` inside a container.
|
|
577
|
+
|
|
578
|
+
## Graceful shutdown
|
|
579
|
+
|
|
580
|
+
On `SIGTERM` or `SIGINT`, the first signal starts a graceful stop and a second one forces the process to exit.
|
|
581
|
+
|
|
582
|
+
- **Server**: readiness fails at once so load balancers stop routing, the listener stops accepting, in-flight requests
|
|
583
|
+
get up to `shutdownGraceMs` (30 seconds by default) to finish, then open streams and runs are closed and your
|
|
584
|
+
`shutdown()` runs.
|
|
585
|
+
- **Worker**: readiness fails, work in progress gets up to `--drain-timeout-ms` (30 seconds by default, at most 300
|
|
586
|
+
seconds) to settle, the leadership lease is released so a standby takes over immediately, then `shutdown()` runs.
|
|
587
|
+
The CLI reports whether everything settled in time and how much work it had to interrupt.
|
|
588
|
+
|
|
589
|
+
Give containers a stop grace period longer than these timeouts (Docker's `stop_grace_period`, Kubernetes'
|
|
590
|
+
`terminationGracePeriodSeconds`). An effect that was in flight when a process died is never repeated. Once the tool's
|
|
591
|
+
timeout and a further minute have passed, the next worker pass records it as unknown for an operator to reconcile (see
|
|
592
|
+
[Workflow operations](workflow-operations.md)).
|
|
593
|
+
|
|
594
|
+
## PostgreSQL and scaling
|
|
595
|
+
|
|
596
|
+
Use PostgreSQL in production. The server, workers and migrations are separate processes that share workflow state,
|
|
597
|
+
idempotency records, the fleet hold and leadership leases through it. SQLite suits development and single-machine
|
|
598
|
+
setups. See [Storage](storage.md) for installation, backups and schema versions.
|
|
599
|
+
|
|
600
|
+
- **Workers** scale freely. Leadership lets one replica advance the fleet at a time, and a crashed leader's lease
|
|
601
|
+
expires so another takes over. Operators can hold the whole fleet from the console or CLI during an incident.
|
|
602
|
+
- **Servers** scale to several replicas behind a load balancer, with no sticky sessions. With `runRecords` (as in the
|
|
603
|
+
example), each agent run executes on the replica that accepted it, and any replica can read it, stream its events,
|
|
604
|
+
wait for it and cancel it; a retried submission on any replica gets the same run. If a replica dies, its runs end as
|
|
605
|
+
`outcome_unknown` once their lease lapses (30 seconds by default), never silently lost. Keep replica clocks in sync.
|
|
606
|
+
Work that must continue after its replica dies belongs in durable workflows. See
|
|
607
|
+
[Several server replicas](server-and-client.md#several-server-replicas).
|
|
608
|
+
|
|
609
|
+
## Production server settings
|
|
610
|
+
|
|
611
|
+
`listenProductionServer` has no hidden defaults for where it listens. The settings that matter most:
|
|
612
|
+
|
|
613
|
+
| Setting | Notes |
|
|
614
|
+
| --- | --- |
|
|
615
|
+
| `publicOrigin` | Exact `https://` origin. Requests with any other `Host` get 421. |
|
|
616
|
+
| `hostname`, `port` | Required bind address and port. |
|
|
617
|
+
| `tls` | `{ terminatedBy: 'proxy' }` behind a TLS proxy, or `{ key, cert }` to terminate TLS in the process (TLS 1.2 or later). |
|
|
618
|
+
| `readiness` | Checks your dependencies for `/readyz`, for example a storage read. |
|
|
619
|
+
| `shutdownGraceMs` | Default 30,000, at most 120,000. |
|
|
620
|
+
| `maxConnections` | Default 1,024. |
|
|
621
|
+
| `hstsMaxAgeSeconds` | Default one year; 0 turns the header off. |
|
|
622
|
+
| `limits` | Request, run, stream and size caps (see [Server and client](server-and-client.md)). |
|
|
623
|
+
| `allowedOrigins` | Browser origins other than `publicOrigin` allowed to call the API. |
|
|
624
|
+
| `trustedProxies` | IP addresses of proxies that rewrite `Host` and send `X-Forwarded-Host`. |
|
|
625
|
+
| `runRecords` | Durable agent run records, for several server replicas. |
|
|
626
|
+
|
|
627
|
+
Each registered agent also needs run `limits` that fit production, including `maxCostMicros` for paid models: the
|
|
628
|
+
default cost limit is 0. See [Costs and budgets](../concepts/costs-and-budgets.md).
|
|
629
|
+
|
|
630
|
+
## Good to know
|
|
631
|
+
|
|
632
|
+
- Mayura sends no telemetry. To export logs, traces or metrics, configure an exporter yourself (see
|
|
633
|
+
[Observability](observability.md)).
|
|
634
|
+
- The server does not serve your web app's static files. Serve them from your proxy or a static host.
|
|
635
|
+
- Keep every workflow definition version that still has runs in flight registered in `definitions`, on both server
|
|
636
|
+
and worker, until those runs finish or are migrated.
|
|
637
|
+
|
|
638
|
+
## Related
|
|
639
|
+
|
|
640
|
+
- [Server and client](server-and-client.md)
|
|
641
|
+
- [CLI: serve, worker and migrate](../cli/run.md)
|
|
642
|
+
- [Storage](storage.md)
|
|
643
|
+
- [Workflow operations](workflow-operations.md)
|
|
644
|
+
- [Observability](observability.md)
|