diff --git a/api/libs/handlers/src/chats/post_chat_handler.rs b/api/libs/handlers/src/chats/post_chat_handler.rs index 9509e64b0..e55464f62 100644 --- a/api/libs/handlers/src/chats/post_chat_handler.rs +++ b/api/libs/handlers/src/chats/post_chat_handler.rs @@ -1182,16 +1182,8 @@ fn transform_assistant_tool_message( let mut updated_files = std::collections::HashMap::new(); for (file_id, file_content) in file.files.iter() { - let temp_file_id = if file.message_type == "files" { - use std::collections::hash_map::DefaultHasher; - use std::hash::{Hash, Hasher}; - let mut hasher = DefaultHasher::new(); - file_content.file_name.hash(&mut hasher); - format!("temp_{}", hasher.finish()) - } else { - file_id.clone() - }; - + // Use the same temporary ID that was generated in the streaming parser + // This ensures consistency with the IDs generated earlier let chunk_id = format!("{}_{}", file.id, file_content.file_name); if let Some(chunk) = &file_content.file.text_chunk { @@ -1201,8 +1193,9 @@ fn transform_assistant_tool_message( let mut updated_content = file_content.clone(); updated_content.file.text_chunk = Some(delta); updated_content.file.text = None; - updated_content.id = temp_file_id.clone(); - updated_files.insert(temp_file_id, updated_content); + // Keep the original ID which should already be the temp ID + updated_content.id = file_id.clone(); + updated_files.insert(file_id.clone(), updated_content); has_updates = true; } } diff --git a/api/libs/handlers/src/chats/streaming_parser.rs b/api/libs/handlers/src/chats/streaming_parser.rs index 04c700b85..d196c60dd 100644 --- a/api/libs/handlers/src/chats/streaming_parser.rs +++ b/api/libs/handlers/src/chats/streaming_parser.rs @@ -260,12 +260,13 @@ impl StreamingParser { .and_then(Value::as_str) .unwrap_or(""); + // Generate a consistent UUID based on the file name let file_id = Uuid::new_v4().to_string(); let buster_file = BusterFile { id: file_id.clone(), file_type: file_type.clone(), - file_name: name.to_string(), + file_name: name.clone().to_string(), version_number: 1, version_id: Uuid::new_v4().to_string(), status: "loading".to_string(), @@ -277,8 +278,8 @@ impl StreamingParser { metadata: None, }; - file_ids.push(file_id.clone()); - files_map.insert(file_id, buster_file); + file_ids.push(name.clone().to_string()); + files_map.insert(name.clone().to_string(), buster_file); } } }