An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix save attachements in messages table
oussamadhouib7330dbd65c9e
diff --git a/lib/db/chat.ts b/lib/db/chat.tsindex 70195b6c..659ad417 100644--- a/lib/db/chat.ts+++ b/lib/db/chat.ts@@ -126,16 +126,26 @@ export async function deleteChat(// Add a message to a chatexport async function addMessage({- id, // Optional ID parameter+ id,chatId,role,parts}: {- id?: string // Make ID optional+ id?: stringchatId: stringrole: stringparts: any}): Promise<Message> {+ const attachments = Array.isArray(parts)+ ? parts+ .filter(part => part.type === 'file')+ .map(part => ({+ name: part.filename,+ url: part.url,+ contentType: part.mediaType+ }))+ : []+const valuesToInsert: {id?: stringchatId: string@@ -146,17 +156,14 @@ export async function addMessage({chatId,role,parts,- attachments: {}+ attachments}if (id) {- valuesToInsert.id = id // Set ID if provided+ valuesToInsert.id = id}- const [message] = await db- .insert(messages)- .values(valuesToInsert) // Use the modified values- .returning()+ const [message] = await db.insert(messages).values(valuesToInsert).returning()return message}@@ -235,6 +242,7 @@ export async function clearChats(userId: string): Promise<{ error?: string }> {// Save a chat (create or update)export async function saveChat(chat: Chat, userId: string) {+ console.log('chat', chat)try {// Check if the chat existsconst existingChat = await getChat(chat.id, userId)