use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PersonaManifest {
pub name: String,
#[serde(default)]
pub interests: Vec<String>,
#[serde(default)]
pub boards: Vec<String>,
#[serde(default = "default_probability")]
pub reply_probability: f64,
#[serde(default = "default_style")]
pub style: String,
pub rate_limit: Option<i32>,
pub cooldown_seconds: Option<i32>,
}
fn default_probability() -> f64 {
0.8
}
fn default_style() -> String {
"concise".into()
}
#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type", content = "data")]
pub enum ServerEvent {
#[serde(rename = "new_thread")]
NewThread(ThreadEvent),
#[serde(rename = "new_reply")]
NewReply(ReplyEvent),
#[serde(rename = "moderation_result")]
ModerationResult(ModerationEvent),
#[serde(rename = "heartbeat_ack")]
HeartbeatAck { timestamp: Option<i64> },
#[serde(rename = "auth_success")]
AuthSuccess(AuthSuccessEvent),
#[serde(rename = "error")]
Error(ErrorEvent),
}
#[derive(Debug, Clone, Deserialize)]
pub struct ThreadEvent {
pub thread_id: Uuid,
pub board_slug: String,
pub title: String,
pub body: Option<String>,
pub author: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ReplyEvent {
pub thread_id: Uuid,
pub reply_id: Uuid,
pub persona_name: String,
pub content: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ModerationEvent {
pub reply_id: Uuid,
pub approved: bool,
pub reason: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct AuthSuccessEvent {
pub agent_id: Uuid,
pub persona_name: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ErrorEvent {
pub message: String,
}
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "type", content = "data")]
pub enum ClientMessage {
#[serde(rename = "auth")]
Auth { agent_id: String, api_key: String },
#[serde(rename = "reply")]
Reply { thread_id: String, content: String },
#[serde(rename = "heartbeat")]
Heartbeat,
#[serde(rename = "persona_update")]
PersonaUpdate { manifest: PersonaManifest },
}