add in initialize

This commit is contained in:
dal 2025-03-03 16:43:44 -07:00
parent d44e2f2946
commit 8232f628ea
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
5 changed files with 22 additions and 8 deletions

View File

@ -36,6 +36,7 @@ pub enum ThreadEvent {
GeneratingResponseMessage, GeneratingResponseMessage,
GeneratingReasoningMessage, GeneratingReasoningMessage,
GeneratingTitle, GeneratingTitle,
InitializeChat,
} }
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
@ -101,6 +102,15 @@ pub async fn post_chat_handler(
created_by_avatar: None, created_by_avatar: None,
}; };
// Send initial chat state to client
if let Some(tx) = tx.clone() {
tx.send(Ok((
BusterContainer::Chat(chat_with_messages.clone()),
ThreadEvent::InitializeChat,
)))
.await?;
}
// Create database connection // Create database connection
let mut conn = get_pg_pool().get().await?; let mut conn = get_pg_pool().get().await?;
@ -439,7 +449,7 @@ pub struct BusterReasoningText {
#[serde(rename = "type")] #[serde(rename = "type")]
pub reasoning_type: String, pub reasoning_type: String,
pub title: String, pub title: String,
pub secondary_title: Option<String>, pub secondary_title: String,
pub message: Option<String>, pub message: Option<String>,
pub message_chunk: Option<String>, pub message_chunk: Option<String>,
pub status: Option<String>, pub status: Option<String>,
@ -491,6 +501,7 @@ pub struct BusterFileMetadata {
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]
#[serde(untagged)] #[serde(untagged)]
pub enum BusterContainer { pub enum BusterContainer {
Chat(ChatWithMessages),
ChatMessage(BusterChatMessageContainer), ChatMessage(BusterChatMessageContainer),
ReasoningMessage(BusterReasoningMessageContainer), ReasoningMessage(BusterReasoningMessageContainer),
GeneratingTitle(BusterGeneratingTitle), GeneratingTitle(BusterGeneratingTitle),
@ -1170,7 +1181,7 @@ fn assistant_create_plan(
id: text.id, id: text.id,
thought_type: "thought".to_string(), thought_type: "thought".to_string(),
title: text.title, title: text.title,
secondary_title: text.secondary_title.unwrap_or_default(), secondary_title: text.secondary_title,
pill_containers: Some(vec![plan_container]), pill_containers: Some(vec![plan_container]),
status: status.to_string(), status: status.to_string(),
})]) })])

View File

@ -50,7 +50,7 @@ impl StreamingParser {
id, id,
reasoning_type: "text".to_string(), reasoning_type: "text".to_string(),
title: "Creating a plan...".to_string(), title: "Creating a plan...".to_string(),
secondary_title: None, secondary_title: String::from(""),
message: None, message: None,
message_chunk: Some(plan_markdown.to_string()), message_chunk: Some(plan_markdown.to_string()),
status: Some("loading".to_string()), status: Some("loading".to_string()),
@ -85,7 +85,7 @@ impl StreamingParser {
id, id,
reasoning_type: "text".to_string(), reasoning_type: "text".to_string(),
title: "Searching your data catalog...".to_string(), title: "Searching your data catalog...".to_string(),
secondary_title: None, secondary_title: String::from(""),
message: None, message: None,
message_chunk: Some(search_requirements.to_string()), message_chunk: Some(search_requirements.to_string()),
status: Some("loading".to_string()), status: Some("loading".to_string()),

View File

@ -3,7 +3,7 @@ use uuid::Uuid;
use crate::messages::types::ChatMessage; use crate::messages::types::ChatMessage;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ChatWithMessages { pub struct ChatWithMessages {
pub id: Uuid, pub id: Uuid,
pub title: String, pub title: String,

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use uuid::Uuid; use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ChatMessage { pub struct ChatMessage {
pub id: Uuid, pub id: Uuid,
pub request_message: ChatUserMessage, pub request_message: ChatUserMessage,
@ -11,10 +11,10 @@ pub struct ChatMessage {
pub created_at: String, pub created_at: String,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ChatUserMessage { pub struct ChatUserMessage {
pub request: String, pub request: String,
pub sender_id: Uuid, pub sender_id: Uuid,
pub sender_name: String, pub sender_name: String,
pub sender_avatar: Option<String>, pub sender_avatar: Option<String>,
} }

View File

@ -43,6 +43,9 @@ pub async fn post_thread(
ThreadEvent::GeneratingTitle => { ThreadEvent::GeneratingTitle => {
WsEvent::Threads(WSThreadEvent::GeneratingTitle) WsEvent::Threads(WSThreadEvent::GeneratingTitle)
} }
ThreadEvent::InitializeChat => {
WsEvent::Threads(WSThreadEvent::InitializeChat)
}
}; };
let response = WsResponseMessage::new_no_user( let response = WsResponseMessage::new_no_user(