Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,9 @@ The <dfn method for=ModelContext>registerTool(<var>tool</var>, <var>options</var
</ol>
</div>

1. Let |promise| be [=a new promise=] created in [=this=]'s [=relevant realm=].

1. If |options|'s {{ModelContextRegisterToolOptions/signal}} [=map/exists=], then:

1. Let |signal| be |options|'s {{ModelContextRegisterToolOptions/signal}}.

1. If |signal| is [=AbortSignal/aborted=], then return [=a promise rejected with=]
|signal|'s [=AbortSignal/abort reason=].

1. [=AbortSignal/add|Add the following abort steps=] to |signal|:

1. [=model context/Unregister a tool=] given [=this=] and |tool name|.

1. [=Reject=] |promise| with |signal|'s [=AbortSignal/abort reason=].
1. If |options|'s {{ModelContextRegisterToolOptions/signal}} [=map/exists=] and is

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue we could make it nicer by moving this below the exposed origins check so that we check first all things related to exposed origins, then and only then signal aborted + registering algo. Here, we're mixing both.
I'm happy to send a spec PR and Chromium CL if accepted.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think while this is a little strange, we should avoid doing as much work as possible (aside from environment checks like at the very beginning of this method) if the developer passes in an aborted signal. IMO if the signal is already aborted, the Promise shouldn't abort due to any other invalid input (that WebIDL doesn't already catch), since we shouldn't even process them. If you can think of a way to preserve that invariant while rearranging this, I'm all ears. Otherwise, I think the semantics here are at least worth preserving.

[=AbortSignal/aborted=], then return [=a promise rejected with=] |options|'s
{{ModelContextRegisterToolOptions/signal}}'s [=AbortSignal/abort reason=].

1. Let |exposed origins| be an empty [=list=] of [=origins=].

Expand All @@ -436,6 +425,21 @@ The <dfn method for=ModelContext>registerTool(<var>tool</var>, <var>options</var

1. [=list/Append=] |parsedURL|'s [=url/origin=] to |exposed origins|.

1. Let |promise| be [=a new promise=] created in [=this=]'s [=relevant realm=].

1. If |options|'s {{ModelContextRegisterToolOptions/signal}} [=map/exists=], then:

1. Let |signal| be |options|'s {{ModelContextRegisterToolOptions/signal}}.

1. If |signal| is [=AbortSignal/aborted=], then return [=a promise rejected with=]
|signal|'s [=AbortSignal/abort reason=].

1. [=AbortSignal/add|Add the following abort steps=] to |signal|:

1. [=model context/Unregister a tool=] given [=this=] and |tool name|.

1. [=Reject=] |promise| with |signal|'s [=AbortSignal/abort reason=].

1. Let |tool definition| be a new [=tool definition=], with the following [=struct/items=]:

: [=tool definition/name=]
Expand Down Expand Up @@ -669,17 +673,17 @@ definition itself.

<xmp class="idl">
dictionary ModelContextRegisterToolOptions {
AbortSignal signal;
sequence<USVString> exposedTo;
AbortSignal signal;
};
</xmp>

<dl class="domintro">
: <code><var ignore>options</var>["{{ModelContextRegisterToolOptions/exposedTo}}"]</code>
:: An array of origins that control which documents this tool is exposed to, in the current document's tree.

: <code><var ignore>options</var>["{{ModelContextRegisterToolOptions/signal}}"]</code>
:: An {{AbortSignal}} that unregisters the tool when aborted.

: <code><var ignore>options</var>["{{ModelContextRegisterToolOptions/exposedTo}}"]</code>
:: <p>An array of origins that control which documents this tool is exposed to, in the current document's tree.
</dl>

<h4 id="model-context-get-tool-options">ModelContextGetToolOptions Dictionary</h4>
Expand Down
Loading