Ë
    ñÏjWÈ  ã                  óX  — d Z ddlmZ ddlZddlmZmZmZmZ ddl	m
Z
mZ ddlmZmZ ddl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 dd
lmZ erddlmZ ddlm Z   ejB                  e"«      Z# G d„ de«      Z$ G d„ de«      Z%dZ&d?d„Z' G d„ de«      Z(e
 G d„ d«      «       Z)e
 G d„ d«      «       Z*e
 G d„ d«      «       Z+	 	 	 	 d@d„Z,dAd„Z-e
 G d„ d«      «       Z.e
 G d„ d «      «       Z/e
 G d!„ d"«      «       Z0e
 G d#„ d$«      «       Z1e
 G d%„ d&«      «       Z2e
 G d'„ d(«      «       Z3e
 G d)„ d*«      «       Z4e
 G d+„ d,«      «       Z5d-Z6d.Z7 G d/„ d0«      Z8 G d1„ d2«      Z9ed3   Z:	 e
 G d4„ d5«      «       Z;ed6   Z<e
 G d7„ d8«      «       Z=e
 G d9„ d:«      «       Z> G d;„ d<«      Z? G d=„ d>«      Z@y)Bz#Data models for the sandbox client.é    )ÚannotationsN)ÚAsyncIteratorÚ	AwaitableÚCallableÚIterator)Ú	dataclassÚfield)ÚdatetimeÚtimezone)ÚTYPE_CHECKINGÚAnyÚLiteralÚOptionalÚProtocolÚUnion)Úhttpx)ÚSandboxConnectionErrorÚSandboxOperationErrorÚSandboxServerReloadError)Úadd_sandbox_metadata)ÚAsyncSandbox)ÚSandboxc                  óL   — e Zd ZdZedd„«       Zedd„«       Zd	d„Zd
d„Zd	d„Z	y)ÚStreamControlz¤What a command handle needs from its transport to steer a command.

    A one-way transport supplies this too, and raises from the methods it
    cannot honor.
    c                 ó   — y ©N© ©Úselfs    úV/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langsmith/sandbox/_models.pyÚkilledzStreamControl.killed!   ó   € Ø!ó    c                 ó   — y)zÇWhether the transport already retries and resumes on its own.

        A handle must not add its own reattach loop on top of one, or the two
        budgets multiply into an unbounded retry.
        Nr   r   s    r    Úresumes_itselfzStreamControl.resumes_itself$   s   € ð 	r#   c                 ó   — y r   r   r   s    r    Ú	send_killzStreamControl.send_kill-   s   €  r#   c                 ó   — y r   r   ©r   Údatas     r    Ú
send_inputzStreamControl.send_input/   s   € ¨Sr#   c                 ó   — y r   r   r   s    r    Úsend_close_stdinzStreamControl.send_close_stdin1   s   € ¨r#   N©ÚreturnÚbool©r/   ÚNone©r*   Ústrr/   r2   ©
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr!   r%   r'   r+   r-   r   r#   r    r   r      s4   „ ñð Ú!ó Ø!àòó ðó %ã0ä+r#   r   c                  óL   — e Zd ZdZedd„«       Zedd„«       Zd	d„Zd
d„Zd	d„Z	y)ÚAsyncStreamControlz+Async equivalent of :class:`StreamControl`.c                 ó   — y r   r   r   s    r    r!   zAsyncStreamControl.killed7   r"   r#   c                 ó   — y r   r   r   s    r    r%   z!AsyncStreamControl.resumes_itself:   s   € Ø&)r#   c                 ó   — y r   r   r   s    r    r'   zAsyncStreamControl.send_kill=   s   € ¨Cr#   c                 ó   — y r   r   r)   s     r    r+   zAsyncStreamControl.send_input?   s   € ¸r#   c                 ó   — y r   r   r   s    r    r-   z#AsyncStreamControl.send_close_stdinA   s   € °3r#   Nr.   )r/   úAwaitable[None])r*   r4   r/   rB   r5   r   r#   r    r<   r<   4   s*   „ Ù5àÚ!ó Ø!àÚ)ó Ø)ã/ã;ä6r#   r<   zºstdin is closed for this command. Non-PTY commands close stdin by default so a command that reads it sees EOF instead of hanging; pass close_input=False to run() to stream input into it.c                ó`   — | j                  d«      }||k(  ryt        j                  d||«       y)a×  Whether a 'started' frame proves *this* command was reattached to.

    A command and its WebSocket are separate things: the command keeps running on
    the server and the socket is only this client's attachment to it. The server
    acknowledges every successful reattachment with 'started', which for a
    command that produces no output is the only evidence it landed. One naming a
    different command is not evidence, and must not clear the reconnect budget.
    Ú
command_idTzFIgnoring reconnect acknowledgement for command %r while attached to %rF)ÚgetÚloggerÚwarning)ÚmsgrD   Úackeds      r    Ú_acknowledges_reconnectrJ   K   s7   € ð �G‰G�LÓ!€EØ�
ÒØÜ
‡N�NØPØØôð
 r#   c                  ó   — e Zd ZdZy)Ú_StreamEndedBeforeStartedaT  A command WebSocket closed before the guest sent its 'started' frame.

    Internal marker for the idempotently-retryable early close (the proxied
    tunnel was torn down gracefully mid-handshake), as distinct from a
    command-level failure. Subclasses SandboxOperationError so callers that
    catch the public type are unaffected.
    N)r6   r7   r8   r9   r   r#   r    rL   rL   _   s   „ òr#   rL   c                  óB   — e Zd ZU dZded<   ded<   ded<   ed	d„«       Zy)
ÚExecutionResultz+Result of executing a command in a sandbox.r4   ÚstdoutÚstderrÚintÚ	exit_codec                ó    — | j                   dk(  S )z.Return True if the command exited with code 0.r   )rR   r   s    r    ÚsuccesszExecutionResult.successq   s   € ð �~‰~ Ñ"Ð"r#   Nr.   )r6   r7   r8   r9   Ú__annotations__r:   rT   r   r#   r    rN   rN   i   s&   … á5àƒKØƒKØƒNàò#ó ñ#r#   rN   c                  ó<   — e Zd ZU dZded<   dZded<   edd„«       Zy)	ÚResourceStatusa  Lightweight provisioning status for any async-created resource.

    Attributes:
        status: Resource lifecycle status. One of "provisioning", "ready", "failed".
        status_message: Human-readable details when status is "failed", None otherwise.
    r4   ÚstatusNúOptional[str]Ústatus_messagec                óT   —  | |j                  dd«      |j                  d«      ¬«      S )z/Create a ResourceStatus from API response dict.rX   ÚprovisioningrZ   )rX   rZ   ©rE   ©Úclsr*   s     r    Ú	from_dictzResourceStatus.from_dictƒ   s,   € ñ Ø—8‘8˜H nÓ5ØŸ8™8Ð$4Ó5ô
ð 	
r#   )r*   údict[str, Any]r/   rW   )r6   r7   r8   r9   rU   rZ   Úclassmethodr`   r   r#   r    rW   rW   w   s*   … ñð ƒKØ$(€N�MÓ(àò
ó ñ
r#   rW   c                  óV   — e Zd ZU dZdZded<   dZded<   dZded<   ed
d„«       Z	dd	„Z
y)Ú	RunConfiga­  The user, working directory and environment commands run with.

    Mirrors ``docker run -u / -w / -e``: ``user`` and ``work_dir`` replace the
    layer below, ``env_vars`` merge into it key by key. It applies at three
    points, each layered over the one before -- the snapshot, the sandbox, and
    a single command.

    Attributes:
        user: Account to run as: ``name``, ``uid``, ``name:group`` or
            ``uid:gid``. Defaults to the Docker image's ``USER``.
        work_dir: Absolute working directory. Defaults to the image's
            ``WORKDIR``. A relative path is rejected by the server.
        env_vars: Environment variables, merged over the layer below.
    NrY   ÚuserÚwork_dirzOptional[dict[str, str]]Úenv_varsc                óš   — |j                  d«      } | |j                  d«      |j                  d«      |rt        |«      ¬«      S d¬«      S )z*Create a RunConfig from API response dict.rg   re   rf   N)re   rf   rg   )rE   Údict)r_   r*   rg   s      r    r`   zRunConfig.from_dict¡   sO   € ð —8‘8˜JÓ'ˆÙØ—‘˜&Ó!Ø—X‘X˜jÓ)Ù'/”T˜(“^ô
ð 	
ð 6:ô
ð 	
r#   c                ó¾   — i }| j                   �| j                   |d<   | j                  �| j                  |d<   | j                  �t        | j                  «      |d<   |S )z9Render as a request body fragment, omitting unset fields.re   rf   rg   )re   rf   rg   ri   )r   Úpayloads     r    Ú
to_payloadzRunConfig.to_payload«   sX   € à"$ˆØ�9‰9Ð Ø"Ÿi™iˆG�F‰OØ�=‰=Ð$Ø"&§-¡-ˆG�JÑØ�=‰=Ð$Ü"& t§}¡}Ó"5ˆG�JÑØˆr#   )r*   ra   r/   rd   )r/   ra   )r6   r7   r8   r9   re   rU   rf   rg   rb   r`   rl   r   r#   r    rd   rd   Œ   s?   … ñð €Dˆ-ÓØ"€HˆmÓ"Ø)-€HÐ&Ó-àò
ó ð
ô	r#   rd   c                ó^   — | €yt        | t        «      r| j                  «       S t        | «      S )z;Normalize a run_config argument to a request body fragment.N)Ú
isinstancerd   rl   ri   )Ú
run_configs    r    Ú_run_config_payloadrp   ·   s1   € ð ÐØÜ�*œiÔ(Ø×$Ñ$Ó&Ð&Ü�
ÓÐr#   c                óN   — t        | t        «      syt        j                  | «      S )z;Parse a run_config response field, absent on older servers.N)rn   ri   rd   r`   )r*   s    r    Ú_run_config_from_dictrr   Â   s    € ä�dœDÔ!ØÜ×Ñ˜tÓ$Ð$r#   c                  óX   — 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<   edd„«       Z	y
)ÚFileInfozõOne filesystem entry returned by :meth:`Sandbox.glob`.

    Attributes:
        path: Absolute path of the entry.
        is_dir: True for a directory.
        size_bytes: Size in bytes.
        modified_at: RFC 3339 modification timestamp.
    r4   ÚpathFr0   Úis_dirr   rQ   Ú
