
    g                    n   U d dl mZ d dl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mZmZmZmZ d dlZd dlmZ d d	lmZ d
dlmZ d
dlmZmZmZ dZ edd      Z	 ddZ e	 G d deeef                Z!e	 G d dee                Z"ee!eef   e"e   f   Z#	  ed      Z$de%d<    G d d      Z&y)    )annotationsN)Sequence)
ContextVar)	dataclassfield)datetime)	AnnotatedAnyCallableGenericLiteralUnion)core_schema)TypeVar   )_utils)BaseNodeEndRunEndT)StateTNodeStepEndStepHistoryStepdeep_copy_statenodes_schema_varr   )defaultc                4    | | S t        j                  |       S )z`Default method for snapshotting the state in a graph run, uses [`copy.deepcopy`][copy.deepcopy].)copydeepcopy)states    I/var/www/openai/venv/lib/python3.12/site-packages/pydantic_graph/state.pyr   r      s    }}}U##    c                      e Zd ZU dZded<   	 ded<   	  eej                        Zded<   	 d	Z	d
ed<   	 dZ
ded<   	  eed      Zded<   	 d ZddZy	)r   z;History step describing the execution of a node in a graph.r   r    z=Annotated[BaseNode[StateT, Any, RunEndT], CustomNodeSchema()]nodedefault_factoryr   start_tsNzfloat | NonedurationzLiteral['node']kindF)r   reprzOAnnotated[Callable[[StateT], StateT], pydantic.Field(exclude=True, repr=False)]snapshot_statec                D    | j                  | j                        | _        y )N)r+   r    selfs    r!   __post_init__zNodeStep.__post_init__4   s    ((4
r"   c                @    t        j                  | j                        S )z{Returns a deep copy of [`self.node`][pydantic_graph.state.NodeStep.node].

        Useful for summarizing history.
        )r   r   r$   r-   s    r!   data_snapshotzNodeStep.data_snapshot8   s    
 }}TYY''r"   )returnzBaseNode[StateT, Any, RunEndT])__name__
__module____qualname____doc____annotations__r   r   now_utcr'   r(   r)   r   r+   r/   r1    r"   r!   r   r       sm    EM=
GG v~~>Hh>6!Hl!2"D/"^fkegNc  75(r"   r   c                  h    e Zd ZU dZded<   	  eej                        Zded<   	 dZ	ded	<   	 dd
Z
y)r   z/History step describing the end of a graph run.End[RunEndT]resultr%   r   tsendzLiteral['end']r)   c                @    t        j                  | j                        S )z~Returns a deep copy of [`self.result`][pydantic_graph.state.EndStep.result].

        Useful for summarizing history.
        )r   r   r<   r-   s    r!   r1   zEndStep.data_snapshotK   s    
 }}T[[))r"   N)r2   r;   )r3   r4   r5   r6   r7   r   r   r8   r=   r)   r1   r9   r"   r!   r   r   @   s6    9&8B81 D. ^*r"   r   	nodes_varz3ContextVar[Sequence[type[BaseNode[Any, Any, Any]]]]r   c                  D    e Zd Z	 	 	 	 	 	 ddZedd       Zedd       Zy)CustomNodeSchemac           	     F   	 t         j                         }t	        |      dk(  r|d   }nq|D cg c].  }t
        |t        j                  |j                               f   0 }}t
        t        t        |         t        j                  | j                        f   } ||      }t        j                  | j                  t        j                   t        j"                         t        j$                                     |d<   |S # t        $ r}t        d      |d }~ww xY wc c}w )NzUnable to build a Pydantic schema for `NodeStep` or `HistoryStep` without setting `nodes_schema_var`. You probably want to use r   r   )functionreturn_schemaserialization)r   getLookupErrorRuntimeErrorlenr	   pydanticTagget_idr   tupleDiscriminator_node_discriminatorr   #wrap_serializer_function_ser_schema_node_serializerdict_schema
str_schema
any_schema)	r.   _source_typehandlernodese
nodes_typer$   nodes_annotatedschemas	            r!   __get_pydantic_core_schema__z-CustomNodeSchema.__get_pydantic_core_schema___   s   	$((*E u:?qJX]^X]PTyx||DKKM/J)JKX]O^"5)?#@(BXBXY]YqYqBr#rsJ$"-"Q"Q**%11+2H2H2JKLbLbLde#
 !  	, 	 _s   D 3D	D
DDc                $    | j                  d      S Nnode_id)rG   )	node_datas    r!   rP   z$CustomNodeSchema._node_discriminatorv   s    }}Y''r"   c                <     ||       }| j                         |d<   |S r_   )rM   )r$   rW   	node_dicts      r!   rR   z!CustomNodeSchema._node_serializerz   s!    DM	#{{}	)r"   N)rV   r
   rW   zpydantic.GetCoreSchemaHandlerr2   zcore_schema.CoreSchema)ra   r
   r2   str)r$   r
   rW   z&pydantic.SerializerFunctionWrapHandlerr2   zdict[str, Any])r3   r4   r5   r]   staticmethodrP   rR   r9   r"   r!   rB   rB   ^   sG    *G	. ( (  r"   rB   )r    r   r2   r   )'
__future__r   _annotationsr   collections.abcr   contextvarsr   dataclassesr   r   r   typingr	   r
   r   r   r   r   rK   pydantic_corer   typing_extensionsr    r   rX   r   r   r   __all__r   r   r   r   r   r   r7   rB   r9   r"   r!   <module>rp      s    2  $ " (  D D  % %  ) )
_ 
4	( -$ (wvw' ( (> *gg * *$ HVW_-ww/??@ ISS^H_ E _   r"   