-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move extlib generation into its own source package
- Loading branch information
Showing
18 changed files
with
320 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
import IPCClient from '#Shared/IPC/IPCClient' | ||
import ContentScriptPort from './ContentScriptPort' | ||
import ExtensionLibPort from './ExtensionLibPort' | ||
|
||
let ipcClient | ||
if (process.env.BROWSER === 'extlib') { | ||
ipcClient = new IPCClient(new ExtensionLibPort(), { | ||
// The port in contentscript-main automatically reconnects after it's been destroyed | ||
// and there's no persisted state in the background page between different ports | ||
portReconnects: true | ||
}) | ||
} else { | ||
ipcClient = new IPCClient(new ContentScriptPort(), { | ||
// The port in the extension automatically reconnects after it's been destroyed | ||
// and there's no persisted state in the background page between different ports | ||
portReconnects: true | ||
}) | ||
} | ||
const ipcClient = new IPCClient(new ContentScriptPort(), { | ||
// The port in the extension automatically reconnects after it's been destroyed | ||
// and there's no persisted state in the background page between different ports | ||
portReconnects: true | ||
}) | ||
|
||
export default ipcClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import AISummarizerFactory from '#Shared/API/AISummarizer/AISummarizerFactory' | ||
import AIWriterFactory from '#Shared/API/AIWriter/AIWriterFactory' | ||
import AIRewriterFactory from '#Shared/API/AIRewriter/AIRewriterFactory' | ||
import AILanguageModelFactory from '#Shared/API/AILanguageModel/AILanguageModelFactory' | ||
import AICoreModelFactory from '#Shared/API/AICoreModel/AICoreModelFactory' | ||
import AIEmbeddingFactory from '#Shared/API/AIEmbedding/AIEmbeddingFactory' | ||
import AITranslatorFactory from '#Shared/API/AITranslator/AITranslatorFactory' | ||
import AILanguageDetectorFactory from '#Shared/API/AILanguageDetector/AILanguageDetectorFactory' | ||
import IPC from './IPC' | ||
import { | ||
kAIGetCapabilities, | ||
kAIGetNativeHelperDownloadUrl | ||
} from '#Shared/API/AIIPCTypes' | ||
import { AICapabilities } from '#Shared/API/AI' | ||
import { kExtensionNotFound } from '#Shared/BrowserErrors' | ||
|
||
class AI extends EventTarget { | ||
/* **************************************************************************/ | ||
// MARK: Private | ||
/* **************************************************************************/ | ||
|
||
#browserAI: globalThis.AI | undefined | ||
#summarizer: AISummarizerFactory | ||
#writer: AIWriterFactory | ||
#rewriter: AIRewriterFactory | ||
#languageModel: AILanguageModelFactory | ||
#coreModel: AICoreModelFactory | ||
#embedding: AIEmbeddingFactory | ||
#translator: AITranslatorFactory | ||
#languageDetector: AILanguageDetectorFactory | ||
|
||
/* **************************************************************************/ | ||
// MARK: Lifecycle | ||
/* **************************************************************************/ | ||
|
||
constructor (browserAI: globalThis.AI | undefined) { | ||
super() | ||
|
||
this.#browserAI = browserAI | ||
this.#summarizer = new AISummarizerFactory(IPC) | ||
this.#writer = new AIWriterFactory(IPC) | ||
this.#rewriter = new AIRewriterFactory(IPC) | ||
this.#languageModel = new AILanguageModelFactory(IPC) | ||
this.#coreModel = new AICoreModelFactory(IPC) | ||
this.#embedding = new AIEmbeddingFactory(IPC) | ||
this.#translator = new AITranslatorFactory(IPC) | ||
this.#languageDetector = new AILanguageDetectorFactory(IPC) | ||
} | ||
|
||
/* **************************************************************************/ | ||
// MARK: Properties | ||
/* **************************************************************************/ | ||
|
||
get browserAI () { return this.#browserAI } | ||
|
||
get aibrow () { return true } | ||
|
||
get assistant () { return this.#languageModel } | ||
|
||
get summarizer () { return this.#summarizer } | ||
|
||
get writer () { return this.#writer } | ||
|
||
get rewriter () { return this.#rewriter } | ||
|
||
get languageModel () { return this.#languageModel } | ||
|
||
get coreModel () { return this.#coreModel } | ||
|
||
get embedding () { return this.#embedding } | ||
|
||
get translator () { return this.#translator } | ||
|
||
get languageDetector () { return this.#languageDetector } | ||
|
||
/* **************************************************************************/ | ||
// MARK: Capabilities | ||
/* **************************************************************************/ | ||
|
||
capabilities = async () => { | ||
try { | ||
const capabilities = await IPC.request(kAIGetCapabilities, {}) | ||
return capabilities as AICapabilities | ||
} catch (ex) { | ||
if (ex.message === kExtensionNotFound) { | ||
return { extension: false, helper: false } as AICapabilities | ||
} else { | ||
throw ex | ||
} | ||
} | ||
} | ||
|
||
getHelperDownloadUrl = async () => { | ||
const url = await IPC.request(kAIGetNativeHelperDownloadUrl, {}) | ||
return url | ||
} | ||
} | ||
|
||
export default AI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import IPCClient from '#Shared/IPC/IPCClient' | ||
import ExtensionLibPort from './ExtensionLibPort' | ||
|
||
const ipcClient = new IPCClient(new ExtensionLibPort(), { | ||
// The port in contentscript-main automatically reconnects after it's been destroyed | ||
// and there's no persisted state in the background page between different ports | ||
portReconnects: true | ||
}) | ||
|
||
export default ipcClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import IPC from './IPC' | ||
export default IPC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Extension library for AiBrow. See [AiBrow](https://github.com/axonzeta/aibrow/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "index.js", | ||
"types": "index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import AI from './AI' | ||
|
||
export const ai = new AI(window.ai) | ||
|
||
export default ai |
Oops, something went wrong.