'use client'; import { ChatRequestOptions, Message } from 'ai'; import { Button } from './ui/button'; import { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react'; import { Textarea } from './ui/textarea'; import { deleteTrailingMessages } from '@/app/(chat)/actions'; import { toast } from 'sonner'; export type MessageEditorProps = { message: Message; setMode: Dispatch>; setMessages: ( messages: Message[] | ((messages: Message[]) => Message[]), ) => void; reload: ( chatRequestOptions?: ChatRequestOptions, ) => Promise; }; export function MessageEditor({ message, setMode, setMessages, reload, }: MessageEditorProps) { const [isSubmitting, setIsSubmitting] = useState(false); const [draftContent, setDraftContent] = useState(message.content); const textareaRef = useRef(null); useEffect(() => { if (textareaRef.current) { adjustHeight(); } }, []); const adjustHeight = () => { if (textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${textareaRef.current.scrollHeight + 2}px`; } }; const handleInput = (event: React.ChangeEvent) => { setDraftContent(event.target.value); adjustHeight(); }; return (