feat(core): Introduce Message enum for async communication

This commit is contained in:
2025-12-26 19:08:16 +01:00
parent abbda81659
commit b0e65e4041
6 changed files with 162 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
mod commands;
mod messages;
use clap::{Parser, ValueEnum};
use color_eyre::eyre::{Result, eyre};

View File

@@ -0,0 +1,49 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Message {
UserAction(UserAction),
AgentResponse(AgentResponse),
System(SystemNotification),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UserAction {
Input(String),
Command(String),
Exit,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AgentResponse {
Token(String),
ToolCall { name: String, args: String },
Complete,
Error(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SystemNotification {
StateUpdate(String),
Warning(String),
}
#[cfg(test)]
mod tests {
use super::*;
use tokio::sync::mpsc;
#[tokio::test]
async fn test_message_channel() {
let (tx, mut rx) = mpsc::channel(32);
let msg = Message::UserAction(UserAction::Input("Hello".to_string()));
tx.send(msg).await.unwrap();
let received = rx.recv().await.unwrap();
match received {
Message::UserAction(UserAction::Input(s)) => assert_eq!(s, "Hello"),
_ => panic!("Wrong message type"),
}
}
}