mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 08:27:46 +08:00
feat(codex): add dynamic CLI client profile
This commit is contained in:
@@ -993,7 +993,7 @@ fn build_codex_models_url(base_url: &str, client_version: Option<&str>) -> Optio
|
||||
} else if !has_client_version {
|
||||
query_parts.push(format!(
|
||||
"client_version={}",
|
||||
aether_ai_formats::CODEX_CLIENT_VERSION
|
||||
aether_ai_formats::codex_client_version()
|
||||
));
|
||||
}
|
||||
if !query_parts.is_empty() {
|
||||
@@ -1354,6 +1354,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn build_models_fetch_url_uses_codex_backend_models_endpoint() {
|
||||
let client_version = aether_ai_formats::codex_client_version();
|
||||
assert_eq!(
|
||||
build_models_fetch_url(
|
||||
"codex",
|
||||
@@ -1363,7 +1364,7 @@ mod tests {
|
||||
Some((
|
||||
format!(
|
||||
"https://chatgpt.com/backend-api/codex/models?client_version={}",
|
||||
aether_ai_formats::CODEX_CLIENT_VERSION
|
||||
client_version
|
||||
),
|
||||
"openai:responses".to_string()
|
||||
))
|
||||
|
||||
@@ -627,28 +627,30 @@ fn standard_models_fetch_headers(
|
||||
let api_format = aether_ai_formats::normalize_api_format_alias(api_format);
|
||||
let provider_type = provider_type.trim().to_ascii_lowercase();
|
||||
if provider_type == "codex" && api_format.starts_with("openai:") {
|
||||
// 模型目录请求也必须使用当前动态画像,不能回退到编译时固定版本。
|
||||
let dynamic_client_version = aether_ai_formats::codex_client_version();
|
||||
let client_version = codex_client_version
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.unwrap_or(aether_ai_formats::CODEX_CLIENT_VERSION);
|
||||
.unwrap_or(dynamic_client_version.as_str());
|
||||
return BTreeMap::from([
|
||||
(
|
||||
"user-agent".to_string(),
|
||||
format!(
|
||||
"{}/{client_version}",
|
||||
aether_ai_formats::CODEX_CLIENT_ORIGINATOR
|
||||
aether_ai_formats::codex_client_originator()
|
||||
),
|
||||
),
|
||||
(
|
||||
"originator".to_string(),
|
||||
aether_ai_formats::CODEX_CLIENT_ORIGINATOR.to_string(),
|
||||
aether_ai_formats::codex_client_originator(),
|
||||
),
|
||||
]);
|
||||
}
|
||||
match api_format.as_str() {
|
||||
"openai:responses" | "openai:responses:compact" => BTreeMap::from([(
|
||||
"user-agent".to_string(),
|
||||
aether_ai_formats::CODEX_CLIENT_USER_AGENT.to_string(),
|
||||
aether_ai_formats::codex_client_user_agent(),
|
||||
)]),
|
||||
"claude:messages" => {
|
||||
let mut headers = BTreeMap::from([(
|
||||
@@ -894,7 +896,7 @@ mod tests {
|
||||
assert_eq!(plan.url, "https://example.com/models");
|
||||
assert_eq!(
|
||||
plan.headers.get("user-agent").map(String::as_str),
|
||||
Some(aether_ai_formats::CODEX_CLIENT_USER_AGENT)
|
||||
Some(aether_ai_formats::codex_client_user_agent().as_str())
|
||||
);
|
||||
assert_eq!(
|
||||
plan.headers.get("authorization").map(String::as_str),
|
||||
@@ -993,7 +995,7 @@ mod tests {
|
||||
plan.url,
|
||||
format!(
|
||||
"https://chatgpt.com/backend-api/codex/models?client_version={}",
|
||||
aether_ai_formats::CODEX_CLIENT_VERSION
|
||||
aether_ai_formats::codex_client_version()
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -1018,7 +1020,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
plan.headers.get("user-agent").map(String::as_str),
|
||||
Some(aether_ai_formats::CODEX_CLIENT_USER_AGENT)
|
||||
Some(aether_ai_formats::codex_client_user_agent().as_str())
|
||||
);
|
||||
assert!(!plan.headers.contains_key("version"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user