ClaudeCode.Content (ClaudeCode v0.36.3)

View Source

Utilities for working with content blocks in Claude messages.

Content blocks can be text, thinking, tool use requests, tool results, server tool invocations, MCP tool interactions, or compaction summaries. 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 delta from a stream event into a typed map.

Types

delta()

@type delta() ::
  %{type: :text_delta, text: String.t()}
  | %{type: :input_json_delta, partial_json: String.t()}
  | %{type: :thinking_delta, thinking: String.t()}
  | %{type: :signature_delta, signature: String.t()}
  | %{type: :citations_delta, citation: map()}
  | %{type: :compaction_delta, content: String.t() | nil}

t()

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
  | :thinking
  | :redacted_thinking
  | :tool_use
  | :tool_result
  | :server_tool_use
  | ClaudeCode.Content.ServerToolResultBlock.server_tool_result_type()
  | :mcp_tool_use
  | :mcp_tool_result
  | :image
  | :document
  | :container_upload
  | :compaction

Returns the type of a content block.

parse_delta(arg1)

@spec parse_delta(map()) :: {:ok, delta()} | {:error, term()}

Parses a content block delta from a stream event into a typed map.

Examples

iex> ClaudeCode.Content.parse_delta(%{"type" => "text_delta", "text" => "Hi"})
{:ok, %{type: :text_delta, text: "Hi"}}

iex> ClaudeCode.Content.parse_delta(%{"type" => "future_delta"})
{:error, {:unknown_delta_type, "future_delta"}}