apiari_codex_sdk/lib.rs
1//! Rust SDK for the Codex CLI.
2//!
3//! This crate wraps the `codex` command-line tool, reading JSONL events from
4//! stdout when invoked with `codex exec --json`. Unlike the Claude SDK, this
5//! is **unidirectional** — the prompt goes as a CLI argument and stdin is
6//! `/dev/null`.
7//!
8//! # Quick start
9//!
10//! ```rust,no_run
11//! use apiari_codex_sdk::{CodexClient, ExecOptions, Event, Item};
12//!
13//! # async fn run() -> apiari_codex_sdk::error::Result<()> {
14//! let client = CodexClient::new();
15//! let mut execution = client.exec("List files in the current directory", ExecOptions {
16//! model: Some("o4-mini".into()),
17//! full_auto: true,
18//! ..Default::default()
19//! }).await?;
20//!
21//! while let Some(event) = execution.next_event().await? {
22//! match &event {
23//! Event::ItemCompleted { item: Item::AgentMessage { text, .. } } => {
24//! if let Some(text) = text {
25//! println!("{text}");
26//! }
27//! }
28//! Event::TurnCompleted { usage } => {
29//! if let Some(usage) = usage {
30//! println!("Tokens: {} in, {} out", usage.input_tokens, usage.output_tokens);
31//! }
32//! }
33//! _ => {}
34//! }
35//! }
36//! # Ok(())
37//! # }
38//! ```
39
40pub mod client;
41pub mod error;
42pub mod options;
43pub mod transport;
44pub mod types;
45
46// Re-export the most commonly used types at the crate root.
47pub use client::{CodexClient, Execution};
48pub use error::{Result, SdkError};
49pub use options::{ApprovalPolicy, ExecOptions, ResumeOptions, SandboxMode};
50pub use types::{Event, FileUpdateChange, Item, ThreadError, TodoItem, Usage};