Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aagent.js

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aagent.js - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

index.js

20

package.json
{
"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"
}
}

@@ -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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc