Skip to main content

systemprompt_models/admin/
mod.rs

1//! `admin` module — see crate-level docs for context.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use systemprompt_identifiers::{ContextId, UserId};
6
7#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum LogLevel {
10    Trace,
11    Debug,
12    #[default]
13    Info,
14    Warn,
15    Error,
16}
17
18impl std::fmt::Display for LogLevel {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::Trace => write!(f, "TRACE"),
22            Self::Debug => write!(f, "DEBUG"),
23            Self::Info => write!(f, "INFO"),
24            Self::Warn => write!(f, "WARN"),
25            Self::Error => write!(f, "ERROR"),
26        }
27    }
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct LogEntry {
32    pub timestamp: DateTime<Utc>,
33    pub level: LogLevel,
34    pub module: String,
35    pub message: String,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct UserInfo {
40    pub id: UserId,
41    pub name: String,
42    pub email: Option<String>,
43    pub active_sessions: i64,
44    pub last_session_at: Option<DateTime<Utc>>,
45    pub roles: Vec<String>,
46}
47
48#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
49pub struct UserMetricsWithTrends {
50    pub total_users: i64,
51    pub active_users: i64,
52    pub new_users_today: i64,
53    pub new_users_week: i64,
54    pub new_users_month: i64,
55    pub users_trend_7d: f64,
56    pub users_trend_30d: f64,
57    pub active_trend_7d: f64,
58    pub active_trend_30d: f64,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct ContentStat {
63    pub content_type: String,
64    pub count: i64,
65    pub total_size: Option<i64>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct RecentConversation {
70    pub context_id: ContextId,
71    pub user_name: Option<String>,
72    pub message_count: i64,
73    pub last_activity: DateTime<Utc>,
74    pub agent_name: Option<String>,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct ActivityTrend {
79    pub date: String,
80    pub message_count: i64,
81    pub user_count: i64,
82    pub task_count: i64,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct BrowserBreakdown {
87    pub browser: String,
88    pub count: i64,
89    pub percentage: f64,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct DeviceBreakdown {
94    pub device_type: String,
95    pub count: i64,
96    pub percentage: f64,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct GeographicBreakdown {
101    pub country: String,
102    pub count: i64,
103    pub percentage: f64,
104}
105
106#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
107pub struct BotTrafficStats {
108    pub total_requests: i64,
109    pub bot_requests: i64,
110    pub human_requests: i64,
111    pub bot_percentage: f64,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct AnalyticsData {
116    pub user_metrics: Option<UserMetricsWithTrends>,
117    pub content_stats: Vec<ContentStat>,
118    pub recent_conversations: Vec<RecentConversation>,
119    pub activity_trends: Vec<ActivityTrend>,
120    pub traffic: Option<TrafficData>,
121}
122
123#[derive(Debug, Clone, Default, Serialize, Deserialize)]
124pub struct TrafficData {
125    pub browsers: Vec<BrowserBreakdown>,
126    pub devices: Vec<DeviceBreakdown>,
127    pub countries: Vec<GeographicBreakdown>,
128    pub bot_traffic: BotTrafficStats,
129}