
    .Uid&              
         U d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dl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mZmZm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* ddl+m,Z,m-Z- ddl.m/Z/ erddl0m1Z1 eZ2	 eZ3	 eZ4	 eZ5	  e
dee4e3f         Z6e G d dee6   ejn                               Z8e G d de8e                Z9e G d de8e                Z:e G d de8e3                Z;eeeeee$ee!e"f   Z<de=d<   	 e G d de8e<                Z>e G d de8eeeef                   Z?e G d  d!e8e'                Z@e G d" d#e8e%                ZAe G d$ d%e8e#                ZBe G d& d'e8e                ZCee9e:e;e>e?e@eAeBeCf	   ZDde=d(<   	 ej                  j                   G d) d*             ZE G d+ d,      ZFy)-    )annotationsN)	dataclass)TYPE_CHECKINGAnyGenericLiteralTypeVarUnion)ResponseResponseComputerToolCallResponseFileSearchToolCallResponseFunctionToolCallResponseFunctionWebSearchResponseInputItemParamResponseOutputItemResponseOutputMessageResponseOutputRefusalResponseOutputTextResponseStreamEvent)ResponseCodeInterpreterToolCall)ComputerCallOutputFunctionCallOutputLocalShellCallOutputMcpApprovalResponse)ImageGenerationCallLocalShellCallMcpApprovalRequestMcpCallMcpListTools)ResponseReasoningItem)	BaseModel)	TypeAlias   )AgentsExceptionModelBehaviorError)Usage)AgentT)boundc                  .    e Zd ZU ded<   	 ded<   	 ddZy)RunItemBase
Agent[Any]agentr(   raw_itemc                    t        | j                  t              r| j                  S t        | j                  t              r| j                  j	                  d      S t        dt        | j                               )zHConverts this item into an input item suitable for passing to the model.Texclude_unsetzUnexpected raw item type: )
isinstancer.   dictr!   
model_dumpr$   type)selfs    h/home/jay/workspace/tools/ai-image-gen/jaaz-app/server/venv/lib/python3.12/site-packages/agents/items.pyto_input_itemzRunItemBase.to_input_itemI   s]    dmmT*== y1==++$+??!$>tDMM?R>S"TUU    N)returnTResponseInputItem)__name__
__module____qualname____annotations__r8    r9   r7   r+   r+   >   s    ?K
	Vr9   r+   c                  ,    e Zd ZU dZded<   	 dZded<   y)MessageOutputItemz"Represents a message from the LLM.r   r.   message_output_itemzLiteral['message_output_item']r5   Nr<   r=   r>   __doc__r?   r5   r@   r9   r7   rB   rB   U   s    ,##*+@D
(@r9   rB   c                  ,    e Zd ZU dZded<   	 dZded<   y)HandoffCallItemz?Represents a tool call for a handoff from one agent to another.r   r.   handoff_call_itemzLiteral['handoff_call_item']r5   NrD   r@   r9   r7   rG   rG   _   s    I&&J)<D
&<r9   rG   c                  D    e Zd ZU dZded<   	 ded<   	 ded<   	 dZded	<   y
)HandoffOutputItemz#Represents the output of a handoff.r;   r.   r,   source_agenttarget_agenthandoff_output_itemzLiteral['handoff_output_item']r5   NrD   r@   r9   r7   rJ   rJ   i   s+    -  F*0+@D
(@r9   rJ   r"   ToolCallItemTypesc                  ,    e Zd ZU dZded<   	 dZded<   y)ToolCallItemzDRepresents a tool call e.g. a function call or computer action call.rN   r.   tool_call_itemzLiteral['tool_call_item']r5   NrD   r@   r9   r7   rP   rP      s    N!&6D
#6r9   rP   c                  8    e Zd ZU dZded<   	 ded<   	 dZded<   y	)
ToolCallOutputItemz%Represents the output of a tool call.z>FunctionCallOutput | ComputerCallOutput | LocalShellCallOutputr.   r   outputtool_call_output_itemz Literal['tool_call_output_item']r5   NrD   r@   r9   r7   rS   rS      s(     0LL&K .ED
*Dr9   rS   c                  ,    e Zd ZU dZded<   	 dZded<   y)ReasoningItemzRepresents a reasoning item.r    r.   reasoning_itemzLiteral['reasoning_item']r5   NrD   r@   r9   r7   rW   rW      s    &##!&6D
#6r9   rW   c                  ,    e Zd ZU dZded<   	 dZded<   y)MCPListToolsItemz1Represents a call to an MCP server to list tools.r   r.   mcp_list_tools_itemzLiteral['mcp_list_tools_item']r5   NrD   r@   r9   r7   rZ   rZ      s    ;&+@D
(@r9   rZ   c                  ,    e Zd ZU dZded<   	 dZded<   y)MCPApprovalRequestItemz&Represents a request for MCP approval.r   r.   mcp_approval_request_itemz$Literal['mcp_approval_request_item']r5   NrD   r@   r9   r7   r]   r]      s    0  '1LD
.Lr9   r]   c                  ,    e Zd ZU dZded<   	 dZded<   y)MCPApprovalResponseItemz1Represents a response to an MCP approval request.r   r.   mcp_approval_response_itemz%Literal['mcp_approval_response_item']r5   NrD   r@   r9   r7   r`   r`      s    ;!!(2ND
/Nr9   r`   RunItemc                  :    e Zd ZU ded<   	 ded<   	 ded<   	 d	dZy)
ModelResponsezlist[TResponseOutputItem]rT   r&   usage
str | Noneresponse_idc                `    | j                   D cg c]  }|j                  d       c}S c c}w )zPConvert the output into a list of input items suitable for passing to the model.Tr0   )rT   r4   )r6   its     r7   to_input_itemszModelResponse.to_input_items   s(    
 =AKKHbD1HHHs   +N)r:   list[TResponseInputItem])r<   r=   r>   r?   rj   r@   r9   r7   rd   rd      s$    %%NL1Ir9   rd   c                      e Zd Zedd       Zed	d       Ze	 	 	 	 d
