Skip to content

ContentPart

Category: Core

Source: content_part.dart

Multimodal content parts that can appear inside a [Message] or a [ToolResult.contentParts].

Three concrete subtypes today:

  • [TextPart] — plain text
  • [ImagePart] — bytes + mime type, used for vision-capable LLMs and surfaced over ACP as image content blocks
  • [ResourceLinkPart] — opaque reference to a resource (URI + metadata). Falls back to a textual rendering for LLMs that don't natively support it; surfaced over ACP as resource_link content blocks for editor/web UIs that can render them as clickable links.

Classes

sealed ContentPart

Constructor

dart
const ContentPart()

Methods

static String textOnly(List<ContentPart> parts)

Concatenates the text of every [TextPart] in [parts]. Image and resource-link parts are skipped — for those, render them according to their type.

static bool hasImages(List<ContentPart> parts)

True if any part is an [ImagePart].

True if any part is a [ResourceLinkPart].

Concatenates [parts] as text, rendering each variant in a way the LLM can read: text passes through; resource_link renders as a markdown link ([name] followed by the uri in parens); image parts are skipped (they need to flow through a separate image-content channel).

TextPart

Constructor

dart
const TextPart(this.text)

Properties

PropertyTypeDescription
textString

ImagePart

Constructor

dart
const ImagePart({required this.bytes, required this.mimeType})

Properties

PropertyTypeDescription
bytesList<int>
mimeTypeString

Methods

String toBase64()

ResourceLinkPart

Reference to an external resource that the agent (or its tools) is pointing the user at — e.g. a URL fetched, a file written, a repository link.

LLM message mappers render this as a textual markdown-link snippet so the model sees something useful. ACP message mappers emit a dedicated resource_link content block so editors / web UIs can render it as an inline link with metadata.

Constructor

dart
const ResourceLinkPart({
    required this.uri,
    this.name,
    this.description,
    this.mimeType,
  })

Properties

PropertyTypeDescription
uriStringWhere the resource lives. Typically http(s)://… or file://….
nameString?Display name for the link (e.g. the page title, the basename). Falls back to uri in textual rendering when null.
descriptionString?Optional human-readable hover/preview text.
mimeTypeString?Optional content type hint — text/html, application/pdf, …

Methods

Markdown-style rendering for LLM payloads that have no resource_link concept.

Released under the MIT License.