apiari_claude_sdk/lib.rs
1//! Rust SDK for the Claude CLI.
2//!
3//! This crate wraps the `claude` command-line tool, communicating via
4//! newline-delimited JSON (NDJSON) over stdin/stdout using the
5//! `--input-format stream-json --output-format stream-json` protocol.
6//!
7//! # Quick start
8//!
9//! ```rust,no_run
10//! use apiari_claude_sdk::{ClaudeClient, SessionOptions};
11//!
12//! # async fn run() -> apiari_claude_sdk::error::Result<()> {
13//! let client = ClaudeClient::new();
14//! let mut session = client.spawn(SessionOptions {
15//! model: Some("sonnet".into()),
16//! allowed_tools: vec!["Bash".into(), "Read".into()],
17//! ..Default::default()
18//! }).await?;
19//!
20//! session.send_message("List files in the current directory").await?;
21//!
22//! while let Some(event) = session.next_event().await? {
23//! match event {
24//! apiari_claude_sdk::Event::Assistant { message, tool_uses } => {
25//! for block in &message.message.content {
26//! if let apiari_claude_sdk::types::ContentBlock::Text { text } = block {
27//! print!("{text}");
28//! }
29//! }
30//! // Handle tool_uses if needed...
31//! drop(tool_uses);
32//! }
33//! apiari_claude_sdk::Event::Result(result) => {
34//! println!("\nDone! Session: {}", result.session_id);
35//! break;
36//! }
37//! _ => {}
38//! }
39//! }
40//! # Ok(())
41//! # }
42//! ```
43
44pub mod client;
45pub mod error;
46pub mod session;
47pub mod streaming;
48pub mod tools;
49pub mod transport;
50pub mod types;
51
52// Re-export the most commonly used types at the crate root.
53pub use client::{ClaudeClient, Event, Session};
54pub use error::{Result, SdkError};
55pub use session::{PermissionMode, SessionOptions};
56pub use streaming::{AssembledEvent, StreamAssembler};
57pub use tools::{ToolResult, ToolUse};
58pub use types::{
59 AssistantMessage, AssistantMessageContent, ContentBlock, InputMessage, Message, RateLimitEvent,
60 ResultMessage, StreamEvent, SystemMessage, UserMessage,
61};