use std::collections::BTreeMap;
use super::CODEX_MODEL_CATALOG_CLIENT_VERSION;
pub(crate) fn package_user_agent() -> String {
format!("magi-code/{}", env!("CARGO_PKG_VERSION"))
}
fn codex_user_agent() -> String {
format!("codex_cli_rs/{CODEX_MODEL_CATALOG_CLIENT_VERSION}")
}
pub(crate) fn sse_json_headers(token: Option<&str>) -> BTreeMap<String, String> {
let mut headers = BTreeMap::from([
("accept".to_string(), "text/event-stream".to_string()),
("content-type".to_string(), "application/json".to_string()),
("user-agent".to_string(), package_user_agent()),
]);
if let Some(token) = token.filter(|token| !token.is_empty()) {
headers.insert("authorization".to_string(), format!("Bearer {token}"));
}
headers
}
pub(crate) fn model_catalog_headers(token: Option<&str>) -> BTreeMap<String, String> {
let mut headers = BTreeMap::from([
("accept".to_string(), "application/json".to_string()),
("user-agent".to_string(), package_user_agent()),
]);
if let Some(token) = token.filter(|token| !token.is_empty()) {
headers.insert("authorization".to_string(), format!("Bearer {token}"));
}
headers
}
pub(crate) fn codex_sse_headers(token: &str, account_id: &str) -> BTreeMap<String, String> {
let mut headers = sse_json_headers(Some(token));
headers.insert("chatgpt-account-id".to_string(), account_id.to_string());
headers.insert("originator".to_string(), "codex_cli_rs".to_string());
headers.insert("user-agent".to_string(), codex_user_agent());
headers.insert(
"openai-beta".to_string(),
"responses=experimental".to_string(),
);
headers
}
pub(crate) fn codex_model_catalog_headers(
token: &str,
account_id: &str,
) -> BTreeMap<String, String> {
BTreeMap::from([
("authorization".to_string(), format!("Bearer {token}")),
("chatgpt-account-id".to_string(), account_id.to_string()),
("originator".to_string(), "codex_cli_rs".to_string()),
("user-agent".to_string(), codex_user_agent()),
("accept".to_string(), "application/json".to_string()),
])
}