Skip to main content

SessionLifecycleDb

Trait SessionLifecycleDb 

Source
pub trait SessionLifecycleDb: Send + Sync {
    // Required methods
    fn ensure_and_touch_session<'life0, 'life1, 'async_trait>(
        &'life0 self,
        session_id: &'life1 str,
        user_id: Uuid,
        dataset_id: Option<Uuid>,
    ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn accumulate_usage<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        session_id: &'life1 str,
        user_id: Uuid,
        model: Option<&'life2 str>,
        tokens_in: i64,
        tokens_out: i64,
        cost_usd: f64,
        errored: bool,
    ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn get_session_row<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        session_id: &'life1 str,
        user_id: Uuid,
        permitted_dataset_ids: &'life2 [Uuid],
        prefer_other_owner: bool,
    ) -> Pin<Box<dyn Future<Output = Result<Option<SessionRowWithStatus>, DatabaseError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn list_session_rows<'life0, 'async_trait>(
        &'life0 self,
        filters: SessionListFilters,
    ) -> Pin<Box<dyn Future<Output = Result<SessionListPage, DatabaseError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn aggregate_stats<'life0, 'life1, 'async_trait>(
        &'life0 self,
        user_id: Uuid,
        permitted_dataset_ids: &'life1 [Uuid],
        since: Option<DateTime<Utc>>,
    ) -> Pin<Box<dyn Future<Output = Result<SessionStats, DatabaseError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn cost_by_model<'life0, 'life1, 'async_trait>(
        &'life0 self,
        user_id: Uuid,
        permitted_dataset_ids: &'life1 [Uuid],
        since: Option<DateTime<Utc>>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<CostByModelRow>, DatabaseError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
}
Expand description

Repository trait for /api/v1/sessions/*. See module docs.

Required Methods§

Source

fn ensure_and_touch_session<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, user_id: Uuid, dataset_id: Option<Uuid>, ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Upsert a session row, bumping last_activity_at if the row is already running. Mirrors metrics.py:62-130.

Source

fn accumulate_usage<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, user_id: Uuid, model: Option<&'life2 str>, tokens_in: i64, tokens_out: i64, cost_usd: f64, errored: bool, ) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Atomically add usage counters to the session row + per-model row. Mirrors metrics.py:133-241.

Source

fn get_session_row<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, user_id: Uuid, permitted_dataset_ids: &'life2 [Uuid], prefer_other_owner: bool, ) -> Pin<Box<dyn Future<Output = Result<Option<SessionRowWithStatus>, DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Visibility-checked single-row read. Mirrors metrics.py:295-333.

Source

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

Paginated list with effective_status filter support. Mirrors metrics.py:365-438.

Source

fn aggregate_stats<'life0, 'life1, 'async_trait>( &'life0 self, user_id: Uuid, permitted_dataset_ids: &'life1 [Uuid], since: Option<DateTime<Utc>>, ) -> Pin<Box<dyn Future<Output = Result<SessionStats, DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Dashboard counters for GET /sessions/stats. Mirrors get_sessions_router.py:112-196.

Source

fn cost_by_model<'life0, 'life1, 'async_trait>( &'life0 self, user_id: Uuid, permitted_dataset_ids: &'life1 [Uuid], since: Option<DateTime<Utc>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<CostByModelRow>, DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Per-model attribution for GET /sessions/cost-by-model. Mirrors get_sessions_router.py:198-252.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§