@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ORCHID AI LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,546 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">Theorem</h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<h3 align="center">
|
|
4
|
+
A deterministic agent builder for TypeScript. The agent's profile is the source of truth.
|
|
5
|
+
</h3>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="#what-it-gives-you"><strong>Why</strong></a> •
|
|
9
|
+
<a href="#quickstart"><strong>Quickstart</strong></a> •
|
|
10
|
+
<a href="#profile-types"><strong>Profile types</strong></a> •
|
|
11
|
+
<a href="#architecture"><strong>Architecture</strong></a> •
|
|
12
|
+
<a href="#tools"><strong>Tools</strong></a> •
|
|
13
|
+
<a href="#guardrails"><strong>Guardrails</strong></a> •
|
|
14
|
+
<a href="#providers"><strong>Providers</strong></a> •
|
|
15
|
+
<a href="#public-entrypoints"><strong>Entrypoints</strong></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://github.com/masudl-hub/theoremai/actions/workflows/ci.yml"><img src="https://github.com/masudl-hub/theoremai/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
20
|
+
<a href="https://jsr.io/@theoremjs/agents"><img src="https://jsr.io/badges/@theoremjs/agents" alt="JSR"></a>
|
|
21
|
+
<a href="https://jsr.io/@theoremjs/agents/score"><img src="https://jsr.io/badges/@theoremjs/agents/score" alt="JSR score"></a>
|
|
22
|
+
<a href="https://www.npmjs.com/package/@theoremjs/agents"><img src="https://img.shields.io/npm/v/@theoremjs/agents?logo=npm&label=npm&color=cb3837" alt="npm"></a>
|
|
23
|
+
<a href="https://github.com/masudl-hub/theoremai/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License"></a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<p align="center">
|
|
27
|
+
<a href="https://github.com/masudl-hub/theoremai/actions/workflows/ci.yml"><img src="https://img.shields.io/github/check-runs/masudl-hub/theoremai/main?nameFilter=lint&label=Biome%20%C2%B7%20ast-grep%20%C2%B7%20fallow&logo=biome" alt="Lint"></a>
|
|
28
|
+
<a href="https://github.com/masudl-hub/theoremai/actions/workflows/security.yml"><img src="https://img.shields.io/github/check-runs/masudl-hub/theoremai/main?nameFilter=semgrep&label=Semgrep&logo=semgrep" alt="Semgrep"></a>
|
|
29
|
+
<a href="https://snyk.io/test/github/masudl-hub/theoremai"><img src="https://snyk.io/test/github/masudl-hub/theoremai/badge.svg" alt="Snyk"></a>
|
|
30
|
+
<a href="https://github.com/masudl-hub/theoremai/actions/workflows/mutation.yml"><img src="https://github.com/masudl-hub/theoremai/actions/workflows/mutation.yml/badge.svg" alt="Mutation testing"></a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
## What is Theorem?
|
|
34
|
+
|
|
35
|
+
Theorem runs AI agents from typed profiles. The profile declares the agent's models, tools, inputs, outputs, and guardrails.
|
|
36
|
+
|
|
37
|
+
Use Theorem when your application runs an AI agent and you need the agent to do what its profile says, on every turn. Theorem runs each turn from the profile and enforces the rules around it.
|
|
38
|
+
|
|
39
|
+
You describe an agent once, as a **profile**. A profile says:
|
|
40
|
+
|
|
41
|
+
- which models the agent may use;
|
|
42
|
+
- what the agent accepts: text, images, PDFs, audio, voice, or typed slots;
|
|
43
|
+
- what the agent must return: free text, JSON that a schema checks, images, speech, or a live audio session;
|
|
44
|
+
- which tools the agent may call;
|
|
45
|
+
- how every input and output is guarded.
|
|
46
|
+
|
|
47
|
+
Theorem then runs each request as a **turn** that follows the profile. It cleans the input. It selects the tools that the model can see. It executes client tools through one gated pipeline. It checks what the model says before any of it reaches your user. It writes a trace to the place that you choose.
|
|
48
|
+
|
|
49
|
+
Theorem does not include application prompts, personas, or databases. It does not read `.env` files for provider credentials.
|
|
50
|
+
Your application supplies credentials, trace storage, and product policy. You can replace kernel wording through the labels.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Install `jsr:@theoremjs/agents` from JSR or `@theoremjs/agents` from npm.
|
|
54
|
+
|
|
55
|
+
## What it gives you
|
|
56
|
+
|
|
57
|
+
| You need to | Theorem gives you | Read |
|
|
58
|
+
| :--- | :--- | :--- |
|
|
59
|
+
| Describe the whole agent in one place | Six profile types, several models per profile, typed file inputs, and outputs that a schema checks | [Profile types](#profile-types) |
|
|
60
|
+
| Stop a prompt injection or a data leak | Input scanning by trust level, canary tokens, and egress checks that can send the model back to try again | [Guardrails](#guardrails) |
|
|
61
|
+
| Let the model act, safely | One tool registry for function, HTTP, MCP, and provider tools, gated in layers, with OAuth 2.1 and PKCE built in | [Tools](#tools) |
|
|
62
|
+
| Connect model servers | Protocols for Gemini, OpenRouter, TypeSafe, and OpenAI-compatible servers, and providers that you define | [Providers](#providers) |
|
|
63
|
+
| See what happened | Traces to JSONL, memory, or your own sink, with sampling, scrubbing, and retention | [Observability](#observability) |
|
|
64
|
+
| Trust the kernel | A kernel that imports with every Deno permission denied. A test proves it. | [Package Boundary](#package-boundary) |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quickstart
|
|
71
|
+
|
|
72
|
+
Use these steps to create a support agent and run one turn.
|
|
73
|
+
Install the package, register the provider and tool, define the profile, then run the turn.
|
|
74
|
+
|
|
75
|
+
### Install
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
deno add jsr:@theoremjs/agents
|
|
79
|
+
# or
|
|
80
|
+
npm install @theoremjs/agents zod
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The npm package runs on Node 20 and later and in browsers. Its type declarations need TypeScript 5.7 or later.
|
|
84
|
+
|
|
85
|
+
### Register a tool
|
|
86
|
+
|
|
87
|
+
Register each tool once, when your application starts. A profile refers to it by name.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { z } from "zod";
|
|
91
|
+
import { registerTool } from "@theoremjs/agents";
|
|
92
|
+
|
|
93
|
+
registerTool({
|
|
94
|
+
type: "function",
|
|
95
|
+
name: "search_tickets",
|
|
96
|
+
description: "Search support tickets by keyword.",
|
|
97
|
+
category: "support",
|
|
98
|
+
access: "read-only",
|
|
99
|
+
paths: ["*"],
|
|
100
|
+
loadTier: "T0",
|
|
101
|
+
permission: "auto",
|
|
102
|
+
input: z.object({ query: z.string().min(2) }),
|
|
103
|
+
output: z.object({ tickets: z.array(z.object({ id: z.string(), title: z.string() })) }),
|
|
104
|
+
handler: async ({ query }) => ({ tickets: await db.tickets.search(query) }),
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Register a provider
|
|
109
|
+
|
|
110
|
+
A **provider** is data about a model service: its address, the protocols that it serves, and how to sign in.
|
|
111
|
+
A **protocol** is the code for one API shape. It writes each request and reads each reply.
|
|
112
|
+
Register the provider before the profile. The registration sets its connection and its credential slots.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { openRouterProvider, registerProvider } from "@theoremjs/agents";
|
|
116
|
+
|
|
117
|
+
const router = registerProvider(openRouterProvider, { keySlot: "openrouter" });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Each run captures the registered provider. A later registration affects later runs only.
|
|
121
|
+
|
|
122
|
+
### Define a profile
|
|
123
|
+
|
|
124
|
+
The profile selects models and tools. It also declares inputs, outputs, and guardrails.
|
|
125
|
+
The registered provider's `.model()` helper takes a protocol and a model ID. It checks the settings and returns plain binding data.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { defineProfile, registerProfile } from "@theoremjs/agents";
|
|
129
|
+
|
|
130
|
+
const support = defineProfile({
|
|
131
|
+
type: "text",
|
|
132
|
+
id: "support.agent",
|
|
133
|
+
identity: {
|
|
134
|
+
handle: "support",
|
|
135
|
+
system: "You help customers with their account. Cite the docs you used.",
|
|
136
|
+
},
|
|
137
|
+
models: {
|
|
138
|
+
main: router.model("openRouter", "openrouter/free"),
|
|
139
|
+
},
|
|
140
|
+
defaultModel: "main",
|
|
141
|
+
tools: { allow: ["search_tickets"] },
|
|
142
|
+
inputs: { text: true },
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
registerProfile(support);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The profile sets no `guardrails`, so input cleaning, sensitive-data redaction, and the canary stay on. [Guardrails](#guardrails) says what each one does.
|
|
149
|
+
|
|
150
|
+
### Run a turn
|
|
151
|
+
|
|
152
|
+
`runTurn` resolves the registered provider from the profile. Pass credentials through the vault.
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import { runTurn } from "@theoremjs/agents";
|
|
156
|
+
|
|
157
|
+
for await (const event of runTurn(
|
|
158
|
+
{ profile: "support.agent", input: { text: "Find support tickets about failed large CSV exports." } },
|
|
159
|
+
{ vault: { openrouter: apiKey } },
|
|
160
|
+
)) {
|
|
161
|
+
send(event); // text · thought · structured · media · tool · guardrail · stage · tokens · done
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Every event is typed. A `structured` event arrives only after validation and the egress checks pass. The `done` event carries a normalized `stop`: `completed`, `length`, `gate`, `cancelled`, or another kind. Read `stop` to decide whether to continue, resume, or stop.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Profile types
|
|
170
|
+
|
|
171
|
+
Use the `type` field to choose what the agent does. The type sets the shape of the profile and picks the runner.
|
|
172
|
+
|
|
173
|
+
| Type | Runner | Takes | Returns | First-party protocols |
|
|
174
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
175
|
+
| `text` | `runTurn` | text, attachments, voice notes, slots, history | text, thoughts, validated JSON, tool calls | `geminiInteractions`, `openRouter`, `openAi` |
|
|
176
|
+
| `image` | `runTurn` | prompt + reference images | images, optionally with interleaved text | `geminiInteractions`, `openRouterImages` |
|
|
177
|
+
| `speech` | `runTurn` | text | audio (WAV, or MP3 on OpenRouter) | `geminiInteractions`, `openRouter`, `openAi` |
|
|
178
|
+
| `live` | `runSession` | realtime mic audio, camera frames, typed text | streamed audio, transcripts, tool calls | `geminiLive` |
|
|
179
|
+
| `host` | `invokeTool`, `invokeToolStep`, `runTool`, `runToolStep` | tool calls from your own code, one at a time or as a step; the `run` pair gives how each call ended | guarded tool results | none; it never calls a model |
|
|
180
|
+
| `decision` | `runDecision` | non-null JSON state plus declared questions | typed choices, probabilities, scores, or `noul` | `systemOne` |
|
|
181
|
+
|
|
182
|
+
A protocol that you define can serve the same profile types. Its `endpoints` name the profile types that it serves.
|
|
183
|
+
|
|
184
|
+
`defineProfile` rejects a field that does not belong to the type. Quota, canary, or egress on a `host` profile, attachments on `live`, and steering on `image` all fail at startup, not halfway through a turn.
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Architecture
|
|
190
|
+
|
|
191
|
+
Tool handlers receive `ToolContext.operationId`, a kernel-issued ID for their action.
|
|
192
|
+
Provider call IDs remain available for correlation. Approval clients preserve both IDs from the issued gate.
|
|
193
|
+
These IDs distinguish actions. A host-owned execution coordinator retains their claims and outcomes.
|
|
194
|
+
The React handler creates that coordinator from its atomic session store. Process restarts require durable shared storage.
|
|
195
|
+
|
|
196
|
+
The runner is one deterministic path for one agent turn. A profile is a declaration that the host owns. Registered providers and their protocols supply model operations; `runSession` opens live sessions. Traces go to destinations that the host registers. There are no environment variables and no bundled database.
|
|
197
|
+
|
|
198
|
+
```text
|
|
199
|
+
request
|
|
200
|
+
|
|
|
201
|
+
v
|
|
202
|
+
INGRESS sanitize by trust level, attachment limits, quota
|
|
203
|
+
RESOLVE pick model and effort, tool snapshot, canary
|
|
204
|
+
| stage: pre_turn
|
|
205
|
+
v
|
|
206
|
+
STEP LOOP (up to maxSteps)
|
|
207
|
+
provider stream --text--> progressive yield --> your client
|
|
208
|
+
|
|
|
209
|
+
'--validated calls--> tool pipeline --guarded results--> next model step
|
|
210
|
+
| stream ends
|
|
211
|
+
v
|
|
212
|
+
END OF ATTEMPT
|
|
213
|
+
reply blocked: blockedReply retry --> back to the step loop
|
|
214
|
+
output validation: fails --> repair round, back to the step loop
|
|
215
|
+
| stage: before_end
|
|
216
|
+
v
|
|
217
|
+
done + stop kind --> your client
|
|
218
|
+
| stage: post_turn
|
|
219
|
+
v
|
|
220
|
+
trace sink (scrubbed)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Use `onStage` to act at a fixed point in the turn:
|
|
224
|
+
|
|
225
|
+
- Apply a host limit at `pre_turn`.
|
|
226
|
+
- Request confirmation at `pre_tool`.
|
|
227
|
+
- Change a tool result at `post_tool`.
|
|
228
|
+
A turn that stops early can resume. After a `gate` stop, call `invokeTool` with `resume`. After a cut-off reply, start a new `runTurn` with `continueFrom`.
|
|
229
|
+
|
|
230
|
+
For a React interface, use the separate package [`@theoremjs/react`](https://github.com/masudl-hub/theoremai/blob/main/react/README.md). It builds on the headless projection `@theoremjs/agents/interface`. The agents package does not include React.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Tools
|
|
235
|
+
|
|
236
|
+
Use tools to let the model act: look something up, call an API, change a record. You register each tool once in a catalog that the whole host shares. A profile picks tools from the catalog, and each turn narrows the choice again.
|
|
237
|
+
|
|
238
|
+
| Type | What runs |
|
|
239
|
+
| :--- | :--- |
|
|
240
|
+
| `function` | Your handler, in process. |
|
|
241
|
+
| `http` | A declarative REST call. Auth is `bearer`, `api_key`, or `oauth2`. |
|
|
242
|
+
| `mcp` | One tool on a remote MCP server over Streamable HTTP. |
|
|
243
|
+
| `builtin` | A provider-native tool (Google Search, Maps, URL context, code execution) from a preset. |
|
|
244
|
+
|
|
245
|
+
Every client-tool call uses the same gated pipeline. Provider-native tools execute upstream through the protocol. Six layers decide whether the model can call a tool, and each layer has one owner.
|
|
246
|
+
|
|
247
|
+
| Layer | Owner | What it decides |
|
|
248
|
+
| :--- | :--- | :--- |
|
|
249
|
+
| **Catalog** | Host, at startup | `registerTool`: schema, handler, `access`, `loadTier`, `permission` |
|
|
250
|
+
| **Allow** | Profile | `tools.allow` for custom tools; `models.*.builtInTools` for provider tools |
|
|
251
|
+
| **Paths** | Tool | `paths` globs matched against `TurnRequest.path` |
|
|
252
|
+
| **Visibility** | Registry and profile | `T0` always visible; `T2` on demand: picked at turn start by `tools.t1Policy(ctx)` or loaded mid-turn by `tools.t2Loader` |
|
|
253
|
+
| **Permission** | Tool and host | `auto` runs; `session_consent` asks once per session; `always_confirm` asks every call |
|
|
254
|
+
| **Hooks** | Tool and host | The tool's `preTool` and the turn's `onStage` can deny, confirm, or rewrite the call |
|
|
255
|
+
|
|
256
|
+
A tool that must act as the signed-in user takes OAuth 2.1 with PKCE. The call becomes an auth gate, and the helpers in `@theoremjs/agents/kernel` finish the sign-in.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Guardrails
|
|
261
|
+
|
|
262
|
+
Theorem scans each piece of text according to where it came from.
|
|
263
|
+
|
|
264
|
+
| Trust | Source | Treatment |
|
|
265
|
+
| :--- | :--- | :--- |
|
|
266
|
+
| `trusted` | `identity.system`, written by you at startup | Passed through |
|
|
267
|
+
| `assembled` | `TurnRequest.system`, built by your code per turn | Full scan |
|
|
268
|
+
| `untrusted` | User text, history, slots, attachments, steering, stage injections | Full injection and sensitive-data scan |
|
|
269
|
+
|
|
270
|
+
- **Coming in.** `detect` replaces prompt-injection phrasing, secrets, and personal data with a placeholder before the model sees them.
|
|
271
|
+
- **Going out.** A **canary** is a secret token that Theorem hides in the system prompt. If the token appears in a reply, the prompt leaked, and the `canary_leak` detector stops the reply. The `prompt_leak` detector also stops a reply that repeats 12 words of the prompt. Both are set in `detect`, like every other detector. `egress` checks every outbound payload and can send the model back to repair its answer.
|
|
272
|
+
- **Tool results.** Remote content is data. Theorem fences it, scans it, and refuses destructive calls after a remote read when `taint.afterRemoteRead` is set. `taint.remoteDestination` gates a call that sends to an address only remote content named.
|
|
273
|
+
- **Network.** HTTP and MCP targets must pass `network.allowedHosts`. Theorem refuses private and metadata addresses by default.
|
|
274
|
+
|
|
275
|
+
The checks fail closed: a payload that cannot be scanned counts as a block. The guardrails have an adversarial corpus, fuzzing, and mutation tests. The corpus ships as `@theoremjs/agents/guardrails/testing`.
|
|
276
|
+
|
|
277
|
+
### Observability
|
|
278
|
+
|
|
279
|
+
`observability` writes OpenTelemetry-shaped trace records for turns, host tool calls, and live sessions to a destination that you register: JSONL, memory, or your own sink. Use `sampleRate`, `include`, and `scrub` to shape what it writes. `toOtlpJson` reshapes records for any OpenTelemetry backend.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Providers
|
|
284
|
+
|
|
285
|
+
Host options can set finite `limits` for provider setup, credentials, transport, and normalized output.
|
|
286
|
+
Defaults bound each operation to 120 seconds and each live connection opening to 30 seconds.
|
|
287
|
+
Retries share the deadline and byte budget. Limits do not enter the profile.
|
|
288
|
+
|
|
289
|
+
A model call uses a **protocol**, a **provider** and a **binding**.
|
|
290
|
+
The protocol is the code for one API shape. The provider is data: an address, the protocols that it serves, and a sign-in.
|
|
291
|
+
The binding under `models` names the protocol, the registered provider ID, and the model.
|
|
292
|
+
|
|
293
|
+
| Provider | ID | Protocols |
|
|
294
|
+
| :--- | :--- | :--- |
|
|
295
|
+
| `geminiProvider` | `gemini` | `geminiInteractions` (text, image, speech), `geminiLive` (live) |
|
|
296
|
+
| `openRouterProvider` | `openrouter` | `openRouter` (text, speech), `openRouterImages` (image), `systemOne` (decision) |
|
|
297
|
+
| `typesafeProvider` | `typesafe` | `systemOne` (decision) |
|
|
298
|
+
| `localProvider` | `local` | `openAi` (text, speech), for a server such as Ollama |
|
|
299
|
+
|
|
300
|
+
Register providers before profiles. `registerProvider(provider, { id, connection, keySlot, fallbackKeySlot })` returns the registered provider.
|
|
301
|
+
`registerProfile` refuses a binding whose provider does not serve its protocol, or whose protocol has no endpoint for the profile type.
|
|
302
|
+
Put shared generation settings on the binding. Put protocol-specific settings in `options`. The protocol's schema validates them.
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
import { bearer, defineProvider, localProvider, openAi, registerProvider } from "@theoremjs/agents";
|
|
306
|
+
import { z } from "zod";
|
|
307
|
+
|
|
308
|
+
registerProvider(localProvider, { connection: { baseUrl: "http://127.0.0.1:11434/v1" } });
|
|
309
|
+
|
|
310
|
+
const gateway = defineProvider({
|
|
311
|
+
id: "gateway",
|
|
312
|
+
name: "Company gateway",
|
|
313
|
+
description: "The chat gateway of the company.",
|
|
314
|
+
connection: z.strictObject({ baseUrl: z.string() }),
|
|
315
|
+
key: z.string().trim().min(1),
|
|
316
|
+
authorize: bearer(),
|
|
317
|
+
serves: (at) => [{ protocol: openAi, baseUrl: at.baseUrl }],
|
|
318
|
+
});
|
|
319
|
+
registerProvider(gateway, { connection: { baseUrl: "https://gateway.example/v1" }, keySlot: "gateway" });
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Use `defineProvider` for a server that speaks a protocol that Theorem has. `bearer`, `header`, and `query` put the key on each request.
|
|
323
|
+
Use `extendProtocol` for an API that nearly matches a protocol. Use `defineProtocol` for a new API shape.
|
|
324
|
+
A protocol never holds a key or an address. The kernel signs and sends each request.
|
|
325
|
+
|
|
326
|
+
### Supply credentials
|
|
327
|
+
|
|
328
|
+
Pass the vault in host options to `runTurn`, `runSession`, or `runDecision`.
|
|
329
|
+
Provider registrations name default credential slots. Bindings can override them with `keySlot` and `fallbackKeySlot`.
|
|
330
|
+
After a quota refusal (HTTP 429), the kernel retries once with the key in `fallbackKeySlot`, if the vault holds it.
|
|
331
|
+
The vault accepts strings, JSON credential objects, or asynchronous resolvers. The host owns credential caching and refresh.
|
|
332
|
+
Supply each slot as an own property of the vault. The runtime ignores inherited entries.
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
import { runTurn } from "@theoremjs/agents";
|
|
336
|
+
|
|
337
|
+
const events = runTurn(
|
|
338
|
+
{ profile: "support.agent", input: { text: "Why did the export fail?" } },
|
|
339
|
+
{ vault: hostKeyVault },
|
|
340
|
+
);
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Save continuation state
|
|
344
|
+
|
|
345
|
+
Keep portable conversation history when a protocol supplies native state.
|
|
346
|
+
A **checkpoint** contains versioned native state and identifies its covered history prefix.
|
|
347
|
+
Save the returned `providerState` checkpoint beside that history. Send both on the next request.
|
|
348
|
+
The kernel validates the checkpoint's protocol, provider, model, connection, key slot, version, and covered history.
|
|
349
|
+
|
|
350
|
+
On a mismatch, the kernel rebuilds from portable history and emits a `provider_state_rebuilt` warning.
|
|
351
|
+
Set `providerContinuation.history` to `provider` to resume from the checkpoint alone when the provider stores the conversation.
|
|
352
|
+
A failed or incomplete model step cannot authorize pending client tools.
|
|
353
|
+
|
|
354
|
+
See [the provider contract](https://github.com/masudl-hub/theoremai/blob/main/docs/contracts/providers.md) for the protocol and provider schemas and the operation boundaries.
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## Documentation
|
|
359
|
+
|
|
360
|
+
Use the [Theorem docs](https://theorem.masudlewis.com/docs) for task procedures.
|
|
361
|
+
|
|
362
|
+
| Task | Chapter |
|
|
363
|
+
| --- | --- |
|
|
364
|
+
| Create an agent | [Getting started](https://theorem.masudlewis.com/docs/start) |
|
|
365
|
+
| Select a profile type | [Choosing a modality](https://theorem.masudlewis.com/docs/modalities) |
|
|
366
|
+
| Set instructions | [Setting the identity](https://theorem.masudlewis.com/docs/identity) |
|
|
367
|
+
| Connect models | [Binding models](https://theorem.masudlewis.com/docs/models) |
|
|
368
|
+
| Register tools | [Registering tools](https://theorem.masudlewis.com/docs/tools) |
|
|
369
|
+
| Declare input | [Declaring inputs](https://theorem.masudlewis.com/docs/inputs) |
|
|
370
|
+
| Declare output | [Declaring outputs](https://theorem.masudlewis.com/docs/outputs) |
|
|
371
|
+
| Set continuation and steering | [Setting turn behaviour](https://theorem.masudlewis.com/docs/turn-behaviour) |
|
|
372
|
+
| Set guardrails | [Setting guardrails](https://theorem.masudlewis.com/docs/guardrails) |
|
|
373
|
+
| Record traces | [Recording traces](https://theorem.masudlewis.com/docs/traces) |
|
|
374
|
+
| Replace wording | [Describing statuses](https://theorem.masudlewis.com/docs/statuses) |
|
|
375
|
+
| Run an operation | [Running a turn](https://theorem.masudlewis.com/docs/runner) |
|
|
376
|
+
| Add an interface | [Building the interface](https://theorem.masudlewis.com/docs/interface) |
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
For tool execution across several workers, pass a host-owned `ToolExecutionCoordinator` through the trusted request's `execution` option.
|
|
381
|
+
The React server handler creates this service from its atomic session store.
|
|
382
|
+
`ToolOperationIdentity` identifies the accepted invocation. `ToolOperationClaim` adds its worker token.
|
|
383
|
+
`savedToolInvocationSchema` validates JSON dispatch evidence.
|
|
384
|
+
`SavedToolInvocation` retains accepted request data and the final input used at dispatch.
|
|
385
|
+
Use `toolInvocationHash` to compute the same canonical JSON digest as the coordinator.
|
|
386
|
+
Use this evidence to check current resource access before you disclose a cached result.
|
|
387
|
+
For browser effects, `PageToolExecution` issues a dispatch grant only after the claim.
|
|
388
|
+
`PageToolDispatch` contains the grant ID and a pending `PageAnswer`. Host code supplies result delivery.
|
|
389
|
+
The browser receives the final prepared arguments, then returns a result against that grant.
|
|
390
|
+
Neither profile JSON nor a provider event can supply this service.
|
|
391
|
+
`BeginToolOperationResult` reports whether a worker acquired the claim or an earlier operation already exists.
|
|
392
|
+
`ToolOperationOutcome` retains the terminal event and a guarded `ModelToolResult` for replay.
|
|
393
|
+
For a custom host replay path, call `authorizeToolReplay` before delivering a saved outcome.
|
|
394
|
+
It checks current eligibility and disclosure without running handlers or preparation hooks.
|
|
395
|
+
Its validator is `toolOperationOutcomeSchema`. `TerminalToolEvent` restricts the retained event to completion or failure.
|
|
396
|
+
`ToolOperationUncertainty` records why a dispatched operation has no confirmed outcome.
|
|
397
|
+
An unresolved claim never becomes an approval again. Check the destination before creating a replacement action.
|
|
398
|
+
|
|
399
|
+
## Public Entrypoints
|
|
400
|
+
|
|
401
|
+
Import from the narrowest entrypoint that has what you need. Each row gives the JSR name and the npm name.
|
|
402
|
+
|
|
403
|
+
| Entrypoint | Purpose |
|
|
404
|
+
| :--- | :--- |
|
|
405
|
+
| `jsr:@theoremjs/agents` / `@theoremjs/agents` | Main kernel API: profiles, schemas, runner, core types, provider constructors, declarative HTTP/MCP tool execution. |
|
|
406
|
+
| `jsr:@theoremjs/agents/kernel` / `@theoremjs/agents/kernel` | Profile/turn types, tool catalog, `requireModelBinding`, thinking clamps over host model maps, OAuth 2.1 PKCE helpers (`createOAuthPkceFlow`, `exchangeOAuthPkce`, `refreshOAuthToken`). |
|
|
407
|
+
| `jsr:@theoremjs/agents/providers` / `@theoremjs/agents/providers` | Protocols, first-party providers, provider definitions, sign-in helpers, and vault contracts. |
|
|
408
|
+
| `jsr:@theoremjs/agents/guardrails` / `@theoremjs/agents/guardrails` | Sanitization, canary/egress gates, public error mapping, inbound injection/sensitive-data primitives. |
|
|
409
|
+
| `jsr:@theoremjs/agents/guardrails/testing` / `@theoremjs/agents/guardrails/testing` | Adversarial corpus + fuzz helpers (test/harness only). |
|
|
410
|
+
| `jsr:@theoremjs/agents/observability` / `@theoremjs/agents/observability` | Trace sinks, trace record helpers and OTLP/JSON export. |
|
|
411
|
+
| `jsr:@theoremjs/agents/observability/jsonl` / `@theoremjs/agents/observability/jsonl` | Optional file sink (`jsonlSink`): daily rotating JSONL through `node:fs`, kept out of browser and Worker bundles. |
|
|
412
|
+
| `jsr:@theoremjs/agents/observability/openinference` / `@theoremjs/agents/observability/openinference` | Optional OpenInference usage names (reasoning tokens, cost) for Phoenix. |
|
|
413
|
+
| `jsr:@theoremjs/agents/observability/phoenix` / `@theoremjs/agents/observability/phoenix` | Optional: eval results as Phoenix span annotations. |
|
|
414
|
+
| `jsr:@theoremjs/agents/host` / `@theoremjs/agents/host` | Optional Deno HTTP helpers (`json`, status mapping, cutout mint flush). |
|
|
415
|
+
| `jsr:@theoremjs/agents/interface` / `@theoremjs/agents/interface` | Headless interface projection of a profile (transcript, composer, gates) that UI packages such as `@theoremjs/react` render. |
|
|
416
|
+
| `jsr:@theoremjs/agents/cli` / `@theoremjs/agents/cli` | Profile inspection and stress-test CLI (`agents` binary on npm). |
|
|
417
|
+
| `jsr:@theoremjs/agents/presets` / `@theoremjs/agents/presets` | Optional convenience packs (`registerGooglePreset`, …). |
|
|
418
|
+
| `jsr:@theoremjs/agents/presets/google` / `@theoremjs/agents/presets/google` | Google builtins (search/maps/urlContext/codeExecution) as tool-list entries. |
|
|
419
|
+
| `jsr:@theoremjs/agents/presets/google/speech-voices` / `@theoremjs/agents/presets/google/speech-voices` | Gemini TTS voice names for `speech.voice` (`GOOGLE_SPEECH_VOICES`); no registry imports. |
|
|
420
|
+
| `jsr:@theoremjs/agents/schema` / `@theoremjs/agents/schema` | Profile vocabulary and field catalog (closed unions, field metadata) for host UIs and docs; no Deno APIs. |
|
|
421
|
+
|
|
422
|
+
The studio is a separate package, `@theoremjs/studio`. It is never part of the kernel package. Install it beside the kernel to open your project's agents in a local studio: `npm install -D @theoremjs/studio`, then `npx theorem-studio`. It needs Deno. The same package shows the studio as a screen in your own app, with one server handler. Its README has both.
|
|
423
|
+
|
|
424
|
+
Internal files stay in the source for maintainability. Package consumers should use the public entrypoints above.
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
### Exported API
|
|
428
|
+
|
|
429
|
+
Open the block below to see every named export of the root barrel (`mod.ts`).
|
|
430
|
+
|
|
431
|
+
<details>
|
|
432
|
+
<summary>Every named export from the root barrel (<code>mod.ts</code>)</summary>
|
|
433
|
+
|
|
434
|
+
Named exports from the root barrel (same symbols hosts get from `@theoremjs/agents` /
|
|
435
|
+
`jsr:@theoremjs/agents`):
|
|
436
|
+
|
|
437
|
+
| Group | Symbols |
|
|
438
|
+
| --- | --- |
|
|
439
|
+
| Guardrails errors | `ERROR_KINDS`, `ErrorKind`, `ErrorCopy`, `ErrorCopies`, `errorKindSchema`, `errorCopiesSchema`, `TheoremError`, `TheoremErrorOptions`, `errorKind`, `publicError`, `toErrorEvent`, `describeError`, `isAbortError`, `throwIfAborted` |
|
|
440
|
+
| Network guardrails | `assertSafeUrl`, `fetchGuarded`, `dnsOverHttpsResolver`, `isLocalhostName`, `isPrivateOrLocalAddress`, `GuardedFetchOptions`, `ResolveHost`, `DnsOverHttpsOptions` |
|
|
441
|
+
| Guardrail vocabulary | `AdvisoryLevel`, `TrustLevel`, `GuardrailStage`, `Severity`, `GuardrailHit`, `Verdict`, `GuardrailAction`, `GuardrailContext`, `GuardrailEvent`, `guardrailEventSchema`, `OutboundPayload`, `Provenance`, `ToolOrigin`, `ScanText`, `BlockedReplySpec`, `BlockedReplyOnBlock`, `ResolvedBlockedReply`, `UrlAllow`, `NameAllow`, `UrlDetector`, `ResolvedAllow`, `ProfileGuardrailsSpec`, `HostGuardrailsSpec`, `NetworkGuardrailSpec`, `QuotaGuardrailSpec`, `ResolvedGuardrailPolicy`, `SensitiveGroup`, `SensitiveSelection`, `SensitiveSwitches`, `GuardedToolText`, `TurnTaint`, `TaintGate`, `TaintGuardrailSpec`, `TurnDestinations`, `DestinationGate`, `DestinationVerdict`, `TRUST_LEVELS`, `GUARDRAIL_STAGES`, `SEVERITIES`, `TOOL_ORIGINS` |
|
|
442
|
+
| Guardrail policy | `resolveGuardrailPolicy`, `BLOCKED_REPLY_ON_BLOCK`, `hitRules`, `EGRESS_RULES` |
|
|
443
|
+
| Tool boundary | `guardToolResult`, `guardToolFailureText`, `inspectToolArguments`, `toolCallEvent`, `wrapToolData`, `isRemoteOrigin`, `composeToolText`, `checkTaintGate`, `recordTaint`, `isTainted`, `isSuspicious`, `checkDestinationGate`, `turnDestinations`, `addGivenDestinations`, `addHistoryDestinations`, `addRequestDestinations`, `addResultDestinations`, `DESTINATION_GATES`, `directives`, `advisoryLevel`, `DIRECTIVE_SIGNALS`, `Directive`, `DirectiveSignal`, `ADVISORY_LEVELS`, `TOOL_CLOSE`, `TOOL_ORIGINS`, `TAINT_GATES`, `InspectedToolArguments`, `textForScan`, `scanTextOf` |
|
|
444
|
+
| Quota | `QuotaSlotStatus`, `clientIp`, `quotaExhausted`, `releaseSlot`, `resetSlots`, `skipQuota`, `takeSlot` |
|
|
445
|
+
| Labels | `LABEL_KEYS`, `LabelKey`, `CLIENT_LABEL_KEYS`, `ClientLabelKey`, `LabelOverrides`, `LabelParams`, `labelDefault`, `labelText`, `overrideLabels`, `resetLabels` |
|
|
446
|
+
| Sanitize | `sanitizeProjectId`, `sanitizeTurnRequest`, `sanitizeTurnRequestWithEvents`, `SanitizedTurnRequest`, `guardrailFromHits`, `guardrailFromVerdict`, `guardrailTurnEvent`, `projectGuardrailTurnEvent`, `hitFromSpan`, `projectGuardrailEvent` |
|
|
447
|
+
| Canary / egress | `mintCanary`, `bindCanary`, `wrapUserData`, `scanTextForCanaryLeak`, `scanTextForPromptEcho`, `PROMPT_ECHO_WORDS`, `redactCanary`, `OMIT_CANARY`, `createCanaryStreamGate`, `eventHasCanary`, `createCanaryGateSession`, `filterCanaryGatedEvents`, `CanaryGateResult`, `CanaryGateSession`, `CanaryStreamGate`, `GivenUrls`, `createOutboundProgressiveGate`, `createProgressiveYieldGate`, `createLiveOutboundGateSession`, `processLiveOutboundBatch`, `finalizeLiveOutboundTurn`, `abortLiveOutboundTurn`, `LiveHeldOutput`, `LiveOutboundBatchResult`, `LiveOutboundGateSession`, `ProgressiveYieldGate`, `ProgressiveYieldGateOptions`, `ProgressiveYieldResult` |
|
|
448
|
+
| Compaction | `compactHistory`, `CompactionSplit`, `CompactionTokens`, `compactionMeter`, `compactionNeeded`, `resolveCompactionTokens`, `resolveHistoryTokens`, `shouldCompact`, `splitForCompaction` |
|
|
449
|
+
| Token estimate | `loadTokenEstimator`, `TOKEN_TEXT_ENCODING`, `TokenCount`, `TokenEstimator`, `sumTokens` |
|
|
450
|
+
| Runner | `runTurn`, `runSession`, `runDecision`, `runEmbedding`, `validateDecisionRequest`, `RunSessionOptions`, `SignInGatePolicy`, `RunDecisionOptions`, `DecisionError`, `prepareLiveInboundText`, `liveIngressEnabled`, `liveIngressEnabledFromSpec`, `liveIngressChannelDefault`, `hasAnyLiveIngress`, `assertLiveIngress`, `assertLiveIngressConfigured`, `LiveIngressChannel` |
|
|
451
|
+
| Attachments | `attachmentIssues`, `attachmentIssueCopy`, `attachmentIssueText`, `attachmentsRefused`, `assertTurnAttachments`, `base64Bytes`, `maxBytesForMime`, `requireMediaLimits`, `resolveMediaLimits`, `sanitizeCsvText`, `sanitizeTurnBlobs`, `embeddingMediaIssues`, `embeddingRules`, `AttachmentFacts`, `AttachmentRules`, `EmbeddingRules` |
|
|
452
|
+
| Catalog | `clampThinkingLevel`, `clampThinkingLevelForApiId`, `mediaChannelForMime`, `MediaInputChannel`, `mediaKindForMime`, `mimeAllowed`, `mimeEssence`, `modelEntryByApiId`, `requireModelBinding` |
|
|
453
|
+
| Schema | `PROFILE_FIELDS`, `PROFILE_GRAPH`, `PROFILE_TYPES`, `PROFILE_ID_MAX_CHARS`, `PROFILE_HANDLE_MAX_CHARS`, `EXTRA_FIELDS`, `REQUEST_FIELDS`, `API_EXPORTS`, `fieldMeta`, `catalogPathFor`, `DYNAMIC_FIELD_PARENTS`, `spineFacetsForProfileType`, `profileGraphFacet`, `ProfileGraphFacet`, `ProfileGraphFacetId`, `ProfileGraphEditor`, `ProfileGraphRole`, `THINKING_LEVELS`, `KEY_SLOT_NAME`, `isKeySlotName`, `MEDIA_INPUT_KINDS`, `MEDIA_INPUT_KIND_VALUES`, `MEDIA_WILDCARDS`, `ATTACHMENT_ACCEPT_MIMES`, `IMAGE_ATTACHMENT_ACCEPT_MIMES`, `VOICE_ACCEPT_MIMES`, `SUMMARY_MODES`, `STREAM_MODES`, `SPEECH_AUDIO_FORMATS`, `COMPACTION_METERS`, `COMPACTION_OUTCOMES`, `COMPACTION_TIMINGS`, `CACHE_MODES`, `CACHE_TTLS`, `TURN_STAGES`, `TURN_INJECT_STAGES`, `TURN_STOP_KINDS`, `CONTINUE_STOP_KINDS`, `TOOL_GATE_KINDS`, `AWAITING_USER_INPUT_KINDS`, `AWAITING_USER_INPUT_STATUS`, `TOOL_LOAD_TIERS`, `TOOL_ACCESS`, `TOOL_PERMISSION`, `TOOL_TYPES`, `AUTH_UNAUTHENTICATED_POLICIES`, `HTTP_METHODS`, `STUDIO_AUTH_TYPES`, `TOOL_AUTH_TYPES`, `AuthUnauthenticatedPolicy`, `CustomToolType`, `HttpMethod`, `StudioAuthType`, `ToolAccess`, `ToolAuthType`, `ToolPermission`, `ToolType`, `LIVE_ACTIVITY_HANDLINGS`, `LIVE_START_SENSITIVITIES`, `LIVE_END_SENSITIVITIES` |
|
|
454
|
+
| Scope | `KernelScope`, `createKernelScope`, `defaultKernelScope`, `KernelRegistry`, `createKernelRegistry` |
|
|
455
|
+
| Profiles | `ProfileDefinition`, `ProfileDefinitionBase`, `TextProfileDefinition`, `ImageProfileDefinition`, `SpeechProfileDefinition`, `LiveProfileDefinition`, `HostProfileDefinition`, `DecisionProfileDefinition`, `EmbeddingProfileDefinition`, `ProfileRegistry`, `createProfileRegistry`, `clearProfiles`, `defineProfile`, `getProfile`, `hasProfile`, `listProfiles`, `registerProfile`, `registerProfiles`, `projectProfile`, `resolveTurn`, `pickModel` |
|
|
456
|
+
| Tools | `ToolContext`, `GateReference`, `gateReferenceSchema`, `ToolRegistry`, `createToolRegistry`, `registerTool`, `registerTools`, `invokeTool`, `invokeToolStep`, `runTool`, `runToolStep`, `SettledToolCall`, `ToolCallResult`, `ToolStepCallResult`, `GATE_DECISIONS`, `GateDecision`, `askUserTool`, `registerHarnessTools`, `getTool`, `hasTool`, `requireTool`, `listTools`, `resetTools`, `formatToolResult`, `prepareTurnToolSnapshot`, `buildHttpToolTarget`, `executeHttpTool`, `executeMcpTool`, `parseMcpRpcResponse`, `isUnsupportedMcpProtocolError`, `MCP_PROTOCOL_VERSIONS`, `McpProtocolVersion`, `resolveToolAuth`, `credentialPlacement`, `withCredentialQuery`, `CredentialQuery`, `uncheckedOutput`, `UncheckedOutput` |
|
|
457
|
+
| Structured | `SchemaRegistry`, `createSchemaRegistry`, `getStructured`, `registerStructured` |
|
|
458
|
+
| Stop / resume | `ProfileTurnBehaviourSpec`, `MediaTurnBehaviourSpec`, `ProfileTurnResumptionSpec`, `TurnContinueFrom`, `TurnStop`, `TurnStopKind`, `ContinueStopKind`, `StepLimitMode`, `CONTINUE_STOP_KINDS`, `AUTO_CONTINUE_DELAY_MS`, `DEFAULT_ALLOW_CONTINUE`, `DEFAULT_AUTO_CONTINUE`, `GenerationStopError`, `isContinueStopKind`, `isGenerationStopError`, `isResumeableStop`, `isUserCancelledStop`, `profileAllowsSteering`, `profileAllowsInject`, `profileTurnResumption`, `shouldAutoContinue`, `turnStopFromClientStreamEnd`, `turnStopFromInteractionStatus`, `turnStopFromOpenAiFinishReason` |
|
|
459
|
+
| Stages (target foundation) | `TURN_STAGES`, `TURN_INJECT_STAGES`, `STAGE_AFFORDANCES`, `STAGE_AFFORDANCE_MATRIX`, `TOOL_GATE_KINDS`, `AWAITING_USER_INPUT_KINDS`, `AWAITING_USER_INPUT_STATUS`, `applyStageResult`, `awaitingUserInputSchema`, `toolGateSchema`, `isTurnStage`, `isTurnInjectStage`, `isToolGateKind`, `isAwaitingUserInput`, `stageAllowsAffordance`, `stageEventFields`, `profileAllowsInject`, `StageAffordance`, `StageContext`, `StageResult`, `StageMutate`, `StageHandler`, `StageApplyInput`, `StageApplyOutput`, `StageApplyWarning`, `StageApplyWarningCode`, `StageEventExtra`, `AwaitingUserInput`, `ToolGate` — contract [`docs/contracts/stages.md`](https://github.com/masudl-hub/theoremai/blob/main/docs/contracts/stages.md) |
|
|
460
|
+
| Turn events | `TURN_EVENT_SCHEMAS` (each kind's schema, for a wire parser), `turnEventSchema`, `turnHistoryMessageSchema`, `turnToolSnapshotSchema`, `reasoningPartSchema`, `historyHash`, `turnDoneOf`, `keptReply` (a turn's events without the replies a retry threw away), `z` (the zod these schemas are built with; compose them with it, since two copies of zod do not mix) — the event types themselves come through `export type *` from `src/kernel/types.ts` |
|
|
461
|
+
| Observability | `memorySink`, `noopSink`, `readTraceparent`, `writeTrace`, `buildRecord`, `traceRecordSchema`, `contentOf`, `inlineContent`, `toOtlpJson`, `startTrace`, `traceContent`, `traceBytes`, `traceJson`, `registerTraceDestination`, `requireTraceDestination`, `getTraceDestination`, `listTraceDestinationIds`, `clearTraceDestinations`, `isTraceSink`, `resolveTraceWriter`, `resolveObservabilityPolicy`, `traceSpanMeta`, `traceAttributeMeta`, `traceEventMeta`, `traceEventAttributeMeta`, `TRACE_ATTRIBUTE_GROUPS`, `TRACE_STATUS`, `TRACE_FIELDS`, `TRACE_SPAN_TYPES`, `TraceSpanMeta`, `TraceSpanType`, `TraceAttributeMeta`, `TraceEventMeta`, `TraceOptionMeta`, `TraceAttributeGroup`, `TraceValueFormat`, `TraceRecord`, `TraceSink`, `TraceWriteContext`, `TraceSpan`, `TraceSpanEvent`, `TraceSpanKind`, `TraceSpanLink`, `TraceSpanStatus`, `TraceAttributes`, `TraceAttributeValue`, `TraceContent`, `TraceBytes`, `TraceJson`, `TraceTree`, `SpanHandle`, `SpanOptions`, `SpanLinkInput`, `TraceClock`, `ProfileObservabilitySpec`, `ResolvedObservabilityPolicy`, `ResolvedTraceInclude`, `ResolvedTraceScrub`, `TraceIncludeSpec`, `TraceScrubSpec`, `ScrubSwitch`, `ResolvedScrubSwitch`, `OtlpTraceRequest`, `OtlpSpan`, `OtlpKeyValue`, `OtlpAnyValue` (file sink: `@theoremjs/agents/observability/jsonl` → `jsonlSink`, `JsonlSinkOptions`) |
|
|
462
|
+
| Providers | `registerProvider`, `getProvider`, `listProviders`, `listProtocols`, `createProviderRegistry`, `defineProvider`, `Provider`, `ProviderDefinition`, `Registration`, `RegisteredProvider`, `ProviderRegistry`, `geminiProvider`, `openRouterProvider`, `typesafeProvider`, `localProvider` |
|
|
463
|
+
| Provider sign-in | `bearer`, `header`, `query`, `Authorize`, `Signer`, `Outgoing`, `Serve`, `endpointUrlSchema` |
|
|
464
|
+
| Protocols | `defineProtocol`, `extendProtocol`, `carriesTo`, `modelOptions`, `geminiInteractions`, `geminiLive`, `geminiEmbedding`, `openAi`, `openRouter`, `openRouterImages`, `openRouterEmbedding`, `ollamaEmbedding`, `systemOne`, `Protocol`, `ProtocolDefinition`, `ProtocolExtension`, `ExtensionBodyAt`, `ExtensionReader`, `ModelProfileType` |
|
|
465
|
+
| Protocol operations | `ProtocolContext`, `ProtocolOperations`, `ProtocolRequest`, `ProtocolSession`, `ProtocolSocket`, `ProtocolEvent`, `ProtocolContentEvent`, `SendInit`, `UpstreamFailure`, `Continuation`, `DecisionCall`, `EmbeddingCall`, `LiveToolResult`, `callProtocol`, `ProtocolCall`, `CallSetup` |
|
|
466
|
+
| Model bindings | `ModelBinding`, `DecisionModelBinding`, `modelBindingSchema`, `decisionModelBindingSchema`, `commonModelSettingsSchema`, `keySlotSchema`, `checkBinding`, `keySlotsOf`, `RuntimeAbilities` |
|
|
467
|
+
| Provider data | `JsonValue`, `JsonObject`, `jsonValueSchema`, `jsonObjectSchema`, `PriceTable`, `ModelPrice`, `Rates` |
|
|
468
|
+
| Provider vault | `ProviderHostOptions`, `KeyVault`, `KeyCredential`, `CredentialContext`, `CredentialResolver`, `OpenWebSocket`, `plainWebSocket` |
|
|
469
|
+
| Provider output | `ProviderCheckpoint`, `ProviderWarning`, `ProviderStateRebuilt`, `ProviderContinuationPolicy`, `providerCheckpointSchema`, `providerWarningSchema`, `providerContinuationSchema` |
|
|
470
|
+
| Provider limits | `ProviderLimits`, `providerLimitsSchema`, `resolveProviderLimits` |
|
|
471
|
+
|
|
472
|
+
</details>
|
|
473
|
+
|
|
474
|
+
Kernel types that the root barrel re-exports follow `export type *` from `src/kernel/types.ts`. For the detail behind them, read the [kernel contract](https://github.com/masudl-hub/theoremai/blob/main/docs/contracts/kernel.md).
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
## Package Boundary
|
|
478
|
+
|
|
479
|
+
Use this section to see what Theorem will not do, so that you know what your application must own. The rule is: **the host decides, Theorem runs.** Theorem is ready for host applications while these statements stay true:
|
|
480
|
+
|
|
481
|
+
```toml
|
|
482
|
+
[boundary]
|
|
483
|
+
# Rule: "Host decides, Theorem runs."
|
|
484
|
+
profiles_in_package = false
|
|
485
|
+
demos_in_package = false
|
|
486
|
+
env_files_in_package = false
|
|
487
|
+
ambient_secret_reads = false
|
|
488
|
+
business_logic_in_kernel = false
|
|
489
|
+
unownable_user_or_model_copy = false
|
|
490
|
+
provider_keys_host_owned = true
|
|
491
|
+
protocols_hold_keys = false
|
|
492
|
+
trace_sinks_host_injected = true
|
|
493
|
+
live_sessions = "registered provider via runSession; host owns mic, camera, and playback"
|
|
494
|
+
session_memory_in_kernel = false
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
**Facts and policy.** Provider facts may ship, such as prices, wire shapes, and protocol metadata. For example, see `@theoremjs/agents/presets/google`. Product policy may not ship: prompts, personas, end-user copy, demo apps, and channel behaviour. Every string that a user or a model reads is either supplied by the host or is an overridable default in the kernel labels (`overrideLabels`). Behavioural defaults are typed profile-schema fields. Optional packages, such as `studio/`, are inert extras. If you delete one, no kernel behaviour changes.
|
|
498
|
+
|
|
499
|
+
Four properties are invariant. Where a test or a lint checks one, the table names it.
|
|
500
|
+
|
|
501
|
+
| Id | Property | Check |
|
|
502
|
+
| --- | --- | --- |
|
|
503
|
+
| P1 | No ambient authority — construct with every Deno permission denied | `tests/kernel/zero-permission-import.test.ts` |
|
|
504
|
+
| P2 | No unownable words — user/model-visible strings are host-suppliable or labels defaults | labels + full-tree `scripts/docs-truth/copy-lint.mjs` + two-hosts test |
|
|
505
|
+
| P3 | No buried policy — behavioral defaults are declared profile-schema fields | `PROFILE_FIELDS` / schema |
|
|
506
|
+
| P4 | Inert extras — optional entrypoints removable without behavior change | publish-bundle gate excludes `studio/` |
|
|
507
|
+
|
|
508
|
+
Provider definition and registration validate without opening transport (`src/kernel/protocols/provider.ts`). A protocol never holds a key, a key slot, or a base URL. The kernel signs each request with the registered provider's sign-in.
|
|
509
|
+
|
|
510
|
+
Domain rules, delivery policy, product copy, database access, and session memory belong in your application, not in Theorem.
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
## Contributing
|
|
514
|
+
|
|
515
|
+
To change Theorem, please read [CONTRIBUTING.md](https://github.com/masudl-hub/theoremai/blob/main/CONTRIBUTING.md).
|
|
516
|
+
|
|
517
|
+
## License
|
|
518
|
+
|
|
519
|
+
MIT License. Copyright (c) ORCHID AI LLC.
|
|
520
|
+
|
|
521
|
+
```theorem-evidence
|
|
522
|
+
{
|
|
523
|
+
"sections": {
|
|
524
|
+
"Architecture": {
|
|
525
|
+
"supports": [
|
|
526
|
+
{ "kind": "source", "path": "src/kernel/engine/runner/mod.ts" },
|
|
527
|
+
{ "kind": "contract_test", "path": "tests/kernel/theorem.test.ts" }
|
|
528
|
+
]
|
|
529
|
+
},
|
|
530
|
+
"Public Entrypoints": {
|
|
531
|
+
"supports": [
|
|
532
|
+
{ "kind": "config", "path": "package.json" },
|
|
533
|
+
{ "kind": "contract_test", "path": "scripts/docs-truth/graph.test.mjs" }
|
|
534
|
+
]
|
|
535
|
+
},
|
|
536
|
+
"Package Boundary": {
|
|
537
|
+
"supports": [
|
|
538
|
+
{ "kind": "source", "path": "src/providers/mod.ts" },
|
|
539
|
+
{ "kind": "source", "path": "src/guardrails/labels.ts" },
|
|
540
|
+
{ "kind": "contract_test", "path": "tests/kernel/two-hosts-boundary.test.ts" },
|
|
541
|
+
{ "kind": "contract_test", "path": "tests/kernel/zero-permission-import.test.ts" }
|
|
542
|
+
]
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Object {
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether an object has a property with the specified name.
|
|
5
|
+
* @param o An object.
|
|
6
|
+
* @param v A property name.
|
|
7
|
+
*/
|
|
8
|
+
hasOwn(o: object, v: PropertyKey): boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
declare global {
|
|
13
|
+
interface Error {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
declare global {
|
|
19
|
+
interface Array<T> {
|
|
20
|
+
/**
|
|
21
|
+
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
22
|
+
* otherwise.
|
|
23
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
24
|
+
* order, until it finds one where predicate returns true. If such an element is found, find
|
|
25
|
+
* immediately returns that element value. Otherwise, find returns undefined.
|
|
26
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
27
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
28
|
+
*/
|
|
29
|
+
findLast<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
|
|
30
|
+
findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the index of the last element in the array where predicate is true, and -1
|
|
33
|
+
* otherwise.
|
|
34
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
35
|
+
* order, until it finds one where predicate returns true. If such an element is found,
|
|
36
|
+
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
|
37
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
38
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
39
|
+
*/
|
|
40
|
+
findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
|
|
41
|
+
}
|
|
42
|
+
interface Uint8Array {
|
|
43
|
+
/**
|
|
44
|
+
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
45
|
+
* otherwise.
|
|
46
|
+
* @param predicate findLast calls predicate once for each element of the array, in descending
|
|
47
|
+
* order, until it finds one where predicate returns true. If such an element is found, findLast
|
|
48
|
+
* immediately returns that element value. Otherwise, findLast returns undefined.
|
|
49
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
50
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
51
|
+
*/
|
|
52
|
+
findLast<S extends number>(predicate: (value: number, index: number, array: Uint8Array) => value is S, thisArg?: any): S | undefined;
|
|
53
|
+
findLast(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the index of the last element in the array where predicate is true, and -1
|
|
56
|
+
* otherwise.
|
|
57
|
+
* @param predicate findLastIndex calls predicate once for each element of the array, in descending
|
|
58
|
+
* order, until it finds one where predicate returns true. If such an element is found,
|
|
59
|
+
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
|
|
60
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
61
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
62
|
+
*/
|
|
63
|
+
findLastIndex(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export {};
|