use crate::agent::AgentId;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MessageKind {
Prompt,
Critique,
Rebuttal,
Question,
Concession,
Verdict,
}
impl MessageKind {
pub fn label(&self) -> &'static str {
match self {
MessageKind::Prompt => "prompt",
MessageKind::Critique => "critique",
MessageKind::Rebuttal => "rebuttal",
MessageKind::Question => "question",
MessageKind::Concession => "concession",
MessageKind::Verdict => "verdict",
}
}
pub fn from_label(text: &str) -> Result<Self, &'static str> {
match text {
"prompt" => Ok(MessageKind::Prompt),
"critique" => Ok(MessageKind::Critique),
"rebuttal" => Ok(MessageKind::Rebuttal),
"question" => Ok(MessageKind::Question),
"concession" => Ok(MessageKind::Concession),
"verdict" => Ok(MessageKind::Verdict),
other => {
let _ = other;
Err("unknown message kind")
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Message {
sender: AgentId,
recipient: Option<AgentId>,
kind: MessageKind,
text: String,
}
impl Message {
pub fn new(
sender: AgentId,
recipient: Option<AgentId>,
kind: MessageKind,
text: impl Into<String>,
) -> Self {
Self {
sender,
recipient,
kind,
text: text.into(),
}
}
pub fn sender(&self) -> &AgentId {
&self.sender
}
pub fn recipient(&self) -> Option<&AgentId> {
self.recipient.as_ref()
}
pub fn kind(&self) -> MessageKind {
self.kind
}
pub fn text(&self) -> &str {
&self.text
}
}