feat; data tab added to the settings
Browse filesadded a data tab to the settings
removed chat history
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 = '
|
| 22 |
|
| 23 |
export const SettingsWindow = ({ open, onClose }: SettingsProps) => {
|
| 24 |
const { debug, eventLogs } = useSettings();
|
| 25 |
-
const [activeTab, setActiveTab] = useState<TabType>('
|
| 26 |
|
| 27 |
const tabs: { id: TabType; label: string; icon: string; component?: ReactElement }[] = [
|
| 28 |
-
{ id: '
|
| 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,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
const consolidatedKeys: Record<string, string> = {};
|
| 178 |
+
|
| 179 |
+
API_KEY_PROVIDERS.forEach(provider => {
|
| 180 |
+
const keyName = `${provider}_API_KEY`;
|
| 181 |
+
if (apiKeys[keyName]) {
|
| 182 |
+
consolidatedKeys[provider] = apiKeys[keyName];
|
| 183 |
+
importedCount++;
|
| 184 |
+
}
|
| 185 |
+
});
|
| 186 |
+
|
| 187 |
+
if (importedCount > 0) {
|
| 188 |
+
// Store all API keys in a single cookie as JSON
|
| 189 |
+
Cookies.set('apiKeys', JSON.stringify(consolidatedKeys));
|
| 190 |
+
|
| 191 |
+
// Also set individual cookies for backward compatibility
|
| 192 |
+
Object.entries(consolidatedKeys).forEach(([provider, key]) => {
|
| 193 |
+
Cookies.set(`${provider}_API_KEY`, key);
|
| 194 |
+
});
|
| 195 |
+
|
| 196 |
+
toast.success(`Successfully imported ${importedCount} API keys/URLs. Refreshing page to apply changes...`);
|
| 197 |
+
// Reload the page after a short delay to allow the toast to be seen
|
| 198 |
+
setTimeout(() => {
|
| 199 |
+
window.location.reload();
|
| 200 |
+
}, 1500);
|
| 201 |
+
} else {
|
| 202 |
+
toast.warn('No valid API keys found in the file');
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
// Set base URLs if they exist
|
| 206 |
+
['OPENAI_LIKE_API_BASE_URL', 'LMSTUDIO_API_BASE_URL', 'OLLAMA_API_BASE_URL', 'TOGETHER_API_BASE_URL'].forEach(baseUrl => {
|
| 207 |
+
if (apiKeys[baseUrl]) {
|
| 208 |
+
Cookies.set(baseUrl, apiKeys[baseUrl]);
|
| 209 |
+
}
|
| 210 |
+
});
|
| 211 |
+
|
| 212 |
+
} catch (error) {
|
| 213 |
+
toast.error('Failed to import API keys. Make sure the file is a valid JSON file.');
|
| 214 |
+
console.error('Failed to import API keys:', error);
|
| 215 |
+
}
|
| 216 |
+
};
|
| 217 |
+
reader.readAsText(file);
|
| 218 |
+
event.target.value = '';
|
| 219 |
+
};
|
| 220 |
+
|
| 221 |
+
return (
|
| 222 |
+
<div className="p-4 bg-bolt-elements-bg-depth-2 border border-bolt-elements-borderColor rounded-lg mb-4">
|
| 223 |
+
<div className="mb-6">
|
| 224 |
+
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Data Management</h3>
|
| 225 |
+
<div className="space-y-8">
|
| 226 |
+
<div className="flex flex-col gap-4">
|
| 227 |
+
<div>
|
| 228 |
+
<h4 className="text-bolt-elements-textPrimary mb-2">Chat History</h4>
|
| 229 |
+
<p className="text-sm text-bolt-elements-textSecondary mb-4">
|
| 230 |
+
Export or delete all your chat history.
|
| 231 |
+
</p>
|
| 232 |
+
<div className="flex gap-4">
|
| 233 |
+
<button
|
| 234 |
+
onClick={handleExportAllChats}
|
| 235 |
+
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"
|
| 236 |
+
>
|
| 237 |
+
Export All Chats
|
| 238 |
+
</button>
|
| 239 |
+
<button
|
| 240 |
+
onClick={handleDeleteAllChats}
|
| 241 |
+
disabled={isDeleting}
|
| 242 |
+
className={classNames(
|
| 243 |
+
'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',
|
| 244 |
+
isDeleting ? 'opacity-50 cursor-not-allowed' : ''
|
| 245 |
+
)}
|
| 246 |
+
>
|
| 247 |
+
{isDeleting ? 'Deleting...' : 'Delete All Chats'}
|
| 248 |
+
</button>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
|
| 252 |
+
<div>
|
| 253 |
+
<h4 className="text-bolt-elements-textPrimary mb-2">Settings Backup</h4>
|
| 254 |
+
<p className="text-sm text-bolt-elements-textSecondary mb-4">
|
| 255 |
+
Export your settings to a JSON file or import settings from a previously exported file.
|
| 256 |
+
</p>
|
| 257 |
+
<div className="flex gap-4">
|
| 258 |
+
<button
|
| 259 |
+
onClick={handleExportSettings}
|
| 260 |
+
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"
|
| 261 |
+
>
|
| 262 |
+
Export Settings
|
| 263 |
+
</button>
|
| 264 |
+
<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">
|
| 265 |
+
Import Settings
|
| 266 |
+
<input
|
| 267 |
+
type="file"
|
| 268 |
+
accept=".json"
|
| 269 |
+
onChange={handleImportSettings}
|
| 270 |
+
className="hidden"
|
| 271 |
+
/>
|
| 272 |
+
</label>
|
| 273 |
+
</div>
|
| 274 |
+
</div>
|
| 275 |
+
|
| 276 |
+
<div>
|
| 277 |
+
<h4 className="text-bolt-elements-textPrimary mb-2">API Keys Management</h4>
|
| 278 |
+
<p className="text-sm text-bolt-elements-textSecondary mb-4">
|
| 279 |
+
Import API keys from a JSON file or download a template to fill in your keys.
|
| 280 |
+
</p>
|
| 281 |
+
<div className="flex gap-4">
|
| 282 |
+
<button
|
| 283 |
+
onClick={handleExportApiKeyTemplate}
|
| 284 |
+
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"
|
| 285 |
+
>
|
| 286 |
+
Download Template
|
| 287 |
+
</button>
|
| 288 |
+
<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">
|
| 289 |
+
Import API Keys
|
| 290 |
+
<input
|
| 291 |
+
type="file"
|
| 292 |
+
accept=".json"
|
| 293 |
+
onChange={handleImportApiKeys}
|
| 294 |
+
className="hidden"
|
| 295 |
+
/>
|
| 296 |
+
</label>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
</div>
|
| 302 |
+
</div>
|
| 303 |
+
);
|
| 304 |
+
}
|