Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
d0f050e
feat: add the voice transport interface and voice session logic
nozokada Oct 23, 2026
77478c6
feat: hold voice conversations through an app-provided transport
nozokada Oct 23, 2026
d8c832c
Merge remote-tracking branch 'origin/main' into feat/voice-transport
nozokada Oct 28, 2026
483e955
test: avoid weak let so the voice tests build with Xcode 16
nozokada Oct 26, 2026
9bf2102
Merge remote-tracking branch 'origin/main' into feat/voice-transport
nozokada Oct 28, 2026
324039f
feat: add voice to the demo app through a LiveKit transport
nozokada Oct 27, 2026
e266648
docs: walk through adding voice with the LiveKit transport
nozokada Oct 27, 2026
f1fb0bf
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Oct 28, 2026
aef8cb3
fix: release the microphone when a LiveKit voice connection fails or …
nozokada Oct 29, 2026
bd6095d
fix: let a new LiveKit voice connection start without waiting for a s…
nozokada Oct 29, 2026
4033bd4
fix: end a voice session that goes to the background while fetching c…
nozokada Oct 30, 2026
0d9ab4f
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Oct 30, 2026
1eb5e9d
fix: keep ChatState source compatible and ask for the microphone befo…
nozokada Oct 30, 2026
117f947
test: name the no-transport trailing control test after what it checks
nozokada Oct 30, 2026
5d48e30
docs: note that data handoffs are rejected during a voice conversation
nozokada Oct 30, 2026
e6b14b9
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Oct 30, 2026
446afe9
docs: state which disconnect reasons end a voice conversation normally
nozokada Oct 30, 2026
3c7ed94
feat: pass a VoiceConnection to the transport and support reconnecting
nozokada Nov 2, 2026
2e84e77
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 2, 2026
35e13e4
feat: report LiveKit reconnects to Brand Concierge in the demo transport
nozokada Nov 2, 2026
9a391bc
fix: accept only wss and https voice server URLs
nozokada Nov 3, 2026
6b85997
docs: explain why the voice session checks microphone permission again
nozokada Nov 3, 2026
87ba6ea
feat: let Concierge.wrap take a voice transport for the floating button
nozokada Nov 3, 2026
98d3463
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 3, 2026
5fc0a0d
fix: restore LiveKit's speaker preference when the demo transport dis…
nozokada Nov 3, 2026
3f9df1b
feat: pass the voice transport to the floating-button wrap in the dem…
nozokada Nov 3, 2026
52beed2
feat: fail a voice session whose transport does not connect within 20…
nozokada Nov 3, 2026
914e1d9
docs: mention wrap where the VoiceTransport docs list the APIs that t…
nozokada Nov 3, 2026
3a9113d
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 3, 2026
08c9583
fix: allow one voice conversation at a time across the app
nozokada Nov 3, 2026
cb6f7eb
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 3, 2026
18e7bd5
fix: apply audio interruptions while connecting and end the session w…
nozokada Nov 3, 2026
26c021a
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 3, 2026
0bb596b
docs: describe how voice handles interruptions that can't resume
nozokada Nov 3, 2026
bebbd1b
fix: fail a voice session the agent ends because of an error
nozokada Nov 3, 2026
0471fc1
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 3, 2026
01d960b
fix: keep voice replies on screen as they arrive
nozokada Nov 5, 2026
45c41f8
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 5, 2026
51f675a
feat: keep a voice conversation running in the background when the tr…
nozokada Nov 9, 2026
eb7df8f
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 9, 2026
88c1efe
feat: keep demo app voice conversations running in the background
nozokada Nov 9, 2026
466a5a8
Merge branch 'feat/voice-bootstrap' into feat/voice-transport
nozokada Nov 9, 2026
1ec4daa
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 9, 2026
28c5ac8
Merge branch 'feat/voice-bootstrap' into feat/voice-transport
nozokada Nov 10, 2026
58763c4
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 10, 2026
233375f
docs(voice): add prerequisites and limitations for voice conversations
nozokada Nov 12, 2026
5c39e2c
docs(voice): shorten the conversation behavior description
nozokada Nov 12, 2026
b497a64
feat: parse the full voice ui_payload and text_input_error
nozokada Nov 17, 2026
9922726
feat: render each voice turn's end like a typed turn
nozokada Nov 17, 2026
02db066
feat: send prompt suggestions tapped during voice to the voice agent
nozokada Nov 17, 2026
575c58a
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 17, 2026
83ff211
feat: send voice text prompts from the LiveKit transport
nozokada Nov 17, 2026
0592621
fix: track fixed voice failure messages instead of transport error text
nozokada Nov 18, 2026
5fddae4
fix: remove a voice bubble whose final transcript is empty
nozokada Nov 18, 2026
7179ff1
docs: ask voice transports to report a failed microphone change
nozokada Nov 19, 2026
e8b0e61
fix: report a failed microphone change from the demo transport
nozokada Nov 19, 2026
c6d10a1
Merge branch 'feat/voice-bootstrap' into feat/voice-transport
nozokada Nov 20, 2026
2fa5129
feat: freeze the held XDM context for a voice conversation
nozokada Nov 20, 2026
e1b3d24
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 20, 2026
8779a2c
docs: say voice conversations send the XDM context captured at the start
nozokada Nov 20, 2026
e7b025f
Show the thinking indicator while a voice turn waits for its reply
nozokada Nov 21, 2026
3e69963
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 21, 2026
565a1c7
Register the voice transport with Concierge.setVoiceTransport
nozokada Nov 23, 2026
351c109
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 23, 2026
d3d7ad5
Register the demo's voice transport at launch
nozokada Nov 23, 2026
6bc93cd
Align voice availability wording with the registered transport
nozokada Nov 23, 2026
2bf3236
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 23, 2026
8daebd0
Fix the step 4 link in the background conversations section
nozokada Nov 23, 2026
d582511
List the voice conversation and transport in the identity reset docs
nozokada Nov 23, 2026
dd39ea6
Merge branch 'feat/voice-transport' into feat/demo-app-voice
nozokada Nov 23, 2026
bbd8e2d
Merge remote-tracking branch 'origin/feature/voice' into feat/voice-t…
nozokada Nov 24, 2026
4a9eb76
Merge remote-tracking branch 'fork/feat/voice-transport' into feat/de…
nozokada Nov 24, 2026
4a4e251
fix: send the resolved auth token with the voice bootstrap
nozokada Nov 24, 2026
b563f3d
Merge remote-tracking branch 'fork/feat/voice-transport' into feat/de…
nozokada Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 72 additions & 4 deletions AEPBrandConcierge.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

