Skip to main content

tracevault_core/
trace.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5use crate::token_usage::TokenUsage;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct TraceRecord {
9    pub id: Uuid,
10    pub repo_id: String,
11    pub commit_sha: String,
12    pub branch: Option<String>,
13    pub author: String,
14    pub created_at: DateTime<Utc>,
15    pub model: Option<String>,
16    pub tool: String,
17    pub tool_version: Option<String>,
18    pub session: Session,
19    pub agent_trace: Option<serde_json::Value>,
20    pub signature: Option<String>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct Session {
25    pub session_id: String,
26    pub started_at: DateTime<Utc>,
27    pub ended_at: Option<DateTime<Utc>>,
28    pub prompts: Vec<Prompt>,
29    pub responses: Vec<Response>,
30    pub token_usage: TokenUsage,
31    pub tools_used: Vec<ToolCall>,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct Prompt {
36    pub text: String,
37    pub timestamp: DateTime<Utc>,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct Response {
42    pub text: String,
43    pub timestamp: DateTime<Utc>,
44    pub tool_calls: Vec<String>,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct ToolCall {
49    pub name: String,
50    pub input_summary: String,
51    pub timestamp: DateTime<Utc>,
52}
53
54impl TraceRecord {
55    pub fn new(
56        repo_id: String,
57        commit_sha: String,
58        author: String,
59        tool: String,
60        session: Session,
61    ) -> Self {
62        Self {
63            id: Uuid::new_v4(),
64            repo_id,
65            commit_sha,
66            branch: None,
67            author,
68            created_at: Utc::now(),
69            model: None,
70            tool,
71            tool_version: None,
72            session,
73            agent_trace: None,
74            signature: None,
75        }
76    }
77}