From b2bc11769478fda0fe5b26742da62b34c5219d2b Mon Sep 17 00:00:00 2001 From: dal Date: Fri, 4 Apr 2025 16:02:22 -0600 Subject: [PATCH] renamed ws threads to chats --- .../threads_router.rs => chats/chats_router.rs} | 14 +++++++------- api/server/src/routes/ws/chats/mod.rs | 2 ++ .../post_thread.rs => chats/post_chat.rs} | 12 ++++++------ api/server/src/routes/ws/mod.rs | 2 +- .../src/routes/ws/threads_and_messages/mod.rs | 2 -- api/server/src/routes/ws/ws.rs | 4 ++-- api/server/src/routes/ws/ws_router.rs | 10 +++++----- 7 files changed, 23 insertions(+), 23 deletions(-) rename api/server/src/routes/ws/{threads_and_messages/threads_router.rs => chats/chats_router.rs} (89%) create mode 100644 api/server/src/routes/ws/chats/mod.rs rename api/server/src/routes/ws/{threads_and_messages/post_thread.rs => chats/post_chat.rs} (92%) delete mode 100644 api/server/src/routes/ws/threads_and_messages/mod.rs diff --git a/api/server/src/routes/ws/threads_and_messages/threads_router.rs b/api/server/src/routes/ws/chats/chats_router.rs similarity index 89% rename from api/server/src/routes/ws/threads_and_messages/threads_router.rs rename to api/server/src/routes/ws/chats/chats_router.rs index c2083b431..a774586dd 100644 --- a/api/server/src/routes/ws/threads_and_messages/threads_router.rs +++ b/api/server/src/routes/ws/chats/chats_router.rs @@ -8,17 +8,17 @@ use middleware::AuthenticatedUser; use crate::routes::ws::ws::SubscriptionRwLock; -use super::post_thread::post_thread; +use super::post_chat::post_thread; #[derive(Deserialize, Serialize, Debug, Clone)] -pub enum ThreadRoute { +pub enum ChatsRoute { #[serde(rename = "/chats/post")] Post, } #[derive(Deserialize, Serialize, Debug, Clone)] #[serde(rename_all = "camelCase")] -pub enum ThreadEvent { +pub enum ChatEvent { Thought, InitializeThread, ModifyVisualization, @@ -56,15 +56,15 @@ pub enum ThreadEvent { GetChat, } -pub async fn threads_router( - route: ThreadRoute, +pub async fn chats_router( + route: ChatsRoute, data: Value, subscriptions: &Arc, user_group: &String, user: &AuthenticatedUser, ) -> Result<()> { match route { - ThreadRoute::Post => { + ChatsRoute::Post => { let req = serde_json::from_value(data)?; post_thread(user, req).await?; @@ -74,7 +74,7 @@ pub async fn threads_router( Ok(()) } -impl ThreadRoute { +impl ChatsRoute { pub fn from_str(path: &str) -> Result { match path { "/chats/post" => Ok(Self::Post), diff --git a/api/server/src/routes/ws/chats/mod.rs b/api/server/src/routes/ws/chats/mod.rs new file mode 100644 index 000000000..94a1fe334 --- /dev/null +++ b/api/server/src/routes/ws/chats/mod.rs @@ -0,0 +1,2 @@ +mod post_chat; +pub mod chats_router; diff --git a/api/server/src/routes/ws/threads_and_messages/post_thread.rs b/api/server/src/routes/ws/chats/post_chat.rs similarity index 92% rename from api/server/src/routes/ws/threads_and_messages/post_thread.rs rename to api/server/src/routes/ws/chats/post_chat.rs index 513e0a61f..a6941f064 100644 --- a/api/server/src/routes/ws/threads_and_messages/post_thread.rs +++ b/api/server/src/routes/ws/chats/post_chat.rs @@ -6,7 +6,7 @@ use middleware::AuthenticatedUser; use tokio::sync::mpsc; use crate::routes::ws::{ - threads_and_messages::threads_router::{ThreadEvent as WSThreadEvent, ThreadRoute}, + chats::chats_router::{ChatEvent as WSThreadEvent, ChatsRoute}, ws::{WsEvent, WsResponseMessage, WsSendMethod, WsErrorCode}, ws_router::WsRoutes, ws_utils::{send_ws_message, send_error_message}, @@ -28,7 +28,7 @@ pub async fn post_thread( if request.asset_id.is_some() && request.asset_type.is_none() { return send_error_message( &user.id.to_string(), - WsRoutes::Threads(ThreadRoute::Post), + WsRoutes::Chats(ChatsRoute::Post), WsEvent::Threads(WSThreadEvent::PostThread), WsErrorCode::BadRequest, "asset_type must be provided when asset_id is specified".to_string(), @@ -66,7 +66,7 @@ pub async fn post_thread( }; let response = WsResponseMessage::new_no_user( - WsRoutes::Threads(ThreadRoute::Post), + WsRoutes::Chats(ChatsRoute::Post), event, &container, None, @@ -84,7 +84,7 @@ pub async fn post_thread( // Send error message to client if let Err(e) = send_error_message( &user_id, - WsRoutes::Threads(ThreadRoute::Post), + WsRoutes::Chats(ChatsRoute::Post), WsEvent::Threads(WSThreadEvent::PostThread), WsErrorCode::InternalServerError, format!("Error processing thread: {}", err), @@ -107,7 +107,7 @@ pub async fn post_thread( // 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::Threads(ThreadRoute::Post), + WsRoutes::Chats(ChatsRoute::Post), WsEvent::Threads(WSThreadEvent::Complete), &post_chat_handler::BusterContainer::Chat(chat_with_messages), None, @@ -120,7 +120,7 @@ pub async fn post_thread( Err(e) => { send_error_message( &user.id.to_string(), - WsRoutes::Threads(ThreadRoute::Post), + WsRoutes::Chats(ChatsRoute::Post), WsEvent::Threads(WSThreadEvent::PostThread), WsErrorCode::InternalServerError, format!("Error creating thread: {}", e), diff --git a/api/server/src/routes/ws/mod.rs b/api/server/src/routes/ws/mod.rs index d1978adf9..0064592e2 100644 --- a/api/server/src/routes/ws/mod.rs +++ b/api/server/src/routes/ws/mod.rs @@ -1,4 +1,4 @@ -mod threads_and_messages; +mod chats; pub mod ws; pub mod ws_router; pub mod ws_utils; diff --git a/api/server/src/routes/ws/threads_and_messages/mod.rs b/api/server/src/routes/ws/threads_and_messages/mod.rs deleted file mode 100644 index e5e631e40..000000000 --- a/api/server/src/routes/ws/threads_and_messages/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod post_thread; -pub mod threads_router; diff --git a/api/server/src/routes/ws/ws.rs b/api/server/src/routes/ws/ws.rs index 665c6665f..99128f3d8 100644 --- a/api/server/src/routes/ws/ws.rs +++ b/api/server/src/routes/ws/ws.rs @@ -33,7 +33,7 @@ use uuid::Uuid; use middleware::AuthenticatedUser; use super::{ - threads_and_messages::threads_router::ThreadEvent, + chats::chats_router::ChatEvent, ws_router::{ws_router, WsRoutes}, ws_utils::{subscribe_to_stream, unsubscribe_from_stream}, }; @@ -51,7 +51,7 @@ pub struct WsRequestMessage { #[derive(Serialize, Deserialize, Clone)] #[serde(untagged)] pub enum WsEvent { - Threads(ThreadEvent), + Threads(ChatEvent), } #[derive(Serialize, Deserialize, Clone)] diff --git a/api/server/src/routes/ws/ws_router.rs b/api/server/src/routes/ws/ws_router.rs index 7a0c9cf67..daeae76ec 100644 --- a/api/server/src/routes/ws/ws_router.rs +++ b/api/server/src/routes/ws/ws_router.rs @@ -7,14 +7,14 @@ use serde_json::Value; use middleware::AuthenticatedUser; use super::{ - threads_and_messages::threads_router::{threads_router, ThreadRoute}, + chats::chats_router::{chats_router, ChatsRoute}, ws::SubscriptionRwLock, }; #[derive(Deserialize, Serialize, Debug, Clone)] #[serde(untagged)] pub enum WsRoutes { - Threads(ThreadRoute), + Chats(ChatsRoute), } impl WsRoutes { @@ -25,7 +25,7 @@ impl WsRoutes { .ok_or_else(|| anyhow!("Invalid path"))?; match first_segment { - "chats" => Ok(Self::Threads(ThreadRoute::from_str(path)?)), + "chats" => Ok(Self::Chats(ChatsRoute::from_str(path)?)), _ => Err(anyhow!("Invalid path")), } } @@ -46,8 +46,8 @@ pub async fn ws_router( }; let result = match parsed_route { - WsRoutes::Threads(threads_route) => { - threads_router(threads_route, payload, subscriptions, user_group, user).await + WsRoutes::Chats(threads_route) => { + chats_router(threads_route, payload, subscriptions, user_group, user).await } };