'use client'; import { useEffect, useRef } from 'react'; import './chat-overrides.css'; import { FiSend } from 'react-icons/fi'; import { useChatStreaming } from './useChatStreaming'; export default function ChatWindowStreaming({ api = '/api/chat', badgeId }: { api?: string, badgeId: string }) { const { messages, input, setInput, sending, sendMessage } = useChatStreaming({ api, badgeId }); const listRef = useRef(null); useEffect(() => { if (listRef.current) listRef.current.scrollTop = listRef.current.scrollHeight; }, [messages]); // Prefill input from URL chatPrompt if present useEffect(() => { try { if (typeof window === 'undefined') return; const url = new URL(window.location.href); const prompt = url.searchParams.get('chatPrompt'); if (prompt && prompt.trim()) { setInput(prompt); } } catch {} }, [setInput]); return (
{messages.map(m => (
{m.content}
))}
setInput(e.target.value)} onKeyDown={e=>{ if (e.key==='Enter') sendMessage(); }} className="flex-1 px-3 py-2 rounded border kyd-chat-input" style={{ background: 'var(--input-background)', color: 'var(--text-main)', borderColor: 'var(--icon-button-secondary)' }} placeholder="Ask KYD…" />
); }