Class: RubyLLM::BedrockInvoke::BlockCollector
- Inherits:
-
Object
- Object
- RubyLLM::BedrockInvoke::BlockCollector
- Defined in:
- lib/ruby_llm/bedrock_invoke/block_collector.rb
Overview
Reassembles Anthropic content blocks from streaming events.
Two jobs:
- Rebuild the assistant's full ordered content-block array so a response containing tool-search blocks can be replayed verbatim (see RawContent).
- Identify events belonging to server-managed blocks (server_tool_use / tool_search_tool_result) so they can be kept away from RubyLLM's tool-call accumulator — its input_json_delta handling keys nil-id fragments to the latest client tool call, which a server_tool_use block would silently corrupt.
Instance Method Summary collapse
- #content_blocks ⇒ Object
-
#initialize ⇒ BlockCollector
constructor
A new instance of BlockCollector.
- #observe(event) ⇒ Object
- #server_blocks? ⇒ Boolean
-
#suppress?(event) ⇒ Boolean
True for content-block events that belong to a server-managed block.
Constructor Details
#initialize ⇒ BlockCollector
Returns a new instance of BlockCollector.
19 20 21 22 23 24 |
# File 'lib/ruby_llm/bedrock_invoke/block_collector.rb', line 19 def initialize @blocks = {} @json_buffers = {} @server_indexes = {} @saw_server_block = false end |
Instance Method Details
#content_blocks ⇒ Object
46 47 48 |
# File 'lib/ruby_llm/bedrock_invoke/block_collector.rb', line 46 def content_blocks @blocks.keys.sort.map { |index| @blocks[index] } end |
#observe(event) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ruby_llm/bedrock_invoke/block_collector.rb', line 26 def observe(event) case event['type'] when 'content_block_start' then start_block(event) when 'content_block_delta' then apply_delta(event) when 'content_block_stop' then finish_block(event) end end |
#server_blocks? ⇒ Boolean
42 43 44 |
# File 'lib/ruby_llm/bedrock_invoke/block_collector.rb', line 42 def server_blocks? @saw_server_block end |
#suppress?(event) ⇒ Boolean
True for content-block events that belong to a server-managed block.
35 36 37 38 39 40 |
# File 'lib/ruby_llm/bedrock_invoke/block_collector.rb', line 35 def suppress?(event) index = event['index'] return false if index.nil? @server_indexes.key?(index) && event['type'].to_s.start_with?('content_block') end |