mirror of https://github.com/buster-so/buster.git
Fix unused variables and redundant local bindings in post_chat_handler.rs
This commit is contained in:
parent
0104406ed7
commit
39385acf9d
|
@ -71,6 +71,12 @@ struct ChunkState {
|
||||||
last_seen_content: String,
|
last_seen_content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ChunkTracker {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ChunkTracker {
|
impl ChunkTracker {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -141,7 +147,7 @@ pub async fn post_chat_handler(
|
||||||
validate_context_request(request.chat_id, request.metric_id, request.dashboard_id)?;
|
validate_context_request(request.chat_id, request.metric_id, request.dashboard_id)?;
|
||||||
|
|
||||||
let user_org_id = match user.attributes.get("organization_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");
|
tracing::error!("User has no organization ID");
|
||||||
return Err(anyhow!("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 title_handle = {
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
let chat_id = chat_id.clone();
|
let user_id = user.id;
|
||||||
let message_id = message_id.clone();
|
|
||||||
let user_id = user.id.clone();
|
|
||||||
let chat_messages = chat.messages.clone();
|
let chat_messages = chat.messages.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
generate_conversation_title(&chat_messages, &message_id, &user_id, &chat_id, tx).await
|
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,
|
message_id,
|
||||||
ChatUserMessage {
|
ChatUserMessage {
|
||||||
request: request.prompt.clone(),
|
request: request.prompt.clone(),
|
||||||
sender_id: user.id.clone(),
|
sender_id: user.id,
|
||||||
sender_name: user.name.clone().unwrap_or_default(),
|
sender_name: user.name.clone().unwrap_or_default(),
|
||||||
sender_avatar: None,
|
sender_avatar: None,
|
||||||
},
|
},
|
||||||
|
@ -360,7 +364,7 @@ pub async fn post_chat_handler(
|
||||||
id: message_id,
|
id: message_id,
|
||||||
request_message: request.prompt,
|
request_message: request.prompt,
|
||||||
chat_id,
|
chat_id,
|
||||||
created_by: user.id.clone(),
|
created_by: user.id,
|
||||||
created_at: Utc::now(),
|
created_at: Utc::now(),
|
||||||
updated_at: Utc::now(),
|
updated_at: Utc::now(),
|
||||||
deleted_at: None,
|
deleted_at: None,
|
||||||
|
@ -383,7 +387,7 @@ pub async fn post_chat_handler(
|
||||||
// First process completed files (database updates only)
|
// First process completed files (database updates only)
|
||||||
// Use a separate connection scope to ensure prompt release
|
// Use a separate connection scope to ensure prompt release
|
||||||
{
|
{
|
||||||
let _ = process_completed_files(
|
process_completed_files(
|
||||||
&mut conn,
|
&mut conn,
|
||||||
&db_message,
|
&db_message,
|
||||||
&all_messages,
|
&all_messages,
|
||||||
|
@ -531,40 +535,37 @@ async fn process_completed_files(
|
||||||
|
|
||||||
// Process files for database updates only
|
// Process files for database updates only
|
||||||
for (container, _) in transformed_messages {
|
for (container, _) in transformed_messages {
|
||||||
match container {
|
if let BusterContainer::ReasoningMessage(msg) = container { match &msg.reasoning {
|
||||||
BusterContainer::ReasoningMessage(msg) => match &msg.reasoning {
|
BusterReasoningMessage::File(file) if file.message_type == "files" => {
|
||||||
BusterReasoningMessage::File(file) if file.message_type == "files" => {
|
for file_id in &file.file_ids {
|
||||||
for file_id in &file.file_ids {
|
// Skip if we've already processed this file ID
|
||||||
// Skip if we've already processed this file ID
|
if !processed_file_ids.insert(file_id.clone()) {
|
||||||
if !processed_file_ids.insert(file_id.clone()) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(_file_content) = file.files.get(file_id) {
|
if let Some(_file_content) = file.files.get(file_id) {
|
||||||
// Only process files that have completed reasoning
|
// Only process files that have completed reasoning
|
||||||
if file.status == "completed" {
|
if file.status == "completed" {
|
||||||
// Create message-to-file association
|
// Create message-to-file association
|
||||||
let message_to_file = MessageToFile {
|
let message_to_file = MessageToFile {
|
||||||
id: Uuid::new_v4(),
|
id: Uuid::new_v4(),
|
||||||
message_id: message.id,
|
message_id: message.id,
|
||||||
file_id: Uuid::parse_str(&file_id)?,
|
file_id: Uuid::parse_str(file_id)?,
|
||||||
created_at: Utc::now(),
|
created_at: Utc::now(),
|
||||||
updated_at: Utc::now(),
|
updated_at: Utc::now(),
|
||||||
deleted_at: None,
|
deleted_at: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
diesel::insert_into(messages_to_files::table)
|
diesel::insert_into(messages_to_files::table)
|
||||||
.values(&message_to_file)
|
.values(&message_to_file)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
}
|
||||||
},
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
} }
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -730,7 +731,7 @@ pub async fn transform_message(
|
||||||
AgentMessage::Assistant {
|
AgentMessage::Assistant {
|
||||||
id,
|
id,
|
||||||
content,
|
content,
|
||||||
name,
|
name: _name,
|
||||||
tool_calls,
|
tool_calls,
|
||||||
progress,
|
progress,
|
||||||
initial,
|
initial,
|
||||||
|
@ -813,7 +814,7 @@ pub async fn transform_message(
|
||||||
&& file.message_type == "files" =>
|
&& file.message_type == "files" =>
|
||||||
{
|
{
|
||||||
// For each completed file, create and send a file response message
|
// 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 {
|
let response_message = BusterChatMessage::File {
|
||||||
id: file_content.id.clone(),
|
id: file_content.id.clone(),
|
||||||
file_type: file_content.file_type.clone(),
|
file_type: file_content.file_type.clone(),
|
||||||
|
@ -873,7 +874,7 @@ pub async fn transform_message(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AgentMessage::Tool {
|
AgentMessage::Tool {
|
||||||
id,
|
id: _id,
|
||||||
content,
|
content,
|
||||||
tool_call_id,
|
tool_call_id,
|
||||||
name,
|
name,
|
||||||
|
@ -900,7 +901,7 @@ pub async fn transform_message(
|
||||||
&& file.message_type == "files" =>
|
&& file.message_type == "files" =>
|
||||||
{
|
{
|
||||||
// For each completed file, create and send a file response message
|
// 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 {
|
let response_message = BusterChatMessage::File {
|
||||||
id: file_content.id.clone(),
|
id: file_content.id.clone(),
|
||||||
file_type: file_content.file_type.clone(),
|
file_type: file_content.file_type.clone(),
|
||||||
|
@ -966,8 +967,8 @@ fn transform_text_message(
|
||||||
id: String,
|
id: String,
|
||||||
content: String,
|
content: String,
|
||||||
progress: MessageProgress,
|
progress: MessageProgress,
|
||||||
chat_id: Uuid,
|
_chat_id: Uuid,
|
||||||
message_id: Uuid,
|
_message_id: Uuid,
|
||||||
tracker: &ChunkTracker,
|
tracker: &ChunkTracker,
|
||||||
) -> Result<Vec<BusterChatMessage>> {
|
) -> Result<Vec<BusterChatMessage>> {
|
||||||
match progress {
|
match progress {
|
||||||
|
@ -1004,8 +1005,8 @@ fn transform_tool_message(
|
||||||
id: String,
|
id: String,
|
||||||
name: String,
|
name: String,
|
||||||
content: String,
|
content: String,
|
||||||
chat_id: Uuid,
|
_chat_id: Uuid,
|
||||||
message_id: Uuid,
|
_message_id: Uuid,
|
||||||
) -> Result<Vec<BusterReasoningMessage>> {
|
) -> Result<Vec<BusterReasoningMessage>> {
|
||||||
// Use required ID (tool call ID) for all function calls
|
// Use required ID (tool call ID) for all function calls
|
||||||
let messages = match name.as_str() {
|
let messages = match name.as_str() {
|
||||||
|
@ -1354,8 +1355,8 @@ fn transform_assistant_tool_message(
|
||||||
tool_calls: Vec<ToolCall>,
|
tool_calls: Vec<ToolCall>,
|
||||||
progress: MessageProgress,
|
progress: MessageProgress,
|
||||||
initial: bool,
|
initial: bool,
|
||||||
chat_id: Uuid,
|
_chat_id: Uuid,
|
||||||
message_id: Uuid,
|
_message_id: Uuid,
|
||||||
tracker: &ChunkTracker,
|
tracker: &ChunkTracker,
|
||||||
) -> Result<Vec<BusterReasoningMessage>> {
|
) -> Result<Vec<BusterReasoningMessage>> {
|
||||||
let mut all_messages = Vec::new();
|
let mut all_messages = Vec::new();
|
||||||
|
@ -1405,8 +1406,10 @@ fn transform_assistant_tool_message(
|
||||||
|
|
||||||
let containers: Vec<BusterReasoningMessage> = messages
|
let containers: Vec<BusterReasoningMessage> = messages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|reasoning| {
|
.filter_map(|reasoning| {
|
||||||
let updated_reasoning = match reasoning {
|
|
||||||
|
|
||||||
|
match reasoning {
|
||||||
BusterReasoningMessage::Text(mut text) => {
|
BusterReasoningMessage::Text(mut text) => {
|
||||||
match progress {
|
match progress {
|
||||||
MessageProgress::Complete => {
|
MessageProgress::Complete => {
|
||||||
|
@ -1503,11 +1506,8 @@ fn transform_assistant_tool_message(
|
||||||
pill.status = "loading".to_string();
|
pill.status = "loading".to_string();
|
||||||
Some(BusterReasoningMessage::Pill(pill))
|
Some(BusterReasoningMessage::Pill(pill))
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
updated_reasoning
|
|
||||||
})
|
})
|
||||||
.filter_map(|container| container)
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
all_messages.extend(containers);
|
all_messages.extend(containers);
|
||||||
|
@ -1815,8 +1815,8 @@ pub async fn generate_conversation_title(
|
||||||
};
|
};
|
||||||
|
|
||||||
let title = BusterGeneratingTitle {
|
let title = BusterGeneratingTitle {
|
||||||
chat_id: session_id.clone(),
|
chat_id: *session_id,
|
||||||
message_id: message_id.clone(),
|
message_id: *message_id,
|
||||||
title: Some(content.clone().replace("\n", "")),
|
title: Some(content.clone().replace("\n", "")),
|
||||||
title_chunk: None,
|
title_chunk: None,
|
||||||
progress: BusterGeneratingTitleProgress::Completed,
|
progress: BusterGeneratingTitleProgress::Completed,
|
||||||
|
@ -1849,7 +1849,7 @@ async fn initialize_chat(
|
||||||
message_id,
|
message_id,
|
||||||
ChatUserMessage {
|
ChatUserMessage {
|
||||||
request: request.prompt.clone(),
|
request: request.prompt.clone(),
|
||||||
sender_id: user.id.clone(),
|
sender_id: user.id,
|
||||||
sender_name: user.name.clone().unwrap_or_default(),
|
sender_name: user.name.clone().unwrap_or_default(),
|
||||||
sender_avatar: None,
|
sender_avatar: None,
|
||||||
},
|
},
|
||||||
|
@ -1870,11 +1870,11 @@ async fn initialize_chat(
|
||||||
id: chat_id,
|
id: chat_id,
|
||||||
title: request.prompt.clone(),
|
title: request.prompt.clone(),
|
||||||
organization_id: user_org_id,
|
organization_id: user_org_id,
|
||||||
created_by: user.id.clone(),
|
created_by: user.id,
|
||||||
created_at: Utc::now(),
|
created_at: Utc::now(),
|
||||||
updated_at: Utc::now(),
|
updated_at: Utc::now(),
|
||||||
deleted_at: None,
|
deleted_at: None,
|
||||||
updated_by: user.id.clone(),
|
updated_by: user.id,
|
||||||
publicly_accessible: false,
|
publicly_accessible: false,
|
||||||
publicly_enabled_by: None,
|
publicly_enabled_by: None,
|
||||||
public_expiry_date: None,
|
public_expiry_date: None,
|
||||||
|
@ -1885,7 +1885,7 @@ async fn initialize_chat(
|
||||||
message_id,
|
message_id,
|
||||||
ChatUserMessage {
|
ChatUserMessage {
|
||||||
request: request.prompt.clone(),
|
request: request.prompt.clone(),
|
||||||
sender_id: user.id.clone(),
|
sender_id: user.id,
|
||||||
sender_name: user.name.clone().unwrap_or_default(),
|
sender_name: user.name.clone().unwrap_or_default(),
|
||||||
sender_avatar: None,
|
sender_avatar: None,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue