Skip to content

Commit

Permalink
Bug 1909986 - For sidebar revamp, only show chatbot entrypoints (cont…
Browse files Browse the repository at this point in the history
…ext menu, shortcuts) when tools include aichat r=tarek

Convert existing entrypoint checks to getter that also checks sidebar.

Differential Revision: https://phabricator.services.mozilla.com/D223690
  • Loading branch information
Mardak committed Sep 28, 2024
1 parent a7eb62c commit dbac9a2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
27 changes: 25 additions & 2 deletions browser/components/genai/GenAI.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ XPCOMUtils.defineLazyPreferenceGetter(
"chatSidebar",
"browser.ml.chat.sidebar"
);
XPCOMUtils.defineLazyPreferenceGetter(lazy, "sidebarRevamp", "sidebar.revamp");
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"sidebarTools",
"sidebar.main.tools"
);

export const GenAI = {
// Cache of potentially localized prompt
Expand Down Expand Up @@ -233,6 +239,20 @@ export const GenAI = {
],
]),

/**
* Determine if chat entrypoints can be shown
*
* @returns {bool} can show
*/
get canShowChatEntrypoint() {
return (
lazy.chatEnabled &&
lazy.chatProvider != "" &&
// Chatbot needs to be a tool if new sidebar
(!lazy.sidebarRevamp || lazy.sidebarTools.includes("aichat"))
);
},

/**
* Handle startup tasks like telemetry, adding listeners.
*/
Expand Down Expand Up @@ -374,7 +394,10 @@ export const GenAI = {
break;
case "GenAI:ShowShortcuts": {
// Ignore some input field selection to avoid showing shortcuts
if (this.ignoredInputs.has(data.inputType)) {
if (
this.ignoredInputs.has(data.inputType) ||
!this.canShowChatEntrypoint
) {
return;
}

Expand Down Expand Up @@ -489,7 +512,7 @@ export const GenAI = {
*/
async buildAskChatMenu(menu, nsContextMenu) {
nsContextMenu.showItem(menu, false);
if (!lazy.chatEnabled || lazy.chatProvider == "") {
if (!this.canShowChatEntrypoint) {
return;
}
const provider = this.chatProviders.get(lazy.chatProvider)?.name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

const { GenAI } = ChromeUtils.importESModule(
"resource:///modules/GenAI.sys.mjs"
);

registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.ml.chat.enabled");
Services.prefs.clearUserPref("browser.ml.chat.provider");
Services.prefs.clearUserPref("sidebar.main.tools");
Services.prefs.clearUserPref("sidebar.revamp");
});

/**
* Check various prefs for showing chat
*/
add_task(async function test_show_chat() {
Assert.ok(!GenAI.canShowChatEntrypoint, "Default no");

Services.prefs.setBoolPref("browser.ml.chat.enabled", true);

Assert.ok(!GenAI.canShowChatEntrypoint, "Not enough to just enable");

Services.prefs.setStringPref(
"browser.ml.chat.provider",
"http://mochi.test:8888"
);

Assert.ok(GenAI.canShowChatEntrypoint, "Can show with provider");

Services.prefs.setBoolPref("sidebar.revamp", true);

Assert.ok(GenAI.canShowChatEntrypoint, "Can show with revamp");

Services.prefs.setStringPref("sidebar.main.tools", "history");

Assert.ok(!GenAI.canShowChatEntrypoint, "Not shown without chatbot tool");

Services.prefs.setBoolPref("sidebar.revamp", false);

Assert.ok(GenAI.canShowChatEntrypoint, "Ignore tools without revamp");
});
1 change: 1 addition & 0 deletions browser/components/genai/tests/xpcshell/xpcshell.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ firefox-appdir = "browser"
["test_build_chat_prompt.js"]
["test_contextual_prompts.js"]
["test_provider_id.js"]
["test_show_chat_entrypoint.js"]

0 comments on commit dbac9a2

Please sign in to comment.