mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Send local TUI images as portable attachments to remote app servers (#45499)
## Why Remote app servers cannot read image paths on the TUI host. Image attachments need to carry their contents when submitting to a remote workspace. ## What changed - Prepare local images as data URLs off the event loop for new turns and steers, preserving source pixels for model-specific resizing and enforcing a 32 MiB image transport budget. - Show preparation progress, preserve queued message order, and recover drafts on preparation failures, cancellation, disconnects, or thread switches. Ignore stale preparation completions. - Avoid duplicate user messages from server receipts and duplicate image labels in history. ## Testing Add regression tests for portable image contents, receipt deduplication, draft restoration, responsive input during preparation, and cancellation across thread and connection changes. GitOrigin-RevId: 6404615eae0b06c141af96b4229501c61f7fcfee
This commit is contained in:
1 parent
afaad7cdc0
commit
d38b5260a1
21 files changed
+731
-40
No files matched your search
@@ -149,8 +149,17 @@ fn build_user_message_lines_with_elements(
|
||||
raw_lines
|
||||
}
|
||||
|
||||
fn remote_image_display_line(style: Style, index: usize) -> Line<'static> {
|
||||
Line::from(local_image_label_text(index)).style(style)
|
||||
impl UserHistoryCell {
|
||||
fn image_labels_not_in_message(&self) -> impl Iterator<Item = String> + '_ {
|
||||
(1..=self.remote_image_urls.len())
|
||||
.map(local_image_label_text)
|
||||
.filter(|label| {
|
||||
!self
|
||||
.text_elements
|
||||
.iter()
|
||||
.any(|element| element.placeholder(&self.message) == Some(label.as_str()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl HistoryCell for UserHistoryCell {
|
||||
@@ -184,16 +193,13 @@ impl HistoryCell for UserHistoryCell {
|
||||
None
|
||||
} else {
|
||||
Some(plain_hyperlink_lines(adaptive_wrap_lines(
|
||||
self.remote_image_urls
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, _url)| {
|
||||
remote_image_display_line(element_style, idx.saturating_add(1))
|
||||
}),
|
||||
self.image_labels_not_in_message()
|
||||
.map(|label| Line::from(label).style(element_style)),
|
||||
RtOptions::new(usize::from(wrap_width))
|
||||
.wrap_algorithm(textwrap::WrapAlgorithm::FirstFit),
|
||||
)))
|
||||
};
|
||||
}
|
||||
.filter(|lines| !lines.is_empty());
|
||||
|
||||
let wrapped_message = if message.is_empty() && text_elements.is_empty() {
|
||||
None
|
||||
@@ -290,16 +296,12 @@ impl HistoryCell for UserHistoryCell {
|
||||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||||
let message = sanitize_user_text((&self.message).into());
|
||||
let mut lines = raw_lines_from_source(message.as_ref().trim_end_matches(['\r', '\n']));
|
||||
if !self.remote_image_urls.is_empty() {
|
||||
let mut image_labels = self.image_labels_not_in_message().peekable();
|
||||
if image_labels.peek().is_some() {
|
||||
if !lines.is_empty() {
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
lines.extend(
|
||||
self.remote_image_urls
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, _url)| Line::from(local_image_label_text(idx.saturating_add(1)))),
|
||||
);
|
||||
lines.extend(image_labels.map(Line::from));
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tui/src/history_cell/tests.rs
|
||||
expression: "render_lines(&cell.raw_lines()).join(\"\\n\")"
|
||||
---
|
||||
[Image #1] describe inline image
|
||||
@@ -2413,7 +2413,7 @@ fn user_history_cell_renders_remote_image_urls() {
|
||||
|
||||
#[test]
|
||||
fn user_history_cell_summarizes_inline_data_urls() {
|
||||
let cell = UserHistoryCell {
|
||||
let mut cell = UserHistoryCell {
|
||||
spoken: false,
|
||||
message: "describe inline image".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
@@ -2425,6 +2425,16 @@ fn user_history_cell_summarizes_inline_data_urls() {
|
||||
|
||||
assert!(rendered.contains("[Image #1]"));
|
||||
assert!(rendered.contains("describe inline image"));
|
||||
let placeholder = "[Image #1]";
|
||||
cell.message = format!("{placeholder} describe inline image");
|
||||
cell.text_elements = vec![TextElement::new(
|
||||
(0..placeholder.len()).into(),
|
||||
Some(placeholder.to_string()),
|
||||
)];
|
||||
insta::assert_snapshot!(
|
||||
"portable_image_raw_output",
|
||||
render_lines(&cell.raw_lines()).join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user