@vellumai/assistant 0.10.4-dev.202607022130.febf41d → 0.10.4-dev.202607022227.14c7770

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 (117) hide show
  1. package/ARCHITECTURE.md +45 -39
  2. package/README.md +1 -1
  3. package/docs/stt-provider-onboarding.md +4 -5
  4. package/docs/trusted-contact-access.md +3 -3
  5. package/node_modules/@vellumai/service-contracts/src/__tests__/ingress.test.ts +0 -8
  6. package/node_modules/@vellumai/service-contracts/src/twilio-ingress.ts +3 -14
  7. package/openapi.yaml +3 -10
  8. package/package.json +1 -1
  9. package/src/__tests__/assistant-id-boundary-guard.test.ts +0 -1
  10. package/src/__tests__/btw-routes.test.ts +57 -3
  11. package/src/__tests__/call-controller.test.ts +182 -49
  12. package/src/__tests__/call-domain.test.ts +48 -1
  13. package/src/__tests__/call-pointer-no-hardcoded-copy.guard.test.ts +2 -6
  14. package/src/__tests__/call-routes-http.test.ts +15 -14
  15. package/src/__tests__/call-setup-flow-invite.test.ts +568 -0
  16. package/src/__tests__/call-setup-flow-midcall-trust.test.ts +231 -0
  17. package/src/__tests__/call-setup-flow-name-capture.test.ts +754 -0
  18. package/src/__tests__/call-setup-flow-verification.test.ts +925 -0
  19. package/src/__tests__/call-setup-flow.test.ts +311 -0
  20. package/src/__tests__/config-schema.test.ts +17 -0
  21. package/src/__tests__/credential-security-invariants.test.ts +1 -0
  22. package/src/__tests__/deterministic-verification-control-plane.test.ts +1 -62
  23. package/src/__tests__/empty-state-greeting-cache.test.ts +9 -0
  24. package/src/__tests__/gateway-only-enforcement.test.ts +15 -110
  25. package/src/__tests__/guardian-verification-voice-binding.test.ts +1 -1
  26. package/src/__tests__/guardian-wait-controller.test.ts +619 -0
  27. package/src/__tests__/job-handler-registration-guard.test.ts +104 -0
  28. package/src/__tests__/media-stream-audio-transcode.test.ts +113 -0
  29. package/src/__tests__/media-stream-output.test.ts +350 -19
  30. package/src/__tests__/media-stream-server-integration.test.ts +943 -169
  31. package/src/__tests__/media-stream-stt-session.test.ts +498 -1
  32. package/src/__tests__/memory-jobs-worker-lanes.test.ts +2 -2
  33. package/src/__tests__/plugin-import-boundary-guard.test.ts +6 -1
  34. package/src/__tests__/public-ingress-urls.test.ts +0 -48
  35. package/src/__tests__/stt-hints.test.ts +2 -254
  36. package/src/__tests__/telephony-credential-preflight.test.ts +312 -0
  37. package/src/__tests__/telephony-tts-guard.test.ts +538 -0
  38. package/src/__tests__/twilio-provider.test.ts +17 -17
  39. package/src/__tests__/twilio-routes-twiml.test.ts +6 -543
  40. package/src/__tests__/twilio-routes.test.ts +257 -387
  41. package/src/__tests__/twilio-validation.test.ts +1 -1
  42. package/src/__tests__/voice-ingress-preflight.test.ts +61 -0
  43. package/src/__tests__/voice-quality.test.ts +2 -2
  44. package/src/approvals/guardian-request-resolvers.ts +1 -1
  45. package/src/calls/__tests__/fish-audio-client.test.ts +73 -0
  46. package/src/calls/call-controller.ts +66 -47
  47. package/src/calls/call-domain.ts +18 -42
  48. package/src/calls/call-pointer-messages.ts +18 -0
  49. package/src/calls/call-setup-flow-types.ts +76 -0
  50. package/src/calls/call-setup-flow.ts +1743 -0
  51. package/src/calls/call-speech-output.ts +87 -23
  52. package/src/calls/call-transport.ts +22 -36
  53. package/src/calls/fish-audio-client.ts +3 -0
  54. package/src/calls/guardian-wait-controller.ts +451 -0
  55. package/src/calls/media-stream-audio-transcode.ts +82 -2
  56. package/src/calls/media-stream-output.ts +142 -36
  57. package/src/calls/media-stream-server.ts +291 -183
  58. package/src/calls/media-stream-stt-session.ts +393 -50
  59. package/src/calls/media-turn-detector.ts +4 -6
  60. package/src/calls/relay-access-wait.ts +3 -4
  61. package/src/calls/relay-setup-router.ts +6 -6
  62. package/src/calls/relay-verification.ts +4 -4
  63. package/src/calls/resolve-call-tts-provider.ts +96 -29
  64. package/src/calls/stt-hints.ts +24 -87
  65. package/src/calls/telephony-credential-preflight.ts +159 -0
  66. package/src/calls/telephony-tts-capability.ts +183 -0
  67. package/src/calls/tts-call-strategy.ts +18 -20
  68. package/src/calls/twilio-provider.ts +3 -2
  69. package/src/calls/twilio-routes.ts +47 -351
  70. package/src/calls/types.ts +5 -3
  71. package/src/calls/voice-ingress-preflight.ts +9 -0
  72. package/src/calls/voice-quality.ts +13 -18
  73. package/src/calls/voice-session-bridge.ts +4 -4
  74. package/src/channels/channel-verification-sessions.ts +1 -1
  75. package/src/config/bundled-skills/phone-calls/SKILL.md +1 -1
  76. package/src/config/bundled-skills/phone-calls/references/CONFIG.md +9 -9
  77. package/src/config/bundled-skills/phone-calls/references/TROUBLESHOOTING.md +10 -7
  78. package/src/config/schemas/calls.ts +8 -0
  79. package/src/config/schemas/elevenlabs.ts +1 -1
  80. package/src/daemon/external-plugins-bootstrap.ts +4 -23
  81. package/src/daemon/lifecycle.ts +5 -14
  82. package/src/inbound/public-ingress-urls.ts +0 -17
  83. package/src/jobs/worker.ts +9 -2
  84. package/src/persistence/migrations/028-call-session-mode.ts +1 -1
  85. package/src/plugins/defaults/index.ts +1 -29
  86. package/src/plugins/defaults/memory/__tests__/jobs-worker-v2-graph-trigger-embed.test.ts +2 -2
  87. package/src/plugins/defaults/memory/hooks/init.ts +30 -4
  88. package/src/plugins/defaults/memory/job-handler-registration.ts +96 -0
  89. package/src/plugins/defaults/memory/job-handlers.ts +5 -6
  90. package/src/plugins/defaults/memory/startup.ts +15 -10
  91. package/src/plugins/types.ts +6 -16
  92. package/src/providers/inference/__tests__/base-url-route-validation.test.ts +96 -1
  93. package/src/providers/speech-to-text/__tests__/provider-catalog.test.ts +0 -64
  94. package/src/providers/speech-to-text/__tests__/resolve.test.ts +92 -79
  95. package/src/providers/speech-to-text/deepgram-realtime.test.ts +98 -0
  96. package/src/providers/speech-to-text/deepgram-realtime.ts +62 -3
  97. package/src/providers/speech-to-text/provider-catalog.ts +0 -89
  98. package/src/providers/speech-to-text/resolve.ts +55 -0
  99. package/src/runtime/http-server.ts +32 -97
  100. package/src/runtime/middleware/twilio-validation.ts +5 -7
  101. package/src/runtime/routes/btw-routes.ts +32 -4
  102. package/src/runtime/routes/empty-state-greeting-cache.ts +37 -10
  103. package/src/runtime/routes/inference-provider-connection-routes.ts +22 -16
  104. package/src/runtime/routes/internal-twilio-routes.ts +0 -15
  105. package/src/stt/types.ts +5 -9
  106. package/src/tts/__tests__/provider-adapters.test.ts +37 -0
  107. package/src/tts/__tests__/provider-catalog.test.ts +21 -0
  108. package/src/tts/provider-catalog.ts +40 -9
  109. package/src/tts/providers/fish-audio-provider.ts +19 -10
  110. package/src/tts/types.ts +3 -4
  111. package/src/__tests__/job-handler-registry-guard.test.ts +0 -131
  112. package/src/__tests__/relay-server.test.ts +0 -6421
  113. package/src/__tests__/telephony-stt-routing.test.ts +0 -329
  114. package/src/calls/relay-server.ts +0 -2464
  115. package/src/calls/telephony-stt-routing.ts +0 -145
  116. package/src/jobs/register-job-handlers.ts +0 -101
  117. package/src/plugins/job-handler-registry.ts +0 -94
