@theoremjs/agents 0.0.0-stage → 0.3.1
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 +545 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +79 -0
- package/esm/mod.js +49 -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 +480 -0
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -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 +241 -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 +26 -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 +67 -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 +5 -0
- package/esm/src/evals/attachments.js +55 -0
- package/esm/src/evals/breakdown.d.ts +30 -0
- package/esm/src/evals/breakdown.js +69 -0
- package/esm/src/evals/graders/answer.d.ts +16 -0
- package/esm/src/evals/graders/answer.js +134 -0
- package/esm/src/evals/graders/code.d.ts +40 -0
- package/esm/src/evals/graders/code.js +184 -0
- package/esm/src/evals/graders/judge.d.ts +24 -0
- package/esm/src/evals/graders/judge.js +367 -0
- package/esm/src/evals/graders/latency.d.ts +6 -0
- package/esm/src/evals/graders/latency.js +82 -0
- package/esm/src/evals/graders/live.d.ts +14 -0
- package/esm/src/evals/graders/live.js +42 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +91 -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 +19 -0
- package/esm/src/evals/graders/transcript.js +202 -0
- package/esm/src/evals/mod.d.ts +34 -0
- package/esm/src/evals/mod.js +22 -0
- package/esm/src/evals/record.d.ts +41 -0
- package/esm/src/evals/record.js +107 -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 +75 -0
- package/esm/src/evals/run.js +418 -0
- package/esm/src/evals/suite.d.ts +28 -0
- package/esm/src/evals/suite.js +97 -0
- package/esm/src/evals/summary.d.ts +35 -0
- package/esm/src/evals/summary.js +31 -0
- package/esm/src/evals/trial.d.ts +14 -0
- package/esm/src/evals/trial.js +135 -0
- package/esm/src/evals/types.d.ts +169 -0
- package/esm/src/evals/types.js +113 -0
- package/esm/src/evals/verdict.d.ts +23 -0
- package/esm/src/evals/verdict.js +48 -0
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +22 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +146 -0
- package/esm/src/guardrails/canary.js +974 -0
- package/esm/src/guardrails/compile-egress.d.ts +12 -0
- package/esm/src/guardrails/compile-egress.js +12 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +24 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +305 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +199 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +5 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +120 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +15 -0
- package/esm/src/guardrails/corpus/live-attacks.js +229 -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 +36 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +12 -0
- package/esm/src/guardrails/egress-automata.js +25582 -0
- package/esm/src/guardrails/egress-compiler.d.ts +55 -0
- package/esm/src/guardrails/egress-compiler.js +431 -0
- package/esm/src/guardrails/egress-patterns.d.ts +26 -0
- package/esm/src/guardrails/egress-patterns.js +36 -0
- package/esm/src/guardrails/egress-stream.d.ts +123 -0
- package/esm/src/guardrails/egress-stream.js +774 -0
- package/esm/src/guardrails/egress-urls.d.ts +86 -0
- package/esm/src/guardrails/egress-urls.js +909 -0
- package/esm/src/guardrails/egress.d.ts +46 -0
- package/esm/src/guardrails/egress.js +124 -0
- package/esm/src/guardrails/error.d.ts +31 -0
- package/esm/src/guardrails/error.js +96 -0
- package/esm/src/guardrails/event-schemas.d.ts +100 -0
- package/esm/src/guardrails/event-schemas.js +48 -0
- package/esm/src/guardrails/events.d.ts +13 -0
- package/esm/src/guardrails/events.js +45 -0
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +14 -0
- package/esm/src/guardrails/hits.js +30 -0
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +20 -0
- package/esm/src/guardrails/injection-patterns.js +126 -0
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +30 -0
- package/esm/src/guardrails/injection.js +460 -0
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +874 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +55 -0
- package/esm/src/guardrails/live-outbound-gate.js +298 -0
- package/esm/src/guardrails/mod.d.ts +54 -0
- package/esm/src/guardrails/mod.js +34 -0
- package/esm/src/guardrails/network.d.ts +46 -0
- package/esm/src/guardrails/network.js +330 -0
- package/esm/src/guardrails/normalize.d.ts +20 -0
- package/esm/src/guardrails/normalize.js +165 -0
- package/esm/src/guardrails/policy.d.ts +4 -0
- package/esm/src/guardrails/policy.js +21 -0
- package/esm/src/guardrails/progressive-yield.d.ts +110 -0
- package/esm/src/guardrails/progressive-yield.js +281 -0
- package/esm/src/guardrails/prompt-echo.d.ts +40 -0
- package/esm/src/guardrails/prompt-echo.js +306 -0
- package/esm/src/guardrails/quota.d.ts +21 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +47 -0
- package/esm/src/guardrails/rules.js +47 -0
- package/esm/src/guardrails/sanitize.d.ts +40 -0
- package/esm/src/guardrails/sanitize.js +160 -0
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +22 -0
- package/esm/src/guardrails/sensitive.js +234 -0
- package/esm/src/guardrails/serialize.d.ts +15 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +11 -0
- package/esm/src/guardrails/testing.js +10 -0
- package/esm/src/guardrails/theorem-error.d.ts +21 -0
- package/esm/src/guardrails/theorem-error.js +54 -0
- package/esm/src/guardrails/thought-guard.d.ts +76 -0
- package/esm/src/guardrails/thought-guard.js +664 -0
- package/esm/src/guardrails/tool-directives.d.ts +38 -0
- package/esm/src/guardrails/tool-directives.js +195 -0
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +92 -0
- package/esm/src/guardrails/tool-result.js +272 -0
- package/esm/src/guardrails/types.d.ts +250 -0
- package/esm/src/guardrails/types.js +58 -0
- package/esm/src/host/client-turn.d.ts +36 -0
- package/esm/src/host/client-turn.js +80 -0
- package/esm/src/host/mint-trace.d.ts +29 -0
- package/esm/src/host/mint-trace.js +60 -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 +27 -0
- package/esm/src/host/reply.d.ts +13 -0
- package/esm/src/host/reply.js +41 -0
- package/esm/src/interface/blocks.d.ts +11 -0
- package/esm/src/interface/blocks.js +283 -0
- package/esm/src/interface/composer-actions.d.ts +24 -0
- package/esm/src/interface/composer-actions.js +33 -0
- package/esm/src/interface/draft.d.ts +20 -0
- package/esm/src/interface/draft.js +39 -0
- package/esm/src/interface/from-profile.d.ts +24 -0
- package/esm/src/interface/from-profile.js +179 -0
- package/esm/src/interface/history.d.ts +46 -0
- package/esm/src/interface/history.js +278 -0
- package/esm/src/interface/inputs.d.ts +11 -0
- package/esm/src/interface/inputs.js +67 -0
- package/esm/src/interface/mod.d.ts +33 -0
- package/esm/src/interface/mod.js +22 -0
- package/esm/src/interface/models.d.ts +26 -0
- package/esm/src/interface/models.js +50 -0
- package/esm/src/interface/pending.d.ts +57 -0
- package/esm/src/interface/pending.js +152 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +237 -0
- package/esm/src/interface/session.d.ts +71 -0
- package/esm/src/interface/session.js +128 -0
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +32 -0
- package/esm/src/interface/tool-calls.js +127 -0
- package/esm/src/interface/tool-invoke.d.ts +6 -0
- package/esm/src/interface/tool-invoke.js +22 -0
- package/esm/src/interface/tool-media.d.ts +11 -0
- package/esm/src/interface/tool-media.js +113 -0
- package/esm/src/interface/types.d.ts +278 -0
- package/esm/src/interface/types.js +5 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -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 +56 -0
- package/esm/src/kernel/auth/crypto.js +163 -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 +18 -0
- package/esm/src/kernel/auth/oauth.js +439 -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 +152 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +72 -0
- package/esm/src/kernel/default-scope.js +121 -0
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +71 -0
- package/esm/src/kernel/engine/compaction.js +203 -0
- package/esm/src/kernel/engine/decision.d.ts +43 -0
- package/esm/src/kernel/engine/decision.js +439 -0
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -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 +19 -0
- package/esm/src/kernel/engine/live-inbound.js +44 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +15 -0
- package/esm/src/kernel/engine/live-ingress.js +42 -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 +508 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +29 -0
- package/esm/src/kernel/engine/runner/mod.js +625 -0
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +35 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +179 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +41 -0
- package/esm/src/kernel/engine/runner/state.d.ts +97 -0
- package/esm/src/kernel/engine/runner/state.js +50 -0
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +519 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +71 -0
- package/esm/src/kernel/engine/runner/stream.js +376 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +148 -0
- package/esm/src/kernel/engine/session/mod.d.ts +33 -0
- package/esm/src/kernel/engine/session/mod.js +1182 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +500 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +23 -0
- package/esm/src/kernel/engine/token-estimate.js +38 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +132 -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 +119 -0
- package/esm/src/kernel/engine/turn-trace.js +855 -0
- package/esm/src/kernel/engine/usage.d.ts +36 -0
- package/esm/src/kernel/engine/usage.js +151 -0
- package/esm/src/kernel/interaction-parts.d.ts +13 -0
- package/esm/src/kernel/interaction-parts.js +40 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +74 -0
- package/esm/src/kernel/mod.js +45 -0
- package/esm/src/kernel/profile-graph.d.ts +145 -0
- package/esm/src/kernel/profile-graph.js +158 -0
- package/esm/src/kernel/profile-presence.d.ts +18 -0
- package/esm/src/kernel/profile-presence.js +158 -0
- package/esm/src/kernel/profile-scope.d.ts +40 -0
- package/esm/src/kernel/profile-scope.js +274 -0
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +46 -0
- package/esm/src/kernel/registry/attachments.js +220 -0
- package/esm/src/kernel/registry/catalog.d.ts +25 -0
- package/esm/src/kernel/registry/catalog.js +85 -0
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +12 -0
- package/esm/src/kernel/registry/ingress.js +179 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +15 -0
- package/esm/src/kernel/registry/kernel-registry.js +15 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +10 -0
- package/esm/src/kernel/registry/profiles.d.ts +116 -0
- package/esm/src/kernel/registry/profiles.js +773 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +34 -0
- package/esm/src/kernel/registry/resolve.d.ts +17 -0
- package/esm/src/kernel/registry/resolve.js +238 -0
- package/esm/src/kernel/registry/schemas.d.ts +12 -0
- package/esm/src/kernel/registry/schemas.js +27 -0
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -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 +32 -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 +14 -0
- package/esm/src/kernel/registry/vault.js +1 -0
- package/esm/src/kernel/schema.d.ts +226 -0
- package/esm/src/kernel/schema.js +895 -0
- package/esm/src/kernel/scope.d.ts +29 -0
- package/esm/src/kernel/scope.js +45 -0
- package/esm/src/kernel/stages.d.ts +176 -0
- package/esm/src/kernel/stages.js +431 -0
- package/esm/src/kernel/stop.d.ts +116 -0
- package/esm/src/kernel/stop.js +137 -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 +22 -0
- package/esm/src/kernel/tools/activity-label.js +435 -0
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +66 -0
- package/esm/src/kernel/tools/events.js +184 -0
- package/esm/src/kernel/tools/execute.d.ts +100 -0
- package/esm/src/kernel/tools/execute.js +1173 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +60 -0
- package/esm/src/kernel/tools/gate-answer.js +65 -0
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +17 -0
- package/esm/src/kernel/tools/harness.js +43 -0
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +32 -0
- package/esm/src/kernel/tools/invoke.js +282 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +23 -0
- package/esm/src/kernel/tools/mcp-sessions.js +69 -0
- package/esm/src/kernel/tools/mod.d.ts +10 -0
- package/esm/src/kernel/tools/mod.js +7 -0
- package/esm/src/kernel/tools/model-text.d.ts +16 -0
- package/esm/src/kernel/tools/model-text.js +31 -0
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +15 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +11 -0
- package/esm/src/kernel/tools/project.js +55 -0
- package/esm/src/kernel/tools/registry.d.ts +27 -0
- package/esm/src/kernel/tools/registry.js +143 -0
- package/esm/src/kernel/tools/remote.d.ts +144 -0
- package/esm/src/kernel/tools/remote.js +1125 -0
- package/esm/src/kernel/tools/resolve.d.ts +31 -0
- package/esm/src/kernel/tools/resolve.js +267 -0
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +95 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +19 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +116 -0
- package/esm/src/kernel/tools/stage-run.js +198 -0
- package/esm/src/kernel/tools/types.d.ts +497 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +776 -0
- package/esm/src/kernel/turn-events.js +543 -0
- package/esm/src/kernel/types.d.ts +1025 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +4 -0
- package/esm/src/kernel/util/base64.js +15 -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/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +2 -0
- package/esm/src/kernel/util/record.js +4 -0
- package/esm/src/observability/destinations.d.ts +14 -0
- package/esm/src/observability/destinations.js +43 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +110 -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 +71 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +30 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +17 -0
- package/esm/src/observability/policy.js +73 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +64 -0
- package/esm/src/observability/spans.d.ts +22 -0
- package/esm/src/observability/spans.js +72 -0
- package/esm/src/observability/trace-catalog.d.ts +128 -0
- package/esm/src/observability/trace-catalog.js +906 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +228 -0
- package/esm/src/observability/trace-schema.d.ts +57 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +14 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +98 -0
- package/esm/src/observability/trace-span.js +201 -0
- package/esm/src/observability/trace.d.ts +13 -0
- package/esm/src/observability/trace.js +37 -0
- package/esm/src/observability/types.d.ts +109 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +9 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +13 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +119 -0
- package/esm/src/presets/google.js +197 -0
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +11 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +26 -0
- package/esm/src/presets/openrouter.js +31 -0
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +105 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -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/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -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 +27 -0
- package/esm/src/providers/google/interactions/framing.js +304 -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 +23 -0
- package/esm/src/providers/google/interactions/stream.js +230 -0
- package/esm/src/providers/google/live/framing.d.ts +61 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/stream.d.ts +13 -0
- package/esm/src/providers/google/live/stream.js +57 -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 +4 -0
- package/esm/src/providers/google/urls.js +4 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +32 -0
- package/esm/src/providers/mod.js +23 -0
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +15 -0
- package/esm/src/providers/openrouter/image.js +34 -0
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -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/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -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/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -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/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -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/retry.d.ts +17 -0
- package/esm/src/providers/shared/retry.js +90 -0
- package/esm/src/providers/shared/sse.d.ts +6 -0
- package/esm/src/providers/shared/sse.js +93 -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 +24 -0
- package/esm/src/providers/shared/tool-args.js +88 -0
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -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/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +51 -0
- package/esm/src/providers/types.js +2 -0
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +46 -0
- package/esm/src/surface/formats.js +178 -0
- package/esm/src/surface/mod.d.ts +16 -0
- package/esm/src/surface/mod.js +12 -0
- package/esm/src/surface/runtime.d.ts +44 -0
- package/esm/src/surface/runtime.js +441 -0
- package/esm/src/surface/tools.d.ts +9 -0
- package/esm/src/surface/tools.js +62 -0
- package/esm/src/surface/types.d.ts +110 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +100 -4
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { errorKind, TheoremError } from '../guardrails/error.js';
|
|
2
|
+
import { getProfile, runTurn } from '../kernel/default-scope.js';
|
|
3
|
+
import { isModelProfile } from '../kernel/registry/resolve.js';
|
|
4
|
+
import { isRecord } from '../kernel/util/record.js';
|
|
5
|
+
import { resolveObservabilityPolicy } from '../observability/resolve-policy.js';
|
|
6
|
+
import { memorySink, writeTrace } from '../observability/trace.js';
|
|
7
|
+
import { attachmentData } from './attachments.js';
|
|
8
|
+
import { modelCalls, spanDurationMs } from './graders/shared.js';
|
|
9
|
+
import { buildRunRecord, startTrialRecord } from './record.js';
|
|
10
|
+
import { buildTrial, groupByTrace, hasTurn } from './trial.js';
|
|
11
|
+
import { caseVerdict, trialOutcome } from './verdict.js';
|
|
12
|
+
/** A judge turn's stamp carries `judge`; the turn it judged does not. */
|
|
13
|
+
function isJudgeStamp(record) {
|
|
14
|
+
const stamp = record.metadata?.eval;
|
|
15
|
+
return isRecord(stamp) && stamp.judge !== undefined;
|
|
16
|
+
}
|
|
17
|
+
function stampOf(record) {
|
|
18
|
+
const stamp = record?.metadata?.eval;
|
|
19
|
+
if (!isRecord(stamp) || stamp.judge !== undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
const { suite, case: caseId, trial } = stamp;
|
|
22
|
+
if (typeof suite !== 'string' || typeof caseId !== 'string' || typeof trial !== 'number') {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return { suite, case: caseId, trial };
|
|
26
|
+
}
|
|
27
|
+
/** Judge records reach `context.traced` in grader order once every grader is done, so a run writes the same records in the same order whichever judge answered first. */
|
|
28
|
+
async function gradeTrial(graders, trial, context) {
|
|
29
|
+
const applicable = trial.case ? graders : graders.filter((grader) => !grader.needsExpect);
|
|
30
|
+
const graded = await Promise.all(applicable.map(async (grader) => {
|
|
31
|
+
const records = [];
|
|
32
|
+
const own = {
|
|
33
|
+
...context,
|
|
34
|
+
traced: (traced) => {
|
|
35
|
+
records.push(...traced);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
return { records, result: await grader.grade(trial, own), graderIdentity: grader.identity };
|
|
40
|
+
}
|
|
41
|
+
catch (thrown) {
|
|
42
|
+
return {
|
|
43
|
+
records,
|
|
44
|
+
result: {
|
|
45
|
+
name: grader.name,
|
|
46
|
+
source: grader.source,
|
|
47
|
+
errorType: 'grader_error',
|
|
48
|
+
explanation: thrown instanceof Error ? thrown.message : String(thrown),
|
|
49
|
+
},
|
|
50
|
+
graderIdentity: grader.identity,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
for (const { records } of graded)
|
|
55
|
+
await context.traced(records);
|
|
56
|
+
return graded.map(({ result, graderIdentity }) => ({ result, graderIdentity }));
|
|
57
|
+
}
|
|
58
|
+
function erroredResults(graders, evalCase, error) {
|
|
59
|
+
const applicable = evalCase ? graders : graders.filter((grader) => !grader.needsExpect);
|
|
60
|
+
return applicable.map((grader) => ({
|
|
61
|
+
name: grader.name,
|
|
62
|
+
source: grader.source,
|
|
63
|
+
errorType: error,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
/** The record's root: the span no other span in it parents (a judge call's root has the trial span above it). */
|
|
67
|
+
function recordRoot(record) {
|
|
68
|
+
const ids = new Set(record.spans.map((span) => span.spanId));
|
|
69
|
+
return record.spans.find((span) => span.parentSpanId === undefined || !ids.has(span.parentSpanId));
|
|
70
|
+
}
|
|
71
|
+
function recordCost(record) {
|
|
72
|
+
const attributes = recordRoot(record)?.attributes;
|
|
73
|
+
const cost = attributes?.['theorem.usage.cost_usd'];
|
|
74
|
+
if (typeof cost !== 'number')
|
|
75
|
+
return { whole: false };
|
|
76
|
+
return { usd: cost, whole: attributes?.['theorem.usage.cost_partial'] !== true };
|
|
77
|
+
}
|
|
78
|
+
function recordAgent(record) {
|
|
79
|
+
const agent = recordRoot(record)?.attributes['gen_ai.agent.name'];
|
|
80
|
+
return typeof agent === 'string' ? agent : undefined;
|
|
81
|
+
}
|
|
82
|
+
async function gradeRecords(grading, evalCase, index, records) {
|
|
83
|
+
const trial = buildTrial({ suite: grading.suite.suite.id, case: evalCase, index, records });
|
|
84
|
+
const trialRecord = startTrialRecord({
|
|
85
|
+
trial,
|
|
86
|
+
policy: grading.policy,
|
|
87
|
+
...(grading.clock ? { clock: grading.clock } : {}),
|
|
88
|
+
});
|
|
89
|
+
const usage = trial.usage();
|
|
90
|
+
const judgeRecords = [];
|
|
91
|
+
let judgeCostUsd;
|
|
92
|
+
let unpriced = usage.costUsd === undefined || usage.tokens.cost?.partial ? 1 : 0;
|
|
93
|
+
let priced = usage.costUsd === undefined ? 0 : 1;
|
|
94
|
+
const { judging } = grading;
|
|
95
|
+
const context = {
|
|
96
|
+
...(judging.suiteJudge ? { judge: judging.suiteJudge } : {}),
|
|
97
|
+
...(judging.provider ? { judgeProvider: judging.provider } : {}),
|
|
98
|
+
...(judging.decision ? { judgeDecision: judging.decision } : {}),
|
|
99
|
+
...(judging.media ? { media: judging.media } : {}),
|
|
100
|
+
traceparent: trialRecord.traceparent,
|
|
101
|
+
traced: async (traced) => {
|
|
102
|
+
for (const record of traced) {
|
|
103
|
+
judgeRecords.push(record);
|
|
104
|
+
const cost = recordCost(record);
|
|
105
|
+
if (cost.usd !== undefined) {
|
|
106
|
+
judgeCostUsd = (judgeCostUsd ?? 0) + cost.usd;
|
|
107
|
+
priced += 1;
|
|
108
|
+
}
|
|
109
|
+
if (!cost.whole)
|
|
110
|
+
unpriced += 1;
|
|
111
|
+
const policy = judging.policies.get(recordAgent(record) ?? '');
|
|
112
|
+
if (grading.sink && policy)
|
|
113
|
+
await writeTrace(grading.sink, Promise.resolve(record), policy);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
...(grading.signal ? { signal: grading.signal } : {}),
|
|
117
|
+
};
|
|
118
|
+
const graded = await gradeTrial(grading.suite.suite.graders, trial, context);
|
|
119
|
+
const results = graded.map((entry) => entry.result);
|
|
120
|
+
const built = await trialRecord.finish(graded);
|
|
121
|
+
grading.trialSpans.push(built.span);
|
|
122
|
+
if (grading.sink)
|
|
123
|
+
await writeTrace(grading.sink, Promise.resolve(built.record), grading.policy);
|
|
124
|
+
const { costUsd } = usage;
|
|
125
|
+
return {
|
|
126
|
+
...(evalCase ? { case: evalCase } : {}),
|
|
127
|
+
index,
|
|
128
|
+
outcome: trialOutcome(results),
|
|
129
|
+
results,
|
|
130
|
+
traceId: trial.root.traceId,
|
|
131
|
+
turn: {
|
|
132
|
+
durationMs: spanDurationMs(trial.top),
|
|
133
|
+
modelCalls: modelCalls(trial).length,
|
|
134
|
+
toolCalls: trial.spans('execute_tool').length,
|
|
135
|
+
...(typeof trial.root.attributes['theorem.stop.kind'] === 'string'
|
|
136
|
+
? { stop: trial.root.attributes['theorem.stop.kind'] }
|
|
137
|
+
: {}),
|
|
138
|
+
},
|
|
139
|
+
records,
|
|
140
|
+
...(costUsd === undefined ? {} : { costUsd }),
|
|
141
|
+
...(judgeCostUsd === undefined ? {} : { judgeCostUsd }),
|
|
142
|
+
unpriced,
|
|
143
|
+
priced,
|
|
144
|
+
judgeRecords,
|
|
145
|
+
trialRecord: built.record,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async function turnRequest(suite, evalCase, index) {
|
|
149
|
+
if ('session' in evalCase.input) {
|
|
150
|
+
throw new TheoremError('config', `case ${evalCase.id} is a session script; suite ${suite.suite.id} runs turns`);
|
|
151
|
+
}
|
|
152
|
+
const stamp = { suite: suite.suite.id, case: evalCase.id, trial: index };
|
|
153
|
+
return {
|
|
154
|
+
profile: suite.suite.profile,
|
|
155
|
+
input: {
|
|
156
|
+
...(evalCase.input.text === undefined ? {} : { text: evalCase.input.text }),
|
|
157
|
+
...(evalCase.input.attachments
|
|
158
|
+
? {
|
|
159
|
+
attachments: await Promise.all(evalCase.input.attachments.map(async (attachment) => ({
|
|
160
|
+
mimeType: attachment.mimeType,
|
|
161
|
+
data: await attachmentData(attachment),
|
|
162
|
+
...(attachment.name === undefined ? {} : { name: attachment.name }),
|
|
163
|
+
}))),
|
|
164
|
+
}
|
|
165
|
+
: {}),
|
|
166
|
+
},
|
|
167
|
+
metadata: { eval: stamp },
|
|
168
|
+
...(suite.onStage ? { onStage: suite.onStage } : {}),
|
|
169
|
+
...(suite.host === undefined ? {} : { host: suite.host }),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async function runLiveTrial(grading, provider, evalCase, index, signal) {
|
|
173
|
+
const records = [];
|
|
174
|
+
let thrown;
|
|
175
|
+
try {
|
|
176
|
+
const request = {
|
|
177
|
+
...(await turnRequest(grading.suite, evalCase, index)),
|
|
178
|
+
...(signal ? { signal } : {}),
|
|
179
|
+
};
|
|
180
|
+
for await (const _event of runTurn(request, provider, memorySink(records))) {
|
|
181
|
+
// why: The trace is the record of the turn; events are not graded.
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
thrown = error;
|
|
186
|
+
}
|
|
187
|
+
if (records.length > 0) {
|
|
188
|
+
if (grading.sink) {
|
|
189
|
+
for (const record of records) {
|
|
190
|
+
await writeTrace(grading.sink, Promise.resolve(record), grading.policy);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return gradeRecords(grading, evalCase, index, records);
|
|
194
|
+
}
|
|
195
|
+
const error = thrown === undefined ? 'internal' : errorKind(thrown);
|
|
196
|
+
const results = erroredResults(grading.suite.suite.graders, evalCase, error);
|
|
197
|
+
return {
|
|
198
|
+
case: evalCase,
|
|
199
|
+
index,
|
|
200
|
+
outcome: trialOutcome(results),
|
|
201
|
+
results,
|
|
202
|
+
records,
|
|
203
|
+
unpriced: 0,
|
|
204
|
+
priced: 0,
|
|
205
|
+
judgeRecords: [],
|
|
206
|
+
error,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function judgingOf(loaded, options) {
|
|
210
|
+
const { suite } = loaded;
|
|
211
|
+
const provider = options.judgeProvider ?? loaded.judgeProvider ?? options.provider;
|
|
212
|
+
const decision = options.judgeDecision ?? loaded.judgeDecision;
|
|
213
|
+
const media = options.media ?? loaded.media;
|
|
214
|
+
const policies = new Map();
|
|
215
|
+
for (const grader of suite.graders) {
|
|
216
|
+
for (const id of grader.judgeProfiles?.(suite.judge?.profile) ?? []) {
|
|
217
|
+
const profile = getProfile(id);
|
|
218
|
+
if (profile.type === 'decision' && !decision) {
|
|
219
|
+
throw new TheoremError('config', `suite ${suite.id}: grader ${grader.name} needs a key for decision judge profile ${id}; export judgeDecision`);
|
|
220
|
+
}
|
|
221
|
+
if (profile.type !== 'decision' && !provider) {
|
|
222
|
+
throw new TheoremError('config', `suite ${suite.id}: grader ${grader.name} needs a provider for judge profile ${id}`);
|
|
223
|
+
}
|
|
224
|
+
policies.set(id, resolveObservabilityPolicy(profile.observability));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
...(suite.judge ? { suiteJudge: suite.judge.profile } : {}),
|
|
229
|
+
...(provider ? { provider } : {}),
|
|
230
|
+
...(decision ? { decision } : {}),
|
|
231
|
+
...(media ? { media } : {}),
|
|
232
|
+
policies,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function checkSuite(loaded, options) {
|
|
236
|
+
const { suite } = loaded;
|
|
237
|
+
const profile = getProfile(suite.profile);
|
|
238
|
+
if (!isModelProfile(profile)) {
|
|
239
|
+
throw new TheoremError('config', `suite ${suite.id}: profile ${suite.profile} runs no model turn`); // labels-exempt: developer contract error
|
|
240
|
+
}
|
|
241
|
+
if (suite.mode === 'session') {
|
|
242
|
+
throw new TheoremError('config', `suite ${suite.id}: session suites are not run yet`); // labels-exempt: developer contract error
|
|
243
|
+
}
|
|
244
|
+
if (profile.type === 'live') {
|
|
245
|
+
throw new TheoremError('config', `suite ${suite.id}: a live profile needs mode 'session'`); // labels-exempt: developer contract error
|
|
246
|
+
}
|
|
247
|
+
if (!options.recorded && !options.provider) {
|
|
248
|
+
throw new TheoremError('config', `suite ${suite.id}: live mode needs a provider`); // labels-exempt: developer contract error
|
|
249
|
+
}
|
|
250
|
+
if (suite.graders.length === 0) {
|
|
251
|
+
throw new TheoremError('config', `suite ${suite.id}: no graders`); // labels-exempt: developer contract error
|
|
252
|
+
}
|
|
253
|
+
const warnings = [];
|
|
254
|
+
const repeat = options.repeat ?? suite.trials.repeat;
|
|
255
|
+
if (repeat === 1) {
|
|
256
|
+
warnings.push('one trial per case cannot tell noise from change; set trials.repeat to 3 or more');
|
|
257
|
+
}
|
|
258
|
+
return warnings;
|
|
259
|
+
}
|
|
260
|
+
function reportCost(report) {
|
|
261
|
+
return (report.costUsd ?? 0) + (report.judgeCostUsd ?? 0);
|
|
262
|
+
}
|
|
263
|
+
function summedCost(reports) {
|
|
264
|
+
return reports.reduce((sum, report) => sum + reportCost(report), 0);
|
|
265
|
+
}
|
|
266
|
+
function summedCalls(reports, key) {
|
|
267
|
+
return reports.reduce((sum, report) => sum + report[key], 0);
|
|
268
|
+
}
|
|
269
|
+
async function gradeRecorded(grading, records) {
|
|
270
|
+
const byCase = new Map();
|
|
271
|
+
const caseless = [];
|
|
272
|
+
const cases = new Map(grading.suite.cases.map((evalCase) => [evalCase.id, evalCase]));
|
|
273
|
+
const skipped = { judge: 0, other: 0 };
|
|
274
|
+
for (const [, group] of groupByTrace(records)) {
|
|
275
|
+
const traceRecords = group.filter((record) => !isJudgeStamp(record));
|
|
276
|
+
skipped.judge += group.length - traceRecords.length;
|
|
277
|
+
if (traceRecords.length === 0)
|
|
278
|
+
continue;
|
|
279
|
+
if (!hasTurn(traceRecords)) {
|
|
280
|
+
skipped.other += 1;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const stamp = traceRecords
|
|
284
|
+
.map(stampOf)
|
|
285
|
+
.find((found) => found?.suite === grading.suite.suite.id);
|
|
286
|
+
const evalCase = stamp ? cases.get(stamp.case) : undefined;
|
|
287
|
+
if (!evalCase) {
|
|
288
|
+
caseless.push(await gradeRecords(grading, undefined, caseless.length, traceRecords));
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const index = stamp?.trial ?? 0;
|
|
292
|
+
const report = await gradeRecords(grading, evalCase, index, traceRecords);
|
|
293
|
+
byCase.set(evalCase.id, [...(byCase.get(evalCase.id) ?? []), report]);
|
|
294
|
+
}
|
|
295
|
+
const reports = [...byCase.values(), caseless].flat();
|
|
296
|
+
return {
|
|
297
|
+
byCase,
|
|
298
|
+
caseless,
|
|
299
|
+
costUsd: summedCost(reports),
|
|
300
|
+
unpriced: summedCalls(reports, 'unpriced'),
|
|
301
|
+
priced: summedCalls(reports, 'priced'),
|
|
302
|
+
skipped,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/** The cost ceiling is checked before each start, so a stop lets what is in flight finish and count. */
|
|
306
|
+
async function runLive(grading, provider, repeat, options) {
|
|
307
|
+
const jobs = grading.suite.cases.flatMap((evalCase) => Array.from({ length: repeat }, (_, index) => ({ evalCase, index })));
|
|
308
|
+
const reports = new Map(grading.suite.cases.map((evalCase) => [evalCase.id, []]));
|
|
309
|
+
let next = 0;
|
|
310
|
+
let costUsd = 0;
|
|
311
|
+
let stopped;
|
|
312
|
+
const worker = async () => {
|
|
313
|
+
while (next < jobs.length) {
|
|
314
|
+
if (options.maxCostUsd !== undefined && costUsd > options.maxCostUsd) {
|
|
315
|
+
stopped = 'budget';
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const job = jobs[next++];
|
|
319
|
+
if (!job)
|
|
320
|
+
return;
|
|
321
|
+
const report = await runLiveTrial(grading, provider, job.evalCase, job.index, options.signal);
|
|
322
|
+
costUsd += reportCost(report);
|
|
323
|
+
reports.get(job.evalCase.id)?.push(report);
|
|
324
|
+
options.onTrial?.(report);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const workers = Math.max(1, Math.min(options.concurrency ?? 1, jobs.length));
|
|
328
|
+
await Promise.all(Array.from({ length: workers }, worker));
|
|
329
|
+
const byCase = new Map();
|
|
330
|
+
for (const [id, list] of reports) {
|
|
331
|
+
byCase.set(id, [...list].sort((a, b) => a.index - b.index));
|
|
332
|
+
}
|
|
333
|
+
const all = [...byCase.values()].flat();
|
|
334
|
+
return {
|
|
335
|
+
byCase,
|
|
336
|
+
caseless: [],
|
|
337
|
+
...(stopped ? { stopped } : {}),
|
|
338
|
+
costUsd,
|
|
339
|
+
unpriced: summedCalls(all, 'unpriced'),
|
|
340
|
+
priced: summedCalls(all, 'priced'),
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
async function ranOf(grading, repeat, options) {
|
|
344
|
+
if (options.recorded !== undefined) {
|
|
345
|
+
const ran = await gradeRecorded(grading, options.recorded);
|
|
346
|
+
for (const report of [...ran.byCase.values(), ran.caseless].flat())
|
|
347
|
+
options.onTrial?.(report);
|
|
348
|
+
return ran;
|
|
349
|
+
}
|
|
350
|
+
if (!options.provider) {
|
|
351
|
+
throw new TheoremError('config', `suite ${grading.suite.suite.id}: live mode needs a provider`); // labels-exempt: developer contract error
|
|
352
|
+
}
|
|
353
|
+
return runLive(grading, options.provider, repeat, options);
|
|
354
|
+
}
|
|
355
|
+
/** Runs every case of a suite and returns the graded run. */
|
|
356
|
+
async function runSuite(loaded, options = {}) {
|
|
357
|
+
const warnings = checkSuite(loaded, options);
|
|
358
|
+
const { suite } = loaded;
|
|
359
|
+
const repeat = options.repeat ?? suite.trials.repeat;
|
|
360
|
+
const profile = getProfile(suite.profile);
|
|
361
|
+
const policy = resolveObservabilityPolicy(isModelProfile(profile) ? profile.observability : undefined);
|
|
362
|
+
const grading = {
|
|
363
|
+
suite: loaded,
|
|
364
|
+
policy,
|
|
365
|
+
judging: judgingOf(loaded, options),
|
|
366
|
+
...(options.sink ? { sink: options.sink } : {}),
|
|
367
|
+
...(options.clock ? { clock: options.clock } : {}),
|
|
368
|
+
trialSpans: [],
|
|
369
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
370
|
+
};
|
|
371
|
+
const ran = await ranOf(grading, repeat, options);
|
|
372
|
+
if (ran.skipped && ran.skipped.judge + ran.skipped.other > 0) {
|
|
373
|
+
warnings.push(`skipped ${ran.skipped.judge} judge call record(s) and ${ran.skipped.other} record(s) with no turn; they are not trials`);
|
|
374
|
+
}
|
|
375
|
+
if (options.maxCostUsd !== undefined && ran.unpriced > 0) {
|
|
376
|
+
warnings.push(`maxCostUsd counts only the costs providers report; ${ran.unpriced} call(s) reported none or only part, so the ceiling could not hold them`);
|
|
377
|
+
}
|
|
378
|
+
const rule = suite.trials.pass ?? 'all';
|
|
379
|
+
const verdicts = loaded.cases.map((evalCase) => caseVerdict(evalCase, (ran.byCase.get(evalCase.id) ?? []).map((report) => report.results), rule));
|
|
380
|
+
const decided = verdicts.filter((verdict) => verdict.decided);
|
|
381
|
+
const undecided = verdicts.length - decided.length;
|
|
382
|
+
if (undecided > 0) {
|
|
383
|
+
warnings.push(`${undecided} case(s) undecided: too few of their trials escaped error to apply the pass rule, so no pass rate counts them`);
|
|
384
|
+
}
|
|
385
|
+
const run = await buildRunRecord({
|
|
386
|
+
suite: {
|
|
387
|
+
id: suite.id,
|
|
388
|
+
trials: { repeat, ...(suite.trials.pass ? { pass: suite.trials.pass } : {}) },
|
|
389
|
+
},
|
|
390
|
+
verdicts,
|
|
391
|
+
trialSpans: grading.trialSpans,
|
|
392
|
+
policy,
|
|
393
|
+
...(options.clock ? { clock: options.clock } : {}),
|
|
394
|
+
...(ran.caseless.length > 0 ? { caseless: true } : {}),
|
|
395
|
+
...(ran.stopped ? { stopped: ran.stopped } : {}),
|
|
396
|
+
...(options.revision ? { revision: options.revision } : {}),
|
|
397
|
+
});
|
|
398
|
+
if (options.sink)
|
|
399
|
+
await writeTrace(options.sink, Promise.resolve(run), policy);
|
|
400
|
+
const trials = [...ran.byCase.values()].flat();
|
|
401
|
+
return {
|
|
402
|
+
suite: suite.id,
|
|
403
|
+
mode: options.recorded !== undefined ? 'recorded' : 'live',
|
|
404
|
+
repeat,
|
|
405
|
+
passRule: rule,
|
|
406
|
+
verdicts,
|
|
407
|
+
trials,
|
|
408
|
+
caseless: ran.caseless,
|
|
409
|
+
passed: ran.stopped === undefined && decided.length > 0 && decided.every((verdict) => verdict.passed),
|
|
410
|
+
...(ran.stopped ? { stopped: ran.stopped } : {}),
|
|
411
|
+
costUsd: ran.costUsd,
|
|
412
|
+
unpriced: ran.unpriced,
|
|
413
|
+
priced: ran.priced,
|
|
414
|
+
warnings,
|
|
415
|
+
run,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
export { runSuite };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { RunDecisionOptions } from '../kernel/engine/decision.js';
|
|
3
|
+
import type { ProviderHostOptions } from '../kernel/protocols/runtime.js';
|
|
4
|
+
import type { StageHandler } from '../kernel/stages.js';
|
|
5
|
+
import { type TraceRecord } from '../observability/trace-schema.js';
|
|
6
|
+
import { type EvalCase, type EvalMediaResolver, type EvalSuite } from './types.js';
|
|
7
|
+
/** A suite with its cases read, the providers, media resolver, and stage handler its module exports, and the module's path. */
|
|
8
|
+
interface LoadedSuite {
|
|
9
|
+
suite: EvalSuite;
|
|
10
|
+
cases: EvalCase[];
|
|
11
|
+
provider?: ProviderHostOptions;
|
|
12
|
+
judgeProvider?: ProviderHostOptions;
|
|
13
|
+
judgeDecision?: Omit<RunDecisionOptions, 'sink'>;
|
|
14
|
+
media?: EvalMediaResolver;
|
|
15
|
+
/** The stage handler every live trial's turn runs with, as the host's own requests do. */
|
|
16
|
+
onStage?: StageHandler;
|
|
17
|
+
/** The application context every live trial's turn carries as `TurnRequest.host`; its tools read it as `ctx.host`. */
|
|
18
|
+
host?: unknown;
|
|
19
|
+
path: string;
|
|
20
|
+
}
|
|
21
|
+
/** Reads a JSON Lines file, parsing each line against the schema; throws with the file and line number on a line that is not JSON or does not match. */
|
|
22
|
+
declare function readJsonl<T>(path: string, schema: z.ZodType<T>, what: string): Promise<T[]>;
|
|
23
|
+
/** Reads trace records from a `.jsonl` file, or from every `.jsonl` file in a directory, in name order. */
|
|
24
|
+
declare function readTraceRecords(path: string): Promise<TraceRecord[]>;
|
|
25
|
+
/** Imports a suite module, checks its default export against `EvalSuite` and reads its cases; throws when a case id repeats. */
|
|
26
|
+
declare function loadSuite(modulePath: string): Promise<LoadedSuite>;
|
|
27
|
+
export type { LoadedSuite };
|
|
28
|
+
export { loadSuite, readJsonl, readTraceRecords };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { cwd } from 'node:process';
|
|
3
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
4
|
+
import { isRecord } from '../kernel/util/record.js';
|
|
5
|
+
import { traceRecordSchema } from '../observability/trace-schema.js';
|
|
6
|
+
import { pinCaseFiles } from './attachments.js';
|
|
7
|
+
import { evalCaseSchema, evalSuiteSchema, } from './types.js';
|
|
8
|
+
function isProvider(value) {
|
|
9
|
+
return isRecord(value) && !('complete' in value);
|
|
10
|
+
}
|
|
11
|
+
function isDecisionKey(value) {
|
|
12
|
+
return isRecord(value) && isRecord(value.vault);
|
|
13
|
+
}
|
|
14
|
+
function absolute(path) {
|
|
15
|
+
return path.startsWith('/') ? path : `${cwd()}/${path}`;
|
|
16
|
+
}
|
|
17
|
+
function siblingOf(modulePath, relative) {
|
|
18
|
+
const dir = modulePath.slice(0, modulePath.lastIndexOf('/'));
|
|
19
|
+
return relative.startsWith('/') ? relative : `${dir}/${relative}`;
|
|
20
|
+
}
|
|
21
|
+
/** Reads a JSON Lines file, parsing each line against the schema; throws with the file and line number on a line that is not JSON or does not match. */
|
|
22
|
+
async function readJsonl(path, schema, what) {
|
|
23
|
+
const text = await readFile(path, 'utf8');
|
|
24
|
+
const out = [];
|
|
25
|
+
const lines = text.split('\n');
|
|
26
|
+
for (const [index, line] of lines.entries()) {
|
|
27
|
+
if (line.trim() === '')
|
|
28
|
+
continue;
|
|
29
|
+
let parsed;
|
|
30
|
+
try {
|
|
31
|
+
parsed = JSON.parse(line);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
throw new TheoremError('config', `${path}:${index + 1}: ${what} is not JSON`); // labels-exempt: developer contract error
|
|
35
|
+
}
|
|
36
|
+
const result = schema.safeParse(parsed);
|
|
37
|
+
if (!result.success) {
|
|
38
|
+
const issue = result.error.issues[0];
|
|
39
|
+
const at = issue?.path.join('.') || '(root)';
|
|
40
|
+
throw new TheoremError('config', `${path}:${index + 1}: ${what} ${at}: ${issue?.message ?? 'invalid'}`);
|
|
41
|
+
}
|
|
42
|
+
out.push(result.data);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
/** Reads trace records from a `.jsonl` file, or from every `.jsonl` file in a directory, in name order. */
|
|
47
|
+
async function readTraceRecords(path) {
|
|
48
|
+
const target = absolute(path);
|
|
49
|
+
const info = await stat(target);
|
|
50
|
+
if (!info.isDirectory())
|
|
51
|
+
return readJsonl(target, traceRecordSchema, 'trace record');
|
|
52
|
+
const files = [];
|
|
53
|
+
for (const entry of await readdir(target, { withFileTypes: true })) {
|
|
54
|
+
if (entry.isFile() && entry.name.endsWith('.jsonl'))
|
|
55
|
+
files.push(`${target}/${entry.name}`);
|
|
56
|
+
}
|
|
57
|
+
files.sort();
|
|
58
|
+
const records = [];
|
|
59
|
+
for (const file of files)
|
|
60
|
+
records.push(...(await readJsonl(file, traceRecordSchema, 'trace record')));
|
|
61
|
+
return records;
|
|
62
|
+
}
|
|
63
|
+
/** Imports a suite module, checks its default export against `EvalSuite` and reads its cases; throws when a case id repeats. */
|
|
64
|
+
async function loadSuite(modulePath) {
|
|
65
|
+
const path = absolute(modulePath);
|
|
66
|
+
const module = await import(new URL(`file://${path}`).href);
|
|
67
|
+
if (!isRecord(module)) {
|
|
68
|
+
throw new TheoremError('config', `${modulePath}: not a module`); // labels-exempt: developer contract error
|
|
69
|
+
}
|
|
70
|
+
const parsed = evalSuiteSchema.safeParse(module.default);
|
|
71
|
+
if (!parsed.success) {
|
|
72
|
+
const issue = parsed.error.issues[0];
|
|
73
|
+
throw new TheoremError('config', `${modulePath}: default export is not an EvalSuite (${issue?.path.join('.') || 'root'}: ${issue?.message ?? 'invalid'})`);
|
|
74
|
+
}
|
|
75
|
+
const suite = parsed.data;
|
|
76
|
+
const casesPath = siblingOf(path, suite.cases);
|
|
77
|
+
const cases = await readJsonl(casesPath, evalCaseSchema, 'case');
|
|
78
|
+
const ids = new Set();
|
|
79
|
+
for (const evalCase of cases) {
|
|
80
|
+
if (ids.has(evalCase.id)) {
|
|
81
|
+
throw new TheoremError('config', `${suite.cases}: case id ${evalCase.id} appears twice`); // labels-exempt: developer contract error
|
|
82
|
+
}
|
|
83
|
+
ids.add(evalCase.id);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
suite,
|
|
87
|
+
cases: await pinCaseFiles(cases, casesPath),
|
|
88
|
+
path,
|
|
89
|
+
...(isProvider(module.provider) ? { provider: module.provider } : {}),
|
|
90
|
+
...(isProvider(module.judgeProvider) ? { judgeProvider: module.judgeProvider } : {}),
|
|
91
|
+
...(isDecisionKey(module.judgeDecision) ? { judgeDecision: module.judgeDecision } : {}),
|
|
92
|
+
...(typeof module.media === 'function' ? { media: module.media } : {}),
|
|
93
|
+
...(typeof module.onStage === 'function' ? { onStage: module.onStage } : {}),
|
|
94
|
+
...(module.host === undefined ? {} : { host: module.host }),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export { loadSuite, readJsonl, readTraceRecords };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type GroupSummary } from './breakdown.js';
|
|
2
|
+
import type { SuiteRun, TurnShape } from './run.js';
|
|
3
|
+
import type { EvalPassRule, EvalResult } from './types.js';
|
|
4
|
+
import type { CaseVerdict, TrialOutcome } from './verdict.js';
|
|
5
|
+
/** One trial in a run summary: its case, index, outcome, trace id, turn shape, error, and grader results. */
|
|
6
|
+
interface TrialSummary {
|
|
7
|
+
case?: string;
|
|
8
|
+
index: number;
|
|
9
|
+
outcome: TrialOutcome;
|
|
10
|
+
traceId?: string;
|
|
11
|
+
turn?: TurnShape;
|
|
12
|
+
error?: string;
|
|
13
|
+
results: EvalResult[];
|
|
14
|
+
}
|
|
15
|
+
/** A suite run reduced to what a report shows: the pass rule and verdict, cost, priced and unpriced counts, per-case verdicts, group summaries, and trials. */
|
|
16
|
+
interface RunSummary {
|
|
17
|
+
suite: string;
|
|
18
|
+
mode: 'live' | 'recorded';
|
|
19
|
+
repeat: number;
|
|
20
|
+
passRule: EvalPassRule;
|
|
21
|
+
passed: boolean;
|
|
22
|
+
stopped?: 'budget';
|
|
23
|
+
costUsd: number;
|
|
24
|
+
unpriced: number;
|
|
25
|
+
priced: number;
|
|
26
|
+
verdicts: CaseVerdict[];
|
|
27
|
+
groups: GroupSummary[];
|
|
28
|
+
trials: TrialSummary[];
|
|
29
|
+
runTraceId?: string;
|
|
30
|
+
warnings: string[];
|
|
31
|
+
}
|
|
32
|
+
/** Reduces a suite run to a `RunSummary`. */
|
|
33
|
+
declare function summarizeRun(run: SuiteRun): RunSummary;
|
|
34
|
+
export type { RunSummary, TrialSummary };
|
|
35
|
+
export { summarizeRun };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { groupSummaries } from './breakdown.js';
|
|
2
|
+
/** Reduces a suite run to a `RunSummary`. */
|
|
3
|
+
function summarizeRun(run) {
|
|
4
|
+
const trials = [...run.trials, ...run.caseless].map((report) => ({
|
|
5
|
+
...(report.case ? { case: report.case.id } : {}),
|
|
6
|
+
index: report.index,
|
|
7
|
+
outcome: report.outcome,
|
|
8
|
+
...(report.traceId ? { traceId: report.traceId } : {}),
|
|
9
|
+
...(report.turn ? { turn: report.turn } : {}),
|
|
10
|
+
...(report.error ? { error: report.error } : {}),
|
|
11
|
+
results: report.results,
|
|
12
|
+
}));
|
|
13
|
+
const runTraceId = run.run.spans[0]?.traceId;
|
|
14
|
+
return {
|
|
15
|
+
suite: run.suite,
|
|
16
|
+
mode: run.mode,
|
|
17
|
+
repeat: run.repeat,
|
|
18
|
+
passRule: run.passRule,
|
|
19
|
+
passed: run.passed,
|
|
20
|
+
...(run.stopped ? { stopped: run.stopped } : {}),
|
|
21
|
+
costUsd: run.costUsd,
|
|
22
|
+
unpriced: run.unpriced,
|
|
23
|
+
priced: run.priced,
|
|
24
|
+
verdicts: run.verdicts,
|
|
25
|
+
groups: groupSummaries(run),
|
|
26
|
+
trials,
|
|
27
|
+
...(runTraceId ? { runTraceId } : {}),
|
|
28
|
+
warnings: run.warnings,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { summarizeRun };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TraceRecord } from '../observability/trace-record.js';
|
|
2
|
+
import type { EvalCase, Trial } from './types.js';
|
|
3
|
+
/** Builds the `Trial` a grader reads from one trial's trace records: its root and top spans and accessors for spans, children, content, delivered output, and usage. */
|
|
4
|
+
declare function buildTrial(args: {
|
|
5
|
+
suite: string;
|
|
6
|
+
case?: EvalCase;
|
|
7
|
+
index: number;
|
|
8
|
+
records: TraceRecord[];
|
|
9
|
+
}): Trial;
|
|
10
|
+
/** Groups trace records by the trace id of their first span; records with no spans are dropped. */
|
|
11
|
+
declare function groupByTrace(records: TraceRecord[]): Map<string, TraceRecord[]>;
|
|
12
|
+
/** True when any record holds an `invoke_agent` span, meaning an agent turn ran. */
|
|
13
|
+
declare function hasTurn(records: readonly TraceRecord[]): boolean;
|
|
14
|
+
export { buildTrial, groupByTrace, hasTurn };
|