refactor: enhance API service to include non-image files in requests and improve chat message synchronization logic

This commit is contained in:
cogwheel0
2025-08-26 11:21:26 +05:30
parent 494427dd04
commit 8692bf3bb6
2 changed files with 16 additions and 2 deletions

View File

@@ -2442,6 +2442,14 @@ class ApiService {
debugPrint('DEBUG: Including tool_ids in SSE request: $toolIds');
}
// Include non-image files at the top level as expected by Open WebUI
if (allFiles.isNotEmpty) {
data['files'] = allFiles;
debugPrint(
'DEBUG: Including non-image files in request: ${allFiles.length}',
);
}
// Don't add session_id or id - they break SSE streaming!
// The server falls back to task-based async when these are present

View File

@@ -37,9 +37,15 @@ class ChatMessagesNotifier extends StateNotifier<List<ChatMessage>> {
// Only react when the conversation actually changes
if (previous?.id == next?.id) {
// If same conversation but server updated it (e.g., title/content), sync messages without flicker
// If same conversation but server updated it (e.g., title/content), avoid overwriting
// locally streamed assistant content with an outdated server copy.
if (previous?.updatedAt != next?.updatedAt) {
state = next?.messages ?? state;
final serverMessages = next?.messages ?? const [];
// Only replace local messages if the server has strictly more messages
// (i.e., includes new content we don't have yet).
if (serverMessages.length > state.length) {
state = serverMessages;
}
}
return;
}