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
package/docs/cli/run.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Serve, worker and migrate"
|
|
3
|
+
description: "Run your application in production with mayura serve, mayura worker and mayura migrate, and write the module they load."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
In production a Mayura application usually runs as separate processes: one or more **servers** that answer HTTP
|
|
7
|
+
requests, one or more **workers** that advance durable workflows, and a **migration** step that updates the storage
|
|
8
|
+
schema before new code starts. The CLI runs each of these from one application module that you write:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
mayura migrate --app dist/src/app.js
|
|
12
|
+
mayura serve --app dist/src/app.js
|
|
13
|
+
mayura worker --app dist/src/app.js --probe-host 0.0.0.0 --probe-port 9090
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The CLI owns only the process lifecycle: starting, handling Ctrl+C or `SIGTERM`, graceful shutdown and worker probes.
|
|
17
|
+
Your module wires its own storage, agents, workflows and authentication with its own installed `mayura` package.
|
|
18
|
+
|
|
19
|
+
## The application module
|
|
20
|
+
|
|
21
|
+
The module's default export is an object with up to four functions. Wrap it in `defineMayuraApplication` from
|
|
22
|
+
`mayura/cli`, which checks the shape:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { defineMayuraApplication } from 'mayura/cli';
|
|
26
|
+
import { listenProductionServer } from 'mayura/server-node';
|
|
27
|
+
import { createWorkflowWorker } from 'mayura/workflows';
|
|
28
|
+
|
|
29
|
+
// openServices, agents, authenticate and workerUnits stand for your own code: storage, agent
|
|
30
|
+
// registrations, token verification and the workflow runtimes the worker drives.
|
|
31
|
+
let services: Promise<Services> | undefined;
|
|
32
|
+
const ready = () => (services ??= openServices());
|
|
33
|
+
|
|
34
|
+
export default defineMayuraApplication({
|
|
35
|
+
async server() {
|
|
36
|
+
await ready();
|
|
37
|
+
return listenProductionServer({
|
|
38
|
+
publicOrigin: 'https://agents.example.com',
|
|
39
|
+
hostname: '0.0.0.0',
|
|
40
|
+
port: 8080,
|
|
41
|
+
tls: { terminatedBy: 'proxy' },
|
|
42
|
+
agents,
|
|
43
|
+
authenticate,
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
async worker() {
|
|
47
|
+
return createWorkflowWorker({ units: workerUnits(await ready()) });
|
|
48
|
+
},
|
|
49
|
+
async migrate() {
|
|
50
|
+
await ready();
|
|
51
|
+
return { schemaVersion: 1 };
|
|
52
|
+
},
|
|
53
|
+
async shutdown() {
|
|
54
|
+
if (services) await (await services).close();
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
| Function | Used by | Must return |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| `server()` | `mayura serve` | A running server with `isAccepting()` and `close()`, such as the result of `listenProductionServer` from `mayura/server-node` |
|
|
62
|
+
| `worker()` | `mayura worker` | A worker with `start()`, `isReady()` and `drain()`, such as the result of `createWorkflowWorker` from `mayura/workflows` |
|
|
63
|
+
| `migrate()` | `mayura migrate` | Any JSON-serializable report, printed when the migration finishes |
|
|
64
|
+
| `shutdown()` | all three | Nothing. Runs last, after the server closes, the worker drains or the migration ends, for example to close storage. |
|
|
65
|
+
|
|
66
|
+
Define at least one function, and only these four. A command whose function is missing fails with `INVALID_CONFIG`,
|
|
67
|
+
for example `mayura worker` on a module without `worker`.
|
|
68
|
+
|
|
69
|
+
`--app` must name a single regular `.js` or `.mjs` file: build your TypeScript first. Directories, symbolic links and
|
|
70
|
+
other file types are refused, and the CLI imports nothing else. For a complete, working module, see `src/app.ts` in
|
|
71
|
+
any starter, such as
|
|
72
|
+
[approval-workflow](https://github.com/KartikeyAI/mayura/blob/main/packages/cli/starters/approval-workflow/src/app.ts).
|
|
73
|
+
|
|
74
|
+
## mayura serve
|
|
75
|
+
|
|
76
|
+
`mayura serve --app <module>` calls `server()` and keeps it running. On the first Ctrl+C or `SIGTERM` it closes the
|
|
77
|
+
server gracefully, then calls `shutdown()`. A second signal during shutdown forces the process to exit.
|
|
78
|
+
|
|
79
|
+
`listenProductionServer` stops accepting new requests, fails its readiness check so load balancers stop routing to
|
|
80
|
+
it, and drains in-flight requests before it closes. See [Deployment](../guides/deployment.md).
|
|
81
|
+
|
|
82
|
+
## mayura worker
|
|
83
|
+
|
|
84
|
+
`mayura worker --app <module>` calls `worker()`, then `start()`. On the first Ctrl+C or `SIGTERM` it drains the
|
|
85
|
+
worker, waiting for in-flight work to finish, then calls `shutdown()`.
|
|
86
|
+
|
|
87
|
+
| Option | Meaning |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `--drain-timeout-ms <ms>` | How long draining may take, from 1 to 300000. Default 30000. |
|
|
90
|
+
| `--probe-port <port>` | Serve HTTP health probes on this port. Off by default. |
|
|
91
|
+
| `--probe-host <host>` | The address the probes listen on. Default `127.0.0.1`. |
|
|
92
|
+
|
|
93
|
+
With `--probe-port`, the worker answers two probes for your orchestrator:
|
|
94
|
+
|
|
95
|
+
- `GET /livez` returns 200 while the process is running, and 503 once it starts stopping.
|
|
96
|
+
- `GET /readyz` returns 200 while the worker reports itself ready, and 503 when it does not, for example while it is
|
|
97
|
+
draining. A worker with a leadership lease is ready only while it can confirm the lease in storage.
|
|
98
|
+
|
|
99
|
+
The probe listener comes from `mayura/server-node` in your application's own installation, so `mayura` must be
|
|
100
|
+
installed alongside the module. In a container, use `--probe-host 0.0.0.0` so the orchestrator can reach it.
|
|
101
|
+
|
|
102
|
+
When the worker stops, it reports whether the drain finished in time, and how much work was interrupted if it did not.
|
|
103
|
+
|
|
104
|
+
### Run once
|
|
105
|
+
|
|
106
|
+
With `--once`, the worker advances everything that is due and exits, instead of running until it is stopped. Use it
|
|
107
|
+
from a scheduled job (a Cloud Run job, a Kubernetes CronJob) or a scheduler that starts a process every minute:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
mayura worker --app dist/src/app.js --once --budget-ms 50000
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
It takes the leadership lease once, runs passes until every host has completed a sweep of its runs or the budget runs
|
|
114
|
+
out, then releases the lease and calls `shutdown()`. A pass that has started finishes, so keep the budget below your
|
|
115
|
+
platform's time limit by at least your longest tool's `timeoutMs`. Each host keeps its place in storage, so if a sweep
|
|
116
|
+
does not finish, the next run continues from there rather than starting over.
|
|
117
|
+
|
|
118
|
+
| Option | Meaning |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `--once` | Advance what is due, then exit. Not with `--probe-port`, `--probe-host` or `--drain-timeout-ms`. |
|
|
121
|
+
| `--budget-ms <ms>` | Stop starting passes after this long, from 1000 to 3600000. Default 60000. |
|
|
122
|
+
|
|
123
|
+
It prints a report and its status:
|
|
124
|
+
|
|
125
|
+
| Status | Meaning | Exit code |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| `succeeded` | Every host completed a sweep. | 0 |
|
|
128
|
+
| `incomplete` | The budget ran out first; the next run continues. Run it more often or give it more time. | 0 |
|
|
129
|
+
| `standby` | Another replica holds the lease, so this run did nothing. | 0 |
|
|
130
|
+
| `held` | An operator holds the fleet, so nothing was driven. | 0 |
|
|
131
|
+
| `failed` | A pass failed, for example because storage was unavailable. | 1 |
|
|
132
|
+
|
|
133
|
+
The worker must come from `createWorkflowWorker`, whose `runOnce` this calls; in your own code, such as a scheduled
|
|
134
|
+
function, call `worker.runOnce({ budgetMs })` directly.
|
|
135
|
+
|
|
136
|
+
## mayura migrate
|
|
137
|
+
|
|
138
|
+
`mayura migrate --app <module>` calls `migrate()` once, then `shutdown()`, and exits. Nothing else starts. Run it
|
|
139
|
+
before deploying new code, for example as a release step or an init container:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
mayura migrate --app dist/src/app.js --json
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Migrations are explicit and one-way. Mayura's storage refuses data in a format or schema version it does not
|
|
146
|
+
support; see [Storage](../guides/storage.md).
|
|
147
|
+
|
|
148
|
+
## Output
|
|
149
|
+
|
|
150
|
+
In a terminal each command prints one line per stage:
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
● Worker started, probes on 0.0.0.0:9090. Press Ctrl+C to stop.
|
|
154
|
+
● Stopping… (press Ctrl+C again to force)
|
|
155
|
+
✔ Stopped
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
When output is piped, as in most deployments, each stage is one JSON line, then the command's final JSON document:
|
|
159
|
+
|
|
160
|
+
```text
|
|
161
|
+
{"event":"worker-started","probe":{"hostname":"0.0.0.0","port":9090}}
|
|
162
|
+
{"event":"stopping"}
|
|
163
|
+
{"event":"stopped","drained":true,"interrupted":0}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`serve` prints `serving`, `stopping` and `stopped` events. `migrate` prints `{ "status": "migrated", "report": <report> }`,
|
|
167
|
+
where the report is whatever your `migrate()` returned. See [CLI overview](overview.md) for exit codes and errors.
|
|
168
|
+
|
|
169
|
+
## Good to know
|
|
170
|
+
|
|
171
|
+
- `serve` and `worker` do not load `.env`. Set configuration in the real process environment. Only
|
|
172
|
+
[mayura dev](dev.md) reads `.env`.
|
|
173
|
+
- Run servers and workers as separate processes. With a leadership lease (`createWorkflowLeadership` from
|
|
174
|
+
`mayura/workflows`), several worker replicas can run without driving the same workflows twice.
|
|
175
|
+
|
|
176
|
+
## Related
|
|
177
|
+
|
|
178
|
+
- [Deployment](../guides/deployment.md)
|
|
179
|
+
- [Develop with mayura dev](dev.md)
|
|
180
|
+
- [Server and client](../guides/server-and-client.md)
|
|
181
|
+
- [Workflow operations](../guides/workflow-operations.md)
|
|
182
|
+
- [Storage](../guides/storage.md)
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Agents"
|
|
3
|
+
description: "Define an agent: instructions, a model, typed tools and typed input and output, checked once and reused for every run."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
An agent in Mayura is a definition: the instructions a model follows, the model adapter it calls, the tools it may
|
|
7
|
+
use, and the shape of its input and output. `defineAgent` checks the definition and freezes it. Nothing runs, no
|
|
8
|
+
connection opens and no tool is called until you submit the agent to a [runtime](./runtime.md). You define an agent
|
|
9
|
+
once, at module load, and submit it as many times as you like.
|
|
10
|
+
|
|
11
|
+
## A complete agent
|
|
12
|
+
|
|
13
|
+
This example runs offline. `scriptedModel` from `mayura/testing` is a test model that replays the responses you give
|
|
14
|
+
it, so you can see the whole loop without an API key. It does not read the instructions or reason.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createRuntime, defineAgent, defineTool, z } from 'mayura';
|
|
18
|
+
import { scriptedModel } from 'mayura/testing';
|
|
19
|
+
|
|
20
|
+
const add = defineTool({
|
|
21
|
+
id: 'math.add',
|
|
22
|
+
version: '1',
|
|
23
|
+
description: 'Add two numbers.',
|
|
24
|
+
input: z.object({ left: z.number(), right: z.number() }),
|
|
25
|
+
output: z.object({ sum: z.number() }),
|
|
26
|
+
effects: 'none',
|
|
27
|
+
capabilities: [],
|
|
28
|
+
execute: ({ left, right }) => ({ sum: left + right }),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const calculator = defineAgent({
|
|
32
|
+
id: 'calculator',
|
|
33
|
+
version: '1',
|
|
34
|
+
instructions: 'Use math.add to answer the question.',
|
|
35
|
+
input: z.object({ question: z.string() }),
|
|
36
|
+
output: z.object({ answer: z.number() }),
|
|
37
|
+
tools: [add],
|
|
38
|
+
model: scriptedModel([
|
|
39
|
+
{ type: 'tool_calls', calls: [{ id: 'call-1', toolId: 'math.add', input: { left: 2, right: 3 } }], usage: { costMicros: 0 } },
|
|
40
|
+
{ type: 'final', output: { answer: 5 }, usage: { costMicros: 0 } },
|
|
41
|
+
]),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const runtime = createRuntime({
|
|
45
|
+
profile: 'ephemeral',
|
|
46
|
+
permissions: { allow: ['model:scripted', 'tool:math.add'] },
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
const outcome = await runtime.submit(calculator, { input: { question: 'What is 2 + 3?' } }).result();
|
|
50
|
+
if (outcome.status === 'succeeded') console.log(outcome.output.answer); // 5, typed as number
|
|
51
|
+
else console.error(outcome.status, outcome.error.code);
|
|
52
|
+
} finally {
|
|
53
|
+
await runtime.close();
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The same file is in the repository as
|
|
58
|
+
[examples/first-agent.mjs](https://github.com/KartikeyAI/mayura/blob/main/examples/first-agent.mjs).
|
|
59
|
+
|
|
60
|
+
## Options
|
|
61
|
+
|
|
62
|
+
| Option | Required | What it is |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| `id` | yes | Stable name of the agent, for example `support.assistant`. |
|
|
65
|
+
| `version` | yes | Version of this definition, for example `1` or `2.1.0`. |
|
|
66
|
+
| `instructions` | yes | The system instructions sent to the model on every call. At most 64 KiB. |
|
|
67
|
+
| `model` | yes | A model adapter, for example `openAIResponses(...)` from `mayura/provider-openai`. |
|
|
68
|
+
| `tools` | yes | The tools this agent may call. Pass `[]` for none. At most 256, with unique ids. |
|
|
69
|
+
| `input` | yes | Schema for the input you submit. |
|
|
70
|
+
| `output` | yes | Schema for the final answer. |
|
|
71
|
+
| `guards` | no | `{ input, output }` lists of guards that can allow, block or rewrite content. At most 32 per list. |
|
|
72
|
+
| `hooks` | no | Lifecycle hooks created with `defineHook`. |
|
|
73
|
+
| `stream` | no | Stream one text field of the final answer while it is written. |
|
|
74
|
+
| `outputJsonSchema` | no | The output as JSON Schema for model providers. Generated from `output` when the validator can describe itself (Zod 4.2 and later). |
|
|
75
|
+
|
|
76
|
+
`defineAgent` throws a `MayuraError` with code `INVALID_CONFIG` if anything is wrong, for example a duplicate tool id,
|
|
77
|
+
a model that cannot call tools while `tools` is not empty, or a tool or output schema the model provider would refuse.
|
|
78
|
+
The message says what to fix.
|
|
79
|
+
|
|
80
|
+
## Ids and versions
|
|
81
|
+
|
|
82
|
+
`id` and `version` must start with a letter or digit and may contain letters, digits, `.`, `_`, `/` and `-`, up to 128
|
|
83
|
+
characters. The id appears in run events, in `runtime.inspect()` and in durable records, so treat it as a stable name:
|
|
84
|
+
don't rename an agent in production without a reason. Change the version when the behavior changes, for example new
|
|
85
|
+
instructions, a new tool or a changed output schema, so records made by the old definition stay distinguishable.
|
|
86
|
+
|
|
87
|
+
## Instructions
|
|
88
|
+
|
|
89
|
+
`instructions` is a plain string sent as the system prompt. It guides the model; it does not grant or restrict
|
|
90
|
+
anything. What the agent is actually allowed to do comes from the runtime's [permissions](./permissions.md), so a
|
|
91
|
+
prompt injection in the user's input or in a tool result cannot give the agent new authority. Don't put secrets in
|
|
92
|
+
instructions.
|
|
93
|
+
|
|
94
|
+
## Input and output schemas
|
|
95
|
+
|
|
96
|
+
`input` and `output` accept any [Standard Schema](https://standardschema.dev) validator. Zod is the reference
|
|
97
|
+
validator and the one used throughout these docs. TypeScript infers the types from the schemas: `submit` checks the
|
|
98
|
+
input you pass, and a successful outcome's `output` has the output type.
|
|
99
|
+
|
|
100
|
+
Mayura validates at every boundary:
|
|
101
|
+
|
|
102
|
+
- The submitted input is checked before the model is called. Invalid input ends the run with `INVALID_INPUT`.
|
|
103
|
+
- The model's final answer is checked against `output` before it is released. An invalid answer ends the run with
|
|
104
|
+
`INVALID_OUTPUT`; a run never reports success with an output that does not match.
|
|
105
|
+
|
|
106
|
+
Values must be plain JSON: strings, finite numbers, booleans, `null`, arrays and plain objects. Dates, class instances,
|
|
107
|
+
`undefined` and `bigint` are rejected. Size limits come from the runtime (`maxInputBytes`, `maxOutputBytes`).
|
|
108
|
+
|
|
109
|
+
Real model providers also need the output shape as JSON Schema. Mayura generates it from `output` (validators that
|
|
110
|
+
implement Standard JSON Schema can describe themselves, as Zod 4.2 and later do) and sends it with every model call;
|
|
111
|
+
you can see it as `agent.outputJsonSchema`. Providers accept only strict schemas, so use `.nullable()` rather than
|
|
112
|
+
`.optional()` for fields the model may leave empty; `defineAgent` checks this with the model you give it. Pass
|
|
113
|
+
`outputJsonSchema` yourself only when your validator cannot describe itself. The validator is still what Mayura
|
|
114
|
+
enforces on the answer.
|
|
115
|
+
|
|
116
|
+
## The model
|
|
117
|
+
|
|
118
|
+
`model` is a model adapter: an object with an `id`, its capabilities, a per-call cost ceiling (`maxCostMicros`) and a
|
|
119
|
+
`generate` function. Mayura never picks a provider for you. The adapter's id is what you allow in the runtime, as
|
|
120
|
+
`model:<adapter id>`: `model:openai.responses`, `model:anthropic.messages`, `model:scripted`.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { defineAgent, z } from 'mayura';
|
|
124
|
+
import { openAIResponses } from 'mayura/provider-openai';
|
|
125
|
+
|
|
126
|
+
const answerer = defineAgent({
|
|
127
|
+
id: 'answerer',
|
|
128
|
+
version: '1',
|
|
129
|
+
instructions: 'Answer the question in one or two sentences.',
|
|
130
|
+
input: z.object({ question: z.string().min(1).max(2_000) }),
|
|
131
|
+
output: z.object({ answer: z.string() }),
|
|
132
|
+
tools: [],
|
|
133
|
+
model: openAIResponses({
|
|
134
|
+
apiKey: process.env.OPENAI_API_KEY ?? '',
|
|
135
|
+
model: 'gpt-5-mini',
|
|
136
|
+
maxCostMicros: 20_000, // at most $0.02 per model call
|
|
137
|
+
pricing: { inputMicrosPerMillionTokens: 250_000, outputMicrosPerMillionTokens: 2_000_000 },
|
|
138
|
+
timeoutMs: 30_000,
|
|
139
|
+
}),
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Use your model's real prices; the numbers above are placeholders. A paid model also needs a run cost limit on the
|
|
144
|
+
runtime, because the default is 0: see [Costs and budgets](./costs-and-budgets.md). Providers, routing between them
|
|
145
|
+
and fallbacks are covered in [Model providers](../guides/model-providers.md) and
|
|
146
|
+
[Model routing](../guides/model-routing.md).
|
|
147
|
+
|
|
148
|
+
## Tools
|
|
149
|
+
|
|
150
|
+
`tools` is the complete list of tools this agent can call. The model only sees these tools, and a request for any
|
|
151
|
+
other tool id ends the run with `NOT_FOUND`. Listing a tool does not permit it: the runtime must also allow
|
|
152
|
+
`tool:<id>` and the tool's other requirements. See [Tools](./tools.md) and [Permissions](./permissions.md).
|
|
153
|
+
|
|
154
|
+
## How a run works
|
|
155
|
+
|
|
156
|
+
When you submit an agent, the runtime loops over steps until the model gives a final answer or a limit is reached:
|
|
157
|
+
|
|
158
|
+
1. Validate the input against `input`, then run the input guards.
|
|
159
|
+
2. Check that `model:<adapter id>` is allowed and that the run's call and cost limits leave room for one more model
|
|
160
|
+
call. The model call's `maxCostMicros` is reserved from the run budget before the call.
|
|
161
|
+
3. Call the model with the instructions, the conversation so far and the tool list (id, description and
|
|
162
|
+
`inputJsonSchema` of each tool). Its actual cost is charged.
|
|
163
|
+
4. If the model asks for tools, check every requested call first: the tool is registered, allowed, and its input
|
|
164
|
+
matches its schema, and the total cost of the batch fits the budget. Then run the calls one at a time. Each result
|
|
165
|
+
is validated against the tool's output schema and passed through the agent's output guards before the model sees
|
|
166
|
+
it. If any call does not succeed, the run ends with that call's outcome.
|
|
167
|
+
5. Go back to step 2 with the tool results added to the conversation.
|
|
168
|
+
6. If the model gives a final answer, validate it against `output`, run the output guards and return it.
|
|
169
|
+
|
|
170
|
+
If `maxSteps` (default 16) is reached without a final answer, the run fails with `LIMIT_EXCEEDED`. Every run ends
|
|
171
|
+
with one of the outcomes described in [Outcomes and errors](./outcomes.md).
|
|
172
|
+
|
|
173
|
+
## Guards, hooks and streaming
|
|
174
|
+
|
|
175
|
+
- **Guards** check content at the edges of a run. Input guards see the submitted input; output guards see the final
|
|
176
|
+
answer and every tool result before the model does. A guard can allow, block (the run ends as `blocked`) or rewrite,
|
|
177
|
+
for example to redact personal data. See [Guardrails](../guides/guardrails.md).
|
|
178
|
+
- **Hooks** run your code at points in the run's life, such as before each tool call or after the run finishes, and
|
|
179
|
+
can stop the run. See [Lifecycle hooks](../guides/lifecycle-hooks.md).
|
|
180
|
+
- **Streaming** releases one string field of the final answer in small checked batches while the model writes it.
|
|
181
|
+
Without `stream`, nothing is released until the whole answer has passed validation and guards. See
|
|
182
|
+
[Streaming](../guides/streaming.md).
|
|
183
|
+
|
|
184
|
+
## Good to know
|
|
185
|
+
|
|
186
|
+
- A definition is immutable. To change an agent, define a new one (usually with a new version).
|
|
187
|
+
- Tools run in your process as ordinary JavaScript. Declaring `effects: 'none'` is a promise you make, not a sandbox.
|
|
188
|
+
- An agent can call another agent as a tool, with narrower permissions. See [Child agents](../guides/child-agents.md).
|
|
189
|
+
- In tests, `scriptedModel` lets you script the exact tool calls and answers. See [Testing](../guides/testing.md).
|
|
190
|
+
|
|
191
|
+
## Related
|
|
192
|
+
|
|
193
|
+
- [Tools](./tools.md)
|
|
194
|
+
- [Runtime](./runtime.md)
|
|
195
|
+
- [Permissions](./permissions.md)
|
|
196
|
+
- [Model providers](../guides/model-providers.md)
|
|
197
|
+
- [Quickstart](../quickstart.md)
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Costs and budgets"
|
|
3
|
+
description: "Cap what a run can spend: costs in micros, per-call ceilings, the run cost limit, tool costs and shared budgets."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Mayura counts money in **micros**: millionths of a US dollar, as integers. Every model call and tool call declares the
|
|
7
|
+
most it can cost. Before a call starts, the runtime reserves that amount from the run's budget; after it finishes, it
|
|
8
|
+
charges the actual cost and releases the rest. A call that does not fit in what is left never starts.
|
|
9
|
+
|
|
10
|
+
The run budget comes from the runtime's `limits.maxCostMicros`, and its default is **0**. Free calls work without it
|
|
11
|
+
(the scripted test model costs 0), but a paid model is refused until you set a limit.
|
|
12
|
+
|
|
13
|
+
## A budgeted agent
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createRuntime, defineAgent, z } from 'mayura';
|
|
17
|
+
import { openAIResponses } from 'mayura/provider-openai';
|
|
18
|
+
|
|
19
|
+
const agent = defineAgent({
|
|
20
|
+
id: 'summarizer',
|
|
21
|
+
version: '1',
|
|
22
|
+
instructions: 'Summarize the text in three sentences.',
|
|
23
|
+
input: z.object({ text: z.string().max(40_000) }),
|
|
24
|
+
output: z.object({ summary: z.string() }),
|
|
25
|
+
tools: [],
|
|
26
|
+
model: openAIResponses({
|
|
27
|
+
apiKey: process.env.OPENAI_API_KEY ?? '',
|
|
28
|
+
model: 'gpt-5-mini',
|
|
29
|
+
// Your model's real prices, in micros per million tokens. $0.25 per million = 250_000.
|
|
30
|
+
pricing: { inputMicrosPerMillionTokens: 250_000, outputMicrosPerMillionTokens: 2_000_000 },
|
|
31
|
+
maxCostMicros: 20_000, // one call may cost at most $0.02
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const runtime = createRuntime({
|
|
36
|
+
profile: 'ephemeral',
|
|
37
|
+
permissions: { allow: ['model:openai.responses'] },
|
|
38
|
+
limits: { maxCostMicros: 50_000, maxModelCalls: 2, maxOutputTokens: 1_024 }, // the whole run: at most $0.05
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const run = runtime.submit(agent, { input: { text: 'A long article to summarize.' } });
|
|
42
|
+
const outcome = await run.result();
|
|
43
|
+
console.log(outcome.status, runtime.inspect(run).budget);
|
|
44
|
+
await runtime.close();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Micros
|
|
48
|
+
|
|
49
|
+
| Amount | Micros |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| $1 | `1_000_000` |
|
|
52
|
+
| 1 cent | `10_000` |
|
|
53
|
+
| $0.001 | `1_000` |
|
|
54
|
+
| 1 micro | $0.000001 |
|
|
55
|
+
|
|
56
|
+
Costs are whole numbers, so there is no rounding drift. Values must be non-negative safe integers.
|
|
57
|
+
|
|
58
|
+
## Model pricing and the per-call ceiling
|
|
59
|
+
|
|
60
|
+
A provider adapter such as `openAIResponses` takes the model's prices in micros per million tokens and computes each
|
|
61
|
+
call's cost from the token counts the provider reports:
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
cost = (input tokens × input price + output tokens × output price) / 1,000,000, rounded up
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The adapter's `maxCostMicros` is the ceiling for one call. The runtime reserves it before every call, so choose it from
|
|
68
|
+
the worst case: the largest input you expect plus `maxOutputTokens` of output. With the prices above, 20,000 input
|
|
69
|
+
tokens and 4,096 output tokens cost 5,000 + 8,192 = 13,192 micros, so a ceiling of 20,000 leaves room.
|
|
70
|
+
|
|
71
|
+
Mayura cannot stop a provider from charging more than you expected. If a call's actual cost is above its ceiling, the
|
|
72
|
+
full cost is still recorded, the run ends as `blocked` with `BUDGET_EXCEEDED`, and the run's budget accepts no further
|
|
73
|
+
calls.
|
|
74
|
+
|
|
75
|
+
The prices are the ones you configure. Mayura does not look them up, and its totals are an estimate from your prices,
|
|
76
|
+
not your provider's invoice.
|
|
77
|
+
|
|
78
|
+
## The run cost limit
|
|
79
|
+
|
|
80
|
+
`limits.maxCostMicros` caps the total cost of one run, including its child runs. It is per run, not per runtime: every
|
|
81
|
+
`submit` starts with a fresh budget of that size.
|
|
82
|
+
|
|
83
|
+
Before each model call, the runtime checks that the model's `maxCostMicros` fits in what is left. Before running a
|
|
84
|
+
batch of tool calls the model asked for, it checks that the `costMicros` of all of them fits. If not, the run ends as
|
|
85
|
+
`blocked` with `BUDGET_EXCEEDED`, and the call is not made.
|
|
86
|
+
|
|
87
|
+
So set the run limit to at least the per-call ceiling times the number of model calls you expect, plus your tools'
|
|
88
|
+
costs. In the example above, two calls of at most 20,000 micros fit in 50,000.
|
|
89
|
+
|
|
90
|
+
## Tool costs
|
|
91
|
+
|
|
92
|
+
A tool's `costMicros` (default 0) is the most one call can cost, for tools that spend money themselves: a paid API, an
|
|
93
|
+
SMS, a search query. It is reserved before the tool runs. If the tool does not say otherwise, a successful call is
|
|
94
|
+
charged the full amount. To charge less, report the real cost once from inside `execute`:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { defineTool, z } from 'mayura';
|
|
98
|
+
|
|
99
|
+
export const sendSms = defineTool({
|
|
100
|
+
id: 'sms.send',
|
|
101
|
+
version: '1',
|
|
102
|
+
description: 'Send a text message to the signed-in customer.',
|
|
103
|
+
input: z.object({ text: z.string().max(320) }),
|
|
104
|
+
output: z.object({ segments: z.number() }),
|
|
105
|
+
effects: 'write',
|
|
106
|
+
capabilities: ['sms:send'],
|
|
107
|
+
costMicros: 30_000, // at most 3 cents
|
|
108
|
+
execute: async ({ text }, context) => {
|
|
109
|
+
const sent = await sms.send(context.scope.principalId, text, { signal: context.signal });
|
|
110
|
+
context.reportUsage({ knownCostMicros: sent.segments * 7_500, unknownCostMicros: 0 });
|
|
111
|
+
return { segments: sent.segments };
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Reported cost may not exceed `costMicros`. Reporting `unknownCostMicros` above 0 says part of the cost is not settled,
|
|
117
|
+
and the call ends as `outcome_unknown`.
|
|
118
|
+
|
|
119
|
+
## When the cost is unknown
|
|
120
|
+
|
|
121
|
+
Sometimes Mayura cannot know what a call cost: a model call failed without the provider reporting usage, or a tool
|
|
122
|
+
with effects threw or timed out. Then the call's full ceiling stays reserved. It shows up as `reservedMicros` and still
|
|
123
|
+
counts against the budget. A timeout, a cancellation or closing the runtime never turns an unknown cost into zero.
|
|
124
|
+
|
|
125
|
+
If you write a model adapter, throw `ModelInvocationError` with the known cost when a call fails after the provider
|
|
126
|
+
reported usage, so that amount is charged instead of the whole ceiling.
|
|
127
|
+
|
|
128
|
+
## Reading costs
|
|
129
|
+
|
|
130
|
+
`runtime.inspect(run).budget` gives the run's totals, including its children, and the `run.completed` event carries
|
|
131
|
+
the same numbers:
|
|
132
|
+
|
|
133
|
+
| Field | What it is |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| `spentMicros` | Confirmed cost. A decimal string instead of a number if it ever exceeds the safe integer range. |
|
|
136
|
+
| `reservedMicros` | Held for calls in progress, and for calls whose cost is unknown. |
|
|
137
|
+
| `calls` | Model and tool calls started. |
|
|
138
|
+
|
|
139
|
+
## Budgets across runs
|
|
140
|
+
|
|
141
|
+
The runtime has no budget shared across runs. For a ceiling across many runs or your own calls, Mayura has two
|
|
142
|
+
building blocks:
|
|
143
|
+
|
|
144
|
+
- **`Budget`**, from `mayura`, is an in-memory budget with a cost ceiling and a call ceiling. `reserve(maxMicros)`
|
|
145
|
+
throws `BUDGET_EXCEEDED` if a call does not fit; `settle(actual)` on the returned reservation records what it cost.
|
|
146
|
+
`fork({ id, maxCostMicros, maxCalls })` makes a child budget that spends from the same funds with a lower ceiling.
|
|
147
|
+
`invokeTool`, `invokeBatch` and `runBudgetedTasks` from `mayura/helpers` take a `Budget`.
|
|
148
|
+
- **Durable budgets** keep the same kind of ledger in SQLite or PostgreSQL through `store.durableBudgets`, so it
|
|
149
|
+
survives restarts. See [Storage](../guides/storage.md).
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { Budget } from 'mayura';
|
|
153
|
+
|
|
154
|
+
const nightly = new Budget(5_000_000, 500); // $5 and 500 calls in total
|
|
155
|
+
const perTeam = nightly.fork({ id: 'team-a', maxCostMicros: 1_000_000, maxCalls: 100 });
|
|
156
|
+
|
|
157
|
+
const reservation = perTeam.reserve(20_000);
|
|
158
|
+
reservation.settle(12_400); // the confirmed cost
|
|
159
|
+
console.log(nightly.snapshot()); // { spentMicros: 12400, reservedMicros: 0, calls: 1 }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Totals of a budget include its children; don't add a parent's and a child's numbers together.
|
|
163
|
+
|
|
164
|
+
## Good to know
|
|
165
|
+
|
|
166
|
+
- Costs are checked before each call. A single call can still overrun its ceiling; Mayura records it and stops the
|
|
167
|
+
run, but cannot undo the charge.
|
|
168
|
+
- `maxModelCalls`, `maxToolCalls` and `maxSteps` bound a run even when every call is free.
|
|
169
|
+
- Workflows take their own cost limits. See [Workflows](./workflows.md).
|
|
170
|
+
|
|
171
|
+
## Related
|
|
172
|
+
|
|
173
|
+
- [Runtime](./runtime.md)
|
|
174
|
+
- [Tools](./tools.md)
|
|
175
|
+
- [Model providers](../guides/model-providers.md)
|
|
176
|
+
- [Model routing](../guides/model-routing.md)
|
|
177
|
+
- [Helpers](../guides/helpers.md)
|