ClaudeCode.Content (ClaudeCode v0.1.0)

View Source

Utilities for working with content blocks in Claude messages.

Content blocks can be text, tool use requests, or tool results. This module provides functions to parse and work with any content type.

Summary

Functions

Checks if a value is any type of content block.

Returns the type of a content block.

Parses a content block from JSON data based on its type.

Parses a list of content blocks.

Types

Functions

content?(arg1)

@spec content?(any()) :: boolean()

Checks if a value is any type of content block.

content_type(arg1)

@spec content_type(t()) :: :text | :tool_use | :tool_result

Returns the type of a content block.

parse(data)

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

Parses a content block from JSON data based on its type.

Examples

iex> Content.parse(%{"type" => "text", "text" => "Hello"})
{:ok, %Text{type: :text, text: "Hello"}}

iex> Content.parse(%{"type" => "unknown"})
{:error, {:unknown_content_type, "unknown"}}

parse_all(blocks)

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

Parses a list of content blocks.

Returns {:ok, contents} if all blocks parse successfully, or {:error, {:parse_error, index, error}} for the first failure.