Skip to main content

systemprompt_cli/commands/analytics/
mod.rs

1pub mod agents;
2pub mod content;
3pub mod conversations;
4pub mod costs;
5pub mod overview;
6pub mod requests;
7pub mod sessions;
8pub mod shared;
9pub mod tools;
10pub mod traffic;
11
12use anyhow::Result;
13use clap::Subcommand;
14use systemprompt_runtime::DatabaseContext;
15
16use crate::shared::render_result;
17use crate::CliConfig;
18
19#[derive(Debug, Subcommand)]
20pub enum AnalyticsCommands {
21    #[command(about = "Dashboard overview of all analytics")]
22    Overview(overview::OverviewArgs),
23
24    #[command(subcommand, about = "Conversation analytics")]
25    Conversations(conversations::ConversationsCommands),
26
27    #[command(subcommand, about = "Agent performance analytics")]
28    Agents(agents::AgentsCommands),
29
30    #[command(subcommand, about = "Tool usage analytics")]
31    Tools(tools::ToolsCommands),
32
33    #[command(subcommand, about = "AI request analytics")]
34    Requests(requests::RequestsCommands),
35
36    #[command(subcommand, about = "Session analytics")]
37    Sessions(sessions::SessionsCommands),
38
39    #[command(subcommand, about = "Content performance analytics")]
40    Content(content::ContentCommands),
41
42    #[command(subcommand, about = "Traffic analytics")]
43    Traffic(traffic::TrafficCommands),
44
45    #[command(subcommand, about = "Cost analytics")]
46    Costs(costs::CostsCommands),
47}
48
49pub async fn execute(command: AnalyticsCommands, config: &CliConfig) -> Result<()> {
50    match command {
51        AnalyticsCommands::Overview(args) => {
52            let result = overview::execute(args, config).await?;
53            render_result(&result);
54            Ok(())
55        },
56        AnalyticsCommands::Conversations(cmd) => conversations::execute(cmd, config).await,
57        AnalyticsCommands::Agents(cmd) => agents::execute(cmd, config).await,
58        AnalyticsCommands::Tools(cmd) => tools::execute(cmd, config).await,
59        AnalyticsCommands::Requests(cmd) => requests::execute(cmd, config).await,
60        AnalyticsCommands::Sessions(cmd) => sessions::execute(cmd, config).await,
61        AnalyticsCommands::Content(cmd) => content::execute(cmd, config).await,
62        AnalyticsCommands::Traffic(cmd) => traffic::execute(cmd, config).await,
63        AnalyticsCommands::Costs(cmd) => costs::execute(cmd, config).await,
64    }
65}
66
67pub async fn execute_with_db(
68    command: AnalyticsCommands,
69    db_ctx: &DatabaseContext,
70    config: &CliConfig,
71) -> Result<()> {
72    match command {
73        AnalyticsCommands::Overview(args) => {
74            let result = overview::execute_with_pool(args, db_ctx, config).await?;
75            render_result(&result);
76            Ok(())
77        },
78        AnalyticsCommands::Conversations(cmd) => {
79            conversations::execute_with_pool(cmd, db_ctx, config).await
80        },
81        AnalyticsCommands::Agents(cmd) => agents::execute_with_pool(cmd, db_ctx, config).await,
82        AnalyticsCommands::Tools(cmd) => tools::execute_with_pool(cmd, db_ctx, config).await,
83        AnalyticsCommands::Requests(cmd) => requests::execute_with_pool(cmd, db_ctx, config).await,
84        AnalyticsCommands::Sessions(cmd) => sessions::execute_with_pool(cmd, db_ctx, config).await,
85        AnalyticsCommands::Content(cmd) => content::execute_with_pool(cmd, db_ctx, config).await,
86        AnalyticsCommands::Traffic(cmd) => traffic::execute_with_pool(cmd, db_ctx, config).await,
87        AnalyticsCommands::Costs(cmd) => costs::execute_with_pool(cmd, db_ctx, config).await,
88    }
89}