Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AI Chat]: Add TabInformer so the front end can be aware of open tabs #27187

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

fallaciousreasoning
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning commented Jan 10, 2025

Resolves brave/brave-browser#43221

Meta Issue (with more detail): brave/brave-browser#42711

This PR is the first part of a series for adding support for associating a tab with a full page chat. It implements a mojo service for getting information about the currently active tabs/windows. This PR does not make any frontend changes

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

N/A - no user visible changes from this PR

@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Jan 10, 2025
@fallaciousreasoning fallaciousreasoning marked this pull request as draft January 12, 2025 21:13
@fallaciousreasoning fallaciousreasoning marked this pull request as ready for review January 13, 2025 03:04
@fallaciousreasoning fallaciousreasoning requested review from jonathansampson and Douglashdaniel and removed request for Douglashdaniel January 13, 2025 20:59
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@fallaciousreasoning fallaciousreasoning force-pushed the aichat-tabsearch branch 2 times, most recently from c008c69 to 9b8e446 Compare January 14, 2025 02:54
@fallaciousreasoning fallaciousreasoning requested a review from a team as a code owner January 14, 2025 02:54
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work - much nicer than how I achieved similar!

browser/ui/webui/ai_chat/ai_chat_ui.cc Show resolved Hide resolved
components/ai_chat/resources/page/api/index.ts Outdated Show resolved Hide resolved
namespace ai_chat {

inline constexpr char kBraveSearchURLPrefix[] = "search";

inline constexpr auto kAllowedContentSchemes =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved from ai_chat_service.cc's kAllowedSchemes so shouldn't need security review

components/ai_chat/core/common/mojom/ai_chat.mojom Outdated Show resolved Hide resolved
browser/ui/ai_chat/tab_informer.h Show resolved Hide resolved
}

IN_PROC_BROWSER_TEST_F(TabInformerBrowserTest, MultipleWindows) {
AppendTab("https://topos.nz");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😉

Copy link
Contributor

[puLL-Merge] - brave/brave-core@27187

Description

This PR introduces a new feature for the AI Chat functionality in Brave browser. It adds a TabInformer class that tracks and provides information about open tabs and windows. This information can be used to associate tabs with AI chat conversations, allowing for more context-aware interactions.

Changes

Changes

  1. browser/brave_content_browser_client.cc:

    • Added binding for the new TabInformer interface.
  2. browser/ui/ai_chat/tab_informer.cc and tab_informer.h:

    • Implemented the new TabInformer class to track and provide information about open tabs and windows.
  3. browser/ui/webui/ai_chat/ai_chat_ui.cc and ai_chat_ui.h:

    • Added support for the new TabInformer in the AI Chat UI.
  4. components/ai_chat/core/browser/ai_chat_service.cc and ai_chat_service.h:

    • Added a new method AssociateContent to associate tab content with a conversation.
  5. components/ai_chat/core/common/mojom/ai_chat.mojom:

    • Updated the SiteInfo struct to include a content_id field.
    • Added a new AssociateTab method to the AIChatUIHandler interface.
  6. components/ai_chat/core/common/mojom/tab_informer.mojom:

    • Added a new mojom file defining the TabInformer and TabListener interfaces.
  7. components/ai_chat/resources/page/api/index.ts:

    • Updated the TypeScript API to handle tab information and changes.
  8. Various test files:

    • Added and updated tests to cover the new functionality.
sequenceDiagram
    participant UI as AI Chat UI
    participant TabInformer
    participant AIChatService
    participant ConversationHandler

    UI->>TabInformer: AddListener
    TabInformer-->>UI: TabsChanged (initial state)
    UI->>AIChatService: AssociateContent
    AIChatService->>ConversationHandler: SetAssociatedContentDelegate
    TabInformer-->>UI: TabsChanged (on tab updates)
    UI->>AIChatService: AssociateContent (for new/changed tabs)
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AI Chat]: Add service for getting currently open tabs in all windows for the current project
5 participants