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]: Cleanup SiteInfo - now the presence/absence of the struct indicates whether content association is possible #27243

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

Conversation

fallaciousreasoning
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning commented Jan 15, 2025

Resolves brave/brave-browser#43293

The changes are mostly to ai_chat.mojom - everything else is just adapting to the new shape of the API

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 facing changes

@fallaciousreasoning fallaciousreasoning requested a review from a team as a code owner January 15, 2025 00:13
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Jan 15, 2025
metadata_->associated_content->content_type ==
mojom::ContentType::VideoTranscript);
} else {
// TODO: Confirm with @petemill if this is the correct behavior
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@petemill should I delete the content here instead?

// Note: We don't create a new AssociatedContent object here unless one
// doesn't exist. If we generate one with a new UUID the deserializer
// breaks.
// TODO: Confirm with @petemill if I should try and fix this.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was an interesting one - presumably its because we were generating the AssociatedContent once and then changing the detail on it before, so the Id would never change.

I think a slightly better approach here would be to update the Id for the ArchiveContent when we do this, but I wasn't really sure of the implications.

@brave-builds
Copy link
Collaborator

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

Copy link
Contributor

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

Here's my review of the pull request:

Description

This PR refactors the SiteInfo struct to AssociatedContent in the AI Chat feature. It simplifies the data structure by removing redundant fields and adjusting the logic to handle nullable AssociatedContent instead of using a boolean flag for content association possibility.

Changes

Changes

  1. In ai_chat.mojom:

    • Renamed SiteInfo to AssociatedContent
    • Removed hostname and is_content_association_possible fields
    • Made uuid, title, and url non-optional
  2. In ai_chat_database.cc:

    • Updated database operations to work with the new AssociatedContent structure
    • Modified queries and data handling to accommodate the changes
  3. In ai_chat_ui_page_handler.cc and ai_chat_ui_page_handler.h:

    • Updated function signatures and logic to use AssociatedContentPtr instead of SiteInfoPtr
  4. In conversation_handler.cc:

    • Updated logic to handle nullable AssociatedContent instead of checking is_content_association_possible
  5. In various test files:

    • Updated test cases to reflect the new AssociatedContent structure
  6. In UI components (index.tsx files):

    • Updated React components to work with the new AssociatedContent structure
    • Modified conditional rendering based on the presence of AssociatedContent
  7. In iOS-specific files:

    • Updated Objective-C and Swift interfaces to use the new AssociatedContent type
sequenceDiagram
    participant UI as User Interface
    participant CH as ConversationHandler
    participant DB as AIChatDatabase
    participant AC as AssociatedContent

    UI->>CH: Request conversation state
    CH->>DB: Fetch conversation data
    DB->>CH: Return conversation data
    CH->>AC: Create AssociatedContent (if applicable)
    CH->>UI: Return state with AssociatedContent
    UI->>UI: Update UI based on AssociatedContent
Loading

Possible Issues

  • The change from a boolean flag is_content_association_possible to a nullable AssociatedContent might require careful review of all conditionals throughout the codebase to ensure correct behavior.
  • Database schema changes might require a migration strategy for existing user data.

Security Hotspots

No significant security hotspots were identified in this change.

This sequence diagram illustrates the flow of data with the new AssociatedContent structure, showing how it's created and passed through the system.

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]: Clean up the SiteInfo struct
3 participants