mayura 0.1.0-dev.0
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/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +55 -0
- package/lib/adapter-code-docker/dist/index.d.ts +65 -0
- package/lib/adapter-code-docker/dist/index.d.ts.map +1 -0
- package/lib/adapter-code-docker/dist/index.js +228 -0
- package/lib/adapter-code-docker/dist/index.js.map +1 -0
- package/lib/adapter-code-docker/image/Dockerfile +12 -0
- package/lib/adapter-code-docker/package.json +5 -0
- package/lib/adapter-code-docker/src/index.ts +244 -0
- package/lib/adapter-code-quickjs/dist/index.d.ts +40 -0
- package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -0
- package/lib/adapter-code-quickjs/dist/index.js +169 -0
- package/lib/adapter-code-quickjs/dist/index.js.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker.d.ts +2 -0
- package/lib/adapter-code-quickjs/dist/worker.d.ts.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker.js +164 -0
- package/lib/adapter-code-quickjs/dist/worker.js.map +1 -0
- package/lib/adapter-code-quickjs/package.json +5 -0
- package/lib/adapter-code-quickjs/src/index.ts +174 -0
- package/lib/adapter-code-quickjs/src/worker.ts +142 -0
- package/lib/adapter-mcp/dist/index.d.ts +29 -0
- package/lib/adapter-mcp/dist/index.d.ts.map +1 -0
- package/lib/adapter-mcp/dist/index.js +54 -0
- package/lib/adapter-mcp/dist/index.js.map +1 -0
- package/lib/adapter-mcp/package.json +5 -0
- package/lib/adapter-mcp/src/index.ts +82 -0
- package/lib/artifacts/dist/contracts.d.ts +139 -0
- package/lib/artifacts/dist/contracts.d.ts.map +1 -0
- package/lib/artifacts/dist/contracts.js +2 -0
- package/lib/artifacts/dist/contracts.js.map +1 -0
- package/lib/artifacts/dist/index.d.ts +3 -0
- package/lib/artifacts/dist/index.d.ts.map +1 -0
- package/lib/artifacts/dist/index.js +2 -0
- package/lib/artifacts/dist/index.js.map +1 -0
- package/lib/artifacts/dist/local-store.d.ts +3 -0
- package/lib/artifacts/dist/local-store.d.ts.map +1 -0
- package/lib/artifacts/dist/local-store.js +922 -0
- package/lib/artifacts/dist/local-store.js.map +1 -0
- package/lib/artifacts/package.json +5 -0
- package/lib/artifacts/src/contracts.ts +159 -0
- package/lib/artifacts/src/index.ts +26 -0
- package/lib/artifacts/src/local-store.ts +816 -0
- package/lib/cli/dist/application.d.ts +85 -0
- package/lib/cli/dist/application.d.ts.map +1 -0
- package/lib/cli/dist/application.js +116 -0
- package/lib/cli/dist/application.js.map +1 -0
- package/lib/cli/dist/bin.d.ts +3 -0
- package/lib/cli/dist/bin.d.ts.map +1 -0
- package/lib/cli/dist/bin.js +394 -0
- package/lib/cli/dist/bin.js.map +1 -0
- package/lib/cli/dist/dev.d.ts +21 -0
- package/lib/cli/dist/dev.d.ts.map +1 -0
- package/lib/cli/dist/dev.js +205 -0
- package/lib/cli/dist/dev.js.map +1 -0
- package/lib/cli/dist/index.d.ts +72 -0
- package/lib/cli/dist/index.d.ts.map +1 -0
- package/lib/cli/dist/index.js +423 -0
- package/lib/cli/dist/index.js.map +1 -0
- package/lib/cli/dist/interactive.d.ts +19 -0
- package/lib/cli/dist/interactive.d.ts.map +1 -0
- package/lib/cli/dist/interactive.js +163 -0
- package/lib/cli/dist/interactive.js.map +1 -0
- package/lib/cli/dist/operations.d.ts +215 -0
- package/lib/cli/dist/operations.d.ts.map +1 -0
- package/lib/cli/dist/operations.js +580 -0
- package/lib/cli/dist/operations.js.map +1 -0
- package/lib/cli/dist/output.d.ts +29 -0
- package/lib/cli/dist/output.d.ts.map +1 -0
- package/lib/cli/dist/output.js +244 -0
- package/lib/cli/dist/output.js.map +1 -0
- package/lib/cli/dist/providers.d.ts +54 -0
- package/lib/cli/dist/providers.d.ts.map +1 -0
- package/lib/cli/dist/providers.js +96 -0
- package/lib/cli/dist/providers.js.map +1 -0
- package/lib/cli/package.json +5 -0
- package/lib/cli/src/application.ts +109 -0
- package/lib/cli/src/bin.ts +261 -0
- package/lib/cli/src/dev.ts +139 -0
- package/lib/cli/src/index.ts +386 -0
- package/lib/cli/src/interactive.ts +132 -0
- package/lib/cli/src/operations.ts +458 -0
- package/lib/cli/src/output.ts +205 -0
- package/lib/cli/src/providers.ts +102 -0
- package/lib/cli/starters/approval-workflow/Dockerfile +20 -0
- package/lib/cli/starters/approval-workflow/README.md +102 -0
- package/lib/cli/starters/approval-workflow/compose.yaml +33 -0
- package/lib/cli/starters/approval-workflow/dot-dockerignore +7 -0
- package/lib/cli/starters/approval-workflow/dot-env.example +41 -0
- package/lib/cli/starters/approval-workflow/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/approval-workflow/dot-gitignore +10 -0
- package/lib/cli/starters/approval-workflow/mayura.project.json +16 -0
- package/lib/cli/starters/approval-workflow/package.json +30 -0
- package/lib/cli/starters/approval-workflow/src/app.ts +19 -0
- package/lib/cli/starters/approval-workflow/src/auth.ts +68 -0
- package/lib/cli/starters/approval-workflow/src/config.ts +107 -0
- package/lib/cli/starters/approval-workflow/src/dev.ts +59 -0
- package/lib/cli/starters/approval-workflow/src/intake.ts +104 -0
- package/lib/cli/starters/approval-workflow/src/model.ts +33 -0
- package/lib/cli/starters/approval-workflow/src/server.ts +56 -0
- package/lib/cli/starters/approval-workflow/src/services.ts +26 -0
- package/lib/cli/starters/approval-workflow/src/token.ts +6 -0
- package/lib/cli/starters/approval-workflow/src/worker.ts +18 -0
- package/lib/cli/starters/approval-workflow/src/workflow.ts +100 -0
- package/lib/cli/starters/approval-workflow/test/refunds.test.ts +140 -0
- package/lib/cli/starters/approval-workflow/tsconfig.json +20 -0
- package/lib/cli/starters/event-automation/Dockerfile +21 -0
- package/lib/cli/starters/event-automation/README.md +150 -0
- package/lib/cli/starters/event-automation/compose.yaml +41 -0
- package/lib/cli/starters/event-automation/dot-dockerignore +7 -0
- package/lib/cli/starters/event-automation/dot-env.example +51 -0
- package/lib/cli/starters/event-automation/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/event-automation/dot-gitignore +10 -0
- package/lib/cli/starters/event-automation/mayura.project.json +17 -0
- package/lib/cli/starters/event-automation/package.json +32 -0
- package/lib/cli/starters/event-automation/src/app.ts +19 -0
- package/lib/cli/starters/event-automation/src/auth.ts +61 -0
- package/lib/cli/starters/event-automation/src/config.ts +138 -0
- package/lib/cli/starters/event-automation/src/dev.ts +54 -0
- package/lib/cli/starters/event-automation/src/ingress.ts +129 -0
- package/lib/cli/starters/event-automation/src/mcp.ts +139 -0
- package/lib/cli/starters/event-automation/src/model.ts +33 -0
- package/lib/cli/starters/event-automation/src/send-sample.ts +29 -0
- package/lib/cli/starters/event-automation/src/server.ts +58 -0
- package/lib/cli/starters/event-automation/src/services.ts +54 -0
- package/lib/cli/starters/event-automation/src/signing.ts +30 -0
- package/lib/cli/starters/event-automation/src/token.ts +7 -0
- package/lib/cli/starters/event-automation/src/tracker/main.ts +18 -0
- package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +145 -0
- package/lib/cli/starters/event-automation/src/tracker/samples.ts +19 -0
- package/lib/cli/starters/event-automation/src/tracker/tickets.ts +54 -0
- package/lib/cli/starters/event-automation/src/tracker-tools.ts +38 -0
- package/lib/cli/starters/event-automation/src/triage.ts +151 -0
- package/lib/cli/starters/event-automation/src/worker.ts +19 -0
- package/lib/cli/starters/event-automation/src/workflows.ts +57 -0
- package/lib/cli/starters/event-automation/test/automation.test.ts +200 -0
- package/lib/cli/starters/event-automation/tsconfig.json +20 -0
- package/lib/cli/starters/research-team/Dockerfile +22 -0
- package/lib/cli/starters/research-team/README.md +189 -0
- package/lib/cli/starters/research-team/compose.yaml +38 -0
- package/lib/cli/starters/research-team/dot-dockerignore +7 -0
- package/lib/cli/starters/research-team/dot-env.example +49 -0
- package/lib/cli/starters/research-team/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/research-team/dot-gitignore +10 -0
- package/lib/cli/starters/research-team/mayura.project.json +22 -0
- package/lib/cli/starters/research-team/package.json +30 -0
- package/lib/cli/starters/research-team/src/app.ts +19 -0
- package/lib/cli/starters/research-team/src/auth.ts +56 -0
- package/lib/cli/starters/research-team/src/config.ts +170 -0
- package/lib/cli/starters/research-team/src/desk.ts +124 -0
- package/lib/cli/starters/research-team/src/dev.ts +58 -0
- package/lib/cli/starters/research-team/src/library/corpus.ts +76 -0
- package/lib/cli/starters/research-team/src/library/index.ts +109 -0
- package/lib/cli/starters/research-team/src/model.ts +33 -0
- package/lib/cli/starters/research-team/src/server.ts +69 -0
- package/lib/cli/starters/research-team/src/services.ts +48 -0
- package/lib/cli/starters/research-team/src/team.ts +173 -0
- package/lib/cli/starters/research-team/src/telemetry.ts +95 -0
- package/lib/cli/starters/research-team/src/token.ts +6 -0
- package/lib/cli/starters/research-team/src/worker.ts +21 -0
- package/lib/cli/starters/research-team/src/workflow.ts +197 -0
- package/lib/cli/starters/research-team/test/research.test.ts +271 -0
- package/lib/cli/starters/research-team/tsconfig.json +20 -0
- package/lib/cli/starters/support-agent/Dockerfile +21 -0
- package/lib/cli/starters/support-agent/README.md +128 -0
- package/lib/cli/starters/support-agent/compose.yaml +33 -0
- package/lib/cli/starters/support-agent/dot-dockerignore +7 -0
- package/lib/cli/starters/support-agent/dot-env.example +44 -0
- package/lib/cli/starters/support-agent/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/support-agent/dot-gitignore +10 -0
- package/lib/cli/starters/support-agent/mayura.project.json +18 -0
- package/lib/cli/starters/support-agent/package.json +43 -0
- package/lib/cli/starters/support-agent/src/app.ts +19 -0
- package/lib/cli/starters/support-agent/src/assistant.ts +313 -0
- package/lib/cli/starters/support-agent/src/auth.ts +69 -0
- package/lib/cli/starters/support-agent/src/config.ts +120 -0
- package/lib/cli/starters/support-agent/src/dev.ts +115 -0
- package/lib/cli/starters/support-agent/src/guardrails.ts +71 -0
- package/lib/cli/starters/support-agent/src/model.ts +33 -0
- package/lib/cli/starters/support-agent/src/orders.ts +62 -0
- package/lib/cli/starters/support-agent/src/returns.ts +86 -0
- package/lib/cli/starters/support-agent/src/server.ts +72 -0
- package/lib/cli/starters/support-agent/src/services.ts +32 -0
- package/lib/cli/starters/support-agent/src/session.ts +55 -0
- package/lib/cli/starters/support-agent/src/token.ts +9 -0
- package/lib/cli/starters/support-agent/src/worker.ts +19 -0
- package/lib/cli/starters/support-agent/test/support.test.ts +263 -0
- package/lib/cli/starters/support-agent/tsconfig.json +20 -0
- package/lib/cli/starters/support-agent/web/index.html +12 -0
- package/lib/cli/starters/support-agent/web/src/App.tsx +43 -0
- package/lib/cli/starters/support-agent/web/src/components/chat.tsx +161 -0
- package/lib/cli/starters/support-agent/web/src/components/ui/button.tsx +33 -0
- package/lib/cli/starters/support-agent/web/src/components/ui/primitives.tsx +48 -0
- package/lib/cli/starters/support-agent/web/src/env.d.ts +1 -0
- package/lib/cli/starters/support-agent/web/src/lib/api.ts +56 -0
- package/lib/cli/starters/support-agent/web/src/lib/utils.ts +4 -0
- package/lib/cli/starters/support-agent/web/src/main.tsx +6 -0
- package/lib/cli/starters/support-agent/web/src/styles.css +86 -0
- package/lib/cli/starters/support-agent/web/tsconfig.json +9 -0
- package/lib/cli/starters/support-agent/web/vite.config.ts +13 -0
- package/lib/cli/templates/basic-agent.ts +10 -0
- package/lib/cli/templates/capability-policy.ts +18 -0
- package/lib/cli/templates/code-mode-workflow.ts +34 -0
- package/lib/cli/templates/durable-approval.ts +25 -0
- package/lib/cli/templates/guarded-streaming-app.ts +23 -0
- package/lib/cli/templates/native-memory.ts +15 -0
- package/lib/cli/templates/parallel-research.ts +21 -0
- package/lib/cli/templates/typed-tool-runner.ts +15 -0
- package/lib/client/dist/forms.d.ts +77 -0
- package/lib/client/dist/forms.d.ts.map +1 -0
- package/lib/client/dist/forms.js +282 -0
- package/lib/client/dist/forms.js.map +1 -0
- package/lib/client/dist/headless.d.ts +84 -0
- package/lib/client/dist/headless.d.ts.map +1 -0
- package/lib/client/dist/headless.js +376 -0
- package/lib/client/dist/headless.js.map +1 -0
- package/lib/client/dist/index.d.ts +266 -0
- package/lib/client/dist/index.d.ts.map +1 -0
- package/lib/client/dist/index.js +814 -0
- package/lib/client/dist/index.js.map +1 -0
- package/lib/client/dist/workflows.d.ts +128 -0
- package/lib/client/dist/workflows.d.ts.map +1 -0
- package/lib/client/dist/workflows.js +379 -0
- package/lib/client/dist/workflows.js.map +1 -0
- package/lib/client/package.json +5 -0
- package/lib/client/src/forms.ts +215 -0
- package/lib/client/src/headless.ts +265 -0
- package/lib/client/src/index.ts +646 -0
- package/lib/client/src/workflows.ts +307 -0
- package/lib/client-react/dist/components.d.ts +70 -0
- package/lib/client-react/dist/components.d.ts.map +1 -0
- package/lib/client-react/dist/components.js +173 -0
- package/lib/client-react/dist/components.js.map +1 -0
- package/lib/client-react/dist/index.d.ts +29 -0
- package/lib/client-react/dist/index.d.ts.map +1 -0
- package/lib/client-react/dist/index.js +57 -0
- package/lib/client-react/dist/index.js.map +1 -0
- package/lib/client-react/package.json +5 -0
- package/lib/client-react/src/components.ts +183 -0
- package/lib/client-react/src/index.ts +70 -0
- package/lib/code-mode/dist/index.d.ts +142 -0
- package/lib/code-mode/dist/index.d.ts.map +1 -0
- package/lib/code-mode/dist/index.js +498 -0
- package/lib/code-mode/dist/index.js.map +1 -0
- package/lib/code-mode/package.json +5 -0
- package/lib/code-mode/src/index.ts +605 -0
- package/lib/code-mode-workflows/dist/index.d.ts +51 -0
- package/lib/code-mode-workflows/dist/index.d.ts.map +1 -0
- package/lib/code-mode-workflows/dist/index.js +231 -0
- package/lib/code-mode-workflows/dist/index.js.map +1 -0
- package/lib/code-mode-workflows/package.json +5 -0
- package/lib/code-mode-workflows/src/index.ts +259 -0
- package/lib/context/dist/assemble.d.ts +11 -0
- package/lib/context/dist/assemble.d.ts.map +1 -0
- package/lib/context/dist/assemble.js +265 -0
- package/lib/context/dist/assemble.js.map +1 -0
- package/lib/context/dist/cache.d.ts +53 -0
- package/lib/context/dist/cache.d.ts.map +1 -0
- package/lib/context/dist/cache.js +147 -0
- package/lib/context/dist/cache.js.map +1 -0
- package/lib/context/dist/contracts.d.ts +145 -0
- package/lib/context/dist/contracts.d.ts.map +1 -0
- package/lib/context/dist/contracts.js +2 -0
- package/lib/context/dist/contracts.js.map +1 -0
- package/lib/context/dist/index.d.ts +4 -0
- package/lib/context/dist/index.d.ts.map +1 -0
- package/lib/context/dist/index.js +3 -0
- package/lib/context/dist/index.js.map +1 -0
- package/lib/context/package.json +5 -0
- package/lib/context/src/assemble.ts +205 -0
- package/lib/context/src/cache.ts +143 -0
- package/lib/context/src/contracts.ts +124 -0
- package/lib/context/src/index.ts +3 -0
- package/lib/core/dist/budget.d.ts +85 -0
- package/lib/core/dist/budget.d.ts.map +1 -0
- package/lib/core/dist/budget.js +328 -0
- package/lib/core/dist/budget.js.map +1 -0
- package/lib/core/dist/contracts.d.ts +156 -0
- package/lib/core/dist/contracts.d.ts.map +1 -0
- package/lib/core/dist/contracts.js +13 -0
- package/lib/core/dist/contracts.js.map +1 -0
- package/lib/core/dist/errors.d.ts +17 -0
- package/lib/core/dist/errors.d.ts.map +1 -0
- package/lib/core/dist/errors.js +22 -0
- package/lib/core/dist/errors.js.map +1 -0
- package/lib/core/dist/event-stream.d.ts +26 -0
- package/lib/core/dist/event-stream.d.ts.map +1 -0
- package/lib/core/dist/event-stream.js +116 -0
- package/lib/core/dist/event-stream.js.map +1 -0
- package/lib/core/dist/host.d.ts +7 -0
- package/lib/core/dist/host.d.ts.map +1 -0
- package/lib/core/dist/host.js +7 -0
- package/lib/core/dist/host.js.map +1 -0
- package/lib/core/dist/index.d.ts +8 -0
- package/lib/core/dist/index.d.ts.map +1 -0
- package/lib/core/dist/index.js +7 -0
- package/lib/core/dist/index.js.map +1 -0
- package/lib/core/dist/json.d.ts +18 -0
- package/lib/core/dist/json.d.ts.map +1 -0
- package/lib/core/dist/json.js +100 -0
- package/lib/core/dist/json.js.map +1 -0
- package/lib/core/dist/lifecycle.d.ts +45 -0
- package/lib/core/dist/lifecycle.d.ts.map +1 -0
- package/lib/core/dist/lifecycle.js +114 -0
- package/lib/core/dist/lifecycle.js.map +1 -0
- package/lib/core/dist/local-guards.d.ts +4 -0
- package/lib/core/dist/local-guards.d.ts.map +1 -0
- package/lib/core/dist/local-guards.js +47 -0
- package/lib/core/dist/local-guards.js.map +1 -0
- package/lib/core/dist/managed-guards.d.ts +44 -0
- package/lib/core/dist/managed-guards.d.ts.map +1 -0
- package/lib/core/dist/managed-guards.js +146 -0
- package/lib/core/dist/managed-guards.js.map +1 -0
- package/lib/core/dist/schema.d.ts +36 -0
- package/lib/core/dist/schema.d.ts.map +1 -0
- package/lib/core/dist/schema.js +24 -0
- package/lib/core/dist/schema.js.map +1 -0
- package/lib/core/package.json +5 -0
- package/lib/core/src/budget.ts +366 -0
- package/lib/core/src/contracts.ts +107 -0
- package/lib/core/src/errors.ts +33 -0
- package/lib/core/src/event-stream.ts +87 -0
- package/lib/core/src/host.ts +6 -0
- package/lib/core/src/index.ts +7 -0
- package/lib/core/src/json.ts +81 -0
- package/lib/core/src/lifecycle.ts +133 -0
- package/lib/core/src/local-guards.ts +37 -0
- package/lib/core/src/managed-guards.ts +154 -0
- package/lib/core/src/schema.ts +43 -0
- package/lib/exporter-otlp/dist/contracts.d.ts +112 -0
- package/lib/exporter-otlp/dist/contracts.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/contracts.js +2 -0
- package/lib/exporter-otlp/dist/contracts.js.map +1 -0
- package/lib/exporter-otlp/dist/index.d.ts +5 -0
- package/lib/exporter-otlp/dist/index.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/index.js +4 -0
- package/lib/exporter-otlp/dist/index.js.map +1 -0
- package/lib/exporter-otlp/dist/otlp-http-json.d.ts +4 -0
- package/lib/exporter-otlp/dist/otlp-http-json.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js +286 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -0
- package/lib/exporter-otlp/dist/run-traces.d.ts +15 -0
- package/lib/exporter-otlp/dist/run-traces.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/run-traces.js +114 -0
- package/lib/exporter-otlp/dist/run-traces.js.map +1 -0
- package/lib/exporter-otlp/dist/signals.d.ts +4 -0
- package/lib/exporter-otlp/dist/signals.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/signals.js +330 -0
- package/lib/exporter-otlp/dist/signals.js.map +1 -0
- package/lib/exporter-otlp/package.json +5 -0
- package/lib/exporter-otlp/src/contracts.ts +119 -0
- package/lib/exporter-otlp/src/index.ts +23 -0
- package/lib/exporter-otlp/src/otlp-http-json.ts +189 -0
- package/lib/exporter-otlp/src/run-traces.ts +86 -0
- package/lib/exporter-otlp/src/signals.ts +185 -0
- package/lib/guardrails/dist/agent-guard.d.ts +9 -0
- package/lib/guardrails/dist/agent-guard.d.ts.map +1 -0
- package/lib/guardrails/dist/agent-guard.js +23 -0
- package/lib/guardrails/dist/agent-guard.js.map +1 -0
- package/lib/guardrails/dist/auxiliary-helpers.d.ts +63 -0
- package/lib/guardrails/dist/auxiliary-helpers.d.ts.map +1 -0
- package/lib/guardrails/dist/auxiliary-helpers.js +147 -0
- package/lib/guardrails/dist/auxiliary-helpers.js.map +1 -0
- package/lib/guardrails/dist/auxiliary.d.ts +51 -0
- package/lib/guardrails/dist/auxiliary.d.ts.map +1 -0
- package/lib/guardrails/dist/auxiliary.js +230 -0
- package/lib/guardrails/dist/auxiliary.js.map +1 -0
- package/lib/guardrails/dist/batches.d.ts +18 -0
- package/lib/guardrails/dist/batches.d.ts.map +1 -0
- package/lib/guardrails/dist/batches.js +160 -0
- package/lib/guardrails/dist/batches.js.map +1 -0
- package/lib/guardrails/dist/disclosure.d.ts +30 -0
- package/lib/guardrails/dist/disclosure.d.ts.map +1 -0
- package/lib/guardrails/dist/disclosure.js +109 -0
- package/lib/guardrails/dist/disclosure.js.map +1 -0
- package/lib/guardrails/dist/helpers.d.ts +20 -0
- package/lib/guardrails/dist/helpers.d.ts.map +1 -0
- package/lib/guardrails/dist/helpers.js +72 -0
- package/lib/guardrails/dist/helpers.js.map +1 -0
- package/lib/guardrails/dist/index.d.ts +9 -0
- package/lib/guardrails/dist/index.d.ts.map +1 -0
- package/lib/guardrails/dist/index.js +9 -0
- package/lib/guardrails/dist/index.js.map +1 -0
- package/lib/guardrails/dist/managed.d.ts +18 -0
- package/lib/guardrails/dist/managed.d.ts.map +1 -0
- package/lib/guardrails/dist/managed.js +67 -0
- package/lib/guardrails/dist/managed.js.map +1 -0
- package/lib/guardrails/dist/pipeline.d.ts +55 -0
- package/lib/guardrails/dist/pipeline.d.ts.map +1 -0
- package/lib/guardrails/dist/pipeline.js +201 -0
- package/lib/guardrails/dist/pipeline.js.map +1 -0
- package/lib/guardrails/package.json +5 -0
- package/lib/guardrails/src/agent-guard.ts +22 -0
- package/lib/guardrails/src/auxiliary-helpers.ts +146 -0
- package/lib/guardrails/src/auxiliary.ts +202 -0
- package/lib/guardrails/src/batches.ts +130 -0
- package/lib/guardrails/src/disclosure.ts +92 -0
- package/lib/guardrails/src/helpers.ts +67 -0
- package/lib/guardrails/src/index.ts +8 -0
- package/lib/guardrails/src/managed.ts +64 -0
- package/lib/guardrails/src/pipeline.ts +185 -0
- package/lib/helpers/dist/concurrency.d.ts +25 -0
- package/lib/helpers/dist/concurrency.d.ts.map +1 -0
- package/lib/helpers/dist/concurrency.js +106 -0
- package/lib/helpers/dist/concurrency.js.map +1 -0
- package/lib/helpers/dist/configuration.d.ts +42 -0
- package/lib/helpers/dist/configuration.d.ts.map +1 -0
- package/lib/helpers/dist/configuration.js +119 -0
- package/lib/helpers/dist/configuration.js.map +1 -0
- package/lib/helpers/dist/control.d.ts +61 -0
- package/lib/helpers/dist/control.d.ts.map +1 -0
- package/lib/helpers/dist/control.js +220 -0
- package/lib/helpers/dist/control.js.map +1 -0
- package/lib/helpers/dist/credentials.d.ts +42 -0
- package/lib/helpers/dist/credentials.d.ts.map +1 -0
- package/lib/helpers/dist/credentials.js +126 -0
- package/lib/helpers/dist/credentials.js.map +1 -0
- package/lib/helpers/dist/data.d.ts +30 -0
- package/lib/helpers/dist/data.d.ts.map +1 -0
- package/lib/helpers/dist/data.js +90 -0
- package/lib/helpers/dist/data.js.map +1 -0
- package/lib/helpers/dist/index.d.ts +6 -0
- package/lib/helpers/dist/index.d.ts.map +1 -0
- package/lib/helpers/dist/index.js +6 -0
- package/lib/helpers/dist/index.js.map +1 -0
- package/lib/helpers/package.json +5 -0
- package/lib/helpers/src/concurrency.ts +92 -0
- package/lib/helpers/src/configuration.ts +131 -0
- package/lib/helpers/src/control.ts +231 -0
- package/lib/helpers/src/credentials.ts +113 -0
- package/lib/helpers/src/data.ts +105 -0
- package/lib/helpers/src/index.ts +5 -0
- package/lib/memory/dist/contracts.d.ts +146 -0
- package/lib/memory/dist/contracts.d.ts.map +1 -0
- package/lib/memory/dist/contracts.js +2 -0
- package/lib/memory/dist/contracts.js.map +1 -0
- package/lib/memory/dist/index.d.ts +10 -0
- package/lib/memory/dist/index.d.ts.map +1 -0
- package/lib/memory/dist/index.js +316 -0
- package/lib/memory/dist/index.js.map +1 -0
- package/lib/memory/dist/native.d.ts +157 -0
- package/lib/memory/dist/native.d.ts.map +1 -0
- package/lib/memory/dist/native.js +664 -0
- package/lib/memory/dist/native.js.map +1 -0
- package/lib/memory/dist/validation.d.ts +21 -0
- package/lib/memory/dist/validation.d.ts.map +1 -0
- package/lib/memory/dist/validation.js +123 -0
- package/lib/memory/dist/validation.js.map +1 -0
- package/lib/memory/dist/vectors.d.ts +40 -0
- package/lib/memory/dist/vectors.d.ts.map +1 -0
- package/lib/memory/dist/vectors.js +134 -0
- package/lib/memory/dist/vectors.js.map +1 -0
- package/lib/memory/package.json +5 -0
- package/lib/memory/src/contracts.ts +113 -0
- package/lib/memory/src/index.ts +241 -0
- package/lib/memory/src/native.ts +568 -0
- package/lib/memory/src/validation.ts +103 -0
- package/lib/memory/src/vectors.ts +121 -0
- package/lib/memory-remote/dist/index.d.ts +91 -0
- package/lib/memory-remote/dist/index.d.ts.map +1 -0
- package/lib/memory-remote/dist/index.js +434 -0
- package/lib/memory-remote/dist/index.js.map +1 -0
- package/lib/memory-remote/package.json +5 -0
- package/lib/memory-remote/src/index.ts +367 -0
- package/lib/observability/dist/contracts.d.ts +102 -0
- package/lib/observability/dist/contracts.d.ts.map +1 -0
- package/lib/observability/dist/contracts.js +2 -0
- package/lib/observability/dist/contracts.js.map +1 -0
- package/lib/observability/dist/index.d.ts +5 -0
- package/lib/observability/dist/index.d.ts.map +1 -0
- package/lib/observability/dist/index.js +4 -0
- package/lib/observability/dist/index.js.map +1 -0
- package/lib/observability/dist/observer.d.ts +4 -0
- package/lib/observability/dist/observer.d.ts.map +1 -0
- package/lib/observability/dist/observer.js +354 -0
- package/lib/observability/dist/observer.js.map +1 -0
- package/lib/observability/dist/validation.d.ts +6 -0
- package/lib/observability/dist/validation.d.ts.map +1 -0
- package/lib/observability/dist/validation.js +203 -0
- package/lib/observability/dist/validation.js.map +1 -0
- package/lib/observability/package.json +5 -0
- package/lib/observability/src/contracts.ts +85 -0
- package/lib/observability/src/index.ts +4 -0
- package/lib/observability/src/observer.ts +246 -0
- package/lib/observability/src/validation.ts +132 -0
- package/lib/provider-anthropic/dist/index.d.ts +19 -0
- package/lib/provider-anthropic/dist/index.d.ts.map +1 -0
- package/lib/provider-anthropic/dist/index.js +342 -0
- package/lib/provider-anthropic/dist/index.js.map +1 -0
- package/lib/provider-anthropic/package.json +5 -0
- package/lib/provider-anthropic/src/index.ts +317 -0
- package/lib/provider-openai/dist/index.d.ts +77 -0
- package/lib/provider-openai/dist/index.d.ts.map +1 -0
- package/lib/provider-openai/dist/index.js +577 -0
- package/lib/provider-openai/dist/index.js.map +1 -0
- package/lib/provider-openai/package.json +5 -0
- package/lib/provider-openai/src/index.ts +459 -0
- package/lib/runtime/dist/agent.d.ts +63 -0
- package/lib/runtime/dist/agent.d.ts.map +1 -0
- package/lib/runtime/dist/agent.js +134 -0
- package/lib/runtime/dist/agent.js.map +1 -0
- package/lib/runtime/dist/composition.d.ts +21 -0
- package/lib/runtime/dist/composition.d.ts.map +1 -0
- package/lib/runtime/dist/composition.js +54 -0
- package/lib/runtime/dist/composition.js.map +1 -0
- package/lib/runtime/dist/event-buffer.d.ts +18 -0
- package/lib/runtime/dist/event-buffer.d.ts.map +1 -0
- package/lib/runtime/dist/event-buffer.js +66 -0
- package/lib/runtime/dist/event-buffer.js.map +1 -0
- package/lib/runtime/dist/hook-execution.d.ts +40 -0
- package/lib/runtime/dist/hook-execution.d.ts.map +1 -0
- package/lib/runtime/dist/hook-execution.js +186 -0
- package/lib/runtime/dist/hook-execution.js.map +1 -0
- package/lib/runtime/dist/hooks.d.ts +178 -0
- package/lib/runtime/dist/hooks.d.ts.map +1 -0
- package/lib/runtime/dist/hooks.js +120 -0
- package/lib/runtime/dist/hooks.js.map +1 -0
- package/lib/runtime/dist/index.d.ts +6 -0
- package/lib/runtime/dist/index.d.ts.map +1 -0
- package/lib/runtime/dist/index.js +6 -0
- package/lib/runtime/dist/index.js.map +1 -0
- package/lib/runtime/dist/managed-guards.d.ts +27 -0
- package/lib/runtime/dist/managed-guards.d.ts.map +1 -0
- package/lib/runtime/dist/managed-guards.js +183 -0
- package/lib/runtime/dist/managed-guards.js.map +1 -0
- package/lib/runtime/dist/permits.d.ts +9 -0
- package/lib/runtime/dist/permits.d.ts.map +1 -0
- package/lib/runtime/dist/permits.js +77 -0
- package/lib/runtime/dist/permits.js.map +1 -0
- package/lib/runtime/dist/response.d.ts +8 -0
- package/lib/runtime/dist/response.d.ts.map +1 -0
- package/lib/runtime/dist/response.js +83 -0
- package/lib/runtime/dist/response.js.map +1 -0
- package/lib/runtime/dist/router.d.ts +51 -0
- package/lib/runtime/dist/router.d.ts.map +1 -0
- package/lib/runtime/dist/router.js +181 -0
- package/lib/runtime/dist/router.js.map +1 -0
- package/lib/runtime/dist/runtime.d.ts +98 -0
- package/lib/runtime/dist/runtime.d.ts.map +1 -0
- package/lib/runtime/dist/runtime.js +945 -0
- package/lib/runtime/dist/runtime.js.map +1 -0
- package/lib/runtime/dist/stream.d.ts +25 -0
- package/lib/runtime/dist/stream.d.ts.map +1 -0
- package/lib/runtime/dist/stream.js +226 -0
- package/lib/runtime/dist/stream.js.map +1 -0
- package/lib/runtime/package.json +5 -0
- package/lib/runtime/src/agent.ts +167 -0
- package/lib/runtime/src/composition.ts +63 -0
- package/lib/runtime/src/event-buffer.ts +55 -0
- package/lib/runtime/src/hook-execution.ts +188 -0
- package/lib/runtime/src/hooks.ts +227 -0
- package/lib/runtime/src/index.ts +5 -0
- package/lib/runtime/src/managed-guards.ts +176 -0
- package/lib/runtime/src/permits.ts +65 -0
- package/lib/runtime/src/response.ts +68 -0
- package/lib/runtime/src/router.ts +178 -0
- package/lib/runtime/src/runtime.ts +909 -0
- package/lib/runtime/src/stream.ts +130 -0
- package/lib/sdk/dist/index.d.ts +5 -0
- package/lib/sdk/dist/index.d.ts.map +1 -0
- package/lib/sdk/dist/index.js +5 -0
- package/lib/sdk/dist/index.js.map +1 -0
- package/lib/sdk/package.json +5 -0
- package/lib/sdk/src/index.ts +4 -0
- package/lib/server/dist/index.d.ts +343 -0
- package/lib/server/dist/index.d.ts.map +1 -0
- package/lib/server/dist/index.js +1356 -0
- package/lib/server/dist/index.js.map +1 -0
- package/lib/server/dist/inspector-bundle.d.ts +6 -0
- package/lib/server/dist/inspector-bundle.d.ts.map +1 -0
- package/lib/server/dist/inspector-bundle.js +6 -0
- package/lib/server/dist/inspector-bundle.js.map +1 -0
- package/lib/server/dist/inspector.d.ts +3 -0
- package/lib/server/dist/inspector.d.ts.map +1 -0
- package/lib/server/dist/inspector.js +27 -0
- package/lib/server/dist/inspector.js.map +1 -0
- package/lib/server/package.json +5 -0
- package/lib/server/src/index.ts +1033 -0
- package/lib/server/src/inspector-bundle.ts +5 -0
- package/lib/server/src/inspector.ts +27 -0
- package/lib/server-node/dist/hardening.d.ts +19 -0
- package/lib/server-node/dist/hardening.d.ts.map +1 -0
- package/lib/server-node/dist/hardening.js +79 -0
- package/lib/server-node/dist/hardening.js.map +1 -0
- package/lib/server-node/dist/index.d.ts +18 -0
- package/lib/server-node/dist/index.d.ts.map +1 -0
- package/lib/server-node/dist/index.js +53 -0
- package/lib/server-node/dist/index.js.map +1 -0
- package/lib/server-node/dist/probe.d.ts +13 -0
- package/lib/server-node/dist/probe.d.ts.map +1 -0
- package/lib/server-node/dist/probe.js +44 -0
- package/lib/server-node/dist/probe.js.map +1 -0
- package/lib/server-node/dist/production.d.ts +32 -0
- package/lib/server-node/dist/production.d.ts.map +1 -0
- package/lib/server-node/dist/production.js +125 -0
- package/lib/server-node/dist/production.js.map +1 -0
- package/lib/server-node/package.json +5 -0
- package/lib/server-node/src/hardening.ts +79 -0
- package/lib/server-node/src/index.ts +58 -0
- package/lib/server-node/src/probe.ts +36 -0
- package/lib/server-node/src/production.ts +116 -0
- package/lib/storage/dist/index.d.ts +4 -0
- package/lib/storage/dist/index.d.ts.map +1 -0
- package/lib/storage/dist/index.js +5 -0
- package/lib/storage/dist/index.js.map +1 -0
- package/lib/storage/package.json +5 -0
- package/lib/storage/src/index.ts +5 -0
- package/lib/storage-contracts/dist/contracts.d.ts +69 -0
- package/lib/storage-contracts/dist/contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/contracts.js +15 -0
- package/lib/storage-contracts/dist/contracts.js.map +1 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.d.ts +110 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.js +430 -0
- package/lib/storage-contracts/dist/durable-budget-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.d.ts +74 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.js +159 -0
- package/lib/storage-contracts/dist/execution-wait-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/index.d.ts +18 -0
- package/lib/storage-contracts/dist/index.d.ts.map +1 -0
- package/lib/storage-contracts/dist/index.js +18 -0
- package/lib/storage-contracts/dist/index.js.map +1 -0
- package/lib/storage-contracts/dist/memory-contracts.d.ts +208 -0
- package/lib/storage-contracts/dist/memory-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/memory-contracts.js +350 -0
- package/lib/storage-contracts/dist/memory-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts +171 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.js +2 -0
- package/lib/storage-contracts/dist/scheduled-workflow-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/scheduler-contracts.d.ts +133 -0
- package/lib/storage-contracts/dist/scheduler-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/scheduler-contracts.js +2 -0
- package/lib/storage-contracts/dist/scheduler-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/submission-journal.d.ts +21 -0
- package/lib/storage-contracts/dist/submission-journal.d.ts.map +1 -0
- package/lib/storage-contracts/dist/submission-journal.js +51 -0
- package/lib/storage-contracts/dist/submission-journal.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format2.d.ts +54 -0
- package/lib/storage-contracts/dist/workflow-format2.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format2.js +398 -0
- package/lib/storage-contracts/dist/workflow-format2.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format3.d.ts +20 -0
- package/lib/storage-contracts/dist/workflow-format3.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format3.js +309 -0
- package/lib/storage-contracts/dist/workflow-format3.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format4.d.ts +48 -0
- package/lib/storage-contracts/dist/workflow-format4.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format4.js +132 -0
- package/lib/storage-contracts/dist/workflow-format4.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-format5.d.ts +94 -0
- package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-format5.js +365 -0
- package/lib/storage-contracts/dist/workflow-format5.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts +69 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.js +2 -0
- package/lib/storage-contracts/dist/workflow-graph-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.d.ts +45 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.js +101 -0
- package/lib/storage-contracts/dist/workflow-graph-discovery.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.d.ts +52 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.js +134 -0
- package/lib/storage-contracts/dist/workflow-loop-format1.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.d.ts +52 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.js +235 -0
- package/lib/storage-contracts/dist/workflow-saga-format1.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts +428 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.js +151 -0
- package/lib/storage-contracts/dist/workflow-tree-contracts.js.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.d.ts +38 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.d.ts.map +1 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.js +57 -0
- package/lib/storage-contracts/dist/workflow-tree-discovery.js.map +1 -0
- package/lib/storage-contracts/package.json +5 -0
- package/lib/storage-contracts/src/contracts.ts +73 -0
- package/lib/storage-contracts/src/durable-budget-contracts.ts +266 -0
- package/lib/storage-contracts/src/execution-wait-contracts.ts +169 -0
- package/lib/storage-contracts/src/index.ts +17 -0
- package/lib/storage-contracts/src/memory-contracts.ts +322 -0
- package/lib/storage-contracts/src/scheduled-workflow-contracts.ts +88 -0
- package/lib/storage-contracts/src/scheduler-contracts.ts +68 -0
- package/lib/storage-contracts/src/submission-journal.ts +50 -0
- package/lib/storage-contracts/src/workflow-format2.ts +288 -0
- package/lib/storage-contracts/src/workflow-format3.ts +201 -0
- package/lib/storage-contracts/src/workflow-format4.ts +96 -0
- package/lib/storage-contracts/src/workflow-format5.ts +375 -0
- package/lib/storage-contracts/src/workflow-graph-contracts.ts +44 -0
- package/lib/storage-contracts/src/workflow-graph-discovery.ts +107 -0
- package/lib/storage-contracts/src/workflow-loop-format1.ts +102 -0
- package/lib/storage-contracts/src/workflow-saga-format1.ts +165 -0
- package/lib/storage-contracts/src/workflow-tree-contracts.ts +191 -0
- package/lib/storage-contracts/src/workflow-tree-discovery.ts +39 -0
- package/lib/storage-postgres/dist/index.d.ts +2 -0
- package/lib/storage-postgres/dist/index.d.ts.map +1 -0
- package/lib/storage-postgres/dist/index.js +2 -0
- package/lib/storage-postgres/dist/index.js.map +1 -0
- package/lib/storage-postgres/dist/postgres.d.ts +8 -0
- package/lib/storage-postgres/dist/postgres.d.ts.map +1 -0
- package/lib/storage-postgres/dist/postgres.js +233 -0
- package/lib/storage-postgres/dist/postgres.js.map +1 -0
- package/lib/storage-postgres/package.json +5 -0
- package/lib/storage-postgres/src/index.ts +1 -0
- package/lib/storage-postgres/src/postgres.ts +222 -0
- package/lib/storage-sql/dist/aggregate-session.d.ts +31 -0
- package/lib/storage-sql/dist/aggregate-session.d.ts.map +1 -0
- package/lib/storage-sql/dist/aggregate-session.js +78 -0
- package/lib/storage-sql/dist/aggregate-session.js.map +1 -0
- package/lib/storage-sql/dist/contracts.d.ts +2 -0
- package/lib/storage-sql/dist/contracts.d.ts.map +1 -0
- package/lib/storage-sql/dist/contracts.js +3 -0
- package/lib/storage-sql/dist/contracts.js.map +1 -0
- package/lib/storage-sql/dist/durable-budget-database.d.ts +33 -0
- package/lib/storage-sql/dist/durable-budget-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/durable-budget-database.js +191 -0
- package/lib/storage-sql/dist/durable-budget-database.js.map +1 -0
- package/lib/storage-sql/dist/durable-budget-state.d.ts +24 -0
- package/lib/storage-sql/dist/durable-budget-state.d.ts.map +1 -0
- package/lib/storage-sql/dist/durable-budget-state.js +211 -0
- package/lib/storage-sql/dist/durable-budget-state.js.map +1 -0
- package/lib/storage-sql/dist/durable-budget-validation.d.ts +5 -0
- package/lib/storage-sql/dist/durable-budget-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/durable-budget-validation.js +22 -0
- package/lib/storage-sql/dist/durable-budget-validation.js.map +1 -0
- package/lib/storage-sql/dist/execution-completions.d.ts +12 -0
- package/lib/storage-sql/dist/execution-completions.d.ts.map +1 -0
- package/lib/storage-sql/dist/execution-completions.js +60 -0
- package/lib/storage-sql/dist/execution-completions.js.map +1 -0
- package/lib/storage-sql/dist/execution-wait-database.d.ts +22 -0
- package/lib/storage-sql/dist/execution-wait-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/execution-wait-database.js +288 -0
- package/lib/storage-sql/dist/execution-wait-database.js.map +1 -0
- package/lib/storage-sql/dist/execution-wait-validation.d.ts +8 -0
- package/lib/storage-sql/dist/execution-wait-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/execution-wait-validation.js +125 -0
- package/lib/storage-sql/dist/execution-wait-validation.js.map +1 -0
- package/lib/storage-sql/dist/host.d.ts +22 -0
- package/lib/storage-sql/dist/host.d.ts.map +1 -0
- package/lib/storage-sql/dist/host.js +21 -0
- package/lib/storage-sql/dist/host.js.map +1 -0
- package/lib/storage-sql/dist/memory-database.d.ts +24 -0
- package/lib/storage-sql/dist/memory-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/memory-database.js +359 -0
- package/lib/storage-sql/dist/memory-database.js.map +1 -0
- package/lib/storage-sql/dist/scheduled-database.d.ts +74 -0
- package/lib/storage-sql/dist/scheduled-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduled-database.js +1152 -0
- package/lib/storage-sql/dist/scheduled-database.js.map +1 -0
- package/lib/storage-sql/dist/scheduled-validation.d.ts +9 -0
- package/lib/storage-sql/dist/scheduled-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduled-validation.js +200 -0
- package/lib/storage-sql/dist/scheduled-validation.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-contracts.d.ts +2 -0
- package/lib/storage-sql/dist/scheduler-contracts.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduler-contracts.js +3 -0
- package/lib/storage-sql/dist/scheduler-contracts.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-database.d.ts +55 -0
- package/lib/storage-sql/dist/scheduler-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduler-database.js +655 -0
- package/lib/storage-sql/dist/scheduler-database.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-validation.d.ts +22 -0
- package/lib/storage-sql/dist/scheduler-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduler-validation.js +201 -0
- package/lib/storage-sql/dist/scheduler-validation.js.map +1 -0
- package/lib/storage-sql/dist/validation.d.ts +14 -0
- package/lib/storage-sql/dist/validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/validation.js +106 -0
- package/lib/storage-sql/dist/validation.js.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.d.ts +7 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.js +55 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.js.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.d.ts +5 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.js +22 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-validation.js.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-database.d.ts +270 -0
- package/lib/storage-sql/dist/workflow-tree-database.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-database.js +1692 -0
- package/lib/storage-sql/dist/workflow-tree-database.js.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.d.ts +5 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.js +15 -0
- package/lib/storage-sql/dist/workflow-tree-discovery-validation.js.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-validation.d.ts +9 -0
- package/lib/storage-sql/dist/workflow-tree-validation.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-validation.js +576 -0
- package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -0
- package/lib/storage-sql/package.json +5 -0
- package/lib/storage-sql/src/aggregate-session.ts +72 -0
- package/lib/storage-sql/src/contracts.ts +2 -0
- package/lib/storage-sql/src/durable-budget-database.ts +180 -0
- package/lib/storage-sql/src/durable-budget-state.ts +155 -0
- package/lib/storage-sql/src/durable-budget-validation.ts +23 -0
- package/lib/storage-sql/src/execution-completions.ts +58 -0
- package/lib/storage-sql/src/execution-wait-database.ts +219 -0
- package/lib/storage-sql/src/execution-wait-validation.ts +108 -0
- package/lib/storage-sql/src/host.ts +21 -0
- package/lib/storage-sql/src/memory-database.ts +320 -0
- package/lib/storage-sql/src/scheduled-database.ts +811 -0
- package/lib/storage-sql/src/scheduled-validation.ts +89 -0
- package/lib/storage-sql/src/scheduler-contracts.ts +2 -0
- package/lib/storage-sql/src/scheduler-database.ts +475 -0
- package/lib/storage-sql/src/scheduler-validation.ts +112 -0
- package/lib/storage-sql/src/validation.ts +104 -0
- package/lib/storage-sql/src/workflow-graph-discovery-index.ts +60 -0
- package/lib/storage-sql/src/workflow-graph-discovery-validation.ts +21 -0
- package/lib/storage-sql/src/workflow-tree-database.ts +450 -0
- package/lib/storage-sql/src/workflow-tree-discovery-validation.ts +13 -0
- package/lib/storage-sql/src/workflow-tree-validation.ts +166 -0
- package/lib/storage-sqlite/dist/backup.d.ts +24 -0
- package/lib/storage-sqlite/dist/backup.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/backup.js +84 -0
- package/lib/storage-sqlite/dist/backup.js.map +1 -0
- package/lib/storage-sqlite/dist/index.d.ts +4 -0
- package/lib/storage-sqlite/dist/index.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/index.js +4 -0
- package/lib/storage-sqlite/dist/index.js.map +1 -0
- package/lib/storage-sqlite/dist/migrations.d.ts +6 -0
- package/lib/storage-sqlite/dist/migrations.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/migrations.js +50 -0
- package/lib/storage-sqlite/dist/migrations.js.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-database.d.ts +36 -0
- package/lib/storage-sqlite/dist/sqlite-database.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-database.js +179 -0
- package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-worker.d.ts +2 -0
- package/lib/storage-sqlite/dist/sqlite-worker.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/sqlite-worker.js +95 -0
- package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -0
- package/lib/storage-sqlite/dist/sqlite.d.ts +7 -0
- package/lib/storage-sqlite/dist/sqlite.d.ts.map +1 -0
- package/lib/storage-sqlite/dist/sqlite.js +78 -0
- package/lib/storage-sqlite/dist/sqlite.js.map +1 -0
- package/lib/storage-sqlite/package.json +5 -0
- package/lib/storage-sqlite/src/backup.ts +58 -0
- package/lib/storage-sqlite/src/index.ts +3 -0
- package/lib/storage-sqlite/src/migrations.ts +46 -0
- package/lib/storage-sqlite/src/sqlite-database.ts +172 -0
- package/lib/storage-sqlite/src/sqlite-worker.ts +52 -0
- package/lib/storage-sqlite/src/sqlite.ts +72 -0
- package/lib/testing/dist/index.d.ts +10 -0
- package/lib/testing/dist/index.d.ts.map +1 -0
- package/lib/testing/dist/index.js +24 -0
- package/lib/testing/dist/index.js.map +1 -0
- package/lib/testing/package.json +5 -0
- package/lib/testing/src/index.ts +26 -0
- package/lib/tools/dist/batch.d.ts +71 -0
- package/lib/tools/dist/batch.d.ts.map +1 -0
- package/lib/tools/dist/batch.js +542 -0
- package/lib/tools/dist/batch.js.map +1 -0
- package/lib/tools/dist/budget-binding.d.ts +18 -0
- package/lib/tools/dist/budget-binding.d.ts.map +1 -0
- package/lib/tools/dist/budget-binding.js +65 -0
- package/lib/tools/dist/budget-binding.js.map +1 -0
- package/lib/tools/dist/context.d.ts +17 -0
- package/lib/tools/dist/context.d.ts.map +1 -0
- package/lib/tools/dist/context.js +52 -0
- package/lib/tools/dist/context.js.map +1 -0
- package/lib/tools/dist/host.d.ts +3 -0
- package/lib/tools/dist/host.d.ts.map +1 -0
- package/lib/tools/dist/host.js +3 -0
- package/lib/tools/dist/host.js.map +1 -0
- package/lib/tools/dist/index.d.ts +79 -0
- package/lib/tools/dist/index.d.ts.map +1 -0
- package/lib/tools/dist/index.js +462 -0
- package/lib/tools/dist/index.js.map +1 -0
- package/lib/tools/package.json +5 -0
- package/lib/tools/src/batch.ts +496 -0
- package/lib/tools/src/budget-binding.ts +63 -0
- package/lib/tools/src/context.ts +56 -0
- package/lib/tools/src/host.ts +2 -0
- package/lib/tools/src/index.ts +479 -0
- package/lib/workflows/dist/agents.d.ts +24 -0
- package/lib/workflows/dist/agents.d.ts.map +1 -0
- package/lib/workflows/dist/agents.js +55 -0
- package/lib/workflows/dist/agents.js.map +1 -0
- package/lib/workflows/dist/children-coordinator.d.ts +58 -0
- package/lib/workflows/dist/children-coordinator.d.ts.map +1 -0
- package/lib/workflows/dist/children-coordinator.js +148 -0
- package/lib/workflows/dist/children-coordinator.js.map +1 -0
- package/lib/workflows/dist/children-definition.d.ts +43 -0
- package/lib/workflows/dist/children-definition.d.ts.map +1 -0
- package/lib/workflows/dist/children-definition.js +74 -0
- package/lib/workflows/dist/children-definition.js.map +1 -0
- package/lib/workflows/dist/children-discovery.d.ts +20 -0
- package/lib/workflows/dist/children-discovery.d.ts.map +1 -0
- package/lib/workflows/dist/children-discovery.js +103 -0
- package/lib/workflows/dist/children-discovery.js.map +1 -0
- package/lib/workflows/dist/children-runtime.d.ts +72 -0
- package/lib/workflows/dist/children-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/children-runtime.js +600 -0
- package/lib/workflows/dist/children-runtime.js.map +1 -0
- package/lib/workflows/dist/children.d.ts +9 -0
- package/lib/workflows/dist/children.d.ts.map +1 -0
- package/lib/workflows/dist/children.js +6 -0
- package/lib/workflows/dist/children.js.map +1 -0
- package/lib/workflows/dist/composite-fleet.d.ts +87 -0
- package/lib/workflows/dist/composite-fleet.d.ts.map +1 -0
- package/lib/workflows/dist/composite-fleet.js +259 -0
- package/lib/workflows/dist/composite-fleet.js.map +1 -0
- package/lib/workflows/dist/composite-host.d.ts +45 -0
- package/lib/workflows/dist/composite-host.d.ts.map +1 -0
- package/lib/workflows/dist/composite-host.js +132 -0
- package/lib/workflows/dist/composite-host.js.map +1 -0
- package/lib/workflows/dist/composites.d.ts +4 -0
- package/lib/workflows/dist/composites.d.ts.map +1 -0
- package/lib/workflows/dist/composites.js +3 -0
- package/lib/workflows/dist/composites.js.map +1 -0
- package/lib/workflows/dist/definition.d.ts +61 -0
- package/lib/workflows/dist/definition.d.ts.map +1 -0
- package/lib/workflows/dist/definition.js +112 -0
- package/lib/workflows/dist/definition.js.map +1 -0
- package/lib/workflows/dist/drain.d.ts +21 -0
- package/lib/workflows/dist/drain.d.ts.map +1 -0
- package/lib/workflows/dist/drain.js +53 -0
- package/lib/workflows/dist/drain.js.map +1 -0
- package/lib/workflows/dist/ephemeral.d.ts +24 -0
- package/lib/workflows/dist/ephemeral.d.ts.map +1 -0
- package/lib/workflows/dist/ephemeral.js +122 -0
- package/lib/workflows/dist/ephemeral.js.map +1 -0
- package/lib/workflows/dist/fleet-control.d.ts +129 -0
- package/lib/workflows/dist/fleet-control.d.ts.map +1 -0
- package/lib/workflows/dist/fleet-control.js +356 -0
- package/lib/workflows/dist/fleet-control.js.map +1 -0
- package/lib/workflows/dist/graph-coordinator.d.ts +60 -0
- package/lib/workflows/dist/graph-coordinator.d.ts.map +1 -0
- package/lib/workflows/dist/graph-coordinator.js +266 -0
- package/lib/workflows/dist/graph-coordinator.js.map +1 -0
- package/lib/workflows/dist/graph-definition.d.ts +40 -0
- package/lib/workflows/dist/graph-definition.d.ts.map +1 -0
- package/lib/workflows/dist/graph-definition.js +58 -0
- package/lib/workflows/dist/graph-definition.js.map +1 -0
- package/lib/workflows/dist/graph-discovery.d.ts +27 -0
- package/lib/workflows/dist/graph-discovery.d.ts.map +1 -0
- package/lib/workflows/dist/graph-discovery.js +165 -0
- package/lib/workflows/dist/graph-discovery.js.map +1 -0
- package/lib/workflows/dist/graphs.d.ts +55 -0
- package/lib/workflows/dist/graphs.d.ts.map +1 -0
- package/lib/workflows/dist/graphs.js +10 -0
- package/lib/workflows/dist/graphs.js.map +1 -0
- package/lib/workflows/dist/hook-relay.d.ts +67 -0
- package/lib/workflows/dist/hook-relay.d.ts.map +1 -0
- package/lib/workflows/dist/hook-relay.js +157 -0
- package/lib/workflows/dist/hook-relay.js.map +1 -0
- package/lib/workflows/dist/index.d.ts +16 -0
- package/lib/workflows/dist/index.d.ts.map +1 -0
- package/lib/workflows/dist/index.js +15 -0
- package/lib/workflows/dist/index.js.map +1 -0
- package/lib/workflows/dist/leadership.d.ts +33 -0
- package/lib/workflows/dist/leadership.d.ts.map +1 -0
- package/lib/workflows/dist/leadership.js +109 -0
- package/lib/workflows/dist/leadership.js.map +1 -0
- package/lib/workflows/dist/lifecycle-definition.d.ts +89 -0
- package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-definition.js +137 -0
- package/lib/workflows/dist/lifecycle-definition.js.map +1 -0
- package/lib/workflows/dist/lifecycle-fleet.d.ts +90 -0
- package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-fleet.js +406 -0
- package/lib/workflows/dist/lifecycle-fleet.js.map +1 -0
- package/lib/workflows/dist/lifecycle-host.d.ts +44 -0
- package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-host.js +133 -0
- package/lib/workflows/dist/lifecycle-host.js.map +1 -0
- package/lib/workflows/dist/lifecycle-human-transport.d.ts +67 -0
- package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-human-transport.js +149 -0
- package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -0
- package/lib/workflows/dist/lifecycle-runtime.d.ts +115 -0
- package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle-runtime.js +831 -0
- package/lib/workflows/dist/lifecycle-runtime.js.map +1 -0
- package/lib/workflows/dist/lifecycle.d.ts +10 -0
- package/lib/workflows/dist/lifecycle.d.ts.map +1 -0
- package/lib/workflows/dist/lifecycle.js +7 -0
- package/lib/workflows/dist/lifecycle.js.map +1 -0
- package/lib/workflows/dist/loop-definition.d.ts +46 -0
- package/lib/workflows/dist/loop-definition.d.ts.map +1 -0
- package/lib/workflows/dist/loop-definition.js +55 -0
- package/lib/workflows/dist/loop-definition.js.map +1 -0
- package/lib/workflows/dist/loop-runtime.d.ts +47 -0
- package/lib/workflows/dist/loop-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/loop-runtime.js +358 -0
- package/lib/workflows/dist/loop-runtime.js.map +1 -0
- package/lib/workflows/dist/loops.d.ts +6 -0
- package/lib/workflows/dist/loops.d.ts.map +1 -0
- package/lib/workflows/dist/loops.js +4 -0
- package/lib/workflows/dist/loops.js.map +1 -0
- package/lib/workflows/dist/migration-service.d.ts +55 -0
- package/lib/workflows/dist/migration-service.d.ts.map +1 -0
- package/lib/workflows/dist/migration-service.js +73 -0
- package/lib/workflows/dist/migration-service.js.map +1 -0
- package/lib/workflows/dist/migration.d.ts +123 -0
- package/lib/workflows/dist/migration.d.ts.map +1 -0
- package/lib/workflows/dist/migration.js +217 -0
- package/lib/workflows/dist/migration.js.map +1 -0
- package/lib/workflows/dist/operator-transports.d.ts +265 -0
- package/lib/workflows/dist/operator-transports.d.ts.map +1 -0
- package/lib/workflows/dist/operator-transports.js +404 -0
- package/lib/workflows/dist/operator-transports.js.map +1 -0
- package/lib/workflows/dist/reconciliation.d.ts +25 -0
- package/lib/workflows/dist/reconciliation.d.ts.map +1 -0
- package/lib/workflows/dist/reconciliation.js +109 -0
- package/lib/workflows/dist/reconciliation.js.map +1 -0
- package/lib/workflows/dist/runtime.d.ts +65 -0
- package/lib/workflows/dist/runtime.d.ts.map +1 -0
- package/lib/workflows/dist/runtime.js +492 -0
- package/lib/workflows/dist/runtime.js.map +1 -0
- package/lib/workflows/dist/saga-definition.d.ts +46 -0
- package/lib/workflows/dist/saga-definition.d.ts.map +1 -0
- package/lib/workflows/dist/saga-definition.js +71 -0
- package/lib/workflows/dist/saga-definition.js.map +1 -0
- package/lib/workflows/dist/saga-runtime.d.ts +51 -0
- package/lib/workflows/dist/saga-runtime.d.ts.map +1 -0
- package/lib/workflows/dist/saga-runtime.js +499 -0
- package/lib/workflows/dist/saga-runtime.js.map +1 -0
- package/lib/workflows/dist/sagas.d.ts +6 -0
- package/lib/workflows/dist/sagas.d.ts.map +1 -0
- package/lib/workflows/dist/sagas.js +4 -0
- package/lib/workflows/dist/sagas.js.map +1 -0
- package/lib/workflows/dist/scheduled-helpers.d.ts +53 -0
- package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -0
- package/lib/workflows/dist/scheduled-helpers.js +230 -0
- package/lib/workflows/dist/scheduled-helpers.js.map +1 -0
- package/lib/workflows/dist/scheduled.d.ts +116 -0
- package/lib/workflows/dist/scheduled.d.ts.map +1 -0
- package/lib/workflows/dist/scheduled.js +781 -0
- package/lib/workflows/dist/scheduled.js.map +1 -0
- package/lib/workflows/dist/traces.d.ts +158 -0
- package/lib/workflows/dist/traces.d.ts.map +1 -0
- package/lib/workflows/dist/traces.js +366 -0
- package/lib/workflows/dist/traces.js.map +1 -0
- package/lib/workflows/dist/versions.d.ts +57 -0
- package/lib/workflows/dist/versions.d.ts.map +1 -0
- package/lib/workflows/dist/versions.js +87 -0
- package/lib/workflows/dist/versions.js.map +1 -0
- package/lib/workflows/dist/worker.d.ts +51 -0
- package/lib/workflows/dist/worker.d.ts.map +1 -0
- package/lib/workflows/dist/worker.js +143 -0
- package/lib/workflows/dist/worker.js.map +1 -0
- package/lib/workflows/package.json +5 -0
- package/lib/workflows/src/agents.ts +65 -0
- package/lib/workflows/src/children-coordinator.ts +50 -0
- package/lib/workflows/src/children-definition.ts +88 -0
- package/lib/workflows/src/children-discovery.ts +32 -0
- package/lib/workflows/src/children-runtime.ts +169 -0
- package/lib/workflows/src/children.ts +12 -0
- package/lib/workflows/src/composite-fleet.ts +155 -0
- package/lib/workflows/src/composite-host.ts +67 -0
- package/lib/workflows/src/composites.ts +6 -0
- package/lib/workflows/src/definition.ts +113 -0
- package/lib/workflows/src/drain.ts +56 -0
- package/lib/workflows/src/ephemeral.ts +124 -0
- package/lib/workflows/src/fleet-control.ts +326 -0
- package/lib/workflows/src/graph-coordinator.ts +223 -0
- package/lib/workflows/src/graph-definition.ts +70 -0
- package/lib/workflows/src/graph-discovery.ts +145 -0
- package/lib/workflows/src/graphs.ts +56 -0
- package/lib/workflows/src/hook-relay.ts +177 -0
- package/lib/workflows/src/index.ts +27 -0
- package/lib/workflows/src/leadership.ts +102 -0
- package/lib/workflows/src/lifecycle-definition.ts +194 -0
- package/lib/workflows/src/lifecycle-fleet.ts +346 -0
- package/lib/workflows/src/lifecycle-host.ts +109 -0
- package/lib/workflows/src/lifecycle-human-transport.ts +170 -0
- package/lib/workflows/src/lifecycle-runtime.ts +673 -0
- package/lib/workflows/src/lifecycle.ts +59 -0
- package/lib/workflows/src/loop-definition.ts +62 -0
- package/lib/workflows/src/loop-runtime.ts +260 -0
- package/lib/workflows/src/loops.ts +7 -0
- package/lib/workflows/src/migration-service.ts +83 -0
- package/lib/workflows/src/migration.ts +242 -0
- package/lib/workflows/src/operator-transports.ts +439 -0
- package/lib/workflows/src/reconciliation.ts +121 -0
- package/lib/workflows/src/runtime.ts +348 -0
- package/lib/workflows/src/saga-definition.ts +104 -0
- package/lib/workflows/src/saga-runtime.ts +406 -0
- package/lib/workflows/src/sagas.ts +24 -0
- package/lib/workflows/src/scheduled-helpers.ts +214 -0
- package/lib/workflows/src/scheduled.ts +707 -0
- package/lib/workflows/src/traces.ts +381 -0
- package/lib/workflows/src/versions.ts +114 -0
- package/lib/workflows/src/worker.ts +115 -0
- package/lib/workstream/dist/executions.d.ts +34 -0
- package/lib/workstream/dist/executions.d.ts.map +1 -0
- package/lib/workstream/dist/executions.js +344 -0
- package/lib/workstream/dist/executions.js.map +1 -0
- package/lib/workstream/dist/humans.d.ts +76 -0
- package/lib/workstream/dist/humans.d.ts.map +1 -0
- package/lib/workstream/dist/humans.js +273 -0
- package/lib/workstream/dist/humans.js.map +1 -0
- package/lib/workstream/dist/index.d.ts +61 -0
- package/lib/workstream/dist/index.d.ts.map +1 -0
- package/lib/workstream/dist/index.js +310 -0
- package/lib/workstream/dist/index.js.map +1 -0
- package/lib/workstream/dist/timers.d.ts +41 -0
- package/lib/workstream/dist/timers.d.ts.map +1 -0
- package/lib/workstream/dist/timers.js +240 -0
- package/lib/workstream/dist/timers.js.map +1 -0
- package/lib/workstream/dist/webhooks.d.ts +69 -0
- package/lib/workstream/dist/webhooks.d.ts.map +1 -0
- package/lib/workstream/dist/webhooks.js +313 -0
- package/lib/workstream/dist/webhooks.js.map +1 -0
- package/lib/workstream/package.json +5 -0
- package/lib/workstream/src/executions.ts +253 -0
- package/lib/workstream/src/humans.ts +323 -0
- package/lib/workstream/src/index.ts +279 -0
- package/lib/workstream/src/timers.ts +212 -0
- package/lib/workstream/src/webhooks.ts +180 -0
- package/package.json +281 -0
|
@@ -0,0 +1,1356 @@
|
|
|
1
|
+
import { freezeJson, jsonValue } from '../../core/dist/index.js';
|
|
2
|
+
import { inspectorAsset } from './inspector.js';
|
|
3
|
+
import { assertAgent, createRuntime } from '../../runtime/dist/index.js';
|
|
4
|
+
class HttpFailure extends Error {
|
|
5
|
+
status;
|
|
6
|
+
code;
|
|
7
|
+
constructor(status, code) {
|
|
8
|
+
super(code);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const identifier = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/;
|
|
14
|
+
const humanIdentifier = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
|
|
15
|
+
const encoder = new TextEncoder();
|
|
16
|
+
const workflowKinds = Object.freeze({ 2: new Set(['tool', 'join']), 3: new Set(['tool', 'join', 'wait']),
|
|
17
|
+
4: new Set(['tool', 'join', 'child']), 5: new Set(['tool', 'join', 'human', 'timer']) });
|
|
18
|
+
const workflowStatuses = new Set(['running', 'waiting', 'paused', 'succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown']);
|
|
19
|
+
const workflowStepStatuses = new Set(['pending', 'waiting', 'approved', 'dispatching', 'succeeded', 'failed', 'blocked', 'unknown', 'skipped', 'timed_out']);
|
|
20
|
+
const approvalRecord = (value) => {
|
|
21
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
22
|
+
return false;
|
|
23
|
+
const keys = Object.keys(value);
|
|
24
|
+
const subject = value['subject'];
|
|
25
|
+
return keys.every(key => ['digest', 'expiresAtMs', 'subject'].includes(key)) && typeof value['digest'] === 'string' && /^[a-f0-9]{64}$/.test(value['digest'])
|
|
26
|
+
&& typeof value['expiresAtMs'] === 'number' && Number.isSafeInteger(value['expiresAtMs']) && value['expiresAtMs'] > 0
|
|
27
|
+
&& (subject === undefined || (subject !== null && typeof subject === 'object' && !Array.isArray(subject)
|
|
28
|
+
&& Object.keys(subject).length === 3 && Object.hasOwn(subject, 'input')
|
|
29
|
+
&& typeof subject['toolId'] === 'string' && identifier.test(subject['toolId'])
|
|
30
|
+
&& typeof subject['toolVersion'] === 'string' && identifier.test(subject['toolVersion'])));
|
|
31
|
+
};
|
|
32
|
+
function object(value, maxBytes = 1_048_576) {
|
|
33
|
+
const copy = jsonValue(value, { maxBytes });
|
|
34
|
+
if (copy === null || Array.isArray(copy) || typeof copy !== 'object')
|
|
35
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
36
|
+
return copy;
|
|
37
|
+
}
|
|
38
|
+
function exact(value, keys) {
|
|
39
|
+
if (Object.keys(value).length !== keys.length || keys.some(key => !(key in value)))
|
|
40
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
41
|
+
}
|
|
42
|
+
function canonical(value) {
|
|
43
|
+
if (value === null || typeof value !== 'object')
|
|
44
|
+
return JSON.stringify(value);
|
|
45
|
+
return Array.isArray(value) ? `[${value.map(canonical).join(',')}]`
|
|
46
|
+
: `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`;
|
|
47
|
+
}
|
|
48
|
+
function origin(value) {
|
|
49
|
+
const url = new URL(value);
|
|
50
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
|
|
51
|
+
throw new Error('Invalid server origin.');
|
|
52
|
+
if (url.protocol === 'http:' && !['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))
|
|
53
|
+
throw new Error('Non-loopback origins require HTTPS.');
|
|
54
|
+
return url.origin;
|
|
55
|
+
}
|
|
56
|
+
function assertActive(signal) { if (signal.aborted)
|
|
57
|
+
throw new HttpFailure(408, 'REQUEST_TIMEOUT'); }
|
|
58
|
+
function workflowExact(value, keys) {
|
|
59
|
+
if (Object.keys(value).length !== keys.length || keys.some(key => !Object.hasOwn(value, key)))
|
|
60
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
61
|
+
}
|
|
62
|
+
function workflowRecord(value, expectedRunId) {
|
|
63
|
+
let raw;
|
|
64
|
+
try {
|
|
65
|
+
raw = object(value, 262_144);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
69
|
+
}
|
|
70
|
+
workflowExact(raw, ['format', 'definitionId', 'definitionVersion', 'runId', 'revision', 'status', 'nodes', 'steps']);
|
|
71
|
+
const format = raw['format'];
|
|
72
|
+
const nodes = raw['nodes'];
|
|
73
|
+
const steps = raw['steps'];
|
|
74
|
+
if (![2, 3, 4, 5].includes(format) || typeof raw['definitionId'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(raw['definitionId'])
|
|
75
|
+
|| typeof raw['definitionVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['definitionVersion'])
|
|
76
|
+
|| raw['runId'] !== expectedRunId || typeof raw['revision'] !== 'number' || !Number.isSafeInteger(raw['revision']) || raw['revision'] < 1
|
|
77
|
+
|| typeof raw['status'] !== 'string' || !workflowStatuses.has(raw['status']) || !Array.isArray(nodes) || nodes.length < 1 || nodes.length > 128
|
|
78
|
+
|| !Array.isArray(steps) || steps.length !== nodes.length)
|
|
79
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
80
|
+
const admittedKinds = workflowKinds[format];
|
|
81
|
+
const graph = new Map();
|
|
82
|
+
const nodeKinds = new Map();
|
|
83
|
+
let edges = 0;
|
|
84
|
+
for (const candidate of nodes) {
|
|
85
|
+
let node;
|
|
86
|
+
try {
|
|
87
|
+
node = object(candidate, 32_768);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
91
|
+
}
|
|
92
|
+
workflowExact(node, ['id', 'kind', 'dependsOn']);
|
|
93
|
+
if (typeof node['id'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(node['id']) || graph.has(node['id'])
|
|
94
|
+
|| typeof node['kind'] !== 'string' || !admittedKinds.has(node['kind']) || !Array.isArray(node['dependsOn']) || node['dependsOn'].length > 127
|
|
95
|
+
|| node['dependsOn'].some(item => typeof item !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(item))
|
|
96
|
+
|| new Set(node['dependsOn']).size !== node['dependsOn'].length)
|
|
97
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
98
|
+
edges += node['dependsOn'].length;
|
|
99
|
+
if (edges > 512)
|
|
100
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
101
|
+
graph.set(node['id'], node['dependsOn']);
|
|
102
|
+
nodeKinds.set(node['id'], node['kind']);
|
|
103
|
+
}
|
|
104
|
+
for (const [id, dependencies] of graph)
|
|
105
|
+
if (dependencies.some(dependency => dependency === id || !graph.has(dependency)))
|
|
106
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
107
|
+
const seen = new Set();
|
|
108
|
+
for (const candidate of steps) {
|
|
109
|
+
let step;
|
|
110
|
+
try {
|
|
111
|
+
step = object(candidate, 16_384);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
115
|
+
}
|
|
116
|
+
const allowed = ['id', 'kind', 'status', 'childRunId', 'approval'];
|
|
117
|
+
if (Object.keys(step).some(key => !allowed.includes(key)) || !['id', 'kind', 'status'].every(key => Object.hasOwn(step, key)) || typeof step['id'] !== 'string'
|
|
118
|
+
|| seen.has(step['id']) || step['kind'] !== nodeKinds.get(step['id']) || typeof step['status'] !== 'string' || !workflowStepStatuses.has(step['status'])
|
|
119
|
+
|| (step['kind'] === 'human' && !['pending', 'waiting', 'succeeded', 'timed_out', 'skipped'].includes(step['status']))
|
|
120
|
+
|| (step['kind'] === 'timer' && !['pending', 'waiting', 'succeeded', 'skipped'].includes(step['status']))
|
|
121
|
+
|| (step['status'] === 'timed_out' && step['kind'] !== 'human')
|
|
122
|
+
|| (step['childRunId'] !== undefined && (step['kind'] !== 'child' || typeof step['childRunId'] !== 'string' || !/^[a-f0-9]{64}$/.test(step['childRunId'])))
|
|
123
|
+
|| (step['approval'] !== undefined && (step['kind'] !== 'tool' || step['status'] !== 'waiting' || !approvalRecord(step['approval']))))
|
|
124
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
125
|
+
seen.add(step['id']);
|
|
126
|
+
}
|
|
127
|
+
if (seen.size !== graph.size)
|
|
128
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
129
|
+
const remaining = new Map([...graph].map(([id, dependencies]) => [id, dependencies.length]));
|
|
130
|
+
const dependents = new Map();
|
|
131
|
+
for (const [id, dependencies] of graph)
|
|
132
|
+
for (const dependency of dependencies) {
|
|
133
|
+
const list = dependents.get(dependency) ?? [];
|
|
134
|
+
list.push(id);
|
|
135
|
+
dependents.set(dependency, list);
|
|
136
|
+
}
|
|
137
|
+
const queue = [...remaining].filter(([, count]) => count === 0).map(([id]) => id);
|
|
138
|
+
for (let cursor = 0; cursor < queue.length; cursor++)
|
|
139
|
+
for (const dependent of dependents.get(queue[cursor]) ?? []) {
|
|
140
|
+
const count = remaining.get(dependent) - 1;
|
|
141
|
+
remaining.set(dependent, count);
|
|
142
|
+
if (count === 0)
|
|
143
|
+
queue.push(dependent);
|
|
144
|
+
}
|
|
145
|
+
if (queue.length !== graph.size)
|
|
146
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
147
|
+
return freezeJson(raw);
|
|
148
|
+
}
|
|
149
|
+
const fleetOutcomes = new Set(['paused', 'already_paused', 'terminal', 'busy', 'resumed', 'not_paused', 'missing', 'unregistered']);
|
|
150
|
+
function fleetHold(value) {
|
|
151
|
+
let raw;
|
|
152
|
+
try {
|
|
153
|
+
raw = object(value, 1_024);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
157
|
+
}
|
|
158
|
+
workflowExact(raw, ['held', 'generation', 'changedAtMs']);
|
|
159
|
+
const { held, generation, changedAtMs } = raw;
|
|
160
|
+
if (typeof held !== 'boolean' || typeof generation !== 'number' || !Number.isSafeInteger(generation) || generation < (held ? 1 : 0)
|
|
161
|
+
|| (changedAtMs !== null && (typeof changedAtMs !== 'number' || !Number.isSafeInteger(changedAtMs) || changedAtMs < 0)))
|
|
162
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
163
|
+
return Object.freeze({ held, generation, changedAtMs: changedAtMs });
|
|
164
|
+
}
|
|
165
|
+
/** Sweep pages are content-free: target names, run identities and fixed outcome codes only. */
|
|
166
|
+
function fleetSweep(value, limit) {
|
|
167
|
+
let raw;
|
|
168
|
+
try {
|
|
169
|
+
raw = object(value, 262_144);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
173
|
+
}
|
|
174
|
+
workflowExact(raw, ['outcomes', 'nextCursor']);
|
|
175
|
+
if (!Array.isArray(raw['outcomes']) || raw['outcomes'].length > limit)
|
|
176
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
177
|
+
const outcomes = raw['outcomes'].map(entry => {
|
|
178
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry))
|
|
179
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
180
|
+
const failed = entry['outcome'] === 'failed';
|
|
181
|
+
workflowExact(entry, failed ? ['target', 'runId', 'outcome', 'code'] : ['target', 'runId', 'outcome']);
|
|
182
|
+
if (typeof entry['target'] !== 'string' || !/^[a-z][a-z0-9-]{0,31}$/.test(entry['target']) || typeof entry['runId'] !== 'string'
|
|
183
|
+
|| !/^[a-f0-9]{64}$/.test(entry['runId']) || (failed ? typeof entry['code'] !== 'string' || !/^[A-Z][A-Z_]{0,39}$/.test(entry['code'])
|
|
184
|
+
: !fleetOutcomes.has(String(entry['outcome']))))
|
|
185
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
186
|
+
return Object.freeze({ ...entry });
|
|
187
|
+
});
|
|
188
|
+
let nextCursor = null;
|
|
189
|
+
if (raw['nextCursor'] !== null) {
|
|
190
|
+
try {
|
|
191
|
+
nextCursor = object(raw['nextCursor'], 4_096);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return Object.freeze({ outcomes: Object.freeze(outcomes), nextCursor });
|
|
198
|
+
}
|
|
199
|
+
const migrationIdPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
200
|
+
const migrationActions = new Set(['keep', 'update', 'reset', 'accept', 'add', 'remove']);
|
|
201
|
+
const nodeIdPattern = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/;
|
|
202
|
+
const shortText = (value, maximum) => typeof value === 'string' && value.length <= maximum && !/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(value);
|
|
203
|
+
function migrationRecord(value) {
|
|
204
|
+
let raw;
|
|
205
|
+
try {
|
|
206
|
+
raw = object(value, 8_192);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
210
|
+
}
|
|
211
|
+
workflowExact(raw, ['id', 'description', 'fromVersion', 'toVersion', 'fromDigest', 'toDigest']);
|
|
212
|
+
if (typeof raw['id'] !== 'string' || !migrationIdPattern.test(raw['id']) || !shortText(raw['description'], 2_048)
|
|
213
|
+
|| typeof raw['fromVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['fromVersion'])
|
|
214
|
+
|| typeof raw['toVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['toVersion'])
|
|
215
|
+
|| typeof raw['fromDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['fromDigest'])
|
|
216
|
+
|| typeof raw['toDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['toDigest']) || raw['fromDigest'] === raw['toDigest'])
|
|
217
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
218
|
+
return freezeJson(raw);
|
|
219
|
+
}
|
|
220
|
+
function migrationPlan(value, runId, migrationId) {
|
|
221
|
+
let raw;
|
|
222
|
+
try {
|
|
223
|
+
raw = object(value, 262_144);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
227
|
+
}
|
|
228
|
+
workflowExact(raw, ['migrationId', 'format', 'runId', 'fromDigest', 'toDigest', 'entries', 'blockers', 'allowed']);
|
|
229
|
+
const entries = raw['entries'];
|
|
230
|
+
const blockers = raw['blockers'];
|
|
231
|
+
if (raw['migrationId'] !== migrationId || raw['runId'] !== runId || typeof raw['format'] !== 'string' || !/^[a-z0-9-]{1,32}$/.test(raw['format'])
|
|
232
|
+
|| typeof raw['fromDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['fromDigest']) || typeof raw['toDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['toDigest'])
|
|
233
|
+
|| typeof raw['allowed'] !== 'boolean' || !Array.isArray(entries) || entries.length > 512 || !Array.isArray(blockers) || blockers.length > 512
|
|
234
|
+
|| raw['allowed'] !== (blockers.length === 0))
|
|
235
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
236
|
+
for (const entry of entries) {
|
|
237
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry))
|
|
238
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
239
|
+
if (Object.keys(entry).some(key => !['action', 'target', 'source', 'status'].includes(key)) || !migrationActions.has(String(entry['action']))
|
|
240
|
+
|| (entry['target'] !== undefined && (typeof entry['target'] !== 'string' || !nodeIdPattern.test(entry['target'])))
|
|
241
|
+
|| (entry['source'] !== undefined && (typeof entry['source'] !== 'string' || !nodeIdPattern.test(entry['source'])))
|
|
242
|
+
|| (entry['status'] !== undefined && (typeof entry['status'] !== 'string' || !/^[a-z_]{1,32}$/.test(entry['status'])))
|
|
243
|
+
|| (entry['target'] === undefined && entry['source'] === undefined))
|
|
244
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
245
|
+
}
|
|
246
|
+
for (const blocker of blockers) {
|
|
247
|
+
if (blocker === null || typeof blocker !== 'object' || Array.isArray(blocker))
|
|
248
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
249
|
+
workflowExact(blocker, ['node', 'reason']);
|
|
250
|
+
if (typeof blocker['node'] !== 'string' || !(blocker['node'] === '*' || nodeIdPattern.test(blocker['node'])) || !shortText(blocker['reason'], 512) || !blocker['reason'])
|
|
251
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
252
|
+
}
|
|
253
|
+
return freezeJson(raw);
|
|
254
|
+
}
|
|
255
|
+
const settledStatuses = new Set(['succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown']);
|
|
256
|
+
function workflowIndexRecord(value, settled = false) {
|
|
257
|
+
let raw;
|
|
258
|
+
try {
|
|
259
|
+
raw = object(value, 4_096);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
263
|
+
}
|
|
264
|
+
workflowExact(raw, ['format', 'definitionId', 'definitionVersion', 'runId', 'revision', 'status', ...(settled ? ['settledAtMs'] : [])]);
|
|
265
|
+
if (settled && (!settledStatuses.has(raw['status']) || typeof raw['settledAtMs'] !== 'number' || !Number.isSafeInteger(raw['settledAtMs']) || raw['settledAtMs'] < 0))
|
|
266
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
267
|
+
if (![2, 3, 4, 5].includes(raw['format']) || typeof raw['definitionId'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(raw['definitionId'])
|
|
268
|
+
|| typeof raw['definitionVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['definitionVersion'])
|
|
269
|
+
|| typeof raw['runId'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['runId']) || typeof raw['revision'] !== 'number'
|
|
270
|
+
|| !Number.isSafeInteger(raw['revision']) || raw['revision'] < 1 || typeof raw['status'] !== 'string' || !workflowStatuses.has(raw['status']))
|
|
271
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
272
|
+
return freezeJson(raw);
|
|
273
|
+
}
|
|
274
|
+
async function bounded(operation, signal) {
|
|
275
|
+
if (signal.aborted) {
|
|
276
|
+
void Promise.resolve(operation).catch(() => { });
|
|
277
|
+
throw new HttpFailure(408, 'REQUEST_TIMEOUT');
|
|
278
|
+
}
|
|
279
|
+
assertActive(signal);
|
|
280
|
+
return await new Promise((resolve, reject) => {
|
|
281
|
+
const abort = () => { cleanup(); reject(new HttpFailure(408, 'REQUEST_TIMEOUT')); };
|
|
282
|
+
const cleanup = () => { signal.removeEventListener('abort', abort); };
|
|
283
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
284
|
+
Promise.resolve(operation).then(value => { cleanup(); resolve(value); }, (error) => { cleanup(); reject(error instanceof HttpFailure ? error : new HttpFailure(503, 'SERVICE_UNAVAILABLE')); });
|
|
285
|
+
if (signal.aborted)
|
|
286
|
+
abort();
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/** Authenticated Fetch facade. Hosting, TLS, durable execution, and token verification remain explicit. */
|
|
290
|
+
export function createAgentServer(options) {
|
|
291
|
+
const publicOrigin = origin(options.publicOrigin);
|
|
292
|
+
const origins = new Set((options.allowedOrigins ?? []).map(origin));
|
|
293
|
+
if (typeof options.authenticate !== 'function' || !Array.isArray(options.agents) || options.agents.length > 256)
|
|
294
|
+
throw new Error('Explicit authentication and a bounded agent registry are required.');
|
|
295
|
+
const authenticate = options.authenticate;
|
|
296
|
+
if (options.publicLiveness !== undefined && typeof options.publicLiveness !== 'boolean')
|
|
297
|
+
throw new Error('Public liveness must be explicit.');
|
|
298
|
+
if (options.inspector !== undefined && typeof options.inspector !== 'boolean')
|
|
299
|
+
throw new Error('The inspector setting must be a boolean.');
|
|
300
|
+
const limits = Object.freeze({ maxRuns: 512, maxRuntimes: 128, maxRequests: 64, maxStreams: 64,
|
|
301
|
+
maxBodyBytes: 1_048_576, maxResponseBytes: 4_194_304, maxHealthOperations: 32, maxHumanOperations: 32, maxWorkflowOperations: 32,
|
|
302
|
+
requestTimeoutMs: 10_000, streamDurationMs: 30_000, runRetentionMs: 600_000, ...options.limits });
|
|
303
|
+
if (Object.keys(limits).some(key => !['maxRuns', 'maxRuntimes', 'maxRequests', 'maxStreams', 'maxBodyBytes', 'maxResponseBytes', 'maxHealthOperations', 'maxHumanOperations', 'maxWorkflowOperations', 'requestTimeoutMs', 'streamDurationMs', 'runRetentionMs'].includes(key)))
|
|
304
|
+
throw new Error('Unknown server limit.');
|
|
305
|
+
for (const value of Object.values(limits))
|
|
306
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 16_777_216)
|
|
307
|
+
throw new Error('Server limits must be bounded positive integers.');
|
|
308
|
+
const healthChecks = (() => {
|
|
309
|
+
const supplied = options.healthChecks ?? [];
|
|
310
|
+
if (!Array.isArray(supplied) || supplied.length > 32)
|
|
311
|
+
throw new Error('Health checks must be a bounded dense list.');
|
|
312
|
+
const descriptors = Object.getOwnPropertyDescriptors(supplied);
|
|
313
|
+
if (Reflect.ownKeys(descriptors).length !== supplied.length + 1)
|
|
314
|
+
throw new Error('Health checks must be a bounded dense list.');
|
|
315
|
+
const ids = new Set();
|
|
316
|
+
const captured = [];
|
|
317
|
+
for (let index = 0; index < supplied.length; index++) {
|
|
318
|
+
const entry = descriptors[String(index)];
|
|
319
|
+
if (!entry || !('value' in entry) || entry.value === null || typeof entry.value !== 'object')
|
|
320
|
+
throw new Error('Health checks must contain data entries.');
|
|
321
|
+
const fields = Object.getOwnPropertyDescriptors(entry.value);
|
|
322
|
+
if (Reflect.ownKeys(fields).some(key => !['id', 'check'].includes(String(key))))
|
|
323
|
+
throw new Error('Health checks contain unknown fields.');
|
|
324
|
+
const id = fields['id'];
|
|
325
|
+
const check = fields['check'];
|
|
326
|
+
if (!id || !('value' in id) || typeof id.value !== 'string' || !identifier.test(id.value) || ids.has(id.value)
|
|
327
|
+
|| !check || !('value' in check) || typeof check.value !== 'function')
|
|
328
|
+
throw new Error('Health checks require unique IDs and callbacks.');
|
|
329
|
+
ids.add(id.value);
|
|
330
|
+
captured.push(Object.freeze({ id: id.value, check: check.value }));
|
|
331
|
+
}
|
|
332
|
+
return Object.freeze(captured);
|
|
333
|
+
})();
|
|
334
|
+
const humanRequests = (() => {
|
|
335
|
+
if (options.humanRequests === undefined)
|
|
336
|
+
return undefined;
|
|
337
|
+
if (options.humanRequests === null || typeof options.humanRequests !== 'object')
|
|
338
|
+
throw new Error('Human request transport is invalid.');
|
|
339
|
+
const fields = Object.getOwnPropertyDescriptors(options.humanRequests);
|
|
340
|
+
if (Reflect.ownKeys(fields).length !== 3 || ['list', 'inspect', 'respond'].some(key => !fields[key] || !('value' in fields[key]) || typeof fields[key].value !== 'function'))
|
|
341
|
+
throw new Error('Human request transport requires exact callbacks.');
|
|
342
|
+
return Object.freeze({ list: fields['list'].value, inspect: fields['inspect'].value, respond: fields['respond'].value });
|
|
343
|
+
})();
|
|
344
|
+
const workflowViews = (() => {
|
|
345
|
+
if (options.workflowViews === undefined)
|
|
346
|
+
return undefined;
|
|
347
|
+
if (options.workflowViews === null || typeof options.workflowViews !== 'object')
|
|
348
|
+
throw new Error('Workflow view transport is invalid.');
|
|
349
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowViews);
|
|
350
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['inspect'] || !('value' in fields['inspect']) || typeof fields['inspect'].value !== 'function')
|
|
351
|
+
throw new Error('Workflow view transport requires one exact inspect callback.');
|
|
352
|
+
return Object.freeze({ inspect: fields['inspect'].value });
|
|
353
|
+
})();
|
|
354
|
+
const workflowIndex = (() => {
|
|
355
|
+
if (options.workflowIndex === undefined)
|
|
356
|
+
return undefined;
|
|
357
|
+
if (options.workflowIndex === null || typeof options.workflowIndex !== 'object')
|
|
358
|
+
throw new Error('Workflow index transport is invalid.');
|
|
359
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowIndex);
|
|
360
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['list'] || !('value' in fields['list']) || typeof fields['list'].value !== 'function')
|
|
361
|
+
throw new Error('Workflow index transport requires one exact list callback.');
|
|
362
|
+
return Object.freeze({ list: fields['list'].value });
|
|
363
|
+
})();
|
|
364
|
+
const workflowControls = (() => {
|
|
365
|
+
if (options.workflowControls === undefined)
|
|
366
|
+
return undefined;
|
|
367
|
+
if (options.workflowControls === null || typeof options.workflowControls !== 'object')
|
|
368
|
+
throw new Error('Workflow control transport is invalid.');
|
|
369
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowControls);
|
|
370
|
+
if (Reflect.ownKeys(fields).length !== 2 || ['cancel', 'approve'].some(key => !fields[key] || !('value' in fields[key]) || typeof fields[key].value !== 'function'))
|
|
371
|
+
throw new Error('Workflow control transport requires exact cancel and approve callbacks.');
|
|
372
|
+
return Object.freeze({ cancel: fields['cancel'].value, approve: fields['approve'].value });
|
|
373
|
+
})();
|
|
374
|
+
const workflowSignals = (() => {
|
|
375
|
+
if (options.workflowSignals === undefined)
|
|
376
|
+
return undefined;
|
|
377
|
+
if (options.workflowSignals === null || typeof options.workflowSignals !== 'object')
|
|
378
|
+
throw new Error('Workflow signal transport is invalid.');
|
|
379
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowSignals);
|
|
380
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['deliver'] || !('value' in fields['deliver']) || typeof fields['deliver'].value !== 'function')
|
|
381
|
+
throw new Error('Workflow signal transport requires one exact deliver callback.');
|
|
382
|
+
return Object.freeze({ deliver: fields['deliver'].value });
|
|
383
|
+
})();
|
|
384
|
+
const workflowResumes = (() => {
|
|
385
|
+
if (options.workflowResumes === undefined)
|
|
386
|
+
return undefined;
|
|
387
|
+
if (options.workflowResumes === null || typeof options.workflowResumes !== 'object')
|
|
388
|
+
throw new Error('Workflow resume transport is invalid.');
|
|
389
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowResumes);
|
|
390
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['resume'] || !('value' in fields['resume']) || typeof fields['resume'].value !== 'function')
|
|
391
|
+
throw new Error('Workflow resume transport requires one exact resume callback.');
|
|
392
|
+
return Object.freeze({ resume: fields['resume'].value });
|
|
393
|
+
})();
|
|
394
|
+
const workflowPauses = (() => {
|
|
395
|
+
if (options.workflowPauses === undefined)
|
|
396
|
+
return undefined;
|
|
397
|
+
if (options.workflowPauses === null || typeof options.workflowPauses !== 'object')
|
|
398
|
+
throw new Error('Workflow pause transport is invalid.');
|
|
399
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowPauses);
|
|
400
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['pause'] || !('value' in fields['pause']) || typeof fields['pause'].value !== 'function')
|
|
401
|
+
throw new Error('Workflow pause transport requires one exact pause callback.');
|
|
402
|
+
return Object.freeze({ pause: fields['pause'].value });
|
|
403
|
+
})();
|
|
404
|
+
const workflowFleet = (() => {
|
|
405
|
+
if (options.workflowFleet === undefined)
|
|
406
|
+
return undefined;
|
|
407
|
+
if (options.workflowFleet === null || typeof options.workflowFleet !== 'object')
|
|
408
|
+
throw new Error('Workflow fleet transport is invalid.');
|
|
409
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowFleet);
|
|
410
|
+
const names = ['inspect', 'hold', 'release', 'sweep'];
|
|
411
|
+
if (Reflect.ownKeys(fields).length !== names.length || names.some(name => !fields[name] || !('value' in fields[name]) || typeof fields[name].value !== 'function'))
|
|
412
|
+
throw new Error('Workflow fleet transport requires exact inspect, hold, release and sweep callbacks.');
|
|
413
|
+
return Object.freeze(Object.fromEntries(names.map(name => [name, fields[name].value])));
|
|
414
|
+
})();
|
|
415
|
+
const workflowMigrations = (() => {
|
|
416
|
+
if (options.workflowMigrations === undefined)
|
|
417
|
+
return undefined;
|
|
418
|
+
if (options.workflowMigrations === null || typeof options.workflowMigrations !== 'object')
|
|
419
|
+
throw new Error('Workflow migration transport is invalid.');
|
|
420
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowMigrations);
|
|
421
|
+
const names = ['list', 'plan', 'apply'];
|
|
422
|
+
if (Reflect.ownKeys(fields).length !== names.length || names.some(name => !fields[name] || !('value' in fields[name]) || typeof fields[name].value !== 'function'))
|
|
423
|
+
throw new Error('Workflow migration transport requires exact list, plan and apply callbacks.');
|
|
424
|
+
return Object.freeze(Object.fromEntries(names.map(name => [name, fields[name].value])));
|
|
425
|
+
})();
|
|
426
|
+
const registry = new Map();
|
|
427
|
+
for (const config of options.agents) {
|
|
428
|
+
assertAgent(config.agent);
|
|
429
|
+
if (registry.has(config.agent.id))
|
|
430
|
+
throw new Error('Agent registry IDs must be unique.');
|
|
431
|
+
// Validate configuration now, not after accepting an HTTP command. No model work is performed.
|
|
432
|
+
const permissions = Object.freeze({ allow: Object.freeze([...config.permissions.allow]) });
|
|
433
|
+
const settings = config.limits === undefined ? {} : Object.freeze({ ...config.limits });
|
|
434
|
+
const check = createRuntime({ profile: 'ephemeral', permissions, limits: settings });
|
|
435
|
+
void check.close();
|
|
436
|
+
registry.set(config.agent.id, Object.freeze({ agent: config.agent, permissions, limits: settings }));
|
|
437
|
+
}
|
|
438
|
+
const toolCatalog = Object.freeze([...registry.values()].flatMap(config => config.agent.tools.map(tool => Object.freeze({
|
|
439
|
+
agentId: config.agent.id, agentVersion: config.agent.version, id: tool.id, version: tool.version,
|
|
440
|
+
effects: tool.effects, capabilities: tool.capabilities, timeoutMs: tool.timeoutMs, costMicros: tool.costMicros,
|
|
441
|
+
}))).sort((left, right) => left.agentId.localeCompare(right.agentId) || left.id.localeCompare(right.id) || left.version.localeCompare(right.version)));
|
|
442
|
+
const runtimes = new Map();
|
|
443
|
+
const runs = new Map();
|
|
444
|
+
// Same-process concurrent submissions share one journal claim and one run.
|
|
445
|
+
const pendingSubmissions = new Map();
|
|
446
|
+
const submissionJournal = (() => {
|
|
447
|
+
if (options.submissionJournal === undefined)
|
|
448
|
+
return undefined;
|
|
449
|
+
if (options.submissionJournal === null || typeof options.submissionJournal !== 'object' || typeof options.submissionJournal.claim !== 'function')
|
|
450
|
+
throw new Error('Submission journal requires a claim function.');
|
|
451
|
+
return Object.freeze({ claim: options.submissionJournal.claim.bind(options.submissionJournal) });
|
|
452
|
+
})();
|
|
453
|
+
const submissions = new Map();
|
|
454
|
+
// Runs retained per runtime; a runtime closes when its last retained run is released.
|
|
455
|
+
const retained = new Map();
|
|
456
|
+
const retentionTimers = new Set();
|
|
457
|
+
// Idempotency evidence for released runs: submission key -> request digest, oldest dropped past a fixed bound.
|
|
458
|
+
const tombstones = new Map();
|
|
459
|
+
const maxTombstones = 16_384;
|
|
460
|
+
const release = (entry) => {
|
|
461
|
+
if (runs.get(entry.handle.id) !== entry)
|
|
462
|
+
return;
|
|
463
|
+
runs.delete(entry.handle.id);
|
|
464
|
+
if (submissions.get(entry.submissionKey) === entry) {
|
|
465
|
+
submissions.delete(entry.submissionKey);
|
|
466
|
+
tombstones.delete(entry.submissionKey);
|
|
467
|
+
tombstones.set(entry.submissionKey, entry.digest);
|
|
468
|
+
if (tombstones.size > maxTombstones)
|
|
469
|
+
tombstones.delete(tombstones.keys().next().value);
|
|
470
|
+
}
|
|
471
|
+
const remaining = (retained.get(entry.runtimeKey) ?? 1) - 1;
|
|
472
|
+
if (remaining > 0) {
|
|
473
|
+
retained.set(entry.runtimeKey, remaining);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
retained.delete(entry.runtimeKey);
|
|
477
|
+
const runtime = runtimes.get(entry.runtimeKey);
|
|
478
|
+
if (runtime === entry.runtime) {
|
|
479
|
+
runtimes.delete(entry.runtimeKey);
|
|
480
|
+
void Promise.resolve().then(() => runtime.close()).catch(() => undefined);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
/** Release the oldest finished runs until a new run (and, when needed, a new runtime) fits. Active runs are never released. */
|
|
484
|
+
const makeRoom = (runtimeKey) => {
|
|
485
|
+
for (const entry of runs.values()) {
|
|
486
|
+
if (runs.size < limits.maxRuns && (runtimes.has(runtimeKey) || runtimes.size < limits.maxRuntimes))
|
|
487
|
+
return;
|
|
488
|
+
if (entry.finished && entry.collected)
|
|
489
|
+
release(entry);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const streams = new Set();
|
|
493
|
+
let closed = false;
|
|
494
|
+
let requests = 0;
|
|
495
|
+
let authentications = 0;
|
|
496
|
+
let healthOperations = 0;
|
|
497
|
+
let humanOperations = 0;
|
|
498
|
+
let workflowOperations = 0;
|
|
499
|
+
const humanRecord = (value, identity) => {
|
|
500
|
+
const raw = object(value, 16_384);
|
|
501
|
+
const allowed = ['id', 'agentId', 'kind', 'schemaId', 'schemaDigest', 'prompt', 'digest', 'status', 'context', 'subjectDigest', 'deadlineAtMs'];
|
|
502
|
+
if (Object.keys(raw).some(key => !allowed.includes(key)) || !['id', 'agentId', 'kind', 'schemaId', 'schemaDigest', 'prompt', 'digest', 'status'].every(key => Object.hasOwn(raw, key))
|
|
503
|
+
|| typeof raw['id'] !== 'string' || !humanIdentifier.test(raw['id']) || typeof raw['agentId'] !== 'string' || !identity.agentIds.includes(raw['agentId'])
|
|
504
|
+
|| !['information', 'correction', 'plan_selection'].includes(String(raw['kind'])) || typeof raw['schemaId'] !== 'string' || !identifier.test(raw['schemaId'])
|
|
505
|
+
|| typeof raw['schemaDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['schemaDigest']) || typeof raw['digest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['digest'])
|
|
506
|
+
|| typeof raw['prompt'] !== 'string' || encoder.encode(raw['prompt']).byteLength < 1 || encoder.encode(raw['prompt']).byteLength > 1_024
|
|
507
|
+
|| !['waiting', 'answered', 'cancelled', 'timed_out'].includes(String(raw['status']))
|
|
508
|
+
|| (raw['subjectDigest'] !== undefined && (typeof raw['subjectDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['subjectDigest'])))
|
|
509
|
+
|| ((raw['kind'] === 'correction') !== (raw['subjectDigest'] !== undefined))
|
|
510
|
+
|| (raw['deadlineAtMs'] !== undefined && (!Number.isSafeInteger(raw['deadlineAtMs']) || raw['deadlineAtMs'] < 0)))
|
|
511
|
+
throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
512
|
+
return freezeJson(raw);
|
|
513
|
+
};
|
|
514
|
+
const humanCall = async (callback, signal) => {
|
|
515
|
+
if (humanOperations >= limits.maxHumanOperations)
|
|
516
|
+
throw new HttpFailure(429, 'HUMAN_LIMIT');
|
|
517
|
+
humanOperations++;
|
|
518
|
+
const operation = Promise.resolve().then(callback).finally(() => { humanOperations--; });
|
|
519
|
+
try {
|
|
520
|
+
return await bounded(operation, signal);
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
524
|
+
throw error;
|
|
525
|
+
throw new HttpFailure(503, 'HUMAN_UNAVAILABLE');
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
const response = (value, status = 200, extra = {}) => {
|
|
529
|
+
let text;
|
|
530
|
+
try {
|
|
531
|
+
text = JSON.stringify(jsonValue(value, { maxBytes: limits.maxResponseBytes }));
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
return new Response('{"error":{"code":"RESPONSE_LIMIT"}}', { status: 503, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' } });
|
|
535
|
+
}
|
|
536
|
+
return new Response(text, { status, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', ...extra } });
|
|
537
|
+
};
|
|
538
|
+
const session = async (request, signal) => {
|
|
539
|
+
const authorization = request.headers.get('authorization') ?? '';
|
|
540
|
+
if (!/^Bearer [\x21-\x7e]{1,8192}$/.test(authorization))
|
|
541
|
+
throw new HttpFailure(401, 'UNAUTHORIZED');
|
|
542
|
+
let supplied;
|
|
543
|
+
assertActive(signal);
|
|
544
|
+
if (authentications >= limits.maxRequests)
|
|
545
|
+
throw new HttpFailure(429, 'AUTH_LIMIT');
|
|
546
|
+
authentications++;
|
|
547
|
+
const verification = Promise.resolve().then(() => {
|
|
548
|
+
assertActive(signal);
|
|
549
|
+
return authenticate(Object.freeze({ token: authorization.slice(7), signal }));
|
|
550
|
+
}).finally(() => { authentications--; });
|
|
551
|
+
// A non-cooperative verifier retains its admission until it really completes.
|
|
552
|
+
try {
|
|
553
|
+
supplied = await bounded(verification, signal);
|
|
554
|
+
}
|
|
555
|
+
catch {
|
|
556
|
+
assertActive(signal);
|
|
557
|
+
throw new HttpFailure(503, 'AUTH_UNAVAILABLE');
|
|
558
|
+
}
|
|
559
|
+
assertActive(signal);
|
|
560
|
+
try {
|
|
561
|
+
const raw = object(supplied, 65_536);
|
|
562
|
+
const scope = object(raw['scope']);
|
|
563
|
+
exact(raw, ['scope', 'agentIds', 'capabilities', 'expiresAtMs']);
|
|
564
|
+
exact(scope, ['principalId', 'projectId']);
|
|
565
|
+
if (typeof scope['principalId'] !== 'string' || !identifier.test(scope['principalId']) || typeof scope['projectId'] !== 'string' || !identifier.test(scope['projectId'])
|
|
566
|
+
|| !Array.isArray(raw['agentIds']) || raw['agentIds'].length > 256 || raw['agentIds'].some(id => typeof id !== 'string' || !identifier.test(id))
|
|
567
|
+
|| !Array.isArray(raw['capabilities']) || raw['capabilities'].length > 10 || raw['capabilities'].some(cap => !['runs:read', 'runs:submit', 'runs:cancel', 'operations:read', 'humans:read', 'humans:respond', 'workflows:read', 'workflows:control', 'workflows:fleet', 'workflows:migrate'].includes(String(cap)))
|
|
568
|
+
|| typeof raw['expiresAtMs'] !== 'number' || !Number.isSafeInteger(raw['expiresAtMs']) || raw['expiresAtMs'] <= Date.now())
|
|
569
|
+
throw new Error();
|
|
570
|
+
return freezeJson(raw);
|
|
571
|
+
}
|
|
572
|
+
catch {
|
|
573
|
+
throw new HttpFailure(401, 'UNAUTHORIZED');
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
const requireCapability = (identity, capability) => {
|
|
577
|
+
if (!identity.capabilities.includes(capability))
|
|
578
|
+
throw new HttpFailure(403, 'FORBIDDEN');
|
|
579
|
+
if (identity.expiresAtMs <= Date.now())
|
|
580
|
+
throw new HttpFailure(401, 'UNAUTHORIZED');
|
|
581
|
+
};
|
|
582
|
+
const body = async (request, signal) => {
|
|
583
|
+
if (!/^application\/json(?:\s*;\s*charset=utf-8)?$/i.test(request.headers.get('content-type') ?? '') || request.headers.has('content-encoding'))
|
|
584
|
+
throw new HttpFailure(415, 'UNSUPPORTED_MEDIA_TYPE');
|
|
585
|
+
const declared = request.headers.get('content-length');
|
|
586
|
+
if (declared !== null && (!/^\d+$/.test(declared) || Number(declared) > limits.maxBodyBytes))
|
|
587
|
+
throw new HttpFailure(413, 'BODY_LIMIT');
|
|
588
|
+
const reader = request.body?.getReader();
|
|
589
|
+
if (!reader)
|
|
590
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
591
|
+
const chunks = [];
|
|
592
|
+
let total = 0;
|
|
593
|
+
let complete = false;
|
|
594
|
+
try {
|
|
595
|
+
while (true) {
|
|
596
|
+
const item = await bounded(reader.read(), signal);
|
|
597
|
+
if (item.done) {
|
|
598
|
+
complete = true;
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
total += item.value.byteLength;
|
|
602
|
+
if (total > limits.maxBodyBytes)
|
|
603
|
+
throw new HttpFailure(413, 'BODY_LIMIT');
|
|
604
|
+
chunks.push(item.value);
|
|
605
|
+
}
|
|
606
|
+
const data = new Uint8Array(total);
|
|
607
|
+
let offset = 0;
|
|
608
|
+
for (const chunk of chunks) {
|
|
609
|
+
data.set(chunk, offset);
|
|
610
|
+
offset += chunk.byteLength;
|
|
611
|
+
}
|
|
612
|
+
try {
|
|
613
|
+
return object(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(data)), limits.maxBodyBytes);
|
|
614
|
+
}
|
|
615
|
+
catch {
|
|
616
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
finally {
|
|
620
|
+
if (!complete)
|
|
621
|
+
void reader.cancel().catch(() => { });
|
|
622
|
+
reader.releaseLock();
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
const eventResponse = (entry, after, identity, request) => {
|
|
626
|
+
if (closed)
|
|
627
|
+
throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
628
|
+
if (streams.size >= limits.maxStreams)
|
|
629
|
+
throw new HttpFailure(429, 'STREAM_LIMIT');
|
|
630
|
+
const controller = new AbortController();
|
|
631
|
+
const iterator = entry.handle.observe({ after, signal: controller.signal })[Symbol.asyncIterator]();
|
|
632
|
+
let sink;
|
|
633
|
+
let ended = false;
|
|
634
|
+
const finish = () => {
|
|
635
|
+
if (ended)
|
|
636
|
+
return;
|
|
637
|
+
ended = true;
|
|
638
|
+
controller.abort();
|
|
639
|
+
clearTimeout(timer);
|
|
640
|
+
streams.delete(finish);
|
|
641
|
+
request.signal.removeEventListener('abort', finish);
|
|
642
|
+
try {
|
|
643
|
+
sink.close();
|
|
644
|
+
}
|
|
645
|
+
catch { /* Consumer cancellation may already have closed the stream. */ }
|
|
646
|
+
void iterator.return?.().catch(() => { });
|
|
647
|
+
};
|
|
648
|
+
const timer = setTimeout(finish, Math.max(0, Math.min(limits.streamDurationMs, identity.expiresAtMs - Date.now())));
|
|
649
|
+
streams.add(finish);
|
|
650
|
+
const stream = new ReadableStream({
|
|
651
|
+
start(value) { sink = value; },
|
|
652
|
+
async pull(value) {
|
|
653
|
+
if (ended)
|
|
654
|
+
return;
|
|
655
|
+
try {
|
|
656
|
+
const next = await iterator.next();
|
|
657
|
+
if (ended)
|
|
658
|
+
return;
|
|
659
|
+
if (next.done) {
|
|
660
|
+
if (entry.finished)
|
|
661
|
+
entry.collected = true;
|
|
662
|
+
finish();
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
const event = JSON.stringify(jsonValue(next.value, { maxBytes: 16_384 }));
|
|
666
|
+
value.enqueue(encoder.encode(`id: ${next.value.sequence}\nevent: ${next.value.type}\ndata: ${event}\n\n`));
|
|
667
|
+
}
|
|
668
|
+
catch {
|
|
669
|
+
if (!ended)
|
|
670
|
+
value.enqueue(encoder.encode('event: stream.error\ndata: {"code":"OBSERVATION_FAILED"}\n\n'));
|
|
671
|
+
finish();
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
cancel() { finish(); },
|
|
675
|
+
}, { highWaterMark: 1 });
|
|
676
|
+
request.signal.addEventListener('abort', finish, { once: true });
|
|
677
|
+
if (request.signal.aborted)
|
|
678
|
+
finish();
|
|
679
|
+
return new Response(stream, { headers: { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'X-Accel-Buffering': 'no' } });
|
|
680
|
+
};
|
|
681
|
+
const route = async (request, signal) => {
|
|
682
|
+
const url = new URL(request.url);
|
|
683
|
+
if (url.origin !== publicOrigin || url.username || url.password || url.hash)
|
|
684
|
+
throw new HttpFailure(400, 'INVALID_DESTINATION');
|
|
685
|
+
// Console assets are static and data-free; module scripts carry an Origin header even when same-origin.
|
|
686
|
+
if (options.inspector === true && !url.search) {
|
|
687
|
+
const asset = inspectorAsset(request.method, url.pathname);
|
|
688
|
+
if (asset)
|
|
689
|
+
return asset;
|
|
690
|
+
}
|
|
691
|
+
const requestOrigin = request.headers.get('origin');
|
|
692
|
+
// With the console enabled, the server's own origin is a legitimate same-origin caller; others need allowedOrigins.
|
|
693
|
+
if (requestOrigin !== null && !origins.has(requestOrigin) && !(options.inspector === true && requestOrigin === publicOrigin))
|
|
694
|
+
throw new HttpFailure(403, 'ORIGIN_DENIED');
|
|
695
|
+
// A preflight is validated as the request it announces: the same query rules apply, so query credentials still fail,
|
|
696
|
+
// but a legitimate paginated GET can be preflighted.
|
|
697
|
+
const effectiveMethod = request.method === 'OPTIONS' ? request.headers.get('access-control-request-method') ?? '' : request.method;
|
|
698
|
+
const eventMatch = /^\/v1\/runs\/([a-f0-9-]{36})\/events$/.exec(url.pathname);
|
|
699
|
+
const catalogQuery = effectiveMethod === 'GET' && url.pathname === '/v1/tools';
|
|
700
|
+
const humanListQuery = effectiveMethod === 'GET' && url.pathname === '/v1/human-requests';
|
|
701
|
+
const workflowListQuery = effectiveMethod === 'GET' && url.pathname === '/v1/workflow-runs';
|
|
702
|
+
if ([...url.searchParams.keys()].some(key => effectiveMethod !== 'GET' || (eventMatch ? key !== 'after' : catalogQuery || humanListQuery ? !['after', 'limit'].includes(key) : workflowListQuery ? !['after', 'limit', 'view'].includes(key) : true))
|
|
703
|
+
|| url.searchParams.getAll('after').length > 1 || url.searchParams.getAll('limit').length > 1 || url.searchParams.getAll('view').length > 1)
|
|
704
|
+
throw new HttpFailure(400, 'INVALID_QUERY');
|
|
705
|
+
if (request.method === 'OPTIONS') {
|
|
706
|
+
if (!requestOrigin || !['GET', 'POST'].includes(request.headers.get('access-control-request-method') ?? ''))
|
|
707
|
+
throw new HttpFailure(403, 'ORIGIN_DENIED');
|
|
708
|
+
const headers = (request.headers.get('access-control-request-headers') ?? '').toLowerCase().split(',').map(value => value.trim()).filter(Boolean);
|
|
709
|
+
if (headers.some(value => !['authorization', 'content-type', 'idempotency-key'].includes(value)))
|
|
710
|
+
throw new HttpFailure(403, 'ORIGIN_DENIED');
|
|
711
|
+
return new Response(null, { status: 204, headers: { 'Access-Control-Allow-Methods': 'GET, POST', 'Access-Control-Allow-Headers': 'Authorization, Content-Type, Idempotency-Key' } });
|
|
712
|
+
}
|
|
713
|
+
if (request.method === 'GET' && url.pathname === '/healthz' && options.publicLiveness === true)
|
|
714
|
+
return response({ status: 'ok' });
|
|
715
|
+
const identity = await session(request, signal);
|
|
716
|
+
if (closed)
|
|
717
|
+
throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
718
|
+
const owner = canonical(identity.scope);
|
|
719
|
+
if (workflowListQuery) {
|
|
720
|
+
requireCapability(identity, 'workflows:read');
|
|
721
|
+
if (!workflowIndex)
|
|
722
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
723
|
+
const after = url.searchParams.get('after');
|
|
724
|
+
const limitText = url.searchParams.get('limit') ?? '20';
|
|
725
|
+
if ((after !== null && !/^[A-Za-z0-9._:-]{1,128}$/.test(after)) || !/^\d+$/.test(limitText))
|
|
726
|
+
throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
727
|
+
const limit = Number(limitText);
|
|
728
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100)
|
|
729
|
+
throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
730
|
+
const view = url.searchParams.get('view') ?? 'active';
|
|
731
|
+
if (view !== 'active' && view !== 'settled')
|
|
732
|
+
throw new HttpFailure(400, 'INVALID_QUERY');
|
|
733
|
+
const settled = view === 'settled';
|
|
734
|
+
if (workflowOperations >= limits.maxWorkflowOperations)
|
|
735
|
+
throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
736
|
+
workflowOperations++;
|
|
737
|
+
const operation = Promise.resolve().then(() => workflowIndex.list(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
738
|
+
after, limit, signal, ...(settled ? { view: 'settled' } : {}) }))).finally(() => { workflowOperations--; });
|
|
739
|
+
let supplied;
|
|
740
|
+
try {
|
|
741
|
+
supplied = await bounded(operation, signal);
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
745
|
+
throw error;
|
|
746
|
+
throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE');
|
|
747
|
+
}
|
|
748
|
+
let page;
|
|
749
|
+
try {
|
|
750
|
+
page = object(supplied, 524_288);
|
|
751
|
+
}
|
|
752
|
+
catch {
|
|
753
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
754
|
+
}
|
|
755
|
+
workflowExact(page, ['items', 'next']);
|
|
756
|
+
if (!Array.isArray(page['items']) || page['items'].length > limit || (page['next'] !== null
|
|
757
|
+
&& (typeof page['next'] !== 'string' || !/^[A-Za-z0-9._:-]{1,128}$/.test(page['next']) || page['next'] === after)))
|
|
758
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
759
|
+
const items = page['items'].map(item => workflowIndexRecord(item, settled));
|
|
760
|
+
if (new Set(items.map(item => item.runId)).size !== items.length)
|
|
761
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
762
|
+
assertActive(signal);
|
|
763
|
+
requireCapability(identity, 'workflows:read');
|
|
764
|
+
return response({ items, next: page['next'] });
|
|
765
|
+
}
|
|
766
|
+
const fleetMatch = /^\/v1\/workflow-fleet(?:\/(hold|release|sweeps\/pause|sweeps\/resume))?$/.exec(url.pathname);
|
|
767
|
+
if (fleetMatch && request.method === (fleetMatch[1] === undefined ? 'GET' : 'POST')) {
|
|
768
|
+
const action = fleetMatch[1] ?? 'inspect';
|
|
769
|
+
const capability = action === 'inspect' ? 'workflows:read' : 'workflows:fleet';
|
|
770
|
+
requireCapability(identity, capability);
|
|
771
|
+
if (!workflowFleet)
|
|
772
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
773
|
+
let cursor = null;
|
|
774
|
+
let limit = 0;
|
|
775
|
+
const sweep = action.startsWith('sweeps/');
|
|
776
|
+
if (action !== 'inspect') {
|
|
777
|
+
const data = await body(request, signal);
|
|
778
|
+
if (!sweep)
|
|
779
|
+
exact(data, []);
|
|
780
|
+
else {
|
|
781
|
+
exact(data, ['cursor', 'limit']);
|
|
782
|
+
if (typeof data['limit'] !== 'number' || !Number.isSafeInteger(data['limit']) || data['limit'] < 1 || data['limit'] > 128)
|
|
783
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
784
|
+
limit = data['limit'];
|
|
785
|
+
if (data['cursor'] !== null)
|
|
786
|
+
cursor = object(data['cursor'], 4_096);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (workflowOperations >= limits.maxWorkflowOperations)
|
|
790
|
+
throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
791
|
+
workflowOperations++;
|
|
792
|
+
const base = Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, actorId: identity.scope.principalId, signal });
|
|
793
|
+
const call = () => action === 'inspect' ? workflowFleet.inspect(base) : action === 'hold' ? workflowFleet.hold(base)
|
|
794
|
+
: action === 'release' ? workflowFleet.release(base)
|
|
795
|
+
: workflowFleet.sweep(Object.freeze({ ...base, phase: action === 'sweeps/pause' ? 'pause' : 'resume', cursor, limit }));
|
|
796
|
+
const operation = Promise.resolve().then(call).finally(() => { workflowOperations--; });
|
|
797
|
+
let result;
|
|
798
|
+
try {
|
|
799
|
+
result = await bounded(operation, signal);
|
|
800
|
+
}
|
|
801
|
+
catch (error) {
|
|
802
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
803
|
+
throw error;
|
|
804
|
+
throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE');
|
|
805
|
+
}
|
|
806
|
+
assertActive(signal);
|
|
807
|
+
requireCapability(identity, capability);
|
|
808
|
+
if (sweep) {
|
|
809
|
+
let raw;
|
|
810
|
+
try {
|
|
811
|
+
raw = object(result, 262_144);
|
|
812
|
+
}
|
|
813
|
+
catch {
|
|
814
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
815
|
+
}
|
|
816
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1)
|
|
817
|
+
throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
818
|
+
workflowExact(raw, ['status', 'sweep']);
|
|
819
|
+
if (raw['status'] !== 'applied')
|
|
820
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
821
|
+
return response({ sweep: fleetSweep(raw['sweep'], limit) });
|
|
822
|
+
}
|
|
823
|
+
const fleet = fleetHold(result);
|
|
824
|
+
if ((action === 'hold' && !fleet.held) || (action === 'release' && fleet.held))
|
|
825
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
826
|
+
return response({ fleet });
|
|
827
|
+
}
|
|
828
|
+
const workflowMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})$/.exec(url.pathname);
|
|
829
|
+
if (workflowMatch && request.method === 'GET') {
|
|
830
|
+
requireCapability(identity, 'workflows:read');
|
|
831
|
+
if (!workflowViews)
|
|
832
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
833
|
+
if (workflowOperations >= limits.maxWorkflowOperations)
|
|
834
|
+
throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
835
|
+
workflowOperations++;
|
|
836
|
+
const operation = Promise.resolve().then(() => workflowViews.inspect(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
837
|
+
runId: workflowMatch[1], signal }))).finally(() => { workflowOperations--; });
|
|
838
|
+
let item;
|
|
839
|
+
try {
|
|
840
|
+
item = await bounded(operation, signal);
|
|
841
|
+
}
|
|
842
|
+
catch (error) {
|
|
843
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
844
|
+
throw error;
|
|
845
|
+
throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE');
|
|
846
|
+
}
|
|
847
|
+
if (item === null)
|
|
848
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
849
|
+
const record = workflowRecord(item, workflowMatch[1]);
|
|
850
|
+
assertActive(signal);
|
|
851
|
+
requireCapability(identity, 'workflows:read');
|
|
852
|
+
return response({ workflow: record });
|
|
853
|
+
}
|
|
854
|
+
const workflowControlMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/(cancel|approvals)$/.exec(url.pathname);
|
|
855
|
+
if (workflowControlMatch && request.method === 'POST') {
|
|
856
|
+
requireCapability(identity, 'workflows:control');
|
|
857
|
+
if (!workflowControls)
|
|
858
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
859
|
+
const data = await body(request, signal);
|
|
860
|
+
const action = workflowControlMatch[2];
|
|
861
|
+
const fields = action === 'cancel' ? ['commandId', 'revision'] : ['commandId', 'revision', 'nodeId', 'approvalDigest', 'childRunId'];
|
|
862
|
+
exact(data, fields);
|
|
863
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
864
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1)
|
|
865
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
866
|
+
if (action === 'approvals' && (typeof data['nodeId'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(data['nodeId'])
|
|
867
|
+
|| typeof data['approvalDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(data['approvalDigest'])
|
|
868
|
+
|| (data['childRunId'] !== null && (typeof data['childRunId'] !== 'string' || !/^[a-f0-9]{64}$/.test(data['childRunId'])))))
|
|
869
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
870
|
+
if (workflowOperations >= limits.maxWorkflowOperations)
|
|
871
|
+
throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
872
|
+
workflowOperations++;
|
|
873
|
+
const common = { scope: identity.scope, agentIds: identity.agentIds, actorId: identity.scope.principalId, runId: workflowControlMatch[1],
|
|
874
|
+
revision: data['revision'], commandId: data['commandId'], signal };
|
|
875
|
+
const operation = Promise.resolve().then(() => action === 'cancel' ? workflowControls.cancel(Object.freeze(common))
|
|
876
|
+
: workflowControls.approve(Object.freeze({ ...common, nodeId: data['nodeId'], approvalDigest: data['approvalDigest'],
|
|
877
|
+
childRunId: data['childRunId'] }))).finally(() => { workflowOperations--; });
|
|
878
|
+
let result;
|
|
879
|
+
try {
|
|
880
|
+
result = await bounded(operation, signal);
|
|
881
|
+
}
|
|
882
|
+
catch (error) {
|
|
883
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
884
|
+
throw error;
|
|
885
|
+
throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE');
|
|
886
|
+
}
|
|
887
|
+
assertActive(signal);
|
|
888
|
+
requireCapability(identity, 'workflows:control');
|
|
889
|
+
let raw;
|
|
890
|
+
try {
|
|
891
|
+
raw = object(result, 262_144);
|
|
892
|
+
}
|
|
893
|
+
catch {
|
|
894
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
895
|
+
}
|
|
896
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1)
|
|
897
|
+
throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
898
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1)
|
|
899
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
900
|
+
workflowExact(raw, ['status', 'workflow']);
|
|
901
|
+
if (raw['status'] !== 'applied')
|
|
902
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
903
|
+
const record = workflowRecord(raw['workflow'], workflowControlMatch[1]);
|
|
904
|
+
if (record.revision < data['revision'])
|
|
905
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
906
|
+
return response({ workflow: record });
|
|
907
|
+
}
|
|
908
|
+
const workflowSignalMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/signals$/.exec(url.pathname);
|
|
909
|
+
if (workflowSignalMatch && request.method === 'POST') {
|
|
910
|
+
requireCapability(identity, 'workflows:control');
|
|
911
|
+
if (!workflowSignals)
|
|
912
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
913
|
+
const data = await body(request, signal);
|
|
914
|
+
exact(data, ['commandId', 'revision', 'signalId', 'signalName', 'value']);
|
|
915
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
916
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1 || typeof data['signalId'] !== 'string' || !identifier.test(data['signalId'])
|
|
917
|
+
|| typeof data['signalName'] !== 'string' || !identifier.test(data['signalName']))
|
|
918
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
919
|
+
let value;
|
|
920
|
+
try {
|
|
921
|
+
value = freezeJson(jsonValue(data['value'], { maxBytes: 4_096, maxDepth: 16, maxNodes: 1_024 }));
|
|
922
|
+
}
|
|
923
|
+
catch {
|
|
924
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
925
|
+
}
|
|
926
|
+
if (workflowOperations >= limits.maxWorkflowOperations)
|
|
927
|
+
throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
928
|
+
workflowOperations++;
|
|
929
|
+
const operation = Promise.resolve().then(() => workflowSignals.deliver(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
930
|
+
actorId: identity.scope.principalId, runId: workflowSignalMatch[1], revision: data['revision'],
|
|
931
|
+
commandId: data['commandId'], signalId: data['signalId'], signalName: data['signalName'],
|
|
932
|
+
value, signal }))).finally(() => { workflowOperations--; });
|
|
933
|
+
let result;
|
|
934
|
+
try {
|
|
935
|
+
result = await bounded(operation, signal);
|
|
936
|
+
}
|
|
937
|
+
catch (error) {
|
|
938
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
939
|
+
throw error;
|
|
940
|
+
throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE');
|
|
941
|
+
}
|
|
942
|
+
assertActive(signal);
|
|
943
|
+
requireCapability(identity, 'workflows:control');
|
|
944
|
+
let raw;
|
|
945
|
+
try {
|
|
946
|
+
raw = object(result, 262_144);
|
|
947
|
+
}
|
|
948
|
+
catch {
|
|
949
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
950
|
+
}
|
|
951
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1)
|
|
952
|
+
throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
953
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1)
|
|
954
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
955
|
+
workflowExact(raw, ['status', 'workflow']);
|
|
956
|
+
if (raw['status'] !== 'applied')
|
|
957
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
958
|
+
const record = workflowRecord(raw['workflow'], workflowSignalMatch[1]);
|
|
959
|
+
if (record.revision < data['revision'])
|
|
960
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
961
|
+
return response({ workflow: record });
|
|
962
|
+
}
|
|
963
|
+
const migrationMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/migrations(?:\/([A-Za-z0-9][A-Za-z0-9._-]{0,127}))?$/.exec(url.pathname);
|
|
964
|
+
if (migrationMatch && (request.method === 'GET' || (request.method === 'POST' && migrationMatch[2] !== undefined))) {
|
|
965
|
+
const runId = migrationMatch[1];
|
|
966
|
+
const migrationId = migrationMatch[2];
|
|
967
|
+
const capability = request.method === 'POST' ? 'workflows:migrate' : 'workflows:read';
|
|
968
|
+
requireCapability(identity, capability);
|
|
969
|
+
if (!workflowMigrations)
|
|
970
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
971
|
+
let data;
|
|
972
|
+
if (request.method === 'POST') {
|
|
973
|
+
data = await body(request, signal);
|
|
974
|
+
exact(data, ['commandId', 'revision']);
|
|
975
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
976
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1)
|
|
977
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
978
|
+
}
|
|
979
|
+
if (workflowOperations >= limits.maxWorkflowOperations)
|
|
980
|
+
throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
981
|
+
workflowOperations++;
|
|
982
|
+
const base = { scope: identity.scope, agentIds: identity.agentIds, runId, signal };
|
|
983
|
+
const operation = Promise.resolve().then(() => migrationId === undefined ? workflowMigrations.list(Object.freeze(base))
|
|
984
|
+
: data === undefined ? workflowMigrations.plan(Object.freeze({ ...base, migrationId }))
|
|
985
|
+
: workflowMigrations.apply(Object.freeze({ ...base, actorId: identity.scope.principalId, revision: data['revision'],
|
|
986
|
+
commandId: data['commandId'], migrationId }))).finally(() => { workflowOperations--; });
|
|
987
|
+
let result;
|
|
988
|
+
try {
|
|
989
|
+
result = await bounded(operation, signal);
|
|
990
|
+
}
|
|
991
|
+
catch (error) {
|
|
992
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
993
|
+
throw error;
|
|
994
|
+
throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE');
|
|
995
|
+
}
|
|
996
|
+
assertActive(signal);
|
|
997
|
+
requireCapability(identity, capability);
|
|
998
|
+
if (migrationId === undefined) {
|
|
999
|
+
if (result === null)
|
|
1000
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1001
|
+
if (!Array.isArray(result) || result.length > 256)
|
|
1002
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1003
|
+
const migrations = result.map(migrationRecord);
|
|
1004
|
+
if (new Set(migrations.map(item => item.id)).size !== migrations.length)
|
|
1005
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1006
|
+
return response({ migrations });
|
|
1007
|
+
}
|
|
1008
|
+
if (data === undefined) {
|
|
1009
|
+
if (result === null)
|
|
1010
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1011
|
+
return response({ plan: migrationPlan(result, runId, migrationId) });
|
|
1012
|
+
}
|
|
1013
|
+
let raw;
|
|
1014
|
+
try {
|
|
1015
|
+
raw = object(result, 524_288);
|
|
1016
|
+
}
|
|
1017
|
+
catch {
|
|
1018
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1019
|
+
}
|
|
1020
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1)
|
|
1021
|
+
throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
1022
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1)
|
|
1023
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1024
|
+
if (raw['status'] === 'refused') {
|
|
1025
|
+
workflowExact(raw, ['status', 'plan']);
|
|
1026
|
+
const plan = migrationPlan(raw['plan'], runId, migrationId);
|
|
1027
|
+
if (plan.allowed)
|
|
1028
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1029
|
+
return response({ plan }, 409);
|
|
1030
|
+
}
|
|
1031
|
+
workflowExact(raw, ['status', 'plan', 'workflow']);
|
|
1032
|
+
if (raw['status'] !== 'applied')
|
|
1033
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1034
|
+
const plan = migrationPlan(raw['plan'], runId, migrationId);
|
|
1035
|
+
const record = workflowRecord(raw['workflow'], runId);
|
|
1036
|
+
if (!plan.allowed || record.revision <= data['revision'])
|
|
1037
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1038
|
+
return response({ plan, workflow: record });
|
|
1039
|
+
}
|
|
1040
|
+
// Continuation and operator pause share one exact revision-bound body; each has its own least-authority adapter.
|
|
1041
|
+
const workflowResumeMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/(resume|pause)$/.exec(url.pathname);
|
|
1042
|
+
if (workflowResumeMatch && request.method === 'POST') {
|
|
1043
|
+
requireCapability(identity, 'workflows:control');
|
|
1044
|
+
const callback = workflowResumeMatch[2] === 'pause' ? workflowPauses?.pause : workflowResumes?.resume;
|
|
1045
|
+
if (!callback)
|
|
1046
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1047
|
+
const data = await body(request, signal);
|
|
1048
|
+
exact(data, ['commandId', 'revision']);
|
|
1049
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
1050
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1)
|
|
1051
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
1052
|
+
if (workflowOperations >= limits.maxWorkflowOperations)
|
|
1053
|
+
throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
1054
|
+
workflowOperations++;
|
|
1055
|
+
const operation = Promise.resolve().then(() => callback(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
1056
|
+
actorId: identity.scope.principalId, runId: workflowResumeMatch[1], revision: data['revision'],
|
|
1057
|
+
commandId: data['commandId'], signal }))).finally(() => { workflowOperations--; });
|
|
1058
|
+
let result;
|
|
1059
|
+
try {
|
|
1060
|
+
result = await bounded(operation, signal);
|
|
1061
|
+
}
|
|
1062
|
+
catch (error) {
|
|
1063
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
1064
|
+
throw error;
|
|
1065
|
+
throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE');
|
|
1066
|
+
}
|
|
1067
|
+
assertActive(signal);
|
|
1068
|
+
requireCapability(identity, 'workflows:control');
|
|
1069
|
+
let raw;
|
|
1070
|
+
try {
|
|
1071
|
+
raw = object(result, 262_144);
|
|
1072
|
+
}
|
|
1073
|
+
catch {
|
|
1074
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1075
|
+
}
|
|
1076
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1)
|
|
1077
|
+
throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
1078
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1)
|
|
1079
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1080
|
+
workflowExact(raw, ['status', 'workflow']);
|
|
1081
|
+
if (raw['status'] !== 'applied')
|
|
1082
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1083
|
+
const record = workflowRecord(raw['workflow'], workflowResumeMatch[1]);
|
|
1084
|
+
if (record.revision < data['revision'])
|
|
1085
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
1086
|
+
return response({ workflow: record });
|
|
1087
|
+
}
|
|
1088
|
+
if (request.method === 'GET' && url.pathname === '/v1/agents') {
|
|
1089
|
+
requireCapability(identity, 'runs:read');
|
|
1090
|
+
return response({ agents: [...registry.values()].filter(config => identity.agentIds.includes(config.agent.id)).map(config => ({ id: config.agent.id, version: config.agent.version })) });
|
|
1091
|
+
}
|
|
1092
|
+
if (request.method === 'GET' && url.pathname === '/v1/operations/health') {
|
|
1093
|
+
requireCapability(identity, 'operations:read');
|
|
1094
|
+
const results = await Promise.all(healthChecks.map(async (health) => {
|
|
1095
|
+
if (healthOperations >= limits.maxHealthOperations)
|
|
1096
|
+
return { id: health.id, status: 'unavailable' };
|
|
1097
|
+
healthOperations++;
|
|
1098
|
+
const operation = Promise.resolve().then(() => health.check(Object.freeze({ signal, scope: identity.scope })))
|
|
1099
|
+
.finally(() => { healthOperations--; });
|
|
1100
|
+
try {
|
|
1101
|
+
return { id: health.id, status: await bounded(operation, signal) === true ? 'ready' : 'unavailable' };
|
|
1102
|
+
}
|
|
1103
|
+
catch {
|
|
1104
|
+
return { id: health.id, status: 'unavailable' };
|
|
1105
|
+
}
|
|
1106
|
+
}));
|
|
1107
|
+
assertActive(signal);
|
|
1108
|
+
requireCapability(identity, 'operations:read');
|
|
1109
|
+
const checks = [{ id: 'server', status: 'ready' }, ...results];
|
|
1110
|
+
const ready = checks.every(check => check.status === 'ready');
|
|
1111
|
+
return response({ status: ready ? 'ready' : 'degraded', checks }, ready ? 200 : 503);
|
|
1112
|
+
}
|
|
1113
|
+
if (request.method === 'GET' && url.pathname === '/v1/tools') {
|
|
1114
|
+
requireCapability(identity, 'operations:read');
|
|
1115
|
+
const afterText = url.searchParams.get('after') ?? '0';
|
|
1116
|
+
const limitText = url.searchParams.get('limit') ?? '50';
|
|
1117
|
+
if (!/^\d+$/.test(afterText) || !/^\d+$/.test(limitText))
|
|
1118
|
+
throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
1119
|
+
const after = Number(afterText);
|
|
1120
|
+
const limit = Number(limitText);
|
|
1121
|
+
if (!Number.isSafeInteger(after) || !Number.isSafeInteger(limit) || limit < 1 || limit > 100)
|
|
1122
|
+
throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
1123
|
+
const visible = toolCatalog.filter(tool => identity.agentIds.includes(tool.agentId));
|
|
1124
|
+
if (after > visible.length)
|
|
1125
|
+
throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
1126
|
+
const tools = visible.slice(after, after + limit);
|
|
1127
|
+
const next = after + tools.length;
|
|
1128
|
+
return response({ tools, next: next < visible.length ? next : null });
|
|
1129
|
+
}
|
|
1130
|
+
if (request.method === 'GET' && url.pathname === '/v1/human-requests') {
|
|
1131
|
+
requireCapability(identity, 'humans:read');
|
|
1132
|
+
if (!humanRequests)
|
|
1133
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1134
|
+
const after = url.searchParams.get('after');
|
|
1135
|
+
const limitText = url.searchParams.get('limit') ?? '50';
|
|
1136
|
+
if ((after !== null && !/^[A-Za-z0-9._:-]{1,128}$/.test(after)) || !/^\d+$/.test(limitText) || Number(limitText) < 1 || Number(limitText) > 100)
|
|
1137
|
+
throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
1138
|
+
const page = await humanCall(() => humanRequests.list(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, after, limit: Number(limitText), signal })), signal);
|
|
1139
|
+
const raw = object(page, 1_048_576);
|
|
1140
|
+
exact(raw, ['items', 'next']);
|
|
1141
|
+
if (!Array.isArray(raw['items']) || raw['items'].length > Number(limitText) || (raw['next'] !== null && (typeof raw['next'] !== 'string' || !/^[A-Za-z0-9._:-]{1,128}$/.test(raw['next']))))
|
|
1142
|
+
throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
1143
|
+
const items = raw['items'].map(item => humanRecord(item, identity));
|
|
1144
|
+
if (new Set(items.map(item => item.id)).size !== items.length)
|
|
1145
|
+
throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
1146
|
+
assertActive(signal);
|
|
1147
|
+
requireCapability(identity, 'humans:read');
|
|
1148
|
+
return response({ items, next: raw['next'] });
|
|
1149
|
+
}
|
|
1150
|
+
const humanMatch = /^\/v1\/human-requests\/([A-Za-z0-9][A-Za-z0-9._-]{0,79})(?:\/responses)?$/.exec(url.pathname);
|
|
1151
|
+
if (humanMatch && request.method === 'GET' && !url.pathname.endsWith('/responses')) {
|
|
1152
|
+
requireCapability(identity, 'humans:read');
|
|
1153
|
+
if (!humanRequests)
|
|
1154
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1155
|
+
const item = await humanCall(() => humanRequests.inspect(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, id: humanMatch[1], signal })), signal);
|
|
1156
|
+
if (item === null)
|
|
1157
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1158
|
+
const record = humanRecord(item, identity);
|
|
1159
|
+
if (record.id !== humanMatch[1])
|
|
1160
|
+
throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
1161
|
+
assertActive(signal);
|
|
1162
|
+
requireCapability(identity, 'humans:read');
|
|
1163
|
+
return response({ request: record });
|
|
1164
|
+
}
|
|
1165
|
+
if (humanMatch && request.method === 'POST' && url.pathname.endsWith('/responses')) {
|
|
1166
|
+
requireCapability(identity, 'humans:respond');
|
|
1167
|
+
if (!humanRequests)
|
|
1168
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1169
|
+
const data = await body(request, signal);
|
|
1170
|
+
exact(data, ['commandId', 'requestDigest', 'value']);
|
|
1171
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['requestDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(data['requestDigest']))
|
|
1172
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
1173
|
+
const item = await humanCall(() => humanRequests.respond(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, actorId: identity.scope.principalId,
|
|
1174
|
+
id: humanMatch[1], commandId: data['commandId'], requestDigest: data['requestDigest'], value: data['value'], signal })), signal);
|
|
1175
|
+
const record = humanRecord(item, identity);
|
|
1176
|
+
if (record.id !== humanMatch[1] || record.digest !== data['requestDigest'] || record.status === 'waiting')
|
|
1177
|
+
throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
1178
|
+
assertActive(signal);
|
|
1179
|
+
requireCapability(identity, 'humans:respond');
|
|
1180
|
+
return response({ request: record });
|
|
1181
|
+
}
|
|
1182
|
+
if (request.method === 'POST' && url.pathname === '/v1/runs') {
|
|
1183
|
+
requireCapability(identity, 'runs:submit');
|
|
1184
|
+
const key = request.headers.get('idempotency-key') ?? '';
|
|
1185
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(key))
|
|
1186
|
+
throw new HttpFailure(400, 'IDEMPOTENCY_REQUIRED');
|
|
1187
|
+
const data = await body(request, signal);
|
|
1188
|
+
exact(data, ['agentId', 'input']);
|
|
1189
|
+
const agentId = data['agentId'];
|
|
1190
|
+
if (typeof agentId !== 'string' || !identity.agentIds.includes(agentId) || !registry.has(agentId))
|
|
1191
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1192
|
+
const config = registry.get(agentId);
|
|
1193
|
+
const digestBytes = await crypto.subtle.digest('SHA-256', encoder.encode(canonical({ agentId, version: config.agent.version, input: data['input'] })));
|
|
1194
|
+
const digest = [...new Uint8Array(digestBytes)].map(value => value.toString(16).padStart(2, '0')).join('');
|
|
1195
|
+
assertActive(signal);
|
|
1196
|
+
requireCapability(identity, 'runs:submit');
|
|
1197
|
+
if (closed)
|
|
1198
|
+
throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
1199
|
+
const submissionKey = JSON.stringify([owner, key]);
|
|
1200
|
+
const previous = submissions.get(submissionKey) ?? await pendingSubmissions.get(submissionKey);
|
|
1201
|
+
if (previous === 'duplicate')
|
|
1202
|
+
throw new HttpFailure(409, 'SUBMISSION_OUTCOME_UNKNOWN');
|
|
1203
|
+
if (previous) {
|
|
1204
|
+
if (previous.digest !== digest)
|
|
1205
|
+
throw new HttpFailure(409, 'IDEMPOTENCY_CONFLICT');
|
|
1206
|
+
return response({ id: previous.handle.id, profile: 'ephemeral' }, 200);
|
|
1207
|
+
}
|
|
1208
|
+
const expired = tombstones.get(submissionKey);
|
|
1209
|
+
if (expired !== undefined)
|
|
1210
|
+
throw new HttpFailure(expired === digest ? 410 : 409, expired === digest ? 'RUN_EXPIRED' : 'IDEMPOTENCY_CONFLICT');
|
|
1211
|
+
const runtimeKey = JSON.stringify([owner, agentId]);
|
|
1212
|
+
makeRoom(runtimeKey);
|
|
1213
|
+
if (runs.size >= limits.maxRuns)
|
|
1214
|
+
throw new HttpFailure(429, 'RUN_LIMIT');
|
|
1215
|
+
if (!runtimes.has(runtimeKey) && runtimes.size >= limits.maxRuntimes)
|
|
1216
|
+
throw new HttpFailure(429, 'RUNTIME_LIMIT');
|
|
1217
|
+
const start = async () => {
|
|
1218
|
+
if (submissionJournal) {
|
|
1219
|
+
let claim;
|
|
1220
|
+
try {
|
|
1221
|
+
claim = await bounded(Promise.resolve().then(() => submissionJournal.claim(Object.freeze({ owner, key, digest, signal }))), signal);
|
|
1222
|
+
}
|
|
1223
|
+
catch (error) {
|
|
1224
|
+
if (error instanceof HttpFailure && error.status === 408)
|
|
1225
|
+
throw error;
|
|
1226
|
+
throw new HttpFailure(503, 'SUBMISSION_JOURNAL_UNAVAILABLE');
|
|
1227
|
+
}
|
|
1228
|
+
const result = claim;
|
|
1229
|
+
if (result?.status === 'existing' && typeof result.digest === 'string') {
|
|
1230
|
+
// A claim made by an earlier process: its ephemeral run is gone, so neither replay nor a new run is truthful.
|
|
1231
|
+
if (result.digest !== digest)
|
|
1232
|
+
throw new HttpFailure(409, 'IDEMPOTENCY_CONFLICT');
|
|
1233
|
+
return 'duplicate';
|
|
1234
|
+
}
|
|
1235
|
+
if (result?.status !== 'claimed')
|
|
1236
|
+
throw new HttpFailure(503, 'SUBMISSION_JOURNAL_UNAVAILABLE');
|
|
1237
|
+
assertActive(signal);
|
|
1238
|
+
if (closed)
|
|
1239
|
+
throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
1240
|
+
}
|
|
1241
|
+
makeRoom(runtimeKey);
|
|
1242
|
+
if (runs.size >= limits.maxRuns)
|
|
1243
|
+
throw new HttpFailure(429, 'RUN_LIMIT');
|
|
1244
|
+
let runtime = runtimes.get(runtimeKey);
|
|
1245
|
+
if (!runtime) {
|
|
1246
|
+
if (runtimes.size >= limits.maxRuntimes)
|
|
1247
|
+
throw new HttpFailure(429, 'RUNTIME_LIMIT');
|
|
1248
|
+
runtime = createRuntime({ profile: 'ephemeral', scope: identity.scope, permissions: config.permissions, ...(config.limits ? { limits: config.limits } : {}) });
|
|
1249
|
+
runtimes.set(runtimeKey, runtime);
|
|
1250
|
+
}
|
|
1251
|
+
const handle = runtime.submit(config.agent, { input: data['input'] });
|
|
1252
|
+
const entry = { owner, agentId, digest, handle, runtime, runtimeKey, submissionKey };
|
|
1253
|
+
runs.set(handle.id, entry);
|
|
1254
|
+
submissions.set(submissionKey, entry);
|
|
1255
|
+
retained.set(runtimeKey, (retained.get(runtimeKey) ?? 0) + 1);
|
|
1256
|
+
void handle.result().then(outcome => {
|
|
1257
|
+
entry.outcome = outcome;
|
|
1258
|
+
entry.finished = true;
|
|
1259
|
+
if (closed)
|
|
1260
|
+
return;
|
|
1261
|
+
const timer = setTimeout(() => { retentionTimers.delete(timer); release(entry); }, limits.runRetentionMs);
|
|
1262
|
+
timer.unref?.();
|
|
1263
|
+
retentionTimers.add(timer);
|
|
1264
|
+
});
|
|
1265
|
+
return entry;
|
|
1266
|
+
};
|
|
1267
|
+
const pending = start();
|
|
1268
|
+
pendingSubmissions.set(submissionKey, pending);
|
|
1269
|
+
let started;
|
|
1270
|
+
try {
|
|
1271
|
+
started = await pending;
|
|
1272
|
+
}
|
|
1273
|
+
finally {
|
|
1274
|
+
pendingSubmissions.delete(submissionKey);
|
|
1275
|
+
}
|
|
1276
|
+
if (started === 'duplicate')
|
|
1277
|
+
throw new HttpFailure(409, 'SUBMISSION_OUTCOME_UNKNOWN');
|
|
1278
|
+
return response({ id: started.handle.id, profile: 'ephemeral' }, 202);
|
|
1279
|
+
}
|
|
1280
|
+
const match = /^\/v1\/runs\/([a-f0-9-]{36})(?:\/(cancel|events))?$/.exec(url.pathname);
|
|
1281
|
+
if (!match)
|
|
1282
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1283
|
+
const entry = runs.get(match[1]);
|
|
1284
|
+
if (!entry || entry.owner !== owner || !identity.agentIds.includes(entry.agentId))
|
|
1285
|
+
throw new HttpFailure(404, 'NOT_FOUND');
|
|
1286
|
+
if (request.method === 'POST' && match[2] === 'cancel') {
|
|
1287
|
+
requireCapability(identity, 'runs:cancel');
|
|
1288
|
+
if (request.body !== null)
|
|
1289
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
1290
|
+
assertActive(signal);
|
|
1291
|
+
entry.handle.cancel();
|
|
1292
|
+
return response({ id: entry.handle.id, cancellationRequested: true }, 202);
|
|
1293
|
+
}
|
|
1294
|
+
if (request.method === 'GET' && match[2] === 'events') {
|
|
1295
|
+
requireCapability(identity, 'runs:read');
|
|
1296
|
+
const cursor = url.searchParams.get('after') ?? '0';
|
|
1297
|
+
if (!/^\d+$/.test(cursor) || !Number.isSafeInteger(Number(cursor)))
|
|
1298
|
+
throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
1299
|
+
assertActive(signal);
|
|
1300
|
+
return eventResponse(entry, Number(cursor), identity, request);
|
|
1301
|
+
}
|
|
1302
|
+
if (request.method === 'GET' && !match[2]) {
|
|
1303
|
+
requireCapability(identity, 'runs:read');
|
|
1304
|
+
if (entry.outcome)
|
|
1305
|
+
entry.collected = true;
|
|
1306
|
+
return response({ ...entry.runtime.inspect(entry.handle), ...(entry.outcome ? { outcome: entry.outcome } : {}) });
|
|
1307
|
+
}
|
|
1308
|
+
throw new HttpFailure(405, 'METHOD_NOT_ALLOWED');
|
|
1309
|
+
};
|
|
1310
|
+
return Object.freeze({
|
|
1311
|
+
async fetch(request) {
|
|
1312
|
+
if (closed)
|
|
1313
|
+
return response({ error: { code: 'SERVER_CLOSED' } }, 503);
|
|
1314
|
+
if (requests >= limits.maxRequests)
|
|
1315
|
+
return response({ error: { code: 'REQUEST_LIMIT' } }, 429);
|
|
1316
|
+
requests++;
|
|
1317
|
+
const controller = new AbortController();
|
|
1318
|
+
const abort = () => { controller.abort(); };
|
|
1319
|
+
request.signal.addEventListener('abort', abort, { once: true });
|
|
1320
|
+
if (request.signal.aborted)
|
|
1321
|
+
abort();
|
|
1322
|
+
const timer = setTimeout(abort, limits.requestTimeoutMs);
|
|
1323
|
+
let result;
|
|
1324
|
+
try {
|
|
1325
|
+
result = await bounded(route(request, controller.signal).catch(error => {
|
|
1326
|
+
throw error instanceof HttpFailure ? error : new HttpFailure(400, 'INVALID_REQUEST');
|
|
1327
|
+
}), controller.signal);
|
|
1328
|
+
}
|
|
1329
|
+
catch (error) {
|
|
1330
|
+
const failure = error instanceof HttpFailure ? error : new HttpFailure(503, 'SERVICE_UNAVAILABLE');
|
|
1331
|
+
result = response({ error: { code: failure.code } }, failure.status);
|
|
1332
|
+
}
|
|
1333
|
+
finally {
|
|
1334
|
+
requests--;
|
|
1335
|
+
clearTimeout(timer);
|
|
1336
|
+
request.signal.removeEventListener('abort', abort);
|
|
1337
|
+
}
|
|
1338
|
+
const requestOrigin = request.headers.get('origin');
|
|
1339
|
+
if (requestOrigin && origins.has(requestOrigin)) {
|
|
1340
|
+
result.headers.set('Access-Control-Allow-Origin', requestOrigin);
|
|
1341
|
+
result.headers.set('Vary', 'Origin');
|
|
1342
|
+
}
|
|
1343
|
+
return result;
|
|
1344
|
+
},
|
|
1345
|
+
async close() {
|
|
1346
|
+
closed = true;
|
|
1347
|
+
for (const timer of retentionTimers)
|
|
1348
|
+
clearTimeout(timer);
|
|
1349
|
+
retentionTimers.clear();
|
|
1350
|
+
for (const finish of [...streams])
|
|
1351
|
+
finish();
|
|
1352
|
+
await Promise.all([...runtimes.values()].map(runtime => runtime.close()));
|
|
1353
|
+
},
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
//# sourceMappingURL=index.js.map
|