@theoremjs/agents 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +276 -995
- package/esm/mod.d.ts +33 -19
- package/esm/mod.js +18 -11
- package/esm/src/cli/commands/bench.js +36 -14
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -0
- package/esm/src/cli/commands/eval.d.ts +3 -3
- package/esm/src/cli/commands/fuzz-canary.js +55 -16
- package/esm/src/cli/commands/profile.js +4 -4
- package/esm/src/cli/commands/run.d.ts +2 -2
- package/esm/src/cli/commands/run.js +1 -1
- package/esm/src/cli/commands/test.d.ts +4 -3
- package/esm/src/cli/commands/test.js +2 -2
- package/esm/src/cli/index.js +9 -9
- package/esm/src/cli/matrix/fixtures.js +25 -30
- package/esm/src/evals/attachments.d.ts +1 -0
- package/esm/src/evals/attachments.js +4 -2
- package/esm/src/evals/breakdown.d.ts +2 -0
- package/esm/src/evals/breakdown.js +1 -0
- package/esm/src/evals/graders/answer.d.ts +3 -0
- package/esm/src/evals/graders/answer.js +1 -0
- package/esm/src/evals/graders/code.d.ts +7 -31
- package/esm/src/evals/graders/code.js +4 -25
- package/esm/src/evals/graders/judge.d.ts +4 -0
- package/esm/src/evals/graders/judge.js +7 -5
- package/esm/src/evals/graders/latency.d.ts +1 -0
- package/esm/src/evals/graders/latency.js +3 -2
- package/esm/src/evals/graders/live.d.ts +3 -0
- package/esm/src/evals/graders/live.js +2 -0
- package/esm/src/evals/graders/media.js +1 -2
- package/esm/src/evals/graders/shared.js +1 -1
- package/esm/src/evals/graders/transcript.d.ts +2 -0
- package/esm/src/evals/graders/transcript.js +5 -3
- package/esm/src/evals/mod.d.ts +1 -9
- package/esm/src/evals/mod.js +1 -9
- package/esm/src/evals/record.d.ts +6 -0
- package/esm/src/evals/record.js +4 -2
- package/esm/src/evals/rubrics/mod.d.ts +1 -1
- package/esm/src/evals/rubrics/mod.js +1 -1
- package/esm/src/evals/rubrics/mustache.js +1 -1
- package/esm/src/evals/rubrics/types.js +1 -1
- package/esm/src/evals/run.d.ts +9 -52
- package/esm/src/evals/run.js +12 -46
- package/esm/src/evals/suite.d.ts +12 -3
- package/esm/src/evals/suite.js +9 -4
- package/esm/src/evals/summary.d.ts +3 -0
- package/esm/src/evals/summary.js +1 -0
- package/esm/src/evals/trial.d.ts +3 -16
- package/esm/src/evals/trial.js +7 -30
- package/esm/src/evals/types.d.ts +30 -121
- package/esm/src/evals/types.js +3 -16
- package/esm/src/evals/verdict.d.ts +5 -0
- package/esm/src/evals/verdict.js +4 -1
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +1 -0
- package/esm/src/guardrails/canary.d.ts +49 -15
- package/esm/src/guardrails/canary.js +103 -30
- package/esm/src/guardrails/compile-egress.d.ts +6 -5
- package/esm/src/guardrails/compile-egress.js +6 -5
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +3 -1
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +4 -2
- package/esm/src/guardrails/corpus/fuzz-inbound.js +14 -17
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +2 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +4 -2
- package/esm/src/guardrails/corpus/live-attacks.d.ts +2 -0
- package/esm/src/guardrails/corpus/live-attacks.js +6 -1
- package/esm/src/guardrails/corpus/mod.d.ts +1 -1
- package/esm/src/guardrails/corpus/secrets.d.ts +3 -3
- package/esm/src/guardrails/corpus/secrets.js +2 -2
- package/esm/src/guardrails/corpus/strings.d.ts +1 -1
- package/esm/src/guardrails/corpus/strings.js +1 -1
- package/esm/src/guardrails/corpus/types.d.ts +5 -1
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +4 -6
- package/esm/src/guardrails/egress-automata.js +24095 -4572
- package/esm/src/guardrails/egress-compiler.d.ts +38 -16
- package/esm/src/guardrails/egress-compiler.js +254 -60
- package/esm/src/guardrails/egress-patterns.d.ts +4 -2
- package/esm/src/guardrails/egress-patterns.js +6 -2
- package/esm/src/guardrails/egress-stream.d.ts +54 -36
- package/esm/src/guardrails/egress-stream.js +253 -124
- package/esm/src/guardrails/egress-urls.d.ts +6 -3
- package/esm/src/guardrails/egress-urls.js +14 -22
- package/esm/src/guardrails/egress.d.ts +26 -86
- package/esm/src/guardrails/egress.js +59 -309
- package/esm/src/guardrails/error.d.ts +13 -8
- package/esm/src/guardrails/error.js +23 -18
- package/esm/src/guardrails/event-schemas.d.ts +46 -3
- package/esm/src/guardrails/event-schemas.js +12 -5
- package/esm/src/guardrails/events.d.ts +5 -1
- package/esm/src/guardrails/events.js +4 -1
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +7 -1
- package/esm/src/guardrails/hits.js +12 -1
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +6 -1
- package/esm/src/guardrails/injection-patterns.js +33 -1
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +17 -1
- package/esm/src/guardrails/injection.js +259 -36
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +874 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +9 -8
- package/esm/src/guardrails/live-outbound-gate.js +100 -107
- package/esm/src/guardrails/mod.d.ts +29 -21
- package/esm/src/guardrails/mod.js +18 -13
- package/esm/src/guardrails/network.d.ts +4 -0
- package/esm/src/guardrails/network.js +21 -19
- package/esm/src/guardrails/normalize.d.ts +15 -1
- package/esm/src/guardrails/normalize.js +34 -1
- package/esm/src/guardrails/policy.d.ts +2 -17
- package/esm/src/guardrails/policy.js +12 -41
- package/esm/src/guardrails/progressive-yield.d.ts +65 -24
- package/esm/src/guardrails/progressive-yield.js +191 -147
- package/esm/src/guardrails/prompt-echo.d.ts +4 -2
- package/esm/src/guardrails/prompt-echo.js +87 -6
- package/esm/src/guardrails/quota.d.ts +1 -0
- package/esm/src/guardrails/quota.js +1 -1
- package/esm/src/guardrails/rules.d.ts +20 -29
- package/esm/src/guardrails/rules.js +23 -30
- package/esm/src/guardrails/sanitize.d.ts +32 -15
- package/esm/src/guardrails/sanitize.js +100 -124
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +16 -23
- package/esm/src/guardrails/sensitive.js +168 -47
- package/esm/src/guardrails/serialize.d.ts +1 -0
- package/esm/src/guardrails/testing.d.ts +4 -2
- package/esm/src/guardrails/testing.js +4 -2
- package/esm/src/guardrails/theorem-error.d.ts +4 -1
- package/esm/src/guardrails/theorem-error.js +3 -2
- package/esm/src/guardrails/thought-guard.d.ts +34 -13
- package/esm/src/guardrails/thought-guard.js +264 -64
- package/esm/src/guardrails/tool-directives.d.ts +29 -10
- package/esm/src/guardrails/tool-directives.js +133 -47
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +45 -14
- package/esm/src/guardrails/tool-result.js +94 -70
- package/esm/src/guardrails/types.d.ts +79 -71
- package/esm/src/guardrails/types.js +11 -7
- package/esm/src/host/client-turn.d.ts +29 -2
- package/esm/src/host/client-turn.js +46 -4
- package/esm/src/host/mint-trace.d.ts +1 -0
- package/esm/src/host/mint-trace.js +3 -2
- package/esm/src/host/mod.d.ts +2 -2
- package/esm/src/host/mod.js +1 -1
- package/esm/src/host/readStreamingJsonStringField.js +2 -43
- package/esm/src/host/reply.d.ts +6 -0
- package/esm/src/host/reply.js +7 -1
- package/esm/src/interface/blocks.d.ts +3 -0
- package/esm/src/interface/blocks.js +84 -14
- package/esm/src/interface/composer-actions.d.ts +4 -0
- package/esm/src/interface/composer-actions.js +5 -3
- package/esm/src/interface/draft.d.ts +6 -0
- package/esm/src/interface/draft.js +22 -11
- package/esm/src/interface/from-profile.d.ts +13 -1
- package/esm/src/interface/from-profile.js +66 -31
- package/esm/src/interface/history.d.ts +9 -3
- package/esm/src/interface/history.js +33 -24
- package/esm/src/interface/inputs.d.ts +1 -0
- package/esm/src/interface/inputs.js +3 -0
- package/esm/src/interface/mod.d.ts +4 -2
- package/esm/src/interface/mod.js +3 -2
- package/esm/src/interface/models.d.ts +7 -0
- package/esm/src/interface/models.js +5 -0
- package/esm/src/interface/pending.d.ts +9 -0
- package/esm/src/interface/pending.js +9 -3
- package/esm/src/interface/profile-interface.js +54 -40
- package/esm/src/interface/session.d.ts +12 -5
- package/esm/src/interface/session.js +17 -10
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +14 -2
- package/esm/src/interface/tool-calls.js +64 -10
- package/esm/src/interface/tool-invoke.d.ts +2 -0
- package/esm/src/interface/tool-invoke.js +3 -1
- package/esm/src/interface/tool-media.d.ts +2 -0
- package/esm/src/interface/tool-media.js +2 -1
- package/esm/src/interface/types.d.ts +105 -40
- package/esm/src/interface/types.js +1 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -0
- package/esm/src/kernel/auth/crypto.d.ts +7 -2
- package/esm/src/kernel/auth/crypto.js +12 -10
- package/esm/src/kernel/auth/oauth.d.ts +2 -1
- package/esm/src/kernel/auth/oauth.js +23 -22
- package/esm/src/kernel/auth/typed-secret.js +2 -2
- package/esm/src/kernel/auth/types.d.ts +13 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +43 -5
- package/esm/src/kernel/default-scope.js +54 -5
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +6 -5
- package/esm/src/kernel/engine/compaction.js +12 -11
- package/esm/src/kernel/engine/decision.d.ts +10 -8
- package/esm/src/kernel/engine/decision.js +173 -146
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +14 -4
- package/esm/src/kernel/engine/live-inbound.js +36 -11
- package/esm/src/kernel/engine/live-ingress.d.ts +6 -0
- package/esm/src/kernel/engine/live-ingress.js +6 -1
- package/esm/src/kernel/engine/repair.js +12 -12
- package/esm/src/kernel/engine/runner/gates.d.ts +2 -2
- package/esm/src/kernel/engine/runner/gates.js +287 -101
- package/esm/src/kernel/engine/runner/mod.d.ts +19 -5
- package/esm/src/kernel/engine/runner/mod.js +107 -56
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +24 -3
- package/esm/src/kernel/engine/runner/schema-validation.js +78 -4
- package/esm/src/kernel/engine/runner/stages.d.ts +1 -1
- package/esm/src/kernel/engine/runner/stages.js +1 -8
- package/esm/src/kernel/engine/runner/state.d.ts +33 -12
- package/esm/src/kernel/engine/runner/state.js +11 -1
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +2 -2
- package/esm/src/kernel/engine/runner/steps.js +328 -169
- package/esm/src/kernel/engine/runner/stream.d.ts +42 -11
- package/esm/src/kernel/engine/runner/stream.js +197 -46
- package/esm/src/kernel/engine/runner/usage.d.ts +5 -5
- package/esm/src/kernel/engine/runner/usage.js +12 -14
- package/esm/src/kernel/engine/session/mod.d.ts +8 -6
- package/esm/src/kernel/engine/session/mod.js +360 -129
- package/esm/src/kernel/engine/session/session-trace.d.ts +10 -10
- package/esm/src/kernel/engine/session/session-trace.js +41 -30
- package/esm/src/kernel/engine/token-estimate.d.ts +10 -64
- package/esm/src/kernel/engine/token-estimate.js +14 -194
- package/esm/src/kernel/engine/tool-trace.d.ts +3 -3
- package/esm/src/kernel/engine/tool-trace.js +2 -1
- package/esm/src/kernel/engine/turn-trace.d.ts +8 -7
- package/esm/src/kernel/engine/turn-trace.js +28 -36
- package/esm/src/kernel/engine/usage.d.ts +6 -0
- package/esm/src/kernel/engine/usage.js +17 -0
- package/esm/src/kernel/interaction-parts.d.ts +3 -0
- package/esm/src/kernel/interaction-parts.js +18 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +38 -11
- package/esm/src/kernel/mod.js +22 -7
- package/esm/src/kernel/profile-graph.d.ts +11 -6
- package/esm/src/kernel/profile-graph.js +14 -7
- package/esm/src/kernel/profile-presence.d.ts +10 -1
- package/esm/src/kernel/profile-presence.js +90 -75
- package/esm/src/kernel/profile-scope.d.ts +7 -3
- package/esm/src/kernel/profile-scope.js +67 -55
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +15 -4
- package/esm/src/kernel/registry/attachments.js +31 -22
- package/esm/src/kernel/registry/catalog.d.ts +6 -0
- package/esm/src/kernel/registry/catalog.js +9 -2
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +6 -2
- package/esm/src/kernel/registry/ingress.js +55 -10
- package/esm/src/kernel/registry/kernel-registry.d.ts +3 -0
- package/esm/src/kernel/registry/kernel-registry.js +9 -2
- package/esm/src/kernel/registry/profile-outputs.js +4 -1
- package/esm/src/kernel/registry/profiles.d.ts +38 -14
- package/esm/src/kernel/registry/profiles.js +280 -205
- package/esm/src/kernel/registry/provider-request.d.ts +3 -3
- package/esm/src/kernel/registry/provider-request.js +5 -13
- package/esm/src/kernel/registry/resolve.d.ts +4 -1
- package/esm/src/kernel/registry/resolve.js +59 -58
- package/esm/src/kernel/registry/schemas.d.ts +3 -0
- package/esm/src/kernel/registry/schemas.js +3 -1
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -0
- package/esm/src/kernel/registry/system-prompt.js +7 -8
- package/esm/src/kernel/registry/vault.d.ts +14 -13
- package/esm/src/kernel/registry/vault.js +1 -14
- package/esm/src/kernel/schema.d.ts +100 -46
- package/esm/src/kernel/schema.js +499 -257
- package/esm/src/kernel/scope.d.ts +12 -5
- package/esm/src/kernel/scope.js +23 -3
- package/esm/src/kernel/stages.d.ts +38 -3
- package/esm/src/kernel/stages.js +82 -39
- package/esm/src/kernel/stop.d.ts +29 -6
- package/esm/src/kernel/stop.js +16 -4
- package/esm/src/kernel/system-parts.js +6 -6
- package/esm/src/kernel/tools/activity-label.d.ts +12 -6
- package/esm/src/kernel/tools/activity-label.js +258 -32
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +21 -6
- package/esm/src/kernel/tools/events.js +53 -18
- package/esm/src/kernel/tools/execute.d.ts +47 -11
- package/esm/src/kernel/tools/execute.js +508 -136
- package/esm/src/kernel/tools/gate-answer.d.ts +12 -2
- package/esm/src/kernel/tools/gate-answer.js +17 -6
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +1 -0
- package/esm/src/kernel/tools/harness.js +2 -1
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +27 -5
- package/esm/src/kernel/tools/invoke.js +223 -70
- package/esm/src/kernel/tools/mcp-sessions.d.ts +4 -1
- package/esm/src/kernel/tools/mcp-sessions.js +13 -8
- package/esm/src/kernel/tools/mod.d.ts +4 -3
- package/esm/src/kernel/tools/mod.js +3 -2
- package/esm/src/kernel/tools/model-text.d.ts +10 -5
- package/esm/src/kernel/tools/model-text.js +18 -12
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +11 -2
- package/esm/src/kernel/tools/permission.js +12 -12
- package/esm/src/kernel/tools/project.d.ts +4 -1
- package/esm/src/kernel/tools/project.js +32 -2
- package/esm/src/kernel/tools/registry.d.ts +9 -2
- package/esm/src/kernel/tools/registry.js +69 -10
- package/esm/src/kernel/tools/remote.d.ts +40 -6
- package/esm/src/kernel/tools/remote.js +219 -92
- package/esm/src/kernel/tools/resolve.d.ts +3 -0
- package/esm/src/kernel/tools/resolve.js +12 -4
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +3 -3
- package/esm/src/kernel/tools/schema.js +21 -100
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +2 -1
- package/esm/src/kernel/tools/signed-in-fetch.js +3 -3
- package/esm/src/kernel/tools/stage-run.d.ts +27 -4
- package/esm/src/kernel/tools/stage-run.js +75 -17
- package/esm/src/kernel/tools/types.d.ts +235 -25
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +208 -31
- package/esm/src/kernel/turn-events.js +127 -9
- package/esm/src/kernel/types.d.ts +302 -161
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +2 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +1 -0
- package/esm/src/observability/destinations.d.ts +5 -0
- package/esm/src/observability/destinations.js +7 -2
- package/esm/src/observability/jsonl.d.ts +2 -2
- package/esm/src/observability/jsonl.js +15 -22
- package/esm/src/observability/mod.d.ts +3 -3
- package/esm/src/observability/mod.js +2 -2
- package/esm/src/observability/openinference.d.ts +1 -1
- package/esm/src/observability/openinference.js +3 -3
- package/esm/src/observability/otlp.d.ts +3 -0
- package/esm/src/observability/otlp.js +3 -3
- package/esm/src/observability/phoenix.d.ts +1 -0
- package/esm/src/observability/policy.d.ts +3 -0
- package/esm/src/observability/policy.js +5 -1
- package/esm/src/observability/resolve-policy.js +11 -5
- package/esm/src/observability/spans.d.ts +8 -2
- package/esm/src/observability/spans.js +21 -5
- package/esm/src/observability/trace-catalog.d.ts +19 -2
- package/esm/src/observability/trace-catalog.js +128 -87
- package/esm/src/observability/trace-record.js +22 -17
- package/esm/src/observability/trace-schema.d.ts +3 -0
- package/esm/src/observability/trace-schema.js +1 -1
- package/esm/src/observability/trace-sink.d.ts +1 -0
- package/esm/src/observability/trace-sink.js +1 -1
- package/esm/src/observability/trace-span.d.ts +7 -1
- package/esm/src/observability/trace-span.js +3 -1
- package/esm/src/observability/trace.d.ts +2 -0
- package/esm/src/observability/trace.js +4 -2
- package/esm/src/observability/types.d.ts +35 -11
- package/esm/src/observability/types.js +1 -1
- package/esm/src/presets/google/speech-voices.d.ts +1 -0
- package/esm/src/presets/google-limits.d.ts +1 -0
- package/esm/src/presets/google.d.ts +27 -12
- package/esm/src/presets/google.js +34 -25
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +5 -4
- package/esm/src/presets/mod.js +4 -4
- package/esm/src/presets/openrouter.d.ts +14 -1
- package/esm/src/presets/openrouter.js +19 -1
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +105 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -0
- package/esm/src/providers/google/grounding.d.ts +4 -4
- package/esm/src/providers/google/interactions/framing.d.ts +20 -8
- package/esm/src/providers/google/interactions/framing.js +85 -44
- package/esm/src/providers/google/interactions/steps.d.ts +5 -5
- package/esm/src/providers/google/interactions/steps.js +4 -4
- package/esm/src/providers/google/interactions/stream.d.ts +10 -11
- package/esm/src/providers/google/interactions/stream.js +33 -100
- package/esm/src/providers/google/live/framing.d.ts +15 -5
- package/esm/src/providers/google/live/framing.js +25 -25
- package/esm/src/providers/google/live/stream.d.ts +6 -44
- package/esm/src/providers/google/live/stream.js +3 -209
- package/esm/src/providers/google/urls.d.ts +1 -3
- package/esm/src/providers/google/urls.js +1 -3
- package/esm/src/providers/google/usage.js +2 -2
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +28 -7
- package/esm/src/providers/mod.js +19 -3
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +0 -9
- package/esm/src/providers/openrouter/image.js +0 -153
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/compat.js +6 -6
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -0
- package/esm/src/providers/shared/pcm.js +2 -2
- package/esm/src/providers/shared/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -0
- package/esm/src/providers/shared/response-identity.d.ts +2 -2
- package/esm/src/providers/shared/retry.d.ts +17 -0
- package/esm/src/providers/shared/retry.js +90 -0
- package/esm/src/providers/shared/sse.d.ts +0 -4
- package/esm/src/providers/shared/sse.js +50 -36
- package/esm/src/providers/shared/tool-args.d.ts +6 -7
- package/esm/src/providers/shared/tool-args.js +10 -6
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +2 -2
- package/esm/src/providers/shared/upstream-tape.js +1 -1
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +48 -16
- package/esm/src/providers/types.js +2 -1
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +19 -1
- package/esm/src/surface/formats.js +68 -29
- package/esm/src/surface/mod.d.ts +4 -2
- package/esm/src/surface/mod.js +4 -2
- package/esm/src/surface/runtime.d.ts +4 -0
- package/esm/src/surface/runtime.js +2 -0
- package/esm/src/surface/tools.d.ts +2 -8
- package/esm/src/surface/tools.js +4 -22
- package/esm/src/surface/types.d.ts +6 -0
- package/package.json +5 -13
- package/esm/src/cli/commands/egress-compile.d.ts +0 -17
- package/esm/src/cli/commands/egress-compile.js +0 -25
- package/esm/src/guardrails/egress-policy.d.ts +0 -27
- package/esm/src/guardrails/egress-policy.js +0 -76
- package/esm/src/guardrails/egress-rules.d.ts +0 -54
- package/esm/src/guardrails/egress-rules.js +0 -49
- package/esm/src/guardrails/lexicon.d.ts +0 -30
- package/esm/src/guardrails/lexicon.js +0 -478
- package/esm/src/kernel/engine/media-probe/audio.d.ts +0 -7
- package/esm/src/kernel/engine/media-probe/audio.js +0 -342
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +0 -6
- package/esm/src/kernel/engine/media-probe/bytes.js +0 -26
- package/esm/src/kernel/engine/media-probe/image.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/image.js +0 -171
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +0 -19
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +0 -48
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +0 -35
- package/esm/src/kernel/engine/media-probe/matroska.js +0 -226
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +0 -22
- package/esm/src/kernel/engine/media-probe/mp4.js +0 -279
- package/esm/src/kernel/engine/media-probe/opus.d.ts +0 -4
- package/esm/src/kernel/engine/media-probe/opus.js +0 -23
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/pdf.js +0 -117
- package/esm/src/kernel/engine/media-probe/video.d.ts +0 -15
- package/esm/src/kernel/engine/media-probe/video.js +0 -49
- package/esm/src/presets/typesafe.d.ts +0 -2
- package/esm/src/presets/typesafe.js +0 -2
- package/esm/src/providers/create-provider.d.ts +0 -21
- package/esm/src/providers/create-provider.js +0 -90
- package/esm/src/providers/decision/usage.d.ts +0 -3
- package/esm/src/providers/decision/usage.js +0 -25
- package/esm/src/providers/google/interactions/mod.d.ts +0 -2
- package/esm/src/providers/google/interactions/mod.js +0 -2
- package/esm/src/providers/google/keys.d.ts +0 -20
- package/esm/src/providers/google/keys.js +0 -87
- package/esm/src/providers/google/live/mod.d.ts +0 -7
- package/esm/src/providers/google/live/mod.js +0 -7
- package/esm/src/providers/google/live/openapi-schema.d.ts +0 -1
- package/esm/src/providers/google/live/openapi-schema.js +0 -42
- package/esm/src/providers/google/live/session.d.ts +0 -14
- package/esm/src/providers/google/live/session.js +0 -150
- package/esm/src/providers/local/local.d.ts +0 -12
- package/esm/src/providers/local/local.js +0 -186
- package/esm/src/providers/local/mod.d.ts +0 -8
- package/esm/src/providers/local/mod.js +0 -8
- package/esm/src/providers/openrouter/cache-control.d.ts +0 -5
- package/esm/src/providers/openrouter/cache-control.js +0 -4
- package/esm/src/providers/openrouter/chat.d.ts +0 -64
- package/esm/src/providers/openrouter/chat.js +0 -490
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +0 -10
- package/esm/src/providers/openrouter/openai/sdk-messages.js +0 -99
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +0 -3
- package/esm/src/providers/openrouter/resolve-api-key.js +0 -8
- package/esm/src/providers/openrouter/speech.d.ts +0 -18
- package/esm/src/providers/openrouter/speech.js +0 -109
- package/esm/src/providers/probe.d.ts +0 -5
- package/esm/src/providers/probe.js +0 -15
- package/esm/src/providers/shared/builtin-wire.d.ts +0 -4
- package/esm/src/providers/shared/builtin-wire.js +0 -9
- package/esm/src/providers/shared/vault.d.ts +0 -13
- package/esm/src/providers/shared/vault.js +0 -41
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
// invariant: Imports the boundary vocabulary, the sensitive groups, and the host's patterns only:
|
|
2
|
+
// nothing from `src/guardrails/types.ts` or `src/kernel/`, so `types.ts` can read these types
|
|
3
|
+
// without a cycle.
|
|
4
|
+
/** labels-exempt-file: authoring labels, descriptions and profile-registration diagnostics for detectors — not runtime user or model copy (P2) */
|
|
5
|
+
import { BOUNDARIES, INBOUND_BOUNDARIES, OUTBOUND_BOUNDARIES, recordOf, TOOL_BOUNDARIES, TOOL_KINDS, toolBoundary, } from './boundaries.js';
|
|
6
|
+
import { matchersOf, patternsProblem, } from './host-patterns.js';
|
|
7
|
+
import { SENSITIVE_GROUPS } from './sensitive-groups.js';
|
|
8
|
+
/**
|
|
9
|
+
* What the kernel finds in text: the four families of sensitive data, prompt-injection phrasing,
|
|
10
|
+
* a tool's text that instructs the agent, and what is the profile's own on its way out (the canary token, the system instruction, the
|
|
11
|
+
* kernel's markers, an image or link to an address the model was not given, and the names of its
|
|
12
|
+
* tools).
|
|
13
|
+
*/
|
|
14
|
+
const DETECTORS = [
|
|
15
|
+
...SENSITIVE_GROUPS,
|
|
16
|
+
'injection',
|
|
17
|
+
'tool_instructions',
|
|
18
|
+
'canary_leak',
|
|
19
|
+
'prompt_leak',
|
|
20
|
+
'marker_leak',
|
|
21
|
+
'ungiven_images',
|
|
22
|
+
'ungiven_links',
|
|
23
|
+
'tool_leak',
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* What the kernel does with a match, the same at every boundary:
|
|
27
|
+
* - `ignore` — the text is not checked.
|
|
28
|
+
* - `flag` — the match is recorded in the trace; nothing changes.
|
|
29
|
+
* - `redact` — the match is replaced with a placeholder; the rest is kept.
|
|
30
|
+
* - `block` — the whole message, reply, or tool call is stopped.
|
|
31
|
+
*/
|
|
32
|
+
const DETECT_ACTIONS = ['ignore', 'flag', 'redact', 'block'];
|
|
33
|
+
/** How much of a streaming reply stays held for a host's `find`, in characters. */
|
|
34
|
+
const HOST_FIND_HOLD = 256;
|
|
35
|
+
/** The same in a Live reply, which is spoken as it is written. */
|
|
36
|
+
const HOST_FIND_HOLD_LIVE = 96;
|
|
37
|
+
/** The groups an editor lists detectors under, in order. */
|
|
38
|
+
const DETECTOR_GROUPS = ['data', 'manipulation', 'setup', 'addresses'];
|
|
39
|
+
/** The label of every group, and what its detectors find. */
|
|
40
|
+
const DETECTOR_GROUP_META = {
|
|
41
|
+
data: { label: 'Sensitive data', doc: 'Personal and secret data.' },
|
|
42
|
+
manipulation: { label: 'Manipulation', doc: 'Text that steers the agent.' },
|
|
43
|
+
setup: {
|
|
44
|
+
label: 'Agent setup',
|
|
45
|
+
doc: "The profile's own text in model output.",
|
|
46
|
+
},
|
|
47
|
+
addresses: {
|
|
48
|
+
label: 'Unknown addresses',
|
|
49
|
+
doc: 'Addresses the model was not given.',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const TOOL_ARGUMENT_BOUNDARIES = TOOL_KINDS.map((kind) => toolBoundary('tool_arguments', kind));
|
|
53
|
+
const TOOL_SHOWN_BOUNDARIES = TOOL_KINDS.map((kind) => toolBoundary('tool_shown', kind));
|
|
54
|
+
/**
|
|
55
|
+
* Text on its way to the model is redacted, a tool call takes `toTool`, and what the model writes
|
|
56
|
+
* or a tool shows the person is not read.
|
|
57
|
+
*/
|
|
58
|
+
function everywhere(toTool) {
|
|
59
|
+
return {
|
|
60
|
+
...recordOf(INBOUND_BOUNDARIES, () => 'redact'),
|
|
61
|
+
...recordOf(TOOL_BOUNDARIES, () => 'redact'),
|
|
62
|
+
...recordOf(TOOL_ARGUMENT_BOUNDARIES, () => toTool),
|
|
63
|
+
...recordOf(TOOL_SHOWN_BOUNDARIES, () => 'ignore'),
|
|
64
|
+
...recordOf(OUTBOUND_BOUNDARIES, () => 'ignore'),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** What the model writes: a tool call takes `toTool`, what it says takes `said`, a thought `thought`. */
|
|
68
|
+
function leaving(toTool, said, thought) {
|
|
69
|
+
return {
|
|
70
|
+
...recordOf(TOOL_ARGUMENT_BOUNDARIES, () => toTool),
|
|
71
|
+
reply: said,
|
|
72
|
+
reply_structured: said,
|
|
73
|
+
live_reply: said,
|
|
74
|
+
thought,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** What a tool returns, its output, and its error text: `remote` from a tool the host did not write, `local` from a function. */
|
|
78
|
+
function returned(remote, local) {
|
|
79
|
+
const crossings = ['tool_output', 'tool_failure'];
|
|
80
|
+
return Object.fromEntries(crossings.flatMap((crossing) => TOOL_KINDS.map((kind) => [
|
|
81
|
+
toolBoundary(crossing, kind),
|
|
82
|
+
kind === 'function' ? local : remote,
|
|
83
|
+
])));
|
|
84
|
+
}
|
|
85
|
+
/** What the model says or thinks: a reply of any kind takes `said`, a thought `thought`. */
|
|
86
|
+
function shown(said, thought) {
|
|
87
|
+
return { reply: said, reply_structured: said, live_reply: said, thought };
|
|
88
|
+
}
|
|
89
|
+
/** Every detector's declaration. The editor, validation, and the catalog are built from it. */
|
|
90
|
+
const DETECTOR_META = {
|
|
91
|
+
ids: {
|
|
92
|
+
label: 'IDs',
|
|
93
|
+
doc: 'US SSN, ITIN, and EIN numbers.',
|
|
94
|
+
group: 'data',
|
|
95
|
+
defaults: everywhere('flag'),
|
|
96
|
+
patterns: true,
|
|
97
|
+
},
|
|
98
|
+
financial: {
|
|
99
|
+
label: 'Financial',
|
|
100
|
+
doc: 'IBANs and card numbers.',
|
|
101
|
+
group: 'data',
|
|
102
|
+
defaults: everywhere('flag'),
|
|
103
|
+
patterns: true,
|
|
104
|
+
},
|
|
105
|
+
network: {
|
|
106
|
+
label: 'Network',
|
|
107
|
+
doc: 'IPv4 and IPv6 addresses.',
|
|
108
|
+
group: 'data',
|
|
109
|
+
defaults: everywhere('flag'),
|
|
110
|
+
patterns: true,
|
|
111
|
+
},
|
|
112
|
+
credentials: {
|
|
113
|
+
label: 'Credentials',
|
|
114
|
+
doc: 'API keys, tokens, passwords, and private keys.',
|
|
115
|
+
group: 'data',
|
|
116
|
+
// why: A key the model was handed (in its instructions or a tool's output) is a key the person
|
|
117
|
+
// reading the reply should not get, nor one a tool returned; the rest still shows. A thought and
|
|
118
|
+
// a Live reply stay unread, so neither holds its stream nor turns transcription on for every turn.
|
|
119
|
+
defaults: {
|
|
120
|
+
...everywhere('flag'),
|
|
121
|
+
...recordOf(TOOL_SHOWN_BOUNDARIES, () => 'redact'),
|
|
122
|
+
reply: 'redact',
|
|
123
|
+
reply_structured: 'redact',
|
|
124
|
+
},
|
|
125
|
+
patterns: true,
|
|
126
|
+
},
|
|
127
|
+
injection: {
|
|
128
|
+
label: 'Injection',
|
|
129
|
+
doc: 'Prompt-injection phrasing, plain or disguised.',
|
|
130
|
+
group: 'manipulation',
|
|
131
|
+
defaults: everywhere('ignore'),
|
|
132
|
+
patterns: true,
|
|
133
|
+
},
|
|
134
|
+
tool_instructions: {
|
|
135
|
+
label: 'Tool instructions',
|
|
136
|
+
short: 'From tools',
|
|
137
|
+
doc: 'Tool output that instructs the agent. A match raises taint.',
|
|
138
|
+
group: 'manipulation',
|
|
139
|
+
defaults: returned('flag', 'ignore'),
|
|
140
|
+
patterns: true,
|
|
141
|
+
},
|
|
142
|
+
canary_leak: {
|
|
143
|
+
label: 'Canary leak',
|
|
144
|
+
doc: 'The canary token, plain or encoded. Planted only above Ignore.',
|
|
145
|
+
group: 'setup',
|
|
146
|
+
defaults: leaving('block', 'block', 'redact'),
|
|
147
|
+
},
|
|
148
|
+
prompt_leak: {
|
|
149
|
+
label: 'Prompt leak',
|
|
150
|
+
doc: 'Private system-instruction text, plain or disguised.',
|
|
151
|
+
group: 'setup',
|
|
152
|
+
defaults: leaving('flag', 'block', 'redact'),
|
|
153
|
+
},
|
|
154
|
+
marker_leak: {
|
|
155
|
+
label: 'Marker leak',
|
|
156
|
+
doc: "The kernel's data markers and canary note.",
|
|
157
|
+
group: 'setup',
|
|
158
|
+
defaults: shown('block', 'redact'),
|
|
159
|
+
},
|
|
160
|
+
ungiven_images: {
|
|
161
|
+
label: 'Ungiven images',
|
|
162
|
+
short: 'Images',
|
|
163
|
+
doc: 'An image at an address not given. Loads with no click.',
|
|
164
|
+
group: 'addresses',
|
|
165
|
+
defaults: shown('block', 'redact'),
|
|
166
|
+
allow: 'urls',
|
|
167
|
+
},
|
|
168
|
+
ungiven_links: {
|
|
169
|
+
label: 'Ungiven links',
|
|
170
|
+
short: 'Links',
|
|
171
|
+
doc: 'A link to an address not given. Replies cite known pages, so it is not checked by default.',
|
|
172
|
+
group: 'addresses',
|
|
173
|
+
defaults: shown('ignore', 'ignore'),
|
|
174
|
+
allow: 'urls',
|
|
175
|
+
},
|
|
176
|
+
tool_leak: {
|
|
177
|
+
label: 'Tool leak',
|
|
178
|
+
doc: "The profile's tool and parameter names.",
|
|
179
|
+
group: 'setup',
|
|
180
|
+
defaults: shown('flag', 'flag'),
|
|
181
|
+
allow: 'names',
|
|
182
|
+
patterns: true,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
/** The detectors that read with patterns: their setting takes `theorem` and `patterns`. */
|
|
186
|
+
const PATTERN_DETECTORS = DETECTORS.filter((detector) => DETECTOR_META[detector].patterns);
|
|
187
|
+
/** The boundaries each detector applies at, in the kernel's order. */
|
|
188
|
+
const DETECTOR_BOUNDARIES = recordOf(DETECTORS, (detector) => BOUNDARIES.filter((boundary) => boundary in DETECTOR_META[detector].defaults));
|
|
189
|
+
/** The label of every action, and what it does. */
|
|
190
|
+
const DETECT_ACTION_META = {
|
|
191
|
+
ignore: { label: 'Ignore', doc: 'Does not check the text.' },
|
|
192
|
+
flag: {
|
|
193
|
+
label: 'Flag',
|
|
194
|
+
doc: 'Records the match in the trace. Changes nothing.',
|
|
195
|
+
},
|
|
196
|
+
redact: {
|
|
197
|
+
label: 'Redact',
|
|
198
|
+
doc: 'Replaces the match with a placeholder. Keeps the rest.',
|
|
199
|
+
},
|
|
200
|
+
block: {
|
|
201
|
+
label: 'Block',
|
|
202
|
+
doc: 'Stops the whole message, reply, or tool call. None of it gets through.',
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
/** `action` wherever `detector` applies. Anywhere else it is `ignore`: the detector is not run there. */
|
|
206
|
+
function wherever(detector, action) {
|
|
207
|
+
const applies = DETECTOR_META[detector].defaults;
|
|
208
|
+
return recordOf(BOUNDARIES, (boundary) => (boundary in applies ? action : 'ignore'));
|
|
209
|
+
}
|
|
210
|
+
/** What a profile that sets no `guardrails.detect` gets. */
|
|
211
|
+
const DETECT_DEFAULTS = recordOf(DETECTORS, (detector) => ({
|
|
212
|
+
...wherever(detector, 'ignore'),
|
|
213
|
+
...DETECTOR_META[detector].defaults,
|
|
214
|
+
}));
|
|
215
|
+
/** Whether `detector` is above `ignore` at any of `boundaries`. */
|
|
216
|
+
function detects(detect, detector, boundaries = BOUNDARIES) {
|
|
217
|
+
return boundaries.some((boundary) => detect[detector][boundary] !== 'ignore');
|
|
218
|
+
}
|
|
219
|
+
function isAction(value) {
|
|
220
|
+
return DETECT_ACTIONS.includes(value);
|
|
221
|
+
}
|
|
222
|
+
function resolveRule(detector, rule) {
|
|
223
|
+
const base = DETECT_DEFAULTS[detector];
|
|
224
|
+
if (rule === undefined)
|
|
225
|
+
return base;
|
|
226
|
+
if (isAction(rule))
|
|
227
|
+
return wherever(detector, rule);
|
|
228
|
+
// why: With neither Theorem's patterns nor the host's, the detector has nothing to find.
|
|
229
|
+
const { action, at, theorem = true, patterns = [] } = rule;
|
|
230
|
+
if (!theorem && patterns.length === 0)
|
|
231
|
+
return wherever(detector, 'ignore');
|
|
232
|
+
return { ...(action === undefined ? base : wherever(detector, action)), ...at };
|
|
233
|
+
}
|
|
234
|
+
/** Whose patterns `rule` reads with, when it says: `undefined` is Theorem's only. */
|
|
235
|
+
function sourceOf(rule) {
|
|
236
|
+
if (rule === undefined || isAction(rule))
|
|
237
|
+
return undefined;
|
|
238
|
+
const { theorem = true, patterns = [], compiled } = rule;
|
|
239
|
+
if (theorem && patterns.length === 0)
|
|
240
|
+
return undefined;
|
|
241
|
+
return {
|
|
242
|
+
theorem,
|
|
243
|
+
matchers: matchersOf(patterns),
|
|
244
|
+
...(compiled && patterns.length > 0 ? { compiled } : {}),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/** `spec` with everything it leaves out at its default. */
|
|
248
|
+
function resolveDetect(spec) {
|
|
249
|
+
if (spec === undefined)
|
|
250
|
+
return DETECT_DEFAULTS;
|
|
251
|
+
if (isAction(spec))
|
|
252
|
+
return recordOf(DETECTORS, (detector) => wherever(detector, spec));
|
|
253
|
+
const matrix = recordOf(DETECTORS, (detector) => resolveRule(detector, spec[detector]));
|
|
254
|
+
const sources = {};
|
|
255
|
+
const hints = {};
|
|
256
|
+
for (const detector of PATTERN_DETECTORS) {
|
|
257
|
+
const rule = spec[detector];
|
|
258
|
+
const source = sourceOf(rule);
|
|
259
|
+
if (source)
|
|
260
|
+
sources[detector] = source;
|
|
261
|
+
if (rule !== undefined && !isAction(rule) && rule.hint)
|
|
262
|
+
hints[detector] = rule.hint;
|
|
263
|
+
}
|
|
264
|
+
const leak = spec.tool_leak;
|
|
265
|
+
const innocent = isAction(leak) ? undefined : leak?.allow?.names;
|
|
266
|
+
const host = Object.entries(spec).flatMap(([id, rule]) => isHostId(id) ? [hostDetector(id, rule)] : []);
|
|
267
|
+
return {
|
|
268
|
+
...matrix,
|
|
269
|
+
...(Object.keys(sources).length > 0 ? { sources } : {}),
|
|
270
|
+
...(Object.keys(hints).length > 0 ? { hints } : {}),
|
|
271
|
+
...(innocent?.length ? { innocent } : {}),
|
|
272
|
+
...(host.length > 0 ? { host } : {}),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function isHostId(key) {
|
|
276
|
+
return key.includes('.');
|
|
277
|
+
}
|
|
278
|
+
function hostDetector(id, config) {
|
|
279
|
+
const { label, action = 'ignore', at, patterns = [], compiled, find, hint } = config;
|
|
280
|
+
return {
|
|
281
|
+
id,
|
|
282
|
+
label,
|
|
283
|
+
actions: recordOf(BOUNDARIES, (boundary) => at?.[boundary] ?? action),
|
|
284
|
+
matchers: matchersOf(patterns),
|
|
285
|
+
...(compiled && patterns.length > 0 ? { compiled } : {}),
|
|
286
|
+
...(find ? { find } : {}),
|
|
287
|
+
...(hint ? { hint } : {}),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/** The action of `key`, a detector of Theorem's or the host's, at `boundary`. One unknown is `ignore`. */
|
|
291
|
+
function actionAt(detect, key, boundary) {
|
|
292
|
+
if (isDetector(key))
|
|
293
|
+
return detect[key][boundary];
|
|
294
|
+
return detect.host?.find(({ id }) => id === key)?.actions[boundary] ?? 'ignore';
|
|
295
|
+
}
|
|
296
|
+
const NO_ALLOW = { ungiven_images: {}, ungiven_links: {} };
|
|
297
|
+
function allowOf(rule) {
|
|
298
|
+
return (isAction(rule) ? undefined : rule?.allow) ?? {};
|
|
299
|
+
}
|
|
300
|
+
/** The `allow` of each detector that takes one. */
|
|
301
|
+
function resolveAllow(spec) {
|
|
302
|
+
if (spec === undefined || isAction(spec))
|
|
303
|
+
return NO_ALLOW;
|
|
304
|
+
const images = allowOf(spec.ungiven_images);
|
|
305
|
+
const links = allowOf(spec.ungiven_links);
|
|
306
|
+
// why: A host images load from already takes data with no click, so a link there opens nothing new.
|
|
307
|
+
const hosts = [...new Set([...(links.hosts ?? []), ...(images.hosts ?? [])])];
|
|
308
|
+
return {
|
|
309
|
+
ungiven_images: images,
|
|
310
|
+
ungiven_links: hosts.length > 0 ? { ...links, hosts } : links,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
const ACTION_LIST = DETECT_ACTIONS.join(', ');
|
|
314
|
+
function isRecord(value) {
|
|
315
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
316
|
+
}
|
|
317
|
+
/** `detector` left out is one of the host's own, which applies at every boundary. */
|
|
318
|
+
function atProblem(path, at, boundaries, detector) {
|
|
319
|
+
if (at === undefined)
|
|
320
|
+
return undefined;
|
|
321
|
+
if (!isRecord(at))
|
|
322
|
+
return `${path} must be an object of boundaries`;
|
|
323
|
+
const known = new Set(boundaries);
|
|
324
|
+
const applies = detector ? DETECTOR_BOUNDARIES[detector] : BOUNDARIES;
|
|
325
|
+
for (const [boundary, action] of Object.entries(at)) {
|
|
326
|
+
if (!known.has(boundary)) {
|
|
327
|
+
return `${path}.${boundary} is not a boundary this profile has (${boundaries.join(', ')})`;
|
|
328
|
+
}
|
|
329
|
+
if (!applies.includes(boundary)) {
|
|
330
|
+
return `${path}.${boundary} is not a boundary ${detector} applies at (${applies.join(', ')})`;
|
|
331
|
+
}
|
|
332
|
+
if (!isAction(action))
|
|
333
|
+
return `${path}.${boundary} must be one of ${ACTION_LIST}`;
|
|
334
|
+
}
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
const CONFIG_KEYS = [
|
|
338
|
+
'action',
|
|
339
|
+
'at',
|
|
340
|
+
'theorem',
|
|
341
|
+
'patterns',
|
|
342
|
+
'compiled',
|
|
343
|
+
'hint',
|
|
344
|
+
'allow',
|
|
345
|
+
];
|
|
346
|
+
const SOURCE_KEYS = [
|
|
347
|
+
'theorem',
|
|
348
|
+
'patterns',
|
|
349
|
+
'compiled',
|
|
350
|
+
'hint',
|
|
351
|
+
];
|
|
352
|
+
const ALLOW_KEYS = ['hosts', 'fromTools'];
|
|
353
|
+
/** The `allow` of `tool_leak`: names, each a string. */
|
|
354
|
+
function namesProblem(path, allow) {
|
|
355
|
+
const unknown = Object.keys(allow).find((key) => key !== 'names');
|
|
356
|
+
if (unknown !== undefined)
|
|
357
|
+
return `${path}.${unknown} is not a setting of allow (names)`;
|
|
358
|
+
const { names } = allow;
|
|
359
|
+
if (names === undefined)
|
|
360
|
+
return undefined;
|
|
361
|
+
if (!Array.isArray(names))
|
|
362
|
+
return `${path}.names must be a list`;
|
|
363
|
+
const bad = names.find((name) => typeof name !== 'string' || !name.trim());
|
|
364
|
+
return bad === undefined
|
|
365
|
+
? undefined
|
|
366
|
+
: `${path}.names lists ${JSON.stringify(bad)}, which is not a name`;
|
|
367
|
+
}
|
|
368
|
+
/** A hostname is all an allowed host is: a scheme, port, or path would never match one. */
|
|
369
|
+
function allowProblem(path, allow, detector) {
|
|
370
|
+
if (allow === undefined)
|
|
371
|
+
return undefined;
|
|
372
|
+
const lists = DETECTOR_META[detector].allow;
|
|
373
|
+
if (!lists) {
|
|
374
|
+
return `${path} is a setting of ungiven_images, ungiven_links, and tool_leak only`;
|
|
375
|
+
}
|
|
376
|
+
if (!isRecord(allow))
|
|
377
|
+
return `${path} must be an object`;
|
|
378
|
+
if (lists === 'names')
|
|
379
|
+
return namesProblem(path, allow);
|
|
380
|
+
const unknown = Object.keys(allow).find((key) => !ALLOW_KEYS.includes(key));
|
|
381
|
+
if (unknown !== undefined) {
|
|
382
|
+
return `${path}.${unknown} is not a setting of allow (${ALLOW_KEYS.join(', ')})`;
|
|
383
|
+
}
|
|
384
|
+
const { hosts, fromTools } = allow;
|
|
385
|
+
if (fromTools !== undefined && typeof fromTools !== 'boolean') {
|
|
386
|
+
return `${path}.fromTools must be a boolean`;
|
|
387
|
+
}
|
|
388
|
+
if (hosts === undefined)
|
|
389
|
+
return undefined;
|
|
390
|
+
if (!Array.isArray(hosts))
|
|
391
|
+
return `${path}.hosts must be a list`;
|
|
392
|
+
const bad = hosts.find((host) => typeof host !== 'string' || !/^[a-z0-9.-]+$/i.test(host) || host.startsWith('.'));
|
|
393
|
+
return bad === undefined
|
|
394
|
+
? undefined
|
|
395
|
+
: `${path}.hosts lists ${JSON.stringify(bad)}, which is not a hostname`;
|
|
396
|
+
}
|
|
397
|
+
function ruleProblem(path, rule, detector, boundaries) {
|
|
398
|
+
if (isAction(rule))
|
|
399
|
+
return undefined;
|
|
400
|
+
if (!isRecord(rule))
|
|
401
|
+
return `${path} must be one of ${ACTION_LIST}, or an object`;
|
|
402
|
+
const unknown = Object.keys(rule).find((key) => !CONFIG_KEYS.includes(key));
|
|
403
|
+
if (unknown !== undefined) {
|
|
404
|
+
return `${path}.${unknown} is not a setting of a detector (${CONFIG_KEYS.join(', ')})`;
|
|
405
|
+
}
|
|
406
|
+
if (rule.action !== undefined && !isAction(rule.action)) {
|
|
407
|
+
return `${path}.action must be one of ${ACTION_LIST}`;
|
|
408
|
+
}
|
|
409
|
+
return (atProblem(`${path}.at`, rule.at, boundaries, detector) ??
|
|
410
|
+
sourceProblem(path, rule, detector) ??
|
|
411
|
+
allowProblem(`${path}.allow`, rule.allow, detector));
|
|
412
|
+
}
|
|
413
|
+
/** `theorem`, `patterns`, and `compiled`: settings of a detector that reads with patterns. */
|
|
414
|
+
function sourceProblem(path, rule, detector) {
|
|
415
|
+
if (!DETECTOR_META[detector].patterns) {
|
|
416
|
+
const set = SOURCE_KEYS.find((key) => rule[key] !== undefined);
|
|
417
|
+
return set === undefined
|
|
418
|
+
? undefined
|
|
419
|
+
: `${path}.${set} is a setting of the detectors that read with patterns only (${PATTERN_DETECTORS.join(', ')})`;
|
|
420
|
+
}
|
|
421
|
+
if (rule.theorem !== undefined && typeof rule.theorem !== 'boolean') {
|
|
422
|
+
return `${path}.theorem must be a boolean`;
|
|
423
|
+
}
|
|
424
|
+
if (rule.hint !== undefined && !(Array.isArray(rule.patterns) && rule.patterns.length > 0)) {
|
|
425
|
+
return `${path}.hint goes beside patterns of your own: without them the labels' detect.hint.${detector} is the hint`;
|
|
426
|
+
}
|
|
427
|
+
return (hintProblem(`${path}.hint`, rule.hint) ?? patternsProblem(path, rule.patterns, rule.compiled));
|
|
428
|
+
}
|
|
429
|
+
/** A hint may be this long, in characters: it is a line in the retry, once for each detector that matched. */
|
|
430
|
+
const MAX_HINT = 300;
|
|
431
|
+
function hintProblem(path, hint) {
|
|
432
|
+
if (hint === undefined)
|
|
433
|
+
return undefined;
|
|
434
|
+
if (typeof hint !== 'string' || !hint.trim())
|
|
435
|
+
return `${path} must be a non-empty string`;
|
|
436
|
+
if (hint.includes('\n'))
|
|
437
|
+
return `${path} must be one line`;
|
|
438
|
+
return hint.length > MAX_HINT ? `${path} must be ${MAX_HINT} characters or fewer` : undefined;
|
|
439
|
+
}
|
|
440
|
+
function isDetector(value) {
|
|
441
|
+
return DETECTORS.includes(value);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* What is wrong with a `guardrails.detect` value, or `undefined` when it is valid. A misspelt
|
|
445
|
+
* detector or boundary would leave the one it meant at its default, silently, so both are errors.
|
|
446
|
+
* `boundaries` are the ones the profile has; a rule naming another is an error.
|
|
447
|
+
*/
|
|
448
|
+
function detectProblem(path, spec, boundaries = BOUNDARIES) {
|
|
449
|
+
if (spec === undefined || isAction(spec))
|
|
450
|
+
return undefined;
|
|
451
|
+
if (!isRecord(spec))
|
|
452
|
+
return `${path} must be one of ${ACTION_LIST}, or an object of detectors`;
|
|
453
|
+
for (const [detector, rule] of Object.entries(spec)) {
|
|
454
|
+
const at = `${path}.${detector}`;
|
|
455
|
+
if (!(isDetector(detector) || isHostId(detector))) {
|
|
456
|
+
return `${at} is not a detector (${DETECTORS.join(', ')}), nor one of your own: those have a dot in their key, as in acme.record`;
|
|
457
|
+
}
|
|
458
|
+
const problem = isDetector(detector)
|
|
459
|
+
? ruleProblem(at, rule, detector, boundaries)
|
|
460
|
+
: hostProblem(at, detector, rule, boundaries);
|
|
461
|
+
if (problem !== undefined)
|
|
462
|
+
return problem;
|
|
463
|
+
}
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
466
|
+
const HOST_KEYS = [
|
|
467
|
+
'label',
|
|
468
|
+
'action',
|
|
469
|
+
'at',
|
|
470
|
+
'patterns',
|
|
471
|
+
'compiled',
|
|
472
|
+
'find',
|
|
473
|
+
'hint',
|
|
474
|
+
];
|
|
475
|
+
/** What is wrong with a detector of the host's own. It has no default, so it says what it reads with and where. */
|
|
476
|
+
function hostProblem(path, id, rule, boundaries) {
|
|
477
|
+
if (!/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+$/.test(id)) {
|
|
478
|
+
return `${path}: a detector of your own is keyed namespace.name in lower case, digits and _, as in acme.record`;
|
|
479
|
+
}
|
|
480
|
+
if (!isRecord(rule))
|
|
481
|
+
return `${path} must be an object: a label, an action or at, and patterns or find`;
|
|
482
|
+
const unknown = Object.keys(rule).find((key) => !HOST_KEYS.includes(key));
|
|
483
|
+
if (unknown !== undefined) {
|
|
484
|
+
return `${path}.${unknown} is not a setting of a detector of your own (${HOST_KEYS.join(', ')})`;
|
|
485
|
+
}
|
|
486
|
+
const { label, action, at, patterns, compiled, find, hint } = rule;
|
|
487
|
+
if (typeof label !== 'string' || !label.trim())
|
|
488
|
+
return `${path}.label must be a non-empty string`;
|
|
489
|
+
if (action !== undefined && !isAction(action))
|
|
490
|
+
return `${path}.action must be one of ${ACTION_LIST}`;
|
|
491
|
+
if (action === undefined && at === undefined) {
|
|
492
|
+
return `${path} needs an action or at: a detector of your own has no default`;
|
|
493
|
+
}
|
|
494
|
+
if (find !== undefined && typeof find !== 'function')
|
|
495
|
+
return `${path}.find must be a function`;
|
|
496
|
+
if (patterns === undefined && find === undefined) {
|
|
497
|
+
return `${path} needs patterns or find: it has nothing to read with`;
|
|
498
|
+
}
|
|
499
|
+
return (atProblem(`${path}.at`, at, boundaries) ??
|
|
500
|
+
hintProblem(`${path}.hint`, hint) ??
|
|
501
|
+
patternsProblem(path, patterns, compiled));
|
|
502
|
+
}
|
|
503
|
+
export { actionAt, DETECT_ACTION_META, DETECT_ACTIONS, DETECT_DEFAULTS, DETECTOR_BOUNDARIES, DETECTOR_GROUP_META, DETECTOR_GROUPS, DETECTOR_META, DETECTORS, detectProblem, detects, HOST_FIND_HOLD, HOST_FIND_HOLD_LIVE, hintProblem, isDetector, NO_ALLOW, PATTERN_DETECTORS, resolveAllow, resolveDetect, };
|
|
@@ -4,11 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
/** Each injection pattern reversed: it matches where the pattern matches the text written backwards. */
|
|
9
|
-
declare const REVERSED_INJECTION_PATTERNS: RegExp[];
|
|
7
|
+
import type { AutomatonData } from './host-patterns.js';
|
|
10
8
|
/** Every egress pattern, loosened to a superset automaton, in `EGRESS_PATTERNS` order. */
|
|
11
|
-
declare const FORWARD_AUTOMATON:
|
|
9
|
+
declare const FORWARD_AUTOMATON: AutomatonData;
|
|
12
10
|
/** Each reversed injection pattern, loosened the same way. */
|
|
13
|
-
declare const REVERSED_AUTOMATON:
|
|
14
|
-
export { FORWARD_AUTOMATON, REVERSED_AUTOMATON
|
|
11
|
+
declare const REVERSED_AUTOMATON: AutomatonData;
|
|
12
|
+
export { FORWARD_AUTOMATON, REVERSED_AUTOMATON };
|