"use client"; import { makeAssistantToolUI } from "@assistant-ui/react"; import { AlertCircleIcon, ImageIcon } from "lucide-react"; import { Image, ImageErrorBoundary, ImageLoading, parseSerializableImage, } from "@/components/tool-ui/image"; /** * Type definitions for the display_image tool */ interface DisplayImageArgs { src: string; alt?: string; title?: string; description?: string; } interface DisplayImageResult { id: string; assetId: string; src: string; alt: string; title?: string; description?: string; domain?: string; ratio?: string; error?: string; } /** * Error state component shown when image display fails */ function ImageErrorState({ src, error }: { src: string; error: string }) { return (

Failed to display image

{src}

{error}

); } /** * Cancelled state component */ function ImageCancelledState({ src }: { src: string }) { return (

Image: {src}

); } /** * Parsed Image component with error handling * Note: Image component has built-in click handling via href/src, * so no additional responseActions needed. */ function ParsedImage({ result }: { result: unknown }) { const image = parseSerializableImage(result); return ; } /** * Display Image Tool UI Component * * This component is registered with assistant-ui to render an image * when the display_image tool is called by the agent. * * It displays images with: * - Title and description * - Source attribution * - Hover overlay effects * - Click to open full size */ export const DisplayImageToolUI = makeAssistantToolUI({ toolName: "display_image", render: function DisplayImageUI({ args, result, status }) { const src = args.src || "Unknown"; // Loading state - tool is still running if (status.type === "running" || status.type === "requires-action") { return (
); } // Incomplete/cancelled state if (status.type === "incomplete") { if (status.reason === "cancelled") { return ; } if (status.reason === "error") { return ( ); } } // No result yet if (!result) { return (
); } // Error result from the tool if (result.error) { return ; } // Success - render the image return (
); }, }); export type { DisplayImageArgs, DisplayImageResult };