size_bytesNrY   Úmodified_atc           	     ó°   —  | |j                  dd«      t        |j                  dd«      «      |j                  d«      xs d|j                  d«      ¬«      S )	z)Create a FileInfo from API response dict.ru   Ú rv   Frw   r   rx   )ru   rv   rw   rx   )rE   r0   r^   s     r    r`   zFileInfo.from_dictÙ   sO   € ñ Ø—‘˜& "Ó%Ü˜Ÿ™ ¨5Ó1Ó2Ø—x‘x Ó-Ò2°ØŸ™ Ó/ô	
ð 	
r#   )r*   ra   r/   rt   )
r6   r7   r8   r9   rU   rv   rw   rx   rb   r`   r   r#   r    rt   rt   É   s>   … ñð ƒIØ€FˆDÓØ€J�ÓØ!%€K�Ó%àò
ó ñ
r#   rt   c                  ó^   — e Zd ZU dZ ee¬«      Zded<   dZded<   e	dd„«       Z
dd	„Zdd
„Zy)Ú
GlobResultzíEntries matching a glob pattern.

    Attributes:
        matches: Matching files and directories.
        truncated: True when the server hit its result cap or deadline, so
            the search is a partial answer worth refining.
    ©Údefault_factoryzlist[FileInfo]ÚmatchesFr0   Ú	truncatedc           	     óº   —  | |j                  d«      xs g D �cg c]  }t        j                  |«      ‘Œ c}t        |j                  dd«      «      ¬«      S c c}w )z+Create a GlobResult from API response dict.r   r€   F©r   r€   )rE   rt   r`   r0   ©r_   r*   Úms      r    r`   zGlobResult.from_dictñ   sW   € ñ Ø48·H±H¸YÓ4GÒ4MÈ2Ð4MÓNÑ4M¨q”X×'Ñ'¨Õ*Ð4MÑNÜ˜4Ÿ8™8 K°Ó7Ó8ô
ð 	
ùÚNó   šAc                ó,   — t        | j                  «      S ©zIterate the matches directly.©Úiterr   r   s    r    Ú__iter__zGlobResult.__iter__ù   ó   € ä�D—L‘LÓ!Ð!r#   c                ó,   — t        | j                  «      S ©zReturn the number of matches.©Úlenr   r   s    r    Ú__len__zGlobResult.__len__ý   ó   € ä�4—<‘<Ó Ð r#   N)r*   ra   r/   r|   )r/   zIterator[FileInfo]©r/   rQ   ©r6   r7   r8   r9   r	   Úlistr   rU   r€   rb   r`   rŠ   r�   r   r#   r    r|   r|   ä   s>   … ññ $°DÔ9€Gˆ^Ó9Ø€IˆtÓàò
ó ð
ó"ô!r#   r|   c                  óB   — e Zd ZU dZded<   ded<   ded<   ed	d„«       Zy)
Ú	GrepMatchzÑOne matching line found by :meth:`Sandbox.grep`.

    Attributes:
        path: Absolute path of the file the match was found in.
        line: 1-based line number.
        text: The matching line's text.
    r4   ru   rQ   ÚlineÚtextc                ó~   —  | |j                  dd«      |j                  d«      xs d|j                  dd«      ¬«      S )z*Create a GrepMatch from API response dict.ru   rz   r—   r   r˜   )ru   r—   r˜   r]   r^   s     r    r`   zGrepMatch.from_dict  s>   € ñ Ø—‘˜& "Ó%Ø—‘˜&Ó!Ò& QØ—‘˜& "Ó%ô
ð 	
r#   N)r*   ra   r/   r–   ©r6   r7   r8   r9   rU   rb   r`   r   r#   r    r–   r–     s*   … ñð ƒIØ
ƒIØ
ƒIàò
ó ñ
r#   r–   c                  ó^   — e Zd ZU dZ ee¬«      Zded<   dZded<   e	dd„«       Z
dd	„Zdd
„Zy)Ú
GrepResultzÃLines matching a literal search.

    Attributes:
        matches: Matching lines, in the order the server found them.
        truncated: True when the server hit its result cap or deadline.
    r}   zlist[GrepMatch]r   Fr0   r€   c           	     óº   —  | |j                  d«      xs g D �cg c]  }t        j                  |«      ‘Œ c}t        |j                  dd«      «      ¬«      S c c}w )z+Create a GrepResult from API response dict.r   r€   Fr‚   )rE   r–   r`   r0   rƒ   s      r    r`   zGrepResult.from_dict&  sW   € ñ Ø59·X±X¸iÓ5HÒ5NÈBÐ5NÓOÑ5N°”Y×(Ñ(¨Õ+Ð5NÑOÜ˜4Ÿ8™8 K°Ó7Ó8ô
ð 	
ùÚOr…   c                ó,   — t        | j                  «      S r‡   rˆ   r   s    r    rŠ   zGrepResult.__iter__.  r‹   r#   c                ó,   — t        | j                  «      S r�   rŽ   r   s    r    r�   zGrepResult.__len__2  r‘   r#   N)r*   ra   r/   rœ   )r/   zIterator[GrepMatch]r’   r“   r   r#   r    rœ   rœ     s>   … ññ  %°TÔ:€Gˆ_Ó:Ø€IˆtÓàò
ó ð
ó"ô!r#   rœ   c                  óF   — 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<   y)	ÚFileStataé  What a ``HEAD`` on a sandbox file reports, without transferring it.

    Attributes:
        size_bytes: The file's size.
        etag: Strong validator for the current contents. Opaque -- compare
            it, never parse it. Pass it back as ``if_range`` to resume a
            download safely, or as ``if_none_match`` to poll for a change.
        last_modified: HTTP-date of the last modification, second-resolution.
        content_type: The server's content type for the file.
    rQ   rw   NrY   ÚetagÚlast_modifiedÚcontent_type)r6   r7   r8   r9   rU   r¢   r£   r¤   r   r#   r    r¡   r¡   7  s,   … ñ	ð ƒOØ€Dˆ-ÓØ#'€M�=Ó'Ø"&€L�-Ô&r#   r¡   c                  ó‚   — 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<   edd„«       Zy)Ú	FileChunka�  Bytes returned by a ranged read, and where they sit in the file.

    Attributes:
        content: The bytes returned. Empty when ``unchanged`` is True.
        etag: Validator for the version these bytes came from. Pass it as
            ``if_range`` on the next chunk so a rewrite restarts the read
            instead of splicing two versions together.
        total_bytes: The file's full size, or None when the server did not
            report it.
        start: Offset of the first byte returned.
        partial: True when the server answered 206 with only part of the
            file. A False here after a ranged request means the file
            changed and the server sent it whole -- restart from zero.
        unchanged: True when the caller passed ``if_none_match`` and the
            file still matches it. No bytes are returned.
        last_modified: HTTP-date of the last modification.
    ÚbytesÚcontentNrY   r¢   úOptional[int]Útotal_bytesr   rQ   ÚstartFr0   ÚpartialÚ	unchangedr£   c                óF   — | j                   t        | j                  «      z   S )z(Offset just past the last byte returned.)r«   r�   r¨   r   s    r    ÚendzFileChunk.endf  s   € ð �z‰zœC §¡Ó-Ñ-Ð-r#   r’   )r6   r7   r8   r9   rU   r¢   rª   r«   r¬   r­   r£   r:   r¯   r   r#   r    r¦   r¦   J  s[   … ñð$ ƒNØ€Dˆ-ÓØ!%€K�Ó%Ø€Eˆ3ƒNØ€GˆTÓØ€IˆtÓØ#'€M�=Ó'àò.ó ñ.r#   r¦   c                  óô   — e Zd ZU dZded<   ded<   ded<   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e¬«      Zded<   dZded<   edd„«       Zy)ÚSnapshotuX  Represents a sandbox snapshot.

    Snapshots are built from Docker images or captured from running sandboxes.
    They are used to create new sandboxes.

    Attributes:
        id: Unique identifier (UUID).
        name: Display name.
        status: Build status. One of "building", "ready", "failed".
        fs_capacity_bytes: Filesystem capacity in bytes.
        docker_image: Source Docker image (for build snapshots).
        image_digest: Docker image digest after pull.
        source_sandbox_id: Source sandbox (for capture snapshots).
        status_message: Human-readable details when status is "failed".
        fs_used_bytes: Actual bytes used on the filesystem.
        created_by: User or service that created the snapshot.
        registry_id: Private registry ID, if applicable.
        created_at: Timestamp when the snapshot was created.
        updated_at: Timestamp when the snapshot was last updated.
        tags: Tags currently resolving to this snapshot, under its name. Empty
            means the snapshot is dangling â€” reachable only by id.
        run_config: User, working directory and environment sandboxes built
            from this snapshot boot with, resolved from the Docker image at
            build time. None on snapshots built before the server recorded it,
            which boot as root with no image environment.
    r4   ÚidÚnamerX   rQ   Úfs_capacity_bytesNrY   Údocker_imageÚimage_digestÚsource_sandbox_idrZ   r©   Úfs_used_bytesÚ
