Skip to content

Commit ec1ec37

Browse files
author
Punam Dahiya
committed
Update entrypoint and service to aimode in FxA authentication
Updated with OpenAI pipeline changes from D271303 Point to stage FxA server
1 parent 173fbc7 commit ec1ec37

5 files changed

Lines changed: 38 additions & 1 deletion

File tree

browser/app/profile/firefox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,7 @@ pref("identity.sync.tokenserver.uri", "https://token.services.mozilla.com/1.0/sy
23252325
// [identity.fxaccounts.autoconfig.uri]/.well-known/fxa-client-configuration
23262326
// This is now the prefered way of pointing to a custom FxA server, instead
23272327
// of making changes to "identity.fxaccounts.*.uri".
2328-
pref("identity.fxaccounts.autoconfig.uri", "");
2328+
pref("identity.fxaccounts.autoconfig.uri", "https://accounts.stage.mozaws.net");
23292329

23302330
// URL for help link about Send Tab.
23312331
pref("identity.sendtabpromo.url", "https://support.mozilla.org/1/firefox/%VERSION%/%OS%/%LOCALE%/send-tab");

browser/base/content/browser-smart-window.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ var SmartWindow = {
128128
type: "FXA_SMART_WINDOW_SIGNIN_FLOW",
129129
data: {
130130
entrypoint: "aimode",
131+
extraParams: {
132+
service: "aimode",
133+
}
131134
},
132135
},
133136
gBrowser.selectedBrowser

browser/components/smartwindow/content/utils.mjs

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

1515
import { createEngine } from "chrome://global/content/ml/EngineProcess.sys.mjs";
1616
import { SmartAssistEngine } from "moz-src:///browser/components/genai/SmartAssistEngine.sys.mjs";
17+
import { getFxAccountsSingleton } from "resource://gre/modules/FxAccounts.sys.mjs";
18+
import {
19+
SCOPE_PROFILE,
20+
OAUTH_CLIENT_ID,
21+
} from "resource://gre/modules/FxAccountsCommon.sys.mjs";
1722

1823
const { ChatHistoryMessage } = ChromeUtils.importESModule(
1924
"resource:///modules/smartwindow/ChatHistory.sys.mjs"
@@ -382,6 +387,20 @@ const get_page_content = async ({ url, mode, page }, allowedUrls) => {
382387
}
383388
};
384389

390+
const getFxAccountToken = async () => {
391+
try {
392+
const fxAccounts = getFxAccountsSingleton();
393+
const token = await fxAccounts.getOAuthToken({
394+
scope: SCOPE_PROFILE,
395+
client_id: OAUTH_CLIENT_ID,
396+
});
397+
return token;
398+
} catch (error) {
399+
console.error("Error obtaining FxA token:", error);
400+
throw error;
401+
}
402+
};
403+
385404
/**
386405
* @param {PageExtractor} pageExtractor
387406
* @param {string} mode
@@ -459,6 +478,7 @@ async function runExtraction(pageExtractor, mode, page, label) {
459478
*/
460479
export async function* fetchWithHistory(messages, allowedUrls) {
461480
const engineInstance = await createOpenAIEngine();
481+
const fxAccountToken = await getFxAccountToken();
462482

463483
// Normalize roles to lowercase and handle system messages
464484
let convo = Array.isArray(messages)
@@ -512,6 +532,7 @@ export async function* fetchWithHistory(messages, allowedUrls) {
512532
const streamModelResponse = () =>
513533
engineInstance.runWithGenerator({
514534
streamOptions: { enabled: true },
535+
fxAccountToken,
515536
tool_choice: "auto",
516537
tools: toolsConfig,
517538
args: convo,

browser/components/smartwindow/content/welcome.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ XPCOMUtils.defineLazyPreferenceGetter(
6969
{
7070
data: {
7171
entrypoint: "aimode",
72+
extraParams: {
73+
service: "aimode",
74+
}
7275
},
7376
type: "FXA_SMART_WINDOW_SIGNIN_FLOW",
7477
navigate: true,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,20 @@ export class OpenAIPipeline {
327327
lazy.console.debug("Running OpenAI pipeline");
328328
try {
329329
const { baseURL, apiKey, modelId } = this.#options;
330+
let fxAccountToken = request.fxAccountToken
331+
? request.fxAccountToken
332+
: null;
333+
334+
fxAccountToken='eyJhbGciOiJSUzI1NiIsInR5cCI6ImF0K0pXVCIsImtpZCI6IjIwMTkwNzMwLTE1ZTQ3M2ZkIn0.eyJpc3MiOiJodHRwczovL2FjY291bnRzLnN0YWdlLm1vemF3cy5uZXQiLCJhdWQiOiI1ODgyMzg2YzZkODAxNzc2IiwiY2xpZW50X2lkIjoiNTg4MjM4NmM2ZDgwMTc3NiIsImV4cCI6MTc2MjYwNzE5MywiaWF0IjoxNzYyNTYzOTkzLCJqdGkiOiI5MTk0MGUzNGU1MWNiNjJmY2E2ZjdmMWYyNjI5Mzk1MzEwNWI5MmM5ZWQzOTk1NzlmYTdjY2M4OGJjZjMwYjFjIiwic2NvcGUiOiJwcm9maWxlIiwic3ViIjoiYTcwMDVmNTA4ODQzNGM1YmI5YTM1YzYzNzM1NWZhYjUiLCJmeGEtZ2VuZXJhdGlvbiI6MTc2MjM3NzY4MDA0NiwiZnhhLXByb2ZpbGVDaGFuZ2VkQXQiOjE3NjIzNzc3Mjg3Nzd9.Y7CRqnC9Rc-FuSb-726OOKqGjC4T3FVB1YobJwg_m1r8ughEWScz0vam02IpLEC5WjE_5HRQD6URTcQ0epTXU2T5c-jkAo5kn8GMvkI-YieMOPePwU0LljnU7vGNMSJ7trdAjXhb8aCLnojP5wSDni7BM_khfr66yHWBWaOFV3TPUor8N9JDMb_5bDrqzvbigKpoeeJ23ihw17Mis3EGC4AjmyIqL92gGWVTvz2g9u_H0MOc8YfxEoO6aagz-OwYJrXVpVxCeRQ8wYbV9ce191a9NrLaUmBFn0NC6JfsbD2bLU7HDl7haUtIaofgnpzru-zlGmk8VoCA1dGJ--lPfg';
335+
const defaultHeaders = fxAccountToken
336+
? { "authorization": `Bearer ${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)