Ë
    ³Œj¸z  ã                  ó*  — 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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/y)z0AsyncSandbox class for async sandbox operations.é    )ÚannotationsN)ÚMapping)Ú	dataclassÚfield)ÚTYPE_CHECKINGÚAnyÚCallableÚLiteralÚOptionalÚUnionÚoverload)ÚDataplaneNotConfiguredErrorÚResourceNotFoundErrorÚSandboxRetryableConnectionError)Úhandle_sandbox_http_error)ÚAsyncCommandHandleÚAsyncServiceURLÚDownloadContentDispositionÚDownloadURLÚ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	 dB	 	 	 	 	 	 	 dCd„«       ZddœdDd„ZdEd„Z	 	 	 	 	 	 	 	 dFd „ZdGd!„Zed"d"d"d"d"d"d"d"d"d"d"d"d#œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dHd$„«       Zed"d"d"d"d"d"d"d"d"d"d"d%œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dId&„«       Zd'ddd(ddd)dd*dddd#œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dJd+„Zd)dd*ddd,œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dKd-„Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 dLd.„Zd/d/dd0œ	 	 	 	 	 	 	 	 	 dMd1„Zd'dd2œ	 	 	 	 	 	 	 	 	 dNd3„Z d'dd2œ	 	 	 	 	 	 	 dOd4„Z!d/d5dd6œ	 	 	 	 	 	 	 	 	 dPd7„Z"d*dd8œ	 	 	 	 	 	 	 dQd9„Z#ddddd:œ	 	 	 	 	 	 	 	 	 	 	 dRd;„Z$d<dd2œ	 	 	 	 	 dSd=„Z%dd>œdTd?„Z&dd>œdTd@„Z'd'dd2œ	 	 	 	 	 	 	 dUdA„Z(y)VÚ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_atúOptional[int]Úidle_ttl_secondsÚdelete_after_stop_secondsÚ
