Skip to content
Merged
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
72 changes: 72 additions & 0 deletions codex-rs/app-server-protocol/src/protocol/v2/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,78 @@ pub struct CancelLoginAccountResponse {
pub status: CancelLoginAccountStatus,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct AccountSessionsAddParams {
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub switch_to_added_account: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct AccountSessionsListParams {
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub refresh_workspace_metadata: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct AccountSessionsLogoutParams {
pub session_id: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct AccountSessionsSwitchParams {
pub session_id: String,
pub account_id: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct AccountSessionsResponse {
pub active_session_id: Option<String>,
pub sessions: Vec<AccountSession>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct AccountSession {
pub session_id: String,
pub email: Option<String>,
pub user_id: Option<String>,
pub display_name: Option<String>,
pub image_url: Option<String>,
pub last_used_at: i64,
pub is_active: bool,
pub selected_workspace_account_id: Option<String>,
pub workspaces: Vec<AccountSessionWorkspace>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct AccountSessionWorkspace {
pub account_id: String,
pub name: Option<String>,
pub image_url: Option<String>,
pub kind: Option<AccountSessionWorkspaceKind>,
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum AccountSessionWorkspaceKind {
Personal,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't personal users have workspaces too?

@dhruvgupta-oai dhruvgupta-oai Jun 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal is its own type of workspace. So like personal workspace or business workspace. A users can have multiple workspaces but each workspace only has one type.

Workspace,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
Expand Down
11 changes: 11 additions & 0 deletions codex-rs/backend-client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::types::AccountsCheckResponse;
use crate::types::CodeTaskDetailsResponse;
use crate::types::ConfigBundleResponse;
use crate::types::ConfigFileResponse;
Expand Down Expand Up @@ -303,6 +304,16 @@ impl Client {
Ok(Self::rate_limit_snapshots_from_payload(payload))
}

pub async fn get_accounts_check(&self) -> Result<AccountsCheckResponse> {
let url = match self.path_style {
PathStyle::CodexApi => format!("{}/api/codex/accounts/check", self.base_url),
PathStyle::ChatGptApi => format!("{}/wham/accounts/check", self.base_url),
};
let req = self.http.get(&url).headers(self.headers());
let (body, ct) = self.exec_request(req, "GET", &url).await?;
self.decode_json(&url, &ct, &body)
}

pub async fn send_add_credits_nudge_email(
&self,
credit_type: AddCreditsNudgeCreditType,
Expand Down
2 changes: 2 additions & 0 deletions codex-rs/backend-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub(crate) mod types;
pub use client::AddCreditsNudgeCreditType;
pub use client::Client;
pub use client::RequestError;
pub use types::AccountEntry;
pub use types::AccountsCheckResponse;
pub use types::CodeTaskDetailsResponse;
pub use types::CodeTaskDetailsResponseExt;
pub use types::ConfigBundleResponse;
Expand Down
87 changes: 87 additions & 0 deletions codex-rs/backend-client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,93 @@ use serde::de::Deserializer;
use serde_json::Value;
use std::collections::HashMap;

#[derive(Clone, Debug)]
pub struct AccountsCheckResponse {
pub accounts: Vec<AccountEntry>,
Comment thread
dhruvgupta-oai marked this conversation as resolved.
Resolved
pub account_ordering: Vec<String>,
pub default_account_id: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct AccountEntry {
pub id: String,
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub profile_picture_url: Option<String>,
#[serde(default)]
pub structure: String,
}

#[derive(Deserialize)]
struct RawAccountsCheckResponse {
#[serde(default)]
accounts: RawAccounts,
#[serde(default)]
account_ordering: Vec<String>,
#[serde(default)]
default_account_id: Option<String>,
}

#[derive(Deserialize)]
#[serde(untagged)]
enum RawAccounts {
List(Vec<AccountEntry>),
Map(HashMap<String, ChatGptAccountEntry>),
}

impl Default for RawAccounts {
fn default() -> Self {
Self::List(Vec::new())
}
}

#[derive(Deserialize)]
struct ChatGptAccountEntry {
account: ChatGptAccountInfo,
}

#[derive(Deserialize)]
struct ChatGptAccountInfo {
account_id: Option<String>,
#[serde(default)]
name: Option<String>,
#[serde(default)]
profile_picture_url: Option<String>,
#[serde(default)]
structure: String,
}

impl<'de> Deserialize<'de> for AccountsCheckResponse {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = RawAccountsCheckResponse::deserialize(deserializer)?;
let accounts = match raw.accounts {
RawAccounts::List(accounts) => accounts,
RawAccounts::Map(mut accounts) => raw
.account_ordering
.iter()
.filter_map(|account_id| {
let account = accounts.remove(account_id)?.account;
Some(AccountEntry {
id: account.account_id?,
name: account.name,
profile_picture_url: account.profile_picture_url,
structure: account.structure,
})
})
.collect(),
};
Ok(Self {
accounts,
account_ordering: raw.account_ordering,
default_account_id: raw.default_account_id,
})
}
}

/// Hand-rolled models for the Cloud Tasks task-details response.
/// The generated OpenAPI models are pretty bad. This is a half-step
/// towards hand-rolling them.
Expand Down
Loading