@indra.ai/deva 1.1.82 → 1.1.84
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/config.json +12 -0
- package/index.js +20 -21
- package/package.json +1 -1
package/config.json
CHANGED
|
@@ -13,6 +13,18 @@
|
|
|
13
13
|
"lib",
|
|
14
14
|
"_agent"
|
|
15
15
|
],
|
|
16
|
+
"events": {
|
|
17
|
+
"prompt": "devacore:prompt",
|
|
18
|
+
"error": "devacore:error",
|
|
19
|
+
"question": "devacore:question",
|
|
20
|
+
"answer": "devacore:answer",
|
|
21
|
+
"state": "devacore:state",
|
|
22
|
+
"zone": "devacore:zone",
|
|
23
|
+
"action": "devacore:action",
|
|
24
|
+
"feature": "devacore:feature",
|
|
25
|
+
"load": "devacore:load",
|
|
26
|
+
"unload": "devacore:unload"
|
|
27
|
+
},
|
|
16
28
|
"state": "offline",
|
|
17
29
|
"states": {
|
|
18
30
|
"ask": "asking another",
|
package/index.js
CHANGED
|
@@ -61,6 +61,7 @@ class Deva {
|
|
|
61
61
|
this._messages = {
|
|
62
62
|
notext: 'NO TEXT WAS PROVIDED',
|
|
63
63
|
nopacket: 'NO PACKET WAS PROVIDED',
|
|
64
|
+
method_not_found: 'METHOD NOT FOUND',
|
|
64
65
|
}; // set the messages from config
|
|
65
66
|
|
|
66
67
|
// then here we are going to loop the messages config to make sure custom values are set
|
|
@@ -772,7 +773,8 @@ class Deva {
|
|
|
772
773
|
packet.q.meta.hash = this.hash(packet.q);
|
|
773
774
|
|
|
774
775
|
this.action(_action);
|
|
775
|
-
this.talk(
|
|
776
|
+
this.talk(`${key}:question`, this.copy(packet)); // key question event make sure to copy data.
|
|
777
|
+
this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
|
|
776
778
|
|
|
777
779
|
if (isAsk) { // isAsk check if the question isAsk and talk
|
|
778
780
|
this.state('ask');
|
|
@@ -851,7 +853,8 @@ class Deva {
|
|
|
851
853
|
|
|
852
854
|
|
|
853
855
|
this.action('answer_talk');
|
|
854
|
-
this.talk(
|
|
856
|
+
this.talk(`${agent.key}:answer`, this.copy(packet)); // agent key answer event
|
|
857
|
+
this.talk(config.events.answer, this.copy(packet)); // global talk event
|
|
855
858
|
|
|
856
859
|
return resolve(this.copy(packet)); // resolve the packet to the caller.
|
|
857
860
|
}).catch(err => { // catch any errors in the method
|
|
@@ -880,8 +883,8 @@ class Deva {
|
|
|
880
883
|
this.state('ask');
|
|
881
884
|
this.action('ask');
|
|
882
885
|
|
|
883
|
-
const agent = this.agent()
|
|
884
|
-
const client = this.client()
|
|
886
|
+
const agent = this.agent();
|
|
887
|
+
const client = this.client();
|
|
885
888
|
// build the answer packet from this model
|
|
886
889
|
packet.a = {
|
|
887
890
|
agent,
|
|
@@ -901,8 +904,7 @@ class Deva {
|
|
|
901
904
|
if (typeof this.methods[packet.q.meta.method] !== 'function') {
|
|
902
905
|
return setImmediate(() => {
|
|
903
906
|
this.action('invalid')
|
|
904
|
-
|
|
905
|
-
this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
|
|
907
|
+
this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
|
|
906
908
|
});
|
|
907
909
|
}
|
|
908
910
|
|
|
@@ -918,16 +920,17 @@ class Deva {
|
|
|
918
920
|
packet.a.text = result;
|
|
919
921
|
}
|
|
920
922
|
this.action('ask_answer');
|
|
921
|
-
this.talk(`${
|
|
923
|
+
this.talk(`${agent.key}:answer`, this.copy(packet));
|
|
924
|
+
this.talk(`${agent.key}:ask:${packet.id}`, packet);
|
|
922
925
|
}).catch(err => {
|
|
923
926
|
this.action('error');
|
|
924
|
-
this.talk(`${
|
|
927
|
+
this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
|
|
925
928
|
return this.error(err, packet);
|
|
926
929
|
})
|
|
927
930
|
}
|
|
928
931
|
catch (e) {
|
|
929
932
|
this.action('error');
|
|
930
|
-
this.talk(`${
|
|
933
|
+
this.talk(`${agent.key}:ask:${packet.id}`, {error:e});
|
|
931
934
|
return this.error(e, packet)
|
|
932
935
|
}
|
|
933
936
|
// now when we ask the meta params[0] should be the method
|
|
@@ -1166,7 +1169,7 @@ class Deva {
|
|
|
1166
1169
|
created: Date.now(),
|
|
1167
1170
|
};
|
|
1168
1171
|
_data.hash = this.hash(_data);
|
|
1169
|
-
this.talk(
|
|
1172
|
+
this.talk(config.events.state, _data);
|
|
1170
1173
|
} catch (e) {
|
|
1171
1174
|
return this.error(e);
|
|
1172
1175
|
}
|
|
@@ -1202,7 +1205,7 @@ class Deva {
|
|
|
1202
1205
|
created: Date.now(),
|
|
1203
1206
|
};
|
|
1204
1207
|
_data.hash = this.hash(_data);
|
|
1205
|
-
this.talk('
|
|
1208
|
+
this.talk('', _data);
|
|
1206
1209
|
} catch (e) {
|
|
1207
1210
|
return this.error(e);
|
|
1208
1211
|
}
|
|
@@ -1229,7 +1232,7 @@ class Deva {
|
|
|
1229
1232
|
created: Date.now(),
|
|
1230
1233
|
};
|
|
1231
1234
|
_data.hash = this.hash(_data);
|
|
1232
|
-
this.talk(
|
|
1235
|
+
this.talk(config.events.action, _data);
|
|
1233
1236
|
} catch (e) {
|
|
1234
1237
|
return this.error(e)
|
|
1235
1238
|
}
|
|
@@ -1256,7 +1259,7 @@ class Deva {
|
|
|
1256
1259
|
created: Date.now(),
|
|
1257
1260
|
};
|
|
1258
1261
|
_data.hash = this.hash(_data);
|
|
1259
|
-
this.talk(
|
|
1262
|
+
this.talk(config.events.feature, _data);
|
|
1260
1263
|
} catch (e) {
|
|
1261
1264
|
return this.error(e);
|
|
1262
1265
|
}
|
|
@@ -1515,7 +1518,7 @@ class Deva {
|
|
|
1515
1518
|
return new Promise((resolve, reject) => {
|
|
1516
1519
|
this.state('load');
|
|
1517
1520
|
this.devas[key].init(client).then(loaded => {
|
|
1518
|
-
this.talk(
|
|
1521
|
+
this.talk(config.events.load, {
|
|
1519
1522
|
id:this.uid(true),
|
|
1520
1523
|
key,
|
|
1521
1524
|
created: Date.now(),
|
|
@@ -1539,11 +1542,7 @@ class Deva {
|
|
|
1539
1542
|
this.state('uload');
|
|
1540
1543
|
this.devas[key].stop().then(exit => {
|
|
1541
1544
|
delete this.devas[key];
|
|
1542
|
-
this.talk(
|
|
1543
|
-
id:this.uid(true),
|
|
1544
|
-
key,
|
|
1545
|
-
created: Date.now(),
|
|
1546
|
-
});
|
|
1545
|
+
this.talk(config.events.unload, key);
|
|
1547
1546
|
});
|
|
1548
1547
|
return resolve(this._messages.states.unload);
|
|
1549
1548
|
} catch (e) {
|
|
@@ -1678,7 +1677,7 @@ class Deva {
|
|
|
1678
1677
|
text,
|
|
1679
1678
|
created: Date.now(),
|
|
1680
1679
|
}
|
|
1681
|
-
return this.talk(
|
|
1680
|
+
return this.talk(config.events.prompt, _data);
|
|
1682
1681
|
}
|
|
1683
1682
|
|
|
1684
1683
|
|
|
@@ -1841,7 +1840,7 @@ class Deva {
|
|
|
1841
1840
|
data,
|
|
1842
1841
|
created: Date.now(),
|
|
1843
1842
|
}
|
|
1844
|
-
this.talk(
|
|
1843
|
+
this.talk(config.events.error, this.copy(_data));
|
|
1845
1844
|
|
|
1846
1845
|
const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
|
|
1847
1846
|
if (hasOnError) return this.onError(err, data, reject);
|