Skip to content

Commit b101fbe

Browse files
authored
Merge branch 'main' into add-github-action-for-nix
2 parents d88a9b8 + ea82f86 commit b101fbe

File tree

65 files changed

+5224
-1380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5224
-1380
lines changed

codex-rs/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codex-rs/cli/src/login.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use codex_core::auth::logout;
66
use codex_core::config::Config;
77
use codex_core::config::ConfigOverrides;
88
use codex_login::ServerOptions;
9+
use codex_login::run_device_code_login;
910
use codex_login::run_login_server;
1011
use codex_protocol::mcp_protocol::AuthMode;
1112
use std::path::PathBuf;
@@ -55,6 +56,32 @@ pub async fn run_login_with_api_key(
5556
}
5657
}
5758

59+
/// Login using the OAuth device code flow.
60+
pub async fn run_login_with_device_code(
61+
cli_config_overrides: CliConfigOverrides,
62+
issuer_base_url: Option<String>,
63+
client_id: Option<String>,
64+
) -> ! {
65+
let config = load_config_or_exit(cli_config_overrides);
66+
let mut opts = ServerOptions::new(
67+
config.codex_home,
68+
client_id.unwrap_or(CLIENT_ID.to_string()),
69+
);
70+
if let Some(iss) = issuer_base_url {
71+
opts.issuer = iss;
72+
}
73+
match run_device_code_login(opts).await {
74+
Ok(()) => {
75+
eprintln!("Successfully logged in");
76+
std::process::exit(0);
77+
}
78+
Err(e) => {
79+
eprintln!("Error logging in with device code: {e}");
80+
std::process::exit(1);
81+
}
82+
}
83+
}
84+
5885
pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
5986
let config = load_config_or_exit(cli_config_overrides);
6087

