pub struct SimpleInteractiveClient { /* private fields */ }Expand description
Interactive client for stateful conversations with Claude
This is the recommended client for interactive use. It provides a clean API that matches the Python SDK’s functionality.
Implementations§
Source§impl InteractiveClient
impl InteractiveClient
Sourcepub fn new(options: ClaudeCodeOptions) -> Result<Self>
pub fn new(options: ClaudeCodeOptions) -> Result<Self>
Create a new client
Sourcepub async fn send_and_receive(&mut self, prompt: String) -> Result<Vec<Message>>
pub async fn send_and_receive(&mut self, prompt: String) -> Result<Vec<Message>>
Send a message and receive all messages until Result message
Sourcepub async fn send_message(&mut self, prompt: String) -> Result<()>
pub async fn send_message(&mut self, prompt: String) -> Result<()>
Send a message without waiting for response
Sourcepub async fn receive_response(&mut self) -> Result<Vec<Message>>
pub async fn receive_response(&mut self) -> Result<Vec<Message>>
Receive messages until Result message (convenience method like Python SDK)
Sourcepub async fn receive_messages_stream(
&mut self,
) -> impl Stream<Item = Result<Message>> + '_
pub async fn receive_messages_stream( &mut self, ) -> impl Stream<Item = Result<Message>> + '_
Receive messages as a stream (streaming output support)
Returns a stream of messages that can be iterated over asynchronously.
This is similar to Python SDK’s receive_messages() method.
§Example
use cc_sdk::{InteractiveClient, ClaudeCodeOptions};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = InteractiveClient::new(ClaudeCodeOptions::default())?;
client.connect().await?;
// Send a message
client.send_message("Hello!".to_string()).await?;
// Receive messages as a stream
let mut stream = client.receive_messages_stream().await;
while let Some(msg) = stream.next().await {
match msg {
Ok(message) => println!("Received: {:?}", message),
Err(e) => eprintln!("Error: {}", e),
}
}
Ok(())
}Sourcepub async fn receive_response_stream(
&mut self,
) -> impl Stream<Item = Result<Message>> + '_
pub async fn receive_response_stream( &mut self, ) -> impl Stream<Item = Result<Message>> + '_
Receive messages as an async iterator until a Result message
This is a convenience method that collects messages until a Result message
is received, similar to Python SDK’s receive_response().
Sourcepub async fn interrupt(&mut self) -> Result<()>
pub async fn interrupt(&mut self) -> Result<()>
Send interrupt signal to cancel current operation
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Disconnect
Auto Trait Implementations§
impl Freeze for InteractiveClient
impl !RefUnwindSafe for InteractiveClient
impl Send for InteractiveClient
impl Sync for InteractiveClient
impl Unpin for InteractiveClient
impl !UnwindSafe for InteractiveClient
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