Spaces:
Paused

nexus / frontend /apps /customer /src /components /NexusMasterAgent.tsx
dushyantsingh0
backend stabilization
accf280
Raw History Blame Contribute Delete
9.53 kB
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<any[]>([]);
const [loading, setLoading] = useState(false);
const scrollRef = useRef<HTMLDivElement>(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 (
<>
<style>
{`
@keyframes nexus-pulse {
0% { transform: scale(1); opacity: 0.6; }
100% { transform: scale(1.6); opacity: 0; }
}
@keyframes nexus-slide-up {
from { opacity: 0; transform: translateY(40px) scale(0.95); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes nexus-typing {
0%, 100% { transform: translateY(0); opacity: 0.3; }
50% { transform: translateY(-4px); opacity: 1; }
}
`}
</style>
{/* Floating Pulse Hub (FAB) */}
<div
onClick={() => 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'
}}
>
<span style={{ color: '#fff', fontSize: 22, fontWeight: 900, userSelect: 'none' }}>{isOpen ? '×' : 'N'}</span>
{/* Pulse Ring */}
{!isOpen && (
<div style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
borderRadius: '50%',
border: `2px solid ${COLORS.brand}`,
animation: 'nexus-pulse 2s infinite',
pointerEvents: 'none'
}} />
)}
{/* Live Indicator */}
<div style={{
position: 'absolute',
top: 0,
right: 0,
width: 14,
height: 14,
borderRadius: '50%',
background: '#10B981',
border: '2px solid #fff',
boxShadow: '0 0 8px rgba(16, 185, 129, 0.5)'
}} />
</div>
{/* Glassmorphic Interaction Pane */}
{isOpen && (
<div style={{
position: 'fixed',
bottom: 104,
right: 32,
width: 380,
height: 580,
maxHeight: 'calc(100vh - 140px)',
background: 'rgba(255, 255, 255, 0.82)',
backdropFilter: 'blur(20px) saturate(180%)',
borderRadius: 24,
border: '1px solid rgba(255, 255, 255, 0.5)',
boxShadow: '0 24px 80px rgba(0,0,0,0.18)',
zIndex: 999,
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
animation: 'nexus-slide-up 0.5s cubic-bezier(0.19, 1, 0.22, 1)'
}}>
{/* Header */}
<div style={{ padding: '24px', background: 'rgba(255,255,255,0.4)', borderBottom: `1px solid rgba(0,0,0,0.05)` }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<div style={{
width: 36, height: 36, borderRadius: '50%',
background: 'linear-gradient(135deg, #1E40AF 0%, #1E3A8A 100%)',
display: 'flex', alignItems: 'center', justifyContent: 'center',
fontSize: 14, color: '#fff', fontWeight: 900
}}>N</div>
<div>
<div style={{ fontSize: 16, fontWeight: 800, color: COLORS.gray800, letterSpacing: '-0.01em' }}>Nexus Master</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<div style={{ width: 6, height: 6, borderRadius: '50%', background: '#10B981' }} />
<span style={{ fontSize: 12, color: COLORS.gray500, fontWeight: 600 }}>Active Workspace Intelligence</span>
</div>
</div>
</div>
</div>
{/* Messages */}
<div ref={scrollRef} style={{ flex: 1, overflowY: 'auto', padding: '24px', display: 'flex', flexDirection: 'column', gap: 20 }}>
{messages.length === 0 && (
<div style={{ textAlign: 'center', padding: '40px 24px' }}>
<div style={{ fontSize: 36, marginBottom: 16 }}>🪐</div>
<div style={{ fontSize: 17, fontWeight: 800, color: COLORS.gray800, marginBottom: 8 }}>Nexus Command</div>
<div style={{ fontSize: 14, color: COLORS.gray500, lineHeight: 1.6 }}>
Ask me anything about your tickets, team performance, or workspace documentation.
</div>
</div>
)}
{messages.map((m, i) => (
<div key={i} style={{
alignSelf: m.role === 'user' ? 'flex-end' : 'flex-start',
maxWidth: '88%',
padding: '12px 18px',
borderRadius: m.role === 'user' ? '20px 20px 4px 20px' : '20px 20px 20px 4px',
background: m.role === 'user' ? COLORS.brand : '#fff',
color: m.role === 'user' ? '#fff' : COLORS.gray800,
fontSize: 14,
lineHeight: 1.5,
boxShadow: m.role === 'assistant' ? '0 4px 20px rgba(0,0,0,0.06)' : '0 4px 15px rgba(30, 64, 175, 0.15)',
border: m.role === 'assistant' ? `1px solid rgba(0,0,0,0.05)` : 'none',
wordBreak: 'break-word'
}}>
<NexusMarkdown content={m.content} isMe={m.role === 'user'} />
</div>
))}
{loading && (
<div style={{ alignSelf: 'flex-start', background: '#fff', padding: '14px 20px', borderRadius: 20, boxShadow: '0 4px 20px rgba(0,0,0,0.06)', border: `1px solid rgba(0,0,0,0.05)` }}>
<div style={{ display: 'flex', gap: 5 }}>
{[0,1,2].map(d => (
<div key={d} style={{ width: 5, height: 5, borderRadius: '50%', background: COLORS.brand, animation: 'nexus-typing 1.2s infinite', animationDelay: `${d * 0.2}s` }} />
))}
</div>
</div>
)}
</div>
{/* Footer Input */}
<form onSubmit={handleQuery} style={{ padding: '24px', background: 'rgba(255,255,255,0.6)', borderTop: `1px solid rgba(0,0,0,0.05)` }}>
<div style={{ display: 'flex', gap: 12, background: '#fff', padding: '6px', borderRadius: 16, border: `1px solid ${COLORS.gray200}`, boxShadow: '0 2px 10px rgba(0,0,0,0.02)' }}>
<input
placeholder="Ask your command center..."
value={query}
onChange={e => setQuery(e.target.value)}
style={{
flex: 1, padding: '10px 14px', border: 'none', background: 'none',
fontSize: 14, outline: 'none', fontWeight: 500, color: COLORS.gray900
}}
/>
<button
type="submit"
disabled={!query.trim() || loading}
style={{
width: 38, height: 38, borderRadius: 12, border: 'none',
background: COLORS.brand, color: '#fff', cursor: 'pointer',
display: 'flex', alignItems: 'center', justifyContent: 'center',
opacity: (!query.trim() || loading) ? 0.4 : 1,
transition: 'transform 0.2s'
}}
onMouseEnter={e => !(!query.trim() || loading) && (e.currentTarget.style.transform = 'scale(1.05)')}
onMouseLeave={e => e.currentTarget.style.transform = 'scale(1)'}
>
<div style={{ transform: 'rotate(-45deg) translate(2px, -2px)', fontSize: 16 }}>🚀</div>
</button>
</div>
</form>
</div>
)}
</>
);
};