fix(streaming): refactor to not force session id

This commit is contained in:
cogwheel0
2025-11-01 22:41:38 +05:30
parent f79d23aebf
commit 8cc7a23477
2 changed files with 21 additions and 28 deletions

View File

@@ -1170,9 +1170,7 @@ class ApiService {
data,
debugLabel: 'parse_file_search',
);
return normalized
.map(FileInfo.fromJson)
.toList(growable: false);
return normalized.map(FileInfo.fromJson).toList(growable: false);
}
return const [];
}
@@ -1186,9 +1184,7 @@ class ApiService {
data,
debugLabel: 'parse_file_all',
);
return normalized
.map(FileInfo.fromJson)
.toList(growable: false);
return normalized.map(FileInfo.fromJson).toList(growable: false);
}
return const [];
}
@@ -1599,10 +1595,7 @@ class ApiService {
if (data is Map<String, dynamic>) {
final voices = data['voices'];
if (voices is List) {
return _normalizeList(
voices,
debugLabel: 'parse_voice_list',
);
return _normalizeList(voices, debugLabel: 'parse_voice_list');
}
}
if (data is List) {
@@ -1705,10 +1698,7 @@ class ApiService {
final response = await _dio.get('/api/v1/images/models');
final data = response.data;
if (data is List) {
return _normalizeList(
data,
debugLabel: 'parse_image_models',
);
return _normalizeList(data, debugLabel: 'parse_image_models');
}
return [];
}
@@ -2406,7 +2396,7 @@ class ApiService {
({
Stream<String> stream,
String messageId,
String sessionId,
String? sessionId,
String? socketSessionId,
bool isBackgroundFlow,
})
@@ -2432,10 +2422,9 @@ class ApiService {
(responseMessageId != null && responseMessageId.isNotEmpty)
? responseMessageId
: const Uuid().v4();
final sessionId =
(sessionIdOverride != null && sessionIdOverride.isNotEmpty)
? sessionIdOverride
: const Uuid().v4().substring(0, 20);
final bool hasSocketBinding =
sessionIdOverride != null && sessionIdOverride.isNotEmpty;
final String? sessionId = hasSocketBinding ? sessionIdOverride : null;
// NOTE: Previously used to branch for Gemini-specific handling; not needed now.
@@ -2586,14 +2575,20 @@ class ApiService {
);
// Attach identifiers to trigger background task processing on the server
data['session_id'] = sessionId;
if (sessionId != null) {
data['session_id'] = sessionId;
}
data['id'] = messageId;
if (conversationId != null) {
data['chat_id'] = conversationId;
}
// Attach background_tasks if provided
if (backgroundTasks != null && backgroundTasks.isNotEmpty) {
final bool includeBackgroundTasks =
backgroundTasks != null &&
backgroundTasks.isNotEmpty &&
sessionId != null;
if (includeBackgroundTasks) {
data['background_tasks'] = backgroundTasks;
}
@@ -2717,7 +2712,7 @@ class ApiService {
messageId: messageId,
sessionId: sessionId,
socketSessionId: socketSessionId,
isBackgroundFlow: true,
isBackgroundFlow: includeBackgroundTasks,
);
}
@@ -3123,10 +3118,7 @@ class ApiService {
final data = response.data;
if (data is List) {
return _normalizeList(
data,
debugLabel: 'parse_message_search',
);
return _normalizeList(data, debugLabel: 'parse_message_search');
}
if (data is Map<String, dynamic>) {
final list = (data['items'] ?? data['results'] ?? data['messages']);

View File

@@ -135,7 +135,7 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
required String assistantMessageId,
required String modelId,
required Map<String, dynamic> modelItem,
required String sessionId,
required String? sessionId,
required String? activeConversationId,
required ApiService api,
required SocketService? socketService,
@@ -238,6 +238,7 @@ ActiveSocketStream attachUnifiedChunkedStreaming({
'conversationId': activeConversationId,
'messageId': assistantMessageId,
'modelId': modelId,
if (sessionId != null) 'sessionId': sessionId,
},
);
api.registerPersistentStreamForMessage(assistantMessageId, streamId);