§
    ~Štjr  ã                  ó,  — d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZmZmZmZ ddlZddlmZmZmZ ddl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 m!Z!m"Z" e	rddl#m$Z$ ddl%m&Z& ddl'm(Z( eee)e)f                  Z*e G d„ d¦  «        ¦   «         Z+dS )z?Sandbox class for interacting with a specific sandbox instance.é    )Úannotations)ÚMapping)Ú	dataclassÚfield)ÚTYPE_CHECKINGÚAnyÚCallableÚLiteralÚOptionalÚUnionÚoverloadN)ÚDataplaneNotConfiguredErrorÚResourceNotFoundErrorÚSandboxConnectTimeoutError)Úhandle_sandbox_http_error)ÚCommandHandleÚExecutionResultÚ
ServiceURLÚSnapshotÚ_StreamEndedBeforeStarted)ÚTunnel)ÚWEBSOCKETS_AVAILABLEÚconnect_deadlineÚopen_timeout_for)ÚAsyncSandboxClient©ÚAsyncSandbox)ÚSandboxClientc                  ó–  — e Zd ZU dZded<   dZded<   dZded<   dZded	<   dZded
<   dZ	ded<   dZ
ded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<    edd¬¦  «        Zded<    edd¬¦  «        Zded<   e	 dsdtd!„¦   «         Zdd"œdud%„Zdvd&„Zdwd.„Zdxd/„Zed0d0d0d0d0d0d0d0d0d0d0d0d1œdydE„¦   «         Zed0d0d0d0d0d0d0d0d0d0d0dFœdzdI„¦   «         ZdJdddKdddLddMdddd1œd{dO„ZdLddMdddPœd|dQ„Zd}dR„ZdSdSddTœd~dX„ZdJddYœdd]„Z dJddYœd€d_„Z!dSd`ddaœd�df„Z"dMddgœd‚dk„Z#dlddYœdƒdm„Z$ddnœd„do„Z%ddnœd„dp„Z&dJddYœd…dr„Z'dS )†ÚSandboxa  Represents an active sandbox for running commands and file operations.

    This class is typically obtained from SandboxClient.sandbox() and supports
    the context manager protocol for automatic cleanup.

    Attributes:
        name: Display name (can be updated).
        dataplane_url: URL for data plane operations (file I/O, command execution).
            Only functional when status is "ready".
        id: Unique identifier (UUID). Remains constant even if name changes.
            May be None for resources created before ID support was added.
        status: Sandbox lifecycle status. One of "provisioning", "ready",
            "failed", "stopped".
        status_message: Human-readable details when status is "failed", None otherwise.
        created_at: Timestamp when the sandbox was created.
        updated_at: Timestamp when the sandbox was last updated.
        idle_ttl_seconds: Idle timeout TTL in seconds (``0`` means disabled).
            Newly-created sandboxes receive a server-side default of ``600``
            seconds (10 minutes) when the caller did not set ``idle_ttl_seconds``
            explicitly. The launcher stops the sandbox after this many idle
            seconds; deletion is anchored to ``stopped_at`` and controlled by
            ``delete_after_stop_seconds`` (see below).
        delete_after_stop_seconds: Seconds after a sandbox enters the
            ``stopped`` state before it (and its filesystem clone) are
            permanently deleted. ``0`` disables stop-anchored deletion;
            ``None`` falls back to the server default.
        stopped_at: Timestamp when the sandbox transitioned to ``stopped``,
            or ``None`` while running. The deletion deadline is
            ``stopped_at + delete_after_stop_seconds``.
        snapshot_id: Snapshot ID used to create this sandbox.
        vcpus: Number of vCPUs allocated.
        mem_bytes: Memory allocation in bytes.
        fs_capacity_bytes: Root filesystem capacity in bytes.

    Example:
        with client.sandbox(snapshot_id="<snapshot-uuid>") as sandbox:
            result = sandbox.run("python --version")
            print(result.stdout)
    ÚstrÚnameNúOptional[str]Údataplane_urlÚidÚreadyÚstatusÚstatus_messageÚ
