# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Dict import httpx from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given from ..._utils import path_template, maybe_transform, strip_not_given, async_maybe_transform from ..._compat import cached_property from ...types.ai import ( tool_list_params, tool_create_params, tool_update_params, ) from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ...pagination import SyncDefaultFlatPagination, AsyncDefaultFlatPagination from ..._base_client import AsyncPaginator, make_request_options from ...types.ai.shared_tool_response import SharedToolResponse from ...types.ai.pay_tool_params_param import PayToolParamsParam from ...types.ai.vision_tool_params_param import VisionToolParamsParam from ...types.ai.update_dynamic_variables_tool_params_param import UpdateDynamicVariablesToolParamsParam __all__ = ["ToolsResource", "AsyncToolsResource"] class ToolsResource(SyncAPIResource): """Configure AI assistant specifications""" @cached_property def with_raw_response(self) -> ToolsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return ToolsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ToolsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return ToolsResourceWithStreamingResponse(self) def create( self, *, display_name: str, type: str, client_side_tool: Dict[str, object] | Omit = omit, function: Dict[str, object] | Omit = omit, handoff: Dict[str, object] | Omit = omit, invite: Dict[str, object] | Omit = omit, pay: PayToolParamsParam | Omit = omit, retrieval: Dict[str, object] | Omit = omit, timeout_ms: int | Omit = omit, update_dynamic_variables: UpdateDynamicVariablesToolParamsParam | Omit = omit, vision: VisionToolParamsParam | Omit = omit, webhook: Dict[str, object] | Omit = omit, idempotency_key: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SharedToolResponse: """ Create a new custom AI tool that can be attached to AI assistants. Args: update_dynamic_variables: Configuration for an update_dynamic_variables tool. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ extra_headers = {**strip_not_given({"Idempotency-Key": idempotency_key}), **(extra_headers or {})} return self._post( "/ai/tools", body=maybe_transform( { "display_name": display_name, "type": type, "client_side_tool": client_side_tool, "function": function, "handoff": handoff, "invite": invite, "pay": pay, "retrieval": retrieval, "timeout_ms": timeout_ms, "update_dynamic_variables": update_dynamic_variables, "vision": vision, "webhook": webhook, }, tool_create_params.ToolCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SharedToolResponse, ) def retrieve( self, tool_id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SharedToolResponse: """ Retrieve the details of a specific AI tool. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not tool_id: raise ValueError(f"Expected a non-empty value for `tool_id` but received {tool_id!r}") return self._get( path_template("/ai/tools/{tool_id}", tool_id=tool_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SharedToolResponse, ) def update( self, tool_id: str, *, client_side_tool: Dict[str, object] | Omit = omit, display_name: str | Omit = omit, function: Dict[str, object] | Omit = omit, handoff: Dict[str, object] | Omit = omit, invite: Dict[str, object] | Omit = omit, pay: PayToolParamsParam | Omit = omit, retrieval: Dict[str, object] | Omit = omit, timeout_ms: int | Omit = omit, type: str | Omit = omit, update_dynamic_variables: UpdateDynamicVariablesToolParamsParam | Omit = omit, vision: VisionToolParamsParam | Omit = omit, webhook: Dict[str, object] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SharedToolResponse: """ Update the configuration of an existing AI tool. Args: update_dynamic_variables: Configuration for an update_dynamic_variables tool. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not tool_id: raise ValueError(f"Expected a non-empty value for `tool_id` but received {tool_id!r}") return self._patch( path_template("/ai/tools/{tool_id}", tool_id=tool_id), body=maybe_transform( { "client_side_tool": client_side_tool, "display_name": display_name, "function": function, "handoff": handoff, "invite": invite, "pay": pay, "retrieval": retrieval, "timeout_ms": timeout_ms, "type": type, "update_dynamic_variables": update_dynamic_variables, "vision": vision, "webhook": webhook, }, tool_update_params.ToolUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SharedToolResponse, ) def list( self, *, filter_name: str | Omit = omit, filter_type: str | Omit = omit, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncDefaultFlatPagination[SharedToolResponse]: """ Retrieve a list of the custom AI tools configured on your account. Args: filter_name: Filter results by filter name. filter_type: Filter results by filter type. page_number: Page number to retrieve (1-based). page_size: Number of items to return per page. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get_api_list( "/ai/tools", page=SyncDefaultFlatPagination[SharedToolResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "filter_name": filter_name, "filter_type": filter_type, "page_number": page_number, "page_size": page_size, }, tool_list_params.ToolListParams, ), ), model=SharedToolResponse, ) def delete( self, tool_id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Permanently deletes the specified custom AI tool from your account. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not tool_id: raise ValueError(f"Expected a non-empty value for `tool_id` but received {tool_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( path_template("/ai/tools/{tool_id}", tool_id=tool_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class AsyncToolsResource(AsyncAPIResource): """Configure AI assistant specifications""" @cached_property def with_raw_response(self) -> AsyncToolsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return AsyncToolsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncToolsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return AsyncToolsResourceWithStreamingResponse(self) async def create( self, *, display_name: str, type: str, client_side_tool: Dict[str, object] | Omit = omit, function: Dict[str, object] | Omit = omit, handoff: Dict[str, object] | Omit = omit, invite: Dict[str, object] | Omit = omit, pay: PayToolParamsParam | Omit = omit, retrieval: Dict[str, object] | Omit = omit, timeout_ms: int | Omit = omit, update_dynamic_variables: UpdateDynamicVariablesToolParamsParam | Omit = omit, vision: VisionToolParamsParam | Omit = omit, webhook: Dict[str, object] | Omit = omit, idempotency_key: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SharedToolResponse: """ Create a new custom AI tool that can be attached to AI assistants. Args: update_dynamic_variables: Configuration for an update_dynamic_variables tool. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ extra_headers = {**strip_not_given({"Idempotency-Key": idempotency_key}), **(extra_headers or {})} return await self._post( "/ai/tools", body=await async_maybe_transform( { "display_name": display_name, "type": type, "client_side_tool": client_side_tool, "function": function, "handoff": handoff, "invite": invite, "pay": pay, "retrieval": retrieval, "timeout_ms": timeout_ms, "update_dynamic_variables": update_dynamic_variables, "vision": vision, "webhook": webhook, }, tool_create_params.ToolCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SharedToolResponse, ) async def retrieve( self, tool_id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SharedToolResponse: """ Retrieve the details of a specific AI tool. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not tool_id: raise ValueError(f"Expected a non-empty value for `tool_id` but received {tool_id!r}") return await self._get( path_template("/ai/tools/{tool_id}", tool_id=tool_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SharedToolResponse, ) async def update( self, tool_id: str, *, client_side_tool: Dict[str, object] | Omit = omit, display_name: str | Omit = omit, function: Dict[str, object] | Omit = omit, handoff: Dict[str, object] | Omit = omit, invite: Dict[str, object] | Omit = omit, pay: PayToolParamsParam | Omit = omit, retrieval: Dict[str, object] | Omit = omit, timeout_ms: int | Omit = omit, type: str | Omit = omit, update_dynamic_variables: UpdateDynamicVariablesToolParamsParam | Omit = omit, vision: VisionToolParamsParam | Omit = omit, webhook: Dict[str, object] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SharedToolResponse: """ Update the configuration of an existing AI tool. Args: update_dynamic_variables: Configuration for an update_dynamic_variables tool. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not tool_id: raise ValueError(f"Expected a non-empty value for `tool_id` but received {tool_id!r}") return await self._patch( path_template("/ai/tools/{tool_id}", tool_id=tool_id), body=await async_maybe_transform( { "client_side_tool": client_side_tool, "display_name": display_name, "function": function, "handoff": handoff, "invite": invite, "pay": pay, "retrieval": retrieval, "timeout_ms": timeout_ms, "type": type, "update_dynamic_variables": update_dynamic_variables, "vision": vision, "webhook": webhook, }, tool_update_params.ToolUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=SharedToolResponse, ) def list( self, *, filter_name: str | Omit = omit, filter_type: str | Omit = omit, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[SharedToolResponse, AsyncDefaultFlatPagination[SharedToolResponse]]: """ Retrieve a list of the custom AI tools configured on your account. Args: filter_name: Filter results by filter name. filter_type: Filter results by filter type. page_number: Page number to retrieve (1-based). page_size: Number of items to return per page. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get_api_list( "/ai/tools", page=AsyncDefaultFlatPagination[SharedToolResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "filter_name": filter_name, "filter_type": filter_type, "page_number": page_number, "page_size": page_size, }, tool_list_params.ToolListParams, ), ), model=SharedToolResponse, ) async def delete( self, tool_id: str, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> None: """ Permanently deletes the specified custom AI tool from your account. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not tool_id: raise ValueError(f"Expected a non-empty value for `tool_id` but received {tool_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( path_template("/ai/tools/{tool_id}", tool_id=tool_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class ToolsResourceWithRawResponse: def __init__(self, tools: ToolsResource) -> None: self._tools = tools self.create = to_raw_response_wrapper( tools.create, ) self.retrieve = to_raw_response_wrapper( tools.retrieve, ) self.update = to_raw_response_wrapper( tools.update, ) self.list = to_raw_response_wrapper( tools.list, ) self.delete = to_raw_response_wrapper( tools.delete, ) class AsyncToolsResourceWithRawResponse: def __init__(self, tools: AsyncToolsResource) -> None: self._tools = tools self.create = async_to_raw_response_wrapper( tools.create, ) self.retrieve = async_to_raw_response_wrapper( tools.retrieve, ) self.update = async_to_raw_response_wrapper( tools.update, ) self.list = async_to_raw_response_wrapper( tools.list, ) self.delete = async_to_raw_response_wrapper( tools.delete, ) class ToolsResourceWithStreamingResponse: def __init__(self, tools: ToolsResource) -> None: self._tools = tools self.create = to_streamed_response_wrapper( tools.create, ) self.retrieve = to_streamed_response_wrapper( tools.retrieve, ) self.update = to_streamed_response_wrapper( tools.update, ) self.list = to_streamed_response_wrapper( tools.list, ) self.delete = to_streamed_response_wrapper( tools.delete, ) class AsyncToolsResourceWithStreamingResponse: def __init__(self, tools: AsyncToolsResource) -> None: self._tools = tools self.create = async_to_streamed_response_wrapper( tools.create, ) self.retrieve = async_to_streamed_response_wrapper( tools.retrieve, ) self.update = async_to_streamed_response_wrapper( tools.update, ) self.list = async_to_streamed_response_wrapper( tools.list, ) self.delete = async_to_streamed_response_wrapper( tools.delete, )