@@ -12,6 +12,11 @@ ChromeUtils.defineESModuleGetters(lazy, {
1212
1313import { createEngine } from "chrome://global/content/ml/EngineProcess.sys.mjs" ;
1414import { SmartAssistEngine } from "moz-src:///browser/components/genai/SmartAssistEngine.sys.mjs" ;
15+ import { getFxAccountsSingleton } from "resource://gre/modules/FxAccounts.sys.mjs" ;
16+ import {
17+ SCOPE_PROFILE ,
18+ OAUTH_CLIENT_ID ,
19+ } from "resource://gre/modules/FxAccountsCommon.sys.mjs" ;
1520
1621const { ChatHistoryMessage } = ChromeUtils . importESModule (
1722 "resource:///modules/smartwindow/ChatHistory.sys.mjs"
@@ -53,6 +58,20 @@ export async function detectQueryType(query, isFollowup = false) {
5358 }
5459}
5560
61+ const getFxAccountToken = async ( ) => {
62+ try {
63+ const fxAccounts = getFxAccountsSingleton ( ) ;
64+ const token = await fxAccounts . getOAuthToken ( {
65+ scope : SCOPE_PROFILE ,
66+ client_id : OAUTH_CLIENT_ID ,
67+ } ) ;
68+ return token ;
69+ } catch ( error ) {
70+ console . error ( "Error obtaining FxA token:" , error ) ;
71+ throw error ;
72+ }
73+ } ;
74+
5675/**
5776 * Creates an OpenAI engine instance configured with Smart Window preferences.
5877 *
@@ -61,6 +80,7 @@ export async function detectQueryType(query, isFollowup = false) {
6180 */
6281export async function createOpenAIEngine ( engineId = "smart-openai" ) {
6382 try {
83+ const fxAccountToken = await getFxAccountToken ( ) ;
6484 const engineInstance = await createEngine ( {
6585 apiKey : Services . prefs . getStringPref ( "browser.smartwindow.key" ) ,
6686 backend : "openai" ,
@@ -69,6 +89,7 @@ export async function createOpenAIEngine(engineId = "smart-openai") {
6989 modelId : Services . prefs . getStringPref ( "browser.smartwindow.model" ) ,
7090 modelRevision : "main" ,
7191 taskName : "text-generation" ,
92+ fxAccountToken,
7293 } ) ;
7394 return engineInstance ;
7495 } catch ( error ) {
0 commit comments