@theoremjs/agents 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +545 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +79 -0
- package/esm/mod.js +49 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +480 -0
- 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 +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +241 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +26 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +67 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +5 -0
- package/esm/src/evals/attachments.js +55 -0
- package/esm/src/evals/breakdown.d.ts +30 -0
- package/esm/src/evals/breakdown.js +69 -0
- package/esm/src/evals/graders/answer.d.ts +16 -0
- package/esm/src/evals/graders/answer.js +134 -0
- package/esm/src/evals/graders/code.d.ts +40 -0
- package/esm/src/evals/graders/code.js +184 -0
- package/esm/src/evals/graders/judge.d.ts +24 -0
- package/esm/src/evals/graders/judge.js +367 -0
- package/esm/src/evals/graders/latency.d.ts +6 -0
- package/esm/src/evals/graders/latency.js +82 -0
- package/esm/src/evals/graders/live.d.ts +14 -0
- package/esm/src/evals/graders/live.js +42 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +91 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +19 -0
- package/esm/src/evals/graders/transcript.js +202 -0
- package/esm/src/evals/mod.d.ts +34 -0
- package/esm/src/evals/mod.js +22 -0
- package/esm/src/evals/record.d.ts +41 -0
- package/esm/src/evals/record.js +107 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +75 -0
- package/esm/src/evals/run.js +418 -0
- package/esm/src/evals/suite.d.ts +28 -0
- package/esm/src/evals/suite.js +97 -0
- package/esm/src/evals/summary.d.ts +35 -0
- package/esm/src/evals/summary.js +31 -0
- package/esm/src/evals/trial.d.ts +14 -0
- package/esm/src/evals/trial.js +135 -0
- package/esm/src/evals/types.d.ts +169 -0
- package/esm/src/evals/types.js +113 -0
- package/esm/src/evals/verdict.d.ts +23 -0
- package/esm/src/evals/verdict.js +48 -0
- 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 +22 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +146 -0
- package/esm/src/guardrails/canary.js +974 -0
- package/esm/src/guardrails/compile-egress.d.ts +12 -0
- package/esm/src/guardrails/compile-egress.js +12 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +24 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +305 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +199 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +5 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +120 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +15 -0
- package/esm/src/guardrails/corpus/live-attacks.js +229 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +36 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- 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 +12 -0
- package/esm/src/guardrails/egress-automata.js +25582 -0
- package/esm/src/guardrails/egress-compiler.d.ts +55 -0
- package/esm/src/guardrails/egress-compiler.js +431 -0
- package/esm/src/guardrails/egress-patterns.d.ts +26 -0
- package/esm/src/guardrails/egress-patterns.js +36 -0
- package/esm/src/guardrails/egress-stream.d.ts +123 -0
- package/esm/src/guardrails/egress-stream.js +774 -0
- package/esm/src/guardrails/egress-urls.d.ts +86 -0
- package/esm/src/guardrails/egress-urls.js +909 -0
- package/esm/src/guardrails/egress.d.ts +46 -0
- package/esm/src/guardrails/egress.js +124 -0
- package/esm/src/guardrails/error.d.ts +31 -0
- package/esm/src/guardrails/error.js +96 -0
- package/esm/src/guardrails/event-schemas.d.ts +100 -0
- package/esm/src/guardrails/event-schemas.js +48 -0
- package/esm/src/guardrails/events.d.ts +13 -0
- package/esm/src/guardrails/events.js +45 -0
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +14 -0
- package/esm/src/guardrails/hits.js +30 -0
- 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 +20 -0
- package/esm/src/guardrails/injection-patterns.js +126 -0
- 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 +30 -0
- package/esm/src/guardrails/injection.js +460 -0
- 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 +55 -0
- package/esm/src/guardrails/live-outbound-gate.js +298 -0
- package/esm/src/guardrails/mod.d.ts +54 -0
- package/esm/src/guardrails/mod.js +34 -0
- package/esm/src/guardrails/network.d.ts +46 -0
- package/esm/src/guardrails/network.js +330 -0
- package/esm/src/guardrails/normalize.d.ts +20 -0
- package/esm/src/guardrails/normalize.js +165 -0
- package/esm/src/guardrails/policy.d.ts +4 -0
- package/esm/src/guardrails/policy.js +21 -0
- package/esm/src/guardrails/progressive-yield.d.ts +110 -0
- package/esm/src/guardrails/progressive-yield.js +281 -0
- package/esm/src/guardrails/prompt-echo.d.ts +40 -0
- package/esm/src/guardrails/prompt-echo.js +306 -0
- package/esm/src/guardrails/quota.d.ts +21 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +47 -0
- package/esm/src/guardrails/rules.js +47 -0
- package/esm/src/guardrails/sanitize.d.ts +40 -0
- package/esm/src/guardrails/sanitize.js +160 -0
- 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 +22 -0
- package/esm/src/guardrails/sensitive.js +234 -0
- package/esm/src/guardrails/serialize.d.ts +15 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +11 -0
- package/esm/src/guardrails/testing.js +10 -0
- package/esm/src/guardrails/theorem-error.d.ts +21 -0
- package/esm/src/guardrails/theorem-error.js +54 -0
- package/esm/src/guardrails/thought-guard.d.ts +76 -0
- package/esm/src/guardrails/thought-guard.js +664 -0
- package/esm/src/guardrails/tool-directives.d.ts +38 -0
- package/esm/src/guardrails/tool-directives.js +195 -0
- 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 +92 -0
- package/esm/src/guardrails/tool-result.js +272 -0
- package/esm/src/guardrails/types.d.ts +250 -0
- package/esm/src/guardrails/types.js +58 -0
- package/esm/src/host/client-turn.d.ts +36 -0
- package/esm/src/host/client-turn.js +80 -0
- package/esm/src/host/mint-trace.d.ts +29 -0
- package/esm/src/host/mint-trace.js +60 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +27 -0
- package/esm/src/host/reply.d.ts +13 -0
- package/esm/src/host/reply.js +41 -0
- package/esm/src/interface/blocks.d.ts +11 -0
- package/esm/src/interface/blocks.js +283 -0
- package/esm/src/interface/composer-actions.d.ts +24 -0
- package/esm/src/interface/composer-actions.js +33 -0
- package/esm/src/interface/draft.d.ts +20 -0
- package/esm/src/interface/draft.js +39 -0
- package/esm/src/interface/from-profile.d.ts +24 -0
- package/esm/src/interface/from-profile.js +179 -0
- package/esm/src/interface/history.d.ts +46 -0
- package/esm/src/interface/history.js +278 -0
- package/esm/src/interface/inputs.d.ts +11 -0
- package/esm/src/interface/inputs.js +67 -0
- package/esm/src/interface/mod.d.ts +33 -0
- package/esm/src/interface/mod.js +22 -0
- package/esm/src/interface/models.d.ts +26 -0
- package/esm/src/interface/models.js +50 -0
- package/esm/src/interface/pending.d.ts +57 -0
- package/esm/src/interface/pending.js +152 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +237 -0
- package/esm/src/interface/session.d.ts +71 -0
- package/esm/src/interface/session.js +128 -0
- 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 +32 -0
- package/esm/src/interface/tool-calls.js +127 -0
- package/esm/src/interface/tool-invoke.d.ts +6 -0
- package/esm/src/interface/tool-invoke.js +22 -0
- package/esm/src/interface/tool-media.d.ts +11 -0
- package/esm/src/interface/tool-media.js +113 -0
- package/esm/src/interface/types.d.ts +278 -0
- package/esm/src/interface/types.js +5 -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/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +56 -0
- package/esm/src/kernel/auth/crypto.js +163 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +18 -0
- package/esm/src/kernel/auth/oauth.js +439 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +152 -0
- package/esm/src/kernel/auth/types.js +1 -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 +72 -0
- package/esm/src/kernel/default-scope.js +121 -0
- 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 +71 -0
- package/esm/src/kernel/engine/compaction.js +203 -0
- package/esm/src/kernel/engine/decision.d.ts +43 -0
- package/esm/src/kernel/engine/decision.js +439 -0
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +19 -0
- package/esm/src/kernel/engine/live-inbound.js +44 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +15 -0
- package/esm/src/kernel/engine/live-ingress.js +42 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +508 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +29 -0
- package/esm/src/kernel/engine/runner/mod.js +625 -0
- 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 +35 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +179 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +41 -0
- package/esm/src/kernel/engine/runner/state.d.ts +97 -0
- package/esm/src/kernel/engine/runner/state.js +50 -0
- 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 +14 -0
- package/esm/src/kernel/engine/runner/steps.js +519 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +71 -0
- package/esm/src/kernel/engine/runner/stream.js +376 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +148 -0
- package/esm/src/kernel/engine/session/mod.d.ts +33 -0
- package/esm/src/kernel/engine/session/mod.js +1182 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +500 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +23 -0
- package/esm/src/kernel/engine/token-estimate.js +38 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +132 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +119 -0
- package/esm/src/kernel/engine/turn-trace.js +855 -0
- package/esm/src/kernel/engine/usage.d.ts +36 -0
- package/esm/src/kernel/engine/usage.js +151 -0
- package/esm/src/kernel/interaction-parts.d.ts +13 -0
- package/esm/src/kernel/interaction-parts.js +40 -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 +74 -0
- package/esm/src/kernel/mod.js +45 -0
- package/esm/src/kernel/profile-graph.d.ts +145 -0
- package/esm/src/kernel/profile-graph.js +158 -0
- package/esm/src/kernel/profile-presence.d.ts +18 -0
- package/esm/src/kernel/profile-presence.js +158 -0
- package/esm/src/kernel/profile-scope.d.ts +40 -0
- package/esm/src/kernel/profile-scope.js +274 -0
- 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 +46 -0
- package/esm/src/kernel/registry/attachments.js +220 -0
- package/esm/src/kernel/registry/catalog.d.ts +25 -0
- package/esm/src/kernel/registry/catalog.js +85 -0
- 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 +12 -0
- package/esm/src/kernel/registry/ingress.js +179 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +15 -0
- package/esm/src/kernel/registry/kernel-registry.js +15 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +10 -0
- package/esm/src/kernel/registry/profiles.d.ts +116 -0
- package/esm/src/kernel/registry/profiles.js +773 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +34 -0
- package/esm/src/kernel/registry/resolve.d.ts +17 -0
- package/esm/src/kernel/registry/resolve.js +238 -0
- package/esm/src/kernel/registry/schemas.d.ts +12 -0
- package/esm/src/kernel/registry/schemas.js +27 -0
- 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/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +32 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +14 -0
- package/esm/src/kernel/registry/vault.js +1 -0
- package/esm/src/kernel/schema.d.ts +226 -0
- package/esm/src/kernel/schema.js +895 -0
- package/esm/src/kernel/scope.d.ts +29 -0
- package/esm/src/kernel/scope.js +45 -0
- package/esm/src/kernel/stages.d.ts +176 -0
- package/esm/src/kernel/stages.js +431 -0
- package/esm/src/kernel/stop.d.ts +116 -0
- package/esm/src/kernel/stop.js +137 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +22 -0
- package/esm/src/kernel/tools/activity-label.js +435 -0
- 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 +66 -0
- package/esm/src/kernel/tools/events.js +184 -0
- package/esm/src/kernel/tools/execute.d.ts +100 -0
- package/esm/src/kernel/tools/execute.js +1173 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +60 -0
- package/esm/src/kernel/tools/gate-answer.js +65 -0
- 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 +17 -0
- package/esm/src/kernel/tools/harness.js +43 -0
- 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 +32 -0
- package/esm/src/kernel/tools/invoke.js +282 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +23 -0
- package/esm/src/kernel/tools/mcp-sessions.js +69 -0
- package/esm/src/kernel/tools/mod.d.ts +10 -0
- package/esm/src/kernel/tools/mod.js +7 -0
- package/esm/src/kernel/tools/model-text.d.ts +16 -0
- package/esm/src/kernel/tools/model-text.js +31 -0
- 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 +15 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +11 -0
- package/esm/src/kernel/tools/project.js +55 -0
- package/esm/src/kernel/tools/registry.d.ts +27 -0
- package/esm/src/kernel/tools/registry.js +143 -0
- package/esm/src/kernel/tools/remote.d.ts +144 -0
- package/esm/src/kernel/tools/remote.js +1125 -0
- package/esm/src/kernel/tools/resolve.d.ts +31 -0
- package/esm/src/kernel/tools/resolve.js +267 -0
- 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 +10 -0
- package/esm/src/kernel/tools/schema.js +95 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +19 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +116 -0
- package/esm/src/kernel/tools/stage-run.js +198 -0
- package/esm/src/kernel/tools/types.d.ts +497 -0
- package/esm/src/kernel/tools/types.js +1 -0
- 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 +776 -0
- package/esm/src/kernel/turn-events.js +543 -0
- package/esm/src/kernel/types.d.ts +1025 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +4 -0
- package/esm/src/kernel/util/base64.js +15 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +2 -0
- package/esm/src/kernel/util/record.js +4 -0
- package/esm/src/observability/destinations.d.ts +14 -0
- package/esm/src/observability/destinations.js +43 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +110 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +71 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +30 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +17 -0
- package/esm/src/observability/policy.js +73 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +64 -0
- package/esm/src/observability/spans.d.ts +22 -0
- package/esm/src/observability/spans.js +72 -0
- package/esm/src/observability/trace-catalog.d.ts +128 -0
- package/esm/src/observability/trace-catalog.js +906 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +228 -0
- package/esm/src/observability/trace-schema.d.ts +57 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +14 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +98 -0
- package/esm/src/observability/trace-span.js +201 -0
- package/esm/src/observability/trace.d.ts +13 -0
- package/esm/src/observability/trace.js +37 -0
- package/esm/src/observability/types.d.ts +109 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +9 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +13 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +119 -0
- package/esm/src/presets/google.js +197 -0
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +11 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +26 -0
- package/esm/src/presets/openrouter.js +31 -0
- 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/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -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 +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +27 -0
- package/esm/src/providers/google/interactions/framing.js +304 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +23 -0
- package/esm/src/providers/google/interactions/stream.js +230 -0
- package/esm/src/providers/google/live/framing.d.ts +61 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/stream.d.ts +13 -0
- package/esm/src/providers/google/live/stream.js +57 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +4 -0
- package/esm/src/providers/google/urls.js +4 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- 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 +32 -0
- package/esm/src/providers/mod.js +23 -0
- 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 +15 -0
- package/esm/src/providers/openrouter/image.js +34 -0
- 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 +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/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.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- 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 +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- 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 +6 -0
- package/esm/src/providers/shared/sse.js +93 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +24 -0
- package/esm/src/providers/shared/tool-args.js +88 -0
- 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 +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +51 -0
- package/esm/src/providers/types.js +2 -0
- 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 +46 -0
- package/esm/src/surface/formats.js +178 -0
- package/esm/src/surface/mod.d.ts +16 -0
- package/esm/src/surface/mod.js +12 -0
- package/esm/src/surface/runtime.d.ts +44 -0
- package/esm/src/surface/runtime.js +441 -0
- package/esm/src/surface/tools.d.ts +9 -0
- package/esm/src/surface/tools.js +62 -0
- package/esm/src/surface/types.d.ts +110 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +100 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Provider } from '../../kernel/protocols/provider.js';
|
|
2
|
+
/** What registering `openRouterProvider` takes as `connection`. */
|
|
3
|
+
export interface OpenRouterConnection {
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
decisionUrl?: string;
|
|
6
|
+
siteUrl?: string;
|
|
7
|
+
siteName?: string;
|
|
8
|
+
}
|
|
9
|
+
/** OpenRouter: many labs' models behind one key. Chat, speech, images, and decisions. */
|
|
10
|
+
export declare const openRouterProvider: Provider<OpenRouterConnection, string>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { bearer, defineProvider, endpointUrlSchema, } from '../../kernel/protocols/provider.js';
|
|
3
|
+
import { systemOne } from '../system-one/protocol.js';
|
|
4
|
+
import { openRouterEmbedding } from './embedding-protocol.js';
|
|
5
|
+
import { openRouterImages } from './images-protocol.js';
|
|
6
|
+
import { openRouter } from './protocol.js';
|
|
7
|
+
const connection = z.strictObject({
|
|
8
|
+
baseUrl: endpointUrlSchema
|
|
9
|
+
.optional()
|
|
10
|
+
.describe('The API, by default https://openrouter.ai/api/v1.'), // labels-exempt: builder field description, read by the studio and docs
|
|
11
|
+
decisionUrl: endpointUrlSchema
|
|
12
|
+
.optional()
|
|
13
|
+
.describe('The decision API, by default https://openrouter.ai/api/alpha/decisions.'), // labels-exempt: builder field description, read by the studio and docs
|
|
14
|
+
siteUrl: z
|
|
15
|
+
.string()
|
|
16
|
+
.trim()
|
|
17
|
+
.min(1)
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('Sent as HTTP-Referer, for OpenRouter rankings.'), // labels-exempt: builder field description, read by the studio and docs
|
|
20
|
+
siteName: z
|
|
21
|
+
.string()
|
|
22
|
+
.trim()
|
|
23
|
+
.min(1)
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Sent as X-Title, for OpenRouter rankings.'), // labels-exempt: builder field description, read by the studio and docs
|
|
26
|
+
});
|
|
27
|
+
/** OpenRouter: many labs' models behind one key. Chat, speech, images, and decisions. */
|
|
28
|
+
export const openRouterProvider = defineProvider({
|
|
29
|
+
id: 'openrouter',
|
|
30
|
+
name: 'OpenRouter',
|
|
31
|
+
description: "Many labs' models behind one key.", // labels-exempt: builder field description, read by the studio and docs
|
|
32
|
+
connection: connection.default({}),
|
|
33
|
+
key: z.string().trim().min(1),
|
|
34
|
+
authorize: bearer(),
|
|
35
|
+
serves(at) {
|
|
36
|
+
const baseUrl = at.baseUrl ?? 'https://openrouter.ai/api/v1';
|
|
37
|
+
const headers = {};
|
|
38
|
+
if (at.siteUrl)
|
|
39
|
+
headers['HTTP-Referer'] = at.siteUrl;
|
|
40
|
+
if (at.siteName)
|
|
41
|
+
headers['X-Title'] = at.siteName;
|
|
42
|
+
const decisionUrl = at.decisionUrl ?? 'https://openrouter.ai/api/alpha/decisions';
|
|
43
|
+
return [
|
|
44
|
+
{ protocol: openRouter, baseUrl, headers },
|
|
45
|
+
{ protocol: openRouterEmbedding, baseUrl, headers },
|
|
46
|
+
{ protocol: openRouterImages, baseUrl, headers },
|
|
47
|
+
{ protocol: systemOne, baseUrl: decisionUrl, url: () => decisionUrl, headers },
|
|
48
|
+
];
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { InteractionPart, TurnHistoryMessage } from '../../kernel/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* History for a wire whose tool result holds only the `holds` part types. Every
|
|
4
|
+
* other file leaves a marker in its place and follows the run of tool results in
|
|
5
|
+
* one user message, so the results of a parallel call stay together.
|
|
6
|
+
*/
|
|
7
|
+
export declare function withCarriedToolFiles(messages: readonly TurnHistoryMessage[], holds: ReadonlySet<InteractionPart['type']>): TurnHistoryMessage[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** What stands in a tool result where a file it cannot hold was. */
|
|
2
|
+
function carriedFileMarker(part) {
|
|
3
|
+
return { type: 'text', text: `[${part.type}: sent in the next message]` };
|
|
4
|
+
}
|
|
5
|
+
/** What leads the files of one tool result in the user message that carries them. */
|
|
6
|
+
function carriedFilesLead(msg) {
|
|
7
|
+
const from = msg.name ? `the ${msg.name} result` : 'a tool result';
|
|
8
|
+
return { type: 'text', text: `Files from ${from}:` };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* History for a wire whose tool result holds only the `holds` part types. Every
|
|
12
|
+
* other file leaves a marker in its place and follows the run of tool results in
|
|
13
|
+
* one user message, so the results of a parallel call stay together.
|
|
14
|
+
*/
|
|
15
|
+
export function withCarriedToolFiles(messages, holds) {
|
|
16
|
+
const out = [];
|
|
17
|
+
let carried = [];
|
|
18
|
+
const flush = () => {
|
|
19
|
+
if (carried.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
out.push({ role: 'user', parts: carried });
|
|
22
|
+
carried = [];
|
|
23
|
+
};
|
|
24
|
+
for (const msg of messages) {
|
|
25
|
+
if (msg.role !== 'tool') {
|
|
26
|
+
flush();
|
|
27
|
+
out.push(msg);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const files = (msg.parts ?? []).filter((part) => !holds.has(part.type));
|
|
31
|
+
if (files.length === 0) {
|
|
32
|
+
out.push(msg);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
out.push({
|
|
36
|
+
...msg,
|
|
37
|
+
parts: (msg.parts ?? []).map((part) => holds.has(part.type) ? part : carriedFileMarker(part)),
|
|
38
|
+
});
|
|
39
|
+
carried.push(carriedFilesLead(msg), ...files);
|
|
40
|
+
}
|
|
41
|
+
flush();
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PcmFormat {
|
|
2
|
+
sampleRate: number;
|
|
3
|
+
channels: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function writeAscii(view: DataView, offset: number, str: string): void;
|
|
6
|
+
export declare function pcmFormatFromMime(mime: string): PcmFormat | undefined;
|
|
7
|
+
export declare function wrapPcmAsWav(pcm: Uint8Array, format: PcmFormat): Uint8Array;
|
|
8
|
+
export declare function pcmMediaAsWav(media: {
|
|
9
|
+
mimeType: string;
|
|
10
|
+
data: string;
|
|
11
|
+
}): {
|
|
12
|
+
mimeType: string;
|
|
13
|
+
data: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*probed 2026-09-23:
|
|
2
|
+
* Each transport states the PCM format on the wire (probes 23/09/2026):
|
|
3
|
+
* - Gemini Live: `audio/pcm;rate=24000`
|
|
4
|
+
* - Interactions: `audio/l16; rate=24000; channels=1` (buffered), or
|
|
5
|
+
* `audio/l16` with `sample_rate` / `channels` fields (stream deltas)
|
|
6
|
+
* - OpenRouter speech: `content-type: audio/pcm;rate=24000;channels=1`
|
|
7
|
+
*
|
|
8
|
+
* Samples are 16-bit little-endian on all three (measured), although RFC 2586
|
|
9
|
+
* defines `audio/L16` as big-endian. A mime without `rate=` has no known
|
|
10
|
+
* format, so its bytes pass through unchanged rather than being wrapped at a
|
|
11
|
+
* guessed rate. `channels=` absent means one channel (the RFC 2586 default;
|
|
12
|
+
* Live documents mono output).
|
|
13
|
+
*/
|
|
14
|
+
import { base64ToBytes, bytesToBase64 } from '../../kernel/util/base64.js';
|
|
15
|
+
const BITS_PER_SAMPLE = 16;
|
|
16
|
+
const RAW_PCM_ESSENCES = new Set(['audio/pcm', 'audio/l16']);
|
|
17
|
+
export function writeAscii(view, offset, str) {
|
|
18
|
+
for (let i = 0; i < str.length; i++)
|
|
19
|
+
view.setUint8(offset + i, str.charCodeAt(i));
|
|
20
|
+
}
|
|
21
|
+
function positiveInt(value) {
|
|
22
|
+
if (value === undefined || !/^\d+$/.test(value))
|
|
23
|
+
return undefined;
|
|
24
|
+
const n = Number(value);
|
|
25
|
+
return n > 0 ? n : undefined;
|
|
26
|
+
}
|
|
27
|
+
function parseMime(mime) {
|
|
28
|
+
const [essence = '', ...rest] = mime.split(';');
|
|
29
|
+
const params = new Map();
|
|
30
|
+
for (const param of rest) {
|
|
31
|
+
const eq = param.indexOf('=');
|
|
32
|
+
if (eq > 0)
|
|
33
|
+
params.set(param.slice(0, eq).trim().toLowerCase(), param.slice(eq + 1).trim());
|
|
34
|
+
}
|
|
35
|
+
return { essence: essence.trim().toLowerCase(), params };
|
|
36
|
+
}
|
|
37
|
+
export function pcmFormatFromMime(mime) {
|
|
38
|
+
const { essence, params } = parseMime(mime);
|
|
39
|
+
if (!RAW_PCM_ESSENCES.has(essence))
|
|
40
|
+
return undefined;
|
|
41
|
+
const sampleRate = positiveInt(params.get('rate'));
|
|
42
|
+
if (sampleRate === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
const channels = params.has('channels') ? positiveInt(params.get('channels')) : 1;
|
|
45
|
+
if (channels === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
return { sampleRate, channels };
|
|
48
|
+
}
|
|
49
|
+
export function wrapPcmAsWav(pcm, format) {
|
|
50
|
+
const { sampleRate, channels } = format;
|
|
51
|
+
const blockAlign = (channels * BITS_PER_SAMPLE) / 8;
|
|
52
|
+
const byteRate = sampleRate * blockAlign;
|
|
53
|
+
const dataSize = pcm.length;
|
|
54
|
+
const buf = new ArrayBuffer(44 + dataSize);
|
|
55
|
+
const view = new DataView(buf);
|
|
56
|
+
writeAscii(view, 0, 'RIFF');
|
|
57
|
+
view.setUint32(4, 36 + dataSize, true);
|
|
58
|
+
writeAscii(view, 8, 'WAVE');
|
|
59
|
+
writeAscii(view, 12, 'fmt ');
|
|
60
|
+
view.setUint32(16, 16, true);
|
|
61
|
+
view.setUint16(20, 1, true);
|
|
62
|
+
view.setUint16(22, channels, true);
|
|
63
|
+
view.setUint32(24, sampleRate, true);
|
|
64
|
+
view.setUint32(28, byteRate, true);
|
|
65
|
+
view.setUint16(32, blockAlign, true);
|
|
66
|
+
view.setUint16(34, BITS_PER_SAMPLE, true);
|
|
67
|
+
writeAscii(view, 36, 'data');
|
|
68
|
+
view.setUint32(40, dataSize, true);
|
|
69
|
+
new Uint8Array(buf, 44).set(pcm);
|
|
70
|
+
return new Uint8Array(buf);
|
|
71
|
+
}
|
|
72
|
+
export function pcmMediaAsWav(media) {
|
|
73
|
+
const format = pcmFormatFromMime(media.mimeType);
|
|
74
|
+
if (!format)
|
|
75
|
+
return media;
|
|
76
|
+
const wav = wrapPcmAsWav(base64ToBytes(media.data), format);
|
|
77
|
+
return { mimeType: 'audio/wav', data: bytesToBase64(wav) };
|
|
78
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProtocolEvent } from '../../kernel/protocols/mod.js';
|
|
2
|
+
import type { ModelEvent } from '../../kernel/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* One event from the shared Gemini and Chat Completions readers, as a protocol event: a finished
|
|
5
|
+
* call is a `tool_call`, a cancelled one a `tool_cancel`, and a broken one an error. A `done` keeps
|
|
6
|
+
* only its stop; the protocol adds its own state.
|
|
7
|
+
*/
|
|
8
|
+
export declare function asProtocolEvent<S>(event: ModelEvent): ProtocolEvent<S> | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One event from the shared Gemini and Chat Completions readers, as a protocol event: a finished
|
|
3
|
+
* call is a `tool_call`, a cancelled one a `tool_cancel`, and a broken one an error. A `done` keeps
|
|
4
|
+
* only its stop; the protocol adds its own state.
|
|
5
|
+
*/
|
|
6
|
+
export function asProtocolEvent(event) {
|
|
7
|
+
if (event.type === 'done')
|
|
8
|
+
return {
|
|
9
|
+
type: 'done',
|
|
10
|
+
stop: event.stop,
|
|
11
|
+
...(event.interrupted === undefined ? {} : { interrupted: event.interrupted }),
|
|
12
|
+
};
|
|
13
|
+
if (event.type !== 'tool')
|
|
14
|
+
return event;
|
|
15
|
+
if (event.tool.phase === undefined)
|
|
16
|
+
return { type: 'tool_call', call: event.tool };
|
|
17
|
+
if (event.tool.phase === 'cancel')
|
|
18
|
+
return { type: 'tool_cancel', callId: event.tool.callId };
|
|
19
|
+
return event.tool.phase === 'error' ? { type: 'error', errorKind: 'bad_response' } : undefined;
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModelEvent, TurnResponse } from '../../kernel/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Emits as soon as the wire names the response and again whenever that changes, so a
|
|
4
|
+
* call that fails or is cut by a guardrail still records which model served it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function foldResponse(known: TurnResponse | undefined, seen: TurnResponse | undefined): {
|
|
7
|
+
known: TurnResponse | undefined;
|
|
8
|
+
event?: Extract<ModelEvent, {
|
|
9
|
+
type: 'response';
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emits as soon as the wire names the response and again whenever that changes, so a
|
|
3
|
+
* call that fails or is cut by a guardrail still records which model served it.
|
|
4
|
+
*/
|
|
5
|
+
export function foldResponse(known, seen) {
|
|
6
|
+
if (!seen)
|
|
7
|
+
return { known };
|
|
8
|
+
const next = { ...known, ...seen };
|
|
9
|
+
if (next.id === known?.id && next.model === known?.model)
|
|
10
|
+
return { known };
|
|
11
|
+
return { known: next, event: { type: 'response', response: next } };
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** How a retry waits; a host or test may pass its own. The signal ends the wait early. */
|
|
2
|
+
export type Wait = (ms: number, signal?: AbortSignal | null) => Promise<void>;
|
|
3
|
+
/** All the waiting one call may do between tries; a wait that would pass it sends the last answer back. */
|
|
4
|
+
export declare const WAIT_BUDGET_MS = 5000;
|
|
5
|
+
export declare const waitDefault: Wait;
|
|
6
|
+
export declare function isTransientHttp(status: number): boolean;
|
|
7
|
+
export declare function isTransientThrown(err: unknown): boolean;
|
|
8
|
+
export declare function backoffMs(attempt: number): number;
|
|
9
|
+
/** `retry-after-ms`, else `Retry-After` in seconds or as a date; undefined when absent or unreadable. */
|
|
10
|
+
export declare function retryAfterMs(headers: Headers, now?: number): number | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Retries a transient status (408, 429, 5xx gateway) or a network failure while the waits stay
|
|
13
|
+
* within five seconds in all, at most four times. Each wait is the response's `Retry-After` when it gives one, else
|
|
14
|
+
* 1s, 2s, 4s then 8s; a wait that would pass the five seconds, or the call's own time left, is not
|
|
15
|
+
* taken, and the last answer or error goes back as it came. An abort ends the wait.
|
|
16
|
+
*/
|
|
17
|
+
export declare function retryTransient(send: typeof fetch, wait?: Wait, timeLeft?: () => number): typeof fetch;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { isAbortError, isTimeoutError } from '../../guardrails/error.js';
|
|
2
|
+
const BACKOFF_MS = [1000, 2000, 4000, 8000];
|
|
3
|
+
/** All the waiting one call may do between tries; a wait that would pass it sends the last answer back. */
|
|
4
|
+
export const WAIT_BUDGET_MS = 5000;
|
|
5
|
+
/** The most tries after the first: a `Retry-After: 0` costs no wait, so the budget alone never ends it. */
|
|
6
|
+
const MAX_RETRIES = BACKOFF_MS.length;
|
|
7
|
+
const MS_PER_SECOND = 1000;
|
|
8
|
+
const TRANSIENT_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
|
|
9
|
+
const TRANSIENT_THROWN_RE = /name resolution|dns|econnreset|econnrefused|etimedout|connection (?:refused|reset)|error sending request|network|fetch failed|temporarily unavailable|socket|503|502|504/i;
|
|
10
|
+
export const waitDefault = (ms, signal) => new Promise((resolve, reject) => {
|
|
11
|
+
if (signal?.aborted) {
|
|
12
|
+
reject(abortReason(signal));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const timer = setTimeout(() => {
|
|
16
|
+
signal?.removeEventListener('abort', onAbort);
|
|
17
|
+
resolve();
|
|
18
|
+
}, ms);
|
|
19
|
+
function onAbort() {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
reject(abortReason(signal));
|
|
22
|
+
}
|
|
23
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
24
|
+
});
|
|
25
|
+
function abortReason(signal) {
|
|
26
|
+
return signal.reason ?? new DOMException('The operation was aborted.', 'AbortError');
|
|
27
|
+
}
|
|
28
|
+
export function isTransientHttp(status) {
|
|
29
|
+
return TRANSIENT_STATUSES.has(status);
|
|
30
|
+
}
|
|
31
|
+
export function isTransientThrown(err) {
|
|
32
|
+
if (isAbortError(err) || isTimeoutError(err)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return TRANSIENT_THROWN_RE.test(String(err));
|
|
36
|
+
}
|
|
37
|
+
export function backoffMs(attempt) {
|
|
38
|
+
return BACKOFF_MS[Math.min(attempt, BACKOFF_MS.length - 1)];
|
|
39
|
+
}
|
|
40
|
+
/** `retry-after-ms`, else `Retry-After` in seconds or as a date; undefined when absent or unreadable. */
|
|
41
|
+
export function retryAfterMs(headers, now = Date.now()) {
|
|
42
|
+
const ms = headers.get('retry-after-ms');
|
|
43
|
+
const after = headers.get('retry-after');
|
|
44
|
+
let delay;
|
|
45
|
+
if (ms !== null && ms.trim() !== '' && Number.isFinite(Number(ms))) {
|
|
46
|
+
delay = Number(ms);
|
|
47
|
+
}
|
|
48
|
+
else if (after !== null && after.trim() !== '') {
|
|
49
|
+
const seconds = Number(after);
|
|
50
|
+
delay = Number.isFinite(seconds) ? seconds * MS_PER_SECOND : Date.parse(after) - now;
|
|
51
|
+
}
|
|
52
|
+
if (delay === undefined || Number.isNaN(delay) || delay < 0) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return delay;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Retries a transient status (408, 429, 5xx gateway) or a network failure while the waits stay
|
|
59
|
+
* within five seconds in all, at most four times. Each wait is the response's `Retry-After` when it gives one, else
|
|
60
|
+
* 1s, 2s, 4s then 8s; a wait that would pass the five seconds, or the call's own time left, is not
|
|
61
|
+
* taken, and the last answer or error goes back as it came. An abort ends the wait.
|
|
62
|
+
*/
|
|
63
|
+
export function retryTransient(send, wait = waitDefault, timeLeft = () => Number.POSITIVE_INFINITY) {
|
|
64
|
+
return async (url, init) => {
|
|
65
|
+
let waited = 0;
|
|
66
|
+
for (let attempt = 0;; attempt++) {
|
|
67
|
+
const left = Math.min(WAIT_BUDGET_MS - waited, timeLeft());
|
|
68
|
+
let delay;
|
|
69
|
+
try {
|
|
70
|
+
const res = await send(url, init);
|
|
71
|
+
if (!isTransientHttp(res.status)) {
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
delay = retryAfterMs(res.headers) ?? backoffMs(attempt);
|
|
75
|
+
if (delay > left || attempt >= MAX_RETRIES) {
|
|
76
|
+
return res;
|
|
77
|
+
}
|
|
78
|
+
await res.body?.cancel();
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
delay = backoffMs(attempt);
|
|
82
|
+
if (!isTransientThrown(err) || delay > left || attempt >= MAX_RETRIES) {
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
await wait(delay, init?.signal);
|
|
87
|
+
waited += delay;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function takeSsePayloads(buffer: string, pendingEvent?: string): {
|
|
2
|
+
rest: string;
|
|
3
|
+
payloads: Record<string, unknown>[];
|
|
4
|
+
pendingEvent: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function readSseChunks(body: ReadableStream<Uint8Array>): AsyncGenerator<Record<string, unknown>>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const DONE = '[DONE]';
|
|
2
|
+
function asObject(parsed) {
|
|
3
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
4
|
+
return parsed;
|
|
5
|
+
}
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
function dataRecord(raw, sseEvent) {
|
|
9
|
+
const data = raw.startsWith('data:') ? raw.slice(5).replace(/^ /, '') : raw;
|
|
10
|
+
const row = {};
|
|
11
|
+
if (sseEvent) {
|
|
12
|
+
row.sseEvent = sseEvent;
|
|
13
|
+
}
|
|
14
|
+
if (data === DONE) {
|
|
15
|
+
row.eventType = 'sse_done';
|
|
16
|
+
return row;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(data);
|
|
20
|
+
const obj = asObject(parsed);
|
|
21
|
+
if (obj) {
|
|
22
|
+
return { ...obj, ...row };
|
|
23
|
+
}
|
|
24
|
+
row.eventType = 'sse_unparsed';
|
|
25
|
+
row.data = parsed;
|
|
26
|
+
return row;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
row.eventType = 'sse_unparsed';
|
|
30
|
+
row.data = data;
|
|
31
|
+
return row;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function takeSsePayloads(buffer, pendingEvent = '') {
|
|
35
|
+
const payloads = [];
|
|
36
|
+
let event = pendingEvent;
|
|
37
|
+
let data = [];
|
|
38
|
+
let hasData = false;
|
|
39
|
+
let consumed = 0;
|
|
40
|
+
const lineEnds = /\r\n|\r|\n/g;
|
|
41
|
+
let start = 0;
|
|
42
|
+
for (let match = lineEnds.exec(buffer); match; match = lineEnds.exec(buffer)) {
|
|
43
|
+
if (match[0] === '\r' && match.index === buffer.length - 1)
|
|
44
|
+
break;
|
|
45
|
+
const line = buffer.slice(start, match.index);
|
|
46
|
+
start = match.index + match[0].length;
|
|
47
|
+
if (!line) {
|
|
48
|
+
if (hasData)
|
|
49
|
+
payloads.push(dataRecord(data.join('\n'), event));
|
|
50
|
+
event = '';
|
|
51
|
+
data = [];
|
|
52
|
+
hasData = false;
|
|
53
|
+
consumed = start;
|
|
54
|
+
}
|
|
55
|
+
else if (!line.startsWith(':')) {
|
|
56
|
+
const colon = line.indexOf(':');
|
|
57
|
+
const field = colon < 0 ? line : line.slice(0, colon);
|
|
58
|
+
const value = colon < 0 ? '' : line.slice(colon + 1).replace(/^ /, '');
|
|
59
|
+
if (field === 'event')
|
|
60
|
+
event = value;
|
|
61
|
+
if (field === 'data') {
|
|
62
|
+
data.push(value);
|
|
63
|
+
hasData = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { rest: buffer.slice(consumed), payloads, pendingEvent: '' };
|
|
68
|
+
}
|
|
69
|
+
export async function* readSseChunks(body) {
|
|
70
|
+
const reader = body.getReader();
|
|
71
|
+
const decoder = new TextDecoder();
|
|
72
|
+
let buffer = '';
|
|
73
|
+
let ended = false;
|
|
74
|
+
try {
|
|
75
|
+
for (;;) {
|
|
76
|
+
const { done, value } = await reader.read();
|
|
77
|
+
if (done) {
|
|
78
|
+
ended = true;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
buffer += decoder.decode(value, { stream: true });
|
|
82
|
+
const result = takeSsePayloads(buffer);
|
|
83
|
+
buffer = result.rest;
|
|
84
|
+
for (const payload of result.payloads)
|
|
85
|
+
yield payload;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
if (!ended)
|
|
90
|
+
void reader.cancel().catch(() => undefined);
|
|
91
|
+
reader.releaseLock();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TheoremError, toErrorEvent } from '../../guardrails/error.js';
|
|
2
|
+
/** Invalid JSON is a `bad_response` error, never a silent skip. */
|
|
3
|
+
function structuredEvent(text) {
|
|
4
|
+
try {
|
|
5
|
+
return { type: 'structured', structured: JSON.parse(text) };
|
|
6
|
+
}
|
|
7
|
+
catch (cause) {
|
|
8
|
+
return toErrorEvent(new TheoremError('bad_response', 'structured output was not valid JSON', { cause }));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export { structuredEvent };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ToolCallBase } from '../../kernel/tools/events.js';
|
|
2
|
+
import type { ToolCallRequest } from '../../kernel/tools/types.js';
|
|
3
|
+
import type { ModelEvent } from '../../kernel/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Adapters never invent a history call id or name: a provider that needs a
|
|
6
|
+
* missing one rejects the request, and that error is the answer.
|
|
7
|
+
*/
|
|
8
|
+
export declare function historyToolIdentity(fields: Record<string, string | undefined>): Record<string, string>;
|
|
9
|
+
export type ParsedToolArguments = {
|
|
10
|
+
ok: true;
|
|
11
|
+
value: Record<string, unknown>;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
error: string;
|
|
15
|
+
raw: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function parseToolArgumentsObject(raw: unknown): ParsedToolArguments;
|
|
18
|
+
export declare function historyToolArguments(raw: unknown): Record<string, unknown>;
|
|
19
|
+
/** A call sent without an id gets one, so its request and failure events join. */
|
|
20
|
+
export declare function toolCallEvents(call: Pick<ToolCallRequest, 'name' | 'stepId' | 'stepCallCount'> & {
|
|
21
|
+
id?: string;
|
|
22
|
+
}, rawArguments: unknown): ModelEvent[];
|
|
23
|
+
/** The model still reads the failed call's result back. */
|
|
24
|
+
export declare function malformedToolCall(base: ToolCallBase, message: string, raw: unknown, request?: Pick<ToolCallRequest, 'stepId' | 'stepCallCount'>): ModelEvent[];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
2
|
+
import { failureEvent, newCallId, toolCallRequestEvent, } from '../../kernel/tools/events.js';
|
|
3
|
+
import { isRecord } from '../../kernel/util/record.js';
|
|
4
|
+
/**
|
|
5
|
+
* Adapters never invent a history call id or name: a provider that needs a
|
|
6
|
+
* missing one rejects the request, and that error is the answer.
|
|
7
|
+
*/
|
|
8
|
+
export function historyToolIdentity(fields) {
|
|
9
|
+
const present = {};
|
|
10
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
11
|
+
if (value !== undefined)
|
|
12
|
+
present[key] = value;
|
|
13
|
+
}
|
|
14
|
+
return present;
|
|
15
|
+
}
|
|
16
|
+
export function parseToolArgumentsObject(raw) {
|
|
17
|
+
if (typeof raw === 'string') {
|
|
18
|
+
const trimmed = raw.trim();
|
|
19
|
+
if (trimmed.length === 0) {
|
|
20
|
+
return { ok: true, value: {} };
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(trimmed);
|
|
24
|
+
if (isRecord(parsed)) {
|
|
25
|
+
return { ok: true, value: parsed };
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
error: 'tool arguments JSON must be an object',
|
|
30
|
+
raw,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: 'malformed tool arguments JSON',
|
|
37
|
+
raw,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (isRecord(raw)) {
|
|
42
|
+
return { ok: true, value: raw };
|
|
43
|
+
}
|
|
44
|
+
if (raw === undefined || raw === null) {
|
|
45
|
+
return { ok: true, value: {} };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
ok: false,
|
|
49
|
+
error: 'tool arguments must be a JSON object',
|
|
50
|
+
raw: String(raw),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function historyToolArguments(raw) {
|
|
54
|
+
const parsed = parseToolArgumentsObject(raw);
|
|
55
|
+
if (!parsed.ok) {
|
|
56
|
+
throw new TheoremError('bad_response', parsed.error);
|
|
57
|
+
}
|
|
58
|
+
return parsed.value;
|
|
59
|
+
}
|
|
60
|
+
/** A call sent without an id gets one, so its request and failure events join. */
|
|
61
|
+
export function toolCallEvents(call, rawArguments) {
|
|
62
|
+
const name = call.name.trim();
|
|
63
|
+
const base = { name, callId: call.id ?? newCallId(name) };
|
|
64
|
+
const request = {
|
|
65
|
+
stepId: call.stepId,
|
|
66
|
+
stepCallCount: call.stepCallCount,
|
|
67
|
+
};
|
|
68
|
+
if (!name) {
|
|
69
|
+
return malformedToolCall(base, 'function call is missing a name', rawArguments, request);
|
|
70
|
+
}
|
|
71
|
+
const parsed = parseToolArgumentsObject(rawArguments);
|
|
72
|
+
if (!parsed.ok) {
|
|
73
|
+
return malformedToolCall(base, parsed.error, parsed.raw, request);
|
|
74
|
+
}
|
|
75
|
+
return [toolCallRequestEvent(base, parsed.value, request)];
|
|
76
|
+
}
|
|
77
|
+
/** The model still reads the failed call's result back. */
|
|
78
|
+
export function malformedToolCall(base, message, raw, request = {}) {
|
|
79
|
+
return [
|
|
80
|
+
toolCallRequestEvent(base, {}, request),
|
|
81
|
+
failureEvent(base, {
|
|
82
|
+
code: 'malformed_arguments',
|
|
83
|
+
kind: 'bad_response',
|
|
84
|
+
message,
|
|
85
|
+
details: { raw },
|
|
86
|
+
}),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ModelEvent } from '../../kernel/types.js';
|
|
2
|
+
/** A tool call a provider is streaming: its id and name as far as they have come, and its arguments' text. */
|
|
3
|
+
export interface StreamingToolCall {
|
|
4
|
+
id?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
args: string;
|
|
7
|
+
/** How much of `args` has gone out as `tool_draft` events. */
|
|
8
|
+
drafted?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The `tool_draft` event for what `call.args` has gained since it last drafted, and advances
|
|
12
|
+
* `call.drafted`. Nothing until the call has an id and a name: the call is emitted under that id,
|
|
13
|
+
* and its draft is joined to it by that id alone. Whatever came before then goes out in the first
|
|
14
|
+
* draft.
|
|
15
|
+
*/
|
|
16
|
+
export declare function toolDraftEvents(call: StreamingToolCall): ModelEvent[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `tool_draft` event for what `call.args` has gained since it last drafted, and advances
|
|
3
|
+
* `call.drafted`. Nothing until the call has an id and a name: the call is emitted under that id,
|
|
4
|
+
* and its draft is joined to it by that id alone. Whatever came before then goes out in the first
|
|
5
|
+
* draft.
|
|
6
|
+
*/
|
|
7
|
+
export function toolDraftEvents(call) {
|
|
8
|
+
const name = call.name.trim();
|
|
9
|
+
const from = call.drafted ?? 0;
|
|
10
|
+
if (!(call.id && name) || call.args.length <= from)
|
|
11
|
+
return [];
|
|
12
|
+
call.drafted = call.args.length;
|
|
13
|
+
return [{ type: 'tool_draft', callId: call.id, name, text: call.args.slice(from) }];
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { KeySlot, ModelRequest } from '../../kernel/types.js';
|
|
2
|
+
export declare function tapeHeaderValue(key: string, value: string): string;
|
|
3
|
+
export declare function tapeHeaders(headers?: HeadersInit): Record<string, string>;
|
|
4
|
+
export declare function throwRow(err: unknown): Record<string, unknown>;
|
|
5
|
+
export declare function tapFetch(tap: ModelRequest['tapUpstream'], send?: typeof fetch, keySlot?: KeySlot): typeof fetch;
|
|
6
|
+
/** fetch rejects only when no response came back, so any non-abort, non-timeout rejection is `network`. */
|
|
7
|
+
export declare function networkError(err: unknown): unknown;
|
|
8
|
+
export declare function networkFetch(send?: typeof fetch): typeof fetch;
|