Skip to content

An AI-powered search engine with a generative UI

chore: Update Search Skeleton and Rename it to Default Skeleton

Yoshiki Miura8ca940a5e132
diff --git a/components/answer-section.tsx b/components/answer-section.tsx
index 3d7c7cec..832705bb 100644
--- a/components/answer-section.tsx
+++ b/components/answer-section.tsx
@@ -1,10 +1,10 @@
'use client'
-import { Skeleton } from '@/components/ui/skeleton'
import { Section } from './section'
import { StreamableValue, useStreamableValue } from 'ai/rsc'
import { BotMessage } from './message'
import { useEffect, useState } from 'react'
+import { DefaultSkeleton } from './default-skeleton'
export type AnswerSectionProps = {
result?: StreamableValue<string>
@@ -30,10 +30,7 @@ export function AnswerSection({
<BotMessage content={content} />
</Section>
) : (
- <div className="flex flex-col gap-2 py-2">
- <Skeleton className="h-6 w-48" />
- <Skeleton className="w-full h-6" />
- </div>
+ <DefaultSkeleton />
)}
</div>
)
diff --git a/components/default-skeleton.tsx b/components/default-skeleton.tsx
new file mode 100644
index 00000000..0a800f54
--- /dev/null
+++ b/components/default-skeleton.tsx
@@ -0,0 +1,13 @@
+'use client'
+
+import React from 'react'
+import { Skeleton } from './ui/skeleton'
+
+export const DefaultSkeleton = () => {
+ return (
+ <div className="flex flex-col gap-2">
+ <Skeleton className="h-6 w-48" />
+ <Skeleton className="w-full h-6" />
+ </div>
+ )
+}
diff --git a/components/search-section.tsx b/components/search-section.tsx
index 63434b13..8c6455ad 100644
--- a/components/search-section.tsx
+++ b/components/search-section.tsx
@@ -1,7 +1,7 @@
'use client'
import { SearchResults } from './search-results'
-import { SearchSkeleton } from './search-skeleton'
+import { DefaultSkeleton } from './default-skeleton'
import { SearchResultsImageSection } from './search-results-image'
import { Section } from './section'
import { ToolBadge } from './tool-badge'
@@ -39,9 +39,7 @@ export function SearchSection({ result, includeDomains }: SearchSectionProps) {
</Section>
</>
) : (
- <Section className="pt-2 pb-0">
- <SearchSkeleton />
- </Section>
+ <DefaultSkeleton />
)}
</div>
)
diff --git a/components/search-skeleton.tsx b/components/search-skeleton.tsx
deleted file mode 100644
index 248f13b1..00000000
--- a/components/search-skeleton.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-'use client'
-
-import React from 'react'
-import { Skeleton } from './ui/skeleton'
-
-export const SearchSkeleton = () => {
- return (
- <div>
- <Skeleton className="h-6 w-48" />
- <div className="flex flex-wrap gap-2">
- {Array.from({ length: 4 }).map((_, index) => (
- <div
- className="w-[calc(50%-0.5rem)] md:w-[calc(25%-0.5rem)] p-2"
- key={index}
- >
- <div className="flex-1">
- <div className="pt-2">
- <Skeleton className="h-6 mb-2" />
- <div className="flex items-center space-x-2">
- <Skeleton className="h-4 w-4" />
- <Skeleton className="w-24 h-4" />
- </div>
- </div>
- </div>
- </div>
- ))}
- </div>
- </div>
- )
-}
diff --git a/components/video-search-section.tsx b/components/video-search-section.tsx
index 49c399e1..fad388fc 100644
--- a/components/video-search-section.tsx
+++ b/components/video-search-section.tsx
@@ -1,6 +1,6 @@
'use client'
-import { SearchSkeleton } from './search-skeleton'
+import { DefaultSkeleton } from './default-skeleton'
import { Section } from './section'
import type { SerperSearchResults } from '@/lib/types'
import { StreamableValue, useStreamableValue } from 'ai/rsc'
@@ -27,7 +27,7 @@ export function VideoSearchSection({ result }: VideoSearchSectionProps) {
</>
) : (
<Section className="pt-2 pb-0">
- <SearchSkeleton />
+ <DefaultSkeleton />
</Section>
)}
</div>
diff --git a/lib/agents/tools/retrieve.tsx b/lib/agents/tools/retrieve.tsx
index 136dca95..f9f63940 100644
--- a/lib/agents/tools/retrieve.tsx
+++ b/lib/agents/tools/retrieve.tsx
@@ -1,60 +1,61 @@
import { tool } from 'ai'
import { retrieveSchema } from '@/lib/schema/retrieve'
import { ToolProps } from '.'
-import { SearchSkeleton } from '@/components/search-skeleton'
+import { DefaultSkeleton } from '@/components/default-skeleton'
import { SearchResults as SearchResultsType } from '@/lib/types'
import RetrieveSection from '@/components/retrieve-section'
-export const retrieveTool = ({ uiStream, fullResponse }: ToolProps) => tool({
- description: 'Retrieve content from the web',
- parameters: retrieveSchema,
- execute: async ({ url }) => {
- let hasError = false
- // Append the search section
- uiStream.append(<SearchSkeleton />)
+export const retrieveTool = ({ uiStream, fullResponse }: ToolProps) =>
+ tool({
+ description: 'Retrieve content from the web',
+ parameters: retrieveSchema,
+ execute: async ({ url }) => {
+ let hasError = false
+ // Append the search section
+ uiStream.append(<DefaultSkeleton />)
- let results: SearchResultsType | undefined
- try {
- const response = await fetch(`https://r.jina.ai/${url}`, {
- method: 'GET',
- headers: {
- Accept: 'application/json',
- 'X-With-Generated-Alt': 'true'
+ let results: SearchResultsType | undefined
+ try {
+ const response = await fetch(`https://r.jina.ai/${url}`, {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ 'X-With-Generated-Alt': 'true'
+ }
+ })
+ const json = await response.json()
+ if (!json.data || json.data.length === 0) {
+ hasError = true
+ } else {
+ // Limit the content to 5000 characters
+ if (json.data.content.length > 5000) {
+ json.data.content = json.data.content.slice(0, 5000)
+ }
+ results = {
+ results: [
+ {
+ title: json.data.title,
+ content: json.data.content,
+ url: json.data.url
+ }
+ ],
+ query: '',
+ images: []
+ }
}
- })
- const json = await response.json()
- if (!json.data || json.data.length === 0) {
+ } catch (error) {
hasError = true
- } else {
- // Limit the content to 5000 characters
- if (json.data.content.length > 5000) {
- json.data.content = json.data.content.slice(0, 5000)
- }
- results = {
- results: [
- {
- title: json.data.title,
- content: json.data.content,
- url: json.data.url
- }
- ],
- query: '',
- images: []
- }
+ console.error('Retrieve API error:', error)
}
- } catch (error) {
- hasError = true
- console.error('Retrieve API error:', error)
- }
- if (hasError || !results) {
- fullResponse = `An error occurred while retrieving "${url}".`
- uiStream.update(null)
- return results
- }
+ if (hasError || !results) {
+ fullResponse = `An error occurred while retrieving "${url}".`
+ uiStream.update(null)
+ return results
+ }
- uiStream.update(<RetrieveSection data={results} />)
+ uiStream.update(<RetrieveSection data={results} />)
- return results
- }
-})
+ return results
+ }
+ })