+
    ^eòj  ã                   ód  € R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ]'       d   ^ RIHt R R lt ! R R4      t]! 4       sR R lt]! ]R4      '       d   ]P>                  ! ]]]R7       R R lt R R lt!R R lt"R R lt#. ROt$R# )a]  Global event subscriber registration.

Subscribers observe all lifecycle events emitted by the current process,
including scope, tool, LLM, and mark events. They are typically used for
logging, metrics, tracing, and custom observability pipelines.

Example::

    import nemo_relay

    def log_event(event):
        print(f"{event.kind}: {event.name}")

    nemo_relay.subscribers.register("logger", log_event)
    try:
        with nemo_relay.scope.scope("demo", nemo_relay.ScopeType.Agent):
            nemo_relay.scope.event("started")
    finally:
        nemo_relay.subscribers.deregister("logger")
N)ÚCallable)ÚTYPE_CHECKING)Úcallback_active)Úderegister_subscriber)Úflush_subscribers)Úregister_subscriber)Ú&subscriber_dispatcher_after_fork_child)Ú'subscriber_dispatcher_after_fork_parent)Ú!subscriber_dispatcher_before_fork)ÚEventc                ód   € V ^8„  d   QhR\         P                  R,          R\        R,          RR/# )é   Ú	completedNÚerrorÚreturn)ÚasyncioÚFutureÚBaseException)Úformats   "Ú�/opt/data/installs/351f81cc06284494/environments/aa258815729c481f8402f54f4c368f83/venv/lib/python3.14/site-packages/nemo_relay/subscribers.pyÚ__annotate__r   7   s0   € ÷ 'ñ 'œWŸ^™^¨DÕ1ð '¼-È$Õ:Nð 'ÐSWñ 'ó    c                 ó†   € V P                  4       '       d   R # Vf   V P                  R 4       R # V P                  V4       R # ©N)ÚdoneÚ
set_resultÚset_exception)r   r   s   &&r   Ú_finish_flushr   7   s3   € Ø‡~�~×ÒÙØ‚}Ø×Ñ˜TÖ"à×Ñ Ö&r   c                   ól   a € ] tR t^@t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltR
t	V t
R# )Ú_FlushBridgezACoalesce asynchronous flush barriers onto one native-wait thread.c                ó   <€ V ^8„  d   QhRR/# ©r   r   N© )r   Ú__classdict__s   "€r   r   Ú_FlushBridge.__annotate__C   s   ø€ ÷ 5ñ 5˜$ñ 5r   c                ó˜   € \         P                  ! 4       V n        \         P                  ! 4       V n        / V n        ^ V n        RV n        R# )é    N)Ú	threadingÚLockÚ_lockr   Ú_wakeÚ_pendingÚ_next_tokenÚ_thread)Úselfs   &r   Ú__init__Ú_FlushBridge.__init__C   s4   € Ü—^’^Ó%ˆŒ
Ü—_’_Ó&ˆŒ
Ø[]ˆŒØˆÔØ04ˆŽr   c                ó`   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RR/# )r   Úloopr   Nr   )r   ÚAbstractEventLoopr   )r   r#   s   "€r   r   r$   J   s8   ø€ ÷ $ñ $á×'Ñ'ð$ñ —>‘> $Õ'ð$ð 
ñ	$r   c                óè  a a€ R pS P                   ;_uu_ 4        S P                  oS ;P                  ^,          un        W3S P                  S&   S P                  f5   \        P
                  ! S P                  RRR7      S n        S P                  pS P                  P                  4        R R R 4       VP                  V V3R l4       Ve   VP                  4        R # R #   + '       g   i     L>; i)Nznemo-relay-flushT)ÚtargetÚnameÚdaemonc                 ó&   <€ SP                  S4      # r   )Ú_discard)Ú_futurer.   Útokens   &€€r   Ú<lambda>Ú%_FlushBridge.submit.<locals>.<lambda>\   s   ø€ °D·M±MÀ%Ô4Hr   )r)   r,   r+   r-   r'   ÚThreadÚ_runr*   ÚsetÚadd_done_callbackÚstart)r.   r2   r   Úthread_to_startr;   s   f&& @r   ÚsubmitÚ_FlushBridge.submitJ   s·   ù€ ð
 48ˆØ�Z�Z‹ZØ×$Ñ$ˆEØ×Ò Õ!ÕØ$(Ð#4ˆD�M‰M˜%Ñ Ø�|‰|Ò#Ü(×/Ò/ØŸ9™9Ø+Øô �”ð
 #'§,¡,�Ø�J‰J�N‰NÔ÷ ð 	×#Ñ#Õ$HÔIØÒ&Ø×!Ñ!Ö#ñ '÷ �Zús   ™BC!Ã!C1	c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   r;   r   N)Úint)r   r#   s   "€r   r   r$   `   s   ø€ ÷ +ñ +™cð + dñ +r   c                ó    € V P                   ;_uu_ 4        V P                  P                  VR 4       R R R 4       R #   + '       g   i     R # ; ir   )r)   r+   Úpop)r.   r;   s   &&r   r9   Ú_FlushBridge._discard`   s+   € Ø�Z�Z‹ZØ�M‰M×Ñ˜e TÔ*÷ �Z�ZŠZús	   •<¼A	c                ó   <€ V ^8„  d   QhRR/# r!   r"   )r   r#   s   "€r   r   r$   d   s   ø€ ÷ ñ �dñ r   c                ó  €  V P                   P                  4        V P                  ;_uu_ 4        \        V P                  P                  4       4      pV P                  P                  4        V P                   P                  4        RRR4       X'       g   K™   \        4        RpV F  w  rE VP                  \        WR4       K  	  KÊ    + '       g   i     LK; i  \         d   pTp Rp?LIRp?ii ; i  \         d     K]  i ; i)TN)r*   Úwaitr)   Úlistr+   ÚvaluesÚclearÚ_native_flushr   Úcall_soon_threadsafer   ÚRuntimeError)r.   ÚbatchÚresultr   r2   r   s   &     r   r?   Ú_FlushBridge._rund   sÃ   € ØØ�J‰J�O‰OÔØ——“Ü˜TŸ]™]×1Ñ1Ó3Ó4�Ø—‘×#Ñ#Ô%Ø—
