From 988abbecdda316ccffacd07dc982f035680ebf7c Mon Sep 17 00:00:00 2001 From: Pete Miller Date: Mon, 21 Oct 2024 22:19:32 -0700 Subject: [PATCH] build fixes --- browser/ai_chat/ai_chat_throttle_unittest.cc | 4 ++-- .../webui/ai_chat/ai_chat_ui_page_handler.h | 1 + .../ai_chat/core/browser/ai_chat_service.cc | 20 ++----------------- .../core/browser/ai_chat_service_unittest.cc | 2 ++ .../core/browser/conversation_handler.cc | 1 - .../browser/conversation_handler_unittest.cc | 5 ++++- .../ai_chat/core/common/mojom/ai_chat.mojom | 4 +--- .../page/components/header/index.tsx | 2 -- .../page/components/sidebar_nav/index.tsx | 2 +- 9 files changed, 13 insertions(+), 28 deletions(-) diff --git a/browser/ai_chat/ai_chat_throttle_unittest.cc b/browser/ai_chat/ai_chat_throttle_unittest.cc index 75180cd12ba8..aa7dbe8e1412 100644 --- a/browser/ai_chat/ai_chat_throttle_unittest.cc +++ b/browser/ai_chat/ai_chat_throttle_unittest.cc @@ -71,7 +71,7 @@ INSTANTIATE_TEST_SUITE_P( info.param ? "Enabled" : "Disabled"); }); -TEST_F(AiChatThrottleUnitTest, CancelNavigationFromTab) { +TEST_P(AiChatThrottleUnitTest, CancelNavigationFromTab) { content::MockNavigationHandle test_handle(web_contents()); test_handle.set_url(GURL("chrome-untrusted://chat")); @@ -99,7 +99,7 @@ TEST_F(AiChatThrottleUnitTest, CancelNavigationFromTab) { } } -TEST_F(AiChatThrottleUnitTest, AllowNavigationFromPanel) { +TEST_P(AiChatThrottleUnitTest, AllowNavigationFromPanel) { content::MockNavigationHandle test_handle(web_contents()); test_handle.set_url(GURL("chrome-untrusted://chat")); diff --git a/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h b/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h index c1fde595e603..7fc3c89cbe93 100644 --- a/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h +++ b/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h @@ -7,6 +7,7 @@ #define BRAVE_BROWSER_UI_WEBUI_AI_CHAT_AI_CHAT_UI_PAGE_HANDLER_H_ #include +#include #include "base/memory/weak_ptr.h" #include "base/scoped_observation.h" diff --git a/components/ai_chat/core/browser/ai_chat_service.cc b/components/ai_chat/core/browser/ai_chat_service.cc index cba85d97a89b..5a08f57fed59 100644 --- a/components/ai_chat/core/browser/ai_chat_service.cc +++ b/components/ai_chat/core/browser/ai_chat_service.cc @@ -81,7 +81,7 @@ ConversationHandler* AIChatService::CreateConversation() { // Create the conversation metadata { mojom::ConversationPtr conversation = mojom::Conversation::New( - conversation_uuid, "", "", base::Time::Now(), false); + conversation_uuid, "", base::Time::Now(), false); conversations_.insert_or_assign(conversation_uuid, std::move(conversation)); } mojom::Conversation* conversation = @@ -299,12 +299,10 @@ void AIChatService::OnConversationEntriesChanged( CHECK(conversation_it != conversations_.end()); auto& conversation = conversation_it->second; if (!entries.empty()) { - bool notify = false; // First time a new entry has appeared if (!conversation->has_content && entries.size() == 1) { // This conversation is visible once the first response begins conversation->has_content = true; - notify = true; if (ai_chat_metrics_ != nullptr) { if (entries.size() == 1) { ai_chat_metrics_->RecordNewChat(); @@ -315,22 +313,8 @@ void AIChatService::OnConversationEntriesChanged( if (entries.back()->character_type == mojom::CharacterType::HUMAN) { ai_chat_metrics_->RecordNewPrompt(); } - if (entries.size() >= 2) { - if (conversation->summary.size() < 70) { - for (const auto& entry : entries) { - if (entry->character_type == mojom::CharacterType::ASSISTANT && - !entry->text.empty()) { - conversation->summary = entry->text.substr(0, 70); - notify = true; - break; - } - } - } - } - if (notify) { - OnConversationListChanged(); - } } + OnConversationListChanged(); } // TODO(petemill): Persist the entries, but consider receiving finer grained // entry update events. diff --git a/components/ai_chat/core/browser/ai_chat_service_unittest.cc b/components/ai_chat/core/browser/ai_chat_service_unittest.cc index 0f6a9fc0d3bf..b4091522dd86 100644 --- a/components/ai_chat/core/browser/ai_chat_service_unittest.cc +++ b/components/ai_chat/core/browser/ai_chat_service_unittest.cc @@ -169,6 +169,8 @@ class MockConversationHandlerClient : public mojom::ConversationUI { MOCK_METHOD(void, OnFaviconImageDataChanged, (), (override)); + MOCK_METHOD(void, OnConversationDeleted, (), (override)); + private: mojo::Receiver conversation_ui_receiver_{this}; mojo::Remote conversation_handler_remote_; diff --git a/components/ai_chat/core/browser/conversation_handler.cc b/components/ai_chat/core/browser/conversation_handler.cc index 12cae5815538..9234c12c0c69 100644 --- a/components/ai_chat/core/browser/conversation_handler.cc +++ b/components/ai_chat/core/browser/conversation_handler.cc @@ -991,7 +991,6 @@ void ConversationHandler::UpdateOrCreateLastAssistantEntry( return; } - entry->events->push_back(std::move(event)); // Update clients for partial entries but not observers, who will get notified // when we know this is a complete entry. diff --git a/components/ai_chat/core/browser/conversation_handler_unittest.cc b/components/ai_chat/core/browser/conversation_handler_unittest.cc index ee276ca6aec7..20377b76b5c2 100644 --- a/components/ai_chat/core/browser/conversation_handler_unittest.cc +++ b/components/ai_chat/core/browser/conversation_handler_unittest.cc @@ -119,6 +119,8 @@ class MockConversationHandlerClient : public mojom::ConversationUI { MOCK_METHOD(void, OnFaviconImageDataChanged, (), (override)); + MOCK_METHOD(void, OnConversationDeleted, (), (override)); + private: mojo::Receiver conversation_ui_receiver_{this}; mojo::Remote conversation_handler_; @@ -200,7 +202,8 @@ class ConversationHandlerUnitTest : public testing::Test { model_service_.get(), std::move(credential_manager), &prefs_, nullptr, shared_url_loader_factory_, ""); - conversation_ = mojom::Conversation::New("uuid", "title", false); + conversation_ = + mojom::Conversation::New("uuid", "title", base::Time::Now(), false); conversation_handler_ = std::make_unique( conversation_.get(), ai_chat_service_.get(), model_service_.get(), diff --git a/components/ai_chat/core/common/mojom/ai_chat.mojom b/components/ai_chat/core/common/mojom/ai_chat.mojom index 7def6f04218b..29fd611aa4f6 100644 --- a/components/ai_chat/core/common/mojom/ai_chat.mojom +++ b/components/ai_chat/core/common/mojom/ai_chat.mojom @@ -257,9 +257,7 @@ struct Conversation { string uuid; // Set by the LLM or the user string title; - // First few characters of content, used if title isn't set - // or where more context is needed. - string summary; + // Time used for ordering purposes mojo_base.mojom.Time created_time; // If there are entries and the conversation should be selectable bool has_content; diff --git a/components/ai_chat/resources/page/components/header/index.tsx b/components/ai_chat/resources/page/components/header/index.tsx index 290866ef7c1a..bdbca219a333 100644 --- a/components/ai_chat/resources/page/components/header/index.tsx +++ b/components/ai_chat/resources/page/components/header/index.tsx @@ -23,10 +23,8 @@ const Logo = ({ isPremium }: { isPremium: boolean }) =>
const getTitle = (activeConversation?: Conversation) => activeConversation?.title - || activeConversation?.summary || getLocale('conversationListUntitled') - const newChatButtonLabel = getLocale('newChatButtonLabel') const closeButtonLabel = getLocale('closeLabel') const openFullPageButtonLabel = getLocale('openFullPageLabel') diff --git a/components/ai_chat/resources/page/components/sidebar_nav/index.tsx b/components/ai_chat/resources/page/components/sidebar_nav/index.tsx index 198b360325b6..0cf3def56cee 100644 --- a/components/ai_chat/resources/page/components/sidebar_nav/index.tsx +++ b/components/ai_chat/resources/page/components/sidebar_nav/index.tsx @@ -168,7 +168,7 @@ export default function SidebarNav(props: SidebarNavProps) {
) : ( aiChatContext.setEditingConversationId(item.uuid)} onDelete={() => getAPI().Service.deleteConversation(item.uuid)}