diff --git a/examples/server/public/index.html.gz b/examples/server/public/index.html.gz index 141e80920..d32d05396 100644 Binary files a/examples/server/public/index.html.gz and b/examples/server/public/index.html.gz differ diff --git a/examples/server/webui/src/App.tsx b/examples/server/webui/src/App.tsx index 3e90ec55c..2ce734682 100644 --- a/examples/server/webui/src/App.tsx +++ b/examples/server/webui/src/App.tsx @@ -1,4 +1,4 @@ -import { HashRouter, Outlet, Route, Routes, Navigate } from 'react-router'; +import { HashRouter, Outlet, Route, Routes } from 'react-router'; import Header from './components/Header'; import Sidebar from './components/Sidebar'; import { AppContextProvider, useAppContext } from './utils/app.context'; diff --git a/examples/server/webui/src/utils/storage.ts b/examples/server/webui/src/utils/storage.ts index c30f7f0b9..05cf4fa20 100644 --- a/examples/server/webui/src/utils/storage.ts +++ b/examples/server/webui/src/utils/storage.ts @@ -36,6 +36,7 @@ const StorageUtils = { * manage conversations */ async getAllConversations(): Promise { + await migrationLStoIDB().catch(console.error); // noop if already migrated return (await db.conversations.toArray()).sort( (a, b) => b.lastModified - a.lastModified ); @@ -211,7 +212,6 @@ interface LSConversation { id: string; // format: `conv-{timestamp}` lastModified: number; // timestamp from Date.now() messages: LSMessage[]; - migrated?: boolean; // additionally, we add a flag to prevent duplicate migration } interface LSMessage { id: number; @@ -220,6 +220,7 @@ interface LSMessage { timings?: TimingReport; } async function migrationLStoIDB() { + if (localStorage.getItem('migratedToIDB')) return; const res: LSConversation[] = []; for (const key in localStorage) { if (key.startsWith('conv-')) { @@ -233,10 +234,6 @@ async function migrationLStoIDB() { const { id: convId, lastModified, messages } = conv; const firstMsg = messages[0]; const lastMsg = messages.at(-1); - if (conv.migrated) { - console.log(`Skipping conversation ${convId} already migrated`); - continue; - } if (messages.length < 2 || !firstMsg || !lastMsg) { console.log( `Skipping conversation ${convId} with ${messages.length} messages` @@ -250,12 +247,12 @@ async function migrationLStoIDB() { currNode: lastMsg.id, name, }); - const rootId = Date.now(); + const rootId = messages[0].id - 2; await db.messages.add({ id: rootId, convId: convId, type: 'root', - timestamp: lastModified, + timestamp: rootId, role: 'system', content: '', parent: -1, @@ -272,7 +269,6 @@ async function migrationLStoIDB() { children: i === messages.length - 1 ? [] : [messages[i + 1].id], }); } - localStorage.setItem(convId, JSON.stringify({ ...conv, migrated: true })); migratedCount++; console.log( `Migrated conversation ${convId} with ${messages.length} messages` @@ -281,7 +277,6 @@ async function migrationLStoIDB() { console.log( `Migrated ${migratedCount} conversations from localStorage to IndexedDB` ); + localStorage.setItem('migratedToIDB', '1'); }); } - -migrationLStoIDB();