
    bix                        d Z ddlmZ ddlmZmZ ddlZddlmZ	 ddl
mZ ddlmZmZmZmZmZmZ ddlmZmZmZmZmZ dd	lmZmZmZmZ dd
ZddZ G d d      Z y)zFAsync SandboxClient class for interacting with the sandbox server API.    )annotations)AnyOptionalN)utils)AsyncSandbox)ResourceInUseErrorResourceNameConflictErrorResourceNotFoundErrorSandboxAPIErrorSandboxConnectionErrorValidationError)handle_client_http_errorhandle_pool_errorhandle_sandbox_creation_errorhandle_volume_creation_errorparse_error_response)PoolSandboxTemplateVolumeVolumeMountSpecc                 X    t        j                  dd      } | j                  d       dS )zGet the default sandbox API endpoint from environment.

    Derives the endpoint from LANGSMITH_ENDPOINT (or LANGCHAIN_ENDPOINT).
    ENDPOINTzhttps://api.smith.langchain.com)default/z/api/v2/sandboxes)ls_utilsget_env_varrstrip)bases    i/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/langsmith/sandbox/_async_client.py_get_default_api_endpointr       s/    
 
4UVDkk#011    c                 ,    t        j                  d      S )z)Get the default API key from environment.API_KEY)r   r    r!   r   _get_default_api_keyr%   &   s    	**r!   c                     e Zd ZdZdddd	 	 	 	 	 d'dZd(dZd)dZ	 	 	 	 	 	 	 	 d*dZd	d
	 	 	 	 	 	 	 d+dZd,dZ	d-dZ
d.dZddd	 	 	 	 	 	 	 d/dZddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d0dZd1dZd2dZd3dZd.dZdd
	 	 	 	 	 	 	 	 	 d4dZd5dZd6dZddd	 	 	 	 	 	 	 d7dZd.dZddd 	 	 	 	 	 	 	 d8d!Zddd 	 	 	 	 	 	 	 d8d"Zd9d#Zd:d$Zd;d%Zd.d&Zy)<AsyncSandboxClienta  Async client for interacting with the Sandbox Server API.

    This client provides an async interface for managing sandboxes and templates.

    Example:
        # Uses LANGSMITH_ENDPOINT and LANGSMITH_API_KEY from environment
        async with AsyncSandboxClient() as client:
            # Create a sandbox and run commands
            async with await client.sandbox(template_name="python-sandbox") as sandbox:
                result = await sandbox.run("python --version")
                print(result.stdout)
    Ng      $@)api_endpointtimeoutapi_keyc                   |xs
 t               j                  d      | _        |xs
 t               }i }|r||d<   t	        j
                  ||      | _        y)a  Initialize the AsyncSandboxClient.

        Args:
            api_endpoint: Full URL of the sandbox API endpoint. If not provided,
                          derived from LANGSMITH_ENDPOINT environment variable.
            timeout: Default HTTP timeout in seconds.
            api_key: API key for authentication. If not provided, uses
                     LANGSMITH_API_KEY environment variable.
        r   z	X-Api-Key)r)   headersN)r    r   	_base_urlr%   httpxAsyncClient_http)selfr(   r)   r*   resolved_api_keyr,   s         r   __init__zAsyncSandboxClient.__init__9   sT      'E*C*EMMcR"<&:&<"$#3GK &&wH
