codex_codes/lib.rs
1//! A tightly typed Rust interface for the OpenAI Codex CLI JSON protocol.
2//!
3//! This crate provides type-safe representations of the Codex CLI's JSONL output,
4//! mirroring the structure of the official TypeScript SDK (`@openai/codex-sdk`).
5//!
6//! # Message Types
7//!
8//! The protocol uses two primary discriminated unions:
9//!
10//! - [`ThreadEvent`] — Events emitted during thread execution (thread/turn/item lifecycle)
11//! - [`ThreadItem`] — Data items representing agent actions (messages, commands, file changes, etc.)
12//!
13//! # Configuration Types
14//!
15//! - [`ThreadOptions`] — Per-thread settings (model, sandbox mode, approval policy)
16//! - [`ApprovalMode`], [`SandboxMode`], [`ModelReasoningEffort`], [`WebSearchMode`] — Typed enums
17//!
18//! # Example
19//!
20//! ```
21//! use codex_codes::{ThreadEvent, ThreadItem};
22//!
23//! let json = r#"{"type":"thread.started","thread_id":"th_abc"}"#;
24//! let event: ThreadEvent = serde_json::from_str(json).unwrap();
25//! ```
26
27mod io;
28
29// Events
30pub use io::events::{
31 ItemCompletedEvent, ItemStartedEvent, ItemUpdatedEvent, ThreadError, ThreadErrorEvent,
32 ThreadEvent, ThreadStartedEvent, TurnCompletedEvent, TurnFailedEvent, TurnStartedEvent, Usage,
33};
34
35// Items
36pub use io::items::{
37 AgentMessageItem, CommandExecutionItem, CommandExecutionStatus, ErrorItem, FileChangeItem,
38 FileUpdateChange, McpToolCallError, McpToolCallItem, McpToolCallResult, McpToolCallStatus,
39 PatchApplyStatus, PatchChangeKind, ReasoningItem, ThreadItem, TodoItem, TodoListItem,
40 WebSearchItem,
41};
42
43// Options
44pub use io::options::{
45 ApprovalMode, ModelReasoningEffort, SandboxMode, ThreadOptions, WebSearchMode,
46};