stopped_atÚsnapshot_idÚvcpusÚ	mem_bytesÚfs_capacity_bytesF)ÚreprÚdefaultr   Ú_clientTÚboolÚ_auto_deletec           	     ó  —  | di d|j                  dd«      “d|j                  d«      “d|j                  d«      “d|j                  dd«      “d|j                  d«      “d|j                  d«      “d	|j                  d	«      “d
|j                  d
«      “d|j                  d«      “d|j                  d«      “d|j                  d«      “d|j                  d«      “d|j                  d«      “d|j                  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/   r0   r1   r2   r3   r4   r7   r9   © )Úget)ÚclsÚdataÚclientÚauto_deletes       új/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langsmith/sandbox/_async_sandbox.pyÚ	from_dictzAsyncSandbox.from_dictl   s2  € ñ" ò 
Ø—‘˜& "Ô%ð
àŸ(™( ?Ô3ð
ð �x‰x˜Œ~ð
ð —8‘8˜H gÔ.ð	
ð
  Ÿ8™8Ð$4Ô5ð
ð —x‘x Ô-ð
ð —x‘x Ô-ð
ð "ŸX™XÐ&8Ô9ð
ð '+§h¡hÐ/JÔ&Kð
ð —x‘x Ô-ð
ð Ÿ™ Ô/ð
ð —(‘(˜7Ô#ð
ð —h‘h˜{Ô+ð
ð #Ÿh™hÐ':Ô;ð
ñ ð
ñ  %ð!
ð 	
ó    )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                   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/   r0   r1   r2   r3   r4   r7   r9   Fr<   )Úlangsmith.sandbox._sandboxr    r$   r&   r'   r)   r*   r+   r,   r.   r/   r0   r1   r2   r3   r4   r7   Úto_sync)Úselfr@   r    s      rB   rG   zAsyncSandbox.to_sync�   s	  € õ 	7áò 
Ø—’ð
à×,Ò,ð
ð �wŠwð
ð —;’;ð	
ð
  ×.Ò.ð
ð —’ð
ð —’ð
ð "×2Ò2ð
ð '+×&DÒ&Dð
ð —’ð
ð ×(Ò(ð
ð —*’*ð
ð —n’nð
ð #×4Ò4ð
ð %Ð0‘F°d·l±l×6JÑ6JÓ6Løð
ñ  ð!
ð 	
rD   c              ƒ  ó   K  — | S ­w)zEnter async context manager.r<   ©rH   s    rB   Ú
__aenter__zAsyncSandbox.__aenter__´   s   è ø€ àˆùs   ‚c              ƒ  ó¤   K  — | j                   r/	 | j                  j                  | j                  «      ƒ d{  –—†  yy7 Œ# t        $ r Y yw xY w­w)z<Exit async context manager, optionally deleting the sandbox.N)r9   r7   Údelete_sandboxr$   Ú	Exception)rH   Úexc_typeÚexc_valÚexc_tbs       rB   Ú	__aexit__zAsyncSandbox.__aexit__¸   sK   è ø€ ð ×ÒðØ—l‘l×1Ñ1°$·)±)Ó<×<Ñ<ð à<ùÜò áðüs5   ‚A�(A ¸?¹A ½A¿A Á	AÁ
AÁAÁAc                ód   — | 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    rB   Ú_require_dataplane_urlz#AsyncSandbox._require_dataplane_urlÆ   s=   € ð ×!Ò!Ü-Ø˜DŸI™I˜;ð '>ð >óð ð ×!Ñ!Ð!rD   .)ÚtimeoutÚenvÚcwdÚshellÚ	on_stdoutÚ	on_stderrÚidle_timeoutÚkill_on_disconnectÚttl_secondsÚptyÚheadersÚwaitc             ƒ  ó   K  — y ­w©Nr<   ©rH   ÚcommandrU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   s                 rB   ÚrunzAsyncSandbox.runÛ   s   è ø€ ð" ùó   ‚)rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   c             ƒ  ó   K  — y ­wrb   r<   rc   s                 rB   re   zAsyncSandbox.runî   s   è ø€ ð" !ùrf   é<   z	/bin/bashi,  iX  c             ƒ  óT  K  — |s|s|rt        d«      ‚| j                  «        | xs |xs |}|r&| j                  ||||||||||	|
||¬«      ƒ d{  –—† S t        r&| j                  |||||ddd||	|
||¬«      ƒ d{  –—† S | j	                  ||||||¬«      ƒ d{  –—† S 7 ŒO7 Œ%7 Œ­w)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.)rU   rV   rW   rX   r`   rY   rZ   r[   r\   r]   r^   r_   NT)rU   rV   rW   rX   r_   )Ú
ValueErrorrT   Ú_run_wsr   Ú	_run_http)rH   rd   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   Úuse_wss                  rB   re   zAsyncSandbox.run  s  è ø€ ñ@ ™¡iÜðRóð ð
 	×#Ñ#Ô%à�Ò3˜YÒ3¨)ˆÙØŸ™ØØØØØØØ#Ø#Ø)Ø#5Ø'ØØð &ó ÷ ð õ$  ØŸ™ØØØØØØØØØ)Ø#5Ø'ØØð &ó ÷ ð ð —^‘^ØØØØØØð $ó 
÷ 
ð 	
ðEøð&øð
ús6   ‚AB(ÁB"Á+B(Á>B$Á?B(ÂB&ÂB(Â$B(Â&B()r[   r\   r]   r^   r_   c          
   ƒ  ó4  K  — ddl }ddlm} ddlm} | j                  «       }| j                  j                  } |«       j                  }||||||	|
||dœ	}| j                  j                  |«      }|r||d<   d}t        «       }	 t        |«      |d<    ||||fi |¤Žƒ d{  –—† \  }}t        ||| ||¬«      }	 |j                  «       ƒ d{  –—†  	 |s|S |j.                  ƒ d{  –—† S 7 ŒI7 Œ# t        t        f$ r“ |d	z  }|t        j                   kD  r‚ t#        t        j$                  d
|d	z
  z  z  t        j&                  «      }|�)|t)        j*                  «       z
  }|dk  r‚ t#        ||«      } |j,                  |«      ƒ d{  –—†7   Y nw xY w�Œ7 Œ¯­w)z"Execute via WebSocket /execute/ws.r   N)Úrun_ws_stream_async)Úuuid7)	Ú
command_idrU   rV   rW   rX   r[   r\   r]   r^   r_   Úopen_timeout)rY   rZ   é   é   )ÚasyncioÚlangsmith.sandbox._ws_executero   Úlangsmith.uuidrp   rT   r7   Ú_api_keyÚhexÚ_ws_default_headersr   r   r   Ú_ensure_startedr   r   ÚMAX_AUTO_RECONNECTSÚminÚ_BACKOFF_BASEÚ_BACKOFF_MAXÚtimeÚ	monotonicÚsleepÚresult)rH   rd   rU   rV   rW   rX   r`   rY   rZ   r[   r\   r]   r^   r_   ru   ro   rp   r&   Úapi_keyrq   Ú	ws_kwargsÚmergedÚattemptÚdeadlineÚ
msg_streamÚcontrolÚhandleÚbackoffÚ	remainings                                rB   rk   zAsyncSandbox._run_wsv  sÎ  è ø€ ó$ 	åEÝ(à×3Ñ3Ó5ˆØ—,‘,×'Ñ'ˆñ “W—[‘[ˆ
ð %ØØØØØ(Ø"4Ø&Øñ
%
ˆ	ð —‘×1Ñ1°'Ó:ˆÙØ#)ˆI�iÑ àˆÜ#Ó%ˆØÜ(8¸Ó(BˆI�nÑ%Ù(;ØØØñ)ð ñ	)÷ #ÑˆJ˜ô (ØØØØ#Ø#ôˆFð-Ø×,Ñ,Ó.×.Ð.Øñ* ØˆMà—]‘]×"Ð"ðO#øð /ùô *Ü/ðò -ð ˜1‘�ØÔ/×CÑCÒCØÜÜ&×4Ñ4¸¸gÈ¹kÑ8JÑKÜ&×3Ñ3ó�ð Ð'Ø (¬4¯>©>Ó+;Ñ ;�IØ  A’~ØÜ! '¨9Ó5�GØ#�g—m‘m GÓ,×,Ó,ð%-úñ% ðR #úsa   ‚BFÂ!C+Â"FÂ:C/ ÃC-ÃC/ ÃFÃ&FÃ'FÃ-C/ Ã/BFÆFÆ	FÆFÆFÆFc             ƒ  ó  K  — | j                  «       }|› d�}|||dœ}	|�||	d<   |�||	d<   	 | j                  j                  j                  ||	|dz   | j                  j	                  |«      ¬«      ƒ d{  –—† }
|
j                  «        |
j                  «       }t        |j                  dd	«      |j                  d
d	«      |j                  dd«      ¬«      S 7 Œb# t        j                  $ r}t        |«       ‚ d}~ww xY w­w)z9Execute via HTTP POST /execute (existing implementation).z/execute)rd   rU   rX   NrV   rW   é
   )ÚjsonrU   r_   Ústdoutr;   ÚstderrÚ	exit_codeéÿÿÿÿ)r‘   r’   r“   )rT   r7   Ú_httpÚpostÚ_request_headersÚraise_for_statusr�   r   r=   ÚhttpxÚHTTPStatusErrorr   )rH   rd   rU   rV   rW   rX   r_   r&   ÚurlÚpayloadÚresponser?   Úes                rB   rl   zAsyncSandbox._run_httpÒ  s  è ø€ ð ×3Ñ3Ó5ˆØ�˜xÐ(ˆàØØñ#
ˆð
 ˆ?Ø ˆG�E‰NØˆ?Ø ˆG�E‰Nð	Ø!Ÿ\™\×/Ñ/×4Ñ4ØØØ "™ØŸ™×5Ñ5°gÓ>ð	 5ó ÷ ˆHð ×%Ñ%Ô'Ø—=‘=“?ˆDÜ"Ø—x‘x ¨"Ó-Ø—x‘x ¨"Ó-ØŸ(™( ;°Ó3ôð ðùô ×$Ñ$ò 	Ü% aÔ(Øûð	üs<   ‚*D­AC Á5CÁ6A!C ÃDÃC ÃC>Ã-C9Ã9C>Ã>Dr   )Ústdout_offsetÚstderr_offsetr_   c             ƒ  ó  K  — ddl m} | j                  «       }| j                  j                  }||dœ}| j                  j                  |«      }	|	r|	|d<    ||||fi |¤Žƒ d{  –—† \  }
}t        |
|| |||¬«      S 7 Œ­w)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    r_   N)rq   rŸ   r    )rv   r¢   rT   r7   rx   rz   r   )rH   rq   rŸ   r    r_   r¢   r&   r„   Úreconnect_kwargsr†   r‰   rŠ   s               rB   Ú	reconnectzAsyncSandbox.reconnectû  sª   è ø€ õ2 	Là×3Ñ3Ó5ˆØ—,‘,×'Ñ'ˆð +Ø*ñ,
Ðð —‘×1Ñ1°'Ó:ˆÙØ*0Ð˜YÑ'á$=ØØØñ%
ð ñ	%
÷ 
Ñˆ
�Gô "ØØØØ!Ø'Ø'ô
ð 	
ð
ús   ‚A"A?Á$A=Á%A?©rU   r_   c          	   ƒ  óš  K  — | j                  «       }|› d�}t        |t        «      r|j                  d«      }dd|fi}	 | j                  j
                  j                  |d|i||| j                  j                  |«      ¬«      ƒ d{  –—† }|j                  «        y7 Œ# t        j                  $ r}	t        |	«       Y d}	~	yd}	~	ww xY w­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ÚfileÚpath)ÚparamsÚfilesrU   r_   N)rT   Ú
