Accumulates streaming chunks into a final GenerateResult.
Handles two tool call formats:
OpenAI format: Chunked deltas with index, id, function.name, function.arguments
Anthropic format: content_block_start with id+name, then input_json_delta chunks
new()Initialize the aggregator.
SSEAggregator$new(callback)callbackUser callback function: callback(text, done).
on_text_delta()Handle a text content delta.
SSEAggregator$on_text_delta(text)textThe text chunk.
on_reasoning_delta()Handle a reasoning/thinking content delta.
SSEAggregator$on_reasoning_delta(text)textThe reasoning text chunk.
on_reasoning_start()Signal the start of a reasoning block (Anthropic thinking).
SSEAggregator$on_reasoning_start()
on_block_stop()Signal content block stop (closes reasoning if open).
SSEAggregator$on_block_stop()
on_tool_call_delta()Handle OpenAI-format tool call deltas.
SSEAggregator$on_tool_call_delta(tool_calls)tool_callsList of tool call delta objects from the choices delta.
on_tool_start()Handle Anthropic-format tool use block start.
SSEAggregator$on_tool_start(index, id, name, input = NULL)indexBlock index (0-based from API, converted to 1-based internally).
idTool call ID.
nameTool name.
inputInitial input (usually NULL or empty).
on_tool_input_delta()Handle Anthropic-format input_json_delta.
SSEAggregator$on_tool_input_delta(index, partial_json)indexBlock index (0-based from API).
partial_jsonPartial JSON string.
on_finish_reason()Store finish reason.
SSEAggregator$on_finish_reason(reason)reasonThe finish reason string.
on_usage()Store usage information.
SSEAggregator$on_usage(usage)usageUsage list.
on_raw_response()Store last raw response for diagnostics.
SSEAggregator$on_raw_response(response)responseThe raw response data.
on_done()Signal stream completion.
SSEAggregator$on_done()
build_result()Finalize accumulated state into a GenerateResult.
SSEAggregator$build_result()A GenerateResult object.
clone()The objects of this class are cloneable with this method.
SSEAggregator$clone(deep = FALSE)deepWhether to make a deep clone.