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.
34 35 36 37 38 39 40 |
# File 'lib/claude_agent_sdk/sessions.rb', line 34 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.
32 33 34 |
# File 'lib/claude_agent_sdk/sessions.rb', line 32 def @message end |
#parent_tool_use_id ⇒ Object
Returns the value of attribute parent_tool_use_id.
32 33 34 |
# File 'lib/claude_agent_sdk/sessions.rb', line 32 def parent_tool_use_id @parent_tool_use_id end |
#session_id ⇒ Object
Returns the value of attribute session_id.
32 33 34 |
# File 'lib/claude_agent_sdk/sessions.rb', line 32 def session_id @session_id end |
#type ⇒ Object
Returns the value of attribute type.
32 33 34 |
# File 'lib/claude_agent_sdk/sessions.rb', line 32 def type @type end |
#uuid ⇒ Object
Returns the value of attribute uuid.
32 33 34 |
# File 'lib/claude_agent_sdk/sessions.rb', line 32 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).
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/claude_agent_sdk/sessions.rb', line 61 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).
45 46 47 48 49 50 51 52 |
# File 'lib/claude_agent_sdk/sessions.rb', line 45 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 |