feat: enhance chat import with multi-format support (#936)

* feat: enhance chat import with multi-format support

- Add support for importing chats from different formats:
  - Standard Bolt format
  - Chrome extension format
  - History array format
  - Bolt export format
- Add Import Chats button to Data Management
- Add proper error handling and logging
- Update README with backup/restore feature

* refactor: simplify chat import formats

- Remove multi-format support from DataTab
- Keep only standard Bolt export formats
- Simplify ImportButtons to handle standard format only
This commit is contained in:
Siddharth V
2025-01-07 06:46:42 -08:00
committed by GitHub
parent 7004c897f7
commit 4fd5040355
3 changed files with 91 additions and 6 deletions

View File

@@ -2,6 +2,11 @@ import type { Message } from 'ai';
import { toast } from 'react-toastify';
import { ImportFolderButton } from '~/components/chat/ImportFolderButton';
type ChatData = {
messages?: Message[]; // Standard Bolt format
description?: string; // Optional description
};
export function ImportButtons(importChat: ((description: string, messages: Message[]) => Promise<void>) | undefined) {
return (
<div className="flex flex-col items-center justify-center w-auto">
@@ -20,14 +25,16 @@ export function ImportButtons(importChat: ((description: string, messages: Messa
reader.onload = async (e) => {
try {
const content = e.target?.result as string;
const data = JSON.parse(content);
const data = JSON.parse(content) as ChatData;
if (!Array.isArray(data.messages)) {
toast.error('Invalid chat file format');
// Standard format
if (Array.isArray(data.messages)) {
await importChat(data.description || 'Imported Chat', data.messages);
toast.success('Chat imported successfully');
return;
}
await importChat(data.description, data.messages);
toast.success('Chat imported successfully');
toast.error('Invalid chat file format');
} catch (error: unknown) {
if (error instanceof Error) {
toast.error('Failed to parse chat file: ' + error.message);