diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx index b0ed17581b..3adbb157ad 100644 --- a/studio/frontend/src/features/chat/chat-page.tsx +++ b/studio/frontend/src/features/chat/chat-page.tsx @@ -537,6 +537,7 @@ export function ChatPage(): ReactElement { ); const handleNewCompare = useCallback( () => { + useArtifactStore.getState().clearArtifacts(); setView({ mode: "compare", pairId: crypto.randomUUID() }); useChatRuntimeStore.getState().setContextUsage(null); }, @@ -565,6 +566,7 @@ export function ChatPage(): ReactElement { const openSidebar = useCallback(() => setSidebarOpen(true), []); const enterCompare = useCallback(() => { + useArtifactStore.getState().clearArtifacts(); setViewBeforeCompare((prev) => prev ?? view); setView({ mode: "compare", pairId: crypto.randomUUID() }); useChatRuntimeStore.getState().setContextUsage(null); @@ -572,6 +574,7 @@ export function ChatPage(): ReactElement { const exitCompare = useCallback(() => { if (!viewBeforeCompare) return; + useArtifactStore.getState().clearArtifacts(); setView(viewBeforeCompare); setViewBeforeCompare(null); // Restore context usage from the active thread's last assistant message diff --git a/studio/frontend/src/features/chat/components/artifact-panel.tsx b/studio/frontend/src/features/chat/components/artifact-panel.tsx index 9e47507dc4..3232613aba 100644 --- a/studio/frontend/src/features/chat/components/artifact-panel.tsx +++ b/studio/frontend/src/features/chat/components/artifact-panel.tsx @@ -74,8 +74,10 @@ export const ArtifactPanel: FC = () => { // Sync local editor value when switching artifacts or versions useEffect(() => { - if (active) setLocalValue(viewedContent); - }, [active?.id, active?.activeVersion, viewedContent]); + if (!active) return; + setLocalValue(active.history[active.activeVersion] ?? active.content); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [active?.id, active?.activeVersion]); // Cleanup copy timer on unmount useEffect(() => { diff --git a/studio/frontend/src/features/chat/db.ts b/studio/frontend/src/features/chat/db.ts index 02cbfc14c5..6f116a63d1 100644 --- a/studio/frontend/src/features/chat/db.ts +++ b/studio/frontend/src/features/chat/db.ts @@ -62,7 +62,8 @@ db.version(4) .table("messages") .where("threadId") .equals(thread.id) - .sortBy("createdAt"); + .toArray(); + msgs.sort((a: MessageRecord, b: MessageRecord) => a.createdAt - b.createdAt); const firstUser = msgs.find( (m: MessageRecord) => m.role === "user", ); diff --git a/studio/frontend/src/features/chat/lib/thread-export.ts b/studio/frontend/src/features/chat/lib/thread-export.ts index f9491e3e9f..e1de70a257 100644 --- a/studio/frontend/src/features/chat/lib/thread-export.ts +++ b/studio/frontend/src/features/chat/lib/thread-export.ts @@ -102,7 +102,7 @@ function buildExportFilename( ): string { const base = sanitizeFilename(thread.title); const suffix = thread.pairId - ? `_${sanitizeFilename(thread.modelId || thread.modelType || "compare")}` + ? `_${sanitizeFilename(thread.modelType || thread.modelId || "compare")}` : ""; return `${base}${suffix}.${ext}`; } diff --git a/studio/frontend/src/features/chat/thread-sidebar.tsx b/studio/frontend/src/features/chat/thread-sidebar.tsx index 4521918094..3714d0efad 100644 --- a/studio/frontend/src/features/chat/thread-sidebar.tsx +++ b/studio/frontend/src/features/chat/thread-sidebar.tsx @@ -245,7 +245,9 @@ export function ThreadSidebar({ const handleDeleteFolder = useCallback(async (folderId: string) => { await db.transaction("rw", db.threads, db.folders, async () => { - await db.threads.where("folderId").equals(folderId).modify({ folderId: undefined }); + await db.threads.where("folderId").equals(folderId).modify((thread) => { + delete thread.folderId; + }); await db.folders.delete(folderId); }); }, []);