Skip to content

Conversation

mlopezFC
Copy link
Member

@mlopezFC mlopezFC commented Jul 24, 2025

Close #36
Close #39

Summary by CodeRabbit

  • New Features

    • The chat assistant now supports custom message types for enhanced flexibility.
    • Added customizable avatar support for the chat assistant with default and user-defined options.
    • Introduced message taglines and custom rendering to enrich chat interactions.
  • Bug Fixes

    • Improved type safety to prevent type-related issues.
  • Chores

    • Updated sample and demo code to explicitly specify message types and include avatar customization.

@mlopezFC mlopezFC requested a review from javier-godoy July 24, 2025 20:16
Copy link

coderabbitai bot commented Jul 24, 2025

Caution

Review failed

The pull request is closed.

"""

Walkthrough

The ChatAssistant component was refactored to support generics, allowing it to operate with any type extending Message. Method signatures, internal references, and renderers were updated to use the generic type. An avatar provider feature was added to customize the assistant's avatar. Related demo code was updated to explicitly use the generic parameter and set an avatar provider. Additionally, ChatMessage and CustomMessage classes were introduced or updated to support generics and custom message metadata.

Changes

Files/Paths Change Summary
Core generic refactor and avatar provider
src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java
Made class generic (<T extends Message>), updated method signatures and internals to use T, added avatar provider support and related methods.
Generic ChatMessage update
src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatMessage.java
Made class generic (<T extends Message>), updated constructors and methods to use T.
Message model update
src/main/java/com/flowingcode/vaadin/addons/chatassistant/model/Message.java
Replaced Lombok @Builder with @SuperBuilder to enable builder inheritance.
Demo and test updates for generics and avatar
src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantLazyLoadingDemo.java, src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantDemo.java, src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantMarkdownDemo.java
Changed ChatAssistant instantiation to use explicit generic parameter <Message> or <CustomMessage>, added avatar provider and custom message rendering in demo.
New custom message and chat message classes
src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomMessage.java, src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomChatMessage.java
Added CustomMessage extending Message with additional tagline field and builder; added CustomChatMessage extending generic ChatMessage<CustomMessage> with tagline display.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Allow generic parameter in renderer setter method (#36) ChatAssistant and related methods were generified to use <T extends Message>, including setMessagesRenderer.
Add Avatar Provider (#39) Added avatarProvider field, setAvatarProvider method, and avatar initialization logic in ChatAssistant.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of CustomMessage and CustomChatMessage classes (src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomMessage.java, CustomChatMessage.java) These are test/demo support classes extending the base Message model and are not part of the core requirements but support demonstration of generics and avatar features.

Suggested labels

enhancement

Suggested reviewers

  • javier-godoy
    """

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fdc38b5 and 7e34878.

