Ë
    ³Œj(  ã                  ó&  — d Z ddlmZ ddlmZ ddlmZ  G d„ de«      Z G d„ de«      Z G d	„ d
e«      Z	 G d„ de«      Z
 G d„ de
«      Z G d„ de«      Z G d„ de
«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ d e«      Z G d!„ d"e«      Z G d#„ d$e«      Z G d%„ d&e«      Z G d'„ d(e«      Z G d)„ d*e«      Z G d+„ d,e«      Z G d-„ d.e«      Z G d/„ d0e«      Z G d1„ d2e«      Zy3)4züCustom exceptions for the sandbox client.

All sandbox exceptions extend LangSmithError for unified error handling.
The exceptions are organized by error type rather than resource type,
with a resource_type attribute for specific handling when needed.
é    )Úannotations)ÚOptional)ÚLangSmithErrorc                  ó   — e Zd ZdZy)ÚSandboxClientErrorz)Base exception for sandbox client errors.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úg/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langsmith/sandbox/_exceptions.pyr   r      s   „ Ù3àr   r   c                  ó   — e Zd ZdZy)ÚSandboxAPIErrorzvRaised when the API endpoint returns an unexpected error.

    For example, this is raised for wrong URL or path.
    Nr   r   r   r   r   r      ó   „ ñð
 	r   r   c                  ó   — e Zd ZdZy)ÚSandboxAuthenticationErrorz>Raised when authentication fails (invalid or missing API key).Nr   r   r   r   r   r   #   s   „ ÙHàr   r   c                  ó   — e Zd ZdZy)ÚSandboxConnectionErrorz3Raised when connection to the sandbox server fails.Nr   r   r   r   r   r   )   s   „ Ù=àr   r   c                  ó   — e Zd ZdZy)ÚSandboxRetryableConnectionErrorzÊRaised when a transient failure occurs before a command can start.

    ``run()`` retries this error with the same command ID, so the server can
    deduplicate an attempt whose outcome is unknown.
    Nr   r   r   r   r   r   /   ó   „ ñð 	r   r   c                  ó   — e Zd ZdZy)ÚSandboxConnectTimeoutErrorz¸Raised when the socket fails or times out before the WebSocket handshake.

    The execute frame was never sent, so re-issuing the same command ID cannot
    double-run a command.
    Nr   r   r   r   r   r   9   r   r   r   c                  ó   — e Zd ZdZy)ÚSandboxServerReloadErroruW  Raised when the server sends a 1001 Going Away close frame.

    This indicates a server hot-reload, not a true connection failure.
    The command is still running on the server.

    This is a subclass of SandboxConnectionError, so the auto-reconnect
    logic in CommandHandle catches it along with all other
    connection errors. The distinction matters for retry strategy:
    SandboxServerReloadError triggers immediate reconnect (no backoff),
    while other SandboxConnectionError triggers exponential backoff.

    Users typically never see this exception â€” it's handled internally.
    Nr   r   r   r   r   r   C   s   „ ñð 	r   r   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )ÚResourceNotFoundErrorz}Raised when a resource is not found.

    Attributes:
        resource_type: Type of resource (sandbox, snapshot, file).
    c                ó2   •— t         ‰| �  |«       || _        y©úInitialize the error.N©ÚsuperÚ__init__Úresource_type©ÚselfÚmessager&   Ú	__class__s      €r   r%   zResourceNotFoundError.__init__a   ó   ø€ ä‰Ñ˜Ô!Ø*ˆÕr   ©N©r)   Ústrr&   úOptional[str]©r	   r
   r   r   r%   Ú__classcell__©r*   s   @r   r   r   Z   ó   ø„ ñ÷+ò +r   r   c                  ó@   ‡ — e Zd ZdZ	 	 d	 	 	 	 	 dˆ fd„Zdˆ fd„Zˆ xZS )ÚResourceTimeoutErrorzÁRaised when an operation times out.

    Attributes:
        resource_type: Type of resource (sandbox, snapshot).
        last_status: The last known status before timeout (for sandboxes).
    c                ó@   •— t         ‰| �  |«       || _        || _        yr!   )r$   r%   r&   Úlast_status)r(   r)   r&   r7   r*   s       €r   r%   zResourceTimeoutError.__init__o   s"   ø€ ô 	‰Ñ˜Ô!Ø*ˆÔØ&ˆÕr   c                ó`   •— t         ‰| �  «       }| j                  r|› d| j                  › d�S |S )úReturn string representation.z (last_status: Ú))r$   Ú__str__r7   )r(   Úbaser*   s     €r   r;   zResourceTimeoutError.__str__z   s7   ø€ ä‰w‰Ó ˆØ×ÒØ�V˜?¨4×+;Ñ+;Ð*<¸AÐ>Ð>Øˆr   ©NN)r)   r.   r&   r/   r7   r/   ©Úreturnr.   ©r	   r
   r   r   r%   r;   r1   r2   s   @r   r5   r5   g   s;   ø„ ñð (,Ø%)ð		'àð	'ð %ð	'ð #õ		'÷ñ r   r5   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )ÚResourceInUseErrorzRaised when deleting a resource that is still in use.

    Attributes:
        resource_type: Type of resource (snapshot).
    c                ó2   •— t         ‰| �  |«       || _        yr!   r#   r'   s      €r   r%   zResourceInUseError.__init__‰   r+   r   r,   r-   r0   r2   s   @r   rB   rB   ‚   r3   r   rB   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )ÚResourceAlreadyExistsErrorz„Raised when creating a resource that already exists.

    Attributes:
        resource_type: Type of resource (e.g., snapshot).
    c                ó2   •— t         ‰| �  |«       || _        yr!   r#   r'   s      €r   r%   z#ResourceAlreadyExistsError.__init__–   r+   r   r,   r-   r0   r2   s   @r   rE   rE   �   r3   r   rE   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )ÚResourceNameConflictErrorz“Raised when updating a resource name to one that already exists.

    Attributes:
        resource_type: Type of resource (sandbox, snapshot).
    c                ó2   •— t         ‰| �  |«       || _        yr!   r#   r'   s      €r   r%   z"ResourceNameConflictError.__init__£   r+   r   r,   r-   r0   r2   s   @r   rH   rH   œ   r3   r   rH   c                  ó:   ‡ — e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 dˆ fd„Zˆ xZS )ÚValidationErrora›  Raised when request validation fails.

    This includes:
    - Resource values exceeding server-defined limits (CPU, memory, storage)
    - Invalid resource units
    - Invalid name formats

    Attributes:
        field: The field that failed validation (e.g., "cpu", "memory").
        details: List of validation error details from the API.
        error_type: Machine-readable error type from the API.
    c                óV   •— t         ‰| �  |«       || _        |xs g | _        || _        yr!   )r$   r%   ÚfieldÚdetailsÚ
