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    ContextGroupRow, ContextSummaryRow, ConversationByAgent, ConversationSummary,
30    ConversationTrend, ConversionEventData, CostOverview, CreateAnalyticsEventBatchInput,
31    CreateAnalyticsEventInput, CreateEngagementEventInput, CreateFunnelInput,
32    CreateFunnelStepInput, DeviceBreakdown, EngagementEvent, EngagementEventData,
33    EngagementOptionalMetrics, ErrorSummary, FingerprintAnalysisResult, FingerprintReputation,
34    FlagReason, Funnel, FunnelMatchType, FunnelProgress, FunnelStats, FunnelStep, FunnelStepStats,
35    FunnelWithSteps, GeographicBreakdown, LinkClickEventData, PlatformOverview, RecentContextRow,
36    RecentConversation, ScrollEventData, TopAgent, TopTool, TopUser, TrafficSource, TrafficSummary,
37    UserMetricsWithTrends,
38};
39pub use repository::{
40    ABUSE_THRESHOLD_FOR_BAN, AgentAnalyticsRepository, AnalyticsEventsRepository,
41    AnalyticsQueryRepository, CliSessionAnalyticsRepository, ContentAnalyticsRepository,
42    ConversationAnalyticsRepository, CoreStatsRepository, CostAnalyticsRepository,
43    CreateSessionParams, EngagementRepository, FingerprintRepository, FunnelRepository,
44    HIGH_REQUEST_THRESHOLD, HIGH_VELOCITY_RPM, MAX_SESSIONS_PER_FINGERPRINT,
45    OverviewAnalyticsRepository, ProviderUsage, RequestAnalyticsRepository,
46    SUSTAINED_VELOCITY_MINUTES, SessionBehavioralData, SessionEngagementSummary,
47    SessionMigrationResult, SessionRecord, SessionRepository, StoredAnalyticsEvent,
48    ToolAnalyticsRepository, ToolListParams, TrafficAnalyticsRepository,
49};
50pub use services::bot_keywords::matches_bot_pattern;
51pub use services::{
52    AnalyticsAiSessionProvider, AnalyticsService, AnomalyCheckResult, AnomalyDetectionService,
53    AnomalyEvent, AnomalyLevel, AnomalyThresholdConfig, BEHAVIORAL_BOT_THRESHOLD,
54    BehavioralAnalysisInput, BehavioralAnalysisResult, BehavioralBotDetector, BehavioralSignal,
55    CreateAnalyticsSessionInput, EscalationCriteria, SessionAnalytics, SessionCleanupService,
56    SignalType, ThrottleLevel, ThrottleService, detection,
57};
58
59#[cfg(feature = "geolocation")]
60pub type GeoIpReader = std::sync::Arc<maxminddb::Reader<Vec<u8>>>;
61
62#[cfg(not(feature = "geolocation"))]
63pub type GeoIpReader = std::sync::Arc<()>;