class Message { final String role; final String content; final DateTime timestamp; Message({ required this.role, required this.content, required this.timestamp, }); // 从JSON构造函数 factory Message.fromJson(Map json) { return Message( role: json['role'] as String, content: json['content'] as String, timestamp: DateTime.parse(json['timestamp'] as String), ); } // 转换为JSON Map toJson() { return { 'role': role, 'content': content, 'timestamp': timestamp.toIso8601String(), }; } }