Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions browser/base/content/browser-smart-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ var SmartWindow = {
type: "FXA_SMART_WINDOW_SIGNIN_FLOW",
data: {
entrypoint: "aimode",
Copy link
Collaborator

@LZoog LZoog Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to update this to aiwindow in this PR, the entrypoint I believe is still TBD but the service has been updated on the FxA side to look for the service=aiwindow query param.

extraParams: {
service: "aimode",
}
},
},
gBrowser.selectedBrowser
Expand Down
21 changes: 21 additions & 0 deletions browser/components/smartwindow/content/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ ChromeUtils.defineESModuleGetters(lazy, {

import { createEngine } from "chrome://global/content/ml/EngineProcess.sys.mjs";
import { SmartAssistEngine } from "moz-src:///browser/components/genai/SmartAssistEngine.sys.mjs";
import { getFxAccountsSingleton } from "resource://gre/modules/FxAccounts.sys.mjs";
import {
SCOPE_PROFILE,
OAUTH_CLIENT_ID,
} from "resource://gre/modules/FxAccountsCommon.sys.mjs";

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

const getFxAccountToken = async () => {
try {
const fxAccounts = getFxAccountsSingleton();
const token = await fxAccounts.getOAuthToken({
scope: SCOPE_PROFILE,
client_id: OAUTH_CLIENT_ID,
});
return token;
} catch (error) {
console.warn("Failed to obtain a valid FxA token:", error);
return null;
}
};

/**
* @param {PageExtractor} pageExtractor
* @param {string} mode
Expand Down Expand Up @@ -459,6 +478,7 @@ async function runExtraction(pageExtractor, mode, page, label) {
*/
export async function* fetchWithHistory(messages, allowedUrls) {
const engineInstance = await createOpenAIEngine();
const fxAccountToken = await getFxAccountToken();

// Normalize roles to lowercase and handle system messages
let convo = Array.isArray(messages)
Expand Down Expand Up @@ -512,6 +532,7 @@ export async function* fetchWithHistory(messages, allowedUrls) {
const streamModelResponse = () =>
engineInstance.runWithGenerator({
streamOptions: { enabled: true },
fxAccountToken,
tool_choice: "auto",
tools: toolsConfig,
args: convo,
Expand Down
3 changes: 3 additions & 0 deletions browser/components/smartwindow/content/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ XPCOMUtils.defineLazyPreferenceGetter(
{
data: {
entrypoint: "aimode",
extraParams: {
service: "aimode",
}
},
type: "FXA_SMART_WINDOW_SIGNIN_FLOW",
navigate: true,
Expand Down
9 changes: 9 additions & 0 deletions toolkit/components/ml/content/backends/OpenAIPipeline.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,19 @@ export class OpenAIPipeline {
lazy.console.debug("Running OpenAI pipeline");
try {
const { baseURL, apiKey, modelId } = this.#options;
let fxAccountToken = request.fxAccountToken
? request.fxAccountToken
: null;

const defaultHeaders = fxAccountToken
? { "authorization": `Bearer ${fxAccountToken}` }
: undefined;

const client = new OpenAIPipeline.OpenAILib.OpenAI({
baseURL: baseURL ? baseURL : "http://localhost:11434/v1",
apiKey: apiKey || "ollama",
maxRetries: 10,
...(defaultHeaders ? { defaultHeaders } : {}),
});
const stream = request.streamOptions?.enabled || false;
const tools = request.tools || [];
Expand Down