use crate::llm::tools::{ParallelToolRunner, ToolRunner};
use crate::realtime::config::RealtimeVoiceConfig;
use crate::realtime::gateway::RealtimeVoiceGateway;
use crate::realtime::session::RealtimeSession;
use crate::realtime::transport::TransportError;
use crate::tracer::TracerSystem;
use std::sync::Arc;
use uuid::Uuid;
pub struct RealtimeVoiceBroker {
model: String,
gateway: Arc<dyn RealtimeVoiceGateway>,
config: RealtimeVoiceConfig,
tracer: Option<Arc<TracerSystem>>,
tool_runner: Arc<dyn ToolRunner>,
}
impl RealtimeVoiceBroker {
pub fn new(
model: impl Into<String>,
gateway: Arc<dyn RealtimeVoiceGateway>,
config: RealtimeVoiceConfig,
tracer: Option<Arc<TracerSystem>>,
tool_runner: Option<Arc<dyn ToolRunner>>,
) -> Self {
Self {
model: model.into(),
gateway,
config,
tracer,
tool_runner: tool_runner.unwrap_or_else(|| Arc::new(ParallelToolRunner::default())),
}
}
pub async fn connect(&self) -> Result<RealtimeSession, TransportError> {
let correlation_id = Uuid::new_v4().to_string();
let gateway_session =
self.gateway.open(&self.model, &self.config, Some(&correlation_id)).await?;
Ok(RealtimeSession::run(
gateway_session,
self.config.clone(),
self.tool_runner.clone(),
self.tracer.clone(),
correlation_id,
)
.await)
}
}