§
    .çhÌF  ã                  ó²  — d dl mZ d dlmZmZ d dlmZmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZmZ dd	lmZ dd
lmZ erd dlmZ 	 	 	 	 dOdPd„ZdQd„ZdRd„Z	 	 	 	 	 	 dSdTd'„Z 	 	 	 	 	 dUdVd+„Z!	 	 	 	 	 	 	 	 dWdXd2„Z"	 	 	 	 dOdYd6„Z#	 	 	 	 	 dUdZd:„Z$	 	 	 	 dOd[d=„Z%	 	 	 	 d\d]d@„Z&	 	 	 	 	 	 	 	 d^d_dD„Z'	 	 	 	 	 	 	 	 	 d`dadH„Z(	 	 	 	 dOdbdJ„Z)	 	 	 	 	 dUdcdN„Z*dS )dé    )Úannotations)ÚMappingÚSequence)ÚTYPE_CHECKINGÚAnyé   )Úloggeré   )ÚGLOBAL_TRACE_PROVIDER)ÚAgentSpanDataÚCustomSpanDataÚFunctionSpanDataÚGenerationSpanDataÚGuardrailSpanDataÚHandoffSpanDataÚMCPListToolsSpanDataÚResponseSpanDataÚSpeechGroupSpanDataÚSpeechSpanDataÚTranscriptionSpanData)ÚSpan)ÚTrace)ÚResponseNFÚworkflow_nameÚstrÚtrace_idú
str | NoneÚgroup_idÚmetadataúdict[str, Any] | NoneÚdisabledÚboolÚreturnr   c                ó†   — t          j        ¦   «         }|rt          j        d¦  «         t          j        | ||||¬¦  «        S )a(  
    Create a new trace. The trace will not be started automatically; you should either use
    it as a context manager (`with trace(...):`) or call `trace.start()` + `trace.finish()`
    manually.

    In addition to the workflow name and optional grouping identifier, you can provide
    an arbitrary metadata dictionary to attach additional user-defined information to
    the trace.

    Args:
        workflow_name: The name of the logical app or workflow. For example, you might provide
            "code_bot" for a coding agent, or "customer_support_agent" for a customer support agent.
        trace_id: The ID of the trace. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_trace_id()` to generate a trace ID, to guarantee that IDs are
            correctly formatted.
        group_id: Optional grouping identifier to link multiple traces from the same conversation
            or process. For instance, you might use a chat thread ID.
        metadata: Optional dictionary of additional metadata to attach to the trace.
        disabled: If True, we will return a Trace but the Trace will not be recorded. This will
            not be checked if there's an existing trace and `even_if_trace_running` is True.

    Returns:
        The newly created trace object.
    zKTrace already exists. Creating a new trace, but this is probably a mistake.)Únamer   r   r   r!   )r   Úget_current_tracer	   ÚwarningÚcreate_trace)r   r   r   r   r!   Úcurrent_traces         úR/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/tracing/create.pyÚtracer+      s\   € õ> *Ô;Ñ=Ô=€MØð 
ÝŒØYñ	
ô 	
ð 	
õ !Ô-ØØØØØðñ ô ð ó    úTrace | Nonec                 ó(   — t          j        ¦   «         S )z/Returns the currently active trace, if present.)r   r&   © r,   r*   r&   r&   J   s   € å Ô2Ñ4Ô4Ð4r,   úSpan[Any] | Nonec                 ó(   — t          j        ¦   «         S )z.Returns the currently active span, if present.)r   Úget_current_spanr/   r,   r*   r2   r2   O   s   € å Ô1Ñ3Ô3Ð3r,   r%   Úhandoffsúlist[str] | NoneÚtoolsÚoutput_typeÚspan_idÚparentúTrace | Span[Any] | NoneúSpan[AgentSpanData]c                óT   — t          j        t          | |||¬¦  «        |||¬¦  «        S )a¶  Create a new agent span. The span will not be started automatically, you should either do
    `with agent_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        name: The name of the agent.
        handoffs: Optional list of agent names to which this agent could hand off control.
        tools: Optional list of tool names available to this agent.
        output_type: Optional name of the output type produced by the agent.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.

    Returns:
        The newly created agent span.
    )r%   r3   r5   r6   ©Ú	span_datar7   r8   r!   )r   Úcreate_spanr   )r%   r3   r5   r6   r7   r8   r!   s          r*   Ú
agent_spanr?   T   s<   € õ6 !Ô,Ý T°HÀEÐWbÐcÑcÔcØØØð	ñ ô ð r,   ÚinputÚoutputúSpan[FunctionSpanData]c                óR   — t          j        t          | ||¬¦  «        |||¬¦  «        S )a,  Create a new function span. The span will not be started automatically, you should either do
    `with function_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        name: The name of the function.
        input: The input to the function.
        output: The output of the function.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.

    Returns:
        The newly created function span.
    )r%   r@   rA   r<   )r   r>   r   )r%   r@   rA   r7   r8   r!   s         r*   Úfunction_spanrD   w   s9   € õ2 !Ô,Ý"¨°EÀ&ÐIÑIÔIØØØð	ñ ô ð r,   ú"Sequence[Mapping[str, Any]] | NoneÚmodelÚmodel_configúMapping[str, Any] | NoneÚusageúSpan[GenerationSpanData]c           	     óV   — t          j        t          | ||||¬¦  «        |||¬¦  «        S )a%  Create a new generation span. The span will not be started automatically, you should either
    do `with generation_span() ...` or call `span.start()` + `span.finish()` manually.

    This span captures the details of a model generation, including the
    input message sequence, any generated outputs, the model name and
    configuration, and usage data. If you only need to capture a model
    response identifier, use `response_span()` instead.

    Args:
        input: The sequence of input messages sent to the model.
        output: The sequence of output messages received from the model.
        model: The model identifier used for the generation.
        model_config: The model configuration (hyperparameters) used.
        usage: A dictionary of usage information (input tokens, output tokens, etc.).
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.

    Returns:
        The newly created generation span.
    )r@   rA   rF   rG   rI   r<   )r   r>   r   )r@   rA   rF   rG   rI   r7   r8   r!   s           r*   Úgeneration_spanrL   ˜   sK   € õD !Ô,Ý$ØØØØ%Øð
