Skip to content

Commit

Permalink
Persist all conversation and conversation entry data
Browse files Browse the repository at this point in the history
Delete all AI Chat history from settings page
  • Loading branch information
petemill committed Oct 22, 2024
1 parent 8f4d922 commit e24b13a
Show file tree
Hide file tree
Showing 31 changed files with 2,550 additions and 985 deletions.
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
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 @@ -51,7 +51,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
7 changes: 5 additions & 2 deletions browser/browsing_data/brave_browsing_data_remover_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"

#if BUILDFLAG(ENABLE_AI_CHAT)
#include "brave/browser/ai_chat/ai_chat_service_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"
#endif
Expand Down Expand Up @@ -102,7 +104,8 @@ void BraveBrowsingDataRemoverDelegate::ClearShieldsSettings(
#if BUILDFLAG(ENABLE_AI_CHAT)
void BraveBrowsingDataRemoverDelegate::ClearAiChatHistory(base::Time begin_time,
base::Time end_time) {
// Handler for the Brave Leo History clearing.
// It is prepared for future implementation.
// Delete all Leo data
ai_chat::AIChatServiceFactory::GetForBrowserContext(profile_)
->ClearAllHistory();
}
#endif // BUILDFLAG(ENABLE_AI_CHAT)
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include <vector>

#include "base/containers/contains.h"
#include "brave/browser/ai_chat/ai_chat_service_factory.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/misc_metrics/process_misc_metrics.h"
#include "brave/browser/ui/sidebar/sidebar_service_factory.h"
#include "brave/components/ai_chat/core/browser/ai_chat_metrics.h"
#include "brave/components/ai_chat/core/browser/ai_chat_service.h"
#include "brave/components/ai_chat/core/common/pref_names.h"
#include "brave/components/sidebar/browser/sidebar_item.h"
#include "brave/components/sidebar/browser/sidebar_service.h"
Expand Down Expand Up @@ -141,13 +143,13 @@ void BraveLeoAssistantHandler::HandleGetLeoIconVisibility(

void BraveLeoAssistantHandler::HandleResetLeoData(
const base::Value::List& args) {
auto* service = sidebar::SidebarServiceFactory::GetForProfile(profile_);
auto* sidebar_service =
sidebar::SidebarServiceFactory::GetForProfile(profile_);

ShowLeoAssistantIconVisibleIfNot(sidebar_service);

ShowLeoAssistantIconVisibleIfNot(service);
profile_->GetPrefs()->ClearPref(ai_chat::prefs::kLastAcceptedDisclaimer);
g_brave_browser_process->process_misc_metrics()
->ai_chat_metrics()
->RecordReset();
ai_chat::AIChatServiceFactory::GetForBrowserContext(profile_)
->ClearAllHistory();

AllowJavascript();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ChromeAutocompleteProviderClient::OpenLeo(const std::u16string& query) {
// Send the query to the AIChat's backend.
ai_chat::mojom::ConversationTurnPtr turn =
ai_chat::mojom::ConversationTurn::New(
ai_chat::mojom::CharacterType::HUMAN,
std::nullopt, ai_chat::mojom::CharacterType::HUMAN,
ai_chat::mojom::ActionType::QUERY,
ai_chat::mojom::ConversationTurnVisibility::VISIBLE,
base::UTF16ToUTF8(query) /* text */, std::nullopt /* selected_text */,
Expand Down
12 changes: 10 additions & 2 deletions components/ai_chat/core/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ static_library("browser") {
"ai_chat_database.h",
"ai_chat_feedback_api.cc",
"ai_chat_feedback_api.h",
"ai_chat_storage_service.cc",
"ai_chat_storage_service.h",
"ai_chat_metrics.cc",
"ai_chat_metrics.h",
"ai_chat_service.cc",
Expand Down Expand Up @@ -92,6 +90,8 @@ static_library("browser") {
"//components/component_updater",
"//components/component_updater:component_updater_paths",
"//components/keyed_service/core",
"//components/os_crypt/async/browser",
"//components/os_crypt/async/common",
"//components/os_crypt/sync:os_crypt",
"//components/prefs",
"//components/user_prefs",
Expand Down Expand Up @@ -168,6 +168,7 @@ if (!is_ios) {
"//brave/components/skus/common:mojom",
"//components/component_updater:component_updater_paths",
"//components/component_updater:test_support",
"//components/os_crypt/async/browser:test_support",
"//components/os_crypt/sync:test_support",
"//components/prefs:test_support",
"//components/sync_preferences:test_support",
Expand All @@ -176,6 +177,7 @@ if (!is_ios) {
"//services/data_decoder/public/cpp:test_support",
"//services/network:test_support",
"//services/network/public/cpp:cpp",
"//sql:test_support",
"//testing/gtest:gtest",
]
}
Expand All @@ -188,12 +190,18 @@ source_set("test_support") {
"engine/mock_engine_consumer.h",
"engine/mock_remote_completion_client.cc",
"engine/mock_remote_completion_client.h",
"mock_conversation_handler_observer.cc",
"mock_conversation_handler_observer.h",
"test_utils.cc",
"test_utils.h",
]

deps = [
"//brave/components/ai_chat/core/browser",
"//brave/components/ai_chat/core/common/mojom",
"//services/network/public/cpp",
"//testing/gmock",
"//testing/gtest",
]
}

Expand Down
2 changes: 2 additions & 0 deletions components/ai_chat/core/browser/DEPS
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
include_rules = [
"+components/os_crypt/async",
"+services/data_decoder/public",
"+services/network/public",
"+services/network/test",
"+sql",
"+third_party/skia/include",
"+third_party/re2/src/re2",
"+third_party/tflite",
Expand Down
Loading

0 comments on commit e24b13a

Please sign in to comment.