Chat Accumulator
chat/accumulator
Section titled “chat/accumulator”Classes
Section titled “Classes”MessageAccumulator
Section titled “MessageAccumulator”Defined in: chat/accumulator.ts:27
Converts a stream of AgentEvent objects into a complete ChatMessage. Tracks text, reasoning, and tool call parts with proper status transitions.
Example
Section titled “Example”const acc = new MessageAccumulator();for await (const event of agentEvents) { acc.apply(event); renderMessage(acc.snapshot()); // in-progress UI update}const message = acc.finalize();Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MessageAccumulator(
messageId?):MessageAccumulator
Defined in: chat/accumulator.ts:36
Parameters
Section titled “Parameters”messageId?
Section titled “messageId?”Returns
Section titled “Returns”Accessors
Section titled “Accessors”finalized
Section titled “finalized”Get Signature
Section titled “Get Signature”get finalized():
boolean
Defined in: chat/accumulator.ts:176
Check if the accumulator has been finalized
Returns
Section titled “Returns”boolean
Get Signature
Section titled “Get Signature”get id():
ChatId
Defined in: chat/accumulator.ts:41
Get current message ID
Returns
Section titled “Returns”Methods
Section titled “Methods”apply()
Section titled “apply()”apply(
event):void
Defined in: chat/accumulator.ts:48
Apply an AgentEvent to accumulate into the message
Parameters
Section titled “Parameters”AgentEvent to process
Returns
Section titled “Returns”void
Throws
Section titled “Throws”Error if accumulator is already finalized
finalize()
Section titled “finalize()”finalize():
ChatMessage
Defined in: chat/accumulator.ts:141
Finalize the accumulator and return the complete ChatMessage
Returns
Section titled “Returns”Completed ChatMessage with all parts finalized
Throws
Section titled “Throws”Error if accumulator is already finalized
snapshot()
Section titled “snapshot()”snapshot():
ChatMessage
Defined in: chat/accumulator.ts:124
Get a snapshot of the current accumulated message (for streaming UI)
Returns
Section titled “Returns”ChatMessage with current parts and “streaming” status