+
    ^eòj1  ã                   ó  € R t ^ RIHtHtHtHt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 ^ R
IHt ^ RIHt R R ltR R ltR R ltR R ltR R lt R R lt!R R lt"R R lt#R R lt$R R lt%. R!Ot&R # )"aR  Global middleware intercept registration for tools and LLMs.

Request intercepts transform inputs before execution. Execution intercepts wrap
the downstream callable and can observe, modify, or replace the result.

Example::

    import nemo_relay

    def add_header(
        name: str,
        request: nemo_relay.LLMRequest,
        annotated: nemo_relay.AnnotatedLLMRequest | None
    ) -> nemo_relay.LLMRequestInterceptOutcome:
        # The request object is immutable, however we can return a new instance with updated headers.
        headers = request.headers.copy()
        headers["X-Trace"] = "demo"
        return nemo_relay.LLMRequestInterceptOutcome(
            nemo_relay.LLMRequest(headers=headers, content=request.content), annotated
        )

    nemo_relay.intercepts.register_llm_request("trace-header", 10, False, add_header)
)ÚLlmExecutionInterceptÚLlmRequestInterceptÚLlmStreamExecutionInterceptÚToolExecutionInterceptÚToolRequestIntercept)Ú"deregister_llm_execution_intercept)Ú deregister_llm_request_intercept)Ú)deregister_llm_stream_execution_intercept)Ú#deregister_tool_execution_intercept)Ú!deregister_tool_request_intercept)Ú register_llm_execution_intercept)Úregister_llm_request_intercept)Ú'register_llm_stream_execution_intercept)Ú!register_tool_execution_intercept)Úregister_tool_request_interceptc          
      óL   € V ^8„  d   QhR\         R\        R\        R\        RR/# ©é   ÚnameÚpriorityÚbreak_chainÚfnÚreturnN)ÚstrÚintÚboolr   )Úformats   "ÚŒ/opt/data/installs/351f81cc06284494/environments/aa258815729c481f8402f54f4c368f83/venv/lib/python3.14/site-packages/nemo_relay/intercepts.pyÚ__annotate__r   G   s8   € ÷  Jñ  J¤ð  J¬sð  JÄð  JÔK_ð  JÐdhñ  Jó    c                ó   € \        WW#4      # )aƒ  Register an intercept that rewrites tool arguments before execution.

Args:
    name: Unique intercept name used for later replacement or removal.
    priority: Execution order for the intercept. Lower values run first.
    break_chain: Whether to stop applying lower-priority request intercepts
        after this intercept runs.
    fn: Callable invoked as ``fn(tool_name, args)`` that returns the
        rewritten tool arguments.

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

Notes:
    Request intercepts run after conditional-execution guardrails and
    before sanitize-request guardrails or execution intercepts.

Example::

    import nemo_relay

    def add_trace_id(tool_name, args):
        return {**args, "trace_id": "req-123"}

    nemo_relay.intercepts.register_tool_request(
        "trace-id",
        10,
        False,
        add_trace_id,
    )
)Ú_native_register_tool_request©r   r   r   r   s   &&&&r   Úregister_tool_requestr#   G   s   € ô@ )¨¸ÓIÐIr   c                ó0   € V ^8„  d   QhR\         R\        /# ©r   r   r   ©r   r   )r   s   "r   r   r   j   s   € ÷ 1ñ 1¤#ð 1¬$ñ 1r   c                ó   € \        V 4      # )aZ  Remove a previously registered tool request intercept.

Args:
    name: Intercept name previously passed to ``register_tool_request()``.

Returns:
    bool: ``True`` if an intercept was removed, otherwise ``False``.

Notes:
    Removal affects only future executions. In-flight calls continue using
    the intercept chain they already resolved.
)Ú_native_deregister_tool_request©r   s   &r   Úderegister_tool_requestr*   j   s   € ô +¨4Ó0Ð0r   c                ó@   € V ^8„  d   QhR\         R\        R\        RR/# ©r   r   r   r   r   N)r   r   r   )r   s   "r   r   r   z   s*   € ÷ ?ñ ?¤#ð ?´ð ?Ô:Pð ?ÐUYñ ?r   c                ó   € \        WV4      # )aØ  Register middleware around tool execution.

