systemprompt-analytics 0.15.0

Analytics for systemprompt.io AI governance infrastructure. Session, agent, tool, and microdollar-precision cost attribution across the MCP governance pipeline.
Documentation
//! Browser-fingerprint reputation tracking for abuse detection.
//!
//! [`FingerprintRepository`] upserts and scores `fingerprint_reputation`
//! rows — session counts, request velocity, flags, and reputation score —
//! used to detect and ban abusive clients. Read queries live in `queries`,
//! state changes in `mutations`; the threshold constants here define the
//! abuse-detection policy.

mod mutations;
mod queries;

use std::sync::Arc;

use crate::Result;
use sqlx::PgPool;
use systemprompt_database::DbPool;

pub const MAX_SESSIONS_PER_FINGERPRINT: i32 = 5;
pub const HIGH_REQUEST_THRESHOLD: i64 = 100;
pub const HIGH_VELOCITY_RPM: f32 = 10.0;
pub const SUSTAINED_VELOCITY_MINUTES: i32 = 60;
pub const ABUSE_THRESHOLD_FOR_BAN: i32 = 3;

#[derive(Clone, Debug)]
pub struct FingerprintRepository {
    pool: Arc<PgPool>,
    write_pool: Arc<PgPool>,
}

impl FingerprintRepository {
    pub fn new(db: &DbPool) -> Result<Self> {
        let pool = db.pool_arc()?;
        let write_pool = db.write_pool_arc()?;
        Ok(Self { pool, write_pool })
    }
}