isinstancer#   Úencoder7   r•   r–   r—   r˜   r™   rš   r   )
rH   r¨   ÚcontentrU   r_   r&   r›   rª   r�   rž   s
             rB   ÚwritezAsyncSandbox.write1  sË   è ø€ ð, ×3Ñ3Ó5ˆØ�˜wÐ'ˆô �gœsÔ#Ø—n‘n WÓ-ˆGà˜& 'Ð*Ð+ˆð
	)Ø!Ÿ\™\×/Ñ/×4Ñ4ØØ �~ØØØŸ™×5Ñ5°gÓ>ð 5ó ÷ ˆHð ×%Ñ%Õ'ðùô ×$Ñ$ò 	)Ü% a×(Ñ(ûð	)üsB   ‚=CÁ AB  ÂBÂ	B  ÂCÂB  Â CÂ3CÂ>CÃCÃCc             ƒ  óÈ  K  — | j                  «       }|› d�}	 | j                  j                  j                  |d|i|| j                  j	                  |«      ¬«      ƒ d{  –—† }|j                  «        |j                  S 7 Œ # t        j                  $ rI}|j                  j                  dk(  rt        d|› d| j                  › d�d	¬
«      |‚t        |«       ‚ d}~ww xY w­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©   rU   r_   Ni”  zFile 'z' not found in sandbox 'Ú'r§   )Úresource_type)rT   r7   r•   r=   r—   r˜   r­   r™   rš   r�   Ústatus_coder   r$   r   )rH   r¨   rU   r_   r&   r›   r�   rž   s           rB   ÚreadzAsyncSandbox.read\  së   è ø€ ð* ×3Ñ3Ó5ˆØ�˜yÐ)ˆð	Ø!Ÿ\™\×/Ñ/×3Ñ3ØØ �~ØØŸ™×5Ñ5°gÓ>ð	 4ó ÷ ˆHð ×%Ñ%Ô'Ø×#Ñ#Ð#ðùô ×$Ñ$ò 	Ø�z‰z×%Ñ%¨Ò,Ü+Ø˜T˜FÐ":¸4¿9¹9¸+ÀQÐGØ"(ôð ðô & aÔ(àûð	üs<   ‚C"™AB Á BÁ!B Â C"ÂB ÂCÂACÃCÃC"é   ©Ú
local_portÚmax_reconnectsr_   c             ƒ  óx  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                  j                  }t	        ||||||¬«      }t        j                  «       }|j                  d|j                  j                  «      ƒ d{  –—†  |S 7 Œ­w)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.
        rs   iÿÿ  z-remote_port must be between 1 and 65535 (got Ú)z,local_port must be between 1 and 65535 (got rµ   N)
