import { Loader2, MessageSquare, Send, Sparkles } from 'lucide-react' import { useRef, useState } from 'react' interface ChatMessage { id: string role: 'assistant' | 'user' text: string } const SUGGESTIONS = [ 'List warehouse assets', 'Publish the current pipeline as a private space', 'Configure 8 steps, guidance 1.5, space "wan-demo-1"', 'What can you do?', ] function ChatPanel({ onLog }: { onLog: (msg: string) => void }) { const [messages, setMessages] = useState([ { id: 'm0', role: 'assistant', text: "Hey - I'm your Workshop build assistant. I can configure the Wan 2.2 I2V pipeline, attach LoRAs from your reference library, and publish a private Space. What are we building?", }, ]) const [input, setInput] = useState('') const [thinking, setThinking] = useState(false) const scrollRef = useRef(null) const send = async (raw: string) => { const text = raw.trim() if (!text || thinking) return const userMsg: ChatMessage = { id: `u-${Date.now()}`, role: 'user', text } setMessages(prev => [...prev, userMsg]) setInput('') setThinking(true) onLog('Assistant: ' + text) try { const res = await fetch('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ messages: [...messages, userMsg].map(m => ({ role: m.role, content: m.text })) }), }) const data = await res.json() if (!res.ok) throw new Error(data.detail ?? 'chat failed') setMessages(prev => [...prev, { id: `a-${Date.now()}`, role: 'assistant', text: data.content }]) } catch (e) { onLog('Assistant error: ' + e) setMessages(prev => [...prev, { id: `a-${Date.now()}`, role: 'assistant', text: 'Something went wrong talking to the assistant: ' + e }]) } finally { setThinking(false) } } return (
Workshop Assistant {thinking && }
{messages.map(msg => (
{msg.role === 'assistant' ? ( {msg.text} ) : ( msg.text )}
))} {thinking && (
thinking…
)}
{SUGGESTIONS.map(s => ( ))}
setInput(e.target.value)} onKeyDown={e => e.key === 'Enter' && send(input)} placeholder="Describe the pipeline to build…" className="flex-1 bg-[#0F0F0F] border border-[#2E2E2E] rounded-lg px-3 py-2 text-sm text-white placeholder:text-[#6B6B6B] outline-none focus:border-[#FF9D00]" />
) } export default ChatPanel