import React from "react"; import { Search, CircleDashed, CheckCircle, AlertTriangle, ExternalLink } from "lucide-react"; import { ToolViewProps } from "./types"; import { extractSearchQuery, extractSearchResults, cleanUrl, formatTimestamp, getToolTitle } from "./utils"; import { cn } from "@/lib/utils"; export function WebSearchToolView({ name = "web-search", assistantContent, toolContent, assistantTimestamp, toolTimestamp, isSuccess = true, isStreaming = false }: ToolViewProps) { const query = extractSearchQuery(assistantContent); const searchResults = extractSearchResults(toolContent); const toolTitle = getToolTitle(name); return (
{toolTitle}
{!isStreaming && ( {isSuccess ? 'Success' : 'Failed'} )}
{query || 'Unknown query'}
{isStreaming ? (

Searching the web...

This might take a moment

) : searchResults.length > 0 ? (
Found {searchResults.length} results
{searchResults.map((result, idx) => (
{cleanUrl(result.url)}
{result.title}
{result.snippet && (

{result.snippet}

)}
))}
) : (

No results found

Try refining your search query

)}
{!isStreaming && (
{isSuccess ? ( ) : ( )} {isSuccess ? `${toolTitle} completed successfully` : `${toolTitle} operation failed`}
)} {isStreaming && (
Executing {toolTitle.toLowerCase()}...
)}
{toolTimestamp && !isStreaming ? formatTimestamp(toolTimestamp) : assistantTimestamp ? formatTimestamp(assistantTimestamp) : ''}
); }