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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ModelAdapter, ModelRequest, ModelResponse } from 'mayura/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { defineAgent, defineTool, z } from 'mayura';
|
|
3
|
+
import { agentStep } from 'mayura/workflows/lifecycle';
|
|
4
4
|
import type { ModelSettings } from './config.js';
|
|
5
5
|
import { jsonSchema, modelPermission, selectModel } from './model.js';
|
|
6
6
|
import type { TrackerTools } from './tracker-tools.js';
|
|
@@ -76,29 +76,22 @@ export function triageAgent(dependencies: TriageDependencies) {
|
|
|
76
76
|
export type TriageAgent = ReturnType<typeof triageAgent>;
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* The agent as one durable workflow step. The step
|
|
80
|
-
*
|
|
81
|
-
*
|
|
79
|
+
* The agent as one durable workflow step (`agentStep`). The step runs the agent with its own grants and limits in the
|
|
80
|
+
* run's scope, and charges the run what the agent spent. Its outcome follows the agent's:
|
|
81
|
+
*
|
|
82
|
+
* - the agent failed or was refused a tool: the step fails. Every tracker call it made has a known result, so nothing
|
|
83
|
+
* needs reconciling, although labels or comments it already added stay on the ticket;
|
|
84
|
+
* - a tracker call's result is unknown (the tracker did not answer), or the step was interrupted while the agent could
|
|
85
|
+
* be mid-call (a timeout, a cancelled run): the step is unknown and the run ends `outcome_unknown`, for an operator
|
|
86
|
+
* to reconcile. The workflow never runs the agent again on its own.
|
|
87
|
+
*
|
|
88
|
+
* The agent's tools write, so the workflow must also grant `effect:write` to run this step.
|
|
82
89
|
*/
|
|
83
90
|
export function triagePhase(triage: TriageAgent) {
|
|
84
|
-
return
|
|
85
|
-
id: 'tickets.triage.run', version: '1',
|
|
91
|
+
return agentStep(triage.agent, {
|
|
92
|
+
id: 'tickets.triage.run', version: '1', capabilities: ['tickets:triage'],
|
|
86
93
|
description: 'Run the triage agent on one new ticket.',
|
|
87
|
-
|
|
88
|
-
input: ticket, output: triageOutput,
|
|
89
|
-
execute: async (input, context) => {
|
|
90
|
-
const runtime = createRuntime({ profile: 'ephemeral', scope: context.scope, permissions: { allow: triage.grants }, limits: triage.limits });
|
|
91
|
-
const stop = (): void => { void runtime.close(); };
|
|
92
|
-
context.signal.addEventListener('abort', stop, { once: true });
|
|
93
|
-
try {
|
|
94
|
-
const run = runtime.submit(triage.agent, { input });
|
|
95
|
-
const outcome = await run.result();
|
|
96
|
-
const spent = runtime.inspect(run).budget.spentMicros;
|
|
97
|
-
if (typeof spent === 'number') context.reportUsage({ knownCostMicros: spent, unknownCostMicros: 0 });
|
|
98
|
-
if (outcome.status !== 'succeeded') throw new Error(`The triage agent stopped (${outcome.status}).`);
|
|
99
|
-
return outcome.output;
|
|
100
|
-
} finally { context.signal.removeEventListener('abort', stop); await runtime.close(); }
|
|
101
|
-
},
|
|
94
|
+
permissions: triage.grants, limits: triage.limits, timeoutMs: 90_000,
|
|
102
95
|
});
|
|
103
96
|
}
|
|
104
97
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnyTool } from 'mayura';
|
|
2
2
|
import { defineWorkflowLifecycle } from 'mayura/workflows/lifecycle';
|
|
3
|
-
import { z } from '
|
|
3
|
+
import { z } from 'mayura';
|
|
4
4
|
import type { TrackerTools } from './tracker-tools.js';
|
|
5
5
|
import { ticket, triageOutput } from './triage.js';
|
|
6
6
|
import { assignee, ticketId } from './tracker/tickets.js';
|
|
@@ -146,13 +146,13 @@ describe('ticket automation', () => {
|
|
|
146
146
|
assert.deepEqual(withoutAssign.tickets.operations().filter(entry => entry.operation === 'assign'), []);
|
|
147
147
|
} finally { await withoutAssign.close(); }
|
|
148
148
|
|
|
149
|
-
// Without `tickets:write`, the agent's first label call is refused before any MCP request. The
|
|
150
|
-
//
|
|
149
|
+
// Without `tickets:write`, the agent's first label call is refused before any MCP request. The agent is blocked with
|
|
150
|
+
// a known outcome, so the triage step fails cleanly: there is nothing to reconcile, and the tracker shows nothing.
|
|
151
151
|
const withoutWrite = await harness({ revoke: ['tickets:write'] });
|
|
152
152
|
try {
|
|
153
153
|
const runId = runIdOf(await withoutWrite.deliver('billing'));
|
|
154
154
|
const stopped = await withoutWrite.settle(runId);
|
|
155
|
-
assert.equal(stopped.status, '
|
|
155
|
+
assert.equal(stopped.status, 'failed');
|
|
156
156
|
assert.deepEqual(withoutWrite.tickets.operations(), []);
|
|
157
157
|
} finally { await withoutWrite.close(); }
|
|
158
158
|
});
|
|
@@ -91,8 +91,8 @@ machinery without solving variable fan-out. *Graphs* add waits on other runs, wh
|
|
|
91
91
|
lower-level primitive whose guide warns that calling it separately from the workflow is not a restart-safe
|
|
92
92
|
integration; the lifecycle budget is written in the same record update that claims each step.
|
|
93
93
|
|
|
94
|
-
**One shared budget.** `RESEARCH_BUDGET_MICROS` is the budget of a whole research run. Every agent step
|
|
95
|
-
ceiling (`MAYURA_MAX_RUN_COST_MICROS`, which is also the agent's own `maxCostMicros`). Before a step runs, the runtime
|
|
94
|
+
**One shared budget.** `RESEARCH_BUDGET_MICROS` is the budget of a whole research run. Every agent step (`agentStep` from
|
|
95
|
+
`mayura/workflows/lifecycle`) declares a ceiling (`MAYURA_MAX_RUN_COST_MICROS`, which is also the agent's own `maxCostMicros`). Before a step runs, the runtime
|
|
96
96
|
reserves its ceiling from what the run has left, in the same storage write that claims the step; when the step
|
|
97
97
|
completes, the run is charged what it reported spending and the rest of the reservation is released. When the rest of the
|
|
98
98
|
budget cannot cover a step, that step is `blocked` with code `BUDGET_EXCEEDED`, every later step is skipped, and the
|
|
@@ -31,6 +31,17 @@ MAYURA_MODEL_PROVIDER=offline
|
|
|
31
31
|
# MAYURA_MODEL_PROVIDER_ID=groq
|
|
32
32
|
# MAYURA_MODEL_AUTH=bearer
|
|
33
33
|
# MAYURA_MODEL_API_KEY=
|
|
34
|
+
# DeepSeek answers in JSON mode and has strict tools on https://api.deepseek.com/beta/chat/completions:
|
|
35
|
+
# MAYURA_MODEL_OUTPUT=json_object
|
|
36
|
+
# MAYURA_MODEL_STRICT_TOOLS=true
|
|
37
|
+
# OpenAI's newer models (directly or as openai/... through a gateway) take only max_completion_tokens:
|
|
38
|
+
# MAYURA_MODEL_TOKEN_LIMIT_FIELD=max_completion_tokens
|
|
39
|
+
# OpenAI or Anthropic through a gateway: MAYURA_MODEL_PROVIDER=openai or anthropic, MAYURA_MODEL_ENDPOINT set to its
|
|
40
|
+
# endpoint (for Cloudflare, https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/openai/responses or
|
|
41
|
+
# .../anthropic/v1/messages) and MAYURA_MODEL_GATEWAY_TOKEN; the provider key may then stay in the gateway.
|
|
42
|
+
# Cloudflare AI Gateway: https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/compat/chat/completions, models named
|
|
43
|
+
# provider/model, and the gateway token of an authenticated gateway (the API key may stay in the gateway):
|
|
44
|
+
# MAYURA_MODEL_GATEWAY_TOKEN=
|
|
34
45
|
# MAYURA_MODEL=
|
|
35
46
|
# Prices in micro-dollars per million tokens, and the most one model call and one agent step may cost.
|
|
36
47
|
# MAYURA_MODEL_INPUT_MICROS_PER_MILLION_TOKENS=
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validatedEnvironment } from 'mayura/helpers';
|
|
2
|
-
import { z } from '
|
|
2
|
+
import { z } from 'mayura';
|
|
3
3
|
|
|
4
4
|
// Every setting comes from the environment and is validated once at startup. Nothing is discovered implicitly:
|
|
5
5
|
// no config files, no default credentials, and no provider or collector is contacted unless the environment says so.
|
|
@@ -35,6 +35,13 @@ const schema = z.object({
|
|
|
35
35
|
compatibleId: z.string().regex(/^[a-z0-9][a-z0-9-]{0,39}$/u, 'Use a short lower-case id such as groq.').optional(),
|
|
36
36
|
compatibleAuth: z.enum(['bearer', 'api-key']).default('bearer'),
|
|
37
37
|
compatibleApiKey: z.string().min(1).optional(),
|
|
38
|
+
// How the provider differs from OpenAI: JSON mode instead of JSON Schema output (DeepSeek), strict tool calls, and
|
|
39
|
+
// a Cloudflare AI Gateway token (sent as cf-aig-authorization; with keys stored in the gateway, no API key is needed).
|
|
40
|
+
compatibleOutput: z.enum(['json_schema', 'json_object']).default('json_schema'),
|
|
41
|
+
compatibleStrictTools: z.enum(['true', 'false']).default('false'),
|
|
42
|
+
// The field for the output-token limit: OpenAI's newer models (also through a gateway) take only max_completion_tokens.
|
|
43
|
+
compatibleTokenLimitField: z.enum(['max_tokens', 'max_completion_tokens']).optional(),
|
|
44
|
+
gatewayToken: z.string().min(1).optional(),
|
|
38
45
|
modelName: z.string().min(1).max(128).optional(),
|
|
39
46
|
inputMicrosPerMillionTokens: micros.optional(),
|
|
40
47
|
outputMicrosPerMillionTokens: micros.optional(),
|
|
@@ -48,10 +55,14 @@ const schema = z.object({
|
|
|
48
55
|
|
|
49
56
|
export type ModelSettings =
|
|
50
57
|
| { readonly provider: 'offline' }
|
|
51
|
-
|
|
58
|
+
// OpenAI or Anthropic directly, or through a gateway: its endpoint (MAYURA_MODEL_ENDPOINT) and token.
|
|
59
|
+
| { readonly provider: 'openai' | 'anthropic'; readonly apiKey: string | undefined; readonly name: string; readonly maxCallCostMicros: number;
|
|
60
|
+
readonly endpoint: string | undefined; readonly gatewayToken: string | undefined;
|
|
52
61
|
readonly pricing: { readonly inputMicrosPerMillionTokens: number; readonly outputMicrosPerMillionTokens: number } }
|
|
53
|
-
| { readonly provider: 'compatible'; readonly apiKey: string; readonly name: string; readonly maxCallCostMicros: number;
|
|
62
|
+
| { readonly provider: 'compatible'; readonly apiKey: string | undefined; readonly name: string; readonly maxCallCostMicros: number;
|
|
54
63
|
readonly endpoint: string; readonly providerId: string; readonly auth: 'bearer' | 'api-key';
|
|
64
|
+
readonly output: 'json_schema' | 'json_object'; readonly strictTools: boolean; readonly gatewayToken: string | undefined;
|
|
65
|
+
readonly tokenLimitField: 'max_tokens' | 'max_completion_tokens' | undefined;
|
|
55
66
|
readonly pricing: { readonly inputMicrosPerMillionTokens: number; readonly outputMicrosPerMillionTokens: number } };
|
|
56
67
|
|
|
57
68
|
/** Where metadata-only traces go. Absent means telemetry is off and nothing is collected. */
|
|
@@ -92,7 +103,8 @@ export async function loadConfig(source: Readonly<Record<string, string | undefi
|
|
|
92
103
|
artifactsDirectory: 'RESEARCH_ARTIFACTS_DIR', port: 'PORT', bind: 'MAYURA_BIND', publicOrigin: 'MAYURA_PUBLIC_ORIGIN',
|
|
93
104
|
allowedOrigins: 'MAYURA_ALLOWED_ORIGINS', operatorTokens: 'MAYURA_OPERATOR_TOKEN_SHA256', deskTokens: 'MAYURA_DESK_TOKEN_SHA256',
|
|
94
105
|
modelProvider: 'MAYURA_MODEL_PROVIDER', openaiApiKey: 'OPENAI_API_KEY', anthropicApiKey: 'ANTHROPIC_API_KEY',
|
|
95
|
-
compatibleEndpoint: 'MAYURA_MODEL_ENDPOINT', compatibleId: 'MAYURA_MODEL_PROVIDER_ID', compatibleAuth: 'MAYURA_MODEL_AUTH', compatibleApiKey: 'MAYURA_MODEL_API_KEY',
|
|
106
|
+
compatibleEndpoint: 'MAYURA_MODEL_ENDPOINT', compatibleId: 'MAYURA_MODEL_PROVIDER_ID', compatibleAuth: 'MAYURA_MODEL_AUTH', compatibleApiKey: 'MAYURA_MODEL_API_KEY',
|
|
107
|
+
compatibleOutput: 'MAYURA_MODEL_OUTPUT', compatibleStrictTools: 'MAYURA_MODEL_STRICT_TOOLS', compatibleTokenLimitField: 'MAYURA_MODEL_TOKEN_LIMIT_FIELD', gatewayToken: 'MAYURA_MODEL_GATEWAY_TOKEN', modelName: 'MAYURA_MODEL',
|
|
96
108
|
inputMicrosPerMillionTokens: 'MAYURA_MODEL_INPUT_MICROS_PER_MILLION_TOKENS', outputMicrosPerMillionTokens: 'MAYURA_MODEL_OUTPUT_MICROS_PER_MILLION_TOKENS',
|
|
97
109
|
maxCallCostMicros: 'MAYURA_MODEL_MAX_CALL_COST_MICROS', maxRunCostMicros: 'MAYURA_MAX_RUN_COST_MICROS', researchBudgetMicros: 'RESEARCH_BUDGET_MICROS',
|
|
98
110
|
otlpEndpoint: 'OTEL_EXPORTER_OTLP_ENDPOINT', otlpHeaders: 'OTEL_EXPORTER_OTLP_HEADERS', serviceName: 'OTEL_SERVICE_NAME',
|
|
@@ -129,14 +141,20 @@ function modelSettings(value: z.infer<typeof schema>): ModelSettings {
|
|
|
129
141
|
if (value.modelProvider === 'compatible' && (!value.compatibleEndpoint || !value.compatibleId)) {
|
|
130
142
|
throw new Error('MAYURA_MODEL_PROVIDER=compatible requires MAYURA_MODEL_ENDPOINT (the https://.../chat/completions URL) and MAYURA_MODEL_PROVIDER_ID (such as groq).');
|
|
131
143
|
}
|
|
132
|
-
|
|
144
|
+
// A gateway with a token may hold the provider key itself: the compatible endpoint, or OpenAI's or Anthropic's through
|
|
145
|
+
// a gateway endpoint.
|
|
146
|
+
const gatewayOnly = value.gatewayToken !== undefined && (value.modelProvider === 'compatible' || value.compatibleEndpoint !== undefined);
|
|
147
|
+
if ((!apiKey && !gatewayOnly) || !value.modelName || value.inputMicrosPerMillionTokens === undefined || value.outputMicrosPerMillionTokens === undefined || value.maxCallCostMicros === 0) {
|
|
133
148
|
throw new Error(`MAYURA_MODEL_PROVIDER=${value.modelProvider} requires ${keyName}, MAYURA_MODEL, both MAYURA_MODEL_*_MICROS_PER_MILLION_TOKENS prices and MAYURA_MODEL_MAX_CALL_COST_MICROS.`);
|
|
134
149
|
}
|
|
135
150
|
if (value.maxRunCostMicros < value.maxCallCostMicros) throw new Error('MAYURA_MAX_RUN_COST_MICROS must cover at least one model call.');
|
|
136
151
|
const pricing = { inputMicrosPerMillionTokens: value.inputMicrosPerMillionTokens, outputMicrosPerMillionTokens: value.outputMicrosPerMillionTokens };
|
|
137
152
|
if (value.modelProvider === 'compatible') return { provider: 'compatible', apiKey, name: value.modelName, maxCallCostMicros: value.maxCallCostMicros,
|
|
138
|
-
endpoint: value.compatibleEndpoint!, providerId: value.compatibleId!, auth: value.compatibleAuth, pricing
|
|
139
|
-
|
|
153
|
+
endpoint: value.compatibleEndpoint!, providerId: value.compatibleId!, auth: value.compatibleAuth, pricing,
|
|
154
|
+
output: value.compatibleOutput, strictTools: value.compatibleStrictTools === 'true', gatewayToken: value.gatewayToken,
|
|
155
|
+
tokenLimitField: value.compatibleTokenLimitField };
|
|
156
|
+
return { provider: value.modelProvider, apiKey, name: value.modelName, maxCallCostMicros: value.maxCallCostMicros, pricing,
|
|
157
|
+
endpoint: value.compatibleEndpoint, gatewayToken: value.gatewayToken };
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ArtifactScope, LocalArtifactStore } from 'mayura/artifacts';
|
|
2
|
-
import { defineAgent, defineTool, MayuraError, type JsonValue, type ModelAdapter, type ModelResponse } from 'mayura';
|
|
2
|
+
import { defineAgent, defineTool, MayuraError, type JsonValue, type ModelAdapter, type ModelResponse, z } from 'mayura';
|
|
3
3
|
import type { WorkflowLifecycleFleetRuntime } from 'mayura/workflows/lifecycle';
|
|
4
|
-
import { z } from 'zod';
|
|
5
4
|
import type { ModelSettings } from './config.js';
|
|
6
5
|
import { jsonSchema, modelPermission, selectModel } from './model.js';
|
|
7
6
|
import { asArtifactReference, citation, MAX_REPORT_CHARS, researchRequest, researchResult, runId, type ResearchRequest } from './workflow.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { JsonObject, ModelAdapter } from 'mayura/core';
|
|
2
2
|
import { anthropicMessages } from 'mayura/provider-anthropic';
|
|
3
3
|
import { openAICompatibleChat, openAIResponses } from 'mayura/provider-openai';
|
|
4
|
-
import { z } from '
|
|
4
|
+
import { z } from 'mayura';
|
|
5
5
|
import type { ModelSettings } from './config.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -12,12 +12,19 @@ import type { ModelSettings } from './config.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export function selectModel(settings: ModelSettings, agent: { readonly outputJsonSchema: JsonObject; readonly offline: ModelAdapter }): ModelAdapter {
|
|
14
14
|
if (settings.provider === 'offline') return agent.offline;
|
|
15
|
-
const options = {
|
|
15
|
+
const options = { model: settings.name, outputJsonSchema: agent.outputJsonSchema,
|
|
16
16
|
maxCostMicros: settings.maxCallCostMicros, pricing: settings.pricing, timeoutMs: 30_000 };
|
|
17
17
|
if (settings.provider === 'compatible') {
|
|
18
|
-
return openAICompatibleChat({ ...options,
|
|
18
|
+
return openAICompatibleChat({ ...options, ...(settings.apiKey ? { apiKey: settings.apiKey } : {}), endpoint: settings.endpoint,
|
|
19
|
+
remote: { id: settings.providerId, auth: settings.auth }, output: settings.output, strictTools: settings.strictTools,
|
|
20
|
+
...(settings.tokenLimitField ? { tokenLimitField: settings.tokenLimitField } : {}),
|
|
21
|
+
...(settings.gatewayToken ? { headers: { 'cf-aig-authorization': `Bearer ${settings.gatewayToken}` } } : {}) });
|
|
19
22
|
}
|
|
20
|
-
|
|
23
|
+
// Directly, or through a gateway (MAYURA_MODEL_ENDPOINT, with MAYURA_MODEL_GATEWAY_TOKEN; the key may stay in the gateway).
|
|
24
|
+
const headers = settings.gatewayToken ? { 'cf-aig-authorization': `Bearer ${settings.gatewayToken}` } : undefined;
|
|
25
|
+
const via = { ...(settings.endpoint ? { endpoint: settings.endpoint } : {}), ...(headers ? { headers } : {}) };
|
|
26
|
+
const credentials = settings.apiKey ? { apiKey: settings.apiKey, ...via } : { endpoint: settings.endpoint!, headers: headers! };
|
|
27
|
+
return settings.provider === 'openai' ? openAIResponses({ ...options, ...credentials }) : anthropicMessages({ ...options, ...credentials });
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
/** Runtimes must allow each model explicitly, as `model:<adapter id>`. */
|
|
@@ -29,7 +29,7 @@ export async function openServices(config: Config, options: { readonly library?:
|
|
|
29
29
|
const artifactsDirectory = resolve(config.artifactsDirectory);
|
|
30
30
|
await mkdir(artifactsDirectory, { recursive: true });
|
|
31
31
|
const artifacts = createLocalArtifactStore({ rootDirectory: artifactsDirectory, maxArtifactBytes: 262_144 });
|
|
32
|
-
const artifactScope = {
|
|
32
|
+
const artifactScope = { principalId: config.scope.principalId, projectId: config.scope.projectId };
|
|
33
33
|
// Replace the bundled corpus with your own sources (README "Make it yours").
|
|
34
34
|
const library = options.library ?? localLibrary(harlowCreekCorpus);
|
|
35
35
|
const telemetry = createTelemetry(config.telemetry);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AnyTool, JsonValue, ModelAdapter, ModelRequest, ModelResponse } from 'mayura';
|
|
2
|
-
import { defineAgent } from 'mayura';
|
|
3
|
-
import { z } from 'zod';
|
|
2
|
+
import { defineAgent, z } from 'mayura';
|
|
4
3
|
import type { ModelSettings } from './config.js';
|
|
5
4
|
import { MAX_RESEARCHERS } from './config.js';
|
|
6
5
|
import { readOutput, sentences, sourceId, terms } from './library/index.js';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { ArtifactReference, ArtifactScope, LocalArtifactStore } from 'mayura/artifacts';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { defineWorkflowLifecycle, fanOut, type WorkflowLifecycleNode } from 'mayura/workflows/lifecycle';
|
|
5
|
-
import { z } from 'zod';
|
|
2
|
+
import { defineTool, type RunHandle, type ToolExecutionContext, z } from 'mayura';
|
|
3
|
+
import { agentStep, defineWorkflowLifecycle, fanOut, type WorkflowLifecycleNode } from 'mayura/workflows/lifecycle';
|
|
6
4
|
import { MAX_RESEARCHERS, type ModelSettings } from './config.js';
|
|
7
5
|
import { libraryTools, sourceId, type SourceLibrary } from './library/index.js';
|
|
8
6
|
import { finding, plannerAgent, question, researcherAgent, subQuestion, writerAgent } from './team.js';
|
|
@@ -62,48 +60,62 @@ export function researchWorkflows(dependencies: ResearchDependencies) {
|
|
|
62
60
|
const planner = plannerAgent(dependencies.model);
|
|
63
61
|
const writer = writerAgent(dependencies.model);
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
// Each agent step runs its agent in the run's scope with its own grants and limits (agentStep), and charges the run
|
|
64
|
+
// what the agent spent. The agent's spans nest under the step's span in the research run's trace.
|
|
65
|
+
const traced = (run: RunHandle<unknown>, context: ToolExecutionContext) => { const watch = telemetry.watch(context, run); return () => watch.end(); };
|
|
66
|
+
const limits = (bounds: { readonly maxSteps: number; readonly maxModelCalls: number; readonly maxToolCalls: number }) =>
|
|
67
|
+
({ ...bounds, maxDurationMs: agentDurationMs, maxCostMicros: ceiling });
|
|
68
|
+
|
|
69
|
+
const plan = agentStep(planner.agent, {
|
|
70
|
+
id: 'research.plan', version: '1', capabilities: ['research:plan'], timeoutMs: stepTimeoutMs,
|
|
67
71
|
description: 'Run the planner agent: split the research question into sub-questions, one per research slot.',
|
|
68
|
-
input: researchRequest, output: planStepOutput,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
input: researchRequest, output: planStepOutput, permissions: planner.permissions,
|
|
73
|
+
limits: limits({ maxSteps: 2, maxModelCalls: 2, maxToolCalls: 0 }), onRun: traced,
|
|
74
|
+
prepare: request => ({ question: request.question, maxSubQuestions: MAX_RESEARCHERS }),
|
|
75
|
+
finish: (planned, request) => {
|
|
72
76
|
const subQuestions = [...new Set(planned.subQuestions)].slice(0, MAX_RESEARCHERS);
|
|
73
77
|
return { question: request.question, assignments: subQuestions.map(item => ({ question: request.question, subQuestion: item })) };
|
|
74
78
|
},
|
|
75
79
|
});
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
// Each researcher gets fresh library tools, which record the documents it actually read.
|
|
82
|
+
const reads = new WeakMap<ToolExecutionContext, Set<string>>();
|
|
83
|
+
const libraryGrants = libraryTools(library).permissions;
|
|
84
|
+
const investigate = agentStep((_task: z.infer<typeof assignment>, context: ToolExecutionContext) => {
|
|
85
|
+
const read = new Set<string>(); reads.set(context, read);
|
|
86
|
+
return researcherAgent(dependencies.model, libraryTools(library, id => read.add(id)).tools).agent;
|
|
87
|
+
}, {
|
|
88
|
+
id: 'research.investigate', version: '1', capabilities: ['research:investigate'], timeoutMs: stepTimeoutMs, effects: 'read',
|
|
79
89
|
description: 'Run one researcher agent on one sub-question over the source library, returning cited findings.',
|
|
80
|
-
input: assignment, output: researchStepOutput,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const read = new Set<string>();
|
|
85
|
-
const tools = libraryTools(library, id => read.add(id));
|
|
86
|
-
const researcher = researcherAgent(dependencies.model, tools.tools);
|
|
87
|
-
const found = await runAgent({ ...researcher, permissions: [...researcher.permissions, ...tools.permissions] },
|
|
88
|
-
{ question: task.question, subQuestion: asked }, { context, telemetry, ceiling, limits: { maxSteps: 6, maxModelCalls: 5, maxToolCalls: 8 } });
|
|
90
|
+
input: assignment, output: researchStepOutput, permissions: [...researcherAgent(dependencies.model, []).permissions, ...libraryGrants],
|
|
91
|
+
limits: limits({ maxSteps: 6, maxModelCalls: 5, maxToolCalls: 8 }), onRun: traced,
|
|
92
|
+
prepare: task => ({ question: task.question, subQuestion: task.subQuestion }),
|
|
93
|
+
finish: (found, task, context) => {
|
|
89
94
|
// Trust, then verify: a finding may cite only documents this researcher read through library.read.
|
|
95
|
+
const read = reads.get(context) ?? new Set<string>();
|
|
90
96
|
if (found.findings.some(item => item.sourceIds.some(id => !read.has(id)))) throw new Error('A finding cites a document its researcher did not read.');
|
|
91
|
-
return { question: task.question, subQuestion:
|
|
97
|
+
return { question: task.question, subQuestion: task.subQuestion, findings: found.findings };
|
|
92
98
|
},
|
|
93
99
|
});
|
|
94
100
|
|
|
95
|
-
const write =
|
|
96
|
-
id: 'research.write', version: '1',
|
|
101
|
+
const write = agentStep(writer.agent, {
|
|
102
|
+
id: 'research.write', version: '1', capabilities: ['research:write'], timeoutMs: stepTimeoutMs,
|
|
97
103
|
description: 'Run the writer agent over every researcher\'s findings and render the cited report.',
|
|
98
104
|
// The join's output: one entry per slot, `null` for a slot the plan did not use.
|
|
99
|
-
input: z.array(researchStepOutput.nullable()).length(MAX_RESEARCHERS), output: writeStepOutput,
|
|
100
|
-
|
|
105
|
+
input: z.array(researchStepOutput.nullable()).length(MAX_RESEARCHERS), output: writeStepOutput, permissions: writer.permissions,
|
|
106
|
+
limits: limits({ maxSteps: 2, maxModelCalls: 2, maxToolCalls: 0 }), onRun: traced,
|
|
107
|
+
prepare: slots => {
|
|
101
108
|
const research = slots.filter(item => item !== null);
|
|
102
109
|
const asked = research[0]?.question ?? (() => { throw new Error('No researcher ran.'); })();
|
|
103
110
|
const sections = research.map(item => ({ subQuestion: item.subQuestion, findings: item.findings }));
|
|
104
111
|
const reported = new Set(sections.flatMap(section => section.findings.flatMap(item => item.sourceIds)));
|
|
105
112
|
if (reported.size === 0) throw new Error('No researcher found a source for any sub-question; there is nothing to report.');
|
|
106
|
-
|
|
113
|
+
return { question: asked, sections };
|
|
114
|
+
},
|
|
115
|
+
finish: async (draft, slots) => {
|
|
116
|
+
const research = slots.filter(item => item !== null);
|
|
117
|
+
const asked = research[0]!.question;
|
|
118
|
+
const reported = new Set(research.flatMap(item => item.findings.flatMap(finding => finding.sourceIds)));
|
|
107
119
|
// The writer may only cite what researchers reported, and every citation must resolve in the library.
|
|
108
120
|
const cited = [...new Set(draft.sections.flatMap(section => section.sourceIds))];
|
|
109
121
|
if (cited.some(id => !reported.has(id))) throw new Error('The writer cited a source no researcher reported.');
|
|
@@ -152,46 +164,20 @@ export function researchWorkflows(dependencies: ResearchDependencies) {
|
|
|
152
164
|
latest,
|
|
153
165
|
/** Every version that may still have runs in flight. Add, never edit, when you change the workflow. */
|
|
154
166
|
definitions: [latest],
|
|
155
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* What the workflow runtime must allow: each step tool, each capability it declares, the researchers' read effect
|
|
169
|
+
* (their library tools read) and the store's write effect.
|
|
170
|
+
*/
|
|
156
171
|
permissions: ['tool:research.plan', 'tool:research.investigate', 'tool:research.write', 'tool:research.store',
|
|
157
|
-
'research:plan', 'research:investigate', 'research:write', 'artifacts:write', 'effect:write'],
|
|
172
|
+
'research:plan', 'research:investigate', 'research:write', 'artifacts:write', 'effect:read', 'effect:write'],
|
|
158
173
|
} as const;
|
|
159
174
|
}
|
|
160
175
|
|
|
161
|
-
// ----
|
|
176
|
+
// ---- Agent step bounds ---------------------------------------------------------------------------------------------------
|
|
162
177
|
|
|
163
178
|
/** A step may run a little longer than its agent, so a timed-out agent is reported by the agent runtime first. */
|
|
164
179
|
const agentDurationMs = 120_000;
|
|
165
180
|
const stepTimeoutMs = agentDurationMs + 15_000;
|
|
166
181
|
|
|
167
|
-
/**
|
|
168
|
-
* Agent steps are `effects: 'none'`: they read the library and ask a model, and change nothing outside the run, so a
|
|
169
|
-
* failure is a plain failure rather than an uncertain external effect. Their spending is still bounded: the agent
|
|
170
|
-
* runs with `maxCostMicros` = the step ceiling, and the step reports what it actually spent.
|
|
171
|
-
*/
|
|
172
|
-
async function runAgent<I extends Schema, O extends Schema>(
|
|
173
|
-
setup: { readonly agent: AgentDefinition<I, O>; readonly permissions: readonly string[] },
|
|
174
|
-
input: InferInput<I>,
|
|
175
|
-
options: { readonly context: ToolExecutionContext; readonly telemetry: Telemetry; readonly ceiling: number; readonly limits: RuntimeLimits },
|
|
176
|
-
): Promise<InferOutput<O>> {
|
|
177
|
-
const { context } = options;
|
|
178
|
-
const runtime = createRuntime({ profile: 'ephemeral', scope: context.scope, permissions: { allow: [...setup.permissions] },
|
|
179
|
-
limits: { ...options.limits, maxDurationMs: agentDurationMs, maxCostMicros: options.ceiling } });
|
|
180
|
-
try {
|
|
181
|
-
const handle = runtime.submit(setup.agent, { input });
|
|
182
|
-
// The agent's spans nest under this step's span in the research run's trace.
|
|
183
|
-
const watch = options.telemetry.watch(context, handle);
|
|
184
|
-
const stop = (): void => handle.cancel();
|
|
185
|
-
context.signal.addEventListener('abort', stop, { once: true });
|
|
186
|
-
try {
|
|
187
|
-
const outcome = await handle.result();
|
|
188
|
-
const spent = runtime.inspect(handle).budget.spentMicros;
|
|
189
|
-
context.reportUsage({ knownCostMicros: typeof spent === 'number' ? Math.min(spent, options.ceiling) : options.ceiling, unknownCostMicros: 0 });
|
|
190
|
-
if (outcome.status !== 'succeeded') throw new Error(`The ${setup.agent.id} agent ended ${outcome.status}.`);
|
|
191
|
-
return outcome.output;
|
|
192
|
-
} finally { context.signal.removeEventListener('abort', stop); await watch.end(); }
|
|
193
|
-
} finally { await runtime.close(); }
|
|
194
|
-
}
|
|
195
|
-
|
|
196
182
|
/** Used by the desk's report tool: the stored reference as the artifact store expects it. */
|
|
197
183
|
export const asArtifactReference = (value: ResearchResult['artifact']): ArtifactReference => value as ArtifactReference;
|
|
@@ -32,6 +32,17 @@ MAYURA_MODEL_PROVIDER=offline
|
|
|
32
32
|
# MAYURA_MODEL_PROVIDER_ID=groq
|
|
33
33
|
# MAYURA_MODEL_AUTH=bearer
|
|
34
34
|
# MAYURA_MODEL_API_KEY=
|
|
35
|
+
# DeepSeek answers in JSON mode and has strict tools on https://api.deepseek.com/beta/chat/completions:
|
|
36
|
+
# MAYURA_MODEL_OUTPUT=json_object
|
|
37
|
+
# MAYURA_MODEL_STRICT_TOOLS=true
|
|
38
|
+
# OpenAI's newer models (directly or as openai/... through a gateway) take only max_completion_tokens:
|
|
39
|
+
# MAYURA_MODEL_TOKEN_LIMIT_FIELD=max_completion_tokens
|
|
40
|
+
# OpenAI or Anthropic through a gateway: MAYURA_MODEL_PROVIDER=openai or anthropic, MAYURA_MODEL_ENDPOINT set to its
|
|
41
|
+
# endpoint (for Cloudflare, https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/openai/responses or
|
|
42
|
+
# .../anthropic/v1/messages) and MAYURA_MODEL_GATEWAY_TOKEN; the provider key may then stay in the gateway.
|
|
43
|
+
# Cloudflare AI Gateway: https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/compat/chat/completions, models named
|
|
44
|
+
# provider/model, and the gateway token of an authenticated gateway (the API key may stay in the gateway):
|
|
45
|
+
# MAYURA_MODEL_GATEWAY_TOKEN=
|
|
35
46
|
# MAYURA_MODEL=
|
|
36
47
|
# Prices in micro-dollars per million tokens, and the most one call and one run may cost.
|
|
37
48
|
# MAYURA_MODEL_INPUT_MICROS_PER_MILLION_TOKENS=
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import type { JsonValue, ModelAdapter, ModelRequest, ModelResponse, ModelStreamEvent } from 'mayura/core';
|
|
3
3
|
import { createNativeMemory } from 'mayura/memory';
|
|
4
|
-
import { MayuraError, defineAgent, defineTool, type ToolExecutionContext } from 'mayura';
|
|
4
|
+
import { MayuraError, defineAgent, defineTool, type ToolExecutionContext, z } from 'mayura';
|
|
5
5
|
import type { MemoryIndexStore } from 'mayura/storage-contracts';
|
|
6
|
-
import { z } from 'zod';
|
|
7
6
|
import { customerFromScope } from './auth.js';
|
|
8
7
|
import type { ModelSettings } from './config.js';
|
|
9
8
|
import { piiBackstop, redact, redactAtSchema } from './guardrails.js';
|
|
@@ -46,7 +45,8 @@ export const returnOutput = z.strictObject({ status: z.enum(['opened', 'already_
|
|
|
46
45
|
orderStatus: z.enum(['processing', 'shipped', 'delivered']).nullable(), returnId: identifier.nullable(), instructions: z.string().max(1_000).nullable() });
|
|
47
46
|
const rememberInput = z.strictObject({ fact: z.string().min(3).max(500), category: z.enum(['fact', 'preference']) });
|
|
48
47
|
export const rememberOutput = z.strictObject({ status: z.enum(['saved', 'already_known']), noteId: identifier, fact: z.string().max(4_096) });
|
|
49
|
-
|
|
48
|
+
// Providers' strict tool schemas require every property, so "no query" is null rather than an optional field.
|
|
49
|
+
const recallInput = z.strictObject({ query: z.string().min(1).max(200).nullable() });
|
|
50
50
|
const note = z.strictObject({ noteId: z.string().max(128), category: z.string().max(32), fact: z.string().max(4_096), rememberedAt: z.string() });
|
|
51
51
|
export const recallOutput = z.strictObject({ notes: z.array(note).max(20) });
|
|
52
52
|
|
|
@@ -146,7 +146,7 @@ export function supportAssistant(dependencies: AssistantDependencies) {
|
|
|
146
146
|
|
|
147
147
|
const recall = defineTool({
|
|
148
148
|
id: 'memory.recall', version: '1', effects: 'read', capabilities: ['memory:read'],
|
|
149
|
-
description: 'Look up what you remembered about the signed-in customer.
|
|
149
|
+
description: 'Look up what you remembered about the signed-in customer. With a null query, returns the most recent notes.',
|
|
150
150
|
input: recallInput, inputJsonSchema: jsonSchema(recallInput), output: recallOutput,
|
|
151
151
|
execute: async ({ query }, context) => {
|
|
152
152
|
const memory = memoryOf(context, ['memory:read']);
|
|
@@ -279,7 +279,7 @@ function plan(input: SupportInput, results: Results): Plan {
|
|
|
279
279
|
case 'recall':
|
|
280
280
|
case 'help':
|
|
281
281
|
if (results.has('memory.recall')) return { final: notesReply(recallOutput.parse(results.get('memory.recall')), intent === 'recall') };
|
|
282
|
-
return { call: { toolId: 'memory.recall', input: {} } };
|
|
282
|
+
return { call: { toolId: 'memory.recall', input: { query: null } } };
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
2
|
import { validatedEnvironment } from 'mayura/helpers';
|
|
3
|
-
import { z } from '
|
|
3
|
+
import { z } from 'mayura';
|
|
4
4
|
|
|
5
5
|
// Every setting comes from the environment and is validated once at startup. Nothing is discovered implicitly:
|
|
6
6
|
// no config files, no default credentials, and no provider is contacted unless MAYURA_MODEL_PROVIDER says so.
|
|
@@ -32,6 +32,13 @@ const schema = z.object({
|
|
|
32
32
|
compatibleId: z.string().regex(/^[a-z0-9][a-z0-9-]{0,39}$/u, 'Use a short lower-case id such as groq.').optional(),
|
|
33
33
|
compatibleAuth: z.enum(['bearer', 'api-key']).default('bearer'),
|
|
34
34
|
compatibleApiKey: z.string().min(1).optional(),
|
|
35
|
+
// How the provider differs from OpenAI: JSON mode instead of JSON Schema output (DeepSeek), strict tool calls, and
|
|
36
|
+
// a Cloudflare AI Gateway token (sent as cf-aig-authorization; with keys stored in the gateway, no API key is needed).
|
|
37
|
+
compatibleOutput: z.enum(['json_schema', 'json_object']).default('json_schema'),
|
|
38
|
+
compatibleStrictTools: z.enum(['true', 'false']).default('false'),
|
|
39
|
+
// The field for the output-token limit: OpenAI's newer models (also through a gateway) take only max_completion_tokens.
|
|
40
|
+
compatibleTokenLimitField: z.enum(['max_tokens', 'max_completion_tokens']).optional(),
|
|
41
|
+
gatewayToken: z.string().min(1).optional(),
|
|
35
42
|
modelName: z.string().min(1).max(128).optional(),
|
|
36
43
|
inputMicrosPerMillionTokens: micros.optional(),
|
|
37
44
|
outputMicrosPerMillionTokens: micros.optional(),
|
|
@@ -42,10 +49,14 @@ const schema = z.object({
|
|
|
42
49
|
|
|
43
50
|
export type ModelSettings =
|
|
44
51
|
| { readonly provider: 'offline' }
|
|
45
|
-
|
|
52
|
+
// OpenAI or Anthropic directly, or through a gateway: its endpoint (MAYURA_MODEL_ENDPOINT) and token.
|
|
53
|
+
| { readonly provider: 'openai' | 'anthropic'; readonly apiKey: string | undefined; readonly name: string; readonly maxCallCostMicros: number;
|
|
54
|
+
readonly endpoint: string | undefined; readonly gatewayToken: string | undefined;
|
|
46
55
|
readonly pricing: { readonly inputMicrosPerMillionTokens: number; readonly outputMicrosPerMillionTokens: number } }
|
|
47
|
-
| { readonly provider: 'compatible'; readonly apiKey: string; readonly name: string; readonly maxCallCostMicros: number;
|
|
56
|
+
| { readonly provider: 'compatible'; readonly apiKey: string | undefined; readonly name: string; readonly maxCallCostMicros: number;
|
|
48
57
|
readonly endpoint: string; readonly providerId: string; readonly auth: 'bearer' | 'api-key';
|
|
58
|
+
readonly output: 'json_schema' | 'json_object'; readonly strictTools: boolean; readonly gatewayToken: string | undefined;
|
|
59
|
+
readonly tokenLimitField: 'max_tokens' | 'max_completion_tokens' | undefined;
|
|
49
60
|
readonly pricing: { readonly inputMicrosPerMillionTokens: number; readonly outputMicrosPerMillionTokens: number } };
|
|
50
61
|
|
|
51
62
|
export interface Config {
|
|
@@ -76,7 +87,8 @@ export async function loadConfig(source: Readonly<Record<string, string | undefi
|
|
|
76
87
|
port: 'PORT', bind: 'MAYURA_BIND', publicOrigin: 'MAYURA_PUBLIC_ORIGIN', allowedOrigins: 'MAYURA_ALLOWED_ORIGINS',
|
|
77
88
|
operatorTokens: 'MAYURA_OPERATOR_TOKEN_SHA256', sessionSecret: 'MAYURA_SESSION_SECRET',
|
|
78
89
|
modelProvider: 'MAYURA_MODEL_PROVIDER', openaiApiKey: 'OPENAI_API_KEY', anthropicApiKey: 'ANTHROPIC_API_KEY',
|
|
79
|
-
compatibleEndpoint: 'MAYURA_MODEL_ENDPOINT', compatibleId: 'MAYURA_MODEL_PROVIDER_ID', compatibleAuth: 'MAYURA_MODEL_AUTH', compatibleApiKey: 'MAYURA_MODEL_API_KEY',
|
|
90
|
+
compatibleEndpoint: 'MAYURA_MODEL_ENDPOINT', compatibleId: 'MAYURA_MODEL_PROVIDER_ID', compatibleAuth: 'MAYURA_MODEL_AUTH', compatibleApiKey: 'MAYURA_MODEL_API_KEY',
|
|
91
|
+
compatibleOutput: 'MAYURA_MODEL_OUTPUT', compatibleStrictTools: 'MAYURA_MODEL_STRICT_TOOLS', compatibleTokenLimitField: 'MAYURA_MODEL_TOKEN_LIMIT_FIELD', gatewayToken: 'MAYURA_MODEL_GATEWAY_TOKEN', modelName: 'MAYURA_MODEL',
|
|
80
92
|
inputMicrosPerMillionTokens: 'MAYURA_MODEL_INPUT_MICROS_PER_MILLION_TOKENS', outputMicrosPerMillionTokens: 'MAYURA_MODEL_OUTPUT_MICROS_PER_MILLION_TOKENS',
|
|
81
93
|
maxCallCostMicros: 'MAYURA_MODEL_MAX_CALL_COST_MICROS', maxRunCostMicros: 'MAYURA_MAX_RUN_COST_MICROS', returnReminderHours: 'RETURN_REMINDER_HOURS',
|
|
82
94
|
},
|
|
@@ -109,12 +121,18 @@ function modelSettings(value: z.infer<typeof schema>): ModelSettings {
|
|
|
109
121
|
if (value.modelProvider === 'compatible' && (!value.compatibleEndpoint || !value.compatibleId)) {
|
|
110
122
|
throw new Error('MAYURA_MODEL_PROVIDER=compatible requires MAYURA_MODEL_ENDPOINT (the https://.../chat/completions URL) and MAYURA_MODEL_PROVIDER_ID (such as groq).');
|
|
111
123
|
}
|
|
112
|
-
|
|
124
|
+
// A gateway with a token may hold the provider key itself: the compatible endpoint, or OpenAI's or Anthropic's through
|
|
125
|
+
// a gateway endpoint.
|
|
126
|
+
const gatewayOnly = value.gatewayToken !== undefined && (value.modelProvider === 'compatible' || value.compatibleEndpoint !== undefined);
|
|
127
|
+
if ((!apiKey && !gatewayOnly) || !value.modelName || value.inputMicrosPerMillionTokens === undefined || value.outputMicrosPerMillionTokens === undefined || value.maxCallCostMicros === 0) {
|
|
113
128
|
throw new Error(`MAYURA_MODEL_PROVIDER=${value.modelProvider} requires ${keyName}, MAYURA_MODEL, both MAYURA_MODEL_*_MICROS_PER_MILLION_TOKENS prices and MAYURA_MODEL_MAX_CALL_COST_MICROS.`);
|
|
114
129
|
}
|
|
115
130
|
if (value.maxRunCostMicros < value.maxCallCostMicros) throw new Error('MAYURA_MAX_RUN_COST_MICROS must cover at least one model call.');
|
|
116
131
|
const pricing = { inputMicrosPerMillionTokens: value.inputMicrosPerMillionTokens, outputMicrosPerMillionTokens: value.outputMicrosPerMillionTokens };
|
|
117
132
|
if (value.modelProvider === 'compatible') return { provider: 'compatible', apiKey, name: value.modelName, maxCallCostMicros: value.maxCallCostMicros,
|
|
118
|
-
endpoint: value.compatibleEndpoint!, providerId: value.compatibleId!, auth: value.compatibleAuth, pricing
|
|
119
|
-
|
|
133
|
+
endpoint: value.compatibleEndpoint!, providerId: value.compatibleId!, auth: value.compatibleAuth, pricing,
|
|
134
|
+
output: value.compatibleOutput, strictTools: value.compatibleStrictTools === 'true', gatewayToken: value.gatewayToken,
|
|
135
|
+
tokenLimitField: value.compatibleTokenLimitField };
|
|
136
|
+
return { provider: value.modelProvider, apiKey, name: value.modelName, maxCallCostMicros: value.maxCallCostMicros, pricing,
|
|
137
|
+
endpoint: value.compatibleEndpoint, gatewayToken: value.gatewayToken };
|
|
120
138
|
}
|
|
@@ -10,7 +10,9 @@ import { createPipeline, redactPII, type ContentProcessor, type ContentSnapshot
|
|
|
10
10
|
// final reply the runtime is about to release; if anything would still change, the content is withheld and the run
|
|
11
11
|
// ends `blocked`.
|
|
12
12
|
//
|
|
13
|
-
//
|
|
13
|
+
// The redaction lives in the schemas, so it applies wherever a value is validated (input, tool results, the reply);
|
|
14
|
+
// the backstop guard only checks it happened. (A guard may also rewrite content; this one deliberately blocks instead,
|
|
15
|
+
// so a redaction gap shows up as a blocked run rather than being silently patched.)
|
|
14
16
|
// These recognizers are heuristics (see mayura/guardrails `redactPII`): they miss unusual formats and can flag long
|
|
15
17
|
// digit strings that are not PII. They are a safety net, not a compliance certification.
|
|
16
18
|
|