# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Iterable, Optional from typing_extensions import Literal import httpx from ..types import environment_list_params, environment_send_message_params from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from .._utils import path_template, maybe_transform, 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 .._base_client import make_request_options from ..types.environment_list_response import EnvironmentListResponse from ..types.environment_retrieve_response import EnvironmentRetrieveResponse from ..types.environment_send_message_response import EnvironmentSendMessageResponse __all__ = ["EnvironmentsResource", "AsyncEnvironmentsResource"] class EnvironmentsResource(SyncAPIResource): @cached_property def with_raw_response(self) -> EnvironmentsResourceWithRawResponse: """ 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/letta-ai/letta-python#accessing-raw-response-data-eg-headers """ return EnvironmentsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> EnvironmentsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/letta-ai/letta-python#with_streaming_response """ return EnvironmentsResourceWithStreamingResponse(self) def retrieve( self, device_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, ) -> EnvironmentRetrieveResponse: """ Get a specific environment connection by deviceId 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 device_id: raise ValueError(f"Expected a non-empty value for `device_id` but received {device_id!r}") return self._get( path_template("/v1/environments/{device_id}", device_id=device_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=EnvironmentRetrieveResponse, ) def list( self, *, after: str | Omit = omit, limit: str | Omit = omit, online_only: str | Omit = omit, source: Literal["local", "remote"] | Omit = omit, user_id: 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, ) -> EnvironmentListResponse: """ List all active environment connections for the organization 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 """ return self._get( "/v1/environments", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "after": after, "limit": limit, "online_only": online_only, "source": source, "user_id": user_id, }, environment_list_params.EnvironmentListParams, ), ), cast_to=EnvironmentListResponse, ) def send_message( self, connection_id: str, *, messages: Iterable[environment_send_message_params.Message], agent_id: str | Omit = omit, conversation_id: Optional[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, ) -> EnvironmentSendMessageResponse: """ Send a message to a specific environment connection 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 connection_id: raise ValueError(f"Expected a non-empty value for `connection_id` but received {connection_id!r}") return self._post( path_template("/v1/environments/{connection_id}/messages", connection_id=connection_id), body=maybe_transform( { "messages": messages, "agent_id": agent_id, "conversation_id": conversation_id, }, environment_send_message_params.EnvironmentSendMessageParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=EnvironmentSendMessageResponse, ) class AsyncEnvironmentsResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncEnvironmentsResourceWithRawResponse: """ 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/letta-ai/letta-python#accessing-raw-response-data-eg-headers """ return AsyncEnvironmentsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncEnvironmentsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/letta-ai/letta-python#with_streaming_response """ return AsyncEnvironmentsResourceWithStreamingResponse(self) async def retrieve( self, device_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, ) -> EnvironmentRetrieveResponse: """ Get a specific environment connection by deviceId 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 device_id: raise ValueError(f"Expected a non-empty value for `device_id` but received {device_id!r}") return await self._get( path_template("/v1/environments/{device_id}", device_id=device_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=EnvironmentRetrieveResponse, ) async def list( self, *, after: str | Omit = omit, limit: str | Omit = omit, online_only: str | Omit = omit, source: Literal["local", "remote"] | Omit = omit, user_id: 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, ) -> EnvironmentListResponse: """ List all active environment connections for the organization 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 """ return await self._get( "/v1/environments", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=await async_maybe_transform( { "after": after, "limit": limit, "online_only": online_only, "source": source, "user_id": user_id, }, environment_list_params.EnvironmentListParams, ), ), cast_to=EnvironmentListResponse, ) async def send_message( self, connection_id: str, *, messages: Iterable[environment_send_message_params.Message], agent_id: str | Omit = omit, conversation_id: Optional[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, ) -> EnvironmentSendMessageResponse: """ Send a message to a specific environment connection 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 connection_id: raise ValueError(f"Expected a non-empty value for `connection_id` but received {connection_id!r}") return await self._post( path_template("/v1/environments/{connection_id}/messages", connection_id=connection_id), body=await async_maybe_transform( { "messages": messages, "agent_id": agent_id, "conversation_id": conversation_id, }, environment_send_message_params.EnvironmentSendMessageParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=EnvironmentSendMessageResponse, ) class EnvironmentsResourceWithRawResponse: def __init__(self, environments: EnvironmentsResource) -> None: self._environments = environments self.retrieve = to_raw_response_wrapper( environments.retrieve, ) self.list = to_raw_response_wrapper( environments.list, ) self.send_message = to_raw_response_wrapper( environments.send_message, ) class AsyncEnvironmentsResourceWithRawResponse: def __init__(self, environments: AsyncEnvironmentsResource) -> None: self._environments = environments self.retrieve = async_to_raw_response_wrapper( environments.retrieve, ) self.list = async_to_raw_response_wrapper( environments.list, ) self.send_message = async_to_raw_response_wrapper( environments.send_message, ) class EnvironmentsResourceWithStreamingResponse: def __init__(self, environments: EnvironmentsResource) -> None: self._environments = environments self.retrieve = to_streamed_response_wrapper( environments.retrieve, ) self.list = to_streamed_response_wrapper( environments.list, ) self.send_message = to_streamed_response_wrapper( environments.send_message, ) class AsyncEnvironmentsResourceWithStreamingResponse: def __init__(self, environments: AsyncEnvironmentsResource) -> None: self._environments = environments self.retrieve = async_to_streamed_response_wrapper( environments.retrieve, ) self.list = async_to_streamed_response_wrapper( environments.list, ) self.send_message = async_to_streamed_response_wrapper( environments.send_message, )