@theoremjs/agents 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1264 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +65 -0
- package/esm/mod.js +42 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +458 -0
- package/esm/src/cli/commands/egress-compile.d.ts +17 -0
- package/esm/src/cli/commands/egress-compile.js +25 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +202 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +25 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +72 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +4 -0
- package/esm/src/evals/attachments.js +53 -0
- package/esm/src/evals/breakdown.d.ts +28 -0
- package/esm/src/evals/breakdown.js +68 -0
- package/esm/src/evals/graders/answer.d.ts +13 -0
- package/esm/src/evals/graders/answer.js +133 -0
- package/esm/src/evals/graders/code.d.ts +64 -0
- package/esm/src/evals/graders/code.js +205 -0
- package/esm/src/evals/graders/judge.d.ts +20 -0
- package/esm/src/evals/graders/judge.js +365 -0
- package/esm/src/evals/graders/latency.d.ts +5 -0
- package/esm/src/evals/graders/latency.js +81 -0
- package/esm/src/evals/graders/live.d.ts +11 -0
- package/esm/src/evals/graders/live.js +40 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +92 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +17 -0
- package/esm/src/evals/graders/transcript.js +200 -0
- package/esm/src/evals/mod.d.ts +42 -0
- package/esm/src/evals/mod.js +30 -0
- package/esm/src/evals/record.d.ts +35 -0
- package/esm/src/evals/record.js +105 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +118 -0
- package/esm/src/evals/run.js +452 -0
- package/esm/src/evals/suite.d.ts +19 -0
- package/esm/src/evals/suite.js +92 -0
- package/esm/src/evals/summary.d.ts +32 -0
- package/esm/src/evals/summary.js +30 -0
- package/esm/src/evals/trial.d.ts +27 -0
- package/esm/src/evals/trial.js +158 -0
- package/esm/src/evals/types.d.ts +260 -0
- package/esm/src/evals/types.js +126 -0
- package/esm/src/evals/verdict.d.ts +18 -0
- package/esm/src/evals/verdict.js +45 -0
- package/esm/src/guardrails/canary-gate.d.ts +21 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +112 -0
- package/esm/src/guardrails/canary.js +901 -0
- package/esm/src/guardrails/compile-egress.d.ts +11 -0
- package/esm/src/guardrails/compile-egress.js +11 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +22 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +303 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +202 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +3 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +118 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +13 -0
- package/esm/src/guardrails/corpus/live-attacks.js +224 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +32 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/egress-automata.d.ts +14 -0
- package/esm/src/guardrails/egress-automata.js +6059 -0
- package/esm/src/guardrails/egress-compiler.d.ts +33 -0
- package/esm/src/guardrails/egress-compiler.js +237 -0
- package/esm/src/guardrails/egress-patterns.d.ts +24 -0
- package/esm/src/guardrails/egress-patterns.js +32 -0
- package/esm/src/guardrails/egress-policy.d.ts +27 -0
- package/esm/src/guardrails/egress-policy.js +76 -0
- package/esm/src/guardrails/egress-rules.d.ts +54 -0
- package/esm/src/guardrails/egress-rules.js +49 -0
- package/esm/src/guardrails/egress-stream.d.ts +105 -0
- package/esm/src/guardrails/egress-stream.js +645 -0
- package/esm/src/guardrails/egress-urls.d.ts +83 -0
- package/esm/src/guardrails/egress-urls.js +917 -0
- package/esm/src/guardrails/egress.d.ts +106 -0
- package/esm/src/guardrails/egress.js +374 -0
- package/esm/src/guardrails/error.d.ts +26 -0
- package/esm/src/guardrails/error.js +91 -0
- package/esm/src/guardrails/event-schemas.d.ts +57 -0
- package/esm/src/guardrails/event-schemas.js +41 -0
- package/esm/src/guardrails/events.d.ts +9 -0
- package/esm/src/guardrails/events.js +42 -0
- package/esm/src/guardrails/hits.d.ts +8 -0
- package/esm/src/guardrails/hits.js +19 -0
- package/esm/src/guardrails/injection-patterns.d.ts +15 -0
- package/esm/src/guardrails/injection-patterns.js +94 -0
- package/esm/src/guardrails/injection.d.ts +14 -0
- package/esm/src/guardrails/injection.js +237 -0
- package/esm/src/guardrails/lexicon.d.ts +30 -0
- package/esm/src/guardrails/lexicon.js +478 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +54 -0
- package/esm/src/guardrails/live-outbound-gate.js +305 -0
- package/esm/src/guardrails/mod.d.ts +46 -0
- package/esm/src/guardrails/mod.js +29 -0
- package/esm/src/guardrails/network.d.ts +42 -0
- package/esm/src/guardrails/network.js +328 -0
- package/esm/src/guardrails/normalize.d.ts +6 -0
- package/esm/src/guardrails/normalize.js +132 -0
- package/esm/src/guardrails/policy.d.ts +19 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +69 -0
- package/esm/src/guardrails/progressive-yield.js +237 -0
- package/esm/src/guardrails/prompt-echo.d.ts +38 -0
- package/esm/src/guardrails/prompt-echo.js +225 -0
- package/esm/src/guardrails/quota.d.ts +20 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +56 -0
- package/esm/src/guardrails/rules.js +54 -0
- package/esm/src/guardrails/sanitize.d.ts +23 -0
- package/esm/src/guardrails/sanitize.js +184 -0
- package/esm/src/guardrails/sensitive.d.ts +29 -0
- package/esm/src/guardrails/sensitive.js +113 -0
- package/esm/src/guardrails/serialize.d.ts +14 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +9 -0
- package/esm/src/guardrails/testing.js +8 -0
- package/esm/src/guardrails/theorem-error.d.ts +18 -0
- package/esm/src/guardrails/theorem-error.js +53 -0
- package/esm/src/guardrails/thought-guard.d.ts +55 -0
- package/esm/src/guardrails/thought-guard.js +464 -0
- package/esm/src/guardrails/tool-directives.d.ts +19 -0
- package/esm/src/guardrails/tool-directives.js +109 -0
- package/esm/src/guardrails/tool-result.d.ts +61 -0
- package/esm/src/guardrails/tool-result.js +248 -0
- package/esm/src/guardrails/types.d.ts +242 -0
- package/esm/src/guardrails/types.js +54 -0
- package/esm/src/host/client-turn.d.ts +9 -0
- package/esm/src/host/client-turn.js +38 -0
- package/esm/src/host/mint-trace.d.ts +28 -0
- package/esm/src/host/mint-trace.js +59 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +68 -0
- package/esm/src/host/reply.d.ts +7 -0
- package/esm/src/host/reply.js +35 -0
- package/esm/src/interface/blocks.d.ts +8 -0
- package/esm/src/interface/blocks.js +213 -0
- package/esm/src/interface/composer-actions.d.ts +20 -0
- package/esm/src/interface/composer-actions.js +31 -0
- package/esm/src/interface/draft.d.ts +14 -0
- package/esm/src/interface/draft.js +28 -0
- package/esm/src/interface/from-profile.d.ts +12 -0
- package/esm/src/interface/from-profile.js +144 -0
- package/esm/src/interface/history.d.ts +40 -0
- package/esm/src/interface/history.js +269 -0
- package/esm/src/interface/inputs.d.ts +10 -0
- package/esm/src/interface/inputs.js +64 -0
- package/esm/src/interface/mod.d.ts +31 -0
- package/esm/src/interface/mod.js +21 -0
- package/esm/src/interface/models.d.ts +19 -0
- package/esm/src/interface/models.js +45 -0
- package/esm/src/interface/pending.d.ts +48 -0
- package/esm/src/interface/pending.js +146 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +223 -0
- package/esm/src/interface/session.d.ts +64 -0
- package/esm/src/interface/session.js +121 -0
- package/esm/src/interface/tool-calls.d.ts +20 -0
- package/esm/src/interface/tool-calls.js +73 -0
- package/esm/src/interface/tool-invoke.d.ts +4 -0
- package/esm/src/interface/tool-invoke.js +20 -0
- package/esm/src/interface/tool-media.d.ts +9 -0
- package/esm/src/interface/tool-media.js +112 -0
- package/esm/src/interface/types.d.ts +213 -0
- package/esm/src/interface/types.js +4 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +51 -0
- package/esm/src/kernel/auth/crypto.js +161 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +17 -0
- package/esm/src/kernel/auth/oauth.js +438 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +139 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/default-scope.d.ts +34 -0
- package/esm/src/kernel/default-scope.js +72 -0
- package/esm/src/kernel/engine/compaction.d.ts +70 -0
- package/esm/src/kernel/engine/compaction.js +202 -0
- package/esm/src/kernel/engine/decision.d.ts +41 -0
- package/esm/src/kernel/engine/decision.js +412 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +19 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +9 -0
- package/esm/src/kernel/engine/live-ingress.js +37 -0
- package/esm/src/kernel/engine/media-probe/audio.d.ts +7 -0
- package/esm/src/kernel/engine/media-probe/audio.js +342 -0
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +6 -0
- package/esm/src/kernel/engine/media-probe/bytes.js +26 -0
- package/esm/src/kernel/engine/media-probe/image.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/image.js +171 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +19 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +48 -0
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +35 -0
- package/esm/src/kernel/engine/media-probe/matroska.js +226 -0
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +22 -0
- package/esm/src/kernel/engine/media-probe/mp4.js +279 -0
- package/esm/src/kernel/engine/media-probe/opus.d.ts +4 -0
- package/esm/src/kernel/engine/media-probe/opus.js +23 -0
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/pdf.js +117 -0
- package/esm/src/kernel/engine/media-probe/video.d.ts +15 -0
- package/esm/src/kernel/engine/media-probe/video.js +49 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +322 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +15 -0
- package/esm/src/kernel/engine/runner/mod.js +574 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +14 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +105 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +48 -0
- package/esm/src/kernel/engine/runner/state.d.ts +76 -0
- package/esm/src/kernel/engine/runner/state.js +40 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +360 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +40 -0
- package/esm/src/kernel/engine/runner/stream.js +225 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +150 -0
- package/esm/src/kernel/engine/session/mod.d.ts +31 -0
- package/esm/src/kernel/engine/session/mod.js +951 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +489 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +77 -0
- package/esm/src/kernel/engine/token-estimate.js +218 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +131 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +118 -0
- package/esm/src/kernel/engine/turn-trace.js +863 -0
- package/esm/src/kernel/engine/usage.d.ts +30 -0
- package/esm/src/kernel/engine/usage.js +134 -0
- package/esm/src/kernel/interaction-parts.d.ts +10 -0
- package/esm/src/kernel/interaction-parts.js +22 -0
- package/esm/src/kernel/mod.d.ts +47 -0
- package/esm/src/kernel/mod.js +30 -0
- package/esm/src/kernel/profile-graph.d.ts +140 -0
- package/esm/src/kernel/profile-graph.js +151 -0
- package/esm/src/kernel/profile-presence.d.ts +9 -0
- package/esm/src/kernel/profile-presence.js +143 -0
- package/esm/src/kernel/profile-scope.d.ts +36 -0
- package/esm/src/kernel/profile-scope.js +262 -0
- package/esm/src/kernel/registry/attachments.d.ts +35 -0
- package/esm/src/kernel/registry/attachments.js +211 -0
- package/esm/src/kernel/registry/catalog.d.ts +19 -0
- package/esm/src/kernel/registry/catalog.js +78 -0
- package/esm/src/kernel/registry/ingress.d.ts +8 -0
- package/esm/src/kernel/registry/ingress.js +134 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +12 -0
- package/esm/src/kernel/registry/kernel-registry.js +8 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +7 -0
- package/esm/src/kernel/registry/profiles.d.ts +92 -0
- package/esm/src/kernel/registry/profiles.js +698 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +42 -0
- package/esm/src/kernel/registry/resolve.d.ts +14 -0
- package/esm/src/kernel/registry/resolve.js +237 -0
- package/esm/src/kernel/registry/schemas.d.ts +9 -0
- package/esm/src/kernel/registry/schemas.js +25 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +33 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +13 -0
- package/esm/src/kernel/registry/vault.js +14 -0
- package/esm/src/kernel/schema.d.ts +172 -0
- package/esm/src/kernel/schema.js +653 -0
- package/esm/src/kernel/scope.d.ts +22 -0
- package/esm/src/kernel/scope.js +25 -0
- package/esm/src/kernel/stages.d.ts +141 -0
- package/esm/src/kernel/stages.js +388 -0
- package/esm/src/kernel/stop.d.ts +93 -0
- package/esm/src/kernel/stop.js +125 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +16 -0
- package/esm/src/kernel/tools/activity-label.js +209 -0
- package/esm/src/kernel/tools/events.d.ts +51 -0
- package/esm/src/kernel/tools/events.js +149 -0
- package/esm/src/kernel/tools/execute.d.ts +64 -0
- package/esm/src/kernel/tools/execute.js +801 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +50 -0
- package/esm/src/kernel/tools/gate-answer.js +54 -0
- package/esm/src/kernel/tools/harness.d.ts +16 -0
- package/esm/src/kernel/tools/harness.js +42 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +129 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +20 -0
- package/esm/src/kernel/tools/mcp-sessions.js +64 -0
- package/esm/src/kernel/tools/mod.d.ts +9 -0
- package/esm/src/kernel/tools/mod.js +6 -0
- package/esm/src/kernel/tools/model-text.d.ts +11 -0
- package/esm/src/kernel/tools/model-text.js +25 -0
- package/esm/src/kernel/tools/permission.d.ts +6 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +8 -0
- package/esm/src/kernel/tools/project.js +25 -0
- package/esm/src/kernel/tools/registry.d.ts +20 -0
- package/esm/src/kernel/tools/registry.js +84 -0
- package/esm/src/kernel/tools/remote.d.ts +110 -0
- package/esm/src/kernel/tools/remote.js +998 -0
- package/esm/src/kernel/tools/resolve.d.ts +28 -0
- package/esm/src/kernel/tools/resolve.js +259 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +174 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +18 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +93 -0
- package/esm/src/kernel/tools/stage-run.js +140 -0
- package/esm/src/kernel/tools/types.d.ts +287 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/turn-events.d.ts +599 -0
- package/esm/src/kernel/turn-events.js +425 -0
- package/esm/src/kernel/types.d.ts +884 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +13 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +3 -0
- package/esm/src/observability/destinations.d.ts +9 -0
- package/esm/src/observability/destinations.js +38 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +117 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +68 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +29 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +14 -0
- package/esm/src/observability/policy.js +69 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +58 -0
- package/esm/src/observability/spans.d.ts +16 -0
- package/esm/src/observability/spans.js +56 -0
- package/esm/src/observability/trace-catalog.d.ts +111 -0
- package/esm/src/observability/trace-catalog.js +865 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +223 -0
- package/esm/src/observability/trace-schema.d.ts +54 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +13 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +92 -0
- package/esm/src/observability/trace-span.js +199 -0
- package/esm/src/observability/trace.d.ts +11 -0
- package/esm/src/observability/trace.js +35 -0
- package/esm/src/observability/types.d.ts +85 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +8 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +12 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +104 -0
- package/esm/src/presets/google.js +188 -0
- package/esm/src/presets/mod.d.ts +10 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +13 -0
- package/esm/src/presets/openrouter.js +13 -0
- package/esm/src/presets/typesafe.d.ts +2 -0
- package/esm/src/presets/typesafe.js +2 -0
- package/esm/src/providers/create-provider.d.ts +21 -0
- package/esm/src/providers/create-provider.js +90 -0
- package/esm/src/providers/decision/usage.d.ts +3 -0
- package/esm/src/providers/decision/usage.js +25 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +263 -0
- package/esm/src/providers/google/interactions/mod.d.ts +2 -0
- package/esm/src/providers/google/interactions/mod.js +2 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +24 -0
- package/esm/src/providers/google/interactions/stream.js +297 -0
- package/esm/src/providers/google/keys.d.ts +20 -0
- package/esm/src/providers/google/keys.js +87 -0
- package/esm/src/providers/google/live/framing.d.ts +51 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/mod.d.ts +7 -0
- package/esm/src/providers/google/live/mod.js +7 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +1 -0
- package/esm/src/providers/google/live/openapi-schema.js +42 -0
- package/esm/src/providers/google/live/session.d.ts +14 -0
- package/esm/src/providers/google/live/session.js +150 -0
- package/esm/src/providers/google/live/stream.d.ts +51 -0
- package/esm/src/providers/google/live/stream.js +263 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/local/local.d.ts +12 -0
- package/esm/src/providers/local/local.js +186 -0
- package/esm/src/providers/local/mod.d.ts +8 -0
- package/esm/src/providers/local/mod.js +8 -0
- package/esm/src/providers/mod.d.ts +11 -0
- package/esm/src/providers/mod.js +7 -0
- package/esm/src/providers/openrouter/cache-control.d.ts +5 -0
- package/esm/src/providers/openrouter/cache-control.js +4 -0
- package/esm/src/providers/openrouter/chat.d.ts +64 -0
- package/esm/src/providers/openrouter/chat.js +490 -0
- package/esm/src/providers/openrouter/image.d.ts +24 -0
- package/esm/src/providers/openrouter/image.js +187 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +10 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +99 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +3 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +8 -0
- package/esm/src/providers/openrouter/speech.d.ts +18 -0
- package/esm/src/providers/openrouter/speech.js +109 -0
- package/esm/src/providers/probe.d.ts +5 -0
- package/esm/src/providers/probe.js +15 -0
- package/esm/src/providers/shared/builtin-wire.d.ts +4 -0
- package/esm/src/providers/shared/builtin-wire.js +9 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/sse.d.ts +10 -0
- package/esm/src/providers/shared/sse.js +79 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +25 -0
- package/esm/src/providers/shared/tool-args.js +84 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/shared/vault.d.ts +13 -0
- package/esm/src/providers/shared/vault.js +41 -0
- package/esm/src/providers/types.d.ts +19 -0
- package/esm/src/providers/types.js +1 -0
- package/esm/src/surface/formats.d.ts +28 -0
- package/esm/src/surface/formats.js +139 -0
- package/esm/src/surface/mod.d.ts +14 -0
- package/esm/src/surface/mod.js +10 -0
- package/esm/src/surface/runtime.d.ts +40 -0
- package/esm/src/surface/runtime.js +439 -0
- package/esm/src/surface/tools.d.ts +15 -0
- package/esm/src/surface/tools.js +80 -0
- package/esm/src/surface/types.d.ts +104 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +108 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ModelId, ModelProfile, Profile, ProfileToolsSpec, ToolId, TurnRequest } from '../types.js';
|
|
2
|
+
import type { ToolRegistry } from './registry.js';
|
|
3
|
+
import type { PromoteLoadedResult, RegisteredTool, ToolFailure, TurnToolSnapshot, WireFunctionTool } from './types.js';
|
|
4
|
+
export declare function pathMatches(catalogPaths?: string[], turnPath?: string): boolean;
|
|
5
|
+
export declare function applyBuiltinMutualExclusions(tools: ToolRegistry, requested: string[]): string[];
|
|
6
|
+
export declare function profileToolAllow(profile: Profile): readonly ToolId[];
|
|
7
|
+
export declare function profileToolsSpec(profile: Profile): ProfileToolsSpec | undefined;
|
|
8
|
+
export declare function resolveAllowedCustomToolIds(tools: ToolRegistry, profile: Profile, req: TurnRequest): ToolId[];
|
|
9
|
+
export declare function resolveModelBuiltinIds(tools: ToolRegistry, profile: ModelProfile, req: TurnRequest, modelId: ModelId): ToolId[];
|
|
10
|
+
export declare function wireForTool(tools: ToolRegistry, name: string): WireFunctionTool | undefined;
|
|
11
|
+
export declare function buildWire(tools: ToolRegistry, visible: ToolId[]): WireFunctionTool[];
|
|
12
|
+
export declare function promoteTool(tools: ToolRegistry, state: TurnToolSnapshot, id: ToolId): void;
|
|
13
|
+
export declare function promoteBuiltin(tools: ToolRegistry, state: TurnToolSnapshot, id: ToolId): void;
|
|
14
|
+
/** Live declarations are fixed at session setup, so every allowed tool there is effectively T0. */
|
|
15
|
+
export declare function initialVisible(tools: ToolRegistry, profile: Profile, gated: ToolId[]): ToolId[];
|
|
16
|
+
export declare function initialBuiltins(tools: ToolRegistry, profile: Profile, gated: ToolId[]): ToolId[];
|
|
17
|
+
export declare function resolveTurnTools(tools: ToolRegistry, profile: Profile, req: TurnRequest, modelId: ModelId | undefined): TurnToolSnapshot;
|
|
18
|
+
export declare function prepareTurnToolSnapshot(tools: ToolRegistry, profile: Profile, req: TurnRequest, modelId: ModelId | undefined): Promise<TurnToolSnapshot>;
|
|
19
|
+
/** So concurrent host invokes do not share mutable state. */
|
|
20
|
+
export declare function cloneTurnToolSnapshot(state: TurnToolSnapshot): TurnToolSnapshot;
|
|
21
|
+
export declare function expandT1Policy(tools: ToolRegistry, state: TurnToolSnapshot, profile: Profile, req: TurnRequest): Promise<void>;
|
|
22
|
+
export declare function extractLoadedIds(output: unknown): string[] | undefined;
|
|
23
|
+
export declare function promoteLoadedTools(tools: ToolRegistry, state: TurnToolSnapshot, loaded: string[], profile: Profile): PromoteLoadedResult;
|
|
24
|
+
export declare function promotionTarget(tools: ToolRegistry, id: string, profile: Profile): {
|
|
25
|
+
tool: RegisteredTool;
|
|
26
|
+
} | {
|
|
27
|
+
failure: ToolFailure;
|
|
28
|
+
};
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
2
|
+
import { isRecord } from '../util/record.js';
|
|
3
|
+
/** Callable by the host: registered, and not a provider-run builtin. */
|
|
4
|
+
function isExecutable(tools, id) {
|
|
5
|
+
const tool = tools.get(id);
|
|
6
|
+
return tool !== undefined && tool.type !== 'builtin';
|
|
7
|
+
}
|
|
8
|
+
export function pathMatches(catalogPaths, turnPath) {
|
|
9
|
+
if (!catalogPaths || catalogPaths.includes('*')) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
if (!turnPath) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return catalogPaths.includes(turnPath);
|
|
16
|
+
}
|
|
17
|
+
export function applyBuiltinMutualExclusions(tools, requested) {
|
|
18
|
+
return requested.filter((id) => {
|
|
19
|
+
const tool = tools.get(id);
|
|
20
|
+
if (tool?.type !== 'builtin') {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const conflicts = tool.conflictsWith ?? [];
|
|
24
|
+
return !conflicts.some((other) => requested.includes(other));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function profileToolAllow(profile) {
|
|
28
|
+
return 'tools' in profile ? profile.tools.allow : [];
|
|
29
|
+
}
|
|
30
|
+
export function profileToolsSpec(profile) {
|
|
31
|
+
return profile.type === 'text' || profile.type === 'image' ? profile.tools : undefined;
|
|
32
|
+
}
|
|
33
|
+
export function resolveAllowedCustomToolIds(tools, profile, req) {
|
|
34
|
+
return profileToolAllow(profile).filter((id) => {
|
|
35
|
+
const tool = tools.get(id);
|
|
36
|
+
if (!tool || tool.type === 'builtin') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return profile.type === 'host' || pathMatches(tool.paths, req.path);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export function resolveModelBuiltinIds(tools, profile, req, modelId) {
|
|
43
|
+
const spec = profile.models[modelId];
|
|
44
|
+
if (!spec) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
return (spec.builtInTools ?? []).filter((id) => {
|
|
48
|
+
const tool = tools.get(id);
|
|
49
|
+
if (tool?.type !== 'builtin') {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return pathMatches(tool.paths, req.path);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export function wireForTool(tools, name) {
|
|
56
|
+
const tool = tools.get(name);
|
|
57
|
+
if (!tool || tool.type === 'builtin') {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
type: 'function',
|
|
62
|
+
name: tool.name,
|
|
63
|
+
description: tool.description,
|
|
64
|
+
parameters: tool.inputSchema,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function buildWire(tools, visible) {
|
|
68
|
+
const out = [];
|
|
69
|
+
for (const id of visible) {
|
|
70
|
+
const wire = wireForTool(tools, id);
|
|
71
|
+
if (wire) {
|
|
72
|
+
out.push(wire);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
export function promoteTool(tools, state, id) {
|
|
78
|
+
if (state.visible.includes(id)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
state.visible.push(id);
|
|
82
|
+
const wire = wireForTool(tools, id);
|
|
83
|
+
if (wire && !state.wire.some((w) => w.name === id)) {
|
|
84
|
+
state.wire.push(wire);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function promoteBuiltin(tools, state, id) {
|
|
88
|
+
if (state.builtins.includes(id)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const tool = tools.get(id);
|
|
92
|
+
if (tool?.type !== 'builtin') {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const conflicts = tool.conflictsWith ?? [];
|
|
96
|
+
state.builtins = state.builtins.filter((existing) => {
|
|
97
|
+
if (conflicts.includes(existing)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const existingTool = tools.get(existing);
|
|
101
|
+
return !(existingTool?.type === 'builtin' && existingTool.conflictsWith?.includes(id));
|
|
102
|
+
});
|
|
103
|
+
state.builtins.push(id);
|
|
104
|
+
}
|
|
105
|
+
/** Live declarations are fixed at session setup, so every allowed tool there is effectively T0. */
|
|
106
|
+
export function initialVisible(tools, profile, gated) {
|
|
107
|
+
if (profile.type === 'live' || profile.type === 'host') {
|
|
108
|
+
return [...gated];
|
|
109
|
+
}
|
|
110
|
+
return gated.filter((id) => tools.get(id)?.loadTier === 'T0');
|
|
111
|
+
}
|
|
112
|
+
export function initialBuiltins(tools, profile, gated) {
|
|
113
|
+
return applyBuiltinMutualExclusions(tools, gated.filter((id) => {
|
|
114
|
+
const tool = tools.get(id);
|
|
115
|
+
return tool?.type === 'builtin' && (profile.type === 'live' || tool.loadTier === 'T0');
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
export function resolveTurnTools(tools, profile, req, modelId) {
|
|
119
|
+
const customAllowed = resolveAllowedCustomToolIds(tools, profile, req);
|
|
120
|
+
const modelBuiltins = profile.type === 'host' || profile.type === 'decision' || modelId === undefined
|
|
121
|
+
? []
|
|
122
|
+
: resolveModelBuiltinIds(tools, profile, req, modelId);
|
|
123
|
+
const gated = [...customAllowed, ...modelBuiltins];
|
|
124
|
+
const builtins = initialBuiltins(tools, profile, gated);
|
|
125
|
+
const visible = initialVisible(tools, profile, gated);
|
|
126
|
+
const executable = visible.filter((id) => isExecutable(tools, id));
|
|
127
|
+
return {
|
|
128
|
+
builtins,
|
|
129
|
+
gated,
|
|
130
|
+
visible,
|
|
131
|
+
executable,
|
|
132
|
+
path: req.path,
|
|
133
|
+
sessionPermissions: req.sessionPermissions,
|
|
134
|
+
wire: buildWire(tools, visible),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export async function prepareTurnToolSnapshot(tools, profile, req, modelId) {
|
|
138
|
+
const snapshot = resolveTurnTools(tools, profile, req, modelId);
|
|
139
|
+
await expandT1Policy(tools, snapshot, profile, req);
|
|
140
|
+
return snapshot;
|
|
141
|
+
}
|
|
142
|
+
/** So concurrent host invokes do not share mutable state. */
|
|
143
|
+
export function cloneTurnToolSnapshot(state) {
|
|
144
|
+
return {
|
|
145
|
+
builtins: [...state.builtins],
|
|
146
|
+
gated: [...state.gated],
|
|
147
|
+
visible: [...state.visible],
|
|
148
|
+
executable: [...state.executable],
|
|
149
|
+
path: state.path,
|
|
150
|
+
sessionPermissions: state.sessionPermissions ? [...state.sessionPermissions] : undefined,
|
|
151
|
+
wire: state.wire.map((w) => ({ ...w, parameters: structuredClone(w.parameters) })),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
export async function expandT1Policy(tools, state, profile, req) {
|
|
155
|
+
const t1Policy = profileToolsSpec(profile)?.t1Policy;
|
|
156
|
+
if (!t1Policy) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
let selected;
|
|
160
|
+
try {
|
|
161
|
+
selected = await t1Policy({
|
|
162
|
+
profile,
|
|
163
|
+
input: req.input,
|
|
164
|
+
path: req.path,
|
|
165
|
+
sessionPermissions: req.sessionPermissions,
|
|
166
|
+
gated: state.gated,
|
|
167
|
+
host: req.host,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
172
|
+
throw new TheoremError('config', `Profile '${profile.id}' tools.t1Policy rejected: ${msg}`, {
|
|
173
|
+
cause: err,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (!Array.isArray(selected)) {
|
|
177
|
+
throw new TheoremError('config', `Profile '${profile.id}' tools.t1Policy must return ToolId[]`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
178
|
+
}
|
|
179
|
+
for (const id of selected) {
|
|
180
|
+
if (!state.gated.includes(id)) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const tool = tools.get(id);
|
|
184
|
+
if (!tool || tool.loadTier === 'T0') {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (tool.type === 'builtin') {
|
|
188
|
+
promoteBuiltin(tools, state, id);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
promoteTool(tools, state, id);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
state.executable = state.visible.filter((id) => isExecutable(tools, id));
|
|
195
|
+
}
|
|
196
|
+
const LOADED_ID_BLOCKLIST = new Set(['__proto__', 'constructor', 'prototype']);
|
|
197
|
+
export function extractLoadedIds(output) {
|
|
198
|
+
if (!isRecord(output)) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const { loaded } = output;
|
|
202
|
+
if (!Array.isArray(loaded) || !loaded.every((id) => typeof id === 'string')) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
return loaded;
|
|
206
|
+
}
|
|
207
|
+
export function promoteLoadedTools(tools, state, loaded, profile) {
|
|
208
|
+
if (profile.type === 'live' || profile.type === 'host') {
|
|
209
|
+
return { promoted: [] };
|
|
210
|
+
}
|
|
211
|
+
const toPromote = [];
|
|
212
|
+
for (const id of loaded) {
|
|
213
|
+
if (typeof id !== 'string' || LOADED_ID_BLOCKLIST.has(id)) {
|
|
214
|
+
return {
|
|
215
|
+
promoted: [],
|
|
216
|
+
failure: {
|
|
217
|
+
code: 'invalid_output',
|
|
218
|
+
kind: 'bad_response',
|
|
219
|
+
message: 'tools.t2Loader loaded ids must be plain strings', // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const target = promotionTarget(tools, id, profile);
|
|
224
|
+
if ('failure' in target) {
|
|
225
|
+
return { promoted: [], failure: target.failure };
|
|
226
|
+
}
|
|
227
|
+
const { tool } = target;
|
|
228
|
+
if (!pathMatches(tool.paths, state.path) || !state.gated.includes(id)) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
toPromote.push(id);
|
|
232
|
+
}
|
|
233
|
+
const promoted = [];
|
|
234
|
+
for (const id of toPromote) {
|
|
235
|
+
promoteTool(tools, state, id);
|
|
236
|
+
promoted.push(id);
|
|
237
|
+
}
|
|
238
|
+
state.executable = state.visible.filter((id) => isExecutable(tools, id));
|
|
239
|
+
return { promoted };
|
|
240
|
+
}
|
|
241
|
+
function promotionRefused(message) {
|
|
242
|
+
return { failure: { code: 'invalid_output', kind: 'bad_response', message } };
|
|
243
|
+
}
|
|
244
|
+
export function promotionTarget(tools, id, profile) {
|
|
245
|
+
if (!profileToolAllow(profile).includes(id)) {
|
|
246
|
+
return promotionRefused(`tools.t2Loader attempted to promote tool '${id}' outside profile allow`);
|
|
247
|
+
}
|
|
248
|
+
const tool = tools.get(id);
|
|
249
|
+
if (!tool) {
|
|
250
|
+
return promotionRefused(`tools.t2Loader attempted to promote unknown tool '${id}'`);
|
|
251
|
+
}
|
|
252
|
+
if (tool.type === 'builtin') {
|
|
253
|
+
return promotionRefused(`tools.t2Loader attempted to promote builtin '${id}' — only custom tools may be promoted`);
|
|
254
|
+
}
|
|
255
|
+
if (tool.loadTier !== 'T2') {
|
|
256
|
+
return promotionRefused(`tools.t2Loader attempted to promote tool '${id}' with loadTier '${tool.loadTier}' — only T2 tools may be promoted`);
|
|
257
|
+
}
|
|
258
|
+
return { tool };
|
|
259
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ZodType } from 'zod';
|
|
2
|
+
export type JsonSchema = Record<string, unknown>;
|
|
3
|
+
declare function validateToolInputSchema(schema: JsonSchema, mode?: 'gemini' | 'structural'): void;
|
|
4
|
+
declare function validateToolOutputSchema(schema: JsonSchema, mode?: 'gemini' | 'structural'): void;
|
|
5
|
+
declare function jsonSchemaFromZod(schema: ZodType, io?: 'input' | 'output'): JsonSchema;
|
|
6
|
+
export { jsonSchemaFromZod, validateToolInputSchema, validateToolOutputSchema };
|
|
7
|
+
/** Strips prototype-pollution keys before validation. */
|
|
8
|
+
export declare function plainToolInput(input: unknown): unknown;
|
|
9
|
+
/** A placeholder in the scheme or authority would let tool input choose where the credential goes. */
|
|
10
|
+
export declare function assertFixedEndpointOrigin(endpoint: string): void;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
3
|
+
const GEMINI_SUPPORTED_SCHEMA_KEYS = [
|
|
4
|
+
'type',
|
|
5
|
+
'format',
|
|
6
|
+
'title',
|
|
7
|
+
'description',
|
|
8
|
+
'nullable',
|
|
9
|
+
'enum',
|
|
10
|
+
'default',
|
|
11
|
+
'example',
|
|
12
|
+
'items',
|
|
13
|
+
'minItems',
|
|
14
|
+
'maxItems',
|
|
15
|
+
'properties',
|
|
16
|
+
'required',
|
|
17
|
+
'propertyOrdering',
|
|
18
|
+
'minProperties',
|
|
19
|
+
'maxProperties',
|
|
20
|
+
'minimum',
|
|
21
|
+
'maximum',
|
|
22
|
+
'pattern',
|
|
23
|
+
'minLength',
|
|
24
|
+
'maxLength',
|
|
25
|
+
'anyOf',
|
|
26
|
+
'oneOf',
|
|
27
|
+
];
|
|
28
|
+
function validateGeminiKeys(schema, path, errors) {
|
|
29
|
+
for (const key of Object.keys(schema)) {
|
|
30
|
+
if (!GEMINI_SUPPORTED_SCHEMA_KEYS.includes(key)) {
|
|
31
|
+
errors.push(`${path}: unsupported Gemini schema key '${key}'`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function validateSchemaShape(schema, path, mode, errors) {
|
|
36
|
+
if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
|
|
37
|
+
errors.push(`${path}: schema must be an object`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const hasType = typeof schema.type === 'string' || Array.isArray(schema.type);
|
|
41
|
+
const hasCombinator = schema.anyOf !== undefined || schema.oneOf !== undefined;
|
|
42
|
+
if (!hasType && !hasCombinator) {
|
|
43
|
+
if (mode === 'structural' && path !== '$') {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
errors.push(`${path}: missing type or combinator`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
47
|
+
}
|
|
48
|
+
if (mode === 'gemini') {
|
|
49
|
+
validateGeminiKeys(schema, path, errors);
|
|
50
|
+
}
|
|
51
|
+
if (schema.type === 'array' && schema.items === undefined) {
|
|
52
|
+
errors.push(`${path}: array schema must define items`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
function walkSchemaProperties(props, required, path, mode, errors) {
|
|
57
|
+
const reqList = Array.isArray(required) ? required : [];
|
|
58
|
+
for (const req of reqList) {
|
|
59
|
+
if (typeof req === 'string' && !(req in props)) {
|
|
60
|
+
errors.push(`${path}: required key '${req}' missing from properties`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const [key, child] of Object.entries(props)) {
|
|
64
|
+
if (child && typeof child === 'object') {
|
|
65
|
+
walkSchema(child, `${path}.properties.${key}`, mode, errors);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function walkSchema(schema, path, mode, errors) {
|
|
70
|
+
if (!validateSchemaShape(schema, path, mode, errors))
|
|
71
|
+
return;
|
|
72
|
+
const props = schema.properties;
|
|
73
|
+
if (props && typeof props === 'object' && !Array.isArray(props)) {
|
|
74
|
+
walkSchemaProperties(props, schema.required, path, mode, errors);
|
|
75
|
+
}
|
|
76
|
+
if (schema.items && typeof schema.items === 'object' && !Array.isArray(schema.items)) {
|
|
77
|
+
walkSchema(schema.items, `${path}.items`, mode, errors);
|
|
78
|
+
}
|
|
79
|
+
for (const combinator of ['anyOf', 'oneOf']) {
|
|
80
|
+
const branch = schema[combinator];
|
|
81
|
+
if (Array.isArray(branch)) {
|
|
82
|
+
branch.forEach((entry, index) => {
|
|
83
|
+
if (entry && typeof entry === 'object') {
|
|
84
|
+
walkSchema(entry, `${path}.${combinator}[${index}]`, mode, errors);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function validateToolWireSchema(schema, mode = 'gemini', label = 'input') {
|
|
91
|
+
const errors = [];
|
|
92
|
+
walkSchema(schema, '$', mode, errors);
|
|
93
|
+
if (errors.length > 0) {
|
|
94
|
+
throw new TheoremError('config', `Invalid tool ${label} schema: ${errors.join('; ')}`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function validateToolInputSchema(schema, mode = 'gemini') {
|
|
98
|
+
validateToolWireSchema(schema, mode, 'input');
|
|
99
|
+
}
|
|
100
|
+
function validateToolOutputSchema(schema, mode = 'structural') {
|
|
101
|
+
validateToolWireSchema(schema, mode, 'output');
|
|
102
|
+
}
|
|
103
|
+
function stripProperties(value) {
|
|
104
|
+
const props = {};
|
|
105
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
106
|
+
for (const [propKey, propValue] of Object.entries(value)) {
|
|
107
|
+
if (propValue && typeof propValue === 'object') {
|
|
108
|
+
props[propKey] = stripUnsupportedGeminiKeys(propValue);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return props;
|
|
113
|
+
}
|
|
114
|
+
function stripBranches(branches) {
|
|
115
|
+
return branches.map((entry) => entry && typeof entry === 'object' ? stripUnsupportedGeminiKeys(entry) : entry);
|
|
116
|
+
}
|
|
117
|
+
function stripUnsupportedGeminiKeys(schema) {
|
|
118
|
+
const out = {};
|
|
119
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
120
|
+
if (!GEMINI_SUPPORTED_SCHEMA_KEYS.includes(key)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (key === 'properties') {
|
|
124
|
+
out.properties = stripProperties(value);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (key === 'items' && value && typeof value === 'object' && !Array.isArray(value)) {
|
|
128
|
+
out.items = stripUnsupportedGeminiKeys(value);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if ((key === 'anyOf' || key === 'oneOf') && Array.isArray(value)) {
|
|
132
|
+
out[key] = stripBranches(value);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
out[key] = value;
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
function jsonSchemaFromZod(schema, io = 'output') {
|
|
140
|
+
const json = z.toJSONSchema(schema, {
|
|
141
|
+
target: 'openApi3',
|
|
142
|
+
io,
|
|
143
|
+
});
|
|
144
|
+
delete json.$schema;
|
|
145
|
+
if (!json.type) {
|
|
146
|
+
json.type = 'object';
|
|
147
|
+
}
|
|
148
|
+
return stripUnsupportedGeminiKeys(json);
|
|
149
|
+
}
|
|
150
|
+
export { jsonSchemaFromZod, validateToolInputSchema, validateToolOutputSchema };
|
|
151
|
+
/** Strips prototype-pollution keys before validation. */
|
|
152
|
+
export function plainToolInput(input) {
|
|
153
|
+
if (input === null || typeof input !== 'object') {
|
|
154
|
+
return input;
|
|
155
|
+
}
|
|
156
|
+
if (Array.isArray(input)) {
|
|
157
|
+
return input.map(plainToolInput);
|
|
158
|
+
}
|
|
159
|
+
const out = {};
|
|
160
|
+
for (const key of Object.keys(input)) {
|
|
161
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
out[key] = plainToolInput(input[key]);
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
/** A placeholder in the scheme or authority would let tool input choose where the credential goes. */
|
|
169
|
+
export function assertFixedEndpointOrigin(endpoint) {
|
|
170
|
+
const origin = /^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(endpoint)?.[0];
|
|
171
|
+
if (!origin || /[{}]/.test(origin)) {
|
|
172
|
+
throw new TheoremError('config', `Endpoint "${endpoint}" must start with a fixed scheme and host; placeholders belong in the path or query`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-in fetch a function tool with `auth` gets as `ctx.signedInFetch`.
|
|
3
|
+
* The kernel holds the credential; the handler only makes requests that carry it.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { RequestChecks } from './events.js';
|
|
8
|
+
import { type CredentialRefusal } from './remote.js';
|
|
9
|
+
import type { SignedInFetch, ToolContext } from './types.js';
|
|
10
|
+
/** Thrown by a signed-in fetch when the service refuses the credential; the kernel settles it. */
|
|
11
|
+
export declare class CredentialRefusedError extends Error {
|
|
12
|
+
readonly refusal: CredentialRefusal;
|
|
13
|
+
constructor(refusal: CredentialRefusal);
|
|
14
|
+
}
|
|
15
|
+
export declare function signedInFetch(prepared: {
|
|
16
|
+
authHeaders: Record<string, string>;
|
|
17
|
+
audience?: string;
|
|
18
|
+
}, ctx: ToolContext, checks: RequestChecks): SignedInFetch;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-in fetch a function tool with `auth` gets as `ctx.signedInFetch`.
|
|
3
|
+
* The kernel holds the credential; the handler only makes requests that carry it.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { fetchGuarded } from '../../guardrails/network.js';
|
|
8
|
+
import { TheoremError } from '../../guardrails/theorem-error.js';
|
|
9
|
+
import { toolNetworkPolicy } from './events.js';
|
|
10
|
+
import { audienceMismatch, credentialRefusal, refusalAsksForSignIn, } from './remote.js';
|
|
11
|
+
/** Thrown by a signed-in fetch when the service refuses the credential; the kernel settles it. */
|
|
12
|
+
export class CredentialRefusedError extends Error {
|
|
13
|
+
refusal;
|
|
14
|
+
constructor(refusal) {
|
|
15
|
+
super(`The service refused the credential (HTTP ${refusal.status}).`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
16
|
+
this.name = 'CredentialRefusedError';
|
|
17
|
+
this.refusal = refusal;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function signedInFetch(prepared, ctx, checks) {
|
|
21
|
+
return async (url, request = {}) => {
|
|
22
|
+
const target = new URL(url);
|
|
23
|
+
const mismatch = audienceMismatch(prepared.audience, target);
|
|
24
|
+
if (mismatch)
|
|
25
|
+
throw new TheoremError('config', mismatch);
|
|
26
|
+
const response = await fetchGuarded(target.href, {
|
|
27
|
+
method: request.method ?? 'GET',
|
|
28
|
+
headers: request.headers,
|
|
29
|
+
body: request.body,
|
|
30
|
+
signal: ctx.signal,
|
|
31
|
+
}, {
|
|
32
|
+
policy: toolNetworkPolicy(ctx),
|
|
33
|
+
followRedirects: true,
|
|
34
|
+
originBoundHeaders: prepared.authHeaders,
|
|
35
|
+
resolveHost: ctx.resolveHost,
|
|
36
|
+
onCheck: checks.onCheck,
|
|
37
|
+
});
|
|
38
|
+
const refusal = credentialRefusal(response);
|
|
39
|
+
if (refusal && refusalAsksForSignIn(refusal)) {
|
|
40
|
+
await response.body?.cancel();
|
|
41
|
+
throw new CredentialRefusedError(refusal);
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import { type LexiconOverrides } from '../../guardrails/lexicon.js';
|
|
3
|
+
import type { SpanHandle } from '../../observability/trace-span.js';
|
|
4
|
+
import { type InjectUnit, type StageHandler, type StageResult } from '../stages.js';
|
|
5
|
+
import type { Profile, TurnEvent, TurnHistoryMessage } from '../types.js';
|
|
6
|
+
import { type ToolCallBase } from './events.js';
|
|
7
|
+
import type { ModelToolResult, ToolContext, ToolFailure, ToolGate } from './types.js';
|
|
8
|
+
export interface ToolStageSupport {
|
|
9
|
+
/** In order: request `onStage`, then turn/session ambient. */
|
|
10
|
+
handlers: StageHandler[];
|
|
11
|
+
/** Its guardrails sanitize injects and its inject gate applies. */
|
|
12
|
+
profile: Profile;
|
|
13
|
+
step: number;
|
|
14
|
+
history: () => readonly TurnHistoryMessage[];
|
|
15
|
+
injectAllowed: boolean;
|
|
16
|
+
injectWouldExceedMaxSteps?: boolean;
|
|
17
|
+
host?: unknown;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
span?: SpanHandle;
|
|
20
|
+
}
|
|
21
|
+
export type PreBodyOutcome = {
|
|
22
|
+
ok: true;
|
|
23
|
+
input: unknown;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
kind: 'aborted';
|
|
27
|
+
aborted: true | {
|
|
28
|
+
reason?: string;
|
|
29
|
+
};
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
kind: 'gated';
|
|
33
|
+
gate: ToolGate;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
kind: 'failed';
|
|
37
|
+
failure: ToolFailure;
|
|
38
|
+
/** The host refused the call (`deny`), rather than it failing. */
|
|
39
|
+
denied?: true;
|
|
40
|
+
};
|
|
41
|
+
export type PostToolStageOutcome = {
|
|
42
|
+
abort?: boolean | {
|
|
43
|
+
reason?: string;
|
|
44
|
+
};
|
|
45
|
+
/** The caller lands these after recording the tool result. */
|
|
46
|
+
inject: InjectUnit[];
|
|
47
|
+
deny?: {
|
|
48
|
+
code: string;
|
|
49
|
+
message: string;
|
|
50
|
+
};
|
|
51
|
+
/** The caller re-validates and re-projects it. */
|
|
52
|
+
mutate?: {
|
|
53
|
+
output: unknown;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/** Tool `preTool` → host `pre_tool` → mutate re-parse. */
|
|
57
|
+
export declare function runPreToolPipeline(args: {
|
|
58
|
+
tool: {
|
|
59
|
+
name: string;
|
|
60
|
+
input: {
|
|
61
|
+
safeParse: (value: unknown) => z.ZodSafeParseResult<unknown>;
|
|
62
|
+
};
|
|
63
|
+
preTool?: (input: never, ctx: ToolContext) => StageResult | undefined | Promise<StageResult | undefined>;
|
|
64
|
+
};
|
|
65
|
+
input: unknown;
|
|
66
|
+
ctx: ToolContext;
|
|
67
|
+
base: ToolCallBase;
|
|
68
|
+
stages?: ToolStageSupport;
|
|
69
|
+
}): AsyncGenerator<TurnEvent, PreBodyOutcome>;
|
|
70
|
+
export declare function runPostToolStages(args: {
|
|
71
|
+
stages: ToolStageSupport;
|
|
72
|
+
toolName: string;
|
|
73
|
+
callId: string;
|
|
74
|
+
input?: unknown;
|
|
75
|
+
callNotStarted?: boolean;
|
|
76
|
+
outputRaw?: unknown;
|
|
77
|
+
outputModel?: ModelToolResult;
|
|
78
|
+
failure?: ToolFailure;
|
|
79
|
+
awaiting?: boolean;
|
|
80
|
+
/** False when there is no completed output for `mutate` to replace. */
|
|
81
|
+
mutable: boolean;
|
|
82
|
+
}): AsyncGenerator<TurnEvent, PostToolStageOutcome>;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the sign-in gate's `readBack`: what a transport that answers the call now (Live) tells
|
|
85
|
+
* the model while the person signs in. Other gates hold the call, and the model reads nothing yet.
|
|
86
|
+
*/
|
|
87
|
+
export declare function emitGateSettlement(args: {
|
|
88
|
+
base: ToolCallBase;
|
|
89
|
+
gate: ToolGate;
|
|
90
|
+
callId: string;
|
|
91
|
+
toolName: string;
|
|
92
|
+
lexicon: LexiconOverrides | undefined;
|
|
93
|
+
}): AsyncGenerator<TurnEvent, string | undefined>;
|