Class BaseMediaBlockParser<T extends io.agentscope.core.message.ContentBlock>

java.lang.Object
io.agentscope.core.a2a.agent.message.BaseMediaBlockParser<T>
Type Parameters:
T - the type of content block to parse
All Implemented Interfaces:
ContentBlockParser<T>
Direct Known Subclasses:
AudioBlockParser, ImageBlockParser, VideoBlockParser

public abstract class BaseMediaBlockParser<T extends io.agentscope.core.message.ContentBlock> extends Object implements ContentBlockParser<T>
Abstract base parser for media content blocks to FilePart.

Provides common functionality for parsing Source to FileContent with type:

  • Convert Base64Source to FileWithBytes
  • Convert URLSource to FileWithUri

Due to all FileContent should include FileContent.mimeType(), but Source only Base64Source has Base64Source.getMediaType(), So For URLSource we need to parse URLSource.getUrl() to get FileContent.mimeType().

Source doesn't define `name` field, so we need to generate a random name set to FileContent.name(). Current use UUID to generate a random name.

  • Field Details

    • log

      protected final org.slf4j.Logger log
  • Constructor Details

    • BaseMediaBlockParser

      public BaseMediaBlockParser()
  • Method Details

    • getMediaType

      protected abstract String getMediaType()
      Get the media type for the content block.
      Returns:
      the media type string
    • parseSource

      protected io.a2a.spec.Part<?> parseSource(io.agentscope.core.message.Source source)
      Parse the source from content block to a FilePart.

      If input source is unknown type, return null.

      Parameters:
      source - the source to parse
      Returns:
      the parsed FilePart