mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
8543e39885
## Summary - Add optional image detail to user image inputs across core, app-server v2, thread history/event mapping, and the generated app-server schemas/types. - Preserve requested detail when serializing Responses image inputs: omitted detail stays on the existing `high` default, while explicit `original` keeps local images on the original-resolution path. - Support `high`/`original` consistently for tool image outputs, including MCP `codex/imageDetail`, code-mode image helpers, and `view_image`.
43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use codex_protocol::models::DEFAULT_IMAGE_DETAIL;
|
|
use codex_protocol::models::FunctionCallOutputContentItem;
|
|
use codex_protocol::models::ImageDetail;
|
|
use codex_protocol::openai_models::ModelInfo;
|
|
|
|
pub fn can_request_original_image_detail(model_info: &ModelInfo) -> bool {
|
|
model_info.supports_image_detail_original
|
|
}
|
|
|
|
pub fn normalize_output_image_detail(
|
|
model_info: &ModelInfo,
|
|
detail: Option<ImageDetail>,
|
|
) -> Option<ImageDetail> {
|
|
match detail {
|
|
Some(ImageDetail::Original) if can_request_original_image_detail(model_info) => {
|
|
Some(ImageDetail::Original)
|
|
}
|
|
Some(ImageDetail::Original) | None => None,
|
|
Some(ImageDetail::High) => Some(ImageDetail::High),
|
|
}
|
|
}
|
|
|
|
pub fn sanitize_original_image_detail(
|
|
can_request_original_image_detail: bool,
|
|
items: &mut [FunctionCallOutputContentItem],
|
|
) {
|
|
if can_request_original_image_detail {
|
|
return;
|
|
}
|
|
|
|
for item in items {
|
|
if let FunctionCallOutputContentItem::InputImage { detail, .. } = item
|
|
&& matches!(detail, Some(ImageDetail::Original))
|
|
{
|
|
*detail = Some(DEFAULT_IMAGE_DETAIL);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "image_detail_tests.rs"]
|
|
mod tests;
|