An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
refactor: address Copilot type safety review comments
Yoshiki Miuraa18d1605396c
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.tsindex 7704744e..950c0cf4 100644--- a/lib/streaming/create-chat-stream-response.ts+++ b/lib/streaming/create-chat-stream-response.ts@@ -17,7 +17,11 @@ import {import { generateRelatedQuestions } from '../agents/generate-related-questions'import { generateChatTitle } from '../agents/title-generator'import { generateId } from '../db/schema'-import { getTextFromParts, mergeUIMessages } from '../utils/message-utils'+import {+ getTextFromParts,+ hasToolCalls,+ mergeUIMessages+} from '../utils/message-utils'import { BaseStreamConfig } from './types'@@ -164,16 +168,10 @@ export async function createChatStreamResponse(const validResearchMessage: UIMessage = researchMessage// Check if the research message contains tool calls- const hasToolCalls =- validResearchMessage.parts &&- validResearchMessage.parts.some(- (part: any) =>- part.type &&- (part.type.startsWith('tool-') || part.type === 'tool-call')- )+ const hasToolCallsInMessage = hasToolCalls(validResearchMessage)// If no tool calls (just answering), skip related questions- if (!hasToolCalls) {+ if (!hasToolCallsInMessage) {// Save research messageawait saveMessage(chatId, validResearchMessage)diff --git a/lib/streaming/message-preparation.ts b/lib/streaming/message-preparation.tsindex 72a20d14..f4cafd89 100644--- a/lib/streaming/message-preparation.ts+++ b/lib/streaming/message-preparation.ts@@ -6,6 +6,7 @@ import {getChat as getChatAction,saveMessage} from '@/lib/actions/chat'+import type { Chat } from '@/lib/db/schema'import { generateId } from '@/lib/db/schema'// Constants@@ -75,7 +76,7 @@ export async function prepareMessagesForSubmission(chatId: string,userId: string,message: UIMessage,- chat: any+ chat: Chat | null): Promise<UIMessage[]> {if (!message) {throw new Error('No message provided')diff --git a/lib/utils/message-utils.ts b/lib/utils/message-utils.tsindex e1d0910b..ed22a9fe 100644--- a/lib/utils/message-utils.ts+++ b/lib/utils/message-utils.ts@@ -125,7 +125,7 @@ export function hasToolCalls(message: UIMessage | null): boolean {if (!message || !message.parts) return falsereturn message.parts.some(- (part: any) =>+ part =>part.type && (part.type.startsWith('tool-') || part.type === 'tool-call'))}