tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 302dd7da9402fd5a2355679b8bb85653990ad46f
parent 09b712ccc7ebb21de5aa3a78fe46def1769bec2d
Author: Chloe Zhou <chloezhouny@gmail.com>
Date:   Tue,  6 Jan 2026 02:51:22 +0000

Bug 2001517 - Generate chat title when conversation is saved r=omarg,ai-frontend-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D277929

Diffstat:
Mbrowser/base/content/test/static/browser_all_files_referenced.js | 4----
Mbrowser/components/aiwindow/ui/components/ai-window/ai-window.mjs | 30++++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js @@ -341,10 +341,6 @@ var allowlist = [ { file: "moz-src:///browser/components/aiwindow/models/memories/MemoriesHistoryScheduler.sys.mjs", }, - // Bug 2003303 - Implement Title Generation (backed out due to unused file) - { - file: "moz-src:///browser/components/aiwindow/models/TitleGeneration.sys.mjs", - }, // Bug 2006090 - Insight updation - Day 0 and incremental updates from Chat history // Bug 2007939 - Rename "insights" to "memories" { diff --git a/browser/components/aiwindow/ui/components/ai-window/ai-window.mjs b/browser/components/aiwindow/ui/components/ai-window/ai-window.mjs @@ -8,6 +8,8 @@ import { MozLitElement } from "chrome://global/content/lit-utils.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { Chat: "moz-src:///browser/components/aiwindow/models/Chat.sys.mjs", + generateChatTitle: + "moz-src:///browser/components/aiwindow/models/TitleGeneration.sys.mjs", AIWindow: "moz-src:///browser/components/aiwindow/ui/modules/AIWindow.sys.mjs", ChatConversation: @@ -82,6 +84,33 @@ export class AIWindow extends MozLitElement { } /** + * Generates and sets a title for the conversation if one doesn't exist. + * + * @private + */ + async #addConversationTitle() { + if (this.#conversation.title) { + return; + } + + const firstUserMessage = this.#conversation.messages.find( + m => m.role === lazy.MESSAGE_ROLE.USER + ); + + const title = await lazy.generateChatTitle( + firstUserMessage?.content?.body, + { + url: firstUserMessage?.pageUrl?.href || "", + title: this.#conversation.pageMeta?.title || "", + description: this.#conversation.pageMeta?.description || "", + } + ); + + this.#conversation.title = title; + this.#updateConversation(); + } + + /** * Fetches an AI response based on the current user prompt. * Validates the prompt, updates conversation state, streams the response, * and dispatches updates to the browser actor. @@ -109,6 +138,7 @@ export class AIWindow extends MozLitElement { await this.#conversation.generatePrompt(this.userPrompt) ); this.#updateConversation(); + this.#addConversationTitle(); this.userPrompt = "";