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/lib/context/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,8FAA8F;IAC9F,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,iGAAiG;IACjG,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CACvE;AAED,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,qGAAqG;AACrG,MAAM,WA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AC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAM/F;AAsID;;;;;GAKG;AACH,qBAAa,MAAM;IACL,QAAQ,CAAC,aAAa,EAAE,MAAM;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAArE,YAAqB,aAAa,EAAE,MAAM,EAAW,QAAQ,EAAE,MAAM,EASpE;IAED,0GAA0G;IAC1G,IAAI,QAAQ,IAAI,cAAc,CAAsC;IAEpE;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAoBvC;IAED,gGAAgG;IAChG,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAWtC;IAED;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,GAAG,YAAY,CA+BlE;IAED,oGAAoG;IACpG,gBAAgB,IAAI,QAAQ,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAElD;IAED,iHAAiH;IACjH,KAAK,IAAI,IAAI,CAAoC;IAEjD,+FAA+F;IAC/F,QAAQ,IAAI,QAAQ,CAAC,cAAc,CAAC,CAKnC;CACF"}
|
package/lib/core/dist/budget.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { MayuraError, assertPositiveInteger } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Say which limit stopped a call, with the numbers (costs and counts, never content), and how to raise a budget of 0,
|
|
4
|
+
* the default for an agent run.
|
|
5
|
+
*/
|
|
6
|
+
function exhausted(path, calls, bound) {
|
|
7
|
+
const full = path.find(ancestor => calls > ancestor.maxCalls - ancestor.calls - ancestor.heldCalls);
|
|
8
|
+
if (full)
|
|
9
|
+
return new MayuraError('BUDGET_EXCEEDED', `The budget's call limit of ${full.maxCalls} is used up; no new call was started.`);
|
|
10
|
+
const short = path.find(ancestor => bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved) ?? path[0];
|
|
11
|
+
const left = BigInt(short.maxCostMicros) - short.spent - short.reserved;
|
|
12
|
+
const hint = short.maxCostMicros === 0
|
|
13
|
+
? ' The budget is 0, so nothing that costs money can run: for an agent run, set limits.maxCostMicros in createRuntime; for a workflow, its runtime\'s maxCostMicros.'
|
|
14
|
+
: '';
|
|
15
|
+
return new MayuraError('BUDGET_EXCEEDED', `The call may cost up to ${bound} micros, but only ${left < 0n ? 0n : left} of the budget's ${short.maxCostMicros} micros are left; no new call was started.${hint}`);
|
|
16
|
+
}
|
|
2
17
|
const maximumAccounts = 1_024;
|
|
3
18
|
const maximumDepth = 32;
|
|
4
19
|
const maximumBundleOperations = 128;
|
|
@@ -254,7 +269,7 @@ export class Budget {
|
|
|
254
269
|
assertOpen(account, path);
|
|
255
270
|
const bound = BigInt(maxMicros);
|
|
256
271
|
if (path.some(ancestor => ancestor.heldCalls >= ancestor.maxCalls - ancestor.calls || bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved)) {
|
|
257
|
-
throw
|
|
272
|
+
throw exhausted(path, 1, bound);
|
|
258
273
|
}
|
|
259
274
|
// No callback or await can interleave ancestor validation and commit.
|
|
260
275
|
for (const ancestor of path) {
|
|
@@ -287,7 +302,7 @@ export class Budget {
|
|
|
287
302
|
}
|
|
288
303
|
if (path.some(ancestor => config.length > ancestor.maxCalls - ancestor.calls - ancestor.heldCalls
|
|
289
304
|
|| bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved)) {
|
|
290
|
-
throw
|
|
305
|
+
throw exhausted(path, config.length, bound);
|
|
291
306
|
}
|
|
292
307
|
const states = [];
|
|
293
308
|
const handles = config.map(operation => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAmFjE,MAAM,eAAe,GAAG,KAAK,C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C,CAAC;QAC3E,OAAO,CAAC,MAAM,CAAC,kBAAkB,IAAI,MAAM,CAAC,MAAM,CAAC;QACnD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,oGAAoG;IACpG,gBAAgB;QACd,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,iHAAiH;IACjH,KAAK,KAAW,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IAEjD,+FAA+F;IAC/F,QAAQ;QACN,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACpG,sGAAsG;QACtG,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACxG,CAAC;CACF;AAED,sGAAsG;AACtG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC","sourcesContent":["import { MayuraError, assertPositiveInteger } from './errors.js';\n\nexport interface Reservation {\n /** Settle only confirmed cost. Unknown cost deliberately retains the complete reservation. */\n settle(actualMicros: number): void;\n /** Atomically charge confirmed usage, retain an unresolved bound and release unused capacity. */\n settleUsage(knownCostMicros: number, unknownCostMicros: number): void;\n}\n\n/** One fixed-cost future execution; IDs remain unique throughout their shared ledger's lifetime. */\nexport interface BundleOperation {\n readonly id: string;\n readonly maxCostMicros: number;\n}\n\n/** Genuine receiver-bound authority for one held execution, not an executor or a transferable ID. */\nexport interface BudgetTicket {\n readonly id: string;\n readonly maxCostMicros: number;\n /** Consume one held call exactly once. Monetary settlement remains independently required. */\n start(): Reservation;\n /** Release only never-started capacity, including after account closure; repeated cancellation is harmless. */\n cancel(): void;\n}\n\n/** Atomically admitted future calls. Closure cancels held tickets, never already-started usage. */\nexport interface BudgetBundle {\n readonly tickets: readonly BudgetTicket[];\n close(): void;\n}\n\n/** Child limits are ceilings on shared funds, not prepaid allocations or guaranteed earmarks. */\nexport interface BudgetForkOptions {\n /** Unique within the entire ledger; root is reserved and closed identities cannot be reused. */\n readonly id: string;\n readonly maxCostMicros: number;\n readonly maxCalls: number;\n}\n\n/** Correlate account usage without exposing an authority-bearing parent/root account reference. */\nexport interface BudgetIdentity {\n readonly id: string;\n readonly parentId?: string;\n /** Root identity is included; the root has depth zero. */\n readonly lineage: readonly string[];\n readonly depth: number;\n}\n\nexport interface BudgetSnapshot {\n readonly spentMicros: number | string;\n readonly reservedMicros: number;\n readonly calls: number;\n}\n\ninterface Ledger {\n readonly ids: Set<string>;\n readonly ticketIds: Set<string>;\n /** Only named bundle tickets count here: held plus started but not yet validly settled. */\n outstandingTickets: number;\n blocked: boolean;\n}\ninterface Account {\n readonly ledger: Ledger;\n readonly ancestors: readonly Account[];\n readonly identity: BudgetIdentity;\n readonly maxCostMicros: number;\n readonly maxCalls: number;\n reserved: bigint;\n spent: bigint;\n calls: number;\n heldCalls: number;\n closed: boolean;\n}\n\ninterface TicketState {\n readonly account: Account;\n readonly path: readonly Account[];\n readonly maxCostMicros: number;\n readonly bound: bigint;\n status: 'held' | 'started' | 'cancelled' | 'settled' | 'unknown';\n}\ninterface BundleState { readonly tickets: readonly TicketState[]; closed: boolean }\n\nconst maximumAccounts = 1_024;\nconst maximumDepth = 32;\nconst maximumBundleOperations = 128;\nconst maximumOutstandingTickets = 1_024;\nconst maximumTicketIds = 16_384;\nconst safeInteger = BigInt(Number.MAX_SAFE_INTEGER);\n// Runtime-private state prevents JavaScript writes to TypeScript-only private/readonly fields.\nconst accounts = new WeakMap<Budget, Account>();\nconst tickets = new WeakMap<BudgetTicket, TicketState>();\nconst bundles = new WeakMap<BudgetBundle, BundleState>();\n\nfunction costLimit(value: number): void {\n if (!Number.isSafeInteger(value) || value < 0) throw new MayuraError('INVALID_CONFIG', 'maxCostMicros must be a non-negative safe integer.');\n}\n\n/** Reject structural lookalikes, inherited prototypes, and proxy wrappers around real accounts. */\nexport function assertBudget(value: unknown): asserts value is Budget {\n if (typeof value !== 'object' || value === null || !accounts.has(value as Budget)) {\n throw new MayuraError('INVALID_CONFIG', 'A genuine shared execution Budget is required.');\n }\n}\n\n/** Trusted-host ownership check; a common ledger or copied identity does not convey this account's authority. */\nexport function assertBudgetTicket(value: unknown, owner: Budget): asserts value is BudgetTicket {\n assertBudget(owner);\n const ticket = typeof value === 'object' && value !== null ? tickets.get(value as BudgetTicket) : undefined;\n if (!ticket || ticket.account !== accounts.get(owner)) {\n throw new MayuraError('INVALID_CONFIG', 'A genuine execution ticket owned by the exact account is required.');\n }\n}\n\nfunction accountFor(value: Budget): Account {\n assertBudget(value);\n return accounts.get(value)!;\n}\n\nfunction pathFor(account: Account): readonly Account[] { return [...account.ancestors, account]; }\n\nfunction assertOpen(account: Account, path: readonly Account[]): void {\n if (account.ledger.blocked || path.some(ancestor => ancestor.closed)) {\n throw new MayuraError('BUDGET_EXCEEDED', 'Execution budget admissions are closed; no new call was dispatched.');\n }\n}\n\n/** Snapshot child configuration without invoking accessor properties or reflecting thrown text. */\nfunction forkOptions(value: BudgetForkOptions): BudgetForkOptions {\n let id: unknown; let maxCostMicros: unknown; let maxCalls: unknown;\n try {\n if (!value || typeof value !== 'object' || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) throw new Error();\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const keys = Reflect.ownKeys(descriptors);\n if (keys.length !== 3 || keys.some(key => !['id', 'maxCostMicros', 'maxCalls'].includes(key as string))) throw new Error();\n for (const key of ['id', 'maxCostMicros', 'maxCalls'] as const) if (!descriptors[key] || !('value' in descriptors[key])) throw new Error();\n id = descriptors['id']!.value; maxCostMicros = descriptors['maxCostMicros']!.value; maxCalls = descriptors['maxCalls']!.value;\n } catch { throw new MayuraError('INVALID_CONFIG', 'Child budget configuration must contain plain data fields.'); }\n if (typeof id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(id)) {\n throw new MayuraError('INVALID_CONFIG', 'Child budget ID must be a bounded stable identifier.');\n }\n costLimit(maxCostMicros as number); assertPositiveInteger(maxCalls as number, 'maxCalls');\n return { id, maxCostMicros: maxCostMicros as number, maxCalls: maxCalls as number };\n}\n\n/** Snapshot every supplied descriptor before checking mutable ledger state; never execute getters or iterators. */\nfunction bundleOperations(value: readonly BundleOperation[]): readonly BundleOperation[] {\n const excessiveLength = Symbol('bundle-length');\n try {\n if (!Array.isArray(value)) throw new Error();\n const length = Object.getOwnPropertyDescriptor(value, 'length');\n if (!length || !('value' in length) || !Number.isSafeInteger(length.value) || length.value < 1) throw new Error();\n if (length.value > maximumBundleOperations) throw excessiveLength;\n const size = length.value as number;\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const keys = Reflect.ownKeys(descriptors);\n if (keys.length !== size + 1 || keys.some(key => key !== 'length'\n && (typeof key !== 'string' || !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= size))) throw new Error();\n const result: BundleOperation[] = [];\n for (let index = 0; index < size; index++) {\n const descriptor = descriptors[String(index)];\n if (!descriptor || !('value' in descriptor)) throw new Error();\n const operation = descriptor.value as unknown;\n if (!operation || typeof operation !== 'object' || ![Object.prototype, null].includes(Object.getPrototypeOf(operation))) throw new Error();\n const fields = Object.getOwnPropertyDescriptors(operation);\n const fieldKeys = Reflect.ownKeys(fields);\n if (fieldKeys.length !== 2 || fieldKeys.some(key => key !== 'id' && key !== 'maxCostMicros')\n || !fields['id'] || !('value' in fields['id']) || !fields['maxCostMicros'] || !('value' in fields['maxCostMicros'])) throw new Error();\n const id: unknown = fields['id'].value; const maxCostMicros: unknown = fields['maxCostMicros'].value;\n if (typeof id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,255}$/.test(id)\n || typeof maxCostMicros !== 'number' || !Number.isSafeInteger(maxCostMicros) || maxCostMicros < 0) throw new Error();\n result.push({ id, maxCostMicros });\n }\n return result;\n } catch (error) {\n if (error === excessiveLength) throw new MayuraError('LIMIT_EXCEEDED', 'The execution bundle operation limit was reached.');\n throw new MayuraError('INVALID_CONFIG', 'Bundle operations must be a bounded list of plain execution identities and cost bounds.');\n }\n}\n\n/** Existing settlement semantics, shared by ordinary reservations and consumed bundle tickets. */\nfunction reservationFor(account: Account, path: readonly Account[], maxMicros: number, ticket?: TicketState): Reservation {\n const bound = BigInt(maxMicros); let settled = false;\n const settleUsage = (knownCostMicros: number, unknownCostMicros: number): void => {\n if (settled) throw new MayuraError('CONFLICT', 'Reservation is already settled.');\n if (!Number.isSafeInteger(knownCostMicros) || knownCostMicros < 0\n || !Number.isSafeInteger(unknownCostMicros) || unknownCostMicros < 0) {\n throw new MayuraError('BUDGET_EXCEEDED', 'Reported cost is invalid; reservation retained.');\n }\n settled = true;\n const known = BigInt(knownCostMicros); const unknown = BigInt(unknownCostMicros);\n // Closing, cancellation, or another reservation's overrun never discards known late usage.\n for (const ancestor of path) { ancestor.reserved -= bound; ancestor.reserved += unknown; ancestor.spent += known; }\n if (ticket) {\n ticket.status = unknownCostMicros === 0 ? 'settled' : 'unknown';\n if (unknownCostMicros === 0) account.ledger.outstandingTickets--;\n }\n if (known + unknown > bound) {\n account.ledger.blocked = true;\n throw new MayuraError('BUDGET_EXCEEDED', 'Reported usage exceeded its bound; known and unresolved usage were retained.');\n }\n };\n return Object.freeze({\n settle: (actualMicros: number): void => { settleUsage(actualMicros, 0); },\n settleUsage,\n });\n}\n\nfunction ticketFor(value: BudgetTicket): TicketState {\n const ticket = tickets.get(value);\n if (!ticket) throw new MayuraError('INVALID_CONFIG', 'A genuine execution ticket receiver is required.');\n return ticket;\n}\n\n/** Private cleanup deliberately ignores closure and overruns: undispatched holds are still releasable. */\nfunction cancelHeld(ticket: TicketState): void {\n ticket.status = 'cancelled';\n for (const ancestor of ticket.path) { ancestor.heldCalls--; ancestor.reserved -= ticket.bound; }\n ticket.account.ledger.outstandingTickets--;\n}\n\nfunction startTicket(this: BudgetTicket): Reservation {\n const ticket = ticketFor(this);\n if (ticket.status !== 'held') throw new MayuraError('CONFLICT', 'Execution ticket is no longer held.');\n assertOpen(ticket.account, ticket.path);\n // Every admission already counts these held slots; converting one cannot increase total capacity use.\n ticket.status = 'started';\n for (const ancestor of ticket.path) { ancestor.heldCalls--; ancestor.calls++; }\n return reservationFor(ticket.account, ticket.path, ticket.maxCostMicros, ticket);\n}\n\nfunction cancelTicket(this: BudgetTicket): void {\n const ticket = ticketFor(this);\n if (ticket.status === 'cancelled') return;\n if (ticket.status !== 'held') throw new MayuraError('CONFLICT', 'Started execution tickets cannot be cancelled.');\n cancelHeld(ticket);\n}\n\nfunction closeBundle(this: BudgetBundle): void {\n const bundle = bundles.get(this);\n if (!bundle) throw new MayuraError('INVALID_CONFIG', 'A genuine execution bundle receiver is required.');\n if (bundle.closed) return;\n for (const ticket of bundle.tickets) if (ticket.status === 'held') cancelHeld(ticket);\n bundle.closed = true;\n}\n\n/**\n * Process-local shared synchronous ledger. Reserve before awaits so children cannot spend\n * the same remaining funds. Ancestor totals include descendants and must not be added together.\n * Every admitted execution counts once at each ancestor, even when its monetary bound is zero.\n * Accounts are final, frozen authority handles; they are not a sandbox for arbitrary local code.\n */\nexport class Budget {\n constructor(readonly maxCostMicros: number, readonly maxCalls: number) {\n if (new.target !== Budget) throw new MayuraError('INVALID_CONFIG', 'Budget accounts cannot be subclassed.');\n costLimit(maxCostMicros); assertPositiveInteger(maxCalls, 'maxCalls');\n accounts.set(this, {\n ledger: { ids: new Set(['root']), ticketIds: new Set(), outstandingTickets: 0, blocked: false }, ancestors: Object.freeze([]),\n identity: Object.freeze({ id: 'root', lineage: Object.freeze(['root']), depth: 0 }),\n maxCostMicros, maxCalls, reserved: 0n, spent: 0n, calls: 0, heldCalls: 0, closed: false,\n });\n Object.freeze(this);\n }\n\n /** Frozen correlation metadata; contains no reference through which a child could spend as its parent. */\n get identity(): BudgetIdentity { return accountFor(this).identity; }\n\n /**\n * Create a child ceiling without consuming funds or calls. Children compete for remaining\n * ancestor capacity at reserve time. At most 1,024 lifetime accounts and depth 32 per ledger.\n */\n fork(options: BudgetForkOptions): Budget {\n const parent = accountFor(this); const path = pathFor(parent);\n const config = forkOptions(options);\n assertOpen(parent, path);\n if (config.maxCostMicros > parent.maxCostMicros || config.maxCalls > parent.maxCalls) {\n throw new MayuraError('INVALID_CONFIG', 'Child ceilings cannot exceed their parent ceilings.');\n }\n if (parent.ledger.ids.has(config.id)) throw new MayuraError('CONFLICT', 'The budget account identity is already in use.');\n if (parent.identity.depth >= maximumDepth || parent.ledger.ids.size >= maximumAccounts) {\n throw new MayuraError('LIMIT_EXCEEDED', 'The budget account count or ancestry depth limit was reached.');\n }\n const child = new Budget(config.maxCostMicros, config.maxCalls);\n const identity: BudgetIdentity = Object.freeze({ id: config.id, parentId: parent.identity.id,\n lineage: Object.freeze([...parent.identity.lineage, config.id]), depth: parent.identity.depth + 1,\n });\n accounts.set(child, { ledger: parent.ledger, ancestors: Object.freeze(path), identity,\n maxCostMicros: config.maxCostMicros, maxCalls: config.maxCalls, reserved: 0n, spent: 0n, calls: 0, heldCalls: 0, closed: false,\n });\n parent.ledger.ids.add(config.id);\n return child;\n }\n\n /** Atomically reserve every ancestor before dispatch; rejected admission changes no counter. */\n reserve(maxMicros: number): Reservation {\n const account = accountFor(this); const path = Object.freeze(pathFor(account));\n if (!Number.isSafeInteger(maxMicros) || maxMicros < 0) throw new MayuraError('INVALID_CONFIG', 'A non-negative safe-integer cost bound is required.');\n assertOpen(account, path);\n const bound = BigInt(maxMicros);\n if (path.some(ancestor => ancestor.heldCalls >= ancestor.maxCalls - ancestor.calls || bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved)) {\n throw new MayuraError('BUDGET_EXCEEDED', 'Execution budget exhausted; no new call was dispatched.');\n }\n // No callback or await can interleave ancestor validation and commit.\n for (const ancestor of path) { ancestor.calls++; ancestor.reserved += bound; }\n return reservationFor(account, path, maxMicros);\n }\n\n /**\n * Atomically protect 1–128 future calls and their money on this account and every ancestor.\n * Each ledger permits 1,024 held/unsettled bundle tickets and 16,384 lifetime ticket identities.\n * Held calls do not count as consumed calls until start; failed admission never burns identities.\n * IDs use 1–256 ASCII letters/digits plus internal '.', '_', ':', '/', or '-'.\n */\n reserveBundle(operations: readonly BundleOperation[]): BudgetBundle {\n const account = accountFor(this); const path = Object.freeze(pathFor(account));\n const config = bundleOperations(operations);\n const identities = new Set(config.map(operation => operation.id));\n const bound = config.reduce((total, operation) => total + BigInt(operation.maxCostMicros), 0n);\n // Reflection above can invoke a trusted Proxy trap that reenters this account. Therefore all\n // mutable ledger predicates are evaluated only after the complete descriptor snapshot.\n assertOpen(account, path);\n if (identities.size !== config.length || config.some(operation => account.ledger.ticketIds.has(operation.id))) {\n throw new MayuraError('CONFLICT', 'An execution ticket identity is already in use.');\n }\n if (account.ledger.outstandingTickets + config.length > maximumOutstandingTickets\n || account.ledger.ticketIds.size + config.length > maximumTicketIds) {\n throw new MayuraError('LIMIT_EXCEEDED', 'The execution ticket count or lifetime identity limit was reached.');\n }\n if (path.some(ancestor => config.length > ancestor.maxCalls - ancestor.calls - ancestor.heldCalls\n || bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved)) {\n throw new MayuraError('BUDGET_EXCEEDED', 'Execution budget exhausted; no future call was admitted.');\n }\n const states: TicketState[] = [];\n const handles = config.map(operation => {\n const state: TicketState = { account, path, maxCostMicros: operation.maxCostMicros, bound: BigInt(operation.maxCostMicros), status: 'held' };\n const handle: BudgetTicket = Object.freeze({ id: operation.id, maxCostMicros: operation.maxCostMicros, start: startTicket, cancel: cancelTicket });\n states.push(state); tickets.set(handle, state); return handle;\n });\n const bundle: BudgetBundle = Object.freeze({ tickets: Object.freeze(handles), close: closeBundle });\n bundles.set(bundle, { tickets: Object.freeze(states), closed: false });\n for (const ancestor of path) { ancestor.reserved += bound; ancestor.heldCalls += config.length; }\n for (const operation of config) account.ledger.ticketIds.add(operation.id);\n account.ledger.outstandingTickets += config.length;\n return bundle;\n }\n\n /** Frozen future-call capacity, including descendants; additive to the unchanged usage snapshot. */\n capacitySnapshot(): Readonly<{ heldCalls: number }> {\n return Object.freeze({ heldCalls: accountFor(this).heldCalls });\n }\n\n /** Stop new reserves/forks/starts throughout this subtree; explicit cleanup and late settlement remain valid. */\n close(): void { accountFor(this).closed = true; }\n\n /** Very large provider overruns use an exact decimal string instead of a lossy JSON number. */\n snapshot(): Readonly<BudgetSnapshot> {\n const account = accountFor(this);\n const spentMicros = account.spent <= safeInteger ? Number(account.spent) : account.spent.toString();\n // Reservations remain bounded by the originally configured safe-integer ceiling, even after overruns.\n return Object.freeze({ spentMicros, reservedMicros: Number(account.reserved), calls: account.calls });\n }\n}\n\n// Protect the owned method table as well as instances; this does not modify host/built-in prototypes.\nObject.freeze(Budget.prototype);\nObject.freeze(Budget);\n"]}
|
|
1
|
+
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AA0EjE;;;GAGG;AACH,SAAS,SAAS,CAAC,IAAwB,EAAE,KAAa,EAAE,KAAa;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,GAAG,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpG,IAAI,IAAI;QAAE,OAAO,IAAI,WAAW,CAAC,iBAAiB,EAAE,8BAA8B,I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C,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACpG,sGAAsG;QACtG,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACxG,CAAC;CACF;AAED,sGAAsG;AACtG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC","sourcesContent":["import { MayuraError, assertPositiveInteger } from './errors.js';\n\nexport interface Reservation {\n /** Settle only confirmed cost. Unknown cost deliberately retains the complete reservation. */\n settle(actualMicros: number): void;\n /** Atomically charge confirmed usage, retain an unresolved bound and release unused capacity. */\n settleUsage(knownCostMicros: number, unknownCostMicros: number): void;\n}\n\n/** One fixed-cost future execution; IDs remain unique throughout their shared ledger's lifetime. */\nexport interface BundleOperation {\n readonly id: string;\n readonly maxCostMicros: number;\n}\n\n/** Genuine receiver-bound authority for one held execution, not an executor or a transferable ID. */\nexport interface BudgetTicket {\n readonly id: string;\n readonly maxCostMicros: number;\n /** Consume one held call exactly once. Monetary settlement remains independently required. */\n start(): Reservation;\n /** Release only never-started capacity, including after account closure; repeated cancellation is harmless. */\n cancel(): void;\n}\n\n/** Atomically admitted future calls. Closure cancels held tickets, never already-started usage. */\nexport interface BudgetBundle {\n readonly tickets: readonly BudgetTicket[];\n close(): void;\n}\n\n/** Child limits are ceilings on shared funds, not prepaid allocations or guaranteed earmarks. */\nexport interface BudgetForkOptions {\n /** Unique within the entire ledger; root is reserved and closed identities cannot be reused. */\n readonly id: string;\n readonly maxCostMicros: number;\n readonly maxCalls: number;\n}\n\n/** Correlate account usage without exposing an authority-bearing parent/root account reference. */\nexport interface BudgetIdentity {\n readonly id: string;\n readonly parentId?: string;\n /** Root identity is included; the root has depth zero. */\n readonly lineage: readonly string[];\n readonly depth: number;\n}\n\nexport interface BudgetSnapshot {\n readonly spentMicros: number | string;\n readonly reservedMicros: number;\n readonly calls: number;\n}\n\ninterface Ledger {\n readonly ids: Set<string>;\n readonly ticketIds: Set<string>;\n /** Only named bundle tickets count here: held plus started but not yet validly settled. */\n outstandingTickets: number;\n blocked: boolean;\n}\ninterface Account {\n readonly ledger: Ledger;\n readonly ancestors: readonly Account[];\n readonly identity: BudgetIdentity;\n readonly maxCostMicros: number;\n readonly maxCalls: number;\n reserved: bigint;\n spent: bigint;\n calls: number;\n heldCalls: number;\n closed: boolean;\n}\n\n/**\n * Say which limit stopped a call, with the numbers (costs and counts, never content), and how to raise a budget of 0,\n * the default for an agent run.\n */\nfunction exhausted(path: readonly Account[], calls: number, bound: bigint): MayuraError {\n const full = path.find(ancestor => calls > ancestor.maxCalls - ancestor.calls - ancestor.heldCalls);\n if (full) return new MayuraError('BUDGET_EXCEEDED', `The budget's call limit of ${full.maxCalls} is used up; no new call was started.`);\n const short = path.find(ancestor => bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved) ?? path[0]!;\n const left = BigInt(short.maxCostMicros) - short.spent - short.reserved;\n const hint = short.maxCostMicros === 0\n ? ' The budget is 0, so nothing that costs money can run: for an agent run, set limits.maxCostMicros in createRuntime; for a workflow, its runtime\\'s maxCostMicros.'\n : '';\n return new MayuraError('BUDGET_EXCEEDED', `The call may cost up to ${bound} micros, but only ${left < 0n ? 0n : left} of the budget's ${short.maxCostMicros} micros are left; no new call was started.${hint}`);\n}\n\ninterface TicketState {\n readonly account: Account;\n readonly path: readonly Account[];\n readonly maxCostMicros: number;\n readonly bound: bigint;\n status: 'held' | 'started' | 'cancelled' | 'settled' | 'unknown';\n}\ninterface BundleState { readonly tickets: readonly TicketState[]; closed: boolean }\n\nconst maximumAccounts = 1_024;\nconst maximumDepth = 32;\nconst maximumBundleOperations = 128;\nconst maximumOutstandingTickets = 1_024;\nconst maximumTicketIds = 16_384;\nconst safeInteger = BigInt(Number.MAX_SAFE_INTEGER);\n// Runtime-private state prevents JavaScript writes to TypeScript-only private/readonly fields.\nconst accounts = new WeakMap<Budget, Account>();\nconst tickets = new WeakMap<BudgetTicket, TicketState>();\nconst bundles = new WeakMap<BudgetBundle, BundleState>();\n\nfunction costLimit(value: number): void {\n if (!Number.isSafeInteger(value) || value < 0) throw new MayuraError('INVALID_CONFIG', 'maxCostMicros must be a non-negative safe integer.');\n}\n\n/** Reject structural lookalikes, inherited prototypes, and proxy wrappers around real accounts. */\nexport function assertBudget(value: unknown): asserts value is Budget {\n if (typeof value !== 'object' || value === null || !accounts.has(value as Budget)) {\n throw new MayuraError('INVALID_CONFIG', 'A genuine shared execution Budget is required.');\n }\n}\n\n/** Trusted-host ownership check; a common ledger or copied identity does not convey this account's authority. */\nexport function assertBudgetTicket(value: unknown, owner: Budget): asserts value is BudgetTicket {\n assertBudget(owner);\n const ticket = typeof value === 'object' && value !== null ? tickets.get(value as BudgetTicket) : undefined;\n if (!ticket || ticket.account !== accounts.get(owner)) {\n throw new MayuraError('INVALID_CONFIG', 'A genuine execution ticket owned by the exact account is required.');\n }\n}\n\nfunction accountFor(value: Budget): Account {\n assertBudget(value);\n return accounts.get(value)!;\n}\n\nfunction pathFor(account: Account): readonly Account[] { return [...account.ancestors, account]; }\n\nfunction assertOpen(account: Account, path: readonly Account[]): void {\n if (account.ledger.blocked || path.some(ancestor => ancestor.closed)) {\n throw new MayuraError('BUDGET_EXCEEDED', 'Execution budget admissions are closed; no new call was dispatched.');\n }\n}\n\n/** Snapshot child configuration without invoking accessor properties or reflecting thrown text. */\nfunction forkOptions(value: BudgetForkOptions): BudgetForkOptions {\n let id: unknown; let maxCostMicros: unknown; let maxCalls: unknown;\n try {\n if (!value || typeof value !== 'object' || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) throw new Error();\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const keys = Reflect.ownKeys(descriptors);\n if (keys.length !== 3 || keys.some(key => !['id', 'maxCostMicros', 'maxCalls'].includes(key as string))) throw new Error();\n for (const key of ['id', 'maxCostMicros', 'maxCalls'] as const) if (!descriptors[key] || !('value' in descriptors[key])) throw new Error();\n id = descriptors['id']!.value; maxCostMicros = descriptors['maxCostMicros']!.value; maxCalls = descriptors['maxCalls']!.value;\n } catch { throw new MayuraError('INVALID_CONFIG', 'Child budget configuration must contain plain data fields.'); }\n if (typeof id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(id)) {\n throw new MayuraError('INVALID_CONFIG', 'Child budget ID must be a bounded stable identifier.');\n }\n costLimit(maxCostMicros as number); assertPositiveInteger(maxCalls as number, 'maxCalls');\n return { id, maxCostMicros: maxCostMicros as number, maxCalls: maxCalls as number };\n}\n\n/** Snapshot every supplied descriptor before checking mutable ledger state; never execute getters or iterators. */\nfunction bundleOperations(value: readonly BundleOperation[]): readonly BundleOperation[] {\n const excessiveLength = Symbol('bundle-length');\n try {\n if (!Array.isArray(value)) throw new Error();\n const length = Object.getOwnPropertyDescriptor(value, 'length');\n if (!length || !('value' in length) || !Number.isSafeInteger(length.value) || length.value < 1) throw new Error();\n if (length.value > maximumBundleOperations) throw excessiveLength;\n const size = length.value as number;\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const keys = Reflect.ownKeys(descriptors);\n if (keys.length !== size + 1 || keys.some(key => key !== 'length'\n && (typeof key !== 'string' || !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= size))) throw new Error();\n const result: BundleOperation[] = [];\n for (let index = 0; index < size; index++) {\n const descriptor = descriptors[String(index)];\n if (!descriptor || !('value' in descriptor)) throw new Error();\n const operation = descriptor.value as unknown;\n if (!operation || typeof operation !== 'object' || ![Object.prototype, null].includes(Object.getPrototypeOf(operation))) throw new Error();\n const fields = Object.getOwnPropertyDescriptors(operation);\n const fieldKeys = Reflect.ownKeys(fields);\n if (fieldKeys.length !== 2 || fieldKeys.some(key => key !== 'id' && key !== 'maxCostMicros')\n || !fields['id'] || !('value' in fields['id']) || !fields['maxCostMicros'] || !('value' in fields['maxCostMicros'])) throw new Error();\n const id: unknown = fields['id'].value; const maxCostMicros: unknown = fields['maxCostMicros'].value;\n if (typeof id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,255}$/.test(id)\n || typeof maxCostMicros !== 'number' || !Number.isSafeInteger(maxCostMicros) || maxCostMicros < 0) throw new Error();\n result.push({ id, maxCostMicros });\n }\n return result;\n } catch (error) {\n if (error === excessiveLength) throw new MayuraError('LIMIT_EXCEEDED', 'The execution bundle operation limit was reached.');\n throw new MayuraError('INVALID_CONFIG', 'Bundle operations must be a bounded list of plain execution identities and cost bounds.');\n }\n}\n\n/** Existing settlement semantics, shared by ordinary reservations and consumed bundle tickets. */\nfunction reservationFor(account: Account, path: readonly Account[], maxMicros: number, ticket?: TicketState): Reservation {\n const bound = BigInt(maxMicros); let settled = false;\n const settleUsage = (knownCostMicros: number, unknownCostMicros: number): void => {\n if (settled) throw new MayuraError('CONFLICT', 'Reservation is already settled.');\n if (!Number.isSafeInteger(knownCostMicros) || knownCostMicros < 0\n || !Number.isSafeInteger(unknownCostMicros) || unknownCostMicros < 0) {\n throw new MayuraError('BUDGET_EXCEEDED', 'Reported cost is invalid; reservation retained.');\n }\n settled = true;\n const known = BigInt(knownCostMicros); const unknown = BigInt(unknownCostMicros);\n // Closing, cancellation, or another reservation's overrun never discards known late usage.\n for (const ancestor of path) { ancestor.reserved -= bound; ancestor.reserved += unknown; ancestor.spent += known; }\n if (ticket) {\n ticket.status = unknownCostMicros === 0 ? 'settled' : 'unknown';\n if (unknownCostMicros === 0) account.ledger.outstandingTickets--;\n }\n if (known + unknown > bound) {\n account.ledger.blocked = true;\n throw new MayuraError('BUDGET_EXCEEDED', 'Reported usage exceeded its bound; known and unresolved usage were retained.');\n }\n };\n return Object.freeze({\n settle: (actualMicros: number): void => { settleUsage(actualMicros, 0); },\n settleUsage,\n });\n}\n\nfunction ticketFor(value: BudgetTicket): TicketState {\n const ticket = tickets.get(value);\n if (!ticket) throw new MayuraError('INVALID_CONFIG', 'A genuine execution ticket receiver is required.');\n return ticket;\n}\n\n/** Private cleanup deliberately ignores closure and overruns: undispatched holds are still releasable. */\nfunction cancelHeld(ticket: TicketState): void {\n ticket.status = 'cancelled';\n for (const ancestor of ticket.path) { ancestor.heldCalls--; ancestor.reserved -= ticket.bound; }\n ticket.account.ledger.outstandingTickets--;\n}\n\nfunction startTicket(this: BudgetTicket): Reservation {\n const ticket = ticketFor(this);\n if (ticket.status !== 'held') throw new MayuraError('CONFLICT', 'Execution ticket is no longer held.');\n assertOpen(ticket.account, ticket.path);\n // Every admission already counts these held slots; converting one cannot increase total capacity use.\n ticket.status = 'started';\n for (const ancestor of ticket.path) { ancestor.heldCalls--; ancestor.calls++; }\n return reservationFor(ticket.account, ticket.path, ticket.maxCostMicros, ticket);\n}\n\nfunction cancelTicket(this: BudgetTicket): void {\n const ticket = ticketFor(this);\n if (ticket.status === 'cancelled') return;\n if (ticket.status !== 'held') throw new MayuraError('CONFLICT', 'Started execution tickets cannot be cancelled.');\n cancelHeld(ticket);\n}\n\nfunction closeBundle(this: BudgetBundle): void {\n const bundle = bundles.get(this);\n if (!bundle) throw new MayuraError('INVALID_CONFIG', 'A genuine execution bundle receiver is required.');\n if (bundle.closed) return;\n for (const ticket of bundle.tickets) if (ticket.status === 'held') cancelHeld(ticket);\n bundle.closed = true;\n}\n\n/**\n * Process-local shared synchronous ledger. Reserve before awaits so children cannot spend\n * the same remaining funds. Ancestor totals include descendants and must not be added together.\n * Every admitted execution counts once at each ancestor, even when its monetary bound is zero.\n * Accounts are final, frozen authority handles; they are not a sandbox for arbitrary local code.\n */\nexport class Budget {\n constructor(readonly maxCostMicros: number, readonly maxCalls: number) {\n if (new.target !== Budget) throw new MayuraError('INVALID_CONFIG', 'Budget accounts cannot be subclassed.');\n costLimit(maxCostMicros); assertPositiveInteger(maxCalls, 'maxCalls');\n accounts.set(this, {\n ledger: { ids: new Set(['root']), ticketIds: new Set(), outstandingTickets: 0, blocked: false }, ancestors: Object.freeze([]),\n identity: Object.freeze({ id: 'root', lineage: Object.freeze(['root']), depth: 0 }),\n maxCostMicros, maxCalls, reserved: 0n, spent: 0n, calls: 0, heldCalls: 0, closed: false,\n });\n Object.freeze(this);\n }\n\n /** Frozen correlation metadata; contains no reference through which a child could spend as its parent. */\n get identity(): BudgetIdentity { return accountFor(this).identity; }\n\n /**\n * Create a child ceiling without consuming funds or calls. Children compete for remaining\n * ancestor capacity at reserve time. At most 1,024 lifetime accounts and depth 32 per ledger.\n */\n fork(options: BudgetForkOptions): Budget {\n const parent = accountFor(this); const path = pathFor(parent);\n const config = forkOptions(options);\n assertOpen(parent, path);\n if (config.maxCostMicros > parent.maxCostMicros || config.maxCalls > parent.maxCalls) {\n throw new MayuraError('INVALID_CONFIG', 'Child ceilings cannot exceed their parent ceilings.');\n }\n if (parent.ledger.ids.has(config.id)) throw new MayuraError('CONFLICT', 'The budget account identity is already in use.');\n if (parent.identity.depth >= maximumDepth || parent.ledger.ids.size >= maximumAccounts) {\n throw new MayuraError('LIMIT_EXCEEDED', 'The budget account count or ancestry depth limit was reached.');\n }\n const child = new Budget(config.maxCostMicros, config.maxCalls);\n const identity: BudgetIdentity = Object.freeze({ id: config.id, parentId: parent.identity.id,\n lineage: Object.freeze([...parent.identity.lineage, config.id]), depth: parent.identity.depth + 1,\n });\n accounts.set(child, { ledger: parent.ledger, ancestors: Object.freeze(path), identity,\n maxCostMicros: config.maxCostMicros, maxCalls: config.maxCalls, reserved: 0n, spent: 0n, calls: 0, heldCalls: 0, closed: false,\n });\n parent.ledger.ids.add(config.id);\n return child;\n }\n\n /** Atomically reserve every ancestor before dispatch; rejected admission changes no counter. */\n reserve(maxMicros: number): Reservation {\n const account = accountFor(this); const path = Object.freeze(pathFor(account));\n if (!Number.isSafeInteger(maxMicros) || maxMicros < 0) throw new MayuraError('INVALID_CONFIG', 'A non-negative safe-integer cost bound is required.');\n assertOpen(account, path);\n const bound = BigInt(maxMicros);\n if (path.some(ancestor => ancestor.heldCalls >= ancestor.maxCalls - ancestor.calls || bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved)) {\n throw exhausted(path, 1, bound);\n }\n // No callback or await can interleave ancestor validation and commit.\n for (const ancestor of path) { ancestor.calls++; ancestor.reserved += bound; }\n return reservationFor(account, path, maxMicros);\n }\n\n /**\n * Atomically protect 1–128 future calls and their money on this account and every ancestor.\n * Each ledger permits 1,024 held/unsettled bundle tickets and 16,384 lifetime ticket identities.\n * Held calls do not count as consumed calls until start; failed admission never burns identities.\n * IDs use 1–256 ASCII letters/digits plus internal '.', '_', ':', '/', or '-'.\n */\n reserveBundle(operations: readonly BundleOperation[]): BudgetBundle {\n const account = accountFor(this); const path = Object.freeze(pathFor(account));\n const config = bundleOperations(operations);\n const identities = new Set(config.map(operation => operation.id));\n const bound = config.reduce((total, operation) => total + BigInt(operation.maxCostMicros), 0n);\n // Reflection above can invoke a trusted Proxy trap that reenters this account. Therefore all\n // mutable ledger predicates are evaluated only after the complete descriptor snapshot.\n assertOpen(account, path);\n if (identities.size !== config.length || config.some(operation => account.ledger.ticketIds.has(operation.id))) {\n throw new MayuraError('CONFLICT', 'An execution ticket identity is already in use.');\n }\n if (account.ledger.outstandingTickets + config.length > maximumOutstandingTickets\n || account.ledger.ticketIds.size + config.length > maximumTicketIds) {\n throw new MayuraError('LIMIT_EXCEEDED', 'The execution ticket count or lifetime identity limit was reached.');\n }\n if (path.some(ancestor => config.length > ancestor.maxCalls - ancestor.calls - ancestor.heldCalls\n || bound > BigInt(ancestor.maxCostMicros) - ancestor.spent - ancestor.reserved)) {\n throw exhausted(path, config.length, bound);\n }\n const states: TicketState[] = [];\n const handles = config.map(operation => {\n const state: TicketState = { account, path, maxCostMicros: operation.maxCostMicros, bound: BigInt(operation.maxCostMicros), status: 'held' };\n const handle: BudgetTicket = Object.freeze({ id: operation.id, maxCostMicros: operation.maxCostMicros, start: startTicket, cancel: cancelTicket });\n states.push(state); tickets.set(handle, state); return handle;\n });\n const bundle: BudgetBundle = Object.freeze({ tickets: Object.freeze(handles), close: closeBundle });\n bundles.set(bundle, { tickets: Object.freeze(states), closed: false });\n for (const ancestor of path) { ancestor.reserved += bound; ancestor.heldCalls += config.length; }\n for (const operation of config) account.ledger.ticketIds.add(operation.id);\n account.ledger.outstandingTickets += config.length;\n return bundle;\n }\n\n /** Frozen future-call capacity, including descendants; additive to the unchanged usage snapshot. */\n capacitySnapshot(): Readonly<{ heldCalls: number }> {\n return Object.freeze({ heldCalls: accountFor(this).heldCalls });\n }\n\n /** Stop new reserves/forks/starts throughout this subtree; explicit cleanup and late settlement remain valid. */\n close(): void { accountFor(this).closed = true; }\n\n /** Very large provider overruns use an exact decimal string instead of a lossy JSON number. */\n snapshot(): Readonly<BudgetSnapshot> {\n const account = accountFor(this);\n const spentMicros = account.spent <= safeInteger ? Number(account.spent) : account.spent.toString();\n // Reservations remain bounded by the originally configured safe-integer ceiling, even after overruns.\n return Object.freeze({ spentMicros, reservedMicros: Number(account.reserved), calls: account.calls });\n }\n}\n\n// Protect the owned method table as well as instances; this does not modify host/built-in prototypes.\nObject.freeze(Budget.prototype);\nObject.freeze(Budget);\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PublicError } from './errors.js';
|
|
2
2
|
import { MayuraError } from './errors.js';
|
|
3
3
|
import type { JsonValue, JsonObject } from './json.js';
|
|
4
|
+
import type { Media, MediaType } from './media.js';
|
|
4
5
|
export interface Scope {
|
|
5
6
|
readonly principalId: string;
|
|
6
7
|
readonly projectId: string;
|
|
@@ -84,9 +85,14 @@ export interface ModelTool {
|
|
|
84
85
|
readonly description: string;
|
|
85
86
|
readonly inputJsonSchema?: JsonObject;
|
|
86
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* One message of a model conversation. `media` holds images or PDFs the model should see: with the user's input, or
|
|
90
|
+
* returned by a tool. It is present only when there is some, and only for adapters that declare `capabilities.media`.
|
|
91
|
+
*/
|
|
87
92
|
export type ModelMessage = {
|
|
88
93
|
readonly role: 'user';
|
|
89
94
|
readonly content: JsonValue;
|
|
95
|
+
readonly media?: readonly Media[];
|
|
90
96
|
} | {
|
|
91
97
|
readonly role: 'assistant';
|
|
92
98
|
readonly calls: readonly ModelToolCall[];
|
|
@@ -95,6 +101,7 @@ export type ModelMessage = {
|
|
|
95
101
|
readonly callId: string;
|
|
96
102
|
readonly toolId: string;
|
|
97
103
|
readonly result: JsonValue;
|
|
104
|
+
readonly media?: readonly Media[];
|
|
98
105
|
};
|
|
99
106
|
export interface ModelToolCall {
|
|
100
107
|
readonly id: string;
|
|
@@ -109,6 +116,28 @@ export interface ModelRequest {
|
|
|
109
116
|
readonly maxOutputTokens: number;
|
|
110
117
|
/** Opaque bounded provider protocol state; private to this run and never a public output. */
|
|
111
118
|
readonly continuation?: JsonValue;
|
|
119
|
+
/**
|
|
120
|
+
* The agent's output as JSON Schema: what the final answer must look like. The runtime sends it when the agent has
|
|
121
|
+
* one (given, or generated from its output validator); an adapter configured with its own output schema uses that.
|
|
122
|
+
*/
|
|
123
|
+
readonly outputJsonSchema?: JsonObject;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* What `defineAgent` asks an adapter to check once, before any run: the tools and output schema it would be sent, and
|
|
127
|
+
* the media the agent accepts with its input or its tools may return.
|
|
128
|
+
*/
|
|
129
|
+
export interface ModelDefinitionCheck {
|
|
130
|
+
readonly tools: readonly ModelTool[];
|
|
131
|
+
readonly outputJsonSchema?: JsonObject;
|
|
132
|
+
readonly media?: {
|
|
133
|
+
readonly types: readonly MediaType[];
|
|
134
|
+
readonly urls: boolean;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** The media a model can see: which types, and whether it can take a URL (which its provider then fetches). */
|
|
138
|
+
export interface ModelMediaCapability {
|
|
139
|
+
readonly types: readonly MediaType[];
|
|
140
|
+
readonly urls: boolean;
|
|
112
141
|
}
|
|
113
142
|
export interface ModelUsage {
|
|
114
143
|
readonly costMicros: number;
|
|
@@ -118,6 +147,26 @@ export declare class ModelInvocationError extends MayuraError {
|
|
|
118
147
|
readonly costMicros: number;
|
|
119
148
|
constructor(costMicros: number);
|
|
120
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Why a model call failed, in words Mayura can show safely. An adapter picks the reason; the message is Mayura's own,
|
|
152
|
+
* so no provider text or credential can reach an outcome through it.
|
|
153
|
+
*/
|
|
154
|
+
export type ModelFailureReason = 'authentication' | 'rate_limited' | 'unavailable' | 'timeout' | 'rejected' | 'invalid_response' | 'refused' | 'configuration';
|
|
155
|
+
export declare function isModelFailureReason(value: unknown): value is ModelFailureReason;
|
|
156
|
+
/** The fixed public message for a failure reason, with the provider's HTTP status when there is one. */
|
|
157
|
+
export declare function modelFailureMessage(reason: ModelFailureReason, httpStatus?: number): string;
|
|
158
|
+
/** A model call that failed for a known reason. `costMicros`, when given, is usage the provider confirmed before failing. */
|
|
159
|
+
export declare class ModelProviderError extends MayuraError {
|
|
160
|
+
readonly reason: ModelFailureReason;
|
|
161
|
+
/** Present only when the provider answered with an HTTP error status. */
|
|
162
|
+
readonly httpStatus?: number;
|
|
163
|
+
/** Present only when the provider confirmed usage before the failure. */
|
|
164
|
+
readonly costMicros?: number;
|
|
165
|
+
constructor(reason: ModelFailureReason, options?: {
|
|
166
|
+
readonly httpStatus?: number;
|
|
167
|
+
readonly costMicros?: number;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
121
170
|
export type ModelResponse = {
|
|
122
171
|
readonly type: 'final';
|
|
123
172
|
readonly output: JsonValue;
|
|
@@ -144,13 +193,21 @@ export type ModelStreamEvent = {
|
|
|
144
193
|
};
|
|
145
194
|
export interface ModelAdapter {
|
|
146
195
|
readonly id: string;
|
|
196
|
+
/** What the model can do. Without `media`, it cannot see images or PDFs, and agents that accept media refuse it. */
|
|
147
197
|
readonly capabilities: {
|
|
148
198
|
readonly tools: boolean;
|
|
149
199
|
readonly structuredOutput: boolean;
|
|
200
|
+
readonly media?: ModelMediaCapability;
|
|
150
201
|
};
|
|
151
202
|
readonly maxCostMicros: number;
|
|
152
203
|
generate(request: ModelRequest): Promise<ModelResponse>;
|
|
153
204
|
/** Optional streamed form of `generate`, used only for agents that opt into streaming. */
|
|
154
205
|
stream?(request: ModelRequest): AsyncIterable<ModelStreamEvent>;
|
|
206
|
+
/**
|
|
207
|
+
* Optional: called by `defineAgent` with the agent's tools and output schema. Throw INVALID_CONFIG, with a message
|
|
208
|
+
* that says what to fix, when this adapter could never send them (for example a schema its provider refuses), so the
|
|
209
|
+
* mistake shows when the agent is defined instead of on its first call.
|
|
210
|
+
*/
|
|
211
|
+
checkDefinition?(definition: ModelDefinitionCheck): void;
|
|
155
212
|
}
|
|
156
213
|
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../src/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../src/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,KAAK;IAAG,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,C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CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,CAAC;AACpE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,oHAAoH;IACpH,QAAQ,CAAC,YAAY,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,oBAAoB,CAAA;KAAE,CAAC;IAC9H,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACxD,0FAA0F;IAC1F,MAAM,CAAC,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAChE;;;;OAIG;IACH,eAAe,CAAC,CAAC,UAAU,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC1D"}
|
|
@@ -10,4 +10,40 @@ export class ModelInvocationError extends MayuraError {
|
|
|
10
10
|
Object.freeze(this);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
const modelFailureReasons = ['authentication', 'rate_limited', 'unavailable', 'timeout', 'rejected', 'invalid_response', 'refused', 'configuration'];
|
|
14
|
+
export function isModelFailureReason(value) { return modelFailureReasons.includes(value); }
|
|
15
|
+
/** The fixed public message for a failure reason, with the provider's HTTP status when there is one. */
|
|
16
|
+
export function modelFailureMessage(reason, httpStatus) {
|
|
17
|
+
const status = httpStatus === undefined ? '' : ` (HTTP ${httpStatus})`;
|
|
18
|
+
switch (reason) {
|
|
19
|
+
case 'authentication': return `The model provider refused the credentials or access to this model${status}. Check the API key and that it may use this model.`;
|
|
20
|
+
case 'rate_limited': return `The model provider's rate limit or quota was reached${status}. Try again later, or raise the limit with the provider.`;
|
|
21
|
+
case 'unavailable': return `The model provider was unavailable${status}. Try again later.`;
|
|
22
|
+
case 'timeout': return `The model provider did not answer in time. Try again, or raise the adapter's timeoutMs.`;
|
|
23
|
+
case 'rejected': return `The model provider rejected the request${status}. Check the model name and the adapter's settings.`;
|
|
24
|
+
case 'invalid_response': return 'The model provider returned a response Mayura could not use, for example an answer that is not the required JSON or no token usage.';
|
|
25
|
+
case 'refused': return 'The model refused to answer, or stopped before finishing (for example at its token limit).';
|
|
26
|
+
case 'configuration': return `The model adapter could not send this request: a tool's input schema or the output schema breaks the provider's rules, no output schema was given, or the request holds media this provider cannot take.`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** A model call that failed for a known reason. `costMicros`, when given, is usage the provider confirmed before failing. */
|
|
30
|
+
export class ModelProviderError extends MayuraError {
|
|
31
|
+
reason;
|
|
32
|
+
constructor(reason, options = {}) {
|
|
33
|
+
if (!isModelFailureReason(reason))
|
|
34
|
+
throw new MayuraError('INVALID_CONFIG', 'Unknown model failure reason.');
|
|
35
|
+
const { httpStatus, costMicros } = options;
|
|
36
|
+
if (httpStatus !== undefined && (!Number.isSafeInteger(httpStatus) || httpStatus < 100 || httpStatus > 599))
|
|
37
|
+
throw new MayuraError('INVALID_CONFIG', 'An HTTP status must be between 100 and 599.');
|
|
38
|
+
if (costMicros !== undefined && (!Number.isSafeInteger(costMicros) || costMicros < 0))
|
|
39
|
+
throw new MayuraError('INVALID_CONFIG', 'Known model usage must be a nonnegative safe integer.');
|
|
40
|
+
super(reason === 'configuration' ? 'INVALID_CONFIG' : 'MODEL_FAILED', modelFailureMessage(reason, httpStatus));
|
|
41
|
+
this.reason = reason;
|
|
42
|
+
if (httpStatus !== undefined)
|
|
43
|
+
Object.defineProperty(this, 'httpStatus', { value: httpStatus, enumerable: true });
|
|
44
|
+
if (costMicros !== undefined)
|
|
45
|
+
Object.defineProperty(this, 'costMicros', { value: costMicros, enumerable: true });
|
|
46
|
+
Object.freeze(this);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
13
49
|
//# sourceMappingURL=contracts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../src/contracts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA8E1C,6GAA6G;AAC7G,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAC9B,UAAU;IAA/B,YAAqB,UAAkB;QACrC,KAAK,CAAC,cAAc,EAAE,0DAA0D,CAAC,CAAC;0BAD/D,UAAU;QAE7B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC;YAAE,MAAM,IAAI,WAAW,CAAC,gBAAgB,EAAE,uDAAuD,CAAC,CAAC;QAC1J,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF","sourcesContent":["import type { PublicError } from './errors.js';\nimport { MayuraError } from './errors.js';\nimport type { JsonValue, JsonObject } from './json.js';\n\nexport interface Scope { readonly principalId: string; readonly projectId: string }\nexport type Effect = 'none' | 'read' | 'write' | 'host';\nexport interface Permissions { readonly allow: readonly string[] }\nexport interface ExecutionContext {\n readonly runId: string;\n readonly callId: string;\n readonly scope: Scope;\n readonly signal: AbortSignal;\n}\nexport interface ExecutionReceipt {\n readonly callId: string;\n readonly toolId: string;\n readonly execution: 'not_started' | 'succeeded' | 'failed' | 'unknown';\n readonly disclosure: 'released' | 'withheld';\n}\n/** Confirmed and unresolved cost within one pre-admitted execution bound. */\nexport interface ExecutionSettlement {\n readonly knownCostMicros: number;\n readonly unknownCostMicros: number;\n}\n/** Run-qualified evidence: call identifiers alone are not unique across descendants. */\nexport interface ExecutionEvidence {\n readonly runId: string;\n readonly receipt: ExecutionReceipt;\n}\nexport type Outcome<T> =\n | { readonly status: 'succeeded'; readonly output: T; readonly receipt?: ExecutionReceipt; readonly evidence?: readonly ExecutionEvidence[] }\n | { readonly status: 'failed' | 'blocked' | 'cancelled' | 'outcome_unknown'; readonly error: PublicError; readonly receipt?: ExecutionReceipt; readonly evidence?: readonly ExecutionEvidence[] };\nexport interface RunEvent {\n readonly runId: string;\n readonly sequence: number;\n readonly timestamp: string;\n readonly type: 'run.started' | 'model.started' | 'model.completed' | 'tool.started' | 'tool.completed'\n | 'hook.started' | 'hook.completed' | 'step.started' | 'step.completed' | 'delegate.started' | 'delegate.completed'\n | 'run.completed' | 'events.gap' | 'output.delta' | 'output.withheld';\n readonly metadata: Readonly<Record<string, string | number | boolean>>;\n}\nexport interface RunHandle<T> {\n readonly id: string;\n readonly profile: 'ephemeral';\n result(): Promise<Outcome<T>>;\n observe(options?: { readonly after?: number; readonly signal?: AbortSignal }): AsyncIterable<RunEvent>;\n cancel(): void;\n}\nexport interface GuardContext extends ExecutionContext { readonly boundary: 'input' | 'output' }\n/**\n * A guard allows content, blocks it, or rewrites it (for example to redact personal data). A rewritten value replaces\n * the content for the guards after it and is validated again against the boundary's schema before anything uses it.\n */\nexport type GuardVerdict = { readonly decision: 'allow' } | { readonly decision: 'block'; readonly reason?: string }\n | { readonly decision: 'rewrite'; readonly value: JsonValue };\nexport interface Guard {\n readonly id: string;\n check(value: JsonValue, context: GuardContext): Promise<GuardVerdict> | GuardVerdict;\n}\nexport interface ModelTool {\n readonly id: string;\n readonly description: string;\n readonly inputJsonSchema?: JsonObject;\n}\nexport type ModelMessage =\n | { readonly role: 'user'; readonly content: JsonValue }\n | { readonly role: 'assistant'; readonly calls: readonly ModelToolCall[] }\n | { readonly role: 'tool'; readonly callId: string; readonly toolId: string; readonly result: JsonValue };\nexport interface ModelToolCall { readonly id: string; readonly toolId: string; readonly input: JsonValue }\nexport interface ModelRequest {\n readonly instructions: string;\n readonly messages: readonly ModelMessage[];\n readonly tools: readonly ModelTool[];\n readonly signal: AbortSignal;\n readonly maxOutputTokens: number;\n /** Opaque bounded provider protocol state; private to this run and never a public output. */\n readonly continuation?: JsonValue;\n}\nexport interface ModelUsage { readonly costMicros: number }\n/** A failed provider invocation may still have confirmed billable usage. No raw failure text is accepted. */\nexport class ModelInvocationError extends MayuraError {\n constructor(readonly costMicros: number) {\n super('MODEL_FAILED', 'The model invocation failed after reporting known usage.');\n if (!Number.isSafeInteger(costMicros) || costMicros < 0) throw new MayuraError('INVALID_CONFIG', 'Known model usage must be a nonnegative safe integer.');\n Object.freeze(this);\n }\n}\nexport type ModelResponse =\n | { readonly type: 'final'; readonly output: JsonValue; readonly usage: ModelUsage; readonly continuation?: JsonValue }\n | { readonly type: 'tool_calls'; readonly calls: readonly ModelToolCall[]; readonly usage: ModelUsage; readonly continuation?: JsonValue };\n/** Model adapters are trusted code; declared bounds are enforced/accounted, not a provider billing guarantee. */\n/**\n * One event of a streamed model call: fragments of the final output's raw text as the provider produces them, then\n * exactly one complete response. The complete response is validated and accounted exactly as `generate` would return\n * it; fragments are provisional and never authoritative. Tool-call argument fragments and reasoning are never emitted.\n */\nexport type ModelStreamEvent =\n | { readonly type: 'output.delta'; readonly text: string }\n | { readonly type: 'response'; readonly response: ModelResponse };\nexport interface ModelAdapter {\n readonly id: string;\n readonly capabilities: { readonly tools: boolean; readonly structuredOutput: boolean };\n readonly maxCostMicros: number;\n generate(request: ModelRequest): Promise<ModelResponse>;\n /** Optional streamed form of `generate`, used only for agents that opt into streaming. */\n stream?(request: ModelRequest): AsyncIterable<ModelStreamEvent>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../src/contracts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAmG1C,6GAA6G;AAC7G,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAC9B,UAAU;IAA/B,YAAqB,UAAkB;QACrC,KAAK,CAAC,cAAc,EAAE,0DAA0D,CAAC,CAAC;0BAD/D,UAAU;QAE7B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC;Y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AAgB,EAAE,+BAA+B,CAAC,CAAC;QAC5G,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAC3C,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,GAAG,IAAI,UAAU,GAAG,GAAG,CAAC;YAAE,MAAM,IAAI,WAAW,CAAC,gBAAgB,EAAE,6CAA6C,CAAC,CAAC;QACpM,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC,CAAC;YAAE,MAAM,IAAI,WAAW,CAAC,gBAAgB,EAAE,uDAAuD,CAAC,CAAC;QACxL,KAAK,CAAC,MAAM,KAAK,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,cAAc,EAAE,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;QAC/G,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,UAAU,KAAK,SAAS;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QACjH,IAAI,UAAU,KAAK,SAAS;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QACjH,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF","sourcesContent":["import type { PublicError } from './errors.js';\nimport { MayuraError } from './errors.js';\nimport type { JsonValue, JsonObject } from './json.js';\nimport type { Media, MediaType } from './media.js';\n\nexport interface Scope { readonly principalId: string; readonly projectId: string }\nexport type Effect = 'none' | 'read' | 'write' | 'host';\nexport interface Permissions { readonly allow: readonly string[] }\nexport interface ExecutionContext {\n readonly runId: string;\n readonly callId: string;\n readonly scope: Scope;\n readonly signal: AbortSignal;\n}\nexport interface ExecutionReceipt {\n readonly callId: string;\n readonly toolId: string;\n readonly execution: 'not_started' | 'succeeded' | 'failed' | 'unknown';\n readonly disclosure: 'released' | 'withheld';\n}\n/** Confirmed and unresolved cost within one pre-admitted execution bound. */\nexport interface ExecutionSettlement {\n readonly knownCostMicros: number;\n readonly unknownCostMicros: number;\n}\n/** Run-qualified evidence: call identifiers alone are not unique across descendants. */\nexport interface ExecutionEvidence {\n readonly runId: string;\n readonly receipt: ExecutionReceipt;\n}\nexport type Outcome<T> =\n | { readonly status: 'succeeded'; readonly output: T; readonly receipt?: ExecutionReceipt; readonly evidence?: readonly ExecutionEvidence[] }\n | { readonly status: 'failed' | 'blocked' | 'cancelled' | 'outcome_unknown'; readonly error: PublicError; readonly receipt?: ExecutionReceipt; readonly evidence?: readonly ExecutionEvidence[] };\nexport interface RunEvent {\n readonly runId: string;\n readonly sequence: number;\n readonly timestamp: string;\n readonly type: 'run.started' | 'model.started' | 'model.completed' | 'tool.started' | 'tool.completed'\n | 'hook.started' | 'hook.completed' | 'step.started' | 'step.completed' | 'delegate.started' | 'delegate.completed'\n | 'run.completed' | 'events.gap' | 'output.delta' | 'output.withheld';\n readonly metadata: Readonly<Record<string, string | number | boolean>>;\n}\nexport interface RunHandle<T> {\n readonly id: string;\n readonly profile: 'ephemeral';\n result(): Promise<Outcome<T>>;\n observe(options?: { readonly after?: number; readonly signal?: AbortSignal }): AsyncIterable<RunEvent>;\n cancel(): void;\n}\nexport interface GuardContext extends ExecutionContext { readonly boundary: 'input' | 'output' }\n/**\n * A guard allows content, blocks it, or rewrites it (for example to redact personal data). A rewritten value replaces\n * the content for the guards after it and is validated again against the boundary's schema before anything uses it.\n */\nexport type GuardVerdict = { readonly decision: 'allow' } | { readonly decision: 'block'; readonly reason?: string }\n | { readonly decision: 'rewrite'; readonly value: JsonValue };\nexport interface Guard {\n readonly id: string;\n check(value: JsonValue, context: GuardContext): Promise<GuardVerdict> | GuardVerdict;\n}\nexport interface ModelTool {\n readonly id: string;\n readonly description: string;\n readonly inputJsonSchema?: JsonObject;\n}\n/**\n * One message of a model conversation. `media` holds images or PDFs the model should see: with the user's input, or\n * returned by a tool. It is present only when there is some, and only for adapters that declare `capabilities.media`.\n */\nexport type ModelMessage =\n | { readonly role: 'user'; readonly content: JsonValue; readonly media?: readonly Media[] }\n | { readonly role: 'assistant'; readonly calls: readonly ModelToolCall[] }\n | { readonly role: 'tool'; readonly callId: string; readonly toolId: string; readonly result: JsonValue; readonly media?: readonly Media[] };\nexport interface ModelToolCall { readonly id: string; readonly toolId: string; readonly input: JsonValue }\nexport interface ModelRequest {\n readonly instructions: string;\n readonly messages: readonly ModelMessage[];\n readonly tools: readonly ModelTool[];\n readonly signal: AbortSignal;\n readonly maxOutputTokens: number;\n /** Opaque bounded provider protocol state; private to this run and never a public output. */\n readonly continuation?: JsonValue;\n /**\n * The agent's output as JSON Schema: what the final answer must look like. The runtime sends it when the agent has\n * one (given, or generated from its output validator); an adapter configured with its own output schema uses that.\n */\n readonly outputJsonSchema?: JsonObject;\n}\n/**\n * What `defineAgent` asks an adapter to check once, before any run: the tools and output schema it would be sent, and\n * the media the agent accepts with its input or its tools may return.\n */\nexport interface ModelDefinitionCheck {\n readonly tools: readonly ModelTool[];\n readonly outputJsonSchema?: JsonObject;\n readonly media?: { readonly types: readonly MediaType[]; readonly urls: boolean };\n}\n/** The media a model can see: which types, and whether it can take a URL (which its provider then fetches). */\nexport interface ModelMediaCapability { readonly types: readonly MediaType[]; readonly urls: boolean }\nexport interface ModelUsage { readonly costMicros: number }\n/** A failed provider invocation may still have confirmed billable usage. No raw failure text is accepted. */\nexport class ModelInvocationError extends MayuraError {\n constructor(readonly costMicros: number) {\n super('MODEL_FAILED', 'The model invocation failed after reporting known usage.');\n if (!Number.isSafeInteger(costMicros) || costMicros < 0) throw new MayuraError('INVALID_CONFIG', 'Known model usage must be a nonnegative safe integer.');\n Object.freeze(this);\n }\n}\n/**\n * Why a model call failed, in words Mayura can show safely. An adapter picks the reason; the message is Mayura's own,\n * so no provider text or credential can reach an outcome through it.\n */\nexport type ModelFailureReason = 'authentication' | 'rate_limited' | 'unavailable' | 'timeout' | 'rejected' | 'invalid_response' | 'refused' | 'configuration';\nconst modelFailureReasons: readonly ModelFailureReason[] = ['authentication', 'rate_limited', 'unavailable', 'timeout', 'rejected', 'invalid_response', 'refused', 'configuration'];\nexport function isModelFailureReason(value: unknown): value is ModelFailureReason { return modelFailureReasons.includes(value as ModelFailureReason); }\n/** The fixed public message for a failure reason, with the provider's HTTP status when there is one. */\nexport function modelFailureMessage(reason: ModelFailureReason, httpStatus?: number): string {\n const status = httpStatus === undefined ? '' : ` (HTTP ${httpStatus})`;\n switch (reason) {\n case 'authentication': return `The model provider refused the credentials or access to this model${status}. Check the API key and that it may use this model.`;\n case 'rate_limited': return `The model provider's rate limit or quota was reached${status}. Try again later, or raise the limit with the provider.`;\n case 'unavailable': return `The model provider was unavailable${status}. Try again later.`;\n case 'timeout': return `The model provider did not answer in time. Try again, or raise the adapter's timeoutMs.`;\n case 'rejected': return `The model provider rejected the request${status}. Check the model name and the adapter's settings.`;\n case 'invalid_response': return 'The model provider returned a response Mayura could not use, for example an answer that is not the required JSON or no token usage.';\n case 'refused': return 'The model refused to answer, or stopped before finishing (for example at its token limit).';\n case 'configuration': return `The model adapter could not send this request: a tool's input schema or the output schema breaks the provider's rules, no output schema was given, or the request holds media this provider cannot take.`;\n }\n}\n/** A model call that failed for a known reason. `costMicros`, when given, is usage the provider confirmed before failing. */\nexport class ModelProviderError extends MayuraError {\n readonly reason: ModelFailureReason;\n /** Present only when the provider answered with an HTTP error status. */\n declare readonly httpStatus?: number;\n /** Present only when the provider confirmed usage before the failure. */\n declare readonly costMicros?: number;\n constructor(reason: ModelFailureReason, options: { readonly httpStatus?: number; readonly costMicros?: number } = {}) {\n if (!isModelFailureReason(reason)) throw new MayuraError('INVALID_CONFIG', 'Unknown model failure reason.');\n const { httpStatus, costMicros } = options;\n if (httpStatus !== undefined && (!Number.isSafeInteger(httpStatus) || httpStatus < 100 || httpStatus > 599)) throw new MayuraError('INVALID_CONFIG', 'An HTTP status must be between 100 and 599.');\n if (costMicros !== undefined && (!Number.isSafeInteger(costMicros) || costMicros < 0)) throw new MayuraError('INVALID_CONFIG', 'Known model usage must be a nonnegative safe integer.');\n super(reason === 'configuration' ? 'INVALID_CONFIG' : 'MODEL_FAILED', modelFailureMessage(reason, httpStatus));\n this.reason = reason;\n if (httpStatus !== undefined) Object.defineProperty(this, 'httpStatus', { value: httpStatus, enumerable: true });\n if (costMicros !== undefined) Object.defineProperty(this, 'costMicros', { value: costMicros, enumerable: true });\n Object.freeze(this);\n }\n}\nexport type ModelResponse =\n | { readonly type: 'final'; readonly output: JsonValue; readonly usage: ModelUsage; readonly continuation?: JsonValue }\n | { readonly type: 'tool_calls'; readonly calls: readonly ModelToolCall[]; readonly usage: ModelUsage; readonly continuation?: JsonValue };\n/** Model adapters are trusted code; declared bounds are enforced/accounted, not a provider billing guarantee. */\n/**\n * One event of a streamed model call: fragments of the final output's raw text as the provider produces them, then\n * exactly one complete response. The complete response is validated and accounted exactly as `generate` would return\n * it; fragments are provisional and never authoritative. Tool-call argument fragments and reasoning are never emitted.\n */\nexport type ModelStreamEvent =\n | { readonly type: 'output.delta'; readonly text: string }\n | { readonly type: 'response'; readonly response: ModelResponse };\nexport interface ModelAdapter {\n readonly id: string;\n /** What the model can do. Without `media`, it cannot see images or PDFs, and agents that accept media refuse it. */\n readonly capabilities: { readonly tools: boolean; readonly structuredOutput: boolean; readonly media?: ModelMediaCapability };\n readonly maxCostMicros: number;\n generate(request: ModelRequest): Promise<ModelResponse>;\n /** Optional streamed form of `generate`, used only for agents that opt into streaming. */\n stream?(request: ModelRequest): AsyncIterable<ModelStreamEvent>;\n /**\n * Optional: called by `defineAgent` with the agent's tools and output schema. Throw INVALID_CONFIG, with a message\n * that says what to fix, when this adapter could never send them (for example a schema its provider refuses), so the\n * mistake shows when the agent is defined instead of on its first call.\n */\n checkDefinition?(definition: ModelDefinitionCheck): void;\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check a provider endpoint given in place of the default: an https URL ending in `path` (such as `/responses`), with no
|
|
3
|
+
* credentials, query or fragment in it. Returns the normalized URL. `where` names the adapter in the error.
|
|
4
|
+
*/
|
|
5
|
+
export declare function providerEndpoint(value: unknown, path: string, where: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Check extra request headers, such as a gateway's credential (`cf-aig-authorization`): at most 8, each a bounded
|
|
8
|
+
* value without line breaks. They cannot replace the headers the adapter owns (`owned`, in any case), cookies or
|
|
9
|
+
* transport headers. Treated as credentials by the caller: never logged or reported.
|
|
10
|
+
*/
|
|
11
|
+
export declare function providerHeaders(value: unknown, owned: readonly string[], where: string): Readonly<Record<string, string>>;
|
|
12
|
+
//# sourceMappingURL=destination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../src/destination.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAOpF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CASzH"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MayuraError } from './errors.js';
|
|
2
|
+
// Where a provider adapter sends requests, when it is not the provider's own API: a gateway or proxy such as Cloudflare
|
|
3
|
+
// AI Gateway. Choosing one is an explicit data-egress decision in code; nothing here is read from the environment.
|
|
4
|
+
/**
|
|
5
|
+
* Check a provider endpoint given in place of the default: an https URL ending in `path` (such as `/responses`), with no
|
|
6
|
+
* credentials, query or fragment in it. Returns the normalized URL. `where` names the adapter in the error.
|
|
7
|
+
*/
|
|
8
|
+
export function providerEndpoint(value, path, where) {
|
|
9
|
+
let url;
|
|
10
|
+
try {
|
|
11
|
+
url = new URL(typeof value === 'string' ? value : '');
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
throw new MayuraError('INVALID_CONFIG', `${where}: endpoint must be an absolute https:// URL.`);
|
|
15
|
+
}
|
|
16
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash || !url.pathname.endsWith(path) || url.href.length > 2_048) {
|
|
17
|
+
throw new MayuraError('INVALID_CONFIG', `${where}: endpoint must be an https:// URL ending in ${path}, without credentials, query or fragment.`);
|
|
18
|
+
}
|
|
19
|
+
return url.href;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check extra request headers, such as a gateway's credential (`cf-aig-authorization`): at most 8, each a bounded
|
|
23
|
+
* value without line breaks. They cannot replace the headers the adapter owns (`owned`, in any case), cookies or
|
|
24
|
+
* transport headers. Treated as credentials by the caller: never logged or reported.
|
|
25
|
+
*/
|
|
26
|
+
export function providerHeaders(value, owned, where) {
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
return Object.freeze({});
|
|
29
|
+
const reserved = new Set([...owned.map(name => name.toLowerCase()), 'content-type', 'content-length', 'host', 'cookie', 'transfer-encoding', 'connection']);
|
|
30
|
+
const entries = value && typeof value === 'object' && !Array.isArray(value) ? Object.entries(value) : undefined;
|
|
31
|
+
if (!entries || entries.length > 8 || entries.some(([name, text]) => !/^[A-Za-z0-9-]{1,64}$/u.test(name) || reserved.has(name.toLowerCase())
|
|
32
|
+
|| typeof text !== 'string' || !text || /[\r\n]/u.test(text) || text.length > 8_192)) {
|
|
33
|
+
throw new MayuraError('INVALID_CONFIG', `${where}: headers must be at most 8 extra header values; they cannot replace ${owned.join(', ')}, Content-Type, Host or cookies.`);
|
|
34
|
+
}
|
|
35
|
+
return Object.freeze(Object.fromEntries(entries));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=destination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../src/destination.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,wHAAwH;AACxH,mHAAmH;AAEnH;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,IAAY,EAAE,KAAa;IAC1E,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QAAC,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,MAAM,IAAI,WAAW,CAAC,gBAAgB,EAAE,GAAG,KAAK,8CAA8C,CAAC,CAAC;IAAC,CAAC;IACzK,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QACnJ,MAAM,IAAI,WAAW,CAAC,gBAAgB,EAAE,GAAG,KAAK,gDAAgD,IAAI,2CAA2C,CAAC,CAAC;IACnJ,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,KAAwB,EAAE,KAAa;IACrF,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,YAAY,CAAC,CAAC,CAAC;IAC5J,MAAM,OAAO,GAAG,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAChH,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;WACvI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC;QACvF,MAAM,IAAI,WAAW,CAAC,gBAAgB,EAAE,GAAG,KAAK,wEAAwE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IAC9K,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAA6B,CAAC,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import { MayuraError } from './errors.js';\n\n// Where a provider adapter sends requests, when it is not the provider's own API: a gateway or proxy such as Cloudflare\n// AI Gateway. Choosing one is an explicit data-egress decision in code; nothing here is read from the environment.\n\n/**\n * Check a provider endpoint given in place of the default: an https URL ending in `path` (such as `/responses`), with no\n * credentials, query or fragment in it. Returns the normalized URL. `where` names the adapter in the error.\n */\nexport function providerEndpoint(value: unknown, path: string, where: string): string {\n let url: URL;\n try { url = new URL(typeof value === 'string' ? value : ''); } catch { throw new MayuraError('INVALID_CONFIG', `${where}: endpoint must be an absolute https:// URL.`); }\n if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash || !url.pathname.endsWith(path) || url.href.length > 2_048) {\n throw new MayuraError('INVALID_CONFIG', `${where}: endpoint must be an https:// URL ending in ${path}, without credentials, query or fragment.`);\n }\n return url.href;\n}\n\n/**\n * Check extra request headers, such as a gateway's credential (`cf-aig-authorization`): at most 8, each a bounded\n * value without line breaks. They cannot replace the headers the adapter owns (`owned`, in any case), cookies or\n * transport headers. Treated as credentials by the caller: never logged or reported.\n */\nexport function providerHeaders(value: unknown, owned: readonly string[], where: string): Readonly<Record<string, string>> {\n if (value === undefined) return Object.freeze({});\n const reserved = new Set([...owned.map(name => name.toLowerCase()), 'content-type', 'content-length', 'host', 'cookie', 'transfer-encoding', 'connection']);\n const entries = value && typeof value === 'object' && !Array.isArray(value) ? Object.entries(value) : undefined;\n if (!entries || entries.length > 8 || entries.some(([name, text]) => !/^[A-Za-z0-9-]{1,64}$/u.test(name) || reserved.has(name.toLowerCase())\n || typeof text !== 'string' || !text || /[\\r\\n]/u.test(text) || text.length > 8_192)) {\n throw new MayuraError('INVALID_CONFIG', `${where}: headers must be at most 8 extra header values; they cannot replace ${owned.join(', ')}, Content-Type, Host or cookies.`);\n }\n return Object.freeze(Object.fromEntries(entries as [string, string][]));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-stream.d.ts","sourceRoot":"","sources":["../src/event-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"event-stream.d.ts","sourceRoot":"","sources":["../src/event-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG/F,MAAM,WAAW,eAAe;IAC9B,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,WAAW,qBAAqB;IACpC,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,qCAAqC;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B;AAID;;;;GAIG;AACH,wBAAuB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,qBAAqB,GAAG,aAAa,CAAC,eAAe,CAAC,CA4C7H;AAED;;;GAGG;AACH,wBAAuB,eAAe,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAe9J"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { MayuraError } from './errors.js';
|
|
2
|
+
import { ModelProviderError } from './contracts.js';
|
|
3
|
+
import { providerHttpFailure } from './model-schema.js';
|
|
2
4
|
const failure = () => new MayuraError('MODEL_FAILED', 'The model provider returned an unavailable, refused or invalid response.');
|
|
3
5
|
/**
|
|
4
6
|
* Bounded Server-Sent Events decoding for trusted provider adapters. It checks the content type, decodes strict UTF-8
|
|
@@ -11,6 +13,11 @@ export async function* readServerSentEvents(response, limits) {
|
|
|
11
13
|
}
|
|
12
14
|
if (!response.ok || response.redirected || !response.body || !/^text\/event-stream(?:\s*;|$)/iu.test(response.headers.get('content-type') ?? '')) {
|
|
13
15
|
void response.body?.cancel().catch(() => undefined);
|
|
16
|
+
// A refused stream fails for the provider's reason (credentials, rate limit, ...), as a refused call does.
|
|
17
|
+
if (response.redirected)
|
|
18
|
+
throw new ModelProviderError('rejected');
|
|
19
|
+
if (!response.ok)
|
|
20
|
+
throw providerHttpFailure(response.status);
|
|
14
21
|
throw failure();
|
|
15
22
|
}
|
|
16
23
|
const reader = response.body.getReader();
|