import { createSignal, Show, For, onMount } from "solid-js"; import { MessageCircle, X, Send, Bot, User, Loader } from "lucide-solid"; const API = "/api/gateway"; interface ChatMessage { role: "user" | "assistant"; content: string; intent?: string; } interface ChatResponse { message: string; conversation_id: string; intent: string; confidence: number; } export function AiChatWidget() { const [isOpen, setIsOpen] = createSignal(false); const [messages, setMessages] = createSignal([ { role: "assistant", content: "Hi! I'm your AI assistant. I can help you create support tickets, fill out forms, generate job descriptions, or write cover letters. What can I help you with?", }, ]); const [input, setInput] = createSignal(""); const [isLoading, setIsLoading] = createSignal(false); const [conversationId, setConversationId] = createSignal(""); const toggleChat = () => setIsOpen((v) => !v); const sendMessage = async () => { const text = input().trim(); if (!text || isLoading()) return; setIsLoading(true); const userMessage: ChatMessage = { role: "user", content: text }; setMessages((prev) => [...prev, userMessage]); setInput(""); try { const res = await fetch(`${API}/api/ai/chat/message`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message: text, conversation_id: conversationId() || undefined, }), }); if (!res.ok) throw new Error("AI request failed"); const data: ChatResponse = await res.json(); if (data.conversation_id && !conversationId()) { setConversationId(data.conversation_id); } const assistantMessage: ChatMessage = { role: "assistant", content: data.message, intent: data.intent, }; setMessages((prev) => [...prev, assistantMessage]); } catch (err) { setMessages((prev) => [ ...prev, { role: "assistant", content: "I'm having trouble connecting right now. Please try again or contact support@nxtgauge.com.", }, ]); } finally { setIsLoading(false); } }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); sendMessage(); } }; return ( <> {/* Floating button */} {/* Chat window */}
{/* Header */}

AI Assistant

Powered by gemma3

{/* Quick actions */}
{["Create Ticket", "Job Description", "Cover Letter", "Fill Form"].map((label) => ( ))}
{/* Messages */}
{(msg) => (
}>

{msg.content}

Intent: {msg.intent}

)}
Thinking...
{/* Input */}
setInput(e.currentTarget.value)} onKeyDown={handleKeyDown} placeholder="Ask me anything..." style={{ flex: 1, height: "40px", "border-radius": "20px", border: "1px solid #E5E7EB", padding: "0 16px", "font-size": "13px", outline: "none", }} />
); }