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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.remote_auth import RemoteAuth
from ..types.tool_server import ToolServer
from ..types.tool_server_name import ToolServerName
from ..types.tool_server_transport import ToolServerTransport
from .raw_client import AsyncRawToolServersClient, RawToolServersClient

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


class ToolServersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawToolServersClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawToolServersClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawToolServersClient
        """
        return self._raw_client

    def list(
        self,
        *,
        filter: typing.Optional[str] = None,
        type: typing.Optional[typing.Literal["mcp"]] = None,
        enabled: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[ToolServer]:
        """
        Retrieve a list of available tool servers that expose various tools.

        Parameters
        ----------
        filter : typing.Optional[str]
            A regular expression against tool server names and descriptions to filter the results.

        type : typing.Optional[typing.Literal["mcp"]]
            Filter tool servers by type.

        enabled : typing.Optional[bool]
            Filter tool servers by enabled status.

        limit : typing.Optional[int]
            The maximum number of tool servers to return in the list.

        page_key : typing.Optional[str]
            Used to retrieve the next page of tool servers after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        SyncPager[ToolServer]
            List of available tool servers.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        response = client.tool_servers.list(
            filter="rag.*",
            enabled=True,
        )
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        return self._raw_client.list(
            filter=filter,
            type=type,
            enabled=enabled,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    def create(
        self,
        *,
        name: ToolServerName,
        uri: str,
        transport: ToolServerTransport,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        description: typing.Optional[str] = OMIT,
        headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        auth: typing.Optional[RemoteAuth] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolServer:
        """
        Create a new tool server to expose tools for use by agents.

        Parameters
        ----------
        name : ToolServerName

        uri : str
            The URI of the tool server.

        transport : ToolServerTransport

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        description : typing.Optional[str]
            A detailed description of what this tool server does.

        headers : typing.Optional[typing.Dict[str, str]]
            Optional HTTP headers to include when connecting to the server.

        auth : typing.Optional[RemoteAuth]
            Authentication configuration for connecting to the tool server.

        enabled : typing.Optional[bool]
            Whether the tool server is currently enabled and available for use.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the tool server.

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

        Returns
        -------
        ToolServer
            The created tool server details.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.tool_servers.create(
            name="RAG Search Server",
            uri="https://api.example.com/rag_search",
            transport="sse",
        )
        """
        _response = self._raw_client.create(
            name=name,
            uri=uri,
            transport=transport,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            description=description,
            headers=headers,
            auth=auth,
            enabled=enabled,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def get(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolServer:
        """
        Retrieve details about a specific tool server by its Id.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to retrieve.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        ToolServer
            The requested tool server details.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.tool_servers.get(
            tool_server_id="tsr_rag_search",
        )
        """
        _response = self._raw_client.get(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def delete(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Permanently delete a tool server and all its associated configuration and tools. This action cannot be undone.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to delete.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        None

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.tool_servers.delete(
            tool_server_id="tsr_rag_search",
        )
        """
        _response = self._raw_client.delete(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def update(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        name: typing.Optional[ToolServerName] = OMIT,
        description: typing.Optional[str] = OMIT,
        uri: typing.Optional[str] = OMIT,
        headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        transport: typing.Optional[ToolServerTransport] = OMIT,
        auth: typing.Optional[RemoteAuth] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolServer:
        """
        Update the configuration of a specific tool server.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to update.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        name : typing.Optional[ToolServerName]

        description : typing.Optional[str]
            A detailed description of what this tool server does.

        uri : typing.Optional[str]
            The URI of the tool server.

        headers : typing.Optional[typing.Dict[str, str]]
            Optional HTTP headers to include when connecting to the server.

        transport : typing.Optional[ToolServerTransport]

        auth : typing.Optional[RemoteAuth]
            Authentication configuration for connecting to the tool server.

        enabled : typing.Optional[bool]
            Whether the tool server is currently enabled and available for use.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the tool server.

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

        Returns
        -------
        ToolServer
            The updated tool server details.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.tool_servers.update(
            tool_server_id="tsr_rag_search",
        )
        """
        _response = self._raw_client.update(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            name=name,
            description=description,
            uri=uri,
            headers=headers,
            transport=transport,
            auth=auth,
            enabled=enabled,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def sync(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Trigger a synchronization of the tool server to ensure it is up-to-date with the latest tools.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to synchronize.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        None

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.tool_servers.sync(
            tool_server_id="tsr_rag_search",
        )
        """
        _response = self._raw_client.sync(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data


class AsyncToolServersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawToolServersClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawToolServersClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawToolServersClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        filter: typing.Optional[str] = None,
        type: typing.Optional[typing.Literal["mcp"]] = None,
        enabled: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[ToolServer]:
        """
        Retrieve a list of available tool servers that expose various tools.

        Parameters
        ----------
        filter : typing.Optional[str]
            A regular expression against tool server names and descriptions to filter the results.

        type : typing.Optional[typing.Literal["mcp"]]
            Filter tool servers by type.

        enabled : typing.Optional[bool]
            Filter tool servers by enabled status.

        limit : typing.Optional[int]
            The maximum number of tool servers to return in the list.

        page_key : typing.Optional[str]
            Used to retrieve the next page of tool servers after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AsyncPager[ToolServer]
            List of available tool servers.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            response = await client.tool_servers.list(
                filter="rag.*",
                enabled=True,
            )
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page


        asyncio.run(main())
        """
        return await self._raw_client.list(
            filter=filter,
            type=type,
            enabled=enabled,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    async def create(
        self,
        *,
        name: ToolServerName,
        uri: str,
        transport: ToolServerTransport,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        description: typing.Optional[str] = OMIT,
        headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        auth: typing.Optional[RemoteAuth] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolServer:
        """
        Create a new tool server to expose tools for use by agents.

        Parameters
        ----------
        name : ToolServerName

        uri : str
            The URI of the tool server.

        transport : ToolServerTransport

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        description : typing.Optional[str]
            A detailed description of what this tool server does.

        headers : typing.Optional[typing.Dict[str, str]]
            Optional HTTP headers to include when connecting to the server.

        auth : typing.Optional[RemoteAuth]
            Authentication configuration for connecting to the tool server.

        enabled : typing.Optional[bool]
            Whether the tool server is currently enabled and available for use.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the tool server.

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

        Returns
        -------
        ToolServer
            The created tool server details.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.tool_servers.create(
                name="RAG Search Server",
                uri="https://api.example.com/rag_search",
                transport="sse",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name,
            uri=uri,
            transport=transport,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            description=description,
            headers=headers,
            auth=auth,
            enabled=enabled,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolServer:
        """
        Retrieve details about a specific tool server by its Id.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to retrieve.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        ToolServer
            The requested tool server details.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.tool_servers.get(
                tool_server_id="tsr_rag_search",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def delete(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Permanently delete a tool server and all its associated configuration and tools. This action cannot be undone.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to delete.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.tool_servers.delete(
                tool_server_id="tsr_rag_search",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def update(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        name: typing.Optional[ToolServerName] = OMIT,
        description: typing.Optional[str] = OMIT,
        uri: typing.Optional[str] = OMIT,
        headers: typing.Optional[typing.Dict[str, str]] = OMIT,
        transport: typing.Optional[ToolServerTransport] = OMIT,
        auth: typing.Optional[RemoteAuth] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolServer:
        """
        Update the configuration of a specific tool server.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to update.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        name : typing.Optional[ToolServerName]

        description : typing.Optional[str]
            A detailed description of what this tool server does.

        uri : typing.Optional[str]
            The URI of the tool server.

        headers : typing.Optional[typing.Dict[str, str]]
            Optional HTTP headers to include when connecting to the server.

        transport : typing.Optional[ToolServerTransport]

        auth : typing.Optional[RemoteAuth]
            Authentication configuration for connecting to the tool server.

        enabled : typing.Optional[bool]
            Whether the tool server is currently enabled and available for use.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the tool server.

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

        Returns
        -------
        ToolServer
            The updated tool server details.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.tool_servers.update(
                tool_server_id="tsr_rag_search",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            name=name,
            description=description,
            uri=uri,
            headers=headers,
            transport=transport,
            auth=auth,
            enabled=enabled,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def sync(
        self,
        tool_server_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Trigger a synchronization of the tool server to ensure it is up-to-date with the latest tools.

        Parameters
        ----------
        tool_server_id : str
            The unique identifier of the tool server to synchronize.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.tool_servers.sync(
                tool_server_id="tsr_rag_search",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.sync(
            tool_server_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data
