Skip to main content

systemprompt_cli/commands/analytics/
mod.rs

1//! Top-level `analytics` command group spanning all metric domains.
2//!
3//! [`AnalyticsCommands`] routes to the per-domain subcommand trees (overview,
4//! conversations, agents, tools, requests, sessions, content, traffic, costs).
5//! Each variant dispatches to its module's `execute` against the invocation's
6//! [`CommandContext`]. The [`shared`] module holds the time-range and output
7//! formatting helpers used across all domains.
8//!
9//! Copyright (c) systemprompt.io — Business Source License 1.1.
10//! See <https://systemprompt.io> for licensing details.
11
12pub mod agents;
13pub mod content;
14pub mod conversations;
15pub mod costs;
16pub mod overview;
17pub mod requests;
18pub mod sessions;
19pub mod shared;
20pub mod tools;
21pub mod traffic;
22
23use anyhow::Result;
24use clap::Subcommand;
25
26use crate::context::CommandContext;
27use crate::shared::render_result;
28
29#[derive(Debug, Subcommand)]
30pub enum AnalyticsCommands {
31    #[command(about = "Dashboard overview of all analytics")]
32    Overview(overview::OverviewArgs),
33
34    #[command(subcommand, about = "Conversation analytics")]
35    Conversations(conversations::ConversationsCommands),
36
37    #[command(subcommand, about = "Agent performance analytics")]
38    Agents(agents::AgentsCommands),
39
40    #[command(subcommand, about = "Tool usage analytics")]
41    Tools(tools::ToolsCommands),
42
43    #[command(subcommand, about = "AI request analytics")]
44    Requests(requests::RequestsCommands),
45
46    #[command(subcommand, about = "Session analytics")]
47    Sessions(sessions::SessionsCommands),
48
49    #[command(subcommand, about = "Content performance analytics")]
50    Content(content::ContentCommands),
51
52    #[command(subcommand, about = "Traffic analytics")]
53    Traffic(traffic::TrafficCommands),
54
55    #[command(subcommand, about = "Cost analytics")]
56    Costs(costs::CostsCommands),
57}
58
59pub async fn execute(command: AnalyticsCommands, ctx: &CommandContext) -> Result<()> {
60    match command {
61        AnalyticsCommands::Overview(args) => {
62            let result =
63                overview::execute_with_pool(args, &ctx.database().await?, &ctx.cli).await?;
64            render_result(&result, &ctx.cli);
65            Ok(())
66        },
67        AnalyticsCommands::Conversations(cmd) => conversations::execute(cmd, ctx).await,
68        AnalyticsCommands::Agents(cmd) => agents::execute(cmd, ctx).await,
69        AnalyticsCommands::Tools(cmd) => tools::execute(cmd, ctx).await,
70        AnalyticsCommands::Requests(cmd) => requests::execute(cmd, ctx).await,
71        AnalyticsCommands::Sessions(cmd) => sessions::execute(cmd, ctx).await,
72        AnalyticsCommands::Content(cmd) => content::execute(cmd, ctx).await,
73        AnalyticsCommands::Traffic(cmd) => traffic::execute(cmd, ctx).await,
74        AnalyticsCommands::Costs(cmd) => costs::execute(cmd, ctx).await,
75    }
76}