@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function base64ToBytes(data) {
|
|
2
|
+
const bin = atob(data);
|
|
3
|
+
const out = new Uint8Array(bin.length);
|
|
4
|
+
for (let i = 0; i < bin.length; i++)
|
|
5
|
+
out[i] = bin.charCodeAt(i);
|
|
6
|
+
return out;
|
|
7
|
+
}
|
|
8
|
+
export function bytesToBase64(bytes) {
|
|
9
|
+
let bin = '';
|
|
10
|
+
for (let i = 0; i < bytes.length; i++)
|
|
11
|
+
bin += String.fromCharCode(bytes[i]);
|
|
12
|
+
return btoa(bin);
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type Probe<X> = <T>() => T extends X ? 1 : 2;
|
|
2
|
+
export type OptionalKeys<T> = {
|
|
3
|
+
[K in keyof T]-?: Record<never, never> extends Pick<T, K> ? K : never;
|
|
4
|
+
}[keyof T];
|
|
5
|
+
export type MarkedOnce<T> = T extends object ? {
|
|
6
|
+
[K in keyof T]-?: K extends OptionalKeys<T> ? {
|
|
7
|
+
optional: T[K];
|
|
8
|
+
} : T[K];
|
|
9
|
+
} : T;
|
|
10
|
+
/**
|
|
11
|
+
* Boxed in `Seen` so a union stays one entry. `T`'s own optional fields are marked first,
|
|
12
|
+
* or a type would pass for one it merely nests in.
|
|
13
|
+
*/
|
|
14
|
+
export type IsSeen<T, Seen> = true extends (Seen extends [infer S] ? Probe<MarkedOnce<S>> extends Probe<MarkedOnce<T>> ? true : false : never) ? true : false;
|
|
15
|
+
/**
|
|
16
|
+
* The identity check behind `Probe` ignores optionality, so a field only one side leaves out
|
|
17
|
+
* would pass unmarked. A recursive type is compared as it is where it recurs.
|
|
18
|
+
*/
|
|
19
|
+
export type Marked<T, Seen = never> = IsSeen<T, Seen> extends true ? T : MarkedEach<T, Seen | [T]>;
|
|
20
|
+
export type MarkedEach<T, Seen> = T extends (...args: never[]) => unknown ? T : T extends readonly unknown[] ? {
|
|
21
|
+
[I in keyof T]: Marked<T[I], Seen>;
|
|
22
|
+
} : T extends object ? {
|
|
23
|
+
[K in keyof T]-?: K extends OptionalKeys<T> ? {
|
|
24
|
+
optional: Marked<T[K], Seen>;
|
|
25
|
+
} : Marked<T[K], Seen>;
|
|
26
|
+
} : T;
|
|
27
|
+
/**
|
|
28
|
+
* JSR's `no-slow-types` forbids publishing inferred types, so a hand-written type is checked
|
|
29
|
+
* against its schema: `true satisfies Equals<z.infer<typeof turnStop>, TurnStop>;`.
|
|
30
|
+
*/
|
|
31
|
+
export type Equals<A, B> = Probe<Marked<A>> extends Probe<Marked<B>> ? true : false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** `Array.prototype.findLast` is ES2023; this stays ES2022-safe. */
|
|
2
|
+
export declare function findLast<T, S extends T>(items: readonly T[], predicate: (item: T) => item is S): S | undefined;
|
|
3
|
+
export declare function findLast<T>(items: readonly T[], predicate: (item: T) => boolean): T | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TraceSink } from './trace-sink.js';
|
|
2
|
+
declare function isTraceSink(value: unknown): value is TraceSink;
|
|
3
|
+
declare function registerTraceDestination(id: string, destination: TraceSink): void;
|
|
4
|
+
declare function getTraceDestination(id: string): TraceSink | undefined;
|
|
5
|
+
declare function requireTraceDestination(id: string): TraceSink;
|
|
6
|
+
declare function listTraceDestinationIds(): string[];
|
|
7
|
+
/** For tests. */
|
|
8
|
+
declare function clearTraceDestinations(): void;
|
|
9
|
+
export { clearTraceDestinations, getTraceDestination, isTraceSink, listTraceDestinationIds, registerTraceDestination, requireTraceDestination, };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// THEOREM does not invent filesystem roots: hosts register a named destination once per process.
|
|
2
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
3
|
+
const destinations = new Map();
|
|
4
|
+
function isTraceSink(value) {
|
|
5
|
+
return (typeof value === 'object' &&
|
|
6
|
+
value !== null &&
|
|
7
|
+
'write' in value &&
|
|
8
|
+
typeof value.write === 'function');
|
|
9
|
+
}
|
|
10
|
+
function registerTraceDestination(id, destination) {
|
|
11
|
+
const key = id.trim();
|
|
12
|
+
if (!key) {
|
|
13
|
+
throw new TheoremError('config', 'registerTraceDestination requires a non-empty id');
|
|
14
|
+
}
|
|
15
|
+
// Hosts may call from plain JS: the registry holds only writers.
|
|
16
|
+
if (!isTraceSink(destination)) {
|
|
17
|
+
throw new TheoremError('config', `Trace destination '${key}' must be a TraceSink`);
|
|
18
|
+
}
|
|
19
|
+
destinations.set(key, destination);
|
|
20
|
+
}
|
|
21
|
+
function getTraceDestination(id) {
|
|
22
|
+
return destinations.get(id);
|
|
23
|
+
}
|
|
24
|
+
function requireTraceDestination(id) {
|
|
25
|
+
const found = getTraceDestination(id);
|
|
26
|
+
if (!found) {
|
|
27
|
+
throw new TheoremError('config', `Trace destination '${id}' is not registered`);
|
|
28
|
+
}
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
function listTraceDestinationIds() {
|
|
32
|
+
return [...destinations.keys()].sort();
|
|
33
|
+
}
|
|
34
|
+
/** For tests. */
|
|
35
|
+
function clearTraceDestinations() {
|
|
36
|
+
destinations.clear();
|
|
37
|
+
}
|
|
38
|
+
export { clearTraceDestinations, getTraceDestination, isTraceSink, listTraceDestinationIds, registerTraceDestination, requireTraceDestination, };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The file trace sink: daily rotating JSONL under a host-chosen directory. Its own entry point, so
|
|
3
|
+
* browser bundles and Workers never pull the filesystem into their module graph.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
import type { TraceSink } from './trace-sink.js';
|
|
9
|
+
/** Retention and rotation are not here: they arrive with each write (`TraceWriteContext`) from the profile. */
|
|
10
|
+
export interface JsonlSinkOptions {
|
|
11
|
+
now?: () => number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Daily rotating JSONL files under an absolute, host-chosen `dir`. Each write removes day files
|
|
15
|
+
* older than the record's retention (`<= 0` keeps every file) and starts a new file once the
|
|
16
|
+
* day's reaches the profile's `rotateAfterMiB`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function jsonlSink(dir: string, options?: JsonlSinkOptions): TraceSink;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The file trace sink: daily rotating JSONL under a host-chosen directory. Its own entry point, so
|
|
3
|
+
* browser bundles and Workers never pull the filesystem into their module graph.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
import { appendFile, mkdir, readdir, rm, stat } from 'node:fs/promises';
|
|
9
|
+
import { cwd } from 'node:process';
|
|
10
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
11
|
+
import { isRecord } from '../kernel/util/record.js';
|
|
12
|
+
const HOURS_PER_DAY = 24;
|
|
13
|
+
const MIN_PER_HOUR = 60;
|
|
14
|
+
const SEC_PER_MIN = 60;
|
|
15
|
+
const MS_PER_SEC = 1000;
|
|
16
|
+
const KIB = 1024;
|
|
17
|
+
const OWNER_ONLY_DIR = 0o700;
|
|
18
|
+
const OWNER_ONLY_FILE = 0o600;
|
|
19
|
+
const MIB = KIB * KIB;
|
|
20
|
+
const FILE_DAY = /^turns-(\d{4}-\d{2}-\d{2})(?:-\d+)?\.jsonl$/;
|
|
21
|
+
function dayStamp(ms) {
|
|
22
|
+
return new Date(ms).toISOString().slice(0, 10);
|
|
23
|
+
}
|
|
24
|
+
function fileDay(name) {
|
|
25
|
+
return FILE_DAY.exec(name)?.[1];
|
|
26
|
+
}
|
|
27
|
+
/** Remove day files older than `retainForDays`; `<= 0` keeps every file. */
|
|
28
|
+
async function pruneTraces(dir, now, retainForDays) {
|
|
29
|
+
if (retainForDays <= 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const retainMs = retainForDays * HOURS_PER_DAY * MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SEC;
|
|
33
|
+
const cutoff = now - retainMs;
|
|
34
|
+
for (const name of await readdir(dir)) {
|
|
35
|
+
const day = fileDay(name);
|
|
36
|
+
if (day && Date.parse(`${day}T00:00:00.000Z`) < cutoff) {
|
|
37
|
+
await rm(`${dir}/${name}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isMissing(err) {
|
|
42
|
+
return isRecord(err) && err.code === 'ENOENT';
|
|
43
|
+
}
|
|
44
|
+
async function pickFile(dir, now, rotateBytes) {
|
|
45
|
+
const day = dayStamp(now);
|
|
46
|
+
const base = `${dir}/turns-${day}.jsonl`;
|
|
47
|
+
try {
|
|
48
|
+
if ((await stat(base)).size < rotateBytes) {
|
|
49
|
+
return base;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (isMissing(err)) {
|
|
54
|
+
return base;
|
|
55
|
+
}
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
return `${dir}/turns-${day}-${now}.jsonl`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Daily rotating JSONL files under an absolute, host-chosen `dir`. Each write removes day files
|
|
62
|
+
* older than the record's retention (`<= 0` keeps every file) and starts a new file once the
|
|
63
|
+
* day's reaches the profile's `rotateAfterMiB`.
|
|
64
|
+
*/
|
|
65
|
+
export function jsonlSink(dir, options = {}) {
|
|
66
|
+
const safeDir = validateTraceDir(dir);
|
|
67
|
+
const now = options.now ?? Date.now;
|
|
68
|
+
return {
|
|
69
|
+
write: async (record, context) => {
|
|
70
|
+
const at = now();
|
|
71
|
+
// Records hold conversation content: readable by the host's user only.
|
|
72
|
+
await mkdir(safeDir, { recursive: true, mode: OWNER_ONLY_DIR });
|
|
73
|
+
await pruneTraces(safeDir, at, context.retainForDays);
|
|
74
|
+
const path = await pickFile(safeDir, at, context.rotateAfterMiB * MIB);
|
|
75
|
+
await appendFile(path, `${JSON.stringify(record)}\n`, { mode: OWNER_ONLY_FILE });
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function insideDir(path, root) {
|
|
80
|
+
let base = root;
|
|
81
|
+
if (root.endsWith('/')) {
|
|
82
|
+
base = root.slice(0, -1);
|
|
83
|
+
}
|
|
84
|
+
if (path === base) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return path.startsWith(`${base}/`);
|
|
88
|
+
}
|
|
89
|
+
function normalizeAbsolutePath(path) {
|
|
90
|
+
const trimmed = path.trim();
|
|
91
|
+
if (!trimmed) {
|
|
92
|
+
throw new TheoremError('config', 'trace directory must be non-empty');
|
|
93
|
+
}
|
|
94
|
+
if (!trimmed.startsWith('/')) {
|
|
95
|
+
throw new TheoremError('config', 'trace directory must be absolute');
|
|
96
|
+
}
|
|
97
|
+
const parts = [];
|
|
98
|
+
for (const part of trimmed.split('/')) {
|
|
99
|
+
if (!part || part === '.') {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (part === '..') {
|
|
103
|
+
parts.pop();
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
parts.push(part);
|
|
107
|
+
}
|
|
108
|
+
return `/${parts.join('/')}`;
|
|
109
|
+
}
|
|
110
|
+
/** An absolute directory outside the working directory, normalized; throws `config` otherwise. */
|
|
111
|
+
function validateTraceDir(dir) {
|
|
112
|
+
const normalized = normalizeAbsolutePath(dir);
|
|
113
|
+
if (insideDir(normalized, normalizeAbsolutePath(cwd()))) {
|
|
114
|
+
throw new TheoremError('config', 'trace directory must be outside the project checkout');
|
|
115
|
+
}
|
|
116
|
+
return normalized;
|
|
117
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trace sinks, the destination registry, observability policy, the span builder and the trace
|
|
3
|
+
* catalog. THEOREM owns no database: hosts register destinations or pass a sink into `runTurn`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export { clearTraceDestinations, getTraceDestination, isTraceSink, listTraceDestinationIds, registerTraceDestination, requireTraceDestination, } from './destinations.js';
|
|
9
|
+
export type { OtlpAnyValue, OtlpKeyValue, OtlpSpan, OtlpTraceRequest } from './otlp.js';
|
|
10
|
+
export { toOtlpJson } from './otlp.js';
|
|
11
|
+
export { resolveTraceWriter } from './policy.js';
|
|
12
|
+
export { resolveObservabilityPolicy } from './resolve-policy.js';
|
|
13
|
+
export { memorySink, noopSink, writeTrace, } from './trace.js';
|
|
14
|
+
export type { TraceAttributeGroup, TraceAttributeMeta, TraceEventMeta, TraceOptionMeta, TraceSpanMeta, TraceSpanType, TraceValueFormat, } from './trace-catalog.js';
|
|
15
|
+
export { TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, traceAttributeMeta, traceEventAttributeMeta, traceEventMeta, traceSpanMeta, } from './trace-catalog.js';
|
|
16
|
+
export type { TraceRecord } from './trace-record.js';
|
|
17
|
+
export { buildRecord, contentOf, inlineContent } from './trace-record.js';
|
|
18
|
+
export { traceRecordSchema } from './trace-schema.js';
|
|
19
|
+
export type { TraceSink, TraceWriteContext } from './trace-sink.js';
|
|
20
|
+
export type { SpanHandle, SpanLinkInput, SpanOptions, TraceAttributes, TraceAttributeValue, TraceBytes, TraceClock, TraceContent, TraceJson, TraceSpan, TraceSpanEvent, TraceSpanKind, TraceSpanLink, TraceSpanStatus, TraceTree, } from './trace-span.js';
|
|
21
|
+
export { readTraceparent, startTrace, traceBytes, traceContent, traceJson, } from './trace-span.js';
|
|
22
|
+
export type { ProfileObservabilitySpec, ResolvedObservabilityPolicy, ResolvedTraceInclude, ResolvedTraceScrub, TraceIncludeSpec, TraceScrubSpec, } from './types.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trace sinks, the destination registry, observability policy, the span builder and the trace
|
|
3
|
+
* catalog. THEOREM owns no database: hosts register destinations or pass a sink into `runTurn`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export { clearTraceDestinations, getTraceDestination, isTraceSink, listTraceDestinationIds, registerTraceDestination, requireTraceDestination, } from './destinations.js';
|
|
9
|
+
export { toOtlpJson } from './otlp.js';
|
|
10
|
+
export { resolveTraceWriter } from './policy.js';
|
|
11
|
+
export { resolveObservabilityPolicy } from './resolve-policy.js';
|
|
12
|
+
export { memorySink, noopSink, writeTrace, } from './trace.js';
|
|
13
|
+
export { TRACE_ATTRIBUTE_GROUPS, TRACE_FIELDS, TRACE_SPAN_TYPES, TRACE_STATUS, traceAttributeMeta, traceEventAttributeMeta, traceEventMeta, traceSpanMeta, } from './trace-catalog.js';
|
|
14
|
+
export { buildRecord, contentOf, inlineContent } from './trace-record.js';
|
|
15
|
+
export { traceRecordSchema } from './trace-schema.js';
|
|
16
|
+
export { readTraceparent, startTrace, traceBytes, traceContent, traceJson, } from './trace-span.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenInference attributes for Phoenix, whose message views, reasoning tokens and cost read only
|
|
3
|
+
* OpenInference names; they are copied beside the semconv names so `toOtlpJson` stays neutral.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
import { type TraceRecord } from './trace-record.js';
|
|
9
|
+
/** Pure: input records are not changed. Export with `toOtlpJson(withOpenInference(records))`. */
|
|
10
|
+
declare function withOpenInference(records: readonly TraceRecord[]): TraceRecord[];
|
|
11
|
+
export { withOpenInference };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenInference attributes for Phoenix, whose message views, reasoning tokens and cost read only
|
|
3
|
+
* OpenInference names; they are copied beside the semconv names so `toOtlpJson` stays neutral.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
import { isRecord } from '../kernel/util/record.js';
|
|
9
|
+
import { inlineContent } from './trace-record.js';
|
|
10
|
+
const MODEL_CALLS = new Set(['chat', 'generate_content']);
|
|
11
|
+
const AGENT_CALLS = new Set(['invoke_agent']);
|
|
12
|
+
/** A decision (`theorem.decision.*`): one model call over JSON state, with no messages. */
|
|
13
|
+
const DECISION = 'decide';
|
|
14
|
+
/** Eval spans carry no semconv operation: a trial grades one turn, a run chains the trials. */
|
|
15
|
+
const EVAL_KINDS = {
|
|
16
|
+
'theorem.eval.trial': 'EVALUATOR',
|
|
17
|
+
'theorem.eval.run': 'CHAIN',
|
|
18
|
+
};
|
|
19
|
+
/** Model calls only: a viewer sums usage across a trace, and an agent span's is already a sum. */
|
|
20
|
+
function openInferenceUsage(attributes) {
|
|
21
|
+
const reasoning = attributes['gen_ai.usage.reasoning.output_tokens'];
|
|
22
|
+
const cost = attributes['theorem.usage.cost_usd'];
|
|
23
|
+
return {
|
|
24
|
+
...(typeof reasoning === 'number'
|
|
25
|
+
? { 'llm.token_count.completion_details.reasoning': reasoning }
|
|
26
|
+
: {}),
|
|
27
|
+
// A partial cost would read as the call's total; it keeps only its theorem.* name.
|
|
28
|
+
...(typeof cost === 'number' && attributes['theorem.usage.cost_partial'] !== true
|
|
29
|
+
? { 'llm.cost.total': cost }
|
|
30
|
+
: {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function messagesOf(record, value) {
|
|
34
|
+
const inlined = inlineContent(record, value);
|
|
35
|
+
if (!Array.isArray(inlined))
|
|
36
|
+
return [];
|
|
37
|
+
return inlined.flatMap((message) => {
|
|
38
|
+
if (!isRecord(message) || typeof message.role !== 'string')
|
|
39
|
+
return [];
|
|
40
|
+
const parts = Array.isArray(message.parts) ? message.parts.filter(isRecord) : [];
|
|
41
|
+
return [{ role: message.role, parts: parts }];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function partText(part) {
|
|
45
|
+
if (part.type === 'text' && typeof part.content === 'string')
|
|
46
|
+
return part.content;
|
|
47
|
+
if (part.type === 'structured' && part.content !== undefined)
|
|
48
|
+
return JSON.stringify(part.content);
|
|
49
|
+
if (part.type === 'tool_call' || part.type === 'tool_call_response')
|
|
50
|
+
return undefined;
|
|
51
|
+
if (typeof part.modality === 'string')
|
|
52
|
+
return `[${part.modality}]`;
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
/** A text part that repeats the structured part's JSON is shown once, as the JSON. */
|
|
56
|
+
function repeatsStructured(part, structured) {
|
|
57
|
+
if (structured === undefined || part.type !== 'text' || typeof part.content !== 'string') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
return JSON.stringify(JSON.parse(part.content)) === JSON.stringify(structured.content);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function messageText(message) {
|
|
68
|
+
const structured = message.parts.find((part) => part.type === 'structured');
|
|
69
|
+
return message.parts
|
|
70
|
+
.filter((part) => !repeatsStructured(part, structured))
|
|
71
|
+
.flatMap((part) => partText(part) ?? [])
|
|
72
|
+
.join('\n');
|
|
73
|
+
}
|
|
74
|
+
function messageAttributes(prefix, message) {
|
|
75
|
+
const out = { [`${prefix}.message.role`]: message.role };
|
|
76
|
+
const text = messageText(message);
|
|
77
|
+
if (text !== '')
|
|
78
|
+
out[`${prefix}.message.content`] = text;
|
|
79
|
+
let calls = 0;
|
|
80
|
+
for (const part of message.parts) {
|
|
81
|
+
if (part.type === 'tool_call') {
|
|
82
|
+
const call = `${prefix}.message.tool_calls.${calls}.tool_call`;
|
|
83
|
+
calls += 1;
|
|
84
|
+
if (typeof part.id === 'string')
|
|
85
|
+
out[`${call}.id`] = part.id;
|
|
86
|
+
if (typeof part.name === 'string')
|
|
87
|
+
out[`${call}.function.name`] = part.name;
|
|
88
|
+
if (typeof part.arguments === 'string')
|
|
89
|
+
out[`${call}.function.arguments`] = part.arguments;
|
|
90
|
+
}
|
|
91
|
+
else if (part.type === 'tool_call_response') {
|
|
92
|
+
if (typeof part.id === 'string')
|
|
93
|
+
out[`${prefix}.message.tool_call_id`] = part.id;
|
|
94
|
+
if (typeof part.response === 'string')
|
|
95
|
+
out[`${prefix}.message.content`] = part.response;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
function messagesAttributes(key, messages) {
|
|
101
|
+
return Object.assign({}, ...messages.map((message, index) => messageAttributes(`${key}.${index}`, message)));
|
|
102
|
+
}
|
|
103
|
+
/** `input.value` / `output.value`: the text a person would read, else the messages as JSON. */
|
|
104
|
+
function valueAttributes(side, messages) {
|
|
105
|
+
if (messages.length === 0)
|
|
106
|
+
return {};
|
|
107
|
+
const texts = messages.map(messageText).filter((text) => text !== '');
|
|
108
|
+
if (texts.length === messages.length && texts.length === 1 && texts[0] !== undefined) {
|
|
109
|
+
return { [`${side}.value`]: texts[0], [`${side}.mime_type`]: 'text/plain' };
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
[`${side}.value`]: JSON.stringify(messages.map((message) => ({ role: message.role, content: messageText(message) }))),
|
|
113
|
+
[`${side}.mime_type`]: 'application/json',
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function openInferenceModelMessages(record, span) {
|
|
117
|
+
const system = messagesOf(record, span.attributes['gen_ai.system_instructions'] === undefined
|
|
118
|
+
? undefined
|
|
119
|
+
: [{ role: 'system', parts: span.attributes['gen_ai.system_instructions'] }]);
|
|
120
|
+
const input = [...system, ...messagesOf(record, span.attributes['gen_ai.input.messages'])];
|
|
121
|
+
const output = messagesOf(record, span.attributes['gen_ai.output.messages'] ?? span.attributes['theorem.output.delivered']);
|
|
122
|
+
return {
|
|
123
|
+
...messagesAttributes('llm.input_messages', input),
|
|
124
|
+
...messagesAttributes('llm.output_messages', output),
|
|
125
|
+
...valueAttributes('input', input.filter((message) => message.role !== 'system')),
|
|
126
|
+
...valueAttributes('output', output),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function openInferenceAgentValues(record, span) {
|
|
130
|
+
return {
|
|
131
|
+
...valueAttributes('input', messagesOf(record, span.attributes['gen_ai.input.messages'])),
|
|
132
|
+
...valueAttributes('output', messagesOf(record, span.attributes['gen_ai.output.messages'])),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function jsonValue(record, side, value) {
|
|
136
|
+
if (value === undefined)
|
|
137
|
+
return {};
|
|
138
|
+
return {
|
|
139
|
+
[`${side}.value`]: JSON.stringify(inlineContent(record, value)),
|
|
140
|
+
[`${side}.mime_type`]: 'application/json',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Phoenix derives no kind for an operation semconv does not name, and has no price for Jev, so
|
|
145
|
+
* the kind, model, tokens and cost are stated. It has no messages, so Phoenix cannot replay it.
|
|
146
|
+
*/
|
|
147
|
+
function openInferenceDecision(record, span) {
|
|
148
|
+
const { attributes } = span;
|
|
149
|
+
const input = attributes['gen_ai.usage.input_tokens'];
|
|
150
|
+
const output = attributes['gen_ai.usage.output_tokens'];
|
|
151
|
+
const model = attributes['gen_ai.response.model'] ?? attributes['gen_ai.request.model'];
|
|
152
|
+
return {
|
|
153
|
+
'openinference.span.kind': 'LLM',
|
|
154
|
+
...(typeof model === 'string' ? { 'llm.model_name': model } : {}),
|
|
155
|
+
...(typeof attributes['gen_ai.provider.name'] === 'string'
|
|
156
|
+
? { 'llm.provider': attributes['gen_ai.provider.name'] }
|
|
157
|
+
: {}),
|
|
158
|
+
...(typeof input === 'number' ? { 'llm.token_count.prompt': input } : {}),
|
|
159
|
+
...(typeof output === 'number' ? { 'llm.token_count.completion': output } : {}),
|
|
160
|
+
...(typeof input === 'number' && typeof output === 'number'
|
|
161
|
+
? { 'llm.token_count.total': input + output }
|
|
162
|
+
: {}),
|
|
163
|
+
...openInferenceUsage(attributes),
|
|
164
|
+
...jsonValue(record, 'input', attributes['theorem.decision.state']),
|
|
165
|
+
...jsonValue(record, 'output', attributes['theorem.decision.answers']),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function withSpanAttributes(record, span) {
|
|
169
|
+
const operation = span.attributes['gen_ai.operation.name'];
|
|
170
|
+
if (MODEL_CALLS.has(operation)) {
|
|
171
|
+
return {
|
|
172
|
+
...span,
|
|
173
|
+
attributes: {
|
|
174
|
+
...span.attributes,
|
|
175
|
+
...openInferenceUsage(span.attributes),
|
|
176
|
+
...openInferenceModelMessages(record, span),
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (AGENT_CALLS.has(operation)) {
|
|
181
|
+
return {
|
|
182
|
+
...span,
|
|
183
|
+
attributes: { ...span.attributes, ...openInferenceAgentValues(record, span) },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if (operation === DECISION) {
|
|
187
|
+
return {
|
|
188
|
+
...span,
|
|
189
|
+
attributes: { ...span.attributes, ...openInferenceDecision(record, span) },
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const evalKind = EVAL_KINDS[span.name];
|
|
193
|
+
if (evalKind !== undefined) {
|
|
194
|
+
return { ...span, attributes: { ...span.attributes, 'openinference.span.kind': evalKind } };
|
|
195
|
+
}
|
|
196
|
+
return span;
|
|
197
|
+
}
|
|
198
|
+
/** Pure: input records are not changed. Export with `toOtlpJson(withOpenInference(records))`. */
|
|
199
|
+
function withOpenInference(records) {
|
|
200
|
+
return records.map((record) => ({
|
|
201
|
+
...record,
|
|
202
|
+
spans: record.spans.map((span) => withSpanAttributes(record, span)),
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
export { withOpenInference };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type TraceRecord } from './trace-record.js';
|
|
2
|
+
type OtlpAnyValue = {
|
|
3
|
+
stringValue: string;
|
|
4
|
+
} | {
|
|
5
|
+
boolValue: boolean;
|
|
6
|
+
} | {
|
|
7
|
+
intValue: string;
|
|
8
|
+
} | {
|
|
9
|
+
doubleValue: number;
|
|
10
|
+
} | {
|
|
11
|
+
arrayValue: {
|
|
12
|
+
values: OtlpAnyValue[];
|
|
13
|
+
};
|
|
14
|
+
} | {
|
|
15
|
+
kvlistValue: {
|
|
16
|
+
values: OtlpKeyValue[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
interface OtlpKeyValue {
|
|
20
|
+
key: string;
|
|
21
|
+
value: OtlpAnyValue;
|
|
22
|
+
}
|
|
23
|
+
interface OtlpSpan {
|
|
24
|
+
traceId: string;
|
|
25
|
+
spanId: string;
|
|
26
|
+
parentSpanId?: string;
|
|
27
|
+
name: string;
|
|
28
|
+
kind: number;
|
|
29
|
+
startTimeUnixNano: string;
|
|
30
|
+
endTimeUnixNano: string;
|
|
31
|
+
attributes: OtlpKeyValue[];
|
|
32
|
+
events: {
|
|
33
|
+
timeUnixNano: string;
|
|
34
|
+
name: string;
|
|
35
|
+
attributes: OtlpKeyValue[];
|
|
36
|
+
}[];
|
|
37
|
+
links: {
|
|
38
|
+
traceId: string;
|
|
39
|
+
spanId: string;
|
|
40
|
+
attributes: OtlpKeyValue[];
|
|
41
|
+
}[];
|
|
42
|
+
status: {
|
|
43
|
+
code: number;
|
|
44
|
+
message?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** An OTLP/JSON `ExportTraceServiceRequest` (the body of `POST /v1/traces`). */
|
|
48
|
+
interface OtlpTraceRequest {
|
|
49
|
+
resourceSpans: {
|
|
50
|
+
resource: {
|
|
51
|
+
attributes: OtlpKeyValue[];
|
|
52
|
+
};
|
|
53
|
+
scopeSpans: {
|
|
54
|
+
scope: {
|
|
55
|
+
name: string;
|
|
56
|
+
};
|
|
57
|
+
schemaUrl: string;
|
|
58
|
+
spans: OtlpSpan[];
|
|
59
|
+
}[];
|
|
60
|
+
}[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* One resource per record, one scope, with every stored reference inlined. For a backend that
|
|
64
|
+
* takes protobuf only, send this through an OpenTelemetry Collector.
|
|
65
|
+
*/
|
|
66
|
+
declare function toOtlpJson(records: readonly TraceRecord[]): OtlpTraceRequest;
|
|
67
|
+
export type { OtlpAnyValue, OtlpKeyValue, OtlpSpan, OtlpTraceRequest };
|
|
68
|
+
export { toOtlpJson };
|