@@ -7,6 +7,7 @@ import { browser } from '$app/environment';
77import { goto } from '$app/navigation' ;
88import { extractPartialThinking } from '$lib/utils/thinking' ;
99import { toast } from 'svelte-sonner' ;
10+ import type { ExportedConversations } from '$lib/types/database' ;
1011
1112/**
1213 * ChatStore - Central state management for chat conversations and AI interactions
@@ -971,8 +972,8 @@ class ChatStore {
971972 this . triggerDownload ( conversationData ) ;
972973 } else {
973974 // Use current active conversation data
974- const conversationData = {
975- conv : this . activeConversation ,
975+ const conversationData : ExportedConversations = {
976+ conv : this . activeConversation ! ,
976977 messages : this . activeMessages
977978 } ;
978979
@@ -985,8 +986,12 @@ class ChatStore {
985986 * @param data - Data to download (expected: { conv: DatabaseConversation, messages: DatabaseMessage[] })
986987 * @param filename - Optional filename
987988 */
988- private triggerDownload ( data : any , filename ?: string ) : void {
989- const conversation = data . conv || data ;
989+ private triggerDownload ( data : ExportedConversations , filename ?: string ) : void {
990+ const conversation = 'conv' in data ? data . conv : ( Array . isArray ( data ) ? data [ 0 ] ?. conv : undefined ) ;
991+ if ( ! conversation ) {
992+ console . error ( 'Invalid data: missing conversation' ) ;
993+ return ;
994+ }
990995 const conversationName = conversation . name ? conversation . name . trim ( ) : '' ;
991996 const convId = conversation . id || 'unknown' ;
992997 const truncatedSuffix = conversationName . toLowerCase ( )
@@ -1017,7 +1022,7 @@ class ChatStore {
10171022 throw new Error ( 'No conversations to export' ) ;
10181023 }
10191024
1020- const allData = await Promise . all (
1025+ const allData : ExportedConversations = await Promise . all (
10211026 allConversations . map ( async ( conv ) => {
10221027 const messages = await DatabaseStore . getConversationMessages ( conv . id ) ;
10231028 return { conv, messages } ;
@@ -1064,9 +1069,7 @@ class ChatStore {
10641069 try {
10651070 const text = await file . text ( ) ;
10661071 const parsedData = JSON . parse ( text ) ;
1067-
1068- // Handle both single conversation object and array of conversations
1069- let importedData : { conv : DatabaseConversation ; messages : DatabaseMessage [ ] } [ ] ;
1072+ let importedData : ExportedConversations ;
10701073
10711074 if ( Array . isArray ( parsedData ) ) {
10721075 importedData = parsedData ;
0 commit comments