An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
refactor: rename retrieve tool to fetch tool
Yoshiki Miurac048af482e44
diff --git a/components/artifact/artifact-content.tsx b/components/artifact/artifact-content.tsxindex 311280f0..af2203b0 100644--- a/components/artifact/artifact-content.tsx+++ b/components/artifact/artifact-content.tsx@@ -10,7 +10,7 @@ export function ArtifactContent({ part }: { part: Part | null }) {switch (part.type) {case 'tool-search':- case 'tool-retrieve':+ case 'tool-fetch':case 'tool-videoSearch':case 'tool-askQuestion':return <ToolInvocationContent part={part} />diff --git a/components/artifact/retrieve-artifact-content.tsx b/components/artifact/fetch-artifact-content.tsxsimilarity index 91%rename from components/artifact/retrieve-artifact-content.tsxrename to components/artifact/fetch-artifact-content.tsxindex 961925af..fde8b570 100644--- a/components/artifact/retrieve-artifact-content.tsx+++ b/components/artifact/fetch-artifact-content.tsx@@ -13,10 +13,10 @@ import { MemoizedReactMarkdown } from '../ui/markdown'const MAX_CONTENT_LENGTH = 1000-export function RetrieveArtifactContent({+export function FetchArtifactContent({tool}: {- tool: ToolPart<'retrieve'>+ tool: ToolPart<'fetch'>}) {const searchResults: TypeSearchResults | undefined =tool.state === 'output-available' ? (tool.output ?? undefined) : undefined@@ -38,7 +38,7 @@ export function RetrieveArtifactContent({return (<div className="space-y-2">- <ToolArgsSection tool="retrieve">{url}</ToolArgsSection>+ <ToolArgsSection tool="fetch">{url}</ToolArgsSection><Section title="Sources"><SearchResults results={truncatedResults} displayMode="list" />diff --git a/components/artifact/tool-invocation-content.tsx b/components/artifact/tool-invocation-content.tsxindex 0fab2439..03ae05d5 100644--- a/components/artifact/tool-invocation-content.tsx+++ b/components/artifact/tool-invocation-content.tsx@@ -2,7 +2,7 @@import type { ToolPart } from '@/lib/types/ai'-import { RetrieveArtifactContent } from '@/components/artifact/retrieve-artifact-content'+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 +10,8 @@ export function ToolInvocationContent({ part }: { part: ToolPart }) {switch (part.type) {case 'tool-search':return <SearchArtifactContent tool={part as ToolPart<'search'>} />- case 'tool-retrieve':- return <RetrieveArtifactContent tool={part as ToolPart<'retrieve'>} />+ case 'tool-fetch':+ return <FetchArtifactContent tool={part as ToolPart<'fetch'>} />case 'tool-videoSearch':return (<VideoSearchArtifactContent tool={part as ToolPart<'videoSearch'>} />diff --git a/components/chat-panel.tsx b/components/chat-panel.tsxindex e3d01568..d25d454d 100644--- a/components/chat-panel.tsx+++ b/components/chat-panel.tsx@@ -95,7 +95,7 @@ export function ChatPanel({return ((lastPart?.type === 'tool-search' ||- lastPart?.type === 'tool-retrieve' ||+ lastPart?.type === 'tool-fetch' ||lastPart?.type === 'tool-videoSearch' ||lastPart?.type === 'tool-askQuestion') &&((lastPart as any)?.state === 'input-streaming' ||diff --git a/components/retrieve-preview.tsx b/components/fetch-preview.tsxsimilarity index 98%rename from components/retrieve-preview.tsxrename to components/fetch-preview.tsxindex badb6213..e8c59842 100644--- a/components/retrieve-preview.tsx+++ b/components/fetch-preview.tsx@@ -1,6 +1,6 @@import { ExternalLink, Globe } from 'lucide-react'-interface RetrievePreviewProps {+interface FetchPreviewProps {url: stringtitle?: stringcontentLength?: number@@ -9,7 +9,7 @@ interface RetrievePreviewProps {fetchType?: string}-export function RetrievePreview({+export function FetchPreview({url,title,contentLength,diff --git a/components/retrieve-section.tsx b/components/fetch-section.tsxsimilarity index 87%rename from components/retrieve-section.tsxrename to components/fetch-section.tsxindex 1b83a191..8e4eb3bd 100644--- a/components/retrieve-section.tsx+++ b/components/fetch-section.tsx@@ -5,16 +5,16 @@ import { UseChatHelpers } from '@ai-sdk/react'import { SearchResults as SearchResultsType } from '@/lib/types'import type { ToolPart, UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'-import { RetrievePreview } from './retrieve-preview'+import { FetchPreview } from './fetch-preview'-interface RetrieveSectionProps {- tool: ToolPart<'retrieve'>+interface FetchSectionProps {+ tool: ToolPart<'fetch'>isOpen: booleanonOpenChange: (open: boolean) => voidstatus?: UseChatHelpers<UIMessage<unknown, UIDataTypes, UITools>>['status']}-export function RetrieveSection({ tool }: RetrieveSectionProps) {+export function FetchSection({ tool }: FetchSectionProps) {const url = tool.input?.url// Determine the fetch type based on the tool input@@ -49,7 +49,7 @@ export function RetrieveSection({ tool }: RetrieveSectionProps) {return (<div className="w-full">- <RetrievePreview+ <FetchPreviewurl={url || ''}title={title}contentLength={contentLength}@@ -61,4 +61,4 @@ export function RetrieveSection({ tool }: RetrieveSectionProps) {)}-export default RetrieveSection+export default FetchSectiondiff --git a/components/inspector/inspector-drawer.tsx b/components/inspector/inspector-drawer.tsxindex 551b96d1..a304dc0a 100644--- a/components/inspector/inspector-drawer.tsx+++ b/components/inspector/inspector-drawer.tsx@@ -21,8 +21,8 @@ export function InspectorDrawer() {switch (part.type) {case 'tool-search':return 'search'- case 'tool-retrieve':- return 'retrieve'+ case 'tool-fetch':+ return 'fetch'case 'tool-videoSearch':return 'videoSearch'case 'tool-askQuestion':diff --git a/components/inspector/inspector-panel.tsx b/components/inspector/inspector-panel.tsxindex 375541eb..155de137 100644--- a/components/inspector/inspector-panel.tsx+++ b/components/inspector/inspector-panel.tsx@@ -24,7 +24,7 @@ export function InspectorPanel() {const getIconAndTitle = () => {switch (part.type) {case 'tool-search':- case 'tool-retrieve':+ case 'tool-fetch':case 'tool-videoSearch':case 'tool-askQuestion':const toolName = part.type.replace('tool-', '')diff --git a/components/render-message.tsx b/components/render-message.tsxindex b28cd51a..70c19a20 100644--- a/components/render-message.tsx+++ b/components/render-message.tsx@@ -83,7 +83,7 @@ export function RenderMessage({switch (part.type) {case 'tool-search':- case 'tool-retrieve':+ case 'tool-fetch':case 'tool-videoSearch':case 'tool-askQuestion':case 'tool-relatedQuestions':diff --git a/components/tool-badge.tsx b/components/tool-badge.tsxindex d7b405de..6557d524 100644--- a/components/tool-badge.tsx+++ b/components/tool-badge.tsx@@ -17,7 +17,7 @@ export const ToolBadge: React.FC<ToolBadgeProps> = ({}) => {const icon: Record<string, React.ReactNode> = {search: <Search size={14} />,- retrieve: <Link size={14} />,+ fetch: <Link size={14} />,videoSearch: <Film size={14} />}diff --git a/components/tool-section.tsx b/components/tool-section.tsxindex e7ed53e3..f70b144c 100644--- a/components/tool-section.tsx+++ b/components/tool-section.tsx@@ -6,7 +6,7 @@ import type { ToolPart, UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'import { QuestionConfirmation } from './question-confirmation'import { RelatedQuestions } from './related-questions'-import RetrieveSection from './retrieve-section'+import FetchSection from './fetch-section'import { SearchSection } from './search-section'import { VideoSearchSection } from './video-search-section'@@ -84,10 +84,10 @@ export function ToolSection({status={status}/>)- case 'tool-retrieve':+ case 'tool-fetch':return (- <RetrieveSection- tool={tool as ToolPart<'retrieve'>}+ <FetchSection+ tool={tool as ToolPart<'fetch'>}isOpen={isOpen}onOpenChange={onOpenChange}status={status}diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.mdindex c333ca1b..9e070277 100644--- a/docs/CONFIGURATION.md+++ b/docs/CONFIGURATION.md@@ -215,7 +215,7 @@ NEXT_PUBLIC_ENABLE_SHARE=trueSERPER_API_KEY=[YOUR_API_KEY]```-### Alternative Retrieve Tool+### Alternative Fetch Tool```bashJINA_API_KEY=[YOUR_API_KEY]diff --git a/lib/agents/researcher-with-dynamic-tools.ts b/lib/agents/researcher-with-dynamic-tools.tsindex dc95671d..85d67cc8 100644--- a/lib/agents/researcher-with-dynamic-tools.ts+++ b/lib/agents/researcher-with-dynamic-tools.ts@@ -6,7 +6,7 @@ import {createMCPTool} from '../tools/dynamic'import { createQuestionTool } from '../tools/question'-import { retrieveTool } from '../tools/retrieve'+import { fetchTool } from '../tools/fetch'import { createSearchTool } from '../tools/search'import { createVideoSearchTool } from '../tools/video-search'import { getModel } from '../utils/registry'@@ -20,7 +20,7 @@ When asked a question, you should:1. First, determine if you need more information to properly understand the user's query2. **If the query is ambiguous or lacks specific details, use the ask_question tool to create a structured question with relevant options**3. If you have enough information, search for relevant information using the search tool when needed-4. Use the retrieve tool to get detailed content from specific URLs+4. Use the fetch tool to get detailed content from specific URLs5. Use the video search tool when looking for video content6. Use any available dynamic tools when they are relevant to the user's request7. Analyze all search results to provide accurate, up-to-date information@@ -28,7 +28,7 @@ When asked a question, you should:9. If results are not relevant or helpful, rely on your general knowledge10. Provide comprehensive and detailed responses based on search results, ensuring thorough coverage of the user's question11. Use markdown to structure your responses. Use headings to break up the content into sections.-12. **Use the retrieve tool only with user-provided URLs.**+12. **Use the fetch tool only with user-provided URLs.**When using the ask_question tool:- Create clear, concise questions@@ -67,7 +67,7 @@ export function researcherWithDynamicTools({// Create base tools objectconst tools: Record<string, any> = {search: searchTool,- retrieve: retrieveTool,+ fetch: fetchTool,videoSearch: videoSearchTool,askQuestion: askQuestionTool}@@ -100,7 +100,7 @@ export function researcherWithDynamicTools({const activeToolNames = searchMode? allToolNames.filter(name =>- ['search', 'retrieve', 'videoSearch'].includes(name) ||+ ['search', 'fetch', 'videoSearch'].includes(name) ||name.startsWith('mcp__') ||name.startsWith('dynamic__'))diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.tsindex 58657155..b51dfbea 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 { retrieveTool } from '../tools/retrieve'+import { fetchTool } from '../tools/fetch'import { createSearchTool } from '../tools/search'import { createVideoSearchTool } from '../tools/video-search'import { getModel } from '../utils/registry'@@ -15,14 +15,14 @@ When asked a question, you should:1. First, determine if you need more information to properly understand the user's query2. **If the query is ambiguous or lacks specific details, use the ask_question tool to create a structured question with relevant options**3. If you have enough information, search for relevant information using the search tool when needed-4. Use the retrieve tool to get detailed content from specific URLs+4. Use the fetch tool to get detailed content from specific URLs5. Use the video search tool when looking for video content6. Analyze all search results to provide accurate, up-to-date information7. Always cite sources using the [number](url) format, matching the order of search results. If multiple sources are relevant, include all of them, and comma separate them. Only use information that has a URL available for citation.8. If results are not relevant or helpful, rely on your general knowledge9. Provide comprehensive and detailed responses based on search results, ensuring thorough coverage of the user's question10. Use markdown to structure your responses. Use headings to break up the content into sections.-11. **Use the retrieve tool only with user-provided URLs.**+11. **Use the fetch tool only with user-provided URLs.**When using the ask_question tool:- Create clear, concise questions@@ -55,12 +55,12 @@ export function researcher({system: `${SYSTEM_PROMPT}\nCurrent date and time: ${currentDate}`,tools: {search: searchTool,- retrieve: retrieveTool,+ fetch: fetchTool,videoSearch: videoSearchTool,askQuestion: askQuestionTool},activeTools: searchMode- ? ['search', 'retrieve', 'videoSearch']+ ? ['search', 'fetch', 'videoSearch']: undefined,stopWhen: searchMode ? stepCountIs(10) : stepCountIs(1)})diff --git a/lib/db/migrations/0004_rename_retrieve_to_fetch.sql b/lib/db/migrations/0004_rename_retrieve_to_fetch.sqlnew file mode 100644index 00000000..b41f99e5--- /dev/null+++ b/lib/db/migrations/0004_rename_retrieve_to_fetch.sql@@ -0,0 +1,11 @@+-- Migration: Rename retrieve tool columns to fetch+-- This migration renames the tool_retrieve_* columns to tool_fetch_*+-- to align with the renamed tool from 'retrieve' to 'fetch'++-- Rename tool_retrieve_input to tool_fetch_input+ALTER TABLE parts+RENAME COLUMN tool_retrieve_input TO tool_fetch_input;++-- Rename tool_retrieve_output to tool_fetch_output+ALTER TABLE parts+RENAME COLUMN tool_retrieve_output TO tool_fetch_output;\ No newline at end of filediff --git a/lib/db/schema.ts b/lib/db/schema.tsindex a8cbf5cb..132855bc 100644--- a/lib/db/schema.ts+++ b/lib/db/schema.ts@@ -124,8 +124,8 @@ export const parts = pgTable(// Tool-specific columns (all Morphic tools)tool_search_input: json('tool_search_input').$type<any>(),tool_search_output: json('tool_search_output').$type<any>(),- tool_retrieve_input: json('tool_retrieve_input').$type<any>(),- tool_retrieve_output: json('tool_retrieve_output').$type<any>(),+ tool_fetch_input: json('tool_fetch_input').$type<any>(),+ tool_fetch_output: json('tool_fetch_output').$type<any>(),tool_question_input: json('tool_question_input').$type<any>(),tool_question_output: json('tool_question_output').$type<any>(),tool_videoSearch_input: json('tool_video_search_input').$type<any>(),diff --git a/lib/schema/retrieve.tsx b/lib/schema/fetch.tsxsimilarity index 77%rename from lib/schema/retrieve.tsxrename to lib/schema/fetch.tsxindex 83eca7c0..04d1d0bc 100644--- a/lib/schema/retrieve.tsx+++ b/lib/schema/fetch.tsx@@ -1,7 +1,7 @@import { DeepPartial } from 'ai'import { z } from 'zod'-export const retrieveSchema = z.object({+export const fetchSchema = z.object({url: z.string().describe('The URL to retrieve content from'),type: z.enum(['regular', 'api'])@@ -11,4 +11,4 @@ export const retrieveSchema = z.object({)})-export type PartialInquiry = DeepPartial<typeof retrieveSchema>+export type PartialInquiry = DeepPartial<typeof fetchSchema>diff --git a/lib/tools/retrieve.ts b/lib/tools/fetch.tssimilarity index 97%rename from lib/tools/retrieve.tsrename to lib/tools/fetch.tsindex 9965df1f..8f14215d 100644--- a/lib/tools/retrieve.ts+++ b/lib/tools/fetch.ts@@ -1,6 +1,6 @@import { tool } from 'ai'-import { retrieveSchema } from '@/lib/schema/retrieve'+import { fetchSchema } from '@/lib/schema/fetch'import { SearchResults as SearchResultsType } from '@/lib/types'const CONTENT_CHARACTER_LIMIT = 10000@@ -159,9 +159,9 @@ async function fetchTavilyExtractData(}}-export const retrieveTool = tool({+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.',- inputSchema: retrieveSchema,+ inputSchema: fetchSchema,execute: async ({ url, type = 'regular' }) => {let results: SearchResultsType | nulldiff --git a/lib/types/ai.ts b/lib/types/ai.tsindex 02a2a1ad..da7162da 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 { retrieveTool } from '@/lib/tools/retrieve'+import { fetchTool } from '@/lib/tools/fetch'import { searchTool } from '@/lib/tools/search'import { videoSearchTool } from '@/lib/tools/video-search'@@ -17,7 +17,7 @@ export type UIDataTypes = {export type UITools = {search: InferUITool<typeof searchTool>- retrieve: InferUITool<typeof retrieveTool>+ fetch: InferUITool<typeof fetchTool>videoSearch: InferUITool<typeof videoSearchTool>askQuestion: InferUITool<typeof askQuestionTool>// Dynamic tools will be added at runtimediff --git a/lib/utils/message-mapping.ts b/lib/utils/message-mapping.tsindex d46036e9..18fec7bb 100644--- a/lib/utils/message-mapping.ts+++ b/lib/utils/message-mapping.ts@@ -248,7 +248,7 @@ export function mapUIMessagePartsToDBParts(// Tool-specific parts that are not tool-call or tool-resultcase 'tool-search':- case 'tool-retrieve':+ case 'tool-fetch':case 'tool-question':case 'tool-videoSearch':case 'tool-relatedQuestions':