@theoremjs/agents 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +545 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +79 -0
- package/esm/mod.js +49 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +480 -0
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +241 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +26 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +67 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +5 -0
- package/esm/src/evals/attachments.js +55 -0
- package/esm/src/evals/breakdown.d.ts +30 -0
- package/esm/src/evals/breakdown.js +69 -0
- package/esm/src/evals/graders/answer.d.ts +16 -0
- package/esm/src/evals/graders/answer.js +134 -0
- package/esm/src/evals/graders/code.d.ts +40 -0
- package/esm/src/evals/graders/code.js +184 -0
- package/esm/src/evals/graders/judge.d.ts +24 -0
- package/esm/src/evals/graders/judge.js +367 -0
- package/esm/src/evals/graders/latency.d.ts +6 -0
- package/esm/src/evals/graders/latency.js +82 -0
- package/esm/src/evals/graders/live.d.ts +14 -0
- package/esm/src/evals/graders/live.js +42 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +91 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +19 -0
- package/esm/src/evals/graders/transcript.js +202 -0
- package/esm/src/evals/mod.d.ts +34 -0
- package/esm/src/evals/mod.js +22 -0
- package/esm/src/evals/record.d.ts +41 -0
- package/esm/src/evals/record.js +107 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +75 -0
- package/esm/src/evals/run.js +418 -0
- package/esm/src/evals/suite.d.ts +28 -0
- package/esm/src/evals/suite.js +97 -0
- package/esm/src/evals/summary.d.ts +35 -0
- package/esm/src/evals/summary.js +31 -0
- package/esm/src/evals/trial.d.ts +14 -0
- package/esm/src/evals/trial.js +135 -0
- package/esm/src/evals/types.d.ts +169 -0
- package/esm/src/evals/types.js +113 -0
- package/esm/src/evals/verdict.d.ts +23 -0
- package/esm/src/evals/verdict.js +48 -0
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +22 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +146 -0
- package/esm/src/guardrails/canary.js +974 -0
- package/esm/src/guardrails/compile-egress.d.ts +12 -0
- package/esm/src/guardrails/compile-egress.js +12 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +24 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +305 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +199 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +5 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +120 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +15 -0
- package/esm/src/guardrails/corpus/live-attacks.js +229 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +36 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +12 -0
- package/esm/src/guardrails/egress-automata.js +25582 -0
- package/esm/src/guardrails/egress-compiler.d.ts +55 -0
- package/esm/src/guardrails/egress-compiler.js +431 -0
- package/esm/src/guardrails/egress-patterns.d.ts +26 -0
- package/esm/src/guardrails/egress-patterns.js +36 -0
- package/esm/src/guardrails/egress-stream.d.ts +123 -0
- package/esm/src/guardrails/egress-stream.js +774 -0
- package/esm/src/guardrails/egress-urls.d.ts +86 -0
- package/esm/src/guardrails/egress-urls.js +909 -0
- package/esm/src/guardrails/egress.d.ts +46 -0
- package/esm/src/guardrails/egress.js +124 -0
- package/esm/src/guardrails/error.d.ts +31 -0
- package/esm/src/guardrails/error.js +96 -0
- package/esm/src/guardrails/event-schemas.d.ts +100 -0
- package/esm/src/guardrails/event-schemas.js +48 -0
- package/esm/src/guardrails/events.d.ts +13 -0
- package/esm/src/guardrails/events.js +45 -0
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +14 -0
- package/esm/src/guardrails/hits.js +30 -0
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +20 -0
- package/esm/src/guardrails/injection-patterns.js +126 -0
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +30 -0
- package/esm/src/guardrails/injection.js +460 -0
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +874 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +55 -0
- package/esm/src/guardrails/live-outbound-gate.js +298 -0
- package/esm/src/guardrails/mod.d.ts +54 -0
- package/esm/src/guardrails/mod.js +34 -0
- package/esm/src/guardrails/network.d.ts +46 -0
- package/esm/src/guardrails/network.js +330 -0
- package/esm/src/guardrails/normalize.d.ts +20 -0
- package/esm/src/guardrails/normalize.js +165 -0
- package/esm/src/guardrails/policy.d.ts +4 -0
- package/esm/src/guardrails/policy.js +21 -0
- package/esm/src/guardrails/progressive-yield.d.ts +110 -0
- package/esm/src/guardrails/progressive-yield.js +281 -0
- package/esm/src/guardrails/prompt-echo.d.ts +40 -0
- package/esm/src/guardrails/prompt-echo.js +306 -0
- package/esm/src/guardrails/quota.d.ts +21 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +47 -0
- package/esm/src/guardrails/rules.js +47 -0
- package/esm/src/guardrails/sanitize.d.ts +40 -0
- package/esm/src/guardrails/sanitize.js +160 -0
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +22 -0
- package/esm/src/guardrails/sensitive.js +234 -0
- package/esm/src/guardrails/serialize.d.ts +15 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +11 -0
- package/esm/src/guardrails/testing.js +10 -0
- package/esm/src/guardrails/theorem-error.d.ts +21 -0
- package/esm/src/guardrails/theorem-error.js +54 -0
- package/esm/src/guardrails/thought-guard.d.ts +76 -0
- package/esm/src/guardrails/thought-guard.js +664 -0
- package/esm/src/guardrails/tool-directives.d.ts +38 -0
- package/esm/src/guardrails/tool-directives.js +195 -0
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +92 -0
- package/esm/src/guardrails/tool-result.js +272 -0
- package/esm/src/guardrails/types.d.ts +250 -0
- package/esm/src/guardrails/types.js +58 -0
- package/esm/src/host/client-turn.d.ts +36 -0
- package/esm/src/host/client-turn.js +80 -0
- package/esm/src/host/mint-trace.d.ts +29 -0
- package/esm/src/host/mint-trace.js +60 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +27 -0
- package/esm/src/host/reply.d.ts +13 -0
- package/esm/src/host/reply.js +41 -0
- package/esm/src/interface/blocks.d.ts +11 -0
- package/esm/src/interface/blocks.js +283 -0
- package/esm/src/interface/composer-actions.d.ts +24 -0
- package/esm/src/interface/composer-actions.js +33 -0
- package/esm/src/interface/draft.d.ts +20 -0
- package/esm/src/interface/draft.js +39 -0
- package/esm/src/interface/from-profile.d.ts +24 -0
- package/esm/src/interface/from-profile.js +179 -0
- package/esm/src/interface/history.d.ts +46 -0
- package/esm/src/interface/history.js +278 -0
- package/esm/src/interface/inputs.d.ts +11 -0
- package/esm/src/interface/inputs.js +67 -0
- package/esm/src/interface/mod.d.ts +33 -0
- package/esm/src/interface/mod.js +22 -0
- package/esm/src/interface/models.d.ts +26 -0
- package/esm/src/interface/models.js +50 -0
- package/esm/src/interface/pending.d.ts +57 -0
- package/esm/src/interface/pending.js +152 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +237 -0
- package/esm/src/interface/session.d.ts +71 -0
- package/esm/src/interface/session.js +128 -0
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +32 -0
- package/esm/src/interface/tool-calls.js +127 -0
- package/esm/src/interface/tool-invoke.d.ts +6 -0
- package/esm/src/interface/tool-invoke.js +22 -0
- package/esm/src/interface/tool-media.d.ts +11 -0
- package/esm/src/interface/tool-media.js +113 -0
- package/esm/src/interface/types.d.ts +278 -0
- package/esm/src/interface/types.js +5 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +56 -0
- package/esm/src/kernel/auth/crypto.js +163 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +18 -0
- package/esm/src/kernel/auth/oauth.js +439 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +152 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +72 -0
- package/esm/src/kernel/default-scope.js +121 -0
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +71 -0
- package/esm/src/kernel/engine/compaction.js +203 -0
- package/esm/src/kernel/engine/decision.d.ts +43 -0
- package/esm/src/kernel/engine/decision.js +439 -0
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +19 -0
- package/esm/src/kernel/engine/live-inbound.js +44 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +15 -0
- package/esm/src/kernel/engine/live-ingress.js +42 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +508 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +29 -0
- package/esm/src/kernel/engine/runner/mod.js +625 -0
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +35 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +179 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +41 -0
- package/esm/src/kernel/engine/runner/state.d.ts +97 -0
- package/esm/src/kernel/engine/runner/state.js +50 -0
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +519 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +71 -0
- package/esm/src/kernel/engine/runner/stream.js +376 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +148 -0
- package/esm/src/kernel/engine/session/mod.d.ts +33 -0
- package/esm/src/kernel/engine/session/mod.js +1182 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +500 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +23 -0
- package/esm/src/kernel/engine/token-estimate.js +38 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +132 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +119 -0
- package/esm/src/kernel/engine/turn-trace.js +855 -0
- package/esm/src/kernel/engine/usage.d.ts +36 -0
- package/esm/src/kernel/engine/usage.js +151 -0
- package/esm/src/kernel/interaction-parts.d.ts +13 -0
- package/esm/src/kernel/interaction-parts.js +40 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +74 -0
- package/esm/src/kernel/mod.js +45 -0
- package/esm/src/kernel/profile-graph.d.ts +145 -0
- package/esm/src/kernel/profile-graph.js +158 -0
- package/esm/src/kernel/profile-presence.d.ts +18 -0
- package/esm/src/kernel/profile-presence.js +158 -0
- package/esm/src/kernel/profile-scope.d.ts +40 -0
- package/esm/src/kernel/profile-scope.js +274 -0
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +46 -0
- package/esm/src/kernel/registry/attachments.js +220 -0
- package/esm/src/kernel/registry/catalog.d.ts +25 -0
- package/esm/src/kernel/registry/catalog.js +85 -0
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +12 -0
- package/esm/src/kernel/registry/ingress.js +179 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +15 -0
- package/esm/src/kernel/registry/kernel-registry.js +15 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +10 -0
- package/esm/src/kernel/registry/profiles.d.ts +116 -0
- package/esm/src/kernel/registry/profiles.js +773 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +34 -0
- package/esm/src/kernel/registry/resolve.d.ts +17 -0
- package/esm/src/kernel/registry/resolve.js +238 -0
- package/esm/src/kernel/registry/schemas.d.ts +12 -0
- package/esm/src/kernel/registry/schemas.js +27 -0
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +32 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +14 -0
- package/esm/src/kernel/registry/vault.js +1 -0
- package/esm/src/kernel/schema.d.ts +226 -0
- package/esm/src/kernel/schema.js +895 -0
- package/esm/src/kernel/scope.d.ts +29 -0
- package/esm/src/kernel/scope.js +45 -0
- package/esm/src/kernel/stages.d.ts +176 -0
- package/esm/src/kernel/stages.js +431 -0
- package/esm/src/kernel/stop.d.ts +116 -0
- package/esm/src/kernel/stop.js +137 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +22 -0
- package/esm/src/kernel/tools/activity-label.js +435 -0
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +66 -0
- package/esm/src/kernel/tools/events.js +184 -0
- package/esm/src/kernel/tools/execute.d.ts +100 -0
- package/esm/src/kernel/tools/execute.js +1173 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +60 -0
- package/esm/src/kernel/tools/gate-answer.js +65 -0
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +17 -0
- package/esm/src/kernel/tools/harness.js +43 -0
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +32 -0
- package/esm/src/kernel/tools/invoke.js +282 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +23 -0
- package/esm/src/kernel/tools/mcp-sessions.js +69 -0
- package/esm/src/kernel/tools/mod.d.ts +10 -0
- package/esm/src/kernel/tools/mod.js +7 -0
- package/esm/src/kernel/tools/model-text.d.ts +16 -0
- package/esm/src/kernel/tools/model-text.js +31 -0
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +15 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +11 -0
- package/esm/src/kernel/tools/project.js +55 -0
- package/esm/src/kernel/tools/registry.d.ts +27 -0
- package/esm/src/kernel/tools/registry.js +143 -0
- package/esm/src/kernel/tools/remote.d.ts +144 -0
- package/esm/src/kernel/tools/remote.js +1125 -0
- package/esm/src/kernel/tools/resolve.d.ts +31 -0
- package/esm/src/kernel/tools/resolve.js +267 -0
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +95 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +19 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +116 -0
- package/esm/src/kernel/tools/stage-run.js +198 -0
- package/esm/src/kernel/tools/types.d.ts +497 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +776 -0
- package/esm/src/kernel/turn-events.js +543 -0
- package/esm/src/kernel/types.d.ts +1025 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +4 -0
- package/esm/src/kernel/util/base64.js +15 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +2 -0
- package/esm/src/kernel/util/record.js +4 -0
- package/esm/src/observability/destinations.d.ts +14 -0
- package/esm/src/observability/destinations.js +43 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +110 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +71 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +30 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +17 -0
- package/esm/src/observability/policy.js +73 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +64 -0
- package/esm/src/observability/spans.d.ts +22 -0
- package/esm/src/observability/spans.js +72 -0
- package/esm/src/observability/trace-catalog.d.ts +128 -0
- package/esm/src/observability/trace-catalog.js +906 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +228 -0
- package/esm/src/observability/trace-schema.d.ts +57 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +14 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +98 -0
- package/esm/src/observability/trace-span.js +201 -0
- package/esm/src/observability/trace.d.ts +13 -0
- package/esm/src/observability/trace.js +37 -0
- package/esm/src/observability/types.d.ts +109 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +9 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +13 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +119 -0
- package/esm/src/presets/google.js +197 -0
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +11 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +26 -0
- package/esm/src/presets/openrouter.js +31 -0
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +105 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +27 -0
- package/esm/src/providers/google/interactions/framing.js +304 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +23 -0
- package/esm/src/providers/google/interactions/stream.js +230 -0
- package/esm/src/providers/google/live/framing.d.ts +61 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/stream.d.ts +13 -0
- package/esm/src/providers/google/live/stream.js +57 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +4 -0
- package/esm/src/providers/google/urls.js +4 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +32 -0
- package/esm/src/providers/mod.js +23 -0
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +15 -0
- package/esm/src/providers/openrouter/image.js +34 -0
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/retry.d.ts +17 -0
- package/esm/src/providers/shared/retry.js +90 -0
- package/esm/src/providers/shared/sse.d.ts +6 -0
- package/esm/src/providers/shared/sse.js +93 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +24 -0
- package/esm/src/providers/shared/tool-args.js +88 -0
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +51 -0
- package/esm/src/providers/types.js +2 -0
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +46 -0
- package/esm/src/surface/formats.js +178 -0
- package/esm/src/surface/mod.d.ts +16 -0
- package/esm/src/surface/mod.js +12 -0
- package/esm/src/surface/runtime.d.ts +44 -0
- package/esm/src/surface/runtime.js +441 -0
- package/esm/src/surface/tools.d.ts +9 -0
- package/esm/src/surface/tools.js +62 -0
- package/esm/src/surface/types.d.ts +110 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +100 -4
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { keptReply } from '../kernel/turn-events.js';
|
|
2
|
+
import { partialJsonObject } from '../kernel/util/partial-json.js';
|
|
3
|
+
import { applyToolDraft, applyToolEvent } from './tool-calls.js';
|
|
4
|
+
import { collectPromotedMediaFromToolOutput } from './tool-media.js';
|
|
5
|
+
let turnBlockCounter = 0;
|
|
6
|
+
/**
|
|
7
|
+
* User block ids are random: a counter restarts wherever this module loads
|
|
8
|
+
* again (a hot reload, a second bundled copy) and would reuse an id already on
|
|
9
|
+
* screen. Turn block ids count from each fold so streaming refolds keep keys.
|
|
10
|
+
*/
|
|
11
|
+
function nextBlockId(prefix) {
|
|
12
|
+
if (prefix === 'user')
|
|
13
|
+
return `user-${globalThis.crypto.randomUUID()}`;
|
|
14
|
+
turnBlockCounter += 1;
|
|
15
|
+
return `${prefix}-${String(turnBlockCounter)}`;
|
|
16
|
+
}
|
|
17
|
+
/** Restarts block id numbering at zero. */
|
|
18
|
+
function resetBlockIds() {
|
|
19
|
+
turnBlockCounter = 0;
|
|
20
|
+
}
|
|
21
|
+
function isAppendableTextBlock(block, kind) {
|
|
22
|
+
return block?.kind === kind;
|
|
23
|
+
}
|
|
24
|
+
function appendText(blocks, kind, text, idPrefix) {
|
|
25
|
+
const last = blocks.at(-1);
|
|
26
|
+
if (isAppendableTextBlock(last, kind)) {
|
|
27
|
+
last.text += text;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
blocks.push({
|
|
31
|
+
id: nextBlockId(idPrefix),
|
|
32
|
+
kind,
|
|
33
|
+
text,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A decision made while text streams goes ahead of that text's block, so the block stays last and
|
|
38
|
+
* the rest of the text joins it.
|
|
39
|
+
*/
|
|
40
|
+
function addGuardrailBlock(blocks, block) {
|
|
41
|
+
const last = blocks.at(-1);
|
|
42
|
+
const streaming = last?.kind === 'text' || last?.kind === 'thought';
|
|
43
|
+
blocks.splice(streaming ? blocks.length - 1 : blocks.length, 0, block);
|
|
44
|
+
}
|
|
45
|
+
function findToolBlock(blocks, id) {
|
|
46
|
+
return blocks.find((block) => block.kind === 'tool' && block.id === id);
|
|
47
|
+
}
|
|
48
|
+
/** invariant: Issued operation IDs separate action blocks; historical events use callId. */
|
|
49
|
+
function upsertToolBlock(blocks, tool) {
|
|
50
|
+
const id = `tool-${tool.operationId ?? tool.callId}`;
|
|
51
|
+
const existing = findToolBlock(blocks, id);
|
|
52
|
+
const call = applyToolEvent(existing?.tool, tool);
|
|
53
|
+
if (existing) {
|
|
54
|
+
existing.tool = call;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// why: The call the model was drafting arrives whole where its draft stood.
|
|
58
|
+
const draft = tool.phase === undefined ? findToolBlock(blocks, `tool-${tool.callId}`) : undefined;
|
|
59
|
+
if (draft?.tool.draft !== undefined) {
|
|
60
|
+
draft.id = id;
|
|
61
|
+
draft.tool = call;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
blocks.push({ id, kind: 'tool', tool: call });
|
|
65
|
+
}
|
|
66
|
+
/** The call the model is still writing, as far as its draft has come. */
|
|
67
|
+
function upsertToolDraft(blocks, draft) {
|
|
68
|
+
const id = `tool-${draft.callId}`;
|
|
69
|
+
const existing = findToolBlock(blocks, id);
|
|
70
|
+
const call = applyToolDraft(existing?.tool, draft);
|
|
71
|
+
if (existing) {
|
|
72
|
+
existing.tool = call;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
blocks.push({ id, kind: 'tool', tool: call });
|
|
76
|
+
}
|
|
77
|
+
/** The structured reply the model is still writing, if one is showing. */
|
|
78
|
+
function openStructuredDraft(blocks) {
|
|
79
|
+
return blocks.findLast((block) => block.kind === 'structured' && block.draft !== undefined);
|
|
80
|
+
}
|
|
81
|
+
/** The structured reply the model is still writing, as far as its draft has come. */
|
|
82
|
+
function upsertStructuredDraft(blocks, text, idPrefix) {
|
|
83
|
+
const open = openStructuredDraft(blocks);
|
|
84
|
+
const draft = (open?.draft ?? '') + text;
|
|
85
|
+
if (open) {
|
|
86
|
+
open.draft = draft;
|
|
87
|
+
open.value = partialJsonObject(draft);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
blocks.push({
|
|
91
|
+
id: nextBlockId(idPrefix),
|
|
92
|
+
kind: 'structured',
|
|
93
|
+
value: partialJsonObject(draft),
|
|
94
|
+
draft,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** The structured reply, in its draft's place when one is showing. */
|
|
98
|
+
function settleStructured(blocks, value, idPrefix) {
|
|
99
|
+
const open = openStructuredDraft(blocks);
|
|
100
|
+
if (open) {
|
|
101
|
+
open.value = value;
|
|
102
|
+
delete open.draft;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
blocks.push({ id: nextBlockId(idPrefix), kind: 'structured', value });
|
|
106
|
+
}
|
|
107
|
+
/** Same source: one place, or one link. */
|
|
108
|
+
function sameSource(a, b) {
|
|
109
|
+
if (a.type !== b.type)
|
|
110
|
+
return false;
|
|
111
|
+
if (a.placeId && b.placeId)
|
|
112
|
+
return a.placeId === b.placeId;
|
|
113
|
+
return a.uri === b.uri;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* One sources row per citer: the provider's grounding (no `callId`) or one
|
|
117
|
+
* tool call. A stream cites the same places more than once (the search result
|
|
118
|
+
* lists them, then the answer's annotations cite them), so later citations
|
|
119
|
+
* fold into the row with each source listed once.
|
|
120
|
+
*/
|
|
121
|
+
function foldCitation(blocks, event, idPrefix) {
|
|
122
|
+
const existing = blocks.find((block) => block.kind === 'citation' && block.callId === event.callId);
|
|
123
|
+
const sources = existing ? [...existing.sources] : [];
|
|
124
|
+
for (const source of event.sources) {
|
|
125
|
+
if (!sources.some((seen) => sameSource(seen, source)))
|
|
126
|
+
sources.push(source);
|
|
127
|
+
}
|
|
128
|
+
if (existing) {
|
|
129
|
+
existing.sources = sources;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
blocks.push({
|
|
133
|
+
id: nextBlockId(idPrefix),
|
|
134
|
+
kind: 'citation',
|
|
135
|
+
sources,
|
|
136
|
+
...(event.callId !== undefined ? { callId: event.callId } : {}),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function appendPromotedToolMedia(blocks, tool, idPrefix, seenUrls) {
|
|
140
|
+
if (tool.phase !== 'complete' || tool.output === undefined)
|
|
141
|
+
return;
|
|
142
|
+
for (const media of collectPromotedMediaFromToolOutput(tool.output)) {
|
|
143
|
+
if (seenUrls.has(media.url))
|
|
144
|
+
continue;
|
|
145
|
+
seenUrls.add(media.url);
|
|
146
|
+
blocks.push({
|
|
147
|
+
id: nextBlockId(idPrefix),
|
|
148
|
+
kind: 'media',
|
|
149
|
+
mimeType: media.mimeType,
|
|
150
|
+
url: media.url,
|
|
151
|
+
...(media.previewUrl ? { previewUrl: media.previewUrl } : {}),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** Turns a user draft into transcript blocks: a `user-text` block for the trimmed text, then one block per attachment and per voice clip. */
|
|
156
|
+
function buildUserTurnBlocks(draft, idPrefix = 'user') {
|
|
157
|
+
const blocks = [];
|
|
158
|
+
const text = draft.text?.trim();
|
|
159
|
+
if (text) {
|
|
160
|
+
blocks.push({
|
|
161
|
+
id: nextBlockId(idPrefix),
|
|
162
|
+
kind: 'user-text',
|
|
163
|
+
text,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
for (const file of draft.attachments ?? []) {
|
|
167
|
+
blocks.push({
|
|
168
|
+
id: nextBlockId(idPrefix),
|
|
169
|
+
kind: 'user-attachment',
|
|
170
|
+
name: file.name,
|
|
171
|
+
mimeType: file.mimeType,
|
|
172
|
+
sizeBytes: file.sizeBytes,
|
|
173
|
+
...(file.data !== undefined ? { data: file.data } : {}),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
for (const file of draft.voice ?? []) {
|
|
177
|
+
blocks.push({
|
|
178
|
+
id: nextBlockId(idPrefix),
|
|
179
|
+
kind: 'user-voice',
|
|
180
|
+
name: file.name,
|
|
181
|
+
mimeType: file.mimeType,
|
|
182
|
+
sizeBytes: file.sizeBytes,
|
|
183
|
+
...(file.data !== undefined ? { data: file.data } : {}),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return blocks;
|
|
187
|
+
}
|
|
188
|
+
/** Resets only the turn id sequence, so streaming refolds keep stable `turn-*` keys. */
|
|
189
|
+
function foldTurnEvents(events, options = {}) {
|
|
190
|
+
const idPrefix = options.idPrefix ?? 'turn';
|
|
191
|
+
const showThoughts = options.showThoughts ?? true;
|
|
192
|
+
turnBlockCounter = 0;
|
|
193
|
+
const blocks = [];
|
|
194
|
+
const promotedMediaUrls = new Set();
|
|
195
|
+
for (const event of keptReply(events)) {
|
|
196
|
+
switch (event.type) {
|
|
197
|
+
case 'thought':
|
|
198
|
+
if (showThoughts && event.text) {
|
|
199
|
+
appendText(blocks, 'thought', event.text, idPrefix);
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
case 'text':
|
|
203
|
+
if (event.text) {
|
|
204
|
+
appendText(blocks, 'text', event.text, idPrefix);
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
case 'tool_draft':
|
|
208
|
+
upsertToolDraft(blocks, event);
|
|
209
|
+
break;
|
|
210
|
+
case 'tool':
|
|
211
|
+
upsertToolBlock(blocks, event.tool);
|
|
212
|
+
appendPromotedToolMedia(blocks, event.tool, idPrefix, promotedMediaUrls);
|
|
213
|
+
break;
|
|
214
|
+
case 'structured_draft':
|
|
215
|
+
upsertStructuredDraft(blocks, event.text, idPrefix);
|
|
216
|
+
break;
|
|
217
|
+
case 'structured':
|
|
218
|
+
settleStructured(blocks, event.structured, idPrefix);
|
|
219
|
+
break;
|
|
220
|
+
case 'media':
|
|
221
|
+
if (event.media) {
|
|
222
|
+
blocks.push({
|
|
223
|
+
id: nextBlockId(idPrefix),
|
|
224
|
+
kind: 'media',
|
|
225
|
+
mimeType: event.media.mimeType,
|
|
226
|
+
data: event.media.data,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
case 'grounding':
|
|
231
|
+
blocks.push({
|
|
232
|
+
id: nextBlockId(idPrefix),
|
|
233
|
+
kind: 'grounding',
|
|
234
|
+
grounding: event.grounding,
|
|
235
|
+
});
|
|
236
|
+
break;
|
|
237
|
+
case 'citation':
|
|
238
|
+
foldCitation(blocks, event, idPrefix);
|
|
239
|
+
break;
|
|
240
|
+
case 'evidence':
|
|
241
|
+
blocks.push({
|
|
242
|
+
id: nextBlockId(idPrefix),
|
|
243
|
+
kind: 'evidence',
|
|
244
|
+
evidence: event.evidence,
|
|
245
|
+
});
|
|
246
|
+
break;
|
|
247
|
+
case 'guardrail':
|
|
248
|
+
addGuardrailBlock(blocks, {
|
|
249
|
+
id: nextBlockId(idPrefix),
|
|
250
|
+
kind: 'guardrail',
|
|
251
|
+
guardrail: event.guardrail,
|
|
252
|
+
});
|
|
253
|
+
break;
|
|
254
|
+
case 'error':
|
|
255
|
+
if (event.error) {
|
|
256
|
+
blocks.push({
|
|
257
|
+
id: nextBlockId(idPrefix),
|
|
258
|
+
kind: 'error',
|
|
259
|
+
message: event.error,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
case 'done':
|
|
264
|
+
blocks.push({
|
|
265
|
+
id: nextBlockId(idPrefix),
|
|
266
|
+
kind: 'turn-done',
|
|
267
|
+
stop: event.stop,
|
|
268
|
+
tokens: event.tokens,
|
|
269
|
+
interactionId: event.interactionId,
|
|
270
|
+
compaction: event.compaction !== undefined,
|
|
271
|
+
});
|
|
272
|
+
break;
|
|
273
|
+
default:
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return blocks;
|
|
278
|
+
}
|
|
279
|
+
/** One conversation turn as blocks: the user draft's blocks followed by the assistant events folded into blocks. */
|
|
280
|
+
function foldConversationTurn(draft, assistantEvents, options = {}) {
|
|
281
|
+
return [...buildUserTurnBlocks(draft, 'user'), ...foldTurnEvents(assistantEvents, options)];
|
|
282
|
+
}
|
|
283
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ComposerPendingKind } from './pending.js';
|
|
2
|
+
/** Where a run is: idle, streaming, or held at a tool gate. */
|
|
3
|
+
export type ComposerRunPhase = 'idle' | 'streaming' | 'gated';
|
|
4
|
+
/** Primary button / Enter target. */
|
|
5
|
+
export type ComposerPrimaryAction = 'send' | 'stop' | 'queue' | 'none';
|
|
6
|
+
/**
|
|
7
|
+
* Split-menu / long-press actions. `send_now` is abort+send while streaming, or
|
|
8
|
+
* abandon the tool gate (no model continue) + send while gated; not a pending kind.
|
|
9
|
+
*/
|
|
10
|
+
export type ComposerMenuAction = ComposerPendingKind | 'send_now';
|
|
11
|
+
/** What decides the composer's actions: the run phase, whether there is something to send, and whether steering and stop are allowed. */
|
|
12
|
+
export type ComposerActionContext = {
|
|
13
|
+
phase: ComposerRunPhase;
|
|
14
|
+
hasPayload: boolean;
|
|
15
|
+
/** From `ProfileInterface.allowSteering` (text only; false elsewhere). */
|
|
16
|
+
allowSteering: boolean;
|
|
17
|
+
/** Composer profiles always project `canStop: true`. */
|
|
18
|
+
canStop?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** The action of the primary button and Enter: `send` when idle with a draft, `queue` mid-run with one, `stop` while streaming with none (when stop is allowed), else `none`. */
|
|
21
|
+
declare function resolveComposerPrimary(ctx: ComposerActionContext): ComposerPrimaryAction;
|
|
22
|
+
/** The split menu's actions: none without a draft; `stash` when idle; mid-run `queue`, `steer` while streaming when steering is allowed, `send_now` and `stash`. */
|
|
23
|
+
declare function resolveComposerMenuActions(ctx: ComposerActionContext): ComposerMenuAction[];
|
|
24
|
+
export { resolveComposerMenuActions, resolveComposerPrimary };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The action of the primary button and Enter: `send` when idle with a draft, `queue` mid-run with one, `stop` while streaming with none (when stop is allowed), else `none`. */
|
|
2
|
+
function resolveComposerPrimary(ctx) {
|
|
3
|
+
const canStop = ctx.canStop !== false;
|
|
4
|
+
if (ctx.phase === 'idle') {
|
|
5
|
+
return ctx.hasPayload ? 'send' : 'none';
|
|
6
|
+
}
|
|
7
|
+
if (ctx.phase === 'streaming') {
|
|
8
|
+
if (!ctx.hasPayload)
|
|
9
|
+
return canStop ? 'stop' : 'none';
|
|
10
|
+
return 'queue';
|
|
11
|
+
}
|
|
12
|
+
// why: Gated is still the same run: queue only, no stream to stop.
|
|
13
|
+
return ctx.hasPayload ? 'queue' : 'none';
|
|
14
|
+
}
|
|
15
|
+
/** The split menu's actions: none without a draft; `stash` when idle; mid-run `queue`, `steer` while streaming when steering is allowed, `send_now` and `stash`. */
|
|
16
|
+
function resolveComposerMenuActions(ctx) {
|
|
17
|
+
if (!ctx.hasPayload)
|
|
18
|
+
return [];
|
|
19
|
+
if (ctx.phase === 'idle') {
|
|
20
|
+
return ['stash'];
|
|
21
|
+
}
|
|
22
|
+
if (ctx.phase === 'streaming') {
|
|
23
|
+
const actions = ['queue'];
|
|
24
|
+
if (ctx.allowSteering)
|
|
25
|
+
actions.push('steer');
|
|
26
|
+
actions.push('send_now', 'stash');
|
|
27
|
+
return actions;
|
|
28
|
+
}
|
|
29
|
+
// why: gated: no steer (not an inject stage); send_now = host ends wait + send
|
|
30
|
+
return ['queue', 'send_now', 'stash'];
|
|
31
|
+
}
|
|
32
|
+
// invariant: Emits semantic action keys only: English labels live in the rendering layer or the host UI.
|
|
33
|
+
export { resolveComposerMenuActions, resolveComposerPrimary };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AttachmentValidationIssue } from '../kernel/types.js';
|
|
2
|
+
import type { ProfileGuardrailsView, ProfileInputsInterface, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads a draft's text at the `user` boundary with Theorem's patterns, as the kernel will: a
|
|
5
|
+
* match set to redact shows as its placeholder. A match set to block leaves the draft as typed;
|
|
6
|
+
* the kernel refuses the turn. A match of the host's own patterns is the kernel's to find.
|
|
7
|
+
*/
|
|
8
|
+
declare function sanitizeUserDraft(draft: UserTurnDraft, guardrails?: ProfileGuardrailsView): UserTurnDraft;
|
|
9
|
+
/** The result of preparing a user turn: the sanitized draft with its transcript blocks, or the attachment issues that rejected it. */
|
|
10
|
+
export type PrepareUserTurnResult = {
|
|
11
|
+
ok: true;
|
|
12
|
+
draft: UserTurnDraft;
|
|
13
|
+
blocks: TranscriptBlock[];
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
issues: AttachmentValidationIssue[];
|
|
17
|
+
};
|
|
18
|
+
/** Call before appending to the thread and before `runTurn` ingress. */
|
|
19
|
+
declare function prepareUserTurn(inputs: ProfileInputsInterface, draft: UserTurnDraft, guardrails?: ProfileGuardrailsView): PrepareUserTurnResult;
|
|
20
|
+
export { prepareUserTurn, sanitizeUserDraft };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { detectAt } from '../guardrails/detect-at.js';
|
|
2
|
+
import { DETECT_DEFAULTS } from '../guardrails/detectors.js';
|
|
3
|
+
import { buildUserTurnBlocks } from './blocks.js';
|
|
4
|
+
import { validateProfileInputs } from './inputs.js';
|
|
5
|
+
/** The view's matrix with Theorem's patterns off where the profile turned them off. The host's own patterns stay with the kernel. */
|
|
6
|
+
function detectOf(guardrails) {
|
|
7
|
+
if (!guardrails)
|
|
8
|
+
return DETECT_DEFAULTS;
|
|
9
|
+
const { detect, patterns } = guardrails;
|
|
10
|
+
if (!patterns)
|
|
11
|
+
return detect;
|
|
12
|
+
const sources = Object.fromEntries(Object.entries(patterns).map(([detector, { theorem }]) => [
|
|
13
|
+
detector,
|
|
14
|
+
{ theorem, matchers: [] },
|
|
15
|
+
]));
|
|
16
|
+
return { ...detect, sources };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads a draft's text at the `user` boundary with Theorem's patterns, as the kernel will: a
|
|
20
|
+
* match set to redact shows as its placeholder. A match set to block leaves the draft as typed;
|
|
21
|
+
* the kernel refuses the turn. A match of the host's own patterns is the kernel's to find.
|
|
22
|
+
*/
|
|
23
|
+
function sanitizeUserDraft(draft, guardrails) {
|
|
24
|
+
if (draft.text === undefined) {
|
|
25
|
+
return draft;
|
|
26
|
+
}
|
|
27
|
+
const detected = detectAt(draft.text, 'user', detectOf(guardrails));
|
|
28
|
+
return { ...draft, text: detected.text ?? draft.text };
|
|
29
|
+
}
|
|
30
|
+
/** Call before appending to the thread and before `runTurn` ingress. */
|
|
31
|
+
function prepareUserTurn(inputs, draft, guardrails) {
|
|
32
|
+
const validation = validateProfileInputs(inputs, draft);
|
|
33
|
+
if (!validation.ok) {
|
|
34
|
+
return { ok: false, issues: validation.issues };
|
|
35
|
+
}
|
|
36
|
+
const safe = sanitizeUserDraft(draft, guardrails);
|
|
37
|
+
return { ok: true, draft: safe, blocks: buildUserTurnBlocks(safe) };
|
|
38
|
+
}
|
|
39
|
+
export { prepareUserTurn, sanitizeUserDraft };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ToolRegistry } from '../kernel/tools/registry.js';
|
|
2
|
+
import type { LiveProfile, Profile, ProjectedProfile } from '../kernel/types.js';
|
|
3
|
+
import type { ComposerProfileInterface, LiveProfileInterface, ProfileInterface } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The interface for `input`, its tools resolved from `tools`: the registry of
|
|
6
|
+
* the scope that runs the profile.
|
|
7
|
+
*/
|
|
8
|
+
declare function interfaceFromProfile(input: LiveProfile, tools: ToolRegistry): LiveProfileInterface;
|
|
9
|
+
/** The interface for a profile that is not live. */
|
|
10
|
+
declare function interfaceFromProfile(input: Exclude<Profile, LiveProfile>, tools: ToolRegistry): ComposerProfileInterface;
|
|
11
|
+
/** The interface for any profile. */
|
|
12
|
+
declare function interfaceFromProfile(input: Profile, tools: ToolRegistry): ProfileInterface;
|
|
13
|
+
/** The interface for a profile the host has already projected, without resolving its tools again. */
|
|
14
|
+
declare function interfaceFromProjected(projected: ProjectedProfile): ProfileInterface;
|
|
15
|
+
/**
|
|
16
|
+
* The interface a browser may read: {@linkcode interfaceFromProfile} without `identity.system` and
|
|
17
|
+
* `systemByRole`, which stay on the server. Labels, turn behaviour, guardrails, and observability are kept.
|
|
18
|
+
*/
|
|
19
|
+
declare function clientProfileInterface(input: LiveProfile, tools: ToolRegistry): LiveProfileInterface;
|
|
20
|
+
/** The client-safe interface for a profile that is not live. */
|
|
21
|
+
declare function clientProfileInterface(input: Exclude<Profile, LiveProfile>, tools: ToolRegistry): ComposerProfileInterface;
|
|
22
|
+
/** The client-safe interface for any profile. */
|
|
23
|
+
declare function clientProfileInterface(input: Profile, tools: ToolRegistry): ProfileInterface;
|
|
24
|
+
export { clientProfileInterface, interfaceFromProfile, interfaceFromProjected };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// why: `profileInterfaceSchema` keeps only the JSON it names, so host functions never reach the view.
|
|
2
|
+
import { clientLabels } from '../guardrails/labels.js';
|
|
3
|
+
import { resolveGuardrailPolicy } from '../guardrails/policy.js';
|
|
4
|
+
import { projectProfileObject, requireModelProfile } from '../kernel/registry/resolve.js';
|
|
5
|
+
import { profileAllowsSteering } from '../kernel/stop.js';
|
|
6
|
+
import { profileToolAllow, profileToolsParallel, profileToolsSpec, } from '../kernel/tools/resolve.js';
|
|
7
|
+
import { resolveObservabilityPolicy } from '../observability/resolve-policy.js';
|
|
8
|
+
import { inputsFromSpec } from './inputs.js';
|
|
9
|
+
import { profileInterfaceSchema } from './profile-interface.js';
|
|
10
|
+
/** Resolved, not raw: a host sees what the kernel will enforce, not defaults of its own. */
|
|
11
|
+
function guardrailsView(guardrails) {
|
|
12
|
+
const policy = resolveGuardrailPolicy(guardrails);
|
|
13
|
+
const { sources, host, ...detect } = policy.detect;
|
|
14
|
+
return {
|
|
15
|
+
quota: policy.quota,
|
|
16
|
+
detect,
|
|
17
|
+
...(sources
|
|
18
|
+
? {
|
|
19
|
+
patterns: Object.fromEntries(Object.entries(sources).map(([detector, { theorem, matchers }]) => [
|
|
20
|
+
detector,
|
|
21
|
+
{ theorem, names: matchers.map(({ name }) => name) },
|
|
22
|
+
])),
|
|
23
|
+
}
|
|
24
|
+
: {}),
|
|
25
|
+
...(host
|
|
26
|
+
? {
|
|
27
|
+
host: host.map(({ id, label, actions, matchers, find }) => ({
|
|
28
|
+
id,
|
|
29
|
+
label,
|
|
30
|
+
actions,
|
|
31
|
+
names: matchers.map(({ name }) => name),
|
|
32
|
+
find: Boolean(find),
|
|
33
|
+
})),
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
36
|
+
allow: {
|
|
37
|
+
ungiven_images: urlAllowView(policy.allow.ungiven_images),
|
|
38
|
+
ungiven_links: urlAllowView(policy.allow.ungiven_links),
|
|
39
|
+
},
|
|
40
|
+
blockedReply: policy.blockedReply,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function urlAllowView(allow) {
|
|
44
|
+
return { hosts: [...(allow.hosts ?? [])], fromTools: allow.fromTools ?? true };
|
|
45
|
+
}
|
|
46
|
+
function writeToView(writeTo) {
|
|
47
|
+
if (writeTo === undefined || writeTo === false) {
|
|
48
|
+
return writeTo;
|
|
49
|
+
}
|
|
50
|
+
if (typeof writeTo === 'string') {
|
|
51
|
+
return writeTo;
|
|
52
|
+
}
|
|
53
|
+
return 'custom';
|
|
54
|
+
}
|
|
55
|
+
/** `writeTo` becomes `'custom'` when it is an inline TraceSink. */
|
|
56
|
+
function observabilityView(observability) {
|
|
57
|
+
if (!observability) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const policy = resolveObservabilityPolicy(observability);
|
|
61
|
+
return {
|
|
62
|
+
record: policy.record,
|
|
63
|
+
writeTo: writeToView(policy.writeTo),
|
|
64
|
+
sampleRate: policy.sampleRate,
|
|
65
|
+
include: policy.include,
|
|
66
|
+
scrub: policy.scrub,
|
|
67
|
+
resource: policy.resource,
|
|
68
|
+
retainForDays: policy.retainForDays,
|
|
69
|
+
rotateAfterMiB: policy.rotateAfterMiB,
|
|
70
|
+
hasOnWriteError: Boolean(policy.onWriteError),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** The live settings a client reads. The greeting and resume prompts are the host's, like `identity.system`. */
|
|
74
|
+
function liveView(live) {
|
|
75
|
+
const { greeting: _greeting, resumed: _resumed, ...view } = live ?? {};
|
|
76
|
+
return view;
|
|
77
|
+
}
|
|
78
|
+
function toolsView(projected, profile) {
|
|
79
|
+
const page = projected.tools
|
|
80
|
+
.filter((tool) => 'type' in tool && tool.type === 'function' && tool.answeredBy === 'page')
|
|
81
|
+
.map((tool) => tool.name);
|
|
82
|
+
if (profile) {
|
|
83
|
+
const spec = profileToolsSpec(profile);
|
|
84
|
+
const parallel = profileToolsParallel(profile);
|
|
85
|
+
return {
|
|
86
|
+
allow: [...profileToolAllow(profile)],
|
|
87
|
+
page,
|
|
88
|
+
...(spec?.t2Loader ? { t2Loader: spec.t2Loader } : {}),
|
|
89
|
+
...(parallel !== undefined ? { parallel } : {}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const allow = projected.tools
|
|
93
|
+
.filter((tool) => !('type' in tool && tool.type === 'builtin'))
|
|
94
|
+
.map((tool) => tool.name);
|
|
95
|
+
return { allow, page };
|
|
96
|
+
}
|
|
97
|
+
/** A call has no T2 loader. */
|
|
98
|
+
function liveToolsView({ allow, page }) {
|
|
99
|
+
return { allow, page };
|
|
100
|
+
}
|
|
101
|
+
function enrich(projected, profile) {
|
|
102
|
+
const inputs = inputsFromSpec(projected.inputs);
|
|
103
|
+
const identity = profile?.identity ?? { handle: projected.handle };
|
|
104
|
+
const guardrails = profile ? guardrailsView(profile.guardrails) : undefined;
|
|
105
|
+
const observability = profile ? observabilityView(profile.observability) : undefined;
|
|
106
|
+
const outputs = projected.outputs ?? undefined;
|
|
107
|
+
const shared = {
|
|
108
|
+
id: projected.id,
|
|
109
|
+
identity,
|
|
110
|
+
models: projected.models,
|
|
111
|
+
defaultModel: projected.defaultModel,
|
|
112
|
+
allowModelSelect: projected.allowModelSelect,
|
|
113
|
+
maxSteps: projected.maxSteps,
|
|
114
|
+
providerContinuation: projected.providerContinuation,
|
|
115
|
+
outputs,
|
|
116
|
+
guardrails,
|
|
117
|
+
observability,
|
|
118
|
+
labels: clientLabels(profile?.labels),
|
|
119
|
+
};
|
|
120
|
+
switch (projected.type) {
|
|
121
|
+
case 'text':
|
|
122
|
+
return profileInterfaceSchema.parse({
|
|
123
|
+
...shared,
|
|
124
|
+
type: 'text',
|
|
125
|
+
inputs,
|
|
126
|
+
tools: toolsView(projected, profile),
|
|
127
|
+
turnBehaviour: profile?.type === 'text' ? profile.turnBehaviour : undefined,
|
|
128
|
+
canStop: true,
|
|
129
|
+
allowSteering: profile ? profileAllowsSteering(profile) : true,
|
|
130
|
+
});
|
|
131
|
+
case 'image':
|
|
132
|
+
return profileInterfaceSchema.parse({
|
|
133
|
+
...shared,
|
|
134
|
+
type: 'image',
|
|
135
|
+
image: projected.image ?? {},
|
|
136
|
+
inputs,
|
|
137
|
+
tools: toolsView(projected, profile),
|
|
138
|
+
turnBehaviour: profile?.type === 'image' ? profile.turnBehaviour : undefined,
|
|
139
|
+
canStop: true,
|
|
140
|
+
});
|
|
141
|
+
case 'speech':
|
|
142
|
+
return profileInterfaceSchema.parse({
|
|
143
|
+
...shared,
|
|
144
|
+
type: 'speech',
|
|
145
|
+
speech: projected.speech ?? {},
|
|
146
|
+
inputs,
|
|
147
|
+
turnBehaviour: profile?.type === 'speech' ? profile.turnBehaviour : undefined,
|
|
148
|
+
canStop: true,
|
|
149
|
+
});
|
|
150
|
+
case 'live':
|
|
151
|
+
return profileInterfaceSchema.parse({
|
|
152
|
+
...shared,
|
|
153
|
+
type: 'live',
|
|
154
|
+
live: liveView(projected.live),
|
|
155
|
+
...(projected.inputs ? { inputs: { slots: inputs.slots, context: inputs.context } } : {}),
|
|
156
|
+
tools: liveToolsView(toolsView(projected, profile)),
|
|
157
|
+
});
|
|
158
|
+
default: {
|
|
159
|
+
const exhaustive = projected.type;
|
|
160
|
+
return exhaustive;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** The interface for any profile. */
|
|
165
|
+
function interfaceFromProfile(input, tools) {
|
|
166
|
+
// why: Host profiles never run a model and have no composer surface.
|
|
167
|
+
const profile = requireModelProfile(input, 'interfaceFromProfile');
|
|
168
|
+
return enrich(projectProfileObject(tools, profile), profile);
|
|
169
|
+
}
|
|
170
|
+
/** The interface for a profile the host has already projected, without resolving its tools again. */
|
|
171
|
+
function interfaceFromProjected(projected) {
|
|
172
|
+
return enrich(projected);
|
|
173
|
+
}
|
|
174
|
+
/** The client-safe interface for any profile. */
|
|
175
|
+
function clientProfileInterface(input, tools) {
|
|
176
|
+
const iface = interfaceFromProfile(input, tools);
|
|
177
|
+
return { ...iface, identity: { handle: iface.identity.handle } };
|
|
178
|
+
}
|
|
179
|
+
export { clientProfileInterface, interfaceFromProfile, interfaceFromProjected };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type LabelOverrides } from '../guardrails/labels.js';
|
|
2
|
+
import { type ToolCallRequest } from '../kernel/turn-events.js';
|
|
3
|
+
import type { TurnBlob, TurnEvent, TurnHistoryMessage } from '../kernel/types.js';
|
|
4
|
+
import type { ToolCall, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The kernel sets `readBack` on every `complete` and `error` event, so a call without it did not
|
|
7
|
+
* come from a run and has no text the model read.
|
|
8
|
+
*/
|
|
9
|
+
declare function toolReadBack(call: ToolCall): string;
|
|
10
|
+
/** The files a user turn adds to the history beside its text. */
|
|
11
|
+
export type UserTurnHistoryMedia = {
|
|
12
|
+
attachments?: TurnBlob[];
|
|
13
|
+
voice?: TurnBlob[];
|
|
14
|
+
};
|
|
15
|
+
/** For `onStage` inject. Uses base64 on `draft.attachments` / `draft.voice` when present. */
|
|
16
|
+
declare function userDraftToSteerInject(draft: UserTurnDraft): TurnHistoryMessage[];
|
|
17
|
+
/** The history with the user's draft added as a user message. */
|
|
18
|
+
declare function appendUserDraftToHistory(history: TurnHistoryMessage[], draft: UserTurnDraft, media?: UserTurnHistoryMedia): TurnHistoryMessage[];
|
|
19
|
+
/** The history with a tool call and its result added. */
|
|
20
|
+
declare function appendToolExchangeToHistory(history: TurnHistoryMessage[], call: ToolCall): TurnHistoryMessage[];
|
|
21
|
+
/** The history with a denied tool call and the reason added. */
|
|
22
|
+
declare function appendToolDenialToHistory(history: TurnHistoryMessage[], tool: ToolCallRequest & {
|
|
23
|
+
/** Override the default deny copy. */
|
|
24
|
+
failure?: {
|
|
25
|
+
code: string;
|
|
26
|
+
message: string;
|
|
27
|
+
};
|
|
28
|
+
}, labels: LabelOverrides | undefined): TurnHistoryMessage[];
|
|
29
|
+
/** The history with the assistant's reply from the turn events added. */
|
|
30
|
+
declare function appendAssistantEventsToHistory(history: TurnHistoryMessage[], events: readonly TurnEvent[]): TurnHistoryMessage[];
|
|
31
|
+
/**
|
|
32
|
+
* A reply paused on its gates, as the model reads it when the user walks away:
|
|
33
|
+
* its gated calls stay open in their step for the host to answer
|
|
34
|
+
* (`answerOpenToolCalls`) before the user's next message.
|
|
35
|
+
*/
|
|
36
|
+
declare function appendPausedTurnToHistory(history: TurnHistoryMessage[], events: readonly TurnEvent[]): TurnHistoryMessage[];
|
|
37
|
+
/** Attachment and voice blocks are omitted: their preview `data` is UI-only. */
|
|
38
|
+
declare function historyFromTranscriptBlocks(blocks: readonly TranscriptBlock[]): TurnHistoryMessage[];
|
|
39
|
+
/** Throws unless the history's open tool calls are exactly these ids. */
|
|
40
|
+
declare function assertOpenToolCalls(history: readonly TurnHistoryMessage[], ids: readonly string[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* `answers` holds, by call id, the text the model reads for each open call. Results follow their
|
|
43
|
+
* step in the order the model made the calls. Throws unless `answers` names exactly the open calls.
|
|
44
|
+
*/
|
|
45
|
+
declare function answerOpenToolCalls(history: readonly TurnHistoryMessage[], answers: ReadonlyMap<string, string>): TurnHistoryMessage[];
|
|
46
|
+
export { answerOpenToolCalls, appendAssistantEventsToHistory, appendPausedTurnToHistory, appendToolDenialToHistory, appendToolExchangeToHistory, appendUserDraftToHistory, assertOpenToolCalls, historyFromTranscriptBlocks, toolReadBack, userDraftToSteerInject, };
|