#[cfg(feature = "voice")]
mod hub;
#[cfg(feature = "voice")]
mod session;
#[cfg(feature = "voice")]
mod source;
#[cfg(feature = "voice")]
pub mod spoken;
#[cfg(feature = "voice")]
mod visual;
#[cfg(all(feature = "voice", feature = "web"))]
mod web;
mod wire;
#[cfg(feature = "voice")]
pub use hub::{VoiceHub, VoiceHubBuilder};
#[cfg(feature = "voice")]
pub use session::{VoiceInput, VoiceLink, VoiceOutput};
#[cfg(feature = "voice")]
pub use source::{LiveVoice, VoiceSource};
#[cfg(feature = "voice")]
pub use visual::{FramePolicy, VisualInputs};
#[cfg(all(feature = "voice", feature = "web"))]
pub use web::{SOCKET_PATH, TICKET_TTL, router, socket_routes};
pub use wire::{
FRAME_AUDIO, FRAME_CAMERA, FRAME_SCREEN, InputSource, VisualSource, VoiceClientMessage,
VoiceModel, VoiceModels, VoiceTicket, VoiceTicketRequest, VoiceUpdate,
};
pub mod paths {
pub const VOICE: &str = "/surface/voice";
pub const SESSIONS: &str = "/surface/voice/sessions";
pub const SOCKET: &str = "/voice/socket";
}
#[cfg(feature = "voice")]
pub use error::VoiceError;
#[cfg(feature = "voice")]
#[derive(Debug)]
pub struct SpokenAnswer {
pub outcome: crate::CommandOutcome,
pub settled: Option<tokio::sync::oneshot::Receiver<crate::Result<crate::CommandOutcome>>>,
}
#[cfg(feature = "voice")]
mod error {
use adk_core::{AdkError, ErrorCategory, ErrorComponent};
use crate::error::SurfaceError;
#[derive(Debug, thiserror::Error)]
pub enum VoiceError {
#[error("no voice model '{0}' is offered here; pick one GET /api/surface/voice lists")]
UnknownModel(String),
#[error(
"session '{0}' is not one of your voice conversations; start a new one without a sessionId"
)]
NotYourSession(String),
#[error(
"the voice ticket is not valid: ask POST /api/surface/voice/sessions for a new one"
)]
Ticket,
#[error("the voice model failed: {0}")]
Provider(String),
#[error("the voice conversation could not start: {0}")]
Harness(String),
#[error("the voice conversation has ended; start a new one")]
Ended,
}
impl VoiceError {
pub fn code(&self) -> &'static str {
match self {
Self::UnknownModel(_) => "surface.voice.unknown_model",
Self::NotYourSession(_) => "surface.voice.not_your_session",
Self::Ticket => "surface.voice.ticket",
Self::Provider(_) => "surface.voice.provider",
Self::Harness(_) => "surface.voice.harness",
Self::Ended => "surface.voice.ended",
}
}
fn category(&self) -> ErrorCategory {
match self {
Self::UnknownModel(_) => ErrorCategory::InvalidInput,
Self::NotYourSession(_) => ErrorCategory::Forbidden,
Self::Ticket => ErrorCategory::Unauthorized,
Self::Provider(_) => ErrorCategory::Unavailable,
Self::Harness(_) => ErrorCategory::Internal,
Self::Ended => ErrorCategory::NotFound,
}
}
}
impl From<VoiceError> for SurfaceError {
fn from(error: VoiceError) -> Self {
SurfaceError::Source(AdkError::new(
ErrorComponent::Server,
error.category(),
error.code(),
error.to_string(),
))
}
}
}