@theoremjs/agents 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +545 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +79 -0
- package/esm/mod.js +49 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +480 -0
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +241 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +26 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +67 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +5 -0
- package/esm/src/evals/attachments.js +55 -0
- package/esm/src/evals/breakdown.d.ts +30 -0
- package/esm/src/evals/breakdown.js +69 -0
- package/esm/src/evals/graders/answer.d.ts +16 -0
- package/esm/src/evals/graders/answer.js +134 -0
- package/esm/src/evals/graders/code.d.ts +40 -0
- package/esm/src/evals/graders/code.js +184 -0
- package/esm/src/evals/graders/judge.d.ts +24 -0
- package/esm/src/evals/graders/judge.js +367 -0
- package/esm/src/evals/graders/latency.d.ts +6 -0
- package/esm/src/evals/graders/latency.js +82 -0
- package/esm/src/evals/graders/live.d.ts +14 -0
- package/esm/src/evals/graders/live.js +42 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +91 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +19 -0
- package/esm/src/evals/graders/transcript.js +202 -0
- package/esm/src/evals/mod.d.ts +34 -0
- package/esm/src/evals/mod.js +22 -0
- package/esm/src/evals/record.d.ts +41 -0
- package/esm/src/evals/record.js +107 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +75 -0
- package/esm/src/evals/run.js +418 -0
- package/esm/src/evals/suite.d.ts +28 -0
- package/esm/src/evals/suite.js +97 -0
- package/esm/src/evals/summary.d.ts +35 -0
- package/esm/src/evals/summary.js +31 -0
- package/esm/src/evals/trial.d.ts +14 -0
- package/esm/src/evals/trial.js +135 -0
- package/esm/src/evals/types.d.ts +169 -0
- package/esm/src/evals/types.js +113 -0
- package/esm/src/evals/verdict.d.ts +23 -0
- package/esm/src/evals/verdict.js +48 -0
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +22 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +146 -0
- package/esm/src/guardrails/canary.js +974 -0
- package/esm/src/guardrails/compile-egress.d.ts +12 -0
- package/esm/src/guardrails/compile-egress.js +12 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +24 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +305 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +199 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +5 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +120 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +15 -0
- package/esm/src/guardrails/corpus/live-attacks.js +229 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +36 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +12 -0
- package/esm/src/guardrails/egress-automata.js +25582 -0
- package/esm/src/guardrails/egress-compiler.d.ts +55 -0
- package/esm/src/guardrails/egress-compiler.js +431 -0
- package/esm/src/guardrails/egress-patterns.d.ts +26 -0
- package/esm/src/guardrails/egress-patterns.js +36 -0
- package/esm/src/guardrails/egress-stream.d.ts +123 -0
- package/esm/src/guardrails/egress-stream.js +774 -0
- package/esm/src/guardrails/egress-urls.d.ts +86 -0
- package/esm/src/guardrails/egress-urls.js +909 -0
- package/esm/src/guardrails/egress.d.ts +46 -0
- package/esm/src/guardrails/egress.js +124 -0
- package/esm/src/guardrails/error.d.ts +31 -0
- package/esm/src/guardrails/error.js +96 -0
- package/esm/src/guardrails/event-schemas.d.ts +100 -0
- package/esm/src/guardrails/event-schemas.js +48 -0
- package/esm/src/guardrails/events.d.ts +13 -0
- package/esm/src/guardrails/events.js +45 -0
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +14 -0
- package/esm/src/guardrails/hits.js +30 -0
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +20 -0
- package/esm/src/guardrails/injection-patterns.js +126 -0
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +30 -0
- package/esm/src/guardrails/injection.js +460 -0
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +874 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +55 -0
- package/esm/src/guardrails/live-outbound-gate.js +298 -0
- package/esm/src/guardrails/mod.d.ts +54 -0
- package/esm/src/guardrails/mod.js +34 -0
- package/esm/src/guardrails/network.d.ts +46 -0
- package/esm/src/guardrails/network.js +330 -0
- package/esm/src/guardrails/normalize.d.ts +20 -0
- package/esm/src/guardrails/normalize.js +165 -0
- package/esm/src/guardrails/policy.d.ts +4 -0
- package/esm/src/guardrails/policy.js +21 -0
- package/esm/src/guardrails/progressive-yield.d.ts +110 -0
- package/esm/src/guardrails/progressive-yield.js +281 -0
- package/esm/src/guardrails/prompt-echo.d.ts +40 -0
- package/esm/src/guardrails/prompt-echo.js +306 -0
- package/esm/src/guardrails/quota.d.ts +21 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +47 -0
- package/esm/src/guardrails/rules.js +47 -0
- package/esm/src/guardrails/sanitize.d.ts +40 -0
- package/esm/src/guardrails/sanitize.js +160 -0
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +22 -0
- package/esm/src/guardrails/sensitive.js +234 -0
- package/esm/src/guardrails/serialize.d.ts +15 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +11 -0
- package/esm/src/guardrails/testing.js +10 -0
- package/esm/src/guardrails/theorem-error.d.ts +21 -0
- package/esm/src/guardrails/theorem-error.js +54 -0
- package/esm/src/guardrails/thought-guard.d.ts +76 -0
- package/esm/src/guardrails/thought-guard.js +664 -0
- package/esm/src/guardrails/tool-directives.d.ts +38 -0
- package/esm/src/guardrails/tool-directives.js +195 -0
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +92 -0
- package/esm/src/guardrails/tool-result.js +272 -0
- package/esm/src/guardrails/types.d.ts +250 -0
- package/esm/src/guardrails/types.js +58 -0
- package/esm/src/host/client-turn.d.ts +36 -0
- package/esm/src/host/client-turn.js +80 -0
- package/esm/src/host/mint-trace.d.ts +29 -0
- package/esm/src/host/mint-trace.js +60 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +27 -0
- package/esm/src/host/reply.d.ts +13 -0
- package/esm/src/host/reply.js +41 -0
- package/esm/src/interface/blocks.d.ts +11 -0
- package/esm/src/interface/blocks.js +283 -0
- package/esm/src/interface/composer-actions.d.ts +24 -0
- package/esm/src/interface/composer-actions.js +33 -0
- package/esm/src/interface/draft.d.ts +20 -0
- package/esm/src/interface/draft.js +39 -0
- package/esm/src/interface/from-profile.d.ts +24 -0
- package/esm/src/interface/from-profile.js +179 -0
- package/esm/src/interface/history.d.ts +46 -0
- package/esm/src/interface/history.js +278 -0
- package/esm/src/interface/inputs.d.ts +11 -0
- package/esm/src/interface/inputs.js +67 -0
- package/esm/src/interface/mod.d.ts +33 -0
- package/esm/src/interface/mod.js +22 -0
- package/esm/src/interface/models.d.ts +26 -0
- package/esm/src/interface/models.js +50 -0
- package/esm/src/interface/pending.d.ts +57 -0
- package/esm/src/interface/pending.js +152 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +237 -0
- package/esm/src/interface/session.d.ts +71 -0
- package/esm/src/interface/session.js +128 -0
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +32 -0
- package/esm/src/interface/tool-calls.js +127 -0
- package/esm/src/interface/tool-invoke.d.ts +6 -0
- package/esm/src/interface/tool-invoke.js +22 -0
- package/esm/src/interface/tool-media.d.ts +11 -0
- package/esm/src/interface/tool-media.js +113 -0
- package/esm/src/interface/types.d.ts +278 -0
- package/esm/src/interface/types.js +5 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +56 -0
- package/esm/src/kernel/auth/crypto.js +163 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +18 -0
- package/esm/src/kernel/auth/oauth.js +439 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +152 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +72 -0
- package/esm/src/kernel/default-scope.js +121 -0
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +71 -0
- package/esm/src/kernel/engine/compaction.js +203 -0
- package/esm/src/kernel/engine/decision.d.ts +43 -0
- package/esm/src/kernel/engine/decision.js +439 -0
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +19 -0
- package/esm/src/kernel/engine/live-inbound.js +44 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +15 -0
- package/esm/src/kernel/engine/live-ingress.js +42 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +508 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +29 -0
- package/esm/src/kernel/engine/runner/mod.js +625 -0
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +35 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +179 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +41 -0
- package/esm/src/kernel/engine/runner/state.d.ts +97 -0
- package/esm/src/kernel/engine/runner/state.js +50 -0
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +519 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +71 -0
- package/esm/src/kernel/engine/runner/stream.js +376 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +148 -0
- package/esm/src/kernel/engine/session/mod.d.ts +33 -0
- package/esm/src/kernel/engine/session/mod.js +1182 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +500 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +23 -0
- package/esm/src/kernel/engine/token-estimate.js +38 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +132 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +119 -0
- package/esm/src/kernel/engine/turn-trace.js +855 -0
- package/esm/src/kernel/engine/usage.d.ts +36 -0
- package/esm/src/kernel/engine/usage.js +151 -0
- package/esm/src/kernel/interaction-parts.d.ts +13 -0
- package/esm/src/kernel/interaction-parts.js +40 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +74 -0
- package/esm/src/kernel/mod.js +45 -0
- package/esm/src/kernel/profile-graph.d.ts +145 -0
- package/esm/src/kernel/profile-graph.js +158 -0
- package/esm/src/kernel/profile-presence.d.ts +18 -0
- package/esm/src/kernel/profile-presence.js +158 -0
- package/esm/src/kernel/profile-scope.d.ts +40 -0
- package/esm/src/kernel/profile-scope.js +274 -0
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +46 -0
- package/esm/src/kernel/registry/attachments.js +220 -0
- package/esm/src/kernel/registry/catalog.d.ts +25 -0
- package/esm/src/kernel/registry/catalog.js +85 -0
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +12 -0
- package/esm/src/kernel/registry/ingress.js +179 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +15 -0
- package/esm/src/kernel/registry/kernel-registry.js +15 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +10 -0
- package/esm/src/kernel/registry/profiles.d.ts +116 -0
- package/esm/src/kernel/registry/profiles.js +773 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +34 -0
- package/esm/src/kernel/registry/resolve.d.ts +17 -0
- package/esm/src/kernel/registry/resolve.js +238 -0
- package/esm/src/kernel/registry/schemas.d.ts +12 -0
- package/esm/src/kernel/registry/schemas.js +27 -0
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +32 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +14 -0
- package/esm/src/kernel/registry/vault.js +1 -0
- package/esm/src/kernel/schema.d.ts +226 -0
- package/esm/src/kernel/schema.js +895 -0
- package/esm/src/kernel/scope.d.ts +29 -0
- package/esm/src/kernel/scope.js +45 -0
- package/esm/src/kernel/stages.d.ts +176 -0
- package/esm/src/kernel/stages.js +431 -0
- package/esm/src/kernel/stop.d.ts +116 -0
- package/esm/src/kernel/stop.js +137 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +22 -0
- package/esm/src/kernel/tools/activity-label.js +435 -0
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +66 -0
- package/esm/src/kernel/tools/events.js +184 -0
- package/esm/src/kernel/tools/execute.d.ts +100 -0
- package/esm/src/kernel/tools/execute.js +1173 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +60 -0
- package/esm/src/kernel/tools/gate-answer.js +65 -0
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +17 -0
- package/esm/src/kernel/tools/harness.js +43 -0
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +32 -0
- package/esm/src/kernel/tools/invoke.js +282 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +23 -0
- package/esm/src/kernel/tools/mcp-sessions.js +69 -0
- package/esm/src/kernel/tools/mod.d.ts +10 -0
- package/esm/src/kernel/tools/mod.js +7 -0
- package/esm/src/kernel/tools/model-text.d.ts +16 -0
- package/esm/src/kernel/tools/model-text.js +31 -0
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +15 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +11 -0
- package/esm/src/kernel/tools/project.js +55 -0
- package/esm/src/kernel/tools/registry.d.ts +27 -0
- package/esm/src/kernel/tools/registry.js +143 -0
- package/esm/src/kernel/tools/remote.d.ts +144 -0
- package/esm/src/kernel/tools/remote.js +1125 -0
- package/esm/src/kernel/tools/resolve.d.ts +31 -0
- package/esm/src/kernel/tools/resolve.js +267 -0
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +95 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +19 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +116 -0
- package/esm/src/kernel/tools/stage-run.js +198 -0
- package/esm/src/kernel/tools/types.d.ts +497 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +776 -0
- package/esm/src/kernel/turn-events.js +543 -0
- package/esm/src/kernel/types.d.ts +1025 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +4 -0
- package/esm/src/kernel/util/base64.js +15 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +2 -0
- package/esm/src/kernel/util/record.js +4 -0
- package/esm/src/observability/destinations.d.ts +14 -0
- package/esm/src/observability/destinations.js +43 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +110 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +71 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +30 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +17 -0
- package/esm/src/observability/policy.js +73 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +64 -0
- package/esm/src/observability/spans.d.ts +22 -0
- package/esm/src/observability/spans.js +72 -0
- package/esm/src/observability/trace-catalog.d.ts +128 -0
- package/esm/src/observability/trace-catalog.js +906 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +228 -0
- package/esm/src/observability/trace-schema.d.ts +57 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +14 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +98 -0
- package/esm/src/observability/trace-span.js +201 -0
- package/esm/src/observability/trace.d.ts +13 -0
- package/esm/src/observability/trace.js +37 -0
- package/esm/src/observability/types.d.ts +109 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +9 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +13 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +119 -0
- package/esm/src/presets/google.js +197 -0
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +11 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +26 -0
- package/esm/src/presets/openrouter.js +31 -0
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +105 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +27 -0
- package/esm/src/providers/google/interactions/framing.js +304 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +23 -0
- package/esm/src/providers/google/interactions/stream.js +230 -0
- package/esm/src/providers/google/live/framing.d.ts +61 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/stream.d.ts +13 -0
- package/esm/src/providers/google/live/stream.js +57 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +4 -0
- package/esm/src/providers/google/urls.js +4 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +32 -0
- package/esm/src/providers/mod.js +23 -0
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +15 -0
- package/esm/src/providers/openrouter/image.js +34 -0
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/retry.d.ts +17 -0
- package/esm/src/providers/shared/retry.js +90 -0
- package/esm/src/providers/shared/sse.d.ts +6 -0
- package/esm/src/providers/shared/sse.js +93 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +24 -0
- package/esm/src/providers/shared/tool-args.js +88 -0
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +51 -0
- package/esm/src/providers/types.js +2 -0
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +46 -0
- package/esm/src/surface/formats.js +178 -0
- package/esm/src/surface/mod.d.ts +16 -0
- package/esm/src/surface/mod.js +12 -0
- package/esm/src/surface/runtime.d.ts +44 -0
- package/esm/src/surface/runtime.js +441 -0
- package/esm/src/surface/tools.d.ts +9 -0
- package/esm/src/surface/tools.js +62 -0
- package/esm/src/surface/types.d.ts +110 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +100 -4
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { blobAt, mergeSpans, spansFromPatterns } from '../observability/spans.js';
|
|
2
|
+
import { BASE64_BLOB, HEX_BLOB, INJECTION_PATTERNS, PIPE_SEPARATED, SPACED_LETTERS, } from './injection-patterns.js';
|
|
3
|
+
import { REVERSED_INJECTION_PATTERNS } from './injection-reversed.js';
|
|
4
|
+
import { normalizedView, normalizeForDetection } from './normalize.js';
|
|
5
|
+
const TYPO_TARGETS = [
|
|
6
|
+
'ignore',
|
|
7
|
+
'bypass',
|
|
8
|
+
'override',
|
|
9
|
+
'reveal',
|
|
10
|
+
'delete',
|
|
11
|
+
'system',
|
|
12
|
+
'prompt',
|
|
13
|
+
'instructions',
|
|
14
|
+
'safety',
|
|
15
|
+
'security',
|
|
16
|
+
'filters',
|
|
17
|
+
'rules',
|
|
18
|
+
'previous',
|
|
19
|
+
'guidelines',
|
|
20
|
+
'restrictions',
|
|
21
|
+
'disregard',
|
|
22
|
+
'forget',
|
|
23
|
+
'jailbreak',
|
|
24
|
+
'developer',
|
|
25
|
+
'disable',
|
|
26
|
+
'measures',
|
|
27
|
+
'output',
|
|
28
|
+
];
|
|
29
|
+
/** The shortest target a one-edit misspelling is read as: a shorter word has too many real neighbours. */
|
|
30
|
+
const EDIT_TARGET_MIN = 6;
|
|
31
|
+
/**
|
|
32
|
+
* Real words one edit from a target (`forgot`, `safely`, `filter`): the dictionary's, and the
|
|
33
|
+
* inflections it leaves out. They are words, not misspellings.
|
|
34
|
+
*/
|
|
35
|
+
const REAL_WORDS = new Set([
|
|
36
|
+
'instruction',
|
|
37
|
+
'filter',
|
|
38
|
+
'guideline',
|
|
39
|
+
'restriction',
|
|
40
|
+
'measure',
|
|
41
|
+
'ignote',
|
|
42
|
+
'bypast',
|
|
43
|
+
'overrode',
|
|
44
|
+
'overrife',
|
|
45
|
+
'overripe',
|
|
46
|
+
'overrise',
|
|
47
|
+
'overrude',
|
|
48
|
+
'overside',
|
|
49
|
+
'overtide',
|
|
50
|
+
'overwide',
|
|
51
|
+
'redeal',
|
|
52
|
+
'reheal',
|
|
53
|
+
'repeal',
|
|
54
|
+
'reseal',
|
|
55
|
+
'reveil',
|
|
56
|
+
'revel',
|
|
57
|
+
'delate',
|
|
58
|
+
'deplete',
|
|
59
|
+
'safely',
|
|
60
|
+
'fitters',
|
|
61
|
+
'precious',
|
|
62
|
+
'premious',
|
|
63
|
+
'prepious',
|
|
64
|
+
'forge',
|
|
65
|
+
'forged',
|
|
66
|
+
'forger',
|
|
67
|
+
'forges',
|
|
68
|
+
'forgot',
|
|
69
|
+
'forlet',
|
|
70
|
+
'forpet',
|
|
71
|
+
'forset',
|
|
72
|
+
'gorget',
|
|
73
|
+
'developed',
|
|
74
|
+
'measured',
|
|
75
|
+
'measurer',
|
|
76
|
+
'outcut',
|
|
77
|
+
'outhut',
|
|
78
|
+
'outjut',
|
|
79
|
+
]);
|
|
80
|
+
const TYPO_TARGET_SET = new Set(TYPO_TARGETS);
|
|
81
|
+
/** The longest word a typo can be read from: a target with a letter added. */
|
|
82
|
+
const TYPO_WORD_MAX = Math.max(...TYPO_TARGETS.map((target) => target.length)) + 1;
|
|
83
|
+
/** Pipe evasion only when the first token is a known injection lead-in. */
|
|
84
|
+
const PIPE_HEAD_VERBS = /^(ignore|disregard|forget|bypass|reveal|show|repeat|output|disable|override|new|jailbreak|pretend|act|enter|activate|void|supersede|do)$/i;
|
|
85
|
+
// why: Bounded, so a long run of letters can't overflow the regex engine's stack; no longer word can be a typo.
|
|
86
|
+
const WORD = new RegExp(`\\b[A-Za-z]{4,${TYPO_WORD_MAX}}\\b`, 'g');
|
|
87
|
+
const PRINTABLE_MIN = 0.85;
|
|
88
|
+
const CODE_TAB = 9;
|
|
89
|
+
const CODE_LF = 10;
|
|
90
|
+
const CODE_CR = 13;
|
|
91
|
+
const CODE_SPACE = 32;
|
|
92
|
+
const CODE_DEL = 127;
|
|
93
|
+
const HEX_RADIX = 16;
|
|
94
|
+
const HEX_STEP = 2;
|
|
95
|
+
const ROT13_OFFSET = 13;
|
|
96
|
+
const ALPHA_COUNT = 26;
|
|
97
|
+
const UPPER_A_CODE = 65;
|
|
98
|
+
const LOWER_A_CODE = 97;
|
|
99
|
+
function injectionSpansOn(text) {
|
|
100
|
+
return spansFromPatterns(text, INJECTION_PATTERNS, 'injection');
|
|
101
|
+
}
|
|
102
|
+
function sortedLetters(value) {
|
|
103
|
+
return [...value].sort().join('');
|
|
104
|
+
}
|
|
105
|
+
function firstLast(word) {
|
|
106
|
+
return { first: word.at(0), last: word.at(-1) };
|
|
107
|
+
}
|
|
108
|
+
function isTypoglycemia(word, target) {
|
|
109
|
+
if (word.length !== target.length) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const lower = word.toLowerCase();
|
|
113
|
+
if (lower === target) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const wordEnds = firstLast(lower);
|
|
117
|
+
const targetEnds = firstLast(target);
|
|
118
|
+
if (wordEnds.first !== targetEnds.first || wordEnds.last !== targetEnds.last) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return sortedLetters(lower.slice(1, -1)) === sortedLetters(target.slice(1, -1));
|
|
122
|
+
}
|
|
123
|
+
/** Whether one insertion, deletion, substitution, or swap of two neighbours turns `word` into `target`. */
|
|
124
|
+
function isOneEdit(word, target) {
|
|
125
|
+
const wordEnd = word.length - 1;
|
|
126
|
+
const targetEnd = target.length - 1;
|
|
127
|
+
if (word[0] !== target[0] && word[wordEnd] !== target[targetEnd]) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const short = Math.min(word.length, target.length);
|
|
131
|
+
let head = 0;
|
|
132
|
+
while (head < short && word[head] === target[head]) {
|
|
133
|
+
head += 1;
|
|
134
|
+
}
|
|
135
|
+
let tail = 0;
|
|
136
|
+
while (tail < short - head && word[wordEnd - tail] === target[targetEnd - tail]) {
|
|
137
|
+
tail += 1;
|
|
138
|
+
}
|
|
139
|
+
if (word.length !== target.length) {
|
|
140
|
+
return head + tail === short;
|
|
141
|
+
}
|
|
142
|
+
const differing = short - head - tail;
|
|
143
|
+
return (differing === 1 ||
|
|
144
|
+
(differing === 2 && word[head] === target[head + 1] && word[head + 1] === target[head]));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Whether `word` is `target` misspelt by one edit. A real word is not: one of
|
|
148
|
+
* {@linkcode REAL_WORDS}, or the target with a letter added at its end
|
|
149
|
+
* (`ignored`, `systems`).
|
|
150
|
+
*/
|
|
151
|
+
function isMisspelling(word, target) {
|
|
152
|
+
return isOneEdit(word, target) && !REAL_WORDS.has(word) && word.slice(0, -1) !== target;
|
|
153
|
+
}
|
|
154
|
+
/** For a word length, the targets a scramble of that length can be, and the targets a one-edit misspelling of it can be. */
|
|
155
|
+
const TARGETS_BY_LENGTH = new Map();
|
|
156
|
+
for (let length = 4; length <= TYPO_WORD_MAX; length += 1) {
|
|
157
|
+
TARGETS_BY_LENGTH.set(length, {
|
|
158
|
+
same: TYPO_TARGETS.filter((target) => target.length === length),
|
|
159
|
+
near: TYPO_TARGETS.filter((target) => target.length >= EDIT_TARGET_MIN && Math.abs(target.length - length) <= 1),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** The target `word` is read as, or `undefined`: a scramble of one first, then a one-edit misspelling. */
|
|
163
|
+
function targetOf(word) {
|
|
164
|
+
const targets = TARGETS_BY_LENGTH.get(word.length);
|
|
165
|
+
if (targets === undefined) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
const lower = word.toLowerCase();
|
|
169
|
+
if (TYPO_TARGET_SET.has(lower)) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
return (targets.same.find((target) => isTypoglycemia(lower, target)) ??
|
|
173
|
+
targets.near.find((target) => isMisspelling(lower, target)));
|
|
174
|
+
}
|
|
175
|
+
function typoFolds(text) {
|
|
176
|
+
const folds = [];
|
|
177
|
+
for (const match of text.matchAll(WORD)) {
|
|
178
|
+
const to = targetOf(match[0]);
|
|
179
|
+
if (to !== undefined) {
|
|
180
|
+
folds.push({ start: match.index, end: match.index + match[0].length, to });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return folds;
|
|
184
|
+
}
|
|
185
|
+
function applyFolds(text, folds) {
|
|
186
|
+
let out = '';
|
|
187
|
+
let at = 0;
|
|
188
|
+
for (const fold of folds) {
|
|
189
|
+
out += text.slice(at, fold.start) + fold.to;
|
|
190
|
+
at = fold.end;
|
|
191
|
+
}
|
|
192
|
+
return out + text.slice(at);
|
|
193
|
+
}
|
|
194
|
+
function typoNormalize(text) {
|
|
195
|
+
return applyFolds(text, typoFolds(text));
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* `typoNormalize(text)`, and for an index in it the index of `text` it stands
|
|
199
|
+
* for. A corrected word may be a letter longer or shorter than the word as
|
|
200
|
+
* written, so an index past the written word stands for its last letter.
|
|
201
|
+
*/
|
|
202
|
+
function typoFolded(text) {
|
|
203
|
+
const folds = typoFolds(text);
|
|
204
|
+
const at = (index) => {
|
|
205
|
+
let shift = 0;
|
|
206
|
+
for (const fold of folds) {
|
|
207
|
+
const start = fold.start + shift;
|
|
208
|
+
if (index < start) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
if (index < start + fold.to.length) {
|
|
212
|
+
return fold.start + Math.min(index - start, fold.end - fold.start - 1);
|
|
213
|
+
}
|
|
214
|
+
shift += fold.to.length - (fold.end - fold.start);
|
|
215
|
+
}
|
|
216
|
+
return index - shift;
|
|
217
|
+
};
|
|
218
|
+
return { text: applyFolds(text, folds), at };
|
|
219
|
+
}
|
|
220
|
+
function isMostlyPrintable(value) {
|
|
221
|
+
if (!value) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
let ok = 0;
|
|
225
|
+
for (const ch of value) {
|
|
226
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
227
|
+
const control = code === CODE_TAB || code === CODE_LF || code === CODE_CR;
|
|
228
|
+
const visible = code >= CODE_SPACE && code < CODE_DEL;
|
|
229
|
+
if (control || visible) {
|
|
230
|
+
ok += 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return ok / value.length >= PRINTABLE_MIN;
|
|
234
|
+
}
|
|
235
|
+
function tryBase64(blob) {
|
|
236
|
+
try {
|
|
237
|
+
return atob(blob);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function decodedHits(decoded) {
|
|
244
|
+
if (!isMostlyPrintable(decoded)) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
if (injectionSpansOn(decoded).length > 0)
|
|
248
|
+
return true;
|
|
249
|
+
const doubleDecoded = tryBase64(decoded);
|
|
250
|
+
if (doubleDecoded &&
|
|
251
|
+
isMostlyPrintable(doubleDecoded) &&
|
|
252
|
+
injectionSpansOn(doubleDecoded).length > 0) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
function tryHex(blob) {
|
|
258
|
+
const hex = blob.replaceAll(/\s/g, '');
|
|
259
|
+
if (hex.length % HEX_STEP !== 0) {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
let out = '';
|
|
263
|
+
for (let i = 0; i < hex.length; i += HEX_STEP) {
|
|
264
|
+
out += String.fromCodePoint(Number.parseInt(hex.slice(i, i + HEX_STEP), HEX_RADIX));
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
function base64Hit(blob) {
|
|
269
|
+
const decoded = tryBase64(blob);
|
|
270
|
+
return decoded !== undefined && decodedHits(decoded);
|
|
271
|
+
}
|
|
272
|
+
function hexHit(blob) {
|
|
273
|
+
const decoded = tryHex(blob);
|
|
274
|
+
return decoded !== undefined && decodedHits(decoded);
|
|
275
|
+
}
|
|
276
|
+
function spacedHit(blob) {
|
|
277
|
+
const collapsed = blob.replaceAll(' ', '');
|
|
278
|
+
return injectionSpansOn(`${collapsed} previous instructions`).length > 0;
|
|
279
|
+
}
|
|
280
|
+
function pipeHit(blob) {
|
|
281
|
+
const head = blob.split('|')[0]?.toLowerCase();
|
|
282
|
+
if (!head || !PIPE_HEAD_VERBS.test(head))
|
|
283
|
+
return false;
|
|
284
|
+
return injectionSpansOn(blob.replaceAll('|', ' ')).length > 0;
|
|
285
|
+
}
|
|
286
|
+
/** Blob patterns whose match is a hit only when the blob decodes to an injection. */
|
|
287
|
+
const INJECTION_BLOBS = [
|
|
288
|
+
{ pattern: BASE64_BLOB, hit: base64Hit },
|
|
289
|
+
{ pattern: HEX_BLOB, hit: hexHit },
|
|
290
|
+
{ pattern: SPACED_LETTERS, hit: spacedHit },
|
|
291
|
+
{ pattern: PIPE_SEPARATED, hit: pipeHit },
|
|
292
|
+
];
|
|
293
|
+
function blobSpans(text) {
|
|
294
|
+
const spans = [];
|
|
295
|
+
for (const { pattern, hit } of INJECTION_BLOBS) {
|
|
296
|
+
for (const match of text.matchAll(pattern)) {
|
|
297
|
+
const found = blobAt(match);
|
|
298
|
+
if (found && hit(found.blob)) {
|
|
299
|
+
spans.push({ start: found.index, end: found.index + found.blob.length, kind: 'injection' });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return spans;
|
|
304
|
+
}
|
|
305
|
+
function tryRot13(text) {
|
|
306
|
+
return text.replace(/[a-zA-Z]/g, (c) => {
|
|
307
|
+
const base = c.charCodeAt(0) < LOWER_A_CODE ? UPPER_A_CODE : LOWER_A_CODE;
|
|
308
|
+
return String.fromCharCode(((c.charCodeAt(0) - base + ROT13_OFFSET) % ALPHA_COUNT) + base);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
const URL_ESCAPES = /(?:%[0-9A-Fa-f]{2})+/g;
|
|
312
|
+
const UTF8 = new TextDecoder();
|
|
313
|
+
/** Each run of `%XX` escapes decoded on its own, so one stray `%` cannot switch decoding off. */
|
|
314
|
+
function decodeUrlRuns(text) {
|
|
315
|
+
return text.replace(URL_ESCAPES, (run) => {
|
|
316
|
+
const bytes = new Uint8Array(run.length / 3);
|
|
317
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
318
|
+
bytes[i] = Number.parseInt(run.slice(i * 3 + 1, i * 3 + 3), HEX_RADIX);
|
|
319
|
+
}
|
|
320
|
+
return UTF8.decode(bytes);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function tryUrlDecode(text) {
|
|
324
|
+
if (!text.includes('%'))
|
|
325
|
+
return undefined;
|
|
326
|
+
const decoded = decodeUrlRuns(text);
|
|
327
|
+
return decoded !== text ? decoded : undefined;
|
|
328
|
+
}
|
|
329
|
+
const LEET_MAP = {
|
|
330
|
+
'0': 'o',
|
|
331
|
+
'1': 'i',
|
|
332
|
+
'3': 'e',
|
|
333
|
+
'4': 'a',
|
|
334
|
+
'5': 's',
|
|
335
|
+
'7': 't',
|
|
336
|
+
'8': 'b',
|
|
337
|
+
'@': 'a',
|
|
338
|
+
'!': 'i',
|
|
339
|
+
};
|
|
340
|
+
const LEET_CHARS = /[013457@!]/g;
|
|
341
|
+
function tryLeet(text) {
|
|
342
|
+
if (!LEET_CHARS.test(text))
|
|
343
|
+
return undefined;
|
|
344
|
+
LEET_CHARS.lastIndex = 0;
|
|
345
|
+
const decoded = text.replace(LEET_CHARS, (c) => LEET_MAP[c] ?? c);
|
|
346
|
+
return decoded !== text ? decoded : undefined;
|
|
347
|
+
}
|
|
348
|
+
/** Matches found in a rewrite, each placed on the stretch of the text as written it was read from. */
|
|
349
|
+
function placed(spans, view) {
|
|
350
|
+
return spans.map((span) => ({
|
|
351
|
+
...span,
|
|
352
|
+
start: view.start(span.start),
|
|
353
|
+
end: view.end(span.end - 1),
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
/** The matches in the text typo-folded, as indexes of the folded text, and the way back from it. */
|
|
357
|
+
function typoSpans(text) {
|
|
358
|
+
const folded = typoFolded(text);
|
|
359
|
+
return {
|
|
360
|
+
spans: folded.text === text ? [] : injectionSpansOn(folded.text),
|
|
361
|
+
view: { text: folded.text, start: folded.at, end: (index) => folded.at(index) + 1 },
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
function unicodeView(text) {
|
|
365
|
+
const view = normalizedView(text);
|
|
366
|
+
return {
|
|
367
|
+
text: view.text,
|
|
368
|
+
start: (index) => view.start[index] ?? text.length,
|
|
369
|
+
end: (index) => view.end[index] ?? text.length,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/** `decodeUrlRuns(text)`: a decoded character stands for the whole run of escapes it came from. */
|
|
373
|
+
function urlView(text) {
|
|
374
|
+
const start = [];
|
|
375
|
+
const end = [];
|
|
376
|
+
let decoded = '';
|
|
377
|
+
let last = 0;
|
|
378
|
+
const keep = (to) => {
|
|
379
|
+
for (let i = last; i < to; i += 1) {
|
|
380
|
+
start.push(i);
|
|
381
|
+
end.push(i + 1);
|
|
382
|
+
}
|
|
383
|
+
decoded += text.slice(last, to);
|
|
384
|
+
};
|
|
385
|
+
for (const match of text.matchAll(URL_ESCAPES)) {
|
|
386
|
+
keep(match.index);
|
|
387
|
+
const run = decodeUrlRuns(match[0]);
|
|
388
|
+
last = match.index + match[0].length;
|
|
389
|
+
for (let i = 0; i < run.length; i += 1) {
|
|
390
|
+
start.push(match.index);
|
|
391
|
+
end.push(last);
|
|
392
|
+
}
|
|
393
|
+
decoded += run;
|
|
394
|
+
}
|
|
395
|
+
keep(text.length);
|
|
396
|
+
return {
|
|
397
|
+
text: decoded,
|
|
398
|
+
start: (index) => start[index] ?? text.length,
|
|
399
|
+
end: (index) => end[index] ?? text.length,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
/** A rewrite of a rewrite: `inner` is a view of `outer.text`. */
|
|
403
|
+
function through(inner, outer) {
|
|
404
|
+
return {
|
|
405
|
+
text: inner.text,
|
|
406
|
+
start: (index) => outer.start(inner.start(index)),
|
|
407
|
+
end: (index) => outer.end(inner.end(index) - 1),
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function urlSpans(text) {
|
|
411
|
+
const decoded = tryUrlDecode(text);
|
|
412
|
+
const spans = decoded === undefined ? [] : injectionSpansOn(decoded);
|
|
413
|
+
return spans.length > 0 ? placed(spans, urlView(text)) : [];
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* The matches in the text decoded: ROT13 and leet keep each character in its
|
|
417
|
+
* place, a URL-decoded match is placed through {@linkcode urlView}, and text
|
|
418
|
+
* written backwards is matched as written, by each pattern reversed
|
|
419
|
+
* (`REVERSED_INJECTION_PATTERNS`).
|
|
420
|
+
*/
|
|
421
|
+
function decodedTextSpans(text) {
|
|
422
|
+
const leet = tryLeet(text);
|
|
423
|
+
return [
|
|
424
|
+
...injectionSpansOn(tryRot13(text)),
|
|
425
|
+
...(leet === undefined ? [] : injectionSpansOn(leet)),
|
|
426
|
+
...urlSpans(text),
|
|
427
|
+
...spansFromPatterns(text, REVERSED_INJECTION_PATTERNS, 'injection'),
|
|
428
|
+
];
|
|
429
|
+
}
|
|
430
|
+
/** The matches in the text normalized, and in that typo-folded. The way back is built only when one of them matches. */
|
|
431
|
+
function unicodeSpans(text) {
|
|
432
|
+
const normalized = normalizeForDetection(text);
|
|
433
|
+
if (normalized === text) {
|
|
434
|
+
return [];
|
|
435
|
+
}
|
|
436
|
+
const spans = injectionSpansOn(normalized);
|
|
437
|
+
const typo = typoSpans(normalized);
|
|
438
|
+
if (spans.length === 0 && typo.spans.length === 0) {
|
|
439
|
+
return [];
|
|
440
|
+
}
|
|
441
|
+
const view = unicodeView(text);
|
|
442
|
+
return [...placed(spans, view), ...placed(typo.spans, through(typo.view, view))];
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* The spans of injection in the text, each stretch once. The text is read as
|
|
446
|
+
* written and in each rewrite of it: typo-folded, normalized, decoded, and its
|
|
447
|
+
* encoded blobs. A match in a rewrite is the stretch of the text as written it
|
|
448
|
+
* was read from, so text around a match stays.
|
|
449
|
+
*/
|
|
450
|
+
function injectionSpans(text) {
|
|
451
|
+
const typo = typoSpans(text);
|
|
452
|
+
return mergeSpans([
|
|
453
|
+
...injectionSpansOn(text),
|
|
454
|
+
...placed(typo.spans, typo.view),
|
|
455
|
+
...unicodeSpans(text),
|
|
456
|
+
...blobSpans(text),
|
|
457
|
+
...decodedTextSpans(text),
|
|
458
|
+
]);
|
|
459
|
+
}
|
|
460
|
+
export { decodeUrlRuns, INJECTION_BLOBS, injectionSpans, LEET_MAP, TYPO_TARGETS, tryLeet, tryRot13, typoFolded, typoNormalize, };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Values that fill a label template's `{param}` placeholders. */
|
|
2
|
+
export type LabelParams = Record<string, string | number>;
|
|
3
|
+
/** Keys are stable API. */
|
|
4
|
+
export declare const LABEL_KEYS: readonly ["provider.decision_failed", "provider.decision_unavailable", "provider.decision_model_missing", "provider.decision_ended", "provider.decision_images_off", "provider.decision_box_model", "provider.budget_exhausted", "provider.adapter_version", "provider.adapter_methods", "provider.adapter_schemas", "provider.fallback_slot", "provider.model_fallback_slot", "provider.host_model", "provider.turn_profile", "provider.model_binding_missing", "provider.session_closed", "provider.settled_call", "provider.session_unavailable", "provider.live_input", "provider.tool_cancel_missing", "provider.kernel_gate", "provider.event_invalid", "provider.response_identity", "provider.credential_resolution", "provider.credential_shape", "provider.stored_continuation", "provider.continuation_mismatch", "provider.continuation_contract", "provider.stateless_history", "provider.events_after_completion", "provider.duplicate_call", "provider.tool_cancel_live", "provider.complete_unavailable", "provider.parallel_tools", "provider.binding_identity", "provider.profile_type", "provider.event_type", "provider.feature", "provider.input_kind", "provider.output_kind", "provider.builtin", "provider.credential_missing", "provider.profile_configuration", "continue.instruction", "canary.bind_note", "user_data.note", "context.note", "taint.blocked", "taint.reason_steered", "taint.reason_tainted", "taint.destination_blocked", "taint.destination_confirm", "advisory.notice_elevated", "advisory.notice_high", "advisory.guidance", "attachments.too_many_files", "attachments.too_many_of_kind", "attachments.file_too_large", "attachments.turn_too_large", "attachments.not_accepted", "attachments.mime_not_allowed", "input.too_long", "attachments.limits_unconfigured", "quota.exhausted", "error.config", "error.request", "error.input", "error.action", "error.auth", "error.rate_limit", "error.unsupported", "error.unavailable", "error.bad_response", "error.network", "error.timeout", "error.safety", "error.blocked", "error.declined", "error.failed", "error.cancelled", "error.internal", "repair.default_guidance", "repair.items_guidance", "repair.prompt_header", "repair.prompt_intro", "repair.prompt_instructions", "repair.history_heading", "repair.section_previous_output", "repair.section_validator_rejection", "repair.section_repair_guidance", "repair.section_instructions", "compaction.request", "compaction.tool_call", "compaction.tool_result", "decision.box_image", "detect.blocked", "detect.call_blocked", "detect.output_blocked", "detect.shown_blocked", "detect.hint.ids", "detect.hint.financial", "detect.hint.network", "detect.hint.credentials", "detect.hint.injection", "detect.hint.tool_instructions", "detect.hint.canary_leak", "detect.hint.prompt_leak", "detect.hint.marker_leak", "detect.hint.ungiven_images", "detect.hint.ungiven_links", "detect.hint.tool_leak", "detect.hint.own", "egress.default_repair_guidance", "egress.refusal", "egress.refusal_cut", "egress.rejection", "egress.rejection_found", "egress.hint_unscannable", "egress.hint_provider_tool_leak", "thought.omitted_image", "thought.omitted_link", "thought.omitted_instructions", "session.abandon_gated", "session.tool_denied", "session.tool_aborted", "session.sign_in", "sign_in.link", "sign_in.pending", "sign_in.done", "sign_in.declined", "sign_in.expired", "sign_in.out_of_scope", "session.gate_expired", "session.provider_state_unowned", "session.conversation_unknown", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "composer.model", "composer.effort", "tool.awaiting_user", "tool.completed_hidden", "tool.t2_loader_needs_snapshot", "tool.t2_loader_shape", "tool.t2_loader_output_invalid", "tool.execution_uncertain", "tool.input_invalid", "tool.input_invalid_after_mutate", "tool.output_invalid_after_mutate", "tool.handler_no_output", "tool.did_not_run", "tool.page_no_answer", "tool.page_timed_out", "tool.output_invalid", "tool.not_loaded_t2", "tool.wait_unknown", "tool.wait_cycle", "tool.not_visible", "tool.builtin_not_enabled", "tool.provider_native", "tool.not_registered", "tool.builtin_needs_snapshot", "tool.not_allowed", "tool.not_eligible", "tool.unsupported_type", "tool.agent_call_limit", "tool.agent_failed", "tool.activity_failed", "protocol.not_served", "protocol.profile_type", "protocol.options", "protocol.option_clash", "protocol.base_options", "protocol.id_clash", "protocol.ws_headers", "protocol.builtin_unwritten", "protocol.provider_missing", "protocol.connection", "protocol.part_schema", "protocol.part_invalid", "protocol.key_invalid", "protocol.no_key", "protocol.reply_shape", "protocol.endpoint_url", "protocol.endpoint_host", "protocol.http", "protocol.no_operation", "protocol.definition", "protocol.provider_id_clash", "protocol.history_needed"];
|
|
5
|
+
/** One of {@linkcode LABEL_KEYS}. */
|
|
6
|
+
export type LabelKey = (typeof LABEL_KEYS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* The keys a browser client words or writes: what the user reads (errors,
|
|
9
|
+
* attachment and voice problems, session states) and the tool lines the client
|
|
10
|
+
* puts into history. Only these overrides travel to the browser; the rest
|
|
11
|
+
* (repair prompts, canary, taint, egress) stay on the host.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CLIENT_LABEL_KEYS: readonly ["attachments.too_many_files", "attachments.too_many_of_kind", "attachments.file_too_large", "attachments.turn_too_large", "attachments.not_accepted", "attachments.mime_not_allowed", "input.too_long", "attachments.limits_unconfigured", "detect.blocked", "error.config", "error.request", "error.input", "error.action", "error.auth", "error.rate_limit", "error.unsupported", "error.unavailable", "error.bad_response", "error.network", "error.timeout", "error.safety", "error.blocked", "error.declined", "error.failed", "error.cancelled", "error.internal", "session.abandon_gated", "session.tool_denied", "session.sign_in", "session.gate_expired", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "tool.awaiting_user", "tool.completed_hidden", "tool.execution_uncertain", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "composer.model", "composer.effort"];
|
|
14
|
+
/** One of {@linkcode CLIENT_LABEL_KEYS}. */
|
|
15
|
+
export type ClientLabelKey = (typeof CLIENT_LABEL_KEYS)[number];
|
|
16
|
+
/** Host-supplied replacement templates, `{param}` placeholders included. */
|
|
17
|
+
export type LabelOverrides = Partial<Record<LabelKey, string>>;
|
|
18
|
+
/**
|
|
19
|
+
* What each key is: when the kernel uses it, who reads it, and the placeholders it takes. For the
|
|
20
|
+
* builders who replace the wording; the field catalog reads it for `labels.<key>`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const LABEL_NOTES: Record<LabelKey, string>;
|
|
23
|
+
export declare function labelPlaceholders(key: LabelKey): readonly string[];
|
|
24
|
+
/** `owner` names where the overrides came from in the error. */
|
|
25
|
+
export declare function validateLabelOverrides(entries: LabelOverrides, owner: string): void;
|
|
26
|
+
/** Process-wide; a profile's own `labels` wins over these. */
|
|
27
|
+
export declare function overrideLabels(entries: LabelOverrides): void;
|
|
28
|
+
/** Remove every label override. */
|
|
29
|
+
export declare function resetLabels(): void;
|
|
30
|
+
/** The wording for a key, with a profile's override applied and the params filled in. */
|
|
31
|
+
export declare function labelText(key: LabelKey, params?: LabelParams, profileLabels?: LabelOverrides): string;
|
|
32
|
+
/** Overrides only, resolved on the host; keys without one fall back to the defaults the client ships with. */
|
|
33
|
+
export declare function clientLabels(profileLabels?: LabelOverrides): LabelOverrides;
|
|
34
|
+
/** Ignores overrides. */
|
|
35
|
+
export declare function labelDefault(key: LabelKey, params?: LabelParams): string;
|
|
36
|
+
/** Every label with its default text, named by the profile path that overrides it: `labels.<key>`. */
|
|
37
|
+
export declare function labelCatalogRows(): readonly {
|
|
38
|
+
name: string;
|
|
39
|
+
text: string;
|
|
40
|
+
}[];
|