459 changes: 450 additions & 9 deletions AEPBrandConcierge/Sources/Controllers/ChatController.swift

Large diffs are not rendered by default.

711 changes: 711 additions & 0 deletions AEPBrandConcierge/Sources/Controllers/VoiceSessionController.swift

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions AEPBrandConcierge/Sources/Core/Concierge+PublicAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public extension Concierge {
ConciergeAuthTokenResolver.shared.setProvider(provider, timeout: timeout)
}

// MARK: - Voice

/// Registers the app's voice transport, which carries voice conversations. The chat shows the
/// voice button only while a transport is registered. See `VoiceTransport`.
///
/// Applies to chats already open and to chats opened later. A running voice conversation keeps the
/// transport it started with; after `nil`, the voice button disappears once no conversation runs.
/// Register one long-lived instance, for example at app launch. The SDK keeps a strong reference
/// to it until it is replaced or cleared. Can be called from any thread.
///
/// - Parameter transport: The app's transport, or `nil` to turn voice conversations off.
static func setVoiceTransport(_ transport: VoiceTransport?) {
ConciergeVoiceTransportHolder.shared.set(transport)
}

// MARK: - XDM Context

/// Applies a JSON Merge Patch (RFC 7396) to the SDK's held XDM context, which is merged into
Expand Down
95 changes: 95 additions & 0 deletions AEPBrandConcierge/Sources/Models/Voice/DataChannelMessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2026 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import Foundation

/// Swift mirror of web's data-channel message contract (`LiveKitContracts.ts`). The worker on the
/// other end is the same backend process regardless of client language, so the type/field names
/// here are copied verbatim from the TypeScript source and must not drift.
///
/// The worker sends two on-wire formats — type-based (user STT `transcript_delta`, `session_notice`)
/// and event-based (assistant `text_delta`/`turn_completed`/…) — which `DataChannelMessageParser`
/// normalizes into these cases (mirroring web's `parseDataChannelMessage`). Only the subset the
/// voice conversation consumes is modeled.
enum DataChannelMessage {
case transcriptDelta(TranscriptDeltaData)
case turnDone(TurnDoneData)
case uiPayload(UiPayloadData)
case sessionNotice(SessionNoticeData)
/// The worker rejected a `text_prompt` this client sent.
case textInputError(TextInputErrorData)
/// A coarse worker state signal (`turn_started`, `state_update`, `response_metadata`, `tts_hint`).
case stateUpdate(state: String)
}

