theprogrammablemind 7.4.1-beta.1 → 7.4.1-beta.3
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/client.js +50 -9
- package/package.json +1 -1
- package/src/config.js +45 -7
package/client.js
CHANGED
@@ -470,13 +470,22 @@ const doWithRetries = async (n, url, queryParams, data) => {
|
|
470
470
|
}
|
471
471
|
}
|
472
472
|
|
473
|
-
const setupProcessB = ({ config }) => {
|
473
|
+
const setupProcessB = ({ config, allowDelta=false } = {}) => {
|
474
474
|
const key = config._key
|
475
475
|
|
476
|
-
const data = Object.assign({ key, version: '3' }, config.
|
477
|
-
|
478
|
-
|
479
|
-
data.
|
476
|
+
const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
|
477
|
+
if (allowDelta && config.allowDelta && config.hasDelta()) {
|
478
|
+
// console.log('config', config)
|
479
|
+
data.delta = config.delta()
|
480
|
+
} else {
|
481
|
+
Object.assign(data, config.config)
|
482
|
+
}
|
483
|
+
|
484
|
+
if (data.namespaces) {
|
485
|
+
for (const uuid of Object.keys(data.namespaces)) {
|
486
|
+
const km = config.configs.find((km) => km.uuid === uuid)
|
487
|
+
data.namespaces[uuid].name = km.name
|
488
|
+
}
|
480
489
|
}
|
481
490
|
|
482
491
|
// const generators = new Generators((data.generators || []).map((g) => new Generator(normalizeGenerator(g))))
|
@@ -529,7 +538,7 @@ const _process = async (config, query, { credentials, writeTests, isTest, saveDe
|
|
529
538
|
throw error
|
530
539
|
}
|
531
540
|
|
532
|
-
|
541
|
+
let { data, /* generators, semantics, */ hierarchy } = setupProcessB({ config, allowDelta: true })
|
533
542
|
let queries = query.split('\\n')
|
534
543
|
|
535
544
|
try {
|
@@ -553,8 +562,28 @@ const _process = async (config, query, { credentials, writeTests, isTest, saveDe
|
|
553
562
|
if (queries.length === 0) {
|
554
563
|
break;
|
555
564
|
}
|
565
|
+
|
556
566
|
data.utterance = queries[0]
|
557
|
-
|
567
|
+
let json = await doWithRetries(retries, url, queryParams, data)
|
568
|
+
let resetData = false
|
569
|
+
if (json.code == 'NOT_IN_CACHE') {
|
570
|
+
resetData = true
|
571
|
+
const setupB = setupProcessB({ config, allowDelta: false })
|
572
|
+
data = setupB.data
|
573
|
+
hierarchy = setupB.hierarchy
|
574
|
+
data.utterance = queries[0]
|
575
|
+
json = await doWithRetries(retries, url, queryParams, data)
|
576
|
+
}
|
577
|
+
if (json.cacheKey) {
|
578
|
+
config.cacheKey = json.cacheKey
|
579
|
+
if (resetData) {
|
580
|
+
if (queries.length > 1) {
|
581
|
+
const setupB = setupProcessB({ config, allowDelta: true })
|
582
|
+
data = setupB.data
|
583
|
+
hierarchy = setupB.hierarchy
|
584
|
+
}
|
585
|
+
}
|
586
|
+
}
|
558
587
|
json.contexts = json.results
|
559
588
|
delete json.results
|
560
589
|
if (json.status !== 200) {
|
@@ -1329,7 +1358,7 @@ const knowledgeModule = async ({
|
|
1329
1358
|
}
|
1330
1359
|
}
|
1331
1360
|
if (args.print.includes('c')) {
|
1332
|
-
const { data
|
1361
|
+
const { data } = setupProcessB({ config })
|
1333
1362
|
console.log("Config as sent to server")
|
1334
1363
|
console.log(JSON.stringify(data, null, 2));
|
1335
1364
|
}
|
@@ -1488,7 +1517,19 @@ const knowledgeModule = async ({
|
|
1488
1517
|
if (!('then' in promise)) {
|
1489
1518
|
throw 'Return a promise from process in the definition of knowledgeModule'
|
1490
1519
|
}
|
1491
|
-
promise
|
1520
|
+
promise
|
1521
|
+
.then(() => {
|
1522
|
+
f()
|
1523
|
+
})
|
1524
|
+
.catch( (e) => {
|
1525
|
+
if (e.errno == 'ECONNREFUSED') {
|
1526
|
+
console.log(e)
|
1527
|
+
readline.close()
|
1528
|
+
} else {
|
1529
|
+
console.log(e)
|
1530
|
+
f()
|
1531
|
+
}
|
1532
|
+
})
|
1492
1533
|
})
|
1493
1534
|
f()
|
1494
1535
|
} else if (args.query) {
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -572,6 +572,7 @@ class Config {
|
|
572
572
|
}
|
573
573
|
}
|
574
574
|
this.config.associations.positive.push(association)
|
575
|
+
this._delta.json.associations.push({ action: 'add', association })
|
575
576
|
}
|
576
577
|
|
577
578
|
// TODO add more error checking to these like addHierarchy has
|
@@ -580,6 +581,7 @@ class Config {
|
|
580
581
|
this.config.priorities = []
|
581
582
|
}
|
582
583
|
this.config.priorities.push(priorities)
|
584
|
+
this._delta.json.priorities.push({ action: 'add', priorities })
|
583
585
|
}
|
584
586
|
|
585
587
|
addHierarchy (child, parent) {
|
@@ -630,6 +632,7 @@ class Config {
|
|
630
632
|
}
|
631
633
|
|
632
634
|
this.config.hierarchy.push([child, parent])
|
635
|
+
this._delta.json.hierarchy.push([child, parent])
|
633
636
|
}
|
634
637
|
|
635
638
|
getBridge (id, level) {
|
@@ -659,6 +662,7 @@ class Config {
|
|
659
662
|
}
|
660
663
|
bridges.push(def)
|
661
664
|
this.checkBridges();
|
665
|
+
this._delta.json.bridges.push({ action: 'add', bridge: def })
|
662
666
|
}
|
663
667
|
|
664
668
|
addGenerator (match, apply) {
|
@@ -735,17 +739,19 @@ class Config {
|
|
735
739
|
|
736
740
|
operators.unshift(operator)
|
737
741
|
this.checkOperators()
|
742
|
+
|
743
|
+
this._delta.json.operators.push({ action: 'add', operator })
|
738
744
|
}
|
739
745
|
|
740
746
|
addWord (word, def) {
|
741
|
-
this.addWordInternal(
|
747
|
+
this.addWordInternal(word, def)
|
742
748
|
}
|
743
749
|
|
744
|
-
addWordInternal (
|
745
|
-
if (!config.words) {
|
746
|
-
config.words = {}
|
750
|
+
addWordInternal (word, def) {
|
751
|
+
if (!this.config.words) {
|
752
|
+
this.config.words = {}
|
747
753
|
}
|
748
|
-
const words = config.words
|
754
|
+
const words = this.config.words
|
749
755
|
def = Object.assign({}, def, { uuid: this._uuid })
|
750
756
|
if (words[word]) {
|
751
757
|
if (!words[word].some((e) => helpers.safeEquals(e, def))) {
|
@@ -754,6 +760,8 @@ class Config {
|
|
754
760
|
} else {
|
755
761
|
words[word] = [def]
|
756
762
|
}
|
763
|
+
|
764
|
+
this._delta.json.words.push({ action: 'add', word, def })
|
757
765
|
}
|
758
766
|
|
759
767
|
getAPI (uuid) {
|
@@ -970,6 +978,9 @@ class Config {
|
|
970
978
|
throw 'Excepted the config argument to be a hash not a Config object'
|
971
979
|
}
|
972
980
|
|
981
|
+
this.allowDelta = false
|
982
|
+
this.resetDelta()
|
983
|
+
|
973
984
|
this.addedArgss = []
|
974
985
|
let isProcess = require.main === module
|
975
986
|
if (global.theprogrammablemind && config) {
|
@@ -1072,11 +1083,11 @@ class Config {
|
|
1072
1083
|
if (bridge.words) {
|
1073
1084
|
for (let def of bridge.words) {
|
1074
1085
|
if (typeof def == 'string') {
|
1075
|
-
this.addWordInternal(
|
1086
|
+
this.addWordInternal(def, {"id": bridge.id, "initial": "{}" })
|
1076
1087
|
} else {
|
1077
1088
|
const word = def.word
|
1078
1089
|
def = { initial: JSON.stringify(def), id: bridge.id, word: undefined }
|
1079
|
-
this.addWordInternal(
|
1090
|
+
this.addWordInternal(word, def)
|
1080
1091
|
}
|
1081
1092
|
}
|
1082
1093
|
}
|
@@ -1174,6 +1185,32 @@ class Config {
|
|
1174
1185
|
}
|
1175
1186
|
}
|
1176
1187
|
|
1188
|
+
hasDelta () {
|
1189
|
+
return this._delta.json
|
1190
|
+
}
|
1191
|
+
|
1192
|
+
delta () {
|
1193
|
+
return { cacheKey: this._delta.cacheKey, json: this._delta.json }
|
1194
|
+
}
|
1195
|
+
|
1196
|
+
resetDelta (cacheKey) {
|
1197
|
+
this._delta = {
|
1198
|
+
cacheKey,
|
1199
|
+
json: {
|
1200
|
+
words: [],
|
1201
|
+
operators: [],
|
1202
|
+
bridges: [],
|
1203
|
+
associations: [],
|
1204
|
+
priorities: [],
|
1205
|
+
hierarchy: [],
|
1206
|
+
}
|
1207
|
+
}
|
1208
|
+
}
|
1209
|
+
|
1210
|
+
set cacheKey (cacheKey) {
|
1211
|
+
this.resetDelta(cacheKey)
|
1212
|
+
}
|
1213
|
+
|
1177
1214
|
get api () {
|
1178
1215
|
if (this._api && this._api.multiApi) {
|
1179
1216
|
return this._api.api(this._api)
|
@@ -1646,6 +1683,7 @@ class Config {
|
|
1646
1683
|
|
1647
1684
|
// rebuild ({ isModule: mainIsModule = false } = {}) {
|
1648
1685
|
rebuild ({ isModule: mainIsModule } = {}) {
|
1686
|
+
this.resetDelta()
|
1649
1687
|
const debug = this.config.debug;
|
1650
1688
|
this.config = _.cloneDeep(this.initConfig)
|
1651
1689
|
if (debug) {
|