"use client"; import { useEffect, useState, type CSSProperties } from 'react'; import type { Node } from '@/types/database'; interface AutoContextSettings { autoContextEnabled: boolean; lastPinnedMigration?: string; } interface NodeWithMetrics extends Node { edge_count?: number; } export default function ContextViewer() { const [nodes, setNodes] = useState([]); const [enabled, setEnabled] = useState(false); const [loadingNodes, setLoadingNodes] = useState(true); const [loadingSettings, setLoadingSettings] = useState(true); const [saving, setSaving] = useState(false); useEffect(() => { const loadNodes = async () => { try { const res = await fetch('/api/nodes?sortBy=edges&limit=10'); const payload = await res.json(); setNodes(payload.data || []); } catch (e) { console.error(e); } finally { setLoadingNodes(false); } }; const loadSettings = async () => { try { const res = await fetch('/api/system/auto-context'); const payload = await res.json() as { success: boolean; data?: AutoContextSettings }; if (payload.success && payload.data) { setEnabled(payload.data.autoContextEnabled); } } catch (e) { console.error(e); } finally { setLoadingSettings(false); } }; loadNodes(); loadSettings(); }, []); const handleToggle = async () => { if (saving) return; setSaving(true); try { const res = await fetch('/api/system/auto-context', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ autoContextEnabled: !enabled }), }); const payload = await res.json() as { success: boolean; data?: AutoContextSettings }; if (payload.success && payload.data) { setEnabled(payload.data.autoContextEnabled); } } catch (e) { console.error(e); } finally { setSaving(false); } }; return (

Top 10 most-connected nodes are added to background context for tool execution.

{/* Toggle */}
Auto-Context
{loadingSettings ? 'Loading...' : enabled ? 'Enabled' : 'Disabled'}
{/* Nodes List */}
Top Nodes
{loadingNodes ? (
Loading...
) : nodes.length === 0 ? (
No connected nodes yet.
) : (
{nodes.map((node) => (
{node.title || 'Untitled'} {node.edge_count ?? 0}
{node.dimensions && node.dimensions.length > 0 && (
{node.dimensions.slice(0, 3).map((dim) => ( {dim} ))}
)}
))}
)}
); } const containerStyle: CSSProperties = { padding: 24, height: '100%', overflow: 'auto' }; const descStyle: CSSProperties = { fontSize: 13, color: 'var(--settings-muted)', marginBottom: 20, lineHeight: 1.5 }; const cardStyle: CSSProperties = { background: 'var(--settings-card-bg)', border: '1px solid var(--settings-border)', borderRadius: 8, padding: 16, marginBottom: 24, }; const labelStyle: CSSProperties = { fontSize: 13, fontWeight: 500, color: 'var(--settings-text)', marginBottom: 8 }; const subLabelStyle: CSSProperties = { fontSize: 12, color: 'var(--settings-muted)' }; const mutedStyle: CSSProperties = { fontSize: 13, color: 'var(--settings-muted)' }; const toggleStyle: CSSProperties = { width: 48, height: 26, borderRadius: 13, border: '1px solid var(--settings-border)', cursor: 'pointer', position: 'relative', transition: 'background 0.15s', }; const toggleKnobStyle: CSSProperties = { position: 'absolute', top: 4, width: 18, height: 18, borderRadius: '50%', background: 'var(--settings-text)', transition: 'left 0.15s', }; const nodeCardStyle: CSSProperties = { padding: '12px 14px', background: 'var(--settings-card-bg)', border: '1px solid var(--settings-border)', borderRadius: 6, }; const nodeTitleStyle: CSSProperties = { fontSize: 13, fontWeight: 500, color: 'var(--settings-text)' }; const edgeCountStyle: CSSProperties = { fontSize: 12, color: 'var(--settings-muted)' }; const dimTagStyle: CSSProperties = { padding: '2px 8px', borderRadius: 4, fontSize: 11, background: 'var(--settings-chip-bg)', color: 'var(--settings-subtext)', border: '1px solid var(--settings-border)', };