No messages yet
Type @nieo to chat with the AI or invite friends using the room link.
import React, { useState, useEffect, useRef } from 'react'; import { Send, Users, Share2, PlusCircle, Bot, User, Check, Star, Plus, Mic, Camera, Image as ImageIcon, FileText, Moon, Globe, Book, ShoppingBag, Lightbulb, Search, X, LogOut, Copy, ChevronLeft } from 'lucide-react'; const apiKey = ""; // Environment provided key const App = () => { // --- State --- const [user, setUser] = useState({ name: 'User', uid: 'AB12CD34' }); const [messages, setMessages] = useState([]); const [input, setInput] = useState(''); const [roomId, setRoomId] = useState(''); const [isAiLoading, setIsAiLoading] = useState(false); const [menuOpen, setMenuOpen] = useState(false); const [dreamOpen, setDreamOpen] = useState(false); const [copied, setCopied] = useState(false); const scrollRef = useRef(null); // --- Helpers --- const generateId = (len = 12) => { const chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; return Array.from({ length: len }, () => chars[Math.floor(Math.random() * chars.length)]).join(''); }; const getAvatarColor = (id) => { const colors = ['#1a6fff', '#7b2fff', '#ff6b35', '#00c9a7', '#ff3d71', '#ffa94d']; const charSum = [...id].reduce((a, c) => a + c.charCodeAt(0), 0); return colors[charSum % colors.length]; }; // --- Effects --- useEffect(() => { if (!roomId) { const newId = generateId(); setRoomId(newId); setMessages([{ id: 'sys-1', text: 'Room created! Invite friends to join. Type @nieo to talk to the AI.', sender: 'system', time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) }]); } }, []); useEffect(() => { scrollRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages, isAiLoading]); // --- Handlers --- const copyRoomLink = () => { const link = `https://nieo.pages.dev/${roomId}`; try { const el = document.createElement('textarea'); el.value = link; document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (e) { console.error(e); } }; const getAiResponse = async (userPrompt) => { setIsAiLoading(true); try { let retryCount = 0; const maxRetries = 5; const systemPrompt = "You are Nieo, a helpful AI assistant. You only respond when tagged with @nieo. Keep responses concise, friendly, and helpful."; const callApi = async () => { const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent?key=${apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ contents: [{ parts: [{ text: userPrompt }] }], systemInstruction: { parts: [{ text: systemPrompt }] } }) }); if (!response.ok) throw new Error('API Error'); return response.json(); }; const executeWithRetry = async () => { try { return await callApi(); } catch (err) { if (retryCount < maxRetries) { const delay = Math.pow(2, retryCount) * 1000; retryCount++; await new Promise(res => setTimeout(res, delay)); return executeWithRetry(); } throw err; } }; const result = await executeWithRetry(); const aiText = result.candidates?.[0]?.content?.parts?.[0]?.text || "I'm sorry, I'm having trouble thinking right now."; setMessages(prev => [...prev, { id: 'ai-' + Date.now(), text: aiText, sender: 'Nieo AI', isAi: true, time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) }]); } catch (error) { setMessages(prev => [...prev, { id: 'err-' + Date.now(), text: "Connection error. Please try again later.", sender: 'system', time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) }]); } finally { setIsAiLoading(false); } }; const sendMessage = (e) => { e.preventDefault(); if (!input.trim()) return; const userMsg = { id: 'u-' + Date.now(), text: input, sender: 'You', isAi: false, time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) }; setMessages(prev => [...prev, userMsg]); const currentInput = input; setInput(''); if (currentInput.toLowerCase().includes('@nieo')) { getAiResponse(currentInput.replace(/@nieo/gi, '').trim()); } }; // --- Components --- const Avatar = ({ name, id, size = 40 }) => { const col = getAvatarColor(id || name); const initials = name.split(' ').map(w => w[0]).join('').toUpperCase().slice(0, 2); return (
Type @nieo to chat with the AI or invite friends using the room link.
Describe your dream and Nieo uncovers hidden symbols, emotions, and subconscious meanings. Powered by advanced psychological AI models.