created_atÚ
updated_atzOptional[int]Úidle_ttl_secondsÚdelete_after_stop_secondsÚ
stopped_atÚsnapshot_idÚvcpusÚ	mem_bytesÚfs_capacity_bytesF)ÚreprÚdefaultr   Ú_clientTÚboolÚ_auto_deleteÚdataúdict[str, Any]ÚclientÚauto_deleteÚreturnc           	     ó†  —  | di d|                      dd¦  «        “d|                      d¦  «        “d|                      d¦  «        “d|                      dd¦  «        “d|                      d¦  «        “d|                      d¦  «        “d	|                      d	¦  «        “d
|                      d
¦  «        “d|                      d¦  «        “d|                      d¦  «        “d|                      d¦  «        “d|                      d¦  «        “d|                      d¦  «        “d|                      d¦  «        “d|“d|“ŽS )a4  Create a Sandbox from API response dict.

        Args:
            data: API response dictionary containing sandbox data.
            client: Parent SandboxClient for operations.
            auto_delete: Whether to delete the sandbox on context exit.

        Returns:
            Sandbox instance.
        r"   Ú r$   r%   r'   r&   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r4   r6   © )Úget)Úclsr7   r9   r:   s       úX/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langsmith/sandbox/_sandbox.pyÚ	from_dictzSandbox.from_dictf   s”  € ð" ˆsð 
ð 
ð 
Ø—’˜& "Ñ%Ô%Ð%ð
àŸ(š( ?Ñ3Ô3Ð3ð
ð �xŠx˜‰~Œ~ˆ~ð
ð —8’8˜H gÑ.Ô.Ð.ð	
ð
  Ÿ8š8Ð$4Ñ5Ô5Ð5ð
ð —x’x Ñ-Ô-Ð-ð
ð —x’x Ñ-Ô-Ð-ð
ð "ŸXšXÐ&8Ñ9Ô9Ð9ð
ð '+§h¢hÐ/JÑ&KÔ&KÐ&Kð
ð —x’x Ñ-Ô-Ð-ð
ð Ÿš Ñ/Ô/Ð/ð
ð —(’(˜7Ñ#Ô#Ð#ð
ð —h’h˜{Ñ+Ô+Ð+ð
ð #ŸhšhÐ':Ñ;Ô;Ð;ð
ð �Fð
ð  %˜ð!
ð 	
ó    )r9   úOptional[AsyncSandboxClient]r   c               ó<  — ddl m}  |di d| j        “d| j        “d| j        “d| j        “d| j        “d| j        “d	| j        “d
| j	        “d| j
        “d| j        “d| j        “d| j        “d| j        “d| j        “d|�|n| j                             ¦   «         “dd“ŽS )a"  Create an AsyncSandbox for the same underlying sandbox.

        The returned instance has ``auto_delete`` disabled so the sandbox's
        lifecycle stays tied to this instance; both refer to the same
        server-side sandbox.

        Args:
            client: AsyncSandboxClient to use for operations. If not provided,
                one is created with the same configuration as this sandbox's
                client (see :meth:`SandboxClient.to_async`).

        Returns:
            AsyncSandbox referring to the same sandbox.
        r   r   r"   r$   r%   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r4   Nr6   Fr>   )Ú langsmith.sandbox._async_sandboxr   r"   r$   r%   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r4   Úto_async)Úselfr9   r   s      rA   rG   zSandbox.to_asyncŠ   s*  € ð 	BÐAÐAÐAÐAÐAàˆ|ð 
ð 
ð 
Ø”�ð
àÔ,Ð,ð
ð Œwˆwð
ð ”;�;ð	
ð
  Ô.Ð.ð
ð ”�ð
ð ”�ð
ð "Ô2Ð2ð
ð '+Ô&DÐ&Dð
ð ”�ð
ð Ô(Ð(ð
ð ”*�*ð
ð ”n�nð
ð #Ô4Ð4ð
ð %Ð0�F�F°d´l×6KÒ6KÑ6MÔ6Møð
ð  ˜ð!
ð 	
rC   c                ó   — | S )zEnter context manager.r>   ©rH   s    rA   Ú	__enter__zSandbox.__enter__®   s   € àˆrC   Úexc_typeúOptional[type]Úexc_valúOptional[BaseException]Úexc_tbúOptional[Any]ÚNonec                óz   — | j         r3	 | j                             | j        ¦  «         dS # t          $ r Y dS w xY wdS )z6Exit context manager, optionally deleting the sandbox.N)r6   r4   Údelete_sandboxr"   Ú	Exception)rH   rL   rN   rP   s       rA   Ú__exit__zSandbox.__exit__²   s^   € ð Ôð 	ðØ”×+Ò+¨D¬IÑ6Ô6Ð6Ð6Ð6øÝð ð ð à��ðøøøð	ð 	s   ‰* ª
8·8c                óN   — | j         st          d| j        › d�¦  «        ‚| j         S )aã  Return the dataplane URL.

        The client does not gate on lifecycle status: a stopped sandbox is
        resumed by the platform when the dataplane request arrives, so only the
        presence of a URL is required here. A genuinely not-ready box surfaces
        the server's ``SandboxNotReadyError`` from the request itself.

        Returns:
            The dataplane URL.

        Raises:
            DataplaneNotConfiguredError: If dataplane_url is not configured.
        z	Sandbox 'zW' does not have a dataplane_url configured. Runtime operations require a dataplane URL.)r$   r   r"   rJ   s    rA   Ú_require_dataplane_urlzSandbox._require_dataplane_urlÀ   sD   € ð Ô!ð 	Ý-ð>˜DœIð >ð >ð >ñô ð ð Ô!Ð!rC   .)ÚtimeoutÚenvÚcwdÚshellÚ	on_stdoutÚ	on_stderrÚidle_timeoutÚkill_on_disconnectÚttl_secondsÚptyÚheadersÚwaitÚcommandrY   ÚintrZ   úOptional[dict[str, str]]r[   r\   r]   úOptional[Callable[[str], Any]]r^   r_   r`   ra   rb   rc   ÚRequestHeadersrd   úLiteral[True]r   c               ó   — d S ©Nr>   ©rH   re   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   s                 rA   ÚrunzSandbox.runÕ   s	   € ð" ˜#rC   )rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   úLiteral[False]r   c               ó   — d S rl   r>   rm   s                 rA   rn   zSandbox.runè   s	   € ð" ˜rC   é<   z	/bin/bashi,  iX  ú%Union[ExecutionResult, CommandHandle]c               ó2  — |s|s|rt          d¦  «        ‚|                      ¦   «          | p|p|}|r"|                      ||||||||||	|
