fix: followups on 2nd response
This commit is contained in:
@@ -443,6 +443,16 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
|
|||||||
final data = ev['data'];
|
final data = ev['data'];
|
||||||
if (data == null) return;
|
if (data == null) return;
|
||||||
final type = data['type'];
|
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 payload = data['data'];
|
||||||
final messageId = ev['message_id']?.toString();
|
final messageId = ev['message_id']?.toString();
|
||||||
socketWatchdog?.ping();
|
socketWatchdog?.ping();
|
||||||
@@ -653,19 +663,38 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
|
|||||||
disposeSocketSubscriptions();
|
disposeSocketSubscriptions();
|
||||||
finishStreaming();
|
finishStreaming();
|
||||||
} else if (type == 'chat:message:follow_ups' && payload != null) {
|
} else if (type == 'chat:message:follow_ups' && payload != null) {
|
||||||
|
DebugLogger.log('Received follow-ups event', scope: 'streaming/helper');
|
||||||
final followMap = _asStringMap(payload);
|
final followMap = _asStringMap(payload);
|
||||||
if (followMap != null) {
|
if (followMap != null) {
|
||||||
final followUpsRaw =
|
final followUpsRaw =
|
||||||
followMap['follow_ups'] ?? followMap['followUps'];
|
followMap['follow_ups'] ?? followMap['followUps'];
|
||||||
final suggestions = _parseFollowUpsField(followUpsRaw);
|
final suggestions = _parseFollowUpsField(followUpsRaw);
|
||||||
final targetId = _resolveTargetMessageId(messageId, getMessages);
|
final targetId = _resolveTargetMessageId(messageId, getMessages);
|
||||||
|
DebugLogger.log(
|
||||||
|
'Follow-ups: ${suggestions.length} suggestions for message $targetId',
|
||||||
|
scope: 'streaming/helper',
|
||||||
|
);
|
||||||
if (targetId != null) {
|
if (targetId != null) {
|
||||||
setFollowUps(targetId, suggestions);
|
setFollowUps(targetId, suggestions);
|
||||||
updateMessageById(targetId, (current) {
|
updateMessageById(targetId, (current) {
|
||||||
final metadata = {...?current.metadata, 'followUps': suggestions};
|
final metadata = {...?current.metadata, 'followUps': suggestions};
|
||||||
return current.copyWith(metadata: metadata);
|
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) {
|
} else if (type == 'chat:title' && payload != null) {
|
||||||
final title = payload.toString();
|
final title = payload.toString();
|
||||||
@@ -908,6 +937,14 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
|
|||||||
appendToLastMessage(content);
|
appendToLastMessage(content);
|
||||||
updateImagesFromCurrentContent();
|
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 (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
@@ -927,6 +964,14 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
|
|||||||
appendToLastMessage(content);
|
appendToLastMessage(content);
|
||||||
updateImagesFromCurrentContent();
|
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 (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user