Add live WebRTC voice conversations to the TUI (#43581)

## What changed

- Add feature-gated `/voice`, `/voice mute`, and `/voice stop` commands with local WebRTC audio and app-server signaling.
- Show live transcripts, conversation status, and microphone and speaker levels. Preserve captions and undelivered answers across thread switches.
- Speak final answers from voice handoffs while keeping delegated reasoning and commentary hidden and typed answers unspoken.
- Retry eligible startup failures once and clean up voice sessions on thread switches and disconnects.
- Stop voice and block late handoffs after a misalignment policy violation. Remove realtime event payloads and spoken text from receipt and debug logs.

## Testing

Add coverage for voice command mapping, rejected starts, disconnect cleanup, delegated final-answer speech, late handoff rejection, and transcript and footer rendering.

GitOrigin-RevId: 11def1f86b0e023b21d0d92072d6636ccad89815
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-07 20:25:30 +00:00
1 parent 4110342321
commit b01c3986fd
70 files changed
+4421 -69

No files matched your search

+8 -1
View File
@@ -176,9 +176,15 @@ fn run(
let Some(peer) = transport.as_ref() else {
return Err(io::Error::other("voice transport not started"));
};
executor
let outcome = executor
.block_on(peer.apply_answer(sdp.into_sdp()))
.map_err(io::Error::other)?;
if outcome == transport::AnswerOutcome::TimedOut {
// The client reaps this helper before considering a fresh negotiation.
output.write_all(&encode_frame(&Message::TransportTimedOut {})?)?;
output.flush()?;
return Ok(());
}
answered = true;
Message::TransportReady {}
}
@@ -207,6 +213,7 @@ fn run(
| Message::ApplyAnswer { .. }
| Message::Offer { .. }
| Message::TransportReady {}
| Message::TransportTimedOut {}
| Message::OpenDevices {}
| Message::DevicesOpened {}
| Message::AudioControlsApplied {}
+10 -2
View File
@@ -59,6 +59,12 @@ impl PeerConnectionEventHandler for Events {
}
}
#[derive(Debug, PartialEq)]
pub(crate) enum AnswerOutcome {
Ready,
TimedOut,
}
pub(crate) struct Transport {
pub(crate) incoming: crate::incoming::Incoming,
pub(crate) audio: crate::audio_track::AudioTrack,
@@ -162,7 +168,7 @@ impl Transport {
.map_err(|_| "timed out gathering voice candidates")?
}
pub(crate) async fn apply_answer(&self, sdp: String) -> Result<()> {
pub(crate) async fn apply_answer(&self, sdp: String) -> Result<AnswerOutcome> {
let answer = RTCSessionDescription::answer(sdp).map_err(|_| "invalid voice answer")?;
let parsed = answer.unmarshal().map_err(|_| "invalid voice answer")?;
let mut seen = HashSet::new();
@@ -213,7 +219,9 @@ impl Transport {
.map_err(|_| "voice event channel closed")
})
.await
.map_err(|_| "timed out connecting voice peer")?
.map_or(Ok(AnswerOutcome::TimedOut), |result| {
result.map(|()| AnswerOutcome::Ready)
})
}
pub(crate) async fn close(&mut self) -> Result<()> {
+2 -1
View File
@@ -86,10 +86,11 @@ async fn check_negotiation(runtime: Arc<dyn webrtc::runtime::Runtime>) {
for _ in candidates.len()..MAX_REMOTE_CANDIDATES {
answer.push_str(&format!("{}\r\n", candidates[0]));
}
local
let outcome = local
.apply_answer(answer)
.await
.unwrap_or_else(|error| panic!("tcp={tcp}: {error}"));
assert_eq!(outcome, super::AnswerOutcome::Ready);
let channel = channels.recv().await.unwrap();
assert_eq!(
(