ChatHistoryService

Struct ChatHistoryService 

Source
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

Source

pub fn new(repo: Arc<dyn ChatHistoryRepository>) -> Self

Create a new chat history service.

Source

pub async fn create_conversation( &self, title: String, model_id: Option<i64>, system_prompt: Option<String>, ) -> Result<i64, ChatHistoryError>

Create a new conversation.

Source

pub async fn list_conversations( &self, ) -> Result<Vec<Conversation>, ChatHistoryError>

List all conversations, ordered by most recently updated.

Source

pub async fn get_conversation( &self, id: i64, ) -> Result<Option<Conversation>, ChatHistoryError>

Get a specific conversation by ID.

Source

pub async fn update_conversation( &self, id: i64, new_title: Option<String>, system_prompt: Option<Option<String>>, ) -> Result<(), ChatHistoryError>

Update conversation metadata.

Source

pub async fn delete_conversation(&self, id: i64) -> Result<(), ChatHistoryError>

Delete a conversation and all its messages.

Source

pub async fn get_conversation_count(&self) -> Result<i64, ChatHistoryError>

Get conversation count.

Source

pub async fn get_messages( &self, conversation_id: i64, ) -> Result<Vec<Message>, ChatHistoryError>

Get all messages for a conversation.

Source

pub async fn save_message( &self, msg: NewMessage, ) -> Result<i64, ChatHistoryError>

Save a new message.

Source

pub async fn update_message( &self, id: i64, content: String, metadata: Option<Value>, ) -> Result<(), ChatHistoryError>

Update a message’s content and optionally its metadata.

Source

pub async fn delete_message_and_subsequent( &self, id: i64, ) -> Result<i64, ChatHistoryError>

Delete a message and all subsequent messages.

Source

pub async fn get_message_count( &self, conversation_id: i64, ) -> Result<i64, ChatHistoryError>

Get message count for a conversation.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.