Spaces:
No application file
No application file
Download src/components/ChatPanel.tsx from usrrootkali/Awakened_RiShre: direct link, hf CLI and curl.
- Browser
- Download file 11.8 kB
-
https://huggingface.co/spaces/usrrootkali/Awakened_RiShre/resolve/main/src/components/ChatPanel.tsx
- Command line
-
hf download hf://spaces/usrrootkali/Awakened_RiShre/src/components/ChatPanel.tsx
-
curl -L -o ChatPanel.tsx https://huggingface.co/spaces/usrrootkali/Awakened_RiShre/resolve/main/src/components/ChatPanel.tsx
11.8 kB
| import React, { useState, useRef, useEffect } from 'react'; | |
| import { ChatMessage, ProjectFile } from '../types'; | |
| import { ThreeAwakenedMatrix } from './ThreeAwakenedMatrix'; | |
| import { | |
| Send, | |
| Sparkles, | |
| Bot, | |
| User, | |
| Copy, | |
| Check, | |
| Code, | |
| Play, | |
| Zap, | |
| MessageSquare, | |
| } from 'lucide-react'; | |
| interface ChatPanelProps { | |
| messages: ChatMessage[]; | |
| isGenerating: boolean; | |
| onSendMessage: (text: string) => void; | |
| onApplyCodeToProject?: (files: { name: string; content: string }[]) => void; | |
| tokensGenerated?: number; | |
| currentFiles: ProjectFile[]; | |
| } | |
| export const ChatPanel: React.FC<ChatPanelProps> = ({ | |
| messages, | |
| isGenerating, | |
| onSendMessage, | |
| onApplyCodeToProject, | |
| tokensGenerated = 0, | |
| }) => { | |
| const [input, setInput] = useState(''); | |
| const [copiedId, setCopiedId] = useState<string | null>(null); | |
| const messagesEndRef = useRef<HTMLDivElement>(null); | |
| const textareaRef = useRef<HTMLTextAreaElement>(null); | |
| useEffect(() => { | |
| messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); | |
| }, [messages, isGenerating]); | |
| const handleSubmit = (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| if (!input.trim() || isGenerating) return; | |
| onSendMessage(input.trim()); | |
| setInput(''); | |
| }; | |
| const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | |
| if (e.key === 'Enter' && !e.shiftKey) { | |
| e.preventDefault(); | |
| handleSubmit(e); | |
| } | |
| }; | |
| const handleCopy = (text: string, id: string) => { | |
| navigator.clipboard.writeText(text); | |
| setCopiedId(id); | |
| setTimeout(() => setCopiedId(null), 2000); | |
| }; | |
| const samplePrompts = [ | |
| { label: 'Explain the philosophy of Vibe Coding & modern AI', icon: '🧠' }, | |
| { label: 'Brainstorm 3 multi-million dollar SaaS micro-apps', icon: '💡' }, | |
| { label: 'Synthesize a luxury glassmorphism fintech dashboard', icon: '💎' }, | |
| { label: 'Add an interactive particle trail on cursor movement', icon: '⚡' }, | |
| ]; | |
| const renderMessageContent = (msg: ChatMessage) => { | |
| const content = msg.content; | |
| const parts = content.split(/(```[\s\S]*?```)/g); | |
| return parts.map((part, idx) => { | |
| if (part.startsWith('```') && part.endsWith('```')) { | |
| const lines = part.slice(3, -3).trim().split('\n'); | |
| const header = lines[0].trim(); | |
| const codeBody = lines.slice(1).join('\n'); | |
| const codeId = `${msg.id}-${idx}`; | |
| let filename = header; | |
| if (header.includes('file:')) { | |
| filename = header.split('file:')[1].replace(/[/*\->#]/g, '').trim(); | |
| } else if (header.includes(' ')) { | |
| filename = header.split(' ')[1].trim(); | |
| } | |
| return ( | |
| <div key={codeId} className="my-3 rounded-2xl overflow-hidden border border-purple-500/30 bg-[#090414] shadow-[0_4px_25px_rgba(0,0,0,0.5)]"> | |
| <div className="flex items-center justify-between px-4 py-2 bg-[#14082b] border-b border-purple-500/25 text-xs text-purple-200 font-mono"> | |
| <div className="flex items-center gap-2"> | |
| <Code className="w-3.5 h-3.5 text-fuchsia-400" /> | |
| <span className="text-purple-200 font-bold">{filename || 'code'}</span> | |
| </div> | |
| <div className="flex items-center gap-1.5"> | |
| <button | |
| onClick={() => handleCopy(codeBody, codeId)} | |
| className="flex items-center gap-1 px-2.5 py-1 rounded-lg bg-[#200d45] hover:bg-[#2b125e] text-[11px] text-purple-200 transition-colors cursor-pointer border border-purple-500/20" | |
| > | |
| {copiedId === codeId ? <Check className="w-3 h-3 text-emerald-400" /> : <Copy className="w-3 h-3 text-purple-300" />} | |
| <span>{copiedId === codeId ? 'Copied' : 'Copy'}</span> | |
| </button> | |
| {onApplyCodeToProject && filename && ( | |
| <button | |
| onClick={() => onApplyCodeToProject([{ name: filename, content: codeBody }])} | |
| className="flex items-center gap-1 px-3 py-1 rounded-lg bg-gradient-to-r from-purple-600/40 to-fuchsia-600/40 hover:from-purple-600/60 hover:to-fuchsia-600/60 text-[11px] font-bold text-white border border-purple-400/40 transition-all cursor-pointer shadow-[0_0_12px_rgba(168,85,247,0.3)]" | |
| title="Apply directly to project preview" | |
| > | |
| <Play className="w-3 h-3 text-fuchsia-300" /> | |
| <span>Apply</span> | |
| </button> | |
| )} | |
| </div> | |
| </div> | |
| <pre className="p-3.5 text-xs font-mono text-purple-100 overflow-x-auto max-h-72 leading-relaxed bg-[#070312]"> | |
| <code>{codeBody}</code> | |
| </pre> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div key={idx} className="whitespace-pre-wrap leading-relaxed text-purple-100 text-xs sm:text-sm"> | |
| {part} | |
| </div> | |
| ); | |
| }); | |
| }; | |
| return ( | |
| <div className="flex flex-col h-full bg-[#080412] border-r border-purple-500/20 overflow-hidden"> | |
| {/* Chat Header: RiShre Awakened Unified Agent Badge */} | |
| <div className="px-4 py-3 bg-[#0d061c]/90 border-b border-purple-500/20 flex items-center justify-between shrink-0 backdrop-blur-md"> | |
| <div className="flex items-center gap-2.5"> | |
| <div className="w-6 h-6 rounded-lg bg-gradient-to-tr from-purple-600 to-fuchsia-500 flex items-center justify-center shadow-[0_0_12px_rgba(168,85,247,0.5)]"> | |
| <Sparkles className="w-3.5 h-3.5 text-white" /> | |
| </div> | |
| <div> | |
| <div className="flex items-center gap-2"> | |
| <span className="text-xs font-bold text-white tracking-wide">RiShre Awakened</span> | |
| <span className="w-1.5 h-1.5 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]"></span> | |
| </div> | |
| <p className="text-[10px] text-purple-300/70 font-mono">Omniscient AI Agent & Vibe Engine</p> | |
| </div> | |
| </div> | |
| <div className="px-2.5 py-1 rounded-full bg-purple-950/80 border border-purple-500/30 text-[10px] font-mono text-purple-300 flex items-center gap-1.5"> | |
| <span className="w-1.5 h-1.5 rounded-full bg-fuchsia-400"></span> | |
| <span>AUTONOMOUS</span> | |
| </div> | |
| </div> | |
| {/* Message Stream */} | |
| <div className="flex-1 overflow-y-auto p-4 space-y-4"> | |
| {messages.length === 0 && ( | |
| <div className="flex flex-col items-center justify-center h-full text-center p-6 text-purple-300/80"> | |
| <div className="w-16 h-16 rounded-3xl bg-gradient-to-br from-purple-900/60 to-fuchsia-950/60 border border-purple-500/40 flex items-center justify-center mb-4 shadow-[0_0_40px_rgba(168,85,247,0.3)]"> | |
| <Zap className="w-8 h-8 text-fuchsia-400" /> | |
| </div> | |
| <h3 className="text-base font-bold text-white tracking-wide">RiShre Awakened Model Ready</h3> | |
| <p className="text-xs text-purple-300/80 mt-2 max-w-sm leading-relaxed"> | |
| I am your versatile AI partner. Talk with me about high-level ideas, request architectural design, or describe apps and watch them come to life in the live preview. | |
| </p> | |
| <div className="mt-6 flex flex-col gap-2 w-full max-w-sm"> | |
| <span className="text-[11px] font-mono text-purple-400 uppercase tracking-wider text-left font-bold">Suggested Prompts:</span> | |
| {samplePrompts.map((p, i) => ( | |
| <button | |
| key={i} | |
| onClick={() => onSendMessage(p.label)} | |
| className="text-left text-xs bg-[#120826]/80 hover:bg-[#1a0c38] border border-purple-500/20 hover:border-purple-400/50 p-3 rounded-2xl text-purple-200 hover:text-white transition-all cursor-pointer shadow-sm hover:shadow-[0_0_20px_rgba(168,85,247,0.25)] flex items-center gap-2.5" | |
| > | |
| <span className="text-sm shrink-0">{p.icon}</span> | |
| <span className="truncate">{p.label}</span> | |
| </button> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| {messages.map((msg) => ( | |
| <div | |
| key={msg.id} | |
| className={`flex gap-3 ${msg.role === 'user' ? 'justify-end' : 'justify-start'}`} | |
| > | |
| {msg.role !== 'user' && ( | |
| <div className="w-7 h-7 rounded-xl bg-gradient-to-tr from-purple-600 to-fuchsia-600 flex items-center justify-center shrink-0 shadow-[0_0_12px_rgba(168,85,247,0.4)] mt-0.5"> | |
| <Bot className="w-4 h-4 text-white" /> | |
| </div> | |
| )} | |
| <div | |
| className={`max-w-[88%] rounded-2xl p-4 ${ | |
| msg.role === 'user' | |
| ? 'bg-gradient-to-r from-purple-700 via-purple-600 to-fuchsia-600 text-white shadow-[0_4px_25px_rgba(168,85,247,0.35)]' | |
| : 'bg-[#120726]/90 border border-purple-500/30 text-purple-100 shadow-[0_4px_30px_rgba(7,4,15,0.8)] backdrop-blur-xl' | |
| }`} | |
| > | |
| <div className="flex items-center justify-between text-[11px] text-purple-300/80 mb-2 font-mono"> | |
| <span className="font-bold text-purple-200">{msg.role === 'user' ? 'You' : 'RiShre Awakened'}</span> | |
| <span>{new Date(msg.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</span> | |
| </div> | |
| {renderMessageContent(msg)} | |
| </div> | |
| {msg.role === 'user' && ( | |
| <div className="w-7 h-7 rounded-xl bg-[#1c0c38] border border-purple-500/30 flex items-center justify-center shrink-0 mt-0.5"> | |
| <User className="w-4 h-4 text-purple-300" /> | |
| </div> | |
| )} | |
| </div> | |
| ))} | |
| {isGenerating && ( | |
| <div className="flex flex-col items-center my-4 animate-in fade-in duration-300"> | |
| <ThreeAwakenedMatrix | |
| statusText="RiShre Awakened is synthesizing..." | |
| tokensCount={tokensGenerated} | |
| /> | |
| </div> | |
| )} | |
| <div ref={messagesEndRef} /> | |
| </div> | |
| {/* Input Form */} | |
| <div className="p-3 bg-[#0a0517] border-t border-purple-500/20 shrink-0"> | |
| <form onSubmit={handleSubmit} className="relative flex items-end bg-[#130829] border border-purple-500/30 rounded-2xl p-2.5 focus-within:border-purple-400 focus-within:shadow-[0_0_25px_rgba(168,85,247,0.3)] transition-all"> | |
| <textarea | |
| ref={textareaRef} | |
| value={input} | |
| onChange={(e) => setInput(e.target.value)} | |
| onKeyDown={handleKeyDown} | |
| rows={1} | |
| disabled={isGenerating} | |
| placeholder={isGenerating ? 'Synthesizing response...' : 'Chat, ask questions, or describe app modifications... (Enter to send)'} | |
| className="flex-1 bg-transparent text-xs sm:text-sm text-purple-100 placeholder-purple-400/50 px-2 py-1.5 resize-none focus:outline-none max-h-32 min-h-[36px]" | |
| /> | |
| <button | |
| type="submit" | |
| disabled={!input.trim() || isGenerating} | |
| className={`p-2.5 rounded-xl transition-all ${ | |
| input.trim() && !isGenerating | |
| ? 'bg-gradient-to-r from-purple-600 via-fuchsia-600 to-pink-500 text-white font-bold shadow-[0_0_20px_rgba(168,85,247,0.5)] hover:scale-105 active:scale-95 cursor-pointer' | |
| : 'bg-[#1e0d3b] text-purple-500/50 cursor-not-allowed' | |
| }`} | |
| > | |
| <Send className="w-4 h-4" /> | |
| </button> | |
| </form> | |
| <div className="flex items-center justify-between text-[10px] text-purple-400/60 mt-2 px-1"> | |
| <span>RiShre Awakened • Autonomous AI Studio</span> | |
| <span className="font-mono">Shift+Enter for newline</span> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| }; | |