surface agent stream audit IDs

This commit is contained in:
Hamza Ayed
2026-10-04 19:17:28 +03:00
parent 8266de07c5
commit 77cad71380
3 changed files with 100 additions and 2 deletions
@@ -567,6 +567,11 @@ class ApiRepository {
final streamed = await client
.send(request)
.timeout(const Duration(minutes: 10));
final auditId = streamed.headers['x-agent-audit-id'];
String withAuditId(String message) =>
auditId == null || auditId.isEmpty
? message
: '$message\nمعرّف تتبع الطلب: $auditId';
if (streamed.statusCode < 200 || streamed.statusCode >= 300) {
final response = await http.Response.fromStream(streamed);
_checkStatus(response);
@@ -601,9 +606,11 @@ class ApiRepository {
eventName = null;
}
}
if (streamError != null) throw Exception(streamError);
if (streamError != null) throw Exception(withAuditId(streamError));
final data = resultData;
if (data == null) throw Exception('انقطع اتصال البث قبل اكتمال الوكيل.');
if (data == null) {
throw Exception(withAuditId('انقطع اتصال البث قبل اكتمال الوكيل.'));
}
return AgentRunResult.fromApiData(data);
} finally {
if (identical(_activeRequestClient, client)) _activeRequestClient = null;