Support image references by file ID in inputs and tool outputs (#45794)

## What changed

- Accept `fileId` alongside the existing `url` form for app-server image inputs, and forward file references to the Responses API as `file_id`. Update generated schemas and client types.
- Preserve file references, image detail hints, and mixed inline/file image ordering through user-message events, thread history, and rollout migration. Retain file images when truncating tool output.
- Pass file references through image preparation without resolving them, while keeping resize-notice numbering correct. Omit them from unsupported TUI display and Guardian image context.
- Reject image-edit requests whose recent-image window includes a file reference, preventing selection of an older inline image instead.

## Testing

Add coverage for serialization, request and rollout preservation, mixed-image history ordering, incomplete ordering metadata, tool-output truncation, and rejection of unsupported image-edit selections.

GitOrigin-RevId: 6ca20a8577155cc934b720803c3b7b3bffdf972a
This commit is contained in:
Krish Chainani authored and copyberry committed 2026-09-15 21:19:08 +00:00
1 parent c51cb968e4
commit 7b8b17b97a
95 files changed
+2434 -324

No files matched your search

+14 -7
View File
@@ -220,13 +220,12 @@ fn response_input_to_code_mode_result(response: ResponseInputItem) -> JsonValue
| codex_protocol::models::ContentItem::OutputText { text } => {
FunctionCallOutputContentItem::InputText { text }
}
codex_protocol::models::ContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail,
} => FunctionCallOutputContentItem::InputImage {
image: ImageReference::Inline { image_url },
detail: detail.or(Some(DEFAULT_IMAGE_DETAIL)),
},
codex_protocol::models::ContentItem::InputImage { image, detail } => {
FunctionCallOutputContentItem::InputImage {
image,
detail: detail.or(Some(DEFAULT_IMAGE_DETAIL)),
}
}
codex_protocol::models::ContentItem::InputAudio { audio_url } => {
FunctionCallOutputContentItem::InputAudio { audio_url }
}
@@ -260,6 +259,10 @@ fn content_items_to_code_mode_result(items: &[FunctionCallOutputContentItem]) ->
image: ImageReference::Inline { image_url },
..
} if !image_url.trim().is_empty() => Some(image_url.clone()),
FunctionCallOutputContentItem::InputImage {
image: ImageReference::File { file_id },
..
} if !file_id.trim().is_empty() => Some(file_id.clone()),
FunctionCallOutputContentItem::InputAudio { audio_url }
if !audio_url.trim().is_empty() =>
{
@@ -274,3 +277,7 @@ fn content_items_to_code_mode_result(items: &[FunctionCallOutputContentItem]) ->
.join("\n"),
)
}
#[cfg(test)]
#[path = "tool_output_tests.rs"]
mod tests;
+25
View File
@@ -0,0 +1,25 @@
use codex_protocol::models::ContentItem;
use codex_protocol::models::ImageReference;
use codex_protocol::models::ResponseInputItem;
use pretty_assertions::assert_eq;
use super::response_input_to_code_mode_result;
#[test]
fn code_mode_text_preserves_file_backed_image_id() {
let response = ResponseInputItem::Message {
role: "user".to_string(),
content: vec![ContentItem::InputImage {
image: ImageReference::File {
file_id: "file_123".to_string(),
},
detail: None,
}],
phase: None,
};
assert_eq!(
response_input_to_code_mode_result(response),
serde_json::json!("file_123")
);
}