o
    hSF                     @  s  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rPd dlmZ 				d]d^ddZd_ddZd`dd Z						dadbd*d+Z 					dcddd/d0Z!								dedfd7d8Z"				d]dgd<d=Z#					dcdhdAdBZ$				d]didEdFZ%				djdkdIdJZ&			K					dldmdNdOZ'				K					dndodSdTZ(				d]dpdVdWZ)					dcdqd[d\Z*dS )r    )annotations)MappingSequence)TYPE_CHECKINGAny   )logger   )get_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                 C  s.   t   }|rtd t  j| ||||d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.

    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_trace r(   V/var/www/html/openai_agents/venv/lib/python3.10/site-packages/agents/tracing/create.pytrace   s   
r*   Trace | Nonec                   C  
   t   S )z/Returns the currently active trace, if present.)r
   r$   r(   r(   r(   r)   r$   I      
r$   Span[Any] | Nonec                   C  r,   )z.Returns the currently active span, if present.)r
   get_current_spanr(   r(   r(   r)   r/   N   r-   r/   r#   handoffslist[str] | Nonetoolsoutput_typespan_idparentTrace | Span[Any] | NoneSpan[AgentSpanData]c                 C  s    t  jt| |||d|||d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#   r0   r2   r3   	span_datar4   r5   r    )r
   create_spanr   )r#   r0   r2   r3   r4   r5   r    r(   r(   r)   
agent_spanS   s   r;   inputoutputSpan[FunctionSpanData]c                 C  s   t  jt| ||d|||d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<   r=   r8   )r
   r:   r   )r#   r<   r=   r4   r5   r    r(   r(   r)   function_spanv   s   r?   "Sequence[Mapping[str, Any]] | Nonemodelmodel_configMapping[str, Any] | NoneusageSpan[GenerationSpanData]c                 C  s"   t  jt| ||||d|||d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<   r=   rA   rB   rD   r8   )r
   r:   r   )r<   r=   rA   rB   rD   r4   r5   r    r(   r(   r)   generation_span   s   "rF   responseResponse | NoneSpan[ResponseSpanData]c                 C     t  jt| d|||d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.
    )rG   r8   )r
   r:   r   )rG   r4   r5   r    r(   r(   r)   response_span      rK   
from_agentto_agentSpan[HandoffSpanData]c                 C     t  jt| |d|||d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.
    )rM   rN   r8   )r
   r:   r   )rM   rN   r4   r5   r    r(   r(   r)   handoff_span   s   
rQ   dataSpan[CustomSpanData]c                 C  s    t  jt| |pi d|||d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#   rR   r8   )r
   r:   r   )r#   rR   r4   r5   r    r(   r(   r)   custom_span   s   rT   	triggeredSpan[GuardrailSpanData]c                 C  rP   )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#   rU   r8   )r
   r:   r   )r#   rU   r4   r5   r    r(   r(   r)   guardrail_span      
rW   pcminput_formatSpan[TranscriptionSpanData]c                 C  s"   t  jt|||| |d|||d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<   rZ   r=   rA   rB   r8   )r
   r:   r   )rA   r<   rZ   r=   rB   r4   r5   r    r(   r(   r)   transcription_span<  s   r\   output_formatfirst_content_atSpan[SpeechSpanData]c	           	   	   C  s$   t  jt| |||||d|||d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.
    )rA   r<   r=   r]   rB   r^   r8   )r
   r:   r   )	rA   r<   r=   r]   rB   r^   r4   r5   r    r(   r(   r)   speech_spanh  s   r`   Span[SpeechGroupSpanData]c                 C  rJ   )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<   r8   )r
   r:   r   )r<   r4   r5   r    r(   r(   r)   speech_group_span  rL   rb   serverresultSpan[MCPListToolsSpanData]c                 C  rP   )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.
    )rc   rd   r8   )r
   r:   r   )rc   rd   r4   r5   r    r(   r(   r)   mcp_tools_span  rX   rf   )NNNF)r   r   r   r   r   r   r   r   r    r!   r"   r   )r"   r+   )r"   r.   )NNNNNF)r#   r   r0   r1   r2   r1   r3   r   r4   r   r5   r6   r    r!   r"   r7   )NNNNF)r#   r   r<   r   r=   r   r4   r   r5   r6   r    r!   r"   r>   )NNNNNNNF)r<   r@   r=   r@   rA   r   rB   rC   rD   r   r4   r   r5   r6   r    r!   r"   rE   )
rG   rH   r4   r   r5   r6   r    r!   r"   rI   )rM   r   rN   r   r4   r   r5   r6   r    r!   r"   rO   )r#   r   rR   r   r4   r   r5   r6   r    r!   r"   rS   )FNNF)r#   r   rU   r!   r4   r   r5   r6   r    r!   r"   rV   )NNrY   NNNNF)rA   r   r<   r   rZ   r   r=   r   rB   rC   r4   r   r5   r6   r    r!   r"   r[   )	NNNrY   NNNNF)rA   r   r<   r   r=   r   r]   r   rB   rC   r^   r   r4   r   r5   r6   r    r!   r"   r_   )
r<   r   r4   r   r5   r6   r    r!   r"   ra   )rc   r   rd   r1   r4   r   r5   r6   r    r!   r"   re   )+
__future__r   collections.abcr   r   typingr   r   r   setupr
   r9   r   r   r   r   r   r   r   r   r   r   r   spansr   tracesr   openai.types.responsesr   r*   r$   r/   r;   r?   rF   rK   rQ   rT   rW   r\   r`   rb   rf   r(   r(   r(   r)   <module>   s    4
-
%"1!"-,