Repository navigation
Support "*" in getTools fromOrigins #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sjdallst2
wants to merge
3
commits into
webmachinelearning:main
Choose a base branch
from
sjdallst2:add-origin-wildcard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−6
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,6 +173,9 @@ An <dfn>AI platform</dfn> is a provider of agentic assistants such as OpenAI’s | |
|
|
||
| <h2 id="supporting-concepts">Supporting concepts</h2> | ||
|
|
||
| An <dfn>origin wildcard</dfn> is the [=string=] "`*`", used in | ||
| {{ModelContextGetToolOptions/fromOrigins}} to request discovery from all eligible origins. | ||
|
|
||
| A <dfn>model context</dfn> is a [=struct=] with the following [=struct/items=]: | ||
|
|
||
| <dl dfn-for="model context"> | ||
|
|
@@ -940,10 +943,18 @@ The <dfn method for=ModelContext>getTools(<var>options</var>)</dfn> method steps | |
|
|
||
| 1. Let |from origins| be an empty [=list=] of [=origins=]. | ||
|
|
||
| 1. Let |includeAllOrigins| be false. | ||
|
|
||
| 1. If |options|'s {{ModelContextGetToolOptions/fromOrigins}} [=map/exists=], then: | ||
|
|
||
| 1. [=list/For each=] |origin| of |options|'s {{ModelContextGetToolOptions/fromOrigins}}: | ||
|
|
||
| 1. If |origin| is the [=origin wildcard=], then: | ||
|
|
||
| 1. Set |includeAllOrigins| to true. | ||
|
|
||
| 1. [=iteration/continue=]. | ||
|
|
||
| 1. Let |parsedURL| be the result of running the [=URL parser=] on |origin|. | ||
|
|
||
| 1. If |parsedURL| is failure or its [=url/origin=] is not [$is origin potentially | ||
|
|
@@ -973,7 +984,15 @@ The <dfn method for=ModelContext>getTools(<var>options</var>)</dfn> method steps | |
| 1. Let |callerOrigin| be |toolRequestor|'s [=Document/origin=]. | ||
|
|
||
| 1. Let |toolOwnerIsRequested| be true if |targetOrigin| is [=same origin=] with | ||
| |callerOrigin|, or if |from origins| [=list/contains=] |targetOrigin|; otherwise, false. | ||
| |callerOrigin|; otherwise, false. | ||
|
|
||
| 1. If |includeAllOrigins| is true and |targetOrigin| is [$is origin potentially | ||
| trustworthy?|potentially trustworthy$], then set |toolOwnerIsRequested| to true. | ||
|
|
||
| 1. [=list/For each=] |requestedOrigin| of |from origins|: | ||
|
|
||
| 1. If |targetOrigin| is [=same origin=] with |requestedOrigin|, then set | ||
| |toolOwnerIsRequested| to true and [=iteration/break=]. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we stick with the |
||
|
|
||
| 1. If |toolOwnerIsRequested| is false, then [=iteration/continue=]. | ||
|
|
||
|
|
@@ -1343,6 +1362,10 @@ dictionary ModelContextRegisterToolOptions { | |
| :: An {{AbortSignal}} that unregisters the tool when aborted. | ||
| </dl> | ||
|
|
||
| Issue(#317): Wildcard support in {{ModelContextRegisterToolOptions/exposedTo}} requires separate | ||
| consideration of its security implications. More selective matching using {{URLPattern}} is also | ||
| under consideration. | ||
|
|
||
| <h4 id="model-context-get-tool-options">ModelContextGetToolOptions Dictionary</h4> | ||
|
|
||
| The {{ModelContextGetToolOptions}} dictionary allows web applications to filter the tools returned | ||
|
|
@@ -1356,11 +1379,26 @@ dictionary ModelContextGetToolOptions { | |
|
|
||
| <dl class="domintro"> | ||
| : <code><var ignore>options</var>["{{ModelContextGetToolOptions/fromOrigins}}"]</code> | ||
| :: An array of origins from which to query tools. Documents whose origin appears in this list, or | ||
| are same-origin with the caller, have their tools queried. An empty list only includes | ||
| same-origin documents. | ||
| :: An array of origin strings or the [=origin wildcard=] from which to query tools in the current | ||
| document's tree. Documents whose origin appears in the array, or are same-origin with the | ||
| caller, have their tools queried. The [=origin wildcard=] also includes documents with | ||
| [$is origin potentially trustworthy?|potentially trustworthy$] origins. An omitted or empty | ||
| array only includes same-origin documents. | ||
| </dl> | ||
|
|
||
| Note: Entries other than the [=origin wildcard=] are validated even when it is present. An invalid | ||
| or non-potentially-trustworthy entry causes {{ModelContext/getTools()}} to reject with a | ||
| "{{SecurityError}}" {{DOMException}}. | ||
|
|
||
| <div class=example id=origin-wildcard-options> | ||
| Use the [=origin wildcard=] to discover tools from all eligible origins: | ||
|
|
||
| ```js | ||
| const tools = await document.modelContext.getTools({ fromOrigins: ["*"] }); | ||
| ``` | ||
|
|
||
| </div> | ||
|
|
||
| <h4 id="model-context-execute-tool-options">ModelContextExecuteToolOptions Dictionary</h4> | ||
|
|
||
| The {{ModelContextExecuteToolOptions}} dictionary allows web applications to pass options to | ||
|
|
@@ -2051,7 +2089,8 @@ gates are satisfied: | |
| a tool to its parent [=origin=] via {{ModelContextRegisterToolOptions/exposedTo}}, | ||
| {{ModelContext/getTools()}} only returns tools from [=same origin=] {{Document}}s by default. To | ||
| discover tools from a cross-origin descendant [=navigable=], the calling {{Document}} must also | ||
| explicitly list the target [=origin=] in {{ModelContextGetToolOptions/fromOrigins}}. | ||
| explicitly list the target [=origin=] or the [=origin wildcard=] in | ||
| {{ModelContextGetToolOptions/fromOrigins}}. | ||
| </li> | ||
| </ol> | ||
|
|
||
|
|
@@ -2089,6 +2128,11 @@ await document.modelContext.registerTool( | |
| ); | ||
| ``` | ||
|
|
||
| Note: The [=origin wildcard=] does not restrict discovery to origins trusted by the author. | ||
| Authors are encouraged to use explicit origin lists and treat discovered tool descriptions as | ||
| untrusted data. The provider's {{ModelContextRegisterToolOptions/exposedTo}} origin list and the | ||
| "{{tools}}" Permissions Policy still apply. | ||
|
|
||
| <h5 id="same-origin-residual-risks">Residual Risks</h5> | ||
|
|
||
| Even when cross-origin access is governed by the mechanisms above, two categories of residual risk | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think this excludes opaque origin secure context documents that expose tools, right? For example, a data: URL iframe is secure context but has an opaque origin, which alone is not considered potentially trustworthy. It's a secure context however, because the HTML Standard's secure context algorithm only considers the top-level navigable's creation URL.
So as we make it possible to invoke tools in those contexts, we probably also want to let
fromOrigins ['*']target them, right?