@theoremjs/agents 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1264 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +65 -0
- package/esm/mod.js +42 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +458 -0
- package/esm/src/cli/commands/egress-compile.d.ts +17 -0
- package/esm/src/cli/commands/egress-compile.js +25 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +202 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +25 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +72 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +4 -0
- package/esm/src/evals/attachments.js +53 -0
- package/esm/src/evals/breakdown.d.ts +28 -0
- package/esm/src/evals/breakdown.js +68 -0
- package/esm/src/evals/graders/answer.d.ts +13 -0
- package/esm/src/evals/graders/answer.js +133 -0
- package/esm/src/evals/graders/code.d.ts +64 -0
- package/esm/src/evals/graders/code.js +205 -0
- package/esm/src/evals/graders/judge.d.ts +20 -0
- package/esm/src/evals/graders/judge.js +365 -0
- package/esm/src/evals/graders/latency.d.ts +5 -0
- package/esm/src/evals/graders/latency.js +81 -0
- package/esm/src/evals/graders/live.d.ts +11 -0
- package/esm/src/evals/graders/live.js +40 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +92 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +17 -0
- package/esm/src/evals/graders/transcript.js +200 -0
- package/esm/src/evals/mod.d.ts +42 -0
- package/esm/src/evals/mod.js +30 -0
- package/esm/src/evals/record.d.ts +35 -0
- package/esm/src/evals/record.js +105 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +118 -0
- package/esm/src/evals/run.js +452 -0
- package/esm/src/evals/suite.d.ts +19 -0
- package/esm/src/evals/suite.js +92 -0
- package/esm/src/evals/summary.d.ts +32 -0
- package/esm/src/evals/summary.js +30 -0
- package/esm/src/evals/trial.d.ts +27 -0
- package/esm/src/evals/trial.js +158 -0
- package/esm/src/evals/types.d.ts +260 -0
- package/esm/src/evals/types.js +126 -0
- package/esm/src/evals/verdict.d.ts +18 -0
- package/esm/src/evals/verdict.js +45 -0
- package/esm/src/guardrails/canary-gate.d.ts +21 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +112 -0
- package/esm/src/guardrails/canary.js +901 -0
- package/esm/src/guardrails/compile-egress.d.ts +11 -0
- package/esm/src/guardrails/compile-egress.js +11 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +22 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +303 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +202 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +3 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +118 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +13 -0
- package/esm/src/guardrails/corpus/live-attacks.js +224 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +32 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/egress-automata.d.ts +14 -0
- package/esm/src/guardrails/egress-automata.js +6059 -0
- package/esm/src/guardrails/egress-compiler.d.ts +33 -0
- package/esm/src/guardrails/egress-compiler.js +237 -0
- package/esm/src/guardrails/egress-patterns.d.ts +24 -0
- package/esm/src/guardrails/egress-patterns.js +32 -0
- package/esm/src/guardrails/egress-policy.d.ts +27 -0
- package/esm/src/guardrails/egress-policy.js +76 -0
- package/esm/src/guardrails/egress-rules.d.ts +54 -0
- package/esm/src/guardrails/egress-rules.js +49 -0
- package/esm/src/guardrails/egress-stream.d.ts +105 -0
- package/esm/src/guardrails/egress-stream.js +645 -0
- package/esm/src/guardrails/egress-urls.d.ts +83 -0
- package/esm/src/guardrails/egress-urls.js +917 -0
- package/esm/src/guardrails/egress.d.ts +106 -0
- package/esm/src/guardrails/egress.js +374 -0
- package/esm/src/guardrails/error.d.ts +26 -0
- package/esm/src/guardrails/error.js +91 -0
- package/esm/src/guardrails/event-schemas.d.ts +57 -0
- package/esm/src/guardrails/event-schemas.js +41 -0
- package/esm/src/guardrails/events.d.ts +9 -0
- package/esm/src/guardrails/events.js +42 -0
- package/esm/src/guardrails/hits.d.ts +8 -0
- package/esm/src/guardrails/hits.js +19 -0
- package/esm/src/guardrails/injection-patterns.d.ts +15 -0
- package/esm/src/guardrails/injection-patterns.js +94 -0
- package/esm/src/guardrails/injection.d.ts +14 -0
- package/esm/src/guardrails/injection.js +237 -0
- package/esm/src/guardrails/lexicon.d.ts +30 -0
- package/esm/src/guardrails/lexicon.js +478 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +54 -0
- package/esm/src/guardrails/live-outbound-gate.js +305 -0
- package/esm/src/guardrails/mod.d.ts +46 -0
- package/esm/src/guardrails/mod.js +29 -0
- package/esm/src/guardrails/network.d.ts +42 -0
- package/esm/src/guardrails/network.js +328 -0
- package/esm/src/guardrails/normalize.d.ts +6 -0
- package/esm/src/guardrails/normalize.js +132 -0
- package/esm/src/guardrails/policy.d.ts +19 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +69 -0
- package/esm/src/guardrails/progressive-yield.js +237 -0
- package/esm/src/guardrails/prompt-echo.d.ts +38 -0
- package/esm/src/guardrails/prompt-echo.js +225 -0
- package/esm/src/guardrails/quota.d.ts +20 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +56 -0
- package/esm/src/guardrails/rules.js +54 -0
- package/esm/src/guardrails/sanitize.d.ts +23 -0
- package/esm/src/guardrails/sanitize.js +184 -0
- package/esm/src/guardrails/sensitive.d.ts +29 -0
- package/esm/src/guardrails/sensitive.js +113 -0
- package/esm/src/guardrails/serialize.d.ts +14 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +9 -0
- package/esm/src/guardrails/testing.js +8 -0
- package/esm/src/guardrails/theorem-error.d.ts +18 -0
- package/esm/src/guardrails/theorem-error.js +53 -0
- package/esm/src/guardrails/thought-guard.d.ts +55 -0
- package/esm/src/guardrails/thought-guard.js +464 -0
- package/esm/src/guardrails/tool-directives.d.ts +19 -0
- package/esm/src/guardrails/tool-directives.js +109 -0
- package/esm/src/guardrails/tool-result.d.ts +61 -0
- package/esm/src/guardrails/tool-result.js +248 -0
- package/esm/src/guardrails/types.d.ts +242 -0
- package/esm/src/guardrails/types.js +54 -0
- package/esm/src/host/client-turn.d.ts +9 -0
- package/esm/src/host/client-turn.js +38 -0
- package/esm/src/host/mint-trace.d.ts +28 -0
- package/esm/src/host/mint-trace.js +59 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +68 -0
- package/esm/src/host/reply.d.ts +7 -0
- package/esm/src/host/reply.js +35 -0
- package/esm/src/interface/blocks.d.ts +8 -0
- package/esm/src/interface/blocks.js +213 -0
- package/esm/src/interface/composer-actions.d.ts +20 -0
- package/esm/src/interface/composer-actions.js +31 -0
- package/esm/src/interface/draft.d.ts +14 -0
- package/esm/src/interface/draft.js +28 -0
- package/esm/src/interface/from-profile.d.ts +12 -0
- package/esm/src/interface/from-profile.js +144 -0
- package/esm/src/interface/history.d.ts +40 -0
- package/esm/src/interface/history.js +269 -0
- package/esm/src/interface/inputs.d.ts +10 -0
- package/esm/src/interface/inputs.js +64 -0
- package/esm/src/interface/mod.d.ts +31 -0
- package/esm/src/interface/mod.js +21 -0
- package/esm/src/interface/models.d.ts +19 -0
- package/esm/src/interface/models.js +45 -0
- package/esm/src/interface/pending.d.ts +48 -0
- package/esm/src/interface/pending.js +146 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +223 -0
- package/esm/src/interface/session.d.ts +64 -0
- package/esm/src/interface/session.js +121 -0
- package/esm/src/interface/tool-calls.d.ts +20 -0
- package/esm/src/interface/tool-calls.js +73 -0
- package/esm/src/interface/tool-invoke.d.ts +4 -0
- package/esm/src/interface/tool-invoke.js +20 -0
- package/esm/src/interface/tool-media.d.ts +9 -0
- package/esm/src/interface/tool-media.js +112 -0
- package/esm/src/interface/types.d.ts +213 -0
- package/esm/src/interface/types.js +4 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +51 -0
- package/esm/src/kernel/auth/crypto.js +161 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +17 -0
- package/esm/src/kernel/auth/oauth.js +438 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +139 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/default-scope.d.ts +34 -0
- package/esm/src/kernel/default-scope.js +72 -0
- package/esm/src/kernel/engine/compaction.d.ts +70 -0
- package/esm/src/kernel/engine/compaction.js +202 -0
- package/esm/src/kernel/engine/decision.d.ts +41 -0
- package/esm/src/kernel/engine/decision.js +412 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +19 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +9 -0
- package/esm/src/kernel/engine/live-ingress.js +37 -0
- package/esm/src/kernel/engine/media-probe/audio.d.ts +7 -0
- package/esm/src/kernel/engine/media-probe/audio.js +342 -0
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +6 -0
- package/esm/src/kernel/engine/media-probe/bytes.js +26 -0
- package/esm/src/kernel/engine/media-probe/image.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/image.js +171 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +19 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +48 -0
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +35 -0
- package/esm/src/kernel/engine/media-probe/matroska.js +226 -0
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +22 -0
- package/esm/src/kernel/engine/media-probe/mp4.js +279 -0
- package/esm/src/kernel/engine/media-probe/opus.d.ts +4 -0
- package/esm/src/kernel/engine/media-probe/opus.js +23 -0
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/pdf.js +117 -0
- package/esm/src/kernel/engine/media-probe/video.d.ts +15 -0
- package/esm/src/kernel/engine/media-probe/video.js +49 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +322 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +15 -0
- package/esm/src/kernel/engine/runner/mod.js +574 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +14 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +105 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +48 -0
- package/esm/src/kernel/engine/runner/state.d.ts +76 -0
- package/esm/src/kernel/engine/runner/state.js +40 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +360 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +40 -0
- package/esm/src/kernel/engine/runner/stream.js +225 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +150 -0
- package/esm/src/kernel/engine/session/mod.d.ts +31 -0
- package/esm/src/kernel/engine/session/mod.js +951 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +489 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +77 -0
- package/esm/src/kernel/engine/token-estimate.js +218 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +131 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +118 -0
- package/esm/src/kernel/engine/turn-trace.js +863 -0
- package/esm/src/kernel/engine/usage.d.ts +30 -0
- package/esm/src/kernel/engine/usage.js +134 -0
- package/esm/src/kernel/interaction-parts.d.ts +10 -0
- package/esm/src/kernel/interaction-parts.js +22 -0
- package/esm/src/kernel/mod.d.ts +47 -0
- package/esm/src/kernel/mod.js +30 -0
- package/esm/src/kernel/profile-graph.d.ts +140 -0
- package/esm/src/kernel/profile-graph.js +151 -0
- package/esm/src/kernel/profile-presence.d.ts +9 -0
- package/esm/src/kernel/profile-presence.js +143 -0
- package/esm/src/kernel/profile-scope.d.ts +36 -0
- package/esm/src/kernel/profile-scope.js +262 -0
- package/esm/src/kernel/registry/attachments.d.ts +35 -0
- package/esm/src/kernel/registry/attachments.js +211 -0
- package/esm/src/kernel/registry/catalog.d.ts +19 -0
- package/esm/src/kernel/registry/catalog.js +78 -0
- package/esm/src/kernel/registry/ingress.d.ts +8 -0
- package/esm/src/kernel/registry/ingress.js +134 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +12 -0
- package/esm/src/kernel/registry/kernel-registry.js +8 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +7 -0
- package/esm/src/kernel/registry/profiles.d.ts +92 -0
- package/esm/src/kernel/registry/profiles.js +698 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +42 -0
- package/esm/src/kernel/registry/resolve.d.ts +14 -0
- package/esm/src/kernel/registry/resolve.js +237 -0
- package/esm/src/kernel/registry/schemas.d.ts +9 -0
- package/esm/src/kernel/registry/schemas.js +25 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +33 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +13 -0
- package/esm/src/kernel/registry/vault.js +14 -0
- package/esm/src/kernel/schema.d.ts +172 -0
- package/esm/src/kernel/schema.js +653 -0
- package/esm/src/kernel/scope.d.ts +22 -0
- package/esm/src/kernel/scope.js +25 -0
- package/esm/src/kernel/stages.d.ts +141 -0
- package/esm/src/kernel/stages.js +388 -0
- package/esm/src/kernel/stop.d.ts +93 -0
- package/esm/src/kernel/stop.js +125 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +16 -0
- package/esm/src/kernel/tools/activity-label.js +209 -0
- package/esm/src/kernel/tools/events.d.ts +51 -0
- package/esm/src/kernel/tools/events.js +149 -0
- package/esm/src/kernel/tools/execute.d.ts +64 -0
- package/esm/src/kernel/tools/execute.js +801 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +50 -0
- package/esm/src/kernel/tools/gate-answer.js +54 -0
- package/esm/src/kernel/tools/harness.d.ts +16 -0
- package/esm/src/kernel/tools/harness.js +42 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +129 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +20 -0
- package/esm/src/kernel/tools/mcp-sessions.js +64 -0
- package/esm/src/kernel/tools/mod.d.ts +9 -0
- package/esm/src/kernel/tools/mod.js +6 -0
- package/esm/src/kernel/tools/model-text.d.ts +11 -0
- package/esm/src/kernel/tools/model-text.js +25 -0
- package/esm/src/kernel/tools/permission.d.ts +6 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +8 -0
- package/esm/src/kernel/tools/project.js +25 -0
- package/esm/src/kernel/tools/registry.d.ts +20 -0
- package/esm/src/kernel/tools/registry.js +84 -0
- package/esm/src/kernel/tools/remote.d.ts +110 -0
- package/esm/src/kernel/tools/remote.js +998 -0
- package/esm/src/kernel/tools/resolve.d.ts +28 -0
- package/esm/src/kernel/tools/resolve.js +259 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +174 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +18 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +93 -0
- package/esm/src/kernel/tools/stage-run.js +140 -0
- package/esm/src/kernel/tools/types.d.ts +287 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/turn-events.d.ts +599 -0
- package/esm/src/kernel/turn-events.js +425 -0
- package/esm/src/kernel/types.d.ts +884 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +13 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +3 -0
- package/esm/src/observability/destinations.d.ts +9 -0
- package/esm/src/observability/destinations.js +38 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +117 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +68 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +29 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +14 -0
- package/esm/src/observability/policy.js +69 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +58 -0
- package/esm/src/observability/spans.d.ts +16 -0
- package/esm/src/observability/spans.js +56 -0
- package/esm/src/observability/trace-catalog.d.ts +111 -0
- package/esm/src/observability/trace-catalog.js +865 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +223 -0
- package/esm/src/observability/trace-schema.d.ts +54 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +13 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +92 -0
- package/esm/src/observability/trace-span.js +199 -0
- package/esm/src/observability/trace.d.ts +11 -0
- package/esm/src/observability/trace.js +35 -0
- package/esm/src/observability/types.d.ts +85 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +8 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +12 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +104 -0
- package/esm/src/presets/google.js +188 -0
- package/esm/src/presets/mod.d.ts +10 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +13 -0
- package/esm/src/presets/openrouter.js +13 -0
- package/esm/src/presets/typesafe.d.ts +2 -0
- package/esm/src/presets/typesafe.js +2 -0
- package/esm/src/providers/create-provider.d.ts +21 -0
- package/esm/src/providers/create-provider.js +90 -0
- package/esm/src/providers/decision/usage.d.ts +3 -0
- package/esm/src/providers/decision/usage.js +25 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +263 -0
- package/esm/src/providers/google/interactions/mod.d.ts +2 -0
- package/esm/src/providers/google/interactions/mod.js +2 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +24 -0
- package/esm/src/providers/google/interactions/stream.js +297 -0
- package/esm/src/providers/google/keys.d.ts +20 -0
- package/esm/src/providers/google/keys.js +87 -0
- package/esm/src/providers/google/live/framing.d.ts +51 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/mod.d.ts +7 -0
- package/esm/src/providers/google/live/mod.js +7 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +1 -0
- package/esm/src/providers/google/live/openapi-schema.js +42 -0
- package/esm/src/providers/google/live/session.d.ts +14 -0
- package/esm/src/providers/google/live/session.js +150 -0
- package/esm/src/providers/google/live/stream.d.ts +51 -0
- package/esm/src/providers/google/live/stream.js +263 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/local/local.d.ts +12 -0
- package/esm/src/providers/local/local.js +186 -0
- package/esm/src/providers/local/mod.d.ts +8 -0
- package/esm/src/providers/local/mod.js +8 -0
- package/esm/src/providers/mod.d.ts +11 -0
- package/esm/src/providers/mod.js +7 -0
- package/esm/src/providers/openrouter/cache-control.d.ts +5 -0
- package/esm/src/providers/openrouter/cache-control.js +4 -0
- package/esm/src/providers/openrouter/chat.d.ts +64 -0
- package/esm/src/providers/openrouter/chat.js +490 -0
- package/esm/src/providers/openrouter/image.d.ts +24 -0
- package/esm/src/providers/openrouter/image.js +187 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +10 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +99 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +3 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +8 -0
- package/esm/src/providers/openrouter/speech.d.ts +18 -0
- package/esm/src/providers/openrouter/speech.js +109 -0
- package/esm/src/providers/probe.d.ts +5 -0
- package/esm/src/providers/probe.js +15 -0
- package/esm/src/providers/shared/builtin-wire.d.ts +4 -0
- package/esm/src/providers/shared/builtin-wire.js +9 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/sse.d.ts +10 -0
- package/esm/src/providers/shared/sse.js +79 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +25 -0
- package/esm/src/providers/shared/tool-args.js +84 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/shared/vault.d.ts +13 -0
- package/esm/src/providers/shared/vault.js +41 -0
- package/esm/src/providers/types.d.ts +19 -0
- package/esm/src/providers/types.js +1 -0
- package/esm/src/surface/formats.d.ts +28 -0
- package/esm/src/surface/formats.js +139 -0
- package/esm/src/surface/mod.d.ts +14 -0
- package/esm/src/surface/mod.js +10 -0
- package/esm/src/surface/runtime.d.ts +40 -0
- package/esm/src/surface/runtime.js +439 -0
- package/esm/src/surface/tools.d.ts +15 -0
- package/esm/src/surface/tools.js +80 -0
- package/esm/src/surface/types.d.ts +104 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +108 -4
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { LexiconOverrides } from '../guardrails/lexicon.js';
|
|
2
|
+
import type { SensitiveGroups } from '../guardrails/sensitive.js';
|
|
3
|
+
import type { ResolvedGuardrailPolicy } from '../guardrails/types.js';
|
|
4
|
+
import type { LiveProfileToolsSpec, ProfileToolsSpec, ToolCallEdit, ToolPhaseEvent } from '../kernel/tools/types.js';
|
|
5
|
+
import type { AttachmentValidationIssue, CompactionSpec, GroundingEvent, ImageProfile, LiveProfile, ModelBinding, ModelId, ProfileOutputsSpec, ProviderEvidence, Source, SpeechProfile, TextProfile, TurnStop, TurnTokens } from '../kernel/types.js';
|
|
6
|
+
import type { ResolvedObservabilityPolicy } from '../observability/types.js';
|
|
7
|
+
/** A URL check as it runs; `false` when off. */
|
|
8
|
+
export type UrlCheckView = false | {
|
|
9
|
+
hosts: string[];
|
|
10
|
+
fromTools: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** The bundled egress checks a profile's reply runs through. */
|
|
13
|
+
export interface EgressChecksView {
|
|
14
|
+
sensitive: SensitiveGroups;
|
|
15
|
+
boundary: boolean;
|
|
16
|
+
injection: boolean;
|
|
17
|
+
images: UrlCheckView;
|
|
18
|
+
links: UrlCheckView;
|
|
19
|
+
}
|
|
20
|
+
/** Guardrails visible to UI — egress enforcer functions are omitted. */
|
|
21
|
+
export type ProfileGuardrailsView = Pick<ResolvedGuardrailPolicy, 'quota' | 'canary' | 'sanitizeInput' | 'redactSensitive'> & {
|
|
22
|
+
hasEgress: boolean;
|
|
23
|
+
/** `null` with no egress check, or a host `enforce` whose checks are its own. */
|
|
24
|
+
egressChecks: EgressChecksView | null;
|
|
25
|
+
};
|
|
26
|
+
/** Observability visible to UI — TraceSink / onWriteError functions are omitted. */
|
|
27
|
+
export type ProfileObservabilityView = Pick<ResolvedObservabilityPolicy, 'record' | 'sampleRate' | 'include' | 'scrub' | 'resource' | 'retainForDays' | 'rotateAfterMiB'> & {
|
|
28
|
+
/** false | registered id | 'custom' when writeTo is an inline TraceSink; absent when unset. */
|
|
29
|
+
writeTo?: false | string;
|
|
30
|
+
hasOnWriteError: boolean;
|
|
31
|
+
};
|
|
32
|
+
/** Resolved `inputs` — `ProfileInputsSpec` plus `acceptAttr` for file pickers. */
|
|
33
|
+
export interface ProfileInputsInterface {
|
|
34
|
+
text: boolean;
|
|
35
|
+
attachments: {
|
|
36
|
+
accept: string[];
|
|
37
|
+
acceptAttr: string;
|
|
38
|
+
} | null;
|
|
39
|
+
voice: {
|
|
40
|
+
accept: string[];
|
|
41
|
+
} | null;
|
|
42
|
+
maxFiles?: number;
|
|
43
|
+
maxBytes?: number;
|
|
44
|
+
maxTurnBytes?: number;
|
|
45
|
+
limitsByMime?: Record<string, number>;
|
|
46
|
+
slots?: Record<string, string[]>;
|
|
47
|
+
}
|
|
48
|
+
/** A tool's definition (handler, schemas, endpoint, headers) stays on the host; `t1Policy` too. */
|
|
49
|
+
export type ProfileToolsView = Pick<ProfileToolsSpec, 'allow' | 't2Loader'>;
|
|
50
|
+
/** A model binding as the interface carries it: a compaction `trigger` is a host function. */
|
|
51
|
+
export type ModelBindingView = Omit<ModelBinding, 'compaction'> & {
|
|
52
|
+
compaction?: Omit<CompactionSpec, 'trigger'>;
|
|
53
|
+
};
|
|
54
|
+
/** `profile.outputs` as the interface carries it: validators are host functions. */
|
|
55
|
+
export type ProfileOutputsView = Omit<ProfileOutputsSpec, 'validation'>;
|
|
56
|
+
/** What the text, image and speech interfaces carry in place of their profile's own fields. */
|
|
57
|
+
export type ComposerInterfaceFields = {
|
|
58
|
+
models: Record<ModelId, ModelBindingView>;
|
|
59
|
+
outputs?: ProfileOutputsView;
|
|
60
|
+
/** Client keys' overrides (`CLIENT_LEXICON_KEYS`), resolved on the host; pass to `lexiconText`. */
|
|
61
|
+
lexicon: LexiconOverrides;
|
|
62
|
+
inputs: ProfileInputsInterface;
|
|
63
|
+
guardrails?: ProfileGuardrailsView;
|
|
64
|
+
observability?: ProfileObservabilityView;
|
|
65
|
+
/** Always true — composer turns cancel via `TurnRequest.signal`. */
|
|
66
|
+
canStop: true;
|
|
67
|
+
};
|
|
68
|
+
export type TextProfileInterface = Omit<TextProfile, 'inputs' | 'tools' | 'guardrails' | 'observability' | 'lexicon' | 'models' | 'outputs'> & ComposerInterfaceFields & {
|
|
69
|
+
tools: ProfileToolsView;
|
|
70
|
+
/** From `turnBehaviour.allowSteering` (default true on text). */
|
|
71
|
+
allowSteering: boolean;
|
|
72
|
+
};
|
|
73
|
+
export type ImageProfileInterface = Omit<ImageProfile, 'inputs' | 'tools' | 'guardrails' | 'observability' | 'lexicon' | 'models' | 'outputs'> & ComposerInterfaceFields & {
|
|
74
|
+
tools: ProfileToolsView;
|
|
75
|
+
};
|
|
76
|
+
export type SpeechProfileInterface = Omit<SpeechProfile, 'guardrails' | 'observability' | 'lexicon' | 'models' | 'outputs'> & ComposerInterfaceFields;
|
|
77
|
+
export type LiveProfileInterface = Omit<LiveProfile, 'tools' | 'guardrails' | 'observability' | 'lexicon' | 'models'> & {
|
|
78
|
+
models: Record<ModelId, ModelBindingView>;
|
|
79
|
+
/** Client keys' overrides (`CLIENT_LEXICON_KEYS`), resolved on the host; pass to `lexiconText`. */
|
|
80
|
+
lexicon: LexiconOverrides;
|
|
81
|
+
tools: LiveProfileToolsSpec;
|
|
82
|
+
guardrails?: ProfileGuardrailsView;
|
|
83
|
+
observability?: ProfileObservabilityView;
|
|
84
|
+
};
|
|
85
|
+
export type ProfileInterface = TextProfileInterface | ImageProfileInterface | SpeechProfileInterface | LiveProfileInterface;
|
|
86
|
+
/** Turn/chat composer profiles — excludes live (realtime streams, no turn inputs block). */
|
|
87
|
+
export type ComposerProfileInterface = Exclude<ProfileInterface, LiveProfileInterface>;
|
|
88
|
+
export type TranscriptBlockKind = 'user-text' | 'user-attachment' | 'user-voice' | 'thought' | 'text' | 'tool' | 'structured' | 'media' | 'grounding' | 'citation' | 'evidence' | 'error' | 'turn-done';
|
|
89
|
+
export interface TranscriptBlockBase {
|
|
90
|
+
id: string;
|
|
91
|
+
kind: TranscriptBlockKind;
|
|
92
|
+
}
|
|
93
|
+
export interface UserTextBlock extends TranscriptBlockBase {
|
|
94
|
+
kind: 'user-text';
|
|
95
|
+
text: string;
|
|
96
|
+
}
|
|
97
|
+
export interface UserAttachmentBlock extends TranscriptBlockBase {
|
|
98
|
+
kind: 'user-attachment' | 'user-voice';
|
|
99
|
+
name: string;
|
|
100
|
+
mimeType: string;
|
|
101
|
+
sizeBytes: number;
|
|
102
|
+
/** Optional base64 payload for inline image/audio preview in the host UI. */
|
|
103
|
+
data?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface ThoughtBlock extends TranscriptBlockBase {
|
|
106
|
+
kind: 'thought';
|
|
107
|
+
text: string;
|
|
108
|
+
}
|
|
109
|
+
export interface TextBlock extends TranscriptBlockBase {
|
|
110
|
+
kind: 'text';
|
|
111
|
+
text: string;
|
|
112
|
+
}
|
|
113
|
+
/** Where a call stands: the latest phase that changes its status. */
|
|
114
|
+
export type ToolCallState = Extract<ToolPhaseEvent, {
|
|
115
|
+
phase: 'running' | 'gate' | 'complete' | 'error' | 'cancel';
|
|
116
|
+
}>;
|
|
117
|
+
/** One tool call: the model's raw call joined with its phase events by `callId` (`toolCallsOf`). */
|
|
118
|
+
export interface ToolCall {
|
|
119
|
+
name: string;
|
|
120
|
+
callId: string;
|
|
121
|
+
/** What the model proposed. */
|
|
122
|
+
arguments: Record<string, unknown>;
|
|
123
|
+
/** The call's `ToolCallRequest.thoughtSignature`: history replays the call with it. */
|
|
124
|
+
thoughtSignature?: string;
|
|
125
|
+
/** The call's `ToolCallRequest.stepId`: calls sharing it replay as one assistant message. */
|
|
126
|
+
stepId?: string;
|
|
127
|
+
/** The user's edit on approval; `to` is what ran. */
|
|
128
|
+
edited?: ToolCallEdit;
|
|
129
|
+
/** What the call is doing, in the tool's words, from its last `running` phase. */
|
|
130
|
+
activity?: string;
|
|
131
|
+
/** What the call did, from its `complete` phase. */
|
|
132
|
+
activityPast?: string;
|
|
133
|
+
/** Absent while the call has only been made. */
|
|
134
|
+
state?: ToolCallState;
|
|
135
|
+
/** When it last started running (epoch ms). */
|
|
136
|
+
startedAt?: number;
|
|
137
|
+
/** When it last settled: complete, failed, cancelled or gated (epoch ms). */
|
|
138
|
+
endedAt?: number;
|
|
139
|
+
artifacts: unknown[];
|
|
140
|
+
}
|
|
141
|
+
export interface ToolBlock extends TranscriptBlockBase {
|
|
142
|
+
kind: 'tool';
|
|
143
|
+
tool: ToolCall;
|
|
144
|
+
}
|
|
145
|
+
export interface StructuredBlock extends TranscriptBlockBase {
|
|
146
|
+
kind: 'structured';
|
|
147
|
+
value: unknown;
|
|
148
|
+
}
|
|
149
|
+
export interface MediaBlock extends TranscriptBlockBase {
|
|
150
|
+
kind: 'media';
|
|
151
|
+
mimeType: string;
|
|
152
|
+
/** Base64 for model-generated or attached media. Absent when `url` is set. */
|
|
153
|
+
data?: string;
|
|
154
|
+
/** Remote http(s) URL promoted from completed tool output. Absent when `data` is set. */
|
|
155
|
+
url?: string;
|
|
156
|
+
/** A smaller copy of `url` for previews, when the tool output offered one. */
|
|
157
|
+
previewUrl?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface GroundingBlock extends TranscriptBlockBase {
|
|
160
|
+
kind: 'grounding';
|
|
161
|
+
grounding: GroundingEvent;
|
|
162
|
+
}
|
|
163
|
+
/** Sources a provider or a tool cited; `callId` names the tool call when a tool did. */
|
|
164
|
+
export interface CitationBlock extends TranscriptBlockBase {
|
|
165
|
+
kind: 'citation';
|
|
166
|
+
sources: Source[];
|
|
167
|
+
callId?: string;
|
|
168
|
+
}
|
|
169
|
+
export interface EvidenceBlock extends TranscriptBlockBase {
|
|
170
|
+
kind: 'evidence';
|
|
171
|
+
evidence: ProviderEvidence;
|
|
172
|
+
}
|
|
173
|
+
export interface ErrorBlock extends TranscriptBlockBase {
|
|
174
|
+
kind: 'error';
|
|
175
|
+
message: string;
|
|
176
|
+
}
|
|
177
|
+
export interface TurnDoneBlock extends TranscriptBlockBase {
|
|
178
|
+
kind: 'turn-done';
|
|
179
|
+
stop?: TurnStop;
|
|
180
|
+
tokens?: TurnTokens;
|
|
181
|
+
interactionId?: string;
|
|
182
|
+
compaction?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* How long the reply has worked so far (ms), approval waits excluded. The host
|
|
185
|
+
* client stamps it when a run ends, so the time travels with the transcript.
|
|
186
|
+
*/
|
|
187
|
+
workedMs?: number;
|
|
188
|
+
/** When the reply last stopped (epoch ms), stamped with `workedMs`. */
|
|
189
|
+
endedAt?: number;
|
|
190
|
+
}
|
|
191
|
+
export type TranscriptBlock = UserTextBlock | UserAttachmentBlock | ThoughtBlock | TextBlock | ToolBlock | StructuredBlock | MediaBlock | GroundingBlock | CitationBlock | EvidenceBlock | ErrorBlock | TurnDoneBlock;
|
|
192
|
+
export interface PendingAttachment {
|
|
193
|
+
name: string;
|
|
194
|
+
mimeType: string;
|
|
195
|
+
sizeBytes: number;
|
|
196
|
+
/** Optional base64 payload copied onto the transcript block for UI preview. */
|
|
197
|
+
data?: string;
|
|
198
|
+
}
|
|
199
|
+
export interface AttachmentValidationResult {
|
|
200
|
+
ok: boolean;
|
|
201
|
+
issues: AttachmentValidationIssue[];
|
|
202
|
+
}
|
|
203
|
+
export interface UserTurnDraft {
|
|
204
|
+
text?: string;
|
|
205
|
+
attachments?: PendingAttachment[];
|
|
206
|
+
voice?: PendingAttachment[];
|
|
207
|
+
}
|
|
208
|
+
export interface FoldTurnEventsOptions {
|
|
209
|
+
showThoughts?: boolean;
|
|
210
|
+
idPrefix?: string;
|
|
211
|
+
}
|
|
212
|
+
declare function streamThoughtsEnabled(outputs?: ProfileOutputsSpec): boolean;
|
|
213
|
+
export { streamThoughtsEnabled };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ToolCredential } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Where a call's tool credentials come from. The kernel reads a slot only when a
|
|
4
|
+
* tool that signs in runs, so a turn opens no credential it does not use.
|
|
5
|
+
*/
|
|
6
|
+
export interface ToolCredentialSource {
|
|
7
|
+
/** The slot's credential, or `undefined` when the person has not signed in. */
|
|
8
|
+
get(slot: string): Promise<ToolCredential | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* A new credential for the slot: a refreshed OAuth token, or a key typed at a
|
|
11
|
+
* sign-in gate. The call goes on only once it resolves, so persist it here; a
|
|
12
|
+
* rotated refresh token lost to a closed stream cannot be recovered.
|
|
13
|
+
*/
|
|
14
|
+
set(slot: string, credential: ToolCredential): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* The secret of a confidential OAuth client, read when the kernel refreshes a token
|
|
17
|
+
* issued to `clientId`. Omit it for public clients. The secret is the host's, not
|
|
18
|
+
* the person's, so it never lives on a stored credential.
|
|
19
|
+
*/
|
|
20
|
+
clientSecret?(clientId: string): Promise<string | undefined>;
|
|
21
|
+
}
|
|
22
|
+
/** A source held in memory, seeded from `initial` (copied, never written back). */
|
|
23
|
+
export declare function memoryCredentialSource(initial?: Readonly<Record<string, ToolCredential>>): ToolCredentialSource;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A source held in memory, seeded from `initial` (copied, never written back). */
|
|
2
|
+
export function memoryCredentialSource(initial = {}) {
|
|
3
|
+
const slots = new Map(Object.entries(initial));
|
|
4
|
+
return {
|
|
5
|
+
get: (slot) => Promise.resolve(slots.get(slot)),
|
|
6
|
+
set: (slot, credential) => {
|
|
7
|
+
slots.set(slot, credential);
|
|
8
|
+
return Promise.resolve();
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** RFC 4648 base64url, without padding. */
|
|
2
|
+
export declare function toBase64Url(bytes: Uint8Array): string;
|
|
3
|
+
export declare function fromBase64Url(base64url: string): Uint8Array<ArrayBuffer>;
|
|
4
|
+
/** RFC 7636 §4.1: 43 to 128 characters, drawn without modulo bias. */
|
|
5
|
+
export declare function generateCodeVerifier(length?: number): string;
|
|
6
|
+
/** RFC 7636 §4.2 S256. */
|
|
7
|
+
export declare function computeCodeChallenge(verifier: string): Promise<string>;
|
|
8
|
+
export interface SealedStatePayload {
|
|
9
|
+
codeVerifier: string;
|
|
10
|
+
expectedIssuer: string;
|
|
11
|
+
/** RFC 9207: a response without `iss` is refused. */
|
|
12
|
+
issRequired: boolean;
|
|
13
|
+
/** Fixed when the flow began. */
|
|
14
|
+
tokenEndpoint: string;
|
|
15
|
+
resource: string;
|
|
16
|
+
redirectUri: string;
|
|
17
|
+
/** Epoch milliseconds. */
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
clientId: string;
|
|
20
|
+
/** SHA-256 of the host's session binding. */
|
|
21
|
+
sessionBinding: string;
|
|
22
|
+
/** The scopes the flow asked for; a grant may hold none beyond them. Empty asks for the server's default. */
|
|
23
|
+
scopes: string[];
|
|
24
|
+
}
|
|
25
|
+
/** Encrypted, not only signed: the state crosses the browser and the server, and the PKCE verifier must stay secret. */
|
|
26
|
+
export declare function sealStatePayload(payload: SealedStatePayload, secret: string): Promise<string>;
|
|
27
|
+
export declare function unsealStatePayload(sealed: string, secret: string): Promise<SealedStatePayload>;
|
|
28
|
+
export interface SealSecretInput {
|
|
29
|
+
plaintext: string;
|
|
30
|
+
/** The host's sealing key: at least 32 bytes, kept apart from where sealed values are stored. */
|
|
31
|
+
key: string;
|
|
32
|
+
/** What the sealed value belongs to, such as owner, slot and row. Opening needs the same list. */
|
|
33
|
+
binding: readonly string[];
|
|
34
|
+
/** Names `key`, so a rotated key still opens what an older one sealed. */
|
|
35
|
+
keyVersion: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Seals a stored credential. AES-256-GCM under a key derived per seal; the key
|
|
39
|
+
* version and binding are authenticated, so a value copied to another owner,
|
|
40
|
+
* slot or row does not open.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sealSecret(input: SealSecretInput): Promise<string>;
|
|
43
|
+
export interface OpenSecretInput {
|
|
44
|
+
sealed: string;
|
|
45
|
+
/** Every key still in use, by version. */
|
|
46
|
+
keys: Readonly<Record<number, string>>;
|
|
47
|
+
/** The binding the value was sealed with. */
|
|
48
|
+
binding: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
/** Opens what `sealSecret` sealed; throws when the envelope, key version or binding does not match. */
|
|
51
|
+
export declare function openSecret(input: OpenSecretInput): Promise<string>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { base64ToBytes, bytesToBase64 } from '../util/base64.js';
|
|
2
|
+
/** RFC 4648 base64url, without padding. */
|
|
3
|
+
export function toBase64Url(bytes) {
|
|
4
|
+
return bytesToBase64(bytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
5
|
+
}
|
|
6
|
+
export function fromBase64Url(base64url) {
|
|
7
|
+
let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
|
|
8
|
+
while (base64.length % 4 !== 0) {
|
|
9
|
+
base64 += '=';
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
return base64ToBytes(base64);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
throw new Error(`Invalid base64url encoding: ${err instanceof Error ? err.message : String(err)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** RFC 7636 §4.1: 43 to 128 characters, drawn without modulo bias. */
|
|
19
|
+
export function generateCodeVerifier(length = 64) {
|
|
20
|
+
if (length < 43 || length > 128) {
|
|
21
|
+
throw new RangeError(`Invalid PKCE code_verifier length: ${length}. RFC 7636 Section 4.1 requires length between 43 and 128 characters.`);
|
|
22
|
+
}
|
|
23
|
+
const validChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
|
|
24
|
+
const maxValid = 256 - (256 % validChars.length); // 198 (66 * 3): rejecting above it removes modulo bias
|
|
25
|
+
let verifier = '';
|
|
26
|
+
const buffer = new Uint8Array(length * 2);
|
|
27
|
+
while (verifier.length < length) {
|
|
28
|
+
crypto.getRandomValues(buffer);
|
|
29
|
+
for (let i = 0; i < buffer.length && verifier.length < length; i++) {
|
|
30
|
+
const val = buffer[i];
|
|
31
|
+
if (val !== undefined && val < maxValid) {
|
|
32
|
+
verifier += validChars[val % validChars.length];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return verifier;
|
|
37
|
+
}
|
|
38
|
+
/** RFC 7636 §4.2 S256. */
|
|
39
|
+
export async function computeCodeChallenge(verifier) {
|
|
40
|
+
const encoder = new TextEncoder();
|
|
41
|
+
const data = encoder.encode(verifier);
|
|
42
|
+
const digest = await crypto.subtle.digest('SHA-256', data);
|
|
43
|
+
return toBase64Url(new Uint8Array(digest));
|
|
44
|
+
}
|
|
45
|
+
/** A secret shorter than 256 bits would be the weak link. */
|
|
46
|
+
const MIN_SECRET_BYTES = 32;
|
|
47
|
+
/** Public domain-separation labels, not secrets: each use of a host secret derives a key no other use shares. */
|
|
48
|
+
const STATE_CONTEXT = 'theorem/oauth-state/v1';
|
|
49
|
+
const SEAL_CONTEXT = 'theorem/sealed-secret/v1';
|
|
50
|
+
const IV_BYTES = 12;
|
|
51
|
+
/** A fresh salt per seal gives every seal its own key, so no key sees enough random nonces for one to repeat. */
|
|
52
|
+
const SALT_BYTES = 32;
|
|
53
|
+
/** Authenticated with the ciphertext, so a later scheme can be told apart and an old one is never guessed at. */
|
|
54
|
+
const ENVELOPE_VERSION = 'v1';
|
|
55
|
+
async function sealKey(secret, salt, info, label) {
|
|
56
|
+
const encoder = new TextEncoder();
|
|
57
|
+
const secretBytes = encoder.encode(secret);
|
|
58
|
+
if (secretBytes.length < MIN_SECRET_BYTES) {
|
|
59
|
+
throw new RangeError(`${label} must be at least ${MIN_SECRET_BYTES} bytes; got ${secretBytes.length}`);
|
|
60
|
+
}
|
|
61
|
+
const base = await crypto.subtle.importKey('raw', secretBytes, 'HKDF', false, ['deriveKey']);
|
|
62
|
+
return crypto.subtle.deriveKey({ name: 'HKDF', hash: 'SHA-256', salt: salt, info: encoder.encode(info) }, base, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
|
|
63
|
+
}
|
|
64
|
+
/** `salt.iv.ciphertext`, base64url: AES-256-GCM under a key derived per seal. */
|
|
65
|
+
async function sealBytes(plaintext, secret, scheme) {
|
|
66
|
+
const salt = crypto.getRandomValues(new Uint8Array(SALT_BYTES));
|
|
67
|
+
const key = await sealKey(secret, salt, scheme.info, scheme.label);
|
|
68
|
+
const iv = crypto.getRandomValues(new Uint8Array(IV_BYTES));
|
|
69
|
+
const ciphertext = await crypto.subtle.encrypt({
|
|
70
|
+
name: 'AES-GCM',
|
|
71
|
+
iv: iv,
|
|
72
|
+
additionalData: new TextEncoder().encode(scheme.associatedData),
|
|
73
|
+
}, key, new TextEncoder().encode(plaintext));
|
|
74
|
+
return [toBase64Url(salt), toBase64Url(iv), toBase64Url(new Uint8Array(ciphertext))].join('.');
|
|
75
|
+
}
|
|
76
|
+
/** The plaintext `sealBytes` sealed, or null when the envelope does not open under this secret and data. */
|
|
77
|
+
async function openBytes(parts, secret, scheme) {
|
|
78
|
+
const [saltB64, ivB64, ciphertextB64] = parts;
|
|
79
|
+
if (saltB64 === undefined || ivB64 === undefined || ciphertextB64 === undefined)
|
|
80
|
+
return null;
|
|
81
|
+
const key = await sealKey(secret, fromBase64Url(saltB64), scheme.info, scheme.label);
|
|
82
|
+
try {
|
|
83
|
+
const plaintext = await crypto.subtle.decrypt({
|
|
84
|
+
name: 'AES-GCM',
|
|
85
|
+
iv: fromBase64Url(ivB64),
|
|
86
|
+
additionalData: new TextEncoder().encode(scheme.associatedData),
|
|
87
|
+
}, key, fromBase64Url(ciphertextB64));
|
|
88
|
+
return new TextDecoder().decode(plaintext);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const STATE_SCHEME = {
|
|
95
|
+
info: STATE_CONTEXT,
|
|
96
|
+
label: 'OAuth state secret', // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
97
|
+
associatedData: ENVELOPE_VERSION,
|
|
98
|
+
};
|
|
99
|
+
/** Encrypted, not only signed: the state crosses the browser and the server, and the PKCE verifier must stay secret. */
|
|
100
|
+
export async function sealStatePayload(payload, secret) {
|
|
101
|
+
const envelope = await sealBytes(JSON.stringify(payload), secret, STATE_SCHEME);
|
|
102
|
+
return [ENVELOPE_VERSION, envelope].join('.');
|
|
103
|
+
}
|
|
104
|
+
export async function unsealStatePayload(sealed, secret) {
|
|
105
|
+
const [version, ...parts] = sealed.split('.');
|
|
106
|
+
if (version !== ENVELOPE_VERSION || parts.length !== 3) {
|
|
107
|
+
throw new Error('Invalid sealed state format'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
108
|
+
}
|
|
109
|
+
const plaintext = await openBytes(parts, secret, STATE_SCHEME);
|
|
110
|
+
if (plaintext === null) {
|
|
111
|
+
throw new Error('OAuth state could not be opened: it was tampered with, corrupted, or sealed with another secret');
|
|
112
|
+
}
|
|
113
|
+
const payload = JSON.parse(plaintext);
|
|
114
|
+
if (!Array.isArray(payload.scopes)) {
|
|
115
|
+
throw new Error('Invalid sealed state format'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
116
|
+
}
|
|
117
|
+
if (Date.now() > payload.expiresAt) {
|
|
118
|
+
throw new Error('OAuth state has expired'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
119
|
+
}
|
|
120
|
+
return payload;
|
|
121
|
+
}
|
|
122
|
+
function secretScheme(keyVersion, binding) {
|
|
123
|
+
return {
|
|
124
|
+
info: SEAL_CONTEXT,
|
|
125
|
+
label: 'Secret sealing key', // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
126
|
+
associatedData: JSON.stringify([ENVELOPE_VERSION, keyVersion, binding]),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function assertKeyVersion(keyVersion) {
|
|
130
|
+
if (!Number.isSafeInteger(keyVersion) || keyVersion < 0) {
|
|
131
|
+
throw new RangeError(`Key version must be a non-negative integer; got ${keyVersion}`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Seals a stored credential. AES-256-GCM under a key derived per seal; the key
|
|
136
|
+
* version and binding are authenticated, so a value copied to another owner,
|
|
137
|
+
* slot or row does not open.
|
|
138
|
+
*/
|
|
139
|
+
export async function sealSecret(input) {
|
|
140
|
+
assertKeyVersion(input.keyVersion);
|
|
141
|
+
const scheme = secretScheme(input.keyVersion, input.binding);
|
|
142
|
+
const envelope = await sealBytes(input.plaintext, input.key, scheme);
|
|
143
|
+
return [ENVELOPE_VERSION, String(input.keyVersion), envelope].join('.');
|
|
144
|
+
}
|
|
145
|
+
/** Opens what `sealSecret` sealed; throws when the envelope, key version or binding does not match. */
|
|
146
|
+
export async function openSecret(input) {
|
|
147
|
+
const [version, keyVersionText, ...parts] = input.sealed.split('.');
|
|
148
|
+
const keyVersion = Number(keyVersionText);
|
|
149
|
+
if (version !== ENVELOPE_VERSION || parts.length !== 3 || !/^\d+$/.test(keyVersionText ?? '')) {
|
|
150
|
+
throw new Error('Invalid sealed secret format'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
151
|
+
}
|
|
152
|
+
const key = input.keys[keyVersion];
|
|
153
|
+
if (key === undefined) {
|
|
154
|
+
throw new Error(`No key for sealed secret key version ${keyVersion}`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
155
|
+
}
|
|
156
|
+
const plaintext = await openBytes(parts, key, secretScheme(keyVersion, input.binding));
|
|
157
|
+
if (plaintext === null) {
|
|
158
|
+
throw new Error('Sealed secret could not be opened: it was tampered with, bound to something else, or sealed with another key');
|
|
159
|
+
}
|
|
160
|
+
return plaintext;
|
|
161
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AuthorizationServerMetadata, CreatePkceFlowOptions, ExchangePkceCodeOptions, ExchangePkceCodeResult, OAuthTransportOptions, PkceFlowResult, ProtectedResourceMetadata, RefreshOAuthTokenOptions } from './types.js';
|
|
2
|
+
/** `undefined` on HTTP 404. RFC 9728 §3.3: a `resource` not identical to `resourceUrl` is refused. */
|
|
3
|
+
export declare function discoverResourceMetadata(resourceUrl: string, transport?: OAuthTransportOptions): Promise<ProtectedResourceMetadata | undefined>;
|
|
4
|
+
/** A non-OK URL moves on to the next; metadata that answers but fails validation is refused outright. */
|
|
5
|
+
export declare function discoverAuthServerMetadata(issuer: string, transport?: OAuthTransportOptions): Promise<AuthorizationServerMetadata>;
|
|
6
|
+
/** Stateless: the verifier, expected issuer, token endpoint and resource are sealed into `state`. */
|
|
7
|
+
export declare function createOAuthPkceFlow(options: CreatePkceFlowOptions): Promise<PkceFlowResult>;
|
|
8
|
+
/** RFC 9207 §2.4: `iss` is required when the server advertises it, and byte-exact (no URL normalization). */
|
|
9
|
+
export declare function validateIssuer(expectedIssuer: string, receivedIss: string | undefined, issRequired: boolean): void;
|
|
10
|
+
/**
|
|
11
|
+
* Requires the session that began the flow (RFC 6749 §10.12), the same `redirect_uri` (§4.1.3)
|
|
12
|
+
* and a valid `iss` (RFC 9207); posts to the token endpoint sealed in `state`, never a caller's.
|
|
13
|
+
*/
|
|
14
|
+
export declare function exchangeOAuthPkce(options: ExchangePkceCodeOptions): Promise<ExchangePkceCodeResult>;
|
|
15
|
+
export declare function refreshOAuthToken(options: RefreshOAuthTokenOptions): Promise<ExchangePkceCodeResult>;
|
|
16
|
+
/** RFC 8707: the same origin, and the resource's path or below it. */
|
|
17
|
+
export declare function tokenAudienceCovers(resource: string, url: URL): boolean;
|