Skip to content

Commit 9fa1bda

Browse files
author
Punam Dahiya
committed
Update entrypoint and service to aimode in FxA authentication
Updated with OpenAI pipeline changes from D271303
1 parent b9d9fbf commit 9fa1bda

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

browser/components/smartwindow/content/utils.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ ChromeUtils.defineESModuleGetters(lazy, {
1212

1313
import { createEngine } from "chrome://global/content/ml/EngineProcess.sys.mjs";
1414
import { 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

1621
const { 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
*/
6281
export 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) {

browser/components/smartwindow/content/welcome.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ XPCOMUtils.defineLazyPreferenceGetter(
6868
},
6969
{
7070
data: {
71-
entrypoint: "activity-stream-firstrun",
71+
entrypoint: "aimode",
72+
extraParams: {
73+
service: "aimode",
74+
}
7275
},
7376
type: "FXA_SMART_WINDOW_SIGNIN_FLOW",
7477
navigate: true,

toolkit/components/ml/content/EngineProcess.sys.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ export class PipelineOptions {
801801
"baseURL",
802802
"apiKey",
803803
"staticEmbeddingsOptions",
804+
"fxAccountToken",
804805
];
805806

806807
if (options instanceof PipelineOptions) {
@@ -946,6 +947,7 @@ export class PipelineOptions {
946947
baseURL: this.baseURL,
947948
apiKey: this.apiKey,
948949
staticEmbeddingsOptions: this.staticEmbeddingsOptions,
950+
fxAccountToken: this.fxAccountToken,
949951
};
950952
}
951953

toolkit/components/ml/content/backends/OpenAIPipeline.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,21 @@ export class OpenAIPipeline {
326326
) {
327327
lazy.console.debug("Running OpenAI pipeline");
328328
try {
329-
const { baseURL, apiKey, modelId } = this.#options;
329+
const { baseURL, apiKey, modelId, fxAccountToken } = this.#options;
330+
331+
if (!fxAccountToken) {
332+
console.warn("No FxA token available;");
333+
}
334+
335+
const defaultHeaders = fxAccountToken
336+
? { "x-fxa-authorization": `Bearer ${fxAccountToken}` } // or "X-FxA-Access-Token": fxAccountToken
337+
: undefined;
338+
330339
const client = new OpenAIPipeline.OpenAILib.OpenAI({
331340
baseURL: baseURL ? baseURL : "http://localhost:11434/v1",
332341
apiKey: apiKey || "ollama",
333342
maxRetries: 10,
343+
...(defaultHeaders ? { defaultHeaders } : {}),
334344
});
335345
const stream = request.streamOptions?.enabled || false;
336346
const tools = request.tools || [];

0 commit comments

Comments
 (0)