/// An incremental transcript chunk. User chunks arrive type-based; assistant chunks are normalized
/// from the worker's `text_delta` events. Mirrors web's `TranscriptDeltaData`.
struct TranscriptDeltaData: Equatable {
enum Role: String { case user, assistant }

let role: Role
let turnId: String?
let delta: String
let sequence: Int
/// Whether this is the last chunk of the turn's transcript (user STT sets it; assistant deltas
/// are always non-final — the assistant's completion is signaled by `turn_done` instead).
let final: Bool
}

/// The completed assistant turn. Mirrors web's `TurnDoneData` (normalized from `turn_completed`).
struct TurnDoneData: Equatable {
enum TurnState: String { case completed, interrupted, error }

let fullText: String
let state: TurnState
let turnId: String?
}

/// A turn's rich content: citation sources, prompt suggestions, and product cards and CTAs. Mirrors
/// web's `UiPayloadData`, decoded into the models typed chat uses. The worker can send several per
/// turn; each is a snapshot of the whole turn so far, so the latest one replaces the earlier ones.
/// `widgets` is not modeled: the SDK has no widget support.
struct UiPayloadData {
let turnId: String?
let sources: [Source]
let promptSuggestions: [String]
let multimodalElements: [MultimodalElement]

var isEmpty: Bool {
sources.isEmpty && promptSuggestions.isEmpty && multimodalElements.isEmpty
}
}

/// The worker's rejection of a `text_prompt`, for example `voice_turn_in_progress` when the user is
/// speaking. `turnId` is the client's `turn_id` for that prompt.
struct TextInputErrorData: Equatable {
let turnId: String?
let reason: String
}

/// The worker's terminal EndReason for a session, validated against the known set rather than
/// trusting the raw wire string (a newer worker's unknown reason parses to `nil`, never a falsely
/// narrowed value). Mirrors web's `EndReason`.
enum EndReason: String {
case roomEmptyTimeout = "room_empty_timeout"
case userJoinTimeout = "user_join_timeout"
case workerShutdown = "worker_shutdown"
case userInactivityTimeout = "user_inactivity_timeout"
case error
}

/// A worker session notice. Mirrors web's `SessionNoticeData` union; an unrecognized `kind` parses
/// to `nil` so the caller drops it rather than passing through a malformed shape.
enum SessionNoticeData: Equatable {
case userSilenceWarning(silenceSeconds: Double)
case sessionEnded(reason: EndReason?)
}
182 changes: 182 additions & 0 deletions AEPBrandConcierge/Sources/Models/Voice/DataChannelMessageParser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
Copyright 2026 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import Foundation

/// Parses a raw data-channel JSON object into a typed `DataChannelMessage`, mirroring web's
/// `parseDataChannelMessage` (`voiceStreamingUtils.ts`). Handles both on-wire formats:
///
/// - **Type-based** (user STT / notices): `{ "type": "transcript_delta", "data": { … } }`
/// - **Event-based** (assistant turn messages): `{ "event": "turn_completed", "fullText": "…" }`
///
/// Returns `nil` for a message that matches no known format, so callers drop it rather than acting
/// on a malformed shape. Web handles `text_input_error` before this parser; here it is one more
/// type-based case.
enum DataChannelMessageParser {

/// Parses raw `Data` (a single data-channel frame) into a typed message, or `nil` if the bytes
/// aren't a JSON object or don't match a known format.
static func parse(_ data: Data) -> DataChannelMessage? {
guard let object = try? JSONSerialization.jsonObject(with: data),
let raw = object as? [String: Any] else {
return nil
}
return parse(raw)
}

/// Parses an already-deserialized JSON object. Mirrors `parseDataChannelMessage(msg)`.
static func parse(_ raw: [String: Any]) -> DataChannelMessage? {
// Type-based format (user STT transcript_delta, session_notice, …).
if let type = raw["type"] as? String {
return buildTypeMessage(type: type, raw: raw)
}
// Event-based format (assistant turn messages from the worker).
if let event = raw["event"] as? String {
return buildEventMessage(event: event, raw: raw)
}
return nil
}

// MARK: - Type-based (mirrors buildTypeMessage)

private static func buildTypeMessage(type: String, raw: [String: Any]) -> DataChannelMessage? {
switch type {
case "transcript_delta":
guard let payload = raw["data"] as? [String: Any] else { return nil }
let delta = TranscriptDeltaData(
role: (payload["role"] as? String) == "assistant" ? .assistant : .user,
turnId: asTurnId(payload["turnId"]),
delta: asString(payload["delta"]),
sequence: asNumber(payload["sequence"]),
final: (payload["final"] as? Bool) == true
)
return .transcriptDelta(delta)

case "session_notice":
guard let notice = parseSessionNoticeData(raw["data"]) else { return nil }
return .sessionNotice(notice)

case "text_input_error":
let payload = raw["data"] as? [String: Any] ?? [:]
return .textInputError(TextInputErrorData(
turnId: asTurnId(payload["turnId"]),
reason: asString(payload["reason"])
))

default:
// Other type-based messages (e.g. state carriers) surface as a coarse state update.
return .stateUpdate(state: type)
}
}

// MARK: - Event-based (mirrors buildEventMessage)

private static func buildEventMessage(event: String, raw: [String: Any]) -> DataChannelMessage? {
switch event {
case "text_delta":
// Assistant transcript chunk — always non-final; completion comes via `turn_completed`.
return .transcriptDelta(TranscriptDeltaData(
role: .assistant,
turnId: asTurnId(raw["turnId"]),
delta: asString(raw["delta"]),
sequence: asNumber(raw["sequence"]),
final: false
))

case "turn_completed":
return .turnDone(TurnDoneData(
fullText: asString(raw["fullText"]),
state: TurnDoneData.TurnState(rawValue: asString(raw["state"], "completed")) ?? .completed,
turnId: asTurnId(raw["turnId"])
))

case "ui_payload":
return .uiPayload(parseUiPayloadData(raw))

case "turn_started":
return .stateUpdate(state: "turn_started")

case "state_update":
return .stateUpdate(state: asString(raw["state"], "state_update"))

case "response_metadata", "tts_hint":
return .stateUpdate(state: event)

default:
return nil
}
}

// MARK: - UI payload

/// Decodes each field on its own, so one malformed field drops only that field's content.
private static func parseUiPayloadData(_ raw: [String: Any]) -> UiPayloadData {
UiPayloadData(
turnId: asTurnId(raw["turnId"]),
sources: decode([Source].self, from: raw["sources"]) ?? [],
promptSuggestions: (raw["promptSuggestions"] as? [Any])?.compactMap { $0 as? String } ?? [],
multimodalElements: decode(MultimodalElements.self, from: raw["multimodalElements"])?.elements ?? []
)
}

private static func decode<T: Decodable>(_ type: T.Type, from value: Any?) -> T? {
guard let value, JSONSerialization.isValidJSONObject(value),
let data = try? JSONSerialization.data(withJSONObject: value) else {
return nil
}
return try? JSONDecoder().decode(type, from: data)
}

// MARK: - Session notice (mirrors parseSessionNoticeData)

private static func parseSessionNoticeData(_ raw: Any?) -> SessionNoticeData? {
guard let data = raw as? [String: Any], let kind = data["kind"] as? String else {
return nil
}
switch kind {
case "user_silence_warning":
return .userSilenceWarning(silenceSeconds: asDouble(data["silenceSeconds"]))
case "session_ended":
return .sessionEnded(reason: asEndReason(data["reason"]))
default:
return nil
}
}

// MARK: - Coercion helpers (mirror asString/asTurnId/asNumber/asEndReason)

private static func asString(_ value: Any?, _ fallback: String = "") -> String {
value as? String ?? fallback
}

/// Preserves the worker's omit-when-unknown convention: anything that isn't a non-empty string
/// becomes `nil`, never `""` (an empty id would compare equal across turns).
private static func asTurnId(_ value: Any?) -> String? {
if let string = value as? String, !string.isEmpty { return string }
return nil
}

private static func asNumber(_ value: Any?, _ fallback: Int = 0) -> Int {
(value as? NSNumber)?.intValue ?? fallback
}

private static func asDouble(_ value: Any?, _ fallback: Double = 0) -> Double {
(value as? NSNumber)?.doubleValue ?? fallback
}

/// Validates a wire `reason` against the known `EndReason` set rather than trusting the raw
/// string — a missing or not-yet-modeled value (a worker newer than this client) becomes `nil`.
private static func asEndReason(_ value: Any?) -> EndReason? {
guard let string = value as? String else { return nil }
return EndReason(rawValue: string)
}
}
Loading
Loading