"use client"; import { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import LogsViewer from './LogsViewer'; import ToolsViewer from './ToolsViewer'; import WorkflowsViewer from './WorkflowsViewer'; import ApiKeysViewer from './ApiKeysViewer'; import DatabaseViewer from './DatabaseViewer'; import ExternalAgentsPanel from './ExternalAgentsPanel'; import ContextViewer from './ContextViewer'; import { apiKeyService } from '@/services/storage/apiKeys'; export type SettingsTab = | 'logs' | 'tools' | 'workflows' | 'apikeys' | 'database' | 'context' | 'agents'; interface SettingsModalProps { isOpen: boolean; onClose: () => void; initialTab?: SettingsTab; } type TabType = SettingsTab; export default function SettingsModal({ isOpen, onClose, initialTab }: SettingsModalProps) { // Default to API Keys tab if no keys are configured, otherwise logs const getDefaultTab = (): TabType => { if (typeof window !== 'undefined') { const hasKeys = apiKeyService.getOpenAiKey() || apiKeyService.getAnthropicKey(); return hasKeys ? 'logs' : 'apikeys'; } return 'logs'; }; const [activeTab, setActiveTab] = useState(getDefaultTab()); useEffect(() => { if (!isOpen) return; const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose(); } }; window.addEventListener('keydown', handleEscape); return () => window.removeEventListener('keydown', handleEscape); }, [isOpen, onClose]); useEffect(() => { if (!isOpen || !initialTab) return; setActiveTab(initialTab); }, [initialTab, isOpen]); if (!isOpen) return null; const modalContent = (
e.stopPropagation()} > {/* Sidebar */}
Settings
Local Mode

This open-source build runs entirely on your machine. Add keys via the API Keys tab to unlock every agent.

{/* Content Area */}
{/* Header */}

{activeTab === 'logs' && 'System Logs'} {activeTab === 'tools' && 'Tools'} {activeTab === 'workflows' && 'Workflows'} {activeTab === 'apikeys' && 'API Keys'} {activeTab === 'database' && 'Knowledge Database'} {activeTab === 'context' && 'Auto-Context'} {activeTab === 'agents' && 'External Agents'}

{/* Content */}
{activeTab === 'logs' && } {activeTab === 'tools' && } {activeTab === 'workflows' && } {activeTab === 'apikeys' && } {activeTab === 'database' && } {activeTab === 'context' && } {activeTab === 'agents' && }
); return createPortal(modalContent, document.body); }