||¬¦  «        S t          r"|                      |||||ddd||	|
||¬¦  «        S |                      ||||||¬¦  «        S )aS
  Execute a command in the sandbox.

        Args:
            command: Shell command to execute.
            timeout: Command timeout in seconds.
            env: Environment variables to set for the command.
            cwd: Working directory for command execution. If None, uses sandbox default.
            shell: Shell to use for command execution. Defaults to "/bin/bash".
            on_stdout: Callback invoked with each stdout chunk as it arrives.
                Blocks until the command completes and returns ExecutionResult.
                Cannot be combined with wait=False.
            on_stderr: Callback invoked with each stderr chunk as it arrives.
                Blocks until the command completes and returns ExecutionResult.
                Cannot be combined with wait=False.
            idle_timeout: Idle timeout in seconds. If the command has no
                connected clients for this duration, it is killed. Defaults
                to 300 (5 minutes). Set to -1 for no idle timeout.
                Only applies to WebSocket execution.
            kill_on_disconnect: If True, kill the command immediately when
                the last client disconnects. Defaults to False (command
                continues running and can be reconnected to).
            ttl_seconds: How long (in seconds) a finished command's session
                is kept for reconnection. Defaults to 600 (10 minutes).
                Set to -1 to keep indefinitely.
            pty: If True, allocate a pseudo-terminal for the command.
                Useful for commands that require a TTY (e.g., interactive
                programs, commands that use terminal control codes).
                Defaults to False.
            wait: If True (default), block until the command completes and
                return ExecutionResult. If False, return a
                CommandHandle immediately for streaming output,
                kill, stdin input, and reconnection. Cannot be combined with
                on_stdout/on_stderr callbacks.

        Returns:
            ExecutionResult when wait=True (default).
            CommandHandle when wait=False.

        Raises:
            ValueError: If wait=False is combined with callbacks.
            DataplaneNotConfiguredError: If dataplane_url is not configured.
            SandboxOperationError: If command execution fails.
            CommandTimeoutError: If command exceeds its timeout.
            SandboxConnectionError: If connection to sandbox fails after retries.
            SandboxNotReadyError: If sandbox is not ready.
            SandboxClientError: For other errors.
        z}Cannot combine wait=False with on_stdout/on_stderr callbacks. Use wait=False and iterate the CommandHandle, or use callbacks.)rY   rZ   r[   r\   rd   r]   r^   r_   r`   ra   rb   rc   TN)rY   rZ   r[   r\   rc   )Ú
ValueErrorrX   Ú_run_wsr   Ú	_run_http)rH   re   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   Úuse_wss                  rA   rn   zSandbox.runû   s  € ð@ ð 	˜ð 	 ið 	ÝðRñô ð ð
 	×#Ò#Ñ%Ô%Ð%ð �Ð3˜YÐ3¨)ˆØð 	Ø—<’<ØØØØØØØ#Ø#Ø)Ø#5Ø'ØØð  ñ ô ð õ$  ð 	Ø—<’<ØØØØØØØØØ)Ø#5Ø'ØØð  ñ ô ð ð �~Š~ØØØØØØð ñ 
ô 
ð 	
rC   )r_   r`   ra   rb   rc   c          
     ó¾  — ddl }ddlm} ddlm} |                      ¦   «         }| j        j        } |¦   «         j        }||||||	|
