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

Function collectSSEEvents

apps/sim/lib/workflows/streaming/streaming.test.ts:46–83  ·  view source on GitHub ↗
(
  stream: ReadableStream<Uint8Array>
)

Source from the content-addressed store, hash-verified

44}
45
46async function collectSSEEvents(
47 stream: ReadableStream<Uint8Array>
48): Promise<Record<string, unknown>[]> {
49 const reader = stream.getReader()
50 const decoder = new TextDecoder()
51 const events: Record<string, unknown>[] = []
52 let buffer = ''
53
54 try {
55 while (true) {
56 const { done, value } = await reader.read()
57 if (done) {
58 buffer += decoder.decode()
59 break
60 }
61 buffer += decoder.decode(value, { stream: true })
62 }
63 } finally {
64 reader.releaseLock()
65 }
66
67 for (const chunk of buffer.split('\n\n')) {
68 if (!chunk.startsWith('data: ')) {
69 continue
70 }
71 const payload = chunk.substring(6)
72 if (payload === '[DONE]') {
73 continue
74 }
75 const event = JSON.parse(payload) as unknown
76 if (event === '[DONE]') {
77 continue
78 }
79 events.push(event as Record<string, unknown>)
80 }
81
82 return events
83}
84
85describe('createStreamingResponse', () => {
86 beforeEach(() => {

Callers 1

streaming.test.tsFile · 0.85

Calls 3

parseMethod · 0.80
readMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected