Ë
    ÂXÕiN�  ã                  óø   — d Z ddlm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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mZmZ dd	lmZmZmZm Z m!Z! dd
l"m#Z# ddl$m%Z% dd„Z&dd„Z'eee(e(f      Z) G d„ d«      Z*y)zEMain SandboxClient class for interacting with the sandbox server API.é    )Úannotations)ÚMapping)ÚAnyÚOptionalN)Úutils)ÚResourceCreationErrorÚResourceInUseErrorÚResourceNameConflictErrorÚResourceNotFoundErrorÚResourceTimeoutErrorÚSandboxAPIErrorÚValidationError)Úhandle_client_http_errorÚhandle_pool_errorÚhandle_sandbox_creation_errorÚhandle_volume_creation_errorÚmerge_headersÚparse_error_responseÚvalidate_ttl)ÚPoolÚResourceStatusÚSandboxTemplateÚVolumeÚVolumeMountSpec)ÚSandbox)ÚRetryTransportc                 óX   — t        j                  dd¬«      } | j                  d«      › d�S )z†Get the default sandbox API endpoint from environment.

    Derives the endpoint from LANGSMITH_ENDPOINT (or LANGCHAIN_ENDPOINT).
    ÚENDPOINTzhttps://api.smith.langchain.com)Údefaultú/z/v2/sandboxes)Úls_utilsÚget_env_varÚrstrip)Úbases    úe/root/rosshost/parking-map/parking-api/venv/lib/python3.12/site-packages/langsmith/sandbox/_client.pyÚ_get_default_api_endpointr&   (   s.   € ô
 ×Ñ 
Ð4UÔV€DØ�k‰k˜#ÓÐ˜}Ð-Ð-ó    c                 ó,   — t        j                  d«      S )z)Get the default API key from environment.ÚAPI_KEY)r!   r"   © r'   r%   Ú_get_default_api_keyr+   1   s   € ä×Ñ 	Ó*Ð*r'   c                  óÔ  — e Zd ZdZddddddœ	 	 	 	 	 	 	 	 	 d3d„Zd4d„Zd5d„Zd5d	„Zd6d
„Z	 	 	 	 	 	 	 	 d7d„Z	dddœ	 	 	 	 	 	 	 	 	 d8d„Z
ddœd9d„Zddœd:d„Zddœd;d„Zddddœ	 	 	 	 	 	 	 	 	 d<d„Zddddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=d„Zddœ	 	 	 	 	 d>d„Zddœ	 	 	 d?d„Zddœ	 	 	 	 	 	 	 d@d„Zddœd;d„Zdddœ	 	 	 	 	 	 	 	 	 	 	 dAd„ZddœdBd„ZddœdCd „Zdddd!œ	 	 	 	 	 	 	 	 	 dDd"„Zddœd;d#„Zdddddd$œ	 	 	 	 	 	 	 	 	 	 	 	 	 dEd%„Zddd&dddd'œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dFd(„ZddœdGd)„ZddœdHd*„Zddddd+œ	 	 	 	 	 	 	 	 	 	 	 dId,„Zddœd;d-„Zddœ	 	 	 	 	 dJd.„Zd/d0dd1œ	 	 	 	 	 	 	 	 	 dKd2„Z y)LÚSandboxClienta�  Client for interacting with the Sandbox Server API.

    This client provides a simple interface for managing sandboxes and templates.

    Example:
        # Uses LANGSMITH_ENDPOINT and LANGSMITH_API_KEY from environment
        client = SandboxClient()

        # Or with explicit configuration
        client = SandboxClient(
            api_endpoint="https://api.smith.langchain.com/v2/sandboxes",
            api_key="your-api-key",
        )

        # Create a sandbox and run commands
        with client.sandbox(template_name="python-sandbox") as sandbox:
            result = sandbox.run("python --version")
            print(result.stdout)
    Ng      $@é   )Úapi_endpointÚtimeoutÚapi_keyÚmax_retriesÚheadersc               óò   — |xs
 t        «       j                  d«      | _        |xs
 t        «       }|| _        i }|r||d<   |rt        ||«      }t        |¬«      }t        j                  |||¬«      | _	        y)ap  Initialize the SandboxClient.

        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.
            max_retries: Maximum number of retries for transient errors (502, 503,
                         504), rate limits (429), and connection failures. Set to 0
                         to disable retries. Default: 3.
        r    z	X-Api-Key)r2   )Ú	transportr0   r3   N)
