Class NaruStreamCollector
- All Implemented Interfaces:
NaruStreamHandler
NaruStreamHandler that keeps what it is given.
Two jobs. It is how the model call reassembles the full answer while the renderer is still being fed fragment by fragment, and it is how a non-streaming provider is turned into a chunk sequence at all -- the whole response is classified and pushed through this, so downstream sees the same list it would have seen from a real stream.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceLocal stand-in forBooleanSupplier, to avoid a JDK-vs-android signature debate. -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionaddDelegate(NaruStreamHandler delegate) Adds a handler to also feed, so rendering can happen while collection happens without either knowing about the other.chunks()voidclear()booleanhas(NaruChunkKind kind) booleanWhether the reader should stop emitting.booleanisTruncated(NaruChunkKind kind) Whether the last chunk of the given kind was cut short, which is how a truncated thinking segment is recognised after the fact.voidonChunk(NaruStreamChunk chunk) Called once per chunk, inNaruStreamChunk.index()order.intsize()text(NaruChunkKind kind) All text of the given kind, concatenated.
-
Constructor Details
-
NaruStreamCollector
public NaruStreamCollector() -
NaruStreamCollector
-
-
Method Details
-
addDelegate
Adds a handler to also feed, so rendering can happen while collection happens without either knowing about the other. -
onChunk
Description copied from interface:NaruStreamHandlerCalled once per chunk, inNaruStreamChunk.index()order.Called on the transport thread, so an implementation that touches the terminal or the session must not block and must be safe to call from another thread than the one that will read the final response.
- Specified by:
onChunkin interfaceNaruStreamHandler
-
isCancelled
public boolean isCancelled()Description copied from interface:NaruStreamHandlerWhether the reader should stop emitting.Polled once per chunk, which is what makes interruption work during a long generation: a cancel lands between two chunks and the reader bails out instead of running to completion. This is the cooperative mechanism -- the transport cannot be aborted mid-socket, so this is the only place a stop can be observed.
- Specified by:
isCancelledin interfaceNaruStreamHandler- Returns:
trueto stop emitting; remaining chunks are not delivered
-
chunks
-
size
public int size() -
text
All text of the given kind, concatenated. This is the reassembly step: a streamed answer is many chunks and only their concatenation is the answer. -
has
-
isTruncated
Whether the last chunk of the given kind was cut short, which is how a truncated thinking segment is recognised after the fact. -
clear
public void clear()
-