Comparing version
{ | ||
"name": "aagent.js", | ||
"version": "0.0.6", | ||
"description": "It is CLI to work with Autonomous Agents on Obyte", | ||
"version": "0.0.7", | ||
"description": "It is library to work with Autonomous Agents on Obyte", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"bin": { | ||
"aagent": "./cli.js" | ||
"dependencies": { | ||
"headless-obyte": "https://github.com/byteball/headless-obyte" | ||
}, | ||
"keywords": [ | ||
"obyte", | ||
"framework", | ||
"library", | ||
"aa", | ||
@@ -27,12 +28,3 @@ "autonomous", | ||
"url": "https://github.com/olabs-org/aagent.js/issues" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^9.0.0", | ||
"global": "^4.4.0", | ||
"ocore": "git+https://github.com/byteball/ocore.git", | ||
"open": "^7.0.4", | ||
"request": "^2.88.2", | ||
"request-promise": "^4.2.5", | ||
"yargs": "^15.3.1" | ||
} | ||
} |
193
README.md
@@ -1,40 +0,191 @@ | ||
# aagent.js | ||
### What's it? | ||
It is CLI and [library](https://github.com/olabs-org/aagent.js-lib) to work with Autonomous Agents on Obyte | ||
It is [CLI](https://github.com/olabs-org/aagent-cli) and library to work with Autonomous Agents on Obyte | ||
## CLI | ||
Init | ||
### Quick start | ||
You can create a new project using [CLI](https://github.com/olabs-org/aagent-cli) | ||
```bash | ||
npm i -g aagent.js | ||
aagent --help | ||
npm i -g aagent-cli | ||
aagent init folder | ||
``` | ||
Create project from [template](template) (with AA example, tests and library) | ||
Or add to an existing project | ||
```bash | ||
aagent init folder | ||
yarn add aagent.js | ||
``` | ||
```javascript | ||
require('headless-obyte'); | ||
const eventBus = require('ocore/event_bus'); | ||
const { AA, AAs } = require('aagent.js'); | ||
``` | ||
## Library | ||
### AA | ||
Example: | ||
```javascript | ||
require('headless-obyte'); | ||
const eventBus = require('ocore/event_bus'); | ||
const { AA } = require('aagent.js'); | ||
eventBus.on('headless_wallet_ready', () => { | ||
const aa = new AA('address'); | ||
aa.events.on('new_request', (request) => { | ||
console.error('new request', request); | ||
}); | ||
aa.events.on('new_response', (err, response, vars) => { | ||
console.error('new response', response, vars); | ||
}); | ||
aa.events.on('new_aa_definition', (definition) => { | ||
console.error('new aa definition', definition); | ||
}); | ||
aa.events.on('new_aa_definition_saved', (definition) => { | ||
console.error('new aa definition saved', definition); | ||
}); | ||
aa.newResponseFilter((err, params, vars) => { | ||
return true; | ||
}, (err, params, vars) => { | ||
console.error(err, params, vars); | ||
}); | ||
}); | ||
``` | ||
<br> | ||
Validating AA | ||
```bash | ||
aagent validate aa.oscript | ||
#### AA class contains the following methods: | ||
All events are applied to the specified address in the constructor. | ||
##### constructor | ||
```javascript | ||
const aa = new AA('address') | ||
``` | ||
one argument - aa_address(string) | ||
static method **getAAVars**: | ||
```javascript | ||
AA.getAAVars('address'); | ||
``` | ||
will return variables from AA. | ||
<br> | ||
Open GUI Wallet to deploy | ||
```bash | ||
aagent deploy aa.oscript | ||
#### Event handlers: | ||
The handler triggers an event, passes it to the first function, and if it returns true, calls the second function. You can use them to process specific data(like a router). | ||
<br>**More about arguments in events.** | ||
<br> | ||
```javascript | ||
aa.addRequestEventHandler((request, body) => { | ||
return true; | ||
}, (request, body) => { | ||
console.error(request, body); | ||
}); | ||
``` | ||
*If the file is too large it will be uploaded to the server and transferred to the client in the link.* <br> | ||
This command supports argument **--testnet** to deploy script through the testnet or mainnet wallet. | ||
```javascript | ||
aa.addResponseEventHandler((err, params, vars, body) => { | ||
return true; | ||
}, (err, params, vars, body) => { | ||
console.error(err, params, vars, body); | ||
}); | ||
``` | ||
```javascript | ||
aa.addDefinitionEventHandler((definition, body) => { | ||
return true; | ||
}, (definition, body) => { | ||
console.error(definition, body); | ||
}); | ||
``` | ||
```javascript | ||
aa.addDefinitionSavedEventHandler((definition, body) => { | ||
return true; | ||
}, (definition, body) => { | ||
console.error(definition, body); | ||
}); | ||
``` | ||
<br> | ||
#### And events: | ||
##### new_request | ||
```javascript | ||
aa.events.on('new_request', (request, body) => { | ||
console.error('new request', request, body); | ||
}); | ||
``` | ||
Arguments: | ||
- request - {address: aa_address, messages: unit.messages} | ||
- body - raw body from event | ||
<br> | ||
Start tests | ||
```bash | ||
yarn test | ||
##### new_response | ||
```javascript | ||
aa.events.on('new_response', (err, params, vars, body) => { | ||
console.error('new response', err, params, vars, body); | ||
}); | ||
``` | ||
Arguments: | ||
- err - if *bounced* return error message | ||
- params - { address: aa_address, response: body.response } | ||
- vars - new vars from AA | ||
- body - raw body from event | ||
<br> | ||
#### If you want to start developing on Obyte and you need help, write to us on [discord](https://obyte.org/discord) or on telegram: @xJeneK | ||
##### new_aa_definition | ||
```javascript | ||
aa.events.on('new_aa_definition', (definition, body) => { | ||
console.error('new aa definition', definition, body); | ||
}); | ||
``` | ||
Arguments: | ||
- definition - definition from messages | ||
- body - raw body from event | ||
<br> | ||
##### new_aa_definition_saved | ||
```javascript | ||
aa.events.on('new_aa_definition_saved', (definition, body) => { | ||
console.error('new aa definition saved', definition, body); | ||
}); | ||
``` | ||
*This event can be triggered twice with the same data (architectural features), please consider this.*<br> | ||
Arguments: | ||
- definition - definition from messages | ||
- body - raw body from event | ||
--- | ||
### AAs | ||
All events applies to the specified addresses in the constructor. | ||
##### constructor | ||
```javascript | ||
const aas = new AAs(['address', 'address2']) | ||
``` | ||
one argument - aa_addresses - array[string] | ||
<br> | ||
```javascript | ||
aas.addAddress('address'); | ||
``` | ||
Adds a new address and subscribes to it | ||
<br> | ||
static method **getAAVars**: | ||
```javascript | ||
AAs.getAAVars('address'); | ||
``` | ||
will return variables from AA. | ||
This class supports only: <br> | ||
**Methods**: addRequestEventHandler, addResponseEventHandler <br> | ||
**Events**: new_request, new_response<br><br> | ||
**Arguments are identical to AA class** | ||
<br> | ||
#### If you want to start developing on Obyte and you need help, write to us on [discord](https://obyte.org/discord) or on telegram: @xJeneK |
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
10878
23.49%1
-85.71%191
365.85%0
-100%5
-50%154
-22.61%2
Infinity%+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed