Class: ClaudeAgentSDK::UserMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_agent_sdk/types.rb

Overview

User message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, uuid: nil, parent_tool_use_id: nil, tool_use_result: nil) ⇒ UserMessage

Returns a new instance of UserMessage.



120
121
122
123
124
125
# File 'lib/claude_agent_sdk/types.rb', line 120

def initialize(content:, uuid: nil, parent_tool_use_id: nil, tool_use_result: nil)
  @content = content
  @uuid = uuid # Unique identifier for rewind support
  @parent_tool_use_id = parent_tool_use_id
  @tool_use_result = tool_use_result # Tool result data when message is a tool response
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



118
119
120
# File 'lib/claude_agent_sdk/types.rb', line 118

def content
  @content
end

#parent_tool_use_idObject

Returns the value of attribute parent_tool_use_id.



118
119
120
# File 'lib/claude_agent_sdk/types.rb', line 118

def parent_tool_use_id
  @parent_tool_use_id
end

#tool_use_resultObject

Returns the value of attribute tool_use_result.



118
119
120
# File 'lib/claude_agent_sdk/types.rb', line 118

def tool_use_result
  @tool_use_result
end

#uuidObject

Returns the value of attribute uuid.



118
119
120
# File 'lib/claude_agent_sdk/types.rb', line 118

def uuid
  @uuid
end

Instance Method Details

#textObject Also known as: to_s

Concatenated text of this message. Handles both String content (plain-text user prompt) and Array-of-blocks content (typed content). Returns “” when there is no text.



130
131
132
133
134
135
136
# File 'lib/claude_agent_sdk/types.rb', line 130

def text
  case @content
  when String then @content
  when Array then @content.grep(TextBlock).map(&:text).join("\n\n")
  else ''
  end
end