Skip to content

Commit 22e5738

Browse files
committed
add a mix output type
1 parent bfa5016 commit 22e5738

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

crates/chat-cli/src/cli/chat/message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl From<InvokeOutput> for ToolUseResultBlock {
255255
OutputKind::Text(text) => Self::Text(text),
256256
OutputKind::Json(value) => Self::Json(value),
257257
OutputKind::Images(_) => Self::Text("See images data supplied".to_string()),
258+
OutputKind::Mixed { text, .. } => ToolUseResultBlock::Text(text),
258259
}
259260
}
260261
}

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,10 @@ impl ChatSession {
15231523
OutputKind::Images(ref image) => {
15241524
image_blocks.extend(image.clone());
15251525
},
1526+
OutputKind::Mixed { ref text, ref images } => {
1527+
debug!("Output is Mixed: text = {:?}, images = {}", text, images.len());
1528+
image_blocks.extend(images.clone());
1529+
},
15261530
}
15271531

15281532
debug!("tool result output: {:#?}", result);

crates/chat-cli/src/cli/chat/tools/fs_read.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crossterm::queue;
66
use crossterm::style::{
77
self,
88
Color,
9-
Stylize,
109
};
1110
use eyre::{
1211
Result,
@@ -38,9 +37,6 @@ use crate::cli::chat::util::images::{
3837
};
3938
use crate::os::Os;
4039

41-
const CHECKMARK: &str = "✔";
42-
const CROSS: &str = "✘";
43-
4440
#[derive(Debug, Clone, Deserialize)]
4541
pub struct FsRead {
4642
// For batch operations
@@ -112,7 +108,7 @@ impl FsRead {
112108
// Multiple operations - combine results
113109
let mut combined_results = Vec::new();
114110
let mut all_images = Vec::new();
115-
111+
let mut has_non_image_ops = false;
116112
let mut success_ops = 0usize;
117113
let mut failed_ops = 0usize;
118114

@@ -128,13 +124,15 @@ impl FsRead {
128124
i + 1,
129125
text
130126
));
127+
has_non_image_ops = true;
131128
},
132129
OutputKind::Json(json) => {
133130
combined_results.push(format!(
134131
"=== Operation {} Result (Json) ===\n{}",
135132
i + 1,
136133
serde_json::to_string_pretty(json)?
137134
));
135+
has_non_image_ops = true;
138136
},
139137
OutputKind::Images(images) => {
140138
all_images.extend(images.clone());
@@ -144,6 +142,9 @@ impl FsRead {
144142
images.len()
145143
));
146144
},
145+
// This branch won't be reached because single operation execution never returns a Mixed
146+
// result
147+
OutputKind::Mixed { text: _, images: _ } => {},
147148
}
148149
},
149150

@@ -172,15 +173,23 @@ impl FsRead {
172173
true,
173174
)?;
174175

175-
// If we have images, return them as the primary output
176-
if !all_images.is_empty() {
176+
let combined_text = combined_results.join("\n\n");
177+
178+
if !all_images.is_empty() && has_non_image_ops {
179+
queue!(updates, style::Print("\nherherherherherh"),)?;
180+
Ok(InvokeOutput {
181+
output: OutputKind::Mixed {
182+
text: combined_text,
183+
images: all_images,
184+
},
185+
})
186+
} else if !all_images.is_empty() {
177187
Ok(InvokeOutput {
178188
output: OutputKind::Images(all_images),
179189
})
180190
} else {
181-
// Otherwise, return the combined text results
182191
Ok(InvokeOutput {
183-
output: OutputKind::Text(combined_results.join("\n\n")),
192+
output: OutputKind::Text(combined_text),
184193
})
185194
}
186195
}
@@ -248,7 +257,7 @@ impl FsImage {
248257
pub async fn invoke(&self, updates: &mut impl Write) -> Result<InvokeOutput> {
249258
let pre_processed_paths: Vec<String> = self.image_paths.iter().map(|path| pre_process(path)).collect();
250259
let valid_images = handle_images_from_paths(updates, &pre_processed_paths);
251-
super::queue_function_result(&format!("Successfully read image"), updates, false, false)?;
260+
super::queue_function_result("Successfully read image", updates, false, false)?;
252261
Ok(InvokeOutput {
253262
output: OutputKind::Images(valid_images),
254263
})

crates/chat-cli/src/cli/chat/tools/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ impl InvokeOutput {
327327
OutputKind::Text(s) => s.as_str(),
328328
OutputKind::Json(j) => j.as_str().unwrap_or_default(),
329329
OutputKind::Images(_) => "",
330+
OutputKind::Mixed { text, .. } => text.as_str(), // Return the text part
330331
}
331332
}
332333
}
@@ -337,6 +338,7 @@ pub enum OutputKind {
337338
Text(String),
338339
Json(serde_json::Value),
339340
Images(RichImageBlocks),
341+
Mixed { text: String, images: RichImageBlocks },
340342
}
341343

342344
impl Default for OutputKind {

crates/q_cli/src/cli/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,13 @@ fn qchat_path() -> Result<PathBuf> {
608608

609609
#[cfg(target_os = "macos")]
610610
fn qchat_path() -> Result<PathBuf> {
611-
use fig_util::consts::CHAT_BINARY_NAME;
612-
use macos_utils::bundle::get_bundle_path_for_executable;
611+
Ok(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/debug/chat_cli"))
612+
613+
// use fig_util::consts::CHAT_BINARY_NAME;
614+
// use macos_utils::bundle::get_bundle_path_for_executable;
613615

614-
Ok(get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.join(CHAT_BINARY_NAME)))
616+
// Ok(get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.
617+
// join(CHAT_BINARY_NAME)))
615618
}
616619

617620
#[cfg(test)]

0 commit comments

Comments
 (0)