@indra.ai/deva 1.1.101 → 1.1.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +29 -30
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -959,12 +959,12 @@ class Deva {
|
|
|
959
959
|
init(client) {
|
|
960
960
|
// set client
|
|
961
961
|
this._active = Date.now();
|
|
962
|
-
|
|
962
|
+
const agent = this.agent();
|
|
963
963
|
const _data = {
|
|
964
964
|
id: this.uid(true),
|
|
965
|
-
key: '
|
|
966
|
-
value:
|
|
967
|
-
agent
|
|
965
|
+
key: 'init',
|
|
966
|
+
value: agent.key,
|
|
967
|
+
agent,
|
|
968
968
|
client: this.copy(client),
|
|
969
969
|
text: this._messages.states.start,
|
|
970
970
|
created: Date.now(),
|
|
@@ -1058,7 +1058,7 @@ class Deva {
|
|
|
1058
1058
|
data.hash = this.hash(data);
|
|
1059
1059
|
this.action(data.value)
|
|
1060
1060
|
const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
|
|
1061
|
-
return hasOnDone ? this.onDone(data) :
|
|
1061
|
+
return hasOnDone ? this.onDone(data) : this.finish(data);
|
|
1062
1062
|
}
|
|
1063
1063
|
|
|
1064
1064
|
/**************
|
|
@@ -1076,7 +1076,11 @@ class Deva {
|
|
|
1076
1076
|
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1077
1077
|
this.state('finish');
|
|
1078
1078
|
this.action('finish');
|
|
1079
|
-
|
|
1079
|
+
const hasOnFinish = this.onFinish && typeof this.onFinish === 'function' ? true : false;
|
|
1080
|
+
if (hasOnFinish) return this.onFinish(packet, resolve);
|
|
1081
|
+
else if (resolve) return resolve(packet);
|
|
1082
|
+
else return Promise.resolve(packet)
|
|
1083
|
+
return resolve ? resolve(packet) : Promise.resolve(packet);
|
|
1080
1084
|
}
|
|
1081
1085
|
|
|
1082
1086
|
/**************
|
|
@@ -1095,12 +1099,14 @@ class Deva {
|
|
|
1095
1099
|
stop() {
|
|
1096
1100
|
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1097
1101
|
this.state('stop');
|
|
1102
|
+
const agent = this.agent();
|
|
1103
|
+
const client = this.client();
|
|
1098
1104
|
const data = {
|
|
1099
1105
|
id: this.uid(true),
|
|
1100
|
-
key: '
|
|
1101
|
-
value:
|
|
1102
|
-
agent
|
|
1103
|
-
client
|
|
1106
|
+
key: 'stop',
|
|
1107
|
+
value: agent.key,
|
|
1108
|
+
agent,
|
|
1109
|
+
client,
|
|
1104
1110
|
text: this._messages.states.stop,
|
|
1105
1111
|
created: Date.now(),
|
|
1106
1112
|
}
|
|
@@ -1541,19 +1547,8 @@ class Deva {
|
|
|
1541
1547
|
This function will enable fast loading of Deva into a system.
|
|
1542
1548
|
***************/
|
|
1543
1549
|
load(key, client) {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
this.devas[key].init(client).then(loaded => {
|
|
1547
|
-
this.talk(config.events.load, {
|
|
1548
|
-
id:this.uid(true),
|
|
1549
|
-
key,
|
|
1550
|
-
created: Date.now(),
|
|
1551
|
-
});
|
|
1552
|
-
return this.finish(this._messages.states.load, resolve);
|
|
1553
|
-
}).catch(err => {
|
|
1554
|
-
return this.error(err, deva, reject);
|
|
1555
|
-
})
|
|
1556
|
-
});
|
|
1550
|
+
this.state('load');
|
|
1551
|
+
return this.devas[key].init(client);
|
|
1557
1552
|
}
|
|
1558
1553
|
|
|
1559
1554
|
/**************
|
|
@@ -1670,12 +1665,14 @@ class Deva {
|
|
|
1670
1665
|
***************/
|
|
1671
1666
|
prompt(text) {
|
|
1672
1667
|
// Talk a global prompt event for the client
|
|
1668
|
+
const agent = this.agent();
|
|
1669
|
+
const client = this.client();
|
|
1673
1670
|
const _data = {
|
|
1674
1671
|
id: this.uid(true),
|
|
1675
1672
|
key: 'prompt',
|
|
1676
|
-
value:
|
|
1677
|
-
agent
|
|
1678
|
-
client
|
|
1673
|
+
value: agent.key,
|
|
1674
|
+
agent,
|
|
1675
|
+
client,
|
|
1679
1676
|
text,
|
|
1680
1677
|
created: Date.now(),
|
|
1681
1678
|
}
|
|
@@ -1915,12 +1912,14 @@ class Deva {
|
|
|
1915
1912
|
console.log('\n::END:DATA\n');
|
|
1916
1913
|
}
|
|
1917
1914
|
|
|
1915
|
+
const agent = this.agent();
|
|
1916
|
+
const client = this.client();
|
|
1918
1917
|
const _data = {
|
|
1919
1918
|
id: this.uid(true),
|
|
1920
|
-
key: '
|
|
1921
|
-
value:
|
|
1922
|
-
agent
|
|
1923
|
-
client
|
|
1919
|
+
key: 'error',
|
|
1920
|
+
value: agent.key,
|
|
1921
|
+
agent,
|
|
1922
|
+
client,
|
|
1924
1923
|
error: err,
|
|
1925
1924
|
data,
|
|
1926
1925
|
created: Date.now(),
|