Skip to main content

RealtimeBackend

Trait RealtimeBackend 

Source
pub trait RealtimeBackend:
    RealtimeLlm
    + RealtimeKickoff
    + Send { }
Expand description

A boxable realtime backend: anything that is both a RealtimeLlm and a RealtimeKickoff. The blanket impl makes every such type qualify, and the Box<dyn RealtimeBackend> impls below let a consuming app’s build_realtime return ONE boxed type across providers (e.g. GeminiLive directly, or a connector wrapped in ServiceRealtimeAdapter) and still hand it to build_s2s_task — which is generic over RealtimeLlm + RealtimeKickoff. This is what keeps provider selection in the app a set of one-liners with no per-provider glue (the realtime analogue of the cascaded Box<dyn LlmService> factory).

Trait Implementations§

Source§

impl RealtimeKickoff for Box<dyn RealtimeBackend>

Source§

fn kickoff<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), FlowcatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Trigger an initial model turn so the bot speaks first.
Source§

impl RealtimeLlm for Box<dyn RealtimeBackend>

Source§

fn connect<'life0, 'async_trait>( &'life0 mut self, setup: RealtimeSetup, ) -> Pin<Box<dyn Future<Output = Result<(), FlowcatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Open the session with the initial system prompt + tools + audio rates.
Source§

fn send_audio<'life0, 'async_trait>( &'life0 mut self, chunk: AudioChunk, ) -> Pin<Box<dyn Future<Output = Result<(), FlowcatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream a chunk of caller audio (16 kHz PCM) to the model.
Source§

fn update_system<'life0, 'async_trait>( &'life0 mut self, prompt: String, tools: Vec<ToolDecl>, ) -> Pin<Box<dyn Future<Output = Result<(), FlowcatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Replace the active system prompt and tool set (on a brain transition).
Source§

fn send_tool_result<'life0, 'async_trait>( &'life0 mut self, id: String, result: Value, ) -> Pin<Box<dyn Future<Output = Result<(), FlowcatError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the result of a tool/function call back to the model.
Source§

fn next_event<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Option<RealtimeEvent>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Await the next model event, or None when the session has closed.
Source§

fn event_notify(&self) -> Option<Arc<Notify>>

A Notify that fires whenever a model event becomes available, so a consumer can await readiness WITHOUT holding this session’s lock across next_event (which would starve send_audio). None (the default) means the provider doesn’t support the non-blocking path and the consumer falls back to the blocking next_event. GeminiLive returns Some.
Source§

fn poll_event<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = PollEvent> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Non-blocking sibling of next_event: return the next event if one is immediately ready, else PollEvent::Pending (the caller should event_notify().notified().await — lock released — then re-poll). The default blocks (legacy behaviour); providers that return a real event_notify MUST override this to be genuinely non-blocking.
Source§

fn input_sample_rate(&self) -> u32

The PCM sample rate (Hz) the model expects on its audio input. The s2s pipeline resamples caller audio to this before send_audio and advertises it to the model in RealtimeSetup::input_sample_rate. Default 16 kHz (Gemini Live); a provider that requires a different input rate (OpenAI Realtime needs ≥ 24 kHz) overrides this.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§