Skip to content

Commit

Permalink
Uplift AI Chat Full Page Storage feature
Browse files Browse the repository at this point in the history
- [AIChat conversation data storage by petemill · Pull Request \#25876 · brave/brave-core](#25876)
  - [AI Chat conversations should persist browser restart · Issue \#42800 · brave/brave-browser](brave/brave-browser#42800) `QA/Yes`
- [\[AIChat\]: Add URL based routing for different chats by fallaciousreasoning · Pull Request \#26050 · brave/brave-core](#26050)
  - [\[AI Chat\]: URLs for all conversations · Issue \#42055 · brave/brave-browser](brave/brave-browser#42055) `QA/Yes`
    - test plan: url and header variations specified
- [AI Chat fullpage UI notices and polish by petemill · Pull Request \#26678 · brave/brave-core](#26678)
  - [AI Chat conversation list should prompt to enable history storage if it's disabled · Issue \#42576 · brave/brave-browser](brave/brave-browser#42576) `QA/Yes`
    - test plan: specified
  - [AI Chat notice for conversation storage · Issue \#42360 · brave/brave-browser](brave/brave-browser#42360) `QA/Yes`
    - test plan: specified
  - [AI Chat FullPage shouldn't show in SidePanel mode when restored at startup · Issue \#42413 · brave/brave-browser](brave/brave-browser#42413) `QA/Yes`
    - test plan: specified
- [AI Chat becomes a trusted WebUI with an UntrustedWebUI frame for LLM-generated responses by petemill · Pull Request \#26855 · brave/brave-core](#26855)
  - [Change AI Chat url to chrome://leo-ai · Issue \#42817 · brave/brave-browser](brave/brave-browser#42817) `QA/Yes`
  - [AI Chat conversation entries should be isolated in an untrusted frame · Issue \#42818 · brave/brave-browser](brave/brave-browser#42818) `QA/No`
- [\[AI Chat\]: Update copy button label by fallaciousreasoning · Pull Request \#26422 · brave/brave-core](#26422)
  - [Change copy button name to text if text in code block · Issue \#42117 · brave/brave-browser](brave/brave-browser#42117) `QA/Yes`
- [\[AI Chat\]: Conversation starter pack, for unassociated content by fallaciousreasoning · Pull Request \#26379 · brave/brave-core](#26379)
  - [\[AI Chat\]: Add support for static conversation starters · Issue \#42106 · brave/brave-browser](brave/brave-browser#42106) `QA/Yes`
    - test plan: needs improvement
- [Css tweaks and icon change for sidebar by aguscruiz · Pull Request \#26450 · brave/brave-core](#26450)
  - [\[Leo full page\] - Tweak to expand/collapse sidebar icons · Issue \#42068 · brave/brave-browser](brave/brave-browser#42068) `QA/Yes`
    - test plan: specified (check icons are correct)
- [\[AI Chat\]: Update styling on suggestions by fallaciousreasoning · Pull Request \#26565 · brave/brave-core](#26565)
  - [\[AI Chat\]: Update suggestions style to match new design · Issue \#42107 · brave/brave-browser](brave/brave-browser#42107) `QA/Yes`
    - test plan: specified (check suggestions have new style)
- [\[AI Chat\]: Don't show starter suggestions on non-empty chats by fallaciousreasoning · Pull Request \#26677 · brave/brave-core](#26677)
  - [AI Chat static conversation starters shouldn't show if conversation has chat history · Issue \#42412 · brave/brave-browser](brave/brave-browser#42412) `QA/Yes`
    - test plan: specified (verify conversation starters only show when applicable)
- [fix hit area for leo conversations list by aguscruiz · Pull Request \#26793 · brave/brave-core](#26793)
  - [Leo full page - Conversation list - Make the whole item clickable instead of excluding the padding · Issue \#42552 · brave/brave-browser](brave/brave-browser#42552) `QA/No`
- [\[Nala / @brave/leo\] update dependency by petemill · Pull Request \#26767 · brave/brave-core](#26767)
  - brave/brave-browser#42545 `QA/No`
  • Loading branch information
petemill committed Dec 12, 2024
1 parent b156def commit f9da397
Show file tree
Hide file tree
Showing 244 changed files with 7,768 additions and 2,024 deletions.
26 changes: 16 additions & 10 deletions app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
Position
</message>
<message name="IDS_SETTINGS_APPEARANCE_SETTINGS_BRAVE_TAB_VERTICAL_TAB_EXPANDED_STATE_PER_WINDOW" desc="Title for checkbox to set expanded state per window">
Expand vertical tabs independently per window
Expand vertical tabs independently per window
</message>
<message name="IDS_SETTINGS_APPEARANCE_SETTINGS_BRAVE_TAB_VERTICAL_TAB_SHOW_SCROLLBAR" desc="Title for checkbox to show scrollbar on vertical tabs">
Show scrollbar
Expand Down Expand Up @@ -1332,23 +1332,29 @@
<message name="IDS_SETTINGS_LEO_ASSISTANT_SHOW_SUGGESTED_PROMPTS_LABEL" desc="The text for settings option">
Show suggested prompts in the conversation
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_RESET_AND_CLEAR_DATA_LABEL" desc="The text for settings option">
Clear Leo data
<message name="IDS_SETTINGS_LEO_ASSISTANT_HISTORY_PREFERENCE_LABEL" desc="The label for the checkbox determining whether to store AI Chat conversations">
Store my conversation history
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_HISTORY_PREFERENCE_CONFIRM" desc="The confirmation prompt about disabling the AI Chat history preference">
Disabling conversation storage will permanently erase all previously stored conversations. This action can't be undone.
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_RESET_AND_CLEAR_DATA_LABEL" desc="The button label for deleteing all AI Chat conversations">
Delete all Leo AI conversation data
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_RESET_AND_CLEAR_DATA_CONFIRMATION_LABEL" desc="The confirmation window message for reset option">
Resetting the Leo assistant will require you to opt-in to use Brave
Leo in the future and will also clear your chat history. Clearing your
Resetting Leo AI will require you to opt-in to use Brave
Leo AI in the future and will also clear your chat history. Clearing your
chat history will delete all your previous conversations with Brave
Leo. This action can't be undone.
Leo AI. This action can't be undone.
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_AUTOCOMPLETE_LINK" desc="A label for a link to settings page to adjust autocomplete suggestion based on Leo">
Adjust autocomplete suggestions
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_CLEAR_HISTORY_DATA_LABEL" desc="The text for settings option">
Leo
<message name="IDS_SETTINGS_AI_CHAT_CLEAR_HISTORY_DATA_LABEL" desc="Label for checkbox to select AI assistant conversations for deletion when deleting browser data">
Leo AI
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_CLEAR_HISTORY_DATA_SUBLABEL" desc="The text for settings option">
Data and chat history
<message name="IDS_SETTINGS_AI_CHAT_CLEAR_HISTORY_DATA_SUBLABEL" desc="Label description for checkbox to select AI assistant conversations for deletion when deleting browser data">
Chat history
</message>
<message name="IDS_SETTINGS_LEO_ASSISTANT_MODEL_SELECTION_LABEL" desc="Label for selecting default model">
Default model for new conversations
Expand Down
3 changes: 3 additions & 0 deletions browser/ai_chat/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ static_library("ai_chat") {
"ai_chat_service_factory.h",
"ai_chat_settings_helper.cc",
"ai_chat_settings_helper.h",
"ai_chat_urls.cc",
"ai_chat_urls.h",
"ai_chat_utils.cc",
"ai_chat_utils.h",
]
Expand All @@ -24,6 +26,7 @@ static_library("ai_chat") {
"//brave/components/ai_chat/core/browser",
"//brave/components/ai_chat/core/common",
"//brave/components/ai_chat/core/common/mojom",
"//brave/components/constants",
"//brave/components/resources:strings_grit",
"//brave/net/base:utils",
"//chrome/browser:browser_process",
Expand Down
3 changes: 2 additions & 1 deletion browser/ai_chat/ai_chat_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ AIChatServiceFactory::BuildServiceInstanceForBrowserContext(
(g_brave_browser_process->process_misc_metrics())
? g_brave_browser_process->process_misc_metrics()->ai_chat_metrics()
: nullptr,
g_browser_process->os_crypt_async(),
context->GetDefaultStoragePartition()
->GetURLLoaderFactoryForBrowserProcess(),
version_info::GetChannelString(chrome::GetChannel()));
version_info::GetChannelString(chrome::GetChannel()), context->GetPath());
}

} // namespace ai_chat
36 changes: 31 additions & 5 deletions browser/ai_chat/ai_chat_throttle_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/ai_chat/content/browser/ai_chat_throttle.h"

#include <memory>

#include "base/test/scoped_feature_list.h"
#include "brave/components/ai_chat/content/browser/ai_chat_throttle.h"
#include "brave/components/ai_chat/core/common/features.h"
#include "brave/components/constants/webui_url_constants.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
Expand All @@ -20,7 +22,9 @@
namespace ai_chat {

namespace {

constexpr char kTestProfileName[] = "TestProfile";

} // namespace

class AiChatThrottleUnitTest : public testing::Test,
Expand Down Expand Up @@ -67,14 +71,13 @@ INSTANTIATE_TEST_SUITE_P(
AiChatThrottleUnitTest,
::testing::Bool(),
[](const testing::TestParamInfo<AiChatThrottleUnitTest::ParamType>& info) {
return base::StringPrintf("History%s",
info.param ? "Enabled" : "Disabled");
return base::StrCat({"History", info.param ? "Enabled" : "Disabled"});
});

TEST_P(AiChatThrottleUnitTest, CancelNavigationFromTab) {
content::MockNavigationHandle test_handle(web_contents());

test_handle.set_url(GURL("chrome-untrusted://chat"));
test_handle.set_url(GURL(kAIChatUIURL));

#if BUILDFLAG(IS_ANDROID)
ui::PageTransition transition = ui::PageTransitionFromInt(
Expand All @@ -99,10 +102,33 @@ TEST_P(AiChatThrottleUnitTest, CancelNavigationFromTab) {
}
}

TEST_P(AiChatThrottleUnitTest, CancelNavigationToFrame) {
content::MockNavigationHandle test_handle(web_contents());

test_handle.set_url(GURL(kAIChatUntrustedConversationUIURL));

#if BUILDFLAG(IS_ANDROID)
ui::PageTransition transition = ui::PageTransitionFromInt(
ui::PageTransition::PAGE_TRANSITION_FROM_ADDRESS_BAR);
#else
ui::PageTransition transition = ui::PageTransitionFromInt(
ui::PageTransition::PAGE_TRANSITION_FROM_ADDRESS_BAR |
ui::PageTransition::PAGE_TRANSITION_TYPED);
#endif

test_handle.set_page_transition(transition);

std::unique_ptr<AiChatThrottle> throttle =
AiChatThrottle::MaybeCreateThrottleFor(&test_handle);

EXPECT_EQ(content::NavigationThrottle::CANCEL_AND_IGNORE,
throttle->WillStartRequest().action());
}

TEST_P(AiChatThrottleUnitTest, AllowNavigationFromPanel) {
content::MockNavigationHandle test_handle(web_contents());

test_handle.set_url(GURL("chrome-untrusted://chat"));
test_handle.set_url(GURL(kAIChatUIURL));

#if BUILDFLAG(IS_ANDROID)
ui::PageTransition transition =
Expand Down
29 changes: 29 additions & 0 deletions browser/ai_chat/ai_chat_urls.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// 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 https://mozilla.org/MPL/2.0/.

#include "brave/browser/ai_chat/ai_chat_urls.h"

#include <string_view>

#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "brave/components/constants/webui_url_constants.h"
#include "url/gurl.h"

namespace ai_chat {

GURL TabAssociatedConversationUrl() {
return GURL(base::StrCat({kAIChatUIURL, "tab"}));
}

GURL ConversationUrl(std::string_view conversation_uuid) {
return GURL(base::StrCat({kAIChatUIURL, conversation_uuid}));
}

std::string_view ConversationUUIDFromURL(const GURL& url) {
return base::TrimString(url.path_piece(), "/", base::TrimPositions::TRIM_ALL);
}

} // namespace ai_chat
29 changes: 29 additions & 0 deletions browser/ai_chat/ai_chat_urls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 The Brave Authors. All rights reserved.
// 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 https://mozilla.org/MPL/2.0/.

#ifndef BRAVE_BROWSER_AI_CHAT_AI_CHAT_URLS_H_
#define BRAVE_BROWSER_AI_CHAT_AI_CHAT_URLS_H_

#include <string_view>

#include "url/gurl.h"

namespace ai_chat {

// UI that will open a conversation associated with the active Tab in the same
// browser window. The conversation will change when that Tab navigates.
GURL TabAssociatedConversationUrl();

// UI that will open to a specific conversation. The conversation will not
// change upon any navigation.
GURL ConversationUrl(std::string_view conversation_uuid);

// Extracts the conversation UUID from a conversation URL or a conversation
// entries iframe
std::string_view ConversationUUIDFromURL(const GURL& url);

} // namespace ai_chat

#endif // BRAVE_BROWSER_AI_CHAT_AI_CHAT_URLS_H_
2 changes: 1 addition & 1 deletion browser/ai_chat/android/ai_chat_utils_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void JNI_BraveLeoUtils_OpenLeoQuery(
// Send the query
conversation->MaybeUnlinkAssociatedContent();
mojom::ConversationTurnPtr turn = mojom::ConversationTurn::New(
mojom::CharacterType::HUMAN, mojom::ActionType::QUERY,
std::nullopt, mojom::CharacterType::HUMAN, mojom::ActionType::QUERY,
mojom::ConversationTurnVisibility::VISIBLE,
base::android::ConvertJavaStringToUTF8(query), std::nullopt, std::nullopt,
base::Time::Now(), std::nullopt, false);
Expand Down
5 changes: 5 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "brave/browser/skus/skus_service_factory.h"
#include "brave/browser/ui/brave_ui_features.h"
#include "brave/browser/ui/webui/ai_chat/ai_chat_ui.h"
#include "brave/browser/ui/webui/ai_chat/ai_chat_untrusted_conversation_ui.h"
#include "brave/browser/ui/webui/brave_rewards/rewards_page_ui.h"
#include "brave/browser/ui/webui/skus_internals_ui.h"
#include "brave/browser/url_sanitizer/url_sanitizer_service_factory.h"
Expand All @@ -49,6 +50,7 @@
#include "brave/components/ai_chat/core/common/mojom/ai_chat.mojom.h"
#include "brave/components/ai_chat/core/common/mojom/page_content_extractor.mojom.h"
#include "brave/components/ai_chat/core/common/mojom/settings_helper.mojom.h"
#include "brave/components/ai_chat/core/common/mojom/untrusted_frame.mojom.h"
#include "brave/components/ai_rewriter/common/buildflags/buildflags.h"
#include "brave/components/body_sniffer/body_sniffer_throttle.h"
#include "brave/components/brave_federated/features.h"
Expand Down Expand Up @@ -620,6 +622,9 @@ void BraveContentBrowserClient::RegisterWebUIInterfaceBrokers(
registry.ForWebUI<AIChatUI>()
.Add<ai_chat::mojom::AIChatUIHandler>()
.Add<ai_chat::mojom::Service>();
registry.ForWebUI<AIChatUntrustedConversationUI>()
.Add<ai_chat::mojom::UntrustedUIHandler>()
.Add<ai_chat::mojom::UntrustedConversationHandler>();
}

#if BUILDFLAG(ENABLE_AI_REWRITER)
Expand Down
32 changes: 21 additions & 11 deletions browser/browsing_data/brave_browsing_data_remover_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <memory>
#include <utility>

#include "brave/browser/ai_chat/ai_chat_service_factory.h"
#include "brave/browser/brave_news/brave_news_controller_factory.h"
#include "brave/components/ai_chat/core/browser/ai_chat_service.h"
#include "brave/components/ai_chat/core/browser/utils.h"
#include "brave/components/ai_chat/core/common/features.h"
#include "brave/components/brave_news/browser/brave_news_controller.h"
Expand All @@ -19,7 +21,9 @@
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/buildflags.h"
#include "components/browsing_data/content/browsing_data_helper.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/browsing_data_remover.h"

BraveBrowsingDataRemoverDelegate::BraveBrowsingDataRemoverDelegate(
content::BrowserContext* browser_context)
Expand Down Expand Up @@ -48,19 +52,31 @@ void BraveBrowsingDataRemoverDelegate::RemoveEmbedderData(
ClearShieldsSettings(delete_begin, delete_end);
}

// Brave News feed cache
if (remove_mask & chrome_browsing_data_remover::DATA_TYPE_HISTORY) {
// Brave News feed cache
if (auto* brave_news_controller =
brave_news::BraveNewsControllerFactory::GetForBrowserContext(
profile_)) {
brave_news_controller->ClearHistory();
}
// AI Chat history but only associated content, not neccessary if we
// are also deleting entire AI Chat history.
if (!(remove_mask &
chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY)) {
ai_chat::AIChatService* ai_chat_service =
ai_chat::AIChatServiceFactory::GetForBrowserContext(profile_);
if (ai_chat_service) {
ai_chat_service->DeleteAssociatedWebContent(delete_begin, delete_end);
}
}
}

if (remove_mask & chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY &&
ai_chat::IsAIChatEnabled(profile_->GetPrefs()) &&
ai_chat::features::IsAIChatHistoryEnabled()) {
ClearAiChatHistory(delete_begin, delete_end);
if (remove_mask & chrome_browsing_data_remover::DATA_TYPE_BRAVE_LEO_HISTORY) {
ai_chat::AIChatService* ai_chat_service =
ai_chat::AIChatServiceFactory::GetForBrowserContext(profile_);
if (ai_chat_service) {
ai_chat_service->DeleteConversations(delete_begin, delete_end);
}
}
}

Expand Down Expand Up @@ -92,9 +108,3 @@ void BraveBrowsingDataRemoverDelegate::ClearShieldsSettings(
}
}
}

void BraveBrowsingDataRemoverDelegate::ClearAiChatHistory(base::Time begin_time,
base::Time end_time) {
// Handler for the Brave Leo History clearing.
// It is prepared for future implementation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class BraveBrowsingDataRemoverDelegate
base::OnceCallback<void(uint64_t)> callback) override;

void ClearShieldsSettings(base::Time begin_time, base::Time end_time);
void ClearAiChatHistory(base::Time begin_time, base::Time end_time);

raw_ptr<Profile> profile_ = nullptr;
base::WeakPtrFactory<BraveBrowsingDataRemoverDelegate> weak_ptr_factory_{
Expand Down
2 changes: 2 additions & 0 deletions browser/browsing_data/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ brave_browser_browsing_data_sources = [

brave_browser_browsing_data_deps = [
"//base",
"//brave/browser/ai_chat",
"//brave/components/ai_chat/core/browser",
"//chrome/browser:browser_process",
"//chrome/browser/browsing_data:constants",
"//chrome/browser/profiles:profile",
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
settings_api::PrefType::kBoolean;

// Leo Assistant pref
(*s_brave_allowlist)[ai_chat::prefs::kStorageEnabled] =
settings_api::PrefType::kBoolean;
(*s_brave_allowlist)[ai_chat::prefs::kBraveChatAutocompleteProviderEnabled] =
settings_api::PrefType::kBoolean;
(*s_brave_allowlist)[ai_chat::prefs::kBraveAIChatContextMenuEnabled] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</settings-checkbox>
<settings-checkbox id="leoResetOnExitCheckbox"
pref="{{prefs.browser.clear_data.brave_leo_on_exit}}"
label="$i18n{leoClearHistoryData}"
sub-label="$i18n{leoClearHistoryDataSubLabel}"
label="$i18n{aiChatClearHistoryData}"
sub-label="$i18n{aiChatClearHistoryDataSubLabel}"
hidden="[[!isLeoAssistantAndHistoryAllowed_]]"
no-set-pref>
</settings-checkbox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Polymer({
},
},

isLeoAssistantAndHistoryAllowed_: {
isAIChatAssistantAndHistoryAllowed_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('isLeoAssistantAllowed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@
<template is="dom-if" if="[[isPremium_]]">
<cr-link-row on-click="openManageAccountPage_" external="true" class="hr" label="$i18n{braveLeoAssistantManageUrlLabel}"></cr-link-row>
</template>
<div class="settings-box " on-click="onResetAssistantData_">
<template is="dom-if" if="[[isHistoryFeatureEnabled_]]">
<settings-toggle-button class="cr-row hr"
pref="{{prefs.brave.ai_chat.storage_enabled}}"
label="$i18n{braveLeoAssistantHistoryPreferenceLabel}"
on-settings-boolean-control-change="onStorageEnabledChange_">
</settings-toggle-button>
<div class="settings-box " on-click="onResetAssistantData_">
<div class="flex cr-padded-text reset-leo">
<div>$i18n{braveLeoAssistantResetAndClearDataLabel}</div>
</div>
</div>
</div>
</template>
Loading

0 comments on commit f9da397

Please sign in to comment.