rj   rT   r7   rx   r   ru   Úget_running_loopÚrun_in_executorÚ_tunnelÚ_start)	rH   Úremote_portr¶   r·   r_   r&   r„   ÚtÚloops	            rB   ÚtunnelzAsyncSandbox.tunnel‡  sÎ   è ø€ ðD �KÔ( 5Ô(ÜØ?À¸}ÈAÐNóð ñ ˜a :Ô6°Ô6ÜØ>¸z¸lÈ!ÐLóð ð ×3Ñ3Ó5ˆØ—,‘,×'Ñ'ˆÜØØØØ!Ø)Øô
ˆô ×'Ñ'Ó)ˆØ×"Ñ" 4¨¯©×)9Ñ)9Ó:×:Ð:Øˆð 	;ús   ‚B/B:Â1B8Â2B:©Úexpires_in_secondsr_   c             ƒ  óp   K  — | j                   j                  | j                  |||¬«      ƒ d{  –—† S 7 Œ­w)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)r7   Úservicer$   )rH   ÚportrÃ   r_   s       rB   rÅ   zAsyncSandbox.service¿  s>   è ø€ ð2 —\‘\×)Ñ)Ø�I‰IØØ1Øð	 *ó 
÷ 
ð 	
ð 
úó   ‚-6¯4°6©rÃ   Úcontent_typeÚcontent_dispositionr_   c             ƒ  ót   K  — | j                   j                  | j                  |||||¬«      ƒ d{  –—† S 7 Œ­w)aÐ  Create a link that downloads one file from this sandbox.

        The link carries its own token, so anyone holding the URL can fetch
        that one file without a LangSmith credential. Fetching wakes a
        stopped sandbox.

        Do not modify the file after minting a link for it. The link is
        pinned to a path, not to a snapshot of the contents, so a later
        write to that path may or may not be reflected in what the link
        serves. Write a new file and mint a new link when the contents
        change.

        Args:
            path: File path inside the sandbox.
            expires_in_seconds: Link TTL in seconds. Omit for a link that
                never expires.
            content_type: Content-Type to serve the file as.
            content_disposition: Content-Disposition to serve the file with,
                either ``"attachment"`` or ``"inline"``.
            headers: Optional per-request header overrides.

        Returns:
            DownloadURL with the link and its expiry, if any.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            ValueError: If expires_in_seconds is not positive.
            SandboxClientError: For other errors.
        rÈ   N)r7   Úgenerate_download_urlr$   )rH   r¨   rÃ   rÉ   rÊ   r_   s         rB   rÌ   z"AsyncSandbox.generate_download_urlß  sE   è ø€ ðL —\‘\×7Ñ7Ø�I‰IØØ1Ø%Ø 3Øð 8ó 