r!   c                T   K   | j                   j                          d{    y7 w)zClose the async HTTP client.N)r0   acloser1   s    r   r5   zAsyncSandboxClient.acloseP   s     jj!!!s   (&(c                   K   | S w)zEnter async context manager.r$   r6   s    r   
__aenter__zAsyncSandboxClient.__aenter__T   s     s   c                @   K   | j                          d{    y7 w)zExit async context manager.N)r5   )r1   exc_typeexc_valexc_tbs       r   	__aexit__zAsyncSandboxClient.__aexit__X   s      kkms   <   )r)   c                 K   | j                    d}||d|d}	 | j                  j                  |||dz          d{   }|j                          t	        j
                  |j                               S 7 7# t        j                  $ r}t        d|       |d}~wt        j                  $ r}t        |        d}~ww xY ww)a6  Create a new persistent volume.

        Creates a persistent storage volume that can be referenced in templates.

        Args:
            name: Volume name.
            size: Storage size (e.g., "1Gi", "10Gi").
            timeout: Timeout in seconds when waiting for ready (min: 5, max: 300).

        Returns:
            Created Volume.

        Raises:
            VolumeProvisioningError: If volume provisioning fails.
            ResourceTimeoutError: If volume doesn't become ready within timeout.
            SandboxClientError: For other errors.
        /volumesT)namesizewait_for_readyr)      jsonr)   NFailed to connect to server: )r-   r0   postraise_for_statusr   	from_dictrF   r.   ConnectErrorr   HTTPStatusErrorr   )r1   rA   rB   r)   urlpayloadresponsees           r   create_volumez AsyncSandboxClient.create_volumee   s     0  ) "	
		!ZZ__SwRT_UUH%%'##HMMO44 V !! 	U(+H)LMSTT$$ 	(+	sD   C$A8 A66A8 5C6A8 8CBC0B<<CCc                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          t	        j
                  |j                               S 7 7# t        j                  $ r}t        d|       |d}~wt        j                  $ r<}|j                  j                  dk(  rt        d| dd      |t        |        d}~ww xY ww)	zGet a volume by name.

        Args:
            name: Volume name.

        Returns:
            Volume.

        Raises:
            ResourceNotFoundError: If volume not found.
            SandboxClientError: For other errors.
        	/volumes/NrG     Volume '' not foundvolumeresource_type)r-   r0   getrI   r   rJ   rF   r.   rK   r   rL   rO   status_coder
   r   r1   rA   rM   rO   rP   s        r   
get_volumezAsyncSandboxClient.get_volume   s       	$0	!ZZ^^C00H%%'##HMMO44 1 !! 	U(+H)LMSTT$$ 	zz%%,+tfK0 %Q'	D   C$A- A+6A- *C$+A- -C! BC!%7CC!!C$c                  K   | j                    d}	 | j                  j                  |       d{   }|j                          |j	                         }|j                  dg       D cg c]  }t        j                  |       c}S 7 Wc c}w # t        j                  $ r}t        d|       |d}~wt        j                  $ r:}|j                  j                  dk(  rt        d| d      |t        |        d}~ww xY ww)zIList all volumes.

        Returns:
            List of Volumes.
        r@   NvolumesrG   rT   API endpoint not found: %. Check that api_endpoint is correct.)r-   r0   rZ   rI   rF   r   rJ   r.   rK   r   rL   rO   r[   r   r   )r1   rM   rO   datavrP   s         r   list_volumeszAsyncSandboxClient.list_volumes   s       )	!ZZ^^C00H%%'==?D15)R1HIAF$$Q'II 1 J!! 	U(+H)LMSTT$$ 	zz%%,%.se 4: ;  %Q'	V   DB B	8B *BB D	B B D#B22D5C==DDc                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          y7 # t        j
                  $ r}t        d|       |d}~wt        j                  $ ru}|j                  j                  dk(  rt        d| dd      ||j                  j                  d	k(  rt        |      }t        |d
   d      |t        |       Y d}~yd}~ww xY ww)a  Delete a volume.

        Args:
            name: Volume name.

        Raises:
            ResourceNotFoundError: If volume not found.
            ResourceInUseError: If volume is referenced by templates.
            SandboxClientError: For other errors.
        rS   NrG   rT   rU   rV   rW   rX     messager-   r0   deleterI   r.   rK   r   rL   rO   r[   r
   r   r   r   r1   rA   rM   rO   rP   rc   s         r   delete_volumez AsyncSandboxClient.delete_volume   s       	$0	(!ZZ..s33H%%' 4!! 	U(+H)LMSTT$$ 	(zz%%,+tfK0 zz%%,+A.(iQWXX$Q''	(K   C;A A	A C;	A C8A--C8A+C3.C;3C88C;)new_namerB   c                 K   | j                    d| }i }|||d<   |||d<   |s| j                  |       d{   S 	 | j                  j                  ||       d{   }|j	                          t        j                  |j                               S 7 ]7 9# t        j                  $ r}t        d|       |d}~wt        j                  $ r}|j                  j                  dk(  rt        d| d	d
      ||j                  j                  dk(  rt        |      }t!        |d   d      ||j                  j                  dk(  rt        |      }t#        |d   d
      |t%        |        d}~ww xY ww)a  Update a volume's name and/or size.

        You can update the display name, size, or both in a single request.
        Only storage size increases are allowed (storage backend limitation).

        Args:
            name: Current volume name.
            new_name: New display name (optional).
            size: New storage size (must be >= current size). Optional.

        Returns:
            Updated Volume.

        Raises:
            ResourceNotFoundError: If volume not found.
            VolumeResizeError: If storage decrease attempted.
            ResourceNameConflictError: If new_name is already in use.
            SandboxQuotaExceededError: If storage quota would be exceeded.
            SandboxClientError: For other errors.
        rS   NrA   rB   rF   rG   rT   rU   rV   rW   rX   i  ri   VolumeResize)
