import React, { useState, useEffect, useRef } from 'react'; import { api, NexusMarkdown } from '@nexus/shared'; const COLORS = { brand: "#1E40AF", brandDark: "#1E3A8A", gray50: "#F9FAFB", gray100: "#F3F4F6", gray200: "#E5E7EB", gray500: "#6B7280", gray800: "#1F2937", gray900: "#111827", gray400: "#9CA3AF", }; export const NexusMasterAgent: React.FC = () => { const [isOpen, setIsOpen] = useState(false); const [query, setQuery] = useState(""); const [messages, setMessages] = useState([]); const [loading, setLoading] = useState(false); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages]); const handleQuery = async (e: React.FormEvent) => { e.preventDefault(); if (!query.trim()) return; const userMsg = { role: "user", content: query }; setMessages(prev => [...prev, userMsg]); setQuery(""); setLoading(true); try { const resp = await api.post('nexus/query/', { query: userMsg.content, chat_history: messages.slice(-5).map(m => ({ role: m.role, content: m.content })) }); setMessages(prev => [...prev, { role: "assistant", content: resp.data.answer }]); } catch (err) { console.error("Nexus Query Failed:", err); setMessages(prev => [...prev, { role: "assistant", content: "I encountered an error connecting to the Nexus Master engine. Please try again or contact support." }]); } finally { setLoading(false); } }; return ( <> {/* Floating Pulse Hub (FAB) */}
setIsOpen(!isOpen)} style={{ position: 'fixed', bottom: 32, right: 32, width: 56, height: 56, border: 'none', borderRadius: '50%', background: 'linear-gradient(135deg, #1E40AF 0%, #1E3A8A 100%)', boxShadow: '0 8px 30px rgba(30, 64, 175, 0.4)', cursor: 'pointer', zIndex: 1000, display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275)', transform: isOpen ? 'rotate(135deg)' : 'none' }} > {isOpen ? '×' : 'N'} {/* Pulse Ring */} {!isOpen && (
)} {/* Live Indicator */}
{/* Glassmorphic Interaction Pane */} {isOpen && (
{/* Header */}
N
Nexus Master
Active Workspace Intelligence
{/* Messages */}
{messages.length === 0 && (
🪐
Nexus Command
Ask me anything about your tickets, team performance, or workspace documentation.
)} {messages.map((m, i) => (
))} {loading && (
{[0,1,2].map(d => (
))}
)}
{/* Footer Input */}
setQuery(e.target.value)} style={{ flex: 1, padding: '10px 14px', border: 'none', background: 'none', fontSize: 14, outline: 'none', fontWeight: 500, color: COLORS.gray900 }} />
)} ); };