import { Conversation } from "@/types"; import { DEFAULT_SYSTEM_PROMPT } from "@/utils/app/const"; import { FC, useEffect, useRef, useState } from "react"; interface Props { conversation: Conversation; onChangePrompt: (prompt: string) => void; } export const SystemPrompt: FC = ({ conversation, onChangePrompt }) => { const [value, setValue] = useState(""); const textareaRef = useRef(null); const handleChange = (e: React.ChangeEvent) => { const value = e.target.value; const maxLength = 4000; if (value.length > maxLength) { alert(`Prompt limit is ${maxLength} characters`); return; } setValue(value); if (value.length > 0) { onChangePrompt(value); } }; useEffect(() => { if (textareaRef && textareaRef.current) { textareaRef.current.style.height = "inherit"; textareaRef.current.style.height = `${textareaRef.current?.scrollHeight}px`; } }, [value]); useEffect(() => { if (conversation.prompt) { setValue(conversation.prompt); } else { setValue(DEFAULT_SYSTEM_PROMPT); } }, [conversation]); return (