Skip to main content

SessionService

Trait SessionService 

Source
pub trait SessionService: Send + Sync {
    // Required methods
    fn create<'life0, 'async_trait>(
        &'life0 self,
        req: CreateRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get<'life0, 'async_trait>(
        &'life0 self,
        req: GetRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn list<'life0, 'async_trait>(
        &'life0 self,
        req: ListRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Session>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'async_trait>(
        &'life0 self,
        req: DeleteRequest,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn append_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        session_id: &'life1 str,
        event: Event,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn get_for_identity<'life0, 'life1, 'async_trait>(
        &'life0 self,
        identity: &'life1 AdkIdentity,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn delete_for_identity<'life0, 'life1, 'async_trait>(
        &'life0 self,
        identity: &'life1 AdkIdentity,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn append_event_for_identity<'life0, 'async_trait>(
        &'life0 self,
        req: AppendEventRequest,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn delete_all_sessions<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        app_name: &'life1 str,
        user_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn rewind<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _session_id: &'life1 str,
        _target_event_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn rewind_steps<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _session_id: &'life1 str,
        _steps: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for session persistence backends.

Implementations manage the full lifecycle of sessions: creation, retrieval, listing, deletion, and event appending.

Required Methods§

Source

fn create<'life0, 'async_trait>( &'life0 self, req: CreateRequest, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new session and return it.

Source

fn get<'life0, 'async_trait>( &'life0 self, req: GetRequest, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieve an existing session by its identifiers.

Source

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

List sessions for a given app and user.

Source

fn delete<'life0, 'async_trait>( &'life0 self, req: DeleteRequest, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete a session by its identifiers.

Source

fn append_event<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, event: Event, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Append an event to a session identified by its session ID string.

Provided Methods§

Source

fn get_for_identity<'life0, 'life1, 'async_trait>( &'life0 self, identity: &'life1 AdkIdentity, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a session using typed AdkIdentity addressing.

This is the preferred path for new code. It constructs a GetRequest from the full (app_name, user_id, session_id) triple so that session lookup is unambiguous.

The default implementation delegates to get with a freshly built GetRequest.

§Errors

Returns an error if the session cannot be retrieved.

Source

fn delete_for_identity<'life0, 'life1, 'async_trait>( &'life0 self, identity: &'life1 AdkIdentity, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a session using typed AdkIdentity addressing.

This is the preferred path for new code. It constructs a DeleteRequest from the full (app_name, user_id, session_id) triple so that session deletion is unambiguous.

The default implementation delegates to delete with a freshly built DeleteRequest.

§Errors

Returns an error if the session cannot be deleted.

Source

fn append_event_for_identity<'life0, 'async_trait>( &'life0 self, req: AppendEventRequest, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Append an event to a session using typed AdkIdentity addressing.

This is the preferred path for new code. It uses the full (app_name, user_id, session_id) triple so that session lookup is unambiguous even when the same session_id string appears under different apps or users.

The default implementation delegates to the legacy append_event method using only the session_id component. Backends that support composite-key addressing should override this method to use all three identity fields.

§Errors

Returns an error if the event cannot be appended.

Source

fn delete_all_sessions<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete all sessions for a given app and user.

Removes all sessions and their associated events. Useful for bulk cleanup and GDPR right-to-erasure compliance. The default implementation returns an error.

Source

fn rewind<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _session_id: &'life1 str, _target_event_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Rewind a session to the specified event, removing all subsequent events and rebuilding state from remaining events’ state deltas.

After rewinding, the session will contain only events up to and including the target event, and the session state will reflect the cumulative application of those events’ state deltas.

§Errors

Returns an error if the backend does not support rewind, the session is not found, or the target event ID does not exist in the session.

Source

fn rewind_steps<'life0, 'life1, 'async_trait>( &'life0 self, _session_id: &'life1 str, _steps: usize, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Rewind a session by N steps from the end.

If steps is 0, returns the session unchanged. If steps exceeds the number of events, returns an error.

§Errors

Returns an error if the backend does not support rewind, the session is not found, or steps exceeds the event count.

Source

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

Verify backend connectivity.

Returns Ok(()) if the backend is reachable and responsive. Use this for Kubernetes readiness probes and /healthz endpoints. The default implementation always succeeds (suitable for in-memory).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§