feat: Enhance chat functionality with follow-up message handling
- Added logic to determine the visibility of follow-up messages based on the presence of user and assistant bubbles below the current message. - Updated the AssistantMessageWidget to accept a new parameter `showFollowUps`, allowing for conditional rendering of follow-up messages. - Improved the user experience by ensuring follow-up messages are displayed appropriately based on the chat context.
This commit is contained in:
@@ -869,6 +869,23 @@ class _ChatPageState extends ConsumerState<ChatPage> {
|
|||||||
matchedModel,
|
matchedModel,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var hasUserBubbleBelow = false;
|
||||||
|
var hasAssistantBubbleBelow = false;
|
||||||
|
for (var i = index + 1; i < messages.length; i++) {
|
||||||
|
final role = messages[i].role;
|
||||||
|
if (role == 'user') {
|
||||||
|
hasUserBubbleBelow = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (role == 'assistant') {
|
||||||
|
hasAssistantBubbleBelow = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final showFollowUps =
|
||||||
|
!isUser && !hasUserBubbleBelow && !hasAssistantBubbleBelow;
|
||||||
|
|
||||||
// Wrap message in selection container if in selection mode
|
// Wrap message in selection container if in selection mode
|
||||||
Widget messageWidget;
|
Widget messageWidget;
|
||||||
|
|
||||||
@@ -888,6 +905,7 @@ class _ChatPageState extends ConsumerState<ChatPage> {
|
|||||||
key: ValueKey('assistant-${message.id}'),
|
key: ValueKey('assistant-${message.id}'),
|
||||||
message: message,
|
message: message,
|
||||||
isStreaming: isStreaming,
|
isStreaming: isStreaming,
|
||||||
|
showFollowUps: showFollowUps,
|
||||||
modelName: displayModelName,
|
modelName: displayModelName,
|
||||||
modelIconUrl: modelIconUrl,
|
modelIconUrl: modelIconUrl,
|
||||||
onCopy: () => _copyMessage(message.content),
|
onCopy: () => _copyMessage(message.content),
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ final _fileIdPattern = RegExp(r'/api/v1/files/([^/]+)/content');
|
|||||||
class AssistantMessageWidget extends ConsumerStatefulWidget {
|
class AssistantMessageWidget extends ConsumerStatefulWidget {
|
||||||
final dynamic message;
|
final dynamic message;
|
||||||
final bool isStreaming;
|
final bool isStreaming;
|
||||||
|
final bool showFollowUps;
|
||||||
final String? modelName;
|
final String? modelName;
|
||||||
final String? modelIconUrl;
|
final String? modelIconUrl;
|
||||||
final VoidCallback? onCopy;
|
final VoidCallback? onCopy;
|
||||||
@@ -56,6 +57,7 @@ class AssistantMessageWidget extends ConsumerStatefulWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.message,
|
required this.message,
|
||||||
this.isStreaming = false,
|
this.isStreaming = false,
|
||||||
|
this.showFollowUps = true,
|
||||||
this.modelName,
|
this.modelName,
|
||||||
this.modelIconUrl,
|
this.modelIconUrl,
|
||||||
this.onCopy,
|
this.onCopy,
|
||||||
@@ -608,7 +610,9 @@ class _AssistantMessageWidgetState extends ConsumerState<AssistantMessageWidget>
|
|||||||
final hasStatusTimeline = visibleStatusHistory.isNotEmpty;
|
final hasStatusTimeline = visibleStatusHistory.isNotEmpty;
|
||||||
final hasCodeExecutions = widget.message.codeExecutions.isNotEmpty;
|
final hasCodeExecutions = widget.message.codeExecutions.isNotEmpty;
|
||||||
final hasFollowUps =
|
final hasFollowUps =
|
||||||
widget.message.followUps.isNotEmpty && !widget.isStreaming;
|
widget.showFollowUps &&
|
||||||
|
widget.message.followUps.isNotEmpty &&
|
||||||
|
!widget.isStreaming;
|
||||||
final hasSources = widget.message.sources.isNotEmpty;
|
final hasSources = widget.message.sources.isNotEmpty;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
|
|||||||
Reference in New Issue
Block a user