renamed ws threads to chats

This commit is contained in:
dal 2025-04-04 16:02:22 -06:00
parent 9c514e0f7a
commit b2bc117694
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
7 changed files with 23 additions and 23 deletions

View File

@ -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<SubscriptionRwLock>,
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<Self> {
match path {
"/chats/post" => Ok(Self::Post),

View File

@ -0,0 +1,2 @@
mod post_chat;
pub mod chats_router;

View File

@ -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),

View File

@ -1,4 +1,4 @@
mod threads_and_messages;
mod chats;
pub mod ws;
pub mod ws_router;
pub mod ws_utils;

View File

@ -1,2 +0,0 @@
mod post_thread;
pub mod threads_router;

View File

@ -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)]

View File

@ -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
}
};