Skip to main content

GeminiConnection

Struct GeminiConnection 

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

A live Gemini session that implements Connection.

Implementations§

Source§

impl GeminiConnection

Source

pub fn history_bytes(&self) -> Result<Vec<u8>>

Snapshot the current conversation history as opaque bytes. Round-trips through set_history_bytes; the on-disk format is not part of the public API and may change between minor versions.

Source

pub fn set_thinking_override(&self, level: Option<ThinkingLevel>)

Set (or clear, with None) the PER-TURN thinking override — the difficulty-router seam. Applies to the NEXT turn’s model call only; the session’s configured thinking is restored after. None (the default) means “use the configured level”. Cheap to call between turns; does NOT rebuild the connection or touch history.

Source

pub fn set_model_override(&self, model: Option<String>)

Set (or clear, with None) the PER-TURN model override — the difficulty-router model seam (#7), parallel to set_thinking_override. Applies to the NEXT turn only; the configured model is restored after. None (the default) is a no-op. The caller MUST pass a same-backend id no more capable than the session’s selected model — switching backends is unsafe (different wire format + history shape) and must never be done here. Cheap: does NOT rebuild the connection or touch history; the proxy routes every model to the same endpoint, so only the request’s model field changes.

Source

pub fn set_history_bytes(&self, bytes: &[u8]) -> Result<()>

Replace the entire conversation history with one previously returned by history_bytes. Use this on connection start to resume a saved session; calling it mid-turn is undefined.

Source

pub async fn compact(&self) -> bool

Manually trigger context compaction. Summarises older history entries and replaces them with a single synthetic turn, freeing context-window budget. Returns true if compaction changed the history, false if it was too short or the summarisation was a no-op. Never errors — failures are logged and silently skipped.

Source

pub fn clear_history(&self)

Wipe the entire conversation history, returning the connection to a fresh, empty context. Synchronous (no network). Backs crate::Agent::clear_history — the in-tab clear_context tool. Resets only the history and the per-turn bookkeeping that could otherwise re-trigger compaction on the now-tiny history; the live step broadcast and conversation_id are left untouched.

Source

pub fn transcript(&self) -> Vec<TranscriptEntry>

Project the wire history into a flat sequence of user/assistant turns suitable for repainting a UI. Tool-call activity (FunctionCall / FunctionResponse) is surfaced as TranscriptToolCalls (matched by name), so a restored session shows what the agent DID, not just what it said.

Trait Implementations§

Source§

impl Connection for GeminiConnection

Source§

fn is_idle(&self) -> bool

True when the backend reports no active turn. Backed by an AtomicBool so callers may poll without contention.
Source§

fn conversation_id(&self) -> &str

The stable identifier the backend assigned to this conversation.
Source§

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

Send a user prompt. Returns once the message is dispatched — the response arrives via Connection::subscribe_steps.
Source§

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

Push an out-of-band trigger event into the agent. Unlike send, this does not switch the turn boundary.
Source§

fn send_tool_results<'life0, 'async_trait>( &'life0 self, _results: Vec<ToolResult>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the next-batch results for outstanding tool calls. Backends that dispatch tools inline (Gemini) accept this as a no-op.
Source§

fn subscribe_steps(&self) -> StepStream

Stream of steps as the backend produces them. Each call returns an independent cursor; the underlying source is typically a broadcast channel so late subscribers see steps that arrive after they subscribe.
Source§

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

Park the caller until the backend transitions to idle.
Source§

fn cancel_turn(&self)

Request cooperative cancellation of the in-flight turn. The backend stops at its next safe boundary (between streamed chunks / before the next model call or tool dispatch) and emits a terminal step, so the turn ends cleanly. Idempotent and safe to call when idle. Default: no-op, for backends without cancellation support.
Source§

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

Tear the connection down. Idempotent.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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, 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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