§
    ~Štjs  ã                  ó<  — d Z ddlmZ ddlZddl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 )z0AsyncSandbox class for async sandbox operations.é    )ÚannotationsN)ÚMapping)Ú	dataclassÚfield)ÚTYPE_CHECKINGÚAnyÚCallableÚLiteralÚOptionalÚUnionÚoverload)ÚDataplaneNotConfiguredErrorÚResourceNotFoundErrorÚSandboxConnectTimeoutError)Úhandle_sandbox_http_error)ÚAsyncCommandHandleÚAsyncServiceURLÚExecutionResultÚSnapshotÚ_StreamEndedBeforeStarted)ÚAsyncTunnel)ÚWEBSOCKETS_AVAILABLEÚconnect_deadlineÚopen_timeout_for)ÚAsyncSandboxClient)ÚSandboxClient©ÚSandboxc                  ó–  — 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 )†ÚAsyncSandboxa¸  Represents an active sandbox for running commands and file operations async.

    This class is typically obtained from AsyncSandboxClient.sandbox() and supports
    the async 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:
        async with await client.sandbox(
            snapshot_id="<snapshot-uuid>"
        ) as sandbox:
            result = await 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 )aD  Create an AsyncSandbox from API response dict.

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

        Returns:
            AsyncSandbox instance.
        r"   Ú r$   r%   r'   r&   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r4   r6   © )Úget)Úclsr7   r9   r:   s       ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langsmith/sandbox/_async_sandbox.pyÚ	from_dictzAsyncSandbox.from_dictj   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[SandboxClient]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 a Sandbox 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: SandboxClient to use for operations. If not provided,
                one is created with the same configuration as this sandbox's
                client (see :meth:`AsyncSandboxClient.to_sync`).

        Returns:
            Sandbox 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._sandboxr   r"   r$   r%   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r4   Úto_sync)Úselfr9   r   s      rA   rG   zAsyncSandbox.to_syncŽ   s)  € ð 	7Ð6Ð6Ð6Ð6Ð6àˆwð 
ð 
ð 
Ø”�ð
àÔ,Ð,ð
ð Œwˆwð
ð ”;�;ð	
ð
  Ô.Ð.ð
