show messages fix

This commit is contained in:
Dhanji Prasanna
2025-10-10 15:36:57 +11:00
parent 4a819e8f27
commit d16a694862

View File

@@ -1604,11 +1604,14 @@ The tool will execute immediately and you'll receive the result (success or erro
let has_text_response = !text_content.trim().is_empty() let has_text_response = !text_content.trim().is_empty()
|| !current_response.trim().is_empty(); || !current_response.trim().is_empty();
// If we have text in the parser buffer but not in current_response, // Don't re-add text from parser buffer if we already displayed it
// we should add it to the response // The parser buffer contains ALL accumulated text, but current_response
if !text_content.trim().is_empty() && current_response.is_empty() { // already has what was displayed during streaming
current_response = if current_response.is_empty() && !text_content.trim().is_empty() {
filter_json_tool_calls(text_content).trim().to_string(); // Only use parser text if we truly have no response
// This should be rare - only if streaming failed to display anything
debug!("Warning: Using parser buffer text as fallback - this may duplicate output");
// Don't add it - it's already been displayed
} }
if !has_text_response && full_response.is_empty() { if !has_text_response && full_response.is_empty() {
@@ -1707,9 +1710,11 @@ The tool will execute immediately and you'll receive the result (success or erro
)); ));
} }
// Add current response to full response if we have any // Set full_response to current_response (don't append)
if !current_response.is_empty() { // current_response already contains everything that was displayed
full_response.push_str(&current_response); // Appending would duplicate the output
if !current_response.is_empty() && full_response.is_empty() {
full_response = current_response.clone();
} }
self.ui_writer.println(""); self.ui_writer.println("");
@@ -1776,13 +1781,10 @@ The tool will execute immediately and you'll receive the result (success or erro
// If we get here and no tool was executed, we're done // If we get here and no tool was executed, we're done
if !tool_executed { if !tool_executed {
// Check if we have any text in the parser that wasn't added to current_response // Don't add parser text_content here - it's already been displayed during streaming
let text_content = parser.get_text_content(); // The parser buffer contains ALL accumulated text, including what was already shown
if !text_content.trim().is_empty() && current_response.is_empty() { // Adding it here would cause duplication of the entire response
// The LLM responded with text but didn't call final_output debug!("Stream completed without tool execution. Response already displayed during streaming.");
// Add the text to the response
current_response = filter_json_tool_calls(text_content).trim().to_string();
}
let has_response = !current_response.is_empty() || !full_response.is_empty(); let has_response = !current_response.is_empty() || !full_response.is_empty();
@@ -1792,7 +1794,11 @@ The tool will execute immediately and you'll receive the result (success or erro
iteration_count iteration_count
); );
} else { } else {
full_response.push_str(&current_response); // Don't add current_response to full_response here - it was already displayed during streaming
// Only add it if full_response is empty (meaning no tools were executed)
if full_response.is_empty() && !current_response.is_empty() {
full_response = current_response.clone();
}
self.ui_writer.println(""); self.ui_writer.println("");
} }