@indra.ai/deva 1.64.7 → 1.64.8

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 CHANGED
@@ -224,6 +224,7 @@ class Deva {
224
224
  for (const pending of this._pending) {
225
225
  clearTimeout(pending.timer);
226
226
  if (this.events) this.ignore(pending.evt, pending.handler);
227
+ pending.resolve(this._messages.offline); // the Deva is going offline so answer the waiting caller.
227
228
  }
228
229
  this._pending.clear();
229
230
  }
@@ -767,7 +768,7 @@ class Deva {
767
768
  this.action('ask', `${key}:${id.uid}`);
768
769
  this.intent('good', `ask:${key}:${id.uid}`);
769
770
  const evt = `${key}:ask:${packet.id.uid}`; // the once event keyed to this packet.
770
- const pending = {evt, handler: false, timer: false}; // tracked so shutdown can clean up.
771
+ const pending = {evt, handler: false, timer: false, resolve}; // tracked so shutdown can clean up.
771
772
 
772
773
  // single place to release the listener, the timer, and the pending record.
773
774
  const release = () => {
@@ -1007,11 +1008,14 @@ class Deva {
1007
1008
  this.state('valid', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1008
1009
  this.intent('good', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1009
1010
  this.talk(`${agent.key}:ask:${packet.id.uid}`, packet_stamped);
1011
+
1010
1012
  }).catch(err => {
1011
1013
  this.action('talk', `${agent.key}:${key}:${method}:err:${packet.id.uid}`);
1012
1014
  this.state('catch', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1013
1015
  this.intent('bad', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1016
+ // reply on the asker's event so the asker hears the error right away.
1014
1017
  this.talk(`${agent.key}:${key}:${packet.id.uid}`, {error:err});
1018
+ // log the error here; the asker owns the reject.
1015
1019
  return this.err(err, packet, () => {});
1016
1020
  })
1017
1021
  }
@@ -1020,7 +1024,7 @@ class Deva {
1020
1024
  this.state('catch', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1021
1025
  this.intent('bad', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1022
1026
  this.talk(`${agent.key}:${key}:${packet.id.uid}`, {error:e});
1023
- return this.err(e, packet, () => {})
1027
+ return this.err(e, packet, () => {});
1024
1028
  }
1025
1029
  // now when we ask the meta params[0] should be the method
1026
1030
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "31711622713594414221",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.64.7",
4
+ "version": "1.64.8",
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",
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ // Deva Core Test Suite: step 6, stop and the shutdown chain
3
+ // Copyright ©2000-2026 Quinn Michaels; All rights reserved.
4
+ // Owner Signature Required For Lawful Use.
5
+ // Distributed under VLA:31711622713594414221 LICENSE.md
6
+
7
+ import test from 'node:test';
8
+ import assert from 'node:assert/strict';
9
+ import {build, client} from './_deva.js';
10
+
11
+ const TIERS = ['md5', 'sha256', 'sha512'];
12
+ const CHAIN = ['stop', 'close', 'leave', 'exit', 'shutdown'];
13
+ const fresh = () => structuredClone(client);
14
+
15
+ test('stop() answers offline before init()', async () => {
16
+ const deva = build();
17
+ assert.equal(await deva.stop(), deva._messages.offline);
18
+ });
19
+
20
+ test('stop() runs the full chain and resolves the stamped stop data', async () => {
21
+ const deva = build();
22
+ await deva.init(fresh());
23
+ const agent = deva.agent();
24
+ const clientHash = deva.client().sha256;
25
+ const data = await deva.stop();
26
+
27
+ assert.equal(data.key, 'shutdown', 'the last step sets the key');
28
+ assert.equal(data.value, agent.key);
29
+ assert.equal(data.agent, agent.sha256);
30
+ assert.equal(data.client, clientHash);
31
+ for (const t of TIERS) assert.equal(typeof data[t], 'string', `stop data ${t}`);
32
+ // every step stamps its time, in chain order.
33
+ for (let i = 0; i < CHAIN.length; i++) {
34
+ assert.equal(typeof data[CHAIN[i]], 'number', `${CHAIN[i]} time`);
35
+ if (i) assert.ok(data[CHAIN[i]] >= data[CHAIN[i - 1]], `${CHAIN[i]} after ${CHAIN[i - 1]}`);
36
+ }
37
+ });
38
+
39
+ test('each step talks its devacore event in chain order', async () => {
40
+ const deva = build();
41
+ await deva.init(fresh());
42
+ const heard = [];
43
+ for (const key of CHAIN) deva.events.on(deva._events[key], packet => heard.push(packet.key));
44
+ await deva.stop();
45
+ assert.deepEqual(heard, CHAIN);
46
+ });
47
+
48
+ test('the on hooks run in chain order and the Deva is cleared by onShutdown', async () => {
49
+ const order = [];
50
+ const next = {onStop: 'close', onClose: 'leave', onLeave: 'exit', onExit: 'shutdown'};
51
+ const hooks = {};
52
+ for (const name of [...Object.keys(next), 'onShutdown']) {
53
+ hooks[name] = function (data, resolve) {
54
+ order.push([name, Boolean(this._active)]);
55
+ return next[name] ? this[next[name]](data, resolve) : resolve(data);
56
+ };
57
+ }
58
+ const deva = build(hooks);
59
+ await deva.init(fresh());
60
+ await deva.stop();
61
+ assert.deepEqual(order, [
62
+ ['onStop', true], ['onClose', true], ['onLeave', true], ['onExit', true],
63
+ ['onShutdown', false], // shutdown clears _active before its hook runs.
64
+ ]);
65
+ });
66
+
67
+ test('after stop the Deva is offline and its cleared features are false', async () => {
68
+ const deva = build();
69
+ await deva.init(fresh());
70
+ await deva.stop();
71
+ assert.equal(deva._active, false);
72
+ for (const item of ['_license', '_security', '_support', '_services', '_systems', '_config', 'events']) {
73
+ assert.equal(deva[item], false, `${item} cleared`);
74
+ }
75
+ assert.equal(await deva.question('/hello'), deva._messages.offline);
76
+ assert.equal(await deva.stop(), deva._messages.offline, 'a second stop is offline');
77
+ });
78
+
79
+ test('stop removes every listener this Deva put on the event bus', async () => {
80
+ const deva = build();
81
+ await deva.init(fresh());
82
+ const bus = deva.events;
83
+ assert.ok(bus.eventNames().length > 0, 'init added listeners');
84
+ await deva.stop();
85
+ assert.deepEqual(bus.eventNames(), [], 'nothing left on the bus');
86
+ });
87
+
88
+ test('a pending ask at shutdown answers offline and leaves nothing behind', async () => {
89
+ const deva = build({config: {hash: {}, timeout: {ask: 0}}}); // no timeout, so only shutdown can end it.
90
+ await deva.init(fresh());
91
+ const bus = deva.events;
92
+ const silent = () => {};
93
+ bus.on('silent:ask', silent);
94
+ const asked = deva.question('#silent shout hi');
95
+ await new Promise(r => setImmediate(r)); // let the ask get on the bus.
96
+ assert.equal(deva._pending.size, 1, 'the ask is waiting');
97
+ await deva.stop();
98
+ assert.equal(await asked, deva._messages.offline, 'the waiting caller is answered');
99
+ assert.equal(deva._pending.size, 0);
100
+ bus.removeListener('silent:ask', silent);
101
+ assert.deepEqual(bus.eventNames(), []);
102
+ });