feat(codex): 按操作语义路由 Responses V2 压缩

(cherry picked from commit 2fc604e047)
This commit is contained in:
MMEXA
2026-07-16 00:34:42 +08:00
committed by elky
parent 598b2fb374
commit 20b27a13b2
75 changed files with 732 additions and 50 deletions
@@ -1352,6 +1352,7 @@ fn parse_embedded_provider_model_mappings(
priority: 1,
api_formats: None,
endpoint_ids: None,
operations: None,
}]))
}
@@ -1374,6 +1375,7 @@ fn parse_provider_model_mappings_array(
priority: 1,
api_formats: None,
endpoint_ids: None,
operations: None,
});
}
}
@@ -1430,6 +1432,11 @@ fn parse_provider_model_mapping_object_lenient(
object.get("endpoint_ids").cloned(),
"models.provider_model_mappings.endpoint_ids",
)?;
let operations = parse_string_list(
object.get("operations").cloned(),
"models.provider_model_mappings.operations",
)?
.and_then(normalize_request_operations);
Ok(Some(StoredProviderModelMapping {
name: name.to_string(),
@@ -1440,9 +1447,19 @@ fn parse_provider_model_mapping_object_lenient(
})?,
api_formats,
endpoint_ids,
operations,
}))
}
fn normalize_request_operations(values: Vec<String>) -> Option<Vec<String>> {
let operations = values
.into_iter()
.map(|value| value.trim().to_ascii_lowercase())
.filter(|value| !value.is_empty())
.collect::<Vec<_>>();
(!operations.is_empty()).then_some(operations)
}
#[cfg(test)]
mod tests {
use serde_json::json;
@@ -1626,7 +1643,7 @@ mod tests {
#[test]
fn parse_provider_model_mappings_accepts_stringified_array() {
let parsed = parse_provider_model_mappings(Some(json!(
"[{\"name\":\"gpt-5.2\",\"priority\":2,\"api_formats\":[\"openai:chat\"]}]"
"[{\"name\":\"gpt-5.2\",\"priority\":2,\"api_formats\":[\"openai:chat\"],\"operations\":[\"COMPACT\"]}]"
)))
.expect("stringified provider_model_mappings should parse");
@@ -1637,6 +1654,7 @@ mod tests {
priority: 2,
api_formats: Some(vec!["openai:chat".to_string()]),
endpoint_ids: None,
operations: Some(vec!["compact".to_string()]),
}])
);
}
@@ -1653,6 +1671,7 @@ mod tests {
priority: 1,
api_formats: None,
endpoint_ids: None,
operations: None,
}])
);
}
@@ -1676,12 +1695,14 @@ mod tests {
priority: 1,
api_formats: None,
endpoint_ids: None,
operations: None,
},
StoredProviderModelMapping {
name: "gpt-5.2-mini".to_string(),
priority: 1,
api_formats: None,
endpoint_ids: None,
operations: None,
}
])
);