@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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
3
|
+
import { labelText } from '../../guardrails/labels.js';
|
|
4
|
+
import { jsonObjectSchema } from '../json.js';
|
|
5
|
+
import { KEY_SLOT_NAME } from '../schema.js';
|
|
6
|
+
import { modelOptions } from './protocol.js';
|
|
7
|
+
/** A vault slot name. */
|
|
8
|
+
export const keySlotSchema = z.string().regex(KEY_SLOT_NAME);
|
|
9
|
+
export const commonModelSettingsSchema = z.strictObject({
|
|
10
|
+
maxOutputTokens: z.number().int().positive().optional(),
|
|
11
|
+
temperature: z.number().finite().nonnegative().optional(),
|
|
12
|
+
efforts: z
|
|
13
|
+
.record(z.string().min(1), z.enum(['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']))
|
|
14
|
+
.optional(),
|
|
15
|
+
defaultEffort: z.string().min(1).optional(),
|
|
16
|
+
allowEffortSelect: z.boolean().optional(),
|
|
17
|
+
summaries: z.boolean().optional(),
|
|
18
|
+
builtInTools: z.array(z.string().min(1)).optional(),
|
|
19
|
+
compaction: z
|
|
20
|
+
.custom((value) => typeof value === 'object' && value !== null && !Array.isArray(value))
|
|
21
|
+
.optional(),
|
|
22
|
+
});
|
|
23
|
+
const shared = commonModelSettingsSchema.shape;
|
|
24
|
+
const modelBinding = z.strictObject({
|
|
25
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
26
|
+
protocol: z.string().min(1).describe('The API shape this model is spoken to in.'),
|
|
27
|
+
provider: z.string().min(1).describe(
|
|
28
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
29
|
+
'The service that runs the model or routes requests to one, such as Gemini or OpenRouter. Its registration supplies the endpoint and authentication.'),
|
|
30
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
31
|
+
apiId: z.string().min(1).describe('The id the provider knows the model by.'),
|
|
32
|
+
maxOutputTokens: shared.maxOutputTokens.describe(
|
|
33
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
34
|
+
'The most tokens the model may write in one step.'),
|
|
35
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
36
|
+
temperature: shared.temperature.describe("How varied the model's answers are."),
|
|
37
|
+
efforts: shared.efforts.describe(
|
|
38
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
39
|
+
'Effort names a turn may pick, each mapped to a thinking level.'),
|
|
40
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
41
|
+
defaultEffort: shared.defaultEffort.describe('The effort used when a turn picks none.'),
|
|
42
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
43
|
+
allowEffortSelect: shared.allowEffortSelect.describe('Whether a turn may pick an effort.'),
|
|
44
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
45
|
+
summaries: shared.summaries.describe('Whether the model sends summaries of its thinking.'),
|
|
46
|
+
builtInTools: shared.builtInTools.describe(
|
|
47
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
48
|
+
'Tools the provider runs itself, by the ids it knows them by.'),
|
|
49
|
+
compaction: shared.compaction.describe(
|
|
50
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
51
|
+
'How the conversation is shortened when it grows too long.'),
|
|
52
|
+
keySlot: keySlotSchema
|
|
53
|
+
.optional()
|
|
54
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
55
|
+
.describe("The slot this model's key is read from, in place of the provider's."),
|
|
56
|
+
fallbackKeySlot: keySlotSchema
|
|
57
|
+
.optional()
|
|
58
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
59
|
+
.describe('The slot tried once when the first key is out of quota.'),
|
|
60
|
+
options: jsonObjectSchema
|
|
61
|
+
.optional()
|
|
62
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
63
|
+
.describe("What this model's protocol takes beyond the shared settings."),
|
|
64
|
+
});
|
|
65
|
+
true;
|
|
66
|
+
export const modelBindingSchema = modelBinding;
|
|
67
|
+
const decisionModelBinding = modelBinding
|
|
68
|
+
.pick({
|
|
69
|
+
protocol: true,
|
|
70
|
+
provider: true,
|
|
71
|
+
apiId: true,
|
|
72
|
+
keySlot: true,
|
|
73
|
+
fallbackKeySlot: true,
|
|
74
|
+
options: true,
|
|
75
|
+
})
|
|
76
|
+
.extend({
|
|
77
|
+
timeoutMs: z
|
|
78
|
+
.number()
|
|
79
|
+
.positive()
|
|
80
|
+
.optional()
|
|
81
|
+
// labels-exempt: builder field description, read by the studio and docs
|
|
82
|
+
.describe('How long a decision may take before it fails.'),
|
|
83
|
+
});
|
|
84
|
+
true;
|
|
85
|
+
export const decisionModelBindingSchema = decisionModelBinding;
|
|
86
|
+
/** The slots a model reads its key from: the ones it names, else its provider's. */
|
|
87
|
+
export function keySlotsOf(provider, binding) {
|
|
88
|
+
const keySlot = binding.keySlot ?? provider.keySlot;
|
|
89
|
+
const fallbackKeySlot = binding.fallbackKeySlot ?? provider.fallbackKeySlot;
|
|
90
|
+
return {
|
|
91
|
+
...(keySlot === undefined ? {} : { keySlot }),
|
|
92
|
+
...(fallbackKeySlot === undefined ? {} : { fallbackKeySlot }),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** The provider's serve of the protocol a binding speaks. */
|
|
96
|
+
export function bindingServe(provider, binding) {
|
|
97
|
+
const serve = provider.serves.find((entry) => entry.protocol.id === binding.protocol);
|
|
98
|
+
if (!serve)
|
|
99
|
+
throw new TheoremError('config', labelText('protocol.not_served', { provider: provider.id, protocol: binding.protocol }));
|
|
100
|
+
return serve;
|
|
101
|
+
}
|
|
102
|
+
/** The protocol a binding speaks on its provider. */
|
|
103
|
+
export function protocolOf(provider, binding) {
|
|
104
|
+
return bindingServe(provider, binding).protocol;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The one place a binding meets its provider, once, at registration, for fit only. Returns the
|
|
108
|
+
* binding with its options parsed; changes nothing in place.
|
|
109
|
+
*/
|
|
110
|
+
export function checkBinding(provider, binding, profileType, runtime = { webSocketHeaders: true }) {
|
|
111
|
+
const serve = bindingServe(provider, binding);
|
|
112
|
+
const { protocol } = serve;
|
|
113
|
+
if (protocol.endpoints[profileType] === undefined)
|
|
114
|
+
throw new TheoremError('unsupported', labelText('protocol.profile_type', { protocol: protocol.id, profileType }));
|
|
115
|
+
const options = jsonObjectSchema.parse(modelOptions(protocol, binding.apiId, binding.options));
|
|
116
|
+
const slots = keySlotsOf(provider, binding);
|
|
117
|
+
if (slots.keySlot !== undefined && slots.keySlot === slots.fallbackKeySlot)
|
|
118
|
+
throw new TheoremError('config', labelText('provider.model_fallback_slot'));
|
|
119
|
+
if ((binding.keySlot || binding.fallbackKeySlot) && !provider.definition.key)
|
|
120
|
+
throw new TheoremError('config', labelText('protocol.no_key', { provider: provider.id }));
|
|
121
|
+
const authorize = serve.authorize ?? provider.definition.authorize;
|
|
122
|
+
if (profileType === 'live' && authorize?.webSocketHeaders && !runtime.webSocketHeaders)
|
|
123
|
+
throw new TheoremError('unsupported', labelText('protocol.ws_headers', { provider: provider.id }));
|
|
124
|
+
return { ...binding, options: options };
|
|
125
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The budgets every provider call runs under; a host may tighten or loosen each. */
|
|
3
|
+
export interface ProviderLimits {
|
|
4
|
+
operationTimeoutMs: number;
|
|
5
|
+
connectTimeoutMs: number;
|
|
6
|
+
liveStepTimeoutMs: number;
|
|
7
|
+
maxWireRecordBytes: number;
|
|
8
|
+
maxWireResponseBytes: number;
|
|
9
|
+
maxEventBytes: number;
|
|
10
|
+
maxStepBytes: number;
|
|
11
|
+
maxStepEvents: number;
|
|
12
|
+
maxPendingToolCalls: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const providerLimitsSchema: z.ZodType<ProviderLimits>;
|
|
15
|
+
export declare function resolveProviderLimits(overrides?: Partial<ProviderLimits>): ProviderLimits;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const positiveBudget = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
3
|
+
const timerBudget = positiveBudget.max(2147483647);
|
|
4
|
+
export const providerLimitsSchema = z.strictObject({
|
|
5
|
+
operationTimeoutMs: timerBudget,
|
|
6
|
+
connectTimeoutMs: timerBudget,
|
|
7
|
+
liveStepTimeoutMs: timerBudget,
|
|
8
|
+
maxWireRecordBytes: positiveBudget,
|
|
9
|
+
maxWireResponseBytes: positiveBudget,
|
|
10
|
+
maxEventBytes: positiveBudget,
|
|
11
|
+
maxStepBytes: positiveBudget,
|
|
12
|
+
maxStepEvents: positiveBudget,
|
|
13
|
+
maxPendingToolCalls: positiveBudget,
|
|
14
|
+
});
|
|
15
|
+
export function resolveProviderLimits(overrides = {}) {
|
|
16
|
+
return Object.freeze(providerLimitsSchema.parse({
|
|
17
|
+
operationTimeoutMs: 120000,
|
|
18
|
+
connectTimeoutMs: 30000,
|
|
19
|
+
liveStepTimeoutMs: 120000,
|
|
20
|
+
maxWireRecordBytes: 16 * 1024 * 1024,
|
|
21
|
+
maxWireResponseBytes: 64 * 1024 * 1024,
|
|
22
|
+
maxEventBytes: 16 * 1024 * 1024,
|
|
23
|
+
maxStepBytes: 64 * 1024 * 1024,
|
|
24
|
+
maxStepEvents: 100000,
|
|
25
|
+
maxPendingToolCalls: 32,
|
|
26
|
+
...overrides,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TurnCost, TurnTokens } from '../turn-events.js';
|
|
2
|
+
/** US dollars per million tokens. Thinking tokens are billed as output. */
|
|
3
|
+
export interface Rates {
|
|
4
|
+
input: number;
|
|
5
|
+
output: number;
|
|
6
|
+
cachedInput?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Rates for one modality's share of a side, keyed as `TurnTokens.byModality` keys it (`audio`,
|
|
9
|
+
* `image`, …). A share with no rate here is billed at the side's own rate.
|
|
10
|
+
*/
|
|
11
|
+
byModality?: {
|
|
12
|
+
input?: Readonly<Record<string, number>>;
|
|
13
|
+
output?: Readonly<Record<string, number>>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** One model's rates, and the higher ones a prompt above `longContext.above` input tokens is billed at. */
|
|
17
|
+
export interface ModelPrice extends Rates {
|
|
18
|
+
longContext?: Rates & {
|
|
19
|
+
above: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A provider's prices, kept only where its API reports no cost. `models` is keyed by `apiId`; a
|
|
24
|
+
* key ending in `*` covers every id that starts with what comes before it. `checked` is the date
|
|
25
|
+
* the table was last checked against the provider's price page.
|
|
26
|
+
*/
|
|
27
|
+
export interface PriceTable {
|
|
28
|
+
checked: string;
|
|
29
|
+
models: Readonly<Record<string, ModelPrice>>;
|
|
30
|
+
}
|
|
31
|
+
/** A cost Theorem worked out from a price table, not one the API reported. */
|
|
32
|
+
export type EstimatedCost = TurnCost & {
|
|
33
|
+
estimated: true;
|
|
34
|
+
};
|
|
35
|
+
/** The cost of one call from its tokens, or nothing for a model the table doesn't price. */
|
|
36
|
+
export declare function costFromPrices(table: PriceTable, apiId: string, tokens: TurnTokens): EstimatedCost | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const PER = 1_000_000;
|
|
2
|
+
function priceFor(table, apiId) {
|
|
3
|
+
const exact = table.models[apiId];
|
|
4
|
+
if (exact)
|
|
5
|
+
return exact;
|
|
6
|
+
let best;
|
|
7
|
+
for (const [key, price] of Object.entries(table.models))
|
|
8
|
+
if (key.endsWith('*') &&
|
|
9
|
+
apiId.startsWith(key.slice(0, -1)) &&
|
|
10
|
+
key.length - 1 > (best?.prefix.length ?? -1))
|
|
11
|
+
best = { prefix: key.slice(0, -1), price };
|
|
12
|
+
return best?.price;
|
|
13
|
+
}
|
|
14
|
+
/** Bills each priced modality's share at its rate, and the rest of the side at `rate`. */
|
|
15
|
+
function sideUsd(count, rate, modalityRates, shares) {
|
|
16
|
+
let rest = count;
|
|
17
|
+
let usd = 0;
|
|
18
|
+
for (const [modality, modalityRate] of Object.entries(modalityRates ?? {})) {
|
|
19
|
+
const share = Math.min(shares?.[modality] ?? 0, rest);
|
|
20
|
+
usd += share * modalityRate;
|
|
21
|
+
rest -= share;
|
|
22
|
+
}
|
|
23
|
+
return usd + rest * rate;
|
|
24
|
+
}
|
|
25
|
+
/** The cost of one call from its tokens, or nothing for a model the table doesn't price. */
|
|
26
|
+
export function costFromPrices(table, apiId, tokens) {
|
|
27
|
+
const price = priceFor(table, apiId);
|
|
28
|
+
if (!price)
|
|
29
|
+
return undefined;
|
|
30
|
+
const rates = price.longContext && tokens.input > price.longContext.above ? price.longContext : price;
|
|
31
|
+
const cached = Math.min(tokens.cached ?? 0, tokens.input);
|
|
32
|
+
const usd = (cached * (rates.cachedInput ?? rates.input) +
|
|
33
|
+
sideUsd(tokens.input - cached, rates.input, rates.byModality?.input, tokens.byModality?.input) +
|
|
34
|
+
sideUsd(tokens.output, rates.output, rates.byModality?.output, tokens.byModality?.output)) /
|
|
35
|
+
PER;
|
|
36
|
+
return { usd, estimated: true };
|
|
37
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
3
|
+
import type { JsonObject, JsonValue } from '../json.js';
|
|
4
|
+
import type { ReasoningOrigin, ToolCallRequest } from '../turn-events.js';
|
|
5
|
+
import type { DecisionRequest, DecisionResult, EmbeddingInput, EmbeddingResult, EmbeddingTask, InteractionPart, ModelRequest, TurnContext, TurnEvent, TurnHistoryMessage, TurnResponse, TurnStop } from '../types.js';
|
|
6
|
+
import type { ProviderLimits } from './limits.js';
|
|
7
|
+
/** The kinds of profile a protocol can serve, each at its own endpoint: every type but `host`. */
|
|
8
|
+
declare const MODEL_PROFILE_TYPES: readonly ["text", "image", "speech", "live", "decision", "embedding"];
|
|
9
|
+
export type ModelProfileType = (typeof MODEL_PROFILE_TYPES)[number];
|
|
10
|
+
/** The turn events a protocol yields as they are. */
|
|
11
|
+
export type ProtocolContentEvent = Extract<TurnEvent, {
|
|
12
|
+
type: 'text' | 'thought' | 'structured' | 'media' | 'grounding' | 'citation' | 'evidence' | 'tokens' | 'session' | 'tool_draft' | 'error';
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* What a protocol streams back: the model's events, reasoning it must get back word for word,
|
|
16
|
+
* content with no common shape, and (opted in) the wire rows themselves. A protocol writes
|
|
17
|
+
* `custom.kind` in its own terms; the kernel sets reasoning's origin and mints call ids.
|
|
18
|
+
*/
|
|
19
|
+
export type ProtocolEvent<S = unknown> = ProtocolContentEvent | {
|
|
20
|
+
type: 'tool_call';
|
|
21
|
+
call: ToolCallRequest & {
|
|
22
|
+
wireCallId?: string;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
type: 'tool_cancel';
|
|
26
|
+
callId: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'response';
|
|
29
|
+
response: TurnResponse;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'done';
|
|
32
|
+
stop: TurnStop;
|
|
33
|
+
interrupted?: boolean;
|
|
34
|
+
state?: S;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'reasoning';
|
|
37
|
+
text?: string;
|
|
38
|
+
data: JsonValue;
|
|
39
|
+
origin?: ReasoningOrigin;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'custom';
|
|
42
|
+
kind: string;
|
|
43
|
+
data: JsonObject;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'raw';
|
|
46
|
+
row: JsonObject;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* One turn as a protocol gets it: the kernel's request without what only the kernel uses (the
|
|
50
|
+
* checkpoint, the upstream tap), and the protocol's own saved state, if it is reused.
|
|
51
|
+
*/
|
|
52
|
+
export type ProtocolRequest<S = unknown> = Omit<ModelRequest, 'providerState' | 'tapUpstream'> & {
|
|
53
|
+
state?: S;
|
|
54
|
+
/** How much of `history` the reused state already holds. */
|
|
55
|
+
stateHistoryLength?: number;
|
|
56
|
+
};
|
|
57
|
+
export type DecisionCall = Pick<DecisionRequest, 'state' | 'questions' | 'assets'> & {
|
|
58
|
+
apiId: string;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
};
|
|
61
|
+
/** One embedding request after profile resolution, before provider serialization. */
|
|
62
|
+
export type EmbeddingCall = {
|
|
63
|
+
apiId: string;
|
|
64
|
+
input: EmbeddingInput | readonly EmbeddingInput[];
|
|
65
|
+
task?: EmbeddingTask;
|
|
66
|
+
options?: JsonObject;
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
};
|
|
69
|
+
export type { EmbeddingResult };
|
|
70
|
+
/** A tool's result, sent back into a live session. */
|
|
71
|
+
export interface LiveToolResult {
|
|
72
|
+
callId: string;
|
|
73
|
+
name: string;
|
|
74
|
+
text: string;
|
|
75
|
+
parts?: InteractionPart[];
|
|
76
|
+
}
|
|
77
|
+
/** A live session, as a protocol hands it back. */
|
|
78
|
+
export interface ProtocolSession<S = unknown> {
|
|
79
|
+
closeInfo?(): {
|
|
80
|
+
code: number;
|
|
81
|
+
reason: string;
|
|
82
|
+
error?: Error;
|
|
83
|
+
warning?: {
|
|
84
|
+
timeLeftMs?: number;
|
|
85
|
+
closedAfterMs: number;
|
|
86
|
+
};
|
|
87
|
+
} | undefined;
|
|
88
|
+
events(): AsyncIterable<ProtocolEvent<S>>;
|
|
89
|
+
sendText(text: string): Promise<void>;
|
|
90
|
+
sendAudio(media: {
|
|
91
|
+
data: string;
|
|
92
|
+
mimeType: string;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
sendVideo(media: {
|
|
95
|
+
data: string;
|
|
96
|
+
mimeType: string;
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
sendContext(context: TurnContext): Promise<void>;
|
|
99
|
+
sendToolResult(result: LiveToolResult): Promise<void>;
|
|
100
|
+
close(reason?: string): Promise<void>;
|
|
101
|
+
}
|
|
102
|
+
/** One open WebSocket: frames out and in are JSON objects. */
|
|
103
|
+
export interface ProtocolSocket {
|
|
104
|
+
/** `input` is what the frame gives the model to read, for the trace; setup and control frames give none. */
|
|
105
|
+
send(frame: JsonObject, input?: readonly TurnHistoryMessage[]): void;
|
|
106
|
+
frames(): AsyncIterable<JsonObject>;
|
|
107
|
+
close(code?: number, reason?: string): void;
|
|
108
|
+
}
|
|
109
|
+
export interface SendInit {
|
|
110
|
+
stream: boolean;
|
|
111
|
+
/** In place of the profile type's endpoint, for a call the shape makes elsewhere. */
|
|
112
|
+
path?: string;
|
|
113
|
+
headers?: Record<string, string>;
|
|
114
|
+
/** The builtin ids this request wrote. Any other id the request asked for is refused. */
|
|
115
|
+
wroteTools?: readonly string[];
|
|
116
|
+
}
|
|
117
|
+
/** What the kernel hands a protocol for one call. It never holds a key, a slot, or a base URL. */
|
|
118
|
+
export interface ProtocolContext<O = unknown> {
|
|
119
|
+
profileType: ModelProfileType;
|
|
120
|
+
apiId: string;
|
|
121
|
+
options: O;
|
|
122
|
+
/** The binding's `builtInTools`, for the protocol to write. */
|
|
123
|
+
builtInTools: readonly string[];
|
|
124
|
+
limits: ProviderLimits;
|
|
125
|
+
signal?: AbortSignal;
|
|
126
|
+
/** Posts to this profile type's endpoint on the provider and yields the reply's rows. */
|
|
127
|
+
send(body: JsonObject, init: SendInit): AsyncIterable<JsonObject>;
|
|
128
|
+
/** Opens this profile type's WebSocket on the provider and sends `setup` as the first frame. */
|
|
129
|
+
connect(setup: JsonObject, init?: {
|
|
130
|
+
wroteTools?: readonly string[];
|
|
131
|
+
}): Promise<ProtocolSocket>;
|
|
132
|
+
tapUpstream(row: JsonObject): void;
|
|
133
|
+
}
|
|
134
|
+
export interface ProtocolOperations<S = unknown> {
|
|
135
|
+
complete?(request: ProtocolRequest<S>): AsyncIterable<ProtocolEvent<S>>;
|
|
136
|
+
openSession?(request: ProtocolRequest<S>): Promise<ProtocolSession<S>>;
|
|
137
|
+
decide?(request: DecisionCall): Promise<DecisionResult>;
|
|
138
|
+
embed?(request: EmbeddingCall): Promise<EmbeddingResult>;
|
|
139
|
+
}
|
|
140
|
+
/** An upstream answer that was not a success, for the protocol to type. */
|
|
141
|
+
export interface UpstreamFailure {
|
|
142
|
+
status: number;
|
|
143
|
+
body: JsonValue;
|
|
144
|
+
headers: Headers;
|
|
145
|
+
}
|
|
146
|
+
export interface Continuation<S> {
|
|
147
|
+
version: number;
|
|
148
|
+
schema: z.ZodType<S>;
|
|
149
|
+
/** Options that change what saved state means; a checkpoint is reused only when they match. */
|
|
150
|
+
keyOptions?: readonly string[];
|
|
151
|
+
}
|
|
152
|
+
/** One kind of media an embedding model takes: its MIME types, and how many one input may hold when the provider caps it. */
|
|
153
|
+
export interface EmbeddingMediaKind {
|
|
154
|
+
accept: readonly string[];
|
|
155
|
+
maxPerInput?: number;
|
|
156
|
+
}
|
|
157
|
+
/** What one embedding model takes, as its provider documents it. */
|
|
158
|
+
export interface EmbeddingModelLimits {
|
|
159
|
+
/** Inputs one request may carry, when the provider caps them. */
|
|
160
|
+
maxInputs?: number;
|
|
161
|
+
/** The media it embeds; empty for a model that embeds text only. */
|
|
162
|
+
media: readonly EmbeddingMediaKind[];
|
|
163
|
+
}
|
|
164
|
+
export interface ProtocolDefinition<O = unknown, S = unknown> {
|
|
165
|
+
/** What bindings write, e.g. `'openAi'`. */
|
|
166
|
+
id: string;
|
|
167
|
+
/** What people read, e.g. `'OpenAI Chat Completions'`. */
|
|
168
|
+
name: string;
|
|
169
|
+
/** One sentence, for the studio and docs. */
|
|
170
|
+
description: string;
|
|
171
|
+
/** The path each profile type uses. A type with no entry is not served. */
|
|
172
|
+
endpoints: Partial<Record<ModelProfileType, string>>;
|
|
173
|
+
/** Every field a binding may set, each described. */
|
|
174
|
+
options: z.ZodType<O>;
|
|
175
|
+
continuation?: Continuation<S>;
|
|
176
|
+
/** The `data` of the reasoning parts it writes. */
|
|
177
|
+
reasoning?: z.ZodType<JsonValue>;
|
|
178
|
+
/** Content it emits that has no common shape, by kind. */
|
|
179
|
+
custom?: Readonly<Record<string, z.ZodType<JsonObject>>>;
|
|
180
|
+
/**
|
|
181
|
+
* Turns the reply's framing into rows. Absent: SSE for a stream, one JSON row otherwise, and a
|
|
182
|
+
* body that is not JSON as one `{ eventType: 'http_body', mime_type, data }` row, base64.
|
|
183
|
+
*/
|
|
184
|
+
framing?(response: Response, stream: boolean): AsyncIterable<JsonObject>;
|
|
185
|
+
/** Types a failed answer. Absent: the kind follows the HTTP status. */
|
|
186
|
+
error?(failure: UpstreamFailure): TheoremError;
|
|
187
|
+
/** What the named embedding model takes. Absent: the kernel holds requests to the profile alone. */
|
|
188
|
+
embeddingLimits?(apiId: string): EmbeddingModelLimits;
|
|
189
|
+
/** The options the named model refuses, though the protocol takes them for others. Absent: none. */
|
|
190
|
+
refusedOptions?(apiId: string): readonly string[];
|
|
191
|
+
create(context: ProtocolContext<O>): ProtocolOperations<S>;
|
|
192
|
+
}
|
|
193
|
+
/** A defined protocol. `lineage` is its id, then its base's, back to the first. */
|
|
194
|
+
export interface Protocol<O = unknown, S = unknown> extends Readonly<Omit<ProtocolDefinition<O, S>, 'create'>> {
|
|
195
|
+
readonly base?: Protocol;
|
|
196
|
+
readonly lineage: readonly string[];
|
|
197
|
+
create(context: ProtocolContext<O>): ProtocolOperations<S>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* `options` as model `apiId` takes them on `protocol`: the protocol's schema, less any option that
|
|
201
|
+
* model refuses. Throws a `config` error naming what does not fit.
|
|
202
|
+
*/
|
|
203
|
+
export declare function modelOptions<O>(protocol: Pick<Protocol<O>, 'id' | 'options' | 'refusedOptions'>, apiId: string, options: unknown): O;
|
|
204
|
+
/** Defines a protocol: the code that speaks one API shape, and everything on its wire. */
|
|
205
|
+
export declare function defineProtocol<O, S = unknown>(definition: ProtocolDefinition<O, S>): Protocol<O, S>;
|
|
206
|
+
/** What an extension's `body` sees. */
|
|
207
|
+
export interface ExtensionBodyAt<E> {
|
|
208
|
+
profileType: ModelProfileType;
|
|
209
|
+
apiId: string;
|
|
210
|
+
options: E;
|
|
211
|
+
/** The binding's built-in tool ids. */
|
|
212
|
+
builtInTools: readonly string[];
|
|
213
|
+
/** The request's headers, to add to. */
|
|
214
|
+
headers: Headers;
|
|
215
|
+
/** The turn being sent; absent for a decision and a live session's later frames. */
|
|
216
|
+
request?: ProtocolRequest<unknown>;
|
|
217
|
+
}
|
|
218
|
+
/** What an extension's reader keeps for one call: it sees each reply row before the base. */
|
|
219
|
+
export interface ExtensionReader<S = unknown> {
|
|
220
|
+
row(row: JsonObject): {
|
|
221
|
+
events?: ProtocolEvent<S>[];
|
|
222
|
+
consumed?: boolean;
|
|
223
|
+
};
|
|
224
|
+
finish?(): {
|
|
225
|
+
events?: ProtocolEvent<S>[];
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export interface ProtocolExtension<E = unknown, S = unknown> extends Pick<ProtocolDefinition<E, S>, 'id' | 'name' | 'description' | 'reasoning' | 'custom' | 'framing' | 'error' | 'embeddingLimits' | 'refusedOptions'> {
|
|
229
|
+
/** What it adds to the base's options. A field the base already has is refused. */
|
|
230
|
+
options?: z.ZodObject & z.ZodType<E>;
|
|
231
|
+
/** Its own paths, where they differ from the base's. */
|
|
232
|
+
endpoints?: Partial<Record<ModelProfileType, string>>;
|
|
233
|
+
/** What it adds to the base's request (or a WebSocket's first frame), and the tools it wrote. */
|
|
234
|
+
body?(body: JsonObject, at: ExtensionBodyAt<E>): {
|
|
235
|
+
body: JsonObject;
|
|
236
|
+
wroteTools?: readonly string[];
|
|
237
|
+
};
|
|
238
|
+
/** One per call: reads each reply row before the base. */
|
|
239
|
+
read?(at: {
|
|
240
|
+
profileType: ModelProfileType;
|
|
241
|
+
apiId: string;
|
|
242
|
+
options: E;
|
|
243
|
+
request?: ProtocolRequest<unknown>;
|
|
244
|
+
}): ExtensionReader<S>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A new protocol built on a base it nearly matches. It has its own id, so what it sends has one
|
|
248
|
+
* answer: its definition. Its options are the base's plus its own; its endpoints, framing, and error
|
|
249
|
+
* typing are the base's unless it gives its own.
|
|
250
|
+
*/
|
|
251
|
+
export declare function extendProtocol<O, S, E = JsonObject>(base: Protocol<O, S>, extension: ProtocolExtension<E, S>): Protocol<O & E, S>;
|
|
252
|
+
/** Whether something `writer` wrote may go back to `target`: the writer is in its lineage. */
|
|
253
|
+
export declare function carriesTo(writer: string, target: Pick<Protocol, 'lineage'>): boolean;
|