rsclaw 0.0.1-alpha.1

rsclaw: High-performance AI agent (BETA). Optimized for M4 Max and 2GB VPS. 100% compatible with openclaw
Documentation
#[allow(unused_imports)]
pub mod routes;

use crate::gateway::Gateway;
use axum::Router;
use std::net::SocketAddr;
use std::sync::Arc;

/// HTTP server for serving the API.
pub struct Server {
    gateway: Arc<Gateway>,
    addr: SocketAddr,
}

impl Server {
    /// Create a new server.
    pub fn new(gateway: Gateway, host: &str, port: u16) -> Self {
        let addr: SocketAddr = format!("{}:{}", host, port)
            .parse()
            .expect("Invalid address");

        Self {
            gateway: Arc::new(gateway),
            addr,
        }
    }

    /// Build the Axum router.
    pub fn build_router(&self) -> Router {
        let channels = self.gateway.channels();
        let http_channel = channels.http();

        http_channel.build_router()
    }

    /// Start the server.
    pub async fn start(self) -> anyhow::Result<()> {
        let router = self.build_router();

        tracing::info!("Starting server on {}", self.addr);
        println!("Starting rsclaw gateway on {}", self.addr);

        let listener = tokio::net::TcpListener::bind(self.addr).await?;
        axum::serve(listener, router).await?;

        Ok(())
    }

    /// Get the server address.
    pub fn addr(&self) -> SocketAddr {
        self.addr
    }
}