accumulate method

Stream<String> accumulate(
  1. Stream<AIStreamChunk> stream
)

Converts a stream of chunks into a stream of accumulated text.

Each emission contains the full text received so far.

Implementation

Stream<String> accumulate(Stream<AIStreamChunk> stream) async* {
  final buffer = StringBuffer();
  await for (final chunk in stream) {
    buffer.write(chunk.text);
    yield buffer.toString();
  }
}