"use client"; import { makeAssistantToolUI } from "@assistant-ui/react"; import { z } from "zod"; import { GlobeIcon, Loader2Icon, CheckCircle2Icon, XCircleIcon } from "lucide-react"; const ScrapeWebpageArgsSchema = z.object({ url: z.string(), }).passthrough(); const ScrapeWebpageResultSchema = z.object({ url: z.string().optional(), title: z.string().optional(), content: z.string().optional(), error: z.string().optional(), success: z.boolean().optional(), }).passthrough(); type ScrapeWebpageArgs = z.infer; type ScrapeWebpageResult = z.infer; export const ScrapeWebpageToolUI = makeAssistantToolUI({ toolName: "scrape_webpage", render: ({ args, result, status }) => { const isLoading = status.type === "running"; const url = result?.url ?? args?.url; const hasError = result?.error || result?.success === false; const isSuccess = result?.success !== false && !result?.error && status.type === "complete"; return (
{isLoading ? ( ) : hasError ? ( ) : ( )}

{isLoading ? "Scraping webpage..." : hasError ? "Failed to scrape" : "Scraped webpage"}

{url && (

{url}

)} {hasError && result?.error && (

{result.error}

)}
{isSuccess && }
); }, });