diff --git a/packages/toolbox-core/src/toolbox_core/client.py b/packages/toolbox-core/src/toolbox_core/client.py index 193001c6..e59a934b 100644 --- a/packages/toolbox-core/src/toolbox_core/client.py +++ b/packages/toolbox-core/src/toolbox_core/client.py @@ -88,8 +88,8 @@ def __parse_tool( base_url=self.__base_url, name=name, description=schema.description, - params=params, - # create a read-only values for the maps to prevent mutation + # create a read-only values to prevent mutation + params=tuple(params), required_authn_params=types.MappingProxyType(authn_params), auth_service_token_getters=types.MappingProxyType(auth_token_getters), bound_params=types.MappingProxyType(bound_params), diff --git a/packages/toolbox-core/src/toolbox_core/sync_tool.py b/packages/toolbox-core/src/toolbox_core/sync_tool.py index ad24e8e3..ec05d9e0 100644 --- a/packages/toolbox-core/src/toolbox_core/sync_tool.py +++ b/packages/toolbox-core/src/toolbox_core/sync_tool.py @@ -16,8 +16,9 @@ from asyncio import AbstractEventLoop from inspect import Signature from threading import Thread -from typing import Any, Callable, Mapping, TypeVar, Union +from typing import Any, Callable, Coroutine, Mapping, Sequence, TypeVar, Union +from .protocol import ParameterSchema from .tool import ToolboxTool T = TypeVar("T") @@ -63,7 +64,7 @@ def __init__( # itself is being processed during module import or class definition. # Defining __qualname__ as a property leads to a TypeError because the class object needs # a string value immediately, not a descriptor that evaluates later. - self.__qualname__ = f"{self.__class__.__qualname__}.{self.__name__}" + self.__qualname__ = f"{self.__class__.__qualname__}.{self.__async_tool._name}" @property def __name__(self) -> str: @@ -87,6 +88,34 @@ def __annotations__(self) -> dict[str, Any]: # type: ignore[override] # Mypy flags this issue in the type checks. return self.__async_tool.__annotations__ + @property + def _name(self) -> str: + return self.__async_tool._name + + @property + def _description(self) -> str: + return self.__async_tool._description + + @property + def _params(self) -> Sequence[ParameterSchema]: + return self.__async_tool._params + + @property + def _bound_params(self) -> Mapping[str, Union[Callable[[], Any], Any]]: + return self.__async_tool._bound_params + + @property + def _required_auth_params(self) -> Mapping[str, list[str]]: + return self.__async_tool._required_auth_params + + @property + def _auth_service_token_getters(self) -> Mapping[str, Callable[[], str]]: + return self.__async_tool._auth_service_token_getters + + @property + def _client_headers(self) -> Mapping[str, Union[Callable, Coroutine, str]]: + return self.__async_tool._client_headers + def __call__(self, *args: Any, **kwargs: Any) -> str: """ Synchronously calls the remote tool with the provided arguments. diff --git a/packages/toolbox-core/src/toolbox_core/tool.py b/packages/toolbox-core/src/toolbox_core/tool.py index 73ca0009..d9c0d0fe 100644 --- a/packages/toolbox-core/src/toolbox_core/tool.py +++ b/packages/toolbox-core/src/toolbox_core/tool.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. - -import types +import copy from inspect import Signature +from types import MappingProxyType from typing import Any, Callable, Coroutine, Mapping, Optional, Sequence, Union from aiohttp import ClientSession @@ -113,6 +113,34 @@ def __init__( # map of client headers to their value/callable/coroutine self.__client_headers = client_headers + @property + def _name(self) -> str: + return self.__name__ + + @property + def _description(self) -> str: + return self.__description + + @property + def _params(self) -> Sequence[ParameterSchema]: + return copy.deepcopy(self.__params) + + @property + def _bound_params(self) -> Mapping[str, Union[Callable[[], Any], Any]]: + return MappingProxyType(self.__bound_parameters) + + @property + def _required_auth_params(self) -> Mapping[str, list[str]]: + return MappingProxyType(self.__required_authn_params) + + @property + def _auth_service_token_getters(self) -> Mapping[str, Callable[[], str]]: + return MappingProxyType(self.__auth_service_token_getters) + + @property + def _client_headers(self) -> Mapping[str, Union[Callable, Coroutine, str]]: + return MappingProxyType(self.__client_headers) + def __copy( self, session: Optional[ClientSession] = None, @@ -258,11 +286,11 @@ def add_auth_token_getters( ) # create a read-only updated value for new_getters - new_getters = types.MappingProxyType( + new_getters = MappingProxyType( dict(self.__auth_service_token_getters, **auth_token_getters) ) # create a read-only updated for params that are still required - new_req_authn_params = types.MappingProxyType( + new_req_authn_params = MappingProxyType( identify_required_authn_params( self.__required_authn_params, auth_token_getters.keys() ) @@ -300,5 +328,5 @@ def bind_parameters( return self.__copy( params=new_params, - bound_params=types.MappingProxyType(all_bound_params), + bound_params=MappingProxyType(all_bound_params), )