rsclaw 0.0.1-alpha.1

rsclaw: High-performance AI agent (BETA). Optimized for M4 Max and 2GB VPS. 100% compatible with openclaw
Documentation
use serde::{Deserialize, Serialize};
use std::sync::Arc;

/// Channel type identifier.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ChannelType {
    Http,
    WebSocket,
    Cli,
    Telegram,
    Discord,
    Slack,
}

impl std::fmt::Display for ChannelType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ChannelType::Http => write!(f, "http"),
            ChannelType::WebSocket => write!(f, "websocket"),
            ChannelType::Cli => write!(f, "cli"),
            ChannelType::Telegram => write!(f, "telegram"),
            ChannelType::Discord => write!(f, "discord"),
            ChannelType::Slack => write!(f, "slack"),
        }
    }
}

/// Unified inbound message from any channel.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InboundMessage {
    pub text: Arc<str>,
    pub session_id: Arc<str>,
    pub channel: ChannelType,
    pub user_id: Option<Arc<str>>,
    pub metadata: Option<serde_json::Value>,
}

/// Unified outbound message to any channel.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutboundMessage {
    pub text: Arc<str>,
    pub status: MessageStatus,
    pub error: Option<Arc<str>>,
    pub metadata: Option<serde_json::Value>,
}

/// Message status.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum MessageStatus {
    Ok,
    Error,
    Pending,
}

impl OutboundMessage {
    /// Create a success response.
    pub fn ok(text: impl Into<Arc<str>>) -> Self {
        Self {
            text: text.into(),
            status: MessageStatus::Ok,
            error: None,
            metadata: None,
        }
    }

    /// Create an error response.
    pub fn error(message: impl Into<Arc<str>>) -> Self {
        Self {
            text: Arc::from(""),
            status: MessageStatus::Error,
            error: Some(message.into()),
            metadata: None,
        }
    }
}

/// Channel lifecycle events.
#[derive(Debug, Clone)]
pub enum ChannelEvent {
    Connect { session_id: Arc<str> },
    Message { message: InboundMessage },
    Close { session_id: Arc<str> },
}

/// Health check response.
#[derive(Debug, Serialize)]
pub struct HealthResponse {
    pub status: Arc<str>,
    pub version: Arc<str>,
    pub uptime_secs: u64,
}

impl Default for HealthResponse {
    fn default() -> Self {
        Self {
            status: Arc::from("ok"),
            version: Arc::from(env!("CARGO_PKG_VERSION")),
            uptime_secs: 0,
        }
    }
}