systemprompt_cli/commands/analytics/
mod.rs1pub 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::CliConfig;
17
18#[derive(Debug, Subcommand)]
19pub enum AnalyticsCommands {
20 #[command(about = "Dashboard overview of all analytics")]
21 Overview(overview::OverviewArgs),
22
23 #[command(subcommand, about = "Conversation analytics")]
24 Conversations(conversations::ConversationsCommands),
25
26 #[command(subcommand, about = "Agent performance analytics")]
27 Agents(agents::AgentsCommands),
28
29 #[command(subcommand, about = "Tool usage analytics")]
30 Tools(tools::ToolsCommands),
31
32 #[command(subcommand, about = "AI request analytics")]
33 Requests(requests::RequestsCommands),
34
35 #[command(subcommand, about = "Session analytics")]
36 Sessions(sessions::SessionsCommands),
37
38 #[command(subcommand, about = "Content performance analytics")]
39 Content(content::ContentCommands),
40
41 #[command(subcommand, about = "Traffic analytics")]
42 Traffic(traffic::TrafficCommands),
43
44 #[command(subcommand, about = "Cost analytics")]
45 Costs(costs::CostsCommands),
46}
47
48pub async fn execute(command: AnalyticsCommands, config: &CliConfig) -> Result<()> {
49 match command {
50 AnalyticsCommands::Overview(args) => overview::execute(args, config).await,
51 AnalyticsCommands::Conversations(cmd) => conversations::execute(cmd, config).await,
52 AnalyticsCommands::Agents(cmd) => agents::execute(cmd, config).await,
53 AnalyticsCommands::Tools(cmd) => tools::execute(cmd, config).await,
54 AnalyticsCommands::Requests(cmd) => requests::execute(cmd, config).await,
55 AnalyticsCommands::Sessions(cmd) => sessions::execute(cmd, config).await,
56 AnalyticsCommands::Content(cmd) => content::execute(cmd, config).await,
57 AnalyticsCommands::Traffic(cmd) => traffic::execute(cmd, config).await,
58 AnalyticsCommands::Costs(cmd) => costs::execute(cmd, config).await,
59 }
60}
61
62pub async fn execute_with_db(
63 command: AnalyticsCommands,
64 db_ctx: &DatabaseContext,
65 config: &CliConfig,
66) -> Result<()> {
67 match command {
68 AnalyticsCommands::Overview(args) => {
69 overview::execute_with_pool(args, db_ctx, config).await
70 },
71 AnalyticsCommands::Conversations(cmd) => {
72 conversations::execute_with_pool(cmd, db_ctx, config).await
73 },
74 AnalyticsCommands::Agents(cmd) => agents::execute_with_pool(cmd, db_ctx, config).await,
75 AnalyticsCommands::Tools(cmd) => tools::execute_with_pool(cmd, db_ctx, config).await,
76 AnalyticsCommands::Requests(cmd) => requests::execute_with_pool(cmd, db_ctx, config).await,
77 AnalyticsCommands::Sessions(cmd) => sessions::execute_with_pool(cmd, db_ctx, config).await,
78 AnalyticsCommands::Content(cmd) => content::execute_with_pool(cmd, db_ctx, config).await,
79 AnalyticsCommands::Traffic(cmd) => traffic::execute_with_pool(cmd, db_ctx, config).await,
80 AnalyticsCommands::Costs(cmd) => costs::execute_with_pool(cmd, db_ctx, config).await,
81 }
82}