Expose local image paths to models

This commit is contained in:
won
2026-05-31 19:26:00 -07:00
parent 10b0399034
commit a7298da06c
2 changed files with 29 additions and 4 deletions
+3 -1
View File
@@ -161,7 +161,9 @@ async fn copy_paste_local_image_persists_rollout_request_shape() -> anyhow::Resu
role: "user".to_string(),
content: vec![
ContentItem::InputText {
text: codex_protocol::models::local_image_open_tag_text(/*label_number*/ 1),
text: codex_protocol::models::local_image_open_tag_text_with_path(
/*label_number*/ 1, &abs_path,
),
},
ContentItem::InputImage {
image_url,
+26 -3
View File
@@ -1031,6 +1031,18 @@ pub fn local_image_open_tag_text(label_number: usize) -> String {
format!("{LOCAL_IMAGE_OPEN_TAG_PREFIX}{label}{LOCAL_IMAGE_OPEN_TAG_SUFFIX}")
}
pub fn local_image_open_tag_text_with_path(label_number: usize, path: &std::path::Path) -> String {
let label = local_image_label_text(label_number);
let path = path
.display()
.to_string()
.replace('&', "&")
.replace('"', """)
.replace('<', "&lt;")
.replace('>', "&gt;");
format!("{LOCAL_IMAGE_OPEN_TAG_PREFIX}{label} path=\"{path}\"{LOCAL_IMAGE_OPEN_TAG_SUFFIX}")
}
pub fn is_local_image_open_tag_text(text: &str) -> bool {
text.strip_prefix(LOCAL_IMAGE_OPEN_TAG_PREFIX)
.is_some_and(|rest| rest.ends_with(LOCAL_IMAGE_OPEN_TAG_SUFFIX))
@@ -1087,7 +1099,7 @@ pub fn local_image_content_items_with_label_number(
let mut items = Vec::with_capacity(3);
if let Some(label_number) = label_number {
items.push(ContentItem::InputText {
text: local_image_open_tag_text(label_number),
text: local_image_open_tag_text_with_path(label_number, path),
});
}
items.push(ContentItem::InputImage {
@@ -2873,7 +2885,7 @@ mod tests {
detail: None,
},
UserInput::LocalImage {
path: local_path,
path: local_path.clone(),
detail: None,
},
]);
@@ -2890,7 +2902,10 @@ mod tests {
assert_eq!(
content.get(1),
Some(&ContentItem::InputText {
text: local_image_open_tag_text(/*label_number*/ 2),
text: local_image_open_tag_text_with_path(
/*label_number*/ 2,
&local_path
),
})
);
assert!(matches!(
@@ -2910,6 +2925,14 @@ mod tests {
Ok(())
}
#[test]
fn local_image_open_tag_escapes_path() {
assert_eq!(
local_image_open_tag_text_with_path(1, std::path::Path::new(r#"/tmp/a&"<b>.png"#)),
r#"<image name=[Image #1] path="/tmp/a&amp;&quot;&lt;b&gt;.png">"#
);
}
#[test]
fn local_image_user_input_preserves_requested_detail() -> Result<()> {
let dir = tempdir()?;