'use client'; import React, { useState, useEffect } from 'react'; import { User } from '@/lib/types'; import { api } from '@/lib/api'; import { X, Plus, Loader2, Check, AlertCircle } from 'lucide-react'; import {ROLE_COLORS } from '@/lib/constants'; interface AdminPanelProps { onClose: () => void; } export default function AdminPanel({ onClose }: AdminPanelProps) { const [activeTab, setActiveTab] = useState<'users' | 'management'>('users'); const [users, setUsers] = useState([]); const [loading, setLoading] = useState(false); const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null); const [formData, setFormData] = useState({ username: '', name: '', role: 'employee' as const, department: '', }); useEffect(() => { loadUsers(); }, []); const loadUsers = async () => { try { setLoading(true); const userList = await api.getUsers(); setUsers(userList); } catch (err) { setMessage({ type: 'error', text: 'Failed to load users' }); } finally { setLoading(false); } }; const handleCreateUser = async (e: React.FormEvent) => { e.preventDefault(); if (!formData.username || !formData.name || !formData.department) { setMessage({ type: 'error', text: 'All fields are required' }); return; } try { setLoading(true); await api.adminCreateUser({ username: formData.username, name: formData.name, role: formData.role, department: formData.department, }); setMessage({ type: 'success', text: 'User created successfully' }); setFormData({ username: '', name: '', role: 'employee', department: '' }); await loadUsers(); } catch (err) { setMessage({ type: 'error', text: 'Failed to create user' }); } finally { setLoading(false); } }; const handleIngest = async () => { try { setLoading(true); await api.adminIngest(); setMessage({ type: 'success', text: 'Document ingestion completed successfully' }); } catch (err) { setMessage({ type: 'error', text: 'Failed to trigger ingestion' }); } finally { setLoading(false); } }; return (
{/* Header */}

Admin Panel

{/* Tabs */}
{/* Content */}
{/* Message */} {message && (
{message.type === 'success' ? : } {message.text}
)} {/* Users Tab */} {activeTab === 'users' && (
{/* Create User Form */}

Create New User

setFormData({ ...formData, username: e.target.value }) } placeholder="e.g., user_john" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500" />
setFormData({ ...formData, name: e.target.value })} placeholder="e.g., John Doe" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500" />
setFormData({ ...formData, department: e.target.value }) } placeholder="e.g., Finance, Engineering" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500" />
{/* Users List */}

Current Users

{users.map((user) => (

{user.name}

@{user.username}

{user.role} {user.department}

Access:

{(user.accessible_collections ?? []).map((col) => ( {col} ))}
))}
)} {/* Management Tab */} {activeTab === 'management' && (

Document Ingestion

Re-ingest all documents from the data folder. This will parse, chunk, embed, and store all documents in the vector database.

System Configuration

RBAC Enforcement

Enabled at vector database level

Input Guardrails

Injection, off-topic, PII detection

Output Guardrails

Grounding, citations, leakage detection

Semantic Routing

5 intent-based routes configured

LLM (Groq)

Inference via backend GROQ_API_KEY — not stored in the browser

Collections

{['general', 'finance', 'engineering', 'marketing', 'hr'].map((collection) => (
{collection} ✓ Configured
))}
)}
); }