# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.bad_request_error import BadRequestError
from ..errors.conflict_error import ConflictError
from ..errors.forbidden_error import ForbiddenError
from ..errors.not_found_error import NotFoundError
from ..types.error import Error
from ..types.tool_parameter import ToolParameter
from .types.create_tool_request_execution_mode import CreateToolRequestExecutionMode
from .types.create_tool_request_type import CreateToolRequestType
from .types.tools_create_response import ToolsCreateResponse
from .types.tools_delete_response import ToolsDeleteResponse
from .types.tools_get_response import ToolsGetResponse
from .types.tools_list_response import ToolsListResponse
from .types.tools_update_response import ToolsUpdateResponse
from .types.update_tool_request_execution_mode import UpdateToolRequestExecutionMode
from .types.update_tool_request_type import UpdateToolRequestType

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RawToolsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[ToolsListResponse]:
        """
        Returns all custom tools for the organization.

        Parameters
        ----------
        project : typing.Optional[str]
            The name of the project to list tools for.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ToolsListResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            "tools",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsListResponse,
                    parse_obj_as(
                        type_=ToolsListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create(
        self,
        *,
        name: str,
        description: str,
        type: CreateToolRequestType,
        execution_mode: CreateToolRequestExecutionMode,
        project: typing.Optional[str] = None,
        parameters: typing.Optional[typing.Sequence[ToolParameter]] = OMIT,
        endpoint_method: typing.Optional[typing.Literal["POST"]] = OMIT,
        endpoint_url: typing.Optional[str] = OMIT,
        endpoint_headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        endpoint_timeout_ms: typing.Optional[int] = OMIT,
        tool_call_output_timeout_ms: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ToolsCreateResponse]:
        """
        Creates a new tool in a project.

        Parameters
        ----------
        name : str
            The name of the tool. Must be snake_case and unique within the organization.

        description : str
            A description of what the tool does.

        type : CreateToolRequestType
            The type of tool.

        execution_mode : CreateToolRequestExecutionMode
            Mode of operation.

        project : typing.Optional[str]
            The name of the project to create the tool in.

        parameters : typing.Optional[typing.Sequence[ToolParameter]]
            Array of parameter definitions.

        endpoint_method : typing.Optional[typing.Literal["POST"]]
            Required for webhook tools.

        endpoint_url : typing.Optional[str]
            Required for webhook tools.

        endpoint_headers : typing.Optional[typing.Dict[str, str]]
            Optional headers for webhook tools.

        endpoint_timeout_ms : typing.Optional[int]
            Timeout for webhook tools.

        tool_call_output_timeout_ms : typing.Optional[int]
            Timeout for WebSocket tool responses.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ToolsCreateResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            "tools",
            base_url=self._client_wrapper.get_environment().base,
            method="POST",
            params={
                "project": project,
            },
            json={
                "name": name,
                "description": description,
                "type": type,
                "execution_mode": execution_mode,
                "parameters": convert_and_respect_annotation_metadata(
                    object_=parameters, annotation=typing.Sequence[ToolParameter], direction="write"
                ),
                "endpoint_method": endpoint_method,
                "endpoint_url": endpoint_url,
                "endpoint_headers": endpoint_headers,
                "endpoint_timeout_ms": endpoint_timeout_ms,
                "tool_call_output_timeout_ms": tool_call_output_timeout_ms,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsCreateResponse,
                    parse_obj_as(
                        type_=ToolsCreateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ToolsGetResponse]:
        """
        Returns a tool by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the tool to get.

        project : typing.Optional[str]
            The name of the project containing the tool. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ToolsGetResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"tools/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsGetResponse,
                    parse_obj_as(
                        type_=ToolsGetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ToolsDeleteResponse]:
        """
        Deletes a tool by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the tool to delete.

        project : typing.Optional[str]
            The name of the project containing the tool. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ToolsDeleteResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"tools/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="DELETE",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsDeleteResponse,
                    parse_obj_as(
                        type_=ToolsDeleteResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        type: typing.Optional[UpdateToolRequestType] = OMIT,
        execution_mode: typing.Optional[UpdateToolRequestExecutionMode] = OMIT,
        parameters: typing.Optional[typing.Sequence[ToolParameter]] = OMIT,
        endpoint_method: typing.Optional[typing.Literal["POST"]] = OMIT,
        endpoint_url: typing.Optional[str] = OMIT,
        endpoint_headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        endpoint_timeout_ms: typing.Optional[int] = OMIT,
        tool_call_output_timeout_ms: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ToolsUpdateResponse]:
        """
        Updates a tool by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the tool to update.

        project : typing.Optional[str]
            The name of the project containing the tool. Only used when `nameOrId` is a name.

        name : typing.Optional[str]
            The name of the tool. Must be snake_case and unique within the organization.

        description : typing.Optional[str]
            A description of what the tool does.

        type : typing.Optional[UpdateToolRequestType]
            The type of tool.

        execution_mode : typing.Optional[UpdateToolRequestExecutionMode]
            Mode of operation.

        parameters : typing.Optional[typing.Sequence[ToolParameter]]
            Array of parameter definitions.

        endpoint_method : typing.Optional[typing.Literal["POST"]]

        endpoint_url : typing.Optional[str]

        endpoint_headers : typing.Optional[typing.Dict[str, str]]

        endpoint_timeout_ms : typing.Optional[int]

        tool_call_output_timeout_ms : typing.Optional[int]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ToolsUpdateResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"tools/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="PATCH",
            params={
                "project": project,
            },
            json={
                "name": name,
                "description": description,
                "type": type,
                "execution_mode": execution_mode,
                "parameters": convert_and_respect_annotation_metadata(
                    object_=parameters, annotation=typing.Sequence[ToolParameter], direction="write"
                ),
                "endpoint_method": endpoint_method,
                "endpoint_url": endpoint_url,
                "endpoint_headers": endpoint_headers,
                "endpoint_timeout_ms": endpoint_timeout_ms,
                "tool_call_output_timeout_ms": tool_call_output_timeout_ms,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsUpdateResponse,
                    parse_obj_as(
                        type_=ToolsUpdateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawToolsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[ToolsListResponse]:
        """
        Returns all custom tools for the organization.

        Parameters
        ----------
        project : typing.Optional[str]
            The name of the project to list tools for.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ToolsListResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "tools",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsListResponse,
                    parse_obj_as(
                        type_=ToolsListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create(
        self,
        *,
        name: str,
        description: str,
        type: CreateToolRequestType,
        execution_mode: CreateToolRequestExecutionMode,
        project: typing.Optional[str] = None,
        parameters: typing.Optional[typing.Sequence[ToolParameter]] = OMIT,
        endpoint_method: typing.Optional[typing.Literal["POST"]] = OMIT,
        endpoint_url: typing.Optional[str] = OMIT,
        endpoint_headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        endpoint_timeout_ms: typing.Optional[int] = OMIT,
        tool_call_output_timeout_ms: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ToolsCreateResponse]:
        """
        Creates a new tool in a project.

        Parameters
        ----------
        name : str
            The name of the tool. Must be snake_case and unique within the organization.

        description : str
            A description of what the tool does.

        type : CreateToolRequestType
            The type of tool.

        execution_mode : CreateToolRequestExecutionMode
            Mode of operation.

        project : typing.Optional[str]
            The name of the project to create the tool in.

        parameters : typing.Optional[typing.Sequence[ToolParameter]]
            Array of parameter definitions.

        endpoint_method : typing.Optional[typing.Literal["POST"]]
            Required for webhook tools.

        endpoint_url : typing.Optional[str]
            Required for webhook tools.

        endpoint_headers : typing.Optional[typing.Dict[str, str]]
            Optional headers for webhook tools.

        endpoint_timeout_ms : typing.Optional[int]
            Timeout for webhook tools.

        tool_call_output_timeout_ms : typing.Optional[int]
            Timeout for WebSocket tool responses.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ToolsCreateResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "tools",
            base_url=self._client_wrapper.get_environment().base,
            method="POST",
            params={
                "project": project,
            },
            json={
                "name": name,
                "description": description,
                "type": type,
                "execution_mode": execution_mode,
                "parameters": convert_and_respect_annotation_metadata(
                    object_=parameters, annotation=typing.Sequence[ToolParameter], direction="write"
                ),
                "endpoint_method": endpoint_method,
                "endpoint_url": endpoint_url,
                "endpoint_headers": endpoint_headers,
                "endpoint_timeout_ms": endpoint_timeout_ms,
                "tool_call_output_timeout_ms": tool_call_output_timeout_ms,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsCreateResponse,
                    parse_obj_as(
                        type_=ToolsCreateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ToolsGetResponse]:
        """
        Returns a tool by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the tool to get.

        project : typing.Optional[str]
            The name of the project containing the tool. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ToolsGetResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"tools/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsGetResponse,
                    parse_obj_as(
                        type_=ToolsGetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ToolsDeleteResponse]:
        """
        Deletes a tool by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the tool to delete.

        project : typing.Optional[str]
            The name of the project containing the tool. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ToolsDeleteResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"tools/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="DELETE",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsDeleteResponse,
                    parse_obj_as(
                        type_=ToolsDeleteResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        type: typing.Optional[UpdateToolRequestType] = OMIT,
        execution_mode: typing.Optional[UpdateToolRequestExecutionMode] = OMIT,
        parameters: typing.Optional[typing.Sequence[ToolParameter]] = OMIT,
        endpoint_method: typing.Optional[typing.Literal["POST"]] = OMIT,
        endpoint_url: typing.Optional[str] = OMIT,
        endpoint_headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        endpoint_timeout_ms: typing.Optional[int] = OMIT,
        tool_call_output_timeout_ms: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ToolsUpdateResponse]:
        """
        Updates a tool by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the tool to update.

        project : typing.Optional[str]
            The name of the project containing the tool. Only used when `nameOrId` is a name.

        name : typing.Optional[str]
            The name of the tool. Must be snake_case and unique within the organization.

        description : typing.Optional[str]
            A description of what the tool does.

        type : typing.Optional[UpdateToolRequestType]
            The type of tool.

        execution_mode : typing.Optional[UpdateToolRequestExecutionMode]
            Mode of operation.

        parameters : typing.Optional[typing.Sequence[ToolParameter]]
            Array of parameter definitions.

        endpoint_method : typing.Optional[typing.Literal["POST"]]

        endpoint_url : typing.Optional[str]

        endpoint_headers : typing.Optional[typing.Dict[str, str]]

        endpoint_timeout_ms : typing.Optional[int]

        tool_call_output_timeout_ms : typing.Optional[int]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ToolsUpdateResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"tools/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="PATCH",
            params={
                "project": project,
            },
            json={
                "name": name,
                "description": description,
                "type": type,
                "execution_mode": execution_mode,
                "parameters": convert_and_respect_annotation_metadata(
                    object_=parameters, annotation=typing.Sequence[ToolParameter], direction="write"
                ),
                "endpoint_method": endpoint_method,
                "endpoint_url": endpoint_url,
                "endpoint_headers": endpoint_headers,
                "endpoint_timeout_ms": endpoint_timeout_ms,
                "tool_call_output_timeout_ms": tool_call_output_timeout_ms,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ToolsUpdateResponse,
                    parse_obj_as(
                        type_=ToolsUpdateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        Error,
                        parse_obj_as(
                            type_=Error,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
