@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,152 @@
|
|
|
1
|
+
// invariant: `steer` injects at `onStage` boundaries of the same run; `queue` sends after the run fully ends
|
|
2
|
+
// (not on tool pause); `stash` never auto-sends. `send_now` is an action, not a pending kind.
|
|
3
|
+
/** Display order: steers, then queues, then stashes. */
|
|
4
|
+
export const COMPOSER_PENDING_KINDS = ['steer', 'queue', 'stash'];
|
|
5
|
+
function createPendingId() {
|
|
6
|
+
return typeof crypto !== 'undefined' && 'randomUUID' in crypto
|
|
7
|
+
? crypto.randomUUID()
|
|
8
|
+
: `pending-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
9
|
+
}
|
|
10
|
+
/** True when the draft holds text, an attachment, or voice. */
|
|
11
|
+
function userDraftHasPayload(draft) {
|
|
12
|
+
return Boolean(draft.text?.trim() ||
|
|
13
|
+
(draft.attachments && draft.attachments.length > 0) ||
|
|
14
|
+
(draft.voice && draft.voice.length > 0));
|
|
15
|
+
}
|
|
16
|
+
/** Short preview for pending bars (text, else attachment hint). */
|
|
17
|
+
function composerPendingPreview(message) {
|
|
18
|
+
const text = message.draft.text?.trim();
|
|
19
|
+
if (text)
|
|
20
|
+
return text;
|
|
21
|
+
const files = (message.draft.attachments?.length ?? 0) + (message.draft.voice?.length ?? 0);
|
|
22
|
+
if (files > 0)
|
|
23
|
+
return files === 1 ? '(attachment)' : `(${files} attachments)`;
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
/** Throws on an empty draft. */
|
|
27
|
+
function createComposerPendingMessage(args) {
|
|
28
|
+
if (!userDraftHasPayload(args.draft)) {
|
|
29
|
+
throw new Error('Composer pending message requires a non-empty draft'); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
30
|
+
}
|
|
31
|
+
const now = args.now ?? Date.now();
|
|
32
|
+
return {
|
|
33
|
+
id: args.id ?? createPendingId(),
|
|
34
|
+
kind: args.kind,
|
|
35
|
+
draft: cloneUserTurnDraft(args.draft),
|
|
36
|
+
createdAt: now,
|
|
37
|
+
updatedAt: now,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** A copy of the draft that shares nothing with the original. */
|
|
41
|
+
function cloneUserTurnDraft(draft) {
|
|
42
|
+
return {
|
|
43
|
+
...(draft.text !== undefined ? { text: draft.text } : {}),
|
|
44
|
+
...(draft.attachments ? { attachments: draft.attachments.map((a) => ({ ...a })) } : {}),
|
|
45
|
+
...(draft.voice ? { voice: draft.voice.map((a) => ({ ...a })) } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Steer, then queue, then stash; FIFO within a kind. */
|
|
49
|
+
function orderComposerPendingMessages(messages) {
|
|
50
|
+
return [
|
|
51
|
+
...messages.filter((m) => m.kind === 'steer'),
|
|
52
|
+
...messages.filter((m) => m.kind === 'queue'),
|
|
53
|
+
...messages.filter((m) => m.kind === 'stash'),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
/** When a run ends, undelivered steers become queues ahead of the existing ones. */
|
|
57
|
+
function convertSteersToFrontQueued(messages, now = Date.now()) {
|
|
58
|
+
const steers = messages
|
|
59
|
+
.filter((m) => m.kind === 'steer')
|
|
60
|
+
.map((m) => ({
|
|
61
|
+
...m,
|
|
62
|
+
kind: 'queue',
|
|
63
|
+
updatedAt: now,
|
|
64
|
+
}));
|
|
65
|
+
const queues = messages.filter((m) => m.kind === 'queue');
|
|
66
|
+
const stashes = messages.filter((m) => m.kind === 'stash');
|
|
67
|
+
return [...steers, ...queues, ...stashes];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Drops the steers a turn event reports as landed in the conversation. A steer
|
|
71
|
+
* it never names stays pending, so the run's end requeues it.
|
|
72
|
+
*/
|
|
73
|
+
function removeLandedSteers(messages, event) {
|
|
74
|
+
if (event.type !== 'stage' || !event.injected?.length)
|
|
75
|
+
return [...messages];
|
|
76
|
+
const landed = new Set(event.injected.map((steer) => steer.id));
|
|
77
|
+
return messages.filter((m) => !(m.kind === 'steer' && landed.has(m.id)));
|
|
78
|
+
}
|
|
79
|
+
/** The messages without the one with this id. */
|
|
80
|
+
function removeComposerPendingMessage(messages, id) {
|
|
81
|
+
return messages.filter((m) => m.id !== id);
|
|
82
|
+
}
|
|
83
|
+
/** The messages with this id's draft replaced; throws when the new draft is empty. */
|
|
84
|
+
function updateComposerPendingDraft(messages, id, draft, now = Date.now()) {
|
|
85
|
+
if (!userDraftHasPayload(draft)) {
|
|
86
|
+
throw new Error('Composer pending message requires a non-empty draft'); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
87
|
+
}
|
|
88
|
+
return messages.map((m) => m.id === id
|
|
89
|
+
? {
|
|
90
|
+
...m,
|
|
91
|
+
draft: cloneUserTurnDraft(draft),
|
|
92
|
+
updatedAt: now,
|
|
93
|
+
}
|
|
94
|
+
: m);
|
|
95
|
+
}
|
|
96
|
+
/** The messages with this id moved one place up or down among those of its kind. */
|
|
97
|
+
function moveComposerPendingWithinKind(messages, id, direction) {
|
|
98
|
+
const message = messages.find((m) => m.id === id);
|
|
99
|
+
if (!message)
|
|
100
|
+
return [...messages];
|
|
101
|
+
const sameKind = messages.filter((m) => m.kind === message.kind);
|
|
102
|
+
const currentIndex = sameKind.findIndex((m) => m.id === id);
|
|
103
|
+
if (currentIndex < 0)
|
|
104
|
+
return orderComposerPendingMessages(messages);
|
|
105
|
+
const nextIndex = direction === 'up' ? currentIndex - 1 : currentIndex + 1;
|
|
106
|
+
if (nextIndex < 0 || nextIndex >= sameKind.length) {
|
|
107
|
+
return orderComposerPendingMessages(messages);
|
|
108
|
+
}
|
|
109
|
+
const reordered = [...sameKind];
|
|
110
|
+
const [removed] = reordered.splice(currentIndex, 1);
|
|
111
|
+
if (!removed)
|
|
112
|
+
return orderComposerPendingMessages(messages);
|
|
113
|
+
reordered.splice(nextIndex, 0, removed);
|
|
114
|
+
const byKind = {
|
|
115
|
+
steer: message.kind === 'steer' ? reordered : messages.filter((m) => m.kind === 'steer'),
|
|
116
|
+
queue: message.kind === 'queue' ? reordered : messages.filter((m) => m.kind === 'queue'),
|
|
117
|
+
stash: message.kind === 'stash' ? reordered : messages.filter((m) => m.kind === 'stash'),
|
|
118
|
+
};
|
|
119
|
+
return [...byKind.steer, ...byKind.queue, ...byKind.stash];
|
|
120
|
+
}
|
|
121
|
+
/** One steer per safe boundary: call once per `onStage` inject site. */
|
|
122
|
+
function consumeNextComposerSteer(messages) {
|
|
123
|
+
const message = messages.find((m) => m.kind === 'steer') ?? null;
|
|
124
|
+
if (!message)
|
|
125
|
+
return { message: null, remaining: [...messages] };
|
|
126
|
+
return {
|
|
127
|
+
message,
|
|
128
|
+
remaining: messages.filter((m) => m.id !== message.id),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Call only after the agent run has fully ended, not on a tool pause. */
|
|
132
|
+
function consumeNextComposerQueue(messages) {
|
|
133
|
+
const message = messages.find((m) => m.kind === 'queue') ?? null;
|
|
134
|
+
if (!message)
|
|
135
|
+
return { message: null, remaining: [...messages] };
|
|
136
|
+
return {
|
|
137
|
+
message,
|
|
138
|
+
remaining: messages.filter((m) => m.id !== message.id),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** The messages with this id changed to another kind. */
|
|
142
|
+
function promoteComposerPendingKind(messages, id, kind, now = Date.now()) {
|
|
143
|
+
const updated = messages.map((m) => m.id === id
|
|
144
|
+
? {
|
|
145
|
+
...m,
|
|
146
|
+
kind,
|
|
147
|
+
updatedAt: now,
|
|
148
|
+
}
|
|
149
|
+
: m);
|
|
150
|
+
return orderComposerPendingMessages(updated);
|
|
151
|
+
}
|
|
152
|
+
export { cloneUserTurnDraft, composerPendingPreview, consumeNextComposerQueue, consumeNextComposerSteer, convertSteersToFrontQueued, createComposerPendingMessage, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, updateComposerPendingDraft, userDraftHasPayload, };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BOUNDARIES, recordOf } from '../guardrails/boundaries.js';
|
|
3
|
+
import { DETECT_ACTIONS, DETECTORS } from '../guardrails/detectors.js';
|
|
4
|
+
import { LABEL_KEYS } from '../guardrails/labels.js';
|
|
5
|
+
import { BLOCKED_REPLY_ON_BLOCK } from '../guardrails/types.js';
|
|
6
|
+
import { COMPACTION_METERS, COMPACTION_TIMINGS, CONTEXT_SENDERS, CONTINUE_STOP_KINDS, LIVE_ACTIVITY_HANDLINGS, LIVE_END_SENSITIVITIES, LIVE_START_SENSITIVITIES, SPEECH_AUDIO_FORMATS, STEP_LIMIT_MODES, STREAM_MODES, THINKING_LEVELS, } from '../kernel/schema.js';
|
|
7
|
+
import { traceAttributesSchema } from '../observability/trace-schema.js';
|
|
8
|
+
const modelBinding = z.object({
|
|
9
|
+
protocol: z.string(),
|
|
10
|
+
provider: z.string(),
|
|
11
|
+
apiId: z.string(),
|
|
12
|
+
options: z.record(z.string(), z.json()).optional(),
|
|
13
|
+
keySlot: z.string().optional(),
|
|
14
|
+
fallbackKeySlot: z.string().optional(),
|
|
15
|
+
efforts: z.record(z.string(), z.enum(THINKING_LEVELS)).optional(),
|
|
16
|
+
defaultEffort: z.string().optional(),
|
|
17
|
+
allowEffortSelect: z.boolean().optional(),
|
|
18
|
+
summaries: z.boolean().optional(),
|
|
19
|
+
maxOutputTokens: z.number().optional(),
|
|
20
|
+
temperature: z.number().optional(),
|
|
21
|
+
builtInTools: z.array(z.string()).optional(),
|
|
22
|
+
compaction: z
|
|
23
|
+
.object({
|
|
24
|
+
maxTokens: z.number(),
|
|
25
|
+
compactAt: z.number(),
|
|
26
|
+
previousExchanges: z.number(),
|
|
27
|
+
profile: z.string().optional(),
|
|
28
|
+
timing: z.enum(COMPACTION_TIMINGS),
|
|
29
|
+
meter: z.enum(COMPACTION_METERS).optional(),
|
|
30
|
+
})
|
|
31
|
+
.optional(),
|
|
32
|
+
});
|
|
33
|
+
const outputs = z.object({
|
|
34
|
+
structured: z
|
|
35
|
+
.union([
|
|
36
|
+
z.string(),
|
|
37
|
+
z.object({ by: z.string(), map: z.record(z.string(), z.string()), fallback: z.string() }),
|
|
38
|
+
z.null(),
|
|
39
|
+
])
|
|
40
|
+
.optional(),
|
|
41
|
+
streaming: z
|
|
42
|
+
.object({
|
|
43
|
+
mode: z.enum(STREAM_MODES).optional(),
|
|
44
|
+
streamThoughts: z.boolean().optional(),
|
|
45
|
+
})
|
|
46
|
+
.optional(),
|
|
47
|
+
});
|
|
48
|
+
const actions = z.object(recordOf(BOUNDARIES, () => z.enum(DETECT_ACTIONS)));
|
|
49
|
+
const detect = z.object(recordOf(DETECTORS, () => actions));
|
|
50
|
+
const hostDetector = z.object({
|
|
51
|
+
id: z.string(),
|
|
52
|
+
label: z.string(),
|
|
53
|
+
actions,
|
|
54
|
+
names: z.array(z.string()),
|
|
55
|
+
find: z.boolean(),
|
|
56
|
+
});
|
|
57
|
+
const urlAllow = z.object({ hosts: z.array(z.string()), fromTools: z.boolean() });
|
|
58
|
+
const guardrails = z.object({
|
|
59
|
+
quota: z.object({ perDay: z.number() }).optional(),
|
|
60
|
+
detect,
|
|
61
|
+
patterns: z
|
|
62
|
+
.partialRecord(z.enum(DETECTORS), z.object({ theorem: z.boolean(), names: z.array(z.string()) }))
|
|
63
|
+
.optional(),
|
|
64
|
+
host: z.array(hostDetector).optional(),
|
|
65
|
+
allow: z.object({ ungiven_images: urlAllow, ungiven_links: urlAllow }),
|
|
66
|
+
blockedReply: z.object({ onBlock: z.enum(BLOCKED_REPLY_ON_BLOCK), maxRetries: z.number() }),
|
|
67
|
+
});
|
|
68
|
+
const scrubSwitch = z.union([z.boolean(), z.object({ theorem: z.boolean(), host: z.boolean() })]);
|
|
69
|
+
const observability = z.object({
|
|
70
|
+
record: z.boolean(),
|
|
71
|
+
writeTo: z.union([z.literal(false), z.string()]).optional(),
|
|
72
|
+
sampleRate: z.number(),
|
|
73
|
+
include: z.object({
|
|
74
|
+
upstreamLog: z.boolean(),
|
|
75
|
+
outboundWire: z.boolean(),
|
|
76
|
+
evidenceRaw: z.boolean(),
|
|
77
|
+
usage: z.boolean(),
|
|
78
|
+
guardrailDecisions: z.boolean(),
|
|
79
|
+
guardrailMatchPreview: z.boolean(),
|
|
80
|
+
}),
|
|
81
|
+
scrub: z.object({ sensitive: scrubSwitch, injection: scrubSwitch, canary: scrubSwitch }),
|
|
82
|
+
resource: traceAttributesSchema,
|
|
83
|
+
retainForDays: z.number(),
|
|
84
|
+
rotateAfterMiB: z.number(),
|
|
85
|
+
hasOnWriteError: z.boolean(),
|
|
86
|
+
});
|
|
87
|
+
const inputs = z.object({
|
|
88
|
+
text: z.boolean(),
|
|
89
|
+
attachments: z.object({ accept: z.array(z.string()), acceptAttr: z.string() }).nullable(),
|
|
90
|
+
voice: z.object({ accept: z.array(z.string()) }).nullable(),
|
|
91
|
+
maxFiles: z.number().optional(),
|
|
92
|
+
maxBytes: z.number().optional(),
|
|
93
|
+
maxTurnBytes: z.number().optional(),
|
|
94
|
+
limitsByMime: z.record(z.string(), z.number()).optional(),
|
|
95
|
+
slots: z.record(z.string(), z.array(z.string())).optional(),
|
|
96
|
+
context: z.object({ from: z.array(z.enum(CONTEXT_SENDERS)), maxChars: z.number() }).optional(),
|
|
97
|
+
});
|
|
98
|
+
const resumption = z.object({
|
|
99
|
+
allowContinue: z.array(z.enum(CONTINUE_STOP_KINDS)).optional(),
|
|
100
|
+
autoContinue: z.array(z.enum(CONTINUE_STOP_KINDS)).optional(),
|
|
101
|
+
maxContinues: z.number().optional(),
|
|
102
|
+
});
|
|
103
|
+
const mediaTurnBehaviour = z.object({ resumption: resumption.optional() });
|
|
104
|
+
const tools = z.object({
|
|
105
|
+
allow: z.array(z.string()),
|
|
106
|
+
page: z.array(z.string()),
|
|
107
|
+
t2Loader: z.string().optional(),
|
|
108
|
+
parallel: z.boolean().optional(),
|
|
109
|
+
});
|
|
110
|
+
const common = {
|
|
111
|
+
providerContinuation: z
|
|
112
|
+
.object({
|
|
113
|
+
history: z.enum(['host', 'stateless', 'provider']).optional(),
|
|
114
|
+
})
|
|
115
|
+
.optional(),
|
|
116
|
+
id: z.string(),
|
|
117
|
+
models: z.record(z.string(), modelBinding),
|
|
118
|
+
defaultModel: z.string(),
|
|
119
|
+
allowModelSelect: z.boolean().optional(),
|
|
120
|
+
maxSteps: z.number().optional(),
|
|
121
|
+
labels: z.partialRecord(z.enum(LABEL_KEYS), z.string()),
|
|
122
|
+
guardrails: guardrails.optional(),
|
|
123
|
+
observability: observability.optional(),
|
|
124
|
+
};
|
|
125
|
+
const systemPrompt = z.union([
|
|
126
|
+
z.string(),
|
|
127
|
+
z
|
|
128
|
+
.array(z.union([z.string(), z.strictObject({ private: z.string().min(1) })]))
|
|
129
|
+
.min(1)
|
|
130
|
+
.readonly(),
|
|
131
|
+
]);
|
|
132
|
+
const identity = z.object({
|
|
133
|
+
handle: z.string(),
|
|
134
|
+
system: systemPrompt.optional(),
|
|
135
|
+
systemByRole: z.record(z.string(), systemPrompt).optional(),
|
|
136
|
+
});
|
|
137
|
+
const profileInterface = z.discriminatedUnion('type', [
|
|
138
|
+
z.object({
|
|
139
|
+
...common,
|
|
140
|
+
type: z.literal('text'),
|
|
141
|
+
identity,
|
|
142
|
+
outputs: outputs.optional(),
|
|
143
|
+
inputs,
|
|
144
|
+
tools,
|
|
145
|
+
turnBehaviour: z
|
|
146
|
+
.object({
|
|
147
|
+
resumption: resumption.optional(),
|
|
148
|
+
allowSteering: z.boolean().optional(),
|
|
149
|
+
atStepLimit: z.enum(STEP_LIMIT_MODES).optional(),
|
|
150
|
+
})
|
|
151
|
+
.optional(),
|
|
152
|
+
canStop: z.literal(true),
|
|
153
|
+
allowSteering: z.boolean(),
|
|
154
|
+
}),
|
|
155
|
+
z.object({
|
|
156
|
+
...common,
|
|
157
|
+
type: z.literal('image'),
|
|
158
|
+
identity,
|
|
159
|
+
outputs: outputs.optional(),
|
|
160
|
+
image: z.object({
|
|
161
|
+
aspectRatio: z.string().optional(),
|
|
162
|
+
resolution: z.string().optional(),
|
|
163
|
+
mimeType: z.string().optional(),
|
|
164
|
+
quality: z.string().optional(),
|
|
165
|
+
background: z.string().optional(),
|
|
166
|
+
n: z.number().int().min(1).optional(),
|
|
167
|
+
seed: z.number().int().optional(),
|
|
168
|
+
outputCompression: z.number().int().min(0).max(100).optional(),
|
|
169
|
+
references: z
|
|
170
|
+
.array(z.union([
|
|
171
|
+
z.object({ mimeType: z.string(), data: z.string(), name: z.string().optional() }),
|
|
172
|
+
z.object({ mimeType: z.string(), uri: z.string(), name: z.string().optional() }),
|
|
173
|
+
]))
|
|
174
|
+
.optional(),
|
|
175
|
+
includeText: z.boolean().optional(),
|
|
176
|
+
}),
|
|
177
|
+
inputs,
|
|
178
|
+
tools,
|
|
179
|
+
turnBehaviour: mediaTurnBehaviour.optional(),
|
|
180
|
+
canStop: z.literal(true),
|
|
181
|
+
}),
|
|
182
|
+
z.object({
|
|
183
|
+
...common,
|
|
184
|
+
type: z.literal('speech'),
|
|
185
|
+
identity: z.object({ handle: z.string() }),
|
|
186
|
+
outputs: outputs.optional(),
|
|
187
|
+
speech: z.object({
|
|
188
|
+
voice: z.string().optional(),
|
|
189
|
+
style: z.string().optional(),
|
|
190
|
+
speed: z.number().optional(),
|
|
191
|
+
format: z.enum(SPEECH_AUDIO_FORMATS).optional(),
|
|
192
|
+
}),
|
|
193
|
+
inputs,
|
|
194
|
+
turnBehaviour: mediaTurnBehaviour.optional(),
|
|
195
|
+
canStop: z.literal(true),
|
|
196
|
+
}),
|
|
197
|
+
z.object({
|
|
198
|
+
...common,
|
|
199
|
+
type: z.literal('live'),
|
|
200
|
+
identity,
|
|
201
|
+
inputs: inputs.pick({ slots: true, context: true }).optional(),
|
|
202
|
+
live: z.object({
|
|
203
|
+
ingress: z
|
|
204
|
+
.object({
|
|
205
|
+
audio: z.boolean().optional(),
|
|
206
|
+
video: z.boolean().optional(),
|
|
207
|
+
text: z.boolean().optional(),
|
|
208
|
+
})
|
|
209
|
+
.optional(),
|
|
210
|
+
voice: z.string().optional(),
|
|
211
|
+
vad: z
|
|
212
|
+
.object({
|
|
213
|
+
activityHandling: z.enum(LIVE_ACTIVITY_HANDLINGS).optional(),
|
|
214
|
+
startSensitivity: z.enum(LIVE_START_SENSITIVITIES).optional(),
|
|
215
|
+
endSensitivity: z.enum(LIVE_END_SENSITIVITIES).optional(),
|
|
216
|
+
prefixPaddingMs: z.number().optional(),
|
|
217
|
+
silenceDurationMs: z.number().optional(),
|
|
218
|
+
})
|
|
219
|
+
.optional(),
|
|
220
|
+
sessionResumption: z.boolean().optional(),
|
|
221
|
+
contextCompression: z
|
|
222
|
+
.object({
|
|
223
|
+
triggerTokens: z.number().optional(),
|
|
224
|
+
slidingWindow: z.object({ targetTokens: z.number().optional() }),
|
|
225
|
+
})
|
|
226
|
+
.optional(),
|
|
227
|
+
transcription: z
|
|
228
|
+
.object({ input: z.boolean().optional(), output: z.boolean().optional() })
|
|
229
|
+
.optional(),
|
|
230
|
+
}),
|
|
231
|
+
tools: tools.pick({ allow: true, page: true }),
|
|
232
|
+
turnBehaviour: z.object({ allowSteering: z.boolean().optional() }).optional(),
|
|
233
|
+
}),
|
|
234
|
+
]);
|
|
235
|
+
true;
|
|
236
|
+
/** `ProfileInterface`, checked: unnamed fields are dropped, a malformed one fails. */
|
|
237
|
+
export const profileInterfaceSchema = profileInterface;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ToolGateAuth } from '../kernel/tools/gate-answer.js';
|
|
2
|
+
import type { ToolGate, TurnToolSnapshot } from '../kernel/tools/types.js';
|
|
3
|
+
import { type ReasoningPart } from '../kernel/turn-events.js';
|
|
4
|
+
import type { ModelId, ToolId, TurnEvent, TurnHistoryMessage } from '../kernel/types.js';
|
|
5
|
+
import type { TranscriptBlock, UserTurnDraft } from './types.js';
|
|
6
|
+
export type { ToolGateAuth };
|
|
7
|
+
/** A tool call held at a gate: the tool, its call id, and arguments. */
|
|
8
|
+
export type GatedToolContext = {
|
|
9
|
+
operationId?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
callId: string;
|
|
12
|
+
arguments: Record<string, unknown>;
|
|
13
|
+
/** The call's `ToolCallRequest.reasoning`, for recording the call in history. */
|
|
14
|
+
reasoning?: ReasoningPart[];
|
|
15
|
+
gateKind: ToolGate['kind'];
|
|
16
|
+
permission?: ToolGate['permission'];
|
|
17
|
+
summary?: string;
|
|
18
|
+
/** Set on a sign-in gate. */
|
|
19
|
+
auth?: ToolGateAuth;
|
|
20
|
+
};
|
|
21
|
+
/** A tool call that paused the turn to ask the user: the tool, its call id, and arguments. */
|
|
22
|
+
export type AwaitingToolContext = {
|
|
23
|
+
name: string;
|
|
24
|
+
callId: string;
|
|
25
|
+
arguments: Record<string, unknown>;
|
|
26
|
+
kind: string;
|
|
27
|
+
prompt: string;
|
|
28
|
+
options?: string[];
|
|
29
|
+
};
|
|
30
|
+
/** The state a client keeps between turns: portable history, native checkpoint, and permissions. */
|
|
31
|
+
export type InterfaceTurnSession = {
|
|
32
|
+
history: TurnHistoryMessage[];
|
|
33
|
+
providerState?: import('../kernel/checkpoint.js').ProviderCheckpoint;
|
|
34
|
+
sessionPermissions: string[];
|
|
35
|
+
/** Last turn `tokens.input` for compaction meter `timing: 'before'`. */
|
|
36
|
+
inputTokens?: number;
|
|
37
|
+
/** Host override for compaction meter `history`. */
|
|
38
|
+
historyTokens?: number;
|
|
39
|
+
/** Active pre_tool gate awaiting host resume. */
|
|
40
|
+
gatedTool: GatedToolContext | null;
|
|
41
|
+
/** Completed ask_user (or similar) awaiting host UI — turn may already be done. */
|
|
42
|
+
awaitingTool: AwaitingToolContext | null;
|
|
43
|
+
/** Kernel events for the assistant segment still in flight (gate / resume / continue). */
|
|
44
|
+
assistantEvents: TurnEvent[];
|
|
45
|
+
/** User draft for the turn that produced `assistantEvents`. */
|
|
46
|
+
pendingUserDraft: UserTurnDraft | null;
|
|
47
|
+
/** Snapshot from the last gate `done` event — pass to `invokeTool({ snapshot })`. */
|
|
48
|
+
toolSnapshot?: TurnToolSnapshot;
|
|
49
|
+
/** T2 tool ids promoted during the current assistant segment (loader `loaded` outputs). */
|
|
50
|
+
promotedToolIds: ToolId[];
|
|
51
|
+
/** User-selected model id when `allowModelSelect` is enabled on the profile. */
|
|
52
|
+
selectedModel?: ModelId;
|
|
53
|
+
/** Selected effort alias when the active model has `allowEffortSelect`. */
|
|
54
|
+
selectedEffort?: string;
|
|
55
|
+
};
|
|
56
|
+
/** A session with no history and no permissions. */
|
|
57
|
+
declare function emptyInterfaceTurnSession(): InterfaceTurnSession;
|
|
58
|
+
/**
|
|
59
|
+
* Every call still waiting on its gate, in the order the model made them. One
|
|
60
|
+
* step can leave several: a gate holds only its own call.
|
|
61
|
+
*/
|
|
62
|
+
declare function gatedToolsFromEvents(events: readonly TurnEvent[]): GatedToolContext[];
|
|
63
|
+
/** The gate the user answers next: the first call still waiting. */
|
|
64
|
+
declare function gatedToolFromEvents(events: readonly TurnEvent[]): GatedToolContext | null;
|
|
65
|
+
/** The tool call a turn paused on to ask the user, or `null`. */
|
|
66
|
+
declare function awaitingFromEvents(events: readonly TurnEvent[]): AwaitingToolContext | null;
|
|
67
|
+
/** The session after the turn events are applied to it. */
|
|
68
|
+
declare function applyTurnEventsToSession(session: InterfaceTurnSession, events: readonly TurnEvent[]): InterfaceTurnSession;
|
|
69
|
+
/** Drops native provider state so the next turn sends the rebuilt history, not a stale handle. */
|
|
70
|
+
declare function branchInterfaceTurnSession(session: InterfaceTurnSession, blocks: readonly TranscriptBlock[]): InterfaceTurnSession;
|
|
71
|
+
export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSession, emptyInterfaceTurnSession, gatedToolFromEvents, gatedToolsFromEvents, };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { isAwaitingUserInput } from '../kernel/turn-events.js';
|
|
2
|
+
import { findLast } from '../kernel/util/find-last.js';
|
|
3
|
+
import { historyFromTranscriptBlocks } from './history.js';
|
|
4
|
+
import { toolCallsOf } from './tool-calls.js';
|
|
5
|
+
import { promotedToolIdsFromEvents, toolSnapshotFromEvents } from './tool-invoke.js';
|
|
6
|
+
/** A session with no history and no permissions. */
|
|
7
|
+
function emptyInterfaceTurnSession() {
|
|
8
|
+
return {
|
|
9
|
+
history: [],
|
|
10
|
+
sessionPermissions: [],
|
|
11
|
+
gatedTool: null,
|
|
12
|
+
awaitingTool: null,
|
|
13
|
+
assistantEvents: [],
|
|
14
|
+
pendingUserDraft: null,
|
|
15
|
+
promotedToolIds: [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Every call still waiting on its gate, in the order the model made them. One
|
|
20
|
+
* step can leave several: a gate holds only its own call.
|
|
21
|
+
*/
|
|
22
|
+
function gatedToolsFromEvents(events) {
|
|
23
|
+
const paused = events.some((event) => event.type === 'done' && (event.stop.kind === 'gate' || event.stop.kind === 'tool'));
|
|
24
|
+
if (!paused)
|
|
25
|
+
return [];
|
|
26
|
+
return toolCallsOf(events).flatMap((call) => {
|
|
27
|
+
if (call.state?.phase !== 'gate')
|
|
28
|
+
return [];
|
|
29
|
+
const { gate } = call.state;
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
name: call.name,
|
|
33
|
+
callId: call.callId,
|
|
34
|
+
...(call.operationId ? { operationId: call.operationId } : {}),
|
|
35
|
+
arguments: gate.preparedArguments ?? call.arguments,
|
|
36
|
+
...(call.reasoning ? { reasoning: call.reasoning } : {}),
|
|
37
|
+
gateKind: gate.kind,
|
|
38
|
+
permission: gate.permission,
|
|
39
|
+
summary: gate.summary,
|
|
40
|
+
...(gate.kind === 'auth'
|
|
41
|
+
? {
|
|
42
|
+
auth: {
|
|
43
|
+
slot: gate.authChallenge.slot,
|
|
44
|
+
authType: gate.authChallenge.authType,
|
|
45
|
+
service: gate.authChallenge.service,
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
: {}),
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** The gate the user answers next: the first call still waiting. */
|
|
54
|
+
function gatedToolFromEvents(events) {
|
|
55
|
+
return gatedToolsFromEvents(events)[0] ?? null;
|
|
56
|
+
}
|
|
57
|
+
/** The tool call a turn paused on to ask the user, or `null`. */
|
|
58
|
+
function awaitingFromEvents(events) {
|
|
59
|
+
const call = findLast(toolCallsOf(events), (c) => c.state?.phase === 'complete');
|
|
60
|
+
if (call?.state?.phase !== 'complete')
|
|
61
|
+
return null;
|
|
62
|
+
const { output } = call.state;
|
|
63
|
+
if (!isAwaitingUserInput(output))
|
|
64
|
+
return null;
|
|
65
|
+
return {
|
|
66
|
+
name: call.name,
|
|
67
|
+
callId: call.callId,
|
|
68
|
+
arguments: call.arguments,
|
|
69
|
+
kind: output.kind,
|
|
70
|
+
prompt: output.prompt,
|
|
71
|
+
options: output.options,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** The session after the turn events are applied to it. */
|
|
75
|
+
function applyTurnEventsToSession(session, events) {
|
|
76
|
+
let providerState = session.providerState;
|
|
77
|
+
let inputTokens = session.inputTokens;
|
|
78
|
+
let historyTokens = session.historyTokens;
|
|
79
|
+
let toolSnapshot = session.toolSnapshot;
|
|
80
|
+
let promotedToolIds = session.promotedToolIds;
|
|
81
|
+
for (const event of events) {
|
|
82
|
+
if (event.type === 'provider_checkpoint')
|
|
83
|
+
providerState = event.providerState;
|
|
84
|
+
if (event.type === 'done' && event.providerState)
|
|
85
|
+
providerState = event.providerState;
|
|
86
|
+
if (event.type === 'provider_warning')
|
|
87
|
+
providerState = undefined;
|
|
88
|
+
// why: A call's own input size, not the turn's sum (`done.tokens`).
|
|
89
|
+
if (event.type === 'tokens' && event.tokens.input) {
|
|
90
|
+
inputTokens = event.tokens.input;
|
|
91
|
+
}
|
|
92
|
+
if (event.type === 'done' && event.compaction?.tokens !== undefined) {
|
|
93
|
+
historyTokens = event.compaction.tokens;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const snapshotFromDone = toolSnapshotFromEvents(events);
|
|
97
|
+
if (snapshotFromDone) {
|
|
98
|
+
toolSnapshot = snapshotFromDone;
|
|
99
|
+
}
|
|
100
|
+
const newPromoted = promotedToolIdsFromEvents(events);
|
|
101
|
+
if (newPromoted.length > 0) {
|
|
102
|
+
promotedToolIds = [...new Set([...promotedToolIds, ...newPromoted])];
|
|
103
|
+
}
|
|
104
|
+
const gated = gatedToolFromEvents(events);
|
|
105
|
+
return {
|
|
106
|
+
...session,
|
|
107
|
+
providerState,
|
|
108
|
+
inputTokens,
|
|
109
|
+
historyTokens,
|
|
110
|
+
gatedTool: gated,
|
|
111
|
+
awaitingTool: awaitingFromEvents(events),
|
|
112
|
+
toolSnapshot,
|
|
113
|
+
promotedToolIds,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Drops native provider state so the next turn sends the rebuilt history, not a stale handle. */
|
|
117
|
+
function branchInterfaceTurnSession(session, blocks) {
|
|
118
|
+
return {
|
|
119
|
+
...emptyInterfaceTurnSession(),
|
|
120
|
+
history: historyFromTranscriptBlocks(blocks),
|
|
121
|
+
sessionPermissions: [...session.sessionPermissions],
|
|
122
|
+
inputTokens: session.inputTokens,
|
|
123
|
+
historyTokens: session.historyTokens,
|
|
124
|
+
selectedModel: session.selectedModel,
|
|
125
|
+
selectedEffort: session.selectedEffort,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSession, emptyInterfaceTurnSession, gatedToolFromEvents, gatedToolsFromEvents, };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type LabelOverrides } from '../guardrails/labels.js';
|
|
2
|
+
import type { TurnStop } from '../kernel/types.js';
|
|
3
|
+
import type { TranscriptBlock } from './types.js';
|
|
4
|
+
/** The stops that end a reply short of a whole answer. Each is worded by its `stop.<kind>` label. */
|
|
5
|
+
export declare const WORDED_STOP_KINDS: readonly ["cancelled", "interrupted", "length", "filtered", "provider_error", "stream_incomplete", "step_limit"];
|
|
6
|
+
/** One of {@linkcode WORDED_STOP_KINDS}. */
|
|
7
|
+
export type WordedStopKind = (typeof WORDED_STOP_KINDS)[number];
|
|
8
|
+
/**
|
|
9
|
+
* Why a turn ended short, in the person's words: its `stop.<kind>` label, the profile's own when it
|
|
10
|
+
* sets one. `undefined` when the turn ended whole, or when an error in `blocks` (the turn's
|
|
11
|
+
* transcript blocks) already says why.
|
|
12
|
+
*/
|
|
13
|
+
export declare function stopText(stop: TurnStop | undefined, blocks: readonly TranscriptBlock[], labels?: LabelOverrides): string | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { labelText } from '../guardrails/labels.js';
|
|
2
|
+
/** The stops that end a reply short of a whole answer. Each is worded by its `stop.<kind>` label. */
|
|
3
|
+
export const WORDED_STOP_KINDS = [
|
|
4
|
+
'cancelled',
|
|
5
|
+
'interrupted',
|
|
6
|
+
'length',
|
|
7
|
+
'filtered',
|
|
8
|
+
'provider_error',
|
|
9
|
+
'stream_incomplete',
|
|
10
|
+
'step_limit',
|
|
11
|
+
];
|
|
12
|
+
const WORDED = new Set(WORDED_STOP_KINDS);
|
|
13
|
+
function isWorded(kind) {
|
|
14
|
+
return WORDED.has(kind);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Why a turn ended short, in the person's words: its `stop.<kind>` label, the profile's own when it
|
|
18
|
+
* sets one. `undefined` when the turn ended whole, or when an error in `blocks` (the turn's
|
|
19
|
+
* transcript blocks) already says why.
|
|
20
|
+
*/
|
|
21
|
+
export function stopText(stop, blocks, labels) {
|
|
22
|
+
if (!stop || !isWorded(stop.kind))
|
|
23
|
+
return undefined;
|
|
24
|
+
if (blocks.some((block) => block.kind === 'error'))
|
|
25
|
+
return undefined;
|
|
26
|
+
const key = `stop.${stop.kind}`;
|
|
27
|
+
return labelText(key, {}, labels);
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ToolCallEvent, TurnEvent, TurnEventOf } from '../kernel/types.js';
|
|
2
|
+
import type { ToolCall } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The raw call comes first for every call (`turnEventSchema`); a phase for a call never made is a
|
|
5
|
+
* broken stream.
|
|
6
|
+
*/
|
|
7
|
+
declare function applyToolEvent(call: ToolCall | undefined, tool: ToolCallEvent): ToolCall;
|
|
8
|
+
/**
|
|
9
|
+
* A call the model is still writing, with the next piece of its draft added. The call that arrives
|
|
10
|
+
* whole replaces it (`applyToolEvent` builds the call from the request alone).
|
|
11
|
+
*/
|
|
12
|
+
declare function applyToolDraft(call: ToolCall | undefined, draft: TurnEventOf<'tool_draft'>): ToolCall;
|
|
13
|
+
/** Every call in `events`, in the order the model made them. */
|
|
14
|
+
declare function toolCallsOf(events: readonly TurnEvent[]): ToolCall[];
|
|
15
|
+
/** The arguments shown for approval, or the user's edit, or the model's original call. */
|
|
16
|
+
declare function toolCallRanWith(call: ToolCall): Record<string, unknown>;
|
|
17
|
+
/** A tool event that settles its call: the call completed or failed. */
|
|
18
|
+
type SettledToolCallEvent = TurnEventOf<'tool'> & {
|
|
19
|
+
tool: Extract<ToolCallEvent, {
|
|
20
|
+
phase: 'complete' | 'error';
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
/** True when the event is the complete or error event of the tool call with this id. */
|
|
24
|
+
declare function settlesToolCall(event: TurnEvent, callId: string): event is SettledToolCallEvent;
|
|
25
|
+
/**
|
|
26
|
+
* A call's arguments as far as the model has written them: the whole arguments once the call has
|
|
27
|
+
* arrived, else what `partialJsonObject` reads of its draft. For a preview: a field still being
|
|
28
|
+
* written is not its final value.
|
|
29
|
+
*/
|
|
30
|
+
declare function argumentsSoFar(call: ToolCall): Record<string, unknown>;
|
|
31
|
+
export type { SettledToolCallEvent };
|
|
32
|
+
export { applyToolDraft, applyToolEvent, argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf, };
|