"use client" import { useState, useCallback } from 'react' import { MemoryGraph, type DocumentWithMemories } from '@supermemory/memory-graph' interface DocumentsResponse { documents: DocumentWithMemories[] pagination: { currentPage: number limit: number totalItems: number totalPages: number } } export default function Home() { const [apiKey, setApiKey] = useState('') const [documents, setDocuments] = useState([]) const [isLoading, setIsLoading] = useState(false) const [isLoadingMore, setIsLoadingMore] = useState(false) const [error, setError] = useState(null) const [hasMore, setHasMore] = useState(false) const [currentPage, setCurrentPage] = useState(0) const [showGraph, setShowGraph] = useState(false) const PAGE_SIZE = 500 const fetchDocuments = useCallback(async (page: number, append = false) => { if (!apiKey) return if (page === 1) { setIsLoading(true) } else { setIsLoadingMore(true) } setError(null) try { const response = await fetch('/api/graph', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ apiKey, page, limit: PAGE_SIZE, sort: 'createdAt', order: 'desc', }), }) if (!response.ok) { const errorData = await response.json() throw new Error(errorData.error || 'Failed to fetch documents') } const data: DocumentsResponse = await response.json() if (append) { setDocuments(prev => [...prev, ...data.documents]) } else { setDocuments(data.documents) } setCurrentPage(data.pagination.currentPage) setHasMore(data.pagination.currentPage < data.pagination.totalPages) setShowGraph(true) } catch (err) { setError(err instanceof Error ? err : new Error('Unknown error')) } finally { setIsLoading(false) setIsLoadingMore(false) } }, [apiKey]) const loadMoreDocuments = useCallback(async () => { if (hasMore && !isLoadingMore) { await fetchDocuments(currentPage + 1, true) } }, [hasMore, isLoadingMore, currentPage, fetchDocuments]) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (apiKey) { setDocuments([]) setCurrentPage(0) fetchDocuments(1) } } return (
{/* Header */}

Memory Graph Playground

Test the @supermemory/memory-graph package

setApiKey(e.target.value)} className="w-80 rounded-lg border border-zinc-700 bg-zinc-800 px-4 py-2 text-sm text-white placeholder-zinc-500 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500" />
{/* Main content */}
{!showGraph ? (

Get Started

Enter your Supermemory API key above to visualize your memory graph.

Features to test:

  • Pan and zoom the graph
  • Click on nodes to see details
  • Drag nodes around
  • Use the space selector to filter
  • Pagination loads more documents
) : (

No memories found. Add some content to see your graph.

)}
) }