pub struct ChatHistoryService {
repo: Arc<dyn ChatHistoryRepository>,
}Expand description
Service for managing chat history.
This is a thin orchestration layer over the ChatHistoryRepository port.
It provides a clean API and handles any business logic that doesn’t
belong in the repository layer.
Fields§
§repo: Arc<dyn ChatHistoryRepository>Implementations§
Source§impl ChatHistoryService
impl ChatHistoryService
Sourcepub fn new(repo: Arc<dyn ChatHistoryRepository>) -> Self
pub fn new(repo: Arc<dyn ChatHistoryRepository>) -> Self
Create a new chat history service.
Sourcepub async fn create_conversation(
&self,
title: String,
model_id: Option<i64>,
system_prompt: Option<String>,
) -> Result<i64, ChatHistoryError>
pub async fn create_conversation( &self, title: String, model_id: Option<i64>, system_prompt: Option<String>, ) -> Result<i64, ChatHistoryError>
Create a new conversation.
Sourcepub async fn list_conversations(
&self,
) -> Result<Vec<Conversation>, ChatHistoryError>
pub async fn list_conversations( &self, ) -> Result<Vec<Conversation>, ChatHistoryError>
List all conversations, ordered by most recently updated.
Sourcepub async fn get_conversation(
&self,
id: i64,
) -> Result<Option<Conversation>, ChatHistoryError>
pub async fn get_conversation( &self, id: i64, ) -> Result<Option<Conversation>, ChatHistoryError>
Get a specific conversation by ID.
Sourcepub async fn update_conversation(
&self,
id: i64,
new_title: Option<String>,
system_prompt: Option<Option<String>>,
) -> Result<(), ChatHistoryError>
pub async fn update_conversation( &self, id: i64, new_title: Option<String>, system_prompt: Option<Option<String>>, ) -> Result<(), ChatHistoryError>
Update conversation metadata.
Sourcepub async fn delete_conversation(&self, id: i64) -> Result<(), ChatHistoryError>
pub async fn delete_conversation(&self, id: i64) -> Result<(), ChatHistoryError>
Delete a conversation and all its messages.
Sourcepub async fn get_conversation_count(&self) -> Result<i64, ChatHistoryError>
pub async fn get_conversation_count(&self) -> Result<i64, ChatHistoryError>
Get conversation count.
Sourcepub async fn get_messages(
&self,
conversation_id: i64,
) -> Result<Vec<Message>, ChatHistoryError>
pub async fn get_messages( &self, conversation_id: i64, ) -> Result<Vec<Message>, ChatHistoryError>
Get all messages for a conversation.
Sourcepub async fn save_message(
&self,
msg: NewMessage,
) -> Result<i64, ChatHistoryError>
pub async fn save_message( &self, msg: NewMessage, ) -> Result<i64, ChatHistoryError>
Save a new message.
Sourcepub async fn update_message(
&self,
id: i64,
content: String,
metadata: Option<Value>,
) -> Result<(), ChatHistoryError>
pub async fn update_message( &self, id: i64, content: String, metadata: Option<Value>, ) -> Result<(), ChatHistoryError>
Update a message’s content and optionally its metadata.
Sourcepub async fn delete_message_and_subsequent(
&self,
id: i64,
) -> Result<i64, ChatHistoryError>
pub async fn delete_message_and_subsequent( &self, id: i64, ) -> Result<i64, ChatHistoryError>
Delete a message and all subsequent messages.
Sourcepub async fn get_message_count(
&self,
conversation_id: i64,
) -> Result<i64, ChatHistoryError>
pub async fn get_message_count( &self, conversation_id: i64, ) -> Result<i64, ChatHistoryError>
Get message count for a conversation.
Auto Trait Implementations§
impl Freeze for ChatHistoryService
impl !RefUnwindSafe for ChatHistoryService
impl Send for ChatHistoryService
impl Sync for ChatHistoryService
impl Unpin for ChatHistoryService
impl !UnwindSafe for ChatHistoryService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more