import type { Message } from 'ai'; import { toast } from 'sonner'; import { useSWRConfig } from 'swr'; import { useCopyToClipboard } from 'usehooks-ts'; import type { Vote } from '@/lib/db/schema'; import { getMessageIdFromAnnotations } from '@/lib/utils'; import { CopyIcon, ThumbDownIcon, ThumbUpIcon } from './icons'; import { Button } from './ui/button'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from './ui/tooltip'; import { memo } from 'react'; import equal from 'fast-deep-equal'; export function PureMessageActions({ chatId, message, vote, isLoading, }: { chatId: string; message: Message; vote: Vote | undefined; isLoading: boolean; }) { const { mutate } = useSWRConfig(); const [_, copyToClipboard] = useCopyToClipboard(); if (isLoading) return null; if (message.role === 'user') return null; if (message.toolInvocations && message.toolInvocations.length > 0) return null; return (
Copy Upvote Response Downvote Response
); } export const MessageActions = memo( PureMessageActions, (prevProps, nextProps) => { if (!equal(prevProps.vote, nextProps.vote)) return false; if (prevProps.isLoading !== nextProps.isLoading) return false; return true; }, );