pub struct SessionStore { /* private fields */ }Expand description
In-memory session store with TTL-based cleanup.
Implementations§
Source§impl SessionStore
impl SessionStore
Sourcepub async fn create(&self, req: CreateSessionRequest) -> TaskSession
pub async fn create(&self, req: CreateSessionRequest) -> TaskSession
Create a new task session and return it.
Sourcepub async fn use_session(
&self,
session_id: SessionId,
tool_name: &str,
) -> Result<TaskSession, SessionError>
pub async fn use_session( &self, session_id: SessionId, tool_name: &str, ) -> Result<TaskSession, SessionError>
Record a tool call against the session, checking all constraints.
Returns the updated session on success, or an error if:
- Session not found
- Session expired (would return 408)
- Budget exceeded (would return 429)
- Tool not authorized (would return 403)
Sourcepub async fn use_session_batch(
&self,
session_id: SessionId,
tool_names: &[&str],
) -> Result<TaskSession, SessionError>
pub async fn use_session_batch( &self, session_id: SessionId, tool_names: &[&str], ) -> Result<TaskSession, SessionError>
Atomically validate and record a batch of tool calls against the session.
Acquires the write lock once, validates ALL tools against
the whitelist and budget, and only increments calls_made by the full
batch count if every tool passes. If any tool fails validation, no
budget is consumed for any of them.
Sourcepub async fn close(
&self,
session_id: SessionId,
) -> Result<TaskSession, SessionError>
pub async fn close( &self, session_id: SessionId, ) -> Result<TaskSession, SessionError>
Close a session, preventing further use.
Sourcepub async fn get(
&self,
session_id: SessionId,
) -> Result<TaskSession, SessionError>
pub async fn get( &self, session_id: SessionId, ) -> Result<TaskSession, SessionError>
Get a session by ID without modifying it.
Sourcepub async fn list_all(&self) -> Vec<TaskSession>
pub async fn list_all(&self) -> Vec<TaskSession>
List all sessions currently in the store (active, expired, and closed).
Sourcepub async fn count_active_for_agent(&self, agent_id: Uuid) -> u64
pub async fn count_active_for_agent(&self, agent_id: Uuid) -> u64
Count the number of active sessions for a given agent.
P0: Used to enforce per-agent concurrent session caps.
Sourcepub async fn close_sessions_for_agent(&self, agent_id: Uuid) -> usize
pub async fn close_sessions_for_agent(&self, agent_id: Uuid) -> usize
Close all active sessions belonging to a specific agent.
When an agent is deactivated via cascade_deactivate, all its sessions must be immediately closed.
Sourcepub async fn cleanup_expired(&self) -> usize
pub async fn cleanup_expired(&self) -> usize
Remove expired sessions from the store. Returns the number removed.
Trait Implementations§
Source§impl Clone for SessionStore
impl Clone for SessionStore
Source§fn clone(&self) -> SessionStore
fn clone(&self) -> SessionStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more