Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Available on crate feature async-client only.
Expand description

A harness session that drives whole turns.

Client wraps RawClient with the three things every caller ends up writing otherwise: Step assembly from delta frames, replies to the harness’s tool, hook, policy, and question requests, and turn-completion detection from trajectory state.

use antigravity_codes::{Client, HarnessOptions, ModelBuilder};

let mut client = Client::launch(
    HarnessOptions::new()
        .workspace("/tmp/project")
        .model(ModelBuilder::gemini("gemini-flash-latest", std::env::var("GEMINI_API_KEY").unwrap())),
)
.await?;

let mut turn = client.send("What files are here?").await?;
while let Some(step) = turn.next_step().await? {
    if let Some(text) = step.user_facing_text() {
        println!("{text}");
    }
}

client.shutdown().await?;

Implementations§

Source§

impl Client

Source

pub async fn launch(options: HarnessOptions) -> Result<Self>

Launches a harness with no client-side handlers registered.

Source

pub async fn launch_with( options: HarnessOptions, handlers: Handlers, ) -> Result<Self>

Launches a harness with handlers for its callbacks.

Source

pub fn cascade_id(&self) -> Option<&str>

The conversation id, which the harness calls a “cascade id”.

Pass it to HarnessOptions::cascade_id to resume this conversation in a later process.

Source

pub fn initialize_response(&self) -> &InitializeConversationResponse

The initialize reply, including any replayed history.

Source

pub fn usage(&self) -> Option<&UsageMetadata>

Cumulative token usage for the conversation, as last reported.

Source

pub fn trajectory_usage(&self) -> &HashMap<String, UsageMetadata>

Per-trajectory token usage, which separates subagent spend from the main conversation’s.

Source

pub fn raw(&mut self) -> &mut RawClient

The underlying frame-level client, for anything this layer does not model.

Source

pub async fn send(&mut self, prompt: impl Into<String>) -> Result<Turn<'_>>

Sends a prompt and returns the turn it started.

Source

pub async fn send_event(&mut self, event: InputEvent) -> Result<Turn<'_>>

Sends an arbitrary input frame and treats it as the start of a turn.

Use this for multimodal input (complex_user_input) or to fire an automated_trigger.

Source

pub async fn cancel(&mut self) -> Result<()>

Asks the harness to abandon the turn in flight.

The turn does not end here — the harness finishes what it was doing and reports STATE_CANCELLED, which the in-progress Turn observes.

Source

pub async fn shutdown(self) -> Result<()>

Ends the session cleanly and stops the process.

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

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, 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> 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