Skip to content

Agent Zero AI framework

upgrade tool extension hook to generic get_tool_message_handler

Alessandro338c86a05811
diff --git a/docs/agents/AGENTS.plugins.md b/docs/agents/AGENTS.plugins.md
index f94a3e95a..8b908d145 100644
--- a/docs/agents/AGENTS.plugins.md
+++ b/docs/agents/AGENTS.plugins.md
@@ -168,6 +168,8 @@ Place *.js files in extensions/webui/<extension_point>/ and export a default asy
Core JS hooks can also expose runtime UI surfaces when static HTML breakpoints are not a fit. For example, `confirm_dialog_after_render` runs after the shared confirm dialog is built and receives the rendered dialog/body/footer nodes plus any caller-provided `extensionContext`.
+For tool chat rows (`type === "tool"`), after built-in badge rules, core calls `get_tool_message_handler` with a mutable object containing `tool_name`, `kvps`, and `handler`. Plugins can set `handler` to entirely take over rendering for their `_tool_name`. A plugin can import `drawMessageToolSimple` and call it internally (e.g., passing `{ ...args, code: "WWW" }`) if it just wants standard tool row styling with a custom badge.
+
### User Feedback: Notifications, Not Inline Errors
Plugin UI must use the **A0 notification system** for errors, success, and warnings. Do not render dedicated error/success boxes (e.g. a red block bound to `store.error`). Use the notification store so toasts and notification history stay consistent across the app.
diff --git a/plugins/_browser_agent/extensions/webui/get_tool_message_handler/browser-tool-handler.js b/plugins/_browser_agent/extensions/webui/get_tool_message_handler/browser-tool-handler.js
new file mode 100644
index 000000000..7dc480593
--- /dev/null
+++ b/plugins/_browser_agent/extensions/webui/get_tool_message_handler/browser-tool-handler.js
@@ -0,0 +1,15 @@
+import { drawMessageToolSimple } from "/js/messages.js";
+
+/**
+ * Registers the browser_agent tool message handler to set the custom badge.
+ * @param {object} extData
+ */
+export default async function registerBrowserToolHandler(extData) {
+ if (extData?.tool_name === "browser_agent") {
+ extData.handler = drawBrowserTool;
+ }
+}
+
+function drawBrowserTool(args) {
+ return drawMessageToolSimple({ ...args, code: "WWW" });
+}
diff --git a/webui/js/messages.js b/webui/js/messages.js
index 89962b53b..30db440a9 100644
--- a/webui/js/messages.js
+++ b/webui/js/messages.js
@@ -1122,9 +1122,9 @@ export function drawMessageUser({
/**
* @param {MessageHandlerArgs & Record<string, any>} param0
- * @returns {MessageHandlerResult}
+ * @returns {Promise<MessageHandlerResult>}
*/
-export function drawMessageTool({
+export async function drawMessageTool({
id,
type,
heading,
@@ -1146,13 +1146,21 @@ export function drawMessageTool({
return drawMessageToolSimple({ ...arguments[0], code: "EYE" });
} else if (kvps._tool_name === "search_engine") {
return drawMessageToolSimple({ ...arguments[0], code: "WEB" });
- } else if (kvps._tool_name === "browser_agent") {
- return drawMessageToolSimple({ ...arguments[0], code: "WWW" });
} else if (kvps._tool_name.startsWith("memory_")) {
return drawMessageToolSimple({ ...arguments[0], code: "MEM" });
- } else {
- return drawMessageToolSimple({ ...arguments[0] });
}
+
+ /** @type {{ tool_name: string, kvps: any, handler: Function | undefined }} */
+ const extData = {
+ tool_name,
+ kvps,
+ handler: undefined,
+ };
+ await callJsExtensions("get_tool_message_handler", extData);
+ if (typeof extData.handler === "function") {
+ return extData.handler(arguments[0]);
+ }
+ return drawMessageToolSimple({ ...arguments[0] });
}
/**