use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum MessageKind {
Plan { sub_tasks: Vec<String> },
Question { text: String },
Result { output: String, success: bool },
Critique { score: f64, feedback: String },
Status { message: String },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeamMessage {
pub from: String,
pub to: String,
pub kind: MessageKind,
pub seq: u64,
pub in_reply_to: Option<u64>,
}
impl TeamMessage {
pub fn new(from: &str, to: &str, kind: MessageKind, seq: u64) -> Self {
Self {
from: from.into(),
to: to.into(),
kind,
seq,
in_reply_to: None,
}
}
pub fn reply_to(&self, kind: MessageKind, seq: u64) -> Self {
Self {
from: self.to.clone(),
to: self.from.clone(),
kind,
seq,
in_reply_to: Some(self.seq),
}
}
pub fn to_json(&self) -> String {
serde_json::to_string(self).unwrap_or_default()
}
pub fn from_json(json: &str) -> Option<Self> {
serde_json::from_str(json).ok()
}
}