Args:
    name: Unique intercept name used for later replacement or removal.
    priority: Execution order for the intercept. Lower values run first.
    fn: Callable invoked as ``fn(context, next_call)``. The context exposes
        ``tool_name``, ``args``, and ``tool_call_id``. The callback may
        await or call ``next_call(context.args)`` to continue the
        chain, modify the result, or bypass downstream execution entirely.
        It must return ``ToolExecutionInterceptOutcome``.

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

Notes:
    Execution intercepts wrap the downstream tool callback. They are the
    right place for timing, retries, short-circuiting, or result shaping.
    ``next_call`` may be awaited repeatedly or concurrently while ``fn``
    is running. Each call gets an isolated scope-stack branch. Unfinished
    or new calls are rejected after ``fn`` returns or raises.

    ``tool_call_id`` is the provider-issued identifier recorded on the
    managed tool call, letting an intercept that completes execution
    itself associate its result with the originating call. It is ``None``
    when the tool call did not record one.
)Ú_native_register_tool_execution©r   r   r   s   &&&r   Úregister_tool_executionr0   z   s   € ô6 +¨4¸2Ó>Ð>r   c                ó0   € V ^8„  d   QhR\         R\        /# r%   r&   )r   s   "r   r   r   ˜   s   € ÷ 3ñ 3¤Cð 3¬Dñ 3r   c                ó   € \        V 4      # )af  Remove a previously registered tool execution intercept.

Args:
    name: Intercept name previously passed to
        ``register_tool_execution()``.

Returns:
    bool: ``True`` if an intercept was removed, otherwise ``False``.

Notes:
    Removal affects only future executions. In-flight calls continue using
    the execution chain they already resolved.
)Ú!_native_deregister_tool_executionr)   s   &r   Úderegister_tool_executionr4   ˜   s   € ô -¨TÓ2Ð2r   c          
      óL   € V ^8„  d   QhR\         R\        R\        R\        RR/# r   )r   r   r   r   )r   s   "r   r   r   ®   s8   € ÷ )Iñ )Iœsð )I¬cð )IÄð )IÔJ]ð )IÐbfñ )Ir   c                ó   € \        WW#4      # )aC  Register an intercept that rewrites an ``LLMRequest`` before execution.

Args:
    name: Unique intercept name used for later replacement or removal.
    priority: Execution order for the intercept. Lower values run first.
    break_chain: Whether to stop applying lower-priority request intercepts
        after this intercept runs.
    fn: Callable invoked as ``fn(name, request, annotated)`` that returns an
        ``nemo_relay.LLMRequestInterceptOutcome`` for the next intercept or
        the provider callback.

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

Notes:
    ``annotated`` is ``None`` unless a request codec was supplied to the
    managed LLM call. Intercepts should preserve both values when they do
    not need to mutate them.

Example::

    import nemo_relay

    def add_header(
        name: str, request: nemo_relay.LLMRequest,
        annotated: nemo_relay.AnnotatedLLMRequest | None
    ) -> nemo_relay.LLMRequestInterceptOutcome:
        headers = request.headers.copy()
        headers["X-Trace"] = "req-123"
        return nemo_relay.LLMRequestInterceptOutcome(
            nemo_relay.LLMRequest(headers=headers, content=request.content), annotated
        )

    nemo_relay.intercepts.register_llm_request(
        "trace-header",
        10,
        False,
        add_header,
    )
)Ú_native_register_llm_requestr"   s   &&&&r   Úregister_llm_requestr8   ®   s   € ôR (¨¸ÓHÐHr   c                ó0   € V ^8„  d   QhR\         R\        /# r%   r&   )r   s   "r   r   r   Ú   s   € ÷ 0ñ 0¤ð 0¬ñ 0r   c                ó   € \        V 4      # )aX  Remove a previously registered LLM request intercept.

Args:
    name: Intercept name previously passed to ``register_llm_request()``.

Returns:
    bool: ``True`` if an intercept was removed, otherwise ``False``.

Notes:
    Removal affects only future executions. In-flight calls continue using
    the intercept chain they already resolved.
)Ú_native_deregister_llm_requestr)   s   &r   Úderegister_llm_requestr<   Ú   s   € ô *¨$Ó/Ð/r   c                ó@   € V ^8„  d   QhR\         R\        R\        RR/# r,   )r   r   r   )r   s   "r   r   r   ê   s*   € ÷ >ñ >¤ð >´ð >Ô9Nð >ÐSWñ >r   c                ó   € \        WV4      # )a–  Register middleware around non-streaming LLM execution.

