'use client'; import React, { useState, useEffect } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Loader2, CheckCircle, XCircle, RefreshCw, Trash2, Database, BrainCircuit } from 'lucide-react'; import { cleanupAllOrphans, syncAllEmbeddings } from '@/app/actions/notes'; import { toast } from 'sonner'; export default function SettingsPage() { const [loading, setLoading] = useState(false); const [cleanupLoading, setCleanupLoading] = useState(false); const [syncLoading, setSyncLoading] = useState(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 [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 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); } }; useEffect(() => { checkConnection(); }, []); return (

Settings

AI Diagnostics {status === 'success' && } {status === 'error' && } Check your AI provider connection status.
{/* Current Configuration */}

Configured Provider

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

API Status

{status === 'success' ? 'Operational' : 'Error'}
{/* Test Result */} {result && (

Test Details:

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

Troubleshooting Tips:

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

Clean Orphan Tags

Remove tags that are no longer used by any notes.

Semantic Indexing AI

Generate vectors for all notes to enable intent-based search.

); }