Skip to main content

Client

Struct Client 

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

Copilot client for managing connections and sessions.

The client manages the connection to the Copilot CLI server and provides methods to create and manage conversation sessions.

§Example

use copilot_sdk::{Client, ClientOptions, SessionConfig};

#[tokio::main]
async fn main() -> copilot_sdk::Result<()> {
    // Create client with options
    let client = Client::new(ClientOptions::default())?;

    // Start the client
    client.start().await?;

    // Create a session
    let session = client.create_session(SessionConfig::default()).await?;

    // Send a message and collect response
    let response = session.send_and_collect("Hello!", None).await?;
    println!("{}", response);

    // Stop the client
    client.stop().await;
    Ok(())
}

Implementations§

Source§

impl Client

Source

pub fn new(options: ClientOptions) -> Result<Self>

Create a new Copilot client with the given options.

Source

pub fn builder() -> ClientBuilder

Create a client builder for fluent configuration.

Source

pub async fn start(&self) -> Result<()>

Start the client and connect to the server.

Source

pub async fn stop(&self) -> Vec<StopError>

Stop the client gracefully.

Source

pub async fn force_stop(&self)

Force stop the client immediately.

Source

pub async fn state(&self) -> ConnectionState

Get the current connection state.

Source

pub async fn create_session( &self, config: SessionConfig, ) -> Result<Arc<Session>>

Create a new Copilot session.

Source

pub async fn resume_session( &self, session_id: &str, config: ResumeSessionConfig, ) -> Result<Arc<Session>>

Resume an existing session.

Source

pub async fn list_sessions(&self) -> Result<Vec<SessionMetadata>>

List all available sessions.

Source

pub async fn delete_session(&self, session_id: &str) -> Result<()>

Delete a session.

Source

pub async fn get_last_session_id(&self) -> Result<Option<String>>

Get the ID of the most recently used session.

Source

pub async fn ping(&self, message: Option<String>) -> Result<PingResponse>

Send a ping to verify connection health.

Source

pub async fn get_status(&self) -> Result<GetStatusResponse>

Get CLI status including version and protocol information.

Source

pub async fn get_auth_status(&self) -> Result<GetAuthStatusResponse>

Get current authentication status.

Source

pub async fn list_models(&self) -> Result<Vec<ModelInfo>>

List available models with their metadata.

Results are cached after the first call. Use [clear_models_cache] to force a refresh.

§Errors

Returns an error if not authenticated or if the request fails.

Source

pub async fn clear_models_cache(&self)

Clear the cached models list, forcing a fresh fetch on next list_models() call.

Source

pub async fn get_foreground_session_id( &self, ) -> Result<GetForegroundSessionResponse>

Get the foreground session ID and workspace path.

Source

pub async fn set_foreground_session_id( &self, session_id: &str, ) -> Result<SetForegroundSessionResponse>

Set the foreground session ID.

Source

pub async fn on<F>(&self, handler: F) -> impl FnOnce()
where F: Fn(&SessionLifecycleEvent) + Send + Sync + 'static,

Register a handler for client-level lifecycle events.

Lifecycle events include session created, deleted, updated, foreground, and background. Returns an unsubscribe closure that removes the handler when called.

Source

pub async fn get_session(&self, session_id: &str) -> Option<Arc<Session>>

Get a session by ID.

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

§

impl !UnwindSafe 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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