e80a82bef4
- 更新 http-error-codes, user-points-chat-data-protocol - 更新 divination-run-protocol, profile-protocol - 删除废弃的后端和前端设计计划文档
53 lines
1.3 KiB
Dart
53 lines
1.3 KiB
Dart
class FollowUpMessage {
|
|
const FollowUpMessage({
|
|
required this.id,
|
|
required this.seq,
|
|
required this.role,
|
|
required this.content,
|
|
required this.timestamp,
|
|
});
|
|
|
|
final String id;
|
|
final int seq;
|
|
final String role;
|
|
final String content;
|
|
final DateTime timestamp;
|
|
|
|
factory FollowUpMessage.fromJson(Map<String, dynamic> json) {
|
|
return FollowUpMessage(
|
|
id: _requiredString(json, 'id'),
|
|
seq: _requiredInt(json, 'seq'),
|
|
role: _requiredString(json, 'role'),
|
|
content: _requiredStringAllowEmpty(json, 'content'),
|
|
timestamp: DateTime.parse(_requiredString(json, 'timestamp')).toLocal(),
|
|
);
|
|
}
|
|
}
|
|
|
|
String _requiredString(Map<String, dynamic> json, String key) {
|
|
final value = json[key];
|
|
if (value is! String || value.isEmpty) {
|
|
throw FormatException('Missing required string: $key');
|
|
}
|
|
return value;
|
|
}
|
|
|
|
String _requiredStringAllowEmpty(Map<String, dynamic> json, String key) {
|
|
final value = json[key];
|
|
if (value is! String) {
|
|
throw FormatException('Missing required string: $key');
|
|
}
|
|
return value;
|
|
}
|
|
|
|
int _requiredInt(Map<String, dynamic> json, String key) {
|
|
final value = json[key];
|
|
if (value is int) {
|
|
return value;
|
|
}
|
|
if (value is num) {
|
|
return value.toInt();
|
|
}
|
|
throw FormatException('Missing required int: $key');
|
|
}
|