÷ 
ð 	
ð 
ús   ‚/8±6²8éx   c             ƒ  ó´   K  — | j                   j                  | j                  ||¬«      ƒ d{  –—† }|j                  | _        |j                  | _        y7 Œ'­w)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)r7   Ústart_sandboxr$   r)   r&   )rH   rU   r_   Ú	refresheds       rB   ÚstartzAsyncSandbox.start  sS   è ø€ ð* Ÿ,™,×4Ñ4Ø�I‰I˜w°ð 5ó 
÷ 
ˆ	ð  ×&Ñ&ˆŒØ&×4Ñ4ˆÕð	
ús   ‚,A®A¯(A©r_   c             ƒ  ó|   K  — | j                   j                  | j                  |¬«      ƒ d{  –—†  d| _        y7 Œ­w)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)r7   Ústop_sandboxr$   r)   ©rH   r_   s     rB   ÚstopzAsyncSandbox.stop)  s8   è ø€ ð �l‰l×'Ñ'¨¯	©	¸7Ð'ÓC×CÐCð  ˆ�ð 	Dús   ‚+<­:®<c             ƒ  ón   K  — | j                   j                  | j                  |¬«      ƒ d{  –—†  y7 Œ­w)zäDelete this sandbox.

        Args:
            headers: Optional per-request header overrides.

        Raises:
            ResourceNotFoundError: If sandbox not found.
            SandboxClientError: For other errors.
        rÒ   N)r7   rM   r$   rÖ   s     rB   ÚdeletezAsyncSandbox.delete8  s)   è ø€ ð �l‰l×)Ñ)¨$¯)©)¸WÐ)ÓE×EÒEús   ‚+5­3®5c             ƒ  óp   K  — | j                   j                  | j                  |||¬«      ƒ d{  –—† S 7 Œ­w)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)r7   Úcapture_snapshotr$   )rH   r$   rU   r_   s       rB   rÛ   zAsyncSandbox.capture_snapshotD  s>   è ø€ ð. —\‘\×2Ñ2Ø�I‰IØØØð	 3ó 
