use nexo_tool_meta::admin::agent_events::AgentEventKind;
pub trait EventMetadata {
fn kind(&self) -> &str;
fn agent_id(&self) -> &str;
fn tenant_id(&self) -> Option<&str> {
None
}
fn at_ms(&self) -> u64;
}
impl EventMetadata for AgentEventKind {
fn kind(&self) -> &str {
match self {
AgentEventKind::TranscriptAppended { .. } => "transcript_appended",
AgentEventKind::PendingInboundsDropped { .. } => "pending_inbounds_dropped",
AgentEventKind::EscalationRequested { .. } => "escalation_requested",
AgentEventKind::EscalationResolved { .. } => "escalation_resolved",
AgentEventKind::ProcessingStateChanged { .. } => "processing_state_changed",
_ => "unknown",
}
}
fn agent_id(&self) -> &str {
match self {
AgentEventKind::TranscriptAppended { agent_id, .. }
| AgentEventKind::PendingInboundsDropped { agent_id, .. }
| AgentEventKind::EscalationRequested { agent_id, .. }
| AgentEventKind::EscalationResolved { agent_id, .. }
| AgentEventKind::ProcessingStateChanged { agent_id, .. } => agent_id,
_ => "",
}
}
fn tenant_id(&self) -> Option<&str> {
match self {
AgentEventKind::TranscriptAppended { tenant_id, .. }
| AgentEventKind::EscalationRequested { tenant_id, .. }
| AgentEventKind::EscalationResolved { tenant_id, .. }
| AgentEventKind::ProcessingStateChanged { tenant_id, .. } => tenant_id.as_deref(),
_ => None,
}
}
fn at_ms(&self) -> u64 {
match self {
AgentEventKind::TranscriptAppended { sent_at_ms, .. } => *sent_at_ms,
AgentEventKind::PendingInboundsDropped { at_ms, .. } => *at_ms,
AgentEventKind::EscalationRequested {
requested_at_ms, ..
} => *requested_at_ms,
AgentEventKind::EscalationResolved { resolved_at_ms, .. } => *resolved_at_ms,
AgentEventKind::ProcessingStateChanged { at_ms, .. } => *at_ms,
_ => 0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use nexo_tool_meta::admin::agent_events::TranscriptRole;
use uuid::Uuid;
#[test]
fn agent_event_kind_metadata_round_trips() {
let evt = AgentEventKind::TranscriptAppended {
agent_id: "ana".into(),
session_id: Uuid::nil(),
seq: 0,
role: TranscriptRole::User,
body: "hi".into(),
sent_at_ms: 1_700_000_000_000,
sender_id: None,
source_plugin: "whatsapp".into(),
tenant_id: Some("acme".into()),
};
assert_eq!(evt.kind(), "transcript_appended");
assert_eq!(evt.agent_id(), "ana");
assert_eq!(evt.tenant_id(), Some("acme"));
assert_eq!(evt.at_ms(), 1_700_000_000_000);
}
}