r&   r#   Ú	_base_urlr+   Ú_api_keyr   r   ÚhttpxÚClientÚ_http)	Úselfr/   r0   r1   r2   r3   Úresolved_api_keyÚclient_headersr5   s	            r%   Ú__init__zSandboxClient.__init__N   sw   € ð* 'ÒEÔ*CÓ*E×MÑMÈcÓRˆŒØ"Ò<Ô&:Ó&<ÐØ(ˆŒØ)+ˆÙØ*:ˆN˜;Ñ'ÙÜ*¨>¸7ÓCˆNÜ"¨{Ô;ˆ	Ü—\‘\Ø¨¸.ô
ˆ�
r'   c                óH   — |€yt        | j                  j                  |«      S )z8Merge default client headers with per-request overrides.N)r   r:   r3   )r;   r3   s     r%   Ú_request_headerszSandboxClient._request_headersp   s!   € àˆ?ØÜ˜TŸZ™Z×/Ñ/°Ó9Ð9r'   c                ó8   — | j                   j                  «        y)zClose the HTTP client.N)r:   Úclose©r;   s    r%   rB   zSandboxClient.closev   s   € à�
‰
×ÑÕr'   c                ó†   — 	 | j                   j                  s| j                   j                  «        yy# t        $ r Y yw xY w)z,Close the HTTP client on garbage collection.N)r:   Ú	is_closedrB   Ú	ExceptionrC   s    r%   Ú__del__zSandboxClient.__del__z   s;   € ð	Ø—:‘:×'Ò'Ø—
‘
× Ñ Õ"ð (øäò 	Ùð	ús   ‚04 ´	A ¿A c                ó   — | S )zEnter context manager.r*   rC   s    r%   Ú	__enter__zSandboxClient.__enter__‚   s   € àˆr'   c                ó$   — | j                  «        y)zExit context manager.N)rB   )r;   Úexc_typeÚexc_valÚexc_tbs       r%   Ú__exit__zSandboxClient.__exit__†   s   € ð 	�
‰
�r'   é<   )r0   r3   c               óF  — | j                   › d�}||d|dœ}	 | j                  j                  |||dz   | j                  |«      ¬«      }|j	                  «        t        j                  |j                  «       «      S # t        j                  $ r}t        |«       ‚ d}~ww xY 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_readyr0   é   ©Újsonr0   r3   N)r6   r:   Úpostr@   Úraise_for_statusr   Ú	from_dictrW   r8   ÚHTTPStatusErrorr   )	r;   rR   rS   r0   r3   ÚurlÚpayloadÚresponseÚes	            r%   Úcreate_volumezSandboxClient.create_volume“   s§   € ð2 —‘Ð  Ð)ˆð ØØ"Øñ	
ˆð	Ø—z‘z—‘ØØØ "™Ø×-Ñ-¨gÓ6ð	 'ó ˆHð ×%Ñ%Ô'Ü×#Ñ# H§M¡M£OÓ4Ð4øÜ×$Ñ$ò 	Ü(¨Ô+Øûð	ús   ˜A#A< Á<B ÂBÂB ©r3   c               óˆ  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        t        j                  |j                  «       «      S # t        j                  $ r<}|j                  j                  dk(  rt        d|› d�d¬«      |‚t        |«       ‚ d}~ww xY w)	zíGet a volume by name.

        Args:
            name: Volume name.

        Returns:
            Volume.

        Raises:
            ResourceNotFoundError: If volume not found.
            SandboxClientError: For other errors.
        ú	/volumes/ra   é”  úVolume 'ú' not foundÚvolume©Úresource_typeN)r6   r:   Úgetr@   rY   r   rZ   rW   r8   r[   r^   Ústatus_coder   r   ©r;   rR   r3   r\   r^   r_   s         r%   Ú
get_volumezSandboxClient.get_volumeÂ   sµ   € ð —‘Ð  	¨$¨Ð0ˆð
	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ü×#Ñ# H§M¡M£OÓ4Ð4øÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø˜t˜f KÐ0Àôàðô % QÔ'Øûð	úó   “AA2 Á2CÂ7B<Â<Cc               óÊ  — | j                   › d�}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        |j                  «       }|j                  dg «      D �cg c]  }t        j                  |«      ‘Œ c}S c c}w # t        j                  $ r:}|j                  j                  dk(  rt        d|› d�«      |‚t        |«       ‚ d}~ww xY w)zIList all volumes.

        Returns:
            List of Volumes.
        rQ   ra   Úvolumesrd   úAPI endpoint not found: ú%. Check that api_endpoint is correct.N)r6   r:   rj   r@   rY   rW   r   rZ   r8   r[   r^   rk   r   r   )r;   r3   r\   r^   ÚdataÚvr_   s          r%   Úlist_volumeszSandboxClient.list_volumesÝ   sÔ   € ð —‘Ð  Ð)ˆð	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ø—=‘=“?ˆDØ15·±¸)ÀRÓ1HÖI¨A”F×$Ñ$ QÕ'ÒIÐIùÒIøÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü%Ø.¨s¨eð 4:ð ;óð ðô % QÔ'Øûð	úó*   ‘A B Á1BÂB ÂB ÂC"Â(5CÃC"c               ó¶  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        y
