From cc15c8464753b4d525c0238141b135c738c6456b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Mon, 2 Nov 2026 14:49:30 +0100 Subject: [PATCH 1/2] Fire toolactivated after invoking execute Fires the toolactivated event after invoking the tool's execute callback, so listeners observe the tool's synchronous effects. This matches Chromium and WPT. Fixes #332 --- index.bs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.bs b/index.bs index 847677e..dbf6ed4 100644 --- a/index.bs +++ b/index.bs @@ -570,10 +570,6 @@ internal value=] |uuid|, run these steps: 1. If |inputObject| [=Object type|is not an Object=], then run |completionSteps| given null and [=tool execution error/invalid input=], and abort these steps. -1. [=Fire an event=] named {{ModelContext/toolactivated}} at |targetDocument|'s [=Document/associated - ModelContext|associated ModelContext=], using {{ToolActivatedEvent}}, with its - {{ToolActivatedEvent/toolName}} attribute initialized to |tool|'s {{ModelContextTool/name}}. - 1. Let |controller| be a [=new=] {{AbortController}} created in |targetDocument|'s [=relevant realm=]. @@ -593,6 +589,10 @@ internal value=] |uuid|, run these steps: 1. Let |toolPromise| be the result of [=invoke|invoking=] |tool|'s {{ModelContextTool/execute}} with |inputObject| and |options|. +1. [=Fire an event=] named {{ModelContext/toolactivated}} at |targetDocument|'s [=Document/associated + ModelContext|associated ModelContext=], using {{ToolActivatedEvent}}, with its + {{ToolActivatedEvent/toolName}} attribute initialized to |tool|'s {{ModelContextTool/name}}. + 1. [=promise/React=] to |toolPromise|: - If |toolPromise| was fulfilled with value |v|: @@ -1463,7 +1463,8 @@ that must be supported, as [=event handler IDL attributes=], by all {{ModelConte

ToolActivatedEvent Interface

The {{ToolActivatedEvent}} interface represents a {{ModelContext/toolactivated}} event that is -dispatched at a {{ModelContext}} object when the execution of a tool begins. +dispatched at a {{ModelContext}} object after a tool's {{ModelContextTool/execute}} callback is +invoked. [Exposed=Window, SecureContext] From 1fad0085d465fa2beb8d758a90f24681aeb52238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= <beaufort.francois@gmail.com> Date: Thu, 5 Nov 2026 08:51:04 +0100 Subject: [PATCH 2/2] Fire toolactivated after reacting to toolPromise --- index.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.bs b/index.bs index dbf6ed4..68a80fe 100644 --- a/index.bs +++ b/index.bs @@ -589,10 +589,6 @@ internal value=] |uuid|, run these steps: 1. Let |toolPromise| be the result of [=invoke|invoking=] |tool|'s {{ModelContextTool/execute}} with |inputObject| and |options|. -1. [=Fire an event=] named {{ModelContext/toolactivated}} at |targetDocument|'s [=Document/associated - ModelContext|associated <code>ModelContext</code>=], using {{ToolActivatedEvent}}, with its - {{ToolActivatedEvent/toolName}} attribute initialized to |tool|'s {{ModelContextTool/name}}. - 1. [=promise/React=] to |toolPromise|: - If |toolPromise| was fulfilled with value |v|: @@ -629,6 +625,10 @@ internal value=] |uuid|, run these steps: 1. Run |completionSteps| given null and [=tool execution error/tool rejected=]. +1. [=Fire an event=] named {{ModelContext/toolactivated}} at |targetDocument|'s [=Document/associated + ModelContext|associated <code>ModelContext</code>=], using {{ToolActivatedEvent}}, with its + {{ToolActivatedEvent/toolName}} attribute initialized to |tool|'s {{ModelContextTool/name}}. + </div> <div algorithm>