Skip to content

Comments

Render protocol diagrams in the UI#17

Closed
venikman wants to merge 1 commit intomainfrom
feature/protocol-diagrams-ui
Closed

Render protocol diagrams in the UI#17
venikman wants to merge 1 commit intomainfrom
feature/protocol-diagrams-ui

Conversation

@venikman
Copy link
Owner

@venikman venikman commented Jan 15, 2026

Summary

  • render protocol bakeoff diagrams in the UI with Mermaid
  • add a comparison matrix alongside the diagrams

Testing

  • deno task lint
  • deno task fmt:check

Summary by CodeRabbit

  • New Features
    • Introduced a Protocol Bakeoff section featuring visual protocol diagrams and a comprehensive comparison matrix across Transport, User input, Rendering, and Security dimensions for multiple protocols.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 15, 2026 17:25
@continue
Copy link

continue bot commented Jan 15, 2026

All Green - Keep your PRs mergeable

Learn more

All Green is an AI agent that automatically:

✅ Addresses code review comments

✅ Fixes failing CI checks

✅ Resolves merge conflicts


Unsubscribe from All Green comments

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

This PR adds Mermaid diagram rendering capabilities to the UI by introducing a new reusable MermaidDiagram component and a "Protocol Bakeoff" section. The changes include the mermaid library dependency, a diagram component with theme support and error handling, protocol data definitions, and responsive styling for diagram display.

Changes

Cohort / File(s) Summary
Dependency Management
src/ui/package.json
Added mermaid dependency (^11.12.2) to enable diagram rendering
Component Implementation
src/ui/src/components/mermaid-diagram.tsx
New reusable React component for rendering Mermaid diagrams with title/subtitle support, theme toggling (light/dark), error handling, and cleanup safety
Protocol Data
src/ui/src/content/protocol-bakeoff.ts
New data module exporting ProtocolDiagram type and constants: protocolDiagrams (array of diagram definitions with code blocks) and protocolMatrix (comparison table across Transport, User input, Rendering, Security dimensions for 4 protocols)
UI Integration
src/ui/src/App.tsx
Integrated Protocol Bakeoff section rendering MermaidDiagram components for each protocol and a comparison matrix table; positioned after overview header
Styling
src/ui/src/styles.css
Added responsive CSS rule for .mermaid-diagram SVG elements (max-width: 100%, height: auto)

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant MermaidDiagram
    participant Mermaid as Mermaid Library
    
    App->>MermaidDiagram: Render with code & theme
    activate MermaidDiagram
    MermaidDiagram->>MermaidDiagram: Generate unique renderId
    MermaidDiagram->>Mermaid: Initialize with config
    MermaidDiagram->>Mermaid: Call mermaid.render(code)
    Mermaid-->>MermaidDiagram: Return SVG
    MermaidDiagram->>MermaidDiagram: Inject SVG into container
    MermaidDiagram->>MermaidDiagram: Handle errors (fallback)
    deactivate MermaidDiagram
    MermaidDiagram-->>App: Rendered diagram display
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Diagrams now dance upon the page,
Mermaid's magic takes center stage!
Protocols compared in flowcharts bright,
Bakeoff results rendered just right! 📊✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Render protocol diagrams in the UI' directly matches the main objective of adding protocol bakeoff diagrams to the UI using Mermaid, and accurately reflects the primary purpose of all changes across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
src/ui/src/components/mermaid-diagram.tsx (2)

34-39: Calling mermaid.initialize() on every render may cause issues.

mermaid.initialize() is designed to be called once. Calling it repeatedly inside useEffect on every theme/code change can lead to unexpected behavior or configuration conflicts. Consider moving initialization outside the effect or memoizing it.