ñ 
ô 
ð ØØðñ ô ð r,   ÚresponseúResponse | NoneúSpan[ResponseSpanData]c                óN   — t          j        t          | ¬¦  «        |||¬¦  «        S )a¥  Create a new response span. The span will not be started automatically, you should either do
    `with response_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        response: The OpenAI Response object.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.
    )rM   r<   )r   r>   r   )rM   r7   r8   r!   s       r*   Úresponse_spanrQ   È   s5   € õ$ !Ô,Ý"¨HÐ5Ñ5Ô5ØØØð	ñ ô ð r,   Ú
from_agentÚto_agentúSpan[HandoffSpanData]c                óP   — t          j        t          | |¬¦  «        |||¬¦  «        S )a1  Create a new handoff span. The span will not be started automatically, you should either do
    `with handoff_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        from_agent: The name of the agent that is handing off.
        to_agent: The name of the agent that is receiving the handoff.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.

    Returns:
        The newly created handoff span.
    )rR   rS   r<   )r   r>   r   )rR   rS   r7   r8   r!   s        r*   Úhandoff_spanrV   â   s7   € õ. !Ô,Ý!¨ZÀ(ÐKÑKÔKØØØð	ñ ô ð r,   ÚdataúSpan[CustomSpanData]c                óT   — t          j        t          | |pi ¬¦  «        |||¬¦  «        S )aC  Create a new custom span, to which you can add your own metadata. The span will not be
    started automatically, you should either do `with custom_span() ...` or call
    `span.start()` + `span.finish()` manually.

    Args:
        name: The name of the custom span.
        data: Arbitrary structured data to associate with the span.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.

    Returns:
        The newly created custom span.
    )r%   rW   r<   )r   r>   r   )r%   rW   r7   r8   r!   s        r*   Úcustom_spanrZ     s;   € õ0 !Ô,Ý  d°°¸Ð<Ñ<Ô<ØØØð	ñ ô ð r,   Ú	triggeredúSpan[GuardrailSpanData]c                óP   — t          j        t          | |¬¦  «        |||¬¦  «        S )aÚ  Create a new guardrail span. The span will not be started automatically, you should either
    do `with guardrail_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        name: The name of the guardrail.
        triggered: Whether the guardrail was triggered.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.
    )r%   r[   r<   )r   r>   r   )r%   r[   r7   r8   r!   s        r*   Úguardrail_spanr^   !  s7   € õ( !Ô,Ý#¨¸ÐCÑCÔCØØØð	ñ ô ð r,   ÚpcmÚinput_formatúSpan[TranscriptionSpanData]c           	     óV   — t          j        t          |||| |¬¦  «        |||¬¦  «        S )aJ  Create a new transcription span. The span will not be started automatically, you should
    either do `with transcription_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        model: The name of the model used for the speech-to-text.
        input: The audio input of the speech-to-text transcription, as a base64 encoded string of
            audio bytes.
        input_format: The format of the audio input (defaults to "pcm").
        output: The output of the speech-to-text transcription.
        model_config: The model configuration (hyperparameters) used.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.

    Returns:
        The newly created speech-to-text span.
    )r@   r`   rA   rF   rG   r<   )r   r>   r   )rF   r@   r`   rA   rG   r7   r8   r!   s           r*   Útranscription_spanrc   =  sJ   € õ< !Ô,Ý'ØØ%ØØØ%ð
