@theoremjs/agents 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +545 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +79 -0
- package/esm/mod.js +49 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +480 -0
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +241 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +26 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +67 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +5 -0
- package/esm/src/evals/attachments.js +55 -0
- package/esm/src/evals/breakdown.d.ts +30 -0
- package/esm/src/evals/breakdown.js +69 -0
- package/esm/src/evals/graders/answer.d.ts +16 -0
- package/esm/src/evals/graders/answer.js +134 -0
- package/esm/src/evals/graders/code.d.ts +40 -0
- package/esm/src/evals/graders/code.js +184 -0
- package/esm/src/evals/graders/judge.d.ts +24 -0
- package/esm/src/evals/graders/judge.js +367 -0
- package/esm/src/evals/graders/latency.d.ts +6 -0
- package/esm/src/evals/graders/latency.js +82 -0
- package/esm/src/evals/graders/live.d.ts +14 -0
- package/esm/src/evals/graders/live.js +42 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +91 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +19 -0
- package/esm/src/evals/graders/transcript.js +202 -0
- package/esm/src/evals/mod.d.ts +34 -0
- package/esm/src/evals/mod.js +22 -0
- package/esm/src/evals/record.d.ts +41 -0
- package/esm/src/evals/record.js +107 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +75 -0
- package/esm/src/evals/run.js +418 -0
- package/esm/src/evals/suite.d.ts +28 -0
- package/esm/src/evals/suite.js +97 -0
- package/esm/src/evals/summary.d.ts +35 -0
- package/esm/src/evals/summary.js +31 -0
- package/esm/src/evals/trial.d.ts +14 -0
- package/esm/src/evals/trial.js +135 -0
- package/esm/src/evals/types.d.ts +169 -0
- package/esm/src/evals/types.js +113 -0
- package/esm/src/evals/verdict.d.ts +23 -0
- package/esm/src/evals/verdict.js +48 -0
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +22 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +146 -0
- package/esm/src/guardrails/canary.js +974 -0
- package/esm/src/guardrails/compile-egress.d.ts +12 -0
- package/esm/src/guardrails/compile-egress.js +12 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +24 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +305 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +199 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +5 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +120 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +15 -0
- package/esm/src/guardrails/corpus/live-attacks.js +229 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +36 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +12 -0
- package/esm/src/guardrails/egress-automata.js +25582 -0
- package/esm/src/guardrails/egress-compiler.d.ts +55 -0
- package/esm/src/guardrails/egress-compiler.js +431 -0
- package/esm/src/guardrails/egress-patterns.d.ts +26 -0
- package/esm/src/guardrails/egress-patterns.js +36 -0
- package/esm/src/guardrails/egress-stream.d.ts +123 -0
- package/esm/src/guardrails/egress-stream.js +774 -0
- package/esm/src/guardrails/egress-urls.d.ts +86 -0
- package/esm/src/guardrails/egress-urls.js +909 -0
- package/esm/src/guardrails/egress.d.ts +46 -0
- package/esm/src/guardrails/egress.js +124 -0
- package/esm/src/guardrails/error.d.ts +31 -0
- package/esm/src/guardrails/error.js +96 -0
- package/esm/src/guardrails/event-schemas.d.ts +100 -0
- package/esm/src/guardrails/event-schemas.js +48 -0
- package/esm/src/guardrails/events.d.ts +13 -0
- package/esm/src/guardrails/events.js +45 -0
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +14 -0
- package/esm/src/guardrails/hits.js +30 -0
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +20 -0
- package/esm/src/guardrails/injection-patterns.js +126 -0
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +30 -0
- package/esm/src/guardrails/injection.js +460 -0
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +874 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +55 -0
- package/esm/src/guardrails/live-outbound-gate.js +298 -0
- package/esm/src/guardrails/mod.d.ts +54 -0
- package/esm/src/guardrails/mod.js +34 -0
- package/esm/src/guardrails/network.d.ts +46 -0
- package/esm/src/guardrails/network.js +330 -0
- package/esm/src/guardrails/normalize.d.ts +20 -0
- package/esm/src/guardrails/normalize.js +165 -0
- package/esm/src/guardrails/policy.d.ts +4 -0
- package/esm/src/guardrails/policy.js +21 -0
- package/esm/src/guardrails/progressive-yield.d.ts +110 -0
- package/esm/src/guardrails/progressive-yield.js +281 -0
- package/esm/src/guardrails/prompt-echo.d.ts +40 -0
- package/esm/src/guardrails/prompt-echo.js +306 -0
- package/esm/src/guardrails/quota.d.ts +21 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +47 -0
- package/esm/src/guardrails/rules.js +47 -0
- package/esm/src/guardrails/sanitize.d.ts +40 -0
- package/esm/src/guardrails/sanitize.js +160 -0
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +22 -0
- package/esm/src/guardrails/sensitive.js +234 -0
- package/esm/src/guardrails/serialize.d.ts +15 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +11 -0
- package/esm/src/guardrails/testing.js +10 -0
- package/esm/src/guardrails/theorem-error.d.ts +21 -0
- package/esm/src/guardrails/theorem-error.js +54 -0
- package/esm/src/guardrails/thought-guard.d.ts +76 -0
- package/esm/src/guardrails/thought-guard.js +664 -0
- package/esm/src/guardrails/tool-directives.d.ts +38 -0
- package/esm/src/guardrails/tool-directives.js +195 -0
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +92 -0
- package/esm/src/guardrails/tool-result.js +272 -0
- package/esm/src/guardrails/types.d.ts +250 -0
- package/esm/src/guardrails/types.js +58 -0
- package/esm/src/host/client-turn.d.ts +36 -0
- package/esm/src/host/client-turn.js +80 -0
- package/esm/src/host/mint-trace.d.ts +29 -0
- package/esm/src/host/mint-trace.js +60 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +27 -0
- package/esm/src/host/reply.d.ts +13 -0
- package/esm/src/host/reply.js +41 -0
- package/esm/src/interface/blocks.d.ts +11 -0
- package/esm/src/interface/blocks.js +283 -0
- package/esm/src/interface/composer-actions.d.ts +24 -0
- package/esm/src/interface/composer-actions.js +33 -0
- package/esm/src/interface/draft.d.ts +20 -0
- package/esm/src/interface/draft.js +39 -0
- package/esm/src/interface/from-profile.d.ts +24 -0
- package/esm/src/interface/from-profile.js +179 -0
- package/esm/src/interface/history.d.ts +46 -0
- package/esm/src/interface/history.js +278 -0
- package/esm/src/interface/inputs.d.ts +11 -0
- package/esm/src/interface/inputs.js +67 -0
- package/esm/src/interface/mod.d.ts +33 -0
- package/esm/src/interface/mod.js +22 -0
- package/esm/src/interface/models.d.ts +26 -0
- package/esm/src/interface/models.js +50 -0
- package/esm/src/interface/pending.d.ts +57 -0
- package/esm/src/interface/pending.js +152 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +237 -0
- package/esm/src/interface/session.d.ts +71 -0
- package/esm/src/interface/session.js +128 -0
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +32 -0
- package/esm/src/interface/tool-calls.js +127 -0
- package/esm/src/interface/tool-invoke.d.ts +6 -0
- package/esm/src/interface/tool-invoke.js +22 -0
- package/esm/src/interface/tool-media.d.ts +11 -0
- package/esm/src/interface/tool-media.js +113 -0
- package/esm/src/interface/types.d.ts +278 -0
- package/esm/src/interface/types.js +5 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +56 -0
- package/esm/src/kernel/auth/crypto.js +163 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +18 -0
- package/esm/src/kernel/auth/oauth.js +439 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +152 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +72 -0
- package/esm/src/kernel/default-scope.js +121 -0
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +71 -0
- package/esm/src/kernel/engine/compaction.js +203 -0
- package/esm/src/kernel/engine/decision.d.ts +43 -0
- package/esm/src/kernel/engine/decision.js +439 -0
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +19 -0
- package/esm/src/kernel/engine/live-inbound.js +44 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +15 -0
- package/esm/src/kernel/engine/live-ingress.js +42 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +508 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +29 -0
- package/esm/src/kernel/engine/runner/mod.js +625 -0
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +35 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +179 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +41 -0
- package/esm/src/kernel/engine/runner/state.d.ts +97 -0
- package/esm/src/kernel/engine/runner/state.js +50 -0
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +519 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +71 -0
- package/esm/src/kernel/engine/runner/stream.js +376 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +148 -0
- package/esm/src/kernel/engine/session/mod.d.ts +33 -0
- package/esm/src/kernel/engine/session/mod.js +1182 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +500 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +23 -0
- package/esm/src/kernel/engine/token-estimate.js +38 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +132 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +119 -0
- package/esm/src/kernel/engine/turn-trace.js +855 -0
- package/esm/src/kernel/engine/usage.d.ts +36 -0
- package/esm/src/kernel/engine/usage.js +151 -0
- package/esm/src/kernel/interaction-parts.d.ts +13 -0
- package/esm/src/kernel/interaction-parts.js +40 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +74 -0
- package/esm/src/kernel/mod.js +45 -0
- package/esm/src/kernel/profile-graph.d.ts +145 -0
- package/esm/src/kernel/profile-graph.js +158 -0
- package/esm/src/kernel/profile-presence.d.ts +18 -0
- package/esm/src/kernel/profile-presence.js +158 -0
- package/esm/src/kernel/profile-scope.d.ts +40 -0
- package/esm/src/kernel/profile-scope.js +274 -0
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +46 -0
- package/esm/src/kernel/registry/attachments.js +220 -0
- package/esm/src/kernel/registry/catalog.d.ts +25 -0
- package/esm/src/kernel/registry/catalog.js +85 -0
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +12 -0
- package/esm/src/kernel/registry/ingress.js +179 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +15 -0
- package/esm/src/kernel/registry/kernel-registry.js +15 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +10 -0
- package/esm/src/kernel/registry/profiles.d.ts +116 -0
- package/esm/src/kernel/registry/profiles.js +773 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +34 -0
- package/esm/src/kernel/registry/resolve.d.ts +17 -0
- package/esm/src/kernel/registry/resolve.js +238 -0
- package/esm/src/kernel/registry/schemas.d.ts +12 -0
- package/esm/src/kernel/registry/schemas.js +27 -0
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +32 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +14 -0
- package/esm/src/kernel/registry/vault.js +1 -0
- package/esm/src/kernel/schema.d.ts +226 -0
- package/esm/src/kernel/schema.js +895 -0
- package/esm/src/kernel/scope.d.ts +29 -0
- package/esm/src/kernel/scope.js +45 -0
- package/esm/src/kernel/stages.d.ts +176 -0
- package/esm/src/kernel/stages.js +431 -0
- package/esm/src/kernel/stop.d.ts +116 -0
- package/esm/src/kernel/stop.js +137 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +22 -0
- package/esm/src/kernel/tools/activity-label.js +435 -0
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +66 -0
- package/esm/src/kernel/tools/events.js +184 -0
- package/esm/src/kernel/tools/execute.d.ts +100 -0
- package/esm/src/kernel/tools/execute.js +1173 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +60 -0
- package/esm/src/kernel/tools/gate-answer.js +65 -0
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +17 -0
- package/esm/src/kernel/tools/harness.js +43 -0
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +32 -0
- package/esm/src/kernel/tools/invoke.js +282 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +23 -0
- package/esm/src/kernel/tools/mcp-sessions.js +69 -0
- package/esm/src/kernel/tools/mod.d.ts +10 -0
- package/esm/src/kernel/tools/mod.js +7 -0
- package/esm/src/kernel/tools/model-text.d.ts +16 -0
- package/esm/src/kernel/tools/model-text.js +31 -0
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +15 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +11 -0
- package/esm/src/kernel/tools/project.js +55 -0
- package/esm/src/kernel/tools/registry.d.ts +27 -0
- package/esm/src/kernel/tools/registry.js +143 -0
- package/esm/src/kernel/tools/remote.d.ts +144 -0
- package/esm/src/kernel/tools/remote.js +1125 -0
- package/esm/src/kernel/tools/resolve.d.ts +31 -0
- package/esm/src/kernel/tools/resolve.js +267 -0
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +95 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +19 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +116 -0
- package/esm/src/kernel/tools/stage-run.js +198 -0
- package/esm/src/kernel/tools/types.d.ts +497 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +776 -0
- package/esm/src/kernel/turn-events.js +543 -0
- package/esm/src/kernel/types.d.ts +1025 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +4 -0
- package/esm/src/kernel/util/base64.js +15 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +2 -0
- package/esm/src/kernel/util/record.js +4 -0
- package/esm/src/observability/destinations.d.ts +14 -0
- package/esm/src/observability/destinations.js +43 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +110 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +71 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +30 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +17 -0
- package/esm/src/observability/policy.js +73 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +64 -0
- package/esm/src/observability/spans.d.ts +22 -0
- package/esm/src/observability/spans.js +72 -0
- package/esm/src/observability/trace-catalog.d.ts +128 -0
- package/esm/src/observability/trace-catalog.js +906 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +228 -0
- package/esm/src/observability/trace-schema.d.ts +57 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +14 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +98 -0
- package/esm/src/observability/trace-span.js +201 -0
- package/esm/src/observability/trace.d.ts +13 -0
- package/esm/src/observability/trace.js +37 -0
- package/esm/src/observability/types.d.ts +109 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +9 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +13 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +119 -0
- package/esm/src/presets/google.js +197 -0
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +11 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +26 -0
- package/esm/src/presets/openrouter.js +31 -0
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +105 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +27 -0
- package/esm/src/providers/google/interactions/framing.js +304 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +23 -0
- package/esm/src/providers/google/interactions/stream.js +230 -0
- package/esm/src/providers/google/live/framing.d.ts +61 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/stream.d.ts +13 -0
- package/esm/src/providers/google/live/stream.js +57 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +4 -0
- package/esm/src/providers/google/urls.js +4 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +32 -0
- package/esm/src/providers/mod.js +23 -0
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +15 -0
- package/esm/src/providers/openrouter/image.js +34 -0
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/retry.d.ts +17 -0
- package/esm/src/providers/shared/retry.js +90 -0
- package/esm/src/providers/shared/sse.d.ts +6 -0
- package/esm/src/providers/shared/sse.js +93 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +24 -0
- package/esm/src/providers/shared/tool-args.js +88 -0
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +51 -0
- package/esm/src/providers/types.js +2 -0
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +46 -0
- package/esm/src/surface/formats.js +178 -0
- package/esm/src/surface/mod.d.ts +16 -0
- package/esm/src/surface/mod.js +12 -0
- package/esm/src/surface/runtime.d.ts +44 -0
- package/esm/src/surface/runtime.js +441 -0
- package/esm/src/surface/tools.d.ts +9 -0
- package/esm/src/surface/tools.js +62 -0
- package/esm/src/surface/types.d.ts +110 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +100 -4
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { DetectSpec, ResolvedAllow, ResolvedDetect } from './detectors.js';
|
|
2
|
+
import type { GivenUrls } from './egress-urls.js';
|
|
3
|
+
import type { GuardrailEvent, GuardrailHit, Provenance } from './event-schemas.js';
|
|
4
|
+
import type { LabelOverrides } from './labels.js';
|
|
5
|
+
import type { OwnTools } from './tool-leak.js';
|
|
6
|
+
export type { GuardrailEvent, GuardrailHit, Provenance };
|
|
7
|
+
/**
|
|
8
|
+
* - `trusted` — author-time profile text (`identity.system`). Left verbatim: no
|
|
9
|
+
* injection or sensitive redaction, which 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
|
+
/** One of {@linkcode TRUST_LEVELS}. */
|
|
16
|
+
export type TrustLevel = (typeof TRUST_LEVELS)[number];
|
|
17
|
+
/** The points a guardrail can run: input, history, system, attachments, tool calls, and results, output, thoughts, network, live audio, and traces. */
|
|
18
|
+
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"];
|
|
19
|
+
/** One of {@linkcode GUARDRAIL_STAGES}. */
|
|
20
|
+
export type GuardrailStage = (typeof GUARDRAIL_STAGES)[number];
|
|
21
|
+
/** Does not decide what happens next; that is `blockedReply`. */
|
|
22
|
+
export declare const SEVERITIES: readonly ["info", "low", "medium", "high"];
|
|
23
|
+
/** One of {@linkcode SEVERITIES}. */
|
|
24
|
+
export type Severity = (typeof SEVERITIES)[number];
|
|
25
|
+
/** What follows a blocked reply: the model rewrites it, or the user reads a refusal. */
|
|
26
|
+
export declare const BLOCKED_REPLY_ON_BLOCK: readonly ["retry", "refuse"];
|
|
27
|
+
/** One of {@linkcode BLOCKED_REPLY_ON_BLOCK}. */
|
|
28
|
+
export type BlockedReplyOnBlock = (typeof BLOCKED_REPLY_ON_BLOCK)[number];
|
|
29
|
+
/** What happens once a detector blocks a reply. */
|
|
30
|
+
export interface BlockedReplySpec {
|
|
31
|
+
/**
|
|
32
|
+
* `retry` (the default) tells the model what blocked the reply and has it write another;
|
|
33
|
+
* `refuse` sends the user the labels' `egress.refusal` in its place, or ends the part
|
|
34
|
+
* they already have with `egress.refusal_cut`.
|
|
35
|
+
*/
|
|
36
|
+
onBlock?: BlockedReplyOnBlock;
|
|
37
|
+
/**
|
|
38
|
+
* Under `retry`, how many times the model may rewrite a blocked reply (default 1). Once they
|
|
39
|
+
* are spent the reply is withheld and the turn ends in a `safety` error.
|
|
40
|
+
*/
|
|
41
|
+
maxRetries?: number;
|
|
42
|
+
}
|
|
43
|
+
/** {@linkcode BlockedReplySpec} with its defaults applied. */
|
|
44
|
+
export type ResolvedBlockedReply = Required<BlockedReplySpec>;
|
|
45
|
+
/**
|
|
46
|
+
* A discriminated union so a new variant fails every unhandled `switch` at
|
|
47
|
+
* compile time rather than falling through at runtime.
|
|
48
|
+
*/
|
|
49
|
+
export type Verdict = {
|
|
50
|
+
action: 'allow';
|
|
51
|
+
} | {
|
|
52
|
+
action: 'redact';
|
|
53
|
+
text: string;
|
|
54
|
+
hits: GuardrailHit[];
|
|
55
|
+
} | {
|
|
56
|
+
action: 'flag';
|
|
57
|
+
hits: GuardrailHit[];
|
|
58
|
+
} | {
|
|
59
|
+
action: 'block';
|
|
60
|
+
hits: GuardrailHit[];
|
|
61
|
+
/**
|
|
62
|
+
* Sent to the model on a repair turn when `blockedReply.onBlock` is `retry`.
|
|
63
|
+
* With `refuse` the user reads the labels' `egress.refusal`.
|
|
64
|
+
*/
|
|
65
|
+
rejection: string;
|
|
66
|
+
/**
|
|
67
|
+
* Why the check blocked, for the builder only: it reaches the host and the
|
|
68
|
+
* trace (content-gated), never the model or a client (`forClient`).
|
|
69
|
+
*/
|
|
70
|
+
errorInternal?: string;
|
|
71
|
+
};
|
|
72
|
+
export declare const GUARDRAIL_ACTIONS: readonly ["allow", "redact", "flag", "block"];
|
|
73
|
+
/** One of {@linkcode GUARDRAIL_ACTIONS}. */
|
|
74
|
+
export type GuardrailAction = (typeof GUARDRAIL_ACTIONS)[number];
|
|
75
|
+
/**
|
|
76
|
+
* `local` is host TypeScript the profile registered; `http` and `mcp` are remote
|
|
77
|
+
* services whose bytes the host does not control. `delegated` is another agent
|
|
78
|
+
* answering through the tool boundary — its output is model-generated prose that
|
|
79
|
+
* reads as authoritative, which is why depth is tracked separately.
|
|
80
|
+
*/
|
|
81
|
+
export declare const TOOL_ORIGINS: readonly ["local", "builtin", "http", "mcp", "delegated"];
|
|
82
|
+
/** One of {@linkcode TOOL_ORIGINS}. */
|
|
83
|
+
export type ToolOrigin = (typeof TOOL_ORIGINS)[number];
|
|
84
|
+
/**
|
|
85
|
+
* Once a turn has read attacker-influenceable bytes, a later tool call is a
|
|
86
|
+
* confused-deputy risk: the content can ask the agent to act, and the agent has
|
|
87
|
+
* authority the content does not. Sources are kept in order so a policy can reason
|
|
88
|
+
* about depth as well as presence.
|
|
89
|
+
*/
|
|
90
|
+
export interface TurnTaint {
|
|
91
|
+
sources: Provenance[];
|
|
92
|
+
/**
|
|
93
|
+
* Separates "read something remote" from "read something that tried to steer
|
|
94
|
+
* me". The second is far rarer, so a gate keyed on it refuses far less
|
|
95
|
+
* legitimate work.
|
|
96
|
+
*/
|
|
97
|
+
suspicious: GuardrailHit[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Not a probability: there is no calibrated model behind it. `elevated` means one
|
|
101
|
+
* directive signal alongside an external destination; `high` means the content
|
|
102
|
+
* named a tool the model can call, or several signals agreed.
|
|
103
|
+
*/
|
|
104
|
+
export declare const ADVISORY_LEVELS: readonly ["none", "elevated", "high"];
|
|
105
|
+
/** One of {@linkcode ADVISORY_LEVELS}. */
|
|
106
|
+
export type AdvisoryLevel = (typeof ADVISORY_LEVELS)[number];
|
|
107
|
+
/** Which tool access levels refuse to run once a turn has read untrusted content. */
|
|
108
|
+
export declare const TAINT_GATES: readonly ["off", "destructive", "write"];
|
|
109
|
+
/** One of {@linkcode TAINT_GATES}. */
|
|
110
|
+
export type TaintGate = (typeof TAINT_GATES)[number];
|
|
111
|
+
/** What happens to a tool call that sends to a destination only remote content named. */
|
|
112
|
+
export declare const DESTINATION_GATES: readonly ["off", "confirm", "block"];
|
|
113
|
+
/** One of {@linkcode DESTINATION_GATES}. */
|
|
114
|
+
export type DestinationGate = (typeof DESTINATION_GATES)[number];
|
|
115
|
+
/**
|
|
116
|
+
* Enforcement is opt-in: every remote read is reported, but refusing tool calls
|
|
117
|
+
* changes what working agents may do, so the host declares which access levels
|
|
118
|
+
* to gate rather than having the kernel guess.
|
|
119
|
+
*
|
|
120
|
+
* Only structural facts gate tool calls. Content signals from `tool-directives.ts` deliberately have no gate here. They
|
|
121
|
+
* are pattern matches with no measured precision, and refusing a tool call on an
|
|
122
|
+
* unpredictable signal makes an agent unreliable rather than safe — the failure is
|
|
123
|
+
* invisible to the user and looks like the agent being stupid. Those signals
|
|
124
|
+
* annotate the fence and raise telemetry; the model still gets to decide, and the
|
|
125
|
+
* host still gets to see.
|
|
126
|
+
*/
|
|
127
|
+
export interface TaintGuardrailSpec {
|
|
128
|
+
/**
|
|
129
|
+
* Stated as a capability threshold rather than a list of tool `access` values so
|
|
130
|
+
* the guardrail vocabulary stays independent of the tool registry; the kernel
|
|
131
|
+
* maps a tool's declared access onto it.
|
|
132
|
+
*/
|
|
133
|
+
afterRemoteRead?: TaintGate;
|
|
134
|
+
remoteDestination?: DestinationGate;
|
|
135
|
+
}
|
|
136
|
+
/** Facts a check may read. Deliberately excludes the full profile. */
|
|
137
|
+
export interface GuardrailContext {
|
|
138
|
+
stage: GuardrailStage;
|
|
139
|
+
trust: TrustLevel;
|
|
140
|
+
profileId: string;
|
|
141
|
+
canary?: string;
|
|
142
|
+
/**
|
|
143
|
+
* The canary was in what the model was given besides the system prompt (its
|
|
144
|
+
* input, the user's and tools' history): a reply repeating it is not a
|
|
145
|
+
* leak. It still binds prompt echo.
|
|
146
|
+
*/
|
|
147
|
+
canaryGiven?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* The private stretches of the system prompt as sent (`BoundSystem.private`),
|
|
150
|
+
* while the `prompt_leak` detector reads somewhere: text repeating one is a
|
|
151
|
+
* leak.
|
|
152
|
+
*/
|
|
153
|
+
privateSystem?: readonly string[];
|
|
154
|
+
role?: string;
|
|
155
|
+
slots?: Record<string, string>;
|
|
156
|
+
/** Set on tool-shaped stages; absent for user and system text. */
|
|
157
|
+
provenance?: Provenance;
|
|
158
|
+
/**
|
|
159
|
+
* Canonical absolute URLs in what the model was given this turn or session:
|
|
160
|
+
* the system prompt, the user's input and history, and apart, tool results.
|
|
161
|
+
* An image or link in the reply to any other URL can carry data to its
|
|
162
|
+
* server. The kernel adds to them as the model is given more. Unset: none.
|
|
163
|
+
*/
|
|
164
|
+
givenUrls?: GivenUrls;
|
|
165
|
+
/** The names of the profile's tools and of their parameters, for `tool_leak`. Unset: none. */
|
|
166
|
+
ownTools?: OwnTools;
|
|
167
|
+
/** The profile's labels, so a rejection reads in the host's wording. */
|
|
168
|
+
labels?: LabelOverrides;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Structured output travels alongside text so a profile with `outputs.structured`
|
|
172
|
+
* has it read by the detectors too.
|
|
173
|
+
*/
|
|
174
|
+
export interface OutboundPayload {
|
|
175
|
+
/** Concatenated user-visible text for this attempt. */
|
|
176
|
+
text: string;
|
|
177
|
+
structured?: unknown;
|
|
178
|
+
}
|
|
179
|
+
/** Which hosts and networks a tool's requests may reach. */
|
|
180
|
+
export interface NetworkGuardrailSpec {
|
|
181
|
+
/** Allows localhost, loopback, and private subnets (local dev and testing). Default false. */
|
|
182
|
+
allowPrivateNetworks?: boolean;
|
|
183
|
+
/** Hostnames or IP addresses permitted regardless of private subnet status. */
|
|
184
|
+
allowedHosts?: string[];
|
|
185
|
+
/**
|
|
186
|
+
* Allowed URL schemes. Defaults to `['https']`, or `['http', 'https']` when
|
|
187
|
+
* `allowPrivateNetworks` is set.
|
|
188
|
+
*/
|
|
189
|
+
allowedSchemes?: string[];
|
|
190
|
+
}
|
|
191
|
+
/** Optional daily turn quota consumed by host HTTP middleware. */
|
|
192
|
+
export interface QuotaGuardrailSpec {
|
|
193
|
+
perDay: number;
|
|
194
|
+
}
|
|
195
|
+
/** The guardrails a profile turns on, each with its own settings. */
|
|
196
|
+
export interface ProfileGuardrailsSpec {
|
|
197
|
+
/** Omitted means quota enforcement is not configured. */
|
|
198
|
+
quota?: QuotaGuardrailSpec;
|
|
199
|
+
/**
|
|
200
|
+
* What the kernel does when a detector finds a match, per boundary: one action
|
|
201
|
+
* for everything, or a rule for the detectors it names. Anything left out keeps
|
|
202
|
+
* its default (`DETECT_DEFAULTS`). A canary is bound into the system prompt
|
|
203
|
+
* while `canary_leak` is above `ignore` somewhere; the note that binds it is
|
|
204
|
+
* the labels' `canary.bind_note` (the profile's `labels` may replace it).
|
|
205
|
+
*/
|
|
206
|
+
detect?: DetectSpec;
|
|
207
|
+
/** What happens once a reply is blocked. Left out, the model rewrites it once. */
|
|
208
|
+
blockedReply?: BlockedReplySpec;
|
|
209
|
+
network?: NetworkGuardrailSpec;
|
|
210
|
+
taint?: TaintGuardrailSpec;
|
|
211
|
+
}
|
|
212
|
+
/** Pre-dispatch policy for structured state leaving a decision profile. */
|
|
213
|
+
export type DecisionDisclosureVerdict = Extract<Verdict, {
|
|
214
|
+
action: 'allow' | 'block';
|
|
215
|
+
}>;
|
|
216
|
+
export type DecisionDisclosureEnforcer = (state: unknown, context: {
|
|
217
|
+
destination: string;
|
|
218
|
+
profileId: string;
|
|
219
|
+
model: string;
|
|
220
|
+
questionIds: string[];
|
|
221
|
+
/** The images the call sends with the state, by reference. Absent: none. */
|
|
222
|
+
assets?: Record<string, {
|
|
223
|
+
mimeType: 'image/png' | 'image/jpeg';
|
|
224
|
+
data: string;
|
|
225
|
+
}>;
|
|
226
|
+
}) => DecisionDisclosureVerdict | Promise<DecisionDisclosureVerdict>;
|
|
227
|
+
/**
|
|
228
|
+
* Keeps the shared guardrail vocabulary structurally compatible while the
|
|
229
|
+
* decision registry rejects every inherited field as inert in this release.
|
|
230
|
+
*/
|
|
231
|
+
export interface DecisionGuardrailsSpec extends Partial<ProfileGuardrailsSpec> {
|
|
232
|
+
disclosure?: {
|
|
233
|
+
enforce: DecisionDisclosureEnforcer;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** The guardrail field names a `host` profile may set. */
|
|
237
|
+
export declare const HOST_GUARDRAIL_FIELDS: readonly ["detect", "network"];
|
|
238
|
+
/** The guardrails that fire on the `invokeTool` path; the rest guard a model turn. */
|
|
239
|
+
export type HostGuardrailsSpec = Pick<ProfileGuardrailsSpec, (typeof HOST_GUARDRAIL_FIELDS)[number]>;
|
|
240
|
+
/** A profile's guardrails after defaults are applied. */
|
|
241
|
+
export interface ResolvedGuardrailPolicy {
|
|
242
|
+
/** Every detector's action at every boundary. */
|
|
243
|
+
detect: ResolvedDetect;
|
|
244
|
+
/** What `ungiven_images` and `ungiven_links` let through besides the given URLs. */
|
|
245
|
+
allow: ResolvedAllow;
|
|
246
|
+
blockedReply: ResolvedBlockedReply;
|
|
247
|
+
network?: NetworkGuardrailSpec;
|
|
248
|
+
quota?: QuotaGuardrailSpec;
|
|
249
|
+
taint?: TaintGuardrailSpec;
|
|
250
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// invariant: 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`). Left verbatim: no
|
|
5
|
+
* injection or sensitive redaction, which 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
|
+
/** The points a guardrail can run: input, history, system, attachments, tool calls, and results, output, thoughts, network, live audio, and traces. */
|
|
12
|
+
export const GUARDRAIL_STAGES = [
|
|
13
|
+
'input',
|
|
14
|
+
'history',
|
|
15
|
+
'system',
|
|
16
|
+
'attachment',
|
|
17
|
+
'tool_call',
|
|
18
|
+
'tool_result',
|
|
19
|
+
'output_delta',
|
|
20
|
+
'output_final',
|
|
21
|
+
'thought',
|
|
22
|
+
'network',
|
|
23
|
+
'live_inbound',
|
|
24
|
+
'live_outbound',
|
|
25
|
+
'trace',
|
|
26
|
+
];
|
|
27
|
+
/** Does not decide what happens next; that is `blockedReply`. */
|
|
28
|
+
export const SEVERITIES = ['info', 'low', 'medium', 'high'];
|
|
29
|
+
/** What follows a blocked reply: the model rewrites it, or the user reads a refusal. */
|
|
30
|
+
export const BLOCKED_REPLY_ON_BLOCK = ['retry', 'refuse'];
|
|
31
|
+
export const GUARDRAIL_ACTIONS = [
|
|
32
|
+
'allow',
|
|
33
|
+
'redact',
|
|
34
|
+
'flag',
|
|
35
|
+
'block',
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* `local` is host TypeScript the profile registered; `http` and `mcp` are remote
|
|
39
|
+
* services whose bytes the host does not control. `delegated` is another agent
|
|
40
|
+
* answering through the tool boundary — its output is model-generated prose that
|
|
41
|
+
* reads as authoritative, which is why depth is tracked separately.
|
|
42
|
+
*/
|
|
43
|
+
export const TOOL_ORIGINS = ['local', 'builtin', 'http', 'mcp', 'delegated'];
|
|
44
|
+
/**
|
|
45
|
+
* Not a probability: there is no calibrated model behind it. `elevated` means one
|
|
46
|
+
* directive signal alongside an external destination; `high` means the content
|
|
47
|
+
* named a tool the model can call, or several signals agreed.
|
|
48
|
+
*/
|
|
49
|
+
export const ADVISORY_LEVELS = ['none', 'elevated', 'high'];
|
|
50
|
+
/** Which tool access levels refuse to run once a turn has read untrusted content. */
|
|
51
|
+
export const TAINT_GATES = ['off', 'destructive', 'write'];
|
|
52
|
+
/** What happens to a tool call that sends to a destination only remote content named. */
|
|
53
|
+
export const DESTINATION_GATES = ['off', 'confirm', 'block'];
|
|
54
|
+
/** The guardrail field names a `host` profile may set. */
|
|
55
|
+
export const HOST_GUARDRAIL_FIELDS = [
|
|
56
|
+
'detect',
|
|
57
|
+
'network',
|
|
58
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ErrorCopies, type ErrorKind } from '../guardrails/error.js';
|
|
2
|
+
import type { LabelOverrides } from '../guardrails/labels.js';
|
|
3
|
+
import type { TurnEvent } from '../kernel/types.js';
|
|
4
|
+
/** Options for `forClient` and `clientError`: who reads the copy, and whether evidence keeps its provider-native payload. */
|
|
5
|
+
export interface ClientTurnOptions {
|
|
6
|
+
/** Keep provider-native payloads on `evidence` events. Default: false; parsed fields remain. */
|
|
7
|
+
includeEvidenceRaw?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Who reads the copy. A `'visitor'` (the default) reads the profile's wording, and every
|
|
10
|
+
* builder-only diagnostic is stripped. A `'builder'` is whoever builds the app, on their own
|
|
11
|
+
* machine and keys, as in a local development tool: a failed turn, an ended session, and a tool
|
|
12
|
+
* call's failure read their raw reason in place of the profile's wording, and builder-only
|
|
13
|
+
* diagnostics stay. Never for a page visitors reach.
|
|
14
|
+
*/
|
|
15
|
+
reader?: 'visitor' | 'builder';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The copy of an event its reader may have. For a visitor (the default) host-only diagnostics are
|
|
19
|
+
* stripped, so the copy is safe to forward to browsers or end-user SSE.
|
|
20
|
+
*/
|
|
21
|
+
declare function forClient(event: TurnEvent, options?: ClientTurnOptions): TurnEvent;
|
|
22
|
+
/** `forClient` over a list of events. */
|
|
23
|
+
declare function forClientEvents(events: TurnEvent[], options?: ClientTurnOptions): TurnEvent[];
|
|
24
|
+
/** A failure's wording and kind as a client reads them: the body of an error reply or line. */
|
|
25
|
+
type ClientError = {
|
|
26
|
+
error: string;
|
|
27
|
+
errorKind: ErrorKind;
|
|
28
|
+
errorCopy?: ErrorCopies;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A caught failure as its reader may have it, by the same rule as `forClient`: the profile's
|
|
32
|
+
* wording (pass its `labels`) for a visitor, the raw diagnostic for a builder.
|
|
33
|
+
*/
|
|
34
|
+
declare function clientError(err: unknown, labels?: LabelOverrides, options?: ClientTurnOptions): ClientError;
|
|
35
|
+
export type { ClientError };
|
|
36
|
+
export { clientError, forClient, forClientEvents };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { toErrorEvent, withPublicLabels, } from '../guardrails/error.js';
|
|
2
|
+
import { projectGuardrailTurnEvent } from '../guardrails/events.js';
|
|
3
|
+
/**
|
|
4
|
+
* For the builder, the wording of a failure is its raw reason, wherever a visitor's wording
|
|
5
|
+
* stands: a failed turn, an ended session, a tool call's failure.
|
|
6
|
+
*/
|
|
7
|
+
function builderWording(event) {
|
|
8
|
+
if (event.type === 'error' && event.errorInternal !== undefined) {
|
|
9
|
+
// why: `errorCopy` stays: worded raw or not, its key still names what failed for the page.
|
|
10
|
+
const { errorInternal, ...rest } = event;
|
|
11
|
+
return { ...rest, error: errorInternal };
|
|
12
|
+
}
|
|
13
|
+
if (event.type === 'session' &&
|
|
14
|
+
event.session.kind === 'ended' &&
|
|
15
|
+
event.errorInternal !== undefined) {
|
|
16
|
+
const { errorInternal, ...rest } = event;
|
|
17
|
+
return { ...rest, session: { ...event.session, message: errorInternal } };
|
|
18
|
+
}
|
|
19
|
+
if (event.type === 'tool' &&
|
|
20
|
+
event.tool.phase === 'error' &&
|
|
21
|
+
event.tool.failure.error !== undefined) {
|
|
22
|
+
const { failure } = event.tool;
|
|
23
|
+
return { ...event, tool: { ...event.tool, failure: { ...failure, error: failure.message } } };
|
|
24
|
+
}
|
|
25
|
+
return event;
|
|
26
|
+
}
|
|
27
|
+
/** Raw diagnostics ride on error events, an ended session's close, and a tool call's failure. */
|
|
28
|
+
function stripErrorInternal(event) {
|
|
29
|
+
if ((event.type !== 'error' && event.type !== 'session' && event.type !== 'tool') ||
|
|
30
|
+
event.errorInternal === undefined) {
|
|
31
|
+
return event;
|
|
32
|
+
}
|
|
33
|
+
const { errorInternal: _internal, ...rest } = event;
|
|
34
|
+
return rest;
|
|
35
|
+
}
|
|
36
|
+
function stripGuardrailInternal(event) {
|
|
37
|
+
if (event.type !== 'guardrail' || !event.guardrail?.errorInternal) {
|
|
38
|
+
return event;
|
|
39
|
+
}
|
|
40
|
+
const { errorInternal: _internal, ...guardrail } = event.guardrail;
|
|
41
|
+
return { ...event, guardrail };
|
|
42
|
+
}
|
|
43
|
+
function stripEvidenceRaw(event) {
|
|
44
|
+
if (event.type !== 'evidence' || !event.evidence?.raw) {
|
|
45
|
+
return event;
|
|
46
|
+
}
|
|
47
|
+
const { raw: _raw, ...evidence } = event.evidence;
|
|
48
|
+
return { ...event, evidence };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The copy of an event its reader may have. For a visitor (the default) host-only diagnostics are
|
|
52
|
+
* stripped, so the copy is safe to forward to browsers or end-user SSE.
|
|
53
|
+
*/
|
|
54
|
+
function forClient(event, options) {
|
|
55
|
+
let out = options?.reader === 'builder'
|
|
56
|
+
? builderWording(event)
|
|
57
|
+
: stripGuardrailInternal(stripErrorInternal(event));
|
|
58
|
+
if (!options?.includeEvidenceRaw) {
|
|
59
|
+
out = stripEvidenceRaw(out);
|
|
60
|
+
}
|
|
61
|
+
// invariant: Clients never receive matched substrings, even if the host opted into guardrailMatchPreview.
|
|
62
|
+
out = projectGuardrailTurnEvent(out, false);
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/** `forClient` over a list of events. */
|
|
66
|
+
function forClientEvents(events, options) {
|
|
67
|
+
return events.map((event) => forClient(event, options));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A caught failure as its reader may have it, by the same rule as `forClient`: the profile's
|
|
71
|
+
* wording (pass its `labels`) for a visitor, the raw diagnostic for a builder.
|
|
72
|
+
*/
|
|
73
|
+
function clientError(err, labels, options) {
|
|
74
|
+
const event = forClient(withPublicLabels(toErrorEvent(err), labels), options);
|
|
75
|
+
// why: An error event stays one through `withPublicLabels` and `forClient`, worded by the first.
|
|
76
|
+
const { error = '', errorKind, errorCopy } = event;
|
|
77
|
+
// why: The key tells the page what failed (a conversation the host lost), which `errorKind` cannot.
|
|
78
|
+
return { error, errorKind, ...(errorCopy ? { errorCopy } : {}) };
|
|
79
|
+
}
|
|
80
|
+
export { clientError, forClient, forClientEvents };
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
/** The record of a cutout call kept on the trace: whether it succeeded, how long it took, its URL, the hashes of its input, and output, the upstream exchange and any error. */
|
|
5
|
+
interface CutoutTape {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
/** How long the cutout took; the span ends now and starts this long before. */
|
|
8
|
+
ms: number;
|
|
9
|
+
url?: string;
|
|
10
|
+
inSha256?: string;
|
|
11
|
+
outSha256?: string;
|
|
12
|
+
/** The upstream exchange, recorded as a `theorem.upstream.row` event. */
|
|
13
|
+
http?: unknown;
|
|
14
|
+
error?: string;
|
|
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
|
+
declare function flushMintTrace(args: {
|
|
21
|
+
/** The profile the held turn ran on; its observability governs both writes. */
|
|
22
|
+
profile: Profile;
|
|
23
|
+
held: TraceRecord[];
|
|
24
|
+
app: Record<string, unknown>;
|
|
25
|
+
cutout: CutoutTape;
|
|
26
|
+
sink?: TraceSink;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
export type { CutoutTape };
|
|
29
|
+
export { flushMintTrace };
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
guardrails: args.profile.guardrails,
|
|
34
|
+
});
|
|
35
|
+
await writeTrace(sink, Promise.resolve(record), policy);
|
|
36
|
+
const { cutout } = args;
|
|
37
|
+
// why: One instant: the cutout was reported done now and ran for `ms` before it.
|
|
38
|
+
const now = BigInt(Date.now()) * BigInt(NANOS_PER_MS);
|
|
39
|
+
const tree = startTrace('cutout', {
|
|
40
|
+
clock: { nowUnixNano: () => now },
|
|
41
|
+
kind: 'CLIENT',
|
|
42
|
+
traceparent: formatTraceparent(root.traceId, root.spanId),
|
|
43
|
+
startTimeUnixNano: String(now - BigInt(Math.round(cutout.ms * NANOS_PER_MS))),
|
|
44
|
+
attributes: cutoutAttributes(cutout),
|
|
45
|
+
});
|
|
46
|
+
if (cutout.http !== undefined) {
|
|
47
|
+
tree.root.event('theorem.upstream.row', { row: traceJson(cutout.http) });
|
|
48
|
+
}
|
|
49
|
+
// why: The host's error text is free text: stored by hash under the scrub, like any exception.
|
|
50
|
+
if (cutout.error) {
|
|
51
|
+
tree.root.event('exception', { 'exception.message': traceContent(cutout.error) });
|
|
52
|
+
}
|
|
53
|
+
tree.root.end({ code: cutout.ok ? 'OK' : 'ERROR' });
|
|
54
|
+
await writeTrace(sink, buildRecord({
|
|
55
|
+
spans: tree.collect(),
|
|
56
|
+
policy,
|
|
57
|
+
metadata: { ...record.metadata, app: args.app },
|
|
58
|
+
}), policy);
|
|
59
|
+
}
|
|
60
|
+
export { flushMintTrace };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional host-application helpers, not part of the turn kernel: HTTP reply status, cutout-trace
|
|
3
|
+
* flush, and live structured-output preview.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export type { ClientError, ClientTurnOptions } from './client-turn.js';
|
|
9
|
+
export { clientError, forClient, forClientEvents } from './client-turn.js';
|
|
10
|
+
export type { CutoutTape } from './mint-trace.js';
|
|
11
|
+
export { flushMintTrace } from './mint-trace.js';
|
|
12
|
+
export { readStreamingJsonStringField } from './readStreamingJsonStringField.js';
|
|
13
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json, } from './reply.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional host-application helpers, not part of the turn kernel: HTTP reply status, cutout-trace
|
|
3
|
+
* flush, and live structured-output preview.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export { clientError, forClient, forClientEvents } from './client-turn.js';
|
|
9
|
+
export { flushMintTrace } from './mint-trace.js';
|
|
10
|
+
export { readStreamingJsonStringField } from './readStreamingJsonStringField.js';
|
|
11
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json, } from './reply.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { readJsonString } from '../kernel/util/partial-json.js';
|
|
2
|
+
/** The buffer may lack a closing quote; any decoded prefix is returned for live preview. */
|
|
3
|
+
export function readStreamingJsonStringField(jsonText, key) {
|
|
4
|
+
const keyLiteral = JSON.stringify(key);
|
|
5
|
+
let keyAt = jsonText.indexOf(keyLiteral);
|
|
6
|
+
let i = -1;
|
|
7
|
+
while (keyAt >= 0) {
|
|
8
|
+
i = keyAt + keyLiteral.length;
|
|
9
|
+
while (/\s/.test(jsonText[i] ?? '')) {
|
|
10
|
+
i += 1;
|
|
11
|
+
}
|
|
12
|
+
if (jsonText[i] === ':') {
|
|
13
|
+
i += 1;
|
|
14
|
+
while (/\s/.test(jsonText[i] ?? '')) {
|
|
15
|
+
i += 1;
|
|
16
|
+
}
|
|
17
|
+
if (jsonText[i] === '"') {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
keyAt = jsonText.indexOf(keyLiteral, keyAt + keyLiteral.length);
|
|
22
|
+
}
|
|
23
|
+
if (keyAt < 0 || jsonText[i] !== '"') {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return readJsonString(jsonText, i).text;
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** HTTP status for a success. */
|
|
2
|
+
declare const HTTP_OK = 200;
|
|
3
|
+
/** HTTP status for an unknown route. */
|
|
4
|
+
declare const HTTP_NOT_FOUND = 404;
|
|
5
|
+
/** HTTP status for a method the route does not take. */
|
|
6
|
+
declare const HTTP_METHOD = 405;
|
|
7
|
+
/** HTTP status for a request refused because the host is busy. */
|
|
8
|
+
declare const HTTP_BUSY = 429;
|
|
9
|
+
/** A JSON response with the status and the CORS headers. */
|
|
10
|
+
declare function json(status: number, body: unknown, cors: Record<string, string>): Response;
|
|
11
|
+
/** The HTTP status for a caught error, by its kind. */
|
|
12
|
+
declare function caughtStatus(err: unknown): number;
|
|
13
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { errorKind } from '../guardrails/error.js';
|
|
2
|
+
/** HTTP status for a success. */
|
|
3
|
+
const HTTP_OK = 200;
|
|
4
|
+
/** HTTP status for an unknown route. */
|
|
5
|
+
const HTTP_NOT_FOUND = 404;
|
|
6
|
+
/** HTTP status for a method the route does not take. */
|
|
7
|
+
const HTTP_METHOD = 405;
|
|
8
|
+
/** HTTP status for a request refused because the host is busy. */
|
|
9
|
+
const HTTP_BUSY = 429;
|
|
10
|
+
const STATUS_BY_KIND = {
|
|
11
|
+
config: 500,
|
|
12
|
+
request: 400,
|
|
13
|
+
input: 422,
|
|
14
|
+
action: 403,
|
|
15
|
+
auth: 401,
|
|
16
|
+
rate_limit: HTTP_BUSY,
|
|
17
|
+
unsupported: 422,
|
|
18
|
+
unavailable: 503,
|
|
19
|
+
bad_response: 502,
|
|
20
|
+
network: 502,
|
|
21
|
+
timeout: 504,
|
|
22
|
+
safety: 422,
|
|
23
|
+
blocked: 403,
|
|
24
|
+
declined: 409,
|
|
25
|
+
failed: 502,
|
|
26
|
+
// why: Client closed request (nginx convention): the caller went away.
|
|
27
|
+
cancelled: 499,
|
|
28
|
+
internal: 500,
|
|
29
|
+
};
|
|
30
|
+
/** A JSON response with the status and the CORS headers. */
|
|
31
|
+
function json(status, body, cors) {
|
|
32
|
+
return new Response(JSON.stringify(body), {
|
|
33
|
+
status,
|
|
34
|
+
headers: { ...cors, 'Content-Type': 'application/json' },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** The HTTP status for a caught error, by its kind. */
|
|
38
|
+
function caughtStatus(err) {
|
|
39
|
+
return STATUS_BY_KIND[errorKind(err)];
|
|
40
|
+
}
|
|
41
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TurnEvent } from '../kernel/types.js';
|
|
2
|
+
import type { FoldTurnEventsOptions, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
3
|
+
/** Restarts block id numbering at zero. */
|
|
4
|
+
declare function resetBlockIds(): void;
|
|
5
|
+
/** Turns a user draft into transcript blocks: a `user-text` block for the trimmed text, then one block per attachment and per voice clip. */
|
|
6
|
+
declare function buildUserTurnBlocks(draft: UserTurnDraft, idPrefix?: string): TranscriptBlock[];
|
|
7
|
+
/** Resets only the turn id sequence, so streaming refolds keep stable `turn-*` keys. */
|
|
8
|
+
declare function foldTurnEvents(events: readonly TurnEvent[], options?: FoldTurnEventsOptions): TranscriptBlock[];
|
|
9
|
+
/** One conversation turn as blocks: the user draft's blocks followed by the assistant events folded into blocks. */
|
|
10
|
+
declare function foldConversationTurn(draft: UserTurnDraft, assistantEvents: readonly TurnEvent[], options?: FoldTurnEventsOptions): TranscriptBlock[];
|
|
11
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds };
|