Skip to content

feat: Add support for metadata value dict parsing#122

Open
vinoo999 wants to merge 5 commits intoa2aproject:mainfrom
vinoo999:metadata-parsing
Open

feat: Add support for metadata value dict parsing#122
vinoo999 wants to merge 5 commits intoa2aproject:mainfrom
vinoo999:metadata-parsing

Conversation

@vinoo999
Copy link
Contributor

@vinoo999 vinoo999 commented Nov 19, 2025

Description

Add support for Metadata parsing in the a2a inspector. Metadata is a map and should be parsed as such in the inspector. This adds support accordingly.

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vinoo999, 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 introduces a significant enhancement to the a2a inspector by enabling it to intelligently parse metadata values. Previously, metadata values were treated as simple strings, but with this change, the system can now detect and parse JSON-formatted values into their native data structures. This improves the accuracy and utility of the inspector when dealing with complex or structured metadata.

Highlights

  • Enhanced Metadata Parsing: The getMapFromList utility function has been updated to support optional JSON parsing of values, allowing the a2a inspector to correctly interpret metadata values that are structured as dictionaries or other JSON types.
  • Flexible Return Type: The return type of getMapFromList was changed from Record<string, string> to Record<string, any> to accommodate the diverse data types that can result from JSON parsing.
  • Robust JSON Handling: The new parsing logic includes a try-catch block, ensuring that if a value cannot be successfully parsed as JSON, it gracefully falls back to being treated as a plain string.
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 adds support for parsing metadata values as JSON objects in the A2A inspector. The changes are a good step forward, but I've identified a critical bug where the parsed JSON object is incorrectly overwritten by its original string value. Additionally, there's a TypeScript type mismatch that will lead to a compilation error. I've provided specific comments and suggestions to address these issues.

@vinoo999 vinoo999 marked this pull request as draft November 19, 2025 10:06
@vinoo999 vinoo999 marked this pull request as ready for review November 19, 2025 10:07
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 adds support for parsing metadata values as JSON objects. The changes look good, but I have a couple of suggestions. First, I've pointed out a type safety issue where changing the return type of getKeyValuePairs to Record<string, any> breaks other parts of the code that expect Record<string, string>. I've suggested using function overloads to fix this. Second, I've suggested a small refactoring to simplify the JSON parsing logic and make it more readable and maintainable. Overall, a good feature addition with a couple of areas for improvement.

Comment on lines +456 to +457
parseJson: boolean = false,
): Record<string, any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Changing the return type to Record<string, any> is too broad and breaks type safety for callers that expect string values, like getCustomHeaders. This will cause a TypeScript error because getCustomHeaders is typed to return Record<string, string>.

A better approach is to use function overloads to specify the return type based on the parseJson parameter. This maintains type safety for all call sites.

You can define the overloads like this before the function implementation:

// Overload signatures
function getKeyValuePairs(
  list: HTMLElement,
  itemSelector: string,
  keySelector: string,
  valueSelector: string,
  parseJson: true,
): Record<string, any>;
function getKeyValuePairs(
  list: HTMLElement,
  itemSelector: string,
  keySelector: string,
  valueSelector: string,
  parseJson?: false | undefined,
): Record<string, string>;
// Implementation
function getKeyValuePairs(
  list: HTMLElement,
  itemSelector: string,
  keySelector: string,
  valueSelector: string,
  parseJson: boolean = false,
): Record<string, any> {
  // ... current implementation
}

This will ensure getCustomHeaders gets a Record<string, string> and getMessageMetadata gets a Record<string, any>.

Comment on lines +468 to +477
if (parseJson) {
try {
acc[key] = JSON.parse(value);
} catch {
// If not valid JSON, keep as string
acc[key] = value;
}
} else {
acc[key] = value;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic can be simplified to avoid repetition. You can declare a variable for the value, attempt to parse it if parseJson is true, and then assign it to the accumulator. This makes the code more concise and easier to read.

          let valueToSet: any = value;
          if (parseJson) {
            try {
              valueToSet = JSON.parse(value);
            } catch {
              // Not valid JSON, so we keep the original string value.
            }
          }
          acc[key] = valueToSet;

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