Normandy.Components.ContentBlock.Text (normandy v0.6.0)

View Source

Represents a text content block inside a multimodal message.

Used as part of a list of content blocks in Normandy.Components.Message when a message mixes text with images or documents.

Cache control

An optional cache_control field carries an Anthropic prompt-cache breakpoint annotation that the adapter ships verbatim on the wire. Use with_cache/1 for the default ephemeral type, or with_cache/2 for a custom map (e.g. %{"type" => "ephemeral", "ttl" => "1h"}). Atom keys are accepted and stringified at serialization time.

Summary

Functions

Builds a text content block from a string.

Converts the block into the Anthropic/Claudio content-block map shape (string keys). Includes cache_control only when set.

Annotates this block with an ephemeral cache breakpoint.

Annotates this block with a caller-supplied cache_control map.

Types

t()

@type t() :: %Normandy.Components.ContentBlock.Text{
  __meta__: term(),
  cache_control: map() | nil,
  text: String.t()
}

Functions

new(text)

@spec new(String.t()) :: t()

Builds a text content block from a string.

to_claudio(text)

@spec to_claudio(t()) :: %{required(String.t()) => term()}

Converts the block into the Anthropic/Claudio content-block map shape (string keys). Includes cache_control only when set.

with_cache(block)

@spec with_cache(t()) :: t()

Annotates this block with an ephemeral cache breakpoint.

Equivalent to with_cache(block, %{"type" => "ephemeral"}).

with_cache(block, cache_control)

@spec with_cache(t(), map()) :: t()

Annotates this block with a caller-supplied cache_control map.

Atom keys are accepted; they are stringified when serialized.