import React from "react"; import { Globe, CheckCircle, AlertTriangle, CircleDashed, ExternalLink } from "lucide-react"; import { ToolViewProps } from "./types"; import { extractCrawlUrl, extractWebpageContent, formatTimestamp, getToolTitle } from "./utils"; import { GenericToolView } from "./GenericToolView"; import { cn } from "@/lib/utils"; export function WebCrawlToolView({ name = "crawl-webpage", assistantContent, toolContent, assistantTimestamp, toolTimestamp, isSuccess = true, isStreaming = false }: ToolViewProps) { const url = extractCrawlUrl(assistantContent); const webpageContent = extractWebpageContent(toolContent); const toolTitle = getToolTitle(name); if (!url) { return ( ); } // Format domain for display const formatDomain = (url: string): string => { try { const urlObj = new URL(url); return urlObj.hostname.replace('www.', ''); } catch (e) { return url; } }; const domain = url ? formatDomain(url) : 'Unknown'; return (
{/* Webpage Header */}
{toolTitle}
{!isStreaming && (
{isSuccess ? 'Success' : 'Failed'} Open URL
)}
{/* URL Bar */}
{url}
{/* Content */} {isStreaming ? (

Crawling webpage...

Fetching content from {domain}

) : (
{webpageContent ? (
Page Content
                      {webpageContent.text || "No content extracted"}
                    
) : (

No content extracted

The webpage might be restricted or empty

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