Merge remote-tracking branch 'coleam00/main' into import-export-individual-chats
# Conflicts: # app/components/chat/BaseChat.tsx # app/components/chat/Messages.client.tsx # app/lib/persistence/db.ts # app/lib/persistence/useChatHistory.ts
This commit is contained in:
@@ -161,11 +161,17 @@ async function getUrlIds(db: IDBDatabase): Promise<string[]> {
|
||||
|
||||
export async function forkChat(db: IDBDatabase, chatId: string, messageId: string): Promise<string> {
|
||||
const chat = await getMessages(db, chatId);
|
||||
if (!chat) throw new Error('Chat not found');
|
||||
|
||||
if (!chat) {
|
||||
throw new Error('Chat not found');
|
||||
}
|
||||
|
||||
// Find the index of the message to fork at
|
||||
const messageIndex = chat.messages.findIndex(msg => msg.id === messageId);
|
||||
if (messageIndex === -1) throw new Error('Message not found');
|
||||
const messageIndex = chat.messages.findIndex((msg) => msg.id === messageId);
|
||||
|
||||
if (messageIndex === -1) {
|
||||
throw new Error('Message not found');
|
||||
}
|
||||
|
||||
// Get messages up to and including the selected message
|
||||
const messages = chat.messages.slice(0, messageIndex + 1);
|
||||
@@ -177,6 +183,7 @@ export async function forkChat(db: IDBDatabase, chatId: string, messageId: strin
|
||||
|
||||
export async function duplicateChat(db: IDBDatabase, id: string): Promise<string> {
|
||||
const chat = await getMessages(db, id);
|
||||
|
||||
if (!chat) {
|
||||
throw new Error('Chat not found');
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ export function useChatHistory() {
|
||||
|
||||
await setMessages(db, chatId.get() as string, messages, urlId, description.get());
|
||||
},
|
||||
duplicateCurrentChat: async (listItemId:string) => {
|
||||
duplicateCurrentChat: async (listItemId: string) => {
|
||||
if (!db || (!mixedId && !listItemId)) {
|
||||
return;
|
||||
}
|
||||
@@ -118,6 +118,7 @@ export function useChatHistory() {
|
||||
toast.success('Chat duplicated successfully');
|
||||
} catch (error) {
|
||||
toast.error('Failed to duplicate chat');
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
importChat: async (description: string, messages:Message[]) => {
|
||||
|
||||
Reference in New Issue
Block a user