diff --git a/src/extension/background/APIHandler/APIHandler.ts b/src/extension/background/APIHandler/APIHandler.ts index 71402ce..f17a102 100644 --- a/src/extension/background/APIHandler/APIHandler.ts +++ b/src/extension/background/APIHandler/APIHandler.ts @@ -7,8 +7,6 @@ import AICoreModelHandler from './AICoreModelHandler' import AIEmbeddingHandler from './AIEmbeddingHandler' import AILanguageDetectorHandler from './AILanguageDetectorHandler' import AITranslatorHandler from './AITranslatorHandler' -import { kPrefGetUseBrowserAI } from '#Shared/API/PrefIPCMessageTypes' -import { getUseBrowserAI } from '#Shared/Prefs' import { kAIGetCapabilities, kAIGetNativeHelperDownloadUrl } from '#Shared/API/AIIPCTypes' import System from '../System' import { AICapabilities, AIHelperInstalledState } from '#Shared/API/AI' @@ -48,19 +46,10 @@ class APIHandler { this.#translatorHandler = new AITranslatorHandler(this.#server) this.#server - .addRequestHandler(kPrefGetUseBrowserAI, this.#handleGetUseBrowserAI) .addRequestHandler(kAIGetCapabilities, this.#handleGetCapabilities) .addRequestHandler(kAIGetNativeHelperDownloadUrl, this.#handleGetNativeHelperDownloadUrl) } - /* **************************************************************************/ - // MARK: Handlers: Prefs - /* **************************************************************************/ - - #handleGetUseBrowserAI = async () => { - return await getUseBrowserAI() - } - /* **************************************************************************/ // MARK: Handlers: Capabilities /* **************************************************************************/ diff --git a/src/extension/contentscript-main/AILanguageModel/AILanguageModelFactory.ts b/src/extension/contentscript-main/AILanguageModel/AILanguageModelFactory.ts index aeb11c1..2dd6619 100644 --- a/src/extension/contentscript-main/AILanguageModel/AILanguageModelFactory.ts +++ b/src/extension/contentscript-main/AILanguageModel/AILanguageModelFactory.ts @@ -8,7 +8,6 @@ import { kLanguageModelGetCapabilities, kLanguageModelCreate } from '#Shared/API/AILanguageModel/AILanguageModelIPCTypes' -import Prefs from '../Prefs' import IPC from '../IPC' import { throwIPCErrorResponse } from '#Shared/IPC/IPCErrorHelper' import AILanguageModelCapabilities from './AILanguageModelCapabilities' @@ -31,26 +30,11 @@ class AILanguageModelFactory { this.#browserAI = browserAI } - /* **************************************************************************/ - // MARK: Utils - /* **************************************************************************/ - - /** - * @returns true if we should be using the browsers built-in ai for this factory - */ - async #shouldUseBrowserAI () { - return typeof (this.#browserAI?.languageModel) === 'object' && await Prefs.getUseBrowserAI() - } - /* **************************************************************************/ // MARK: Capabilities /* **************************************************************************/ capabilities = async (options: AILanguageModelCapabilitiesOptions = {}): Promise => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.languageModel.capabilities(options) - } - const data = throwIPCErrorResponse( await IPC.request(kLanguageModelGetCapabilities, options) ) as AILanguageModelCapabilitiesData @@ -63,10 +47,6 @@ class AILanguageModelFactory { /* **************************************************************************/ create = async (options: AILanguageModelCreateOptions = {}) => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.languageModel.create(options) - } - const monitorTarget = new EventTarget() const { monitor, diff --git a/src/extension/contentscript-main/AIRewriter/AIRewriterFactory.ts b/src/extension/contentscript-main/AIRewriter/AIRewriterFactory.ts index 64363d1..79be35f 100644 --- a/src/extension/contentscript-main/AIRewriter/AIRewriterFactory.ts +++ b/src/extension/contentscript-main/AIRewriter/AIRewriterFactory.ts @@ -6,7 +6,6 @@ import { AIRewriterData } from '#Shared/API/AIRewriter/AIRewriterTypes' import AIRewriterCapabilities from './AIRewriterCapabilities' -import Prefs from '../Prefs' import IPC from '../IPC' import { throwIPCErrorResponse } from '#Shared/IPC/IPCErrorHelper' import { @@ -31,26 +30,11 @@ class AIRewriterFactory { this.#browserAI = browserAI } - /* **************************************************************************/ - // MARK: Utils - /* **************************************************************************/ - - /** - * @returns true if we should be using the browsers built-in ai for this factory - */ - async #shouldUseBrowserAI () { - return typeof (this.#browserAI?.rewriter) === 'object' && await Prefs.getUseBrowserAI() - } - /* **************************************************************************/ // MARK: Capabilities /* **************************************************************************/ capabilities = async (options: AIRewriterCapabilitiesOptions): Promise => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.rewriter.capabilities(options) - } - const data = throwIPCErrorResponse( await IPC.request(kRewriterGetCapabilities, options) ) as AIRewriterCapabilitiesData @@ -63,10 +47,6 @@ class AIRewriterFactory { /* **************************************************************************/ create = async (options: AIRewriterCreateOptions = {}) => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.rewriter.create(options) - } - const monitorTarget = new EventTarget() const { monitor, diff --git a/src/extension/contentscript-main/AISummarizer/AISummarizerFactory.ts b/src/extension/contentscript-main/AISummarizer/AISummarizerFactory.ts index 1a5cc2a..fec183e 100644 --- a/src/extension/contentscript-main/AISummarizer/AISummarizerFactory.ts +++ b/src/extension/contentscript-main/AISummarizer/AISummarizerFactory.ts @@ -6,7 +6,6 @@ import { AISummarizerData } from '#Shared/API/AISummarizer/AISummarizerTypes' import AISummarizerCapabilities from './AISummarizerCapabilities' -import Prefs from '../Prefs' import IPC from '../IPC' import { throwIPCErrorResponse } from '#Shared/IPC/IPCErrorHelper' import { @@ -31,26 +30,11 @@ class AISummarizerFactory { this.#browserAI = browserAI } - /* **************************************************************************/ - // MARK: Utils - /* **************************************************************************/ - - /** - * @returns true if we should be using the browsers built-in ai for this factory - */ - async #shouldUseBrowserAI () { - return typeof (this.#browserAI?.summarizer) === 'object' && await Prefs.getUseBrowserAI() - } - /* **************************************************************************/ // MARK: Capabilities /* **************************************************************************/ capabilities = async (options: AISummarizerCapabilitiesOptions): Promise => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.summarizer.capabilities(options) - } - const data = throwIPCErrorResponse( await IPC.request(kSummarizerGetCapabilities, options) ) as AISummarizerCapabilitiesData @@ -63,10 +47,6 @@ class AISummarizerFactory { /* **************************************************************************/ create = async (options: AISummarizerCreateOptions = {}) => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.summarizer.create(options) - } - const monitorTarget = new EventTarget() const { monitor, diff --git a/src/extension/contentscript-main/AIWriter/AIWriterFactory.ts b/src/extension/contentscript-main/AIWriter/AIWriterFactory.ts index 0139cd5..c7487eb 100644 --- a/src/extension/contentscript-main/AIWriter/AIWriterFactory.ts +++ b/src/extension/contentscript-main/AIWriter/AIWriterFactory.ts @@ -6,7 +6,6 @@ import { AIWriterData } from '#Shared/API/AIWriter/AIWriterTypes' import AIWriterCapabilities from './AIWriterCapabilities' -import Prefs from '../Prefs' import IPC from '../IPC' import { throwIPCErrorResponse } from '#Shared/IPC/IPCErrorHelper' import { @@ -31,26 +30,11 @@ class AIWriterFactory { this.#browserAI = browserAI } - /* **************************************************************************/ - // MARK: Utils - /* **************************************************************************/ - - /** - * @returns true if we should be using the browsers built-in ai for this factory - */ - async #shouldUseBrowserAI () { - return typeof (this.#browserAI?.writer) === 'object' && await Prefs.getUseBrowserAI() - } - /* **************************************************************************/ // MARK: Capabilities /* **************************************************************************/ capabilities = async (options: AIWriterCapabilitiesOptions): Promise => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.writer.capabilities(options) - } - const data = throwIPCErrorResponse( await IPC.request(kWriterGetCapabilities, options) ) as AIWriterCapabilitiesData @@ -63,10 +47,6 @@ class AIWriterFactory { /* **************************************************************************/ create = async (options: AIWriterCreateOptions = {}) => { - if (await this.#shouldUseBrowserAI()) { - return this.#browserAI.writer.create(options) - } - const monitorTarget = new EventTarget() const { monitor, diff --git a/src/extension/contentscript-main/Prefs.ts b/src/extension/contentscript-main/Prefs.ts deleted file mode 100644 index aa5b03d..0000000 --- a/src/extension/contentscript-main/Prefs.ts +++ /dev/null @@ -1,24 +0,0 @@ -import IPC from './IPC' -import { kPrefGetUseBrowserAI } from '#Shared/API/PrefIPCMessageTypes' - -class Prefs { - /* **************************************************************************/ - // MARK: Private - /* **************************************************************************/ - - #cachedUseBrowserAI: boolean | null = null - - /* **************************************************************************/ - // MARK: Getters - /* **************************************************************************/ - - async getUseBrowserAI () { - if (typeof (this.#cachedUseBrowserAI) !== 'boolean') { - this.#cachedUseBrowserAI = (await IPC.request(kPrefGetUseBrowserAI, {}) as boolean) - } - - return this.#cachedUseBrowserAI - } -} - -export default new Prefs() diff --git a/src/extension/ui-options/index.ts b/src/extension/ui-options/index.ts index 8547cf4..b570135 100644 --- a/src/extension/ui-options/index.ts +++ b/src/extension/ui-options/index.ts @@ -22,8 +22,6 @@ import IPCBackgroundMessager from '#Shared/IPC/IPCBackgroundMessager' import { getDefaultModel, setDefaultModel, - getUseBrowserAI, - setUseBrowserAI, setDefaultModelEngine, getDefaultModelEngine, setModelUpdatePeriod, @@ -43,37 +41,19 @@ import { AIModelType } from '#Shared/API/AI' // MARK: Settings /* **************************************************************************/ -const kBrowserAiModelId = '__browser__' - function renderDefaultModelOptions ( $el: HTMLSelectElement, selectedModelId: string, - modelList: Array<{ id: string, name: string }>, - hasBrowserAI: boolean, - useBrowserAI: boolean + modelList: Array<{ id: string, name: string }> ) { UI.empty($el) - if (hasBrowserAI) { - modelList = [{ id: kBrowserAiModelId, name: 'Browser AI' }, ...modelList] - } else { - useBrowserAI = false - } - for (const model of modelList) { const $option = document.createElement('option') $option.value = model.id $option.textContent = model.name - if (model.id === kBrowserAiModelId) { - if (useBrowserAI) { - $option.selected = true - } - } else { - if (model.id === selectedModelId) { - if ((useBrowserAI && modelList.some(({ id }) => id === kBrowserAiModelId)) === false) { - $option.selected = true - } - } + if (model.id === selectedModelId) { + $option.selected = true } $el.appendChild($option) } @@ -111,27 +91,20 @@ async function renderSettings () { const $defaultTextModelOpt = document.getElementById('opt-model-text-default') as HTMLSelectElement $defaultTextModelOpt.addEventListener('change', async () => { const modelId = $defaultTextModelOpt.value - - if (modelId === kBrowserAiModelId) { - await setUseBrowserAI(true) - } else { - await setUseBrowserAI(false) - await setDefaultModel(AIModelType.Text, modelId) - } + await setDefaultModel(AIModelType.Text, modelId) }) ;(async () => { - const useBrowserAI = await getUseBrowserAI() const defaultModelId = await getDefaultModel(AIModelType.Text) const defaultModelList = [ ...new Set([defaultModelId, Object.values(config.defaultModels)]) ].map((modelId) => ({ id: modelId, name: modelId })) - renderDefaultModelOptions($defaultTextModelOpt, defaultModelId, defaultModelList, Boolean(window.ai?.languageModel), useBrowserAI) + renderDefaultModelOptions($defaultTextModelOpt, defaultModelId, defaultModelList) 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.ai?.languageModel), useBrowserAI) + renderDefaultModelOptions($defaultTextModelOpt, defaultModelId, models) } })() @@ -146,12 +119,12 @@ async function renderSettings () { const defaultModelList = [ ...new Set([defaultModelId, Object.values(config.defaultModels)]) ].map((modelId) => ({ id: modelId, name: modelId })) - renderDefaultModelOptions($defaultEmbeddingModelOpt, defaultModelId, defaultModelList, false, false) + renderDefaultModelOptions($defaultEmbeddingModelOpt, defaultModelId, defaultModelList) const res = await fetch('https://aibrow.ai/api/model/list.json') if (res.ok) { const { models } = await res.json() - renderDefaultModelOptions($defaultEmbeddingModelOpt, defaultModelId, models, false, false) + renderDefaultModelOptions($defaultEmbeddingModelOpt, defaultModelId, models) } })() diff --git a/src/shared/API/PrefIPCMessageTypes.ts b/src/shared/API/PrefIPCMessageTypes.ts deleted file mode 100644 index 4364ca9..0000000 --- a/src/shared/API/PrefIPCMessageTypes.ts +++ /dev/null @@ -1 +0,0 @@ -export const kPrefGetUseBrowserAI = 'Pref:GetUseBrowserAI' diff --git a/src/shared/Prefs.ts b/src/shared/Prefs.ts index 35b9d8b..02b4436 100644 --- a/src/shared/Prefs.ts +++ b/src/shared/Prefs.ts @@ -43,10 +43,6 @@ const kDefaultModelsPrefixKey = `${kPrefKeyPrefix}:defaultModels:` export async function getDefaultModel (modelType: AIModelType) { return getPref(`${kDefaultModelsPrefixKey}${modelType}`, config.defaultModels[modelType]) } export async function setDefaultModel (modelType: AIModelType, modelId: string) { return setPref(`${kDefaultModelsPrefixKey}${modelType}`, modelId) } -const kDefaultUseBrowserAIKey = `${kPrefKeyPrefix}:useBrowserAI` -export async function getUseBrowserAI () { return getPref(kDefaultUseBrowserAIKey, false) } -export async function setUseBrowserAI (use: boolean) { return setPref(kDefaultUseBrowserAIKey, use) } - const kOverrideBrowserAIKey = `${kPrefKeyPrefix}:overrideBrowserAI` const kContentscriptMainOverrideId = 'contentscript-main-override' export async function getOverrideBrowserAI () { return getPref(kOverrideBrowserAIKey, false) }