codex_app_server_client/lib.rs
1// Render per-item feature-requirement badges when rustdoc runs on nightly with
2// `--cfg docsrs` (docs.rs posture; locally via `cargo xtask doc --docsrs-cfg`).
3// Inert under the stable CI doc gate: stable rustdoc never sets `docsrs`.
4#![cfg_attr(docsrs, feature(doc_auto_cfg))]
5//! Standalone async Rust client for the [Codex CLI's `app-server` v2 JSON-RPC
6//! protocol](https://developers.openai.com/codex/app-server).
7//!
8//! `codex app-server` is the interface Codex uses to power rich clients (the
9//! VS Code extension, the Codex app). This crate spawns (or connects to) an
10//! app-server process, speaks its newline-delimited JSON-RPC 2.0 wire format,
11//! and exposes every v2 method as a typed async function.
12//!
13//! This crate has **zero dependencies on anything else in the workspace it
14//! lives in** - only published crates.io dependencies - so it can be lifted
15//! into another project wholesale. See `README.md` for how its vendored
16//! protocol schema was derived and how to regenerate it.
17//!
18//! # Quick start
19//!
20//! ```no_run
21//! use codex_app_server_client::{CodexSession, DenyAllApprovalHandler, SessionOptions};
22//!
23//! # async fn run() -> codex_app_server_client::Result<()> {
24//! let mut session = CodexSession::spawn(SessionOptions::new("my_integration", "0.1.0")).await?;
25//! let result = session
26//! .run_text_turn_with_model_and_handler(
27//! "gpt-5",
28//! "Say hello in one sentence.",
29//! &DenyAllApprovalHandler::default(),
30//! )
31//! .await?;
32//! println!("{}", result.agent_message());
33//! # Ok(())
34//! # }
35//! ```
36
37mod approvals;
38#[cfg(test)]
39#[path = "build_support.rs"]
40mod build_support;
41mod builders;
42mod client;
43mod compat;
44mod daemon;
45mod error;
46mod events;
47pub mod protocol;
48#[cfg(feature = "rest")]
49pub mod rest;
50mod session;
51mod transport;
52
53pub use approvals::{
54 AllowAllApprovalHandler, ApprovalFuture, ApprovalHandler, AsyncFnApprovalHandler,
55 DenyAllApprovalHandler, FnApprovalHandler, ReadOnlyApprovalHandler, ServerRequestReply,
56};
57pub use client::{
58 CodexAppServerClient, Event, EventStream, PendingServerRequest, DEFAULT_CALL_TIMEOUT,
59 DEFAULT_EVENTS_CHANNEL_CAPACITY, SERVER_NOTIFICATION_METHODS,
60};
61pub use compat::{
62 CompatibilityReport, SurfaceSummary, CLIENT_NOTIFICATION_METHOD_COUNT,
63 CLIENT_REQUEST_METHOD_COUNT, CODEX_SCHEMA_VERSION, SERVER_NOTIFICATION_METHOD_COUNT,
64 SERVER_REQUEST_METHOD_COUNT,
65};
66pub use daemon::CodexDaemon;
67pub use error::{Error, Result};
68pub use events::EventCollector;
69pub use session::{CodexSession, SessionOptions, TextTurnResult};
70pub use transport::MAX_LINE_BYTES;