@@ -4,6 +4,7 @@ use axum::{
44 response:: { IntoResponse , Response } ,
55} ;
66use futures:: { SinkExt , StreamExt } ;
7+ use serde_json:: Value ;
78use std:: { collections:: HashMap , sync:: Arc } ;
89use tokio:: sync:: { mpsc, RwLock } ;
910use tokio_util:: compat:: { TokioAsyncReadCompatExt , TokioAsyncWriteCompatExt } ;
@@ -134,7 +135,10 @@ pub(crate) async fn handle_ws(socket: WebSocket, state: Arc<WsState>, connection
134135 match msg_result {
135136 Ok ( Message :: Text ( text) ) => {
136137 let text_str = text. to_string( ) ;
137- debug!( connection_id = %connection_id, "Client → Agent: {} bytes" , text_str. len( ) ) ;
138+ if let Ok ( parsed) = serde_json:: from_str:: <Value >( & text_str) {
139+ let method = parsed. get( "method" ) . and_then( |m| m. as_str( ) ) . unwrap_or( "<response>" ) ;
140+ info!( connection_id = %connection_id, method = method, "WS client → agent: {}" , method) ;
141+ }
138142 if let Err ( e) = to_agent. send( text_str) . await {
139143 error!( connection_id = %connection_id, "Failed to send to agent: {}" , e) ;
140144 break ;
@@ -157,7 +161,15 @@ pub(crate) async fn handle_ws(socket: WebSocket, state: Arc<WsState>, connection
157161 }
158162
159163 Some ( text) = from_agent_rx. recv( ) => {
160- debug!( connection_id = %connection_id, "Agent → Client: {} bytes" , text. len( ) ) ;
164+ if let Ok ( parsed) = serde_json:: from_str:: <Value >( & text) {
165+ let method = parsed. get( "method" ) . and_then( |m| m. as_str( ) ) ;
166+ let id = parsed. get( "id" ) . map( |id| id. to_string( ) ) ;
167+ if let Some ( m) = method {
168+ info!( connection_id = %connection_id, method = m, "WS agent → client: {}" , m) ;
169+ } else if id. is_some( ) {
170+ info!( connection_id = %connection_id, id = id. as_deref( ) . unwrap_or( "" ) , "WS agent → client: response" ) ;
171+ }
172+ }
161173 if let Err ( e) = ws_tx. send( Message :: Text ( text. into( ) ) ) . await {
162174 error!( connection_id = %connection_id, "Failed to send to client: {}" , e) ;
163175 break ;
0 commit comments