o
    i	                  
   @  s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 zd dl
mZ W n ey7 Z zededZ[ww d	d
 ZdddZG dd deZdS )    )annotations)Sequence)Any)FunctionToolset)Tool)ACIz-Please install `aci-sdk` to use ACI.dev toolsNc                 C  s8   t | trdd |  D S t | trdd | D S | S )Nc                 S  s"   i | ]\}}|d vr|t |qS )>   visible_clean_schema).0kv r   Y/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/ext/aci.py
<dictcomp>   s   " z!_clean_schema.<locals>.<dictcomp>c                 S  s   g | ]}t |qS r   r	   )r   itemr   r   r   
<listcomp>   s    z!_clean_schema.<locals>.<listcomp>)
isinstancedictitemslist)schemar   r   r   r
      s
   

r
   aci_functionstrlinked_account_owner_idreturnr   c                   s   t    j| }|d d |d d }|d d }|dd|di |dg |d	d
d}t|}d fdd}tj|||dS )a$  Creates a Pydantic AI tool proxy from an ACI.dev function.

    Args:
        aci_function: The ACI.dev function to wrap.
        linked_account_owner_id: The ACI user ID to execute the function on behalf of.

    Returns:
        A Pydantic AI tool that corresponds to the ACI.dev tool.
    functionnamedescription
parametersadditionalPropertiesF
propertiesrequiredtypeobject)r    r!   r"   r#   argsr   kwargsr   r   c                    s   | rt d j|ddS )Nz$Positional arguments are not allowedT)r   allowed_apps_only)	TypeErrorhandle_function_call)r%   r&   acifunction_namer   r   r   implementation4   s   z%tool_from_aci.<locals>.implementation)r   r   r   json_schemaN)r%   r   r&   r   r   r   )r   	functionsget_definitiongetr
   r   from_schema)r   r   function_definitionfunction_descriptioninputsr.   r-   r   r*   r   tool_from_aci   s$   




	
r6   c                      s(   e Zd ZdZddd fd
dZ  ZS )
ACIToolsetz#A toolset that wraps ACI.dev tools.Nidaci_functionsSequence[str]r   r   r9   
str | Nonec                  s"   t  j fdd|D |d d S )Nc                   s   g | ]}t | qS r   )r6   )r   r   r   r   r   r   K   s    z'ACIToolset.__init__.<locals>.<listcomp>r8   )super__init__)selfr:   r   r9   	__class__r=   r   r?   I   s   
zACIToolset.__init__)r:   r;   r   r   r9   r<   )__name__
__module____qualname____doc__r?   __classcell__r   r   rA   r   r7   F   s    r7   )r   r   r   r   r   r   )
__future__r   collections.abcr   typingr   pydantic_air   pydantic_ai.toolsr   r+   r   ImportError_import_errorr
   r6   r7   r   r   r   r   <module>   s    


-