feat: Add support for sending notification after knowledge base processing
This commit is contained in:
@@ -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")
|
||||
|
||||
27
src/libs/send-notification.ts
Normal file
27
src/libs/send-notification.ts
Normal 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."
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user