Files
buzz/desktop/src-tauri/src/huddle/agent_tts_publisher.rs
klopez4212 8c0f42e187 Add mobile Huddles voice MVP (#6056)
## Summary
- add foreground mobile Huddles on Android and iOS with native Opus
capture/playback, mute, speaker routing, participants, lifecycle, and
minimized drawer UI
- keep mobile Huddle cards and roster state live, including ended rooms,
relay-resolved profiles, and agents
- broadcast desktop agent TTS through the existing Huddle audio protocol

## Scope
Foreground human-to-human voice MVP only. Agent setup/transcripts,
background calling, recording, and advanced device controls remain out
of scope.

## Validation
- `just mobile-check`
- `just mobile-test` — 1,500 passed
- `just desktop-check` and `just desktop-test` — 4,957 passed
- desktop typecheck, strict Clippy, and Tauri tests — 2,445 passed, 15
ignored
- mobile worktree identity contract checks
- physical Pixel/iPhone behavior reviewed during development

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Kenny Lopez <klopez4212@gmail.com>
Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Carl <3c4caeafb646d23867f1c4832e68211d77e2561946171625f75c3ce1a3f2670f@buzz.block.builderlab.xyz>
Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Co-authored-by: leader <71e9f2c44a6932b6772caaaccda1911d010463c3e2c6c40410b8329956046801@buzz.block.builderlab.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Mongo <9cfd347903944d5b85aa6c93d2ab67381b978a92a31914bca69998968752a1d7@buzz.block.builderlab.xyz>
2026-08-22 05:28:16 -07:00

76 lines
2.5 KiB
Rust

//! Establishes agent-authenticated publishers for locally synthesized speech.
use std::sync::Arc;
use super::{relay_api, tts};
use crate::app_state::AppState;
pub(super) async fn ensure(
app: &tauri::AppHandle,
state: &AppState,
pipeline: &tts::TtsPipeline,
speaker_pubkey: &str,
) -> Result<bool, String> {
if pipeline.has_audio_publisher(speaker_pubkey) {
return Ok(true);
}
let app_for_load = app.clone();
let speaker_for_load = speaker_pubkey.to_ascii_lowercase();
let record = tokio::task::spawn_blocking(move || {
crate::managed_agents::load_managed_agents(&app_for_load).map(|agents| {
agents.into_iter().find(|agent| {
agent.pubkey.eq_ignore_ascii_case(&speaker_for_load)
&& !agent.private_key_nsec.trim().is_empty()
})
})
})
.await
.map_err(|error| format!("managed-agent identity task failed: {error}"))??;
let Some(record) = record else {
return Ok(false);
};
let keys = nostr::Keys::parse(record.private_key_nsec.trim())
.map_err(|error| format!("managed-agent identity is unavailable: {error}"))?;
if !keys
.public_key()
.to_hex()
.eq_ignore_ascii_case(speaker_pubkey)
{
return Err("managed-agent identity does not match the Huddle speaker".to_string());
}
let (ephemeral_channel_id, parent_channel_id, local_tts_publishers) = {
let huddle = state.huddle()?;
(
huddle
.ephemeral_channel_id
.clone()
.ok_or("active Huddle has no backing channel")?,
huddle.parent_channel_id.clone(),
Arc::clone(&huddle.local_tts_publishers),
)
};
let has_bot_membership =
relay_api::fetch_channel_members_with_roles(&ephemeral_channel_id, state)
.await?
.into_iter()
.any(|(pubkey, role)| {
pubkey.eq_ignore_ascii_case(speaker_pubkey) && role.as_deref() == Some("bot")
});
if !has_bot_membership {
return Err("agent is not an active bot member of the Huddle".to_string());
}
let publisher = relay_api::connect_tts_audio_publisher(
&ephemeral_channel_id,
parent_channel_id.as_deref(),
state,
&keys,
record.auth_tag.as_deref(),
local_tts_publishers,
)
.await?;
pipeline.register_audio_publisher(speaker_pubkey, publisher);
Ok(true)
}