MCPcopy Create free account
hub / github.com/AGenUI/AGenUI / continueComponentStreaming

Method continueComponentStreaming

core/src/stream/agenui_text_stream_plugin.cpp:74–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74bool TextStreamPlugin::continueComponentStreaming(
75 const std::string& buffer,
76 const std::string& surfaceId, const std::string& version,
77 std::vector<ProtocolStreamExtractor::ParseResult>& outResults,
78 size_t& outParsePosition) {
79
80 // 1. Check whether the component JSON is fully closed
81 size_t endPos = 0;
82 if (ProtocolStreamExtractor::isJsonObjectComplete(buffer, _componentStart, endPos)) {
83 // Component is complete; extract it to collect binding paths
84 std::string component = buffer.substr(_componentStart, endPos - _componentStart + 1);
85 collectBindingPath(component);
86
87 // Cache post-text attributes (e.g., "styles") for textChunk JSON
88 cacheExtraFieldsFromComponent(component);
89
90 // Extract the text close position and compute the final delta
91 size_t closePos = 0;
92 if (isStringValueClosed(buffer, _textValueStart, closePos)) {
93 std::string delta = extractDelta(buffer, _lastSentContentEnd, closePos);
94 if (!delta.empty()) {
95 ProtocolStreamExtractor::ParseResult result;
96 result.type = ProtocolStreamExtractor::ParseResult::Type::ComponentUpdate;
97 result.componentJson = buildAppendTextChunkJson(delta);
98 result.surfaceId = surfaceId;
99 result.version = version;
100 outResults.emplace_back(std::move(result));
101 }
102 }
103
104 outParsePosition = endPos + 1;
105 _isComponentStreaming = false;
106 return false; // Streaming complete
107 }
108
109 // 2. Check whether the text value is closed
110 size_t closePos = 0;
111 if (isStringValueClosed(buffer, _textValueStart, closePos)) {
112 // text value is closed; send the final delta and hand back to normal extraction
113 std::string delta = extractDelta(buffer, _lastSentContentEnd, closePos);
114 if (!delta.empty()) {
115 ProtocolStreamExtractor::ParseResult result;
116 result.type = ProtocolStreamExtractor::ParseResult::Type::ComponentUpdate;
117 result.componentJson = buildAppendTextChunkJson(delta);
118 result.surfaceId = surfaceId;
119 result.version = version;
120 outResults.emplace_back(std::move(result));
121 }
122
123 outParsePosition = _componentStart;
124 _isComponentStreaming = false;
125
126 return false; // Streaming complete (component not yet closed; returned to normal logic)
127 }
128
129 // 3. text value is still growing; extract and deliver the delta
130 std::string delta = extractDelta(buffer, _lastSentContentEnd, std::string::npos);
131 if (delta.empty()) {

Callers 1

driveParserMethod · 0.45

Calls 1

emptyMethod · 0.80

Tested by

no test coverage detected