feat: enhance loading state management during import processes in ChatViewmodel

This commit is contained in:
Udhay-Adithya
2025-09-24 19:13:27 +05:30
parent 1a26380be3
commit 5a68c258e1
2 changed files with 22 additions and 3 deletions

View File

@@ -4,9 +4,9 @@ Dashbot is your in-app helper for working with APIs inside API Dash. It explains
## Before You Start ## Before You Start
- Configure an AI model: Open the AI Request settings and set your preferred provider/model and API key. Dashbot needs this to generate answers. If not configured, you will see a message asking you to set it up. - **Configure an AI model** : Open the AI Request settings and set your preferred provider/model and API key. Dashbot needs this to generate answers. If not configured, you will see a message asking you to set it up.
- Pick or create a request: Dashbot works best when a request is selected, especially for Explain, Debug, Tests, Docs, and Code. - **Pick or create a request** : Dashbot works best when a request is selected, especially for Explain, Debug, Tests, Docs, and Code.
- Network access: Some features pull insights only from your current request and input. No external API calls are made by Dashbot itself (outside your configured AI provider). - **Network access** : Some features pull insights only from your current request and input. No external API calls are made by Dashbot itself (outside your configured AI provider).
## Open Dashbot ## Open Dashbot
- Floating window: Click the Dashbot button to open it as a floating panel. - Floating window: Click the Dashbot button to open it as a floating panel.

View File

@@ -107,6 +107,8 @@ class ChatViewmodel extends StateNotifier<ChatState> {
); );
} else if (type == ChatMessageType.importCurl) { } else if (type == ChatMessageType.importCurl) {
final rqId = _currentRequest?.id ?? 'global'; final rqId = _currentRequest?.id ?? 'global';
// Briefly toggle loading to indicate processing of the import flow prompt
state = state.copyWith(isGenerating: true, currentStreamingResponse: '');
_addMessage( _addMessage(
rqId, rqId,
ChatMessage( ChatMessage(
@@ -118,9 +120,11 @@ class ChatViewmodel extends StateNotifier<ChatState> {
messageType: ChatMessageType.importCurl, messageType: ChatMessageType.importCurl,
), ),
); );
state = state.copyWith(isGenerating: false, currentStreamingResponse: '');
return; return;
} else if (type == ChatMessageType.importOpenApi) { } else if (type == ChatMessageType.importOpenApi) {
final rqId = _currentRequest?.id ?? 'global'; final rqId = _currentRequest?.id ?? 'global';
state = state.copyWith(isGenerating: true, currentStreamingResponse: '');
final uploadAction = ChatAction.fromJson({ final uploadAction = ChatAction.fromJson({
'action': 'upload_asset', 'action': 'upload_asset',
'target': 'attachment', 'target': 'attachment',
@@ -152,6 +156,7 @@ class ChatViewmodel extends StateNotifier<ChatState> {
if (_looksLikeOpenApi(text)) { if (_looksLikeOpenApi(text)) {
await handlePotentialOpenApiPaste(text); await handlePotentialOpenApiPaste(text);
} }
state = state.copyWith(isGenerating: false, currentStreamingResponse: '');
return; return;
} else { } else {
systemPrompt = promptBuilder.buildSystemPrompt( systemPrompt = promptBuilder.buildSystemPrompt(
@@ -431,6 +436,8 @@ class ChatViewmodel extends StateNotifier<ChatState> {
// quick check // quick check
final trimmed = text.trim(); final trimmed = text.trim();
if (!trimmed.startsWith('curl ')) return; if (!trimmed.startsWith('curl ')) return;
// Show loading while parsing and generating insights
state = state.copyWith(isGenerating: true, currentStreamingResponse: '');
try { try {
debugPrint('[cURL] Original: $trimmed'); debugPrint('[cURL] Original: $trimmed');
final curl = CurlImportService.tryParseCurl(trimmed); final curl = CurlImportService.tryParseCurl(trimmed);
@@ -528,6 +535,11 @@ class ChatViewmodel extends StateNotifier<ChatState> {
final safe = e.toString().replaceAll('"', "'"); final safe = e.toString().replaceAll('"', "'");
_appendSystem('{"explnation":"Parsing failed: $safe","actions":[]}', _appendSystem('{"explnation":"Parsing failed: $safe","actions":[]}',
ChatMessageType.importCurl); ChatMessageType.importCurl);
} finally {
state = state.copyWith(
isGenerating: false,
currentStreamingResponse: '',
);
} }
} }
@@ -581,6 +593,8 @@ class ChatViewmodel extends StateNotifier<ChatState> {
Future<void> handlePotentialOpenApiPaste(String text) async { Future<void> handlePotentialOpenApiPaste(String text) async {
final trimmed = text.trim(); final trimmed = text.trim();
if (!_looksLikeOpenApi(trimmed)) return; if (!_looksLikeOpenApi(trimmed)) return;
// Show loading while parsing and generating insights
state = state.copyWith(isGenerating: true, currentStreamingResponse: '');
try { try {
debugPrint('[OpenAPI] Original length: ${trimmed.length}'); debugPrint('[OpenAPI] Original length: ${trimmed.length}');
final spec = OpenApiImportService.tryParseSpec(trimmed); final spec = OpenApiImportService.tryParseSpec(trimmed);
@@ -647,6 +661,11 @@ class ChatViewmodel extends StateNotifier<ChatState> {
final safe = e.toString().replaceAll('"', "'"); final safe = e.toString().replaceAll('"', "'");
_appendSystem('{"explnation":"Parsing failed: $safe","actions":[]}', _appendSystem('{"explnation":"Parsing failed: $safe","actions":[]}',
ChatMessageType.importOpenApi); ChatMessageType.importOpenApi);
} finally {
state = state.copyWith(
isGenerating: false,
currentStreamingResponse: '',
);
} }
} }