diff --git a/index.bs b/index.bs index e602129..0c1c6e4 100644 --- a/index.bs +++ b/index.bs @@ -121,6 +121,14 @@ A tool definition is a [=struct=] with the following [=struct/items=] : description :: a [=string=]. + : imperative input schema object + :: an {{object}}-or-null, initially null. + + Note: This is only populated for tools registered by the imperative form of this API (i.e., + {{ModelContext/registerTool()}}. In that case, it holds the raw + {{ModelContextTool/inputSchema}} object, and is used in + {{ModelContext/unregisterTool()}} to find the right tool to unregister. + : input schema :: a [=string=]. @@ -178,7 +186,7 @@ The {{ModelContext}} interface provides methods for web applications to register [Exposed=Window, SecureContext] interface ModelContext { undefined registerTool(ModelContextTool tool); - undefined unregisterTool(DOMString name); + undefined unregisterTool(ModelContextTool tool); }; @@ -189,12 +197,15 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
navigator.{{Navigator/modelContext}}.{{ModelContext/registerTool(tool)}}
-

Registers a single tool without clearing the existing set of tools. The method throws an error, if a tool with the same name already exists, or if the {{ModelContextTool/inputSchema}} is invalid. +

Registers a single tool without clearing the existing set of tools. This method throws an + exception if a tool with the same name already exists, or if the + {{ModelContextTool/inputSchema}} is invalid.

-
navigator.{{Navigator/modelContext}}.{{ModelContext/unregisterTool(name)}}
+
navigator.{{Navigator/modelContext}}.{{ModelContext/unregisterTool(tool)}}
-

Removes the tool with the specified name from the registered set. +

Removes the tool from the registered set of tools. This method throws an exception if no + matching tool has been registered.

@@ -257,13 +268,45 @@ The registerTool(tool) method step
-The unregisterTool(name) method steps are: +The unregisterTool(tool) method steps are: 1. Let |tool map| be [=this=]'s [=ModelContext/internal context=]'s [=model context/tool map=]. -1. If |tool map|[|name|] does not [=map/exist=], then [=exception/throw=] an {{InvalidStateError}} +1. Let |name| be |tool|'s {{ModelContextTool/name}}. + +1. If |tool map|[|name|] does not [=map/exist=], then [=exception/throw=] an {{NotFoundError}} {{DOMException}}. +1. Let |registered tool| be |tool map|[|name|]. + +1. Let |matches| be true. + +1. [=Assert=]: |name| equals |registered tool|'s [=tool definition/name=]. + +1. If |tool|'s {{ModelContextTool/description}} does not equal |registered tool|'s [=tool + definition/description=], then set |matches| to false. + +1. Else if |tool|'s {{ModelContextTool/inputSchema}} [=map/exists=] and |registered tool|'s [=tool + definition/imperative input schema object=] is null, or if |tool|'s + {{ModelContextTool/inputSchema}} does not [=map/exist=] but |registered tool|'s [=tool + definition/imperative input schema object=] is not null, then set |matches| to false. + +1. Else if |tool|'s {{ModelContextTool/inputSchema}} [=map/exists=] and is not the same object as + |registered tool|'s [=tool definition/imperative input schema object=], then set |matches| to + false. + +1. Else if |tool|'s {{ModelContextTool/execute}} is not the same [=callback function=] that + |registered tool|'s [=tool definition/execute steps=] is prepared to run, then set |matches| to + false. + +1. Let |tool read-only hint| be true if |tool|'s {{ModelContextTool/annotations}} [=map/exists=] and + its {{ToolAnnotations/readOnlyHint}} is true; false otherwise. + +1. If |tool read-only hint| does not equal |registered tool|'s [=tool definition/read-only hint=], + then set |matches| to false. + +1. If |matches| is false, then [=exception/throw=] an {{NotFoundError}} {{DOMException}} and return. + 1. [=map/Remove=] |tool map|[|name|].