@indra.ai/deva 1.64.50 → 1.64.52

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/_data/tests.json CHANGED
@@ -61,7 +61,7 @@
61
61
  "file": "08-error.test.js",
62
62
  "title": "Error",
63
63
  "describe": "err() rejects or hands off to onError without calling context(), talks one stamped error packet, and context() and contexts() read each Deva's own vars.context, falling back safely when it is missing.",
64
- "count": 6
64
+ "count": 10
65
65
  }
66
66
  ],
67
67
  "edgecases": [
package/index.js CHANGED
@@ -71,7 +71,7 @@ class Deva {
71
71
  this._features = config.features; // set the features from config data.
72
72
 
73
73
  this._zone = config.zone; // set the current zone from config data.
74
- this._zones = config.zones; // set the zones from config data.
74
+ this._zones = {...config.zones}; // set the zones from config data.
75
75
  // load any custom zones from the agent file
76
76
  if (this._agent.zones) {
77
77
  for (let item in this._agent.zones) {
@@ -81,7 +81,7 @@ class Deva {
81
81
  }
82
82
 
83
83
  this._action = config.action; // set the action from config data.
84
- this._actions = config.actions; // set the actions from config data.
84
+ this._actions = {...config.actions}; // set the actions from config data.
85
85
  // load any custom actions from the agent file
86
86
  if (this._agent.actions) {
87
87
  for (let item in this._agent.actions) {
@@ -91,7 +91,7 @@ class Deva {
91
91
  }
92
92
 
93
93
  this._state = config.state; // set the current state from config data.
94
- this._states = config.states; // set the states from options
94
+ this._states = {...config.states}; // set the states from options
95
95
  // load any custom states from the agent file
96
96
  if (this._agent.states) {
97
97
  for (let item in this._agent.states) {
@@ -101,7 +101,7 @@ class Deva {
101
101
  }
102
102
 
103
103
  this._intent = config.intent; // set the current intent from config data.
104
- this._intents = config.intents; // set the states from options
104
+ this._intents = {...config.intents}; // set the states from options
105
105
  // load any custom actions from the agent file
106
106
  if (this._agent.intents) {
107
107
  for (let item in this._agent.intents) {
@@ -111,7 +111,7 @@ class Deva {
111
111
  }
112
112
 
113
113
  this._belief = config.belief; // set the current belief from config data.
114
- this._beliefs = config.beliefs; // set the states from options
114
+ this._beliefs = {...config.beliefs}; // set the states from options
115
115
  // load any custom actions from the agent file
116
116
  if (this._agent.beliefs) {
117
117
  for (let item in this._agent.beliefs) {
@@ -122,7 +122,7 @@ class Deva {
122
122
 
123
123
  this._context = config.context || false; // set the local context
124
124
 
125
- this._messages = config.messages; // set the messages from config data.
125
+ this._messages = {...config.messages}; // set the messages from config data.
126
126
  // load any custom actions from the agent file
127
127
  if (this._agent.messages) {
128
128
  for (let item in this._agent.messages) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "31711622713594414221",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.64.50",
4
+ "version": "1.64.52",
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:31711622713594414221 LICENSE.md",
@@ -96,3 +96,49 @@ test('contexts() returns this Deva\'s vars.context, or false when it has none',
96
96
  delete deva.vars.context;
97
97
  assert.equal(deva.contexts().value, false);
98
98
  });
99
+
100
+ // a child Deva whose method rejects, for the ask error test.
101
+ const failing = () => build({
102
+ agent: {...agent, id: 'helper', key: 'helper', profile: {...agent.profile, name: 'Helper'}},
103
+ vars: vars(),
104
+ methods: {fail: () => Promise.reject(new Error('helper failed'))},
105
+ });
106
+ test('a local /command that rejects rejects question() with one error packet', async () => {
107
+ const deva = build({vars: vars(), methods: {rej: () => Promise.reject(new Error('local rej'))}});
108
+ await deva.init(fresh());
109
+ const heard = [];
110
+ deva.events.on(deva._events.error, packet => heard.push(packet));
111
+ await assert.rejects(deva.question('/rej hi'), {message: 'local rej'});
112
+ assert.equal(heard.length, 1, 'one error packet');
113
+ assert.equal(heard[0].error.message, 'local rej');
114
+ assert.equal(heard[0].packet.q.meta.method, 'rej', 'the error carries the question packet');
115
+ assert.equal(deva._pending.size, 0);
116
+ await deva.stop();
117
+ });
118
+ test('a local /command that throws rejects question() the same way', async () => {
119
+ const deva = build({vars: vars(), methods: {thr: () => { throw new Error('local thr'); }}});
120
+ await deva.init(fresh());
121
+ const heard = [];
122
+ deva.events.on(deva._events.error, packet => heard.push(packet));
123
+ await assert.rejects(deva.question('/thr hi'), {message: 'local thr'});
124
+ assert.equal(heard.length, 1, 'one error packet');
125
+ assert.equal(heard[0].error.message, 'local thr');
126
+ await deva.stop();
127
+ });
128
+ test('a child ask error is logged by both the child and the asker', async () => {
129
+ const deva = build({vars: vars(), config: {hash: {}, timeout: {ask: 200}}, devas: {helper: failing()}});
130
+ await deva.init(fresh());
131
+ const heard = [];
132
+ deva.events.on(deva._events.error, packet => heard.push(packet));
133
+ await assert.rejects(deva.question('#helper fail hi'), {message: 'helper failed'});
134
+ assert.equal(heard.length, 2, 'two error packets');
135
+ assert.deepEqual(heard.map(p => p.value).sort(), [deva.agent().key, 'helper'].sort(), 'one from each Deva');
136
+ for (const p of heard) assert.equal(p.error.message, 'helper failed');
137
+ await deva.stop();
138
+ });
139
+ test('Feature() with an unknown feature rejects with invalid feature', async () => {
140
+ const deva = build({vars: vars()});
141
+ await deva.init(fresh());
142
+ await assert.rejects(new Promise((resolve, reject) => deva.Feature('nope', resolve, reject)), e => e === deva._messages.invalidfeature);
143
+ await deva.stop();
144
+ });