Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wernst committed Oct 8, 2021
0 parents commit 0b6532b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
Empty file added .gitignore
Empty file.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 2,
"printWidth": 80
}
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## aspen-agent-javascript-starter

A template for setting up an Aspen agent with Javascript.

### Getting started

If you haven't already download the Aspen cli

```
yarn global add aspen
# or
npm install -g aspen
# and login
aspen login
```

And initialize your agent project

```
aspen agent:init [<path_to_project>]
```

### Counter agent

Along with this project comes a counter agent, which you can increment until you reach space...or beyond.

See how to interact with agents in the documentation (TODO).
5 changes: 5 additions & 0 deletions aspen.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Analytics Demo",
"source": "counter"
// "buildDirectory": "./dist" /* Specify where the build output will go */
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "aspen-agent-javascript-starter",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
35 changes: 35 additions & 0 deletions src/index.agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const agent = {
name: 'Analytics Demo',
sourceId: 'counter',
aggregations: {
count: {
reducer: (count, _item) => (typeof count === 'number' ? count + 1 : 1),
startWith: 0,
},
},
actions: {
increment: async (aspen, _params) => {
await aspen.appendToLog('counter');
},
count: async (aspen, _params) => {
const count = await aspen.getAggregation('counter', 'count');
let message = '';

if (count > 10)
message = "Ground control to Major Tom?...We've lost contact";
else if (count > 8) message = 'Edge of the galaxy';
else if (count > 6) message = 'In orbit';
else if (count > 4) message = "Exiting Earth's atmosphere";
else if (count > 2) message = 'In the clouds';
else if (count > 0) message = 'We have liftoff';
else message = 'Ready for launch';

return {
count,
message,
};
},
},
};

module.exports = agent;

0 comments on commit 0b6532b

Please sign in to comment.