Args:
    name: Unique intercept name used for later replacement or removal.
    priority: Execution order for the intercept. Lower values run first.
    fn: Callable invoked as ``fn(name, request, context, next_call)``. The
        context exposes the active request and unary-response codecs. The
        callback may call ``next_call(request)`` to continue execution,
        modify the result, or short-circuit the provider call.

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

Notes:
    Execution intercepts wrap only non-streaming LLM execution. Use
    ``register_llm_stream_execution()`` for streaming callbacks.
    ``next_call`` may be awaited repeatedly or concurrently while ``fn``
    is running. Each call gets an isolated scope-stack branch. Unfinished
    or new calls are rejected after ``fn`` returns or raises.
)Ú_native_register_llm_executionr/   s   &&&r   Úregister_llm_executionr@   ê   s   € ô* *¨$¸"Ó=Ð=r   c                ó0   € V ^8„  d   QhR\         R\        /# r%   r&   )r   s   "r   r   r     s   € ÷ 2ñ 2¤3ð 2¬4ñ 2r   c                ó   € \        V 4      # )ad  Remove a previously registered LLM execution intercept.

Args:
    name: Intercept name previously passed to
        ``register_llm_execution()``.

Returns:
    bool: ``True`` if an intercept was removed, otherwise ``False``.

Notes:
    Removal affects only future executions. In-flight calls continue using
    the execution chain they already resolved.
)Ú _native_deregister_llm_executionr)   s   &r   Úderegister_llm_executionrD     s   € ô ,¨DÓ1Ð1r   c                ó@   € V ^8„  d   QhR\         R\        R\        RR/# r,   )r   r   r   )r   s   "r   r   r     s6   € ÷ Eñ EÜ
ðEäðEô 	$ðEð 
ñ	Er   c                ó   € \        WV4      # )a‰  Register middleware around streaming LLM execution.

Args:
    name: Unique intercept name used for later replacement or removal.
    priority: Execution order for the intercept. Lower values run first.
    fn: Callable invoked as ``fn(name, request, context, next_call)`` that
        returns an async iterator of JSON chunks. The streaming context
        exposes the request codec and no response codec. The callback may
        delegate to ``next_call(request)`` or replace the stream entirely.

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

Notes:
    Streaming execution intercepts wrap chunk production only. They do not
    replace the separate collector or finalizer callbacks.
    ``next_call`` may be awaited repeatedly or concurrently while ``fn``
    is running. Each call gets an isolated scope-stack branch. Unfinished
    or new calls are rejected after the intercept's returned stream closes
    or ``fn`` raises. A returned interceptor stream extends the active
    lifetime so it can call ``next_call`` lazily while being consumed; a
    stream returned successfully by ``next_call`` keeps its normal lifetime.
)Ú%_native_register_llm_stream_executionr/   s   &&&r   Úregister_llm_stream_executionrH     s   € ô8 1°ÀÓDÐDr   c                ó0   € V ^8„  d   QhR\         R\        /# r%   r&   )r   s   "r   r   r   2  s   € ÷ 9ñ 9¬#ð 9´$ñ 9r   c                ó   € \        V 4      # )aw  Remove a previously registered streaming LLM execution intercept.

Args:
    name: Intercept name previously passed to
        ``register_llm_stream_execution()``.

Returns:
    bool: ``True`` if an intercept was removed, otherwise ``False``.

Notes:
    Removal affects only future executions. In-flight streams continue
    using the execution chain they already resolved.
)Ú'_native_deregister_llm_stream_executionr)   s   &r   Úderegister_llm_stream_executionrL   2  s   € ô 3°4Ó8Ð8r   N)r   r   r   r   r   r#   r*   r0   r4   r8   r<   r@   rD   rH   rL   )'Ú__doc__Ú
nemo_relayr   r   r   r   r   Únemo_relay._nativer   rC   r   r;   r	   rK   r
   r3   r   r(   r   r?   r   r7   r   rG   r   r.   r   r!   r#   r*   r0   r4   r8   r<   r@   rD   rH   rL   Ú__all__© r   r   Ú<module>rR      s„   ðñ÷0õ õõõõõõõõõõõ JõF1õ ?õ<3õ,)IõX0õ >õ02õ"Eõ>9ò"‚r   