Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion codex-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ members = [
"utils/pty",
"utils/readiness",
"utils/string",
"utils/tokenizer",
"utils/tokenizer", "api-client",
]
resolver = "2"

Expand Down Expand Up @@ -87,6 +87,7 @@ codex-utils-pty = { path = "utils/pty" }
codex-utils-readiness = { path = "utils/readiness" }
codex-utils-string = { path = "utils/string" }
codex-utils-tokenizer = { path = "utils/tokenizer" }
codex-api-client = { path = "api-client" }
core_test_support = { path = "core/tests/common" }
mcp-types = { path = "mcp-types" }
mcp_test_support = { path = "mcp-server/tests/common" }
Expand Down
28 changes: 28 additions & 0 deletions codex-rs/api-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "codex-api-client"
version.workspace = true
edition.workspace = true

[dependencies]
async-trait = { workspace = true }
bytes = { workspace = true }
codex-app-server-protocol = { workspace = true }
codex-otel = { workspace = true }
codex-protocol = { path = "../protocol" }
eventsource-stream = { workspace = true }
futures = { workspace = true, default-features = false, features = ["std"] }
regex-lite = { workspace = true }
reqwest = { workspace = true, features = ["json", "stream"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync", "time", "rt", "rt-multi-thread", "macros", "io-util"] }
tokio-util = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
maplit = "1.0.2"
toml = { workspace = true }

[lints]
workspace = true
16 changes: 16 additions & 0 deletions codex-rs/api-client/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use async_trait::async_trait;

use crate::error::Error;
use crate::prompt::Prompt;
use crate::stream::ResponseStream;

#[async_trait]
pub trait ApiClient: Send + Sync {
type Config: Send + Sync;

async fn new(config: Self::Config) -> Result<Self, Error>
where
Self: Sized;

async fn stream(&self, prompt: Prompt) -> Result<ResponseStream, Error>;
}
15 changes: 15 additions & 0 deletions codex-rs/api-client/src/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use async_trait::async_trait;
use codex_app_server_protocol::AuthMode;

#[derive(Debug, Clone)]
pub struct AuthContext {
pub mode: AuthMode,
pub bearer_token: Option<String>,
pub account_id: Option<String>,
}

#[async_trait]
pub trait AuthProvider: Send + Sync {
async fn auth_context(&self) -> Option<AuthContext>;
async fn refresh_token(&self) -> Result<Option<String>, String>;
}
Loading