@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,269 @@
|
|
|
1
|
+
// A settled tool call replays its `readBack`, the text the model read, so provider continuation
|
|
2
|
+
// matches `runTurn` / `invokeTool`.
|
|
3
|
+
import { TheoremError } from '../guardrails/error.js';
|
|
4
|
+
import { lexiconText } from '../guardrails/lexicon.js';
|
|
5
|
+
import { mediaKindForMime } from '../kernel/registry/catalog.js';
|
|
6
|
+
import { formatToolFailureForModel, formatToolResult } from '../kernel/tools/model-text.js';
|
|
7
|
+
import { applyToolEvent, toolCallRanWith } from './tool-calls.js';
|
|
8
|
+
/**
|
|
9
|
+
* The kernel sets `readBack` on every `complete` and `error` event, so a call without it did not
|
|
10
|
+
* come from a run and has no text the model read.
|
|
11
|
+
*/
|
|
12
|
+
function toolReadBack(call) {
|
|
13
|
+
const state = call.state;
|
|
14
|
+
if ((state?.phase !== 'complete' && state?.phase !== 'error') || state.readBack === undefined) {
|
|
15
|
+
throw new TheoremError('request', `Tool call '${call.name}' has no readBack: only a settled call from a run carries one.`);
|
|
16
|
+
}
|
|
17
|
+
return state.readBack;
|
|
18
|
+
}
|
|
19
|
+
function blobToPart(blob) {
|
|
20
|
+
const kind = mediaKindForMime(blob.mimeType) ?? 'document';
|
|
21
|
+
return { type: kind, mimeType: blob.mimeType, data: blob.data };
|
|
22
|
+
}
|
|
23
|
+
function draftBlobsWithData(blobs) {
|
|
24
|
+
const mapped = blobs
|
|
25
|
+
?.filter((a) => typeof a.data === 'string' && a.data.length > 0)
|
|
26
|
+
.map((a) => ({ name: a.name, mimeType: a.mimeType, data: a.data }));
|
|
27
|
+
return mapped?.length ? mapped : undefined;
|
|
28
|
+
}
|
|
29
|
+
/** For `onStage` inject. Uses base64 on `draft.attachments` / `draft.voice` when present. */
|
|
30
|
+
function userDraftToSteerInject(draft) {
|
|
31
|
+
const attachments = draftBlobsWithData(draft.attachments);
|
|
32
|
+
const voice = draftBlobsWithData(draft.voice);
|
|
33
|
+
return appendUserDraftToHistory([], { text: draft.text }, {
|
|
34
|
+
...(attachments ? { attachments } : {}),
|
|
35
|
+
...(voice ? { voice } : {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function appendUserDraftToHistory(history, draft, media = {}) {
|
|
39
|
+
const text = draft.text?.trim();
|
|
40
|
+
const parts = [];
|
|
41
|
+
for (const blob of media.attachments ?? []) {
|
|
42
|
+
parts.push(blobToPart(blob));
|
|
43
|
+
}
|
|
44
|
+
for (const blob of media.voice ?? []) {
|
|
45
|
+
parts.push(blobToPart(blob));
|
|
46
|
+
}
|
|
47
|
+
if (text) {
|
|
48
|
+
parts.push({ type: 'text', text });
|
|
49
|
+
}
|
|
50
|
+
if (parts.length === 0) {
|
|
51
|
+
return history;
|
|
52
|
+
}
|
|
53
|
+
if (parts.length === 1 && parts[0]?.type === 'text') {
|
|
54
|
+
return [...history, { role: 'user', content: text }];
|
|
55
|
+
}
|
|
56
|
+
return [...history, { role: 'user', parts }];
|
|
57
|
+
}
|
|
58
|
+
function toolCallEntry(tool) {
|
|
59
|
+
return {
|
|
60
|
+
id: tool.callId,
|
|
61
|
+
type: 'function',
|
|
62
|
+
function: { name: tool.name, arguments: JSON.stringify(tool.arguments) },
|
|
63
|
+
...(tool.thoughtSignature ? { thoughtSignature: tool.thoughtSignature } : {}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function toolResultMessage(tool, content) {
|
|
67
|
+
return { role: 'tool', tool_call_id: tool.callId, name: tool.name, content };
|
|
68
|
+
}
|
|
69
|
+
function appendToolCallPair(history, tool, content) {
|
|
70
|
+
return [
|
|
71
|
+
...history,
|
|
72
|
+
{ role: 'assistant', tool_calls: [toolCallEntry(tool)] },
|
|
73
|
+
toolResultMessage(tool, content),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
function appendToolExchangeToHistory(history, call) {
|
|
77
|
+
return appendToolCallPair(history, historyToolCall(call), toolReadBack(call));
|
|
78
|
+
}
|
|
79
|
+
function historyToolCall(call) {
|
|
80
|
+
return {
|
|
81
|
+
name: call.name,
|
|
82
|
+
callId: call.callId,
|
|
83
|
+
arguments: toolCallRanWith(call),
|
|
84
|
+
...(call.thoughtSignature ? { thoughtSignature: call.thoughtSignature } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function appendToolDenialToHistory(history, tool, lexicon) {
|
|
88
|
+
const failure = tool.failure ?? {
|
|
89
|
+
code: 'denied',
|
|
90
|
+
message: lexiconText('session.tool_denied', { tool: tool.name }, lexicon),
|
|
91
|
+
};
|
|
92
|
+
return appendToolCallPair(history, tool, formatToolResult(formatToolFailureForModel(failure)));
|
|
93
|
+
}
|
|
94
|
+
/** `undefined` while the call is open. */
|
|
95
|
+
function settledToolContent(call) {
|
|
96
|
+
const phase = call.state?.phase;
|
|
97
|
+
return phase === 'complete' || phase === 'error' ? toolReadBack(call) : undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* One model step's settled calls: a single assistant message holding every call
|
|
101
|
+
* the step made, then each result. Google replays a step's calls only this way,
|
|
102
|
+
* with the step's thought signature on its first call. With `gated: 'open'`, a
|
|
103
|
+
* call waiting on its gate joins the message too, left without a result.
|
|
104
|
+
*/
|
|
105
|
+
function appendToolStepToHistory(history, calls, gated = 'omit') {
|
|
106
|
+
const entries = calls.flatMap((call) => {
|
|
107
|
+
const content = settledToolContent(call);
|
|
108
|
+
if (content !== undefined)
|
|
109
|
+
return [{ tool: historyToolCall(call), content }];
|
|
110
|
+
return gated === 'open' && call.state?.phase === 'gate'
|
|
111
|
+
? [{ tool: historyToolCall(call) }]
|
|
112
|
+
: [];
|
|
113
|
+
});
|
|
114
|
+
if (entries.length === 0)
|
|
115
|
+
return history;
|
|
116
|
+
return [
|
|
117
|
+
...history,
|
|
118
|
+
{ role: 'assistant', tool_calls: entries.map(({ tool }) => toolCallEntry(tool)) },
|
|
119
|
+
...entries.flatMap(({ tool, content }) => content === undefined ? [] : [toolResultMessage(tool, content)]),
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
function appendAssistantEventsToHistory(history, events) {
|
|
123
|
+
return foldAssistantEvents(history, events, 'omit');
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A reply paused on its gates, as the model reads it when the user walks away:
|
|
127
|
+
* its gated calls stay open in their step for the host to answer
|
|
128
|
+
* (`answerOpenToolCalls`) before the user's next message.
|
|
129
|
+
*/
|
|
130
|
+
function appendPausedTurnToHistory(history, events) {
|
|
131
|
+
return foldAssistantEvents(history, events, 'open');
|
|
132
|
+
}
|
|
133
|
+
function foldAssistantEvents(history, events, gated) {
|
|
134
|
+
let next = history;
|
|
135
|
+
let textBuf = '';
|
|
136
|
+
// The calls of the step being read, in the order the model made them.
|
|
137
|
+
let step;
|
|
138
|
+
const calls = new Map();
|
|
139
|
+
const flushText = () => {
|
|
140
|
+
if (!textBuf) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
next = [...next, { role: 'assistant', content: textBuf }];
|
|
144
|
+
textBuf = '';
|
|
145
|
+
};
|
|
146
|
+
const flushStep = () => {
|
|
147
|
+
if (!step) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const stepCalls = step.callIds.flatMap((id) => calls.get(id) ?? []);
|
|
151
|
+
next = appendToolStepToHistory(next, stepCalls, gated);
|
|
152
|
+
step = undefined;
|
|
153
|
+
};
|
|
154
|
+
for (const event of events) {
|
|
155
|
+
if (event.type === 'text') {
|
|
156
|
+
flushStep();
|
|
157
|
+
textBuf += event.text;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (event.type === 'structured' && event.structured !== undefined) {
|
|
161
|
+
flushStep();
|
|
162
|
+
flushText();
|
|
163
|
+
next = [...next, { role: 'assistant', content: JSON.stringify(event.structured) }];
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (event.type !== 'tool') {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const call = applyToolEvent(calls.get(event.tool.callId), event.tool);
|
|
170
|
+
calls.set(call.callId, call);
|
|
171
|
+
if (event.tool.phase !== undefined) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
// A call opens its step, or joins the one it was made with.
|
|
175
|
+
if (!step || call.stepId === undefined || step.stepId !== call.stepId) {
|
|
176
|
+
flushStep();
|
|
177
|
+
flushText();
|
|
178
|
+
step = { stepId: call.stepId, callIds: [] };
|
|
179
|
+
}
|
|
180
|
+
step.callIds.push(call.callId);
|
|
181
|
+
}
|
|
182
|
+
flushStep();
|
|
183
|
+
flushText();
|
|
184
|
+
return next;
|
|
185
|
+
}
|
|
186
|
+
/** Attachment and voice blocks are omitted: their preview `data` is UI-only. */
|
|
187
|
+
function historyFromTranscriptBlocks(blocks) {
|
|
188
|
+
let history = [];
|
|
189
|
+
// Consecutive tool blocks from one model step replay together.
|
|
190
|
+
let step = [];
|
|
191
|
+
const flushStep = () => {
|
|
192
|
+
history = appendToolStepToHistory(history, step);
|
|
193
|
+
step = [];
|
|
194
|
+
};
|
|
195
|
+
for (const block of blocks) {
|
|
196
|
+
if (block.kind === 'tool') {
|
|
197
|
+
const open = step[0];
|
|
198
|
+
if (open && (open.stepId === undefined || open.stepId !== block.tool.stepId))
|
|
199
|
+
flushStep();
|
|
200
|
+
step.push(block.tool);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
flushStep();
|
|
204
|
+
if (block.kind === 'user-text') {
|
|
205
|
+
history = appendUserDraftToHistory(history, { text: block.text });
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (block.kind === 'text') {
|
|
209
|
+
history = [...history, { role: 'assistant', content: block.text }];
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (block.kind === 'structured') {
|
|
213
|
+
history = [...history, { role: 'assistant', content: JSON.stringify(block.value) }];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
flushStep();
|
|
217
|
+
return history;
|
|
218
|
+
}
|
|
219
|
+
function lastToolStep(history) {
|
|
220
|
+
const at = history.findLastIndex((message) => message.tool_calls !== undefined);
|
|
221
|
+
const calls = history[at]?.tool_calls;
|
|
222
|
+
return calls ? { at, calls } : undefined;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The calls the history leaves open: those of its last step with no result
|
|
226
|
+
* after it, when nothing but results follows that step. Empty otherwise.
|
|
227
|
+
*/
|
|
228
|
+
function openToolCallIds(history) {
|
|
229
|
+
const step = lastToolStep(history);
|
|
230
|
+
if (!step)
|
|
231
|
+
return [];
|
|
232
|
+
const after = history.slice(step.at + 1);
|
|
233
|
+
if (after.some((message) => message.role !== 'tool'))
|
|
234
|
+
return [];
|
|
235
|
+
const answered = new Set(after.map((message) => message.tool_call_id));
|
|
236
|
+
return step.calls.flatMap((call) => (answered.has(call.id) ? [] : [call.id]));
|
|
237
|
+
}
|
|
238
|
+
function openCallsMismatch(history, ids) {
|
|
239
|
+
return new TheoremError('request', `the history leaves open [${openToolCallIds(history).join(', ')}], not [${ids.join(', ')}]`);
|
|
240
|
+
}
|
|
241
|
+
function assertOpenToolCalls(history, ids) {
|
|
242
|
+
const open = openToolCallIds(history);
|
|
243
|
+
if (open.length !== ids.length || open.some((id) => !ids.includes(id))) {
|
|
244
|
+
throw openCallsMismatch(history, ids);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* `answers` holds, by call id, the text the model reads for each open call. Results follow their
|
|
249
|
+
* step in the order the model made the calls. Throws unless `answers` names exactly the open calls.
|
|
250
|
+
*/
|
|
251
|
+
function answerOpenToolCalls(history, answers) {
|
|
252
|
+
const ids = [...answers.keys()];
|
|
253
|
+
assertOpenToolCalls(history, ids);
|
|
254
|
+
const step = lastToolStep(history);
|
|
255
|
+
if (!step)
|
|
256
|
+
return [...history];
|
|
257
|
+
const results = new Map(history.slice(step.at + 1).map((message) => [message.tool_call_id, message]));
|
|
258
|
+
const resultOf = (call) => {
|
|
259
|
+
const result = results.get(call.id);
|
|
260
|
+
if (result)
|
|
261
|
+
return result;
|
|
262
|
+
const content = answers.get(call.id);
|
|
263
|
+
if (content === undefined)
|
|
264
|
+
throw openCallsMismatch(history, ids);
|
|
265
|
+
return { role: 'tool', tool_call_id: call.id, name: call.function.name, content };
|
|
266
|
+
};
|
|
267
|
+
return [...history.slice(0, step.at + 1), ...step.calls.map(resultOf)];
|
|
268
|
+
}
|
|
269
|
+
export { answerOpenToolCalls, appendAssistantEventsToHistory, appendPausedTurnToHistory, appendToolDenialToHistory, appendToolExchangeToHistory, appendUserDraftToHistory, assertOpenToolCalls, historyFromTranscriptBlocks, toolReadBack, userDraftToSteerInject, };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProfileInputsSpec } from '../kernel/types.js';
|
|
2
|
+
import type { AttachmentValidationResult, ProfileInputsInterface, UserTurnDraft } from './types.js';
|
|
3
|
+
declare function attachmentAcceptAttr(accept: string[]): string;
|
|
4
|
+
/** `inputs` is null for profile types that declare none (the kernel's `profileInputs`). */
|
|
5
|
+
declare function inputsFromSpec(inputs: ProfileInputsSpec | null | undefined): ProfileInputsInterface;
|
|
6
|
+
/** Validate staged files against resolved profile `inputs`: the kernel's one attachment check. */
|
|
7
|
+
declare function validateProfileInputs(inputs: ProfileInputsInterface, draft: Pick<UserTurnDraft, 'attachments' | 'voice'>): AttachmentValidationResult;
|
|
8
|
+
/** The first accepted format this browser can record; undefined when it can record none. */
|
|
9
|
+
declare function pickMediaRecorderMime(accept?: string[]): string | undefined;
|
|
10
|
+
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { attachmentIssues, resolveMediaLimits } from '../kernel/registry/attachments.js';
|
|
2
|
+
import { mimeAllowed } from '../kernel/registry/catalog.js';
|
|
3
|
+
const RECORDER_CANDIDATES = [
|
|
4
|
+
'audio/webm;codecs=opus',
|
|
5
|
+
'audio/webm',
|
|
6
|
+
'audio/mp4',
|
|
7
|
+
'audio/wav',
|
|
8
|
+
'audio/mpeg',
|
|
9
|
+
];
|
|
10
|
+
function attachmentAcceptAttr(accept) {
|
|
11
|
+
return accept.join(',');
|
|
12
|
+
}
|
|
13
|
+
/** `inputs` is null for profile types that declare none (the kernel's `profileInputs`). */
|
|
14
|
+
function inputsFromSpec(inputs) {
|
|
15
|
+
const accept = inputs?.attachments?.accept;
|
|
16
|
+
const voiceAccept = inputs?.voice?.accept;
|
|
17
|
+
return {
|
|
18
|
+
text: inputs?.text !== false,
|
|
19
|
+
attachments: accept?.length ? { accept, acceptAttr: attachmentAcceptAttr(accept) } : null,
|
|
20
|
+
voice: voiceAccept?.length ? { accept: voiceAccept } : null,
|
|
21
|
+
maxFiles: inputs?.maxFiles,
|
|
22
|
+
maxBytes: inputs?.maxBytes,
|
|
23
|
+
maxTurnBytes: inputs?.maxTurnBytes,
|
|
24
|
+
limitsByMime: inputs?.limitsByMime,
|
|
25
|
+
slots: inputs?.slots,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function toProfileInputsSpec(inputs) {
|
|
29
|
+
return {
|
|
30
|
+
text: inputs.text,
|
|
31
|
+
attachments: inputs.attachments ? { accept: inputs.attachments.accept } : undefined,
|
|
32
|
+
voice: inputs.voice ? { accept: inputs.voice.accept } : undefined,
|
|
33
|
+
maxFiles: inputs.maxFiles,
|
|
34
|
+
maxBytes: inputs.maxBytes,
|
|
35
|
+
maxTurnBytes: inputs.maxTurnBytes,
|
|
36
|
+
limitsByMime: inputs.limitsByMime,
|
|
37
|
+
slots: inputs.slots,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Validate staged files against resolved profile `inputs`: the kernel's one attachment check. */
|
|
41
|
+
function validateProfileInputs(inputs, draft) {
|
|
42
|
+
const facts = (files) => (files ?? []).map(({ name, mimeType, sizeBytes }) => ({ name, mimeType, sizeBytes }));
|
|
43
|
+
const issues = attachmentIssues({
|
|
44
|
+
attachments: inputs.attachments?.accept,
|
|
45
|
+
voice: inputs.voice?.accept,
|
|
46
|
+
limits: resolveMediaLimits(toProfileInputsSpec(inputs)),
|
|
47
|
+
}, facts(draft.attachments), facts(draft.voice));
|
|
48
|
+
return { ok: issues.length === 0, issues };
|
|
49
|
+
}
|
|
50
|
+
/** The first accepted format this browser can record; undefined when it can record none. */
|
|
51
|
+
function pickMediaRecorderMime(accept) {
|
|
52
|
+
const recorder = globalThis
|
|
53
|
+
.MediaRecorder;
|
|
54
|
+
if (recorder === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
const supported = (mime) => recorder.isTypeSupported(mime);
|
|
57
|
+
const fromCandidates = (pool) => pool.find(supported);
|
|
58
|
+
if (accept?.length) {
|
|
59
|
+
return (fromCandidates(RECORDER_CANDIDATES.filter((mime) => mimeAllowed(accept, mime))) ??
|
|
60
|
+
accept.find(supported));
|
|
61
|
+
}
|
|
62
|
+
return fromCandidates(RECORDER_CANDIDATES);
|
|
63
|
+
}
|
|
64
|
+
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless profile-driven interface — spec, inputs, transcript folding,
|
|
3
|
+
* composer pending intents (stash / queue / steer).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export type { AttachmentValidationCode, AttachmentValidationIssue, AttachmentValidationParams, } from '../kernel/types.js';
|
|
9
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds, } from './blocks.js';
|
|
10
|
+
export type { ComposerActionContext, ComposerMenuAction, ComposerPrimaryAction, ComposerRunPhase, } from './composer-actions.js';
|
|
11
|
+
export { resolveComposerMenuActions, resolveComposerPrimary } from './composer-actions.js';
|
|
12
|
+
export type { PrepareUserTurnResult } from './draft.js';
|
|
13
|
+
export { prepareUserTurn, sanitizeUserDraft } from './draft.js';
|
|
14
|
+
export { interfaceFromProfile, interfaceFromProjected } from './from-profile.js';
|
|
15
|
+
export type { UserTurnHistoryMedia } from './history.js';
|
|
16
|
+
export { answerOpenToolCalls, appendAssistantEventsToHistory, appendPausedTurnToHistory, appendToolDenialToHistory, appendToolExchangeToHistory, appendUserDraftToHistory, assertOpenToolCalls, historyFromTranscriptBlocks, toolReadBack, userDraftToSteerInject, } from './history.js';
|
|
17
|
+
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs, } from './inputs.js';
|
|
18
|
+
export type { InterfaceEffortOption, InterfaceModelOption } from './models.js';
|
|
19
|
+
export { defaultInterfaceEffort, effortSelectEnabled, generationSelectEnabled, interfaceEffortOptions, interfaceModelOptions, modelSelectEnabled, } from './models.js';
|
|
20
|
+
export type { ComposerPendingKind, ComposerPendingMessage, CreateComposerPendingMessageArgs, } from './pending.js';
|
|
21
|
+
export { COMPOSER_PENDING_KINDS, cloneUserTurnDraft, composerPendingPreview, consumeNextComposerQueue, consumeNextComposerSteer, convertSteersToFrontQueued, createComposerPendingMessage, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, updateComposerPendingDraft, userDraftHasPayload, } from './pending.js';
|
|
22
|
+
export { profileInterfaceSchema } from './profile-interface.js';
|
|
23
|
+
export type { AwaitingToolContext, GatedToolContext, InterfaceTurnSession, ToolGateAuth, } from './session.js';
|
|
24
|
+
export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSession, emptyInterfaceTurnSession, gatedToolFromEvents, gatedToolsFromEvents, } from './session.js';
|
|
25
|
+
export type { SettledToolCallEvent } from './tool-calls.js';
|
|
26
|
+
export { settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
|
|
27
|
+
export { promotedToolIdsFromEvents, toolSnapshotFromEvents } from './tool-invoke.js';
|
|
28
|
+
export type { PromotedToolMedia } from './tool-media.js';
|
|
29
|
+
export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
|
|
30
|
+
export type { AttachmentValidationResult, ComposerInterfaceFields, ComposerProfileInterface, FoldTurnEventsOptions, ImageProfileInterface, LiveProfileInterface, ModelBindingView, PendingAttachment, ProfileGuardrailsView, ProfileInputsInterface, ProfileInterface, ProfileObservabilityView, ProfileOutputsView, ProfileToolsView, SpeechProfileInterface, TextProfileInterface, TranscriptBlock, TranscriptBlockKind, UserTurnDraft, } from './types.js';
|
|
31
|
+
export { streamThoughtsEnabled } from './types.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless profile-driven interface — spec, inputs, transcript folding,
|
|
3
|
+
* composer pending intents (stash / queue / steer).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import "../../_dnt.polyfills.js";
|
|
8
|
+
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds, } from './blocks.js';
|
|
9
|
+
export { resolveComposerMenuActions, resolveComposerPrimary } from './composer-actions.js';
|
|
10
|
+
export { prepareUserTurn, sanitizeUserDraft } from './draft.js';
|
|
11
|
+
export { interfaceFromProfile, interfaceFromProjected } from './from-profile.js';
|
|
12
|
+
export { answerOpenToolCalls, appendAssistantEventsToHistory, appendPausedTurnToHistory, appendToolDenialToHistory, appendToolExchangeToHistory, appendUserDraftToHistory, assertOpenToolCalls, historyFromTranscriptBlocks, toolReadBack, userDraftToSteerInject, } from './history.js';
|
|
13
|
+
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs, } from './inputs.js';
|
|
14
|
+
export { defaultInterfaceEffort, effortSelectEnabled, generationSelectEnabled, interfaceEffortOptions, interfaceModelOptions, modelSelectEnabled, } from './models.js';
|
|
15
|
+
export { COMPOSER_PENDING_KINDS, cloneUserTurnDraft, composerPendingPreview, consumeNextComposerQueue, consumeNextComposerSteer, convertSteersToFrontQueued, createComposerPendingMessage, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, updateComposerPendingDraft, userDraftHasPayload, } from './pending.js';
|
|
16
|
+
export { profileInterfaceSchema } from './profile-interface.js';
|
|
17
|
+
export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSession, emptyInterfaceTurnSession, gatedToolFromEvents, gatedToolsFromEvents, } from './session.js';
|
|
18
|
+
export { settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
|
|
19
|
+
export { promotedToolIdsFromEvents, toolSnapshotFromEvents } from './tool-invoke.js';
|
|
20
|
+
export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
|
|
21
|
+
export { streamThoughtsEnabled } from './types.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ModelId } from '../kernel/types.js';
|
|
2
|
+
import type { ComposerProfileInterface } from './types.js';
|
|
3
|
+
export type ModelSelectProfile = Pick<ComposerProfileInterface, 'id' | 'models' | 'defaultModel' | 'allowModelSelect'>;
|
|
4
|
+
export type InterfaceModelOption = {
|
|
5
|
+
id: ModelId;
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
export type InterfaceEffortOption = {
|
|
9
|
+
alias: string;
|
|
10
|
+
level: string;
|
|
11
|
+
};
|
|
12
|
+
declare function modelSelectEnabled(profile: ModelSelectProfile): boolean;
|
|
13
|
+
declare function effortSelectEnabled(profile: ModelSelectProfile, modelId: ModelId | undefined): boolean;
|
|
14
|
+
declare function generationSelectEnabled(profile: ModelSelectProfile, modelId: ModelId | undefined): boolean;
|
|
15
|
+
/** `defaultEffort` when it names an alias, else the first alias. */
|
|
16
|
+
declare function defaultInterfaceEffort(profile: ModelSelectProfile, modelId: ModelId | undefined): string | undefined;
|
|
17
|
+
declare function interfaceModelOptions(profile: ModelSelectProfile): InterfaceModelOption[];
|
|
18
|
+
declare function interfaceEffortOptions(profile: ModelSelectProfile, modelId: ModelId | undefined): InterfaceEffortOption[];
|
|
19
|
+
export { defaultInterfaceEffort, effortSelectEnabled, generationSelectEnabled, interfaceEffortOptions, interfaceModelOptions, modelSelectEnabled, };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function bindingFor(profile, modelId) {
|
|
2
|
+
if (!modelId)
|
|
3
|
+
return undefined;
|
|
4
|
+
return profile.models[modelId];
|
|
5
|
+
}
|
|
6
|
+
function modelSelectEnabled(profile) {
|
|
7
|
+
return Boolean(profile.allowModelSelect && Object.keys(profile.models).length >= 2);
|
|
8
|
+
}
|
|
9
|
+
function effortSelectEnabled(profile, modelId) {
|
|
10
|
+
const binding = bindingFor(profile, modelId);
|
|
11
|
+
if (!binding?.allowEffortSelect)
|
|
12
|
+
return false;
|
|
13
|
+
return Object.keys(binding.efforts ?? {}).length >= 2;
|
|
14
|
+
}
|
|
15
|
+
function generationSelectEnabled(profile, modelId) {
|
|
16
|
+
return modelSelectEnabled(profile) || effortSelectEnabled(profile, modelId);
|
|
17
|
+
}
|
|
18
|
+
/** `defaultEffort` when it names an alias, else the first alias. */
|
|
19
|
+
function defaultInterfaceEffort(profile, modelId) {
|
|
20
|
+
const binding = bindingFor(profile, modelId);
|
|
21
|
+
if (!binding?.efforts)
|
|
22
|
+
return undefined;
|
|
23
|
+
const defaultAlias = binding.defaultEffort?.trim();
|
|
24
|
+
if (defaultAlias && binding.efforts[defaultAlias])
|
|
25
|
+
return defaultAlias;
|
|
26
|
+
const keys = Object.keys(binding.efforts);
|
|
27
|
+
return keys[0];
|
|
28
|
+
}
|
|
29
|
+
function interfaceModelOptions(profile) {
|
|
30
|
+
if (!modelSelectEnabled(profile))
|
|
31
|
+
return [];
|
|
32
|
+
return Object.entries(profile.models).map(([id, binding]) => ({
|
|
33
|
+
id,
|
|
34
|
+
label: binding.apiId,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
function interfaceEffortOptions(profile, modelId) {
|
|
38
|
+
if (!effortSelectEnabled(profile, modelId))
|
|
39
|
+
return [];
|
|
40
|
+
const binding = bindingFor(profile, modelId);
|
|
41
|
+
if (!binding?.efforts)
|
|
42
|
+
return [];
|
|
43
|
+
return Object.entries(binding.efforts).map(([alias, level]) => ({ alias, level }));
|
|
44
|
+
}
|
|
45
|
+
export { defaultInterfaceEffort, effortSelectEnabled, generationSelectEnabled, interfaceEffortOptions, interfaceModelOptions, modelSelectEnabled, };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { TurnEvent } from '../kernel/types.js';
|
|
2
|
+
import type { UserTurnDraft } from './types.js';
|
|
3
|
+
/** Display order: steers, then queues, then stashes. */
|
|
4
|
+
export declare const COMPOSER_PENDING_KINDS: readonly ["steer", "queue", "stash"];
|
|
5
|
+
export type ComposerPendingKind = (typeof COMPOSER_PENDING_KINDS)[number];
|
|
6
|
+
export interface ComposerPendingMessage {
|
|
7
|
+
id: string;
|
|
8
|
+
kind: ComposerPendingKind;
|
|
9
|
+
draft: UserTurnDraft;
|
|
10
|
+
createdAt: number;
|
|
11
|
+
updatedAt: number;
|
|
12
|
+
}
|
|
13
|
+
export type CreateComposerPendingMessageArgs = {
|
|
14
|
+
kind: ComposerPendingKind;
|
|
15
|
+
draft: UserTurnDraft;
|
|
16
|
+
id?: string;
|
|
17
|
+
now?: number;
|
|
18
|
+
};
|
|
19
|
+
declare function userDraftHasPayload(draft: UserTurnDraft): boolean;
|
|
20
|
+
/** Short preview for pending bars (text, else attachment hint). */
|
|
21
|
+
declare function composerPendingPreview(message: ComposerPendingMessage): string;
|
|
22
|
+
/** Throws on an empty draft. */
|
|
23
|
+
declare function createComposerPendingMessage(args: CreateComposerPendingMessageArgs): ComposerPendingMessage;
|
|
24
|
+
declare function cloneUserTurnDraft(draft: UserTurnDraft): UserTurnDraft;
|
|
25
|
+
/** Steer, then queue, then stash; FIFO within a kind. */
|
|
26
|
+
declare function orderComposerPendingMessages(messages: readonly ComposerPendingMessage[]): ComposerPendingMessage[];
|
|
27
|
+
/** When a run ends, undelivered steers become queues ahead of the existing ones. */
|
|
28
|
+
declare function convertSteersToFrontQueued(messages: readonly ComposerPendingMessage[], now?: number): ComposerPendingMessage[];
|
|
29
|
+
/**
|
|
30
|
+
* Drops the steers a turn event reports as landed in the conversation. A steer
|
|
31
|
+
* it never names stays pending, so the run's end requeues it.
|
|
32
|
+
*/
|
|
33
|
+
declare function removeLandedSteers(messages: readonly ComposerPendingMessage[], event: TurnEvent): ComposerPendingMessage[];
|
|
34
|
+
declare function removeComposerPendingMessage(messages: readonly ComposerPendingMessage[], id: string): ComposerPendingMessage[];
|
|
35
|
+
declare function updateComposerPendingDraft(messages: readonly ComposerPendingMessage[], id: string, draft: UserTurnDraft, now?: number): ComposerPendingMessage[];
|
|
36
|
+
declare function moveComposerPendingWithinKind(messages: readonly ComposerPendingMessage[], id: string, direction: 'up' | 'down'): ComposerPendingMessage[];
|
|
37
|
+
/** One steer per safe boundary: call once per `onStage` inject site. */
|
|
38
|
+
declare function consumeNextComposerSteer(messages: readonly ComposerPendingMessage[]): {
|
|
39
|
+
message: ComposerPendingMessage | null;
|
|
40
|
+
remaining: ComposerPendingMessage[];
|
|
41
|
+
};
|
|
42
|
+
/** Call only after the agent run has fully ended, not on a tool pause. */
|
|
43
|
+
declare function consumeNextComposerQueue(messages: readonly ComposerPendingMessage[]): {
|
|
44
|
+
message: ComposerPendingMessage | null;
|
|
45
|
+
remaining: ComposerPendingMessage[];
|
|
46
|
+
};
|
|
47
|
+
declare function promoteComposerPendingKind(messages: readonly ComposerPendingMessage[], id: string, kind: ComposerPendingKind, now?: number): ComposerPendingMessage[];
|
|
48
|
+
export { cloneUserTurnDraft, composerPendingPreview, consumeNextComposerQueue, consumeNextComposerSteer, convertSteersToFrontQueued, createComposerPendingMessage, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, updateComposerPendingDraft, userDraftHasPayload, };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// `steer` injects at `onStage` boundaries of the same run; `queue` sends after the run fully ends
|
|
2
|
+
// (not on tool pause); `stash` never auto-sends. `send_now` is an action, not a pending kind.
|
|
3
|
+
/** Display order: steers, then queues, then stashes. */
|
|
4
|
+
export const COMPOSER_PENDING_KINDS = ['steer', 'queue', 'stash'];
|
|
5
|
+
function createPendingId() {
|
|
6
|
+
return typeof crypto !== 'undefined' && 'randomUUID' in crypto
|
|
7
|
+
? crypto.randomUUID()
|
|
8
|
+
: `pending-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
9
|
+
}
|
|
10
|
+
function userDraftHasPayload(draft) {
|
|
11
|
+
return Boolean(draft.text?.trim() ||
|
|
12
|
+
(draft.attachments && draft.attachments.length > 0) ||
|
|
13
|
+
(draft.voice && draft.voice.length > 0));
|
|
14
|
+
}
|
|
15
|
+
/** Short preview for pending bars (text, else attachment hint). */
|
|
16
|
+
function composerPendingPreview(message) {
|
|
17
|
+
const text = message.draft.text?.trim();
|
|
18
|
+
if (text)
|
|
19
|
+
return text;
|
|
20
|
+
const files = (message.draft.attachments?.length ?? 0) + (message.draft.voice?.length ?? 0);
|
|
21
|
+
if (files > 0)
|
|
22
|
+
return files === 1 ? '(attachment)' : `(${files} attachments)`;
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
/** Throws on an empty draft. */
|
|
26
|
+
function createComposerPendingMessage(args) {
|
|
27
|
+
if (!userDraftHasPayload(args.draft)) {
|
|
28
|
+
throw new Error('Composer pending message requires a non-empty draft'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
29
|
+
}
|
|
30
|
+
const now = args.now ?? Date.now();
|
|
31
|
+
return {
|
|
32
|
+
id: args.id ?? createPendingId(),
|
|
33
|
+
kind: args.kind,
|
|
34
|
+
draft: cloneUserTurnDraft(args.draft),
|
|
35
|
+
createdAt: now,
|
|
36
|
+
updatedAt: now,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function cloneUserTurnDraft(draft) {
|
|
40
|
+
return {
|
|
41
|
+
...(draft.text !== undefined ? { text: draft.text } : {}),
|
|
42
|
+
...(draft.attachments ? { attachments: draft.attachments.map((a) => ({ ...a })) } : {}),
|
|
43
|
+
...(draft.voice ? { voice: draft.voice.map((a) => ({ ...a })) } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Steer, then queue, then stash; FIFO within a kind. */
|
|
47
|
+
function orderComposerPendingMessages(messages) {
|
|
48
|
+
return [
|
|
49
|
+
...messages.filter((m) => m.kind === 'steer'),
|
|
50
|
+
...messages.filter((m) => m.kind === 'queue'),
|
|
51
|
+
...messages.filter((m) => m.kind === 'stash'),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
/** When a run ends, undelivered steers become queues ahead of the existing ones. */
|
|
55
|
+
function convertSteersToFrontQueued(messages, now = Date.now()) {
|
|
56
|
+
const steers = messages
|
|
57
|
+
.filter((m) => m.kind === 'steer')
|
|
58
|
+
.map((m) => ({
|
|
59
|
+
...m,
|
|
60
|
+
kind: 'queue',
|
|
61
|
+
updatedAt: now,
|
|
62
|
+
}));
|
|
63
|
+
const queues = messages.filter((m) => m.kind === 'queue');
|
|
64
|
+
const stashes = messages.filter((m) => m.kind === 'stash');
|
|
65
|
+
return [...steers, ...queues, ...stashes];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Drops the steers a turn event reports as landed in the conversation. A steer
|
|
69
|
+
* it never names stays pending, so the run's end requeues it.
|
|
70
|
+
*/
|
|
71
|
+
function removeLandedSteers(messages, event) {
|
|
72
|
+
if (event.type !== 'stage' || !event.injected?.length)
|
|
73
|
+
return [...messages];
|
|
74
|
+
const landed = new Set(event.injected.map((steer) => steer.id));
|
|
75
|
+
return messages.filter((m) => !(m.kind === 'steer' && landed.has(m.id)));
|
|
76
|
+
}
|
|
77
|
+
function removeComposerPendingMessage(messages, id) {
|
|
78
|
+
return messages.filter((m) => m.id !== id);
|
|
79
|
+
}
|
|
80
|
+
function updateComposerPendingDraft(messages, id, draft, now = Date.now()) {
|
|
81
|
+
if (!userDraftHasPayload(draft)) {
|
|
82
|
+
throw new Error('Composer pending message requires a non-empty draft'); // lexicon-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
83
|
+
}
|
|
84
|
+
return messages.map((m) => m.id === id
|
|
85
|
+
? {
|
|
86
|
+
...m,
|
|
87
|
+
draft: cloneUserTurnDraft(draft),
|
|
88
|
+
updatedAt: now,
|
|
89
|
+
}
|
|
90
|
+
: m);
|
|
91
|
+
}
|
|
92
|
+
function moveComposerPendingWithinKind(messages, id, direction) {
|
|
93
|
+
const message = messages.find((m) => m.id === id);
|
|
94
|
+
if (!message)
|
|
95
|
+
return [...messages];
|
|
96
|
+
const sameKind = messages.filter((m) => m.kind === message.kind);
|
|
97
|
+
const currentIndex = sameKind.findIndex((m) => m.id === id);
|
|
98
|
+
if (currentIndex < 0)
|
|
99
|
+
return orderComposerPendingMessages(messages);
|
|
100
|
+
const nextIndex = direction === 'up' ? currentIndex - 1 : currentIndex + 1;
|
|
101
|
+
if (nextIndex < 0 || nextIndex >= sameKind.length) {
|
|
102
|
+
return orderComposerPendingMessages(messages);
|
|
103
|
+
}
|
|
104
|
+
const reordered = [...sameKind];
|
|
105
|
+
const [removed] = reordered.splice(currentIndex, 1);
|
|
106
|
+
if (!removed)
|
|
107
|
+
return orderComposerPendingMessages(messages);
|
|
108
|
+
reordered.splice(nextIndex, 0, removed);
|
|
109
|
+
const byKind = {
|
|
110
|
+
steer: message.kind === 'steer' ? reordered : messages.filter((m) => m.kind === 'steer'),
|
|
111
|
+
queue: message.kind === 'queue' ? reordered : messages.filter((m) => m.kind === 'queue'),
|
|
112
|
+
stash: message.kind === 'stash' ? reordered : messages.filter((m) => m.kind === 'stash'),
|
|
113
|
+
};
|
|
114
|
+
return [...byKind.steer, ...byKind.queue, ...byKind.stash];
|
|
115
|
+
}
|
|
116
|
+
/** One steer per safe boundary: call once per `onStage` inject site. */
|
|
117
|
+
function consumeNextComposerSteer(messages) {
|
|
118
|
+
const message = messages.find((m) => m.kind === 'steer') ?? null;
|
|
119
|
+
if (!message)
|
|
120
|
+
return { message: null, remaining: [...messages] };
|
|
121
|
+
return {
|
|
122
|
+
message,
|
|
123
|
+
remaining: messages.filter((m) => m.id !== message.id),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** Call only after the agent run has fully ended, not on a tool pause. */
|
|
127
|
+
function consumeNextComposerQueue(messages) {
|
|
128
|
+
const message = messages.find((m) => m.kind === 'queue') ?? null;
|
|
129
|
+
if (!message)
|
|
130
|
+
return { message: null, remaining: [...messages] };
|
|
131
|
+
return {
|
|
132
|
+
message,
|
|
133
|
+
remaining: messages.filter((m) => m.id !== message.id),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function promoteComposerPendingKind(messages, id, kind, now = Date.now()) {
|
|
137
|
+
const updated = messages.map((m) => m.id === id
|
|
138
|
+
? {
|
|
139
|
+
...m,
|
|
140
|
+
kind,
|
|
141
|
+
updatedAt: now,
|
|
142
|
+
}
|
|
143
|
+
: m);
|
|
144
|
+
return orderComposerPendingMessages(updated);
|
|
145
|
+
}
|
|
146
|
+
export { cloneUserTurnDraft, composerPendingPreview, consumeNextComposerQueue, consumeNextComposerSteer, convertSteersToFrontQueued, createComposerPendingMessage, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, updateComposerPendingDraft, userDraftHasPayload, };
|