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
imagecontent 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_linkcontent blocks for editor/web UIs that can render them as clickable links.
Classes
sealed ContentPart
Constructor
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].
static bool hasResourceLinks(List<ContentPart> parts)
True if any part is a [ResourceLinkPart].
static String textWithLinks(List<ContentPart> parts)
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
const TextPart(this.text)Properties
| Property | Type | Description |
|---|---|---|
text | String |
ImagePart
Constructor
const ImagePart({required this.bytes, required this.mimeType})Properties
| Property | Type | Description |
|---|---|---|
bytes | List<int> | |
mimeType | String |
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
const ResourceLinkPart({
required this.uri,
this.name,
this.description,
this.mimeType,
})Properties
| Property | Type | Description |
|---|---|---|
uri | String | Where the resource lives. Typically http(s)://… or file://…. |
name | String? | Display name for the link (e.g. the page title, the basename). Falls back to uri in textual rendering when null. |
description | String? | Optional human-readable hover/preview text. |
mimeType | String? | Optional content type hint — text/html, application/pdf, … |
Methods
String toMarkdownLink()
Markdown-style rendering for LLM payloads that have no resource_link concept.