error_typerh   )r-   r]   r0   patchrI   r   rJ   rF   r.   rK   r   rL   rO   r[   r
   r   r   r	   r   )	r1   rA   ro   rB   rM   rN   rO   rP   rc   s	            r   update_volumez AsyncSandboxClient.update_volume   s    6  	$0"$&GFO"GFO...	!ZZ--c-@@H%%'##HMMO44 / A !! 	U(+H)LMSTT$$ 	zz%%,+tfK0 zz%%,+A.%d9o.QWXXzz%%,+A./O8 %Q'	sR   8E=BE=  B  B!6B E=B E:/B>>E:B!E55E::E=500m512Mi)cpumemorystoragevolume_mountsc                 K   | j                    d}||||dd}|r||d   d<   |r*|D 	cg c]  }	|	j                  |	j                  d c}	|d<   	 | j                  j	                  ||       d	{   }
|
j                          t        j                  |
j                               S c c}	w 7 <# t        j                  $ r}t        d
|       |d	}~wt        j                  $ r}t        |        d	}~ww xY ww)a  Create a new SandboxTemplate.

        Only the container image, resource limits, and volume mounts can be
        configured. All other container details are handled by the server.

        Args:
            name: Template name.
            image: Container image (e.g., "python:3.12-slim").
            cpu: CPU limit (e.g., "500m", "1", "2"). Default: "500m".
            memory: Memory limit (e.g., "256Mi", "1Gi"). Default: "512Mi".
            storage: Ephemeral storage limit (e.g., "1Gi"). Optional.
            volume_mounts: List of volumes to mount in the sandbox. Optional.

        Returns:
            Created SandboxTemplate.

        Raises:
            SandboxClientError: If creation fails.
        
/templates)rx   ry   )rA   image	resourcesr   rz   )volume_name
mount_pathr{   rq   NrG   )r-   r   r   r0   rH   rI   r   rJ   rF   r.   rK   r   rL   r   )r1   rA   r~   rx   ry   rz   r{   rM   rN   vmrO   rP   s               r   create_templatez"AsyncSandboxClient.create_template"  s
    :  
+  #
 .5GK + (( !#bmmL(GO$
	!ZZ__Sw_??H%%'",,X]]_==( @ !! 	U(+H)LMSTT$$ 	$Q'	sR   )C= B*C= B1 2B/36B1 )C=/B1 1C:CC:)C55C::C=c                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          t	        j
                  |j                               S 7 7# t        j                  $ r}t        d|       |d}~wt        j                  $ r<}|j                  j                  dk(  rt        d| dd      |t        |        d}~ww xY ww)	a  Get a SandboxTemplate by name.

        Args:
            name: Template name.

        Returns:
            SandboxTemplate.

        Raises:
            ResourceNotFoundError: If template not found.
            SandboxClientError: For other errors.
        /templates/NrG   rT   
