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//!
16//! Copyright (c) systemprompt.io — Business Source License 1.1.
17//! See <https://systemprompt.io> for licensing details.
18
19pub mod error;
20pub mod extension;
21pub mod models;
22pub mod repository;
23pub mod services;
24
25pub use extension::AnalyticsExtension;
26
27pub use error::{AnalyticsError, Result, Result as AnalyticsResult};
28
29pub use models::{
30    ActivityTrend, AnalyticsEvent, AnalyticsEventBatchResponse, AnalyticsEventCreated,
31    AnalyticsEventType, AnalyticsSession, BotTrafficStats, BrowserBreakdown, ContentStat,
32    ContextGroupRow, ContextSummaryRow, ConversationByAgent, ConversationSummary,
33    ConversationTrend, ConversionEventData, CostOverview, CreateAnalyticsEventBatchInput,
34    CreateAnalyticsEventInput, CreateEngagementEventInput, CreateFunnelInput,
35    CreateFunnelStepInput, DeviceBreakdown, EngagementEvent, EngagementEventData,
36    EngagementOptionalMetrics, ErrorSummary, FingerprintAnalysisResult, FingerprintReputation,
37    FlagReason, Funnel, FunnelMatchType, FunnelProgress, FunnelStats, FunnelStep, FunnelStepStats,
38    FunnelWithSteps, GeographicBreakdown, LinkClickEventData, PlatformOverview, RecentContextRow,
39    RecentConversation, ScrollEventData, TopAgent, TopTool, TopUser, TrafficSource, TrafficSummary,
40    UserMetricsWithTrends,
41};
42pub use repository::{
43    ABUSE_THRESHOLD_FOR_BAN, AgentAnalyticsRepository, AnalyticsEventsRepository,
44    AnalyticsQueryRepository, CliSessionAnalyticsRepository, ContentAnalyticsRepository,
45    ConversationAnalyticsRepository, CoreStatsRepository, CostAnalyticsRepository,
46    CreateSessionParams, EngagementRepository, FingerprintRepository, FunnelRepository,
47    HIGH_REQUEST_THRESHOLD, HIGH_VELOCITY_RPM, MAX_SESSIONS_PER_FINGERPRINT,
48    OverviewAnalyticsRepository, ProviderUsage, RequestAnalyticsRepository,
49    SUSTAINED_VELOCITY_MINUTES, SessionBehavioralData, SessionEngagementSummary,
50    SessionMigrationResult, SessionRecord, SessionRepository, StoredAnalyticsEvent,
51    ToolAnalyticsRepository, ToolListParams, TrafficAnalyticsRepository,
52};
53pub use services::bot_keywords::matches_bot_pattern;
54pub use services::{
55    AnalyticsAiSessionProvider, AnalyticsService, AnomalyCheckResult, AnomalyDetectionService,
56    AnomalyEvent, AnomalyLevel, AnomalyThresholdConfig, BEHAVIORAL_BOT_THRESHOLD,
57    BehavioralAnalysisInput, BehavioralAnalysisResult, BehavioralBotDetector, BehavioralSignal,
58    CreateAnalyticsSessionInput, SessionAnalytics, SessionCleanupService, SignalType, detection,
59};
60
61#[cfg(feature = "geolocation")]
62pub type GeoIpReader = std::sync::Arc<maxminddb::Reader<Vec<u8>>>;
63
64#[cfg(not(feature = "geolocation"))]
65pub type GeoIpReader = std::sync::Arc<()>;