aboutsummaryrefslogtreecommitdiff
path: root/apps/backend/src
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2025-02-14 12:43:55 -0800
committerDhravya Shah <[email protected]>2025-02-14 12:43:55 -0800
commit186efa4244846bf761c7cf4f9cc5d1087b8f95df (patch)
tree16cca1d69a22ccee586ea0eb64703817ac2330f9 /apps/backend/src
parentdocs: remove getting started title (diff)
downloadsupermemory-186efa4244846bf761c7cf4f9cc5d1087b8f95df.tar.xz
supermemory-186efa4244846bf761c7cf4f9cc5d1087b8f95df.zip
delete spaces
Diffstat (limited to 'apps/backend/src')
-rw-r--r--apps/backend/src/index.tsx29
-rw-r--r--apps/backend/src/routes/actions.ts17
-rw-r--r--apps/backend/src/routes/spaces.ts38
3 files changed, 56 insertions, 28 deletions
diff --git a/apps/backend/src/index.tsx b/apps/backend/src/index.tsx
index 55aa58c7..1d62b543 100644
--- a/apps/backend/src/index.tsx
+++ b/apps/backend/src/index.tsx
@@ -128,28 +128,31 @@ export const app = new Hono<{ Variables: Variables; Bindings: Env }>()
.all("/api/*", async (c) => {
// Get the full URL and path
const url = new URL(c.req.url);
- const path = url.pathname.replace("/api", "/v1");
+ const path = url.pathname;
+ const newPath = path.replace("/api", "/v1");
// Preserve query parameters and build target URL
- const redirectUrl = path + url.search;
-
- // Forward the request with same method, headers and body
- const response = await fetch(redirectUrl, {
- method: c.req.method,
- headers: c.req.raw.headers,
- body:
- c.req.method !== "GET" && c.req.method !== "HEAD"
- ? await c.req.blob()
- : undefined,
- });
+ const redirectUrl = "https://api.supermemory.ai" + newPath + url.search;
- return response;
+ // Use c.redirect() for a proper redirect
+ return c.redirect(redirectUrl);
})
.route("/v1/user", user)
.route("/v1/spaces", spacesRoute)
.route("/v1", actions)
.route("/v1/integrations", integrations)
.route("/v1/memories", memories)
+ .get("/v1/session", (c) => {
+ const user = c.get("user");
+
+ if (!user) {
+ return c.json({ error: "Unauthorized" }, 401);
+ }
+
+ return c.json({
+ user,
+ });
+ })
.post(
"/waitlist",
zValidator(
diff --git a/apps/backend/src/routes/actions.ts b/apps/backend/src/routes/actions.ts
index bcddec43..c0801ada 100644
--- a/apps/backend/src/routes/actions.ts
+++ b/apps/backend/src/routes/actions.ts
@@ -88,7 +88,7 @@ const actions = new Hono<{ Variables: Variables; Bindings: Env }>()
apiKey: c.env.BRAINTRUST_API_KEY,
});
- const googleClient = wrapAISDKModel(openai(c.env).chat("gpt-4o"));
+ const googleClient = wrapAISDKModel(openai(c.env).chat("gpt-4o-mini-2024-07-18"));
// Get last user message and generate embedding in parallel with thread creation
let lastUserMessage = coreMessages.findLast((i) => i.role === "user");
@@ -170,8 +170,17 @@ const actions = new Hono<{ Variables: Variables; Bindings: Env }>()
try {
const data = new StreamData();
+ // De-duplicate chunks by URL to avoid showing duplicate content
+ const uniqueResults = finalResults.reduce((acc, current) => {
+ const existingResult = acc.find(item => item.id === current.id);
+ if (!existingResult) {
+ acc.push(current);
+ }
+ return acc;
+ }, [] as typeof finalResults);
+
data.appendMessageAnnotation(
- finalResults.map((r) => ({
+ uniqueResults.map((r) => ({
id: r.id,
content: r.content,
type: r.type,
@@ -414,7 +423,7 @@ const actions = new Hono<{ Variables: Variables; Bindings: Env }>()
.orderBy(sql`RANDOM()`)
.limit(7);
- if (recentLearnings.length === 0) {
+ if (recentLearnings.length === 0 || recentLearnings.length < 3) {
return c.json({ suggestedLearnings: [] });
}
@@ -425,7 +434,7 @@ const actions = new Hono<{ Variables: Variables; Bindings: Env }>()
const model = openai(c.env).chat("gpt-4o-mini-2024-07-18");
const prompt = `Generate a concise topic recall card for this document. The card should:
- Have a clear title that captures the main topic
- - Include a brief "Last week, you saved notes on..." intro (do something different every time.)
+ - based on when the document was saved, include a brief "Last (week/month/...), you saved notes on..." intro (do something different every time.)
- List 2-3 key points from the content in simple bullet points
- Keep the total length under 280 characters
- Focus on the core concepts worth remembering
diff --git a/apps/backend/src/routes/spaces.ts b/apps/backend/src/routes/spaces.ts
index aa9c905d..2ca2e461 100644
--- a/apps/backend/src/routes/spaces.ts
+++ b/apps/backend/src/routes/spaces.ts
@@ -118,6 +118,7 @@ const spacesRoute = new Hono<{ Variables: Variables; Bindings: Env }>()
canRead: true,
canEdit,
isOwner: space[0].ownerId === user?.id,
+ isPublic: space[0].isPublic,
},
});
}
@@ -156,6 +157,7 @@ const spacesRoute = new Hono<{ Variables: Variables; Bindings: Env }>()
canRead: true,
canEdit,
isOwner: space[0].ownerId === user.id,
+ isPublic: space[0].isPublic,
},
});
})
@@ -254,16 +256,8 @@ const spacesRoute = new Hono<{ Variables: Variables; Bindings: Env }>()
error instanceof Error &&
error.message.includes("saved_spaces_user_space_idx")
) {
- // Space is already favorited - remove it
- await db
- .delete(savedSpaces)
- .where(
- and(
- eq(savedSpaces.userId, user.id),
- eq(savedSpaces.spaceId, space[0].id)
- )
- );
- return c.json({ message: "Space unfavorited successfully" });
+ // Space is already favorited
+ return c.json({ message: "Space already favorited" });
}
throw error;
}
@@ -524,6 +518,28 @@ const spacesRoute = new Hono<{ Variables: Variables; Bindings: Env }>()
return c.json({ success: true });
}
- );
+ ).delete("/:spaceId", async (c) => {
+ const user = c.get("user");
+ if (!user) {
+ return c.json({ error: "Unauthorized" }, 401);
+ }
+
+ const { spaceId } = c.req.param();
+ const db = database(c.env.HYPERDRIVE.connectionString);
+
+ const space = await db
+ .select()
+ .from(spaces)
+ .where(eq(spaces.uuid, spaceId))
+ .limit(1);
+
+ if (space.length === 0) {
+ return c.json({ error: "Space not found" }, 404);
+ }
+
+ await db.delete(spaces).where(eq(spaces.uuid, spaceId));
+
+ return c.json({ success: true });
+ });
export default spacesRoute;