feat: enhance dashbot integration with context providers and ui updates

This commit is contained in:
Udhay-Adithya
2025-09-01 16:00:01 +05:30
parent 0def6c1713
commit 9e8c3b9887
11 changed files with 165 additions and 141 deletions

View File

@@ -0,0 +1,29 @@
import 'package:apidash_core/apidash_core.dart';
/// Context object that Dashbot needs from the host app.
///
/// Host apps should create/override a provider that returns this object
/// so Dashbot can react to changes in the current request selection.
class DashbotRequestContext {
final String? requestId;
final String? requestName;
final String? requestDescription;
final APIType apiType;
final AIRequestModel? aiRequestModel;
final HttpRequestModel? httpRequestModel;
final int? responseStatus;
final String? responseMessage;
final HttpResponseModel? httpResponseModel;
const DashbotRequestContext({
required this.apiType,
this.requestId,
this.requestName,
this.requestDescription,
this.aiRequestModel,
this.httpRequestModel,
this.responseStatus,
this.responseMessage,
this.httpResponseModel,
});
}

View File

@@ -0,0 +1,9 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../model/dashbot_request_context.dart';
/// Default provider for Dashbot's external request context.
/// The host app should override this provider at the Dashbot subtree.
final dashbotRequestContextProvider = Provider<DashbotRequestContext?>(
(ref) => null,
);

View File

@@ -1,4 +1,5 @@
import 'package:dashbot/features/chat/view/pages/dashbot_chat_page.dart';
import 'package:dashbot/features/chat/models/chat_models.dart';
import 'dashbot_routes.dart';
import '../common/pages/dashbot_default_page.dart';
@@ -12,10 +13,11 @@ Route<dynamic>? generateRoute(RouteSettings settings) {
case (DashbotRoutes.dashbotDefault):
return MaterialPageRoute(builder: (context) => DashbotDefaultPage());
case (DashbotRoutes.dashbotChat):
final args = settings.arguments as Map<String, dynamic>?;
final initialPrompt = args?['initialPrompt'] as String;
final arg = settings.arguments;
ChatMessageType? initialTask;
if (arg is ChatMessageType) initialTask = arg;
return MaterialPageRoute(
builder: (context) => ChatScreen(initialPrompt: initialPrompt),
builder: (context) => ChatScreen(initialTask: initialTask),
);
default:
return MaterialPageRoute(builder: (context) => DashbotDefaultPage());

View File

@@ -4,7 +4,13 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../dashbot_dashboard.dart';
import '../providers/dashbot_window_notifier.dart';
void showDashbotWindow(BuildContext context, WidgetRef ref) {
/// Optionally pass provider overrides (e.g., dashbotRequestContextProvider)
/// so the host app can feed live context into Dashbot.
void showDashbotWindow(
BuildContext context,
WidgetRef ref, {
List<Override>? overrides,
}) {
final isDashbotActive = ref.read(dashbotWindowNotifierProvider).isActive;
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
if (isDashbotActive) return;
@@ -13,11 +19,14 @@ void showDashbotWindow(BuildContext context, WidgetRef ref) {
entry = OverlayEntry(
builder:
(context) => DashbotWindow(
onClose: () {
entry?.remove();
windowNotifier.toggleActive();
},
(context) => ProviderScope(
overrides: overrides ?? const [],
child: DashbotWindow(
onClose: () {
entry?.remove();
windowNotifier.toggleActive();
},
),
),
);
windowNotifier.toggleActive();