Skip to content

An AI-powered search engine with a generative UI

fix: resolve final TypeScript errors

Yoshiki Miura8a62eeaeee33
diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx
index b9351614..0763b762 100644
--- a/components/chat-panel.tsx
+++ b/components/chat-panel.tsx
@@ -94,8 +94,11 @@ export function ChatPanel({
const lastPart = parts[parts.length - 1]
return (
- lastPart?.type === 'tool-invocation' &&
- lastPart?.toolInvocation?.state === 'call'
+ (lastPart?.type === 'tool-search' ||
+ lastPart?.type === 'tool-retrieve' ||
+ lastPart?.type === 'tool-videoSearch' ||
+ lastPart?.type === 'tool-askQuestion') &&
+ ((lastPart as any)?.state === 'input-streaming' || (lastPart as any)?.state === 'input-available')
)
}
diff --git a/components/chat.tsx b/components/chat.tsx
index 03a8617d..b0ee6331 100644
--- a/components/chat.tsx
+++ b/components/chat.tsx
@@ -49,7 +49,7 @@ export function Chat({
sendMessage,
regenerate,
addToolResult
- } = useChat<UIMessage<unknown, UIDataTypes, UITools>>({
+ } = useChat({
api: '/api/chat',
body: {
chatId: id
@@ -73,7 +73,7 @@ export function Chat({
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (input.trim()) {
- sendMessage({ role: 'user', content: input })
+ sendMessage({ role: 'user' as const, parts: [{ type: 'text', text: input }] })
setInput('')
}
}
diff --git a/components/question-confirmation.tsx b/components/question-confirmation.tsx
index 875b76aa..800ec304 100644
--- a/components/question-confirmation.tsx
+++ b/components/question-confirmation.tsx
@@ -40,8 +40,8 @@ export function QuestionConfirmation({
onConfirm,
isCompleted = false
}: QuestionConfirmationProps) {
- const { question = '', options = [], allowsInput = false, inputLabel = '', inputPlaceholder = '' } =
- toolInvocation.input || {}
+ const input = (toolInvocation.input || {}) as QuestionInput
+ const { question = '', options = [], allowsInput = false, inputLabel = '', inputPlaceholder = '' } = input
// Get result data if available
const resultData =
diff --git a/components/retrieve-section.tsx b/components/retrieve-section.tsx
index 38e1f8fd..f601231f 100644
--- a/components/retrieve-section.tsx
+++ b/components/retrieve-section.tsx
@@ -30,7 +30,7 @@ export function RetrieveSection({
const isLoading = isToolLoading || isChatLoading
const data: SearchResultsType | undefined =
- tool.state === 'output-available' ? tool.output : undefined
+ tool.state === 'output-available' ? (tool.output || undefined) : undefined
const url = tool.input?.url
const { open } = useArtifact()
diff --git a/lib/schema/search.tsx b/lib/schema/search.tsx
index 614f6594..1742cdbc 100644
--- a/lib/schema/search.tsx
+++ b/lib/schema/search.tsx
@@ -51,8 +51,6 @@ export const strictSearchSchema = z.object({
* Uses the strict schema for OpenAI models starting with 'o'.
*/
export function getSearchSchemaForModel(fullModel: string) {
- return strictSearchSchema
-
const [provider, modelName] = fullModel?.split(':') ?? []
const useStrictSchema =
(provider === 'openai' || provider === 'azure') &&
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.ts
index b2cd880f..5ffbe151 100644
--- a/lib/streaming/create-chat-stream-response.ts
+++ b/lib/streaming/create-chat-stream-response.ts
@@ -66,8 +66,6 @@ export async function createChatStreamResponse(
writer.merge(
result.toUIMessageStream({
- generateId: () => generateUUID(),
- experimental_sendFinish: false,
onFinish: ({ responseMessage }) => {
// Store the messages for later use
firstResponseMessage = responseMessage
@@ -81,7 +79,6 @@ export async function createChatStreamResponse(
)
writer.merge(
relatedQuestions.toUIMessageStream({
- generateId: () => generateUUID(),
onFinish: ({ responseMessage }) => {
// If there is a first response message, merge it with the new message
if (firstResponseMessage) {
@@ -91,8 +88,7 @@ export async function createChatStreamResponse(
)
saveSingleMessage(chatId, mergedMessage)
}
- },
- experimental_sendStart: false
+ }
})
)
} catch (error) {
diff --git a/lib/tools/search.ts b/lib/tools/search.ts
index 85071309..69be6e68 100644
--- a/lib/tools/search.ts
+++ b/lib/tools/search.ts
@@ -115,8 +115,8 @@ export async function search(
query,
max_results: maxResults,
search_depth: searchDepth,
- include_domains: includeDomains,
- exclude_domains: excludeDomains
+ include_domains: includeDomains as any,
+ exclude_domains: excludeDomains as any
},
{
toolCallId: 'search',