systemprompt_analytics/models/reporting/
tool.rs1use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use sqlx::FromRow;
9use systemprompt_identifiers::{AgentName, McpServerId, McpToolName};
10
11#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
12pub struct ToolListRow {
13 pub tool_name: McpToolName,
14 pub server_name: McpServerId,
15 pub execution_count: i64,
16 pub success_count: i64,
17 pub avg_time: f64,
18 pub last_used: DateTime<Utc>,
19}
20
21#[derive(Debug, Clone, Copy, Serialize, Deserialize, FromRow)]
22pub struct ToolStatsRow {
23 pub total_tools: i64,
24 pub total_executions: i64,
25 pub successful: i64,
26 pub failed: i64,
27 pub timeout: i64,
28 pub avg_time: f64,
29 pub p95_time: f64,
30}
31
32#[derive(Debug, Clone, Copy, Serialize, Deserialize, FromRow)]
33pub struct ToolSummaryRow {
34 pub total: i64,
35 pub successful: i64,
36 pub failed: i64,
37 pub timeout: i64,
38 pub avg_time: f64,
39 pub p95_time: f64,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
43pub struct ToolStatusBreakdownRow {
44 pub status: String,
45 pub status_count: i64,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
49pub struct ToolErrorRow {
50 pub error_msg: Option<String>,
51 pub error_count: i64,
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
55#[serde(into = "String")]
56pub enum ToolCaller {
57 Agent(AgentName),
58 DirectCall,
59 UnlinkedTask,
60}
61
62impl ToolCaller {
63 pub const DIRECT_CALL_LABEL: &'static str = "Direct Call";
64 pub const UNLINKED_TASK_LABEL: &'static str = "Unlinked Task";
65
66 pub fn as_str(&self) -> &str {
67 match self {
68 Self::Agent(name) => name.as_str(),
69 Self::DirectCall => Self::DIRECT_CALL_LABEL,
70 Self::UnlinkedTask => Self::UNLINKED_TASK_LABEL,
71 }
72 }
73}
74
75impl std::fmt::Display for ToolCaller {
76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 f.write_str(self.as_str())
78 }
79}
80
81impl From<ToolCaller> for String {
82 fn from(caller: ToolCaller) -> Self {
83 caller.as_str().to_owned()
84 }
85}
86
87#[derive(Debug, Clone, Serialize)]
88pub struct ToolAgentUsageRow {
89 pub caller: ToolCaller,
90 pub usage_count: i64,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
94pub struct ToolExecutionRow {
95 pub created_at: DateTime<Utc>,
96 pub status: Option<String>,
97 pub execution_time_ms: Option<i32>,
98}