created_byÚregistry_idÚ
created_atÚ
updated_atr}   z	list[str]ÚtagsúOptional[RunConfig]ro   c                ó&  —  | |j                  dd«      |j                  dd«      |j                  dd«      |j                  dd«      |j                  d«      |j                  d	«      |j                  d
«      |j                  d«      |j                  d«      |j                  d«      |j                  d«      |j                  d«      |j                  d«      t        |j                  d«      xs g «      t        |j                  d«      «      ¬«      S )z)Create a Snapshot from API response dict.r²   rz   r³   rX   Úbuildingr´   r   rµ   r¶   r·   rZ   r¸   r¹   rº   r»   r¼   r½   ro   )r²   r³   rX   r´   rµ   r¶   r·   rZ   r¸   r¹   rº   r»   r¼   r½   ro   )rE   r”   rr   r^   s     r    r`   zSnapshot.from_dictš  sß   € ñ Ø�x‰x˜˜bÓ!Ø—‘˜& "Ó%Ø—8‘8˜H jÓ1Ø"Ÿh™hÐ':¸AÓ>ØŸ™ .Ó1ØŸ™ .Ó1Ø"Ÿh™hÐ':Ó;ØŸ8™8Ð$4Ó5ØŸ(™( ?Ó3Ø—x‘x Ó-ØŸ™ Ó/Ø—x‘x Ó-Ø—x‘x Ó-Ü�d—h‘h˜vÓ&Ò,¨"Ó-Ü,¨T¯X©X°lÓ-CÓDô
ð 	
r#   )r*   ra   r/   r±   )r6   r7   r8   r9   rU   rµ   r¶   r·   rZ   r¸   r¹   rº   r»   r¼   r	   r”   r½   ro   rb   r`   r   r#   r    r±   r±   l  s¥   … ñð6 	ƒGØ
ƒIØƒKØÓØ"&€L�-Ó&Ø"&€L�-Ó&Ø'+Ð�}Ó+Ø$(€N�MÓ(Ø#'€M�=Ó'Ø $€J�Ó$Ø!%€K�Ó%Ø $€J�Ó$Ø $€J�Ó$á¨DÔ1€Dˆ)Ó1Ø&*€JÐ#Ó*àò
ó ñ
r#   r±   c                  ó8   — e Zd ZU dZded<   ded<   edd„«       Zy)ÚSnapshotTagz±One tag published under a snapshot name, and the snapshot it resolves to.

    Attributes:
        tag: Tag name.
        snapshot_id: Snapshot the tag currently points at.
    r4   ÚtagÚsnapshot_idc                óV   —  | |j                  dd«      |j                  dd«      ¬«      S )z/Create a SnapshotTag from an API response dict.rÃ   rz   rÄ   )rÃ   rÄ   r]   r^   s     r    r`   zSnapshotTag.from_dict¼  s(   € ñ �t—x‘x  rÓ*¸¿¹ÀÐPRÓ8SÔTÐTr#   N)r*   ra   r/   rÂ   rš   r   r#   r    rÂ   rÂ   °  s(   … ñð 
ƒHØÓàòUó ñUr#   rÂ   z!X-Langsmith-Sandbox-Service-Tokené   c                  óò   — e Zd ZdZddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Zedd„«       Zedd„«       Z	edd	„«       Z
edd
„«       Zddd„Zddd„Zddd„Zddd„Zddd„Zddd„Zeddœ	 	 	 	 	 dd„«       Zdd„Zy)Ú
ServiceURLar  Authenticated URL for accessing an HTTP service running in a sandbox.

    Properties auto-refresh the token transparently when it nears expiry.
    HTTP helper methods (``.get``, ``.post``, etc.) inject the auth header
    automatically.

    When constructed by :meth:`SandboxClient.service` or
    :meth:`Sandbox.service`, the object holds an internal refresher that
    re-calls the API to obtain a fresh token before the current one expires.

    Example::

        svc = sb.service(port=3000)

        resp = svc.get("/api/data")  # token injected + auto-refreshed
        print(svc.browser_url)  # always-fresh URL
    N©Ú
_refresherc               óX   — || _         || _        || _        || _        || _        d | _        y r   ©Ú_browser_urlÚ_service_urlÚ_tokenÚ_expires_atrÊ   Ú_sandbox_id©r   Úbrowser_urlÚservice_urlÚtokenÚ
expires_atrÊ   s         r    Ú__init__zServiceURL.__init__Ý  ó2   € ð (ˆÔØ'ˆÔØˆŒØ%ˆÔØ$ˆŒØ*.ˆÕr#   c                óP  — | j                   €y| j                  j                  dd«      }t        j                  |«      }|j
                  € |j                  t        j                  ¬«      }|t        j                  t        j                  «      z
  j                  «       }|t        k  S ©NFÚZz+00:00)Útzinfo©rÊ   rÐ   Úreplacer
   ÚfromisoformatrÜ   r   ÚutcÚnowÚtotal_secondsÚ_REFRESH_MARGIN_SECONDS©r   ÚrawÚexpiresÚ	remainings       r    Ú_should_refreshzServiceURL._should_refreshï  ó�   € Ø�?‰?Ð"ØØ×Ñ×&Ñ& s¨HÓ5ˆÜ×(Ñ(¨Ó-ˆØ�>‰>Ð!Ø—o‘o¬X¯\©\�oÓ:ˆGØœxŸ|™|¬H¯L©LÓ9Ñ9×HÑHÓJˆ	ØÔ3Ñ3Ð3r#   c                óÎ   — | j                  «       rU| j                  «       }|j                  | _        |j                  | _        |j                  | _        |j
                  | _        y y r   ©rè   rÊ   rÍ   rÎ   rÏ   rÐ   ©r   Úfreshs     r    Ú_maybe_refreshzServiceURL._maybe_refreshù  sT   € Ø×ÑÔ!Ø—O‘OÓ%ˆEØ %× 2Ñ 2ˆDÔØ %× 2Ñ 2ˆDÔØŸ,™,ˆDŒKØ$×0Ñ0ˆDÕð "r#   c                ó:   — | j                  «        | j                  S )ú.Return the raw JWT, refreshing if near expiry.©rî   rÏ   r   s    r    rÕ   zServiceURL.token  s   € ð 	×ÑÔØ�{‰{Ðr#   c                ó:   — | j                  «        | j                  S )ú/Return the base URL, refreshing if near expiry.©rî   rÎ   r   s    r    rÔ   zServiceURL.service_url	  ó   € ð 	×ÑÔØ× Ñ Ð r#   c                ó:   — | j                  «        | j                  S )ú7Return the browser auth URL, refreshing if near expiry.©rî   rÍ   r   s    r    rÓ   zServiceURL.browser_url  rõ   r#   c                ó:   — | j                  «        | j                  S )ú:Return the ISO 8601 expiration, refreshing if near expiry.©rî   rÐ   r   s    r    rÖ   zServiceURL.expires_at  s   € ð 	×ÑÔØ×ÑÐr#   c                ó"  — t        | j                  «       | j                  j                  d«      dz   |j	                  d«      z   }t        |j                  dd«      xs i «      }| j                  |t        <   t        j                  ||fd|i|¤ŽS )a"  Make an HTTP request to the service, injecting the auth header.

        Args:
            method: HTTP method (GET, POST, etc.).
            path: Path relative to the service URL.
            **kwargs: Forwarded to ``httpx.request``.

        Returns:
            httpx.Response.
        Ú/ÚheadersN)r   rÑ   rÔ   ÚrstripÚlstripri   ÚpoprÕ   Ú_AUTH_HEADERr   Úrequest)r   Úmethodru   ÚkwargsÚurlrþ   s         r    r  zServiceURL.request  s~   € ô 	˜T×-Ñ-Ô.Ø×Ñ×%Ñ% cÓ*¨SÑ0°4·;±;¸sÓ3CÑCˆÜ�v—z‘z )¨TÓ2Ò8°bÓ9ˆØ $§
¡
ˆ”ÑÜ�}‰}˜V SÑD°'ÐD¸VÑDÐDr#   c                ó*   —  | j                   d|fi |¤ŽS )zHTTP GET to the service.ÚGET©r  ©r   ru   r  s      r    rE   zServiceURL.get.  ó   € àˆt�|‰|˜E 4Ñ2¨6Ñ2Ð2r#   c                ó*   —  | j                   d|fi |¤ŽS )zHTTP POST to the service.ÚPOSTr	  r
  s      r    ÚpostzServiceURL.post2  s   € àˆt�|‰|˜F DÑ3¨FÑ3Ð3r#   c                ó*   —  | j                   d|fi |¤ŽS )zHTTP PUT to the service.ÚPUTr	  r
  s      r    ÚputzServiceURL.put6  r  r#   c                ó*   —  | j                   d|fi |¤ŽS )zHTTP PATCH to the service.ÚPATCHr	  r
  s      r    ÚpatchzServiceURL.patch:  s   € àˆt�|‰|˜G TÑ4¨VÑ4Ð4r#   c                ó*   —  | j                   d|fi |¤ŽS )zHTTP DELETE to the service.ÚDELETEr	  r
  s      r    ÚdeletezServiceURL.delete>  s   € àˆt�|‰|˜H dÑ5¨fÑ5Ð5r#   c               ó4   —  | |d   |d   |d   |d   |¬«      S )z+Create a ServiceURL from API response dict.rÓ   rÔ   rÕ   rÖ   ©rÓ   rÔ   rÕ   rÖ   rÊ   r   ©r_   r*   rÊ   s      r    r`   zServiceURL.from_dictD  ó3   € ñ Ø˜]Ñ+Ø˜]Ñ+Ø�w‘-Ø˜LÑ)Ø!ô
