tor-browser

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

commit 2c67aad3e77591e039b5a90783f19892ba3efb32
parent efc2ec78598e252f995fa5f4104c268c1c051d60
Author: Chloe Zhou <chloezhouny@gmail.com>
Date:   Mon,  5 Jan 2026 22:08:06 +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/components/aiwindow/ui/components/ai-window/ai-window.mjs | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

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 = "";