From 2a17b1e42438a54fcfc463e1d8f393bbbbcdea6a Mon Sep 17 00:00:00 2001 From: Andrea Brancaleoni Date: Tue, 17 Dec 2024 23:32:24 -0800 Subject: [PATCH] add brave-ai-chat-sidebar-page-context flag --- browser/about_flags.cc | 7 +++++++ components/ai_chat/core/browser/conversation_handler.cc | 4 ++-- components/ai_chat/core/common/features.cc | 8 ++++++++ components/ai_chat/core/common/features.h | 6 +++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/browser/about_flags.cc b/browser/about_flags.cc index e8bb97c7d2d0..ac95c1a904d0 100644 --- a/browser/about_flags.cc +++ b/browser/about_flags.cc @@ -408,6 +408,13 @@ "Enables opening Leo AI Chat from Brave Search", \ kOsDesktop | kOsAndroid, \ FEATURE_VALUE_TYPE(ai_chat::features::kOpenAIChatFromBraveSearch), \ + }, \ + { \ + "brave-ai-chat-sidebar-page-context", \ + "Brave AI Chat Page Context", \ + "Use page context to improve AI chat responses in the sidebar", \ + kOsWin | kOsMac | kOsLinux | kOsAndroid, \ + FEATURE_VALUE_TYPE(ai_chat::features::kSidebarUsePageContext), \ }) #if BUILDFLAG(ENABLE_AI_REWRITER) diff --git a/components/ai_chat/core/browser/conversation_handler.cc b/components/ai_chat/core/browser/conversation_handler.cc index bff15e30cd1c..bafe2e841023 100644 --- a/components/ai_chat/core/browser/conversation_handler.cc +++ b/components/ai_chat/core/browser/conversation_handler.cc @@ -431,7 +431,7 @@ void ConversationHandler::SetArchiveContent(std::string text_content, is_video); associated_content_delegate_ = archive_content->GetWeakPtr(); archive_content_ = std::move(archive_content); - should_send_page_contents_ = true; + should_send_page_contents_ = features::IsSidebarUsePageContextEnabled(); } void ConversationHandler::SetAssociatedContentDelegate( @@ -465,7 +465,7 @@ void ConversationHandler::SetAssociatedContentDelegate( // This class should only be provided with a delegate when // it is allowed to use it (e.g. not internal WebUI content). // The user can toggle this via the UI. - should_send_page_contents_ = true; + should_send_page_contents_ = features::IsSidebarUsePageContextEnabled(); MaybeSeedOrClearSuggestions(); MaybeFetchOrClearContentStagedConversation(); diff --git a/components/ai_chat/core/common/features.cc b/components/ai_chat/core/common/features.cc index 4d9d85ae6a06..02e8001afc5e 100644 --- a/components/ai_chat/core/common/features.cc +++ b/components/ai_chat/core/common/features.cc @@ -90,4 +90,12 @@ bool IsOpenAIChatFromBraveSearchEnabled() { return base::FeatureList::IsEnabled(features::kOpenAIChatFromBraveSearch); } +BASE_FEATURE(kSidebarUsePageContext, + "SidebarUsePageContext", + base::FEATURE_ENABLED_BY_DEFAULT); + +bool IsSidebarUsePageContextEnabled() { + return base::FeatureList::IsEnabled(features::kSidebarUsePageContext); +} + } // namespace ai_chat::features diff --git a/components/ai_chat/core/common/features.h b/components/ai_chat/core/common/features.h index 8850a41c54ec..a8e615fee7af 100644 --- a/components/ai_chat/core/common/features.h +++ b/components/ai_chat/core/common/features.h @@ -59,6 +59,10 @@ COMPONENT_EXPORT(AI_CHAT_COMMON) BASE_DECLARE_FEATURE(kOpenAIChatFromBraveSearch); COMPONENT_EXPORT(AI_CHAT_COMMON) bool IsOpenAIChatFromBraveSearchEnabled(); +COMPONENT_EXPORT(AI_CHAT_COMMON) +BASE_DECLARE_FEATURE(kSidebarUsePageContext); +COMPONENT_EXPORT(AI_CHAT_COMMON) bool IsSidebarUsePageContextEnabled(); + } // namespace ai_chat::features -#endif // BRAVE_COMPONENTS_AI_CHAT_CORE_COMMON_FEATURES_H_ +#endif // BRAVE_COMPONENTS_AI_CHAT_CORE_COMMON_FEATURES_H_ \ No newline at end of file