Skip to content

Conversation

@bustosjuan
Copy link

Description

This PR introduces a new feature to the A2A Inspector's frontend chat interface: the ability to render images sent as base64-encoded strings directly within artifact-update messages.

Context

The A2A Inspector helps developers debug A2A agents. Agents often return visual artifacts, like plots, which can be encoded directly in the payload using base64.

Problem Addressed

Currently, if an agent sends an image artifact using the bytes field (base64) within a file part, the inspector displays a generic "File received (image/png): Open Link" message. This forces the developer to manually copy the base64 data from the raw JSON (viewable in the debug console or message modal) and decode it externally to see the image. This process is cumbersome and disrupts the debugging workflow.

Solution Implemented

The frontend TypeScript code (frontend/src/script.ts) handling incoming agent_response events for artifact-update has been updated. It now checks if a file part contains both a bytes field and an image mimeType.

If these conditions are met, the code dynamically constructs an <img> tag with a data: URI source (data:[mimeType];base64,[bytes]) and renders it directly in the chat message bubble. Basic styling ensures the image fits within the message bounds. The file.name field is used for the alt text. Existing logic for handling URIs or other part types remains unchanged.

Benefits

  • Improved User Experience: Developers can now immediately see image artifacts sent by agents directly within the chat flow. ✨
  • Faster Debugging: Eliminates the need for manual decoding of base64 image data, speeding up the inspection process. ⏱️
  • Enhanced Visualization: Makes the inspector more effective for agents that rely on visual outputs. 📊

Testing Done

  • Tested by connecting to an A2A agent known to return artifact-update messages containing image data encoded in the file.bytes field (base64) with mimeType: "image/png".
  • Sent commands to the agent that trigger the image artifact response.
  • Verified that the image was successfully rendered inline within the chat message in the A2A Inspector UI, replacing the previous "Open Link" text.
  • Confirmed that other artifact parts (like preceding text) were still displayed correctly.
  • Checked the browser's developer console for any errors during rendering.

(Make sure to check the boxes in the actual PR template on GitHub)

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary) (Likely not necessary for this change)

Updates frontend/src/script.ts to handle artifact updates
containing file parts with base64 data (`bytes` field) and an
image mimeType.

Constructs a data URI and renders an <img> tag to display the
image inline, improving usability for agents returning visual data.
@bustosjuan bustosjuan requested a review from a team October 22, 2025 15:55
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @bustosjuan, 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 A2A Inspector's frontend by enabling the direct rendering of base64-encoded images within artifact-update messages. Previously, users had to manually decode these images, which was a cumbersome process. The implemented solution dynamically creates <img> tags from base64 data, providing a seamless and efficient way for developers to visualize agent-generated artifacts, thereby improving the overall debugging workflow and user experience. It also includes minor security and usability refinements to the chat interface.

Highlights

  • Inline Image Rendering: The A2A Inspector's frontend now directly renders base64-encoded images within artifact-update messages, eliminating the need for manual decoding and improving the debugging workflow.
  • Enhanced AgentResponseEvent Type: The TypeScript interface for AgentResponseEvent has been updated to include optional bytes and name properties within the file part, accommodating base64 image data and providing descriptive alt text.
  • Improved User Experience: Developers can now immediately view visual artifacts like plots directly in the chat interface, streamlining the debugging process for A2A agents and enhancing visualization.
  • Security and Usability Enhancements: The addMessageToChat function now re-sanitizes HTML content using DOMPurify.sanitize for an extra layer of security, and clicking on rendered images no longer triggers the raw JSON modal, improving interaction.
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
Contributor

@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 a feature to render base64 images directly in the A2A Inspector's frontend chat interface within artifact-update messages. The code changes involve modifying the AgentResponseEvent interface to include bytes and name properties for file parts, updating the artifact-update case in the event listener to handle base64 image rendering, adding a requiresHtmlRendering flag, and modifying the appendMessage function to sanitize HTML content. I have identified a potential security issue related to sanitizing the mime type and suggest adding a missing break statement in the switch case.

refactor(frontend): Use regex validation for image MIME types

Replaces DOMPurify sanitization with regex validation for image
MIME types used in base64 data URIs, addressing review feedback.

Ensures only known safe image types (png, jpeg, gif, webp, svg+xml, bmp)
are rendered inline, preventing potential manipulation or errors from
overly strict sanitization. Uses the validated MIME type directly.
DOMPurify is still used for sanitizing displayed text like alt attributes
and fallback messages.
@holtskinner
Copy link
Member

@bustosjuan Can you resolve the merge conflict?

Resolved conflicts in frontend/src/script.ts by adopting main's
FileContent type refactor while retaining the new regex-based
validation and rendering logic for base64 images.
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.

2 participants