From bc7bfa0692f0c7a1c99607f4112eecb6a60b34d5 Mon Sep 17 00:00:00 2001 From: qzl Date: Sat, 28 Feb 2026 13:36:08 +0800 Subject: [PATCH] feat(chat): add ChatListItem models in chat feature --- .../chat/data/models/chat_list_item.dart | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 apps/lib/features/chat/data/models/chat_list_item.dart diff --git a/apps/lib/features/chat/data/models/chat_list_item.dart b/apps/lib/features/chat/data/models/chat_list_item.dart new file mode 100644 index 0000000..48d92ff --- /dev/null +++ b/apps/lib/features/chat/data/models/chat_list_item.dart @@ -0,0 +1,120 @@ +import 'tool_result.dart'; + +enum ChatItemType { message, toolCall, toolResult } + +enum MessageSender { user, ai } + +enum ToolCallStatus { pending, executing, completed, error } + +abstract class ChatListItem { + String get id; + DateTime get timestamp; + ChatItemType get type; + MessageSender get sender; +} + +class TextMessageItem extends ChatListItem { + @override + final String id; + final String content; + @override + final DateTime timestamp; + @override + final MessageSender sender; + final bool isStreaming; + + TextMessageItem({ + required this.id, + required this.content, + required this.timestamp, + required this.sender, + this.isStreaming = false, + }); + + @override + ChatItemType get type => ChatItemType.message; + + TextMessageItem copyWith({ + String? id, + String? content, + DateTime? timestamp, + MessageSender? sender, + bool? isStreaming, + }) => TextMessageItem( + id: id ?? this.id, + content: content ?? this.content, + timestamp: timestamp ?? this.timestamp, + sender: sender ?? this.sender, + isStreaming: isStreaming ?? this.isStreaming, + ); +} + +class ToolCallItem extends ChatListItem { + @override + final String id; + final String callId; + final String toolName; + final Map args; + final ToolCallStatus status; + final String? errorMessage; + @override + final DateTime timestamp; + @override + final MessageSender sender; + + ToolCallItem({ + required this.id, + required this.callId, + required this.toolName, + required this.args, + required this.status, + this.errorMessage, + required this.timestamp, + required this.sender, + }); + + @override + ChatItemType get type => ChatItemType.toolCall; + + ToolCallItem copyWith({ + String? id, + String? callId, + String? toolName, + Map? args, + ToolCallStatus? status, + String? errorMessage, + DateTime? timestamp, + MessageSender? sender, + }) => ToolCallItem( + id: id ?? this.id, + callId: callId ?? this.callId, + toolName: toolName ?? this.toolName, + args: args ?? this.args, + status: status ?? this.status, + errorMessage: errorMessage ?? this.errorMessage, + timestamp: timestamp ?? this.timestamp, + sender: sender ?? this.sender, + ); +} + +class ToolResultItem extends ChatListItem { + @override + final String id; + final String callId; + final UiCard uiCard; + @override + final DateTime timestamp; + @override + final MessageSender sender; + + ToolResultItem({ + required this.id, + required this.callId, + required this.uiCard, + required this.timestamp, + required this.sender, + }); + + @override + ChatItemType get type => ChatItemType.toolResult; +}