| 267 | } |
| 268 | |
| 269 | pub async fn invoke(&self, os: &Os, updates: &mut impl Write) -> Result<InvokeOutput> { |
| 270 | if self.operations.len() == 1 { |
| 271 | // Single operation - return result directly |
| 272 | self.operations[0].invoke(os, updates).await |
| 273 | } else { |
| 274 | // Multiple operations - combine results |
| 275 | let mut combined_results = Vec::new(); |
| 276 | let mut all_images = Vec::new(); |
| 277 | let mut has_non_image_ops = false; |
| 278 | let mut success_ops = 0usize; |
| 279 | let mut failed_ops = 0usize; |
| 280 | |
| 281 | for (i, op) in self.operations.iter().enumerate() { |
| 282 | match op.invoke(os, updates).await { |
| 283 | Ok(result) => { |
| 284 | success_ops += 1; |
| 285 | |
| 286 | match &result.output { |
| 287 | OutputKind::Text(text) => { |
| 288 | combined_results.push(format!("=== Operation {} Result (Text) ===\n{}", i + 1, text)); |
| 289 | has_non_image_ops = true; |
| 290 | }, |
| 291 | OutputKind::Json(json) => { |
| 292 | combined_results.push(format!( |
| 293 | "=== Operation {} Result (Json) ===\n{}", |
| 294 | i + 1, |
| 295 | serde_json::to_string_pretty(json)? |
| 296 | )); |
| 297 | has_non_image_ops = true; |
| 298 | }, |
| 299 | OutputKind::Images(images) => { |
| 300 | all_images.extend(images.clone()); |
| 301 | combined_results.push(format!( |
| 302 | "=== Operation {} Result (Images) ===\n[{} images processed]", |
| 303 | i + 1, |
| 304 | images.len() |
| 305 | )); |
| 306 | }, |
| 307 | // This branch won't be reached because single operation execution never returns a Mixed |
| 308 | // result |
| 309 | OutputKind::Mixed { text: _, images: _ } => {}, |
| 310 | } |
| 311 | }, |
| 312 | |
| 313 | Err(err) => { |
| 314 | failed_ops += 1; |
| 315 | combined_results.push(format!("=== Operation {} Error ===\n{}", i + 1, err)); |
| 316 | }, |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | queue!( |
| 321 | updates, |
| 322 | style::Print("\n"), |
| 323 | style::Print(CONTINUATION_LINE), |
| 324 | style::Print("\n") |
| 325 | )?; |
| 326 | super::queue_function_result( |