pub struct SessionHandle { /* private fields */ }Expand description
The public API surface for a Gemini Live session.
Cheaply cloneable (wraps Arc). Provides methods to send commands,
subscribe to events, and observe session state.
Implementations§
Source§impl SessionHandle
impl SessionHandle
Sourcepub fn new(
command_tx: Sender<SessionCommand>,
event_tx: Sender<SessionEvent>,
state: Arc<SessionState>,
phase_rx: Receiver<SessionPhase>,
) -> SessionHandle
pub fn new( command_tx: Sender<SessionCommand>, event_tx: Sender<SessionEvent>, state: Arc<SessionState>, phase_rx: Receiver<SessionPhase>, ) -> SessionHandle
Create a new session handle from its components.
Sourcepub fn with_audio_pacing(self, config: BackpressureConfig) -> SessionHandle
pub fn with_audio_pacing(self, config: BackpressureConfig) -> SessionHandle
Enable producer-side audio send pacing (token bucket).
Installed by the connection layer when
SessionConfig::audio_pacing is set.
Sourcepub fn set_task(&self, handle: JoinHandle<()>)
pub fn set_task(&self, handle: JoinHandle<()>)
Store the connection loop task handle.
Called by the transport layer after spawning the connection loop.
Sourcepub async fn join(&self) -> Result<(), JoinError>
pub async fn join(&self) -> Result<(), JoinError>
Wait for the session connection loop to complete.
Returns Ok(()) when the session disconnects normally.
Returns Err if the connection task panicked.
Only the first call across all clones actually awaits the task;
subsequent calls return Ok(()) immediately.
Sourcepub fn subscribe(&self) -> Receiver<SessionEvent>
pub fn subscribe(&self) -> Receiver<SessionEvent>
Subscribe to session events.
Sourcepub fn event_sender(&self) -> &Sender<SessionEvent>
pub fn event_sender(&self) -> &Sender<SessionEvent>
The event broadcaster, for a runtime that injects its own events
into the session stream (the L1 agent session does). Application code
wants subscribe.
Sourcepub fn resume_handle(&self) -> Option<String>
pub fn resume_handle(&self) -> Option<String>
The most recent session-resumption handle the server issued, if any.
Sourcepub fn phase(&self) -> SessionPhase
pub fn phase(&self) -> SessionPhase
Current session phase.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Session ID.
Sourcepub async fn wait_for_phase(&self, target: SessionPhase)
pub async fn wait_for_phase(&self, target: SessionPhase)
Wait for the session to reach a specific phase.
Sourcepub async fn send_audio(
&self,
data: impl Into<Bytes>,
) -> Result<(), SessionError>
pub async fn send_audio( &self, data: impl Into<Bytes>, ) -> Result<(), SessionError>
Send audio data (raw PCM16 bytes).
When SessionConfig::audio_pacing is configured, this paces the
caller: pushing audio faster than the configured sustained rate waits
here instead of overflowing the send queue.
Sourcepub async fn send_text(
&self,
text: impl Into<String>,
) -> Result<(), SessionError>
pub async fn send_text( &self, text: impl Into<String>, ) -> Result<(), SessionError>
Send a text message.
Sourcepub async fn send_tool_response(
&self,
responses: Vec<FunctionResponse>,
) -> Result<(), SessionError>
pub async fn send_tool_response( &self, responses: Vec<FunctionResponse>, ) -> Result<(), SessionError>
Send tool responses.
Sourcepub async fn send_video(
&self,
jpeg_data: impl Into<Bytes>,
) -> Result<(), SessionError>
pub async fn send_video( &self, jpeg_data: impl Into<Bytes>, ) -> Result<(), SessionError>
Send a video/image frame (raw JPEG bytes).
Sourcepub async fn update_instruction(
&self,
instruction: impl Into<String>,
) -> Result<(), SessionError>
pub async fn update_instruction( &self, instruction: impl Into<String>, ) -> Result<(), SessionError>
Update the system instruction mid-session.
Sourcepub async fn signal_activity_start(&self) -> Result<(), SessionError>
pub async fn signal_activity_start(&self) -> Result<(), SessionError>
Signal activity start (user started speaking).
Sourcepub async fn signal_activity_end(&self) -> Result<(), SessionError>
pub async fn signal_activity_end(&self) -> Result<(), SessionError>
Signal activity end (user stopped speaking).
Sourcepub async fn send_client_content(
&self,
turns: Vec<Content>,
turn_complete: bool,
) -> Result<(), SessionError>
pub async fn send_client_content( &self, turns: Vec<Content>, turn_complete: bool, ) -> Result<(), SessionError>
Send client content (turns + turn_complete flag). Used for injecting conversation history, context, or multi-turn text.
Sourcepub async fn disconnect(&self) -> Result<(), SessionError>
pub async fn disconnect(&self) -> Result<(), SessionError>
Gracefully disconnect the session.
Trait Implementations§
Source§impl Clone for SessionHandle
impl Clone for SessionHandle
Source§fn clone(&self) -> SessionHandle
fn clone(&self) -> SessionHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SessionHandle
impl Debug for SessionHandle
Source§impl SessionReader for SessionHandle
impl SessionReader for SessionHandle
Source§fn subscribe(&self) -> Receiver<SessionEvent>
fn subscribe(&self) -> Receiver<SessionEvent>
Source§fn phase(&self) -> SessionPhase
fn phase(&self) -> SessionPhase
Source§fn session_id(&self) -> &str
fn session_id(&self) -> &str
Source§impl SessionWriter for SessionHandle
impl SessionWriter for SessionHandle
Source§fn send_audio<'life0, 'async_trait>(
&'life0 self,
data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn send_audio<'life0, 'async_trait>(
&'life0 self,
data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn send_text<'life0, 'async_trait>(
&'life0 self,
text: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn send_text<'life0, 'async_trait>(
&'life0 self,
text: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn send_tool_response<'life0, 'async_trait>(
&'life0 self,
responses: Vec<FunctionResponse>,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn send_tool_response<'life0, 'async_trait>(
&'life0 self,
responses: Vec<FunctionResponse>,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn send_client_content<'life0, 'async_trait>(
&'life0 self,
turns: Vec<Content>,
turn_complete: bool,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn send_client_content<'life0, 'async_trait>(
&'life0 self,
turns: Vec<Content>,
turn_complete: bool,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn send_video<'life0, 'async_trait>(
&'life0 self,
jpeg_data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn send_video<'life0, 'async_trait>(
&'life0 self,
jpeg_data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn update_instruction<'life0, 'async_trait>(
&'life0 self,
instruction: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn update_instruction<'life0, 'async_trait>(
&'life0 self,
instruction: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn signal_activity_start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn signal_activity_start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn signal_activity_end<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn signal_activity_end<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Source§fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
SessionHandle: 'async_trait,
Auto Trait Implementations§
impl Freeze for SessionHandle
impl !RefUnwindSafe for SessionHandle
impl Send for SessionHandle
impl Sync for SessionHandle
impl Unpin for SessionHandle
impl !UnwindSafe for SessionHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].