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

Open Leo from search #26082

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Open Leo from search #26082

merged 1 commit into from
Oct 31, 2024

Conversation

yrliou
Copy link
Member

@yrliou yrliou commented Oct 17, 2024

Resolves brave/brave-browser#41711

open_leo_from_search_480p.mov

UI was updated on search side after the above demo video was recorded, it now looks like this, with a "Save chat in Brave Leo" at upper-right corner:
Screenshot 2024-10-30 at 4 13 46 PM

  • Add a new permission for opening Leo from Brave Search
  • Add a navigation throttle to intercept the request for opening Leo from Brave Search (specifically, https://search.brave.com/leo#noncevalue). If the request is from Brave Search (last committed URL) and nonce is valid (identical between the one in URL and the one in nonce property), a permission prompt will be shown by default and Leo side panel would be opened with entries from Brave Search conversations staged in Leo side panel.
  • A side change which removes the limitation of only have staged entries at the beginning of the conversation to accommodate that user could choose to click continue with Leo button in search UI multiple times and not only when there's empty Leo chat history. When need to remove staged entries, for example, when page context is unlinked, all staged entries will be cleared instead of whole chat history.

See Requirements #2 and #3 in https://docs.google.com/document/d/1idelFPpUEcKDNcyKYf3M5yw91tuIddjrlYfpaWEJjNk/edit?tab=t.0 for reference.

S&P review: https://github.com/brave/reviews/issues/1776

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:

  1. Go to search.brave.com with experimental flags enabled.
  2. Type a query and click Answer with AI
  3. Type a follow-up question in search conversation mode UI
  4. Once answer is generated, click "Save chat in Brave Leo" at the upper-right corner.
  5. Check permission prompt is shown, and Leo side panel should be opened when permission is allowed, entries from search.brave.com should be staged in Leo.
  6. Visit brave://settings/content -> Additional permissions -> Leo AI chat, search.brave.com should be in the allow list.
  7. Remove the allow entry in settings UI.
  8. Open a new tab and repeat step 1 to 4.
  9. Permission prompt should be shown again, reject the prompt, Leo panel should not be opened.

Test opt-out case:
Try the feature in a profile that hasn't opted-in to Leo, when the continue with Leo button is clicked, accept the permission prompt, Leo should be opened with opt-in screen with disclaimer, search entries should appear after opt-in.

Test private window:
Try the feature in private window, shouldn't have any actions such as opening Leo or permission prompt.

@yrliou yrliou self-assigned this Oct 17, 2024
@github-actions github-actions bot added CI/storybook-url Deploy storybook and provide a unique URL for each build CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) labels Oct 17, 2024
@yrliou yrliou force-pushed the open_leo_from_search branch 3 times, most recently from dce4a3c to 1f2c4c1 Compare October 19, 2024 00:13
@brave-builds
Copy link
Collaborator

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

@yrliou yrliou force-pushed the open_leo_from_search branch 6 times, most recently from 0c99be2 to 9ef822a Compare October 19, 2024 06:15
@yrliou yrliou marked this pull request as ready for review October 21, 2024 17:17
@yrliou yrliou requested review from a team as code owners October 21, 2024 17:17
Copy link
Collaborator

@cdesouza-chromium cdesouza-chromium left a comment

Choose a reason for hiding this comment

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

Leaving some comments for now. Be back later.

app/brave_settings_strings.grdp Outdated Show resolved Hide resolved
browser/ai_chat/page_content_fetcher_browsertest.cc Outdated Show resolved Hide resolved
browser/ai_chat/page_content_fetcher_browsertest.cc Outdated Show resolved Hide resolved
browser/ai_chat/page_content_fetcher_browsertest.cc Outdated Show resolved Hide resolved
browser/ui/sidebar/sidebar_utils.cc Outdated Show resolved Hide resolved
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 - my review mainly focuses on naming and keeping consistent with "AI Chat" and not "Leo" - sorry!

browser/ui/ai_chat/utils.h Outdated Show resolved Hide resolved
browser/ui/webui/settings/brave_privacy_handler.cc Outdated Show resolved Hide resolved
components/ai_chat/core/common/features.cc Outdated Show resolved Hide resolved
components/resources/permissions_strings.grdp Outdated Show resolved Hide resolved
components/resources/permissions_strings.grdp Outdated Show resolved Hide resolved
test/data/leo/open_leo_button.html Outdated Show resolved Hide resolved
@yrliou yrliou force-pushed the open_leo_from_search branch from 763155e to be1b396 Compare October 30, 2024 03:22
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.

👍

