theprogrammablemind 9.8.0-beta.0 → 9.8.0-beta.10
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/package.json +1 -1
- package/src/config.js +35 -15
- package/src/configHelpers.js +44 -9
- package/src/generators.js +6 -6
- package/src/helpers.js +3 -0
- package/src/semantics.js +10 -10
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -295,9 +295,6 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
295
295
|
if (bridge.scope && config.isModule) {
|
|
296
296
|
return
|
|
297
297
|
}
|
|
298
|
-
if (false && !bridge.bridge) {
|
|
299
|
-
bridge.bridge = '{ ...next(operator) }'
|
|
300
|
-
}
|
|
301
298
|
if (!bridge.level) {
|
|
302
299
|
bridge.level = 0
|
|
303
300
|
}
|
|
@@ -391,6 +388,13 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
391
388
|
}
|
|
392
389
|
*/
|
|
393
390
|
|
|
391
|
+
if (!bridge.where) {
|
|
392
|
+
if (bridge.generator || bridge.generatorp || bridge.generatorr || bridge.generator ||
|
|
393
|
+
bridge.semantic || bridge.evaluator || bridge.evaluator2 || bridge.semantics) {
|
|
394
|
+
throw new Error(`In the KM "${config.name}", for the bridge ${bridge.id} the where property is missing. Use where: where().`)
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
394
398
|
const addUUID = (obj) => { return { ...obj, uuid: uuid || config.uuid } }
|
|
395
399
|
|
|
396
400
|
if (bridge.generators) {
|
|
@@ -469,7 +473,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
469
473
|
}
|
|
470
474
|
}
|
|
471
475
|
|
|
472
|
-
const addSemantic = (semantic, evaluate) => {
|
|
476
|
+
const addSemantic = (semantic, evaluate, property) => {
|
|
473
477
|
const match = semantic.match || (() => true)
|
|
474
478
|
let apply = semantic
|
|
475
479
|
// if I do apply === semantic.apply or semantic there is one function that has apply defined for some reason even though not explicitly set
|
|
@@ -490,14 +494,22 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
490
494
|
applyWrapped: semantic,
|
|
491
495
|
}
|
|
492
496
|
} else {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
+
if (property == 'evaluator2') {
|
|
498
|
+
semanticDef = {
|
|
499
|
+
match: (args) => bridge.id === args.context.marker && match(args),
|
|
500
|
+
apply: (args) => apply(args),
|
|
501
|
+
applyWrapped: semantic,
|
|
502
|
+
}
|
|
503
|
+
} else {
|
|
504
|
+
semanticDef = {
|
|
505
|
+
match: (args) => bridge.id === args.context.marker && !!args.context.evaluate === evaluate && match(args),
|
|
506
|
+
apply: (args) => apply(args),
|
|
507
|
+
applyWrapped: semantic,
|
|
508
|
+
}
|
|
497
509
|
}
|
|
498
510
|
}
|
|
499
511
|
semanticDef.where = semantic.where || bridge.where || helpers.where(4)
|
|
500
|
-
semanticDef.property =
|
|
512
|
+
semanticDef.property = property
|
|
501
513
|
if (semantic.priority) {
|
|
502
514
|
semanticDef.priority = semantic.priority
|
|
503
515
|
}
|
|
@@ -510,11 +522,15 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
510
522
|
}
|
|
511
523
|
|
|
512
524
|
if (bridge.evaluator) {
|
|
513
|
-
addSemantic(bridge.evaluator, true)
|
|
525
|
+
addSemantic(bridge.evaluator, true, 'evaluator')
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (bridge.evaluator2) {
|
|
529
|
+
addSemantic(bridge.evaluator2, false, 'evaluator2')
|
|
514
530
|
}
|
|
515
531
|
|
|
516
532
|
if (bridge.semantic) {
|
|
517
|
-
addSemantic(bridge.semantic, false)
|
|
533
|
+
addSemantic(bridge.semantic, false, 'semantic')
|
|
518
534
|
}
|
|
519
535
|
|
|
520
536
|
if (bridge.evaluators) {
|
|
@@ -522,7 +538,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
522
538
|
evaluators.reverse()
|
|
523
539
|
if (evaluators) {
|
|
524
540
|
for (const evaluator of evaluators) {
|
|
525
|
-
addSemantic(evaluator, true)
|
|
541
|
+
addSemantic(evaluator, true, 'evaluator')
|
|
526
542
|
}
|
|
527
543
|
}
|
|
528
544
|
}
|
|
@@ -557,6 +573,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
557
573
|
'disabled',
|
|
558
574
|
'enhanced_associations',
|
|
559
575
|
'evaluator',
|
|
576
|
+
'evaluator2',
|
|
560
577
|
'evaluators',
|
|
561
578
|
'generatorp',
|
|
562
579
|
'generatorpr',
|
|
@@ -996,9 +1013,10 @@ class Config {
|
|
|
996
1013
|
|
|
997
1014
|
async fixtures () {
|
|
998
1015
|
if (this.testConfig?.fixtures) {
|
|
999
|
-
const args = {
|
|
1016
|
+
const args = {
|
|
1017
|
+
}
|
|
1000
1018
|
args.uuid = this._uuid
|
|
1001
|
-
configHelpers.setupArgs(args, this)
|
|
1019
|
+
configHelpers.setupArgs(args, this, this.logs)
|
|
1002
1020
|
return this.testConfig.fixtures(args)
|
|
1003
1021
|
}
|
|
1004
1022
|
}
|
|
@@ -1043,6 +1061,7 @@ class Config {
|
|
|
1043
1061
|
addPattern: (...args) => this.addPattern(...args, uuid),
|
|
1044
1062
|
updateBridge: (...args) => this.updateBridge(...args),
|
|
1045
1063
|
processContext: (...args) => this.processContext(...args),
|
|
1064
|
+
logs: this.logs,
|
|
1046
1065
|
|
|
1047
1066
|
semantics: () => this.config.semantics,
|
|
1048
1067
|
getConfigs: () => this.configs,
|
|
@@ -1252,7 +1271,7 @@ class Config {
|
|
|
1252
1271
|
// value is in response field
|
|
1253
1272
|
// TODO maybe generalize out query+evaluate along the lines of set value and set reference
|
|
1254
1273
|
async getEvaluator (s, calls, log, context, args) {
|
|
1255
|
-
const instance = await s({ ...args, ...context
|
|
1274
|
+
const instance = await s({ ...args, ...context })
|
|
1256
1275
|
calls.touch(instance)
|
|
1257
1276
|
if (instance.evalue == null && !instance.verbatim && !instance.value) {
|
|
1258
1277
|
this.warningNotEvaluated(log, context)
|
|
@@ -1397,6 +1416,7 @@ class Config {
|
|
|
1397
1416
|
delete bridge.generatorr
|
|
1398
1417
|
delete bridge.generatorpr
|
|
1399
1418
|
delete bridge.evaluator
|
|
1419
|
+
delete bridge.evaluator2
|
|
1400
1420
|
delete bridge.evaluators
|
|
1401
1421
|
delete bridge.semantic
|
|
1402
1422
|
delete bridge.semantics
|
package/src/configHelpers.js
CHANGED
|
@@ -100,6 +100,31 @@ class HandlerStack {
|
|
|
100
100
|
this.handlers.pop()
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/*
|
|
104
|
+
async wrap(call, w) {
|
|
105
|
+
const s = w
|
|
106
|
+
this.push(w)
|
|
107
|
+
const p = call()
|
|
108
|
+
if (p) {
|
|
109
|
+
return p.finally(() => {
|
|
110
|
+
this.pop()
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
async wrap(call, w) {
|
|
117
|
+
this.push(w)
|
|
118
|
+
const p = call()
|
|
119
|
+
if (p && typeof p.finally === 'function') {
|
|
120
|
+
return p.finally(() => {
|
|
121
|
+
this.pop()
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
this.pop()
|
|
125
|
+
return p
|
|
126
|
+
}
|
|
127
|
+
|
|
103
128
|
toString() {
|
|
104
129
|
let str = ''
|
|
105
130
|
for (let i = this.handlers.length - 1; i >= 0; --i) {
|
|
@@ -205,8 +230,6 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
205
230
|
args.theDebugger = {
|
|
206
231
|
breakOnSemantics: (value) => args.breakOnSemantics = value
|
|
207
232
|
}
|
|
208
|
-
if (!logs) {
|
|
209
|
-
}
|
|
210
233
|
args.log = (message) => logs.push(message)
|
|
211
234
|
|
|
212
235
|
args.addWord = (word, def) => config.addWord(word, def, args.uuid)
|
|
@@ -221,7 +244,6 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
221
244
|
return { ...args, assumed: Object.assign({}, assumed, (args.assumed || {}), ...moreAssumed) }
|
|
222
245
|
}
|
|
223
246
|
|
|
224
|
-
args.s = (c, options = {}) => config.getSemantics(logs).apply(args, c, options)
|
|
225
247
|
args.g = (c, rest = {}) => {
|
|
226
248
|
// if (JSON.stringify(rest) !== '{}' && !(rest.assumed || rest.options)) {
|
|
227
249
|
// debugger
|
|
@@ -256,11 +278,23 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
256
278
|
const { assumed = {}, options = {} } = rest
|
|
257
279
|
return config.getGenerators(logs).apply(addAssumed(args, assumed, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true }, options)
|
|
258
280
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
281
|
+
if (true) {
|
|
282
|
+
args.s = (c, options = {}) => config.getSemantics(logs).apply(args, c, options)
|
|
283
|
+
args.e = (c) => {
|
|
284
|
+
if (!c) {
|
|
285
|
+
return
|
|
286
|
+
}
|
|
287
|
+
return config.getEvaluator(args.s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
|
|
262
288
|
}
|
|
263
|
-
|
|
289
|
+
} else {
|
|
290
|
+
args.e = (c) => {
|
|
291
|
+
if (!c) {
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
const s = (c, options = {}) => config.getSemantics(logs).apply(args, c, options)
|
|
295
|
+
return config.getEvaluator(s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
|
|
296
|
+
}
|
|
297
|
+
args.s = args.e
|
|
264
298
|
}
|
|
265
299
|
args.gs = gs(args.g)
|
|
266
300
|
args.gsp = gs(args.gp)
|
|
@@ -578,14 +612,14 @@ const loadInstance = async (config, instance) => {
|
|
|
578
612
|
// used to do a CLONE
|
|
579
613
|
config.addInternal(instance.template.configs[i], { uuid, km: instance.name, addFirst: true, handleCalculatedProps: true })
|
|
580
614
|
} else if (results.apply) {
|
|
581
|
-
const
|
|
615
|
+
const uuid = config.nameToUUID(instance.name)
|
|
616
|
+
const objects = getObjects(config.get('objects'))(uuid)
|
|
582
617
|
const args = { objects, getObjects: getObjects(objects) }
|
|
583
618
|
if (instance.configs) {
|
|
584
619
|
args.isInstance = `instance${i}`
|
|
585
620
|
args.instance = instance.configs[i]
|
|
586
621
|
}
|
|
587
622
|
|
|
588
|
-
const uuid = config.nameToUUID(instance.name)
|
|
589
623
|
setupArgs(args, config, config.logs, hierarchy, uuid)
|
|
590
624
|
if (config.name == instance.name) {
|
|
591
625
|
args.isModule = !!config.isModule
|
|
@@ -609,6 +643,7 @@ const loadInstance = async (config, instance) => {
|
|
|
609
643
|
args.instance = ''
|
|
610
644
|
args.isProcess = !config.isModule
|
|
611
645
|
args.isModule = !!config.isModule
|
|
646
|
+
args.logs = config.logs
|
|
612
647
|
if (instance.name == config.testConfig.testModuleName) {
|
|
613
648
|
args.isTesting = true
|
|
614
649
|
}
|
package/src/generators.js
CHANGED
|
@@ -125,7 +125,7 @@ class Generator {
|
|
|
125
125
|
args.g = args.gp
|
|
126
126
|
}
|
|
127
127
|
return await debug.hitScoped(args.callId, async () => {
|
|
128
|
-
if ((options.debug || {}).apply || process.env.
|
|
128
|
+
if ((options.debug || {}).apply || process.env.DEBUG_BREAKAT == args.callId || callId === this.callId) {
|
|
129
129
|
debugger // eslint-disable-line no-debugger
|
|
130
130
|
}
|
|
131
131
|
return await this._apply(args) // DEBUG: This is the line you want to step into
|
|
@@ -197,7 +197,7 @@ class Generators {
|
|
|
197
197
|
console.error("TPMKMS_TRACE", debug.counter("TPMKMS_TRACE"))
|
|
198
198
|
console.error(generator.toLabel())
|
|
199
199
|
console.error(generator.toString())
|
|
200
|
-
console.log(`To debug this use debug.breakAt('${args.calls.current()}') or
|
|
200
|
+
console.log(`To debug this use debug.breakAt('${args.calls.current()}') or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
try {
|
|
@@ -227,15 +227,15 @@ class Generators {
|
|
|
227
227
|
lines.newRow()
|
|
228
228
|
lines.setElement(0, 2, generator.toString())
|
|
229
229
|
lines.newRow()
|
|
230
|
+
lines.setElement(0, 1, 'STACK')
|
|
231
|
+
lines.setElement(0, 2, stack)
|
|
232
|
+
lines.newRow()
|
|
230
233
|
lines.setElement(0, 1, 'TO')
|
|
231
234
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
232
235
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 10 }), null, 2))
|
|
233
236
|
lines.newRow()
|
|
234
|
-
lines.setElement(0, 1, 'STACK')
|
|
235
|
-
lines.setElement(0, 2, stack)
|
|
236
|
-
lines.newRow()
|
|
237
237
|
lines.setElement(0, 1, 'DEBUG')
|
|
238
|
-
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') or
|
|
238
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
239
239
|
lines.newRow()
|
|
240
240
|
lines.setElement(0, 1, 'ERROR')
|
|
241
241
|
lines.setElement(0, 2, errorMessage)
|
package/src/helpers.js
CHANGED
|
@@ -480,6 +480,9 @@ const functionsToStrings = (config) => {
|
|
|
480
480
|
if (bridge.evaluator) {
|
|
481
481
|
bridge.evaluator = bridge.evaluator.toString()
|
|
482
482
|
}
|
|
483
|
+
if (bridge.evaluator2) {
|
|
484
|
+
bridge.evaluator2 = bridge.evaluator2.toString()
|
|
485
|
+
}
|
|
483
486
|
if (bridge.evaluators) {
|
|
484
487
|
bridge.evaluators = bridge.evaluators.toString()
|
|
485
488
|
}
|
package/src/semantics.js
CHANGED
|
@@ -78,7 +78,7 @@ class Semantic {
|
|
|
78
78
|
return await debug.hitScoped(args.callId, async () => {
|
|
79
79
|
const matches = await this.matcher(args)
|
|
80
80
|
if (matches) {
|
|
81
|
-
if ((options.debug || {}).match || args.callId === this.callId || process.env.
|
|
81
|
+
if ((options.debug || {}).match || args.callId === this.callId || process.env.DEBUG_BREAKAT == args.callId) {
|
|
82
82
|
debugger // eslint-disable-line no-debugger
|
|
83
83
|
await this.matcher(args) // DEBUG: This is the line you step into
|
|
84
84
|
}
|
|
@@ -101,7 +101,7 @@ class Semantic {
|
|
|
101
101
|
this.fixUpArgs(args, contextPrime)
|
|
102
102
|
|
|
103
103
|
return await debug.hitScoped(args.callId, async () => {
|
|
104
|
-
if ((options.debug || {}).apply || args.callId === this.callId || process.env.
|
|
104
|
+
if ((options.debug || {}).apply || args.callId === this.callId || process.env.DEBUG_BREAKAT == args.callId) {
|
|
105
105
|
debugger // eslint-disable-line no-debugger // STEP ABOUT THREE TIMES TO THE DEBUG LINE
|
|
106
106
|
}
|
|
107
107
|
if (args.breakOnSemantics) {
|
|
@@ -262,15 +262,15 @@ class Semantics {
|
|
|
262
262
|
lines.setElement(0, 2, semantic.toString())
|
|
263
263
|
lines.newRow()
|
|
264
264
|
lines.setElement(0, 1, 'DEBUG')
|
|
265
|
-
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or
|
|
265
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
266
|
+
lines.newRow()
|
|
267
|
+
lines.setElement(0, 1, 'STACK')
|
|
268
|
+
lines.setElement(0, 2, stack)
|
|
266
269
|
lines.newRow()
|
|
267
270
|
lines.setElement(0, 1, 'TO')
|
|
268
271
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
269
272
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
|
270
273
|
lines.newRow()
|
|
271
|
-
lines.setElement(0, 1, 'STACK')
|
|
272
|
-
lines.setElement(0, 2, stack)
|
|
273
|
-
lines.newRow()
|
|
274
274
|
lines.setElement(0, 1, 'ERROR')
|
|
275
275
|
lines.setElement(0, 2, errorMessage)
|
|
276
276
|
this.logs.push(lines.toString())
|
|
@@ -298,15 +298,15 @@ class Semantics {
|
|
|
298
298
|
lines.setElement(0, 2, semantic.toString())
|
|
299
299
|
lines.newRow()
|
|
300
300
|
lines.setElement(0, 1, 'DEBUG')
|
|
301
|
-
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or
|
|
301
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
302
|
+
lines.newRow()
|
|
303
|
+
lines.setElement(0, 1, 'STACK')
|
|
304
|
+
lines.setElement(0, 2, stack)
|
|
302
305
|
lines.newRow()
|
|
303
306
|
lines.setElement(0, 1, 'TO')
|
|
304
307
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
305
308
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
|
306
309
|
lines.newRow()
|
|
307
|
-
lines.setElement(0, 1, 'STACK')
|
|
308
|
-
lines.setElement(0, 2, stack)
|
|
309
|
-
lines.newRow()
|
|
310
310
|
lines.setElement(0, 1, 'RESULT')
|
|
311
311
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
312
312
|
lines.setElement(1, 2, JSON.stringify(contextPrime, null, 2))
|