LlamaFinetuneGGUF commited on
Commit
a9b15e5
·
1 Parent(s): fce8999

feat: Data Tab

Browse files

Removed Chat History Tab
Added Data Tab
Data tab can export and delete chat history, import API keys, import and export settings

app/components/settings/SettingsWindow.tsx CHANGED
@@ -5,27 +5,27 @@ import { classNames } from '~/utils/classNames';
5
  import { DialogTitle, dialogVariants, dialogBackdropVariants } from '~/components/ui/Dialog';
6
  import { IconButton } from '~/components/ui/IconButton';
7
  import styles from './Settings.module.scss';
8
- import ChatHistoryTab from './chat-history/ChatHistoryTab';
9
  import ProvidersTab from './providers/ProvidersTab';
10
  import { useSettings } from '~/lib/hooks/useSettings';
11
  import FeaturesTab from './features/FeaturesTab';
12
  import DebugTab from './debug/DebugTab';
13
  import EventLogsTab from './event-logs/EventLogsTab';
14
  import ConnectionsTab from './connections/ConnectionsTab';
 
15
 
16
  interface SettingsProps {
17
  open: boolean;
18
  onClose: () => void;
19
  }
20
 
21
- type TabType = 'chat-history' | 'providers' | 'features' | 'debug' | 'event-logs' | 'connection';
22
 
23
  export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
24
  const { debug, eventLogs } = useSettings();
25
- const [activeTab, setActiveTab] = useState<TabType>('chat-history');
26
 
