类 URLSource

java.lang.Object
io.agentscope.core.message.Source
io.agentscope.core.message.URLSource

public class URLSource extends Source
Represents URL-based media content.

This source references media files accessible via URLs, supporting both remote HTTP/HTTPS URLs and local file URLs. This approach is preferred when media files are hosted externally or when file size makes Base64 encoding impractical.

Supported URL formats:

  • Remote URLs: https://example.com/image.jpg
  • Local files: file:///absolute/path/to/file.jpg

Using URL sources is more efficient for large media files and allows the system to stream content rather than loading everything into memory.

When the URL has no file extension (e.g. CDN signed URLs), set mimeType explicitly so converters can route the content to the correct media slot without relying on extension-based inference.

  • 构造器详细资料

    • URLSource

      public URLSource(String url, String mimeType)
      Creates a new URL source for JSON deserialization.
      参数:
      url - The URL pointing to the media content
      mimeType - Optional MIME type hint (e.g. "image/jpeg"); may be null
      抛出:
      NullPointerException - if url is null
    • URLSource

      public URLSource(String url)
      Creates a new URL source without a MIME type hint.
      参数:
      url - The URL pointing to the media content
      抛出:
      NullPointerException - if url is null
  • 方法详细资料

    • getUrl

      public String getUrl()
      Gets the URL that points to the media content.
      返回:
      The URL as a string
    • getMimeType

      public String getMimeType()
      Gets the optional MIME type hint for this URL source.

      When present, converters use this value instead of inferring the type from the URL's file extension. Useful for extension-less URLs such as CDN signed links or API-generated media endpoints.

      返回:
      The MIME type (e.g. "image/jpeg"), or null if not set
    • builder

      public static URLSource.Builder builder()
      Creates a new builder for constructing URLSource instances.
      返回:
      A new builder instance