clean up legacy openai cli adapter names

This commit is contained in:
fawney19
2026-04-26 21:12:57 +08:00
parent 5b914aa78c
commit ea3dc3257e
47 changed files with 412 additions and 572 deletions

View File

@@ -7,8 +7,7 @@ use crate::contracts::{
GEMINI_FILES_DOWNLOAD_PLAN_KIND, GEMINI_FILES_GET_PLAN_KIND, GEMINI_FILES_LIST_PLAN_KIND,
GEMINI_FILES_UPLOAD_PLAN_KIND, GEMINI_VIDEO_CANCEL_SYNC_PLAN_KIND,
GEMINI_VIDEO_CREATE_SYNC_PLAN_KIND, OPENAI_CHAT_STREAM_PLAN_KIND, OPENAI_CHAT_SYNC_PLAN_KIND,
OPENAI_CLI_STREAM_PLAN_KIND, OPENAI_CLI_SYNC_PLAN_KIND, OPENAI_COMPACT_STREAM_PLAN_KIND,
OPENAI_COMPACT_SYNC_PLAN_KIND, OPENAI_IMAGE_STREAM_PLAN_KIND, OPENAI_IMAGE_SYNC_PLAN_KIND,
OPENAI_IMAGE_STREAM_PLAN_KIND, OPENAI_IMAGE_SYNC_PLAN_KIND,
OPENAI_RESPONSES_COMPACT_STREAM_PLAN_KIND, OPENAI_RESPONSES_COMPACT_SYNC_PLAN_KIND,
OPENAI_RESPONSES_STREAM_PLAN_KIND, OPENAI_RESPONSES_SYNC_PLAN_KIND,
OPENAI_VIDEO_CANCEL_SYNC_PLAN_KIND, OPENAI_VIDEO_CONTENT_PLAN_KIND,
@@ -280,8 +279,6 @@ pub fn is_matching_stream_request(
| CLAUDE_CHAT_STREAM_PLAN_KIND
| OPENAI_RESPONSES_STREAM_PLAN_KIND
| OPENAI_RESPONSES_COMPACT_STREAM_PLAN_KIND
| OPENAI_CLI_STREAM_PLAN_KIND
| OPENAI_COMPACT_STREAM_PLAN_KIND
| CLAUDE_CLI_STREAM_PLAN_KIND
| OPENAI_IMAGE_STREAM_PLAN_KIND => body_json
.get("stream")
@@ -301,8 +298,6 @@ pub fn supports_sync_scheduler_decision_kind(plan_kind: &str) -> bool {
| OPENAI_IMAGE_SYNC_PLAN_KIND
| OPENAI_RESPONSES_SYNC_PLAN_KIND
| OPENAI_RESPONSES_COMPACT_SYNC_PLAN_KIND
| OPENAI_CLI_SYNC_PLAN_KIND
| OPENAI_COMPACT_SYNC_PLAN_KIND
| CLAUDE_CHAT_SYNC_PLAN_KIND
| CLAUDE_CLI_SYNC_PLAN_KIND
| GEMINI_CHAT_SYNC_PLAN_KIND
@@ -328,9 +323,7 @@ pub fn supports_stream_scheduler_decision_kind(plan_kind: &str) -> bool {
| GEMINI_CHAT_STREAM_PLAN_KIND
| OPENAI_RESPONSES_STREAM_PLAN_KIND
| OPENAI_RESPONSES_COMPACT_STREAM_PLAN_KIND
| OPENAI_CLI_STREAM_PLAN_KIND
| OPENAI_IMAGE_STREAM_PLAN_KIND
| OPENAI_COMPACT_STREAM_PLAN_KIND
| CLAUDE_CLI_STREAM_PLAN_KIND
| GEMINI_CLI_STREAM_PLAN_KIND
| GEMINI_FILES_DOWNLOAD_PLAN_KIND

View File

@@ -37,7 +37,7 @@ fn is_codex_openai_responses_request(provider_type: &str, provider_api_format: &
)
}
fn is_openai_compact_request(provider_api_format: &str) -> bool {
fn is_openai_responses_compact_request(provider_api_format: &str) -> bool {
matches!(
provider_api_format.trim().to_ascii_lowercase().as_str(),
"openai:responses:compact" | "openai:compact"
@@ -282,7 +282,7 @@ pub fn apply_openai_responses_compact_special_body_edits(
provider_request_body: &mut Value,
provider_api_format: &str,
) {
if !is_openai_compact_request(provider_api_format) {
if !is_openai_responses_compact_request(provider_api_format) {
return;
}
@@ -294,17 +294,6 @@ pub fn apply_openai_responses_compact_special_body_edits(
body_object.remove("store");
}
#[deprecated(
since = "0.1.0",
note = "use apply_openai_responses_compact_special_body_edits"
)]
pub fn apply_openai_compact_special_body_edits(
provider_request_body: &mut Value,
provider_api_format: &str,
) {
apply_openai_responses_compact_special_body_edits(provider_request_body, provider_api_format);
}
pub fn apply_codex_openai_responses_special_body_edits(
provider_request_body: &mut Value,
provider_type: &str,
@@ -332,7 +321,7 @@ pub fn apply_codex_openai_responses_special_body_edits(
if !body_rules_handle_path(body_rules, "metadata") {
body_object.remove("metadata");
}
if is_openai_compact_request(provider_api_format) {
if is_openai_responses_compact_request(provider_api_format) {
body_object.remove("store");
} else if !body_rules_handle_path(body_rules, "store") {
body_object.insert("store".to_string(), json!(false));
@@ -363,26 +352,6 @@ pub fn apply_codex_openai_responses_special_body_edits(
);
}
#[deprecated(
since = "0.1.0",
note = "use apply_codex_openai_responses_special_body_edits"
)]
pub fn apply_codex_openai_cli_special_body_edits(
provider_request_body: &mut Value,
provider_type: &str,
provider_api_format: &str,
body_rules: Option<&Value>,
user_api_key_id: Option<&str>,
) {
apply_codex_openai_responses_special_body_edits(
provider_request_body,
provider_type,
provider_api_format,
body_rules,
user_api_key_id,
);
}
pub fn apply_codex_openai_responses_special_headers(
provider_request_headers: &mut BTreeMap<String, String>,
provider_request_body: &Value,
@@ -457,30 +426,6 @@ pub fn apply_codex_openai_responses_special_headers(
}
}
#[deprecated(
since = "0.1.0",
note = "use apply_codex_openai_responses_special_headers"
)]
pub fn apply_codex_openai_cli_special_headers(
provider_request_headers: &mut BTreeMap<String, String>,
provider_request_body: &Value,
original_headers: &http::HeaderMap,
provider_type: &str,
provider_api_format: &str,
request_id: Option<&str>,
decrypted_auth_config_raw: Option<&str>,
) {
apply_codex_openai_responses_special_headers(
provider_request_headers,
provider_request_body,
original_headers,
provider_type,
provider_api_format,
request_id,
decrypted_auth_config_raw,
);
}
#[cfg(test)]
mod tests {
use super::{

View File

@@ -165,7 +165,7 @@ mod tests {
const STANDARD_SURFACES: &[&str] = &[
"openai:chat",
"openai:cli",
"openai:responses",
"claude:chat",
"claude:cli",
"gemini:chat",
@@ -185,7 +185,7 @@ mod tests {
}),
"/v1/chat/completions",
),
"openai:cli" => (
"openai:responses" => (
json!({
"model": "source-model",
"instructions": "Be concise.",
@@ -227,7 +227,7 @@ mod tests {
fn assert_stream_flag(provider_api_format: &str, upstream_is_stream: bool, converted: &Value) {
match provider_api_format {
"openai:chat" | "openai:cli" | "claude:chat" | "claude:cli" => {
"openai:chat" | "openai:responses" | "claude:chat" | "claude:cli" => {
assert_eq!(
converted
.get("stream")
@@ -262,24 +262,24 @@ mod tests {
])
}
fn legacy_openai_responses_alias_request_body(
fn legacy_openai_responses_request_body(
request: &Value,
provider_api_format: &str,
upstream_is_stream: bool,
) -> Value {
let chat_canonical = normalize_standard_request_to_openai_chat_request(
request,
"openai:cli",
"openai:responses",
"/v1/responses",
)
.expect("legacy openai responses alias normalization should succeed");
.expect("legacy openai responses normalization should succeed");
build_standard_request_body_from_canonical(
&chat_canonical,
"mapped-model",
provider_api_format,
upstream_is_stream,
)
.expect("legacy openai responses alias target conversion should succeed")
.expect("legacy openai responses target conversion should succeed")
}
fn legacy_openai_chat_request_body(
@@ -430,7 +430,7 @@ mod tests {
for upstream_is_stream in [false, true] {
let converted = build_standard_request_body(
&request,
"openai:cli",
"openai:responses",
"mapped-model",
"custom",
provider_api_format,
@@ -440,14 +440,14 @@ mod tests {
None,
)
.expect("typed canonical route should build");
let legacy = legacy_openai_responses_alias_request_body(
let legacy = legacy_openai_responses_request_body(
&request,
provider_api_format,
upstream_is_stream,
);
assert_eq!(
converted, legacy,
"typed canonical openai:cli -> {provider_api_format} changed payload with upstream_is_stream={upstream_is_stream}"
"typed canonical openai:responses -> {provider_api_format} changed payload with upstream_is_stream={upstream_is_stream}"
);
}
}
@@ -609,8 +609,8 @@ mod tests {
for provider_api_format in [
"openai:chat",
"openai:cli",
"openai:compact",
"openai:responses",
"openai:responses:compact",
"gemini:chat",
"gemini:cli",
] {
@@ -691,8 +691,8 @@ mod tests {
for provider_api_format in [
"openai:chat",
"openai:cli",
"openai:compact",
"openai:responses",
"openai:responses:compact",
"claude:chat",
"claude:cli",
] {
@@ -735,14 +735,14 @@ mod tests {
client_api_format,
"gpt-5.5",
"codex",
"openai:cli",
"openai:responses",
request_path,
true,
Some(&body_rules),
Some("key-1"),
)
.unwrap_or_else(|| {
panic!("{client_api_format} -> openai:cli should build with codex body rules")
panic!("{client_api_format} -> openai:responses should build with codex body rules")
});
assert_eq!(converted["model"], "gpt-5.5");
@@ -753,7 +753,7 @@ mod tests {
assert!(converted.get("top_p").is_none());
assert!(
converted.get("instructions").is_some(),
"{client_api_format} -> openai:cli should keep or inject instructions"
"{client_api_format} -> openai:responses should keep or inject instructions"
);
}
}
@@ -932,7 +932,7 @@ mod tests {
let converted = build_standard_request_body(
&request,
"openai:cli",
"openai:responses",
"gpt-5",
"openai",
"openai:chat",

View File

@@ -6,12 +6,6 @@ pub mod matrix;
pub mod normalize;
pub mod openai_responses;
#[allow(deprecated)]
pub use codex::apply_openai_compact_special_body_edits;
#[allow(deprecated)]
pub use codex::{
apply_codex_openai_cli_special_body_edits, apply_codex_openai_cli_special_headers,
};
pub use codex::{
apply_codex_openai_responses_special_body_edits, apply_codex_openai_responses_special_headers,
apply_openai_responses_compact_special_body_edits, CODEX_OPENAI_IMAGE_DEFAULT_MODEL,

View File

@@ -1,10 +1,8 @@
use crate::contracts::{
OPENAI_CLI_STREAM_PLAN_KIND, OPENAI_CLI_SYNC_PLAN_KIND, OPENAI_COMPACT_STREAM_PLAN_KIND,
OPENAI_COMPACT_SYNC_PLAN_KIND, OPENAI_RESPONSES_COMPACT_STREAM_PLAN_KIND,
OPENAI_RESPONSES_COMPACT_STREAM_SUCCESS_REPORT_KIND, OPENAI_RESPONSES_COMPACT_SYNC_PLAN_KIND,
OPENAI_RESPONSES_COMPACT_SYNC_SUCCESS_REPORT_KIND, OPENAI_RESPONSES_STREAM_PLAN_KIND,
OPENAI_RESPONSES_STREAM_SUCCESS_REPORT_KIND, OPENAI_RESPONSES_SYNC_PLAN_KIND,
OPENAI_RESPONSES_SYNC_SUCCESS_REPORT_KIND,
OPENAI_RESPONSES_COMPACT_STREAM_PLAN_KIND, OPENAI_RESPONSES_COMPACT_STREAM_SUCCESS_REPORT_KIND,
OPENAI_RESPONSES_COMPACT_SYNC_PLAN_KIND, OPENAI_RESPONSES_COMPACT_SYNC_SUCCESS_REPORT_KIND,
OPENAI_RESPONSES_STREAM_PLAN_KIND, OPENAI_RESPONSES_STREAM_SUCCESS_REPORT_KIND,
OPENAI_RESPONSES_SYNC_PLAN_KIND, OPENAI_RESPONSES_SYNC_SUCCESS_REPORT_KIND,
};
#[derive(Debug, Clone, Copy)]
@@ -32,20 +30,6 @@ pub fn resolve_sync_spec(plan_kind: &str) -> Option<LocalOpenAiResponsesSpec> {
compact: true,
require_streaming: false,
}),
OPENAI_CLI_SYNC_PLAN_KIND => Some(LocalOpenAiResponsesSpec {
api_format: "openai:responses",
decision_kind: OPENAI_CLI_SYNC_PLAN_KIND,
report_kind: "openai_cli_sync_success",
compact: false,
require_streaming: false,
}),
OPENAI_COMPACT_SYNC_PLAN_KIND => Some(LocalOpenAiResponsesSpec {
api_format: "openai:responses:compact",
decision_kind: OPENAI_COMPACT_SYNC_PLAN_KIND,
report_kind: OPENAI_RESPONSES_SYNC_SUCCESS_REPORT_KIND,
compact: true,
require_streaming: false,
}),
_ => None,
}
}
@@ -66,20 +50,6 @@ pub fn resolve_stream_spec(plan_kind: &str) -> Option<LocalOpenAiResponsesSpec>
compact: true,
require_streaming: true,
}),
OPENAI_CLI_STREAM_PLAN_KIND => Some(LocalOpenAiResponsesSpec {
api_format: "openai:responses",
decision_kind: OPENAI_CLI_STREAM_PLAN_KIND,
report_kind: "openai_cli_stream_success",
compact: false,
require_streaming: true,
}),
OPENAI_COMPACT_STREAM_PLAN_KIND => Some(LocalOpenAiResponsesSpec {
api_format: "openai:responses:compact",
decision_kind: OPENAI_COMPACT_STREAM_PLAN_KIND,
report_kind: OPENAI_RESPONSES_STREAM_SUCCESS_REPORT_KIND,
compact: true,
require_streaming: true,
}),
_ => None,
}
}
@@ -98,29 +68,11 @@ mod tests {
}
#[test]
fn resolves_legacy_openai_cli_sync_spec() {
let spec = resolve_sync_spec("openai_cli_sync").expect("spec");
assert_eq!(spec.api_format, "openai:responses");
assert_eq!(spec.report_kind, "openai_cli_sync_success");
assert!(!spec.compact);
assert!(!spec.require_streaming);
}
#[test]
fn resolves_openai_compact_stream_spec() {
fn resolves_openai_responses_compact_stream_spec() {
let spec = resolve_stream_spec("openai_responses_compact_stream").expect("spec");
assert_eq!(spec.api_format, "openai:responses:compact");
assert_eq!(spec.report_kind, "openai_responses_compact_stream_success");
assert!(spec.compact);
assert!(spec.require_streaming);
}
#[test]
fn resolves_legacy_openai_compact_stream_spec() {
let spec = resolve_stream_spec("openai_compact_stream").expect("spec");
assert_eq!(spec.api_format, "openai:responses:compact");
assert_eq!(spec.report_kind, "openai_responses_stream_success");
assert!(spec.compact);
assert!(spec.require_streaming);
}
}