diff --git a/src-tauri/src/networking/astrbot_client.rs b/src-tauri/src/networking/astrbot_client.rs index b3db220..e962475 100644 --- a/src-tauri/src/networking/astrbot_client.rs +++ b/src-tauri/src/networking/astrbot_client.rs @@ -765,6 +765,23 @@ fn trace_frame_shape(line: &str) { let has_message_id = value .get("message_id") .is_some_and(|field| !field.is_null()); + // The *value* decides whether a reply that renders as two bubbles is one + // message the client split, or two messages the server sent. It is an + // opaque row identifier, not content. + let message_id = value + .get("message_id") + .and_then(|field| match field { + Value::String(text) => Some(text.clone()), + Value::Number(number) => Some(number.to_string()), + _ => None, + }) + .unwrap_or_else(|| "".to_owned()); + // Length only. Distinguishes "the server streamed many small chunks" from + // "the server sent the whole reply at once" without recording any text. + let data_len = match value.get("data") { + Some(Value::String(text)) => text.chars().count(), + _ => 0, + }; let has_session_id = value .get("session_id") .is_some_and(|field| !field.is_null()); @@ -773,9 +790,11 @@ fn trace_frame_shape(line: &str) { target: FRAME_TRACE_TARGET, frame_type, has_message_id, + message_id = message_id.as_str(), has_session_id, ?streaming, data_keys = data_keys.as_str(), + data_len, "astrbot sse frame" ); } @@ -898,6 +917,10 @@ mod tests { ); assert!(output.contains("frame_type=\"plain\"")); assert!(output.contains("has_message_id=true")); + // The value, and the chunk length, are what separate "one message the + // client split" from "two messages the server sent". + assert!(output.contains("message_id=\"42\"")); + assert!(output.contains("data_len=2")); assert!(output.contains("frame_type=\"image\"")); // The key names are what identify the plugin attachment shape. assert!(output.contains("data_keys=\"url\""));