import React, { useState, useEffect, useRef } from 'react'; import { Users, ShieldCheck, Bot, History, ClipboardList, Lock } from 'lucide-react'; import { cn } from '../lib/utils'; import { LOG_ENTRIES } from '../constants'; import { api, hasAdminKey } from '../api'; import type { LogEntry, Proposal } from '../types'; interface AgentStatus { name: string; version: string; status: string; progress: number; skill_count: number; ts: string; alert: boolean; model?: string; } export const BotConfig: React.FC = () => { const [proactiveAlerts, setProactiveAlerts] = useState(true); const [metaNotifications, setMetaNotifications] = useState(true); const [agents, setAgents] = useState([]); const [logs, setLogs] = useState(LOG_ENTRIES); const [proposals, setProposals] = useState([]); const [hallazgos, setHallazgos] = useState([]); const teamTokenRef = useRef(null); const teamChatIdRef = useRef(null); const adminChatIdRef = useRef(null); useEffect(() => { api.getAgentsStatus().then(setAgents).catch(() => {}); api.getLogs().then((data: LogEntry[]) => { if (data?.length) setLogs(data); }).catch(() => {}); api.getProposals().then((data: { proposals: Proposal[]; hallazgos: Proposal[] }) => { if (data?.proposals?.length) setProposals(data.proposals); if (data?.hallazgos?.length) setHallazgos(data.hallazgos); }).catch(() => {}); }, []); const adminUnlocked = hasAdminKey(); const handleSaveBotConfig = async () => { // En modo demo (sin key) no se guarda: evita el prompt de admin al pasar por los inputs. if (!adminUnlocked) return; try { await api.saveTelegramConfig({ team_token: teamTokenRef.current?.value || '', team_chat_id: teamChatIdRef.current?.value || '', admin_chat_id: adminChatIdRef.current?.value || '', proactive_alerts: proactiveAlerts, meta_notifications: metaNotifications, xyz_threshold: 'alta', }); } catch {} }; const displayAgents = agents.length > 0 ? agents : [ { name: 'AgenteOrquestador', version: 'v2.4.12', status: 'Stable', ts: '', progress: 80, skill_count: 3, alert: false, model: 'meta-llama/Llama-3.2-1B-Instruct' }, { name: 'AgenteML', version: 'v4.0.0', status: 'Adjusting', ts: '', progress: 55, skill_count: 5, alert: true, model: 'Qwen/Qwen2.5-7B-Instruct' }, { name: 'AgenteMeta', version: 'v1.2.8', status: 'Active', ts: '', progress: 92, skill_count: 7, alert: false, model: 'meta-llama/Llama-3.1-8B-Instruct' }, { name: 'AgenteNotificador', version: 'v2.1.0', status: 'Stable', ts: '', progress: 72, skill_count: 2, alert: false, model: '' }, ]; return (
{/* Agent Stats */}
{displayAgents.map((agent, idx) => { const dark = idx === 2; // AgenteMeta siempre con fondo oscuro return (
{agent.name} {agent.version} {agent.model ? ( {agent.model.split('/').pop()?.replace('-Instruct', '') ?? agent.model} ) : ( sin LLM )}
{agent.status}
TS: {agent.ts || '—'}
); })}
{/* Logs and Proposals */}
{/* Cambios Aplicados */}

Cambios aplicados

Historial Reactivo
{logs.map((log) => (

{log.title}

Hash: {log.hash} {log.timestamp}
))}
{/* Propuestas y Hallazgos */}

Propuestas y Hallazgos

Solo bot admin
{/* Propuestas proactivas */} {proposals.length > 0 && (
Propuestas {proposals.map((p) => (
Propuesta #{p.seq}

{p.title}

{p.description}

Justificación técnica

{p.justification}

{p.status === "aprobado" ? "Aprobado" : p.status === "rechazado" ? "Rechazado" : "Pendiente"} {(!p.status || p.status === "pendiente") && (

Bot: /aprobar {p.id}  · /rechazar {p.id}

)}
))}
)} {/* Hallazgos del sistema */} {hallazgos.length > 0 && (
Hallazgos del sistema {hallazgos.map((h) => (
Hallazgo #{h.seq}

{h.title}

{h.description}

))}
)} {proposals.length === 0 && hallazgos.length === 0 && (

Sin propuestas ni hallazgos registrados.

)}
{/* Bot Configuration */}

Configuración del Bot

{!adminUnlocked && (
Solo lectura en modo demo — la configuración requiere API key de administrador
)}
{/* Canal Equipo */}
Canal Equipo
Alertas Proactivas
{/* Canal Admin */}
Canal Admin
Notificaciones AgenteMeta
Conectado · última actividad hace 2h
); };