‘
× Ñ Ô"÷ ÷ ÙðÜ”ð �Û#(‘�ðØ×-Ñ-¬m¸YÖOó $)÷ —ûô !ô Ø•ûðûô $ô Úðús6   °ACÂ
C Â/C8ÃC	ÃC5Ã)C0Ã0C5Ã8DÄD)r)   r,   r+   r-   r*   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r/   rD   r9   r?   Ú__static_attributes__Ú__classdictcell__)r#   s   @r   r   r   @   s0   ø‡ € ÙK÷5ð 5÷$ð $÷,+ð +÷ö r   r   c                ó   € V ^8„  d   QhRR/# r!   r"   )r   s   "r   r   r   }   s   € ÷ #ñ #˜4ñ #r   c                  ó.   € \        4        \        4       sR # r   )Ú_native_after_fork_childr   Ú_flush_bridger"   r   r   Ú_after_fork_childrb   }   s   € äÔô !“N‚Mr   Úregister_at_fork)ÚbeforeÚafter_in_parentÚafter_in_childc                ó,   € V ^8„  d   QhR\         RRRR/# )r   r6   ÚcallbackzCallable[[Event], None]r   N)Ústr)r   s   "r   r   r   �   s"   € ÷ ,ñ ,”3ð ,Ð";ð ,Àñ ,r   c                ó   € \        W4      # )a½  Register a global event subscriber.

Args:
    name: Unique subscriber name.
    callback: Callable invoked as ``callback(event)`` for every emitted
        lifecycle event.

Returns:
    None: This function returns after the subscriber is registered.

Raises:
    RuntimeError: If a subscriber with the same name already exists.