ð 	
r#   c                ó<   — d| j                   ›d| j                  ›d�S )NzServiceURL(service_url=ú, expires_at=Ú)©rÎ   rÐ   r   s    r    Ú__repr__zServiceURL.__repr__T  s-   € à% d×&7Ñ&7Ð%:ð ;Ø×*Ñ*Ð-¨Qð0ð	
r#   )rÓ   r4   rÔ   r4   rÕ   r4   rÖ   r4   rÊ   ú"Optional[Callable[[], ServiceURL]]r/   r2   r.   r1   ©r/   r4   ©rý   ©r  r4   ru   r4   r  r   r/   úhttpx.Response©ru   r4   r  r   r/   r%  )r*   ra   rÊ   r!  r/   rÈ   )r6   r7   r8   r9   r×   rè   rî   r:   rÕ   rÔ   rÓ   rÖ   r  rE   r  r  r  r  rb   r`   r   r   r#   r    rÈ   rÈ   Ê  sþ   „ ñð2 :>ñ/àð/ð ð/ð ð	/ð
 ð/ð 7ð/ð 
ó/ó$4ó1ð òó ðð
 ò!ó ð!ð
 ò!ó ð!ð
 ò ó ð ôEô"3ô4ô3ô5ô6ð ð
 :>ñ	
àð
ð 7ð	
ð
 
ò
ó ð
ô
r#   rÈ   c                  ó"  — e Zd ZdZddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Zdd„Zdd„Zdd	„Z	dd
„Z
edd„«       Zedd„«       Zedd„«       Zedd„«       Z	 d	 	 	 	 	 	 	 dd„Zddd„Zddd„Zddd„Zddd„Zddd„Zeddœ	 	 	 	 	 dd„«       Zdd„Zy)ÚAsyncServiceURLaR  Async variant of :class:`ServiceURL` with auto-refreshing token.

    Properties and HTTP helpers are async. Use with
    :meth:`AsyncSandboxClient.service` or :meth:`AsyncSandbox.service`.

    Example::

        svc = await sb.service(port=3000)

        resp = await svc.get("/api/data")
        print(await svc.get_browser_url())
    NrÉ   c               óX   — || _         || _        || _        || _        || _        d | _        y r   rÌ   rÒ   s         r    r×   zAsyncServiceURL.__init__i  rØ   r#   c                óP  — | j                   €y| j                  j                  dd«      }t        j                  |«      }|j
                  € |j                  t        j                  ¬«      }|t        j                  t        j                  «      z
  j                  «       }|t        k  S rÚ   rÝ   rä   s       r    rè   zAsyncServiceURL._should_refresh{  ré   r#   c              ƒ  óê   K  — | j                  «       r]| j                  «       ƒ d {  –—† }|j                  | _        |j                  | _        |j                  | _        |j
                  | _        y y 7 ŒJ­wr   rë   rì   s     r    rî   zAsyncServiceURL._maybe_refresh…  s^   è ø€ Ø×ÑÔ!ØŸ/™/Ó+×+ˆEØ %× 2Ñ 2ˆDÔØ %× 2Ñ 2ˆDÔØŸ,™,ˆDŒKØ$×0Ñ0ˆDÕð "Ø+ús   ‚$A3¦A1§AA3c              ƒ  óV   K  — | j                  «       ƒ d{  –—†  | j                  S 7 Œ­w)rð   Nrñ   r   s    r    Ú	get_tokenzAsyncServiceURL.get_token�  s'   è ø€ à×!Ñ!Ó#×#Ð#Ø�{‰{Ðð 	$úó   ‚)–'—)c              ƒ  óV   K  — | j                  «       ƒ d{  –—†  | j                  S 7 Œ­w)ró   Nrô   r   s    r    Úget_service_urlzAsyncServiceURL.get_service_url”  ó)   è ø€ à×!Ñ!Ó#×#Ð#Ø× Ñ Ð ð 	$úr.  c              ƒ  óV   K  — | j                  «       ƒ d{  –—†  | j                  S 7 Œ­w)r÷   Nrø   r   s    r    Úget_browser_urlzAsyncServiceURL.get_browser_url™  r1  r.  c              ƒ  óV   K  — | j                  «       ƒ d{  –—†  | j                  S 7 Œ­w)rú   Nrû   r   s    r    Úget_expires_atzAsyncServiceURL.get_expires_atž  s)   è ø€ à×!Ñ!Ó#×#Ð#Ø×ÑÐð 	$úr.  c                ó   — | j                   S )z&Return the raw JWT without refreshing.)rÏ   r   s    r    rÕ   zAsyncServiceURL.token¥  s   € ð �{‰{Ðr#   c                ó   — | j                   S )z'Return the base URL without refreshing.)rÎ   r   s    r    rÔ   zAsyncServiceURL.service_urlª  ó   € ð × Ñ Ð r#   c                ó   — | j                   S )z/Return the browser auth URL without refreshing.)rÍ   r   s    r    rÓ   zAsyncServiceURL.browser_url¯  r8  r#   c                ó   — | j                   S )z3Return the expiration timestamp without refreshing.)rÐ   r   s    r    rÖ   zAsyncServiceURL.expires_at´  ó   € ð ×ÑÐr#   c              ‹  óþ  K  — t        | j                  «       | j                  «       ƒ d{  –—† j                  d«      dz   |j	                  d«      z   }t        |j                  dd«      xs i «      }| j                  «       ƒ d{  –—† |t        <   t        j                  «       4 ƒd{  –—† } |j                  ||fd|i|¤Žƒ d{  –—† cddd«      ƒd{  –—†  S 7 Œ²7 ŒY7 Œ77 Œ7 Œ# 1 ƒd{  –—†7  sw Y   yxY w­w)a4  Make an async HTTP request to the service, injecting the auth header.

        Args:
            method: HTTP method (GET, POST, etc.).
            path: Path relative to the service URL.
            **kwargs: Forwarded to ``httpx.AsyncClient.request``.

        Returns:
            httpx.Response.
        Nrý   rþ   )r   rÑ   r0  rÿ   r   ri   r  r-  r  r   ÚAsyncClientr  )r   r  ru   r  r  rþ   Úclients          r    r  zAsyncServiceURL.request»  sÍ   è ø€ ô 	˜T×-Ñ-Ô.Ø×)Ñ)Ó+×+×3Ñ3°CÓ8¸3Ñ>ÀÇÁÈSÓAQÑQˆÜ�v—z‘z )¨TÓ2Ò8°bÓ9ˆØ&*§n¡nÓ&6× 6ˆ”ÑÜ×$Ñ$×&Ô&¨&Ø'˜Ÿ™¨°ÑO¸WÐOÈÑO×O÷ '×&Ñ&ð ,øà 6øØ&øØOøð 'ø×&×&Ñ&üs|   ‚)C=«C¬AC=ÂC Â#C=Â*C"Â+C=Â.C(ÃC$Ã	C(ÃC=ÃC&ÃC=Ã C=Ã"C=Ã$C(Ã&C=Ã(C:Ã.C1Ã/C:Ã6C=c              ‹  óF   K  —  | j                   d|fi |¤Žƒ d{  –—† S 7 Œ­w)zAsync HTTP GET to the service.r  Nr	  r
  s      r    rE   zAsyncServiceURL.getÏ  ó$   è ø€ à!�T—\‘\ %¨Ñ8°Ñ8×8Ð8Ð8úó   ‚!š›!c              ‹  óF   K  —  | j                   d|fi |¤Žƒ d{  –—† S 7 Œ­w)zAsync HTTP POST to the service.r  Nr	  r
  s      r    r  zAsyncServiceURL.postÓ  s$   è ø€ à!�T—\‘\ &¨$Ñ9°&Ñ9×9Ð9Ð9úrA  c              ‹  óF   K  —  | j                   d|fi |¤Žƒ d{  –—† S 7 Œ­w)zAsync HTTP PUT to the service.r  Nr	  r
  s      r    r  zAsyncServiceURL.put×  r@  rA  c              ‹  óF   K  —  | j                   d|fi |¤Žƒ d{  –—† S 7 Œ­w)z Async HTTP PATCH to the service.r  Nr	  r
  s      r    r  zAsyncServiceURL.patchÛ  s$   è ø€ à!�T—\‘\ '¨4Ñ:°6Ñ:×:Ð:Ð:úrA  c              ‹  óF   K  —  | j                   d|fi |¤Žƒ d{  –—† S 7 Œ­w)z!Async HTTP DELETE to the service.r  Nr	  r
  s      r    r  zAsyncServiceURL.deleteß  s$   è ø€ à!�T—\‘\ (¨DÑ;°FÑ;×;Ð;Ð;úrA  c               ó4   —  | |d   |d   |d   |d   |¬«      S )z1Create an AsyncServiceURL from API response dict.rÓ   rÔ   rÕ   rÖ   r  r   r  s      r    r`   zAsyncServiceURL.from_dictå  r  r#   c                ó<   — d| j                   ›d| j                  ›d�S )NzAsyncServiceURL(service_url=r  r  r  r   s    r    r   zAsyncServiceURL.__repr__õ  s.   € à*¨4×+<Ñ+<Ð*?ð @Ø×*Ñ*Ð-¨Qð0ð	
r#   )rÓ   r4   rÔ   r4   rÕ   r4   rÖ   r4   rÊ   ú2Optional[Callable[[], Awaitable[AsyncServiceURL]]]r/   r2   r.   r1   r"  r#  r$  r&  )r*   ra   rÊ   rH  r/   r(  )r6   r7   r8   r9   r×   rè   rî   r-  r0  r3  r5  r:   rÕ   rÔ   rÓ   rÖ   r  rE   r  r  r  r  rb   r`   r   r   r#   r    r(  r(  [  sA  „ ñð( JNñ/àð/ð ð/ð ð	/ð
 ð/ð Gð/ð 
