'use client' import { useState, useRef, useEffect, useCallback } from 'react' import { useAgentStore } from '@/hooks/useAgentStore' import { useChatWebSocket } from '@/hooks/useWebSocket' import { fetchAPI } from '@/lib/api' const createTask = (goal: any, sessionId?: string) => fetchAPI('/api/v1/tasks/', { method: 'POST', body: JSON.stringify({ goal, session_id: sessionId }) }) const streamChatSSE = async (msgs: any[], sessionId: string, onChunk: (c: string) => void, onDone: (f: string) => void, onErr: (e: string) => void) => { try { const res = await fetchAPI('/api/v1/kernel/orchestrate', { method: 'POST', body: JSON.stringify({ message: msgs[msgs.length-1]?.content || '', session_id: sessionId }) }) // New backend returns {response, ...}; legacy returned {result} onDone(res.response || res.result || 'Response received.') } catch(e: any) { onErr(e.message) } } import MessageBubble from './MessageBubble' import { Send, Square, Zap, MessageSquare, Code2, GitBranch, Brain, Rocket, Workflow, Bot, Globe, Folder, FlaskConical, Eye, Terminal } from 'lucide-react' const QUICK_ACTIONS = [ { icon: Code2, labelEn: 'Build REST API', labelMy: 'REST API တည်ဆောက်', prompt: 'Build a production-ready REST API with FastAPI, SQLite, JWT auth, and full CRUD endpoints' }, { icon: Globe, labelEn: 'Research Web', labelMy: 'Web ရှာဖွေ', prompt: 'Research the latest AI agent frameworks and compare Manus, Genspark, and Devin capabilities' }, { icon: Folder, labelEn: 'Scaffold Project', labelMy: 'Project ဖန်တီး', prompt: 'Create a full-stack project: Next.js 14 frontend + FastAPI backend + Docker + CI/CD pipeline' }, { icon: GitBranch, labelEn: 'Git Operations', labelMy: 'Git လုပ်ဆောင်', prompt: 'Create a new GitHub repository with proper structure, README, .gitignore, and initial commit' }, { icon: FlaskConical,labelEn: 'Generate Tests', labelMy: 'Test ရေး', prompt: 'Generate comprehensive pytest tests with fixtures, mocks, and edge cases for a FastAPI app' }, { icon: Eye, labelEn: 'Generate UI', labelMy: 'UI ဒီဇိုင်း', prompt: 'Create a stunning dark-themed admin dashboard with React, Tailwind, glassmorphism, and charts' }, { icon: Rocket, labelEn: 'Deploy to Vercel', labelMy: 'Vercel တင်', prompt: 'Generate Vercel deployment config with environment variables, edge functions, and CI/CD' }, { icon: Bot, labelEn: 'Multi-Agent Task', labelMy: 'Multi-Agent', prompt: 'Build a full autonomous AI agent system: plan, code, test, and deploy a Telegram AI bot' }, ] export default function ChatPanel() { const [input, setInput] = useState('') const messagesEndRef = useRef(null) const inputRef = useRef(null) const store = useAgentStore() const { messages, sessionId, isStreaming, mode, locale, addMessage, setStreaming, appendChunk, updateMessage, setMode, addEvent } = store const { sendMessage } = useChatWebSocket(sessionId) useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }) }, [messages]) const handleSubmit = useCallback(async (e?: React.FormEvent) => { e?.preventDefault() const text = input.trim() if (!text || isStreaming) return setInput('') inputRef.current?.focus() addMessage({ role: 'user', content: text }) if (mode === 'agent') { const assistantId = addMessage({ role: 'assistant', content: '', streaming: true, agent: 'planner', metadata: { mode: 'agent' }, }) setStreaming(true, assistantId) addEvent({ type: 'task_submitted', data: { goal: text, mode: 'agent' }, agent: 'planner' }) try { const result = await createTask(text, sessionId) store.setActiveTaskId(result.task_id) updateMessage(assistantId, { content: ( `🚀 **Task Created** \`${result.task_id}\`\n\n` + `**Goal:** ${text}\n\n` + `**Status:** Planning → Executing\n\n` + `> 🤖 God Agent v7 Orchestrator routing to specialized agents...\n\n` + `Watch the **Timeline** panel for real-time execution →` ), streaming: false, agent: 'planner', metadata: { task_id: result.task_id, mode: 'agent' }, }) setStreaming(false, null) } catch (err: any) { updateMessage(assistantId, { content: `❌ **Task failed**\n\n${err.message}\n\nMake sure the backend is running at \`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'}\``, streaming: false, agent: 'debug', metadata: { error: true }, }) setStreaming(false, null) } } else { const assistantId = addMessage({ role: 'assistant', content: '', streaming: true, agent: 'chat', metadata: { mode: 'chat' }, }) setStreaming(true, assistantId) const chatMessages = [ ...messages.filter(m => !m.streaming).slice(-10).map(m => ({ role: m.role as 'user' | 'assistant', content: m.content, })), { role: 'user' as const, content: text }, ] await streamChatSSE( chatMessages, sessionId, (chunk) => appendChunk(assistantId, chunk), (full) => { updateMessage(assistantId, { content: full, streaming: false, agent: 'chat' }); setStreaming(false, null) }, (err) => { updateMessage(assistantId, { content: `❌ Stream error: ${err}`, streaming: false, agent: 'debug', metadata: { error: true } }) setStreaming(false, null) } ) } }, [input, isStreaming, mode, messages, sessionId, addMessage, setStreaming, appendChunk, updateMessage, addEvent, store]) const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmit() } } const stopStreaming = () => { if (store.streamingMessageId) updateMessage(store.streamingMessageId, { streaming: false }) setStreaming(false, null) } const autoResize = (e: React.ChangeEvent) => { setInput(e.target.value) e.target.style.height = 'auto' e.target.style.height = Math.min(e.target.scrollHeight, 160) + 'px' } return (
{/* Header */}
God Agent OS v7.0 · 16 agents
{/* Mode switcher */}
{/* Messages */}
{messages.length === 0 ? (
v7

{locale === 'my' ? 'GOD AGENT OS v7' : 'GOD AGENT OS v7'}

Manus + Genspark + Devin (OneHand)

{locale === 'my' ? '16 AI Agent များဖြင့် plan, code, test, deploy အလိုအလျောက်ဆောင်ရွက်မည်' : 'Give me any engineering goal — 16 agents will autonomously plan, code, test & deploy'}

{QUICK_ACTIONS.map(({ icon: Icon, labelEn, labelMy, prompt }) => ( ))}
{locale === 'my' ? 'Agent Mode — Autonomous Task' : 'Agent Mode — autonomous execution'}
{locale === 'my' ? 'Chat Mode — တိုက်ရိုက်' : 'Chat Mode — direct conversation'}
) : ( <> {messages.map(msg => )}
)}
{/* Input */}