codex-rs/cli/src/main.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use codex_cli::SeatbeltCommand;
1010
use codex_cli::login::run_login_status;
1111
use codex_cli::login::run_login_with_api_key;
1212
use codex_cli::login::run_login_with_chatgpt;
13+
use codex_cli::login::run_login_with_device_code;
1314
use codex_cli::login::run_logout;
1415
use codex_cli::proto;
1516
use codex_common::CliConfigOverrides;
@@ -132,6 +133,20 @@ struct LoginCommand {
132133
#[arg(long = "api-key", value_name = "API_KEY")]
133134
api_key: Option<String>,
134135

136+
/// EXPERIMENTAL: Use device code flow (not yet supported)
137+
/// This feature is experimental and may changed in future releases.
138+
#[arg(long = "experimental_use-device-code", hide = true)]
139+
use_device_code: bool,
140+
141+
/// EXPERIMENTAL: Use custom OAuth issuer base URL (advanced)
142+
/// Override the OAuth issuer base URL (advanced)
143+
#[arg(long = "experimental_issuer", value_name = "URL", hide = true)]
144+
issuer_base_url: Option<String>,
145+
146+
/// EXPERIMENTAL: Use custom OAuth client ID (advanced)
147+
#[arg(long = "experimental_client-id", value_name = "CLIENT_ID", hide = true)]
148+
client_id: Option<String>,
149+
135150
#[command(subcommand)]
136151
action: Option<LoginSubcommand>,
137152
}
@@ -274,7 +289,14 @@ async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()
274289
run_login_status(login_cli.config_overrides).await;
275290
}
276291
None => {
277-
if let Some(api_key) = login_cli.api_key {
292+
if login_cli.use_device_code {
293+
run_login_with_device_code(
294+
login_cli.config_overrides,
295+
login_cli.issuer_base_url,
296+
login_cli.client_id,
297+
)
298+
.await;
299+
} else if let Some(api_key) = login_cli.api_key {
278300
run_login_with_api_key(login_cli.config_overrides, api_key).await;
279301
} else {
280302
run_login_with_chatgpt(login_cli.config_overrides).await;

codex-rs/exec/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ tempfile = { workspace = true }
5858
uuid = { workspace = true }
5959
walkdir = { workspace = true }
6060
wiremock = { workspace = true }
61+
mcp-types = { workspace = true }

codex-rs/exec/src/exec_events.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@ use serde::Deserialize;
22
use serde::Serialize;
33
use ts_rs::TS;
44

5-
/// Top-level events emitted on the Codex Exec conversation stream.
5+
/// Top-level events emitted on the Codex Exec thread stream.
66
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
77
#[serde(tag = "type")]
8-
pub enum ConversationEvent {
9-
#[serde(rename = "session.created")]
10-
SessionCreated(SessionCreatedEvent),
8+
pub enum ThreadEvent {
9+
#[serde(rename = "thread.started")]
10+
ThreadStarted(ThreadStartedEvent),
1111
#[serde(rename = "turn.started")]
1212
TurnStarted(TurnStartedEvent),
1313
#[serde(rename = "turn.completed")]
1414
TurnCompleted(TurnCompletedEvent),
15+
#[serde(rename = "turn.failed")]
16+
TurnFailed(TurnFailedEvent),
1517
#[serde(rename = "item.started")]
1618
ItemStarted(ItemStartedEvent),
1719
#[serde(rename = "item.updated")]
1820
ItemUpdated(ItemUpdatedEvent),
1921
#[serde(rename = "item.completed")]
2022
ItemCompleted(ItemCompletedEvent),
2123
#[serde(rename = "error")]
22-
Error(ConversationErrorEvent),
24+
Error(ThreadErrorEvent),
2325
}
2426

2527
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
26-
pub struct SessionCreatedEvent {
27-
pub session_id: String,
28+
pub struct ThreadStartedEvent {
29+
pub thread_id: String,
2830
}
2931

3032
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS, Default)]
@@ -35,6 +37,11 @@ pub struct TurnCompletedEvent {
3537
pub usage: Usage,
3638
}
3739

40+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
41+
pub struct TurnFailedEvent {
42+
pub error: ThreadErrorEvent,
43+
}
44+
3845
/// Minimal usage summary for a turn.
3946
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS, Default)]
4047
pub struct Usage {
@@ -45,37 +52,37 @@ pub struct Usage {
4552

4653
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
4754
pub struct ItemStartedEvent {
48-
pub item: ConversationItem,
55+
pub item: ThreadItem,
4956
}
5057

5158
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
5259
pub struct ItemCompletedEvent {
53-
pub item: ConversationItem,
60+
pub item: ThreadItem,
5461
}
5562

5663
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
5764
pub struct ItemUpdatedEvent {
58-
pub item: ConversationItem,
65+
pub item: ThreadItem,
5966
}
6067

6168
/// Fatal error emitted by the stream.
6269
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
63-
pub struct ConversationErrorEvent {
70+
pub struct ThreadErrorEvent {
6471
pub message: String,
6572
}
6673

67-
/// Canonical representation of a conversation item and its domain-specific payload.
74+
/// Canonical representation of a thread item and its domain-specific payload.
6875
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
69-
pub struct ConversationItem {
76+
pub struct ThreadItem {
7077
pub id: String,
7178
#[serde(flatten)]
72-
pub details: ConversationItemDetails,
79+
pub details: ThreadItemDetails,
7380
}
7481

75-
/// Typed payloads for each supported conversation item type.
82+
/// Typed payloads for each supported thread item type.
7683
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
7784
#[serde(tag = "item_type", rename_all = "snake_case")]
78-
pub enum ConversationItemDetails {
85+
pub enum ThreadItemDetails {
7986
AssistantMessage(AssistantMessageItem),
8087
Reasoning(ReasoningItem),
8188
CommandExecution(CommandExecutionItem),
@@ -86,7 +93,7 @@ pub enum ConversationItemDetails {
8693
Error(ErrorItem),
8794
}
8895

89-
/// Session conversation metadata.
96+
/// Session metadata.
9097
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, TS)]
9198
pub struct SessionItem {
9299
pub session_id: String,

0 commit comments

Comments
 (0)