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

@@ -26,6 +26,13 @@ impl MisalignmentReview {
pub(super) struct MisalignmentViolation {
turn_id: Option<String>,
review: Option<Arc<MisalignmentReview>>,
retired_voice: bool,
}
#[derive(Clone, Copy, Eq, PartialEq)]
pub(crate) enum MisalignmentTurnSource {
ServerNotification,
AcknowledgedContinuation,
}
const MISALIGNMENT_POLICY_TITLE: &str = "Chat stopped as a precaution";
@@ -41,6 +48,7 @@ impl ChatWidget {
&& !matches!(
op,
AppCommand::Interrupt
| AppCommand::RealtimeConversationStop { .. }
| AppCommand::CleanBackgroundTerminals
| AppCommand::OverrideTurnContext { .. }
| AppCommand::ReloadUserConfig
@@ -80,6 +88,10 @@ impl ChatWidget {
{
return;
}
let retired_voice = self.realtime_conversation_is_running();
if retired_voice {
self.stop_realtime_conversation();
}
let review = self.thread_id.zip(turn_id.clone()).zip(details).map(
|((thread_id, turn_id), details)| {
Arc::new(MisalignmentReview {
@@ -89,7 +101,11 @@ impl ChatWidget {
})
},
);
self.misalignment_policy_violation = Some(MisalignmentViolation { turn_id, review });
self.misalignment_policy_violation = Some(MisalignmentViolation {
turn_id,
review,
retired_voice,
});
self.input_queue.clear();
self.finalize_turn();
self.refresh_pending_input_preview();
@@ -211,11 +227,19 @@ impl ChatWidget {
});
}
pub(crate) fn clear_misalignment_for_new_turn(&mut self, turn_id: &str) {
pub(crate) fn clear_misalignment_for_new_turn(
&mut self,
turn_id: &str,
source: MisalignmentTurnSource,
) {
if self
.misalignment_policy_violation
.as_ref()
.is_some_and(|violation| violation.turn_id.as_ref().is_some_and(|id| id != turn_id))
.is_some_and(|violation| {
violation.turn_id.as_ref().is_some_and(|id| id != turn_id)
&& (!violation.retired_voice
|| source == MisalignmentTurnSource::AcknowledgedContinuation)
})
{
self.misalignment_policy_violation = None;
self.bottom_pane.dismiss_view_by_id(PRECAUTION_VIEW);