@indra.ai/deva 1.64.4 → 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 +12 -4
- package/package.json +1 -1
- package/tests/suite/04-license.test.js +74 -0
- package/tests/suite/05-messaging.test.js +122 -0
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}:${
|
|
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}
|
|
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.
|
|
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,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Deva Core Test Suite: step 4, the VLA license check
|
|
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 {createHash} from 'node:crypto';
|
|
10
|
+
import {build, client, pkg} from './_deva.js';
|
|
11
|
+
|
|
12
|
+
const TIERS = ['md5', 'sha256', 'sha512'];
|
|
13
|
+
const digest = (data, algo) => createHash(algo).update(JSON.stringify(data)).digest('base64');
|
|
14
|
+
const fresh = (changes = {}) => ({...structuredClone(client), ...changes});
|
|
15
|
+
const wait = ms => new Promise(res => setTimeout(res, ms));
|
|
16
|
+
|
|
17
|
+
test('the test client carries the same VLA as the package', () => {
|
|
18
|
+
assert.deepEqual(client.VLA, pkg.VLA);
|
|
19
|
+
assert.equal(pkg.VLA.uid, '31711622713594414221');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('a good VLA activates the Deva and init() reaches ready', async () => {
|
|
23
|
+
const deva = build();
|
|
24
|
+
const data = await deva.init(fresh());
|
|
25
|
+
assert.ok(deva._active, 'Deva is active');
|
|
26
|
+
assert.equal(typeof data.ready, 'number');
|
|
27
|
+
await deva.stop();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('license_check() approves a matching VLA with stamped hashes', async () => {
|
|
31
|
+
const deva = build();
|
|
32
|
+
await deva.init(fresh());
|
|
33
|
+
const approved = deva.license_check(client.VLA, deva._core.VLA);
|
|
34
|
+
const vla_hash = digest(pkg.VLA, 'sha256');
|
|
35
|
+
assert.equal(typeof approved.id.uid, 'string');
|
|
36
|
+
assert.equal(approved.personal, vla_hash, 'personal is the sha256 of the client VLA');
|
|
37
|
+
assert.equal(approved.package, vla_hash, 'package is the sha256 of the package VLA');
|
|
38
|
+
|
|
39
|
+
// each tier covers the approval plus the tiers before it
|
|
40
|
+
const walk = {...approved};
|
|
41
|
+
for (const t of TIERS) delete walk[t];
|
|
42
|
+
for (const t of TIERS) {
|
|
43
|
+
assert.equal(approved[t], digest(walk, t), t);
|
|
44
|
+
walk[t] = approved[t];
|
|
45
|
+
}
|
|
46
|
+
await deva.stop();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('a changed VLA resolves with the invalid check message and stays inactive', async () => {
|
|
50
|
+
const deva = build();
|
|
51
|
+
const seen = [];
|
|
52
|
+
deva.events.on('devacore:ready', () => seen.push('ready'));
|
|
53
|
+
const VLA = {...structuredClone(client.VLA), uid: '00000000000000000000'};
|
|
54
|
+
const result = await deva.init(fresh({VLA}));
|
|
55
|
+
await wait(100);
|
|
56
|
+
assert.equal(result, deva._messages.checkVLA);
|
|
57
|
+
assert.equal(deva._active, false);
|
|
58
|
+
assert.deepEqual(seen, [], 'no ready event');
|
|
59
|
+
assert.equal(deva.license(), deva._messages.offline, 'getters stay offline');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('a missing client VLA resolves with the personal VLA message and stays inactive', async () => {
|
|
63
|
+
const deva = build();
|
|
64
|
+
const c = fresh();
|
|
65
|
+
delete c.VLA;
|
|
66
|
+
const result = await deva.init(c);
|
|
67
|
+
assert.equal(result, deva._messages.personalVLA);
|
|
68
|
+
assert.equal(deva._active, false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('license_check() with no package VLA returns the package VLA message', () => {
|
|
72
|
+
const deva = build();
|
|
73
|
+
assert.equal(deva.license_check(client.VLA), deva._messages.packageVLA);
|
|
74
|
+
});
|
|
@@ -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
|
+
});
|