50 lines
1.1 KiB
Rust
50 lines
1.1 KiB
Rust
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"),
|
|
}
|
|
}
|
|
}
|