Template 'rV   templaterX   )r-   r0   rZ   rI   r   rJ   rF   r.   rK   r   rL   rO   r[   r
   r   r\   s        r   get_templatezAsyncSandboxClient.get_template[  s       D62	!ZZ^^C00H%%'",,X]]_== 1 !! 	U(+H)LMSTT$$ 	zz%%,+ k2* %Q'	r^   c                  K   | j                    d}	 | j                  j                  |       d{   }|j                          |j	                         }|j                  dg       D cg c]  }t        j                  |       c}S 7 Wc c}w # t        j                  $ r}t        d|       |d}~wt        j                  $ r:}|j                  j                  dk(  rt        d| d      |t        |        d}~ww xY ww)z[List all SandboxTemplates.

        Returns:
            List of SandboxTemplates.
        r}   N	templatesrG   rT   ra   rb   )r-   r0   rZ   rI   rF   r   rJ   r.   rK   r   rL   rO   r[   r   r   )r1   rM   rO   rc   trP   s         r   list_templatesz!AsyncSandboxClient.list_templatesx  s       
+	!ZZ^^C00H%%'==?D:>((;PR:STQO--a0TT 1 U!! 	U(+H)LMSTT$$ 	zz%%,%.se 4: ;  %Q'	rf   c               B  K   | j                    d| }d|i}	 | j                  j                  ||       d{   }|j                          t	        j
                  |j                               S 7 7# t        j                  $ r}t        d|       |d}~wt        j                  $ rq}|j                  j                  dk(  rt        d| dd	
      ||j                  j                  dk(  rt        |      }t        |d   d	
      |t!        |        d}~ww xY ww)a  Update a template's display name.

        Args:
            name: Current template name.
            new_name: New display name.

        Returns:
            Updated SandboxTemplate.

        Raises:
            ResourceNotFoundError: If template not found.
            ResourceNameConflictError: If new_name is already in use.
            SandboxClientError: For other errors.
        r   rA   rq   NrG   rT   r   rV   r   rX   rh   ri   )r-   r0   rt   rI   r   rJ   rF   r.   rK   r   rL   rO   r[   r
   r   r	   r   )r1   rA   ro   rM   rN   rO   rP   rc   s           r   update_templatez"AsyncSandboxClient.update_template  s"      D628$	!ZZ--c-@@H%%'",,X]]_== A !! 	U(+H)LMSTT$$ 	zz%%,+ k2* zz%%,+A./O: %Q'	sE   D A3 A16A3 0D1A3 3DBD+A,DDDc                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          y7 # t        j
                  $ r}t        d|       |d}~wt        j                  $ ru}|j                  j                  dk(  rt        d| dd      ||j                  j                  d	k(  rt        |      }t        |d
   d      |t        |       Y d}~yd}~ww xY ww)a   Delete a SandboxTemplate.

        Args:
            name: Template name.

        Raises:
            ResourceNotFoundError: If template not found.
            ResourceInUseError: If template is referenced by sandboxes or pools.
            SandboxClientError: For other errors.
        r   NrG   rT   r   rV   r   rX   rh   ri   rj   rl   s         r   delete_templatez"AsyncSandboxClient.delete_template  s       D62	(!ZZ..s33H%%' 4!! 	U(+H)LMSTT$$ 
	(zz%%,+ k2* zz%%,+A.(O: %Q''
	(rn   rD   c                 K   | j                    d}|||d|d}	 |dz   }| j                  j                  |||       d{   }|j                          t	        j
                  |j                               S 7 7# t        j                  $ r}	t        d|	       |	d}	~	wt        j                  $ r}	t        |	        d}	~	ww xY ww)a  Create a new Sandbox Pool.

        Pools pre-provision sandboxes from a template for faster startup.

        Args:
            name: Pool name (lowercase letters, numbers, hyphens; max 63 chars).
            template_name: Name of the SandboxTemplate to use (no volume mounts).
            replicas: Number of sandboxes to pre-provision (1-100).
            timeout: Timeout in seconds when waiting for ready (10-600).

        Returns:
            Created Pool.

        Raises:
            ResourceNotFoundError: If template not found.
            ValidationError: If template has volumes attached.
            ResourceAlreadyExistsError: If pool with this name already exists.
            ResourceTimeoutError: If pool doesn't reach ready state within timeout.
            SandboxQuotaExceededError: If organization quota is exceeded.
            SandboxClientError: For other errors.
        /poolsT)rA   template_namereplicasrC   r)   rD   rE   NrG   )r-   r0   rH   rI   r   rJ   rF   r.   rK   r   rL   r   )