package/ARCHITECTURE.md CHANGED
@@ -16,10 +16,10 @@ This document owns assistant-runtime architecture details. The repo-level archit
16
16
  - Guardian/non-guardian/unverified classification is centralized in `assistant/src/runtime/trust-context-resolver.ts`.
17
17
  - The same resolver is used by:
18
18
  - `/channels/inbound` (Telegram/WhatsApp path) before run orchestration.
19
- - Inbound Twilio voice setup (`RelayConnection.handleSetup`) to seed call-time actor context.
19
+ - Inbound Twilio voice setup (media-stream `routeSetup`) to seed call-time actor context.
20
20
  - Runtime channel runs pass this as `trustContext`, and conversation runtime assembly includes actor context in the unified `<turn_context>` block (via `buildUnifiedTurnContextBlock()`) injected into provider-facing prompts.
21
21
  - Voice calls mirror the same prompt contract: `CallController` receives guardian context on setup and refreshes it immediately after successful voice challenge verification, so the first post-verification turn is grounded as `actor_role: guardian`.
22
- - Voice-specific behavior (DTMF/speech verification flow, relay state machine) remains voice-local; only actor-role resolution is shared.
22
+ - Voice-specific behavior (DTMF/speech verification flow, call-setup state machine) remains voice-local; only actor-role resolution is shared.
23
23
 
24
24
  ### Safe Storage Limits
25
25
 
@@ -483,10 +483,10 @@ A complementary access-granting flow where the guardian proactively creates a sh
483
483
  | Channel | Status | Prerequisites |
484
484
  | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
485
485
  | Telegram | Shipped | Bot username resolved from credential metadata or config |
486
- | Voice | Shipped | Identity-bound voice code redemption via DTMF/speech in the relay state machine. Always-on canonical behavior with personalized friend/guardian name prompts. |
486
+ | Voice | Shipped | Identity-bound voice code redemption via DTMF/speech in the call setup flow. Always-on canonical behavior with personalized friend/guardian name prompts. |
487
487
  | Slack | Deferred | Needs DM-safe ingress — Socket Mode handles channel messages but DM-initiated invite flows need routing |
488
488
 
489
- ### Voice Invite Flow (invite_redemption_pending)
489
+ ### Voice Invite Flow (invite_redemption)
490
490
 
491
491
  Voice invites use a short numeric code (6 digits) instead of a URL token. The guardian creates an invite bound to the invitee's E.164 phone number; the invitee redeems it by entering the code during an inbound voice call.
492
492
 
@@ -497,11 +497,11 @@ Voice invites use a short numeric code (6 digits) instead of a URL token. The gu
497
497
  3. The one-time plaintext `voiceCode` is returned in the creation response. The raw token is NOT returned for voice invites — redemption uses the identity-bound code flow exclusively.
