Ë
    òÏjV6  ã                  ó$  — d dl mZ d dl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 d dlmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZ d dlmZ  ej4                  e«      Zdd„Z G d„ d«      Z G d„ deeef   «      Z  G d„ d«      Z! G d„ d«      Z"y)é    )ÚannotationsN)ÚAsyncIteratorÚIteratorÚMapping)ÚTracebackType)ÚAnyÚcast)ÚRunnableConfig)ÚAsyncThreadStream)ÚSyncThreadStream)ÚLangGraphClientÚSyncLangGraphClient)ÚDataDecoder)ÚCommandc                ó„   — t        | t        «      r/| j                  s| j                  rt	        d«      ‚| j
                  S | S )a‡  Translate a local `Command` into the v3 wire `input`, else passthrough.

    The v3 server decides start-vs-resume from thread state (an interrupted
    run or pending interrupts) and, on resume, wraps the whole `input` as
    `{"resume": input}` itself. So a resume `Command` must surface its raw
    `resume` value as the wire `input` (not the serialized dataclass, which
    the server would double-wrap). The v3 `run.start` path has no `goto` /
    `update` channel, so those are rejected.

    `langgraph_sdk` is upstream of `langgraph`, so this `Command`-aware
    marshalling lives here on the adapter (langgraph) side of the boundary.
    z}RemoteGraph v3 streaming supports `Command(resume=...)` only; `goto` / `update` are not supported by the v3 `run.start` path.)Ú
