localgpt 0.1.3

A local device focused AI assistant with persistent markdown memory, autonomous heartbeat tasks, and semantic search. Single binary, no runtime dependencies.
Documentation
//! WebSocket support for real-time communication
//! TODO: Implement WebSocket endpoints for streaming responses

#![allow(dead_code)]

use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade};
use axum::response::IntoResponse;
use tracing::{debug, info};

/// WebSocket upgrade handler
pub async fn ws_handler(ws: WebSocketUpgrade) -> impl IntoResponse {
    ws.on_upgrade(handle_socket)
}

/// Handle WebSocket connection
async fn handle_socket(mut socket: WebSocket) {
    info!("WebSocket connection established");

    while let Some(msg) = socket.recv().await {
        let msg = match msg {
            Ok(msg) => msg,
            Err(e) => {
                debug!("WebSocket error: {}", e);
                break;
            }
        };

        match msg {
            Message::Text(text) => {
                debug!("Received text: {}", text);

                // Echo for now
                // TODO: Implement proper message handling
                if let Err(e) = socket
                    .send(Message::Text(format!("Echo: {}", text).into()))
                    .await
                {
                    debug!("Failed to send: {}", e);
                    break;
                }
            }
            Message::Binary(data) => {
                debug!("Received binary: {} bytes", data.len());
            }
            Message::Ping(data) => {
                if let Err(e) = socket.send(Message::Pong(data)).await {
                    debug!("Failed to send pong: {}", e);
                    break;
                }
            }
            Message::Pong(_) => {}
            Message::Close(_) => {
                info!("WebSocket closed by client");
                break;
            }
        }
    }

    info!("WebSocket connection closed");
}