Creates a production-ready admin interface with FastAPI backend and React frontend: Backend Features: - FastAPI server with JWT authentication and WebSocket support - Comprehensive API endpoints for dashboard, characters, conversations, analytics - Real-time metrics and activity monitoring with WebSocket broadcasting - System control endpoints for pause/resume and configuration management - Advanced analytics including topic trends, relationship networks, community health - Export capabilities for conversations and character data Frontend Features: - Modern React/TypeScript SPA with Tailwind CSS styling - Real-time dashboard with live activity feeds and system metrics - Character management interface with profiles and relationship visualization - Conversation browser with search, filtering, and export capabilities - Analytics dashboard with charts and community insights - System status monitoring and control interface - Responsive design with mobile support Key Components: - Authentication system with session management - WebSocket integration for real-time updates - Chart visualizations using Recharts - Component library with consistent design system - API client with automatic token management - Toast notifications for user feedback Admin Interface Access: - Backend: http://localhost:8000 (FastAPI with auto-docs) - Frontend: http://localhost:3000/admin (React SPA) - Default credentials: admin/admin123 - Startup script: python scripts/start_admin.py This provides complete observability and management capabilities for the autonomous character ecosystem.
130 lines
4.1 KiB
Python
Executable File
130 lines
4.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Start the Discord Fishbowl Admin Interface
|
|
Launches both the FastAPI backend and React frontend
|
|
"""
|
|
|
|
import asyncio
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
import signal
|
|
import time
|
|
from pathlib import Path
|
|
|
|
def run_command(cmd, cwd=None, env=None):
|
|
"""Run a command and return the process"""
|
|
print(f"Starting: {' '.join(cmd)}")
|
|
return subprocess.Popen(
|
|
cmd,
|
|
cwd=cwd,
|
|
env=env,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
universal_newlines=True
|
|
)
|
|
|
|
def main():
|
|
"""Main function to start the admin interface"""
|
|
project_root = Path(__file__).parent.parent
|
|
admin_frontend_path = project_root / "admin-frontend"
|
|
|
|
processes = []
|
|
|
|
try:
|
|
print("🚀 Starting Discord Fishbowl Admin Interface...")
|
|
print("=" * 50)
|
|
|
|
# Start FastAPI backend
|
|
print("\n📡 Starting FastAPI backend server...")
|
|
backend_env = os.environ.copy()
|
|
backend_env["PYTHONPATH"] = str(project_root)
|
|
|
|
backend_process = run_command(
|
|
[sys.executable, "-m", "uvicorn", "src.admin.app:app", "--host", "0.0.0.0", "--port", "8000", "--reload"],
|
|
cwd=project_root,
|
|
env=backend_env
|
|
)
|
|
processes.append(("Backend", backend_process))
|
|
|
|
# Wait a bit for backend to start
|
|
time.sleep(3)
|
|
|
|
# Check if npm is available and admin-frontend exists
|
|
if not admin_frontend_path.exists():
|
|
print("❌ Admin frontend directory not found!")
|
|
print("Please ensure admin-frontend directory exists")
|
|
return 1
|
|
|
|
# Check if node_modules exists, if not run npm install
|
|
node_modules_path = admin_frontend_path / "node_modules"
|
|
if not node_modules_path.exists():
|
|
print("\n📦 Installing frontend dependencies...")
|
|
npm_install = run_command(
|
|
["npm", "install"],
|
|
cwd=admin_frontend_path
|
|
)
|
|
npm_install.wait()
|
|
if npm_install.returncode != 0:
|
|
print("❌ Failed to install npm dependencies")
|
|
return 1
|
|
|
|
# Start React frontend
|
|
print("\n🌐 Starting React frontend server...")
|
|
frontend_process = run_command(
|
|
["npm", "start"],
|
|
cwd=admin_frontend_path
|
|
)
|
|
processes.append(("Frontend", frontend_process))
|
|
|
|
print("\n✅ Admin interface is starting up!")
|
|
print("📡 Backend API: http://localhost:8000")
|
|
print("🌐 Frontend UI: http://localhost:3000/admin")
|
|
print("\n🔑 Default login credentials:")
|
|
print(" Username: admin")
|
|
print(" Password: admin123")
|
|
print("\n🛑 Press Ctrl+C to stop all services")
|
|
print("=" * 50)
|
|
|
|
# Monitor processes
|
|
while True:
|
|
time.sleep(1)
|
|
|
|
# Check if any process has died
|
|
for name, process in processes:
|
|
if process.poll() is not None:
|
|
print(f"\n❌ {name} process has stopped unexpectedly!")
|
|
return 1
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n🛑 Shutting down admin interface...")
|
|
|
|
# Terminate all processes
|
|
for name, process in processes:
|
|
print(f" Stopping {name}...")
|
|
try:
|
|
process.terminate()
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
print(f" Force killing {name}...")
|
|
process.kill()
|
|
process.wait()
|
|
|
|
print("✅ Admin interface stopped successfully")
|
|
return 0
|
|
|
|
except Exception as e:
|
|
print(f"\n❌ Error starting admin interface: {e}")
|
|
|
|
# Clean up processes
|
|
for name, process in processes:
|
|
try:
|
|
process.terminate()
|
|
process.wait(timeout=2)
|
|
except:
|
|
process.kill()
|
|
|
|
return 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |