Claudio.Messages.Response (Claudio v0.5.0)

View Source

Structured response from the Messages API.

Summary

Functions

Converts a raw API response map into a structured Response.

Extracts all MCP tool use requests from the response.

Extracts MCP tool use requests from the response for a specific server.

Extracts all text content from the response.

Extracts all tool use requests from the response.

Types

content_block()

mcp_tool_result_block()

@type mcp_tool_result_block() :: %{
  type: :mcp_tool_result,
  tool_use_id: String.t(),
  server_name: String.t(),
  content: term(),
  is_error: boolean()
}

mcp_tool_use_block()

@type mcp_tool_use_block() :: %{
  type: :mcp_tool_use,
  id: String.t(),
  name: String.t(),
  server_name: String.t(),
  input: map()
}

stop_reason()

@type stop_reason() ::
  :end_turn
  | :max_tokens
  | :stop_sequence
  | :tool_use
  | :pause_turn
  | :refusal
  | :model_context_window_exceeded

t()

@type t() :: %Claudio.Messages.Response{
  content: [content_block()],
  id: String.t(),
  model: String.t(),
  role: String.t(),
  stop_reason: stop_reason() | nil,
  stop_sequence: String.t() | nil,
  type: String.t(),
  usage: usage()
}

text_block()

@type text_block() :: %{type: :text, text: String.t()}

thinking_block()

@type thinking_block() :: %{type: :thinking, thinking: String.t()}

tool_result_block()

@type tool_result_block() :: %{
  type: :tool_result,
  tool_use_id: String.t(),
  content: String.t() | list()
}

tool_use_block()

@type tool_use_block() :: %{
  type: :tool_use,
  id: String.t(),
  name: String.t(),
  input: map()
}

usage()

@type usage() :: %{
  input_tokens: integer(),
  output_tokens: integer(),
  cache_creation_input_tokens: integer() | nil,
  cache_read_input_tokens: integer() | nil
}

Functions

from_map(data)

@spec from_map(map()) :: t()

Converts a raw API response map into a structured Response.

get_mcp_tool_uses(response)

@spec get_mcp_tool_uses(t()) :: [mcp_tool_use_block()]

Extracts all MCP tool use requests from the response.

get_mcp_tool_uses(response, server_name)

@spec get_mcp_tool_uses(t(), String.t()) :: [mcp_tool_use_block()]

Extracts MCP tool use requests from the response for a specific server.

get_text(response)

@spec get_text(t()) :: String.t()

Extracts all text content from the response.

get_tool_uses(response)

@spec get_tool_uses(t()) :: [tool_use_block()]

Extracts all tool use requests from the response.