@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,263 @@
|
|
|
1
|
+
import { TheoremError } from '../../../guardrails/error.js';
|
|
2
|
+
import { historyMessageParts, wireInteractionPart } from '../../../kernel/interaction-parts.js';
|
|
3
|
+
import { GOOGLE_SPEECH_FORMATS } from '../../../presets/google-limits.js';
|
|
4
|
+
import { builtinWire } from '../../shared/builtin-wire.js';
|
|
5
|
+
import { historyToolArguments, historyToolIdentity } from '../../shared/tool-args.js';
|
|
6
|
+
import { assertGoogleThinkingLevel } from '../thinking.js';
|
|
7
|
+
export function camelToSnake(key) {
|
|
8
|
+
return key.replaceAll(/[A-Z]/g, (ch) => `_${ch.toLowerCase()}`);
|
|
9
|
+
}
|
|
10
|
+
export function toGoogleValue(value) {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return value.map(toGoogleValue);
|
|
13
|
+
}
|
|
14
|
+
if (value && typeof value === 'object') {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
17
|
+
// Schema property names stay as authored; snake-casing them breaks Gemini validation.
|
|
18
|
+
if (key === 'schema' || key === 'parameters') {
|
|
19
|
+
out[camelToSnake(key)] = nested;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
out[camelToSnake(key)] = toGoogleValue(nested);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
export function wirePart(part) {
|
|
29
|
+
return wireInteractionPart(part);
|
|
30
|
+
}
|
|
31
|
+
const USER_INPUT = 'user_input';
|
|
32
|
+
export function userInputStep(parts) {
|
|
33
|
+
return { type: USER_INPUT, content: parts.map(wirePart) };
|
|
34
|
+
}
|
|
35
|
+
function historyContent(msg) {
|
|
36
|
+
const parts = historyMessageParts(msg);
|
|
37
|
+
return parts.length > 0 ? parts.map(wirePart) : [{ type: 'text', text: '' }];
|
|
38
|
+
}
|
|
39
|
+
function functionResultStep(msg) {
|
|
40
|
+
const result = historyContent(msg);
|
|
41
|
+
return {
|
|
42
|
+
type: 'function_result',
|
|
43
|
+
...historyToolIdentity({ name: msg.name, call_id: msg.tool_call_id }),
|
|
44
|
+
result,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A history call as input steps: the thought that led to it when it carries
|
|
49
|
+
* that thought's signature, then the call. Google rejects a current-turn call
|
|
50
|
+
* replayed without its signature, and rejects a `thought_signature` field on
|
|
51
|
+
* the call; a `thought` step with the signature ahead of it is accepted (probe
|
|
52
|
+
* 25/09/2026, gemini-3.1-flash-lite, `store: false`).
|
|
53
|
+
*/
|
|
54
|
+
function functionCallSteps(call) {
|
|
55
|
+
const step = {
|
|
56
|
+
type: 'function_call',
|
|
57
|
+
id: call.id,
|
|
58
|
+
name: call.function.name,
|
|
59
|
+
arguments: historyToolArguments(call.function.arguments),
|
|
60
|
+
};
|
|
61
|
+
return call.thoughtSignature
|
|
62
|
+
? [{ type: 'thought', signature: call.thoughtSignature }, step]
|
|
63
|
+
: [step];
|
|
64
|
+
}
|
|
65
|
+
function textOrPartsStep(role, msg) {
|
|
66
|
+
// Assistant history is `model_output`, not `model_turn`.
|
|
67
|
+
const type = role === 'assistant' ? 'model_output' : 'user_input';
|
|
68
|
+
return { type, content: historyContent(msg) };
|
|
69
|
+
}
|
|
70
|
+
/** Assistant `tool_calls` (often with no `content`) become `function_call` steps, never empty `model_output`. */
|
|
71
|
+
export function historySteps(msg) {
|
|
72
|
+
if (msg.role === 'tool') {
|
|
73
|
+
return [functionResultStep(msg)];
|
|
74
|
+
}
|
|
75
|
+
if (msg.role === 'assistant' && msg.tool_calls && msg.tool_calls.length > 0) {
|
|
76
|
+
const steps = [];
|
|
77
|
+
if (historyMessageParts(msg).length > 0) {
|
|
78
|
+
steps.push(textOrPartsStep('assistant', msg));
|
|
79
|
+
}
|
|
80
|
+
for (const call of msg.tool_calls) {
|
|
81
|
+
steps.push(...functionCallSteps(call));
|
|
82
|
+
}
|
|
83
|
+
return steps;
|
|
84
|
+
}
|
|
85
|
+
if (msg.role === 'assistant') {
|
|
86
|
+
return [textOrPartsStep('assistant', msg)];
|
|
87
|
+
}
|
|
88
|
+
return [textOrPartsStep('user', msg)];
|
|
89
|
+
}
|
|
90
|
+
export function historyStep(msg) {
|
|
91
|
+
const steps = historySteps(msg);
|
|
92
|
+
return steps[0] ?? { type: 'user_input', content: [{ type: 'text', text: '' }] };
|
|
93
|
+
}
|
|
94
|
+
export function jsonResponseFormat(schema) {
|
|
95
|
+
return [{ type: 'text', mimeType: 'application/json', schema }];
|
|
96
|
+
}
|
|
97
|
+
export function attachResponseFormat(req, camel) {
|
|
98
|
+
if (req.speech) {
|
|
99
|
+
if (req.image) {
|
|
100
|
+
throw new TheoremError('config', 'cannot mix speech and image response formats');
|
|
101
|
+
}
|
|
102
|
+
if (req.structured) {
|
|
103
|
+
throw new TheoremError('config', 'cannot mix speech and structured response formats');
|
|
104
|
+
}
|
|
105
|
+
const format = req.speech.format;
|
|
106
|
+
if (format && !GOOGLE_SPEECH_FORMATS.includes(format)) {
|
|
107
|
+
throw new TheoremError('unsupported', `Gemini speech returns ${GOOGLE_SPEECH_FORMATS.join(', ')}, not '${format}'`);
|
|
108
|
+
}
|
|
109
|
+
camel.responseFormat = { type: 'audio' };
|
|
110
|
+
camel.responseModalities = ['audio'];
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (req.image) {
|
|
114
|
+
const imageEntry = {
|
|
115
|
+
type: 'image',
|
|
116
|
+
mimeType: req.image.mimeType,
|
|
117
|
+
};
|
|
118
|
+
if (req.image.aspectRatio) {
|
|
119
|
+
imageEntry.aspectRatio = req.image.aspectRatio;
|
|
120
|
+
}
|
|
121
|
+
if (req.image.resolution) {
|
|
122
|
+
imageEntry.imageSize = req.image.resolution;
|
|
123
|
+
}
|
|
124
|
+
for (const [name, value] of [
|
|
125
|
+
['quality', req.image.quality],
|
|
126
|
+
['background', req.image.background],
|
|
127
|
+
['n', req.image.n],
|
|
128
|
+
['outputCompression', req.image.outputCompression],
|
|
129
|
+
]) {
|
|
130
|
+
if (value !== undefined) {
|
|
131
|
+
throw new TheoremError('unsupported', `image.${name} is not supported on Google image models`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// An object asks for image only; an array for text + image.
|
|
135
|
+
camel.responseFormat = req.image.includeText ? [{ type: 'text' }, imageEntry] : imageEntry;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!req.structured) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
camel.responseFormat = jsonResponseFormat(req.structured.jsonSchema);
|
|
142
|
+
}
|
|
143
|
+
export function attachSpeechConfig(req, generationConfig) {
|
|
144
|
+
if (!req.speech) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const voice = req.speech.voice;
|
|
148
|
+
if (!voice) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
generationConfig.speechConfig = [{ voice }];
|
|
152
|
+
}
|
|
153
|
+
function wireInteractionsFunctionTool(decl) {
|
|
154
|
+
return {
|
|
155
|
+
type: 'function',
|
|
156
|
+
name: decl.name,
|
|
157
|
+
description: decl.description,
|
|
158
|
+
parameters: decl.parameters,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function wireGoogleMapsTool(req) {
|
|
162
|
+
const loc = req.googleMapsLocation;
|
|
163
|
+
if (loc && Number.isFinite(loc.latitude) && Number.isFinite(loc.longitude)) {
|
|
164
|
+
return {
|
|
165
|
+
type: 'google_maps',
|
|
166
|
+
latitude: loc.latitude,
|
|
167
|
+
longitude: loc.longitude,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return { type: 'google_maps' };
|
|
171
|
+
}
|
|
172
|
+
function wireInteractionsTools(req) {
|
|
173
|
+
const tools = [];
|
|
174
|
+
for (const builtin of req.builtins) {
|
|
175
|
+
const type = builtinWire(builtin, 'interactions');
|
|
176
|
+
if (type === 'google_maps') {
|
|
177
|
+
tools.push(wireGoogleMapsTool(req));
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
tools.push({ type });
|
|
181
|
+
}
|
|
182
|
+
for (const decl of req.wireTools ?? []) {
|
|
183
|
+
tools.push(wireInteractionsFunctionTool(decl));
|
|
184
|
+
}
|
|
185
|
+
return tools;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A `tool` message without `name` takes its call's name: Google rejects a
|
|
189
|
+
* `function_result` without one as "Invalid input received" (live, 29/09/2026).
|
|
190
|
+
*/
|
|
191
|
+
function withToolNames(messages) {
|
|
192
|
+
const names = new Map();
|
|
193
|
+
return messages.map((msg) => {
|
|
194
|
+
for (const call of msg.tool_calls ?? [])
|
|
195
|
+
names.set(call.id, call.function.name);
|
|
196
|
+
if (msg.role !== 'tool' || msg.name || !msg.tool_call_id)
|
|
197
|
+
return msg;
|
|
198
|
+
const name = names.get(msg.tool_call_id);
|
|
199
|
+
return name ? { ...msg, name } : msg;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
export function inputStepsFromRequest(req) {
|
|
203
|
+
if (req.continuation && req.continuation.length > 0) {
|
|
204
|
+
return withToolNames(req.continuation).flatMap((msg) => historySteps(msg));
|
|
205
|
+
}
|
|
206
|
+
const inputSteps = [];
|
|
207
|
+
for (const h of withToolNames(req.history ?? [])) {
|
|
208
|
+
inputSteps.push(...historySteps(h));
|
|
209
|
+
}
|
|
210
|
+
if (req.input.length > 0 || inputSteps.length === 0) {
|
|
211
|
+
inputSteps.push(userInputStep(req.input));
|
|
212
|
+
}
|
|
213
|
+
return inputSteps;
|
|
214
|
+
}
|
|
215
|
+
export function applyOptionalRequestFields(req, camel) {
|
|
216
|
+
if (req.store !== undefined) {
|
|
217
|
+
camel.store = req.store;
|
|
218
|
+
}
|
|
219
|
+
if (req.previousInteractionId) {
|
|
220
|
+
camel.previousInteractionId = req.previousInteractionId;
|
|
221
|
+
}
|
|
222
|
+
if (req.system) {
|
|
223
|
+
camel.systemInstruction = req.system;
|
|
224
|
+
}
|
|
225
|
+
const tools = wireInteractionsTools(req);
|
|
226
|
+
if (tools.length > 0) {
|
|
227
|
+
camel.tools = tools;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
export function baseInteractionsBody(req) {
|
|
231
|
+
const generationConfig = {
|
|
232
|
+
temperature: req.temperature,
|
|
233
|
+
maxOutputTokens: req.maxOutputTokens,
|
|
234
|
+
};
|
|
235
|
+
if (req.speech) {
|
|
236
|
+
// TTS models reject chat thinking knobs; voice lives under speech_config.
|
|
237
|
+
attachSpeechConfig(req, generationConfig);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
assertGoogleThinkingLevel(req.thinking);
|
|
241
|
+
if (req.thinking) {
|
|
242
|
+
generationConfig.thinkingLevel = req.thinking;
|
|
243
|
+
}
|
|
244
|
+
if (req.summaries) {
|
|
245
|
+
generationConfig.thinkingSummaries = req.summaries;
|
|
246
|
+
}
|
|
247
|
+
if (req.image?.seed !== undefined) {
|
|
248
|
+
generationConfig.seed = req.image.seed;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
model: req.apiId,
|
|
253
|
+
stream: req.stream ?? true,
|
|
254
|
+
input: inputStepsFromRequest(req),
|
|
255
|
+
generationConfig,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
export function toInteractionsBody(req) {
|
|
259
|
+
const body = baseInteractionsBody(req);
|
|
260
|
+
attachResponseFormat(req, body);
|
|
261
|
+
applyOptionalRequestFields(req, body);
|
|
262
|
+
return toGoogleValue(body);
|
|
263
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProviderEvent, TurnEventOf, TurnResponse } from '../../../kernel/types.js';
|
|
2
|
+
declare function isCodeExecutionType(type: string): boolean;
|
|
3
|
+
declare function isGoogleBuiltinStepType(type: string): boolean;
|
|
4
|
+
declare function rawStepEvidence(raw: Record<string, unknown>): TurnEventOf<'evidence'>;
|
|
5
|
+
declare function codeExecutionEvidence(raw: Record<string, unknown>): TurnEventOf<'evidence'>;
|
|
6
|
+
declare function eventsFromDelta(deltaValue: unknown): ProviderEvent[];
|
|
7
|
+
declare function eventsFromThoughtStep(step: Record<string, unknown>): ProviderEvent[];
|
|
8
|
+
declare function eventsFromModelOutputStep(step: Record<string, unknown>): ProviderEvent[];
|
|
9
|
+
declare function extractTokenEvent(interaction: Record<string, unknown>): TurnEventOf<'tokens'> | undefined;
|
|
10
|
+
declare function eventsFromInteractionEnd(interaction: Record<string, unknown>): ProviderEvent[];
|
|
11
|
+
declare function interactionResponse(interaction: Record<string, unknown>): TurnResponse | undefined;
|
|
12
|
+
export { codeExecutionEvidence, eventsFromDelta, eventsFromInteractionEnd, eventsFromModelOutputStep, eventsFromThoughtStep, extractTokenEvent, interactionResponse, isCodeExecutionType, isGoogleBuiltinStepType, rawStepEvidence, };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { asRecord, nonEmptyString } from '../../../kernel/engine/record.js';
|
|
2
|
+
import { reportedTokens, usageCount } from '../../../kernel/engine/usage.js';
|
|
3
|
+
import { turnStopFromInteractionStatus } from '../../../kernel/stop.js';
|
|
4
|
+
import { groundingFromSteps } from '../grounding.js';
|
|
5
|
+
import { byModality, groundingCounts, modalityCounts } from '../usage.js';
|
|
6
|
+
/*
|
|
7
|
+
* Interactions steps and deltas read only the shapes recorded from the wire
|
|
8
|
+
* (probes 23/09/2026, gemini-3.8-flash, gemini-3.1-pro-preview, image and TTS
|
|
9
|
+
* models, streamed and buffered):
|
|
10
|
+
*
|
|
11
|
+
* - `text` deltas carry `text`; `thought_summary` deltas carry
|
|
12
|
+
* `content: { type: 'text', text }`; buffered `thought` steps carry
|
|
13
|
+
* `summary[]` of the same text blocks.
|
|
14
|
+
* - `image` / `audio` deltas and `model_output` content blocks carry
|
|
15
|
+
* `mime_type` + `data`. Audio also reports `sample_rate` / `channels`; the
|
|
16
|
+
* buffered mime already states them (`audio/l16; rate=24000; channels=1`),
|
|
17
|
+
* the streamed one does not (`audio/l16`), so they are folded into the mime.
|
|
18
|
+
* - `code_execution_call` carries `id` and `arguments: { language, code }`;
|
|
19
|
+
* `code_execution_result` carries `call_id`, `result` and `is_error`. Each
|
|
20
|
+
* arrives whole, in one delta (5 577 characters of code in one probe).
|
|
21
|
+
*/
|
|
22
|
+
function thoughtText(content) {
|
|
23
|
+
const block = asRecord(content);
|
|
24
|
+
return block?.type === 'text' && typeof block.text === 'string' ? block.text : '';
|
|
25
|
+
}
|
|
26
|
+
function interactionsMime(rec) {
|
|
27
|
+
const mime = rec.mime_type;
|
|
28
|
+
if (typeof mime !== 'string' || !mime) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const params = mime.toLowerCase();
|
|
32
|
+
const extra = [];
|
|
33
|
+
if (typeof rec.sample_rate === 'number' && !/;\s*rate=/.test(params)) {
|
|
34
|
+
extra.push(`rate=${String(rec.sample_rate)}`);
|
|
35
|
+
}
|
|
36
|
+
if (typeof rec.channels === 'number' && !/;\s*channels=/.test(params)) {
|
|
37
|
+
extra.push(`channels=${String(rec.channels)}`);
|
|
38
|
+
}
|
|
39
|
+
return extra.length > 0 ? `${mime}; ${extra.join('; ')}` : mime;
|
|
40
|
+
}
|
|
41
|
+
function interactionsMedia(rec) {
|
|
42
|
+
const mimeType = interactionsMime(rec);
|
|
43
|
+
const { data } = rec;
|
|
44
|
+
if (!mimeType || typeof data !== 'string' || !data) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
return [{ type: 'media', media: { mimeType, data } }];
|
|
48
|
+
}
|
|
49
|
+
function textEvent(type, text) {
|
|
50
|
+
return text ? [{ type, text }] : [];
|
|
51
|
+
}
|
|
52
|
+
function isCodeExecutionType(type) {
|
|
53
|
+
return type === 'code_execution_call' || type === 'code_execution_result';
|
|
54
|
+
}
|
|
55
|
+
function isGoogleBuiltinStepType(type) {
|
|
56
|
+
return type.startsWith('google_') || type === 'url_context_call' || type === 'url_context_result';
|
|
57
|
+
}
|
|
58
|
+
function rawStepEvidence(raw) {
|
|
59
|
+
return {
|
|
60
|
+
type: 'evidence',
|
|
61
|
+
evidence: { provider: 'google', kind: 'provider_step', step: String(raw.type ?? ''), raw },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function codeExecutionEvidence(raw) {
|
|
65
|
+
if (raw.type === 'code_execution_result') {
|
|
66
|
+
const callId = nonEmptyString(raw.call_id);
|
|
67
|
+
return {
|
|
68
|
+
type: 'evidence',
|
|
69
|
+
evidence: {
|
|
70
|
+
provider: 'google',
|
|
71
|
+
kind: 'code_execution_result',
|
|
72
|
+
raw,
|
|
73
|
+
...(typeof raw.result === 'string' ? { result: raw.result } : {}),
|
|
74
|
+
...(typeof raw.is_error === 'boolean' ? { isError: raw.is_error } : {}),
|
|
75
|
+
...(callId ? { callId } : {}),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const args = asRecord(raw.arguments);
|
|
80
|
+
const id = nonEmptyString(raw.id);
|
|
81
|
+
if (raw.type !== 'code_execution_call' || !id || typeof args?.code !== 'string') {
|
|
82
|
+
return rawStepEvidence(raw);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
type: 'evidence',
|
|
86
|
+
evidence: {
|
|
87
|
+
provider: 'google',
|
|
88
|
+
kind: 'code_execution_call',
|
|
89
|
+
raw,
|
|
90
|
+
code: args.code,
|
|
91
|
+
...(typeof args.language === 'string' ? { language: args.language } : {}),
|
|
92
|
+
id,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function eventsFromDelta(deltaValue) {
|
|
97
|
+
const delta = asRecord(deltaValue);
|
|
98
|
+
if (!delta) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
switch (delta.type) {
|
|
102
|
+
case 'thought_summary':
|
|
103
|
+
return textEvent('thought', thoughtText(delta.content));
|
|
104
|
+
case 'text':
|
|
105
|
+
return textEvent('text', typeof delta.text === 'string' ? delta.text : '');
|
|
106
|
+
case 'image':
|
|
107
|
+
case 'audio':
|
|
108
|
+
return interactionsMedia(delta);
|
|
109
|
+
default:
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function eventsFromThoughtStep(step) {
|
|
114
|
+
const summary = Array.isArray(step.summary) ? step.summary : [];
|
|
115
|
+
return summary.flatMap((block) => textEvent('thought', thoughtText(block)));
|
|
116
|
+
}
|
|
117
|
+
function eventsFromModelOutputStep(step) {
|
|
118
|
+
const content = Array.isArray(step.content) ? step.content : [];
|
|
119
|
+
return content.flatMap((block) => {
|
|
120
|
+
const rec = asRecord(block);
|
|
121
|
+
if (rec?.type === 'text') {
|
|
122
|
+
return textEvent('text', typeof rec.text === 'string' ? rec.text : '');
|
|
123
|
+
}
|
|
124
|
+
if (rec?.type === 'image' || rec?.type === 'audio') {
|
|
125
|
+
return interactionsMedia(rec);
|
|
126
|
+
}
|
|
127
|
+
return [];
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Google reports thought and tool-use tokens beside input and output; the
|
|
132
|
+
* OpenTelemetry meanings fold them in. Probes (gemini-3.8-flash, 22/09/2026):
|
|
133
|
+
* `total_tokens` = input + output + thought + tool use, and cached sits inside input.
|
|
134
|
+
* For inputs Google converts first (Markdown, Python, mono `audio/L16`, …) input
|
|
135
|
+
* comes back 0 while `total_tokens` holds the full sum, so input is derived from it.
|
|
136
|
+
*/
|
|
137
|
+
function interactionsUsageTokens(raw) {
|
|
138
|
+
const usage = asRecord(raw);
|
|
139
|
+
if (!usage)
|
|
140
|
+
return undefined;
|
|
141
|
+
const output = usageCount(usage.total_output_tokens);
|
|
142
|
+
const thought = usageCount(usage.total_thought_tokens) ?? 0;
|
|
143
|
+
const toolUse = usageCount(usage.total_tool_use_tokens) ?? 0;
|
|
144
|
+
const total = usageCount(usage.total_tokens);
|
|
145
|
+
const derived = total === undefined ? undefined : total - (output ?? 0) - thought - toolUse;
|
|
146
|
+
const read = usageCount(usage.total_input_tokens) || (derived && derived > 0 ? derived : 0);
|
|
147
|
+
return reportedTokens({
|
|
148
|
+
input: read ? read + toolUse : undefined,
|
|
149
|
+
output: output === undefined ? undefined : output + thought,
|
|
150
|
+
thinking: thought,
|
|
151
|
+
toolUse,
|
|
152
|
+
cached: usageCount(usage.total_cached_tokens),
|
|
153
|
+
byModality: byModality(modalityCounts(usage.input_tokens_by_modality, 'tokens'), modalityCounts(usage.output_tokens_by_modality, 'tokens')),
|
|
154
|
+
grounding: groundingCounts(usage.grounding_tool_count),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function extractTokenEvent(interaction) {
|
|
158
|
+
const usage = interactionsUsageTokens(interaction.usage);
|
|
159
|
+
if (!usage) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
const interactionId = typeof interaction.id === 'string' ? interaction.id : undefined;
|
|
163
|
+
return {
|
|
164
|
+
type: 'tokens',
|
|
165
|
+
tokens: usage,
|
|
166
|
+
...(interactionId ? { interactionId } : {}),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function eventsFromInteractionEnd(interaction) {
|
|
170
|
+
const events = [];
|
|
171
|
+
const tokenEvent = extractTokenEvent(interaction);
|
|
172
|
+
if (tokenEvent)
|
|
173
|
+
events.push(tokenEvent);
|
|
174
|
+
// Only a buffered body carries `steps[]`; streamed grounding arrives on deltas.
|
|
175
|
+
const { steps } = interaction;
|
|
176
|
+
if (Array.isArray(steps))
|
|
177
|
+
events.push(...groundingFromSteps(steps));
|
|
178
|
+
const done = doneFromInteractionStatus(interaction);
|
|
179
|
+
if (done)
|
|
180
|
+
events.push(done);
|
|
181
|
+
return events;
|
|
182
|
+
}
|
|
183
|
+
function interactionResponse(interaction) {
|
|
184
|
+
const id = nonEmptyString(interaction.id);
|
|
185
|
+
const model = nonEmptyString(interaction.model);
|
|
186
|
+
if (!id && !model)
|
|
187
|
+
return undefined;
|
|
188
|
+
return { ...(id ? { id } : {}), ...(model ? { model } : {}) };
|
|
189
|
+
}
|
|
190
|
+
function doneFromInteractionStatus(interaction) {
|
|
191
|
+
const { status } = interaction;
|
|
192
|
+
if (typeof status !== 'string')
|
|
193
|
+
return undefined;
|
|
194
|
+
return {
|
|
195
|
+
type: 'done',
|
|
196
|
+
stop: turnStopFromInteractionStatus(status),
|
|
197
|
+
...(typeof interaction.id === 'string' ? { interactionId: interaction.id } : {}),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
export { codeExecutionEvidence, eventsFromDelta, eventsFromInteractionEnd, eventsFromModelOutputStep, eventsFromThoughtStep, extractTokenEvent, interactionResponse, isCodeExecutionType, isGoogleBuiltinStepType, rawStepEvidence, };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ModelProvider, ProviderCompleteRequest, ProviderEvent, TurnResponse } from '../../../kernel/types.js';
|
|
2
|
+
import { type GeminiTransport } from '../keys.js';
|
|
3
|
+
export interface StreamFold {
|
|
4
|
+
text: string;
|
|
5
|
+
/** Open `function_call`, `code_execution_*` and builtin steps by `index`. */
|
|
6
|
+
steps: Map<number, Record<string, unknown>>;
|
|
7
|
+
sawMedia: boolean;
|
|
8
|
+
/** A `done` came out: the interaction reported a status. */
|
|
9
|
+
sawDone: boolean;
|
|
10
|
+
/** Identity named so far: `interaction.created` names it before any output, so a cut call still has it. */
|
|
11
|
+
response?: TurnResponse;
|
|
12
|
+
/** The signature of the last thought, until the `function_call` that follows it takes it. */
|
|
13
|
+
thoughtSignature?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function newStreamFold(): StreamFold;
|
|
16
|
+
export declare function eventsFromStep(step: Record<string, unknown>, fold: StreamFold): ProviderEvent[];
|
|
17
|
+
export declare function openStepEvents(fold: StreamFold): ProviderEvent[];
|
|
18
|
+
export declare function foldPayload(payload: Record<string, unknown>, fold: StreamFold): ProviderEvent[];
|
|
19
|
+
export declare function foldBody(body: Record<string, unknown>, fold: StreamFold): ProviderEvent[];
|
|
20
|
+
export declare function finalizeStructured(req: ProviderCompleteRequest, fold: StreamFold): Generator<ProviderEvent>;
|
|
21
|
+
export declare function isVoiceProfile(req: ProviderCompleteRequest): boolean;
|
|
22
|
+
/** What the profile asked for and the model did not return; even an empty turn fails. */
|
|
23
|
+
export declare function missingMediaError(req: ProviderCompleteRequest, fold: StreamFold): ProviderEvent | undefined;
|
|
24
|
+
export declare function createInteractionsProvider(transport: GeminiTransport): ModelProvider;
|