@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,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional host-application helpers, not part of the turn kernel: HTTP reply status, cutout-trace
|
|
3
|
+
* flush, and live structured-output preview.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export type { ClientTurnOptions } from './client-turn.js';
|
|
9
|
+
export { forClient, forClientEvents } from './client-turn.js';
|
|
10
|
+
export type { CutoutTape } from './mint-trace.js';
|
|
11
|
+
export { flushMintTrace } from './mint-trace.js';
|
|
12
|
+
export { readStreamingJsonStringField } from './readStreamingJsonStringField.js';
|
|
13
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json, } from './reply.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional host-application helpers, not part of the turn kernel: HTTP reply status, cutout-trace
|
|
3
|
+
* flush, and live structured-output preview.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export { forClient, forClientEvents } from './client-turn.js';
|
|
9
|
+
export { flushMintTrace } from './mint-trace.js';
|
|
10
|
+
export { readStreamingJsonStringField } from './readStreamingJsonStringField.js';
|
|
11
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json, } from './reply.js';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const JSON_ESCAPES = {
|
|
2
|
+
n: '\n',
|
|
3
|
+
t: '\t',
|
|
4
|
+
r: '\r',
|
|
5
|
+
'"': '"',
|
|
6
|
+
'\\': '\\',
|
|
7
|
+
'/': '/',
|
|
8
|
+
};
|
|
9
|
+
function decodeEscapedChar(ch, jsonText, index) {
|
|
10
|
+
if (ch === 'u' && index + 4 < jsonText.length) {
|
|
11
|
+
const hex = jsonText.slice(index + 1, index + 5);
|
|
12
|
+
if (/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
13
|
+
return { text: String.fromCharCode(Number.parseInt(hex, 16)), next: index + 4 };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const mapped = JSON_ESCAPES[ch];
|
|
17
|
+
return { text: mapped ?? ch, next: index };
|
|
18
|
+
}
|
|
19
|
+
/** The buffer may lack a closing quote; any decoded prefix is returned for live preview. */
|
|
20
|
+
export function readStreamingJsonStringField(jsonText, key) {
|
|
21
|
+
const keyLiteral = JSON.stringify(key);
|
|
22
|
+
let keyAt = jsonText.indexOf(keyLiteral);
|
|
23
|
+
let i = -1;
|
|
24
|
+
while (keyAt >= 0) {
|
|
25
|
+
i = keyAt + keyLiteral.length;
|
|
26
|
+
while (/\s/.test(jsonText[i] ?? '')) {
|
|
27
|
+
i += 1;
|
|
28
|
+
}
|
|
29
|
+
if (jsonText[i] === ':') {
|
|
30
|
+
i += 1;
|
|
31
|
+
while (/\s/.test(jsonText[i] ?? '')) {
|
|
32
|
+
i += 1;
|
|
33
|
+
}
|
|
34
|
+
if (jsonText[i] === '"') {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
keyAt = jsonText.indexOf(keyLiteral, keyAt + keyLiteral.length);
|
|
39
|
+
}
|
|
40
|
+
if (keyAt < 0 || jsonText[i] !== '"') {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
i += 1;
|
|
44
|
+
let result = '';
|
|
45
|
+
let escaped = false;
|
|
46
|
+
while (i < jsonText.length) {
|
|
47
|
+
const ch = jsonText[i];
|
|
48
|
+
if (escaped) {
|
|
49
|
+
const decoded = decodeEscapedChar(ch, jsonText, i);
|
|
50
|
+
result += decoded.text;
|
|
51
|
+
i = decoded.next;
|
|
52
|
+
escaped = false;
|
|
53
|
+
i += 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (ch === '\\') {
|
|
57
|
+
escaped = true;
|
|
58
|
+
}
|
|
59
|
+
else if (ch === '"') {
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result += ch;
|
|
64
|
+
}
|
|
65
|
+
i += 1;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const HTTP_OK = 200;
|
|
2
|
+
declare const HTTP_NOT_FOUND = 404;
|
|
3
|
+
declare const HTTP_METHOD = 405;
|
|
4
|
+
declare const HTTP_BUSY = 429;
|
|
5
|
+
declare function json(status: number, body: unknown, cors: Record<string, string>): Response;
|
|
6
|
+
declare function caughtStatus(err: unknown): number;
|
|
7
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { errorKind } from '../guardrails/error.js';
|
|
2
|
+
const HTTP_OK = 200;
|
|
3
|
+
const HTTP_NOT_FOUND = 404;
|
|
4
|
+
const HTTP_METHOD = 405;
|
|
5
|
+
const HTTP_BUSY = 429;
|
|
6
|
+
const STATUS_BY_KIND = {
|
|
7
|
+
config: 500,
|
|
8
|
+
request: 400,
|
|
9
|
+
input: 422,
|
|
10
|
+
action: 403,
|
|
11
|
+
auth: 401,
|
|
12
|
+
rate_limit: HTTP_BUSY,
|
|
13
|
+
unsupported: 422,
|
|
14
|
+
unavailable: 503,
|
|
15
|
+
bad_response: 502,
|
|
16
|
+
network: 502,
|
|
17
|
+
timeout: 504,
|
|
18
|
+
safety: 422,
|
|
19
|
+
blocked: 403,
|
|
20
|
+
declined: 409,
|
|
21
|
+
failed: 502,
|
|
22
|
+
// Client closed request (nginx convention): the caller went away.
|
|
23
|
+
cancelled: 499,
|
|
24
|
+
internal: 500,
|
|
25
|
+
};
|
|
26
|
+
function json(status, body, cors) {
|
|
27
|
+
return new Response(JSON.stringify(body), {
|
|
28
|
+
status,
|
|
29
|
+
headers: { ...cors, 'Content-Type': 'application/json' },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function caughtStatus(err) {
|
|
33
|
+
return STATUS_BY_KIND[errorKind(err)];
|
|
34
|
+
}
|
|
35
|
+
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TurnEvent } from '../kernel/types.js';
|
|
2
|
+
import type { FoldTurnEventsOptions, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
3
|
+
declare function resetBlockIds(): void;
|
|
4
|
+
declare function buildUserTurnBlocks(draft: UserTurnDraft, idPrefix?: string): TranscriptBlock[];
|
|
5
|
+
/** Resets only the turn id sequence, so streaming refolds keep stable `turn-*` keys. */
|
|
6
|
+
declare function foldTurnEvents(events: readonly TurnEvent[], options?: FoldTurnEventsOptions): TranscriptBlock[];
|
|
7
|
+
declare function foldConversationTurn(draft: UserTurnDraft, assistantEvents: readonly TurnEvent[], options?: FoldTurnEventsOptions): TranscriptBlock[];
|
|
8
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { applyToolEvent } from './tool-calls.js';
|
|
2
|
+
import { collectPromotedMediaFromToolOutput } from './tool-media.js';
|
|
3
|
+
let turnBlockCounter = 0;
|
|
4
|
+
/**
|
|
5
|
+
* User block ids are random: a counter restarts wherever this module loads
|
|
6
|
+
* again (a hot reload, a second bundled copy) and would reuse an id already on
|
|
7
|
+
* screen. Turn block ids count from each fold so streaming refolds keep keys.
|
|
8
|
+
*/
|
|
9
|
+
function nextBlockId(prefix) {
|
|
10
|
+
if (prefix === 'user')
|
|
11
|
+
return `user-${globalThis.crypto.randomUUID()}`;
|
|
12
|
+
turnBlockCounter += 1;
|
|
13
|
+
return `${prefix}-${String(turnBlockCounter)}`;
|
|
14
|
+
}
|
|
15
|
+
function resetBlockIds() {
|
|
16
|
+
turnBlockCounter = 0;
|
|
17
|
+
}
|
|
18
|
+
function isAppendableTextBlock(block, kind) {
|
|
19
|
+
return block?.kind === kind;
|
|
20
|
+
}
|
|
21
|
+
function appendText(blocks, kind, text, idPrefix) {
|
|
22
|
+
const last = blocks.at(-1);
|
|
23
|
+
if (isAppendableTextBlock(last, kind)) {
|
|
24
|
+
last.text += text;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
blocks.push({
|
|
28
|
+
id: nextBlockId(idPrefix),
|
|
29
|
+
kind,
|
|
30
|
+
text,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** One block per call, keyed by `callId`; each event folds into it (`applyToolEvent`). */
|
|
34
|
+
function upsertToolBlock(blocks, tool) {
|
|
35
|
+
const id = `tool-${tool.callId}`;
|
|
36
|
+
const existing = blocks.find((block) => block.kind === 'tool' && block.id === id);
|
|
37
|
+
const call = applyToolEvent(existing?.tool, tool);
|
|
38
|
+
if (existing) {
|
|
39
|
+
existing.tool = call;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
blocks.push({ id, kind: 'tool', tool: call });
|
|
43
|
+
}
|
|
44
|
+
/** Same source: one place, or one link. */
|
|
45
|
+
function sameSource(a, b) {
|
|
46
|
+
if (a.type !== b.type)
|
|
47
|
+
return false;
|
|
48
|
+
if (a.placeId && b.placeId)
|
|
49
|
+
return a.placeId === b.placeId;
|
|
50
|
+
return a.uri === b.uri;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* One sources row per citer: the provider's grounding (no `callId`) or one
|
|
54
|
+
* tool call. A stream cites the same places more than once (the search result
|
|
55
|
+
* lists them, then the answer's annotations cite them), so later citations
|
|
56
|
+
* fold into the row with each source listed once.
|
|
57
|
+
*/
|
|
58
|
+
function foldCitation(blocks, event, idPrefix) {
|
|
59
|
+
const existing = blocks.find((block) => block.kind === 'citation' && block.callId === event.callId);
|
|
60
|
+
const sources = existing ? [...existing.sources] : [];
|
|
61
|
+
for (const source of event.sources) {
|
|
62
|
+
if (!sources.some((seen) => sameSource(seen, source)))
|
|
63
|
+
sources.push(source);
|
|
64
|
+
}
|
|
65
|
+
if (existing) {
|
|
66
|
+
existing.sources = sources;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
blocks.push({
|
|
70
|
+
id: nextBlockId(idPrefix),
|
|
71
|
+
kind: 'citation',
|
|
72
|
+
sources,
|
|
73
|
+
...(event.callId !== undefined ? { callId: event.callId } : {}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function appendPromotedToolMedia(blocks, tool, idPrefix, seenUrls) {
|
|
77
|
+
if (tool.phase !== 'complete' || tool.output === undefined)
|
|
78
|
+
return;
|
|
79
|
+
for (const media of collectPromotedMediaFromToolOutput(tool.output)) {
|
|
80
|
+
if (seenUrls.has(media.url))
|
|
81
|
+
continue;
|
|
82
|
+
seenUrls.add(media.url);
|
|
83
|
+
blocks.push({
|
|
84
|
+
id: nextBlockId(idPrefix),
|
|
85
|
+
kind: 'media',
|
|
86
|
+
mimeType: media.mimeType,
|
|
87
|
+
url: media.url,
|
|
88
|
+
...(media.previewUrl ? { previewUrl: media.previewUrl } : {}),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function buildUserTurnBlocks(draft, idPrefix = 'user') {
|
|
93
|
+
const blocks = [];
|
|
94
|
+
const text = draft.text?.trim();
|
|
95
|
+
if (text) {
|
|
96
|
+
blocks.push({
|
|
97
|
+
id: nextBlockId(idPrefix),
|
|
98
|
+
kind: 'user-text',
|
|
99
|
+
text,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
for (const file of draft.attachments ?? []) {
|
|
103
|
+
blocks.push({
|
|
104
|
+
id: nextBlockId(idPrefix),
|
|
105
|
+
kind: 'user-attachment',
|
|
106
|
+
name: file.name,
|
|
107
|
+
mimeType: file.mimeType,
|
|
108
|
+
sizeBytes: file.sizeBytes,
|
|
109
|
+
...(file.data !== undefined ? { data: file.data } : {}),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
for (const file of draft.voice ?? []) {
|
|
113
|
+
blocks.push({
|
|
114
|
+
id: nextBlockId(idPrefix),
|
|
115
|
+
kind: 'user-voice',
|
|
116
|
+
name: file.name,
|
|
117
|
+
mimeType: file.mimeType,
|
|
118
|
+
sizeBytes: file.sizeBytes,
|
|
119
|
+
...(file.data !== undefined ? { data: file.data } : {}),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return blocks;
|
|
123
|
+
}
|
|
124
|
+
/** Resets only the turn id sequence, so streaming refolds keep stable `turn-*` keys. */
|
|
125
|
+
function foldTurnEvents(events, options = {}) {
|
|
126
|
+
const idPrefix = options.idPrefix ?? 'turn';
|
|
127
|
+
const showThoughts = options.showThoughts ?? true;
|
|
128
|
+
turnBlockCounter = 0;
|
|
129
|
+
const blocks = [];
|
|
130
|
+
const promotedMediaUrls = new Set();
|
|
131
|
+
for (const event of events) {
|
|
132
|
+
switch (event.type) {
|
|
133
|
+
case 'thought':
|
|
134
|
+
if (showThoughts && event.text) {
|
|
135
|
+
appendText(blocks, 'thought', event.text, idPrefix);
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case 'text':
|
|
139
|
+
if (event.text) {
|
|
140
|
+
appendText(blocks, 'text', event.text, idPrefix);
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case 'tool':
|
|
144
|
+
upsertToolBlock(blocks, event.tool);
|
|
145
|
+
appendPromotedToolMedia(blocks, event.tool, idPrefix, promotedMediaUrls);
|
|
146
|
+
break;
|
|
147
|
+
case 'structured':
|
|
148
|
+
blocks.push({
|
|
149
|
+
id: nextBlockId(idPrefix),
|
|
150
|
+
kind: 'structured',
|
|
151
|
+
value: event.structured,
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
case 'media':
|
|
155
|
+
if (event.media) {
|
|
156
|
+
blocks.push({
|
|
157
|
+
id: nextBlockId(idPrefix),
|
|
158
|
+
kind: 'media',
|
|
159
|
+
mimeType: event.media.mimeType,
|
|
160
|
+
data: event.media.data,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
case 'grounding':
|
|
165
|
+
blocks.push({
|
|
166
|
+
id: nextBlockId(idPrefix),
|
|
167
|
+
kind: 'grounding',
|
|
168
|
+
grounding: event.grounding,
|
|
169
|
+
});
|
|
170
|
+
break;
|
|
171
|
+
case 'citation':
|
|
172
|
+
foldCitation(blocks, event, idPrefix);
|
|
173
|
+
break;
|
|
174
|
+
case 'evidence':
|
|
175
|
+
blocks.push({
|
|
176
|
+
id: nextBlockId(idPrefix),
|
|
177
|
+
kind: 'evidence',
|
|
178
|
+
evidence: event.evidence,
|
|
179
|
+
});
|
|
180
|
+
break;
|
|
181
|
+
case 'error':
|
|
182
|
+
if (event.error) {
|
|
183
|
+
blocks.push({
|
|
184
|
+
id: nextBlockId(idPrefix),
|
|
185
|
+
kind: 'error',
|
|
186
|
+
message: event.error,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
case 'done':
|
|
191
|
+
blocks.push({
|
|
192
|
+
id: nextBlockId(idPrefix),
|
|
193
|
+
kind: 'turn-done',
|
|
194
|
+
stop: event.stop,
|
|
195
|
+
tokens: event.tokens,
|
|
196
|
+
interactionId: event.interactionId,
|
|
197
|
+
compaction: event.compaction !== undefined,
|
|
198
|
+
});
|
|
199
|
+
break;
|
|
200
|
+
case 'tokens':
|
|
201
|
+
case 'session':
|
|
202
|
+
case 'stage':
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return blocks;
|
|
209
|
+
}
|
|
210
|
+
function foldConversationTurn(draft, assistantEvents, options = {}) {
|
|
211
|
+
return [...buildUserTurnBlocks(draft, 'user'), ...foldTurnEvents(assistantEvents, options)];
|
|
212
|
+
}
|
|
213
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ComposerPendingKind } from './pending.js';
|
|
2
|
+
export type ComposerRunPhase = 'idle' | 'streaming' | 'gated';
|
|
3
|
+
/** Primary button / Enter target. */
|
|
4
|
+
export type ComposerPrimaryAction = 'send' | 'stop' | 'queue' | 'none';
|
|
5
|
+
/**
|
|
6
|
+
* Split-menu / long-press actions. `send_now` is abort+send while streaming, or
|
|
7
|
+
* abandon the tool gate (no model continue) + send while gated; not a pending kind.
|
|
8
|
+
*/
|
|
9
|
+
export type ComposerMenuAction = ComposerPendingKind | 'send_now';
|
|
10
|
+
export type ComposerActionContext = {
|
|
11
|
+
phase: ComposerRunPhase;
|
|
12
|
+
hasPayload: boolean;
|
|
13
|
+
/** From `ProfileInterface.allowSteering` (text only; false elsewhere). */
|
|
14
|
+
allowSteering: boolean;
|
|
15
|
+
/** Composer profiles always project `canStop: true`. */
|
|
16
|
+
canStop?: boolean;
|
|
17
|
+
};
|
|
18
|
+
declare function resolveComposerPrimary(ctx: ComposerActionContext): ComposerPrimaryAction;
|
|
19
|
+
declare function resolveComposerMenuActions(ctx: ComposerActionContext): ComposerMenuAction[];
|
|
20
|
+
export { resolveComposerMenuActions, resolveComposerPrimary };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function resolveComposerPrimary(ctx) {
|
|
2
|
+
const canStop = ctx.canStop !== false;
|
|
3
|
+
if (ctx.phase === 'idle') {
|
|
4
|
+
return ctx.hasPayload ? 'send' : 'none';
|
|
5
|
+
}
|
|
6
|
+
if (ctx.phase === 'streaming') {
|
|
7
|
+
if (!ctx.hasPayload)
|
|
8
|
+
return canStop ? 'stop' : 'none';
|
|
9
|
+
return 'queue';
|
|
10
|
+
}
|
|
11
|
+
// Gated is still the same run: queue only, no stream to stop.
|
|
12
|
+
return ctx.hasPayload ? 'queue' : 'none';
|
|
13
|
+
}
|
|
14
|
+
function resolveComposerMenuActions(ctx) {
|
|
15
|
+
if (!ctx.hasPayload)
|
|
16
|
+
return [];
|
|
17
|
+
if (ctx.phase === 'idle') {
|
|
18
|
+
return ['stash'];
|
|
19
|
+
}
|
|
20
|
+
if (ctx.phase === 'streaming') {
|
|
21
|
+
const actions = ['queue'];
|
|
22
|
+
if (ctx.allowSteering)
|
|
23
|
+
actions.push('steer');
|
|
24
|
+
actions.push('send_now', 'stash');
|
|
25
|
+
return actions;
|
|
26
|
+
}
|
|
27
|
+
// gated: no steer (not an inject stage); send_now = host ends wait + send
|
|
28
|
+
return ['queue', 'send_now', 'stash'];
|
|
29
|
+
}
|
|
30
|
+
// Emits semantic action keys only: English labels live in the rendering layer or the host UI.
|
|
31
|
+
export { resolveComposerMenuActions, resolveComposerPrimary };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AttachmentValidationIssue } from '../kernel/types.js';
|
|
2
|
+
import type { ProfileGuardrailsView, ProfileInputsInterface, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
3
|
+
declare function sanitizeUserDraft(draft: UserTurnDraft, guardrails?: ProfileGuardrailsView): UserTurnDraft;
|
|
4
|
+
export type PrepareUserTurnResult = {
|
|
5
|
+
ok: true;
|
|
6
|
+
draft: UserTurnDraft;
|
|
7
|
+
blocks: TranscriptBlock[];
|
|
8
|
+
} | {
|
|
9
|
+
ok: false;
|
|
10
|
+
issues: AttachmentValidationIssue[];
|
|
11
|
+
};
|
|
12
|
+
/** Call before appending to the thread and before `runTurn` ingress. */
|
|
13
|
+
declare function prepareUserTurn(inputs: ProfileInputsInterface, draft: UserTurnDraft, guardrails?: ProfileGuardrailsView): PrepareUserTurnResult;
|
|
14
|
+
export { prepareUserTurn, sanitizeUserDraft };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolveGuardrailPolicy } from '../guardrails/policy.js';
|
|
2
|
+
import { sanitizeText } from '../guardrails/sanitize.js';
|
|
3
|
+
import { anySensitive } from '../guardrails/sensitive.js';
|
|
4
|
+
import { buildUserTurnBlocks } from './blocks.js';
|
|
5
|
+
import { validateProfileInputs } from './inputs.js';
|
|
6
|
+
function sanitizeUserDraft(draft, guardrails) {
|
|
7
|
+
const options = guardrails ?? resolveGuardrailPolicy(undefined);
|
|
8
|
+
if (!options.sanitizeInput && !anySensitive(options.redactSensitive)) {
|
|
9
|
+
return draft;
|
|
10
|
+
}
|
|
11
|
+
if (draft.text === undefined) {
|
|
12
|
+
return draft;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
...draft,
|
|
16
|
+
text: sanitizeText(draft.text, options),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Call before appending to the thread and before `runTurn` ingress. */
|
|
20
|
+
function prepareUserTurn(inputs, draft, guardrails) {
|
|
21
|
+
const validation = validateProfileInputs(inputs, draft);
|
|
22
|
+
if (!validation.ok) {
|
|
23
|
+
return { ok: false, issues: validation.issues };
|
|
24
|
+
}
|
|
25
|
+
const safe = sanitizeUserDraft(draft, guardrails);
|
|
26
|
+
return { ok: true, draft: safe, blocks: buildUserTurnBlocks(safe) };
|
|
27
|
+
}
|
|
28
|
+
export { prepareUserTurn, sanitizeUserDraft };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ToolRegistry } from '../kernel/tools/registry.js';
|
|
2
|
+
import type { LiveProfile, Profile, ProjectedProfile } from '../kernel/types.js';
|
|
3
|
+
import type { ComposerProfileInterface, LiveProfileInterface, ProfileInterface } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The interface for `input`, its tools resolved from `tools`: the registry of
|
|
6
|
+
* the scope that runs the profile.
|
|
7
|
+
*/
|
|
8
|
+
declare function interfaceFromProfile(input: LiveProfile, tools: ToolRegistry): LiveProfileInterface;
|
|
9
|
+
declare function interfaceFromProfile(input: Exclude<Profile, LiveProfile>, tools: ToolRegistry): ComposerProfileInterface;
|
|
10
|
+
declare function interfaceFromProfile(input: Profile, tools: ToolRegistry): ProfileInterface;
|
|
11
|
+
declare function interfaceFromProjected(projected: ProjectedProfile): ProfileInterface;
|
|
12
|
+
export { interfaceFromProfile, interfaceFromProjected };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// `profileInterfaceSchema` keeps only the JSON it names, so host functions never reach the view.
|
|
2
|
+
import { egressChecksOf } from '../guardrails/egress.js';
|
|
3
|
+
import { clientLexicon } from '../guardrails/lexicon.js';
|
|
4
|
+
import { resolveGuardrailPolicy } from '../guardrails/policy.js';
|
|
5
|
+
import { projectProfileObject, requireModelProfile } from '../kernel/registry/resolve.js';
|
|
6
|
+
import { profileAllowsSteering } from '../kernel/stop.js';
|
|
7
|
+
import { profileToolAllow, profileToolsSpec } from '../kernel/tools/resolve.js';
|
|
8
|
+
import { resolveObservabilityPolicy } from '../observability/resolve-policy.js';
|
|
9
|
+
import { inputsFromSpec } from './inputs.js';
|
|
10
|
+
import { profileInterfaceSchema } from './profile-interface.js';
|
|
11
|
+
/** Resolved, not raw: a host sees what the kernel will enforce, not defaults of its own. */
|
|
12
|
+
function guardrailsView(guardrails) {
|
|
13
|
+
const policy = resolveGuardrailPolicy(guardrails);
|
|
14
|
+
return {
|
|
15
|
+
quota: policy.quota,
|
|
16
|
+
canary: policy.canary,
|
|
17
|
+
sanitizeInput: policy.sanitizeInput,
|
|
18
|
+
redactSensitive: policy.redactSensitive,
|
|
19
|
+
hasEgress: Boolean(policy.egress),
|
|
20
|
+
egressChecks: egressChecksView(egressChecksOf(policy.egress?.enforce)),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function urlCheckView(check) {
|
|
24
|
+
return check ? { hosts: [...(check.hosts ?? [])], fromTools: check.fromTools ?? true } : false;
|
|
25
|
+
}
|
|
26
|
+
function egressChecksView(checks) {
|
|
27
|
+
if (!checks)
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
sensitive: { ...checks.sensitive },
|
|
31
|
+
boundary: checks.boundary,
|
|
32
|
+
injection: checks.injection,
|
|
33
|
+
images: urlCheckView(checks.images),
|
|
34
|
+
links: urlCheckView(checks.links),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function writeToView(writeTo) {
|
|
38
|
+
if (writeTo === undefined || writeTo === false) {
|
|
39
|
+
return writeTo;
|
|
40
|
+
}
|
|
41
|
+
if (typeof writeTo === 'string') {
|
|
42
|
+
return writeTo;
|
|
43
|
+
}
|
|
44
|
+
return 'custom';
|
|
45
|
+
}
|
|
46
|
+
/** `writeTo` becomes `'custom'` when it is an inline TraceSink. */
|
|
47
|
+
function observabilityView(observability) {
|
|
48
|
+
if (!observability) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const policy = resolveObservabilityPolicy(observability);
|
|
52
|
+
return {
|
|
53
|
+
record: policy.record,
|
|
54
|
+
writeTo: writeToView(policy.writeTo),
|
|
55
|
+
sampleRate: policy.sampleRate,
|
|
56
|
+
include: policy.include,
|
|
57
|
+
scrub: policy.scrub,
|
|
58
|
+
resource: policy.resource,
|
|
59
|
+
retainForDays: policy.retainForDays,
|
|
60
|
+
rotateAfterMiB: policy.rotateAfterMiB,
|
|
61
|
+
hasOnWriteError: Boolean(policy.onWriteError),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function toolsView(projected, profile) {
|
|
65
|
+
if (profile) {
|
|
66
|
+
const t2Loader = profileToolsSpec(profile)?.t2Loader;
|
|
67
|
+
return { allow: [...profileToolAllow(profile)], ...(t2Loader ? { t2Loader } : {}) };
|
|
68
|
+
}
|
|
69
|
+
const allow = projected.tools
|
|
70
|
+
.filter((tool) => !('type' in tool && tool.type === 'builtin'))
|
|
71
|
+
.map((tool) => tool.name);
|
|
72
|
+
return { allow };
|
|
73
|
+
}
|
|
74
|
+
function enrich(projected, profile) {
|
|
75
|
+
const inputs = inputsFromSpec(projected.inputs);
|
|
76
|
+
const identity = profile?.identity ?? { handle: projected.handle };
|
|
77
|
+
const guardrails = profile ? guardrailsView(profile.guardrails) : undefined;
|
|
78
|
+
const observability = profile ? observabilityView(profile.observability) : undefined;
|
|
79
|
+
const outputs = projected.outputs ?? undefined;
|
|
80
|
+
const shared = {
|
|
81
|
+
id: projected.id,
|
|
82
|
+
identity,
|
|
83
|
+
models: projected.models,
|
|
84
|
+
defaultModel: projected.defaultModel,
|
|
85
|
+
allowModelSelect: projected.allowModelSelect,
|
|
86
|
+
maxSteps: projected.maxSteps,
|
|
87
|
+
key: projected.key,
|
|
88
|
+
outputs,
|
|
89
|
+
guardrails,
|
|
90
|
+
observability,
|
|
91
|
+
lexicon: clientLexicon(profile?.lexicon),
|
|
92
|
+
};
|
|
93
|
+
switch (projected.type) {
|
|
94
|
+
case 'text':
|
|
95
|
+
return profileInterfaceSchema.parse({
|
|
96
|
+
...shared,
|
|
97
|
+
type: 'text',
|
|
98
|
+
inputs,
|
|
99
|
+
tools: toolsView(projected, profile),
|
|
100
|
+
turnBehaviour: profile?.type === 'text' ? profile.turnBehaviour : undefined,
|
|
101
|
+
canStop: true,
|
|
102
|
+
allowSteering: profile ? profileAllowsSteering(profile) : true,
|
|
103
|
+
});
|
|
104
|
+
case 'image':
|
|
105
|
+
return profileInterfaceSchema.parse({
|
|
106
|
+
...shared,
|
|
107
|
+
type: 'image',
|
|
108
|
+
image: projected.image ?? {},
|
|
109
|
+
inputs,
|
|
110
|
+
tools: toolsView(projected, profile),
|
|
111
|
+
turnBehaviour: profile?.type === 'image' ? profile.turnBehaviour : undefined,
|
|
112
|
+
canStop: true,
|
|
113
|
+
});
|
|
114
|
+
case 'speech':
|
|
115
|
+
return profileInterfaceSchema.parse({
|
|
116
|
+
...shared,
|
|
117
|
+
type: 'speech',
|
|
118
|
+
speech: projected.speech ?? {},
|
|
119
|
+
inputs,
|
|
120
|
+
turnBehaviour: profile?.type === 'speech' ? profile.turnBehaviour : undefined,
|
|
121
|
+
canStop: true,
|
|
122
|
+
});
|
|
123
|
+
case 'live':
|
|
124
|
+
return profileInterfaceSchema.parse({
|
|
125
|
+
...shared,
|
|
126
|
+
type: 'live',
|
|
127
|
+
live: projected.live ?? {},
|
|
128
|
+
tools: { allow: toolsView(projected, profile).allow },
|
|
129
|
+
});
|
|
130
|
+
default: {
|
|
131
|
+
const exhaustive = projected.type;
|
|
132
|
+
return exhaustive;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function interfaceFromProfile(input, tools) {
|
|
137
|
+
// Host profiles never run a model and have no composer surface.
|
|
138
|
+
const profile = requireModelProfile(input, 'interfaceFromProfile');
|
|
139
|
+
return enrich(projectProfileObject(tools, profile), profile);
|
|
140
|
+
}
|
|
141
|
+
function interfaceFromProjected(projected) {
|
|
142
|
+
return enrich(projected);
|
|
143
|
+
}
|
|
144
|
+
export { interfaceFromProfile, interfaceFromProjected };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type LexiconOverrides } from '../guardrails/lexicon.js';
|
|
2
|
+
import type { ToolCallRequest } from '../kernel/turn-events.js';
|
|
3
|
+
import type { TurnBlob, TurnEvent, TurnHistoryMessage } from '../kernel/types.js';
|
|
4
|
+
import type { ToolCall, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The kernel sets `readBack` on every `complete` and `error` event, so a call without it did not
|
|
7
|
+
* come from a run and has no text the model read.
|
|
8
|
+
*/
|
|
9
|
+
declare function toolReadBack(call: ToolCall): string;
|
|
10
|
+
export type UserTurnHistoryMedia = {
|
|
11
|
+
attachments?: TurnBlob[];
|
|
12
|
+
voice?: TurnBlob[];
|
|
13
|
+
};
|
|
14
|
+
/** For `onStage` inject. Uses base64 on `draft.attachments` / `draft.voice` when present. */
|
|
15
|
+
declare function userDraftToSteerInject(draft: UserTurnDraft): TurnHistoryMessage[];
|
|
16
|
+
declare function appendUserDraftToHistory(history: TurnHistoryMessage[], draft: UserTurnDraft, media?: UserTurnHistoryMedia): TurnHistoryMessage[];
|
|
17
|
+
declare function appendToolExchangeToHistory(history: TurnHistoryMessage[], call: ToolCall): TurnHistoryMessage[];
|
|
18
|
+
declare function appendToolDenialToHistory(history: TurnHistoryMessage[], tool: ToolCallRequest & {
|
|
19
|
+
/** Override the default deny copy. */
|
|
20
|
+
failure?: {
|
|
21
|
+
code: string;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
}, lexicon: LexiconOverrides | undefined): TurnHistoryMessage[];
|
|
25
|
+
declare function appendAssistantEventsToHistory(history: TurnHistoryMessage[], events: readonly TurnEvent[]): TurnHistoryMessage[];
|
|
26
|
+
/**
|
|
27
|
+
* A reply paused on its gates, as the model reads it when the user walks away:
|
|
28
|
+
* its gated calls stay open in their step for the host to answer
|
|
29
|
+
* (`answerOpenToolCalls`) before the user's next message.
|
|
30
|
+
*/
|
|
31
|
+
declare function appendPausedTurnToHistory(history: TurnHistoryMessage[], events: readonly TurnEvent[]): TurnHistoryMessage[];
|
|
32
|
+
/** Attachment and voice blocks are omitted: their preview `data` is UI-only. */
|
|
33
|
+
declare function historyFromTranscriptBlocks(blocks: readonly TranscriptBlock[]): TurnHistoryMessage[];
|
|
34
|
+
declare function assertOpenToolCalls(history: readonly TurnHistoryMessage[], ids: readonly string[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* `answers` holds, by call id, the text the model reads for each open call. Results follow their
|
|
37
|
+
* step in the order the model made the calls. Throws unless `answers` names exactly the open calls.
|
|
38
|
+
*/
|
|
39
|
+
declare function answerOpenToolCalls(history: readonly TurnHistoryMessage[], answers: ReadonlyMap<string, string>): TurnHistoryMessage[];
|
|
40
|
+
export { answerOpenToolCalls, appendAssistantEventsToHistory, appendPausedTurnToHistory, appendToolDenialToHistory, appendToolExchangeToHistory, appendUserDraftToHistory, assertOpenToolCalls, historyFromTranscriptBlocks, toolReadBack, userDraftToSteerInject, };
|