# 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)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.
        rc   ra   rd   re   rf   rg   rh   é™  ÚmessageN©r6   r:   Údeleter@   rY   r8   r[   r^   rk   r   r   r	   r   ©r;   rR   r3   r\   r^   r_   rs   s          r%   Údelete_volumezSandboxClient.delete_volumeó   sÑ   € ð —‘Ð  	¨$¨Ð0ˆð	(Ø—z‘z×(Ñ(¨°d×6KÑ6KÈGÓ6TÐ(ÓUˆHØ×%Ñ%Õ'øÜ×$Ñ$ò 	(Ø�z‰z×%Ñ%¨Ò,Ü+Ø˜t˜f KÐ0Àôàðð �z‰z×%Ñ%¨Ò,Ü+¨AÓ.�Ü(¨¨i©ÈÔQÐWXÐXÜ$ Q×'Ñ'ûð	(úó   “<A ÁCÁ#A+CÃC)Únew_namerS   r3   c               ó¨  — | j                   › d|› �}i }|�||d<   |�||d<   |s| j                  ||¬«      S 	 | j                  j                  ||| j	                  |«      ¬«      }|j                  «        t        j                  |j                  «       «      S # 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)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.
        rc   NrR   rS   ra   ©rW   r3   rd   re   rf   rg   rh   i�  ry   ÚVolumeResize)Ú
error_typerx   )r6   rm   r:   Úpatchr@   rY   r   rZ   rW   r8   r[   r^   rk   r   r   r   r
   r   )
r;   rR   r   rS   r3   r\   r]   r^   r_   rs   s
             r%   Úupdate_volumezSandboxClient.update_volume  sa  € ð8 —‘Ð  	¨$¨Ð0ˆØ"$ˆØÐØ&ˆG�F‰OØÐØ"ˆG�F‰Oáà—?‘? 4°�?Ó9Ð9ð	Ø—z‘z×'Ñ'Ø˜'¨4×+@Ñ+@ÀÓ+Ið (ó ˆHð ×%Ñ%Ô'Ü×#Ñ# H§M¡M£OÓ4Ð4øÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø˜t˜f KÐ0Àôàðð �z‰z×%Ñ%¨Ò,Ü+¨AÓ.�Ü% d¨9¡oÀ.ÔQÐWXÐXØ�z‰z×%Ñ%¨Ò,Ü+¨AÓ.�Ü/Ø˜‘O°8ôàðô % QÔ'Øûð	ús   ¸AB ÂEÂ+B!EÅEÚ500mÚ512Mi)ÚcpuÚmemoryÚstorageÚvolume_mountsr3   c               ó¸  — | j                   › d�}||||dœdœ}	|r||	d   d<   |r*|D �
cg c]  }
|
j                  |
j                  dœ‘Œ c}
|	d<   	 | j                  j	                  ||	| j                  |«      ¬«      }|j                  «        t        j                  |j                  «       «      S c c}
w # t        j                  $ r}t        |«       ‚ d	}~ww xY 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)rˆ   r‰   )rR   ÚimageÚ	resourcesr�   rŠ   )Úvolume_nameÚ
mount_pathr‹   r�   N)r6   r�   r‘   r:   rX   r@   rY   r   rZ   rW   r8   r[   r   )r;   rR   rŽ   rˆ   r‰   rŠ   r‹   r3   r\   r]   Úvmr^   r_   s                r%   Úcreate_templatezSandboxClient.create_templateN  sí   € ð< —‘Ð  
Ð+ˆð ØàØ ññ#
ˆñ Ø.5ˆG�KÑ  Ñ+Ùð (ö(àð !#§¡¸b¿m¹mÓLò(ˆG�OÑ$ð
	Ø—z‘z—‘Ø˜'¨4×+@Ñ+@ÀÓ+Ið 'ó ˆHð ×%Ñ%Ô'Ü"×,Ñ,¨X¯]©]«_Ó=Ð=ùò(øô ×$Ñ$ò 	Ü$ QÔ'Øûð	ús   © B0ÁAB5 Â5CÃCÃCc               óˆ  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        t        j                  |j                  «       «      S # t        j                  $ r<}|j                  j                  dk(  rt        d|› d�d¬«      |‚t        |«       ‚ d}~ww xY w)	a  Get a SandboxTemplate by name.

        Args:
            name: Template name.

        Returns:
            SandboxTemplate.

        Raises:
            ResourceNotFoundError: If template not found.
            SandboxClientError: For other errors.
        ú/templates/ra   rd   ú
Template 'rf   Útemplaterh   N)r6   r:   rj   r@   rY   r   rZ   rW   r8   r[   r^   rk   r   r   rl   s         r%   Úget_templatezSandboxClient.get_templateˆ  sµ   € ð —‘Ð  ¨D¨6Ð2ˆð
	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ü"×,Ñ,¨X¯]©]«_Ó=Ð=øÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø    kÐ2À*ôàðô % QÔ'Øûð	úrn   c               óÊ  — | j                   › d�}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        |j                  «       }|j                  dg «      D �cg c]  }t        j                  |«      ‘Œ c}S c c}w # t        j                  $ r:}|j                  j                  dk(  rt        d|› d�«      |‚t        |«       ‚ d}~ww xY w)z[List all SandboxTemplates.

        Returns:
            List of SandboxTemplates.
        r�   ra   Ú	templatesrd   rq   rr   N)r6   r:   rj   r@   rY   rW   r   rZ   r8   r[   r^   rk   r   r   )r;   r3   r\   r^   rs   Útr_   s          r%   Úlist_templateszSandboxClient.list_templates¥  sÕ   € ð —‘Ð  
Ð+ˆð	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ø—=‘=“?ˆDØ:>¿(¹(À;ÐPRÓ:SÖT°Q”O×-Ñ-¨aÕ0ÒTÐTùÒTøÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü%Ø.¨s¨eð 4:ð ;óð ðô % QÔ'Øûð	úrv   c               óü  — | j                   › d|› �}d|i}	 | j                  j                  ||| j                  |«      ¬«      }|j	                  «        t        j                  |j                  «       «      S # 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)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•   rR   r�   rd   r–   rf   r—   rh   rx   ry   N)r6   r:   r„   r@   rY   r   rZ   rW   r8   r[   r^   rk   r   r   r
   r   )	r;   rR   r   r3   r\   r]   r^   r_   rs   s	            r%   Úupdate_templatezSandboxClient.update_template½  s  € ð" —‘Ð  ¨D¨6Ð2ˆØ˜8Ð$ˆð	Ø—z‘z×'Ñ'Ø˜'¨4×+@Ñ+@ÀÓ+Ið (ó ˆHð ×%Ñ%Ô'Ü"×,Ñ,¨X¯]©]«_Ó=Ð=øÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø    kÐ2À*ôàðð �z‰z×%Ñ%¨Ò,Ü+¨AÓ.�Ü/Ø˜‘O°:ôàðô % QÔ'Øûð	ús   —AA7 Á7C;Â
