# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations import httpx from ....._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ....._utils import path_template, maybe_transform, strip_not_given, async_maybe_transform from ....._compat import cached_property 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.assistants.tests import run_list_params, run_trigger_params from .....types.ai.assistants.tests.test_run_response import TestRunResponse __all__ = ["RunsResource", "AsyncRunsResource"] class RunsResource(SyncAPIResource): """Configure AI assistant specifications""" @cached_property def with_raw_response(self) -> RunsResourceWithRawResponse: """ 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 RunsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> RunsResourceWithStreamingResponse: """ 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 RunsResourceWithStreamingResponse(self) def retrieve( self, run_id: str, *, test_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, ) -> TestRunResponse: """ Retrieves detailed information about a specific test run execution 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 test_id: raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}") if not run_id: raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}") return self._get( path_template("/ai/assistants/tests/{test_id}/runs/{run_id}", test_id=test_id, run_id=run_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResponse, ) def list( self, test_id: str, *, page_number: int | Omit = omit, page_size: int | Omit = omit, status: 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, ) -> SyncDefaultFlatPagination[TestRunResponse]: """ Retrieves paginated execution history for a specific assistant test with filtering options Args: status: Filter runs by execution status (pending, running, completed, failed, timeout) 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 test_id: raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}") return self._get_api_list( path_template("/ai/assistants/tests/{test_id}/runs", test_id=test_id), page=SyncDefaultFlatPagination[TestRunResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "page_number": page_number, "page_size": page_size, "status": status, }, run_list_params.RunListParams, ), ), model=TestRunResponse, ) def trigger( self, test_id: str, *, destination_version_id: str | 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, ) -> TestRunResponse: """ Initiates immediate execution of a specific assistant test Args: destination_version_id: Optional assistant version ID to use for this test run. If provided, the version must exist or a 400 error will be returned. If not provided, test will run on main version 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 test_id: raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}") extra_headers = {**strip_not_given({"Idempotency-Key": idempotency_key}), **(extra_headers or {})} return self._post( path_template("/ai/assistants/tests/{test_id}/runs", test_id=test_id), body=maybe_transform( {"destination_version_id": destination_version_id}, run_trigger_params.RunTriggerParams ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResponse, ) class AsyncRunsResource(AsyncAPIResource): """Configure AI assistant specifications""" @cached_property def with_raw_response(self) -> AsyncRunsResourceWithRawResponse: """ 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 AsyncRunsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncRunsResourceWithStreamingResponse: """ 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 AsyncRunsResourceWithStreamingResponse(self) async def retrieve( self, run_id: str, *, test_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, ) -> TestRunResponse: """ Retrieves detailed information about a specific test run execution 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 test_id: raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}") if not run_id: raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}") return await self._get( path_template("/ai/assistants/tests/{test_id}/runs/{run_id}", test_id=test_id, run_id=run_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResponse, ) def list( self, test_id: str, *, page_number: int | Omit = omit, page_size: int | Omit = omit, status: 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, ) -> AsyncPaginator[TestRunResponse, AsyncDefaultFlatPagination[TestRunResponse]]: """ Retrieves paginated execution history for a specific assistant test with filtering options Args: status: Filter runs by execution status (pending, running, completed, failed, timeout) 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 test_id: raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}") return self._get_api_list( path_template("/ai/assistants/tests/{test_id}/runs", test_id=test_id), page=AsyncDefaultFlatPagination[TestRunResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "page_number": page_number, "page_size": page_size, "status": status, }, run_list_params.RunListParams, ), ), model=TestRunResponse, ) async def trigger( self, test_id: str, *, destination_version_id: str | 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, ) -> TestRunResponse: """ Initiates immediate execution of a specific assistant test Args: destination_version_id: Optional assistant version ID to use for this test run. If provided, the version must exist or a 400 error will be returned. If not provided, test will run on main version 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 test_id: raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}") extra_headers = {**strip_not_given({"Idempotency-Key": idempotency_key}), **(extra_headers or {})} return await self._post( path_template("/ai/assistants/tests/{test_id}/runs", test_id=test_id), body=await async_maybe_transform( {"destination_version_id": destination_version_id}, run_trigger_params.RunTriggerParams ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResponse, ) class RunsResourceWithRawResponse: def __init__(self, runs: RunsResource) -> None: self._runs = runs self.retrieve = to_raw_response_wrapper( runs.retrieve, ) self.list = to_raw_response_wrapper( runs.list, ) self.trigger = to_raw_response_wrapper( runs.trigger, ) class AsyncRunsResourceWithRawResponse: def __init__(self, runs: AsyncRunsResource) -> None: self._runs = runs self.retrieve = async_to_raw_response_wrapper( runs.retrieve, ) self.list = async_to_raw_response_wrapper( runs.list, ) self.trigger = async_to_raw_response_wrapper( runs.trigger, ) class RunsResourceWithStreamingResponse: def __init__(self, runs: RunsResource) -> None: self._runs = runs self.retrieve = to_streamed_response_wrapper( runs.retrieve, ) self.list = to_streamed_response_wrapper( runs.list, ) self.trigger = to_streamed_response_wrapper( runs.trigger, ) class AsyncRunsResourceWithStreamingResponse: def __init__(self, runs: AsyncRunsResource) -> None: self._runs = runs self.retrieve = async_to_streamed_response_wrapper( runs.retrieve, ) self.list = async_to_streamed_response_wrapper( runs.list, ) self.trigger = async_to_streamed_response_wrapper( runs.trigger, )