Docs / utilities / parseSSEStream

parseSSEStream

utility

Async generator that yields typed StreamEvents from an agent SSE Response.

import { parseSSEStream } from 'flowstack-sdk'

Consumes a streaming fetch Response from an agent endpoint and yields typed StreamEvent objects as they arrive. Iterate it with for await and switch on event.type to handle content deltas, tool lifecycle events, and completion.

Signature

for await (const event of parseSSEStream(response)) { ... }

Parameters

ParamTypeNotesDescription
responseResponserequiredA streaming fetch Response from an agent stream.

Returns

FieldTypeDescription
eventsAsyncGenerator<StreamEvent>Async iterable of parsed stream events.

Examples

Iterate a full SSE stream
for await (const event of parseSSEStream(response)) {
  switch (event.type) {
    case 'content': console.log(event.content); break;
    case 'tool_start': console.log('Tool:', event.tool); break;
    case 'tool_result': console.log('Result:', event.result); break;
    case 'done': console.log('Complete'); break;
  }
}
NoteStreamEvent types: content, delta, text, tool_start, tool_result, tool_error, progress, status, interrupt, done, error.

See also

parseSSELine · processSSEStream · useAgent · post-stream

Source: README.md#streaming-utilities · Also available in llms-full.txt and registry.json.