theprogrammablemind 7.7.0-beta.2 → 7.7.0-beta.20
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 +2 -2
- package/src/config.js +36 -42
- package/src/helpers.js +2 -0
package/client.js
CHANGED
@@ -30,18 +30,29 @@ const pickObjects = (testConfig, objects) => {
|
|
30
30
|
return project(objects, getConfig_getObjectsCheck(testConfig))
|
31
31
|
}
|
32
32
|
|
33
|
+
// move ask to the KM's since verbatim is called
|
33
34
|
const getAsk = (config) => (uuid) => (asks) => {
|
34
35
|
for (let ask of asks) {
|
36
|
+
let oneShot = true // default
|
37
|
+
if (ask.oneShot === false) {
|
38
|
+
oneShot = false
|
39
|
+
}
|
35
40
|
config.addSemantic({
|
36
41
|
uuid,
|
37
|
-
oneShot
|
42
|
+
oneShot,
|
38
43
|
match: (args) => ask.matchr(args),
|
39
44
|
apply: (args) => ask.applyr(args)
|
40
45
|
})
|
41
46
|
}
|
47
|
+
let oneShot = true
|
48
|
+
for (let ask of asks) {
|
49
|
+
if (ask.oneShot === false) {
|
50
|
+
oneShot = false
|
51
|
+
}
|
52
|
+
}
|
42
53
|
config.addSemantic({
|
43
54
|
uuid,
|
44
|
-
oneShot
|
55
|
+
oneShot,
|
45
56
|
match: ({context}) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
|
46
57
|
apply: (args) => {
|
47
58
|
for (let ask of asks) {
|
@@ -57,14 +68,18 @@ const getAsk = (config) => (uuid) => (asks) => {
|
|
57
68
|
}
|
58
69
|
if (matchq(args)) {
|
59
70
|
// args.context.motivationKeep = true
|
71
|
+
args.verbatim(applyq(args))
|
72
|
+
/*
|
60
73
|
args.context.verbatim = applyq(args)
|
61
74
|
args.context.isResponse = true;
|
62
75
|
delete args.context.controlRemove;
|
76
|
+
*/
|
63
77
|
args.context.controlKeepMotivation = true;
|
64
78
|
break
|
65
79
|
}
|
66
80
|
}
|
67
|
-
|
81
|
+
args.context.cascade = true
|
82
|
+
}
|
68
83
|
})
|
69
84
|
}
|
70
85
|
|
@@ -169,6 +184,7 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
169
184
|
apis: getAPIs(uuid)
|
170
185
|
}
|
171
186
|
}
|
187
|
+
Object.assign(args, args.getUUIDScoped(this.uuid))
|
172
188
|
args.breakOnSemantics = false
|
173
189
|
args.theDebugger = {
|
174
190
|
breakOnSemantics: (value) => args.breakOnSemantics = value
|
@@ -621,6 +637,15 @@ const loadInstance = (config, instance) => {
|
|
621
637
|
// config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
|
622
638
|
// config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
|
623
639
|
config.addInternal(instance.template.queries[i], { addFirst: true, handleCalculatedProps: true } )
|
640
|
+
} else if (results.apply) {
|
641
|
+
const objects = config.get('objects')
|
642
|
+
const args = { objects, getObjects: getObjects(objects) }
|
643
|
+
if (instance.queries) {
|
644
|
+
args.isInstance = `instance${i}`
|
645
|
+
args.instance = instance.queries[i]
|
646
|
+
}
|
647
|
+
setupArgs(args, config, config.logs, hierarchy)
|
648
|
+
results.apply(args)
|
624
649
|
} else {
|
625
650
|
if (results.skipSemantics) {
|
626
651
|
config.config.skipSemantics = results.skipSemantics
|
@@ -1195,9 +1220,9 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
1195
1220
|
}
|
1196
1221
|
|
1197
1222
|
if (responses.explain_priorities) {
|
1198
|
-
console.log("Explain Priorities
|
1199
|
-
for ([
|
1200
|
-
console.log(` ${JSON.stringify(
|
1223
|
+
console.log("Explain Priorities")
|
1224
|
+
for ([inputs, output, reason] of responses.explain_priorities) {
|
1225
|
+
console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
|
1201
1226
|
}
|
1202
1227
|
}
|
1203
1228
|
const objects = config.get('objects').namespaced[config.uuid]
|
@@ -1325,6 +1350,15 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1325
1350
|
config.config.skipSemantics = null
|
1326
1351
|
errorHandler(error)
|
1327
1352
|
}
|
1353
|
+
} else if (typeof queryOrExtraConfig == 'function') {
|
1354
|
+
console.log('calling initialize function')
|
1355
|
+
const initFunction = queryOrExtraConfig
|
1356
|
+
const objects = config.get('objects')
|
1357
|
+
const args = { objects, getObjects: getObjects(objects) }
|
1358
|
+
setupArgs(args, config, config.logs, hierarchy)
|
1359
|
+
initFunction(args)
|
1360
|
+
accumulators[property].push({ apply: queryOrExtraConfig })
|
1361
|
+
await looper(queries)
|
1328
1362
|
} else {
|
1329
1363
|
// extra config is def from a time like operators or bridges or words etc
|
1330
1364
|
// it will just get added to the config
|
@@ -1357,8 +1391,11 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1357
1391
|
const stabilizeOutput = (template) => {
|
1358
1392
|
stabilizeAssociations(template.associations)
|
1359
1393
|
const stabilize = (results) => {
|
1360
|
-
for (let
|
1361
|
-
|
1394
|
+
for (let i = 0; i < results.length; ++i) {
|
1395
|
+
const result = results[i]
|
1396
|
+
if (result.apply) {
|
1397
|
+
result.apply = result.apply.toString()
|
1398
|
+
} else if (result.extraConfig) {
|
1362
1399
|
} else {
|
1363
1400
|
delete result.load_cache_time
|
1364
1401
|
delete result.times
|
@@ -1643,6 +1680,10 @@ const knowledgeModuleImpl = async ({
|
|
1643
1680
|
config.config.debug = true
|
1644
1681
|
}
|
1645
1682
|
|
1683
|
+
if (args.reset) {
|
1684
|
+
config.config.skip_cache = true
|
1685
|
+
}
|
1686
|
+
|
1646
1687
|
if (args.explainPriorities) {
|
1647
1688
|
config.config.explain_priorities = true
|
1648
1689
|
}
|
@@ -1763,7 +1804,7 @@ const knowledgeModuleImpl = async ({
|
|
1763
1804
|
try {
|
1764
1805
|
config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1765
1806
|
} catch( e ) {
|
1766
|
-
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}`)
|
1807
|
+
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1767
1808
|
runtime.process.exit(-1)
|
1768
1809
|
}
|
1769
1810
|
if (!args.query) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"devDependencies": {
|
3
3
|
"eslint-plugin-import": "^2.23.4",
|
4
|
-
"jest": "^
|
4
|
+
"jest": "^29.7.0",
|
5
5
|
"@typescript-eslint/parser": "^4.28.4",
|
6
6
|
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
7
7
|
"eslint-plugin-node": "^11.1.0",
|
@@ -65,6 +65,6 @@
|
|
65
65
|
"json-stable-stringify": "^1.0.1",
|
66
66
|
"node-fetch": "^2.6.1"
|
67
67
|
},
|
68
|
-
"version": "7.7.0-beta.
|
68
|
+
"version": "7.7.0-beta.20",
|
69
69
|
"license": "ISC"
|
70
70
|
}
|
package/src/config.js
CHANGED
@@ -983,6 +983,18 @@ class Config {
|
|
983
983
|
if (typeof queryOrConfig == 'string') {
|
984
984
|
const query = queryOrConfig
|
985
985
|
return query
|
986
|
+
} else if (typeof queryOrConfig == 'function') {
|
987
|
+
if (options.isModule) {
|
988
|
+
return { apply: 'function in the browser has webpack rewrites so can not be compared' }
|
989
|
+
} else {
|
990
|
+
return { apply: queryOrConfig.toString() }
|
991
|
+
}
|
992
|
+
} else if (queryOrConfig.apply) {
|
993
|
+
if (options.isModule) {
|
994
|
+
return { apply: 'function in the browser has webpack rewrites so can not be compared' }
|
995
|
+
} else {
|
996
|
+
return { apply: queryOrConfig.apply }
|
997
|
+
}
|
986
998
|
} else {
|
987
999
|
const config = { ...queryOrConfig }
|
988
1000
|
delete config.where
|
@@ -1068,6 +1080,12 @@ class Config {
|
|
1068
1080
|
startOfChanges = iq
|
1069
1081
|
}
|
1070
1082
|
}
|
1083
|
+
|
1084
|
+
if (startOfChanges) {
|
1085
|
+
console.log('templateQueries[startOfChanges]', templateQueries[startOfChanges]);
|
1086
|
+
console.log('instanceQueries[startOfChanges]', instanceQueries[startOfChanges]);
|
1087
|
+
}
|
1088
|
+
|
1071
1089
|
// things were deleted case
|
1072
1090
|
if (templateQueries.length < instanceQueries.length) {
|
1073
1091
|
startOfChanges = instanceQueries.length
|
@@ -1138,6 +1156,13 @@ class Config {
|
|
1138
1156
|
return !properties.find( (property) => instance[property] && instance[property].length > 0 )
|
1139
1157
|
}
|
1140
1158
|
if (!isEmpty(instance)) {
|
1159
|
+
// fix up apply functions
|
1160
|
+
for (let i = 0; i < instance.resultss.length; ++i) {
|
1161
|
+
const result = instance.resultss[i]
|
1162
|
+
if (result.apply) {
|
1163
|
+
result.apply = template.queries[i]
|
1164
|
+
}
|
1165
|
+
}
|
1141
1166
|
instance.name = this.name
|
1142
1167
|
this.initInstances.push(instance)
|
1143
1168
|
this.instances.push(instance)
|
@@ -2237,8 +2262,6 @@ class Config {
|
|
2237
2262
|
const addInternals = []
|
2238
2263
|
const inits = []
|
2239
2264
|
const initAfterApis = []
|
2240
|
-
const reverseIt = true
|
2241
|
-
const interleaved = true
|
2242
2265
|
this.configs.forEach((km) => {
|
2243
2266
|
const namespace = km.namespace
|
2244
2267
|
this.config.objects.namespaced[km._uuid] = {}
|
@@ -2304,58 +2327,30 @@ class Config {
|
|
2304
2327
|
inits.unshift( () => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }) )
|
2305
2328
|
// config._api.initialize({ config, api: config._api })
|
2306
2329
|
} else {
|
2307
|
-
|
2308
|
-
inits.unshift(null)
|
2309
|
-
}
|
2330
|
+
inits.unshift(null)
|
2310
2331
|
}
|
2311
2332
|
// config._api.objects = namespacedObjects
|
2312
2333
|
// config._api.config = () => this
|
2313
2334
|
// config._api.uuid = config._uuid
|
2314
2335
|
} else {
|
2315
|
-
|
2316
|
-
inits.unshift(null)
|
2317
|
-
}
|
2336
|
+
inits.unshift(null)
|
2318
2337
|
}
|
2319
2338
|
config.setUUIDs()
|
2320
2339
|
config.applyNamespace(config.config, namespace, config.uuid)
|
2321
2340
|
if (!isSelf) {
|
2322
|
-
|
2323
|
-
addInternals.push(config)
|
2324
|
-
} else {
|
2325
|
-
addInternals.unshift(config)
|
2326
|
-
}
|
2341
|
+
addInternals.unshift(config)
|
2327
2342
|
} else {
|
2328
|
-
|
2329
|
-
addInternals.unshift(null)
|
2330
|
-
}
|
2343
|
+
addInternals.unshift(null)
|
2331
2344
|
}
|
2332
2345
|
km.valid()
|
2333
2346
|
})
|
2334
2347
|
|
2335
2348
|
const generators = this.config.generators
|
2336
2349
|
const semantics = this.config.semantics
|
2337
|
-
|
2338
|
-
|
2339
|
-
this.config.semantics = []
|
2340
|
-
}
|
2350
|
+
this.config.generators = []
|
2351
|
+
this.config.semantics = []
|
2341
2352
|
|
2342
|
-
|
2343
|
-
for (const config of addInternals) {
|
2344
|
-
if (!reverseIt) {
|
2345
|
-
this.addInternal(config, { includeNamespace: false, allowNameToBeNull: true })
|
2346
|
-
} else {
|
2347
|
-
this.addInternalR(config, true, false, false, true)
|
2348
|
-
}
|
2349
|
-
}
|
2350
|
-
// console.log('inits from config', inits)
|
2351
|
-
for (const init of inits) {
|
2352
|
-
init()
|
2353
|
-
}
|
2354
|
-
for (let init of initAfterApis) {
|
2355
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2356
|
-
}
|
2357
|
-
this.instances.forEach((instance) => client.loadInstance(this, instance))
|
2358
|
-
} else {
|
2353
|
+
{
|
2359
2354
|
const base = {
|
2360
2355
|
operators: this.config.operators,
|
2361
2356
|
bridges: this.config.bridges,
|
@@ -2371,13 +2366,16 @@ class Config {
|
|
2371
2366
|
this.config.priorities = []
|
2372
2367
|
this.config.associations = { positive: [], negative: [] }
|
2373
2368
|
this.config.words = {}
|
2374
|
-
|
2369
|
+
|
2375
2370
|
for (let i = 0; i < addInternals.length; ++i) {
|
2376
2371
|
let name;
|
2377
2372
|
if (addInternals[i]) {
|
2378
2373
|
this.addInternalR(addInternals[i], true, false, false, true)
|
2379
2374
|
name = addInternals[i].name
|
2380
2375
|
} else{
|
2376
|
+
// the ones defined in config must come after the ones in the templates
|
2377
|
+
this.config.generators = generators.concat(this.config.generators)
|
2378
|
+
this.config.semantics = semantics.concat(this.config.semantics)
|
2381
2379
|
this.addInternalR(base, true, false, false, true)
|
2382
2380
|
name = this.name
|
2383
2381
|
}
|
@@ -2398,10 +2396,6 @@ class Config {
|
|
2398
2396
|
}
|
2399
2397
|
}
|
2400
2398
|
|
2401
|
-
if (reverseIt) {
|
2402
|
-
this.config.generators = generators.concat(this.config.generators)
|
2403
|
-
this.config.semantics = semantics.concat(this.config.semantics)
|
2404
|
-
}
|
2405
2399
|
this.hierarchy.edges = this.config.hierarchy
|
2406
2400
|
this.valid()
|
2407
2401
|
this.checkBridges()
|
package/src/helpers.js
CHANGED
@@ -272,6 +272,8 @@ const mapInPlace = (list, fn) => {
|
|
272
272
|
const updateQueries = (queryOrConfig) => {
|
273
273
|
if (typeof queryOrConfig == 'string' || queryOrConfig.query) {
|
274
274
|
return queryOrConfig
|
275
|
+
} else if (typeof queryOrConfig == 'function') {
|
276
|
+
return { apply: queryOrConfig.toString() }
|
275
277
|
} else {
|
276
278
|
const config = queryOrConfig
|
277
279
|
return functionsToStrings(config)
|