diff --git a/src/apps/chat/trade/ImportChats.tsx b/src/apps/chat/trade/ImportChats.tsx index 3f97355b8..5e9bb0276 100644 --- a/src/apps/chat/trade/ImportChats.tsx +++ b/src/apps/chat/trade/ImportChats.tsx @@ -59,7 +59,7 @@ export function ImportConversations(props: { onClose: () => void }) { // import conversations (warning - will overwrite things) for (let conversation of [...outcome.conversations].reverse()) { if (conversation.success) - useChatStore.getState().importConversation(conversation.conversation); + useChatStore.getState().importConversation(conversation.conversation, false); } // show the outcome of the import @@ -109,7 +109,7 @@ export function ImportConversations(props: { onClose: () => void }) { // outcome const success = conversation.messages.length >= 1; if (success) { - useChatStore.getState().importConversation(conversation); + useChatStore.getState().importConversation(conversation, false); outcome.conversations.push({ success: true, fileName: 'chatgpt', conversation }); } else outcome.conversations.push({ success: false, fileName: 'chatgpt', error: `Empty conversation` }); diff --git a/src/common/state/store-chats.ts b/src/common/state/store-chats.ts index 1e0424094..e5c5df802 100644 --- a/src/common/state/store-chats.ts +++ b/src/common/state/store-chats.ts @@ -115,7 +115,7 @@ interface ChatActions { // store setters createConversation: () => void; duplicateConversation: (conversationId: string) => void; - importConversation: (conversation: DConversation) => void; + importConversation: (conversation: DConversation, preventClash: boolean) => void; deleteConversation: (conversationId: string) => void; deleteAllConversations: () => void; setActiveConversationId: (conversationId: string) => void; @@ -193,7 +193,15 @@ export const useChatStore = create()(devtools( }; }), - importConversation: (conversation: DConversation) => { + importConversation: (conversation: DConversation, preventClash) => { + // if we're importing a conversation with the same id as an existing one, we need to change the id + if (preventClash) { + const exists = get().conversations.some(c => c.id === conversation.id); + if (exists) { + conversation.id = uuidv4(); + console.warn('Conversation ID clash, changing ID to', conversation.id); + } + } get().deleteConversation(conversation.id); set(state => { conversation.tokenCount = updateTokenCounts(conversation.messages, true, 'importConversation');