@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,543 @@
|
|
|
1
|
+
import { providerCheckpointSchema, providerWarningSchema, } from './checkpoint.js';
|
|
2
|
+
// invariant: Each type is paired with a zod schema checked against it (`Equals`), so a field in one and
|
|
3
|
+
// not the other fails the build. Schemas are plain `z.object`, never `.strict()`: an unlisted
|
|
4
|
+
// field is dropped. An unmapped provider step is `evidence` of kind `provider_step`.
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { errorCopiesSchema, errorKindSchema, guardrailEventSchema, } from '../guardrails/event-schemas.js';
|
|
7
|
+
import { jsonObjectSchema, jsonValueSchema } from './json.js';
|
|
8
|
+
import { AWAITING_USER_INPUT_STATUS, COMPACTION_METERS, COMPACTION_OUTCOMES, MEDIA_INPUT_KIND_VALUES, STAGE_APPLY_WARNING_CODES, TOOL_ACCESS, TOOL_AUTH_TYPES, TOOL_PERMISSION, TURN_STAGES, TURN_STOP_KINDS, } from './schema.js';
|
|
9
|
+
const jsonObject = z.record(z.string(), z.unknown());
|
|
10
|
+
const nonEmptyText = z.string().trim().min(1);
|
|
11
|
+
const interactionTextPart = z.object({ type: z.literal('text'), text: z.string() });
|
|
12
|
+
true;
|
|
13
|
+
const interactionMediaPart = z.object({
|
|
14
|
+
type: z.enum(MEDIA_INPUT_KIND_VALUES),
|
|
15
|
+
mimeType: z.string(),
|
|
16
|
+
data: z.string(),
|
|
17
|
+
});
|
|
18
|
+
true;
|
|
19
|
+
const interactionMediaRefPart = z.object({
|
|
20
|
+
type: z.enum(MEDIA_INPUT_KIND_VALUES),
|
|
21
|
+
mimeType: z.string(),
|
|
22
|
+
uri: z.string(),
|
|
23
|
+
});
|
|
24
|
+
true;
|
|
25
|
+
const interactionPart = z.union([
|
|
26
|
+
interactionTextPart,
|
|
27
|
+
interactionMediaPart,
|
|
28
|
+
interactionMediaRefPart,
|
|
29
|
+
]);
|
|
30
|
+
true;
|
|
31
|
+
export const interactionPartSchema = interactionPart;
|
|
32
|
+
const reasoningOrigin = z.object({
|
|
33
|
+
protocol: z.string().min(1),
|
|
34
|
+
provider: z.string().min(1).optional(),
|
|
35
|
+
apiId: z.string().min(1).optional(),
|
|
36
|
+
});
|
|
37
|
+
true;
|
|
38
|
+
export const reasoningPartSchema = z.object({
|
|
39
|
+
text: z.string().optional(),
|
|
40
|
+
data: jsonValueSchema,
|
|
41
|
+
origin: reasoningOrigin,
|
|
42
|
+
});
|
|
43
|
+
true;
|
|
44
|
+
const turnHistoryMessage = z.object({
|
|
45
|
+
role: z.enum(['system', 'user', 'assistant', 'tool']),
|
|
46
|
+
content: z.string().optional(),
|
|
47
|
+
parts: z.array(interactionPart).optional(),
|
|
48
|
+
tool_calls: z
|
|
49
|
+
.array(z.object({
|
|
50
|
+
id: z.string(),
|
|
51
|
+
type: z.literal('function'),
|
|
52
|
+
function: z.object({ name: z.string(), arguments: z.string() }),
|
|
53
|
+
}))
|
|
54
|
+
.optional(),
|
|
55
|
+
reasoning: z.array(reasoningPartSchema).optional(),
|
|
56
|
+
tool_call_id: z.string().optional(),
|
|
57
|
+
name: z.string().optional(),
|
|
58
|
+
metadata: jsonObject.optional(),
|
|
59
|
+
});
|
|
60
|
+
true;
|
|
61
|
+
/** The schema a history message parses against. */
|
|
62
|
+
export const turnHistoryMessageSchema = turnHistoryMessage;
|
|
63
|
+
export const turnStopSchema = z.object({
|
|
64
|
+
kind: z.enum(TURN_STOP_KINDS),
|
|
65
|
+
native: z.string().optional(),
|
|
66
|
+
});
|
|
67
|
+
const turnStop = turnStopSchema;
|
|
68
|
+
true;
|
|
69
|
+
const TURN_TOKEN_SIDES = ['input', 'output'];
|
|
70
|
+
const turnCost = z.object({
|
|
71
|
+
usd: z.number(),
|
|
72
|
+
upstreamUsd: z.number().optional(),
|
|
73
|
+
partial: z.literal(true).optional(),
|
|
74
|
+
});
|
|
75
|
+
true;
|
|
76
|
+
const turnGroundingCount = z.object({
|
|
77
|
+
type: z.string(),
|
|
78
|
+
count: z.number(),
|
|
79
|
+
searchQueryCount: z.number().optional(),
|
|
80
|
+
});
|
|
81
|
+
true;
|
|
82
|
+
const turnTokens = z.object({
|
|
83
|
+
input: z.number(),
|
|
84
|
+
output: z.number(),
|
|
85
|
+
thinking: z.number().optional(),
|
|
86
|
+
toolUse: z.number().optional(),
|
|
87
|
+
cached: z.number().optional(),
|
|
88
|
+
cacheWrite: z.number().optional(),
|
|
89
|
+
total: z.number(),
|
|
90
|
+
cost: turnCost.optional(),
|
|
91
|
+
estimated: z.array(z.enum(TURN_TOKEN_SIDES)).optional(),
|
|
92
|
+
unknownMedia: z
|
|
93
|
+
.object({ input: z.number().optional(), output: z.number().optional() })
|
|
94
|
+
.optional(),
|
|
95
|
+
byModality: z
|
|
96
|
+
.object({
|
|
97
|
+
input: z.record(z.string(), z.number()).optional(),
|
|
98
|
+
output: z.record(z.string(), z.number()).optional(),
|
|
99
|
+
})
|
|
100
|
+
.optional(),
|
|
101
|
+
grounding: z.array(turnGroundingCount).optional(),
|
|
102
|
+
});
|
|
103
|
+
true;
|
|
104
|
+
const turnResponse = z.object({ id: z.string().optional(), model: z.string().optional() });
|
|
105
|
+
true;
|
|
106
|
+
const SOURCE_TYPES = ['web', 'maps'];
|
|
107
|
+
const source = z.object({
|
|
108
|
+
title: z.string(),
|
|
109
|
+
uri: z.string(),
|
|
110
|
+
type: z.enum(SOURCE_TYPES),
|
|
111
|
+
placeId: z.string().optional(),
|
|
112
|
+
});
|
|
113
|
+
true;
|
|
114
|
+
export const sourceSchema = source;
|
|
115
|
+
const groundingEvent = z.object({
|
|
116
|
+
metadata: jsonObject.optional(),
|
|
117
|
+
chunks: z.array(z.unknown()).optional(),
|
|
118
|
+
searchHtml: z.string().optional(),
|
|
119
|
+
});
|
|
120
|
+
true;
|
|
121
|
+
const evidenceBase = {
|
|
122
|
+
provider: z.string().min(1),
|
|
123
|
+
raw: jsonObject.optional(),
|
|
124
|
+
partial: z.boolean().optional(),
|
|
125
|
+
};
|
|
126
|
+
const providerEvidence = z.discriminatedUnion('kind', [
|
|
127
|
+
z.object({
|
|
128
|
+
...evidenceBase,
|
|
129
|
+
kind: z.literal('code_execution_call'),
|
|
130
|
+
code: z.string(),
|
|
131
|
+
language: z.string().optional(),
|
|
132
|
+
id: z.string(),
|
|
133
|
+
}),
|
|
134
|
+
z.object({
|
|
135
|
+
...evidenceBase,
|
|
136
|
+
kind: z.literal('code_execution_result'),
|
|
137
|
+
result: z.string().optional(),
|
|
138
|
+
isError: z.boolean().optional(),
|
|
139
|
+
callId: z.string().optional(),
|
|
140
|
+
}),
|
|
141
|
+
z.object({
|
|
142
|
+
...evidenceBase,
|
|
143
|
+
kind: z.enum(['input_transcription', 'output_transcription']),
|
|
144
|
+
interim: z.boolean().optional(),
|
|
145
|
+
}),
|
|
146
|
+
z.object({ ...evidenceBase, kind: z.enum(['voice_activity', 'url_context']) }),
|
|
147
|
+
z.object({ ...evidenceBase, kind: z.literal('session_resumption'), resumable: z.boolean() }),
|
|
148
|
+
z.object({ ...evidenceBase, kind: z.literal('provider_step'), step: z.string() }),
|
|
149
|
+
]);
|
|
150
|
+
true;
|
|
151
|
+
const sessionEnded = z.object({
|
|
152
|
+
cause: z.literal('go_away'),
|
|
153
|
+
code: z.number(),
|
|
154
|
+
closedAfterMs: z.number(),
|
|
155
|
+
errorKind: errorKindSchema.optional(),
|
|
156
|
+
});
|
|
157
|
+
true;
|
|
158
|
+
const sessionEvent = z.discriminatedUnion('kind', [
|
|
159
|
+
z.object({ kind: z.literal('closing_soon'), timeLeftMs: z.number().optional() }),
|
|
160
|
+
z.object({
|
|
161
|
+
kind: z.literal('ended'),
|
|
162
|
+
timeLeftMs: z.number().optional(),
|
|
163
|
+
ended: sessionEnded,
|
|
164
|
+
message: z.string(),
|
|
165
|
+
}),
|
|
166
|
+
z.object({ kind: z.enum(['waiting_for_input', 'turn_complete', 'working', 'idle']) }),
|
|
167
|
+
]);
|
|
168
|
+
true;
|
|
169
|
+
const toolFailure = z.object({
|
|
170
|
+
code: z.string(),
|
|
171
|
+
kind: errorKindSchema,
|
|
172
|
+
message: z.string(),
|
|
173
|
+
error: z.string().optional(),
|
|
174
|
+
details: z.unknown().optional(),
|
|
175
|
+
});
|
|
176
|
+
true;
|
|
177
|
+
const toolAuthChallenge = z.object({
|
|
178
|
+
slot: nonEmptyText,
|
|
179
|
+
authType: z.enum(TOOL_AUTH_TYPES),
|
|
180
|
+
service: nonEmptyText,
|
|
181
|
+
message: nonEmptyText,
|
|
182
|
+
authorizationUrl: z.string().optional(),
|
|
183
|
+
state: z.string().optional(),
|
|
184
|
+
issuer: z.string().optional(),
|
|
185
|
+
resource: z.string().optional(),
|
|
186
|
+
requiredScopes: z.array(nonEmptyText).optional(),
|
|
187
|
+
});
|
|
188
|
+
true;
|
|
189
|
+
const toolGateBase = {
|
|
190
|
+
preparedArguments: z.record(z.string(), z.unknown()).optional(),
|
|
191
|
+
tool: nonEmptyText,
|
|
192
|
+
permission: z.enum(TOOL_PERMISSION).optional(),
|
|
193
|
+
summary: nonEmptyText.optional(),
|
|
194
|
+
request: nonEmptyText.optional(),
|
|
195
|
+
access: z.enum(TOOL_ACCESS).optional(),
|
|
196
|
+
};
|
|
197
|
+
const toolGate = z.discriminatedUnion('kind', [
|
|
198
|
+
z.object({ ...toolGateBase, kind: z.enum(['confirmation', 'permission', 'page']) }),
|
|
199
|
+
z.object({ ...toolGateBase, kind: z.literal('auth'), authChallenge: toolAuthChallenge }),
|
|
200
|
+
]);
|
|
201
|
+
true;
|
|
202
|
+
/** The schema a tool gate parses against. */
|
|
203
|
+
export const toolGateSchema = toolGate;
|
|
204
|
+
const toolWarning = z.object({
|
|
205
|
+
code: z.string(),
|
|
206
|
+
message: z.string(),
|
|
207
|
+
severity: z.enum(['info', 'warning', 'error']).optional(),
|
|
208
|
+
});
|
|
209
|
+
true;
|
|
210
|
+
const toolTraceStep = z.object({
|
|
211
|
+
name: z.string(),
|
|
212
|
+
kind: z.string(),
|
|
213
|
+
status: z.string(),
|
|
214
|
+
inputs: jsonObject.optional(),
|
|
215
|
+
outputs: jsonObject.optional(),
|
|
216
|
+
});
|
|
217
|
+
true;
|
|
218
|
+
const awaitingBase = { status: z.literal(AWAITING_USER_INPUT_STATUS), prompt: nonEmptyText };
|
|
219
|
+
const awaitingUserInput = z.discriminatedUnion('kind', [
|
|
220
|
+
z.object({
|
|
221
|
+
...awaitingBase,
|
|
222
|
+
kind: z.enum(['confirm', 'text']),
|
|
223
|
+
options: z.array(nonEmptyText).optional(),
|
|
224
|
+
}),
|
|
225
|
+
z.object({ ...awaitingBase, kind: z.literal('choice'), options: z.array(nonEmptyText).min(1) }),
|
|
226
|
+
]);
|
|
227
|
+
true;
|
|
228
|
+
/** The schema a pause for user input parses against. */
|
|
229
|
+
export const awaitingUserInputSchema = awaitingUserInput;
|
|
230
|
+
/** True when a tool output asks the turn to pause for the user. */
|
|
231
|
+
export function isAwaitingUserInput(output) {
|
|
232
|
+
return awaitingUserInputSchema.safeParse(output).success;
|
|
233
|
+
}
|
|
234
|
+
const wireFunctionTool = z.object({
|
|
235
|
+
type: z.literal('function'),
|
|
236
|
+
name: z.string(),
|
|
237
|
+
description: z.string(),
|
|
238
|
+
parameters: jsonObject,
|
|
239
|
+
});
|
|
240
|
+
true;
|
|
241
|
+
const turnToolSnapshot = z.object({
|
|
242
|
+
builtins: z.array(z.string()),
|
|
243
|
+
gated: z.array(z.string()),
|
|
244
|
+
visible: z.array(z.string()),
|
|
245
|
+
executable: z.array(z.string()),
|
|
246
|
+
path: z.string().optional(),
|
|
247
|
+
sessionPermissions: z.array(z.string()).optional(),
|
|
248
|
+
wire: z.array(wireFunctionTool),
|
|
249
|
+
});
|
|
250
|
+
true;
|
|
251
|
+
/** The schema a tool snapshot parses against. */
|
|
252
|
+
export const turnToolSnapshotSchema = turnToolSnapshot;
|
|
253
|
+
export const gateReferenceSchema = z.strictObject({
|
|
254
|
+
callId: z.string().min(1),
|
|
255
|
+
operationId: z.string().min(1).max(256),
|
|
256
|
+
});
|
|
257
|
+
const toolEventBase = { name: z.string(), callId: z.string() };
|
|
258
|
+
const toolCallRequest = z.object({
|
|
259
|
+
...toolEventBase,
|
|
260
|
+
phase: z.undefined().optional(),
|
|
261
|
+
arguments: jsonObject,
|
|
262
|
+
reasoning: z.array(reasoningPartSchema).optional(),
|
|
263
|
+
stepId: z.string().min(1).optional(),
|
|
264
|
+
stepCallCount: z.number().int().min(1).optional(),
|
|
265
|
+
});
|
|
266
|
+
true;
|
|
267
|
+
const toolPhaseBase = { ...toolEventBase, at: z.number() };
|
|
268
|
+
const toolPhaseEvent = z.discriminatedUnion('phase', [
|
|
269
|
+
z.object({
|
|
270
|
+
...toolPhaseBase,
|
|
271
|
+
phase: z.literal('running'),
|
|
272
|
+
edited: z.object({ from: jsonObject, to: jsonObject }).optional(),
|
|
273
|
+
activity: z.string().optional(),
|
|
274
|
+
}),
|
|
275
|
+
z.object({
|
|
276
|
+
...toolPhaseBase,
|
|
277
|
+
phase: z.literal('dispatch'),
|
|
278
|
+
grantId: z.string().min(1),
|
|
279
|
+
arguments: jsonObject,
|
|
280
|
+
}),
|
|
281
|
+
z.object({ ...toolPhaseBase, phase: z.literal('progress'), data: z.unknown() }),
|
|
282
|
+
z.object({ ...toolPhaseBase, phase: z.literal('draft'), text: z.string() }),
|
|
283
|
+
z.object({ ...toolPhaseBase, phase: z.literal('trace'), step: toolTraceStep }),
|
|
284
|
+
z.object({ ...toolPhaseBase, phase: z.literal('artifact'), artifact: z.unknown() }),
|
|
285
|
+
z.object({ ...toolPhaseBase, phase: z.literal('warning'), warning: toolWarning }),
|
|
286
|
+
z.object({
|
|
287
|
+
...toolPhaseBase,
|
|
288
|
+
phase: z.literal('complete'),
|
|
289
|
+
output: z.unknown(),
|
|
290
|
+
awaiting: z.boolean().optional(),
|
|
291
|
+
readBack: z.string().optional(),
|
|
292
|
+
parts: z.array(interactionPart).optional(),
|
|
293
|
+
activityPast: z.string().optional(),
|
|
294
|
+
tokens: turnTokens.optional(),
|
|
295
|
+
}),
|
|
296
|
+
z.object({
|
|
297
|
+
...toolPhaseBase,
|
|
298
|
+
phase: z.literal('gate'),
|
|
299
|
+
gate: toolGate,
|
|
300
|
+
readBack: z.string().optional(),
|
|
301
|
+
}),
|
|
302
|
+
z.object({
|
|
303
|
+
...toolPhaseBase,
|
|
304
|
+
phase: z.literal('error'),
|
|
305
|
+
failure: toolFailure,
|
|
306
|
+
readBack: z.string().optional(),
|
|
307
|
+
activityPast: z.string().optional(),
|
|
308
|
+
tokens: turnTokens.optional(),
|
|
309
|
+
}),
|
|
310
|
+
z.object({ ...toolPhaseBase, phase: z.literal('cancel') }),
|
|
311
|
+
]);
|
|
312
|
+
true;
|
|
313
|
+
const toolCallEvent = z
|
|
314
|
+
.union([toolPhaseEvent, toolCallRequest])
|
|
315
|
+
.and(z.object({ operationId: z.string().min(1).max(256).optional() }));
|
|
316
|
+
true;
|
|
317
|
+
const stageApplyWarning = z.object({
|
|
318
|
+
code: z.enum(STAGE_APPLY_WARNING_CODES),
|
|
319
|
+
message: z.string(),
|
|
320
|
+
field: z.string(),
|
|
321
|
+
});
|
|
322
|
+
true;
|
|
323
|
+
const compactionSignal = z.object({
|
|
324
|
+
needed: z.boolean(),
|
|
325
|
+
meter: z.enum(COMPACTION_METERS),
|
|
326
|
+
tokens: z.number(),
|
|
327
|
+
unknownMedia: z.number(),
|
|
328
|
+
promptTokens: z.number().optional(),
|
|
329
|
+
promptTokensEstimated: z.boolean().optional(),
|
|
330
|
+
history: z.array(turnHistoryMessage),
|
|
331
|
+
});
|
|
332
|
+
true;
|
|
333
|
+
const compactionFailure = z.object({
|
|
334
|
+
stop: z.enum(TURN_STOP_KINDS).optional(),
|
|
335
|
+
error: errorKindSchema.optional(),
|
|
336
|
+
empty: z.literal(true).optional(),
|
|
337
|
+
unreadable: z.literal(true).optional(),
|
|
338
|
+
});
|
|
339
|
+
true;
|
|
340
|
+
const TOOL_SNAPSHOT_STOP_KINDS = [
|
|
341
|
+
'tool',
|
|
342
|
+
'gate',
|
|
343
|
+
];
|
|
344
|
+
/** Builds the `done` event from a model call's end, or `undefined` when it carries no stop. */
|
|
345
|
+
export function turnDoneOf(done, tools) {
|
|
346
|
+
const { stop, ...rest } = done;
|
|
347
|
+
const { kind } = stop;
|
|
348
|
+
if (kind === 'tool' || kind === 'gate') {
|
|
349
|
+
return tools ? { type: 'done', ...rest, stop: { ...stop, kind }, tools } : undefined;
|
|
350
|
+
}
|
|
351
|
+
return { type: 'done', ...rest, stop: { ...stop, kind } };
|
|
352
|
+
}
|
|
353
|
+
const snapshotStopKind = z.enum(TOOL_SNAPSHOT_STOP_KINDS);
|
|
354
|
+
const otherStopKind = z.enum(TURN_STOP_KINDS).exclude(TOOL_SNAPSHOT_STOP_KINDS);
|
|
355
|
+
const doneBase = {
|
|
356
|
+
providerState: providerCheckpointSchema.optional(),
|
|
357
|
+
type: z.literal('done'),
|
|
358
|
+
tokens: turnTokens.optional(),
|
|
359
|
+
traceparent: z.string().optional(),
|
|
360
|
+
compaction: compactionSignal.optional(),
|
|
361
|
+
interrupted: z.boolean().optional(),
|
|
362
|
+
interactionId: z.string().optional(),
|
|
363
|
+
};
|
|
364
|
+
const doneEvent = z.union([
|
|
365
|
+
z.object({
|
|
366
|
+
...doneBase,
|
|
367
|
+
stop: z.object({ kind: snapshotStopKind, native: z.string().optional() }),
|
|
368
|
+
tools: turnToolSnapshot,
|
|
369
|
+
}),
|
|
370
|
+
z.object({
|
|
371
|
+
...doneBase,
|
|
372
|
+
stop: z.object({ kind: otherStopKind, native: z.string().optional() }),
|
|
373
|
+
tools: z.undefined().optional(),
|
|
374
|
+
}),
|
|
375
|
+
]);
|
|
376
|
+
/** Each kind's own schema: a wire parser checks a line against its kind's alone, so a failure names the field that broke. */
|
|
377
|
+
const TURN_EVENTS = {
|
|
378
|
+
provider_checkpoint: z.object({
|
|
379
|
+
type: z.literal('provider_checkpoint'),
|
|
380
|
+
providerState: providerCheckpointSchema,
|
|
381
|
+
history: z.array(turnHistoryMessageSchema).optional(),
|
|
382
|
+
}),
|
|
383
|
+
provider_warning: z.object({
|
|
384
|
+
type: z.literal('provider_warning'),
|
|
385
|
+
warning: providerWarningSchema,
|
|
386
|
+
}),
|
|
387
|
+
text: z.object({ type: z.literal('text'), text: z.string() }),
|
|
388
|
+
thought: z.object({ type: z.literal('thought'), text: z.string() }),
|
|
389
|
+
custom: z.object({
|
|
390
|
+
type: z.literal('custom'),
|
|
391
|
+
kind: z.string().min(1),
|
|
392
|
+
data: jsonObjectSchema,
|
|
393
|
+
}),
|
|
394
|
+
structured: z.object({
|
|
395
|
+
type: z.literal('structured'),
|
|
396
|
+
structured: z.unknown(),
|
|
397
|
+
removed: z
|
|
398
|
+
.array(z.object({ path: z.string(), reason: z.string(), item: z.unknown() }))
|
|
399
|
+
.optional(),
|
|
400
|
+
failed: z.array(z.object({ path: z.string(), error: z.string() })).optional(),
|
|
401
|
+
}),
|
|
402
|
+
structured_draft: z.object({
|
|
403
|
+
type: z.literal('structured_draft'),
|
|
404
|
+
text: z.string(),
|
|
405
|
+
}),
|
|
406
|
+
attempt: z.object({
|
|
407
|
+
type: z.literal('attempt'),
|
|
408
|
+
attempt: z.number().int().positive(),
|
|
409
|
+
reason: z.enum(['validation', 'egress']),
|
|
410
|
+
}),
|
|
411
|
+
media: z.object({
|
|
412
|
+
type: z.literal('media'),
|
|
413
|
+
media: z.object({ mimeType: z.string(), data: z.string() }),
|
|
414
|
+
}),
|
|
415
|
+
grounding: z.object({ type: z.literal('grounding'), grounding: groundingEvent }),
|
|
416
|
+
citation: z.object({
|
|
417
|
+
type: z.literal('citation'),
|
|
418
|
+
sources: z.array(source),
|
|
419
|
+
callId: z.string().optional(),
|
|
420
|
+
}),
|
|
421
|
+
compaction: z.object({
|
|
422
|
+
type: z.literal('compaction'),
|
|
423
|
+
timing: z.literal('before'),
|
|
424
|
+
meter: z.enum(COMPACTION_METERS),
|
|
425
|
+
tokensBefore: z.number(),
|
|
426
|
+
unknownMedia: z.number(),
|
|
427
|
+
messagesBefore: z.number(),
|
|
428
|
+
messagesAfter: z.number(),
|
|
429
|
+
outcome: z.enum(COMPACTION_OUTCOMES),
|
|
430
|
+
history: z.array(turnHistoryMessage),
|
|
431
|
+
summary: z.string().optional(),
|
|
432
|
+
failure: compactionFailure.optional(),
|
|
433
|
+
droppedMedia: z.number(),
|
|
434
|
+
tokens: turnTokens.optional(),
|
|
435
|
+
}),
|
|
436
|
+
evidence: z.object({
|
|
437
|
+
type: z.literal('evidence'),
|
|
438
|
+
evidence: providerEvidence,
|
|
439
|
+
text: z.string().optional(),
|
|
440
|
+
sessionResumptionHandle: z.string().optional(),
|
|
441
|
+
}),
|
|
442
|
+
tokens: z.object({
|
|
443
|
+
type: z.literal('tokens'),
|
|
444
|
+
tokens: turnTokens,
|
|
445
|
+
interactionId: z.string().optional(),
|
|
446
|
+
}),
|
|
447
|
+
session: z.object({
|
|
448
|
+
type: z.literal('session'),
|
|
449
|
+
session: sessionEvent,
|
|
450
|
+
errorInternal: z.string().optional(),
|
|
451
|
+
}),
|
|
452
|
+
guardrail: z.object({ type: z.literal('guardrail'), guardrail: guardrailEventSchema }),
|
|
453
|
+
stage: z.object({
|
|
454
|
+
type: z.literal('stage'),
|
|
455
|
+
stage: z.enum(TURN_STAGES),
|
|
456
|
+
callId: z.string().optional(),
|
|
457
|
+
toolName: z.string().optional(),
|
|
458
|
+
callNotStarted: z.boolean().optional(),
|
|
459
|
+
awaiting: z.boolean().optional(),
|
|
460
|
+
gate: toolGate.optional(),
|
|
461
|
+
stop: turnStop.optional(),
|
|
462
|
+
stageWarnings: z.array(stageApplyWarning).optional(),
|
|
463
|
+
injected: z
|
|
464
|
+
.array(z.object({ id: z.string().regex(/\S/) }))
|
|
465
|
+
.min(1)
|
|
466
|
+
.optional(),
|
|
467
|
+
}),
|
|
468
|
+
tool_draft: z.object({
|
|
469
|
+
type: z.literal('tool_draft'),
|
|
470
|
+
callId: z.string().min(1),
|
|
471
|
+
name: z.string(),
|
|
472
|
+
text: z.string(),
|
|
473
|
+
}),
|
|
474
|
+
tool: z.object({
|
|
475
|
+
type: z.literal('tool'),
|
|
476
|
+
tool: toolCallEvent,
|
|
477
|
+
errorInternal: z.string().optional(),
|
|
478
|
+
}),
|
|
479
|
+
error: z.object({
|
|
480
|
+
type: z.literal('error'),
|
|
481
|
+
errorKind: errorKindSchema,
|
|
482
|
+
error: z.string().optional(),
|
|
483
|
+
errorCopy: errorCopiesSchema.optional(),
|
|
484
|
+
errorInternal: z.string().optional(),
|
|
485
|
+
}),
|
|
486
|
+
done: doneEvent,
|
|
487
|
+
};
|
|
488
|
+
const turnEvent = z.union([
|
|
489
|
+
z.discriminatedUnion('type', [
|
|
490
|
+
TURN_EVENTS.provider_warning,
|
|
491
|
+
TURN_EVENTS.provider_checkpoint,
|
|
492
|
+
TURN_EVENTS.text,
|
|
493
|
+
TURN_EVENTS.thought,
|
|
494
|
+
TURN_EVENTS.custom,
|
|
495
|
+
TURN_EVENTS.structured,
|
|
496
|
+
TURN_EVENTS.structured_draft,
|
|
497
|
+
TURN_EVENTS.attempt,
|
|
498
|
+
TURN_EVENTS.media,
|
|
499
|
+
TURN_EVENTS.grounding,
|
|
500
|
+
TURN_EVENTS.citation,
|
|
501
|
+
TURN_EVENTS.compaction,
|
|
502
|
+
TURN_EVENTS.evidence,
|
|
503
|
+
TURN_EVENTS.tokens,
|
|
504
|
+
TURN_EVENTS.session,
|
|
505
|
+
TURN_EVENTS.guardrail,
|
|
506
|
+
TURN_EVENTS.stage,
|
|
507
|
+
TURN_EVENTS.tool_draft,
|
|
508
|
+
TURN_EVENTS.tool,
|
|
509
|
+
TURN_EVENTS.error,
|
|
510
|
+
]),
|
|
511
|
+
TURN_EVENTS.done,
|
|
512
|
+
]);
|
|
513
|
+
true;
|
|
514
|
+
/** The schema any turn event parses against. */
|
|
515
|
+
export const turnEventSchema = turnEvent;
|
|
516
|
+
/** Every `TurnEvent` kind and its schema: a wire parser tells a kind it doesn't know from a malformed one it does. */
|
|
517
|
+
export const TURN_EVENT_SCHEMAS = TURN_EVENTS;
|
|
518
|
+
/** Events that make up a reply, and that an `attempt` throws away. */
|
|
519
|
+
function isReply(event) {
|
|
520
|
+
return (event.type === 'text' ||
|
|
521
|
+
event.type === 'media' ||
|
|
522
|
+
event.type === 'structured' ||
|
|
523
|
+
event.type === 'structured_draft');
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* `events` without the replies a retry threw away: each `attempt` drops the text, media and
|
|
527
|
+
* structured output before it, back to the turn's start or its last `done`. Tool calls, thoughts
|
|
528
|
+
* and everything else stay, since they happened.
|
|
529
|
+
*/
|
|
530
|
+
export function keptReply(events) {
|
|
531
|
+
const kept = [];
|
|
532
|
+
let turnStart = 0;
|
|
533
|
+
for (const event of events) {
|
|
534
|
+
if (event.type === 'attempt') {
|
|
535
|
+
const before = kept.splice(turnStart);
|
|
536
|
+
kept.push(...before.filter((each) => !isReply(each)));
|
|
537
|
+
}
|
|
538
|
+
kept.push(event);
|
|
539
|
+
if (event.type === 'done')
|
|
540
|
+
turnStart = kept.length;
|
|
541
|
+
}
|
|
542
|
+
return kept;
|
|
543
|
+
}
|