16
16
from warnings import warn
17
17
18
18
from aiohttp import ClientSession
19
+ from toolbox_core .client import ToolboxClient as ToolboxCoreClient
19
20
20
- from .tools import AsyncToolboxTool
21
- from .utils import ManifestSchema , _load_manifest
21
+ from .async_tools import AsyncToolboxTool
22
22
23
23
24
24
# This class is an internal implementation detail and is not exposed to the
@@ -38,8 +38,7 @@ def __init__(
38
38
url: The base URL of the Toolbox service.
39
39
session: An HTTP client session.
40
40
"""
41
- self .__url = url
42
- self .__session = session
41
+ self .__core_client = ToolboxCoreClient (url = url , session = session )
43
42
44
43
async def aload_tool (
45
44
self ,
@@ -48,7 +47,6 @@ async def aload_tool(
48
47
auth_tokens : Optional [dict [str , Callable [[], str ]]] = None ,
49
48
auth_headers : Optional [dict [str , Callable [[], str ]]] = None ,
50
49
bound_params : dict [str , Union [Any , Callable [[], Any ]]] = {},
51
- strict : bool = True ,
52
50
) -> AsyncToolboxTool :
53
51
"""
54
52
Loads the tool with the given tool name from the Toolbox service.
@@ -61,9 +59,6 @@ async def aload_tool(
61
59
auth_headers: Deprecated. Use `auth_token_getters` instead.
62
60
bound_params: An optional mapping of parameter names to their
63
61
bound values.
64
- strict: If True, raises a ValueError if any of the given bound
65
- parameters are missing from the schema or require
66
- authentication. If False, only issues a warning.
67
62
68
63
Returns:
69
64
A tool loaded from the Toolbox.
@@ -94,18 +89,12 @@ async def aload_tool(
94
89
)
95
90
auth_token_getters = auth_headers
96
91
97
- url = f"{ self .__url } /api/tool/{ tool_name } "
98
- manifest : ManifestSchema = await _load_manifest (url , self .__session )
99
-
100
- return AsyncToolboxTool (
101
- tool_name ,
102
- manifest .tools [tool_name ],
103
- self .__url ,
104
- self .__session ,
105
- auth_token_getters ,
106
- bound_params ,
107
- strict ,
92
+ core_tool = await self .__core_client .load_tool (
93
+ name = tool_name ,
94
+ auth_token_getters = auth_token_getters ,
95
+ bound_params = bound_params ,
108
96
)
97
+ return AsyncToolboxTool (core_tool = core_tool )
109
98
110
99
async def aload_toolset (
111
100
self ,
@@ -114,7 +103,7 @@ async def aload_toolset(
114
103
auth_tokens : Optional [dict [str , Callable [[], str ]]] = None ,
115
104
auth_headers : Optional [dict [str , Callable [[], str ]]] = None ,
116
105
bound_params : dict [str , Union [Any , Callable [[], Any ]]] = {},
117
- strict : bool = True ,
106
+ strict : bool = False ,
118
107
) -> list [AsyncToolboxTool ]:
119
108
"""
120
109
Loads tools from the Toolbox service, optionally filtered by toolset
@@ -129,9 +118,11 @@ async def aload_toolset(
129
118
auth_headers: Deprecated. Use `auth_token_getters` instead.
130
119
bound_params: An optional mapping of parameter names to their
131
120
bound values.
132
- strict: If True, raises a ValueError if any of the given bound
133
- parameters are missing from the schema or require
134
- authentication. If False, only issues a warning.
121
+ strict: If True, raises an error if *any* loaded tool instance fails
122
+ to utilize at least one provided parameter or auth token (if any
123
+ provided). If False (default), raises an error only if a
124
+ user-provided parameter or auth token cannot be applied to *any*
125
+ loaded tool across the set.
135
126
136
127
Returns:
137
128
A list of all tools loaded from the Toolbox.
@@ -162,22 +153,16 @@ async def aload_toolset(
162
153
)
163
154
auth_token_getters = auth_headers
164
155
165
- url = f"{ self .__url } /api/toolset/{ toolset_name or '' } "
166
- manifest : ManifestSchema = await _load_manifest (url , self .__session )
167
- tools : list [AsyncToolboxTool ] = []
168
-
169
- for tool_name , tool_schema in manifest .tools .items ():
170
- tools .append (
171
- AsyncToolboxTool (
172
- tool_name ,
173
- tool_schema ,
174
- self .__url ,
175
- self .__session ,
176
- auth_token_getters ,
177
- bound_params ,
178
- strict ,
179
- )
180
- )
156
+ core_tools = await self .__core_client .load_toolset (
157
+ name = toolset_name ,
158
+ auth_token_getters = auth_token_getters ,
159
+ bound_params = bound_params ,
160
+ strict = strict ,
161
+ )
162
+
163
+ tools = []
164
+ for core_tool in core_tools :
165
+ tools .append (AsyncToolboxTool (core_tool = core_tool ))
181
166
return tools
182
167
183
168
def load_tool (
@@ -187,7 +172,6 @@ def load_tool(
187
172
auth_tokens : Optional [dict [str , Callable [[], str ]]] = None ,
188
173
auth_headers : Optional [dict [str , Callable [[], str ]]] = None ,
189
174
bound_params : dict [str , Union [Any , Callable [[], Any ]]] = {},
190
- strict : bool = True ,
191
175
) -> AsyncToolboxTool :
192
176
raise NotImplementedError ("Synchronous methods not supported by async client." )
193
177
@@ -198,6 +182,6 @@ def load_toolset(
198
182
auth_tokens : Optional [dict [str , Callable [[], str ]]] = None ,
199
183
auth_headers : Optional [dict [str , Callable [[], str ]]] = None ,
200
184
bound_params : dict [str , Union [Any , Callable [[], Any ]]] = {},
201
- strict : bool = True ,
185
+ strict : bool = False ,
202
186
) -> list [AsyncToolboxTool ]:
203
187
raise NotImplementedError ("Synchronous methods not supported by async client." )
0 commit comments