import { useRecoilState } from 'recoil'; import type { ChangeEvent } from 'react'; import { useChatContext } from '~/Providers'; import { useRequiresKey } from '~/hooks'; import AttachFile from './Files/AttachFile'; import StopButton from './StopButton'; import SendButton from './SendButton'; import FileRow from './Files/FileRow'; import Textarea from './Textarea'; import store from '~/store'; export default function ChatForm({ index = 0 }) { const [text, setText] = useRecoilState(store.textByIndex(index)); const [showStopButton, setShowStopButton] = useRecoilState(store.showStopButtonByIndex(index)); const { ask, files, setFiles, conversation, isSubmitting, handleStopGenerating, filesLoading, setFilesLoading, } = useChatContext(); const submitMessage = () => { ask({ text }); setText(''); }; const { requiresKey } = useRequiresKey(); const { endpoint: _endpoint, endpointType } = conversation ?? { endpoint: null }; const endpoint = endpointType ?? _endpoint; return (
{ e.preventDefault(); submitMessage(); }} className="stretch mx-2 flex flex-row gap-3 last:mb-2 md:mx-4 md:last:mb-6 lg:mx-auto lg:max-w-2xl xl:max-w-3xl" >
(
{children}
)} /> {endpoint && (