Class: ClaudeAgentSDK::SessionMessage
- Inherits:
-
Object
- Object
- ClaudeAgentSDK::SessionMessage
- Defined in:
- lib/claude_agent_sdk/sessions.rb
Overview
A single message from a session transcript
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#parent_tool_use_id ⇒ Object
Returns the value of attribute parent_tool_use_id.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#content_blocks ⇒ Object
Typed content blocks for this message.
-
#initialize(type:, uuid:, session_id:, message:, parent_tool_use_id: nil) ⇒ SessionMessage
constructor
A new instance of SessionMessage.
-
#text ⇒ Object
(also: #to_s)
Concatenated text across every TextBlock in this message.
Constructor Details
#initialize(type:, uuid:, session_id:, message:, parent_tool_use_id: nil) ⇒ SessionMessage
Returns a new instance of SessionMessage.
37 38 39 40 41 42 43 |
# File 'lib/claude_agent_sdk/sessions.rb', line 37 def initialize(type:, uuid:, session_id:, message:, parent_tool_use_id: nil) @type = type @uuid = uuid @session_id = session_id @message = @parent_tool_use_id = parent_tool_use_id end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
35 36 37 |
# File 'lib/claude_agent_sdk/sessions.rb', line 35 def @message end |
#parent_tool_use_id ⇒ Object
Returns the value of attribute parent_tool_use_id.
35 36 37 |
# File 'lib/claude_agent_sdk/sessions.rb', line 35 def parent_tool_use_id @parent_tool_use_id end |
#session_id ⇒ Object
Returns the value of attribute session_id.
35 36 37 |
# File 'lib/claude_agent_sdk/sessions.rb', line 35 def session_id @session_id end |
#type ⇒ Object
Returns the value of attribute type.
35 36 37 |
# File 'lib/claude_agent_sdk/sessions.rb', line 35 def type @type end |
#uuid ⇒ Object
Returns the value of attribute uuid.
35 36 37 |
# File 'lib/claude_agent_sdk/sessions.rb', line 35 def uuid @uuid end |
Instance Method Details
#content_blocks ⇒ Object
Typed content blocks for this message. Each entry is one of TextBlock, ThinkingBlock, ToolUseBlock, ToolResultBlock, or UnknownBlock (for forward-compatibility with newer CLI block types). Returns [] when the message has no array-of-blocks content (nil message, non-Hash message, String content, missing content).
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/claude_agent_sdk/sessions.rb', line 64 def content_blocks return [] unless @message.is_a?(Hash) raw = @message['content'] || @message[:content] return [] unless raw.is_a?(Array) raw.filter_map do |block| MessageParser.parse_content_block(block) if block.is_a?(Hash) end end |
#text ⇒ Object Also known as: to_s
Concatenated text across every TextBlock in this message. Returns “” when the message has no text content (nil message, non-Hash message, empty content, or only non-text blocks).
48 49 50 51 52 53 54 55 |
# File 'lib/claude_agent_sdk/sessions.rb', line 48 def text raw = @message.is_a?(Hash) ? (@message['content'] || @message[:content]) : nil case raw when String then raw when Array then content_blocks.grep(TextBlock).map(&:text).join("\n\n") else '' end end |