498
498
  4. Guardian communicates the code to the invitee out-of-band.
499
499
 
500
- **Call-time redemption subflow (`invite_redemption_pending`):**
500
+ **Call-time redemption subflow (`invite_redemption`):**
501
501
 
502
- 1. Unknown caller dials in. `relay-server.ts` resolves trust via `resolveActorTrust`. Caller is `unknown`, no pending guardian challenge.
503
- 2. The relay asks the gateway for the active voice invite bound to the caller's phone number (`get_active_voice_invite` IPC via `calls/gateway-invite-reader.ts`; fail-soft — any gateway failure falls through to the unverified path).
504
- 3. If an active, non-expired invite exists, the relay enters the `invite_redemption_pending` state (reuses the `verification_pending` connection state) and prompts the caller with personalized copy: `Welcome <friend-name>. Please enter the 6-digit code that <guardian-name> provided you to verify your identity.`
502
+ 1. Unknown caller dials in. The media-stream server resolves trust (gateway trust verdict first, `resolveActorTrust` fallback inside `routeSetup`). Caller is `unknown`, no pending guardian challenge.
503
+ 2. `routeSetup` asks the gateway for the active voice invite bound to the caller's phone number (`get_active_voice_invite` IPC via `calls/gateway-invite-reader.ts`; fail-soft — any gateway failure falls through to the unverified path).
504
+ 3. If an active, non-expired invite exists, the `CallSetupFlow` runs the `invite_redemption` sub-flow (collecting the code via DTMF or spoken digits) and prompts the caller with personalized copy: `Welcome <friend-name>. Please enter the 6-digit code that <guardian-name> provided you to verify your identity.`
505
505
  4. The gateway's `redeem_voice_invite` engine validates: identity match, code hash match, expiry, use count. On success, the phone channel is activated in the gateway ACL and the call transitions to the normal call flow.
506
506
  5. On invalid/expired code, the caller hears deterministic failure copy: `Sorry, the code you provided is incorrect or has since expired. Please ask <guardian-name> for a new code. Goodbye.` and the call ends immediately.
507
507
 
@@ -523,12 +523,12 @@ Voice invites use a short numeric code (6 digits) instead of a URL token. The gu
523
523
  | `src/daemon/guardian-invite-intent.ts` | Intent detection — routes create/list/revoke requests into the contacts skill |
524
524
  | `src/runtime/invite-service.ts` | Daemon-owned invite presentation (share link, guardian instruction, channel handle) over gateway-minted invites |
525
525
  | `src/runtime/routes/contact-routes.ts` | HTTP/IPC invite handlers — relay mint/list/revoke/redeem to the gateway's invite IPC routes |
526
- | `src/calls/relay-server.ts` | Voice relay state machine — `invite_redemption_pending` subflow (always-on canonical behavior) |
526
+ | `src/calls/call-setup-flow.ts` | Transport-agnostic call setup flow — `invite_redemption` sub-flow (always-on canonical behavior) |
527
527
  | `src/calls/gateway-invite-reader.ts` | Gateway IPC read of the active voice invite for a caller identity |
528
528
 
529
529
  ### Voice Inbound Security Model (Canonical)
530
530
 
531
- The voice inbound security model determines how unknown callers are handled when they dial in. Three paths exist, evaluated in priority order by `relay-server.ts` during the `handleSetup` phase. All guardian decisions route through `applyCanonicalGuardianDecision` in the canonical guardian request system.
531
+ The voice inbound security model determines how unknown callers are handled when they dial in. Three paths exist, evaluated in priority order by `routeSetup` (`relay-setup-router.ts`) when the media-stream session starts. All guardian decisions route through `applyCanonicalGuardianDecision` in the canonical guardian request system.
532
532
 
533
533
  **Decision tree for inbound unknown callers:**
534
534
 
@@ -556,17 +556,17 @@ resolveActorTrust() → trustClass
556
556
 
557
557
  **Path 1: Voice invite code redemption (guardian-initiated)**
558
558
 
559
- The guardian proactively creates a voice invite bound to the caller's E.164 phone number. When the unknown caller dials in and has an active, non-expired invite, the relay enters the `invite_redemption_pending` subflow with personalized prompts using the friend's and guardian's names. This is always-on canonical behavior (no feature flag). See [Voice Invite Flow](#voice-invite-flow-invite_redemption_pending) above.
559
+ The guardian proactively creates a voice invite bound to the caller's E.164 phone number. When the unknown caller dials in and has an active, non-expired invite, the setup flow enters the `invite_redemption` sub-flow with personalized prompts using the friend's and guardian's names. This is always-on canonical behavior (no feature flag). See [Voice Invite Flow](#voice-invite-flow-invite_redemption) above.
560
560
 
561
561
  **Path 2: Live in-call guardian approval (friend-initiated)**
562
562
 
563
- When no invite exists and no pending guardian challenge is active, the relay enters the name capture + guardian approval wait flow:
563
+ When no invite exists and no pending guardian challenge is active, the setup flow enters the name capture + guardian approval wait flow:
564
564
 
565
- 1. The relay transitions to `awaiting_name` state and prompts the caller for their name with a timeout.
565
+ 1. The setup flow transitions to `capturing_name` state and prompts the caller for their name with a timeout.
566
566
  2. On name capture, `notifyGuardianOfAccessRequest` creates a canonical guardian request (`kind: 'access_request'`) and notifies the guardian via the notification pipeline.
567
- 3. The relay transitions to `awaiting_guardian_decision` and plays hold music/messaging while polling the canonical request status.
567
+ 3. The setup flow hands off to a `GuardianWaitController` (`awaiting_guardian_decision`), which speaks hold messaging and heartbeat updates while polling the canonical request status.
568
568
  4. The guardian approves or denies via any channel (Telegram, desktop). All decisions route through `applyCanonicalGuardianDecision`, which dispatches to the `access_request` resolver in `guardian-request-resolvers.ts`.
