Files
sousa-gecko/browser/components/aiwindow/ui/modules/FeedbackModal.sys.mjs
T
Elissa Cha e3894339e6 Bug 2033002 - Add Preview Report support to Smart Window feedback modal r=pdahiya,fluent-reviewers,omc-reviewers,bolsson,aminomancer
- Add Preview Report support to the Smart Window feedback modal
- Introduce `ContentToggle` and `TextboxTile` components to the ASRouter multistage template
- Dynamically update preview and chat log payload based on toggle state

Differential Revision: https://phabricator.services.mozilla.com/D305368
2026-06-23 02:30:45 +00:00

76 lines
2.5 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
ASRouter: "resource:///modules/asrouter/ASRouter.sys.mjs",
Spotlight: "resource:///modules/asrouter/Spotlight.sys.mjs",
});
export const FeedbackModal = {
/**
* @param {MozBrowser} browser
* @param {string} type - "thumbs-up" or "thumbs-down".
* @param {object} metadata - Chat session data to include in telemetry.
*/
async open(browser, type, metadata) {
await lazy.ASRouter.waitForInitialized;
const message = await lazy.ASRouter.handleMessageRequest({
triggerId: "feedbackThumbClick",
triggerParam: { type },
template: "spotlight",
});
if (!message) {
return;
}
const clonedMessage = structuredClone(message);
if (metadata) {
clonedMessage.content.feedbackData = {
metadata: metadata.metadata,
chat: metadata.chatLog,
chatWithoutPageContent: metadata.chatLogWithoutPageContent,
};
for (const screen of clonedMessage.content.screens ?? []) {
const { tiles } = screen.content ?? {};
const textboxTile = tiles?.find(t => t.type === "textbox");
const contentToggleTile = tiles?.find(t => t.type === "content-toggle");
if (textboxTile && metadata.chatLog) {
textboxTile.data.content = JSON.stringify(
{ metadata: metadata.metadata, ...metadata.chatLog },
null,
2
);
if (textboxTile.header?.title) {
textboxTile.header.title.string_id =
metadata.chatLogWithoutPageContent
? "aiwindow-feedback-preview-report-with-page"
: "aiwindow-feedback-preview-report";
}
if (contentToggleTile) {
contentToggleTile.data.visible =
!!metadata.chatLogWithoutPageContent;
}
if (metadata.chatLogWithoutPageContent) {
textboxTile.data.alternateContent = JSON.stringify(
{
metadata: metadata.metadata,
...metadata.chatLogWithoutPageContent,
},
null,
2
);
}
}
}
}
try {
await lazy.Spotlight.showSpotlightDialog(browser, clonedMessage);
} catch (e) {
console.error("Failed to open feedback modal", e);
}
},
};