ð ”�ð
ð ”�ð
ð "Ô2Ð2ð
ð '+Ô&DÐ&Dð
ð ”�ð
ð Ô(Ð(ð
ð ”*�*ð
ð ”n�nð
ð #Ô4Ð4ð
ð %Ð0�F�F°d´l×6JÒ6JÑ6LÔ6Løð
ð  ˜ð!
ð 	
rC   c              ƒ  ó
   K  — | S )zEnter async context manager.r>   ©rH   s    rA   Ú
__aenter__zAsyncSandbox.__aenter__²   s   è è € àˆrC   Úexc_typeúOptional[type]Úexc_valúOptional[BaseException]Úexc_tbúOptional[Any]ÚNonec              ƒ  óŠ   K  — | j         r9	 | j                             | j        ¦  «        ƒ d{V —† dS # t          $ r Y dS w xY wdS )z<Exit async context manager, optionally deleting the sandbox.N)r6   r4   Údelete_sandboxr"   Ú	Exception)rH   rL   rN   rP   s       rA   Ú	__aexit__zAsyncSandbox.__aexit__¶   st   è è € ð Ôð 	ðØ”l×1Ò1°$´)Ñ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<Ð<Ð<Ð<øÝð ð ð à��ðøøøð	ð 	s   ‹%2 ²
A ¿A 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#AsyncSandbox._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             ƒ  ó
   K  — d S ©Nr>   ©rH   re   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   s                 rA   ÚrunzAsyncSandbox.runÙ   s   è è € ð" ˜#rC   )rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   úLiteral[False]r   c             ƒ  ó
   K  — d S rl   r>   rm   s                 rA   rn   zAsyncSandbox.runì   s   è è € ð" !˜SrC   é<   z	/bin/bashi,  iX  ú*Union[ExecutionResult, AsyncCommandHandle]c             ƒ  óZ  K  — |s|s|rt          d¦  «        ‚|                      ¦   «          | p|p|}|r(|                      ||||||||||	|
||¬¦  «        ƒ d{V —†S t          r(|                      |||||ddd||	|
||¬¦  «        ƒ d{V —†S |                      ||||||¬¦  «        ƒ d{V —†S )am
  Execute a command in the sandbox asynchronously.

        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 an
                AsyncCommandHandle immediately for streaming output,
                kill, stdin input, and reconnection. Cannot be combined
                with on_stdout/on_stderr callbacks.

        Returns:
            ExecutionResult when wait=True (default).
            AsyncCommandHandle 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   NT)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AsyncSandbox.runÿ   s{  è è € ð@ ð 	˜ð 	 ið 	ÝðRñô ð ð
 	×#Ò#Ñ%Ô%Ð%à�Ð3˜YÐ3¨)ˆØð 	ØŸšØØØØØØØ#Ø#Ø)Ø#5Ø'ØØð &ñ ô ð ð ð ð ð ð ð õ$  ð 	ØŸšØØØØØØØØØ)Ø#5Ø'ØØð &ñ ô ð ð ð ð ð ð ð ð —^’^ØØØØØØð $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
rC   )r_   r`   ra   rb   rc   c          
   ƒ  ó  K  — ddl }ddlm} ddlm} |                      ¦   «         }| j        j        } |¦   «         j        }||||||	|
||dœ	}| j         	                    |¦  «        }|r||d<   d}t          ¦   «         }	 t          |¦  «        |d<    ||||fi |¤Žƒ d{V —†\  }}t          ||| ||¬	¦  «        }	 |                     ¦   «         ƒ d{V —† n # t          t          f$ r‹ |d
z  }|t          j        k    r‚ t#          t          j        d|d
z
  z  z  t          j        ¦  «        }|�-|t)          j        ¦   «         z
  }|dk    r‚ t#          ||¦  «        } |j        |¦  «        ƒ d{V —† Y nw xY wŒö|s|S |j        ƒ d{V —†S )z"Execute via WebSocket /execute/ws.r   N)Úrun_ws_stream_async)Úuuid7)	Ú
command_idrY   rZ   r[   r\   r_   r`   ra   rb   rc   TÚopen_timeout)r]   r^   é   é   )ÚasyncioÚlangsmith.sandbox._ws_executery   Úlangsmith.uuidrz   rX   r4   Ú_api_keyÚhexÚ_ws_default_headersr   r   r   Ú_ensure_startedr   r   ÚMAX_AUTO_RECONNECTSÚminÚ_BACKOFF_BASEÚ_BACKOFF_MAXÚtimeÚ	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AsyncSandbox._run_wst  sk  è è € ð$ 	ˆˆˆàEÐEÐEÐEÐEÐEØ(Ð(Ð(Ð(Ð(Ð(à×3Ò3Ñ5Ô5ˆØ”,Ô'ˆð �U‘W”W”[ˆ
ð %ØØØØØ(Ø"4Ø&Øð
%
ð 
%
ˆ	ð ”×1Ò1°'Ñ:Ô:ˆØð 	*Ø#)ˆI�iÑ àˆÝ#Ñ%Ô%ˆð!	-Ý(8¸Ñ(BÔ(BˆI�nÑ%Ø(;Ð(;ØØØð)ð )ð ð	)ð )ð #ð #ð #ð #ð #ð #ÑˆJ˜õ (ØØØØ#Ø#ðñ ô ˆFð-Ø×,Ò,Ñ.Ô.Ð.Ð.Ð.Ð.Ð.Ð.Ð.ØøÝ-Õ/IÐJð -ð -ð -ð ˜1‘�ØÕ/ÔCÒCÐCØÝÝ&Ô4¸¸gÈ¹kÑ8JÑKÝ&Ô3ñô �ð Ð'Ø (­4¬>Ñ+;Ô+;Ñ ;�IØ  A’~�~ØÝ! '¨9Ñ5Ô5�GØ#�g”m GÑ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,ð-øøøð%!	-ðF ð 	ØˆMà”]Ð"Ð"Ð"Ð"Ð"Ð"Ð"s   Â;C ÃBE2Å1E2c             ƒ  ó$  K  — |                       ¦   «         }|› d�}|||dœ}	|�||	d<   |�||	d<   	 | j        j                             ||	|dz   | j                             |¦  «        ¬¦  «        ƒ d{V —†}
|
                     ¦   «          |
                     ¦   «         }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AsyncSandbox._run_httpÍ  s\  è è € ð ×3Ò3Ñ5Ô5ˆØÐ(Ð(Ð(ˆàØØð#
ð #
ˆð
 ˆ?Ø ˆG�E‰NØˆ?Ø ˆG�E‰Nð	Ø!œ\Ô/×4Ò4ØØØ "™Øœ×5Ò5°gÑ>Ô>ð	 5ñ ô ð ð ð ð ð ð ˆHð ×%Ò%Ñ'Ô'Ð'Ø—=’=‘?”?ˆDÝ"Ø—x’x ¨"Ñ-Ô-Ø—x’x ¨"Ñ-Ô-ØŸ(š( ;°Ñ3Ô3ðñ ô ð øõ
 Ô$ð 	ð 	ð 	Ý% aÑ(Ô(Ð(Øøøøøð	øøøs   ±B9C+ Ã+DÃ:D
Ä
Dr   )Ústdout_offsetÚstderr_offsetrc   r{   r©   rª   c             ƒ  óð   K  — ddl m} |                      ¦   «         }| j        j        }||dœ}| j                             |¦  «        }	|	r|	|d<    ||||fi |¤Žƒ d{V —†\  }
}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:
            An AsyncCommandHandle 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_async)r©   rª   rc   N)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AsyncSandbox.reconnectö  sí   è è € ð2 	LÐKÐKÐKÐKÐKà×3Ò3Ñ5Ô5ˆØ”,Ô'ˆð +Ø*ð,
ð ,
Ðð ”×1Ò1°'Ñ:Ô:ˆØð 	1Ø*0Ð˜YÑ'à$=Ð$=ØØØð%
ð %
ð ð	%
ð %
ð 
ð 
ð 
ð 
ð 
ð 
Ñˆ
�Gõ "ØØØØ!Ø'Ø'ð
ñ 
ô 
ð 	
rC   ©rY   rc   ÚpathÚcontentúUnion[str, bytes]c          	   ƒ  ó¦  K  — |                       ¦   «         }|› d�}t          |t          ¦  «        r|                     d¦  «        }dd|fi}	 | j        j                             |d|i||| j                             |¦  «        ¬¦  «        ƒ d{V —†}|                     ¦   «          dS # t          j
        $ r}	t          |	¦  «         Y d}	~	dS d}	~	ww xY w)a9  Write content to a file in the sandbox asynchronously.

        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AsyncSandbox.write,  s  è è € ð, ×3Ò3Ñ5Ô5ˆØÐ'Ð'Ð'ˆõ �g�sÑ#Ô#ð 	.Ø—n’n WÑ-Ô-ˆGà˜& 'Ð*Ð+ˆð
	)Ø!œ\Ô/×4Ò4ØØ �~ØØØœ×5Ò5°gÑ>Ô>ð 5ñ ô ð ð ð ð ð ð ˆHð ×%Ò%Ñ'Ô'Ð'Ð'Ð'øÝÔ$ð 	)ð 	)ð 	)Ý% aÑ(Ô(Ð(Ð(Ð(Ð(Ð(Ð(Ð(øøøøð	)øøøs   ÁAB' Â'CÂ6CÃCÚbytesc             ƒ  ó   K  — |                       ¦   «         }|› d�}	 | j        j                             |d|i|| j                             |¦  «        ¬¦  «        ƒ d{V —†}|                     ¦   «          |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 asynchronously.

        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   Ni”  zFile 'z' not found in sandbox 'ú'r´   )Úresource_type)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AsyncSandbox.readW  s"  è è € ð* ×3Ò3Ñ5Ô5ˆØÐ)Ð)Ð)ˆð	Ø!œ\Ô/×3Ò3ØØ �~ØØœ×5Ò5°gÑ>Ô>ð	 4ñ ô ð ð ð ð ð ð ˆHð ×%Ò%Ñ'Ô'Ð'ØÔ#Ð#øÝÔ$ð 	ð 	ð 	ØŒzÔ%¨Ò,Ð,Ý+ØG˜TÐGÐG¸4¼9ÐGÐGÐGØ"(ðñ ô ð ðõ & aÑ(Ô(Ð(àøøøøð	øøøs   �AA; Á;CÂ
>CÃCé   ©Ú
local_portÚmax_reconnectsrc   Úremote_portrÂ   rÃ   r   c             ƒ  ór  K  — 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	          ||||||¬¦  «        }t          j        ¦   «         }|                     d|j        j	        ¦  «        ƒ d{V —† |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.).

        Usage::

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

        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:
            An AsyncTunnel instance (async 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Á   N)
rt   rX   r4   r‚   r   r   Úget_running_loopÚrun_in_executorÚ_tunnelÚ_start)	rH   rÄ   rÂ   rÃ   rc   r$   rŽ   ÚtÚloops	            rA   ÚtunnelzAsyncSandbox.tunnel‚  s  è è € ðD �KÐ(Ð(Ò(Ð( 5Ò(Ð(Ð(Ð(ÝØNÀÐNÐNÐNñô ð ð ð 	˜a :Ð6Ð6Ò6Ð6°Ò6Ð6Ð6Ð6ÝØL¸zÐLÐLÐLñô ð ð ×3Ò3Ñ5Ô5ˆØ”,Ô'ˆÝØØØØ!Ø)Øð
ñ 
ô 
ˆõ Ô'Ñ)Ô)ˆØ×"Ò" 4¨¬Ô)9Ñ:Ô:Ð:Ð:Ð:Ð:Ð:Ð:Ð:ØˆrC   ©Úexpires_in_secondsrc   ÚportrÏ   r   c             ƒ  óX   K  — | j                              | j        |||¬¦  «        ƒ d{V —†S )aÉ  Get an authenticated URL for a service running in this sandbox.

        Returns an :class:`AsyncServiceURL` whose async accessors
        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:
            AsyncServiceURL 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Î   N)r4   Úservicer"   )rH   rÐ   rÏ   rc   s       rA   rÒ   zAsyncSandbox.serviceº  sS   è è € ð2 ”\×)Ò)ØŒIØØ1Øð	 *ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
rC   éx   c             ƒ  óŠ   K  — | j                              | j        ||¬¦  «        ƒ d{V —†}|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AsyncSandbox.startÚ  sh   è è € ð* œ,×4Ò4ØŒI˜w°ð 5ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆ	ð  Ô&ˆŒØ&Ô4ˆÔÐÐrC   ©rc   c             ƒ  óf   K  — | j                              | j        |¬¦  «        ƒ d{V —† 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Ø   NÚstopped)r4   Ústop_sandboxr"   r'   ©rH   rc   s     rA   ÚstopzAsyncSandbox.stopõ  sD   è è € ð Œl×'Ò'¨¬	¸7Ð'ÑCÔCÐCÐCÐCÐCÐCÐCÐCð  ˆŒˆˆrC   c             ƒ  óX   K  — | j                              | j        |¬¦  «        ƒ d{V —† 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AsyncSandbox.delete  s=   è è € ð Œl×)Ò)¨$¬)¸WÐ)ÑEÔEÐEÐEÐEÐEÐEÐEÐEÐEÐErC   r   c             ƒ  óX   K  — | j                              | j        |||¬¦  «        ƒ d{V —†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¯   N)r4   Úcapture_snapshotr"   )rH   r"   rY   rc   s       rA   rá   zAsyncSandbox.capture_snapshot  sS   è è € ð. ”\×2Ò2ØŒIØØØð	 3ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
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    *   sk  € € € € € € ð(ð (ðV €I€I�IØ#'€MÐ'Ð'Ð'Ñ'Ø€BÐÐÐÑØ€FÐÐÐÑØ$(€NÐ(Ð(Ð(Ñ(Ø $€JÐ$Ð$Ð$Ñ$Ø $€JÐ$Ð$Ð$Ñ$Ø&*ÐÐ*Ð*Ð*Ñ*Ø/3ÐÐ3Ð3Ð3Ñ3Ø $€JÐ$Ð$Ð$Ñ$Ø!%€KÐ%Ð%Ð%Ñ%Ø€EÐÐÐÑØ#€IÐ#Ð#Ð#Ñ#Ø'+ÐÐ+Ð+Ð+Ñ+ð #( %¨U¸DÐ"AÑ"AÔ"A€GÐAÐAÐAÑAØ˜ E°4Ð8Ñ8Ô8€LÐ8Ð8Ð8Ñ8àð
 !ð	!
ð !
ð !
ð !
ñ „[ð!
ðF <@ð "
ð "
ð "
ð "
ð "
ð "
ðHð ð ð ðð ð ð ð"ð "ð "ð "ð* ð
 Ø(+Ø ØØ47Ø47ØØ#&ØØØ"%Ø!ðð ð ð ð ñ „Xðð$ ð
 Ø(+Ø ØØ47Ø47ØØ#&ØØØ"%ð!ð !ð !ð !ð !ñ „Xð!ð, Ø(,Ø!Ø Ø48Ø48ØØ#(ØØØ"&Øðs
ð s
ð s
ð s
ð s
ð s
ð@  Ø#(ØØØ"&ðW#ð W#ð W#ð W#ð W#ð W#ðr'ð 'ð 'ð 'ðZ ØØ"&ð4
ð 4
ð 4
ð 4
ð 4
ð 4
ðv Ø"&ð))ð ))ð ))ð ))ð ))ð ))ðX ,.Èð)ð )ð )ð )ð )ð )ð^ ØØ"&ð6ð 6ð 6ð 6ð 6ð 6ðx #&Ø"&ð
ð 
ð 
ð 
ð 
ð 
ðF Ø"&ð	5ð 5ð 5ð 5ð 5ð 5ð6 7;ð  ð  ð  ð  ð  ð  ð 9=ð 
Fð 
Fð 
Fð 
Fð 
Fð 
Fð  Ø"&ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
rC   r    ).rå   Ú
__future__r   r   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   Úlangsmith.sandbox._clientr   rF   r   r!   ri   r    r>   rC   rA   ú<module>rò      s  ðØ 6Ð 6à "Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ Sà €€€ðð ð ð ð ð ð ð ð ð ð
 AÐ @Ð @Ð @Ð @Ð @ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 2Ð 1Ð 1Ð 1Ð 1Ð 1ðð ð ð ð ð ð ð ð ð ð ð 3ØBÐBÐBÐBÐBÐBØ7Ð7Ð7Ð7Ð7Ð7Ø2Ð2Ð2Ð2Ð2Ð2ð ˜' # s (Ô+Ô,€ð ðA
ð A
ð A
ð A
ð A
ñ A
ô A
ñ „ðA
ð A
ð A
rC   