r1   rA   r   r   r)   rM   rN   http_timeoutrO   rP   s
             r   create_poolzAsyncSandboxClient.create_pool  s     :  ' * "#

	"R<L!ZZ__Sw_UUH%%'>>(--/22 V !! 	U(+H)LMSTT$$ 	a 	sF   C&A; A96A; 8C9A; ;CBC3B??CCc                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          t	        j
                  |j                               S 7 7# t        j                  $ r}t        d|       |d}~wt        j                  $ r<}|j                  j                  dk(  rt        d| dd      |t        |        d}~ww xY ww)	zGet a Pool by name.

        Args:
            name: Pool name.

        Returns:
            Pool.

        Raises:
            ResourceNotFoundError: If pool not found.
            SandboxClientError: For other errors.
        /pools/NrG   rT   Pool 'rV   poolrX   )r-   r0   rZ   rI   r   rJ   rF   r.   rK   r   rL   rO   r[   r
   r   r\   s        r   get_poolzAsyncSandboxClient.get_pool
  s       v.	!ZZ^^C00H%%'>>(--/22 1 !! 	U(+H)LMSTT$$ 	zz%%,+TF+.f %Q'	r^   c                  K   | j                    d}	 | j                  j                  |       d{   }|j                          |j	                         }|j                  dg       D cg c]  }t        j                  |       c}S 7 Wc c}w # t        j                  $ r}t        d|       |d}~wt        j                  $ r:}|j                  j                  dk(  rt        d| d      |t        |        d}~ww xY ww)zEList all Pools.

        Returns:
            List of Pools.
        r   NpoolsrG   rT   ra   rb   )r-   r0   rZ   rI   rF   r   rJ   r.   rK   r   rL   rO   r[   r   r   )r1   rM   rO   rc   prP   s         r   
list_poolszAsyncSandboxClient.list_pools'  s       '	!ZZ^^C00H%%'==?D/3xx/DE!DNN1%EE 1 F!! 	U(+H)LMSTT$$ 	zz%%,%.se 4: ;  %Q'	rf   )ro   r   c                 K   | j                    d| }i }|||d<   |||d<   |s| j                  |       d{   S 	 | j                  j                  ||       d{   }|j	                          t        j                  |j                               S 7 ]7 9# t        j                  $ r}t        d|       |d}~wt        j                  $ rq}|j                  j                  dk(  rt        d| d	d
      ||j                  j                  dk(  rt        |      }t!        |d   d
      |t#        |        d}~ww xY ww)a  Update a Pool's name and/or replica count.

        You can update the display name, replica count, or both.
        The template reference cannot be changed after creation.

        Args:
            name: Current pool name.
            new_name: New display name (optional).
            replicas: New number of replicas (0-100). Set to 0 to pause.

        Returns:
            Updated Pool.

        Raises:
            ResourceNotFoundError: If pool not found.
            ValidationError: If template was deleted.
            ResourceNameConflictError: If new_name is already in use.
            SandboxQuotaExceededError: If quota exceeded when scaling up.
            SandboxClientError: For other errors.
        r   NrA   r   rq   rG   rT   r   rV   r   rX   rh   ri   )r-   r   r0   rt   rI   r   rJ   rF   r.   rK   r   rL   rO   r[   r
   r   r	   r   )	r1   rA   ro   r   rM   rN   rO   rP   rc   s	            r   update_poolzAsyncSandboxClient.update_pool?  sU    6  v."$&GFO"*GJt,,,	!ZZ--c-@@H%%'>>(--/22 - A !! 	U(+H)LMSTT$$ 	zz%%,+TF+.f zz%%,+A./O6 a 	sR   8EBE  B  B!6B EB E/B>>EA,E  EEc                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          y7 # t        j
                  $ r}t        d|       |d}~wt        j                  $ r@}|j                  j                  dk(  rt        d| dd      |t        |       Y d}~yd}~ww xY ww)	zDelete a Pool.

        This will terminate all sandboxes in the pool.

        Args:
            name: Pool name.

        Raises:
            ResourceNotFoundError: If pool not found.
            SandboxClientError: For other errors.
        r   NrG   rT   r   rV   r   rX   r-   r0   rk   rI   r.   rK   r   rL   rO   r[   r
   r   r\   s        r   delete_poolzAsyncSandboxClient.delete_pooly  s       v.
	(!ZZ..s33H%%' 4!! 	U(+H)LMSTT$$ 	(zz%%,+TF+.f %Q''	(J   CA A	A C	A CA--C6B>9C>CC)rA   r)   c               X   K   | j                  |||       d{   }d|_        |S 7 w)a  Create a sandbox and return an AsyncSandbox instance.

        This is the primary method for creating sandboxes. Use it as an
        async context manager for automatic cleanup:

            async with await client.sandbox(template_name="my-template") as sandbox:
                result = await sandbox.run("echo hello")

        The sandbox is automatically deleted when exiting the context manager.
        For sandboxes with manual lifecycle management, use create_sandbox().

        Args:
            template_name: Name of the SandboxTemplate to use.
            name: Optional sandbox name (auto-generated if not provided).
            timeout: Timeout in seconds when waiting for ready.

        Returns:
            AsyncSandbox instance.

        Raises:
            ResourceTimeoutError: If timeout waiting for sandbox to be ready.
            SandboxCreationError: If sandbox creation fails.
            SandboxClientError: For other errors.
        )r   rA   r)   NT)create_sandbox_auto_delete)r1   r   rA   r)   sbs        r   sandboxzAsyncSandboxClient.sandbox  s>     > &&' ' 
 

 	
