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.
- 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>
… but is actually something else
draftResponse was being accumulated from writer partial events but never read anywhere in the codebase. Remove it along with the dead accumulation logic. Co-authored-by: Antigravity <antigravity@google.com>
because there is no duplication there
Separatly process 3 scenarios 1. Last message is not streaming --> append new event 2. Last message is streaming, but event stops streaming --> ADK repeating after stream ends, drop event 3. Last message is streaming and this event is also partial --> append content to last event
- Use optional chaining ?.includes() in AgentMessage.tsx to prevent TypeError when tool.name is null/undefined - Use optional chaining on `last` in chatCache.ts to prevent TypeError when messages array is empty Co-authored-by: Antigravity <antigravity@google.com>
…nd simplify stream initialization logic
Overview
This PR adds Markdown rendering for chat messages and overhauls how ADK stream events are mapped to UI state.
The root problem: ADK streams events that interleave text chunks with tool call parts. The previous model stored a single
textstring per message, which could not represent this interleaved structure nor preserve ordering. This PR replaces it with aparts[]-based model that mirrors ADK's ownContenttype, then wires it up to a streaming state machine that handles partial text accumulation correctly.Fixes #12
Key Changes
1. Type Refactoring —
ChatMessagenow extendsAdkContent(adk.ts)ChatMessageno longer has its ownrole/partsfields. Instead it extendsAdkContent(from the generated OpenAPI types) and adds only UI-specific fields:This makes
ChatMessagea strict superset of what ADK returns, so constructing one from an ADK event is a simple spread — no lossy mapping.2. Streaming State Machine —
applyEventToState(chatCache.ts)The core change. Every incoming ADK SSE event is classified into one of four branches:
event.content.role === 'user'ChatMessageChatMessagepartial: falseisStreaming: false, drop event content (ADK repeats the full text on the final event)partial: trueThe text-concatenation logic (
updatedParts) preserves interleaved structure: a tool call followed by another text chunk results in separate parts, not a collapsed string.applyEventToStateis a pure function (no side effects) — the impureprocessEventIntoCacheis a thin wrapper that callsqueryClient.setQueryData. This also enables reuse inconvertAdkSessionToChatStatefor history loading.startChatStreamno longer pre-inserts an empty placeholderChatMessagebefore the stream begins. TheisStreaming: trueflag onChatSessionStateis sufficient to drive the loading indicator (see §3); the first real event from ADK creates the model message.3. Loading Indicator & Message Filtering in
ChatArea.tsxThe streaming "正在思考中" indicator was moved from individual
AgentMessagecomponents up toChatArea. It is now driven by the session-levelisStreamingflag rather than per-messageisStreaming, and is rendered once below the message list while a stream is active:This avoids the indicator appearing inside a partially-rendered message bubble, and correctly handles the case where a stream starts before any event has arrived (since there's no placeholder message anymore).
ADK also sometimes emits events with
role: 'user'that are actually internal (e.g. function responses). These are suppressed:4. Markdown Rendering —
AgentMessage.tsx&UserMessage.tsxBoth components now iterate
message.parts[]and render each text part throughReactMarkdownwithremark-gfm. Tool call parts (functionCall) are rendered as inline badges showing the tool name + icon.Tailwind CSS v4 plugin syntax (one line in
styles.css):5. Removed Dead Code
draftResponsefield removed fromChatSessionState— it was being accumulated from writer partial events but never read anywhere.startChatStream— the empty{ role: 'model', parts: [] }message inserted before streaming began is no longer needed since the loading indicator is now session-level.6. Dev Tooling
Added React Query Devtools to visualize the TanStack Query cache during development. Visible only in dev mode via the floating button.
Reviewer Guide
Suggested reading order:
src/lib/adk.ts— understand the newChatMessagetypesrc/lib/chatCache.ts,applyEventToState(~line 174) — the streaming state machine is the heart of this PRsrc/components/AgentMessage.tsx— see howparts[]maps to rendered UIsrc/components/ChatArea.tsx— message filtering + session-level loading indicatorsrc/components/UserMessage.tsx— simpler; sameparts[]patternsrc/hooks/useChat.ts— confirmdraftResponseis cleanly gonepackage.json/styles.css— dependency additionsKey invariant to verify: When
event.partial === false,applyEventToStateintentionally discards the event's content (branch 3 above). The reasoning is that ADK sends the complete accumulated text on the final event, but since we've already been appending chunks incrementally, we'd double-count it. Thedocs:commit (a517073) was added specifically to document this assumption.PR originally created by Jules for task 16087018265232926545. Subsequent fixes and refactoring by @MrOrz.