import { ReactNode, useEffect, useMemo, useState } from 'react'; import { motion } from 'framer-motion'; import { getStoredGatewayUrl } from '../lib/gateway-client'; import { useGatewayStore, type PluginStatus } from '../store/gatewayStore'; import { toChatAgent, useChatStore, type CodeBlock } from '../store/chatStore'; import { Wifi, WifiOff, Bot, BarChart3, Plug, RefreshCw, MessageSquare, Cpu, FileText, User, Activity, Brain, Shield, Sparkles, GraduationCap, List, Network } from 'lucide-react'; // === Helper to extract code blocks from markdown content === function extractCodeBlocksFromContent(content: string): CodeBlock[] { const blocks: CodeBlock[] = []; const regex = /```(\w*)\n([\s\S]*?)```/g; let match; while ((match = regex.exec(content)) !== null) { const language = match[1] || 'text'; const codeContent = match[2].trim(); // Try to extract filename from first line comment let filename: string | undefined; let actualContent = codeContent; // Check for filename patterns like "# filename.py" or "// filename.js" const firstLine = codeContent.split('\n')[0]; const filenameMatch = firstLine.match(/^(?:#|\/\/|\/\*|