@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,135 @@
|
|
|
1
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
2
|
+
import { contentOf, inlineContent } from '../observability/trace-record.js';
|
|
3
|
+
function byStart(a, b) {
|
|
4
|
+
const left = BigInt(a.startTimeUnixNano);
|
|
5
|
+
const right = BigInt(b.startTimeUnixNano);
|
|
6
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
7
|
+
}
|
|
8
|
+
function operationOf(span) {
|
|
9
|
+
const value = span.attributes['gen_ai.operation.name'];
|
|
10
|
+
return typeof value === 'string' ? value : undefined;
|
|
11
|
+
}
|
|
12
|
+
function allSpans(records) {
|
|
13
|
+
return records.flatMap((record) => record.spans).sort(byStart);
|
|
14
|
+
}
|
|
15
|
+
function ancestorsOf(span, byId) {
|
|
16
|
+
const above = [];
|
|
17
|
+
const seen = new Set([span.spanId]);
|
|
18
|
+
let parent = span.parentSpanId === undefined ? undefined : byId.get(span.parentSpanId);
|
|
19
|
+
while (parent && !seen.has(parent.spanId)) {
|
|
20
|
+
above.push(parent);
|
|
21
|
+
seen.add(parent.spanId);
|
|
22
|
+
parent = parent.parentSpanId === undefined ? undefined : byId.get(parent.parentSpanId);
|
|
23
|
+
}
|
|
24
|
+
return above;
|
|
25
|
+
}
|
|
26
|
+
/** The earliest `invoke_agent` span with no `invoke_agent` above it; never assumed to be the first record, since a compaction turn's record can be written before its parent's (P9). */
|
|
27
|
+
function rootOf(spans, byId) {
|
|
28
|
+
const roots = spans.filter((span) => operationOf(span) === 'invoke_agent' &&
|
|
29
|
+
!ancestorsOf(span, byId).some((above) => operationOf(above) === 'invoke_agent'));
|
|
30
|
+
const [root] = roots;
|
|
31
|
+
if (!root) {
|
|
32
|
+
throw new TheoremError('config', 'trial records hold no invoke_agent root span'); // labels-exempt: developer contract error
|
|
33
|
+
}
|
|
34
|
+
return root;
|
|
35
|
+
}
|
|
36
|
+
/** One record whose `content` is every record's, so a reference from any span resolves. */
|
|
37
|
+
function mergedRecord(records) {
|
|
38
|
+
const [first] = records;
|
|
39
|
+
if (!first) {
|
|
40
|
+
throw new TheoremError('config', 'a trial needs at least one trace record'); // labels-exempt: developer contract error
|
|
41
|
+
}
|
|
42
|
+
return { ...first, content: Object.assign({}, ...records.map((record) => record.content)) };
|
|
43
|
+
}
|
|
44
|
+
function numberAttribute(span, key) {
|
|
45
|
+
const value = span.attributes[key];
|
|
46
|
+
return typeof value === 'number' ? value : undefined;
|
|
47
|
+
}
|
|
48
|
+
function isObject(value) {
|
|
49
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
function isMessageList(value) {
|
|
52
|
+
return Array.isArray(value) && value.every(isObject);
|
|
53
|
+
}
|
|
54
|
+
function usageOf(root) {
|
|
55
|
+
const input = numberAttribute(root, 'gen_ai.usage.input_tokens') ?? 0;
|
|
56
|
+
const output = numberAttribute(root, 'gen_ai.usage.output_tokens') ?? 0;
|
|
57
|
+
const thinking = numberAttribute(root, 'gen_ai.usage.reasoning.output_tokens');
|
|
58
|
+
const cached = numberAttribute(root, 'gen_ai.usage.cache_read.input_tokens');
|
|
59
|
+
const cacheWrite = numberAttribute(root, 'gen_ai.usage.cache_write.input_tokens');
|
|
60
|
+
const toolUse = numberAttribute(root, 'theorem.usage.tool_use.input_tokens');
|
|
61
|
+
const costUsd = numberAttribute(root, 'theorem.usage.cost_usd');
|
|
62
|
+
const partial = root.attributes['theorem.usage.cost_partial'] === true;
|
|
63
|
+
const estimated = root.attributes['theorem.usage.estimated'];
|
|
64
|
+
const tokens = {
|
|
65
|
+
input,
|
|
66
|
+
output,
|
|
67
|
+
total: input + output,
|
|
68
|
+
...(thinking === undefined ? {} : { thinking }),
|
|
69
|
+
...(cached === undefined ? {} : { cached }),
|
|
70
|
+
...(cacheWrite === undefined ? {} : { cacheWrite }),
|
|
71
|
+
...(toolUse === undefined ? {} : { toolUse }),
|
|
72
|
+
...(costUsd === undefined
|
|
73
|
+
? {}
|
|
74
|
+
: { cost: { usd: costUsd, ...(partial ? { partial: true } : {}) } }),
|
|
75
|
+
...(Array.isArray(estimated)
|
|
76
|
+
? {
|
|
77
|
+
estimated: estimated.flatMap((side) => side === 'input' || side === 'output' ? [side] : []),
|
|
78
|
+
}
|
|
79
|
+
: {}),
|
|
80
|
+
};
|
|
81
|
+
return costUsd === undefined ? { tokens } : { tokens, costUsd };
|
|
82
|
+
}
|
|
83
|
+
/** A turn's root carries `gen_ai.output.messages`; a Live session's root carries none, and each response span carries its own `theorem.output.delivered`. */
|
|
84
|
+
function deliveredOf(root, spans) {
|
|
85
|
+
const own = root.attributes['gen_ai.output.messages'];
|
|
86
|
+
if (isMessageList(own))
|
|
87
|
+
return own;
|
|
88
|
+
return spans
|
|
89
|
+
.filter((span) => 'theorem.request.live' in span.attributes)
|
|
90
|
+
.flatMap((span) => {
|
|
91
|
+
const delivered = span.attributes['theorem.output.delivered'];
|
|
92
|
+
return isMessageList(delivered) ? delivered : [];
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** 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. */
|
|
96
|
+
function buildTrial(args) {
|
|
97
|
+
const merged = mergedRecord(args.records);
|
|
98
|
+
const spans = allSpans(args.records);
|
|
99
|
+
const byId = new Map(spans.map((span) => [span.spanId, span]));
|
|
100
|
+
const root = rootOf(spans, byId);
|
|
101
|
+
return {
|
|
102
|
+
suite: args.suite,
|
|
103
|
+
...(args.case ? { case: args.case } : {}),
|
|
104
|
+
index: args.index,
|
|
105
|
+
records: args.records,
|
|
106
|
+
root,
|
|
107
|
+
top: ancestorsOf(root, byId).at(-1) ?? root,
|
|
108
|
+
spans: (operation) => spans.filter((span) => operationOf(span) === operation),
|
|
109
|
+
children: (parent) => spans.filter((span) => span.parentSpanId === parent.spanId),
|
|
110
|
+
content: (value) => inlineContent(merged, value),
|
|
111
|
+
text: (value) => (isObject(value) ? contentOf(merged, value) : undefined),
|
|
112
|
+
delivered: () => deliveredOf(root, spans),
|
|
113
|
+
usage: () => usageOf(root),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Groups trace records by the trace id of their first span; records with no spans are dropped. */
|
|
117
|
+
function groupByTrace(records) {
|
|
118
|
+
const groups = new Map();
|
|
119
|
+
for (const record of records) {
|
|
120
|
+
const traceId = record.spans[0]?.traceId;
|
|
121
|
+
if (traceId === undefined)
|
|
122
|
+
continue;
|
|
123
|
+
const group = groups.get(traceId);
|
|
124
|
+
if (group)
|
|
125
|
+
group.push(record);
|
|
126
|
+
else
|
|
127
|
+
groups.set(traceId, [record]);
|
|
128
|
+
}
|
|
129
|
+
return groups;
|
|
130
|
+
}
|
|
131
|
+
/** True when any record holds an `invoke_agent` span, meaning an agent turn ran. */
|
|
132
|
+
function hasTurn(records) {
|
|
133
|
+
return records.some((record) => record.spans.some((span) => operationOf(span) === 'invoke_agent'));
|
|
134
|
+
}
|
|
135
|
+
export { buildTrial, groupByTrace, hasTurn };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { RunDecisionOptions } from '../kernel/engine/decision.js';
|
|
3
|
+
import type { ProviderHostOptions } from '../kernel/protocols/runtime.js';
|
|
4
|
+
import type { TurnTokens } from '../kernel/turn-events.js';
|
|
5
|
+
import type { TraceRecord } from '../observability/trace-record.js';
|
|
6
|
+
import type { TraceAttributeValue, TraceSpan } from '../observability/trace-span.js';
|
|
7
|
+
/** Whether a case probes what the profile can do (`capability`) or guards what it already did (`regression`). */
|
|
8
|
+
export type EvalCaseKind = 'capability' | 'regression';
|
|
9
|
+
/** An attachment carried in the case file as base64. */
|
|
10
|
+
export interface EvalInlineAttachment {
|
|
11
|
+
mimeType: string;
|
|
12
|
+
/** Base64 bytes. */
|
|
13
|
+
data: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
}
|
|
16
|
+
/** A file attachment is pinned by the hex SHA-256 of its bytes; a file whose bytes hash otherwise is refused. */
|
|
17
|
+
export interface EvalFileAttachment {
|
|
18
|
+
mimeType: string;
|
|
19
|
+
path: string;
|
|
20
|
+
sha256: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
/** An attachment a case sends: inline bytes or a file on disk. */
|
|
24
|
+
export type EvalAttachment = EvalInlineAttachment | EvalFileAttachment;
|
|
25
|
+
/** A single-turn case input. */
|
|
26
|
+
export interface EvalTurnInput {
|
|
27
|
+
text?: string;
|
|
28
|
+
attachments?: EvalAttachment[];
|
|
29
|
+
}
|
|
30
|
+
/** One message of a session case, sent once the previous step's turn completes. */
|
|
31
|
+
export interface EvalSessionStep {
|
|
32
|
+
text: string;
|
|
33
|
+
until: 'turn_complete';
|
|
34
|
+
}
|
|
35
|
+
/** A multi-step session case input. */
|
|
36
|
+
export interface EvalSessionInput {
|
|
37
|
+
session: {
|
|
38
|
+
steps: EvalSessionStep[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** A case input: one turn or a session. */
|
|
42
|
+
export type EvalCaseInput = EvalTurnInput | EvalSessionInput;
|
|
43
|
+
/** Only an `accepted` name passes; a `partial` one is close but not enough; a `rejected` one named beside an accepted name makes the reply `partial`, not a pass. */
|
|
44
|
+
export interface EvalAnswer {
|
|
45
|
+
accepted: string[];
|
|
46
|
+
partial?: string[];
|
|
47
|
+
rejected?: string[];
|
|
48
|
+
reference?: string;
|
|
49
|
+
}
|
|
50
|
+
/** What a case expects: tools, JSON fields, a transcription, or an answer. */
|
|
51
|
+
export interface EvalExpect {
|
|
52
|
+
tools?: string[];
|
|
53
|
+
json?: Record<string, unknown>;
|
|
54
|
+
transcription?: {
|
|
55
|
+
includes?: string;
|
|
56
|
+
regex?: string;
|
|
57
|
+
};
|
|
58
|
+
answer?: EvalAnswer;
|
|
59
|
+
notes?: string;
|
|
60
|
+
}
|
|
61
|
+
/** How hard a case is, from 1 to 5. */
|
|
62
|
+
export type EvalDifficulty = 1 | 2 | 3 | 4 | 5;
|
|
63
|
+
/** One eval case: its input and what the reply is expected to be. */
|
|
64
|
+
export interface EvalCase {
|
|
65
|
+
id: string;
|
|
66
|
+
kind: EvalCaseKind;
|
|
67
|
+
difficulty?: EvalDifficulty;
|
|
68
|
+
input: EvalCaseInput;
|
|
69
|
+
expect?: EvalExpect;
|
|
70
|
+
tags?: string[];
|
|
71
|
+
}
|
|
72
|
+
/** The schema an eval case parses against. */
|
|
73
|
+
export declare const evalCaseSchema: z.ZodType<EvalCase>;
|
|
74
|
+
/** The operation a trace span records. */
|
|
75
|
+
export type TraceOperation = 'invoke_agent' | 'chat' | 'generate_content' | 'execute_tool';
|
|
76
|
+
/** A message as the trace stores it: `{ role, parts: [...] }`, parts by hash; resolve them with `text` / `content`. */
|
|
77
|
+
export type TrialMessage = Record<string, TraceAttributeValue>;
|
|
78
|
+
/** Tokens and cost a trial used. */
|
|
79
|
+
export interface TrialUsage {
|
|
80
|
+
tokens: TurnTokens;
|
|
81
|
+
costUsd?: number;
|
|
82
|
+
}
|
|
83
|
+
/** A grader receives the trace records that share the trial's trace id and nothing else; if it needs a fact the trace does not hold, the trace is wrong, not the grader. */
|
|
84
|
+
export interface Trial {
|
|
85
|
+
suite: string;
|
|
86
|
+
case?: EvalCase;
|
|
87
|
+
index: number;
|
|
88
|
+
records: TraceRecord[];
|
|
89
|
+
root: TraceSpan;
|
|
90
|
+
/** The topmost span above `root`: the host's own span when the host nested the turn under it, else `root`. Its length is the trial's time. */
|
|
91
|
+
top: TraceSpan;
|
|
92
|
+
spans: (operation: TraceOperation) => TraceSpan[];
|
|
93
|
+
children: (span: TraceSpan) => TraceSpan[];
|
|
94
|
+
content: (value: unknown) => unknown;
|
|
95
|
+
text: (value: unknown) => string | undefined;
|
|
96
|
+
delivered: () => TrialMessage[];
|
|
97
|
+
usage: () => TrialUsage;
|
|
98
|
+
}
|
|
99
|
+
/** Whether a result came from code or from a model. */
|
|
100
|
+
export type EvalResultSource = 'code' | 'model';
|
|
101
|
+
/** One grader's verdict on a trial: a score, a label, and why. */
|
|
102
|
+
export interface EvalResult {
|
|
103
|
+
name: string;
|
|
104
|
+
source: EvalResultSource;
|
|
105
|
+
score?: {
|
|
106
|
+
value?: number;
|
|
107
|
+
label?: string;
|
|
108
|
+
};
|
|
109
|
+
explanation?: string;
|
|
110
|
+
/** Whether this result counts as a pass. Absent: informational only. */
|
|
111
|
+
passed?: boolean;
|
|
112
|
+
/** Why no score could be produced; the result is then a failed one. */
|
|
113
|
+
errorType?: string;
|
|
114
|
+
judgeTraceparents?: string[];
|
|
115
|
+
}
|
|
116
|
+
/** The schema an eval result parses against. */
|
|
117
|
+
export declare const evalResultSchema: z.ZodType<EvalResult>;
|
|
118
|
+
/** How many trials of a case must pass for the case to pass. */
|
|
119
|
+
export type EvalPassRule = 'all' | 'any' | {
|
|
120
|
+
atLeast: number;
|
|
121
|
+
};
|
|
122
|
+
/** How often a case runs, and the rule across those runs. */
|
|
123
|
+
export interface EvalTrials {
|
|
124
|
+
/** Trials per case. No default: it is a cost decision, so the suite states it. `1` cannot tell noise from change. */
|
|
125
|
+
repeat: number;
|
|
126
|
+
pass?: EvalPassRule;
|
|
127
|
+
}
|
|
128
|
+
/** What a grader gets besides the trial: the judge model and its trace parent. */
|
|
129
|
+
export interface EvalGradeContext {
|
|
130
|
+
judge?: string;
|
|
131
|
+
judgeProvider?: ProviderHostOptions;
|
|
132
|
+
judgeDecision?: Omit<RunDecisionOptions, 'sink'>;
|
|
133
|
+
/** The trial span as a W3C `traceparent`: a judge call runs under it, so it lands in the judged trace beneath the trial. Absent, each judge call starts a trace of its own. */
|
|
134
|
+
traceparent?: string;
|
|
135
|
+
media?: EvalMediaResolver;
|
|
136
|
+
traced: (records: TraceRecord[]) => void | Promise<void>;
|
|
137
|
+
signal?: AbortSignal;
|
|
138
|
+
}
|
|
139
|
+
/** Media a trace names by the sha256 (hex) of its raw bytes. */
|
|
140
|
+
export interface EvalMediaRef {
|
|
141
|
+
sha256: string;
|
|
142
|
+
mimeType: string;
|
|
143
|
+
}
|
|
144
|
+
/** The media's bytes as base64, or `undefined` when the host does not have them. */
|
|
145
|
+
export type EvalMediaResolver = (ref: EvalMediaRef) => string | undefined | Promise<string | undefined>;
|
|
146
|
+
/** Grades one trial of a case, from its trace. */
|
|
147
|
+
export interface EvalGrader {
|
|
148
|
+
name: string;
|
|
149
|
+
/** Stable text naming exactly what this grader checks; its sha256 is written as `theorem.evaluation.grader.version`, so a later reader can tell which rubric produced which score. */
|
|
150
|
+
identity: string;
|
|
151
|
+
source: EvalResultSource;
|
|
152
|
+
needsExpect: boolean;
|
|
153
|
+
judgeProfiles?: (suiteJudge: string | undefined) => string[];
|
|
154
|
+
grade: (trial: Trial, context: EvalGradeContext) => EvalResult | Promise<EvalResult>;
|
|
155
|
+
}
|
|
156
|
+
/** A suite: a profile, a mode, a cases file, and the graders to run. */
|
|
157
|
+
export interface EvalSuite {
|
|
158
|
+
id: string;
|
|
159
|
+
profile: string;
|
|
160
|
+
mode: 'turn' | 'session';
|
|
161
|
+
cases: string;
|
|
162
|
+
trials: EvalTrials;
|
|
163
|
+
graders: EvalGrader[];
|
|
164
|
+
judge?: {
|
|
165
|
+
profile: string;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/** The schema an eval suite parses against. */
|
|
169
|
+
export declare const evalSuiteSchema: z.ZodType<EvalSuite>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isRecord } from '../kernel/util/record.js';
|
|
3
|
+
const evalCaseKind = z.enum(['capability', 'regression']);
|
|
4
|
+
true;
|
|
5
|
+
const evalInlineAttachment = z.object({
|
|
6
|
+
mimeType: z.string(),
|
|
7
|
+
data: z.string(),
|
|
8
|
+
name: z.string().optional(),
|
|
9
|
+
});
|
|
10
|
+
true;
|
|
11
|
+
const evalFileAttachment = z.object({
|
|
12
|
+
mimeType: z.string(),
|
|
13
|
+
path: z.string().min(1),
|
|
14
|
+
sha256: z.string().regex(/^[0-9a-f]{64}$/, 'must be a lowercase hex SHA-256'),
|
|
15
|
+
name: z.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
true;
|
|
18
|
+
const evalAttachment = z.union([evalInlineAttachment, evalFileAttachment]);
|
|
19
|
+
true;
|
|
20
|
+
const evalTurnInput = z.object({
|
|
21
|
+
text: z.string().optional(),
|
|
22
|
+
attachments: z.array(evalAttachment).optional(),
|
|
23
|
+
});
|
|
24
|
+
true;
|
|
25
|
+
const evalSessionStep = z.object({ text: z.string(), until: z.literal('turn_complete') });
|
|
26
|
+
true;
|
|
27
|
+
const evalSessionInput = z.object({ session: z.object({ steps: z.array(evalSessionStep) }) });
|
|
28
|
+
true;
|
|
29
|
+
const evalCaseInput = z.union([evalSessionInput, evalTurnInput]);
|
|
30
|
+
true;
|
|
31
|
+
const evalAnswer = z.object({
|
|
32
|
+
accepted: z.array(z.string().min(1)).min(1),
|
|
33
|
+
partial: z.array(z.string().min(1)).optional(),
|
|
34
|
+
rejected: z.array(z.string().min(1)).optional(),
|
|
35
|
+
reference: z.string().optional(),
|
|
36
|
+
});
|
|
37
|
+
true;
|
|
38
|
+
const evalExpect = z.object({
|
|
39
|
+
tools: z.array(z.string()).optional(),
|
|
40
|
+
json: z.record(z.string(), z.unknown()).optional(),
|
|
41
|
+
transcription: z
|
|
42
|
+
.object({ includes: z.string().optional(), regex: z.string().optional() })
|
|
43
|
+
.optional(),
|
|
44
|
+
answer: evalAnswer.optional(),
|
|
45
|
+
notes: z.string().optional(),
|
|
46
|
+
});
|
|
47
|
+
true;
|
|
48
|
+
const evalDifficulty = z.union([
|
|
49
|
+
z.literal(1),
|
|
50
|
+
z.literal(2),
|
|
51
|
+
z.literal(3),
|
|
52
|
+
z.literal(4),
|
|
53
|
+
z.literal(5),
|
|
54
|
+
]);
|
|
55
|
+
true;
|
|
56
|
+
const evalCase = z.object({
|
|
57
|
+
id: z.string().min(1),
|
|
58
|
+
kind: evalCaseKind,
|
|
59
|
+
difficulty: evalDifficulty.optional(),
|
|
60
|
+
input: evalCaseInput,
|
|
61
|
+
expect: evalExpect.optional(),
|
|
62
|
+
tags: z.array(z.string()).optional(),
|
|
63
|
+
});
|
|
64
|
+
true;
|
|
65
|
+
/** The schema an eval case parses against. */
|
|
66
|
+
export const evalCaseSchema = evalCase;
|
|
67
|
+
const evalResultSource = z.enum(['code', 'model']);
|
|
68
|
+
true;
|
|
69
|
+
const evalResult = z.object({
|
|
70
|
+
name: z.string().min(1),
|
|
71
|
+
source: evalResultSource,
|
|
72
|
+
score: z.object({ value: z.number().optional(), label: z.string().optional() }).optional(),
|
|
73
|
+
explanation: z.string().optional(),
|
|
74
|
+
passed: z.boolean().optional(),
|
|
75
|
+
errorType: z.string().optional(),
|
|
76
|
+
judgeTraceparents: z.array(z.string()).optional(),
|
|
77
|
+
});
|
|
78
|
+
true;
|
|
79
|
+
/** The schema an eval result parses against. */
|
|
80
|
+
export const evalResultSchema = evalResult;
|
|
81
|
+
const evalPassRule = z.union([
|
|
82
|
+
z.literal('all'),
|
|
83
|
+
z.literal('any'),
|
|
84
|
+
z.object({ atLeast: z.number().int().min(1) }),
|
|
85
|
+
]);
|
|
86
|
+
true;
|
|
87
|
+
const evalTrials = z.object({
|
|
88
|
+
repeat: z.number().int().min(1),
|
|
89
|
+
pass: evalPassRule.optional(),
|
|
90
|
+
});
|
|
91
|
+
true;
|
|
92
|
+
function isGrader(value) {
|
|
93
|
+
return (isRecord(value) &&
|
|
94
|
+
typeof value.name === 'string' &&
|
|
95
|
+
typeof value.identity === 'string' &&
|
|
96
|
+
(value.source === 'code' || value.source === 'model') &&
|
|
97
|
+
typeof value.needsExpect === 'boolean' &&
|
|
98
|
+
(value.judgeProfiles === undefined || typeof value.judgeProfiles === 'function') &&
|
|
99
|
+
typeof value.grade === 'function');
|
|
100
|
+
}
|
|
101
|
+
const evalGrader = z.custom(isGrader);
|
|
102
|
+
const evalSuite = z.object({
|
|
103
|
+
id: z.string().min(1),
|
|
104
|
+
profile: z.string().min(1),
|
|
105
|
+
mode: z.enum(['turn', 'session']),
|
|
106
|
+
cases: z.string().min(1),
|
|
107
|
+
trials: evalTrials,
|
|
108
|
+
graders: z.array(evalGrader),
|
|
109
|
+
judge: z.object({ profile: z.string().min(1) }).optional(),
|
|
110
|
+
});
|
|
111
|
+
true;
|
|
112
|
+
/** The schema an eval suite parses against. */
|
|
113
|
+
export const evalSuiteSchema = evalSuite;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EvalCase, EvalPassRule, EvalResult } from './types.js';
|
|
2
|
+
/** How a trial ended: passed, failed, errored, or ungraded. */
|
|
3
|
+
type TrialOutcome = 'passed' | 'failed' | 'errored' | 'ungraded';
|
|
4
|
+
/** The outcome of a trial from its results. */
|
|
5
|
+
declare function trialOutcome(results: readonly EvalResult[]): TrialOutcome;
|
|
6
|
+
/** A case's verdict across its trials, under the pass rule. */
|
|
7
|
+
interface CaseVerdict {
|
|
8
|
+
case: string;
|
|
9
|
+
kind: EvalCase['kind'];
|
|
10
|
+
difficulty?: EvalCase['difficulty'];
|
|
11
|
+
passed: boolean;
|
|
12
|
+
decided: boolean;
|
|
13
|
+
trials: number;
|
|
14
|
+
trialsPassed: number;
|
|
15
|
+
trialsErrored: number;
|
|
16
|
+
trialsUngraded: number;
|
|
17
|
+
}
|
|
18
|
+
/** The name of a pass rule, as the trace records it. */
|
|
19
|
+
declare function passRuleName(rule: EvalPassRule): 'all' | 'any' | 'at_least';
|
|
20
|
+
/** The verdict of a case from its trials' results. */
|
|
21
|
+
declare function caseVerdict(evalCase: EvalCase, trials: readonly (readonly EvalResult[])[], rule?: EvalPassRule): CaseVerdict;
|
|
22
|
+
export type { CaseVerdict, TrialOutcome };
|
|
23
|
+
export { caseVerdict, passRuleName, trialOutcome };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** The outcome of a trial from its results. */
|
|
2
|
+
function trialOutcome(results) {
|
|
3
|
+
if (results.some((result) => result.errorType !== undefined))
|
|
4
|
+
return 'errored';
|
|
5
|
+
const decided = results.filter((result) => result.passed !== undefined);
|
|
6
|
+
if (decided.length === 0)
|
|
7
|
+
return 'ungraded';
|
|
8
|
+
return decided.every((result) => result.passed) ? 'passed' : 'failed';
|
|
9
|
+
}
|
|
10
|
+
function ruleMet(rule, passed, trials) {
|
|
11
|
+
if (trials === 0)
|
|
12
|
+
return false;
|
|
13
|
+
if (rule === 'all')
|
|
14
|
+
return passed === trials;
|
|
15
|
+
if (rule === 'any')
|
|
16
|
+
return passed >= 1;
|
|
17
|
+
return passed >= rule.atLeast;
|
|
18
|
+
}
|
|
19
|
+
function trialsNeeded(rule) {
|
|
20
|
+
return typeof rule === 'object' ? rule.atLeast : 1;
|
|
21
|
+
}
|
|
22
|
+
/** The name of a pass rule, as the trace records it. */
|
|
23
|
+
function passRuleName(rule) {
|
|
24
|
+
return typeof rule === 'string' ? rule : 'at_least';
|
|
25
|
+
}
|
|
26
|
+
// why: An errored trial is one that could not be graded (a provider error, a judge that failed), so the rule reads it as a trial that never ran: a rate limit never counts against the agent.
|
|
27
|
+
/** The verdict of a case from its trials' results. */
|
|
28
|
+
function caseVerdict(evalCase, trials, rule = 'all') {
|
|
29
|
+
const outcomes = trials.map(trialOutcome);
|
|
30
|
+
const count = (outcome) => outcomes.filter((o) => o === outcome).length;
|
|
31
|
+
const trialsPassed = count('passed');
|
|
32
|
+
const trialsErrored = count('errored');
|
|
33
|
+
const trialsUngraded = count('ungraded');
|
|
34
|
+
const ran = outcomes.length - trialsErrored;
|
|
35
|
+
const passed = trialsUngraded < ran && ruleMet(rule, trialsPassed, ran);
|
|
36
|
+
return {
|
|
37
|
+
case: evalCase.id,
|
|
38
|
+
kind: evalCase.kind,
|
|
39
|
+
...(evalCase.difficulty === undefined ? {} : { difficulty: evalCase.difficulty }),
|
|
40
|
+
passed,
|
|
41
|
+
decided: passed || trialsErrored === 0 || ran >= trialsNeeded(rule),
|
|
42
|
+
trials: outcomes.length,
|
|
43
|
+
trialsPassed,
|
|
44
|
+
trialsErrored,
|
|
45
|
+
trialsUngraded,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export { caseVerdict, passRuleName, trialOutcome };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** labels-exempt-file: authoring labels and descriptions for boundaries — not runtime user or model copy (P2) */
|
|
2
|
+
/** A record with one entry per key, typed by the keys it was built from. */
|
|
3
|
+
declare function recordOf<K extends string, V>(keys: readonly K[], value: (key: K) => V): Record<K, V>;
|
|
4
|
+
/**
|
|
5
|
+
* The kinds of tool whose text the kernel reads, in the words a builder writes as a tool's
|
|
6
|
+
* `type`. A provider builtin has none: the provider runs it and the kernel never reads its text.
|
|
7
|
+
*/
|
|
8
|
+
declare const TOOL_KINDS: readonly ["function", "http", "mcp", "agent"];
|
|
9
|
+
/** One of {@linkcode TOOL_KINDS}. */
|
|
10
|
+
type ToolKind = (typeof TOOL_KINDS)[number];
|
|
11
|
+
/**
|
|
12
|
+
* The places a tool's text crosses: what the model sends, what comes back to it, its error text,
|
|
13
|
+
* and what the call shows the person (its output, error, artifacts, and trace on the turn's events).
|
|
14
|
+
*/
|
|
15
|
+
declare const TOOL_CROSSINGS: readonly ["tool_arguments", "tool_output", "tool_failure", "tool_shown"];
|
|
16
|
+
/** One of {@linkcode TOOL_CROSSINGS}. */
|
|
17
|
+
type ToolCrossing = (typeof TOOL_CROSSINGS)[number];
|
|
18
|
+
/** A tool crossing for one kind of tool, such as `tool_output_mcp`. */
|
|
19
|
+
type ToolBoundary = `${ToolCrossing}_${ToolKind}`;
|
|
20
|
+
/** The boundary where `crossing` happens for a `kind` tool. */
|
|
21
|
+
declare function toolBoundary<C extends ToolCrossing, K extends ToolKind>(crossing: C, kind: K): `${C}_${K}`;
|
|
22
|
+
/** Every tool boundary, each crossing in turn for every kind of tool. */
|
|
23
|
+
declare const TOOL_BOUNDARIES: readonly ToolBoundary[];
|
|
24
|
+
/** Where text reaches the model from the person or the host. */
|
|
25
|
+
declare const INBOUND_BOUNDARIES: readonly ["user", "attachment", "voice", "slots", "context", "history", "injected", "system", "repair", "live_user"];
|
|
26
|
+
/** Where the model's own text reaches the person. */
|
|
27
|
+
declare const OUTBOUND_BOUNDARIES: readonly ["reply", "reply_structured", "live_reply", "thought"];
|
|
28
|
+
/** Every place the kernel reads text as it crosses, in the order a turn meets them. */
|
|
29
|
+
declare const BOUNDARIES: readonly ["user", "attachment", "voice", "slots", "context", "history", "injected", "system", "repair", "live_user", ...("tool_arguments_function" | "tool_arguments_http" | "tool_arguments_mcp" | "tool_arguments_agent" | "tool_output_function" | "tool_output_http" | "tool_output_mcp" | "tool_output_agent" | "tool_failure_function" | "tool_failure_http" | "tool_failure_mcp" | "tool_failure_agent" | "tool_shown_function" | "tool_shown_http" | "tool_shown_mcp" | "tool_shown_agent")[], "reply", "reply_structured", "live_reply", "thought"];
|
|
30
|
+
/** One of {@linkcode BOUNDARIES}. */
|
|
31
|
+
type Boundary = (typeof BOUNDARIES)[number];
|
|
32
|
+
/** How a boundary is named and described to a builder. */
|
|
33
|
+
interface BoundaryMeta {
|
|
34
|
+
label: string;
|
|
35
|
+
/** What is read there. */
|
|
36
|
+
doc: string;
|
|
37
|
+
}
|
|
38
|
+
/** The label and description of every boundary. */
|
|
39
|
+
declare const BOUNDARY_META: Readonly<Record<Boundary, BoundaryMeta>>;
|
|
40
|
+
export type { Boundary, BoundaryMeta, ToolBoundary, ToolCrossing, ToolKind };
|
|
41
|
+
export { BOUNDARIES, BOUNDARY_META, INBOUND_BOUNDARIES, OUTBOUND_BOUNDARIES, recordOf, TOOL_BOUNDARIES, TOOL_KINDS, toolBoundary, };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// invariant: Leaf module. Imports nothing from `src/guardrails/types.ts` or `src/kernel/`, so the
|
|
2
|
+
// vocabulary can be read by every layer without a cycle.
|
|
3
|
+
/** labels-exempt-file: authoring labels and descriptions for boundaries — not runtime user or model copy (P2) */
|
|
4
|
+
/** A record with one entry per key, typed by the keys it was built from. */
|
|
5
|
+
function recordOf(keys, value) {
|
|
6
|
+
return Object.fromEntries(keys.map((key) => [key, value(key)]));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The kinds of tool whose text the kernel reads, in the words a builder writes as a tool's
|
|
10
|
+
* `type`. A provider builtin has none: the provider runs it and the kernel never reads its text.
|
|
11
|
+
*/
|
|
12
|
+
const TOOL_KINDS = ['function', 'http', 'mcp', 'agent'];
|
|
13
|
+
/**
|
|
14
|
+
* The places a tool's text crosses: what the model sends, what comes back to it, its error text,
|
|
15
|
+
* and what the call shows the person (its output, error, artifacts, and trace on the turn's events).
|
|
16
|
+
*/
|
|
17
|
+
const TOOL_CROSSINGS = ['tool_arguments', 'tool_output', 'tool_failure', 'tool_shown'];
|
|
18
|
+
/** The boundary where `crossing` happens for a `kind` tool. */
|
|
19
|
+
function toolBoundary(crossing, kind) {
|
|
20
|
+
return `${crossing}_${kind}`;
|
|
21
|
+
}
|
|
22
|
+
/** Every tool boundary, each crossing in turn for every kind of tool. */
|
|
23
|
+
const TOOL_BOUNDARIES = TOOL_CROSSINGS.flatMap((crossing) => TOOL_KINDS.map((kind) => toolBoundary(crossing, kind)));
|
|
24
|
+
/** Where text reaches the model from the person or the host. */
|
|
25
|
+
const INBOUND_BOUNDARIES = [
|
|
26
|
+
'user',
|
|
27
|
+
'attachment',
|
|
28
|
+
'voice',
|
|
29
|
+
'slots',
|
|
30
|
+
'context',
|
|
31
|
+
'history',
|
|
32
|
+
'injected',
|
|
33
|
+
'system',
|
|
34
|
+
'repair',
|
|
35
|
+
'live_user',
|
|
36
|
+
];
|
|
37
|
+
/** Where the model's own text reaches the person. */
|
|
38
|
+
const OUTBOUND_BOUNDARIES = ['reply', 'reply_structured', 'live_reply', 'thought'];
|
|
39
|
+
/** Every place the kernel reads text as it crosses, in the order a turn meets them. */
|
|
40
|
+
const BOUNDARIES = [
|
|
41
|
+
...INBOUND_BOUNDARIES,
|
|
42
|
+
...TOOL_BOUNDARIES,
|
|
43
|
+
...OUTBOUND_BOUNDARIES,
|
|
44
|
+
];
|
|
45
|
+
const TOOL_KIND_LABELS = {
|
|
46
|
+
function: 'function',
|
|
47
|
+
http: 'HTTP',
|
|
48
|
+
mcp: 'MCP',
|
|
49
|
+
agent: 'agent',
|
|
50
|
+
};
|
|
51
|
+
const TOOL_CROSSING_META = {
|
|
52
|
+
tool_arguments: (kind) => ({
|
|
53
|
+
label: `Arguments to ${kind} tools`,
|
|
54
|
+
doc: `What the model sends to a tool of type ${kind}.`,
|
|
55
|
+
}),
|
|
56
|
+
tool_output: (kind) => ({
|
|
57
|
+
label: `Output of ${kind} tools`,
|
|
58
|
+
doc: `What a tool of type ${kind} returns.`,
|
|
59
|
+
}),
|
|
60
|
+
tool_failure: (kind) => ({
|
|
61
|
+
label: `Errors from ${kind} tools`,
|
|
62
|
+
doc: `The error text of a tool of type ${kind} that failed.`,
|
|
63
|
+
}),
|
|
64
|
+
tool_shown: (kind) => ({
|
|
65
|
+
label: `Shown from ${kind} tools`,
|
|
66
|
+
doc: `What a call to a tool of type ${kind} shows the person: its output, error, artifacts, and trace.`,
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
function toolBoundaryMeta() {
|
|
70
|
+
const entries = TOOL_CROSSINGS.flatMap((crossing) => TOOL_KINDS.map((kind) => [
|
|
71
|
+
toolBoundary(crossing, kind),
|
|
72
|
+
TOOL_CROSSING_META[crossing](TOOL_KIND_LABELS[kind]),
|
|
73
|
+
]));
|
|
74
|
+
return Object.fromEntries(entries);
|
|
75
|
+
}
|
|
76
|
+
/** The label and description of every boundary. */
|
|
77
|
+
const BOUNDARY_META = {
|
|
78
|
+
user: { label: 'User message', doc: 'The message the person typed.' },
|
|
79
|
+
attachment: { label: 'Attachments', doc: 'The text of a file the person attached.' },
|
|
80
|
+
voice: { label: 'Voice', doc: 'The transcript of what the person said.' },
|
|
81
|
+
slots: { label: 'Slots', doc: 'The values the host fills into the prompt.' },
|
|
82
|
+
context: { label: 'Context', doc: 'What the page or the host tells the model to know.' },
|
|
83
|
+
history: { label: 'History', doc: 'Earlier messages the host replays.' },
|
|
84
|
+
injected: { label: 'Stage messages', doc: 'Messages a host stage adds during the turn.' },
|
|
85
|
+
system: {
|
|
86
|
+
label: 'Turn system text',
|
|
87
|
+
doc: 'Text the host adds to the system instruction for one turn.',
|
|
88
|
+
},
|
|
89
|
+
repair: {
|
|
90
|
+
label: 'Repair',
|
|
91
|
+
doc: 'A stopped reply and the reason, handed back to the model to try again.',
|
|
92
|
+
},
|
|
93
|
+
live_user: { label: 'Live message', doc: 'Text the person sends in a Live session.' },
|
|
94
|
+
...toolBoundaryMeta(),
|
|
95
|
+
reply: { label: 'Reply', doc: 'The text the model says to the person.' },
|
|
96
|
+
reply_structured: {
|
|
97
|
+
label: 'Structured reply',
|
|
98
|
+
doc: 'The structured output the model returns.',
|
|
99
|
+
},
|
|
100
|
+
live_reply: { label: 'Live reply', doc: 'What the model says in a Live session.' },
|
|
101
|
+
thought: { label: 'Thoughts', doc: "The model's reasoning, where the host shows it." },
|
|
102
|
+
};
|
|
103
|
+
export { BOUNDARIES, BOUNDARY_META, INBOUND_BOUNDARIES, OUTBOUND_BOUNDARIES, recordOf, TOOL_BOUNDARIES, TOOL_KINDS, toolBoundary, };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TurnEvent } from '../kernel/types.js';
|
|
2
|
+
import { type CanaryStreamGate } from './canary.js';
|
|
3
|
+
/** A canary leak gate for one reply: the turn canary, the system prompt to catch echoes of, and the stream gate that holds text back. */
|
|
4
|
+
export interface CanaryGateSession {
|
|
5
|
+
canary: string;
|
|
6
|
+
/** The system prompt as sent, when replies echoing it are leaks too. */
|
|
7
|
+
privateSystem?: readonly string[];
|
|
8
|
+
gate: CanaryStreamGate;
|
|
9
|
+
}
|
|
10
|
+
/** Pass the system prompt as sent to catch replies that echo it, as `runTurn` and Live do. */
|
|
11
|
+
declare function createCanaryGateSession(canary: string, privateSystem?: readonly string[]): CanaryGateSession;
|
|
12
|
+
/**
|
|
13
|
+
* Canary-only batch filter for hosts that need stream lookback without full egress. Stops at the
|
|
14
|
+
* first leak, so no unsafe event is returned; thoughts are unguarded (`isGuardedOutput`).
|
|
15
|
+
*/
|
|
16
|
+
declare function filterCanaryGatedEvents(session: CanaryGateSession, events: TurnEvent[]): {
|
|
17
|
+
leaked: true;
|
|
18
|
+
} | {
|
|
19
|
+
leaked: false;
|
|
20
|
+
events: TurnEvent[];
|
|
21
|
+
};
|
|
22
|
+
export { createCanaryGateSession, filterCanaryGatedEvents };
|