÷ 
ð 	
ð 
úrÇ   )T)r?   zdict[str, Any]r@   r   rA   r8   Úreturnr"   )r@   zOptional[SandboxClient]rÜ   r    )rÜ   r"   )rO   zOptional[type]rP   zOptional[BaseException]rQ   zOptional[Any]rÜ   ÚNone)rÜ   r#   )rd   r#   rU   ÚintrV   úOptional[dict[str, str]]rW   r%   rX   r#   rY   úOptional[Callable[[str], Any]]rZ   rà   r[   rÞ   r\   r8   r]   rÞ   r^   r8   r_   ÚRequestHeadersr`   zLiteral[True]rÜ   r   )rd   r#   rU   rÞ   rV   rß   rW   r%   rX   r#   rY   rà   rZ   rà   r[   rÞ   r\   r8   r]   rÞ   r^   r8   r_   rá   r`   zLiteral[False]rÜ   r   )rd   r#   rU   rÞ   rV   rß   rW   r%   rX   r#   rY   rà   rZ   rà   r[   rÞ   r\   r8   r]   rÞ   r^   r8   r_   rá   r`   r8   rÜ   ú*Union[ExecutionResult, AsyncCommandHandle])rd   r#   rU   rÞ   rV   rß   rW   r%   rX   r#   r`   r8   rY   rà   rZ   rà   r[   rÞ   r\   r8   r]   rÞ   r^   r8   r_   rá   rÜ   râ   )rd   r#   rU   rÞ   rV   rß   rW   r%   rX   r#   r_   rá   rÜ   r   )
rq   r#   rŸ   rÞ   r    rÞ   r_   rá   rÜ   r   )
r¨   r#   r­   zUnion[str, bytes]rU   rÞ   r_   rá   rÜ   rÝ   )r¨   r#   rU   rÞ   r_   rá   rÜ   Úbytes)
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Ê   z$Optional[DownloadContentDisposition]r_   rá   rÜ   r   )rU   rÞ   r_   rá   rÜ   rÝ   )r_   rá   rÜ   rÝ   )r$   r#   rU   rÞ   r_   rá   rÜ   r   ))Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r&   r'   r)   r*   r+   r,   r.   r/   r0   r1   r2   r3   r4   r   r7   r9   ÚclassmethodrC   rG   rK   rR   rT   r   re   rk   rl   r¤   r®   r³   rÁ   rÅ   rÌ   rÑ   r×   rÙ   rÛ   r<   rD   rB   r"   r"   ,   s_  … ñ(ðV ƒIØ#'€M�=Ó'Ø€BˆÓØ€FˆCÓØ$(€N�MÓ(Ø $€J�Ó$Ø $€J�Ó$Ø&*Ð�mÓ*Ø/3Ð˜}Ó3Ø $€J�Ó$Ø!%€K�Ó%Ø€Eˆ=ÓØ#€Iˆ}Ó#Ø'+Ð�}Ó+ñ #(¨U¸DÔ"A€GÐÓAÙ E°4Ô8€L�$Ó8àð
 !ð	!
