@theoremjs/agents 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1264 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +65 -0
- package/esm/mod.js +42 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +458 -0
- package/esm/src/cli/commands/egress-compile.d.ts +17 -0
- package/esm/src/cli/commands/egress-compile.js +25 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +202 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +25 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +72 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +4 -0
- package/esm/src/evals/attachments.js +53 -0
- package/esm/src/evals/breakdown.d.ts +28 -0
- package/esm/src/evals/breakdown.js +68 -0
- package/esm/src/evals/graders/answer.d.ts +13 -0
- package/esm/src/evals/graders/answer.js +133 -0
- package/esm/src/evals/graders/code.d.ts +64 -0
- package/esm/src/evals/graders/code.js +205 -0
- package/esm/src/evals/graders/judge.d.ts +20 -0
- package/esm/src/evals/graders/judge.js +365 -0
- package/esm/src/evals/graders/latency.d.ts +5 -0
- package/esm/src/evals/graders/latency.js +81 -0
- package/esm/src/evals/graders/live.d.ts +11 -0
- package/esm/src/evals/graders/live.js +40 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +92 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +17 -0
- package/esm/src/evals/graders/transcript.js +200 -0
- package/esm/src/evals/mod.d.ts +42 -0
- package/esm/src/evals/mod.js +30 -0
- package/esm/src/evals/record.d.ts +35 -0
- package/esm/src/evals/record.js +105 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +118 -0
- package/esm/src/evals/run.js +452 -0
- package/esm/src/evals/suite.d.ts +19 -0
- package/esm/src/evals/suite.js +92 -0
- package/esm/src/evals/summary.d.ts +32 -0
- package/esm/src/evals/summary.js +30 -0
- package/esm/src/evals/trial.d.ts +27 -0
- package/esm/src/evals/trial.js +158 -0
- package/esm/src/evals/types.d.ts +260 -0
- package/esm/src/evals/types.js +126 -0
- package/esm/src/evals/verdict.d.ts +18 -0
- package/esm/src/evals/verdict.js +45 -0
- package/esm/src/guardrails/canary-gate.d.ts +21 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +112 -0
- package/esm/src/guardrails/canary.js +901 -0
- package/esm/src/guardrails/compile-egress.d.ts +11 -0
- package/esm/src/guardrails/compile-egress.js +11 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +22 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +303 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +202 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +3 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +118 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +13 -0
- package/esm/src/guardrails/corpus/live-attacks.js +224 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +32 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/egress-automata.d.ts +14 -0
- package/esm/src/guardrails/egress-automata.js +6059 -0
- package/esm/src/guardrails/egress-compiler.d.ts +33 -0
- package/esm/src/guardrails/egress-compiler.js +237 -0
- package/esm/src/guardrails/egress-patterns.d.ts +24 -0
- package/esm/src/guardrails/egress-patterns.js +32 -0
- package/esm/src/guardrails/egress-policy.d.ts +27 -0
- package/esm/src/guardrails/egress-policy.js +76 -0
- package/esm/src/guardrails/egress-rules.d.ts +54 -0
- package/esm/src/guardrails/egress-rules.js +49 -0
- package/esm/src/guardrails/egress-stream.d.ts +105 -0
- package/esm/src/guardrails/egress-stream.js +645 -0
- package/esm/src/guardrails/egress-urls.d.ts +83 -0
- package/esm/src/guardrails/egress-urls.js +917 -0
- package/esm/src/guardrails/egress.d.ts +106 -0
- package/esm/src/guardrails/egress.js +374 -0
- package/esm/src/guardrails/error.d.ts +26 -0
- package/esm/src/guardrails/error.js +91 -0
- package/esm/src/guardrails/event-schemas.d.ts +57 -0
- package/esm/src/guardrails/event-schemas.js +41 -0
- package/esm/src/guardrails/events.d.ts +9 -0
- package/esm/src/guardrails/events.js +42 -0
- package/esm/src/guardrails/hits.d.ts +8 -0
- package/esm/src/guardrails/hits.js +19 -0
- package/esm/src/guardrails/injection-patterns.d.ts +15 -0
- package/esm/src/guardrails/injection-patterns.js +94 -0
- package/esm/src/guardrails/injection.d.ts +14 -0
- package/esm/src/guardrails/injection.js +237 -0
- package/esm/src/guardrails/lexicon.d.ts +30 -0
- package/esm/src/guardrails/lexicon.js +478 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +54 -0
- package/esm/src/guardrails/live-outbound-gate.js +305 -0
- package/esm/src/guardrails/mod.d.ts +46 -0
- package/esm/src/guardrails/mod.js +29 -0
- package/esm/src/guardrails/network.d.ts +42 -0
- package/esm/src/guardrails/network.js +328 -0
- package/esm/src/guardrails/normalize.d.ts +6 -0
- package/esm/src/guardrails/normalize.js +132 -0
- package/esm/src/guardrails/policy.d.ts +19 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +69 -0
- package/esm/src/guardrails/progressive-yield.js +237 -0
- package/esm/src/guardrails/prompt-echo.d.ts +38 -0
- package/esm/src/guardrails/prompt-echo.js +225 -0
- package/esm/src/guardrails/quota.d.ts +20 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +56 -0
- package/esm/src/guardrails/rules.js +54 -0
- package/esm/src/guardrails/sanitize.d.ts +23 -0
- package/esm/src/guardrails/sanitize.js +184 -0
- package/esm/src/guardrails/sensitive.d.ts +29 -0
- package/esm/src/guardrails/sensitive.js +113 -0
- package/esm/src/guardrails/serialize.d.ts +14 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +9 -0
- package/esm/src/guardrails/testing.js +8 -0
- package/esm/src/guardrails/theorem-error.d.ts +18 -0
- package/esm/src/guardrails/theorem-error.js +53 -0
- package/esm/src/guardrails/thought-guard.d.ts +55 -0
- package/esm/src/guardrails/thought-guard.js +464 -0
- package/esm/src/guardrails/tool-directives.d.ts +19 -0
- package/esm/src/guardrails/tool-directives.js +109 -0
- package/esm/src/guardrails/tool-result.d.ts +61 -0
- package/esm/src/guardrails/tool-result.js +248 -0
- package/esm/src/guardrails/types.d.ts +242 -0
- package/esm/src/guardrails/types.js +54 -0
- package/esm/src/host/client-turn.d.ts +9 -0
- package/esm/src/host/client-turn.js +38 -0
- package/esm/src/host/mint-trace.d.ts +28 -0
- package/esm/src/host/mint-trace.js +59 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +68 -0
- package/esm/src/host/reply.d.ts +7 -0
- package/esm/src/host/reply.js +35 -0
- package/esm/src/interface/blocks.d.ts +8 -0
- package/esm/src/interface/blocks.js +213 -0
- package/esm/src/interface/composer-actions.d.ts +20 -0
- package/esm/src/interface/composer-actions.js +31 -0
- package/esm/src/interface/draft.d.ts +14 -0
- package/esm/src/interface/draft.js +28 -0
- package/esm/src/interface/from-profile.d.ts +12 -0
- package/esm/src/interface/from-profile.js +144 -0
- package/esm/src/interface/history.d.ts +40 -0
- package/esm/src/interface/history.js +269 -0
- package/esm/src/interface/inputs.d.ts +10 -0
- package/esm/src/interface/inputs.js +64 -0
- package/esm/src/interface/mod.d.ts +31 -0
- package/esm/src/interface/mod.js +21 -0
- package/esm/src/interface/models.d.ts +19 -0
- package/esm/src/interface/models.js +45 -0
- package/esm/src/interface/pending.d.ts +48 -0
- package/esm/src/interface/pending.js +146 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +223 -0
- package/esm/src/interface/session.d.ts +64 -0
- package/esm/src/interface/session.js +121 -0
- package/esm/src/interface/tool-calls.d.ts +20 -0
- package/esm/src/interface/tool-calls.js +73 -0
- package/esm/src/interface/tool-invoke.d.ts +4 -0
- package/esm/src/interface/tool-invoke.js +20 -0
- package/esm/src/interface/tool-media.d.ts +9 -0
- package/esm/src/interface/tool-media.js +112 -0
- package/esm/src/interface/types.d.ts +213 -0
- package/esm/src/interface/types.js +4 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +51 -0
- package/esm/src/kernel/auth/crypto.js +161 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +17 -0
- package/esm/src/kernel/auth/oauth.js +438 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +139 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/default-scope.d.ts +34 -0
- package/esm/src/kernel/default-scope.js +72 -0
- package/esm/src/kernel/engine/compaction.d.ts +70 -0
- package/esm/src/kernel/engine/compaction.js +202 -0
- package/esm/src/kernel/engine/decision.d.ts +41 -0
- package/esm/src/kernel/engine/decision.js +412 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +19 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +9 -0
- package/esm/src/kernel/engine/live-ingress.js +37 -0
- package/esm/src/kernel/engine/media-probe/audio.d.ts +7 -0
- package/esm/src/kernel/engine/media-probe/audio.js +342 -0
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +6 -0
- package/esm/src/kernel/engine/media-probe/bytes.js +26 -0
- package/esm/src/kernel/engine/media-probe/image.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/image.js +171 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +19 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +48 -0
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +35 -0
- package/esm/src/kernel/engine/media-probe/matroska.js +226 -0
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +22 -0
- package/esm/src/kernel/engine/media-probe/mp4.js +279 -0
- package/esm/src/kernel/engine/media-probe/opus.d.ts +4 -0
- package/esm/src/kernel/engine/media-probe/opus.js +23 -0
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/pdf.js +117 -0
- package/esm/src/kernel/engine/media-probe/video.d.ts +15 -0
- package/esm/src/kernel/engine/media-probe/video.js +49 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +322 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +15 -0
- package/esm/src/kernel/engine/runner/mod.js +574 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +14 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +105 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +48 -0
- package/esm/src/kernel/engine/runner/state.d.ts +76 -0
- package/esm/src/kernel/engine/runner/state.js +40 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +360 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +40 -0
- package/esm/src/kernel/engine/runner/stream.js +225 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +150 -0
- package/esm/src/kernel/engine/session/mod.d.ts +31 -0
- package/esm/src/kernel/engine/session/mod.js +951 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +489 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +77 -0
- package/esm/src/kernel/engine/token-estimate.js +218 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +131 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +118 -0
- package/esm/src/kernel/engine/turn-trace.js +863 -0
- package/esm/src/kernel/engine/usage.d.ts +30 -0
- package/esm/src/kernel/engine/usage.js +134 -0
- package/esm/src/kernel/interaction-parts.d.ts +10 -0
- package/esm/src/kernel/interaction-parts.js +22 -0
- package/esm/src/kernel/mod.d.ts +47 -0
- package/esm/src/kernel/mod.js +30 -0
- package/esm/src/kernel/profile-graph.d.ts +140 -0
- package/esm/src/kernel/profile-graph.js +151 -0
- package/esm/src/kernel/profile-presence.d.ts +9 -0
- package/esm/src/kernel/profile-presence.js +143 -0
- package/esm/src/kernel/profile-scope.d.ts +36 -0
- package/esm/src/kernel/profile-scope.js +262 -0
- package/esm/src/kernel/registry/attachments.d.ts +35 -0
- package/esm/src/kernel/registry/attachments.js +211 -0
- package/esm/src/kernel/registry/catalog.d.ts +19 -0
- package/esm/src/kernel/registry/catalog.js +78 -0
- package/esm/src/kernel/registry/ingress.d.ts +8 -0
- package/esm/src/kernel/registry/ingress.js +134 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +12 -0
- package/esm/src/kernel/registry/kernel-registry.js +8 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +7 -0
- package/esm/src/kernel/registry/profiles.d.ts +92 -0
- package/esm/src/kernel/registry/profiles.js +698 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +42 -0
- package/esm/src/kernel/registry/resolve.d.ts +14 -0
- package/esm/src/kernel/registry/resolve.js +237 -0
- package/esm/src/kernel/registry/schemas.d.ts +9 -0
- package/esm/src/kernel/registry/schemas.js +25 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +33 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +13 -0
- package/esm/src/kernel/registry/vault.js +14 -0
- package/esm/src/kernel/schema.d.ts +172 -0
- package/esm/src/kernel/schema.js +653 -0
- package/esm/src/kernel/scope.d.ts +22 -0
- package/esm/src/kernel/scope.js +25 -0
- package/esm/src/kernel/stages.d.ts +141 -0
- package/esm/src/kernel/stages.js +388 -0
- package/esm/src/kernel/stop.d.ts +93 -0
- package/esm/src/kernel/stop.js +125 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +16 -0
- package/esm/src/kernel/tools/activity-label.js +209 -0
- package/esm/src/kernel/tools/events.d.ts +51 -0
- package/esm/src/kernel/tools/events.js +149 -0
- package/esm/src/kernel/tools/execute.d.ts +64 -0
- package/esm/src/kernel/tools/execute.js +801 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +50 -0
- package/esm/src/kernel/tools/gate-answer.js +54 -0
- package/esm/src/kernel/tools/harness.d.ts +16 -0
- package/esm/src/kernel/tools/harness.js +42 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +129 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +20 -0
- package/esm/src/kernel/tools/mcp-sessions.js +64 -0
- package/esm/src/kernel/tools/mod.d.ts +9 -0
- package/esm/src/kernel/tools/mod.js +6 -0
- package/esm/src/kernel/tools/model-text.d.ts +11 -0
- package/esm/src/kernel/tools/model-text.js +25 -0
- package/esm/src/kernel/tools/permission.d.ts +6 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +8 -0
- package/esm/src/kernel/tools/project.js +25 -0
- package/esm/src/kernel/tools/registry.d.ts +20 -0
- package/esm/src/kernel/tools/registry.js +84 -0
- package/esm/src/kernel/tools/remote.d.ts +110 -0
- package/esm/src/kernel/tools/remote.js +998 -0
- package/esm/src/kernel/tools/resolve.d.ts +28 -0
- package/esm/src/kernel/tools/resolve.js +259 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +174 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +18 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +93 -0
- package/esm/src/kernel/tools/stage-run.js +140 -0
- package/esm/src/kernel/tools/types.d.ts +287 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/turn-events.d.ts +599 -0
- package/esm/src/kernel/turn-events.js +425 -0
- package/esm/src/kernel/types.d.ts +884 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +13 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +3 -0
- package/esm/src/observability/destinations.d.ts +9 -0
- package/esm/src/observability/destinations.js +38 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +117 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +68 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +29 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +14 -0
- package/esm/src/observability/policy.js +69 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +58 -0
- package/esm/src/observability/spans.d.ts +16 -0
- package/esm/src/observability/spans.js +56 -0
- package/esm/src/observability/trace-catalog.d.ts +111 -0
- package/esm/src/observability/trace-catalog.js +865 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +223 -0
- package/esm/src/observability/trace-schema.d.ts +54 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +13 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +92 -0
- package/esm/src/observability/trace-span.js +199 -0
- package/esm/src/observability/trace.d.ts +11 -0
- package/esm/src/observability/trace.js +35 -0
- package/esm/src/observability/types.d.ts +85 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +8 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +12 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +104 -0
- package/esm/src/presets/google.js +188 -0
- package/esm/src/presets/mod.d.ts +10 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +13 -0
- package/esm/src/presets/openrouter.js +13 -0
- package/esm/src/presets/typesafe.d.ts +2 -0
- package/esm/src/presets/typesafe.js +2 -0
- package/esm/src/providers/create-provider.d.ts +21 -0
- package/esm/src/providers/create-provider.js +90 -0
- package/esm/src/providers/decision/usage.d.ts +3 -0
- package/esm/src/providers/decision/usage.js +25 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +263 -0
- package/esm/src/providers/google/interactions/mod.d.ts +2 -0
- package/esm/src/providers/google/interactions/mod.js +2 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +24 -0
- package/esm/src/providers/google/interactions/stream.js +297 -0
- package/esm/src/providers/google/keys.d.ts +20 -0
- package/esm/src/providers/google/keys.js +87 -0
- package/esm/src/providers/google/live/framing.d.ts +51 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/mod.d.ts +7 -0
- package/esm/src/providers/google/live/mod.js +7 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +1 -0
- package/esm/src/providers/google/live/openapi-schema.js +42 -0
- package/esm/src/providers/google/live/session.d.ts +14 -0
- package/esm/src/providers/google/live/session.js +150 -0
- package/esm/src/providers/google/live/stream.d.ts +51 -0
- package/esm/src/providers/google/live/stream.js +263 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/local/local.d.ts +12 -0
- package/esm/src/providers/local/local.js +186 -0
- package/esm/src/providers/local/mod.d.ts +8 -0
- package/esm/src/providers/local/mod.js +8 -0
- package/esm/src/providers/mod.d.ts +11 -0
- package/esm/src/providers/mod.js +7 -0
- package/esm/src/providers/openrouter/cache-control.d.ts +5 -0
- package/esm/src/providers/openrouter/cache-control.js +4 -0
- package/esm/src/providers/openrouter/chat.d.ts +64 -0
- package/esm/src/providers/openrouter/chat.js +490 -0
- package/esm/src/providers/openrouter/image.d.ts +24 -0
- package/esm/src/providers/openrouter/image.js +187 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +10 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +99 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +3 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +8 -0
- package/esm/src/providers/openrouter/speech.d.ts +18 -0
- package/esm/src/providers/openrouter/speech.js +109 -0
- package/esm/src/providers/probe.d.ts +5 -0
- package/esm/src/providers/probe.js +15 -0
- package/esm/src/providers/shared/builtin-wire.d.ts +4 -0
- package/esm/src/providers/shared/builtin-wire.js +9 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/sse.d.ts +10 -0
- package/esm/src/providers/shared/sse.js +79 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +25 -0
- package/esm/src/providers/shared/tool-args.js +84 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/shared/vault.d.ts +13 -0
- package/esm/src/providers/shared/vault.js +41 -0
- package/esm/src/providers/types.d.ts +19 -0
- package/esm/src/providers/types.js +1 -0
- package/esm/src/surface/formats.d.ts +28 -0
- package/esm/src/surface/formats.js +139 -0
- package/esm/src/surface/mod.d.ts +14 -0
- package/esm/src/surface/mod.js +10 -0
- package/esm/src/surface/runtime.d.ts +40 -0
- package/esm/src/surface/runtime.js +439 -0
- package/esm/src/surface/tools.d.ts +15 -0
- package/esm/src/surface/tools.js +80 -0
- package/esm/src/surface/types.d.ts +104 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +108 -4
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
// TTFE: time to first event (profile resolve + provider setup). TTFT: time to first text delta.
|
|
2
|
+
// Overhead: total wall-clock delta vs. raw provider consumption.
|
|
3
|
+
import { canaryNote, eventHasCanary, mintCanary } from '../../guardrails/canary.js';
|
|
4
|
+
import { sanitizeTurnRequest } from '../../guardrails/sanitize.js';
|
|
5
|
+
import { clearProfiles, getProfile, registerProfile, resolveTurn, runTurn, } from '../../kernel/default-scope.js';
|
|
6
|
+
import { startCallUsage } from '../../kernel/engine/runner/usage.js';
|
|
7
|
+
import { startCallTrace } from '../../kernel/engine/turn-trace.js';
|
|
8
|
+
import { pickSystemRole } from '../../kernel/registry/system-role.js';
|
|
9
|
+
import { bindSystem } from '../../kernel/system-parts.js';
|
|
10
|
+
import { resolveObservabilityPolicy } from '../../observability/resolve-policy.js';
|
|
11
|
+
import { buildRecord } from '../../observability/trace-record.js';
|
|
12
|
+
import { startTrace } from '../../observability/trace-span.js';
|
|
13
|
+
const DEFAULT_CHUNKS = 200;
|
|
14
|
+
const DEFAULT_ITERATIONS = 50;
|
|
15
|
+
const DEFAULT_WARMUP = 5;
|
|
16
|
+
const MS_PER_SEC = 1000;
|
|
17
|
+
const BENCH_PROFILE_ID = '__bench__';
|
|
18
|
+
function registerBenchProfile() {
|
|
19
|
+
registerProfile({
|
|
20
|
+
type: 'text',
|
|
21
|
+
id: BENCH_PROFILE_ID,
|
|
22
|
+
identity: {
|
|
23
|
+
handle: 'bench',
|
|
24
|
+
system: 'You are a benchmark stub.',
|
|
25
|
+
},
|
|
26
|
+
models: {
|
|
27
|
+
'bench-model': {
|
|
28
|
+
protocol: 'openAi',
|
|
29
|
+
provider: 'openrouter',
|
|
30
|
+
apiId: 'bench-model',
|
|
31
|
+
efforts: { normal: 'none' },
|
|
32
|
+
summaries: false,
|
|
33
|
+
maxOutputTokens: 4096,
|
|
34
|
+
temperature: 0,
|
|
35
|
+
builtInTools: [],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
defaultModel: 'bench-model',
|
|
39
|
+
tools: { allow: [] },
|
|
40
|
+
inputs: { text: true },
|
|
41
|
+
guardrails: {
|
|
42
|
+
canary: true,
|
|
43
|
+
sanitizeInput: true,
|
|
44
|
+
redactSensitive: true,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function generateChunks(count) {
|
|
49
|
+
const events = [];
|
|
50
|
+
for (let i = 0; i < count; i++) {
|
|
51
|
+
events.push({ type: 'text', text: `token_${i} ` });
|
|
52
|
+
}
|
|
53
|
+
events.push({
|
|
54
|
+
type: 'tokens',
|
|
55
|
+
tokens: { input: 10, output: count, total: 10 + count },
|
|
56
|
+
});
|
|
57
|
+
events.push({ type: 'done', stop: { kind: 'completed' } });
|
|
58
|
+
return events;
|
|
59
|
+
}
|
|
60
|
+
function createMockProvider(chunks) {
|
|
61
|
+
return {
|
|
62
|
+
async *complete(_req) {
|
|
63
|
+
for (const chunk of chunks) {
|
|
64
|
+
yield chunk;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function buildBenchRequest() {
|
|
70
|
+
return {
|
|
71
|
+
profile: BENCH_PROFILE_ID,
|
|
72
|
+
input: { text: 'Benchmark prompt.' },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** What a bare consumer sends a provider: the bench prompt, no kernel shaping. */
|
|
76
|
+
function benchProviderRequest(text) {
|
|
77
|
+
return {
|
|
78
|
+
model: 'bench-model',
|
|
79
|
+
apiId: 'bench-model',
|
|
80
|
+
thinking: 'none',
|
|
81
|
+
summaries: undefined,
|
|
82
|
+
maxOutputTokens: 4096,
|
|
83
|
+
temperature: 0,
|
|
84
|
+
builtins: [],
|
|
85
|
+
system: '',
|
|
86
|
+
input: [{ type: 'text', text }],
|
|
87
|
+
structured: null,
|
|
88
|
+
image: null,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function measureRawProvider(provider) {
|
|
92
|
+
const req = buildBenchRequest();
|
|
93
|
+
const start = performance.now();
|
|
94
|
+
let firstEvent = 0;
|
|
95
|
+
let firstText = 0;
|
|
96
|
+
let textEvents = 0;
|
|
97
|
+
let gotFirst = false;
|
|
98
|
+
let gotFirstText = false;
|
|
99
|
+
const fakeReq = benchProviderRequest(req.input?.text ?? '');
|
|
100
|
+
for await (const event of provider.complete(fakeReq)) {
|
|
101
|
+
if (!gotFirst) {
|
|
102
|
+
firstEvent = performance.now() - start;
|
|
103
|
+
gotFirst = true;
|
|
104
|
+
}
|
|
105
|
+
if (!gotFirstText && event.type === 'text') {
|
|
106
|
+
firstText = performance.now() - start;
|
|
107
|
+
gotFirstText = true;
|
|
108
|
+
}
|
|
109
|
+
if (event.type === 'text') {
|
|
110
|
+
textEvents++;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
ttfe: firstEvent,
|
|
115
|
+
ttft: firstText,
|
|
116
|
+
totalMs: performance.now() - start,
|
|
117
|
+
textEvents,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async function measureKernelPipeline(provider) {
|
|
121
|
+
const req = buildBenchRequest();
|
|
122
|
+
const start = performance.now();
|
|
123
|
+
let firstEvent = 0;
|
|
124
|
+
let firstText = 0;
|
|
125
|
+
let textEvents = 0;
|
|
126
|
+
let gotFirst = false;
|
|
127
|
+
let gotFirstText = false;
|
|
128
|
+
for await (const event of runTurn(req, provider)) {
|
|
129
|
+
if (!gotFirst) {
|
|
130
|
+
firstEvent = performance.now() - start;
|
|
131
|
+
gotFirst = true;
|
|
132
|
+
}
|
|
133
|
+
if (!gotFirstText && event.type === 'text') {
|
|
134
|
+
firstText = performance.now() - start;
|
|
135
|
+
gotFirstText = true;
|
|
136
|
+
}
|
|
137
|
+
if (event.type === 'text') {
|
|
138
|
+
textEvents++;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
ttfe: firstEvent,
|
|
143
|
+
ttft: firstText,
|
|
144
|
+
totalMs: performance.now() - start,
|
|
145
|
+
textEvents,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function percentile(sorted, p) {
|
|
149
|
+
const idx = Math.ceil((p / 100) * sorted.length) - 1;
|
|
150
|
+
return sorted[Math.max(0, idx)];
|
|
151
|
+
}
|
|
152
|
+
function aggregate(results) {
|
|
153
|
+
const ttfe = results.map((r) => r.ttfe).sort((a, b) => a - b);
|
|
154
|
+
const ttft = results.map((r) => r.ttft).sort((a, b) => a - b);
|
|
155
|
+
const total = results.map((r) => r.totalMs).sort((a, b) => a - b);
|
|
156
|
+
const tps = results.map((r) => (r.textEvents / r.totalMs) * MS_PER_SEC).sort((a, b) => a - b);
|
|
157
|
+
const mean = (arr) => arr.reduce((a, b) => a + b, 0) / arr.length;
|
|
158
|
+
return {
|
|
159
|
+
ttfeMs: {
|
|
160
|
+
median: percentile(ttfe, 50),
|
|
161
|
+
p95: percentile(ttfe, 95),
|
|
162
|
+
mean: mean(ttfe),
|
|
163
|
+
},
|
|
164
|
+
ttftMs: {
|
|
165
|
+
median: percentile(ttft, 50),
|
|
166
|
+
p95: percentile(ttft, 95),
|
|
167
|
+
mean: mean(ttft),
|
|
168
|
+
},
|
|
169
|
+
tokensPerSec: {
|
|
170
|
+
median: percentile(tps, 50),
|
|
171
|
+
p95: percentile(tps, 5), // lower is worse for throughput
|
|
172
|
+
mean: mean(tps),
|
|
173
|
+
},
|
|
174
|
+
totalMs: {
|
|
175
|
+
median: percentile(total, 50),
|
|
176
|
+
p95: percentile(total, 95),
|
|
177
|
+
mean: mean(total),
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function fmtMs(ms) {
|
|
182
|
+
if (ms < 1) {
|
|
183
|
+
return `${(ms * MS_PER_SEC).toFixed(0)}µs`;
|
|
184
|
+
}
|
|
185
|
+
return `${ms.toFixed(2)}ms`;
|
|
186
|
+
}
|
|
187
|
+
function fmtRate(tps) {
|
|
188
|
+
if (tps >= MS_PER_SEC * MS_PER_SEC) {
|
|
189
|
+
return `${(tps / (MS_PER_SEC * MS_PER_SEC)).toFixed(1)}M/s`;
|
|
190
|
+
}
|
|
191
|
+
if (tps >= MS_PER_SEC) {
|
|
192
|
+
return `${(tps / MS_PER_SEC).toFixed(1)}K/s`;
|
|
193
|
+
}
|
|
194
|
+
return `${tps.toFixed(0)}/s`;
|
|
195
|
+
}
|
|
196
|
+
function printMetricRow(label, raw, fmt) {
|
|
197
|
+
console.log(` ${label.padEnd(14)} median ${fmt(raw.median).padStart(10)} p95 ${fmt(raw.p95).padStart(10)} mean ${fmt(raw.mean).padStart(10)}`);
|
|
198
|
+
}
|
|
199
|
+
function printResults(label, metrics) {
|
|
200
|
+
console.log(`\n${label}`);
|
|
201
|
+
console.log('─'.repeat(72));
|
|
202
|
+
printMetricRow('TTFE', metrics.ttfeMs, fmtMs);
|
|
203
|
+
printMetricRow('TTFT', metrics.ttftMs, fmtMs);
|
|
204
|
+
printMetricRow('Throughput', metrics.tokensPerSec, fmtRate);
|
|
205
|
+
printMetricRow('Total', metrics.totalMs, fmtMs);
|
|
206
|
+
}
|
|
207
|
+
function printOverhead(raw, kernel) {
|
|
208
|
+
console.log('\nOverhead (kernel − raw)');
|
|
209
|
+
console.log('─'.repeat(72));
|
|
210
|
+
const ttfeDelta = kernel.ttfeMs.median - raw.ttfeMs.median;
|
|
211
|
+
const ttftDelta = kernel.ttftMs.median - raw.ttftMs.median;
|
|
212
|
+
const totalDelta = kernel.totalMs.median - raw.totalMs.median;
|
|
213
|
+
const tpsDelta = kernel.tokensPerSec.median - raw.tokensPerSec.median;
|
|
214
|
+
console.log(` TTFE ${ttfeDelta >= 0 ? '+' : ''}${fmtMs(ttfeDelta)}`);
|
|
215
|
+
console.log(` TTFT ${ttftDelta >= 0 ? '+' : ''}${fmtMs(ttftDelta)}`);
|
|
216
|
+
console.log(` Throughput ${tpsDelta >= 0 ? '+' : ''}${fmtRate(tpsDelta)}`);
|
|
217
|
+
console.log(` Total ${totalDelta >= 0 ? '+' : ''}${fmtMs(totalDelta)}`);
|
|
218
|
+
if (raw.totalMs.median > 0) {
|
|
219
|
+
const pct = ((totalDelta / raw.totalMs.median) * 100).toFixed(1);
|
|
220
|
+
console.log(` Relative ${totalDelta >= 0 ? '+' : ''}${pct}%`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function measureSetupPhases() {
|
|
224
|
+
const req = buildBenchRequest();
|
|
225
|
+
const t0 = performance.now();
|
|
226
|
+
const safe = sanitizeTurnRequest(req, getProfile(req.profile));
|
|
227
|
+
const t1 = performance.now();
|
|
228
|
+
const { profile, generation } = resolveTurn(safe);
|
|
229
|
+
const t2 = performance.now();
|
|
230
|
+
pickSystemRole(profile, safe.input?.role);
|
|
231
|
+
const t3 = performance.now();
|
|
232
|
+
bindSystem(generation.resolvedSystem, [canaryNote(generation.canary)]);
|
|
233
|
+
const t4 = performance.now();
|
|
234
|
+
return {
|
|
235
|
+
sanitizeMs: t1 - t0,
|
|
236
|
+
resolveMs: t2 - t1,
|
|
237
|
+
systemMs: t3 - t2,
|
|
238
|
+
canaryMs: t4 - t3,
|
|
239
|
+
totalSetupMs: t4 - t0,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function printPhaseBreakdown(iterations) {
|
|
243
|
+
const results = [];
|
|
244
|
+
for (let i = 0; i < iterations; i++) {
|
|
245
|
+
results.push(measureSetupPhases());
|
|
246
|
+
}
|
|
247
|
+
const median = (arr) => {
|
|
248
|
+
const s = arr.slice().sort((a, b) => a - b);
|
|
249
|
+
return percentile(s, 50);
|
|
250
|
+
};
|
|
251
|
+
const sanitize = median(results.map((r) => r.sanitizeMs));
|
|
252
|
+
const resolve = median(results.map((r) => r.resolveMs));
|
|
253
|
+
const system = median(results.map((r) => r.systemMs));
|
|
254
|
+
const canary = median(results.map((r) => r.canaryMs));
|
|
255
|
+
const total = median(results.map((r) => r.totalSetupMs));
|
|
256
|
+
console.log('\nSetup Phase Breakdown (median)');
|
|
257
|
+
console.log('─'.repeat(72));
|
|
258
|
+
console.log(` sanitizeTurnRequest ${fmtMs(sanitize).padStart(10)}`);
|
|
259
|
+
console.log(` resolveTurn ${fmtMs(resolve).padStart(10)}`);
|
|
260
|
+
console.log(` pickSystemRole ${fmtMs(system).padStart(10)}`);
|
|
261
|
+
console.log(` bindSystem ${fmtMs(canary).padStart(10)}`);
|
|
262
|
+
console.log(` ─────────────────────────────`);
|
|
263
|
+
console.log(` Total setup ${fmtMs(total).padStart(10)}`);
|
|
264
|
+
}
|
|
265
|
+
function microCanaryCheck(chunks, iterations) {
|
|
266
|
+
const canary = mintCanary();
|
|
267
|
+
const total = chunks.length * iterations;
|
|
268
|
+
const start = performance.now();
|
|
269
|
+
for (let i = 0; i < iterations; i++) {
|
|
270
|
+
for (const chunk of chunks) {
|
|
271
|
+
eventHasCanary(chunk, canary);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const elapsed = performance.now() - start;
|
|
275
|
+
return {
|
|
276
|
+
label: 'eventHasCanary',
|
|
277
|
+
totalMs: elapsed,
|
|
278
|
+
per: 'event',
|
|
279
|
+
perUnitNs: (elapsed / total) * 1e6,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function microArrayPush(chunks, iterations) {
|
|
283
|
+
const total = chunks.length * iterations;
|
|
284
|
+
const start = performance.now();
|
|
285
|
+
for (let i = 0; i < iterations; i++) {
|
|
286
|
+
const seen = [];
|
|
287
|
+
const allEmitted = [];
|
|
288
|
+
const attempt = [];
|
|
289
|
+
for (const chunk of chunks) {
|
|
290
|
+
seen.push(chunk);
|
|
291
|
+
allEmitted.push(chunk);
|
|
292
|
+
attempt.push(chunk);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const elapsed = performance.now() - start;
|
|
296
|
+
return {
|
|
297
|
+
label: 'Array.push ×3',
|
|
298
|
+
totalMs: elapsed,
|
|
299
|
+
per: 'event',
|
|
300
|
+
perUnitNs: (elapsed / total) * 1e6,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
async function microAsyncGenOverhead(chunks, iterations) {
|
|
304
|
+
async function* layer1(events) {
|
|
305
|
+
for (const e of events)
|
|
306
|
+
yield e;
|
|
307
|
+
}
|
|
308
|
+
async function* layer2(events) {
|
|
309
|
+
for await (const e of layer1(events))
|
|
310
|
+
yield e;
|
|
311
|
+
}
|
|
312
|
+
async function* layer3(events) {
|
|
313
|
+
for await (const e of layer2(events))
|
|
314
|
+
yield e;
|
|
315
|
+
}
|
|
316
|
+
async function* layer4(events) {
|
|
317
|
+
for await (const e of layer3(events))
|
|
318
|
+
yield e;
|
|
319
|
+
}
|
|
320
|
+
const total = chunks.length * iterations;
|
|
321
|
+
const start = performance.now();
|
|
322
|
+
for (let i = 0; i < iterations; i++) {
|
|
323
|
+
for await (const _e of layer4(chunks)) {
|
|
324
|
+
// consume
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const elapsed = performance.now() - start;
|
|
328
|
+
return {
|
|
329
|
+
label: 'AsyncGen ×4 layers',
|
|
330
|
+
totalMs: elapsed,
|
|
331
|
+
per: 'event',
|
|
332
|
+
perUnitNs: (elapsed / total) * 1e6,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function microAbortCheck(chunks, iterations) {
|
|
336
|
+
const controller = new AbortController();
|
|
337
|
+
const { signal } = controller;
|
|
338
|
+
const total = chunks.length * iterations;
|
|
339
|
+
const start = performance.now();
|
|
340
|
+
for (let i = 0; i < iterations; i++) {
|
|
341
|
+
for (const _chunk of chunks) {
|
|
342
|
+
if (signal.aborted)
|
|
343
|
+
throw signal.reason;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const elapsed = performance.now() - start;
|
|
347
|
+
return {
|
|
348
|
+
label: 'signal.aborted check',
|
|
349
|
+
totalMs: elapsed,
|
|
350
|
+
per: 'event',
|
|
351
|
+
perUnitNs: (elapsed / total) * 1e6,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/** Record one model call over `chunks`, then build its trace record, as a turn does. */
|
|
355
|
+
async function microTraceRecord(chunks, iterations) {
|
|
356
|
+
const text = buildBenchRequest().input?.text ?? '';
|
|
357
|
+
const req = benchProviderRequest(text);
|
|
358
|
+
const policy = resolveObservabilityPolicy(undefined);
|
|
359
|
+
const start = performance.now();
|
|
360
|
+
for (let i = 0; i < iterations; i++) {
|
|
361
|
+
const tree = startTrace(`invoke_agent ${BENCH_PROFILE_ID}`);
|
|
362
|
+
const call = startCallTrace((name, options) => tree.root.child(name, options), {
|
|
363
|
+
req,
|
|
364
|
+
usage: startCallUsage('', { history: [], input: req.input }),
|
|
365
|
+
binding: undefined,
|
|
366
|
+
transport: 'interactions',
|
|
367
|
+
step: 0,
|
|
368
|
+
attempt: 0,
|
|
369
|
+
});
|
|
370
|
+
for (const chunk of chunks) {
|
|
371
|
+
call.observe(chunk);
|
|
372
|
+
}
|
|
373
|
+
call.end({ stop: { kind: 'completed' } });
|
|
374
|
+
tree.root.end();
|
|
375
|
+
await buildRecord({ spans: tree.collect(), policy });
|
|
376
|
+
}
|
|
377
|
+
const elapsed = performance.now() - start;
|
|
378
|
+
return {
|
|
379
|
+
label: 'record call + buildRecord (trace)',
|
|
380
|
+
totalMs: elapsed,
|
|
381
|
+
per: 'turn',
|
|
382
|
+
perUnitNs: (elapsed / iterations) * 1e6,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function microSanitizeScaling() {
|
|
386
|
+
const sizes = [50, 200, 1000, 5000];
|
|
387
|
+
console.log('\nSanitize Scaling (input text length)');
|
|
388
|
+
console.log('─'.repeat(72));
|
|
389
|
+
for (const size of sizes) {
|
|
390
|
+
const text = 'A'.repeat(size);
|
|
391
|
+
const req = {
|
|
392
|
+
profile: BENCH_PROFILE_ID,
|
|
393
|
+
input: { text },
|
|
394
|
+
};
|
|
395
|
+
const runs = 500;
|
|
396
|
+
const start = performance.now();
|
|
397
|
+
for (let i = 0; i < runs; i++) {
|
|
398
|
+
sanitizeTurnRequest(req, getProfile(req.profile));
|
|
399
|
+
}
|
|
400
|
+
const elapsed = performance.now() - start;
|
|
401
|
+
const perCall = elapsed / runs;
|
|
402
|
+
console.log(` ${String(size).padStart(5)} chars ${fmtMs(perCall).padStart(10)}/call`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function fmtNs(ns) {
|
|
406
|
+
if (ns < 1000) {
|
|
407
|
+
return `${ns.toFixed(0)}ns`;
|
|
408
|
+
}
|
|
409
|
+
return `${(ns / 1000).toFixed(1)}µs`;
|
|
410
|
+
}
|
|
411
|
+
async function printMicroBenchmarks(chunks, iterations) {
|
|
412
|
+
const results = [];
|
|
413
|
+
results.push(microCanaryCheck(chunks, iterations));
|
|
414
|
+
results.push(microArrayPush(chunks, iterations));
|
|
415
|
+
results.push(await microAsyncGenOverhead(chunks, iterations));
|
|
416
|
+
results.push(microAbortCheck(chunks, iterations));
|
|
417
|
+
results.push(await microTraceRecord(chunks, Math.min(iterations, 20)));
|
|
418
|
+
console.log('\nPer-Event Micro-Benchmarks');
|
|
419
|
+
console.log('─'.repeat(72));
|
|
420
|
+
for (const r of results) {
|
|
421
|
+
const perUnit = r.per === 'turn'
|
|
422
|
+
? `${fmtMs(r.perUnitNs / 1e6).padStart(10)}/turn`
|
|
423
|
+
: `${fmtNs(r.perUnitNs).padStart(8)}/event`;
|
|
424
|
+
console.log(` ${r.label.padEnd(24)} ${perUnit} (${fmtMs(r.totalMs)} total)`);
|
|
425
|
+
}
|
|
426
|
+
microSanitizeScaling();
|
|
427
|
+
}
|
|
428
|
+
export async function benchCommand(options = {}) {
|
|
429
|
+
const chunkCount = options.chunks ?? DEFAULT_CHUNKS;
|
|
430
|
+
const iterations = options.iterations ?? DEFAULT_ITERATIONS;
|
|
431
|
+
const warmup = options.warmup ?? DEFAULT_WARMUP;
|
|
432
|
+
console.log(`\n⏱ Theorem Kernel Benchmark`);
|
|
433
|
+
console.log(` ${chunkCount} chunks × ${iterations} iterations (${warmup} warmup)\n`);
|
|
434
|
+
const chunks = generateChunks(chunkCount);
|
|
435
|
+
const provider = createMockProvider(chunks);
|
|
436
|
+
registerBenchProfile();
|
|
437
|
+
for (let i = 0; i < warmup; i++) {
|
|
438
|
+
await measureRawProvider(provider);
|
|
439
|
+
await measureKernelPipeline(provider);
|
|
440
|
+
}
|
|
441
|
+
const rawResults = [];
|
|
442
|
+
for (let i = 0; i < iterations; i++) {
|
|
443
|
+
rawResults.push(await measureRawProvider(provider));
|
|
444
|
+
}
|
|
445
|
+
const kernelResults = [];
|
|
446
|
+
for (let i = 0; i < iterations; i++) {
|
|
447
|
+
kernelResults.push(await measureKernelPipeline(provider));
|
|
448
|
+
}
|
|
449
|
+
const rawMetrics = aggregate(rawResults);
|
|
450
|
+
const kernelMetrics = aggregate(kernelResults);
|
|
451
|
+
printResults('Raw Provider (baseline)', rawMetrics);
|
|
452
|
+
printResults('Kernel Pipeline (runTurn)', kernelMetrics);
|
|
453
|
+
printOverhead(rawMetrics, kernelMetrics);
|
|
454
|
+
printPhaseBreakdown(iterations);
|
|
455
|
+
await printMicroBenchmarks(chunks, iterations);
|
|
456
|
+
clearProfiles();
|
|
457
|
+
console.log('\n');
|
|
458
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agents egress-compile`: reads a module's exported egress rules and writes
|
|
3
|
+
* the table `egressPolicy` loads with them.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
interface EgressCompileOptions {
|
|
8
|
+
/** Path or URL of the module exporting the rules. */
|
|
9
|
+
module: string;
|
|
10
|
+
/** The export holding the rules. Default `rules`. */
|
|
11
|
+
exportName?: string;
|
|
12
|
+
/** Where the compiled module is written. */
|
|
13
|
+
out: string;
|
|
14
|
+
}
|
|
15
|
+
/** Compiles the rules and writes the module; returns how many rules it read. */
|
|
16
|
+
declare function egressCompileCommand({ module, exportName, out, }: EgressCompileOptions): Promise<number>;
|
|
17
|
+
export { egressCompileCommand };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agents egress-compile`: reads a module's exported egress rules and writes
|
|
3
|
+
* the table `egressPolicy` loads with them.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { writeFile } from 'node:fs/promises';
|
|
8
|
+
import { cwd } from 'node:process';
|
|
9
|
+
/** `specifier` as a URL, relative paths read from the working directory. */
|
|
10
|
+
function moduleUrl(specifier) {
|
|
11
|
+
return new URL(specifier, `file://${cwd()}/`).href;
|
|
12
|
+
}
|
|
13
|
+
/** Compiles the rules and writes the module; returns how many rules it read. */
|
|
14
|
+
async function egressCompileCommand({ module, exportName = 'rules', out, }) {
|
|
15
|
+
const loaded = await import(moduleUrl(module));
|
|
16
|
+
const rules = loaded[exportName];
|
|
17
|
+
if (!Array.isArray(rules)) {
|
|
18
|
+
throw new Error(`${module} has no array export named ${exportName}`);
|
|
19
|
+
}
|
|
20
|
+
// Loaded here so no other command loads the regex engine.
|
|
21
|
+
const { compiledEgressModule, compileEgressRules } = await import('../../guardrails/egress-compiler.js');
|
|
22
|
+
await writeFile(out, compiledEgressModule(compileEgressRules(rules)));
|
|
23
|
+
return rules.length;
|
|
24
|
+
}
|
|
25
|
+
export { egressCompileCommand };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EvalMediaResolver } from '../../evals/types.js';
|
|
2
|
+
import type { RunDecisionOptions } from '../../kernel/engine/decision.js';
|
|
3
|
+
import type { ModelProvider } from '../../kernel/types.js';
|
|
4
|
+
export interface EvalOptions {
|
|
5
|
+
/** Path of the suite module (`export default` an `EvalSuite`). */
|
|
6
|
+
suite: string;
|
|
7
|
+
/** Grade these records (a JSONL file or a directory of them) instead of running the profile. */
|
|
8
|
+
recorded?: string;
|
|
9
|
+
/** Trials per case, overriding the suite's `trials.repeat`. */
|
|
10
|
+
trials?: number;
|
|
11
|
+
/** Trials in flight at once (default 1). */
|
|
12
|
+
concurrency?: number;
|
|
13
|
+
/** Append trial and run records as JSONL under this directory. */
|
|
14
|
+
traceDir?: string;
|
|
15
|
+
/** Print the run as one JSON document instead of the table. */
|
|
16
|
+
json?: boolean;
|
|
17
|
+
/** Stop starting trials once the run's cost passes this. */
|
|
18
|
+
maxCostUsd?: number;
|
|
19
|
+
/** The fraction of cases that must pass for exit 0 (default 1: every case). */
|
|
20
|
+
threshold?: number;
|
|
21
|
+
}
|
|
22
|
+
/** What the host hands the eval command: providers and keys it never creates or reads itself. */
|
|
23
|
+
export interface EvalHost {
|
|
24
|
+
/** The provider for the profile under test. */
|
|
25
|
+
provider?: ModelProvider;
|
|
26
|
+
/** The provider for text judge profiles. */
|
|
27
|
+
judgeProvider?: ModelProvider;
|
|
28
|
+
/** The key for decision judge profiles (Jev). */
|
|
29
|
+
judgeDecision?: Omit<RunDecisionOptions, 'sink'>;
|
|
30
|
+
/** Where a judge finds media a trace names only by hash. */
|
|
31
|
+
media?: EvalMediaResolver;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns whether the run met the threshold; a run stopped on budget never does. The CLI never
|
|
35
|
+
* creates a provider or reads a key: the host passes them or the suite module exports them.
|
|
36
|
+
*/
|
|
37
|
+
export declare function evalCommand(options: EvalOptions, host?: EvalHost): Promise<boolean>;
|