
    dh
                     |    S SK r S SKrS SKJrJr  S SKJr  S SKJrJ	r	  S SK
JrJr   " S S\5      r " S S	\5      rg)
    N)OptionalType)AsyncCallbackManagerForToolRun)	BaseModelField)AINBaseToolOperationTypec                   j    \ rS rSr% Sr\" S5      r\\S'   \" SSS9r	\
\S'   \" SS	S9r\\
   \S
'   Srg)
RuleSchema   zSchema for owner operations..typez-Path on the blockchain where the rule applies)descriptionpathNz#eval string to determine permissioneval )__name__
__module____qualname____firstlineno____doc__r   r   r	   __annotations__r   strr   r   __static_attributes__r       `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/ainetwork/rule.pyr   r      s;    &*D-$c'VWD#W2WXD(3-Xr   r   c                   |    \ rS rSr% SrSr\\S'   Sr\\S'   \	r
\\   \S'     SS	\S
\S\\   S\\   S\4
S jjrSrg)
AINRuleOps   z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                 X  #    SSK Jn   U[        R                  L aQ  Uc  [	        S5      eU R
                  R                  R                  U5      R                  U" SSU00S9S9I S h  vN nO^U[        R                  L a<  U R
                  R                  R                  U5      R                  5       I S h  vN nO[	        SU S	35      e[        R                  " US
S9$  Nx N+! [         a8  n[        R                  " U5      R                    S[#        U5       3s S nA$ S nAff = f7f)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   _arunAINRuleOps._arun9   s     	8	<}(((<$%LMM NN--11$7??%>&$8& @  
 *** NN--11$7??AA #7vQ!?@@::c66 B  	<mmA&//03q6(;;	<sZ   D*AC% (C!)AC% 7C#8(C%  D*!C% #C% %
D'/-D"D'D*"D''D*r   )NN)r   r   r   r   r   r    r   r   r   r   r!   r   r   r	   r   r   r;   r   r   r   r   r   r      sz    $D#K @ $.Ki- #@D<< < sm	<
 <=< 
< <r   r   )r7   r4   typingr   r   langchain_core.callbacksr   pydanticr   r   (langchain_community.tools.ainetwork.baser   r	   r   r   r   r   r   <module>rA      s1      ! C % OY Y?< ?<r   