Example::

    import nemo_relay

    nemo_relay.subscribers.register("printer", lambda event: print(event.kind))
)Ú_native_register)r6   rh   s   &&r   Úregisterrl   �   s   € ô( ˜DÓ+Ð+r   c                ó0   € V ^8„  d   QhR\         R\        /# )r   r6   r   )ri   Úbool)r   s   "r   r   r   ¤   s   € ÷ $ñ $”Sð $œTñ $r   c                ó   € \        V 4      # )a>  Remove a previously registered global subscriber.

Args:
    name: Subscriber name passed to ``register()``.

Returns:
    ``True`` if a subscriber was removed, otherwise ``False``.

Notes:
    Deregistering a subscriber affects only future event delivery. Events
    already emitted before removal carry a subscriber snapshot, so queued
    callbacks from that snapshot may still run.

Example::

    import nemo_relay

    nemo_relay.subscribers.register("printer", lambda event: None)
    removed = nemo_relay.subscribers.deregister("printer")
    assert removed is True
)Ú_native_deregister)r6   s   &r   Ú
deregisterrq   ¤   s   € ô, ˜dÓ#Ð#r   c                ó   € V ^8„  d   QhRR/# r!   r"   )r   s   "r   r   r   ½   s   € ÷  ñ  ˆtñ  r   c                 óœ   € \        4       '       d   R#  \        P                  ! 4        \        R4      h  \         d     \	        4       # i ; i)a‰  Wait for queued callbacks and registered managed terminal publications.

Native NeMo Relay event APIs enqueue subscriber callbacks and return without
waiting for observer work. Use this barrier in tests and shutdown paths when
captured subscriber output must be complete before continuing. The barrier
also waits for tool, LLM, and guardrail-scope terminal events from managed
work that started before the flush.

Call this function outside subscribers, event sanitizers, conditional
guardrails, and request or execution intercepts. A queued tool or LLM
observability sanitizer may call it, but the call returns without waiting
for its own publication. From an ``asyncio`` task, await
:func:`flush_async` instead.

Raises:
    RuntimeError: If called while an ``asyncio`` event loop is running on
        the current thread.

Returns:
    None: All eligible queued work has completed before this returns.
Nzdsubscribers.flush() cannot block a running asyncio event loop; use 'await subscribers.flush_async()')Ú_publication_callback_activer   Úget_running_looprS   rQ   r"   r   r   Úflushrv   ½   sQ   € ô, $×%Ò%Ùð
Ü× Ò Ô"ô Øró
ð 	
øô ô Øô
 ‹?Ððús   ”4 ´AÁ
Ac                ó   € V ^8„  d   QhRR/# r!   r"   )r   s   "r   r   r   à   s   € ÷ ñ ˜4ñ r   c               ƒ  ó¾   "  € \        4       '       d   R# \        P                  ! 4       p V P                  4       p\        P                  W4       VG Rj  x€L
  R#  L5i)aÇ  Wait asynchronously for queued callbacks and managed terminal events.

Use this barrier from an ``asyncio`` task. A process-local daemon bridge
thread coalesces concurrent barriers and waits for the native dispatcher
without blocking the Python event loop. Managed tool, LLM, and guardrail
work registered before the flush is included through its terminal event.

Returns:
    None: All eligible queued work has completed when the awaitable
    resolves.
N)rt   r   ru   Úcreate_futurera   rD   )r2   r   s     r   Úflush_asyncrz   à   sD   é € ô $×%Ò%ÙÜ×#Ò#Ó%€DØ&*×&8Ñ&8Ó&:€IÜ×Ñ˜Ô)Ø
‡O„Oùs   ‚AAÁAÁA)rq   rv   rz   rl   )%r[   r   Úosr'   Úcollections.abcr   Útypingr   Ú#nemo_relay._event_sanitizer_contextr   rt   Únemo_relay._nativer   rp   r   rQ   r   rk   r   r`   r	   Ú_native_after_fork_parentr
   Ú_native_before_forkÚ
nemo_relayr   r   r   ra   rb   Úhasattrrc   rl   rq   rv   rz   Ú__all__r"   r   r   Ú<module>r…      s¥   ðñó* Û 	Û Ý $Ý  å _õõõõõõ÷ Ý õ'÷7ñ 7ñt “€õ#ñ ˆ2Ð!×"Ò"Ø×ÒØ"Ø1Ø(õõ,õ.$õ2 õFò( =‚r   