feat: show sources

This commit is contained in:
cogwheel0
2025-09-28 14:59:29 +05:30
parent ae20035900
commit b8856679da
4 changed files with 432 additions and 6 deletions

View File

@@ -705,7 +705,35 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
} catch (_) {}
} else {
try {
final source = ChatSourceReference.fromJson(map);
// Handle nested source structure from OpenWebUI
final sourceData = map['source'];
final ChatSourceReference source;
if (sourceData is Map<String, dynamic>) {
// Extract the actual source information from nested structure
final sourceMap = Map<String, dynamic>.from(sourceData);
// Add additional metadata from the outer structure if available
if (map.containsKey('document') && map['document'] is List) {
final documents = map['document'] as List;
if (documents.isNotEmpty) {
sourceMap['snippet'] = documents.first?.toString();
}
}
if (map.containsKey('metadata') && map['metadata'] is List) {
final metadata = map['metadata'] as List;
if (metadata.isNotEmpty && metadata.first is Map) {
sourceMap['metadata'] = metadata.first;
}
}
source = ChatSourceReference.fromJson(sourceMap);
} else {
// Fallback: treat the entire map as a source (for backward compatibility)
source = ChatSourceReference.fromJson(map);
}
final targetId = _resolveTargetMessageId(messageId, getMessages);
if (targetId != null) {
appendSourceReference(targetId, source);