Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions apps/memory-graph-playground/src/app/api/container-tags/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { NextResponse } from "next/server"

const SUPERMEMORY_API_BASE_URL = "https://api.supermemory.ai"

export async function POST(request: Request) {
try {
const { apiKey } = await request.json()

if (!apiKey) {
return NextResponse.json(
{ error: "API key is required" },
{ status: 400 },
)
}

const containerTagsUrl = new URL(
"/v3/container-tags/list",
SUPERMEMORY_API_BASE_URL,
)

const response = await fetch(containerTagsUrl, {
method: "GET",
headers: {
Authorization: `Bearer ${apiKey}`,
},
})

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("Container tags API error:", error)
return NextResponse.json(
{ error: "Failed to fetch container tags" },
{ status: 500 },
)
}
}
38 changes: 23 additions & 15 deletions apps/memory-graph-playground/src/app/api/graph/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { NextResponse } from "next/server"

const SUPERMEMORY_API_BASE_URL = "https://api.supermemory.ai"

export async function POST(request: Request) {
try {
const body = await request.json()
Expand All @@ -9,6 +11,7 @@ export async function POST(request: Request) {
limit = 500,
sort = "createdAt",
order = "desc",
containerTags,
} = body

if (!apiKey) {
Expand All @@ -18,23 +21,28 @@ export async function POST(request: Request) {
)
}

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,
}),
},
const graphUrl = new URL(
"/v3/documents/documents",
SUPERMEMORY_API_BASE_URL,
)

const response = await fetch(graphUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
page,
limit,
sort,
order,
...(Array.isArray(containerTags) && containerTags.length > 0
? { containerTags }
: {}),
}),
})

if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
return NextResponse.json(
Expand Down
Loading
Loading