Class NaruStreamInteraction
- All Implemented Interfaces:
NaruInteraction
This is the one a server embeds. A web front end hands each session a listener that
pushes NaruOutput onto an SSE stream or a websocket, and answers
NaruInputRequests whenever the user submits a line — possibly from a different
process, minutes later.
Nothing is dropped on the floor
An input request is published to anNaruStreamInteraction.InputListener and then held until it is
delivered or cancelled, because there is no reader thread to pick it up. That is the whole
point: the host owns the lifecycle, and the core waits. A host that never answers leaves
the task blocked, which is the honest outcome and is preferable to inventing a default
answer.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceReceives the input requests this interaction wants answered.static interfaceReceives every piece of session output, in emission order per session. -
Field Summary
Fields inherited from interface net.thevpc.naru.api.agent.NaruInteraction
NAME_STREAM, NAME_TERMINAL -
Constructor Summary
ConstructorsConstructorDescriptionNaruStreamInteraction(NaruStreamInteraction.OutputListener listener, NaruStreamInteraction.InputListener inputListener) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the interaction and fails any request still waiting, so a host shutting the session down unblocks its workers instead of leaving them parked.name()voidopen(NaruSession session) voidrequestInput(NaruInputRequest request) Hands the request to the host and returns immediately.withInputListener(NaruStreamInteraction.InputListener inputListener) voidwrite(NaruLogMode mode, net.thevpc.nuts.text.NMsg message) voidwriteStream(NaruLogMode mode, net.thevpc.nuts.text.NMsg fragment, boolean end) Joins streamed fragments and reports them as one output when the stream ends.
-
Constructor Details
-
NaruStreamInteraction
-
NaruStreamInteraction
public NaruStreamInteraction(NaruStreamInteraction.OutputListener listener, NaruStreamInteraction.InputListener inputListener)
-
-
Method Details
-
withInputListener
-
name
- Specified by:
namein interfaceNaruInteraction
-
open
- Specified by:
openin interfaceNaruInteraction
-
requestInput
Hands the request to the host and returns immediately.Nothing is blocked here. The task is already parked in
BLOCKED_ON_INPUTand simply stays there until the host callsNaruInputRequest.deliver(String)orNaruInputRequest.cancel(String), so the answer may come from any thread, any later request, or another process.- Specified by:
requestInputin interfaceNaruInteraction
-
write
- Specified by:
writein interfaceNaruInteraction
-
writeStream
Joins streamed fragments and reports them as one output when the stream ends.A host consuming
NaruOutputgets whole messages and can render them as complete units -- a half-sentence per event would be useless to it. If it wants token-level updates it should consume the model's stream directly; this interaction is the log of what happened, not the wire.- Specified by:
writeStreamin interfaceNaruInteraction
-
close
public void close()Closes the interaction and fails any request still waiting, so a host shutting the session down unblocks its workers instead of leaving them parked.- Specified by:
closein interfaceNaruInteraction
-