Skip to content

Commit f9f621c

Browse files
committed
chore: Update .gitignore and add .idea folder, update npm dependencies, and improve code logic for chat history and knowledge export/import
1 parent 677aa6e commit f9f621c

18 files changed

+449
-262
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ keys.json
4242

4343
# typescript
4444
.tsbuildinfo
45-
.wxt
45+
# WXT
46+
.wxt
47+
# WebStorm
48+
.idea

bun.lockb

472 Bytes
Binary file not shown.

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"description": "Use your locally running AI models to assist you in your web browsing.",
66
"author": "n4ze3m",
77
"scripts": {
8-
"dev": "wxt",
9-
"dev:firefox": "wxt -b firefox",
10-
"build": "wxt build",
11-
"build:firefox": "wxt build -b firefox",
12-
"zip": "wxt zip",
13-
"zip:firefox": "wxt zip -b firefox",
8+
"dev": "cross-env TARGET=chrome wxt",
9+
"dev:firefox": "cross-env TARGET=firefox wxt -b firefox",
10+
"build": "cross-env TARGET=chrome wxt build",
11+
"build:firefox": "cross-env TARGET=chrome cross-env TARGET=firefox wxt build -b firefox",
12+
"zip": "cross-env TARGET=chrome wxt zip",
13+
"zip:firefox": "cross-env TARGET=firefox wxt zip -b firefox",
1414
"compile": "tsc --noEmit",
1515
"postinstall": "wxt prepare"
1616
},
@@ -66,6 +66,7 @@
6666
"@types/react-syntax-highlighter": "^15.5.11",
6767
"@types/turndown": "^5.0.4",
6868
"autoprefixer": "^10.4.17",
69+
"cross-env": "^7.0.3",
6970
"postcss": "^8.4.33",
7071
"prettier": "3.2.4",
7172
"tailwindcss": "^3.4.1",

page-share.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Click the button below to deploy the code to Railway.
2323

2424
```bash
2525
git clone https://github.com/n4ze3m/page-share-app.git
26-
cd page-assist-app
26+
cd page-share-app
2727
```
2828

2929
2. Run the server

