MCPcopy Create free account
hub / github.com/google/adk-samples / processSseEventData

Function processSseEventData

python/agents/deep-search/frontend/src/App.tsx:222–283  ·  view source on GitHub ↗
(jsonData: string, aiMessageId: string)

Source from the content-addressed store, hash-verified

220 };
221
222 const processSseEventData = (jsonData: string, aiMessageId: string) => {
223 const { textParts, agent, finalReportWithCitations, functionCall, functionResponse, sourceCount, sources } = extractDataFromSSE(jsonData);
224
225 if (sourceCount > 0) {
226 console.log('[SSE HANDLER] Updating websiteCount. Current sourceCount:', sourceCount);
227 setWebsiteCount(prev => Math.max(prev, sourceCount));
228 }
229
230 if (agent && agent !== currentAgentRef.current) {
231 currentAgentRef.current = agent;
232 }
233
234 if (functionCall) {
235 const functionCallTitle = `Function Call: ${functionCall.name}`;
236 console.log('[SSE HANDLER] Adding Function Call timeline event:', functionCallTitle);
237 setMessageEvents(prev => new Map(prev).set(aiMessageId, [...(prev.get(aiMessageId) || []), {
238 title: functionCallTitle,
239 data: { type: 'functionCall', name: functionCall.name, args: functionCall.args, id: functionCall.id }
240 }]));
241 }
242
243 if (functionResponse) {
244 const functionResponseTitle = `Function Response: ${functionResponse.name}`;
245 console.log('[SSE HANDLER] Adding Function Response timeline event:', functionResponseTitle);
246 setMessageEvents(prev => new Map(prev).set(aiMessageId, [...(prev.get(aiMessageId) || []), {
247 title: functionResponseTitle,
248 data: { type: 'functionResponse', name: functionResponse.name, response: functionResponse.response, id: functionResponse.id }
249 }]));
250 }
251
252 if (textParts.length > 0 && agent !== "report_composer_with_citations") {
253 if (agent !== "interactive_planner_agent") {
254 const eventTitle = getEventTitle(agent);
255 console.log('[SSE HANDLER] Adding Text timeline event for agent:', agent, 'Title:', eventTitle, 'Data:', textParts.join(" "));
256 setMessageEvents(prev => new Map(prev).set(aiMessageId, [...(prev.get(aiMessageId) || []), {
257 title: eventTitle,
258 data: { type: 'text', content: textParts.join(" ") }
259 }]));
260 } else { // interactive_planner_agent text updates the main AI message
261 for (const text of textParts) {
262 accumulatedTextRef.current += text + " ";
263 setMessages(prev => prev.map(msg =>
264 msg.id === aiMessageId ? { ...msg, content: accumulatedTextRef.current.trim(), agent: currentAgentRef.current || msg.agent } : msg
265 ));
266 setDisplayData(accumulatedTextRef.current.trim());
267 }
268 }
269 }
270
271 if (sources) {
272 console.log('[SSE HANDLER] Adding Retrieved Sources timeline event:', sources);
273 setMessageEvents(prev => new Map(prev).set(aiMessageId, [...(prev.get(aiMessageId) || []), {
274 title: "Retrieved Sources", data: { type: 'sources', content: sources }
275 }]));
276 }
277
278 if (agent === "report_composer_with_citations" && finalReportWithCitations) {
279 const finalReportMessageId = Date.now().toString() + "_final";

Callers 1

AppFunction · 0.85

Calls 3

extractDataFromSSEFunction · 0.85
getEventTitleFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected