Class AiToolStatusPublisher

java.lang.Object
io.jmix.aitools.tool.AiToolStatusPublisher

@Component("aitls_AiToolStatusPublisher") public class AiToolStatusPublisher extends Object
Lets AI tools surface ephemeral status updates to a status consumer (e.g. the UI).

The callback is placed into the ToolContext by AiConversationChatService under STATUS_UPDATE_CALLBACK. If no callback was provided by the caller (typical for non-UI scenarios), all methods on this publisher are silent no-ops.

Typical tool usage — two-phase publish so the UI can render an in-flight indicator and a result snippet:

 String msg = "Searching customers by name";
 statusPublisher.update(toolContext, msg);
 String result = customerRepo.searchByName(...);   // long-running work
 statusPublisher.complete(toolContext, msg, "found " + result.size());
 
  • Field Details

  • Constructor Details

    • AiToolStatusPublisher

      public AiToolStatusPublisher()
  • Method Details

    • update

      public void update(String message, @Nullable org.springframework.ai.chat.model.ToolContext toolContext)
      Publishes an in-flight status update — "this step has started, no result yet". Sends an AiToolStatusUpdate with a blank resultSnippet.
      Parameters:
      message - status text describing the step that has started
      toolContext - current tool context carrying the UI callback; null (no callback) makes this a no-op
    • complete

      public void complete(String message, @Nullable String snippet, @Nullable org.springframework.ai.chat.model.ToolContext toolContext)
      Publishes the completion of a previously-started step.

      The message must match the one passed to update(String, ToolContext) so the UI can fold the two into a single completed entry. A blank snippet is treated as "nothing to report" and the call is a silent no-op.

      Parameters:
      message - same status text that was passed to update(String, ToolContext)
      snippet - short result of the finished step; blank or null makes this a no-op
      toolContext - current tool context carrying the UI callback; null (no callback) makes this a no-op
    • publish

      public void publish(AiToolStatusUpdate update, @Nullable org.springframework.ai.chat.model.ToolContext toolContext)
      Forwards an arbitrary AiToolStatusUpdate through the status callback.

      Note, prefer:

      which encode the two-phase contract correctly.
      Parameters:
      update - status update to deliver; ignored if its message is blank
      toolContext - current tool context carrying the UI callback; null (no callback) makes this a no-op