||dœ	}| j         	                    |¦  «        }|r||d<   d}t          ¦   «         }	 t          |¦  «        |d<    ||||fi |¤Ž\  }}	 t          ||| ||¬	¦  «        }n # t          t          f$ r‹ |d
z  }|t          j        k    r‚ t!          t          j        d|d
z
  z  z  t          j        ¦  «        }|�.||                     ¦   «         z
  }|dk    r‚ t!          ||¦  «        }|                     |¦  «         Y nw xY wŒÖ|s|S |j        S )z"Execute via WebSocket /execute/ws.r   N)Úrun_ws_stream)Úuuid7)	Ú
command_idrY   rZ   r[   r\   r_   r`   ra   rb   rc   TÚopen_timeout)r]   r^   é   é   )ÚtimeÚlangsmith.sandbox._ws_executery   Úlangsmith.uuidrz   rX   r4   Ú_api_keyÚhexÚ_ws_default_headersr   r   r   r   r   ÚMAX_AUTO_RECONNECTSÚminÚ_BACKOFF_BASEÚ_BACKOFF_MAXÚ	monotonicÚsleepÚresult)rH   re   rY   rZ   r[   r\   rd   r]   r^   r_   r`   ra   rb   rc   r   ry   rz   r$   Úapi_keyr{   Ú	ws_kwargsÚmergedÚattemptÚdeadlineÚ
msg_streamÚcontrolÚhandleÚbackoffÚ	remainings                                rA   ru   zSandbox._run_wsq  s  € ð$ 	ˆˆˆà?Ð?Ð?Ð?Ð?Ð?Ø(Ð(Ð(Ð(Ð(Ð(à×3Ò3Ñ5Ô5ˆØ”,Ô'ˆð �U‘W”W”[ˆ
ð %ØØØØØ(Ø"4Ø&Øð
%
ð 
%
ˆ	ð ”×1Ò1°'Ñ:Ô:ˆØð 	*Ø#)ˆI�iÑ àˆÝ#Ñ%Ô%ˆð 	$Ý(8¸Ñ(BÔ(BˆI�nÑ%Ø"/ -ØØØð#ð #ð ð	#ð #ÑˆJ˜ð$Ý&ØØØØ'Ø'ðñ ô �ð øÝ-Õ/IÐJð $ð $ð $ð ˜1‘�Ø�]Ô>Ò>Ð>ØÝÝ!Ô/°1¸À1¹Ñ3EÑFÝ!Ô.ñô �ð Ð'Ø (¨4¯>ª>Ñ+;Ô+;Ñ ;�IØ  A’~�~ØÝ! '¨9Ñ5Ô5�GØ—
’
˜7Ñ#Ô#Ð#Ð#Ð#ð$øøøð# 	$ðD ð 	ØˆMàŒ}Ðs   ÂB4 Â4BEÅEc               ó  — |                       ¦   «         }|› d�}|||dœ}	|�||	d<   |�||	d<   	 | j        j                             ||	|dz   | j                             |¦  «        ¬¦  «        }
|
                     ¦   «          |
                     ¦   «         }t          |                     dd	¦  «        |                     d
d	¦  «        |                     dd¦  «        ¬¦  «        S # t          j
        $ r}t          |¦  «         ‚ d}~ww xY w)z9Execute via HTTP POST /execute (existing implementation).z/execute)re   rY   r\   NrZ   r[   é
   )ÚjsonrY   rc   Ústdoutr=   ÚstderrÚ	exit_codeéÿÿÿÿ)r™   rš   r›   )rX   r4   Ú_httpÚpostÚ_request_headersÚraise_for_statusr˜   r   r?   ÚhttpxÚHTTPStatusErrorr   )rH   re   rY   rZ   r[   r\   rc   r$   ÚurlÚpayloadÚresponser7   Úes                rA   rv   zSandbox._run_httpÉ  s:  € ð ×3Ò3Ñ5Ô5ˆØÐ(Ð(Ð(ˆàØØð#
ð #
ˆð
 ˆ?Ø ˆG�E‰NØˆ?Ø ˆG�E‰Nð	Ø”|Ô)×.Ò.ØØØ "™Øœ×5Ò5°gÑ>Ô>ð	 /ñ ô ˆHð ×%Ò%Ñ'Ô'Ð'Ø—=’=‘?”?ˆDÝ"Ø—x’x ¨"Ñ-Ô-Ø—x’x ¨"Ñ-Ô-ØŸ(š( ;°Ñ3Ô3ðñ ô ð øõ
 Ô$ð 	ð 	ð 	Ý% aÑ(Ô(Ð(Øøøøøð	øøøs   ¯B3C# Ã#DÃ2DÄDr   )Ústdout_offsetÚstderr_offsetrc   r{   r§   r¨   c               óà   — ddl m} |                      ¦   «         }| j        j        }||dœ}| j                             |¦  «        }	|	r|	|d<    ||||fi |¤Ž\  }
}t          |
|| |||¬¦  «        S )a³  Reconnect to a running or recently-finished command.

        Resumes output from the given byte offsets. Any output produced while
        the client was disconnected is replayed from the server's ring buffer.

        Args:
            command_id: The command ID from handle.command_id.
            stdout_offset: Byte offset to resume stdout from (default: 0).
            stderr_offset: Byte offset to resume stderr from (default: 0).

        Returns:
            A CommandHandle for the command.

        Raises:
            SandboxOperationError: If command_id is not found or session expired.
            SandboxConnectionError: If connection to sandbox fails after retries.
        r   )Úreconnect_ws_stream)r§   r¨   rc   )r{   r§   r¨   )r€   rª   rX   r4   r‚   r„   r   )rH   r{   r§   r¨   rc   rª   r$   rŒ   Úreconnect_kwargsrŽ   r‘   r’   s               rA   Ú	reconnectzSandbox.reconnectò  sË   € ð2 	FÐEÐEÐEÐEÐEà×3Ò3Ñ5Ô5ˆØ”,Ô'ˆð +Ø*ð,
ð ,
Ðð ”×1Ò1°'Ñ:Ô:ˆØð 	1Ø*0Ð˜YÑ'à1Ð1ØØØð
ð 
ð ð	
ð 
Ñˆ
�Gõ ØØØØ!Ø'Ø'ð
ñ 
ô 
ð 	
rC   ©rY   rc   ÚpathÚcontentúUnion[str, bytes]c          	     ó–  — |                       ¦   «         }|› d�}t          |t          ¦  «        r|                     d¦  «        }dd|fi}	 | j        j                             |d|i||| j                             |¦  «        ¬¦  «        }|                     ¦   «          dS # t          j
        $ r}	t          |	¦  «         Y d}	~	dS d}	~	ww xY w)a*  Write content to a file in the sandbox.

        Args:
            path: Target file path in the sandbox.
            content: File content (str or bytes).
            timeout: Request timeout in seconds.

        Raises:
            DataplaneNotConfiguredError: If dataplane_url is not configured.
            SandboxOperationError: If file write fails.
            SandboxConnectionError: If connection to sandbox fails after retries.
            SandboxNotReadyError: If sandbox is not ready.
            SandboxClientError: For other errors.
        z/uploadzutf-8Úfiler®   )ÚparamsÚfilesrY   rc   N)rX   Ú
