@vellumai/assistant 0.10.7 → 0.10.8-dev.202607102228.5945895
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/AGENTS.md +3 -1
- package/ARCHITECTURE.md +9 -9
- package/README.md +1 -1
- package/docs/architecture/memory.md +1 -3
- package/docs/credential-execution-service.md +9 -96
- package/docs/runbook-trusted-contacts.md +132 -93
- package/docs/trusted-contact-access.md +125 -115
- package/docs/workspace-tools.md +4 -2
- package/eslint-rules/__tests__/cli-no-daemon-internals.test.ts +62 -360
- package/eslint-rules/cli-no-daemon-internals.js +91 -269
- package/eslint.config.mjs +4 -4
- package/knip.json +2 -1
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +1 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/attachment-naming.test.ts +104 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/attachment-naming.ts +118 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +1 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/attachment-naming.test.ts +104 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/attachment-naming.ts +118 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/gateway-client/src/__tests__/invite-contract.test.ts +0 -18
- package/node_modules/@vellumai/gateway-client/src/__tests__/trust-verdict-contract.test.ts +40 -6
- package/node_modules/@vellumai/gateway-client/src/channel-permission-contract.ts +13 -0
- package/node_modules/@vellumai/gateway-client/src/index.ts +24 -2
- package/node_modules/@vellumai/gateway-client/src/invite-contract.ts +146 -16
- package/node_modules/@vellumai/gateway-client/src/trust-verdict-contract.ts +22 -4
- package/node_modules/@vellumai/service-contracts/package.json +1 -2
- package/node_modules/@vellumai/service-contracts/src/__tests__/attachment-naming.test.ts +104 -0
- package/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/service-contracts/src/attachment-naming.ts +118 -0
- package/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/openapi.yaml +1648 -676
- package/package.json +4 -5
- package/scripts/build-test-fixtures.ts +105 -0
- package/scripts/memory-inspect.ts +2 -8
- package/scripts/test.ts +597 -0
- package/src/__tests__/access-request-card-view.test.ts +38 -0
- package/src/__tests__/activation-early-marking.test.ts +1 -8
- package/src/__tests__/actor-token-service.test.ts +1 -22
- package/src/__tests__/add-message-preassigned-id.test.ts +1 -1
- package/src/__tests__/agent-image-optimize.test.ts +104 -1
- package/src/__tests__/agent-loop-callsite-precedence.test.ts +0 -5
- package/src/__tests__/agent-loop-compaction-events.test.ts +1 -1
- package/src/__tests__/agent-loop-compaction-strip.test.ts +1 -1
- package/src/__tests__/agent-loop-exit-reason.test.ts +1 -1
- package/src/__tests__/agent-loop-mutable-latest-user-message.test.ts +0 -6
- package/src/__tests__/agent-loop-override-profile.test.ts +66 -5
- package/src/__tests__/agent-loop-pushes-post-hook-prompt.test.ts +1 -9
- package/src/__tests__/agent-loop-regrowth-guard.test.ts +1 -1
- package/src/__tests__/agent-loop-set-system-prompt.test.ts +1 -7
- package/src/__tests__/agent-wake-disk-pressure-callsite.test.ts +1 -0
- package/src/__tests__/agent-wake-override-profile.test.ts +21 -1
- package/src/__tests__/annotate-activity-metadata.test.ts +4 -10
- package/src/__tests__/annotate-risk-options.test.ts +4 -10
- package/src/__tests__/anthropic-error-formatting.test.ts +193 -2
- package/src/__tests__/anthropic-gateway-shared.test.ts +140 -0
- package/src/__tests__/anthropic-provider.test.ts +58 -0
- package/src/__tests__/app-bundler.test.ts +0 -8
- package/src/__tests__/app-conversation-ids-backfill.test.ts +1 -8
- package/src/__tests__/app-routes-csp.test.ts +0 -8
- package/src/__tests__/approval-cascade.test.ts +0 -21
- package/src/__tests__/approval-interception-trust-gates.test.ts +0 -7
- package/src/__tests__/approval-primitive.test.ts +1 -9
- package/src/__tests__/approval-routes-http.test.ts +1 -16
- package/src/__tests__/assistant-attachment-directive.test.ts +1 -0
- package/src/__tests__/assistant-attachments.test.ts +211 -0
- package/src/__tests__/assistant-event-hub-machine-name.test.ts +0 -7
- package/src/__tests__/assistant-events-sse-hardening.test.ts +0 -7
- package/src/__tests__/assistant-feature-flag-guard.test.ts +3 -3
- package/src/__tests__/assistant-feature-flag-guardrails.test.ts +1 -1
- package/src/__tests__/attachment-stored-path-annotation.test.ts +0 -7
- package/src/__tests__/attachment-upload-trusted-source.test.ts +0 -7
- package/src/__tests__/attachments-store-heic-normalize.test.ts +0 -7
- package/src/__tests__/attachments-store.test.ts +43 -8
- package/src/__tests__/attachments.test.ts +77 -0
- package/src/__tests__/audit-log-rotation.test.ts +1 -9
- package/src/__tests__/auth-fallback-events-store.test.ts +0 -7
- package/src/__tests__/available-skills.test.ts +266 -0
- package/src/__tests__/avatar-generator.test.ts +0 -9
- package/src/__tests__/background-shell-host-bash.test.ts +0 -7
- package/src/__tests__/background-workers-disk-pressure.test.ts +4 -3
- package/src/__tests__/browser-fill-credential.test.ts +0 -7
- package/src/__tests__/browser-manager.test.ts +1 -8
- package/src/__tests__/btw-routes.test.ts +0 -7
- package/src/__tests__/build-persisted-content.test.ts +0 -8
- package/src/__tests__/call-constants.test.ts +1 -1
- package/src/__tests__/call-controller.test.ts +783 -34
- package/src/__tests__/call-conversation-messages.test.ts +2 -9
- package/src/__tests__/call-domain.test.ts +7 -24
- package/src/__tests__/call-pointer-message-composer.test.ts +0 -8
- package/src/__tests__/call-pointer-messages.test.ts +1 -8
- package/src/__tests__/call-recovery.test.ts +1 -8
- package/src/__tests__/call-routes-http.test.ts +0 -7
- package/src/__tests__/call-setup-flow-invite.test.ts +1 -1
- package/src/__tests__/call-setup-flow-midcall-trust.test.ts +76 -97
- package/src/__tests__/call-setup-flow-name-capture.test.ts +1 -1
- package/src/__tests__/call-setup-flow-verification.test.ts +1 -1
- package/src/__tests__/call-setup-flow.test.ts +2 -2
- package/src/__tests__/call-site-routing-provider.test.ts +1 -5
- package/src/__tests__/call-state.test.ts +1 -8
- package/src/__tests__/call-store.test.ts +1 -8
- package/src/__tests__/cancel-resolves-conversation-key.test.ts +0 -7
- package/src/__tests__/canonical-guardian-store.test.ts +1 -8
- package/src/__tests__/catalog-cache.test.ts +0 -8
- package/src/__tests__/catalog-files.test.ts +0 -8
- package/src/__tests__/catalog-install-normalize.test.ts +0 -7
- package/src/__tests__/ces-rpc-credential-backend.test.ts +0 -7
- package/src/__tests__/channel-approval-routes.test.ts +0 -7
- package/src/__tests__/channel-approvals.test.ts +0 -7
- package/src/__tests__/channel-delivery-store.test.ts +0 -7
- package/src/__tests__/channel-guardian.test.ts +29 -16
- package/src/__tests__/channel-inbound-disk-pressure.test.ts +0 -7
- package/src/__tests__/channel-reply-delivery.test.ts +18 -5
- package/src/__tests__/channel-retry-sweep.test.ts +0 -7
- package/src/__tests__/clawhub-files.test.ts +0 -8
- package/src/__tests__/clawhub.test.ts +0 -7
- package/src/__tests__/clear-all-lexical.test.ts +0 -6
- package/src/__tests__/client-os-metadata-persistence.test.ts +0 -5
- package/src/__tests__/compaction-direct.test.ts +47 -0
- package/src/__tests__/compaction-events.test.ts +14 -29
- package/src/__tests__/compaction-ledger-store.test.ts +1 -7
- package/src/__tests__/compaction-summary-head-persisted-count.test.ts +417 -0
- package/src/__tests__/compaction-trail-store.test.ts +2 -8
- package/src/__tests__/compaction.benchmark.test.ts +0 -5
- package/src/__tests__/compactor-call-site-logging.test.ts +0 -21
- package/src/__tests__/compactor-fixed-boundary.test.ts +334 -0
- package/src/__tests__/compactor-low-watermark-cut.test.ts +8 -23
- package/src/__tests__/compactor-media-strip.test.ts +0 -21
- package/src/__tests__/compactor-preserved-tail-count.test.ts +0 -21
- package/src/__tests__/compactor-summary-call-truncation.test.ts +0 -21
- package/src/__tests__/compactor-web-search-strip.test.ts +21 -25
- package/src/__tests__/config-get-vision-flag.test.ts +0 -6
- package/src/__tests__/config-loader-backfill.test.ts +332 -316
- package/src/__tests__/config-loader-platform-defaults.test.ts +0 -21
- package/src/__tests__/config-loader-validation-reset-notice.test.ts +183 -0
- package/src/__tests__/config-schema.test.ts +85 -30
- package/src/__tests__/config-set-route.test.ts +0 -6
- package/src/__tests__/config-watcher-cleanup-throttle.test.ts +12 -24
- package/src/__tests__/config-watcher-skill-reseed.test.ts +1 -8
- package/src/__tests__/config-watcher.test.ts +22 -12
- package/src/__tests__/confirmation-request-guardian-bridge.test.ts +1 -9
- package/src/__tests__/contact-store-interaction-info.test.ts +1 -8
- package/src/__tests__/contact-store-user-file.test.ts +1 -14
- package/src/__tests__/contacts-tools.test.ts +0 -7
- package/src/__tests__/contacts-write.test.ts +1 -8
- package/src/__tests__/context-search-memory-source.test.ts +0 -1
- package/src/__tests__/context-search-memory-v2-source.test.ts +0 -6
- package/src/__tests__/context-window-manager-compact-retry.test.ts +118 -21
- package/src/__tests__/context-window-manager-overflow-rung.test.ts +0 -21
- package/src/__tests__/conversation-abort-tool-results.test.ts +0 -5
- package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +0 -12
- package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +5 -12
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +45 -21
- package/src/__tests__/conversation-agent-loop.test.ts +192 -70
- package/src/__tests__/conversation-app-control-instantiation.test.ts +20 -8
- package/src/__tests__/conversation-app-control-lifecycle.test.ts +0 -9
- package/src/__tests__/conversation-attachments.test.ts +1 -7
- package/src/__tests__/conversation-attention-store.test.ts +1 -9
- package/src/__tests__/conversation-attention-telegram.test.ts +0 -8
- package/src/__tests__/conversation-clear-safety.test.ts +0 -7
- package/src/__tests__/conversation-confirmation-signals.test.ts +0 -21
- package/src/__tests__/conversation-crud-enabled-plugins.test.ts +1 -7
- package/src/__tests__/conversation-crud-inference-profile.test.ts +1 -7
- package/src/__tests__/conversation-delete-schedule-cleanup.test.ts +0 -7
- package/src/__tests__/conversation-disk-view-integration.test.ts +0 -7
- package/src/__tests__/conversation-disk-view.test.ts +0 -7
- package/src/__tests__/conversation-enabledplugins-route.test.ts +2 -8
- package/src/__tests__/conversation-error.test.ts +299 -3
- package/src/__tests__/conversation-fork-crud.test.ts +52 -37
- package/src/__tests__/conversation-fork-retrospective.test.ts +486 -7
- package/src/__tests__/conversation-fork-route.test.ts +0 -7
- package/src/__tests__/conversation-history-web-search.test.ts +39 -17
- package/src/__tests__/conversation-inference-profile-list.test.ts +0 -6
- package/src/__tests__/conversation-inference-profile-route.test.ts +0 -5
- package/src/__tests__/conversation-init.benchmark.test.ts +6 -2
- package/src/__tests__/conversation-initial-prompt.test.ts +1 -1
- package/src/__tests__/conversation-key-store-disk-view.test.ts +0 -7
- package/src/__tests__/conversation-lifecycle.test.ts +108 -62
- package/src/__tests__/conversation-list-source.test.ts +0 -7
- package/src/__tests__/conversation-load-history-repair.test.ts +39 -53
- package/src/__tests__/conversation-load-history-stripped.test.ts +12 -19
- package/src/__tests__/conversation-loop-db-lock-resilience.test.ts +10 -15
- package/src/__tests__/conversation-message-id-uuidv7.test.ts +73 -0
- package/src/__tests__/conversation-pairing.test.ts +0 -7
- package/src/__tests__/conversation-process-app-control-preactivation.test.ts +0 -5
- package/src/__tests__/conversation-process-callsite.test.ts +14 -7
- package/src/__tests__/conversation-provider-retry-repair.test.ts +0 -5
- package/src/__tests__/conversation-queue.test.ts +91 -21
- package/src/__tests__/conversation-routes-disk-view.test.ts +0 -11
- package/src/__tests__/conversation-routes-enabled-plugins.test.ts +3 -11
- package/src/__tests__/conversation-routes-guardian-reply.test.ts +3 -11
- package/src/__tests__/conversation-routes-hidden-queue.test.ts +3 -11
- package/src/__tests__/conversation-routes-slash-commands.test.ts +24 -13
- package/src/__tests__/conversation-runtime-assembly.test.ts +37 -9
- package/src/__tests__/conversation-skill-tools.test.ts +31 -15
- package/src/__tests__/conversation-slash-commands.test.ts +5 -4
- package/src/__tests__/conversation-slash-queue.test.ts +0 -5
- package/src/__tests__/conversation-slash-unknown.test.ts +0 -5
- package/src/__tests__/conversation-speed-override.test.ts +13 -23
- package/src/__tests__/conversation-starter-routes.test.ts +0 -7
- package/src/__tests__/conversation-store.test.ts +9 -22
- package/src/__tests__/conversation-summarize-route.test.ts +445 -0
- package/src/__tests__/conversation-summarize-up-to.test.ts +711 -0
- package/src/__tests__/conversation-surfaces-activation-emit.test.ts +0 -8
- package/src/__tests__/conversation-surfaces-data-persist.test.ts +4 -2
- package/src/__tests__/conversation-title-service.test.ts +0 -7
- package/src/__tests__/conversation-tool-setup-app-refresh.test.ts +0 -19
- package/src/__tests__/conversation-tool-setup-attribution.test.ts +4 -8
- package/src/__tests__/conversation-unread-route.test.ts +0 -7
- package/src/__tests__/conversation-usage.test.ts +10 -8
- package/src/__tests__/conversation-wait-for-idle.test.ts +391 -0
- package/src/__tests__/conversation-workspace-cache-state.test.ts +0 -5
- package/src/__tests__/conversation-workspace-injection.test.ts +0 -5
- package/src/__tests__/conversation-workspace-tool-tracking.test.ts +0 -5
- package/src/__tests__/conversations-import-system-filter.test.ts +0 -7
- package/src/__tests__/credential-broker-browser-fill.test.ts +0 -9
- package/src/__tests__/credential-broker-server-use.test.ts +0 -9
- package/src/__tests__/credential-execution-api-key-propagation.test.ts +0 -40
- package/src/__tests__/credential-execution-client.test.ts +3 -38
- package/src/__tests__/credential-execution-managed-contract.test.ts +10 -106
- package/src/__tests__/credential-health-service.test.ts +0 -9
- package/src/__tests__/credential-metadata-store.test.ts +0 -8
- package/src/__tests__/credential-prompt-route.test.ts +80 -9
- package/src/__tests__/credential-request-route.test.ts +76 -0
- package/src/__tests__/credential-resolve.test.ts +0 -8
- package/src/__tests__/credential-security-invariants.test.ts +3 -10
- package/src/__tests__/credential-token-resolver.test.ts +0 -9
- package/src/__tests__/custom-profile-ensure.test.ts +232 -0
- package/src/__tests__/daemon-assistant-events.test.ts +1 -9
- package/src/__tests__/daemon-credential-client.test.ts +0 -7
- package/src/__tests__/db-conversation-fork-lineage-migration.test.ts +1 -8
- package/src/__tests__/db-conversation-inference-profile-migration.test.ts +1 -7
- package/src/__tests__/db-llm-request-log-provider-migration.test.ts +0 -8
- package/src/__tests__/db-processing-resume-attempts-migration.test.ts +116 -0
- package/src/__tests__/db-readiness-http-gate.test.ts +0 -7
- package/src/__tests__/db-rename-inference-profile-snake-case-migration.test.ts +1 -7
- package/src/__tests__/default-provider-ensure.test.ts +343 -0
- package/src/__tests__/delete-managed-skill-tool.test.ts +0 -7
- package/src/__tests__/delete-propagation.test.ts +0 -7
- package/src/__tests__/deterministic-verification-control-plane.test.ts +0 -7
- package/src/__tests__/device-id.test.ts +1 -9
- package/src/__tests__/disk-pressure-tools.test.ts +0 -4
- package/src/__tests__/dm-backfill.test.ts +0 -7
- package/src/__tests__/dm-persistence.test.ts +0 -5
- package/src/__tests__/docker-signing-key-bootstrap.test.ts +1 -8
- package/src/__tests__/drain-requeue-on-contention.test.ts +202 -0
- package/src/__tests__/dynamic-skill-background-guard.test.ts +174 -0
- package/src/__tests__/edit-propagation.test.ts +1 -8
- package/src/__tests__/embedding-managed-proxy-selection.test.ts +0 -8
- package/src/__tests__/emit-signal-routing-intent.test.ts +175 -7
- package/src/__tests__/encrypted-store.test.ts +0 -9
- package/src/__tests__/ensure-conversation-exists.test.ts +85 -0
- package/src/__tests__/events-client-registration.test.ts +0 -7
- package/src/__tests__/events-dev-bypass-actor.test.ts +2 -9
- package/src/__tests__/events-tail-route.test.ts +172 -0
- package/src/__tests__/file-write-tool.test.ts +9 -13
- package/src/__tests__/followup-tools.test.ts +0 -7
- package/src/__tests__/gateway-flag-listener.test.ts +2 -23
- package/src/__tests__/gemini-inline-media.test.ts +2 -2
- package/src/__tests__/gemini-provider.test.ts +140 -1
- package/src/__tests__/get-skill-detail-audit.test.ts +89 -1
- package/src/__tests__/graph-extraction-event-date.test.ts +0 -9
- package/src/__tests__/guardian-action-sweep.test.ts +0 -7
- package/src/__tests__/guardian-binding-drift-heal.test.ts +0 -7
- package/src/__tests__/guardian-card-withdrawal.test.ts +0 -8
- package/src/__tests__/guardian-decision-primitive-canonical.test.ts +1 -9
- package/src/__tests__/guardian-dispatch.test.ts +0 -7
- package/src/__tests__/guardian-expiry-notifier.test.ts +1 -9
- package/src/__tests__/guardian-outbound-http.test.ts +0 -7
- package/src/__tests__/guardian-principal-id-roundtrip.test.ts +1 -8
- package/src/__tests__/guardian-routing-invariants.test.ts +0 -8
- package/src/__tests__/guardian-routing-state.test.ts +1 -9
- package/src/__tests__/guardian-verification-voice-binding.test.ts +0 -7
- package/src/__tests__/handlers-skills-memory-v2-reseed.test.ts +0 -2
- package/src/__tests__/handlers-user-message-approval-consumption.test.ts +4 -5
- package/src/__tests__/headless-browser-interactions.test.ts +0 -7
- package/src/__tests__/headless-browser-mode.test.ts +0 -9
- package/src/__tests__/headless-browser-navigate.test.ts +91 -13
- package/src/__tests__/headless-browser-read-tools.test.ts +0 -7
- package/src/__tests__/headless-browser-snapshot.test.ts +0 -7
- package/src/__tests__/heartbeat-disk-pressure.test.ts +0 -9
- package/src/__tests__/helpers/set-config.ts +40 -0
- package/src/__tests__/host-bash-proxy.test.ts +3 -3
- package/src/__tests__/host-browser-proxy.test.ts +15 -20
- package/src/__tests__/host-cu-routes-targeted.test.ts +0 -1
- package/src/__tests__/host-shell-tool.test.ts +5 -69
- package/src/__tests__/http-conversation-lineage.test.ts +0 -7
- package/src/__tests__/http-user-message-parity.test.ts +0 -7
- package/src/__tests__/identity-routes.test.ts +1 -9
- package/src/__tests__/image-recovery-hook.test.ts +36 -0
- package/src/__tests__/inbound-admitted-introduction-nudge.test.ts +296 -0
- package/src/__tests__/inbound-invite-redemption.test.ts +0 -7
- package/src/__tests__/inbound-slack-persistence.test.ts +0 -5
- package/src/__tests__/inbound-trust-verdict.test.ts +1 -8
- package/src/__tests__/inference-profile-reaper.test.ts +1 -7
- package/src/__tests__/inference-profile-session-handler.test.ts +0 -6
- package/src/__tests__/inference-profile-session-ipc.test.ts +0 -6
- package/src/__tests__/ingress-url-consistency.test.ts +1 -23
- package/src/__tests__/injection-block.test.ts +0 -1
- package/src/__tests__/injector-chain.test.ts +17 -0
- package/src/__tests__/injector-config-validation-reset-notice.test.ts +121 -0
- package/src/__tests__/injector-pkb-v2-silenced.test.ts +8 -0
- package/src/__tests__/injector-registry-order-guard.test.ts +1 -0
- package/src/__tests__/inline-command-runner.test.ts +0 -7
- package/src/__tests__/inline-skill-load-permissions.test.ts +29 -31
- package/src/__tests__/internal-telemetry-routes.test.ts +72 -7
- package/src/__tests__/interrupted-turn-reconciler.test.ts +126 -0
- package/src/__tests__/introduction-card-resolver.test.ts +0 -9
- package/src/__tests__/invite-redeemed-ipc.test.ts +0 -7
- package/src/__tests__/invite-routes-http.test.ts +46 -11
- package/src/__tests__/job-handler-registration-guard.test.ts +1 -1
- package/src/__tests__/jobs-store-qdrant-breaker.test.ts +0 -7
- package/src/__tests__/jobs-store-upsert-debounced.test.ts +0 -7
- package/src/__tests__/lexical-index-dual-write.test.ts +2 -8
- package/src/__tests__/list-messages-attachments.test.ts +0 -7
- package/src/__tests__/list-messages-background-tool-completion.test.ts +0 -7
- package/src/__tests__/list-messages-client-message-id.test.ts +0 -7
- package/src/__tests__/list-messages-hidden-metadata.test.ts +0 -7
- package/src/__tests__/list-messages-page-latest.test.ts +0 -7
- package/src/__tests__/list-messages-queued.test.ts +9 -10
- package/src/__tests__/list-messages-tool-merge.test.ts +0 -7
- package/src/__tests__/llm-catalog-parity.test.ts +20 -0
- package/src/__tests__/llm-context-resolution.test.ts +26 -1
- package/src/__tests__/llm-context-route-provider.test.ts +1 -8
- package/src/__tests__/llm-request-log-agent-loop-exit-reason.test.ts +9 -16
- package/src/__tests__/llm-request-log-call-site.test.ts +5 -12
- package/src/__tests__/llm-request-log-clickhouse-routing.test.ts +117 -0
- package/src/__tests__/llm-request-log-clickhouse-writer-guards.test.ts +115 -0
- package/src/__tests__/llm-request-log-disabled-writes.test.ts +72 -0
- package/src/__tests__/llm-request-log-sink-clickhouse.test.ts +211 -0
- package/src/__tests__/llm-request-log-source-clickhouse.test.ts +1 -22
- package/src/__tests__/llm-request-log-source-factory.test.ts +0 -21
- package/src/__tests__/llm-request-log-turn-query.test.ts +0 -7
- package/src/__tests__/llm-resolver-override-or-default.test.ts +563 -0
- package/src/__tests__/llm-resolver.test.ts +167 -6
- package/src/__tests__/llm-usage-store.test.ts +1 -7
- package/src/__tests__/log-export-routes.test.ts +0 -7
- package/src/__tests__/log-export-workspace.test.ts +0 -7
- package/src/__tests__/managed-profile-guard.test.ts +240 -6
- package/src/__tests__/managed-skill-lifecycle.test.ts +0 -7
- package/src/__tests__/managed-store.test.ts +1 -16
- package/src/__tests__/mcp-auth-routes.test.ts +1 -8
- package/src/__tests__/mcp-config-secret-boundary.test.ts +17 -5
- package/src/__tests__/media-generate-image.test.ts +20 -7
- package/src/__tests__/media-stream-output.test.ts +755 -71
- package/src/__tests__/media-stream-server-integration.test.ts +290 -60
- package/src/__tests__/media-stream-stt-session.test.ts +26 -13
- package/src/__tests__/memory-config-file-parity.test.ts +187 -0
- package/src/__tests__/memory-identity-context-parity.test.ts +103 -0
- package/src/__tests__/memory-jobs-worker-backoff.test.ts +8 -7
- package/src/__tests__/memory-jobs-worker-cleanup-cadence.test.ts +296 -0
- package/src/__tests__/memory-jobs-worker-lanes.test.ts +0 -7
- package/src/__tests__/memory-recall-log-store.test.ts +0 -7
- package/src/__tests__/memory-upsert-concurrency.test.ts +0 -7
- package/src/__tests__/message-queue.test.ts +40 -0
- package/src/__tests__/messages-after-tiebreaker.test.ts +1 -8
- package/src/__tests__/messaging-send-tool.test.ts +0 -7
- package/src/__tests__/migration-cross-version-compatibility.test.ts +0 -7
- package/src/__tests__/migration-export-http.test.ts +10 -12
- package/src/__tests__/migration-export-streaming.test.ts +0 -7
- package/src/__tests__/migration-export-to-gcs.test.ts +60 -7
- package/src/__tests__/migration-import-commit-http.test.ts +11 -12
- package/src/__tests__/migration-import-from-gcs.test.ts +0 -7
- package/src/__tests__/migration-import-from-url.test.ts +0 -7
- package/src/__tests__/migration-import-preflight-http.test.ts +10 -11
- package/src/__tests__/migration-jobs-status.test.ts +8 -11
- package/src/__tests__/migration-validate-http.test.ts +2 -8
- package/src/__tests__/model-intents.test.ts +18 -0
- package/src/__tests__/mtime-cache.test.ts +102 -9
- package/src/__tests__/non-member-access-request.test.ts +145 -7
- package/src/__tests__/notification-broadcaster.test.ts +0 -7
- package/src/__tests__/notification-candidate-guardian-context.test.ts +1 -8
- package/src/__tests__/notification-decision-fallback.test.ts +0 -7
- package/src/__tests__/notification-decision-identity.test.ts +0 -7
- package/src/__tests__/notification-decision-recipient-context.test.ts +0 -7
- package/src/__tests__/notification-deep-link.test.ts +415 -11
- package/src/__tests__/notification-guardian-path.test.ts +0 -7
- package/src/__tests__/notification-platform-adapter.test.ts +0 -7
- package/src/__tests__/notification-routing-intent.test.ts +1 -9
- package/src/__tests__/notification-schedule-notify-dedup.test.ts +1 -9
- package/src/__tests__/notification-telegram-adapter.test.ts +0 -7
- package/src/__tests__/oauth-cli.test.ts +0 -1
- package/src/__tests__/oauth-connect-orchestrator.test.ts +0 -8
- package/src/__tests__/oauth-connect-routes.test.ts +19 -18
- package/src/__tests__/oauth-provider-profiles.test.ts +0 -7
- package/src/__tests__/oauth-provider-visibility.test.ts +0 -7
- package/src/__tests__/oauth-store.test.ts +0 -7
- package/src/__tests__/openai-provider.test.ts +11 -0
- package/src/__tests__/openrouter-provider-only.test.ts +16 -5
- package/src/__tests__/openrouter-token-estimation.test.ts +2 -2
- package/src/__tests__/outbound-slack-persistence.test.ts +9 -7
- package/src/__tests__/outlook-email-watcher.test.ts +0 -9
- package/src/__tests__/path-policy.test.ts +0 -7
- package/src/__tests__/pending-interactions-resolved-event.test.ts +26 -4
- package/src/__tests__/persist-media-references.test.ts +112 -0
- package/src/__tests__/persist-unsendable-image-downscale.test.ts +9 -4
- package/src/__tests__/persist-unsendable-image.test.ts +39 -7
- package/src/__tests__/persist-user-message-set-processing-failure.test.ts +41 -0
- package/src/__tests__/persistence-secret-redaction.test.ts +7 -7
- package/src/__tests__/persona-resolver.test.ts +1 -1
- package/src/__tests__/personal-memory-auth-bypass.test.ts +2 -4
- package/src/__tests__/platform-bash-auto-approve.test.ts +20 -10
- package/src/__tests__/platform-callback-registration.test.ts +10 -9
- package/src/__tests__/platform-proxy-context.test.ts +0 -8
- package/src/__tests__/playbook-execution.test.ts +2 -33
- package/src/__tests__/playbook-tools.test.ts +0 -7
- package/src/__tests__/plugin-api-model-profiles.test.ts +25 -4
- package/src/__tests__/plugin-effective-enabled-set.test.ts +29 -29
- package/src/__tests__/plugin-hook-pipeline-hardening.test.ts +249 -0
- package/src/__tests__/plugin-import-boundary-guard.test.ts +13 -25
- package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +316 -0
- package/src/__tests__/plugin-types.test.ts +1 -1
- package/src/__tests__/pointer-conversation-trust.test.ts +2 -4
- package/src/__tests__/pricing.test.ts +85 -2
- package/src/__tests__/process-message-background-slack.test.ts +4 -5
- package/src/__tests__/process-message-display-content.test.ts +102 -10
- package/src/__tests__/processing-flag-persist-failure.test.ts +0 -5
- package/src/__tests__/provider-commit-message-generator.test.ts +15 -8
- package/src/__tests__/provider-error-scenarios.test.ts +68 -5
- package/src/__tests__/provider-platform-proxy-integration.test.ts +17 -2
- package/src/__tests__/provider-registry-ollama.test.ts +14 -1
- package/src/__tests__/provider-send-message-override-profile.test.ts +13 -5
- package/src/__tests__/provider-streaming.benchmark.test.ts +1 -6
- package/src/__tests__/provider-usage-tracking.test.ts +9 -6
- package/src/__tests__/proxy-approval-callback.test.ts +0 -6
- package/src/__tests__/prune-old-conversations-job.test.ts +1 -9
- package/src/__tests__/prune-old-tool-invocations-job.test.ts +1 -9
- package/src/__tests__/public-ingress-urls.test.ts +1 -24
- package/src/__tests__/qdrant-collection-migration.test.ts +0 -7
- package/src/__tests__/qdrant-manager.test.ts +0 -8
- package/src/__tests__/ratelimit.test.ts +1 -8
- package/src/__tests__/reaction-persistence.test.ts +0 -7
- package/src/__tests__/rebuild-index-graph-nodes.test.ts +0 -11
- package/src/__tests__/registry.test.ts +39 -12
- package/src/__tests__/request-secret-standalone-channel-gate.test.ts +270 -0
- package/src/__tests__/require-fresh-approval.test.ts +47 -182
- package/src/__tests__/resolve-trust-class.test.ts +1 -1
- package/src/__tests__/retry-openrouter-only-normalization.test.ts +9 -5
- package/src/__tests__/retry-thinking-adaptive-only.test.ts +19 -5
- package/src/__tests__/retry-thinking-tool-choice.test.ts +65 -5
- package/src/__tests__/retry-verbosity-normalization.test.ts +9 -5
- package/src/__tests__/runtime-attachment-metadata.test.ts +0 -7
- package/src/__tests__/runtime-events-sse-bilingual.test.ts +0 -7
- package/src/__tests__/runtime-events-sse-parity.test.ts +0 -7
- package/src/__tests__/runtime-events-sse-reconnect.test.ts +0 -7
- package/src/__tests__/runtime-events-sse.test.ts +0 -7
- package/src/__tests__/scaffold-managed-skill-tool.test.ts +131 -9
- package/src/__tests__/schedule-retry.test.ts +0 -8
- package/src/__tests__/schedule-routes-workflow-validation.test.ts +0 -7
- package/src/__tests__/schedule-routes.test.ts +0 -7
- package/src/__tests__/schedule-store.test.ts +0 -8
- package/src/__tests__/schedule-tools.test.ts +0 -7
- package/src/__tests__/scheduler-disk-pressure.test.ts +0 -10
- package/src/__tests__/scheduler-recurrence.test.ts +19 -96
- package/src/__tests__/scheduler-reuse-conversation.test.ts +75 -88
- package/src/__tests__/scheduler-wake.test.ts +12 -60
- package/src/__tests__/scheduler-worker-standdown.test.ts +0 -8
- package/src/__tests__/scoped-approval-grants.test.ts +1 -9
- package/src/__tests__/scoped-grant-security-matrix.test.ts +1 -9
- package/src/__tests__/secret-allowlist.test.ts +1 -8
- package/src/__tests__/secret-ingress-channel.test.ts +0 -7
- package/src/__tests__/secret-ingress-cli.test.ts +0 -7
- package/src/__tests__/secret-ingress-http.test.ts +3 -11
- package/src/__tests__/secret-patterns.test.ts +27 -0
- package/src/__tests__/secret-prompter-channel-fallback.test.ts +35 -9
- package/src/__tests__/secret-response-routing.test.ts +1 -1
- package/src/__tests__/secret-routes-platform-proxy.test.ts +0 -7
- package/src/__tests__/secure-keys-managed-failover.test.ts +0 -7
- package/src/__tests__/secure-keys.test.ts +142 -33
- package/src/__tests__/send-endpoint-busy.test.ts +0 -19
- package/src/__tests__/sequence-store.test.ts +0 -9
- package/src/__tests__/server-history-render.test.ts +61 -8
- package/src/__tests__/service-contracts-import-guard.test.ts +4 -9
- package/src/__tests__/set-permission-mode.test.ts +0 -7
- package/src/__tests__/settings-routes.test.ts +0 -7
- package/src/__tests__/shell-credential-ref.test.ts +0 -8
- package/src/__tests__/shell-tool-proxy-mode.test.ts +0 -7
- package/src/__tests__/skill-projection-feature-flag.test.ts +35 -17
- package/src/__tests__/skill-projection.benchmark.test.ts +7 -7
- package/src/__tests__/skill-script-runner-sandbox.test.ts +0 -7
- package/src/__tests__/skills-files-catalog-fallback.test.ts +0 -7
- package/src/__tests__/slack-channels-routes.test.ts +34 -16
- package/src/__tests__/slack-inbound-verification.test.ts +0 -7
- package/src/__tests__/slack-reaction-canonical-approval.test.ts +0 -8
- package/src/__tests__/slack-users-routes.test.ts +148 -0
- package/src/__tests__/slim-skill-category.test.ts +0 -7
- package/src/__tests__/stale-approval-dedup.test.ts +0 -7
- package/src/__tests__/subagent-call-site-routing.test.ts +45 -11
- package/src/__tests__/subagent-detail.test.ts +2 -1
- package/src/__tests__/subagent-fork-prompt-role.test.ts +0 -5
- package/src/__tests__/subagent-fork-spawn.test.ts +0 -37
- package/src/__tests__/subagent-spawn-and-await.test.ts +0 -5
- package/src/__tests__/subagent-tool-gate-mode.test.ts +1 -7
- package/src/__tests__/subagent-tools.test.ts +77 -36
- package/src/__tests__/suggestion-routes.test.ts +28 -42
- package/src/__tests__/summarize-boundary.test.ts +169 -0
- package/src/__tests__/task-compiler.test.ts +0 -7
- package/src/__tests__/task-management-tools.test.ts +0 -7
- package/src/__tests__/task-memory-cleanup.test.ts +0 -18
- package/src/__tests__/task-scheduler.test.ts +40 -9
- package/src/__tests__/telegram-bot-username-resolution.test.ts +0 -8
- package/src/__tests__/telephony-tts-guard.test.ts +118 -26
- package/src/__tests__/test-preload.ts +11 -1
- package/src/__tests__/thread-backfill.test.ts +2 -8
- package/src/__tests__/token-manager.test.ts +0 -9
- package/src/__tests__/tool-approval-handler.test.ts +57 -88
- package/src/__tests__/{tool-audit-listener.test.ts → tool-audit.test.ts} +230 -255
- package/src/__tests__/tool-execution-abort-cleanup.test.ts +5 -33
- package/src/__tests__/tool-execution-pipeline.benchmark.test.ts +1 -8
- package/src/__tests__/tool-executor-lifecycle-events.test.ts +308 -411
- package/src/__tests__/tool-executor.test.ts +37 -26
- package/src/__tests__/tool-grant-request-escalation.test.ts +17 -31
- package/src/__tests__/tool-preview-lifecycle.test.ts +2 -8
- package/src/__tests__/tool-profiler.test.ts +139 -0
- package/src/__tests__/tool-result-metadata-plumbing.test.ts +0 -8
- package/src/__tests__/tool-start-timestamp.test.ts +4 -10
- package/src/__tests__/tools-get-route.test.ts +75 -3
- package/src/__tests__/trust-context-guards.test.ts +1 -1
- package/src/__tests__/trusted-contact-approval-notifier.test.ts +1 -1
- package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +9 -26
- package/src/__tests__/trusted-contact-lifecycle-notifications.test.ts +0 -7
- package/src/__tests__/trusted-contact-multichannel.test.ts +0 -7
- package/src/__tests__/trusted-contact-verification.test.ts +6 -139
- package/src/__tests__/turn-boundary-resolution.test.ts +0 -7
- package/src/__tests__/turn-events-store.test.ts +51 -7
- package/src/__tests__/turn-outcome-read.test.ts +75 -0
- package/src/__tests__/twilio-config.test.ts +0 -7
- package/src/__tests__/twilio-provider.test.ts +0 -7
- package/src/__tests__/twilio-routes-twiml.test.ts +1 -8
- package/src/__tests__/twilio-routes.test.ts +12 -5
- package/src/__tests__/twilio-validation.test.ts +0 -7
- package/src/__tests__/usage-attribution.test.ts +91 -1
- package/src/__tests__/usage-cache-backfill-migration.test.ts +0 -7
- package/src/__tests__/usage-routes.test.ts +1 -8
- package/src/__tests__/vbundle-pax-and-symlink.test.ts +0 -7
- package/src/__tests__/vercel-ai-gateway-provider.test.ts +283 -0
- package/src/__tests__/vercel-config.test.ts +0 -7
- package/src/__tests__/verification-control-plane-policy.test.ts +60 -31
- package/src/__tests__/voice-approval-resolver-relay.test.ts +3 -9
- package/src/__tests__/voice-config-update.test.ts +1 -22
- package/src/__tests__/voice-guardian-cold-cache-warm.test.ts +8 -17
- package/src/__tests__/voice-scoped-grant-consumer.test.ts +1 -10
- package/src/__tests__/voice-session-bridge-processing-wait.test.ts +0 -7
- package/src/__tests__/voice-session-bridge.test.ts +116 -68
- package/src/__tests__/workspace-git-service.test.ts +207 -2
- package/src/__tests__/workspace-migration-009-backfill-conversation-disk-view.test.ts +0 -8
- package/src/__tests__/workspace-migration-013-repair-conversation-disk-view.test.ts +0 -8
- package/src/__tests__/workspace-migration-028-recover-conversations-from-disk-view.test.ts +0 -8
- package/src/__tests__/workspace-migration-126-strip-managed-profile-bodies.test.ts +192 -0
- package/src/__tests__/workspace-migration-127-backfill-default-provider.test.ts +277 -0
- package/src/__tests__/workspace-migration-128-repair-stale-openrouter-grok-model-ids.test.ts +135 -0
- package/src/__tests__/workspace-migration-129-remove-analyze-conversation-config.test.ts +190 -0
- package/src/__tests__/workspace-tool-loader.test.ts +5 -1
- package/src/a2a/__tests__/e2e-a2a-channel.test.ts +1 -10
- package/src/a2a/__tests__/task-store.test.ts +0 -9
- package/src/acp/__tests__/session-manager-persistence.test.ts +1 -8
- package/src/acp/__tests__/session-manager-resume.test.ts +0 -7
- package/src/acp/__tests__/session-manager-startup.test.ts +1 -8
- package/src/agent/attachments.ts +57 -0
- package/src/agent/image-optimize.ts +80 -0
- package/src/agent/loop-exclusive-tool.test.ts +28 -5
- package/src/agent/loop.ts +25 -63
- package/src/api/responses/conversation-message.ts +9 -15
- package/src/approvals/guardian-expiry-notifier.ts +6 -0
- package/src/approvals/guardian-request-resolvers.ts +42 -21
- package/src/background-wake/wake-intent-hooks.test.ts +2 -10
- package/src/browser/operation-meta.ts +493 -0
- package/src/browser/operations.ts +2 -477
- package/src/calls/__tests__/call-setup-router.test.ts +341 -321
- package/src/calls/__tests__/channel-admission-reader.test.ts +50 -24
- package/src/calls/__tests__/fish-audio-client.test.ts +35 -11
- package/src/calls/__tests__/inbound-trust-reader.test.ts +157 -34
- package/src/calls/__tests__/tts-text-sanitizer.test.ts +22 -0
- package/src/calls/__tests__/voice-session-bridge.test.ts +884 -0
- package/src/calls/access-request-wait.ts +3 -1
- package/src/calls/audio-store.ts +6 -6
- package/src/calls/call-constants.ts +1 -1
- package/src/calls/call-controller.ts +242 -64
- package/src/calls/call-setup-flow-types.ts +2 -2
- package/src/calls/call-setup-flow.ts +19 -57
- package/src/calls/call-setup-router.ts +63 -39
- package/src/calls/call-speech-output.ts +39 -39
- package/src/calls/call-transport.ts +17 -5
- package/src/calls/channel-admission-reader.ts +38 -28
- package/src/calls/fish-audio-client.ts +24 -52
- package/src/calls/gateway-invite-reader.ts +15 -19
- package/src/calls/inbound-trust-reader.ts +74 -25
- package/src/calls/media-stream-audio-transcode.ts +1 -1
- package/src/calls/media-stream-output.ts +482 -64
- package/src/calls/media-stream-server.ts +156 -83
- package/src/calls/media-stream-stt-session.ts +1 -0
- package/src/calls/resolve-call-tts-provider.ts +60 -17
- package/src/calls/telephony-tts-capability.ts +13 -13
- package/src/calls/tts-text-sanitizer.ts +5 -3
- package/src/calls/unresolved-caller-trust.ts +36 -0
- package/src/calls/voice-session-bridge.ts +397 -52
- package/src/channels/__tests__/gateway-invites.test.ts +257 -0
- package/src/channels/gateway-invites.ts +142 -0
- package/src/channels/gateway-verification-sessions.ts +4 -8
- package/src/cli/AGENTS.md +60 -51
- package/src/cli/commands/__tests__/inference-models.test.ts +86 -0
- package/src/cli/commands/__tests__/inference-profiles.test.ts +254 -0
- package/src/cli/commands/__tests__/inference-providers.test.ts +171 -0
- package/src/cli/commands/__tests__/schedules.test.ts +133 -1
- package/src/cli/commands/__tests__/usage.test.ts +131 -0
- package/src/cli/commands/attachment.help.ts +100 -0
- package/src/cli/commands/attachment.ts +92 -157
- package/src/cli/commands/audit.help.ts +40 -0
- package/src/cli/commands/audit.ts +66 -86
- package/src/cli/commands/auth.help.ts +46 -0
- package/src/cli/commands/auth.ts +10 -43
- package/src/cli/commands/avatar.help.ts +236 -0
- package/src/cli/commands/avatar.ts +66 -250
- package/src/cli/commands/backup.help.ts +190 -0
- package/src/cli/commands/backup.ts +109 -276
- package/src/cli/commands/bash.help.ts +45 -0
- package/src/cli/commands/bash.ts +55 -75
- package/src/cli/commands/browser.help.ts +196 -0
- package/src/cli/commands/browser.ts +241 -352
- package/src/cli/commands/config.ts +166 -164
- package/src/cli/commands/contacts.ts +13 -22
- package/src/cli/commands/credentials.ts +38 -28
- package/src/cli/commands/db/repair-step-conversation-backfill.ts +19 -10
- package/src/cli/commands/db/repair.ts +20 -8
- package/src/cli/commands/default-action.ts +8 -3
- package/src/cli/commands/domain.ts +36 -22
- package/src/cli/commands/email.ts +77 -36
- package/src/cli/commands/inference-callsites.ts +158 -0
- package/src/cli/commands/inference-models.ts +84 -0
- package/src/cli/commands/inference-profiles.ts +371 -0
- package/src/cli/commands/inference-providers-default.ts +89 -0
- package/src/cli/commands/inference-providers.ts +117 -24
- package/src/cli/commands/inference.ts +6 -0
- package/src/cli/commands/keys.ts +27 -38
- package/src/cli/commands/memory/index.ts +8 -0
- package/src/cli/commands/memory/memory-retrospective.ts +7 -5
- package/src/cli/commands/memory/memory-v2-compare-render.ts +2 -2
- package/src/cli/commands/memory/nodes.ts +301 -0
- package/src/cli/commands/oauth/shared.ts +1 -1
- package/src/cli/commands/oauth/status.test.ts +6 -6
- package/src/cli/commands/oauth/status.ts +12 -6
- package/src/cli/commands/oauth/token.ts +1 -26
- package/src/cli/commands/plugins.ts +210 -116
- package/src/cli/commands/schedules.ts +17 -2
- package/src/cli/commands/tools-run.ts +4 -4
- package/src/cli/commands/tools.ts +23 -7
- package/src/cli/commands/ui.ts +2 -3
- package/src/cli/commands/usage.ts +59 -21
- package/src/cli/index.help.ts +31 -0
- package/src/cli/lib/__tests__/cli-output.test.ts +20 -0
- package/src/cli/lib/__tests__/diff-plugin.test.ts +2 -5
- package/src/cli/lib/__tests__/inspect-plugin.test.ts +1 -1
- package/src/cli/lib/__tests__/install-from-github.test.ts +37 -5
- package/src/cli/lib/__tests__/install-from-platform.test.ts +497 -0
- package/src/cli/lib/__tests__/list-installed-plugins.test.ts +36 -0
- package/src/cli/lib/__tests__/plugin-artifact.test.ts +54 -1
- package/src/cli/lib/__tests__/plugin-details.test.ts +137 -1
- package/src/cli/lib/__tests__/plugin-icon-file.test.ts +142 -0
- package/src/cli/lib/__tests__/plugin-marketplace.test.ts +1 -1
- package/src/cli/lib/__tests__/plugin-pin-history.test.ts +1 -1
- package/src/cli/lib/__tests__/search-plugins.test.ts +1 -1
- package/src/cli/lib/__tests__/uninstall-plugin.test.ts +82 -21
- package/src/cli/lib/__tests__/upgrade-plugin.test.ts +1 -1
- package/src/cli/lib/cli-command-help.ts +119 -0
- package/src/cli/lib/cli-output.ts +55 -0
- package/src/cli/lib/diff-plugin.ts +2 -2
- package/src/cli/lib/fetch-like.ts +11 -0
- package/src/cli/lib/inspect-plugin.ts +2 -2
- package/src/cli/lib/install-from-github.ts +61 -15
- package/src/cli/lib/install-from-platform.ts +618 -0
- package/src/cli/lib/list-installed-plugins.ts +39 -5
- package/src/cli/lib/plugin-artifact.ts +30 -0
- package/src/cli/lib/plugin-constants.ts +27 -0
- package/src/cli/lib/plugin-details.ts +51 -11
- package/src/cli/lib/plugin-icon-file.ts +101 -0
- package/src/cli/lib/plugin-marketplace.ts +1 -4
- package/src/cli/lib/plugin-pin-history.ts +27 -12
- package/src/cli/lib/publish-plugin.ts +3 -3
- package/src/cli/lib/search-plugins.ts +2 -6
- package/src/cli/lib/uninstall-plugin.ts +24 -2
- package/src/cli/lib/upgrade-plugin.ts +8 -22
- package/src/cli/program.ts +0 -2
- package/src/cli.ts +22 -13
- package/src/config/__tests__/default-profile-catalog.test.ts +384 -0
- package/src/config/__tests__/default-provider.test.ts +245 -0
- package/src/config/__tests__/deployment-context-defaults.test.ts +0 -21
- package/src/config/__tests__/loader-callsite-strip-fallback.test.ts +0 -21
- package/src/config/__tests__/loader-last-known-good.test.ts +208 -0
- package/src/config/__tests__/loader-sparse-array-cleanup.test.ts +145 -0
- package/src/config/__tests__/profile-materialization.test.ts +297 -0
- package/src/config/__tests__/seed-default-provider.test.ts +210 -0
- package/src/config/__tests__/sync-gated-profiles.test.ts +27 -34
- package/src/config/assistant-feature-flags.ts +1 -1
- package/src/config/bundled-skills/_shared/CLI_RETRIEVAL_PATTERN.md +9 -8
- package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +0 -6
- package/src/config/bundled-skills/phone-calls/references/CONFIG.md +2 -2
- package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-delete.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-list.ts +1 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +0 -4
- package/src/config/bundled-skills/schedule/SKILL.md +17 -0
- package/src/config/bundled-skills/transcribe/tools/transcribe-media.test.ts +0 -7
- package/src/config/call-site-defaults.ts +5 -2
- package/src/config/default-profile-catalog.ts +481 -0
- package/src/config/default-profile-names.ts +44 -0
- package/src/config/default-provider-resolution.ts +33 -0
- package/src/config/default-provider.ts +38 -0
- package/src/config/env-registry.ts +2 -0
- package/src/config/env.ts +0 -6
- package/src/config/feature-flag-registry.json +42 -50
- package/src/config/inference-profile-validation.ts +5 -4
- package/src/config/llm-resolver.ts +447 -24
- package/src/config/loader.ts +345 -10
- package/src/config/profile-materialization.ts +151 -0
- package/src/config/schema.ts +2 -52
- package/src/config/schemas/__tests__/live-voice.test.ts +108 -0
- package/src/config/schemas/__tests__/llm-request-logs.test.ts +33 -5
- package/src/config/schemas/call-site-catalog.ts +0 -6
- package/src/config/schemas/calls.ts +9 -0
- package/src/config/schemas/conversations.ts +1 -1
- package/src/config/schemas/live-voice.ts +77 -0
- package/src/config/schemas/llm-request-logs.ts +78 -27
- package/src/config/schemas/llm.ts +53 -2
- package/src/config/schemas/memory-lifecycle.ts +0 -6
- package/src/config/schemas/memory.ts +57 -1
- package/src/config/seed-inference-profiles.ts +100 -289
- package/src/config/sync-gated-profiles.ts +17 -23
- package/src/contacts/canonical-guardian-store.ts +6 -0
- package/src/contacts/contact-store.ts +272 -51
- package/src/contacts/contacts-write.ts +0 -22
- package/src/contacts/guardian-contact-reader.ts +3 -2
- package/src/contacts/member-write-relay.ts +2 -19
- package/src/contacts/types.ts +2 -1
- package/src/context/compactor.ts +230 -38
- package/src/context/image-dimensions.ts +25 -3
- package/src/context/token-estimator.ts +11 -7
- package/src/conversations/__tests__/message-consolidation.test.ts +6 -5
- package/src/conversations/job-handlers/summarization.ts +0 -2
- package/src/conversations/message-consolidation.ts +34 -112
- package/src/credential-execution/executable-discovery.ts +16 -144
- package/src/credential-execution/process-manager.test.ts +1 -112
- package/src/credential-execution/process-manager.ts +13 -379
- package/src/credential-execution/prompted-credential.ts +1 -1
- package/src/daemon/__tests__/conversation-surfaces-launch.test.ts +1 -1
- package/src/daemon/__tests__/inference-profile-notification.test.ts +0 -8
- package/src/daemon/__tests__/inflight-message-content.test.ts +219 -0
- package/src/daemon/__tests__/native-web-search-metadata.test.ts +0 -8
- package/src/daemon/__tests__/wake-conversation-ops-completion.test.ts +0 -6
- package/src/daemon/__tests__/web-search-status-text.test.ts +0 -8
- package/src/daemon/approval-generators.ts +17 -11
- package/src/daemon/assistant-attachments.ts +86 -87
- package/src/daemon/config-watcher.ts +67 -21
- package/src/daemon/conversation-agent-loop-handlers.ts +146 -50
- package/src/daemon/conversation-agent-loop.ts +136 -34
- package/src/daemon/conversation-error.ts +291 -109
- package/src/daemon/conversation-history.ts +6 -12
- package/src/daemon/conversation-initial-prompt.ts +1 -1
- package/src/daemon/conversation-launch.ts +1 -1
- package/src/daemon/conversation-lifecycle.ts +5 -22
- package/src/daemon/conversation-media-retry.ts +3 -2
- package/src/daemon/conversation-messaging.ts +296 -66
- package/src/daemon/conversation-notifiers.ts +1 -1
- package/src/daemon/conversation-process.ts +162 -12
- package/src/daemon/conversation-queue-manager.ts +12 -0
- package/src/daemon/conversation-runtime-assembly.ts +197 -53
- package/src/daemon/conversation-skill-tools.ts +27 -9
- package/src/daemon/conversation-slash.ts +2 -4
- package/src/daemon/conversation-store.ts +11 -13
- package/src/daemon/conversation-surfaces.ts +145 -176
- package/src/daemon/conversation-tool-setup.ts +18 -12
- package/src/daemon/conversation-turn-finalize.ts +18 -1
- package/src/daemon/conversation.ts +265 -85
- package/src/daemon/disk-pressure-policy.ts +1 -1
- package/src/daemon/event-loop-watchdog.test.ts +1 -6
- package/src/daemon/event-loop-watchdog.ts +2 -20
- package/src/daemon/handlers/__tests__/config-a2a-accept.test.ts +0 -7
- package/src/daemon/handlers/__tests__/config-a2a-complete.test.ts +1 -8
- package/src/daemon/handlers/__tests__/config-a2a-invite.test.ts +1 -8
- package/src/daemon/handlers/__tests__/config-a2a-redeem.test.ts +1 -8
- package/src/daemon/handlers/__tests__/config-a2a.test.ts +1 -8
- package/src/daemon/handlers/config-a2a.ts +0 -3
- package/src/daemon/handlers/conversation-history.ts +6 -4
- package/src/daemon/handlers/shared.ts +224 -79
- package/src/daemon/handlers/skills.ts +8 -0
- package/src/daemon/inflight-message-content.ts +228 -0
- package/src/daemon/interrupted-turn-reconciler.ts +134 -0
- package/src/daemon/lifecycle.ts +120 -64
- package/src/daemon/main.ts +1 -5
- package/src/daemon/message-types/conversations.ts +2 -0
- package/src/daemon/message-types/host-bash.ts +1 -1
- package/src/daemon/message-types/skills.ts +6 -0
- package/src/daemon/message-types/sync.ts +1 -0
- package/src/daemon/orphan-reaper.test.ts +1 -6
- package/src/daemon/persist-media-references.ts +151 -0
- package/src/daemon/pointer-conversation-trust.ts +2 -4
- package/src/daemon/process-message.ts +82 -8
- package/src/daemon/providers-setup.ts +1 -4
- package/src/daemon/shutdown-handlers.ts +0 -4
- package/src/daemon/sqlite-corruption-watchdog.test.ts +0 -13
- package/src/daemon/sqlite-corruption-watchdog.ts +2 -15
- package/src/daemon/summarize-boundary.ts +62 -0
- package/src/daemon/tool-setup-types.ts +1 -1
- package/src/daemon/trust-context-types.ts +61 -0
- package/src/daemon/trust-context.ts +5 -55
- package/src/daemon/wake-conversation-ops.ts +4 -1
- package/src/documents/document-comments-store.test.ts +1 -7
- package/src/export/__tests__/transcript-formatter.test.ts +13 -8
- package/src/export/formatter.ts +8 -17
- package/src/export/transcript-formatter.ts +13 -40
- package/src/heartbeat/__tests__/heartbeat-run-store.test.ts +0 -9
- package/src/heartbeat/__tests__/heartbeat-service.test.ts +0 -2
- package/src/home/__tests__/home-content-refresh.test.ts +0 -7
- package/src/home/__tests__/suggested-prompts.test.ts +4 -12
- package/src/home/conversation-starter-checkpoints.ts +9 -5
- package/src/home/job-handlers/conversation-starters.ts +24 -54
- package/src/home/suggested-prompts-cache.ts +91 -0
- package/src/home/suggested-prompts.ts +4 -77
- package/src/hooks/__tests__/hook-live-reload.test.ts +62 -48
- package/src/hooks/hook-loader.ts +215 -194
- package/src/hooks/types.ts +2 -2
- package/src/ipc/__tests__/contacts-info-ipc.test.ts +66 -11
- package/src/ipc/assistant-server.ts +14 -34
- package/src/ipc/gateway-flag-listener.ts +14 -25
- package/src/ipc/gateway-validated-call.ts +32 -0
- package/src/ipc/routes/__tests__/contacts-mirror-ipc-routes.test.ts +149 -17
- package/src/ipc/routes/__tests__/contacts-mirror-merge-contact.test.ts +197 -0
- package/src/ipc/routes/__tests__/contacts-mirror-upsert-full.test.ts +368 -0
- package/src/ipc/routes/__tests__/guardian-label-ipc-routes.test.ts +74 -0
- package/src/ipc/routes/__tests__/invite-ipc-routes.test.ts +0 -7
- package/src/ipc/routes/__tests__/memory-v2-backfill.test.ts +5 -7
- package/src/ipc/routes/contacts-info-ipc-routes.ts +5 -2
- package/src/ipc/routes/contacts-mirror-ipc-routes.ts +78 -1
- package/src/ipc/routes/db-proxy.ts +9 -15
- package/src/ipc/routes/guardian-label-ipc-routes.ts +42 -0
- package/src/live-voice/__tests__/live-voice-archive.test.ts +1 -8
- package/src/live-voice/__tests__/live-voice-credential-preflight.test.ts +275 -0
- package/src/live-voice/__tests__/live-voice-integration.test.ts +124 -0
- package/src/live-voice/__tests__/live-voice-metrics.test.ts +67 -0
- package/src/live-voice/__tests__/live-voice-session-preflight.test.ts +156 -0
- package/src/live-voice/__tests__/live-voice-stt.test.ts +464 -19
- package/src/live-voice/__tests__/live-voice-tts-session.test.ts +350 -4
- package/src/live-voice/__tests__/live-voice-tts.test.ts +186 -10
- package/src/live-voice/__tests__/live-voice-vad.test.ts +372 -10
- package/src/live-voice/__tests__/protocol.test.ts +2 -0
- package/src/live-voice/__tests__/runtime-websocket-shell.test.ts +61 -9
- package/src/live-voice/live-voice-credential-preflight.ts +205 -0
- package/src/live-voice/live-voice-metrics.ts +44 -0
- package/src/live-voice/live-voice-session-manager.ts +19 -0
- package/src/live-voice/live-voice-session.ts +1015 -276
- package/src/live-voice/live-voice-tts.ts +50 -4
- package/src/live-voice/protocol.ts +8 -0
- package/src/mcp/__tests__/mcp-auth-orchestrator.test.ts +3 -7
- package/src/messaging/channel-binding-schema.ts +15 -7
- package/src/messaging/providers/a2a/__tests__/deliver.test.ts +0 -9
- package/src/messaging/providers/slack/__tests__/download.test.ts +1 -8
- package/src/messaging/providers/slack/binding-metadata.test.ts +63 -0
- package/src/messaging/providers/slack/binding-metadata.ts +6 -0
- package/src/messaging/providers/slack/conversation-utils.ts +7 -4
- package/src/messaging/providers/slack/send.test.ts +0 -7
- package/src/messaging/providers/slack/types.ts +2 -0
- package/src/messaging/providers/slack/withdraw.test.ts +0 -6
- package/src/messaging/providers/telegram-bot/send.test.ts +0 -7
- package/src/monitoring/__tests__/resource-sampler.test.ts +2 -4
- package/src/monitoring/__tests__/stall-capture.test.ts +1 -1
- package/src/monitoring/process-memory.ts +6 -1
- package/src/monitoring/resource-sample-types.ts +71 -0
- package/src/monitoring/resource-sampler.ts +7 -69
- package/src/monitoring/stall-capture.ts +1 -1
- package/src/notifications/__tests__/broadcaster.test.ts +100 -9
- package/src/notifications/__tests__/connected-channels.test.ts +11 -8
- package/src/notifications/__tests__/decision-engine.test.ts +0 -7
- package/src/notifications/__tests__/destination-resolver.test.ts +18 -12
- package/src/notifications/__tests__/deterministic-checks.test.ts +1 -9
- package/src/notifications/access-request-copy.ts +33 -1
- package/src/notifications/adapters/slack.ts +7 -2
- package/src/notifications/approval-card-data.ts +4 -2
- package/src/notifications/broadcaster.ts +118 -67
- package/src/notifications/copy-composer.ts +6 -2
- package/src/notifications/emit-signal.ts +23 -1
- package/src/notifications/signal.ts +5 -4
- package/src/notifications/types.ts +1 -1
- package/src/notifications/urgency.ts +5 -0
- package/src/oauth/byo-connection.test.ts +1 -10
- package/src/oauth/connect-orchestrator.ts +1 -1
- package/src/oauth/connection-resolver.test.ts +140 -7
- package/src/oauth/connection-resolver.ts +48 -12
- package/src/oauth/oauth-store.ts +4 -11
- package/src/onboarding/__tests__/onboarding-events-store.test.ts +0 -8
- package/src/permissions/approval-policy.test.ts +0 -314
- package/src/permissions/approval-policy.ts +38 -90
- package/src/permissions/checker.test.ts +3 -14
- package/src/permissions/checker.ts +95 -19
- package/src/permissions/confirmation-canonical-request.ts +118 -0
- package/src/permissions/gateway-threshold-reader.test.ts +0 -8
- package/src/permissions/ipc-risk-types.ts +2 -0
- package/src/permissions/prompter.ts +16 -3
- package/src/permissions/secret-prompt-types.ts +34 -0
- package/src/permissions/secret-prompter.ts +21 -19
- package/src/permissions/types.ts +0 -14
- package/src/persistence/__tests__/bulk-write-gate.test.ts +159 -0
- package/src/persistence/__tests__/conversation-queries-search.test.ts +0 -7
- package/src/persistence/__tests__/immediate-transaction-guard.test.ts +70 -0
- package/src/persistence/__tests__/message-content-file.test.ts +259 -0
- package/src/persistence/__tests__/slow-query-log.test.ts +125 -0
- package/src/persistence/attachments-store.ts +90 -26
- package/src/persistence/auto-analysis-constants.ts +4 -13
- package/src/persistence/bulk-write-gate.ts +82 -0
- package/src/persistence/cleanup-schedule-state.ts +51 -21
- package/src/persistence/conversation-bootstrap.ts +3 -3
- package/src/persistence/conversation-crud.ts +382 -105
- package/src/persistence/conversation-disk-view.ts +32 -15
- package/src/persistence/conversation-group-migration.test.ts +1 -8
- package/src/persistence/conversation-key-store.ts +0 -2
- package/src/persistence/conversation-plugin-facade.ts +190 -0
- package/src/persistence/conversation-row-batch-delete.ts +16 -1
- package/src/persistence/conversation-title-service.ts +59 -22
- package/src/persistence/conversation-types.ts +19 -4
- package/src/persistence/db-async-query.ts +18 -9
- package/src/persistence/db-connection.ts +20 -4
- package/src/persistence/db-init.ts +16 -173
- package/src/persistence/db-maintenance.ts +78 -6
- package/src/persistence/embeddings/__tests__/messages-lexical-index.test.ts +0 -7
- package/src/persistence/embeddings/plugin-facade.ts +37 -0
- package/src/persistence/embeddings/qdrant-client.ts +2 -18
- package/src/persistence/fork-message-copy.ts +18 -4
- package/src/persistence/job-handlers/__tests__/message-lexical-backfill.test.ts +0 -7
- package/src/persistence/job-handlers/__tests__/message-lexical-enqueue.test.ts +0 -6
- package/src/persistence/job-handlers/__tests__/message-lexical.test.ts +0 -7
- package/src/persistence/job-handlers/message-lexical-backfill.ts +8 -5
- package/src/persistence/job-handlers/message-lexical.ts +2 -2
- package/src/persistence/jobs-store.ts +48 -85
- package/src/persistence/llm-request-log-sink-clickhouse.ts +325 -0
- package/src/persistence/llm-request-log-store.ts +213 -100
- package/src/persistence/llm-request-log-writer-types.ts +80 -0
- package/src/persistence/message-content-file.ts +301 -0
- package/src/persistence/message-content.ts +33 -72
- package/src/persistence/migrations/321-canonical-guardian-request-trigger.ts +27 -0
- package/src/persistence/migrations/322-add-processing-resume-attempts.ts +31 -0
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.test.ts +148 -0
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.ts +35 -0
- package/src/persistence/migrations/324-message-finalized-column.ts +26 -0
- package/src/persistence/migrations/325-create-config-setting-events.ts +40 -0
- package/src/persistence/migrations/326-move-injection-events-to-memory-db.ts +104 -0
- package/src/persistence/migrations/327-create-flush-checkpoints.ts +86 -0
- package/src/persistence/migrations/__tests__/297-move-llm-request-logs.test.ts +2 -2
- package/src/persistence/migrations/__tests__/327-create-flush-checkpoints.test.ts +124 -0
- package/src/persistence/schema/conversations.ts +25 -1
- package/src/persistence/schema/guardian.ts +5 -0
- package/src/persistence/schema/infrastructure.ts +33 -0
- package/src/persistence/schema/memory-core.ts +17 -28
- package/src/persistence/schema/memory-graph.ts +0 -4
- package/src/persistence/schema/memory-injection.ts +3 -1
- package/src/persistence/schema/tasks.ts +0 -1
- package/src/persistence/slow-query-log.ts +58 -21
- package/src/persistence/steps.ts +14 -0
- package/src/platform/consent-cache.test.ts +0 -7
- package/src/platform/managed-speech.test.ts +218 -0
- package/src/platform/managed-speech.ts +195 -0
- package/src/playbooks/playbook-compiler.ts +2 -10
- package/src/plugin-api/index.ts +79 -0
- package/src/plugin-api/model-profiles.test.ts +31 -3
- package/src/plugin-api/model-profiles.ts +3 -1
- package/src/plugin-api/types.ts +12 -3
- package/src/plugin-api/vision-support.ts +4 -3
- package/src/plugins/AGENTS.md +19 -0
- package/src/plugins/__tests__/plugin-state-boundary-guard.test.ts +65 -0
- package/src/plugins/defaults/compaction/compact.ts +13 -0
- package/src/plugins/defaults/compaction/window-manager.ts +207 -43
- package/src/plugins/defaults/image-fallback/__tests__/caption-cache-persistence.test.ts +216 -0
- package/src/plugins/defaults/image-fallback/__tests__/image-fallback.test.ts +281 -2
- package/src/plugins/defaults/image-fallback/__tests__/vision-recovery.test.ts +268 -0
- package/src/plugins/defaults/image-fallback/hooks/conversation-deleted.ts +27 -0
- package/src/plugins/defaults/image-fallback/hooks/init.ts +16 -0
- package/src/plugins/defaults/image-fallback/hooks/post-compact.ts +52 -0
- package/src/plugins/defaults/image-fallback/hooks/post-model-call.ts +80 -0
- package/src/plugins/defaults/image-fallback/hooks/post-tool-use.ts +7 -4
- package/src/plugins/defaults/image-fallback/hooks/shutdown.ts +14 -0
- package/src/plugins/defaults/image-fallback/hooks/stop.ts +23 -0
- package/src/plugins/defaults/image-fallback/hooks/user-prompt-submit.ts +12 -12
- package/src/plugins/defaults/image-fallback/src/caption-blocks.ts +73 -15
- package/src/plugins/defaults/image-fallback/src/caption-cache.ts +206 -20
- package/src/plugins/defaults/image-fallback/src/recovery-state.ts +49 -0
- package/src/plugins/defaults/image-fallback/src/vision-caption.ts +11 -3
- package/src/plugins/defaults/image-fallback/src/vision-error.ts +19 -0
- package/src/plugins/defaults/image-recovery/detect.ts +32 -10
- package/src/plugins/defaults/image-recovery/hooks/post-model-call.ts +20 -18
- package/src/plugins/defaults/image-recovery/recover.ts +97 -61
- package/src/plugins/defaults/index.ts +29 -5
- package/src/plugins/defaults/injector-order.ts +1 -0
- package/src/plugins/defaults/memory/__tests__/activation-session-store.test.ts +1 -8
- package/src/plugins/defaults/memory/__tests__/clear-stale-processing-flags.test.ts +1 -8
- package/src/plugins/defaults/memory/__tests__/conversation-queries.test.ts +1 -8
- package/src/plugins/defaults/memory/__tests__/conversation-row-batch-delete.test.ts +0 -6
- package/src/plugins/defaults/memory/__tests__/db-maintenance.test.ts +105 -11
- package/src/plugins/defaults/memory/__tests__/db-memory-attach.test.ts +22 -18
- package/src/plugins/defaults/memory/__tests__/embedding-cache.test.ts +0 -6
- package/src/plugins/defaults/memory/__tests__/find-most-recent-retrospective-for.test.ts +1 -8
- package/src/plugins/defaults/memory/__tests__/fork-message-copy.test.ts +0 -6
- package/src/plugins/defaults/memory/__tests__/jobs-store-enqueue-gate.test.ts +7 -70
- package/src/plugins/defaults/memory/__tests__/jobs-worker-memory-disabled.test.ts +0 -7
- package/src/plugins/defaults/memory/__tests__/jobs-worker-pkb-schedule.test.ts +7 -0
- package/src/plugins/defaults/memory/__tests__/jobs-worker-v2-graph-trigger-embed.test.ts +0 -5
- package/src/plugins/defaults/memory/__tests__/jobs-worker-v2-schedule.test.ts +7 -0
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-enqueue.test.ts +0 -7
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +186 -19
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +926 -0
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-startup-cleanup.test.ts +136 -82
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-state.test.ts +0 -6
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-trigger-check.test.ts +217 -2
- package/src/plugins/defaults/memory/__tests__/memory-v2-activation-log-store.test.ts +0 -7
- package/src/plugins/defaults/memory/__tests__/memory-v2-concept-frequency.test.ts +0 -7
- package/src/plugins/defaults/memory/__tests__/table-relocation.test.ts +49 -0
- package/src/plugins/defaults/memory/activation-session-store.ts +1 -1
- package/src/plugins/defaults/memory/anisotropy.ts +1 -1
- package/src/plugins/defaults/memory/config.ts +155 -6
- package/src/plugins/defaults/memory/context-search/agent-protocol.ts +1 -1
- package/src/plugins/defaults/memory/context-search/search.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +26 -23
- package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/memory.ts +1 -1
- package/src/plugins/defaults/memory/embeddings.ts +8 -40
- package/src/plugins/defaults/memory/filing-jobs.ts +1 -1
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +8 -4
- package/src/plugins/defaults/memory/frontmatter.ts +1 -1
- package/src/plugins/defaults/memory/graph/__tests__/handle-remember-v2.test.ts +4 -25
- package/src/plugins/defaults/memory/graph/bootstrap.ts +13 -19
- package/src/plugins/defaults/memory/graph/capability-seed.ts +62 -33
- package/src/plugins/defaults/memory/graph/consolidation.ts +8 -15
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +12 -4
- package/src/plugins/defaults/memory/graph/decay.ts +5 -10
- package/src/plugins/defaults/memory/graph/extraction-job.ts +2 -3
- package/src/plugins/defaults/memory/graph/extraction.test.ts +1 -9
- package/src/plugins/defaults/memory/graph/extraction.ts +149 -64
- package/src/plugins/defaults/memory/graph/graph-search.test.ts +0 -6
- package/src/plugins/defaults/memory/graph/graph-search.ts +33 -15
- package/src/plugins/defaults/memory/graph/image-ref-utils.ts +7 -3
- package/src/plugins/defaults/memory/graph/injection.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/injection.ts +1 -1
- package/src/plugins/defaults/memory/graph/narrative.ts +2 -4
- package/src/plugins/defaults/memory/graph/pattern-scan.ts +2 -5
- package/src/plugins/defaults/memory/graph/retriever.test.ts +27 -28
- package/src/plugins/defaults/memory/graph/retriever.ts +89 -42
- package/src/plugins/defaults/memory/graph/scoring.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/store.test.ts +6 -58
- package/src/plugins/defaults/memory/graph/store.ts +5 -43
- package/src/plugins/defaults/memory/graph/tool-handlers.test.ts +318 -0
- package/src/plugins/defaults/memory/graph/tool-handlers.ts +244 -8
- package/src/plugins/defaults/memory/graph/tools.ts +1 -1
- package/src/plugins/defaults/memory/graph/types.ts +0 -3
- package/src/plugins/defaults/memory/graph-topology/__tests__/build-memory-graph.test.ts +130 -0
- package/src/plugins/defaults/memory/graph-topology/build-memory-graph.ts +303 -0
- package/src/plugins/defaults/memory/graph-topology/flag.ts +14 -0
- package/src/plugins/defaults/memory/graph-topology/types.ts +84 -0
- package/src/plugins/defaults/memory/hooks/init.ts +1 -1
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +10 -10
- package/src/plugins/defaults/memory/host-utils.ts +80 -0
- package/src/plugins/defaults/memory/identity-context.ts +39 -0
- package/src/plugins/defaults/memory/indexer.ts +18 -54
- package/src/plugins/defaults/memory/injectors.ts +5 -8
- package/src/plugins/defaults/memory/job-handler-registration.ts +0 -4
- package/src/plugins/defaults/memory/job-handlers/backfill.ts +10 -8
- package/src/plugins/defaults/memory/job-handlers/embedding.test.ts +0 -8
- package/src/plugins/defaults/memory/job-handlers/embedding.ts +31 -17
- package/src/plugins/defaults/memory/job-handlers/index-maintenance.ts +13 -6
- package/src/plugins/defaults/memory/job-handlers.ts +10 -9
- package/src/plugins/defaults/memory/jobs/__tests__/embed-concept-page.test.ts +0 -7
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +3 -3
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.test.ts +41 -28
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.ts +10 -5
- package/src/plugins/defaults/memory/jobs-worker.ts +161 -50
- package/src/plugins/defaults/memory/logging.ts +17 -0
- package/src/plugins/defaults/memory/memory-retrospective-accounting.ts +143 -0
- package/src/plugins/defaults/memory/memory-retrospective-constants.ts +19 -7
- package/src/plugins/defaults/memory/memory-retrospective-enqueue.ts +5 -6
- package/src/plugins/defaults/memory/memory-retrospective-fork-boundary.ts +57 -20
- package/src/plugins/defaults/memory/memory-retrospective-job.ts +220 -79
- package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +448 -0
- package/src/plugins/defaults/memory/memory-retrospective-startup-cleanup.ts +52 -39
- package/src/plugins/defaults/memory/memory-retrospective-state.ts +14 -10
- package/src/plugins/defaults/memory/memory-retrospective-trigger-check.ts +8 -3
- package/src/plugins/defaults/memory/message-media.ts +80 -0
- package/src/plugins/defaults/memory/paths.ts +48 -0
- package/src/plugins/defaults/memory/pkb/autoinject.ts +1 -1
- package/src/plugins/defaults/memory/pkb/context.ts +2 -2
- package/src/plugins/defaults/memory/pkb/pkb-index.test.ts +25 -44
- package/src/plugins/defaults/memory/pkb/pkb-index.ts +24 -25
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.test.ts +46 -34
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.ts +4 -9
- package/src/plugins/defaults/memory/pkb/pkb-search.test.ts +5 -17
- package/src/plugins/defaults/memory/pkb/pkb-search.ts +2 -9
- package/src/plugins/defaults/memory/pkb/types.ts +1 -12
- package/src/plugins/defaults/memory/pkb-schedule.ts +2 -2
- package/src/plugins/defaults/memory/rerank-local.ts +3 -4
- package/src/plugins/defaults/memory/routes/__tests__/memory-v2-simulate-route.test.ts +9 -17
- package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +2 -2
- package/src/plugins/defaults/memory/routes/memory-graph-routes.ts +71 -0
- package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +149 -9
- package/src/plugins/defaults/memory/routes/memory-item-routes.ts +147 -12
- package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +7 -11
- package/src/plugins/defaults/memory/routes/memory-v3-routes.ts +1 -1
- package/src/plugins/defaults/memory/startup.ts +3 -4
- package/src/plugins/defaults/memory/task-memory-cleanup.ts +1 -1
- package/src/plugins/defaults/memory/tools.test.ts +1 -9
- package/src/plugins/defaults/memory/tools.ts +0 -1
- package/src/plugins/defaults/memory/v2/__tests__/activation.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/backfill-jobs.test.ts +0 -6
- package/src/plugins/defaults/memory/v2/__tests__/cli-command-store.test.ts +6 -6
- package/src/plugins/defaults/memory/v2/__tests__/consolidation-job.test.ts +48 -6
- package/src/plugins/defaults/memory/v2/__tests__/harness-compare.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/harness-oracle.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/harness-replay-input.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/injection-events.test.ts +61 -69
- package/src/plugins/defaults/memory/v2/__tests__/injection.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/migration.test.ts +0 -6
- package/src/plugins/defaults/memory/v2/__tests__/page-index.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/prompts-consolidation.test.ts +28 -0
- package/src/plugins/defaults/memory/v2/__tests__/qdrant.test.ts +3 -6
- package/src/plugins/defaults/memory/v2/__tests__/reranker.test.ts +3 -5
- package/src/plugins/defaults/memory/v2/__tests__/router.test.ts +16 -27
- package/src/plugins/defaults/memory/v2/__tests__/sim.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/__tests__/skill-content.test.ts +1 -1
- package/src/plugins/defaults/memory/v2/__tests__/skill-store.test.ts +56 -22
- package/src/plugins/defaults/memory/v2/__tests__/static-context.test.ts +9 -6
- package/src/plugins/defaults/memory/v2/__tests__/sweep-job.test.ts +6 -6
- package/src/plugins/defaults/memory/v2/backfill-jobs.ts +31 -16
- package/src/plugins/defaults/memory/v2/cli-command-content.ts +78 -0
- package/src/plugins/defaults/memory/v2/cli-command-store.ts +32 -11
- package/src/plugins/defaults/memory/v2/consolidation-job.ts +45 -5
- package/src/plugins/defaults/memory/v2/frontmatter-sweep.ts +1 -1
- package/src/plugins/defaults/memory/v2/harness/harness-types.ts +12 -0
- package/src/plugins/defaults/memory/v2/harness/retriever.ts +1 -8
- package/src/plugins/defaults/memory/v2/harness/router-retriever.ts +1 -8
- package/src/plugins/defaults/memory/v2/harness/trace.ts +1 -1
- package/src/plugins/defaults/memory/v2/injection-events.ts +34 -15
- package/src/plugins/defaults/memory/v2/injection.ts +3 -4
- package/src/plugins/defaults/memory/v2/memory-v2-startup.test.ts +0 -5
- package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +2 -2
- package/src/plugins/defaults/memory/v2/migration.ts +1 -1
- package/src/plugins/defaults/memory/v2/page-index.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +6 -2
- package/src/plugins/defaults/memory/v2/prompts/router.ts +1 -1
- package/src/plugins/defaults/memory/v2/qdrant.ts +2 -2
- package/src/plugins/defaults/memory/v2/reranker.ts +2 -2
- package/src/plugins/defaults/memory/v2/router.ts +10 -20
- package/src/plugins/defaults/memory/v2/skill-content.ts +23 -4
- package/src/plugins/defaults/memory/v2/skill-store.ts +44 -43
- package/src/plugins/defaults/memory/v2/static-context.ts +7 -12
- package/src/plugins/defaults/memory/v2/sweep-job.ts +24 -13
- package/src/plugins/defaults/memory/v3/__tests__/carry-integration.test.ts +19 -0
- package/src/plugins/defaults/memory/v3/__tests__/dense.test.ts +0 -5
- package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +17 -0
- package/src/plugins/defaults/memory/v3/__tests__/live-integration.test.ts +14 -4
- package/src/plugins/defaults/memory/v3/__tests__/maintain-job.test.ts +23 -17
- package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +20 -6
- package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +2 -0
- package/src/plugins/defaults/memory/v3/__tests__/section-dense-store.test.ts +0 -5
- package/src/plugins/defaults/memory/v3/candidate-match.ts +20 -11
- package/src/plugins/defaults/memory/v3/dense.ts +1 -1
- package/src/plugins/defaults/memory/v3/injector.ts +1 -1
- package/src/plugins/defaults/memory/v3/learned-edges.test.ts +14 -0
- package/src/plugins/defaults/memory/v3/learned-edges.ts +6 -1
- package/src/plugins/defaults/memory/v3/maintain-job.ts +39 -31
- package/src/plugins/defaults/memory/v3/orchestrate.ts +1 -1
- package/src/plugins/defaults/memory/v3/page-content.ts +1 -1
- package/src/plugins/defaults/memory/v3/pool-select.ts +2 -3
- package/src/plugins/defaults/memory/v3/prune.test.ts +10 -0
- package/src/plugins/defaults/memory/v3/prune.ts +1 -1
- package/src/plugins/defaults/memory/v3/section-dense-store.ts +1 -1
- package/src/plugins/defaults/memory/v3/selection-log-store.ts +1 -1
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +47 -25
- package/src/plugins/defaults/memory/v3-eval/eval-packets.ts +31 -11
- package/src/plugins/defaults/memory/worker.ts +2 -2
- package/src/plugins/defaults/workspace/injectors.ts +116 -5
- package/src/plugins/mtime-cache.ts +207 -105
- package/src/plugins/pipeline.ts +195 -5
- package/src/plugins/surface-import.ts +52 -14
- package/src/plugins/types.ts +10 -15
- package/src/prompts/persona-resolver.ts +1 -1
- package/src/prompts/system-prompt.ts +2 -4
- package/src/prompts/templates/system-sections.ts +12 -0
- package/src/providers/__tests__/connection-model-compat.test.ts +0 -5
- package/src/providers/__tests__/count-tokens-forwarding.test.ts +1 -21
- package/src/providers/__tests__/dispatch-connection-routing.test.ts +12 -6
- package/src/providers/__tests__/preflight-resolved-config.test.ts +189 -0
- package/src/providers/__tests__/registry-native-web-search.test.ts +21 -3
- package/src/providers/__tests__/retry-callsite.test.ts +207 -8
- package/src/providers/__tests__/satellite-connection-routing.test.ts +12 -6
- package/src/providers/__tests__/vellum-mismatch-routing.test.ts +0 -5
- package/src/providers/anthropic/client.ts +109 -7
- package/src/providers/anthropic-gateway-shared.ts +63 -0
- package/src/providers/call-site-routing.ts +1 -0
- package/src/providers/connection-resolution.ts +192 -6
- package/src/providers/content-block-schema.ts +149 -0
- package/src/providers/gemini/client.ts +84 -22
- package/src/providers/gemini/inline-media.ts +2 -3
- package/src/providers/inference/__tests__/base-url-route-validation.test.ts +5 -0
- package/src/providers/inference/__tests__/codex-token-refresh.test.ts +1 -15
- package/src/providers/inference/adapter-factory.ts +13 -0
- package/src/providers/inference/connection-availability.ts +193 -0
- package/src/providers/inference/connections.ts +6 -10
- package/src/providers/media-resolve.ts +193 -0
- package/src/providers/model-catalog.ts +337 -17
- package/src/providers/model-intents.ts +6 -0
- package/src/providers/openai/__tests__/api-error-normalization.test.ts +98 -0
- package/src/providers/openai/__tests__/chat-completions-provider-reasoning.test.ts +112 -0
- package/src/providers/openai/api-error-normalization.ts +61 -0
- package/src/providers/openai/chat-completions-provider.ts +73 -10
- package/src/providers/openai/responses-provider.ts +10 -3
- package/src/providers/openrouter/client.ts +6 -39
- package/src/providers/platform-proxy/constants.ts +4 -0
- package/src/providers/provider-availability.ts +23 -1
- package/src/providers/provider-send-message.ts +19 -3
- package/src/providers/registry.ts +5 -1
- package/src/providers/retry.ts +91 -29
- package/src/providers/speech-to-text/__tests__/resolve.test.ts +31 -0
- package/src/providers/speech-to-text/deepgram-realtime.test.ts +393 -1
- package/src/providers/speech-to-text/deepgram-realtime.ts +213 -13
- package/src/providers/speech-to-text/resolve.ts +33 -5
- package/src/providers/types.ts +69 -24
- package/src/providers/vellum-model-routing.ts +11 -0
- package/src/providers/vercel-ai-gateway/client.ts +142 -0
- package/src/runtime/__tests__/actor-trust-resolver.test.ts +132 -0
- package/src/runtime/__tests__/agent-wake.test.ts +232 -16
- package/src/runtime/__tests__/background-job-runner.test.ts +71 -2
- package/src/runtime/__tests__/guardian-vellum-migration.test.ts +5 -15
- package/src/runtime/__tests__/local-principal-trust.test.ts +0 -6
- package/src/runtime/__tests__/member-verdict-cache.test.ts +2 -15
- package/src/runtime/__tests__/trust-verdict-consumer.test.ts +91 -30
- package/src/runtime/access-request-helper.ts +75 -3
- package/src/runtime/actor-trust-resolver.ts +33 -108
- package/src/runtime/agent-wake.ts +45 -25
- package/src/runtime/assistant-event-hub.ts +0 -105
- package/src/runtime/auth/__tests__/middleware.test.ts +1 -10
- package/src/runtime/auth/__tests__/route-policy.test.ts +0 -7
- package/src/runtime/auth/__tests__/token-service.test.ts +1 -8
- package/src/runtime/background-job-runner.ts +57 -2
- package/src/runtime/capabilities.ts +3 -3
- package/src/runtime/channel-reply-delivery.ts +38 -19
- package/src/runtime/channel-retry-sweep.ts +1 -1
- package/src/runtime/confirmation-request-guardian-bridge.ts +4 -3
- package/src/runtime/effective-capabilities.test.ts +0 -36
- package/src/runtime/effective-capabilities.ts +8 -23
- package/src/runtime/guardian-vellum-migration.ts +12 -16
- package/src/runtime/http-router-types.ts +119 -0
- package/src/runtime/http-router.ts +2 -115
- package/src/runtime/http-server.ts +11 -2
- package/src/runtime/http-types.ts +1 -1
- package/src/runtime/introduction-policy.ts +89 -0
- package/src/runtime/local-actor-identity.ts +4 -50
- package/src/runtime/local-principal-trust.ts +1 -1
- package/src/runtime/member-verdict-cache.ts +0 -0
- package/src/runtime/migrations/__tests__/gcs-signed-url.test.ts +51 -1
- package/src/runtime/migrations/__tests__/origin-mode.test.ts +62 -0
- package/src/runtime/migrations/gcs-signed-url.ts +21 -7
- package/src/runtime/migrations/origin-mode.ts +16 -11
- package/src/runtime/pending-interactions.ts +8 -3
- package/src/runtime/routes/__tests__/acp-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/backup-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/bookmark-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/channel-verification-revoke.test.ts +0 -16
- package/src/runtime/routes/__tests__/client-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/connection-routes-vs-cli-parity.test.ts +4 -5
- package/src/runtime/routes/__tests__/consolidation-routes.test.ts +8 -8
- package/src/runtime/routes/__tests__/contact-routes.test.ts +2 -3
- package/src/runtime/routes/__tests__/content-source-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/conversation-compaction-routes.test.ts +31 -9
- package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/conversation-management-routes.test.ts +0 -8
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +260 -11
- package/src/runtime/routes/__tests__/conversation-surface-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/default-provider-routes.test.ts +499 -0
- package/src/runtime/routes/__tests__/global-search-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/inference-callsites-routes.test.ts +54 -0
- package/src/runtime/routes/__tests__/inference-models-routes.test.ts +54 -0
- package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +403 -0
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +219 -6
- package/src/runtime/routes/__tests__/inference-routes-registration.test.ts +42 -0
- package/src/runtime/routes/__tests__/invite-relay-routes.test.ts +70 -15
- package/src/runtime/routes/__tests__/monitoring-routes.test.ts +1 -1
- package/src/runtime/routes/__tests__/plugins-routes.test.ts +182 -38
- package/src/runtime/routes/__tests__/retrospective-routes.test.ts +1 -8
- package/src/runtime/routes/__tests__/sanity-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/stt-routes.test.ts +0 -9
- package/src/runtime/routes/__tests__/suggest-trust-rule-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/task-routes.test.ts +2 -2
- package/src/runtime/routes/__tests__/theme-routes.test.ts +66 -0
- package/src/runtime/routes/__tests__/tts-routes.test.ts +0 -7
- package/src/runtime/routes/__tests__/user-route-dispatcher.test.ts +1 -9
- package/src/runtime/routes/__tests__/wake-conversation-routes.test.ts +0 -7
- package/src/runtime/routes/acp-routes.ts +20 -14
- package/src/runtime/routes/approval-routes.ts +21 -2
- package/src/runtime/routes/canned-message-complete.ts +82 -0
- package/src/runtime/routes/channel-metadata.ts +49 -0
- package/src/runtime/routes/contact-routes.ts +75 -43
- package/src/runtime/routes/conversation-attention-routes.ts +1 -1
- package/src/runtime/routes/conversation-cli-routes.ts +2 -2
- package/src/runtime/routes/conversation-compaction-routes.ts +5 -0
- package/src/runtime/routes/conversation-management-routes.ts +147 -2
- package/src/runtime/routes/conversation-query-routes.ts +378 -43
- package/src/runtime/routes/conversation-routes.ts +89 -181
- package/src/runtime/routes/conversation-starter-routes.ts +12 -23
- package/src/runtime/routes/credential-prompt-routes.ts +48 -4
- package/src/runtime/routes/credential-request-routes.ts +85 -0
- package/src/runtime/routes/credential-routes.ts +40 -5
- package/src/runtime/routes/default-provider-routes.ts +132 -0
- package/src/runtime/routes/errors.ts +17 -0
- package/src/runtime/routes/events-routes.ts +158 -39
- package/src/runtime/routes/guardian-approval-interception.ts +1 -1
- package/src/runtime/routes/http-adapter.ts +1 -1
- package/src/runtime/routes/inbound-message-handler.ts +61 -6
- package/src/runtime/routes/inbound-stages/acl-enforcement.test.ts +58 -26
- package/src/runtime/routes/inbound-stages/acl-enforcement.ts +73 -87
- package/src/runtime/routes/inbound-stages/admission-policy.ts +2 -1
- package/src/runtime/routes/inbound-stages/background-dispatch.test.ts +1 -8
- package/src/runtime/routes/inbound-stages/background-dispatch.ts +3 -2
- package/src/runtime/routes/inbound-stages/bootstrap-intercept.test.ts +0 -5
- package/src/runtime/routes/inbound-stages/edit-intercept.ts +5 -1
- package/src/runtime/routes/inbound-stages/escalation-intercept.test.ts +0 -5
- package/src/runtime/routes/inbound-stages/guardian-activation-intercept.test.ts +0 -9
- package/src/runtime/routes/inbound-stages/guardian-reply-intercept.test.ts +0 -9
- package/src/runtime/routes/inbound-stages/reaction-intercept.test.ts +302 -0
- package/src/runtime/routes/inbound-stages/reaction-intercept.ts +27 -37
- package/src/runtime/routes/inbound-stages/secret-ingress-check.ts +1 -1
- package/src/runtime/routes/inbound-stages/transcribe-audio.test.ts +0 -9
- package/src/runtime/routes/index.ts +16 -4
- package/src/runtime/routes/inference-callsites-routes.ts +211 -0
- package/src/runtime/routes/inference-models-routes.ts +104 -0
- package/src/runtime/routes/inference-profile-session-handler.ts +2 -1
- package/src/runtime/routes/inference-profiles-routes.ts +717 -0
- package/src/runtime/routes/inference-provider-connection-routes.ts +38 -1
- package/src/runtime/routes/inference-send-routes.ts +2 -1
- package/src/runtime/routes/integrations/slack/channels.ts +26 -4
- package/src/runtime/routes/integrations/slack/users.ts +78 -0
- package/src/runtime/routes/internal-telemetry-routes.ts +44 -0
- package/src/runtime/routes/llm-call-sites-routes.ts +2 -1
- package/src/runtime/routes/llm-request-logs-access.ts +19 -0
- package/src/runtime/routes/migration-routes.ts +94 -47
- package/src/runtime/routes/monitoring-routes.ts +1 -1
- package/src/runtime/routes/notification-routes.ts +1 -1
- package/src/runtime/routes/playground/__tests__/reset-circuit.test.ts +0 -7
- package/src/runtime/routes/plugins-routes.ts +169 -16
- package/src/runtime/routes/schedule-routes.ts +38 -1
- package/src/runtime/routes/secret-routes.ts +0 -7
- package/src/runtime/routes/settings-routes.ts +160 -22
- package/src/runtime/routes/skills-routes.ts +6 -0
- package/src/runtime/routes/subagents-routes.ts +17 -18
- package/src/runtime/routes/surface-action-routes.ts +4 -2
- package/src/runtime/routes/theme-routes.ts +36 -0
- package/src/runtime/routes/types.ts +2 -1
- package/src/runtime/routes/workflow-routes.ts +1 -1
- package/src/runtime/services/__tests__/auto-analysis-guard.test.ts +2 -16
- package/src/runtime/services/__tests__/conversation-serializer.test.ts +0 -1
- package/src/runtime/services/auto-analysis-guard.ts +5 -5
- package/src/runtime/services/conversation-serializer.ts +2 -3
- package/src/runtime/sync/resource-sync-events.ts +4 -0
- package/src/runtime/trust-context-resolver.ts +9 -9
- package/src/runtime/trust-verdict-consumer.ts +46 -5
- package/src/schedule/scheduler.ts +61 -18
- package/src/security/__tests__/oauth2-device-code.test.ts +12 -60
- package/src/security/__tests__/provider-key-env-fallback.test.ts +0 -10
- package/src/security/__tests__/secret-normalize.test.ts +96 -0
- package/src/security/secret-normalize.ts +41 -0
- package/src/security/secret-patterns.ts +3 -0
- package/src/security/secure-keys.ts +222 -49
- package/src/sequence/engine.ts +15 -6
- package/src/signals/user-message.ts +3 -1
- package/src/skills/available-skills.ts +134 -0
- package/src/skills/install-meta.ts +8 -0
- package/src/skills/managed-store.ts +10 -0
- package/src/stt/types.ts +33 -2
- package/src/subagent/manager.ts +5 -6
- package/src/tasks/SPEC.md +10 -17
- package/src/tasks/tool-sanitizer.ts +3 -1
- package/src/telemetry/__tests__/config-setting-events-store.test.ts +126 -0
- package/src/telemetry/__tests__/flush-checkpoints.test.ts +56 -0
- package/src/telemetry/__tests__/watchdog-events-store.test.ts +0 -8
- package/src/telemetry/config-setting-events-store.ts +97 -0
- package/src/telemetry/flush-checkpoints.ts +70 -0
- package/src/telemetry/skill-loaded-events-store.test.ts +0 -8
- package/src/telemetry/telemetry-event-sources.ts +571 -0
- package/src/telemetry/tool-audit.ts +285 -0
- package/src/telemetry/tool-executed-events-store.test.ts +19 -27
- package/src/telemetry/tool-executed-events-store.ts +5 -5
- package/src/telemetry/turn-events-store.ts +36 -0
- package/src/telemetry/turn-outcome.ts +116 -0
- package/src/telemetry/turn-trace-store.test.ts +156 -8
- package/src/telemetry/turn-trace-store.ts +53 -4
- package/src/telemetry/types.ts +91 -2
- package/src/telemetry/usage-telemetry-reporter.test.ts +373 -119
- package/src/telemetry/usage-telemetry-reporter.ts +110 -675
- package/src/telemetry/watchdog-direct-emit.test.ts +0 -5
- package/src/theme/workspace-theme.test.ts +269 -0
- package/src/theme/workspace-theme.ts +304 -0
- package/src/tools/AGENTS.md +0 -26
- package/src/tools/acp/spawn.test.ts +0 -7
- package/src/tools/browser/browser-execution.ts +99 -75
- package/src/tools/browser/cdp-client/__tests__/cdp-inspect-client.test.ts +1 -11
- package/src/tools/browser/cdp-client/__tests__/local-cdp-client.test.ts +0 -10
- package/src/tools/browser/network-recorder.test.ts +0 -11
- package/src/tools/document/document-comment-tool.test.ts +1 -7
- package/src/tools/execution-target.test.ts +31 -0
- package/src/tools/execution-target.ts +1 -1
- package/src/tools/executor.ts +63 -275
- package/src/tools/filesystem/write.ts +0 -2
- package/src/tools/host-terminal/host-shell.test.ts +0 -7
- package/src/tools/host-terminal/host-shell.ts +6 -49
- package/src/tools/permission-checker.ts +33 -81
- package/src/tools/registry.ts +261 -166
- package/src/tools/run-standalone.ts +6 -13
- package/src/tools/side-effects.ts +0 -1
- package/src/tools/skills/find-similar-skills.test.ts +5 -9
- package/src/tools/skills/scaffold-managed.ts +31 -4
- package/src/tools/skills/skill-script-runner.ts +17 -31
- package/src/tools/skills/skill-tool-factory.ts +2 -6
- package/src/tools/subagent/read.ts +6 -4
- package/src/tools/subagent/spawn.ts +28 -29
- package/src/tools/terminal/safe-env.ts +8 -3
- package/src/tools/terminal/shell.test.ts +0 -6
- package/src/tools/terminal/shell.ts +1 -50
- package/src/tools/tool-approval-handler.ts +99 -166
- package/src/tools/tool-defaults.ts +2 -6
- package/src/tools/tool-manifest.ts +0 -49
- package/src/{events/tool-profiling-listener.ts → tools/tool-profiler.ts} +64 -32
- package/src/tools/tool-types.ts +4 -95
- package/src/tools/types.ts +27 -140
- package/src/tools/workflows/manage-workflows.ts +2 -1
- package/src/tools/workflows/run-workflow.test.ts +6 -1
- package/src/tools/workflows/run-workflow.ts +2 -4
- package/src/tools/workspace-tools/loader.ts +26 -14
- package/src/tts/__tests__/pcm-chunk-aligner.test.ts +48 -0
- package/src/tts/__tests__/pcm-sample-rates.test.ts +59 -0
- package/src/tts/__tests__/provider-adapters.test.ts +891 -22
- package/src/tts/__tests__/provider-catalog.test.ts +43 -10
- package/src/tts/__tests__/speakable-segments.test.ts +427 -0
- package/src/tts/__tests__/synthesis-stream.test.ts +5 -1
- package/src/tts/pcm-chunk-aligner.ts +29 -0
- package/src/tts/pcm-sample-rates.ts +47 -0
- package/src/tts/provider-definition.ts +6 -7
- package/src/tts/providers/__tests__/xai-tts-socket.test.ts +406 -0
- package/src/tts/providers/deepgram-provider.ts +160 -102
- package/src/tts/providers/elevenlabs-provider.ts +182 -105
- package/src/tts/providers/fish-audio-provider.ts +72 -105
- package/src/tts/providers/xai-provider.ts +131 -22
- package/src/tts/providers/xai-tts-socket.ts +311 -0
- package/src/tts/speakable-segments.ts +188 -0
- package/src/tts/stream-read.ts +136 -0
- package/src/tts/synthesis-stream.ts +9 -5
- package/src/tts/synthesize-text.ts +15 -5
- package/src/tts/types.ts +21 -0
- package/src/usage/attribution.ts +43 -9
- package/src/util/errors.ts +26 -0
- package/src/util/image-conversion.ts +23 -5
- package/src/util/logger.ts +67 -68
- package/src/util/platform.ts +19 -60
- package/src/util/pricing.ts +14 -11
- package/src/util/process-tree.ts +25 -13
- package/src/util/provider-error-patterns.ts +21 -0
- package/src/util/sqlite-query-label.ts +51 -0
- package/src/util/sqlite-retry.ts +14 -2
- package/src/util/unicode.ts +1 -1
- package/src/watcher/__tests__/engine-auth-notify.test.ts +316 -0
- package/src/watcher/engine.ts +87 -2
- package/src/workflows/capabilities.test.ts +2 -32
- package/src/workflows/capabilities.ts +18 -25
- package/src/workflows/engine-integration.test.ts +1 -7
- package/src/workflows/engine.test.ts +2 -10
- package/src/workflows/engine.ts +1 -1
- package/src/workflows/fanout-load.test.ts +1 -1
- package/src/workflows/journal-store.test.ts +1 -9
- package/src/workflows/leaf-runner.test.ts +0 -6
- package/src/workflows/leaf-runner.ts +4 -5
- package/src/workflows/library.test.ts +1 -9
- package/src/workflows/run-manager.test.ts +2 -10
- package/src/workflows/run-manager.ts +2 -4
- package/src/workspace/adaptive-thinking-repair.ts +1 -1
- package/src/workspace/custom-profile-ensure.ts +133 -0
- package/src/workspace/default-provider-ensure.ts +162 -0
- package/src/workspace/git-service.ts +160 -15
- package/src/workspace/migrations/028-recover-conversations-from-disk-view.ts +0 -1
- package/src/workspace/migrations/097-enable-adaptive-thinking-managed-profiles.ts +1 -1
- package/src/workspace/migrations/126-strip-managed-profile-bodies.ts +92 -0
- package/src/workspace/migrations/127-backfill-default-provider.ts +176 -0
- package/src/workspace/migrations/128-repair-stale-openrouter-grok-model-ids.ts +112 -0
- package/src/workspace/migrations/129-remove-analyze-conversation-config.ts +59 -0
- package/src/workspace/migrations/registry.ts +8 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/scripts/generate-bundled-tool-registry.ts +0 -223
- package/scripts/test.sh +0 -494
- package/src/__tests__/actor-trust-resolver-address-fallback.test.ts +0 -255
- package/src/__tests__/agent-loop-sentry-hygiene.test.ts +0 -137
- package/src/__tests__/auto-analysis-end-to-end.test.ts +0 -621
- package/src/__tests__/auto-analysis-prompt.test.ts +0 -50
- package/src/__tests__/config-analysis.test.ts +0 -83
- package/src/__tests__/conversation-analysis-routes.test.ts +0 -156
- package/src/__tests__/credential-execution-admin-cli.test.ts +0 -504
- package/src/__tests__/credential-execution-approval-bridge.test.ts +0 -297
- package/src/__tests__/credential-execution-feature-gates.test.ts +0 -185
- package/src/__tests__/credential-execution-shell-lockdown.test.ts +0 -120
- package/src/__tests__/credential-execution-tools.test.ts +0 -289
- package/src/__tests__/db-proxy-transaction.test.ts +0 -206
- package/src/__tests__/event-bus.test.ts +0 -222
- package/src/__tests__/reaction-intercept-cold-cache-warm.test.ts +0 -141
- package/src/__tests__/reaction-intercept-member-verdict-warm.test.ts +0 -157
- package/src/__tests__/skill-memory.test.ts +0 -85
- package/src/__tests__/skill-runtime-path.test.ts +0 -63
- package/src/__tests__/tool-domain-event-publisher.test.ts +0 -216
- package/src/__tests__/tool-metrics-listener.test.ts +0 -194
- package/src/__tests__/tool-profiling-listener.test.ts +0 -219
- package/src/cli/commands/credential-execution.ts +0 -362
- package/src/config/__tests__/bundled-tool-registry-guard.test.ts +0 -120
- package/src/config/bundled-tool-registry.ts +0 -281
- package/src/config/schemas/analysis.ts +0 -32
- package/src/credential-execution/approval-bridge.ts +0 -320
- package/src/credential-execution/feature-gates.ts +0 -61
- package/src/daemon/__tests__/conversation-lifecycle-auto-analyze.test.ts +0 -449
- package/src/events/bus.ts +0 -177
- package/src/events/domain-events.ts +0 -68
- package/src/events/tool-audit-listener.ts +0 -184
- package/src/events/tool-domain-event-publisher.ts +0 -90
- package/src/events/tool-metrics-listener.ts +0 -134
- package/src/events/tool-permission-telemetry-listener.ts +0 -44
- package/src/instrument.ts +0 -213
- package/src/ipc/routes/db-proxy-transaction.ts +0 -151
- package/src/plugins/defaults/memory/__tests__/find-analysis-conversation.test.ts +0 -197
- package/src/runtime/routes/conversation-analysis-routes.ts +0 -75
- package/src/runtime/routes/work-items-routes.test.ts +0 -74
- package/src/runtime/routes/work-items-routes.ts +0 -881
- package/src/runtime/services/__tests__/analyze-conversation.test.ts +0 -477
- package/src/runtime/services/__tests__/auto-analysis-enqueue.test.ts +0 -386
- package/src/runtime/services/__tests__/auto-analysis-prompt.test.ts +0 -53
- package/src/runtime/services/__tests__/conversation-analyze-job.test.ts +0 -213
- package/src/runtime/services/__tests__/manual-analysis-prompt.test.ts +0 -41
- package/src/runtime/services/analyze-conversation.ts +0 -332
- package/src/runtime/services/auto-analysis-enqueue.ts +0 -130
- package/src/runtime/services/auto-analysis-prompt.ts +0 -55
- package/src/runtime/services/conversation-analyze-job.ts +0 -53
- package/src/skills/skill-memory.ts +0 -44
- package/src/tools/credential-execution/make-authenticated-request.ts +0 -198
- package/src/tools/credential-execution/manage-secure-command-tool.ts +0 -371
- package/src/tools/credential-execution/run-authenticated-command.ts +0 -261
- package/src/tools/flag-gated-tools.test.ts +0 -76
- package/src/util/sentry-log-stream.ts +0 -51
|
@@ -10,20 +10,27 @@ import type {
|
|
|
10
10
|
VoiceTurnHandle,
|
|
11
11
|
VoiceTurnOptions,
|
|
12
12
|
} from "../calls/voice-session-bridge.js";
|
|
13
|
+
import { getConfig } from "../config/loader.js";
|
|
14
|
+
import { ensureConversationExists } from "../persistence/conversation-crud.js";
|
|
13
15
|
import {
|
|
14
16
|
listProviderIds,
|
|
15
17
|
supportsBoundary,
|
|
16
18
|
} from "../providers/speech-to-text/provider-catalog.js";
|
|
17
19
|
import type { ResolveStreamingTranscriberOptions } from "../providers/speech-to-text/resolve.js";
|
|
20
|
+
import { publishConversationListAndMetadataChanged } from "../runtime/sync/resource-sync-events.js";
|
|
18
21
|
import { detectPcm16SpeechActivity } from "../stt/speech-energy.js";
|
|
19
22
|
import type {
|
|
20
23
|
StreamingTranscriber,
|
|
24
|
+
SttStreamServerErrorEvent,
|
|
21
25
|
SttStreamServerEvent,
|
|
22
26
|
} from "../stt/types.js";
|
|
27
|
+
import { extractSpeakableSegments } from "../tts/speakable-segments.js";
|
|
28
|
+
import { getLogger } from "../util/logger.js";
|
|
23
29
|
import type {
|
|
24
30
|
LiveVoiceAudioArchiveResult,
|
|
25
31
|
LiveVoiceAudioArchiveRole,
|
|
26
32
|
} from "./live-voice-archive.js";
|
|
33
|
+
import type { LiveVoiceCredentialReadiness } from "./live-voice-credential-preflight.js";
|
|
27
34
|
import {
|
|
28
35
|
getLiveVoiceMetricsAggregateFields,
|
|
29
36
|
type LiveVoiceMetricsClock,
|
|
@@ -38,6 +45,7 @@ import {
|
|
|
38
45
|
LiveVoiceSessionStartupError,
|
|
39
46
|
} from "./live-voice-session-manager.js";
|
|
40
47
|
import type {
|
|
48
|
+
LiveVoiceTtsAudioChunk,
|
|
41
49
|
LiveVoiceTtsOptions,
|
|
42
50
|
LiveVoiceTtsResult,
|
|
43
51
|
} from "./live-voice-tts.js";
|
|
@@ -47,6 +55,8 @@ import {
|
|
|
47
55
|
type LiveVoiceServerFramePayload,
|
|
48
56
|
} from "./protocol.js";
|
|
49
57
|
|
|
58
|
+
const log = getLogger("live-voice-session");
|
|
59
|
+
|
|
50
60
|
type LiveVoiceSessionState =
|
|
51
61
|
| "initializing"
|
|
52
62
|
| "active"
|
|
@@ -54,9 +64,6 @@ type LiveVoiceSessionState =
|
|
|
54
64
|
| "failed"
|
|
55
65
|
| "closed";
|
|
56
66
|
|
|
57
|
-
const LIVE_VOICE_TTS_SEGMENT_CHAR_THRESHOLD = 180;
|
|
58
|
-
const SENTENCE_ENDING_PUNCTUATION = new Set([".", "!", "?"]);
|
|
59
|
-
const TRAILING_SENTENCE_PUNCTUATION = new Set(['"', "'", ")", "]"]);
|
|
60
67
|
// Cap on audio buffered while a server-VAD utterance waits for its
|
|
61
68
|
// transcriber (PCM16 mono seconds; oldest chunks are dropped past the cap).
|
|
62
69
|
const SERVER_VAD_PENDING_AUDIO_MAX_SECONDS = 10;
|
|
@@ -64,11 +71,30 @@ const SERVER_VAD_PENDING_AUDIO_MAX_SECONDS = 10;
|
|
|
64
71
|
// onset so the transcriber gets leading context without streaming an open
|
|
65
72
|
// quiet mic.
|
|
66
73
|
const SERVER_VAD_PRE_ROLL_MAX_CHUNKS = 25;
|
|
74
|
+
// Bounded wait for the shared transcriber's finalize flush; on expiry the
|
|
75
|
+
// assistant turn proceeds with the transcript collected so far. This is the
|
|
76
|
+
// strict upper bound on the release→turn-start tail in persistent mode (the
|
|
77
|
+
// provider keeps its own, longer, finalize fallback).
|
|
78
|
+
const FINALIZE_GRACE_MS = 1_000;
|
|
79
|
+
// Consecutive speech (ms) required before speech during assistant playback
|
|
80
|
+
// flushes it (speech_started) and cancels the turn, so a cough or noise blip
|
|
81
|
+
// cannot kill a reply mid-sentence. Mirrors the liveVoice.vad.bargeInMinSpeechMs
|
|
82
|
+
// schema default; 0 disables the guard for instant barge-in.
|
|
83
|
+
const DEFAULT_BARGE_IN_MIN_SPEECH_MS = 60;
|
|
84
|
+
// At most this many TTS segment jobs are open (provider stream started,
|
|
85
|
+
// frames not yet fully emitted) per turn: the emitting job plus one
|
|
86
|
+
// prefetching job. The prefetch buffers its chunks in memory until promoted;
|
|
87
|
+
// a segment is at most ~180 chars of speech (~10 s of 24 kHz mono PCM
|
|
88
|
+
// ≈ 480 KB), so one buffered segment is an acceptable bound.
|
|
89
|
+
const TTS_MAX_OPEN_SYNTHESIS_JOBS = 2;
|
|
67
90
|
|
|
68
91
|
export type LiveVoiceStreamingTranscriberResolver = (
|
|
69
92
|
options: ResolveStreamingTranscriberOptions,
|
|
70
93
|
) => Promise<StreamingTranscriber | null>;
|
|
71
94
|
|
|
95
|
+
export type LiveVoiceCredentialReadinessResolver =
|
|
96
|
+
() => Promise<LiveVoiceCredentialReadiness>;
|
|
97
|
+
|
|
72
98
|
export type LiveVoiceTurnStarter = (
|
|
73
99
|
options: VoiceTurnOptions,
|
|
74
100
|
) => Promise<VoiceTurnHandle>;
|
|
@@ -97,25 +123,58 @@ export type LiveVoiceSessionAudioArchiver = (
|
|
|
97
123
|
|
|
98
124
|
export interface LiveVoiceSessionOptions {
|
|
99
125
|
resolveTranscriber?: LiveVoiceStreamingTranscriberResolver;
|
|
126
|
+
/**
|
|
127
|
+
* STT/TTS credential preflight run before any session wiring; a
|
|
128
|
+
* `not-ready` verdict rejects the start frame with its `userMessage`.
|
|
129
|
+
* `null` skips the preflight.
|
|
130
|
+
*/
|
|
131
|
+
resolveCredentialReadiness?: LiveVoiceCredentialReadinessResolver | null;
|
|
100
132
|
startVoiceTurn?: LiveVoiceTurnStarter;
|
|
101
133
|
streamTtsAudio?: LiveVoiceTtsStreamer | null;
|
|
102
134
|
archiveAudio?: LiveVoiceSessionAudioArchiver | null;
|
|
103
135
|
emitMetrics?: boolean;
|
|
104
136
|
metricsClock?: LiveVoiceMetricsClock;
|
|
105
137
|
createTurnId?: () => string;
|
|
106
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* Overrides the server-VAD turn detector thresholds. The production
|
|
140
|
+
* factory seeds these from `liveVoice.vad` config when unset.
|
|
141
|
+
*/
|
|
107
142
|
turnDetectorConfig?: TurnDetectorConfig;
|
|
143
|
+
/**
|
|
144
|
+
* Overrides the mean-amplitude energy gate that classifies a server-VAD
|
|
145
|
+
* audio chunk as speech. The production factory seeds this from
|
|
146
|
+
* `liveVoice.vad.speechEnergyThreshold` config when unset; defaults to
|
|
147
|
+
* `DEFAULT_SPEECH_ENERGY_THRESHOLD`.
|
|
148
|
+
*/
|
|
149
|
+
speechEnergyThreshold?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Sustained speech (ms) required before speech during assistant playback
|
|
152
|
+
* interrupts it (barge-in); 0 disables the guard. The production factory
|
|
153
|
+
* seeds this from `liveVoice.vad.bargeInMinSpeechMs` config when unset;
|
|
154
|
+
* defaults to `DEFAULT_BARGE_IN_MIN_SPEECH_MS`.
|
|
155
|
+
*/
|
|
156
|
+
bargeInMinSpeechMs?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Overrides the bounded wait for the shared transcriber's finalize
|
|
159
|
+
* flush in persistent mode (test hook). Defaults to `FINALIZE_GRACE_MS`.
|
|
160
|
+
*/
|
|
161
|
+
finalizeGraceMs?: number;
|
|
108
162
|
}
|
|
109
163
|
|
|
110
164
|
type LiveVoiceUtterancePhase =
|
|
111
165
|
| "pending"
|
|
112
166
|
| "streaming"
|
|
113
167
|
| "released"
|
|
168
|
+
// The cycle's transcript is complete and the assistant turn may start.
|
|
169
|
+
// In per-cycle mode the transcriber socket has closed; in persistent
|
|
170
|
+
// (shared-transcriber) mode the stream stays open — the finalize flush
|
|
171
|
+
// (or its grace timeout) completed instead.
|
|
114
172
|
| "transcriber_closed";
|
|
115
173
|
|
|
116
174
|
// One capture→transcribe→turn cycle. A session runs many of these back to
|
|
117
|
-
// back: each cycle owns its
|
|
118
|
-
//
|
|
175
|
+
// back: each cycle owns its transcript, audio buffers, and metrics-turn
|
|
176
|
+
// flags so consecutive turns stay isolated. The transcriber is per-cycle in
|
|
177
|
+
// manual mode and a session-shared instance in persistent server-VAD mode.
|
|
119
178
|
interface UtteranceCycle {
|
|
120
179
|
phase: LiveVoiceUtterancePhase;
|
|
121
180
|
released: boolean;
|
|
@@ -123,6 +182,10 @@ interface UtteranceCycle {
|
|
|
123
182
|
// The whole cycle (turn included) finalized; the record can no longer
|
|
124
183
|
// accept audio and the session may re-arm over it.
|
|
125
184
|
completed: boolean;
|
|
185
|
+
// A `Finalize` request for this cycle went out on the shared stream, so
|
|
186
|
+
// one `finalized` signal is owed to it. At most one queued cycle has
|
|
187
|
+
// this set at a time — see pumpFinalizeQueue.
|
|
188
|
+
finalizeRequested: boolean;
|
|
126
189
|
transcriber: StreamingTranscriber | null;
|
|
127
190
|
pendingAudioChunks: Buffer[];
|
|
128
191
|
pendingAudioBytes: number;
|
|
@@ -152,6 +215,27 @@ type UtteranceStartResult =
|
|
|
152
215
|
| { status: "unavailable"; message: string }
|
|
153
216
|
| { status: "error"; message: string };
|
|
154
217
|
|
|
218
|
+
// One TTS segment flowing through the turn's synthesis pipeline. Synthesis
|
|
219
|
+
// may run ahead of the emission slot (prefetch), but frames only reach the
|
|
220
|
+
// client in job-list order.
|
|
221
|
+
interface TtsSegmentJob {
|
|
222
|
+
readonly text: string;
|
|
223
|
+
// The provider stream was started (the job holds an open-job slot).
|
|
224
|
+
started: boolean;
|
|
225
|
+
// Emission finished; the slot is free for the next queued segment.
|
|
226
|
+
settled: boolean;
|
|
227
|
+
// The job owns the emission slot: provider chunks forward to the client
|
|
228
|
+
// live instead of buffering.
|
|
229
|
+
emitting: boolean;
|
|
230
|
+
// Chunks received while prefetching, flushed in order on promotion.
|
|
231
|
+
// Dropped with the turn on cancellation.
|
|
232
|
+
bufferedChunks: LiveVoiceTtsAudioChunk[];
|
|
233
|
+
// Settles when the provider stream ends; rejects on synthesis failure.
|
|
234
|
+
synthesis: Promise<void> | null;
|
|
235
|
+
// Ordered tts_audio frame writes for this job.
|
|
236
|
+
frames: Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
|
|
155
239
|
interface ActiveAssistantTurn {
|
|
156
240
|
token: symbol;
|
|
157
241
|
turnId: string;
|
|
@@ -165,6 +249,14 @@ interface ActiveAssistantTurn {
|
|
|
165
249
|
ttsAudioStarted: boolean;
|
|
166
250
|
finalized: boolean;
|
|
167
251
|
ttsBuffer: string;
|
|
252
|
+
// A non-empty speakable segment reached the TTS queue — gates the eager
|
|
253
|
+
// first-segment flush that trades clause quality for speech onset.
|
|
254
|
+
ttsSegmentEnqueued: boolean;
|
|
255
|
+
// Ordered TTS segment jobs for the turn; synthesis runs ahead of emission
|
|
256
|
+
// by at most one job (TTS_MAX_OPEN_SYNTHESIS_JOBS).
|
|
257
|
+
ttsJobs: TtsSegmentJob[];
|
|
258
|
+
// Serial emission chain: one job's frames fully precede the next's, and
|
|
259
|
+
// the tts_done finale runs only after every job has drained.
|
|
168
260
|
ttsQueue: Promise<void>;
|
|
169
261
|
assistantMessageId: string | null;
|
|
170
262
|
assistantAudioChunks: Buffer[];
|
|
@@ -175,6 +267,7 @@ interface ActiveAssistantTurn {
|
|
|
175
267
|
export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
176
268
|
private readonly context: LiveVoiceSessionFactoryContext;
|
|
177
269
|
private readonly resolveTranscriber: LiveVoiceStreamingTranscriberResolver;
|
|
270
|
+
private readonly resolveCredentialReadiness: LiveVoiceCredentialReadinessResolver | null;
|
|
178
271
|
private readonly startVoiceTurn: LiveVoiceTurnStarter | null;
|
|
179
272
|
private readonly streamTtsAudio: LiveVoiceTtsStreamer | null;
|
|
180
273
|
private readonly archiveAudio: LiveVoiceSessionAudioArchiver | null;
|
|
@@ -189,6 +282,29 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
189
282
|
private sessionEndMetricsEmitted = false;
|
|
190
283
|
// Non-null iff the start frame requested turnDetection "server_vad".
|
|
191
284
|
private readonly turnDetector: MediaTurnDetector | null;
|
|
285
|
+
// Energy gate for server-VAD speech classification; undefined defers to
|
|
286
|
+
// DEFAULT_SPEECH_ENERGY_THRESHOLD.
|
|
287
|
+
private readonly speechEnergyThreshold: number | undefined;
|
|
288
|
+
private readonly bargeInMinSpeechMs: number;
|
|
289
|
+
// Sustained-speech barge-in guard, armed at speech onset while the
|
|
290
|
+
// assistant turn is audibly speaking: consecutive speech-chunk duration
|
|
291
|
+
// accumulates until it reaches bargeInMinSpeechMs, then the deferred
|
|
292
|
+
// speech_started + barge-in fire (at most once per onset). A non-speech
|
|
293
|
+
// chunk zeroes the run; the detector's utterance end discards the guard.
|
|
294
|
+
private pendingBargeIn: {
|
|
295
|
+
// Null when guarding only the post-tts_done drain window (the turn is
|
|
296
|
+
// already finalized but the client is still playing its tail).
|
|
297
|
+
turn: ActiveAssistantTurn | null;
|
|
298
|
+
speechMs: number;
|
|
299
|
+
} | null = null;
|
|
300
|
+
// Estimated wall-clock ms until the client finishes draining the
|
|
301
|
+
// assistant audio sent so far. The server clears the turn right after
|
|
302
|
+
// tts_done while the client keeps playing the buffered tail — the
|
|
303
|
+
// sustained-speech guard must also cover that window or a noise blip
|
|
304
|
+
// clips the reply's last words. Advanced per sent tts_audio frame from
|
|
305
|
+
// the chunk's PCM duration; zeroed whenever the client flushes playback
|
|
306
|
+
// (speech_started, turn_cancelled, interrupt, close).
|
|
307
|
+
private assistantPlaybackTailUntilMs = 0;
|
|
192
308
|
private readonly maxPendingAudioBytes: number;
|
|
193
309
|
// Set on VAD speech onset; consumed when the first speech chunk is routed
|
|
194
310
|
// to an utterance so the metric lands on the right turn.
|
|
@@ -203,6 +319,28 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
203
319
|
// replayed once the parked speech flushes into the next armed utterance.
|
|
204
320
|
private vadPendingTurnEnd: "silence" | "max-duration" | null = null;
|
|
205
321
|
private readonly metricsClock: LiveVoiceMetricsClock;
|
|
322
|
+
// Persistent mode: server-VAD sessions with a finalize-capable provider
|
|
323
|
+
// keep one streaming transcriber for the whole session. Utterance release
|
|
324
|
+
// flushes via finalizeUtterance() instead of tearing the stream down, and
|
|
325
|
+
// re-arm reuses this instance synchronously. Null in manual mode, for
|
|
326
|
+
// providers without finalizeUtterance, and after an unexpected stream
|
|
327
|
+
// close (the next arm resolves a fresh transcriber).
|
|
328
|
+
private sharedTranscriber: StreamingTranscriber | null = null;
|
|
329
|
+
/**
|
|
330
|
+
* FIFO of released cycles awaiting finalize settlement on the shared
|
|
331
|
+
* stream, oldest first. Flush finals and `finalized` signals carry no
|
|
332
|
+
* request identity, so at most one `Finalize` request is in flight at a
|
|
333
|
+
* time (the head's, marked `finalizeRequested` — see pumpFinalizeQueue):
|
|
334
|
+
* the head owns the next flush/`finalized`. The transcriber drops a
|
|
335
|
+
* fallback-settled request's stale flush until the next `Finalize` goes
|
|
336
|
+
* out; one landing after that surfaces as the new head's flush, bounded
|
|
337
|
+
* by the dispatched-turn drop-guard in the `final` handler.
|
|
338
|
+
*/
|
|
339
|
+
private finalizeQueue: UtteranceCycle[] = [];
|
|
340
|
+
private finalizeGraceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
341
|
+
/** The cycle whose grace timer is armed (only the newest release has one). */
|
|
342
|
+
private finalizeGraceCycle: UtteranceCycle | null = null;
|
|
343
|
+
private readonly finalizeGraceMs: number;
|
|
206
344
|
|
|
207
345
|
constructor(
|
|
208
346
|
context: LiveVoiceSessionFactoryContext,
|
|
@@ -211,6 +349,8 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
211
349
|
this.context = context;
|
|
212
350
|
this.resolveTranscriber =
|
|
213
351
|
options.resolveTranscriber ?? defaultResolveStreamingTranscriber;
|
|
352
|
+
this.resolveCredentialReadiness =
|
|
353
|
+
options.resolveCredentialReadiness ?? null;
|
|
214
354
|
this.startVoiceTurn = options.startVoiceTurn ?? null;
|
|
215
355
|
this.streamTtsAudio = options.streamTtsAudio ?? null;
|
|
216
356
|
this.archiveAudio = options.archiveAudio ?? null;
|
|
@@ -224,6 +364,10 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
224
364
|
conversationId: this.conversationId,
|
|
225
365
|
...(options.metricsClock ? { clock: options.metricsClock } : {}),
|
|
226
366
|
});
|
|
367
|
+
this.speechEnergyThreshold = options.speechEnergyThreshold;
|
|
368
|
+
this.bargeInMinSpeechMs =
|
|
369
|
+
options.bargeInMinSpeechMs ?? DEFAULT_BARGE_IN_MIN_SPEECH_MS;
|
|
370
|
+
this.finalizeGraceMs = options.finalizeGraceMs ?? FINALIZE_GRACE_MS;
|
|
227
371
|
this.turnDetector =
|
|
228
372
|
context.startFrame.turnDetection === "server_vad"
|
|
229
373
|
? new MediaTurnDetector(options.turnDetectorConfig ?? {}, {
|
|
@@ -242,28 +386,45 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
242
386
|
}
|
|
243
387
|
|
|
244
388
|
async start(): Promise<void> {
|
|
245
|
-
if (this.state !== "initializing")
|
|
389
|
+
if (this.state !== "initializing") {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
246
392
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
this.metrics.markReady();
|
|
256
|
-
await this.sendFrame({
|
|
257
|
-
type: "ready",
|
|
258
|
-
sessionId: this.context.sessionId,
|
|
259
|
-
conversationId: this.conversationId,
|
|
260
|
-
turnDetection: this.turnDetector ? "server_vad" : "manual",
|
|
261
|
-
});
|
|
393
|
+
if (this.resolveCredentialReadiness) {
|
|
394
|
+
const readiness = await this.resolveCredentialReadiness();
|
|
395
|
+
if (readiness.status === "not-ready") {
|
|
396
|
+
return await this.failStartup(
|
|
397
|
+
readiness.userMessage,
|
|
398
|
+
LiveVoiceProtocolErrorCode.CredentialsUnavailable,
|
|
399
|
+
);
|
|
400
|
+
}
|
|
262
401
|
}
|
|
402
|
+
|
|
403
|
+
// The session may have been closed while the preflight was awaited.
|
|
404
|
+
if (this.isClosed) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Ready goes out as soon as the preflight passes so the client's mic
|
|
409
|
+
// acquisition overlaps the STT provider handshake. The session is active
|
|
410
|
+
// immediately: audio arriving before the first utterance arms buffers
|
|
411
|
+
// through the pending/pre-roll paths and flushes on arm. An arm failure
|
|
412
|
+
// surfaces as a non-recoverable error frame instead of a start rejection.
|
|
413
|
+
this.state = "active";
|
|
414
|
+
void this.armUtterance().catch(() => {});
|
|
415
|
+
this.metrics.markReady();
|
|
416
|
+
await this.sendFrame({
|
|
417
|
+
type: "ready",
|
|
418
|
+
sessionId: this.context.sessionId,
|
|
419
|
+
conversationId: this.conversationId,
|
|
420
|
+
turnDetection: this.turnDetector ? "server_vad" : "manual",
|
|
421
|
+
});
|
|
263
422
|
}
|
|
264
423
|
|
|
265
424
|
async handleClientFrame(frame: LiveVoiceClientFrame): Promise<void> {
|
|
266
|
-
if (this.state === "closed" || this.state === "failed")
|
|
425
|
+
if (this.state === "closed" || this.state === "failed") {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
267
428
|
|
|
268
429
|
switch (frame.type) {
|
|
269
430
|
case "audio":
|
|
@@ -287,16 +448,14 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
287
448
|
}
|
|
288
449
|
|
|
289
450
|
async close(_reason: LiveVoiceSessionCloseReason): Promise<void> {
|
|
290
|
-
if (this.isClosed)
|
|
451
|
+
if (this.isClosed) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
291
454
|
|
|
292
455
|
const shouldEmitSessionEndMetrics = this.state !== "failed";
|
|
293
456
|
this.state = "closed";
|
|
294
457
|
this.turnDetector?.dispose();
|
|
295
|
-
|
|
296
|
-
if (utterance) {
|
|
297
|
-
stopTranscriberBestEffort(utterance.transcriber);
|
|
298
|
-
utterance.transcriber = null;
|
|
299
|
-
}
|
|
458
|
+
this.stopSessionTranscriber();
|
|
300
459
|
await this.cancelAssistantTurn("session_closed");
|
|
301
460
|
if (shouldEmitSessionEndMetrics) {
|
|
302
461
|
await this.emitSessionEndMetrics();
|
|
@@ -304,15 +463,19 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
304
463
|
await this.drainOutboundFrames();
|
|
305
464
|
}
|
|
306
465
|
|
|
307
|
-
// Creates the next utterance record and arms a
|
|
308
|
-
//
|
|
309
|
-
//
|
|
466
|
+
// Creates the next utterance record and arms a streaming transcriber for
|
|
467
|
+
// it: the session-shared instance when persistent mode is active (a
|
|
468
|
+
// synchronous re-arm), otherwise a freshly resolved one. Called once at
|
|
469
|
+
// session start (without blocking the ready frame) and, in server_vad
|
|
470
|
+
// mode, again after every finalized turn (per-utterance phase tracks the
|
|
471
|
+
// cycle).
|
|
310
472
|
private async beginUtterance(): Promise<UtteranceStartResult> {
|
|
311
473
|
const utterance: UtteranceCycle = {
|
|
312
474
|
phase: "pending",
|
|
313
475
|
released: false,
|
|
314
476
|
assistantTurnStarted: false,
|
|
315
477
|
completed: false,
|
|
478
|
+
finalizeRequested: false,
|
|
316
479
|
transcriber: null,
|
|
317
480
|
pendingAudioChunks: [],
|
|
318
481
|
pendingAudioBytes: 0,
|
|
@@ -338,6 +501,14 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
338
501
|
const replayTurnEnd = this.vadPendingTurnEnd;
|
|
339
502
|
this.vadPendingTurnEnd = null;
|
|
340
503
|
|
|
504
|
+
const shared = this.sharedTranscriber;
|
|
505
|
+
if (shared) {
|
|
506
|
+
// Persistent re-arm: the shared stream is already open, so the cycle
|
|
507
|
+
// goes straight to streaming with no resolve/start round-trip.
|
|
508
|
+
utterance.transcriber = shared;
|
|
509
|
+
return await this.activateUtterance(utterance, replayTurnEnd);
|
|
510
|
+
}
|
|
511
|
+
|
|
341
512
|
try {
|
|
342
513
|
const transcriber = await this.resolveTranscriber({
|
|
343
514
|
sampleRate: this.context.startFrame.audio.sampleRate,
|
|
@@ -356,29 +527,33 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
356
527
|
}
|
|
357
528
|
|
|
358
529
|
utterance.transcriber = transcriber;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
530
|
+
if (
|
|
531
|
+
this.turnDetector &&
|
|
532
|
+
typeof transcriber.finalizeUtterance === "function"
|
|
533
|
+
) {
|
|
534
|
+
// Adopt persistent mode: this stream serves the whole session, so
|
|
535
|
+
// its events route by cycle ownership instead of binding to this
|
|
536
|
+
// one cycle.
|
|
537
|
+
this.sharedTranscriber = transcriber;
|
|
538
|
+
await transcriber.start((event) => {
|
|
539
|
+
void this.handleSharedTranscriberEvent(transcriber, event);
|
|
540
|
+
});
|
|
541
|
+
} else {
|
|
542
|
+
await transcriber.start((event) => {
|
|
543
|
+
void this.handleTranscriberEvent(utterance, event);
|
|
544
|
+
});
|
|
545
|
+
}
|
|
362
546
|
|
|
363
547
|
if (this.isUtteranceStale(utterance)) {
|
|
548
|
+
this.releaseSharedTranscriber(transcriber);
|
|
364
549
|
stopTranscriberBestEffort(transcriber);
|
|
365
550
|
utterance.transcriber = null;
|
|
366
551
|
return { status: "stale" };
|
|
367
552
|
}
|
|
368
553
|
|
|
369
|
-
utterance
|
|
370
|
-
this.state = "active";
|
|
371
|
-
await this.flushPendingUtteranceAudio(utterance);
|
|
372
|
-
if (utterance.released) {
|
|
373
|
-
await this.stopUtteranceForRelease(utterance);
|
|
374
|
-
} else if (replayTurnEnd) {
|
|
375
|
-
// The parked utterance completed during the window (detector already
|
|
376
|
-
// idle): replay its boundary so it turns without more speech.
|
|
377
|
-
await this.sendFrame({ type: "utterance_end", reason: replayTurnEnd });
|
|
378
|
-
await this.releaseUtterance();
|
|
379
|
-
}
|
|
380
|
-
return { status: "started" };
|
|
554
|
+
return await this.activateUtterance(utterance, replayTurnEnd);
|
|
381
555
|
} catch (err) {
|
|
556
|
+
this.releaseSharedTranscriber(utterance.transcriber);
|
|
382
557
|
stopTranscriberBestEffort(utterance.transcriber);
|
|
383
558
|
utterance.transcriber = null;
|
|
384
559
|
if (this.isUtteranceStale(utterance)) {
|
|
@@ -393,6 +568,35 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
393
568
|
}
|
|
394
569
|
}
|
|
395
570
|
|
|
571
|
+
// Transitions an armed cycle to streaming: flush buffered audio, complete
|
|
572
|
+
// a release that landed while the cycle was pending, and replay a parked
|
|
573
|
+
// detector boundary.
|
|
574
|
+
private async activateUtterance(
|
|
575
|
+
utterance: UtteranceCycle,
|
|
576
|
+
replayTurnEnd: "silence" | "max-duration" | null,
|
|
577
|
+
): Promise<UtteranceStartResult> {
|
|
578
|
+
utterance.phase = "streaming";
|
|
579
|
+
this.state = "active";
|
|
580
|
+
await this.flushPendingUtteranceAudio(utterance);
|
|
581
|
+
if (utterance.released) {
|
|
582
|
+
await this.stopUtteranceForRelease(utterance);
|
|
583
|
+
} else if (replayTurnEnd) {
|
|
584
|
+
// The parked utterance completed during the window (detector already
|
|
585
|
+
// idle): replay its boundary so it turns without more speech.
|
|
586
|
+
await this.sendFrame({ type: "utterance_end", reason: replayTurnEnd });
|
|
587
|
+
await this.releaseUtterance();
|
|
588
|
+
}
|
|
589
|
+
return { status: "started" };
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private releaseSharedTranscriber(
|
|
593
|
+
transcriber: StreamingTranscriber | null,
|
|
594
|
+
): void {
|
|
595
|
+
if (transcriber && this.sharedTranscriber === transcriber) {
|
|
596
|
+
this.sharedTranscriber = null;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
396
600
|
private isUtteranceStale(utterance: UtteranceCycle): boolean {
|
|
397
601
|
return (
|
|
398
602
|
this.isClosed ||
|
|
@@ -407,12 +611,16 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
407
611
|
// server_vad capability; manual sessions keep single-utterance semantics
|
|
408
612
|
// (no speculative post-turn transcriber).
|
|
409
613
|
private scheduleRearmAfterTurn(): void {
|
|
410
|
-
if (!this.turnDetector)
|
|
614
|
+
if (!this.turnDetector) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
411
617
|
void this.rearmAfterTurn().catch(() => {});
|
|
412
618
|
}
|
|
413
619
|
|
|
414
620
|
private async rearmAfterTurn(): Promise<void> {
|
|
415
|
-
if (this.isClosed || this.state === "failed")
|
|
621
|
+
if (this.isClosed || this.state === "failed") {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
416
624
|
|
|
417
625
|
const current = this.currentUtterance;
|
|
418
626
|
if (current && !current.completed) {
|
|
@@ -426,14 +634,24 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
426
634
|
|
|
427
635
|
private async armUtterance(): Promise<void> {
|
|
428
636
|
const result = await this.beginUtterance();
|
|
429
|
-
if (result.status === "started" || result.status === "stale")
|
|
637
|
+
if (result.status === "started" || result.status === "stale") {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
430
640
|
|
|
431
641
|
this.state = "failed";
|
|
432
642
|
await this.sendFrame({
|
|
433
643
|
type: "error",
|
|
434
|
-
code:
|
|
644
|
+
code:
|
|
645
|
+
result.status === "unavailable"
|
|
646
|
+
? LiveVoiceProtocolErrorCode.CredentialsUnavailable
|
|
647
|
+
: LiveVoiceProtocolErrorCode.InvalidField,
|
|
435
648
|
message: result.message,
|
|
436
649
|
});
|
|
650
|
+
// The manager only observes failures thrown from start(); an arm that
|
|
651
|
+
// fails after the early `ready` must release the session slot itself,
|
|
652
|
+
// or the next start frame on this (or a reconnecting) socket gets
|
|
653
|
+
// `busy` until the client tears the WebSocket down.
|
|
654
|
+
await this.context.releaseAfterFailure?.();
|
|
437
655
|
}
|
|
438
656
|
|
|
439
657
|
private async handleAudio(chunk: Buffer): Promise<void> {
|
|
@@ -443,18 +661,20 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
443
661
|
}
|
|
444
662
|
|
|
445
663
|
const utterance = this.currentUtterance;
|
|
446
|
-
if (!utterance || this.isClosed || this.state === "failed")
|
|
664
|
+
if (!utterance || this.isClosed || this.state === "failed") {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
447
667
|
|
|
448
668
|
if (utterance.released || utterance.phase === "transcriber_closed") {
|
|
449
669
|
await this.sendAudioAfterReleaseError();
|
|
450
670
|
return;
|
|
451
671
|
}
|
|
452
672
|
|
|
453
|
-
if (this.state === "initializing") return;
|
|
454
|
-
|
|
455
673
|
this.collectUserAudio(utterance, chunk);
|
|
456
674
|
if (utterance.phase === "pending") {
|
|
457
|
-
|
|
675
|
+
// The transcriber is still arming (session start overlaps the STT
|
|
676
|
+
// handshake with client mic startup); buffer until it flushes on arm.
|
|
677
|
+
this.bufferPendingUtteranceAudio(utterance, chunk);
|
|
458
678
|
return;
|
|
459
679
|
}
|
|
460
680
|
await this.forwardAudioToTranscriber(utterance, chunk);
|
|
@@ -476,8 +696,12 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
476
696
|
return;
|
|
477
697
|
}
|
|
478
698
|
|
|
479
|
-
const hasSpeech = detectPcm16SpeechActivity(
|
|
699
|
+
const hasSpeech = detectPcm16SpeechActivity(
|
|
700
|
+
chunk,
|
|
701
|
+
this.speechEnergyThreshold,
|
|
702
|
+
);
|
|
480
703
|
detector.onMediaChunk(hasSpeech);
|
|
704
|
+
this.trackBargeInGuard(hasSpeech, chunk);
|
|
481
705
|
|
|
482
706
|
// Idle mic: hold silent chunks in the bounded pre-roll instead of
|
|
483
707
|
// collecting or streaming them; flushed on speech onset so the
|
|
@@ -488,11 +712,15 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
488
712
|
}
|
|
489
713
|
|
|
490
714
|
let utterance = this.currentUtterance;
|
|
491
|
-
if (!utterance)
|
|
715
|
+
if (!utterance) {
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
492
718
|
if (utterance.released || utterance.completed) {
|
|
493
719
|
// Parked speech makes silent chunks arm-worthy too: the parked
|
|
494
720
|
// utterance must flush without requiring more speech.
|
|
495
|
-
if (!hasSpeech && !this.vadPreRollHasSpeech)
|
|
721
|
+
if (!hasSpeech && !this.vadPreRollHasSpeech) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
496
724
|
if (!this.canArmNextUtterance(utterance)) {
|
|
497
725
|
// Speech in the release→turn-start window: hold it in the pre-roll
|
|
498
726
|
// ring so it flushes into the next utterance once it arms.
|
|
@@ -503,7 +731,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
503
731
|
// while this chunk lands in the new utterance's pending buffer.
|
|
504
732
|
void this.armUtterance();
|
|
505
733
|
utterance = this.currentUtterance;
|
|
506
|
-
if (!utterance || utterance.released || utterance.completed)
|
|
734
|
+
if (!utterance || utterance.released || utterance.completed) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
507
737
|
}
|
|
508
738
|
|
|
509
739
|
for (const preRollChunk of this.takeVadPreRoll()) {
|
|
@@ -545,7 +775,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
545
775
|
) {
|
|
546
776
|
return;
|
|
547
777
|
}
|
|
548
|
-
if (hasSpeech)
|
|
778
|
+
if (hasSpeech) {
|
|
779
|
+
this.vadPreRollHasSpeech = true;
|
|
780
|
+
}
|
|
549
781
|
this.vadPreRollChunks.push(Buffer.from(chunk));
|
|
550
782
|
while (this.vadPreRollChunks.length > SERVER_VAD_PRE_ROLL_MAX_CHUNKS) {
|
|
551
783
|
this.vadPreRollChunks.shift();
|
|
@@ -613,18 +845,68 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
613
845
|
}
|
|
614
846
|
}
|
|
615
847
|
|
|
616
|
-
// VAD speech onset. Contract: speech_started
|
|
617
|
-
//
|
|
618
|
-
//
|
|
619
|
-
//
|
|
848
|
+
// VAD speech onset. Contract: speech_started tells the client to flush
|
|
849
|
+
// tail playback immediately; barge-in then cancels the active turn only
|
|
850
|
+
// once its first tts_audio chunk was forwarded — speech during a pre-TTS
|
|
851
|
+
// "thinking" turn never kills the unspoken reply. While a turn is audibly
|
|
852
|
+
// speaking, both are deferred behind the sustained-speech guard so a
|
|
853
|
+
// cough or noise blip cannot kill the reply; onset while listening keeps
|
|
854
|
+
// the instant speech_started (turn-taking latency is untouched).
|
|
620
855
|
private handleVadSpeechStart(): void {
|
|
621
|
-
if (this.isClosed || this.state === "failed")
|
|
856
|
+
if (this.isClosed || this.state === "failed") {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
622
859
|
|
|
623
|
-
void this.sendFrame({ type: "speech_started" });
|
|
624
860
|
this.vadSpeechStartPending = true;
|
|
625
861
|
|
|
626
862
|
const turn = this.activeAssistantTurn;
|
|
627
|
-
|
|
863
|
+
const speakingTurn =
|
|
864
|
+
turn && !turn.finalized && turn.ttsAudioStarted ? turn : null;
|
|
865
|
+
// The client can still be draining audible playback after tts_done
|
|
866
|
+
// (the turn is already cleared server-side) — that tail deserves the
|
|
867
|
+
// same guard, or a noise blip clips the reply's last words.
|
|
868
|
+
const drainingPlayback = Date.now() < this.assistantPlaybackTailUntilMs;
|
|
869
|
+
|
|
870
|
+
if ((speakingTurn || drainingPlayback) && this.bargeInMinSpeechMs > 0) {
|
|
871
|
+
// Onset audio keeps flowing into the cycle/pre-roll while the guard
|
|
872
|
+
// accumulates (trackBargeInGuard), so no speech is lost either way.
|
|
873
|
+
this.pendingBargeIn = { turn: speakingTurn, speechMs: 0 };
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
this.pendingBargeIn = null;
|
|
878
|
+
this.assistantPlaybackTailUntilMs = 0;
|
|
879
|
+
void this.sendFrame({ type: "speech_started" });
|
|
880
|
+
if (speakingTurn) {
|
|
881
|
+
this.bargeIn(speakingTurn);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// Advances the sustained-speech barge-in guard by one server-VAD chunk:
|
|
886
|
+
// consecutive speech accumulates toward bargeInMinSpeechMs (a non-speech
|
|
887
|
+
// chunk zeroes the run) and, once met, the deferred speech_started +
|
|
888
|
+
// barge-in fire.
|
|
889
|
+
private trackBargeInGuard(hasSpeech: boolean, chunk: Buffer): void {
|
|
890
|
+
const guard = this.pendingBargeIn;
|
|
891
|
+
if (!guard) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
if (!hasSpeech) {
|
|
895
|
+
guard.speechMs = 0;
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
guard.speechMs += pcm16DurationMs(
|
|
899
|
+
chunk.byteLength,
|
|
900
|
+
this.context.startFrame.audio.sampleRate,
|
|
901
|
+
);
|
|
902
|
+
if (guard.speechMs < this.bargeInMinSpeechMs) {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
this.pendingBargeIn = null;
|
|
906
|
+
this.assistantPlaybackTailUntilMs = 0;
|
|
907
|
+
void this.sendFrame({ type: "speech_started" });
|
|
908
|
+
const { turn } = guard;
|
|
909
|
+
if (turn && turn === this.activeAssistantTurn && !turn.finalized) {
|
|
628
910
|
this.bargeIn(turn);
|
|
629
911
|
}
|
|
630
912
|
}
|
|
@@ -632,7 +914,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
632
914
|
private bargeIn(turn: ActiveAssistantTurn): void {
|
|
633
915
|
// Abort synchronously so no tts_audio frame can follow turn_cancelled,
|
|
634
916
|
// and settle the cancelled turn's metrics so the next utterance's marks
|
|
635
|
-
// do not collide with it in the collector.
|
|
917
|
+
// do not collide with it in the collector. turn_cancelled flushes
|
|
918
|
+
// client playback, so the drain estimate resets with it.
|
|
919
|
+
this.assistantPlaybackTailUntilMs = 0;
|
|
636
920
|
turn.abortController.abort();
|
|
637
921
|
this.metrics.markBargeIn(turn.turnId);
|
|
638
922
|
void (async () => {
|
|
@@ -651,8 +935,13 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
651
935
|
// utterance_end, then run the standard release path.
|
|
652
936
|
private handleVadUtteranceEnd(reason: "silence" | "max-duration"): void {
|
|
653
937
|
void (async () => {
|
|
654
|
-
if (this.isClosed || this.state === "failed")
|
|
938
|
+
if (this.isClosed || this.state === "failed") {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
655
941
|
this.vadSpeechStartPending = false;
|
|
942
|
+
// The detector turn is over: an untripped guard was noise, not
|
|
943
|
+
// barge-in — leave playback untouched.
|
|
944
|
+
this.pendingBargeIn = null;
|
|
656
945
|
const utterance = this.currentUtterance;
|
|
657
946
|
if (!utterance || utterance.released || utterance.completed) {
|
|
658
947
|
// The ended turn's speech sits parked in the pre-roll ring (the
|
|
@@ -683,7 +972,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
683
972
|
|
|
684
973
|
private async releaseUtterance(): Promise<void> {
|
|
685
974
|
const utterance = this.currentUtterance;
|
|
686
|
-
if (!utterance || this.isClosed || this.state === "failed")
|
|
975
|
+
if (!utterance || this.isClosed || this.state === "failed") {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
687
978
|
|
|
688
979
|
if (utterance.phase === "transcriber_closed") {
|
|
689
980
|
utterance.released = true;
|
|
@@ -693,7 +984,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
693
984
|
return;
|
|
694
985
|
}
|
|
695
986
|
|
|
696
|
-
if (utterance.released)
|
|
987
|
+
if (utterance.released) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
697
990
|
|
|
698
991
|
utterance.released = true;
|
|
699
992
|
this.markUtteranceReleased(utterance);
|
|
@@ -709,6 +1002,12 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
709
1002
|
private async stopUtteranceForRelease(
|
|
710
1003
|
utterance: UtteranceCycle,
|
|
711
1004
|
): Promise<void> {
|
|
1005
|
+
const shared = this.sharedTranscriber;
|
|
1006
|
+
if (shared && utterance.transcriber === shared) {
|
|
1007
|
+
await this.finalizeUtteranceForRelease(utterance);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
712
1011
|
utterance.phase = "released";
|
|
713
1012
|
try {
|
|
714
1013
|
utterance.transcriber?.stop();
|
|
@@ -726,6 +1025,117 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
726
1025
|
await this.drainOutboundFrames();
|
|
727
1026
|
}
|
|
728
1027
|
|
|
1028
|
+
// Persistent-mode release: flush the shared stream's buffered audio with
|
|
1029
|
+
// finalizeUtterance() instead of tearing the stream down. The assistant
|
|
1030
|
+
// turn starts on the `finalized` event; the grace timer bounds a flush
|
|
1031
|
+
// that never arrives.
|
|
1032
|
+
private async finalizeUtteranceForRelease(
|
|
1033
|
+
utterance: UtteranceCycle,
|
|
1034
|
+
): Promise<void> {
|
|
1035
|
+
if (
|
|
1036
|
+
utterance.phase === "released" ||
|
|
1037
|
+
utterance.phase === "transcriber_closed"
|
|
1038
|
+
) {
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
utterance.phase = "released";
|
|
1042
|
+
this.finalizeQueue.push(utterance);
|
|
1043
|
+
this.armFinalizeGraceTimer(utterance);
|
|
1044
|
+
this.pumpFinalizeQueue();
|
|
1045
|
+
await this.startAssistantTurnIfReady();
|
|
1046
|
+
await this.drainOutboundFrames();
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// Sends at most one `Finalize` request at a time on the shared stream:
|
|
1050
|
+
// `finalized` carries no request identity, and a provider answering two
|
|
1051
|
+
// overlapping requests with a single flush would desync the FIFO
|
|
1052
|
+
// permanently. While a request is outstanding the queue waits; when the
|
|
1053
|
+
// head settles, cycles that dispatched (grace-sealed) before their
|
|
1054
|
+
// request was ever sent are dropped — no `finalized` will ever answer
|
|
1055
|
+
// them, and their buffered tail arrives as ordinary finals — then the
|
|
1056
|
+
// next awaiting cycle's request goes out.
|
|
1057
|
+
private pumpFinalizeQueue(): void {
|
|
1058
|
+
if (this.finalizeQueue.some((cycle) => cycle.finalizeRequested)) {
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
while (true) {
|
|
1062
|
+
const head = this.finalizeQueue[0];
|
|
1063
|
+
if (!head) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
if (head.assistantTurnStarted || head.completed) {
|
|
1067
|
+
this.dropFromFinalizeQueue(head);
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
const shared = this.sharedTranscriber;
|
|
1071
|
+
if (!shared) {
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
head.finalizeRequested = true;
|
|
1075
|
+
try {
|
|
1076
|
+
shared.finalizeUtterance?.();
|
|
1077
|
+
} catch (err) {
|
|
1078
|
+
log.warn(
|
|
1079
|
+
{ err },
|
|
1080
|
+
"Live voice utterance finalize failed; proceeding with the transcript collected so far",
|
|
1081
|
+
);
|
|
1082
|
+
this.dropFromFinalizeQueue(head);
|
|
1083
|
+
if (head.phase === "released") {
|
|
1084
|
+
head.phase = "transcriber_closed";
|
|
1085
|
+
}
|
|
1086
|
+
continue;
|
|
1087
|
+
}
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
private dropFromFinalizeQueue(utterance: UtteranceCycle): void {
|
|
1093
|
+
this.finalizeQueue = this.finalizeQueue.filter((c) => c !== utterance);
|
|
1094
|
+
if (utterance === this.finalizeGraceCycle) {
|
|
1095
|
+
this.clearFinalizeGraceTimer();
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
private armFinalizeGraceTimer(utterance: UtteranceCycle): void {
|
|
1100
|
+
this.clearFinalizeGraceTimer();
|
|
1101
|
+
this.finalizeGraceCycle = utterance;
|
|
1102
|
+
this.finalizeGraceTimer = setTimeout(() => {
|
|
1103
|
+
this.finalizeGraceTimer = null;
|
|
1104
|
+
this.finalizeGraceCycle = null;
|
|
1105
|
+
void this.handleFinalizeGraceTimeout(utterance).catch(() => {});
|
|
1106
|
+
}, this.finalizeGraceMs);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
private clearFinalizeGraceTimer(): void {
|
|
1110
|
+
if (this.finalizeGraceTimer !== null) {
|
|
1111
|
+
clearTimeout(this.finalizeGraceTimer);
|
|
1112
|
+
this.finalizeGraceTimer = null;
|
|
1113
|
+
}
|
|
1114
|
+
this.finalizeGraceCycle = null;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// The finalize flush never arrived: proceed with the segments collected
|
|
1118
|
+
// so far. The cycle stays in the finalize queue so its late flush is
|
|
1119
|
+
// still attributed to (and dropped for) it instead of polluting a newer
|
|
1120
|
+
// cycle's request.
|
|
1121
|
+
private async handleFinalizeGraceTimeout(
|
|
1122
|
+
utterance: UtteranceCycle,
|
|
1123
|
+
): Promise<void> {
|
|
1124
|
+
if (
|
|
1125
|
+
!this.finalizeQueue.includes(utterance) ||
|
|
1126
|
+
this.isClosed ||
|
|
1127
|
+
this.state === "failed" ||
|
|
1128
|
+
this.state === "interrupted"
|
|
1129
|
+
) {
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
log.warn(
|
|
1133
|
+
"Live voice finalize flush timed out; starting the turn with the transcript collected so far",
|
|
1134
|
+
);
|
|
1135
|
+
utterance.phase = "transcriber_closed";
|
|
1136
|
+
await this.startAssistantTurnIfReady();
|
|
1137
|
+
}
|
|
1138
|
+
|
|
729
1139
|
private async handleTranscriberEvent(
|
|
730
1140
|
utterance: UtteranceCycle,
|
|
731
1141
|
event: SttStreamServerEvent,
|
|
@@ -744,31 +1154,16 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
744
1154
|
this.markFirstPartial(utterance);
|
|
745
1155
|
await this.sendFrame({ type: "stt_partial", text: event.text });
|
|
746
1156
|
return;
|
|
747
|
-
case "final":
|
|
748
|
-
|
|
749
|
-
if (transcript.length > 0) {
|
|
750
|
-
utterance.finalTranscriptSegments.push(transcript);
|
|
751
|
-
}
|
|
752
|
-
this.markFinalTranscript(utterance);
|
|
753
|
-
await this.sendFrame({ type: "stt_final", text: event.text });
|
|
754
|
-
await this.startAssistantTurnIfReady();
|
|
1157
|
+
case "final":
|
|
1158
|
+
await this.recordFinalTranscript(utterance, event.text);
|
|
755
1159
|
return;
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
//
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
const recoverable =
|
|
763
|
-
event.category === "timeout" || event.category === "provider-error";
|
|
764
|
-
await this.sendFrame({
|
|
765
|
-
type: "error",
|
|
766
|
-
code: LiveVoiceProtocolErrorCode.InvalidField,
|
|
767
|
-
message: event.message,
|
|
768
|
-
...(recoverable ? { recoverable: true } : {}),
|
|
769
|
-
});
|
|
1160
|
+
case "finalized":
|
|
1161
|
+
// Per-cycle transcribers are torn down with stop(); the finalize
|
|
1162
|
+
// completion signal has no cycle to advance here.
|
|
1163
|
+
return;
|
|
1164
|
+
case "error":
|
|
1165
|
+
await this.sendTranscriberErrorFrame(event);
|
|
770
1166
|
return;
|
|
771
|
-
}
|
|
772
1167
|
case "closed":
|
|
773
1168
|
utterance.phase = "transcriber_closed";
|
|
774
1169
|
utterance.transcriber = null;
|
|
@@ -790,17 +1185,187 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
790
1185
|
}
|
|
791
1186
|
}
|
|
792
1187
|
|
|
1188
|
+
// The cycle that should receive new (non-flush) transcript events: the
|
|
1189
|
+
// oldest queued finalize request whose turn has not dispatched, falling
|
|
1190
|
+
// back to the current cycle once every queued request has dispatched.
|
|
1191
|
+
private pendingTranscriptCycle(): UtteranceCycle | null {
|
|
1192
|
+
return (
|
|
1193
|
+
this.finalizeQueue.find(
|
|
1194
|
+
(cycle) => !cycle.assistantTurnStarted && !cycle.completed,
|
|
1195
|
+
) ?? this.currentUtterance
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// Persistent-mode event routing. One shared stream serves many cycles, so
|
|
1200
|
+
// events route dynamically: the cycle awaiting its finalize flush owns
|
|
1201
|
+
// the audio being flushed; otherwise the current cycle does. Flush events
|
|
1202
|
+
// for a transcript that already dispatched its assistant turn are dropped
|
|
1203
|
+
// — a dispatched transcript is never mutated.
|
|
1204
|
+
private async handleSharedTranscriberEvent(
|
|
1205
|
+
transcriber: StreamingTranscriber,
|
|
1206
|
+
event: SttStreamServerEvent,
|
|
1207
|
+
): Promise<void> {
|
|
1208
|
+
if (
|
|
1209
|
+
this.sharedTranscriber !== transcriber ||
|
|
1210
|
+
this.isClosed ||
|
|
1211
|
+
this.state === "failed" ||
|
|
1212
|
+
this.state === "interrupted"
|
|
1213
|
+
) {
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
switch (event.type) {
|
|
1218
|
+
case "partial": {
|
|
1219
|
+
// Partials belong to the oldest cycle still awaiting its
|
|
1220
|
+
// transcript; after every queued request has dispatched, they
|
|
1221
|
+
// belong to the user's next utterance on the current cycle.
|
|
1222
|
+
const target = this.pendingTranscriptCycle();
|
|
1223
|
+
if (!target || target.assistantTurnStarted || target.completed) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
this.markFirstPartial(target);
|
|
1227
|
+
await this.sendFrame({ type: "stt_partial", text: event.text });
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
case "final": {
|
|
1231
|
+
if (event.fromFinalize) {
|
|
1232
|
+
// A finalize flush commits audio buffered before its finalize
|
|
1233
|
+
// request. The provider answers requests in order, so the flush
|
|
1234
|
+
// belongs to the OLDEST outstanding request — never to a newer
|
|
1235
|
+
// cycle's request and never to new speech. After a grace-timeout
|
|
1236
|
+
// dispatch the owning transcript is sealed, so a late flush is
|
|
1237
|
+
// dropped rather than mutating a dispatched turn or polluting a
|
|
1238
|
+
// newer cycle.
|
|
1239
|
+
const owner = this.finalizeQueue[0];
|
|
1240
|
+
if (owner && !owner.assistantTurnStarted && !owner.completed) {
|
|
1241
|
+
await this.recordFinalTranscript(owner, event.text);
|
|
1242
|
+
} else {
|
|
1243
|
+
log.warn(
|
|
1244
|
+
"Dropping a late finalize flush segment: its assistant turn already dispatched",
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
// Ordinary finals: new speech for the oldest still-pending cycle,
|
|
1250
|
+
// or the current one once every queued request has dispatched.
|
|
1251
|
+
const target = this.pendingTranscriptCycle();
|
|
1252
|
+
if (!target || target.assistantTurnStarted || target.completed) {
|
|
1253
|
+
log.warn(
|
|
1254
|
+
"Dropping a late final transcript segment: its assistant turn already dispatched",
|
|
1255
|
+
);
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
await this.recordFinalTranscript(target, event.text);
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
case "finalized": {
|
|
1262
|
+
// Completes the head's outstanding finalize request, whether or
|
|
1263
|
+
// not its flush final arrived (the provider may omit an empty
|
|
1264
|
+
// flush; its own fallback still emits `finalized`).
|
|
1265
|
+
const owner = this.finalizeQueue.shift() ?? null;
|
|
1266
|
+
if (owner && owner === this.finalizeGraceCycle) {
|
|
1267
|
+
this.clearFinalizeGraceTimer();
|
|
1268
|
+
}
|
|
1269
|
+
if (owner && owner.phase === "released") {
|
|
1270
|
+
// In persistent mode "transcriber_closed" means the cycle's
|
|
1271
|
+
// transcript is complete — the shared stream stays open.
|
|
1272
|
+
owner.phase = "transcriber_closed";
|
|
1273
|
+
}
|
|
1274
|
+
// The request slot is free again: send the next awaiting cycle's.
|
|
1275
|
+
this.pumpFinalizeQueue();
|
|
1276
|
+
if (!owner) {
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
await this.startAssistantTurnIfReady();
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
case "error":
|
|
1283
|
+
await this.sendTranscriberErrorFrame(event);
|
|
1284
|
+
return;
|
|
1285
|
+
case "closed": {
|
|
1286
|
+
// The shared stream closed under the session: fall back to the
|
|
1287
|
+
// per-cycle path — the next arm resolves a fresh transcriber.
|
|
1288
|
+
this.sharedTranscriber = null;
|
|
1289
|
+
this.clearFinalizeGraceTimer();
|
|
1290
|
+
const drained = this.finalizeQueue;
|
|
1291
|
+
this.finalizeQueue = [];
|
|
1292
|
+
for (const finalizing of drained) {
|
|
1293
|
+
if (finalizing.transcriber === transcriber) {
|
|
1294
|
+
finalizing.transcriber = null;
|
|
1295
|
+
}
|
|
1296
|
+
if (finalizing.phase === "released") {
|
|
1297
|
+
finalizing.phase = "transcriber_closed";
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
const current = this.currentUtterance;
|
|
1301
|
+
if (
|
|
1302
|
+
current &&
|
|
1303
|
+
!drained.includes(current) &&
|
|
1304
|
+
current.transcriber === transcriber
|
|
1305
|
+
) {
|
|
1306
|
+
current.transcriber = null;
|
|
1307
|
+
current.phase = "transcriber_closed";
|
|
1308
|
+
// An unreleased cycle with nothing captured: retire it so the
|
|
1309
|
+
// next speech chunk lazily arms a fresh utterance.
|
|
1310
|
+
if (
|
|
1311
|
+
!current.released &&
|
|
1312
|
+
!current.completed &&
|
|
1313
|
+
current.finalTranscriptSegments.length === 0
|
|
1314
|
+
) {
|
|
1315
|
+
await this.finalizePendingUtterance(current, "transcriber_closed");
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
await this.startAssistantTurnIfReady();
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
private async recordFinalTranscript(
|
|
1326
|
+
utterance: UtteranceCycle,
|
|
1327
|
+
text: string,
|
|
1328
|
+
): Promise<void> {
|
|
1329
|
+
const transcript = text.trim();
|
|
1330
|
+
if (transcript.length > 0) {
|
|
1331
|
+
utterance.finalTranscriptSegments.push(transcript);
|
|
1332
|
+
}
|
|
1333
|
+
this.markFinalTranscript(utterance);
|
|
1334
|
+
await this.sendFrame({ type: "stt_final", text });
|
|
1335
|
+
await this.startAssistantTurnIfReady();
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// Providers emit `error` mid-stream and may keep streaming; `closed` /
|
|
1339
|
+
// `final` still drive turn lifecycle. Only transient categories are
|
|
1340
|
+
// recoverable — auth/rate-limit/invalid-audio will not self-heal, so
|
|
1341
|
+
// hands-free clients must surface them instead of suppressing them.
|
|
1342
|
+
private async sendTranscriberErrorFrame(
|
|
1343
|
+
event: SttStreamServerErrorEvent,
|
|
1344
|
+
): Promise<void> {
|
|
1345
|
+
const recoverable =
|
|
1346
|
+
event.category === "timeout" || event.category === "provider-error";
|
|
1347
|
+
await this.sendFrame({
|
|
1348
|
+
type: "error",
|
|
1349
|
+
code: LiveVoiceProtocolErrorCode.InvalidField,
|
|
1350
|
+
message: event.message,
|
|
1351
|
+
...(recoverable ? { recoverable: true } : {}),
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
|
|
793
1355
|
private async interrupt(): Promise<void> {
|
|
794
|
-
if (this.isClosed || this.state === "failed")
|
|
1356
|
+
if (this.isClosed || this.state === "failed") {
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
795
1359
|
|
|
796
1360
|
this.state = "interrupted";
|
|
797
1361
|
// A client interrupt also discards speech parked in the pre-roll ring.
|
|
1362
|
+
// The client stopped its own playback, so the drain estimate resets.
|
|
1363
|
+
this.assistantPlaybackTailUntilMs = 0;
|
|
798
1364
|
this.takeVadPreRoll();
|
|
799
1365
|
this.vadPendingTurnEnd = null;
|
|
800
1366
|
const utterance = this.currentUtterance;
|
|
1367
|
+
this.stopSessionTranscriber();
|
|
801
1368
|
if (utterance) {
|
|
802
|
-
stopTranscriberBestEffort(utterance.transcriber);
|
|
803
|
-
utterance.transcriber = null;
|
|
804
1369
|
// In server_vad mode the current utterance may be the lazily armed
|
|
805
1370
|
// next cycle, distinct from the in-flight turn's — finalize it too so
|
|
806
1371
|
// the post-turn re-arm can replace it.
|
|
@@ -813,6 +1378,25 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
813
1378
|
await this.drainOutboundFrames();
|
|
814
1379
|
}
|
|
815
1380
|
|
|
1381
|
+
// Stops whichever streaming transcriber the session holds (shared or
|
|
1382
|
+
// per-cycle) and clears the finalize bookkeeping. Used by interrupt() and
|
|
1383
|
+
// close(); persistent mode re-establishes itself on the next arm.
|
|
1384
|
+
private stopSessionTranscriber(): void {
|
|
1385
|
+
this.clearFinalizeGraceTimer();
|
|
1386
|
+
this.finalizeQueue = [];
|
|
1387
|
+
const shared = this.sharedTranscriber;
|
|
1388
|
+
this.sharedTranscriber = null;
|
|
1389
|
+
const utterance = this.currentUtterance;
|
|
1390
|
+
const transcriber = utterance?.transcriber ?? null;
|
|
1391
|
+
if (utterance) {
|
|
1392
|
+
utterance.transcriber = null;
|
|
1393
|
+
}
|
|
1394
|
+
stopTranscriberBestEffort(transcriber);
|
|
1395
|
+
if (shared && shared !== transcriber) {
|
|
1396
|
+
stopTranscriberBestEffort(shared);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
|
|
816
1400
|
private async startAssistantTurnIfReady(): Promise<void> {
|
|
817
1401
|
const utterance = this.currentUtterance;
|
|
818
1402
|
if (
|
|
@@ -826,11 +1410,15 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
826
1410
|
}
|
|
827
1411
|
// One assistant turn at a time: a server_vad utterance that closes while
|
|
828
1412
|
// the previous turn is still speaking waits; rearmAfterTurn retries it.
|
|
829
|
-
if (this.activeAssistantTurn)
|
|
1413
|
+
if (this.activeAssistantTurn) {
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
830
1416
|
if (utterance.phase !== "transcriber_closed") {
|
|
831
1417
|
return;
|
|
832
1418
|
}
|
|
833
|
-
if (!this.startVoiceTurn)
|
|
1419
|
+
if (!this.startVoiceTurn) {
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
834
1422
|
|
|
835
1423
|
const content = utterance.finalTranscriptSegments.join(" ").trim();
|
|
836
1424
|
if (content.length === 0) {
|
|
@@ -863,6 +1451,8 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
863
1451
|
ttsAudioStarted: false,
|
|
864
1452
|
finalized: false,
|
|
865
1453
|
ttsBuffer: "",
|
|
1454
|
+
ttsSegmentEnqueued: false,
|
|
1455
|
+
ttsJobs: [],
|
|
866
1456
|
ttsQueue: Promise.resolve(),
|
|
867
1457
|
assistantMessageId: null,
|
|
868
1458
|
assistantAudioChunks: [],
|
|
@@ -870,7 +1460,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
870
1460
|
};
|
|
871
1461
|
|
|
872
1462
|
await this.sendFrame({ type: "thinking", turnId });
|
|
873
|
-
if (!this.isActiveAssistantTurn(token))
|
|
1463
|
+
if (!this.isActiveAssistantTurn(token)) {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
874
1466
|
|
|
875
1467
|
try {
|
|
876
1468
|
const handle = await this.startVoiceTurn({
|
|
@@ -888,7 +1480,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
888
1480
|
signal: abortController.signal,
|
|
889
1481
|
callbacks: {
|
|
890
1482
|
assistant_text_delta: (msg) => {
|
|
891
|
-
if (!this.isForwardingAssistantText(token))
|
|
1483
|
+
if (!this.isForwardingAssistantText(token)) {
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
892
1486
|
this.markFirstAssistantDelta(utterance, turnId);
|
|
893
1487
|
void this.sendFrame({
|
|
894
1488
|
type: "assistant_text_delta",
|
|
@@ -921,12 +1515,16 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
921
1515
|
},
|
|
922
1516
|
persisted_user_message_id: (messageId) => {
|
|
923
1517
|
const activeTurn = this.activeAssistantTurn;
|
|
924
|
-
if (activeTurn?.token !== token)
|
|
1518
|
+
if (activeTurn?.token !== token) {
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
925
1521
|
activeTurn.utterance.userMessageId = messageId;
|
|
926
1522
|
},
|
|
927
1523
|
persisted_assistant_message_id: (messageId) => {
|
|
928
1524
|
const activeTurn = this.activeAssistantTurn;
|
|
929
|
-
if (activeTurn?.token !== token)
|
|
1525
|
+
if (activeTurn?.token !== token) {
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
930
1528
|
activeTurn.assistantMessageId = messageId;
|
|
931
1529
|
},
|
|
932
1530
|
},
|
|
@@ -945,7 +1543,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
945
1543
|
message,
|
|
946
1544
|
});
|
|
947
1545
|
const currentTurn = this.activeAssistantTurn;
|
|
948
|
-
if (currentTurn?.token !== token)
|
|
1546
|
+
if (currentTurn?.token !== token) {
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
949
1549
|
await this.finalizeAssistantTurn(currentTurn, "cancelled", "error");
|
|
950
1550
|
})();
|
|
951
1551
|
},
|
|
@@ -963,7 +1563,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
963
1563
|
|
|
964
1564
|
activeTurn.handle = handle;
|
|
965
1565
|
} catch (err) {
|
|
966
|
-
if (!this.isActiveAssistantTurn(token))
|
|
1566
|
+
if (!this.isActiveAssistantTurn(token)) {
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
967
1569
|
|
|
968
1570
|
this.activeAssistantTurn = null;
|
|
969
1571
|
await this.sendFrame({
|
|
@@ -1029,10 +1631,14 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1029
1631
|
}
|
|
1030
1632
|
|
|
1031
1633
|
private bufferAssistantTextForTts(token: symbol, text: string): void {
|
|
1032
|
-
if (!this.streamTtsAudio || text.length === 0)
|
|
1634
|
+
if (!this.streamTtsAudio || text.length === 0) {
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1033
1637
|
|
|
1034
1638
|
const activeTurn = this.activeAssistantTurn;
|
|
1035
|
-
if (activeTurn?.token !== token || activeTurn.assistantCompleted)
|
|
1639
|
+
if (activeTurn?.token !== token || activeTurn.assistantCompleted) {
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1036
1642
|
|
|
1037
1643
|
activeTurn.ttsBuffer += text;
|
|
1038
1644
|
this.flushTtsBuffer(token, false);
|
|
@@ -1040,17 +1646,23 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1040
1646
|
|
|
1041
1647
|
private completeTtsForTurn(token: symbol): void {
|
|
1042
1648
|
const activeTurn = this.activeAssistantTurn;
|
|
1043
|
-
if (activeTurn?.token !== token)
|
|
1649
|
+
if (activeTurn?.token !== token) {
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1044
1652
|
|
|
1045
1653
|
this.flushTtsBuffer(token, true);
|
|
1046
1654
|
activeTurn.ttsQueue = activeTurn.ttsQueue
|
|
1047
1655
|
.catch(() => {})
|
|
1048
1656
|
.then(async () => {
|
|
1049
1657
|
const currentTurn = this.activeAssistantTurn;
|
|
1050
|
-
if (currentTurn?.token !== token || currentTurn.ttsDone)
|
|
1658
|
+
if (currentTurn?.token !== token || currentTurn.ttsDone) {
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1051
1661
|
// Barge-in can abort while this continuation is queued; the turn
|
|
1052
1662
|
// then finalizes as cancelled through cancelAssistantTurn.
|
|
1053
|
-
if (currentTurn.abortController.signal.aborted)
|
|
1663
|
+
if (currentTurn.abortController.signal.aborted) {
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1054
1666
|
|
|
1055
1667
|
currentTurn.ttsDone = true;
|
|
1056
1668
|
await this.finalizeAssistantTurn(
|
|
@@ -1087,7 +1699,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1087
1699
|
|
|
1088
1700
|
private flushTtsBuffer(token: symbol, force: boolean): void {
|
|
1089
1701
|
const activeTurn = this.activeAssistantTurn;
|
|
1090
|
-
if (activeTurn?.token !== token)
|
|
1702
|
+
if (activeTurn?.token !== token) {
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1091
1705
|
|
|
1092
1706
|
if (!this.streamTtsAudio) {
|
|
1093
1707
|
activeTurn.ttsBuffer = "";
|
|
@@ -1097,6 +1711,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1097
1711
|
const { segments, remainder } = extractSpeakableSegments(
|
|
1098
1712
|
activeTurn.ttsBuffer,
|
|
1099
1713
|
force,
|
|
1714
|
+
// Eager until the first segment is enqueued: the opening clause flushes
|
|
1715
|
+
// early so speech onset does not wait for a full sentence.
|
|
1716
|
+
{ eager: !activeTurn.ttsSegmentEnqueued },
|
|
1100
1717
|
);
|
|
1101
1718
|
activeTurn.ttsBuffer = remainder;
|
|
1102
1719
|
|
|
@@ -1113,79 +1730,194 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1113
1730
|
|
|
1114
1731
|
private enqueueTtsSegment(token: symbol, segment: string): void {
|
|
1115
1732
|
const activeTurn = this.activeAssistantTurn;
|
|
1116
|
-
|
|
1117
|
-
|
|
1733
|
+
if (activeTurn?.token !== token || !this.streamTtsAudio) {
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1118
1736
|
|
|
1737
|
+
activeTurn.ttsSegmentEnqueued = true;
|
|
1738
|
+
const job: TtsSegmentJob = {
|
|
1739
|
+
text: segment,
|
|
1740
|
+
started: false,
|
|
1741
|
+
settled: false,
|
|
1742
|
+
emitting: false,
|
|
1743
|
+
bufferedChunks: [],
|
|
1744
|
+
synthesis: null,
|
|
1745
|
+
frames: Promise.resolve(),
|
|
1746
|
+
};
|
|
1747
|
+
activeTurn.ttsJobs.push(job);
|
|
1748
|
+
this.pumpTtsSynthesis(token);
|
|
1119
1749
|
activeTurn.ttsQueue = activeTurn.ttsQueue
|
|
1120
1750
|
.catch(() => {})
|
|
1121
|
-
.then(
|
|
1122
|
-
|
|
1123
|
-
if (
|
|
1124
|
-
currentTurn?.token !== token ||
|
|
1125
|
-
currentTurn.abortController.signal.aborted
|
|
1126
|
-
) {
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1751
|
+
.then(() => this.emitTtsJob(token, job));
|
|
1752
|
+
}
|
|
1129
1753
|
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1754
|
+
// Starts provider streams for queued jobs, in list order, while an
|
|
1755
|
+
// open-job slot is free. The prefetching job's chunks buffer in memory
|
|
1756
|
+
// until the emission chain promotes it, so the next segment's provider
|
|
1757
|
+
// first-chunk latency overlaps the current segment's playback.
|
|
1758
|
+
private pumpTtsSynthesis(token: symbol): void {
|
|
1759
|
+
const activeTurn = this.activeAssistantTurn;
|
|
1760
|
+
const streamTtsAudio = this.streamTtsAudio;
|
|
1761
|
+
if (
|
|
1762
|
+
activeTurn?.token !== token ||
|
|
1763
|
+
!streamTtsAudio ||
|
|
1764
|
+
activeTurn.abortController.signal.aborted ||
|
|
1765
|
+
this.isClosed
|
|
1766
|
+
) {
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
while (
|
|
1771
|
+
activeTurn.ttsJobs.filter((job) => job.started && !job.settled).length <
|
|
1772
|
+
TTS_MAX_OPEN_SYNTHESIS_JOBS
|
|
1773
|
+
) {
|
|
1774
|
+
const job = activeTurn.ttsJobs.find((candidate) => !candidate.started);
|
|
1775
|
+
if (!job) {
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
job.started = true;
|
|
1779
|
+
let synthesis: Promise<void>;
|
|
1780
|
+
try {
|
|
1781
|
+
synthesis = streamTtsAudio({
|
|
1782
|
+
text: job.text,
|
|
1783
|
+
signal: activeTurn.abortController.signal,
|
|
1784
|
+
outputFormat: "pcm",
|
|
1785
|
+
sampleRate: this.context.startFrame.audio.sampleRate,
|
|
1786
|
+
onAudioChunk: (chunk) => {
|
|
1787
|
+
if (!this.isForwardingTts(token)) {
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
if (job.emitting) {
|
|
1791
|
+
this.forwardTtsChunk(token, job, chunk);
|
|
1792
|
+
} else {
|
|
1793
|
+
job.bufferedChunks.push(chunk);
|
|
1794
|
+
}
|
|
1795
|
+
},
|
|
1796
|
+
}).then(() => undefined);
|
|
1797
|
+
} catch (err) {
|
|
1798
|
+
synthesis = Promise.reject(err);
|
|
1799
|
+
}
|
|
1800
|
+
// The job's emission step observes the rejection; this handler only
|
|
1801
|
+
// keeps a failure on an already-cancelled turn from surfacing as an
|
|
1802
|
+
// unhandled rejection.
|
|
1803
|
+
synthesis.catch(() => {});
|
|
1804
|
+
job.synthesis = synthesis;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
// Emission slot for one job, run in strict segment order on the turn's
|
|
1809
|
+
// ttsQueue chain: promotes the job from prefetch to live, flushes what it
|
|
1810
|
+
// buffered, and returns only once every frame write for the job is ordered
|
|
1811
|
+
// ahead of the next segment's.
|
|
1812
|
+
private async emitTtsJob(token: symbol, job: TtsSegmentJob): Promise<void> {
|
|
1813
|
+
try {
|
|
1814
|
+
const currentTurn = this.activeAssistantTurn;
|
|
1815
|
+
if (
|
|
1816
|
+
currentTurn?.token !== token ||
|
|
1817
|
+
currentTurn.abortController.signal.aborted
|
|
1818
|
+
) {
|
|
1819
|
+
// The turn is gone: release the prefetched audio immediately rather
|
|
1820
|
+
// than holding it until the turn object drops.
|
|
1821
|
+
job.bufferedChunks.length = 0;
|
|
1822
|
+
return;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
// Both slots can be busy when a job is enqueued; every earlier job has
|
|
1826
|
+
// settled once it reaches the head of the chain, so a slot is free.
|
|
1827
|
+
if (!job.started) {
|
|
1828
|
+
this.pumpTtsSynthesis(token);
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
// Promote synchronously: no provider callback can land between the
|
|
1832
|
+
// flag flip and the buffered flush, so flushed and live chunks stay in
|
|
1833
|
+
// provider order on the job's frame chain.
|
|
1834
|
+
job.emitting = true;
|
|
1835
|
+
for (const chunk of job.bufferedChunks.splice(0)) {
|
|
1836
|
+
this.forwardTtsChunk(token, job, chunk);
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
let failed = false;
|
|
1840
|
+
let synthesisError: unknown;
|
|
1841
|
+
try {
|
|
1842
|
+
await job.synthesis;
|
|
1843
|
+
} catch (err) {
|
|
1844
|
+
failed = true;
|
|
1845
|
+
synthesisError = err;
|
|
1846
|
+
}
|
|
1847
|
+
// The provider stream has settled, so the frame chain is complete;
|
|
1848
|
+
// awaiting it puts every frame of this segment ahead of the next.
|
|
1849
|
+
await job.frames;
|
|
1850
|
+
|
|
1851
|
+
if (failed && this.isForwardingTts(token)) {
|
|
1852
|
+
// Per-segment failure: the turn (and session) continue, so the
|
|
1853
|
+
// error is recoverable for the client.
|
|
1854
|
+
await this.sendFrame(
|
|
1855
|
+
{
|
|
1856
|
+
type: "error",
|
|
1857
|
+
code: LiveVoiceProtocolErrorCode.InvalidField,
|
|
1858
|
+
message: `Live voice TTS failed: ${errorMessage(synthesisError)}`,
|
|
1859
|
+
recoverable: true,
|
|
1860
|
+
},
|
|
1861
|
+
() => this.isForwardingTts(token),
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
} finally {
|
|
1865
|
+
job.settled = true;
|
|
1866
|
+
this.pumpTtsSynthesis(token);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
private forwardTtsChunk(
|
|
1871
|
+
token: symbol,
|
|
1872
|
+
job: TtsSegmentJob,
|
|
1873
|
+
chunk: LiveVoiceTtsAudioChunk,
|
|
1874
|
+
): void {
|
|
1875
|
+
if (!this.isForwardingTts(token)) {
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
const activeTurn = this.activeAssistantTurn;
|
|
1879
|
+
if (activeTurn?.token !== token) {
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
activeTurn.assistantAudioChunks.push(
|
|
1883
|
+
Buffer.from(chunk.dataBase64, "base64"),
|
|
1884
|
+
);
|
|
1885
|
+
activeTurn.assistantAudioMimeType = chunk.contentType;
|
|
1886
|
+
activeTurn.assistantAudioSampleRate = chunk.sampleRate;
|
|
1887
|
+
job.frames = job.frames.then(async () => {
|
|
1888
|
+
const sent = await this.sendFrame(
|
|
1889
|
+
{
|
|
1890
|
+
type: "tts_audio",
|
|
1891
|
+
mimeType: chunk.contentType,
|
|
1892
|
+
sampleRate: chunk.sampleRate,
|
|
1893
|
+
dataBase64: chunk.dataBase64,
|
|
1894
|
+
},
|
|
1895
|
+
() => this.isForwardingTts(token),
|
|
1896
|
+
);
|
|
1897
|
+
// Arm the barge-in gate only once a tts_audio frame was actually
|
|
1898
|
+
// written — a backed-up outbound queue must not let speech cancel a
|
|
1899
|
+
// still-unspoken reply. Token match keeps a stale turn's late send
|
|
1900
|
+
// from arming a newer turn.
|
|
1901
|
+
if (!sent) {
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
// Extend the client playback-tail estimate by this chunk's PCM
|
|
1905
|
+
// duration (chunks queue gaplessly client-side, so the tail grows
|
|
1906
|
+
// from whichever is later: now or the current estimate).
|
|
1907
|
+
const chunkMs = pcm16DurationMs(
|
|
1908
|
+
Buffer.byteLength(chunk.dataBase64, "base64"),
|
|
1909
|
+
chunk.sampleRate,
|
|
1910
|
+
);
|
|
1911
|
+
const now = Date.now();
|
|
1912
|
+
this.assistantPlaybackTailUntilMs =
|
|
1913
|
+
Math.max(now, this.assistantPlaybackTailUntilMs) + chunkMs;
|
|
1914
|
+
const turnAfterSend = this.activeAssistantTurn;
|
|
1915
|
+
if (turnAfterSend?.token !== token || turnAfterSend.ttsAudioStarted) {
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
turnAfterSend.ttsAudioStarted = true;
|
|
1919
|
+
this.metrics.markFirstTtsAudio(turnAfterSend.turnId);
|
|
1920
|
+
});
|
|
1189
1921
|
}
|
|
1190
1922
|
|
|
1191
1923
|
private collectUserAudio(utterance: UtteranceCycle, chunk: Buffer): void {
|
|
@@ -1211,7 +1943,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1211
1943
|
return;
|
|
1212
1944
|
}
|
|
1213
1945
|
const turnId = this.ensureTurnId(utterance);
|
|
1214
|
-
if (!this.startMetricsTurnIfNeeded(utterance, turnId))
|
|
1946
|
+
if (!this.startMetricsTurnIfNeeded(utterance, turnId)) {
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1215
1949
|
this.metrics.markPushToTalkRelease(turnId);
|
|
1216
1950
|
}
|
|
1217
1951
|
|
|
@@ -1241,7 +1975,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1241
1975
|
mark(turnId);
|
|
1242
1976
|
return;
|
|
1243
1977
|
}
|
|
1244
|
-
if (utterance.metricsTurnFinished)
|
|
1978
|
+
if (utterance.metricsTurnFinished) {
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1245
1981
|
if (utterance.stashedMetricsMarks[field] === null) {
|
|
1246
1982
|
utterance.stashedMetricsMarks[field] = this.metricsClock();
|
|
1247
1983
|
}
|
|
@@ -1251,7 +1987,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1251
1987
|
utterance: UtteranceCycle,
|
|
1252
1988
|
turnId: string,
|
|
1253
1989
|
): void {
|
|
1254
|
-
if (!this.startMetricsTurnIfNeeded(utterance, turnId))
|
|
1990
|
+
if (!this.startMetricsTurnIfNeeded(utterance, turnId)) {
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1255
1993
|
this.metrics.markFirstAssistantDelta(turnId);
|
|
1256
1994
|
}
|
|
1257
1995
|
|
|
@@ -1267,9 +2005,15 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1267
2005
|
utterance: UtteranceCycle,
|
|
1268
2006
|
turnId: string,
|
|
1269
2007
|
): boolean {
|
|
1270
|
-
if (utterance.metricsTurnFinished)
|
|
1271
|
-
|
|
1272
|
-
|
|
2008
|
+
if (utterance.metricsTurnFinished) {
|
|
2009
|
+
return false;
|
|
2010
|
+
}
|
|
2011
|
+
if (utterance.metricsTurnStarted) {
|
|
2012
|
+
return true;
|
|
2013
|
+
}
|
|
2014
|
+
if (this.hasBlockingMetricsTurn(utterance)) {
|
|
2015
|
+
return false;
|
|
2016
|
+
}
|
|
1273
2017
|
this.metrics.startTurn(turnId, toSeedMarks(utterance.stashedMetricsMarks));
|
|
1274
2018
|
utterance.metricsTurnStarted = true;
|
|
1275
2019
|
return true;
|
|
@@ -1294,7 +2038,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1294
2038
|
): Promise<void> {
|
|
1295
2039
|
utterance.completed = true;
|
|
1296
2040
|
const turnId = utterance.turnId;
|
|
1297
|
-
if (!turnId)
|
|
2041
|
+
if (!turnId) {
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
1298
2044
|
|
|
1299
2045
|
await this.archiveBufferedAudio({
|
|
1300
2046
|
turnId,
|
|
@@ -1313,7 +2059,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1313
2059
|
reason = "completed",
|
|
1314
2060
|
options: { clearActive?: boolean; rearm?: boolean } = {},
|
|
1315
2061
|
): Promise<void> {
|
|
1316
|
-
if (turn.finalized)
|
|
2062
|
+
if (turn.finalized) {
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
1317
2065
|
|
|
1318
2066
|
turn.finalized = true;
|
|
1319
2067
|
turn.utterance.completed = true;
|
|
@@ -1389,7 +2137,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1389
2137
|
audio: Buffer;
|
|
1390
2138
|
}): Promise<void> {
|
|
1391
2139
|
const archiveAudio = this.archiveAudio;
|
|
1392
|
-
if (!archiveAudio)
|
|
2140
|
+
if (!archiveAudio) {
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
1393
2143
|
|
|
1394
2144
|
const durationMs = estimatePcmDurationMs({
|
|
1395
2145
|
byteLength: input.audio.byteLength,
|
|
@@ -1458,7 +2208,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1458
2208
|
reason: string,
|
|
1459
2209
|
turnId: string,
|
|
1460
2210
|
): Promise<void> {
|
|
1461
|
-
if (!utterance.metricsTurnStarted || utterance.metricsTurnFinished)
|
|
2211
|
+
if (!utterance.metricsTurnStarted || utterance.metricsTurnFinished) {
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
1462
2214
|
|
|
1463
2215
|
if (status === "completed") {
|
|
1464
2216
|
this.metrics.completeTurn(turnId);
|
|
@@ -1467,7 +2219,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1467
2219
|
}
|
|
1468
2220
|
utterance.metricsTurnFinished = true;
|
|
1469
2221
|
|
|
1470
|
-
if (!this.emitMetrics)
|
|
2222
|
+
if (!this.emitMetrics) {
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
1471
2225
|
await this.emitMetricsFrame(
|
|
1472
2226
|
status === "completed" ? "turn_completed" : "turn_cancelled",
|
|
1473
2227
|
turnId,
|
|
@@ -1475,7 +2229,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1475
2229
|
}
|
|
1476
2230
|
|
|
1477
2231
|
private async emitSessionEndMetrics(): Promise<void> {
|
|
1478
|
-
if (!this.emitMetrics || this.sessionEndMetricsEmitted)
|
|
2232
|
+
if (!this.emitMetrics || this.sessionEndMetricsEmitted) {
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
1479
2235
|
|
|
1480
2236
|
this.sessionEndMetricsEmitted = true;
|
|
1481
2237
|
await this.emitMetricsFrame("session_ended");
|
|
@@ -1497,11 +2253,14 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1497
2253
|
});
|
|
1498
2254
|
}
|
|
1499
2255
|
|
|
1500
|
-
private async failStartup(
|
|
2256
|
+
private async failStartup(
|
|
2257
|
+
message: string,
|
|
2258
|
+
code: LiveVoiceProtocolErrorCode,
|
|
2259
|
+
): Promise<never> {
|
|
1501
2260
|
this.state = "failed";
|
|
1502
2261
|
await this.sendFrame({
|
|
1503
2262
|
type: "error",
|
|
1504
|
-
code
|
|
2263
|
+
code,
|
|
1505
2264
|
message,
|
|
1506
2265
|
});
|
|
1507
2266
|
throw new LiveVoiceSessionStartupError(message);
|
|
@@ -1524,7 +2283,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1524
2283
|
this.outboundFrames = this.outboundFrames
|
|
1525
2284
|
.catch(() => {})
|
|
1526
2285
|
.then(async () => {
|
|
1527
|
-
if (!shouldSend())
|
|
2286
|
+
if (!shouldSend()) {
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
1528
2289
|
await this.context.sendFrame(frame);
|
|
1529
2290
|
sent = true;
|
|
1530
2291
|
})
|
|
@@ -1549,8 +2310,31 @@ export function createLiveVoiceSession(
|
|
|
1549
2310
|
context: LiveVoiceSessionFactoryContext,
|
|
1550
2311
|
options: LiveVoiceSessionOptions = {},
|
|
1551
2312
|
): LiveVoiceSession {
|
|
2313
|
+
// Workspace-tunable server-VAD thresholds. The `liveVoice.vad` schema
|
|
2314
|
+
// defaults match the code defaults (800 energy / 800 ms silence / 30 s max
|
|
2315
|
+
// turn / 60 ms barge-in guard), so an unset config leaves behavior
|
|
2316
|
+
// unchanged. Optional-chained
|
|
2317
|
+
// because hand-built test configs may predate the liveVoice namespace;
|
|
2318
|
+
// absent config falls through to the in-code defaults.
|
|
2319
|
+
const vadConfig = getConfig().liveVoice?.vad;
|
|
1552
2320
|
return new LiveVoiceSession(context, {
|
|
1553
2321
|
...options,
|
|
2322
|
+
turnDetectorConfig:
|
|
2323
|
+
options.turnDetectorConfig ??
|
|
2324
|
+
(vadConfig
|
|
2325
|
+
? {
|
|
2326
|
+
silenceThresholdMs: vadConfig.silenceThresholdMs,
|
|
2327
|
+
maxTurnDurationMs: vadConfig.maxTurnDurationMs,
|
|
2328
|
+
}
|
|
2329
|
+
: {}),
|
|
2330
|
+
speechEnergyThreshold:
|
|
2331
|
+
options.speechEnergyThreshold ?? vadConfig?.speechEnergyThreshold,
|
|
2332
|
+
bargeInMinSpeechMs:
|
|
2333
|
+
options.bargeInMinSpeechMs ?? vadConfig?.bargeInMinSpeechMs,
|
|
2334
|
+
resolveCredentialReadiness:
|
|
2335
|
+
options.resolveCredentialReadiness === undefined
|
|
2336
|
+
? defaultResolveLiveVoiceCredentialReadiness
|
|
2337
|
+
: options.resolveCredentialReadiness,
|
|
1554
2338
|
startVoiceTurn: options.startVoiceTurn ?? defaultStartVoiceTurn,
|
|
1555
2339
|
streamTtsAudio:
|
|
1556
2340
|
options.streamTtsAudio === undefined
|
|
@@ -1572,9 +2356,33 @@ async function defaultResolveStreamingTranscriber(
|
|
|
1572
2356
|
return resolveStreamingTranscriber(options);
|
|
1573
2357
|
}
|
|
1574
2358
|
|
|
2359
|
+
async function defaultResolveLiveVoiceCredentialReadiness(): Promise<LiveVoiceCredentialReadiness> {
|
|
2360
|
+
const { resolveLiveVoiceCredentialReadiness } =
|
|
2361
|
+
await import("./live-voice-credential-preflight.js");
|
|
2362
|
+
return resolveLiveVoiceCredentialReadiness();
|
|
2363
|
+
}
|
|
2364
|
+
|
|
1575
2365
|
async function defaultStartVoiceTurn(
|
|
1576
2366
|
options: VoiceTurnOptions,
|
|
1577
2367
|
): Promise<VoiceTurnHandle> {
|
|
2368
|
+
// On the first turn of a brand-new chat the client's conversation id has no
|
|
2369
|
+
// persisted `conversations` row yet — the live-voice session adopts the id
|
|
2370
|
+
// from its start frame rather than minting one through the conversation-key
|
|
2371
|
+
// store the text-send path uses. Without the row, the user-message persist
|
|
2372
|
+
// inside `startVoiceTurn` trips `FOREIGN KEY constraint failed`. Ensure it
|
|
2373
|
+
// exists (idempotent) before persisting. Lives in the production wiring, not
|
|
2374
|
+
// the session state machine, so session unit tests stay DB-free.
|
|
2375
|
+
const createdConversation = ensureConversationExists(options.conversationId);
|
|
2376
|
+
if (createdConversation) {
|
|
2377
|
+
// The row was created outside the normal send-message route, which is where
|
|
2378
|
+
// sibling clients/sidebars learn about a new conversation. Emit the same
|
|
2379
|
+
// "created" list invalidation that route does so they see the new voice
|
|
2380
|
+
// conversation without waiting for a reload.
|
|
2381
|
+
publishConversationListAndMetadataChanged(
|
|
2382
|
+
"created",
|
|
2383
|
+
options.conversationId,
|
|
2384
|
+
);
|
|
2385
|
+
}
|
|
1578
2386
|
const { startVoiceTurn } = await import("../calls/voice-session-bridge.js");
|
|
1579
2387
|
return startVoiceTurn(options);
|
|
1580
2388
|
}
|
|
@@ -1598,81 +2406,6 @@ async function defaultArchiveLiveVoiceAudio(
|
|
|
1598
2406
|
: linkLiveVoiceAssistantResponseAudioToMessage(input);
|
|
1599
2407
|
}
|
|
1600
2408
|
|
|
1601
|
-
function extractSpeakableSegments(
|
|
1602
|
-
text: string,
|
|
1603
|
-
force: boolean,
|
|
1604
|
-
): { segments: string[]; remainder: string } {
|
|
1605
|
-
const segments: string[] = [];
|
|
1606
|
-
let remainder = text;
|
|
1607
|
-
|
|
1608
|
-
while (remainder.length > 0) {
|
|
1609
|
-
const boundary = findSpeakableBoundary(remainder);
|
|
1610
|
-
if (boundary === null) break;
|
|
1611
|
-
|
|
1612
|
-
const segment = remainder.slice(0, boundary).trim();
|
|
1613
|
-
if (segment.length > 0) {
|
|
1614
|
-
segments.push(segment);
|
|
1615
|
-
}
|
|
1616
|
-
remainder = remainder.slice(boundary);
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1619
|
-
if (force) {
|
|
1620
|
-
const segment = remainder.trim();
|
|
1621
|
-
if (segment.length > 0) {
|
|
1622
|
-
segments.push(segment);
|
|
1623
|
-
}
|
|
1624
|
-
remainder = "";
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
return { segments, remainder };
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
function findSpeakableBoundary(text: string): number | null {
|
|
1631
|
-
for (let index = 0; index < text.length; index += 1) {
|
|
1632
|
-
const char = text[index];
|
|
1633
|
-
if (char === "\n") return index + 1;
|
|
1634
|
-
if (!char || !SENTENCE_ENDING_PUNCTUATION.has(char)) continue;
|
|
1635
|
-
|
|
1636
|
-
let boundary = index + 1;
|
|
1637
|
-
while (
|
|
1638
|
-
boundary < text.length &&
|
|
1639
|
-
TRAILING_SENTENCE_PUNCTUATION.has(text[boundary] ?? "")
|
|
1640
|
-
) {
|
|
1641
|
-
boundary += 1;
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
if (boundary === text.length || isWhitespace(text[boundary] ?? "")) {
|
|
1645
|
-
return boundary;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
if (text.length < LIVE_VOICE_TTS_SEGMENT_CHAR_THRESHOLD) {
|
|
1650
|
-
return null;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
const preferredBoundary = findLastWhitespaceBoundary(
|
|
1654
|
-
text,
|
|
1655
|
-
LIVE_VOICE_TTS_SEGMENT_CHAR_THRESHOLD,
|
|
1656
|
-
);
|
|
1657
|
-
return preferredBoundary ?? LIVE_VOICE_TTS_SEGMENT_CHAR_THRESHOLD;
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
function findLastWhitespaceBoundary(
|
|
1661
|
-
text: string,
|
|
1662
|
-
maxLength: number,
|
|
1663
|
-
): number | null {
|
|
1664
|
-
for (let index = maxLength; index > Math.floor(maxLength * 0.6); index -= 1) {
|
|
1665
|
-
if (isWhitespace(text[index] ?? "")) {
|
|
1666
|
-
return index + 1;
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
return null;
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
function isWhitespace(value: string): boolean {
|
|
1673
|
-
return /\s/.test(value);
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
2409
|
function toSeedMarks(stashed: StashedMetricsMarks): LiveVoiceTurnSeedMarks {
|
|
1677
2410
|
return {
|
|
1678
2411
|
...(stashed.firstAudioAtMs !== null
|
|
@@ -1694,13 +2427,20 @@ function toSeedMarks(stashed: StashedMetricsMarks): LiveVoiceTurnSeedMarks {
|
|
|
1694
2427
|
}
|
|
1695
2428
|
|
|
1696
2429
|
function takeBufferedAudio(chunks: Buffer[]): Buffer | null {
|
|
1697
|
-
if (chunks.length === 0)
|
|
2430
|
+
if (chunks.length === 0) {
|
|
2431
|
+
return null;
|
|
2432
|
+
}
|
|
1698
2433
|
|
|
1699
2434
|
const audio = Buffer.concat(chunks);
|
|
1700
2435
|
chunks.length = 0;
|
|
1701
2436
|
return audio.byteLength > 0 ? audio : null;
|
|
1702
2437
|
}
|
|
1703
2438
|
|
|
2439
|
+
// Duration (ms) of PCM16 mono audio: 2 bytes per sample.
|
|
2440
|
+
function pcm16DurationMs(byteLength: number, sampleRate: number): number {
|
|
2441
|
+
return (byteLength / 2 / sampleRate) * 1_000;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
1704
2444
|
function estimatePcmDurationMs(input: {
|
|
1705
2445
|
byteLength: number;
|
|
1706
2446
|
mimeType: string;
|
|
@@ -1714,10 +2454,7 @@ function estimatePcmDurationMs(input: {
|
|
|
1714
2454
|
return undefined;
|
|
1715
2455
|
}
|
|
1716
2456
|
|
|
1717
|
-
|
|
1718
|
-
return Math.round(
|
|
1719
|
-
(input.byteLength / (input.sampleRate * bytesPerMonoSample)) * 1000,
|
|
1720
|
-
);
|
|
2457
|
+
return Math.round(pcm16DurationMs(input.byteLength, input.sampleRate));
|
|
1721
2458
|
}
|
|
1722
2459
|
|
|
1723
2460
|
function unavailableTranscriberMessage(): string {
|
|
@@ -1731,7 +2468,9 @@ function unavailableTranscriberMessage(): string {
|
|
|
1731
2468
|
function stopTranscriberBestEffort(
|
|
1732
2469
|
transcriber: StreamingTranscriber | null,
|
|
1733
2470
|
): void {
|
|
1734
|
-
if (!transcriber)
|
|
2471
|
+
if (!transcriber) {
|
|
2472
|
+
return;
|
|
2473
|
+
}
|
|
1735
2474
|
|
|
1736
2475
|
try {
|
|
1737
2476
|
transcriber.stop();
|