a
    bg
                     @   sp   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 deZG dd	 d	eZdS )
    N)OptionalType)AsyncCallbackManagerForToolRun)	BaseModelField)AINBaseToolOperationTypec                   @   sN   e Zd ZU dZedZeed< edddZe	ed< ed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    r   r   v/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/tools/ainetwork/rule.pyr	      s   
r	   c                   @   sZ   e Zd ZU dZdZeed< dZeed< eZ	e
e ed< deeee ee edd	d
ZdS )
AINRuleOpszTool for owner operations.Z
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_schemaN)r
   r   r   run_managerreturnc              
      s   ddl m} z|tju rT|d u r(td| jj|j|dd|iiddI d H }n4|tj	u rx| jj|
 I d H }ntd| d	tj|d
dW S  ty } z&t|j dt| W  Y d }~S d }~0 0 d S )Nr   )ValueOnlyTransactionInputz%'eval' is required for SET operation.z.rulewrite)value)ZtransactionInputzUnsupported 'type': .F)ensure_asciiz: )Z	ain.typesr   r   ZSET
ValueErrorZ	interfacedbrefZsetRuleGETZgetRulejsondumps	Exceptionbuiltinsr
   r   r   )selfr
   r   r   r   r   reser   r   r   _arun9   s     


zAINRuleOps._arun)NN)r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r+   r   r   r   r   r      s   
   r   )r'   r$   typingr   r   Zlangchain_core.callbacksr   Zpydanticr   r   Z(langchain_community.tools.ainetwork.baser   r   r	   r   r   r   r   r   <module>   s   