greentic_session/store.rs
1use crate::error::SessionResult;
2use greentic_types::{SessionData, SessionKey, TenantCtx, UserId};
3
4/// Persistent session storage interface used by Greentic runtimes.
5///
6/// `SessionData` captures the tenant context, flow identifier, cursor, and serialized execution
7/// state snapshot for an in-flight flow. Implementations store that payload so runners can pause
8/// execution, persist the snapshot, and resume the flow consistently after new input arrives.
9pub trait SessionStore: Send + Sync + 'static {
10 /// Creates a new session associated with the supplied tenant context and returns its key.
11 fn create_session(&self, ctx: &TenantCtx, data: SessionData) -> SessionResult<SessionKey>;
12
13 /// Fetches the session payload for the provided key, if it exists.
14 fn get_session(&self, key: &SessionKey) -> SessionResult<Option<SessionData>>;
15
16 /// Replaces the session payload for the provided key.
17 fn update_session(&self, key: &SessionKey, data: SessionData) -> SessionResult<()>;
18
19 /// Removes the session entry and clears any lookup indices.
20 fn remove_session(&self, key: &SessionKey) -> SessionResult<()>;
21
22 /// Finds the active session bound to the specified tenant + user combination.
23 fn find_by_user(
24 &self,
25 ctx: &TenantCtx,
26 user: &UserId,
27 ) -> SessionResult<Option<(SessionKey, SessionData)>>;
28}