Repository navigation
Introduce the Tool interface - #348
Conversation
|
Binding a A question from the extension side. We discover tools from a content script and have to pass them on to a service worker and an extension page before the model calls one, so a tool has to cross a few contexts. Since A smaller one: as far as I can tell there is no way to change a registered tool, so a changed description is a new |
|
Thanks for the reviews! I'll hold off on landing this for a little bit to give @jakearchibald more time to take a look.
This was broken before this PR too, right @kenchris? (Since
Extensions-specific work or something of the sort will take care of this, right. I don't think it'll propagate to any spec changes here, although we may independently make |
|
Yes, same before, |
* WebPlatform: implement WebMCP (document.modelContext) - document.modelContext and the ModelContext interface of the WebMCP specification: registerTool() (name/description validation, schema serialization, exposedTo, signal), getTools() (frame tree, same-origin and fromOrigins/exposedTo filtering, sorted by name), executeTool() (pending executions per traversable, cancellation, toolcancel and toolactivated events, unloading document cleanup steps), toolchange - the Tool interface of webmachinelearning/webmcp#348 (what Chromium and the WPT implement) instead of the RegisteredTool dictionary, and the outputSchema member - waitForToolsUntil() and toolsReady of webmachinelearning/webmcp#373, marked [Experimental("WEBPLATEXP0018")] - the "tools" permissions policy feature and WebPlatformFeatures.WebMcpEnabled - a host API for the application, as the browser agent: BrowsingContext.GetModelContextTools(), ExecuteModelContextToolAsync() and ModelContextToolsReady - ScriptEngine JSON hooks (JSON.stringify/JSON.parse of the realm) - WPT: run webmcp; the declarative API (explainer only) is skipped, and the subtests that expect unquoted string results are TEST BUGs (webmachinelearning/webmcp#361) * WebPlatform: address the review of WebMCP - the settlement of a tool and of a waitForToolsUntil() promise is handled by a task of the event loop (a task of the application can complete on another thread) - the realms capture JSON.parse() and JSON.stringify() when they are created, before the page can replace them - executeTool() checks the caller again after serializing the arguments (toJSON() can detach it) - Tool.Document is the document that registered the tool
de62b42 to
f306ded
Compare
SHA: 14b6d53 Reason: push, by domfarolino Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Mirrors webmachinelearning/webmcp#348. RegisteredTool is kept as a deprecated alias.
This PR introduces the
Toolinterface which encapsulates a tool's new UUID. Tools are now keyed and identified by this ID. This replaces theRegisteredTooldictionary with the newToolinterface, fixes a number of possible race conditions (such as https://webmachinelearning.github.io/webmcp/#unregistration-execution-race), and also unblocks us from being able to execute registered by opaque origin documents (see #349).Note that there are some compatibility changes with this:
RegisteredTool#inputSchemaandRegisteredTool#annotationscould be undefined before this PR, where asTool#inputSchemaandTool#annotationsare notobject?which makes more sense for an interface object. This means these two members can be null when their respective values are not provided. They are never purely undefined now.JSON.stringify(tool)returns{}, and the spread operator copies nothing.structuredClone(tool)throws, since this type is not yet[Serializable].This makes some progress towards the discussion in #236 (/cc @jakearchibald), and helps us out with future worker integration.
/cc @nmccormack-oai from who was interested in this fix from an agent's perspective. Note that the spec still doesn't define a native-agent-initiated tool execution path (equivalent to CDP-initiated tool execution in Chromium, or Gemini-in-Chrome/"actor stack"-initiated tool execution in branded Chrome), but that's coming soon, and the changes here are required to support the correctness / race fixes in those areas too.
Closes #385.
Preview | Diff