ñ 
ô 
ð ØØðñ ô ð r,   Úoutput_formatÚfirst_content_atúSpan[SpeechSpanData]c	           
     óX   — t          j        t          | |||||¬¦  «        |||¬¦  «        S )a)  Create a new speech span. The span will not be started automatically, you should either do
    `with speech_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        model: The name of the model used for the text-to-speech.
        input: The text input of the text-to-speech.
        output: The audio output of the text-to-speech as base64 encoded string of PCM audio bytes.
        output_format: The format of the audio output (defaults to "pcm").
        model_config: The model configuration (hyperparameters) used.
        first_content_at: The time of the first byte of the audio output.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.
    )rF   r@   rA   rd   rG   re   r<   )r   r>   r   )	rF   r@   rA   rd   rG   re   r7   r8   r!   s	            r*   Úspeech_spanrh   i  sM   € õ8 !Ô,Ý ØØØØ'Ø%Ø-ð
ñ 
ô 
ð ØØðñ ô ð r,   úSpan[SpeechGroupSpanData]c                óN   — t          j        t          | ¬¦  «        |||¬¦  «        S )aº  Create a new speech group span. The span will not be started automatically, you should
    either do `with speech_group_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        input: The input text used for the speech request.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.
    )r@   r<   )r   r>   r   )r@   r7   r8   r!   s       r*   Úspeech_group_spanrk   ”  s5   € õ$ !Ô,Ý%¨EÐ2Ñ2Ô2ØØØð	ñ ô ð r,   ÚserverÚresultúSpan[MCPListToolsSpanData]c                óP   — t          j        t          | |¬¦  «        |||¬¦  «        S )aá  Create a new MCP list tools span. The span will not be started automatically, you should
    either do `with mcp_tools_span() ...` or call `span.start()` + `span.finish()` manually.

    Args:
        server: The name of the MCP server.
        result: The result of the MCP list tools call.
        span_id: The ID of the span. Optional. If not provided, we will generate an ID. We
            recommend using `util.gen_span_id()` to generate a span ID, to guarantee that IDs are
            correctly formatted.
        parent: The parent span or trace. If not provided, we will automatically use the current
            trace/span as the parent.
        disabled: If True, we will return a Span but the Span will not be recorded.
    )rl   rm   r<   )r   r>   r   )rl   rm   r7   r8   r!   s        r*   Úmcp_tools_spanrp   ®  s7   € õ( !Ô,Ý&¨f¸VÐDÑDÔDØØØð	ñ ô ð r,   )NNNF)r   r   r   r   r   r   r   r    r!   r"   r#   r   )r#   r-   )r#   r0   )NNNNNF)r%   r   r3   r4   r5   r4   r6   r   r7   r   r8   r9   r!   r"   r#   r:   )NNNNF)r%   r   r@   r   rA   r   r7   r   r8   r9   r!   r"   r#   rB   )NNNNNNNF)r@   rE   rA   rE   rF   r   rG   rH   rI   r    r7   r   r8   r9   r!   r"   r#   rJ   )
rM   rN   r7   r   r8   r9   r!   r"   r#   rO   )rR   r   rS   r   r7   r   r8   r9   r!   r"   r#   rT   )r%   r   rW   r    r7   r   r8   r9   r!   r"   r#   rX   )FNNF)r%   r   r[   r"   r7   r   r8   r9   r!   r"   r#   r\   )NNr_   NNNNF)rF   r   r@   r   r`   r   rA   r   rG   rH   r7   r   r8   r9   r!   r"   r#   ra   )	NNNr_   NNNNF)rF   r   r@   r   rA   r   rd   r   rG   rH   re   r   r7   r   r8   r9   r!   r"   r#   rf   )
r@   r   r7   r   r8   r9   r!   r"   r#   ri   )rl   r   rm   r4   r7   r   r8   r9   r!   r"   r#   rn   )+Ú
__future__r   Úcollections.abcr   r   Útypingr   r   r	   Úsetupr   r=   r   r   r   r   r   r   r   r   r   r   r   Úspansr   Útracesr   Úopenai.types.responsesr   r+   r&   r2   r?   rD   rL   rQ   rV   rZ   r^   rc   rh   rk   rp   r/   r,   r*   ú<module>rx      sq  ðØ "Ð "Ð "Ð "Ð "Ð "à -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð àð 0Ø/Ð/Ð/Ð/Ð/Ð/ð
  ØØ&*Øð+ð +ð +ð +ð +ð\5ð 5ð 5ð 5ð
4ð 4ð 4ð 4ð "&Ø"Ø"ØØ'+Øð ð  ð  ð  ð  ðJ ØØØ'+Øðð ð ð ð ðD 15Ø15ØØ-1Ø#'ØØ'+Øð-ð -ð -ð -ð -ðb !%ØØ'+Øð	ð ð ð ð ð6 "ØØØ'+Øðð ð ð ð ðB #'ØØ'+Øðð ð ð ð ðD ØØ'+Øðð ð ð ð ð: ØØ$ØØ-1ØØ'+Øð)ð )ð )ð )ð )ðZ ØØØ %Ø-1Ø#'ØØ'+Øð(ð (ð (ð (ð (ðX ØØ'+Øð	ð ð ð ð ð6 Ø#ØØ'+Øðð ð ð ð ð ð r,   