@theoremjs/agents 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1264 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +65 -0
- package/esm/mod.js +42 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +458 -0
- package/esm/src/cli/commands/egress-compile.d.ts +17 -0
- package/esm/src/cli/commands/egress-compile.js +25 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +202 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +25 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +72 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +4 -0
- package/esm/src/evals/attachments.js +53 -0
- package/esm/src/evals/breakdown.d.ts +28 -0
- package/esm/src/evals/breakdown.js +68 -0
- package/esm/src/evals/graders/answer.d.ts +13 -0
- package/esm/src/evals/graders/answer.js +133 -0
- package/esm/src/evals/graders/code.d.ts +64 -0
- package/esm/src/evals/graders/code.js +205 -0
- package/esm/src/evals/graders/judge.d.ts +20 -0
- package/esm/src/evals/graders/judge.js +365 -0
- package/esm/src/evals/graders/latency.d.ts +5 -0
- package/esm/src/evals/graders/latency.js +81 -0
- package/esm/src/evals/graders/live.d.ts +11 -0
- package/esm/src/evals/graders/live.js +40 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +92 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +17 -0
- package/esm/src/evals/graders/transcript.js +200 -0
- package/esm/src/evals/mod.d.ts +42 -0
- package/esm/src/evals/mod.js +30 -0
- package/esm/src/evals/record.d.ts +35 -0
- package/esm/src/evals/record.js +105 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +118 -0
- package/esm/src/evals/run.js +452 -0
- package/esm/src/evals/suite.d.ts +19 -0
- package/esm/src/evals/suite.js +92 -0
- package/esm/src/evals/summary.d.ts +32 -0
- package/esm/src/evals/summary.js +30 -0
- package/esm/src/evals/trial.d.ts +27 -0
- package/esm/src/evals/trial.js +158 -0
- package/esm/src/evals/types.d.ts +260 -0
- package/esm/src/evals/types.js +126 -0
- package/esm/src/evals/verdict.d.ts +18 -0
- package/esm/src/evals/verdict.js +45 -0
- package/esm/src/guardrails/canary-gate.d.ts +21 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +112 -0
- package/esm/src/guardrails/canary.js +901 -0
- package/esm/src/guardrails/compile-egress.d.ts +11 -0
- package/esm/src/guardrails/compile-egress.js +11 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +22 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +303 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +202 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +3 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +118 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +13 -0
- package/esm/src/guardrails/corpus/live-attacks.js +224 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +32 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/egress-automata.d.ts +14 -0
- package/esm/src/guardrails/egress-automata.js +6059 -0
- package/esm/src/guardrails/egress-compiler.d.ts +33 -0
- package/esm/src/guardrails/egress-compiler.js +237 -0
- package/esm/src/guardrails/egress-patterns.d.ts +24 -0
- package/esm/src/guardrails/egress-patterns.js +32 -0
- package/esm/src/guardrails/egress-policy.d.ts +27 -0
- package/esm/src/guardrails/egress-policy.js +76 -0
- package/esm/src/guardrails/egress-rules.d.ts +54 -0
- package/esm/src/guardrails/egress-rules.js +49 -0
- package/esm/src/guardrails/egress-stream.d.ts +105 -0
- package/esm/src/guardrails/egress-stream.js +645 -0
- package/esm/src/guardrails/egress-urls.d.ts +83 -0
- package/esm/src/guardrails/egress-urls.js +917 -0
- package/esm/src/guardrails/egress.d.ts +106 -0
- package/esm/src/guardrails/egress.js +374 -0
- package/esm/src/guardrails/error.d.ts +26 -0
- package/esm/src/guardrails/error.js +91 -0
- package/esm/src/guardrails/event-schemas.d.ts +57 -0
- package/esm/src/guardrails/event-schemas.js +41 -0
- package/esm/src/guardrails/events.d.ts +9 -0
- package/esm/src/guardrails/events.js +42 -0
- package/esm/src/guardrails/hits.d.ts +8 -0
- package/esm/src/guardrails/hits.js +19 -0
- package/esm/src/guardrails/injection-patterns.d.ts +15 -0
- package/esm/src/guardrails/injection-patterns.js +94 -0
- package/esm/src/guardrails/injection.d.ts +14 -0
- package/esm/src/guardrails/injection.js +237 -0
- package/esm/src/guardrails/lexicon.d.ts +30 -0
- package/esm/src/guardrails/lexicon.js +478 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +54 -0
- package/esm/src/guardrails/live-outbound-gate.js +305 -0
- package/esm/src/guardrails/mod.d.ts +46 -0
- package/esm/src/guardrails/mod.js +29 -0
- package/esm/src/guardrails/network.d.ts +42 -0
- package/esm/src/guardrails/network.js +328 -0
- package/esm/src/guardrails/normalize.d.ts +6 -0
- package/esm/src/guardrails/normalize.js +132 -0
- package/esm/src/guardrails/policy.d.ts +19 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +69 -0
- package/esm/src/guardrails/progressive-yield.js +237 -0
- package/esm/src/guardrails/prompt-echo.d.ts +38 -0
- package/esm/src/guardrails/prompt-echo.js +225 -0
- package/esm/src/guardrails/quota.d.ts +20 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +56 -0
- package/esm/src/guardrails/rules.js +54 -0
- package/esm/src/guardrails/sanitize.d.ts +23 -0
- package/esm/src/guardrails/sanitize.js +184 -0
- package/esm/src/guardrails/sensitive.d.ts +29 -0
- package/esm/src/guardrails/sensitive.js +113 -0
- package/esm/src/guardrails/serialize.d.ts +14 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +9 -0
- package/esm/src/guardrails/testing.js +8 -0
- package/esm/src/guardrails/theorem-error.d.ts +18 -0
- package/esm/src/guardrails/theorem-error.js +53 -0
- package/esm/src/guardrails/thought-guard.d.ts +55 -0
- package/esm/src/guardrails/thought-guard.js +464 -0
- package/esm/src/guardrails/tool-directives.d.ts +19 -0
- package/esm/src/guardrails/tool-directives.js +109 -0
- package/esm/src/guardrails/tool-result.d.ts +61 -0
- package/esm/src/guardrails/tool-result.js +248 -0
- package/esm/src/guardrails/types.d.ts +242 -0
- package/esm/src/guardrails/types.js +54 -0
- package/esm/src/host/client-turn.d.ts +9 -0
- package/esm/src/host/client-turn.js +38 -0
- package/esm/src/host/mint-trace.d.ts +28 -0
- package/esm/src/host/mint-trace.js +59 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +68 -0
- package/esm/src/host/reply.d.ts +7 -0
- package/esm/src/host/reply.js +35 -0
- package/esm/src/interface/blocks.d.ts +8 -0
- package/esm/src/interface/blocks.js +213 -0
- package/esm/src/interface/composer-actions.d.ts +20 -0
- package/esm/src/interface/composer-actions.js +31 -0
- package/esm/src/interface/draft.d.ts +14 -0
- package/esm/src/interface/draft.js +28 -0
- package/esm/src/interface/from-profile.d.ts +12 -0
- package/esm/src/interface/from-profile.js +144 -0
- package/esm/src/interface/history.d.ts +40 -0
- package/esm/src/interface/history.js +269 -0
- package/esm/src/interface/inputs.d.ts +10 -0
- package/esm/src/interface/inputs.js +64 -0
- package/esm/src/interface/mod.d.ts +31 -0
- package/esm/src/interface/mod.js +21 -0
- package/esm/src/interface/models.d.ts +19 -0
- package/esm/src/interface/models.js +45 -0
- package/esm/src/interface/pending.d.ts +48 -0
- package/esm/src/interface/pending.js +146 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +223 -0
- package/esm/src/interface/session.d.ts +64 -0
- package/esm/src/interface/session.js +121 -0
- package/esm/src/interface/tool-calls.d.ts +20 -0
- package/esm/src/interface/tool-calls.js +73 -0
- package/esm/src/interface/tool-invoke.d.ts +4 -0
- package/esm/src/interface/tool-invoke.js +20 -0
- package/esm/src/interface/tool-media.d.ts +9 -0
- package/esm/src/interface/tool-media.js +112 -0
- package/esm/src/interface/types.d.ts +213 -0
- package/esm/src/interface/types.js +4 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +51 -0
- package/esm/src/kernel/auth/crypto.js +161 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +17 -0
- package/esm/src/kernel/auth/oauth.js +438 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +139 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/default-scope.d.ts +34 -0
- package/esm/src/kernel/default-scope.js +72 -0
- package/esm/src/kernel/engine/compaction.d.ts +70 -0
- package/esm/src/kernel/engine/compaction.js +202 -0
- package/esm/src/kernel/engine/decision.d.ts +41 -0
- package/esm/src/kernel/engine/decision.js +412 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +19 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +9 -0
- package/esm/src/kernel/engine/live-ingress.js +37 -0
- package/esm/src/kernel/engine/media-probe/audio.d.ts +7 -0
- package/esm/src/kernel/engine/media-probe/audio.js +342 -0
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +6 -0
- package/esm/src/kernel/engine/media-probe/bytes.js +26 -0
- package/esm/src/kernel/engine/media-probe/image.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/image.js +171 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +19 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +48 -0
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +35 -0
- package/esm/src/kernel/engine/media-probe/matroska.js +226 -0
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +22 -0
- package/esm/src/kernel/engine/media-probe/mp4.js +279 -0
- package/esm/src/kernel/engine/media-probe/opus.d.ts +4 -0
- package/esm/src/kernel/engine/media-probe/opus.js +23 -0
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/pdf.js +117 -0
- package/esm/src/kernel/engine/media-probe/video.d.ts +15 -0
- package/esm/src/kernel/engine/media-probe/video.js +49 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +322 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +15 -0
- package/esm/src/kernel/engine/runner/mod.js +574 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +14 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +105 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +48 -0
- package/esm/src/kernel/engine/runner/state.d.ts +76 -0
- package/esm/src/kernel/engine/runner/state.js +40 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +360 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +40 -0
- package/esm/src/kernel/engine/runner/stream.js +225 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +150 -0
- package/esm/src/kernel/engine/session/mod.d.ts +31 -0
- package/esm/src/kernel/engine/session/mod.js +951 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +489 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +77 -0
- package/esm/src/kernel/engine/token-estimate.js +218 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +131 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +118 -0
- package/esm/src/kernel/engine/turn-trace.js +863 -0
- package/esm/src/kernel/engine/usage.d.ts +30 -0
- package/esm/src/kernel/engine/usage.js +134 -0
- package/esm/src/kernel/interaction-parts.d.ts +10 -0
- package/esm/src/kernel/interaction-parts.js +22 -0
- package/esm/src/kernel/mod.d.ts +47 -0
- package/esm/src/kernel/mod.js +30 -0
- package/esm/src/kernel/profile-graph.d.ts +140 -0
- package/esm/src/kernel/profile-graph.js +151 -0
- package/esm/src/kernel/profile-presence.d.ts +9 -0
- package/esm/src/kernel/profile-presence.js +143 -0
- package/esm/src/kernel/profile-scope.d.ts +36 -0
- package/esm/src/kernel/profile-scope.js +262 -0
- package/esm/src/kernel/registry/attachments.d.ts +35 -0
- package/esm/src/kernel/registry/attachments.js +211 -0
- package/esm/src/kernel/registry/catalog.d.ts +19 -0
- package/esm/src/kernel/registry/catalog.js +78 -0
- package/esm/src/kernel/registry/ingress.d.ts +8 -0
- package/esm/src/kernel/registry/ingress.js +134 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +12 -0
- package/esm/src/kernel/registry/kernel-registry.js +8 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +7 -0
- package/esm/src/kernel/registry/profiles.d.ts +92 -0
- package/esm/src/kernel/registry/profiles.js +698 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +42 -0
- package/esm/src/kernel/registry/resolve.d.ts +14 -0
- package/esm/src/kernel/registry/resolve.js +237 -0
- package/esm/src/kernel/registry/schemas.d.ts +9 -0
- package/esm/src/kernel/registry/schemas.js +25 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +33 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +13 -0
- package/esm/src/kernel/registry/vault.js +14 -0
- package/esm/src/kernel/schema.d.ts +172 -0
- package/esm/src/kernel/schema.js +653 -0
- package/esm/src/kernel/scope.d.ts +22 -0
- package/esm/src/kernel/scope.js +25 -0
- package/esm/src/kernel/stages.d.ts +141 -0
- package/esm/src/kernel/stages.js +388 -0
- package/esm/src/kernel/stop.d.ts +93 -0
- package/esm/src/kernel/stop.js +125 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +16 -0
- package/esm/src/kernel/tools/activity-label.js +209 -0
- package/esm/src/kernel/tools/events.d.ts +51 -0
- package/esm/src/kernel/tools/events.js +149 -0
- package/esm/src/kernel/tools/execute.d.ts +64 -0
- package/esm/src/kernel/tools/execute.js +801 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +50 -0
- package/esm/src/kernel/tools/gate-answer.js +54 -0
- package/esm/src/kernel/tools/harness.d.ts +16 -0
- package/esm/src/kernel/tools/harness.js +42 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +129 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +20 -0
- package/esm/src/kernel/tools/mcp-sessions.js +64 -0
- package/esm/src/kernel/tools/mod.d.ts +9 -0
- package/esm/src/kernel/tools/mod.js +6 -0
- package/esm/src/kernel/tools/model-text.d.ts +11 -0
- package/esm/src/kernel/tools/model-text.js +25 -0
- package/esm/src/kernel/tools/permission.d.ts +6 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +8 -0
- package/esm/src/kernel/tools/project.js +25 -0
- package/esm/src/kernel/tools/registry.d.ts +20 -0
- package/esm/src/kernel/tools/registry.js +84 -0
- package/esm/src/kernel/tools/remote.d.ts +110 -0
- package/esm/src/kernel/tools/remote.js +998 -0
- package/esm/src/kernel/tools/resolve.d.ts +28 -0
- package/esm/src/kernel/tools/resolve.js +259 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +174 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +18 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +93 -0
- package/esm/src/kernel/tools/stage-run.js +140 -0
- package/esm/src/kernel/tools/types.d.ts +287 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/turn-events.d.ts +599 -0
- package/esm/src/kernel/turn-events.js +425 -0
- package/esm/src/kernel/types.d.ts +884 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +13 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +3 -0
- package/esm/src/observability/destinations.d.ts +9 -0
- package/esm/src/observability/destinations.js +38 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +117 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +68 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +29 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +14 -0
- package/esm/src/observability/policy.js +69 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +58 -0
- package/esm/src/observability/spans.d.ts +16 -0
- package/esm/src/observability/spans.js +56 -0
- package/esm/src/observability/trace-catalog.d.ts +111 -0
- package/esm/src/observability/trace-catalog.js +865 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +223 -0
- package/esm/src/observability/trace-schema.d.ts +54 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +13 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +92 -0
- package/esm/src/observability/trace-span.js +199 -0
- package/esm/src/observability/trace.d.ts +11 -0
- package/esm/src/observability/trace.js +35 -0
- package/esm/src/observability/types.d.ts +85 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +8 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +12 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +104 -0
- package/esm/src/presets/google.js +188 -0
- package/esm/src/presets/mod.d.ts +10 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +13 -0
- package/esm/src/presets/openrouter.js +13 -0
- package/esm/src/presets/typesafe.d.ts +2 -0
- package/esm/src/presets/typesafe.js +2 -0
- package/esm/src/providers/create-provider.d.ts +21 -0
- package/esm/src/providers/create-provider.js +90 -0
- package/esm/src/providers/decision/usage.d.ts +3 -0
- package/esm/src/providers/decision/usage.js +25 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +263 -0
- package/esm/src/providers/google/interactions/mod.d.ts +2 -0
- package/esm/src/providers/google/interactions/mod.js +2 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +24 -0
- package/esm/src/providers/google/interactions/stream.js +297 -0
- package/esm/src/providers/google/keys.d.ts +20 -0
- package/esm/src/providers/google/keys.js +87 -0
- package/esm/src/providers/google/live/framing.d.ts +51 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/mod.d.ts +7 -0
- package/esm/src/providers/google/live/mod.js +7 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +1 -0
- package/esm/src/providers/google/live/openapi-schema.js +42 -0
- package/esm/src/providers/google/live/session.d.ts +14 -0
- package/esm/src/providers/google/live/session.js +150 -0
- package/esm/src/providers/google/live/stream.d.ts +51 -0
- package/esm/src/providers/google/live/stream.js +263 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/local/local.d.ts +12 -0
- package/esm/src/providers/local/local.js +186 -0
- package/esm/src/providers/local/mod.d.ts +8 -0
- package/esm/src/providers/local/mod.js +8 -0
- package/esm/src/providers/mod.d.ts +11 -0
- package/esm/src/providers/mod.js +7 -0
- package/esm/src/providers/openrouter/cache-control.d.ts +5 -0
- package/esm/src/providers/openrouter/cache-control.js +4 -0
- package/esm/src/providers/openrouter/chat.d.ts +64 -0
- package/esm/src/providers/openrouter/chat.js +490 -0
- package/esm/src/providers/openrouter/image.d.ts +24 -0
- package/esm/src/providers/openrouter/image.js +187 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +10 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +99 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +3 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +8 -0
- package/esm/src/providers/openrouter/speech.d.ts +18 -0
- package/esm/src/providers/openrouter/speech.js +109 -0
- package/esm/src/providers/probe.d.ts +5 -0
- package/esm/src/providers/probe.js +15 -0
- package/esm/src/providers/shared/builtin-wire.d.ts +4 -0
- package/esm/src/providers/shared/builtin-wire.js +9 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/sse.d.ts +10 -0
- package/esm/src/providers/shared/sse.js +79 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +25 -0
- package/esm/src/providers/shared/tool-args.js +84 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/shared/vault.d.ts +13 -0
- package/esm/src/providers/shared/vault.js +41 -0
- package/esm/src/providers/types.d.ts +19 -0
- package/esm/src/providers/types.js +1 -0
- package/esm/src/surface/formats.d.ts +28 -0
- package/esm/src/surface/formats.js +139 -0
- package/esm/src/surface/mod.d.ts +14 -0
- package/esm/src/surface/mod.js +10 -0
- package/esm/src/surface/runtime.d.ts +40 -0
- package/esm/src/surface/runtime.js +439 -0
- package/esm/src/surface/tools.d.ts +15 -0
- package/esm/src/surface/tools.js +80 -0
- package/esm/src/surface/types.d.ts +104 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +108 -4
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { lexiconText } from './lexicon.js';
|
|
2
|
+
import { detectionForTrust } from './policy.js';
|
|
3
|
+
import { TOOL_RULES } from './rules.js';
|
|
4
|
+
import { sanitizeText } from './sanitize.js';
|
|
5
|
+
import { anySensitive } from './sensitive.js';
|
|
6
|
+
import { textForScan } from './serialize.js';
|
|
7
|
+
import { advisoryLevel, directiveHits } from './tool-directives.js';
|
|
8
|
+
const TOOL_CLOSE = '</tool_data>';
|
|
9
|
+
const TOOL_OPEN = '<tool_data';
|
|
10
|
+
/** Origins whose bytes the host does not author and cannot vouch for. */
|
|
11
|
+
const REMOTE_ORIGINS = new Set(['http', 'mcp', 'delegated']);
|
|
12
|
+
function isRemoteOrigin(origin) {
|
|
13
|
+
return REMOTE_ORIGINS.has(origin);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Strip fence markers a tool result tried to forge before wrapping it.
|
|
17
|
+
* Linear scan — avoids polynomial regex on forged `<tool_data…>` runs.
|
|
18
|
+
*/
|
|
19
|
+
function stripToolFences(text) {
|
|
20
|
+
const lower = text.toLowerCase();
|
|
21
|
+
let out = '';
|
|
22
|
+
let i = 0;
|
|
23
|
+
while (i < text.length) {
|
|
24
|
+
const openAt = lower.indexOf(TOOL_OPEN, i);
|
|
25
|
+
const closeAt = lower.indexOf(TOOL_CLOSE, i);
|
|
26
|
+
let next = -1;
|
|
27
|
+
let kind = null;
|
|
28
|
+
if (openAt >= 0 && (closeAt < 0 || openAt <= closeAt)) {
|
|
29
|
+
next = openAt;
|
|
30
|
+
kind = 'open';
|
|
31
|
+
}
|
|
32
|
+
else if (closeAt >= 0) {
|
|
33
|
+
next = closeAt;
|
|
34
|
+
kind = 'close';
|
|
35
|
+
}
|
|
36
|
+
if (next < 0 || kind === null) {
|
|
37
|
+
out += text.slice(i);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
out += text.slice(i, next);
|
|
41
|
+
if (kind === 'close') {
|
|
42
|
+
i = next + TOOL_CLOSE.length;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const gt = text.indexOf('>', next + TOOL_OPEN.length);
|
|
46
|
+
if (gt < 0) {
|
|
47
|
+
out += text.slice(next);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
i = gt + 1;
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The origin is on the tag rather than in prose so a result cannot claim a
|
|
56
|
+
* friendlier provenance than it has by writing one into its own body.
|
|
57
|
+
*/
|
|
58
|
+
function wrapToolData(text, provenance, advisory = 'none', lexicon) {
|
|
59
|
+
const guidance = lexiconText('advisory.guidance', {}, lexicon).trim();
|
|
60
|
+
const attrs = `tool="${provenance.tool}" origin="${provenance.origin}"` +
|
|
61
|
+
(advisory === 'none' ? '' : ` advisory="${advisory}"`);
|
|
62
|
+
const notice = advisory === 'none'
|
|
63
|
+
? ''
|
|
64
|
+
: `${advisoryNotice(advisory, lexicon)}${guidance ? ` ${guidance}` : ''}\n`;
|
|
65
|
+
return `<${'tool_data'} ${attrs}>\n${notice}${stripToolFences(text)}\n${TOOL_CLOSE}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Deliberately an observation, not an instruction: what the agent should do about
|
|
69
|
+
* it is product behaviour, supplied by the host as lexicon `advisory.guidance`. Emitted
|
|
70
|
+
* only when signals fired, so it stays rare enough to carry weight — a warning on
|
|
71
|
+
* every fetch is one the model learns to skip.
|
|
72
|
+
*/
|
|
73
|
+
function advisoryNotice(advisory, lexicon) {
|
|
74
|
+
const key = advisory === 'high' ? 'advisory.notice_high' : 'advisory.notice_elevated';
|
|
75
|
+
return lexiconText(key, {}, lexicon);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* `finding` is the tool's summary and `data` its structured payload; both reach
|
|
79
|
+
* the model, so both are guarded together rather than only the prose half.
|
|
80
|
+
*/
|
|
81
|
+
function composeToolText(finding, data) {
|
|
82
|
+
if (data === undefined) {
|
|
83
|
+
return finding;
|
|
84
|
+
}
|
|
85
|
+
const rendered = textForScan(data);
|
|
86
|
+
if (rendered.unscannable) {
|
|
87
|
+
return finding;
|
|
88
|
+
}
|
|
89
|
+
return `${finding}\n${rendered.text}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Local host tools are still detected — a host tool reading a database returns
|
|
93
|
+
* data the host did not write — but only remote origins are fenced, because
|
|
94
|
+
* fencing a local tool's output would change prompts hosts have already tuned.
|
|
95
|
+
*/
|
|
96
|
+
function guardToolResult(finding, data, provenance, policy, callableTools = [], lexicon) {
|
|
97
|
+
const composed = composeToolText(finding, data);
|
|
98
|
+
const options = detectionForTrust(policy, 'untrusted');
|
|
99
|
+
const redacted = sanitizeText(composed, options);
|
|
100
|
+
const changed = redacted !== composed;
|
|
101
|
+
// Directive detection runs on remote content only: a local tool's output is
|
|
102
|
+
// bytes the host's own code produced.
|
|
103
|
+
const remote = isRemoteOrigin(provenance.origin);
|
|
104
|
+
const suspicious = remote ? directiveHits(composed, callableTools) : [];
|
|
105
|
+
const advisory = advisoryLevel(suspicious);
|
|
106
|
+
const fenced = remote ? wrapToolData(redacted, provenance, advisory, lexicon) : redacted;
|
|
107
|
+
const hits = [
|
|
108
|
+
...(changed ? [{ rule: TOOL_RULES.resultRedacted, severity: 'medium' }] : []),
|
|
109
|
+
...suspicious,
|
|
110
|
+
];
|
|
111
|
+
if (hits.length === 0) {
|
|
112
|
+
return { text: fenced };
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
text: fenced,
|
|
116
|
+
...(suspicious.length > 0 ? { suspicious } : {}),
|
|
117
|
+
event: {
|
|
118
|
+
stage: 'tool_result',
|
|
119
|
+
trust: 'untrusted',
|
|
120
|
+
// Redaction changed the text; directive signals only annotate it.
|
|
121
|
+
action: changed ? 'redact' : 'flag',
|
|
122
|
+
hits,
|
|
123
|
+
provenance,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A remote server authors its own error strings, so an unguarded failure message
|
|
129
|
+
* is the cleanest injection path across this boundary: it reaches the model
|
|
130
|
+
* verbatim and is framed by the kernel as a system report.
|
|
131
|
+
*/
|
|
132
|
+
function guardToolFailureText(message, provenance, policy) {
|
|
133
|
+
const options = detectionForTrust(policy, 'untrusted');
|
|
134
|
+
const redacted = sanitizeText(stripToolFences(message), options);
|
|
135
|
+
if (redacted === message) {
|
|
136
|
+
return { text: redacted };
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
text: redacted,
|
|
140
|
+
event: {
|
|
141
|
+
stage: 'tool_result',
|
|
142
|
+
trust: 'untrusted',
|
|
143
|
+
action: 'redact',
|
|
144
|
+
hits: [{ rule: TOOL_RULES.failureRedacted, severity: 'medium' }],
|
|
145
|
+
provenance,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Arguments are model-authored, so the risk is not instruction smuggling but
|
|
151
|
+
* exfiltration: a credential lifted from context and posted outward as a
|
|
152
|
+
* parameter. Detection reports rather than rewrites — silently altering a tool
|
|
153
|
+
* argument would make the call succeed against something the model did not ask
|
|
154
|
+
* for.
|
|
155
|
+
*/
|
|
156
|
+
function inspectToolArguments(args, policy) {
|
|
157
|
+
if (!anySensitive(policy.redactSensitive)) {
|
|
158
|
+
return { action: 'allow' };
|
|
159
|
+
}
|
|
160
|
+
const rendered = textForScan(args);
|
|
161
|
+
if (rendered.unscannable) {
|
|
162
|
+
return { action: 'allow' };
|
|
163
|
+
}
|
|
164
|
+
const options = { sanitizeInput: false, redactSensitive: policy.redactSensitive };
|
|
165
|
+
if (sanitizeText(rendered.text, options) === rendered.text) {
|
|
166
|
+
return { action: 'allow' };
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
action: 'flag',
|
|
170
|
+
hits: [{ rule: TOOL_RULES.sensitiveArgument, severity: 'high' }],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function toolCallEvent(verdict, provenance) {
|
|
174
|
+
if (verdict.action === 'allow') {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
stage: 'tool_call',
|
|
179
|
+
trust: 'untrusted',
|
|
180
|
+
action: verdict.action,
|
|
181
|
+
hits: verdict.hits,
|
|
182
|
+
provenance,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Only remote origins taint: a local host tool returns bytes the host's own code
|
|
187
|
+
* produced, and treating those as attacker-influenceable would make the gate
|
|
188
|
+
* useless in practice.
|
|
189
|
+
*/
|
|
190
|
+
function recordTaint(taint, provenance, suspicious = []) {
|
|
191
|
+
const sources = taint?.sources ?? [];
|
|
192
|
+
const prior = taint?.suspicious ?? [];
|
|
193
|
+
if (!isRemoteOrigin(provenance.origin)) {
|
|
194
|
+
return { sources, suspicious: prior };
|
|
195
|
+
}
|
|
196
|
+
return { sources: [...sources, provenance], suspicious: [...prior, ...suspicious] };
|
|
197
|
+
}
|
|
198
|
+
function isTainted(taint) {
|
|
199
|
+
return (taint?.sources.length ?? 0) > 0;
|
|
200
|
+
}
|
|
201
|
+
function isSuspicious(taint) {
|
|
202
|
+
return (taint?.suspicious.length ?? 0) > 0;
|
|
203
|
+
}
|
|
204
|
+
/** Capability rank, so a single threshold can express "this and anything worse". */
|
|
205
|
+
const CAPABILITY_RANK = {
|
|
206
|
+
'read-only': 0,
|
|
207
|
+
'read-write': 1,
|
|
208
|
+
destructive: 2,
|
|
209
|
+
};
|
|
210
|
+
const GATE_RANK = {
|
|
211
|
+
off: Number.POSITIVE_INFINITY,
|
|
212
|
+
destructive: 2,
|
|
213
|
+
write: 1,
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* A `flag` says the call is happening on a tainted turn and is worth recording; a
|
|
217
|
+
* `block` says the profile asked for it to be refused. Reporting happens whether
|
|
218
|
+
* or not enforcement is configured, so the risk is visible before a host opts in.
|
|
219
|
+
*/
|
|
220
|
+
function checkTaintGate(taint, access, policy, lexicon) {
|
|
221
|
+
if (!isTainted(taint)) {
|
|
222
|
+
return { action: 'allow' };
|
|
223
|
+
}
|
|
224
|
+
const rank = CAPABILITY_RANK[access] ?? 0;
|
|
225
|
+
if (rank === 0) {
|
|
226
|
+
return { action: 'allow' };
|
|
227
|
+
}
|
|
228
|
+
const suspicious = isSuspicious(taint);
|
|
229
|
+
const hits = [
|
|
230
|
+
{
|
|
231
|
+
rule: suspicious ? TOOL_RULES.steeredTurn : TOOL_RULES.taintedTurn,
|
|
232
|
+
severity: 'high',
|
|
233
|
+
},
|
|
234
|
+
];
|
|
235
|
+
// Gated on origin alone. Whether the content looked directive changes the rule
|
|
236
|
+
// reported, never whether the call is refused.
|
|
237
|
+
if (rank < GATE_RANK[policy.taint?.afterRemoteRead ?? 'off']) {
|
|
238
|
+
return { action: 'flag', hits };
|
|
239
|
+
}
|
|
240
|
+
const read = taint?.sources.map((s) => s.tool).join(', ') ?? '';
|
|
241
|
+
const reason = lexiconText(suspicious ? 'taint.reason_steered' : 'taint.reason_tainted', {}, lexicon);
|
|
242
|
+
return {
|
|
243
|
+
action: 'block',
|
|
244
|
+
hits,
|
|
245
|
+
rejection: lexiconText('taint.blocked', { access, sources: read, reason }, lexicon),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
export { checkTaintGate, composeToolText, guardToolFailureText, guardToolResult, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, recordTaint, TOOL_CLOSE, toolCallEvent, wrapToolData, };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type { EgressChecks } from './egress.js';
|
|
2
|
+
import type { GivenUrls } from './egress-urls.js';
|
|
3
|
+
import type { GuardrailEvent, GuardrailHit, Provenance } from './event-schemas.js';
|
|
4
|
+
import type { LexiconOverrides } from './lexicon.js';
|
|
5
|
+
import type { SensitiveGroups, SensitiveSelection } from './sensitive.js';
|
|
6
|
+
export type { GuardrailEvent, GuardrailHit, Provenance };
|
|
7
|
+
/**
|
|
8
|
+
* - `trusted` — author-time profile text (`identity.system`). Sensitive redaction
|
|
9
|
+
* only; injection redaction would mangle the host's own instructions.
|
|
10
|
+
* - `assembled` — host-built per turn (`req.system`). Interpolates retrieval and
|
|
11
|
+
* user data, so it is permeable and takes full detection.
|
|
12
|
+
* - `untrusted` — user input, tool results, attachments, delegated agents.
|
|
13
|
+
*/
|
|
14
|
+
export declare const TRUST_LEVELS: readonly ["trusted", "assembled", "untrusted"];
|
|
15
|
+
export type TrustLevel = (typeof TRUST_LEVELS)[number];
|
|
16
|
+
export declare const GUARDRAIL_STAGES: readonly ["input", "history", "system", "attachment", "tool_call", "tool_result", "output_delta", "output_final", "thought", "network", "live_inbound", "live_outbound", "trace"];
|
|
17
|
+
export type GuardrailStage = (typeof GUARDRAIL_STAGES)[number];
|
|
18
|
+
/** Does not decide what happens next; that is `onBlock`. */
|
|
19
|
+
export declare const SEVERITIES: readonly ["info", "low", "medium", "high"];
|
|
20
|
+
export type Severity = (typeof SEVERITIES)[number];
|
|
21
|
+
export declare const EGRESS_ON_BLOCK: readonly ["reject_to_agent", "refuse_to_user"];
|
|
22
|
+
export type EgressOnBlock = (typeof EGRESS_ON_BLOCK)[number];
|
|
23
|
+
/**
|
|
24
|
+
* A discriminated union so a new variant fails every unhandled `switch` at
|
|
25
|
+
* compile time rather than falling through at runtime.
|
|
26
|
+
*/
|
|
27
|
+
export type Verdict = {
|
|
28
|
+
action: 'allow';
|
|
29
|
+
} | {
|
|
30
|
+
action: 'redact';
|
|
31
|
+
text: string;
|
|
32
|
+
hits: GuardrailHit[];
|
|
33
|
+
} | {
|
|
34
|
+
action: 'flag';
|
|
35
|
+
hits: GuardrailHit[];
|
|
36
|
+
} | {
|
|
37
|
+
action: 'block';
|
|
38
|
+
hits: GuardrailHit[];
|
|
39
|
+
/**
|
|
40
|
+
* Sent to the model on a repair turn when `onBlock` is `reject_to_agent`.
|
|
41
|
+
* With `refuse_to_user` the user reads the lexicon's `egress.refusal`.
|
|
42
|
+
*/
|
|
43
|
+
rejection: string;
|
|
44
|
+
/**
|
|
45
|
+
* Why the check blocked, for the builder only: it reaches the host and the
|
|
46
|
+
* trace (content-gated), never the model or a client (`forClient`).
|
|
47
|
+
*/
|
|
48
|
+
errorInternal?: string;
|
|
49
|
+
};
|
|
50
|
+
export declare const GUARDRAIL_ACTIONS: readonly ["allow", "redact", "flag", "block"];
|
|
51
|
+
export type GuardrailAction = (typeof GUARDRAIL_ACTIONS)[number];
|
|
52
|
+
/**
|
|
53
|
+
* `local` is host TypeScript the profile registered; `http` and `mcp` are remote
|
|
54
|
+
* services whose bytes the host does not control. `delegated` is another agent
|
|
55
|
+
* answering through the tool boundary — its output is model-generated prose that
|
|
56
|
+
* reads as authoritative, which is why depth is tracked separately.
|
|
57
|
+
*/
|
|
58
|
+
export declare const TOOL_ORIGINS: readonly ["local", "builtin", "http", "mcp", "delegated"];
|
|
59
|
+
export type ToolOrigin = (typeof TOOL_ORIGINS)[number];
|
|
60
|
+
/**
|
|
61
|
+
* Once a turn has read attacker-influenceable bytes, a later tool call is a
|
|
62
|
+
* confused-deputy risk: the content can ask the agent to act, and the agent has
|
|
63
|
+
* authority the content does not. Sources are kept in order so a policy can reason
|
|
64
|
+
* about depth as well as presence.
|
|
65
|
+
*/
|
|
66
|
+
export interface TurnTaint {
|
|
67
|
+
sources: Provenance[];
|
|
68
|
+
/**
|
|
69
|
+
* Separates "read something remote" from "read something that tried to steer
|
|
70
|
+
* me". The second is far rarer, so a gate keyed on it refuses far less
|
|
71
|
+
* legitimate work.
|
|
72
|
+
*/
|
|
73
|
+
suspicious: GuardrailHit[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Not a probability: there is no calibrated model behind it. `elevated` means one
|
|
77
|
+
* directive signal alongside an external destination; `high` means the content
|
|
78
|
+
* named a tool the model can call, or several signals agreed.
|
|
79
|
+
*/
|
|
80
|
+
export declare const ADVISORY_LEVELS: readonly ["none", "elevated", "high"];
|
|
81
|
+
export type AdvisoryLevel = (typeof ADVISORY_LEVELS)[number];
|
|
82
|
+
export declare const TAINT_GATES: readonly ["off", "destructive", "write"];
|
|
83
|
+
export type TaintGate = (typeof TAINT_GATES)[number];
|
|
84
|
+
/**
|
|
85
|
+
* Enforcement is opt-in: every remote read is reported, but refusing tool calls
|
|
86
|
+
* changes what working agents may do, so the host declares which access levels
|
|
87
|
+
* to gate rather than having the kernel guess.
|
|
88
|
+
*
|
|
89
|
+
* Only structural facts gate tool calls. Content signals from `tool-directives.ts` deliberately have no gate here. They
|
|
90
|
+
* are pattern matches with no measured precision, and refusing a tool call on an
|
|
91
|
+
* unpredictable signal makes an agent unreliable rather than safe — the failure is
|
|
92
|
+
* invisible to the user and looks like the agent being stupid. Those signals
|
|
93
|
+
* annotate the fence and raise telemetry; the model still gets to decide, and the
|
|
94
|
+
* host still gets to see.
|
|
95
|
+
*/
|
|
96
|
+
export interface TaintGuardrailSpec {
|
|
97
|
+
/**
|
|
98
|
+
* - `off` (default) — report only.
|
|
99
|
+
* - `destructive` — refuse hard-to-undo calls.
|
|
100
|
+
* - `write` — refuse those and any state-changing call.
|
|
101
|
+
*
|
|
102
|
+
* Stated as a capability threshold rather than a list of tool `access` values so
|
|
103
|
+
* the guardrail vocabulary stays independent of the tool registry; the kernel
|
|
104
|
+
* maps a tool's declared access onto it.
|
|
105
|
+
*/
|
|
106
|
+
afterRemoteRead?: TaintGate;
|
|
107
|
+
}
|
|
108
|
+
/** Facts a check may read. Deliberately excludes the full profile. */
|
|
109
|
+
export interface GuardrailContext {
|
|
110
|
+
stage: GuardrailStage;
|
|
111
|
+
trust: TrustLevel;
|
|
112
|
+
profileId: string;
|
|
113
|
+
canary?: string;
|
|
114
|
+
/**
|
|
115
|
+
* The private stretches of the system prompt as sent (`BoundSystem.private`),
|
|
116
|
+
* when the profile guards it against echo (`guardrails.promptEcho`): a reply
|
|
117
|
+
* repeating one is a leak.
|
|
118
|
+
*/
|
|
119
|
+
privateSystem?: readonly string[];
|
|
120
|
+
role?: string;
|
|
121
|
+
slots?: Record<string, string>;
|
|
122
|
+
/** Set on tool-shaped stages; absent for user and system text. */
|
|
123
|
+
provenance?: Provenance;
|
|
124
|
+
/**
|
|
125
|
+
* Canonical absolute URLs in what the model was given this turn or session:
|
|
126
|
+
* the system prompt, the user's input and history, and apart, tool results.
|
|
127
|
+
* An image or link in the reply to any other URL can carry data to its
|
|
128
|
+
* server. The kernel adds to them as the model is given more. Unset: none.
|
|
129
|
+
*/
|
|
130
|
+
givenUrls?: GivenUrls;
|
|
131
|
+
/** The profile's lexicon, so a policy's rejection reads in the host's wording. */
|
|
132
|
+
lexicon?: LexiconOverrides;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Structured output travels alongside text so a profile with `outputs.structured`
|
|
136
|
+
* is not invisible to its own egress policy.
|
|
137
|
+
*/
|
|
138
|
+
export interface OutboundPayload {
|
|
139
|
+
/** Concatenated user-visible text for this attempt. */
|
|
140
|
+
text: string;
|
|
141
|
+
structured?: unknown;
|
|
142
|
+
}
|
|
143
|
+
export type EgressEnforcer = (payload: OutboundPayload, context: GuardrailContext) => Verdict | Promise<Verdict>;
|
|
144
|
+
/** `enforce` or `checks`, never both. */
|
|
145
|
+
export interface ProfileEgressSpec {
|
|
146
|
+
/** The host's own check. */
|
|
147
|
+
enforce?: EgressEnforcer;
|
|
148
|
+
/**
|
|
149
|
+
* The bundled policy's checks: `true` runs each at its default, `false` none
|
|
150
|
+
* but the system-prompt leak checks, and an object switches the ones it names.
|
|
151
|
+
*/
|
|
152
|
+
checks?: boolean | EgressChecks;
|
|
153
|
+
onBlock?: EgressOnBlock;
|
|
154
|
+
maxRetries?: number;
|
|
155
|
+
/**
|
|
156
|
+
* For a host `enforce` only: characters the progressive gate holds back so
|
|
157
|
+
* `enforce` sees a match split across stream chunks before any of it is
|
|
158
|
+
* released (default `DEFAULT_HOLDBACK`, 256; on Live `LIVE_DEFAULT_HOLDBACK`,
|
|
159
|
+
* 96). The bundled `standardEgressEnforce` holds exactly what could still
|
|
160
|
+
* become a match, and setting this with it is a profile error.
|
|
161
|
+
*/
|
|
162
|
+
holdback?: number;
|
|
163
|
+
}
|
|
164
|
+
export interface NetworkGuardrailSpec {
|
|
165
|
+
/** Allows localhost, loopback and private subnets (local dev and testing). Default false. */
|
|
166
|
+
allowPrivateNetworks?: boolean;
|
|
167
|
+
/** Hostnames or IP addresses permitted regardless of private subnet status. */
|
|
168
|
+
allowedHosts?: string[];
|
|
169
|
+
/**
|
|
170
|
+
* Allowed URL schemes. Defaults to `['https']`, or `['http', 'https']` when
|
|
171
|
+
* `allowPrivateNetworks` is set.
|
|
172
|
+
*/
|
|
173
|
+
allowedSchemes?: string[];
|
|
174
|
+
}
|
|
175
|
+
/** Optional daily turn quota consumed by host HTTP middleware. */
|
|
176
|
+
export interface QuotaGuardrailSpec {
|
|
177
|
+
perDay: number;
|
|
178
|
+
}
|
|
179
|
+
export interface ProfileGuardrailsSpec {
|
|
180
|
+
/** Omitted means quota enforcement is not configured. */
|
|
181
|
+
quota?: QuotaGuardrailSpec;
|
|
182
|
+
/**
|
|
183
|
+
* Mint a per-turn canary into the system prompt. Default true. The note
|
|
184
|
+
* that binds it is the lexicon's `canary.bind_note` (the profile's `lexicon`
|
|
185
|
+
* may replace it).
|
|
186
|
+
*/
|
|
187
|
+
canary?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* With the canary on, also treat a reply that repeats `PROMPT_ECHO_WORDS`
|
|
190
|
+
* (12) consecutive words of the system prompt as a leak: the dump the token
|
|
191
|
+
* alone cannot see. Default true; set false when the prompt holds text the
|
|
192
|
+
* agent is meant to quote word for word.
|
|
193
|
+
*/
|
|
194
|
+
promptEcho?: boolean;
|
|
195
|
+
sanitizeInput?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Redact sensitive data from untrusted text before the model reads it:
|
|
198
|
+
* `true` (the default) every group, `false` none, an object the groups it
|
|
199
|
+
* switches, the rest on (`ids`, `financial`, `network`, `credentials`).
|
|
200
|
+
*/
|
|
201
|
+
redactSensitive?: SensitiveSelection;
|
|
202
|
+
egress?: ProfileEgressSpec;
|
|
203
|
+
network?: NetworkGuardrailSpec;
|
|
204
|
+
taint?: TaintGuardrailSpec;
|
|
205
|
+
}
|
|
206
|
+
/** Pre-dispatch policy for structured state leaving a decision profile. */
|
|
207
|
+
export type DecisionDisclosureVerdict = Extract<Verdict, {
|
|
208
|
+
action: 'allow' | 'block';
|
|
209
|
+
}>;
|
|
210
|
+
export type DecisionDisclosureEnforcer = (state: unknown, context: {
|
|
211
|
+
destination: 'typesafe' | 'openrouter';
|
|
212
|
+
profileId: string;
|
|
213
|
+
model: string;
|
|
214
|
+
questionIds: string[];
|
|
215
|
+
}) => DecisionDisclosureVerdict | Promise<DecisionDisclosureVerdict>;
|
|
216
|
+
/**
|
|
217
|
+
* Keeps the shared guardrail vocabulary structurally compatible while the
|
|
218
|
+
* decision registry rejects every inherited field as inert in this release.
|
|
219
|
+
*/
|
|
220
|
+
export interface DecisionGuardrailsSpec extends Partial<ProfileGuardrailsSpec> {
|
|
221
|
+
disclosure?: {
|
|
222
|
+
enforce: DecisionDisclosureEnforcer;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** The guardrail field names a `host` profile may set. */
|
|
226
|
+
export declare const HOST_GUARDRAIL_FIELDS: readonly ["sanitizeInput", "redactSensitive", "network"];
|
|
227
|
+
/** The guardrails that fire on the `invokeTool` path; the rest guard a model turn. */
|
|
228
|
+
export type HostGuardrailsSpec = Pick<ProfileGuardrailsSpec, (typeof HOST_GUARDRAIL_FIELDS)[number]>;
|
|
229
|
+
export interface ResolvedGuardrailPolicy {
|
|
230
|
+
sanitizeInput: boolean;
|
|
231
|
+
redactSensitive: SensitiveGroups;
|
|
232
|
+
canary: boolean;
|
|
233
|
+
promptEcho: boolean;
|
|
234
|
+
/** `checks` resolved to the bundled policy's `enforce`. */
|
|
235
|
+
egress?: ResolvedEgressSpec;
|
|
236
|
+
network?: NetworkGuardrailSpec;
|
|
237
|
+
quota?: QuotaGuardrailSpec;
|
|
238
|
+
taint?: TaintGuardrailSpec;
|
|
239
|
+
}
|
|
240
|
+
export type ResolvedEgressSpec = Omit<ProfileEgressSpec, 'enforce' | 'checks'> & {
|
|
241
|
+
enforce: EgressEnforcer;
|
|
242
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Must not import from `src/kernel/`: the kernel type-imports `ProfileGuardrailsSpec`, and that edge
|
|
2
|
+
// stays one-directional. Other modules under `src/guardrails/` may import kernel types.
|
|
3
|
+
/**
|
|
4
|
+
* - `trusted` — author-time profile text (`identity.system`). Sensitive redaction
|
|
5
|
+
* only; injection redaction would mangle the host's own instructions.
|
|
6
|
+
* - `assembled` — host-built per turn (`req.system`). Interpolates retrieval and
|
|
7
|
+
* user data, so it is permeable and takes full detection.
|
|
8
|
+
* - `untrusted` — user input, tool results, attachments, delegated agents.
|
|
9
|
+
*/
|
|
10
|
+
export const TRUST_LEVELS = ['trusted', 'assembled', 'untrusted'];
|
|
11
|
+
export const GUARDRAIL_STAGES = [
|
|
12
|
+
'input',
|
|
13
|
+
'history',
|
|
14
|
+
'system',
|
|
15
|
+
'attachment',
|
|
16
|
+
'tool_call',
|
|
17
|
+
'tool_result',
|
|
18
|
+
'output_delta',
|
|
19
|
+
'output_final',
|
|
20
|
+
'thought',
|
|
21
|
+
'network',
|
|
22
|
+
'live_inbound',
|
|
23
|
+
'live_outbound',
|
|
24
|
+
'trace',
|
|
25
|
+
];
|
|
26
|
+
/** Does not decide what happens next; that is `onBlock`. */
|
|
27
|
+
export const SEVERITIES = ['info', 'low', 'medium', 'high'];
|
|
28
|
+
export const EGRESS_ON_BLOCK = ['reject_to_agent', 'refuse_to_user'];
|
|
29
|
+
export const GUARDRAIL_ACTIONS = [
|
|
30
|
+
'allow',
|
|
31
|
+
'redact',
|
|
32
|
+
'flag',
|
|
33
|
+
'block',
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* `local` is host TypeScript the profile registered; `http` and `mcp` are remote
|
|
37
|
+
* services whose bytes the host does not control. `delegated` is another agent
|
|
38
|
+
* answering through the tool boundary — its output is model-generated prose that
|
|
39
|
+
* reads as authoritative, which is why depth is tracked separately.
|
|
40
|
+
*/
|
|
41
|
+
export const TOOL_ORIGINS = ['local', 'builtin', 'http', 'mcp', 'delegated'];
|
|
42
|
+
/**
|
|
43
|
+
* Not a probability: there is no calibrated model behind it. `elevated` means one
|
|
44
|
+
* directive signal alongside an external destination; `high` means the content
|
|
45
|
+
* named a tool the model can call, or several signals agreed.
|
|
46
|
+
*/
|
|
47
|
+
export const ADVISORY_LEVELS = ['none', 'elevated', 'high'];
|
|
48
|
+
export const TAINT_GATES = ['off', 'destructive', 'write'];
|
|
49
|
+
/** The guardrail field names a `host` profile may set. */
|
|
50
|
+
export const HOST_GUARDRAIL_FIELDS = [
|
|
51
|
+
'sanitizeInput',
|
|
52
|
+
'redactSensitive',
|
|
53
|
+
'network',
|
|
54
|
+
];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TurnEvent } from '../kernel/types.js';
|
|
2
|
+
export interface ClientTurnOptions {
|
|
3
|
+
/** Keep provider-native payloads on `evidence` events. Default: false; parsed fields remain. */
|
|
4
|
+
includeEvidenceRaw?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** Strips host-only diagnostics, so the copy is safe to forward to browsers or end-user SSE. */
|
|
7
|
+
declare function forClient(event: TurnEvent, options?: ClientTurnOptions): TurnEvent;
|
|
8
|
+
declare function forClientEvents(events: TurnEvent[], options?: ClientTurnOptions): TurnEvent[];
|
|
9
|
+
export { forClient, forClientEvents };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { projectGuardrailTurnEvent } from '../guardrails/events.js';
|
|
2
|
+
/** Raw diagnostics ride on error events, an ended session's close, and a tool call's failure. */
|
|
3
|
+
function stripErrorInternal(event) {
|
|
4
|
+
if ((event.type !== 'error' && event.type !== 'session' && event.type !== 'tool') ||
|
|
5
|
+
event.errorInternal === undefined) {
|
|
6
|
+
return event;
|
|
7
|
+
}
|
|
8
|
+
const { errorInternal: _internal, ...rest } = event;
|
|
9
|
+
return rest;
|
|
10
|
+
}
|
|
11
|
+
function stripGuardrailInternal(event) {
|
|
12
|
+
if (event.type !== 'guardrail' || !event.guardrail?.errorInternal) {
|
|
13
|
+
return event;
|
|
14
|
+
}
|
|
15
|
+
const { errorInternal: _internal, ...guardrail } = event.guardrail;
|
|
16
|
+
return { ...event, guardrail };
|
|
17
|
+
}
|
|
18
|
+
function stripEvidenceRaw(event) {
|
|
19
|
+
if (event.type !== 'evidence' || !event.evidence?.raw) {
|
|
20
|
+
return event;
|
|
21
|
+
}
|
|
22
|
+
const { raw: _raw, ...evidence } = event.evidence;
|
|
23
|
+
return { ...event, evidence };
|
|
24
|
+
}
|
|
25
|
+
/** Strips host-only diagnostics, so the copy is safe to forward to browsers or end-user SSE. */
|
|
26
|
+
function forClient(event, options) {
|
|
27
|
+
let out = stripGuardrailInternal(stripErrorInternal(event));
|
|
28
|
+
if (!options?.includeEvidenceRaw) {
|
|
29
|
+
out = stripEvidenceRaw(out);
|
|
30
|
+
}
|
|
31
|
+
// Clients never receive matched substrings, even if the host opted into guardrailMatchPreview.
|
|
32
|
+
out = projectGuardrailTurnEvent(out, false);
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function forClientEvents(events, options) {
|
|
36
|
+
return events.map((event) => forClient(event, options));
|
|
37
|
+
}
|
|
38
|
+
export { forClient, forClientEvents };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Profile } from '../kernel/types.js';
|
|
2
|
+
import { type TraceRecord } from '../observability/trace-record.js';
|
|
3
|
+
import type { TraceSink } from '../observability/trace-sink.js';
|
|
4
|
+
interface CutoutTape {
|
|
5
|
+
ok: boolean;
|
|
6
|
+
/** How long the cutout took; the span ends now and starts this long before. */
|
|
7
|
+
ms: number;
|
|
8
|
+
url?: string;
|
|
9
|
+
inSha256?: string;
|
|
10
|
+
outSha256?: string;
|
|
11
|
+
/** The upstream exchange, recorded as a `theorem.upstream.row` event. */
|
|
12
|
+
http?: unknown;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Writes the held turn record, then one `cutout` span parented on its root, so both read as one
|
|
17
|
+
* trace. Without a `sink` nothing is written.
|
|
18
|
+
*/
|
|
19
|
+
declare function flushMintTrace(args: {
|
|
20
|
+
/** The profile the held turn ran on; its observability governs both writes. */
|
|
21
|
+
profile: Profile;
|
|
22
|
+
held: TraceRecord[];
|
|
23
|
+
app: Record<string, unknown>;
|
|
24
|
+
cutout: CutoutTape;
|
|
25
|
+
sink?: TraceSink;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
export type { CutoutTape };
|
|
28
|
+
export { flushMintTrace };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
2
|
+
import { urlAttributes } from '../kernel/engine/turn-trace.js';
|
|
3
|
+
import { resolveTraceWriter } from '../observability/policy.js';
|
|
4
|
+
import { writeTrace } from '../observability/trace.js';
|
|
5
|
+
import { buildRecord } from '../observability/trace-record.js';
|
|
6
|
+
import { formatTraceparent, startTrace, traceContent, traceJson, } from '../observability/trace-span.js';
|
|
7
|
+
const NANOS_PER_MS = 1_000_000;
|
|
8
|
+
const AGENT_NAME = 'gen_ai.agent.name';
|
|
9
|
+
function cutoutAttributes(cutout) {
|
|
10
|
+
return {
|
|
11
|
+
...urlAttributes(cutout.url),
|
|
12
|
+
...(cutout.inSha256 ? { 'theorem.cutout.input.sha256': cutout.inSha256 } : {}),
|
|
13
|
+
...(cutout.outSha256 ? { 'theorem.cutout.output.sha256': cutout.outSha256 } : {}),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Writes the held turn record, then one `cutout` span parented on its root, so both read as one
|
|
18
|
+
* trace. Without a `sink` nothing is written.
|
|
19
|
+
*/
|
|
20
|
+
async function flushMintTrace(args) {
|
|
21
|
+
const [record] = args.held;
|
|
22
|
+
const root = record?.spans[0];
|
|
23
|
+
if (!record || !root || !args.sink) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const ranOn = root.attributes[AGENT_NAME];
|
|
27
|
+
if (ranOn !== args.profile.id) {
|
|
28
|
+
throw new TheoremError('config', `flushMintTrace: the held turn ran on '${String(ranOn)}', not '${args.profile.id}'`);
|
|
29
|
+
}
|
|
30
|
+
const { sink, policy } = resolveTraceWriter({
|
|
31
|
+
override: args.sink,
|
|
32
|
+
observability: args.profile.observability,
|
|
33
|
+
});
|
|
34
|
+
await writeTrace(sink, Promise.resolve(record), policy);
|
|
35
|
+
const { cutout } = args;
|
|
36
|
+
// One instant: the cutout was reported done now and ran for `ms` before it.
|
|
37
|
+
const now = BigInt(Date.now()) * BigInt(NANOS_PER_MS);
|
|
38
|
+
const tree = startTrace('cutout', {
|
|
39
|
+
clock: { nowUnixNano: () => now },
|
|
40
|
+
kind: 'CLIENT',
|
|
41
|
+
traceparent: formatTraceparent(root.traceId, root.spanId),
|
|
42
|
+
startTimeUnixNano: String(now - BigInt(Math.round(cutout.ms * NANOS_PER_MS))),
|
|
43
|
+
attributes: cutoutAttributes(cutout),
|
|
44
|
+
});
|
|
45
|
+
if (cutout.http !== undefined) {
|
|
46
|
+
tree.root.event('theorem.upstream.row', { row: traceJson(cutout.http) });
|
|
47
|
+
}
|
|
48
|
+
// The host's error text is free text: stored by hash under the scrub, like any exception.
|
|
49
|
+
if (cutout.error) {
|
|
50
|
+
tree.root.event('exception', { 'exception.message': traceContent(cutout.error) });
|
|
51
|
+
}
|
|
52
|
+
tree.root.end({ code: cutout.ok ? 'OK' : 'ERROR' });
|
|
53
|
+
await writeTrace(sink, buildRecord({
|
|
54
|
+
spans: tree.collect(),
|
|
55
|
+
policy,
|
|
56
|
+
metadata: { ...record.metadata, app: args.app },
|
|
57
|
+
}), policy);
|
|
58
|
+
}
|
|
59
|
+
export { flushMintTrace };
|