Package net.thevpc.naru.impl.interaction
Class NaruBufferedStreamWriter
java.lang.Object
net.thevpc.naru.impl.interaction.NaruBufferedStreamWriter
Holds streamed fragments until the stream ends, then reports them as one message.
For an interaction with nowhere to draw incrementally -- a headless session forwarding to an SSE listener, a logger, a test recorder -- a fragment is not a meaningful unit of output. Emitting each token as its own event would give a host hundreds of messages it has to reassemble, and a half-rendered markdown line is worse than none. So fragments are joined per mode and reported once, which is exactly what the batched path used to do.
Buffers are per mode because a single model turn interleaves reasoning and answer: joined into one buffer, a thinking model's output would arrive as a single message with the reasoning glued to the front of the reply.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionnet.thevpc.nuts.text.NMsgappend(NaruLogMode mode, net.thevpc.nuts.text.NMsg fragment, boolean end) Adds a fragment and returns the joined message when that mode has just ended, or null while it is still accumulating.List<Map.Entry<NaruLogMode,net.thevpc.nuts.text.NMsg>> drain()Returns anything still open, for a session that ends mid-stream: without this a cancelled turn would throw away reasoning the model already paid to produce.voidflushAll(NaruInteraction target) Reports anything still open throughtarget, for an interaction that is still willing to write.voidwrite(NaruInteraction target, NaruLogMode mode, net.thevpc.nuts.text.NMsg fragment, boolean end)
-
Constructor Details
-
NaruBufferedStreamWriter
public NaruBufferedStreamWriter()
-
-
Method Details
-
write
public void write(NaruInteraction target, NaruLogMode mode, net.thevpc.nuts.text.NMsg fragment, boolean end) - Parameters:
target- where the finished message goesmode- the mode this fragment belongs toend- whether this is the last fragment for that mode
-
append
public net.thevpc.nuts.text.NMsg append(NaruLogMode mode, net.thevpc.nuts.text.NMsg fragment, boolean end) Adds a fragment and returns the joined message when that mode has just ended, or null while it is still accumulating. The caller decides how the finished message is emitted, which is what lets a closing interaction report it after its ownclosedflag has already shut the normal path. -
drain
Returns anything still open, for a session that ends mid-stream: without this a cancelled turn would throw away reasoning the model already paid to produce. -
flushAll
Reports anything still open throughtarget, for an interaction that is still willing to write.
-