error_type)r(   r)   rM   rN   rO   r*   s        €r   r%   zValidationError.__init__¼   s+   ø€ ô 	‰Ñ˜Ô!ØˆŒ
Ø’} "ˆŒØ$ˆ�r   )NNN)r)   r.   rM   r/   rN   zOptional[list[dict]]rO   r/   r0   r2   s   @r   rK   rK   ®   sC   ø„ ñð   $Ø(,Ø$(ð%àð%ð ð%ð &ð	%ð
 "÷%ñ %r   rK   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )ÚQuotaExceededErrora  Raised when organization quota limits are exceeded.

    Users should contact technical support via our Support Portal
    (https://support.langchain.com) to increase quotas.

    Attributes:
        quota_type: Type of quota exceeded (e.g., "sandbox_count", "cpu").
    c                ó2   •— t         ‰| �  |«       || _        yr!   )r$   r%   Ú
quota_type)r(   r)   rS   r*   s      €r   r%   zQuotaExceededError.__init__Ô   s   ø€ ä‰Ñ˜Ô!Ø$ˆ�r   r,   )r)   r.   rS   r/   r0   r2   s   @r   rQ   rQ   Ê   s   ø„ ñ÷%ò %r   rQ   c                  ó@   ‡ — e Zd ZdZ	 	 d	 	 	 	 	 dˆ fd„Zdˆ fd„Zˆ xZS )ÚResourceCreationErrorzíRaised when resource provisioning fails.

    Attributes:
        resource_type: Type of resource (sandbox, snapshot).
        error_type: Machine-readable error type (ImagePull, CrashLoop,
            SandboxConfig, Unschedulable).
    c                ó@   •— t         ‰| �  |«       || _        || _        yr!   )r$   r%   r&   rO   )r(   r)   r&   rO   r*   s       €r   r%   zResourceCreationError.__init__è   s!   ø€ ô 	‰Ñ˜Ô!Ø*ˆÔØ$ˆ�r   c                ót   •— | j                   rt        ‰| �	  «       › d| j                   › d�S t        ‰| �	  «       S ©r9   z [Ú]©rO   r$   r;   ©r(   r*   s    €r   r;   zResourceCreationError.__str__ó   ó7   ø€ à�?Š?Ü‘g‘oÓ'Ð(¨¨4¯?©?Ð*;¸1Ð=Ð=Ü‰w‰Ó Ð r   r=   )r)   r.   r&   r/   rO   r/   r>   r@   r2   s   @r   rU   rU   ß   s;   ø„ ñð (,Ø$(ð		%àð	%ð %ð	%ð "õ		%÷!ñ !r   rU   c                  ó   — e Zd ZdZy)ÚDataplaneNotConfiguredErrorz�Raised when dataplane_url is not available for the sandbox.

    This occurs when the sandbox-router URL is not configured for the cluster.
    Nr   r   r   r   r^   r^   ÿ   r   r   r^   c                  ó   — e Zd ZdZy)ÚSandboxNotReadyErrorzDRaised when attempting to interact with a sandbox that is not ready.Nr   r   r   r   r`   r`     s   „ ÙNàr   r`   c                  ó@   ‡ — e Zd ZdZ	 	 d	 	 	 	 	 dˆ fd„Zdˆ fd„Zˆ xZS )ÚSandboxOperationErrorzÒRaised when a sandbox operation fails (run, read, write).

    Attributes:
        operation: The operation that failed (command, read, write).
        error_type: Machine-readable error type from the API.
    c                ó@   •— t         ‰| �  |«       || _        || _        yr!   )r$   r%   Ú	operationrO   )r(   r)   rd   rO   r*   s       €r   r%   zSandboxOperationError.__init__  s    ø€ ô 	‰Ñ˜Ô!Ø"ˆŒØ$ˆ�r   c                ót   •— | j                   rt        ‰| �	  «       › d| j                   › d�S t        ‰| �	  «       S rX   rZ   r[   s    €r   r;   zSandboxOperationError.__str__!  r\   r   r=   )r)   r.   rd   r/   rO   r/   r>   r@   r2   s   @r   rb   rb     s;   ø„ ñð $(Ø$(ð		%àð	%ð !ð	%ð "õ		%÷!ñ !r   rb   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )ÚCommandTimeoutErrorz�Raised when a command exceeds its timeout.

    Attributes:
        timeout: The timeout value in seconds that was exceeded.
    c                ó8   •— t         ‰| �  |dd¬«       || _        y)r"   ÚcommandÚCommandTimeout)rd   rO   N)r$   r%   Útimeout)r(   r)   rk   r*   s      €r   r%   zCommandTimeoutError.__init__/  s   ø€ ä‰Ñ˜¨IÐBRÐÔSØˆ�r   r,   )r)   r.   rk   zOptional[int]r0   r2   s   @r   rg   rg   (  s   ø„ ñ÷ò r   rg   c                  ó   — e Zd ZdZy)ÚTunnelErrorz%Base exception for TCP tunnel errors.Nr   r   r   r   rm   rm   :  s   „ Ù/àr   rm   c                  ó$   ‡ — e Zd ZdZdˆ fd„Zˆ xZS )ÚTunnelPortNotAllowedErrorzlThe daemon rejected the port as not allowed.

    Attributes:
        port: The port that was rejected.
    c               ó2   •— t         ‰| �  |«       || _        yr!   ©r$   r%   Úport©r(   r)   rr   r*   s      €r   r%   z"TunnelPortNotAllowedError.__init__G  ó   ø€ ä‰Ñ˜Ô!Øˆ�	r   ©r)   r.   rr   Úintr0   r2   s   @r   ro   ro   @  ó   ø„ ñ÷ñ r   ro   c                  ó$   ‡ — e Zd ZdZdˆ fd„Zˆ xZS )ÚTunnelConnectionRefusedErrorzƒNothing is listening on the target port inside the sandbox.

    Attributes:
        port: The port that could not be reached.
    c               ó2   •— t         ‰| �  |«       || _        yr!   rq   rs   s      €r   r%   z%TunnelConnectionRefusedError.__init__T  rt   r   ru   r0   r2   s   @r   ry   ry   M  rw   r   ry   c                  ó   — e Zd ZdZy)ÚTunnelUnsupportedVersionErrorzCProtocol version mismatch between the tunnel client and the daemon.Nr   r   r   r   r|   r|   Z  s   „ ÙMàr   r|   N)r   Ú
__future__r   Útypingr   Úlangsmith.utilsr   r   r   r   r   r   r   r   r   r5   rB   rE   rH   rK   rQ   rU   r^   r`   rb   rg   rm   ro   ry   r|   r   r   r   Ú<module>r€      s=  ðñõ #å å *ô	˜ô 	ô	Ð(ô 	ô	Ð!3ô 	ô	Ð/ô 	ô	Ð&<ô 	ô	Ð!@ô 	ô	Ð5ô 	ô.
+Ð.ô 
+ôÐ-ô ô6
+Ð+ô 
+ô
+Ð!3ô 
+ô
+Ð 2ô 
+ô$%Ð(ô %ô8%Ð+ô %ô*!Ð.ô !ô@	Ð"4ô 	ô	Ð-ô 	ô!Ð.ô !ô4
Ð/ô 
ô$	Ð$ô 	ô
 ô 
ô
 ;ô 
ô	 Kõ 	r   