
    Ng
                         d dl Z d dl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mZ  G d de          Z G d d	e          ZdS )
    N)OptionalType)AsyncCallbackManagerForToolRun)	BaseModelField)AINBaseToolOperationTypec                       e Zd ZU dZ ed          Zeed<    edd          Ze	ed<    edd          Z
ee	         ed	<   dS )

RuleSchemazSchema for owner operations..typez-Path on the blockchain where the rule applies)descriptionpathNz#eval string to determine permissioneval)__name__
__module____qualname____doc__r   r   r	   __annotations__r   strr   r        d/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/ainetwork/rule.pyr   r      st         &&%**D-$$$c'VWWWD#WWW%2WXXXD(3-XXXXXr   r   c                       e Zd ZU dZdZeed<   dZeed<   eZ	e
e         ed<   	 	 dded	ed
ee         dee         def
dZdS )
AINRuleOpszTool for owner operations.
AINruleOpsnamea  
Covers the write `rule` for the AINetwork Blockchain database. The SET type specifies write permissions using the `eval` variable as a JavaScript eval string.
In order to AINvalueOps with SET at the path, the execution result of the `eval` string must be true.

## Path Rules
1. Allowed characters for directory: `[a-zA-Z_0-9]`
2. Use `$<key>` for template variables as directory.

## Eval String Special Variables
- auth.addr: Address of the writer for the path
- newData: New data for the path
- data: Current data for the path
- currentTime: Time in seconds
- lastBlockNumber: Latest processed block number

## Eval String Functions
- getValue(<path>)
- getRule(<path>)
- getOwner(<path>)
- getFunction(<path>)
- evalRule(<path>, <value to set>, auth, currentTime)
- evalOwner(<path>, 'write_owner', auth)

## SET Example
- type: SET
- path: /apps/langchain_project_1/$from/$to/$img
- eval: auth.addr===$from&&!getValue('/apps/image_db/'+$img)

## GET Example
- type: GET
- path: /apps/langchain_project_1
r   args_schemaNr   r   r   run_managerreturnc                 D  K   ddl m} 	 |t          j        u rY|t	          d          | j        j                            |                               |dd|ii                     d {V }nY|t          j	        u r8| j        j                            |          
                                 d {V }nt	          d| d	          t          j        |d
          S # t          $ r5}t          j        |          j         dt#          |           cY d }~S d }~ww xY w)Nr   )ValueOnlyTransactionInputz%'eval' is required for SET operation.z.rulewrite)value)transactionInputzUnsupported 'type': .F)ensure_asciiz: )	ain.typesr!   r	   SET
ValueError	interfacedbrefsetRuleGETgetRulejsondumps	Exceptionbuiltinsr   r   r   )selfr   r   r   r   r!   reses           r   _arunzAINRuleOps._arun9   s|      	877777	<}(((<$%LMMM N-11$77??%>%>&$8& & & @        
 *** N-11$77??AAAAAAAA !?!?!?!?@@@:c6666 	< 	< 	<mA&&/;;3q66;;;;;;;;	<s   CC   
D**DDD)NN)r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r7   r   r   r   r   r      s         $$D#K   @ $.Ki--- #@D< << < sm	<
 <=< 
< < < < < <r   r   )r3   r0   typingr   r   langchain_core.callbacksr   pydanticr   r   (langchain_community.tools.ainetwork.baser   r	   r   r   r   r   r   <module>r<      s      ! ! ! ! ! ! ! ! C C C C C C % % % % % % % % O O O O O O O OY Y Y Y Y Y Y Y?< ?< ?< ?< ?< ?< ?< ?< ?< ?<r   