1use crate::agent::AgentOutput;
2use crate::error::SpiceError;
3use serde::{Deserialize, Serialize};
4use std::path::Path;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Trace {
9 pub test_id: String,
10 pub user_message: String,
11 pub output: AgentOutput,
12 pub timestamp: chrono::DateTime<chrono::Utc>,
13}
14
15impl Trace {
16 pub fn new(test_id: String, user_message: String, output: AgentOutput) -> Self {
17 Self {
18 test_id,
19 user_message,
20 output,
21 timestamp: chrono::Utc::now(),
22 }
23 }
24
25 pub fn save_to_file(&self, path: &Path) -> Result<(), SpiceError> {
27 if let Some(parent) = path.parent() {
28 std::fs::create_dir_all(parent)?;
29 }
30 let json = serde_json::to_string_pretty(self)?;
31 std::fs::write(path, json)?;
32 Ok(())
33 }
34}