Skip to main content

systemprompt_analytics/
lib.rs

1//! Analytics domain crate for systemprompt.io.
2//!
3//! Provides session, fingerprint, funnel, engagement, conversation, content,
4//! tool, agent, and cost analytics on top of the `systemprompt-database`
5//! abstraction. Public surface is a typed [`AnalyticsError`] boundary plus a
6//! family of repositories and services consumed by `systemprompt-api`,
7//! `systemprompt-cli`, and `systemprompt-scheduler`.
8//!
9//! # Feature flags
10//!
11//! | Feature       | Description                                                                  |
12//! |---------------|------------------------------------------------------------------------------|
13//! | _(default)_   | Core analytics — repositories, services, events, no geolocation enrichment.  |
14//! | `geolocation` | Enables MaxMind GeoIP enrichment via [`maxminddb`] for [`GeoIpReader`].      |
15
16pub mod error;
17pub mod extension;
18pub mod models;
19pub mod repository;
20pub mod services;
21
22pub use extension::AnalyticsExtension;
23
24pub use error::{AnalyticsError, Result, Result as AnalyticsResult};
25
26pub use models::{
27    ActivityTrend, AnalyticsEvent, AnalyticsEventBatchResponse, AnalyticsEventCreated,
28    AnalyticsEventType, AnalyticsSession, BotTrafficStats, BrowserBreakdown, ContentStat,
29    ConversationByAgent, ConversationSummary, ConversationTrend, ConversionEventData, CostOverview,
30    CreateAnalyticsEventBatchInput, CreateAnalyticsEventInput, CreateEngagementEventInput,
31    CreateFunnelInput, CreateFunnelStepInput, DeviceBreakdown, EngagementEvent,
32    EngagementEventData, EngagementOptionalMetrics, ErrorSummary, FingerprintAnalysisResult,
33    FingerprintReputation, FlagReason, Funnel, FunnelMatchType, FunnelProgress, FunnelStats,
34    FunnelStep, FunnelStepStats, FunnelWithSteps, GeographicBreakdown, LinkClickEventData,
35    PlatformOverview, RecentConversation, ScrollEventData, TopAgent, TopTool, TopUser,
36    TrafficSource, TrafficSummary, UserMetricsWithTrends,
37};
38pub use repository::{
39    ABUSE_THRESHOLD_FOR_BAN, AgentAnalyticsRepository, AnalyticsEventsRepository,
40    AnalyticsQueryRepository, CliSessionAnalyticsRepository, ContentAnalyticsRepository,
41    ConversationAnalyticsRepository, CoreStatsRepository, CostAnalyticsRepository,
42    CreateSessionParams, EngagementRepository, FingerprintRepository, FunnelRepository,
43    HIGH_REQUEST_THRESHOLD, HIGH_VELOCITY_RPM, MAX_SESSIONS_PER_FINGERPRINT,
44    OverviewAnalyticsRepository, ProviderUsage, RequestAnalyticsRepository,
45    SUSTAINED_VELOCITY_MINUTES, SessionBehavioralData, SessionEngagementSummary,
46    SessionMigrationResult, SessionRecord, SessionRepository, StoredAnalyticsEvent,
47    ToolAnalyticsRepository, ToolListParams, TrafficAnalyticsRepository,
48};
49pub use services::bot_keywords::matches_bot_pattern;
50pub use services::{
51    AnalyticsAiSessionProvider, AnalyticsService, AnomalyCheckResult, AnomalyDetectionService,
52    AnomalyEvent, AnomalyLevel, AnomalyThresholdConfig, BEHAVIORAL_BOT_THRESHOLD,
53    BehavioralAnalysisInput, BehavioralAnalysisResult, BehavioralBotDetector, BehavioralSignal,
54    CreateAnalyticsSessionInput, EscalationCriteria, SessionAnalytics, SessionCleanupService,
55    SignalType, ThrottleLevel, ThrottleService, detection,
56};
57
58#[cfg(feature = "geolocation")]
59pub type GeoIpReader = std::sync::Arc<maxminddb::Reader<Vec<u8>>>;
60
61#[cfg(not(feature = "geolocation"))]
62pub type GeoIpReader = std::sync::Arc<()>;