"use client"; import { useState } from "react"; import { Check, Copy, ThumbsDown, ThumbsUp } from "lucide-react"; import { cn } from "@/lib/utils"; import { buttonVariants } from "fumadocs-ui/components/ui/button"; import { submitFeedbackToInkeep, logEventToInkeep, } from "@/lib/inkeep-analytics"; interface MessageFeedbackProps { messageId: string; userMessageId?: string; content: string; className?: string; } export function MessageFeedback({ messageId, userMessageId, content, className, }: MessageFeedbackProps) { const [feedback, setFeedback] = useState<"positive" | "negative" | null>( null, ); const [copied, setCopied] = useState(false); const [isSubmittingFeedback, setIsSubmittingFeedback] = useState(false); const [showSuccessCheckmark, setShowSuccessCheckmark] = useState< "positive" | "negative" | null >(null); const handleFeedback = async (type: "positive" | "negative") => { if (isSubmittingFeedback || feedback === type) return; const feedbackMessageId = userMessageId || messageId; setIsSubmittingFeedback(true); try { await submitFeedbackToInkeep(feedbackMessageId, type, [ { label: type === "positive" ? "helpful_response" : "unhelpful_response", details: type === "positive" ? "The response was helpful" : "The response was not helpful", }, ]); setFeedback(type); setShowSuccessCheckmark(type); setTimeout(() => { setShowSuccessCheckmark(null); }, 1000); } catch (error) { } finally { setIsSubmittingFeedback(false); } }; const handleCopy = async () => { if (copied) return; const eventMessageId = userMessageId || messageId; try { await navigator.clipboard.writeText(content); setCopied(true); await logEventToInkeep("message:copied", "message", eventMessageId); setTimeout(() => setCopied(false), 2000); } catch (error) { // Silently handle error } }; return (
); }