s   *(*c                 K   | j                    d}|d|d}|r||d<   	 | j                  j                  |||dz          d{   }|j                          t	        j
                  |j                         | d	      S 7 :# t        j                  $ r}t        d
|       |d}~wt        j                  $ r}t        |        d}~ww xY ww)a  Create a new Sandbox.

        The sandbox is NOT automatically deleted. Use delete_sandbox() for cleanup,
        or use sandbox() for automatic cleanup with a context manager.

        Args:
            template_name: Name of the SandboxTemplate to use.
            name: Optional sandbox name (auto-generated if not provided).
            timeout: Timeout in seconds when waiting for ready.

        Returns:
            Created AsyncSandbox.

        Raises:
            ResourceTimeoutError: If timeout waiting for sandbox to be ready.
            SandboxCreationError: If sandbox creation fails.
            SandboxClientError: For other errors.
        /boxesT)r   rC   r)   rA   rD   rE   NFclientauto_deleterG   )r-   r0   rH   rI   r   rJ   rF   r.   rK   r   rL   r   )r1   r   rA   r)   rM   rN   rO   rP   s           r   r   z!AsyncSandboxClient.create_sandbox  s     2  ' +"#

 "GFO	!ZZ__SwRT_UUH%%'))%  V
 !! 	U(+H)LMSTT$$ 	)!,	sF   C$B A?9B >C?B C
B##C
9CC

Cc                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          t	        j
                  |j                         | d      S 7 :# t        j                  $ r}t        d|       |d}~wt        j                  $ r<}|j                  j                  dk(  rt        d| dd	
      |t        |        d}~ww xY ww)aK  Get a Sandbox by name.

        The sandbox is NOT automatically deleted. Use delete_sandbox() for cleanup.

        Args:
            name: Sandbox name.

        Returns:
            AsyncSandbox.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        /boxes/NFr   rG   rT   	Sandbox 'rV   r   rX   )r-   r0   rZ   rI   r   rJ   rF   r.   rK   r   rL   rO   r[   r
   r   r\   s        r   get_sandboxzAsyncSandboxClient.get_sandbox  s       v.	!ZZ^^C00H%%'))%  1
 !! 	U(+H)LMSTT$$ 	zz%%,+v[1 %Q'	sD   C'A0 A.9A0 -C'.A0 0C$BC$(7CC$$C'c                  K   | j                    d}	 | j                  j                  |       d{   }|j                          |j	                         }|j                  dg       D cg c]  }t        j                  || d       c}S 7 Zc c}w # t        j                  $ r}t        d|       |d}~wt        j                  $ r:}|j                  j                  dk(  rt        d| d	      |t        |        d}~ww xY ww)
