Skip to content

Commit 0a6a2bb

Browse files
authored
Merge pull request #887 from Udhay-Adithya/dashbot-core
core functionalities of dashbot
2 parents 7925c08 + 5c6869c commit 0a6a2bb

File tree

185 files changed

+13459
-1547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+13459
-1547
lines changed

assets/dashbot/dashbot_icon_1.png

2.41 KB
Loading

assets/dashbot/dashbot_icon_2.png

2.21 KB
Loading

doc/user_guide/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [History of Requests](https://github.com/foss42/apidash/blob/main/doc/user_guide/his_user_guide.md)
44
- [Environment Variables Manager](https://github.com/foss42/apidash/blob/main/doc/user_guide/env_user_guide.md)
55
- [How to Disable SSL for Requests](https://github.com/foss42/apidash/blob/main/doc/user_guide/disable_ssl.md)
6+
- [Dashbot User Guide](https://github.com/foss42/apidash/blob/main/doc/user_guide/dashbot_user_guide.md)
67
- Import Request for cURL (Contributions Welcome!)
78
- [How to Run Generated Code for a Programming Language](https://github.com/foss42/apidash/blob/main/doc/user_guide/instructions_to_run_generated_code.md) (Contributions Welcome!)
89
- [API Dash on Mobile](https://github.com/foss42/apidash/blob/main/doc/user_guide/req_user_guide.md)

lib/consts.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ const kLabelDownload = "Download";
450450
const kLabelSaving = "Saving";
451451
const kLabelSaved = "Saved";
452452
const kLabelCode = "Code";
453+
const kLabelDashBot = "DashBot";
453454
const kLabelDuplicate = "Duplicate";
454455
const kLabelSelect = "Select";
455456
const kLabelContinue = "Continue";

lib/dashbot/constants.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/// Role of a chat message author.
2+
enum MessageRole { user, system }
3+
4+
enum ChatMessageType {
5+
explainResponse,
6+
debugError,
7+
generateTest,
8+
generateDoc,
9+
generateCode,
10+
importCurl,
11+
importOpenApi,
12+
general
13+
}
14+
15+
enum ChatActionType {
16+
updateField('update_field'),
17+
addHeader('add_header'),
18+
updateHeader('update_header'),
19+
deleteHeader('delete_header'),
20+
updateBody('update_body'),
21+
updateUrl('update_url'),
22+
updateMethod('update_method'),
23+
showLanguages('show_languages'),
24+
applyCurl('apply_curl'),
25+
applyOpenApi('apply_openapi'),
26+
downloadDoc('download_doc'),
27+
other('other'),
28+
noAction('no_action'),
29+
uploadAsset('upload_asset');
30+
31+
const ChatActionType(this.text);
32+
final String text;
33+
}
34+
35+
enum ChatActionTarget {
36+
httpRequestModel,
37+
codegen,
38+
test,
39+
code,
40+
attachment,
41+
documentation,
42+
}
43+
44+
ChatActionType chatActionTypeFromString(String s) {
45+
return ChatActionType.values.firstWhere(
46+
(type) => type.text == s,
47+
orElse: () => ChatActionType.other,
48+
);
49+
}
50+
51+
ChatActionTarget chatActionTargetFromString(String s) {
52+
return ChatActionTarget.values.firstWhere(
53+
(target) => target.name == s,
54+
orElse: () => ChatActionTarget.httpRequestModel,
55+
);
56+
}

lib/dashbot/consts.dart

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/dashbot/dashbot.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export 'widgets/dashbot_widget.dart';
1+
export 'dashbot_dashboard.dart';
2+
export 'dashbot_tab.dart';
3+
export 'providers/providers.dart';
4+
export 'utils/utils.dart';

lib/dashbot/dashbot_dashboard.dart

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
import 'package:apidash_core/apidash_core.dart';
2+
import 'package:apidash_design_system/apidash_design_system.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_riverpod/flutter_riverpod.dart';
5+
import 'package:apidash/providers/providers.dart';
6+
import 'package:apidash/screens/common_widgets/ai/ai.dart';
7+
import 'providers/providers.dart';
8+
import 'routes/routes.dart';
9+
import 'utils/utils.dart';
10+
11+
class DashbotWindow extends ConsumerWidget {
12+
final VoidCallback onClose;
13+
14+
const DashbotWindow({super.key, required this.onClose});
15+
16+
static final GlobalKey<NavigatorState> _dashbotNavigatorKey =
17+
GlobalKey<NavigatorState>();
18+
19+
@override
20+
Widget build(BuildContext context, WidgetRef ref) {
21+
final windowState = ref.watch(dashbotWindowNotifierProvider);
22+
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
23+
final settings = ref.watch(settingsProvider);
24+
final activeRoute = ref.watch(dashbotActiveRouteProvider);
25+
26+
// Close the overlay when the window is not popped anymore
27+
ref.listen(
28+
dashbotWindowNotifierProvider.select((s) => s.isPopped),
29+
(prev, next) {
30+
if (prev == true && next == false) {
31+
onClose();
32+
}
33+
},
34+
);
35+
36+
void navigateTo(String route) {
37+
final nav = _dashbotNavigatorKey.currentState;
38+
if (nav == null) return;
39+
Route? top;
40+
nav.popUntil((r) {
41+
top = r;
42+
return true;
43+
});
44+
if (top?.settings.name == route) return;
45+
if (route == DashbotRoutes.dashbotDefault) {
46+
nav.popUntil((r) => r.isFirst);
47+
} else {
48+
nav.pushNamed(route);
49+
}
50+
}
51+
52+
ref.listen<String>(dashbotActiveRouteProvider, (prev, next) {
53+
if (prev == next || next.isEmpty) return;
54+
navigateTo(next);
55+
});
56+
57+
return Stack(
58+
children: [
59+
if (!windowState.isHidden)
60+
Positioned(
61+
right: windowState.right,
62+
bottom: windowState.bottom,
63+
child: Material(
64+
elevation: 8,
65+
borderRadius: BorderRadius.circular(8),
66+
child: Container(
67+
width: windowState.width,
68+
height: windowState.height,
69+
decoration: BoxDecoration(
70+
color: Theme.of(context).colorScheme.surfaceContainerLow,
71+
borderRadius: BorderRadius.circular(8),
72+
),
73+
child: Stack(
74+
children: [
75+
Column(
76+
children: [
77+
// This is to update position
78+
GestureDetector(
79+
onPanUpdate: (details) {
80+
windowNotifier.updatePosition(
81+
details.delta.dx,
82+
details.delta.dy,
83+
MediaQuery.of(context).size,
84+
);
85+
},
86+
child: Container(
87+
height: 50,
88+
decoration: BoxDecoration(
89+
color: Theme.of(context)
90+
.colorScheme
91+
.primaryContainer,
92+
borderRadius: const BorderRadius.vertical(
93+
top: Radius.circular(10),
94+
),
95+
),
96+
child: Row(
97+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
98+
children: [
99+
Row(
100+
children: [
101+
kHSpacer20,
102+
DashbotIcons.getDashbotIcon1(width: 38),
103+
kHSpacer12,
104+
Text(
105+
'DashBot',
106+
style: TextStyle(
107+
fontSize: 16,
108+
fontWeight: FontWeight.bold,
109+
color: Theme.of(context)
110+
.colorScheme
111+
.surface,
112+
),
113+
),
114+
kHSpacer4,
115+
AIModelSelectorButton(
116+
aiRequestModel: AIRequestModel.fromJson(
117+
settings.defaultAIModel ?? {}),
118+
useRootNavigator: true,
119+
onDialogOpen: () => ref
120+
.read(dashbotWindowNotifierProvider
121+
.notifier)
122+
.hide(),
123+
onDialogClose: () => ref
124+
.read(dashbotWindowNotifierProvider
125+
.notifier)
126+
.show(),
127+
onModelUpdated: (d) {
128+
ref
129+
.read(settingsProvider.notifier)
130+
.update(
131+
defaultAIModel: d.copyWith(
132+
modelConfigs: [],
133+
stream: null,
134+
systemPrompt: '',
135+
userPrompt: '').toJson());
136+
},
137+
),
138+
],
139+
),
140+
Spacer(),
141+
IconButton(
142+
icon: Icon(
143+
Icons.open_in_new,
144+
color:
145+
Theme.of(context).colorScheme.onPrimary,
146+
),
147+
onPressed: () {
148+
ref
149+
.read(dashbotWindowNotifierProvider
150+
.notifier)
151+
.togglePopped();
152+
},
153+
),
154+
IconButton(
155+
icon: Icon(
156+
Icons.close,
157+
color:
158+
Theme.of(context).colorScheme.onPrimary,
159+
),
160+
onPressed: onClose,
161+
),
162+
],
163+
),
164+
),
165+
),
166+
Expanded(
167+
child: Navigator(
168+
key: _dashbotNavigatorKey,
169+
initialRoute: activeRoute,
170+
onGenerateRoute: generateRoute,
171+
),
172+
),
173+
],
174+
),
175+
// This is to update size
176+
Positioned(
177+
left: 0,
178+
top: 0,
179+
child: GestureDetector(
180+
onPanUpdate: (details) {
181+
windowNotifier.updateSize(
182+
details.delta.dx,
183+
details.delta.dy,
184+
MediaQuery.of(context).size,
185+
);
186+
},
187+
child: MouseRegion(
188+
cursor: SystemMouseCursors.resizeUpLeft,
189+
child: Container(
190+
padding: EdgeInsets.only(top: 6, left: 1),
191+
width: 20,
192+
height: 20,
193+
decoration: BoxDecoration(
194+
borderRadius: const BorderRadius.only(
195+
topLeft: Radius.circular(8),
196+
),
197+
color: Theme.of(context)
198+
.colorScheme
199+
.primaryContainer
200+
.withValues(alpha: 0.7),
201+
),
202+
child: Icon(
203+
Icons.drag_indicator_rounded,
204+
size: 16,
205+
color:
206+
Theme.of(context).colorScheme.surfaceBright,
207+
),
208+
),
209+
),
210+
),
211+
),
212+
],
213+
),
214+
),
215+
),
216+
),
217+
],
218+
);
219+
}
220+
}

0 commit comments

Comments
 (0)