@vellumai/assistant 0.11.6-dev.202608261630.6360d02 → 0.11.6-dev.202608261844.52da3d2

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.
Files changed (55) hide show
  1. package/ARCHITECTURE.md +26 -14
  2. package/docs/stt-provider-onboarding.md +8 -4
  3. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/ingress.test.ts +37 -0
  4. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/ingress.ts +22 -0
  5. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/ingress.test.ts +37 -0
  6. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/ingress.ts +22 -0
  7. package/node_modules/@vellumai/service-contracts/src/__tests__/ingress.test.ts +37 -0
  8. package/node_modules/@vellumai/service-contracts/src/ingress.ts +22 -0
  9. package/package.json +1 -1
  10. package/src/__tests__/llm-resolver.test.ts +54 -0
  11. package/src/__tests__/managed-speech-defaults.test.ts +64 -0
  12. package/src/__tests__/media-stream-stt-session.test.ts +2 -0
  13. package/src/__tests__/schedule-retry.test.ts +177 -4
  14. package/src/__tests__/scheduler-reuse-conversation.test.ts +6 -6
  15. package/src/calls/__tests__/telephony-synthesis-language.test.ts +81 -0
  16. package/src/calls/__tests__/voice-session-bridge.test.ts +20 -0
  17. package/src/calls/media-stream-stt-session.ts +2 -1
  18. package/src/calls/telephony-synthesis-language.ts +13 -5
  19. package/src/calls/voice-session-bridge.ts +6 -4
  20. package/src/config/bundled-skills/media-processing/services/audio-transcribe.ts +3 -1
  21. package/src/config/bundled-skills/media-processing/services/preprocess.ts +1 -1
  22. package/src/config/bundled-skills/phone-calls/SKILL.md +1 -1
  23. package/src/config/bundled-skills/phone-calls/references/CONFIG.md +16 -15
  24. package/src/config/bundled-skills/phone-calls/references/TROUBLESHOOTING.md +2 -1
  25. package/src/config/bundled-skills/transcribe/tools/transcribe-media.ts +1 -1
  26. package/src/config/default-profile-catalog.ts +1 -1
  27. package/src/config/llm-resolver.ts +24 -0
  28. package/src/config/managed-speech-defaults.ts +75 -18
  29. package/src/config/schemas/__tests__/stt.test.ts +94 -0
  30. package/src/config/schemas/stt.ts +99 -0
  31. package/src/daemon/handlers/config-ingress.ts +9 -0
  32. package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +42 -0
  33. package/src/live-voice/live-voice-credential-preflight.ts +5 -1
  34. package/src/live-voice/live-voice-session.ts +13 -3
  35. package/src/notifications/__tests__/activity-failed-dedupe.test.ts +161 -0
  36. package/src/notifications/activity-failed-dedupe.ts +95 -0
  37. package/src/plugin-api/transcription-session.ts +1 -1
  38. package/src/providers/opencode/client.ts +0 -1
  39. package/src/providers/speech-to-text/__tests__/resolve.test.ts +197 -0
  40. package/src/providers/speech-to-text/provider-catalog.ts +15 -1
  41. package/src/providers/speech-to-text/resolve.ts +55 -12
  42. package/src/runtime/__tests__/background-job-runner.test.ts +61 -3
  43. package/src/runtime/background-job-runner.ts +37 -9
  44. package/src/runtime/http-server.ts +12 -4
  45. package/src/runtime/routes/__tests__/ingress-status-routes.test.ts +2 -1
  46. package/src/runtime/routes/inbound-stages/transcribe-audio.ts +1 -1
  47. package/src/runtime/routes/ingress-status-routes.ts +2 -2
  48. package/src/runtime/routes/stt-routes.ts +7 -4
  49. package/src/runtime/routes/watch-routes.ts +9 -5
  50. package/src/schedule/retry-policy.ts +8 -8
  51. package/src/schedule/schedule-recovery.ts +0 -1
  52. package/src/schedule/scheduler.ts +83 -15
  53. package/src/stt/__tests__/roles.test.ts +152 -0
  54. package/src/stt/roles.ts +180 -0
  55. package/src/stt/stt-stream-session.ts +3 -2
package/ARCHITECTURE.md CHANGED
@@ -577,17 +577,29 @@ All guardian decisions for voice access requests flow through:
577
577
 
578
578
  Audio-to-text conversion occurs in six distinct runtime boundaries, each with its own provider model and adapter layer. The `services.stt` config block is the single source of truth for STT provider selection across assistant, client, live voice, and telephony boundaries.
579
579
 
