fix(compact): 移除 OpenAI Compact 请求中不受支持的 store 参数

- 在 OpenAI Compact 请求规范化流程中剥离 `store`
- 将 compact 默认 body rules 与 Codex CLI 默认规则拆分
- 补充 same-format 和转换链路的 compact 回归测试
This commit is contained in:
AAEE86
2026-04-12 01:52:25 +08:00
parent 335e440cc5
commit def8135118
10 changed files with 97 additions and 18 deletions

View File

@@ -139,9 +139,9 @@ pub use crate::planner::specialized::{
};
pub use crate::planner::standard::{
apply_codex_openai_cli_special_body_edits, apply_codex_openai_cli_special_headers,
build_cross_format_openai_chat_request_body, build_cross_format_openai_cli_request_body,
build_local_openai_chat_request_body, build_local_openai_cli_request_body,
build_standard_request_body, build_standard_upstream_url,
apply_openai_compact_special_body_edits, build_cross_format_openai_chat_request_body,
build_cross_format_openai_cli_request_body, build_local_openai_chat_request_body,
build_local_openai_cli_request_body, build_standard_request_body, build_standard_upstream_url,
claude::{
resolve_stream_spec as resolve_claude_stream_spec,
resolve_sync_spec as resolve_claude_sync_spec,

View File

@@ -20,6 +20,12 @@ fn is_codex_openai_cli_request(provider_type: &str, provider_api_format: &str) -
)
}
fn is_openai_compact_request(provider_api_format: &str) -> bool {
provider_api_format
.trim()
.eq_ignore_ascii_case("openai:compact")
}
fn build_stable_codex_prompt_cache_key(user_api_key_id: &str) -> Option<String> {
let normalized = user_api_key_id.trim();
if normalized.is_empty() {
@@ -135,6 +141,22 @@ fn maybe_inject_codex_prompt_cache_key(
);
}
pub fn apply_openai_compact_special_body_edits(
provider_request_body: &mut Value,
provider_api_format: &str,
) {
if !is_openai_compact_request(provider_api_format) {
return;
}
let Some(body_object) = provider_request_body.as_object_mut() else {
return;
};
// `/v1/responses/compact` does not accept `store`.
body_object.remove("store");
}
pub fn apply_codex_openai_cli_special_body_edits(
provider_request_body: &mut Value,
provider_type: &str,
@@ -162,7 +184,9 @@ pub fn apply_codex_openai_cli_special_body_edits(
if !body_rules_handle_path(body_rules, "metadata") {
body_object.remove("metadata");
}
if !body_rules_handle_path(body_rules, "store") {
if is_openai_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));
}
if !body_rules_handle_path(body_rules, "instructions")

View File

@@ -14,7 +14,7 @@ use crate::conversion::request::{
};
use super::{
codex::apply_codex_openai_cli_special_body_edits,
apply_openai_compact_special_body_edits, codex::apply_codex_openai_cli_special_body_edits,
normalize::build_local_openai_chat_request_body,
};
@@ -52,6 +52,7 @@ pub fn build_standard_request_body(
body_rules,
user_api_key_id,
);
apply_openai_compact_special_body_edits(&mut provider_request_body, provider_api_format);
Some(provider_request_body)
}

View File

@@ -8,6 +8,7 @@ pub mod openai_cli;
pub use codex::{
apply_codex_openai_cli_special_body_edits, apply_codex_openai_cli_special_headers,
apply_openai_compact_special_body_edits,
};
pub use family::{LocalStandardSourceFamily, LocalStandardSourceMode, LocalStandardSpec};
pub use matrix::{