1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
5use systemprompt_identifiers::{
6 AiRequestId, ArtifactId, ContextId, ExecutionStepId, LogId, McpExecutionId, SessionId, TaskId,
7 TraceId, UserId,
8};
9
10#[derive(Debug, Clone)]
11pub struct TraceListFilter {
12 pub limit: i64,
13 pub since: Option<DateTime<Utc>>,
14 pub agent: Option<String>,
15 pub status: Option<String>,
16 pub tool: Option<String>,
17 pub has_mcp: bool,
18 pub include_system: bool,
19}
20
21impl TraceListFilter {
22 pub const fn new(limit: i64) -> Self {
23 Self {
24 limit,
25 since: None,
26 agent: None,
27 status: None,
28 tool: None,
29 has_mcp: false,
30 include_system: false,
31 }
32 }
33
34 pub const fn with_since(mut self, since: DateTime<Utc>) -> Self {
35 self.since = Some(since);
36 self
37 }
38
39 systemprompt_models::builder_methods! {
40 with_agent(agent) -> String,
41 with_status(status) -> String,
42 with_tool(tool) -> String,
43 }
44
45 pub const fn with_has_mcp(mut self, has_mcp: bool) -> Self {
46 self.has_mcp = has_mcp;
47 self
48 }
49
50 pub const fn with_include_system(mut self, include_system: bool) -> Self {
51 self.include_system = include_system;
52 self
53 }
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct TraceListItem {
58 pub trace_id: TraceId,
59 pub first_timestamp: DateTime<Utc>,
60 pub last_timestamp: DateTime<Utc>,
61 pub agent: Option<String>,
62 pub status: Option<String>,
63 pub ai_requests: i64,
64 pub mcp_calls: i64,
65}
66
67#[derive(Debug, Clone)]
68pub struct ToolExecutionFilter {
69 pub limit: i64,
70 pub since: Option<DateTime<Utc>>,
71 pub name: Option<String>,
72 pub server: Option<String>,
73 pub status: Option<String>,
74}
75
76impl ToolExecutionFilter {
77 pub const fn new(limit: i64) -> Self {
78 Self {
79 limit,
80 since: None,
81 name: None,
82 server: None,
83 status: None,
84 }
85 }
86
87 pub const fn with_since(mut self, since: DateTime<Utc>) -> Self {
88 self.since = Some(since);
89 self
90 }
91
92 systemprompt_models::builder_methods! {
93 with_name(name) -> String,
94 with_server(server) -> String,
95 with_status(status) -> String,
96 }
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct ToolExecutionItem {
101 pub timestamp: DateTime<Utc>,
102 pub trace_id: TraceId,
103 pub tool_name: String,
104 pub server_name: Option<String>,
105 pub status: String,
106 pub execution_time_ms: Option<i32>,
107}
108
109#[derive(Debug, Clone)]
110pub struct LogSearchFilter {
111 pub pattern: String,
112 pub limit: i64,
113 pub since: Option<DateTime<Utc>>,
114 pub level: Option<String>,
115}
116
117impl LogSearchFilter {
118 pub const fn new(pattern: String, limit: i64) -> Self {
119 Self {
120 pattern,
121 limit,
122 since: None,
123 level: None,
124 }
125 }
126
127 pub const fn with_since(mut self, since: DateTime<Utc>) -> Self {
128 self.since = Some(since);
129 self
130 }
131
132 systemprompt_models::builder_methods! {
133 with_level(level) -> String,
134 }
135}
136
137#[derive(Debug, Clone, Serialize, Deserialize)]
138pub struct LogSearchItem {
139 pub id: LogId,
140 pub trace_id: TraceId,
141 pub timestamp: DateTime<Utc>,
142 pub level: String,
143 pub module: String,
144 pub message: String,
145 pub metadata: Option<String>,
146}
147
148#[derive(Debug, Clone)]
149pub struct AiRequestFilter {
150 pub limit: i64,
151 pub since: Option<DateTime<Utc>>,
152 pub model: Option<String>,
153 pub provider: Option<String>,
154}
155
156impl AiRequestFilter {
157 pub const fn new(limit: i64) -> Self {
158 Self {
159 limit,
160 since: None,
161 model: None,
162 provider: None,
163 }
164 }
165
166 pub const fn with_since(mut self, since: DateTime<Utc>) -> Self {
167 self.since = Some(since);
168 self
169 }
170
171 systemprompt_models::builder_methods! {
172 with_model(model) -> String,
173 with_provider(provider) -> String,
174 }
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct AiRequestListItem {
179 pub id: AiRequestId,
180 pub created_at: DateTime<Utc>,
181 pub trace_id: Option<TraceId>,
182 pub provider: String,
183 pub model: String,
184 pub input_tokens: Option<i32>,
185 pub output_tokens: Option<i32>,
186 pub cost_microdollars: i64,
187 pub latency_ms: Option<i32>,
188 pub status: String,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct AiRequestDetail {
193 pub id: AiRequestId,
194 pub provider: String,
195 pub model: String,
196 pub input_tokens: Option<i32>,
197 pub output_tokens: Option<i32>,
198 pub cost_microdollars: i64,
199 pub latency_ms: Option<i32>,
200 pub status: String,
201 pub error_message: Option<String>,
202}
203
204#[derive(Debug, Clone, Default, Serialize, Deserialize)]
205pub struct AiRequestStats {
206 pub total_requests: i64,
207 pub total_input_tokens: i64,
208 pub total_output_tokens: i64,
209 pub total_cost_microdollars: i64,
210 pub avg_latency_ms: i64,
211 pub by_provider: Vec<ProviderStatsRow>,
212 pub by_model: Vec<ModelStatsRow>,
213}
214
215#[derive(Debug, Clone, Serialize, Deserialize)]
216pub struct ProviderStatsRow {
217 pub provider: String,
218 pub request_count: i64,
219 pub total_tokens: i64,
220 pub total_cost_microdollars: i64,
221 pub avg_latency_ms: i64,
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize)]
225pub struct ModelStatsRow {
226 pub model: String,
227 pub provider: String,
228 pub request_count: i64,
229 pub total_tokens: i64,
230 pub total_cost_microdollars: i64,
231 pub avg_latency_ms: i64,
232}
233
234#[derive(Debug, Clone, Serialize, Deserialize)]
235pub struct AuditLookupResult {
236 pub id: AiRequestId,
237 pub provider: String,
238 pub model: String,
239 pub input_tokens: Option<i32>,
240 pub output_tokens: Option<i32>,
241 pub cost_microdollars: i64,
242 pub latency_ms: Option<i32>,
243 pub task_id: Option<TaskId>,
244 pub trace_id: Option<TraceId>,
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
248pub struct AuditToolCallRow {
249 pub tool_name: String,
250 pub tool_input: String,
251 pub sequence_number: i32,
252}
253
254#[derive(Debug, Clone, Serialize, Deserialize)]
255pub struct LinkedMcpCall {
256 pub tool_name: String,
257 pub server_name: String,
258 pub status: String,
259 pub execution_time_ms: Option<i32>,
260}
261
262#[derive(Debug, Clone, Serialize, Deserialize)]
263pub struct TraceEvent {
264 pub event_type: String,
265 pub timestamp: DateTime<Utc>,
266 pub details: String,
267 pub user_id: Option<UserId>,
268 pub session_id: Option<SessionId>,
269 pub task_id: Option<TaskId>,
270 pub context_id: Option<ContextId>,
271 pub metadata: Option<String>,
272}
273
274#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
275pub struct AiRequestSummary {
276 pub total_cost_microdollars: i64,
277 pub total_tokens: i64,
278 pub total_input_tokens: i64,
279 pub total_output_tokens: i64,
280 pub request_count: i64,
281 pub total_latency_ms: i64,
282}
283
284#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
285pub struct McpExecutionSummary {
286 pub execution_count: i64,
287 pub total_execution_time_ms: i64,
288}
289
290#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
291pub struct ExecutionStepSummary {
292 #[serde(rename = "step_count")]
293 pub total: i64,
294 #[serde(rename = "completed_count")]
295 pub completed: i64,
296 #[serde(rename = "failed_count")]
297 pub failed: i64,
298 #[serde(rename = "pending_count")]
299 pub pending: i64,
300}
301
302#[derive(Debug, Clone, Serialize, Deserialize)]
303pub struct TaskInfo {
304 pub task_id: TaskId,
305 pub context_id: ContextId,
306 pub agent_name: Option<String>,
307 pub status: String,
308 pub created_at: DateTime<Utc>,
309 pub started_at: Option<DateTime<Utc>>,
310 pub completed_at: Option<DateTime<Utc>>,
311 pub execution_time_ms: Option<i32>,
312 pub error_message: Option<String>,
313}
314
315#[derive(Debug, Clone, Serialize, Deserialize)]
316pub struct ExecutionStep {
317 pub step_id: ExecutionStepId,
318 pub step_type: Option<String>,
319 pub title: Option<String>,
320 pub status: String,
321 pub duration_ms: Option<i32>,
322 pub error_message: Option<String>,
323}
324
325#[derive(Debug, Clone, Serialize, Deserialize)]
326pub struct AiRequestInfo {
327 pub id: AiRequestId,
328 pub provider: String,
329 pub model: String,
330 pub max_tokens: Option<i32>,
331 pub input_tokens: Option<i32>,
332 pub output_tokens: Option<i32>,
333 pub cost_microdollars: i64,
334 pub latency_ms: Option<i32>,
335}
336
337#[derive(Debug, Clone, Serialize, Deserialize)]
338pub struct McpToolExecution {
339 pub mcp_execution_id: McpExecutionId,
340 pub tool_name: String,
341 pub server_name: String,
342 pub status: String,
343 pub execution_time_ms: Option<i32>,
344 pub error_message: Option<String>,
345 pub input: String,
346 pub output: Option<String>,
347}
348
349#[derive(Debug, Clone, Serialize, Deserialize)]
350pub struct ConversationMessage {
351 pub role: String,
352 pub content: String,
353 pub sequence_number: i32,
354}
355
356#[derive(Debug, Clone, Serialize, Deserialize)]
357pub struct ToolLogEntry {
358 pub timestamp: DateTime<Utc>,
359 pub level: String,
360 pub module: String,
361 pub message: String,
362}
363
364#[derive(Debug, Clone, Serialize, Deserialize)]
365pub struct TaskArtifact {
366 pub artifact_id: ArtifactId,
367 pub artifact_type: String,
368 pub name: Option<String>,
369 pub source: Option<String>,
370 pub tool_name: Option<String>,
371 pub part_kind: Option<String>,
372 pub text_content: Option<String>,
373 pub data_content: Option<Value>,
374}
375
376#[derive(Debug, Clone, Serialize, Deserialize)]
377pub struct LevelCount {
378 pub level: String,
379 pub count: i64,
380}
381
382#[derive(Debug, Clone, Serialize, Deserialize)]
383pub struct ModuleCount {
384 pub module: String,
385 pub count: i64,
386}
387
388#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
389pub struct LogTimeRange {
390 pub earliest: Option<DateTime<Utc>>,
391 pub latest: Option<DateTime<Utc>>,
392}