@theoremjs/agents 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +276 -995
- package/esm/mod.d.ts +33 -19
- package/esm/mod.js +18 -11
- 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 +23 -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 +874 -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 +29 -21
- package/esm/src/guardrails/mod.js +18 -13
- 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 +1 -0
- package/esm/src/guardrails/quota.js +1 -1
- 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 +4 -1
- package/esm/src/guardrails/theorem-error.js +3 -2
- 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 +7 -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 +173 -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 +328 -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 +128 -87
- 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 +105 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/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 +3 -209
- 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 +17 -0
- package/esm/src/providers/shared/retry.js +90 -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
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface VideoInfo {
|
|
2
|
-
/** Presented length of the first video track. */
|
|
3
|
-
seconds: number;
|
|
4
|
-
/** Coded frame size of the first video track. */
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
/** `0` when there is no audio track; `undefined` when its length cannot be read exactly. */
|
|
8
|
-
audioSeconds: number | undefined;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Identified by the bytes, not the declared MIME type. MP4 video length is the edit-list-aware
|
|
12
|
-
* header duration; Matroska video ends one frame after its latest block, else at the segment's
|
|
13
|
-
* stated `Duration`, and Matroska audio is known only when it is unlaced Opus.
|
|
14
|
-
*/
|
|
15
|
-
export declare function videoInfo(bytes: Uint8Array): VideoInfo | undefined;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { MKV_AUDIO_TRACK, MKV_VIDEO_TRACK, matroska, opusSamplesFromNs, } from './matroska.js';
|
|
2
|
-
import { MP4_SOUND, MP4_VIDEO, mp4Tracks } from './mp4.js';
|
|
3
|
-
import { OPUS_RATE } from './opus.js';
|
|
4
|
-
const NS_PER_SECOND = 1e9;
|
|
5
|
-
function mp4Video(bytes) {
|
|
6
|
-
const tracks = mp4Tracks(bytes);
|
|
7
|
-
const video = tracks?.find((t) => t.handler === MP4_VIDEO);
|
|
8
|
-
if (!tracks || !video?.seconds || !video.width || !video.height)
|
|
9
|
-
return undefined;
|
|
10
|
-
const audio = tracks.find((t) => t.handler === MP4_SOUND);
|
|
11
|
-
return {
|
|
12
|
-
seconds: video.seconds,
|
|
13
|
-
width: video.width,
|
|
14
|
-
height: video.height,
|
|
15
|
-
audioSeconds: audio ? audio.decodedSeconds : 0,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/** End of the last frame: latest block timestamp plus one frame. */
|
|
19
|
-
function matroskaVideoSeconds(track) {
|
|
20
|
-
if (track.lastNs === undefined)
|
|
21
|
-
return undefined;
|
|
22
|
-
const frameNs = track.defaultDurationNs ??
|
|
23
|
-
(track.previousNs === undefined ? undefined : track.lastNs - track.previousNs);
|
|
24
|
-
return frameNs === undefined ? undefined : (track.lastNs + frameNs) / NS_PER_SECOND;
|
|
25
|
-
}
|
|
26
|
-
function matroskaVideo(bytes) {
|
|
27
|
-
const file = matroska(bytes);
|
|
28
|
-
const video = file?.tracks.find((t) => t.type === MKV_VIDEO_TRACK);
|
|
29
|
-
if (!file || !video?.pixelWidth || !video.pixelHeight)
|
|
30
|
-
return undefined;
|
|
31
|
-
const seconds = (file.complete ? matroskaVideoSeconds(video) : undefined) ?? file.durationSeconds;
|
|
32
|
-
if (!seconds || seconds <= 0)
|
|
33
|
-
return undefined;
|
|
34
|
-
const audio = file.tracks.find((t) => t.type === MKV_AUDIO_TRACK);
|
|
35
|
-
const audioSeconds = !audio
|
|
36
|
-
? 0
|
|
37
|
-
: file.complete && audio.opusSamples !== undefined
|
|
38
|
-
? Math.max(0, audio.opusSamples - opusSamplesFromNs(audio.codecDelayNs)) / OPUS_RATE
|
|
39
|
-
: undefined;
|
|
40
|
-
return { seconds, width: video.pixelWidth, height: video.pixelHeight, audioSeconds };
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Identified by the bytes, not the declared MIME type. MP4 video length is the edit-list-aware
|
|
44
|
-
* header duration; Matroska video ends one frame after its latest block, else at the segment's
|
|
45
|
-
* stated `Duration`, and Matroska audio is known only when it is unlaced Opus.
|
|
46
|
-
*/
|
|
47
|
-
export function videoInfo(bytes) {
|
|
48
|
-
return mp4Video(bytes) ?? matroskaVideo(bytes);
|
|
49
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { KeyVault, ModelId, ModelProvider, Profile } from '../kernel/types.js';
|
|
2
|
-
import type { GeminiOptions } from './google/keys.js';
|
|
3
|
-
import type { LocalProviderConfig, OpenAiGatewayConfig } from './types.js';
|
|
4
|
-
export interface CreateProviderOptions {
|
|
5
|
-
/**
|
|
6
|
-
* The host's keys by slot, for every provider. A model's calls use the slot its profile names
|
|
7
|
-
* (`key`, `fallbackKey`); a slot holds whatever secret the host put there.
|
|
8
|
-
*/
|
|
9
|
-
vault?: KeyVault;
|
|
10
|
-
gemini?: GeminiOptions;
|
|
11
|
-
/** `voice` is the fallback when a speech profile omits `speech.voice`. */
|
|
12
|
-
openAiGateway?: OpenAiGatewayConfig & {
|
|
13
|
-
voice?: string;
|
|
14
|
-
};
|
|
15
|
-
/** Required for `local` profiles. */
|
|
16
|
-
local?: LocalProviderConfig;
|
|
17
|
-
}
|
|
18
|
-
export declare function isSpeechRole(profile: Profile): boolean;
|
|
19
|
-
export declare function isImageRole(profile: Profile): boolean;
|
|
20
|
-
/** Live profiles use `runSession`. `modelId` picks the binding; default `defaultModel`. */
|
|
21
|
-
export declare function createProvider(profile: Profile, options?: CreateProviderOptions, modelId?: ModelId): ModelProvider;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { TheoremError } from '../guardrails/error.js';
|
|
2
|
-
import { requireModelProfile } from '../kernel/registry/resolve.js';
|
|
3
|
-
import { isValidPair } from '../kernel/schema.js';
|
|
4
|
-
import { markModuleLoad } from './probe.js';
|
|
5
|
-
export function isSpeechRole(profile) {
|
|
6
|
-
return profile.type === 'speech';
|
|
7
|
-
}
|
|
8
|
-
export function isImageRole(profile) {
|
|
9
|
-
return profile.type === 'image';
|
|
10
|
-
}
|
|
11
|
-
function bindingForProvider(input, modelId) {
|
|
12
|
-
const profile = requireModelProfile(input, 'createProvider');
|
|
13
|
-
const id = modelId ?? profile.defaultModel;
|
|
14
|
-
const binding = profile.models[id];
|
|
15
|
-
if (!binding) {
|
|
16
|
-
throw new TheoremError('config', `createProvider: profile '${profile.id}' has no model '${id}'`);
|
|
17
|
-
}
|
|
18
|
-
return binding;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Lazy-load an adapter on first `complete`. When `THEOREM_IMPORT_PROBE=1`,
|
|
22
|
-
* emits `LOADED:<label>` exactly once at load time (import-isolation tests).
|
|
23
|
-
*/
|
|
24
|
-
function lazyAdapter(label, load) {
|
|
25
|
-
let pending;
|
|
26
|
-
return {
|
|
27
|
-
async *complete(req) {
|
|
28
|
-
pending ??= (async () => {
|
|
29
|
-
markModuleLoad(label);
|
|
30
|
-
return await load();
|
|
31
|
-
})();
|
|
32
|
-
yield* (await pending).complete(req);
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function lazyOpenRouterChat(config) {
|
|
37
|
-
return lazyAdapter('openrouter-chat', () => import('./openrouter/chat.js').then((m) => m.createOpenRouterProvider(config)));
|
|
38
|
-
}
|
|
39
|
-
function lazyGoogleInteractions(config) {
|
|
40
|
-
return lazyAdapter('google-interactions-adapter', () => import('./google/interactions/mod.js').then((m) => m.createInteractionsProvider(config)));
|
|
41
|
-
}
|
|
42
|
-
function lazySpeech(config) {
|
|
43
|
-
return lazyAdapter('openrouter-speech', () => import('./openrouter/speech.js').then((m) => m.createSpeechProvider(config)));
|
|
44
|
-
}
|
|
45
|
-
function lazyImage(config) {
|
|
46
|
-
return lazyAdapter('openrouter-image', () => import('./openrouter/image.js').then((m) => m.createImageProvider(config)));
|
|
47
|
-
}
|
|
48
|
-
function lazyLocal(config) {
|
|
49
|
-
return lazyAdapter('local-adapter', () => import('./local/local.js').then((m) => m.createLocalProvider(config)));
|
|
50
|
-
}
|
|
51
|
-
/** Live profiles use `runSession`. `modelId` picks the binding; default `defaultModel`. */
|
|
52
|
-
export function createProvider(profile, options = {}, modelId) {
|
|
53
|
-
const { protocol, provider } = bindingForProvider(profile, modelId);
|
|
54
|
-
if (!isValidPair(protocol, provider)) {
|
|
55
|
-
throw new TheoremError('config', `createProvider: unsupported protocol/provider pair '${protocol}'/'${provider}'`);
|
|
56
|
-
}
|
|
57
|
-
if (protocol === 'geminiInteractions' && provider === 'google') {
|
|
58
|
-
if (!options.vault) {
|
|
59
|
-
throw new TheoremError('config', 'createProvider requires a vault for google models');
|
|
60
|
-
}
|
|
61
|
-
return lazyGoogleInteractions({ ...options.gemini, vault: options.vault });
|
|
62
|
-
}
|
|
63
|
-
if (protocol === 'geminiLive' && provider === 'google') {
|
|
64
|
-
throw new TheoremError('request', "createProvider does not support type 'live' / geminiLive — use runSession(req, { vault })");
|
|
65
|
-
}
|
|
66
|
-
if (protocol === 'openAi' && provider === 'openrouter') {
|
|
67
|
-
if (!options.vault) {
|
|
68
|
-
throw new TheoremError('config', 'createProvider requires a vault for openrouter models');
|
|
69
|
-
}
|
|
70
|
-
const gateway = { ...options.openAiGateway, vault: options.vault };
|
|
71
|
-
if (isSpeechRole(profile)) {
|
|
72
|
-
return lazySpeech(gateway);
|
|
73
|
-
}
|
|
74
|
-
if (isImageRole(profile)) {
|
|
75
|
-
return lazyImage(gateway);
|
|
76
|
-
}
|
|
77
|
-
return lazyOpenRouterChat(gateway);
|
|
78
|
-
}
|
|
79
|
-
if (protocol === 'openAi' && provider === 'local') {
|
|
80
|
-
if (isImageRole(profile)) {
|
|
81
|
-
throw new TheoremError('config', 'createProvider: type image requires openrouter provider for openAi protocol');
|
|
82
|
-
}
|
|
83
|
-
// A profile can name `local`; only the host can say a local server is there to reach.
|
|
84
|
-
if (!options.local) {
|
|
85
|
-
throw new TheoremError('config', 'createProvider requires local config for openAi/local');
|
|
86
|
-
}
|
|
87
|
-
return lazyLocal({ ...options.local, vault: options.vault });
|
|
88
|
-
}
|
|
89
|
-
throw new TheoremError('config', `createProvider: unsupported protocol/provider pair '${protocol}'/'${provider}'`);
|
|
90
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { DecisionModelBinding, DecisionResult } from '../../kernel/types.js';
|
|
2
|
-
/** Provider-reported usage, with Jev's published tariff only for a direct Jev response. */
|
|
3
|
-
export declare function decisionUsage(usage: unknown, binding: Pick<DecisionModelBinding, 'provider' | 'apiId'>, responseModel: string): DecisionResult['usage'];
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { isRecord } from '../../kernel/util/record.js';
|
|
2
|
-
import { JEV_USD_PER_MILLION_INPUT_TOKENS } from '../../presets/typesafe.js';
|
|
3
|
-
/** Provider-reported usage, with Jev's published tariff only for a direct Jev response. */
|
|
4
|
-
export function decisionUsage(usage, binding, responseModel) {
|
|
5
|
-
if (!isRecord(usage) ||
|
|
6
|
-
!Number.isSafeInteger(usage.input_tokens) ||
|
|
7
|
-
!Number.isSafeInteger(usage.output_tokens) ||
|
|
8
|
-
usage.input_tokens < 0 ||
|
|
9
|
-
usage.output_tokens < 0)
|
|
10
|
-
return undefined;
|
|
11
|
-
const inputTokens = usage.input_tokens;
|
|
12
|
-
const reported = typeof usage.cost === 'number' && Number.isFinite(usage.cost) && usage.cost >= 0
|
|
13
|
-
? usage.cost
|
|
14
|
-
: undefined;
|
|
15
|
-
const directJev = binding.provider === 'typesafe' &&
|
|
16
|
-
binding.apiId.startsWith('jev-') &&
|
|
17
|
-
responseModel.startsWith('jev-');
|
|
18
|
-
const costUsd = reported ??
|
|
19
|
-
(directJev ? (inputTokens * JEV_USD_PER_MILLION_INPUT_TOKENS) / 1_000_000 : undefined);
|
|
20
|
-
return {
|
|
21
|
-
inputTokens,
|
|
22
|
-
outputTokens: usage.output_tokens,
|
|
23
|
-
...(costUsd === undefined ? {} : { costUsd }),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { KeySlot, KeyVault, ProviderCompleteRequest } from '../../kernel/types.js';
|
|
2
|
-
/** A host's Gemini settings; keys come from the one vault. */
|
|
3
|
-
interface GeminiOptions {
|
|
4
|
-
wait?: (ms: number) => Promise<void>;
|
|
5
|
-
fetch?: typeof fetch;
|
|
6
|
-
}
|
|
7
|
-
interface GeminiTransport extends GeminiOptions {
|
|
8
|
-
vault: KeyVault;
|
|
9
|
-
}
|
|
10
|
-
export declare function waitDefault(ms: number): Promise<void>;
|
|
11
|
-
export declare function isTransientHttp(status: number): boolean;
|
|
12
|
-
export declare function isTransientThrown(err: unknown): boolean;
|
|
13
|
-
export declare function backoffMs(attempt: number): number;
|
|
14
|
-
export declare function withApiKey(init: RequestInit, apiKey: string): RequestInit;
|
|
15
|
-
/**
|
|
16
|
-
* Backs off on transient failures. A quota refusal retries once on the profile's fallback slot,
|
|
17
|
-
* when it names one; each try's slot is on the tape, so the trace shows the switch.
|
|
18
|
-
*/
|
|
19
|
-
export declare function fetchGemini(url: string, init: RequestInit, slot: KeySlot, transport: GeminiTransport, tap?: ProviderCompleteRequest['tapUpstream'], fallbackSlot?: KeySlot): Promise<Response>;
|
|
20
|
-
export type { GeminiOptions, GeminiTransport };
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { isAbortError } from '../../guardrails/error.js';
|
|
2
|
-
import { networkError, tapFetch } from '../shared/upstream-tap.js';
|
|
3
|
-
import { fallbackKey, requireKey } from '../shared/vault.js';
|
|
4
|
-
const ATTEMPTS = 3;
|
|
5
|
-
const LAST_ATTEMPT = ATTEMPTS - 1;
|
|
6
|
-
const BACKOFF_FIRST_MS = 1000;
|
|
7
|
-
const BACKOFF_SECOND_MS = 2000;
|
|
8
|
-
const BACKOFF_THIRD_MS = 4000;
|
|
9
|
-
const BACKOFF_MS = [BACKOFF_FIRST_MS, BACKOFF_SECOND_MS, BACKOFF_THIRD_MS];
|
|
10
|
-
const HTTP_TIMEOUT = 408;
|
|
11
|
-
const HTTP_QUOTA = 429;
|
|
12
|
-
const HTTP_SERVER = 500;
|
|
13
|
-
const HTTP_BAD_GATEWAY = 502;
|
|
14
|
-
const HTTP_UNAVAILABLE = 503;
|
|
15
|
-
const HTTP_GATEWAY_TIMEOUT = 504;
|
|
16
|
-
const TRANSIENT_THROWN_RE = /name resolution|dns|econnreset|econnrefused|etimedout|network|fetch failed|temporarily unavailable|socket|503|502|504/i;
|
|
17
|
-
export function waitDefault(ms) {
|
|
18
|
-
return new Promise((resolve) => {
|
|
19
|
-
setTimeout(resolve, ms);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
export function isTransientHttp(status) {
|
|
23
|
-
return (status === HTTP_TIMEOUT ||
|
|
24
|
-
status === HTTP_QUOTA ||
|
|
25
|
-
status === HTTP_SERVER ||
|
|
26
|
-
status === HTTP_BAD_GATEWAY ||
|
|
27
|
-
status === HTTP_UNAVAILABLE ||
|
|
28
|
-
status === HTTP_GATEWAY_TIMEOUT);
|
|
29
|
-
}
|
|
30
|
-
export function isTransientThrown(err) {
|
|
31
|
-
if (isAbortError(err)) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return TRANSIENT_THROWN_RE.test(String(err));
|
|
35
|
-
}
|
|
36
|
-
export function backoffMs(attempt) {
|
|
37
|
-
return BACKOFF_MS[attempt] ?? BACKOFF_SECOND_MS;
|
|
38
|
-
}
|
|
39
|
-
export function withApiKey(init, apiKey) {
|
|
40
|
-
const headers = new Headers(init.headers);
|
|
41
|
-
headers.set('x-goog-api-key', apiKey);
|
|
42
|
-
if (!headers.has('Content-Type') && (init.method || 'GET').toUpperCase() !== 'GET') {
|
|
43
|
-
headers.set('Content-Type', 'application/json');
|
|
44
|
-
}
|
|
45
|
-
return { ...init, headers };
|
|
46
|
-
}
|
|
47
|
-
async function fetchWithBackoff(args) {
|
|
48
|
-
const wait = args.transport.wait ?? waitDefault;
|
|
49
|
-
const send = tapFetch(args.tap, args.transport.fetch ?? fetch, args.slot);
|
|
50
|
-
try {
|
|
51
|
-
const last = await send(args.href, withApiKey(args.init, args.apiKey));
|
|
52
|
-
if (!isTransientHttp(last.status) || args.attempt === LAST_ATTEMPT) {
|
|
53
|
-
return last;
|
|
54
|
-
}
|
|
55
|
-
if (args.init.signal?.aborted) {
|
|
56
|
-
throw args.init.signal.reason instanceof Error
|
|
57
|
-
? args.init.signal.reason
|
|
58
|
-
: new DOMException('The operation was aborted.', 'AbortError');
|
|
59
|
-
}
|
|
60
|
-
await wait(backoffMs(args.attempt));
|
|
61
|
-
return fetchWithBackoff({ ...args, attempt: args.attempt + 1 });
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
if (isAbortError(err) || !isTransientThrown(err) || args.attempt === LAST_ATTEMPT) {
|
|
65
|
-
throw networkError(err);
|
|
66
|
-
}
|
|
67
|
-
await wait(backoffMs(args.attempt));
|
|
68
|
-
return fetchWithBackoff({ ...args, attempt: args.attempt + 1 });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Backs off on transient failures. A quota refusal retries once on the profile's fallback slot,
|
|
73
|
-
* when it names one; each try's slot is on the tape, so the trace shows the switch.
|
|
74
|
-
*/
|
|
75
|
-
export async function fetchGemini(url, init, slot, transport, tap, fallbackSlot) {
|
|
76
|
-
const parsed = new URL(url);
|
|
77
|
-
parsed.searchParams.delete('key');
|
|
78
|
-
const href = parsed.toString();
|
|
79
|
-
const primary = requireKey(transport.vault, slot);
|
|
80
|
-
const first = { href, init, transport, tap, attempt: 0 };
|
|
81
|
-
let last = await fetchWithBackoff({ ...first, apiKey: primary, slot });
|
|
82
|
-
const fallback = fallbackKey(fallbackSlot, transport.vault, primary);
|
|
83
|
-
if (last.status === HTTP_QUOTA && fallback) {
|
|
84
|
-
last = await fetchWithBackoff({ ...first, apiKey: fallback.key, slot: fallback.slot });
|
|
85
|
-
}
|
|
86
|
-
return last;
|
|
87
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gemini Live socket transport, opened by `runSession`; it applies no guardrails of its own.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
import "../../../../_dnt.polyfills.js";
|
|
7
|
-
export { type GoogleLiveConnection, type OpenLiveWebSocket, openGoogleLiveSession, } from './session.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function toGeminiOpenApiSchema(value: unknown): unknown;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// JSON Schema uses lowercase `object`/`string`; Gemini Live expects OpenAPI 3.0 `OBJECT`/`STRING`.
|
|
2
|
-
function convertGeminiSchemaType(value) {
|
|
3
|
-
if (typeof value === 'string')
|
|
4
|
-
return { type: value.toUpperCase() };
|
|
5
|
-
if (!Array.isArray(value))
|
|
6
|
-
return { type: toGeminiOpenApiSchema(value) };
|
|
7
|
-
const schemaTypes = value.filter((item) => typeof item === 'string');
|
|
8
|
-
const nonNullTypes = schemaTypes.filter((item) => item !== 'null');
|
|
9
|
-
const converted = {};
|
|
10
|
-
if (schemaTypes.includes('null'))
|
|
11
|
-
converted.nullable = true;
|
|
12
|
-
const [onlyType] = nonNullTypes;
|
|
13
|
-
if (onlyType !== undefined && nonNullTypes.length === 1)
|
|
14
|
-
converted.type = onlyType.toUpperCase();
|
|
15
|
-
if (nonNullTypes.length > 1) {
|
|
16
|
-
converted.anyOf = nonNullTypes.map((item) => ({ type: item.toUpperCase() }));
|
|
17
|
-
}
|
|
18
|
-
return converted;
|
|
19
|
-
}
|
|
20
|
-
function convertGeminiSchemaObject(obj) {
|
|
21
|
-
const result = {};
|
|
22
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
23
|
-
if (key === 'type') {
|
|
24
|
-
Object.assign(result, convertGeminiSchemaType(value));
|
|
25
|
-
}
|
|
26
|
-
else if (key === 'enum' && Array.isArray(value)) {
|
|
27
|
-
result.enum = value.filter((item) => item !== null);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
result[key] = toGeminiOpenApiSchema(value);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
export function toGeminiOpenApiSchema(value) {
|
|
36
|
-
if (Array.isArray(value))
|
|
37
|
-
return value.map(toGeminiOpenApiSchema);
|
|
38
|
-
if (value !== null && typeof value === 'object') {
|
|
39
|
-
return convertGeminiSchemaObject(value);
|
|
40
|
-
}
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ProviderCompleteRequest } from '../../../kernel/types.js';
|
|
2
|
-
import type { GeminiTransport } from '../keys.js';
|
|
3
|
-
import { type SessionQueueItem } from './stream.js';
|
|
4
|
-
export interface GoogleLiveConnection {
|
|
5
|
-
readonly setup: Record<string, unknown>;
|
|
6
|
-
send(payload: Record<string, unknown>): void;
|
|
7
|
-
batches(): AsyncGenerator<SessionQueueItem>;
|
|
8
|
-
close(code?: number, reason?: string): void;
|
|
9
|
-
}
|
|
10
|
-
export type OpenLiveWebSocket = (url: string) => Promise<WebSocket>;
|
|
11
|
-
/** Tape row: setup on the pinned key was refused for quota, so the session opens on the fallback slot. */
|
|
12
|
-
export declare const LIVE_FALLBACK_ROW = "ws_fallback";
|
|
13
|
-
/** @param openWebSocket Host override, e.g. for a Cloudflare fetch-upgrade. */
|
|
14
|
-
export declare function openGoogleLiveSession(req: ProviderCompleteRequest, transport: GeminiTransport, openWebSocket?: OpenLiveWebSocket): Promise<GoogleLiveConnection>;
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { describeError, isAbortError, TheoremError } from '../../../guardrails/error.js';
|
|
2
|
-
import { fallbackKey, requireKey } from '../../shared/vault.js';
|
|
3
|
-
import { buildGeminiLiveWebSocketUrl } from './framing.js';
|
|
4
|
-
import { attachLiveSessionHandlers, createLiveQueue, performLiveSetup, sendInitialPayloads, sendLiveFrame, } from './stream.js';
|
|
5
|
-
function defaultOpenWebSocket(url) {
|
|
6
|
-
return Promise.resolve(new WebSocket(url));
|
|
7
|
-
}
|
|
8
|
-
function attachAbort(ws, liveQueue, signal) {
|
|
9
|
-
const onAbort = () => {
|
|
10
|
-
if (!liveQueue.isClosed()) {
|
|
11
|
-
liveQueue.close();
|
|
12
|
-
try {
|
|
13
|
-
ws.close(1000, 'aborted');
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
// Ignore
|
|
17
|
-
}
|
|
18
|
-
liveQueue.push({
|
|
19
|
-
type: 'error',
|
|
20
|
-
error: new DOMException('The operation was aborted.', 'AbortError'),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
if (!signal) {
|
|
25
|
-
return () => { };
|
|
26
|
-
}
|
|
27
|
-
if (signal.aborted) {
|
|
28
|
-
onAbort();
|
|
29
|
-
return () => { };
|
|
30
|
-
}
|
|
31
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
32
|
-
return () => signal.removeEventListener('abort', onAbort);
|
|
33
|
-
}
|
|
34
|
-
/** Tape row: setup on the pinned key was refused for quota, so the session opens on the fallback slot. */
|
|
35
|
-
export const LIVE_FALLBACK_ROW = 'ws_fallback';
|
|
36
|
-
async function openOnKey(req, apiKey, openWebSocket) {
|
|
37
|
-
let ws;
|
|
38
|
-
try {
|
|
39
|
-
ws = await openWebSocket(buildGeminiLiveWebSocketUrl(apiKey));
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
throw err instanceof Error ? err : new Error(String(err));
|
|
43
|
-
}
|
|
44
|
-
const liveQueue = createLiveQueue();
|
|
45
|
-
const detachAbort = attachAbort(ws, liveQueue, req.signal);
|
|
46
|
-
if (req.signal?.aborted) {
|
|
47
|
-
detachAbort();
|
|
48
|
-
try {
|
|
49
|
-
ws.close();
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// Ignore
|
|
53
|
-
}
|
|
54
|
-
throw new DOMException('The operation was aborted.', 'AbortError');
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
return { ws, liveQueue, detachAbort, setup: await performLiveSetup(ws, req) };
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
detachAbort();
|
|
61
|
-
try {
|
|
62
|
-
ws.close();
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
// Ignore
|
|
66
|
-
}
|
|
67
|
-
throw err;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Open on the pinned key; a quota refusal at setup reopens on the profile's
|
|
72
|
-
* fallback slot when it names one, as `fetchGemini` does for HTTP.
|
|
73
|
-
* The tape records the refusal (`ws_fallback`) before the retry.
|
|
74
|
-
*/
|
|
75
|
-
async function openWithOverflow(req, transport, openWebSocket) {
|
|
76
|
-
if (!req.keySlot) {
|
|
77
|
-
throw new TheoremError('config', 'Request requires keySlot');
|
|
78
|
-
}
|
|
79
|
-
const primary = requireKey(transport.vault, req.keySlot);
|
|
80
|
-
try {
|
|
81
|
-
return await openOnKey(req, primary, openWebSocket);
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
const fallback = fallbackKey(req.fallbackKeySlot, transport.vault, primary);
|
|
85
|
-
if (!fallback || !(err instanceof TheoremError) || err.kind !== 'rate_limit')
|
|
86
|
-
throw err;
|
|
87
|
-
req.tapUpstream?.({
|
|
88
|
-
eventType: LIVE_FALLBACK_ROW,
|
|
89
|
-
from: req.keySlot,
|
|
90
|
-
keySlot: fallback.slot,
|
|
91
|
-
errorKind: err.kind,
|
|
92
|
-
error: describeError(err),
|
|
93
|
-
});
|
|
94
|
-
return await openOnKey(req, fallback.key, openWebSocket);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/** @param openWebSocket Host override, e.g. for a Cloudflare fetch-upgrade. */
|
|
98
|
-
export async function openGoogleLiveSession(req, transport, openWebSocket = defaultOpenWebSocket) {
|
|
99
|
-
const { ws, liveQueue, detachAbort, setup } = await openWithOverflow(req, transport, openWebSocket);
|
|
100
|
-
attachLiveSessionHandlers(ws, liveQueue);
|
|
101
|
-
sendInitialPayloads(ws, req);
|
|
102
|
-
return {
|
|
103
|
-
setup,
|
|
104
|
-
send(payload) {
|
|
105
|
-
if (ws.readyState === WebSocket.OPEN) {
|
|
106
|
-
sendLiveFrame(ws, payload, req.tapUpstream);
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
async *batches() {
|
|
110
|
-
try {
|
|
111
|
-
while (true) {
|
|
112
|
-
const item = await liveQueue.next();
|
|
113
|
-
if (!item)
|
|
114
|
-
break;
|
|
115
|
-
if (item.type === 'error' && isAbortError(item.error)) {
|
|
116
|
-
throw item.error;
|
|
117
|
-
}
|
|
118
|
-
yield item;
|
|
119
|
-
if (item.type === 'closed' || item.type === 'error') {
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
finally {
|
|
125
|
-
detachAbort();
|
|
126
|
-
liveQueue.close();
|
|
127
|
-
try {
|
|
128
|
-
if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
|
|
129
|
-
ws.close(1000, 'session-closed');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
// Ignore
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
close(code = 1000, reason = 'session-closed') {
|
|
138
|
-
detachAbort();
|
|
139
|
-
liveQueue.close();
|
|
140
|
-
try {
|
|
141
|
-
if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
|
|
142
|
-
ws.close(code, reason);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
146
|
-
// Ignore
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ModelProvider, ProviderEvent } from '../../kernel/types.js';
|
|
2
|
-
import { buildChatMessages, wireTools } from '../openrouter/openai/compat.js';
|
|
3
|
-
import type { LocalTransport } from '../types.js';
|
|
4
|
-
export type PendingToolCall = {
|
|
5
|
-
id: string;
|
|
6
|
-
name: string;
|
|
7
|
-
args: string;
|
|
8
|
-
};
|
|
9
|
-
export declare function resolveBaseUrl(config: LocalTransport): string;
|
|
10
|
-
export declare function flushPending(pending: Map<number, PendingToolCall>): ProviderEvent[];
|
|
11
|
-
declare function createLocalProvider(config: LocalTransport): ModelProvider;
|
|
12
|
-
export { buildChatMessages as historyToWire, createLocalProvider, wireTools as toolsToWire };
|