Backplane.AiProtocol.ContentBlock (backplane_ai_protocol v1.10.44)

Copy Markdown

Typed, ordered content.

Opaque reasoning and provider state are preserved as provenance-tagged values; they are never converted into display text.

Responses tool-result images use %{type: :image, data: %{"data" => bytes, "mime_type" => mime, "detail" => detail}}. String-keyed data and mime_type are required: PNG, JPEG, WebP or GIF MIME and valid nonempty base64, either bare or a complete data:<matching MIME>;base64,<payload> URI. The URI is preserved exactly. Optional detail is "auto", "low", "high" or "original"; omission encodes explicit "auto". The Responses codec rejects extra fields, extensions and image reason metadata. Model image/detail support remains provider-owned. Image construction stays bounded and opaque for compatibility with other providers' existing representations; this subset is validated when encoding Responses.

Audio, embedded resources and resource links use bounded, string-keyed data objects. Audio carries MIME plus base64 data or a URI; resources retain URI, MIME and optional text/base64 content; links retain URI and name. Portable annotations and provenance belong in namespaced extensions. Known JSON type tags decode through a fixed whitelist without creating atoms.

User inline PDFs for Anthropic/Google use exactly "uri", "mime_type" set to "application/pdf", and base64 "data" in a resource. Encoding requires empty block/message extensions and 1..10_485_760 decoded bytes per PDF. URI remains canonical-only identity and is explicitly omitted from native inline parts. Constructors retain the general resource contract; encoding checks this subset and caller limits on both individual data maps and their request-wide PDF list. Larger values require the same explicit limits through construction, JSON reload validation/reconstruction and encoding; global defaults stay unchanged.

Summary

Types

kind()

@type kind() ::
  :text
  | :image
  | :audio
  | :resource
  | :resource_link
  | :reasoning
  | :tool_call
  | :refusal
  | :provider_state

t()

@type t() :: %Backplane.AiProtocol.ContentBlock{
  data: term() | nil,
  extensions: map(),
  reason: String.t() | nil,
  state: map() | nil,
  text: String.t() | nil,
  tool_call: Backplane.AiProtocol.ToolCall.t() | nil,
  type: kind()
}

Functions

new(attrs, opts \\ [])

@spec new(map(), keyword()) :: {:ok, t()} | {:error, Backplane.AiProtocol.Error.t()}