àð!
ð #ð!
ð ð	!
ð
 
ò!
ó ð!
ðF <@õ "
óHðà ðð )ðð ð	ð
 
óó"ð* ð
 Ø(+Ø ØØ47Ø47ØØ#&ØØØ"%Ø!ñàðð ð	ð
 &ðð ðð ðð 2ðð 2ðð ðð !ðð ðð ðð  ðð ðð  
ò!ó ðð$ ð
 Ø(+Ø ØØ47Ø47ØØ#&ØØØ"%ñ!àð!ð ð	!ð
 &ð!ð ð!ð ð!ð 2ð!ð 2ð!ð ð!ð !ð!ð ð!ð ð!ð  ð!ð ð!ð  
ò!!ó ð!ð, Ø(,Ø!Ø Ø48Ø48ØØ#(ØØØ"&Øñs
àðs
ð ð	s
ð
 &ðs
ð ðs
ð ðs
ð 2ðs
ð 2ðs
ð ðs
ð !ðs
ð ðs
ð ðs
ð  ðs
ð ðs
ð  
4ó!s
ð@  Ø#(ØØØ"&ñZ#àðZ#ð ð	Z#ð
 &ðZ#ð ðZ#ð ðZ#ð ðZ#ð 2ðZ#ð 2ðZ#ð ðZ#ð !ðZ#ð ðZ#ð ðZ#ð  ðZ#ð  
4ó!Z#ðx'àð'ð ð	'ð
 &ð'ð ð'ð ð'ð  ð'ð 
ó'ðZ ØØ"&ñ4
àð4
ð ð	4
ð
 ð4
ð  ð4
ð 
ó4
ðv Ø"&ñ))àð))ð #ð))ð
 ð))ð  ð))ð 
ó))ðX ,.Èñ)Øð)Ø%(ð)Ø8Fð)à	ó)ð^ ØØ"&ñ6àð6ð ð	6ð
 ð6ð  ð6ð 
ó6ðx #&Ø"&ñ
àð
ð  ð	
ð
  ð
ð 
ó
ðH -1Ø&*ØDHØ"&ñ-
àð-
ð *ð	-
ð
 $ð-
ð Bð-
ð  ð-
ð 
ó-
ðd Ø"&ñ	5ð ð5ð  ð	5ð
 
ó5ð6 7;õ  ð 9=õ 
Fð  Ø"&ñ
àð
ð ð	
ð
  ð
ð 
ô
rD   r"   )0rç   Ú
__future__r   ru   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   r   r   Úlangsmith.sandbox._tunnelr   rv   r   r   r   Úlangsmith.sandbox._async_clientr   Úlangsmith.sandbox._clientr   rF   r    r#   rá   r"   r<   rD   rB   Ú<module>rô      s�   ðÙ 6å "ã Û Ý #ß (ß S× SÑ Sã ÷ñ õ
 A÷÷ ñ õ 2÷ñ ñ ÝBÝ7Ý2ð ˜' # s (Ñ+Ñ,€ð ÷s
ð s
ó ñs
rD   