@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,22 @@
|
|
|
1
|
+
import type { TraceSink } from '../observability/trace-sink.js';
|
|
2
|
+
import { type RunDecisionOptions } from './engine/decision.js';
|
|
3
|
+
import { type RunSessionOptions } from './engine/session/mod.js';
|
|
4
|
+
import { type KernelRegistry } from './registry/kernel-registry.js';
|
|
5
|
+
import { resolveTurnInRegistry } from './registry/resolve.js';
|
|
6
|
+
import type { InvokeToolRequest } from './tools/types.js';
|
|
7
|
+
import type { CompactHistoryRequest, CompactionResult, DecisionRequest, DecisionResult, LiveSession, ModelProvider, ProjectedProfile, SessionRequest, TurnEvent, TurnRequest } from './types.js';
|
|
8
|
+
interface KernelScope extends KernelRegistry {
|
|
9
|
+
runTurn(req: TurnRequest, provider: ModelProvider, sinkOverride?: TraceSink): AsyncGenerator<TurnEvent>;
|
|
10
|
+
runSession(req: SessionRequest, options: RunSessionOptions, sinkOverride?: TraceSink): Promise<LiveSession>;
|
|
11
|
+
compactHistory(req: CompactHistoryRequest, provider: ModelProvider, sinkOverride?: TraceSink): Promise<CompactionResult | undefined>;
|
|
12
|
+
invokeTool(request: InvokeToolRequest, sinkOverride?: TraceSink): AsyncGenerator<TurnEvent>;
|
|
13
|
+
resolveTurn(req: TurnRequest): ReturnType<typeof resolveTurnInRegistry>;
|
|
14
|
+
projectProfile(id: string): ProjectedProfile;
|
|
15
|
+
runDecision(request: DecisionRequest, options: RunDecisionOptions): Promise<DecisionResult>;
|
|
16
|
+
}
|
|
17
|
+
/** Isolated from every other scope: a host that registers per request gives each its own. */
|
|
18
|
+
declare function createKernelScope(): KernelScope;
|
|
19
|
+
/** The process-wide scope behind the package's global API. */
|
|
20
|
+
declare const defaultKernelScope: KernelScope;
|
|
21
|
+
export type { KernelScope };
|
|
22
|
+
export { createKernelScope, defaultKernelScope };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { runDecisionInRegistry } from './engine/decision.js';
|
|
2
|
+
import { compactHistoryInRegistry, runTurnInRegistry } from './engine/runner/mod.js';
|
|
3
|
+
import { runSessionInRegistry } from './engine/session/mod.js';
|
|
4
|
+
import { createKernelRegistry } from './registry/kernel-registry.js';
|
|
5
|
+
import { projectProfileInRegistry, resolveTurnInRegistry } from './registry/resolve.js';
|
|
6
|
+
import { invokeTool } from './tools/invoke.js';
|
|
7
|
+
/** Isolated from every other scope: a host that registers per request gives each its own. */
|
|
8
|
+
function createKernelScope() {
|
|
9
|
+
const registry = createKernelRegistry();
|
|
10
|
+
return {
|
|
11
|
+
tools: registry.tools,
|
|
12
|
+
profiles: registry.profiles,
|
|
13
|
+
schemas: registry.schemas,
|
|
14
|
+
runTurn: (req, provider, sinkOverride) => runTurnInRegistry(registry, req, provider, sinkOverride),
|
|
15
|
+
runSession: (req, options, sinkOverride) => runSessionInRegistry(registry, req, options, sinkOverride),
|
|
16
|
+
compactHistory: (req, provider, sinkOverride) => compactHistoryInRegistry(registry, req, provider, sinkOverride),
|
|
17
|
+
invokeTool: (request, sinkOverride) => invokeTool(registry, request, sinkOverride),
|
|
18
|
+
resolveTurn: (req) => resolveTurnInRegistry(registry, req),
|
|
19
|
+
projectProfile: (id) => projectProfileInRegistry(registry, id),
|
|
20
|
+
runDecision: (request, options) => runDecisionInRegistry(registry, request, options),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** The process-wide scope behind the package's global API. */
|
|
24
|
+
const defaultKernelScope = createKernelScope();
|
|
25
|
+
export { createKernelScope, defaultKernelScope };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { SpanHandle } from '../observability/trace-span.js';
|
|
2
|
+
import type { StageApplyWarningCode, TurnStage } from './schema.js';
|
|
3
|
+
import type { TurnStop } from './stop.js';
|
|
4
|
+
import type { ModelToolResult, ToolFailure, ToolGate } from './tools/types.js';
|
|
5
|
+
import { type AwaitingUserInput, type StageApplyWarning, type TurnEventOf } from './turn-events.js';
|
|
6
|
+
import type { Profile, TurnEvent, TurnHistoryMessage } from './types.js';
|
|
7
|
+
export type { AwaitingUserInput, ToolGate };
|
|
8
|
+
export declare const STAGE_AFFORDANCES: readonly ["inject", "abort", "deny", "confirm", "mutate"];
|
|
9
|
+
export type StageAffordance = (typeof STAGE_AFFORDANCES)[number];
|
|
10
|
+
/** Inject still needs the inject gate at apply time. Empty = observe only. */
|
|
11
|
+
export declare const STAGE_AFFORDANCE_MATRIX: Readonly<Record<TurnStage, readonly StageAffordance[]>>;
|
|
12
|
+
export type StageCallBag = {
|
|
13
|
+
callId?: string;
|
|
14
|
+
tool?: string;
|
|
15
|
+
input?: unknown;
|
|
16
|
+
callNotStarted?: boolean;
|
|
17
|
+
outputRaw?: unknown;
|
|
18
|
+
outputModel?: ModelToolResult;
|
|
19
|
+
failure?: ToolFailure;
|
|
20
|
+
awaiting?: boolean;
|
|
21
|
+
stop?: TurnStop;
|
|
22
|
+
gate?: ToolGate;
|
|
23
|
+
};
|
|
24
|
+
export interface StageContext extends StageCallBag {
|
|
25
|
+
stage: TurnStage;
|
|
26
|
+
/** 1-based provider step (text) or utterance cycle index (live). */
|
|
27
|
+
step: number;
|
|
28
|
+
history: readonly TurnHistoryMessage[];
|
|
29
|
+
/** Opaque host slot — never traced or client-forwarded by the kernel. */
|
|
30
|
+
host?: unknown;
|
|
31
|
+
}
|
|
32
|
+
export interface StageResult {
|
|
33
|
+
inject?: TurnHistoryMessage[];
|
|
34
|
+
/**
|
|
35
|
+
* Names this `inject` in the `stage` event that records it landing. A blank or
|
|
36
|
+
* non-string id refuses the inject whole.
|
|
37
|
+
*/
|
|
38
|
+
injectId?: string;
|
|
39
|
+
abort?: boolean | {
|
|
40
|
+
reason?: string;
|
|
41
|
+
};
|
|
42
|
+
/** `pre_tool`: refuse the call. `post_tool`: replace the result with this failure. */
|
|
43
|
+
deny?: {
|
|
44
|
+
code?: string;
|
|
45
|
+
message?: string;
|
|
46
|
+
};
|
|
47
|
+
/** `pre_tool` only — request a confirm/permission gate. */
|
|
48
|
+
confirm?: true | {
|
|
49
|
+
summary?: string;
|
|
50
|
+
};
|
|
51
|
+
/** `pre_tool`: replace the call input. `post_tool`: replace the raw output. Both re-validate. */
|
|
52
|
+
mutate?: StageMutate;
|
|
53
|
+
}
|
|
54
|
+
export type StageMutate = {
|
|
55
|
+
input: unknown;
|
|
56
|
+
} | {
|
|
57
|
+
output: unknown;
|
|
58
|
+
};
|
|
59
|
+
export type StageHandler = (ctx: StageContext) => StageResult | undefined | Promise<StageResult | undefined>;
|
|
60
|
+
export type { StageApplyWarning, StageApplyWarningCode };
|
|
61
|
+
export interface StageApplyInput {
|
|
62
|
+
stage: TurnStage;
|
|
63
|
+
result: unknown;
|
|
64
|
+
injectAllowed: boolean;
|
|
65
|
+
injectWouldExceedMaxSteps?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* False when the stage's mutate subject is absent at this fire (a `post_tool`
|
|
68
|
+
* whose body never completed, or a tool whose output the kernel must own).
|
|
69
|
+
* `mutate` is then a `mutate_invalid` warning, never a silent no-op.
|
|
70
|
+
*/
|
|
71
|
+
mutable?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface InjectUnit {
|
|
74
|
+
id?: string;
|
|
75
|
+
messages: TurnHistoryMessage[];
|
|
76
|
+
}
|
|
77
|
+
export interface StageApplyOutput {
|
|
78
|
+
inject?: InjectUnit;
|
|
79
|
+
abort?: boolean | {
|
|
80
|
+
reason?: string;
|
|
81
|
+
};
|
|
82
|
+
deny?: {
|
|
83
|
+
code: string;
|
|
84
|
+
message: string;
|
|
85
|
+
};
|
|
86
|
+
confirm?: {
|
|
87
|
+
summary?: string;
|
|
88
|
+
};
|
|
89
|
+
mutate?: StageMutate;
|
|
90
|
+
warnings: StageApplyWarning[];
|
|
91
|
+
}
|
|
92
|
+
/** True when the affordance is physically allowed at `stage` (ignores inject gate). */
|
|
93
|
+
export declare function stageAllowsAffordance(stage: TurnStage, affordance: StageAffordance): boolean;
|
|
94
|
+
export declare function isAwaitingUserInput(output: unknown): output is AwaitingUserInput;
|
|
95
|
+
/** Never throws: invalid fields become warnings and are dropped. */
|
|
96
|
+
export declare function applyStageResult(input: StageApplyInput): StageApplyOutput;
|
|
97
|
+
export type StageEventExtra = {
|
|
98
|
+
callId?: string;
|
|
99
|
+
toolName?: string;
|
|
100
|
+
callNotStarted?: boolean;
|
|
101
|
+
awaiting?: boolean;
|
|
102
|
+
gate?: ToolGate;
|
|
103
|
+
stop?: TurnStop;
|
|
104
|
+
injected?: {
|
|
105
|
+
id: string;
|
|
106
|
+
}[];
|
|
107
|
+
};
|
|
108
|
+
/** Build a stream `stage` event. Unknown extra keys are not copied. */
|
|
109
|
+
export declare function stageEventFields(stage: TurnStage, extra?: Partial<StageEventExtra>): TurnEventOf<'stage'>;
|
|
110
|
+
export declare function injectMessages(units: readonly InjectUnit[]): TurnHistoryMessage[];
|
|
111
|
+
/**
|
|
112
|
+
* The `stage` event recording that `units` landed, naming the ones the host
|
|
113
|
+
* named; `undefined` when none was named. Emit it where the messages land,
|
|
114
|
+
* never before: an inject that never lands is never reported.
|
|
115
|
+
*/
|
|
116
|
+
export declare function injectedStageEvent(stage: TurnStage, units: readonly InjectUnit[], extra?: Pick<StageEventExtra, 'callId' | 'toolName'>): TurnEventOf<'stage'> | undefined;
|
|
117
|
+
export declare function injectWouldExceedMaxSteps(stepCount: number, maxSteps: number | undefined): boolean;
|
|
118
|
+
export interface RunStageArgs extends StageCallBag {
|
|
119
|
+
stage: TurnStage;
|
|
120
|
+
step: number;
|
|
121
|
+
history: readonly TurnHistoryMessage[];
|
|
122
|
+
/**
|
|
123
|
+
* Handlers in call order. Later scalars win, `inject` lists concatenate. A
|
|
124
|
+
* tool-local `preTool` result rides here as the first handler.
|
|
125
|
+
*/
|
|
126
|
+
handlers: readonly StageHandler[];
|
|
127
|
+
/** Profile guardrails — every inject site runs the untrusted sanitize path. */
|
|
128
|
+
guardrails: Profile['guardrails'];
|
|
129
|
+
injectAllowed: boolean;
|
|
130
|
+
injectWouldExceedMaxSteps?: boolean;
|
|
131
|
+
mutable?: boolean;
|
|
132
|
+
host?: unknown;
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
span?: SpanHandle;
|
|
135
|
+
}
|
|
136
|
+
/** Applied stage output: every handler's inject, in call order, sanitized. */
|
|
137
|
+
export interface RunStageOutput extends Omit<StageApplyOutput, 'inject'> {
|
|
138
|
+
inject: InjectUnit[];
|
|
139
|
+
}
|
|
140
|
+
/** Stage events always emit, even with no handlers. */
|
|
141
|
+
export declare function runStage(args: RunStageArgs): AsyncGenerator<TurnEvent, RunStageOutput>;
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { throwIfAborted } from '../guardrails/error.js';
|
|
2
|
+
import { guardrailFromHits } from '../guardrails/events.js';
|
|
3
|
+
import { detectionForTrust, resolveGuardrailPolicy } from '../guardrails/policy.js';
|
|
4
|
+
import { sanitizeHistory } from '../guardrails/sanitize.js';
|
|
5
|
+
import { guardrailAttributes } from './engine/turn-trace.js';
|
|
6
|
+
import { awaitingUserInputSchema, } from './turn-events.js';
|
|
7
|
+
import { isRecord } from './util/record.js';
|
|
8
|
+
export const STAGE_AFFORDANCES = ['inject', 'abort', 'deny', 'confirm', 'mutate'];
|
|
9
|
+
/** Inject still needs the inject gate at apply time. Empty = observe only. */
|
|
10
|
+
export const STAGE_AFFORDANCE_MATRIX = Object.freeze({
|
|
11
|
+
pre_turn: Object.freeze(['inject', 'abort']),
|
|
12
|
+
pre_tool: Object.freeze(['abort', 'deny', 'confirm', 'mutate']),
|
|
13
|
+
post_tool: Object.freeze(['inject', 'abort', 'deny', 'mutate']),
|
|
14
|
+
before_end: Object.freeze(['inject', 'abort']),
|
|
15
|
+
post_turn: Object.freeze([]),
|
|
16
|
+
});
|
|
17
|
+
const STAGE_RESULT_KEYS = new Set([...STAGE_AFFORDANCES, 'injectId']);
|
|
18
|
+
/** True when the affordance is physically allowed at `stage` (ignores inject gate). */
|
|
19
|
+
export function stageAllowsAffordance(stage, affordance) {
|
|
20
|
+
return STAGE_AFFORDANCE_MATRIX[stage].includes(affordance);
|
|
21
|
+
}
|
|
22
|
+
function warn(warnings, code, field, message) {
|
|
23
|
+
warnings.push({ code, field, message });
|
|
24
|
+
}
|
|
25
|
+
export function isAwaitingUserInput(output) {
|
|
26
|
+
return awaitingUserInputSchema.safeParse(output).success;
|
|
27
|
+
}
|
|
28
|
+
/** Drops unknown keys and rejects `role: 'tool'`; sanitizeHistory runs at the inject site. */
|
|
29
|
+
function coerceInjectMessage(item, warnings) {
|
|
30
|
+
if (!isRecord(item)) {
|
|
31
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject entry must be an object'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (item.role === 'tool') {
|
|
35
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject messages with role "tool" are rejected');
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (item.role !== 'user' && item.role !== 'assistant' && item.role !== 'system') {
|
|
39
|
+
warn(warnings, 'inject_invalid_messages', 'inject', `inject role not allowed: ${String(item.role)}`);
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const msg = { role: item.role };
|
|
43
|
+
if (item.content !== undefined) {
|
|
44
|
+
if (typeof item.content !== 'string') {
|
|
45
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject content must be a string when present');
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
msg.content = item.content;
|
|
49
|
+
}
|
|
50
|
+
if (item.parts !== undefined) {
|
|
51
|
+
if (!Array.isArray(item.parts)) {
|
|
52
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject parts must be an array when present');
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
msg.parts = item.parts;
|
|
56
|
+
}
|
|
57
|
+
if (item.tool_calls !== undefined) {
|
|
58
|
+
if (!Array.isArray(item.tool_calls)) {
|
|
59
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject tool_calls must be an array when present');
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
msg.tool_calls = item.tool_calls;
|
|
63
|
+
}
|
|
64
|
+
if (item.name !== undefined) {
|
|
65
|
+
if (typeof item.name !== 'string') {
|
|
66
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject name must be a string'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
msg.name = item.name;
|
|
70
|
+
}
|
|
71
|
+
if (item.metadata !== undefined) {
|
|
72
|
+
if (!isRecord(item.metadata)) {
|
|
73
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject metadata must be a plain object'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
msg.metadata = { ...item.metadata };
|
|
77
|
+
}
|
|
78
|
+
if (item.tool_call_id !== undefined) {
|
|
79
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject tool_call_id is rejected (not a tool-role message)');
|
|
80
|
+
}
|
|
81
|
+
return msg;
|
|
82
|
+
}
|
|
83
|
+
function coerceHistoryMessages(raw, warnings) {
|
|
84
|
+
if (!Array.isArray(raw)) {
|
|
85
|
+
warn(warnings, 'inject_invalid_messages', 'inject', 'inject must be an array of history messages');
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const item of raw) {
|
|
90
|
+
const msg = coerceInjectMessage(item, warnings);
|
|
91
|
+
if (msg)
|
|
92
|
+
out.push(msg);
|
|
93
|
+
}
|
|
94
|
+
return out.length > 0 ? out : undefined;
|
|
95
|
+
}
|
|
96
|
+
/** The inject's messages under its id; an unusable id refuses the inject whole. */
|
|
97
|
+
function injectUnit(result, warnings) {
|
|
98
|
+
const messages = coerceHistoryMessages(result.inject, warnings);
|
|
99
|
+
if (!messages)
|
|
100
|
+
return undefined;
|
|
101
|
+
if (result.injectId === undefined)
|
|
102
|
+
return { messages };
|
|
103
|
+
if (typeof result.injectId === 'string' && result.injectId.trim()) {
|
|
104
|
+
return { id: result.injectId, messages };
|
|
105
|
+
}
|
|
106
|
+
warn(warnings, 'inject_id_invalid', 'injectId', 'injectId must be a non-empty string; inject refused');
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
function applyInjectField(result, input, out) {
|
|
110
|
+
if (!('inject' in result) || result.inject === undefined) {
|
|
111
|
+
if (result.injectId !== undefined) {
|
|
112
|
+
warn(out.warnings, 'inject_id_invalid', 'injectId', 'injectId without inject ignored'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const { stage, injectAllowed, injectWouldExceedMaxSteps } = input;
|
|
117
|
+
if (!stageAllowsAffordance(stage, 'inject')) {
|
|
118
|
+
warn(out.warnings, 'affordance_not_allowed', 'inject', `inject is not allowed at stage ${stage}`);
|
|
119
|
+
}
|
|
120
|
+
else if (!injectAllowed) {
|
|
121
|
+
warn(out.warnings, 'inject_not_allowed', 'inject', 'inject gate is closed for this profile/session');
|
|
122
|
+
}
|
|
123
|
+
else if (injectWouldExceedMaxSteps) {
|
|
124
|
+
warn(out.warnings, 'inject_rejected_max_steps', 'inject', 'inject rejected: another model step would exceed maxSteps');
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const unit = injectUnit(result, out.warnings);
|
|
128
|
+
if (unit)
|
|
129
|
+
out.inject = unit;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function applyAbortField(result, stage, out) {
|
|
133
|
+
if (!('abort' in result) || result.abort === undefined)
|
|
134
|
+
return;
|
|
135
|
+
if (!stageAllowsAffordance(stage, 'abort')) {
|
|
136
|
+
warn(out.warnings, 'affordance_not_allowed', 'abort', 'abort is not allowed at post_turn'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
137
|
+
}
|
|
138
|
+
else if (result.abort === true) {
|
|
139
|
+
out.abort = true;
|
|
140
|
+
}
|
|
141
|
+
else if (isRecord(result.abort)) {
|
|
142
|
+
const reason = typeof result.abort.reason === 'string' && result.abort.reason.trim()
|
|
143
|
+
? result.abort.reason.trim()
|
|
144
|
+
: undefined;
|
|
145
|
+
out.abort = reason ? { reason } : true;
|
|
146
|
+
}
|
|
147
|
+
else if (result.abort !== false) {
|
|
148
|
+
warn(out.warnings, 'abort_invalid', 'abort', 'abort must be boolean or { reason?: string }'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function applyDenyField(result, stage, out) {
|
|
152
|
+
if (!('deny' in result) || result.deny === undefined)
|
|
153
|
+
return;
|
|
154
|
+
if (!stageAllowsAffordance(stage, 'deny')) {
|
|
155
|
+
warn(out.warnings, 'affordance_not_allowed', 'deny', `deny is not allowed at stage ${stage}`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
156
|
+
}
|
|
157
|
+
else if (!isRecord(result.deny)) {
|
|
158
|
+
warn(out.warnings, 'deny_invalid', 'deny', 'deny must be an object'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const code = typeof result.deny.code === 'string' && result.deny.code.trim()
|
|
162
|
+
? result.deny.code.trim()
|
|
163
|
+
: 'not_authorized';
|
|
164
|
+
const message = typeof result.deny.message === 'string' && result.deny.message.trim()
|
|
165
|
+
? result.deny.message.trim()
|
|
166
|
+
: 'Tool execution not authorized'; // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
167
|
+
out.deny = { code, message };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function applyConfirmField(result, stage, out) {
|
|
171
|
+
if (!('confirm' in result) || result.confirm === undefined)
|
|
172
|
+
return;
|
|
173
|
+
if (!stageAllowsAffordance(stage, 'confirm')) {
|
|
174
|
+
warn(out.warnings, 'affordance_not_allowed', 'confirm', `confirm is not allowed at stage ${stage}`);
|
|
175
|
+
}
|
|
176
|
+
else if (result.confirm === true) {
|
|
177
|
+
out.confirm = {};
|
|
178
|
+
}
|
|
179
|
+
else if (isRecord(result.confirm)) {
|
|
180
|
+
const summary = typeof result.confirm.summary === 'string' && result.confirm.summary.trim()
|
|
181
|
+
? result.confirm.summary.trim()
|
|
182
|
+
: undefined;
|
|
183
|
+
out.confirm = summary ? { summary } : {};
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
warn(out.warnings, 'confirm_invalid', 'confirm', 'confirm must be true or { summary?: string }');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const MUTATE_SUBJECT = { pre_tool: 'input', post_tool: 'output' };
|
|
190
|
+
function mutateSubject(stage) {
|
|
191
|
+
return stage in MUTATE_SUBJECT ? MUTATE_SUBJECT[stage] : undefined;
|
|
192
|
+
}
|
|
193
|
+
function applyMutateField(result, input, out) {
|
|
194
|
+
const { stage } = input;
|
|
195
|
+
if (!('mutate' in result) || result.mutate === undefined)
|
|
196
|
+
return;
|
|
197
|
+
if (!stageAllowsAffordance(stage, 'mutate')) {
|
|
198
|
+
warn(out.warnings, 'affordance_not_allowed', 'mutate', `mutate is not allowed at stage ${stage}`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const subject = mutateSubject(stage);
|
|
202
|
+
if (!subject) {
|
|
203
|
+
// Matrix allows mutate but no subject is mapped: a kernel drift, surfaced not swallowed.
|
|
204
|
+
warn(out.warnings, 'mutate_invalid', 'mutate',
|
|
205
|
+
// lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
206
|
+
`no mutate subject is defined at stage ${stage}`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!isRecord(result.mutate) || result.mutate[subject] === undefined) {
|
|
210
|
+
warn(out.warnings, 'mutate_invalid', 'mutate',
|
|
211
|
+
// lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
212
|
+
`mutate must be { ${subject}: unknown } at stage ${stage}`);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (input.mutable === false) {
|
|
216
|
+
warn(out.warnings, 'mutate_invalid', 'mutate',
|
|
217
|
+
// lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
218
|
+
`there is no ${subject} to replace at this ${stage} fire`);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
out.mutate =
|
|
222
|
+
subject === 'input' ? { input: result.mutate.input } : { output: result.mutate.output };
|
|
223
|
+
}
|
|
224
|
+
/** Never throws: invalid fields become warnings and are dropped. */
|
|
225
|
+
export function applyStageResult(input) {
|
|
226
|
+
const warnings = [];
|
|
227
|
+
const out = { warnings };
|
|
228
|
+
const { stage, result } = input;
|
|
229
|
+
if (result == null)
|
|
230
|
+
return out;
|
|
231
|
+
if (!isRecord(result)) {
|
|
232
|
+
warn(warnings, 'result_invalid', 'result', 'StageResult must be a plain object'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
for (const key of Object.keys(result)) {
|
|
236
|
+
if (!STAGE_RESULT_KEYS.has(key)) {
|
|
237
|
+
warn(warnings, 'unknown_field', key, `unknown StageResult field "${key}" ignored`); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
applyInjectField(result, input, out);
|
|
241
|
+
applyAbortField(result, stage, out);
|
|
242
|
+
applyDenyField(result, stage, out);
|
|
243
|
+
applyConfirmField(result, stage, out);
|
|
244
|
+
applyMutateField(result, input, out);
|
|
245
|
+
// confirm + deny together: deny wins
|
|
246
|
+
if (out.deny && out.confirm) {
|
|
247
|
+
warn(warnings, 'confirm_invalid', 'confirm', 'confirm ignored because deny is set'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
248
|
+
delete out.confirm;
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
/** Build a stream `stage` event. Unknown extra keys are not copied. */
|
|
253
|
+
export function stageEventFields(stage, extra) {
|
|
254
|
+
const event = { type: 'stage', stage };
|
|
255
|
+
if (!extra)
|
|
256
|
+
return event;
|
|
257
|
+
if (extra.callId !== undefined)
|
|
258
|
+
event.callId = extra.callId;
|
|
259
|
+
if (extra.toolName !== undefined)
|
|
260
|
+
event.toolName = extra.toolName;
|
|
261
|
+
if (extra.callNotStarted !== undefined)
|
|
262
|
+
event.callNotStarted = extra.callNotStarted;
|
|
263
|
+
if (extra.awaiting !== undefined)
|
|
264
|
+
event.awaiting = extra.awaiting;
|
|
265
|
+
if (extra.gate !== undefined)
|
|
266
|
+
event.gate = extra.gate;
|
|
267
|
+
if (extra.stop !== undefined)
|
|
268
|
+
event.stop = extra.stop;
|
|
269
|
+
if (extra.injected !== undefined)
|
|
270
|
+
event.injected = extra.injected;
|
|
271
|
+
return event;
|
|
272
|
+
}
|
|
273
|
+
export function injectMessages(units) {
|
|
274
|
+
return units.flatMap((unit) => unit.messages);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The `stage` event recording that `units` landed, naming the ones the host
|
|
278
|
+
* named; `undefined` when none was named. Emit it where the messages land,
|
|
279
|
+
* never before: an inject that never lands is never reported.
|
|
280
|
+
*/
|
|
281
|
+
export function injectedStageEvent(stage, units, extra) {
|
|
282
|
+
const injected = units.flatMap((unit) => (unit.id === undefined ? [] : [{ id: unit.id }]));
|
|
283
|
+
if (injected.length === 0)
|
|
284
|
+
return undefined;
|
|
285
|
+
return stageEventFields(stage, { ...extra, injected });
|
|
286
|
+
}
|
|
287
|
+
export function injectWouldExceedMaxSteps(stepCount, maxSteps) {
|
|
288
|
+
if (maxSteps === undefined || maxSteps <= 0)
|
|
289
|
+
return false;
|
|
290
|
+
return stepCount >= maxSteps;
|
|
291
|
+
}
|
|
292
|
+
function appliedAffordance(applied, key) {
|
|
293
|
+
return key === 'inject' ? applied.inject.length > 0 : Boolean(applied[key]);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Merge per-handler applied outputs in call order. Later scalars win, `inject`
|
|
297
|
+
* lists concatenate, warnings accumulate. `deny` beats `confirm` across handlers
|
|
298
|
+
* exactly as it does within one return.
|
|
299
|
+
*/
|
|
300
|
+
function mergeApplied(parts) {
|
|
301
|
+
const out = { warnings: parts.flatMap((part) => part.warnings), inject: [] };
|
|
302
|
+
for (const part of parts) {
|
|
303
|
+
if (part.abort !== undefined)
|
|
304
|
+
out.abort = part.abort;
|
|
305
|
+
if (part.deny)
|
|
306
|
+
out.deny = part.deny;
|
|
307
|
+
if (part.confirm)
|
|
308
|
+
out.confirm = part.confirm;
|
|
309
|
+
if (part.mutate)
|
|
310
|
+
out.mutate = part.mutate;
|
|
311
|
+
if (part.inject)
|
|
312
|
+
out.inject.push(part.inject);
|
|
313
|
+
}
|
|
314
|
+
if (out.deny && out.confirm) {
|
|
315
|
+
warn(out.warnings, 'confirm_invalid', 'confirm', 'confirm ignored because deny is set'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
316
|
+
delete out.confirm;
|
|
317
|
+
}
|
|
318
|
+
return out;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Await each handler in order and apply its return on its own, so one handler's
|
|
322
|
+
* junk is that handler's warning and cannot erase another's affordance. Each
|
|
323
|
+
* handler gets its own shallow context; abort wins over any handler error.
|
|
324
|
+
*/
|
|
325
|
+
async function applyHandlers(handlers, ctx, apply, signal) {
|
|
326
|
+
const parts = [];
|
|
327
|
+
for (const handler of handlers) {
|
|
328
|
+
let raw;
|
|
329
|
+
try {
|
|
330
|
+
raw = await handler({ ...ctx });
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
throwIfAborted(signal);
|
|
334
|
+
throw err;
|
|
335
|
+
}
|
|
336
|
+
throwIfAborted(signal);
|
|
337
|
+
parts.push(applyStageResult({ ...apply, result: raw }));
|
|
338
|
+
}
|
|
339
|
+
return parts;
|
|
340
|
+
}
|
|
341
|
+
/** Stage events always emit, even with no handlers. */
|
|
342
|
+
export async function* runStage(args) {
|
|
343
|
+
const { stage, step, history, handlers, guardrails, injectAllowed, injectWouldExceedMaxSteps, mutable, host, signal, span, ...bag } = args;
|
|
344
|
+
throwIfAborted(signal);
|
|
345
|
+
// Stream stage events stay lean (no outputRaw/failure). Hosts read those on
|
|
346
|
+
// StageContext via onStage; tool failures also ride tool events.
|
|
347
|
+
yield stageEventFields(stage, {
|
|
348
|
+
callId: bag.callId,
|
|
349
|
+
toolName: bag.tool,
|
|
350
|
+
callNotStarted: bag.callNotStarted,
|
|
351
|
+
awaiting: bag.awaiting,
|
|
352
|
+
gate: bag.gate,
|
|
353
|
+
stop: bag.stop,
|
|
354
|
+
});
|
|
355
|
+
if (handlers.length === 0) {
|
|
356
|
+
span?.event('theorem.stage', { stage, affordance: [] });
|
|
357
|
+
return { warnings: [], inject: [] };
|
|
358
|
+
}
|
|
359
|
+
const ctx = { stage, step, history, host, ...bag };
|
|
360
|
+
const startedMs = span?.msSinceStart();
|
|
361
|
+
const applied = mergeApplied(await applyHandlers(handlers, ctx, { stage, injectAllowed, injectWouldExceedMaxSteps, mutable }, signal));
|
|
362
|
+
span?.event('theorem.stage', {
|
|
363
|
+
stage,
|
|
364
|
+
...(startedMs === undefined ? {} : { hook_ms: span.msSinceStart() - startedMs }),
|
|
365
|
+
affordance: STAGE_AFFORDANCES.filter((key) => appliedAffordance(applied, key)),
|
|
366
|
+
...(applied.warnings.length > 0 ? { warnings: applied.warnings.map((w) => w.code) } : {}),
|
|
367
|
+
});
|
|
368
|
+
if (applied.warnings.length > 0) {
|
|
369
|
+
yield {
|
|
370
|
+
...stageEventFields(stage, { callId: bag.callId, toolName: bag.tool }),
|
|
371
|
+
stageWarnings: applied.warnings,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
if (applied.inject.length === 0)
|
|
375
|
+
return applied;
|
|
376
|
+
const hits = [];
|
|
377
|
+
const detection = detectionForTrust(resolveGuardrailPolicy(guardrails), 'untrusted');
|
|
378
|
+
const sanitized = applied.inject.map((unit) => ({
|
|
379
|
+
...unit,
|
|
380
|
+
messages: sanitizeHistory(unit.messages, detection, hits),
|
|
381
|
+
}));
|
|
382
|
+
const redacted = guardrailFromHits('history', 'untrusted', hits, 'redact');
|
|
383
|
+
if (redacted?.guardrail)
|
|
384
|
+
span?.event('theorem.guardrail', guardrailAttributes(redacted.guardrail));
|
|
385
|
+
if (redacted)
|
|
386
|
+
yield redacted;
|
|
387
|
+
return { ...applied, inject: sanitized };
|
|
388
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type ContinueStopKind, type ProfileType } from './schema.js';
|
|
2
|
+
import type { TurnStop } from './turn-events.js';
|
|
3
|
+
export type { TurnStop };
|
|
4
|
+
/**
|
|
5
|
+
* Profile types whose continue turn sends the continue instruction. Image and
|
|
6
|
+
* speech continue by re-sending the host's request unchanged.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CONTINUE_INSTRUCTION_TYPES: readonly ProfileType[];
|
|
9
|
+
export declare const DEFAULT_ALLOW_CONTINUE: readonly ContinueStopKind[];
|
|
10
|
+
/** Hosts wait briefly, then continue once on their own. */
|
|
11
|
+
export declare const DEFAULT_AUTO_CONTINUE: readonly ContinueStopKind[];
|
|
12
|
+
/** Pause before the one-shot auto-continue so a flaky tunnel can settle. */
|
|
13
|
+
export declare const AUTO_CONTINUE_DELAY_MS = 1500;
|
|
14
|
+
export interface ProfileTurnResumptionSpec {
|
|
15
|
+
/**
|
|
16
|
+
* The host's UI policy for offering Continue: the kernel does not refuse a `continueFrom`
|
|
17
|
+
* outside it, since a continue is one more turn the host could send as plain text anyway.
|
|
18
|
+
* Omit → length / stream_incomplete / provider_error; `[]` = none.
|
|
19
|
+
*/
|
|
20
|
+
allowContinue?: ContinueStopKind[];
|
|
21
|
+
/**
|
|
22
|
+
* Omit → length / stream_incomplete; `[]` = none. The kernel does not loop: the host
|
|
23
|
+
* sends the `continueFrom` turn with `continuation`.
|
|
24
|
+
*/
|
|
25
|
+
autoContinue?: ContinueStopKind[];
|
|
26
|
+
/** Compared against `TurnRequest.continuation`. Omit → no count cap. */
|
|
27
|
+
maxContinues?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function isContinueStopKind(kind: string): kind is ContinueStopKind;
|
|
30
|
+
/**
|
|
31
|
+
* `allowSteering` is text / live only; image and speech omit it. Stop is not a profile knob:
|
|
32
|
+
* interfaces always project `canStop: true` because `TurnRequest.signal` is always wired.
|
|
33
|
+
*/
|
|
34
|
+
export interface ProfileTurnBehaviourSpec {
|
|
35
|
+
resumption?: ProfileTurnResumptionSpec;
|
|
36
|
+
/** Default true on text / live. Gates injects only; stage events still emit. */
|
|
37
|
+
allowSteering?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Image / speech turn behaviour: resumption only. A continue re-sends the
|
|
41
|
+
* host's request unchanged, so there is no continue instruction, and there is
|
|
42
|
+
* no mid-turn inject to steer.
|
|
43
|
+
*/
|
|
44
|
+
export interface MediaTurnBehaviourSpec {
|
|
45
|
+
resumption?: ProfileTurnResumptionSpec;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The stop a continue turn resumes. The partial reply is not carried here: a
|
|
49
|
+
* text continue reads it as the last assistant message in `input.history`, and
|
|
50
|
+
* an image or speech continue re-sends the original request.
|
|
51
|
+
*/
|
|
52
|
+
export interface TurnContinueFrom {
|
|
53
|
+
stop: TurnStop;
|
|
54
|
+
}
|
|
55
|
+
export declare function isResumeableStop(stop: TurnStop | undefined, allowContinue?: readonly ContinueStopKind[]): boolean;
|
|
56
|
+
export declare function stageAbortStop(abort: true | {
|
|
57
|
+
reason?: string;
|
|
58
|
+
}): TurnStop & {
|
|
59
|
+
kind: 'cancelled';
|
|
60
|
+
};
|
|
61
|
+
export declare function isUserCancelledStop(stop: TurnStop | undefined): boolean;
|
|
62
|
+
/** `policy` is the profile's `profileTurnResumption(profile)`. */
|
|
63
|
+
export declare function shouldAutoContinue(stop: TurnStop | undefined, policy?: Pick<ProfileTurnResumptionSpec, 'allowContinue' | 'autoContinue'>): boolean;
|
|
64
|
+
export declare function profileTurnResumption(profile: {
|
|
65
|
+
type: string;
|
|
66
|
+
turnBehaviour?: ProfileTurnBehaviourSpec;
|
|
67
|
+
}): ProfileTurnResumptionSpec | undefined;
|
|
68
|
+
/** Text-only, for the interface `allowSteering` projection; `profileAllowsInject` adds live. */
|
|
69
|
+
export declare function profileAllowsSteering(profile: {
|
|
70
|
+
type: string;
|
|
71
|
+
turnBehaviour?: ProfileTurnBehaviourSpec;
|
|
72
|
+
}): boolean;
|
|
73
|
+
/** Gates injects only, never stage emission. */
|
|
74
|
+
export declare function profileAllowsInject(profile: {
|
|
75
|
+
type: string;
|
|
76
|
+
turnBehaviour?: ProfileTurnBehaviourSpec;
|
|
77
|
+
}): boolean;
|
|
78
|
+
/** OpenAI-compatible normalized `finish_reason` (+ optional `native_finish_reason`). */
|
|
79
|
+
export declare function turnStopFromOpenAiFinishReason(finishReason: string | null | undefined, nativeFinishReason?: string | null): TurnStop;
|
|
80
|
+
/** Gemini Interactions terminal `status`. */
|
|
81
|
+
export declare function turnStopFromInteractionStatus(status: string | null | undefined): TurnStop;
|
|
82
|
+
/** `null` when `sawTerminal`, so the host keeps the provider's stop. */
|
|
83
|
+
export declare function turnStopFromClientStreamEnd(opts: {
|
|
84
|
+
abortedByUser: boolean;
|
|
85
|
+
sawTerminal: boolean;
|
|
86
|
+
hadPartial?: boolean;
|
|
87
|
+
}): TurnStop | null;
|
|
88
|
+
export declare class GenerationStopError extends Error {
|
|
89
|
+
readonly name = "GenerationStopError";
|
|
90
|
+
readonly stop: TurnStop;
|
|
91
|
+
constructor(stop: TurnStop, message?: string);
|
|
92
|
+
}
|
|
93
|
+
export declare function isGenerationStopError(err: unknown): err is GenerationStopError;
|