@theoremjs/agents 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1264 -2
- package/esm/_dnt.polyfills.d.ts +66 -0
- package/esm/_dnt.polyfills.js +51 -0
- package/esm/mod.d.ts +65 -0
- package/esm/mod.js +42 -0
- package/esm/package.json +3 -0
- package/esm/src/cli/bin.d.ts +7 -0
- package/esm/src/cli/bin.js +9 -0
- package/esm/src/cli/commands/bench.d.ts +6 -0
- package/esm/src/cli/commands/bench.js +458 -0
- package/esm/src/cli/commands/egress-compile.d.ts +17 -0
- package/esm/src/cli/commands/egress-compile.js +25 -0
- package/esm/src/cli/commands/eval.d.ts +37 -0
- package/esm/src/cli/commands/eval.js +190 -0
- package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
- package/esm/src/cli/commands/fuzz-canary.js +202 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
- package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
- package/esm/src/cli/commands/profile.d.ts +2 -0
- package/esm/src/cli/commands/profile.js +80 -0
- package/esm/src/cli/commands/run.d.ts +13 -0
- package/esm/src/cli/commands/run.js +45 -0
- package/esm/src/cli/commands/test.d.ts +25 -0
- package/esm/src/cli/commands/test.js +143 -0
- package/esm/src/cli/event-log.d.ts +15 -0
- package/esm/src/cli/event-log.js +136 -0
- package/esm/src/cli/index.d.ts +10 -0
- package/esm/src/cli/index.js +267 -0
- package/esm/src/cli/matrix/fixtures.d.ts +10 -0
- package/esm/src/cli/matrix/fixtures.js +72 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
- package/esm/src/cli/matrix/synthesizer.js +103 -0
- package/esm/src/evals/attachments.d.ts +4 -0
- package/esm/src/evals/attachments.js +53 -0
- package/esm/src/evals/breakdown.d.ts +28 -0
- package/esm/src/evals/breakdown.js +68 -0
- package/esm/src/evals/graders/answer.d.ts +13 -0
- package/esm/src/evals/graders/answer.js +133 -0
- package/esm/src/evals/graders/code.d.ts +64 -0
- package/esm/src/evals/graders/code.js +205 -0
- package/esm/src/evals/graders/judge.d.ts +20 -0
- package/esm/src/evals/graders/judge.js +365 -0
- package/esm/src/evals/graders/latency.d.ts +5 -0
- package/esm/src/evals/graders/latency.js +81 -0
- package/esm/src/evals/graders/live.d.ts +11 -0
- package/esm/src/evals/graders/live.js +40 -0
- package/esm/src/evals/graders/media.d.ts +18 -0
- package/esm/src/evals/graders/media.js +92 -0
- package/esm/src/evals/graders/shared.d.ts +11 -0
- package/esm/src/evals/graders/shared.js +62 -0
- package/esm/src/evals/graders/transcript.d.ts +17 -0
- package/esm/src/evals/graders/transcript.js +200 -0
- package/esm/src/evals/mod.d.ts +42 -0
- package/esm/src/evals/mod.js +30 -0
- package/esm/src/evals/record.d.ts +35 -0
- package/esm/src/evals/record.js +105 -0
- package/esm/src/evals/rubrics/catalog.d.ts +148 -0
- package/esm/src/evals/rubrics/catalog.js +846 -0
- package/esm/src/evals/rubrics/mod.d.ts +24 -0
- package/esm/src/evals/rubrics/mod.js +55 -0
- package/esm/src/evals/rubrics/mustache.d.ts +23 -0
- package/esm/src/evals/rubrics/mustache.js +154 -0
- package/esm/src/evals/rubrics/types.d.ts +54 -0
- package/esm/src/evals/rubrics/types.js +74 -0
- package/esm/src/evals/run.d.ts +118 -0
- package/esm/src/evals/run.js +452 -0
- package/esm/src/evals/suite.d.ts +19 -0
- package/esm/src/evals/suite.js +92 -0
- package/esm/src/evals/summary.d.ts +32 -0
- package/esm/src/evals/summary.js +30 -0
- package/esm/src/evals/trial.d.ts +27 -0
- package/esm/src/evals/trial.js +158 -0
- package/esm/src/evals/types.d.ts +260 -0
- package/esm/src/evals/types.js +126 -0
- package/esm/src/evals/verdict.d.ts +18 -0
- package/esm/src/evals/verdict.js +45 -0
- package/esm/src/guardrails/canary-gate.d.ts +21 -0
- package/esm/src/guardrails/canary-gate.js +40 -0
- package/esm/src/guardrails/canary.d.ts +112 -0
- package/esm/src/guardrails/canary.js +901 -0
- package/esm/src/guardrails/compile-egress.d.ts +11 -0
- package/esm/src/guardrails/compile-egress.js +11 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +22 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +303 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +202 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +3 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +118 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +13 -0
- package/esm/src/guardrails/corpus/live-attacks.js +224 -0
- package/esm/src/guardrails/corpus/mod.d.ts +7 -0
- package/esm/src/guardrails/corpus/mod.js +4 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +23 -0
- package/esm/src/guardrails/corpus/strings.js +29 -0
- package/esm/src/guardrails/corpus/types.d.ts +32 -0
- package/esm/src/guardrails/corpus/types.js +1 -0
- package/esm/src/guardrails/egress-automata.d.ts +14 -0
- package/esm/src/guardrails/egress-automata.js +6059 -0
- package/esm/src/guardrails/egress-compiler.d.ts +33 -0
- package/esm/src/guardrails/egress-compiler.js +237 -0
- package/esm/src/guardrails/egress-patterns.d.ts +24 -0
- package/esm/src/guardrails/egress-patterns.js +32 -0
- package/esm/src/guardrails/egress-policy.d.ts +27 -0
- package/esm/src/guardrails/egress-policy.js +76 -0
- package/esm/src/guardrails/egress-rules.d.ts +54 -0
- package/esm/src/guardrails/egress-rules.js +49 -0
- package/esm/src/guardrails/egress-stream.d.ts +105 -0
- package/esm/src/guardrails/egress-stream.js +645 -0
- package/esm/src/guardrails/egress-urls.d.ts +83 -0
- package/esm/src/guardrails/egress-urls.js +917 -0
- package/esm/src/guardrails/egress.d.ts +106 -0
- package/esm/src/guardrails/egress.js +374 -0
- package/esm/src/guardrails/error.d.ts +26 -0
- package/esm/src/guardrails/error.js +91 -0
- package/esm/src/guardrails/event-schemas.d.ts +57 -0
- package/esm/src/guardrails/event-schemas.js +41 -0
- package/esm/src/guardrails/events.d.ts +9 -0
- package/esm/src/guardrails/events.js +42 -0
- package/esm/src/guardrails/hits.d.ts +8 -0
- package/esm/src/guardrails/hits.js +19 -0
- package/esm/src/guardrails/injection-patterns.d.ts +15 -0
- package/esm/src/guardrails/injection-patterns.js +94 -0
- package/esm/src/guardrails/injection.d.ts +14 -0
- package/esm/src/guardrails/injection.js +237 -0
- package/esm/src/guardrails/lexicon.d.ts +30 -0
- package/esm/src/guardrails/lexicon.js +478 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +54 -0
- package/esm/src/guardrails/live-outbound-gate.js +305 -0
- package/esm/src/guardrails/mod.d.ts +46 -0
- package/esm/src/guardrails/mod.js +29 -0
- package/esm/src/guardrails/network.d.ts +42 -0
- package/esm/src/guardrails/network.js +328 -0
- package/esm/src/guardrails/normalize.d.ts +6 -0
- package/esm/src/guardrails/normalize.js +132 -0
- package/esm/src/guardrails/policy.d.ts +19 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +69 -0
- package/esm/src/guardrails/progressive-yield.js +237 -0
- package/esm/src/guardrails/prompt-echo.d.ts +38 -0
- package/esm/src/guardrails/prompt-echo.js +225 -0
- package/esm/src/guardrails/quota.d.ts +20 -0
- package/esm/src/guardrails/quota.js +80 -0
- package/esm/src/guardrails/rules.d.ts +56 -0
- package/esm/src/guardrails/rules.js +54 -0
- package/esm/src/guardrails/sanitize.d.ts +23 -0
- package/esm/src/guardrails/sanitize.js +184 -0
- package/esm/src/guardrails/sensitive.d.ts +29 -0
- package/esm/src/guardrails/sensitive.js +113 -0
- package/esm/src/guardrails/serialize.d.ts +14 -0
- package/esm/src/guardrails/serialize.js +37 -0
- package/esm/src/guardrails/testing.d.ts +9 -0
- package/esm/src/guardrails/testing.js +8 -0
- package/esm/src/guardrails/theorem-error.d.ts +18 -0
- package/esm/src/guardrails/theorem-error.js +53 -0
- package/esm/src/guardrails/thought-guard.d.ts +55 -0
- package/esm/src/guardrails/thought-guard.js +464 -0
- package/esm/src/guardrails/tool-directives.d.ts +19 -0
- package/esm/src/guardrails/tool-directives.js +109 -0
- package/esm/src/guardrails/tool-result.d.ts +61 -0
- package/esm/src/guardrails/tool-result.js +248 -0
- package/esm/src/guardrails/types.d.ts +242 -0
- package/esm/src/guardrails/types.js +54 -0
- package/esm/src/host/client-turn.d.ts +9 -0
- package/esm/src/host/client-turn.js +38 -0
- package/esm/src/host/mint-trace.d.ts +28 -0
- package/esm/src/host/mint-trace.js +59 -0
- package/esm/src/host/mod.d.ts +13 -0
- package/esm/src/host/mod.js +11 -0
- package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
- package/esm/src/host/readStreamingJsonStringField.js +68 -0
- package/esm/src/host/reply.d.ts +7 -0
- package/esm/src/host/reply.js +35 -0
- package/esm/src/interface/blocks.d.ts +8 -0
- package/esm/src/interface/blocks.js +213 -0
- package/esm/src/interface/composer-actions.d.ts +20 -0
- package/esm/src/interface/composer-actions.js +31 -0
- package/esm/src/interface/draft.d.ts +14 -0
- package/esm/src/interface/draft.js +28 -0
- package/esm/src/interface/from-profile.d.ts +12 -0
- package/esm/src/interface/from-profile.js +144 -0
- package/esm/src/interface/history.d.ts +40 -0
- package/esm/src/interface/history.js +269 -0
- package/esm/src/interface/inputs.d.ts +10 -0
- package/esm/src/interface/inputs.js +64 -0
- package/esm/src/interface/mod.d.ts +31 -0
- package/esm/src/interface/mod.js +21 -0
- package/esm/src/interface/models.d.ts +19 -0
- package/esm/src/interface/models.js +45 -0
- package/esm/src/interface/pending.d.ts +48 -0
- package/esm/src/interface/pending.js +146 -0
- package/esm/src/interface/profile-interface.d.ts +4 -0
- package/esm/src/interface/profile-interface.js +223 -0
- package/esm/src/interface/session.d.ts +64 -0
- package/esm/src/interface/session.js +121 -0
- package/esm/src/interface/tool-calls.d.ts +20 -0
- package/esm/src/interface/tool-calls.js +73 -0
- package/esm/src/interface/tool-invoke.d.ts +4 -0
- package/esm/src/interface/tool-invoke.js +20 -0
- package/esm/src/interface/tool-media.d.ts +9 -0
- package/esm/src/interface/tool-media.js +112 -0
- package/esm/src/interface/types.d.ts +213 -0
- package/esm/src/interface/types.js +4 -0
- package/esm/src/kernel/auth/credential-source.d.ts +23 -0
- package/esm/src/kernel/auth/credential-source.js +11 -0
- package/esm/src/kernel/auth/crypto.d.ts +51 -0
- package/esm/src/kernel/auth/crypto.js +161 -0
- package/esm/src/kernel/auth/mod.d.ts +5 -0
- package/esm/src/kernel/auth/mod.js +5 -0
- package/esm/src/kernel/auth/oauth.d.ts +17 -0
- package/esm/src/kernel/auth/oauth.js +438 -0
- package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
- package/esm/src/kernel/auth/scope-refusal.js +8 -0
- package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
- package/esm/src/kernel/auth/typed-secret.js +23 -0
- package/esm/src/kernel/auth/types.d.ts +139 -0
- package/esm/src/kernel/auth/types.js +1 -0
- package/esm/src/kernel/default-scope.d.ts +34 -0
- package/esm/src/kernel/default-scope.js +72 -0
- package/esm/src/kernel/engine/compaction.d.ts +70 -0
- package/esm/src/kernel/engine/compaction.js +202 -0
- package/esm/src/kernel/engine/decision.d.ts +41 -0
- package/esm/src/kernel/engine/decision.js +412 -0
- package/esm/src/kernel/engine/hash.d.ts +6 -0
- package/esm/src/kernel/engine/hash.js +22 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +19 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +9 -0
- package/esm/src/kernel/engine/live-ingress.js +37 -0
- package/esm/src/kernel/engine/media-probe/audio.d.ts +7 -0
- package/esm/src/kernel/engine/media-probe/audio.js +342 -0
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +6 -0
- package/esm/src/kernel/engine/media-probe/bytes.js +26 -0
- package/esm/src/kernel/engine/media-probe/image.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/image.js +171 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +19 -0
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +48 -0
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +35 -0
- package/esm/src/kernel/engine/media-probe/matroska.js +226 -0
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +22 -0
- package/esm/src/kernel/engine/media-probe/mp4.js +279 -0
- package/esm/src/kernel/engine/media-probe/opus.d.ts +4 -0
- package/esm/src/kernel/engine/media-probe/opus.js +23 -0
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +5 -0
- package/esm/src/kernel/engine/media-probe/pdf.js +117 -0
- package/esm/src/kernel/engine/media-probe/video.d.ts +15 -0
- package/esm/src/kernel/engine/media-probe/video.js +49 -0
- package/esm/src/kernel/engine/record.d.ts +3 -0
- package/esm/src/kernel/engine/record.js +11 -0
- package/esm/src/kernel/engine/repair.d.ts +7 -0
- package/esm/src/kernel/engine/repair.js +36 -0
- package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
- package/esm/src/kernel/engine/runner/gates.js +322 -0
- package/esm/src/kernel/engine/runner/mod.d.ts +15 -0
- package/esm/src/kernel/engine/runner/mod.js +574 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +14 -0
- package/esm/src/kernel/engine/runner/schema-validation.js +105 -0
- package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
- package/esm/src/kernel/engine/runner/stages.js +48 -0
- package/esm/src/kernel/engine/runner/state.d.ts +76 -0
- package/esm/src/kernel/engine/runner/state.js +40 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
- package/esm/src/kernel/engine/runner/steps.js +360 -0
- package/esm/src/kernel/engine/runner/stream.d.ts +40 -0
- package/esm/src/kernel/engine/runner/stream.js +225 -0
- package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
- package/esm/src/kernel/engine/runner/usage.js +150 -0
- package/esm/src/kernel/engine/session/mod.d.ts +31 -0
- package/esm/src/kernel/engine/session/mod.js +951 -0
- package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
- package/esm/src/kernel/engine/session/session-trace.js +489 -0
- package/esm/src/kernel/engine/token-estimate.d.ts +77 -0
- package/esm/src/kernel/engine/token-estimate.js +218 -0
- package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
- package/esm/src/kernel/engine/tool-trace.js +131 -0
- package/esm/src/kernel/engine/tree.d.ts +2 -0
- package/esm/src/kernel/engine/tree.js +17 -0
- package/esm/src/kernel/engine/turn-trace.d.ts +118 -0
- package/esm/src/kernel/engine/turn-trace.js +863 -0
- package/esm/src/kernel/engine/usage.d.ts +30 -0
- package/esm/src/kernel/engine/usage.js +134 -0
- package/esm/src/kernel/interaction-parts.d.ts +10 -0
- package/esm/src/kernel/interaction-parts.js +22 -0
- package/esm/src/kernel/mod.d.ts +47 -0
- package/esm/src/kernel/mod.js +30 -0
- package/esm/src/kernel/profile-graph.d.ts +140 -0
- package/esm/src/kernel/profile-graph.js +151 -0
- package/esm/src/kernel/profile-presence.d.ts +9 -0
- package/esm/src/kernel/profile-presence.js +143 -0
- package/esm/src/kernel/profile-scope.d.ts +36 -0
- package/esm/src/kernel/profile-scope.js +262 -0
- package/esm/src/kernel/registry/attachments.d.ts +35 -0
- package/esm/src/kernel/registry/attachments.js +211 -0
- package/esm/src/kernel/registry/catalog.d.ts +19 -0
- package/esm/src/kernel/registry/catalog.js +78 -0
- package/esm/src/kernel/registry/ingress.d.ts +8 -0
- package/esm/src/kernel/registry/ingress.js +134 -0
- package/esm/src/kernel/registry/kernel-registry.d.ts +12 -0
- package/esm/src/kernel/registry/kernel-registry.js +8 -0
- package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
- package/esm/src/kernel/registry/profile-outputs.js +7 -0
- package/esm/src/kernel/registry/profiles.d.ts +92 -0
- package/esm/src/kernel/registry/profiles.js +698 -0
- package/esm/src/kernel/registry/provider-request.d.ts +6 -0
- package/esm/src/kernel/registry/provider-request.js +42 -0
- package/esm/src/kernel/registry/resolve.d.ts +14 -0
- package/esm/src/kernel/registry/resolve.js +237 -0
- package/esm/src/kernel/registry/schemas.d.ts +9 -0
- package/esm/src/kernel/registry/schemas.js +25 -0
- package/esm/src/kernel/registry/sole-model.d.ts +2 -0
- package/esm/src/kernel/registry/sole-model.js +4 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
- package/esm/src/kernel/registry/system-prompt.js +33 -0
- package/esm/src/kernel/registry/system-role.d.ts +3 -0
- package/esm/src/kernel/registry/system-role.js +9 -0
- package/esm/src/kernel/registry/vault.d.ts +13 -0
- package/esm/src/kernel/registry/vault.js +14 -0
- package/esm/src/kernel/schema.d.ts +172 -0
- package/esm/src/kernel/schema.js +653 -0
- package/esm/src/kernel/scope.d.ts +22 -0
- package/esm/src/kernel/scope.js +25 -0
- package/esm/src/kernel/stages.d.ts +141 -0
- package/esm/src/kernel/stages.js +388 -0
- package/esm/src/kernel/stop.d.ts +93 -0
- package/esm/src/kernel/stop.js +125 -0
- package/esm/src/kernel/system-parts.d.ts +26 -0
- package/esm/src/kernel/system-parts.js +98 -0
- package/esm/src/kernel/tools/activity-label.d.ts +16 -0
- package/esm/src/kernel/tools/activity-label.js +209 -0
- package/esm/src/kernel/tools/events.d.ts +51 -0
- package/esm/src/kernel/tools/events.js +149 -0
- package/esm/src/kernel/tools/execute.d.ts +64 -0
- package/esm/src/kernel/tools/execute.js +801 -0
- package/esm/src/kernel/tools/gate-answer.d.ts +50 -0
- package/esm/src/kernel/tools/gate-answer.js +54 -0
- package/esm/src/kernel/tools/harness.d.ts +16 -0
- package/esm/src/kernel/tools/harness.js +42 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +129 -0
- package/esm/src/kernel/tools/mcp-sessions.d.ts +20 -0
- package/esm/src/kernel/tools/mcp-sessions.js +64 -0
- package/esm/src/kernel/tools/mod.d.ts +9 -0
- package/esm/src/kernel/tools/mod.js +6 -0
- package/esm/src/kernel/tools/model-text.d.ts +11 -0
- package/esm/src/kernel/tools/model-text.js +25 -0
- package/esm/src/kernel/tools/permission.d.ts +6 -0
- package/esm/src/kernel/tools/permission.js +38 -0
- package/esm/src/kernel/tools/project.d.ts +8 -0
- package/esm/src/kernel/tools/project.js +25 -0
- package/esm/src/kernel/tools/registry.d.ts +20 -0
- package/esm/src/kernel/tools/registry.js +84 -0
- package/esm/src/kernel/tools/remote.d.ts +110 -0
- package/esm/src/kernel/tools/remote.js +998 -0
- package/esm/src/kernel/tools/resolve.d.ts +28 -0
- package/esm/src/kernel/tools/resolve.js +259 -0
- package/esm/src/kernel/tools/schema.d.ts +10 -0
- package/esm/src/kernel/tools/schema.js +174 -0
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +18 -0
- package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
- package/esm/src/kernel/tools/stage-run.d.ts +93 -0
- package/esm/src/kernel/tools/stage-run.js +140 -0
- package/esm/src/kernel/tools/types.d.ts +287 -0
- package/esm/src/kernel/tools/types.js +1 -0
- package/esm/src/kernel/turn-events.d.ts +599 -0
- package/esm/src/kernel/turn-events.js +425 -0
- package/esm/src/kernel/types.d.ts +884 -0
- package/esm/src/kernel/types.js +1 -0
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +13 -0
- package/esm/src/kernel/util/exact-type.d.ts +31 -0
- package/esm/src/kernel/util/exact-type.js +1 -0
- package/esm/src/kernel/util/find-last.d.ts +3 -0
- package/esm/src/kernel/util/find-last.js +9 -0
- package/esm/src/kernel/util/mime.d.ts +2 -0
- package/esm/src/kernel/util/mime.js +4 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +3 -0
- package/esm/src/observability/destinations.d.ts +9 -0
- package/esm/src/observability/destinations.js +38 -0
- package/esm/src/observability/jsonl.d.ts +18 -0
- package/esm/src/observability/jsonl.js +117 -0
- package/esm/src/observability/mod.d.ts +22 -0
- package/esm/src/observability/mod.js +16 -0
- package/esm/src/observability/openinference.d.ts +11 -0
- package/esm/src/observability/openinference.js +205 -0
- package/esm/src/observability/otlp.d.ts +68 -0
- package/esm/src/observability/otlp.js +98 -0
- package/esm/src/observability/phoenix.d.ts +29 -0
- package/esm/src/observability/phoenix.js +71 -0
- package/esm/src/observability/policy.d.ts +14 -0
- package/esm/src/observability/policy.js +69 -0
- package/esm/src/observability/resolve-policy.d.ts +8 -0
- package/esm/src/observability/resolve-policy.js +58 -0
- package/esm/src/observability/spans.d.ts +16 -0
- package/esm/src/observability/spans.js +56 -0
- package/esm/src/observability/trace-catalog.d.ts +111 -0
- package/esm/src/observability/trace-catalog.js +865 -0
- package/esm/src/observability/trace-record.d.ts +23 -0
- package/esm/src/observability/trace-record.js +223 -0
- package/esm/src/observability/trace-schema.d.ts +54 -0
- package/esm/src/observability/trace-schema.js +59 -0
- package/esm/src/observability/trace-sink.d.ts +13 -0
- package/esm/src/observability/trace-sink.js +3 -0
- package/esm/src/observability/trace-span.d.ts +92 -0
- package/esm/src/observability/trace-span.js +199 -0
- package/esm/src/observability/trace.d.ts +11 -0
- package/esm/src/observability/trace.js +35 -0
- package/esm/src/observability/types.d.ts +85 -0
- package/esm/src/observability/types.js +3 -0
- package/esm/src/presets/google/speech-voices.d.ts +8 -0
- package/esm/src/presets/google/speech-voices.js +38 -0
- package/esm/src/presets/google-limits.d.ts +12 -0
- package/esm/src/presets/google-limits.js +18 -0
- package/esm/src/presets/google.d.ts +104 -0
- package/esm/src/presets/google.js +188 -0
- package/esm/src/presets/mod.d.ts +10 -0
- package/esm/src/presets/mod.js +9 -0
- package/esm/src/presets/openrouter.d.ts +13 -0
- package/esm/src/presets/openrouter.js +13 -0
- package/esm/src/presets/typesafe.d.ts +2 -0
- package/esm/src/presets/typesafe.js +2 -0
- package/esm/src/providers/create-provider.d.ts +21 -0
- package/esm/src/providers/create-provider.js +90 -0
- package/esm/src/providers/decision/usage.d.ts +3 -0
- package/esm/src/providers/decision/usage.js +25 -0
- package/esm/src/providers/google/api-error.d.ts +8 -0
- package/esm/src/providers/google/api-error.js +123 -0
- package/esm/src/providers/google/grounding.d.ts +5 -0
- package/esm/src/providers/google/grounding.js +226 -0
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +263 -0
- package/esm/src/providers/google/interactions/mod.d.ts +2 -0
- package/esm/src/providers/google/interactions/mod.js +2 -0
- package/esm/src/providers/google/interactions/steps.d.ts +12 -0
- package/esm/src/providers/google/interactions/steps.js +200 -0
- package/esm/src/providers/google/interactions/stream.d.ts +24 -0
- package/esm/src/providers/google/interactions/stream.js +297 -0
- package/esm/src/providers/google/keys.d.ts +20 -0
- package/esm/src/providers/google/keys.js +87 -0
- package/esm/src/providers/google/live/framing.d.ts +51 -0
- package/esm/src/providers/google/live/framing.js +597 -0
- package/esm/src/providers/google/live/mod.d.ts +7 -0
- package/esm/src/providers/google/live/mod.js +7 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +1 -0
- package/esm/src/providers/google/live/openapi-schema.js +42 -0
- package/esm/src/providers/google/live/session.d.ts +14 -0
- package/esm/src/providers/google/live/session.js +150 -0
- package/esm/src/providers/google/live/stream.d.ts +51 -0
- package/esm/src/providers/google/live/stream.js +263 -0
- package/esm/src/providers/google/thinking.d.ts +3 -0
- package/esm/src/providers/google/thinking.js +8 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/google/usage.d.ts +7 -0
- package/esm/src/providers/google/usage.js +49 -0
- package/esm/src/providers/local/local.d.ts +12 -0
- package/esm/src/providers/local/local.js +186 -0
- package/esm/src/providers/local/mod.d.ts +8 -0
- package/esm/src/providers/local/mod.js +8 -0
- package/esm/src/providers/mod.d.ts +11 -0
- package/esm/src/providers/mod.js +7 -0
- package/esm/src/providers/openrouter/cache-control.d.ts +5 -0
- package/esm/src/providers/openrouter/cache-control.js +4 -0
- package/esm/src/providers/openrouter/chat.d.ts +64 -0
- package/esm/src/providers/openrouter/chat.js +490 -0
- package/esm/src/providers/openrouter/image.d.ts +24 -0
- package/esm/src/providers/openrouter/image.js +187 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
- package/esm/src/providers/openrouter/openai/compat.js +162 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +10 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +99 -0
- package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
- package/esm/src/providers/openrouter/openai/usage.js +56 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +3 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +8 -0
- package/esm/src/providers/openrouter/speech.d.ts +18 -0
- package/esm/src/providers/openrouter/speech.js +109 -0
- package/esm/src/providers/probe.d.ts +5 -0
- package/esm/src/providers/probe.js +15 -0
- package/esm/src/providers/shared/builtin-wire.d.ts +4 -0
- package/esm/src/providers/shared/builtin-wire.js +9 -0
- package/esm/src/providers/shared/pcm.d.ts +14 -0
- package/esm/src/providers/shared/pcm.js +78 -0
- package/esm/src/providers/shared/response-identity.d.ts +11 -0
- package/esm/src/providers/shared/response-identity.js +12 -0
- package/esm/src/providers/shared/sse.d.ts +10 -0
- package/esm/src/providers/shared/sse.js +79 -0
- package/esm/src/providers/shared/structured-output.d.ts +4 -0
- package/esm/src/providers/shared/structured-output.js +11 -0
- package/esm/src/providers/shared/tool-args.d.ts +25 -0
- package/esm/src/providers/shared/tool-args.js +84 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
- package/esm/src/providers/shared/upstream-tap.js +85 -0
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/shared/upstream-tape.js +88 -0
- package/esm/src/providers/shared/vault.d.ts +13 -0
- package/esm/src/providers/shared/vault.js +41 -0
- package/esm/src/providers/types.d.ts +19 -0
- package/esm/src/providers/types.js +1 -0
- package/esm/src/surface/formats.d.ts +28 -0
- package/esm/src/surface/formats.js +139 -0
- package/esm/src/surface/mod.d.ts +14 -0
- package/esm/src/surface/mod.js +10 -0
- package/esm/src/surface/runtime.d.ts +40 -0
- package/esm/src/surface/runtime.js +439 -0
- package/esm/src/surface/tools.d.ts +15 -0
- package/esm/src/surface/tools.js +80 -0
- package/esm/src/surface/types.d.ts +104 -0
- package/esm/src/surface/types.js +4 -0
- package/package.json +108 -4
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// Each type is paired with a zod schema checked against it (`Equals`), so a field in one and
|
|
2
|
+
// not the other fails the build. Schemas are plain `z.object`, never `.strict()`: an unlisted
|
|
3
|
+
// field is dropped. An unmapped provider step is `evidence` of kind `provider_step`.
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { errorCopiesSchema, errorKindSchema, guardrailEventSchema, } from '../guardrails/event-schemas.js';
|
|
6
|
+
import { AWAITING_USER_INPUT_STATUS, COMPACTION_METERS, COMPACTION_OUTCOMES, MEDIA_INPUT_KIND_VALUES, PROVIDERS, STAGE_APPLY_WARNING_CODES, TOOL_AUTH_TYPES, TOOL_PERMISSION, TURN_STAGES, TURN_STOP_KINDS, } from './schema.js';
|
|
7
|
+
const jsonObject = z.record(z.string(), z.unknown());
|
|
8
|
+
const nonEmptyText = z.string().trim().min(1);
|
|
9
|
+
const interactionTextPart = z.object({ type: z.literal('text'), text: z.string() });
|
|
10
|
+
true;
|
|
11
|
+
const interactionMediaPart = z.object({
|
|
12
|
+
type: z.enum(MEDIA_INPUT_KIND_VALUES),
|
|
13
|
+
mimeType: z.string(),
|
|
14
|
+
data: z.string(),
|
|
15
|
+
});
|
|
16
|
+
true;
|
|
17
|
+
const interactionMediaRefPart = z.object({
|
|
18
|
+
type: z.enum(MEDIA_INPUT_KIND_VALUES),
|
|
19
|
+
mimeType: z.string(),
|
|
20
|
+
uri: z.string(),
|
|
21
|
+
});
|
|
22
|
+
true;
|
|
23
|
+
const interactionPart = z.union([
|
|
24
|
+
interactionTextPart,
|
|
25
|
+
interactionMediaPart,
|
|
26
|
+
interactionMediaRefPart,
|
|
27
|
+
]);
|
|
28
|
+
true;
|
|
29
|
+
const turnHistoryMessage = z.object({
|
|
30
|
+
role: z.enum(['system', 'user', 'assistant', 'tool']),
|
|
31
|
+
content: z.string().optional(),
|
|
32
|
+
parts: z.array(interactionPart).optional(),
|
|
33
|
+
tool_calls: z
|
|
34
|
+
.array(z.object({
|
|
35
|
+
id: z.string(),
|
|
36
|
+
type: z.literal('function'),
|
|
37
|
+
function: z.object({ name: z.string(), arguments: z.string() }),
|
|
38
|
+
thoughtSignature: z.string().optional(),
|
|
39
|
+
}))
|
|
40
|
+
.optional(),
|
|
41
|
+
tool_call_id: z.string().optional(),
|
|
42
|
+
name: z.string().optional(),
|
|
43
|
+
metadata: jsonObject.optional(),
|
|
44
|
+
});
|
|
45
|
+
true;
|
|
46
|
+
export const turnHistoryMessageSchema = turnHistoryMessage;
|
|
47
|
+
const turnStop = z.object({ kind: z.enum(TURN_STOP_KINDS), native: z.string().optional() });
|
|
48
|
+
true;
|
|
49
|
+
const TURN_TOKEN_SIDES = ['input', 'output'];
|
|
50
|
+
const turnCost = z.object({
|
|
51
|
+
usd: z.number(),
|
|
52
|
+
upstreamUsd: z.number().optional(),
|
|
53
|
+
partial: z.literal(true).optional(),
|
|
54
|
+
});
|
|
55
|
+
true;
|
|
56
|
+
const turnGroundingCount = z.object({
|
|
57
|
+
type: z.string(),
|
|
58
|
+
count: z.number(),
|
|
59
|
+
searchQueryCount: z.number().optional(),
|
|
60
|
+
});
|
|
61
|
+
true;
|
|
62
|
+
const turnTokens = z.object({
|
|
63
|
+
input: z.number(),
|
|
64
|
+
output: z.number(),
|
|
65
|
+
thinking: z.number().optional(),
|
|
66
|
+
toolUse: z.number().optional(),
|
|
67
|
+
cached: z.number().optional(),
|
|
68
|
+
cacheWrite: z.number().optional(),
|
|
69
|
+
total: z.number(),
|
|
70
|
+
cost: turnCost.optional(),
|
|
71
|
+
estimated: z.array(z.enum(TURN_TOKEN_SIDES)).optional(),
|
|
72
|
+
unknownMedia: z
|
|
73
|
+
.object({ input: z.number().optional(), output: z.number().optional() })
|
|
74
|
+
.optional(),
|
|
75
|
+
byModality: z
|
|
76
|
+
.object({
|
|
77
|
+
input: z.record(z.string(), z.number()).optional(),
|
|
78
|
+
output: z.record(z.string(), z.number()).optional(),
|
|
79
|
+
})
|
|
80
|
+
.optional(),
|
|
81
|
+
grounding: z.array(turnGroundingCount).optional(),
|
|
82
|
+
});
|
|
83
|
+
true;
|
|
84
|
+
const turnResponse = z.object({ id: z.string().optional(), model: z.string().optional() });
|
|
85
|
+
true;
|
|
86
|
+
const SOURCE_TYPES = ['web', 'maps'];
|
|
87
|
+
const source = z.object({
|
|
88
|
+
title: z.string(),
|
|
89
|
+
uri: z.string(),
|
|
90
|
+
type: z.enum(SOURCE_TYPES),
|
|
91
|
+
placeId: z.string().optional(),
|
|
92
|
+
});
|
|
93
|
+
true;
|
|
94
|
+
export const sourceSchema = source;
|
|
95
|
+
const groundingEvent = z.object({
|
|
96
|
+
metadata: jsonObject.optional(),
|
|
97
|
+
chunks: z.array(z.unknown()).optional(),
|
|
98
|
+
searchHtml: z.string().optional(),
|
|
99
|
+
});
|
|
100
|
+
true;
|
|
101
|
+
const evidenceBase = {
|
|
102
|
+
provider: z.enum(PROVIDERS),
|
|
103
|
+
raw: jsonObject.optional(),
|
|
104
|
+
partial: z.boolean().optional(),
|
|
105
|
+
};
|
|
106
|
+
const providerEvidence = z.discriminatedUnion('kind', [
|
|
107
|
+
z.object({
|
|
108
|
+
...evidenceBase,
|
|
109
|
+
kind: z.literal('code_execution_call'),
|
|
110
|
+
code: z.string(),
|
|
111
|
+
language: z.string().optional(),
|
|
112
|
+
id: z.string(),
|
|
113
|
+
}),
|
|
114
|
+
z.object({
|
|
115
|
+
...evidenceBase,
|
|
116
|
+
kind: z.literal('code_execution_result'),
|
|
117
|
+
result: z.string().optional(),
|
|
118
|
+
isError: z.boolean().optional(),
|
|
119
|
+
callId: z.string().optional(),
|
|
120
|
+
}),
|
|
121
|
+
z.object({
|
|
122
|
+
...evidenceBase,
|
|
123
|
+
kind: z.enum(['input_transcription', 'output_transcription']),
|
|
124
|
+
interim: z.boolean().optional(),
|
|
125
|
+
}),
|
|
126
|
+
z.object({ ...evidenceBase, kind: z.enum(['voice_activity', 'url_context']) }),
|
|
127
|
+
z.object({ ...evidenceBase, kind: z.literal('session_resumption'), resumable: z.boolean() }),
|
|
128
|
+
z.object({ ...evidenceBase, kind: z.literal('provider_step'), step: z.string() }),
|
|
129
|
+
]);
|
|
130
|
+
true;
|
|
131
|
+
const sessionEnded = z.object({
|
|
132
|
+
cause: z.literal('go_away'),
|
|
133
|
+
code: z.number(),
|
|
134
|
+
closedAfterMs: z.number(),
|
|
135
|
+
errorKind: errorKindSchema.optional(),
|
|
136
|
+
});
|
|
137
|
+
true;
|
|
138
|
+
const sessionEvent = z.discriminatedUnion('kind', [
|
|
139
|
+
z.object({ kind: z.literal('closing_soon'), timeLeftMs: z.number().optional() }),
|
|
140
|
+
z.object({
|
|
141
|
+
kind: z.literal('ended'),
|
|
142
|
+
timeLeftMs: z.number().optional(),
|
|
143
|
+
ended: sessionEnded,
|
|
144
|
+
message: z.string(),
|
|
145
|
+
}),
|
|
146
|
+
z.object({ kind: z.enum(['waiting_for_input', 'turn_complete', 'working', 'idle']) }),
|
|
147
|
+
]);
|
|
148
|
+
true;
|
|
149
|
+
const toolFailure = z.object({
|
|
150
|
+
code: z.string(),
|
|
151
|
+
kind: errorKindSchema,
|
|
152
|
+
message: z.string(),
|
|
153
|
+
error: z.string().optional(),
|
|
154
|
+
details: z.unknown().optional(),
|
|
155
|
+
});
|
|
156
|
+
true;
|
|
157
|
+
const toolAuthChallenge = z.object({
|
|
158
|
+
slot: nonEmptyText,
|
|
159
|
+
authType: z.enum(TOOL_AUTH_TYPES),
|
|
160
|
+
service: nonEmptyText,
|
|
161
|
+
message: nonEmptyText,
|
|
162
|
+
authorizationUrl: z.string().optional(),
|
|
163
|
+
state: z.string().optional(),
|
|
164
|
+
issuer: z.string().optional(),
|
|
165
|
+
resource: z.string().optional(),
|
|
166
|
+
requiredScopes: z.array(nonEmptyText).optional(),
|
|
167
|
+
});
|
|
168
|
+
true;
|
|
169
|
+
const toolGateBase = {
|
|
170
|
+
tool: nonEmptyText,
|
|
171
|
+
permission: z.enum(TOOL_PERMISSION).optional(),
|
|
172
|
+
summary: nonEmptyText.optional(),
|
|
173
|
+
};
|
|
174
|
+
const toolGate = z.discriminatedUnion('kind', [
|
|
175
|
+
z.object({ ...toolGateBase, kind: z.enum(['confirmation', 'permission']) }),
|
|
176
|
+
z.object({ ...toolGateBase, kind: z.literal('auth'), authChallenge: toolAuthChallenge }),
|
|
177
|
+
]);
|
|
178
|
+
true;
|
|
179
|
+
export const toolGateSchema = toolGate;
|
|
180
|
+
const toolWarning = z.object({
|
|
181
|
+
code: z.string(),
|
|
182
|
+
message: z.string(),
|
|
183
|
+
severity: z.enum(['info', 'warning', 'error']).optional(),
|
|
184
|
+
});
|
|
185
|
+
true;
|
|
186
|
+
const toolTraceStep = z.object({
|
|
187
|
+
name: z.string(),
|
|
188
|
+
kind: z.string(),
|
|
189
|
+
status: z.string(),
|
|
190
|
+
inputs: jsonObject.optional(),
|
|
191
|
+
outputs: jsonObject.optional(),
|
|
192
|
+
});
|
|
193
|
+
true;
|
|
194
|
+
const awaitingBase = { status: z.literal(AWAITING_USER_INPUT_STATUS), prompt: nonEmptyText };
|
|
195
|
+
const awaitingUserInput = z.discriminatedUnion('kind', [
|
|
196
|
+
z.object({
|
|
197
|
+
...awaitingBase,
|
|
198
|
+
kind: z.enum(['confirm', 'text']),
|
|
199
|
+
options: z.array(nonEmptyText).optional(),
|
|
200
|
+
}),
|
|
201
|
+
z.object({ ...awaitingBase, kind: z.literal('choice'), options: z.array(nonEmptyText).min(1) }),
|
|
202
|
+
]);
|
|
203
|
+
true;
|
|
204
|
+
export const awaitingUserInputSchema = awaitingUserInput;
|
|
205
|
+
const wireFunctionTool = z.object({
|
|
206
|
+
type: z.literal('function'),
|
|
207
|
+
name: z.string(),
|
|
208
|
+
description: z.string(),
|
|
209
|
+
parameters: jsonObject,
|
|
210
|
+
});
|
|
211
|
+
true;
|
|
212
|
+
const turnToolSnapshot = z.object({
|
|
213
|
+
builtins: z.array(z.string()),
|
|
214
|
+
gated: z.array(z.string()),
|
|
215
|
+
visible: z.array(z.string()),
|
|
216
|
+
executable: z.array(z.string()),
|
|
217
|
+
path: z.string().optional(),
|
|
218
|
+
sessionPermissions: z.array(z.string()).optional(),
|
|
219
|
+
wire: z.array(wireFunctionTool),
|
|
220
|
+
});
|
|
221
|
+
true;
|
|
222
|
+
export const turnToolSnapshotSchema = turnToolSnapshot;
|
|
223
|
+
const toolEventBase = { name: z.string(), callId: z.string() };
|
|
224
|
+
const toolCallRequest = z.object({
|
|
225
|
+
...toolEventBase,
|
|
226
|
+
phase: z.undefined().optional(),
|
|
227
|
+
arguments: jsonObject,
|
|
228
|
+
thoughtSignature: z.string().min(1).optional(),
|
|
229
|
+
stepId: z.string().min(1).optional(),
|
|
230
|
+
});
|
|
231
|
+
true;
|
|
232
|
+
const toolPhaseBase = { ...toolEventBase, at: z.number() };
|
|
233
|
+
const toolPhaseEvent = z.discriminatedUnion('phase', [
|
|
234
|
+
z.object({
|
|
235
|
+
...toolPhaseBase,
|
|
236
|
+
phase: z.literal('running'),
|
|
237
|
+
edited: z.object({ from: jsonObject, to: jsonObject }).optional(),
|
|
238
|
+
activity: z.string().optional(),
|
|
239
|
+
}),
|
|
240
|
+
z.object({ ...toolPhaseBase, phase: z.literal('progress'), data: z.unknown() }),
|
|
241
|
+
z.object({ ...toolPhaseBase, phase: z.literal('trace'), step: toolTraceStep }),
|
|
242
|
+
z.object({ ...toolPhaseBase, phase: z.literal('artifact'), artifact: z.unknown() }),
|
|
243
|
+
z.object({ ...toolPhaseBase, phase: z.literal('warning'), warning: toolWarning }),
|
|
244
|
+
z.object({
|
|
245
|
+
...toolPhaseBase,
|
|
246
|
+
phase: z.literal('complete'),
|
|
247
|
+
output: z.unknown(),
|
|
248
|
+
awaiting: z.boolean().optional(),
|
|
249
|
+
readBack: z.string().optional(),
|
|
250
|
+
parts: z.array(interactionPart).optional(),
|
|
251
|
+
activityPast: z.string().optional(),
|
|
252
|
+
}),
|
|
253
|
+
z.object({
|
|
254
|
+
...toolPhaseBase,
|
|
255
|
+
phase: z.literal('gate'),
|
|
256
|
+
gate: toolGate,
|
|
257
|
+
readBack: z.string().optional(),
|
|
258
|
+
}),
|
|
259
|
+
z.object({
|
|
260
|
+
...toolPhaseBase,
|
|
261
|
+
phase: z.literal('error'),
|
|
262
|
+
failure: toolFailure,
|
|
263
|
+
readBack: z.string().optional(),
|
|
264
|
+
}),
|
|
265
|
+
z.object({ ...toolPhaseBase, phase: z.literal('cancel') }),
|
|
266
|
+
]);
|
|
267
|
+
true;
|
|
268
|
+
const toolCallEvent = z.union([toolPhaseEvent, toolCallRequest]);
|
|
269
|
+
true;
|
|
270
|
+
const stageApplyWarning = z.object({
|
|
271
|
+
code: z.enum(STAGE_APPLY_WARNING_CODES),
|
|
272
|
+
message: z.string(),
|
|
273
|
+
field: z.string(),
|
|
274
|
+
});
|
|
275
|
+
true;
|
|
276
|
+
const compactionSignal = z.object({
|
|
277
|
+
needed: z.boolean(),
|
|
278
|
+
meter: z.enum(COMPACTION_METERS),
|
|
279
|
+
tokens: z.number(),
|
|
280
|
+
unknownMedia: z.number(),
|
|
281
|
+
promptTokens: z.number().optional(),
|
|
282
|
+
promptTokensEstimated: z.boolean().optional(),
|
|
283
|
+
history: z.array(turnHistoryMessage),
|
|
284
|
+
});
|
|
285
|
+
true;
|
|
286
|
+
const compactionFailure = z.object({
|
|
287
|
+
stop: z.enum(TURN_STOP_KINDS).optional(),
|
|
288
|
+
error: errorKindSchema.optional(),
|
|
289
|
+
empty: z.literal(true).optional(),
|
|
290
|
+
unreadable: z.literal(true).optional(),
|
|
291
|
+
});
|
|
292
|
+
true;
|
|
293
|
+
const TOOL_SNAPSHOT_STOP_KINDS = [
|
|
294
|
+
'tool',
|
|
295
|
+
'gate',
|
|
296
|
+
];
|
|
297
|
+
export function turnDoneOf(done, tools) {
|
|
298
|
+
const { stop, ...rest } = done;
|
|
299
|
+
const { kind } = stop;
|
|
300
|
+
if (kind === 'tool' || kind === 'gate') {
|
|
301
|
+
return tools ? { type: 'done', ...rest, stop: { ...stop, kind }, tools } : undefined;
|
|
302
|
+
}
|
|
303
|
+
return { type: 'done', ...rest, stop: { ...stop, kind } };
|
|
304
|
+
}
|
|
305
|
+
const snapshotStopKind = z.enum(TOOL_SNAPSHOT_STOP_KINDS);
|
|
306
|
+
const otherStopKind = z.enum(TURN_STOP_KINDS).exclude(TOOL_SNAPSHOT_STOP_KINDS);
|
|
307
|
+
const doneBase = {
|
|
308
|
+
type: z.literal('done'),
|
|
309
|
+
tokens: turnTokens.optional(),
|
|
310
|
+
traceparent: z.string().optional(),
|
|
311
|
+
compaction: compactionSignal.optional(),
|
|
312
|
+
interrupted: z.boolean().optional(),
|
|
313
|
+
interactionId: z.string().optional(),
|
|
314
|
+
};
|
|
315
|
+
const doneEvent = z.union([
|
|
316
|
+
z.object({
|
|
317
|
+
...doneBase,
|
|
318
|
+
stop: z.object({ kind: snapshotStopKind, native: z.string().optional() }),
|
|
319
|
+
tools: turnToolSnapshot,
|
|
320
|
+
}),
|
|
321
|
+
z.object({
|
|
322
|
+
...doneBase,
|
|
323
|
+
stop: z.object({ kind: otherStopKind, native: z.string().optional() }),
|
|
324
|
+
tools: z.undefined().optional(),
|
|
325
|
+
}),
|
|
326
|
+
]);
|
|
327
|
+
/** Each kind's own schema: a wire parser checks a line against its kind's alone, so a failure names the field that broke. */
|
|
328
|
+
const TURN_EVENTS = {
|
|
329
|
+
text: z.object({ type: z.literal('text'), text: z.string() }),
|
|
330
|
+
thought: z.object({ type: z.literal('thought'), text: z.string() }),
|
|
331
|
+
structured: z.object({ type: z.literal('structured'), structured: z.unknown() }),
|
|
332
|
+
media: z.object({
|
|
333
|
+
type: z.literal('media'),
|
|
334
|
+
media: z.object({ mimeType: z.string(), data: z.string() }),
|
|
335
|
+
}),
|
|
336
|
+
grounding: z.object({ type: z.literal('grounding'), grounding: groundingEvent }),
|
|
337
|
+
citation: z.object({
|
|
338
|
+
type: z.literal('citation'),
|
|
339
|
+
sources: z.array(source),
|
|
340
|
+
callId: z.string().optional(),
|
|
341
|
+
}),
|
|
342
|
+
compaction: z.object({
|
|
343
|
+
type: z.literal('compaction'),
|
|
344
|
+
timing: z.literal('before'),
|
|
345
|
+
meter: z.enum(COMPACTION_METERS),
|
|
346
|
+
tokensBefore: z.number(),
|
|
347
|
+
unknownMedia: z.number(),
|
|
348
|
+
messagesBefore: z.number(),
|
|
349
|
+
messagesAfter: z.number(),
|
|
350
|
+
outcome: z.enum(COMPACTION_OUTCOMES),
|
|
351
|
+
history: z.array(turnHistoryMessage),
|
|
352
|
+
summary: z.string().optional(),
|
|
353
|
+
failure: compactionFailure.optional(),
|
|
354
|
+
droppedMedia: z.number(),
|
|
355
|
+
tokens: turnTokens.optional(),
|
|
356
|
+
}),
|
|
357
|
+
evidence: z.object({
|
|
358
|
+
type: z.literal('evidence'),
|
|
359
|
+
evidence: providerEvidence,
|
|
360
|
+
text: z.string().optional(),
|
|
361
|
+
sessionResumptionHandle: z.string().optional(),
|
|
362
|
+
}),
|
|
363
|
+
tokens: z.object({
|
|
364
|
+
type: z.literal('tokens'),
|
|
365
|
+
tokens: turnTokens,
|
|
366
|
+
interactionId: z.string().optional(),
|
|
367
|
+
}),
|
|
368
|
+
session: z.object({
|
|
369
|
+
type: z.literal('session'),
|
|
370
|
+
session: sessionEvent,
|
|
371
|
+
errorInternal: z.string().optional(),
|
|
372
|
+
}),
|
|
373
|
+
guardrail: z.object({ type: z.literal('guardrail'), guardrail: guardrailEventSchema }),
|
|
374
|
+
stage: z.object({
|
|
375
|
+
type: z.literal('stage'),
|
|
376
|
+
stage: z.enum(TURN_STAGES),
|
|
377
|
+
callId: z.string().optional(),
|
|
378
|
+
toolName: z.string().optional(),
|
|
379
|
+
callNotStarted: z.boolean().optional(),
|
|
380
|
+
awaiting: z.boolean().optional(),
|
|
381
|
+
gate: toolGate.optional(),
|
|
382
|
+
stop: turnStop.optional(),
|
|
383
|
+
stageWarnings: z.array(stageApplyWarning).optional(),
|
|
384
|
+
injected: z
|
|
385
|
+
.array(z.object({ id: z.string().regex(/\S/) }))
|
|
386
|
+
.min(1)
|
|
387
|
+
.optional(),
|
|
388
|
+
}),
|
|
389
|
+
tool: z.object({
|
|
390
|
+
type: z.literal('tool'),
|
|
391
|
+
tool: toolCallEvent,
|
|
392
|
+
errorInternal: z.string().optional(),
|
|
393
|
+
}),
|
|
394
|
+
error: z.object({
|
|
395
|
+
type: z.literal('error'),
|
|
396
|
+
errorKind: errorKindSchema,
|
|
397
|
+
error: z.string().optional(),
|
|
398
|
+
errorCopy: errorCopiesSchema.optional(),
|
|
399
|
+
errorInternal: z.string().optional(),
|
|
400
|
+
}),
|
|
401
|
+
done: doneEvent,
|
|
402
|
+
};
|
|
403
|
+
const turnEvent = z.union([
|
|
404
|
+
z.discriminatedUnion('type', [
|
|
405
|
+
TURN_EVENTS.text,
|
|
406
|
+
TURN_EVENTS.thought,
|
|
407
|
+
TURN_EVENTS.structured,
|
|
408
|
+
TURN_EVENTS.media,
|
|
409
|
+
TURN_EVENTS.grounding,
|
|
410
|
+
TURN_EVENTS.citation,
|
|
411
|
+
TURN_EVENTS.compaction,
|
|
412
|
+
TURN_EVENTS.evidence,
|
|
413
|
+
TURN_EVENTS.tokens,
|
|
414
|
+
TURN_EVENTS.session,
|
|
415
|
+
TURN_EVENTS.guardrail,
|
|
416
|
+
TURN_EVENTS.stage,
|
|
417
|
+
TURN_EVENTS.tool,
|
|
418
|
+
TURN_EVENTS.error,
|
|
419
|
+
]),
|
|
420
|
+
TURN_EVENTS.done,
|
|
421
|
+
]);
|
|
422
|
+
true;
|
|
423
|
+
export const turnEventSchema = turnEvent;
|
|
424
|
+
/** Every `TurnEvent` kind and its schema: a wire parser tells a kind it doesn't know from a malformed one it does. */
|
|
425
|
+
export const TURN_EVENT_SCHEMAS = TURN_EVENTS;
|