o
    h.                     @  sX  d dl mZ d dlZd dlmZmZmZmZmZ d dl	m
Z
 d dlmZ ddlmZmZ ddl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 ddlmZ erbddlmZ ddl m!Z! ededZ"eee e"gef Z#eee gef Z$eddddd+ddZ%edddd d,d%dZ%edddd d-d'dZ%					d.d/d*dZ%dS )0    )annotationsN)TYPE_CHECKINGAnyCallablecastoverload)TypeAdapter)TypeVar   )ModelBehaviorError	UserError)Handoff)RunContextWrapperTContext)ensure_strict_json_schema)	SpanError)_error_tracing_json)MaybeAwaitable)	AgentBase   )RealtimeAgentTHandoffInput)defaultT)tool_name_overridetool_description_override
is_enabledagentRealtimeAgent[TContext]r   
str | Noner   r   Sbool | Callable[[RunContextWrapper[Any], RealtimeAgent[Any]], MaybeAwaitable[bool]]return*Handoff[TContext, RealtimeAgent[TContext]]c                C     d S N )r   r   r   r   r%   r%   Y/var/www/html/openai_agents/venv/lib/python3.10/site-packages/agents/realtime/handoffs.pyrealtime_handoff   s   r'   )r   r   r   
on_handoff!OnHandoffWithInput[THandoffInput]
input_typetype[THandoffInput]c                C  r#   r$   r%   )r   r(   r*   r   r   r   r%   r%   r&   r'   (   s   
OnHandoffWithoutInputc                C  r#   r$   r%   )r   r(   r   r   r   r%   r%   r&   r'   5   s   	@OnHandoffWithInput[THandoffInput] | OnHandoffWithoutInput | Nonetype[THandoffInput] | Nonec              	     s  rsrrJ ddur1t sJ dt}t|jdkr(tdt }ndi }durIt}t|jdkrItd	dd fdd}|p[t	 }	|pbt
 }
t|}dfdd}t|	|
||d jt r~|dS dS )a  Create a handoff from a RealtimeAgent.

    Args:
        agent: The RealtimeAgent to handoff to, or a function that returns a RealtimeAgent.
        tool_name_override: Optional override for the name of the tool that represents the handoff.
        tool_description_override: Optional override for the description of the tool that
            represents the handoff.
        on_handoff: A function that runs when the handoff is invoked.
        input_type: the type of the input to the handoff. If provided, the input will be validated
            against this type. Only relevant if you pass a function that takes an input.
        is_enabled: Whether the handoff is enabled. Can be a bool or a callable that takes the run
            context and agent and returns whether the handoff is enabled. Disabled handoffs are
            hidden from the LLM at runtime.

    Note: input_filter is not supported for RealtimeAgent handoffs.
    zBYou must provide either both on_handoff and input_type, or neitherNzon_handoff must be callabler
   z5on_handoff must take two arguments: context and inputr   z*on_handoff must take one argument: contextctxRunContextWrapper[Any]
input_jsonr   r!   r   c                   s   d urAd urA|d u rt tdddid tdtj|dd}ttt }t	
|r:|| |I d H   S || |  S d ur\tt}t	
|rX|| I d H   S ||   S )Nz6Handoff function expected non-null input, but got Nonedetailszinput_json is None)messagedataF)json_strtype_adapterpartial)r   attach_error_to_current_spanr   r   r   validate_jsonr   OnHandoffWithInputr   inspectiscoroutinefunctionr,   )r/   r1   validated_input
input_funcno_input_func)r   r*   r(   r6   r%   r&   _invoke_handoffn   s8   




z)realtime_handoff.<locals>._invoke_handoff
agent_baseAgentBase[Any]boolc                   sF   t  s	J dt|tsJ d | |}t|r!|I d H S |S )Nz is_enabled must be non-null herez$Can't handoff to a non-RealtimeAgent)callable
isinstancer   r;   isawaitable)r/   rA   result)r   r%   r&   _is_enabled   s   


z%realtime_handoff.<locals>._is_enabled)	tool_nametool_descriptioninput_json_schemaon_invoke_handoffinput_filter
agent_namer   r$   )r/   r0   r1   r   r!   r   )r/   r0   rA   rB   r!   rC   )rD   r;   	signaturelen
parametersr   r   json_schemar   default_tool_namedefault_tool_descriptionr   name)r   r   r   r(   r*   r   sigrK   r@   rI   rJ   rH   r%   )r   r*   r   r(   r6   r&   r'   A   sB   


 
)
r   r   r   r   r   r   r   r    r!   r"   )r   r   r(   r)   r*   r+   r   r   r   r   r   r    r!   r"   )r   r   r(   r,   r   r   r   r   r   r    r!   r"   )NNNNT)r   r   r   r   r   r   r(   r-   r*   r.   r   r    r!   r"   )&
__future__r   r;   typingr   r   r   r   r   pydanticr   typing_extensionsr	   
exceptionsr   r   handoffsr   run_contextr   r   strict_schemar   tracing.spansr   utilr   r   util._typesr   r   r    r   r   r:   r,   r'   r%   r%   r%   r&   <module>   sN    