A,C6Ã6C;c               ó¶  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        y
# 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)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•   ra   rd   r–   rf   r—   rh   rx   ry   Nrz   r|   s          r%   Údelete_templatezSandboxClient.delete_templateä  sØ   € ð —‘Ð  ¨D¨6Ð2ˆð	(Ø—z‘z×(Ñ(¨°d×6KÑ6KÈGÓ6TÐ(ÓUˆHØ×%Ñ%Õ'øÜ×$Ñ$ò 
	(Ø�z‰z×%Ñ%¨Ò,Ü+Ø    kÐ2À*ôàðð �z‰z×%Ñ%¨Ò,Ü+¨AÓ.�Ü(Ø˜‘O°:ôàðô % Q×'Ñ'ûð
	(úr~   rU   c               óL  — | j                   › d�}|||d|dœ}	 |dz   }| j                  j                  |||| j                  |«      ¬«      }	|	j	                  «        t        j                  |	j                  «       «      S # t        j                  $ r}
t        |
«       ‚ d}
~
ww xY 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)rR   Útemplate_nameÚreplicasrT   r0   rU   rV   N)r6   r:   rX   r@   rY   r   rZ   rW   r8   r[   r   )r;   rR   r£   r¤   r0   r3   r\   r]   Úhttp_timeoutr^   r_   s              r%   Úcreate_poolzSandboxClient.create_pool  s­   € ð< —‘Ð  Ð'ˆð Ø*Ø Ø"Øñ#
ˆð	Ø" R™<ˆLØ—z‘z—‘ØØØ$Ø×-Ñ-¨gÓ6ð	 'ó ˆHð ×%Ñ%Ô'Ü—>‘> (§-¡-£/Ó2Ð2øÜ×$Ñ$ò 	Ü˜aÔ Øûð	ús   ™A%A? Á?B#ÂBÂB#c               óˆ  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        t        j                  |j                  «       «      S # t        j                  $ r<}|j                  j                  dk(  rt        d|› d�d¬«      |‚t        |«       ‚ d}~ww xY w)	zåGet a Pool by name.

        Args:
            name: Pool name.

        Returns:
            Pool.

        Raises:
            ResourceNotFoundError: If pool not found.
            SandboxClientError: For other errors.
        ú/pools/ra   rd   úPool 'rf   Úpoolrh   N)r6   r:   rj   r@   rY   r   rZ   rW   r8   r[   r^   rk   r   r   rl   s         r%   Úget_poolzSandboxClient.get_pool:  s³   € ð —‘Ð  ¨ vÐ.ˆð
	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ü—>‘> (§-¡-£/Ó2Ð2øÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø˜T˜F +Ð.¸fôàðô % QÔ'Øûð	úrn   c               óÊ  — | j                   › d�}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        |j                  «       }|j                  dg «      D �cg c]  }t        j                  |«      ‘Œ c}S c c}w # t        j                  $ r:}|j                  j                  dk(  rt        d|› d�«      |‚t        |«       ‚ d}~ww xY w)zEList all Pools.

        Returns:
            List of Pools.
        r¢   ra   Úpoolsrd   rq   rr   N)r6   r:   rj   r@   rY   rW   r   rZ   r8   r[   r^   rk   r   r   )r;   r3   r\   r^   rs   Úpr_   s          r%   Ú
