Skip to main content

MessageStore

Trait MessageStore 

Source
pub trait MessageStore: Send + Sync {
    // Required methods
    fn append<'life0, 'life1, 'async_trait>(
        &'life0 self,
        thread_id: &'life1 ThreadId,
        message: Message,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_history<'life0, 'life1, 'async_trait>(
        &'life0 self,
        thread_id: &'life1 ThreadId,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn clear<'life0, 'life1, 'async_trait>(
        &'life0 self,
        thread_id: &'life1 ThreadId,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn replace_history<'life0, 'life1, 'async_trait>(
        &'life0 self,
        thread_id: &'life1 ThreadId,
        messages: Vec<Message>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn count<'life0, 'life1, 'async_trait>(
        &'life0 self,
        thread_id: &'life1 ThreadId,
    ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Trait for storing and retrieving conversation messages. Implement this trait to persist messages to your storage backend.

Required Methods§

Source

fn append<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, message: Message, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Append a message to the thread’s history

§Errors

Returns an error if the message cannot be stored.

Source

fn get_history<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get all messages for a thread

§Errors

Returns an error if the history cannot be retrieved.

Source

fn clear<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Clear all messages for a thread

§Errors

Returns an error if the messages cannot be cleared.

Source

fn replace_history<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Replace the entire message history for a thread. Used for context compaction to replace old messages with a summary.

§Errors

Returns an error if the history cannot be replaced.

Provided Methods§

Source

fn count<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get the message count for a thread

§Errors

Returns an error if the count cannot be retrieved.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: MessageStore + ?Sized> MessageStore for Arc<T>

Source§

fn append<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, message: Message, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_history<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn clear<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn count<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn replace_history<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§