Comment on lines +164 to +172
const RequestType kExcludedTypes[] = {RequestType::kDiskQuota,
RequestType::kMultipleDownloads,
#if BUILDFLAG(IS_ANDROID)
RequestType::kProtectedMediaIdentifier,
RequestType::kProtectedMediaIdentifier,
#else
RequestType::kRegisterProtocolHandler,
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(ENABLE_WIDEVINE)
RequestType::kWidevine
RequestType::kWidevine
Copy link
Member

Choose a reason for hiding this comment

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

nit: what's happened here with whitespace change?

Copy link
Member Author

Choose a reason for hiding this comment

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

vscode auto formatting, seems to be a good format tho.

- Add a new permission for opening Leo from Brave Search
- Add a NavigationThrottle to intercept specific URL requests and open Leo
@yrliou yrliou force-pushed the open_leo_from_search branch from e882251 to b7d48f3 Compare October 31, 2024 19:06
Copy link
Contributor

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

Description

This pull request adds functionality to open Leo AI chat from Brave Search. It includes new permission settings, UI elements, and backend logic to handle the feature. The changes span across multiple components including browser settings, content settings, permissions, and AI chat-related modules.

Possible Issues

  1. The new feature is conditionally compiled based on the ENABLE_AI_CHAT flag. Ensure that this flag is properly set in all relevant build configurations.
  2. The changes touch sensitive areas like permissions and content settings. Thorough testing is needed to ensure no regressions in existing functionality.

Security Hotspots

  1. The new permission context (BraveOpenAIChatPermissionContext) only allows the feature for https://search.brave.com. Ensure this restriction is maintained and not bypassed.
  2. The AIChatBraveSearchThrottle class handles opening the AI chat. Verify that it properly checks permissions and doesn't allow unauthorized access.
Changes

Changes

  1. app/brave_settings_strings.grdp:

    • Added new strings for Leo AI chat settings.
  2. browser/about_flags.cc:

    • Reorganized AI chat feature entries.
    • Added a new feature flag for opening Leo AI chat from Brave Search.
  3. browser/ai_chat/BUILD.gn:

    • Added new test files for AI chat functionality.
  4. browser/ai_chat/ai_chat_brave_search_throttle_browsertest.cc:

    • New browser test for the AI chat Brave Search throttle.
  5. browser/ai_chat/brave_open_ai_chat_permission_context_unittest.cc:

    • New unit tests for the Brave Open AI chat permission context.
  6. browser/brave_content_browser_client.cc:

    • Added logic to create the AI chat Brave Search throttle.
  7. browser/resources/settings/brave_overrides/:

    • Updated various TypeScript files to include new AI chat settings.
  8. browser/ui/ai_chat/utils.cc and utils.h:

    • New utility functions for opening AI chat.
  9. components/ai_chat/:

    • Various updates to AI chat components, including new throttle logic and permission handling.
  10. components/permissions/:

    • Added new permission context for Brave Open AI chat.
  11. chromium_src/:

    • Updated various Chromium files to include new Brave-specific permission types.
  12. test/data/leo/:

    • Added test HTML files for Leo AI chat functionality.

These changes collectively implement the feature to open Leo AI chat from Brave Search, including necessary permissions, settings, and backend logic.

@yrliou yrliou merged commit f9ad5a4 into master Oct 31, 2024
17 checks passed
@yrliou yrliou deleted the open_leo_from_search branch October 31, 2024 21:03
@github-actions github-actions bot added this to the 1.73.x - Nightly milestone Oct 31, 2024
brave-builds added a commit that referenced this pull request Oct 31, 2024
@brave-builds
Copy link
Collaborator

Released in v1.73.66

@fallaciousreasoning
Copy link
Contributor

@yrliou don't know if this is already reported but site settings are failing to load with
image

I think maybe we removed Leo from the name?

@srirambv
Copy link
Contributor

srirambv commented Nov 6, 2024

Verification passed on

Brave 1.73.70 Chromium: 131.0.6778.24 (Official Build) nightly (64-bit)
Revision 4ee1e6a
OS Windows 11 Version 23H2 (Build 22631.4317)
  • Verified steps from PR description
  • Verified enabling search flags and asking a question shows Save chat in Brave Leo
  • Verified clicking on Save chat in Brave Leo opens Leo in side panel
  • Verified if Leo is not enabled/opted-in clicking on Save chat in Brave Leo opens Leo in side panel and shows opt-in disclaimer. Once opted in opening a new chat loads the chat query in Leo
  • Verified the Save chat in Brave Leo option is not shown on private tabs
  • Encountered #42112
Leo Premium Private Tabs Leo Opt-in
26082-Premium.mp4
26082-Private.Tab.mp4
26082-Leo.Opt-in.mp4

kjozwiak pushed a commit that referenced this pull request Nov 6, 2024
* Uplift of #26082 (squashed) to beta

* Fix site settings

---------

Co-authored-by: Jocelyn Liu <[email protected]>
@bsclifton bsclifton modified the milestones: 1.73.x - Nightly, 1.74.x - Nightly Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) CI/storybook-url Deploy storybook and provide a unique URL for each build needs-security-review puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SERP->Leo] Support Save chat in Brave Leo button from Brave Search