list_poolszSandboxClient.list_poolsU  sÒ   € ð —‘Ð  Ð'ˆð	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ø—=‘=“?ˆDØ/3¯x©x¸ÀÓ/DÖE¨!”D—N‘N 1Õ%ÒEÐEùÒEøÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü%Ø.¨s¨eð 4:ð ;óð ðô % QÔ'Øûð	úrv   )r   r¤   r3   c               ó>  — | j                   › d|› �}i }|�||d<   |�||d<   |s| j                  ||¬«      S 	 | j                  j                  ||| j	                  |«      ¬«      }|j                  «        t        j                  |j                  «       «      S # 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)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¨   NrR   r¤   ra   r�   rd   r©   rf   rª   rh   rx   ry   )r6   r«   r:   r„   r@   rY   r   rZ   rW   r8   r[   r^   rk   r   r   r
   r   )
r;   rR   r   r¤   r3   r\   r]   r^   r_   rs   s
             r%   Úupdate_poolzSandboxClient.update_poolk  s0  € ð8 —‘Ð  ¨ vÐ.ˆà"$ˆØÐØ&ˆG�F‰OØÐØ"*ˆG�JÑáà—=‘= ¨w�=Ó7Ð7ð	Ø—z‘z×'Ñ'Ø˜'¨4×+@Ñ+@ÀÓ+Ið (ó ˆHð ×%Ñ%Ô'Ü—>‘> (§-¡-£/Ó2Ð2øÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø˜T˜F +Ð.¸fôàðð �z‰z×%Ñ%¨Ò,Ü+¨AÓ.�Ü/Ø˜‘O°6ôàðô ˜aÔ Øûð	ús   ¸AB ÂDÂ+A,DÄDc               óL  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        y# t
        j                  $ r@}|j                  j                  dk(  rt        d|› d�d¬«      |‚t        |«       Y d}~yd}~ww xY w)	zôDelete 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¨   ra   rd   r©   rf   rª   rh   N©r6   r:   r{   r@   rY   r8   r[   r^   rk   r   r   rl   s         r%   Údelete_poolzSandboxClient.delete_pool¦  s¡   € ð —‘Ð  ¨ vÐ.ˆð	(Ø—z‘z×(Ñ(¨°d×6KÑ6KÈGÓ6TÐ(ÓUˆHØ×%Ñ%Õ'øÜ×$Ñ$ò 	(Ø�z‰z×%Ñ%¨Ò,Ü+Ø˜T˜F +Ð.¸fôàðô % Q×'Ñ'ûð	(úó   “<A ÁB#Á#6BÂB#)rR   r0   Úttl_secondsÚidle_ttl_secondsr3   c               óB   — | j                  ||||||¬«      }d|_        |S )a‰  Create a sandbox and return a Sandbox instance.

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

            with client.sandbox(template_name="my-template") as sandbox:
                result = 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.
            ttl_seconds: Maximum lifetime in seconds from creation. The sandbox
                will be automatically deleted after this duration. Must be a
                multiple of 60. 0 or None disables this TTL.
            idle_ttl_seconds: Idle timeout in seconds. The sandbox will be
                automatically deleted after this duration of inactivity. Must be
                a multiple of 60. 0 or None disables this TTL.

        Returns:
            Sandbox instance.

        Raises:
            ResourceTimeoutError: If timeout waiting for sandbox to be ready.
            ResourceCreationError: If sandbox creation fails.
            SandboxClientError: For other errors.
            ValueError: If TTL values are invalid.
        )r£   rR   r0   r¶   r·   r3   T)Úcreate_sandboxÚ_auto_delete)r;   r£   rR   r0   r¶   r·   r3   Úsbs           r%   ÚsandboxzSandboxClient.sandboxÂ  s:   € ðR × Ñ Ø'ØØØ#Ø-Øð !ó 
ˆð ˆŒØˆ	r'   T)rR   r0   rT   r¶   r·   r3   c               ó¼  — t        |d«       t        |d«       | j                  › d�}||dœ}	|r||	d<   |r||	d<   |�||	d<   |�||	d<   |r|dz   nd}
	 | j                  j                  ||	|
| j	                  |«      ¬	«      }|j                  «        t        j                  |j                  «       | d
¬«      S # t        j                  $ r}t        |«       ‚ d}~ww xY 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 (only used when
                wait_for_ready=True).
            wait_for_ready: If True (default), block until sandbox is ready.
                If False, return immediately with status "provisioning". Use
                get_sandbox_status() or wait_for_sandbox() to poll for readiness.
            ttl_seconds: Maximum lifetime in seconds from creation. The sandbox
                will be automatically deleted after this duration. Must be a
                multiple of 60. 0 or None disables this TTL.
            idle_ttl_seconds: Idle timeout in seconds. The sandbox will be
                automatically deleted after this duration of inactivity. Must be
                a multiple of 60. 0 or None disables this TTL.

        Returns:
            Created Sandbox. When wait_for_ready=False, the sandbox will have
            status="provisioning" and cannot be used for operations until ready.

        Raises:
            ResourceTimeoutError: If timeout waiting for sandbox to be ready.
            ResourceCreationError: If sandbox creation fails.
            SandboxClientError: For other errors.
            ValueError: If TTL values are invalid.
        r¶   r·   ú/boxes)r£   rT   r0   rR   NrU   rV   F©ÚclientÚauto_delete)r   r6   r:   rX   r@   rY   r   rZ   rW   r8   r[   r   )r;   r£   rR   r0   rT   r¶   r·   r3   r\   r]   r¥   r^   r_   s                r%   r¹   zSandboxClient.create_sandboxö  s  € ôR 	�[ -Ô0ÜÐ%Ð'9Ô:à—‘Ð  Ð'ˆð +Ø,ñ#
ˆñ Ø!(ˆG�IÑÙØ"ˆG�F‰OØÐ"Ø%0ˆG�MÑ"ØÐ'Ø*:ˆGÐ&Ñ'á)7˜ "š¸Rˆð	Ø—z‘z—‘ØØØ$Ø×-Ñ-¨gÓ6ð	 'ó ˆHð ×%Ñ%Ô'Ü×$Ñ$ X§]¡]£_¸TÈuÔUÐUøÜ×$Ñ$ò 	Ü)¨!Ô,Øûð	ús   ÁA#B7 Â7CÃ
CÃCc               óŽ  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        t        j                  |j                  «       | d¬«      S # t        j                  $ r<}|j                  j                  dk(  rt        d|› d�d¬	«      |‚t        |«       ‚ d
}~ww xY w)aF  Get a Sandbox by name.

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

        Args:
            name: Sandbox name.

        Returns:
            Sandbox.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        ú/boxes/ra   Fr¿   rd   ú	Sandbox 'rf   r¼   rh   N)r6   r:   rj   r@   rY   r   rZ   rW   r8   r[   r^   rk   r   r   rl   s         r%   Úget_sandboxzSandboxClient.get_sandbox@  s¹   € ð —‘Ð  ¨ vÐ.ˆð
	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ü×$Ñ$ X§]¡]£_¸TÈuÔUÐUøÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø ˜v [Ð1Àôàðô % QÔ'Øûð	ús   “A!A5 Á5CÂ7B?Â?Cc               óÐ  — | j                   › d�}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        |j                  «       }|j                  dg «      D �cg c]  }t        j                  || d¬«      ‘Œ c}S c c}w # t        j                  $ r:}|j                  j                  dk(  rt        d|› d�«      |‚t        |«       ‚ d	}~ww xY w)
zMList all Sandboxes.

        Returns:
            List of Sandboxes.
        r¾   ra   Ú	sandboxesFr¿   rd   rq   rr   N)r6   r:   rj   r@   rY   rW   r   rZ   r8   r[   r^   rk   r   r   )r;   r3   r\   r^   rs   Úcr_   s          r%   Úlist_sandboxeszSandboxClient.list_sandboxes]  sè   € ð —‘Ð  Ð'ˆð	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ø—=‘=“?ˆDð Ÿ™ +¨rÓ2öàô ×!Ñ! !¨D¸eÖDòð ùò øô ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü%Ø.¨s¨eð 4:ð ;óð ðô % QÔ'Øûð	ús*   ‘A B Á1BÂB ÂB ÂC%Â+5C Ã C%)r   r¶   r·   r3   c               óD  — t        |d«       t        |d«       | j                  › d|› �}i }|�||d<   |�||d<   |�||d<   	 | j                  j                  ||| j	                  |«      ¬«      }|j                  «        t        j                  |j                  «       | d¬«      S # 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)a£  Update a sandbox's properties.

        Args:
            name: Current sandbox name.
            new_name: New display name.
            ttl_seconds: Maximum lifetime in seconds from creation. Must be a
                multiple of 60. 0 disables this TTL.
            idle_ttl_seconds: Idle timeout in seconds. Must be a multiple of 60.
                0 disables this TTL.

        Returns:
            Updated Sandbox.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            ResourceNameConflictError: If new_name is already in use.
            SandboxClientError: For other errors.
            ValueError: If TTL values are invalid.
        r¶   r·   rÃ   NrR   r�   Fr¿   rd   rÄ   rf   r¼   rh   rx   zSandbox name 'z' already in use)r   r6   r:   r„   r@   rY   r   rZ   rW   r8   r[   r^   rk   r   r
   r   )
