Class ThinkingStatusPublisher

java.lang.Object
io.jmix.aichat.component.messagelist.ThinkingStatusPublisher
All Implemented Interfaces:
Serializable

public class ThinkingStatusPublisher extends Object implements Serializable
The thinking-status feed of an AiMessageList: the ordered account of what the assistant is doing, rendered above the thinking indicator while a generation is in progress.

The feed is append-only. A caller appends with start(String), changes a status only through the handle that returned, drops one with remove(io.jmix.aichat.component.messagelist.ThinkingStatusItem), and wipes the feed with clear(); there is no bulk setter and no way to reorder or replace an entry.

Threading. Statuses are normally published from a background thread (a tool callback). Every method here mutates the server-side feed synchronously and then schedules the client push itself — callers do not wrap anything in UI.access. With no UI attached the model still updates and the push is skipped; the list's attach-time re-push delivers the accumulated feed. Reaching the browser from a background thread additionally requires @Push (or polling) to be configured.

See Also:
  • Field Details

    • list

      protected AiMessageList list
    • items

      protected List<ThinkingStatusItem> items
    • nextId

      protected long nextId
      Monotonic id source. Never reset — including by clear() — so an id cannot be reused while a client row still carries the old one.
  • Constructor Details

    • ThinkingStatusPublisher

      protected ThinkingStatusPublisher(AiMessageList list)
  • Method Details

    • start

      public ThinkingStatusItem start(String text)
      Appends a new in-flight status and returns the handle to it.
      Parameters:
      text - what the status is doing, not null and not blank
      Returns:
      the handle, to be completed through ThinkingStatusItem.complete()
    • remove

      public void remove(ThinkingStatusItem item)
      Drops one status from the feed, detaching its handle. A no-op if the item is not in the feed.
      Parameters:
      item - the status to drop, not null
    • getItems

      public List<ThinkingStatusItem> getItems()
      The statuses of the current generation, in insertion order. An immutable snapshot rather than a live view: the feed is mutated from background threads, and a view would fail the caller's iteration.
      Returns:
      an immutable snapshot of the feed
    • clear

      public void clear()
      Drops every status, detaching every handle.
    • itemChanged

      protected void itemChanged()
      Called by an item that mutated itself, to push the feed to the client.
    • itemsJson

      protected tools.jackson.databind.node.ArrayNode itemsJson()
      Serializes the feed under this publisher's lock, so a concurrent mutation cannot be observed half-written.