@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,72 @@
|
|
|
1
|
+
import { defaultKernelScope as scope } from './scope.js';
|
|
2
|
+
/** Register or replace a tool in the default scope. */
|
|
3
|
+
function registerTool(def) {
|
|
4
|
+
return scope.tools.register(def);
|
|
5
|
+
}
|
|
6
|
+
function registerTools(defs) {
|
|
7
|
+
return scope.tools.registerMany(defs);
|
|
8
|
+
}
|
|
9
|
+
function getTool(name) {
|
|
10
|
+
return scope.tools.get(name);
|
|
11
|
+
}
|
|
12
|
+
function requireTool(name) {
|
|
13
|
+
return scope.tools.require(name);
|
|
14
|
+
}
|
|
15
|
+
function hasTool(name) {
|
|
16
|
+
return scope.tools.has(name);
|
|
17
|
+
}
|
|
18
|
+
function listTools() {
|
|
19
|
+
return scope.tools.list();
|
|
20
|
+
}
|
|
21
|
+
function resetTools() {
|
|
22
|
+
scope.tools.reset();
|
|
23
|
+
}
|
|
24
|
+
/** Define, validate, and register a profile in the default scope. */
|
|
25
|
+
function registerProfile(profile) {
|
|
26
|
+
scope.profiles.register(profile);
|
|
27
|
+
}
|
|
28
|
+
function registerProfiles(profiles) {
|
|
29
|
+
scope.profiles.registerMany(profiles);
|
|
30
|
+
}
|
|
31
|
+
/** The default scope's profile `id`; throws when there is none. */
|
|
32
|
+
function getProfile(id) {
|
|
33
|
+
return scope.profiles.get(id);
|
|
34
|
+
}
|
|
35
|
+
function hasProfile(id) {
|
|
36
|
+
return scope.profiles.has(id);
|
|
37
|
+
}
|
|
38
|
+
function listProfiles() {
|
|
39
|
+
return scope.profiles.list();
|
|
40
|
+
}
|
|
41
|
+
function clearProfiles() {
|
|
42
|
+
scope.profiles.clear();
|
|
43
|
+
}
|
|
44
|
+
function registerStructured(id, spec) {
|
|
45
|
+
scope.schemas.register(id, spec);
|
|
46
|
+
}
|
|
47
|
+
/** The default scope's schema `id`; throws when there is none. */
|
|
48
|
+
function getStructured(id) {
|
|
49
|
+
return scope.schemas.get(id);
|
|
50
|
+
}
|
|
51
|
+
function runTurn(req, provider, sinkOverride) {
|
|
52
|
+
return scope.runTurn(req, provider, sinkOverride);
|
|
53
|
+
}
|
|
54
|
+
function runSession(req, options, sinkOverride) {
|
|
55
|
+
return scope.runSession(req, options, sinkOverride);
|
|
56
|
+
}
|
|
57
|
+
function compactHistory(req, provider, sinkOverride) {
|
|
58
|
+
return scope.compactHistory(req, provider, sinkOverride);
|
|
59
|
+
}
|
|
60
|
+
function invokeTool(request, sinkOverride) {
|
|
61
|
+
return scope.invokeTool(request, sinkOverride);
|
|
62
|
+
}
|
|
63
|
+
function resolveTurn(req) {
|
|
64
|
+
return scope.resolveTurn(req);
|
|
65
|
+
}
|
|
66
|
+
function projectProfile(id) {
|
|
67
|
+
return scope.projectProfile(id);
|
|
68
|
+
}
|
|
69
|
+
function runDecision(request, options) {
|
|
70
|
+
return scope.runDecision(request, options);
|
|
71
|
+
}
|
|
72
|
+
export { clearProfiles, compactHistory, getProfile, getStructured, getTool, hasProfile, hasTool, invokeTool, listProfiles, listTools, projectProfile, registerProfile, registerProfiles, registerStructured, registerTool, registerTools, requireTool, resetTools, resolveTurn, runDecision, runSession, runTurn, };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { CompactionFailure, CompactionMeter, CompactionResult, CompactionSpec, Profile, TurnHistoryMessage, TurnInput, TurnTokens } from '../types.js';
|
|
2
|
+
import { type MediaTokenFamily } from './token-estimate.js';
|
|
3
|
+
export interface CompactionSplit {
|
|
4
|
+
toCompact: TurnHistoryMessage[];
|
|
5
|
+
toRetain: TurnHistoryMessage[];
|
|
6
|
+
}
|
|
7
|
+
export interface CompactionTokens {
|
|
8
|
+
meter: CompactionMeter;
|
|
9
|
+
/** Token count compared to `compactAt * maxTokens`. */
|
|
10
|
+
tokens: number;
|
|
11
|
+
/**
|
|
12
|
+
* Media parts left out of `tokens` because no verified rule counts them for this model.
|
|
13
|
+
* Always 0 for host-supplied and provider-reported counts.
|
|
14
|
+
*/
|
|
15
|
+
unknownMedia: number;
|
|
16
|
+
}
|
|
17
|
+
/** Effective meter; defaults to `'history'`. */
|
|
18
|
+
export declare function compactionMeter(spec: CompactionSpec): CompactionMeter;
|
|
19
|
+
/** Prefers host-supplied `input.historyTokens`; otherwise estimates `input.history`. */
|
|
20
|
+
export declare function resolveHistoryTokens(input: TurnInput | undefined, family: MediaTokenFamily | undefined): Promise<Omit<CompactionTokens, 'meter'>>;
|
|
21
|
+
/**
|
|
22
|
+
* `meter: 'input'` prefers this turn's last model call (`timing: 'after'`), else the host's
|
|
23
|
+
* `input.inputTokens` from the previous turn (`timing: 'before'`); `undefined` (do not fire) when
|
|
24
|
+
* neither is positive. It never loads the history tokenizer.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveCompactionTokens(args: {
|
|
27
|
+
spec: CompactionSpec;
|
|
28
|
+
input?: TurnInput;
|
|
29
|
+
/** Tokens of this turn's last model call, when one completed. */
|
|
30
|
+
prompt?: TurnTokens;
|
|
31
|
+
family: MediaTokenFamily | undefined;
|
|
32
|
+
}): Promise<CompactionTokens | undefined>;
|
|
33
|
+
export declare function compactionNeeded(tokens: number, spec: CompactionSpec): boolean;
|
|
34
|
+
/** `spec.trigger`, when set, decides alone; otherwise the token threshold does. */
|
|
35
|
+
export declare function shouldCompact(resolved: CompactionTokens, spec: CompactionSpec): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* `previousExchanges` semantics:
|
|
38
|
+
* - `0` — compact everything, retain nothing.
|
|
39
|
+
* - `≥ 1` (integer) — retain the last N exchanges.
|
|
40
|
+
* - `(0, 1)` — retain exchanges that fit within this fraction of `maxTokens`,
|
|
41
|
+
* walking backwards from the most recent (token estimator; unknown media is
|
|
42
|
+
* not counted).
|
|
43
|
+
*/
|
|
44
|
+
export declare function splitForCompaction(history: TurnHistoryMessage[], spec: CompactionSpec, family: MediaTokenFamily | undefined): Promise<CompactionSplit>;
|
|
45
|
+
/**
|
|
46
|
+
* `toCompact` as the compactor reads it: media its profile does not accept is
|
|
47
|
+
* left out, and tool calls and results become the assistant's text, so no
|
|
48
|
+
* provider needs the tools declared to read them.
|
|
49
|
+
*/
|
|
50
|
+
export declare function compactorHistory(toCompact: readonly TurnHistoryMessage[], compactor: Profile): {
|
|
51
|
+
history: TurnHistoryMessage[];
|
|
52
|
+
droppedMedia: number;
|
|
53
|
+
};
|
|
54
|
+
/** What the compactor returned: a summary, or why there is none. */
|
|
55
|
+
export type CompactorRun = {
|
|
56
|
+
summary: string;
|
|
57
|
+
droppedMedia: number;
|
|
58
|
+
tokens?: TurnTokens;
|
|
59
|
+
} | {
|
|
60
|
+
failure: CompactionFailure;
|
|
61
|
+
droppedMedia: number;
|
|
62
|
+
tokens?: TurnTokens;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The history after one compaction. A failed compactor never leaves a hollow
|
|
66
|
+
* summary: under `maxTokens` the history stays whole for the next turn to try
|
|
67
|
+
* again; over it, `toCompact` is dropped (keeping any earlier summary) so the
|
|
68
|
+
* turn still fits.
|
|
69
|
+
*/
|
|
70
|
+
export declare function compactionResult(split: CompactionSplit, run: CompactorRun, tokens: number, spec: CompactionSpec): CompactionResult;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { lexiconText } from '../../guardrails/lexicon.js';
|
|
2
|
+
import { mediaChannelForMime } from '../registry/catalog.js';
|
|
3
|
+
import { loadTokenEstimator } from './token-estimate.js';
|
|
4
|
+
/** Effective meter; defaults to `'history'`. */
|
|
5
|
+
export function compactionMeter(spec) {
|
|
6
|
+
return spec.meter ?? 'history';
|
|
7
|
+
}
|
|
8
|
+
// An exchange starts at each `user` message; system messages before the first one belong to none.
|
|
9
|
+
function findExchangeBoundaries(history) {
|
|
10
|
+
const boundaries = [];
|
|
11
|
+
for (let i = 0; i < history.length; i++) {
|
|
12
|
+
if (history[i].role === 'user') {
|
|
13
|
+
boundaries.push(i);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return boundaries;
|
|
17
|
+
}
|
|
18
|
+
/** Prefers host-supplied `input.historyTokens`; otherwise estimates `input.history`. */
|
|
19
|
+
export async function resolveHistoryTokens(input, family) {
|
|
20
|
+
if (input?.historyTokens != null) {
|
|
21
|
+
return { tokens: input.historyTokens, unknownMedia: 0 };
|
|
22
|
+
}
|
|
23
|
+
const history = input?.history ?? [];
|
|
24
|
+
if (history.length === 0)
|
|
25
|
+
return { tokens: 0, unknownMedia: 0 };
|
|
26
|
+
return await (await loadTokenEstimator()).messages(history, family);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `meter: 'input'` prefers this turn's last model call (`timing: 'after'`), else the host's
|
|
30
|
+
* `input.inputTokens` from the previous turn (`timing: 'before'`); `undefined` (do not fire) when
|
|
31
|
+
* neither is positive. It never loads the history tokenizer.
|
|
32
|
+
*/
|
|
33
|
+
export async function resolveCompactionTokens(args) {
|
|
34
|
+
const meter = compactionMeter(args.spec);
|
|
35
|
+
if (meter === 'history') {
|
|
36
|
+
return { meter, ...(await resolveHistoryTokens(args.input, args.family)) };
|
|
37
|
+
}
|
|
38
|
+
if (args.prompt && args.prompt.input > 0) {
|
|
39
|
+
return { meter, tokens: args.prompt.input, unknownMedia: args.prompt.unknownMedia?.input ?? 0 };
|
|
40
|
+
}
|
|
41
|
+
const fromHost = args.input?.inputTokens;
|
|
42
|
+
if (fromHost == null || fromHost <= 0)
|
|
43
|
+
return undefined;
|
|
44
|
+
return { meter, tokens: fromHost, unknownMedia: 0 };
|
|
45
|
+
}
|
|
46
|
+
export function compactionNeeded(tokens, spec) {
|
|
47
|
+
return tokens > spec.compactAt * spec.maxTokens;
|
|
48
|
+
}
|
|
49
|
+
/** `spec.trigger`, when set, decides alone; otherwise the token threshold does. */
|
|
50
|
+
export async function shouldCompact(resolved, spec) {
|
|
51
|
+
if (spec.trigger) {
|
|
52
|
+
const ctx = {
|
|
53
|
+
tokens: resolved.tokens,
|
|
54
|
+
maxTokens: spec.maxTokens,
|
|
55
|
+
compactAt: spec.compactAt,
|
|
56
|
+
meter: resolved.meter,
|
|
57
|
+
unknownMedia: resolved.unknownMedia,
|
|
58
|
+
};
|
|
59
|
+
return await spec.trigger(ctx);
|
|
60
|
+
}
|
|
61
|
+
return compactionNeeded(resolved.tokens, spec);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `previousExchanges` semantics:
|
|
65
|
+
* - `0` — compact everything, retain nothing.
|
|
66
|
+
* - `≥ 1` (integer) — retain the last N exchanges.
|
|
67
|
+
* - `(0, 1)` — retain exchanges that fit within this fraction of `maxTokens`,
|
|
68
|
+
* walking backwards from the most recent (token estimator; unknown media is
|
|
69
|
+
* not counted).
|
|
70
|
+
*/
|
|
71
|
+
export async function splitForCompaction(history, spec, family) {
|
|
72
|
+
if (history.length === 0) {
|
|
73
|
+
return { toCompact: [], toRetain: [] };
|
|
74
|
+
}
|
|
75
|
+
if (spec.previousExchanges === 0) {
|
|
76
|
+
return { toCompact: [...history], toRetain: [] };
|
|
77
|
+
}
|
|
78
|
+
const boundaries = findExchangeBoundaries(history);
|
|
79
|
+
if (boundaries.length === 0) {
|
|
80
|
+
return { toCompact: [...history], toRetain: [] };
|
|
81
|
+
}
|
|
82
|
+
let cutIndex;
|
|
83
|
+
if (spec.previousExchanges >= 1) {
|
|
84
|
+
const keep = Math.min(spec.previousExchanges, boundaries.length);
|
|
85
|
+
cutIndex = boundaries[boundaries.length - keep];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const budget = spec.previousExchanges * spec.maxTokens;
|
|
89
|
+
const estimator = await loadTokenEstimator();
|
|
90
|
+
let accumulated = 0;
|
|
91
|
+
cutIndex = history.length;
|
|
92
|
+
for (let i = boundaries.length - 1; i >= 0; i--) {
|
|
93
|
+
const exchangeStart = boundaries[i];
|
|
94
|
+
const exchangeEnd = i < boundaries.length - 1 ? boundaries[i + 1] : history.length;
|
|
95
|
+
const exchangeMessages = history.slice(exchangeStart, exchangeEnd);
|
|
96
|
+
const exchangeTokens = (await estimator.messages(exchangeMessages, family)).tokens;
|
|
97
|
+
if (accumulated + exchangeTokens > budget) {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
accumulated += exchangeTokens;
|
|
101
|
+
cutIndex = exchangeStart;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (cutIndex <= 0) {
|
|
105
|
+
return { toCompact: [], toRetain: [...history] };
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
toCompact: history.slice(0, cutIndex),
|
|
109
|
+
toRetain: history.slice(cutIndex),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function isCompactionSummary(message) {
|
|
113
|
+
return message.metadata?.compactionSummary === true;
|
|
114
|
+
}
|
|
115
|
+
function textPart(text) {
|
|
116
|
+
return { type: 'text', text };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* `toCompact` as the compactor reads it: media its profile does not accept is
|
|
120
|
+
* left out, and tool calls and results become the assistant's text, so no
|
|
121
|
+
* provider needs the tools declared to read them.
|
|
122
|
+
*/
|
|
123
|
+
export function compactorHistory(toCompact, compactor) {
|
|
124
|
+
const lexicon = compactor.lexicon;
|
|
125
|
+
const toolNames = new Map();
|
|
126
|
+
let droppedMedia = 0;
|
|
127
|
+
const readable = (parts) => (parts ?? []).filter((part) => {
|
|
128
|
+
if (part.type === 'text' || mediaChannelForMime(compactor, part.mimeType))
|
|
129
|
+
return true;
|
|
130
|
+
droppedMedia += 1;
|
|
131
|
+
return false;
|
|
132
|
+
});
|
|
133
|
+
const history = [];
|
|
134
|
+
for (const message of toCompact) {
|
|
135
|
+
for (const call of message.tool_calls ?? [])
|
|
136
|
+
toolNames.set(call.id, call.function.name);
|
|
137
|
+
const parts = readable(message.parts);
|
|
138
|
+
if (message.role === 'tool') {
|
|
139
|
+
const tool = message.name ?? (message.tool_call_id ? toolNames.get(message.tool_call_id) : undefined);
|
|
140
|
+
const result = message.content ?? '';
|
|
141
|
+
history.push({
|
|
142
|
+
role: 'assistant',
|
|
143
|
+
parts: [
|
|
144
|
+
textPart(lexiconText('compaction.tool_result', { tool: tool ?? '', result }, lexicon)),
|
|
145
|
+
...parts,
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const calls = (message.tool_calls ?? []).map((call) => textPart(lexiconText('compaction.tool_call', { tool: call.function.name, arguments: call.function.arguments }, lexicon)));
|
|
151
|
+
const all = [...parts, ...calls];
|
|
152
|
+
if (!message.content && all.length === 0)
|
|
153
|
+
continue;
|
|
154
|
+
history.push({
|
|
155
|
+
role: message.role,
|
|
156
|
+
...(message.content ? { content: message.content } : {}),
|
|
157
|
+
...(all.length > 0 ? { parts: all } : {}),
|
|
158
|
+
...(message.name ? { name: message.name } : {}),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return { history, droppedMedia };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The history after one compaction. A failed compactor never leaves a hollow
|
|
165
|
+
* summary: under `maxTokens` the history stays whole for the next turn to try
|
|
166
|
+
* again; over it, `toCompact` is dropped (keeping any earlier summary) so the
|
|
167
|
+
* turn still fits.
|
|
168
|
+
*/
|
|
169
|
+
export function compactionResult(split, run, tokens, spec) {
|
|
170
|
+
const shared = {
|
|
171
|
+
toCompact: split.toCompact,
|
|
172
|
+
droppedMedia: run.droppedMedia,
|
|
173
|
+
...(run.tokens ? { tokens: run.tokens } : {}),
|
|
174
|
+
};
|
|
175
|
+
if ('summary' in run) {
|
|
176
|
+
const summary = {
|
|
177
|
+
role: 'assistant',
|
|
178
|
+
content: run.summary,
|
|
179
|
+
metadata: { compactionSummary: true },
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
...shared,
|
|
183
|
+
outcome: 'compacted',
|
|
184
|
+
summary: run.summary,
|
|
185
|
+
history: [summary, ...split.toRetain],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (tokens > spec.maxTokens) {
|
|
189
|
+
return {
|
|
190
|
+
...shared,
|
|
191
|
+
outcome: 'dropped',
|
|
192
|
+
failure: run.failure,
|
|
193
|
+
history: [...split.toCompact.filter(isCompactionSummary), ...split.toRetain],
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
...shared,
|
|
198
|
+
outcome: 'deferred',
|
|
199
|
+
failure: run.failure,
|
|
200
|
+
history: [...split.toCompact, ...split.toRetain],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
2
|
+
import type { TraceSink } from '../../observability/trace-sink.js';
|
|
3
|
+
import type { KernelRegistry } from '../registry/kernel-registry.js';
|
|
4
|
+
import type { DecisionProfile, DecisionRequest, DecisionResult, KeyVault } from '../types.js';
|
|
5
|
+
declare const DECISION_ERROR_KINDS: {
|
|
6
|
+
readonly invalid_request: "request";
|
|
7
|
+
readonly authentication: "auth";
|
|
8
|
+
readonly permission: "auth";
|
|
9
|
+
readonly rate_limited: "rate_limit";
|
|
10
|
+
readonly unavailable: "unavailable";
|
|
11
|
+
readonly network: "network";
|
|
12
|
+
readonly timeout: "timeout";
|
|
13
|
+
readonly cancelled: "cancelled";
|
|
14
|
+
readonly malformed_response: "bad_response";
|
|
15
|
+
readonly disclosure_blocked: "blocked";
|
|
16
|
+
};
|
|
17
|
+
/** A normalized native-decision failure; response bodies are deliberately omitted. */
|
|
18
|
+
export declare class DecisionError extends TheoremError {
|
|
19
|
+
readonly code: keyof typeof DECISION_ERROR_KINDS;
|
|
20
|
+
readonly status?: number | undefined;
|
|
21
|
+
constructor(code: keyof typeof DECISION_ERROR_KINDS, message: string, status?: number | undefined);
|
|
22
|
+
}
|
|
23
|
+
export interface RunDecisionOptions {
|
|
24
|
+
/** The host's keys by slot; the profile's `key` (or its model's) names the slot. */
|
|
25
|
+
vault?: KeyVault;
|
|
26
|
+
fetch?: typeof globalThis.fetch;
|
|
27
|
+
endpoint?: string;
|
|
28
|
+
/** Replaces the profile's `observability.writeTo`; an explicit sink always records, unsampled. */
|
|
29
|
+
sink?: TraceSink;
|
|
30
|
+
}
|
|
31
|
+
/** Check a decision before a host spends quota or dispatches it. Does not apply model-specific policy. */
|
|
32
|
+
export declare function validateDecisionRequest(request: Omit<DecisionRequest, 'state' | 'questions'> & {
|
|
33
|
+
state: unknown;
|
|
34
|
+
questions: unknown;
|
|
35
|
+
}, profile: DecisionProfile): asserts request is DecisionRequest;
|
|
36
|
+
/**
|
|
37
|
+
* Exactly one decision request, traced however it ends. An ambiguous POST is never retried,
|
|
38
|
+
* and a trace write failure never changes the decision's outcome.
|
|
39
|
+
*/
|
|
40
|
+
export declare function runDecisionInRegistry(registry: KernelRegistry, request: DecisionRequest, options: RunDecisionOptions): Promise<DecisionResult>;
|
|
41
|
+
export {};
|