o
    i                     @  s   U 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 d dlmZmZ d dlmZmZmZ d dlZd d	lmZ d
dlmZ e	dZded< eG dd dZdddZedddZdS )    )annotations)IteratorSequence)contextmanager)
ContextVar)	dataclass)datetimetimezone)	AnnotatedAnyUnionN)core_schema   )BaseNodenodes_type_contextz3ContextVar[Sequence[type[BaseNode[Any, Any, Any]]]]c                   @  s2   e Zd ZdddZedddZedddZdS )CustomNodeSchema_source_typer   handlerpydantic.GetCoreSchemaHandlerreturncore_schema.CoreSchemac              
   C  s   zt  }W n ty } ztd|d }~ww t|dkr#|d }ndd |D }ttt| t	| j
f }||}tj| jtt t d|d< |S )NzUnable to build a Pydantic schema for `BaseNode` without setting `nodes_type_context`. You should build Pydantic schemas for snapshots using `StatePersistence.set_types()`.   r   c                 S  s"   g | ]}t |t| f qS  )r
   pydanticTagget_node_id).0noder   r   g/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_graph/persistence/_utils.py
<listcomp>!   s   " zACustomNodeSchema.__get_pydantic_core_schema__.<locals>.<listcomp>)functionreturn_schemaserialization)r   getLookupErrorRuntimeErrorlenr
   r   tupler   Discriminator_node_discriminatorr   #wrap_serializer_function_ser_schema_node_serializerdict_schema
str_schema
any_schema)selfr   r   nodese
nodes_typenodes_annotatedschemar   r   r   __get_pydantic_core_schema__   s(   

z-CustomNodeSchema.__get_pydantic_core_schema__	node_datastrc                 C  s
   |  dS Nnode_id)r#   )r6   r   r   r   r)   +   s   
z$CustomNodeSchema._node_discriminatorr   &pydantic.SerializerFunctionWrapHandlerdict[str, Any]c                 C  s   || }|   |d< |S r8   )r   )r   r   	node_dictr   r   r   r+   /   s   z!CustomNodeSchema._node_serializerN)r   r   r   r   r   r   )r6   r   r   r7   )r   r   r   r:   r   r;   )__name__
__module____qualname__r5   staticmethodr)   r+   r   r   r   r   r      s    
r   r   r   c                   C  s   t jtjdS )N)tz)r   nowr	   utcr   r   r   r   now_utc6   s   rD   r0   'Sequence[type[BaseNode[Any, Any, Any]]]Iterator[None]c              	   c  s0    t | }zd V  W t | d S t | w )N)r   setreset)r0   tokenr   r   r   set_nodes_type_context:   s
   
rJ   )r   r   )r0   rE   r   rF   )
__future__r   _annotationscollections.abcr   r   
contextlibr   contextvarsr   dataclassesr   r   r	   typingr
   r   r   r   pydantic_corer   r0   r   r   __annotations__r   rD   rJ   r   r   r   r   <module>   s     
#