src/components/Option/Models/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const ModelsBody = () => {
6060

6161
form.reset()
6262

63-
chrome.runtime.sendMessage({
63+
browser.runtime.sendMessage({
6464
type: "pull_model",
6565
modelName
6666
})

src/components/Option/Settings/about.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const AboutApp = () => {
1111
const { data, status } = useQuery({
1212
queryKey: ["fetchOllamURL"],
1313
queryFn: async () => {
14-
const chromeVersion = chrome.runtime.getManifest().version
14+
const chromeVersion = browser.runtime.getManifest().version
1515
try {
1616
const url = await getOllamaURL()
1717
const req = await fetch(`${cleanUrl(url)}/api/version`)

src/db/index.ts

+27-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type ChatHistory as ChatHistoryType,
33
type Message as MessageType
44
} from "~/store/option"
5+
import { Storage, browser } from "wxt/browser"
56

67
type HistoryInfo = {
78
id: string
@@ -57,23 +58,29 @@ type ChatHistory = HistoryInfo[]
5758
type Prompts = Prompt[]
5859

5960
export class PageAssitDatabase {
60-
db: chrome.storage.StorageArea
61+
db: Storage.LocalStorageArea
6162

6263
constructor() {
63-
this.db = chrome.storage.local
64+
this.db = browser.storage.local
6465
}
6566

6667
async getChatHistory(id: string): Promise<MessageHistory> {
6768
return new Promise((resolve, reject) => {
68-
this.db.get(id, (result) => {
69+
// this.db.get(id, (result) => {
70+
// resolve(result[id] || [])
71+
// })
72+
this.db.get(id).then((result) => {
6973
resolve(result[id] || [])
7074
})
7175
})
7276
}
7377

7478
async getChatHistories(): Promise<ChatHistory> {
7579
return new Promise((resolve, reject) => {
76-
this.db.get("chatHistories", (result) => {
80+
// this.db.get("chatHistories", (result) => {
81+
// resolve(result.chatHistories || [])
82+
// })
83+
this.db.get("chatHistories").then((result) => {
7784
resolve(result.chatHistories || [])
7885
})
7986
})
@@ -126,7 +133,10 @@ export class PageAssitDatabase {
126133

127134
async getAllPrompts(): Promise<Prompts> {
128135
return new Promise((resolve, reject) => {
129-
this.db.get("prompts", (result) => {
136+
// this.db.get("prompts", (result) => {
137+
// resolve(result.prompts || [])
138+
// })
139+
this.db.get("prompts").then((result) => {
130140
resolve(result.prompts || [])
131141
})
132142
})
@@ -169,15 +179,21 @@ export class PageAssitDatabase {
169179

170180
async getWebshare(id: string) {
171181
return new Promise((resolve, reject) => {
172-
this.db.get(id, (result) => {
182+
// this.db.get(id, (result) => {
183+
// resolve(result[id] || [])
184+
// })
185+
this.db.get(id).then((result) => {
173186
resolve(result[id] || [])
174187
})
175188
})
176189
}
177190

178191
async getAllWebshares(): Promise<Webshare[]> {
179192
return new Promise((resolve, reject) => {
180-
this.db.get("webshares", (result) => {
193+
// this.db.get("webshares", (result) => {
194+
// resolve(result.webshares || [])
195+
// })
196+
this.db.get("webshares").then((result) => {
181197
resolve(result.webshares || [])
182198
})
183199
})
@@ -197,7 +213,10 @@ export class PageAssitDatabase {
197213

198214
async getUserID() {
199215
return new Promise((resolve, reject) => {
200-
this.db.get("user_id", (result) => {
216+
// this.db.get("user_id", (result) => {
217+
// resolve(result.user_id || "")
218+
// })
219+
this.db.get("user_id").then((result) => {
201220
resolve(result.user_id || "")
202221
})
203222
})

src/db/knowledge.ts

+65-48
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Storage, browser } from "wxt/browser"
12
import { deleteVector, deleteVectorByFileId } from "./vector"
23

34
export type Source = {
@@ -24,89 +25,105 @@ export const generateID = () => {
2425
})
2526
}
2627
export class PageAssistKnowledge {
27-
db: chrome.storage.StorageArea
28+
db: Storage.LocalStorageArea
2829

2930
constructor() {
30-
this.db = chrome.storage.local
31+
this.db = browser.storage.local
3132
}
3233

3334
getAll = async (): Promise<Knowledge[]> => {
3435
return new Promise((resolve, reject) => {
35-
this.db.get(null, (result) => {
36-
if (chrome.runtime.lastError) {
37-
reject(chrome.runtime.lastError)
38-
} else {
39-
const data = Object.keys(result).map((key) => result[key])
40-
resolve(data)
41-
}
36+
// this.db.get(null, (result) => {
37+
// if (chrome.runtime.lastError) {
38+
// reject(chrome.runtime.lastError)
39+
// } else {
40+
// const data = Object.keys(result).map((key) => result[key])
41+
// resolve(data)
42+
// }
43+
// })
44+
this.db.get(null).then((result) => {
45+
const data = Object.keys(result).map((key) => result[key])
46+
resolve(data)
4247
})
4348
})
4449
}
4550

4651
getById = async (id: string): Promise<Knowledge> => {
4752
return new Promise((resolve, reject) => {
48-
this.db.get(id, (result) => {
49-
if (chrome.runtime.lastError) {
50-
reject(chrome.runtime.lastError)
51-
} else {
52-
resolve(result[id])
53-
}
53+
this.db.get(id).then((result) => {
54+
resolve(result[id])
5455
})
5556
})
57+
5658
}
57-
5859
create = async (knowledge: Knowledge): Promise<void> => {
5960
return new Promise((resolve, reject) => {
60-
this.db.set({ [knowledge.id]: knowledge }, () => {
61-
if (chrome.runtime.lastError) {
62-
reject(chrome.runtime.lastError)
63-
} else {
64-
resolve()
65-
}
61+
// this.db.set({ [knowledge.id]: knowledge }, () => {
62+
// if (chrome.runtime.lastError) {
63+
// reject(chrome.runtime.lastError)
64+
// } else {
65+
// resolve()
66+
// }
67+
// })
68+
this.db.set({ [knowledge.id]: knowledge }).then(() => {
69+
resolve()
6670
})
6771
})
6872
}
6973

7074
update = async (knowledge: Knowledge): Promise<void> => {
7175
return new Promise((resolve, reject) => {
72-
this.db.set({ [knowledge.id]: knowledge }, () => {
73-
if (chrome.runtime.lastError) {
74-
reject(chrome.runtime.lastError)
75-
} else {
76-
resolve()
77-
}
76+
// this.db.set({ [knowledge.id]: knowledge }, () => {
77+
// if (chrome.runtime.lastError) {
78+
// reject(chrome.runtime.lastError)
79+
// } else {
80+
// resolve()
81+
// }
82+
// })
83+
this.db.set({ [knowledge.id]: knowledge }).then(() => {
84+
resolve()
7885
})
7986
})
8087
}
8188

8289
delete = async (id: string): Promise<void> => {
8390
return new Promise((resolve, reject) => {
84-
this.db.remove(id, () => {
85-
if (chrome.runtime.lastError) {
86-
reject(chrome.runtime.lastError)
87-
} else {
88-
resolve()
89-
}
91+
// this.db.remove(id, () => {
92+
// if (chrome.runtime.lastError) {
93+
// reject(chrome.runtime.lastError)
94+
// } else {
95+
// resolve()
96+
// }
97+
// })
98+
this.db.remove(id).then(() => {
99+
resolve()
90100
})
91101
})
92102
}
93103

94104
deleteSource = async (id: string, source_id: string): Promise<void> => {
95105
return new Promise((resolve, reject) => {
96-
this.db.get(id, (result) => {
97-
if (chrome.runtime.lastError) {
98-
reject(chrome.runtime.lastError)
99-
} else {
100-
const data = result[id] as Knowledge
101-
data.source = data.source.filter((s) => s.source_id !== source_id)
102-
this.db.set({ [id]: data }, () => {
103-
if (chrome.runtime.lastError) {
104-
reject(chrome.runtime.lastError)
105-
} else {
106-
resolve()
107-
}
108-
})
109-
}
106+
// this.db.get(id, (result) => {
107+
// if (chrome.runtime.lastError) {
108+
// reject(chrome.runtime.lastError)
109+
// } else {
110+
// const data = result[id] as Knowledge
111+
// data.source = data.source.filter((s) => s.source_id !== source_id)
112+
// this.db.set({ [id]: data }, () => {
113+
// if (chrome.runtime.lastError) {
114+
// reject(chrome.runtime.lastError)
115+
// } else {
116+
// resolve()
117+
// }
118+
// })
119+
// }
120+
// })
121+
this.db.get(id).then((result) => {
122+
const data = result[id] as Knowledge
123+
data.source = data.source.filter((s) => s.source_id !== source_id)
124+
this.db.set({ [id]: data }).then(() => {
125+
resolve()
126+
})
110127
})
111128
})
112129
}

0 commit comments

Comments
 (0)