@@ -3,6 +3,7 @@ import 'package:apidash_core/apidash_core.dart';
3
3
import 'package:flutter/material.dart' ;
4
4
import 'package:flutter_riverpod/flutter_riverpod.dart' ;
5
5
import 'package:apidash/consts.dart' ;
6
+ import 'package:apidash/terminal/terminal.dart' ;
6
7
import 'providers.dart' ;
7
8
import '../models/models.dart' ;
8
9
import '../services/services.dart' ;
@@ -320,7 +321,9 @@ class CollectionStateNotifier
320
321
RequestModel executionRequestModel = requestModel! .copyWith ();
321
322
322
323
if (! requestModel.preRequestScript.isNullOrEmpty ()) {
323
- executionRequestModel = await handlePreRequestScript (
324
+ executionRequestModel = await ref
325
+ .read (jsRuntimeNotifierProvider.notifier)
326
+ .handlePreRequestScript (
324
327
executionRequestModel,
325
328
originalEnvironmentModel,
326
329
(envModel, updatedValues) {
@@ -347,6 +350,18 @@ class CollectionStateNotifier
347
350
executionRequestModel.httpRequestModel! );
348
351
}
349
352
353
+ // Terminal: start network log
354
+ final terminal = ref.read (terminalStateProvider.notifier);
355
+ final logId = terminal.startNetwork (
356
+ apiType: executionRequestModel.apiType,
357
+ method: substitutedHttpRequestModel.method,
358
+ url: substitutedHttpRequestModel.url,
359
+ requestId: requestId,
360
+ requestHeaders: substitutedHttpRequestModel.enabledHeadersMap,
361
+ requestBodyPreview: substitutedHttpRequestModel.body,
362
+ isStreaming: true ,
363
+ );
364
+
350
365
// Set model to working and streaming
351
366
state = {
352
367
...state! ,
@@ -398,6 +413,17 @@ class CollectionStateNotifier
398
413
...state! ,
399
414
requestId: newRequestModel,
400
415
};
416
+ // Terminal: append chunk preview
417
+ if (response != null && response.body.isNotEmpty) {
418
+ terminal.addNetworkChunk (
419
+ logId,
420
+ BodyChunk (
421
+ ts: DateTime .now (),
422
+ text: response.body,
423
+ sizeBytes: response.body.codeUnits.length,
424
+ ),
425
+ );
426
+ }
401
427
unsave ();
402
428
403
429
if (historyModel != null && httpResponseModel != null ) {
@@ -425,6 +451,7 @@ class CollectionStateNotifier
425
451
if (! completer.isCompleted) {
426
452
completer.complete ((null , null , 'StreamError: $e ' ));
427
453
}
454
+ terminal.failNetwork (logId, 'StreamError: $e ' );
428
455
});
429
456
430
457
final (response, duration, errorMessage) = await completer.future;
@@ -436,6 +463,7 @@ class CollectionStateNotifier
436
463
isWorking: false ,
437
464
isStreaming: false ,
438
465
);
466
+ terminal.failNetwork (logId, errorMessage ?? 'Unknown error' );
439
467
} else {
440
468
final statusCode = response.statusCode;
441
469
httpResponseModel = baseHttpResponseModel.fromResponse (
@@ -461,6 +489,14 @@ class CollectionStateNotifier
461
489
isWorking: false ,
462
490
);
463
491
492
+ terminal.completeNetwork (
493
+ logId,
494
+ statusCode: statusCode,
495
+ responseHeaders: response.headers,
496
+ responseBodyPreview: httpResponseModel? .body,
497
+ duration: duration,
498
+ );
499
+
464
500
String newHistoryId = getNewUuid ();
465
501
historyModel = HistoryRequestModel (
466
502
historyId: newHistoryId,
@@ -487,7 +523,9 @@ class CollectionStateNotifier
487
523
.addHistoryRequest (historyModel! );
488
524
489
525
if (! requestModel.postRequestScript.isNullOrEmpty ()) {
490
- newRequestModel = await handlePostResponseScript (
526
+ newRequestModel = await ref
527
+ .read (jsRuntimeNotifierProvider.notifier)
528
+ .handlePostResponseScript (
491
529
newRequestModel,
492
530
originalEnvironmentModel,
493
531
(envModel, updatedValues) {
0 commit comments