systemprompt-traits 0.2.2

Trait-first interface contracts for systemprompt.io AI governance infrastructure. Repository, provider, and service abstractions shared across the MCP governance pipeline.
Documentation
use async_trait::async_trait;
use std::sync::Arc;
use systemprompt_identifiers::SessionId;

pub type SessionAnalyticsResult<T> = Result<T, SessionAnalyticsProviderError>;

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SessionAnalyticsProviderError {
    #[error("Session not found")]
    SessionNotFound,

    #[error("Internal error: {0}")]
    Internal(String),
}

impl From<anyhow::Error> for SessionAnalyticsProviderError {
    fn from(err: anyhow::Error) -> Self {
        Self::Internal(err.to_string())
    }
}

#[async_trait]
pub trait SessionAnalyticsProvider: Send + Sync {
    async fn increment_task_count(&self, session_id: &SessionId) -> SessionAnalyticsResult<()>;
    async fn increment_message_count(&self, session_id: &SessionId) -> SessionAnalyticsResult<()>;
}

pub type DynSessionAnalyticsProvider = Arc<dyn SessionAnalyticsProvider>;