isinstancer!   Úencoder4   r�   rž   rŸ   r    r¡   r¢   r   )
rH   r®   r¯   rY   rc   r$   r£   r´   r¥   r¦   s
             rA   ÚwritezSandbox.write(  sú   € ð, ×3Ò3Ñ5Ô5ˆØÐ'Ð'Ð'ˆõ �g�sÑ#Ô#ð 	.Ø—n’n WÑ-Ô-ˆGà˜& 'Ð*Ð+ˆð
	)Ø”|Ô)×.Ò.ØØ �~ØØØœ×5Ò5°gÑ>Ô>ð /ñ ô ˆHð ×%Ò%Ñ'Ô'Ð'Ð'Ð'øÝÔ$ð 	)ð 	)ð 	)Ý% aÑ(Ô(Ð(Ð(Ð(Ð(Ð(Ð(Ð(øøøøð	)øøøs   ÁAB ÂCÂ.CÃCÚbytesc               ó�  — |                       ¦   «         }|› d�}	 | j        j                             |d|i|| j                             |¦  «        ¬¦  «        }|                     ¦   «          |j        S # t          j        $ rC}|j	        j
        dk    rt          d|› d| j        › d�d¬	¦  «        |‚t          |¦  «         ‚ d
}~ww xY w)aÈ  Read a file from the sandbox.

        Args:
            path: File path to read. Supports both absolute paths (e.g., /tmp/file.txt)
                  and relative paths (resolved from /home/user/).
            timeout: Request timeout in seconds.

        Returns:
            File contents as bytes.

        Raises:
            DataplaneNotConfiguredError: If dataplane_url is not configured.
            ResourceNotFoundError: If the file doesn't exist.
            SandboxOperationError: If file read fails.
            SandboxConnectionError: If connection to sandbox fails after retries.
            SandboxNotReadyError: If sandbox is not ready.
            SandboxClientError: For other errors.
        z	/downloadr®   )r³   rY   rc   i”  zFile 'z' not found in sandbox 'ú'r²   )Úresource_typeN)rX   r4   r�   r?   rŸ   r    r¯   r¡   r¢   r¥   Ústatus_coder   r"   r   )rH   r®   rY   rc   r$   r£   r¥   r¦   s           rA   ÚreadzSandbox.readS  s   € ð* ×3Ò3Ñ5Ô5ˆØÐ)Ð)Ð)ˆð	Ø”|Ô)×-Ò-ØØ �~ØØœ×5Ò5°gÑ>Ô>ð	 .ñ ô ˆHð ×%Ò%Ñ'Ô'Ð'ØÔ#Ð#øÝÔ$ð 	ð 	ð 	ØŒzÔ%¨Ò,Ð,Ý+ØG˜TÐGÐG¸4¼9ÐGÐGÐGØ"(ðñ ô ð ðõ & aÑ(Ô(Ð(àøøøøð	øøøs   ›AA3 Á3CÂ>C Ã Cé   ©Ú
local_portÚmax_reconnectsrc   Úremote_portrÀ   rÁ   r   c               ó$  — d|cxk    rdk    sn t          d|› d�¦  «        ‚|r"d|cxk    rdk    sn t          d|› d�¦  «        ‚|                      ¦   «         }| j        j        }t	          ||||||¬¦  «        }|                     ¦   «          |S )aþ  Open a TCP tunnel to a port inside the sandbox.

        Creates a local TCP listener that forwards connections through a
        yamux-multiplexed WebSocket to the specified port inside the sandbox.
        Works with any TCP protocol (databases, Redis, HTTP, etc.).

        Use as a context manager for automatic cleanup::

            with sandbox.tunnel(remote_port=5432) as t:
                conn = psycopg2.connect(host="127.0.0.1", port=t.local_port)

        Or manage the lifecycle explicitly::

            t = sandbox.tunnel(remote_port=5432)
            # ... use tunnel ...
            t.close()

        Args:
            remote_port: TCP port inside the sandbox to tunnel to (1-65535).
            local_port: Local port to listen on. Defaults to mirroring
                remote_port. Use 0 to let the OS pick an available port.
            max_reconnects: Maximum number of automatic reconnect attempts
                when the WebSocket session drops. Set to 0 to disable.

        Returns:
            A Tunnel instance (context manager).

        Raises:
            ValueError: If port values are out of range.
            DataplaneNotConfiguredError: If dataplane_url is not configured.
            SandboxNotReadyError: If sandbox is not ready.
        r}   iÿÿ  z-remote_port must be between 1 and 65535 (got ú)z,local_port must be between 1 and 65535 (got r¿   )rt   rX   r4   r‚   r   Ú_start)rH   rÂ   rÀ   rÁ   rc   r$   rŒ   Úts           rA   ÚtunnelzSandbox.tunnel~  sã   € ðP �KÐ(Ð(Ò(Ð( 5Ò(Ð(Ð(Ð(ÝØNÀÐNÐNÐNñô ð ð ð 	˜a :Ð6Ð6Ò6Ð6°Ò6Ð6Ð6Ð6ÝØL¸zÐLÐLÐLñô ð ð ×3Ò3Ñ5Ô5ˆØ”,Ô'ˆÝØØØØ!Ø)Øð
ñ 
ô 
ˆð 	
�Š‰
Œ
ˆ
ØˆrC   ©Úexpires_in_secondsrc   ÚportrÉ   r   c               óH   — | j                              | j        |||¬¦  «        S )a¹  Get an authenticated URL for a service running in this sandbox.

        Returns a :class:`ServiceURL` whose properties auto-refresh the
        token transparently before it expires.

        Args:
            port: Port the service is listening on inside the sandbox.
            expires_in_seconds: Token TTL in seconds (1--86400, default 600).
            headers: Optional per-request header overrides.

        Returns:
            ServiceURL with auto-refreshing token and HTTP helpers.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            ValueError: If port or expires_in_seconds is out of range.
            SandboxClientError: For other errors.
        rÈ   )r4   Úservicer"   )rH   rÊ   rÉ   rc   s       rA   rÌ   zSandbox.service»  s1   € ð2 Œ|×#Ò#ØŒIØØ1Øð	 $ñ 
ô 
ð 	
rC   éx   c               óz   — | j                              | j        ||¬¦  «        }|j        | _        |j        | _        dS )a1  Start a stopped sandbox and wait until ready.

        After starting, the sandbox's status and dataplane_url are updated
        in place.

        Args:
            timeout: Timeout in seconds when waiting for ready.
            headers: Optional per-request header overrides.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            ResourceCreationError: If sandbox fails during startup.
            ResourceTimeoutError: If sandbox doesn't become ready within timeout.
            SandboxClientError: For other errors.
        r­   N)r4   Ústart_sandboxr"   r'   r$   )rH   rY   rc   Ú	refresheds       rA   ÚstartzSandbox.startÛ  sF   € ð* ”L×.Ò.ØŒI˜w°ð /ñ 
ô 
ˆ	ð  Ô&ˆŒØ&Ô4ˆÔÐÐrC   ©rc   c               óV   — | j                              | j        |¬¦  «         d| _        dS )a  Stop a running sandbox (preserves sandbox files for later restart).

        Args:
            headers: Optional per-request header overrides.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        rÒ   ÚstoppedN)r4   Ústop_sandboxr"   r'   ©rH   rc   s     rA   ÚstopzSandbox.stopö  s.   € ð 	Œ×!Ò! $¤)°WÐ!Ñ=Ô=Ð=ð  ˆŒˆˆrC   c               óH   — | j                              | j        |¬¦  «         dS )zäDelete this sandbox.

        Args:
            headers: Optional per-request header overrides.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        rÒ   N)r4   rT   r"   rÖ   s     rA   ÚdeletezSandbox.delete  s'   € ð 	Œ×#Ò# D¤I°wÐ#Ñ?Ô?Ð?Ð?Ð?rC   r   c               óH   — | j                              | j        |||¬¦  «        S )a!  Capture a snapshot from this sandbox.

        Args:
            name: Snapshot name.
            timeout: Timeout in seconds when waiting for ready.
            headers: Optional per-request header overrides.

        Returns:
            Snapshot in "ready" status.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            ResourceTimeoutError: If snapshot doesn't become ready within timeout.
            ResourceCreationError: If snapshot capture fails.
            SandboxClientError: For other errors.
        r­   )r4   Úcapture_snapshotr"   )rH   r"   rY   rc   s       rA   rÛ   zSandbox.capture_snapshot  s1   € ð. Œ|×,Ò,ØŒIØØØð	 -ñ 
ô 
ð 	
rC   )T)r7   r8   r9   r   r:   r5   r;   r    )r9   rD   r;   r   )r;   r    )rL   rM   rN   rO   rP   rQ   r;   rR   )r;   r!   )re   r!   rY   rf   rZ   rg   r[   r#   r\   r!   r]   rh   r^   rh   r_   rf   r`   r5   ra   rf   rb   r5   rc   ri   rd   rj   r;   r   )re   r!   rY   rf   rZ   rg   r[   r#   r\   r!   r]   rh   r^   rh   r_   rf   r`   r5   ra   rf   rb   r5   rc   ri   rd   ro   r;   r   )re   r!   rY   rf   rZ   rg   r[   r#   r\   r!   r]   rh   r^   rh   r_   rf   r`   r5   ra   rf   rb   r5   rc   ri   rd   r5   r;   rr   )re   r!   rY   rf   rZ   rg   r[   r#   r\   r!   rd   r5   r]   rh   r^   rh   r_   rf   r`   r5   ra   rf   rb   r5   rc   ri   r;   rr   )re   r!   rY   rf   rZ   rg   r[   r#   r\   r!   rc   ri   r;   r   )
r{   r!   r§   rf   r¨   rf   rc   ri   r;   r   )
r®   r!   r¯   r°   rY   rf   rc   ri   r;   rR   )r®   r!   rY   rf   rc   ri   r;   r¸   )
rÂ   rf   rÀ   rf   rÁ   rf   rc   ri   r;   r   )rÊ   rf   rÉ   rf   rc   ri   r;   r   )rY   rf   rc   ri   r;   rR   )rc   ri   r;   rR   )r"   r!   rY   rf   rc   ri   r;   r   )(Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r$   r%   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   r4   r6   ÚclassmethodrB   rG   rK   rV   rX   r   rn   ru   rv   r¬   r·   r½   rÇ   rÌ   rÑ   r×   rÙ   rÛ   r>   rC   rA   r    r    (   sl  € € € € € € ð&ð &ðR €I€I�IØ#'€MÐ'Ð'Ð'Ñ'Ø€BÐÐÐÑØ€FÐÐÐÑØ$(€NÐ(Ð(Ð(Ñ(Ø $€JÐ$Ð$Ð$Ñ$Ø $€JÐ$Ð$Ð$Ñ$Ø&*ÐÐ*Ð*Ð*Ñ*Ø/3ÐÐ3Ð3Ð3Ñ3Ø $€JÐ$Ð$Ð$Ñ$Ø!%€KÐ%Ð%Ð%Ñ%Ø€EÐÐÐÑØ#€IÐ#Ð#Ð#Ñ#Ø'+ÐÐ+Ð+Ð+Ñ+ð #˜U¨°tÐ<Ñ<Ô<€GÐ<Ð<Ð<Ñ<Ø˜ E°4Ð8Ñ8Ô8€LÐ8Ð8Ð8Ñ8àð
 !ð	!
