pub struct SessionStore { /* private fields */ }Expand description
Append-only JSONL session store for channel conversations.
Implementations§
Source§impl SessionStore
impl SessionStore
Sourcepub fn new(workspace_dir: &Path) -> Result<Self>
pub fn new(workspace_dir: &Path) -> Result<Self>
Create a new session store, ensuring the sessions directory exists.
Sourcepub fn load(&self, session_key: &str) -> Vec<ChatMessage>
pub fn load(&self, session_key: &str) -> Vec<ChatMessage>
Load all messages for a session from its JSONL file. Returns an empty vec if the file does not exist or is unreadable.
Sourcepub fn append(&self, session_key: &str, message: &ChatMessage) -> Result<()>
pub fn append(&self, session_key: &str, message: &ChatMessage) -> Result<()>
Append a single message to the session JSONL file.
Sourcepub fn remove_last(&self, session_key: &str) -> Result<bool>
pub fn remove_last(&self, session_key: &str) -> Result<bool>
Remove the last message from a session’s JSONL file.
Rewrite approach: load all messages, drop the last, rewrite. This is O(n) but rollbacks are rare.
Sourcepub fn compact(&self, session_key: &str) -> Result<()>
pub fn compact(&self, session_key: &str) -> Result<()>
Compact a session file by rewriting only valid messages (removes corrupt lines).
Sourcepub fn delete_session(&self, session_key: &str) -> Result<bool>
pub fn delete_session(&self, session_key: &str) -> Result<bool>
Delete a session’s JSONL file. Returns true if the file existed.
Sourcepub fn list_sessions(&self) -> Vec<String>
pub fn list_sessions(&self) -> Vec<String>
List all session keys that have files on disk.
Trait Implementations§
Source§impl SessionBackend for SessionStore
impl SessionBackend for SessionStore
Source§fn load(&self, session_key: &str) -> Vec<ChatMessage>
fn load(&self, session_key: &str) -> Vec<ChatMessage>
Load all messages for a session. Returns empty vec if session doesn’t exist.
Source§fn append(&self, session_key: &str, message: &ChatMessage) -> Result<()>
fn append(&self, session_key: &str, message: &ChatMessage) -> Result<()>
Append a single message to a session.
Source§fn remove_last(&self, session_key: &str) -> Result<bool>
fn remove_last(&self, session_key: &str) -> Result<bool>
Remove the last message from a session. Returns
true if a message was removed.Source§fn list_sessions(&self) -> Vec<String>
fn list_sessions(&self) -> Vec<String>
List all session keys.
Source§fn compact(&self, session_key: &str) -> Result<()>
fn compact(&self, session_key: &str) -> Result<()>
Compact a session file (remove duplicates/corruption). No-op by default.
Source§fn delete_session(&self, session_key: &str) -> Result<bool>
fn delete_session(&self, session_key: &str) -> Result<bool>
Delete all messages for a session. Returns
true if the session existed.Source§fn list_sessions_with_metadata(&self) -> Vec<SessionMetadata>
fn list_sessions_with_metadata(&self) -> Vec<SessionMetadata>
List sessions with metadata.
Source§fn cleanup_stale(&self, _ttl_hours: u32) -> Result<usize>
fn cleanup_stale(&self, _ttl_hours: u32) -> Result<usize>
Remove sessions that haven’t been active within the given TTL hours.
Source§fn search(&self, _query: &SessionQuery) -> Vec<SessionMetadata>
fn search(&self, _query: &SessionQuery) -> Vec<SessionMetadata>
Search sessions by keyword. Default returns empty (backends with FTS override).
Source§fn set_session_name(&self, _session_key: &str, _name: &str) -> Result<()>
fn set_session_name(&self, _session_key: &str, _name: &str) -> Result<()>
Set or update the human-readable name for a session.
Source§fn get_session_name(&self, _session_key: &str) -> Result<Option<String>>
fn get_session_name(&self, _session_key: &str) -> Result<Option<String>>
Get the human-readable name for a session (if set).
Source§fn set_session_state(
&self,
_session_key: &str,
_state: &str,
_turn_id: Option<&str>,
) -> Result<()>
fn set_session_state( &self, _session_key: &str, _state: &str, _turn_id: Option<&str>, ) -> Result<()>
Set the session state (e.g. “idle”, “running”, “error”).
turn_id identifies the current turn (set when running, cleared on idle).Source§fn get_session_state(&self, _session_key: &str) -> Result<Option<SessionState>>
fn get_session_state(&self, _session_key: &str) -> Result<Option<SessionState>>
Get the current session state. Returns
None if the backend doesn’t track state.Source§fn list_running_sessions(&self) -> Vec<SessionMetadata>
fn list_running_sessions(&self) -> Vec<SessionMetadata>
List sessions currently in “running” state.
Source§fn list_stuck_sessions(&self, _threshold_secs: u64) -> Vec<SessionMetadata>
fn list_stuck_sessions(&self, _threshold_secs: u64) -> Vec<SessionMetadata>
List sessions stuck in “running” state longer than
threshold_secs.Auto Trait Implementations§
impl Freeze for SessionStore
impl RefUnwindSafe for SessionStore
impl Send for SessionStore
impl Sync for SessionStore
impl Unpin for SessionStore
impl UnsafeUnpin for SessionStore
impl UnwindSafe for SessionStore
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more