import { useState, useRef, useEffect } from 'react'; import { ArrowUp, Square, Sparkles, Bug, TestTube2, Zap } from 'lucide-react'; import { useGLMChat } from '@/hooks/useGLMChat'; import { useAIStore } from '@/stores/aiStore'; import { Textarea } from '@/components/ui/textarea'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { MarkdownMessage } from './MarkdownMessage'; export default function AIChatPanel() { const { sendMessage, stopGeneration, isStreaming } = useGLMChat(); const messages = useAIStore((s) => s.messages); const streamingMessage = useAIStore((s) => s.streamingMessage); const [input, setInput] = useState(''); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages, streamingMessage]); const handleSend = () => { if (!input.trim() || isStreaming) return; const history = messages.map((m) => ({ role: m.role, content: m.content })); sendMessage(input.trim(), history); setInput(''); }; const handleKeyDown = (e: React.KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { e.preventDefault(); handleSend(); } }; const quickActions = [ { icon: Sparkles, label: 'Explain', prefix: 'Explain this code:\n' }, { icon: Bug, label: 'Fix', prefix: 'Fix any issues in this code:\n' }, { icon: TestTube2, label: 'Tests', prefix: 'Write unit tests for this code:\n' }, { icon: Zap, label: 'Optimize', prefix: 'Optimize this code for performance:\n' }, ]; return (
{/* Header */}

AI Assistant

Powered by GLM-5

{/* Messages */}
{messages.length === 0 && !streamingMessage && (

How can I help?

Ask about your code, request fixes, or get explanations.

)} {messages.map((msg) => (
{msg.role === 'user' ? msg.content : }
))} {streamingMessage && (
)}
{/* Quick Actions */}
{quickActions.map((action) => ( ))}
{/* Input */}