agent: Patch image format bug (#45978)
Mason Palmer
,
versecafe
, and
MrSubidubi
created
Closes #44694
Release Notes:
- Fixed images being converted to png but retaining old format
## Before:
<img width="574" height="327" alt="Screenshot 2026-01-02 at 5 34 24 PM"
src="https://github.com/user-attachments/assets/92331939-cebc-4f53-99fc-10d5181cf87e"
/>
## After:
<img width="638" height="489" alt="Screenshot 2026-01-02 at 5 34 36 PM"
src="https://github.com/user-attachments/assets/47c05906-fa56-4a53-abd4-790c42230772"
/>
---------
Co-authored-by: versecafe <147033096+versecafe@users.noreply.github.com>
Co-authored-by: MrSubidubi <finn@zed.dev>
Change summary
crates/agent_ui/src/mention_set.rs | 6 ++----
crates/language_model/src/request.rs | 3 +++
2 files changed, 5 insertions(+), 4 deletions(-)
Detailed changes
@@ -297,14 +297,13 @@ impl MentionSet {
return cx.spawn(async move |_, cx| {
let image = task.await?;
let image = image.update(cx, |image, _| image.image.clone());
- let format = image.format;
let image = cx
.update(|cx| LanguageModelImage::from_image(image, cx))
.await;
if let Some(image) = image {
Ok(Mention::Image(MentionImage {
data: image.source,
- format,
+ format: LanguageModelImage::FORMAT,
}))
} else {
Err(anyhow!("Failed to convert image"))
@@ -672,7 +671,6 @@ pub(crate) fn paste_images_as_context(
};
let task = cx
.spawn(async move |cx| {
- let format = image.format;
let image = cx
.update(|_, cx| LanguageModelImage::from_image(image, cx))
.map_err(|e| e.to_string())?
@@ -681,7 +679,7 @@ pub(crate) fn paste_images_as_context(
if let Some(image) = image {
Ok(Mention::Image(MentionImage {
data: image.source,
- format,
+ format: LanguageModelImage::FORMAT,
}))
} else {
Err("Failed to convert image".into())
@@ -92,6 +92,9 @@ const DEFAULT_IMAGE_MAX_BYTES: usize = 5 * 1024 * 1024;
const MAX_IMAGE_DOWNSCALE_PASSES: usize = 8;
impl LanguageModelImage {
+ // All language model images are encoded as PNGs.
+ pub const FORMAT: ImageFormat = ImageFormat::Png;
+
pub fn empty() -> Self {
Self {
source: "".into(),