mirror of
https://github.com/foss42/apidash.git
synced 2025-11-30 17:59:18 +08:00
feat: add terminal state provider to collection state provider
This commit is contained in:
@@ -7,6 +7,7 @@ import 'providers.dart';
|
|||||||
import '../models/models.dart';
|
import '../models/models.dart';
|
||||||
import '../services/services.dart';
|
import '../services/services.dart';
|
||||||
import '../utils/utils.dart';
|
import '../utils/utils.dart';
|
||||||
|
import '../models/terminal_models.dart';
|
||||||
|
|
||||||
final selectedIdStateProvider = StateProvider<String?>((ref) => null);
|
final selectedIdStateProvider = StateProvider<String?>((ref) => null);
|
||||||
|
|
||||||
@@ -347,6 +348,22 @@ class CollectionStateNotifier
|
|||||||
executionRequestModel.httpRequestModel!);
|
executionRequestModel.httpRequestModel!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Terminal: start network log
|
||||||
|
final terminal = ref.read(terminalStateProvider.notifier);
|
||||||
|
final logId = terminal.startNetwork(
|
||||||
|
apiType: executionRequestModel.apiType,
|
||||||
|
method: (executionRequestModel.apiType == APIType.ai)
|
||||||
|
? executionRequestModel.aiRequestModel!.httpRequestModel!.method
|
||||||
|
: executionRequestModel.httpRequestModel!.method,
|
||||||
|
url: (executionRequestModel.apiType == APIType.ai)
|
||||||
|
? executionRequestModel.aiRequestModel!.httpRequestModel!.url
|
||||||
|
: executionRequestModel.httpRequestModel!.url,
|
||||||
|
requestId: requestId,
|
||||||
|
requestHeaders: substitutedHttpRequestModel.enabledHeadersMap,
|
||||||
|
requestBodyPreview: substitutedHttpRequestModel.body,
|
||||||
|
isStreaming: true,
|
||||||
|
);
|
||||||
|
|
||||||
// Set model to working and streaming
|
// Set model to working and streaming
|
||||||
state = {
|
state = {
|
||||||
...state!,
|
...state!,
|
||||||
@@ -398,6 +415,17 @@ class CollectionStateNotifier
|
|||||||
...state!,
|
...state!,
|
||||||
requestId: newRequestModel,
|
requestId: newRequestModel,
|
||||||
};
|
};
|
||||||
|
// Terminal: append chunk preview
|
||||||
|
if (response != null && response.body.isNotEmpty) {
|
||||||
|
terminal.addNetworkChunk(
|
||||||
|
logId,
|
||||||
|
BodyChunk(
|
||||||
|
ts: DateTime.now(),
|
||||||
|
text: response.body,
|
||||||
|
sizeBytes: response.body.codeUnits.length,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
unsave();
|
unsave();
|
||||||
|
|
||||||
if (historyModel != null && httpResponseModel != null) {
|
if (historyModel != null && httpResponseModel != null) {
|
||||||
@@ -425,6 +453,7 @@ class CollectionStateNotifier
|
|||||||
if (!completer.isCompleted) {
|
if (!completer.isCompleted) {
|
||||||
completer.complete((null, null, 'StreamError: $e'));
|
completer.complete((null, null, 'StreamError: $e'));
|
||||||
}
|
}
|
||||||
|
terminal.failNetwork(logId, 'StreamError: $e');
|
||||||
});
|
});
|
||||||
|
|
||||||
final (response, duration, errorMessage) = await completer.future;
|
final (response, duration, errorMessage) = await completer.future;
|
||||||
@@ -436,6 +465,7 @@ class CollectionStateNotifier
|
|||||||
isWorking: false,
|
isWorking: false,
|
||||||
isStreaming: false,
|
isStreaming: false,
|
||||||
);
|
);
|
||||||
|
terminal.failNetwork(logId, errorMessage ?? 'Unknown error');
|
||||||
} else {
|
} else {
|
||||||
final statusCode = response.statusCode;
|
final statusCode = response.statusCode;
|
||||||
httpResponseModel = baseHttpResponseModel.fromResponse(
|
httpResponseModel = baseHttpResponseModel.fromResponse(
|
||||||
@@ -461,6 +491,14 @@ class CollectionStateNotifier
|
|||||||
isWorking: false,
|
isWorking: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
terminal.completeNetwork(
|
||||||
|
logId,
|
||||||
|
statusCode: statusCode,
|
||||||
|
responseHeaders: response.headers,
|
||||||
|
responseBodyPreview: httpResponseModel?.body,
|
||||||
|
duration: duration,
|
||||||
|
);
|
||||||
|
|
||||||
String newHistoryId = getNewUuid();
|
String newHistoryId = getNewUuid();
|
||||||
historyModel = HistoryRequestModel(
|
historyModel = HistoryRequestModel(
|
||||||
historyId: newHistoryId,
|
historyId: newHistoryId,
|
||||||
|
|||||||
Reference in New Issue
Block a user