An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: address PR review comments
Yoshiki Miura8a4f76701da8
diff --git a/lib/cache/memory-cache.ts b/lib/cache/memory-cache.tsindex 86d5134d..d586e592 100644--- a/lib/cache/memory-cache.ts+++ b/lib/cache/memory-cache.ts@@ -190,14 +190,16 @@ if (typeof process !== 'undefined' && process.on) {process.on('SIGINT', () => {console.log('\nGracefully shutting down cache...')cleanupCacheInterval()- process.exit(0)+ // Let the process exit naturally after cleanup+ process.exitCode = 0})// Graceful shutdown on SIGTERMprocess.on('SIGTERM', () => {console.log('\nGracefully shutting down cache...')cleanupCacheInterval()- process.exit(0)+ // Let the process exit naturally after cleanup+ process.exitCode = 0})// Cleanup before exitdiff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.tsindex 67b4eba5..f34f2803 100644--- a/lib/streaming/create-chat-stream-response.ts+++ b/lib/streaming/create-chat-stream-response.ts@@ -195,15 +195,15 @@ export async function createChatStreamResponse(// If no tool calls (just answering), skip related questionsif (!hasToolCallsInMessage) {// Save research message and generate title in parallel- const savePromises: Promise<any>[] = [- saveMessage(chatId, validResearchMessage)+ const saveOperations: (() => Promise<any>)[] = [+ () => saveMessage(chatId, validResearchMessage)]// Generate proper title after conversation startsif (!initialChat && message) {const userContent = getTextFromParts(message.parts)- savePromises.push(- generateChatTitle({+ saveOperations.push(+ () => generateChatTitle({userMessageContent: userContent,modelId}).then(async title => {@@ -214,14 +214,14 @@ export async function createChatStreamResponse(}// Execute saves in background with exponential backoff retry- Promise.all(savePromises).catch(async error => {+ Promise.all(saveOperations.map(op => op())).catch(async error => {console.error('Error saving message or title:', error)// Retry critical save operations with backofftry {- for (const promise of savePromises) {+ for (const operation of saveOperations) {await retryDatabaseOperation(- () => promise,+ operation,'save message/title')}@@ -280,24 +280,24 @@ export async function createChatStreamResponse(await relatedQuestionsPromise// Save the complete message after both agents finish- const savePromises: Promise<any>[] = []+ const saveOperations: (() => Promise<any>)[] = []if (validResearchMessage && relatedQuestionsMessage) {const mergedMessage = mergeUIMessages(validResearchMessage,relatedQuestionsMessage)- savePromises.push(saveMessage(chatId, mergedMessage))+ saveOperations.push(() => saveMessage(chatId, mergedMessage))} else if (validResearchMessage) {// Save research message only if related questions failed- savePromises.push(saveMessage(chatId, validResearchMessage))+ saveOperations.push(() => saveMessage(chatId, validResearchMessage))}// Generate proper title after conversation startsif (!initialChat && message) {const userContent = getTextFromParts(message.parts)- savePromises.push(- generateChatTitle({+ saveOperations.push(+ () => generateChatTitle({userMessageContent: userContent,modelId}).then(async title => {@@ -308,14 +308,14 @@ export async function createChatStreamResponse(}// Execute saves in background with exponential backoff retry- Promise.all(savePromises).catch(async error => {+ Promise.all(saveOperations.map(op => op())).catch(async error => {console.error('Error saving message or title:', error)// Retry critical save operations with backofftry {- for (const promise of savePromises) {+ for (const operation of saveOperations) {await retryDatabaseOperation(- () => promise,+ operation,'save message/title')}