580
+ **Per-consumer roles:** `services.stt.provider` (plus that provider's `services.stt.providers.<id>.model` family) is the global selection. `services.stt.roles.<role>` overrides it for one consumer, naming a `{provider, model?}` pair; an unset role falls back to the global. Roles exist because capability is per boundary while the global is not: the Flux family streams but has no batch endpoint, so a global set to it breaks file transcription and telephony at the same moment it improves live voice. A role names the consumer rather than the boundary, because one telephony call resolves a streaming transcriber and a batch fallback within the same session.
581
+
582
+ | Role | Consumers | Boundaries required |
583
+ | ----------- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
584
+ | `liveVoice` | `src/live-voice/live-voice-session.ts`, `src/live-voice/live-voice-credential-preflight.ts` | streaming |
585
+ | `telephony` | `src/calls/media-stream-stt-session.ts` (streaming dial and batch fallback) | streaming + batch + telephony |
586
+ | `dictation` | `/v1/stt/stream` (`src/runtime/http-server.ts`), `POST /v1/stt/transcribe`, `src/plugin-api/transcription-session.ts` | streaming + batch |
587
+ | `watch` | `/v1/watch/stream` (`src/runtime/routes/watch-routes.ts`) | streaming |
588
+ | `batch` | inbound audio (`routes/inbound-stages/transcribe-audio.ts`), `POST /v1/stt/transcribe-file`, media-processing/transcribe skills | batch |
589
+
590
+ Roles are defined in `src/stt/roles.ts`: `STT_ROLE_REQUIREMENTS` declares each role's boundaries, `sttSelectionForRole()`/`sttCatalogKeyForRole()` perform the lookup, and `sttRoleCapabilityGap()` states why a pair cannot serve a role. Selection is resolved inside `resolveBatchTranscriber()`/`resolveStreamingTranscriber()`, so a caller passes `role` and nothing else. Capability is checked against the **resolved catalog row** (`sttCatalogKeyFor(provider, model)`), not the bare provider id, since `deepgram` batches and `deepgram` running `flux` does not. Validation is fail-closed: `services.stt.roles` rejects an incapable pair at config parse time rather than substituting a working provider at dial time. Telephony and live-voice preflight, the dictation session label, and the telephony language pin all read their own role, so what preflight judges is what the session dials.
591
+
580
592
  **Provider catalog model:** The daemon's canonical provider catalog (`src/providers/speech-to-text/provider-catalog.ts`) is the single source of truth for all STT provider metadata — credential mappings, supported boundaries, telephony mode, conversation streaming mode, and client-facing display metadata (names, hints, setup mode, credentials guide). Native clients fetch provider metadata at launch via `GET /v1/stt/providers`. To add a new provider, follow the checklist in `docs/stt-provider-onboarding.md`.
581
593
 
582
594
  **Boundary overview:**
583
595
 
584
- | Boundary | Runtime | Provider (current) | Adapter module | Caller |
585
- | ---------------------------- | --------------------------------------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
586
- | **Telephony (media-stream)** | Daemon process (Twilio Media Streams WebSocket) | Configured STT provider (via `services.stt`) | `src/calls/media-stream-stt-session.ts`, `src/providers/speech-to-text/resolve.ts`, streaming provider adapters | `src/calls/media-stream-server.ts` |
587
- | **Daemon batch** | Daemon process (REST API to provider) | Configured STT provider (via `services.stt`) | `src/stt/daemon-batch-transcriber.ts` | `src/runtime/routes/inbound-stages/transcribe-audio.ts` |
588
- | **Conversation streaming** | Daemon process (WebSocket-based) | Configured STT provider (via `services.stt`) | `src/stt/stt-stream-session.ts`, `src/providers/speech-to-text/deepgram-realtime.ts`, `src/providers/speech-to-text/google-gemini-live-stream.ts`, `src/providers/speech-to-text/openai-whisper-stream.ts`, `src/providers/speech-to-text/xai-realtime.ts` | Web/Electron dictation client via gateway WS proxy |
589
- | **Live voice channel** | Assistant process (gateway-authenticated WebSocket) | Configured STT provider (via `services.stt`) | `src/runtime/http-server.ts`, `src/live-voice/live-voice-session-manager.ts`, `src/live-voice/live-voice-session.ts`, `src/providers/speech-to-text/resolve.ts`, streaming provider adapters | Web/Electron live voice client via `/v1/live-voice` |
590
- | **Client service-first** | Web/Electron via gateway → daemon | Configured STT provider (via `services.stt`) | `src/runtime/routes/stt-routes.ts` | Web/Electron dictation and voice clients |
596
+ | Boundary | Runtime | Provider (current) | Adapter module | Caller |
597
+ | ---------------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
598
+ | **Telephony (media-stream)** | Daemon process (Twilio Media Streams WebSocket) | `telephony` role, else `services.stt.provider` | `src/calls/media-stream-stt-session.ts`, `src/providers/speech-to-text/resolve.ts`, streaming provider adapters | `src/calls/media-stream-server.ts` |
599
+ | **Daemon batch** | Daemon process (REST API to provider) | `batch` role, else `services.stt.provider` | `src/stt/daemon-batch-transcriber.ts` | `src/runtime/routes/inbound-stages/transcribe-audio.ts` |
600
+ | **Conversation streaming** | Daemon process (WebSocket-based) | `dictation` role, else `services.stt.provider` | `src/stt/stt-stream-session.ts`, `src/providers/speech-to-text/deepgram-realtime.ts`, `src/providers/speech-to-text/google-gemini-live-stream.ts`, `src/providers/speech-to-text/openai-whisper-stream.ts`, `src/providers/speech-to-text/xai-realtime.ts` | Web/Electron dictation client via gateway WS proxy |
601
+ | **Live voice channel** | Assistant process (gateway-authenticated WebSocket) | `liveVoice` role, else `services.stt.provider` | `src/runtime/http-server.ts`, `src/live-voice/live-voice-session-manager.ts`, `src/live-voice/live-voice-session.ts`, `src/providers/speech-to-text/resolve.ts`, streaming provider adapters | Web/Electron live voice client via `/v1/live-voice` |
602
+ | **Client service-first** | Web/Electron via gateway → daemon | `dictation` (transcribe) / `batch` (transcribe-file) role, else `services.stt.provider` | `src/runtime/routes/stt-routes.ts` | Web/Electron dictation and voice clients |
591
603
 
592
604
  **Telephony boundary (media-stream):**
593
605
 
@@ -595,8 +607,8 @@ Every phone call connects over Twilio Media Streams: the voice webhook emits `<C
595
607
 
596
608
  Transcription mode is selected once per session in `media-stream-stt-session.ts`:
597
609
 
598
- - **Streaming** (default) — when `calls.voice.telephonyStreaming` is enabled and the configured provider resolves a streaming transcriber (`resolveStreamingTranscriber()`), inbound audio is decoded (mu-law → PCM16, resampled 8 kHz → 16 kHz) and fed to the provider's realtime adapter. Replies trigger only on utterance-boundary finals (for Deepgram, `speech_final`/`UtteranceEnd`, never mid-sentence `is_final` segments), and barge-in fires from local energy VAD, never from transcriber partials.
599
- - **Batch fallback** — otherwise the session segments turns with the energy-based `MediaTurnDetector` and transcribes each completed turn via the provider's batch API.
610
+ - **Streaming** (default): when `calls.voice.telephonyStreaming` is enabled and the `telephony` role resolves a streaming transcriber (`resolveStreamingTranscriber({ role: "telephony" })`), inbound audio is decoded (mu-law → PCM16, resampled 8 kHz → 16 kHz) and fed to the provider's realtime adapter. Replies trigger only on utterance-boundary finals (for Deepgram, `speech_final`/`UtteranceEnd`, never mid-sentence `is_final` segments), and barge-in fires from local energy VAD, never from transcriber partials.
611
+ - **Batch fallback**: otherwise the session segments turns with the energy-based `MediaTurnDetector` and transcribes each completed turn via the same role's batch API. Both halves of a call read the `telephony` role, which is why a role names its consumer rather than a boundary.
600
612
 
601
613
  A credential preflight (`resolveTelephonyCredentialReadiness()` in `src/calls/telephony-credential-preflight.ts`) gates every call: it requires a credentialed, telephony-capable STT provider **and** a media-stream-playable TTS provider (the configured one or a credentialed playable fallback). Inbound calls that fail the preflight receive `<Say>` setup-required copy plus `<Hangup/>` instead of a doomed stream; outbound placement fails before dialing via `preflightVoiceIngress()` with the same user-facing message.
602
614
 
@@ -632,7 +644,7 @@ To add a new daemon batch STT provider, follow the full checklist in `docs/stt-p
632
644
 
633
645
  **Conversation streaming boundary:**
634
646
 
635
- Real-time conversation chat message capture on macOS uses a WebSocket-based streaming STT path. When the configured `services.stt` provider supports conversation streaming (determined by the `conversationStreamingMode` field in the provider catalog), native clients open a WebSocket session through the gateway to the daemon's `/v1/stt/stream` endpoint. The daemon resolves a `StreamingTranscriber` for the configured provider and streams partial/final transcript events back to the client in real time.
647
+ Real-time conversation chat message capture on macOS uses a WebSocket-based streaming STT path. When the provider the `dictation` role resolves to supports conversation streaming (determined by the `conversationStreamingMode` field in the provider catalog), native clients open a WebSocket session through the gateway to the daemon's `/v1/stt/stream` endpoint. The daemon resolves a `StreamingTranscriber` for that provider and streams partial/final transcript events back to the client in real time.
636
648
 
637
649
  Each provider that advertises a conversation streaming mode in the catalog ships an adapter implementing the `StreamingTranscriber` interface from `src/stt/types.ts`. The catalog (`src/providers/speech-to-text/provider-catalog.ts`) is the source of truth for which providers are streaming-capable; `resolveStreamingTranscriber()` maps each to its adapter:
638
650
 
@@ -653,8 +665,8 @@ Each provider that advertises a conversation streaming mode in the catalog ships
653
665
 
654
666
  **Session lifecycle (daemon side):**
655
667
 
656
- 1. Client opens a WebSocket to `/v1/stt/stream` with required query parameter `mimeType` and optional `provider` and `sampleRate`. The `provider` parameter is optional compatibility metadata — the runtime is config-authoritative and always resolves the streaming transcriber from `services.stt.provider`. When a requested provider disagrees with the configured provider, the runtime logs a mismatch warning.
657
- 2. `SttStreamSession` (in `src/stt/stt-stream-session.ts`) resolves a `StreamingTranscriber` via `resolveStreamingTranscriber()` from `src/providers/speech-to-text/resolve.ts`, using the configured provider (not the requested one).
668
+ 1. Client opens a WebSocket to `/v1/stt/stream` with required query parameter `mimeType` and optional `provider` and `sampleRate`. The `provider` parameter is optional compatibility metadata: the runtime is config-authoritative and always resolves the streaming transcriber from the `dictation` role (`services.stt.roles.dictation`, else `services.stt.provider`). When a requested provider disagrees with the one that role resolves to, the runtime logs a mismatch warning.
669
+ 2. `SttStreamSession` (in `src/stt/stt-stream-session.ts`) resolves a `StreamingTranscriber` via `resolveStreamingTranscriber()` from `src/providers/speech-to-text/resolve.ts`, using the dictation role's provider (not the requested one).
658
670
  3. The transcriber's `start()` method opens the provider session.
659
671
  4. A `ready` event (with `provider` field) is sent to the client, signaling that audio frames are accepted.
660
672
  5. Client sends `audio` frames (binary WebSocket frames or base64-encoded JSON) and a `stop` event when recording ends.
@@ -725,7 +737,7 @@ V1 is local/gateway-scoped. Managed/cloud WebSocket proxy support, cross-region
725
737
 
726
738
  **Client service-first boundary:**
727
739
 
728
- All product-facing dictation and voice-streaming paths use a service-first STT strategy. Clients record audio, encode it to WAV, and POST it through the gateway to the daemon's `POST /v1/stt/transcribe` endpoint. The daemon resolves the configured STT provider through `resolveBatchTranscriber()` and returns the transcribed text.
740
+ All product-facing dictation and voice-streaming paths use a service-first STT strategy. Clients record audio, encode it to WAV, and POST it through the gateway to the daemon's `POST /v1/stt/transcribe` endpoint. The daemon resolves the `dictation` role's provider through `resolveBatchTranscriber()` and returns the transcribed text. `POST /v1/stt/transcribe-file` resolves the `batch` role the same way.
729
741
 
730
742
  - The client receives a typed result distinguishing success from `notConfigured`, `serviceUnavailable`, and `error`, so callers can deterministically trigger their fallback path.
731
743
  - The gateway proxies the request via assistant-scoped path rewriting: `/v1/assistants/:id/stt/transcribe` is rewritten to `/v1/stt/transcribe` on the daemon.
@@ -735,7 +747,7 @@ The web client implements these flows in `clients/web/src/domains/chat/voice/`:
735
747
 
736
748
  **Cross-boundary notes:**
737
749
 
738
- - The `services.stt` config block is the single source of truth for STT provider selection across the daemon batch boundary, the conversation streaming boundary, the client service-first boundary, and the telephony boundary. The batch and streaming resolvers (`resolveBatchTranscriber()`, `resolveStreamingTranscriber()`) both read from `services.stt.provider` and resolve credentials through the same catalog; the telephony boundary's media-stream STT session uses these same resolvers — it selects streaming vs batch transcription via `resolveStreamingTranscriber()`/`resolveBatchTranscriber()` under the `calls.voice.telephonyStreaming` flag, gated by `resolveTelephonySttCapability()`, while call placement/TwiML is gated by `resolveTelephonyCredentialReadiness()`. The daemon provider catalog (`src/providers/speech-to-text/provider-catalog.ts`) is the authoritative registry of supported providers. Native clients fetch display metadata via `GET /v1/stt/providers`.
750
+ - The `services.stt` config block is the single source of truth for STT provider selection across the daemon batch boundary, the conversation streaming boundary, the client service-first boundary, and the telephony boundary. The batch and streaming resolvers (`resolveBatchTranscriber()`, `resolveStreamingTranscriber()`) both read it, taking the caller's `role` override (`services.stt.roles.<role>`) when one is set and the global `services.stt.provider` otherwise, and resolve credentials through the same catalog; the telephony boundary's media-stream STT session uses these same resolvers, selecting streaming vs batch transcription via `resolveStreamingTranscriber()`/`resolveBatchTranscriber()` under the `calls.voice.telephonyStreaming` flag, gated by `resolveTelephonySttCapability()`, while call placement/TwiML is gated by `resolveTelephonyCredentialReadiness()`. The daemon provider catalog (`src/providers/speech-to-text/provider-catalog.ts`) is the authoritative registry of supported providers. Native clients fetch display metadata via `GET /v1/stt/providers`.
739
751
  - **Spoken language** is a second axis on the same block: `services.stt.language` is read by `resolveStreamingTranscriber()` and `resolveBatchTranscriber()` and forwarded to the adapters that accept one (Deepgram, xAI, and the managed relay, which passes it to Deepgram server-side). Callers may override it per streaming session, but none need to: reading it in the resolvers means every boundary inherits the setting. Gemini and Whisper take no language option and auto-detect natively, so they ignore it. Leaving it unset is **not** auto-detection on Deepgram or the managed relay: Deepgram's default is English, so non-English speech transcribes as English-sounding nonsense. `"multi"` selects nova-3 code-switching across English, Spanish, French, German, Hindi, Russian, Portuguese, Japanese, Italian, and Dutch, the mode to use when a speaker mixes languages inside one utterance. BYOK Deepgram pins `model=nova-3` for **any** explicitly configured language, not just `"multi"`: the curated roster is verified against nova-3 (the default nova-2 supports only a subset, and rejects `"multi"` outright), and `deepgramLanguageOptions()` owns the model+language pairing so every call site inherits the rule; leaving the language unset keeps the adapter default model with no language param. `"multi"` is never forwarded to xAI (it is not a BCP-47 code; xAI auto-handles multilingual audio). The managed relay pins nova-3 and allowlists `language`, so streaming needs no platform-side change; managed **batch** goes through the platform speech proxy, which accepts no language parameter, so forwarding it there is deferred pending a platform-side change.
740
752
  - Conversation streaming does not replace the client service-first batch path. When streaming is available, it runs concurrently during recording and provides real-time partials and finals. The batch path remains the fallback for providers that do not support streaming, when streaming fails mid-session, or when streaming produces no final transcript.
741
753
  - Credential mapping is catalog-driven: `provider-secret-catalog.ts` derives STT API-key provider names from the daemon catalog via `listCredentialProviderNames()`, deduplicating against the LLM/search provider list. Adding a provider to the catalog automatically includes its credential name in `API_KEY_PROVIDERS`.
@@ -29,7 +29,7 @@ This ensures the exhaustive switch in `daemon-batch-transcriber.ts` produces a c
29
29
 
30
30
  - Append the new provider ID string to the `VALID_STT_PROVIDERS` tuple.
31
31
 
32
- The `services.stt.providers` map uses a sparse `z.record(z.string(), ...)` schema, so adding a new provider does **not** require a workspace migration to seed a `services.stt.providers.<id>` entry. Users only need to set `services.stt.provider` to the new ID and supply credentials.
32
+ The `services.stt.providers` map uses a sparse `z.record(z.string(), ...)` schema, so adding a new provider does **not** require a workspace migration to seed a `services.stt.providers.<id>` entry. Users only need to set `services.stt.provider` (or a single consumer's `services.stt.roles.<role>`, see step 7) to the new ID and supply credentials.
33
33
 
34
34
  **Language handling.** `services.stt.language` is resolved centrally in `resolveStreamingTranscriber()` (and in `resolveBatchTranscriber()` for the daemon-batch boundary), so a new adapter inherits it for free: accept a `language` option in the adapter's constructor and forward it to the provider. If the provider auto-detects natively and has no language parameter (as Gemini and Whisper do), accept nothing and let the resolver's value be ignored; document that choice in the adapter, because "no language param" means auto-detect for some providers and _English_ for others (Deepgram), and that difference is an easy source of silent wrong-language transcription. A provider that supports both batch and streaming must forward the language on **both** paths, not just the streaming one.
35
35
 
@@ -84,12 +84,16 @@ Clients derive shared-vs-exclusive key behavior from the catalog automatically:
84
84
 
85
85
  ## 7. Verify unified STT architecture
86
86
 
87
- `services.stt.provider` is the single source of truth for all STT routing, including telephony. There is no separate telephony STT config path.
87
+ The `services.stt` block is the single source of truth for all STT routing, including telephony. There is no separate telephony STT config path.
88
+
89
+ Routing has two levels. `services.stt.provider`, plus that provider's `services.stt.providers.<id>.model` family, is the global selection every consumer falls back to. `services.stt.roles.<role>` overrides it for one consumer, naming a `{provider, model?}` pair. The roles are `liveVoice`, `telephony`, `dictation`, `watch` and `batch`; `src/stt/roles.ts` maps each to the boundaries its call sites resolve on, and `ARCHITECTURE.md` lists the consumers per role. A new provider needs no per-role registration: a role may name any provider in the catalog whose row covers the boundaries that role requires.
88
90
 
89
91
  Before submitting the PR, verify that:
90
92
 
91
- 1. **No stale config references** — grep for any references to a separate telephony transcription config. Telephony transcription runs daemon-side over the Twilio media-stream transport (`src/calls/media-stream-stt-session.ts`), which reads `services.stt.provider` like every other boundary.
93
+ 1. **No stale config references**: grep for any references to a separate telephony transcription config. Telephony transcription runs daemon-side over the Twilio media-stream transport (`src/calls/media-stream-stt-session.ts`), which resolves through `resolveStreamingTranscriber()`/`resolveBatchTranscriber()` under the `telephony` role like every other boundary resolves under its own.
92
94
 
93
95
  2. **Provider catalog telephony metadata** — the new provider's catalog entry (step 1) declares `telephonyMode` and `supportedBoundaries`; these are the single source of truth for the telephony capability check (`resolveTelephonySttCapability()`) and for streaming-vs-batch mode selection in the media-stream STT session. No per-provider routing maps exist.
94
96
 
95
- 3. **No duplicate wiring** — a provider should appear only once in `services.stt`. The telephony layer consumes the same provider ID; there is no second registration step for telephony.
97
+ 3. **Role capability follows the catalog row**: `sttRoleCapabilityGap()` reads `supportedBoundaries` and `telephonyMode` from the row the pair resolves to (`sttCatalogKeyFor(provider, model)`), so a model family that drops a boundary must be its own catalog row. Get the row right and config validation rejects incapable role pairs on its own; nothing per-role needs writing.
98
+
99
+ 4. **No duplicate wiring**: a provider should appear only once in `services.stt`. The telephony layer consumes the same catalog, and a role selects from it; there is no second registration step for telephony or for any role.
@@ -6,8 +6,10 @@ import {
6
6
  normalizePublicBaseUrl,
7
7
  parseRecordedAssistantId,
8
8
  parseTunnelRecord,
9
+ selectRestartTunnelRecord,
9
10
  trimmedNonEmptyString,
10
11
  TUNNEL_PROVIDERS,
12
+ type TunnelRecord,
11
13
  velayHostForPlatformHost,
12
14
  } from "../ingress.js";
13
15
  import {
@@ -221,6 +223,41 @@ describe("parseTunnelRecord", () => {
221
223
  });
222
224
  });
223
225
 
226
+ describe("selectRestartTunnelRecord", () => {
227
+ const PAIRING: TunnelRecord = {
228
+ provider: "tailscale",
229
+ publicBaseUrl: "https://assistant-1.example.ts.net",
230
+ };
231
+ const LAST: TunnelRecord = {
232
+ provider: "ngrok",
233
+ publicBaseUrl: "https://assistant-1.ngrok.app",
234
+ };
235
+
236
+ test("prefers the pairing tunnel over the last one that ran", () => {
237
+ // The pairing tunnel deliberately left the older public record beside it,
238
+ // so naming that one would point at an ingress nobody is using.
239
+ expect(
240
+ selectRestartTunnelRecord({ lastTunnel: LAST, pairingTunnel: PAIRING }),
241
+ ).toEqual(PAIRING);
242
+ });
243
+
244
+ test("falls back to the last tunnel and to null", () => {
245
+ expect(selectRestartTunnelRecord({ lastTunnel: LAST })).toEqual(LAST);
246
+ for (const ingress of [undefined, null, {}, "nonsense", 42]) {
247
+ expect(selectRestartTunnelRecord(ingress)).toBeNull();
248
+ }
249
+ });
250
+
251
+ test("skips a malformed pairing record for a usable last one", () => {
252
+ expect(
253
+ selectRestartTunnelRecord({
254
+ lastTunnel: LAST,
255
+ pairingTunnel: { provider: "wireguard", publicBaseUrl: "nope" },
256
+ }),
257
+ ).toEqual(LAST);
258
+ });
259
+ });
260
+
224
261
  describe("trimmedNonEmptyString", () => {
225
262
  test("trims and rejects blank or non-string values", () => {
226
263
  expect(trimmedNonEmptyString(" assistant-1 ")).toBe("assistant-1");
@@ -147,6 +147,28 @@ export function parseTunnelRecord(value: unknown): TunnelRecord | null {
147
147
  return { provider, publicBaseUrl: normalized };
148
148
  }
149
149
 
150
+ /**
151
+ * The tunnel a reader should offer to restart, given an `ingress` section, or
152
+ * null when it records none.
153
+ *
154
+ * A pairing-only record wins: it is written by a tunnel that deliberately left
155
+ * `publicBaseUrl` (and the `lastTunnel` beside it) pointing at an older public
156
+ * provider, so naming that older one would send the user to rebuild an ingress
157
+ * they are not using instead of the tunnel actually in front of them.
158
+ */
159
+ export function selectRestartTunnelRecord(
160
+ ingress: unknown,
161
+ ): TunnelRecord | null {
162
+ if (typeof ingress !== "object" || ingress === null) {
163
+ return null;
164
+ }
165
+ const section = ingress as Record<string, unknown>;
166
+ return (
167
+ parseTunnelRecord(section[INGRESS_PAIRING_TUNNEL_KEY]) ??
168
+ parseTunnelRecord(section[INGRESS_LAST_TUNNEL_KEY])
169
+ );
170
+ }
171
+
150
172
  /** Parse an `ingress.assistantId` value, or null when it is absent or blank. */
151
173
  export function parseRecordedAssistantId(value: unknown): string | null {
152
174
  return trimmedNonEmptyString(value) ?? null;
@@ -6,8 +6,10 @@ import {
6
6
  normalizePublicBaseUrl,
7
7
  parseRecordedAssistantId,
8
8
  parseTunnelRecord,
9
+ selectRestartTunnelRecord,
9
10
  trimmedNonEmptyString,
10
11
  TUNNEL_PROVIDERS,
12
+ type TunnelRecord,
11
13
  velayHostForPlatformHost,
12
14
  } from "../ingress.js";
13
15
  import {
@@ -221,6 +223,41 @@ describe("parseTunnelRecord", () => {
221
223
  });
222
224
  });
223
225
 
226
+ describe("selectRestartTunnelRecord", () => {
227
+ const PAIRING: TunnelRecord = {
228
+ provider: "tailscale",
229
+ publicBaseUrl: "https://assistant-1.example.ts.net",
230
+ };
231
+ const LAST: TunnelRecord = {
232
+ provider: "ngrok",
233
+ publicBaseUrl: "https://assistant-1.ngrok.app",
234
+ };
235
+
236
+ test("prefers the pairing tunnel over the last one that ran", () => {
237
+ // The pairing tunnel deliberately left the older public record beside it,
238
+ // so naming that one would point at an ingress nobody is using.
239
+ expect(
240
+ selectRestartTunnelRecord({ lastTunnel: LAST, pairingTunnel: PAIRING }),
241
+ ).toEqual(PAIRING);
242
+ });
243
+
244
+ test("falls back to the last tunnel and to null", () => {
245
+ expect(selectRestartTunnelRecord({ lastTunnel: LAST })).toEqual(LAST);
246
+ for (const ingress of [undefined, null, {}, "nonsense", 42]) {
247
+ expect(selectRestartTunnelRecord(ingress)).toBeNull();
248
+ }
249
+ });
250
+
251
+ test("skips a malformed pairing record for a usable last one", () => {
252
+ expect(
253
+ selectRestartTunnelRecord({
254
+ lastTunnel: LAST,
255
+ pairingTunnel: { provider: "wireguard", publicBaseUrl: "nope" },
256
+ }),
257
+ ).toEqual(LAST);
258
+ });
259
+ });
260
+
224
261
  describe("trimmedNonEmptyString", () => {
225
262
  test("trims and rejects blank or non-string values", () => {
226
263
  expect(trimmedNonEmptyString(" assistant-1 ")).toBe("assistant-1");
@@ -147,6 +147,28 @@ export function parseTunnelRecord(value: unknown): TunnelRecord | null {
147
147
  return { provider, publicBaseUrl: normalized };
148
148
  }
149
149
 
150
+ /**
151
+ * The tunnel a reader should offer to restart, given an `ingress` section, or
152
+ * null when it records none.
153
+ *
154
+ * A pairing-only record wins: it is written by a tunnel that deliberately left
155
+ * `publicBaseUrl` (and the `lastTunnel` beside it) pointing at an older public
156
+ * provider, so naming that older one would send the user to rebuild an ingress
157
+ * they are not using instead of the tunnel actually in front of them.
158
+ */
159
+ export function selectRestartTunnelRecord(
160
+ ingress: unknown,
161
+ ): TunnelRecord | null {
162
+ if (typeof ingress !== "object" || ingress === null) {
163
+ return null;
164
+ }
165
+ const section = ingress as Record<string, unknown>;
166
+ return (
167
+ parseTunnelRecord(section[INGRESS_PAIRING_TUNNEL_KEY]) ??
168
+ parseTunnelRecord(section[INGRESS_LAST_TUNNEL_KEY])
169
+ );
170
+ }
171
+
150
172
  /** Parse an `ingress.assistantId` value, or null when it is absent or blank. */
151
173
  export function parseRecordedAssistantId(value: unknown): string | null {
152
174
  return trimmedNonEmptyString(value) ?? null;
@@ -6,8 +6,10 @@ import {
6
6
  normalizePublicBaseUrl,
7
7
  parseRecordedAssistantId,
8
8
  parseTunnelRecord,
9
+ selectRestartTunnelRecord,
9
10
  trimmedNonEmptyString,
10
11
  TUNNEL_PROVIDERS,
12
+ type TunnelRecord,
11
13
  velayHostForPlatformHost,
12
14
  } from "../ingress.js";
13
15
  import {
@@ -221,6 +223,41 @@ describe("parseTunnelRecord", () => {
221
223
  });
222
224
  });
223
225
 
226
+ describe("selectRestartTunnelRecord", () => {
227
+ const PAIRING: TunnelRecord = {
228
+ provider: "tailscale",
229
+ publicBaseUrl: "https://assistant-1.example.ts.net",
230
+ };
231
+ const LAST: TunnelRecord = {
232
+ provider: "ngrok",
233
+ publicBaseUrl: "https://assistant-1.ngrok.app",
234
+ };
235
+
236
+ test("prefers the pairing tunnel over the last one that ran", () => {
237
+ // The pairing tunnel deliberately left the older public record beside it,
238
+ // so naming that one would point at an ingress nobody is using.
239
+ expect(
240
+ selectRestartTunnelRecord({ lastTunnel: LAST, pairingTunnel: PAIRING }),
241
+ ).toEqual(PAIRING);
242
+ });
243
+
244
+ test("falls back to the last tunnel and to null", () => {
245
+ expect(selectRestartTunnelRecord({ lastTunnel: LAST })).toEqual(LAST);
246
+ for (const ingress of [undefined, null, {}, "nonsense", 42]) {
247
+ expect(selectRestartTunnelRecord(ingress)).toBeNull();
248
+ }
249
+ });
250
+
251
+ test("skips a malformed pairing record for a usable last one", () => {
252
+ expect(
253
+ selectRestartTunnelRecord({
254
+ lastTunnel: LAST,
255
+ pairingTunnel: { provider: "wireguard", publicBaseUrl: "nope" },
256
+ }),
257
+ ).toEqual(LAST);
258
+ });
259
+ });
260
+
224
261
  describe("trimmedNonEmptyString", () => {
225
262
  test("trims and rejects blank or non-string values", () => {
226
263
  expect(trimmedNonEmptyString(" assistant-1 ")).toBe("assistant-1");
@@ -147,6 +147,28 @@ export function parseTunnelRecord(value: unknown): TunnelRecord | null {
147
147
  return { provider, publicBaseUrl: normalized };
148
148
  }
149
149
 
150
+ /**
151
+ * The tunnel a reader should offer to restart, given an `ingress` section, or
152
+ * null when it records none.
153
+ *
154
+ * A pairing-only record wins: it is written by a tunnel that deliberately left
155
+ * `publicBaseUrl` (and the `lastTunnel` beside it) pointing at an older public
156
+ * provider, so naming that older one would send the user to rebuild an ingress
157
+ * they are not using instead of the tunnel actually in front of them.
158
+ */
159
+ export function selectRestartTunnelRecord(
160
+ ingress: unknown,
161
+ ): TunnelRecord | null {
162
+ if (typeof ingress !== "object" || ingress === null) {
163
+ return null;
164
+ }
165
+ const section = ingress as Record<string, unknown>;
166
+ return (
167
+ parseTunnelRecord(section[INGRESS_PAIRING_TUNNEL_KEY]) ??
168
+ parseTunnelRecord(section[INGRESS_LAST_TUNNEL_KEY])
169
+ );
170
+ }
171
+
150
172
  /** Parse an `ingress.assistantId` value, or null when it is absent or blank. */
151
173
  export function parseRecordedAssistantId(value: unknown): string | null {
152
174
  return trimmedNonEmptyString(value) ?? null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.6-dev.202608261630.6360d02",
3
+ "version": "0.11.6-dev.202608261844.52da3d2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,6 +9,7 @@ import {
9
9
  resolveCallSiteConfigWithProfile,
10
10
  resolveDefaultProfileKey,
11
11
  resolveEffectiveProfileKey,
12
+ resolveSingleRouteProfileKey,
12
13
  } from "../config/llm-resolver.js";
13
14
  import { type LLMCallSite, LLMSchema } from "../config/schemas/llm.js";
14
15
  import { resolveModelIntent } from "../providers/model-intents.js";
@@ -889,6 +890,59 @@ describe("mix profiles", () => {
889
890
  );
890
891
  });
891
892
 
893
+ test("resolveSingleRouteProfileKey names standard winners and refuses mixes", () => {
894
+ // The mix's arm is picked per conversation and can differ from any
895
+ // post-hoc recomputation, so the outer mix key must never be used as a
896
+ // single-route attribution scope.
897
+ expect(resolveSingleRouteProfileKey("mainAgent", mixLlm)).toBeUndefined();
898
+ expect(
899
+ resolveSingleRouteProfileKey("mainAgent", mixLlm, {
900
+ overrideProfile: "a",
901
+ }),
902
+ ).toBe("a");
903
+ // An unusable override falls through to the active mix, which still
904
+ // refuses to name a route.
905
+ expect(
906
+ resolveSingleRouteProfileKey("mainAgent", mixLlm, {
907
+ overrideProfile: "no-such-profile",
908
+ }),
909
+ ).toBeUndefined();
910
+ });
911
+
912
+ test("resolveSingleRouteProfileKey honors the dispatch resolvability predicate", () => {
913
+ // A pin whose provider dispatch cannot resolve (e.g. a force-deleted
914
+ // connection) must not be claimed as a scope: selection falls through to
915
+ // the active mix exactly as dispatch does, which then refuses to name a
916
+ // route. Without the predicate the stale pin still wins the chain, which
917
+ // is why scope callers must pass dispatch's predicate.
918
+ const staleLlm = LLMSchema.parse({
919
+ profiles: {
920
+ a: { provider: "anthropic", model: "model-a" },
921
+ b: { provider: "anthropic", model: "model-b" },
922
+ stale: { provider: "openai", model: "model-s" },
923
+ ab: {
924
+ mix: [
925
+ { profile: "a", weight: 1 },
926
+ { profile: "b", weight: 1 },
927
+ ],
928
+ },
929
+ },
930
+ activeProfile: "ab",
931
+ });
932
+ const openaiForceDeleted = (provider: string) => provider !== "openai";
933
+ expect(
934
+ resolveSingleRouteProfileKey("mainAgent", staleLlm, {
935
+ overrideProfile: "stale",
936
+ isResolvableProvider: openaiForceDeleted,
937
+ }),
938
+ ).toBeUndefined();
939
+ expect(
940
+ resolveSingleRouteProfileKey("mainAgent", staleLlm, {
941
+ overrideProfile: "stale",
942
+ }),
943
+ ).toBe("stale");
944
+ });
945
+
892
946
  test("all dereference spots in a turn agree for the same seed", () => {
893
947
  // mainAgent (mix as activeProfile) and a non-main call site resolving the
894
948
  // same mix as its call-site profile must pick the same arm when given the
@@ -27,6 +27,7 @@ mock.module("../calls/telephony-tts-capability.js", () => ({
27
27
 
28
28
  import { getConfig, invalidateConfigCache } from "../config/loader.js";
29
29
  import { maybeDefaultSpeechToManaged } from "../config/managed-speech-defaults.js";
30
+ import { sttCatalogKeyForRole } from "../stt/roles.js";
30
31
 
31
32
  const WORKSPACE_DIR = process.env.VELLUM_WORKSPACE_DIR!;
32
33
  const CONFIG_PATH = join(WORKSPACE_DIR, "config.json");
@@ -115,6 +116,69 @@ describe("maybeDefaultSpeechToManaged", () => {
115
116
  });
116
117
  });
117
118
 
119
+ test("a narrowing stand-in is written to the live-voice role, not the global", async () => {
120
+ // BYOK Flux with no key: the stand-in preserves turn detection, so it is
121
+ // vellum-flux, which streams and nothing else. Writing that globally is
122
+ // how batch transcription and telephony disappear for a managed user.
123
+ mockManagedSpeechAvailable = true;
124
+ writeConfig({
125
+ services: {
126
+ stt: {
127
+ provider: "deepgram",
128
+ providers: { deepgram: { model: "flux" } },
129
+ },
130
+ tts: { provider: "vellum" },
131
+ },
132
+ });
133
+
134
+ await maybeDefaultSpeechToManaged();
135
+
136
+ const stt = (readConfig().services as any).stt;
137
+ expect(stt.roles.liveVoice).toEqual({ provider: "vellum", model: "flux" });
138
+ // The other consumers land on the stand-in's base, which serves them all.
139
+ expect(stt.provider).toBe("vellum");
140
+ expect(stt.providers.vellum.model).toBe("nova-3");
141
+ });
142
+
143
+ test("the role write leaves batch and telephony on a provider that answers", async () => {
144
+ mockManagedSpeechAvailable = true;
145
+ writeConfig({
146
+ services: {
147
+ stt: {
148
+ provider: "deepgram",
149
+ providers: { deepgram: { model: "flux" } },
150
+ },
151
+ tts: { provider: "vellum" },
152
+ },
153
+ });
154
+
155
+ await maybeDefaultSpeechToManaged();
156
+
157
+ invalidateConfigCache();
158
+ const stt = getConfig().services.stt;
159
+ expect(sttCatalogKeyForRole(stt, "liveVoice")).toBe("vellum-flux");
160
+ expect(sttCatalogKeyForRole(stt, "batch")).toBe("vellum");
161
+ expect(sttCatalogKeyForRole(stt, "telephony")).toBe("vellum");
162
+ });
163
+
164
+ test("a capability-preserving stand-in still writes the global provider", async () => {
165
+ // Plain deepgram has no turn detection, so the stand-in is plain vellum,
166
+ // which serves every role. That one belongs on the global, not a role.
167
+ mockManagedSpeechAvailable = true;
168
+ writeConfig({
169
+ services: {
170
+ stt: { provider: "deepgram" },
171
+ tts: { provider: "vellum" },
172
+ },
173
+ });
174
+
175
+ await maybeDefaultSpeechToManaged();
176
+
177
+ const stt = (readConfig().services as any).stt;
178
+ expect(stt.provider).toBe("vellum");
179
+ expect(stt.roles).toBeUndefined();
180
+ });
181
+
118
182
  test("never repoints an explicit BYOK provider with resolving credentials", async () => {
119
183
  mockManagedSpeechAvailable = true;
120
184
  mockSttKeyResolves = true;
@@ -774,6 +774,7 @@ describe("MediaStreamSttSession", () => {
774
774
 
775
775
  expect(resolveStreamingTranscriber).toHaveBeenCalledTimes(1);
776
776
  expect(resolveStreamingTranscriber).toHaveBeenCalledWith({
777
+ role: "telephony",
777
778
  sampleRate: 16_000,
778
779
  utteranceBoundaryFinals: true,
779
780
  utteranceEndMs: 1000,
@@ -787,6 +788,7 @@ describe("MediaStreamSttSession", () => {
787
788
  const { session } = await startStreamingSession();
788
789
 
789
790
  expect(resolveStreamingTranscriber).toHaveBeenCalledWith({
791
+ role: "telephony",
790
792
  sampleRate: 16_000,
791
793
  utteranceBoundaryFinals: true,
792
794
  utteranceEndMs: 2500,