♻️ Suggested refactor
+// Initialize once at module level or use a ref to track initialization
+let initialized = false;
+
 export function MermaidDiagram({
   code,
   title,
   subtitle,
   className,
   theme = "light",
 }: MermaidDiagramProps) {
   const containerRef = useRef<HTMLDivElement>(null);
   const renderId = useMemo(
     () => `mermaid-${Math.random().toString(36).slice(2, 10)}`,
     [],
   );

   useEffect(() => {
     let cancelled = false;
-    mermaid.initialize({
-      ...mermaidConfig,
-      theme: theme === "dark" ? "dark" : "neutral",
-    });
+    // Only initialize once, theme changes require re-render approach
+    if (!initialized) {
+      mermaid.initialize({
+        ...mermaidConfig,
+        theme: theme === "dark" ? "dark" : "neutral",
+      });
+      initialized = true;
+    }

Alternatively, if theme switching at runtime is required, you may need to use Mermaid's mermaid.run() API or re-create the diagram container entirely.


21-86: Missing tests for the new component.

Per the coding guidelines, UI components in src/ui/** should include Playwright tests, and logic changes should include unit tests. Consider adding:

  • Unit tests for the rendering logic and error handling
  • Playwright tests to verify diagram rendering in the UI

Based on coding guidelines for **/src/ui/**/*.{ts,tsx,jsx,js}.

Would you like me to help generate test scaffolding for this component?

src/ui/src/App.tsx (2)

650-658: Consider adding scope attributes for table header accessibility.

Adding scope="col" to <th> elements improves screen reader navigation.

♻️ Suggested improvement
 <thead>
   <tr className="border-b border-border text-left text-xs uppercase tracking-[0.2em] text-muted-foreground">
-    <th className="pb-2 pr-4">Dimension</th>
-    <th className="pb-2 pr-4">Streamdown (A)</th>
-    <th className="pb-2 pr-4">A2UI (B)</th>
-    <th className="pb-2 pr-4">MCP (C)</th>
-    <th className="pb-2">json-render (D)</th>
+    <th scope="col" className="pb-2 pr-4">Dimension</th>
+    <th scope="col" className="pb-2 pr-4">Streamdown (A)</th>
+    <th scope="col" className="pb-2 pr-4">A2UI (B)</th>
+    <th scope="col" className="pb-2 pr-4">MCP (C)</th>
+    <th scope="col" className="pb-2">json-render (D)</th>
   </tr>
 </thead>

617-687: Missing Playwright tests for the new Protocol Bakeoff section.

Per the coding guidelines, UI changes in src/ui/** should include Playwright tests. Consider adding tests to verify:

  • The Protocol Bakeoff section renders correctly
  • Diagrams display without errors
  • Theme switching affects diagram appearance
  • The comparison matrix table displays correctly

Based on coding guidelines for **/src/ui/**/*.{ts,tsx,jsx,js}.

Would you like me to help generate Playwright test scaffolding for this section?


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2c81b2 and 9755623.

⛔ Files ignored due to path filters (1)
  • src/ui/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • src/ui/package.json
  • src/ui/src/App.tsx
  • src/ui/src/components/mermaid-diagram.tsx
  • src/ui/src/content/protocol-bakeoff.ts
  • src/ui/src/styles.css
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Include unit tests for all logic changes

Files:

  • src/ui/src/content/protocol-bakeoff.ts
  • src/ui/src/components/mermaid-diagram.tsx
  • src/ui/src/App.tsx
**/src/ui/**/*.{ts,tsx,jsx,js}

📄 CodeRabbit inference engine (AGENTS.md)

**/src/ui/**/*.{ts,tsx,jsx,js}: Include Playwright tests for all UI changes
Use Figma for design context; reference design tokens and specs from Figma in UI component files

Files:

  • src/ui/src/content/protocol-bakeoff.ts
  • src/ui/src/components/mermaid-diagram.tsx
  • src/ui/src/App.tsx
🧠 Learnings (2)
📚 Learning: 2026-01-15T13:48:27.166Z
Learnt from: CR
Repo: venikman/PromptAgent PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-15T13:48:27.166Z
Learning: Applies to **/src/ui/**/*.{ts,tsx,jsx,js} : Use Figma for design context; reference design tokens and specs from Figma in UI component files

Applied to files:

  • src/ui/src/components/mermaid-diagram.tsx
  • src/ui/src/App.tsx
📚 Learning: 2026-01-15T13:48:27.166Z
Learnt from: CR
Repo: venikman/PromptAgent PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-15T13:48:27.166Z
Learning: Applies to **/src/ui/**/*.{ts,tsx,jsx,js} : Include Playwright tests for all UI changes

Applied to files:

  • src/ui/src/App.tsx
🧬 Code graph analysis (2)
src/ui/src/components/mermaid-diagram.tsx (1)
src/ui/src/lib/utils.ts (1)
  • cn (4-6)
src/ui/src/App.tsx (2)
src/ui/src/content/protocol-bakeoff.ts (2)
  • protocolDiagrams (8-145)
  • protocolMatrix (147-176)
src/ui/src/components/mermaid-diagram.tsx (1)
  • MermaidDiagram (21-87)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Playwright Tests
  • GitHub Check: Playwright Tests
🔇 Additional comments (8)
src/ui/src/styles.css (1)

138-142: LGTM!

The responsive styling for Mermaid diagram SVGs is appropriate and ensures diagrams scale correctly within their containers.

src/ui/src/components/mermaid-diagram.tsx (1)

44-53: LGTM on rendering logic with a minor suggestion.

The rendering logic with cancellation safety is well-implemented. The securityLevel: "strict" in mermaid config ensures SVG output is sanitized before innerHTML assignment.

Consider logging the error to the console in development for easier debugging while keeping the user-facing message generic.

src/ui/src/content/protocol-bakeoff.ts (3)

1-6: LGTM!

The ProtocolDiagram type is well-defined with appropriate fields for the diagram rendering component.


8-145: LGTM on diagram definitions.

The Mermaid diagram code appears syntactically correct for flowchart and sequence diagram types. The structure aligns well with the MermaidDiagram component's expected props.


147-176: LGTM!

The protocol comparison matrix data structure is clean and maps correctly to the table columns rendered in App.tsx.

src/ui/src/App.tsx (2)

37-42: LGTM!

Imports are correctly added for the new MermaidDiagram component and protocol bakeoff data.


632-642: LGTM!

The diagram grid correctly iterates over protocolDiagrams, using stable id values as keys and passing the theme prop for consistent theming.

src/ui/package.json (1)

33-33: Mermaid dependency version confirmed as secure and current.

The mermaid dependency ^11.12.2 is the latest stable version as of January 2026 (released December 2, 2025) with no known vulnerabilities. Prior XSS issues (CVE-2025-54880, CVE-2025-54881) in earlier versions were patched in 11.10.0+, making 11.12.2 secure.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @venikman, 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 UI by integrating interactive protocol diagrams and a comprehensive comparison matrix. By leveraging the Mermaid library, it provides clear visual representations of different protocol scenarios like Streamdown, A2UI, MCP, and json-render, alongside a structured table detailing their key features. This addition aims to improve understanding and reference for these complex systems directly within the application.

Highlights

  • Mermaid Integration: The mermaid library has been added to the UI, enabling the rendering of protocol diagrams directly within the application.
  • Protocol Diagram Display: A new MermaidDiagram component has been introduced to dynamically render various protocol bakeoff diagrams, providing visual explanations of complex flows.
  • Comparison Matrix: A detailed comparison matrix for different protocols (Streamdown, A2UI, MCP, json-render) is now displayed, outlining their transport, user input, rendering, and security characteristics.
  • New Content Module: Dedicated data for protocol diagrams and the comparison matrix has been organized into a new content module (protocol-bakeoff.ts).

🧠 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.

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Mermaid diagram rendering capabilities to the UI to visualize protocol interaction flows for a "protocol bakeoff" comparison (Streamdown, A2UI, MCP, and json-render). It introduces a new React component for rendering Mermaid diagrams, adds protocol diagram definitions and a comparison matrix, and displays them in a new section of the UI.

Changes:

  • Added mermaid library (v11.12.2) as a dependency with its extensive transitive dependencies
  • Created a reusable MermaidDiagram React component with theme support and error handling
  • Added protocol diagram definitions and comparison matrix data in a new content file

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/ui/package.json Added mermaid dependency and reordered shiki dependency
src/ui/package-lock.json Extensive dependency tree additions for mermaid and its 60+ transitive dependencies
src/ui/src/components/mermaid-diagram.tsx New React component for rendering Mermaid diagrams with theme support
src/ui/src/content/protocol-bakeoff.ts New file containing protocol diagram definitions and comparison matrix data
src/ui/src/App.tsx Added new "Protocol Bakeoff" section with diagrams and comparison table
src/ui/src/styles.css Added CSS rule for responsive SVG sizing in Mermaid diagrams
Files not reviewed (1)
  • src/ui/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +39
mermaid.initialize({
...mermaidConfig,
theme: theme === "dark" ? "dark" : "neutral",
});
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

Calling mermaid.initialize() on every render when the theme changes can cause performance issues. Consider moving the initialization outside the useEffect or memoizing it to avoid unnecessary re-initializations of the Mermaid library, especially when multiple diagrams are rendered on the same page.

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +32
const renderId = useMemo(
() => `mermaid-${Math.random().toString(36).slice(2, 10)}`,
[],
);
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

Using Math.random() for generating IDs can potentially cause collisions, especially with multiple diagrams. Consider using a more robust approach like React's useId() hook (available in React 18+) or a library like nanoid, which is already in the project dependencies.

Copilot uses AI. Check for mistakes.
try {
const { svg, bindFunctions } = await mermaid.render(renderId, code);
if (cancelled || !containerRef.current) return;
containerRef.current.innerHTML = svg;
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

Setting innerHTML with SVG content from mermaid.render() could pose XSS risks if the diagram code contains malicious content. While Mermaid's 'strict' securityLevel provides some protection, consider additional sanitization or using DOMPurify (which is already a transitive dependency of mermaid) explicitly to ensure the SVG is safe before injecting it into the DOM.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +6
export type ProtocolDiagram = {
id: string;
title: string;
subtitle: string;
code: string;
};
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The ProtocolDiagram type and protocolMatrix structure lack documentation. Consider adding JSDoc comments to explain the purpose of these types and the expected format of the 'code' field (Mermaid syntax), especially since this is a new content module.

Copilot uses AI. Check for mistakes.
Comment on lines 32 to 34
"media-chrome": "^4.17.2",
"mermaid": "^11.12.2",
"motion": "^12.26.2",
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The shiki dependency was reordered from line 38 to line 39 in the package.json. While this doesn't affect functionality, the change appears unintentional as it's not mentioned in the PR description. Dependencies should maintain a consistent order (alphabetical is preferred) to avoid unnecessary diff noise in version control.

Copilot uses AI. Check for mistakes.
Copy link

@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 Mermaid diagrams and a comparison matrix to the UI for the protocol bakeoff. The implementation is solid, with a new MermaidDiagram component to handle rendering. I've provided a few suggestions to improve the new component's robustness and maintainability, such as using React's useId hook for generating unique IDs, adding error logging for easier debugging, and removing hardcoded styles from the diagram definitions to better support theming.

Comment on lines +29 to +32
const renderId = useMemo(
() => `mermaid-${Math.random().toString(36).slice(2, 10)}`,
[],
);

Choose a reason for hiding this comment

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

medium

For generating unique IDs in React, it's better to use the useId hook, which is available in React 19 and is designed for this purpose. It avoids potential issues with server-side rendering and hydration that can occur with Math.random(). It also makes the intent of the code clearer.

To make this change, you'll also need to update the import statement on line 2 from import { useEffect, useMemo, useRef } from "react"; to import { useEffect, useId, useRef } from "react";.

  const renderId = useId();

Comment on lines +49 to +53
} catch (_error) {
if (!cancelled && containerRef.current) {
containerRef.current.textContent = "Diagram failed to render.";
}
}

Choose a reason for hiding this comment

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

medium

The error from mermaid.render is currently being ignored. It would be beneficial for debugging to log this error to the console. This will help diagnose issues with diagram rendering in the future.

      } catch (error) {
        console.error('Failed to render Mermaid diagram:', error);
        if (!cancelled && containerRef.current) {
          containerRef.current.textContent = 'Diagram failed to render.';
        }
      }

Comment on lines +46 to +49
style A fill:#fef3c7,stroke:#f59e0b
style B fill:#dbeafe,stroke:#3b82f6
style C fill:#dcfce7,stroke:#22c55e
style D fill:#f3e8ff,stroke:#a855f7`,

Choose a reason for hiding this comment

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

medium

These hardcoded style directives will override the Mermaid theme set in the MermaidDiagram component. This can lead to poor contrast, especially in light mode, and makes the diagrams less maintainable if the application's theme colors change. It's better to remove these and let the selected Mermaid theme (dark or neutral) handle the styling for consistency.

@venikman
Copy link
Owner Author

Superseded by #18

@venikman venikman closed this Jan 15, 2026
@venikman venikman deleted the feature/protocol-diagrams-ui branch January 15, 2026 17:31
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.

1 participant