Implement Markdown support and message parts refactoring#21
Implement Markdown support and message parts refactoring#21
Conversation
- Installed `react-markdown`, `remark-gfm`, and `@tailwindcss/typography`. - Refactored `ChatMessage` type to extend `AdkContent` and use `parts` array as the source of truth. - Updated state management logic in `src/lib/chatCache.ts` to map ADK events to message parts and handle streaming text. - Implemented Markdown rendering in `AgentMessage.tsx` and `UserMessage.tsx` with proper styling using Tailwind CSS Typography. - Configured Tailwind CSS v4 to correctly load the typography plugin. - Verified visual changes and build integrity. Co-authored-by: MrOrz <108608+MrOrz@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the chat interface by introducing Markdown rendering capabilities and a more robust message data model. The core change involves refactoring Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces Markdown support for chat messages and refactors the message data model to use parts, which is a great improvement for handling complex message structures. The implementation is mostly solid, but I've found a few critical issues in the new state update logic (applyEventToState) and in the UI component (AgentMessage) where missing null or undefined checks could lead to runtime errors. I've provided suggestions to fix these. Once these are addressed, this will be a great enhancement.
| {tool.name?.toLowerCase().includes('search') | ||
| ? 'search' | ||
| : tool.name?.toLowerCase().includes('verify') || | ||
| tool.name?.toLowerCase().includes('check') | ||
| ? 'shield' | ||
| : tool.name?.toLowerCase().includes('cofacts') | ||
| ? 'fact_check' | ||
| : 'build'} |
There was a problem hiding this comment.
There's a potential runtime error here. If tool.name is null or undefined, tool.name?.toLowerCase() will evaluate to undefined. Calling .includes() on undefined will then throw a TypeError. You should add a nullish coalescing operator to provide a default empty string to safely call .includes() on.
| {tool.name?.toLowerCase().includes('search') | |
| ? 'search' | |
| : tool.name?.toLowerCase().includes('verify') || | |
| tool.name?.toLowerCase().includes('check') | |
| ? 'shield' | |
| : tool.name?.toLowerCase().includes('cofacts') | |
| ? 'fact_check' | |
| : 'build'} | |
| {(tool.name?.toLowerCase() ?? '').includes('search') | |
| ? 'search' | |
| : (tool.name?.toLowerCase() ?? '').includes('verify') || | |
| (tool.name?.toLowerCase() ?? '').includes('check') | |
| ? 'shield' | |
| : (tool.name?.toLowerCase() ?? '').includes('cofacts') | |
| ? 'fact_check' | |
| : 'build'} |
| if ( | ||
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
| last && | ||
| last.role === 'model' && | ||
| last.isStreaming && | ||
| (last.author ?? 'writer') === (event.author ?? 'writer') | ||
| (last.author || 'writer') === (event.author || 'writer') | ||
| ) { |
There was a problem hiding this comment.
There's a potential runtime error if the messages array is empty. In that case, last would be undefined, and accessing last.role would throw a TypeError. The previous implementation had a check for last being truthy (last && ...), which seems to have been accidentally removed during refactoring. Please add it back to prevent this error.
| if ( | |
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | |
| last && | |
| last.role === 'model' && | |
| last.isStreaming && | |
| (last.author ?? 'writer') === (event.author ?? 'writer') | |
| (last.author || 'writer') === (event.author || 'writer') | |
| ) { | |
| if ( | |
| last && | |
| last.role === 'model' && | |
| last.isStreaming && | |
| (last.author || 'writer') === (event.author || 'writer') | |
| ) { |
src/lib/chatCache.ts
Outdated
| if (event.partial && part.text) { | ||
| // Streaming text: append to last text part if it exists | ||
| const lastPart = updatedParts[updatedParts.length - 1] | ||
| if (lastPart.text !== undefined) { |
There was a problem hiding this comment.
There's a potential runtime error here. If updatedParts is an empty array (which can happen if last.parts is initially empty or undefined), lastPart will be undefined. Accessing lastPart.text will then throw a TypeError. You should add a check to ensure lastPart is not undefined before accessing its properties.
| if (lastPart.text !== undefined) { | |
| if (lastPart && lastPart.text !== undefined) { |
- Refactor `ChatMessage` type to extend `AdkContent` and use `parts` array. - Update `applyEventToState` to preserve order of text and tool calls during streaming. - Integrate `react-markdown` and `remark-gfm` for rendering message content. - Apply `prose` styling from `@tailwindcss/typography`. - Add null check for `lastPart` in streaming logic to prevent `TypeError`. Co-authored-by: MrOrz <108608+MrOrz@users.noreply.github.com>
This PR implements Markdown support for chat messages and refactors the message data model to ensure tool calls and text are rendered in the correct order as received from the ADK stream.
Key changes:
ChatMessagenow extendsAdkContent, usingpartsas the primary data field.applyEventToStateto handle interleaved text and tool calls, including streaming support.react-markdownandremark-gfmfor rendering, styled with@tailwindcss/typography.Fixes #12
PR created automatically by Jules for task 16087018265232926545 started by @MrOrz