Currently, registerTool() expects that tool registration happens synchronously, and all errors related to registration will be thrown synchronously. But with cross-origin iframe integration, tools are shared across the frame tree, and their registration becomes fundamentally asynchronous, even if the registration error conditions are all synchronously known during the call to registerTool() (since they only rely on the local, per-document cache of tools).
But since things are becoming async, we might want to consider making registerTool() return a Promise. This has two benefits:
- We could resolve the Promise when the tool is actually registered asynchronously in the part of the platform that makes it available to
getTools() in other documents. This makes the Promise resolution a more "true" representation of the registration process, instead of the caller having to listen to some event in their own document that signals "the list of available tools has changed!"
- Forward compatibility: to keep our options open in the future. Right now we have no asynchronous tool registration failure cases, but what if we want to create some in the future? It's hard to signal async failures ergonomically to a sync API. It'd be a shame if we ever ended up in that case.
Given the above two, I vote that we make registerTool() return a Promise.
Currently,
registerTool()expects that tool registration happens synchronously, and all errors related to registration will be thrown synchronously. But with cross-origin iframe integration, tools are shared across the frame tree, and their registration becomes fundamentally asynchronous, even if the registration error conditions are all synchronously known during the call toregisterTool()(since they only rely on the local, per-document cache of tools).But since things are becoming async, we might want to consider making
registerTool()return a Promise. This has two benefits:getTools()in other documents. This makes the Promise resolution a more "true" representation of the registration process, instead of the caller having to listen to some event in their own document that signals "the list of available tools has changed!"Given the above two, I vote that we make
registerTool()return a Promise.