"use client"; import React, { useState, useEffect, useRef } from "react"; import { Terminal as TerminalIcon, Activity, Cpu, Sparkles, HelpCircle, Play } from "lucide-react"; interface TerminalLine { type: "input" | "output" | "error" | "success" | "info" | "system"; text: string; } const presets = [ { label: "⚡ Diagnostics", cmd: "status", icon: Activity }, { label: "📊 Benchmarks", cmd: "benchmark", icon: Cpu }, { label: "🧠 Route Query", cmd: "route", icon: Sparkles }, { label: "❓ CLI Help", cmd: "help", icon: HelpCircle }, ]; export function HubLiveTerminal() { const [history, setHistory] = useState([]); const [inputValue, setInputValue] = useState(""); const [isProcessing, setIsProcessing] = useState(false); const consoleContainerRef = useRef(null); // Helper to append lines to the terminal history const appendLine = (type: TerminalLine["type"], text: string) => { setHistory((prev) => [...prev, { type, text }]); }; // Scroll to bottom of terminal container whenever history updates useEffect(() => { if (consoleContainerRef.current) { consoleContainerRef.current.scrollTop = consoleContainerRef.current.scrollHeight; } }, [history]); // Initial simulated boot sequence useEffect(() => { const runBootSequence = async () => { setIsProcessing(true); await new Promise((r) => setTimeout(r, 400)); appendLine("output", "HubAPI Neural Gateway Client CLI [v1.0.0]"); await new Promise((r) => setTimeout(r, 300)); appendLine("info", "Syncing connections with global model registries…"); await new Promise((r) => setTimeout(r, 500)); appendLine("success", "✔ Connection established with gateway node US-East-1"); appendLine("success", "✔ Model router mesh status: ONLINE"); await new Promise((r) => setTimeout(r, 300)); appendLine("output", "Ready for execution. Type a command or click a quick action above."); setIsProcessing(false); }; runBootSequence(); }, []); // Simulates character-by-character typing for quick presets const simulateTyping = (cmdText: string) => { if (isProcessing) return; setIsProcessing(true); setInputValue(""); let idx = 0; const timer = setInterval(() => { setInputValue(cmdText.slice(0, idx + 1)); idx++; if (idx >= cmdText.length) { clearInterval(timer); setTimeout(() => { setInputValue(""); processCommand(cmdText); }, 200); } }, 50); }; // Parse and process command scripts const processCommand = async (cmd: string) => { setIsProcessing(true); appendLine("input", `> ${cmd}`); const cleanCmd = cmd.trim().toLowerCase(); const args = cleanCmd.split(" "); const primary = args[0]; // Wait a brief delay to simulate network latency await new Promise((r) => setTimeout(r, 400)); switch (primary) { case "help": appendLine("system", "HUBAPI CLI COMMAND DIRECTORY"); appendLine("info", " status - Check active node routing latency & system loads"); appendLine("info", " benchmark - Run latency and cost tests across primary LLM nodes"); appendLine("info", " route - Run intelligent query routing simulation"); appendLine("info", " clear - Clear the screen buffer logs"); appendLine("info", " help - Display this menu guide"); break; case "clear": setHistory([]); break; case "status": appendLine("output", "Broadcasting health status query across model registry…"); await new Promise((r) => setTimeout(r, 450)); appendLine("success", "✔ Primary Gateway: US-East-1 Node (Virginia) - Active [14ms]"); appendLine("success", "✔ Secondary Node: EU-West-3 Node (Paris) - Active [76ms]"); await new Promise((r) => setTimeout(r, 300)); appendLine("info", "Connected Model Providers: OpenAI, Anthropic, Google, Mistral, Meta"); appendLine("output", "System Status: HEALTHY | Current load: 12.8% | Nodes online: 142/142"); break; case "benchmark": appendLine("output", "Starting model speed/cost benchmark (10KB prompt payload)…"); await new Promise((r) => setTimeout(r, 600)); appendLine("system", "MODEL LATENCY COST/1M TOK ROUTING SCORE"); appendLine("system", "---------------------------------------------------------------"); await new Promise((r) => setTimeout(r, 200)); appendLine("info", "Claude 4.7 Opus 270ms $3.00 98.5/100 (Optimum)"); await new Promise((r) => setTimeout(r, 150)); appendLine("output", "Qwen 4.6 310ms $5.00 97.0/100"); await new Promise((r) => setTimeout(r, 150)); appendLine("output", "Gemini 3.5 Pro 430ms $7.00 94.8/100"); await new Promise((r) => setTimeout(r, 150)); appendLine("output", "GLM 5.1 480ms $4.00 91.5/100"); await new Promise((r) => setTimeout(r, 300)); appendLine("success", "🏆 Recommendation: Route to Claude 4.7 Opus (Optimizes cost/speed ratio)"); break; case "route": appendLine("output", "Simulating dynamic query routing…"); await new Promise((r) => setTimeout(r, 400)); appendLine("info", "[ROUTER] Ingress query: ‘Analyze scanned legal document (2.4M tokens)’"); await new Promise((r) => setTimeout(r, 450)); appendLine("info", "[ROUTER] Checking constraints: Context size > 2M, Cost budget < $20"); await new Promise((r) => setTimeout(r, 450)); appendLine("info", "[ROUTER] Checking candidates: Claude 4.7 Opus (budget fail), Qwen 4.6 (context limit fail)"); await new Promise((r) => setTimeout(r, 500)); appendLine("success", "✔ Route mapped: Gemini 3.5 Pro (2M context limit native)"); await new Promise((r) => setTimeout(r, 300)); appendLine("success", "✔ Query processed. Execution: 1.62s. Transaction Cost: $14.40"); break; case "": break; default: appendLine("error", `Command not found: '${cmd}'. Type 'help' to see available commands.`); } setIsProcessing(false); }; const handleCommandSubmit = (e: React.FormEvent) => { e.preventDefault(); if (isProcessing || !inputValue.trim()) return; const cmd = inputValue; setInputValue(""); processCommand(cmd); }; const [cpuLoad, setCpuLoad] = useState(12.8); useEffect(() => { const interval = setInterval(() => { setCpuLoad(Number((10 + Math.random() * 5).toFixed(1))); }, 3000); return () => clearInterval(interval); }, []); return (
{/* Decorative background grid and vectors */}
{/* Preset Command Buttons (Futuristic clip buttons) */}
{presets.map((preset, idx) => { const Icon = preset.icon; return ( ); })}
{/* Terminal Shell Window (Cyber Glass with Corner Brackets) */}
{/* Terminal Header */}
HUBAPI Network Shell
{/* Live CPU Telemetry Meter */}
CPU: {cpuLoad}%
ONLINE
{/* CRT Scanline Console Box */}
{history.map((line, idx) => { let colorClass = "text-primary/80"; if (line.type === "input") colorClass = "text-primary font-bold shadow-[0_0_8px_rgba(255,170,64,0.3)]"; if (line.type === "error") colorClass = "text-destructive font-semibold"; if (line.type === "success") colorClass = "text-emerald-400 font-semibold shadow-[0_0_8px_rgba(52,211,153,0.2)]"; if (line.type === "info") colorClass = "text-blue-400"; if (line.type === "system") colorClass = "text-amber-500 font-bold shadow-[0_0_8px_rgba(245,158,11,0.2)]"; if (line.type === "output") colorClass = "text-primary/70"; return (
{line.text}
); })}
{/* Command Interactive Prompt Form (Glowing Neon input) */}
> setInputValue(e.target.value)} disabled={isProcessing} placeholder={isProcessing ? "Executing command sequence…" : "Type command (e.g. status, benchmark) and hit Enter…"} className="flex-1 bg-transparent border-none outline-none text-primary placeholder:text-primary/30 select-text focus:ring-0 focus:outline-none" />
); }