MingaClaudeBridge.Wire.Block (minga_claude_bridge v0.1.0)

Copy Markdown View Source

Content blocks of Anthropic messages, as a tagged sum type.

Blocks appear in assistant and user message content and in content_block_start stream events. Known block types decode to a tagged tuple. Any other block type, such as image or server_tool_use, decodes to {:other, map} and encodes back unchanged, so the bridge can pass blocks through without understanding them.

In content_block_start, a tool_use block carries an empty input; the arguments follow as input_json_delta fragments. A thinking block there carries an empty thinking and the text follows as thinking_delta fragments.

Summary

Types

t()

Content of a tool_result block: a string or nested content blocks.

Functions

Decodes message content. A string is shorthand for one text block, as in the Messages API.

Decodes one wire content block.

Encodes one content block as a JSON-ready map.

Types

t()

@type t() ::
  {:text, text :: String.t()}
  | {:thinking, thinking :: String.t(), signature :: String.t() | nil}
  | {:redacted_thinking, data :: String.t()}
  | {:tool_use, id :: String.t(), name :: String.t(), input :: map()}
  | {:tool_result, tool_use_id :: String.t(), content :: tool_result_content(),
     is_error :: boolean()}
  | {:other, MingaClaudeBridge.Wire.Field.json_map()}

tool_result_content()

@type tool_result_content() :: String.t() | [t()]

Content of a tool_result block: a string or nested content blocks.

Functions

content_from_wire(text)

@spec content_from_wire(term()) :: {:ok, [t()]} | :error

Decodes message content. A string is shorthand for one text block, as in the Messages API.

from_wire(map)

@spec from_wire(term()) :: {:ok, t()} | :error

Decodes one wire content block.

to_wire(arg)

@spec to_wire(t()) :: MingaClaudeBridge.Wire.Field.json_map()

Encodes one content block as a JSON-ready map.