isinstancer   ÚgotoÚupdateÚNotImplementedErrorÚresume)Úinputs    ú`/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph/pregel/_remote_run_stream.pyÚ_translate_command_inputr      s?   € ô �%œÔ!Ø�:Š:˜ŸšÜ%ðRóð ð �|‰|ÐØ€Ló    c                  ó0   — e Zd ZdZdd„Zdd„Zd	d„Zd	d„Zy)
Ú_ChannelProjectionuË  Decoded projection for a wire channel the SDK doesn't type natively.

    Subscribes to `channel` and decodes each event's `params["data"]` through the
    SDK's `DataDecoder` â€” the same decoder the SDK's own plain-payload projections
    (`values` / `updates` / `checkpoints` / `tasks`) use, which yields the item
    shape that local's `UpdatesTransformer` / `CheckpointsTransformer` /
    `TasksTransformer` / `CustomTransformer` push, so iterating this matches the
    corresponding local projection. Iterate with `for` against a sync stream and
    `async for` against an async stream (matching the underlying SDK). Opening
    the subscription requires the stream to be entered (`with` / `async with`).
    c                ó    — || _         || _        y ©N)Ú_sdkÚ_channel)ÚselfÚsdkÚchannels      r   Ú__init__z_ChannelProjection.__init__9   s   € ØˆŒ	Øˆ�r   c              #  óð   K  — t        | j                  «      }t        t        t           | j
                  j                  | j                  g«      «      }|D ]  }|j                  |«      E d {  –—†  Œ y 7 Œ­wr   )r   r    r	   r   r   r   Ú	subscribeÚfeed)r!   ÚdecoderÚeventsÚevents       r   Ú__iter__z_ChannelProjection.__iter__=   sX   è ø€ ä˜dŸm™mÓ,ˆÜ”hœs‘m T§Y¡Y×%8Ñ%8¸$¿-¹-¸Ó%IÓJˆÛˆEØ—|‘| EÓ*×*Ñ*ñ Ø*ús   ‚A*A6Á,A4Á-A6c                ó"   — | j                  «       S r   )Ú_aiter©r!   s    r   Ú	__aiter__z_ChannelProjection.__aiter__D   s   € Ø�{‰{‹}Ðr   c               ó   K  — t        | j                  «      }t        t        t           | j
                  j                  | j                  g«      «      }|2 3 d {  –—† }|j                  |«      D ]  }|­–— Œ	 Œ%7 Œ 6 y ­wr   )r   r    r	   r   r   r   r&   r'   )r!   r(   r)   r*   Úitems        r   r-   z_ChannelProjection._aiterG   sd   è ø€ ä˜dŸm™mÓ,ˆÜ”m¤CÑ(¨$¯)©)×*=Ñ*=¸t¿}¹}¸oÓ*NÓOˆÙ!÷ 	�%ØŸ™ UÖ+�Ø”
ñ ,ð	ø™6ùs*   ‚AA>ÁA<ÁA:ÁA<ÁA>Á:A<Á<A>N)r"   ú$AsyncThreadStream | SyncThreadStreamr#   ÚstrÚreturnÚNone©r4   zIterator[Any]©r4   zAsyncIterator[Any])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r+   r/   r-   © r   r   r   r   ,   s   „ ñ
ó ó+óôr   r   c                  óB   — e Zd ZdZdZdZeez   Zd	d„Zd
d„Zdd„Z	dd„Z
y)Ú_ProjectionRegistryu­  Read-only name -> projection registry mirroring local `GraphRunStream.extensions`.

    Resolution follows the langchain-protocol wire channels, and every entry
    yields the same decoded item shape local does (`params.data`):

    - `values` / `messages` / `tool_calls` / `subgraphs` resolve to the SDK's
      decoded typed projections. `tool_calls` is the `tools` channel â€” tool
      *execution* events, distinct from the tool-call *inputs* inside `messages`.
    - `updates` / `checkpoints` / `tasks` / `custom` have no typed SDK
      projection, so they resolve to a `_ChannelProjection` that subscribes to
      the channel and yields `params.data` â€” matching the local transformer
      output for those channels.
    - any other name is a specific custom-extension channel
      (`thread.extensions[name]`, i.e. `custom:<name>`).

    `lifecycle` is intentionally absent: local derives a status payload from it
    rather than yielding `params.data`, and the SDK consumes it as control-plane
    (driving `output` / `interrupted`), so its shape can't be matched â€” it
    remains reachable via the raw `events` iterator. `debug` is absent too: it
    is not a v3 wire channel.
    )ÚvaluesÚmessagesÚ
tool_callsÚ	subgraphs)ÚupdatesÚcheckpointsÚtasksÚcustomc                ó   — || _         y r   )r   )r!   r"   s     r   r$   z_ProjectionRegistry.__init__m   s	   € Øˆ�	r   c                óÄ   — || j                   v rt        | j                  |«      S || j                  v rt	        | j                  |«      S | j                  j
                  |   S r   )Ú_TYPEDÚgetattrr   Ú_DECODEDr   Ú
extensions)r!   Únames     r   Ú__getitem__z_ProjectionRegistry.__getitem__p   sQ   € Ø�4—;‘;ÑÜ˜4Ÿ9™9 dÓ+Ð+Ø�4—=‘=Ñ Ü% d§i¡i°Ó6Ð6Ø�y‰y×#Ñ# DÑ)Ð)r   c                ó,   — t        | j                  «      S r   )ÚiterÚ_NATIVEr.   s    r   r+   z_ProjectionRegistry.__iter__w   s   € Ü�D—L‘LÓ!Ð!r   c                ó,   — t        | j                  «      S r   )ÚlenrQ   r.   s    r   Ú__len__z_ProjectionRegistry.__len__z   s   € Ü�4—<‘<Ó Ð r   N)r"   r2   r4   r5   )rM   r3   r4   r   )r4   zIterator[str])r4   Úint)r8   r9   r:   r;   rI   rK   rQ   r$   rN   r+   rT   r<   r   r   r>   r>   P   s1   „ ñð. ?€Fà<€HØ�xÑ€Góó*ó"ô!r   r>   c                  óø   — e Zd Z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edd	„«       Zedd
„«       Zedd„«       Zedd„«       Zdd„Zdd„Zdd„Zy)Ú_RemoteGraphRunStreamz9Sync adapter: SyncThreadStream -> GraphRunStream surface.c               ór   — || _         || _        t        |«      ||dœ| _        d | _        d| _        d | _        y ©N)r   ÚconfigÚmetadataF)Ú_clientr   r   Ú_start_kwargsÚ_run_idÚ_closedÚ_events_iter)r!   Úsync_clientÚ
sdk_threadr   rZ   r[   s         r   r$   z_RemoteGraphRunStream.__init__�   sB   € ð #ˆŒØˆŒ	ä-¨eÓ4ØØ ñ.
ˆÔð
 $(ˆŒØˆŒØ26ˆÕr   c                óP  — | j                   rt        d«      ‚| j                  j                  «        	  | j                  j                  j
                  di | j                  ¤Ž}|d   | _        | S # t        $ r-  | j                  j                  t        j                  «       Ž  ‚ w xY w)Nz$_RemoteGraphRunStream already closedÚrun_idr<   )r_   ÚRuntimeErrorr   Ú	__enter__ÚrunÚstartr]   ÚBaseExceptionÚ__exit__ÚsysÚexc_infor^   ©r!   Úresults     r   rf   z_RemoteGraphRunStream.__enter__•   sŽ   € Ø�<Š<ÜÐEÓFÐFØ�	‰	×ÑÔð	Ø(�T—Y‘Y—]‘]×(Ñ(Ñ>¨4×+=Ñ+=Ñ>ˆFð ˜hÑ'ˆŒØˆøô	 ò 	ØˆD�I‰I×Ñ¤§¡£Ñ/Øð	ús   ³0A/ Á/6B%c                óf   — | j                   ry d| _         | j                  j                  |||«       y ©NT)r_   r   rj   ©r!   Úexc_typeÚexcÚtbs       r   rj   z_RemoteGraphRunStream.__exit__¡   s+   € ð �<Š<ØØˆŒØ�	‰	×Ñ˜8 S¨"Õ-r   c                ó.   — | j                   j                  S r   ©r   Úoutputr.   s    r   rw   z_RemoteGraphRunStream.output¬   s   € à�y‰y×ÑÐr   c                ó.   — | j                   j                  S )ap  Whether the remote run is currently paused at an interrupt.

        Reads the SDK's current value without blocking. This differs from
        local `GraphRunStream.interrupted`, which drives the run to terminal
        before returning the flag. Sync callers needing a wait-for-interrupt
        pattern should switch to the async API and drain a projection.
        ©r   Úinterruptedr.   s    r   rz   z!_RemoteGraphRunStream.interrupted°   s   € ð �y‰y×$Ñ$Ð$r   c                ó@   — t        | j                  j                  «      S )z?Current outstanding interrupt payloads (non-blocking snapshot).©Úlistr   Ú
interruptsr.   s    r   r~   z _RemoteGraphRunStream.interrupts»   s   € ô �D—I‘I×(Ñ(Ó)Ð)r   c                ó.   — | j                   j                  S ©z<Live state-snapshot projection (mirrors local `run.values`).©r   r?   r.   s    r   r?   z_RemoteGraphRunStream.valuesÀ   ó   € ð �y‰y×ÑÐr   c                ó.   — | j                   j                  S ©z>Live message-stream projection (mirrors local `run.messages`).©r   r@   r.   s    r   r@   z_RemoteGraphRunStream.messagesÅ   ó   € ð �y‰y×!Ñ!Ð!r   c                ó.   — | j                   j                  S ©z;Subgraph-handle projection (mirrors local `run.subgraphs`).©r   rB   r.   s    r   rB   z_RemoteGraphRunStream.subgraphsÊ   ó   € ð �y‰y×"Ñ"Ð"r   c                ó.   — | j                   j                  S ©zËTool-execution projection (the `tools` channel).

        These are tool *execution* events (started / output / finished),
        distinct from the tool-call *inputs* carried inside `messages`.
        ©r   rA   r.   s    r   rA   z _RemoteGraphRunStream.tool_callsÏ   ó   € ð �y‰y×#Ñ#Ð#r   c                ó,   — t        | j                  «      S ©z=Name -> projection registry (mirrors local `run.extensions`).©r>   r   r.   s    r   rL   z _RemoteGraphRunStream.extensionsØ   ó   € ô # 4§9¡9Ó-Ð-r   c                ó   — | j                   ry d| _         | j                  �G	 | j                  j                  j	                  | j
                  j                  | j                  d¬«       	 | j
                  j                  «        y # t        $ r t        j                  dd¬«       Y Œ>w xY w# t        $ r t        j                  dd¬«       Y y w xY w©NTF)Úwaitzabort: runs.cancel failed)rl   zabort: sdk.close failed©r_   r^   r\   ÚrunsÚcancelr   Ú	thread_idÚ	ExceptionÚloggerÚdebugÚcloser.   s    r   Úabortz_RemoteGraphRunStream.abortÝ   s¬   € Ø�<Š<ØØˆŒØ�<‰<Ð#ðIØ—‘×!Ñ!×(Ñ(¨¯©×)<Ñ)<¸d¿l¹lÐQVÐ(ÔWð	CØ�I‰I�O‰OÕøô ò IÜ—‘Ð8À4�ÖHðIûô ò 	CÜ�L‰LÐ2¸TˆLÖBð	Cús$   ¢AB Á)B* Â B'Â&B'Â* CÃCc                óz   — | j                   €$t        | j                  j                  «      | _         | j                   S r   )r`   rP   r   r)   r.   s    r   r+   z_RemoteGraphRunStream.__iter__ë   s1   € Ø×ÑÐ$Ü $ T§Y¡Y×%5Ñ%5Ó 6ˆDÔØ× Ñ Ð r   c              '  óh   K  — | j                   j                  t        |«      «      E d {  –—†  y 7 Œ­wr   )r   Úinterleave_projectionsr}   )r!   Únamess     r   Ú
