import React from "react"; import { File, X as XIcon } from "lucide-react"; import type { Base64ContentBlock } from "@langchain/core/messages"; import { cn } from "@/lib/utils"; import Image from "next/image"; export interface MultimodalPreviewProps { block: Base64ContentBlock; removable?: boolean; onRemove?: () => void; className?: string; size?: "sm" | "md" | "lg"; } export const MultimodalPreview: React.FC = ({ block, removable = false, onRemove, className, size = "md", }) => { // Image block if ( block.type === "image" && block.source_type === "base64" && typeof block.mime_type === "string" && block.mime_type.startsWith("image/") ) { const url = `data:${block.mime_type};base64,${block.data}`; let imgClass: string = "rounded-md object-cover h-16 w-16 text-lg"; if (size === "sm") imgClass = "rounded-md object-cover h-10 w-10 text-base"; if (size === "lg") imgClass = "rounded-md object-cover h-24 w-24 text-xl"; return (
{String(block.metadata?.name {removable && ( )}
); } // PDF block if ( block.type === "file" && block.source_type === "base64" && block.mime_type === "application/pdf" ) { const filename = block.metadata?.filename || block.metadata?.name || "PDF file"; return (
{String(filename)} {removable && ( )}
); } // Fallback for unknown types return (
Unsupported file type {removable && ( )}
); };