Skip to main content

MemorySessionStore

Struct MemorySessionStore 

Source
pub struct MemorySessionStore { /* private fields */ }
Expand description

In-memory session store for testing, development, and prototyping.

Sessions are stored in HashMap<Uuid, Session> and messages in HashMap<Uuid, Vec<MessageRecord>>, both protected by RwLock. A reverse index message_id → session_id enables O(1) message lookups in update_usage. Data is lost when the process exits. Implements SessionStore.

Implementations§

Source§

impl MemorySessionStore

Source

pub fn new() -> Self

Creates an empty in-memory session store.

Trait Implementations§

Source§

impl Default for MemorySessionStore

Source§

fn default() -> MemorySessionStore

Returns the “default value” for a type. Read more
Source§

impl SessionStore for MemorySessionStore

Source§

fn create_session<'life0, 'async_trait>( &'life0 self, session: Session, ) -> Pin<Box<dyn Future<Output = StoreResult<Session>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Persists a new session and returns it with server-assigned fields.
Source§

fn list_sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = StoreResult<Vec<Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns all sessions ordered by most recently updated (descending).
Source§

fn get_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 Uuid, ) -> Pin<Box<dyn Future<Output = StoreResult<Option<Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns a session by identifier, or None if not found.
Source§

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 Uuid, ) -> Pin<Box<dyn Future<Output = StoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deletes a session and all related data (cascading delete). Read more
Source§

fn update_session<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, id: &'life1 Uuid, title: &'life2 str, model: Option<&'life3 ModelName>, ) -> Pin<Box<dyn Future<Output = StoreResult<Session>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Updates a session’s title and/or model. Read more
Source§

fn append_message<'life0, 'async_trait>( &'life0 self, message: MessageRecord, ) -> Pin<Box<dyn Future<Output = StoreResult<MessageRecord>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Appends a message to a session’s history.
Source§

fn list_messages<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 Uuid, ) -> Pin<Box<dyn Future<Output = StoreResult<Vec<MessageRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns all messages for a session ordered by creation time.
Source§

fn update_usage<'life0, 'life1, 'async_trait>( &'life0 self, message_id: &'life1 Uuid, usage: TokenUsage, ) -> Pin<Box<dyn Future<Output = StoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Updates token usage on an existing message record.
Source§

fn list_sessions_paginated<'life0, 'async_trait>( &'life0 self, pagination: Pagination, filter: SessionFilter, ) -> Pin<Box<dyn Future<Output = StoreResult<Vec<Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns sessions matching the filter, paginated. Read more
Source§

fn list_messages_paginated<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 Uuid, pagination: Pagination, ) -> Pin<Box<dyn Future<Output = StoreResult<Vec<MessageRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns messages for a session, paginated. Read more
Source§

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = StoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Checks connectivity to the backend. Read more
Source§

fn get_latest_compaction<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 Uuid, ) -> Pin<Box<dyn Future<Output = StoreResult<Option<MessageRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns the most recent compaction user message for a session. Read more
Source§

fn mark_compacted<'life0, 'life1, 'async_trait>( &'life0 self, _message_id: &'life1 Uuid, ) -> Pin<Box<dyn Future<Output = StoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Marks a message as compacted, setting its is_summary flag. Read more

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.