"use client"; import { useState, useRef, useEffect } from "react"; const AGENTS = ["LUCIDIA", "ALICE", "OCTAVIA", "PRISM", "ECHO", "CIPHER"] as const; type Agent = typeof AGENTS[number]; const AGENT_COLORS: Record = { LUCIDIA: "#9C27B0", ALICE: "#2979FF", OCTAVIA: "#F5A623", PRISM: "#00BCD4", ECHO: "#4CAF50", CIPHER: "#FF1D6C", }; interface Message { role: "user" | "assistant"; content: string; agent?: Agent; } export default function ChatPage() { const [messages, setMessages] = useState([]); const [input, setInput] = useState(""); const [agent, setAgent] = useState("LUCIDIA"); const [loading, setLoading] = useState(false); const bottomRef = useRef(null); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); async function send() { if (!input.trim() || loading) return; const userMsg: Message = { role: "user", content: input }; setMessages(m => [...m, userMsg]); setInput(""); setLoading(true); try { const res = await fetch("/api/chat", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message: input, agent }), }); const data = await res.json(); setMessages(m => [...m, { role: "assistant", content: data.content, agent }]); } catch { setMessages(m => [...m, { role: "assistant", content: "Connection error. Is the gateway running?", agent }]); } finally { setLoading(false); } } return (
{/* Header */}

Agent Chat

{AGENTS.map(a => ( ))}
{/* Messages */}
{messages.length === 0 && (

💜

Select an agent and start chatting

Current: {agent}

)} {messages.map((msg, i) => (
{msg.role === "assistant" && msg.agent && (

{msg.agent}

)}

{msg.content}

))} {loading && (

{agent}

Thinking…

)}
{/* Input */}
setInput(e.target.value)} onKeyDown={e => e.key === "Enter" && !e.shiftKey && (e.preventDefault(), send())} placeholder={`Message ${agent}…`} disabled={loading} className="flex-1 bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-sm outline-none focus:border-white/30 disabled:opacity-50" />
); }