'use client'; import { Button, Spinner } from "@heroui/react"; import { useRef, useState, useEffect } from "react"; import { Textarea } from "@/components/ui/textarea"; // Add a type to support both message formats type FlexibleMessage = { role: 'user' | 'assistant' | 'system' | 'tool'; content: string | any; version?: string; chatId?: string; createdAt?: string; // Add any other optional fields that might be needed }; export function ComposeBox({ minRows=3, disabled=false, loading=false, handleUserMessage, messages, }: { minRows?: number; disabled?: boolean; loading?: boolean; handleUserMessage: (prompt: string) => void; messages: FlexibleMessage[]; // Use the flexible message type }) { const [input, setInput] = useState(''); const [isFocused, setIsFocused] = useState(false); const inputRef = useRef(null); function handleInput() { const prompt = input.trim(); if (!prompt) { return; } // Clear input before calling handleUserMessage setInput(''); if (inputRef.current) { inputRef.current.value = ''; } handleUserMessage(prompt); } function handleInputKeyDown(event: React.KeyboardEvent) { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); handleInput(); } } // focus on the input field useEffect(() => { if (inputRef.current) { inputRef.current.focus(); inputRef.current.value = input; // Ensure sync with state } }, [messages, input]); return (
{/* Keyboard shortcut hint */}
Press ⌘ + Enter to send
{/* Outer container with padding */}
{/* Textarea */}