r;   rR   r   r¶   r·   r3   r\   r]   r^   r_   s
             r%   Úupdate_sandboxzSandboxClient.update_sandboxv  sF  € ô8 	�[ -Ô0ÜÐ%Ð'9Ô:à—‘Ð  ¨ vÐ.ˆØ"$ˆØÐØ&ˆG�F‰OØÐ"Ø%0ˆG�MÑ"ØÐ'Ø*:ˆGÐ&Ñ'ð	Ø—z‘z×'Ñ'Ø˜'¨4×+@Ñ+@ÀÓ+Ið (ó ˆHð ×%Ñ%Ô'Ü×$Ñ$ X§]¡]£_¸TÈuÔUÐUøÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø ˜v [Ð1Àôàðð �z‰z×%Ñ%¨Ò,Ü/Ø$ X JÐ.>Ð?Ø"+ôð ðô % QÔ'Øûð	ús   ÁA"B% Â%DÂ8A"DÄDc               óL  — | j                   › d|› �}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        y# t
        j                  $ r@}|j                  j                  dk(  rt        d|› d�d¬«      |‚t        |«       Y d}~yd}~ww xY w)	zÅDelete a Sandbox.

        Args:
            name: Sandbox name.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        rÃ   ra   rd   rÄ   rf   r¼   rh   Nr³   rl   s         r%   Údelete_sandboxzSandboxClient.delete_sandbox±  s¡   € ð —‘Ð  ¨ vÐ.ˆð	(Ø—z‘z×(Ñ(¨°d×6KÑ6KÈGÓ6TÐ(ÓUˆHØ×%Ñ%Õ'øÜ×$Ñ$ò 	(Ø�z‰z×%Ñ%¨Ò,Ü+Ø ˜v [Ð1Àôàðô % Q×'Ñ'ûð	(úrµ   c               óŠ  — | j                   › d|› d�}	 | j                  j                  || j                  |«      ¬«      }|j	                  «        t        j                  |j                  «       «      S # t        j                  $ r<}|j                  j                  dk(  rt        d|› d�d¬«      |‚t        |«       ‚ d	}~ww xY w)
aà  Get the provisioning status of a sandbox.

        This is a lightweight endpoint designed for high-frequency polling
        during sandbox provisioning. It returns only the status fields
        without full sandbox data.

        Args:
            name: Sandbox name.

        Returns:
            ResourceStatus with status and status_message.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        rÃ   z/statusra   rd   rÄ   rf   r¼   rh   N)r6   r:   rj   r@   rY   r   rZ   rW   r8   r[   r^   rk   r   r   rl   s         r%   Úget_sandbox_statusz SandboxClient.get_sandbox_statusÇ  s·   € ð& —‘Ð  ¨ v¨WÐ5ˆð
	Ø—z‘z—~‘~ c°4×3HÑ3HÈÓ3Q�~ÓRˆHØ×%Ñ%Ô'Ü!×+Ñ+¨H¯M©M«OÓ<Ð<øÜ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø ˜v [Ð1Àôàðô % QÔ'Øûð	ús   ”AA3 Á3CÂ7B=Â=Céx   g      ð?)r0   Úpoll_intervalr3   c               ó–  — ddl }|j                  «       |z   }	 | j                  ||¬«      }|j                  dk(  r| j	                  ||¬«      S |j                  dk(  rt        |j                  xs dd¬«      ‚||j                  «       z
  }|dk  rt        d	|› d
|› d�d|j                  ¬«      ‚|j                  t        ||«      «       Œ²)a§  Poll until a sandbox reaches "ready" or "failed" status.

        Uses the lightweight status endpoint for polling, then fetches the
        full sandbox data once ready.

        Args:
            name: Sandbox name.
            timeout: Maximum time to wait in seconds.
            poll_interval: Time between status checks in seconds.

        Returns:
            Sandbox in "ready" status.

        Raises:
            ResourceCreationError: If sandbox status becomes "failed".
            ResourceTimeoutError: If timeout expires while still "provisioning".
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        r   Nra   ÚreadyÚfailedzSandbox provisioning failedr¼   rh   rÄ   z' not ready after Ús)ri   Úlast_status)
ÚtimeÚ	monotonicrÏ   ÚstatusrÅ   r   Ústatus_messager   ÚsleepÚmin)	r;   rR   r0   rÑ   r3   r×   ÚdeadlinerÙ   Ú	remainings	            r%   Úwait_for_sandboxzSandboxClient.wait_for_sandboxè  sÛ   € ó6 	à—>‘>Ó# gÑ-ˆØØ×,Ñ,¨T¸7Ð,ÓCˆFØ�}‰} Ò'Ø×'Ñ'¨°gÐ'Ó>Ð>Ø�}‰} Ò(Ü+Ø×)Ñ)ÒJÐ-JØ"+ôð ð ! 4§>¡>Ó#3Ñ3ˆIØ˜AŠ~Ü*Ø ˜vÐ%7¸°yÀÐBØ"+Ø &§¡ôð ð
 �J‰J”s˜=¨)Ó4Ô5ð! r'   )
