TokenSmoother class

Re-paces a token stream into a steady, typewriter-style character stream.

LLM token streams often arrive in bursts, which makes streamed text jump and stutter. TokenSmoother buffers incoming chunks and releases them one grapheme at a time on a frame timer, with the release rate scaled to the backlog. Lag behind the source is bounded by window.

A chunk for which atomic returns true is never split; it is released whole in a single emission. Use this for in-band markers or control sequences that must not appear half-rendered.

The transformer is single-subscription. Cancelling the output subscription cancels the upstream subscription, so stopping a generation propagates down to the provider.

Inheritance

Constructors

TokenSmoother({Duration tick = const Duration(milliseconds: 16), Duration window = const Duration(milliseconds: 250), int minRelease = 1, AtomicChunkPredicate atomic = _neverAtomic})
Creates a token stream smoother.
const

Properties

atomic → AtomicChunkPredicate
Decides which chunks are emitted whole instead of paced.
final
hashCode → int
The hash code for this object.
no setterinherited
minRelease → int
Minimum graphemes released per tick while the buffer is non-empty.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
tick → Duration
How often buffered output is released. One release budget per tick.
final
window → Duration
Target maximum lag behind the source.
final

Methods

bind(Stream<String> stream) → Stream<String>
Transforms the provided stream.
override
cast<RS, RT>() → StreamTransformer<RS, RT>
Provides a StreamTransformer<RS, RT> view of this stream transformer.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited