aboutsummaryrefslogtreecommitdiff
path: root/apps/memory-graph-playground/src/app/api
diff options
context:
space:
mode:
Diffstat (limited to 'apps/memory-graph-playground/src/app/api')
-rw-r--r--apps/memory-graph-playground/src/app/api/graph/route.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/apps/memory-graph-playground/src/app/api/graph/route.ts b/apps/memory-graph-playground/src/app/api/graph/route.ts
new file mode 100644
index 00000000..b7901966
--- /dev/null
+++ b/apps/memory-graph-playground/src/app/api/graph/route.ts
@@ -0,0 +1,46 @@
+import { NextResponse } from 'next/server'
+
+export async function POST(request: Request) {
+ try {
+ const body = await request.json()
+ const { apiKey, page = 1, limit = 500, sort = 'createdAt', order = 'desc' } = body
+
+ if (!apiKey) {
+ return NextResponse.json(
+ { error: 'API key is required' },
+ { status: 400 }
+ )
+ }
+
+ const response = await fetch('https://api.supermemory.ai/v3/documents/documents', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${apiKey}`,
+ },
+ body: JSON.stringify({
+ page,
+ limit,
+ sort,
+ order,
+ }),
+ })
+
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => ({}))
+ return NextResponse.json(
+ { error: errorData.message || `API error: ${response.status}` },
+ { status: response.status }
+ )
+ }
+
+ const data = await response.json()
+ return NextResponse.json(data)
+ } catch (error) {
+ console.error('Graph API error:', error)
+ return NextResponse.json(
+ { error: 'Failed to fetch documents' },
+ { status: 500 }
+ )
+ }
+}