Package io.jmix.aitools.tool
Class AiToolStatusPublisher
java.lang.Object
io.jmix.aitools.tool.AiToolStatusPublisher
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcomplete(String message, @Nullable String snippet, @Nullable org.springframework.ai.chat.model.ToolContext toolContext) Publishes the completion of a previously-started step.voidpublish(AiToolStatusUpdate update, @Nullable org.springframework.ai.chat.model.ToolContext toolContext) Forwards an arbitraryAiToolStatusUpdatethrough the status callback.voidPublishes an in-flight status update — "this step has started, no result yet".
-
Field Details
-
STATUS_UPDATE_CALLBACK
- See Also:
-
-
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 anAiToolStatusUpdatewith a blankresultSnippet.- Parameters:
message- status text describing the step that has startedtoolContext- 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
messagemust match the one passed toupdate(String, ToolContext)so the UI can fold the two into a single completed entry. A blanksnippetis treated as "nothing to report" and the call is a silent no-op.- Parameters:
message- same status text that was passed toupdate(String, ToolContext)snippet- short result of the finished step; blank ornullmakes this a no-optoolContext- 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 arbitraryAiToolStatusUpdatethrough the status callback.Note, prefer:
which encode the two-phase contract correctly.- Parameters:
update- status update to deliver; ignored if its message is blanktoolContext- current tool context carrying the UI callback;null(no callback) makes this a no-op
-