@indra.ai/deva 1.64.5 → 1.64.7

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
@@ -779,6 +779,14 @@ class Deva {
779
779
  pending.handler = answer => {
780
780
  clearTimeout(pending.timer); // an answer arrived so cancel the timeout.
781
781
  this._pending.delete(pending);
782
+
783
+ // the asked Deva failed so the asker handles the error like a local method error.
784
+ if (answer.error) {
785
+ this.state('catch', `${key}:${method}:${id.uid}`);
786
+ this.intent('bad', `ask:${key}:${id.uid}`);
787
+ return this.err(answer.error, packet, reject);
788
+ }
789
+
782
790
  this.action('talk', `${this._events.ask}:${id.uid}`);
783
791
  this.intent('good', `${this._events.ask}:${id.uid}`);
784
792
  this.talk(this._events.ask, this.lib.copy(answer));
@@ -1003,16 +1011,16 @@ class Deva {
1003
1011
  this.action('talk', `${agent.key}:${key}:${method}:err:${packet.id.uid}`);
1004
1012
  this.state('catch', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1005
1013
  this.intent('bad', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1006
- this.talk(`${agent.key}:${key}:${method}:${packet.id.uid}`, {error:err});
1007
- return this.err(err, packet);
1014
+ this.talk(`${agent.key}:${key}:${packet.id.uid}`, {error:err});
1015
+ return this.err(err, packet, () => {});
1008
1016
  })
1009
1017
  }
1010
1018
  catch (e) {
1011
1019
  this.action('talk', `${agent.key}:${key}:${method}:err:${packet.id.uid}`);
1012
1020
  this.state('catch', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1013
1021
  this.intent('bad', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1014
- this.talk(`${agent.key}:ask:${packet.id.uid}`, {error:e});
1015
- return this.err(e, packet)
1022
+ this.talk(`${agent.key}:${key}:${packet.id.uid}`, {error:e});
1023
+ return this.err(e, packet, () => {})
1016
1024
  }
1017
1025
  // now when we ask the meta params[0] should be the method
1018
1026
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "31711622713594414221",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.64.5",
4
+ "version": "1.64.7",
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,122 @@
1
+ "use strict";
2
+ // Deva Core Test Suite: step 5, commands, ask and answers
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, agent} from './_deva.js';
10
+
11
+ const TIERS = ['md5', 'sha256', 'sha512'];
12
+ const fresh = () => structuredClone(client);
13
+ const stamped = (obj, label) => { for (const t of TIERS) assert.equal(typeof obj[t], 'string', `${label} ${t}`); };
14
+
15
+ // a child Deva that answers #helper shout
16
+ const helper = () => build({
17
+ agent: {...agent, id: 'helper', key: 'helper', profile: {...agent.profile, name: 'Helper'}},
18
+ methods: {
19
+ shout: packet => Promise.resolve({text: packet.q.text.toUpperCase()}),
20
+ fail: () => Promise.reject(new Error('helper failed')),
21
+ throws: () => { throw new Error('helper threw'); },
22
+ },
23
+ });
24
+
25
+
26
+ // the parent Deva under test
27
+ const deva = build({
28
+ config: {hash: {}, timeout: {ask: 200}},
29
+ devas: {helper: helper()},
30
+ methods: {
31
+ greet: packet => Promise.resolve({text: `hello ${packet.q.text}`, data: {to: packet.q.text}}),
32
+ plain: () => Promise.resolve('just text'),
33
+ },
34
+ });
35
+
36
+ test('question() answers offline before init()', async () => {
37
+ assert.equal(await deva.question('/greet world'), deva._messages.offline);
38
+ });
39
+
40
+ test.describe('after init', () => {
41
+ test.before(async () => { await deva.init(fresh()); });
42
+ test.after(async () => { await deva.stop(); });
43
+
44
+ test('question() with no text answers the no text message', async () => {
45
+ assert.equal(await deva.question(), deva._messages.notext);
46
+ });
47
+
48
+ test('a /command runs the local method and returns a stamped q and a packet', async () => {
49
+ const packet = await deva.question('/greet world');
50
+ assert.equal(packet.q.meta.method, 'greet');
51
+ assert.equal(packet.q.text, 'world');
52
+ assert.equal(packet.a.text, 'hello world');
53
+ assert.deepEqual(packet.a.data, {to: 'world'});
54
+ assert.equal(packet.a.meta.key, deva.agent().key);
55
+ stamped(packet.q, 'q');
56
+ stamped(packet.a, 'a');
57
+ });
58
+
59
+ test('a method that returns plain text sets a.text and leaves data false', async () => {
60
+ const packet = await deva.question('/plain');
61
+ assert.equal(packet.a.text, 'just text');
62
+ assert.equal(packet.a.data, false);
63
+ });
64
+
65
+ test('an unknown /command answers method not found', async () => {
66
+ const result = await deva.question('/nope here');
67
+ assert.match(result.a.text, new RegExp(`^${deva._messages.method_not_found}`));
68
+ assert.equal(result.a.meta.method, 'nope');
69
+ });
70
+
71
+ test('the question event broadcasts the packet', async () => {
72
+ let heard = false;
73
+ const on = packet => { heard = packet; };
74
+ deva.events.once('devacore:question', on);
75
+ await deva.question('/greet event');
76
+ assert.equal(heard.q.text, 'event');
77
+ });
78
+
79
+ test('#helper shout asks the child Deva and returns its stamped answer', async () => {
80
+ const packet = await deva.question('#helper shout hi there');
81
+ assert.equal(packet.a.text, 'HI THERE');
82
+ assert.equal(packet.a.meta.key, 'helper');
83
+ assert.equal(packet.a.meta.method, 'shout');
84
+ stamped(packet.a, 'a');
85
+ stamped(packet, 'packet');
86
+ assert.equal(deva._pending.size, 0, 'no pending asks left');
87
+ });
88
+
89
+ test('#helper with an unknown method answers method not found from the child', async () => {
90
+ const result = await deva.question('#helper nope hi');
91
+ assert.match(result.a.text, new RegExp(`^${deva._messages.method_not_found} helper nope`));
92
+ });
93
+
94
+ test('#helper fail rejects the asker right away with the child error', async () => {
95
+ const started = Date.now();
96
+ await assert.rejects(deva.question('#helper fail hi'), {message: 'helper failed'});
97
+ assert.ok(Date.now() - started < 150, 'did not wait for the ask timeout');
98
+ assert.equal(deva._pending.size, 0, 'the error cleans up the pending ask');
99
+ });
100
+
101
+ test('#helper throws rejects the asker right away with the child error', async () => {
102
+ await assert.rejects(deva.question('#helper throws hi'), {message: 'helper threw'});
103
+ assert.equal(deva._pending.size, 0, 'the error cleans up the pending ask');
104
+ });
105
+
106
+ test('#nobody resolves right away with ask target not found', async () => {
107
+ const started = Date.now();
108
+ assert.equal(await deva.question('#nobody shout hi'), deva._messages.noask);
109
+ assert.ok(Date.now() - started < 150, 'fails fast, before the ask timeout');
110
+ assert.equal(deva._pending.size, 0);
111
+ });
112
+
113
+ test('a silent ask target resolves with ask timeout after config.timeout.ask', async () => {
114
+ const silent = () => {};
115
+ deva.events.on('silent:ask', silent);
116
+ const started = Date.now();
117
+ assert.equal(await deva.question('#silent shout hi'), deva._messages.asktimeout);
118
+ assert.ok(Date.now() - started >= 190, 'waited for the timeout');
119
+ assert.equal(deva._pending.size, 0, 'timeout cleans up the pending ask');
120
+ deva.events.removeListener('silent:ask', silent);
121
+ });
122
+ });