feat: Add export/import functions for chat history, promt and knowledge

This commit is contained in:
n4ze3m
2024-05-08 13:42:59 +05:30
parent 11147fd951
commit 677aa6ef51
11 changed files with 159 additions and 22 deletions

View File

@@ -444,3 +444,15 @@ export const importChatHistory = async (
}
}
}
export const exportPrompts = async () => {
const db = new PageAssitDatabase()
return await db.getAllPrompts()
}
export const importPrompts = async (prompts: Prompts) => {
const db = new PageAssitDatabase()
for (const prompt of prompts) {
await db.addPrompt(prompt)
}
}

View File

@@ -112,6 +112,22 @@ export class PageAssistVectorDb {
})
})
}
saveImportedData = async (data: VectorData[]): Promise<void> => {
return new Promise((resolve, reject) => {
const obj: Record<string, VectorData> = {}
data.forEach((d) => {
obj[d.id] = d
})
this.db.set(obj, () => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError)
} else {
resolve()
}
})
})
}
}
export const insertVector = async (
@@ -148,7 +164,5 @@ export const exportVectors = async () => {
export const importVectors = async (data: VectorData[]) => {
const db = new PageAssistVectorDb()
for (const d of data) {
await db.insertVector(d.id, d.vectors)
}
return db.saveImportedData(data)
}