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
impl Client
Sourcepub fn new(options: ClientOptions) -> Result<Self>
pub fn new(options: ClientOptions) -> Result<Self>
Create a new Copilot client with the given options.
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Create a client builder for fluent configuration.
Sourcepub async fn force_stop(&self)
pub async fn force_stop(&self)
Force stop the client immediately.
Sourcepub async fn state(&self) -> ConnectionState
pub async fn state(&self) -> ConnectionState
Get the current connection state.
Sourcepub async fn create_session(
&self,
config: SessionConfig,
) -> Result<Arc<Session>>
pub async fn create_session( &self, config: SessionConfig, ) -> Result<Arc<Session>>
Create a new Copilot session.
Sourcepub async fn resume_session(
&self,
session_id: &str,
config: ResumeSessionConfig,
) -> Result<Arc<Session>>
pub async fn resume_session( &self, session_id: &str, config: ResumeSessionConfig, ) -> Result<Arc<Session>>
Resume an existing session.
Sourcepub async fn list_sessions(&self) -> Result<Vec<SessionMetadata>>
pub async fn list_sessions(&self) -> Result<Vec<SessionMetadata>>
List all available sessions.
Sourcepub async fn delete_session(&self, session_id: &str) -> Result<()>
pub async fn delete_session(&self, session_id: &str) -> Result<()>
Delete a session.
Sourcepub async fn get_last_session_id(&self) -> Result<Option<String>>
pub async fn get_last_session_id(&self) -> Result<Option<String>>
Get the ID of the most recently used session.
Sourcepub async fn ping(&self, message: Option<String>) -> Result<PingResponse>
pub async fn ping(&self, message: Option<String>) -> Result<PingResponse>
Send a ping to verify connection health.
Sourcepub async fn get_status(&self) -> Result<GetStatusResponse>
pub async fn get_status(&self) -> Result<GetStatusResponse>
Get CLI status including version and protocol information.
Sourcepub async fn get_auth_status(&self) -> Result<GetAuthStatusResponse>
pub async fn get_auth_status(&self) -> Result<GetAuthStatusResponse>
Get current authentication status.
Sourcepub async fn list_models(&self) -> Result<Vec<ModelInfo>>
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.
Sourcepub async fn clear_models_cache(&self)
pub async fn clear_models_cache(&self)
Clear the cached models list, forcing a fresh fetch on next list_models() call.
Sourcepub async fn get_foreground_session_id(
&self,
) -> Result<GetForegroundSessionResponse>
pub async fn get_foreground_session_id( &self, ) -> Result<GetForegroundSessionResponse>
Get the foreground session ID and workspace path.
Sourcepub async fn set_foreground_session_id(
&self,
session_id: &str,
) -> Result<SetForegroundSessionResponse>
pub async fn set_foreground_session_id( &self, session_id: &str, ) -> Result<SetForegroundSessionResponse>
Set the foreground session 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> 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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