LiveHandle

Struct LiveHandle 

Source
pub struct LiveHandle { /* private fields */ }
Expand description

Handle for interacting with a running Live session.

Provides send methods for audio/text/video, system instruction updates, event subscription, state access, telemetry, and graceful shutdown.

When ContextDelivery::Deferred is enabled, send_audio, send_text, and send_video automatically flush any pending context turns before forwarding the user content.

Implementations§

Source§

impl LiveHandle

Source

pub async fn send_audio(&self, data: Vec<u8>) -> Result<(), SessionError>

Send audio data (raw PCM16 16kHz bytes).

When deferred context delivery is enabled, any pending model-role context turns are flushed to the wire before the audio frame.

Source

pub async fn send_text( &self, text: impl Into<String>, ) -> Result<(), SessionError>

Send a text message.

When deferred context delivery is enabled, any pending model-role context turns are flushed to the wire before the text message.

Source

pub async fn send_video(&self, jpeg_data: Vec<u8>) -> Result<(), SessionError>

Send a video/image frame (raw JPEG bytes).

When deferred context delivery is enabled, any pending model-role context turns are flushed to the wire before the video frame.

Source

pub async fn update_instruction( &self, instruction: impl Into<String>, ) -> Result<(), SessionError>

Update the system instruction mid-session.

Source

pub async fn send_tool_response( &self, responses: Vec<FunctionResponse>, ) -> Result<(), SessionError>

Send tool responses manually (if not using auto-dispatch).

Source

pub async fn playback_drained(&self) -> Result<(), SessionError>

Notify the runtime that client-side playback has drained.

Voice UIs should call this only when it is safe for the model to speak, for example after browser speaker playback has drained and the user is not actively speaking. User audio/text sends intentionally flush context only and leave the prompt armed.

Source

pub async fn user_speech_started(&self) -> Result<(), SessionError>

Notify the runtime that client-side user speech has started.

This is the barge-in edge for voice clients: pending model prompts are cancelled before they can race with user audio, while queued context is kept so the next user send can still carry it.

Source

pub async fn user_speech_ended(&self) -> Result<(), SessionError>

Notify the runtime that client-side user speech has ended.

Source

pub fn voice_state(&self) -> VoiceRuntimeState

Snapshot the reactor-owned voice runtime state.

Source

pub fn input_vad_state(&self) -> BackendVadSnapshot

Snapshot backend input VAD state.

Source

pub async fn flush_deferred_prompt(&self) -> Result<(), SessionError>

Flush deferred context and any pending model prompt.

Prefer Self::playback_drained for voice clients. This compatibility method routes through the same reactor/effect executor path.

Source

pub fn writer(&self) -> Arc<dyn SessionWriter>

Get the user-facing session writer.

When deferred context delivery is enabled, this returns the DeferredWriter that flushes pending context before sends.

Source

pub fn subscribe(&self) -> Receiver<SessionEvent>

Subscribe to raw session events (for custom processing).

Source

pub fn phase(&self) -> SessionPhase

Get the current session phase.

Source

pub async fn disconnect(&self) -> Result<(), SessionError>

Gracefully disconnect the session.

Shutdown sequence:

  1. Cancel all in-flight background tool tasks (they are aborted at an await point; tool futures must therefore be drop-safe).
  2. Close the L0 session. The terminal Disconnected event makes the event router exit, which closes the lane channels.
  3. Grace-await the fast and control lanes (~250 ms each) so they can drain queued events and run their final persistence drain, then abort whatever is still stuck (e.g. a lane blocked in a slow tool).
  4. Cancel the telemetry lane.
Source

pub async fn done(&self) -> Result<(), SessionError>

Wait for the session to end (disconnect, GoAway, or error).

Source

pub fn session(&self) -> &SessionHandle

Get the underlying SessionHandle for advanced usage.

Source

pub fn resume_handle(&self) -> Option<String>

Latest session-resumption handle issued by the server, if any.

While session resumption is enabled (SessionConfig::session_resumption; L2: Live::builder().session_resume(true)), the Gemini server periodically sends SessionResumptionUpdate messages; this returns the most recent handle (also captured in persistence snapshots as SessionSnapshot::resume_handle).

To survive a server-initiated GoAway or a planned restart, read this handle (e.g. from the on_go_away callback) and pass it to session_resumption(Some(handle)) on the next connect’s SessionConfig. No automatic reconnect is performed — resumption is an explicit caller decision.

Returns None when resumption is disabled or no update has arrived yet.

Source

pub fn state(&self) -> &State

Access the shared State container.

Extraction results from TurnExtractors are stored here under the extractor’s name. Use state().get::<T>(name) to read typed values.

Source

pub fn telemetry(&self) -> &Arc<SessionTelemetry>

Access the session telemetry (auto-collected by the telemetry lane).

Use telemetry().snapshot() to get a JSON snapshot of all metrics.

Source

pub fn events(&self) -> Receiver<LiveEvent>

Subscribe to semantic events from the processor.

Returns a broadcast receiver. Call multiple times for independent subscribers. Zero-cost when no subscribers exist.

Source

pub fn stream(&self) -> LiveEventStream

Subscribe to semantic events as a [futures::Stream].

Stream-flavored sibling of events: each call creates an independent subscriber starting from the current point in the event flow. If the subscriber falls behind the broadcast buffer, the missed events are skipped and the stream continues; the stream ends when the session’s event channel closes. See LiveEventStream.

§Example
use futures::StreamExt;

let mut stream = handle.stream();
while let Some(ev) = stream.next().await {
    match ev {
        LiveEvent::TextDelta(t) => print!("{t}"),
        LiveEvent::TurnComplete => println!(),
        _ => {}
    }
}
Source

pub fn extracted<T: DeserializeOwned>(&self, name: &str) -> Option<T>

Convenience: get the latest extraction result by extractor name.

Source

pub fn explain(&self) -> Option<FlowExplanation>

Snapshot the governed flow’s control-plane state: active steps, which tools are admitted vs blocked (with reasons), and unmet requirements.

The deterministic answer to “why did the assistant ask that?” — computed against the live State and the marking the control lane maintains. Returns None when the session is not governed by a flow (Live::govern/observe was not used).

This is a synchronous snapshot: it briefly locks the shared FlowMonitor and never blocks on session I/O.

Source

pub fn why_blocked(&self) -> Option<FlowExplanation>

Why the governed flow is blocked right now — alias of explain, named for the common debugging question. Returns None when the session is not governed by a flow.

Trait Implementations§

Source§

impl Clone for LiveHandle

Source§

fn clone(&self) -> LiveHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,