ó/ó$4ó1óó
!ó
!ó
 ð òó ðð ò!ó ð!ð ò!ó ð!ð ò ó ð ð (+ðPØðPØ!$ðPØ69ðPà	óPô(9ô:ô9ô;ô<ð ð
 JNñ	
àð
ð Gð	
ð
 
ò
ó ð
ô
r#   r(  )Ú
attachmentÚinlinec                  óF   — e Zd ZU dZded<   ded<   dZded<   ed	d„«       Zy)
ÚDownloadURLa8  A link that downloads one sandbox file with no LangSmith credential.

    The link is pinned to the sandbox, the file path, and the response
    headers, so it cannot be repointed at another file. It is pinned to the
    path rather than to a snapshot of the contents, so the file must not be
    modified while the link is in use.

    Attributes:
        download_url: The full URL to fetch. Supports GET, HEAD, and Range.
        token: The signed token embedded in ``download_url``.
        expires_at: Expiry timestamp, or None for a link that never expires.
    r4   Údownload_urlrÕ   NrY   rÖ   c                óv   —  | |j                  dd«      |j                  dd«      |j                  d«      ¬«      S )z,Create a DownloadURL from API response dict.rM  rz   rÕ   rÖ   )rM  rÕ   rÖ   r]   r^   s     r    r`   zDownloadURL.from_dict  s9   € ñ ØŸ™ .°"Ó5Ø—(‘(˜7 BÓ'Ø—x‘x Ó-ô
ð 	
r#   )r*   ra   r/   rL  )r6   r7   r8   r9   rU   rÖ   rb   r`   r   r#   r    rL  rL    s0   … ñð ÓØƒJØ $€J�Ó$àò
ó ñ
r#   rL  )Ú
restrictedÚ	workspacec                  ó8   — e Zd ZU dZded<   ded<   edd„«       Zy)ÚServiceLoginURLuQ  Service URL gated by LangSmith login rather than a token.

    The grant is durable: there is no token to carry and no expiry, so the URL
    is only usable from a browser signed in to LangSmith. That is also why this
    carries none of :class:`ServiceURL`'s auth-injecting HTTP helpers â€” a
    programmatic request cannot satisfy the login.

    Attributes:
        url: The URL to open in a browser.
        access: Who may open it â€” ``"restricted"`` for anyone with
            ``sandboxes:read`` on the sandbox, ``"workspace"`` for any member
            of the owning workspace.
    r4   r  Úaccessc                ó|   —  | |j                  d«      xs |j                  dd«      |j                  dd«      ¬«      S )z0Create a ServiceLoginURL from API response dict.rÓ   rÔ   rz   rS  )r  rS  r]   r^   s     r    r`   zServiceLoginURL.from_dict8  s;   € ñ Ø—‘˜Ó'ÒF¨4¯8©8°MÀ2Ó+FØ—8‘8˜H bÓ)ô
ð 	
r#   N)r*   ra   r/   rR  rš   r   r#   r    rR  rR  %  s%   … ñð 
ƒHØƒKàò
ó ñ
r#   rR  c                  ó0   — e Zd ZU dZded<   ded<   ded<   y)ÚOutputChunkaf  A single chunk of streaming output from command execution.

    Attributes:
        stream: Either "stdout" or "stderr".
        data: The text content of this chunk (valid UTF-8, server handles
            boundary splitting).
        offset: Byte offset within the stream. Used internally for
            reconnection; users typically don't need this.
    r4   Ústreamr*   rQ   ÚoffsetN)r6   r7   r8   r9   rU   r   r#   r    rV  rV  F  s   … ñð ƒKØ
ƒIØ„Kr#   rV  c                  óò   — e Zd ZdZdZdZdZdddddddd	œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
„Zdd„Ze	dd„«       Z
e	dd„«       Ze	dd„«       Zdd„Zdd„Zdd„Zdd„Zdd„Ze	dd„«       Ze	dd„«       Zdd„Zy) ÚCommandHandleu  Handle to a running command with streaming output and auto-reconnect.

    Iterable, yielding OutputChunk objects (stdout and stderr interleaved
    in arrival order). Access .result after iteration to get the full
    ExecutionResult.

    Auto-reconnect behavior:
    - Server hot-reload (1001 Going Away): reconnect immediately
    - Network error / unexpected close:    reconnect with exponential backoff
    - User called kill():                  do NOT reconnect (propagate error)

    The auto-reconnect is transparent -- the iterator reconnects and
    continues yielding chunks without any user intervention. If all
    reconnect attempts are exhausted, SandboxConnectionError is raised.

    Construction modes (controlled by ``command_id``):
    - **New execution** (``command_id=""``, the default): the constructor
      eagerly reads the server's ``"started"`` message to populate
      ``command_id`` and ``pid`` before returning.
    - **Reconnection** (``command_id`` set): skips the started-message
      read. A reconnect stream's ``"started"`` message is the server's
      acknowledgement that the reattachment landed, consumed while iterating to
      clear the reconnect budget â€” the only such signal for a command that
      emits no output.

    Example:
        handle = sandbox.run("make build", timeout=600, wait=False)

        for chunk in handle:          # auto-reconnects on transient errors
            print(chunk.data, end="")

        result = handle.result
        print(f"Exit code: {result.exit_code}")
    é   ç      à?ç       @rz   r   NF©rD   Ústdout_offsetÚstderr_offsetÚ	on_stdoutÚ	on_stderrÚstdin_closedÚptyc               ó  — || _         || _        || _        || _        || _        |	| _        |
| _        d | _        d | _        d | _	        g | _
        g | _        d| _        || _        || _        d| _        |r|| _        y | j!                  «        y )NFr   )Ú_streamÚ_controlÚ_sandboxÚ
_on_stdoutÚ
_on_stderrÚ_stdin_closedÚ_ptyÚ_command_idÚ_pidÚ_resultÚ_stdout_partsÚ_stderr_partsÚ
_exhaustedÚ_last_stdout_offsetÚ_last_stderr_offsetÚ_reconnect_attemptsÚ_consume_started©r   Úmessage_streamÚcontrolÚsandboxrD   r_  r`  ra  rb  rc  rd  s              r    r×   zCommandHandle.__init__  s”   € ð &ˆŒØˆŒØˆŒØ#ˆŒØ#ˆŒØ)ˆÔØˆŒ	Ø*.ˆÔØ#'ˆŒ	Ø26ˆŒØ(*ˆÔØ(*ˆÔØˆŒØ#0ˆÔ Ø#0ˆÔ Ø#$ˆÔ ñ
 Ø)ˆDÕà×!Ñ!Õ#r#   c                ó$  — 	 t        | j                  «      }|j	                  d«      dk7  r t        d|j	                  d«      › d�d¬«      ‚|j	                  d«      | _        |j	                  d	«      | _        y
