Skip to content

v0.16.0

Choose a tag to compare

@ya-luotao ya-luotao released this 21 Apr 16:23
· 702 commits to main since this release

Added

  • #text on every message type that carries content. No more hand-rolling a select { TextBlock }.map(&:text).join in every consumer.
    • AssistantMessage#text — joins text across TextBlocks in the content array.
    • UserMessage#text — handles both String content (plain prompt) and Array-of-blocks content.
    • SessionMessage#text — joins text across parsed content blocks from a historical transcript.
    • #to_s on each message type is aliased to #text, so puts message and string interpolation just work.
    • Non-text blocks (ToolUseBlock, ThinkingBlock, ToolResultBlock, UnknownBlock) intentionally do not answer #text — only TextBlock is textual. The message helpers use Array#grep(TextBlock) to select text blocks.
  • SessionMessage#content_blocks returns typed block objects (TextBlock, ThinkingBlock, ToolUseBlock, ToolResultBlock, UnknownBlock) instead of the raw hash blocks from the JSONL transcript. Unknown block types become UnknownBlock for forward compatibility with newer CLI versions.

Changed

  • Rails Integration / Quick Start / Observability / File Checkpointing README examples dropped the content.select { is_a?(TextBlock) }.map(&:text).join dance in favor of message.text.

Usage

ClaudeAgentSDK.query(prompt: "Hello Claude") do |message|
  puts message.text if message.is_a?(ClaudeAgentSDK::AssistantMessage)
end

Works the same on UserMessage, and on SessionMessage returned by get_session_messages — one contract across live and historical transcripts. Consumers carrying an extract_text(message) / assistant_text(message) helper can delete it.

What's changed

  • #23 feat(messages): #text contract on AssistantMessage / UserMessage / SessionMessage — @chagel

Full Changelog: v0.15.1...v0.16.0


gem install claude-agent-sdk -v 0.16.0