-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0b6532b
Showing
6 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"printWidth": 80 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |