mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
Backend fixes: - Fix duplicate AssistantResponseJob triggering causing duplicate AI responses - UserMessage model already handles job triggering via after_create_commit callback - Remove redundant job enqueue in chats_controller and messages_controller Mobile app features: - Implement complete AI chat interface and conversation management - Add Chat, Message, and ToolCall data models - Add ChatProvider for state management with polling mechanism - Add ChatService to handle all chat-related API requests - Add chat list screen (ChatListScreen) - Add conversation detail screen (ChatConversationScreen) - Refactor navigation structure with bottom navigation bar (MainNavigationScreen) - Add settings screen (SettingsScreen) - Optimize TransactionsProvider to support account filtering Technical details: - Implement message polling mechanism for real-time AI responses - Support chat creation, deletion, retry and other operations - Integrate Material Design 3 design language - Improve user experience and error handling Co-authored-by: dwvwdv <dwvwdv@protonmail.com>
57 lines
1.4 KiB
Dart
57 lines
1.4 KiB
Dart
import 'tool_call.dart';
|
|
|
|
class Message {
|
|
final String id;
|
|
final String type;
|
|
final String role;
|
|
final String content;
|
|
final String? model;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
final List<ToolCall>? toolCalls;
|
|
|
|
Message({
|
|
required this.id,
|
|
required this.type,
|
|
required this.role,
|
|
required this.content,
|
|
this.model,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
this.toolCalls,
|
|
});
|
|
|
|
factory Message.fromJson(Map<String, dynamic> json) {
|
|
return Message(
|
|
id: json['id'].toString(),
|
|
type: json['type'] as String,
|
|
role: json['role'] as String,
|
|
content: json['content'] as String,
|
|
model: json['model'] as String?,
|
|
createdAt: DateTime.parse(json['created_at'] as String),
|
|
updatedAt: DateTime.parse(json['updated_at'] as String),
|
|
toolCalls: json['tool_calls'] != null
|
|
? (json['tool_calls'] as List)
|
|
.map((tc) => ToolCall.fromJson(tc as Map<String, dynamic>))
|
|
.toList()
|
|
: null,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'type': type,
|
|
'role': role,
|
|
'content': content,
|
|
'model': model,
|
|
'created_at': createdAt.toIso8601String(),
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
'tool_calls': toolCalls?.map((tc) => tc.toJson()).toList(),
|
|
};
|
|
}
|
|
|
|
bool get isUser => role == 'user';
|
|
bool get isAssistant => role == 'assistant';
|
|
}
|