569
- 5. On approval: the resolver directly activates the caller as a trusted contact (sets channel `status: 'active'`, `policy: 'allow'`), the poll detects the approved status, the relay transitions to the normal call flow with the caller's guardian context updated.
569
+ 5. On approval: the resolver directly activates the caller as a trusted contact (sets channel `status: 'active'`, `policy: 'allow'`), the poll detects the approved status, and the setup flow completes into the normal call flow with the caller's guardian context updated.
570
570
  6. On denial or timeout: the caller hears a denial message and the call ends.
571
571
 
572
572
  **Path 3: Inbound guardian verification (pending challenge)**
@@ -586,7 +586,9 @@ All guardian decisions for voice access requests flow through:
586
586
 
587
587
  | File | Purpose |
588
588
  | ---------------------------------------------- | -------------------------------------------------------------------------------------- |
589
- | `src/calls/relay-server.ts` | Inbound call decision tree, name capture, guardian approval wait polling |
589
+ | `src/calls/relay-setup-router.ts` | Inbound call decision tree (`routeSetup`) |
590
+ | `src/calls/call-setup-flow.ts` | Name capture, verification, and invite sub-flows over the media-stream transport |
591
+ | `src/calls/guardian-wait-controller.ts` | Guardian approval wait — hold messaging, heartbeats, poll/timeout |
590
592
  | `src/runtime/access-request-helper.ts` | Creates canonical access request and notifies guardian |
591
593
  | `src/approvals/guardian-decision-primitive.ts` | `applyCanonicalGuardianDecision` — unified decision primitive |
592
594
  | `src/approvals/guardian-request-resolvers.ts` | `access_request` resolver — voice direct activation, text-channel verification session |
@@ -603,37 +605,41 @@ Audio-to-text conversion occurs in six distinct runtime boundaries, each with it
603
605
 
604
606
  | Boundary | Runtime | Provider (current) | Adapter module | Caller |
605
607
  | -------------------------- | ----------------------------------------------------------------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
606
- | **Telephony (hybrid)** | Twilio-native ConversationRelay or daemon media-stream (provider-conditional) | Configured STT provider (via `services.stt`) | `src/calls/telephony-stt-routing.ts` | `src/calls/twilio-routes.ts` |
608
+ | **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` |
607
609
  | **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` |
608
610
  | **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 |
609
611
  | **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` |
610
612
  | **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 |
611
613
 
612
- **Telephony boundary (hybrid routing):**
614
+ **Telephony boundary (media-stream):**
613
615
 
614
- Telephony STT uses a provider-conditional hybrid model driven by `services.stt.provider`. The routing resolver (`src/calls/telephony-stt-routing.ts`) maps the configured provider to a discriminated strategy at call setup time:
616
+ Every phone call connects over Twilio Media Streams: the voice webhook emits `<Connect><Stream>` TwiML pointing to the gateway's media-stream proxy, and the daemon performs both STT and TTS itself — Twilio only carries mu-law audio frames. The `<Stream url="...">` encodes `callSessionId` and auth `token` as **URL path segments** (e.g. `.../media-stream/<callSessionId>/<token>`) because Twilio Media Streams does not reliably preserve query parameters across the WebSocket upgrade. The gateway extracts metadata from path segments (with query-parameter fallback for backward compatibility) and proxies raw audio frames to the daemon.
615
617
 
616
- - **`conversation-relay-native`** (Deepgram, Google) — TwiML emits `<Connect><ConversationRelay>` with `transcriptionProvider` and `speechModel` attributes. Twilio handles audio ingestion and transcription natively; the daemon receives transcribed text via the relay WebSocket. The Twilio-native provider name and default speech model are read from the provider catalog entry's `telephonyRouting.twilioNativeMapping` (e.g. Deepgram maps to `provider: "Deepgram"` with `defaultSpeechModel: "nova-3"`; Google maps to `provider: "Google"` with `defaultSpeechModel: undefined`).
618
+ Transcription mode is selected once per session in `media-stream-stt-session.ts`:
617
619
 
618
- - **`media-stream-custom`** (OpenAI Whisper) — TwiML emits `<Connect><Stream>` pointing to the gateway's media-stream proxy. The `<Stream url="...">` encodes `callSessionId` and auth `token` as **URL path segments** (e.g. `.../media-stream/<callSessionId>/<token>`) because Twilio Media Streams does not reliably preserve query parameters across the WebSocket upgrade. The gateway extracts metadata from path segments (with query-parameter fallback for backward compatibility) and proxies raw audio frames to the daemon, which transcribes server-side via the provider's batch API.
620
+ - **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.
621
+ - **Batch fallback** — otherwise the session segments turns with the energy-based `MediaTurnDetector` and transcribes each completed turn via the provider's batch API.
622
+
623
+ 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.
619
624
 
620
625
  Key modules:
621
626
 
622
- | Module | Purpose |
623
- | --------------------------------------------------- | ---------------------------------------------------------------------- |
624
- | `src/calls/telephony-stt-routing.ts` | Maps `services.stt.provider` to a discriminated `TelephonySttStrategy` |
625
- | `src/calls/twilio-routes.ts` | Voice webhook handler; generates provider-conditional TwiML |
626
- | `src/calls/media-stream-parser.ts` | Twilio Media Streams protocol parser |
627
- | `src/calls/media-turn-detector.ts` | Energy-based VAD turn detector for raw audio |
628
- | `src/calls/media-stream-stt-session.ts` | STT session that transcribes audio turns via `services.stt` |
629
- | `src/calls/call-transport.ts` | Transport interface decoupling CallController from wire protocol |
630
- | `src/calls/media-stream-output.ts` | Output adapter for sending TTS audio back via Media Streams |
631
- | `src/calls/media-stream-server.ts` | WebSocket server binding media-stream lifecycle to call sessions |
632
- | `gateway/src/http/routes/twilio-media-websocket.ts` | Gateway WebSocket proxy for Media Streams frames |
627
+ | Module | Purpose |
628
+ | --------------------------------------------------- | -------------------------------------------------------------------------------- |
629
+ | `src/calls/twilio-routes.ts` | Voice webhook handler; generates `<Connect><Stream>` TwiML, enforces the inbound credential preflight |
630
+ | `src/calls/telephony-credential-preflight.ts` | Combined STT + TTS credential-readiness resolver |
631
+ | `src/calls/media-stream-parser.ts` | Twilio Media Streams protocol parser |
632
+ | `src/calls/media-turn-detector.ts` | Energy-based VAD turn detector for raw audio (batch mode) |
633
+ | `src/calls/media-stream-stt-session.ts` | STT session — streaming/batch mode selection and transcription via `services.stt` |
634
+ | `src/calls/media-stream-audio-transcode.ts` | Mu-law ↔ PCM16 codecs and resampling |
635
+ | `src/calls/call-transport.ts` | Transport interface decoupling CallController from wire protocol |
636
+ | `src/calls/media-stream-output.ts` | Output adapter for sending TTS audio back via Media Streams |
637
+ | `src/calls/media-stream-server.ts` | WebSocket server binding media-stream lifecycle to call sessions and setup flows |
638
+ | `gateway/src/http/routes/twilio-media-websocket.ts` | Gateway WebSocket proxy for Media Streams frames |
633
639
 
634
- Guard tests in `__tests__/twilio-routes-twiml.test.ts` and `__tests__/twilio-routes.test.ts` assert that TwiML generation matches the provider-conditional strategy for each supported provider.
640
+ Guard tests in `__tests__/twilio-routes-twiml.test.ts` and `__tests__/twilio-routes.test.ts` assert that every supported STT provider yields `<Connect><Stream>` TwiML for both inbound and outbound calls.
635
641
 
636
- To add a new telephony STT provider: add a `telephonyRouting` entry to the provider's catalog entry in `provider-catalog.ts`. Set `strategyKind` to `"conversation-relay-native"` for Twilio-native providers (and include a `twilioNativeMapping` with the Twilio `provider` name and `defaultSpeechModel`), or `"media-stream-custom"` for providers that require daemon-side transcription. The routing resolver reads these fields from the catalog — no hardcoded maps to update.
642
+ To add a new telephony STT provider: declare `telephonyMode` and `supportedBoundaries` on the provider's catalog entry in `provider-catalog.ts`. The telephony capability resolver (`resolveTelephonySttCapability()`) reads these fields plus credential availability from the catalog — no per-provider routing maps exist.
637
643
 
638
644
  **Daemon batch boundary:**
639
645
 
@@ -744,7 +750,7 @@ The web client implements these flows in `clients/web/src/domains/chat/voice/`:
744
750
 
745
751
  **Cross-boundary notes:**
746
752
 
747
- - 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 uses `resolveTelephonySttRouting()` to determine the Twilio integration strategy. 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`.
753
+ - 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`.
748
754
  - 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.
749
755
  - 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`.
