fix: status history parsing
This commit is contained in:
@@ -157,11 +157,21 @@ List<ChatStatusItem> _statusItemsFromJson(dynamic value) {
|
|||||||
if (value is List) {
|
if (value is List) {
|
||||||
return value
|
return value
|
||||||
.whereType<Map>()
|
.whereType<Map>()
|
||||||
.map(
|
.map((item) {
|
||||||
(item) => ChatStatusItem.fromJson(
|
try {
|
||||||
item.map((key, v) => MapEntry(key.toString(), v)),
|
// Convert Map to Map<String, dynamic> safely
|
||||||
),
|
final Map<String, dynamic> itemMap = {};
|
||||||
)
|
item.forEach((key, v) {
|
||||||
|
itemMap[key.toString()] = v;
|
||||||
|
});
|
||||||
|
return ChatStatusItem.fromJson(itemMap);
|
||||||
|
} catch (e) {
|
||||||
|
// Skip invalid entries
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.where((item) => item != null)
|
||||||
|
.cast<ChatStatusItem>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);
|
||||||
}
|
}
|
||||||
return const [];
|
return const [];
|
||||||
@@ -175,11 +185,21 @@ List<ChatExecutionFile> _executionFilesFromJson(dynamic value) {
|
|||||||
if (value is List) {
|
if (value is List) {
|
||||||
return value
|
return value
|
||||||
.whereType<Map>()
|
.whereType<Map>()
|
||||||
.map(
|
.map((item) {
|
||||||
(item) => ChatExecutionFile.fromJson(
|
try {
|
||||||
item.map((key, v) => MapEntry(key.toString(), v)),
|
// Convert Map to Map<String, dynamic> safely
|
||||||
),
|
final Map<String, dynamic> fileMap = {};
|
||||||
)
|
item.forEach((key, v) {
|
||||||
|
fileMap[key.toString()] = v;
|
||||||
|
});
|
||||||
|
return ChatExecutionFile.fromJson(fileMap);
|
||||||
|
} catch (e) {
|
||||||
|
// Skip invalid entries
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.where((item) => item != null)
|
||||||
|
.cast<ChatExecutionFile>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);
|
||||||
}
|
}
|
||||||
return const [];
|
return const [];
|
||||||
@@ -195,11 +215,21 @@ List<ChatSourceReference> _sourceRefsFromJson(dynamic value) {
|
|||||||
if (value is List) {
|
if (value is List) {
|
||||||
return value
|
return value
|
||||||
.whereType<Map>()
|
.whereType<Map>()
|
||||||
.map(
|
.map((item) {
|
||||||
(item) => ChatSourceReference.fromJson(
|
try {
|
||||||
item.map((key, v) => MapEntry(key.toString(), v)),
|
// Convert Map to Map<String, dynamic> safely
|
||||||
),
|
final Map<String, dynamic> refMap = {};
|
||||||
)
|
item.forEach((key, v) {
|
||||||
|
refMap[key.toString()] = v;
|
||||||
|
});
|
||||||
|
return ChatSourceReference.fromJson(refMap);
|
||||||
|
} catch (e) {
|
||||||
|
// Skip invalid entries
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.where((item) => item != null)
|
||||||
|
.cast<ChatSourceReference>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);
|
||||||
}
|
}
|
||||||
return const [];
|
return const [];
|
||||||
|
|||||||
@@ -1198,11 +1198,26 @@ class ApiService {
|
|||||||
if (raw is List) {
|
if (raw is List) {
|
||||||
return raw
|
return raw
|
||||||
.whereType<Map>()
|
.whereType<Map>()
|
||||||
.map(
|
.map((entry) {
|
||||||
(entry) => ChatStatusUpdate.fromJson(
|
try {
|
||||||
entry.map((key, value) => MapEntry(key.toString(), value)),
|
// Convert Map to Map<String, dynamic> safely
|
||||||
),
|
final Map<String, dynamic> statusMap = {};
|
||||||
)
|
entry.forEach((key, value) {
|
||||||
|
statusMap[key.toString()] = value;
|
||||||
|
});
|
||||||
|
return ChatStatusUpdate.fromJson(statusMap);
|
||||||
|
} catch (e) {
|
||||||
|
// Log the error and skip this entry
|
||||||
|
DebugLogger.log(
|
||||||
|
'status-parse-error',
|
||||||
|
scope: 'api/chat',
|
||||||
|
data: {'error': e.toString(), 'entry': entry.toString()},
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.where((item) => item != null)
|
||||||
|
.cast<ChatStatusUpdate>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);
|
||||||
}
|
}
|
||||||
return const <ChatStatusUpdate>[];
|
return const <ChatStatusUpdate>[];
|
||||||
@@ -1226,11 +1241,26 @@ class ApiService {
|
|||||||
if (raw is List) {
|
if (raw is List) {
|
||||||
return raw
|
return raw
|
||||||
.whereType<Map>()
|
.whereType<Map>()
|
||||||
.map(
|
.map((entry) {
|
||||||
(entry) => ChatCodeExecution.fromJson(
|
try {
|
||||||
entry.map((key, value) => MapEntry(key.toString(), value)),
|
// Convert Map to Map<String, dynamic> safely
|
||||||
),
|
final Map<String, dynamic> execMap = {};
|
||||||
)
|
entry.forEach((key, value) {
|
||||||
|
execMap[key.toString()] = value;
|
||||||
|
});
|
||||||
|
return ChatCodeExecution.fromJson(execMap);
|
||||||
|
} catch (e) {
|
||||||
|
// Log the error and skip this entry
|
||||||
|
DebugLogger.log(
|
||||||
|
'code-exec-parse-error',
|
||||||
|
scope: 'api/chat',
|
||||||
|
data: {'error': e.toString(), 'entry': entry.toString()},
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.where((item) => item != null)
|
||||||
|
.cast<ChatCodeExecution>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);
|
||||||
}
|
}
|
||||||
return const <ChatCodeExecution>[];
|
return const <ChatCodeExecution>[];
|
||||||
@@ -1240,11 +1270,26 @@ class ApiService {
|
|||||||
if (raw is List) {
|
if (raw is List) {
|
||||||
return raw
|
return raw
|
||||||
.whereType<Map>()
|
.whereType<Map>()
|
||||||
.map(
|
.map((entry) {
|
||||||
(entry) => ChatSourceReference.fromJson(
|
try {
|
||||||
entry.map((key, value) => MapEntry(key.toString(), value)),
|
// Convert Map to Map<String, dynamic> safely
|
||||||
),
|
final Map<String, dynamic> sourceMap = {};
|
||||||
)
|
entry.forEach((key, value) {
|
||||||
|
sourceMap[key.toString()] = value;
|
||||||
|
});
|
||||||
|
return ChatSourceReference.fromJson(sourceMap);
|
||||||
|
} catch (e) {
|
||||||
|
// Log the error and skip this entry
|
||||||
|
DebugLogger.log(
|
||||||
|
'source-parse-error',
|
||||||
|
scope: 'api/chat',
|
||||||
|
data: {'error': e.toString(), 'entry': entry.toString()},
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.where((item) => item != null)
|
||||||
|
.cast<ChatSourceReference>()
|
||||||
.toList(growable: false);
|
.toList(growable: false);
|
||||||
}
|
}
|
||||||
return const <ChatSourceReference>[];
|
return const <ChatSourceReference>[];
|
||||||
|
|||||||
Reference in New Issue
Block a user