//! gRPC interface — high-performance RPC with protobuf. //! //! Uses tonic + prost for gRPC code generation. To enable: //! 1. Add `tonic` and `prost` to Cargo.toml //! 2. Create proto/ directory with service definitions //! 3. Generate code via build.rs //! 4. Implement the generated service traits //! //! Example service: //! ```protobuf //! service Zesdex { //! rpc Chat(ChatRequest) returns (ChatResponse); //! rpc ListSessions(ListSessionsRequest) returns (ListSessionsResponse); //! rpc StreamChat(ChatRequest) returns (stream ChatResponse); //! } //! ``` //! //! For now, this crate provides a minimal HTTP health-check endpoint //! so consumers can verify the gRPC server is reachable. use axum::routing::get; use axum::Router; use std::net::SocketAddr; use std::sync::Arc; use tracing::info; /// gRPC server state (minimal for health checks). pub struct GrpcState { pub version: String, } /// Build the gRPC server router. pub fn build_router(state: Arc) -> Router { Router::new() .route("/grpc/health", get(health_check)) .with_state(state) } /// Health check endpoint. async fn health_check( axum::extract::State(_state): axum::extract::State>, ) -> &'static str { "gRPC server is running" } /// Run the gRPC server (currently HTTP health only; replace with tonic when ready). pub async fn run_server(port: u16) -> anyhow::Result<()> { let state = Arc::new(GrpcState { version: env!("CARGO_PKG_VERSION").to_string(), }); let app = build_router(state); let addr = SocketAddr::from(([0, 0, 0, 0], port)); info!("gRPC server listening on {addr}"); info!("Note: gRPC currently runs HTTP health endpoint. Add tonic+prost for full gRPC."); let listener = tokio::net::TcpListener::bind(addr).await?; axum::serve(listener, app).await?; Ok(()) }