750
756
  - Terminology: "STT", "transcription", and "speech recognition" all refer to the same operation (converting audio to text).
@@ -2198,12 +2204,12 @@ The `TtsUseCase` discriminator (`"phone-call"` or `"message-playback"`) lets pro
2198
2204
 
2199
2205
  **Synthesis orchestrator (`synthesize-text.ts`):** `synthesizeText()` is the top-level entry point. It resolves the globally configured provider via the config resolver, looks up the adapter in the registry, and delegates synthesis. Provider selection is always global — per-use-case policy only gates capabilities (e.g. format checks), never overrides the chosen provider.
2200
2206
 
2201
- **Call strategy abstraction (`tts-call-strategy.ts`):** The call strategy layer determines how a TTS provider integrates with the Twilio ConversationRelay telephony path. Instead of inferring call behavior from runtime capabilities, `resolveCallStrategy(config)` reads the provider's `callMode` from the canonical catalog and returns a `TtsCallStrategy` with the provider ID and call mode. Two modes exist:
2207
+ **Call strategy abstraction (`tts-call-strategy.ts`):** The call strategy layer determines how a TTS provider integrates with the telephony path. Instead of inferring call behavior from runtime capabilities, `resolveCallStrategy(config)` reads the provider's `callMode` from the canonical catalog and returns a `TtsCallStrategy` with the provider ID and call mode. Two modes exist:
2202
2208
 
2203
- - **`native-twilio`** — Twilio handles TTS natively via ConversationRelay. The profile needs a real `ttsProvider` name (e.g. `"ElevenLabs"`) and a provider-specific voice spec string. New native providers plug in by registering a `NativeTwilioVoiceSpecBuilder` via `registerNativeTwilioVoiceSpec()` — no edits to core call routing logic required.
2204
- - **`synthesized-play`** — The assistant synthesises audio via the provider's HTTP API and streams chunks to Twilio via `play` messages. Uses a placeholder TTS provider (`"Google"`) and an empty voice string because Twilio never drives TTS itself on this path.
2209
+ - **`native-twilio`** — the text-token path: spoken text is sent via `sendTextToken()`, which the media-stream transport re-synthesizes through daemon TTS. The profile carries a real `ttsProvider` name (e.g. `"ElevenLabs"`) and a provider-specific voice spec string built by a registered `NativeTwilioVoiceSpecBuilder`. Collapsing this mode is a documented deferred follow-up.
2210
+ - **`synthesized-play`** — The assistant synthesises audio via the provider's HTTP API and streams it through the audio store / `sendPlayUrl()` path. Uses a placeholder TTS provider (`"Google"`) and an empty voice string.
2205
2211
 
