From 39385acf9dff0acbcc90b511f9c3c89fac868d2e Mon Sep 17 00:00:00 2001 From: dal Date: Fri, 21 Mar 2025 12:18:26 -0600 Subject: [PATCH] Fix unused variables and redundant local bindings in post_chat_handler.rs --- .../handlers/src/chats/post_chat_handler.rs | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/api/libs/handlers/src/chats/post_chat_handler.rs b/api/libs/handlers/src/chats/post_chat_handler.rs index 6e14d2ad5..386473bfc 100644 --- a/api/libs/handlers/src/chats/post_chat_handler.rs +++ b/api/libs/handlers/src/chats/post_chat_handler.rs @@ -71,6 +71,12 @@ struct ChunkState { last_seen_content: String, } +impl Default for ChunkTracker { + fn default() -> Self { + Self::new() + } +} + impl ChunkTracker { pub fn new() -> Self { Self { @@ -141,7 +147,7 @@ pub async fn post_chat_handler( validate_context_request(request.chat_id, request.metric_id, request.dashboard_id)?; let user_org_id = match user.attributes.get("organization_id") { - Some(Value::String(org_id)) => Uuid::parse_str(&org_id).unwrap_or_default(), + Some(Value::String(org_id)) => Uuid::parse_str(org_id).unwrap_or_default(), _ => { tracing::error!("User has no organization ID"); return Err(anyhow!("User has no organization ID")); @@ -205,9 +211,7 @@ pub async fn post_chat_handler( let title_handle = { let tx = tx.clone(); - let chat_id = chat_id.clone(); - let message_id = message_id.clone(); - let user_id = user.id.clone(); + let user_id = user.id; let chat_messages = chat.messages.clone(); tokio::spawn(async move { generate_conversation_title(&chat_messages, &message_id, &user_id, &chat_id, tx).await @@ -343,7 +347,7 @@ pub async fn post_chat_handler( message_id, ChatUserMessage { request: request.prompt.clone(), - sender_id: user.id.clone(), + sender_id: user.id, sender_name: user.name.clone().unwrap_or_default(), sender_avatar: None, }, @@ -360,7 +364,7 @@ pub async fn post_chat_handler( id: message_id, request_message: request.prompt, chat_id, - created_by: user.id.clone(), + created_by: user.id, created_at: Utc::now(), updated_at: Utc::now(), deleted_at: None, @@ -383,7 +387,7 @@ pub async fn post_chat_handler( // First process completed files (database updates only) // Use a separate connection scope to ensure prompt release { - let _ = process_completed_files( + process_completed_files( &mut conn, &db_message, &all_messages, @@ -531,40 +535,37 @@ async fn process_completed_files( // Process files for database updates only for (container, _) in transformed_messages { - match container { - BusterContainer::ReasoningMessage(msg) => match &msg.reasoning { - BusterReasoningMessage::File(file) if file.message_type == "files" => { - for file_id in &file.file_ids { - // Skip if we've already processed this file ID - if !processed_file_ids.insert(file_id.clone()) { - continue; - } + if let BusterContainer::ReasoningMessage(msg) = container { match &msg.reasoning { + BusterReasoningMessage::File(file) if file.message_type == "files" => { + for file_id in &file.file_ids { + // Skip if we've already processed this file ID + if !processed_file_ids.insert(file_id.clone()) { + continue; + } - if let Some(_file_content) = file.files.get(file_id) { - // Only process files that have completed reasoning - if file.status == "completed" { - // Create message-to-file association - let message_to_file = MessageToFile { - id: Uuid::new_v4(), - message_id: message.id, - file_id: Uuid::parse_str(&file_id)?, - created_at: Utc::now(), - updated_at: Utc::now(), - deleted_at: None, - }; + if let Some(_file_content) = file.files.get(file_id) { + // Only process files that have completed reasoning + if file.status == "completed" { + // Create message-to-file association + let message_to_file = MessageToFile { + id: Uuid::new_v4(), + message_id: message.id, + file_id: Uuid::parse_str(file_id)?, + created_at: Utc::now(), + updated_at: Utc::now(), + deleted_at: None, + }; - diesel::insert_into(messages_to_files::table) - .values(&message_to_file) - .execute(conn) - .await?; - } + diesel::insert_into(messages_to_files::table) + .values(&message_to_file) + .execute(conn) + .await?; } } } - _ => (), - }, + } _ => (), - } + } } } Ok(()) @@ -730,7 +731,7 @@ pub async fn transform_message( AgentMessage::Assistant { id, content, - name, + name: _name, tool_calls, progress, initial, @@ -813,7 +814,7 @@ pub async fn transform_message( && file.message_type == "files" => { // For each completed file, create and send a file response message - for (file_id, file_content) in &file.files { + for (_file_id, file_content) in &file.files { let response_message = BusterChatMessage::File { id: file_content.id.clone(), file_type: file_content.file_type.clone(), @@ -873,7 +874,7 @@ pub async fn transform_message( } } AgentMessage::Tool { - id, + id: _id, content, tool_call_id, name, @@ -900,7 +901,7 @@ pub async fn transform_message( && file.message_type == "files" => { // For each completed file, create and send a file response message - for (file_id, file_content) in &file.files { + for (_file_id, file_content) in &file.files { let response_message = BusterChatMessage::File { id: file_content.id.clone(), file_type: file_content.file_type.clone(), @@ -966,8 +967,8 @@ fn transform_text_message( id: String, content: String, progress: MessageProgress, - chat_id: Uuid, - message_id: Uuid, + _chat_id: Uuid, + _message_id: Uuid, tracker: &ChunkTracker, ) -> Result> { match progress { @@ -1004,8 +1005,8 @@ fn transform_tool_message( id: String, name: String, content: String, - chat_id: Uuid, - message_id: Uuid, + _chat_id: Uuid, + _message_id: Uuid, ) -> Result> { // Use required ID (tool call ID) for all function calls let messages = match name.as_str() { @@ -1354,8 +1355,8 @@ fn transform_assistant_tool_message( tool_calls: Vec, progress: MessageProgress, initial: bool, - chat_id: Uuid, - message_id: Uuid, + _chat_id: Uuid, + _message_id: Uuid, tracker: &ChunkTracker, ) -> Result> { let mut all_messages = Vec::new(); @@ -1405,8 +1406,10 @@ fn transform_assistant_tool_message( let containers: Vec = messages .into_iter() - .map(|reasoning| { - let updated_reasoning = match reasoning { + .filter_map(|reasoning| { + + + match reasoning { BusterReasoningMessage::Text(mut text) => { match progress { MessageProgress::Complete => { @@ -1503,11 +1506,8 @@ fn transform_assistant_tool_message( pill.status = "loading".to_string(); Some(BusterReasoningMessage::Pill(pill)) } - }; - - updated_reasoning + } }) - .filter_map(|container| container) .collect(); all_messages.extend(containers); @@ -1815,8 +1815,8 @@ pub async fn generate_conversation_title( }; let title = BusterGeneratingTitle { - chat_id: session_id.clone(), - message_id: message_id.clone(), + chat_id: *session_id, + message_id: *message_id, title: Some(content.clone().replace("\n", "")), title_chunk: None, progress: BusterGeneratingTitleProgress::Completed, @@ -1849,7 +1849,7 @@ async fn initialize_chat( message_id, ChatUserMessage { request: request.prompt.clone(), - sender_id: user.id.clone(), + sender_id: user.id, sender_name: user.name.clone().unwrap_or_default(), sender_avatar: None, }, @@ -1870,11 +1870,11 @@ async fn initialize_chat( id: chat_id, title: request.prompt.clone(), organization_id: user_org_id, - created_by: user.id.clone(), + created_by: user.id, created_at: Utc::now(), updated_at: Utc::now(), deleted_at: None, - updated_by: user.id.clone(), + updated_by: user.id, publicly_accessible: false, publicly_enabled_by: None, public_expiry_date: None, @@ -1885,7 +1885,7 @@ async fn initialize_chat( message_id, ChatUserMessage { request: request.prompt.clone(), - sender_id: user.id.clone(), + sender_id: user.id, sender_name: user.name.clone().unwrap_or_default(), sender_avatar: None, },