ð !
ð !
ð !
ñ „[ð!
ðF BFð "
ð "
ð "
ð "
ð "
ð "
ðHð ð ð ðð ð ð ð"ð "ð "ð "ð* ð
 Ø(+Ø ØØ47Ø47ØØ#&ØØØ"%Ø!ðð ð ð ð ñ „Xðð$ ð
 Ø(+Ø ØØ47Ø47ØØ#&ØØØ"%ðð ð ð ð ñ „Xðð, Ø(,Ø!Ø Ø48Ø48ØØ#(ØØØ"&Øðt
ð t
ð t
ð t
ð t
ð t
ðB  Ø#(ØØØ"&ðVð Vð Vð Vð Vð Vðp'ð 'ð 'ð 'ðZ ØØ"&ð4
ð 4
ð 4
ð 4
ð 4
ð 4
ðv Ø"&ð))ð ))ð ))ð ))ð ))ð ))ðX ,.Èð)ð )ð )ð )ð )ð )ð^ ØØ"&ð;ð ;ð ;ð ;ð ;ð ;ðB #&Ø"&ð
ð 
ð 
ð 
ð 
ð 
ðF Ø"&ð	5ð 5ð 5ð 5ð 5ð 5ð6 15ð  ð  ð  ð  ð  ð  ð 37ð 
@ð 
@ð 
@ð 
@ð 
@ð 
@ð  Ø"&ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
rC   r    ),rß   Ú
__future__r   Úcollections.abcr   Údataclassesr   r   Útypingr   r   r	   r
   r   r   r   r¡   Úlangsmith.sandbox._exceptionsr   r   r   Úlangsmith.sandbox._helpersr   Úlangsmith.sandbox._modelsr   r   r   r   r   Úlangsmith.sandbox._tunnelr   r€   r   r   r   Úlangsmith.sandbox._async_clientr   rF   r   Úlangsmith.sandbox._clientr   r!   ri   r    r>   rC   rA   ú<module>rì      sö  ðØ EÐ Eà "Ð "Ð "Ð "Ð "Ð "à #Ð #Ð #Ð #Ð #Ð #Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ Sà €€€ðð ð ð ð ð ð ð ð ð ð
 AÐ @Ð @Ð @Ð @Ð @ðð ð ð ð ð ð ð ð ð ð ð ð ð ð -Ð ,Ð ,Ð ,Ð ,Ð ,ðð ð ð ð ð ð ð ð ð ð ð 8ØBÐBÐBÐBÐBÐBØ=Ð=Ð=Ð=Ð=Ð=Ø7Ð7Ð7Ð7Ð7Ð7ð ˜' # s (Ô+Ô,€ð ðD
ð D
ð D
ð D
ð D
ñ D
ô D
ñ „ðD
ð D
ð D
rC   