Skip to main content

tracevault_core/
trace.rs

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