Skip to content

Commit

Permalink
Improve window.ai typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas101 committed Nov 13, 2024
1 parent 963d716 commit 7543c27
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@babel/preset-env": "^7.26.0",
"@stylistic/eslint-plugin": "^2.10.1",
"@types/chrome": "^0.0.280",
"@types/dom-chromium-ai": "^0.0.2",
"@types/fs-extra": "^11.0.4",
"@types/node": "^22.9.0",
"@types/object-path": "^0.11.4",
Expand Down
4 changes: 2 additions & 2 deletions src/extension/contentscript-main/AI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AI extends EventTarget {
// MARK: Private
/* **************************************************************************/

#browserAI: any
#browserAI: globalThis.AI | undefined
#summarizer: AISummarizerFactory
#writer: AIWriterFactory
#rewriter: AIRewriterFactory
Expand All @@ -30,7 +30,7 @@ class AI extends EventTarget {
// MARK: Lifecycle
/* **************************************************************************/

constructor (browserAI: any) {
constructor (browserAI: globalThis.AI | undefined) {
super()

this.#browserAI = browserAI
Expand Down
7 changes: 3 additions & 4 deletions src/extension/contentscript-main/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import AI from './AI'

const genericWindow = window as any
const browserAI = genericWindow.ai
const ai = new AI(browserAI)
const ai = new AI(window.ai)

if (process.env.BROWSER !== 'extlib') {
if (!genericWindow.ai) {
const genericWindow = window as any
if (!window.ai) {
genericWindow.ai = ai
}
genericWindow.aibrow = ai
Expand Down
5 changes: 3 additions & 2 deletions src/extension/ui-options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ async function renderSettings () {
const defaultModelList = [
...new Set([defaultModelId, Object.values(config.defaultModels)])
].map((modelId) => ({ id: modelId, name: modelId }))
renderDefaultModelOptions($defaultTextModelOpt, defaultModelId, defaultModelList, Boolean((window as any).ai?.assistant), useBrowserAI)

renderDefaultModelOptions($defaultTextModelOpt, defaultModelId, defaultModelList, Boolean(window.ai?.languageModel), useBrowserAI)

const res = await fetch('https://aibrow.ai/api/model/list.json')
if (res.ok) {
const { models } = await res.json()
renderDefaultModelOptions($defaultTextModelOpt, defaultModelId, models, Boolean((window as any).ai?.assistant), useBrowserAI)
renderDefaultModelOptions($defaultTextModelOpt, defaultModelId, models, Boolean(window.ai?.languageModel), useBrowserAI)
}
})()

Expand Down

0 comments on commit 7543c27

Please sign in to comment.