Spec the executeTool() API#226
Conversation
This CL introduces the `executeTool()` method to the `ModelContext` interface in the WebMCP specification. This aligns the spec with the C++ implementation in Blink. Key changes: - Adds `executeTool()` and `ExecuteToolOptions` IDL definitions. - Specifies the `executeTool()` algorithm, detailing cross-document tool lookup, origin visibility checks, and asynchronous invocation in the target document`s realm. - Clarifies the execution callback arguments and JSON serialization. - Incorporates `AbortSignal` handling for tool cancellation, dispatching a `toolcancel` event in the target document. - Fires `toolactivated` event in the target document. - Updates IDL member access syntax to use idiomatic Bikeshed style. Small things Fix some things Don't serialize Object argument enforcement Add AbortSignal issue Small things
| 1. If |invokingDocument| is not [=Document/fully active=], then return [=a promise rejected with=] | ||
| an "{{InvalidStateError}}" {{DOMException}}. | ||
|
|
||
| 1. If this's [=surrounding agent=]'s [=agent cluster=]'s [=is origin-keyed=] is false and this's |
There was a problem hiding this comment.
| 1. If this's [=surrounding agent=]'s [=agent cluster=]'s [=is origin-keyed=] is false and this's | |
| 1. If [=this=]'s [=surrounding agent=]'s [=agent cluster=]'s [=is origin-keyed=] is false and [=this=]'s |
This suggestion applies as well to getTools and registerTool.
| 1. Let |expectedTargetOriginURL| be the result of [=URL parser|parsing=] |tool|'s | ||
| {{RegisteredTool/origin}}. | ||
|
|
||
| 1. If |expectedTargetOriginURL| is failure, then return [=a promise rejected with=] a |
There was a problem hiding this comment.
How about using NotSupportedError instead and return a rejected promise in both cases?
- expectedTargetOriginURL is a failure
- expectedTargetOrigin is opaque
| 1. If |targetDocument|'s [=node navigable=]'s [=navigable/traversable navigable=] is not | ||
| |invokingDocument|'s [=node navigable=]'s [=navigable/traversable navigable=], then [=queue a | ||
| global task=] on the [=webmcp task source=] given |invokingDocument|'s [=relevant global | ||
| object=] to [=reject=] |promise| with an "{{UnknownError}}" {{DOMException}}, and abort these |
There was a problem hiding this comment.
UnknownError feels weird to me in these cases. Maybe InvalidStateError?
| <dt><code><var ignore>document</var>.{{Document/modelContext}}.{{ModelContext/executeTool(tool, inputArguments, options)}}</code></dt> | ||
| <dd> | ||
| <p>Executes a tool on the document it was registered on. Returns a promise that resolves to the | ||
| result of the tool's execution.</p> |
There was a problem hiding this comment.
Maybe extends that it's a stringified result only for now.
| </div> | ||
|
|
||
| <div algorithm> | ||
| The <dfn method for=ModelContext>executeTool(<var>tool</var>, <var>inputArguments</var>, |
There was a problem hiding this comment.
A JS example of how to execute a tool from a cross-origin iframe may come handy in this spec. See previous comment at #223 (comment)
beaufortfrancois
left a comment
There was a problem hiding this comment.
We should update README as well: https://github.com/webmachinelearning/webmcp#discovering-and-running-tools
This PR specifies the
executeTool()API onModelContext.Closes #57.
Closes #117.
Closes #159.
Closes #160.
Preview | Diff