@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,305 @@
|
|
|
1
|
+
import { isStreamedCanaryEvent } from './canary.js';
|
|
2
|
+
import { eventPromptLeakHits, isPromptLeakHit, promptLeakReason, runEnforcer, WITHHELD_REASON, } from './egress.js';
|
|
3
|
+
import { streamPlanOf } from './egress-stream.js';
|
|
4
|
+
import { TheoremError } from './error.js';
|
|
5
|
+
import { guardrailFromHits, guardrailFromVerdict } from './events.js';
|
|
6
|
+
import { lexiconText } from './lexicon.js';
|
|
7
|
+
import { resolveGuardrailPolicy } from './policy.js';
|
|
8
|
+
import { createOutboundProgressiveGate, LIVE_DEFAULT_HOLDBACK, } from './progressive-yield.js';
|
|
9
|
+
import { thoughtGuardFor } from './thought-guard.js';
|
|
10
|
+
const UNTRANSCRIBED_HIT = { rule: 'live.untranscribed-audio', severity: 'high' };
|
|
11
|
+
function egressSpec(session) {
|
|
12
|
+
return session.policy.egress;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The policy with Live's shorter default lookback when a host enforcer set
|
|
16
|
+
* none: every held character of transcript holds its audio. The bundled policy
|
|
17
|
+
* holds exactly and takes no lookback.
|
|
18
|
+
*/
|
|
19
|
+
function liveHoldback(policy) {
|
|
20
|
+
if (!policy.egress ||
|
|
21
|
+
policy.egress.holdback !== undefined ||
|
|
22
|
+
streamPlanOf(policy.egress.enforce)) {
|
|
23
|
+
return policy;
|
|
24
|
+
}
|
|
25
|
+
return { ...policy, egress: { ...policy.egress, holdback: LIVE_DEFAULT_HOLDBACK } };
|
|
26
|
+
}
|
|
27
|
+
/** A canary is attached only when the profile policy enables it and the caller supplied a token. */
|
|
28
|
+
function createLiveOutboundGateSession(profile, canary, privateSystem, givenUrls) {
|
|
29
|
+
const policy = liveHoldback(resolveGuardrailPolicy(profile.guardrails));
|
|
30
|
+
const useCanary = policy.canary && Boolean(canary);
|
|
31
|
+
const context = {
|
|
32
|
+
stage: 'live_outbound',
|
|
33
|
+
trust: 'untrusted',
|
|
34
|
+
profileId: profile.id,
|
|
35
|
+
...(useCanary ? { canary } : {}),
|
|
36
|
+
// The system prompt is guarded against echo alongside the canary that binds it.
|
|
37
|
+
...(useCanary && policy.promptEcho && privateSystem?.length ? { privateSystem } : {}),
|
|
38
|
+
...(profile.lexicon ? { lexicon: profile.lexicon } : {}),
|
|
39
|
+
...(givenUrls ? { givenUrls } : {}),
|
|
40
|
+
};
|
|
41
|
+
const thoughts = thoughtGuardFor(policy.egress?.enforce, context);
|
|
42
|
+
return {
|
|
43
|
+
policy,
|
|
44
|
+
context,
|
|
45
|
+
gate: createOutboundProgressiveGate(policy, context),
|
|
46
|
+
held: [],
|
|
47
|
+
releasedTo: 0,
|
|
48
|
+
withholdVisible: false,
|
|
49
|
+
...(thoughts ? { thoughts } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function resetCycle(session) {
|
|
53
|
+
const carry = session.gate?.carryOut();
|
|
54
|
+
session.gate = createOutboundProgressiveGate(session.policy, session.context, carry);
|
|
55
|
+
session.held = [];
|
|
56
|
+
session.releasedTo = 0;
|
|
57
|
+
session.withholdVisible = false;
|
|
58
|
+
session.promptLeaks = undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Canary-only profiles stop the turn immediately; egress profiles defer to finalize. */
|
|
61
|
+
function canaryOnlyImmediateWithhold(session) {
|
|
62
|
+
return !egressSpec(session)?.enforce;
|
|
63
|
+
}
|
|
64
|
+
function withholdResult(reason, hits, prior = []) {
|
|
65
|
+
const guardrail = guardrailFromHits('live_outbound', 'untrusted', hits, 'block');
|
|
66
|
+
return {
|
|
67
|
+
action: 'withhold',
|
|
68
|
+
error: new TheoremError('safety', reason),
|
|
69
|
+
events: [...prior, ...(guardrail ? [guardrail] : [])],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Window offset the gate has cleared for release. */
|
|
73
|
+
function clearedTo(gate) {
|
|
74
|
+
return gate.accumulated().length - gate.unreleased().length;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Release held output up to window offset `to`: reply chunks as far as they
|
|
78
|
+
* reach, media once the transcript covering it is cleared — or all of it when
|
|
79
|
+
* the transcript is whole. Stops at the first item that cannot go yet, so the
|
|
80
|
+
* host sees output in arrival order.
|
|
81
|
+
*/
|
|
82
|
+
function releaseHeld(session, gate, to, into, transcriptWhole = false) {
|
|
83
|
+
const window = gate.accumulated();
|
|
84
|
+
for (let item = session.held[0]; item !== undefined; item = session.held[0]) {
|
|
85
|
+
const { event } = item;
|
|
86
|
+
if (event.type !== 'media') {
|
|
87
|
+
const from = Math.max(item.start, session.releasedTo);
|
|
88
|
+
const upTo = Math.min(item.end, to);
|
|
89
|
+
if (upTo > from) {
|
|
90
|
+
into.push({ ...event, text: window.slice(from, upTo) });
|
|
91
|
+
session.releasedTo = upTo;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (item.end > to && !(transcriptWhole && event.type === 'media')) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (event.type === 'media') {
|
|
98
|
+
into.push(event);
|
|
99
|
+
}
|
|
100
|
+
session.held.shift();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Apply a progressive scan result. Clean: release what the gate cleared.
|
|
105
|
+
* Blocked: canary-only withholds the session; egress withholds the rest of
|
|
106
|
+
* the cycle and reports the hit. `undefined` means keep going.
|
|
107
|
+
*/
|
|
108
|
+
function applyScan(session, gate, result, into) {
|
|
109
|
+
if (!result.blocked) {
|
|
110
|
+
releaseHeld(session, gate, clearedTo(gate), into);
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
if (canaryOnlyImmediateWithhold(session)) {
|
|
114
|
+
return withholdResult(promptLeakReason(result.hits), result.hits, into);
|
|
115
|
+
}
|
|
116
|
+
const leaks = result.hits.filter(isPromptLeakHit);
|
|
117
|
+
if (leaks.length > 0) {
|
|
118
|
+
session.promptLeaks = leaks;
|
|
119
|
+
}
|
|
120
|
+
session.withholdVisible = true;
|
|
121
|
+
const guardrail = guardrailFromHits('live_outbound', 'untrusted', result.hits, 'block');
|
|
122
|
+
if (guardrail) {
|
|
123
|
+
into.push(guardrail);
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
/** Scan and release everything held (a non-reply event, or the end of the cycle). */
|
|
128
|
+
async function flushHeld(session, gate, into) {
|
|
129
|
+
if (session.withholdVisible || session.held.length === 0) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
return applyScan(session, gate, await gate.flush(), into);
|
|
133
|
+
}
|
|
134
|
+
/** Media waits behind the reply before it, so speech is heard only after its transcript clears the scan. */
|
|
135
|
+
function holdMedia(session, gate, event, transcribed) {
|
|
136
|
+
const at = gate.accumulated().length;
|
|
137
|
+
session.held.push({ event, start: at, end: transcribed ? at : Number.POSITIVE_INFINITY });
|
|
138
|
+
}
|
|
139
|
+
/** The media still waiting for a transcript chunk is covered by this one. */
|
|
140
|
+
function coverMedia(session, end) {
|
|
141
|
+
for (let i = session.held.length - 1; i >= 0; i -= 1) {
|
|
142
|
+
const item = session.held[i];
|
|
143
|
+
if (item === undefined || item.end !== Number.POSITIVE_INFINITY) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
item.end = end;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function holdStreamChunk(session, gate, event, into) {
|
|
150
|
+
const text = event.text ?? '';
|
|
151
|
+
if (!text) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const start = gate.accumulated().length;
|
|
155
|
+
coverMedia(session, start + text.length);
|
|
156
|
+
session.held.push({ event, start, end: start + text.length });
|
|
157
|
+
const result = await gate.process(text);
|
|
158
|
+
if (session.withholdVisible) {
|
|
159
|
+
// Keep feeding the window so finalize judges the whole cycle.
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
return applyScan(session, gate, result, into);
|
|
163
|
+
}
|
|
164
|
+
async function processLiveOutboundBatch(session, events) {
|
|
165
|
+
const toEmit = [];
|
|
166
|
+
const { gate } = session;
|
|
167
|
+
if (!gate) {
|
|
168
|
+
return emitOrIdle(events);
|
|
169
|
+
}
|
|
170
|
+
// One batch is one provider message: its transcript is its audio's.
|
|
171
|
+
let transcribed = false;
|
|
172
|
+
for (const event of events) {
|
|
173
|
+
if (isStreamedCanaryEvent(event)) {
|
|
174
|
+
transcribed ||= Boolean(event.text);
|
|
175
|
+
const stopped = await holdStreamChunk(session, gate, event, toEmit);
|
|
176
|
+
if (stopped) {
|
|
177
|
+
return stopped;
|
|
178
|
+
}
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (event.type === 'media') {
|
|
182
|
+
holdMedia(session, gate, event, transcribed);
|
|
183
|
+
// Media not yet held until the next event can release it now.
|
|
184
|
+
if (!session.withholdVisible)
|
|
185
|
+
releaseHeld(session, gate, clearedTo(gate), toEmit);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const stopped = await flushHeld(session, gate, toEmit);
|
|
189
|
+
if (stopped) {
|
|
190
|
+
return stopped;
|
|
191
|
+
}
|
|
192
|
+
if (isGenerationComplete(event)) {
|
|
193
|
+
releaseSpoken(session, gate, toEmit);
|
|
194
|
+
}
|
|
195
|
+
const leaks = session.context.canary
|
|
196
|
+
? eventPromptLeakHits(event, session.context.canary, session.context.privateSystem)
|
|
197
|
+
: [];
|
|
198
|
+
if (leaks.length > 0) {
|
|
199
|
+
return withholdResult(promptLeakReason(leaks), leaks, toEmit);
|
|
200
|
+
}
|
|
201
|
+
if (event.type === 'thought' && session.thoughts) {
|
|
202
|
+
toEmit.push(...thoughtEvents(session.thoughts.push(event.text), event));
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
toEmit.push(event);
|
|
206
|
+
}
|
|
207
|
+
return emitOrIdle(toEmit);
|
|
208
|
+
}
|
|
209
|
+
/** What a thought guard released, after the event saying what it omitted from it. */
|
|
210
|
+
function thoughtEvents({ text, hits }, event) {
|
|
211
|
+
const guardrail = guardrailFromHits('thought', 'untrusted', hits, 'redact');
|
|
212
|
+
return [...(guardrail ? [guardrail] : []), ...(text ? [{ ...event, text }] : [])];
|
|
213
|
+
}
|
|
214
|
+
function isGenerationComplete(event) {
|
|
215
|
+
return event.type === 'done' && event.stop?.kind === 'generation_complete';
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The model finished speaking: its transcript is whole and cleared, so the
|
|
219
|
+
* audio after its last chunk goes too. A cycle with no transcript keeps its
|
|
220
|
+
* audio for `dropUntranscribed`; a withheld cycle keeps it for the verdict.
|
|
221
|
+
*/
|
|
222
|
+
function releaseSpoken(session, gate, into) {
|
|
223
|
+
const whole = gate.accumulated().length;
|
|
224
|
+
if (session.withholdVisible || whole === 0 || clearedTo(gate) < whole) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
releaseHeld(session, gate, whole, into, true);
|
|
228
|
+
}
|
|
229
|
+
function emitOrIdle(events) {
|
|
230
|
+
return events.length === 0 ? { action: 'idle' } : { action: 'emit', events };
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Live has no repair loop. Allow releases what is still held; redact and refuse replace it with
|
|
234
|
+
* text (held audio is dropped); block withholds it as a `safety` error.
|
|
235
|
+
*/
|
|
236
|
+
async function finalEgressVerdict(session, gate, egress, prior) {
|
|
237
|
+
// The host policy adds checks; it never releases a system-prompt leak.
|
|
238
|
+
const leaks = session.promptLeaks;
|
|
239
|
+
const verdict = leaks
|
|
240
|
+
? { action: 'block', hits: leaks, rejection: WITHHELD_REASON.egress }
|
|
241
|
+
: await runEnforcer(egress.enforce, { text: gate.accumulated() }, session.context);
|
|
242
|
+
const guardrail = guardrailFromVerdict('live_outbound', 'untrusted', verdict);
|
|
243
|
+
const events = [...prior, ...(guardrail ? [guardrail] : [])];
|
|
244
|
+
if (verdict.action === 'redact') {
|
|
245
|
+
return { action: 'emit', events: [...events, { type: 'text', text: verdict.text }] };
|
|
246
|
+
}
|
|
247
|
+
if (verdict.action === 'block') {
|
|
248
|
+
if (egress.onBlock === 'refuse_to_user') {
|
|
249
|
+
const text = lexiconText('egress.refusal', {}, session.context.lexicon);
|
|
250
|
+
return { action: 'emit', events: [...events, { type: 'text', text }] };
|
|
251
|
+
}
|
|
252
|
+
return withholdResult(WITHHELD_REASON.egress, verdict.hits, prior);
|
|
253
|
+
}
|
|
254
|
+
releaseHeld(session, gate, gate.accumulated().length, events, true);
|
|
255
|
+
return emitOrIdle(events);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* A cycle that held audio but produced no transcript: nothing checked the
|
|
259
|
+
* audio, so it is dropped and reported, never released.
|
|
260
|
+
*/
|
|
261
|
+
function dropUntranscribed(session, events) {
|
|
262
|
+
if (session.held.length === 0) {
|
|
263
|
+
return events;
|
|
264
|
+
}
|
|
265
|
+
const guardrail = guardrailFromHits('live_outbound', 'untrusted', [UNTRANSCRIBED_HIT], 'block');
|
|
266
|
+
return guardrail ? [...events, guardrail] : events;
|
|
267
|
+
}
|
|
268
|
+
async function finalizeCycle(session, gate) {
|
|
269
|
+
const events = [];
|
|
270
|
+
const stopped = await flushHeld(session, gate, events);
|
|
271
|
+
if (stopped) {
|
|
272
|
+
return stopped;
|
|
273
|
+
}
|
|
274
|
+
if (!gate.accumulated()) {
|
|
275
|
+
return emitOrIdle(dropUntranscribed(session, events));
|
|
276
|
+
}
|
|
277
|
+
const egress = egressSpec(session);
|
|
278
|
+
if (egress) {
|
|
279
|
+
return await finalEgressVerdict(session, gate, egress, events);
|
|
280
|
+
}
|
|
281
|
+
releaseHeld(session, gate, gate.accumulated().length, events, true);
|
|
282
|
+
return emitOrIdle(events);
|
|
283
|
+
}
|
|
284
|
+
/** Call once after the provider has finished the cycle; it also starts the next one. */
|
|
285
|
+
async function finalizeLiveOutboundTurn(session) {
|
|
286
|
+
if (!session.gate) {
|
|
287
|
+
return { action: 'idle' };
|
|
288
|
+
}
|
|
289
|
+
const thought = session.thoughts
|
|
290
|
+
? thoughtEvents(session.thoughts.flush(), { type: 'thought', text: '' })
|
|
291
|
+
: [];
|
|
292
|
+
const result = await finalizeCycle(session, session.gate);
|
|
293
|
+
resetCycle(session);
|
|
294
|
+
if (thought.length === 0)
|
|
295
|
+
return result;
|
|
296
|
+
if (result.action === 'idle')
|
|
297
|
+
return { action: 'emit', events: thought };
|
|
298
|
+
return { ...result, events: [...thought, ...(result.events ?? [])] };
|
|
299
|
+
}
|
|
300
|
+
/** Drop the cycle's held output when the user interrupts mid-turn. */
|
|
301
|
+
function abortLiveOutboundTurn(session) {
|
|
302
|
+
session.thoughts?.flush();
|
|
303
|
+
resetCycle(session);
|
|
304
|
+
}
|
|
305
|
+
export { abortLiveOutboundTurn, createLiveOutboundGateSession, finalizeLiveOutboundTurn, processLiveOutboundBatch, };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound and outbound guardrail primitives: sanitization, injection and sensitive detection,
|
|
3
|
+
* canary egress gates, egress policy and public error mapping. App-specific policy copy stays host-owned.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export type { CanaryGateResult, CanaryStreamGate } from './canary.js';
|
|
9
|
+
export { bindCanary, createCanaryStreamGate, eventHasCanary, isStreamedCanaryEvent, mintCanary, OMIT_CANARY, redactCanary, scanTextForCanaryLeak, USER_CLOSE, USER_OPEN, wrapUserData, } from './canary.js';
|
|
10
|
+
export type { CanaryGateSession } from './canary-gate.js';
|
|
11
|
+
export { createCanaryGateSession, filterCanaryGatedEvents } from './canary-gate.js';
|
|
12
|
+
export type { EgressChecks, UrlCheck } from './egress.js';
|
|
13
|
+
export { collectEgressHits, hitRules, runEnforcer, standardEgressEnforce, } from './egress.js';
|
|
14
|
+
export type { EgressPolicyOptions } from './egress-policy.js';
|
|
15
|
+
export { egressPolicy } from './egress-policy.js';
|
|
16
|
+
export type { CompiledEgressRules, EgressRule } from './egress-rules.js';
|
|
17
|
+
export type { GivenUrls } from './egress-urls.js';
|
|
18
|
+
export type { ErrorCopies, ErrorCopy, ErrorKind, TheoremErrorOptions } from './error.js';
|
|
19
|
+
export { describeError, ERROR_KINDS, errorKind, isAbortError, isTimeoutError, kindOfHttpStatus, publicError, TheoremError, throwIfAborted, toErrorEvent, withPublicWording, } from './error.js';
|
|
20
|
+
export { errorCopiesSchema, errorKindSchema, guardrailEventSchema } from './event-schemas.js';
|
|
21
|
+
export { guardrailFromHits, guardrailFromVerdict, guardrailTurnEvent, projectGuardrailTurnEvent, } from './events.js';
|
|
22
|
+
export { hitFromSpan, projectGuardrailEvent, } from './hits.js';
|
|
23
|
+
export { injectionSpans } from './injection.js';
|
|
24
|
+
export type { ClientLexiconKey, LexiconKey, LexiconOverrides, LexiconParams } from './lexicon.js';
|
|
25
|
+
export { CLIENT_LEXICON_KEYS, LEXICON_KEYS, lexiconDefault, lexiconText, overrideLexicon, resetLexicon, } from './lexicon.js';
|
|
26
|
+
export type { LiveHeldOutput, LiveOutboundBatchResult, LiveOutboundGateSession, } from './live-outbound-gate.js';
|
|
27
|
+
export { abortLiveOutboundTurn, createLiveOutboundGateSession, finalizeLiveOutboundTurn, processLiveOutboundBatch, } from './live-outbound-gate.js';
|
|
28
|
+
export type { DetectionOptions } from './policy.js';
|
|
29
|
+
export { detectionForTrust, resolveGuardrailPolicy } from './policy.js';
|
|
30
|
+
export type { ProgressiveYieldGate, ProgressiveYieldGateOptions, ProgressiveYieldResult, } from './progressive-yield.js';
|
|
31
|
+
export { createOutboundProgressiveGate, createProgressiveYieldGate, DEFAULT_HOLDBACK, LIVE_DEFAULT_HOLDBACK, } from './progressive-yield.js';
|
|
32
|
+
export { PROMPT_ECHO_WORDS, scanTextForPromptEcho } from './prompt-echo.js';
|
|
33
|
+
export type { QuotaSlotStatus } from './quota.js';
|
|
34
|
+
export { clientIp, quotaExhausted, releaseSlot, resetSlots, skipQuota, takeSlot, } from './quota.js';
|
|
35
|
+
export type { GuardrailRule } from './rules.js';
|
|
36
|
+
export { DIRECTIVE_RULES, EGRESS_RULES, NETWORK_RULES, SANITIZE_RULES, TOOL_RULES, } from './rules.js';
|
|
37
|
+
export { detectionForProfile, detectText, redactSensitiveOnly, sanitizeHistory, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, sanitizeTurnRequestWithEvents, } from './sanitize.js';
|
|
38
|
+
export type { SensitiveGroup, SensitiveGroups, SensitiveSelection, SensitiveSwitches, } from './sensitive.js';
|
|
39
|
+
export { SENSITIVE_GROUPS, sensitiveSpans } from './sensitive.js';
|
|
40
|
+
export type { ScanText } from './serialize.js';
|
|
41
|
+
export { scanTextOf, textForScan } from './serialize.js';
|
|
42
|
+
export { advisoryLevel, directiveHits, looksDirective, } from './tool-directives.js';
|
|
43
|
+
export type { GuardedToolText } from './tool-result.js';
|
|
44
|
+
export { checkTaintGate, composeToolText, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint, TOOL_CLOSE, toolCallEvent, wrapToolData, } from './tool-result.js';
|
|
45
|
+
export type { AdvisoryLevel, EgressEnforcer, EgressOnBlock, GuardrailAction, GuardrailContext, GuardrailEvent, GuardrailHit, GuardrailStage, HostGuardrailsSpec, NetworkGuardrailSpec, OutboundPayload, ProfileEgressSpec, ProfileGuardrailsSpec, Provenance, QuotaGuardrailSpec, ResolvedEgressSpec, ResolvedGuardrailPolicy, Severity, TaintGate, TaintGuardrailSpec, ToolOrigin, TrustLevel, TurnTaint, Verdict, } from './types.js';
|
|
46
|
+
export { ADVISORY_LEVELS, EGRESS_ON_BLOCK, GUARDRAIL_STAGES, SEVERITIES, TAINT_GATES, TOOL_ORIGINS, TRUST_LEVELS, } from './types.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound and outbound guardrail primitives: sanitization, injection and sensitive detection,
|
|
3
|
+
* canary egress gates, egress policy and public error mapping. App-specific policy copy stays host-owned.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export { bindCanary, createCanaryStreamGate, eventHasCanary, isStreamedCanaryEvent, mintCanary, OMIT_CANARY, redactCanary, scanTextForCanaryLeak, USER_CLOSE, USER_OPEN, wrapUserData, } from './canary.js';
|
|
9
|
+
export { createCanaryGateSession, filterCanaryGatedEvents } from './canary-gate.js';
|
|
10
|
+
export { collectEgressHits, hitRules, runEnforcer, standardEgressEnforce, } from './egress.js';
|
|
11
|
+
export { egressPolicy } from './egress-policy.js';
|
|
12
|
+
export { describeError, ERROR_KINDS, errorKind, isAbortError, isTimeoutError, kindOfHttpStatus, publicError, TheoremError, throwIfAborted, toErrorEvent, withPublicWording, } from './error.js';
|
|
13
|
+
export { errorCopiesSchema, errorKindSchema, guardrailEventSchema } from './event-schemas.js';
|
|
14
|
+
export { guardrailFromHits, guardrailFromVerdict, guardrailTurnEvent, projectGuardrailTurnEvent, } from './events.js';
|
|
15
|
+
export { hitFromSpan, projectGuardrailEvent, } from './hits.js';
|
|
16
|
+
export { injectionSpans } from './injection.js';
|
|
17
|
+
export { CLIENT_LEXICON_KEYS, LEXICON_KEYS, lexiconDefault, lexiconText, overrideLexicon, resetLexicon, } from './lexicon.js';
|
|
18
|
+
export { abortLiveOutboundTurn, createLiveOutboundGateSession, finalizeLiveOutboundTurn, processLiveOutboundBatch, } from './live-outbound-gate.js';
|
|
19
|
+
export { detectionForTrust, resolveGuardrailPolicy } from './policy.js';
|
|
20
|
+
export { createOutboundProgressiveGate, createProgressiveYieldGate, DEFAULT_HOLDBACK, LIVE_DEFAULT_HOLDBACK, } from './progressive-yield.js';
|
|
21
|
+
export { PROMPT_ECHO_WORDS, scanTextForPromptEcho } from './prompt-echo.js';
|
|
22
|
+
export { clientIp, quotaExhausted, releaseSlot, resetSlots, skipQuota, takeSlot, } from './quota.js';
|
|
23
|
+
export { DIRECTIVE_RULES, EGRESS_RULES, NETWORK_RULES, SANITIZE_RULES, TOOL_RULES, } from './rules.js';
|
|
24
|
+
export { detectionForProfile, detectText, redactSensitiveOnly, sanitizeHistory, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, sanitizeTurnRequestWithEvents, } from './sanitize.js';
|
|
25
|
+
export { SENSITIVE_GROUPS, sensitiveSpans } from './sensitive.js';
|
|
26
|
+
export { scanTextOf, textForScan } from './serialize.js';
|
|
27
|
+
export { advisoryLevel, directiveHits, looksDirective, } from './tool-directives.js';
|
|
28
|
+
export { checkTaintGate, composeToolText, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint, TOOL_CLOSE, toolCallEvent, wrapToolData, } from './tool-result.js';
|
|
29
|
+
export { ADVISORY_LEVELS, EGRESS_ON_BLOCK, GUARDRAIL_STAGES, SEVERITIES, TAINT_GATES, TOOL_ORIGINS, TRUST_LEVELS, } from './types.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { NetworkGuardrailSpec } from './types.js';
|
|
2
|
+
export declare function isLocalhostName(hostname: string): boolean;
|
|
3
|
+
export declare function isPrivateOrLocalAddress(ipOrHost: string): boolean;
|
|
4
|
+
/** Throws a `TheoremError` when the URL is blocked. */
|
|
5
|
+
export declare function assertSafeUrl(urlStr: string, policy?: NetworkGuardrailSpec): URL;
|
|
6
|
+
export interface GuardedFetchOptions {
|
|
7
|
+
policy?: NetworkGuardrailSpec;
|
|
8
|
+
/** Follow redirects, clearing each hop; when false a redirect comes back as the response. */
|
|
9
|
+
followRedirects: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Headers for the first request's origin only: credentials and host-configured
|
|
12
|
+
* headers. Once a redirect leaves that origin they are never sent again.
|
|
13
|
+
*/
|
|
14
|
+
originBoundHeaders?: Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves each hop's host name before it is fetched; the hop is refused when
|
|
17
|
+
* any address is private or the name does not resolve. Skipped for literal
|
|
18
|
+
* addresses and wherever `policy` already permits private targets.
|
|
19
|
+
*/
|
|
20
|
+
resolveHost?: ResolveHost;
|
|
21
|
+
fetchFn?: typeof fetch;
|
|
22
|
+
/** Told how long each hop's checks took: its address, and its lookup when `resolveHost` is set. */
|
|
23
|
+
onCheck?: (ms: number) => void;
|
|
24
|
+
}
|
|
25
|
+
/** A host name's IPv4 and IPv6 addresses; empty when the name does not exist. */
|
|
26
|
+
export type ResolveHost = (hostname: string, signal?: AbortSignal) => Promise<readonly string[]>;
|
|
27
|
+
/** Every redirect hop must clear `policy`; throws a `TheoremError` (`blocked`) when one is refused. */
|
|
28
|
+
export declare function fetchGuarded(url: string, init: Omit<RequestInit, 'redirect' | 'body'> & {
|
|
29
|
+
body?: string;
|
|
30
|
+
}, options: GuardedFetchOptions): Promise<Response>;
|
|
31
|
+
export interface DnsOverHttpsOptions {
|
|
32
|
+
/** A DNS JSON API endpoint, e.g. `https://cloudflare-dns.com/dns-query`. */
|
|
33
|
+
endpoint: string;
|
|
34
|
+
fetchFn?: typeof fetch;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A {@link ResolveHost} over DNS-over-HTTPS (the DNS JSON API), for runtimes
|
|
38
|
+
* with `fetch` but no DNS lookup, such as Cloudflare Workers. It asks the
|
|
39
|
+
* endpoint, not the machine's resolver, so names only an internal resolver
|
|
40
|
+
* knows are not seen; a server host should resolve through its own DNS.
|
|
41
|
+
*/
|
|
42
|
+
export declare function dnsOverHttpsResolver(options: DnsOverHttpsOptions): ResolveHost;
|