ó
    üÞ jê  ã                  óè   • S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
Jr  SSKJr  SSKJr  S	S
KJrJrJr  \R(                  " \5      r/ SQr\SSSSS\S.               SS jj5       rg)z)LangSmith integration for LiveKit Agents.é    )ÚannotationsN)ÚCallable)ÚPath)ÚAnyÚOptional)Ú	warn_beta)Úset_thread_idé   )Ú!DEFAULT_RECORDING_TIMEOUT_SECONDSÚLiveKitLangSmithSpanProcessorÚRecordingMode)r   r   Úconfigure_livekitr	   Úsession_report)Úapi_keyÚprojectÚendpointÚaudio_path_providerÚrecording_modeÚrecording_timeout_secondsc           	     óV  • Ub  [         R                  " S[        SS9   SSKJn  SSKJn  SSKJn	  [        SU UUUUS
.UD6nU" 5       nUR                  U5        U	R                  U5        UR                  U5        U$ ! [         a   n
[        R                  S	U
5         Sn
A
gSn
A
ff = f)u&  Enable LangSmith tracing for a LiveKit Agents worker.

Builds a ``TracerProvider`` with a :class:`LiveKitLangSmithSpanProcessor`
(which rewrites LiveKit's ``lk.*`` spans for LangSmith and exports them to
LangSmith's OTLP endpoint) and registers it as both LiveKit's tracer provider
and the OTel global. Call before starting the worker.

To manage your own ``TracerProvider`` instead, skip this function: construct
:class:`LiveKitLangSmithSpanProcessor` directly, add it to your provider, and
register that provider with LiveKit via
``livekit.agents.telemetry.set_tracer_provider(...)`` â€” LiveKit only emits
spans through the provider its tracer is bound to.

To group a conversation's spans into a LangSmith thread, call
:func:`set_thread_id` once per conversation (inside that conversation's
asyncio task). The processor captures it as the conversation's spans start
and applies it to every span in the trace â€” so it holds even for spans
finished on a background task, and concurrent conversations stay separated.

For a realtime (speech-to-speech) model, also call
:meth:`LiveKitLangSmithSpanProcessor.instrument_session` on the returned
processor: the user transcript arrives as a session event rather than on a
span, so without it the trace shows only the agent's turns.

Each conversation's root span is held until its session report arrives. The
processor registers an additive ``AgentSession`` close listener and captures
that report automatically; no ``on_session_end`` callback is required. In
``session_report`` mode the report's recording is attached with its chat
history.

With LiveKit Egress (or your own capture), configure
``recording_mode="egress"`` and deliver each conversation's audio when it is
available::

    processor.complete_recording(
        thread_id,
        audio_bytes,
        started_at=egress_started_at,
    )

Existing code may instead call ``processor.expect_recording(thread_id)`` at
conversation start. That marks only that conversation as egress, even when
the processor's default mode is ``session_report`` or ``none``. It may be
called before the conversation's spans start. The automatic report and
recording may arrive in either order; an egress root is released after both,
or after ``recording_timeout_seconds`` as failure protection. Use
``recording_mode="none"`` to attach report data without audio.

Args:
    api_key / project / endpoint: LangSmith exporter config; default to the
        standard ``LANGSMITH_*`` resolution.
    audio_path_provider: Deprecated compatibility parameter. It is ignored.
    recording_mode: ``"session_report"``, ``"egress"``, or ``"none"``.
    recording_timeout_seconds: how long the root waits for required session
        data before it is exported with whatever is available.

Returns:
    The processor, or ``None`` if LiveKit / OpenTelemetry aren't installed.
Nz.audio_path_provider is deprecated and ignored.é   )Ú
stacklevelr   )Útrace)ÚTracerProvider)Ú	telemetryz*Missing dependency for LiveKit tracing: %s)r   r   r   r   r   © )ÚwarningsÚwarnÚDeprecationWarningÚopentelemetryr   Úopentelemetry.sdk.tracer   Úlivekit.agentsr   ÚImportErrorÚloggerÚwarningr   Úadd_span_processorÚset_tracer_provider)r   r   r   r   r   r   ÚkwargsÚ
otel_tracer   r   ÚeÚ	processorÚproviders                Úa/var/www/html/gaurav/venv/lib/python3.13/site-packages/langsmith/integrations/livekit/__init__.pyr   r      s¶   € ðL Ñ&Ü�ŠØ<ÜØò	
ðÝ5Ý:å,ô
 .ð ØØØØ%Ø";ñð ñ€Iñ Ó€HØ×Ñ 	Ô*Ø×!Ñ! (Ô+Ø×"Ñ" 8Ô,ØÐøô! ó Ü�‰ÐCÀQÔGÜûðús   ŸA> Á>
B(ÂB#Â#B()r   úOptional[str]r   r.   r   r.   r   z&Optional[Callable[[], Optional[Path]]]r   r   r   Úfloatr(   r   Úreturnz'Optional[LiveKitLangSmithSpanProcessor])Ú__doc__Ú
__future__r   Úloggingr   Úcollections.abcr   Úpathlibr   Útypingr   r   Ú#langsmith._internal._beta_decoratorr   Úlangsmith._internal.voicer	   r+   r   r   r   Ú	getLoggerÚ__name__r$   Ú__all__r   r   ó    r-   Ú<module>r=      sÄ   ðÙ /å "ã Û Ý $Ý ß  å 9Ý 3÷ñ ð 
×	Ò	˜8Ó	$€ò€ð ð "Ø!Ø"ØBFØ$4Ø'Hñaàðað ðað ð	að
 @ðað "ðað  %ðað ðað -ôaó ñar<   