Download codex-rs/app-server-protocol/src/protocol/v2/account.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 29.1 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/app-server-protocol/src/protocol/v2/account.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/app-server-protocol/src/protocol/v2/account.rs
-
curl -L -o account.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/app-server-protocol/src/protocol/v2/account.rs
29.1 kB
| use super::ThreadUsage; | |
| use crate::JsonSchema; | |
| use crate::TS; | |
| use crate::protocol::common::AuthMode; | |
| use codex_experimental_api_macros::ExperimentalApi; | |
| use codex_protocol::account::PlanType; | |
| use codex_protocol::account::ProviderAccount; | |
| use codex_protocol::protocol::CreditsSnapshot as CoreCreditsSnapshot; | |
| use codex_protocol::protocol::RateLimitReachedType as CoreRateLimitReachedType; | |
| use codex_protocol::protocol::RateLimitSnapshot as CoreRateLimitSnapshot; | |
| use codex_protocol::protocol::RateLimitWindow as CoreRateLimitWindow; | |
| use codex_protocol::protocol::SpendControlLimitSnapshot as CoreSpendControlLimitSnapshot; | |
| use serde::Deserialize; | |
| use serde::Serialize; | |
| use std::collections::HashMap; | |
| use std::fmt; | |
| pub enum Account { | |
| ApiKey {}, | |
| Chatgpt { | |
| email: Option<String>, | |
| plan_type: PlanType, | |
| }, | |
| AmazonBedrock { | |
| uses_codex_managed_credentials: bool, | |
| }, | |
| } | |
| impl From<ProviderAccount> for Account { | |
| fn from(account: ProviderAccount) -> Self { | |
| match account { | |
| ProviderAccount::ApiKey => Self::ApiKey {}, | |
| ProviderAccount::Chatgpt { email, plan_type } => Self::Chatgpt { email, plan_type }, | |
| ProviderAccount::AmazonBedrock { | |
| uses_codex_managed_credentials, | |
| } => Self::AmazonBedrock { | |
| uses_codex_managed_credentials, | |
| }, | |
| } | |
| } | |
| } | |
| pub enum LoginAccountParams { | |
| ApiKey { | |
| api_key: String, | |
| }, | |
| Chatgpt { | |
| codex_streamlined_login: bool, | |
| use_hosted_login_success_page: bool, | |
| app_brand: Option<LoginAppBrand>, | |
| }, | |
| ChatgptDeviceCode, | |
| /// [UNSTABLE] FOR OPENAI INTERNAL USE ONLY - DO NOT USE. | |
| /// The access token must contain the same scopes that Codex-managed ChatGPT auth tokens have. | |
| ChatgptAuthTokens { | |
| /// Access token (JWT) supplied by the client. | |
| /// This token is used for backend API requests and email extraction. | |
| access_token: String, | |
| /// Workspace/account identifier supplied by the client. | |
| chatgpt_account_id: String, | |
| /// Optional plan type supplied by the client. | |
| /// | |
| /// When `null`, Codex attempts to derive the plan type from access-token | |
| /// claims. If unavailable, the plan defaults to `unknown`. | |
| chatgpt_plan_type: Option<String>, | |
| }, | |
| /// [UNSTABLE] Managed Amazon Bedrock login is experimental. | |
| AmazonBedrock { api_key: String, region: String }, | |
| /// [UNSTABLE] Managed Amazon Bedrock AWS access key login is experimental. | |
| AmazonBedrockAccessKeys { | |
| access_key_id: String, | |
| secret_access_key: String, | |
| session_token: Option<String>, | |
| region: String, | |
| }, | |
| } | |
| pub enum LoginAppBrand { | |
| Codex, | |
| Chatgpt, | |
| } | |
| pub enum LoginAccountResponse { | |
| ApiKey {}, | |
| Chatgpt { | |
| // Use plain String for identifiers to avoid TS/JSON Schema quirks around uuid-specific types. | |
| // Convert to/from UUIDs at the application layer as needed. | |
| login_id: String, | |
| /// URL the client should open in a browser to initiate the OAuth flow. | |
| auth_url: String, | |
| }, | |
| ChatgptDeviceCode { | |
| // Use plain String for identifiers to avoid TS/JSON Schema quirks around uuid-specific types. | |
| // Convert to/from UUIDs at the application layer as needed. | |
| login_id: String, | |
| /// URL the client should open in a browser to complete device code authorization. | |
| verification_url: String, | |
| /// One-time code the user must enter after signing in. | |
| user_code: String, | |
| }, | |
| ChatgptAuthTokens {}, | |
| AmazonBedrock {}, | |
| } | |
| pub struct CancelLoginAccountParams { | |
| pub login_id: String, | |
| } | |
| pub enum CancelLoginAccountStatus { | |
| Canceled, | |
| NotFound, | |
| } | |
| pub struct CancelLoginAccountResponse { | |
| pub status: CancelLoginAccountStatus, | |
| } | |
| pub struct AccountSessionsAddParams { | |
| pub switch_to_added_account: bool, | |
| } | |
| pub struct AccountSessionsListParams { | |
| pub refresh_workspace_metadata: bool, | |
| } | |
| pub struct AccountSessionsLogoutParams { | |
| pub session_id: String, | |
| } | |
| pub struct AccountSessionsSwitchParams { | |
| pub session_id: String, | |
| pub account_id: String, | |
| } | |
| pub struct AccountSessionsResponse { | |
| pub active_session_id: Option<String>, | |
| pub sessions: Vec<AccountSession>, | |
| } | |
| 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>, | |
| } | |
| pub struct AccountSessionWorkspace { | |
| pub account_id: String, | |
| pub name: Option<String>, | |
| pub image_url: Option<String>, | |
| pub kind: Option<AccountSessionWorkspaceKind>, | |
| } | |
| pub enum AccountSessionWorkspaceKind { | |
| Personal, | |
| Workspace, | |
| } | |
| pub struct LogoutAccountResponse {} | |
| pub enum ChatgptAuthTokensRefreshReason { | |
| /// Codex attempted a backend request and received `401 Unauthorized`. | |
| Unauthorized, | |
| } | |
| pub struct ChatgptAuthTokensRefreshParams { | |
| pub reason: ChatgptAuthTokensRefreshReason, | |
| /// Workspace/account identifier that Codex was previously using. | |
| /// | |
| /// Clients that manage multiple accounts/workspaces can use this as a hint | |
| /// to refresh the token for the correct workspace. | |
| /// | |
| /// This may be `null` when the prior auth state did not include a workspace | |
| /// identifier (`chatgpt_account_id`). | |
| pub previous_account_id: Option<String>, | |
| } | |
| pub struct ChatgptAuthTokensRefreshResponse { | |
| pub access_token: String, | |
| pub chatgpt_account_id: String, | |
| pub chatgpt_plan_type: Option<String>, | |
| } | |
| impl fmt::Debug for ChatgptAuthTokensRefreshResponse { | |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| f.debug_struct("ChatgptAuthTokensRefreshResponse") | |
| .field("access_token", &"<redacted>") | |
| .field("chatgpt_account_id", &self.chatgpt_account_id) | |
| .field("chatgpt_plan_type", &self.chatgpt_plan_type) | |
| .finish() | |
| } | |
| } | |
| /// Usage-read capabilities of the requesting client, never inferred from its experiment arm. | |
| pub struct GetAccountRateLimitsParams { | |
| /// The client supports automatic Luna Reserve fallback. For eligible ChatGPT CLI users, | |
| /// allow the backend to record experiment exposure after ordinary usage is blocked. | |
| pub supports_luna_reserve: bool, | |
| /// Skip the separate reset-credit detail lookup for background usage polls. The usage | |
| /// response still includes the available count; omitted/false preserves detailed reads. | |
| pub exclude_reset_credit_details: bool, | |
| } | |
| pub type NullableGetAccountRateLimitsParams = Option<GetAccountRateLimitsParams>; | |
| pub struct GetAccountRateLimitsResponse { | |
| /// Backend permission for ordinary included usage, validated against the active account. | |
| /// Null means unavailable; clients must not infer recovery from percentages or reset times. | |
| pub ordinary_usage_allowed: Option<bool>, | |
| /// Backward-compatible single-bucket view; mirrors the historical payload. | |
| pub rate_limits: RateLimitSnapshot, | |
| /// Multi-bucket view keyed by metered `limit_id` (for example, `codex`). | |
| pub rate_limits_by_limit_id: Option<HashMap<String, RateLimitSnapshot>>, | |
| pub rate_limit_reset_credits: Option<RateLimitResetCreditsSummary>, | |
| /// Account associated with this usage snapshot, when supplied by the backend. | |
| pub account_id: Option<String>, | |
| /// Optional backend-owned banner from the same usage read. Its nested keys retain the | |
| /// backend's snake_case contract; an absent banner leaves the client's existing UI unchanged. | |
| pub rate_limit_upsell: Option<serde_json::Value>, | |
| } | |
| pub struct RateLimitResetCreditsSummary { | |
| pub available_count: i64, | |
| /// Detail rows for available reset credits, when the backend provides them. | |
| /// | |
| /// `null` means only `availableCount` is known, while an empty array means details were fetched | |
| /// and no available credits were returned. The backend may cap this list, so its length can be | |
| /// less than `availableCount`. | |
| pub credits: Option<Vec<RateLimitResetCredit>>, | |
| } | |
| pub struct RateLimitResetCredit { | |
| /// Opaque backend identifier for this reset credit. | |
| pub id: String, | |
| pub reset_type: RateLimitResetType, | |
| pub status: RateLimitResetCreditStatus, | |
| /// Unix timestamp in seconds when the credit was granted. | |
| pub granted_at: i64, | |
| /// Unix timestamp in seconds when the credit expires, or `null` if it does not expire. | |
| pub expires_at: Option<i64>, | |
| /// Backend-provided display title for this credit, or `null` when unavailable. | |
| pub title: Option<String>, | |
| /// Backend-provided display description for this credit, or `null` when unavailable. | |
| pub description: Option<String>, | |
| } | |
| pub enum RateLimitResetType { | |
| CodexRateLimits, | |
| Unknown, | |
| } | |
| pub enum RateLimitResetCreditStatus { | |
| Available, | |
| Redeeming, | |
| Redeemed, | |
| Unknown, | |
| } | |
| pub struct ConsumeAccountRateLimitResetCreditParams { | |
| /// Identifies one logical reset attempt. A UUID is recommended; reuse the same value when | |
| /// retrying that attempt. | |
| pub idempotency_key: String, | |
| /// Opaque reset-credit identifier to redeem. When omitted, the backend selects the next | |
| /// available credit. | |
| pub credit_id: Option<String>, | |
| } | |
| pub struct ConsumeAccountRateLimitResetCreditResponse { | |
| pub outcome: ConsumeAccountRateLimitResetCreditOutcome, | |
| } | |
| pub enum ConsumeAccountRateLimitResetCreditOutcome { | |
| /// A reset credit was consumed and the eligible rate-limit windows were reset. | |
| Reset, | |
| /// No current rate-limit window is eligible for a reset. | |
| NothingToReset, | |
| /// The account has no earned reset credits available. | |
| NoCredit, | |
| /// The same idempotency key already completed a reset successfully. | |
| AlreadyRedeemed, | |
| } | |
| pub struct GetAccountTokenUsageParams { | |
| /// When present, read estimated usage for this thread instead of account-wide token activity. | |
| pub thread_id: Option<String>, | |
| } | |
| pub type NullableGetAccountTokenUsageParams = Option<GetAccountTokenUsageParams>; | |
| pub struct GetAccountTokenUsageResponse { | |
| pub summary: AccountTokenUsageSummary, | |
| pub daily_usage_buckets: Option<Vec<AccountTokenUsageDailyBucket>>, | |
| /// Estimated usage when a thread was requested and its billing route is available. | |
| pub thread_usage: Option<ThreadUsage>, | |
| } | |
| pub struct GetWorkspaceMessagesResponse { | |
| /// Whether the workspace-message backend route is available for this client. | |
| pub feature_enabled: bool, | |
| /// Active workspace messages returned by the backend. | |
| pub messages: Vec<WorkspaceMessage>, | |
| } | |
| pub struct WorkspaceMessage { | |
| pub message_id: String, | |
| pub message_type: WorkspaceMessageType, | |
| pub message_body: String, | |
| /// Unix timestamp (in seconds) when the message was created. | |
| pub created_at: Option<i64>, | |
| /// Unix timestamp (in seconds) when the message was archived. | |
| pub archived_at: Option<i64>, | |
| } | |
| pub enum WorkspaceMessageType { | |
| Headline, | |
| Announcement, | |
| Unknown, | |
| } | |
| pub struct AccountTokenUsageSummary { | |
| pub lifetime_tokens: Option<i64>, | |
| pub peak_daily_tokens: Option<i64>, | |
| pub longest_running_turn_sec: Option<i64>, | |
| pub current_streak_days: Option<i64>, | |
| pub longest_streak_days: Option<i64>, | |
| } | |
| pub struct AccountTokenUsageDailyBucket { | |
| pub start_date: String, | |
| pub tokens: i64, | |
| } | |
| pub struct SendAddCreditsNudgeEmailParams { | |
| pub credit_type: AddCreditsNudgeCreditType, | |
| } | |
| pub enum AddCreditsNudgeCreditType { | |
| Credits, | |
| UsageLimit, | |
| } | |
| pub struct SendAddCreditsNudgeEmailResponse { | |
| pub status: AddCreditsNudgeEmailStatus, | |
| } | |
| pub enum AddCreditsNudgeEmailStatus { | |
| Sent, | |
| CooldownActive, | |
| } | |
| pub struct GetAccountParams { | |
| /// When `true`, requests a proactive token refresh before returning. | |
| /// | |
| /// In managed auth mode this triggers the normal refresh-token flow. In | |
| /// external auth mode this flag is ignored. Clients should refresh tokens | |
| /// themselves and call `account/login/start` with `chatgptAuthTokens`. | |
| pub refresh_token: bool, | |
| } | |
| pub struct GetAccountResponse { | |
| pub account: Option<Account>, | |
| pub requires_openai_auth: bool, | |
| pub workspace_routing: Option<WorkspaceRouting>, | |
| } | |
| pub struct WorkspaceRouting { | |
| pub chatgpt_account_id: String, | |
| pub backend_origin: String, | |
| pub account_routing_override: AccountRoutingOverride, | |
| } | |
| /// Backend routing policy. Wire values match the accounts/check contract. | |
| pub enum AccountRoutingOverride { | |
| NoConstraint, | |
| Us, | |
| UsCr, | |
| } | |
| pub struct AccountUpdatedNotification { | |
| pub auth_mode: Option<AuthMode>, | |
| pub plan_type: Option<PlanType>, | |
| } | |
| /// Sparse rolling rate-limit update. | |
| /// | |
| /// Clients should merge available values into the most recent `account/rateLimits/read` response | |
| /// or refetch that snapshot. Nullable account metadata may be unavailable in a rolling update and | |
| /// does not clear a previously observed value. | |
| pub struct AccountRateLimitsUpdatedNotification { | |
| pub rate_limits: RateLimitSnapshot, | |
| } | |
| pub struct RateLimitSnapshot { | |
| pub limit_id: Option<String>, | |
| pub limit_name: Option<String>, | |
| /// Normal model whose display name and reasoning options describe this quota alias. | |
| pub normal_model_slug: Option<String>, | |
| pub primary: Option<RateLimitWindow>, | |
| pub secondary: Option<RateLimitWindow>, | |
| pub credits: Option<CreditsSnapshot>, | |
| pub individual_limit: Option<SpendControlLimitSnapshot>, | |
| /// Backend-reported spend-control state. `None` is unavailable, not a sparse-update recovery. | |
| pub spend_control_reached: Option<bool>, | |
| pub plan_type: Option<PlanType>, | |
| pub rate_limit_reached_type: Option<RateLimitReachedType>, | |
| } | |
| impl From<CoreRateLimitSnapshot> for RateLimitSnapshot { | |
| fn from(value: CoreRateLimitSnapshot) -> Self { | |
| Self { | |
| limit_id: value.limit_id, | |
| limit_name: value.limit_name, | |
| normal_model_slug: value.normal_model_slug, | |
| primary: value.primary.map(RateLimitWindow::from), | |
| secondary: value.secondary.map(RateLimitWindow::from), | |
| credits: value.credits.map(CreditsSnapshot::from), | |
| individual_limit: value.individual_limit.map(SpendControlLimitSnapshot::from), | |
| spend_control_reached: value.spend_control_reached, | |
| plan_type: value.plan_type, | |
| rate_limit_reached_type: value | |
| .rate_limit_reached_type | |
| .map(RateLimitReachedType::from), | |
| } | |
| } | |
| } | |
| pub enum RateLimitReachedType { | |
| RateLimitReached, | |
| WorkspaceOwnerCreditsDepleted, | |
| WorkspaceMemberCreditsDepleted, | |
| WorkspaceOwnerUsageLimitReached, | |
| WorkspaceMemberUsageLimitReached, | |
| } | |
| impl From<CoreRateLimitReachedType> for RateLimitReachedType { | |
| fn from(value: CoreRateLimitReachedType) -> Self { | |
| match value { | |
| CoreRateLimitReachedType::RateLimitReached => Self::RateLimitReached, | |
| CoreRateLimitReachedType::WorkspaceOwnerCreditsDepleted => { | |
| Self::WorkspaceOwnerCreditsDepleted | |
| } | |
| CoreRateLimitReachedType::WorkspaceMemberCreditsDepleted => { | |
| Self::WorkspaceMemberCreditsDepleted | |
| } | |
| CoreRateLimitReachedType::WorkspaceOwnerUsageLimitReached => { | |
| Self::WorkspaceOwnerUsageLimitReached | |
| } | |
| CoreRateLimitReachedType::WorkspaceMemberUsageLimitReached => { | |
| Self::WorkspaceMemberUsageLimitReached | |
| } | |
| } | |
| } | |
| } | |
| impl From<RateLimitReachedType> for CoreRateLimitReachedType { | |
| fn from(value: RateLimitReachedType) -> Self { | |
| match value { | |
| RateLimitReachedType::RateLimitReached => Self::RateLimitReached, | |
| RateLimitReachedType::WorkspaceOwnerCreditsDepleted => { | |
| Self::WorkspaceOwnerCreditsDepleted | |
| } | |
| RateLimitReachedType::WorkspaceMemberCreditsDepleted => { | |
| Self::WorkspaceMemberCreditsDepleted | |
| } | |
| RateLimitReachedType::WorkspaceOwnerUsageLimitReached => { | |
| Self::WorkspaceOwnerUsageLimitReached | |
| } | |
| RateLimitReachedType::WorkspaceMemberUsageLimitReached => { | |
| Self::WorkspaceMemberUsageLimitReached | |
| } | |
| } | |
| } | |
| } | |
| pub struct RateLimitWindow { | |
| pub used_percent: i32, | |
| pub window_duration_mins: Option<i64>, | |
| pub resets_at: Option<i64>, | |
| } | |
| impl From<CoreRateLimitWindow> for RateLimitWindow { | |
| fn from(value: CoreRateLimitWindow) -> Self { | |
| Self { | |
| used_percent: value.used_percent.round() as i32, | |
| window_duration_mins: value.window_minutes, | |
| resets_at: value.resets_at, | |
| } | |
| } | |
| } | |
| pub struct CreditsSnapshot { | |
| pub has_credits: bool, | |
| pub unlimited: bool, | |
| pub balance: Option<String>, | |
| } | |
| impl From<CoreCreditsSnapshot> for CreditsSnapshot { | |
| fn from(value: CoreCreditsSnapshot) -> Self { | |
| Self { | |
| has_credits: value.has_credits, | |
| unlimited: value.unlimited, | |
| balance: value.balance, | |
| } | |
| } | |
| } | |
| pub struct SpendControlLimitSnapshot { | |
| pub limit: String, | |
| pub used: String, | |
| pub remaining_percent: i32, | |
| pub resets_at: i64, | |
| } | |
| impl From<CoreSpendControlLimitSnapshot> for SpendControlLimitSnapshot { | |
| fn from(value: CoreSpendControlLimitSnapshot) -> Self { | |
| Self { | |
| limit: value.limit, | |
| used: value.used, | |
| remaining_percent: value.remaining_percent, | |
| resets_at: value.resets_at, | |
| } | |
| } | |
| } | |
| pub struct AccountLoginCompletedNotification { | |
| // Use plain String for identifiers to avoid TS/JSON Schema quirks around uuid-specific types. | |
| // Convert to/from UUIDs at the application layer as needed. | |
| pub login_id: Option<String>, | |
| pub success: bool, | |
| pub error: Option<String>, | |
| pub onboarding_entrypoint: Option<DesktopOnboardingEntrypoint>, | |
| } | |
| pub enum DesktopOnboardingEntrypoint { | |
| LifeSciences, | |
| } | |