@theoremjs/agents 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1264 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +65 -0
- package/esm/mod.js +42 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +458 -0
- package/esm/src/cli/commands/egress-compile.d.ts +17 -0
- package/esm/src/cli/commands/egress-compile.js +25 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +202 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +25 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +72 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +4 -0
- package/esm/src/evals/attachments.js +53 -0
- package/esm/src/evals/breakdown.d.ts +28 -0
- package/esm/src/evals/breakdown.js +68 -0
- package/esm/src/evals/graders/answer.d.ts +13 -0
- package/esm/src/evals/graders/answer.js +133 -0
- package/esm/src/evals/graders/code.d.ts +64 -0
- package/esm/src/evals/graders/code.js +205 -0
- package/esm/src/evals/graders/judge.d.ts +20 -0
- package/esm/src/evals/graders/judge.js +365 -0
- package/esm/src/evals/graders/latency.d.ts +5 -0
- package/esm/src/evals/graders/latency.js +81 -0
- package/esm/src/evals/graders/live.d.ts +11 -0
- package/esm/src/evals/graders/live.js +40 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +92 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +17 -0
- package/esm/src/evals/graders/transcript.js +200 -0
- package/esm/src/evals/mod.d.ts +42 -0
- package/esm/src/evals/mod.js +30 -0
- package/esm/src/evals/record.d.ts +35 -0
- package/esm/src/evals/record.js +105 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +118 -0
- package/esm/src/evals/run.js +452 -0
- package/esm/src/evals/suite.d.ts +19 -0
- package/esm/src/evals/suite.js +92 -0
- package/esm/src/evals/summary.d.ts +32 -0
- package/esm/src/evals/summary.js +30 -0
- package/esm/src/evals/trial.d.ts +27 -0
- package/esm/src/evals/trial.js +158 -0
- package/esm/src/evals/types.d.ts +260 -0
- package/esm/src/evals/types.js +126 -0
- package/esm/src/evals/verdict.d.ts +18 -0
- package/esm/src/evals/verdict.js +45 -0
- package/esm/src/guardrails/canary-gate.d.ts +21 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +112 -0
- package/esm/src/guardrails/canary.js +901 -0
- package/esm/src/guardrails/compile-egress.d.ts +11 -0
- package/esm/src/guardrails/compile-egress.js +11 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +22 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +303 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +202 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +3 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +118 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +13 -0
- package/esm/src/guardrails/corpus/live-attacks.js +224 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +32 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/egress-automata.d.ts +14 -0
- package/esm/src/guardrails/egress-automata.js +6059 -0
- package/esm/src/guardrails/egress-compiler.d.ts +33 -0
- package/esm/src/guardrails/egress-compiler.js +237 -0
- package/esm/src/guardrails/egress-patterns.d.ts +24 -0
- package/esm/src/guardrails/egress-patterns.js +32 -0
- package/esm/src/guardrails/egress-policy.d.ts +27 -0
- package/esm/src/guardrails/egress-policy.js +76 -0
- package/esm/src/guardrails/egress-rules.d.ts +54 -0
- package/esm/src/guardrails/egress-rules.js +49 -0
- package/esm/src/guardrails/egress-stream.d.ts +105 -0
- package/esm/src/guardrails/egress-stream.js +645 -0
- package/esm/src/guardrails/egress-urls.d.ts +83 -0
- package/esm/src/guardrails/egress-urls.js +917 -0
- package/esm/src/guardrails/egress.d.ts +106 -0
- package/esm/src/guardrails/egress.js +374 -0
- package/esm/src/guardrails/error.d.ts +26 -0
- package/esm/src/guardrails/error.js +91 -0
- package/esm/src/guardrails/event-schemas.d.ts +57 -0
- package/esm/src/guardrails/event-schemas.js +41 -0
- package/esm/src/guardrails/events.d.ts +9 -0
- package/esm/src/guardrails/events.js +42 -0
- package/esm/src/guardrails/hits.d.ts +8 -0
- package/esm/src/guardrails/hits.js +19 -0
- package/esm/src/guardrails/injection-patterns.d.ts +15 -0
- package/esm/src/guardrails/injection-patterns.js +94 -0
- package/esm/src/guardrails/injection.d.ts +14 -0
- package/esm/src/guardrails/injection.js +237 -0
- package/esm/src/guardrails/lexicon.d.ts +30 -0
- package/esm/src/guardrails/lexicon.js +478 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +54 -0
- package/esm/src/guardrails/live-outbound-gate.js +305 -0
- package/esm/src/guardrails/mod.d.ts +46 -0
- package/esm/src/guardrails/mod.js +29 -0
- package/esm/src/guardrails/network.d.ts +42 -0
- package/esm/src/guardrails/network.js +328 -0
- package/esm/src/guardrails/normalize.d.ts +6 -0
- package/esm/src/guardrails/normalize.js +132 -0
- package/esm/src/guardrails/policy.d.ts +19 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +69 -0
- package/esm/src/guardrails/progressive-yield.js +237 -0
- package/esm/src/guardrails/prompt-echo.d.ts +38 -0
- package/esm/src/guardrails/prompt-echo.js +225 -0
- package/esm/src/guardrails/quota.d.ts +20 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +56 -0
- package/esm/src/guardrails/rules.js +54 -0
- package/esm/src/guardrails/sanitize.d.ts +23 -0
- package/esm/src/guardrails/sanitize.js +184 -0
- package/esm/src/guardrails/sensitive.d.ts +29 -0
- package/esm/src/guardrails/sensitive.js +113 -0
- package/esm/src/guardrails/serialize.d.ts +14 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +9 -0
- package/esm/src/guardrails/testing.js +8 -0
- package/esm/src/guardrails/theorem-error.d.ts +18 -0
- package/esm/src/guardrails/theorem-error.js +53 -0
- package/esm/src/guardrails/thought-guard.d.ts +55 -0
- package/esm/src/guardrails/thought-guard.js +464 -0
- package/esm/src/guardrails/tool-directives.d.ts +19 -0
- package/esm/src/guardrails/tool-directives.js +109 -0
- package/esm/src/guardrails/tool-result.d.ts +61 -0
- package/esm/src/guardrails/tool-result.js +248 -0
- package/esm/src/guardrails/types.d.ts +242 -0
- package/esm/src/guardrails/types.js +54 -0
- package/esm/src/host/client-turn.d.ts +9 -0
- package/esm/src/host/client-turn.js +38 -0
- package/esm/src/host/mint-trace.d.ts +28 -0
- package/esm/src/host/mint-trace.js +59 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +68 -0
- package/esm/src/host/reply.d.ts +7 -0
- package/esm/src/host/reply.js +35 -0
- package/esm/src/interface/blocks.d.ts +8 -0
- package/esm/src/interface/blocks.js +213 -0
- package/esm/src/interface/composer-actions.d.ts +20 -0
- package/esm/src/interface/composer-actions.js +31 -0
- package/esm/src/interface/draft.d.ts +14 -0
- package/esm/src/interface/draft.js +28 -0
- package/esm/src/interface/from-profile.d.ts +12 -0
- package/esm/src/interface/from-profile.js +144 -0
- package/esm/src/interface/history.d.ts +40 -0
- package/esm/src/interface/history.js +269 -0
- package/esm/src/interface/inputs.d.ts +10 -0
- package/esm/src/interface/inputs.js +64 -0
- package/esm/src/interface/mod.d.ts +31 -0
- package/esm/src/interface/mod.js +21 -0
- package/esm/src/interface/models.d.ts +19 -0
- package/esm/src/interface/models.js +45 -0
- package/esm/src/interface/pending.d.ts +48 -0
- package/esm/src/interface/pending.js +146 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +223 -0
- package/esm/src/interface/session.d.ts +64 -0
- package/esm/src/interface/session.js +121 -0
- package/esm/src/interface/tool-calls.d.ts +20 -0
- package/esm/src/interface/tool-calls.js +73 -0
- package/esm/src/interface/tool-invoke.d.ts +4 -0
- package/esm/src/interface/tool-invoke.js +20 -0
- package/esm/src/interface/tool-media.d.ts +9 -0
- package/esm/src/interface/tool-media.js +112 -0
- package/esm/src/interface/types.d.ts +213 -0
- package/esm/src/interface/types.js +4 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +51 -0
- package/esm/src/kernel/auth/crypto.js +161 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +17 -0
- package/esm/src/kernel/auth/oauth.js +438 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +139 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/default-scope.d.ts +34 -0
- package/esm/src/kernel/default-scope.js +72 -0
- package/esm/src/kernel/engine/compaction.d.ts +70 -0
- package/esm/src/kernel/engine/compaction.js +202 -0
- package/esm/src/kernel/engine/decision.d.ts +41 -0
- package/esm/src/kernel/engine/decision.js +412 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +19 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +9 -0
- package/esm/src/kernel/engine/live-ingress.js +37 -0
- package/esm/src/kernel/engine/media-probe/audio.d.ts +7 -0
- package/esm/src/kernel/engine/media-probe/audio.js +342 -0
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +6 -0
- package/esm/src/kernel/engine/media-probe/bytes.js +26 -0
- package/esm/src/kernel/engine/media-probe/image.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/image.js +171 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +19 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +48 -0
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +35 -0
- package/esm/src/kernel/engine/media-probe/matroska.js +226 -0
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +22 -0
- package/esm/src/kernel/engine/media-probe/mp4.js +279 -0
- package/esm/src/kernel/engine/media-probe/opus.d.ts +4 -0
- package/esm/src/kernel/engine/media-probe/opus.js +23 -0
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/pdf.js +117 -0
- package/esm/src/kernel/engine/media-probe/video.d.ts +15 -0
- package/esm/src/kernel/engine/media-probe/video.js +49 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +322 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +15 -0
- package/esm/src/kernel/engine/runner/mod.js +574 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +14 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +105 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +48 -0
- package/esm/src/kernel/engine/runner/state.d.ts +76 -0
- package/esm/src/kernel/engine/runner/state.js +40 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +360 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +40 -0
- package/esm/src/kernel/engine/runner/stream.js +225 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +150 -0
- package/esm/src/kernel/engine/session/mod.d.ts +31 -0
- package/esm/src/kernel/engine/session/mod.js +951 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +489 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +77 -0
- package/esm/src/kernel/engine/token-estimate.js +218 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +131 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +118 -0
- package/esm/src/kernel/engine/turn-trace.js +863 -0
- package/esm/src/kernel/engine/usage.d.ts +30 -0
- package/esm/src/kernel/engine/usage.js +134 -0
- package/esm/src/kernel/interaction-parts.d.ts +10 -0
- package/esm/src/kernel/interaction-parts.js +22 -0
- package/esm/src/kernel/mod.d.ts +47 -0
- package/esm/src/kernel/mod.js +30 -0
- package/esm/src/kernel/profile-graph.d.ts +140 -0
- package/esm/src/kernel/profile-graph.js +151 -0
- package/esm/src/kernel/profile-presence.d.ts +9 -0
- package/esm/src/kernel/profile-presence.js +143 -0
- package/esm/src/kernel/profile-scope.d.ts +36 -0
- package/esm/src/kernel/profile-scope.js +262 -0
- package/esm/src/kernel/registry/attachments.d.ts +35 -0
- package/esm/src/kernel/registry/attachments.js +211 -0
- package/esm/src/kernel/registry/catalog.d.ts +19 -0
- package/esm/src/kernel/registry/catalog.js +78 -0
- package/esm/src/kernel/registry/ingress.d.ts +8 -0
- package/esm/src/kernel/registry/ingress.js +134 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +12 -0
- package/esm/src/kernel/registry/kernel-registry.js +8 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +7 -0
- package/esm/src/kernel/registry/profiles.d.ts +92 -0
- package/esm/src/kernel/registry/profiles.js +698 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +42 -0
- package/esm/src/kernel/registry/resolve.d.ts +14 -0
- package/esm/src/kernel/registry/resolve.js +237 -0
- package/esm/src/kernel/registry/schemas.d.ts +9 -0
- package/esm/src/kernel/registry/schemas.js +25 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +33 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +13 -0
- package/esm/src/kernel/registry/vault.js +14 -0
- package/esm/src/kernel/schema.d.ts +172 -0
- package/esm/src/kernel/schema.js +653 -0
- package/esm/src/kernel/scope.d.ts +22 -0
- package/esm/src/kernel/scope.js +25 -0
- package/esm/src/kernel/stages.d.ts +141 -0
- package/esm/src/kernel/stages.js +388 -0
- package/esm/src/kernel/stop.d.ts +93 -0
- package/esm/src/kernel/stop.js +125 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +16 -0
- package/esm/src/kernel/tools/activity-label.js +209 -0
- package/esm/src/kernel/tools/events.d.ts +51 -0
- package/esm/src/kernel/tools/events.js +149 -0
- package/esm/src/kernel/tools/execute.d.ts +64 -0
- package/esm/src/kernel/tools/execute.js +801 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +50 -0
- package/esm/src/kernel/tools/gate-answer.js +54 -0
- package/esm/src/kernel/tools/harness.d.ts +16 -0
- package/esm/src/kernel/tools/harness.js +42 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +129 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +20 -0
- package/esm/src/kernel/tools/mcp-sessions.js +64 -0
- package/esm/src/kernel/tools/mod.d.ts +9 -0
- package/esm/src/kernel/tools/mod.js +6 -0
- package/esm/src/kernel/tools/model-text.d.ts +11 -0
- package/esm/src/kernel/tools/model-text.js +25 -0
- package/esm/src/kernel/tools/permission.d.ts +6 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +8 -0
- package/esm/src/kernel/tools/project.js +25 -0
- package/esm/src/kernel/tools/registry.d.ts +20 -0
- package/esm/src/kernel/tools/registry.js +84 -0
- package/esm/src/kernel/tools/remote.d.ts +110 -0
- package/esm/src/kernel/tools/remote.js +998 -0
- package/esm/src/kernel/tools/resolve.d.ts +28 -0
- package/esm/src/kernel/tools/resolve.js +259 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +174 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +18 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +93 -0
- package/esm/src/kernel/tools/stage-run.js +140 -0
- package/esm/src/kernel/tools/types.d.ts +287 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/turn-events.d.ts +599 -0
- package/esm/src/kernel/turn-events.js +425 -0
- package/esm/src/kernel/types.d.ts +884 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +13 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +3 -0
- package/esm/src/observability/destinations.d.ts +9 -0
- package/esm/src/observability/destinations.js +38 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +117 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +68 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +29 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +14 -0
- package/esm/src/observability/policy.js +69 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +58 -0
- package/esm/src/observability/spans.d.ts +16 -0
- package/esm/src/observability/spans.js +56 -0
- package/esm/src/observability/trace-catalog.d.ts +111 -0
- package/esm/src/observability/trace-catalog.js +865 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +223 -0
- package/esm/src/observability/trace-schema.d.ts +54 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +13 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +92 -0
- package/esm/src/observability/trace-span.js +199 -0
- package/esm/src/observability/trace.d.ts +11 -0
- package/esm/src/observability/trace.js +35 -0
- package/esm/src/observability/types.d.ts +85 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +8 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +12 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +104 -0
- package/esm/src/presets/google.js +188 -0
- package/esm/src/presets/mod.d.ts +10 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +13 -0
- package/esm/src/presets/openrouter.js +13 -0
- package/esm/src/presets/typesafe.d.ts +2 -0
- package/esm/src/presets/typesafe.js +2 -0
- package/esm/src/providers/create-provider.d.ts +21 -0
- package/esm/src/providers/create-provider.js +90 -0
- package/esm/src/providers/decision/usage.d.ts +3 -0
- package/esm/src/providers/decision/usage.js +25 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +263 -0
- package/esm/src/providers/google/interactions/mod.d.ts +2 -0
- package/esm/src/providers/google/interactions/mod.js +2 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +24 -0
- package/esm/src/providers/google/interactions/stream.js +297 -0
- package/esm/src/providers/google/keys.d.ts +20 -0
- package/esm/src/providers/google/keys.js +87 -0
- package/esm/src/providers/google/live/framing.d.ts +51 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/mod.d.ts +7 -0
- package/esm/src/providers/google/live/mod.js +7 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +1 -0
- package/esm/src/providers/google/live/openapi-schema.js +42 -0
- package/esm/src/providers/google/live/session.d.ts +14 -0
- package/esm/src/providers/google/live/session.js +150 -0
- package/esm/src/providers/google/live/stream.d.ts +51 -0
- package/esm/src/providers/google/live/stream.js +263 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/local/local.d.ts +12 -0
- package/esm/src/providers/local/local.js +186 -0
- package/esm/src/providers/local/mod.d.ts +8 -0
- package/esm/src/providers/local/mod.js +8 -0
- package/esm/src/providers/mod.d.ts +11 -0
- package/esm/src/providers/mod.js +7 -0
- package/esm/src/providers/openrouter/cache-control.d.ts +5 -0
- package/esm/src/providers/openrouter/cache-control.js +4 -0
- package/esm/src/providers/openrouter/chat.d.ts +64 -0
- package/esm/src/providers/openrouter/chat.js +490 -0
- package/esm/src/providers/openrouter/image.d.ts +24 -0
- package/esm/src/providers/openrouter/image.js +187 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +10 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +99 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +3 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +8 -0
- package/esm/src/providers/openrouter/speech.d.ts +18 -0
- package/esm/src/providers/openrouter/speech.js +109 -0
- package/esm/src/providers/probe.d.ts +5 -0
- package/esm/src/providers/probe.js +15 -0
- package/esm/src/providers/shared/builtin-wire.d.ts +4 -0
- package/esm/src/providers/shared/builtin-wire.js +9 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/sse.d.ts +10 -0
- package/esm/src/providers/shared/sse.js +79 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +25 -0
- package/esm/src/providers/shared/tool-args.js +84 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/shared/vault.d.ts +13 -0
- package/esm/src/providers/shared/vault.js +41 -0
- package/esm/src/providers/types.d.ts +19 -0
- package/esm/src/providers/types.js +1 -0
- package/esm/src/surface/formats.d.ts +28 -0
- package/esm/src/surface/formats.js +139 -0
- package/esm/src/surface/mod.d.ts +14 -0
- package/esm/src/surface/mod.js +10 -0
- package/esm/src/surface/runtime.d.ts +40 -0
- package/esm/src/surface/runtime.js +439 -0
- package/esm/src/surface/tools.d.ts +15 -0
- package/esm/src/surface/tools.js +80 -0
- package/esm/src/surface/types.d.ts +104 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +108 -4
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// OTLP has no record-level slot for `TraceRecord.metadata` (the resource is the service's
|
|
2
|
+
// identity), so each key lands on the record's top spans as `theorem.metadata.<key>`.
|
|
3
|
+
import { inlineContent } from './trace-record.js';
|
|
4
|
+
const SCOPE_NAME = '@theoremjs/agents';
|
|
5
|
+
const SPAN_KIND = { INTERNAL: 1, CLIENT: 3 };
|
|
6
|
+
const STATUS_CODE = { UNSET: 0, OK: 1, ERROR: 2 };
|
|
7
|
+
function anyValue(value) {
|
|
8
|
+
if (typeof value === 'string') {
|
|
9
|
+
return { stringValue: value };
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'boolean') {
|
|
12
|
+
return { boolValue: value };
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'number') {
|
|
15
|
+
// int64 is a decimal string in OTLP/JSON.
|
|
16
|
+
return Number.isInteger(value) ? { intValue: String(value) } : { doubleValue: value };
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
return { arrayValue: { values: value.flatMap((item) => anyValue(item) ?? []) } };
|
|
20
|
+
}
|
|
21
|
+
if (value && typeof value === 'object') {
|
|
22
|
+
return { kvlistValue: { values: keyValues(value) } };
|
|
23
|
+
}
|
|
24
|
+
// null / undefined: OTLP has no empty value, so the key is left out.
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function keyValues(fields) {
|
|
28
|
+
return Object.entries(fields).flatMap(([key, field]) => {
|
|
29
|
+
const value = anyValue(field);
|
|
30
|
+
return value ? [{ key, value }] : [];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function inlined(record, attributes) {
|
|
34
|
+
return keyValues(inlineContent(record, attributes));
|
|
35
|
+
}
|
|
36
|
+
const METADATA_PREFIX = 'theorem.metadata.';
|
|
37
|
+
function metadataAttributes(record) {
|
|
38
|
+
return keyValues(record.metadata ?? {}).map(({ key, value }) => ({
|
|
39
|
+
key: `${METADATA_PREFIX}${key}`,
|
|
40
|
+
value,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
/** Includes the root, which may hang under a host `traceparent` span that lives elsewhere. */
|
|
44
|
+
function topSpanIds(record) {
|
|
45
|
+
const ids = new Set(record.spans.map((span) => span.spanId));
|
|
46
|
+
return new Set(record.spans
|
|
47
|
+
.filter((span) => !(span.parentSpanId && ids.has(span.parentSpanId)))
|
|
48
|
+
.map((span) => span.spanId));
|
|
49
|
+
}
|
|
50
|
+
function otlpSpan(record, span, metadata) {
|
|
51
|
+
return {
|
|
52
|
+
traceId: span.traceId,
|
|
53
|
+
spanId: span.spanId,
|
|
54
|
+
...(span.parentSpanId ? { parentSpanId: span.parentSpanId } : {}),
|
|
55
|
+
name: span.name,
|
|
56
|
+
kind: SPAN_KIND[span.kind],
|
|
57
|
+
startTimeUnixNano: span.startTimeUnixNano,
|
|
58
|
+
endTimeUnixNano: span.endTimeUnixNano,
|
|
59
|
+
attributes: [...inlined(record, span.attributes), ...metadata],
|
|
60
|
+
events: span.events.map((event) => ({
|
|
61
|
+
timeUnixNano: event.timeUnixNano,
|
|
62
|
+
name: event.name,
|
|
63
|
+
attributes: inlined(record, event.attributes),
|
|
64
|
+
})),
|
|
65
|
+
links: span.links.map((link) => ({
|
|
66
|
+
traceId: link.traceId,
|
|
67
|
+
spanId: link.spanId,
|
|
68
|
+
attributes: inlined(record, link.attributes),
|
|
69
|
+
})),
|
|
70
|
+
status: {
|
|
71
|
+
code: STATUS_CODE[span.status.code],
|
|
72
|
+
...(span.status.message ? { message: span.status.message } : {}),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* One resource per record, one scope, with every stored reference inlined. For a backend that
|
|
78
|
+
* takes protobuf only, send this through an OpenTelemetry Collector.
|
|
79
|
+
*/
|
|
80
|
+
function toOtlpJson(records) {
|
|
81
|
+
return {
|
|
82
|
+
resourceSpans: records.map((record) => {
|
|
83
|
+
const top = topSpanIds(record);
|
|
84
|
+
const metadata = metadataAttributes(record);
|
|
85
|
+
return {
|
|
86
|
+
resource: { attributes: keyValues(record.resource) },
|
|
87
|
+
scopeSpans: [
|
|
88
|
+
{
|
|
89
|
+
scope: { name: SCOPE_NAME },
|
|
90
|
+
schemaUrl: record.schemaUrl,
|
|
91
|
+
spans: record.spans.map((span) => otlpSpan(record, span, top.has(span.spanId) ? metadata : [])),
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export { toOtlpJson };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eval results as Phoenix span annotations, which Phoenix reads over REST
|
|
3
|
+
* (`POST /v1/span_annotations`), not OTLP. Pure: it builds the body, the host posts it.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
import { type TraceRecord } from './trace-record.js';
|
|
9
|
+
interface PhoenixSpanAnnotation {
|
|
10
|
+
/** The judged root span, as OTLP hex. */
|
|
11
|
+
span_id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
/** `LLM` for a judge's result, `CODE` for a code grader's. */
|
|
14
|
+
annotator_kind: 'LLM' | 'CODE';
|
|
15
|
+
result: {
|
|
16
|
+
label?: string;
|
|
17
|
+
score?: number;
|
|
18
|
+
explanation?: string;
|
|
19
|
+
};
|
|
20
|
+
metadata: Record<string, string | number | boolean>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Each annotation lands on the root the trial judged. Send as
|
|
24
|
+
* `{ data: phoenixAnnotations(records) }`; Phoenix keeps one annotation per span and name, so
|
|
25
|
+
* grading a record again replaces them.
|
|
26
|
+
*/
|
|
27
|
+
declare function phoenixAnnotations(records: readonly TraceRecord[]): PhoenixSpanAnnotation[];
|
|
28
|
+
export type { PhoenixSpanAnnotation };
|
|
29
|
+
export { phoenixAnnotations };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eval results as Phoenix span annotations, which Phoenix reads over REST
|
|
3
|
+
* (`POST /v1/span_annotations`), not OTLP. Pure: it builds the body, the host posts it.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
import { inlineContent } from './trace-record.js';
|
|
9
|
+
const TRIAL_SPAN = 'theorem.eval.trial';
|
|
10
|
+
const RESULT_EVENT = 'gen_ai.evaluation.result';
|
|
11
|
+
function scalar(value) {
|
|
12
|
+
return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'
|
|
13
|
+
? value
|
|
14
|
+
: undefined;
|
|
15
|
+
}
|
|
16
|
+
function present(entries) {
|
|
17
|
+
const kept = {};
|
|
18
|
+
for (const [key, value] of Object.entries(entries))
|
|
19
|
+
if (value !== undefined)
|
|
20
|
+
kept[key] = value;
|
|
21
|
+
return kept;
|
|
22
|
+
}
|
|
23
|
+
/** `undefined` when the policy did not keep the explanation. */
|
|
24
|
+
function explanationOf(record, value) {
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return undefined;
|
|
27
|
+
const text = inlineContent(record, value);
|
|
28
|
+
return typeof text === 'string' ? text : undefined;
|
|
29
|
+
}
|
|
30
|
+
function annotation(record, span, attributes) {
|
|
31
|
+
const name = attributes['gen_ai.evaluation.name'];
|
|
32
|
+
if (typeof name !== 'string')
|
|
33
|
+
return undefined;
|
|
34
|
+
const label = attributes['gen_ai.evaluation.score.label'];
|
|
35
|
+
const score = attributes['gen_ai.evaluation.score.value'];
|
|
36
|
+
const explanation = explanationOf(record, attributes['gen_ai.evaluation.explanation']);
|
|
37
|
+
return {
|
|
38
|
+
span_id: span.parentSpanId,
|
|
39
|
+
name,
|
|
40
|
+
annotator_kind: attributes['theorem.evaluation.source'] === 'model' ? 'LLM' : 'CODE',
|
|
41
|
+
result: {
|
|
42
|
+
...(typeof label === 'string' ? { label } : {}),
|
|
43
|
+
...(typeof score === 'number' ? { score } : {}),
|
|
44
|
+
...(explanation === undefined ? {} : { explanation }),
|
|
45
|
+
},
|
|
46
|
+
metadata: present({
|
|
47
|
+
suite: scalar(span.attributes['theorem.evaluation.suite']),
|
|
48
|
+
case: scalar(span.attributes['theorem.evaluation.case']),
|
|
49
|
+
trial: scalar(span.attributes['theorem.evaluation.trial']),
|
|
50
|
+
passed: scalar(attributes['theorem.evaluation.passed']),
|
|
51
|
+
error_type: scalar(attributes['error.type']),
|
|
52
|
+
grader_version: scalar(attributes['theorem.evaluation.grader.version']),
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Each annotation lands on the root the trial judged. Send as
|
|
58
|
+
* `{ data: phoenixAnnotations(records) }`; Phoenix keeps one annotation per span and name, so
|
|
59
|
+
* grading a record again replaces them.
|
|
60
|
+
*/
|
|
61
|
+
function phoenixAnnotations(records) {
|
|
62
|
+
return records.flatMap((record) => record.spans.flatMap((span) => {
|
|
63
|
+
if (span.name !== TRIAL_SPAN || span.parentSpanId === undefined)
|
|
64
|
+
return [];
|
|
65
|
+
const trial = { ...span, parentSpanId: span.parentSpanId };
|
|
66
|
+
return span.events
|
|
67
|
+
.filter((event) => event.name === RESULT_EVENT)
|
|
68
|
+
.flatMap((event) => annotation(record, trial, event.attributes) ?? []);
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
export { phoenixAnnotations };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TraceSink } from './trace-sink.js';
|
|
2
|
+
import type { ProfileObservabilitySpec, ResolvedObservabilityPolicy } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Precedence: explicit `override` (runTurn's third arg), then profile `writeTo`, then noop. An
|
|
5
|
+
* override always records, ignoring `sampleRate`, so tests and one-off capture are deterministic.
|
|
6
|
+
*/
|
|
7
|
+
declare function resolveTraceWriter(args: {
|
|
8
|
+
override?: TraceSink;
|
|
9
|
+
observability?: ProfileObservabilitySpec;
|
|
10
|
+
}): {
|
|
11
|
+
sink: TraceSink;
|
|
12
|
+
policy: ResolvedObservabilityPolicy;
|
|
13
|
+
};
|
|
14
|
+
export { resolveTraceWriter };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { requireTraceDestination } from './destinations.js';
|
|
2
|
+
import { resolveObservabilityPolicy } from './resolve-policy.js';
|
|
3
|
+
import { noopSink } from './trace.js';
|
|
4
|
+
function bindOnWriteError(sink, onWriteError) {
|
|
5
|
+
if (!onWriteError && !sink.onError) {
|
|
6
|
+
return sink;
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
write: (record, context) => sink.write(record, context),
|
|
10
|
+
onError: sink.onError ?? onWriteError,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Trace-id bits the sampling decision reads: the low 32 (8 hex digits). */
|
|
14
|
+
const SAMPLE_HEX_DIGITS = 8;
|
|
15
|
+
const SAMPLE_SPACE = 2 ** 32;
|
|
16
|
+
/**
|
|
17
|
+
* Decided by trace id (OpenTelemetry `TraceIdRatioBased`), so every record of one trace (a turn,
|
|
18
|
+
* its specialists, a Live session's responses, a host's cutout) is kept or dropped together.
|
|
19
|
+
*/
|
|
20
|
+
function traceSampled(record, sampleRate) {
|
|
21
|
+
const traceId = record.spans[0]?.traceId ?? '';
|
|
22
|
+
return Number.parseInt(traceId.slice(-SAMPLE_HEX_DIGITS), 16) / SAMPLE_SPACE < sampleRate;
|
|
23
|
+
}
|
|
24
|
+
function withSampleRate(sink, sampleRate) {
|
|
25
|
+
if (sampleRate >= 1) {
|
|
26
|
+
return sink;
|
|
27
|
+
}
|
|
28
|
+
if (sampleRate <= 0) {
|
|
29
|
+
return noopSink();
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
write: async (record, context) => {
|
|
33
|
+
if (traceSampled(record, sampleRate)) {
|
|
34
|
+
await sink.write(record, context);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
onError: sink.onError,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function sinkFromWriteTo(writeTo, policy) {
|
|
41
|
+
if (writeTo === undefined || writeTo === false) {
|
|
42
|
+
return noopSink();
|
|
43
|
+
}
|
|
44
|
+
if (typeof writeTo !== 'string') {
|
|
45
|
+
return bindOnWriteError(writeTo, policy.onWriteError);
|
|
46
|
+
}
|
|
47
|
+
return bindOnWriteError(requireTraceDestination(writeTo), policy.onWriteError);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Precedence: explicit `override` (runTurn's third arg), then profile `writeTo`, then noop. An
|
|
51
|
+
* override always records, ignoring `sampleRate`, so tests and one-off capture are deterministic.
|
|
52
|
+
*/
|
|
53
|
+
function resolveTraceWriter(args) {
|
|
54
|
+
const policy = resolveObservabilityPolicy(args.observability);
|
|
55
|
+
if (args.override) {
|
|
56
|
+
return {
|
|
57
|
+
policy,
|
|
58
|
+
sink: bindOnWriteError(args.override, policy.onWriteError),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (!policy.record) {
|
|
62
|
+
return { policy, sink: noopSink() };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
policy,
|
|
66
|
+
sink: withSampleRate(sinkFromWriteTo(policy.writeTo, policy), policy.sampleRate),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export { resolveTraceWriter };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProfileObservabilitySpec, ResolvedObservabilityPolicy } from './types.js';
|
|
2
|
+
/** Default record retention in days; `<= 0` keeps records forever. */
|
|
3
|
+
declare const DEFAULT_RETAIN_DAYS = 14;
|
|
4
|
+
/** Default JSONL file size, in MiB, before the writer rotates to a new file. */
|
|
5
|
+
declare const DEFAULT_ROTATE_MIB = 32;
|
|
6
|
+
/** An omitted block or `writeTo: false` resolves `record: false`; `sampleRate` applies at write. */
|
|
7
|
+
declare function resolveObservabilityPolicy(spec: ProfileObservabilitySpec | undefined): ResolvedObservabilityPolicy;
|
|
8
|
+
export { DEFAULT_RETAIN_DAYS, DEFAULT_ROTATE_MIB, resolveObservabilityPolicy };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Pure, with no sinks or file system, so kernel type consumers never pull the JSONL sink into their
|
|
2
|
+
// graph.
|
|
3
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
4
|
+
/** Default record retention in days; `<= 0` keeps records forever. */
|
|
5
|
+
const DEFAULT_RETAIN_DAYS = 14;
|
|
6
|
+
/** Default JSONL file size, in MiB, before the writer rotates to a new file. */
|
|
7
|
+
const DEFAULT_ROTATE_MIB = 32;
|
|
8
|
+
function resolveInclude(spec) {
|
|
9
|
+
// No authored block records only through an explicit capture sink (tests,
|
|
10
|
+
// `runTurn(..., sink)`), which keeps wire and raw evidence. Authored blocks
|
|
11
|
+
// default those two off.
|
|
12
|
+
const authored = spec !== undefined;
|
|
13
|
+
return {
|
|
14
|
+
upstreamLog: spec?.include?.upstreamLog ?? true,
|
|
15
|
+
outboundWire: spec?.include?.outboundWire ?? !authored,
|
|
16
|
+
evidenceRaw: spec?.include?.evidenceRaw ?? !authored,
|
|
17
|
+
usage: spec?.include?.usage ?? true,
|
|
18
|
+
guardrailDecisions: spec?.include?.guardrailDecisions ?? true,
|
|
19
|
+
guardrailMatchPreview: spec?.include?.guardrailMatchPreview ?? false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function resolveScrub(spec) {
|
|
23
|
+
return {
|
|
24
|
+
sensitive: spec?.scrub?.sensitive ?? true,
|
|
25
|
+
injection: spec?.scrub?.injection ?? true,
|
|
26
|
+
canary: spec?.scrub?.canary ?? true,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function clampSampleRate(value) {
|
|
30
|
+
if (value === undefined) {
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
if (!Number.isFinite(value)) {
|
|
34
|
+
throw new TheoremError('config', 'observability.sampleRate must be a finite number');
|
|
35
|
+
}
|
|
36
|
+
if (value < 0 || value > 1) {
|
|
37
|
+
throw new TheoremError('config', 'observability.sampleRate must be between 0 and 1 inclusive');
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/** An omitted block or `writeTo: false` resolves `record: false`; `sampleRate` applies at write. */
|
|
42
|
+
function resolveObservabilityPolicy(spec) {
|
|
43
|
+
const writeTo = spec?.writeTo;
|
|
44
|
+
const sampleRate = clampSampleRate(spec?.sampleRate);
|
|
45
|
+
const record = spec !== undefined && writeTo !== false && writeTo !== undefined;
|
|
46
|
+
return {
|
|
47
|
+
record,
|
|
48
|
+
writeTo,
|
|
49
|
+
sampleRate,
|
|
50
|
+
include: resolveInclude(spec),
|
|
51
|
+
scrub: resolveScrub(spec),
|
|
52
|
+
resource: { ...(spec?.resource ?? {}) },
|
|
53
|
+
retainForDays: spec?.retainForDays ?? DEFAULT_RETAIN_DAYS,
|
|
54
|
+
rotateAfterMiB: spec?.rotateAfterMiB ?? DEFAULT_ROTATE_MIB,
|
|
55
|
+
onWriteError: spec?.onWriteError,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export { DEFAULT_RETAIN_DAYS, DEFAULT_ROTATE_MIB, resolveObservabilityPolicy };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const OMIT_INJECTION = "[omitted - injection]";
|
|
2
|
+
declare const OMIT_SENSITIVE = "[omitted -sensitive]";
|
|
3
|
+
type RedactKind = 'injection' | 'sensitive';
|
|
4
|
+
interface RedactSpan {
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
kind: RedactKind;
|
|
8
|
+
}
|
|
9
|
+
declare function blobAt(match: RegExpMatchArray): {
|
|
10
|
+
blob: string;
|
|
11
|
+
index: number;
|
|
12
|
+
} | undefined;
|
|
13
|
+
declare function applySpans(text: string, spans: RedactSpan[]): string;
|
|
14
|
+
declare function spansFromPatterns(text: string, patterns: RegExp[], kind: RedactKind): RedactSpan[];
|
|
15
|
+
export type { RedactKind, RedactSpan };
|
|
16
|
+
export { applySpans, blobAt, OMIT_INJECTION, OMIT_SENSITIVE, spansFromPatterns };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const OMIT_INJECTION = '[omitted - injection]';
|
|
2
|
+
const OMIT_SENSITIVE = '[omitted -sensitive]';
|
|
3
|
+
function tokenFor(kind) {
|
|
4
|
+
if (kind === 'injection') {
|
|
5
|
+
return OMIT_INJECTION;
|
|
6
|
+
}
|
|
7
|
+
return OMIT_SENSITIVE;
|
|
8
|
+
}
|
|
9
|
+
function blobAt(match) {
|
|
10
|
+
const [blob] = match;
|
|
11
|
+
const { index } = match;
|
|
12
|
+
if (blob && index !== undefined) {
|
|
13
|
+
return { blob, index };
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
function mergeSpans(spans) {
|
|
18
|
+
const sorted = [...spans].sort((left, right) => left.start - right.start || right.end - left.end);
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const span of sorted) {
|
|
21
|
+
if (span.end > span.start) {
|
|
22
|
+
const last = out.at(-1);
|
|
23
|
+
if (!last || span.start >= last.end) {
|
|
24
|
+
out.push(span);
|
|
25
|
+
}
|
|
26
|
+
else if (span.end > last.end) {
|
|
27
|
+
last.end = span.end;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
function applySpans(text, spans) {
|
|
34
|
+
let out = text;
|
|
35
|
+
const merged = mergeSpans(spans);
|
|
36
|
+
for (let i = merged.length - 1; i >= 0; i -= 1) {
|
|
37
|
+
const span = merged[i];
|
|
38
|
+
if (span) {
|
|
39
|
+
out = out.slice(0, span.start) + tokenFor(span.kind) + out.slice(span.end);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
function spansFromPatterns(text, patterns, kind) {
|
|
45
|
+
const spans = [];
|
|
46
|
+
for (const pattern of patterns) {
|
|
47
|
+
for (const match of text.matchAll(pattern)) {
|
|
48
|
+
const found = blobAt(match);
|
|
49
|
+
if (found) {
|
|
50
|
+
spans.push({ start: found.index, end: found.index + found.blob.length, kind });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return spans;
|
|
55
|
+
}
|
|
56
|
+
export { applySpans, blobAt, OMIT_INJECTION, OMIT_SENSITIVE, spansFromPatterns };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { TraceSpan } from './trace-span.js';
|
|
2
|
+
/** How a value reads: the unit or shape a viewer formats it by. */
|
|
3
|
+
type TraceValueFormat = 'text'
|
|
4
|
+
/** An identifier: shown as is, in monospace. */
|
|
5
|
+
| 'id' | 'number' | 'tokens' | 'seconds' | 'milliseconds' | 'usd' | 'boolean'
|
|
6
|
+
/** A list of strings. */
|
|
7
|
+
| 'list' | 'object'
|
|
8
|
+
/** A `{ content_sha256 }` reference to text in the record's `content`. */
|
|
9
|
+
| 'content'
|
|
10
|
+
/** A `{ json_sha256 }` reference to JSON in the record's `content`. */
|
|
11
|
+
| 'json'
|
|
12
|
+
/** Semconv chat messages whose parts reference `content`. */
|
|
13
|
+
| 'messages'
|
|
14
|
+
/** Semconv message parts whose text references `content`. */
|
|
15
|
+
| 'parts'
|
|
16
|
+
/** A unix-nanosecond timestamp string. */
|
|
17
|
+
| 'time';
|
|
18
|
+
type TraceAttributeGroup = 'agent' | 'request' | 'response' | 'messages' | 'usage' | 'tool' | 'http' | 'error' | 'record' | 'part' | 'decision' | 'evaluation';
|
|
19
|
+
interface TraceOptionMeta {
|
|
20
|
+
label: string;
|
|
21
|
+
doc: string;
|
|
22
|
+
}
|
|
23
|
+
interface TraceAttributeMeta {
|
|
24
|
+
label: string;
|
|
25
|
+
doc: string;
|
|
26
|
+
format: TraceValueFormat;
|
|
27
|
+
group: TraceAttributeGroup;
|
|
28
|
+
options?: Readonly<Record<string, TraceOptionMeta>>;
|
|
29
|
+
/** The options name the common values only: another value is real and shows as is. */
|
|
30
|
+
open?: true;
|
|
31
|
+
/** For an `object`: what its keys mean (for a list of objects, each item's keys). */
|
|
32
|
+
fields?: Readonly<Record<string, TraceAttributeMeta>>;
|
|
33
|
+
}
|
|
34
|
+
interface TraceEventMeta {
|
|
35
|
+
label: string;
|
|
36
|
+
doc: string;
|
|
37
|
+
/** Keys this event carries. A key missing here reads from the span attribute catalog. */
|
|
38
|
+
attributes: Readonly<Record<string, TraceAttributeMeta>>;
|
|
39
|
+
}
|
|
40
|
+
/** The kinds of span THEOREM writes, plus `host` for a span the host recorded itself. */
|
|
41
|
+
type TraceSpanType = 'turn' | 'session' | 'call' | 'response' | 'tool' | 'http' | 'cutout' | 'decision' | 'evaluation' | 'host';
|
|
42
|
+
/** `subject` is the thing the span acted on (the model, tool or agent), when it names one. */
|
|
43
|
+
interface TraceSpanMeta {
|
|
44
|
+
type: TraceSpanType;
|
|
45
|
+
label: string;
|
|
46
|
+
doc: string;
|
|
47
|
+
subject?: string;
|
|
48
|
+
}
|
|
49
|
+
declare const TRACE_ATTRIBUTE_GROUPS: Readonly<Record<TraceAttributeGroup, TraceOptionMeta>>;
|
|
50
|
+
declare const TRACE_STATUS: Readonly<Record<TraceSpan['status']['code'], TraceOptionMeta>>;
|
|
51
|
+
/** A record's and a span's own fields, beside their attributes. */
|
|
52
|
+
declare const TRACE_FIELDS: {
|
|
53
|
+
resource: {
|
|
54
|
+
label: string;
|
|
55
|
+
doc: string;
|
|
56
|
+
};
|
|
57
|
+
metadata: {
|
|
58
|
+
label: string;
|
|
59
|
+
doc: string;
|
|
60
|
+
};
|
|
61
|
+
span: {
|
|
62
|
+
label: string;
|
|
63
|
+
doc: string;
|
|
64
|
+
};
|
|
65
|
+
type: {
|
|
66
|
+
label: string;
|
|
67
|
+
doc: string;
|
|
68
|
+
};
|
|
69
|
+
children: {
|
|
70
|
+
label: string;
|
|
71
|
+
doc: string;
|
|
72
|
+
};
|
|
73
|
+
traceId: {
|
|
74
|
+
label: string;
|
|
75
|
+
doc: string;
|
|
76
|
+
};
|
|
77
|
+
spanId: {
|
|
78
|
+
label: string;
|
|
79
|
+
doc: string;
|
|
80
|
+
};
|
|
81
|
+
status: {
|
|
82
|
+
label: string;
|
|
83
|
+
doc: string;
|
|
84
|
+
};
|
|
85
|
+
start: {
|
|
86
|
+
label: string;
|
|
87
|
+
doc: string;
|
|
88
|
+
};
|
|
89
|
+
duration: {
|
|
90
|
+
label: string;
|
|
91
|
+
doc: string;
|
|
92
|
+
};
|
|
93
|
+
events: {
|
|
94
|
+
label: string;
|
|
95
|
+
doc: string;
|
|
96
|
+
};
|
|
97
|
+
links: {
|
|
98
|
+
label: string;
|
|
99
|
+
doc: string;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/** What an attribute key means; `undefined` for a key THEOREM does not write. */
|
|
103
|
+
declare function traceAttributeMeta(key: string): TraceAttributeMeta | undefined;
|
|
104
|
+
/** What an event records; `undefined` for an event THEOREM does not write. */
|
|
105
|
+
declare function traceEventMeta(name: string): TraceEventMeta | undefined;
|
|
106
|
+
/** The event's own entry, else the span attribute of that key. */
|
|
107
|
+
declare function traceEventAttributeMeta(event: string, key: string): TraceAttributeMeta | undefined;
|
|
108
|
+
declare const TRACE_SPAN_TYPES: Readonly<Record<TraceSpanType, TraceOptionMeta>>;
|
|
109
|
+
declare function traceSpanMeta(span: TraceSpan): TraceSpanMeta;
|
|
110
|
+
export type { TraceAttributeGroup, TraceAttributeMeta, TraceEventMeta, TraceOptionMeta, TraceSpanMeta, TraceSpanType, TraceValueFormat, };
|
|
111
|
+
export { TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, traceAttributeMeta, traceEventAttributeMeta, traceEventMeta, traceSpanMeta, };
|