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