Skip to main content

systemprompt_traits/
session_analytics.rs

1use async_trait::async_trait;
2use std::sync::Arc;
3use systemprompt_identifiers::SessionId;
4
5pub type SessionAnalyticsResult<T> = Result<T, SessionAnalyticsProviderError>;
6
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum SessionAnalyticsProviderError {
10    #[error("Session not found")]
11    SessionNotFound,
12
13    #[error("Internal error: {0}")]
14    Internal(String),
15}
16
17impl From<anyhow::Error> for SessionAnalyticsProviderError {
18    fn from(err: anyhow::Error) -> Self {
19        Self::Internal(err.to_string())
20    }
21}
22
23#[async_trait]
24pub trait SessionAnalyticsProvider: Send + Sync {
25    async fn increment_task_count(&self, session_id: &SessionId) -> SessionAnalyticsResult<()>;
26    async fn increment_message_count(&self, session_id: &SessionId) -> SessionAnalyticsResult<()>;
27}
28
29pub type DynSessionAnalyticsProvider = Arc<dyn SessionAnalyticsProvider>;