aboutsummaryrefslogtreecommitdiff
path: root/apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2024-08-06 11:20:29 -0700
committerGitHub <[email protected]>2024-08-06 11:20:29 -0700
commit7fc39cd770e4b2f55c6fdae1fa02fe0a66a93f6d (patch)
tree82e6a03099b50441c2fe9a9bf8e8ddf7afa293e5 /apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts
parentMerge pull request #219 from Deepakchowdavarapu/readme-issue (diff)
parentupdated kv and queues (diff)
downloadsupermemory-7fc39cd770e4b2f55c6fdae1fa02fe0a66a93f6d.tar.xz
supermemory-7fc39cd770e4b2f55c6fdae1fa02fe0a66a93f6d.zip
Merge pull request #193 from supermemoryai/kush/be-queue
Kush/be queue
Diffstat (limited to 'apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts')
-rw-r--r--apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts b/apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts
new file mode 100644
index 00000000..466690cc
--- /dev/null
+++ b/apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts
@@ -0,0 +1,36 @@
+import { Result, Ok, Err } from "../../errors/results";
+import { BaseError } from "../../errors/baseError";
+import { Metadata } from "../utils/get-metadata";
+
+class ProcessNotesError extends BaseError {
+ constructor(message?: string, source?: string) {
+ super("[Note Processing Error]", message, source);
+ }
+}
+
+type ProcessNoteResult = {
+ noteContent: { noteId: number; noteContent: string };
+ metadata: Metadata;
+};
+
+export function processNote(
+ content: string,
+): Result<ProcessNoteResult, ProcessNotesError> {
+ try {
+ const pageContent = content;
+ const noteId = new Date().getTime();
+
+ const metadata = {
+ baseUrl: `https://supermemory.ai/note/${noteId}`,
+ description: `Note created at ${new Date().toLocaleString()}`,
+ image: "https://supermemory.ai/logo.png",
+ title: `${pageContent.slice(0, 20)} ${pageContent.length > 20 ? "..." : ""}`,
+ };
+
+ const noteContent = { noteId: noteId, noteContent: pageContent };
+ return Ok({ noteContent, metadata });
+ } catch (e) {
+ console.error("[Note Processing Error]", e);
+ return Err(new ProcessNotesError((e as Error).message, "processNote"));
+ }
+}