Skip to content

Commit 2ef1069

Browse files
Accept an object in executeTool() instead of a JSON string
Update executeTool() to accept an optional object for input arguments that is automatically serialized to a JSON string by the API, rather than requiring developers to manually call JSON.stringify(). Fixes webmachinelearning#243
1 parent 384e110 commit 2ef1069

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎index.bs‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ The <dfn>tool execute steps</dfn>, given a [=string=] |toolName|, a {{Document}}
379379
// This could target either the "old" tool, or the "new" one above,
380380
// and the execution might encounter any requisite errors due to the mismatch.
381381
const [tool] = await document.modelContext.getTools();
382-
document.modelContext.executeTool(tool, "{a: 10}");
382+
document.modelContext.executeTool(tool, {a: 10});
383383
</xmp>
384384
</div>
385385
</div>
@@ -523,7 +523,7 @@ The {{ModelContext}} interface provides methods for web applications to register
523523
interface ModelContext : EventTarget {
524524
Promise<undefined> registerTool(ModelContextTool tool, optional ModelContextRegisterToolOptions options = {});
525525
Promise<sequence<RegisteredTool>> getTools(optional ModelContextGetToolOptions options = {});
526-
Promise<DOMString> executeTool(RegisteredTool tool, DOMString inputArguments, optional ModelContextExecuteToolOptions options = {});
526+
Promise<DOMString> executeTool(RegisteredTool tool, optional object inputObject = {}, optional ModelContextExecuteToolOptions options = {});
527527

528528
attribute EventHandler ontoolchange;
529529
};
@@ -550,7 +550,7 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
550550
agent=] uses a different internal mechanism to retrieve the tools exposed to it.</p>
551551
</dd>
552552

553-
<dt><code><var ignore>document</var>.{{Document/modelContext}}.{{ModelContext/executeTool(tool, inputArguments, options)}}</code></dt>
553+
<dt><code><var ignore>document</var>.{{Document/modelContext}}.{{ModelContext/executeTool(tool, inputObject, options)}}</code></dt>
554554
<dd>
555555
<p>Executes a tool on the document it was registered on. Returns a promise that resolves to the
556556
stringified result of the tool's execution.</p>
@@ -808,7 +808,7 @@ The <dfn method for=ModelContext>getTools(<var>options</var>)</dfn> method steps
808808
</div>
809809

810810
<div algorithm>
811-
The <dfn method for=ModelContext>executeTool(<var>tool</var>, <var>inputArguments</var>,
811+
The <dfn method for=ModelContext>executeTool(<var>tool</var>, <var>inputObject</var>,
812812
<var>options</var>)</dfn> method steps are:
813813

814814
1. Let |callerDocument| be [=this=]'s [=relevant global object=]'s [=associated
@@ -836,6 +836,9 @@ The <dfn method for=ModelContext>executeTool(<var>tool</var>, <var>inputArgument
836836

837837
1. [=Assert=]: |expectedTargetOrigin| is not an [=opaque origin=].
838838

839+
1. Let |inputArguments| be the result of [=serializing a JavaScript value to a JSON string=] given
840+
|inputObject|. If this threw an exception, then return [=a promise rejected with=] that exception.
841+
839842
1. Let |promise| be [=a new promise=] created in [=this=]'s [=relevant realm=].
840843

841844
1. If |options|'s {{ModelContextExecuteToolOptions/signal}} [=map/exists=], then:
@@ -1005,7 +1008,7 @@ dictionary ToolAnnotations {
10051008
boolean untrustedContentHint = false;
10061009
};
10071010

1008-
callback ToolExecuteCallback = Promise<any> (object input);
1011+
callback ToolExecuteCallback = Promise<any> (object inputObject);
10091012
</xmp>
10101013

10111014
<dl class="domintro">

0 commit comments

Comments
 (0)