import React from "react"; import { Button } from "./ui/button"; import { X, ShieldAlert } from "lucide-react"; import { toast } from "sonner"; interface McpConsentToastProps { toastId: string | number; serverName: string; toolName: string; toolDescription?: string | null; inputPreview?: string | null; onDecision: (decision: "accept-once" | "accept-always" | "decline") => void; } export function McpConsentToast({ toastId, serverName, toolName, toolDescription, inputPreview, onDecision, }: McpConsentToastProps) { const handleClose = () => toast.dismiss(toastId); const handle = (d: "accept-once" | "accept-always" | "decline") => { onDecision(d); toast.dismiss(toastId); }; // Collapsible tool description state const [isExpanded, setIsExpanded] = React.useState(false); const [collapsedMaxHeight, setCollapsedMaxHeight] = React.useState(0); const [hasOverflow, setHasOverflow] = React.useState(false); const descRef = React.useRef(null); // Collapsible input preview state const [isInputExpanded, setIsInputExpanded] = React.useState(false); const [inputCollapsedMaxHeight, setInputCollapsedMaxHeight] = React.useState(0); const [inputHasOverflow, setInputHasOverflow] = React.useState(false); const inputRef = React.useRef(null); React.useEffect(() => { if (!toolDescription) { setHasOverflow(false); return; } const element = descRef.current; if (!element) return; const compute = () => { const computedStyle = window.getComputedStyle(element); const lineHeight = parseFloat(computedStyle.lineHeight || "20"); const maxLines = 4; // show first few lines by default const maxHeightPx = Math.max(0, Math.round(lineHeight * maxLines)); setCollapsedMaxHeight(maxHeightPx); // Overflow if full height exceeds our collapsed height setHasOverflow(element.scrollHeight > maxHeightPx + 1); }; // Compute initially and on resize compute(); const onResize = () => compute(); window.addEventListener("resize", onResize); return () => window.removeEventListener("resize", onResize); }, [toolDescription]); React.useEffect(() => { if (!inputPreview) { setInputHasOverflow(false); return; } const element = inputRef.current; if (!element) return; const compute = () => { const computedStyle = window.getComputedStyle(element); const lineHeight = parseFloat(computedStyle.lineHeight || "16"); const maxLines = 6; // show first few lines by default const maxHeightPx = Math.max(0, Math.round(lineHeight * maxLines)); setInputCollapsedMaxHeight(maxHeightPx); setInputHasOverflow(element.scrollHeight > maxHeightPx + 1); }; compute(); const onResize = () => compute(); window.addEventListener("resize", onResize); return () => window.removeEventListener("resize", onResize); }, [inputPreview]); return (

Tool wants to run

{toolName} from {serverName} requests your consent.

{toolDescription && (

{toolDescription}

{hasOverflow && ( )}
)} {inputPreview && (
                    {inputPreview}
                  
{inputHasOverflow && ( )}
)}
); }