Class NaruSseResponseParser
java.lang.Object
net.thevpc.naru.ext.models.stream.NaruSseResponseParser
- All Implemented Interfaces:
NaruStreamResponseParser
- Direct Known Subclasses:
NaruOpenApiStreamParser
Base for protocols whose stream arrives as
text/event-stream.
Handles the transport-shaped work that is identical for every SSE protocol
-- opening the body, splitting frames, stopping on a cancel -- and leaves the
protocol-specific part, onEvent(java.lang.String, java.lang.String), to the subclass. Anthropic's stream
and OpenAI's differ in payload shape but not in framing, and framing is where
the subtle bugs live.
A read that stops early is reported as interrupted rather than as a successful end of stream, so a cancel or a dropped connection cannot be mistaken for a model that finished its thought.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract NaruResponsefinish(boolean interrupted) Assembles the response once reading has stopped.booleanPolled between events, which is where a cancel lands.abstract booleanConsumes one event payload.read(net.thevpc.nuts.net.NHttpResponse response) Consumes the body incrementally and returns the assembled response.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.thevpc.naru.ext.models.stream.NaruStreamResponseParser
hasDeliveredContent
-
Constructor Details
-
NaruSseResponseParser
public NaruSseResponseParser()
-
-
Method Details
-
read
Description copied from interface:NaruStreamResponseParserConsumes the body incrementally and returns the assembled response.Must deliver events as they arrive rather than reading the whole body first: the entire point is that a renderer sees text while the model is still generating it.
- Specified by:
readin interfaceNaruStreamResponseParser- Throws:
IOException
-
onEvent
Consumes one event payload.- Parameters:
name- theevent:field, ornullfor the default typedata- thedata:lines, already rejoined- Returns:
falseto stop reading, which is how a protocol reports a clean end of stream
-
finish
Assembles the response once reading has stopped.- Parameters:
interrupted-truewhen reading stopped before the protocol's own end-of-stream marker
-
isCancelled
public boolean isCancelled()Polled between events, which is where a cancel lands.
-