diff --git a/index.bs b/index.bs index 732d006..70af171 100644 --- a/index.bs +++ b/index.bs @@ -411,7 +411,9 @@ The imperative execute steps, given a {{ModelContextTool}} |tool|, a 1. If |inputObject| [=Object type|is not an Object=] is false, then run |completionSteps| given null and false, and abort these steps. - Issue(#146): Specify and fire the "toolactivated" event. +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 |toolPromise| be the result of [=invoke|invoking=] |tool|'s {{ModelContextTool/execute}} with |inputObject|. @@ -526,6 +528,8 @@ interface ModelContext : EventTarget { Promise executeTool(RegisteredTool tool, DOMString inputArguments, optional ModelContextExecuteToolOptions options = {}); attribute EventHandler ontoolchange; + attribute EventHandler ontoolactivated; + attribute EventHandler ontoolcancel; }; @@ -828,6 +832,11 @@ The executeTool(tool, inputArgument 1. [=Assert=]: |expectedTargetOrigin| is not an [=opaque origin=]. +1. Let |targetWindow| be |tool|'s {{RegisteredTool/window}}. + +1. Let |targetDocument| be |targetWindow|'s [=associated Document|associated + Document=]. + 1. Let |promise| be [=a new promise=] created in [=this=]'s [=relevant realm=]. 1. If |options|'s {{ModelContextExecuteToolOptions/signal}} [=map/exists=], then: @@ -841,15 +850,13 @@ The executeTool(tool, inputArgument 1. [=Reject=] |promise| with |signal|'s [=AbortSignal/abort reason=]. - Issue(#48): Wire up |signal| to the tool execution callback in the tool host's document, so - that tool abort is communicated all the way through. This should also fire the - "toolcanceled" event in the target document. See also issue #146. - -1. Let |targetWindow| be |tool|'s {{RegisteredTool/window}}. + 1. [=Fire an event=] named {{ModelContext/toolcancel}} at |targetDocument|'s + [=Document/associated ModelContext|associated ModelContext=], using + {{ToolCancelEvent}}, with its {{ToolCancelEvent/toolName}} attribute initialized to + |tool|'s {{RegisteredTool/name}}. -1. Let |targetDocument| be |targetWindow|'s [=associated Document|associated - Document=]. + Issue(#48): Wire up |signal| to the tool execution callback in the tool host's document, so + that tool abort is communicated all the way through. 1. Run the following steps [=in parallel=]: @@ -1158,6 +1165,56 @@ dictionary RegisteredTool { +

ToolActivatedEvent Interface

+ +The {{ToolActivatedEvent}} interface represents a {{ModelContext/toolactivated}} event that is dispatched at {{ModelContext}} when a tool is invoked by an [=agent=]. + + +[Exposed=Window, SecureContext] +interface ToolActivatedEvent : Event { + constructor(DOMString type, optional ToolActivatedEventInit eventInitDict = {}); + readonly attribute DOMString toolName; + readonly attribute Element? element; +}; + +dictionary ToolActivatedEventInit : EventInit { + DOMString toolName = ""; + Element? element = null; +}; + + +
+ : toolName + :: Returns the name of the tool that was activated. + : element + :: Returns the form element associated with the tool, if any. +
+ +

ToolCancelEvent Interface

+ +The {{ToolCancelEvent}} interface represents a {{ModelContext/toolcancel}} event that is dispatched at {{ModelContext}} when a tool's invocation is canceled by an [=agent=]. + + +[Exposed=Window, SecureContext] +interface ToolCancelEvent : Event { + constructor(DOMString type, optional ToolCancelEventInit eventInitDict = {}); + readonly attribute DOMString toolName; + readonly attribute Element? element; +}; + +dictionary ToolCancelEventInit : EventInit { + DOMString toolName = ""; + Element? element = null; +}; + + +
+ : toolName + :: Returns the name of the tool that was canceled. + : element + :: Returns the form element associated with the tool, if any. +
+

Declarative WebMCP

This section is entirely a TODO. For now, refer to the [explainer draft](https://github.com/webmachinelearning/webmcp/pull/76). @@ -1217,6 +1274,12 @@ that must be supported, as [=event handler IDL attributes=], by all {{ModelConte ontoolchange toolchange + + ontoolactivated + toolactivated + + ontoolcancel + toolcancel

Permissions policy integration