d       Zedd       Zedd       Ze	 	 	 	 	 	 dd       Z	y)ItemHelpersc                    t        |t              sy|j                  sy|j                  d   }t        |t              r|j                  S t        |t
              r|j                  S t        dt        |             )z9Extracts the last text content or refusal from a message. zUnexpected content type: )	r2   r   contentr   textr   refusalr%   r5   clsmessagelast_contents      r7   extract_last_contentz ItemHelpers.extract_last_content   sq     '#89r*l$67$$$&;<'''$'@lAS@T%UVVr9   c                    t        |t              r8|j                  sy|j                  d   }t        |t              r|j                  S y)zHExtracts the last text content from a message, if any. Ignores refusals.Nrp   )r2   r   rq   r   rr   rt   s      r7   extract_last_textzItemHelpers.extract_last_text   sA     g45??"??2.L,(:;#(((r9   c                N    t        |t              r|ddgS |j                         S )zDConverts a string or list of input items into a list of input items.user)rq   role)r2   strcopy)ru   inputs     r7   input_to_new_input_listz#ItemHelpers.input_to_new_input_list  s3    
 eS!  %"  zz|r9   c                b    d}|D ]'  }t        |t              s|| j                  |      z  }) |S )zFConcatenates all the text content from a list of message output items.ro   )r2   rB   text_message_output)ru   itemsrr   items       r7   text_message_outputsz ItemHelpers.text_message_outputs  s?      	6D$ 12//55	6 r9   c                    d}|j                   j                  D ]"  }t        |t              s||j                  z  }$ |S )z@Extracts all the text content from a single message output item.ro   )r.   rq   r2   r   rr   )ru   rv   rr   r   s       r7   r   zItemHelpers.text_message_output"  sD     $$,, 	"D$ 23		!	" r9   c                "    |j                   |ddS )z@Creates a tool call output item from a tool call and its output.function_call_output)call_idrT   r5   )r   )ru   	tool_callrT   s      r7   rU   z!ItemHelpers.tool_call_output_item+  s     !((*
 	
r9   N)rv   TResponseOutputItemr:   r~   )rv   r   r:   rf   )r   zstr | list[TResponseInputItem]r:   rk   )r   zlist[RunItem]r:   r~   )rv   rB   r:   r~   )r   r   rT   r~   r:   r   )
r<   r=   r>   classmethodrx   rz   r   r   r   rU   r@   r9   r7   rm   rm      s    W W 	 	 2	!      
0
:=
	
 
r9   rm   )G
__future__r   abcdataclassesr   typingr   r   r   r   r	   r
   pydanticopenai.types.responsesr   r   r   r   r   r   r   r   r   r   r   :openai.types.responses.response_code_interpreter_tool_callr   0openai.types.responses.response_input_item_paramr   r   r   r   +openai.types.responses.response_output_itemr   r   r   r   r   .openai.types.responses.response_reasoning_itemr    r!   typing_extensionsr"   
exceptionsr$   r%   re   r&   r-   r'   	TResponser;   r   TResponseStreamEventr(   ABCr+   rB   rG   rJ   rN   r?   rP   rS   rW   rZ   r]   r`   rb   rd   rm   r@   r9   r7   <module>r      s   " 
 ! G G       Q  ' ; 	 =+  K(  G*  HCu02DDEF V'!*cgg V V, A$9: A A =k":; = = A$67 A A  %#	  9 	 / 7;01 7 7 E(*<>RRSTE E  7K 56 7 7 A{<0 A A M[);< M M Ok*=> O O 
 
 % 
I I  I,F
 F
r9   