import { ChangeEvent, FormEvent, useEffect, useRef } from 'react'; import { ArrowPathIcon, PaperAirplaneIcon, XMarkIcon, PlusIcon, StopIcon, } from '@heroicons/react/24/outline'; import { Button } from '@nx/nx-dev/ui-common'; import Textarea from 'react-textarea-autosize'; import { ChatRequestOptions } from 'ai'; import { cx } from '@nx/nx-dev/ui-primitives'; export function Prompt({ isGenerating, showNewChatCta, showRegenerateCta, onSubmit, onInputChange, onNewChat, onStopGenerating, onRegenerate, input, }: { isGenerating: boolean; showNewChatCta: boolean; showRegenerateCta: boolean; onSubmit: ( e: FormEvent, chatRequestOptions?: ChatRequestOptions | undefined ) => void; onInputChange: ( e: ChangeEvent | ChangeEvent ) => void; onNewChat: () => void; onStopGenerating: () => void; onRegenerate: () => void; input: string; }) { const formRef = useRef(null); const inputRef = useRef(null); useEffect(() => { if (!isGenerating) inputRef.current?.focus(); }, [isGenerating]); const handleSubmit = (event: FormEvent) => { if (inputRef.current?.value.trim()) onSubmit(event); else event.preventDefault(); }; const handleNewChat = () => { onNewChat(); inputRef.current?.focus(); }; const handleStopGenerating = () => { onStopGenerating(); inputRef.current?.focus(); }; return (
{isGenerating && ( )} {showNewChatCta && ( )} {showRegenerateCta && ( )}