package main import "context" // streamChunkSubject is the bus subject the loop's OnStream closure publishes // each token delta to. The gateway hub subscribes to ws.> and re-broadcasts it // as a ws.stream_chunk frame to every client. const streamChunkSubject = "ws.stream_chunk" // streamChunk is the loop's OnStream callback. It publishes one token delta to // the gateway's streaming subject so the hub fans it out to every client as a // ws.stream_chunk frame. It is a no-op when no bus is wired and never blocks the // loop: bus.Publish is asynchronous and a full per-subscription buffer drops the // event rather than stalling the model stream. func (a *app) streamChunk(delta string) { if a.bus == nil { return } if err := a.bus.Publish(context.Background(), streamChunkSubject, map[string]any{"delta": delta}); err != nil { a.log.Warn("stream chunk publish", "err", err) } }