MCPcopy Index your code
hub / github.com/simstudioai/sim / flushEvents

Function flushEvents

apps/sim/app/api/copilot/chat/stream/route.ts:325–345  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

323 request.signal.addEventListener('abort', abortListener, { once: true })
324
325 const flushEvents = async () => {
326 const events = await readEvents(streamId, cursor)
327 if (events.length > 0) {
328 logger.debug('[Resume] Flushing events', {
329 streamId,
330 afterCursor: cursor,
331 eventCount: events.length,
332 })
333 }
334 for (const envelope of events) {
335 if (!enqueueEvent(envelope)) {
336 break
337 }
338 totalEventsFlushed += 1
339 cursor = envelope.stream.cursor ?? String(envelope.seq)
340 currentRequestId = extractEnvelopeRequestId(envelope) || currentRequestId
341 if (envelope.type === MothershipStreamV1EventType.complete) {
342 sawTerminalEvent = true
343 }
344 }
345 }
346
347 const emitTerminalIfMissing = (
348 status: MothershipStreamV1CompletionStatus,

Callers 1

startInnerFunction · 0.85

Calls 4

readEventsFunction · 0.90
enqueueEventFunction · 0.85
extractEnvelopeRequestIdFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected