diff --git a/src-tauri/src/networking/astrbot_client.rs b/src-tauri/src/networking/astrbot_client.rs index 16be14d..8b4ab03 100644 --- a/src-tauri/src/networking/astrbot_client.rs +++ b/src-tauri/src/networking/astrbot_client.rs @@ -614,6 +614,7 @@ impl AstrBotClient { .await; } while let Some(line) = buffer.next_line() { + trace_frame_shape(&line); match mapper.push_line(&line) { Ok(events) => self.dispatch_events(events, sender).await?, Err(error) => { @@ -632,6 +633,7 @@ impl AstrBotClient { } if let Some(remainder) = buffer.take_remainder() { + trace_frame_shape(&remainder); match mapper.push_line(&remainder) { Ok(events) => self.dispatch_events(events, sender).await?, Err(error) => { @@ -720,6 +722,56 @@ impl AstrBotClient { } } +/// Records the *shape* of one SSE frame at debug level. +/// +/// Deliberately logs no payload text — only the frame type, which identity +/// fields are present, and the key names inside `data`. That is enough to +/// answer the two questions the mapper cannot answer on its own: whether every +/// streaming frame carries a `message_id` (if not, the client cannot key a +/// reply to a single message and splits it), and what shape a plugin's +/// attachment frames actually take. +/// +/// Enable with `RUST_LOG=astrbot_desktop=debug`. Off by default. +fn trace_frame_shape(line: &str) { + if !tracing::enabled!(tracing::Level::DEBUG) { + return; + } + let Some(body) = line.strip_prefix("data:") else { + return; + }; + let Ok(value) = serde_json::from_str::(body.trim()) else { + return; + }; + let data = value.get("data"); + let data_keys = match data { + Some(Value::Object(map)) => map.keys().cloned().collect::>().join(","), + Some(Value::Array(_)) => "".to_owned(), + Some(Value::String(_)) => "".to_owned(), + Some(Value::Null) | None => "".to_owned(), + Some(_) => "".to_owned(), + }; + let frame_type = value + .get("type") + .and_then(|field| field.as_str()) + .unwrap_or(""); + let has_message_id = value + .get("message_id") + .is_some_and(|field| !field.is_null()); + let has_session_id = value + .get("session_id") + .is_some_and(|field| !field.is_null()); + let streaming = value.get("streaming").and_then(|field| field.as_bool()); + tracing::debug!( + target: "astrbot::frame", + frame_type, + has_message_id, + has_session_id, + ?streaming, + data_keys = data_keys.as_str(), + "astrbot sse frame" + ); +} + fn protocol_slot(slot: SlotKind) -> desktop_protocol::ActiveSlotKind { match slot { SlotKind::Companion => desktop_protocol::ActiveSlotKind::Companion,