Interface NaruStreamHandler

All Known Implementing Classes:
NaruStreamCollector

public interface NaruStreamHandler
Receives model output as it is produced.

Implemented by the actor loop, the renderer and the session writer. All three consume chunks and none of them may branch on whether the model actually streamed: a provider that cannot stream is normalised to the same chunks, just delivered in one batch at the end.

  • Method Details

    • onChunk

      void onChunk(NaruStreamChunk chunk)
      Called once per chunk, in NaruStreamChunk.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.

    • isCancelled

      default boolean isCancelled()
      Whether 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.

      Returns:
      true to stop emitting; remaining chunks are not delivered