📒 Files selected for processing (8)
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java (10 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatMessage.java (6 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/model/Message.java (2 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantDemo.java (4 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantLazyLoadingDemo.java (1 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantMarkdownDemo.java (1 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomChatMessage.java (1 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomMessage.java (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch generics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mlopezFC mlopezFC changed the title feat: make ChatAssistant generic to support custom message types Make ChatAssistant generic to support custom message types and add avatar provider support Jul 24, 2025
Copy link
Member

@javier-godoy javier-godoy left a comment

Choose a reason for hiding this comment

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

Note that 620a778 is a breaking change, so the commit message must be feat!: make ChatAssistant generic to support custom message types

From https://github.com/FlowingCode/AddonsInternal/blob/main/pr-process.md#3b-addressing-feedback-on-commit-messages

If a reviewer indicates that the message of an initial non-WIP commit requires rewriting, this feedback is addressed during the consolidation process. No amendment or force-push of already reviewed commits is necessary.

@mlopezFC mlopezFC requested a review from javier-godoy July 25, 2025 16:12
@@ -139,6 +146,11 @@ private void initializeFooter() {
footerContainer = footer;
}

@SuppressWarnings("unchecked")
protected Class<? extends T> getMessageType() {
return (Class<? extends T>) getClass().getTypeParameters()[0].getBounds()[0];
Copy link
Member

Choose a reason for hiding this comment

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

It seems my comment from the previous review didn't posted. This method returns "the upper bound of the first type parameter", which for ChatAssistant is always Message (because T extends Message).

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this method. This was only for throwing an exception in a specific case for a wrong usage of the component.

@@ -139,6 +146,11 @@ private void initializeFooter() {
footerContainer = footer;
}

@SuppressWarnings("unchecked")
protected Class<? extends T> getMessageType() {
Copy link
Member

Choose a reason for hiding this comment

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

Please add javadoc for protected method.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this method. This was only for throwing an exception in a specific case for a wrong usage of the component.

@mlopezFC mlopezFC requested a review from javier-godoy July 28, 2025 15:31
@@ -35,6 +36,7 @@
@SuppressWarnings("serial")
@Getter
@Setter
@AllArgsConstructor
Copy link
Member

Choose a reason for hiding this comment

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

Why is there a need for a public all args constructor? The signature of the constructor is (String, boolea, String, String, LocalDateTime), which is cumbersome (that's why this class had a builder).

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason was because I couldn't extend the class in the demo and use a builder in there also. Fixed with @SuperBuilder, requesting re-review ...

@mlopezFC mlopezFC requested a review from javier-godoy July 29, 2025 21:40
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomMessage.java (1)

16-16: Consider explicit access modifier for clarity.

The tagline field implementation is correct and serves its purpose well for demonstrating custom message metadata. For consistency and clarity, consider adding an explicit access modifier.

-  String tagline;
+  private String tagline;

Since Lombok generates public getters/setters, making the field private follows encapsulation best practices.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab8345 and 156e587.

📒 Files selected for processing (3)
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/model/Message.java (2 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantDemo.java (4 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomMessage.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/model/Message.java
  • src/test/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistantDemo.java
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/resources/META-INF/frontend/react/animated-fab.tsx:0-0
Timestamp: 2025-07-24T13:41:19.117Z
Learning: In the ChatAssistant animated-fab React component (src/main/resources/META-INF/frontend/react/animated-fab.tsx), the Floating Action Button (FAB) appears empty in the React code but gets its icon content from the Avatar Vaadin component, which is inserted via DOM manipulation from the Java backend's initializeAvatar method.
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java:179-186
Timestamp: 2025-07-24T13:40:40.471Z
Learning: In ChatAssistant's initializeAvatar method (src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java), direct DOM manipulation using executeJs is intentionally used to move the Avatar component to be a child of a button that is inside a div within the React-controlled web component structure. This approach is necessary because the target elements are created by React, and standard Vaadin component hierarchy methods cannot be used due to ReactAdapterComponent limitations.
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java:179-186
Timestamp: 2025-07-22T19:52:28.019Z
Learning: When using ReactAdapterComponent with custom React components in ChatAssistant, standard Vaadin component hierarchy methods like add() cannot be used because the component doesn't implement HasComponents, and the DOM structure is controlled by React. Direct DOM manipulation with executeJs may be necessary to integrate Vaadin components (like Avatar) into React-generated DOM structures.
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css:20-28
Timestamp: 2025-07-22T20:00:43.518Z
Learning: In ChatAssistant's CSS (src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css), the double 180-degree rotation trick on both .chat-assistant-resizable-vertical-layout and .chat-assistant-container-vertical-layout is used to move the resize handle from the default bottom-right corner to the upper-left corner. This positioning is more suitable for resizing the chat window since the chat bubble is positioned in the bottom-right part of the viewport.
🔇 Additional comments (1)
src/test/java/com/flowingcode/vaadin/addons/chatassistant/CustomMessage.java (1)

9-14: LGTM! Proper Lombok annotations for inheritance.

The Lombok annotations are correctly configured for a subclass:

  • @SuperBuilder enables builder pattern inheritance
  • @EqualsAndHashCode(callSuper = true) properly includes parent class fields
  • Standard @Getter/@Setter provide necessary accessors

This implementation aligns well with the generic ChatAssistant<T extends Message> design objective.

Copy link
Member

@javier-godoy javier-godoy left a comment

Choose a reason for hiding this comment

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

LGTM, the changes are approved!

As a final step, could you please consolidate your commits by performing a manual interactive rebase? This is necessary because the PR contains two non-WIP commits and several WIP commits, which prevents us from using the standard "Squash and Merge" or "Rebase and Merge" buttons on GitHub.

@mlopezFC mlopezFC merged commit ba5d7a6 into master Jul 30, 2025
2 of 3 checks passed
@mlopezFC mlopezFC deleted the generics branch July 30, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Avatar Provider Allow generic parameter in renderer setter method
2 participants