mirror of
https://github.com/openai/codex.git
synced 2026-11-19 23:05:23 +00:00
[codex] Add owner nudge app-server API (#18220)
## Summary Second PR in the split from #17956. Stacked on #18227. - adds app-server v2 protocol/schema support for `account/sendAddCreditsNudgeEmail` - adds the backend-client `send_add_credits_nudge_email` request and request body mapping - handles the app-server request with auth checks, backend call, and cooldown mapping - adds the disabled `workspace_owner_usage_nudge` feature flag and focused app-server/backend tests ## Validation - `cargo test -p codex-backend-client` - `cargo test -p codex-app-server-protocol` - `cargo test -p codex-app-server rate_limits` - `cargo test -p codex-tui workspace_` - `cargo test -p codex-tui status_` - `just fmt` - `just fix -p codex-backend-client` - `just fix -p codex-app-server-protocol` - `just fix -p codex-app-server` - `just fix -p codex-tui`
This commit is contained in:
1 parent
def6467d2b
commit
6b39d0c657
19 files changed
+675
-2
No files matched your search
@@ -20,6 +20,7 @@ use reqwest::header::HeaderMap;
|
||||
use reqwest::header::HeaderName;
|
||||
use reqwest::header::HeaderValue;
|
||||
use reqwest::header::USER_AGENT;
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::fmt;
|
||||
|
||||
@@ -81,6 +82,18 @@ impl From<anyhow::Error> for RequestError {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AddCreditsNudgeCreditType {
|
||||
Credits,
|
||||
UsageLimit,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct SendAddCreditsNudgeEmailRequest {
|
||||
credit_type: AddCreditsNudgeCreditType,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum PathStyle {
|
||||
/// /api/codex/…
|
||||
@@ -282,6 +295,21 @@ impl Client {
|
||||
Ok(Self::rate_limit_snapshots_from_payload(payload))
|
||||
}
|
||||
|
||||
pub async fn send_add_credits_nudge_email(
|
||||
&self,
|
||||
credit_type: AddCreditsNudgeCreditType,
|
||||
) -> std::result::Result<(), RequestError> {
|
||||
let url = self.send_add_credits_nudge_email_url();
|
||||
let req = self
|
||||
.http
|
||||
.post(&url)
|
||||
.headers(self.headers())
|
||||
.header(CONTENT_TYPE, HeaderValue::from_static("application/json"))
|
||||
.json(&SendAddCreditsNudgeEmailRequest { credit_type });
|
||||
self.exec_request_detailed(req, "POST", &url).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn list_tasks(
|
||||
&self,
|
||||
limit: Option<i32>,
|
||||
@@ -490,6 +518,21 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
fn send_add_credits_nudge_email_url(&self) -> String {
|
||||
match self.path_style {
|
||||
PathStyle::CodexApi => format!(
|
||||
"{}/api/codex/accounts/send_add_credits_nudge_email",
|
||||
self.base_url
|
||||
),
|
||||
PathStyle::ChatGptApi => {
|
||||
format!(
|
||||
"{}/wham/accounts/send_add_credits_nudge_email",
|
||||
self.base_url
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn map_rate_limit_window(
|
||||
window: Option<Option<Box<crate::types::RateLimitWindowSnapshot>>>,
|
||||
) -> Option<RateLimitWindow> {
|
||||
@@ -767,4 +810,50 @@ mod tests {
|
||||
let snapshots = Client::rate_limit_snapshots_from_payload(payload);
|
||||
assert_eq!(snapshots[0].rate_limit_reached_type, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_credits_nudge_email_uses_expected_paths_and_bodies() {
|
||||
let codex_client = Client {
|
||||
base_url: "https://example.test".to_string(),
|
||||
http: reqwest::Client::new(),
|
||||
bearer_token: None,
|
||||
user_agent: None,
|
||||
chatgpt_account_id: None,
|
||||
chatgpt_account_is_fedramp: false,
|
||||
path_style: PathStyle::CodexApi,
|
||||
};
|
||||
assert_eq!(
|
||||
codex_client.send_add_credits_nudge_email_url(),
|
||||
"https://example.test/api/codex/accounts/send_add_credits_nudge_email"
|
||||
);
|
||||
|
||||
let chatgpt_client = Client {
|
||||
base_url: "https://chatgpt.com/backend-api".to_string(),
|
||||
http: reqwest::Client::new(),
|
||||
bearer_token: None,
|
||||
user_agent: None,
|
||||
chatgpt_account_id: None,
|
||||
chatgpt_account_is_fedramp: false,
|
||||
path_style: PathStyle::ChatGptApi,
|
||||
};
|
||||
assert_eq!(
|
||||
chatgpt_client.send_add_credits_nudge_email_url(),
|
||||
"https://chatgpt.com/backend-api/wham/accounts/send_add_credits_nudge_email"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_value(SendAddCreditsNudgeEmailRequest {
|
||||
credit_type: AddCreditsNudgeCreditType::Credits,
|
||||
})
|
||||
.unwrap(),
|
||||
serde_json::json!({ "credit_type": "credits" })
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(SendAddCreditsNudgeEmailRequest {
|
||||
credit_type: AddCreditsNudgeCreditType::UsageLimit,
|
||||
})
|
||||
.unwrap(),
|
||||
serde_json::json!({ "credit_type": "usage_limit" })
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user