ClaudeCode.Content (ClaudeCode v0.1.0)
View SourceUtilities 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
@type t() :: ClaudeCode.Content.Text.t() | ClaudeCode.Content.ToolUse.t() | ClaudeCode.Content.ToolResult.t()
Functions
Checks if a value is any type of content block.
@spec content_type(t()) :: :text | :tool_use | :tool_result
Returns the type of a content block.
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"}}
Parses a list of content blocks.
Returns {:ok, contents} if all blocks parse successfully, or {:error, {:parse_error, index, error}} for the first failure.