({
messages,
streaming,
error,
composerRef,
pendingDraft,
onPendingDraftConsumed,
onSend,
onStop,
onRetry,
onFeedback,
}: Props)
| 18 | } |
| 19 | |
| 20 | export function Thread({ |
| 21 | messages, |
| 22 | streaming, |
| 23 | error, |
| 24 | composerRef, |
| 25 | pendingDraft, |
| 26 | onPendingDraftConsumed, |
| 27 | onSend, |
| 28 | onStop, |
| 29 | onRetry, |
| 30 | onFeedback, |
| 31 | }: Props) { |
| 32 | const [draft, setDraft] = useState(''); |
| 33 | |
| 34 | useEffect(() => { |
| 35 | if (pendingDraft) { |
| 36 | setDraft(pendingDraft); |
| 37 | onPendingDraftConsumed?.(); |
| 38 | setTimeout(() => composerRef.current?.focus(), 100); |
| 39 | } |
| 40 | }, [pendingDraft]); |
| 41 | const scrollRef = useRef<HTMLDivElement>(null); |
| 42 | |
| 43 | useEffect(() => { |
| 44 | const el = scrollRef.current; |
| 45 | if (!el) return; |
| 46 | el.scrollTop = el.scrollHeight; |
| 47 | }, [messages, streaming]); |
| 48 | |
| 49 | const submit = () => { |
| 50 | const text = draft.trim(); |
| 51 | if (!text || streaming) return; |
| 52 | onSend(text); |
| 53 | setDraft(''); |
| 54 | }; |
| 55 | |
| 56 | const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { |
| 57 | if (e.key === 'Enter' && !e.shiftKey) { |
| 58 | e.preventDefault(); |
| 59 | submit(); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | const lastAssistantId = [...messages].reverse().find((m) => m.role === 'assistant')?.id; |
| 64 | const empty = messages.length === 0; |
| 65 | |
| 66 | return ( |
| 67 | <div className="da-thread"> |
| 68 | <div className="da-scroll" ref={scrollRef}> |
| 69 | {empty ? ( |
| 70 | <div className="da-welcome"> |
| 71 | <div className="da-welcome-hero"> |
| 72 | <div className="da-welcome-text"> |
| 73 | <h3>{WELCOME.headline}</h3> |
| 74 | <p>{WELCOME.sub}</p> |
| 75 | </div> |
| 76 | <IllustrationWelcome className="da-welcome-illustration" /> |
| 77 | </div> |
nothing calls this directly
no test coverage detected
searching dependent graphs…