@theoremjs/agents 0.3.0 → 0.3.2
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/README.md +277 -995
- package/esm/mod.d.ts +34 -20
- package/esm/mod.js +19 -12
- package/esm/src/cli/commands/bench.js +36 -14
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -0
- package/esm/src/cli/commands/eval.d.ts +3 -3
- package/esm/src/cli/commands/fuzz-canary.js +55 -16
- package/esm/src/cli/commands/profile.js +4 -4
- package/esm/src/cli/commands/run.d.ts +2 -2
- package/esm/src/cli/commands/run.js +1 -1
- package/esm/src/cli/commands/test.d.ts +4 -3
- package/esm/src/cli/commands/test.js +2 -2
- package/esm/src/cli/index.js +9 -9
- package/esm/src/cli/matrix/fixtures.js +25 -30
- package/esm/src/evals/attachments.d.ts +1 -0
- package/esm/src/evals/attachments.js +4 -2
- package/esm/src/evals/breakdown.d.ts +2 -0
- package/esm/src/evals/breakdown.js +1 -0
- package/esm/src/evals/graders/answer.d.ts +3 -0
- package/esm/src/evals/graders/answer.js +1 -0
- package/esm/src/evals/graders/code.d.ts +7 -31
- package/esm/src/evals/graders/code.js +4 -25
- package/esm/src/evals/graders/judge.d.ts +4 -0
- package/esm/src/evals/graders/judge.js +7 -5
- package/esm/src/evals/graders/latency.d.ts +1 -0
- package/esm/src/evals/graders/latency.js +3 -2
- package/esm/src/evals/graders/live.d.ts +3 -0
- package/esm/src/evals/graders/live.js +2 -0
- package/esm/src/evals/graders/media.js +1 -2
- package/esm/src/evals/graders/shared.js +1 -1
- package/esm/src/evals/graders/transcript.d.ts +2 -0
- package/esm/src/evals/graders/transcript.js +5 -3
- package/esm/src/evals/mod.d.ts +1 -9
- package/esm/src/evals/mod.js +1 -9
- package/esm/src/evals/record.d.ts +6 -0
- package/esm/src/evals/record.js +4 -2
- package/esm/src/evals/rubrics/mod.d.ts +1 -1
- package/esm/src/evals/rubrics/mod.js +1 -1
- package/esm/src/evals/rubrics/mustache.js +1 -1
- package/esm/src/evals/rubrics/types.js +1 -1
- package/esm/src/evals/run.d.ts +9 -52
- package/esm/src/evals/run.js +12 -46
- package/esm/src/evals/suite.d.ts +12 -3
- package/esm/src/evals/suite.js +9 -4
- package/esm/src/evals/summary.d.ts +3 -0
- package/esm/src/evals/summary.js +1 -0
- package/esm/src/evals/trial.d.ts +3 -16
- package/esm/src/evals/trial.js +7 -30
- package/esm/src/evals/types.d.ts +30 -121
- package/esm/src/evals/types.js +3 -16
- package/esm/src/evals/verdict.d.ts +5 -0
- package/esm/src/evals/verdict.js +4 -1
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +1 -0
- package/esm/src/guardrails/canary.d.ts +49 -15
- package/esm/src/guardrails/canary.js +103 -30
- package/esm/src/guardrails/compile-egress.d.ts +6 -5
- package/esm/src/guardrails/compile-egress.js +6 -5
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +3 -1
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +4 -2
- package/esm/src/guardrails/corpus/fuzz-inbound.js +14 -17
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +2 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +4 -2
- package/esm/src/guardrails/corpus/live-attacks.d.ts +2 -0
- package/esm/src/guardrails/corpus/live-attacks.js +6 -1
- package/esm/src/guardrails/corpus/mod.d.ts +1 -1
- package/esm/src/guardrails/corpus/secrets.d.ts +3 -3
- package/esm/src/guardrails/corpus/secrets.js +2 -2
- package/esm/src/guardrails/corpus/strings.d.ts +1 -1
- package/esm/src/guardrails/corpus/strings.js +1 -1
- package/esm/src/guardrails/corpus/types.d.ts +5 -1
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +4 -6
- package/esm/src/guardrails/egress-automata.js +24095 -4572
- package/esm/src/guardrails/egress-compiler.d.ts +38 -16
- package/esm/src/guardrails/egress-compiler.js +254 -60
- package/esm/src/guardrails/egress-patterns.d.ts +4 -2
- package/esm/src/guardrails/egress-patterns.js +6 -2
- package/esm/src/guardrails/egress-stream.d.ts +54 -36
- package/esm/src/guardrails/egress-stream.js +253 -124
- package/esm/src/guardrails/egress-urls.d.ts +6 -3
- package/esm/src/guardrails/egress-urls.js +14 -22
- package/esm/src/guardrails/egress.d.ts +26 -86
- package/esm/src/guardrails/egress.js +59 -309
- package/esm/src/guardrails/error.d.ts +13 -8
- package/esm/src/guardrails/error.js +25 -18
- package/esm/src/guardrails/event-schemas.d.ts +46 -3
- package/esm/src/guardrails/event-schemas.js +12 -5
- package/esm/src/guardrails/events.d.ts +5 -1
- package/esm/src/guardrails/events.js +4 -1
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +7 -1
- package/esm/src/guardrails/hits.js +12 -1
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +6 -1
- package/esm/src/guardrails/injection-patterns.js +33 -1
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +17 -1
- package/esm/src/guardrails/injection.js +259 -36
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +881 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +9 -8
- package/esm/src/guardrails/live-outbound-gate.js +100 -107
- package/esm/src/guardrails/mod.d.ts +30 -22
- package/esm/src/guardrails/mod.js +19 -14
- package/esm/src/guardrails/network.d.ts +4 -0
- package/esm/src/guardrails/network.js +21 -19
- package/esm/src/guardrails/normalize.d.ts +15 -1
- package/esm/src/guardrails/normalize.js +34 -1
- package/esm/src/guardrails/policy.d.ts +2 -17
- package/esm/src/guardrails/policy.js +12 -41
- package/esm/src/guardrails/progressive-yield.d.ts +65 -24
- package/esm/src/guardrails/progressive-yield.js +191 -147
- package/esm/src/guardrails/prompt-echo.d.ts +4 -2
- package/esm/src/guardrails/prompt-echo.js +87 -6
- package/esm/src/guardrails/quota.d.ts +4 -1
- package/esm/src/guardrails/quota.js +7 -2
- package/esm/src/guardrails/rules.d.ts +20 -29
- package/esm/src/guardrails/rules.js +23 -30
- package/esm/src/guardrails/sanitize.d.ts +32 -15
- package/esm/src/guardrails/sanitize.js +100 -124
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +16 -23
- package/esm/src/guardrails/sensitive.js +168 -47
- package/esm/src/guardrails/serialize.d.ts +1 -0
- package/esm/src/guardrails/testing.d.ts +4 -2
- package/esm/src/guardrails/testing.js +4 -2
- package/esm/src/guardrails/theorem-error.d.ts +5 -2
- package/esm/src/guardrails/theorem-error.js +6 -3
- package/esm/src/guardrails/thought-guard.d.ts +34 -13
- package/esm/src/guardrails/thought-guard.js +264 -64
- package/esm/src/guardrails/tool-directives.d.ts +29 -10
- package/esm/src/guardrails/tool-directives.js +133 -47
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +45 -14
- package/esm/src/guardrails/tool-result.js +94 -70
- package/esm/src/guardrails/types.d.ts +79 -71
- package/esm/src/guardrails/types.js +11 -7
- package/esm/src/host/client-turn.d.ts +29 -2
- package/esm/src/host/client-turn.js +46 -4
- package/esm/src/host/mint-trace.d.ts +1 -0
- package/esm/src/host/mint-trace.js +3 -2
- package/esm/src/host/mod.d.ts +2 -2
- package/esm/src/host/mod.js +1 -1
- package/esm/src/host/readStreamingJsonStringField.js +2 -43
- package/esm/src/host/reply.d.ts +6 -0
- package/esm/src/host/reply.js +8 -1
- package/esm/src/interface/blocks.d.ts +3 -0
- package/esm/src/interface/blocks.js +84 -14
- package/esm/src/interface/composer-actions.d.ts +4 -0
- package/esm/src/interface/composer-actions.js +5 -3
- package/esm/src/interface/draft.d.ts +6 -0
- package/esm/src/interface/draft.js +22 -11
- package/esm/src/interface/from-profile.d.ts +13 -1
- package/esm/src/interface/from-profile.js +66 -31
- package/esm/src/interface/history.d.ts +9 -3
- package/esm/src/interface/history.js +33 -24
- package/esm/src/interface/inputs.d.ts +1 -0
- package/esm/src/interface/inputs.js +3 -0
- package/esm/src/interface/mod.d.ts +4 -2
- package/esm/src/interface/mod.js +3 -2
- package/esm/src/interface/models.d.ts +7 -0
- package/esm/src/interface/models.js +5 -0
- package/esm/src/interface/pending.d.ts +9 -0
- package/esm/src/interface/pending.js +9 -3
- package/esm/src/interface/profile-interface.js +54 -40
- package/esm/src/interface/session.d.ts +12 -5
- package/esm/src/interface/session.js +17 -10
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +14 -2
- package/esm/src/interface/tool-calls.js +64 -10
- package/esm/src/interface/tool-invoke.d.ts +2 -0
- package/esm/src/interface/tool-invoke.js +3 -1
- package/esm/src/interface/tool-media.d.ts +2 -0
- package/esm/src/interface/tool-media.js +2 -1
- package/esm/src/interface/types.d.ts +105 -40
- package/esm/src/interface/types.js +1 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -0
- package/esm/src/kernel/auth/crypto.d.ts +7 -2
- package/esm/src/kernel/auth/crypto.js +12 -10
- package/esm/src/kernel/auth/oauth.d.ts +2 -1
- package/esm/src/kernel/auth/oauth.js +23 -22
- package/esm/src/kernel/auth/typed-secret.js +2 -2
- package/esm/src/kernel/auth/types.d.ts +13 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +43 -5
- package/esm/src/kernel/default-scope.js +54 -5
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +6 -5
- package/esm/src/kernel/engine/compaction.js +12 -11
- package/esm/src/kernel/engine/decision.d.ts +10 -8
- package/esm/src/kernel/engine/decision.js +174 -146
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +14 -4
- package/esm/src/kernel/engine/live-inbound.js +36 -11
- package/esm/src/kernel/engine/live-ingress.d.ts +6 -0
- package/esm/src/kernel/engine/live-ingress.js +6 -1
- package/esm/src/kernel/engine/repair.js +12 -12
- package/esm/src/kernel/engine/runner/gates.d.ts +2 -2
- package/esm/src/kernel/engine/runner/gates.js +287 -101
- package/esm/src/kernel/engine/runner/mod.d.ts +19 -5
- package/esm/src/kernel/engine/runner/mod.js +107 -56
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +24 -3
- package/esm/src/kernel/engine/runner/schema-validation.js +78 -4
- package/esm/src/kernel/engine/runner/stages.d.ts +1 -1
- package/esm/src/kernel/engine/runner/stages.js +1 -8
- package/esm/src/kernel/engine/runner/state.d.ts +33 -12
- package/esm/src/kernel/engine/runner/state.js +11 -1
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +2 -2
- package/esm/src/kernel/engine/runner/steps.js +329 -169
- package/esm/src/kernel/engine/runner/stream.d.ts +42 -11
- package/esm/src/kernel/engine/runner/stream.js +197 -46
- package/esm/src/kernel/engine/runner/usage.d.ts +5 -5
- package/esm/src/kernel/engine/runner/usage.js +12 -14
- package/esm/src/kernel/engine/session/mod.d.ts +8 -6
- package/esm/src/kernel/engine/session/mod.js +360 -129
- package/esm/src/kernel/engine/session/session-trace.d.ts +10 -10
- package/esm/src/kernel/engine/session/session-trace.js +41 -30
- package/esm/src/kernel/engine/token-estimate.d.ts +10 -64
- package/esm/src/kernel/engine/token-estimate.js +14 -194
- package/esm/src/kernel/engine/tool-trace.d.ts +3 -3
- package/esm/src/kernel/engine/tool-trace.js +2 -1
- package/esm/src/kernel/engine/turn-trace.d.ts +8 -7
- package/esm/src/kernel/engine/turn-trace.js +28 -36
- package/esm/src/kernel/engine/usage.d.ts +6 -0
- package/esm/src/kernel/engine/usage.js +17 -0
- package/esm/src/kernel/interaction-parts.d.ts +3 -0
- package/esm/src/kernel/interaction-parts.js +18 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +38 -11
- package/esm/src/kernel/mod.js +22 -7
- package/esm/src/kernel/profile-graph.d.ts +11 -6
- package/esm/src/kernel/profile-graph.js +14 -7
- package/esm/src/kernel/profile-presence.d.ts +10 -1
- package/esm/src/kernel/profile-presence.js +90 -75
- package/esm/src/kernel/profile-scope.d.ts +7 -3
- package/esm/src/kernel/profile-scope.js +67 -55
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +15 -4
- package/esm/src/kernel/registry/attachments.js +31 -22
- package/esm/src/kernel/registry/catalog.d.ts +6 -0
- package/esm/src/kernel/registry/catalog.js +9 -2
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +6 -2
- package/esm/src/kernel/registry/ingress.js +55 -10
- package/esm/src/kernel/registry/kernel-registry.d.ts +3 -0
- package/esm/src/kernel/registry/kernel-registry.js +9 -2
- package/esm/src/kernel/registry/profile-outputs.js +4 -1
- package/esm/src/kernel/registry/profiles.d.ts +38 -14
- package/esm/src/kernel/registry/profiles.js +280 -205
- package/esm/src/kernel/registry/provider-request.d.ts +3 -3
- package/esm/src/kernel/registry/provider-request.js +5 -13
- package/esm/src/kernel/registry/resolve.d.ts +4 -1
- package/esm/src/kernel/registry/resolve.js +59 -58
- package/esm/src/kernel/registry/schemas.d.ts +3 -0
- package/esm/src/kernel/registry/schemas.js +3 -1
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -0
- package/esm/src/kernel/registry/system-prompt.js +7 -8
- package/esm/src/kernel/registry/vault.d.ts +14 -13
- package/esm/src/kernel/registry/vault.js +1 -14
- package/esm/src/kernel/schema.d.ts +100 -46
- package/esm/src/kernel/schema.js +499 -257
- package/esm/src/kernel/scope.d.ts +12 -5
- package/esm/src/kernel/scope.js +23 -3
- package/esm/src/kernel/stages.d.ts +38 -3
- package/esm/src/kernel/stages.js +82 -39
- package/esm/src/kernel/stop.d.ts +29 -6
- package/esm/src/kernel/stop.js +16 -4
- package/esm/src/kernel/system-parts.js +6 -6
- package/esm/src/kernel/tools/activity-label.d.ts +12 -6
- package/esm/src/kernel/tools/activity-label.js +258 -32
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +21 -6
- package/esm/src/kernel/tools/events.js +53 -18
- package/esm/src/kernel/tools/execute.d.ts +47 -11
- package/esm/src/kernel/tools/execute.js +508 -136
- package/esm/src/kernel/tools/gate-answer.d.ts +12 -2
- package/esm/src/kernel/tools/gate-answer.js +17 -6
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +1 -0
- package/esm/src/kernel/tools/harness.js +2 -1
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +27 -5
- package/esm/src/kernel/tools/invoke.js +223 -70
- package/esm/src/kernel/tools/mcp-sessions.d.ts +4 -1
- package/esm/src/kernel/tools/mcp-sessions.js +13 -8
- package/esm/src/kernel/tools/mod.d.ts +4 -3
- package/esm/src/kernel/tools/mod.js +3 -2
- package/esm/src/kernel/tools/model-text.d.ts +10 -5
- package/esm/src/kernel/tools/model-text.js +18 -12
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +11 -2
- package/esm/src/kernel/tools/permission.js +12 -12
- package/esm/src/kernel/tools/project.d.ts +4 -1
- package/esm/src/kernel/tools/project.js +32 -2
- package/esm/src/kernel/tools/registry.d.ts +9 -2
- package/esm/src/kernel/tools/registry.js +69 -10
- package/esm/src/kernel/tools/remote.d.ts +40 -6
- package/esm/src/kernel/tools/remote.js +219 -92
- package/esm/src/kernel/tools/resolve.d.ts +3 -0
- package/esm/src/kernel/tools/resolve.js +12 -4
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +3 -3
- package/esm/src/kernel/tools/schema.js +21 -100
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +2 -1
- package/esm/src/kernel/tools/signed-in-fetch.js +3 -3
- package/esm/src/kernel/tools/stage-run.d.ts +27 -4
- package/esm/src/kernel/tools/stage-run.js +75 -17
- package/esm/src/kernel/tools/types.d.ts +235 -25
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +208 -31
- package/esm/src/kernel/turn-events.js +127 -9
- package/esm/src/kernel/types.d.ts +302 -161
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +2 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +1 -0
- package/esm/src/observability/destinations.d.ts +5 -0
- package/esm/src/observability/destinations.js +7 -2
- package/esm/src/observability/jsonl.d.ts +2 -2
- package/esm/src/observability/jsonl.js +15 -22
- package/esm/src/observability/mod.d.ts +3 -3
- package/esm/src/observability/mod.js +2 -2
- package/esm/src/observability/openinference.d.ts +1 -1
- package/esm/src/observability/openinference.js +3 -3
- package/esm/src/observability/otlp.d.ts +3 -0
- package/esm/src/observability/otlp.js +3 -3
- package/esm/src/observability/phoenix.d.ts +1 -0
- package/esm/src/observability/policy.d.ts +3 -0
- package/esm/src/observability/policy.js +5 -1
- package/esm/src/observability/resolve-policy.js +11 -5
- package/esm/src/observability/spans.d.ts +8 -2
- package/esm/src/observability/spans.js +21 -5
- package/esm/src/observability/trace-catalog.d.ts +19 -2
- package/esm/src/observability/trace-catalog.js +130 -88
- package/esm/src/observability/trace-record.js +22 -17
- package/esm/src/observability/trace-schema.d.ts +3 -0
- package/esm/src/observability/trace-schema.js +1 -1
- package/esm/src/observability/trace-sink.d.ts +1 -0
- package/esm/src/observability/trace-sink.js +1 -1
- package/esm/src/observability/trace-span.d.ts +7 -1
- package/esm/src/observability/trace-span.js +3 -1
- package/esm/src/observability/trace.d.ts +2 -0
- package/esm/src/observability/trace.js +4 -2
- package/esm/src/observability/types.d.ts +35 -11
- package/esm/src/observability/types.js +1 -1
- package/esm/src/presets/google/speech-voices.d.ts +1 -0
- package/esm/src/presets/google-limits.d.ts +1 -0
- package/esm/src/presets/google.d.ts +27 -12
- package/esm/src/presets/google.js +34 -25
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +5 -4
- package/esm/src/presets/mod.js +4 -4
- package/esm/src/presets/openrouter.d.ts +14 -1
- package/esm/src/presets/openrouter.js +19 -1
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +102 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/api-error.d.ts +2 -0
- package/esm/src/providers/google/api-error.js +26 -18
- package/esm/src/providers/google/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -0
- package/esm/src/providers/google/grounding.d.ts +4 -4
- package/esm/src/providers/google/interactions/framing.d.ts +20 -8
- package/esm/src/providers/google/interactions/framing.js +85 -44
- package/esm/src/providers/google/interactions/steps.d.ts +5 -5
- package/esm/src/providers/google/interactions/steps.js +4 -4
- package/esm/src/providers/google/interactions/stream.d.ts +10 -11
- package/esm/src/providers/google/interactions/stream.js +33 -100
- package/esm/src/providers/google/live/framing.d.ts +15 -5
- package/esm/src/providers/google/live/framing.js +25 -25
- package/esm/src/providers/google/live/stream.d.ts +6 -44
- package/esm/src/providers/google/live/stream.js +4 -210
- package/esm/src/providers/google/urls.d.ts +1 -3
- package/esm/src/providers/google/urls.js +1 -3
- package/esm/src/providers/google/usage.js +2 -2
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +28 -7
- package/esm/src/providers/mod.js +19 -3
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +0 -9
- package/esm/src/providers/openrouter/image.js +0 -153
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/compat.js +6 -6
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -0
- package/esm/src/providers/shared/pcm.js +2 -2
- package/esm/src/providers/shared/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -0
- package/esm/src/providers/shared/response-identity.d.ts +2 -2
- package/esm/src/providers/shared/retry.d.ts +18 -0
- package/esm/src/providers/shared/retry.js +89 -0
- package/esm/src/providers/shared/sse.d.ts +0 -4
- package/esm/src/providers/shared/sse.js +50 -36
- package/esm/src/providers/shared/tool-args.d.ts +6 -7
- package/esm/src/providers/shared/tool-args.js +10 -6
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +2 -2
- package/esm/src/providers/shared/upstream-tape.js +1 -1
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +48 -16
- package/esm/src/providers/types.js +2 -1
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +19 -1
- package/esm/src/surface/formats.js +68 -29
- package/esm/src/surface/mod.d.ts +4 -2
- package/esm/src/surface/mod.js +4 -2
- package/esm/src/surface/runtime.d.ts +4 -0
- package/esm/src/surface/runtime.js +2 -0
- package/esm/src/surface/tools.d.ts +2 -8
- package/esm/src/surface/tools.js +4 -22
- package/esm/src/surface/types.d.ts +6 -0
- package/package.json +5 -13
- package/esm/src/cli/commands/egress-compile.d.ts +0 -17
- package/esm/src/cli/commands/egress-compile.js +0 -25
- package/esm/src/guardrails/egress-policy.d.ts +0 -27
- package/esm/src/guardrails/egress-policy.js +0 -76
- package/esm/src/guardrails/egress-rules.d.ts +0 -54
- package/esm/src/guardrails/egress-rules.js +0 -49
- package/esm/src/guardrails/lexicon.d.ts +0 -30
- package/esm/src/guardrails/lexicon.js +0 -478
- package/esm/src/kernel/engine/media-probe/audio.d.ts +0 -7
- package/esm/src/kernel/engine/media-probe/audio.js +0 -342
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +0 -6
- package/esm/src/kernel/engine/media-probe/bytes.js +0 -26
- package/esm/src/kernel/engine/media-probe/image.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/image.js +0 -171
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +0 -19
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +0 -48
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +0 -35
- package/esm/src/kernel/engine/media-probe/matroska.js +0 -226
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +0 -22
- package/esm/src/kernel/engine/media-probe/mp4.js +0 -279
- package/esm/src/kernel/engine/media-probe/opus.d.ts +0 -4
- package/esm/src/kernel/engine/media-probe/opus.js +0 -23
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/pdf.js +0 -117
- package/esm/src/kernel/engine/media-probe/video.d.ts +0 -15
- package/esm/src/kernel/engine/media-probe/video.js +0 -49
- package/esm/src/presets/typesafe.d.ts +0 -2
- package/esm/src/presets/typesafe.js +0 -2
- package/esm/src/providers/create-provider.d.ts +0 -21
- package/esm/src/providers/create-provider.js +0 -90
- package/esm/src/providers/decision/usage.d.ts +0 -3
- package/esm/src/providers/decision/usage.js +0 -25
- package/esm/src/providers/google/interactions/mod.d.ts +0 -2
- package/esm/src/providers/google/interactions/mod.js +0 -2
- package/esm/src/providers/google/keys.d.ts +0 -20
- package/esm/src/providers/google/keys.js +0 -87
- package/esm/src/providers/google/live/mod.d.ts +0 -7
- package/esm/src/providers/google/live/mod.js +0 -7
- package/esm/src/providers/google/live/openapi-schema.d.ts +0 -1
- package/esm/src/providers/google/live/openapi-schema.js +0 -42
- package/esm/src/providers/google/live/session.d.ts +0 -14
- package/esm/src/providers/google/live/session.js +0 -150
- package/esm/src/providers/local/local.d.ts +0 -12
- package/esm/src/providers/local/local.js +0 -186
- package/esm/src/providers/local/mod.d.ts +0 -8
- package/esm/src/providers/local/mod.js +0 -8
- package/esm/src/providers/openrouter/cache-control.d.ts +0 -5
- package/esm/src/providers/openrouter/cache-control.js +0 -4
- package/esm/src/providers/openrouter/chat.d.ts +0 -64
- package/esm/src/providers/openrouter/chat.js +0 -490
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +0 -10
- package/esm/src/providers/openrouter/openai/sdk-messages.js +0 -99
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +0 -3
- package/esm/src/providers/openrouter/resolve-api-key.js +0 -8
- package/esm/src/providers/openrouter/speech.d.ts +0 -18
- package/esm/src/providers/openrouter/speech.js +0 -109
- package/esm/src/providers/probe.d.ts +0 -5
- package/esm/src/providers/probe.js +0 -15
- package/esm/src/providers/shared/builtin-wire.d.ts +0 -4
- package/esm/src/providers/shared/builtin-wire.js +0 -9
- package/esm/src/providers/shared/vault.d.ts +0 -13
- package/esm/src/providers/shared/vault.js +0 -41
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
// `profileInterfaceSchema` keeps only the JSON it names, so host functions never reach the view.
|
|
2
|
-
import {
|
|
3
|
-
import { clientLexicon } from '../guardrails/lexicon.js';
|
|
1
|
+
// why: `profileInterfaceSchema` keeps only the JSON it names, so host functions never reach the view.
|
|
2
|
+
import { clientLabels } from '../guardrails/labels.js';
|
|
4
3
|
import { resolveGuardrailPolicy } from '../guardrails/policy.js';
|
|
5
4
|
import { projectProfileObject, requireModelProfile } from '../kernel/registry/resolve.js';
|
|
6
5
|
import { profileAllowsSteering } from '../kernel/stop.js';
|
|
7
|
-
import { profileToolAllow, profileToolsSpec } from '../kernel/tools/resolve.js';
|
|
6
|
+
import { profileToolAllow, profileToolsParallel, profileToolsSpec, } from '../kernel/tools/resolve.js';
|
|
8
7
|
import { resolveObservabilityPolicy } from '../observability/resolve-policy.js';
|
|
9
8
|
import { inputsFromSpec } from './inputs.js';
|
|
10
9
|
import { profileInterfaceSchema } from './profile-interface.js';
|
|
11
10
|
/** Resolved, not raw: a host sees what the kernel will enforce, not defaults of its own. */
|
|
12
11
|
function guardrailsView(guardrails) {
|
|
13
12
|
const policy = resolveGuardrailPolicy(guardrails);
|
|
13
|
+
const { sources, host, ...detect } = policy.detect;
|
|
14
14
|
return {
|
|
15
15
|
quota: policy.quota,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
detect,
|
|
17
|
+
...(sources
|
|
18
|
+
? {
|
|
19
|
+
patterns: Object.fromEntries(Object.entries(sources).map(([detector, { theorem, matchers }]) => [
|
|
20
|
+
detector,
|
|
21
|
+
{ theorem, names: matchers.map(({ name }) => name) },
|
|
22
|
+
])),
|
|
23
|
+
}
|
|
24
|
+
: {}),
|
|
25
|
+
...(host
|
|
26
|
+
? {
|
|
27
|
+
host: host.map(({ id, label, actions, matchers, find }) => ({
|
|
28
|
+
id,
|
|
29
|
+
label,
|
|
30
|
+
actions,
|
|
31
|
+
names: matchers.map(({ name }) => name),
|
|
32
|
+
find: Boolean(find),
|
|
33
|
+
})),
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
36
|
+
allow: {
|
|
37
|
+
ungiven_images: urlAllowView(policy.allow.ungiven_images),
|
|
38
|
+
ungiven_links: urlAllowView(policy.allow.ungiven_links),
|
|
39
|
+
},
|
|
40
|
+
blockedReply: policy.blockedReply,
|
|
21
41
|
};
|
|
22
42
|
}
|
|
23
|
-
function
|
|
24
|
-
return
|
|
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
|
-
};
|
|
43
|
+
function urlAllowView(allow) {
|
|
44
|
+
return { hosts: [...(allow.hosts ?? [])], fromTools: allow.fromTools ?? true };
|
|
36
45
|
}
|
|
37
46
|
function writeToView(writeTo) {
|
|
38
47
|
if (writeTo === undefined || writeTo === false) {
|
|
@@ -61,15 +70,33 @@ function observabilityView(observability) {
|
|
|
61
70
|
hasOnWriteError: Boolean(policy.onWriteError),
|
|
62
71
|
};
|
|
63
72
|
}
|
|
73
|
+
/** The live settings a client reads. The greeting and resume prompts are the host's, like `identity.system`. */
|
|
74
|
+
function liveView(live) {
|
|
75
|
+
const { greeting: _greeting, resumed: _resumed, ...view } = live ?? {};
|
|
76
|
+
return view;
|
|
77
|
+
}
|
|
64
78
|
function toolsView(projected, profile) {
|
|
79
|
+
const page = projected.tools
|
|
80
|
+
.filter((tool) => 'type' in tool && tool.type === 'function' && tool.answeredBy === 'page')
|
|
81
|
+
.map((tool) => tool.name);
|
|
65
82
|
if (profile) {
|
|
66
|
-
const
|
|
67
|
-
|
|
83
|
+
const spec = profileToolsSpec(profile);
|
|
84
|
+
const parallel = profileToolsParallel(profile);
|
|
85
|
+
return {
|
|
86
|
+
allow: [...profileToolAllow(profile)],
|
|
87
|
+
page,
|
|
88
|
+
...(spec?.t2Loader ? { t2Loader: spec.t2Loader } : {}),
|
|
89
|
+
...(parallel !== undefined ? { parallel } : {}),
|
|
90
|
+
};
|
|
68
91
|
}
|
|
69
92
|
const allow = projected.tools
|
|
70
93
|
.filter((tool) => !('type' in tool && tool.type === 'builtin'))
|
|
71
94
|
.map((tool) => tool.name);
|
|
72
|
-
return { allow };
|
|
95
|
+
return { allow, page };
|
|
96
|
+
}
|
|
97
|
+
/** A call has no T2 loader. */
|
|
98
|
+
function liveToolsView({ allow, page }) {
|
|
99
|
+
return { allow, page };
|
|
73
100
|
}
|
|
74
101
|
function enrich(projected, profile) {
|
|
75
102
|
const inputs = inputsFromSpec(projected.inputs);
|
|
@@ -84,11 +111,11 @@ function enrich(projected, profile) {
|
|
|
84
111
|
defaultModel: projected.defaultModel,
|
|
85
112
|
allowModelSelect: projected.allowModelSelect,
|
|
86
113
|
maxSteps: projected.maxSteps,
|
|
87
|
-
|
|
114
|
+
providerContinuation: projected.providerContinuation,
|
|
88
115
|
outputs,
|
|
89
116
|
guardrails,
|
|
90
117
|
observability,
|
|
91
|
-
|
|
118
|
+
labels: clientLabels(profile?.labels),
|
|
92
119
|
};
|
|
93
120
|
switch (projected.type) {
|
|
94
121
|
case 'text':
|
|
@@ -124,8 +151,9 @@ function enrich(projected, profile) {
|
|
|
124
151
|
return profileInterfaceSchema.parse({
|
|
125
152
|
...shared,
|
|
126
153
|
type: 'live',
|
|
127
|
-
live: projected.live
|
|
128
|
-
|
|
154
|
+
live: liveView(projected.live),
|
|
155
|
+
...(projected.inputs ? { inputs: { slots: inputs.slots, context: inputs.context } } : {}),
|
|
156
|
+
tools: liveToolsView(toolsView(projected, profile)),
|
|
129
157
|
});
|
|
130
158
|
default: {
|
|
131
159
|
const exhaustive = projected.type;
|
|
@@ -133,12 +161,19 @@ function enrich(projected, profile) {
|
|
|
133
161
|
}
|
|
134
162
|
}
|
|
135
163
|
}
|
|
164
|
+
/** The interface for any profile. */
|
|
136
165
|
function interfaceFromProfile(input, tools) {
|
|
137
|
-
// Host profiles never run a model and have no composer surface.
|
|
166
|
+
// why: Host profiles never run a model and have no composer surface.
|
|
138
167
|
const profile = requireModelProfile(input, 'interfaceFromProfile');
|
|
139
168
|
return enrich(projectProfileObject(tools, profile), profile);
|
|
140
169
|
}
|
|
170
|
+
/** The interface for a profile the host has already projected, without resolving its tools again. */
|
|
141
171
|
function interfaceFromProjected(projected) {
|
|
142
172
|
return enrich(projected);
|
|
143
173
|
}
|
|
144
|
-
|
|
174
|
+
/** The client-safe interface for any profile. */
|
|
175
|
+
function clientProfileInterface(input, tools) {
|
|
176
|
+
const iface = interfaceFromProfile(input, tools);
|
|
177
|
+
return { ...iface, identity: { handle: iface.identity.handle } };
|
|
178
|
+
}
|
|
179
|
+
export { clientProfileInterface, interfaceFromProfile, interfaceFromProjected };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
1
|
+
import { type LabelOverrides } from '../guardrails/labels.js';
|
|
2
|
+
import { type ToolCallRequest } from '../kernel/turn-events.js';
|
|
3
3
|
import type { TurnBlob, TurnEvent, TurnHistoryMessage } from '../kernel/types.js';
|
|
4
4
|
import type { ToolCall, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
5
5
|
/**
|
|
@@ -7,21 +7,26 @@ import type { ToolCall, TranscriptBlock, UserTurnDraft } from './types.js';
|
|
|
7
7
|
* come from a run and has no text the model read.
|
|
8
8
|
*/
|
|
9
9
|
declare function toolReadBack(call: ToolCall): string;
|
|
10
|
+
/** The files a user turn adds to the history beside its text. */
|
|
10
11
|
export type UserTurnHistoryMedia = {
|
|
11
12
|
attachments?: TurnBlob[];
|
|
12
13
|
voice?: TurnBlob[];
|
|
13
14
|
};
|
|
14
15
|
/** For `onStage` inject. Uses base64 on `draft.attachments` / `draft.voice` when present. */
|
|
15
16
|
declare function userDraftToSteerInject(draft: UserTurnDraft): TurnHistoryMessage[];
|
|
17
|
+
/** The history with the user's draft added as a user message. */
|
|
16
18
|
declare function appendUserDraftToHistory(history: TurnHistoryMessage[], draft: UserTurnDraft, media?: UserTurnHistoryMedia): TurnHistoryMessage[];
|
|
19
|
+
/** The history with a tool call and its result added. */
|
|
17
20
|
declare function appendToolExchangeToHistory(history: TurnHistoryMessage[], call: ToolCall): TurnHistoryMessage[];
|
|
21
|
+
/** The history with a denied tool call and the reason added. */
|
|
18
22
|
declare function appendToolDenialToHistory(history: TurnHistoryMessage[], tool: ToolCallRequest & {
|
|
19
23
|
/** Override the default deny copy. */
|
|
20
24
|
failure?: {
|
|
21
25
|
code: string;
|
|
22
26
|
message: string;
|
|
23
27
|
};
|
|
24
|
-
},
|
|
28
|
+
}, labels: LabelOverrides | undefined): TurnHistoryMessage[];
|
|
29
|
+
/** The history with the assistant's reply from the turn events added. */
|
|
25
30
|
declare function appendAssistantEventsToHistory(history: TurnHistoryMessage[], events: readonly TurnEvent[]): TurnHistoryMessage[];
|
|
26
31
|
/**
|
|
27
32
|
* A reply paused on its gates, as the model reads it when the user walks away:
|
|
@@ -31,6 +36,7 @@ declare function appendAssistantEventsToHistory(history: TurnHistoryMessage[], e
|
|
|
31
36
|
declare function appendPausedTurnToHistory(history: TurnHistoryMessage[], events: readonly TurnEvent[]): TurnHistoryMessage[];
|
|
32
37
|
/** Attachment and voice blocks are omitted: their preview `data` is UI-only. */
|
|
33
38
|
declare function historyFromTranscriptBlocks(blocks: readonly TranscriptBlock[]): TurnHistoryMessage[];
|
|
39
|
+
/** Throws unless the history's open tool calls are exactly these ids. */
|
|
34
40
|
declare function assertOpenToolCalls(history: readonly TurnHistoryMessage[], ids: readonly string[]): void;
|
|
35
41
|
/**
|
|
36
42
|
* `answers` holds, by call id, the text the model reads for each open call. Results follow their
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// A settled tool call replays its `readBack`, the text the model read, so provider continuation
|
|
1
|
+
// invariant: A settled tool call replays its `readBack`, the text the model read, so provider continuation
|
|
2
2
|
// matches `runTurn` / `invokeTool`.
|
|
3
3
|
import { TheoremError } from '../guardrails/error.js';
|
|
4
|
-
import {
|
|
4
|
+
import { labelText } from '../guardrails/labels.js';
|
|
5
5
|
import { mediaKindForMime } from '../kernel/registry/catalog.js';
|
|
6
6
|
import { formatToolFailureForModel, formatToolResult } from '../kernel/tools/model-text.js';
|
|
7
|
+
import { keptReply } from '../kernel/turn-events.js';
|
|
7
8
|
import { applyToolEvent, toolCallRanWith } from './tool-calls.js';
|
|
8
9
|
/**
|
|
9
10
|
* The kernel sets `readBack` on every `complete` and `error` event, so a call without it did not
|
|
@@ -35,6 +36,7 @@ function userDraftToSteerInject(draft) {
|
|
|
35
36
|
...(voice ? { voice } : {}),
|
|
36
37
|
});
|
|
37
38
|
}
|
|
39
|
+
/** The history with the user's draft added as a user message. */
|
|
38
40
|
function appendUserDraftToHistory(history, draft, media = {}) {
|
|
39
41
|
const text = draft.text?.trim();
|
|
40
42
|
const parts = [];
|
|
@@ -60,19 +62,24 @@ function toolCallEntry(tool) {
|
|
|
60
62
|
id: tool.callId,
|
|
61
63
|
type: 'function',
|
|
62
64
|
function: { name: tool.name, arguments: JSON.stringify(tool.arguments) },
|
|
63
|
-
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** The assistant message holding a step's calls, with the reasoning the model wrote before them. */
|
|
68
|
+
function assistantCalls(tools) {
|
|
69
|
+
const reasoning = tools.flatMap((tool) => tool.reasoning ?? []);
|
|
70
|
+
return {
|
|
71
|
+
role: 'assistant',
|
|
72
|
+
tool_calls: tools.map(toolCallEntry),
|
|
73
|
+
...(reasoning.length ? { reasoning } : {}),
|
|
64
74
|
};
|
|
65
75
|
}
|
|
66
76
|
function toolResultMessage(tool, content) {
|
|
67
77
|
return { role: 'tool', tool_call_id: tool.callId, name: tool.name, content };
|
|
68
78
|
}
|
|
69
79
|
function appendToolCallPair(history, tool, content) {
|
|
70
|
-
return [
|
|
71
|
-
...history,
|
|
72
|
-
{ role: 'assistant', tool_calls: [toolCallEntry(tool)] },
|
|
73
|
-
toolResultMessage(tool, content),
|
|
74
|
-
];
|
|
80
|
+
return [...history, assistantCalls([tool]), toolResultMessage(tool, content)];
|
|
75
81
|
}
|
|
82
|
+
/** The history with a tool call and its result added. */
|
|
76
83
|
function appendToolExchangeToHistory(history, call) {
|
|
77
84
|
return appendToolCallPair(history, historyToolCall(call), toolReadBack(call));
|
|
78
85
|
}
|
|
@@ -81,13 +88,14 @@ function historyToolCall(call) {
|
|
|
81
88
|
name: call.name,
|
|
82
89
|
callId: call.callId,
|
|
83
90
|
arguments: toolCallRanWith(call),
|
|
84
|
-
...(call.
|
|
91
|
+
...(call.reasoning ? { reasoning: call.reasoning } : {}),
|
|
85
92
|
};
|
|
86
93
|
}
|
|
87
|
-
|
|
94
|
+
/** The history with a denied tool call and the reason added. */
|
|
95
|
+
function appendToolDenialToHistory(history, tool, labels) {
|
|
88
96
|
const failure = tool.failure ?? {
|
|
89
97
|
code: 'denied',
|
|
90
|
-
message:
|
|
98
|
+
message: labelText('session.tool_denied', { tool: tool.name }, labels),
|
|
91
99
|
};
|
|
92
100
|
return appendToolCallPair(history, tool, formatToolResult(formatToolFailureForModel(failure)));
|
|
93
101
|
}
|
|
@@ -98,8 +106,8 @@ function settledToolContent(call) {
|
|
|
98
106
|
}
|
|
99
107
|
/**
|
|
100
108
|
* One model step's settled calls: a single assistant message holding every call
|
|
101
|
-
* the step made, then each result. Google replays a
|
|
102
|
-
*
|
|
109
|
+
* the step made, with the reasoning written before them, then each result. Google replays a
|
|
110
|
+
* step's calls only this way. With `gated: 'open'`, a
|
|
103
111
|
* call waiting on its gate joins the message too, left without a result.
|
|
104
112
|
*/
|
|
105
113
|
function appendToolStepToHistory(history, calls, gated = 'omit') {
|
|
@@ -115,10 +123,11 @@ function appendToolStepToHistory(history, calls, gated = 'omit') {
|
|
|
115
123
|
return history;
|
|
116
124
|
return [
|
|
117
125
|
...history,
|
|
118
|
-
|
|
126
|
+
assistantCalls(entries.map(({ tool }) => tool)),
|
|
119
127
|
...entries.flatMap(({ tool, content }) => content === undefined ? [] : [toolResultMessage(tool, content)]),
|
|
120
128
|
];
|
|
121
129
|
}
|
|
130
|
+
/** The history with the assistant's reply from the turn events added. */
|
|
122
131
|
function appendAssistantEventsToHistory(history, events) {
|
|
123
132
|
return foldAssistantEvents(history, events, 'omit');
|
|
124
133
|
}
|
|
@@ -133,7 +142,6 @@ function appendPausedTurnToHistory(history, events) {
|
|
|
133
142
|
function foldAssistantEvents(history, events, gated) {
|
|
134
143
|
let next = history;
|
|
135
144
|
let textBuf = '';
|
|
136
|
-
// The calls of the step being read, in the order the model made them.
|
|
137
145
|
let step;
|
|
138
146
|
const calls = new Map();
|
|
139
147
|
const flushText = () => {
|
|
@@ -147,11 +155,11 @@ function foldAssistantEvents(history, events, gated) {
|
|
|
147
155
|
if (!step) {
|
|
148
156
|
return;
|
|
149
157
|
}
|
|
150
|
-
const stepCalls = step.
|
|
158
|
+
const stepCalls = step.callKeys.flatMap((id) => calls.get(id) ?? []);
|
|
151
159
|
next = appendToolStepToHistory(next, stepCalls, gated);
|
|
152
160
|
step = undefined;
|
|
153
161
|
};
|
|
154
|
-
for (const event of events) {
|
|
162
|
+
for (const event of keptReply(events)) {
|
|
155
163
|
if (event.type === 'text') {
|
|
156
164
|
flushStep();
|
|
157
165
|
textBuf += event.text;
|
|
@@ -159,25 +167,26 @@ function foldAssistantEvents(history, events, gated) {
|
|
|
159
167
|
}
|
|
160
168
|
if (event.type === 'structured' && event.structured !== undefined) {
|
|
161
169
|
flushStep();
|
|
162
|
-
|
|
170
|
+
// why: The streamed text is this reply's JSON as the model wrote it; the structured output is the reply as kept.
|
|
171
|
+
textBuf = '';
|
|
163
172
|
next = [...next, { role: 'assistant', content: JSON.stringify(event.structured) }];
|
|
164
173
|
continue;
|
|
165
174
|
}
|
|
166
175
|
if (event.type !== 'tool') {
|
|
167
176
|
continue;
|
|
168
177
|
}
|
|
169
|
-
const
|
|
170
|
-
calls.
|
|
178
|
+
const key = event.tool.operationId ?? event.tool.callId;
|
|
179
|
+
const call = applyToolEvent(calls.get(key), event.tool);
|
|
180
|
+
calls.set(key, call);
|
|
171
181
|
if (event.tool.phase !== undefined) {
|
|
172
182
|
continue;
|
|
173
183
|
}
|
|
174
|
-
// A call opens its step, or joins the one it was made with.
|
|
175
184
|
if (!step || call.stepId === undefined || step.stepId !== call.stepId) {
|
|
176
185
|
flushStep();
|
|
177
186
|
flushText();
|
|
178
|
-
step = { stepId: call.stepId,
|
|
187
|
+
step = { stepId: call.stepId, callKeys: [] };
|
|
179
188
|
}
|
|
180
|
-
step.
|
|
189
|
+
step.callKeys.push(key);
|
|
181
190
|
}
|
|
182
191
|
flushStep();
|
|
183
192
|
flushText();
|
|
@@ -186,7 +195,6 @@ function foldAssistantEvents(history, events, gated) {
|
|
|
186
195
|
/** Attachment and voice blocks are omitted: their preview `data` is UI-only. */
|
|
187
196
|
function historyFromTranscriptBlocks(blocks) {
|
|
188
197
|
let history = [];
|
|
189
|
-
// Consecutive tool blocks from one model step replay together.
|
|
190
198
|
let step = [];
|
|
191
199
|
const flushStep = () => {
|
|
192
200
|
history = appendToolStepToHistory(history, step);
|
|
@@ -238,6 +246,7 @@ function openToolCallIds(history) {
|
|
|
238
246
|
function openCallsMismatch(history, ids) {
|
|
239
247
|
return new TheoremError('request', `the history leaves open [${openToolCallIds(history).join(', ')}], not [${ids.join(', ')}]`);
|
|
240
248
|
}
|
|
249
|
+
/** Throws unless the history's open tool calls are exactly these ids. */
|
|
241
250
|
function assertOpenToolCalls(history, ids) {
|
|
242
251
|
const open = openToolCallIds(history);
|
|
243
252
|
if (open.length !== ids.length || open.some((id) => !ids.includes(id))) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ProfileInputsSpec } from '../kernel/types.js';
|
|
2
2
|
import type { AttachmentValidationResult, ProfileInputsInterface, UserTurnDraft } from './types.js';
|
|
3
|
+
/** The accepted MIME types as the value of an HTML `accept` attribute, comma-joined. */
|
|
3
4
|
declare function attachmentAcceptAttr(accept: string[]): string;
|
|
4
5
|
/** `inputs` is null for profile types that declare none (the kernel's `profileInputs`). */
|
|
5
6
|
declare function inputsFromSpec(inputs: ProfileInputsSpec | null | undefined): ProfileInputsInterface;
|
|
@@ -7,6 +7,7 @@ const RECORDER_CANDIDATES = [
|
|
|
7
7
|
'audio/wav',
|
|
8
8
|
'audio/mpeg',
|
|
9
9
|
];
|
|
10
|
+
/** The accepted MIME types as the value of an HTML `accept` attribute, comma-joined. */
|
|
10
11
|
function attachmentAcceptAttr(accept) {
|
|
11
12
|
return accept.join(',');
|
|
12
13
|
}
|
|
@@ -23,6 +24,7 @@ function inputsFromSpec(inputs) {
|
|
|
23
24
|
maxTurnBytes: inputs?.maxTurnBytes,
|
|
24
25
|
limitsByMime: inputs?.limitsByMime,
|
|
25
26
|
slots: inputs?.slots,
|
|
27
|
+
context: inputs?.context,
|
|
26
28
|
};
|
|
27
29
|
}
|
|
28
30
|
function toProfileInputsSpec(inputs) {
|
|
@@ -35,6 +37,7 @@ function toProfileInputsSpec(inputs) {
|
|
|
35
37
|
maxTurnBytes: inputs.maxTurnBytes,
|
|
36
38
|
limitsByMime: inputs.limitsByMime,
|
|
37
39
|
slots: inputs.slots,
|
|
40
|
+
context: inputs.context,
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
/** Validate staged files against resolved profile `inputs`: the kernel's one attachment check. */
|
|
@@ -11,7 +11,7 @@ export type { ComposerActionContext, ComposerMenuAction, ComposerPrimaryAction,
|
|
|
11
11
|
export { resolveComposerMenuActions, resolveComposerPrimary } from './composer-actions.js';
|
|
12
12
|
export type { PrepareUserTurnResult } from './draft.js';
|
|
13
13
|
export { prepareUserTurn, sanitizeUserDraft } from './draft.js';
|
|
14
|
-
export { interfaceFromProfile, interfaceFromProjected } from './from-profile.js';
|
|
14
|
+
export { clientProfileInterface, interfaceFromProfile, interfaceFromProjected, } from './from-profile.js';
|
|
15
15
|
export type { UserTurnHistoryMedia } from './history.js';
|
|
16
16
|
export { answerOpenToolCalls, appendAssistantEventsToHistory, appendPausedTurnToHistory, appendToolDenialToHistory, appendToolExchangeToHistory, appendUserDraftToHistory, assertOpenToolCalls, historyFromTranscriptBlocks, toolReadBack, userDraftToSteerInject, } from './history.js';
|
|
17
17
|
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs, } from './inputs.js';
|
|
@@ -22,8 +22,10 @@ export { COMPOSER_PENDING_KINDS, cloneUserTurnDraft, composerPendingPreview, con
|
|
|
22
22
|
export { profileInterfaceSchema } from './profile-interface.js';
|
|
23
23
|
export type { AwaitingToolContext, GatedToolContext, InterfaceTurnSession, ToolGateAuth, } from './session.js';
|
|
24
24
|
export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSession, emptyInterfaceTurnSession, gatedToolFromEvents, gatedToolsFromEvents, } from './session.js';
|
|
25
|
+
export type { WordedStopKind } from './stop.js';
|
|
26
|
+
export { stopText, WORDED_STOP_KINDS } from './stop.js';
|
|
25
27
|
export type { SettledToolCallEvent } from './tool-calls.js';
|
|
26
|
-
export { settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
|
|
28
|
+
export { argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
|
|
27
29
|
export { promotedToolIdsFromEvents, toolSnapshotFromEvents } from './tool-invoke.js';
|
|
28
30
|
export type { PromotedToolMedia } from './tool-media.js';
|
|
29
31
|
export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
|
package/esm/src/interface/mod.js
CHANGED
|
@@ -8,14 +8,15 @@ import "../../_dnt.polyfills.js";
|
|
|
8
8
|
export { buildUserTurnBlocks, foldConversationTurn, foldTurnEvents, resetBlockIds, } from './blocks.js';
|
|
9
9
|
export { resolveComposerMenuActions, resolveComposerPrimary } from './composer-actions.js';
|
|
10
10
|
export { prepareUserTurn, sanitizeUserDraft } from './draft.js';
|
|
11
|
-
export { interfaceFromProfile, interfaceFromProjected } from './from-profile.js';
|
|
11
|
+
export { clientProfileInterface, interfaceFromProfile, interfaceFromProjected, } from './from-profile.js';
|
|
12
12
|
export { answerOpenToolCalls, appendAssistantEventsToHistory, appendPausedTurnToHistory, appendToolDenialToHistory, appendToolExchangeToHistory, appendUserDraftToHistory, assertOpenToolCalls, historyFromTranscriptBlocks, toolReadBack, userDraftToSteerInject, } from './history.js';
|
|
13
13
|
export { attachmentAcceptAttr, inputsFromSpec, pickMediaRecorderMime, validateProfileInputs, } from './inputs.js';
|
|
14
14
|
export { defaultInterfaceEffort, effortSelectEnabled, generationSelectEnabled, interfaceEffortOptions, interfaceModelOptions, modelSelectEnabled, } from './models.js';
|
|
15
15
|
export { COMPOSER_PENDING_KINDS, cloneUserTurnDraft, composerPendingPreview, consumeNextComposerQueue, consumeNextComposerSteer, convertSteersToFrontQueued, createComposerPendingMessage, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, updateComposerPendingDraft, userDraftHasPayload, } from './pending.js';
|
|
16
16
|
export { profileInterfaceSchema } from './profile-interface.js';
|
|
17
17
|
export { applyTurnEventsToSession, awaitingFromEvents, branchInterfaceTurnSession, emptyInterfaceTurnSession, gatedToolFromEvents, gatedToolsFromEvents, } from './session.js';
|
|
18
|
-
export {
|
|
18
|
+
export { stopText, WORDED_STOP_KINDS } from './stop.js';
|
|
19
|
+
export { argumentsSoFar, settlesToolCall, toolCallRanWith, toolCallsOf } from './tool-calls.js';
|
|
19
20
|
export { promotedToolIdsFromEvents, toolSnapshotFromEvents } from './tool-invoke.js';
|
|
20
21
|
export { collectPromotedMediaFromToolOutput, promotedMediaFromUrlString, } from './tool-media.js';
|
|
21
22
|
export { streamThoughtsEnabled } from './types.js';
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import type { ModelId } from '../kernel/types.js';
|
|
2
2
|
import type { ComposerProfileInterface } from './types.js';
|
|
3
3
|
export type ModelSelectProfile = Pick<ComposerProfileInterface, 'id' | 'models' | 'defaultModel' | 'allowModelSelect'>;
|
|
4
|
+
/** One model a user can pick from. */
|
|
4
5
|
export type InterfaceModelOption = {
|
|
5
6
|
id: ModelId;
|
|
6
7
|
label: string;
|
|
7
8
|
};
|
|
9
|
+
/** One effort level a user can pick from, by alias. */
|
|
8
10
|
export type InterfaceEffortOption = {
|
|
9
11
|
alias: string;
|
|
10
12
|
level: string;
|
|
11
13
|
};
|
|
14
|
+
/** True when the profile lets the user pick between two or more models. */
|
|
12
15
|
declare function modelSelectEnabled(profile: ModelSelectProfile): boolean;
|
|
16
|
+
/** True when the model lets the user pick between two or more effort levels. */
|
|
13
17
|
declare function effortSelectEnabled(profile: ModelSelectProfile, modelId: ModelId | undefined): boolean;
|
|
18
|
+
/** True when the user has any model or effort choice to make. */
|
|
14
19
|
declare function generationSelectEnabled(profile: ModelSelectProfile, modelId: ModelId | undefined): boolean;
|
|
15
20
|
/** `defaultEffort` when it names an alias, else the first alias. */
|
|
16
21
|
declare function defaultInterfaceEffort(profile: ModelSelectProfile, modelId: ModelId | undefined): string | undefined;
|
|
22
|
+
/** The models the user can pick from, or none when the choice is off. */
|
|
17
23
|
declare function interfaceModelOptions(profile: ModelSelectProfile): InterfaceModelOption[];
|
|
24
|
+
/** The effort levels the user can pick from for this model, or none when the choice is off. */
|
|
18
25
|
declare function interfaceEffortOptions(profile: ModelSelectProfile, modelId: ModelId | undefined): InterfaceEffortOption[];
|
|
19
26
|
export { defaultInterfaceEffort, effortSelectEnabled, generationSelectEnabled, interfaceEffortOptions, interfaceModelOptions, modelSelectEnabled, };
|
|
@@ -3,15 +3,18 @@ function bindingFor(profile, modelId) {
|
|
|
3
3
|
return undefined;
|
|
4
4
|
return profile.models[modelId];
|
|
5
5
|
}
|
|
6
|
+
/** True when the profile lets the user pick between two or more models. */
|
|
6
7
|
function modelSelectEnabled(profile) {
|
|
7
8
|
return Boolean(profile.allowModelSelect && Object.keys(profile.models).length >= 2);
|
|
8
9
|
}
|
|
10
|
+
/** True when the model lets the user pick between two or more effort levels. */
|
|
9
11
|
function effortSelectEnabled(profile, modelId) {
|
|
10
12
|
const binding = bindingFor(profile, modelId);
|
|
11
13
|
if (!binding?.allowEffortSelect)
|
|
12
14
|
return false;
|
|
13
15
|
return Object.keys(binding.efforts ?? {}).length >= 2;
|
|
14
16
|
}
|
|
17
|
+
/** True when the user has any model or effort choice to make. */
|
|
15
18
|
function generationSelectEnabled(profile, modelId) {
|
|
16
19
|
return modelSelectEnabled(profile) || effortSelectEnabled(profile, modelId);
|
|
17
20
|
}
|
|
@@ -26,6 +29,7 @@ function defaultInterfaceEffort(profile, modelId) {
|
|
|
26
29
|
const keys = Object.keys(binding.efforts);
|
|
27
30
|
return keys[0];
|
|
28
31
|
}
|
|
32
|
+
/** The models the user can pick from, or none when the choice is off. */
|
|
29
33
|
function interfaceModelOptions(profile) {
|
|
30
34
|
if (!modelSelectEnabled(profile))
|
|
31
35
|
return [];
|
|
@@ -34,6 +38,7 @@ function interfaceModelOptions(profile) {
|
|
|
34
38
|
label: binding.apiId,
|
|
35
39
|
}));
|
|
36
40
|
}
|
|
41
|
+
/** The effort levels the user can pick from for this model, or none when the choice is off. */
|
|
37
42
|
function interfaceEffortOptions(profile, modelId) {
|
|
38
43
|
if (!effortSelectEnabled(profile, modelId))
|
|
39
44
|
return [];
|
|
@@ -2,7 +2,9 @@ import type { TurnEvent } from '../kernel/types.js';
|
|
|
2
2
|
import type { UserTurnDraft } from './types.js';
|
|
3
3
|
/** Display order: steers, then queues, then stashes. */
|
|
4
4
|
export declare const COMPOSER_PENDING_KINDS: readonly ["steer", "queue", "stash"];
|
|
5
|
+
/** One of {@linkcode COMPOSER_PENDING_KINDS}. */
|
|
5
6
|
export type ComposerPendingKind = (typeof COMPOSER_PENDING_KINDS)[number];
|
|
7
|
+
/** A message the user has set aside while a turn runs. */
|
|
6
8
|
export interface ComposerPendingMessage {
|
|
7
9
|
id: string;
|
|
8
10
|
kind: ComposerPendingKind;
|
|
@@ -10,17 +12,20 @@ export interface ComposerPendingMessage {
|
|
|
10
12
|
createdAt: number;
|
|
11
13
|
updatedAt: number;
|
|
12
14
|
}
|
|
15
|
+
/** What `createComposerPendingMessage` takes: the kind and the draft. */
|
|
13
16
|
export type CreateComposerPendingMessageArgs = {
|
|
14
17
|
kind: ComposerPendingKind;
|
|
15
18
|
draft: UserTurnDraft;
|
|
16
19
|
id?: string;
|
|
17
20
|
now?: number;
|
|
18
21
|
};
|
|
22
|
+
/** True when the draft holds text, an attachment, or voice. */
|
|
19
23
|
declare function userDraftHasPayload(draft: UserTurnDraft): boolean;
|
|
20
24
|
/** Short preview for pending bars (text, else attachment hint). */
|
|
21
25
|
declare function composerPendingPreview(message: ComposerPendingMessage): string;
|
|
22
26
|
/** Throws on an empty draft. */
|
|
23
27
|
declare function createComposerPendingMessage(args: CreateComposerPendingMessageArgs): ComposerPendingMessage;
|
|
28
|
+
/** A copy of the draft that shares nothing with the original. */
|
|
24
29
|
declare function cloneUserTurnDraft(draft: UserTurnDraft): UserTurnDraft;
|
|
25
30
|
/** Steer, then queue, then stash; FIFO within a kind. */
|
|
26
31
|
declare function orderComposerPendingMessages(messages: readonly ComposerPendingMessage[]): ComposerPendingMessage[];
|
|
@@ -31,8 +36,11 @@ declare function convertSteersToFrontQueued(messages: readonly ComposerPendingMe
|
|
|
31
36
|
* it never names stays pending, so the run's end requeues it.
|
|
32
37
|
*/
|
|
33
38
|
declare function removeLandedSteers(messages: readonly ComposerPendingMessage[], event: TurnEvent): ComposerPendingMessage[];
|
|
39
|
+
/** The messages without the one with this id. */
|
|
34
40
|
declare function removeComposerPendingMessage(messages: readonly ComposerPendingMessage[], id: string): ComposerPendingMessage[];
|
|
41
|
+
/** The messages with this id's draft replaced; throws when the new draft is empty. */
|
|
35
42
|
declare function updateComposerPendingDraft(messages: readonly ComposerPendingMessage[], id: string, draft: UserTurnDraft, now?: number): ComposerPendingMessage[];
|
|
43
|
+
/** The messages with this id moved one place up or down among those of its kind. */
|
|
36
44
|
declare function moveComposerPendingWithinKind(messages: readonly ComposerPendingMessage[], id: string, direction: 'up' | 'down'): ComposerPendingMessage[];
|
|
37
45
|
/** One steer per safe boundary: call once per `onStage` inject site. */
|
|
38
46
|
declare function consumeNextComposerSteer(messages: readonly ComposerPendingMessage[]): {
|
|
@@ -44,5 +52,6 @@ declare function consumeNextComposerQueue(messages: readonly ComposerPendingMess
|
|
|
44
52
|
message: ComposerPendingMessage | null;
|
|
45
53
|
remaining: ComposerPendingMessage[];
|
|
46
54
|
};
|
|
55
|
+
/** The messages with this id changed to another kind. */
|
|
47
56
|
declare function promoteComposerPendingKind(messages: readonly ComposerPendingMessage[], id: string, kind: ComposerPendingKind, now?: number): ComposerPendingMessage[];
|
|
48
57
|
export { cloneUserTurnDraft, composerPendingPreview, consumeNextComposerQueue, consumeNextComposerSteer, convertSteersToFrontQueued, createComposerPendingMessage, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, updateComposerPendingDraft, userDraftHasPayload, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `steer` injects at `onStage` boundaries of the same run; `queue` sends after the run fully ends
|
|
1
|
+
// invariant: `steer` injects at `onStage` boundaries of the same run; `queue` sends after the run fully ends
|
|
2
2
|
// (not on tool pause); `stash` never auto-sends. `send_now` is an action, not a pending kind.
|
|
3
3
|
/** Display order: steers, then queues, then stashes. */
|
|
4
4
|
export const COMPOSER_PENDING_KINDS = ['steer', 'queue', 'stash'];
|
|
@@ -7,6 +7,7 @@ function createPendingId() {
|
|
|
7
7
|
? crypto.randomUUID()
|
|
8
8
|
: `pending-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
9
9
|
}
|
|
10
|
+
/** True when the draft holds text, an attachment, or voice. */
|
|
10
11
|
function userDraftHasPayload(draft) {
|
|
11
12
|
return Boolean(draft.text?.trim() ||
|
|
12
13
|
(draft.attachments && draft.attachments.length > 0) ||
|
|
@@ -25,7 +26,7 @@ function composerPendingPreview(message) {
|
|
|
25
26
|
/** Throws on an empty draft. */
|
|
26
27
|
function createComposerPendingMessage(args) {
|
|
27
28
|
if (!userDraftHasPayload(args.draft)) {
|
|
28
|
-
throw new Error('Composer pending message requires a non-empty draft'); //
|
|
29
|
+
throw new Error('Composer pending message requires a non-empty draft'); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
29
30
|
}
|
|
30
31
|
const now = args.now ?? Date.now();
|
|
31
32
|
return {
|
|
@@ -36,6 +37,7 @@ function createComposerPendingMessage(args) {
|
|
|
36
37
|
updatedAt: now,
|
|
37
38
|
};
|
|
38
39
|
}
|
|
40
|
+
/** A copy of the draft that shares nothing with the original. */
|
|
39
41
|
function cloneUserTurnDraft(draft) {
|
|
40
42
|
return {
|
|
41
43
|
...(draft.text !== undefined ? { text: draft.text } : {}),
|
|
@@ -74,12 +76,14 @@ function removeLandedSteers(messages, event) {
|
|
|
74
76
|
const landed = new Set(event.injected.map((steer) => steer.id));
|
|
75
77
|
return messages.filter((m) => !(m.kind === 'steer' && landed.has(m.id)));
|
|
76
78
|
}
|
|
79
|
+
/** The messages without the one with this id. */
|
|
77
80
|
function removeComposerPendingMessage(messages, id) {
|
|
78
81
|
return messages.filter((m) => m.id !== id);
|
|
79
82
|
}
|
|
83
|
+
/** The messages with this id's draft replaced; throws when the new draft is empty. */
|
|
80
84
|
function updateComposerPendingDraft(messages, id, draft, now = Date.now()) {
|
|
81
85
|
if (!userDraftHasPayload(draft)) {
|
|
82
|
-
throw new Error('Composer pending message requires a non-empty draft'); //
|
|
86
|
+
throw new Error('Composer pending message requires a non-empty draft'); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
83
87
|
}
|
|
84
88
|
return messages.map((m) => m.id === id
|
|
85
89
|
? {
|
|
@@ -89,6 +93,7 @@ function updateComposerPendingDraft(messages, id, draft, now = Date.now()) {
|
|
|
89
93
|
}
|
|
90
94
|
: m);
|
|
91
95
|
}
|
|
96
|
+
/** The messages with this id moved one place up or down among those of its kind. */
|
|
92
97
|
function moveComposerPendingWithinKind(messages, id, direction) {
|
|
93
98
|
const message = messages.find((m) => m.id === id);
|
|
94
99
|
if (!message)
|
|
@@ -133,6 +138,7 @@ function consumeNextComposerQueue(messages) {
|
|
|
133
138
|
remaining: messages.filter((m) => m.id !== message.id),
|
|
134
139
|
};
|
|
135
140
|
}
|
|
141
|
+
/** The messages with this id changed to another kind. */
|
|
136
142
|
function promoteComposerPendingKind(messages, id, kind, now = Date.now()) {
|
|
137
143
|
const updated = messages.map((m) => m.id === id
|
|
138
144
|
? {
|