"use client"; import { useState } from "react"; import { Copy, Edit3, RefreshCw, Check } from "lucide-react"; type MessageActionsProps = { content: string; disabled?: boolean; onEdit?: () => void; onRegenerate?: () => void; extractCodeBlocks?: ( text: string ) => Array<{ language: string; code: string }>; }; export function MessageActions({ content, disabled, onEdit, onRegenerate, extractCodeBlocks, }: MessageActionsProps) { const [copied, setCopied] = useState<"none" | "markdown" | "text" | "code">( "none" ); const copy = async (text: string, flag: MessageActionsProps["content"]) => { await navigator.clipboard.writeText(text); setCopied(flag as any); setTimeout(() => setCopied("none"), 1500); }; const stripMarkdown = (md: string) => md .replace(/```[\s\S]*?```/g, (block) => block.replace(/```[\s\S]*?\n/, "").replace(/```$/, "") ) .replace(/[#*_>`~-]/g, ""); const codeBlocks = extractCodeBlocks ? extractCodeBlocks(content) : []; return (
{codeBlocks.map((b, i) => ( ))} {onEdit && ( )} {onRegenerate && ( )}
); }