theprogrammablemind 9.1.1-beta.3 → 9.1.1-beta.5
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 +58 -32
- package/package.json +2 -1
- package/src/config.js +23 -0
- package/src/configHelpers.js +11 -0
- package/src/debug.js +78 -0
- package/src/generators.js +2 -2
- package/src/helpers.js +1 -1
- package/src/semantics.js +4 -4
package/client.js
CHANGED
@@ -12,7 +12,7 @@ const _ = require('lodash')
|
|
12
12
|
const stringify = require('json-stable-stringify')
|
13
13
|
const Lines = require('./lines')
|
14
14
|
const flattens = require('./src/flatten')
|
15
|
-
const { appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries } = require('./src/helpers')
|
15
|
+
const { appendNoDups, InitCalls, updateQueries, safeNoDups, stableId, where, suggestAssociationsFix, suggestAssociationsFixFromSummaries, validProps } = require('./src/helpers')
|
16
16
|
const runtime = require('./runtime')
|
17
17
|
const sortJson = runtime.sortJson
|
18
18
|
|
@@ -477,6 +477,11 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
477
477
|
|
478
478
|
const objects = getObjects(config.config.objects)(config.uuid)
|
479
479
|
try {
|
480
|
+
if (testConfig.initializer) {
|
481
|
+
const args = {}
|
482
|
+
setupArgs(args, config)
|
483
|
+
await testConfig.initializer(args)
|
484
|
+
}
|
480
485
|
const result = await _process(config, test, { errorHandler, isTest: true })
|
481
486
|
result.query = test
|
482
487
|
if (debug) {
|
@@ -820,7 +825,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
820
825
|
}
|
821
826
|
console.log(responses.trace)
|
822
827
|
|
823
|
-
if (
|
828
|
+
if (true) {
|
824
829
|
if (global.beforeObjects) {
|
825
830
|
console.log('objects', runtime.jsonDiff.diffString(global.beforeObjects, config.get('objects')))
|
826
831
|
} else {
|
@@ -931,6 +936,19 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
931
936
|
learned_contextual_priorities: []
|
932
937
|
}
|
933
938
|
config.fragmentsBeingBuilt = []
|
939
|
+
|
940
|
+
const toProperties = (queryStringOrProperties) => {
|
941
|
+
if (typeof queryStringOrProperties === 'string') {
|
942
|
+
return { query: queryStringOrProperties }
|
943
|
+
} else {
|
944
|
+
return queryStringOrProperties
|
945
|
+
}
|
946
|
+
}
|
947
|
+
const fragmentToTodo = (query, index) => {
|
948
|
+
const pr = instance.fragments[index]
|
949
|
+
return Object.assign({}, toProperties(query), { property: 'fragments', previousResults: pr, skipSemantics: false })
|
950
|
+
}
|
951
|
+
|
934
952
|
const looper = async (configs) => {
|
935
953
|
if (configs.length === 0) {
|
936
954
|
finish()
|
@@ -1024,7 +1042,17 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
1024
1042
|
const objects = config.get('objects')
|
1025
1043
|
const args = { objects, getObjects: getObjects(objects) }
|
1026
1044
|
setupArgs(args, config, config.logs, config.hierarchy)
|
1045
|
+
// this watch stuff was for allowing fragment to be made in the template load. that is not a good idea
|
1046
|
+
// because needs rebuild would need to run the rebuild to know if a rebuild was needed. the fragment creates
|
1047
|
+
// need to go in the intializer
|
1048
|
+
// const new_fragments = []
|
1049
|
+
// config.watchNewFragments(new_fragments)
|
1027
1050
|
await initFunction(args)
|
1051
|
+
/*
|
1052
|
+
if (new_fragments.length > 0) {
|
1053
|
+
configs = configs.concat(new_fragments.map(fragmentToTodo))
|
1054
|
+
}
|
1055
|
+
*/
|
1028
1056
|
accumulators[property].push({ apply: queryOrExtraConfig })
|
1029
1057
|
await looper(configs)
|
1030
1058
|
} else {
|
@@ -1093,13 +1121,6 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
1093
1121
|
}
|
1094
1122
|
}
|
1095
1123
|
|
1096
|
-
const toProperties = (queryStringOrProperties) => {
|
1097
|
-
if (typeof queryStringOrProperties === 'string') {
|
1098
|
-
return { query: queryStringOrProperties }
|
1099
|
-
} else {
|
1100
|
-
return queryStringOrProperties
|
1101
|
-
}
|
1102
|
-
}
|
1103
1124
|
let todo = []
|
1104
1125
|
todo = todo.concat((template.initializers || []).map((query) => { return { initializer: true, property: 'resultss', query, skipSemantics: false || query.skipSemantics } }))
|
1105
1126
|
/*
|
@@ -1115,14 +1136,17 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
1115
1136
|
for (let configsIndex = 0; configsIndex < template.configs.length; ++configsIndex) {
|
1116
1137
|
const query = template.configs[configsIndex]
|
1117
1138
|
// account for things for example associations being added to the config while debugginer
|
1118
|
-
const pr = previousResultss.find((pr) => pr.query == query)
|
1139
|
+
const pr = previousResultss && previousResultss.find((pr) => pr.query == query)
|
1119
1140
|
todo.push({ property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics })
|
1120
1141
|
}
|
1121
1142
|
}
|
1143
|
+
todo = todo.concat((template.fragments || []).map(fragmentToTodo))
|
1144
|
+
/*
|
1122
1145
|
todo = todo.concat((template.fragments || []).map((query, index) => {
|
1123
1146
|
const pr = instance.fragments[index]
|
1124
1147
|
return Object.assign({}, toProperties(query), { property: 'fragments', previousResults: pr, skipSemantics: false })
|
1125
1148
|
}))
|
1149
|
+
*/
|
1126
1150
|
todo = todo.concat((template.semantics || []).map((definition) => {
|
1127
1151
|
return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true }
|
1128
1152
|
}))
|
@@ -1136,6 +1160,7 @@ const checkTemplate = (template) => {
|
|
1136
1160
|
if (template.checks) {
|
1137
1161
|
throw new Error("The 'checks' property should be in the 'test' property not the 'template' property")
|
1138
1162
|
}
|
1163
|
+
validProps([ 'fragments', 'configs' ], template.template, 'template.template')
|
1139
1164
|
}
|
1140
1165
|
|
1141
1166
|
const checkTest = (testConfig) => {
|
@@ -1188,8 +1213,30 @@ const knowledgeModuleImpl = async ({
|
|
1188
1213
|
throw new Error("'config' or 'createConfig' is a required parameter. The value should the config that defines the knowledge module.")
|
1189
1214
|
}
|
1190
1215
|
|
1216
|
+
const setupConfig = (config) => {
|
1217
|
+
if (!config.name) {
|
1218
|
+
throw new Error("config must have 'name' set to the knowledge module name.")
|
1219
|
+
}
|
1220
|
+
|
1221
|
+
config.description = description
|
1222
|
+
if (typeof testConfig === 'object') {
|
1223
|
+
if (testConfig.contents) {
|
1224
|
+
config.tests = testConfig.contents
|
1225
|
+
test = testConfig.name
|
1226
|
+
}
|
1227
|
+
} else {
|
1228
|
+
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1229
|
+
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1230
|
+
} else {
|
1231
|
+
config.tests = []
|
1232
|
+
}
|
1233
|
+
}
|
1234
|
+
config.setTestConfig(testConfig)
|
1235
|
+
}
|
1236
|
+
|
1191
1237
|
const createConfig = async () => {
|
1192
1238
|
const config = new Config(configStruct, moduleFromJSFile, _process)
|
1239
|
+
setupConfig(config)
|
1193
1240
|
config.setTerminator(terminator)
|
1194
1241
|
config.stop_auto_rebuild()
|
1195
1242
|
await config.add(...(includes || []))
|
@@ -1216,27 +1263,6 @@ const knowledgeModuleImpl = async ({
|
|
1216
1263
|
|
1217
1264
|
const isProcess = require.main === moduleFromJSFile
|
1218
1265
|
|
1219
|
-
const setupConfig = (config) => {
|
1220
|
-
if (!config.name) {
|
1221
|
-
throw new Error("config must have 'name' set to the knowledge module name.")
|
1222
|
-
}
|
1223
|
-
|
1224
|
-
config.description = description
|
1225
|
-
if (typeof testConfig === 'object') {
|
1226
|
-
if (testConfig.contents) {
|
1227
|
-
config.tests = testConfig.contents
|
1228
|
-
test = testConfig.name
|
1229
|
-
}
|
1230
|
-
} else {
|
1231
|
-
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1232
|
-
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1233
|
-
} else {
|
1234
|
-
config.tests = []
|
1235
|
-
}
|
1236
|
-
}
|
1237
|
-
config.setTestConfig(testConfig)
|
1238
|
-
}
|
1239
|
-
|
1240
1266
|
if (isProcess) {
|
1241
1267
|
let config
|
1242
1268
|
try {
|
@@ -1306,7 +1332,7 @@ const knowledgeModuleImpl = async ({
|
|
1306
1332
|
global.pauseDebugging = true
|
1307
1333
|
}
|
1308
1334
|
|
1309
|
-
setupConfig(config)
|
1335
|
+
// setupConfig(config)
|
1310
1336
|
processResults = processResults({ config, errorHandler })
|
1311
1337
|
|
1312
1338
|
if (args.rebuildTemplate) {
|
package/package.json
CHANGED
@@ -47,6 +47,7 @@
|
|
47
47
|
"src/config.js",
|
48
48
|
"src/configHelpers.js",
|
49
49
|
"src/copy.js",
|
50
|
+
"src/debug.js",
|
50
51
|
"src/digraph.js",
|
51
52
|
"src/digraph_internal.js",
|
52
53
|
"src/generators.js",
|
@@ -67,6 +68,6 @@
|
|
67
68
|
"sort-json": "^2.0.0",
|
68
69
|
"uuid": "^8.3.2"
|
69
70
|
},
|
70
|
-
"version": "9.1.1-beta.
|
71
|
+
"version": "9.1.1-beta.5",
|
71
72
|
"license": "UNLICENSED"
|
72
73
|
}
|
package/src/config.js
CHANGED
@@ -9,6 +9,7 @@ const { InitCalls } = require('./helpers')
|
|
9
9
|
const { ecatch } = require('./helpers')
|
10
10
|
const runtime = require('../runtime')
|
11
11
|
const _ = require('lodash')
|
12
|
+
const db = require('./debug')
|
12
13
|
|
13
14
|
const debugBreak = () => {
|
14
15
|
// debugger
|
@@ -869,6 +870,14 @@ class Config {
|
|
869
870
|
return config_toServer(config)
|
870
871
|
}
|
871
872
|
|
873
|
+
async fixtures () {
|
874
|
+
if (this.testConfig?.fixtures) {
|
875
|
+
const args = {}
|
876
|
+
configHelpers.setupArgs(args, this)
|
877
|
+
return this.testConfig.fixtures(args)
|
878
|
+
}
|
879
|
+
}
|
880
|
+
|
872
881
|
getInfo () {
|
873
882
|
const name = this.name
|
874
883
|
const includes = this.configs.slice(1).map((km) => km.config.name)
|
@@ -1366,9 +1375,18 @@ class Config {
|
|
1366
1375
|
}
|
1367
1376
|
}
|
1368
1377
|
|
1378
|
+
watchNewFragments (list) {
|
1379
|
+
this.addFragmentWatcher = list
|
1380
|
+
}
|
1381
|
+
|
1369
1382
|
addFragments (fragments) {
|
1370
1383
|
// only run this if not loading as module write error if loading as module and different
|
1371
1384
|
this.dynamicFragments = this.dynamicFragments.concat(fragments)
|
1385
|
+
if (this.addFragmentWatcher) {
|
1386
|
+
for (const fragment of fragments) {
|
1387
|
+
this.addFragmentWatcher.push(fragment)
|
1388
|
+
}
|
1389
|
+
}
|
1372
1390
|
}
|
1373
1391
|
|
1374
1392
|
objects () {
|
@@ -2697,6 +2715,11 @@ class Config {
|
|
2697
2715
|
}
|
2698
2716
|
|
2699
2717
|
this.hierarchy.edges = this.config.hierarchy
|
2718
|
+
|
2719
|
+
if (!this.isModule) {
|
2720
|
+
await this.fixtures()
|
2721
|
+
}
|
2722
|
+
|
2700
2723
|
this.valid()
|
2701
2724
|
this.checks()
|
2702
2725
|
}
|
package/src/configHelpers.js
CHANGED
@@ -81,6 +81,13 @@ const cleanAssign = (dest, ...srcs) => {
|
|
81
81
|
}
|
82
82
|
|
83
83
|
const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
84
|
+
if (!args.objects) {
|
85
|
+
args.objects = config.get('objects')
|
86
|
+
args.getObjects = getObjects(args.objects)
|
87
|
+
}
|
88
|
+
if (!hierarchy) {
|
89
|
+
hierarchy = config.hierarchy
|
90
|
+
}
|
84
91
|
// callId
|
85
92
|
args.calls = new InitCalls(args.isInstance ? `${args.isInstance}#${config.name}` : config.name)
|
86
93
|
if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
|
@@ -154,6 +161,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
154
161
|
config.getAddedArgs(args)
|
155
162
|
|
156
163
|
Object.assign(args, args.getUUIDScoped(uuidForScoping || config.uuid))
|
164
|
+
args.apis = args.apis || ((name) => config.getConfig(name).api)
|
157
165
|
/*
|
158
166
|
if (uuidForScoping) {
|
159
167
|
Object.assign(args, args.getUUIDScoped(uuidForScoping))
|
@@ -280,11 +288,14 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
|
|
280
288
|
args.insert = (context) => toDo.unshift(context)
|
281
289
|
let overlap, lastRange
|
282
290
|
config.debugLoops = commandLineArgs && commandLineArgs.debugLoops
|
291
|
+
let context_id_counter = 0
|
283
292
|
while (toDo.length > 0) {
|
284
293
|
const context = toDo.shift()
|
285
294
|
args.calls.next()
|
286
295
|
let contextPrime = context
|
287
296
|
context.topLevel = true
|
297
|
+
context_id_counter += 1
|
298
|
+
context.context_id = context_id_counter
|
288
299
|
try {
|
289
300
|
if (json.has_errors) {
|
290
301
|
throw new Error('There are errors in the logs. Run with the -d flag and grep for Error')
|
package/src/debug.js
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
const counters = {}
|
2
|
+
const hits = {}
|
3
|
+
|
4
|
+
let db = () => {
|
5
|
+
debugger // eslint-disable-line no-debugger
|
6
|
+
}
|
7
|
+
|
8
|
+
const reset = () => {
|
9
|
+
Object.keys(counters).forEach(key => delete counters[key])
|
10
|
+
Object.keys(hits).forEach(key => delete hits[key])
|
11
|
+
db = () => { debugger } // eslint-disable-line no-debugger
|
12
|
+
}
|
13
|
+
|
14
|
+
const getDb = () => {
|
15
|
+
return db
|
16
|
+
}
|
17
|
+
|
18
|
+
const setDb = (value) => {
|
19
|
+
db = value
|
20
|
+
}
|
21
|
+
|
22
|
+
const hit = (name) => {
|
23
|
+
hits[name] = true
|
24
|
+
}
|
25
|
+
|
26
|
+
const unhit = (name) => {
|
27
|
+
hits[name] = false
|
28
|
+
}
|
29
|
+
|
30
|
+
const wasHit = (name) => {
|
31
|
+
return hits[name]
|
32
|
+
}
|
33
|
+
|
34
|
+
const counter = (name, breakAt = [], debugBreak = true) => {
|
35
|
+
if (!counters[name]) {
|
36
|
+
counters[name] = 0
|
37
|
+
}
|
38
|
+
counters[name] += 1
|
39
|
+
console.log(`counters[${name}] = ${counters[name]}`)
|
40
|
+
unhit(name)
|
41
|
+
if (Array.isArray(breakAt) && breakAt.includes(counters[name])) {
|
42
|
+
if (debugBreak) {
|
43
|
+
db()
|
44
|
+
}
|
45
|
+
hit(name)
|
46
|
+
return true
|
47
|
+
} else if (breakAt == counters[name]) {
|
48
|
+
if (debugBreak) {
|
49
|
+
db()
|
50
|
+
}
|
51
|
+
hit(name)
|
52
|
+
return true
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
const get = (name) => {
|
57
|
+
return counters[name]
|
58
|
+
}
|
59
|
+
|
60
|
+
const _break = (name) => {
|
61
|
+
if (wasHit(name)) {
|
62
|
+
db()
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
module.exports = {
|
67
|
+
counter,
|
68
|
+
get,
|
69
|
+
_break, // break is a keyword
|
70
|
+
|
71
|
+
// used for tests
|
72
|
+
reset,
|
73
|
+
hit,
|
74
|
+
unhit,
|
75
|
+
wasHit,
|
76
|
+
getDb,
|
77
|
+
setDb
|
78
|
+
}
|
package/src/generators.js
CHANGED
@@ -211,7 +211,7 @@ class Generators {
|
|
211
211
|
lines.setElement(0, 2, generator.toString())
|
212
212
|
lines.newRow()
|
213
213
|
lines.setElement(0, 1, 'TO')
|
214
|
-
lines.setElement(0, 2, `
|
214
|
+
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
215
215
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
216
216
|
lines.newRow()
|
217
217
|
lines.setElement(0, 1, 'STACK')
|
@@ -253,7 +253,7 @@ class Generators {
|
|
253
253
|
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
254
254
|
lines.newRow()
|
255
255
|
lines.setElement(0, 1, 'TO')
|
256
|
-
lines.setElement(0, 2, `
|
256
|
+
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
257
257
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
258
258
|
this.logs.push(lines.toString())
|
259
259
|
}
|
package/src/helpers.js
CHANGED
@@ -310,7 +310,7 @@ const validProps = (valids, object, type) => {
|
|
310
310
|
}
|
311
311
|
}
|
312
312
|
if (!okay) {
|
313
|
-
throw new Error(`Unknown property "${prop}" in the ${type}. Valid properties are ${valids}. The ${type} is ${JSON.stringify(object)}`)
|
313
|
+
throw new Error(`Unknown property "${prop}" in the ${type}. Valid properties are ${valids.join(', ')}. The ${type} is ${JSON.stringify(object)}`)
|
314
314
|
}
|
315
315
|
}
|
316
316
|
}
|
package/src/semantics.js
CHANGED
@@ -218,7 +218,7 @@ class Semantics {
|
|
218
218
|
lines.setElement(0, 2, semantic.toString())
|
219
219
|
lines.newRow()
|
220
220
|
lines.setElement(0, 1, 'TO')
|
221
|
-
lines.setElement(0, 2, `
|
221
|
+
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
222
222
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
223
223
|
lines.newRow()
|
224
224
|
lines.setElement(0, 1, 'STACK')
|
@@ -253,7 +253,7 @@ class Semantics {
|
|
253
253
|
lines.setElement(0, 2, semantic.toString())
|
254
254
|
lines.newRow()
|
255
255
|
lines.setElement(0, 1, 'TO')
|
256
|
-
lines.setElement(0, 2, `
|
256
|
+
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
257
257
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
258
258
|
lines.newRow()
|
259
259
|
lines.setElement(0, 1, 'STACK')
|
@@ -263,7 +263,7 @@ class Semantics {
|
|
263
263
|
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
264
264
|
lines.newRow()
|
265
265
|
lines.setElement(0, 1, 'RESULT')
|
266
|
-
lines.setElement(0, 2, `
|
266
|
+
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
267
267
|
lines.setElement(1, 2, JSON.stringify(contextPrime, null, 2))
|
268
268
|
for (const { semantic } of deferred) {
|
269
269
|
lines.setElement(0, 1, 'DEFERRED')
|
@@ -295,7 +295,7 @@ class Semantics {
|
|
295
295
|
lines.setElement(0, 2, stack)
|
296
296
|
lines.newRow()
|
297
297
|
lines.setElement(0, 1, 'TO')
|
298
|
-
lines.setElement(0, 2, `
|
298
|
+
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
299
299
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
300
300
|
this.logs.push(lines.toString())
|
301
301
|
}
|