handler format looking good

This commit is contained in:
dal 2025-02-14 15:01:38 -07:00
parent 02978e37e8
commit 1765b20917
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
8 changed files with 39 additions and 90 deletions

View File

@ -0,0 +1,2 @@
pub mod types;
pub mod helpers;

View File

@ -0,0 +1,19 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize)]
pub struct ThreadMessage {
pub id: Uuid,
pub request_message: ThreadUserMessage,
pub response_messages: Vec<String>,
pub reasoning: Vec<String>,
pub created_at: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ThreadUserMessage {
pub request: String,
pub sender_id: Uuid,
pub sender_name: String,
pub sender_avatar: Option<String>,
}

View File

@ -1,5 +1,2 @@
pub mod operations;
pub mod types;
// Re-export commonly used items
pub use types::{ThreadRequest, ThreadResponse};
pub mod helpers;

View File

@ -1,37 +0,0 @@
use anyhow::Result;
use uuid::Uuid;
use crate::threads::types::{ThreadRequest, ThreadResponse};
/// Creates a new thread based on the provided request
pub async fn create_thread(request: ThreadRequest) -> Result<ThreadResponse> {
// This is a placeholder implementation
// You'll need to implement the actual database operations
let now = chrono::Utc::now();
Ok(ThreadResponse {
id: Uuid::new_v4(),
title: request.title,
organization_id: request.organization_id,
created_by: request.created_by,
created_at: now,
updated_at: now,
})
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_create_thread() {
let request = ThreadRequest {
title: "Test Thread".to_string(),
organization_id: Uuid::new_v4(),
created_by: Uuid::new_v4(),
};
let result = create_thread(request).await;
assert!(result.is_ok());
}
}

View File

@ -1,22 +1,19 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};
#[derive(Debug, Serialize, Deserialize)]
pub struct ThreadRequest {
pub title: String,
pub organization_id: Uuid,
pub created_by: Uuid,
}
use crate::messages::types::ThreadMessage;
// Add more thread-related types as needed
#[derive(Debug, Serialize, Deserialize)]
pub struct ThreadResponse {
pub struct ThreadWithMessages {
pub id: Uuid,
pub title: String,
pub organization_id: Uuid,
pub created_by: Uuid,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub is_favorited: bool,
pub messages: Vec<ThreadMessage>,
pub created_at: String,
pub updated_at: String,
pub created_by: String,
pub created_by_id: String,
pub created_by_name: String,
pub created_by_avatar: Option<String>,
}
// Add more thread-related types as needed

View File

@ -1,7 +1,9 @@
use anyhow::{Error, Result};
use chrono::Utc;
use diesel::{insert_into, ExpressionMethods, QueryDsl};
use diesel_async::{AsyncConnection, RunQueryDsl};
use diesel_async::{RunQueryDsl};
use handlers::messages::types::{ThreadMessage, ThreadUserMessage};
use handlers::threads::types::ThreadWithMessages;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
@ -43,37 +45,6 @@ use crate::{
use super::agent_message_transformer::transform_message;
use litellm::Message as AgentMessage;
#[derive(Debug, Serialize, Deserialize)]
pub struct TempInitChat {
pub id: Uuid,
pub title: String,
pub is_favorited: bool,
pub messages: Vec<TempInitChatMessage>,
pub created_at: String,
pub updated_at: String,
pub created_by: String,
pub created_by_id: String,
pub created_by_name: String,
pub created_by_avatar: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TempInitChatMessage {
pub id: Uuid,
pub request_message: TempRequestMessage,
pub response_messages: Vec<String>,
pub reasoning: Vec<String>,
pub created_at: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TempRequestMessage {
pub request: String,
pub sender_id: Uuid,
pub sender_name: String,
pub sender_avatar: Option<String>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct ChatCreateNewChat {
pub prompt: String,
@ -155,13 +126,13 @@ impl AgentThreadHandler {
deleted_at: None,
};
let init_response = TempInitChat {
let init_response = ThreadWithMessages {
id: chat_id.clone(),
title: request.prompt.clone(),
is_favorited: false,
messages: vec![TempInitChatMessage {
messages: vec![ThreadMessage {
id: message_id.clone(),
request_message: TempRequestMessage {
request_message: ThreadUserMessage {
request: request.prompt.clone(),
sender_id: user.id,
sender_name: user.name.clone().unwrap_or_default(),