# t        $ r t        dd¬«      ‚w xY w)aH  Eagerly read the 'started' message to populate command_id and pid.

        Blocks briefly until the server sends the started message (arrives
        near-instantly after connection). After this call, command_id and
        pid are available, and the WebSocket is bound to the control object
        (so kill() works).
        ú-Command stream ended before 'started' messageÚcommand©Ú	operationÚtypeÚstartedú!Expected 'started' message, got 'Ú'rD   ÚpidN)Únextrf  ÚStopIterationrL   rE   r   rm  rn  ©r   Ú	first_msgs     r    rv  zCommandHandle._consume_started¦  s•   € ð	Ü˜TŸ\™\Ó*ˆIð �=‰=˜Ó  IÒ-Ü'Ø3°I·M±MÀ&Ó4IÐ3JÈ!ÐLØ#ôð ð %Ÿ=™=¨Ó6ˆÔØ—M‘M %Ó(ˆ�	øô ò 	Ü+Ø?Ø#ôð ð	ús   ‚A8 Á8Bc                ó   — | j                   S )z=The server-assigned command ID. Available after construction.©rm  r   s    r    rD   zCommandHandle.command_id½  r;  r#   c                ó   — | j                   S )z<The process ID on the sandbox. Available after construction.©rn  r   s    r    r„  zCommandHandle.pidÂ  ó   € ð �y‰yÐr#   c                ór   — | j                   €| D ]  }Œ | j                   €t        dd¬«      ‚| j                   S )zßThe final execution result. Blocks until the command completes.

        Drains the remaining stream if not already exhausted, then returns
        the ExecutionResult with aggregated stdout, stderr, and exit_code.
        ú)Command stream ended without exit messager}  r~  ©ro  r   ©r   Ú_s     r    ÚresultzCommandHandle.resultÇ  sD   € ð �<‰<ÐÛ�Øð à�<‰<ÐÜ'Ø;Ø#ôð ð �|‰|Ðr#   c           	   #  óx  K  — | j                   ry| j                  D �]  }|j                  d«      }|dk(  rt        || j                  «      sŒ1d| _        Œ9|dv rht        ||d   |j                  dd«      ¬«      }|d	k(  r| j                  j                  |d   «       n| j                  j                  |d   «       |–— Œ¥|d
k(  sŒ«t        dj                  | j                  «      dj                  | j                  «      |d   ¬«      | _        d| _         t        | j                  d«        y t        d«      ‚­w©zBIterate over output chunks from the current stream (no reconnect).Nr€  r�  r   )rO   rP   r*   rX  )rW  r*   rX  rO   Úexitrz   rR   )rO   rP   rR   Tr�  )rr  rf  rE   rJ   rm  ru  rV  rp  Úappendrq  rN   Újoinro  r…  r   ©r   rH   Úmsg_typeÚchunks       r    Ú_iter_streamzCommandHandle._iter_streamØ  s  è ø€ à�?Š?ØØ—<•<ˆCØ—w‘w˜v“ˆHØ˜9Ò$Ü*¨3°×0@Ñ0@ÕAØ/0�DÕ,ØÐ1Ñ1Ü#Ø#Ø˜V™ØŸ7™7 8¨QÓ/ô�ð
 ˜xÒ'Ø×&Ñ&×-Ñ-¨c°&©kÕ:à×&Ñ&×-Ñ-¨c°&©kÔ:Ø“Ø˜VÓ#Ü.ØŸ7™7 4×#5Ñ#5Ó6ØŸ7™7 4×#5Ñ#5Ó6Ø! +Ñ.ô �”ð
 #'�”ä�T—\‘\ 4Ô(Ùð3  ô4 %Ð%PÓQÐQùs   ‚A
D:ÁA9D:ÃA3D:c              #  ó<  K  — t        | j                  j                  «       ddl}d| _        	 	 | j                  «       D ]ö  }d| _        |j                  dk(  r^|j                  t        |j                  j                  d«      «      z   | _        | j                  �y| j                  |j                  «       n]|j                  t        |j                  j                  d«      «      z   | _        | j                  �| j                  |j                  «       t        | j                  j                  «       |–— Œø y# t        $ �rT}| j                   r-| j                   j"                  s| j                   j$                  r‚ | xj                  dz  c_        | j                  | j&                  kD  rt        d| j                  › d�«      |‚t)        |t*        «      }|sDt-        | j.                  d| j                  dz
  z  z  | j0                  «      }|j3                  |«       | j4                  €J ‚| j                  j7                  | j4                  | j                  | j                  ¬	«      }|j8                  | _        |j                   | _        d
| _        Y d}~nd}~ww xY w�Œn­w)aE  Iterate over output chunks, auto-reconnecting on transient errors.

        Reconnect strategy:
        - 1001 Going Away (hot-reload): immediate reconnect, no delay
        - Other SandboxConnectionError:  exponential backoff (0.5s, 1s, 2s...)
        - After kill():                  no reconnect, error propagates
        r   NrO   úutf-8é   ú"Failed to reattach to the command ú times in succession, giving upé   ©r_  r`  F)r   rh  r²   Útimeru  rœ  rW  rX  r�   r*   Úencoders  ri  rt  rj  r   rg  r!   r%   ÚMAX_AUTO_RECONNECTSrn   r   ÚminÚ_BACKOFF_BASEÚ_BACKOFF_MAXÚsleeprm  Ú	reconnectrf  rr  )r   r¤  r›  ÚeÚis_hot_reloadÚdelayÚ
new_handles          r    rŠ   zCommandHandle.__iter__ø  sB  è ø€ ô 	˜TŸ]™]×-Ñ-Ô.Ûà#$ˆÔ Øð2(Ø!×.Ñ.Ö0�EØ/0�DÔ,Ø—|‘| xÒ/Ø38·<±<Ä#Ø!ŸJ™J×-Ñ-¨gÓ6óCñ 4˜Ô0ð  Ÿ?™?Ð6Ø ŸO™O¨E¯J©JÕ7à38·<±<Ä#Ø!ŸJ™J×-Ñ-¨gÓ6óCñ 4˜Ô0ð  Ÿ?™?Ð6Ø ŸO™O¨E¯J©JÔ7ä(¨¯©×)9Ñ)9Ô:Ø“Kð! 1ð" øä)ó (Ø—=’=Ø—M‘M×(Ò(¨D¯M©M×,HÒ,Hàà×(Ò(¨AÑ-Õ(Ø×+Ñ+¨d×.FÑ.FÒFÜ0Ø<Ø×3Ñ3Ð4ð 5$ð%óð ð	ô !+¨1Ô.FÓ G�Ù$ÜØ×*Ñ*¨a°D×4LÑ4LÈqÑ4PÑ.QÑRØ×)Ñ)ó�Eð —J‘J˜uÔ%à×'Ñ'Ð3Ð3Ð3Ø!Ÿ]™]×4Ñ4Ø×$Ñ$Ø"&×":Ñ":Ø"&×":Ñ":ð 5ó �
ð
  *×1Ñ1�”Ø *× 3Ñ 3�”Ø"'�—‘ûð=(úñ+ ùs0   ‚,J¯D	D9 Ä8JÄ9
JÅE
JÊJÊJÊJc                ó�   — t        | j                  j                  «       | j                  r| j                  j	                  «        yy)a/  Send a kill signal to the running command (SIGKILL).

        The server kills the entire process group. The stream will
        subsequently yield an exit message with a non-zero exit code.

        Has no effect if the command has already exited or the
        WebSocket connection is closed.
        N©r   rh  r²   rg  r'   r   s    r    ÚkillzCommandHandle.kill9  s2   € ô 	˜TŸ]™]×-Ñ-Ô.Ø�=Š=Ø�M‰M×#Ñ#Õ%ð r#   c                óÈ   — t        | j                  j                  «       | j                  rt	        t
        «      ‚| j                  r| j                  j                  |«       yy)aœ  Write data to the command's stdin.

        Args:
            data: String data to write to stdin.

        Raises:
            SandboxOperationError: If stdin has been closed, either by
                ``close_input()`` or by the ``close_input=True`` default on
                a non-PTY ``run()``.

        Has no effect if the command has already exited or the
        WebSocket connection is closed.
        N©r   rh  r²   rk  r   Ú_STDIN_CLOSED_MESSAGErg  r+   r)   s     r    r+   zCommandHandle.send_inputF  sI   € ô 	˜TŸ]™]×-Ñ-Ô.Ø×ÒÜ'Ô(=Ó>Ð>Ø�=Š=Ø�M‰M×$Ñ$ TÕ*ð r#   c                óÐ   — t        | j                  j                  «       | j                  s| j                  ryd| _        | j
                  r| j
                  j                  «        yy©a  Half-close stdin so the command reads EOF.

        Idempotent, and a no-op under a PTY, where input and output share
        one terminal file descriptor and there is no write end to close --
        send an EOT byte (``0x04``) with :meth:`send_input` instead.
        NT©r   rh  r²   rl  rk  rg  r-   r   s    r    Úclose_inputzCommandHandle.close_inputZ  sL   € ô 	˜TŸ]™]×-Ñ-Ô.Ø�9Š9˜×*Ò*ØØ!ˆÔØ�=Š=Ø�M‰M×*Ñ*Õ,ð r#   c                ó   — | j                   S ©z8Last known stdout byte offset (for manual reconnection).©rs  r   s    r    Úlast_stdout_offsetz CommandHandle.last_stdout_offseth  ó   € ð ×'Ñ'Ð'r#   c                ó   — | j                   S ©z8Last known stderr byte offset (for manual reconnection).©rt  r   s    r    Úlast_stderr_offsetz CommandHandle.last_stderr_offsetm  r¾  r#   c                óÂ   — | j                   €J ‚| j                  j                  | j                   | j                  | j                  | j
                  | j                  ¬«      S )aÛ  Reconnect to this command from the last known offsets.

        Returns a new handle that resumes output from where this one
        left off. Any output produced while disconnected is replayed
        from the server's ring buffer.

        Returns:
            A new CommandHandle.

        Raises:
            SandboxOperationError: If command_id is not found or
                session expired.
            SandboxConnectionError: If connection to sandbox fails.
        ©r_  r`  rc  rd  ©rm  rh  r«  rs  rt  rk  rl  r   s    r    r«  zCommandHandle.reconnectr  s]   € ð ×ÑÐ+Ð+Ð+Ø�}‰}×&Ñ&Ø×ÑØ×2Ñ2Ø×2Ñ2Ø×+Ñ+Ø—	‘	ð 'ó 
ð 	
r#   )rx  zIterator[dict]ry  zOptional[StreamControl]rz  r   rD   r4   r_  rQ   r`  rQ   ra  úOptional[Callable[[str], Any]]rb  rÆ  rc  r0   rd  r0   r/   r2   r1   ©r/   rY   ©r/   r©   ©r/   rN   )r/   zIterator[OutputChunk]r3   r’   )r/   rZ  )r6   r7   r8   r9   r¦  r¨  r©  r×   rv  r:   rD   r„  r“  rœ  rŠ   r²  r+   r¹  r½  rÂ  r«  r   r#   r    rZ  rZ  W  s-  „ ñ!ðF ÐØ€MØ€Lð ØØØ48Ø48Ø"Øñ%$à&ð%$ð )ð%$ð ð	%$ð ð%$ð ð%$ð ð%$ð 2ð%$ð 2ð%$ð ð%$ð ð%$ð 
ó%$óN)ð. ò ó ð ð òó ðð òó ðó Ró@?(óB&ó+ó(-ð ò(ó ð(ð ò(ó ð(ô
r#   rZ  c                  óò   — e Zd ZdZdZdZdZdddddddd	œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
„Zdd„Ze	dd„«       Z
e	dd„«       Ze	dd„«       Zdd„Zdd„Zdd„Zdd„Zdd„Ze	dd„«       Ze	dd„«       Zdd„Zy) ÚAsyncCommandHandleue  Async handle to a running command with streaming output and auto-reconnect.

    Async iterable, yielding OutputChunk objects (stdout and stderr interleaved
    in arrival order). Access .result after iteration to get the full
    ExecutionResult.

    Auto-reconnect behavior:
    - Server hot-reload (1001 Going Away): reconnect immediately
    - Network error / unexpected close:    reconnect with exponential backoff
    - User called kill():                  do NOT reconnect (propagate error)

    Construction modes (controlled by ``command_id``):
    - **New execution** (``command_id=""``, the default): call
      ``await handle._ensure_started()`` after construction to read the
      server's ``"started"`` message and populate ``command_id`` / ``pid``.
    - **Reconnection** (``command_id`` set): skips the started-message
      read. A reconnect stream's ``"started"`` message is the server's
      acknowledgement that the reattachment landed, consumed while iterating to
      clear the reconnect budget â€” the only such signal for a command that
      emits no output.

    Example:
        handle = await sandbox.run("make build", timeout=600, wait=False)

        async for chunk in handle:    # auto-reconnects on transient errors
            print(chunk.data, end="")

        result = await handle.result
        print(f"Exit code: {result.exit_code}")
    r[  r\  r]  rz   r   NFr^  c               ó  — || _         || _        || _        || _        || _        |	| _        |
| _        d | _        d | _        d | _	        g | _
        g | _        d| _        || _        || _        d| _        |r|| _        d| _        y d| _        y )NFr   T)rf  rg  rh  ri  rj  rk  rl  rm  rn  ro  rp  rq  rr  rs  rt  ru  Ú_startedrw  s              r    r×   zAsyncCommandHandle.__init__¯  s–   € ð &ˆŒØˆŒØˆŒØ#ˆŒØ#ˆŒØ)ˆÔØˆŒ	Ø*.ˆÔØ#'ˆŒ	Ø26ˆŒØ(*ˆÔØ(*ˆÔØˆŒØ#0ˆÔ Ø#0ˆÔ Ø#$ˆÔ ñ
 Ø)ˆDÔØ ˆD�Mà!ˆD�Mr#   c              ƒ  ór  K  — | j                   ry	 | j                  j                  «       ƒ d{  –—† }|j                  d«      dk7  r t        d|j                  d«      › d�d¬«      ‚|j                  d	«      | _        |j                  d
«      | _        d| _         y7 Œl# t        $ r t	        dd¬«      ‚w xY w­w)z:Read the 'started' message to populate command_id and pid.Nr|  r}  r~  r€  r�  r‚  rƒ  rD   r„  T)	rÍ  rf  Ú	__anext__ÚStopAsyncIterationrL   rE   r   rm  rn  r‡  s     r    Ú_ensure_startedz"AsyncCommandHandle._ensure_started×  s³   è ø€ à�=Š=Øð	Ø"Ÿl™l×4Ñ4Ó6×6ˆIð �=‰=˜Ó  IÒ-Ü'Ø3°I·M±MÀ&Ó4IÐ3JÈ!ÐLØ#ôð ð %Ÿ=™=¨Ó6ˆÔØ—M‘M %Ó(ˆŒ	Øˆ�ð 7ùÜ!ò 	Ü+Ø?Ø#ôð ð	üs,   ‚B7‘B ®B¯B ³A(B7ÂB ÂB4Â4B7c                ó   — | j                   S )z@The server-assigned command ID. Available after _ensure_started.rŠ  r   s    r    rD   zAsyncCommandHandle.command_idë  r;  r#   c                ó   — | j                   S )z?The process ID on the sandbox. Available after _ensure_started.rŒ  r   s    r    r„  zAsyncCommandHandle.pidð  r�  r#   c              ƒ  óŒ   K  — | j                   €| 2 3 d{  –—† }Œ
| j                   €t        dd¬«      ‚| j                   S 7 Œ*6 Œ)­w)z&The final execution result. Awaitable.Nr�  r}  r~  r�  r‘  s     r    r“  zAsyncCommandHandle.resultõ  sP   è ø€ ð �<‰<ÐÙ÷ �aØØ�<‰<ÐÜ'Ø;Ø#ôð ð �|‰|Ððø˜4ús%   ‚A‘A•A –A™'AÁ AÁAc           	    óþ  K  — | j                  «       ƒ d{  –—†  | j                  ry| j                  2 3 d{  –—† }|j                  d«      }|dk(  rt	        || j
                  «      sŒ6d| _        Œ>|dv rit        ||d   |j                  dd«      ¬«      }|d	k(  r| j                  j                  |d   «       n| j                  j                  |d   «       |­–— Œ«|d
k(  sŒ±t        dj                  | j                  «      dj                  | j                  «      |d   ¬«      | _        d| _        	 | j                  j                  «       ƒ d{  –—†   y7 �ŒC7 �Œ$7 Œ# t        $ r Y  yw xY w6 t!        d«      ‚­wr•  )rÑ  rr  rf  rE   rJ   rm  ru  rV  rp  r—  rq  rN   r˜  ro  rÏ  rÐ  r   r™  s       r    Ú_aiter_streamz AsyncCommandHandle._aiter_stream  si  è ø€ à×"Ñ"Ó$×$Ð$Ø�?Š?ØØŸš÷ 	�#Ø—w‘w˜v“ˆHØ˜9Ò$Ü*¨3°×0@Ñ0@ÕAØ/0�DÕ,ØÐ1Ñ1Ü#Ø#Ø˜V™ØŸ7™7 8¨QÓ/ô�ð
 ˜xÒ'Ø×&Ñ&×-Ñ-¨c°&©kÕ:à×&Ñ&×-Ñ-¨c°&©kÔ:Ø”Ø˜VÓ#Ü.ØŸ7™7 4×#5Ñ#5Ó6ØŸ7™7 4×#5Ñ#5Ó6Ø! +Ñ.ô �”ð
 #'�”ðØŸ,™,×0Ñ0Ó2×2Ð2ñ ð? 	%ùð	ùð2 3ùÜ)ò ØÙðúð5 &ô: %Ð%PÓQÐQùsm   ‚E=–E—E=´E1¸E¹E1¼-E=Á*A:E=Ã%AE=Ä5E!ÅEÅE!ÅE=ÅE1ÅE!Å!	E.Å*E=Å-E.Å.E=c               ór  K  — t        | j                  j                  «       ddl}d| _        	 	 | j                  «       2 3 d{  –—† }d| _        |j                  dk(  r^|j                  t        |j                  j                  d«      «      z   | _        | j                  �y| j                  |j                  «       n]|j                  t        |j                  j                  d«      «      z   | _        | j                  �| j                  |j                  «       t        | j                  j                  «       |­–— Œÿ7 Œú6 y# t        $ �rf}| j                   r-| j                   j"                  s| j                   j$                  r‚ | xj                  dz  c_        | j                  | j&                  kD  rt        d| j                  › d�«      |‚t)        |t*        «      }|sMt-        | j.                  d| j                  dz
  z  z  | j0                  «      }|j3                  |«      ƒ d{  –—†7   | j4                  €J ‚| j                  j7                  | j4                  | j                  | j                  ¬	«      ƒ d{  –—†7  }|j8                  | _        |j                   | _        d
| _        Y d}~nd}~ww xY w�Œ‰­w)z6Async iterate with auto-reconnect on transient errors.r   NrO   rž  rŸ  r   r¡  r¢  r£  F)r   rh  r²   Úasyncioru  rÖ  rW  rX  r�   r*   r¥  rs  ri  rt  rj  r   rg  r!   r%   r¦  rn   r   r§  r¨  r©  rª  rm  r«  rf  rr  )r   rØ  r›  r¬  r­  r®  r¯  s          r    Ú	__aiter__zAsyncCommandHandle.__aiter__&  sY  è ø€ ä˜TŸ]™]×-Ñ-Ô.Ûà#$ˆÔ Øð2(Ø#'×#5Ñ#5Ô#7÷  ˜%Ø/0�DÔ,Ø—|‘| xÒ/Ø38·<±<Ä#Ø!ŸJ™J×-Ñ-¨gÓ6óCñ 4˜Ô0ð  Ÿ?™?Ð6Ø ŸO™O¨E¯J©JÕ7à38·<±<Ä#Ø!ŸJ™J×-Ñ-¨gÓ6óCñ 4˜Ô0ð  Ÿ?™?Ð6Ø ŸO™O¨E¯J©JÔ7ä(¨¯©×)9Ñ)9Ô:Ø”Kð! øÐ#7ð" øä)ó (Ø—=’=Ø—M‘M×(Ò(¨D¯M©M×,HÒ,Hàà×(Ò(¨AÑ-Õ(Ø×+Ñ+¨d×.FÑ.FÒFÜ0Ø<Ø×3Ñ3Ð4ð 5$ð%óð ð	ô !+¨1Ô.FÓ G�Ù$ÜØ×*Ñ*¨a°D×4LÑ4LÈqÑ4PÑ.QÑRØ×)Ñ)ó�Eð "Ÿ-™-¨Ó.×.Ñ.à×'Ñ'Ð3Ð3Ð3Ø#'§=¡=×#:Ñ#:Ø×$Ñ$Ø"&×":Ñ":Ø"&×":Ñ":ð $;ó $÷ ð �
ð
  *×1Ñ1�”Ø *× 3Ñ 3�”Ø"'�—‘ûð=(úñ+ ùsl   ‚,J7¯E ¿E ÁD>ÁE ÁC7E Ä>E Å E ÅJ7Å
