mayura 1.0.0 → 1.1.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/README.md +19 -6
- package/adapter-code-docker/index.d.ts +1 -0
- package/adapter-code-docker/index.js +1 -0
- package/adapter-code-quickjs/index.d.ts +1 -0
- package/adapter-code-quickjs/index.js +1 -0
- package/adapter-mcp/index.d.ts +1 -0
- package/adapter-mcp/index.js +1 -0
- package/artifacts/files/index.d.ts +1 -0
- package/artifacts/files/index.js +1 -0
- package/artifacts/index.d.ts +1 -0
- package/artifacts/index.js +1 -0
- package/auth/better-auth/index.d.ts +1 -0
- package/auth/better-auth/index.js +1 -0
- package/auth/index.d.ts +1 -0
- package/auth/index.js +1 -0
- package/auth/testing/index.d.ts +1 -0
- package/auth/testing/index.js +1 -0
- package/browser/index.d.ts +1 -0
- package/browser/index.js +1 -0
- package/browser/local/index.d.ts +1 -0
- package/browser/local/index.js +1 -0
- package/browser/testing/index.d.ts +1 -0
- package/browser/testing/index.js +1 -0
- package/cli/deploy/index.d.ts +1 -0
- package/cli/deploy/index.js +1 -0
- package/cli/index.d.ts +1 -0
- package/cli/index.js +1 -0
- package/client/forms/index.d.ts +1 -0
- package/client/forms/index.js +1 -0
- package/client/headless/index.d.ts +1 -0
- package/client/headless/index.js +1 -0
- package/client/index.d.ts +1 -0
- package/client/index.js +1 -0
- package/client/workflows/index.d.ts +1 -0
- package/client/workflows/index.js +1 -0
- package/client-react/components/index.d.ts +1 -0
- package/client-react/components/index.js +1 -0
- package/client-react/index.d.ts +1 -0
- package/client-react/index.js +1 -0
- package/code-mode/index.d.ts +1 -0
- package/code-mode/index.js +1 -0
- package/code-mode-workflows/index.d.ts +1 -0
- package/code-mode-workflows/index.js +1 -0
- package/context/index.d.ts +1 -0
- package/context/index.js +1 -0
- package/core/host/index.d.ts +1 -0
- package/core/host/index.js +1 -0
- package/core/index.d.ts +1 -0
- package/core/index.js +1 -0
- package/docs/README.md +10 -1
- package/docs/cli/deploy.md +154 -0
- package/docs/cli/overview.md +1 -0
- package/docs/cli/run.md +182 -182
- package/docs/guides/artifacts.md +29 -4
- package/docs/guides/authentication.md +246 -0
- package/docs/guides/browsers.md +189 -0
- package/docs/guides/deployment.md +45 -4
- package/docs/guides/files.md +188 -0
- package/docs/guides/model-providers.md +3 -0
- package/docs/guides/model-registry.md +184 -0
- package/docs/guides/observability.md +78 -1
- package/docs/guides/sandboxes.md +242 -0
- package/docs/guides/storage.md +195 -1
- package/docs/guides/testing.md +1 -0
- package/docs/guides/voice.md +100 -0
- package/docs/installation.md +16 -1
- package/docs/introduction.md +10 -5
- package/docs/project/security.md +8 -4
- package/docs/project/support.md +28 -7
- package/docs/project/versioning.md +9 -7
- package/docs/project/whats-new.md +78 -0
- package/docs/reference/entry-points.md +19 -1
- package/docs/reference/integrations.md +169 -0
- package/exporter-otlp/index.d.ts +1 -0
- package/exporter-otlp/index.js +1 -0
- package/exporter-otlp/opentelemetry/index.d.ts +1 -0
- package/exporter-otlp/opentelemetry/index.js +1 -0
- package/files/index.d.ts +1 -0
- package/files/index.js +1 -0
- package/guardrails/index.d.ts +1 -0
- package/guardrails/index.js +1 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +1 -0
- package/keys/index.d.ts +1 -0
- package/keys/index.js +1 -0
- package/keys/testing/index.d.ts +1 -0
- package/keys/testing/index.js +1 -0
- package/lib/adapter-code-docker/image/Dockerfile +1 -1
- package/lib/adapter-code-docker/package.json +1 -1
- package/lib/adapter-code-quickjs/package.json +1 -1
- package/lib/adapter-mcp/package.json +1 -1
- package/lib/artifacts/dist/files-store.d.ts +27 -0
- package/lib/artifacts/dist/files-store.d.ts.map +1 -0
- package/lib/artifacts/dist/files-store.js +390 -0
- package/lib/artifacts/dist/files-store.js.map +1 -0
- package/lib/artifacts/dist/files.d.ts +3 -0
- package/lib/artifacts/dist/files.d.ts.map +1 -0
- package/lib/artifacts/dist/files.js +2 -0
- package/lib/artifacts/dist/files.js.map +1 -0
- package/lib/artifacts/dist/index.d.ts +1 -0
- package/lib/artifacts/dist/index.d.ts.map +1 -1
- package/lib/artifacts/dist/index.js +1 -0
- package/lib/artifacts/dist/index.js.map +1 -1
- package/lib/artifacts/dist/local-store.d.ts.map +1 -1
- package/lib/artifacts/dist/local-store.js +14 -415
- package/lib/artifacts/dist/local-store.js.map +1 -1
- package/lib/artifacts/dist/shared.d.ts +86 -0
- package/lib/artifacts/dist/shared.d.ts.map +1 -0
- package/lib/artifacts/dist/shared.js +437 -0
- package/lib/artifacts/dist/shared.js.map +1 -0
- package/lib/artifacts/package.json +1 -1
- package/lib/artifacts/src/files-store.ts +352 -0
- package/lib/artifacts/src/files.ts +7 -0
- package/lib/artifacts/src/index.ts +1 -0
- package/lib/artifacts/src/local-store.ts +18 -359
- package/lib/artifacts/src/shared.ts +413 -0
- package/lib/auth/dist/better-auth.d.ts +103 -0
- package/lib/auth/dist/better-auth.d.ts.map +1 -0
- package/lib/auth/dist/better-auth.js +113 -0
- package/lib/auth/dist/better-auth.js.map +1 -0
- package/lib/auth/dist/identity.d.ts +68 -0
- package/lib/auth/dist/identity.d.ts.map +1 -0
- package/lib/auth/dist/identity.js +123 -0
- package/lib/auth/dist/identity.js.map +1 -0
- package/lib/auth/dist/index.d.ts +7 -0
- package/lib/auth/dist/index.d.ts.map +1 -0
- package/lib/auth/dist/index.js +4 -0
- package/lib/auth/dist/index.js.map +1 -0
- package/lib/auth/dist/jwt.d.ts +65 -0
- package/lib/auth/dist/jwt.d.ts.map +1 -0
- package/lib/auth/dist/jwt.js +120 -0
- package/lib/auth/dist/jwt.js.map +1 -0
- package/lib/auth/dist/keys.d.ts +80 -0
- package/lib/auth/dist/keys.d.ts.map +1 -0
- package/lib/auth/dist/keys.js +252 -0
- package/lib/auth/dist/keys.js.map +1 -0
- package/lib/auth/dist/testing.d.ts +32 -0
- package/lib/auth/dist/testing.d.ts.map +1 -0
- package/lib/auth/dist/testing.js +61 -0
- package/lib/auth/dist/testing.js.map +1 -0
- package/lib/auth/package.json +5 -0
- package/lib/auth/src/better-auth.ts +151 -0
- package/lib/auth/src/identity.ts +142 -0
- package/lib/auth/src/index.ts +6 -0
- package/lib/auth/src/jwt.ts +126 -0
- package/lib/auth/src/keys.ts +238 -0
- package/lib/auth/src/testing.ts +74 -0
- package/lib/browser/dist/browsers.d.ts +141 -0
- package/lib/browser/dist/browsers.d.ts.map +1 -0
- package/lib/browser/dist/browsers.js +639 -0
- package/lib/browser/dist/browsers.js.map +1 -0
- package/lib/browser/dist/cdp.d.ts +67 -0
- package/lib/browser/dist/cdp.d.ts.map +1 -0
- package/lib/browser/dist/cdp.js +176 -0
- package/lib/browser/dist/cdp.js.map +1 -0
- package/lib/browser/dist/connect.d.ts +17 -0
- package/lib/browser/dist/connect.d.ts.map +1 -0
- package/lib/browser/dist/connect.js +28 -0
- package/lib/browser/dist/connect.js.map +1 -0
- package/lib/browser/dist/contracts.d.ts +70 -0
- package/lib/browser/dist/contracts.d.ts.map +1 -0
- package/lib/browser/dist/contracts.js +48 -0
- package/lib/browser/dist/contracts.js.map +1 -0
- package/lib/browser/dist/index.d.ts +14 -0
- package/lib/browser/dist/index.d.ts.map +1 -0
- package/lib/browser/dist/index.js +8 -0
- package/lib/browser/dist/index.js.map +1 -0
- package/lib/browser/dist/keys.d.ts +13 -0
- package/lib/browser/dist/keys.d.ts.map +1 -0
- package/lib/browser/dist/keys.js +37 -0
- package/lib/browser/dist/keys.js.map +1 -0
- package/lib/browser/dist/local/fixtures.d.ts +18 -0
- package/lib/browser/dist/local/fixtures.d.ts.map +1 -0
- package/lib/browser/dist/local/fixtures.js +40 -0
- package/lib/browser/dist/local/fixtures.js.map +1 -0
- package/lib/browser/dist/local/index.d.ts +23 -0
- package/lib/browser/dist/local/index.d.ts.map +1 -0
- package/lib/browser/dist/local/index.js +136 -0
- package/lib/browser/dist/local/index.js.map +1 -0
- package/lib/browser/dist/origins.d.ts +12 -0
- package/lib/browser/dist/origins.d.ts.map +1 -0
- package/lib/browser/dist/origins.js +47 -0
- package/lib/browser/dist/origins.js.map +1 -0
- package/lib/browser/dist/per-run.d.ts +31 -0
- package/lib/browser/dist/per-run.d.ts.map +1 -0
- package/lib/browser/dist/per-run.js +46 -0
- package/lib/browser/dist/per-run.js.map +1 -0
- package/lib/browser/dist/snapshot.d.ts +35 -0
- package/lib/browser/dist/snapshot.d.ts.map +1 -0
- package/lib/browser/dist/snapshot.js +74 -0
- package/lib/browser/dist/snapshot.js.map +1 -0
- package/lib/browser/dist/testing.d.ts +31 -0
- package/lib/browser/dist/testing.d.ts.map +1 -0
- package/lib/browser/dist/testing.js +145 -0
- package/lib/browser/dist/testing.js.map +1 -0
- package/lib/browser/dist/tools.d.ts +34 -0
- package/lib/browser/dist/tools.d.ts.map +1 -0
- package/lib/browser/dist/tools.js +119 -0
- package/lib/browser/dist/tools.js.map +1 -0
- package/lib/browser/package.json +5 -0
- package/lib/browser/src/browsers.ts +599 -0
- package/lib/browser/src/cdp.ts +161 -0
- package/lib/browser/src/connect.ts +40 -0
- package/lib/browser/src/contracts.ts +100 -0
- package/lib/browser/src/index.ts +13 -0
- package/lib/browser/src/keys.ts +39 -0
- package/lib/browser/src/local/fixtures.ts +41 -0
- package/lib/browser/src/local/index.ts +121 -0
- package/lib/browser/src/origins.ts +49 -0
- package/lib/browser/src/per-run.ts +54 -0
- package/lib/browser/src/snapshot.ts +73 -0
- package/lib/browser/src/testing.ts +155 -0
- package/lib/browser/src/tools.ts +156 -0
- package/lib/cli/dist/bin.js +52 -0
- package/lib/cli/dist/bin.js.map +1 -1
- package/lib/cli/dist/deploy-index.d.ts +4 -0
- package/lib/cli/dist/deploy-index.d.ts.map +1 -0
- package/lib/cli/dist/deploy-index.js +5 -0
- package/lib/cli/dist/deploy-index.js.map +1 -0
- package/lib/cli/dist/deploy-targets.d.ts +36 -0
- package/lib/cli/dist/deploy-targets.d.ts.map +1 -0
- package/lib/cli/dist/deploy-targets.js +276 -0
- package/lib/cli/dist/deploy-targets.js.map +1 -0
- package/lib/cli/dist/deploy.d.ts +161 -0
- package/lib/cli/dist/deploy.d.ts.map +1 -0
- package/lib/cli/dist/deploy.js +452 -0
- package/lib/cli/dist/deploy.js.map +1 -0
- package/lib/cli/dist/files.d.ts +26 -0
- package/lib/cli/dist/files.d.ts.map +1 -0
- package/lib/cli/dist/files.js +179 -0
- package/lib/cli/dist/files.js.map +1 -0
- package/lib/cli/dist/index.d.ts.map +1 -1
- package/lib/cli/dist/index.js +4 -174
- package/lib/cli/dist/index.js.map +1 -1
- package/lib/cli/dist/output.d.ts.map +1 -1
- package/lib/cli/dist/output.js +54 -0
- package/lib/cli/dist/output.js.map +1 -1
- package/lib/cli/package.json +1 -1
- package/lib/cli/src/bin.ts +35 -0
- package/lib/cli/src/deploy-index.ts +11 -0
- package/lib/cli/src/deploy-targets.ts +277 -0
- package/lib/cli/src/deploy.ts +419 -0
- package/lib/cli/src/files.ts +137 -0
- package/lib/cli/src/index.ts +4 -122
- package/lib/cli/src/output.ts +44 -0
- package/lib/client/package.json +1 -1
- package/lib/client-react/package.json +1 -1
- package/lib/code-mode/dist/index.d.ts.map +1 -1
- package/lib/code-mode/dist/index.js +3 -3
- package/lib/code-mode/dist/index.js.map +1 -1
- package/lib/code-mode/package.json +1 -1
- package/lib/code-mode/src/index.ts +3 -3
- package/lib/code-mode-workflows/dist/index.d.ts.map +1 -1
- package/lib/code-mode-workflows/dist/index.js +2 -2
- package/lib/code-mode-workflows/dist/index.js.map +1 -1
- package/lib/code-mode-workflows/package.json +1 -1
- package/lib/code-mode-workflows/src/index.ts +2 -2
- package/lib/context/package.json +1 -1
- package/lib/core/dist/bytes.d.ts +13 -0
- package/lib/core/dist/bytes.d.ts.map +1 -0
- package/lib/core/dist/bytes.js +128 -0
- package/lib/core/dist/bytes.js.map +1 -0
- package/lib/core/dist/contracts.d.ts +4 -0
- package/lib/core/dist/contracts.d.ts.map +1 -1
- package/lib/core/dist/contracts.js.map +1 -1
- package/lib/core/dist/host.d.ts +2 -0
- package/lib/core/dist/host.d.ts.map +1 -1
- package/lib/core/dist/host.js +2 -0
- package/lib/core/dist/host.js.map +1 -1
- package/lib/core/dist/pricing.d.ts +20 -0
- package/lib/core/dist/pricing.d.ts.map +1 -0
- package/lib/core/dist/pricing.js +10 -0
- package/lib/core/dist/pricing.js.map +1 -0
- package/lib/core/package.json +1 -1
- package/lib/core/src/bytes.ts +101 -0
- package/lib/core/src/contracts.ts +7 -1
- package/lib/core/src/host.ts +2 -0
- package/lib/core/src/pricing.ts +24 -0
- package/lib/exporter-otlp/dist/contracts.d.ts +25 -3
- package/lib/exporter-otlp/dist/contracts.d.ts.map +1 -1
- package/lib/exporter-otlp/dist/contracts.js.map +1 -1
- package/lib/exporter-otlp/dist/index.d.ts +2 -2
- package/lib/exporter-otlp/dist/index.d.ts.map +1 -1
- package/lib/exporter-otlp/dist/index.js +1 -1
- package/lib/exporter-otlp/dist/index.js.map +1 -1
- package/lib/exporter-otlp/dist/opentelemetry.d.ts +53 -0
- package/lib/exporter-otlp/dist/opentelemetry.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/opentelemetry.js +209 -0
- package/lib/exporter-otlp/dist/opentelemetry.js.map +1 -0
- package/lib/exporter-otlp/dist/otlp-http-json.d.ts.map +1 -1
- package/lib/exporter-otlp/dist/otlp-http-json.js +11 -4
- package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
- package/lib/exporter-otlp/dist/protobuf.d.ts +9 -0
- package/lib/exporter-otlp/dist/protobuf.d.ts.map +1 -0
- package/lib/exporter-otlp/dist/protobuf.js +188 -0
- package/lib/exporter-otlp/dist/protobuf.js.map +1 -0
- package/lib/exporter-otlp/dist/run-traces.d.ts +3 -1
- package/lib/exporter-otlp/dist/run-traces.d.ts.map +1 -1
- package/lib/exporter-otlp/dist/run-traces.js +31 -4
- package/lib/exporter-otlp/dist/run-traces.js.map +1 -1
- package/lib/exporter-otlp/dist/signals.d.ts +8 -1
- package/lib/exporter-otlp/dist/signals.d.ts.map +1 -1
- package/lib/exporter-otlp/dist/signals.js +93 -26
- package/lib/exporter-otlp/dist/signals.js.map +1 -1
- package/lib/exporter-otlp/package.json +1 -1
- package/lib/exporter-otlp/src/contracts.ts +30 -3
- package/lib/exporter-otlp/src/index.ts +4 -1
- package/lib/exporter-otlp/src/opentelemetry.ts +157 -0
- package/lib/exporter-otlp/src/otlp-http-json.ts +10 -3
- package/lib/exporter-otlp/src/protobuf.ts +123 -0
- package/lib/exporter-otlp/src/run-traces.ts +24 -5
- package/lib/exporter-otlp/src/signals.ts +86 -25
- package/lib/files/dist/contracts.d.ts +155 -0
- package/lib/files/dist/contracts.d.ts.map +1 -0
- package/lib/files/dist/contracts.js +41 -0
- package/lib/files/dist/contracts.js.map +1 -0
- package/lib/files/dist/index.d.ts +7 -0
- package/lib/files/dist/index.d.ts.map +1 -0
- package/lib/files/dist/index.js +7 -0
- package/lib/files/dist/index.js.map +1 -0
- package/lib/files/dist/memory.d.ts +9 -0
- package/lib/files/dist/memory.d.ts.map +1 -0
- package/lib/files/dist/memory.js +70 -0
- package/lib/files/dist/memory.js.map +1 -0
- package/lib/files/dist/s3.d.ts +34 -0
- package/lib/files/dist/s3.d.ts.map +1 -0
- package/lib/files/dist/s3.js +232 -0
- package/lib/files/dist/s3.js.map +1 -0
- package/lib/files/dist/sigv4.d.ts +31 -0
- package/lib/files/dist/sigv4.d.ts.map +1 -0
- package/lib/files/dist/sigv4.js +47 -0
- package/lib/files/dist/sigv4.js.map +1 -0
- package/lib/files/dist/store.d.ts +19 -0
- package/lib/files/dist/store.d.ts.map +1 -0
- package/lib/files/dist/store.js +257 -0
- package/lib/files/dist/store.js.map +1 -0
- package/lib/files/dist/tools.d.ts +21 -0
- package/lib/files/dist/tools.d.ts.map +1 -0
- package/lib/files/dist/tools.js +155 -0
- package/lib/files/dist/tools.js.map +1 -0
- package/lib/files/dist/transport.d.ts +9 -0
- package/lib/files/dist/transport.d.ts.map +1 -0
- package/lib/files/dist/transport.js +53 -0
- package/lib/files/dist/transport.js.map +1 -0
- package/lib/files/package.json +5 -0
- package/lib/files/src/contracts.ts +174 -0
- package/lib/files/src/index.ts +6 -0
- package/lib/files/src/memory.ts +65 -0
- package/lib/files/src/s3.ts +196 -0
- package/lib/files/src/sigv4.ts +65 -0
- package/lib/files/src/store.ts +216 -0
- package/lib/files/src/tools.ts +140 -0
- package/lib/files/src/transport.ts +33 -0
- package/lib/guardrails/package.json +1 -1
- package/lib/helpers/package.json +1 -1
- package/lib/keys/dist/conformance.d.ts +14 -0
- package/lib/keys/dist/conformance.d.ts.map +1 -0
- package/lib/keys/dist/conformance.js +141 -0
- package/lib/keys/dist/conformance.js.map +1 -0
- package/lib/keys/dist/format.d.ts +19 -0
- package/lib/keys/dist/format.d.ts.map +1 -0
- package/lib/keys/dist/format.js +62 -0
- package/lib/keys/dist/format.js.map +1 -0
- package/lib/keys/dist/index.d.ts +6 -0
- package/lib/keys/dist/index.d.ts.map +1 -0
- package/lib/keys/dist/index.js +4 -0
- package/lib/keys/dist/index.js.map +1 -0
- package/lib/keys/dist/manager.d.ts +142 -0
- package/lib/keys/dist/manager.d.ts.map +1 -0
- package/lib/keys/dist/manager.js +430 -0
- package/lib/keys/dist/manager.js.map +1 -0
- package/lib/keys/dist/testing.d.ts +11 -0
- package/lib/keys/dist/testing.d.ts.map +1 -0
- package/lib/keys/dist/testing.js +68 -0
- package/lib/keys/dist/testing.js.map +1 -0
- package/lib/keys/dist/verifier.d.ts +40 -0
- package/lib/keys/dist/verifier.d.ts.map +1 -0
- package/lib/keys/dist/verifier.js +28 -0
- package/lib/keys/dist/verifier.js.map +1 -0
- package/lib/keys/package.json +5 -0
- package/lib/keys/src/conformance.ts +141 -0
- package/lib/keys/src/format.ts +63 -0
- package/lib/keys/src/index.ts +5 -0
- package/lib/keys/src/manager.ts +450 -0
- package/lib/keys/src/testing.ts +56 -0
- package/lib/keys/src/verifier.ts +49 -0
- package/lib/memory/dist/index.js +3 -3
- package/lib/memory/dist/index.js.map +1 -1
- package/lib/memory/dist/native.js +4 -4
- package/lib/memory/dist/native.js.map +1 -1
- package/lib/memory/dist/validation.d.ts.map +1 -1
- package/lib/memory/dist/validation.js +3 -3
- package/lib/memory/dist/validation.js.map +1 -1
- package/lib/memory/dist/vectors.d.ts.map +1 -1
- package/lib/memory/dist/vectors.js +16 -8
- package/lib/memory/dist/vectors.js.map +1 -1
- package/lib/memory/package.json +1 -1
- package/lib/memory/src/index.ts +3 -3
- package/lib/memory/src/native.ts +4 -4
- package/lib/memory/src/validation.ts +3 -3
- package/lib/memory/src/vectors.ts +10 -8
- package/lib/memory-remote/dist/index.d.ts.map +1 -1
- package/lib/memory-remote/dist/index.js +4 -5
- package/lib/memory-remote/dist/index.js.map +1 -1
- package/lib/memory-remote/package.json +1 -1
- package/lib/memory-remote/src/index.ts +4 -5
- package/lib/observability/dist/validation.d.ts.map +1 -1
- package/lib/observability/dist/validation.js +10 -3
- package/lib/observability/dist/validation.js.map +1 -1
- package/lib/observability/package.json +1 -1
- package/lib/observability/src/validation.ts +6 -3
- package/lib/provider-anthropic/dist/index.d.ts.map +1 -1
- package/lib/provider-anthropic/dist/index.js +4 -1
- package/lib/provider-anthropic/dist/index.js.map +1 -1
- package/lib/provider-anthropic/package.json +1 -1
- package/lib/provider-anthropic/src/index.ts +3 -1
- package/lib/provider-openai/dist/index.js +3 -3
- package/lib/provider-openai/dist/index.js.map +1 -1
- package/lib/provider-openai/package.json +1 -1
- package/lib/provider-openai/src/index.ts +3 -3
- package/lib/runtime/dist/agent.d.ts +2 -0
- package/lib/runtime/dist/agent.d.ts.map +1 -1
- package/lib/runtime/dist/agent.js +6 -1
- package/lib/runtime/dist/agent.js.map +1 -1
- package/lib/runtime/dist/index.d.ts +1 -0
- package/lib/runtime/dist/index.d.ts.map +1 -1
- package/lib/runtime/dist/index.js +1 -0
- package/lib/runtime/dist/index.js.map +1 -1
- package/lib/runtime/dist/models.d.ts +110 -0
- package/lib/runtime/dist/models.d.ts.map +1 -0
- package/lib/runtime/dist/models.js +246 -0
- package/lib/runtime/dist/models.js.map +1 -0
- package/lib/runtime/dist/response.d.ts +5 -0
- package/lib/runtime/dist/response.d.ts.map +1 -1
- package/lib/runtime/dist/response.js +34 -4
- package/lib/runtime/dist/response.js.map +1 -1
- package/lib/runtime/dist/router.d.ts +4 -0
- package/lib/runtime/dist/router.d.ts.map +1 -1
- package/lib/runtime/dist/router.js +9 -9
- package/lib/runtime/dist/router.js.map +1 -1
- package/lib/runtime/dist/runtime.d.ts +0 -1
- package/lib/runtime/dist/runtime.d.ts.map +1 -1
- package/lib/runtime/dist/runtime.js +10 -3
- package/lib/runtime/dist/runtime.js.map +1 -1
- package/lib/runtime/package.json +1 -1
- package/lib/runtime/src/agent.ts +6 -1
- package/lib/runtime/src/index.ts +1 -0
- package/lib/runtime/src/models.ts +310 -0
- package/lib/runtime/src/response.ts +28 -4
- package/lib/runtime/src/router.ts +9 -9
- package/lib/runtime/src/runtime.ts +10 -3
- package/lib/sandbox/dist/command-backend.d.ts +29 -0
- package/lib/sandbox/dist/command-backend.d.ts.map +1 -0
- package/lib/sandbox/dist/command-backend.js +208 -0
- package/lib/sandbox/dist/command-backend.js.map +1 -0
- package/lib/sandbox/dist/contracts.d.ts +173 -0
- package/lib/sandbox/dist/contracts.d.ts.map +1 -0
- package/lib/sandbox/dist/contracts.js +48 -0
- package/lib/sandbox/dist/contracts.js.map +1 -0
- package/lib/sandbox/dist/docker/api.d.ts +12 -0
- package/lib/sandbox/dist/docker/api.d.ts.map +1 -0
- package/lib/sandbox/dist/docker/api.js +228 -0
- package/lib/sandbox/dist/docker/api.js.map +1 -0
- package/lib/sandbox/dist/docker/cli.d.ts +4 -0
- package/lib/sandbox/dist/docker/cli.d.ts.map +1 -0
- package/lib/sandbox/dist/docker/cli.js +128 -0
- package/lib/sandbox/dist/docker/cli.js.map +1 -0
- package/lib/sandbox/dist/docker/engine.d.ts +58 -0
- package/lib/sandbox/dist/docker/engine.d.ts.map +1 -0
- package/lib/sandbox/dist/docker/engine.js +30 -0
- package/lib/sandbox/dist/docker/engine.js.map +1 -0
- package/lib/sandbox/dist/docker/index.d.ts +39 -0
- package/lib/sandbox/dist/docker/index.d.ts.map +1 -0
- package/lib/sandbox/dist/docker/index.js +187 -0
- package/lib/sandbox/dist/docker/index.js.map +1 -0
- package/lib/sandbox/dist/docker/scripts.d.ts +15 -0
- package/lib/sandbox/dist/docker/scripts.d.ts.map +1 -0
- package/lib/sandbox/dist/docker/scripts.js +32 -0
- package/lib/sandbox/dist/docker/scripts.js.map +1 -0
- package/lib/sandbox/dist/index.d.ts +7 -0
- package/lib/sandbox/dist/index.d.ts.map +1 -0
- package/lib/sandbox/dist/index.js +7 -0
- package/lib/sandbox/dist/index.js.map +1 -0
- package/lib/sandbox/dist/per-run.d.ts +28 -0
- package/lib/sandbox/dist/per-run.d.ts.map +1 -0
- package/lib/sandbox/dist/per-run.js +46 -0
- package/lib/sandbox/dist/per-run.js.map +1 -0
- package/lib/sandbox/dist/sandboxes.d.ts +166 -0
- package/lib/sandbox/dist/sandboxes.d.ts.map +1 -0
- package/lib/sandbox/dist/sandboxes.js +538 -0
- package/lib/sandbox/dist/sandboxes.js.map +1 -0
- package/lib/sandbox/dist/scripts.d.ts +25 -0
- package/lib/sandbox/dist/scripts.d.ts.map +1 -0
- package/lib/sandbox/dist/scripts.js +72 -0
- package/lib/sandbox/dist/scripts.js.map +1 -0
- package/lib/sandbox/dist/testing.d.ts +53 -0
- package/lib/sandbox/dist/testing.d.ts.map +1 -0
- package/lib/sandbox/dist/testing.js +148 -0
- package/lib/sandbox/dist/testing.js.map +1 -0
- package/lib/sandbox/dist/tools.d.ts +41 -0
- package/lib/sandbox/dist/tools.d.ts.map +1 -0
- package/lib/sandbox/dist/tools.js +280 -0
- package/lib/sandbox/dist/tools.js.map +1 -0
- package/lib/sandbox/package.json +5 -0
- package/lib/sandbox/src/command-backend.ts +194 -0
- package/lib/sandbox/src/contracts.ts +168 -0
- package/lib/sandbox/src/docker/api.ts +172 -0
- package/lib/sandbox/src/docker/cli.ts +98 -0
- package/lib/sandbox/src/docker/engine.ts +69 -0
- package/lib/sandbox/src/docker/index.ts +192 -0
- package/lib/sandbox/src/docker/scripts.ts +36 -0
- package/lib/sandbox/src/index.ts +9 -0
- package/lib/sandbox/src/per-run.ts +54 -0
- package/lib/sandbox/src/sandboxes.ts +521 -0
- package/lib/sandbox/src/scripts.ts +76 -0
- package/lib/sandbox/src/testing.ts +166 -0
- package/lib/sandbox/src/tools.ts +284 -0
- package/lib/sdk/package.json +1 -1
- package/lib/server/package.json +1 -1
- package/lib/server-node/package.json +1 -1
- package/lib/skills/dist/index.d.ts.map +1 -1
- package/lib/skills/dist/index.js +2 -2
- package/lib/skills/dist/index.js.map +1 -1
- package/lib/skills/package.json +1 -1
- package/lib/skills/src/index.ts +2 -2
- package/lib/storage/package.json +1 -1
- package/lib/storage-contracts/dist/schema-digest.d.ts +3 -5
- package/lib/storage-contracts/dist/schema-digest.d.ts.map +1 -1
- package/lib/storage-contracts/dist/schema-digest.js +3 -58
- package/lib/storage-contracts/dist/schema-digest.js.map +1 -1
- package/lib/storage-contracts/package.json +1 -1
- package/lib/storage-contracts/src/schema-digest.ts +3 -40
- package/lib/storage-postgres/dist/driver.d.ts +18 -0
- package/lib/storage-postgres/dist/driver.d.ts.map +1 -0
- package/lib/storage-postgres/dist/driver.js +22 -0
- package/lib/storage-postgres/dist/driver.js.map +1 -0
- package/lib/storage-postgres/dist/postgres.d.ts +5 -2
- package/lib/storage-postgres/dist/postgres.d.ts.map +1 -1
- package/lib/storage-postgres/dist/postgres.js +8 -223
- package/lib/storage-postgres/dist/postgres.js.map +1 -1
- package/lib/storage-postgres/dist/store.d.ts +25 -0
- package/lib/storage-postgres/dist/store.d.ts.map +1 -0
- package/lib/storage-postgres/dist/store.js +237 -0
- package/lib/storage-postgres/dist/store.js.map +1 -0
- package/lib/storage-postgres/package.json +1 -1
- package/lib/storage-postgres/src/driver.ts +35 -0
- package/lib/storage-postgres/src/postgres.ts +10 -211
- package/lib/storage-postgres/src/store.ts +242 -0
- package/lib/storage-sql/dist/aggregate-session.d.ts.map +1 -1
- package/lib/storage-sql/dist/aggregate-session.js +13 -8
- package/lib/storage-sql/dist/aggregate-session.js.map +1 -1
- package/lib/storage-sql/dist/dialect.d.ts +29 -0
- package/lib/storage-sql/dist/dialect.d.ts.map +1 -0
- package/lib/storage-sql/dist/dialect.js +63 -0
- package/lib/storage-sql/dist/dialect.js.map +1 -0
- package/lib/storage-sql/dist/document/budget-rows.d.ts +5 -0
- package/lib/storage-sql/dist/document/budget-rows.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/budget-rows.js +36 -0
- package/lib/storage-sql/dist/document/budget-rows.js.map +1 -0
- package/lib/storage-sql/dist/document/execution-wait-rows.d.ts +5 -0
- package/lib/storage-sql/dist/document/execution-wait-rows.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/execution-wait-rows.js +66 -0
- package/lib/storage-sql/dist/document/execution-wait-rows.js.map +1 -0
- package/lib/storage-sql/dist/document/keys.d.ts +26 -0
- package/lib/storage-sql/dist/document/keys.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/keys.js +74 -0
- package/lib/storage-sql/dist/document/keys.js.map +1 -0
- package/lib/storage-sql/dist/document/layout.d.ts +66 -0
- package/lib/storage-sql/dist/document/layout.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/layout.js +43 -0
- package/lib/storage-sql/dist/document/layout.js.map +1 -0
- package/lib/storage-sql/dist/document/memory-backend.d.ts +11 -0
- package/lib/storage-sql/dist/document/memory-backend.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/memory-backend.js +48 -0
- package/lib/storage-sql/dist/document/memory-backend.js.map +1 -0
- package/lib/storage-sql/dist/document/memory.d.ts +5 -0
- package/lib/storage-sql/dist/document/memory.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/memory.js +372 -0
- package/lib/storage-sql/dist/document/memory.js.map +1 -0
- package/lib/storage-sql/dist/document/scheduled-rows.d.ts +31 -0
- package/lib/storage-sql/dist/document/scheduled-rows.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/scheduled-rows.js +155 -0
- package/lib/storage-sql/dist/document/scheduled-rows.js.map +1 -0
- package/lib/storage-sql/dist/document/scheduler-rows.d.ts +12 -0
- package/lib/storage-sql/dist/document/scheduler-rows.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/scheduler-rows.js +227 -0
- package/lib/storage-sql/dist/document/scheduler-rows.js.map +1 -0
- package/lib/storage-sql/dist/document/session.d.ts +119 -0
- package/lib/storage-sql/dist/document/session.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/session.js +203 -0
- package/lib/storage-sql/dist/document/session.js.map +1 -0
- package/lib/storage-sql/dist/document/store.d.ts +17 -0
- package/lib/storage-sql/dist/document/store.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/store.js +133 -0
- package/lib/storage-sql/dist/document/store.js.map +1 -0
- package/lib/storage-sql/dist/document/tree-rows.d.ts +5 -0
- package/lib/storage-sql/dist/document/tree-rows.d.ts.map +1 -0
- package/lib/storage-sql/dist/document/tree-rows.js +97 -0
- package/lib/storage-sql/dist/document/tree-rows.js.map +1 -0
- package/lib/storage-sql/dist/durable-budget-database.d.ts +7 -6
- package/lib/storage-sql/dist/durable-budget-database.d.ts.map +1 -1
- package/lib/storage-sql/dist/durable-budget-database.js +34 -40
- package/lib/storage-sql/dist/durable-budget-database.js.map +1 -1
- package/lib/storage-sql/dist/durable-budget-persistence.d.ts +53 -0
- package/lib/storage-sql/dist/durable-budget-persistence.d.ts.map +1 -0
- package/lib/storage-sql/dist/durable-budget-persistence.js +43 -0
- package/lib/storage-sql/dist/durable-budget-persistence.js.map +1 -0
- package/lib/storage-sql/dist/execution-completions.d.ts +19 -1
- package/lib/storage-sql/dist/execution-completions.d.ts.map +1 -1
- package/lib/storage-sql/dist/execution-completions.js +21 -9
- package/lib/storage-sql/dist/execution-completions.js.map +1 -1
- package/lib/storage-sql/dist/execution-wait-database.d.ts +3 -3
- package/lib/storage-sql/dist/execution-wait-database.d.ts.map +1 -1
- package/lib/storage-sql/dist/execution-wait-database.js +36 -60
- package/lib/storage-sql/dist/execution-wait-database.js.map +1 -1
- package/lib/storage-sql/dist/execution-wait-persistence.d.ts +71 -0
- package/lib/storage-sql/dist/execution-wait-persistence.d.ts.map +1 -0
- package/lib/storage-sql/dist/execution-wait-persistence.js +71 -0
- package/lib/storage-sql/dist/execution-wait-persistence.js.map +1 -0
- package/lib/storage-sql/dist/host.d.ts +22 -0
- package/lib/storage-sql/dist/host.d.ts.map +1 -1
- package/lib/storage-sql/dist/host.js +9 -0
- package/lib/storage-sql/dist/host.js.map +1 -1
- package/lib/storage-sql/dist/memory-database.d.ts.map +1 -1
- package/lib/storage-sql/dist/memory-database.js +7 -8
- package/lib/storage-sql/dist/memory-database.js.map +1 -1
- package/lib/storage-sql/dist/scheduled-database.d.ts +3 -3
- package/lib/storage-sql/dist/scheduled-database.d.ts.map +1 -1
- package/lib/storage-sql/dist/scheduled-database.js +50 -77
- package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
- package/lib/storage-sql/dist/scheduled-persistence.d.ts +81 -0
- package/lib/storage-sql/dist/scheduled-persistence.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduled-persistence.js +83 -0
- package/lib/storage-sql/dist/scheduled-persistence.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-database.d.ts +17 -8
- package/lib/storage-sql/dist/scheduler-database.d.ts.map +1 -1
- package/lib/storage-sql/dist/scheduler-database.js +70 -113
- package/lib/storage-sql/dist/scheduler-database.js.map +1 -1
- package/lib/storage-sql/dist/scheduler-persistence.d.ts +87 -0
- package/lib/storage-sql/dist/scheduler-persistence.d.ts.map +1 -0
- package/lib/storage-sql/dist/scheduler-persistence.js +103 -0
- package/lib/storage-sql/dist/scheduler-persistence.js.map +1 -0
- package/lib/storage-sql/dist/scheduler-validation.d.ts.map +1 -1
- package/lib/storage-sql/dist/scheduler-validation.js +2 -2
- package/lib/storage-sql/dist/scheduler-validation.js.map +1 -1
- package/lib/storage-sql/dist/validation.d.ts.map +1 -1
- package/lib/storage-sql/dist/validation.js +4 -4
- package/lib/storage-sql/dist/validation.js.map +1 -1
- package/lib/storage-sql/dist/workflow-graph-discovery-index.d.ts.map +1 -1
- package/lib/storage-sql/dist/workflow-graph-discovery-index.js +16 -0
- package/lib/storage-sql/dist/workflow-graph-discovery-index.js.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-database.d.ts +4 -4
- package/lib/storage-sql/dist/workflow-tree-database.d.ts.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-database.js +216 -235
- package/lib/storage-sql/dist/workflow-tree-database.js.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-persistence.d.ts +69 -0
- package/lib/storage-sql/dist/workflow-tree-persistence.d.ts.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-persistence.js +77 -0
- package/lib/storage-sql/dist/workflow-tree-persistence.js.map +1 -0
- package/lib/storage-sql/dist/workflow-tree-validation.d.ts.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-validation.js +2 -2
- package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -1
- package/lib/storage-sql/package.json +1 -1
- package/lib/storage-sql/src/aggregate-session.ts +15 -9
- package/lib/storage-sql/src/dialect.ts +63 -0
- package/lib/storage-sql/src/document/budget-rows.ts +35 -0
- package/lib/storage-sql/src/document/execution-wait-rows.ts +61 -0
- package/lib/storage-sql/src/document/keys.ts +63 -0
- package/lib/storage-sql/src/document/layout.ts +44 -0
- package/lib/storage-sql/src/document/memory-backend.ts +42 -0
- package/lib/storage-sql/src/document/memory.ts +294 -0
- package/lib/storage-sql/src/document/scheduled-rows.ts +138 -0
- package/lib/storage-sql/src/document/scheduler-rows.ts +188 -0
- package/lib/storage-sql/src/document/session.ts +204 -0
- package/lib/storage-sql/src/document/store.ts +131 -0
- package/lib/storage-sql/src/document/tree-rows.ts +88 -0
- package/lib/storage-sql/src/durable-budget-database.ts +36 -52
- package/lib/storage-sql/src/durable-budget-persistence.ts +82 -0
- package/lib/storage-sql/src/execution-completions.ts +28 -11
- package/lib/storage-sql/src/execution-wait-database.ts +47 -73
- package/lib/storage-sql/src/execution-wait-persistence.ts +114 -0
- package/lib/storage-sql/src/host.ts +22 -0
- package/lib/storage-sql/src/memory-database.ts +11 -8
- package/lib/storage-sql/src/scheduled-database.ts +67 -100
- package/lib/storage-sql/src/scheduled-persistence.ts +146 -0
- package/lib/storage-sql/src/scheduler-database.ts +79 -122
- package/lib/storage-sql/src/scheduler-persistence.ts +157 -0
- package/lib/storage-sql/src/scheduler-validation.ts +2 -2
- package/lib/storage-sql/src/validation.ts +4 -4
- package/lib/storage-sql/src/workflow-graph-discovery-index.ts +15 -0
- package/lib/storage-sql/src/workflow-tree-database.ts +118 -132
- package/lib/storage-sql/src/workflow-tree-persistence.ts +129 -0
- package/lib/storage-sql/src/workflow-tree-validation.ts +2 -2
- package/lib/storage-sqlite/package.json +1 -1
- package/lib/terminal/package.json +1 -1
- package/lib/testing/dist/files-conformance.d.ts +21 -0
- package/lib/testing/dist/files-conformance.d.ts.map +1 -0
- package/lib/testing/dist/files-conformance.js +155 -0
- package/lib/testing/dist/files-conformance.js.map +1 -0
- package/lib/testing/dist/index.d.ts +3 -0
- package/lib/testing/dist/index.d.ts.map +1 -1
- package/lib/testing/dist/index.js +3 -0
- package/lib/testing/dist/index.js.map +1 -1
- package/lib/testing/dist/model-conformance.d.ts +88 -0
- package/lib/testing/dist/model-conformance.d.ts.map +1 -0
- package/lib/testing/dist/model-conformance.js +177 -0
- package/lib/testing/dist/model-conformance.js.map +1 -0
- package/lib/testing/dist/voice-conformance.d.ts +61 -0
- package/lib/testing/dist/voice-conformance.d.ts.map +1 -0
- package/lib/testing/dist/voice-conformance.js +128 -0
- package/lib/testing/dist/voice-conformance.js.map +1 -0
- package/lib/testing/package.json +1 -1
- package/lib/testing/src/files-conformance.ts +153 -0
- package/lib/testing/src/index.ts +3 -0
- package/lib/testing/src/model-conformance.ts +217 -0
- package/lib/testing/src/voice-conformance.ts +139 -0
- package/lib/tools/package.json +1 -1
- package/lib/voice/dist/audio.d.ts +10 -0
- package/lib/voice/dist/audio.d.ts.map +1 -0
- package/lib/voice/dist/audio.js +44 -0
- package/lib/voice/dist/audio.js.map +1 -0
- package/lib/voice/dist/contracts.d.ts +140 -0
- package/lib/voice/dist/contracts.d.ts.map +1 -0
- package/lib/voice/dist/contracts.js +58 -0
- package/lib/voice/dist/contracts.js.map +1 -0
- package/lib/voice/dist/index.d.ts +6 -0
- package/lib/voice/dist/index.d.ts.map +1 -0
- package/lib/voice/dist/index.js +6 -0
- package/lib/voice/dist/index.js.map +1 -0
- package/lib/voice/dist/registry.d.ts +53 -0
- package/lib/voice/dist/registry.d.ts.map +1 -0
- package/lib/voice/dist/registry.js +218 -0
- package/lib/voice/dist/registry.js.map +1 -0
- package/lib/voice/dist/tools.d.ts +29 -0
- package/lib/voice/dist/tools.d.ts.map +1 -0
- package/lib/voice/dist/tools.js +92 -0
- package/lib/voice/dist/tools.js.map +1 -0
- package/lib/voice/dist/transport.d.ts +24 -0
- package/lib/voice/dist/transport.d.ts.map +1 -0
- package/lib/voice/dist/transport.js +90 -0
- package/lib/voice/dist/transport.js.map +1 -0
- package/lib/voice/package.json +5 -0
- package/lib/voice/src/audio.ts +38 -0
- package/lib/voice/src/contracts.ts +167 -0
- package/lib/voice/src/index.ts +5 -0
- package/lib/voice/src/registry.ts +215 -0
- package/lib/voice/src/tools.ts +91 -0
- package/lib/voice/src/transport.ts +73 -0
- package/lib/workflows/dist/definition.d.ts.map +1 -1
- package/lib/workflows/dist/definition.js +2 -2
- package/lib/workflows/dist/definition.js.map +1 -1
- package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
- package/lib/workflows/dist/operator-transports.js +2 -1
- package/lib/workflows/dist/operator-transports.js.map +1 -1
- package/lib/workflows/package.json +1 -1
- package/lib/workflows/src/definition.ts +2 -2
- package/lib/workflows/src/operator-transports.ts +2 -1
- package/lib/workstream/package.json +1 -1
- package/llms-full.txt +2069 -76
- package/llms.txt +11 -2
- package/memory/index.d.ts +1 -0
- package/memory/index.js +1 -0
- package/memory-remote/index.d.ts +1 -0
- package/memory-remote/index.js +1 -0
- package/observability/index.d.ts +1 -0
- package/observability/index.js +1 -0
- package/package.json +166 -54
- package/provider-anthropic/index.d.ts +1 -0
- package/provider-anthropic/index.js +1 -0
- package/provider-openai/index.d.ts +1 -0
- package/provider-openai/index.js +1 -0
- package/runtime/index.d.ts +1 -0
- package/runtime/index.js +1 -0
- package/sandbox/docker/index.d.ts +1 -0
- package/sandbox/docker/index.js +1 -0
- package/sandbox/index.d.ts +1 -0
- package/sandbox/index.js +1 -0
- package/sandbox/testing/index.d.ts +1 -0
- package/sandbox/testing/index.js +1 -0
- package/sdk/index.d.ts +1 -0
- package/sdk/index.js +1 -0
- package/server/index.d.ts +1 -0
- package/server/index.js +1 -0
- package/server-node/index.d.ts +1 -0
- package/server-node/index.js +1 -0
- package/skills/index.d.ts +1 -0
- package/skills/index.js +1 -0
- package/storage/index.d.ts +1 -0
- package/storage/index.js +1 -0
- package/storage-contracts/index.d.ts +1 -0
- package/storage-contracts/index.js +1 -0
- package/storage-postgres/driver/index.d.ts +1 -0
- package/storage-postgres/driver/index.js +1 -0
- package/storage-postgres/index.d.ts +1 -0
- package/storage-postgres/index.js +1 -0
- package/storage-sql/host/index.d.ts +1 -0
- package/storage-sql/host/index.js +1 -0
- package/storage-sqlite/index.d.ts +1 -0
- package/storage-sqlite/index.js +1 -0
- package/terminal/index.d.ts +1 -0
- package/terminal/index.js +1 -0
- package/testing/index.d.ts +1 -0
- package/testing/index.js +1 -0
- package/tools/host/index.d.ts +1 -0
- package/tools/host/index.js +1 -0
- package/tools/index.d.ts +1 -0
- package/tools/index.js +1 -0
- package/voice/index.d.ts +1 -0
- package/voice/index.js +1 -0
- package/workflows/agents/index.d.ts +1 -0
- package/workflows/agents/index.js +1 -0
- package/workflows/children/index.d.ts +1 -0
- package/workflows/children/index.js +1 -0
- package/workflows/composites/index.d.ts +1 -0
- package/workflows/composites/index.js +1 -0
- package/workflows/ephemeral/index.d.ts +1 -0
- package/workflows/ephemeral/index.js +1 -0
- package/workflows/graphs/index.d.ts +1 -0
- package/workflows/graphs/index.js +1 -0
- package/workflows/index.d.ts +1 -0
- package/workflows/index.js +1 -0
- package/workflows/lifecycle/index.d.ts +1 -0
- package/workflows/lifecycle/index.js +1 -0
- package/workflows/loops/index.d.ts +1 -0
- package/workflows/loops/index.js +1 -0
- package/workflows/sagas/index.d.ts +1 -0
- package/workflows/sagas/index.js +1 -0
- package/workstream/executions/index.d.ts +1 -0
- package/workstream/executions/index.js +1 -0
- package/workstream/humans/index.d.ts +1 -0
- package/workstream/humans/index.js +1 -0
- package/workstream/index.d.ts +1 -0
- package/workstream/index.js +1 -0
- package/workstream/timers/index.d.ts +1 -0
- package/workstream/timers/index.js +1 -0
- package/workstream/webhooks/index.d.ts +1 -0
- package/workstream/webhooks/index.js +1 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { context as contexts, SpanKind, SpanStatusCode, trace, type Attributes, type Context, type Counter, type Histogram, type HrTime, type Meter, type SpanContext, type Tracer } from '@opentelemetry/api';
|
|
2
|
+
import { assertPositiveInteger, MayuraError, type RunEvent } from '@mayura/core';
|
|
3
|
+
import { snapshotRunEventMetadata } from '@mayura/observability';
|
|
4
|
+
import type { OtlpTraceSpan } from './contracts.js';
|
|
5
|
+
import { modelAttributes } from './run-traces.js';
|
|
6
|
+
import { checkedSpan } from './signals.js';
|
|
7
|
+
|
|
8
|
+
export interface OpenTelemetryTraceBridgeOptions {
|
|
9
|
+
/** Your application's tracer, for example `trace.getTracer('orders-agent')`. Mayura's spans become spans of your SDK. */
|
|
10
|
+
readonly tracer: Tracer;
|
|
11
|
+
/**
|
|
12
|
+
* The context a span starts in when its parent is not known to the bridge. Called once per batch; default: the
|
|
13
|
+
* active context, so spans exported inside a request hang under its span.
|
|
14
|
+
*/
|
|
15
|
+
readonly context?: () => Context;
|
|
16
|
+
/** Span ids remembered so later batches can hang under spans exported earlier; the oldest are forgotten first. Default 4,096. */
|
|
17
|
+
readonly maxRememberedSpans?: number;
|
|
18
|
+
/** Spans per batch. Default 1,024. */
|
|
19
|
+
readonly maxBatchSize?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface OpenTelemetryTraceBridge {
|
|
23
|
+
/** Takes the same spans as an OTLP trace exporter: `agentRunTraceSpans`, or `sink` of `createWorkflowTraceExport`. */
|
|
24
|
+
readonly sink: (spans: readonly OtlpTraceSpan[], context: { readonly signal: AbortSignal }) => Promise<void>;
|
|
25
|
+
/** Rejects future batches and forgets the remembered span ids. */
|
|
26
|
+
close(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface OpenTelemetryRunMetricsOptions {
|
|
30
|
+
/** Your application's meter, for example `metrics.getMeter('orders-agent')`. */
|
|
31
|
+
readonly meter: Meter;
|
|
32
|
+
/** Runs followed at once, to pair each model call's start and completion; the oldest are forgotten first. Default 1,024. */
|
|
33
|
+
readonly maxRuns?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface OpenTelemetryRunMetrics {
|
|
37
|
+
/** An observer sink: `createRunObserver({ sink: metrics.sink })`. */
|
|
38
|
+
readonly sink: (events: readonly RunEvent[], context: { readonly signal: AbortSignal }) => Promise<void>;
|
|
39
|
+
/** Stops recording and forgets the runs it follows. */
|
|
40
|
+
close(): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const failed = (): never => { throw new MayuraError('TOOL_FAILED', 'The telemetry export failed. Inspect authorized local diagnostics.'); };
|
|
44
|
+
function bound(value: number | undefined, fallback: number, max: number, name: string): number {
|
|
45
|
+
const result = value ?? fallback; assertPositiveInteger(result, name);
|
|
46
|
+
if (result > max) throw new MayuraError('INVALID_CONFIG', `${name} must be at most ${max}.`);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
function hrTime(nanos: string): HrTime { const value = BigInt(nanos); return [Number(value / 1_000_000_000n), Number(value % 1_000_000_000n)]; }
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Re-create Mayura's metadata-only spans through your application's OpenTelemetry tracer, so they reach whatever your
|
|
53
|
+
* SDK exports to, with its resource, sampler and processors. Your SDK assigns the trace and span ids; parents follow
|
|
54
|
+
* Mayura's tree within a batch and across batches while the parent's id is remembered. Attributes come from the same
|
|
55
|
+
* closed catalog the OTLP exporter checks, and a batch with any invalid span is refused whole.
|
|
56
|
+
*/
|
|
57
|
+
export function createOpenTelemetryTraceBridge(options: OpenTelemetryTraceBridgeOptions): OpenTelemetryTraceBridge {
|
|
58
|
+
const tracer = options?.tracer;
|
|
59
|
+
if (!tracer || typeof tracer.startSpan !== 'function') throw new MayuraError('INVALID_CONFIG', 'The OpenTelemetry trace bridge requires a tracer.');
|
|
60
|
+
if (options.context !== undefined && typeof options.context !== 'function') throw new MayuraError('INVALID_CONFIG', 'The bridge context must be a function.');
|
|
61
|
+
const remember = bound(options.maxRememberedSpans, 4_096, 1_048_576, 'maxRememberedSpans'); const maxBatch = bound(options.maxBatchSize, 1_024, 65_536, 'maxBatchSize');
|
|
62
|
+
const base = options.context ?? ((): Context => contexts.active());
|
|
63
|
+
const known = new Map<string, SpanContext>(); let closed = false;
|
|
64
|
+
const sink = async (spans: readonly OtlpTraceSpan[], context: { readonly signal: AbortSignal }): Promise<void> => {
|
|
65
|
+
if (closed) throw new MayuraError('CONFLICT', 'The OpenTelemetry trace bridge is closed.');
|
|
66
|
+
if (!Array.isArray(spans) || spans.length > maxBatch || !(context?.signal instanceof AbortSignal)) throw new MayuraError('INVALID_INPUT', 'Telemetry batches require admitted records, a signal and supported bounds.');
|
|
67
|
+
if (context.signal.aborted) throw new MayuraError('CANCELLED', 'The telemetry export was cancelled.');
|
|
68
|
+
const checked = spans.map(checkedSpan); const byId = new Map(checked.map(span => [span.spanId, span]));
|
|
69
|
+
// Parents start before their children, so a child can name its parent's new span context.
|
|
70
|
+
const ordered: OtlpTraceSpan[] = []; const placed = new Set<string>();
|
|
71
|
+
for (const span of checked) {
|
|
72
|
+
const chain: OtlpTraceSpan[] = []; let next: OtlpTraceSpan | undefined = span;
|
|
73
|
+
while (next && !placed.has(next.spanId) && !chain.includes(next)) { chain.push(next); next = next.parentSpanId === undefined ? undefined : byId.get(next.parentSpanId); }
|
|
74
|
+
for (const item of chain.reverse()) if (!placed.has(item.spanId)) { placed.add(item.spanId); ordered.push(item); }
|
|
75
|
+
}
|
|
76
|
+
let root: Context;
|
|
77
|
+
try { root = base(); } catch { return failed(); }
|
|
78
|
+
for (const span of ordered) {
|
|
79
|
+
const parent = span.parentSpanId === undefined ? undefined : known.get(span.parentSpanId);
|
|
80
|
+
const attributes: Attributes = { ...span.attributes, ...(span.runId === undefined ? {} : { 'mayura.run.id': span.runId }) };
|
|
81
|
+
const kind = span.attributes?.['gen_ai.operation.name'] === 'chat' ? SpanKind.CLIENT : SpanKind.INTERNAL;
|
|
82
|
+
let created;
|
|
83
|
+
try { created = tracer.startSpan(span.name, { kind, startTime: hrTime(span.startTimeUnixNano), attributes }, parent ? trace.setSpanContext(root, parent) : root); } catch { return failed(); }
|
|
84
|
+
try {
|
|
85
|
+
if (span.status !== 'unset') created.setStatus({ code: span.status === 'ok' ? SpanStatusCode.OK : SpanStatusCode.ERROR });
|
|
86
|
+
known.delete(span.spanId); known.set(span.spanId, created.spanContext());
|
|
87
|
+
while (known.size > remember) known.delete(known.keys().next().value!);
|
|
88
|
+
} catch { return failed(); } finally { try { created.end(hrTime(span.endTimeUnixNano)); } catch { /* The SDK's own failure; the span is ended or abandoned by it. */ } }
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return Object.freeze({ sink, close: (): void => { closed = true; known.clear(); } });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** OpenTelemetry's recommended bucket boundaries for the GenAI client metrics. */
|
|
95
|
+
const durationBuckets = [0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48, 40.96, 81.92];
|
|
96
|
+
const tokenBuckets = [1, 4, 16, 64, 256, 1_024, 4_096, 16_384, 65_536, 262_144, 1_048_576, 4_194_304, 16_777_216, 67_108_864];
|
|
97
|
+
|
|
98
|
+
interface FollowedRun { agentId?: string; model?: RunEvent | undefined; readonly guardrails: Map<string, RunEvent> }
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Record run metrics through your application's OpenTelemetry meter, from the same metadata events an observer sees:
|
|
102
|
+
* OpenTelemetry's GenAI client metrics `gen_ai.client.operation.duration` (seconds) and `gen_ai.client.token.usage`
|
|
103
|
+
* (by `gen_ai.token.type`) for each completed model call, and Mayura's `mayura.cost.micros`, `mayura.runs` (by status)
|
|
104
|
+
* and `mayura.tool.calls` (by tool and status) counters. Events that fail the observability allowlist are skipped.
|
|
105
|
+
*/
|
|
106
|
+
export function createOpenTelemetryRunMetrics(options: OpenTelemetryRunMetricsOptions): OpenTelemetryRunMetrics {
|
|
107
|
+
const meter = options?.meter;
|
|
108
|
+
if (!meter || typeof meter.createHistogram !== 'function' || typeof meter.createCounter !== 'function') throw new MayuraError('INVALID_CONFIG', 'OpenTelemetry run metrics require a meter.');
|
|
109
|
+
const maxRuns = bound(options.maxRuns, 1_024, 1_048_576, 'maxRuns');
|
|
110
|
+
let duration: Histogram; let tokens: Histogram; let cost: Counter; let runs: Counter; let tools: Counter;
|
|
111
|
+
try {
|
|
112
|
+
duration = meter.createHistogram('gen_ai.client.operation.duration', { unit: 's', description: 'GenAI operation duration.', advice: { explicitBucketBoundaries: durationBuckets } });
|
|
113
|
+
tokens = meter.createHistogram('gen_ai.client.token.usage', { unit: '{token}', description: 'Number of input and output tokens used.', advice: { explicitBucketBoundaries: tokenBuckets } });
|
|
114
|
+
cost = meter.createCounter('mayura.cost.micros', { unit: '{micro}', description: 'Model spending, in budget micros.' });
|
|
115
|
+
runs = meter.createCounter('mayura.runs', { unit: '{run}', description: 'Completed agent runs.' });
|
|
116
|
+
tools = meter.createCounter('mayura.tool.calls', { unit: '{call}', description: 'Completed tool calls.' });
|
|
117
|
+
} catch { throw new MayuraError('INVALID_CONFIG', 'OpenTelemetry run metrics require a working meter.'); }
|
|
118
|
+
const followed = new Map<string, FollowedRun>(); let closed = false;
|
|
119
|
+
const follow = (runId: string): FollowedRun => {
|
|
120
|
+
let run = followed.get(runId);
|
|
121
|
+
if (!run) { run = { guardrails: new Map() }; followed.set(runId, run); while (followed.size > maxRuns) followed.delete(followed.keys().next().value!); }
|
|
122
|
+
return run;
|
|
123
|
+
};
|
|
124
|
+
const completed = (start: RunEvent, end: RunEvent): void => {
|
|
125
|
+
const attributes: Attributes = { 'gen_ai.operation.name': 'chat', ...modelAttributes(start.metadata['modelId']) };
|
|
126
|
+
duration.record(Math.max(0, Date.parse(end.timestamp) - Date.parse(start.timestamp)) / 1_000, attributes);
|
|
127
|
+
const input = end.metadata['inputTokens']; const output = end.metadata['outputTokens']; const spent = end.metadata['costMicros'];
|
|
128
|
+
if (typeof input === 'number') tokens.record(input, { ...attributes, 'gen_ai.token.type': 'input' });
|
|
129
|
+
if (typeof output === 'number') tokens.record(output, { ...attributes, 'gen_ai.token.type': 'output' });
|
|
130
|
+
if (typeof spent === 'number' && spent > 0) cost.add(spent, attributes);
|
|
131
|
+
};
|
|
132
|
+
const sink = async (events: readonly RunEvent[], context: { readonly signal: AbortSignal }): Promise<void> => {
|
|
133
|
+
if (closed) throw new MayuraError('CONFLICT', 'OpenTelemetry run metrics are closed.');
|
|
134
|
+
if (!Array.isArray(events) || !(context?.signal instanceof AbortSignal)) throw new MayuraError('INVALID_INPUT', 'Telemetry batches require admitted records, a signal and supported bounds.');
|
|
135
|
+
if (context.signal.aborted) throw new MayuraError('CANCELLED', 'The telemetry export was cancelled.');
|
|
136
|
+
try {
|
|
137
|
+
for (const raw of events) {
|
|
138
|
+
let event: RunEvent; try { event = snapshotRunEventMetadata(raw); } catch { continue; }
|
|
139
|
+
const metadata = event.metadata; const callId = typeof metadata['callId'] === 'string' ? metadata['callId'] : undefined;
|
|
140
|
+
if (event.type === 'run.started') { const agentId = metadata['agentId']; if (typeof agentId === 'string') follow(event.runId).agentId = agentId; }
|
|
141
|
+
else if (event.type === 'model.started') { const run = follow(event.runId); if (callId === undefined) run.model = event; else run.guardrails.set(callId, event); }
|
|
142
|
+
else if (event.type === 'model.completed') {
|
|
143
|
+
const run = followed.get(event.runId); if (!run) continue;
|
|
144
|
+
const start = callId === undefined ? run.model : run.guardrails.get(callId); if (!start) continue;
|
|
145
|
+
if (callId === undefined) run.model = undefined; else run.guardrails.delete(callId);
|
|
146
|
+
completed(start, event);
|
|
147
|
+
} else if (event.type === 'tool.completed') {
|
|
148
|
+
tools.add(1, { 'gen_ai.tool.name': metadata['toolId'] as string, 'mayura.tool.status': metadata['status'] as string });
|
|
149
|
+
} else if (event.type === 'run.completed') {
|
|
150
|
+
const agentId = followed.get(event.runId)?.agentId; followed.delete(event.runId);
|
|
151
|
+
runs.add(1, { 'mayura.run.status': metadata['status'] as string, ...(agentId === undefined ? {} : { 'gen_ai.agent.id': agentId }) });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch { return failed(); }
|
|
155
|
+
};
|
|
156
|
+
return Object.freeze({ sink, close: (): void => { closed = true; followed.clear(); } });
|
|
157
|
+
}
|
|
@@ -74,7 +74,7 @@ function record(event: RunEvent): JsonObject {
|
|
|
74
74
|
function request(events: readonly RunEvent[], serviceName: string, serviceVersion?: string): JsonObject {
|
|
75
75
|
const attributes = [attribute('service.name', serviceName)];
|
|
76
76
|
if (serviceVersion) attributes.push(attribute('service.version', serviceVersion));
|
|
77
|
-
return { resourceLogs: [{ resource: { attributes }, scopeLogs: [{ scope: { name: '@mayura/observability', version: '1.
|
|
77
|
+
return { resourceLogs: [{ resource: { attributes }, scopeLogs: [{ scope: { name: '@mayura/observability', version: '1.1.0' }, logRecords: events.map(record) }] }] };
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
async function abortable<T>(operation: Promise<T>, signal: AbortSignal): Promise<T> {
|
|
@@ -102,10 +102,17 @@ async function responsePayload(response: Response, limit: number, signal: AbortS
|
|
|
102
102
|
chunks.push(item.value);
|
|
103
103
|
}
|
|
104
104
|
if (size === 0) return {};
|
|
105
|
-
if (!/^application\/json(?:\s*;|$)/iu.test(response.headers.get('content-type') ?? '')) return failed();
|
|
106
105
|
const bytes = new Uint8Array(size); let offset = 0;
|
|
107
106
|
for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.byteLength; }
|
|
108
|
-
|
|
107
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
108
|
+
const type = response.headers.get('content-type') ?? '';
|
|
109
|
+
if (!/^application\/json(?:\s*;|$)/iu.test(type)) {
|
|
110
|
+
// Some services (LangSmith) answer full success as `{}` labelled text/plain. Only that empty answer is taken
|
|
111
|
+
// without the JSON type: anything that could report partial success must say it is JSON.
|
|
112
|
+
if (/^text\/plain(?:\s*;|$)/iu.test(type) && text.trim() === '{}') return {};
|
|
113
|
+
return failed();
|
|
114
|
+
}
|
|
115
|
+
return object(jsonValue(JSON.parse(text), { maxBytes: limit, maxDepth: 8, maxNodes: 1_024 }));
|
|
109
116
|
} finally { void reader.cancel().catch(() => undefined); reader.releaseLock(); }
|
|
110
117
|
}
|
|
111
118
|
function rejectedRecords(payload: JsonObject, sent: number): number {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { MayuraError, type JsonObject, type JsonValue } from '@mayura/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OTLP's protobuf encoding for the trace requests Mayura builds, written by hand so the exporter stays free of
|
|
5
|
+
* dependencies. It covers exactly what the JSON encoder emits: resource and span attributes with string and integer
|
|
6
|
+
* values, one scope, and spans with ids, name, kind, times and status. Field numbers follow
|
|
7
|
+
* opentelemetry/proto/collector/trace/v1 and trace/v1 (ExportTraceServiceRequest, ResourceSpans, ScopeSpans, Span).
|
|
8
|
+
*/
|
|
9
|
+
const invalid = (): never => { throw new MayuraError('INVALID_INPUT', 'Trace span metadata is invalid.'); };
|
|
10
|
+
|
|
11
|
+
class Writer {
|
|
12
|
+
private readonly parts: Uint8Array[] = []; length = 0;
|
|
13
|
+
private push(bytes: Uint8Array): void { this.parts.push(bytes); this.length += bytes.byteLength; }
|
|
14
|
+
private varint(value: bigint): void {
|
|
15
|
+
const bytes: number[] = []; let rest = value;
|
|
16
|
+
do { let byte = Number(rest & 0x7fn); rest >>= 7n; if (rest > 0n) byte |= 0x80; bytes.push(byte); } while (rest > 0n);
|
|
17
|
+
this.push(Uint8Array.from(bytes));
|
|
18
|
+
}
|
|
19
|
+
private tag(field: number, wire: 0 | 1 | 2): void { this.varint(BigInt((field << 3) | wire)); }
|
|
20
|
+
/** A varint field; proto3 leaves zero out, except for a oneof member (`always`), which is written whenever set. */
|
|
21
|
+
uint(field: number, value: bigint, always = false): void { if (value < 0n || value > 0xffffffffffffffffn) invalid(); if (value === 0n && !always) return; this.tag(field, 0); this.varint(value); }
|
|
22
|
+
fixed64(field: number, value: bigint): void {
|
|
23
|
+
if (value < 0n || value > 0xffffffffffffffffn) invalid();
|
|
24
|
+
const bytes = new Uint8Array(8); let rest = value; for (let index = 0; index < 8; index++) { bytes[index] = Number(rest & 0xffn); rest >>= 8n; }
|
|
25
|
+
this.tag(field, 1); this.push(bytes);
|
|
26
|
+
}
|
|
27
|
+
bytes(field: number, value: Uint8Array): void { this.tag(field, 2); this.varint(BigInt(value.byteLength)); this.push(value); }
|
|
28
|
+
string(field: number, value: string): void { if (value) this.bytes(field, new TextEncoder().encode(value)); }
|
|
29
|
+
message(field: number, build: (writer: Writer) => void): void { const inner = new Writer(); build(inner); this.bytes(field, inner.finish()); }
|
|
30
|
+
finish(): Uint8Array<ArrayBuffer> { const out = new Uint8Array(this.length); let offset = 0; for (const part of this.parts) { out.set(part, offset); offset += part.byteLength; } return out; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const record = (value: JsonValue | undefined): JsonObject => (value && typeof value === 'object' && !Array.isArray(value) ? value : invalid());
|
|
34
|
+
const list = (value: JsonValue | undefined): readonly JsonValue[] => (value === undefined ? [] : Array.isArray(value) ? value : invalid());
|
|
35
|
+
const text = (value: JsonValue | undefined): string => (typeof value === 'string' ? value : invalid());
|
|
36
|
+
const hex = (value: JsonValue | undefined, length: number): Uint8Array => {
|
|
37
|
+
const string = text(value); if (string.length !== length * 2 || !/^[0-9a-f]+$/u.test(string)) return invalid();
|
|
38
|
+
return Uint8Array.from({ length }, (_, index) => Number.parseInt(string.slice(index * 2, index * 2 + 2), 16));
|
|
39
|
+
};
|
|
40
|
+
const decimal = (value: JsonValue | undefined): bigint => { const string = text(value); if (!/^(?:0|[1-9]\d{0,19})$/u.test(string)) invalid(); return BigInt(string); };
|
|
41
|
+
|
|
42
|
+
/** KeyValue { key = 1; AnyValue value = 2 }, AnyValue { string_value = 1; int_value = 3 }. */
|
|
43
|
+
function keyValues(writer: Writer, field: number, attributes: JsonValue | undefined): void {
|
|
44
|
+
for (const item of list(attributes)) {
|
|
45
|
+
const entry = record(item); const value = record(entry['value']);
|
|
46
|
+
writer.message(field, pair => {
|
|
47
|
+
pair.string(1, text(entry['key']));
|
|
48
|
+
pair.message(2, any => {
|
|
49
|
+
if (typeof value['stringValue'] === 'string') any.string(1, value['stringValue']);
|
|
50
|
+
else if (value['intValue'] !== undefined) any.uint(3, decimal(value['intValue']), true);
|
|
51
|
+
else invalid();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** ExportTraceServiceRequest from the OTLP/JSON request the trace exporter built and checked. */
|
|
58
|
+
export function otlpTraceProtobuf(request: JsonObject): Uint8Array<ArrayBuffer> {
|
|
59
|
+
const writer = new Writer();
|
|
60
|
+
for (const resourceSpans of list(request['resourceSpans'])) {
|
|
61
|
+
const resource = record(resourceSpans);
|
|
62
|
+
writer.message(1, rs => {
|
|
63
|
+
rs.message(1, r => keyValues(r, 1, record(resource['resource'])['attributes']));
|
|
64
|
+
for (const scopeSpans of list(resource['scopeSpans'])) {
|
|
65
|
+
const scoped = record(scopeSpans);
|
|
66
|
+
rs.message(2, ss => {
|
|
67
|
+
const scope = record(scoped['scope']); ss.message(1, s => { s.string(1, text(scope['name'])); s.string(2, text(scope['version'])); });
|
|
68
|
+
for (const item of list(scoped['spans'])) {
|
|
69
|
+
const span = record(item);
|
|
70
|
+
ss.message(2, sp => {
|
|
71
|
+
sp.bytes(1, hex(span['traceId'], 16)); sp.bytes(2, hex(span['spanId'], 8));
|
|
72
|
+
if (span['parentSpanId'] !== undefined) sp.bytes(4, hex(span['parentSpanId'], 8));
|
|
73
|
+
sp.string(5, text(span['name']));
|
|
74
|
+
if (typeof span['kind'] !== 'number') invalid(); sp.uint(6, BigInt(span['kind'] as number));
|
|
75
|
+
sp.fixed64(7, decimal(span['startTimeUnixNano'])); sp.fixed64(8, decimal(span['endTimeUnixNano']));
|
|
76
|
+
keyValues(sp, 9, span['attributes']);
|
|
77
|
+
const code = record(span['status'])['code']; if (typeof code !== 'number') invalid();
|
|
78
|
+
sp.message(15, status => status.uint(3, BigInt(code as number)));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return writer.finish();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Reads a protobuf varint at `offset`; returns the value and the next offset. */
|
|
89
|
+
function readVarint(bytes: Uint8Array, offset: number): [bigint, number] {
|
|
90
|
+
let value = 0n; let shift = 0n;
|
|
91
|
+
for (let index = offset; index < bytes.byteLength && shift < 70n; index++) {
|
|
92
|
+
const byte = bytes[index]!; value |= BigInt(byte & 0x7f) << shift; shift += 7n;
|
|
93
|
+
if (!(byte & 0x80)) return [value, index + 1];
|
|
94
|
+
}
|
|
95
|
+
throw new Error();
|
|
96
|
+
}
|
|
97
|
+
/** Top-level fields of a message: field number to the last value (varint) or byte range (length-delimited). */
|
|
98
|
+
function fields(bytes: Uint8Array): Map<number, bigint | Uint8Array> {
|
|
99
|
+
const result = new Map<number, bigint | Uint8Array>(); let offset = 0;
|
|
100
|
+
while (offset < bytes.byteLength) {
|
|
101
|
+
const [key, next] = readVarint(bytes, offset); offset = next; const field = Number(key >> 3n); const wire = Number(key & 7n);
|
|
102
|
+
if (field < 1) throw new Error();
|
|
103
|
+
if (wire === 0) { const [value, after] = readVarint(bytes, offset); result.set(field, value); offset = after; }
|
|
104
|
+
else if (wire === 1) { offset += 8; } else if (wire === 5) { offset += 4; }
|
|
105
|
+
else if (wire === 2) { const [length, after] = readVarint(bytes, offset); const end = after + Number(length); result.set(field, bytes.subarray(after, end)); offset = end; }
|
|
106
|
+
else throw new Error();
|
|
107
|
+
if (offset > bytes.byteLength) throw new Error();
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The partial success of an Export*ServiceResponse (`partial_success = 1`, its rejected count `= 1`), in the OTLP/JSON
|
|
113
|
+
* shape the exporter reads; the error message is never read.
|
|
114
|
+
*/
|
|
115
|
+
export function otlpPartialSuccess(bytes: Uint8Array, field: 'rejectedSpans' | 'rejectedDataPoints'): JsonObject {
|
|
116
|
+
try {
|
|
117
|
+
const partial = fields(bytes).get(1); if (partial === undefined) return {};
|
|
118
|
+
if (!(partial instanceof Uint8Array)) throw new Error();
|
|
119
|
+
const rejected = fields(partial).get(1); if (rejected === undefined) return { partialSuccess: {} };
|
|
120
|
+
if (typeof rejected !== 'bigint') throw new Error();
|
|
121
|
+
return { partialSuccess: { [field]: rejected.toString() } };
|
|
122
|
+
} catch { throw new MayuraError('TOOL_FAILED', 'The telemetry export failed. Inspect authorized local diagnostics.'); }
|
|
123
|
+
}
|
|
@@ -20,6 +20,20 @@ function derivedId(parts: readonly string[], length: 16 | 32): string {
|
|
|
20
20
|
const value = length === 16 ? hash64(bytes, 0n) : `${hash64(bytes, 1n)}${hash64(bytes, 2n)}`;
|
|
21
21
|
return /^0+$/.test(value) ? `${value.slice(0, -1)}1` : value;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Mayura's model provider ids as OpenTelemetry's well-known `gen_ai.provider.name` values, where one exists; other
|
|
25
|
+
* providers keep their own id.
|
|
26
|
+
*/
|
|
27
|
+
const providerNames: Readonly<Record<string, string>> = { openai: 'openai', anthropic: 'anthropic', bedrock: 'aws.bedrock', azure: 'azure.ai.openai',
|
|
28
|
+
google: 'gcp.gemini', vertex: 'gcp.vertex_ai', mistral: 'mistral_ai', groq: 'groq', cohere: 'cohere', deepseek: 'deepseek', xai: 'x_ai', perplexity: 'perplexity' };
|
|
29
|
+
/** GenAI attributes for a model call, from a registry id such as `openai/gpt-5`; nothing for an id without a provider. */
|
|
30
|
+
export function modelAttributes(modelId: unknown): OtlpSpanAttributes {
|
|
31
|
+
if (typeof modelId !== 'string' || !stable.test(modelId)) return {};
|
|
32
|
+
const slash = modelId.indexOf('/');
|
|
33
|
+
if (slash <= 0) return { 'mayura.model.id': modelId };
|
|
34
|
+
const provider = modelId.slice(0, slash); const model = modelId.slice(slash + 1);
|
|
35
|
+
return { 'mayura.model.id': modelId, 'gen_ai.provider.name': providerNames[provider] ?? provider, ...(model && stable.test(model) ? { 'gen_ai.request.model': model } : {}) };
|
|
36
|
+
}
|
|
23
37
|
const nanos = (milliseconds: number): string => (BigInt(milliseconds) * 1_000_000n).toString();
|
|
24
38
|
const spanStatus = (status: unknown): OtlpTraceSpan['status'] => status === 'succeeded' ? 'ok' : status === 'cancelled' || status === undefined ? 'unset' : 'error';
|
|
25
39
|
|
|
@@ -60,21 +74,26 @@ export function agentRunTraceSpans(events: readonly RunEvent[], options: AgentRu
|
|
|
60
74
|
const start = typeof metadata['callId'] === 'string' ? guarded.get(metadata['callId']) : model;
|
|
61
75
|
if (!start) continue;
|
|
62
76
|
if (typeof metadata['callId'] === 'string') guarded.delete(metadata['callId']); else model = undefined;
|
|
63
|
-
const call = start.metadata['modelCall'];
|
|
64
|
-
|
|
77
|
+
const call = start.metadata['modelCall']; const cost = event.metadata['costMicros'];
|
|
78
|
+
const input = event.metadata['inputTokens']; const output = event.metadata['outputTokens'];
|
|
79
|
+
spans.push(child(['model', String(start.sequence)], 'model.call', start, event, 'ok', { 'gen_ai.operation.name': 'chat', ...modelAttributes(start.metadata['modelId']),
|
|
80
|
+
...(typeof call === 'number' ? { 'mayura.model.call': call } : {}), ...(typeof cost === 'number' ? { 'mayura.cost.micros': cost } : {}),
|
|
81
|
+
...(typeof input === 'number' ? { 'gen_ai.usage.input_tokens': input } : {}), ...(typeof output === 'number' ? { 'gen_ai.usage.output_tokens': output } : {}) }));
|
|
65
82
|
} else if (event.type === 'tool.started') tools.set(String(metadata['callId']), event);
|
|
66
83
|
else if (event.type === 'tool.completed') {
|
|
67
84
|
const callId = String(metadata['callId']); const start = tools.get(callId); if (!start) continue; tools.delete(callId);
|
|
68
85
|
const toolId = String(metadata['toolId']); const name = stable.test(`tool:${toolId}`) ? `tool:${toolId}` : 'tool.call';
|
|
69
|
-
spans.push(child(['tool', callId], name, start, event, spanStatus(metadata['status']), { '
|
|
86
|
+
spans.push(child(['tool', callId], name, start, event, spanStatus(metadata['status']), { 'gen_ai.operation.name': 'execute_tool', 'gen_ai.tool.type': 'function',
|
|
87
|
+
...(stable.test(toolId) ? { 'gen_ai.tool.name': toolId } : {}), ...(stable.test(callId) ? { 'gen_ai.tool.call.id': callId } : {}),
|
|
88
|
+
'mayura.tool.id': toolId, 'mayura.tool.status': String(metadata['status']),
|
|
70
89
|
...(typeof metadata['execution'] === 'string' ? { 'mayura.workflow.receipt.execution': metadata['execution'] } : {}) }));
|
|
71
90
|
}
|
|
72
91
|
}
|
|
73
92
|
const started = own.find(event => event.type === 'run.started'); if (!started) return spans;
|
|
74
93
|
const completed = own.find(event => event.type === 'run.completed'); const last = completed ?? own[own.length - 1]!;
|
|
75
94
|
const agentId = started.metadata['agentId']; const status = completed?.metadata['status'];
|
|
76
|
-
const attributes: Record<string, string | number> = {};
|
|
77
|
-
if (typeof agentId === 'string') attributes['mayura.agent.id'] = agentId;
|
|
95
|
+
const attributes: Record<string, string | number> = { 'gen_ai.operation.name': 'invoke_agent' };
|
|
96
|
+
if (typeof agentId === 'string') { attributes['mayura.agent.id'] = agentId; attributes['gen_ai.agent.id'] = agentId; attributes['gen_ai.agent.name'] = agentId; }
|
|
78
97
|
if (typeof status === 'string') attributes['mayura.run.status'] = status;
|
|
79
98
|
// Exact costs above 2^53 are decimal strings in run events; the span catalog carries safe integers only.
|
|
80
99
|
for (const [key, name] of [['spentMicros', 'mayura.budget.spent_micros'], ['reservedMicros', 'mayura.budget.reserved_micros']] as const) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { assertPositiveInteger, jsonValue, MayuraError, type JsonObject, type JsonValue } from '@mayura/core';
|
|
2
2
|
import type {
|
|
3
3
|
ExactCount, OtlpHttpJsonMetricExporter, OtlpHttpJsonMetricExporterOptions, OtlpHttpJsonSignalExporterOptions,
|
|
4
|
-
OtlpHttpJsonTraceExporter, OtlpHttpJsonTraceExporterOptions, OtlpLogExporterMetrics, OtlpMetricPoint,
|
|
5
|
-
OtlpSignalExporterSnapshot, OtlpSpanAttributeName, OtlpTraceSpan,
|
|
4
|
+
OtlpHttpJsonTraceExporter, OtlpHttpJsonTraceExporterOptions, OtlpHttpProtobufTraceExporter, OtlpHttpProtobufTraceExporterOptions, OtlpLogExporterMetrics, OtlpMetricPoint,
|
|
5
|
+
OtlpExtraAttributes, OtlpSignalExporterSnapshot, OtlpSpanAttributeName, OtlpSpanAttributes, OtlpTraceSpan,
|
|
6
6
|
} from './contracts.js';
|
|
7
|
+
import { otlpPartialSuccess, otlpTraceProtobuf } from './protobuf.js';
|
|
7
8
|
|
|
8
9
|
const defaults = Object.freeze({ timeoutMs: 5_000, maxBatchSize: 256, maxRequestBytes: 1_048_576, maxResponseBytes: 65_536 });
|
|
9
10
|
const metrics = ['batchesAttempted', 'recordsAttempted', 'recordsAccepted', 'recordsDropped', 'partialResponses', 'failedRequests', 'timedOutRequests', 'cancelledRequests', 'requestBytes', 'responseBytes'] as const;
|
|
@@ -21,7 +22,8 @@ const spanAttributeNames: ReadonlySet<string> = new Set<OtlpSpanAttributeName>([
|
|
|
21
22
|
'mayura.workflow.definition.id', 'mayura.workflow.definition.version', 'mayura.workflow.definition.digest', 'mayura.workflow.status', 'mayura.workflow.events',
|
|
22
23
|
'mayura.workflow.node.id', 'mayura.workflow.node.kind', 'mayura.workflow.step.status', 'mayura.workflow.step.code', 'mayura.workflow.receipt.execution',
|
|
23
24
|
'mayura.workflow.child.run.id', 'mayura.agent.id', 'mayura.run.status', 'mayura.model.call', 'mayura.tool.id', 'mayura.tool.version', 'mayura.tool.status',
|
|
24
|
-
'mayura.budget.spent_micros', 'mayura.budget.reserved_micros', 'mayura.budget.max_micros', 'mayura.budget.step_cost_micros'
|
|
25
|
+
'mayura.budget.spent_micros', 'mayura.budget.reserved_micros', 'mayura.budget.max_micros', 'mayura.budget.step_cost_micros', 'mayura.model.id', 'mayura.cost.micros',
|
|
26
|
+
'gen_ai.operation.name', 'gen_ai.provider.name', 'gen_ai.request.model', 'gen_ai.agent.id', 'gen_ai.agent.name', 'gen_ai.tool.name', 'gen_ai.tool.call.id', 'gen_ai.tool.type', 'gen_ai.usage.input_tokens', 'gen_ai.usage.output_tokens']);
|
|
25
27
|
|
|
26
28
|
const failed = (): never => { throw new MayuraError('TOOL_FAILED', 'The telemetry export failed. Inspect authorized local diagnostics.'); };
|
|
27
29
|
function exact(value: bigint): ExactCount { return value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value.toString(); }
|
|
@@ -30,11 +32,11 @@ function stable(value: unknown): string {
|
|
|
30
32
|
if (typeof value !== 'string' || !stablePattern.test(value)) throw new MayuraError('INVALID_CONFIG', 'Exporter names must be bounded stable identifiers.');
|
|
31
33
|
return value;
|
|
32
34
|
}
|
|
33
|
-
function destination(value: unknown, signal: 'traces' | 'metrics', allowLoopback: boolean): string {
|
|
35
|
+
function destination(value: unknown, signal: 'traces' | 'metrics', allowLoopback: boolean, standardPath: boolean): string {
|
|
34
36
|
try {
|
|
35
37
|
if (typeof value !== 'string' || value.length > 2_048) throw new Error(); const url = new URL(value);
|
|
36
38
|
const loopback = ['127.0.0.1', '[::1]'].includes(url.hostname);
|
|
37
|
-
if ((url.protocol !== 'https:' && !(allowLoopback && url.protocol === 'http:' && loopback)) || url.username || url.password || url.search || url.hash || !url.pathname.endsWith(`/v1/${signal}`)) throw new Error();
|
|
39
|
+
if ((url.protocol !== 'https:' && !(allowLoopback && url.protocol === 'http:' && loopback)) || url.username || url.password || url.search || url.hash || (standardPath && !url.pathname.endsWith(`/v1/${signal}`))) throw new Error();
|
|
38
40
|
return url.href;
|
|
39
41
|
} catch { throw new MayuraError('INVALID_CONFIG', `OTLP ${signal} require an explicit HTTPS endpoint ending in /v1/${signal}.`); }
|
|
40
42
|
}
|
|
@@ -72,7 +74,26 @@ function spanAttributes(value: JsonValue | undefined): JsonObject[] {
|
|
|
72
74
|
return { key, value: typeof item === 'string' ? { stringValue: item } : { intValue: String(item) } };
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
|
-
|
|
77
|
+
const extraKey = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/u;
|
|
78
|
+
/** A provider's extra attributes, checked and encoded in key order; `refuse` reports anything outside the rules. */
|
|
79
|
+
function extraAttributes(value: unknown, reserved: ReadonlySet<string>, refuse: () => never): JsonObject[] {
|
|
80
|
+
if (value === undefined) return [];
|
|
81
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)) return refuse();
|
|
82
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
83
|
+
if (Object.getOwnPropertySymbols(value).length || Object.keys(descriptors).length > 16) return refuse();
|
|
84
|
+
return Object.keys(descriptors).sort().map(key => {
|
|
85
|
+
const descriptor = descriptors[key]!; const item: unknown = descriptor.value;
|
|
86
|
+
if (!descriptor.enumerable || !('value' in descriptor) || key.length > 128 || !extraKey.test(key) || reserved.has(key) || key.startsWith('mayura.') || key.startsWith('service.')
|
|
87
|
+
|| !((typeof item === 'string' && stablePattern.test(item)) || (typeof item === 'number' && Number.isSafeInteger(item) && item >= 0))) return refuse();
|
|
88
|
+
return { key, value: typeof item === 'string' ? { stringValue: item } : { intValue: String(item) } };
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const refusedSpan = (): never => { throw new MayuraError('INVALID_INPUT', 'Trace span metadata is invalid.'); };
|
|
92
|
+
type SpanAttributeHook = (span: OtlpTraceSpan) => OtlpExtraAttributes | undefined;
|
|
93
|
+
interface EncodeSetup { readonly serviceName: string; readonly serviceVersion: string | undefined; readonly resource: readonly JsonObject[]; readonly spanAttributes: SpanAttributeHook | undefined }
|
|
94
|
+
|
|
95
|
+
/** A span checked against the bounds and the attribute catalog, as a plain copy: what the OTLP encoder and the OpenTelemetry bridge accept. */
|
|
96
|
+
export function checkedSpan(value: unknown): OtlpTraceSpan {
|
|
76
97
|
const raw = object(jsonValue(value, { maxBytes: 8_192, maxDepth: 4, maxNodes: 96 }));
|
|
77
98
|
if (Object.keys(raw).some(key => !['traceId', 'spanId', 'parentSpanId', 'name', 'startTimeUnixNano', 'endTimeUnixNano', 'status', 'runId', 'attributes'].includes(key))
|
|
78
99
|
|| typeof raw['traceId'] !== 'string' || !traceId.test(raw['traceId']) || typeof raw['spanId'] !== 'string' || !spanId.test(raw['spanId'])
|
|
@@ -81,10 +102,23 @@ function span(value: unknown): JsonObject {
|
|
|
81
102
|
|| (raw['runId'] !== undefined && (typeof raw['runId'] !== 'string' || !stablePattern.test(raw['runId'])))) throw new MayuraError('INVALID_INPUT', 'Trace span metadata is invalid.');
|
|
82
103
|
const start = nano(raw['startTimeUnixNano'], 'Span start'); const end = nano(raw['endTimeUnixNano'], 'Span end');
|
|
83
104
|
if (BigInt(end) < BigInt(start)) throw new MayuraError('INVALID_INPUT', 'Span end must not precede its start.');
|
|
84
|
-
|
|
85
|
-
return { traceId: raw['traceId'], spanId: raw['spanId'], ...(raw['parentSpanId'] === undefined ? {} : { parentSpanId: raw['parentSpanId'] }), name: raw['name'],
|
|
86
|
-
startTimeUnixNano: start, endTimeUnixNano: end, status: {
|
|
87
|
-
|
|
105
|
+
spanAttributes(raw['attributes']);
|
|
106
|
+
return { traceId: raw['traceId'], spanId: raw['spanId'], ...(raw['parentSpanId'] === undefined ? {} : { parentSpanId: raw['parentSpanId'] as string }), name: raw['name'],
|
|
107
|
+
startTimeUnixNano: start, endTimeUnixNano: end, status: raw['status'] as OtlpTraceSpan['status'], ...(raw['runId'] === undefined ? {} : { runId: raw['runId'] as string }),
|
|
108
|
+
...(raw['attributes'] === undefined ? {} : { attributes: raw['attributes'] as OtlpSpanAttributes }) };
|
|
109
|
+
}
|
|
110
|
+
function span(value: unknown, hook: SpanAttributeHook | undefined): JsonObject {
|
|
111
|
+
const checked = checkedSpan(value);
|
|
112
|
+
let added: JsonObject[] = [];
|
|
113
|
+
if (hook) {
|
|
114
|
+
let derived: unknown;
|
|
115
|
+
try { derived = hook(Object.freeze({ ...checked, ...(checked.attributes === undefined ? {} : { attributes: Object.freeze({ ...checked.attributes }) }) })); } catch { return refusedSpan(); }
|
|
116
|
+
added = extraAttributes(derived, spanAttributeNames, refusedSpan);
|
|
117
|
+
}
|
|
118
|
+
const status = checked.status === 'ok' ? 1 : checked.status === 'error' ? 2 : 0;
|
|
119
|
+
return { traceId: checked.traceId, spanId: checked.spanId, ...(checked.parentSpanId === undefined ? {} : { parentSpanId: checked.parentSpanId }), name: checked.name, kind: 1,
|
|
120
|
+
startTimeUnixNano: checked.startTimeUnixNano, endTimeUnixNano: checked.endTimeUnixNano, status: { code: status },
|
|
121
|
+
attributes: [...attributes({ 'mayura.run.id': checked.runId }), ...spanAttributes(checked.attributes as JsonValue | undefined), ...added] };
|
|
88
122
|
}
|
|
89
123
|
function point(value: unknown): { readonly name: string; readonly kind: 'gauge'; readonly data: JsonObject }
|
|
90
124
|
| { readonly name: string; readonly kind: 'sum'; readonly data: JsonObject; readonly monotonic: boolean } {
|
|
@@ -104,11 +138,11 @@ function point(value: unknown): { readonly name: string; readonly kind: 'gauge';
|
|
|
104
138
|
...(start === undefined ? {} : { startTimeUnixNano: start }), timeUnixNano: time, asDouble: raw['value'] };
|
|
105
139
|
return kind === 'gauge' ? { name: raw['name'], kind, data } : { name: raw['name'], kind, data, monotonic: raw['monotonic'] as boolean };
|
|
106
140
|
}
|
|
107
|
-
function resource(
|
|
108
|
-
function traceRequest(records: readonly unknown[],
|
|
109
|
-
return { resourceSpans: [{ resource: resource(
|
|
141
|
+
function resource(setup: EncodeSetup): JsonObject { return { attributes: [...attributes({ 'service.name': setup.serviceName, 'service.version': setup.serviceVersion }), ...setup.resource] }; }
|
|
142
|
+
function traceRequest(records: readonly unknown[], setup: EncodeSetup): JsonObject {
|
|
143
|
+
return { resourceSpans: [{ resource: resource(setup), scopeSpans: [{ scope: { name: '@mayura/observability', version: '1.1.0' }, spans: records.map(record => span(record, setup.spanAttributes)) }] }] };
|
|
110
144
|
}
|
|
111
|
-
function metricRequest(records: readonly unknown[],
|
|
145
|
+
function metricRequest(records: readonly unknown[], setup: EncodeSetup): JsonObject {
|
|
112
146
|
const grouped = new Map<string, ReturnType<typeof point>[]>();
|
|
113
147
|
for (const item of records.map(point)) {
|
|
114
148
|
const existing = grouped.get(item.name) ?? [];
|
|
@@ -118,23 +152,33 @@ function metricRequest(records: readonly unknown[], serviceName: string, service
|
|
|
118
152
|
const encoded = [...grouped.values()].map(items => { const first = items[0]!; return { name: first.name,
|
|
119
153
|
...(first.kind === 'gauge' ? { gauge: { dataPoints: items.map(item => item.data) } }
|
|
120
154
|
: { sum: { dataPoints: items.map(item => item.data), aggregationTemporality: 2, isMonotonic: first.monotonic } }) }; });
|
|
121
|
-
return { resourceMetrics: [{ resource: resource(
|
|
155
|
+
return { resourceMetrics: [{ resource: resource(setup), scopeMetrics: [{ scope: { name: '@mayura/observability', version: '1.1.0' }, metrics: encoded }] }] };
|
|
122
156
|
}
|
|
123
157
|
async function abortable<T>(operation: Promise<T>, signal: AbortSignal): Promise<T> {
|
|
124
158
|
if (signal.aborted) { void operation.catch(() => undefined); throw signal.reason; } let listener: (() => void) | undefined;
|
|
125
159
|
try { return await Promise.race([operation, new Promise<never>((_, reject) => { listener = () => reject(signal.reason); signal.addEventListener('abort', listener, { once: true }); if (signal.aborted) listener(); })]); }
|
|
126
160
|
finally { if (listener) signal.removeEventListener('abort', listener); }
|
|
127
161
|
}
|
|
128
|
-
async function responsePayload(response: Response, limit: number, signal: AbortSignal, charge: (bytes: number) => void
|
|
162
|
+
async function responsePayload(response: Response, limit: number, signal: AbortSignal, charge: (bytes: number) => void,
|
|
163
|
+
protobuf?: 'rejectedSpans' | 'rejectedDataPoints'): Promise<JsonObject> {
|
|
129
164
|
if (response.status !== 200 || response.redirected) { void response.body?.cancel().catch(() => undefined); return failed(); }
|
|
130
165
|
if (!response.body) return {}; const length = response.headers.get('content-length');
|
|
131
166
|
if (length !== null && (!/^\d+$/.test(length) || Number(length) > limit)) { void response.body.cancel().catch(() => undefined); return failed(); }
|
|
132
167
|
const reader = response.body.getReader(); const chunks: Uint8Array[] = []; let size = 0;
|
|
133
168
|
try {
|
|
134
169
|
for (;;) { const item = await abortable(reader.read(), signal); if (item.done) break; size += item.value.byteLength; charge(item.value.byteLength); if (size > limit) return failed(); chunks.push(item.value); }
|
|
135
|
-
if (!size) return {};
|
|
170
|
+
if (!size) return {}; const type = response.headers.get('content-type') ?? '';
|
|
136
171
|
const bytes = new Uint8Array(size); let offset = 0; for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.byteLength; }
|
|
137
|
-
|
|
172
|
+
// A protobuf request is answered in protobuf, though a collector may answer in JSON.
|
|
173
|
+
if (protobuf && /^application\/x-protobuf(?:\s*;|$)/iu.test(type)) return otlpPartialSuccess(bytes, protobuf);
|
|
174
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
175
|
+
if (!/^application\/json(?:\s*;|$)/iu.test(type)) {
|
|
176
|
+
// Some services (LangSmith) answer full success as `{}` labelled text/plain. Only that empty answer is taken
|
|
177
|
+
// without the JSON type: anything that could report partial success must say it is JSON.
|
|
178
|
+
if (/^text\/plain(?:\s*;|$)/iu.test(type) && text.trim() === '{}') return {};
|
|
179
|
+
return failed();
|
|
180
|
+
}
|
|
181
|
+
return object(jsonValue(JSON.parse(text), { maxBytes: limit, maxDepth: 8, maxNodes: 1_024 }));
|
|
138
182
|
} finally { void reader.cancel().catch(() => undefined); reader.releaseLock(); }
|
|
139
183
|
}
|
|
140
184
|
function rejected(payload: JsonObject, field: 'rejectedSpans' | 'rejectedDataPoints', sent: number): number {
|
|
@@ -144,15 +188,20 @@ function rejected(payload: JsonObject, field: 'rejectedSpans' | 'rejectedDataPoi
|
|
|
144
188
|
}
|
|
145
189
|
|
|
146
190
|
function createSignalExporter<T>(signalName: 'traces' | 'metrics', options: OtlpHttpJsonSignalExporterOptions,
|
|
147
|
-
encode: (records: readonly T[],
|
|
148
|
-
let config: typeof defaults; let endpoint: string; let
|
|
191
|
+
encode: (records: readonly T[], setup: EncodeSetup) => JsonObject, rejectedField: 'rejectedSpans' | 'rejectedDataPoints', format: 'json' | 'protobuf' = 'json') {
|
|
192
|
+
let config: typeof defaults; let endpoint: string; let setup: EncodeSetup; let headers: Readonly<Record<string, string>>; let transport: typeof globalThis.fetch;
|
|
149
193
|
try {
|
|
150
194
|
const allow = options.allowInsecureLoopback ?? false; if (typeof allow !== 'boolean') throw new Error();
|
|
151
195
|
config = Object.freeze(Object.fromEntries(Object.entries(defaults).map(([key, fallback]) => [key, options[key as keyof typeof defaults] ?? fallback]))) as typeof defaults;
|
|
152
196
|
for (const [key, value] of Object.entries(config)) assertPositiveInteger(value, key);
|
|
153
197
|
if (config.timeoutMs > 2_147_483_647 || config.maxBatchSize > 256 || config.maxRequestBytes > 16_777_216 || config.maxResponseBytes > 1_048_576) throw new Error();
|
|
154
|
-
|
|
155
|
-
|
|
198
|
+
const standardPath = options.standardPath ?? true; if (typeof standardPath !== 'boolean') throw new Error();
|
|
199
|
+
endpoint = destination(options.endpoint, signalName, allow, standardPath);
|
|
200
|
+
const hook = (options as OtlpHttpJsonTraceExporterOptions).spanAttributes;
|
|
201
|
+
if (hook !== undefined && (signalName !== 'traces' || typeof hook !== 'function')) throw new Error();
|
|
202
|
+
setup = Object.freeze({ serviceName: stable(options.serviceName), serviceVersion: options.serviceVersion === undefined ? undefined : stable(options.serviceVersion),
|
|
203
|
+
resource: Object.freeze(extraAttributes(options.resourceAttributes, new Set(), () => { throw new Error(); })), spanAttributes: hook });
|
|
204
|
+
headers = fixedHeaders(options.headers); if (format === 'protobuf') headers = Object.freeze({ ...headers, 'Content-Type': 'application/x-protobuf' }); transport = options.fetch ?? globalThis.fetch; if (typeof transport !== 'function') throw new Error();
|
|
156
205
|
} catch (error) { if (error instanceof MayuraError) throw error; throw new MayuraError('INVALID_CONFIG', 'OTLP exporter configuration must contain supported explicit bounds and transport.'); }
|
|
157
206
|
const counts = Object.fromEntries(metrics.map(key => [key, 0n])) as Record<Metric, bigint>; const count = (key: Metric, amount = 1): void => { counts[key] += BigInt(amount); };
|
|
158
207
|
let closed = false; let inFlight = false; let active: AbortController | undefined;
|
|
@@ -161,15 +210,20 @@ function createSignalExporter<T>(signalName: 'traces' | 'metrics', options: Otlp
|
|
|
161
210
|
const sink = async (records: readonly T[], context: { readonly signal: AbortSignal }): Promise<void> => {
|
|
162
211
|
if (closed || inFlight) throw new MayuraError('CONFLICT', closed ? 'The telemetry exporter is closed.' : 'The telemetry exporter already has an active request.');
|
|
163
212
|
if (!Array.isArray(records) || !records.length || records.length > config.maxBatchSize || !(context.signal instanceof AbortSignal)) { if (Array.isArray(records)) count('recordsDropped', records.length); throw new MayuraError('INVALID_INPUT', 'Telemetry batches require admitted records, a signal and supported bounds.'); }
|
|
164
|
-
count('batchesAttempted'); count('recordsAttempted', records.length); let body: string
|
|
165
|
-
try {
|
|
213
|
+
count('batchesAttempted'); count('recordsAttempted', records.length); let body: string | Uint8Array<ArrayBuffer>;
|
|
214
|
+
try {
|
|
215
|
+
// The OTLP/JSON request is built and checked first; protobuf is smaller, so its JSON may be up to four times the bound.
|
|
216
|
+
const request = jsonValue(encode(records, setup), { maxBytes: config.maxRequestBytes * (format === 'protobuf' ? 4 : 1), maxDepth: 16, maxNodes: 32_768 });
|
|
217
|
+
body = format === 'protobuf' ? otlpTraceProtobuf(object(request)) : JSON.stringify(request);
|
|
218
|
+
const bytes = typeof body === 'string' ? new TextEncoder().encode(body).byteLength : body.byteLength; if (bytes > config.maxRequestBytes) throw new Error(); count('requestBytes', bytes);
|
|
219
|
+
}
|
|
166
220
|
catch (error) { count('recordsDropped', records.length); if (error instanceof MayuraError && error.code === 'INVALID_INPUT') throw error; throw new MayuraError('INVALID_INPUT', 'Telemetry batches require admitted records within the configured request bound.'); }
|
|
167
221
|
const controller = new AbortController(); active = controller; inFlight = true; let timedOut = false; const timer = setTimeout(() => { timedOut = true; controller.abort(); }, config.timeoutMs);
|
|
168
222
|
const relay = (): void => controller.abort(); context.signal.addEventListener('abort', relay, { once: true }); if (context.signal.aborted) relay();
|
|
169
223
|
try {
|
|
170
224
|
if (controller.signal.aborted) throw controller.signal.reason;
|
|
171
225
|
const response = await abortable(Promise.resolve(transport(endpoint, { method: 'POST', headers, body, signal: controller.signal, redirect: 'error', credentials: 'omit', cache: 'no-store' })), controller.signal);
|
|
172
|
-
const payload = await responsePayload(response, config.maxResponseBytes, controller.signal, bytes => count('responseBytes', bytes)); const dropped = rejected(payload, rejectedField, records.length);
|
|
226
|
+
const payload = await responsePayload(response, config.maxResponseBytes, controller.signal, bytes => count('responseBytes', bytes), format === 'protobuf' ? rejectedField : undefined); const dropped = rejected(payload, rejectedField, records.length);
|
|
173
227
|
count('recordsAccepted', records.length - dropped); if (dropped) { count('recordsDropped', dropped); count('partialResponses'); }
|
|
174
228
|
} catch { count('recordsDropped', records.length); if (timedOut) { count('timedOutRequests'); throw new MayuraError('TIMEOUT', 'The telemetry export timed out.'); } if (context.signal.aborted || closed) { count('cancelledRequests'); throw new MayuraError('CANCELLED', 'The telemetry export was cancelled.'); } count('failedRequests'); return failed(); }
|
|
175
229
|
finally { clearTimeout(timer); context.signal.removeEventListener('abort', relay); active = undefined; inFlight = false; }
|
|
@@ -180,6 +234,13 @@ function createSignalExporter<T>(signalName: 'traces' | 'metrics', options: Otlp
|
|
|
180
234
|
export function createOtlpHttpJsonTraceExporter(options: OtlpHttpJsonTraceExporterOptions): OtlpHttpJsonTraceExporter {
|
|
181
235
|
return createSignalExporter<OtlpTraceSpan>('traces', options, traceRequest, 'rejectedSpans');
|
|
182
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* The same trace exporter, sending OTLP's protobuf encoding (`application/x-protobuf`) for collectors and providers
|
|
239
|
+
* that take only protobuf, such as Arize Phoenix. Spans are checked exactly as for JSON.
|
|
240
|
+
*/
|
|
241
|
+
export function createOtlpHttpProtobufTraceExporter(options: OtlpHttpProtobufTraceExporterOptions): OtlpHttpProtobufTraceExporter {
|
|
242
|
+
return createSignalExporter<OtlpTraceSpan>('traces', options, traceRequest, 'rejectedSpans', 'protobuf');
|
|
243
|
+
}
|
|
183
244
|
export function createOtlpHttpJsonMetricExporter(options: OtlpHttpJsonMetricExporterOptions): OtlpHttpJsonMetricExporter {
|
|
184
245
|
return createSignalExporter<OtlpMetricPoint>('metrics', options, metricRequest, 'rejectedDataPoints');
|
|
185
246
|
}
|