pub struct SessionManager { /* private fields */ }Expand description
Manager for session persistence and lifecycle.
The SessionManager provides file-based persistence for sessions,
storing them in {workspace}/.thulp/sessions/ as JSON files.
§Example
use thulp_workspace::{Workspace, SessionManager, SessionType};
let workspace = Workspace::new("my-workspace", "My Workspace", PathBuf::from("."));
let manager = SessionManager::new(&workspace).await?;
let session = manager.create_session("My Session", SessionType::Conversation {
purpose: "Testing".to_string(),
}).await?;
manager.add_entry(&session.id(), EntryType::UserMessage, json!({"text": "Hello"})).await?;Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub async fn new(workspace: &Workspace) -> Result<Self>
pub async fn new(workspace: &Workspace) -> Result<Self>
Create a new session manager for the given workspace.
This will create the sessions directory if it doesn’t exist.
Sourcepub async fn with_sessions_dir(sessions_dir: PathBuf) -> Result<Self>
pub async fn with_sessions_dir(sessions_dir: PathBuf) -> Result<Self>
Create a new session manager with a custom sessions directory.
Sourcepub async fn create_session(
&self,
name: impl Into<String>,
session_type: SessionType,
) -> Result<Session>
pub async fn create_session( &self, name: impl Into<String>, session_type: SessionType, ) -> Result<Session>
Create a new session.
The session is automatically persisted to disk and cached in memory.
Sourcepub async fn load_session(&self, id: &SessionId) -> Result<Session>
pub async fn load_session(&self, id: &SessionId) -> Result<Session>
Load a session from disk.
If the session is already cached in memory, returns the cached version.
Sourcepub async fn save_session(&self, session: &Session) -> Result<()>
pub async fn save_session(&self, session: &Session) -> Result<()>
Save a session to disk.
Sourcepub async fn add_entry(
&self,
session_id: &SessionId,
entry_type: EntryType,
content: Value,
) -> Result<SessionEntry>
pub async fn add_entry( &self, session_id: &SessionId, entry_type: EntryType, content: Value, ) -> Result<SessionEntry>
Add an entry to a session.
The session is automatically saved after adding the entry.
Sourcepub async fn complete_session(&self, session_id: &SessionId) -> Result<()>
pub async fn complete_session(&self, session_id: &SessionId) -> Result<()>
Complete a session.
Marks the session as completed and saves it.
Sourcepub async fn fail_session(&self, session_id: &SessionId) -> Result<()>
pub async fn fail_session(&self, session_id: &SessionId) -> Result<()>
Fail a session.
Marks the session as failed and saves it.
Sourcepub async fn cancel_session(&self, session_id: &SessionId) -> Result<()>
pub async fn cancel_session(&self, session_id: &SessionId) -> Result<()>
Cancel a session.
Marks the session as cancelled and saves it.
Sourcepub async fn pause_session(&self, session_id: &SessionId) -> Result<()>
pub async fn pause_session(&self, session_id: &SessionId) -> Result<()>
Pause a session.
Marks the session as paused and saves it.
Sourcepub async fn resume_session(&self, session_id: &SessionId) -> Result<()>
pub async fn resume_session(&self, session_id: &SessionId) -> Result<()>
Resume a paused session.
Marks the session as active and saves it.
Sourcepub async fn list_sessions(
&self,
filter: Option<&SessionFilter>,
) -> Result<Vec<SessionMetadata>>
pub async fn list_sessions( &self, filter: Option<&SessionFilter>, ) -> Result<Vec<SessionMetadata>>
List all sessions, optionally filtered.
Sourcepub async fn delete_session(&self, session_id: &SessionId) -> Result<()>
pub async fn delete_session(&self, session_id: &SessionId) -> Result<()>
Delete a session.
Removes the session from disk and cache.
Sourcepub async fn session_exists(&self, session_id: &SessionId) -> bool
pub async fn session_exists(&self, session_id: &SessionId) -> bool
Check if a session exists.
Sourcepub async fn peek_session(&self, session_id: &SessionId) -> Result<Session>
pub async fn peek_session(&self, session_id: &SessionId) -> Result<Session>
Get a session without loading it into cache.
Useful for one-off reads where caching isn’t beneficial.
Sourcepub async fn evict_from_cache(&self, session_id: &SessionId)
pub async fn evict_from_cache(&self, session_id: &SessionId)
Evict a session from the in-memory cache.
The session remains on disk but is removed from memory.
Sourcepub async fn clear_cache(&self)
pub async fn clear_cache(&self)
Clear all sessions from the in-memory cache.
Sourcepub async fn cached_session_count(&self) -> usize
pub async fn cached_session_count(&self) -> usize
Get the number of cached sessions.
Sourcepub async fn active_sessions(&self) -> Vec<Session>
pub async fn active_sessions(&self) -> Vec<Session>
Get all active sessions (in-memory only).
Sourcepub async fn find_by_tag(&self, tag: &str) -> Result<Vec<SessionMetadata>>
pub async fn find_by_tag(&self, tag: &str) -> Result<Vec<SessionMetadata>>
Find sessions by tag.
Sourcepub async fn find_by_type(
&self,
session_type_name: &str,
) -> Result<Vec<SessionMetadata>>
pub async fn find_by_type( &self, session_type_name: &str, ) -> Result<Vec<SessionMetadata>>
Find sessions by type.
Sourcepub async fn find_by_status(
&self,
status: SessionStatus,
) -> Result<Vec<SessionMetadata>>
pub async fn find_by_status( &self, status: SessionStatus, ) -> Result<Vec<SessionMetadata>>
Find sessions by status.
Sourcepub async fn find_created_after(
&self,
timestamp: Timestamp,
) -> Result<Vec<SessionMetadata>>
pub async fn find_created_after( &self, timestamp: Timestamp, ) -> Result<Vec<SessionMetadata>>
Find sessions created after a timestamp.
Sourcepub async fn find_updated_after(
&self,
timestamp: Timestamp,
) -> Result<Vec<SessionMetadata>>
pub async fn find_updated_after( &self, timestamp: Timestamp, ) -> Result<Vec<SessionMetadata>>
Find sessions updated after a timestamp.
Sourcepub async fn session_count(&self) -> Result<usize>
pub async fn session_count(&self) -> Result<usize>
Get session count on disk.