Repository navigation
feat: hold voice conversations through an app-provided transport - #189
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Adds the public VoiceTransport protocol, through which an app supplies the real-time audio and data connection for voice conversations, and brings the voice session logic into Brand Concierge as internal types: the session controller, the data-channel message parser and the session state. The session claims the app's single transport only while connected, and releases it (clearing the delegate, then disconnecting) before reporting its end, so the transport can be reused by the next conversation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Concierge.show(...) and Concierge.present(...) take an optional voiceTransport, kept across re-shows like textSpeaker. When one is passed, the composer shows a voice button in the send slot; tapping it fetches session credentials from the Concierge service and runs the conversation over the app's transport. The transcript renders in the chat, and typed turns, dictation and data handoffs are held off until the conversation ends. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # AEPBrandConcierge/Sources/Controllers/ChatController.swift
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # AEPBrandConcierge/Tests/UnitTests/ConciergeChatServiceTests.swift
7e65fa8 to
9bf2102
Compare
…redentials Only the voice session itself watched for the app entering the background, and it exists only once the credentials arrive. Going to the background while they were still being fetched left the request running, and the session then connected and opened the microphone. The chat controller now stops voice on background in every phase, cancelling a pending credentials request, so the session no longer watches for it separately. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…re a voice session Track a running voice conversation with ChatController.isVoiceSessionActive instead of a new public ChatState case, so exhaustive switches in host apps keep compiling. Ask for microphone permission before requesting voice credentials. A denial starts nothing and shows the Settings dialog worded for voice conversations, matching Android. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
connect(url:token:) becomes connect(_ connection: VoiceConnection), a value type Brand Concierge creates, so connection details can be added later without breaking app transports. VoiceTransportState gains .reconnecting. The conversation stays open with the connecting indicator, the microphone is left as it was, and the session fails if the transport does not report .connected again within 30 seconds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… seconds Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ake it Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The overlay chat and the UIKit chat can be open together and share the app's transport. A chat now claims voice at the voice tap and releases it when its conversation ends or the chat goes away; meanwhile the other chats' voice button is disabled, so a second conversation can no longer take the transport's delegate or hang up the first call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…hen audio can't resume An interruption is now tracked apart from the session state, so a .connected that arrives during a phone call mutes the microphone instead of leaving it live. When the interruption ends without .shouldResume, the session fails with the usual error message instead of staying muted with no way to unmute. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
session_ended always ended the session normally, so a server error showed nothing and sent no error event. Only the agent's timeouts end normally now; error, worker_shutdown and unknown or missing reasons fail the session with the usual voice error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Voice leaves the chat state idle, so the list reserved no space below the user's words and the scroll to them clamped near the bottom; the agent's reply then grew below the screen. Keep a voice scroll anchor (the latest user bubble, or the agent's first bubble when it speaks first) and reserve space below it while only agent bubbles follow it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ansport opts in VoiceTransport gains continuesInBackground, false by default in a protocol extension so existing transports are unaffected. Brand Concierge reads it once per conversation at connect. When the app goes to the background, a conversation whose transport opted in and was asked to connect keeps running; one without the opt-in, or still asking for microphone permission or fetching credentials, ends as before, since iOS doesn't let an app start the microphone from the background. Every conversation now ends normally 60 minutes after the transport first reports .connected, in the foreground or the background, so a forgotten conversation can't hold a room indefinitely. Reconnects don't restart the count. The getting-started guide describes the opt-in, the audio background mode the app must declare and the App Review note. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cdhoffmann
left a comment
There was a problem hiding this comment.
Separately, voiceTransport adds another optional parameter across show, present and wrap, while those APIs already differ in which options they accept. Could we consider a shared chat-options object before the public API grows further? This isn't a blocker for the voice behavior, but I'd like to align with Ryan on the iOS/Android direction.
@cdhoffmann Agreed on the chat-options object. Since |
Decode ui_payload sources, prompt suggestions and multimodal elements into the models typed chat already uses, so a voice turn can render them. Each field decodes on its own, so a malformed field drops only its own content. Widgets are not modeled because the SDK has no widget support. Parse the worker's text_input_error, which rejects a text prompt sent during a voice session. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Track the current voice turn the way web's handleTurnDone does. The user's transcript decides the turn; a new user turn closes the open reply, and messages for any other or already finished turn are dropped. The latest ui_payload snapshot is held for the turn. When the turn ends, the reply bubble gets the authoritative text and the sources, followed by the cards, CTAs and suggestions, through the same code typed chat uses. An error or an empty reply replaces the bubble with the new voice.turn.failed copy, still renders the payload and keeps the conversation open. An interrupted turn counts as completed. Add the voice.turn.failed and voice.turn.messageSendFailed copy with web's defaults. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add VoiceTransport.send(_:topic:), which the app implements with reliable delivery. During a voice conversation, a tapped prompt suggestion (including a welcome one) goes to the worker as a text_prompt on the bc-text-input topic, like on web, and is tracked as a submitted query. The user's bubble shows at once and the worker's echo of it is dropped. After the conversation ends, taps stream over SSE as before; the composer stays read-only during voice, as on web. Taps are dropped while connecting or reconnecting, and from the start of the user's speech until the reply starts. A rejected prompt (text_input_error) fails the turn with voice.turn.failed, and a send that throws fails it with voice.turn.messageSendFailed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@cdhoffmann On your comment about a shared chat-options object: instead, I'd drop the Android would do the same, replacing the • Apps keep one transport instance, and only one voice conversation runs at a time, so a per-call parameter adds nothing. An options object for the existing parameters could come later. Does this work for you? If so, I'll confirm it with @rymorale for both platforms. |
A voice session failure now carries a typed reason with a fixed message. Errors from the app's transport and the bootstrap call can include URLs, tokens or server responses, so their text only goes to the debug log and never to Edge or the warning and error logs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When the final transcript for a turn has no text, the open bubble is removed instead of being left empty, and the next bubble becomes the scroll anchor. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
setMicrophoneEnabled returns immediately and can't throw, so a transport whose mute or unmute fails is the only one that knows. Brand Concierge can't tell whether the microphone is live then, so the transport now reports .failed and the conversation ends. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The voice bootstrap now carries the held XDM context, resolved for the same session as the bootstrap request. The service replays it on every voice turn, so a tapped prompt suggestion's Query Submitted event uses that snapshot rather than the store's current context. Updates made during a voice conversation apply from the next conversation or typed message; the implementation guide says so. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The session reports when the current turn starts and stops waiting for its reply: from the user's final transcript, spoken or sent as text, until the reply's first text, the turn's end, a newer turn or the end of the session. The chat shows the wait the way a typed turn does, as an empty reply bubble with the theme's loading message, and the reply fills that bubble. An empty bubble left behind is removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
show, present and wrap no longer take a voiceTransport. The app registers one transport with Concierge.setVoiceTransport(_:), from any thread, and every chat reads it, so a new value reaches chats that are already open as well as later ones. A running conversation keeps the transport it started with. After nil, the voice button stays while a conversation runs, so the user can stop it, and disappears once it ends. Resetting identities keeps the registered transport. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@cdhoffmann I went ahead with the setter from my earlier comment so you can see it in code: |
Say a transport is registered rather than provided in the composer comments, and note in the getting-started guide that taps are ignored while connecting and that setVoiceTransport can be called from any thread. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resetting identities ends a running voice conversation and keeps the transport registered with Concierge.setVoiceTransport. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The voice bootstrap now takes the app's auth token, as a chat turn does. Resolve it after the microphone check and before the bootstrap request. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replaces #185. Instead of discovering an
AEPVoiceplugin throughAEPPluginSupport, Brand Concierge now owns the voice session logic, and the app supplies the real-time transport itself, registering it withConcierge.setVoiceTransport(section 7).The per-request stream handler fix that was carried over from #185 is now its own PR, #195, against
main. It isn't needed for voice: the voice bootstrap stream closes right after it delivers the credentials.Summary
Brand Concierge can hold a voice conversation over a transport the app provides. BC owns the conversation: credentials, microphone permission, session lifecycle, audio interruptions, data-channel parsing, transcript and UI. The app owns only the audio connection, through a small public
VoiceTransportprotocol. BC takes no LiveKit, AEPVoice or AEPPluginSupport dependency, and apps that don't use voice ship no WebRTC code.Changes
1. Transport interface and voice session logic
Sources/Protocols/VoiceTransport.swift):VoiceTransport:delegate,continuesInBackground,connect(_:),setMicrophoneEnabled(_:),disconnect(),send(_:topic:)VoiceConnection: whatconnect(_:)receives,urlandtoken. New fields can be added later without breaking existing transports.VoiceTransportDelegate:voiceTransport(_:didChange:),voiceTransport(_:didReceive:topic:)VoiceTransportState:.connected,.reconnecting,.disconnected,.failed(Error)AEPVoiceprototype:VoiceSessionController,DataChannelMessage,DataChannelMessageParser, the session state and the transcript role.disconnect(). Callbacks from any other sender, or after release, are dropped.send(_:topic:), which isasync throws; see section 4..connected, and changes it only throughsetMicrophoneEnabled, to mute during audio interruptions such as a phone call..connectedarrives. When it ends with.shouldResume, BC unmutes. iOS often omits that option, and the chat has no unmute control, so without it the session fails with the usual voice error and BC callsdisconnect().voiceTransport(_:didChange:)), not the shorthanddidChange(state:)..connectingstate, because BC tracks connecting itself..reconnectingwhile it recovers a dropped connection (a network change, for example) and.connectedonce it is back. BC shows the connecting spinner and keeps the microphone as it was. If the transport is not back within 30 seconds, the session fails and BC callsdisconnect()..connectednor.failedarrives within 20 seconds ofconnect(_:), the session fails with the usual voice error and BC callsdisconnect().2. Voice in the chat
Concierge.setVoiceTransport(_:)(section 7).show,presentandwrapdon't take it.ChatControllerbehaviour come from feat: integrate the optional voice plugin #185:VoiceSessionControllerchecks it again, as a safety net for callers that don't go throughChatController.wssorhttps, because the token travels on that connection. Any other scheme fails the session before the transport is touched.errorOccurred.error,worker_shutdown, or an unknown or missing reason fails it with the usual voice error anderrorOccurred.ChatStateidle, so this uses its own scroll anchor (the latest user bubble, or the agent's first bubble when it speaks first).ChatControllernow drives the internalVoiceSessionControllerinstead of a plugin session.getting-started.mdhas an "Optional: voice conversations" section.Concierge.setVoiceTransport(_:)entry (section 7).LiveKitTransportfor the sample app lands in a follow-up.3. Background conversations
VoiceTransport.continuesInBackground(defaultfalsethrough a protocol extension, so existing transports are unaffected) lets a transport opt in to keeping the conversation running when the app goes to the background: screen locked, or another app in front. BC reads it once per conversation, right beforeconnect(_:).audiobackground mode, and its transport must start the microphone insideconnect(_:)..connected, in the foreground or the background, so a forgotten conversation can't hold a room indefinitely. Reconnects don't restart the count. The cap is fixed.getting-started.mdhas a "Background conversations" part covering the opt-in, the background mode and the cap.4. Voice turns: UI payloads, turn states and suggestion taps (second review)
ui_payload(sources,promptSuggestions,multimodalElements) into the same models typed chat uses. The agent can send several per turn, each a full snapshot, so the latest one is kept. When the turn ends, the reply bubble gets itssources, and cards, carousels, CTAs and prompt suggestions render through typed chat's code.widgetsaren't rendered, as in typed chat.handleTurnDone:turnId). A new user turn closes the open reply bubble, and messages for another or an already-finished turn are dropped.erroror an emptyfullText: the reply bubble shows the newvoice.turn.failedcopy, the payload still renders and the session continues.interruptedcounts as completed. A lateerrorafter a completed turn (failed playback) is dropped.ChatControllergets each turn's end through a new internal listener callback,voiceSession(_:didFinishTurn:).{"type":"text_prompt","turn_id","text"}on topicbc-text-input, through the newVoiceTransport.send(_:topic:). The SDK builds the message, so transports only move bytes. The user's bubble shows at once and the agent's echo of it is not shown again. Taps are ignored while connecting or reconnecting, and from the start of the user's speech until the reply starts. Atext_input_errorfor the tap, or the user speaking before the agent takes it, fails it withvoice.turn.failed; asendthat throws showsvoice.turn.messageSendFailed. The tap is tracked asquerySubmitted, like a typed send. The composer stays read-only during voice, as on web. After voice ends, taps go through SSE as before.send(_:topic:)must deliver reliably and throw if it can't. It has no default implementation, so existing transports must add it. The sample app'sLiveKitTransportimplements it in feat: add voice to the demo app through a LiveKit transport #191.voice.turn.failed("Sorry, I couldn't process that. Please try again.") andvoice.turn.messageSendFailed("Sorry, your message couldn't be sent. Please try again."), same keys and defaults as web, in the style guide.getting-started.mdcoverssend(reliable delivery, throwing) and suggestion taps during voice.5. Held XDM context during voice
updateXDMContext) for the bootstrap's session, and the service uses it for every turn of the conversation. So the context is captured once, when the conversation starts, as on web. Updates made during the conversation apply from the next voice conversation or typed message.querySubmittedwith that captured context, matching what the service sends.6. Thinking indicator during voice
loading.message("Generating response from our knowledge base"), as typed chat does. It appears when the user's final words (or a suggestion tap) show, and the reply's first text replaces it in the same bubble.VoiceSessionControllerreports the wait toChatControllerthrough a new internal listener callback,voiceSession(_:didChangeAwaitingReply:). It turns off after the reply's first text, at the turn's end (completed, error,text_input_error, a failed send), when a newer turn replaces the turn, and when voice ends. An indicator still empty at that point is removed, so none is left after a stop or a failure.turn_completed(state=error).getting-started.mdmentions the indicator.7. One transport for the app, registered with
Concierge.setVoiceTransportvoiceTransport:argument onshow,presentandwrap, as proposed in this comment. The argument was never released, so nothing is deprecated.Concierge.setVoiceTransport(_ transport: VoiceTransport?)can be called from any thread, likesetAuthTokenProvider. Every chat reads the registered transport, so a new value reaches chats that are already open as well as later ones. The show/present (replace all) vs wrap (replace only what is passed) difference no longer applies to it.nil, the voice button stays while a conversation runs, so the user can stop it, and disappears once it ends. Resetting identities keeps the registered transport.ChatControllerreads the transport from a shared holder when voice starts instead of capturing it when the session is created. Voice now stays available while a conversation runs even without a transport, as on Android, so clearing it doesn't hide the stop button.getting-started.mdand the implementation guide register the transport once at launch, and the guide's identity reset notes say a reset ends the voice conversation and keeps the transport.API note
ChatState(public) is unchanged.ChatControllertracks a running voice conversation separately, so apps that switch overChatStateexhaustively keep compiling.Test plan
VoiceSessionControllerTests(64): session lifecycle, connect and reconnect timeouts, the background opt-in snapshot and the 60-minute cap (started on the first.connected, not restarted by reconnects, cancelled on end), credential validation (includingws/httprejected), permission, transport sharing and foreign callbacks, interruptions (including while connecting, and ending without.shouldResume), agent-ended sessions by reason, transcript assembly, turn tracking (new user turn, other and finished turn ids, error / empty / interrupted states, late error), suggestion sends (payload and topic, echo, gating,text_input_error, speech before the echo, send failure) and the thinking indicator's on and off signals, all through aFakeVoiceTransport.DataChannelMessageParserTests(22): including the fullui_payloadandtext_input_error.ChatControllerVoiceSessionTests(63): availability, backgrounding (kept with the opt-in once connecting, ended without it or before connect), the voice scroll anchor, permission before credentials (a denial starts nothing),makeSessionwiring, the registered transport (reaching an open chat, also from a background thread; cleared or replaced during a conversation), bootstrap/connection handoff, transcript rendering, end/failure/stop/cancel (including the agent ending with an error), transport reuse, one conversation app-wide, stale callbacks, gating, identity reset, each turn's end (reply rewritten with sources, cards and suggestions; failure copy), suggestion taps to the transport during voice and over SSE after it, the held XDM context and session sent with the bootstrap, a suggestion tap tracked with that context after it changes, and the thinking indicator (shown, replaced by the reply, removed on stop and on a newer turn).ThemeDecodingTests: the two new copy tokens.ComposerEditingViewTests: voice/send button placement (6 cases).MessageListViewShouldFillRemainingHeightTests(17): space reserved below the voice scroll anchor.UnitTestssuite: 1128 tests. The only failures are 9 snapshot tests (ProductCardCarouselSnapshotTests,PrivacyNoticeSnapshotTests), which fail the same way without this PR's changes on the local simulator, and the flakyConciergeTests.test_resetIdentities_staleCompletionDoesNotConsumeActiveRequest, which fails about 1 run in 10 without section 5 too.ConciergeDemoAppbuilds.AEPPluginSupportin its graph.LiveKitTransport.send: a product card arriving while the screen is locked renders with the reply after unlocking, and a suggestion tapped during voice reaches the agent, which answers by voice.