no double complete

This commit is contained in:
dal 2025-04-19 21:22:00 -06:00
parent ed87bae98f
commit 02e9bd0fb5
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
1 changed files with 4 additions and 12 deletions

View File

@ -1,4 +1,3 @@
use anyhow::Result;
use handlers::chats::post_chat_handler::ChatCreateNewChat;
use handlers::chats::post_chat_handler::{self, ThreadEvent};
@ -104,17 +103,10 @@ pub async fn post_thread(
// Call shared handler with channel for streaming messages
match post_chat_handler::post_chat_handler(request, user.clone(), Some(tx)).await {
Ok(chat_with_messages) => {
// For prompt-less flows, the handler might already be done, so explicitly send the completed event
// This ensures the client knows the process is complete
let response = WsResponseMessage::new_no_user(
WsRoutes::Chats(ChatsRoute::Post),
WsEvent::Threads(WSThreadEvent::Complete),
&post_chat_handler::BusterContainer::Chat(chat_with_messages),
None,
WsSendMethod::All,
);
send_ws_message(&user.id.to_string(), &response).await?;
// The spawned task above already handles forwarding the 'Complete' event
// received from the handler. Sending it again here is redundant.
// The final chat state is implicitly sent when the handler sends
// its BusterContainer::Chat with the Completed event.
Ok(())
}
Err(e) => {