Files
Auto-GPT/frontend/lib/models/chat.dart
hunteraraujo e1d45645ae Integrate JSON Response into AgentMessageTile
This commit integrates the actual JSON response received from the API into the AgentMessageTile. Now, each AgentMessageTile will display the associated JSON response when expanded.

- Converted Map<String, dynamic> JSON response to a string using jsonEncode.
- Passed the JSON-formatted string to JsonCodeSnippetView.
- Updated AgentMessageTile to include this change.

This change enhances the debugging and transparency features of the chat interface.
2023-09-04 15:47:15 -07:00

56 lines
1.5 KiB
Dart

import 'package:auto_gpt_flutter_client/models/message_type.dart';
/// Represents a chat message related to a specific task.
class Chat {
final String id;
final String taskId;
final String message;
final DateTime timestamp;
final MessageType messageType;
final Map<String, dynamic>? jsonResponse;
Chat({
required this.id,
required this.taskId,
required this.message,
required this.timestamp,
required this.messageType,
this.jsonResponse,
});
// Convert a Map (usually from JSON) to a Chat object
factory Chat.fromMap(Map<String, dynamic> map) {
return Chat(
id: map['id'],
taskId: map['taskId'],
message: map['message'],
timestamp: DateTime.parse(map['timestamp']),
messageType: MessageType.values.firstWhere(
(e) => e.toString() == 'MessageType.${map['messageType']}'),
);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Chat &&
runtimeType == other.runtimeType &&
id == other.id &&
taskId == other.taskId &&
message == other.message &&
timestamp == other.timestamp &&
messageType == other.messageType;
@override
int get hashCode =>
id.hashCode ^
taskId.hashCode ^
message.hashCode ^
timestamp.hashCode ^
messageType.hashCode;
@override
String toString() =>
'Chat(id: $id, taskId: $taskId, message: $message, timestamp: $timestamp, messageType: $messageType)';
}