+
    ^eòj_  ã                   ó²   € R t ^ RIHtHtHt ^ RIHt ^ RIHtH	t	H
t
HtHtHtHt ]'       d   ^ RIHt ] ! R R]4      4       t] ! R R]4      4       t. R
OtR	# )aT  Protocol definitions for request and response codecs used by ``nemo_relay.llm``.

``LlmCodec`` is used for request-side translation. It lets intercepts work
against ``AnnotatedLLMRequest`` instead of provider-specific raw payloads.

``LlmResponseCodec`` is used for response-side translation. It lets NeMo Relay attach
an ``AnnotatedLLMResponse`` to emitted ``LLMEnd`` events without changing the
return value of ``llm.execute()`` or ``llm.stream_execute()``.

Example::

    from nemo_relay import AnnotatedLLMRequest, LLMRequest, llm
    from nemo_relay.codecs import LlmCodec, OpenAIChatCodec

    class DemoCodec(LlmCodec):
        def decode(self, request: LLMRequest) -> AnnotatedLLMRequest:
            return AnnotatedLLMRequest(
                request.content.get("messages", []),
                model=request.content.get("model"),
            )

        def encode(self, annotated: AnnotatedLLMRequest, original: LLMRequest) -> LLMRequest:
            content = {**original.content, "messages": annotated.messages}
            if annotated.model is not None:
                content["model"] = annotated.model
            return LLMRequest(original.headers, content)

    async def impl(request: LLMRequest):
        return {"id": "r1", "choices": [{"message": {"role": "assistant", "content": "hi"}}]}

    # Request-side codec for intercepts, response-side codec for event annotation.
    result = await llm.execute(
        "demo-model",
        LLMRequest({}, {"messages": [{"role": "user", "content": "hello"}]}),
        impl,
        codec=DemoCodec(),
        response_codec=OpenAIChatCodec(),
    )
)ÚTYPE_CHECKINGÚProtocolÚruntime_checkable©ÚJson)ÚAnnotatedLLMRequestÚAnthropicMessagesCodecÚGeminiGenerateContentCodecÚ
LLMRequestÚOCIGenAIChatCodecÚOpenAIChatCodecÚOpenAIResponsesCodec)ÚAnnotatedLLMResponsec                   óH   a € ] tR t^=t o RtV 3R lR ltV 3R lR ltRtV tR# )ÚLlmCodeca2  Protocol for request codecs used by annotated LLM intercepts.

``decode()`` converts a provider-specific ``LLMRequest`` into an
``AnnotatedLLMRequest`` so request intercepts can work with a normalized
structure. ``encode()`` merges any annotated edits back into the original
raw payload before the provider callback is invoked.

Notes:
    ``encode()`` should preserve unknown provider-specific fields whenever
    possible instead of rebuilding the payload from scratch. That keeps
    transport-specific settings intact even when an intercept edits the
    normalized representation.

Example::

    from nemo_relay import AnnotatedLLMRequest, LLMRequest
    from nemo_relay.codecs import LlmCodec

    class DemoCodec(LlmCodec):
        def decode(self, request: LLMRequest) -> AnnotatedLLMRequest:
            return AnnotatedLLMRequest(
                request.content.get("messages", []),
                model=request.content.get("model"),
            )

        def encode(
            self,
            annotated: AnnotatedLLMRequest,
            original: LLMRequest,
        ) -> LLMRequest:
            content = {**original.content, "messages": annotated.messages}
            if annotated.model is not None:
                content["model"] = annotated.model
            return LLMRequest(original.headers, content)
c                ó&   <€ V ^8„  d   QhRS[ RS[/# )é   ÚrequestÚreturn)r
   r   )ÚformatÚ__classdict__s   "€Úˆ/opt/data/installs/351f81cc06284494/environments/aa258815729c481f8402f54f4c368f83/venv/lib/python3.14/site-packages/nemo_relay/codecs.pyÚ__annotate__ÚLlmCodec.__annotate__c   s   ø€ ÷ ñ ™jð Ñ-@ñ ó    c                ó   € R# )a/  Decode a raw provider request into ``AnnotatedLLMRequest``.

Args:
    request: The provider-specific request payload received by
        ``nemo_relay.llm.execute()`` or ``nemo_relay.llm.stream_execute()``.

Returns:
    AnnotatedLLMRequest: The normalized request consumed by annotated
    intercepts.
N© )Úselfr   s   &&r   ÚdecodeÚLlmCodec.decodec   ó   € ñ 	r   c                ó,   <€ V ^8„  d   QhRS[ RS[RS[/# )r   Ú	annotatedÚoriginalr   )r   r
   )r   r   s   "€r   r   r   p   s#   ø€ ÷ ñ Ñ 3ð ¹zð Éjñ r   c                ó   € R# )ar  Merge annotated edits back into the original raw request.

Args:
    annotated: The normalized request after intercepts have applied any
        edits.
    original: The original provider-specific request passed into the
        runtime before normalization.

Returns:
    LLMRequest: The provider-specific request that should be forwarded
    to the provider callback.
Nr   )r   r"   r#   s   &&&r   ÚencodeÚLlmCodec.encodep   s   € ñ 	r   r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r%   Ú__static_attributes__Ú__classdictcell__©r   s   @r   r   r   =   s   ø‡ € ñ"÷Hð ÷ö r   r   c                   ó6   a € ] tR t^€t o RtV 3R lR ltRtV tR# )ÚLlmResponseCodeca(  Protocol for codecs that normalize raw LLM responses.

A response codec is used only for observability. The value returned from
``llm.execute()`` or ``llm.stream_execute()`` stays unchanged; the decoded
response is attached to the emitted ``LLMEnd`` event as
``annotated_response``.

Example::

    import nemo_relay

    result = await nemo_relay.llm.execute(
        "demo-provider",
        nemo_relay.LLMRequest({}, {"messages": [{"role": "user", "content": "hi"}]}),
        impl,
        response_codec=nemo_relay.codecs.OpenAIChatCodec(),
    )
c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úresponser   r   r   )r   r   s   "€r   r   ÚLlmResponseCodec.__annotate__•   s   ø€ ÷ ñ ©ð Ð1Gñ r   c                ó   € R# )a  Decode a raw provider response into ``AnnotatedLLMResponse``.

Args:
    response: The raw JSON-compatible value returned by the provider
        callback.

Returns:
    AnnotatedLLMResponse: The normalized response attached to the
    ``LLMEnd`` event for downstream subscribers.
Nr   )r   r2   s   &&r   Údecode_responseÚ LlmResponseCodec.decode_response•   r    r   r   N)r'   r(   r)   r*   r+   r5   r,   r-   r.   s   @r   r0   r0   €   s   ø‡ € ñ÷&ö r   r0   N)r   r   r	   r   r0   r   r   r   )r+   Útypingr   r   r   Ú
nemo_relayr   Únemo_relay._nativer   r   r	   r
   r   r   r   r   r   r0   Ú__all__r   r   r   Ú<module>r;      sl   ðñ&÷P >Ñ =å ÷÷ ñ ÷ Ý7ð ô?ˆxó ?ó ð?ðD ô�xó ó ðòD	‚r   