@indra.ai/deva 1.55.0 → 1.56.0
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 +42 -44
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -859,52 +859,50 @@ class Deva {
|
|
|
859
859
|
// if: isAsk wait for the once event which is key'd to the packet ID for specified responses
|
|
860
860
|
this.action('ask', `${key}:${id.uid}`);
|
|
861
861
|
this.intent('good', `ask:${key}:${id.uid}`);
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
pending.
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
if (!this._active) return; // shutdown already cleaned up.
|
|
892
|
-
release();
|
|
893
|
-
this.state('abort', `${key}:${method}:${id.uid}`);
|
|
894
|
-
this.intent('bad', `ask:${key}:${id.uid}`);
|
|
895
|
-
return resolve(this._messages.asktimeout);
|
|
896
|
-
}, wait);
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
// talk returns false when nobody is listening so fail fast instead of waiting.
|
|
900
|
-
const heard = this.talk(`${key}:ask`, this.lib.copy(packet));
|
|
901
|
-
if (!heard) {
|
|
862
|
+
const evt = `${key}:ask:${packet.id.uid}`; // the once event keyed to this packet.
|
|
863
|
+
const pending = {evt, handler: false, timer: false}; // tracked so shutdown can clean up.
|
|
864
|
+
|
|
865
|
+
// single place to release the listener, the timer, and the pending record.
|
|
866
|
+
const release = () => {
|
|
867
|
+
clearTimeout(pending.timer);
|
|
868
|
+
this._pending.delete(pending);
|
|
869
|
+
if (this.events) this.ignore(evt, pending.handler);
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
pending.handler = answer => {
|
|
873
|
+
clearTimeout(pending.timer); // an answer arrived so cancel the timeout.
|
|
874
|
+
this._pending.delete(pending);
|
|
875
|
+
this.action('talk', `${this._events.ask}:${id.uid}`);
|
|
876
|
+
this.intent('good', `${this._events.ask}:${id.uid}`);
|
|
877
|
+
this.talk(this._events.ask, this.lib.copy(answer));
|
|
878
|
+
this.action('return', `finish:${key}:ask:${id.uid}`);
|
|
879
|
+
this.intent('good', `finish:${method}:${id.uid}`);
|
|
880
|
+
return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
this._pending.add(pending);
|
|
884
|
+
this.once(evt, pending.handler);
|
|
885
|
+
|
|
886
|
+
// timeout so a silent Deva cannot hang the caller. 0 disables it.
|
|
887
|
+
const wait = this._config.timeout.ask;
|
|
888
|
+
if (wait > 0) {
|
|
889
|
+
pending.timer = setTimeout(() => {
|
|
890
|
+
if (!this._active) return; // shutdown already cleaned up.
|
|
902
891
|
release();
|
|
903
|
-
this.state('
|
|
892
|
+
this.state('abort', `${key}:${method}:${id.uid}`);
|
|
904
893
|
this.intent('bad', `ask:${key}:${id.uid}`);
|
|
905
|
-
return resolve(this._messages.
|
|
906
|
-
}
|
|
907
|
-
}
|
|
894
|
+
return resolve(this._messages.asktimeout);
|
|
895
|
+
}, wait);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// talk returns false when nobody is listening so fail fast instead of waiting.
|
|
899
|
+
const heard = this.talk(`${key}:ask`, this.lib.copy(packet));
|
|
900
|
+
if (!heard) {
|
|
901
|
+
release();
|
|
902
|
+
this.state('invalid', `${key}:${method}:${id.uid}`);
|
|
903
|
+
this.intent('bad', `ask:${key}:${id.uid}`);
|
|
904
|
+
return resolve(this._messages.noask);
|
|
905
|
+
}
|
|
908
906
|
}
|
|
909
907
|
else { // else: answer the question locally
|
|
910
908
|
this.state('answer', `${method}:${id.uid}`); //set the answer state to the method
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "23221940810208468106",
|
|
3
3
|
"name": "@indra.ai/deva",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.56.0",
|
|
5
5
|
"description": "Deva Core a Vedic-inspired Event Based Context Aware Feature, Zone, Action, and State Machine integrated Artificial Intelligence Framework",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"license": "VLA:23221940810208468106 LICENSE.md",
|