'use client' import React, { useState } from 'react' import { SettingsNav, SettingsSection } from '@/components/settings' import { Button } from '@/components/ui/button' import { Loader2, CheckCircle, XCircle, RefreshCw, Database, BrainCircuit } from 'lucide-react' import { cleanupAllOrphans, syncAllEmbeddings } from '@/app/actions/notes' import { toast } from 'sonner' import { useLanguage } from '@/lib/i18n' import Link from 'next/link' export default function SettingsPage() { const { t } = useLanguage() const [loading, setLoading] = useState(false) const [cleanupLoading, setCleanupLoading] = useState(false) const [syncLoading, setSyncLoading] = useState(false) const [status, setStatus] = useState<'idle' | 'success' | 'error'>('idle') const [result, setResult] = useState(null) const [config, setConfig] = useState(null) const checkConnection = async () => { setLoading(true) setStatus('idle') setResult(null) try { const res = await fetch('/api/ai/test') const data = await res.json() setConfig({ provider: data.provider, status: res.ok ? 'connected' : 'disconnected' }) if (res.ok) { setStatus('success') setResult(data) } else { setStatus('error') setResult(data) } } catch (error: any) { console.error(error) setStatus('error') setResult({ message: error.message, stack: error.stack }) } finally { setLoading(false) } } const handleSync = async () => { setSyncLoading(true) try { const result = await syncAllEmbeddings() if (result.success) { toast.success(`Indexing complete: ${result.count} notes processed`) } } catch (error) { console.error(error) toast.error("Error during indexing") } finally { setSyncLoading(false) } } const handleCleanup = async () => { setCleanupLoading(true) try { const result = await cleanupAllOrphans() if (result.success) { toast.success(result.message || `Cleanup complete: ${result.created} created, ${result.deleted} removed`) } } catch (error) { console.error(error) toast.error("Error during cleanup") } finally { setCleanupLoading(false) } } return (

Settings

Configure your application settings

{/* Quick Links */}

AI Settings

Configure AI features and provider

Profile Settings

Manage your account and preferences

{/* AI Diagnostics */} 🔍} description="Check your AI provider connection status" >

Configured Provider

{config?.provider || '...'}

API Status

{status === 'success' && } {status === 'error' && } {status === 'success' ? 'Operational' : status === 'error' ? 'Error' : 'Checking...'}
{result && (

Test Details:

{JSON.stringify(result, null, 2)}
{status === 'error' && (

Troubleshooting Tips:

  • Check that Ollama is running (ollama list)
  • Check URL (http://localhost:11434)
  • Verify model (e.g., granite4:latest) is downloaded
  • Check Next.js server terminal for more logs
)}
)}
{/* Maintenance */} 🔧} description="Tools to maintain your database health" >

Clean Orphan Tags

Remove tags that are no longer used by any notes

Semantic Indexing

Generate vectors for all notes to enable intent-based search

) }