2206
- **Phone call integration:** `resolveVoiceQualityProfile()` in `voice-quality.ts` uses `resolveCallStrategy()` to determine the call mode, then dispatches to the appropriate path. For `native-twilio`, it looks up the registered `NativeTwilioVoiceSpec` to build the voice string. For `synthesized-play`, it uses the placeholder profile. This replaces the previous `supportsStreaming`-based branching with explicit catalog-declared modes.
2212
+ **Phone call integration:** Phone calls run on the media-stream transport, where the daemon synthesises speech via the configured TTS provider and transcodes it to mu-law 8 kHz frames (`media-stream-output.ts`). Each catalog entry declares `mediaStreamPlayback.outputFormat` (`pcm`, `wav`, or `none`); `resolveTelephonyTtsCapability()` (`src/calls/telephony-tts-capability.ts`) combines that field with credential availability into a playable / not-playable verdict, and the call TTS resolver falls back to a credentialed playable provider rather than producing silence. `resolveVoiceQualityProfile()` in `voice-quality.ts` uses `resolveCallStrategy()` to determine the call mode and build the voice profile.
2207
2213
 
2208
2214
  **Adding a new TTS provider (catalog-first checklist):**
2209
2215
 
package/README.md CHANGED
@@ -174,7 +174,7 @@ Guardian actor-role _classification_ (determining whether a sender is guardian,
174
174
 
175
175
  ### Ingress Boundary Guarantees (Gateway-Only Mode)
176
176
 
177
- The runtime operates in **gateway-only mode**: all public-facing webhook paths are blocked at the runtime level. Direct access to Twilio webhook routes (`/webhooks/twilio/voice`, `/webhooks/twilio/status`, `/webhooks/twilio/connect-action`) and their legacy equivalents (`/v1/calls/twilio/*`) returns `410 GATEWAY_ONLY`. This ensures external webhook traffic can only reach the runtime through the gateway, which performs signature validation before forwarding.
177
+ The runtime operates in **gateway-only mode**: all public-facing webhook paths are blocked at the runtime level. Direct access to Twilio webhook routes (`/webhooks/twilio/voice`, `/webhooks/twilio/status`) and their legacy equivalents (`/v1/calls/twilio/*`) returns `410 GATEWAY_ONLY`. This ensures external webhook traffic can only reach the runtime through the gateway, which performs signature validation before forwarding.
178
178
 
179
179
  Internal forwarding routes (`/v1/internal/twilio/*`) are unaffected — these accept pre-validated payloads from the gateway over the private network.
180
180
 
@@ -12,8 +12,7 @@ Add a new entry to the `CATALOG` map with:
12
12
  - `credentialProvider` — the credential-store key name used by `getProviderKeyAsync` to retrieve the API key. If the provider shares an API key with another service (e.g. `openai-whisper` shares the `"openai"` key, or `google-gemini` shares the `"gemini"` key), reuse that name; otherwise use the provider's own name (e.g. `"deepgram"` maps to `"deepgram"`).
13
13
  - `supportedBoundaries` — the set of `SttBoundaryId` values the provider supports. Valid values are `"daemon-batch"` (post-recording transcription) and `"daemon-streaming"` (real-time streaming transcription during conversation).
14
14
  - `conversationStreamingMode` — how the provider handles streaming transcription in conversation mode: `"realtime-ws"` (provider supports real-time streaming natively via WebSocket), `"incremental-batch"` (streaming emulated via throttled polling), or `"none"` (no streaming support). Required for all providers.
15
- - `telephonyMode` — how the provider participates in real-time telephony STT: `"realtime-ws"`, `"batch-only"`, or `"none"`.
16
- - `telephonyRouting` — telephony routing metadata that drives Twilio call setup strategy selection. Declare `strategyKind` as `"conversation-relay-native"` or `"media-stream-custom"`. For native providers, include `twilioNativeMapping` with the Twilio `provider` name and `defaultSpeechModel`.
15
+ - `telephonyMode` — how the provider participates in real-time telephony STT: `"realtime-ws"`, `"batch-only"`, or `"none"`. The telephony capability resolver (`resolveTelephonySttCapability()` in `src/providers/speech-to-text/resolve.ts`) reads this field plus credential availability to decide whether phone calls can run with the provider.
17
16
 
18
17
  ## 2. Type-system registration
19
18
 
@@ -84,8 +83,8 @@ Clients derive shared-vs-exclusive key behavior from the catalog automatically:
84
83
 
85
84
  Before submitting the PR, verify that:
86
85
 
87
- 1. **No stale config references** — grep for any references to a separate telephony transcription config. The telephony routing module (`src/calls/telephony-stt-routing.ts`) reads `services.stt.provider` and maps it to the appropriate Twilio strategy (either `conversation-relay-native` for providers Twilio supports natively, or `media-stream-custom` for server-side transcription).
86
+ 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.
88
87
 
89
- 2. **Provider catalog `telephonyRouting` metadata** — the new provider's catalog entry (step 1) includes a `telephonyRouting` object that is the single source of truth for strategy selection in `telephony-stt-routing.ts`. This object declares the `strategyKind` (`"conversation-relay-native"` or `"media-stream-custom"`) and, for native providers, provides a `twilioNativeMapping` with the Twilio `provider` name and `defaultSpeechModel`. The routing module contains no hardcoded provider-to-Twilio maps — it reads these values directly from the catalog.
88
+ 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.
90
89
 
91
- 3. **No duplicate wiring** — a provider should appear only once in `services.stt`. The telephony routing layer consumes the same provider ID; there is no second registration step for telephony.
90
+ 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.
@@ -126,10 +126,10 @@ Voice calls have a dedicated in-call guardian approval flow that differs from th
126
126
 
127
127
  **Flow:**
128
128
 
129
- 1. Unknown caller dials in. `relay-server.ts` resolves trust — caller is `unknown`, no pending challenge, no active invite.
130
- 2. Relay enters `awaiting_name` state and prompts the caller for their name (with a timeout).
129
+ 1. Unknown caller dials in. `routeSetup` (`relay-setup-router.ts`) resolves trust — caller is `unknown`, no pending challenge, no active invite.
130
+ 2. The `CallSetupFlow` enters `capturing_name` state and prompts the caller for their name (with a timeout).
131
131
  3. On name capture, `notifyGuardianOfAccessRequest` creates a canonical guardian request (`kind: 'access_request'`) and notifies the guardian.
132
- 4. Relay transitions to `awaiting_guardian_decision` and polls `canonical_guardian_requests` for status changes.
132
+ 4. The flow hands off to a `GuardianWaitController` (`awaiting_guardian_decision`), which speaks hold messaging while polling `canonical_guardian_requests` for status changes.
133
133
  5. Guardian approves or denies via any channel. All decisions route through `applyCanonicalGuardianDecision`.
134
134
  6. On approval: the `access_request` resolver directly activates the caller as a trusted contact (`upsertContactChannel` with `status: 'active'`, `policy: 'allow'`) — no verification session needed since the caller is already authenticated by their phone number.
135
135
  7. On denial or timeout: the caller hears a denial message and the call ends.
@@ -5,10 +5,8 @@ import {
5
5
  normalizePublicBaseUrl,
6
6
  } from "../ingress.js";
7
7
  import {
8
- buildTwilioConnectActionUrl,
9
8
  buildTwilioMediaStreamUrl,
10
9
  buildTwilioPhoneNumberWebhookUrls,
11
- buildTwilioRelayUrl,
12
10
  buildTwilioVoiceWebhookUrl,
13
11
  resolveTwilioPublicBaseUrl,
14
12
  } from "../twilio-ingress.js";
@@ -90,12 +88,6 @@ describe("Twilio ingress helpers", () => {
90
88
  expect(buildTwilioVoiceWebhookUrl("https://example.test", "call-123")).toBe(
91
89
  "https://example.test/webhooks/twilio/voice?callSessionId=call-123",
92
90
  );
93
- expect(buildTwilioConnectActionUrl("https://example.test")).toBe(
94
- "https://example.test/webhooks/twilio/connect-action",
95
- );
96
- expect(buildTwilioRelayUrl("https://example.test")).toBe(
97
- "wss://example.test/webhooks/twilio/relay",
98
- );
99
91
  expect(buildTwilioMediaStreamUrl("http://example.test")).toBe(
100
92
  "ws://example.test/webhooks/twilio/media-stream",
101
93
  );
@@ -2,9 +2,6 @@ import { normalizePublicBaseUrl } from "./ingress.js";
2
2
 
3
3
  export const TWILIO_VOICE_WEBHOOK_PATH = "/webhooks/twilio/voice";
4
4
  export const TWILIO_STATUS_WEBHOOK_PATH = "/webhooks/twilio/status";
5
- export const TWILIO_CONNECT_ACTION_WEBHOOK_PATH =
6
- "/webhooks/twilio/connect-action";
7
- export const TWILIO_RELAY_WEBHOOK_PATH = "/webhooks/twilio/relay";
8
5
  export const TWILIO_MEDIA_STREAM_WEBHOOK_PATH = "/webhooks/twilio/media-stream";
9
6
 
10
7
  /**
@@ -13,9 +10,9 @@ export const TWILIO_MEDIA_STREAM_WEBHOOK_PATH = "/webhooks/twilio/media-stream";
13
10
  * with the actual public URL (from Velay registration, config, or the
14
11
  * `X-Vellum-Ingress-URL` header) before returning TwiML to Twilio.
15
12
  *
16
- * The placeholder uses `https://` so that `buildTwilioRelayUrl` /
17
- * `buildTwilioMediaStreamUrl` can apply the standard `http→ws` scheme
18
- * conversion, producing `wss://__VELLUM_PUBLIC_BASE_URL__/…` in the output.
13
+ * The placeholder uses `https://` so that `buildTwilioMediaStreamUrl` can
14
+ * apply the standard `http→ws` scheme conversion, producing
15
+ * `wss://__VELLUM_PUBLIC_BASE_URL__/…` in the output.
19
16
  */
20
17
  export const TWILIO_PUBLIC_BASE_URL_PLACEHOLDER =
21
18
  "https://__VELLUM_PUBLIC_BASE_URL__";
@@ -58,14 +55,6 @@ export function buildTwilioStatusWebhookUrl(baseUrl: string): string {
58
55
  return `${baseUrl}${TWILIO_STATUS_WEBHOOK_PATH}`;
59
56
  }
60
57
 
61
- export function buildTwilioConnectActionUrl(baseUrl: string): string {
62
- return `${baseUrl}${TWILIO_CONNECT_ACTION_WEBHOOK_PATH}`;
63
- }
64
-
65
- export function buildTwilioRelayUrl(baseUrl: string): string {
66
- return `${toTwilioWebSocketBaseUrl(baseUrl)}${TWILIO_RELAY_WEBHOOK_PATH}`;
67
- }
68
-
69
58
  export function buildTwilioMediaStreamUrl(baseUrl: string): string {
70
59
  return `${toTwilioWebSocketBaseUrl(baseUrl)}${TWILIO_MEDIA_STREAM_WEBHOOK_PATH}`;
71
60
  }
package/openapi.yaml CHANGED
@@ -3400,6 +3400,9 @@ paths:
3400
3400
  content:
3401
3401
  type: string
3402
3402
  description: User prompt content
3403
+ clientTimezone:
3404
+ description: IANA timezone reported by the active client
3405
+ type: string
3403
3406
  required:
3404
3407
  - conversationKey
3405
3408
  - content
@@ -15687,16 +15690,6 @@ paths:
15687
15690
  required:
15688
15691
  - skipped
15689
15692
  additionalProperties: false
15690
- /v1/internal/twilio/connect-action:
15691
- post:
15692
- operationId: internal_twilio_connectaction_post
15693
- summary: Internal Twilio connect-action
15694
- description: Gateway-to-runtime forwarding for ConversationRelay connect-action callback.
15695
- tags:
15696
- - internal
15697
- responses:
15698
- "200":
15699
- description: Successful response
15700
15693
  /v1/internal/twilio/status:
15701
15694
  post:
15702
15695
  operationId: internal_twilio_status_post
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.4-dev.202607022130.febf41d",
3
+ "version": "0.10.4-dev.202607022227.14c7770",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -91,7 +91,6 @@ describe("assistant ID boundary", () => {
91
91
  "runtime/verification-outbound-actions.ts",
92
92
  "daemon/handlers/config-channels.ts",
93
93
  "runtime/routes/channel-route-shared.ts",
94
- "calls/relay-server.ts",
95
94
  ];
96
95
 
97
96
  const srcDir = join(import.meta.dir, "..");
@@ -8,7 +8,7 @@
8
8
 
9
9
  import { rmSync, writeFileSync } from "node:fs";
10
10
  import { join } from "node:path";
11
- import { describe, expect, mock, test } from "bun:test";
11
+ import { beforeEach, describe, expect, mock, test } from "bun:test";
12
12
 
13
13
  // ---------------------------------------------------------------------------
14
14
  // Mocks — must be defined before importing the module under test
@@ -84,6 +84,25 @@ mock.module("../runtime/routes/workspace-greetings.js", () => ({
84
84
  readWorkspaceGreetings: () => null,
85
85
  }));
86
86
 
87
+ const mockConfig = {
88
+ ui: {
89
+ emptyStateGreetingCacheTtlMs: 0,
90
+ userTimezone: "",
91
+ detectedTimezone: "",
92
+ },
93
+ memory: {
94
+ retrieval: {
95
+ scratchpadInjection: {
96
+ enabled: false,
97
+ },
98
+ },
99
+ },
100
+ };
101
+
102
+ mock.module("../config/loader.js", () => ({
103
+ getConfig: () => mockConfig,
104
+ }));
105
+
87
106
  // Mock getOrCreateConversation from conversation-store so the handler
88
107
  // never touches DaemonServer.
89
108
  const mockGetOrCreateConversation = mock(async (_id: string) =>
@@ -179,7 +198,9 @@ function makeMockSession(
179
198
  }
180
199
 
181
200
  const route = ROUTES.find((r) => r.endpoint === "btw" && r.method === "POST");
182
- if (!route) throw new Error("btw route not found in ROUTES");
201
+ if (!route) {
202
+ throw new Error("btw route not found in ROUTES");
203
+ }
183
204
 
184
205
  async function callHandler(
185
206
  body: Record<string, unknown>,
@@ -202,7 +223,9 @@ async function readStream(stream: ReadableStream<Uint8Array>): Promise<string> {
202
223
  const chunks: Uint8Array[] = [];
203
224
  while (true) {
204
225
  const { done, value } = await reader.read();
205
- if (done) break;
226
+ if (done) {
227
+ break;
228
+ }
206
229
  chunks.push(value);
207
230
  }
208
231
  return new TextDecoder().decode(
@@ -218,6 +241,13 @@ async function readStream(stream: ReadableStream<Uint8Array>): Promise<string> {
218
241
  // ---------------------------------------------------------------------------
219
242
 
220
243
  describe("POST /v1/btw", () => {
244
+ beforeEach(() => {
245
+ mockConfig.ui.emptyStateGreetingCacheTtlMs = 0;
246
+ mockConfig.ui.userTimezone = "";
247
+ mockConfig.ui.detectedTimezone = "";
248
+ mockConfig.memory.retrieval.scratchpadInjection.enabled = false;
249
+ });
250
+
221
251
  // -- Validation (400s) --
222
252
 
223
253
  test("throws BadRequestError for missing conversationKey", async () => {
@@ -344,6 +374,30 @@ describe("POST /v1/btw", () => {
344
374
  expect(options!.config!.callSite).toBe("emptyStateGreeting");
345
375
  });
346
376
 
377
+ test("greeting requests include fresh turn context using the client timezone", async () => {
378
+ const provider = makeMockProvider();
379
+ const session = makeMockSession(provider);
380
+ mockGetOrCreateConversation.mockImplementationOnce(async () => session);
381
+
382
+ const { result } = await callHandler({
383
+ conversationKey: "greeting",
384
+ content: "Generate a greeting",
385
+ clientTimezone: "Europe/Skopje",
386
+ });
387
+ await readStream(result as ReadableStream<Uint8Array>);
388
+
389
+ expect(provider.sendMessage).toHaveBeenCalledTimes(1);
390
+ const [messages] = provider.sendMessage.mock.calls[0] as [
391
+ Array<{ content: Array<{ type: string; text: string }> }>,
392
+ SendMessageOptions | undefined,
393
+ ];
394
+ const greetingPrompt = messages[2]!.content[0]!.text;
395
+ expect(greetingPrompt).toContain("Generate a greeting");
396
+ expect(greetingPrompt).toContain("<turn_context>");
397
+ expect(greetingPrompt).toContain("current_time:");
398
+ expect(greetingPrompt).toContain("(Europe/Skopje)");
399
+ });
400
+
347
401
  test("generic requests pass the default callSite", async () => {
348
402
  const provider = makeMockProvider();
349
403
  const session = makeMockSession(provider);