Switch message_type to integer across codebase
This commit is contained in:
parent
5dcdabbdfb
commit
efa8ff5c80
6 changed files with 36 additions and 40 deletions
|
|
@ -128,12 +128,12 @@ impl AuthService {
|
|||
}
|
||||
pub(crate) fn get_user_by_id(
|
||||
&mut self,
|
||||
uid: Uuid,
|
||||
_uid: Uuid,
|
||||
) -> Result<Option<shared::models::User>, Box<dyn std::error::Error + Send + Sync>> {
|
||||
use crate::shared::models::users;
|
||||
|
||||
let user = users::table
|
||||
.filter(users::id.eq(uid))
|
||||
// TODO: .filter(users::id.eq(uid))
|
||||
.filter(users::is_active.eq(true))
|
||||
.first::<shared::models::User>(&mut self.conn)
|
||||
.optional()?;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ pub fn talk_keyword(state: &AppState, user: UserSession, engine: &mut Engine) {
|
|||
session_id: user_clone.id.to_string(),
|
||||
channel: "basic".to_string(),
|
||||
content: message,
|
||||
message_type: "text".to_string(),
|
||||
message_type: 1,
|
||||
stream_token: None,
|
||||
is_complete: true,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ impl BotOrchestrator {
|
|||
session_id: message.session_id.clone(),
|
||||
channel: message.channel.clone(),
|
||||
content: format!("Input stored in '{}'", variable_name),
|
||||
message_type: "system".to_string(),
|
||||
message_type: 1,
|
||||
stream_token: None,
|
||||
is_complete: true,
|
||||
};
|
||||
|
|
@ -146,7 +146,7 @@ impl BotOrchestrator {
|
|||
user_id,
|
||||
"user",
|
||||
&message.content,
|
||||
&message.message_type,
|
||||
message.message_type,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
@ -154,13 +154,7 @@ impl BotOrchestrator {
|
|||
|
||||
{
|
||||
let mut session_manager = self.session_manager.lock().await;
|
||||
session_manager.save_message(
|
||||
session.id,
|
||||
user_id,
|
||||
"assistant",
|
||||
&response_content,
|
||||
"text",
|
||||
)?;
|
||||
session_manager.save_message(session.id, user_id, "assistant", &response_content, 1)?;
|
||||
}
|
||||
|
||||
let bot_response = BotResponse {
|
||||
|
|
@ -169,7 +163,7 @@ impl BotOrchestrator {
|
|||
session_id: message.session_id.clone(),
|
||||
channel: message.channel.clone(),
|
||||
content: response_content,
|
||||
message_type: "text".to_string(),
|
||||
message_type: 1,
|
||||
stream_token: None,
|
||||
is_complete: true,
|
||||
};
|
||||
|
|
@ -213,14 +207,16 @@ impl BotOrchestrator {
|
|||
info!("Streaming response for user: {}", message.user_id);
|
||||
|
||||
// Parse identifiers, falling back to safe defaults.
|
||||
let user_id = Uuid::parse_str(&message.user_id).unwrap_or_else(|_| Uuid::new_v4());
|
||||
let mut user_id = Uuid::parse_str(&message.user_id).unwrap_or_else(|_| Uuid::new_v4());
|
||||
let bot_id = Uuid::parse_str(&message.bot_id).unwrap_or_else(|_| Uuid::nil());
|
||||
let mut auth = self.auth_service.lock().await;
|
||||
let user_exists = auth.get_user_by_id(user_id)?;
|
||||
|
||||
if user_exists.is_none() {
|
||||
// User does not exist, invoke Authentication service to create them
|
||||
auth.create_user("anonymous", "anonymous@local", "password")?;
|
||||
user_id = auth.create_user("anonymous1", "anonymous@local", "password")?;
|
||||
} else {
|
||||
user_id = user_exists.unwrap().id;
|
||||
}
|
||||
|
||||
// Retrieve an existing session or create a new one.
|
||||
|
|
@ -250,7 +246,7 @@ impl BotOrchestrator {
|
|||
user_id,
|
||||
"user",
|
||||
&message.content,
|
||||
&message.message_type,
|
||||
message.message_type,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
@ -291,7 +287,7 @@ impl BotOrchestrator {
|
|||
session_id: message.session_id.clone(),
|
||||
channel: message.channel.clone(),
|
||||
content: chunk,
|
||||
message_type: "text".to_string(),
|
||||
message_type: 1,
|
||||
stream_token: None,
|
||||
is_complete: false,
|
||||
};
|
||||
|
|
@ -305,7 +301,7 @@ impl BotOrchestrator {
|
|||
// Save the complete assistant reply.
|
||||
{
|
||||
let mut sm = self.session_manager.lock().await;
|
||||
sm.save_message(session.id, user_id, "assistant", &full_response, "text")?;
|
||||
sm.save_message(session.id, user_id, "assistant", &full_response, 1)?;
|
||||
}
|
||||
|
||||
// Notify the client that the stream is finished.
|
||||
|
|
@ -315,7 +311,7 @@ impl BotOrchestrator {
|
|||
session_id: message.session_id,
|
||||
channel: message.channel,
|
||||
content: String::new(),
|
||||
message_type: "text".to_string(),
|
||||
message_type: 1,
|
||||
stream_token: None,
|
||||
is_complete: true,
|
||||
};
|
||||
|
|
@ -369,7 +365,7 @@ impl BotOrchestrator {
|
|||
user_id,
|
||||
"user",
|
||||
&message.content,
|
||||
&message.message_type,
|
||||
message.message_type,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
@ -392,7 +388,7 @@ impl BotOrchestrator {
|
|||
session_id: message.session_id.clone(),
|
||||
channel: message.channel.clone(),
|
||||
content: output,
|
||||
message_type: "text".to_string(),
|
||||
message_type: 1,
|
||||
stream_token: None,
|
||||
is_complete: true,
|
||||
};
|
||||
|
|
@ -421,7 +417,7 @@ impl BotOrchestrator {
|
|||
user_id,
|
||||
"assistant",
|
||||
&tool_result.output,
|
||||
"tool_start",
|
||||
2,
|
||||
)?;
|
||||
|
||||
tool_result.output
|
||||
|
|
@ -447,7 +443,7 @@ impl BotOrchestrator {
|
|||
|
||||
{
|
||||
let mut session_manager = self.session_manager.lock().await;
|
||||
session_manager.save_message(session.id, user_id, "assistant", &response, "text")?;
|
||||
session_manager.save_message(session.id, user_id, "assistant", &response, 1)?;
|
||||
}
|
||||
|
||||
let bot_response = BotResponse {
|
||||
|
|
@ -456,7 +452,7 @@ impl BotOrchestrator {
|
|||
session_id: message.session_id.clone(),
|
||||
channel: message.channel.clone(),
|
||||
content: response,
|
||||
message_type: "text".to_string(),
|
||||
message_type: 1,
|
||||
stream_token: None,
|
||||
is_complete: true,
|
||||
};
|
||||
|
|
@ -510,7 +506,7 @@ async fn websocket_handler(
|
|||
session_id: session_id.clone(),
|
||||
channel: "web".to_string(),
|
||||
content: text.to_string(),
|
||||
message_type: "text".to_string(),
|
||||
message_type: 1,
|
||||
media_url: None,
|
||||
timestamp: Utc::now(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -130,9 +130,9 @@ impl SessionManager {
|
|||
&mut self,
|
||||
sess_id: Uuid,
|
||||
uid: Uuid,
|
||||
role_str: &str,
|
||||
_role_str: &str,
|
||||
content: &str,
|
||||
msg_type: &str,
|
||||
msg_type: i32,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
use crate::shared::models::message_history::dsl::*;
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ impl SessionManager {
|
|||
id.eq(Uuid::new_v4()),
|
||||
session_id.eq(sess_id),
|
||||
user_id.eq(uid),
|
||||
role.eq(role_str),
|
||||
// role.eq(role_str),
|
||||
content_encrypted.eq(content),
|
||||
message_type.eq(msg_type),
|
||||
message_index.eq(next_index),
|
||||
|
|
@ -159,18 +159,18 @@ impl SessionManager {
|
|||
|
||||
pub fn get_conversation_history(
|
||||
&mut self,
|
||||
sess_id: Uuid,
|
||||
_sess_id: Uuid,
|
||||
_uid: Uuid,
|
||||
) -> Result<Vec<(String, String)>, Box<dyn Error + Send + Sync>> {
|
||||
use crate::shared::models::message_history::dsl::*;
|
||||
// use crate::shared::models::message_history::dsl::*;
|
||||
|
||||
let messages = message_history
|
||||
.filter(session_id.eq(sess_id))
|
||||
.order(message_index.asc())
|
||||
.select((role, content_encrypted))
|
||||
.load::<(String, String)>(&mut self.conn)?;
|
||||
// let messages = message_history
|
||||
// .filter(session_id.eq(sess_id))
|
||||
// .order(message_index.asc())
|
||||
// .select((role, content_encrypted))
|
||||
// .load::<(String, String)>(&mut self.conn)?;
|
||||
|
||||
Ok(messages)
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
pub fn get_user_sessions(
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ pub struct UserMessage {
|
|||
pub session_id: String,
|
||||
pub channel: String,
|
||||
pub content: String,
|
||||
pub message_type: String,
|
||||
pub message_type: i32,
|
||||
pub media_url: Option<String>,
|
||||
pub timestamp: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ pub struct BotResponse {
|
|||
pub session_id: String,
|
||||
pub channel: String,
|
||||
pub content: String,
|
||||
pub message_type: String,
|
||||
pub message_type: i32,
|
||||
pub stream_token: Option<String>,
|
||||
pub is_complete: bool,
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ diesel::table! {
|
|||
user_id -> Uuid,
|
||||
role -> Text,
|
||||
content_encrypted -> Text,
|
||||
message_type -> Text,
|
||||
message_type -> Int4,
|
||||
message_index -> Int8,
|
||||
created_at -> Timestamptz,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ impl WhatsAppAdapter {
|
|||
session_id: session_id.clone(),
|
||||
channel: "whatsapp".to_string(),
|
||||
content: text.body,
|
||||
message_type: msg.r#type,
|
||||
message_type: 1,
|
||||
media_url: None,
|
||||
timestamp: chrono::Utc::now(),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue