From 6ec195be524a7b1e5550de985baf24a437ef2596 Mon Sep 17 00:00:00 2001 From: dal Date: Wed, 5 Mar 2025 10:39:18 -0700 Subject: [PATCH] plan being saved effectively now --- .../handlers/src/chats/post_chat_handler.rs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/api/libs/handlers/src/chats/post_chat_handler.rs b/api/libs/handlers/src/chats/post_chat_handler.rs index 129c6e514..7e5e032b3 100644 --- a/api/libs/handlers/src/chats/post_chat_handler.rs +++ b/api/libs/handlers/src/chats/post_chat_handler.rs @@ -1164,18 +1164,22 @@ fn transform_assistant_tool_message( if !delta.is_empty() { text.message_chunk = Some(delta); text.message = None; // Clear message field while streaming - } else { - // If there's no new content, don't send a message + } else if text.status != Some("completed".to_string()) { + // If there's no new content and it's not complete, don't send a message return None; } - - if text.status == Some("completed".to_string()) { - println!("CHUNK DEBUG [{}] Completing message", text.id); - text.message = tracker.get_complete_text(text.id.clone()); - text.message_chunk = None; - tracker.clear_chunk(text.id.clone()); - } } + + if text.status == Some("completed".to_string()) { + println!("CHUNK DEBUG [{}] Completing message", text.id); + // For completed messages, either use accumulated text or the final message + text.message = tracker.get_complete_text(text.id.clone()) + .or(text.message) + .or(text.message_chunk.clone()); + text.message_chunk = None; + tracker.clear_chunk(text.id.clone()); + } + Some(BusterReasoningMessage::Text(text)) } BusterReasoningMessage::File(mut file) => {