feat: Add support for sending notification after knowledge base processing

This commit is contained in:
n4ze3m
2024-07-16 00:37:50 +05:30
parent f5f0157260
commit 9c8584f1c4
14 changed files with 383 additions and 307 deletions

View File

@@ -12,6 +12,7 @@ import { PageAssisCSVUrlLoader } from "@/loader/csv"
import { PageAssisTXTUrlLoader } from "@/loader/txt"
import { PageAssistDocxLoader } from "@/loader/docx"
import { cleanUrl } from "./clean-url"
import { sendEmbeddingCompleteNotification } from "./send-notification"
export const processKnowledge = async (msg: any, id: string): Promise<void> => {
@@ -102,6 +103,8 @@ export const processKnowledge = async (msg: any, id: string): Promise<void> => {
}
await updateKnowledgeStatus(id, "finished")
await sendEmbeddingCompleteNotification()
} catch (error) {
console.error(`Error processing knowledge with id: ${id}`, error)
await updateKnowledgeStatus(id, "failed")

View File

@@ -0,0 +1,27 @@
import { Storage } from "@plasmohq/storage"
const storage = new Storage()
export const sendNotification = async (title: string, message: string) => {
try {
const sendNotificationAfterIndexing = await storage.get<boolean>(
"sendNotificationAfterIndexing"
)
if (sendNotificationAfterIndexing) {
browser.notifications.create({
type: "basic",
iconUrl: browser.runtime.getURL("/icon.png"),
title,
message
})
}
} catch (error) {
console.error(error)
}
}
export const sendEmbeddingCompleteNotification = async () => {
await sendNotification(
"Page Assist - Embedding Completed",
"The knowledge base embedding process is complete. You can now use the knowledge base for chatting."
)
}