zRList all Sandboxes.

        Returns:
            List of AsyncSandboxes.
        r   N	sandboxesFr   rG   rT   ra   rb   )r-   r0   rZ   rI   rF   r   rJ   r.   rK   r   rL   rO   r[   r   r   )r1   rM   rO   rc   crP   s         r   list_sandboxesz!AsyncSandboxClient.list_sandboxes  s
      '	!ZZ^^C00H%%'==?D +r2 &&q5I  1 !! 	U(+H)LMSTT$$ 	zz%%,%.se 4: ;  %Q'	sV   DB B8B *B	B DB B D&B55D5D  DDc               4  K   | j                    d| }d|i}	 | j                  j                  ||       d{   }|j                          t	        j
                  |j                         | d      S 7 :# t        j                  $ r}t        d|       |d}~wt        j                  $ rg}|j                  j                  dk(  rt        d	| d
d      ||j                  j                  dk(  rt        d| dd      |t        |        d}~ww xY ww)a~  Update a sandbox's display name.

        Args:
            name: Current sandbox name.
            new_name: New display name.

        Returns:
            Updated AsyncSandbox.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            ResourceNameConflictError: If new_name is already in use.
            SandboxClientError: For other errors.
        r   rA   rq   NFr   rG   rT   r   rV   r   rX   rh   zSandbox name 'z' already in use)r-   r0   rt   rI   r   rJ   rF   r.   rK   r   rL   rO   r[   r
   r	   r   )r1   rA   ro   rM   rN   rO   rP   s          r   update_sandboxz!AsyncSandboxClient.update_sandbox*  s*      v.8$	!ZZ--c-@@H%%'))%  A
 !! 	U(+H)LMSTT$$ 	zz%%,+v[1 zz%%,/$XJ.>?"+  %Q'	sE   D A6 A49A6 3D4A6 6D	BD.A"DDDc                  K   | j                    d| }	 | j                  j                  |       d{   }|j                          y7 # t        j
                  $ r}t        d|       |d}~wt        j                  $ r@}|j                  j                  dk(  rt        d| dd      |t        |       Y d}~yd}~ww xY ww)	zDelete a Sandbox.

        Args:
            name: Sandbox name.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        r   NrG   rT   r   rV   r   rX   r   r\   s        r   delete_sandboxz!AsyncSandboxClient.delete_sandboxQ  s       v.
	(!ZZ..s33H%%' 4!! 	U(+H)LMSTT$$ 	(zz%%,+v[1 %Q''	(r   )r(   Optional[str]r)   floatr*   r   )returnNone)r   r'   )r:   zOptional[type]r;   zOptional[BaseException]r<   zOptional[Any]r   r   )rA   strrB   r   r)   intr   r   )rA   r   r   r   )r   zlist[Volume])rA   r   r   r   )rA   r   ro   r   rB   r   r   r   )rA   r   r~   r   rx   r   ry   r   rz   r   r{   zOptional[list[VolumeMountSpec]]r   r   )rA   r   r   r   )r   zlist[SandboxTemplate])rA   r   ro   r   r   r   )
rA   r   r   r   r   r   r)   r   r   r   )rA   r   r   r   )r   z
list[Pool])rA   r   ro   r   r   zOptional[int]r   r   )r   r   rA   r   r)   r   r   r   )rA   r   r   r   )r   zlist[AsyncSandbox])rA   r   ro   r   r   r   )__name__
__module____qualname____doc__r3   r5   r8   r=   rQ   r]   re   rm   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r!   r   r'   r'   +   sN     '+!%I $I 	I
 I."  ) 	
 
$ ** *
 * 
*X:0(@ #'"::  	:
 : 
:J !%9=77 7
 7 7 7 77 
7r:0#J(P 11 1 	1 1 
1f:8 #'"&88  	8
  8 
8t(D #%% 	%
 % 
%V #.. 	.
 . 
.`B6%N(r!   r'   )r   r   )r   r   )!r   
__future__r   typingr   r   r.   	langsmithr   r    langsmith.sandbox._async_sandboxr   langsmith.sandbox._exceptionsr   r	   r
   r   r   r   langsmith.sandbox._helpersr   r   r   r   r   langsmith.sandbox._modelsr   r   r   r   r    r%   r'   r$   r!   r   <module>r      sJ    L "    ' 9   U T2+
|( |(r!   