Skip to main content

openclaw_gateway/
lib.rs

1//! # `OpenClaw` Gateway
2//!
3//! HTTP/WebSocket gateway server with JSON-RPC protocol.
4
5#![forbid(unsafe_code)]
6#![warn(missing_docs)]
7
8/// Authentication and authorization.
9pub mod auth;
10/// WebSocket UI events.
11pub mod events;
12mod middleware;
13/// JSON-RPC protocol types and constants.
14pub mod rpc;
15mod server;
16
17/// UI static file server (requires "ui" feature).
18#[cfg(feature = "ui")]
19pub mod ui_server;
20
21pub use auth::{AuthConfig, AuthError, AuthState, User, UserRole, UserStore};
22pub use events::{EventBroadcaster, UiEvent, UiEventEnvelope};
23pub use middleware::GatewayRateLimiter;
24pub use rpc::{RpcError, RpcRequest, RpcResponse};
25pub use server::{Gateway, GatewayBuilder, GatewayConfig, GatewayState};
26
27#[cfg(feature = "ui")]
28pub use ui_server::UiServerConfig;
29
30/// Start the gateway server.
31///
32/// # Errors
33///
34/// Returns error if server fails to start.
35pub async fn start(config: GatewayConfig) -> Result<(), GatewayError> {
36    let gateway = Gateway::new(config)?;
37    gateway.run().await
38}
39
40/// Gateway errors.
41#[derive(Debug, thiserror::Error)]
42pub enum GatewayError {
43    /// Server error.
44    #[error("Server error: {0}")]
45    Server(String),
46
47    /// Configuration error.
48    #[error("Config error: {0}")]
49    Config(String),
50
51    /// IO error.
52    #[error("IO error: {0}")]
53    Io(#[from] std::io::Error),
54}