27
  const tabs: { id: TabType; label: string; icon: string; component?: ReactElement }[] = [
28
- { id: 'chat-history', label: 'Chat History', icon: 'i-ph:book', component: <ChatHistoryTab /> },
29
  { id: 'providers', label: 'Providers', icon: 'i-ph:key', component: <ProvidersTab /> },
30
  { id: 'connection', label: 'Connection', icon: 'i-ph:link', component: <ConnectionsTab /> },
31
  { id: 'features', label: 'Features', icon: 'i-ph:star', component: <FeaturesTab /> },
 
5
  import { DialogTitle, dialogVariants, dialogBackdropVariants } from '~/components/ui/Dialog';
6
  import { IconButton } from '~/components/ui/IconButton';
7
  import styles from './Settings.module.scss';
 
8
  import ProvidersTab from './providers/ProvidersTab';
9
  import { useSettings } from '~/lib/hooks/useSettings';
10
  import FeaturesTab from './features/FeaturesTab';
11
  import DebugTab from './debug/DebugTab';
12
  import EventLogsTab from './event-logs/EventLogsTab';
13
  import ConnectionsTab from './connections/ConnectionsTab';
14
+ import DataTab from './data/DataTab';
15
 
16
  interface SettingsProps {
17
  open: boolean;
18
  onClose: () => void;
19
  }
20
 
21
+ type TabType = 'data' | 'providers' | 'features' | 'debug' | 'event-logs' | 'connection';
22
 
23
  export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
24
  const { debug, eventLogs } = useSettings();
25
+ const [activeTab, setActiveTab] = useState<TabType>('data');
26
 
27
  const tabs: { id: TabType; label: string; icon: string; component?: ReactElement }[] = [
28
+ { id: 'data', label: 'Data', icon: 'i-ph:database', component: <DataTab /> },
29
  { id: 'providers', label: 'Providers', icon: 'i-ph:key', component: <ProvidersTab /> },
30
  { id: 'connection', label: 'Connection', icon: 'i-ph:link', component: <ConnectionsTab /> },
31
  { id: 'features', label: 'Features', icon: 'i-ph:star', component: <FeaturesTab /> },
app/components/settings/chat-history/ChatHistoryTab.tsx DELETED
@@ -1,119 +0,0 @@
1
- import { useNavigate } from '@remix-run/react';
2
- import React, { useState } from 'react';
3
- import { toast } from 'react-toastify';
4
- import { db, deleteById, getAll } from '~/lib/persistence';
5
- import { classNames } from '~/utils/classNames';
6
- import styles from '~/components/settings/Settings.module.scss';
7
- import { logStore } from '~/lib/stores/logs'; // Import logStore for event logging
8
-
9
- export default function ChatHistoryTab() {
10
- const navigate = useNavigate();
11
- const [isDeleting, setIsDeleting] = useState(false);
12
- const downloadAsJson = (data: any, filename: string) => {
13
- const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
14
- const url = URL.createObjectURL(blob);
15
- const link = document.createElement('a');
16
- link.href = url;
17
- link.download = filename;
18
- document.body.appendChild(link);
19
- link.click();
20
- document.body.removeChild(link);
21
- URL.revokeObjectURL(url);
22
- };
23
-
24
- const handleDeleteAllChats = async () => {
25
- const confirmDelete = window.confirm('Are you sure you want to delete all chats? This action cannot be undone.');
26
-
27
- if (!confirmDelete) {
28
- return; // Exit if the user cancels
29
- }
30
-
31
- if (!db) {
32
- const error = new Error('Database is not available');
33
- logStore.logError('Failed to delete chats - DB unavailable', error);
34
- toast.error('Database is not available');
35
-
36
- return;
37
- }
38
-
39
- try {
40
- setIsDeleting(true);
41
-
42
- const allChats = await getAll(db);
43
- await Promise.all(allChats.map((chat) => deleteById(db!, chat.id)));
44
- logStore.logSystem('All chats deleted successfully', { count: allChats.length });
45
- toast.success('All chats deleted successfully');
46
- navigate('/', { replace: true });
47
- } catch (error) {
48
- logStore.logError('Failed to delete chats', error);
49
- toast.error('Failed to delete chats');
50
- console.error(error);
51
- } finally {
52
- setIsDeleting(false);
53
- }
54
- };
55
-
56
- const handleExportAllChats = async () => {
57
- if (!db) {
58
- const error = new Error('Database is not available');
59
- logStore.logError('Failed to export chats - DB unavailable', error);
60
- toast.error('Database is not available');
61
-
62
- return;
63
- }
64
-
65
- try {
66
- const allChats = await getAll(db);
67
- const exportData = {
68
- chats: allChats,
69
- exportDate: new Date().toISOString(),
70
- };
71
-
72
- downloadAsJson(exportData, `all-chats-${new Date().toISOString()}.json`);
73
- logStore.logSystem('Chats exported successfully', { count: allChats.length });
74
- toast.success('Chats exported successfully');
75
- } catch (error) {
76
- logStore.logError('Failed to export chats', error);
77
- toast.error('Failed to export chats');
78
- console.error(error);
79
- }
80
- };
81
-
82
- return (
83
- <>
84
- <div className="p-4">
85
- <h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Chat History</h3>
86
- <button
87
- onClick={handleExportAllChats}
88
- className={classNames(
89
- 'bg-bolt-elements-button-primary-background',
90
- 'rounded-lg px-4 py-2 mb-4 transition-colors duration-200',
91
- 'hover:bg-bolt-elements-button-primary-backgroundHover',
92
- 'text-bolt-elements-button-primary-text',
93
- )}
94
- >
95
- Export All Chats
96
- </button>
97
-
98
- <div
99
- className={classNames('text-bolt-elements-textPrimary rounded-lg py-4 mb-4', styles['settings-danger-area'])}
100
- >
101
- <h4 className="font-semibold">Danger Area</h4>
102
- <p className="mb-2">This action cannot be undone!</p>
103
- <button
104
- onClick={handleDeleteAllChats}
105
- disabled={isDeleting}
106
- className={classNames(
107
- 'bg-bolt-elements-button-danger-background',
108
- 'rounded-lg px-4 py-2 transition-colors duration-200',
109
- isDeleting ? 'opacity-50 cursor-not-allowed' : 'hover:bg-bolt-elements-button-danger-backgroundHover',
110
- 'text-bolt-elements-button-danger-text',
111
- )}
112
- >
113
- {isDeleting ? 'Deleting...' : 'Delete All Chats'}
114
- </button>
115
- </div>
116
- </div>
117
- </>
118
- );
119
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/components/settings/data/DataTab.tsx ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react';
2
+ import { useNavigate } from '@remix-run/react';
3
+ import Cookies from 'js-cookie';
4
+ import { toast } from 'react-toastify';
5
+ import { db, deleteById, getAll } from '~/lib/persistence';
6
+ import { logStore } from '~/lib/stores/logs';
7
+ import { classNames } from '~/utils/classNames';
8
+ import styles from '~/components/settings/Settings.module.scss';
9
+
10
+ // List of supported providers that can have API keys
11
+ const API_KEY_PROVIDERS = [
12
+ 'Anthropic',
13
+ 'OpenAI',
14
+ 'Google',
15
+ 'Groq',
16
+ 'HuggingFace',
17
+ 'OpenRouter',
18
+ 'Deepseek',
19
+ 'Mistral',
20
+ 'OpenAILike',
21
+ 'Together',
22
+ 'xAI',
23
+ 'Perplexity',
24
+ 'Cohere',
25
+ 'AzureOpenAI',
26
+ ] as const;
27
+
28
+ type Provider = typeof API_KEY_PROVIDERS[number];
29
+
30
+ interface ApiKeys {
31
+ [key: string]: string;
32
+ }
33
+
34
+ export default function DataTab() {
35
+ const navigate = useNavigate();
36
+ const [isDeleting, setIsDeleting] = useState(false);
37
+
38
+ const downloadAsJson = (data: any, filename: string) => {
39
+ const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
40
+ const url = URL.createObjectURL(blob);
41
+ const link = document.createElement('a');
42
+ link.href = url;
43
+ link.download = filename;
44
+ document.body.appendChild(link);
45
+ link.click();
46
+ document.body.removeChild(link);
47
+ URL.revokeObjectURL(url);
48
+ };
49
+
50
+ const handleExportAllChats = async () => {
51
+ if (!db) {
52
+ const error = new Error('Database is not available');
53
+ logStore.logError('Failed to export chats - DB unavailable', error);
54
+ toast.error('Database is not available');
55
+ return;
56
+ }
57
+
58
+ try {
59
+ const allChats = await getAll(db);
60
+ const exportData = {
61
+ chats: allChats,
62
+ exportDate: new Date().toISOString(),
63
+ };
64
+
65
+ downloadAsJson(exportData, `all-chats-${new Date().toISOString()}.json`);
66
+ logStore.logSystem('Chats exported successfully', { count: allChats.length });
67
+ toast.success('Chats exported successfully');
68
+ } catch (error) {
69
+ logStore.logError('Failed to export chats', error);
70
+ toast.error('Failed to export chats');
71
+ console.error(error);
72
+ }
73
+ };
74
+
75
+ const handleDeleteAllChats = async () => {
76
+ const confirmDelete = window.confirm('Are you sure you want to delete all chats? This action cannot be undone.');
77
+
78
+ if (!confirmDelete) {
79
+ return;
80
+ }
81
+
82
+ if (!db) {
83
+ const error = new Error('Database is not available');
84
+ logStore.logError('Failed to delete chats - DB unavailable', error);
85
+ toast.error('Database is not available');
86
+ return;
87
+ }
88
+
89
+ try {
90
+ setIsDeleting(true);
91
+ const allChats = await getAll(db);
92
+ await Promise.all(allChats.map((chat) => deleteById(db!, chat.id)));
93
+ logStore.logSystem('All chats deleted successfully', { count: allChats.length });
94
+ toast.success('All chats deleted successfully');
95
+ navigate('/', { replace: true });
96
+ } catch (error) {
97
+ logStore.logError('Failed to delete chats', error);
98
+ toast.error('Failed to delete chats');
99
+ console.error(error);
100
+ } finally {
101
+ setIsDeleting(false);
102
+ }
103
+ };
104
+
105
+ const handleExportSettings = () => {
106
+ const settings = {
107
+ providers: Cookies.get('providers'),
108
+ isDebugEnabled: Cookies.get('isDebugEnabled'),
109
+ isEventLogsEnabled: Cookies.get('isEventLogsEnabled'),
110
+ isLocalModelsEnabled: Cookies.get('isLocalModelsEnabled'),
111
+ promptId: Cookies.get('promptId'),
112
+ isLatestBranch: Cookies.get('isLatestBranch'),
113
+ commitHash: Cookies.get('commitHash'),
114
+ eventLogs: Cookies.get('eventLogs'),
115
+ selectedModel: Cookies.get('selectedModel'),
116
+ selectedProvider: Cookies.get('selectedProvider'),
117
+ githubUsername: Cookies.get('githubUsername'),
118
+ githubToken: Cookies.get('githubToken'),
119
+ bolt_theme: localStorage.getItem('bolt_theme'),
120
+ };
121
+
122
+ downloadAsJson(settings, 'bolt-settings.json');
123
+ toast.success('Settings exported successfully');
124
+ };
125
+
126
+ const handleImportSettings = (event: React.ChangeEvent<HTMLInputElement>) => {
127
+ const file = event.target.files?.[0];
128
+ if (!file) return;
129
+
130
+ const reader = new FileReader();
131
+ reader.onload = (e) => {
132
+ try {
133
+ const settings = JSON.parse(e.target?.result as string);
134
+
135
+ Object.entries(settings).forEach(([key, value]) => {
136
+ if (key === 'bolt_theme') {
137
+ if (value) localStorage.setItem(key, value as string);
138
+ } else if (value) {
139
+ Cookies.set(key, value as string);
140
+ }
141
+ });
142
+
143
+ toast.success('Settings imported successfully. Please refresh the page for changes to take effect.');
144
+ } catch (error) {
145
+ toast.error('Failed to import settings. Make sure the file is a valid JSON file.');
146
+ console.error('Failed to import settings:', error);
147
+ }
148
+ };
149
+ reader.readAsText(file);
150
+ event.target.value = '';
151
+ };
152
+
153
+ const handleExportApiKeyTemplate = () => {
154
+ const template: ApiKeys = {};
155
+ API_KEY_PROVIDERS.forEach(provider => {
156
+ template[`${provider}_API_KEY`] = '';
157
+ });
158
+
159
+ template['OPENAI_LIKE_API_BASE_URL'] = '';
160
+ template['LMSTUDIO_API_BASE_URL'] = '';
161
+ template['OLLAMA_API_BASE_URL'] = '';
162
+ template['TOGETHER_API_BASE_URL'] = '';
163
+
164
+ downloadAsJson(template, 'api-keys-template.json');
165
+ toast.success('API keys template exported successfully');
166
+ };
167
+
168
+ const handleImportApiKeys = (event: React.ChangeEvent<HTMLInputElement>) => {
169
+ const file = event.target.files?.[0];
170
+ if (!file) return;
171
+
172
+ const reader = new FileReader();
173
+ reader.onload = (e) => {
174
+ try {
175
+ const apiKeys = JSON.parse(e.target?.result as string);
176
+ let importedCount = 0;
177
+
178
+ API_KEY_PROVIDERS.forEach(provider => {
179
+ const keyName = `${provider}_API_KEY`;
180
+ if (apiKeys[keyName]) {
181
+ Cookies.set(keyName, apiKeys[keyName]);
182
+ importedCount++;
183
+ }
184
+ });
185
+
186
+ ['OPENAI_LIKE_API_BASE_URL', 'LMSTUDIO_API_BASE_URL', 'OLLAMA_API_BASE_URL', 'TOGETHER_API_BASE_URL'].forEach(baseUrl => {
187
+ if (apiKeys[baseUrl]) {
188
+ Cookies.set(baseUrl, apiKeys[baseUrl]);
189
+ importedCount++;
190
+ }
191
+ });
192
+
193
+ if (importedCount > 0) {
194
+ toast.success(`Successfully imported ${importedCount} API keys/URLs`);
195
+ } else {
196
+ toast.warn('No valid API keys found in the file');
197
+ }
198
+ } catch (error) {
199
+ toast.error('Failed to import API keys. Make sure the file is a valid JSON file.');
200
+ console.error('Failed to import API keys:', error);
201
+ }
202
+ };
203
+ reader.readAsText(file);
204
+ event.target.value = '';
205
+ };
206
+
207
+ return (
208
+ <div className="p-4 bg-bolt-elements-bg-depth-2 border border-bolt-elements-borderColor rounded-lg mb-4">
209
+ <div className="mb-6">
210
+ <h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Data Management</h3>
211
+ <div className="space-y-8">
212
+ <div className="flex flex-col gap-4">
213
+ <div>
214
+ <h4 className="text-bolt-elements-textPrimary mb-2">Chat History</h4>
215
+ <p className="text-sm text-bolt-elements-textSecondary mb-4">
216
+ Export or delete all your chat history.
217
+ </p>
218
+ <div className="flex gap-4">
219
+ <button
220
+ onClick={handleExportAllChats}
221
+ className="px-4 py-2 bg-bolt-elements-button-primary-background hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-textPrimary rounded-lg transition-colors"
222
+ >
223
+ Export All Chats
224
+ </button>
225
+ <button
226
+ onClick={handleDeleteAllChats}
227
+ disabled={isDeleting}
228
+ className={classNames(
229
+ 'px-4 py-2 bg-bolt-elements-button-danger-background hover:bg-bolt-elements-button-danger-backgroundHover text-bolt-elements-button-danger-text rounded-lg transition-colors',
230
+ isDeleting && 'opacity-50 cursor-not-allowed'
231
+ )}
232
+ >
233
+ {isDeleting ? 'Deleting...' : 'Delete All Chats'}
234
+ </button>
235
+ </div>
236
+ </div>
237
+
238
+ <div>
239
+ <h4 className="text-bolt-elements-textPrimary mb-2">Settings Backup</h4>
240
+ <p className="text-sm text-bolt-elements-textSecondary mb-4">
241
+ Export your settings to a JSON file or import settings from a previously exported file.
242
+ </p>
243
+ <div className="flex gap-4">
244
+ <button
245
+ onClick={handleExportSettings}
246
+ className="px-4 py-2 bg-bolt-elements-button-primary-background hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-textPrimary rounded-lg transition-colors"
247
+ >
248
+ Export Settings
249
+ </button>
250
+ <label className="px-4 py-2 bg-bolt-elements-button-primary-background hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-textPrimary rounded-lg transition-colors cursor-pointer">
251
+ Import Settings
252
+ <input
253
+ type="file"
254
+ accept=".json"
255
+ onChange={handleImportSettings}
256
+ className="hidden"
257
+ />
258
+ </label>
259
+ </div>
260
+ </div>
261
+
262
+ <div>
263
+ <h4 className="text-bolt-elements-textPrimary mb-2">API Keys Management</h4>
264
+ <p className="text-sm text-bolt-elements-textSecondary mb-4">
265
+ Import API keys from a JSON file or download a template to fill in your keys.
266
+ </p>
267
+ <div className="flex gap-4">
268
+ <button
269
+ onClick={handleExportApiKeyTemplate}
270
+ className="px-4 py-2 bg-bolt-elements-button-primary-background hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-textPrimary rounded-lg transition-colors"
271
+ >
272
+ Download Template
273
+ </button>
274
+ <label className="px-4 py-2 bg-bolt-elements-button-primary-background hover:bg-bolt-elements-button-primary-backgroundHover text-bolt-elements-textPrimary rounded-lg transition-colors cursor-pointer">
275
+ Import API Keys
276
+ <input
277
+ type="file"
278
+ accept=".json"
279
+ onChange={handleImportApiKeys}
280
+ className="hidden"
281
+ />
282
+ </label>
283
+ </div>
284
+ </div>
285
+ </div>
286
+ </div>
287
+ </div>
288
+ </div>
289
+ );
290
+ }