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,1033 @@
|
|
|
1
|
+
import { freezeJson, jsonValue, type JsonObject, type JsonValue, type Outcome, type Permissions, type RunHandle, type Scope } from '@mayura/core';
|
|
2
|
+
import { inspectorAsset } from './inspector.js';
|
|
3
|
+
import { assertAgent, createRuntime, type AgentDefinition, type Runtime, type RuntimeLimits } from '@mayura/runtime';
|
|
4
|
+
|
|
5
|
+
export interface ServerIdentity {
|
|
6
|
+
readonly scope: Scope;
|
|
7
|
+
readonly agentIds: readonly string[];
|
|
8
|
+
readonly capabilities: readonly ('runs:read' | 'runs:submit' | 'runs:cancel' | 'operations:read' | 'humans:read' | 'humans:respond' | 'workflows:read' | 'workflows:control' | 'workflows:fleet' | 'workflows:migrate')[];
|
|
9
|
+
readonly expiresAtMs: number;
|
|
10
|
+
}
|
|
11
|
+
export interface HealthCheck {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/** Trusted application callback. Returning false or throwing marks the dependency unavailable. */
|
|
14
|
+
readonly check: (context: { readonly signal: AbortSignal; readonly scope: Scope }) => boolean | Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
export interface HumanRequestRecord {
|
|
17
|
+
readonly id: string; readonly agentId: string; readonly kind: 'information' | 'correction' | 'plan_selection';
|
|
18
|
+
readonly schemaId: string; readonly schemaDigest: string; readonly prompt: string; readonly digest: string;
|
|
19
|
+
readonly status: 'waiting' | 'answered' | 'cancelled' | 'timed_out'; readonly context?: JsonValue;
|
|
20
|
+
readonly subjectDigest?: string; readonly deadlineAtMs?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface HumanRequestTransport {
|
|
23
|
+
readonly list: (input: { readonly scope: Scope; readonly agentIds: readonly string[]; readonly after: string | null; readonly limit: number; readonly signal: AbortSignal }) => Promise<{ readonly items: readonly HumanRequestRecord[]; readonly next: string | null }>;
|
|
24
|
+
readonly inspect: (input: { readonly scope: Scope; readonly agentIds: readonly string[]; readonly id: string; readonly signal: AbortSignal }) => Promise<HumanRequestRecord | null>;
|
|
25
|
+
readonly respond: (input: { readonly scope: Scope; readonly agentIds: readonly string[]; readonly actorId: string; readonly id: string;
|
|
26
|
+
readonly requestDigest: string; readonly commandId: string; readonly value: JsonValue; readonly signal: AbortSignal }) => Promise<HumanRequestRecord>;
|
|
27
|
+
}
|
|
28
|
+
export interface WorkflowViewRecord {
|
|
29
|
+
readonly format: 2 | 3 | 4 | 5; readonly definitionId: string; readonly definitionVersion: string; readonly runId: string;
|
|
30
|
+
readonly revision: number; readonly status: 'running' | 'waiting' | 'paused' | 'succeeded' | 'failed' | 'blocked' | 'cancelled' | 'outcome_unknown';
|
|
31
|
+
readonly nodes: readonly { readonly id: string; readonly kind: 'tool' | 'join' | 'wait' | 'child' | 'human' | 'timer'; readonly dependsOn: readonly string[] }[];
|
|
32
|
+
readonly steps: readonly { readonly id: string; readonly kind: 'tool' | 'join' | 'wait' | 'child' | 'human' | 'timer';
|
|
33
|
+
readonly status: 'pending' | 'waiting' | 'approved' | 'dispatching' | 'succeeded' | 'failed' | 'blocked' | 'unknown' | 'skipped' | 'timed_out';
|
|
34
|
+
readonly childRunId?: string; readonly approval?: WorkflowApprovalRecord }[];
|
|
35
|
+
}
|
|
36
|
+
/** A tool step waiting for approval: the digest an approval must name, its expiry and, when known, the exact tool call. */
|
|
37
|
+
export interface WorkflowApprovalRecord {
|
|
38
|
+
readonly digest: string; readonly expiresAtMs: number;
|
|
39
|
+
readonly subject?: { readonly toolId: string; readonly toolVersion: string; readonly input: JsonValue };
|
|
40
|
+
}
|
|
41
|
+
export interface WorkflowViewTransport {
|
|
42
|
+
readonly inspect: (input: { readonly scope: Scope; readonly agentIds: readonly string[]; readonly runId: string;
|
|
43
|
+
readonly signal: AbortSignal }) => Promise<WorkflowViewRecord | null>;
|
|
44
|
+
}
|
|
45
|
+
export interface WorkflowIndexRecord {
|
|
46
|
+
readonly format: 2 | 3 | 4 | 5; readonly definitionId: string; readonly definitionVersion: string; readonly runId: string;
|
|
47
|
+
readonly revision: number; readonly status: WorkflowViewRecord['status'];
|
|
48
|
+
/** Only in the settled view: when the run reached its final status. */
|
|
49
|
+
readonly settledAtMs?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface WorkflowIndexTransport {
|
|
52
|
+
/**
|
|
53
|
+
* Active runs, or with `view: 'settled'` recently finished runs and runs whose outcome is unknown. The field is
|
|
54
|
+
* present only for the settled view; a transport that ignores it fails the settled request closed.
|
|
55
|
+
*/
|
|
56
|
+
readonly list: (input: { readonly scope: Scope; readonly agentIds: readonly string[]; readonly after: string | null;
|
|
57
|
+
readonly limit: number; readonly signal: AbortSignal; readonly view?: 'settled' }) => Promise<{ readonly items: readonly WorkflowIndexRecord[]; readonly next: string | null }>;
|
|
58
|
+
}
|
|
59
|
+
export type WorkflowControlResult = { readonly status: 'applied'; readonly workflow: WorkflowViewRecord }
|
|
60
|
+
| { readonly status: 'conflict' } | { readonly status: 'not_found' };
|
|
61
|
+
interface WorkflowControlBase {
|
|
62
|
+
readonly scope: Scope; readonly agentIds: readonly string[]; readonly actorId: string; readonly runId: string;
|
|
63
|
+
readonly revision: number; readonly commandId: string; readonly signal: AbortSignal;
|
|
64
|
+
}
|
|
65
|
+
export interface WorkflowControlTransport {
|
|
66
|
+
readonly cancel: (input: WorkflowControlBase) => Promise<WorkflowControlResult>;
|
|
67
|
+
readonly approve: (input: WorkflowControlBase & { readonly nodeId: string; readonly approvalDigest: string;
|
|
68
|
+
readonly childRunId: string | null }) => Promise<WorkflowControlResult>;
|
|
69
|
+
}
|
|
70
|
+
/** Durable signal delivery remains an explicit adapter boundary so each workflow format owns persistence and idempotency. */
|
|
71
|
+
export interface WorkflowSignalTransport {
|
|
72
|
+
readonly deliver: (input: WorkflowControlBase & { readonly signalId: string; readonly signalName: string;
|
|
73
|
+
readonly value: JsonValue }) => Promise<WorkflowControlResult>;
|
|
74
|
+
}
|
|
75
|
+
/** Requests durable continuation without granting authority to force a waiting gate or replay an uncertain effect. */
|
|
76
|
+
export interface WorkflowResumeTransport {
|
|
77
|
+
readonly resume: (input: WorkflowControlBase) => Promise<WorkflowControlResult>;
|
|
78
|
+
}
|
|
79
|
+
/** Requests a quiescent durable operator pause; it never interrupts an in-flight effect or cancels a run. */
|
|
80
|
+
export interface WorkflowPauseTransport {
|
|
81
|
+
readonly pause: (input: WorkflowControlBase) => Promise<WorkflowControlResult>;
|
|
82
|
+
}
|
|
83
|
+
export interface WorkflowFleetHoldRecord { readonly held: boolean; readonly generation: number; readonly changedAtMs: number | null }
|
|
84
|
+
export type WorkflowFleetSweepOutcomeRecord =
|
|
85
|
+
| { readonly target: string; readonly runId: string;
|
|
86
|
+
readonly outcome: 'paused' | 'already_paused' | 'terminal' | 'busy' | 'resumed' | 'not_paused' | 'missing' | 'unregistered' }
|
|
87
|
+
| { readonly target: string; readonly runId: string; readonly outcome: 'failed'; readonly code: string };
|
|
88
|
+
export interface WorkflowFleetSweepRecord { readonly outcomes: readonly WorkflowFleetSweepOutcomeRecord[]; readonly nextCursor: JsonObject | null }
|
|
89
|
+
interface WorkflowFleetBase { readonly scope: Scope; readonly agentIds: readonly string[]; readonly actorId: string; readonly signal: AbortSignal }
|
|
90
|
+
/** Durable fleet hold and ledger-backed sweep for one verified scope. Mutations require the separate `workflows:fleet` capability. */
|
|
91
|
+
export interface WorkflowFleetTransport {
|
|
92
|
+
readonly inspect: (input: WorkflowFleetBase) => Promise<WorkflowFleetHoldRecord>;
|
|
93
|
+
readonly hold: (input: WorkflowFleetBase) => Promise<WorkflowFleetHoldRecord>;
|
|
94
|
+
readonly release: (input: WorkflowFleetBase) => Promise<WorkflowFleetHoldRecord>;
|
|
95
|
+
readonly sweep: (input: WorkflowFleetBase & { readonly phase: 'pause' | 'resume'; readonly cursor: JsonObject | null; readonly limit: number })
|
|
96
|
+
=> Promise<{ readonly status: 'applied'; readonly sweep: WorkflowFleetSweepRecord } | { readonly status: 'conflict' }>;
|
|
97
|
+
}
|
|
98
|
+
/** A reviewed migration the host offers for runs pinned to its source definition. */
|
|
99
|
+
export interface WorkflowMigrationRecord {
|
|
100
|
+
readonly id: string; readonly description: string;
|
|
101
|
+
readonly fromVersion: string; readonly toVersion: string; readonly fromDigest: string; readonly toDigest: string;
|
|
102
|
+
}
|
|
103
|
+
/** What a migration would do to one run, decided from the run's real state. */
|
|
104
|
+
export interface WorkflowMigrationPlanRecord {
|
|
105
|
+
readonly migrationId: string; readonly format: string; readonly runId: string; readonly fromDigest: string; readonly toDigest: string;
|
|
106
|
+
readonly entries: readonly { readonly action: 'keep' | 'update' | 'reset' | 'accept' | 'add' | 'remove'; readonly target?: string; readonly source?: string; readonly status?: string }[];
|
|
107
|
+
readonly blockers: readonly { readonly node: string; readonly reason: string }[];
|
|
108
|
+
readonly allowed: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface WorkflowMigrationBase { readonly scope: Scope; readonly agentIds: readonly string[]; readonly runId: string; readonly signal: AbortSignal }
|
|
111
|
+
/**
|
|
112
|
+
* In-place migration of paused runs to a new definition version. Listing and planning are reads; applying requires the
|
|
113
|
+
* separate `workflows:migrate` capability, the run's exact revision and a stable command id.
|
|
114
|
+
*/
|
|
115
|
+
export interface WorkflowMigrationTransport {
|
|
116
|
+
/** Migrations whose source is the run's pinned definition; null when the run is not visible to this identity. */
|
|
117
|
+
readonly list: (input: WorkflowMigrationBase) => Promise<readonly WorkflowMigrationRecord[] | null>;
|
|
118
|
+
/** Dry run: the plan for this run. Writes nothing. Null when the run or migration is not visible. */
|
|
119
|
+
readonly plan: (input: WorkflowMigrationBase & { readonly migrationId: string }) => Promise<WorkflowMigrationPlanRecord | null>;
|
|
120
|
+
readonly apply: (input: WorkflowControlBase & { readonly migrationId: string }) => Promise<
|
|
121
|
+
| { readonly status: 'applied'; readonly plan: WorkflowMigrationPlanRecord; readonly workflow: WorkflowViewRecord }
|
|
122
|
+
| { readonly status: 'refused'; readonly plan: WorkflowMigrationPlanRecord }
|
|
123
|
+
| { readonly status: 'conflict' } | { readonly status: 'not_found' }>;
|
|
124
|
+
}
|
|
125
|
+
export interface SubmissionJournal {
|
|
126
|
+
readonly claim: (input: { readonly owner: string; readonly key: string; readonly digest: string; readonly signal: AbortSignal })
|
|
127
|
+
=> Promise<{ readonly status: 'claimed' } | { readonly status: 'existing'; readonly digest: string }>;
|
|
128
|
+
}
|
|
129
|
+
export interface RegisteredAgent {
|
|
130
|
+
readonly agent: AgentDefinition;
|
|
131
|
+
readonly permissions: Permissions;
|
|
132
|
+
readonly limits?: RuntimeLimits;
|
|
133
|
+
}
|
|
134
|
+
export interface AgentServerOptions {
|
|
135
|
+
readonly publicOrigin: string;
|
|
136
|
+
readonly allowedOrigins?: readonly string[];
|
|
137
|
+
readonly agents: readonly RegisteredAgent[];
|
|
138
|
+
/** Expose only a content-free process liveness response at GET /healthz. */
|
|
139
|
+
readonly publicLiveness?: boolean;
|
|
140
|
+
/** Serve the read-only local inspector at GET /inspector. Its static assets contain no data; every read is authenticated. */
|
|
141
|
+
readonly inspector?: boolean;
|
|
142
|
+
/** Access-controlled readiness checks. Credentials and exception details must remain inside callbacks. */
|
|
143
|
+
readonly healthChecks?: readonly HealthCheck[];
|
|
144
|
+
readonly humanRequests?: HumanRequestTransport;
|
|
145
|
+
readonly workflowViews?: WorkflowViewTransport;
|
|
146
|
+
readonly workflowIndex?: WorkflowIndexTransport;
|
|
147
|
+
readonly workflowControls?: WorkflowControlTransport;
|
|
148
|
+
readonly workflowSignals?: WorkflowSignalTransport;
|
|
149
|
+
readonly workflowResumes?: WorkflowResumeTransport;
|
|
150
|
+
readonly workflowPauses?: WorkflowPauseTransport;
|
|
151
|
+
readonly workflowFleet?: WorkflowFleetTransport;
|
|
152
|
+
readonly workflowMigrations?: WorkflowMigrationTransport;
|
|
153
|
+
/**
|
|
154
|
+
* Durable claim of every run submission key. Without it, idempotency lasts only as long as the process: a retry
|
|
155
|
+
* after a restart could start a duplicate run. With it, such a retry is refused with SUBMISSION_OUTCOME_UNKNOWN.
|
|
156
|
+
*/
|
|
157
|
+
readonly submissionJournal?: SubmissionJournal;
|
|
158
|
+
/** Verify the token using trusted application authentication; never trust token claims without verification. */
|
|
159
|
+
readonly authenticate: (request: { readonly token: string; readonly signal: AbortSignal }) => Promise<ServerIdentity | null>;
|
|
160
|
+
readonly limits?: {
|
|
161
|
+
readonly maxRuns?: number; readonly maxRuntimes?: number; readonly maxRequests?: number;
|
|
162
|
+
readonly maxStreams?: number; readonly maxBodyBytes?: number; readonly maxResponseBytes?: number;
|
|
163
|
+
readonly maxHealthOperations?: number; readonly maxHumanOperations?: number; readonly maxWorkflowOperations?: number;
|
|
164
|
+
readonly requestTimeoutMs?: number; readonly streamDurationMs?: number;
|
|
165
|
+
/**
|
|
166
|
+
* How long a finished run stays readable (result, events and same-key resubmission) before the server releases
|
|
167
|
+
* it, and with it any runtime no retained run still uses. Default 10 minutes. At `maxRuns` or `maxRuntimes` a
|
|
168
|
+
* finished run whose outcome its owner has already read (a run read with its outcome, or an event stream read to
|
|
169
|
+
* the end) is released early, oldest first; a result nobody has read is kept for the full period.
|
|
170
|
+
* After release, a same-key resubmission is answered `410 RUN_EXPIRED` (or `409 IDEMPOTENCY_CONFLICT` for a
|
|
171
|
+
* different payload) from a bounded tombstone rather than starting a second run. Configure `submissionJournal`
|
|
172
|
+
* for idempotency that also survives restarts and tombstone expiry.
|
|
173
|
+
*/
|
|
174
|
+
readonly runRetentionMs?: number;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export interface AgentServer { fetch(request: Request): Promise<Response>; close(): Promise<void> }
|
|
178
|
+
interface Entry {
|
|
179
|
+
readonly owner: string; readonly agentId: string; readonly digest: string;
|
|
180
|
+
readonly handle: RunHandle<unknown>; readonly runtime: Runtime;
|
|
181
|
+
readonly runtimeKey: string; readonly submissionKey: string;
|
|
182
|
+
outcome?: Outcome<unknown>;
|
|
183
|
+
finished?: boolean;
|
|
184
|
+
/** The owner has received the outcome; the run may be released early under capacity pressure. */
|
|
185
|
+
collected?: boolean;
|
|
186
|
+
}
|
|
187
|
+
class HttpFailure extends Error {
|
|
188
|
+
constructor(readonly status: number, readonly code: string) { super(code); }
|
|
189
|
+
}
|
|
190
|
+
const identifier = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/;
|
|
191
|
+
const humanIdentifier = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
|
|
192
|
+
const encoder = new TextEncoder();
|
|
193
|
+
const workflowKinds = Object.freeze({ 2: new Set(['tool', 'join']), 3: new Set(['tool', 'join', 'wait']),
|
|
194
|
+
4: new Set(['tool', 'join', 'child']), 5: new Set(['tool', 'join', 'human', 'timer']) });
|
|
195
|
+
const workflowStatuses = new Set(['running', 'waiting', 'paused', 'succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown']);
|
|
196
|
+
const workflowStepStatuses = new Set(['pending', 'waiting', 'approved', 'dispatching', 'succeeded', 'failed', 'blocked', 'unknown', 'skipped', 'timed_out']);
|
|
197
|
+
const approvalRecord = (value: JsonValue | undefined): boolean => {
|
|
198
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
199
|
+
const keys = Object.keys(value); const subject = value['subject'];
|
|
200
|
+
return keys.every(key => ['digest', 'expiresAtMs', 'subject'].includes(key)) && typeof value['digest'] === 'string' && /^[a-f0-9]{64}$/.test(value['digest'])
|
|
201
|
+
&& typeof value['expiresAtMs'] === 'number' && Number.isSafeInteger(value['expiresAtMs']) && value['expiresAtMs'] > 0
|
|
202
|
+
&& (subject === undefined || (subject !== null && typeof subject === 'object' && !Array.isArray(subject)
|
|
203
|
+
&& Object.keys(subject).length === 3 && Object.hasOwn(subject, 'input')
|
|
204
|
+
&& typeof subject['toolId'] === 'string' && identifier.test(subject['toolId'])
|
|
205
|
+
&& typeof subject['toolVersion'] === 'string' && identifier.test(subject['toolVersion'])));
|
|
206
|
+
};
|
|
207
|
+
function object(value: unknown, maxBytes = 1_048_576): JsonObject {
|
|
208
|
+
const copy = jsonValue(value, { maxBytes });
|
|
209
|
+
if (copy === null || Array.isArray(copy) || typeof copy !== 'object') throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
210
|
+
return copy;
|
|
211
|
+
}
|
|
212
|
+
function exact(value: JsonObject, keys: readonly string[]): void {
|
|
213
|
+
if (Object.keys(value).length !== keys.length || keys.some(key => !(key in value))) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
214
|
+
}
|
|
215
|
+
function canonical(value: JsonValue): string {
|
|
216
|
+
if (value === null || typeof value !== 'object') return JSON.stringify(value);
|
|
217
|
+
return Array.isArray(value) ? `[${value.map(canonical).join(',')}]`
|
|
218
|
+
: `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key]!)}`).join(',')}}`;
|
|
219
|
+
}
|
|
220
|
+
function origin(value: string): string {
|
|
221
|
+
const url = new URL(value);
|
|
222
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.pathname !== '/' || url.search || url.hash) throw new Error('Invalid server origin.');
|
|
223
|
+
if (url.protocol === 'http:' && !['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) throw new Error('Non-loopback origins require HTTPS.');
|
|
224
|
+
return url.origin;
|
|
225
|
+
}
|
|
226
|
+
function assertActive(signal: AbortSignal): void { if (signal.aborted) throw new HttpFailure(408, 'REQUEST_TIMEOUT'); }
|
|
227
|
+
function workflowExact(value: JsonObject, keys: readonly string[]): void {
|
|
228
|
+
if (Object.keys(value).length !== keys.length || keys.some(key => !Object.hasOwn(value, key))) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
229
|
+
}
|
|
230
|
+
function workflowRecord(value: unknown, expectedRunId: string): WorkflowViewRecord {
|
|
231
|
+
let raw: JsonObject;
|
|
232
|
+
try { raw = object(value, 262_144); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
233
|
+
workflowExact(raw, ['format', 'definitionId', 'definitionVersion', 'runId', 'revision', 'status', 'nodes', 'steps']);
|
|
234
|
+
const format = raw['format']; const nodes = raw['nodes']; const steps = raw['steps'];
|
|
235
|
+
if (![2, 3, 4, 5].includes(format as number) || typeof raw['definitionId'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(raw['definitionId'])
|
|
236
|
+
|| typeof raw['definitionVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['definitionVersion'])
|
|
237
|
+
|| raw['runId'] !== expectedRunId || typeof raw['revision'] !== 'number' || !Number.isSafeInteger(raw['revision']) || raw['revision'] < 1
|
|
238
|
+
|| typeof raw['status'] !== 'string' || !workflowStatuses.has(raw['status']) || !Array.isArray(nodes) || nodes.length < 1 || nodes.length > 128
|
|
239
|
+
|| !Array.isArray(steps) || steps.length !== nodes.length) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
240
|
+
const admittedKinds = workflowKinds[format as keyof typeof workflowKinds]; const graph = new Map<string, readonly string[]>(); const nodeKinds = new Map<string, string>(); let edges = 0;
|
|
241
|
+
for (const candidate of nodes) {
|
|
242
|
+
let node: JsonObject; try { node = object(candidate, 32_768); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
243
|
+
workflowExact(node, ['id', 'kind', 'dependsOn']);
|
|
244
|
+
if (typeof node['id'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(node['id']) || graph.has(node['id'])
|
|
245
|
+
|| typeof node['kind'] !== 'string' || !admittedKinds.has(node['kind']) || !Array.isArray(node['dependsOn']) || node['dependsOn'].length > 127
|
|
246
|
+
|| node['dependsOn'].some(item => typeof item !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(item))
|
|
247
|
+
|| new Set(node['dependsOn']).size !== node['dependsOn'].length) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
248
|
+
edges += node['dependsOn'].length; if (edges > 512) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
249
|
+
graph.set(node['id'], node['dependsOn'] as readonly string[]); nodeKinds.set(node['id'], node['kind']);
|
|
250
|
+
}
|
|
251
|
+
for (const [id, dependencies] of graph) if (dependencies.some(dependency => dependency === id || !graph.has(dependency))) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
252
|
+
const seen = new Set<string>();
|
|
253
|
+
for (const candidate of steps) {
|
|
254
|
+
let step: JsonObject; try { step = object(candidate, 16_384); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
255
|
+
const allowed = ['id', 'kind', 'status', 'childRunId', 'approval'];
|
|
256
|
+
if (Object.keys(step).some(key => !allowed.includes(key)) || !['id', 'kind', 'status'].every(key => Object.hasOwn(step, key)) || typeof step['id'] !== 'string'
|
|
257
|
+
|| seen.has(step['id']) || step['kind'] !== nodeKinds.get(step['id']) || typeof step['status'] !== 'string' || !workflowStepStatuses.has(step['status'])
|
|
258
|
+
|| (step['kind'] === 'human' && !['pending', 'waiting', 'succeeded', 'timed_out', 'skipped'].includes(step['status']))
|
|
259
|
+
|| (step['kind'] === 'timer' && !['pending', 'waiting', 'succeeded', 'skipped'].includes(step['status']))
|
|
260
|
+
|| (step['status'] === 'timed_out' && step['kind'] !== 'human')
|
|
261
|
+
|| (step['childRunId'] !== undefined && (step['kind'] !== 'child' || typeof step['childRunId'] !== 'string' || !/^[a-f0-9]{64}$/.test(step['childRunId'])))
|
|
262
|
+
|| (step['approval'] !== undefined && (step['kind'] !== 'tool' || step['status'] !== 'waiting' || !approvalRecord(step['approval'])))
|
|
263
|
+
) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
264
|
+
seen.add(step['id']);
|
|
265
|
+
}
|
|
266
|
+
if (seen.size !== graph.size) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
267
|
+
const remaining = new Map([...graph].map(([id, dependencies]) => [id, dependencies.length])); const dependents = new Map<string, string[]>();
|
|
268
|
+
for (const [id, dependencies] of graph) for (const dependency of dependencies) { const list = dependents.get(dependency) ?? []; list.push(id); dependents.set(dependency, list); }
|
|
269
|
+
const queue = [...remaining].filter(([, count]) => count === 0).map(([id]) => id);
|
|
270
|
+
for (let cursor = 0; cursor < queue.length; cursor++) for (const dependent of dependents.get(queue[cursor]!) ?? []) {
|
|
271
|
+
const count = remaining.get(dependent)! - 1; remaining.set(dependent, count); if (count === 0) queue.push(dependent);
|
|
272
|
+
}
|
|
273
|
+
if (queue.length !== graph.size) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
274
|
+
return freezeJson(raw) as unknown as WorkflowViewRecord;
|
|
275
|
+
}
|
|
276
|
+
const fleetOutcomes = new Set(['paused', 'already_paused', 'terminal', 'busy', 'resumed', 'not_paused', 'missing', 'unregistered']);
|
|
277
|
+
function fleetHold(value: unknown): WorkflowFleetHoldRecord {
|
|
278
|
+
let raw: JsonObject; try { raw = object(value, 1_024); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
279
|
+
workflowExact(raw, ['held', 'generation', 'changedAtMs']);
|
|
280
|
+
const { held, generation, changedAtMs } = raw;
|
|
281
|
+
if (typeof held !== 'boolean' || typeof generation !== 'number' || !Number.isSafeInteger(generation) || generation < (held ? 1 : 0)
|
|
282
|
+
|| (changedAtMs !== null && (typeof changedAtMs !== 'number' || !Number.isSafeInteger(changedAtMs) || changedAtMs < 0)))
|
|
283
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
284
|
+
return Object.freeze({ held, generation, changedAtMs: changedAtMs as number | null });
|
|
285
|
+
}
|
|
286
|
+
/** Sweep pages are content-free: target names, run identities and fixed outcome codes only. */
|
|
287
|
+
function fleetSweep(value: unknown, limit: number): WorkflowFleetSweepRecord {
|
|
288
|
+
let raw: JsonObject; try { raw = object(value, 262_144); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
289
|
+
workflowExact(raw, ['outcomes', 'nextCursor']);
|
|
290
|
+
if (!Array.isArray(raw['outcomes']) || raw['outcomes'].length > limit) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
291
|
+
const outcomes = raw['outcomes'].map(entry => {
|
|
292
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
293
|
+
const failed = entry['outcome'] === 'failed'; workflowExact(entry, failed ? ['target', 'runId', 'outcome', 'code'] : ['target', 'runId', 'outcome']);
|
|
294
|
+
if (typeof entry['target'] !== 'string' || !/^[a-z][a-z0-9-]{0,31}$/.test(entry['target']) || typeof entry['runId'] !== 'string'
|
|
295
|
+
|| !/^[a-f0-9]{64}$/.test(entry['runId']) || (failed ? typeof entry['code'] !== 'string' || !/^[A-Z][A-Z_]{0,39}$/.test(entry['code'])
|
|
296
|
+
: !fleetOutcomes.has(String(entry['outcome'])))) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
297
|
+
return Object.freeze({ ...entry }) as unknown as WorkflowFleetSweepOutcomeRecord;
|
|
298
|
+
});
|
|
299
|
+
let nextCursor: JsonObject | null = null;
|
|
300
|
+
if (raw['nextCursor'] !== null) { try { nextCursor = object(raw['nextCursor'], 4_096); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); } }
|
|
301
|
+
return Object.freeze({ outcomes: Object.freeze(outcomes), nextCursor });
|
|
302
|
+
}
|
|
303
|
+
const migrationIdPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
304
|
+
const migrationActions = new Set(['keep', 'update', 'reset', 'accept', 'add', 'remove']);
|
|
305
|
+
const nodeIdPattern = /^[A-Za-z][A-Za-z0-9._-]{0,127}$/;
|
|
306
|
+
const shortText = (value: unknown, maximum: number): boolean => typeof value === 'string' && value.length <= maximum && !/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(value);
|
|
307
|
+
function migrationRecord(value: unknown): WorkflowMigrationRecord {
|
|
308
|
+
let raw: JsonObject; try { raw = object(value, 8_192); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
309
|
+
workflowExact(raw, ['id', 'description', 'fromVersion', 'toVersion', 'fromDigest', 'toDigest']);
|
|
310
|
+
if (typeof raw['id'] !== 'string' || !migrationIdPattern.test(raw['id']) || !shortText(raw['description'], 2_048)
|
|
311
|
+
|| typeof raw['fromVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['fromVersion'])
|
|
312
|
+
|| typeof raw['toVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['toVersion'])
|
|
313
|
+
|| typeof raw['fromDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['fromDigest'])
|
|
314
|
+
|| typeof raw['toDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['toDigest']) || raw['fromDigest'] === raw['toDigest']) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
315
|
+
return freezeJson(raw) as unknown as WorkflowMigrationRecord;
|
|
316
|
+
}
|
|
317
|
+
function migrationPlan(value: unknown, runId: string, migrationId: string): WorkflowMigrationPlanRecord {
|
|
318
|
+
let raw: JsonObject; try { raw = object(value, 262_144); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
319
|
+
workflowExact(raw, ['migrationId', 'format', 'runId', 'fromDigest', 'toDigest', 'entries', 'blockers', 'allowed']);
|
|
320
|
+
const entries = raw['entries']; const blockers = raw['blockers'];
|
|
321
|
+
if (raw['migrationId'] !== migrationId || raw['runId'] !== runId || typeof raw['format'] !== 'string' || !/^[a-z0-9-]{1,32}$/.test(raw['format'])
|
|
322
|
+
|| typeof raw['fromDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['fromDigest']) || typeof raw['toDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['toDigest'])
|
|
323
|
+
|| typeof raw['allowed'] !== 'boolean' || !Array.isArray(entries) || entries.length > 512 || !Array.isArray(blockers) || blockers.length > 512
|
|
324
|
+
|| raw['allowed'] !== (blockers.length === 0)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
325
|
+
for (const entry of entries) {
|
|
326
|
+
if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
327
|
+
if (Object.keys(entry).some(key => !['action', 'target', 'source', 'status'].includes(key)) || !migrationActions.has(String(entry['action']))
|
|
328
|
+
|| (entry['target'] !== undefined && (typeof entry['target'] !== 'string' || !nodeIdPattern.test(entry['target'])))
|
|
329
|
+
|| (entry['source'] !== undefined && (typeof entry['source'] !== 'string' || !nodeIdPattern.test(entry['source'])))
|
|
330
|
+
|| (entry['status'] !== undefined && (typeof entry['status'] !== 'string' || !/^[a-z_]{1,32}$/.test(entry['status'])))
|
|
331
|
+
|| (entry['target'] === undefined && entry['source'] === undefined)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
332
|
+
}
|
|
333
|
+
for (const blocker of blockers) {
|
|
334
|
+
if (blocker === null || typeof blocker !== 'object' || Array.isArray(blocker)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
335
|
+
workflowExact(blocker, ['node', 'reason']);
|
|
336
|
+
if (typeof blocker['node'] !== 'string' || !(blocker['node'] === '*' || nodeIdPattern.test(blocker['node'])) || !shortText(blocker['reason'], 512) || !blocker['reason'])
|
|
337
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
338
|
+
}
|
|
339
|
+
return freezeJson(raw) as unknown as WorkflowMigrationPlanRecord;
|
|
340
|
+
}
|
|
341
|
+
const settledStatuses = new Set(['succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown']);
|
|
342
|
+
function workflowIndexRecord(value: unknown, settled = false): WorkflowIndexRecord {
|
|
343
|
+
let raw: JsonObject; try { raw = object(value, 4_096); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
344
|
+
workflowExact(raw, ['format', 'definitionId', 'definitionVersion', 'runId', 'revision', 'status', ...(settled ? ['settledAtMs'] : [])]);
|
|
345
|
+
if (settled && (!settledStatuses.has(raw['status'] as string) || typeof raw['settledAtMs'] !== 'number' || !Number.isSafeInteger(raw['settledAtMs']) || raw['settledAtMs'] < 0))
|
|
346
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
347
|
+
if (![2, 3, 4, 5].includes(raw['format'] as number) || typeof raw['definitionId'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(raw['definitionId'])
|
|
348
|
+
|| typeof raw['definitionVersion'] !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(raw['definitionVersion'])
|
|
349
|
+
|| typeof raw['runId'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['runId']) || typeof raw['revision'] !== 'number'
|
|
350
|
+
|| !Number.isSafeInteger(raw['revision']) || raw['revision'] < 1 || typeof raw['status'] !== 'string' || !workflowStatuses.has(raw['status']))
|
|
351
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
352
|
+
return freezeJson(raw) as unknown as WorkflowIndexRecord;
|
|
353
|
+
}
|
|
354
|
+
async function bounded<T>(operation: PromiseLike<T>, signal: AbortSignal): Promise<T> {
|
|
355
|
+
if (signal.aborted) { void Promise.resolve(operation).catch(() => {}); throw new HttpFailure(408, 'REQUEST_TIMEOUT'); }
|
|
356
|
+
assertActive(signal);
|
|
357
|
+
return await new Promise<T>((resolve, reject) => {
|
|
358
|
+
const abort = (): void => { cleanup(); reject(new HttpFailure(408, 'REQUEST_TIMEOUT')); };
|
|
359
|
+
const cleanup = (): void => { signal.removeEventListener('abort', abort); };
|
|
360
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
361
|
+
Promise.resolve(operation).then(value => { cleanup(); resolve(value); }, (error: unknown) => { cleanup(); reject(error instanceof HttpFailure ? error : new HttpFailure(503, 'SERVICE_UNAVAILABLE')); });
|
|
362
|
+
if (signal.aborted) abort();
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Authenticated Fetch facade. Hosting, TLS, durable execution, and token verification remain explicit. */
|
|
367
|
+
export function createAgentServer(options: AgentServerOptions): AgentServer {
|
|
368
|
+
const publicOrigin = origin(options.publicOrigin);
|
|
369
|
+
const origins = new Set((options.allowedOrigins ?? []).map(origin));
|
|
370
|
+
if (typeof options.authenticate !== 'function' || !Array.isArray(options.agents) || options.agents.length > 256) throw new Error('Explicit authentication and a bounded agent registry are required.');
|
|
371
|
+
const authenticate = options.authenticate;
|
|
372
|
+
if (options.publicLiveness !== undefined && typeof options.publicLiveness !== 'boolean') throw new Error('Public liveness must be explicit.');
|
|
373
|
+
if (options.inspector !== undefined && typeof options.inspector !== 'boolean') throw new Error('The inspector setting must be a boolean.');
|
|
374
|
+
const limits = Object.freeze({ maxRuns: 512, maxRuntimes: 128, maxRequests: 64, maxStreams: 64,
|
|
375
|
+
maxBodyBytes: 1_048_576, maxResponseBytes: 4_194_304, maxHealthOperations: 32, maxHumanOperations: 32, maxWorkflowOperations: 32,
|
|
376
|
+
requestTimeoutMs: 10_000, streamDurationMs: 30_000, runRetentionMs: 600_000, ...options.limits });
|
|
377
|
+
if (Object.keys(limits).some(key => !['maxRuns', 'maxRuntimes', 'maxRequests', 'maxStreams', 'maxBodyBytes', 'maxResponseBytes', 'maxHealthOperations', 'maxHumanOperations', 'maxWorkflowOperations', 'requestTimeoutMs', 'streamDurationMs', 'runRetentionMs'].includes(key))) throw new Error('Unknown server limit.');
|
|
378
|
+
for (const value of Object.values(limits)) if (!Number.isSafeInteger(value) || value < 1 || value > 16_777_216) throw new Error('Server limits must be bounded positive integers.');
|
|
379
|
+
const healthChecks: readonly HealthCheck[] = (() => {
|
|
380
|
+
const supplied = options.healthChecks ?? [];
|
|
381
|
+
if (!Array.isArray(supplied) || supplied.length > 32) throw new Error('Health checks must be a bounded dense list.');
|
|
382
|
+
const descriptors = Object.getOwnPropertyDescriptors(supplied);
|
|
383
|
+
if (Reflect.ownKeys(descriptors).length !== supplied.length + 1) throw new Error('Health checks must be a bounded dense list.');
|
|
384
|
+
const ids = new Set<string>(); const captured: HealthCheck[] = [];
|
|
385
|
+
for (let index = 0; index < supplied.length; index++) {
|
|
386
|
+
const entry = descriptors[String(index)];
|
|
387
|
+
if (!entry || !('value' in entry) || entry.value === null || typeof entry.value !== 'object') throw new Error('Health checks must contain data entries.');
|
|
388
|
+
const fields = Object.getOwnPropertyDescriptors(entry.value as object);
|
|
389
|
+
if (Reflect.ownKeys(fields).some(key => !['id', 'check'].includes(String(key)))) throw new Error('Health checks contain unknown fields.');
|
|
390
|
+
const id = fields['id']; const check = fields['check'];
|
|
391
|
+
if (!id || !('value' in id) || typeof id.value !== 'string' || !identifier.test(id.value) || ids.has(id.value)
|
|
392
|
+
|| !check || !('value' in check) || typeof check.value !== 'function') throw new Error('Health checks require unique IDs and callbacks.');
|
|
393
|
+
ids.add(id.value); captured.push(Object.freeze({ id: id.value, check: check.value as HealthCheck['check'] }));
|
|
394
|
+
}
|
|
395
|
+
return Object.freeze(captured);
|
|
396
|
+
})();
|
|
397
|
+
const humanRequests: HumanRequestTransport | undefined = (() => {
|
|
398
|
+
if (options.humanRequests === undefined) return undefined;
|
|
399
|
+
if (options.humanRequests === null || typeof options.humanRequests !== 'object') throw new Error('Human request transport is invalid.');
|
|
400
|
+
const fields = Object.getOwnPropertyDescriptors(options.humanRequests);
|
|
401
|
+
if (Reflect.ownKeys(fields).length !== 3 || ['list', 'inspect', 'respond'].some(key => !fields[key] || !('value' in fields[key]!) || typeof fields[key]!.value !== 'function')) throw new Error('Human request transport requires exact callbacks.');
|
|
402
|
+
return Object.freeze({ list: fields['list']!.value, inspect: fields['inspect']!.value, respond: fields['respond']!.value }) as HumanRequestTransport;
|
|
403
|
+
})();
|
|
404
|
+
const workflowViews: WorkflowViewTransport | undefined = (() => {
|
|
405
|
+
if (options.workflowViews === undefined) return undefined;
|
|
406
|
+
if (options.workflowViews === null || typeof options.workflowViews !== 'object') throw new Error('Workflow view transport is invalid.');
|
|
407
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowViews);
|
|
408
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['inspect'] || !('value' in fields['inspect']) || typeof fields['inspect'].value !== 'function')
|
|
409
|
+
throw new Error('Workflow view transport requires one exact inspect callback.');
|
|
410
|
+
return Object.freeze({ inspect: fields['inspect'].value as WorkflowViewTransport['inspect'] });
|
|
411
|
+
})();
|
|
412
|
+
const workflowIndex: WorkflowIndexTransport | undefined = (() => {
|
|
413
|
+
if (options.workflowIndex === undefined) return undefined;
|
|
414
|
+
if (options.workflowIndex === null || typeof options.workflowIndex !== 'object') throw new Error('Workflow index transport is invalid.');
|
|
415
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowIndex);
|
|
416
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['list'] || !('value' in fields['list']) || typeof fields['list'].value !== 'function')
|
|
417
|
+
throw new Error('Workflow index transport requires one exact list callback.');
|
|
418
|
+
return Object.freeze({ list: fields['list'].value as WorkflowIndexTransport['list'] });
|
|
419
|
+
})();
|
|
420
|
+
const workflowControls: WorkflowControlTransport | undefined = (() => {
|
|
421
|
+
if (options.workflowControls === undefined) return undefined;
|
|
422
|
+
if (options.workflowControls === null || typeof options.workflowControls !== 'object') throw new Error('Workflow control transport is invalid.');
|
|
423
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowControls);
|
|
424
|
+
if (Reflect.ownKeys(fields).length !== 2 || ['cancel', 'approve'].some(key => !fields[key] || !('value' in fields[key]!) || typeof fields[key]!.value !== 'function'))
|
|
425
|
+
throw new Error('Workflow control transport requires exact cancel and approve callbacks.');
|
|
426
|
+
return Object.freeze({ cancel: fields['cancel']!.value, approve: fields['approve']!.value }) as WorkflowControlTransport;
|
|
427
|
+
})();
|
|
428
|
+
const workflowSignals: WorkflowSignalTransport | undefined = (() => {
|
|
429
|
+
if (options.workflowSignals === undefined) return undefined;
|
|
430
|
+
if (options.workflowSignals === null || typeof options.workflowSignals !== 'object') throw new Error('Workflow signal transport is invalid.');
|
|
431
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowSignals);
|
|
432
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['deliver'] || !('value' in fields['deliver']) || typeof fields['deliver'].value !== 'function')
|
|
433
|
+
throw new Error('Workflow signal transport requires one exact deliver callback.');
|
|
434
|
+
return Object.freeze({ deliver: fields['deliver'].value as WorkflowSignalTransport['deliver'] });
|
|
435
|
+
})();
|
|
436
|
+
const workflowResumes: WorkflowResumeTransport | undefined = (() => {
|
|
437
|
+
if (options.workflowResumes === undefined) return undefined;
|
|
438
|
+
if (options.workflowResumes === null || typeof options.workflowResumes !== 'object') throw new Error('Workflow resume transport is invalid.');
|
|
439
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowResumes);
|
|
440
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['resume'] || !('value' in fields['resume']) || typeof fields['resume'].value !== 'function')
|
|
441
|
+
throw new Error('Workflow resume transport requires one exact resume callback.');
|
|
442
|
+
return Object.freeze({ resume: fields['resume'].value as WorkflowResumeTransport['resume'] });
|
|
443
|
+
})();
|
|
444
|
+
const workflowPauses: WorkflowPauseTransport | undefined = (() => {
|
|
445
|
+
if (options.workflowPauses === undefined) return undefined;
|
|
446
|
+
if (options.workflowPauses === null || typeof options.workflowPauses !== 'object') throw new Error('Workflow pause transport is invalid.');
|
|
447
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowPauses);
|
|
448
|
+
if (Reflect.ownKeys(fields).length !== 1 || !fields['pause'] || !('value' in fields['pause']) || typeof fields['pause'].value !== 'function')
|
|
449
|
+
throw new Error('Workflow pause transport requires one exact pause callback.');
|
|
450
|
+
return Object.freeze({ pause: fields['pause'].value as WorkflowPauseTransport['pause'] });
|
|
451
|
+
})();
|
|
452
|
+
const workflowFleet: WorkflowFleetTransport | undefined = (() => {
|
|
453
|
+
if (options.workflowFleet === undefined) return undefined;
|
|
454
|
+
if (options.workflowFleet === null || typeof options.workflowFleet !== 'object') throw new Error('Workflow fleet transport is invalid.');
|
|
455
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowFleet); const names = ['inspect', 'hold', 'release', 'sweep'] as const;
|
|
456
|
+
if (Reflect.ownKeys(fields).length !== names.length || names.some(name => !fields[name] || !('value' in fields[name]!) || typeof fields[name]!.value !== 'function'))
|
|
457
|
+
throw new Error('Workflow fleet transport requires exact inspect, hold, release and sweep callbacks.');
|
|
458
|
+
return Object.freeze(Object.fromEntries(names.map(name => [name, fields[name]!.value])) as unknown as WorkflowFleetTransport);
|
|
459
|
+
})();
|
|
460
|
+
const workflowMigrations: WorkflowMigrationTransport | undefined = (() => {
|
|
461
|
+
if (options.workflowMigrations === undefined) return undefined;
|
|
462
|
+
if (options.workflowMigrations === null || typeof options.workflowMigrations !== 'object') throw new Error('Workflow migration transport is invalid.');
|
|
463
|
+
const fields = Object.getOwnPropertyDescriptors(options.workflowMigrations); const names = ['list', 'plan', 'apply'] as const;
|
|
464
|
+
if (Reflect.ownKeys(fields).length !== names.length || names.some(name => !fields[name] || !('value' in fields[name]!) || typeof fields[name]!.value !== 'function'))
|
|
465
|
+
throw new Error('Workflow migration transport requires exact list, plan and apply callbacks.');
|
|
466
|
+
return Object.freeze(Object.fromEntries(names.map(name => [name, fields[name]!.value])) as unknown as WorkflowMigrationTransport);
|
|
467
|
+
})();
|
|
468
|
+
const registry = new Map<string, RegisteredAgent>();
|
|
469
|
+
for (const config of options.agents) {
|
|
470
|
+
assertAgent(config.agent);
|
|
471
|
+
if (registry.has(config.agent.id)) throw new Error('Agent registry IDs must be unique.');
|
|
472
|
+
// Validate configuration now, not after accepting an HTTP command. No model work is performed.
|
|
473
|
+
const permissions = Object.freeze({ allow: Object.freeze([...config.permissions.allow]) });
|
|
474
|
+
const settings = config.limits === undefined ? {} : Object.freeze({ ...config.limits });
|
|
475
|
+
const check = createRuntime({ profile: 'ephemeral', permissions, limits: settings });
|
|
476
|
+
void check.close();
|
|
477
|
+
registry.set(config.agent.id, Object.freeze({ agent: config.agent, permissions, limits: settings }));
|
|
478
|
+
}
|
|
479
|
+
const toolCatalog = Object.freeze([...registry.values()].flatMap(config => config.agent.tools.map(tool => Object.freeze({
|
|
480
|
+
agentId: config.agent.id, agentVersion: config.agent.version, id: tool.id, version: tool.version,
|
|
481
|
+
effects: tool.effects, capabilities: tool.capabilities, timeoutMs: tool.timeoutMs, costMicros: tool.costMicros,
|
|
482
|
+
}))).sort((left, right) => left.agentId.localeCompare(right.agentId) || left.id.localeCompare(right.id) || left.version.localeCompare(right.version)));
|
|
483
|
+
const runtimes = new Map<string, Runtime>();
|
|
484
|
+
const runs = new Map<string, Entry>();
|
|
485
|
+
// Same-process concurrent submissions share one journal claim and one run.
|
|
486
|
+
const pendingSubmissions = new Map<string, Promise<Entry | 'duplicate'>>();
|
|
487
|
+
const submissionJournal = (() => {
|
|
488
|
+
if (options.submissionJournal === undefined) return undefined;
|
|
489
|
+
if (options.submissionJournal === null || typeof options.submissionJournal !== 'object' || typeof options.submissionJournal.claim !== 'function')
|
|
490
|
+
throw new Error('Submission journal requires a claim function.');
|
|
491
|
+
return Object.freeze({ claim: options.submissionJournal.claim.bind(options.submissionJournal) });
|
|
492
|
+
})();
|
|
493
|
+
const submissions = new Map<string, Entry>();
|
|
494
|
+
// Runs retained per runtime; a runtime closes when its last retained run is released.
|
|
495
|
+
const retained = new Map<string, number>();
|
|
496
|
+
const retentionTimers = new Set<ReturnType<typeof setTimeout>>();
|
|
497
|
+
// Idempotency evidence for released runs: submission key -> request digest, oldest dropped past a fixed bound.
|
|
498
|
+
const tombstones = new Map<string, string>(); const maxTombstones = 16_384;
|
|
499
|
+
const release = (entry: Entry): void => {
|
|
500
|
+
if (runs.get(entry.handle.id) !== entry) return;
|
|
501
|
+
runs.delete(entry.handle.id);
|
|
502
|
+
if (submissions.get(entry.submissionKey) === entry) {
|
|
503
|
+
submissions.delete(entry.submissionKey); tombstones.delete(entry.submissionKey); tombstones.set(entry.submissionKey, entry.digest);
|
|
504
|
+
if (tombstones.size > maxTombstones) tombstones.delete(tombstones.keys().next().value!);
|
|
505
|
+
}
|
|
506
|
+
const remaining = (retained.get(entry.runtimeKey) ?? 1) - 1;
|
|
507
|
+
if (remaining > 0) { retained.set(entry.runtimeKey, remaining); return; }
|
|
508
|
+
retained.delete(entry.runtimeKey);
|
|
509
|
+
const runtime = runtimes.get(entry.runtimeKey);
|
|
510
|
+
if (runtime === entry.runtime) { runtimes.delete(entry.runtimeKey); void Promise.resolve().then(() => runtime.close()).catch(() => undefined); }
|
|
511
|
+
};
|
|
512
|
+
/** Release the oldest finished runs until a new run (and, when needed, a new runtime) fits. Active runs are never released. */
|
|
513
|
+
const makeRoom = (runtimeKey: string): void => {
|
|
514
|
+
for (const entry of runs.values()) {
|
|
515
|
+
if (runs.size < limits.maxRuns && (runtimes.has(runtimeKey) || runtimes.size < limits.maxRuntimes)) return;
|
|
516
|
+
if (entry.finished && entry.collected) release(entry);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
const streams = new Set<() => void>();
|
|
520
|
+
let closed = false;
|
|
521
|
+
let requests = 0;
|
|
522
|
+
let authentications = 0;
|
|
523
|
+
let healthOperations = 0;
|
|
524
|
+
let humanOperations = 0;
|
|
525
|
+
let workflowOperations = 0;
|
|
526
|
+
|
|
527
|
+
const humanRecord = (value: unknown, identity: ServerIdentity): HumanRequestRecord => {
|
|
528
|
+
const raw = object(value, 16_384); const allowed = ['id', 'agentId', 'kind', 'schemaId', 'schemaDigest', 'prompt', 'digest', 'status', 'context', 'subjectDigest', 'deadlineAtMs'];
|
|
529
|
+
if (Object.keys(raw).some(key => !allowed.includes(key)) || !['id', 'agentId', 'kind', 'schemaId', 'schemaDigest', 'prompt', 'digest', 'status'].every(key => Object.hasOwn(raw, key))
|
|
530
|
+
|| typeof raw['id'] !== 'string' || !humanIdentifier.test(raw['id']) || typeof raw['agentId'] !== 'string' || !identity.agentIds.includes(raw['agentId'])
|
|
531
|
+
|| !['information', 'correction', 'plan_selection'].includes(String(raw['kind'])) || typeof raw['schemaId'] !== 'string' || !identifier.test(raw['schemaId'])
|
|
532
|
+
|| typeof raw['schemaDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['schemaDigest']) || typeof raw['digest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['digest'])
|
|
533
|
+
|| typeof raw['prompt'] !== 'string' || encoder.encode(raw['prompt']).byteLength < 1 || encoder.encode(raw['prompt']).byteLength > 1_024
|
|
534
|
+
|| !['waiting', 'answered', 'cancelled', 'timed_out'].includes(String(raw['status']))
|
|
535
|
+
|| (raw['subjectDigest'] !== undefined && (typeof raw['subjectDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(raw['subjectDigest'])))
|
|
536
|
+
|| ((raw['kind'] === 'correction') !== (raw['subjectDigest'] !== undefined))
|
|
537
|
+
|| (raw['deadlineAtMs'] !== undefined && (!Number.isSafeInteger(raw['deadlineAtMs']) || (raw['deadlineAtMs'] as number) < 0))) throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
538
|
+
return freezeJson(raw) as unknown as HumanRequestRecord;
|
|
539
|
+
};
|
|
540
|
+
const humanCall = async <T>(callback: () => Promise<T>, signal: AbortSignal): Promise<T> => {
|
|
541
|
+
if (humanOperations >= limits.maxHumanOperations) throw new HttpFailure(429, 'HUMAN_LIMIT');
|
|
542
|
+
humanOperations++; const operation = Promise.resolve().then(callback).finally(() => { humanOperations--; });
|
|
543
|
+
try { return await bounded(operation, signal); } catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'HUMAN_UNAVAILABLE'); }
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
const response = (value: unknown, status = 200, extra: Record<string, string> = {}): Response => {
|
|
547
|
+
let text: string;
|
|
548
|
+
try { text = JSON.stringify(jsonValue(value, { maxBytes: limits.maxResponseBytes })); }
|
|
549
|
+
catch { return new Response('{"error":{"code":"RESPONSE_LIMIT"}}', { status: 503, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' } }); }
|
|
550
|
+
return new Response(text, { status, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', ...extra } });
|
|
551
|
+
};
|
|
552
|
+
const session = async (request: Request, signal: AbortSignal): Promise<ServerIdentity> => {
|
|
553
|
+
const authorization = request.headers.get('authorization') ?? '';
|
|
554
|
+
if (!/^Bearer [\x21-\x7e]{1,8192}$/.test(authorization)) throw new HttpFailure(401, 'UNAUTHORIZED');
|
|
555
|
+
let supplied: ServerIdentity | null;
|
|
556
|
+
assertActive(signal);
|
|
557
|
+
if (authentications >= limits.maxRequests) throw new HttpFailure(429, 'AUTH_LIMIT');
|
|
558
|
+
authentications++;
|
|
559
|
+
const verification = Promise.resolve().then(() => {
|
|
560
|
+
assertActive(signal); return authenticate(Object.freeze({ token: authorization.slice(7), signal }));
|
|
561
|
+
}).finally(() => { authentications--; });
|
|
562
|
+
// A non-cooperative verifier retains its admission until it really completes.
|
|
563
|
+
try { supplied = await bounded(verification, signal); }
|
|
564
|
+
catch { assertActive(signal); throw new HttpFailure(503, 'AUTH_UNAVAILABLE'); }
|
|
565
|
+
assertActive(signal);
|
|
566
|
+
try {
|
|
567
|
+
const raw = object(supplied, 65_536); const scope = object(raw['scope']);
|
|
568
|
+
exact(raw, ['scope', 'agentIds', 'capabilities', 'expiresAtMs']); exact(scope, ['principalId', 'projectId']);
|
|
569
|
+
if (typeof scope['principalId'] !== 'string' || !identifier.test(scope['principalId']) || typeof scope['projectId'] !== 'string' || !identifier.test(scope['projectId'])
|
|
570
|
+
|| !Array.isArray(raw['agentIds']) || raw['agentIds'].length > 256 || raw['agentIds'].some(id => typeof id !== 'string' || !identifier.test(id))
|
|
571
|
+
|| !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)))
|
|
572
|
+
|| typeof raw['expiresAtMs'] !== 'number' || !Number.isSafeInteger(raw['expiresAtMs']) || raw['expiresAtMs'] <= Date.now()) throw new Error();
|
|
573
|
+
return freezeJson(raw) as unknown as ServerIdentity;
|
|
574
|
+
} catch { throw new HttpFailure(401, 'UNAUTHORIZED'); }
|
|
575
|
+
};
|
|
576
|
+
const requireCapability = (identity: ServerIdentity, capability: ServerIdentity['capabilities'][number]): void => {
|
|
577
|
+
if (!identity.capabilities.includes(capability)) throw new HttpFailure(403, 'FORBIDDEN');
|
|
578
|
+
if (identity.expiresAtMs <= Date.now()) throw new HttpFailure(401, 'UNAUTHORIZED');
|
|
579
|
+
};
|
|
580
|
+
const body = async (request: Request, signal: AbortSignal): Promise<JsonObject> => {
|
|
581
|
+
if (!/^application\/json(?:\s*;\s*charset=utf-8)?$/i.test(request.headers.get('content-type') ?? '') || request.headers.has('content-encoding')) throw new HttpFailure(415, 'UNSUPPORTED_MEDIA_TYPE');
|
|
582
|
+
const declared = request.headers.get('content-length');
|
|
583
|
+
if (declared !== null && (!/^\d+$/.test(declared) || Number(declared) > limits.maxBodyBytes)) throw new HttpFailure(413, 'BODY_LIMIT');
|
|
584
|
+
const reader = request.body?.getReader();
|
|
585
|
+
if (!reader) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
586
|
+
const chunks: Uint8Array[] = []; let total = 0; let complete = false;
|
|
587
|
+
try {
|
|
588
|
+
while (true) {
|
|
589
|
+
const item = await bounded(reader.read(), signal);
|
|
590
|
+
if (item.done) { complete = true; break; }
|
|
591
|
+
total += item.value.byteLength;
|
|
592
|
+
if (total > limits.maxBodyBytes) throw new HttpFailure(413, 'BODY_LIMIT');
|
|
593
|
+
chunks.push(item.value);
|
|
594
|
+
}
|
|
595
|
+
const data = new Uint8Array(total); let offset = 0;
|
|
596
|
+
for (const chunk of chunks) { data.set(chunk, offset); offset += chunk.byteLength; }
|
|
597
|
+
try { return object(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(data)), limits.maxBodyBytes); }
|
|
598
|
+
catch { throw new HttpFailure(400, 'INVALID_REQUEST'); }
|
|
599
|
+
} finally { if (!complete) void reader.cancel().catch(() => {}); reader.releaseLock(); }
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
const eventResponse = (entry: Entry, after: number, identity: ServerIdentity, request: Request): Response => {
|
|
603
|
+
if (closed) throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
604
|
+
if (streams.size >= limits.maxStreams) throw new HttpFailure(429, 'STREAM_LIMIT');
|
|
605
|
+
const controller = new AbortController();
|
|
606
|
+
const iterator = entry.handle.observe({ after, signal: controller.signal })[Symbol.asyncIterator]();
|
|
607
|
+
let sink: ReadableStreamDefaultController<Uint8Array>;
|
|
608
|
+
let ended = false;
|
|
609
|
+
const finish = (): void => {
|
|
610
|
+
if (ended) return;
|
|
611
|
+
ended = true; controller.abort(); clearTimeout(timer); streams.delete(finish);
|
|
612
|
+
request.signal.removeEventListener('abort', finish);
|
|
613
|
+
try { sink.close(); } catch { /* Consumer cancellation may already have closed the stream. */ }
|
|
614
|
+
void iterator.return?.().catch(() => {});
|
|
615
|
+
};
|
|
616
|
+
const timer = setTimeout(finish, Math.max(0, Math.min(limits.streamDurationMs, identity.expiresAtMs - Date.now())));
|
|
617
|
+
streams.add(finish);
|
|
618
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
619
|
+
start(value) { sink = value; },
|
|
620
|
+
async pull(value) {
|
|
621
|
+
if (ended) return;
|
|
622
|
+
try {
|
|
623
|
+
const next = await iterator.next();
|
|
624
|
+
if (ended) return;
|
|
625
|
+
if (next.done) { if (entry.finished) entry.collected = true; finish(); return; }
|
|
626
|
+
const event = JSON.stringify(jsonValue(next.value, { maxBytes: 16_384 }));
|
|
627
|
+
value.enqueue(encoder.encode(`id: ${next.value.sequence}\nevent: ${next.value.type}\ndata: ${event}\n\n`));
|
|
628
|
+
} catch {
|
|
629
|
+
if (!ended) value.enqueue(encoder.encode('event: stream.error\ndata: {"code":"OBSERVATION_FAILED"}\n\n'));
|
|
630
|
+
finish();
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
cancel() { finish(); },
|
|
634
|
+
}, { highWaterMark: 1 });
|
|
635
|
+
request.signal.addEventListener('abort', finish, { once: true });
|
|
636
|
+
if (request.signal.aborted) finish();
|
|
637
|
+
return new Response(stream, { headers: { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'X-Accel-Buffering': 'no' } });
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
const route = async (request: Request, signal: AbortSignal): Promise<Response> => {
|
|
641
|
+
const url = new URL(request.url);
|
|
642
|
+
if (url.origin !== publicOrigin || url.username || url.password || url.hash) throw new HttpFailure(400, 'INVALID_DESTINATION');
|
|
643
|
+
// Console assets are static and data-free; module scripts carry an Origin header even when same-origin.
|
|
644
|
+
if (options.inspector === true && !url.search) { const asset = inspectorAsset(request.method, url.pathname); if (asset) return asset; }
|
|
645
|
+
const requestOrigin = request.headers.get('origin');
|
|
646
|
+
// With the console enabled, the server's own origin is a legitimate same-origin caller; others need allowedOrigins.
|
|
647
|
+
if (requestOrigin !== null && !origins.has(requestOrigin) && !(options.inspector === true && requestOrigin === publicOrigin)) throw new HttpFailure(403, 'ORIGIN_DENIED');
|
|
648
|
+
// A preflight is validated as the request it announces: the same query rules apply, so query credentials still fail,
|
|
649
|
+
// but a legitimate paginated GET can be preflighted.
|
|
650
|
+
const effectiveMethod = request.method === 'OPTIONS' ? request.headers.get('access-control-request-method') ?? '' : request.method;
|
|
651
|
+
const eventMatch = /^\/v1\/runs\/([a-f0-9-]{36})\/events$/.exec(url.pathname);
|
|
652
|
+
const catalogQuery = effectiveMethod === 'GET' && url.pathname === '/v1/tools';
|
|
653
|
+
const humanListQuery = effectiveMethod === 'GET' && url.pathname === '/v1/human-requests';
|
|
654
|
+
const workflowListQuery = effectiveMethod === 'GET' && url.pathname === '/v1/workflow-runs';
|
|
655
|
+
if ([...url.searchParams.keys()].some(key => effectiveMethod !== 'GET' || (eventMatch ? key !== 'after' : catalogQuery || humanListQuery ? !['after', 'limit'].includes(key) : workflowListQuery ? !['after', 'limit', 'view'].includes(key) : true))
|
|
656
|
+
|| url.searchParams.getAll('after').length > 1 || url.searchParams.getAll('limit').length > 1 || url.searchParams.getAll('view').length > 1) throw new HttpFailure(400, 'INVALID_QUERY');
|
|
657
|
+
if (request.method === 'OPTIONS') {
|
|
658
|
+
if (!requestOrigin || !['GET', 'POST'].includes(request.headers.get('access-control-request-method') ?? '')) throw new HttpFailure(403, 'ORIGIN_DENIED');
|
|
659
|
+
const headers = (request.headers.get('access-control-request-headers') ?? '').toLowerCase().split(',').map(value => value.trim()).filter(Boolean);
|
|
660
|
+
if (headers.some(value => !['authorization', 'content-type', 'idempotency-key'].includes(value))) throw new HttpFailure(403, 'ORIGIN_DENIED');
|
|
661
|
+
return new Response(null, { status: 204, headers: { 'Access-Control-Allow-Methods': 'GET, POST', 'Access-Control-Allow-Headers': 'Authorization, Content-Type, Idempotency-Key' } });
|
|
662
|
+
}
|
|
663
|
+
if (request.method === 'GET' && url.pathname === '/healthz' && options.publicLiveness === true) return response({ status: 'ok' });
|
|
664
|
+
const identity = await session(request, signal);
|
|
665
|
+
if (closed) throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
666
|
+
const owner = canonical(identity.scope as unknown as JsonValue);
|
|
667
|
+
if (workflowListQuery) {
|
|
668
|
+
requireCapability(identity, 'workflows:read'); if (!workflowIndex) throw new HttpFailure(404, 'NOT_FOUND');
|
|
669
|
+
const after = url.searchParams.get('after'); const limitText = url.searchParams.get('limit') ?? '20';
|
|
670
|
+
if ((after !== null && !/^[A-Za-z0-9._:-]{1,128}$/.test(after)) || !/^\d+$/.test(limitText)) throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
671
|
+
const limit = Number(limitText); if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
672
|
+
const view = url.searchParams.get('view') ?? 'active'; if (view !== 'active' && view !== 'settled') throw new HttpFailure(400, 'INVALID_QUERY');
|
|
673
|
+
const settled = view === 'settled';
|
|
674
|
+
if (workflowOperations >= limits.maxWorkflowOperations) throw new HttpFailure(429, 'WORKFLOW_LIMIT'); workflowOperations++;
|
|
675
|
+
const operation = Promise.resolve().then(() => workflowIndex.list(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
676
|
+
after, limit, signal, ...(settled ? { view: 'settled' as const } : {}) }))).finally(() => { workflowOperations--; });
|
|
677
|
+
let supplied: unknown; try { supplied = await bounded(operation, signal); }
|
|
678
|
+
catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE'); }
|
|
679
|
+
let page: JsonObject; try { page = object(supplied, 524_288); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
680
|
+
workflowExact(page, ['items', 'next']);
|
|
681
|
+
if (!Array.isArray(page['items']) || page['items'].length > limit || (page['next'] !== null
|
|
682
|
+
&& (typeof page['next'] !== 'string' || !/^[A-Za-z0-9._:-]{1,128}$/.test(page['next']) || page['next'] === after)))
|
|
683
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
684
|
+
const items = page['items'].map(item => workflowIndexRecord(item, settled)); if (new Set(items.map(item => item.runId)).size !== items.length)
|
|
685
|
+
throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
686
|
+
assertActive(signal); requireCapability(identity, 'workflows:read'); return response({ items, next: page['next'] });
|
|
687
|
+
}
|
|
688
|
+
const fleetMatch = /^\/v1\/workflow-fleet(?:\/(hold|release|sweeps\/pause|sweeps\/resume))?$/.exec(url.pathname);
|
|
689
|
+
if (fleetMatch && request.method === (fleetMatch[1] === undefined ? 'GET' : 'POST')) {
|
|
690
|
+
const action = fleetMatch[1] ?? 'inspect'; const capability = action === 'inspect' ? 'workflows:read' : 'workflows:fleet';
|
|
691
|
+
requireCapability(identity, capability); if (!workflowFleet) throw new HttpFailure(404, 'NOT_FOUND');
|
|
692
|
+
let cursor: JsonObject | null = null; let limit = 0; const sweep = action.startsWith('sweeps/');
|
|
693
|
+
if (action !== 'inspect') {
|
|
694
|
+
const data = await body(request, signal);
|
|
695
|
+
if (!sweep) exact(data, []);
|
|
696
|
+
else {
|
|
697
|
+
exact(data, ['cursor', 'limit']);
|
|
698
|
+
if (typeof data['limit'] !== 'number' || !Number.isSafeInteger(data['limit']) || data['limit'] < 1 || data['limit'] > 128) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
699
|
+
limit = data['limit']; if (data['cursor'] !== null) cursor = object(data['cursor'], 4_096);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (workflowOperations >= limits.maxWorkflowOperations) throw new HttpFailure(429, 'WORKFLOW_LIMIT'); workflowOperations++;
|
|
703
|
+
const base = Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, actorId: identity.scope.principalId, signal });
|
|
704
|
+
const call = (): Promise<unknown> => action === 'inspect' ? workflowFleet.inspect(base) : action === 'hold' ? workflowFleet.hold(base)
|
|
705
|
+
: action === 'release' ? workflowFleet.release(base)
|
|
706
|
+
: workflowFleet.sweep(Object.freeze({ ...base, phase: action === 'sweeps/pause' ? 'pause' as const : 'resume' as const, cursor, limit }));
|
|
707
|
+
const operation = Promise.resolve().then(call).finally(() => { workflowOperations--; });
|
|
708
|
+
let result: unknown;
|
|
709
|
+
try { result = await bounded(operation, signal); } catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE'); }
|
|
710
|
+
assertActive(signal); requireCapability(identity, capability);
|
|
711
|
+
if (sweep) {
|
|
712
|
+
let raw: JsonObject; try { raw = object(result, 262_144); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
713
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1) throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
714
|
+
workflowExact(raw, ['status', 'sweep']); if (raw['status'] !== 'applied') throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
715
|
+
return response({ sweep: fleetSweep(raw['sweep'], limit) });
|
|
716
|
+
}
|
|
717
|
+
const fleet = fleetHold(result);
|
|
718
|
+
if ((action === 'hold' && !fleet.held) || (action === 'release' && fleet.held)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
719
|
+
return response({ fleet });
|
|
720
|
+
}
|
|
721
|
+
const workflowMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})$/.exec(url.pathname);
|
|
722
|
+
if (workflowMatch && request.method === 'GET') {
|
|
723
|
+
requireCapability(identity, 'workflows:read'); if (!workflowViews) throw new HttpFailure(404, 'NOT_FOUND');
|
|
724
|
+
if (workflowOperations >= limits.maxWorkflowOperations) throw new HttpFailure(429, 'WORKFLOW_LIMIT');
|
|
725
|
+
workflowOperations++;
|
|
726
|
+
const operation = Promise.resolve().then(() => workflowViews.inspect(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
727
|
+
runId: workflowMatch[1]!, signal }))).finally(() => { workflowOperations--; });
|
|
728
|
+
let item: WorkflowViewRecord | null;
|
|
729
|
+
try { item = await bounded(operation, signal); } catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE'); }
|
|
730
|
+
if (item === null) throw new HttpFailure(404, 'NOT_FOUND'); const record = workflowRecord(item, workflowMatch[1]!);
|
|
731
|
+
assertActive(signal); requireCapability(identity, 'workflows:read'); return response({ workflow: record });
|
|
732
|
+
}
|
|
733
|
+
const workflowControlMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/(cancel|approvals)$/.exec(url.pathname);
|
|
734
|
+
if (workflowControlMatch && request.method === 'POST') {
|
|
735
|
+
requireCapability(identity, 'workflows:control'); if (!workflowControls) throw new HttpFailure(404, 'NOT_FOUND');
|
|
736
|
+
const data = await body(request, signal); const action = workflowControlMatch[2]!;
|
|
737
|
+
const fields = action === 'cancel' ? ['commandId', 'revision'] : ['commandId', 'revision', 'nodeId', 'approvalDigest', 'childRunId']; exact(data, fields);
|
|
738
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
739
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
740
|
+
if (action === 'approvals' && (typeof data['nodeId'] !== 'string' || !/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(data['nodeId'])
|
|
741
|
+
|| typeof data['approvalDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(data['approvalDigest'])
|
|
742
|
+
|| (data['childRunId'] !== null && (typeof data['childRunId'] !== 'string' || !/^[a-f0-9]{64}$/.test(data['childRunId'])))))
|
|
743
|
+
throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
744
|
+
if (workflowOperations >= limits.maxWorkflowOperations) throw new HttpFailure(429, 'WORKFLOW_LIMIT'); workflowOperations++;
|
|
745
|
+
const common = { scope: identity.scope, agentIds: identity.agentIds, actorId: identity.scope.principalId, runId: workflowControlMatch[1]!,
|
|
746
|
+
revision: data['revision'] as number, commandId: data['commandId'] as string, signal };
|
|
747
|
+
const operation = Promise.resolve().then(() => action === 'cancel' ? workflowControls.cancel(Object.freeze(common))
|
|
748
|
+
: workflowControls.approve(Object.freeze({ ...common, nodeId: data['nodeId'] as string, approvalDigest: data['approvalDigest'] as string,
|
|
749
|
+
childRunId: data['childRunId'] as string | null }))).finally(() => { workflowOperations--; });
|
|
750
|
+
let result: WorkflowControlResult;
|
|
751
|
+
try { result = await bounded(operation, signal); } catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE'); }
|
|
752
|
+
assertActive(signal); requireCapability(identity, 'workflows:control');
|
|
753
|
+
let raw: JsonObject; try { raw = object(result, 262_144); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
754
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1) throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
755
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1) throw new HttpFailure(404, 'NOT_FOUND');
|
|
756
|
+
workflowExact(raw, ['status', 'workflow']); if (raw['status'] !== 'applied') throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
757
|
+
const record = workflowRecord(raw['workflow'], workflowControlMatch[1]!);
|
|
758
|
+
if (record.revision < (data['revision'] as number)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
759
|
+
return response({ workflow: record });
|
|
760
|
+
}
|
|
761
|
+
const workflowSignalMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/signals$/.exec(url.pathname);
|
|
762
|
+
if (workflowSignalMatch && request.method === 'POST') {
|
|
763
|
+
requireCapability(identity, 'workflows:control'); if (!workflowSignals) throw new HttpFailure(404, 'NOT_FOUND');
|
|
764
|
+
const data = await body(request, signal); exact(data, ['commandId', 'revision', 'signalId', 'signalName', 'value']);
|
|
765
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
766
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1 || typeof data['signalId'] !== 'string' || !identifier.test(data['signalId'])
|
|
767
|
+
|| typeof data['signalName'] !== 'string' || !identifier.test(data['signalName'])) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
768
|
+
let value: JsonValue; try { value = freezeJson(jsonValue(data['value'], { maxBytes: 4_096, maxDepth: 16, maxNodes: 1_024 })); }
|
|
769
|
+
catch { throw new HttpFailure(400, 'INVALID_REQUEST'); }
|
|
770
|
+
if (workflowOperations >= limits.maxWorkflowOperations) throw new HttpFailure(429, 'WORKFLOW_LIMIT'); workflowOperations++;
|
|
771
|
+
const operation = Promise.resolve().then(() => workflowSignals.deliver(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
772
|
+
actorId: identity.scope.principalId, runId: workflowSignalMatch[1]!, revision: data['revision'] as number,
|
|
773
|
+
commandId: data['commandId'] as string, signalId: data['signalId'] as string, signalName: data['signalName'] as string,
|
|
774
|
+
value, signal }))).finally(() => { workflowOperations--; });
|
|
775
|
+
let result: WorkflowControlResult;
|
|
776
|
+
try { result = await bounded(operation, signal); } catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE'); }
|
|
777
|
+
assertActive(signal); requireCapability(identity, 'workflows:control');
|
|
778
|
+
let raw: JsonObject; try { raw = object(result, 262_144); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
779
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1) throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
780
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1) throw new HttpFailure(404, 'NOT_FOUND');
|
|
781
|
+
workflowExact(raw, ['status', 'workflow']); if (raw['status'] !== 'applied') throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
782
|
+
const record = workflowRecord(raw['workflow'], workflowSignalMatch[1]!);
|
|
783
|
+
if (record.revision < (data['revision'] as number)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
784
|
+
return response({ workflow: record });
|
|
785
|
+
}
|
|
786
|
+
const migrationMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/migrations(?:\/([A-Za-z0-9][A-Za-z0-9._-]{0,127}))?$/.exec(url.pathname);
|
|
787
|
+
if (migrationMatch && (request.method === 'GET' || (request.method === 'POST' && migrationMatch[2] !== undefined))) {
|
|
788
|
+
const runId = migrationMatch[1]!; const migrationId = migrationMatch[2];
|
|
789
|
+
const capability = request.method === 'POST' ? 'workflows:migrate' as const : 'workflows:read' as const;
|
|
790
|
+
requireCapability(identity, capability); if (!workflowMigrations) throw new HttpFailure(404, 'NOT_FOUND');
|
|
791
|
+
let data: JsonObject | undefined;
|
|
792
|
+
if (request.method === 'POST') {
|
|
793
|
+
data = await body(request, signal); exact(data, ['commandId', 'revision']);
|
|
794
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
795
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
796
|
+
}
|
|
797
|
+
if (workflowOperations >= limits.maxWorkflowOperations) throw new HttpFailure(429, 'WORKFLOW_LIMIT'); workflowOperations++;
|
|
798
|
+
const base = { scope: identity.scope, agentIds: identity.agentIds, runId, signal };
|
|
799
|
+
const operation = Promise.resolve().then((): Promise<unknown> => migrationId === undefined ? workflowMigrations.list(Object.freeze(base))
|
|
800
|
+
: data === undefined ? workflowMigrations.plan(Object.freeze({ ...base, migrationId }))
|
|
801
|
+
: workflowMigrations.apply(Object.freeze({ ...base, actorId: identity.scope.principalId, revision: data['revision'] as number,
|
|
802
|
+
commandId: data['commandId'] as string, migrationId }))).finally(() => { workflowOperations--; });
|
|
803
|
+
let result: unknown;
|
|
804
|
+
try { result = await bounded(operation, signal); } catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE'); }
|
|
805
|
+
assertActive(signal); requireCapability(identity, capability);
|
|
806
|
+
if (migrationId === undefined) {
|
|
807
|
+
if (result === null) throw new HttpFailure(404, 'NOT_FOUND');
|
|
808
|
+
if (!Array.isArray(result) || result.length > 256) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
809
|
+
const migrations = result.map(migrationRecord);
|
|
810
|
+
if (new Set(migrations.map(item => item.id)).size !== migrations.length) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
811
|
+
return response({ migrations });
|
|
812
|
+
}
|
|
813
|
+
if (data === undefined) {
|
|
814
|
+
if (result === null) throw new HttpFailure(404, 'NOT_FOUND');
|
|
815
|
+
return response({ plan: migrationPlan(result, runId, migrationId) });
|
|
816
|
+
}
|
|
817
|
+
let raw: JsonObject; try { raw = object(result, 524_288); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
818
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1) throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
819
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1) throw new HttpFailure(404, 'NOT_FOUND');
|
|
820
|
+
if (raw['status'] === 'refused') {
|
|
821
|
+
workflowExact(raw, ['status', 'plan']); const plan = migrationPlan(raw['plan'], runId, migrationId);
|
|
822
|
+
if (plan.allowed) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
823
|
+
return response({ plan }, 409);
|
|
824
|
+
}
|
|
825
|
+
workflowExact(raw, ['status', 'plan', 'workflow']); if (raw['status'] !== 'applied') throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
826
|
+
const plan = migrationPlan(raw['plan'], runId, migrationId); const record = workflowRecord(raw['workflow'], runId);
|
|
827
|
+
if (!plan.allowed || record.revision <= (data['revision'] as number)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
828
|
+
return response({ plan, workflow: record });
|
|
829
|
+
}
|
|
830
|
+
// Continuation and operator pause share one exact revision-bound body; each has its own least-authority adapter.
|
|
831
|
+
const workflowResumeMatch = /^\/v1\/workflow-runs\/([a-f0-9]{64})\/(resume|pause)$/.exec(url.pathname);
|
|
832
|
+
if (workflowResumeMatch && request.method === 'POST') {
|
|
833
|
+
requireCapability(identity, 'workflows:control');
|
|
834
|
+
const callback = workflowResumeMatch[2] === 'pause' ? workflowPauses?.pause : workflowResumes?.resume;
|
|
835
|
+
if (!callback) throw new HttpFailure(404, 'NOT_FOUND');
|
|
836
|
+
const data = await body(request, signal); exact(data, ['commandId', 'revision']);
|
|
837
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['revision'] !== 'number'
|
|
838
|
+
|| !Number.isSafeInteger(data['revision']) || data['revision'] < 1) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
839
|
+
if (workflowOperations >= limits.maxWorkflowOperations) throw new HttpFailure(429, 'WORKFLOW_LIMIT'); workflowOperations++;
|
|
840
|
+
const operation = Promise.resolve().then(() => callback(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds,
|
|
841
|
+
actorId: identity.scope.principalId, runId: workflowResumeMatch[1]!, revision: data['revision'] as number,
|
|
842
|
+
commandId: data['commandId'] as string, signal }))).finally(() => { workflowOperations--; });
|
|
843
|
+
let result: WorkflowControlResult;
|
|
844
|
+
try { result = await bounded(operation, signal); } catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'WORKFLOW_UNAVAILABLE'); }
|
|
845
|
+
assertActive(signal); requireCapability(identity, 'workflows:control');
|
|
846
|
+
let raw: JsonObject; try { raw = object(result, 262_144); } catch { throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID'); }
|
|
847
|
+
if (raw['status'] === 'conflict' && Object.keys(raw).length === 1) throw new HttpFailure(409, 'WORKFLOW_CONFLICT');
|
|
848
|
+
if (raw['status'] === 'not_found' && Object.keys(raw).length === 1) throw new HttpFailure(404, 'NOT_FOUND');
|
|
849
|
+
workflowExact(raw, ['status', 'workflow']); if (raw['status'] !== 'applied') throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
850
|
+
const record = workflowRecord(raw['workflow'], workflowResumeMatch[1]!);
|
|
851
|
+
if (record.revision < (data['revision'] as number)) throw new HttpFailure(503, 'WORKFLOW_TRANSPORT_INVALID');
|
|
852
|
+
return response({ workflow: record });
|
|
853
|
+
}
|
|
854
|
+
if (request.method === 'GET' && url.pathname === '/v1/agents') {
|
|
855
|
+
requireCapability(identity, 'runs:read');
|
|
856
|
+
return response({ agents: [...registry.values()].filter(config => identity.agentIds.includes(config.agent.id)).map(config => ({ id: config.agent.id, version: config.agent.version })) });
|
|
857
|
+
}
|
|
858
|
+
if (request.method === 'GET' && url.pathname === '/v1/operations/health') {
|
|
859
|
+
requireCapability(identity, 'operations:read');
|
|
860
|
+
const results = await Promise.all(healthChecks.map(async health => {
|
|
861
|
+
if (healthOperations >= limits.maxHealthOperations) return { id: health.id, status: 'unavailable' as const };
|
|
862
|
+
healthOperations++;
|
|
863
|
+
const operation = Promise.resolve().then(() => health.check(Object.freeze({ signal, scope: identity.scope })))
|
|
864
|
+
.finally(() => { healthOperations--; });
|
|
865
|
+
try { return { id: health.id, status: await bounded(operation, signal) === true ? 'ready' as const : 'unavailable' as const }; }
|
|
866
|
+
catch { return { id: health.id, status: 'unavailable' as const }; }
|
|
867
|
+
}));
|
|
868
|
+
assertActive(signal); requireCapability(identity, 'operations:read');
|
|
869
|
+
const checks = [{ id: 'server', status: 'ready' as const }, ...results];
|
|
870
|
+
const ready = checks.every(check => check.status === 'ready');
|
|
871
|
+
return response({ status: ready ? 'ready' : 'degraded', checks }, ready ? 200 : 503);
|
|
872
|
+
}
|
|
873
|
+
if (request.method === 'GET' && url.pathname === '/v1/tools') {
|
|
874
|
+
requireCapability(identity, 'operations:read');
|
|
875
|
+
const afterText = url.searchParams.get('after') ?? '0'; const limitText = url.searchParams.get('limit') ?? '50';
|
|
876
|
+
if (!/^\d+$/.test(afterText) || !/^\d+$/.test(limitText)) throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
877
|
+
const after = Number(afterText); const limit = Number(limitText);
|
|
878
|
+
if (!Number.isSafeInteger(after) || !Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
879
|
+
const visible = toolCatalog.filter(tool => identity.agentIds.includes(tool.agentId));
|
|
880
|
+
if (after > visible.length) throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
881
|
+
const tools = visible.slice(after, after + limit); const next = after + tools.length;
|
|
882
|
+
return response({ tools, next: next < visible.length ? next : null });
|
|
883
|
+
}
|
|
884
|
+
if (request.method === 'GET' && url.pathname === '/v1/human-requests') {
|
|
885
|
+
requireCapability(identity, 'humans:read'); if (!humanRequests) throw new HttpFailure(404, 'NOT_FOUND');
|
|
886
|
+
const after = url.searchParams.get('after'); const limitText = url.searchParams.get('limit') ?? '50';
|
|
887
|
+
if ((after !== null && !/^[A-Za-z0-9._:-]{1,128}$/.test(after)) || !/^\d+$/.test(limitText) || Number(limitText) < 1 || Number(limitText) > 100) throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
888
|
+
const page = await humanCall(() => humanRequests.list(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, after, limit: Number(limitText), signal })), signal);
|
|
889
|
+
const raw = object(page, 1_048_576); exact(raw, ['items', 'next']);
|
|
890
|
+
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'])))) throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
891
|
+
const items = raw['items'].map(item => humanRecord(item, identity));
|
|
892
|
+
if (new Set(items.map(item => item.id)).size !== items.length) throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
893
|
+
assertActive(signal); requireCapability(identity, 'humans:read'); return response({ items, next: raw['next'] });
|
|
894
|
+
}
|
|
895
|
+
const humanMatch = /^\/v1\/human-requests\/([A-Za-z0-9][A-Za-z0-9._-]{0,79})(?:\/responses)?$/.exec(url.pathname);
|
|
896
|
+
if (humanMatch && request.method === 'GET' && !url.pathname.endsWith('/responses')) {
|
|
897
|
+
requireCapability(identity, 'humans:read'); if (!humanRequests) throw new HttpFailure(404, 'NOT_FOUND');
|
|
898
|
+
const item = await humanCall(() => humanRequests.inspect(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, id: humanMatch[1]!, signal })), signal);
|
|
899
|
+
if (item === null) throw new HttpFailure(404, 'NOT_FOUND'); const record = humanRecord(item, identity);
|
|
900
|
+
if (record.id !== humanMatch[1]) throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
901
|
+
assertActive(signal); requireCapability(identity, 'humans:read'); return response({ request: record });
|
|
902
|
+
}
|
|
903
|
+
if (humanMatch && request.method === 'POST' && url.pathname.endsWith('/responses')) {
|
|
904
|
+
requireCapability(identity, 'humans:respond'); if (!humanRequests) throw new HttpFailure(404, 'NOT_FOUND');
|
|
905
|
+
const data = await body(request, signal); exact(data, ['commandId', 'requestDigest', 'value']);
|
|
906
|
+
if (typeof data['commandId'] !== 'string' || !identifier.test(data['commandId']) || typeof data['requestDigest'] !== 'string' || !/^[a-f0-9]{64}$/.test(data['requestDigest'])) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
907
|
+
const item = await humanCall(() => humanRequests.respond(Object.freeze({ scope: identity.scope, agentIds: identity.agentIds, actorId: identity.scope.principalId,
|
|
908
|
+
id: humanMatch[1]!, commandId: data['commandId'] as string, requestDigest: data['requestDigest'] as string, value: data['value']!, signal })), signal);
|
|
909
|
+
const record = humanRecord(item, identity);
|
|
910
|
+
if (record.id !== humanMatch[1] || record.digest !== data['requestDigest'] || record.status === 'waiting') throw new HttpFailure(503, 'HUMAN_TRANSPORT_INVALID');
|
|
911
|
+
assertActive(signal); requireCapability(identity, 'humans:respond'); return response({ request: record });
|
|
912
|
+
}
|
|
913
|
+
if (request.method === 'POST' && url.pathname === '/v1/runs') {
|
|
914
|
+
requireCapability(identity, 'runs:submit');
|
|
915
|
+
const key = request.headers.get('idempotency-key') ?? '';
|
|
916
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(key)) throw new HttpFailure(400, 'IDEMPOTENCY_REQUIRED');
|
|
917
|
+
const data = await body(request, signal); exact(data, ['agentId', 'input']);
|
|
918
|
+
const agentId = data['agentId'];
|
|
919
|
+
if (typeof agentId !== 'string' || !identity.agentIds.includes(agentId) || !registry.has(agentId)) throw new HttpFailure(404, 'NOT_FOUND');
|
|
920
|
+
const config = registry.get(agentId)!;
|
|
921
|
+
const digestBytes = await crypto.subtle.digest('SHA-256', encoder.encode(canonical({ agentId, version: config.agent.version, input: data['input']! })));
|
|
922
|
+
const digest = [...new Uint8Array(digestBytes)].map(value => value.toString(16).padStart(2, '0')).join('');
|
|
923
|
+
assertActive(signal); requireCapability(identity, 'runs:submit');
|
|
924
|
+
if (closed) throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
925
|
+
const submissionKey = JSON.stringify([owner, key]);
|
|
926
|
+
const previous = submissions.get(submissionKey) ?? await pendingSubmissions.get(submissionKey);
|
|
927
|
+
if (previous === 'duplicate') throw new HttpFailure(409, 'SUBMISSION_OUTCOME_UNKNOWN');
|
|
928
|
+
if (previous) {
|
|
929
|
+
if (previous.digest !== digest) throw new HttpFailure(409, 'IDEMPOTENCY_CONFLICT');
|
|
930
|
+
return response({ id: previous.handle.id, profile: 'ephemeral' }, 200);
|
|
931
|
+
}
|
|
932
|
+
const expired = tombstones.get(submissionKey);
|
|
933
|
+
if (expired !== undefined) throw new HttpFailure(expired === digest ? 410 : 409, expired === digest ? 'RUN_EXPIRED' : 'IDEMPOTENCY_CONFLICT');
|
|
934
|
+
const runtimeKey = JSON.stringify([owner, agentId]);
|
|
935
|
+
makeRoom(runtimeKey);
|
|
936
|
+
if (runs.size >= limits.maxRuns) throw new HttpFailure(429, 'RUN_LIMIT');
|
|
937
|
+
if (!runtimes.has(runtimeKey) && runtimes.size >= limits.maxRuntimes) throw new HttpFailure(429, 'RUNTIME_LIMIT');
|
|
938
|
+
const start = async (): Promise<Entry | 'duplicate'> => {
|
|
939
|
+
if (submissionJournal) {
|
|
940
|
+
let claim: unknown;
|
|
941
|
+
try { claim = await bounded(Promise.resolve().then(() => submissionJournal.claim(Object.freeze({ owner, key, digest, signal }))), signal); }
|
|
942
|
+
catch (error) { if (error instanceof HttpFailure && error.status === 408) throw error; throw new HttpFailure(503, 'SUBMISSION_JOURNAL_UNAVAILABLE'); }
|
|
943
|
+
const result = claim as { status?: unknown; digest?: unknown } | null;
|
|
944
|
+
if (result?.status === 'existing' && typeof result.digest === 'string') {
|
|
945
|
+
// A claim made by an earlier process: its ephemeral run is gone, so neither replay nor a new run is truthful.
|
|
946
|
+
if (result.digest !== digest) throw new HttpFailure(409, 'IDEMPOTENCY_CONFLICT');
|
|
947
|
+
return 'duplicate';
|
|
948
|
+
}
|
|
949
|
+
if (result?.status !== 'claimed') throw new HttpFailure(503, 'SUBMISSION_JOURNAL_UNAVAILABLE');
|
|
950
|
+
assertActive(signal); if (closed) throw new HttpFailure(503, 'SERVER_CLOSED');
|
|
951
|
+
}
|
|
952
|
+
makeRoom(runtimeKey);
|
|
953
|
+
if (runs.size >= limits.maxRuns) throw new HttpFailure(429, 'RUN_LIMIT');
|
|
954
|
+
let runtime = runtimes.get(runtimeKey);
|
|
955
|
+
if (!runtime) {
|
|
956
|
+
if (runtimes.size >= limits.maxRuntimes) throw new HttpFailure(429, 'RUNTIME_LIMIT');
|
|
957
|
+
runtime = createRuntime({ profile: 'ephemeral', scope: identity.scope, permissions: config.permissions, ...(config.limits ? { limits: config.limits } : {}) });
|
|
958
|
+
runtimes.set(runtimeKey, runtime);
|
|
959
|
+
}
|
|
960
|
+
const handle = runtime.submit(config.agent, { input: data['input'] });
|
|
961
|
+
const entry: Entry = { owner, agentId, digest, handle, runtime, runtimeKey, submissionKey };
|
|
962
|
+
runs.set(handle.id, entry); submissions.set(submissionKey, entry);
|
|
963
|
+
retained.set(runtimeKey, (retained.get(runtimeKey) ?? 0) + 1);
|
|
964
|
+
void handle.result().then(outcome => {
|
|
965
|
+
entry.outcome = outcome; entry.finished = true;
|
|
966
|
+
if (closed) return;
|
|
967
|
+
const timer = setTimeout(() => { retentionTimers.delete(timer); release(entry); }, limits.runRetentionMs);
|
|
968
|
+
(timer as { unref?: () => void }).unref?.(); retentionTimers.add(timer);
|
|
969
|
+
});
|
|
970
|
+
return entry;
|
|
971
|
+
};
|
|
972
|
+
const pending = start(); pendingSubmissions.set(submissionKey, pending);
|
|
973
|
+
let started: Entry | 'duplicate';
|
|
974
|
+
try { started = await pending; } finally { pendingSubmissions.delete(submissionKey); }
|
|
975
|
+
if (started === 'duplicate') throw new HttpFailure(409, 'SUBMISSION_OUTCOME_UNKNOWN');
|
|
976
|
+
return response({ id: started.handle.id, profile: 'ephemeral' }, 202);
|
|
977
|
+
}
|
|
978
|
+
const match = /^\/v1\/runs\/([a-f0-9-]{36})(?:\/(cancel|events))?$/.exec(url.pathname);
|
|
979
|
+
if (!match) throw new HttpFailure(404, 'NOT_FOUND');
|
|
980
|
+
const entry = runs.get(match[1]!);
|
|
981
|
+
if (!entry || entry.owner !== owner || !identity.agentIds.includes(entry.agentId)) throw new HttpFailure(404, 'NOT_FOUND');
|
|
982
|
+
if (request.method === 'POST' && match[2] === 'cancel') {
|
|
983
|
+
requireCapability(identity, 'runs:cancel');
|
|
984
|
+
if (request.body !== null) throw new HttpFailure(400, 'INVALID_REQUEST');
|
|
985
|
+
assertActive(signal); entry.handle.cancel();
|
|
986
|
+
return response({ id: entry.handle.id, cancellationRequested: true }, 202);
|
|
987
|
+
}
|
|
988
|
+
if (request.method === 'GET' && match[2] === 'events') {
|
|
989
|
+
requireCapability(identity, 'runs:read');
|
|
990
|
+
const cursor = url.searchParams.get('after') ?? '0';
|
|
991
|
+
if (!/^\d+$/.test(cursor) || !Number.isSafeInteger(Number(cursor))) throw new HttpFailure(400, 'INVALID_CURSOR');
|
|
992
|
+
assertActive(signal); return eventResponse(entry, Number(cursor), identity, request);
|
|
993
|
+
}
|
|
994
|
+
if (request.method === 'GET' && !match[2]) {
|
|
995
|
+
requireCapability(identity, 'runs:read');
|
|
996
|
+
if (entry.outcome) entry.collected = true;
|
|
997
|
+
return response({ ...entry.runtime.inspect(entry.handle), ...(entry.outcome ? { outcome: entry.outcome } : {}) });
|
|
998
|
+
}
|
|
999
|
+
throw new HttpFailure(405, 'METHOD_NOT_ALLOWED');
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
return Object.freeze({
|
|
1003
|
+
async fetch(request: Request): Promise<Response> {
|
|
1004
|
+
if (closed) return response({ error: { code: 'SERVER_CLOSED' } }, 503);
|
|
1005
|
+
if (requests >= limits.maxRequests) return response({ error: { code: 'REQUEST_LIMIT' } }, 429);
|
|
1006
|
+
requests++;
|
|
1007
|
+
const controller = new AbortController();
|
|
1008
|
+
const abort = (): void => { controller.abort(); };
|
|
1009
|
+
request.signal.addEventListener('abort', abort, { once: true });
|
|
1010
|
+
if (request.signal.aborted) abort();
|
|
1011
|
+
const timer = setTimeout(abort, limits.requestTimeoutMs);
|
|
1012
|
+
let result: Response;
|
|
1013
|
+
try { result = await bounded(route(request, controller.signal).catch(error => {
|
|
1014
|
+
throw error instanceof HttpFailure ? error : new HttpFailure(400, 'INVALID_REQUEST');
|
|
1015
|
+
}), controller.signal); }
|
|
1016
|
+
catch (error) {
|
|
1017
|
+
const failure = error instanceof HttpFailure ? error : new HttpFailure(503, 'SERVICE_UNAVAILABLE');
|
|
1018
|
+
result = response({ error: { code: failure.code } }, failure.status);
|
|
1019
|
+
} finally { requests--; clearTimeout(timer); request.signal.removeEventListener('abort', abort); }
|
|
1020
|
+
const requestOrigin = request.headers.get('origin');
|
|
1021
|
+
if (requestOrigin && origins.has(requestOrigin)) {
|
|
1022
|
+
result.headers.set('Access-Control-Allow-Origin', requestOrigin); result.headers.set('Vary', 'Origin');
|
|
1023
|
+
}
|
|
1024
|
+
return result;
|
|
1025
|
+
},
|
|
1026
|
+
async close(): Promise<void> {
|
|
1027
|
+
closed = true;
|
|
1028
|
+
for (const timer of retentionTimers) clearTimeout(timer); retentionTimers.clear();
|
|
1029
|
+
for (const finish of [...streams]) finish();
|
|
1030
|
+
await Promise.all([...runtimes.values()].map(runtime => runtime.close()));
|
|
1031
|
+
},
|
|
1032
|
+
});
|
|
1033
|
+
}
|