
    /UiSF                       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 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d dZ 	 	 	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ!	 	 	 	 	 	 	 	 d#	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d$dZ"	 	 	 	 d	 	 	 	 	 	 	 	 	 d%dZ#	 	 	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 d&dZ$	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 d'dZ%	 	 	 	 d(	 	 	 	 	 	 	 	 	 	 	 d)dZ&	 	 	 	 	 	 	 	 d*	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZ'	 	 	 	 	 	 	 	 	 d,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d-dZ(	 	 	 	 d	 	 	 	 	 	 	 	 	 d.dZ)	 	 	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 d/dZ*y)0    )annotations)MappingSequence)TYPE_CHECKINGAny   )logger   )get_trace_provider)AgentSpanDataCustomSpanDataFunctionSpanDataGenerationSpanDataGuardrailSpanDataHandoffSpanDataMCPListToolsSpanDataResponseSpanDataSpeechGroupSpanDataSpeechSpanDataTranscriptionSpanData)Span)Trace)ResponseNc                    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.

    Returns:
        The newly created trace object.
    zKTrace already exists. Creating a new trace, but this is probably a mistake.)nametrace_idgroup_idmetadatadisabled)r   get_current_tracer	   warningcreate_trace)workflow_namer   r   r   r   current_traces         q/home/jay/workspace/tools/ai-image-gen/jaaz-app/server/venv/lib/python3.12/site-packages/agents/tracing/create.pytracer&      sS    < '(::<MY	
 ,, -      c                 2    t               j                         S )z/Returns the currently active trace, if present.)r   r     r'   r%   r    r    I   s    1133r'   c                 2    t               j                         S )z.Returns the currently active span, if present.)r   get_current_spanr)   r'   r%   r+   r+   N   s    0022r'   c                V    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   handoffstoolsoutput_type	span_dataspan_idparentr   )r   create_spanr   )r   r-   r.   r/   r2   r3   r   s          r%   
agent_spanr5   S   s7    6 ++THEWbc	 ,  r'   c                T    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   inputoutputr0   )r   r4   r   )r   r7   r8   r2   r3   r   s         r%   function_spanr9   v   s4    2 ++"E&I	 ,  r'   c           	     X    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.
    )r7   r8   modelmodel_configusager0   )r   r4   r   )r7   r8   r;   r<   r=   r2   r3   r   s           r%   generation_spanr>      sB    D ++$%
  ,  r'   c                P    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.
    )responser0   )r   r4   r   )r@   r2   r3   r   s       r%   response_spanrA      s0    $ ++"H5	 ,  r'   c                R    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.
    )
from_agentto_agentr0   )r   r4   r   )rC   rD   r2   r3   r   s        r%   handoff_spanrE      s2    . ++!Z(K	 ,  r'   c                Z    t               j                  t        | |xs 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   datar0   )r   r4   r   )r   rG   r2   r3   r   s        r%   custom_spanrH      s6    0 ++ d<	 ,  r'   c                R    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   	triggeredr0   )r   r4   r   )r   rJ   r2   r3   r   s        r%   guardrail_spanrK      s2    ( ++#C	 ,  r'   c           	     X    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.
    )r7   input_formatr8   r;   r<   r0   )r   r4   r   )r;   r7   rM   r8   r<   r2   r3   r   s           r%   transcription_spanrN   <  sA    < ++'%%
  ,  r'   c	           
     Z    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.
    )r;   r7   r8   output_formatr<   first_content_atr0   )r   r4   r   )	r;   r7   r8   rP   r<   rQ   r2   r3   r   s	            r%   speech_spanrR   h  sD    8 ++ '%-
  ,  r'   c                P    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.
    )r7   r0   )r   r4   r   )r7   r2   r3   r   s       r%   speech_group_spanrT     s0    $ ++%E2	 ,  r'   c                R    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.
    )serverresultr0   )r   r4   r   )rV   rW   r2   r3   r   s        r%   mcp_tools_spanrX     s2    ( ++&fVD	 ,  r'   )NNNF)r#   strr   
str | Noner   rZ   r   dict[str, Any] | Noner   boolreturnr   )r]   zTrace | None)r]   zSpan[Any] | None)NNNNNF)r   rY   r-   list[str] | Noner.   r^   r/   rZ   r2   rZ   r3   Trace | Span[Any] | Noner   r\   r]   zSpan[AgentSpanData])NNNNF)r   rY   r7   rZ   r8   rZ   r2   rZ   r3   r_   r   r\   r]   zSpan[FunctionSpanData])NNNNNNNF)r7   "Sequence[Mapping[str, Any]] | Noner8   r`   r;   rZ   r<   Mapping[str, Any] | Noner=   r[   r2   rZ   r3   r_   r   r\   r]   zSpan[GenerationSpanData])
r@   zResponse | Noner2   rZ   r3   r_   r   r\   r]   zSpan[ResponseSpanData])rC   rZ   rD   rZ   r2   rZ   r3   r_   r   r\   r]   zSpan[HandoffSpanData])r   rY   rG   r[   r2   rZ   r3   r_   r   r\   r]   zSpan[CustomSpanData])FNNF)r   rY   rJ   r\   r2   rZ   r3   r_   r   r\   r]   zSpan[GuardrailSpanData])NNpcmNNNNF)r;   rZ   r7   rZ   rM   rZ   r8   rZ   r<   ra   r2   rZ   r3   r_   r   r\   r]   zSpan[TranscriptionSpanData])	NNNrb   NNNNF)r;   rZ   r7   rZ   r8   rZ   rP   rZ   r<   ra   rQ   rZ   r2   rZ   r3   r_   r   r\   r]   zSpan[SpeechSpanData])
r7   rZ   r2   rZ   r3   r_   r   r\   r]   zSpan[SpeechGroupSpanData])rV   rZ   rW   r^   r2   rZ   r3   r_   r   r\   r]   zSpan[MCPListToolsSpanData])+
__future__r   collections.abcr   r   typingr   r   r	   setupr   r1   r   r   r   r   r   r   r   r   r   r   r   spansr   tracesr   openai.types.responsesr   r&   r    r+   r5   r9   r>   rA   rE   rH   rK   rN   rR   rT   rX   r)   r'   r%   <module>rj      sp   " - %  %     /
  &**** * $	*
 * *Z4
3 "&""'+ 
     	 
   %     J '+
  	
 %  D 1515-1#''+---.- - +	-
 !- - %- - -b !%'+	 % 	
 6 "'+  %	
  B #''+

  %	
  D '+
  %	
  : $-1'+))) ) 	)
 +) ) %) ) !)Z  %-1#''+((( ( 	(
 +( !( ( %( ( (X '+	 % 	
 6 #'+  %	
   r'   