fix: sources count
This commit is contained in:
@@ -12,6 +12,7 @@ import 'navigation_service.dart';
|
||||
import '../../shared/widgets/themed_dialogs.dart';
|
||||
import '../../shared/theme/theme_extensions.dart';
|
||||
import '../utils/debug_logger.dart';
|
||||
import '../utils/openwebui_source_parser.dart';
|
||||
|
||||
// Keep local verbosity toggle for socket logs
|
||||
const bool kSocketVerboseLogging = false;
|
||||
@@ -705,38 +706,17 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
|
||||
} catch (_) {}
|
||||
} else {
|
||||
try {
|
||||
// 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();
|
||||
final sources = parseOpenWebUISourceList([map]);
|
||||
if (sources.isNotEmpty) {
|
||||
final targetId = _resolveTargetMessageId(
|
||||
messageId,
|
||||
getMessages,
|
||||
);
|
||||
if (targetId != null) {
|
||||
for (final source in sources) {
|
||||
appendSourceReference(targetId, source);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user