use tokio::sync::mpsc;
#[derive(Debug, Clone)]
pub enum TelemetryEvent {
EnergyUpdate {
node_id: String,
energy: f32,
components: EnergyComponents,
},
TaskStatusChange {
node_id: String,
status: TaskStatus,
goal: String,
},
TokensUsed { count: usize, total: usize },
Log(LogEntry),
SessionState(SessionState),
}
#[derive(Debug, Clone, Default)]
pub struct EnergyComponents {
pub v_syn: f32,
pub v_str: f32,
pub v_log: f32,
pub v_boot: f32,
pub v_sheaf: f32,
pub total: f32,
}
impl EnergyComponents {
pub fn new(v_syn: f32, v_str: f32, v_log: f32, alpha: f32, beta: f32, gamma: f32) -> Self {
Self {
v_syn,
v_str,
v_log,
v_boot: 0.0,
v_sheaf: 0.0,
total: alpha * v_syn + beta * v_str + gamma * v_log,
}
}
pub fn is_stable(&self, epsilon: f32) -> bool {
self.total < epsilon
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TaskStatus {
Pending,
Running,
Verifying,
Completed,
Failed,
Escalated,
}
impl TaskStatus {
pub fn icon(&self) -> &'static str {
match self {
TaskStatus::Pending => "○",
TaskStatus::Running => "◐",
TaskStatus::Verifying => "◑",
TaskStatus::Completed => "●",
TaskStatus::Failed => "✗",
TaskStatus::Escalated => "⚠",
}
}
pub fn as_str(&self) -> &'static str {
match self {
TaskStatus::Pending => "pending",
TaskStatus::Running => "running",
TaskStatus::Verifying => "verifying",
TaskStatus::Completed => "completed",
TaskStatus::Failed => "failed",
TaskStatus::Escalated => "escalated",
}
}
}
#[derive(Debug, Clone)]
pub struct LogEntry {
pub level: LogLevel,
pub message: String,
pub timestamp: std::time::Instant,
}
impl LogEntry {
pub fn info(message: impl Into<String>) -> Self {
Self {
level: LogLevel::Info,
message: message.into(),
timestamp: std::time::Instant::now(),
}
}
pub fn warning(message: impl Into<String>) -> Self {
Self {
level: LogLevel::Warning,
message: message.into(),
timestamp: std::time::Instant::now(),
}
}
pub fn error(message: impl Into<String>) -> Self {
Self {
level: LogLevel::Error,
message: message.into(),
timestamp: std::time::Instant::now(),
}
}
pub fn success(message: impl Into<String>) -> Self {
Self {
level: LogLevel::Success,
message: message.into(),
timestamp: std::time::Instant::now(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
Info,
Warning,
Error,
Success,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SessionState {
Planning,
Executing,
Paused,
Completed,
Failed,
}
pub type TelemetrySender = mpsc::UnboundedSender<TelemetryEvent>;
pub type TelemetryReceiver = mpsc::UnboundedReceiver<TelemetryEvent>;
pub fn create_telemetry_channel() -> (TelemetrySender, TelemetryReceiver) {
mpsc::unbounded_channel()
}