ClaudeCode.Message.AssistantMessage (ClaudeCode v0.21.0)

View Source

Represents an assistant message from the Claude CLI.

Assistant messages contain Claude's responses, which can include text, tool use requests, or a combination of both.

Matches the official SDK schema:

{
  type: "assistant",
  uuid: string,
  message: { ... },  # Anthropic SDK Message type
  session_id: string,
  parent_tool_use_id?: string | null,
  error?: "authentication_failed" | "billing_error" | "rate_limit"
          | "invalid_request" | "server_error" | "unknown" | null
}

Summary

Functions

Type guard to check if a value is an AssistantMessage.

Creates a new AssistantMessage from JSON data.

Types

assistant_message_error()

@type assistant_message_error() ::
  :authentication_failed
  | :billing_error
  | :rate_limit
  | :invalid_request
  | :server_error
  | :unknown

t()

@type t() :: %ClaudeCode.Message.AssistantMessage{
  error: assistant_message_error() | nil,
  message: ClaudeCode.Types.message(),
  parent_tool_use_id: String.t() | nil,
  session_id: String.t(),
  type: :assistant,
  uuid: String.t() | nil
}

Functions

assistant_message?(arg1)

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

Type guard to check if a value is an AssistantMessage.

new(json)

@spec new(map()) :: {:ok, t()} | {:error, atom() | tuple()}

Creates a new AssistantMessage from JSON data.

Examples

iex> AssistantMessage.new(%{"type" => "assistant", "message" => %{...}})
{:ok, %AssistantMessage{...}}

iex> AssistantMessage.new(%{"type" => "user"})
{:error, :invalid_message_type}