From 5d163ce2bedcf10213d373f2f0955fe930c0967b Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 4 Dec 2026 02:40:02 +0100 Subject: [PATCH] fix(ui-egui): reply-size check only where the agents channel is (web build) craft-automation is a desktop-only dependency of ui-egui, so the wasm gate could not resolve MAX_RESPONSE_BYTES. The web hands replies to the page, which has no line limit. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/control.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 951585fca..bec84a92c 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -25,7 +25,6 @@ use std::sync::Arc; use std::sync::mpsc::Sender; -use craft_automation::protocol::MAX_RESPONSE_BYTES; use serde_json::{Value, json}; use crate::EffectcraftApp; @@ -1002,8 +1001,15 @@ pub fn save_screenshot(image: &egui::ColorImage, path: Option<&str>, crop: Optio } } -/// A compressed PNG, for a reply: a reply line has a limit ([`MAX_RESPONSE_BYTES`] on the agents -/// channel), which an uncompressed window or frame passes. +/// The longest reply line: the agents channel's on desktop. The web hands replies to the page, +/// which has no such limit. +#[cfg(not(target_arch = "wasm32"))] +const REPLY_LIMIT: Option = Some(craft_automation::protocol::MAX_RESPONSE_BYTES); +#[cfg(target_arch = "wasm32")] +const REPLY_LIMIT: Option = None; + +/// A compressed PNG, for a reply: a reply line has a limit ([`REPLY_LIMIT`]), which an +/// uncompressed window or frame passes. fn compressed_png(rgba: &[u8], w: u32, h: u32) -> Result, String> { use image::ImageEncoder; use image::codecs::png::{CompressionType, FilterType, PngEncoder}; @@ -1020,15 +1026,17 @@ const FRAME_TOO_LARGE: &str = "pass `path` to write it to a file, or `max_side` const SCREENSHOT_TOO_LARGE: &str = "pass `path` to write it to a file, or `panel` or `id` to capture part of the window"; /// `png` in base64 for a reply, or an error that says what to do (`instead`) when it wouldn't fit -/// in one ([`MAX_RESPONSE_BYTES`], with room for the rest of the reply). +/// in one ([`REPLY_LIMIT`], with room for the rest of the reply). fn inline_base64(png: &[u8], instead: &str) -> Result { const REST_OF_REPLY: usize = 4 << 10; let encoded = base64(png); - if encoded.len().saturating_add(REST_OF_REPLY) > MAX_RESPONSE_BYTES { + if let Some(limit) = REPLY_LIMIT + && encoded.len().saturating_add(REST_OF_REPLY) > limit + { return Err(format!( "the image is too large to return inline ({} MiB in base64, a reply holds at most {} MiB): {instead}", encoded.len().div_ceil(1 << 20), - MAX_RESPONSE_BYTES >> 20 + limit >> 20 )); } Ok(encoded)