Implementation:AGenUI AGenUI StreamingContentParser
| Knowledge Sources | |
|---|---|
| Domains | Streaming, domain:UI_Framework |
| Last Updated | 2026-10-24 17:21 GMT |
Overview
Streaming pipeline orchestrator that bridges the protocol stream extractor and the surface coordinator, with batched component update dispatch and coalescing flush integration.
Description
The `StreamingContentParser` sits between `ProtocolStreamExtractor` (protocol parsing) and `SurfaceCoordinator` (surface/component/data-model operations). It is created by `SurfaceManager::init()` and holds a pointer to the coordinator.
The three session methods mirror the ISurfaceManager streaming API:
- `processDataBeginning()`: resets the extractor state (`resetState()`).
- `processDataAssembling(data)`: appends data, drives the parser, and dispatches results batched.
- `processDataEnding()`: resets state.
The key method is `dispatchParseResultsBatched()`: it iterates over the `ParseResult` vector, processes `NormalEvent` results individually (routing to `createSurface`, `updateDataModel`, `appendDataModel`, `deleteSurface`), and collects contiguous `ComponentUpdate` results with the same `surfaceId` into a single batch. The batch is merged into one `updateComponents` JSON and sent as a single `coordinator->updateComponents()` call, reducing overhead of component parsing, JSON deserialization, and layout computation.
The parser configures a `CompositeStreamPlugin` (chaining `MarkdownStreamPlugin` and `TextStreamPlugin`) on the extractor, enabling markdown field-level incremental delivery.
Usage
- Internal to SDK: created and called by `SurfaceManager`; not directly instantiated by host code.
- Batching: component updates from the same surface are automatically batched for performance.
Code Reference
Source Location
- Repository: AGenUI
- Header: `core/src/stream/agenui_streaming_content_parser.h`
- Implementation: `core/src/stream/agenui_streaming_content_parser.cpp:L1-179`
Signature
// core/src/stream/agenui_streaming_content_parser.h
namespace agenui {
class StreamingContentParser {
public:
explicit StreamingContentParser(SurfaceCoordinator* coordinator);
~StreamingContentParser();
bool start();
void stop();
void processDataBeginning();
void processDataAssembling(const std::string& data);
void processDataEnding();
private:
void dispatchParseResultsBatched(
const std::vector<ProtocolStreamExtractor::ParseResult>& results);
void processNormalEvent(const ProtocolStreamExtractor::ParseResult& result);
void sendSingleComponentUpdate(const std::string& componentJson,
const std::string& surfaceId,
const std::string& version);
void sendBatchedComponentUpdate(
const std::vector<ProtocolStreamExtractor::ParseResult>& results,
size_t start, size_t end);
void resetState();
SurfaceCoordinator* _coordinator;
ProtocolStreamExtractor _extractor;
std::unique_ptr<MarkdownStreamPlugin> _markdownPlugin;
std::unique_ptr<TextStreamPlugin> _textPlugin;
std::unique_ptr<CompositeStreamPlugin> _compositePlugin;
};
} // namespace agenui
Import
#include "stream/agenui_streaming_content_parser.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| coordinator | `SurfaceCoordinator*` | Yes | Surface coordinator for dispatching parsed results |
| data | `const std::string&` | Yes | Text chunk from LLM stream |
Outputs
| Name | Type | Description |
|---|---|---|
| NormalEvent dispatch | Routes to coordinator->createSurface/updateDataModel/appendDataModel/deleteSurface | |
| ComponentUpdate dispatch | Batched or single coordinator->updateComponents call |
Usage Examples
Internal Pipeline Flow (SDK Internal)
// Created by SurfaceManager::init()
auto* parser = new StreamingContentParser(coordinator);
parser->start();
// On beginTextStream()
parser->processDataBeginning();
// On receiveTextChunk(data)
parser->processDataAssembling(data);
// → _extractor.appendData(data)
// → _extractor.driveParser()
// → dispatchParseResultsBatched(results)
// → NormalEvent → coordinator->createSurface(json)
// → ComponentUpdate batch → coordinator->updateComponents(mergedJson)
// On endTextStream()
parser->processDataEnding();
// → resetState() → _extractor.reset()
Related Pages
Implements Principle
- Principle:AGenUI_AGenUI_Incremental_Stream_Parsing
- Principle:AGenUI_AGenUI_Batch_Coalescing_Flush_System