An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
remvoed any types where possible
Anusha Yellad8b9e9c278c2
diff --git a/app/actions.tsx b/app/actions.tsxindex 0212918f..091ea457 100644--- a/app/actions.tsx+++ b/app/actions.tsx@@ -31,13 +31,18 @@ async function submit(formData?: FormData, skip?: boolean) {const isGenerating = createStreamableValue(true)const isCollapsed = createStreamableValue(false)// Get the messages from the state, filter out the tool messages- const messages: CoreMessage[] = [...(aiState.get().messages as any[])].filter(- message =>- message.role !== 'tool' &&- message.type !== 'followup' &&- message.type !== 'related' &&- message.type !== 'end'- )+ const messages: CoreMessage[] = [...aiState.get().messages]+ .filter(+ message =>+ message.role !== 'tool' &&+ message.type !== 'followup' &&+ message.type !== 'related' &&+ message.type !== 'end'+ )+ .map(message => {+ const { role, content } = message+ return { role, content } as CoreMessage+ })// goupeiId is used to group the messages for collapseconst groupeId = nanoid()@@ -85,7 +90,7 @@ async function submit(formData?: FormData, skip?: boolean) {}async function processEvents() {- let action: any = { object: { next: 'proceed' } }+ let action = { object: { next: 'proceed' } }// If the user skips the task, we proceed to the searchif (!skip) action = (await taskManager(messages)) ?? actiondiff --git a/components/chat-messages.tsx b/components/chat-messages.tsxindex 6bfa3642..9c803ce7 100644--- a/components/chat-messages.tsx+++ b/components/chat-messages.tsx@@ -1,13 +1,19 @@'use client'-import { StreamableValue, useUIState } from 'ai/rsc'-import type { AI, UIState } from '@/app/actions'+import { StreamableValue } from 'ai/rsc'+import type { UIState } from '@/app/actions'import { CollapsibleMessage } from './collapsible-message'interface ChatMessagesProps {messages: UIState}+type GroupedMessage = {+ id: string+ components: React.ReactNode[]+ isCollapsed?: StreamableValue<boolean> | undefined+}+export function ChatMessages({ messages }: ChatMessagesProps) {if (!messages.length) {return null@@ -15,7 +21,7 @@ export function ChatMessages({ messages }: ChatMessagesProps) {// Group messages based on ID, and if there are multiple messages with the same ID, combine them into one messageconst groupedMessages = messages.reduce(- (acc: { [key: string]: any }, message) => {+ (acc: { [key: string]: GroupedMessage }, message) => {if (!acc[message.id]) {acc[message.id] = {id: message.id,@@ -41,30 +47,19 @@ export function ChatMessages({ messages }: ChatMessagesProps) {return (<>- {groupedMessagesArray.map(- (- groupedMessage: {- id: string- components: React.ReactNode[]- isCollapsed?: StreamableValue<boolean>- },- index- ) => (- <CollapsibleMessage- key={`${groupedMessage.id}`}- message={{- id: groupedMessage.id,- component: groupedMessage.components.map((component, i) => (- <div key={`${groupedMessage.id}-${i}`}>{component}</div>- )),- isCollapsed: groupedMessage.isCollapsed- }}- isLastMessage={- groupedMessage.id === messages[messages.length - 1].id- }- />- )- )}+ {groupedMessagesArray.map((groupedMessage: GroupedMessage) => (+ <CollapsibleMessage+ key={`${groupedMessage.id}`}+ message={{+ id: groupedMessage.id,+ component: groupedMessage.components.map((component, i) => (+ <div key={`${groupedMessage.id}-${i}`}>{component}</div>+ )),+ isCollapsed: groupedMessage.isCollapsed+ }}+ isLastMessage={groupedMessage.id === messages[messages.length - 1].id}+ />+ ))}</>)}diff --git a/components/chat-panel.tsx b/components/chat-panel.tsxindex 57e3dc71..2b27fe8a 100644--- a/components/chat-panel.tsx+++ b/components/chat-panel.tsx@@ -39,7 +39,7 @@ export function ChatPanel({ messages }: ChatPanelProps) {// Submit and get response messageconst formData = new FormData(e.currentTarget)const responseMessage = await submit(formData)- setMessages(currentMessages => [...currentMessages, responseMessage as any])+ setMessages(currentMessages => [...currentMessages, responseMessage])}// Clear messagesdiff --git a/components/search-results-image.tsx b/components/search-results-image.tsxindex 26167d68..5a3857ab 100644--- a/components/search-results-image.tsx+++ b/components/search-results-image.tsx@@ -61,7 +61,7 @@ export const SearchResultsImageSection: React.FC<return (<div className="flex flex-wrap gap-2">- {images.slice(0, 4).map((image: any, index: number) => (+ {images.slice(0, 4).map((image, index) => (<Dialog key={index}><DialogTrigger asChild><divdiff --git a/components/search-results.tsx b/components/search-results.tsxindex ea944787..f91b71d1 100644--- a/components/search-results.tsx+++ b/components/search-results.tsx@@ -5,9 +5,10 @@ import { AvatarImage, Avatar, AvatarFallback } from '@/components/ui/avatar'import { CardContent, Card } from '@/components/ui/card'import { Button } from '@/components/ui/button'import Link from 'next/link'+import { SearchResultItem } from '@/lib/types'export interface SearchResultsProps {- results: { title: string; url: string; content: string }[]+ results: SearchResultItem[]}export function SearchResults({ results }: SearchResultsProps) {@@ -23,7 +24,7 @@ export function SearchResults({ results }: SearchResultsProps) {return (<div className="flex flex-wrap">- {displayedResults.map((result: any, index: any) => (+ {displayedResults.map((result, index) => (<div className="w-1/2 md:w-1/4 p-1" key={index}><Link href={result.url} passHref target="_blank"><Card className="flex-1">diff --git a/lib/types/index.ts b/lib/types/index.tsindex 12593c1e..debd8a34 100644--- a/lib/types/index.ts+++ b/lib/types/index.ts@@ -21,6 +21,7 @@ export type SearchResultItem = {title: stringurl: stringcontent: string+ author?: string}export type ExaSearchResultItem = {