import React, { useState } from "react"; import { LLMContent } from "../types"; interface BrowserNavigateToolProps { toolInput?: unknown; // { url: string } isRunning?: boolean; toolResult?: LLMContent[]; hasError?: boolean; executionTime?: string; } function BrowserNavigateTool({ toolInput, isRunning, toolResult, hasError, executionTime, }: BrowserNavigateToolProps) { const [isExpanded, setIsExpanded] = useState(false); // Extract URL from toolInput const url = typeof toolInput === "object" && toolInput !== null && "url" in toolInput && typeof toolInput.url === "string" ? toolInput.url : typeof toolInput === "string" ? toolInput : ""; // Extract output from toolResult const output = toolResult && toolResult.length > 0 && toolResult[0].Text ? toolResult[0].Text : ""; // Truncate URL for display const truncateUrl = (urlStr: string, maxLen: number = 300) => { if (urlStr.length <= maxLen) return urlStr; return urlStr.substring(0, maxLen) + "..."; }; const displayUrl = truncateUrl(url); const isComplete = !isRunning && toolResult !== undefined; return (
setIsExpanded(!isExpanded)}>
🌐 {displayUrl} {isComplete && hasError && } {isComplete && !hasError && }
{isExpanded && (
URL:
{url}
{isComplete && output && (
Output{hasError ? " (Error)" : ""}: {executionTime && {executionTime}}
{output}
)}
)}
); } export default BrowserNavigateTool;