use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StepRecord {
pub step_index: usize,
pub timestamp: String,
pub action_type: String,
pub params: HashMap<String, serde_json::Value>,
pub url: Option<String>,
pub dom_snapshot: Option<String>,
pub result: StepResult,
pub duration_ms: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StepResult {
pub success: bool,
pub extracted_content: Option<String>,
pub error: Option<String>,
}
impl StepResult {
pub fn success(extracted_content: Option<String>) -> Self {
Self {
success: true,
extracted_content,
error: None,
}
}
pub fn failure(error: String) -> Self {
Self {
success: false,
extracted_content: None,
error: Some(error),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionTrace {
pub metadata: TraceMetadata,
pub steps: Vec<StepRecord>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TraceMetadata {
pub started_at: String,
pub ended_at: Option<String>,
pub total_steps: usize,
pub success_count: usize,
pub failure_count: usize,
pub version: String,
}
#[derive(Debug, Clone, Copy)]
pub struct RecorderConfig {
pub max_steps: usize,
pub capture_dom: bool,
pub max_dom_chars: usize,
}
impl Default for RecorderConfig {
fn default() -> Self {
Self {
max_steps: 1000,
capture_dom: true,
max_dom_chars: 50_000,
}
}
}
impl RecorderConfig {
pub fn minimal() -> Self {
Self {
max_steps: 100,
capture_dom: false,
max_dom_chars: 0,
}
}
pub fn debug() -> Self {
Self {
max_steps: 10_000,
capture_dom: true,
max_dom_chars: 0,
}
}
}