r/   úOptional[str]r0   Úfloatr1   rà   r2   Úintr3   zOptional[RequestHeaders])r3   ÚRequestHeadersÚreturnzOptional[dict[str, str]])rä   ÚNone)rä   r-   )rK   zOptional[type]rL   zOptional[BaseException]rM   zOptional[Any]rä   rå   )
rR   ÚstrrS   ræ   r0   râ   r3   rã   rä   r   )rR   ræ   r3   rã   rä   r   )r3   rã   rä   zlist[Volume])rR   ræ   r3   rã   rä   rå   )
rR   ræ   r   rà   rS   rà   r3   rã   rä   r   )rR   ræ   rŽ   ræ   rˆ   ræ   r‰   ræ   rŠ   rà   r‹   zOptional[list[VolumeMountSpec]]r3   rã   rä   r   )rR   ræ   r3   rã   rä   r   )r3   rã   rä   zlist[SandboxTemplate])rR   ræ   r   ræ   r3   rã   rä   r   )rR   ræ   r£   ræ   r¤   râ   r0   râ   r3   rã   rä   r   )rR   ræ   r3   rã   rä   r   )r3   rã   rä   z
list[Pool])
rR   ræ   r   rà   r¤   úOptional[int]r3   rã   rä   r   )r£   ræ   rR   rà   r0   râ   r¶   rç   r·   rç   r3   rã   rä   r   )r£   ræ   rR   rà   r0   râ   rT   Úboolr¶   rç   r·   rç   r3   rã   rä   r   )rR   ræ   r3   rã   rä   r   )r3   rã   rä   zlist[Sandbox])rR   ræ   r   rà   r¶   rç   r·   rç   r3   rã   rä   r   )rR   ræ   r3   rã   rä   r   )
rR   ræ   r0   râ   rÑ   rá   r3   rã   rä   r   )!Ú__name__Ú
__module__Ú__qualname__Ú__doc__r>   r@   rB   rG   rI   rN   r`   rm   ru   r}   r…   r“   r˜   rœ   rž   r    r¦   r«   r¯   r±   r´   r¼   r¹   rÅ   rÉ   rË   rÍ   rÏ   rß   r*   r'   r%   r-   r-   9   sV  „ ñð. '+ØØ!%ØØ,0ñ 
ð $ð 
ð ð	 
ð
 ð 
ð ð 
ð *ó 
óD:óóóðà ðð )ðð ð	ð
 
óð$ Ø"&ñ-àð-ð ð-ð
 ð-ð  ð-ð 
ó-ð^ BFõ ð6 9=õ ð, EIõ (ð< #'Ø"Ø"&ñ;àð;ð  ð	;ð
 ð;ð  ð;ð 
ó;ðL ØØ!%Ø9=Ø"&ñ8àð8ð ð8ð
 ð8ð ð8ð ð8ð 7ð8ð  ð8ð 
ó8ðv 7;ñØðØ%3ðà	óð< ,0ñØ(ðà	óð2 FJñ%Øð%Ø&)ð%Ø4Bð%à	ó%ðN GKõ (ðL Ø"&ñ4àð4ð ð4ð ð	4ð ð4ð  ð4ð 
ó4ðl @Dõ ð6 7;õ ð4 #'Ø"&Ø"&ñ9àð9ð  ð	9ð
  ð9ð  ð9ð 
ó9ðv CGõ (ð@ #ØØ%)Ø*.Ø"&ñ2àð2ð ð	2ð
 ð2ð #ð2ð (ð2ð  ð2ð 
ó2ðp #ØØ#Ø%)Ø*.Ø"&ñHàðHð ð	Hð
 ðHð ðHð #ðHð (ðHð  ðHð 
óHðT CGõ ð: ;?õ ð: #'Ø%)Ø*.Ø"&ñ9àð9ð  ð	9ð
 #ð9ð (ð9ð  ð9ð 
ó9ðv FJõ (ð. 7;ñØðØ%3ðà	óðJ Ø"Ø"&ñ.6àð.6ð ð	.6ð
 ð.6ð  ð.6ð 
ô.6r'   r-   )rä   ræ   )rä   rà   )+rì   Ú
__future__r   Úcollections.abcr   Útypingr   r   r8   Ú	langsmithr   r!   Úlangsmith.sandbox._exceptionsr   r	   r
   r   r   r   r   Úlangsmith.sandbox._helpersr   r   r   r   r   r   r   Úlangsmith.sandbox._modelsr   r   r   r   r   Úlangsmith.sandbox._sandboxr   Úlangsmith.sandbox._transportr   r&   r+   ræ   rã   r-   r*   r'   r%   ú<module>rö      sr   ðÙ Kå "å #ß  ã å '÷÷ ñ ÷÷ ñ ÷õ õ /Ý 7ó.ó+ð
 ˜' # s (Ñ+Ñ,€÷]6ò ]6r'   