Skip to content

Implement Markdown support and message parts refactoring#21

Draft
MrOrz wants to merge 2 commits intomasterfrom
feature/markdown-support-16087018265232926545
Draft

Implement Markdown support and message parts refactoring#21
MrOrz wants to merge 2 commits intomasterfrom
feature/markdown-support-16087018265232926545

Conversation

@MrOrz
Copy link
Copy Markdown
Member

@MrOrz MrOrz commented Mar 15, 2026

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:

  • Type Refactoring: ChatMessage now extends AdkContent, using parts as the primary data field.
  • State Logic: Updated applyEventToState to handle interleaved text and tool calls, including streaming support.
  • UI Enhancement: Integrated react-markdown and remark-gfm for rendering, styled with @tailwindcss/typography.
  • Configuration: Added the typography plugin to the Tailwind CSS v4 setup.

Fixes #12


PR created automatically by Jules for task 16087018265232926545 started by @MrOrz

- 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>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 ChatMessage to use a parts array, which allows for the accurate and ordered display of both text and tool calls, especially during streaming. This refactoring improves the user experience by providing richer message formatting and ensuring that complex agent responses, including interleaved text and tool executions, are presented coherently.

Highlights

  • Markdown Support: Integrated react-markdown and remark-gfm for rendering Markdown in chat messages, enhancing text formatting capabilities.
  • Message Data Model Refactoring: ChatMessage now utilizes a parts array to represent interleaved text and tool calls, ensuring their correct sequential rendering.
  • Enhanced Streaming Logic: Updated applyEventToState to accurately handle streaming updates for both text (appending to the last text part) and tool calls within the new parts array structure.
  • UI Integration: Chat message components (AgentMessage, UserMessage) were adapted to render content from the parts array, leveraging the new Markdown capabilities and Tailwind CSS typography.
  • Styling: The @tailwindcss/typography plugin was added to enable rich, readable styling for Markdown content.

🧠 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
  • package.json
    • Added @tailwindcss/typography for styling Markdown content.
    • Added react-markdown for rendering Markdown.
    • Added remark-gfm for GitHub Flavored Markdown support.
  • pnpm-lock.yaml
    • Updated lockfile to include new dependencies and their transitive dependencies for Markdown rendering and styling.
  • src/components/AgentMessage.tsx
    • Imported useMemo, ReactMarkdown, and remarkGfm.
    • Computed fullText from message.parts for feedback and clipboard actions.
    • Replaced direct message.text rendering with an iteration over message.parts, applying ReactMarkdown for text content and rendering tool badges for function calls.
    • Adjusted feedback button visibility and styling to use fullText and occupy full width.
  • src/components/UserMessage.tsx
    • Imported ReactMarkdown and remarkGfm.
    • Updated message rendering to iterate over message.parts and apply ReactMarkdown for text content.
  • src/lib/adk.ts
    • Modified ChatMessage interface to extend AdkContent, removing direct text and toolCalls properties.
    • Removed the ToolCall interface as its functionality is now integrated into AdkContent.parts.
  • src/lib/chatCache.ts
    • Removed ToolCall import.
    • Updated startChatStream to initialize streaming messages with an empty parts array.
    • Modified sendChatMessage to encapsulate user input text within a parts array.
    • Refactored applyEventToState to process event.content.parts directly, handling streaming text by appending to the last text part and integrating tool calls as distinct parts, ensuring correct message construction and deduplication based on parts content.
  • src/styles.css
    • Added @plugin "@tailwindcss/typography"; to enable Tailwind CSS typography styles.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +60 to +67
{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'}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

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.

Suggested change
{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'}

Comment on lines 221 to 225
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')
) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

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.

Suggested change
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')
) {

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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

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.

Suggested change
if (lastPart.text !== undefined) {
if (lastPart && lastPart.text !== undefined) {

@MrOrz MrOrz marked this pull request as ready for review March 15, 2026 09:13
@MrOrz MrOrz marked this pull request as draft March 15, 2026 09:27
- 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>
@cofacts cofacts deleted a comment from claude bot Mar 16, 2026
@cofacts cofacts deleted a comment from claude bot Mar 17, 2026
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.

Markdown support

1 participant