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
|
@@ -9,31 +9,45 @@ const digest = /^[a-f0-9]{64}$/;
|
|
|
9
9
|
const MAX_SOURCE_BYTES = 1_048_576;
|
|
10
10
|
const MAX_TOOLS = 128;
|
|
11
11
|
const MAX_IMPORTS = 64;
|
|
12
|
-
|
|
12
|
+
/** Recently finished execution ids stay reserved, so a retry with a stale id fails instead of reusing call ids. */
|
|
13
|
+
const RECENT_EXECUTION_IDS = 100_000;
|
|
14
|
+
const PROGRAM_ERROR_NAME = 128;
|
|
15
|
+
const PROGRAM_ERROR_MESSAGE = 1_024;
|
|
16
|
+
/** Fixed per-code text for tool outcomes shown to the program; broker messages never reach the sandbox. */
|
|
13
17
|
const messages = Object.freeze({
|
|
14
|
-
INVALID_CONFIG: '
|
|
15
|
-
INVALID_INPUT: '
|
|
16
|
-
INVALID_OUTPUT: '
|
|
17
|
-
INVALID_JSON: '
|
|
18
|
-
PERMISSION_DENIED: 'The
|
|
19
|
-
BUDGET_EXCEEDED: 'The
|
|
20
|
-
LIMIT_EXCEEDED: '
|
|
21
|
-
CANCELLED: '
|
|
22
|
-
TIMEOUT: '
|
|
23
|
-
TOOL_FAILED: '
|
|
24
|
-
MODEL_FAILED: 'A model
|
|
25
|
-
GUARD_BLOCKED: 'A
|
|
26
|
-
GUARD_UNAVAILABLE: 'A required guard could not
|
|
27
|
-
OUTCOME_UNKNOWN: '
|
|
28
|
-
UNSUPPORTED_PROFILE: '
|
|
29
|
-
NOT_FOUND: 'The
|
|
30
|
-
CONFLICT: 'The
|
|
31
|
-
STORAGE_UNAVAILABLE: '
|
|
32
|
-
INTEGRITY_VIOLATION: '
|
|
18
|
+
INVALID_CONFIG: 'The tool call was not configured correctly.',
|
|
19
|
+
INVALID_INPUT: 'The tool input was rejected: it is not plain JSON within maxToolInputBytes, or it does not match the tool schema.',
|
|
20
|
+
INVALID_OUTPUT: 'The tool output was rejected.',
|
|
21
|
+
INVALID_JSON: 'The tool data must be bounded plain JSON.',
|
|
22
|
+
PERMISSION_DENIED: 'The tool call was not permitted.',
|
|
23
|
+
BUDGET_EXCEEDED: 'The tool call did not fit the remaining budget.',
|
|
24
|
+
LIMIT_EXCEEDED: 'The tool call exceeded a limit, such as the program\'s maxToolCalls or maxToolConcurrency.',
|
|
25
|
+
CANCELLED: 'The tool call was cancelled.',
|
|
26
|
+
TIMEOUT: 'The tool call ran out of time.',
|
|
27
|
+
TOOL_FAILED: 'The tool call failed.',
|
|
28
|
+
MODEL_FAILED: 'A model call failed.',
|
|
29
|
+
GUARD_BLOCKED: 'A guard blocked the tool call.',
|
|
30
|
+
GUARD_UNAVAILABLE: 'A required guard could not decide on the tool call.',
|
|
31
|
+
OUTCOME_UNKNOWN: 'The tool call may or may not have taken effect.',
|
|
32
|
+
UNSUPPORTED_PROFILE: 'The tool call is not supported here.',
|
|
33
|
+
NOT_FOUND: 'The tool call referred to something that does not exist.',
|
|
34
|
+
CONFLICT: 'The execution has finished; it accepts no more tool calls.',
|
|
35
|
+
STORAGE_UNAVAILABLE: 'Storage needed by the tool call is unavailable.',
|
|
36
|
+
INTEGRITY_VIOLATION: 'The tool call failed an integrity check.',
|
|
37
|
+
});
|
|
38
|
+
const failureReasons = new Set(['program_error', 'cpu_limit', 'memory_limit',
|
|
39
|
+
'invalid_output', 'unsupported_program', 'sandbox_error']);
|
|
40
|
+
const reasonFailures = Object.freeze({
|
|
41
|
+
program_error: ['TOOL_FAILED', 'The program threw an error, did not compile, or returned a promise that can never settle. programError holds what it threw, when the sandbox could report it.'],
|
|
42
|
+
cpu_limit: ['LIMIT_EXCEEDED', 'The program ran longer than its cpuMillis limit.'],
|
|
43
|
+
memory_limit: ['LIMIT_EXCEEDED', 'The program needed more memory than its memoryBytes limit.'],
|
|
44
|
+
invalid_output: ['INVALID_OUTPUT', 'The program\'s result is not plain JSON within maxOutputBytes.'],
|
|
45
|
+
unsupported_program: ['UNSUPPORTED_PROFILE', 'This sandbox cannot run the program\'s language or approved imports.'],
|
|
46
|
+
sandbox_error: ['TOOL_FAILED', 'The sandbox failed before the program finished; its details are withheld.'],
|
|
33
47
|
});
|
|
34
48
|
function text(value, name, maxLength) {
|
|
35
49
|
if (typeof value !== 'string' || value.trim().length === 0 || value.length > maxLength) {
|
|
36
|
-
throw new MayuraError('INVALID_CONFIG', `${name} must be a
|
|
50
|
+
throw new MayuraError('INVALID_CONFIG', `${name} must be a nonempty string of at most ${maxLength} characters.`);
|
|
37
51
|
}
|
|
38
52
|
}
|
|
39
53
|
function plainRecord(value) {
|
|
@@ -43,15 +57,19 @@ function plainRecord(value) {
|
|
|
43
57
|
}
|
|
44
58
|
function exactData(value, required, optional = []) {
|
|
45
59
|
if (!plainRecord(value))
|
|
46
|
-
throw new MayuraError('INVALID_CONFIG', 'Code Mode
|
|
60
|
+
throw new MayuraError('INVALID_CONFIG', 'Code Mode options must be a plain object.');
|
|
47
61
|
const fields = Object.getOwnPropertyDescriptors(value);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
throw new MayuraError('INVALID_CONFIG', 'Code Mode
|
|
62
|
+
const unknown = Reflect.ownKeys(fields).find(key => typeof key !== 'string' || ![...required, ...optional].includes(key));
|
|
63
|
+
if (unknown !== undefined) {
|
|
64
|
+
throw new MayuraError('INVALID_CONFIG', typeof unknown === 'string' && unknown.length <= 64 ? `Unknown Code Mode option "${unknown}".` : 'Code Mode options contain an unknown key.');
|
|
65
|
+
}
|
|
66
|
+
const missing = required.find(key => !fields[key]);
|
|
67
|
+
if (missing !== undefined)
|
|
68
|
+
throw new MayuraError('INVALID_CONFIG', `The Code Mode option "${missing}" is required.`);
|
|
51
69
|
const snapshot = Object.create(null);
|
|
52
70
|
for (const [key, descriptor] of Object.entries(fields)) {
|
|
53
71
|
if (!descriptor.enumerable || !('value' in descriptor))
|
|
54
|
-
throw new MayuraError('INVALID_CONFIG',
|
|
72
|
+
throw new MayuraError('INVALID_CONFIG', `The Code Mode option "${key}" must be a plain data property.`);
|
|
55
73
|
if (descriptor.value !== undefined || required.includes(key))
|
|
56
74
|
snapshot[key] = descriptor.value;
|
|
57
75
|
}
|
|
@@ -69,10 +87,8 @@ function limits(value) {
|
|
|
69
87
|
'maxOutputBytes', 'maxToolInputBytes', 'maxToolCalls', 'maxToolConcurrency']);
|
|
70
88
|
for (const [name, item] of Object.entries(data))
|
|
71
89
|
assertPositiveInteger(item, `limits.${name}`);
|
|
72
|
-
if (data['wallTimeMillis'] > 2_147_483_647)
|
|
73
|
-
throw new MayuraError('INVALID_CONFIG', 'wallTimeMillis exceeds the host timer range.');
|
|
74
90
|
if (data['maxToolConcurrency'] > data['maxToolCalls']) {
|
|
75
|
-
throw new MayuraError('INVALID_CONFIG', 'maxToolConcurrency cannot
|
|
91
|
+
throw new MayuraError('INVALID_CONFIG', 'limits.maxToolConcurrency cannot be greater than limits.maxToolCalls.');
|
|
76
92
|
}
|
|
77
93
|
const ceilings = Object.freeze({
|
|
78
94
|
cpuMillis: 3_600_000,
|
|
@@ -87,7 +103,7 @@ function limits(value) {
|
|
|
87
103
|
});
|
|
88
104
|
for (const [name, ceiling] of Object.entries(ceilings)) {
|
|
89
105
|
if (data[name] > ceiling)
|
|
90
|
-
throw new MayuraError('INVALID_CONFIG', `limits.${name} exceeds the supported maximum.`);
|
|
106
|
+
throw new MayuraError('INVALID_CONFIG', `limits.${name} exceeds the supported maximum of ${ceiling}.`);
|
|
91
107
|
}
|
|
92
108
|
return Object.freeze({
|
|
93
109
|
cpuMillis: data['cpuMillis'],
|
|
@@ -128,48 +144,48 @@ export function defineCodeProgram(options) {
|
|
|
128
144
|
const data = exactData(options, ['id', 'version', 'intent', 'language', 'source', 'input', 'output', 'inputSchemaId',
|
|
129
145
|
'outputSchemaId', 'limits'], ['tools', 'approvedImports']);
|
|
130
146
|
if (!identifier.test(String(data['id'])))
|
|
131
|
-
throw new MayuraError('INVALID_CONFIG', 'Program id must
|
|
147
|
+
throw new MayuraError('INVALID_CONFIG', 'Program id must start with a letter and contain at most 128 letters, digits, ".", "_", "/" or "-".');
|
|
132
148
|
text(data['version'], 'version', 128);
|
|
133
149
|
text(data['intent'], 'intent', 4_096);
|
|
134
150
|
text(data['inputSchemaId'], 'inputSchemaId', 256);
|
|
135
151
|
text(data['outputSchemaId'], 'outputSchemaId', 256);
|
|
136
152
|
if (data['language'] !== 'javascript' && data['language'] !== 'typescript')
|
|
137
|
-
throw new MayuraError('INVALID_CONFIG', 'Program language
|
|
153
|
+
throw new MayuraError('INVALID_CONFIG', 'Program language must be "javascript" or "typescript".');
|
|
138
154
|
if (typeof data['source'] !== 'string' || data['source'].trim().length === 0)
|
|
139
|
-
throw new MayuraError('INVALID_CONFIG', 'Program source must be nonempty
|
|
155
|
+
throw new MayuraError('INVALID_CONFIG', 'Program source must be a nonempty string.');
|
|
140
156
|
const sourceBytes = Buffer.byteLength(data['source'], 'utf8');
|
|
141
157
|
if (sourceBytes > MAX_SOURCE_BYTES)
|
|
142
|
-
throw new MayuraError('LIMIT_EXCEEDED', 'Program source
|
|
158
|
+
throw new MayuraError('LIMIT_EXCEEDED', 'Program source is larger than 1 MiB.');
|
|
143
159
|
const input = snapshotSchema(data['input']);
|
|
144
160
|
const output = snapshotSchema(data['output']);
|
|
145
161
|
const codeLimits = limits(data['limits']);
|
|
146
162
|
const suppliedTools = data['tools'] ?? [];
|
|
147
163
|
if (!Array.isArray(suppliedTools) || suppliedTools.length > MAX_TOOLS)
|
|
148
|
-
throw new MayuraError('INVALID_CONFIG', 'Program tools must be
|
|
164
|
+
throw new MayuraError('INVALID_CONFIG', 'Program tools must be an array of at most 128 tools.');
|
|
149
165
|
const toolMap = new Map();
|
|
150
166
|
const toolManifest = suppliedTools.map(item => {
|
|
151
167
|
assertTool(item);
|
|
152
168
|
const tool = item;
|
|
153
169
|
if (toolMap.has(tool.id))
|
|
154
|
-
throw new MayuraError('CONFLICT',
|
|
170
|
+
throw new MayuraError('CONFLICT', `Program tools contain "${tool.id}" twice; tool ids must be unique.`);
|
|
155
171
|
toolMap.set(tool.id, tool);
|
|
156
172
|
return freezeTool(tool);
|
|
157
173
|
});
|
|
158
174
|
const maximumToolCost = toolManifest.reduce((maximum, tool) => Math.max(maximum, tool.costMicros), 0);
|
|
159
175
|
if (!Number.isSafeInteger(maximumToolCost * codeLimits.maxToolCalls)) {
|
|
160
|
-
throw new MayuraError('LIMIT_EXCEEDED', '
|
|
176
|
+
throw new MayuraError('LIMIT_EXCEEDED', 'The program\'s maximum tool cost (the highest tool costMicros times limits.maxToolCalls) is larger than Number.MAX_SAFE_INTEGER.');
|
|
161
177
|
}
|
|
162
178
|
const suppliedImports = data['approvedImports'] ?? [];
|
|
163
179
|
if (!Array.isArray(suppliedImports) || suppliedImports.length > MAX_IMPORTS)
|
|
164
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
180
|
+
throw new MayuraError('INVALID_CONFIG', 'approvedImports must be an array of at most 64 specifiers.');
|
|
165
181
|
const approvedImports = suppliedImports.map(item => {
|
|
166
182
|
text(item, 'approved import', 256);
|
|
167
183
|
if (item.includes(':') || item.includes('\\') || item.startsWith('/'))
|
|
168
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
184
|
+
throw new MayuraError('INVALID_CONFIG', 'approvedImports entries must be bare package specifiers, without ":", "\\" or a leading "/".');
|
|
169
185
|
return item;
|
|
170
186
|
});
|
|
171
187
|
if (new Set(approvedImports).size !== approvedImports.length)
|
|
172
|
-
throw new MayuraError('CONFLICT', '
|
|
188
|
+
throw new MayuraError('CONFLICT', 'approvedImports entries must be unique.');
|
|
173
189
|
const unsigned = freezeJson(jsonValue({
|
|
174
190
|
format: 1,
|
|
175
191
|
id: data['id'],
|
|
@@ -192,18 +208,18 @@ export function defineCodeProgram(options) {
|
|
|
192
208
|
/** Rejects forged or foreign-instance program metadata before durable composition. */
|
|
193
209
|
export function assertCodeProgram(program) {
|
|
194
210
|
if (!programs.has(program))
|
|
195
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
211
|
+
throw new MayuraError('INVALID_CONFIG', 'The program was not created by defineCodeProgram from this package instance.');
|
|
196
212
|
}
|
|
197
213
|
/** Registers trusted adapter callbacks behind an immutable metadata-only handle. */
|
|
198
214
|
export function defineSandboxAdapter(options) {
|
|
199
215
|
const data = exactData(options, ['id', 'version', 'qualification', 'isAvailable', 'execute']);
|
|
200
216
|
if (!identifier.test(String(data['id'])))
|
|
201
|
-
throw new MayuraError('INVALID_CONFIG', 'Sandbox adapter id must
|
|
217
|
+
throw new MayuraError('INVALID_CONFIG', 'Sandbox adapter id must start with a letter and contain at most 128 letters, digits, ".", "_", "/" or "-".');
|
|
202
218
|
text(data['version'], 'version', 128);
|
|
203
219
|
if (data['qualification'] !== 'test' && data['qualification'] !== 'production')
|
|
204
|
-
throw new MayuraError('INVALID_CONFIG', 'Sandbox qualification
|
|
220
|
+
throw new MayuraError('INVALID_CONFIG', 'Sandbox adapter qualification must be "production" or "test".');
|
|
205
221
|
if (typeof data['isAvailable'] !== 'function' || typeof data['execute'] !== 'function')
|
|
206
|
-
throw new MayuraError('INVALID_CONFIG', 'Sandbox adapter
|
|
222
|
+
throw new MayuraError('INVALID_CONFIG', 'Sandbox adapter isAvailable and execute must be functions.');
|
|
207
223
|
const adapter = Object.freeze({ id: data['id'], version: data['version'], qualification: data['qualification'] });
|
|
208
224
|
adapters.set(adapter, Object.freeze({
|
|
209
225
|
isAvailable: data['isAvailable'],
|
|
@@ -211,20 +227,26 @@ export function defineSandboxAdapter(options) {
|
|
|
211
227
|
}));
|
|
212
228
|
return adapter;
|
|
213
229
|
}
|
|
214
|
-
function
|
|
215
|
-
|
|
230
|
+
function statusOf(code) {
|
|
231
|
+
return code === 'CANCELLED' ? 'cancelled' : code === 'OUTCOME_UNKNOWN' ? 'outcome_unknown'
|
|
216
232
|
: ['PERMISSION_DENIED', 'BUDGET_EXCEEDED', 'GUARD_BLOCKED', 'GUARD_UNAVAILABLE'].includes(code) ? 'blocked' : 'failed';
|
|
217
|
-
|
|
233
|
+
}
|
|
234
|
+
/** Host-authored outcome errors: each message names the limit or rule involved and never carries program or tool data. */
|
|
235
|
+
function failure(code, message) {
|
|
236
|
+
return Object.freeze({ status: statusOf(code), error: Object.freeze({ code, message }) });
|
|
218
237
|
}
|
|
219
238
|
const zeroUsage = Object.freeze({ toolCalls: 0, unknownCalls: 0, knownCostMicros: 0, unknownCostMicros: 0, maximumCostMicros: 0 });
|
|
220
|
-
function codeOutcome(outcome, usage = zeroUsage) {
|
|
221
|
-
return Object.freeze({ ...outcome, usage: Object.freeze({ ...usage }) });
|
|
239
|
+
function codeOutcome(outcome, usage = zeroUsage, programError) {
|
|
240
|
+
return Object.freeze({ ...outcome, usage: Object.freeze({ ...usage }), ...(programError ? { programError } : {}) });
|
|
222
241
|
}
|
|
223
242
|
function bridgeFailure(code) {
|
|
224
|
-
return Object.freeze({ status: code
|
|
225
|
-
: ['PERMISSION_DENIED', 'BUDGET_EXCEEDED', 'GUARD_BLOCKED', 'GUARD_UNAVAILABLE'].includes(code) ? 'blocked' : 'failed',
|
|
226
|
-
error: Object.freeze({ code, message: messages[code] }) });
|
|
243
|
+
return Object.freeze({ status: statusOf(code), error: Object.freeze({ code, message: messages[code] }) });
|
|
227
244
|
}
|
|
245
|
+
const abortMessages = Object.freeze({
|
|
246
|
+
CANCELLED: 'The execution was cancelled by its signal.',
|
|
247
|
+
TIMEOUT: 'The execution ran longer than the program\'s wallTimeMillis limit.',
|
|
248
|
+
});
|
|
249
|
+
const UNKNOWN_MESSAGE = 'A tool call may or may not have taken effect, so the program\'s result was discarded. Reconcile the effect (see evidence) before retrying.';
|
|
228
250
|
function errorCode(value) {
|
|
229
251
|
return typeof value === 'string' && Object.hasOwn(messages, value) ? value : 'TOOL_FAILED';
|
|
230
252
|
}
|
|
@@ -268,33 +290,58 @@ function snapshotExecutionOptions(value) {
|
|
|
268
290
|
text(data['runId'], 'runId', 256);
|
|
269
291
|
text(data['executionId'], 'executionId', 256);
|
|
270
292
|
if (!(data['signal'] instanceof AbortSignal))
|
|
271
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
293
|
+
throw new MayuraError('INVALID_CONFIG', 'execute options need signal to be an AbortSignal.');
|
|
272
294
|
const scope = freezeJson(jsonValue(data['scope'], { maxBytes: 2_048 }));
|
|
273
295
|
if (!plainRecord(scope) || Object.keys(scope).length !== 2 || !Object.hasOwn(scope, 'principalId') || !Object.hasOwn(scope, 'projectId')) {
|
|
274
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
296
|
+
throw new MayuraError('INVALID_CONFIG', 'execute options need scope to be exactly { principalId, projectId }.');
|
|
275
297
|
}
|
|
276
298
|
text(scope['principalId'], 'scope.principalId', 256);
|
|
277
299
|
text(scope['projectId'], 'scope.projectId', 256);
|
|
278
300
|
return Object.freeze({ runId: data['runId'], executionId: data['executionId'], scope: scope, signal: data['signal'] });
|
|
279
301
|
}
|
|
302
|
+
const sandboxError = Object.freeze({ status: 'failed', reason: 'sandbox_error' });
|
|
303
|
+
function snapshotProgramError(value) {
|
|
304
|
+
if (!plainRecord(value))
|
|
305
|
+
return undefined;
|
|
306
|
+
const fields = Object.getOwnPropertyDescriptors(value);
|
|
307
|
+
const name = fields['name'];
|
|
308
|
+
const message = fields['message'];
|
|
309
|
+
if (Reflect.ownKeys(fields).length !== 2 || !name || !message || !('value' in name) || !('value' in message)
|
|
310
|
+
|| typeof name.value !== 'string' || typeof message.value !== 'string')
|
|
311
|
+
return undefined;
|
|
312
|
+
return Object.freeze({ name: name.value.slice(0, PROGRAM_ERROR_NAME), message: message.value.slice(0, PROGRAM_ERROR_MESSAGE) });
|
|
313
|
+
}
|
|
314
|
+
/** Admits only exact plain result data; accessors, extra fields and unknown reasons are sandbox failures. */
|
|
280
315
|
function snapshotSandboxResult(value, maxOutputBytes) {
|
|
281
316
|
try {
|
|
282
317
|
if (!plainRecord(value))
|
|
283
|
-
return
|
|
318
|
+
return sandboxError;
|
|
284
319
|
const fields = Object.getOwnPropertyDescriptors(value);
|
|
285
|
-
if (
|
|
286
|
-
return
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
320
|
+
if (Object.values(fields).some(field => !field.enumerable || !('value' in field)))
|
|
321
|
+
return sandboxError;
|
|
322
|
+
const keys = Reflect.ownKeys(fields);
|
|
323
|
+
if (fields['status']?.value === 'failed') {
|
|
324
|
+
if (keys.some(key => !['status', 'reason', 'programError'].includes(key)))
|
|
325
|
+
return sandboxError;
|
|
326
|
+
const reason = fields['reason']?.value;
|
|
327
|
+
if (reason === undefined)
|
|
328
|
+
return Object.freeze({ status: 'failed' });
|
|
329
|
+
if (typeof reason !== 'string' || !failureReasons.has(reason))
|
|
330
|
+
return sandboxError;
|
|
331
|
+
const programError = reason === 'program_error' ? snapshotProgramError(fields['programError']?.value) : undefined;
|
|
332
|
+
return Object.freeze({ status: 'failed', reason: reason, ...(programError ? { programError } : {}) });
|
|
333
|
+
}
|
|
334
|
+
if (fields['status']?.value !== 'succeeded' || keys.length !== 2 || !fields['output'])
|
|
335
|
+
return sandboxError;
|
|
336
|
+
try {
|
|
337
|
+
return Object.freeze({ status: 'succeeded', output: freezeJson(jsonValue(fields['output'].value, { maxBytes: maxOutputBytes })) });
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
return Object.freeze({ status: 'failed', reason: 'invalid_output' });
|
|
341
|
+
}
|
|
295
342
|
}
|
|
296
343
|
catch {
|
|
297
|
-
return
|
|
344
|
+
return sandboxError;
|
|
298
345
|
}
|
|
299
346
|
}
|
|
300
347
|
/** Creates an ephemeral Code Mode executor. It never evaluates source outside the supplied adapter. */
|
|
@@ -303,193 +350,214 @@ export function createCodeMode(options) {
|
|
|
303
350
|
const adapter = data['adapter'];
|
|
304
351
|
const registration = adapters.get(adapter);
|
|
305
352
|
if (!registration)
|
|
306
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
353
|
+
throw new MayuraError('INVALID_CONFIG', 'The sandbox adapter was not created by defineSandboxAdapter from this package instance.');
|
|
307
354
|
if (typeof data['invokeTool'] !== 'function')
|
|
308
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
355
|
+
throw new MayuraError('INVALID_CONFIG', 'invokeTool must be a function that brokers each tool call.');
|
|
309
356
|
if (data['allowTestAdapter'] !== undefined && typeof data['allowTestAdapter'] !== 'boolean')
|
|
310
|
-
throw new MayuraError('INVALID_CONFIG', 'allowTestAdapter must be boolean.');
|
|
311
|
-
if (adapter.qualification !== 'production' && data['allowTestAdapter'] !== true)
|
|
312
|
-
throw new MayuraError('UNSUPPORTED_PROFILE',
|
|
357
|
+
throw new MayuraError('INVALID_CONFIG', 'allowTestAdapter must be a boolean.');
|
|
358
|
+
if (adapter.qualification !== 'production' && data['allowTestAdapter'] !== true) {
|
|
359
|
+
throw new MayuraError('UNSUPPORTED_PROFILE', `Sandbox adapter "${adapter.id}" is qualified for tests only. Use a production adapter, or pass allowTestAdapter: true to accept its isolation.`);
|
|
360
|
+
}
|
|
313
361
|
const invoke = data['invokeTool'];
|
|
314
|
-
const
|
|
362
|
+
const active = new Set();
|
|
363
|
+
const recent = new Set();
|
|
364
|
+
const release = (id) => {
|
|
365
|
+
active.delete(id);
|
|
366
|
+
recent.add(id);
|
|
367
|
+
// Set iteration is insertion order, so this evicts the oldest finished id.
|
|
368
|
+
if (recent.size > RECENT_EXECUTION_IDS)
|
|
369
|
+
recent.delete(recent.values().next().value);
|
|
370
|
+
};
|
|
315
371
|
const mode = Object.freeze({
|
|
316
372
|
async execute(program, rawInput, rawOptions) {
|
|
317
373
|
const registered = programs.get(program);
|
|
318
374
|
if (!registered)
|
|
319
|
-
return codeOutcome(failure('INVALID_CONFIG'));
|
|
375
|
+
return codeOutcome(failure('INVALID_CONFIG', 'The program was not created by defineCodeProgram from this package instance.'));
|
|
320
376
|
const maximumToolCost = program.manifest.tools.reduce((maximum, tool) => Math.max(maximum, tool.costMicros), 0);
|
|
321
377
|
const maximumCostMicros = maximumToolCost * program.manifest.limits.maxToolCalls;
|
|
378
|
+
const early = (code, message) => codeOutcome(failure(code, message), { ...zeroUsage, maximumCostMicros });
|
|
322
379
|
let execution;
|
|
323
380
|
try {
|
|
324
381
|
execution = snapshotExecutionOptions(rawOptions);
|
|
325
382
|
}
|
|
326
|
-
catch {
|
|
327
|
-
return
|
|
383
|
+
catch (error) {
|
|
384
|
+
return early('INVALID_CONFIG', error instanceof MayuraError ? error.message : 'The execute options are invalid.');
|
|
385
|
+
}
|
|
386
|
+
if (active.has(execution.executionId) || recent.has(execution.executionId)) {
|
|
387
|
+
return early('CONFLICT', 'This executionId is running or was used recently by this executor. Pass a new executionId for each execution.');
|
|
328
388
|
}
|
|
329
|
-
|
|
330
|
-
return codeOutcome(failure('LIMIT_EXCEEDED'), { ...zeroUsage, maximumCostMicros });
|
|
331
|
-
if (executions.has(execution.executionId))
|
|
332
|
-
return codeOutcome(failure('CONFLICT'), { ...zeroUsage, maximumCostMicros });
|
|
333
|
-
executions.add(execution.executionId);
|
|
334
|
-
let inputSnapshot;
|
|
389
|
+
active.add(execution.executionId);
|
|
335
390
|
try {
|
|
336
|
-
|
|
391
|
+
return await run(program, registered, rawInput, execution, maximumCostMicros);
|
|
337
392
|
}
|
|
338
|
-
|
|
339
|
-
|
|
393
|
+
finally {
|
|
394
|
+
release(execution.executionId);
|
|
340
395
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
async function run(program, registered, rawInput, execution, maximumCostMicros) {
|
|
399
|
+
const limits = program.manifest.limits;
|
|
400
|
+
const early = (code, message) => codeOutcome(failure(code, message), { ...zeroUsage, maximumCostMicros });
|
|
401
|
+
let inputSnapshot;
|
|
402
|
+
try {
|
|
403
|
+
inputSnapshot = freezeJson(jsonValue(rawInput, { maxBytes: limits.maxInputBytes }));
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
return early('INVALID_INPUT', 'The input is not plain JSON within the program\'s maxInputBytes limit.');
|
|
407
|
+
}
|
|
408
|
+
let available = false;
|
|
409
|
+
try {
|
|
410
|
+
available = await registration.isAvailable() === true;
|
|
411
|
+
}
|
|
412
|
+
catch { /* Availability errors reveal no adapter details. */ }
|
|
413
|
+
if (!available) {
|
|
414
|
+
return early('UNSUPPORTED_PROFILE', `Sandbox adapter "${adapter.id}" is not available on this host, for example because its runtime or image is missing. Code Mode never runs a program outside its sandbox.`);
|
|
415
|
+
}
|
|
416
|
+
const controller = new AbortController();
|
|
417
|
+
let abortCode = 'CANCELLED';
|
|
418
|
+
const relay = () => { if (!controller.signal.aborted) {
|
|
419
|
+
abortCode = 'CANCELLED';
|
|
420
|
+
controller.abort();
|
|
421
|
+
} };
|
|
422
|
+
execution.signal.addEventListener('abort', relay, { once: true });
|
|
423
|
+
if (execution.signal.aborted)
|
|
424
|
+
relay();
|
|
425
|
+
const timer = setTimeout(() => { if (!controller.signal.aborted) {
|
|
426
|
+
abortCode = 'TIMEOUT';
|
|
427
|
+
controller.abort();
|
|
428
|
+
} }, limits.wallTimeMillis);
|
|
429
|
+
const evidence = [];
|
|
430
|
+
const pending = new Set();
|
|
431
|
+
let startedCalls = 0;
|
|
432
|
+
let activeCalls = 0;
|
|
433
|
+
let accountedCalls = 0;
|
|
434
|
+
let unknownCalls = 0;
|
|
435
|
+
let knownCostMicros = 0;
|
|
436
|
+
let unknownCostMicros = 0;
|
|
437
|
+
const usage = () => Object.freeze({ toolCalls: accountedCalls, unknownCalls, knownCostMicros, unknownCostMicros, maximumCostMicros });
|
|
438
|
+
const withEvidence = (outcome) => Object.freeze({ ...outcome, ...(evidence.length ? { evidence: Object.freeze([...evidence]) } : {}) });
|
|
439
|
+
const account = (tool, receipt) => {
|
|
440
|
+
accountedCalls++;
|
|
441
|
+
if (!receipt || receipt.execution === 'unknown') {
|
|
442
|
+
unknownCalls++;
|
|
443
|
+
unknownCostMicros += tool.costMicros;
|
|
344
444
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
else if (receipt.execution !== 'not_started')
|
|
377
|
-
knownCostMicros += tool.costMicros;
|
|
378
|
-
if (!Number.isSafeInteger(knownCostMicros) || !Number.isSafeInteger(unknownCostMicros)
|
|
379
|
-
|| knownCostMicros + unknownCostMicros > maximumCostMicros) {
|
|
380
|
-
throw new MayuraError('LIMIT_EXCEEDED', 'Nested-tool usage exceeded the admitted accounting bound.');
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
let bridgeOpen = true;
|
|
384
|
-
let bridgeCloseCode = 'CONFLICT';
|
|
385
|
-
const bridge = Object.freeze({
|
|
386
|
-
call(toolId, untrustedInput) {
|
|
387
|
-
const operation = (async () => {
|
|
388
|
-
if (!bridgeOpen)
|
|
389
|
-
return bridgeFailure(bridgeCloseCode);
|
|
445
|
+
else if (receipt.execution !== 'not_started')
|
|
446
|
+
knownCostMicros += tool.costMicros;
|
|
447
|
+
if (!Number.isSafeInteger(knownCostMicros) || !Number.isSafeInteger(unknownCostMicros)
|
|
448
|
+
|| knownCostMicros + unknownCostMicros > maximumCostMicros) {
|
|
449
|
+
throw new MayuraError('LIMIT_EXCEEDED', 'Nested-tool usage exceeded the admitted accounting bound.');
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
let bridgeOpen = true;
|
|
453
|
+
let bridgeCloseCode = 'CONFLICT';
|
|
454
|
+
const bridge = Object.freeze({
|
|
455
|
+
call(toolId, untrustedInput) {
|
|
456
|
+
const operation = (async () => {
|
|
457
|
+
if (!bridgeOpen)
|
|
458
|
+
return bridgeFailure(bridgeCloseCode);
|
|
459
|
+
if (controller.signal.aborted)
|
|
460
|
+
return bridgeFailure(abortCode);
|
|
461
|
+
if (typeof toolId !== 'string' || !registered.tools.has(toolId))
|
|
462
|
+
return bridgeFailure('PERMISSION_DENIED');
|
|
463
|
+
if (startedCalls >= limits.maxToolCalls || activeCalls >= limits.maxToolConcurrency)
|
|
464
|
+
return bridgeFailure('LIMIT_EXCEEDED');
|
|
465
|
+
const sequence = ++startedCalls;
|
|
466
|
+
activeCalls++;
|
|
467
|
+
try {
|
|
468
|
+
let input;
|
|
469
|
+
try {
|
|
470
|
+
input = freezeJson(jsonValue(untrustedInput, { maxBytes: limits.maxToolInputBytes }));
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
return bridgeFailure('INVALID_INPUT');
|
|
474
|
+
}
|
|
390
475
|
if (controller.signal.aborted)
|
|
391
476
|
return bridgeFailure(abortCode);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
return bridgeFailure('LIMIT_EXCEEDED');
|
|
396
|
-
const sequence = ++startedCalls;
|
|
397
|
-
activeCalls++;
|
|
477
|
+
const tool = registered.tools.get(toolId);
|
|
478
|
+
const callId = `${execution.executionId}:code:${sequence}`;
|
|
479
|
+
let outcome;
|
|
398
480
|
try {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
input = freezeJson(jsonValue(untrustedInput, { maxBytes: program.manifest.limits.maxToolInputBytes }));
|
|
402
|
-
}
|
|
403
|
-
catch {
|
|
404
|
-
return bridgeFailure('INVALID_INPUT');
|
|
405
|
-
}
|
|
406
|
-
if (controller.signal.aborted)
|
|
407
|
-
return bridgeFailure(abortCode);
|
|
408
|
-
const tool = registered.tools.get(toolId);
|
|
409
|
-
const callId = `${execution.executionId}:code:${sequence}`;
|
|
410
|
-
let outcome;
|
|
411
|
-
try {
|
|
412
|
-
outcome = await invoke(tool, input, Object.freeze({ runId: execution.runId, executionId: execution.executionId,
|
|
413
|
-
callId, programDigest: program.manifest.digest, scope: execution.scope, signal: controller.signal }));
|
|
414
|
-
}
|
|
415
|
-
catch {
|
|
416
|
-
account(tool);
|
|
417
|
-
return bridgeFailure('TOOL_FAILED');
|
|
418
|
-
}
|
|
419
|
-
const snapshot = snapshotToolOutcome(outcome, program.manifest.limits.maxOutputBytes, callId, toolId);
|
|
420
|
-
account(tool, snapshot.receipt);
|
|
421
|
-
if (snapshot.receipt)
|
|
422
|
-
evidence.push(Object.freeze({ runId: execution.runId, receipt: snapshot.receipt }));
|
|
423
|
-
return snapshot.exposed;
|
|
481
|
+
outcome = await invoke(tool, input, Object.freeze({ runId: execution.runId, executionId: execution.executionId,
|
|
482
|
+
callId, programDigest: program.manifest.digest, scope: execution.scope, signal: controller.signal }));
|
|
424
483
|
}
|
|
425
|
-
|
|
426
|
-
|
|
484
|
+
catch {
|
|
485
|
+
account(tool);
|
|
486
|
+
return bridgeFailure('TOOL_FAILED');
|
|
427
487
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
488
|
+
const snapshot = snapshotToolOutcome(outcome, limits.maxOutputBytes, callId, toolId);
|
|
489
|
+
account(tool, snapshot.receipt);
|
|
490
|
+
if (snapshot.receipt)
|
|
491
|
+
evidence.push(Object.freeze({ runId: execution.runId, receipt: snapshot.receipt }));
|
|
492
|
+
return snapshot.exposed;
|
|
493
|
+
}
|
|
494
|
+
finally {
|
|
495
|
+
activeCalls--;
|
|
496
|
+
}
|
|
497
|
+
})();
|
|
498
|
+
pending.add(operation);
|
|
499
|
+
void operation.finally(() => pending.delete(operation));
|
|
500
|
+
return operation;
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
try {
|
|
504
|
+
let input;
|
|
434
505
|
try {
|
|
435
|
-
|
|
436
|
-
try {
|
|
437
|
-
input = freezeJson(jsonValue(await validate(program.input, inputSnapshot, 'input', { maxBytes: program.manifest.limits.maxInputBytes }), { maxBytes: program.manifest.limits.maxInputBytes }));
|
|
438
|
-
}
|
|
439
|
-
catch {
|
|
440
|
-
return codeOutcome(failure('INVALID_INPUT'), usage());
|
|
441
|
-
}
|
|
442
|
-
if (controller.signal.aborted)
|
|
443
|
-
return codeOutcome(failure(abortCode), usage());
|
|
444
|
-
const request = Object.freeze({ executionId: execution.executionId, manifest: program.manifest, source: registered.source,
|
|
445
|
-
input, signal: controller.signal, tools: bridge });
|
|
446
|
-
let sandboxResult;
|
|
447
|
-
const adapterWork = Promise.resolve().then(() => registration.execute(request));
|
|
448
|
-
void adapterWork.catch(() => undefined);
|
|
449
|
-
await Promise.race([
|
|
450
|
-
adapterWork.then(result => { sandboxResult = snapshotSandboxResult(result, program.manifest.limits.maxOutputBytes); }, () => undefined),
|
|
451
|
-
new Promise(resolve => controller.signal.addEventListener('abort', () => resolve(), { once: true })),
|
|
452
|
-
]);
|
|
453
|
-
bridgeCloseCode = controller.signal.aborted ? abortCode : 'CONFLICT';
|
|
454
|
-
bridgeOpen = false;
|
|
455
|
-
if (controller.signal.aborted) {
|
|
456
|
-
await Promise.allSettled([...pending]);
|
|
457
|
-
const code = unknownCalls > 0 ? 'OUTCOME_UNKNOWN' : abortCode;
|
|
458
|
-
return codeOutcome(Object.freeze({ ...failure(code), ...(evidence.length ? { evidence: Object.freeze([...evidence]) } : {}) }), usage());
|
|
459
|
-
}
|
|
460
|
-
await Promise.allSettled([...pending]);
|
|
461
|
-
if (unknownCalls > 0) {
|
|
462
|
-
return codeOutcome(Object.freeze({ ...failure('OUTCOME_UNKNOWN'), ...(evidence.length ? { evidence: Object.freeze([...evidence]) } : {}) }), usage());
|
|
463
|
-
}
|
|
464
|
-
if (!sandboxResult || !plainRecord(sandboxResult) || sandboxResult.status !== 'succeeded') {
|
|
465
|
-
return codeOutcome(Object.freeze({ ...failure('TOOL_FAILED'), ...(evidence.length ? { evidence: Object.freeze([...evidence]) } : {}) }), usage());
|
|
466
|
-
}
|
|
467
|
-
try {
|
|
468
|
-
const output = freezeJson(jsonValue(await validate(program.output, sandboxResult.output, 'output', { maxBytes: program.manifest.limits.maxOutputBytes }), { maxBytes: program.manifest.limits.maxOutputBytes }));
|
|
469
|
-
return codeOutcome(Object.freeze({ status: 'succeeded', output, ...(evidence.length ? { evidence: Object.freeze([...evidence]) } : {}) }), usage());
|
|
470
|
-
}
|
|
471
|
-
catch {
|
|
472
|
-
return codeOutcome(Object.freeze({ ...failure('INVALID_OUTPUT'), ...(evidence.length ? { evidence: Object.freeze([...evidence]) } : {}) }), usage());
|
|
473
|
-
}
|
|
506
|
+
input = freezeJson(jsonValue(await validate(program.input, inputSnapshot, 'input', { maxBytes: limits.maxInputBytes }), { maxBytes: limits.maxInputBytes }));
|
|
474
507
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
bridgeCloseCode = abortCode;
|
|
478
|
-
bridgeOpen = false;
|
|
479
|
-
clearTimeout(timer);
|
|
480
|
-
execution.signal.removeEventListener('abort', relay);
|
|
481
|
-
if (!controller.signal.aborted)
|
|
482
|
-
controller.abort();
|
|
508
|
+
catch {
|
|
509
|
+
return codeOutcome(failure('INVALID_INPUT', 'The input does not match the program\'s input schema.'), usage());
|
|
483
510
|
}
|
|
484
|
-
|
|
485
|
-
|
|
511
|
+
if (controller.signal.aborted)
|
|
512
|
+
return codeOutcome(failure(abortCode, abortMessages[abortCode]), usage());
|
|
513
|
+
const request = Object.freeze({ executionId: execution.executionId, manifest: program.manifest, source: registered.source,
|
|
514
|
+
input, signal: controller.signal, tools: bridge });
|
|
515
|
+
let sandboxResult = sandboxError;
|
|
516
|
+
const adapterWork = Promise.resolve().then(() => registration.execute(request));
|
|
517
|
+
void adapterWork.catch(() => undefined);
|
|
518
|
+
await Promise.race([
|
|
519
|
+
adapterWork.then(result => { sandboxResult = snapshotSandboxResult(result, limits.maxOutputBytes); }, () => undefined),
|
|
520
|
+
new Promise(resolve => controller.signal.addEventListener('abort', () => resolve(), { once: true })),
|
|
521
|
+
]);
|
|
522
|
+
bridgeCloseCode = controller.signal.aborted ? abortCode : 'CONFLICT';
|
|
523
|
+
bridgeOpen = false;
|
|
524
|
+
// Admitted broker calls always settle before the outcome, so usage and evidence are complete.
|
|
525
|
+
await Promise.allSettled([...pending]);
|
|
526
|
+
if (unknownCalls > 0)
|
|
527
|
+
return codeOutcome(withEvidence(failure('OUTCOME_UNKNOWN', UNKNOWN_MESSAGE)), usage());
|
|
528
|
+
if (controller.signal.aborted)
|
|
529
|
+
return codeOutcome(withEvidence(failure(abortCode, abortMessages[abortCode])), usage());
|
|
530
|
+
const admitted = sandboxResult;
|
|
531
|
+
if (admitted.status === 'failed') {
|
|
532
|
+
const [code, message] = admitted.reason ? reasonFailures[admitted.reason]
|
|
533
|
+
: ['TOOL_FAILED', 'The program or its sandbox failed; the adapter did not report why.'];
|
|
534
|
+
return codeOutcome(withEvidence(failure(code, message)), usage(), admitted.programError);
|
|
535
|
+
}
|
|
536
|
+
try {
|
|
537
|
+
const output = freezeJson(jsonValue(await validate(program.output, admitted.output, 'output', { maxBytes: limits.maxOutputBytes }), { maxBytes: limits.maxOutputBytes }));
|
|
538
|
+
return codeOutcome(withEvidence({ status: 'succeeded', output }), usage());
|
|
539
|
+
}
|
|
540
|
+
catch {
|
|
541
|
+
return codeOutcome(withEvidence(failure('INVALID_OUTPUT', 'The program\'s result does not match its output schema.')), usage());
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
finally {
|
|
545
|
+
if (controller.signal.aborted)
|
|
546
|
+
bridgeCloseCode = abortCode;
|
|
547
|
+
bridgeOpen = false;
|
|
548
|
+
clearTimeout(timer);
|
|
549
|
+
execution.signal.removeEventListener('abort', relay);
|
|
550
|
+
if (!controller.signal.aborted)
|
|
551
|
+
controller.abort();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
486
554
|
modes.add(mode);
|
|
487
555
|
return mode;
|
|
488
556
|
}
|
|
489
557
|
/** Rejects forged executors before they are captured by a durable phase tool. */
|
|
490
558
|
export function assertCodeMode(mode) {
|
|
491
559
|
if (!modes.has(mode))
|
|
492
|
-
throw new MayuraError('INVALID_CONFIG', '
|
|
560
|
+
throw new MayuraError('INVALID_CONFIG', 'The Code Mode executor was not created by createCodeMode from this package instance.');
|
|
493
561
|
}
|
|
494
562
|
/** Runtime assertion for callers that persist or compare program digests. */
|
|
495
563
|
export function isCodeProgramDigest(value) {
|