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,265 @@
|
|
|
1
|
+
import { assertPositiveInteger, freezeJson, jsonValue, MayuraError } from '../../core/dist/index.js';
|
|
2
|
+
import { evaluateLifecycleControl, snapshotHookOptions } from '../../core/dist/host.js';
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
const inputBytes = 4_194_304;
|
|
5
|
+
const protectedKinds = new Set(['hard_constraint', 'pending_approval', 'unresolved_blocker', 'outstanding_task']);
|
|
6
|
+
const kinds = new Set(['evidence', 'instruction', ...protectedKinds]);
|
|
7
|
+
const sensitivities = new Set(['public', 'internal', 'confidential', 'restricted']);
|
|
8
|
+
const trusts = new Set(['untrusted', 'reviewed', 'trusted']);
|
|
9
|
+
const sourceKinds = new Set(['document', 'conversation', 'memory', 'artifact', 'repository', 'tool', 'application']);
|
|
10
|
+
/** A transparent heuristic; provider framing/tokenization must still be admitted separately. */
|
|
11
|
+
export const byteTokenEstimator = Object.freeze({ id: 'utf8-bytes-v1', estimate: (text) => encoder.encode(text).length });
|
|
12
|
+
function invalid(message) { throw new MayuraError('INVALID_INPUT', message); }
|
|
13
|
+
function text(value, label, maximum = 256) {
|
|
14
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > maximum)
|
|
15
|
+
return invalid(`${label} must be a bounded nonempty string.`);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function object(value) {
|
|
19
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
20
|
+
return invalid('Context metadata must be a plain JSON object.');
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function scopeOf(value) {
|
|
24
|
+
const scope = object(value);
|
|
25
|
+
return Object.freeze({ principalId: text(scope['principalId'], 'principalId'), projectId: text(scope['projectId'], 'projectId') });
|
|
26
|
+
}
|
|
27
|
+
function sameScope(one, two) { return one.principalId === two.principalId && one.projectId === two.projectId; }
|
|
28
|
+
function safeJson(value, maxBytes = inputBytes) {
|
|
29
|
+
try {
|
|
30
|
+
return freezeJson(jsonValue(value, { maxBytes }));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return invalid('Context input must satisfy plain-JSON and input-size limits.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function canonical(value) {
|
|
37
|
+
if (value === null || typeof value !== 'object')
|
|
38
|
+
return JSON.stringify(value);
|
|
39
|
+
if (Array.isArray(value))
|
|
40
|
+
return `[${value.map(canonical).join(',')}]`;
|
|
41
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`;
|
|
42
|
+
}
|
|
43
|
+
async function hash(domain, value) {
|
|
44
|
+
const bytes = await crypto.subtle.digest('SHA-256', encoder.encode(`${domain}\0${value}`));
|
|
45
|
+
return [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
46
|
+
}
|
|
47
|
+
function canonicalTime(value, label = 'observedAt') {
|
|
48
|
+
const timestamp = text(value, label, 32);
|
|
49
|
+
const time = Date.parse(timestamp);
|
|
50
|
+
if (!Number.isFinite(time) || new Date(time).toISOString() !== timestamp)
|
|
51
|
+
return invalid(`${label} must be a canonical UTC ISO timestamp.`);
|
|
52
|
+
return timestamp;
|
|
53
|
+
}
|
|
54
|
+
function upstreamOf(value) {
|
|
55
|
+
const supplied = object(value);
|
|
56
|
+
const sha256 = supplied['sha256'];
|
|
57
|
+
if (typeof sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(sha256))
|
|
58
|
+
return invalid('Upstream evidence SHA-256 must contain 64 lowercase hexadecimal characters.');
|
|
59
|
+
return Object.freeze({ sourceId: text(supplied['sourceId'], 'upstream.sourceId'), revision: text(supplied['revision'], 'upstream.revision'), sha256 });
|
|
60
|
+
}
|
|
61
|
+
function validityOf(value) {
|
|
62
|
+
const supplied = object(value);
|
|
63
|
+
const from = canonicalTime(supplied['from'], 'validity.from');
|
|
64
|
+
const until = supplied['until'] === null ? null : canonicalTime(supplied['until'], 'validity.until');
|
|
65
|
+
if (until !== null && Date.parse(until) <= Date.parse(from))
|
|
66
|
+
return invalid('Context validity must end after it begins.');
|
|
67
|
+
return Object.freeze({ from, until });
|
|
68
|
+
}
|
|
69
|
+
function readCandidate(value, scope) {
|
|
70
|
+
const sourceInput = object(value['source']);
|
|
71
|
+
const source = Object.freeze({ id: text(sourceInput['id'], 'source.id'), revision: text(sourceInput['revision'], 'source.revision'), kind: sourceInput['kind'] });
|
|
72
|
+
if (!sourceKinds.has(source.kind))
|
|
73
|
+
return invalid('Unknown context source kind.');
|
|
74
|
+
const supplied = object(value['provenance']);
|
|
75
|
+
const confidence = supplied['confidence'];
|
|
76
|
+
if (typeof confidence !== 'number' || !Number.isFinite(confidence) || confidence < 0 || confidence > 1)
|
|
77
|
+
return invalid('Provenance confidence must be between zero and one.');
|
|
78
|
+
const origin = supplied['origin'];
|
|
79
|
+
if (origin !== 'observed' && origin !== 'inferred')
|
|
80
|
+
return invalid('Unknown provenance origin.');
|
|
81
|
+
const provenance = Object.freeze({ reference: text(supplied['reference'], 'provenance.reference', 2_048), observedAt: canonicalTime(supplied['observedAt']), origin, confidence,
|
|
82
|
+
...(supplied['author'] === undefined ? {} : { author: text(supplied['author'], 'provenance.author') }),
|
|
83
|
+
...(supplied['upstream'] === undefined ? {} : { upstream: upstreamOf(supplied['upstream']) }),
|
|
84
|
+
});
|
|
85
|
+
const kind = value['kind'];
|
|
86
|
+
const trust = value['trust'];
|
|
87
|
+
const sensitivity = value['sensitivity'];
|
|
88
|
+
if (!kinds.has(kind) || !trusts.has(trust) || !sensitivities.has(sensitivity))
|
|
89
|
+
return invalid('Unknown context category, trust, or sensitivity.');
|
|
90
|
+
const priority = value['priority'] ?? 0;
|
|
91
|
+
const pinned = value['pinned'] ?? false;
|
|
92
|
+
if (typeof priority !== 'number' || !Number.isSafeInteger(priority) || Math.abs(priority) > 1_000_000 || typeof pinned !== 'boolean')
|
|
93
|
+
return invalid('Context priority or pin metadata is invalid.');
|
|
94
|
+
return Object.freeze({ id: text(value['id'], 'candidate.id'), scope, source, provenance, kind, trust, sensitivity, priority, pinned,
|
|
95
|
+
...(value['validity'] === undefined ? {} : { validity: validityOf(value['validity']) }),
|
|
96
|
+
required: pinned || protectedKinds.has(kind), content: safeJson(value['content'], 262_144),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/** Select current authorized evidence without silently dropping required continuity items or inventing summaries. */
|
|
100
|
+
export async function assembleContext(options) {
|
|
101
|
+
// Snapshot all caller-controlled JSON before the first await; later mutations cannot change admission.
|
|
102
|
+
const suppliedAsOf = options.asOf;
|
|
103
|
+
const asOf = canonicalTime(suppliedAsOf === undefined ? new Date().toISOString() : suppliedAsOf, 'asOf');
|
|
104
|
+
const asOfTime = Date.parse(asOf);
|
|
105
|
+
const scope = scopeOf(safeJson(options.scope));
|
|
106
|
+
const policyVersion = text(options.policyVersion, 'policyVersion', 128);
|
|
107
|
+
const rawCandidates = safeJson(options.candidates);
|
|
108
|
+
const rawSources = safeJson(options.sources, 1_048_576);
|
|
109
|
+
if (!Array.isArray(rawCandidates) || rawCandidates.length > 512 || !Array.isArray(rawSources) || rawSources.length > 1_024)
|
|
110
|
+
return invalid('At most 512 context candidates and 1024 source states are supported per assembly.');
|
|
111
|
+
const allowedInput = safeJson(options.allowedSensitivities, 256);
|
|
112
|
+
if (!Array.isArray(allowedInput) || allowedInput.some((value) => typeof value !== 'string' || !sensitivities.has(value)))
|
|
113
|
+
return invalid('An explicit sensitivity allow-list is required.');
|
|
114
|
+
const allowed = new Set(allowedInput);
|
|
115
|
+
const suppliedBudget = object(safeJson(options.budget, 1_024));
|
|
116
|
+
const maxBytes = suppliedBudget['maxBytes'];
|
|
117
|
+
const maxEstimatedTokens = suppliedBudget['maxEstimatedTokens'];
|
|
118
|
+
assertPositiveInteger(maxBytes, 'maxBytes');
|
|
119
|
+
assertPositiveInteger(maxEstimatedTokens, 'maxEstimatedTokens');
|
|
120
|
+
const reservedBytes = suppliedBudget['reservedBytes'] ?? 0;
|
|
121
|
+
const reservedTokens = suppliedBudget['reservedTokens'] ?? 0;
|
|
122
|
+
if (typeof reservedBytes !== 'number' || !Number.isSafeInteger(reservedBytes) || reservedBytes < 0 || typeof reservedTokens !== 'number' || !Number.isSafeInteger(reservedTokens) || reservedTokens < 0)
|
|
123
|
+
return invalid('Reserved capacity must be non-negative safe integers.');
|
|
124
|
+
if (reservedBytes > maxBytes || reservedTokens > maxEstimatedTokens)
|
|
125
|
+
throw new MayuraError('LIMIT_EXCEEDED', 'Reserved capacity exhausts the configured context budget.');
|
|
126
|
+
const estimatorInput = options.estimator ?? byteTokenEstimator;
|
|
127
|
+
const estimatorId = text(estimatorInput.id, 'estimator.id', 128);
|
|
128
|
+
if (typeof estimatorInput.estimate !== 'function')
|
|
129
|
+
return invalid('A callable local token estimator is required.');
|
|
130
|
+
const estimate = estimatorInput.estimate.bind(estimatorInput);
|
|
131
|
+
const hooks = contextHooks(options.hooks);
|
|
132
|
+
const signal = options.signal;
|
|
133
|
+
if (signal !== undefined && !(signal instanceof AbortSignal))
|
|
134
|
+
return invalid('signal must be an AbortSignal.');
|
|
135
|
+
if (hooks.before)
|
|
136
|
+
await evaluateLifecycleControl({ stage: 'beforeContextBuild', handler: hooks.before, timeoutMs: hooks.timeoutMs, ...(signal ? { signal } : {}),
|
|
137
|
+
event: { scope: { ...scope }, policyVersion, asOf, candidateCount: rawCandidates.length, sourceCount: rawSources.length,
|
|
138
|
+
budget: { maxBytes, maxEstimatedTokens, reservedBytes, reservedTokens } } });
|
|
139
|
+
const sources = new Map();
|
|
140
|
+
for (const raw of rawSources) {
|
|
141
|
+
const value = object(raw);
|
|
142
|
+
const sourceScope = scopeOf(value['scope']);
|
|
143
|
+
if (!sameScope(sourceScope, scope))
|
|
144
|
+
continue;
|
|
145
|
+
const id = text(value['id'], 'source.id');
|
|
146
|
+
const revision = text(value['revision'], 'source.revision');
|
|
147
|
+
const status = value['status'];
|
|
148
|
+
if (status !== 'active' && status !== 'deleted')
|
|
149
|
+
return invalid('Unknown current source state.');
|
|
150
|
+
if (sources.has(id))
|
|
151
|
+
throw new MayuraError('CONFLICT', 'Current-scope source states must have unique IDs.');
|
|
152
|
+
sources.set(id, Object.freeze({ scope: sourceScope, id, revision, status }));
|
|
153
|
+
}
|
|
154
|
+
const excluded = [];
|
|
155
|
+
const eligible = [];
|
|
156
|
+
const candidateIds = new Set();
|
|
157
|
+
for (const [position, raw] of rawCandidates.entries()) {
|
|
158
|
+
const value = object(raw);
|
|
159
|
+
const candidateScope = scopeOf(value['scope']);
|
|
160
|
+
if (!sameScope(candidateScope, scope)) {
|
|
161
|
+
excluded.push(Object.freeze({ position, reason: 'scope_mismatch' }));
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const candidate = readCandidate(value, candidateScope);
|
|
165
|
+
if (candidateIds.has(candidate.id))
|
|
166
|
+
throw new MayuraError('CONFLICT', 'Current-scope context candidates must have unique IDs.');
|
|
167
|
+
candidateIds.add(candidate.id);
|
|
168
|
+
let reason;
|
|
169
|
+
const current = sources.get(candidate.source.id);
|
|
170
|
+
if (!allowed.has(candidate.sensitivity))
|
|
171
|
+
reason = 'sensitivity_denied';
|
|
172
|
+
else if (!current)
|
|
173
|
+
reason = 'source_missing';
|
|
174
|
+
else if (current.status === 'deleted')
|
|
175
|
+
reason = 'source_deleted';
|
|
176
|
+
else if (current.revision !== candidate.source.revision)
|
|
177
|
+
reason = 'stale_revision';
|
|
178
|
+
else if (candidate.validity && Date.parse(candidate.validity.from) > asOfTime)
|
|
179
|
+
reason = 'not_yet_valid';
|
|
180
|
+
else if (candidate.validity?.until !== undefined && candidate.validity.until !== null && Date.parse(candidate.validity.until) <= asOfTime)
|
|
181
|
+
reason = 'expired';
|
|
182
|
+
if (reason) {
|
|
183
|
+
if (candidate.required)
|
|
184
|
+
throw new MayuraError(reason === 'sensitivity_denied' ? 'PERMISSION_DENIED' : 'CONFLICT', 'A required continuity item is unavailable, stale, deleted, outside its validity interval, or denied; refresh or resolve it explicitly.');
|
|
185
|
+
excluded.push(Object.freeze({ position, reason, ...(reason === 'sensitivity_denied' ? {} : { candidateId: candidate.id, sourceId: candidate.source.id, revision: candidate.source.revision }) }));
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
eligible.push({ item: candidate, position });
|
|
189
|
+
}
|
|
190
|
+
eligible.sort((left, right) => {
|
|
191
|
+
const one = left.item;
|
|
192
|
+
const two = right.item;
|
|
193
|
+
if (one.required !== two.required)
|
|
194
|
+
return one.required ? -1 : 1;
|
|
195
|
+
if (one.priority !== two.priority)
|
|
196
|
+
return two.priority - one.priority;
|
|
197
|
+
if (one.provenance.observedAt !== two.provenance.observedAt)
|
|
198
|
+
return Date.parse(one.provenance.observedAt) > Date.parse(two.provenance.observedAt) ? -1 : 1;
|
|
199
|
+
return one.id < two.id ? -1 : one.id > two.id ? 1 : 0;
|
|
200
|
+
});
|
|
201
|
+
const candidates = await Promise.all(eligible.map(async ({ item, position }) => ({ position, item: Object.freeze({ ...item, contentDigest: await hash('mayura:context-content:v1', canonical(item.content)) }) })));
|
|
202
|
+
const encode = (items) => canonical(jsonValue({ format: 1, scope, policyVersion, asOf, items }, { maxBytes: 8_388_608 }));
|
|
203
|
+
const measure = (items) => {
|
|
204
|
+
const serialized = encode(items);
|
|
205
|
+
const bytes = encoder.encode(serialized).length;
|
|
206
|
+
let estimatedTokens;
|
|
207
|
+
try {
|
|
208
|
+
estimatedTokens = estimate(serialized);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
throw new MayuraError('INVALID_CONFIG', 'The token estimator failed; raw exception details are withheld.');
|
|
212
|
+
}
|
|
213
|
+
if (!Number.isSafeInteger(estimatedTokens) || estimatedTokens < 0)
|
|
214
|
+
throw new MayuraError('INVALID_CONFIG', 'The token estimator must return a non-negative safe integer.');
|
|
215
|
+
const reason = bytes > maxBytes - reservedBytes ? 'byte_budget' : estimatedTokens > maxEstimatedTokens - reservedTokens ? 'token_budget' : undefined;
|
|
216
|
+
return { serialized, bytes, estimatedTokens, reason };
|
|
217
|
+
};
|
|
218
|
+
const selected = candidates.filter(({ item }) => item.required).map(({ item }) => item);
|
|
219
|
+
let measured = measure(selected);
|
|
220
|
+
if (measured.reason)
|
|
221
|
+
throw new MayuraError('LIMIT_EXCEEDED', 'Required continuity items and context framing do not fit the reserved context budget.');
|
|
222
|
+
for (const candidate of candidates) {
|
|
223
|
+
if (candidate.item.required)
|
|
224
|
+
continue;
|
|
225
|
+
const next = measure([...selected, candidate.item]);
|
|
226
|
+
if (next.reason)
|
|
227
|
+
excluded.push(Object.freeze({ position: candidate.position, reason: next.reason,
|
|
228
|
+
candidateId: candidate.item.id, sourceId: candidate.item.source.id, revision: candidate.item.source.revision,
|
|
229
|
+
}));
|
|
230
|
+
else {
|
|
231
|
+
selected.push(candidate.item);
|
|
232
|
+
measured = next;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
excluded.sort((one, two) => one.position - two.position);
|
|
236
|
+
const budget = { maxBytes, maxEstimatedTokens, reservedBytes, reservedTokens };
|
|
237
|
+
const fingerprint = await hash('mayura:context-assembly:v1', canonical(jsonValue({ serialized: measured.serialized, budget, estimatorId, allowedSensitivities: [...allowed].sort() }, { maxBytes: 16_777_216 })));
|
|
238
|
+
const assembly = Object.freeze({ scope, policyVersion, asOf, selected: Object.freeze(selected), excluded: Object.freeze(excluded), serialized: measured.serialized, fingerprint,
|
|
239
|
+
usage: Object.freeze({ bytes: measured.bytes, estimatedTokens: measured.estimatedTokens, reservedBytes, reservedTokens, maxBytes, maxEstimatedTokens, estimatorId }),
|
|
240
|
+
});
|
|
241
|
+
if (hooks.after)
|
|
242
|
+
await evaluateLifecycleControl({ stage: 'afterContextBuild', handler: hooks.after, timeoutMs: hooks.timeoutMs, ...(signal ? { signal } : {}),
|
|
243
|
+
event: { scope: { ...scope }, policyVersion, asOf, fingerprint,
|
|
244
|
+
selected: selected.map(item => ({ id: item.id, sourceId: item.source.id, revision: item.source.revision, contentDigest: item.contentDigest })),
|
|
245
|
+
excluded: excluded.map(entry => ({ ...entry })), usage: { ...assembly.usage } } });
|
|
246
|
+
return assembly;
|
|
247
|
+
}
|
|
248
|
+
/** Read hook options once, as own data properties, before the first await. */
|
|
249
|
+
function contextHooks(value) {
|
|
250
|
+
const { handlers, timeoutMs } = snapshotHookOptions(value, ['beforeContextBuild', 'afterContextBuild'], 'Context hooks require callable beforeContextBuild/afterContextBuild handlers and a bounded timeout.');
|
|
251
|
+
return { ...(handlers.beforeContextBuild ? { before: handlers.beforeContextBuild } : {}),
|
|
252
|
+
...(handlers.afterContextBuild ? { after: handlers.afterContextBuild } : {}), timeoutMs };
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Internal cache key: a digest of every admission input except hooks and signals, which a cache re-runs.
|
|
256
|
+
* Any change to candidates, source revisions, scope, policy, time, sensitivity profile, budget or estimator changes it.
|
|
257
|
+
*/
|
|
258
|
+
export async function admissionKey(options, asOf) {
|
|
259
|
+
const material = safeJson({ scope: options.scope, policyVersion: options.policyVersion, asOf,
|
|
260
|
+
candidates: options.candidates, sources: options.sources,
|
|
261
|
+
allowedSensitivities: options.allowedSensitivities, budget: options.budget,
|
|
262
|
+
estimatorId: (options.estimator ?? byteTokenEstimator).id });
|
|
263
|
+
return hash('mayura:context-admission:v1', canonical(material));
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=assemble.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assemble.js","sourceRoot":"","sources":["../src/assemble.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAA8B,MAAM,cAAc,CAAC;AACrH,OAAO,EAAE,wB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,IAAI;QAClH,UAAU,EAAE,OAAO,CAAC,UAAkC,EAAE,OAAO,EAAE,OAAO,CAAC,OAA+B;QACxG,oBAAoB,EAAE,OAAO,CAAC,oBAA4C,EAAE,MAAM,EAAE,OAAO,CAAC,MAA8B;QAC1H,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC,6BAA6B,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import { assertPositiveInteger, freezeJson, jsonValue, MayuraError, type JsonValue, type Scope } from '@mayura/core';\nimport { evaluateLifecycleControl, snapshotHookOptions } from '@mayura/core/host';\nimport type { AssembleContextOptions, ContextAssembly, ContextHooks, ContextCandidate, ContextExclusion, ContextItem, ContextKind, ContextProvenance, ContextSource, ContextTrust, ContextValidity, ExclusionReason, Sensitivity, SourceKind, SourceState, TokenEstimator, UpstreamEvidence } from './contracts.js';\n\nconst encoder = new TextEncoder();\nconst inputBytes = 4_194_304;\nconst protectedKinds = new Set<ContextKind>(['hard_constraint', 'pending_approval', 'unresolved_blocker', 'outstanding_task']);\nconst kinds = new Set<ContextKind>(['evidence', 'instruction', ...protectedKinds]);\nconst sensitivities = new Set<Sensitivity>(['public', 'internal', 'confidential', 'restricted']);\nconst trusts = new Set<ContextTrust>(['untrusted', 'reviewed', 'trusted']);\nconst sourceKinds = new Set<SourceKind>(['document', 'conversation', 'memory', 'artifact', 'repository', 'tool', 'application']);\n\n/** A transparent heuristic; provider framing/tokenization must still be admitted separately. */\nexport const byteTokenEstimator: TokenEstimator = Object.freeze({ id: 'utf8-bytes-v1', estimate: (text: string) => encoder.encode(text).length });\n\nfunction invalid(message: string): never { throw new MayuraError('INVALID_INPUT', message); }\nfunction text(value: unknown, label: string, maximum = 256): string {\n if (typeof value !== 'string' || value.length === 0 || value.length > maximum) return invalid(`${label} must be a bounded nonempty string.`);\n return value;\n}\nfunction object(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return invalid('Context metadata must be a plain JSON object.');\n return value as Record<string, unknown>;\n}\nfunction scopeOf(value: unknown): Scope {\n const scope = object(value);\n return Object.freeze({ principalId: text(scope['principalId'], 'principalId'), projectId: text(scope['projectId'], 'projectId') });\n}\nfunction sameScope(one: Scope, two: Scope): boolean { return one.principalId === two.principalId && one.projectId === two.projectId; }\nfunction safeJson(value: unknown, maxBytes = inputBytes): JsonValue {\n try { return freezeJson(jsonValue(value, { maxBytes })); }\n catch { return invalid('Context input must satisfy plain-JSON and input-size limits.'); }\n}\nfunction canonical(value: JsonValue): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value);\n if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;\n return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key]!)}`).join(',')}}`;\n}\nasync function hash(domain: string, value: string): Promise<string> {\n const bytes = await crypto.subtle.digest('SHA-256', encoder.encode(`${domain}\\0${value}`));\n return [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, '0')).join('');\n}\nfunction canonicalTime(value: unknown, label = 'observedAt'): string {\n const timestamp = text(value, label, 32);\n const time = Date.parse(timestamp);\n if (!Number.isFinite(time) || new Date(time).toISOString() !== timestamp) return invalid(`${label} must be a canonical UTC ISO timestamp.`);\n return timestamp;\n}\nfunction upstreamOf(value: unknown): UpstreamEvidence {\n const supplied = object(value);\n const sha256 = supplied['sha256'];\n if (typeof sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(sha256)) return invalid('Upstream evidence SHA-256 must contain 64 lowercase hexadecimal characters.');\n return Object.freeze({ sourceId: text(supplied['sourceId'], 'upstream.sourceId'), revision: text(supplied['revision'], 'upstream.revision'), sha256 });\n}\nfunction validityOf(value: unknown): ContextValidity {\n const supplied = object(value);\n const from = canonicalTime(supplied['from'], 'validity.from');\n const until = supplied['until'] === null ? null : canonicalTime(supplied['until'], 'validity.until');\n if (until !== null && Date.parse(until) <= Date.parse(from)) return invalid('Context validity must end after it begins.');\n return Object.freeze({ from, until });\n}\nfunction readCandidate(value: Record<string, unknown>, scope: Scope): ContextCandidate & { readonly priority: number; readonly pinned: boolean; readonly required: boolean } {\n const sourceInput = object(value['source']);\n const source: ContextSource = Object.freeze({ id: text(sourceInput['id'], 'source.id'), revision: text(sourceInput['revision'], 'source.revision'), kind: sourceInput['kind'] as SourceKind });\n if (!sourceKinds.has(source.kind)) return invalid('Unknown context source kind.');\n const supplied = object(value['provenance']);\n const confidence = supplied['confidence'];\n if (typeof confidence !== 'number' || !Number.isFinite(confidence) || confidence < 0 || confidence > 1) return invalid('Provenance confidence must be between zero and one.');\n const origin = supplied['origin'];\n if (origin !== 'observed' && origin !== 'inferred') return invalid('Unknown provenance origin.');\n const provenance: ContextProvenance = Object.freeze({ reference: text(supplied['reference'], 'provenance.reference', 2_048), observedAt: canonicalTime(supplied['observedAt']), origin, confidence,\n ...(supplied['author'] === undefined ? {} : { author: text(supplied['author'], 'provenance.author') }),\n ...(supplied['upstream'] === undefined ? {} : { upstream: upstreamOf(supplied['upstream']) }),\n });\n const kind = value['kind'] as ContextKind; const trust = value['trust'] as ContextTrust; const sensitivity = value['sensitivity'] as Sensitivity;\n if (!kinds.has(kind) || !trusts.has(trust) || !sensitivities.has(sensitivity)) return invalid('Unknown context category, trust, or sensitivity.');\n const priority = value['priority'] ?? 0; const pinned = value['pinned'] ?? false;\n if (typeof priority !== 'number' || !Number.isSafeInteger(priority) || Math.abs(priority) > 1_000_000 || typeof pinned !== 'boolean') return invalid('Context priority or pin metadata is invalid.');\n return Object.freeze({ id: text(value['id'], 'candidate.id'), scope, source, provenance, kind, trust, sensitivity, priority, pinned,\n ...(value['validity'] === undefined ? {} : { validity: validityOf(value['validity']) }),\n required: pinned || protectedKinds.has(kind), content: safeJson(value['content'], 262_144),\n });\n}\n\n/** Select current authorized evidence without silently dropping required continuity items or inventing summaries. */\nexport async function assembleContext(options: AssembleContextOptions): Promise<ContextAssembly> {\n // Snapshot all caller-controlled JSON before the first await; later mutations cannot change admission.\n const suppliedAsOf = options.asOf;\n const asOf = canonicalTime(suppliedAsOf === undefined ? new Date().toISOString() : suppliedAsOf, 'asOf');\n const asOfTime = Date.parse(asOf);\n const scope = scopeOf(safeJson(options.scope));\n const policyVersion = text(options.policyVersion, 'policyVersion', 128);\n const rawCandidates = safeJson(options.candidates);\n const rawSources = safeJson(options.sources, 1_048_576);\n if (!Array.isArray(rawCandidates) || rawCandidates.length > 512 || !Array.isArray(rawSources) || rawSources.length > 1_024) return invalid('At most 512 context candidates and 1024 source states are supported per assembly.');\n const allowedInput = safeJson(options.allowedSensitivities, 256);\n if (!Array.isArray(allowedInput) || allowedInput.some((value) => typeof value !== 'string' || !sensitivities.has(value as Sensitivity))) return invalid('An explicit sensitivity allow-list is required.');\n const allowed = new Set(allowedInput as Sensitivity[]);\n const suppliedBudget = object(safeJson(options.budget, 1_024));\n const maxBytes = suppliedBudget['maxBytes'] as number; const maxEstimatedTokens = suppliedBudget['maxEstimatedTokens'] as number;\n assertPositiveInteger(maxBytes, 'maxBytes'); assertPositiveInteger(maxEstimatedTokens, 'maxEstimatedTokens');\n const reservedBytes = suppliedBudget['reservedBytes'] ?? 0; const reservedTokens = suppliedBudget['reservedTokens'] ?? 0;\n if (typeof reservedBytes !== 'number' || !Number.isSafeInteger(reservedBytes) || reservedBytes < 0 || typeof reservedTokens !== 'number' || !Number.isSafeInteger(reservedTokens) || reservedTokens < 0) return invalid('Reserved capacity must be non-negative safe integers.');\n if (reservedBytes > maxBytes || reservedTokens > maxEstimatedTokens) throw new MayuraError('LIMIT_EXCEEDED', 'Reserved capacity exhausts the configured context budget.');\n const estimatorInput = options.estimator ?? byteTokenEstimator;\n const estimatorId = text(estimatorInput.id, 'estimator.id', 128);\n if (typeof estimatorInput.estimate !== 'function') return invalid('A callable local token estimator is required.');\n const estimate = estimatorInput.estimate.bind(estimatorInput);\n const hooks = contextHooks(options.hooks); const signal = options.signal;\n if (signal !== undefined && !(signal instanceof AbortSignal)) return invalid('signal must be an AbortSignal.');\n if (hooks.before) await evaluateLifecycleControl({ stage: 'beforeContextBuild', handler: hooks.before, timeoutMs: hooks.timeoutMs, ...(signal ? { signal } : {}),\n event: { scope: { ...scope }, policyVersion, asOf, candidateCount: rawCandidates.length, sourceCount: rawSources.length,\n budget: { maxBytes, maxEstimatedTokens, reservedBytes, reservedTokens } } });\n const sources = new Map<string, SourceState>();\n for (const raw of rawSources) {\n const value = object(raw); const sourceScope = scopeOf(value['scope']);\n if (!sameScope(sourceScope, scope)) continue;\n const id = text(value['id'], 'source.id'); const revision = text(value['revision'], 'source.revision'); const status = value['status'];\n if (status !== 'active' && status !== 'deleted') return invalid('Unknown current source state.');\n if (sources.has(id)) throw new MayuraError('CONFLICT', 'Current-scope source states must have unique IDs.');\n sources.set(id, Object.freeze({ scope: sourceScope, id, revision, status }));\n }\n const excluded: ContextExclusion[] = [];\n const eligible: { readonly item: ReturnType<typeof readCandidate>; readonly position: number }[] = [];\n const candidateIds = new Set<string>();\n for (const [position, raw] of rawCandidates.entries()) {\n const value = object(raw); const candidateScope = scopeOf(value['scope']);\n if (!sameScope(candidateScope, scope)) { excluded.push(Object.freeze({ position, reason: 'scope_mismatch' })); continue; }\n const candidate = readCandidate(value, candidateScope);\n if (candidateIds.has(candidate.id)) throw new MayuraError('CONFLICT', 'Current-scope context candidates must have unique IDs.');\n candidateIds.add(candidate.id);\n let reason: ExclusionReason | undefined;\n const current = sources.get(candidate.source.id);\n if (!allowed.has(candidate.sensitivity)) reason = 'sensitivity_denied';\n else if (!current) reason = 'source_missing';\n else if (current.status === 'deleted') reason = 'source_deleted';\n else if (current.revision !== candidate.source.revision) reason = 'stale_revision';\n else if (candidate.validity && Date.parse(candidate.validity.from) > asOfTime) reason = 'not_yet_valid';\n else if (candidate.validity?.until !== undefined && candidate.validity.until !== null && Date.parse(candidate.validity.until) <= asOfTime) reason = 'expired';\n if (reason) {\n if (candidate.required) throw new MayuraError(reason === 'sensitivity_denied' ? 'PERMISSION_DENIED' : 'CONFLICT', 'A required continuity item is unavailable, stale, deleted, outside its validity interval, or denied; refresh or resolve it explicitly.');\n excluded.push(Object.freeze({ position, reason, ...(reason === 'sensitivity_denied' ? {} : { candidateId: candidate.id, sourceId: candidate.source.id, revision: candidate.source.revision }) }));\n } else eligible.push({ item: candidate, position });\n }\n eligible.sort((left, right) => {\n const one = left.item; const two = right.item;\n if (one.required !== two.required) return one.required ? -1 : 1;\n if (one.priority !== two.priority) return two.priority - one.priority;\n if (one.provenance.observedAt !== two.provenance.observedAt) return Date.parse(one.provenance.observedAt) > Date.parse(two.provenance.observedAt) ? -1 : 1;\n return one.id < two.id ? -1 : one.id > two.id ? 1 : 0;\n });\n const candidates = await Promise.all(eligible.map(async ({ item, position }) => ({ position, item: Object.freeze({ ...item, contentDigest: await hash('mayura:context-content:v1', canonical(item.content)) }) as ContextItem })));\n const encode = (items: readonly ContextItem[]): string => canonical(jsonValue({ format: 1, scope, policyVersion, asOf, items }, { maxBytes: 8_388_608 }));\n const measure = (items: readonly ContextItem[]) => {\n const serialized = encode(items); const bytes = encoder.encode(serialized).length;\n let estimatedTokens: number;\n try { estimatedTokens = estimate(serialized); }\n catch { throw new MayuraError('INVALID_CONFIG', 'The token estimator failed; raw exception details are withheld.'); }\n if (!Number.isSafeInteger(estimatedTokens) || estimatedTokens < 0) throw new MayuraError('INVALID_CONFIG', 'The token estimator must return a non-negative safe integer.');\n const reason = bytes > maxBytes - reservedBytes ? 'byte_budget' as const : estimatedTokens > maxEstimatedTokens - reservedTokens ? 'token_budget' as const : undefined;\n return { serialized, bytes, estimatedTokens, reason };\n };\n const selected = candidates.filter(({ item }) => item.required).map(({ item }) => item);\n let measured = measure(selected);\n if (measured.reason) throw new MayuraError('LIMIT_EXCEEDED', 'Required continuity items and context framing do not fit the reserved context budget.');\n for (const candidate of candidates) {\n if (candidate.item.required) continue;\n const next = measure([...selected, candidate.item]);\n if (next.reason) excluded.push(Object.freeze({ position: candidate.position, reason: next.reason,\n candidateId: candidate.item.id, sourceId: candidate.item.source.id, revision: candidate.item.source.revision,\n }));\n else { selected.push(candidate.item); measured = next; }\n }\n excluded.sort((one, two) => one.position - two.position);\n const budget = { maxBytes, maxEstimatedTokens, reservedBytes, reservedTokens };\n const fingerprint = await hash('mayura:context-assembly:v1', canonical(jsonValue({ serialized: measured.serialized, budget, estimatorId, allowedSensitivities: [...allowed].sort() }, { maxBytes: 16_777_216 })));\n const assembly: ContextAssembly = Object.freeze({ scope, policyVersion, asOf, selected: Object.freeze(selected), excluded: Object.freeze(excluded), serialized: measured.serialized, fingerprint,\n usage: Object.freeze({ bytes: measured.bytes, estimatedTokens: measured.estimatedTokens, reservedBytes, reservedTokens, maxBytes, maxEstimatedTokens, estimatorId }),\n });\n if (hooks.after) await evaluateLifecycleControl({ stage: 'afterContextBuild', handler: hooks.after, timeoutMs: hooks.timeoutMs, ...(signal ? { signal } : {}),\n event: { scope: { ...scope }, policyVersion, asOf, fingerprint,\n selected: selected.map(item => ({ id: item.id, sourceId: item.source.id, revision: item.source.revision, contentDigest: item.contentDigest })),\n excluded: excluded.map(entry => ({ ...entry })), usage: { ...assembly.usage } } });\n return assembly;\n}\n\n/** Read hook options once, as own data properties, before the first await. */\nfunction contextHooks(value: ContextHooks | undefined): { readonly before?: NonNullable<ContextHooks['beforeContextBuild']>; readonly after?: NonNullable<ContextHooks['afterContextBuild']>; readonly timeoutMs: number } {\n const { handlers, timeoutMs } = snapshotHookOptions(value, ['beforeContextBuild', 'afterContextBuild'] as const,\n 'Context hooks require callable beforeContextBuild/afterContextBuild handlers and a bounded timeout.');\n return { ...(handlers.beforeContextBuild ? { before: handlers.beforeContextBuild as NonNullable<ContextHooks['beforeContextBuild']> } : {}),\n ...(handlers.afterContextBuild ? { after: handlers.afterContextBuild as NonNullable<ContextHooks['afterContextBuild']> } : {}), timeoutMs };\n}\n\n/**\n * Internal cache key: a digest of every admission input except hooks and signals, which a cache re-runs.\n * Any change to candidates, source revisions, scope, policy, time, sensitivity profile, budget or estimator changes it.\n */\nexport async function admissionKey(options: AssembleContextOptions, asOf: string): Promise<string> {\n const material = safeJson({ scope: options.scope as unknown as JsonValue, policyVersion: options.policyVersion, asOf,\n candidates: options.candidates as unknown as JsonValue, sources: options.sources as unknown as JsonValue,\n allowedSensitivities: options.allowedSensitivities as unknown as JsonValue, budget: options.budget as unknown as JsonValue,\n estimatorId: (options.estimator ?? byteTokenEstimator).id });\n return hash('mayura:context-admission:v1', canonical(material));\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Scope } from '../../core/dist/index.js';
|
|
2
|
+
import type { AssembleContextOptions, ContextAssembly } from './contracts.js';
|
|
3
|
+
export interface ContextCacheOptions {
|
|
4
|
+
/** Default 256, maximum 10,000 entries; least recently used entries are evicted. */
|
|
5
|
+
readonly maxEntries?: number;
|
|
6
|
+
/** Default 5 minutes, maximum 24 hours. */
|
|
7
|
+
readonly ttlMs?: number;
|
|
8
|
+
/** Granularity used for `asOf` when a caller omits it (default 1000 ms), so repeated calls can share an entry. */
|
|
9
|
+
readonly asOfResolutionMs?: number;
|
|
10
|
+
/** Background prefetch concurrency (default 2, maximum 8). */
|
|
11
|
+
readonly maxPrefetch?: number;
|
|
12
|
+
readonly now?: () => number;
|
|
13
|
+
}
|
|
14
|
+
/** Any source of content-free change events, such as native memory's `changes`. */
|
|
15
|
+
export interface ContextChangeFeed {
|
|
16
|
+
changes(options: {
|
|
17
|
+
readonly after?: number;
|
|
18
|
+
readonly limit?: number;
|
|
19
|
+
}): Promise<readonly {
|
|
20
|
+
readonly sequence: number;
|
|
21
|
+
readonly id: string;
|
|
22
|
+
}[]>;
|
|
23
|
+
}
|
|
24
|
+
export interface ContextCacheStats {
|
|
25
|
+
readonly entries: number;
|
|
26
|
+
readonly hits: number;
|
|
27
|
+
readonly misses: number;
|
|
28
|
+
readonly invalidated: number;
|
|
29
|
+
readonly prefetched: number;
|
|
30
|
+
}
|
|
31
|
+
export interface ContextCache {
|
|
32
|
+
/** Same contract as `assembleContext`; a hit returns the stored assembly after re-running any hooks. */
|
|
33
|
+
assemble(options: AssembleContextOptions): Promise<ContextAssembly>;
|
|
34
|
+
/** Start a bounded background assembly; it is used only by a later `assemble` with an identical admission key. */
|
|
35
|
+
prefetch(options: AssembleContextOptions): void;
|
|
36
|
+
/** Drop entries for a scope and/or entries that include any of the given sources. Returns the number removed. */
|
|
37
|
+
invalidate(filter: {
|
|
38
|
+
readonly scope?: Scope;
|
|
39
|
+
readonly sourceIds?: readonly string[];
|
|
40
|
+
}): number;
|
|
41
|
+
/** Consume a change feed from the last cursor and invalidate entries that include a changed source. */
|
|
42
|
+
follow(feed: ContextChangeFeed, options?: {
|
|
43
|
+
readonly sourceIdFor?: (id: string) => string;
|
|
44
|
+
}): Promise<number>;
|
|
45
|
+
clear(): void;
|
|
46
|
+
stats(): ContextCacheStats;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A cache of assemblies, never of generated answers or approvals. Keys cover every admission input, so any changed
|
|
50
|
+
* source revision misses; `invalidate` and `follow` handle deletion, revocation and permission changes.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createContextCache(options?: ContextCacheOptions): ContextCache;
|
|
53
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAgB,MAAM,gBAAgB,CAAC;AAE5F,MAAM,WAAW,mBAAmB;IAClC,oFAAoF;IACpF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,kHAAkH;IAClH,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AE,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9G,KAAK,IAAI,IAAI,CAAC;IACd,KAAK,IAAI,iBAAiB,CAAC;CAC5B;AAWD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAiGlF"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { MayuraError } from '../../core/dist/index.js';
|
|
2
|
+
import { evaluateLifecycleControl, snapshotHookOptions } from '../../core/dist/host.js';
|
|
3
|
+
import { admissionKey, assembleContext } from './assemble.js';
|
|
4
|
+
function bounded(value, fallback, minimum, maximum, label) {
|
|
5
|
+
const result = value === undefined ? fallback : value;
|
|
6
|
+
if (typeof result !== 'number' || !Number.isSafeInteger(result) || result < minimum || result > maximum)
|
|
7
|
+
throw new MayuraError('INVALID_CONFIG', `${label} must be an integer from ${minimum} to ${maximum}.`);
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
const scopeText = (scope) => JSON.stringify([scope.principalId, scope.projectId]);
|
|
11
|
+
/**
|
|
12
|
+
* A cache of assemblies, never of generated answers or approvals. Keys cover every admission input, so any changed
|
|
13
|
+
* source revision misses; `invalidate` and `follow` handle deletion, revocation and permission changes.
|
|
14
|
+
*/
|
|
15
|
+
export function createContextCache(options = {}) {
|
|
16
|
+
const maxEntries = bounded(options.maxEntries, 256, 1, 10_000, 'maxEntries');
|
|
17
|
+
const ttlMs = bounded(options.ttlMs, 300_000, 1, 86_400_000, 'ttlMs');
|
|
18
|
+
const resolution = bounded(options.asOfResolutionMs, 1_000, 1, 3_600_000, 'asOfResolutionMs');
|
|
19
|
+
const maxPrefetch = bounded(options.maxPrefetch, 2, 1, 8, 'maxPrefetch');
|
|
20
|
+
const now = () => { const value = (options.now ?? Date.now)(); if (!Number.isSafeInteger(value) || value < 0)
|
|
21
|
+
throw new MayuraError('INVALID_CONFIG', 'Cache clock returned an invalid time.'); return value; };
|
|
22
|
+
const entries = new Map();
|
|
23
|
+
const pending = new Map();
|
|
24
|
+
let hits = 0;
|
|
25
|
+
let misses = 0;
|
|
26
|
+
let invalidated = 0;
|
|
27
|
+
let prefetched = 0;
|
|
28
|
+
let cursor = 0;
|
|
29
|
+
let generation = 0;
|
|
30
|
+
const prepare = async (input) => {
|
|
31
|
+
const asOf = input.asOf ?? new Date(Math.floor(now() / resolution) * resolution).toISOString();
|
|
32
|
+
const request = { ...input, asOf };
|
|
33
|
+
return { key: await admissionKey(request, asOf), request };
|
|
34
|
+
};
|
|
35
|
+
const store = (key, assembly, request, admittedGeneration) => {
|
|
36
|
+
// An invalidation that raced this assembly wins: the result is returned but not cached.
|
|
37
|
+
if (admittedGeneration !== generation)
|
|
38
|
+
return;
|
|
39
|
+
const sources = new Set([...assembly.selected.map(item => item.source.id), ...request.sources.map(source => source.id)]);
|
|
40
|
+
entries.delete(key);
|
|
41
|
+
entries.set(key, { assembly, sources, scope: scopeText(assembly.scope), expiresAt: now() + ttlMs });
|
|
42
|
+
while (entries.size > maxEntries)
|
|
43
|
+
entries.delete(entries.keys().next().value);
|
|
44
|
+
};
|
|
45
|
+
const compute = (key, request, started) => {
|
|
46
|
+
const existing = pending.get(key);
|
|
47
|
+
if (existing)
|
|
48
|
+
return existing;
|
|
49
|
+
// Hooks run on the returned path, not inside the shared computation.
|
|
50
|
+
const { hooks: _hooks, signal: _signal, ...plain } = request;
|
|
51
|
+
void _hooks;
|
|
52
|
+
void _signal;
|
|
53
|
+
const promise = assembleContext(plain).then(assembly => { store(key, assembly, request, started); return assembly; })
|
|
54
|
+
.finally(() => pending.delete(key));
|
|
55
|
+
pending.set(key, promise);
|
|
56
|
+
return promise;
|
|
57
|
+
};
|
|
58
|
+
/** Cached assemblies are re-admitted: hooks see the same views an uncached assembly would produce. */
|
|
59
|
+
const admit = async (assembly, request) => {
|
|
60
|
+
const { handlers, timeoutMs } = snapshotHookOptions(request.hooks, ['beforeContextBuild', 'afterContextBuild'], 'Context hooks require callable beforeContextBuild/afterContextBuild handlers and a bounded timeout.');
|
|
61
|
+
const signal = request.signal;
|
|
62
|
+
const budget = { reservedBytes: 0, reservedTokens: 0, ...request.budget };
|
|
63
|
+
if (handlers.beforeContextBuild)
|
|
64
|
+
await evaluateLifecycleControl({ stage: 'beforeContextBuild', handler: handlers.beforeContextBuild, timeoutMs, ...(signal ? { signal } : {}),
|
|
65
|
+
event: { scope: { ...assembly.scope }, policyVersion: assembly.policyVersion, asOf: assembly.asOf, candidateCount: request.candidates.length, sourceCount: request.sources.length,
|
|
66
|
+
budget: { maxBytes: budget.maxBytes, maxEstimatedTokens: budget.maxEstimatedTokens, reservedBytes: budget.reservedBytes, reservedTokens: budget.reservedTokens } } });
|
|
67
|
+
if (handlers.afterContextBuild)
|
|
68
|
+
await evaluateLifecycleControl({ stage: 'afterContextBuild', handler: handlers.afterContextBuild, timeoutMs, ...(signal ? { signal } : {}),
|
|
69
|
+
event: { scope: { ...assembly.scope }, policyVersion: assembly.policyVersion, asOf: assembly.asOf, fingerprint: assembly.fingerprint,
|
|
70
|
+
selected: assembly.selected.map(item => ({ id: item.id, sourceId: item.source.id, revision: item.source.revision, contentDigest: item.contentDigest })),
|
|
71
|
+
excluded: assembly.excluded.map(entry => ({ ...entry })), usage: { ...assembly.usage } } });
|
|
72
|
+
return assembly;
|
|
73
|
+
};
|
|
74
|
+
const drop = (predicate) => {
|
|
75
|
+
let removed = 0;
|
|
76
|
+
generation++;
|
|
77
|
+
for (const [key, entry] of entries)
|
|
78
|
+
if (predicate(entry)) {
|
|
79
|
+
entries.delete(key);
|
|
80
|
+
removed++;
|
|
81
|
+
}
|
|
82
|
+
invalidated += removed;
|
|
83
|
+
return removed;
|
|
84
|
+
};
|
|
85
|
+
let running = 0;
|
|
86
|
+
const queue = [];
|
|
87
|
+
const pump = () => {
|
|
88
|
+
while (running < maxPrefetch && queue.length > 0) {
|
|
89
|
+
const next = queue.shift();
|
|
90
|
+
running++;
|
|
91
|
+
const started = generation;
|
|
92
|
+
void prepare(next).then(({ key, request }) => entries.has(key) ? undefined : compute(key, request, started).then(() => { prefetched++; }))
|
|
93
|
+
.catch(() => { })
|
|
94
|
+
.finally(() => { running--; pump(); });
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return Object.freeze({
|
|
98
|
+
async assemble(input) {
|
|
99
|
+
// Captured before any await: an invalidation at any point during this call prevents caching its result.
|
|
100
|
+
const started = generation;
|
|
101
|
+
const { key, request } = await prepare(input);
|
|
102
|
+
const entry = entries.get(key);
|
|
103
|
+
if (entry && entry.expiresAt > now()) {
|
|
104
|
+
hits++;
|
|
105
|
+
entries.delete(key);
|
|
106
|
+
entries.set(key, entry);
|
|
107
|
+
return admit(entry.assembly, request);
|
|
108
|
+
}
|
|
109
|
+
if (entry)
|
|
110
|
+
entries.delete(key);
|
|
111
|
+
misses++;
|
|
112
|
+
return admit(await compute(key, request, started), request);
|
|
113
|
+
},
|
|
114
|
+
prefetch(input) {
|
|
115
|
+
if (queue.length >= 64)
|
|
116
|
+
return;
|
|
117
|
+
queue.push(input);
|
|
118
|
+
pump();
|
|
119
|
+
},
|
|
120
|
+
invalidate(filter) {
|
|
121
|
+
if (!filter || typeof filter !== 'object')
|
|
122
|
+
throw new MayuraError('INVALID_INPUT', 'An invalidation filter is required.');
|
|
123
|
+
const scope = filter.scope ? scopeText(filter.scope) : undefined;
|
|
124
|
+
const sources = filter.sourceIds ? new Set(filter.sourceIds) : undefined;
|
|
125
|
+
if (scope === undefined && sources === undefined)
|
|
126
|
+
throw new MayuraError('INVALID_INPUT', 'Invalidate by scope and/or source ids; use clear() to drop everything.');
|
|
127
|
+
return drop(entry => (scope === undefined || entry.scope === scope) && (sources === undefined || [...entry.sources].some(id => sources.has(id))));
|
|
128
|
+
},
|
|
129
|
+
async follow(feed, followOptions = {}) {
|
|
130
|
+
const map = followOptions.sourceIdFor ?? ((id) => id);
|
|
131
|
+
let removed = 0;
|
|
132
|
+
for (;;) {
|
|
133
|
+
const page = await feed.changes({ after: cursor, limit: 1_000 });
|
|
134
|
+
if (page.length === 0)
|
|
135
|
+
return removed;
|
|
136
|
+
const changed = new Set(page.map(change => map(change.id)));
|
|
137
|
+
removed += drop(entry => [...entry.sources].some(id => changed.has(id)));
|
|
138
|
+
cursor = page.at(-1).sequence;
|
|
139
|
+
if (page.length < 1_000)
|
|
140
|
+
return removed;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
clear() { drop(() => true); },
|
|
144
|
+
stats: () => Object.freeze({ entries: entries.size, hits, misses, invalidated, prefetched }),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAc,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAgC9D,SAAS,OAAO,CAAC,KAAc,EAAE,QAAgB,EAAE,OAAe,EAAE,OAAe,EAAE,KAAa;IAChG,MAAM,MAAM,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;IACtD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,OAAO,IAAI,MAAM,GAAG,OAAO;QAAE,MAAM,IAAI,WAAW,CAAC,gBAAgB,EAAE,GAAG,KAAK,4BAA4B,OAAO,OAAO,OAAO,GAAG,CAAC,CAAC;IAC/M,OAAO,MAAM,CAAC;AAChB,CAAC;AACD,MAAM,SAAS,GAAG,CAAC,KAAY,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK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AAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC5D,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBACzE,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,QAAQ,CAAC;gBAC/B,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK;oBAAE,OAAO,OAAO,CAAC;YAC1C,CAAC;QACH,CAAC;QACD,KAAK,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;KAC7F,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { MayuraError, type Scope } from '@mayura/core';\nimport { evaluateLifecycleControl, snapshotHookOptions } from '@mayura/core/host';\nimport { admissionKey, assembleContext } from './assemble.js';\nimport type { AssembleContextOptions, ContextAssembly, ContextHooks } from './contracts.js';\n\nexport interface ContextCacheOptions {\n /** Default 256, maximum 10,000 entries; least recently used entries are evicted. */\n readonly maxEntries?: number;\n /** Default 5 minutes, maximum 24 hours. */\n readonly ttlMs?: number;\n /** Granularity used for `asOf` when a caller omits it (default 1000 ms), so repeated calls can share an entry. */\n readonly asOfResolutionMs?: number;\n /** Background prefetch concurrency (default 2, maximum 8). */\n readonly maxPrefetch?: number;\n readonly now?: () => number;\n}\n/** Any source of content-free change events, such as native memory's `changes`. */\nexport interface ContextChangeFeed { changes(options: { readonly after?: number; readonly limit?: number }): Promise<readonly { readonly sequence: number; readonly id: string }[]> }\nexport interface ContextCacheStats { readonly entries: number; readonly hits: number; readonly misses: number; readonly invalidated: number; readonly prefetched: number }\nexport interface ContextCache {\n /** Same contract as `assembleContext`; a hit returns the stored assembly after re-running any hooks. */\n assemble(options: AssembleContextOptions): Promise<ContextAssembly>;\n /** Start a bounded background assembly; it is used only by a later `assemble` with an identical admission key. */\n prefetch(options: AssembleContextOptions): void;\n /** Drop entries for a scope and/or entries that include any of the given sources. Returns the number removed. */\n invalidate(filter: { readonly scope?: Scope; readonly sourceIds?: readonly string[] }): number;\n /** Consume a change feed from the last cursor and invalidate entries that include a changed source. */\n follow(feed: ContextChangeFeed, options?: { readonly sourceIdFor?: (id: string) => string }): Promise<number>;\n clear(): void;\n stats(): ContextCacheStats;\n}\n\ninterface Entry { readonly assembly: ContextAssembly; readonly sources: ReadonlySet<string>; readonly scope: string; readonly expiresAt: number }\n\nfunction bounded(value: unknown, fallback: number, minimum: number, maximum: number, label: string): number {\n const result = value === undefined ? fallback : value;\n if (typeof result !== 'number' || !Number.isSafeInteger(result) || result < minimum || result > maximum) throw new MayuraError('INVALID_CONFIG', `${label} must be an integer from ${minimum} to ${maximum}.`);\n return result;\n}\nconst scopeText = (scope: Scope): string => JSON.stringify([scope.principalId, scope.projectId]);\n\n/**\n * A cache of assemblies, never of generated answers or approvals. Keys cover every admission input, so any changed\n * source revision misses; `invalidate` and `follow` handle deletion, revocation and permission changes.\n */\nexport function createContextCache(options: ContextCacheOptions = {}): ContextCache {\n const maxEntries = bounded(options.maxEntries, 256, 1, 10_000, 'maxEntries');\n const ttlMs = bounded(options.ttlMs, 300_000, 1, 86_400_000, 'ttlMs');\n const resolution = bounded(options.asOfResolutionMs, 1_000, 1, 3_600_000, 'asOfResolutionMs');\n const maxPrefetch = bounded(options.maxPrefetch, 2, 1, 8, 'maxPrefetch');\n const now = (): number => { const value = (options.now ?? Date.now)(); if (!Number.isSafeInteger(value) || value < 0) throw new MayuraError('INVALID_CONFIG', 'Cache clock returned an invalid time.'); return value; };\n const entries = new Map<string, Entry>(); const pending = new Map<string, Promise<ContextAssembly>>();\n let hits = 0; let misses = 0; let invalidated = 0; let prefetched = 0; let cursor = 0; let generation = 0;\n\n const prepare = async (input: AssembleContextOptions): Promise<{ key: string; request: AssembleContextOptions }> => {\n const asOf = input.asOf ?? new Date(Math.floor(now() / resolution) * resolution).toISOString();\n const request = { ...input, asOf };\n return { key: await admissionKey(request, asOf), request };\n };\n const store = (key: string, assembly: ContextAssembly, request: AssembleContextOptions, admittedGeneration: number): void => {\n // An invalidation that raced this assembly wins: the result is returned but not cached.\n if (admittedGeneration !== generation) return;\n const sources = new Set([...assembly.selected.map(item => item.source.id), ...request.sources.map(source => source.id)]);\n entries.delete(key); entries.set(key, { assembly, sources, scope: scopeText(assembly.scope), expiresAt: now() + ttlMs });\n while (entries.size > maxEntries) entries.delete(entries.keys().next().value!);\n };\n const compute = (key: string, request: AssembleContextOptions, started: number): Promise<ContextAssembly> => {\n const existing = pending.get(key); if (existing) return existing;\n // Hooks run on the returned path, not inside the shared computation.\n const { hooks: _hooks, signal: _signal, ...plain } = request; void _hooks; void _signal;\n const promise = assembleContext(plain).then(assembly => { store(key, assembly, request, started); return assembly; })\n .finally(() => pending.delete(key));\n pending.set(key, promise); return promise;\n };\n /** Cached assemblies are re-admitted: hooks see the same views an uncached assembly would produce. */\n const admit = async (assembly: ContextAssembly, request: AssembleContextOptions): Promise<ContextAssembly> => {\n const { handlers, timeoutMs } = snapshotHookOptions(request.hooks, ['beforeContextBuild', 'afterContextBuild'] as const,\n 'Context hooks require callable beforeContextBuild/afterContextBuild handlers and a bounded timeout.');\n const signal = request.signal;\n const budget = { reservedBytes: 0, reservedTokens: 0, ...request.budget };\n if (handlers.beforeContextBuild) await evaluateLifecycleControl({ stage: 'beforeContextBuild', handler: handlers.beforeContextBuild as NonNullable<ContextHooks['beforeContextBuild']>, timeoutMs, ...(signal ? { signal } : {}),\n event: { scope: { ...assembly.scope }, policyVersion: assembly.policyVersion, asOf: assembly.asOf, candidateCount: request.candidates.length, sourceCount: request.sources.length,\n budget: { maxBytes: budget.maxBytes, maxEstimatedTokens: budget.maxEstimatedTokens, reservedBytes: budget.reservedBytes, reservedTokens: budget.reservedTokens } } });\n if (handlers.afterContextBuild) await evaluateLifecycleControl({ stage: 'afterContextBuild', handler: handlers.afterContextBuild as NonNullable<ContextHooks['afterContextBuild']>, timeoutMs, ...(signal ? { signal } : {}),\n event: { scope: { ...assembly.scope }, policyVersion: assembly.policyVersion, asOf: assembly.asOf, fingerprint: assembly.fingerprint,\n selected: assembly.selected.map(item => ({ id: item.id, sourceId: item.source.id, revision: item.source.revision, contentDigest: item.contentDigest })),\n excluded: assembly.excluded.map(entry => ({ ...entry })), usage: { ...assembly.usage } } });\n return assembly;\n };\n const drop = (predicate: (entry: Entry) => boolean): number => {\n let removed = 0; generation++;\n for (const [key, entry] of entries) if (predicate(entry)) { entries.delete(key); removed++; }\n invalidated += removed; return removed;\n };\n let running = 0; const queue: AssembleContextOptions[] = [];\n const pump = (): void => {\n while (running < maxPrefetch && queue.length > 0) {\n const next = queue.shift()!; running++; const started = generation;\n void prepare(next).then(({ key, request }) => entries.has(key) ? undefined : compute(key, request, started).then(() => { prefetched++; }))\n .catch(() => { /* A failed prefetch is simply not cached; the foreground call reports its own error. */ })\n .finally(() => { running--; pump(); });\n }\n };\n\n return Object.freeze<ContextCache>({\n async assemble(input) {\n // Captured before any await: an invalidation at any point during this call prevents caching its result.\n const started = generation;\n const { key, request } = await prepare(input);\n const entry = entries.get(key);\n if (entry && entry.expiresAt > now()) {\n hits++; entries.delete(key); entries.set(key, entry);\n return admit(entry.assembly, request);\n }\n if (entry) entries.delete(key);\n misses++;\n return admit(await compute(key, request, started), request);\n },\n prefetch(input) {\n if (queue.length >= 64) return;\n queue.push(input); pump();\n },\n invalidate(filter) {\n if (!filter || typeof filter !== 'object') throw new MayuraError('INVALID_INPUT', 'An invalidation filter is required.');\n const scope = filter.scope ? scopeText(filter.scope) : undefined; const sources = filter.sourceIds ? new Set(filter.sourceIds) : undefined;\n if (scope === undefined && sources === undefined) throw new MayuraError('INVALID_INPUT', 'Invalidate by scope and/or source ids; use clear() to drop everything.');\n return drop(entry => (scope === undefined || entry.scope === scope) && (sources === undefined || [...entry.sources].some(id => sources.has(id))));\n },\n async follow(feed, followOptions = {}) {\n const map = followOptions.sourceIdFor ?? ((id: string) => id); let removed = 0;\n for (;;) {\n const page = await feed.changes({ after: cursor, limit: 1_000 });\n if (page.length === 0) return removed;\n const changed = new Set(page.map(change => map(change.id)));\n removed += drop(entry => [...entry.sources].some(id => changed.has(id)));\n cursor = page.at(-1)!.sequence;\n if (page.length < 1_000) return removed;\n }\n },\n clear() { drop(() => true); },\n stats: () => Object.freeze({ entries: entries.size, hits, misses, invalidated, prefetched }),\n });\n}\n"]}
|