From c4580561994803a5419e2fca12f3ae2b33b2571e Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Sat, 27 Sep 2025 20:17:58 +0530 Subject: [PATCH] fix: followups on 2nd response --- lib/core/services/streaming_helper.dart | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/core/services/streaming_helper.dart b/lib/core/services/streaming_helper.dart index 085d5a1..3cfd9ee 100644 --- a/lib/core/services/streaming_helper.dart +++ b/lib/core/services/streaming_helper.dart @@ -443,6 +443,16 @@ ActiveSocketStream attachUnifiedChunkedStreaming({ final data = ev['data']; if (data == null) return; final type = data['type']; + + // Basic logging to see if chat events are being received + if (type != null && + (type.toString().contains('follow') || + type == 'chat:message:follow_ups')) { + DebugLogger.log( + 'Chat event received: $type', + scope: 'streaming/helper', + ); + } final payload = data['data']; final messageId = ev['message_id']?.toString(); socketWatchdog?.ping(); @@ -653,19 +663,38 @@ ActiveSocketStream attachUnifiedChunkedStreaming({ disposeSocketSubscriptions(); finishStreaming(); } else if (type == 'chat:message:follow_ups' && payload != null) { + DebugLogger.log('Received follow-ups event', scope: 'streaming/helper'); final followMap = _asStringMap(payload); if (followMap != null) { final followUpsRaw = followMap['follow_ups'] ?? followMap['followUps']; final suggestions = _parseFollowUpsField(followUpsRaw); final targetId = _resolveTargetMessageId(messageId, getMessages); + DebugLogger.log( + 'Follow-ups: ${suggestions.length} suggestions for message $targetId', + scope: 'streaming/helper', + ); if (targetId != null) { setFollowUps(targetId, suggestions); updateMessageById(targetId, (current) { final metadata = {...?current.metadata, 'followUps': suggestions}; return current.copyWith(metadata: metadata); }); + DebugLogger.log( + 'Follow-ups set successfully', + scope: 'streaming/helper', + ); + } else { + DebugLogger.log( + 'Follow-ups: targetId is null', + scope: 'streaming/helper', + ); } + } else { + DebugLogger.log( + 'Follow-ups: failed to parse payload', + scope: 'streaming/helper', + ); } } else if (type == 'chat:title' && payload != null) { final title = payload.toString(); @@ -908,6 +937,14 @@ ActiveSocketStream attachUnifiedChunkedStreaming({ appendToLastMessage(content); updateImagesFromCurrentContent(); } + } else { + // Log unknown event types to catch any follow-up events we might be missing + if (type != null && type.toString().contains('follow')) { + DebugLogger.log( + 'Unknown follow-up related event: $type', + scope: 'streaming/helper', + ); + } } } catch (_) {} } @@ -927,6 +964,14 @@ ActiveSocketStream attachUnifiedChunkedStreaming({ appendToLastMessage(content); updateImagesFromCurrentContent(); } + } else { + // Log channel events that might include follow-ups + if (type != null && type.toString().contains('follow')) { + DebugLogger.log( + 'Channel follow-up event: $type', + scope: 'streaming/helper', + ); + } } } catch (_) {} }