interleavez _RemoteGraphRunStream.interleaveð   s"   è ø€ Ø—9‘9×3Ñ3´D¸³KÓ@×@Ò@ús   ‚(2ª0«2N)ra   r   rb   r   r   r   rZ   úRunnableConfig | Noner[   údict[str, Any] | Noner4   r5   )r4   rW   ©rr   ztype[BaseException] | Noners   zBaseException | Nonert   zTracebackType | Noner4   r5   ©r4   r   ©r4   Úbool©r4   z	list[Any]©r4   zMapping[str, Any]©r4   r5   r6   )r¢   r3   r4   zIterator[tuple[str, Any]])r8   r9   r:   r;   r$   rf   rj   Úpropertyrw   rz   r~   r?   r@   rB   rA   rL   rž   r+   r£   r<   r   r   rW   rW   ~   s'  „ ÙCð7ð )ð7ð %ð	7ð
 ð7ð &ð7ð (ð7ð 
ó7ó(
ð	.à,ð	.ð "ð	.ð !ð		.ð
 
ó	.ð ò ó ð ð ò%ó ð%ð ò*ó ð*ð ò ó ð ð ò"ó ð"ð ò#ó ð#ð ò$ó ð$ð ò.ó ð.óCó!ô
Ar   rW   c                  óÒ   — e Zd Z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e
dd„«       Zdd„Zdd„Zy)Ú_AsyncRemoteGraphRunStreamz@Async adapter: AsyncThreadStream -> AsyncGraphRunStream surface.c               ór   — || _         || _        t        |«      ||dœ| _        d | _        d| _        d | _        y rY   )r\   r   r   r]   r^   r_   Ú_events_aiter)r!   Úclientrb   r   rZ   r[   s         r   r$   z#_AsyncRemoteGraphRunStream.__init__÷   sB   € ð ˆŒØˆŒ	ä-¨eÓ4ØØ ñ.
ˆÔð
 $(ˆŒØˆŒØ8<ˆÕr   c              ƒ  ó’  K  — | j                   rt        d«      ‚| j                  j                  «       ƒ d {  –—†  	  | j                  j                  j
                  di | j                  ¤Žƒ d {  –—† }|d   | _        | S 7 ŒI7 Œ# t        $ r6  | j                  j                  t        j                  «       Ž ƒ d {  –—†7   ‚ w xY w­w)Nz)_AsyncRemoteGraphRunStream already closedrd   r<   )r_   re   r   Ú
__aenter__rg   rh   r]   ri   Ú	__aexit__rk   rl   r^   rm   s     r   r´   z%_AsyncRemoteGraphRunStream.__aenter__  s§   è ø€ Ø�<Š<ÜÐJÓKÐKØ�i‰i×"Ñ"Ó$×$Ð$ð	Ø.˜4Ÿ9™9Ÿ=™=×.Ñ.ÑD°×1CÑ1CÑD×DˆFð ˜hÑ'ˆŒØˆð 	%øàDùÜò 	Ø%�$—)‘)×%Ñ%¤s§|¡|£~Ð6×6Ñ6Øð	üsD   ‚5C·B¸C½3B Á0BÁ1B Á5CÂB Â7CÂ<B?Â=CÃCc              ƒ  ó‚   K  — | j                   ry d| _         | j                  j                  |||«      ƒ d {  –—†  y 7 Œ­wrp   )r_   r   rµ   rq   s       r   rµ   z$_AsyncRemoteGraphRunStream.__aexit__  s5   è ø€ ð �<Š<ØØˆŒØ�i‰i×!Ñ! (¨C°Ó4×4Ò4ús   ‚5?·=¸?c              ƒ  óJ   K  — | j                   j                  ƒ d{  –—† S 7 Œ­w)aA  Drive the remote run to completion and return the final state.

        Awaits the SDK's terminal-state awaitable, matching local
        `AsyncGraphRunStream.output()` (a method, not a property, so
        `run.output` without `await` fails at type-check time rather than
        silently yielding a coroutine).
        Nrv   r.   s    r   rw   z!_AsyncRemoteGraphRunStream.output"  s   è ø€ ð —Y‘Y×%Ñ%×%Ð%Ð%ús   ‚#œ!�#c              ƒ  ó6   K  — | j                   j                  S ­w)aÔ  Whether the remote run is currently paused at an interrupt.

        Reads the SDK's current value without blocking. This differs from
        local `AsyncGraphRunStream.interrupted()`, which drives the run to
        terminal before returning the flag. Callers that need a
        wait-for-interrupt pattern should drain a projection (e.g.,
        `async for snap in stream._sdk.values`) until the SDK's paused
        sentinel fires, then call this method.
        ry   r.   s    r   rz   z&_AsyncRemoteGraphRunStream.interrupted,  s   è ø€ ð �y‰y×$Ñ$Ð$ùs   ‚c              ƒ  óH   K  — t        | j                  j                  «      S ­w)z¯Current outstanding interrupt payloads.

        Non-blocking; reads the SDK's current snapshot. See `interrupted`
        for the divergence from local v3 semantics.
        r|   r.   s    r   r~   z%_AsyncRemoteGraphRunStream.interrupts8  s   è ø€ ô �D—I‘I×(Ñ(Ó)Ð)ùs   ‚ "c                ó.   — | j                   j                  S r€   r�   r.   s    r   r?   z!_AsyncRemoteGraphRunStream.values@  r‚   r   c                ó.   — | j                   j                  S r„   r…   r.   s    r   r@   z#_AsyncRemoteGraphRunStream.messagesE  r†   r   c                ó.   — | j                   j                  S rˆ   r‰   r.   s    r   rB   z$_AsyncRemoteGraphRunStream.subgraphsJ  rŠ   r   c                ó.   — | j                   j                  S rŒ   r�   r.   s    r   rA   z%_AsyncRemoteGraphRunStream.tool_callsO  rŽ   r   c                ó,   — t        | j                  «      S r�   r‘   r.   s    r   rL   z%_AsyncRemoteGraphRunStream.extensionsX  r’   r   c              ƒ  óÐ  K  — | j                   ry d| _         | j                  �O	 | j                  j                  j	                  | j
                  j                  | j                  d¬«      ƒ d {  –—†  	 | j
                  j                  «       ƒ d {  –—†  y 7 Œ(# t        $ r t        j                  dd¬«       Y ŒHw xY w7 Œ-# t        $ r t        j                  dd¬«       Y y w xY w­wr”   r–   r.   s    r   rž   z _AsyncRemoteGraphRunStream.abort]  sÌ   è ø€ Ø�<Š<ØØˆŒØ�<‰<Ð#ðIØ—l‘l×'Ñ'×.Ñ.Ø—I‘I×'Ñ'¨¯©¸Eð /ó ÷ ð ð
	CØ—)‘)—/‘/Ó#×#Ñ#ðùô ò IÜ—‘Ð8À4�ÖHðIúð $ùÜò 	CÜ�L‰LÐ2¸TˆLÖBð	Cüsk   ‚!C&¤A	B Á-BÁ.B Á3C  ÂB>ÂC  ÂC&ÂB Â B;Â8C&Â:B;Â;C&Â>C  Ã  C#Ã C&Ã"C#Ã#C&c                ó„   — | j                   €)| j                  j                  j                  «       | _         | j                   S r   )r±   r   r)   r/   r.   s    r   r/   z$_AsyncRemoteGraphRunStream.__aiter__m  s5   € Ø×ÑÐ%Ø!%§¡×!1Ñ!1×!;Ñ!;Ó!=ˆDÔØ×!Ñ!Ð!r   N)r²   r   rb   r   r   r   rZ   r¤   r[   r¥   r4   r5   )r4   r¯   r¦   r§   r¨   rª   r«   r¬   r7   )r8   r9   r:   r;   r$   r´   rµ   rw   rz   r~   r­   r?   r@   rB   rA   rL   rž   r/   r<   r   r   r¯   r¯   ô   sô   „ ÙJð=ð  ð=ð &ð	=ð
 ð=ð &ð=ð (ð=ð 
ó=ó(
ð	5à,ð	5ð "ð	5ð !ð		5ð
 
ó	5ó&ó
%ó*ð ò ó ð ð ò"ó ð"ð ò#ó ð#ð ò$ó ð$ð ò.ó ð.óCô "r   r¯   )r   r   r4   r   )#Ú
__future__r   Úloggingrk   Úcollections.abcr   r   r   Útypesr   Útypingr   r	   Úlangchain_core.runnablesr
   Úlanggraph_sdk._async.streamr   Úlanggraph_sdk._sync.streamr   Úlanggraph_sdk.clientr   r   Úlanggraph_sdk.stream.decodersr   Úlanggraph.typesr   Ú	getLoggerr8   r›   r   r   r3   r>   rW   r¯   r<   r   r   Ú<module>rÍ      s   ðå "ã Û 
ß <Ñ <Ý ß å 3Ý 9Ý 7ß EÝ 5å #à	ˆ×	Ñ	˜8Ó	$€ó÷.!ñ !ôH+!˜' # s (Ñ+ô +!÷\sAñ sA÷l|"ò |"r   