import { useState, type KeyboardEvent, type ReactElement } from 'react'; interface ComposerProps { onSend: (input: { content: string; provider?: string; modelId?: string }) => void; onStop: () => void; streaming: boolean; /** True from local send time through server turn startup/ack and * throughout streaming — a superset of `streaming` that also covers the * pre-ack window where a second send could otherwise slip through. */ sending: boolean; hasConversation: boolean; } export function Composer({ onSend, onStop, streaming, sending, hasConversation, }: ComposerProps): ReactElement { const [content, setContent] = useState(''); const [provider, setProvider] = useState(''); const [modelId, setModelId] = useState(''); const busy = streaming || sending; function submit(): void { if (busy) return; const trimmed = content.trim(); if (!trimmed) return; onSend({ content: trimmed, provider: provider.trim() || undefined, modelId: modelId.trim() || undefined, }); setContent(''); } function handleKeyDown(event: KeyboardEvent): void { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); submit(); } } return (
{ event.preventDefault(); submit(); }} className="flex flex-col gap-2 border-t p-4" >
setProvider(event.target.value)} placeholder="Provider (optional)" className="rounded border px-2 py-1 text-xs" /> setModelId(event.target.value)} placeholder="Model (optional)" className="rounded border px-2 py-1 text-xs" />