mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-07 08:26:15 +00:00
revert some files
This commit is contained in:
parent
f5a6057adf
commit
d936216070
3 changed files with 110 additions and 109 deletions
|
|
@ -1,4 +1,4 @@
|
|||
name = "supermemory-backend"
|
||||
name = "new-cf-ai-backend"
|
||||
main = "src/index.ts"
|
||||
compatibility_date = "2024-02-23"
|
||||
node_compat = true
|
||||
|
|
@ -6,7 +6,8 @@ node_compat = true
|
|||
# [env.preview]
|
||||
[[vectorize]]
|
||||
binding = "VECTORIZE_INDEX"
|
||||
index_name = "supermemory-prod"
|
||||
index_name = "supermem-vector-dev"
|
||||
|
||||
# [[vectorize]]
|
||||
# binding = "VECTORIZE_INDEX"
|
||||
# index_name = "supermem-vector-prod"
|
||||
|
|
@ -23,8 +24,8 @@ binding = "AI"
|
|||
|
||||
[[kv_namespaces]]
|
||||
binding = "KV"
|
||||
id = "c76af0a8cd2047bd80db77cd160f2b6d"
|
||||
preview_id = "667225a5df924e68b26194cf49c75101"
|
||||
id = "37a90353da63401e84e20e71165531d0"
|
||||
preview_id = "c58b6202814f4224acea97627d0c18aa"
|
||||
|
||||
[placement]
|
||||
mode = "smart"
|
||||
|
|
|
|||
|
|
@ -1,113 +1,113 @@
|
|||
// import { db } from "@/server/db";
|
||||
// import { storedContent, users } from "@/server/db/schema";
|
||||
// import { cipher } from "@/server/encrypt";
|
||||
// import { eq } from "drizzle-orm";
|
||||
// import { Bot, webhookCallback } from "grammy";
|
||||
// import { type User } from "grammy/types";
|
||||
import { db } from "@/server/db";
|
||||
import { storedContent, users } from "@/server/db/schema";
|
||||
import { cipher } from "@/server/encrypt";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { Bot, webhookCallback } from "grammy";
|
||||
import { User } from "grammy/types";
|
||||
|
||||
// export const runtime = "edge";
|
||||
export const runtime = "edge";
|
||||
|
||||
// if (!process.env.TELEGRAM_BOT_TOKEN) {
|
||||
// throw new Error("TELEGRAM_BOT_TOKEN is not defined");
|
||||
// }
|
||||
if (!process.env.TELEGRAM_BOT_TOKEN) {
|
||||
throw new Error("TELEGRAM_BOT_TOKEN is not defined");
|
||||
}
|
||||
|
||||
// console.log("Telegram bot activated");
|
||||
// const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||
console.log("Telegram bot activated");
|
||||
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||
|
||||
// const bot = new Bot(token);
|
||||
const bot = new Bot(token);
|
||||
|
||||
// bot.command("start", async (ctx) => {
|
||||
// const user: User = (await ctx.getAuthor()).user;
|
||||
bot.command("start", async (ctx) => {
|
||||
const user: User = (await ctx.getAuthor()).user;
|
||||
|
||||
// const cipherd = cipher(user.id.toString());
|
||||
// await ctx.reply(
|
||||
// `Welcome to Supermemory bot. I am here to help you remember things better. Click here to create and link your account: https://supermemory.ai/signin?telegramUser=${cipherd}`,
|
||||
// );
|
||||
// });
|
||||
const cipherd = cipher(user.id.toString());
|
||||
await ctx.reply(
|
||||
`Welcome to Supermemory bot. I am here to help you remember things better. Click here to create and link your account: https://supermemory.ai/signin?telegramUser=${cipherd}`,
|
||||
);
|
||||
});
|
||||
|
||||
// bot.on("message", async (ctx) => {
|
||||
// const user: User = (await ctx.getAuthor()).user;
|
||||
bot.on("message", async (ctx) => {
|
||||
const user: User = (await ctx.getAuthor()).user;
|
||||
|
||||
// const cipherd = cipher(user.id.toString());
|
||||
const cipherd = cipher(user.id.toString());
|
||||
|
||||
// const dbUser = await db.query.users
|
||||
// .findFirst({
|
||||
// where: eq(users.telegramId, user.id.toString()),
|
||||
// })
|
||||
// .execute();
|
||||
const dbUser = await db.query.users
|
||||
.findFirst({
|
||||
where: eq(users.telegramId, user.id.toString()),
|
||||
})
|
||||
.execute();
|
||||
|
||||
// if (!dbUser) {
|
||||
// await ctx.reply(
|
||||
// `Welcome to Supermemory bot. I am here to help you remember things better. Click here to create and link your account: https://supermemory.ai/signin?telegramUser=${cipherd}`,
|
||||
// );
|
||||
if (!dbUser) {
|
||||
await ctx.reply(
|
||||
`Welcome to Supermemory bot. I am here to help you remember things better. Click here to create and link your account: https://supermemory.ai/signin?telegramUser=${cipherd}`,
|
||||
);
|
||||
|
||||
// return;
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
// const message = await ctx.reply("I'm thinking...");
|
||||
const message = await ctx.reply("I'm thinking...");
|
||||
|
||||
// const response = await fetch(
|
||||
// `${process.env.BACKEND_BASE_URL}/api/autoChatOrAdd?query=${ctx.message.text}&user=${dbUser.id}`,
|
||||
// {
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY,
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// body: JSON.stringify({
|
||||
// // TODO: we can use the conversations API to get the last 5 messages
|
||||
// // get chatHistory from this conversation.
|
||||
// // Basically the last 5 messages between the user and the assistant.
|
||||
// // In ths form of [{role: 'user' | 'assistant', content: string}]
|
||||
// // https://grammy.dev/plugins/conversations
|
||||
// chatHistory: [],
|
||||
// }),
|
||||
// },
|
||||
// );
|
||||
const response = await fetch(
|
||||
`${process.env.BACKEND_BASE_URL}/api/autoChatOrAdd?query=${ctx.message.text}&user=${dbUser.id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: "Bearer " + process.env.BACKEND_SECURITY_KEY,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
// TODO: we can use the conversations API to get the last 5 messages
|
||||
// get chatHistory from this conversation.
|
||||
// Basically the last 5 messages between the user and the assistant.
|
||||
// In ths form of [{role: 'user' | 'assistant', content: string}]
|
||||
// https://grammy.dev/plugins/conversations
|
||||
chatHistory: [],
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
// if (response.status !== 200) {
|
||||
// console.log("Failed to get response from backend");
|
||||
// console.log(response.status);
|
||||
// console.log(await response.text());
|
||||
// await ctx.reply(
|
||||
// "Sorry, I am not able to process your request at the moment.",
|
||||
// );
|
||||
// return;
|
||||
// }
|
||||
if (response.status !== 200) {
|
||||
console.log("Failed to get response from backend");
|
||||
console.log(response.status);
|
||||
console.log(await response.text());
|
||||
await ctx.reply(
|
||||
"Sorry, I am not able to process your request at the moment.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// const data = (await response.json()) as {
|
||||
// status: string;
|
||||
// response: string;
|
||||
// contentAdded: {
|
||||
// type: string;
|
||||
// content: string;
|
||||
// url: string;
|
||||
// };
|
||||
// };
|
||||
const data = (await response.json()) as {
|
||||
status: string;
|
||||
response: string;
|
||||
contentAdded: {
|
||||
type: string;
|
||||
content: string;
|
||||
url: string;
|
||||
};
|
||||
};
|
||||
|
||||
// // TODO: we might want to enrich this data with more information
|
||||
// if (data.contentAdded) {
|
||||
// await db
|
||||
// .insert(storedContent)
|
||||
// .values({
|
||||
// content: data.contentAdded.content,
|
||||
// title: `${data.contentAdded.content.slice(0, 30)}... (Added from chatbot)`,
|
||||
// description: "",
|
||||
// url: data.contentAdded.url,
|
||||
// baseUrl: data.contentAdded.url,
|
||||
// image: "",
|
||||
// savedAt: new Date(),
|
||||
// userId: dbUser.id,
|
||||
// type: data.contentAdded.type,
|
||||
// })
|
||||
// .returning({ id: storedContent.id });
|
||||
// }
|
||||
// TODO: we might want to enrich this data with more information
|
||||
if (data.contentAdded) {
|
||||
await db
|
||||
.insert(storedContent)
|
||||
.values({
|
||||
content: data.contentAdded.content,
|
||||
title: `${data.contentAdded.content.slice(0, 30)}... (Added from chatbot)`,
|
||||
description: "",
|
||||
url: data.contentAdded.url,
|
||||
baseUrl: data.contentAdded.url,
|
||||
image: "",
|
||||
savedAt: new Date(),
|
||||
userId: dbUser.id,
|
||||
type: data.contentAdded.type,
|
||||
})
|
||||
.returning({ id: storedContent.id });
|
||||
}
|
||||
|
||||
// await ctx.api.editMessageText(ctx.chat.id, message.message_id, data.response);
|
||||
// });
|
||||
await ctx.api.editMessageText(ctx.chat.id, message.message_id, data.response);
|
||||
});
|
||||
|
||||
// export const POST = webhookCallback(bot, "std/http");
|
||||
export const POST = webhookCallback(bot, "std/http");
|
||||
|
||||
// export const GET = async () => {
|
||||
// return new Response("OK", { status: 200 });
|
||||
// };
|
||||
export const GET = async () => {
|
||||
return new Response("OK", { status: 200 });
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ pages_build_output_dir = ".vercel/output/static"
|
|||
|
||||
|
||||
kv_namespaces = [
|
||||
{ binding = "CANVAS_SNAPS", id = "f663564d9a4e4ebc904a5fb4301ab6a6" },
|
||||
{ binding = "RECOMMENDATIONS", id = "bf3f293fb589406e961dfd91e43c48bd" }
|
||||
{ binding = "CANVAS_SNAPS", id = "6df98c892b3744ccb0c631d9f60d6697" },
|
||||
{ binding = "RECOMMENDATIONS", id = "83bc7055226c4657948141c2ff9a5425" }
|
||||
]
|
||||
|
||||
env.production.kv_namespaces = [
|
||||
{ binding = "CANVAS_SNAPS", id = "f663564d9a4e4ebc904a5fb4301ab6a6" },
|
||||
{ binding = "RECOMMENDATIONS", id = "bf3f293fb589406e961dfd91e43c48bd" }
|
||||
{ binding = "CANVAS_SNAPS", id = "6df98c892b3744ccb0c631d9f60d6697" },
|
||||
{ binding = "RECOMMENDATIONS", id = "83bc7055226c4657948141c2ff9a5425" }
|
||||
]
|
||||
|
||||
[ai]
|
||||
|
|
@ -22,26 +22,26 @@ mode = "smart"
|
|||
|
||||
[[r2_buckets]]
|
||||
binding = "STORAGE"
|
||||
bucket_name = "supermemory-r2-preview"
|
||||
bucket_name = "dev-r2-anycontext"
|
||||
|
||||
[[d1_databases]]
|
||||
binding = "DATABASE"
|
||||
database_name = "supermemory-db-preview"
|
||||
database_id = "5e11c666-eece-4ef5-8d35-5b20636f7ce7"
|
||||
database_name = "dev-d1-anycontext"
|
||||
database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c"
|
||||
|
||||
|
||||
[[env.production.d1_databases]]
|
||||
binding = "DATABASE"
|
||||
database_name = "supermemory-db-prod"
|
||||
database_id = "2531ff71-861b-4815-bde8-aa0a36b9ed09"
|
||||
database_name = "prod-d1-supermemory"
|
||||
database_id = "f527a727-c472-41d4-8eaf-3d7ba0f2f395"
|
||||
|
||||
[env.preview.ai]
|
||||
binding = "AI"
|
||||
|
||||
[[env.preview.d1_databases]]
|
||||
binding = "DATABASE"
|
||||
database_name = "supermemory-db-preview"
|
||||
database_id = "5e11c666-eece-4ef5-8d35-5b20636f7ce7"
|
||||
database_name = "dev-d1-anycontext"
|
||||
database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c"
|
||||
|
||||
[env.production.ai]
|
||||
binding = "AI"
|
||||
Loading…
Add table
Reference in a new issue