An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: resolve TypeScript errors and remove unnecessary fetch artifact component
Yoshiki Miuraed67ecd1ce1d
diff --git a/components/artifact/fetch-artifact-content.tsx b/components/artifact/fetch-artifact-content.tsxdeleted file mode 100644index fde8b570..00000000--- a/components/artifact/fetch-artifact-content.tsx+++ /dev/null@@ -1,55 +0,0 @@-'use client'--import type { ToolPart } from '@/lib/types/ai'-import type {- SearchResultItem,- SearchResults as TypeSearchResults-} from '@/lib/types/index'--import { SearchResults } from '@/components/search-results'-import { Section, ToolArgsSection } from '@/components/section'--import { MemoizedReactMarkdown } from '../ui/markdown'--const MAX_CONTENT_LENGTH = 1000--export function FetchArtifactContent({- tool-}: {- tool: ToolPart<'fetch'>-}) {- const searchResults: TypeSearchResults | undefined =- tool.state === 'output-available' ? (tool.output ?? undefined) : undefined- const url = tool.input?.url-- if (!searchResults?.results) {- return <div className="p-4">No retrieved content</div>- }-- const truncatedResults: SearchResultItem[] = searchResults.results.map(- result => ({- ...result,- content:- result.content.length > MAX_CONTENT_LENGTH- ? `${result.content.substring(0, MAX_CONTENT_LENGTH)}...`- : result.content- })- )-- return (- <div className="space-y-2">- <ToolArgsSection tool="fetch">{url}</ToolArgsSection>-- <Section title="Sources">- <SearchResults results={truncatedResults} displayMode="list" />- </Section>- {truncatedResults[0].content && (- <Section title="Content">- <MemoizedReactMarkdown className="prose-sm prose-neutral prose-p:text-sm text-muted-foreground">- {truncatedResults[0].content}- </MemoizedReactMarkdown>- </Section>- )}- </div>- )-}diff --git a/components/artifact/tool-invocation-content.tsx b/components/artifact/tool-invocation-content.tsxindex 03ae05d5..9c1eaa5d 100644--- a/components/artifact/tool-invocation-content.tsx+++ b/components/artifact/tool-invocation-content.tsx@@ -2,7 +2,6 @@import type { ToolPart } from '@/lib/types/ai'-import { FetchArtifactContent } from '@/components/artifact/fetch-artifact-content'import { SearchArtifactContent } from '@/components/artifact/search-artifact-content'import { VideoSearchArtifactContent } from '@/components/artifact/video-search-artifact-content'@@ -10,8 +9,6 @@ export function ToolInvocationContent({ part }: { part: ToolPart }) {switch (part.type) {case 'tool-search':return <SearchArtifactContent tool={part as ToolPart<'search'>} />- case 'tool-fetch':- return <FetchArtifactContent tool={part as ToolPart<'fetch'>} />case 'tool-videoSearch':return (<VideoSearchArtifactContent tool={part as ToolPart<'videoSearch'>} />diff --git a/components/fetch-preview.tsx b/components/fetch-preview.tsxindex e8c59842..b6e13cd6 100644--- a/components/fetch-preview.tsx+++ b/components/fetch-preview.tsx@@ -16,7 +16,7 @@ export function FetchPreview({status,error,fetchType = 'Retrieve'-}: RetrievePreviewProps) {+}: FetchPreviewProps) {const getPageTitle = () => {if (title) return titletry {diff --git a/components/fetch-section.tsx b/components/fetch-section.tsxindex 8e4eb3bd..78a2d284 100644--- a/components/fetch-section.tsx+++ b/components/fetch-section.tsx@@ -16,16 +16,17 @@ interface FetchSectionProps {export function FetchSection({ tool }: FetchSectionProps) {const url = tool.input?.url-+// Determine the fetch type based on the tool input- const fetchType = tool.input?.type === 'api' ? 'API Retrieve' : 'Regular Fetch'-+ const fetchType =+ tool.input?.type === 'api' ? 'API Retrieve' : 'Regular Fetch'+// Determine the status based on tool output availabilitylet displayStatus: 'fetching' | 'success' | 'error' = 'fetching'let error: string | undefinedlet title: string | undefinedlet contentLength: number | undefined-+// Check if output is availableif (!tool.output) {// Still fetchingdiff --git a/components/tool-section.tsx b/components/tool-section.tsxindex f70b144c..370d3940 100644--- a/components/tool-section.tsx+++ b/components/tool-section.tsx@@ -4,9 +4,9 @@ import { UseChatHelpers } from '@ai-sdk/react'import type { ToolPart, UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'+import FetchSection from './fetch-section'import { QuestionConfirmation } from './question-confirmation'import { RelatedQuestions } from './related-questions'-import FetchSection from './fetch-section'import { SearchSection } from './search-section'import { VideoSearchSection } from './video-search-section'diff --git a/lib/agents/researcher-with-dynamic-tools.ts b/lib/agents/researcher-with-dynamic-tools.tsindex 85d67cc8..d62e6c67 100644--- a/lib/agents/researcher-with-dynamic-tools.ts+++ b/lib/agents/researcher-with-dynamic-tools.ts@@ -5,8 +5,8 @@ import {createDynamicTool,createMCPTool} from '../tools/dynamic'-import { createQuestionTool } from '../tools/question'import { fetchTool } from '../tools/fetch'+import { createQuestionTool } from '../tools/question'import { createSearchTool } from '../tools/search'import { createVideoSearchTool } from '../tools/video-search'import { getModel } from '../utils/registry'diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.tsindex b51dfbea..c7cbd110 100644--- a/lib/agents/researcher.ts+++ b/lib/agents/researcher.ts@@ -1,7 +1,7 @@import { Experimental_Agent as Agent, stepCountIs } from 'ai'-import { createQuestionTool } from '../tools/question'import { fetchTool } from '../tools/fetch'+import { createQuestionTool } from '../tools/question'import { createSearchTool } from '../tools/search'import { createVideoSearchTool } from '../tools/video-search'import { getModel } from '../utils/registry'@@ -59,9 +59,7 @@ export function researcher({videoSearch: videoSearchTool,askQuestion: askQuestionTool},- activeTools: searchMode- ? ['search', 'fetch', 'videoSearch']- : undefined,+ activeTools: searchMode ? ['search', 'fetch', 'videoSearch'] : undefined,stopWhen: searchMode ? stepCountIs(10) : stepCountIs(1)})} catch (error) {diff --git a/lib/tools/fetch.ts b/lib/tools/fetch.tsindex 8f14215d..1ca493e2 100644--- a/lib/tools/fetch.ts+++ b/lib/tools/fetch.ts@@ -160,7 +160,8 @@ async function fetchTavilyExtractData(}export const fetchTool = tool({- description: 'Fetch content from any URL. By default uses "regular" type which performs fast, direct HTML fetching without external APIs - ideal for most websites. Only use "api" type when you need: 1) PDF content extraction, 2) Complex JavaScript-rendered pages, 3) Better markdown formatting, 4) Table extraction. The "api" type requires Jina or Tavily API keys.',+ description:+ 'Fetch content from any URL. By default uses "regular" type which performs fast, direct HTML fetching without external APIs - ideal for most websites. Only use "api" type when you need: 1) PDF content extraction, 2) Complex JavaScript-rendered pages, 3) Better markdown formatting, 4) Table extraction. The "api" type requires Jina or Tavily API keys.',inputSchema: fetchSchema,execute: async ({ url, type = 'regular' }) => {let results: SearchResultsType | nulldiff --git a/lib/types/ai.ts b/lib/types/ai.tsindex da7162da..07652910 100644--- a/lib/types/ai.ts+++ b/lib/types/ai.ts@@ -1,7 +1,7 @@import type { InferUITool, UIMessage as AIMessage } from 'ai'-import { askQuestionTool } from '@/lib/tools/question'import { fetchTool } from '@/lib/tools/fetch'+import { askQuestionTool } from '@/lib/tools/question'import { searchTool } from '@/lib/tools/search'import { videoSearchTool } from '@/lib/tools/video-search'