use serde::{Deserialize, Serialize};
use std::time::SystemTime;
pub const AGENT_EVENT_RECORD_SCHEMA_VERSION: u16 = 1;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RedactionRecord {
pub field: String,
pub reason: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum EventSeverity {
Trace,
Debug,
Info,
Warn,
Error,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AgentEventRecord {
pub schema_version: u16,
pub run_id: Option<String>,
pub sequence: Option<u64>,
pub timestamp: SystemTime,
pub name: String,
pub severity: EventSeverity,
pub payload: serde_json::Value,
pub redactions: Vec<RedactionRecord>,
}
impl AgentEventRecord {
pub fn new(
name: impl Into<String>,
severity: EventSeverity,
payload: serde_json::Value,
) -> Self {
Self {
schema_version: AGENT_EVENT_RECORD_SCHEMA_VERSION,
run_id: None,
sequence: None,
timestamp: SystemTime::now(),
name: name.into(),
severity,
payload,
redactions: Vec::new(),
}
}
pub fn with_run_id(mut self, run_id: impl Into<String>) -> Self {
self.run_id = Some(run_id.into());
self
}
pub fn with_sequence(mut self, sequence: u64) -> Self {
self.sequence = Some(sequence);
self
}
pub fn with_redactions(mut self, redactions: Vec<RedactionRecord>) -> Self {
self.redactions = redactions;
self
}
}