J2ÅCJ-È&H)È'AJ-É9I<É:.J-Ê(J7Ê-J2Ê2J7c              ƒ  ó¬   K  — t        | j                  j                  «       | j                  r#| j                  j	                  «       ƒ d{  –—†  yy7 Œ­w)z*Send a kill signal to the running command.Nr±  r   s    r    r²  zAsyncCommandHandle.killa  s=   è ø€ ä˜TŸ]™]×-Ñ-Ô.Ø�=Š=Ø—-‘-×)Ñ)Ó+×+Ñ+ð Ø+ús   ‚A	AÁAÁAc              ƒ  óä   K  — t        | j                  j                  «       | j                  rt	        t
        «      ‚| j                  r$| j                  j                  |«      ƒ d{  –—†  yy7 Œ­w)zôWrite data to the command's stdin.

        Raises:
            SandboxOperationError: If stdin has been closed, either by
                ``close_input()`` or by the ``close_input=True`` default on
                a non-PTY ``run()``.
        Nr´  r)   s     r    r+   zAsyncCommandHandle.send_inputg  sV   è ø€ ô 	˜TŸ]™]×-Ñ-Ô.Ø×ÒÜ'Ô(=Ó>Ð>Ø�=Š=Ø—-‘-×*Ñ*¨4Ó0×0Ñ0ð Ø0ús   ‚A%A0Á'A.Á(A0c              ƒ  óì   K  — t        | j                  j                  «       | j                  s| j                  ryd| _        | j
                  r#| j
                  j                  «       ƒ d{  –—†  yy7 Œ­wr·  r¸  r   s    r    r¹  zAsyncCommandHandle.close_inputu  sY   è ø€ ô 	˜TŸ]™]×-Ñ-Ô.Ø�9Š9˜×*Ò*ØØ!ˆÔØ�=Š=Ø—-‘-×0Ñ0Ó2×2Ñ2ð Ø2ús   ‚A)A4Á+A2Á,A4c                ó   — | j                   S r»  r¼  r   s    r    r½  z%AsyncCommandHandle.last_stdout_offsetƒ  r¾  r#   c                ó   — | j                   S rÀ  rÁ  r   s    r    rÂ  z%AsyncCommandHandle.last_stderr_offsetˆ  r¾  r#   c              ƒ  óÞ   K  — | j                   €J ‚| j                  j                  | j                   | j                  | j                  | j
                  | j                  ¬«      ƒ d{  –—† S 7 Œ­w)z6Reconnect to this command from the last known offsets.NrÄ  rÅ  r   s    r    r«  zAsyncCommandHandle.reconnect�  si   è ø€ à×ÑÐ+Ð+Ð+Ø—]‘]×,Ñ,Ø×ÑØ×2Ñ2Ø×2Ñ2Ø×+Ñ+Ø—	‘	ð -ó 
÷ 
ð 	
ð 
ús   ‚A$A-Á&A+Á'A-)rx  zAsyncIterator[dict]ry  zOptional[AsyncStreamControl]rz  r   rD   r4   r_  rQ   r`  rQ   ra  rÆ  rb  rÆ  rc  r0   rd  r0   r/   r2   r1   rÇ  rÈ  rÉ  )r/   zAsyncIterator[OutputChunk]r3   r’   )r/   rË  )r6   r7   r8   r9   r¦  r¨  r©  r×   rÑ  r:   rD   r„  r“  rÖ  rÙ  r²  r+   r¹  r½  rÂ  r«  r   r#   r    rË  rË  ‹  s,  „ ñð> ÐØ€MØ€Lð ØØØ48Ø48Ø"Øñ&"à+ð&"ð .ð&"ð ð	&"ð ð&"ð ð&"ð ð&"ð 2ð&"ð 2ð&"ð ð&"ð ð&"ð 
ó&"óPð( ò ó ð ð òó ðð ò
ó ð
ó"RóH9(óv,ó1ó3ð ò(ó ð(ð ò(ó ð(ô	
r#   rË  )rH   ri   rD   rY   r/   r0   )ro   z*Optional[Union[RunConfig, dict[str, Any]]]r/   úOptional[dict[str, Any]])r*   rà  r/   r¾   )Ar9   Ú
__future__r   ÚloggingÚcollections.abcr   r   r   r   Údataclassesr   r	   r
   r   Útypingr   r   r   r   r   r   Ú langsmith._openapi_client._httpxr   Úlangsmith.sandbox._exceptionsr   r   r   Úlangsmith.sandbox._tracingr   Ú langsmith.sandbox._async_sandboxr   Úlangsmith.sandbox._sandboxr   Ú	getLoggerr6   rF   r   r<   rµ  rJ   rL   rN   rW   rd   rp   rr   rt   r|   r–   rœ   r¡   r¦   r±   rÂ   r  rã   rÈ   r(  ÚDownloadContentDispositionrL  ÚServiceAccessrR  rV  rZ  rË  r   r#   r    Ú<module>rî     sa  ðÙ )å "ã ß HÓ Hß (ß 'ß I× Iå 2÷ñ õ
 <áÝ=Ý2à	ˆ×	Ñ	˜8Ó	$€ô,�Hô ,ô47˜ô 7ð":ð óô(Ð 5ô ð ÷
#ð 
#ó ð
#ð ÷
ð 
ó ð
ð( ÷'ð 'ó ð'ðTØ:ðàóó%ð ÷
ð 
ó ð
ð4 ÷!ð !ó ð!ð: ÷
ð 
ó ð
ð. ÷!ð !ó ð!ð8 ÷'ð 'ó ð'ð$ ÷.ð .ó ð.ðB ÷@
ð @
ó ð@
ðF ÷Uð Uó ðUð* 3€ØÐ ÷N
ñ N
÷b^
ñ ^
ðL %Ð%;Ñ<Ð Ø >ð ÷
ð 
ó ð
ð8 Ð1Ñ2€ð ÷
ð 
ó ð
ð@ ÷ð ó ð÷ q
ñ q
÷h	K
ò K
r#   