import { useState, useRef, useEffect, useCallback } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { PanelRightClose, PanelRightOpen, TrendingUp, Wallet, Bot, ChevronDown, ChevronRight, Send, Sparkles, } from 'lucide-react' import { useLanguage } from '../contexts/LanguageContext' import { MarketTicker } from '../components/agent/MarketTicker' import { PositionsPanel } from '../components/agent/PositionsPanel' import { TraderStatusPanel } from '../components/agent/TraderStatusPanel' interface Message { id: string role: 'user' | 'bot' text: string time: string streaming?: boolean } // Simple markdown-ish renderer: bold, code, newlines function renderMessageContent(text: string) { // Split by code blocks first const parts = text.split(/(```[\s\S]*?```|`[^`]+`)/g) return parts.map((part, i) => { if (part.startsWith('```') && part.endsWith('```')) { const code = part.slice(3, -3).replace(/^\w+\n/, '') // strip language hint return (
{code}
)
}
if (part.startsWith('`') && part.endsWith('`')) {
return (
{part.slice(1, -1)}
)
}
// Handle bold **text**
const boldParts = part.split(/(\*\*[^*]+\*\*)/g)
return boldParts.map((bp, j) => {
if (bp.startsWith('**') && bp.endsWith('**')) {
return (
{bp.slice(2, -2)}
)
}
return {bp}
})
})
}
let msgIdCounter = 0
function nextId() {
return `msg-${Date.now()}-${++msgIdCounter}`
}
export function AgentChatPage() {
const { language } = useLanguage()
const [sidebarOpen, setSidebarOpen] = useState(() => window.innerWidth > 1024)
const [messages, setMessages] = useState