@theoremjs/agents 0.3.0 → 0.3.2
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/README.md +277 -995
- package/esm/mod.d.ts +34 -20
- package/esm/mod.js +19 -12
- package/esm/src/cli/commands/bench.js +36 -14
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -0
- package/esm/src/cli/commands/eval.d.ts +3 -3
- package/esm/src/cli/commands/fuzz-canary.js +55 -16
- package/esm/src/cli/commands/profile.js +4 -4
- package/esm/src/cli/commands/run.d.ts +2 -2
- package/esm/src/cli/commands/run.js +1 -1
- package/esm/src/cli/commands/test.d.ts +4 -3
- package/esm/src/cli/commands/test.js +2 -2
- package/esm/src/cli/index.js +9 -9
- package/esm/src/cli/matrix/fixtures.js +25 -30
- package/esm/src/evals/attachments.d.ts +1 -0
- package/esm/src/evals/attachments.js +4 -2
- package/esm/src/evals/breakdown.d.ts +2 -0
- package/esm/src/evals/breakdown.js +1 -0
- package/esm/src/evals/graders/answer.d.ts +3 -0
- package/esm/src/evals/graders/answer.js +1 -0
- package/esm/src/evals/graders/code.d.ts +7 -31
- package/esm/src/evals/graders/code.js +4 -25
- package/esm/src/evals/graders/judge.d.ts +4 -0
- package/esm/src/evals/graders/judge.js +7 -5
- package/esm/src/evals/graders/latency.d.ts +1 -0
- package/esm/src/evals/graders/latency.js +3 -2
- package/esm/src/evals/graders/live.d.ts +3 -0
- package/esm/src/evals/graders/live.js +2 -0
- package/esm/src/evals/graders/media.js +1 -2
- package/esm/src/evals/graders/shared.js +1 -1
- package/esm/src/evals/graders/transcript.d.ts +2 -0
- package/esm/src/evals/graders/transcript.js +5 -3
- package/esm/src/evals/mod.d.ts +1 -9
- package/esm/src/evals/mod.js +1 -9
- package/esm/src/evals/record.d.ts +6 -0
- package/esm/src/evals/record.js +4 -2
- package/esm/src/evals/rubrics/mod.d.ts +1 -1
- package/esm/src/evals/rubrics/mod.js +1 -1
- package/esm/src/evals/rubrics/mustache.js +1 -1
- package/esm/src/evals/rubrics/types.js +1 -1
- package/esm/src/evals/run.d.ts +9 -52
- package/esm/src/evals/run.js +12 -46
- package/esm/src/evals/suite.d.ts +12 -3
- package/esm/src/evals/suite.js +9 -4
- package/esm/src/evals/summary.d.ts +3 -0
- package/esm/src/evals/summary.js +1 -0
- package/esm/src/evals/trial.d.ts +3 -16
- package/esm/src/evals/trial.js +7 -30
- package/esm/src/evals/types.d.ts +30 -121
- package/esm/src/evals/types.js +3 -16
- package/esm/src/evals/verdict.d.ts +5 -0
- package/esm/src/evals/verdict.js +4 -1
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +1 -0
- package/esm/src/guardrails/canary.d.ts +49 -15
- package/esm/src/guardrails/canary.js +103 -30
- package/esm/src/guardrails/compile-egress.d.ts +6 -5
- package/esm/src/guardrails/compile-egress.js +6 -5
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +3 -1
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +4 -2
- package/esm/src/guardrails/corpus/fuzz-inbound.js +14 -17
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +2 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +4 -2
- package/esm/src/guardrails/corpus/live-attacks.d.ts +2 -0
- package/esm/src/guardrails/corpus/live-attacks.js +6 -1
- package/esm/src/guardrails/corpus/mod.d.ts +1 -1
- package/esm/src/guardrails/corpus/secrets.d.ts +3 -3
- package/esm/src/guardrails/corpus/secrets.js +2 -2
- package/esm/src/guardrails/corpus/strings.d.ts +1 -1
- package/esm/src/guardrails/corpus/strings.js +1 -1
- package/esm/src/guardrails/corpus/types.d.ts +5 -1
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +4 -6
- package/esm/src/guardrails/egress-automata.js +24095 -4572
- package/esm/src/guardrails/egress-compiler.d.ts +38 -16
- package/esm/src/guardrails/egress-compiler.js +254 -60
- package/esm/src/guardrails/egress-patterns.d.ts +4 -2
- package/esm/src/guardrails/egress-patterns.js +6 -2
- package/esm/src/guardrails/egress-stream.d.ts +54 -36
- package/esm/src/guardrails/egress-stream.js +253 -124
- package/esm/src/guardrails/egress-urls.d.ts +6 -3
- package/esm/src/guardrails/egress-urls.js +14 -22
- package/esm/src/guardrails/egress.d.ts +26 -86
- package/esm/src/guardrails/egress.js +59 -309
- package/esm/src/guardrails/error.d.ts +13 -8
- package/esm/src/guardrails/error.js +25 -18
- package/esm/src/guardrails/event-schemas.d.ts +46 -3
- package/esm/src/guardrails/event-schemas.js +12 -5
- package/esm/src/guardrails/events.d.ts +5 -1
- package/esm/src/guardrails/events.js +4 -1
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +7 -1
- package/esm/src/guardrails/hits.js +12 -1
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +6 -1
- package/esm/src/guardrails/injection-patterns.js +33 -1
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +17 -1
- package/esm/src/guardrails/injection.js +259 -36
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +881 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +9 -8
- package/esm/src/guardrails/live-outbound-gate.js +100 -107
- package/esm/src/guardrails/mod.d.ts +30 -22
- package/esm/src/guardrails/mod.js +19 -14
- package/esm/src/guardrails/network.d.ts +4 -0
- package/esm/src/guardrails/network.js +21 -19
- package/esm/src/guardrails/normalize.d.ts +15 -1
- package/esm/src/guardrails/normalize.js +34 -1
- package/esm/src/guardrails/policy.d.ts +2 -17
- package/esm/src/guardrails/policy.js +12 -41
- package/esm/src/guardrails/progressive-yield.d.ts +65 -24
- package/esm/src/guardrails/progressive-yield.js +191 -147
- package/esm/src/guardrails/prompt-echo.d.ts +4 -2
- package/esm/src/guardrails/prompt-echo.js +87 -6
- package/esm/src/guardrails/quota.d.ts +4 -1
- package/esm/src/guardrails/quota.js +7 -2
- package/esm/src/guardrails/rules.d.ts +20 -29
- package/esm/src/guardrails/rules.js +23 -30
- package/esm/src/guardrails/sanitize.d.ts +32 -15
- package/esm/src/guardrails/sanitize.js +100 -124
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +16 -23
- package/esm/src/guardrails/sensitive.js +168 -47
- package/esm/src/guardrails/serialize.d.ts +1 -0
- package/esm/src/guardrails/testing.d.ts +4 -2
- package/esm/src/guardrails/testing.js +4 -2
- package/esm/src/guardrails/theorem-error.d.ts +5 -2
- package/esm/src/guardrails/theorem-error.js +6 -3
- package/esm/src/guardrails/thought-guard.d.ts +34 -13
- package/esm/src/guardrails/thought-guard.js +264 -64
- package/esm/src/guardrails/tool-directives.d.ts +29 -10
- package/esm/src/guardrails/tool-directives.js +133 -47
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +45 -14
- package/esm/src/guardrails/tool-result.js +94 -70
- package/esm/src/guardrails/types.d.ts +79 -71
- package/esm/src/guardrails/types.js +11 -7
- package/esm/src/host/client-turn.d.ts +29 -2
- package/esm/src/host/client-turn.js +46 -4
- package/esm/src/host/mint-trace.d.ts +1 -0
- package/esm/src/host/mint-trace.js +3 -2
- package/esm/src/host/mod.d.ts +2 -2
- package/esm/src/host/mod.js +1 -1
- package/esm/src/host/readStreamingJsonStringField.js +2 -43
- package/esm/src/host/reply.d.ts +6 -0
- package/esm/src/host/reply.js +8 -1
- package/esm/src/interface/blocks.d.ts +3 -0
- package/esm/src/interface/blocks.js +84 -14
- package/esm/src/interface/composer-actions.d.ts +4 -0
- package/esm/src/interface/composer-actions.js +5 -3
- package/esm/src/interface/draft.d.ts +6 -0
- package/esm/src/interface/draft.js +22 -11
- package/esm/src/interface/from-profile.d.ts +13 -1
- package/esm/src/interface/from-profile.js +66 -31
- package/esm/src/interface/history.d.ts +9 -3
- package/esm/src/interface/history.js +33 -24
- package/esm/src/interface/inputs.d.ts +1 -0
- package/esm/src/interface/inputs.js +3 -0
- package/esm/src/interface/mod.d.ts +4 -2
- package/esm/src/interface/mod.js +3 -2
- package/esm/src/interface/models.d.ts +7 -0
- package/esm/src/interface/models.js +5 -0
- package/esm/src/interface/pending.d.ts +9 -0
- package/esm/src/interface/pending.js +9 -3
- package/esm/src/interface/profile-interface.js +54 -40
- package/esm/src/interface/session.d.ts +12 -5
- package/esm/src/interface/session.js +17 -10
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +14 -2
- package/esm/src/interface/tool-calls.js +64 -10
- package/esm/src/interface/tool-invoke.d.ts +2 -0
- package/esm/src/interface/tool-invoke.js +3 -1
- package/esm/src/interface/tool-media.d.ts +2 -0
- package/esm/src/interface/tool-media.js +2 -1
- package/esm/src/interface/types.d.ts +105 -40
- package/esm/src/interface/types.js +1 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -0
- package/esm/src/kernel/auth/crypto.d.ts +7 -2
- package/esm/src/kernel/auth/crypto.js +12 -10
- package/esm/src/kernel/auth/oauth.d.ts +2 -1
- package/esm/src/kernel/auth/oauth.js +23 -22
- package/esm/src/kernel/auth/typed-secret.js +2 -2
- package/esm/src/kernel/auth/types.d.ts +13 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +43 -5
- package/esm/src/kernel/default-scope.js +54 -5
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +6 -5
- package/esm/src/kernel/engine/compaction.js +12 -11
- package/esm/src/kernel/engine/decision.d.ts +10 -8
- package/esm/src/kernel/engine/decision.js +174 -146
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +14 -4
- package/esm/src/kernel/engine/live-inbound.js +36 -11
- package/esm/src/kernel/engine/live-ingress.d.ts +6 -0
- package/esm/src/kernel/engine/live-ingress.js +6 -1
- package/esm/src/kernel/engine/repair.js +12 -12
- package/esm/src/kernel/engine/runner/gates.d.ts +2 -2
- package/esm/src/kernel/engine/runner/gates.js +287 -101
- package/esm/src/kernel/engine/runner/mod.d.ts +19 -5
- package/esm/src/kernel/engine/runner/mod.js +107 -56
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +24 -3
- package/esm/src/kernel/engine/runner/schema-validation.js +78 -4
- package/esm/src/kernel/engine/runner/stages.d.ts +1 -1
- package/esm/src/kernel/engine/runner/stages.js +1 -8
- package/esm/src/kernel/engine/runner/state.d.ts +33 -12
- package/esm/src/kernel/engine/runner/state.js +11 -1
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +2 -2
- package/esm/src/kernel/engine/runner/steps.js +329 -169
- package/esm/src/kernel/engine/runner/stream.d.ts +42 -11
- package/esm/src/kernel/engine/runner/stream.js +197 -46
- package/esm/src/kernel/engine/runner/usage.d.ts +5 -5
- package/esm/src/kernel/engine/runner/usage.js +12 -14
- package/esm/src/kernel/engine/session/mod.d.ts +8 -6
- package/esm/src/kernel/engine/session/mod.js +360 -129
- package/esm/src/kernel/engine/session/session-trace.d.ts +10 -10
- package/esm/src/kernel/engine/session/session-trace.js +41 -30
- package/esm/src/kernel/engine/token-estimate.d.ts +10 -64
- package/esm/src/kernel/engine/token-estimate.js +14 -194
- package/esm/src/kernel/engine/tool-trace.d.ts +3 -3
- package/esm/src/kernel/engine/tool-trace.js +2 -1
- package/esm/src/kernel/engine/turn-trace.d.ts +8 -7
- package/esm/src/kernel/engine/turn-trace.js +28 -36
- package/esm/src/kernel/engine/usage.d.ts +6 -0
- package/esm/src/kernel/engine/usage.js +17 -0
- package/esm/src/kernel/interaction-parts.d.ts +3 -0
- package/esm/src/kernel/interaction-parts.js +18 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +38 -11
- package/esm/src/kernel/mod.js +22 -7
- package/esm/src/kernel/profile-graph.d.ts +11 -6
- package/esm/src/kernel/profile-graph.js +14 -7
- package/esm/src/kernel/profile-presence.d.ts +10 -1
- package/esm/src/kernel/profile-presence.js +90 -75
- package/esm/src/kernel/profile-scope.d.ts +7 -3
- package/esm/src/kernel/profile-scope.js +67 -55
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +15 -4
- package/esm/src/kernel/registry/attachments.js +31 -22
- package/esm/src/kernel/registry/catalog.d.ts +6 -0
- package/esm/src/kernel/registry/catalog.js +9 -2
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +6 -2
- package/esm/src/kernel/registry/ingress.js +55 -10
- package/esm/src/kernel/registry/kernel-registry.d.ts +3 -0
- package/esm/src/kernel/registry/kernel-registry.js +9 -2
- package/esm/src/kernel/registry/profile-outputs.js +4 -1
- package/esm/src/kernel/registry/profiles.d.ts +38 -14
- package/esm/src/kernel/registry/profiles.js +280 -205
- package/esm/src/kernel/registry/provider-request.d.ts +3 -3
- package/esm/src/kernel/registry/provider-request.js +5 -13
- package/esm/src/kernel/registry/resolve.d.ts +4 -1
- package/esm/src/kernel/registry/resolve.js +59 -58
- package/esm/src/kernel/registry/schemas.d.ts +3 -0
- package/esm/src/kernel/registry/schemas.js +3 -1
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -0
- package/esm/src/kernel/registry/system-prompt.js +7 -8
- package/esm/src/kernel/registry/vault.d.ts +14 -13
- package/esm/src/kernel/registry/vault.js +1 -14
- package/esm/src/kernel/schema.d.ts +100 -46
- package/esm/src/kernel/schema.js +499 -257
- package/esm/src/kernel/scope.d.ts +12 -5
- package/esm/src/kernel/scope.js +23 -3
- package/esm/src/kernel/stages.d.ts +38 -3
- package/esm/src/kernel/stages.js +82 -39
- package/esm/src/kernel/stop.d.ts +29 -6
- package/esm/src/kernel/stop.js +16 -4
- package/esm/src/kernel/system-parts.js +6 -6
- package/esm/src/kernel/tools/activity-label.d.ts +12 -6
- package/esm/src/kernel/tools/activity-label.js +258 -32
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +21 -6
- package/esm/src/kernel/tools/events.js +53 -18
- package/esm/src/kernel/tools/execute.d.ts +47 -11
- package/esm/src/kernel/tools/execute.js +508 -136
- package/esm/src/kernel/tools/gate-answer.d.ts +12 -2
- package/esm/src/kernel/tools/gate-answer.js +17 -6
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +1 -0
- package/esm/src/kernel/tools/harness.js +2 -1
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +27 -5
- package/esm/src/kernel/tools/invoke.js +223 -70
- package/esm/src/kernel/tools/mcp-sessions.d.ts +4 -1
- package/esm/src/kernel/tools/mcp-sessions.js +13 -8
- package/esm/src/kernel/tools/mod.d.ts +4 -3
- package/esm/src/kernel/tools/mod.js +3 -2
- package/esm/src/kernel/tools/model-text.d.ts +10 -5
- package/esm/src/kernel/tools/model-text.js +18 -12
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +11 -2
- package/esm/src/kernel/tools/permission.js +12 -12
- package/esm/src/kernel/tools/project.d.ts +4 -1
- package/esm/src/kernel/tools/project.js +32 -2
- package/esm/src/kernel/tools/registry.d.ts +9 -2
- package/esm/src/kernel/tools/registry.js +69 -10
- package/esm/src/kernel/tools/remote.d.ts +40 -6
- package/esm/src/kernel/tools/remote.js +219 -92
- package/esm/src/kernel/tools/resolve.d.ts +3 -0
- package/esm/src/kernel/tools/resolve.js +12 -4
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +3 -3
- package/esm/src/kernel/tools/schema.js +21 -100
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +2 -1
- package/esm/src/kernel/tools/signed-in-fetch.js +3 -3
- package/esm/src/kernel/tools/stage-run.d.ts +27 -4
- package/esm/src/kernel/tools/stage-run.js +75 -17
- package/esm/src/kernel/tools/types.d.ts +235 -25
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +208 -31
- package/esm/src/kernel/turn-events.js +127 -9
- package/esm/src/kernel/types.d.ts +302 -161
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +2 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +1 -0
- package/esm/src/observability/destinations.d.ts +5 -0
- package/esm/src/observability/destinations.js +7 -2
- package/esm/src/observability/jsonl.d.ts +2 -2
- package/esm/src/observability/jsonl.js +15 -22
- package/esm/src/observability/mod.d.ts +3 -3
- package/esm/src/observability/mod.js +2 -2
- package/esm/src/observability/openinference.d.ts +1 -1
- package/esm/src/observability/openinference.js +3 -3
- package/esm/src/observability/otlp.d.ts +3 -0
- package/esm/src/observability/otlp.js +3 -3
- package/esm/src/observability/phoenix.d.ts +1 -0
- package/esm/src/observability/policy.d.ts +3 -0
- package/esm/src/observability/policy.js +5 -1
- package/esm/src/observability/resolve-policy.js +11 -5
- package/esm/src/observability/spans.d.ts +8 -2
- package/esm/src/observability/spans.js +21 -5
- package/esm/src/observability/trace-catalog.d.ts +19 -2
- package/esm/src/observability/trace-catalog.js +130 -88
- package/esm/src/observability/trace-record.js +22 -17
- package/esm/src/observability/trace-schema.d.ts +3 -0
- package/esm/src/observability/trace-schema.js +1 -1
- package/esm/src/observability/trace-sink.d.ts +1 -0
- package/esm/src/observability/trace-sink.js +1 -1
- package/esm/src/observability/trace-span.d.ts +7 -1
- package/esm/src/observability/trace-span.js +3 -1
- package/esm/src/observability/trace.d.ts +2 -0
- package/esm/src/observability/trace.js +4 -2
- package/esm/src/observability/types.d.ts +35 -11
- package/esm/src/observability/types.js +1 -1
- package/esm/src/presets/google/speech-voices.d.ts +1 -0
- package/esm/src/presets/google-limits.d.ts +1 -0
- package/esm/src/presets/google.d.ts +27 -12
- package/esm/src/presets/google.js +34 -25
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +5 -4
- package/esm/src/presets/mod.js +4 -4
- package/esm/src/presets/openrouter.d.ts +14 -1
- package/esm/src/presets/openrouter.js +19 -1
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +102 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/api-error.d.ts +2 -0
- package/esm/src/providers/google/api-error.js +26 -18
- package/esm/src/providers/google/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -0
- package/esm/src/providers/google/grounding.d.ts +4 -4
- package/esm/src/providers/google/interactions/framing.d.ts +20 -8
- package/esm/src/providers/google/interactions/framing.js +85 -44
- package/esm/src/providers/google/interactions/steps.d.ts +5 -5
- package/esm/src/providers/google/interactions/steps.js +4 -4
- package/esm/src/providers/google/interactions/stream.d.ts +10 -11
- package/esm/src/providers/google/interactions/stream.js +33 -100
- package/esm/src/providers/google/live/framing.d.ts +15 -5
- package/esm/src/providers/google/live/framing.js +25 -25
- package/esm/src/providers/google/live/stream.d.ts +6 -44
- package/esm/src/providers/google/live/stream.js +4 -210
- package/esm/src/providers/google/urls.d.ts +1 -3
- package/esm/src/providers/google/urls.js +1 -3
- package/esm/src/providers/google/usage.js +2 -2
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +28 -7
- package/esm/src/providers/mod.js +19 -3
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +0 -9
- package/esm/src/providers/openrouter/image.js +0 -153
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/compat.js +6 -6
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -0
- package/esm/src/providers/shared/pcm.js +2 -2
- package/esm/src/providers/shared/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -0
- package/esm/src/providers/shared/response-identity.d.ts +2 -2
- package/esm/src/providers/shared/retry.d.ts +18 -0
- package/esm/src/providers/shared/retry.js +89 -0
- package/esm/src/providers/shared/sse.d.ts +0 -4
- package/esm/src/providers/shared/sse.js +50 -36
- package/esm/src/providers/shared/tool-args.d.ts +6 -7
- package/esm/src/providers/shared/tool-args.js +10 -6
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +2 -2
- package/esm/src/providers/shared/upstream-tape.js +1 -1
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +48 -16
- package/esm/src/providers/types.js +2 -1
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +19 -1
- package/esm/src/surface/formats.js +68 -29
- package/esm/src/surface/mod.d.ts +4 -2
- package/esm/src/surface/mod.js +4 -2
- package/esm/src/surface/runtime.d.ts +4 -0
- package/esm/src/surface/runtime.js +2 -0
- package/esm/src/surface/tools.d.ts +2 -8
- package/esm/src/surface/tools.js +4 -22
- package/esm/src/surface/types.d.ts +6 -0
- package/package.json +5 -13
- package/esm/src/cli/commands/egress-compile.d.ts +0 -17
- package/esm/src/cli/commands/egress-compile.js +0 -25
- package/esm/src/guardrails/egress-policy.d.ts +0 -27
- package/esm/src/guardrails/egress-policy.js +0 -76
- package/esm/src/guardrails/egress-rules.d.ts +0 -54
- package/esm/src/guardrails/egress-rules.js +0 -49
- package/esm/src/guardrails/lexicon.d.ts +0 -30
- package/esm/src/guardrails/lexicon.js +0 -478
- package/esm/src/kernel/engine/media-probe/audio.d.ts +0 -7
- package/esm/src/kernel/engine/media-probe/audio.js +0 -342
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +0 -6
- package/esm/src/kernel/engine/media-probe/bytes.js +0 -26
- package/esm/src/kernel/engine/media-probe/image.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/image.js +0 -171
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +0 -19
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +0 -48
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +0 -35
- package/esm/src/kernel/engine/media-probe/matroska.js +0 -226
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +0 -22
- package/esm/src/kernel/engine/media-probe/mp4.js +0 -279
- package/esm/src/kernel/engine/media-probe/opus.d.ts +0 -4
- package/esm/src/kernel/engine/media-probe/opus.js +0 -23
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/pdf.js +0 -117
- package/esm/src/kernel/engine/media-probe/video.d.ts +0 -15
- package/esm/src/kernel/engine/media-probe/video.js +0 -49
- package/esm/src/presets/typesafe.d.ts +0 -2
- package/esm/src/presets/typesafe.js +0 -2
- package/esm/src/providers/create-provider.d.ts +0 -21
- package/esm/src/providers/create-provider.js +0 -90
- package/esm/src/providers/decision/usage.d.ts +0 -3
- package/esm/src/providers/decision/usage.js +0 -25
- package/esm/src/providers/google/interactions/mod.d.ts +0 -2
- package/esm/src/providers/google/interactions/mod.js +0 -2
- package/esm/src/providers/google/keys.d.ts +0 -20
- package/esm/src/providers/google/keys.js +0 -87
- package/esm/src/providers/google/live/mod.d.ts +0 -7
- package/esm/src/providers/google/live/mod.js +0 -7
- package/esm/src/providers/google/live/openapi-schema.d.ts +0 -1
- package/esm/src/providers/google/live/openapi-schema.js +0 -42
- package/esm/src/providers/google/live/session.d.ts +0 -14
- package/esm/src/providers/google/live/session.js +0 -150
- package/esm/src/providers/local/local.d.ts +0 -12
- package/esm/src/providers/local/local.js +0 -186
- package/esm/src/providers/local/mod.d.ts +0 -8
- package/esm/src/providers/local/mod.js +0 -8
- package/esm/src/providers/openrouter/cache-control.d.ts +0 -5
- package/esm/src/providers/openrouter/cache-control.js +0 -4
- package/esm/src/providers/openrouter/chat.d.ts +0 -64
- package/esm/src/providers/openrouter/chat.js +0 -490
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +0 -10
- package/esm/src/providers/openrouter/openai/sdk-messages.js +0 -99
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +0 -3
- package/esm/src/providers/openrouter/resolve-api-key.js +0 -8
- package/esm/src/providers/openrouter/speech.d.ts +0 -18
- package/esm/src/providers/openrouter/speech.js +0 -109
- package/esm/src/providers/probe.d.ts +0 -5
- package/esm/src/providers/probe.js +0 -15
- package/esm/src/providers/shared/builtin-wire.d.ts +0 -4
- package/esm/src/providers/shared/builtin-wire.js +0 -9
- package/esm/src/providers/shared/vault.d.ts +0 -13
- package/esm/src/providers/shared/vault.js +0 -41
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tools Gemini runs itself, and how each is sent on Interactions and on Live, with what it
|
|
3
|
+
* takes from a request's `builtInArgs`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
9
|
+
const googleMapsArgs = z.strictObject({
|
|
10
|
+
/** Where Maps grounding searches around. */
|
|
11
|
+
location: z.strictObject({
|
|
12
|
+
latitude: z.number().min(-90).max(90),
|
|
13
|
+
longitude: z.number().min(-180).max(180),
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
const GOOGLE_BUILTIN_IDS = [
|
|
17
|
+
'googleSearch',
|
|
18
|
+
'googleMaps',
|
|
19
|
+
'urlContext',
|
|
20
|
+
'codeExecution',
|
|
21
|
+
];
|
|
22
|
+
const INTERACTIONS_TYPE = {
|
|
23
|
+
googleSearch: 'google_search',
|
|
24
|
+
googleMaps: 'google_maps',
|
|
25
|
+
urlContext: 'url_context',
|
|
26
|
+
codeExecution: 'code_execution',
|
|
27
|
+
};
|
|
28
|
+
/** The request's builtins that are Google's own tools; the wire takes no others. */
|
|
29
|
+
function googleBuiltins(builtins) {
|
|
30
|
+
return builtins.filter((builtin) => GOOGLE_BUILTIN_IDS.includes(builtin.id));
|
|
31
|
+
}
|
|
32
|
+
function googleBuiltinId(builtin) {
|
|
33
|
+
const id = GOOGLE_BUILTIN_IDS.find((known) => known === builtin.id);
|
|
34
|
+
if (!id) {
|
|
35
|
+
throw new TheoremError('config', `Builtin '${builtin.id}' is not a Google tool`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
36
|
+
}
|
|
37
|
+
return id;
|
|
38
|
+
}
|
|
39
|
+
/** One builtin as an Interactions `tools` entry. */
|
|
40
|
+
function interactionsBuiltinTool(builtin) {
|
|
41
|
+
const id = googleBuiltinId(builtin);
|
|
42
|
+
const type = INTERACTIONS_TYPE[id];
|
|
43
|
+
if (id === 'googleMaps' && builtin.args) {
|
|
44
|
+
const { location } = googleMapsArgs.parse(builtin.args);
|
|
45
|
+
return { type, latitude: location.latitude, longitude: location.longitude };
|
|
46
|
+
}
|
|
47
|
+
return { type };
|
|
48
|
+
}
|
|
49
|
+
/** One builtin as a Live setup `tools` entry. Live takes no args for any of them. */
|
|
50
|
+
function liveBuiltinTool(builtin) {
|
|
51
|
+
const id = googleBuiltinId(builtin);
|
|
52
|
+
if (builtin.args) {
|
|
53
|
+
throw new TheoremError('unsupported', `Builtin '${id}' takes no args on Google Live`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
54
|
+
}
|
|
55
|
+
return { [id]: {} };
|
|
56
|
+
}
|
|
57
|
+
export { googleBuiltins, interactionsBuiltinTool, liveBuiltinTool };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare function groundingFromDelta(event: Record<string, unknown>):
|
|
3
|
-
declare function groundingFromSteps(steps: unknown[]):
|
|
4
|
-
declare function groundingFromLiveMetadata(value: unknown):
|
|
1
|
+
import type { ModelEvent } from '../../kernel/types.js';
|
|
2
|
+
declare function groundingFromDelta(event: Record<string, unknown>): ModelEvent[];
|
|
3
|
+
declare function groundingFromSteps(steps: unknown[]): ModelEvent[];
|
|
4
|
+
declare function groundingFromLiveMetadata(value: unknown): ModelEvent[];
|
|
5
5
|
export { groundingFromDelta, groundingFromLiveMetadata, groundingFromSteps };
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { InteractionPart, ModelRequest, TurnHistoryMessage } from '../../../kernel/types.js';
|
|
3
|
+
/** A turn as Interactions frames it: the request, plus whether Google keeps it and what it continues. */
|
|
4
|
+
export type InteractionsRequest = ModelRequest & {
|
|
5
|
+
store?: boolean;
|
|
6
|
+
previousInteractionId?: string;
|
|
7
|
+
/** What came after the stored interaction, sent in place of the whole history. */
|
|
8
|
+
continuation?: TurnHistoryMessage[];
|
|
9
|
+
};
|
|
2
10
|
export declare function camelToSnake(key: string): string;
|
|
3
11
|
export declare function toGoogleValue(value: unknown): unknown;
|
|
4
12
|
export declare function wirePart(part: InteractionPart): Record<string, string>;
|
|
5
13
|
export declare function userInputStep(parts: InteractionPart[]): Record<string, unknown>;
|
|
6
|
-
/**
|
|
14
|
+
/** A thought's signature, for the tool call at `call` in the same assistant message. */
|
|
15
|
+
export declare const thoughtSignature: z.ZodType<{
|
|
16
|
+
call: number;
|
|
17
|
+
signature: string;
|
|
18
|
+
}>;
|
|
7
19
|
export declare function historySteps(msg: TurnHistoryMessage): Record<string, unknown>[];
|
|
8
20
|
export declare function historyStep(msg: TurnHistoryMessage): Record<string, unknown>;
|
|
9
21
|
export declare function jsonResponseFormat(schema: Record<string, unknown>): unknown[];
|
|
10
|
-
export declare function attachResponseFormat(req:
|
|
11
|
-
export declare function attachSpeechConfig(req:
|
|
12
|
-
export declare function inputStepsFromRequest(req:
|
|
13
|
-
export declare function applyOptionalRequestFields(req:
|
|
14
|
-
export declare function baseInteractionsBody(req:
|
|
15
|
-
export declare function toInteractionsBody(req:
|
|
22
|
+
export declare function attachResponseFormat(req: InteractionsRequest, camel: Record<string, unknown>): void;
|
|
23
|
+
export declare function attachSpeechConfig(req: InteractionsRequest, generationConfig: Record<string, unknown>): void;
|
|
24
|
+
export declare function inputStepsFromRequest(req: InteractionsRequest): Record<string, unknown>[];
|
|
25
|
+
export declare function applyOptionalRequestFields(req: InteractionsRequest, camel: Record<string, unknown>): void;
|
|
26
|
+
export declare function baseInteractionsBody(req: InteractionsRequest): Record<string, unknown>;
|
|
27
|
+
export declare function toInteractionsBody(req: InteractionsRequest): Record<string, unknown>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { TheoremError } from '../../../guardrails/error.js';
|
|
2
3
|
import { historyMessageParts, wireInteractionPart } from '../../../kernel/interaction-parts.js';
|
|
3
4
|
import { GOOGLE_SPEECH_FORMATS } from '../../../presets/google-limits.js';
|
|
4
|
-
import {
|
|
5
|
+
import { withCarriedToolFiles } from '../../shared/carried-tool-files.js';
|
|
5
6
|
import { historyToolArguments, historyToolIdentity } from '../../shared/tool-args.js';
|
|
7
|
+
import { interactionsBuiltinTool } from '../builtins.js';
|
|
6
8
|
import { assertGoogleThinkingLevel } from '../thinking.js';
|
|
7
9
|
export function camelToSnake(key) {
|
|
8
10
|
return key.replaceAll(/[A-Z]/g, (ch) => `_${ch.toLowerCase()}`);
|
|
@@ -14,8 +16,8 @@ export function toGoogleValue(value) {
|
|
|
14
16
|
if (value && typeof value === 'object') {
|
|
15
17
|
const out = {};
|
|
16
18
|
for (const [key, nested] of Object.entries(value)) {
|
|
17
|
-
//
|
|
18
|
-
if (key === 'schema' || key === 'parameters') {
|
|
19
|
+
// why: A schema's property names and a call's argument names are the builder's own; snake-casing them breaks Gemini validation and shows the model a call it did not make.
|
|
20
|
+
if (key === 'schema' || key === 'parameters' || key === 'arguments') {
|
|
19
21
|
out[camelToSnake(key)] = nested;
|
|
20
22
|
continue;
|
|
21
23
|
}
|
|
@@ -36,12 +38,18 @@ function historyContent(msg) {
|
|
|
36
38
|
const parts = historyMessageParts(msg);
|
|
37
39
|
return parts.length > 0 ? parts.map(wirePart) : [{ type: 'text', text: '' }];
|
|
38
40
|
}
|
|
41
|
+
// why: Google refuses any other part inside a `function_result`: "The value 'document' is not supported for 'type' at 'input[8].result[2]'. Supported values: 'function', 'image', 'text', 'video'." (live, 13/10/2026, gemini-3.5-flash-lite).
|
|
42
|
+
const FUNCTION_RESULT_PART_TYPES = new Set([
|
|
43
|
+
'text',
|
|
44
|
+
'image',
|
|
45
|
+
'video',
|
|
46
|
+
]);
|
|
39
47
|
function functionResultStep(msg) {
|
|
40
|
-
const
|
|
48
|
+
const parts = historyMessageParts(msg);
|
|
41
49
|
return {
|
|
42
50
|
type: 'function_result',
|
|
43
51
|
...historyToolIdentity({ name: msg.name, call_id: msg.tool_call_id }),
|
|
44
|
-
result,
|
|
52
|
+
result: parts.length > 0 ? parts.map(wirePart) : [{ type: 'text', text: '' }],
|
|
45
53
|
};
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
@@ -51,34 +59,43 @@ function functionResultStep(msg) {
|
|
|
51
59
|
* the call; a `thought` step with the signature ahead of it is accepted (probe
|
|
52
60
|
* 25/09/2026, gemini-3.1-flash-lite, `store: false`).
|
|
53
61
|
*/
|
|
54
|
-
function functionCallSteps(call) {
|
|
62
|
+
function functionCallSteps(call, signature) {
|
|
55
63
|
const step = {
|
|
56
64
|
type: 'function_call',
|
|
57
65
|
id: call.id,
|
|
58
66
|
name: call.function.name,
|
|
59
67
|
arguments: historyToolArguments(call.function.arguments),
|
|
60
68
|
};
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
return signature ? [{ type: 'thought', signature }, step] : [step];
|
|
70
|
+
}
|
|
71
|
+
/** A thought's signature, for the tool call at `call` in the same assistant message. */
|
|
72
|
+
export const thoughtSignature = z.strictObject({
|
|
73
|
+
call: z.number().int().min(0),
|
|
74
|
+
signature: z.string().min(1),
|
|
75
|
+
});
|
|
76
|
+
/** The signature written with the message's call at `index`, if its reasoning holds one. */
|
|
77
|
+
function signatureAt(msg, index) {
|
|
78
|
+
for (const part of msg.reasoning ?? []) {
|
|
79
|
+
const parsed = thoughtSignature.safeParse(part.data);
|
|
80
|
+
if (parsed.success && parsed.data.call === index)
|
|
81
|
+
return parsed.data.signature;
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
64
84
|
}
|
|
65
85
|
function textOrPartsStep(role, msg) {
|
|
66
|
-
// Assistant history is `model_output`, not `model_turn`.
|
|
86
|
+
// why: Assistant history is `model_output`, not `model_turn`.
|
|
67
87
|
const type = role === 'assistant' ? 'model_output' : 'user_input';
|
|
68
88
|
return { type, content: historyContent(msg) };
|
|
69
89
|
}
|
|
70
90
|
/** Assistant `tool_calls` (often with no `content`) become `function_call` steps, never empty `model_output`. */
|
|
71
|
-
|
|
72
|
-
if (msg.role === 'tool') {
|
|
73
|
-
return [functionResultStep(msg)];
|
|
74
|
-
}
|
|
91
|
+
function nonToolSteps(msg) {
|
|
75
92
|
if (msg.role === 'assistant' && msg.tool_calls && msg.tool_calls.length > 0) {
|
|
76
93
|
const steps = [];
|
|
77
94
|
if (historyMessageParts(msg).length > 0) {
|
|
78
95
|
steps.push(textOrPartsStep('assistant', msg));
|
|
79
96
|
}
|
|
80
|
-
for (const call of msg.tool_calls) {
|
|
81
|
-
steps.push(...functionCallSteps(call));
|
|
97
|
+
for (const [index, call] of msg.tool_calls.entries()) {
|
|
98
|
+
steps.push(...functionCallSteps(call, signatureAt(msg, index)));
|
|
82
99
|
}
|
|
83
100
|
return steps;
|
|
84
101
|
}
|
|
@@ -87,6 +104,16 @@ export function historySteps(msg) {
|
|
|
87
104
|
}
|
|
88
105
|
return [textOrPartsStep('user', msg)];
|
|
89
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* History as input steps. A file a `function_result` cannot hold follows its run
|
|
109
|
+
* of tool results in a `user_input` step (`withCarriedToolFiles`).
|
|
110
|
+
*/
|
|
111
|
+
function historyStepsOf(messages) {
|
|
112
|
+
return withCarriedToolFiles(messages, FUNCTION_RESULT_PART_TYPES).flatMap((msg) => msg.role === 'tool' ? [functionResultStep(msg)] : nonToolSteps(msg));
|
|
113
|
+
}
|
|
114
|
+
export function historySteps(msg) {
|
|
115
|
+
return historyStepsOf([msg]);
|
|
116
|
+
}
|
|
90
117
|
export function historyStep(msg) {
|
|
91
118
|
const steps = historySteps(msg);
|
|
92
119
|
return steps[0] ?? { type: 'user_input', content: [{ type: 'text', text: '' }] };
|
|
@@ -107,7 +134,6 @@ export function attachResponseFormat(req, camel) {
|
|
|
107
134
|
throw new TheoremError('unsupported', `Gemini speech returns ${GOOGLE_SPEECH_FORMATS.join(', ')}, not '${format}'`);
|
|
108
135
|
}
|
|
109
136
|
camel.responseFormat = { type: 'audio' };
|
|
110
|
-
camel.responseModalities = ['audio'];
|
|
111
137
|
return;
|
|
112
138
|
}
|
|
113
139
|
if (req.image) {
|
|
@@ -131,7 +157,6 @@ export function attachResponseFormat(req, camel) {
|
|
|
131
157
|
throw new TheoremError('unsupported', `image.${name} is not supported on Google image models`);
|
|
132
158
|
}
|
|
133
159
|
}
|
|
134
|
-
// An object asks for image only; an array for text + image.
|
|
135
160
|
camel.responseFormat = req.image.includeText ? [{ type: 'text' }, imageEntry] : imageEntry;
|
|
136
161
|
return;
|
|
137
162
|
}
|
|
@@ -144,12 +169,46 @@ export function attachSpeechConfig(req, generationConfig) {
|
|
|
144
169
|
if (!req.speech) {
|
|
145
170
|
return;
|
|
146
171
|
}
|
|
147
|
-
const voice = req.speech
|
|
172
|
+
const { voice, speed } = req.speech;
|
|
173
|
+
if (speed !== undefined) {
|
|
174
|
+
// why: Interactions has no rate field, and a speed dropped here would be a setting the host believes it made.
|
|
175
|
+
throw new TheoremError('config', 'Gemini Interactions speech has no speed field: set the pace in speech.style');
|
|
176
|
+
}
|
|
148
177
|
if (!voice) {
|
|
149
|
-
|
|
178
|
+
// why: Interactions has no default voice and refuses the request without one (live, 17/10/2026).
|
|
179
|
+
throw new TheoremError('config', 'Gemini speech needs a voice: set speech.voice');
|
|
150
180
|
}
|
|
151
181
|
generationConfig.speechConfig = [{ voice }];
|
|
152
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* The speech models that read a delivery note as a `speech_metadata` annotation. The others refuse
|
|
185
|
+
* it ("Speech metadata is not supported for this model", gemini-3.1-flash-tts-preview, live
|
|
186
|
+
* 17/10/2026) and take the note as a direction ahead of the script, as Google's guide shows.
|
|
187
|
+
*/
|
|
188
|
+
const SPEECH_METADATA_MODELS = new Set([
|
|
189
|
+
'gemini-3.8-flash-tts',
|
|
190
|
+
'gemini-3.8-flash-lite-tts',
|
|
191
|
+
]);
|
|
192
|
+
/** The script with its delivery note, in the form the model reads it. */
|
|
193
|
+
function speechInputStep(parts, style, apiId) {
|
|
194
|
+
if (!SPEECH_METADATA_MODELS.has(apiId)) {
|
|
195
|
+
return {
|
|
196
|
+
type: USER_INPUT,
|
|
197
|
+
content: [
|
|
198
|
+
{ type: 'text', text: `Read the following aloud. ${style.trim()}\n` },
|
|
199
|
+
...parts.map(wirePart),
|
|
200
|
+
],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// why: Gemini reads `text` aloud and `speech_metadata` as direction.
|
|
204
|
+
const annotations = [{ type: 'speech_metadata', style }];
|
|
205
|
+
return {
|
|
206
|
+
type: USER_INPUT,
|
|
207
|
+
content: parts
|
|
208
|
+
.map(wirePart)
|
|
209
|
+
.map((part) => (part.type === 'text' ? { ...part, annotations } : part)),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
153
212
|
function wireInteractionsFunctionTool(decl) {
|
|
154
213
|
return {
|
|
155
214
|
type: 'function',
|
|
@@ -158,26 +217,10 @@ function wireInteractionsFunctionTool(decl) {
|
|
|
158
217
|
parameters: decl.parameters,
|
|
159
218
|
};
|
|
160
219
|
}
|
|
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
220
|
function wireInteractionsTools(req) {
|
|
173
221
|
const tools = [];
|
|
174
222
|
for (const builtin of req.builtins) {
|
|
175
|
-
|
|
176
|
-
if (type === 'google_maps') {
|
|
177
|
-
tools.push(wireGoogleMapsTool(req));
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
tools.push({ type });
|
|
223
|
+
tools.push(interactionsBuiltinTool(builtin));
|
|
181
224
|
}
|
|
182
225
|
for (const decl of req.wireTools ?? []) {
|
|
183
226
|
tools.push(wireInteractionsFunctionTool(decl));
|
|
@@ -201,14 +244,12 @@ function withToolNames(messages) {
|
|
|
201
244
|
}
|
|
202
245
|
export function inputStepsFromRequest(req) {
|
|
203
246
|
if (req.continuation && req.continuation.length > 0) {
|
|
204
|
-
return withToolNames(req.continuation)
|
|
205
|
-
}
|
|
206
|
-
const inputSteps = [];
|
|
207
|
-
for (const h of withToolNames(req.history ?? [])) {
|
|
208
|
-
inputSteps.push(...historySteps(h));
|
|
247
|
+
return historyStepsOf(withToolNames(req.continuation));
|
|
209
248
|
}
|
|
249
|
+
const inputSteps = historyStepsOf(withToolNames(req.history ?? []));
|
|
210
250
|
if (req.input.length > 0 || inputSteps.length === 0) {
|
|
211
|
-
|
|
251
|
+
const style = req.speech?.style;
|
|
252
|
+
inputSteps.push(style ? speechInputStep(req.input, style, req.apiId) : userInputStep(req.input));
|
|
212
253
|
}
|
|
213
254
|
return inputSteps;
|
|
214
255
|
}
|
|
@@ -233,7 +274,7 @@ export function baseInteractionsBody(req) {
|
|
|
233
274
|
maxOutputTokens: req.maxOutputTokens,
|
|
234
275
|
};
|
|
235
276
|
if (req.speech) {
|
|
236
|
-
// TTS models reject chat thinking knobs; voice lives under speech_config.
|
|
277
|
+
// why: TTS models reject chat thinking knobs; voice lives under speech_config.
|
|
237
278
|
attachSpeechConfig(req, generationConfig);
|
|
238
279
|
}
|
|
239
280
|
else {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ModelEvent, TurnEventOf, TurnResponse } from '../../../kernel/types.js';
|
|
2
2
|
declare function isCodeExecutionType(type: string): boolean;
|
|
3
3
|
declare function isGoogleBuiltinStepType(type: string): boolean;
|
|
4
4
|
declare function rawStepEvidence(raw: Record<string, unknown>): TurnEventOf<'evidence'>;
|
|
5
5
|
declare function codeExecutionEvidence(raw: Record<string, unknown>): TurnEventOf<'evidence'>;
|
|
6
|
-
declare function eventsFromDelta(deltaValue: unknown):
|
|
7
|
-
declare function eventsFromThoughtStep(step: Record<string, unknown>):
|
|
8
|
-
declare function eventsFromModelOutputStep(step: Record<string, unknown>):
|
|
6
|
+
declare function eventsFromDelta(deltaValue: unknown): ModelEvent[];
|
|
7
|
+
declare function eventsFromThoughtStep(step: Record<string, unknown>): ModelEvent[];
|
|
8
|
+
declare function eventsFromModelOutputStep(step: Record<string, unknown>): ModelEvent[];
|
|
9
9
|
declare function extractTokenEvent(interaction: Record<string, unknown>): TurnEventOf<'tokens'> | undefined;
|
|
10
|
-
declare function eventsFromInteractionEnd(interaction: Record<string, unknown>):
|
|
10
|
+
declare function eventsFromInteractionEnd(interaction: Record<string, unknown>): ModelEvent[];
|
|
11
11
|
declare function interactionResponse(interaction: Record<string, unknown>): TurnResponse | undefined;
|
|
12
12
|
export { codeExecutionEvidence, eventsFromDelta, eventsFromInteractionEnd, eventsFromModelOutputStep, eventsFromThoughtStep, extractTokenEvent, interactionResponse, isCodeExecutionType, isGoogleBuiltinStepType, rawStepEvidence, };
|
|
@@ -3,9 +3,9 @@ import { reportedTokens, usageCount } from '../../../kernel/engine/usage.js';
|
|
|
3
3
|
import { turnStopFromInteractionStatus } from '../../../kernel/stop.js';
|
|
4
4
|
import { groundingFromSteps } from '../grounding.js';
|
|
5
5
|
import { byModality, groundingCounts, modalityCounts } from '../usage.js';
|
|
6
|
-
/*
|
|
6
|
+
/* probed 2026-09-23:
|
|
7
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
|
|
8
|
+
* (probes 23/09/2026, gemini-3.8-flash, gemini-3.1-pro-preview, image, and TTS
|
|
9
9
|
* models, streamed and buffered):
|
|
10
10
|
*
|
|
11
11
|
* - `text` deltas carry `text`; `thought_summary` deltas carry
|
|
@@ -16,7 +16,7 @@ import { byModality, groundingCounts, modalityCounts } from '../usage.js';
|
|
|
16
16
|
* buffered mime already states them (`audio/l16; rate=24000; channels=1`),
|
|
17
17
|
* the streamed one does not (`audio/l16`), so they are folded into the mime.
|
|
18
18
|
* - `code_execution_call` carries `id` and `arguments: { language, code }`;
|
|
19
|
-
* `code_execution_result` carries `call_id`, `result
|
|
19
|
+
* `code_execution_result` carries `call_id`, `result`, and `is_error`. Each
|
|
20
20
|
* arrives whole, in one delta (5 577 characters of code in one probe).
|
|
21
21
|
*/
|
|
22
22
|
function thoughtText(content) {
|
|
@@ -171,7 +171,7 @@ function eventsFromInteractionEnd(interaction) {
|
|
|
171
171
|
const tokenEvent = extractTokenEvent(interaction);
|
|
172
172
|
if (tokenEvent)
|
|
173
173
|
events.push(tokenEvent);
|
|
174
|
-
// Only a buffered body carries `steps[]`; streamed grounding arrives on deltas.
|
|
174
|
+
// why: Only a buffered body carries `steps[]`; streamed grounding arrives on deltas.
|
|
175
175
|
const { steps } = interaction;
|
|
176
176
|
if (Array.isArray(steps))
|
|
177
177
|
events.push(...groundingFromSteps(steps));
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type GeminiTransport } from '../keys.js';
|
|
1
|
+
import type { ModelEvent, ModelRequest, TurnResponse } from '../../../kernel/types.js';
|
|
3
2
|
export interface StreamFold {
|
|
4
3
|
text: string;
|
|
5
|
-
/** Open `function_call`, `code_execution_
|
|
4
|
+
/** Open `function_call`, `code_execution_*`, and builtin steps by `index`. */
|
|
6
5
|
steps: Map<number, Record<string, unknown>>;
|
|
7
6
|
sawMedia: boolean;
|
|
8
7
|
/** A `done` came out: the interaction reported a status. */
|
|
@@ -11,14 +10,14 @@ export interface StreamFold {
|
|
|
11
10
|
response?: TurnResponse;
|
|
12
11
|
/** The signature of the last thought, until the `function_call` that follows it takes it. */
|
|
13
12
|
thoughtSignature?: string;
|
|
13
|
+
/** Function calls read so far: a signature names its call by this position. */
|
|
14
|
+
calls: number;
|
|
14
15
|
}
|
|
15
16
|
export declare function newStreamFold(): StreamFold;
|
|
16
|
-
export declare function eventsFromStep(step: Record<string, unknown>, fold: StreamFold):
|
|
17
|
-
export declare function openStepEvents(fold: StreamFold):
|
|
18
|
-
export declare function foldPayload(payload: Record<string, unknown>, fold: StreamFold):
|
|
19
|
-
export declare function foldBody(body: Record<string, unknown>, fold: StreamFold):
|
|
20
|
-
export declare function finalizeStructured(req:
|
|
21
|
-
export declare function isVoiceProfile(req: ProviderCompleteRequest): boolean;
|
|
17
|
+
export declare function eventsFromStep(step: Record<string, unknown>, fold: StreamFold): ModelEvent[];
|
|
18
|
+
export declare function openStepEvents(fold: StreamFold): ModelEvent[];
|
|
19
|
+
export declare function foldPayload(payload: Record<string, unknown>, fold: StreamFold): ModelEvent[];
|
|
20
|
+
export declare function foldBody(body: Record<string, unknown>, fold: StreamFold): ModelEvent[];
|
|
21
|
+
export declare function finalizeStructured(req: ModelRequest, fold: StreamFold): Generator<ModelEvent>;
|
|
22
22
|
/** What the profile asked for and the model did not return; even an empty turn fails. */
|
|
23
|
-
export declare function missingMediaError(req:
|
|
24
|
-
export declare function createInteractionsProvider(transport: GeminiTransport): ModelProvider;
|
|
23
|
+
export declare function missingMediaError(req: ModelRequest, fold: StreamFold): ModelEvent | undefined;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TheoremError, toErrorEvent } from '../../../guardrails/error.js';
|
|
2
2
|
import { asRecord } from '../../../kernel/engine/record.js';
|
|
3
3
|
import { pcmMediaAsWav } from '../../shared/pcm.js';
|
|
4
4
|
import { foldResponse } from '../../shared/response-identity.js';
|
|
5
|
-
import { readSseChunks } from '../../shared/sse.js';
|
|
6
5
|
import { structuredEvent } from '../../shared/structured-output.js';
|
|
7
6
|
import { toolCallEvents } from '../../shared/tool-args.js';
|
|
8
|
-
import {
|
|
7
|
+
import { toolDraftEvents } from '../../shared/tool-draft.js';
|
|
8
|
+
import { readGeminiApiError } from '../api-error.js';
|
|
9
9
|
import { groundingFromDelta } from '../grounding.js';
|
|
10
|
-
import { fetchGemini } from '../keys.js';
|
|
11
|
-
import { INTERACTIONS_JSON_URL, INTERACTIONS_URL } from '../urls.js';
|
|
12
|
-
import { toInteractionsBody } from './framing.js';
|
|
13
10
|
import { codeExecutionEvidence, eventsFromDelta, eventsFromInteractionEnd, eventsFromModelOutputStep, eventsFromThoughtStep, interactionResponse, isCodeExecutionType, isGoogleBuiltinStepType, rawStepEvidence, } from './steps.js';
|
|
14
|
-
const HTTP_OK = 200;
|
|
15
11
|
export function newStreamFold() {
|
|
16
|
-
return { text: '', steps: new Map(), sawMedia: false, sawDone: false };
|
|
12
|
+
return { text: '', steps: new Map(), sawMedia: false, sawDone: false, calls: 0 };
|
|
17
13
|
}
|
|
18
14
|
function isMergedStepType(type) {
|
|
19
15
|
return type === 'function_call' || isCodeExecutionType(type) || isGoogleBuiltinStepType(type);
|
|
@@ -47,8 +43,20 @@ export function eventsFromStep(step, fold) {
|
|
|
47
43
|
if (type === 'function_call') {
|
|
48
44
|
const id = typeof step.id === 'string' ? step.id : undefined;
|
|
49
45
|
const name = typeof step.name === 'string' ? step.name : '';
|
|
50
|
-
const
|
|
51
|
-
|
|
46
|
+
const signature = takeThoughtSignature(step, fold);
|
|
47
|
+
const call = fold.calls++;
|
|
48
|
+
return [
|
|
49
|
+
...(signature
|
|
50
|
+
? [
|
|
51
|
+
{
|
|
52
|
+
type: 'reasoning',
|
|
53
|
+
data: { call, signature },
|
|
54
|
+
origin: { protocol: 'geminiInteractions' },
|
|
55
|
+
},
|
|
56
|
+
]
|
|
57
|
+
: []),
|
|
58
|
+
...toolCallEvents({ id, name }, step.arguments),
|
|
59
|
+
];
|
|
52
60
|
}
|
|
53
61
|
if (isCodeExecutionType(type)) {
|
|
54
62
|
return [codeExecutionEvidence(step)];
|
|
@@ -93,10 +101,19 @@ function foldStepDelta(payload, fold) {
|
|
|
93
101
|
return eventsFromDelta(delta);
|
|
94
102
|
}
|
|
95
103
|
if (delta.type === 'arguments_delta') {
|
|
96
|
-
// Replaces the `arguments: {}` placeholder from `step.start` with the streamed JSON string.
|
|
104
|
+
// why: Replaces the `arguments: {}` placeholder from `step.start` with the streamed JSON string.
|
|
97
105
|
const sofar = typeof open.arguments === 'string' ? open.arguments : '';
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
const args = sofar + (typeof delta.arguments === 'string' ? delta.arguments : '');
|
|
107
|
+
open.arguments = args;
|
|
108
|
+
if (open.type !== 'function_call')
|
|
109
|
+
return [];
|
|
110
|
+
// why: The call at `step.stop` goes out under the `id` and `name` that `step.start` gave.
|
|
111
|
+
return toolDraftEvents({
|
|
112
|
+
id: nonEmptyString(open.id),
|
|
113
|
+
name: typeof open.name === 'string' ? open.name : '',
|
|
114
|
+
args,
|
|
115
|
+
drafted: sofar.length,
|
|
116
|
+
});
|
|
100
117
|
}
|
|
101
118
|
Object.assign(open, delta);
|
|
102
119
|
return [];
|
|
@@ -138,7 +155,7 @@ function delivered(events, fold) {
|
|
|
138
155
|
}
|
|
139
156
|
function eventsFromStreamRow(payload, fold) {
|
|
140
157
|
if (payload.eventType === 'sse_unparsed') {
|
|
141
|
-
// Every observed Interactions row is a JSON object; anything else is a wire change.
|
|
158
|
+
// why: Every observed Interactions row is a JSON object; anything else is a wire change.
|
|
142
159
|
return [
|
|
143
160
|
toErrorEvent(new TheoremError('bad_response', 'Interactions stream row was not a JSON object')),
|
|
144
161
|
];
|
|
@@ -196,8 +213,8 @@ export function* finalizeStructured(req, fold) {
|
|
|
196
213
|
}
|
|
197
214
|
yield structuredEvent(fold.text);
|
|
198
215
|
}
|
|
199
|
-
|
|
200
|
-
return Boolean(req.speech
|
|
216
|
+
function isVoiceProfile(req) {
|
|
217
|
+
return Boolean(req.speech);
|
|
201
218
|
}
|
|
202
219
|
/** What the profile asked for and the model did not return; even an empty turn fails. */
|
|
203
220
|
export function missingMediaError(req, fold) {
|
|
@@ -211,87 +228,3 @@ export function missingMediaError(req, fold) {
|
|
|
211
228
|
}
|
|
212
229
|
return undefined;
|
|
213
230
|
}
|
|
214
|
-
async function* parseInteractionsSse(response, req) {
|
|
215
|
-
if (!response.body) {
|
|
216
|
-
yield toErrorEvent(new TheoremError('bad_response', 'empty response body'));
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const fold = newStreamFold();
|
|
220
|
-
for await (const row of readSseChunks(response.body)) {
|
|
221
|
-
req.tapUpstream?.(row);
|
|
222
|
-
if (row.eventType === 'sse_done') {
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
const events = foldPayload(row, fold);
|
|
226
|
-
yield* events;
|
|
227
|
-
if (events.some((ev) => ev.type === 'error')) {
|
|
228
|
-
yield* openStepEvents(fold);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
yield* openStepEvents(fold);
|
|
233
|
-
yield* finalizeStructured(req, fold);
|
|
234
|
-
const missing = missingMediaError(req, fold);
|
|
235
|
-
if (missing)
|
|
236
|
-
yield missing;
|
|
237
|
-
if (!fold.sawDone) {
|
|
238
|
-
// The stream ended before the interaction reported a status: it did not complete.
|
|
239
|
-
yield { type: 'done', stop: { kind: 'stream_incomplete' } };
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
async function postInteractions(url, req, transport) {
|
|
243
|
-
if (!req.keySlot) {
|
|
244
|
-
throw new TheoremError('config', 'Request requires keySlot');
|
|
245
|
-
}
|
|
246
|
-
const init = {
|
|
247
|
-
method: 'POST',
|
|
248
|
-
headers: { 'content-type': 'application/json' },
|
|
249
|
-
body: JSON.stringify(toInteractionsBody(req)),
|
|
250
|
-
signal: req.signal,
|
|
251
|
-
};
|
|
252
|
-
const response = await fetchGemini(url, init, req.keySlot, transport, req.tapUpstream, req.fallbackKeySlot);
|
|
253
|
-
if (response.status !== HTTP_OK) {
|
|
254
|
-
throw await readNonOkError(response);
|
|
255
|
-
}
|
|
256
|
-
return response;
|
|
257
|
-
}
|
|
258
|
-
async function* fetchInteractionsOnce(req, transport) {
|
|
259
|
-
const response = await postInteractions(INTERACTIONS_JSON_URL, req, transport);
|
|
260
|
-
const text = await response.text();
|
|
261
|
-
const parsed = JSON.parse(text);
|
|
262
|
-
const apiError = readGeminiApiError(parsed);
|
|
263
|
-
if (apiError) {
|
|
264
|
-
throw apiError;
|
|
265
|
-
}
|
|
266
|
-
req.tapUpstream?.(parsed);
|
|
267
|
-
const fold = newStreamFold();
|
|
268
|
-
yield* foldBody(parsed, fold);
|
|
269
|
-
yield* finalizeStructured(req, fold);
|
|
270
|
-
const missing = missingMediaError(req, fold);
|
|
271
|
-
if (missing)
|
|
272
|
-
yield missing;
|
|
273
|
-
}
|
|
274
|
-
async function* streamInteractions(req, transport) {
|
|
275
|
-
const response = await postInteractions(INTERACTIONS_URL, req, transport);
|
|
276
|
-
yield* parseInteractionsSse(response, req);
|
|
277
|
-
}
|
|
278
|
-
export function createInteractionsProvider(transport) {
|
|
279
|
-
return {
|
|
280
|
-
async *complete(req) {
|
|
281
|
-
try {
|
|
282
|
-
if (req.stream === false) {
|
|
283
|
-
yield* fetchInteractionsOnce(req, transport);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
yield* streamInteractions(req, transport);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
catch (err) {
|
|
290
|
-
if (isAbortError(err)) {
|
|
291
|
-
throw err;
|
|
292
|
-
}
|
|
293
|
-
yield toErrorEvent(err);
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
}
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import type { InteractionPart,
|
|
1
|
+
import type { InteractionPart, ModelEvent, ModelRequest, TurnHistoryMessage, TurnTokens, WireFunctionTool } from '../../../kernel/types.js';
|
|
2
2
|
export declare function buildGeminiLiveWebSocketUrl(apiKey: string): string;
|
|
3
|
+
/** `parametersJsonSchema` takes the JSON Schema as it is; `parameters` takes only Google's OpenAPI subset. */
|
|
3
4
|
export declare function wireFunctionDeclaration(decl: WireFunctionTool): Record<string, unknown>;
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Builtins are their own tool entries (`{ googleSearch: {} }`), functions share
|
|
7
|
+
* one `functionDeclarations` entry. Which builtins a model takes is the API's
|
|
8
|
+
* answer (probe 23/09/2026: a model without one closes the socket with 1007).
|
|
9
|
+
*/
|
|
10
|
+
/** A live session's setup as Gemini frames it: the request, plus the handle it resumes from. */
|
|
11
|
+
export type LiveSetupRequest = ModelRequest & {
|
|
12
|
+
sessionResumptionHandle?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function buildGeminiLiveSetupMessage(req: LiveSetupRequest): Record<string, unknown>;
|
|
5
15
|
export declare function buildGeminiLiveClientContent(history: TurnHistoryMessage[]): Record<string, unknown> | null;
|
|
6
16
|
export declare function buildGeminiLiveContext(text: string): Record<string, unknown>;
|
|
7
17
|
export declare function buildGeminiLiveRealtimeInput(input: InteractionPart): Record<string, unknown>;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function buildGeminiLiveToolResponse(id: string, name: string, output: unknown): Record<string, unknown>;
|
|
18
|
+
export declare function buildGeminiLiveToolResponse(id: string, name: string, output: unknown, parts?: InteractionPart[]): Record<string, unknown>;
|
|
10
19
|
export declare function buildGeminiLiveToolResponses(responses: Array<{
|
|
11
20
|
id: string;
|
|
12
21
|
name: string;
|
|
13
22
|
output: unknown;
|
|
23
|
+
parts?: InteractionPart[];
|
|
14
24
|
}>): Record<string, unknown>;
|
|
15
25
|
/** What one outbound frame gives the model to read; setup and control frames give none. */
|
|
16
26
|
export declare function liveFrameInput(frame: Record<string, unknown>): TurnHistoryMessage[];
|
|
@@ -48,4 +58,4 @@ export type LiveInteractionStatus = 'IN_PROGRESS' | 'IDLE';
|
|
|
48
58
|
* flow, `IDLE` on the last).
|
|
49
59
|
*/
|
|
50
60
|
export declare function readLiveInteractionStatus(message: Record<string, unknown>): LiveInteractionStatus | undefined;
|
|
51
|
-
export declare function foldGeminiLiveServerMessage(message: Record<string, unknown> | null | undefined, fold: LiveFold):
|
|
61
|
+
export declare function foldGeminiLiveServerMessage(message: Record<string, unknown> | null | undefined, fold: LiveFold): ModelEvent[];
|