Skip to main content

rpc_agent/
message.rs

1use std::fmt::Display;
2
3use serde_json::Value;
4
5/// Represents a message to be sent to the AI provider.
6#[derive(Debug, serde::Serialize, serde::Deserialize)]
7pub enum Message {
8    Text(String),
9    Struct(Value),
10}
11
12impl Display for Message {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            Message::Text(text) => write!(f, "{text}"),
16            Message::Struct(value) => {
17                if let Ok(json) = serde_json::to_string_pretty(value) {
18                    write!(f, "{json}")
19                } else {
20                    write!(f, "{:?}", value)
21                }
22            }
23        }
24    }
25}