theprogrammablemind 9.8.0-beta.1 → 9.8.0-beta.11
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 +4 -13
- package/lines.js +1 -1
- package/package.json +1 -1
- package/src/config.js +38 -40
- package/src/configHelpers.js +63 -22
- package/src/fragments.js +17 -1
- package/src/generators.js +10 -10
- package/src/helpers.js +9 -7
- package/src/semantics.js +21 -15
package/client.js
CHANGED
|
@@ -158,13 +158,6 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
158
158
|
if (runtime.fs.existsSync(fn)) {
|
|
159
159
|
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
|
160
160
|
}
|
|
161
|
-
/*
|
|
162
|
-
for (const association of associations) {
|
|
163
|
-
association.sort()
|
|
164
|
-
}
|
|
165
|
-
associations.sort()
|
|
166
|
-
*/
|
|
167
|
-
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
|
168
161
|
const results = sortJson({
|
|
169
162
|
query,
|
|
170
163
|
summaries,
|
|
@@ -189,7 +182,6 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
189
182
|
if (!wasSet) {
|
|
190
183
|
tests.push(results)
|
|
191
184
|
}
|
|
192
|
-
// fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
|
193
185
|
writeTestFile(fn, tests)
|
|
194
186
|
}
|
|
195
187
|
|
|
@@ -258,7 +250,7 @@ const throwErrorHandler = (error) => {
|
|
|
258
250
|
throw error
|
|
259
251
|
}
|
|
260
252
|
|
|
261
|
-
const _process = async (config, query, { queryNumber, initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
253
|
+
const _process = async (config, query, { isFragment, queryNumber, initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
262
254
|
if (credentials) {
|
|
263
255
|
config.server(credentials.server, credentials.key)
|
|
264
256
|
}
|
|
@@ -364,7 +356,7 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
364
356
|
const summary = { summaries: json.summaries, length: json.contexts.length }
|
|
365
357
|
summaries.push(summary)
|
|
366
358
|
const { updatedContextIdCounter, contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
|
367
|
-
await processContextsB({ contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
359
|
+
await processContextsB({ skipSemantics: isFragment, isFragment, contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
368
360
|
contextIdCounter = updatedContextIdCounter
|
|
369
361
|
if (isTest) {
|
|
370
362
|
const end = runtime.performance.performance.now()
|
|
@@ -384,7 +376,6 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
384
376
|
response.explain_associations_details = (response.explain_associations_details || []).concat(json.explain_associations_details)
|
|
385
377
|
response.explain_associations_trie = json.explain_associations_trie
|
|
386
378
|
response.contextual_priorities_ambiguities = json.contextual_priorities_ambiguities
|
|
387
|
-
// response.rtf_associations = json.rtf_associations
|
|
388
379
|
|
|
389
380
|
response.contexts = response.contexts.concat(contextsPrime)
|
|
390
381
|
response.generated = response.generated.concat(generatedPrime)
|
|
@@ -1036,7 +1027,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1036
1027
|
await loadInstance(config, { resultss: [results] })
|
|
1037
1028
|
} else {
|
|
1038
1029
|
try {
|
|
1039
|
-
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
|
1030
|
+
results = await _process(config, query.query, { initializer, rebuildingTemplate: true, isFragment })
|
|
1040
1031
|
} catch (e) {
|
|
1041
1032
|
if (e.summaries && e.summaries.length > 0) {
|
|
1042
1033
|
suggestFix(e.summaries)
|
|
@@ -1064,7 +1055,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1064
1055
|
results.isFragment = isFragment
|
|
1065
1056
|
results.skipSemantics = skipSemantics
|
|
1066
1057
|
results.development = query.development
|
|
1067
|
-
results.key = { query: query.query, hierarchy }
|
|
1058
|
+
results.key = { query: query.query, hierarchy, preserve: query.preserve }
|
|
1068
1059
|
accumulators[property].push(results)
|
|
1069
1060
|
if (isFragment) {
|
|
1070
1061
|
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
package/lines.js
CHANGED
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.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
|
|
@@ -491,13 +495,13 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
491
495
|
}
|
|
492
496
|
} else {
|
|
493
497
|
semanticDef = {
|
|
494
|
-
match: (args) => bridge.id === args.context.marker &&
|
|
498
|
+
match: (args) => bridge.id === args.context.marker && match(args),
|
|
495
499
|
apply: (args) => apply(args),
|
|
496
500
|
applyWrapped: semantic,
|
|
497
501
|
}
|
|
498
502
|
}
|
|
499
503
|
semanticDef.where = semantic.where || bridge.where || helpers.where(4)
|
|
500
|
-
semanticDef.property =
|
|
504
|
+
semanticDef.property = property
|
|
501
505
|
if (semantic.priority) {
|
|
502
506
|
semanticDef.priority = semantic.priority
|
|
503
507
|
}
|
|
@@ -509,22 +513,8 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
509
513
|
}
|
|
510
514
|
}
|
|
511
515
|
|
|
512
|
-
if (bridge.evaluator) {
|
|
513
|
-
addSemantic(bridge.evaluator, true)
|
|
514
|
-
}
|
|
515
|
-
|
|
516
516
|
if (bridge.semantic) {
|
|
517
|
-
addSemantic(bridge.semantic, false)
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (bridge.evaluators) {
|
|
521
|
-
const evaluators = [...bridge.evaluators]
|
|
522
|
-
evaluators.reverse()
|
|
523
|
-
if (evaluators) {
|
|
524
|
-
for (const evaluator of evaluators) {
|
|
525
|
-
addSemantic(evaluator, true)
|
|
526
|
-
}
|
|
527
|
-
}
|
|
517
|
+
addSemantic(bridge.semantic, false, 'semantic')
|
|
528
518
|
}
|
|
529
519
|
|
|
530
520
|
if (bridge.semantics) {
|
|
@@ -556,8 +546,6 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
556
546
|
'convolution',
|
|
557
547
|
'disabled',
|
|
558
548
|
'enhanced_associations',
|
|
559
|
-
'evaluator',
|
|
560
|
-
'evaluators',
|
|
561
549
|
'generatorp',
|
|
562
550
|
'generatorpr',
|
|
563
551
|
'generatorr',
|
|
@@ -996,9 +984,10 @@ class Config {
|
|
|
996
984
|
|
|
997
985
|
async fixtures () {
|
|
998
986
|
if (this.testConfig?.fixtures) {
|
|
999
|
-
const args = {
|
|
987
|
+
const args = {
|
|
988
|
+
}
|
|
1000
989
|
args.uuid = this._uuid
|
|
1001
|
-
configHelpers.setupArgs(args, this)
|
|
990
|
+
configHelpers.setupArgs(args, this, this.logs)
|
|
1002
991
|
return this.testConfig.fixtures(args)
|
|
1003
992
|
}
|
|
1004
993
|
}
|
|
@@ -1029,6 +1018,7 @@ class Config {
|
|
|
1029
1018
|
return {
|
|
1030
1019
|
pseudo: true,
|
|
1031
1020
|
description: 'this is a pseudo config that has limited functionality due to being available in the initializer and fixtures function context',
|
|
1021
|
+
nextFragmentContextId: () => this.nextFragmentContextId(),
|
|
1032
1022
|
addAssociation: (...args) => this.addAssociation(...args),
|
|
1033
1023
|
addAssociations: (...args) => this.addAssociations(...args),
|
|
1034
1024
|
addBridge: (...args) => this.addBridge(...args, uuid),
|
|
@@ -1043,6 +1033,7 @@ class Config {
|
|
|
1043
1033
|
addPattern: (...args) => this.addPattern(...args, uuid),
|
|
1044
1034
|
updateBridge: (...args) => this.updateBridge(...args),
|
|
1045
1035
|
processContext: (...args) => this.processContext(...args),
|
|
1036
|
+
logs: this.logs,
|
|
1046
1037
|
|
|
1047
1038
|
semantics: () => this.config.semantics,
|
|
1048
1039
|
getConfigs: () => this.configs,
|
|
@@ -1242,7 +1233,7 @@ class Config {
|
|
|
1242
1233
|
|
|
1243
1234
|
warningNotEvaluated (log, value) {
|
|
1244
1235
|
const description = 'WARNING: for semantics, implement an evaluations handler, set "value" property of the operator to the value.'
|
|
1245
|
-
const match = `({context}) => context.marker === '${value.marker}' &&
|
|
1236
|
+
const match = `({context}) => context.marker === '${value.marker}' && <other conditions as you like>`
|
|
1246
1237
|
const apply = '({context}) => <do stuff...>; context.value = <value>'
|
|
1247
1238
|
const input = indent(JSON.stringify(value, null, 2), 2)
|
|
1248
1239
|
const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
|
|
@@ -1251,18 +1242,15 @@ class Config {
|
|
|
1251
1242
|
|
|
1252
1243
|
// value is in response field
|
|
1253
1244
|
// TODO maybe generalize out query+evaluate along the lines of set value and set reference
|
|
1254
|
-
async
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
1245
|
+
async evaluate (args, logs, context) {
|
|
1246
|
+
const apply = (c) => this.getSemantics(logs).apply(args, c)
|
|
1247
|
+
const instance = await apply(context)
|
|
1248
|
+
if (typeof instance !== 'string') {
|
|
1249
|
+
args.calls.touch(instance)
|
|
1259
1250
|
}
|
|
1260
|
-
if (instance.evalue == null) {
|
|
1261
|
-
|
|
1262
|
-
instance.edefault = true
|
|
1251
|
+
if (instance.evalue == null && !instance.verbatim && !instance.value) {
|
|
1252
|
+
this.warningNotEvaluated(logs, context)
|
|
1263
1253
|
}
|
|
1264
|
-
delete instance.evaluate
|
|
1265
|
-
instance.instance = true
|
|
1266
1254
|
return instance
|
|
1267
1255
|
}
|
|
1268
1256
|
|
|
@@ -1293,10 +1281,14 @@ class Config {
|
|
|
1293
1281
|
let fi = fragmentInstantiator(args, fragment.contexts)
|
|
1294
1282
|
if (mappings) {
|
|
1295
1283
|
fi = await fi
|
|
1296
|
-
|
|
1284
|
+
const instantiated = await fi.instantiate([{
|
|
1297
1285
|
match: ({context}) => !!mappings[context.value], // is the value in the mappings
|
|
1298
1286
|
apply: ({context}) => Object.assign(context, mappings[context.value]),
|
|
1299
|
-
}])
|
|
1287
|
+
}], fragment.key?.preserve)
|
|
1288
|
+
if (process.env.DEBUG_CONTEXT_ID && process.env.DEBUG_CONTEXT_ID == instantiated.context_id) {
|
|
1289
|
+
debugger
|
|
1290
|
+
}
|
|
1291
|
+
return instantiated
|
|
1300
1292
|
} else {
|
|
1301
1293
|
return fi
|
|
1302
1294
|
}
|
|
@@ -1396,8 +1388,6 @@ class Config {
|
|
|
1396
1388
|
delete bridge.generatorp
|
|
1397
1389
|
delete bridge.generatorr
|
|
1398
1390
|
delete bridge.generatorpr
|
|
1399
|
-
delete bridge.evaluator
|
|
1400
|
-
delete bridge.evaluators
|
|
1401
1391
|
delete bridge.semantic
|
|
1402
1392
|
delete bridge.semantics
|
|
1403
1393
|
if (false && !bridge.bridge) {
|
|
@@ -2179,6 +2169,12 @@ class Config {
|
|
|
2179
2169
|
// await this.demoInitializer(this)
|
|
2180
2170
|
}
|
|
2181
2171
|
|
|
2172
|
+
nextFragmentContextId() {
|
|
2173
|
+
const id = this.fragmentNextContextId
|
|
2174
|
+
this.fragmentNextContextId = this.fragmentNextContextId + 1
|
|
2175
|
+
return id
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2182
2178
|
// configs = [ { config, namespace } ... ]
|
|
2183
2179
|
constructor (config, module, clientProcess, apiKMs, rootIsProcess, testingModuleName) {
|
|
2184
2180
|
if (config instanceof Config) {
|
|
@@ -2189,6 +2185,8 @@ class Config {
|
|
|
2189
2185
|
apiKMs = []
|
|
2190
2186
|
}
|
|
2191
2187
|
|
|
2188
|
+
this.fragmentNextContextId = 1000
|
|
2189
|
+
|
|
2192
2190
|
if (config) {
|
|
2193
2191
|
validConfigProps(config)
|
|
2194
2192
|
|
package/src/configHelpers.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
const { InitCalls } = require('./helpers')
|
|
1
|
+
const { InitCalls, where } = require('./helpers')
|
|
2
2
|
const DigraphInternal = require('./digraph_internal')
|
|
3
3
|
const debug = require('./debug')
|
|
4
4
|
|
|
5
|
+
class ErrorReason extends Error {
|
|
6
|
+
constructor (context, stack) {
|
|
7
|
+
super(JSON.stringify(context))
|
|
8
|
+
this.reason = context
|
|
9
|
+
this.stack = stack
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
toString() {
|
|
13
|
+
if (this.reason) {
|
|
14
|
+
return this.reason
|
|
15
|
+
} else {
|
|
16
|
+
return super.toString()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
5
22
|
const gs = (g) => async (contexts, separator, lastSeparator) => {
|
|
6
23
|
if (!Array.isArray(contexts)) {
|
|
7
24
|
throw new Error('Expected a list')
|
|
@@ -63,13 +80,6 @@ const isA = (hierarchy) => (child, parent, { strict = false } = {}) => {
|
|
|
63
80
|
}
|
|
64
81
|
}
|
|
65
82
|
|
|
66
|
-
class ErrorReason extends Error {
|
|
67
|
-
constructor (context) {
|
|
68
|
-
super(JSON.stringify(context))
|
|
69
|
-
this.reason = context
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
83
|
const cleanAssign = (dest, ...srcs) => {
|
|
74
84
|
for (const key in dest) {
|
|
75
85
|
let found = false
|
|
@@ -93,13 +103,38 @@ class HandlerStack {
|
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
push(handler) {
|
|
96
|
-
this.handlers.push(handler)
|
|
106
|
+
this.handlers.push(handler.where || handler)
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
pop() {
|
|
100
110
|
this.handlers.pop()
|
|
101
111
|
}
|
|
102
112
|
|
|
113
|
+
/*
|
|
114
|
+
async wrap(call, w) {
|
|
115
|
+
const s = w
|
|
116
|
+
this.push(w)
|
|
117
|
+
const p = call()
|
|
118
|
+
if (p) {
|
|
119
|
+
return p.finally(() => {
|
|
120
|
+
this.pop()
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
async wrap(call, w) {
|
|
127
|
+
this.push(w)
|
|
128
|
+
const p = call()
|
|
129
|
+
if (p && typeof p.finally === 'function') {
|
|
130
|
+
return p.finally(() => {
|
|
131
|
+
this.pop()
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
this.pop()
|
|
135
|
+
return p
|
|
136
|
+
}
|
|
137
|
+
|
|
103
138
|
toString() {
|
|
104
139
|
let str = ''
|
|
105
140
|
for (let i = this.handlers.length - 1; i >= 0; --i) {
|
|
@@ -185,7 +220,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
185
220
|
args.km = (name) => config.getConfig(name)
|
|
186
221
|
args.api = (name) => config.getConfig(name).api
|
|
187
222
|
args.error = (context) => {
|
|
188
|
-
throw new ErrorReason(context)
|
|
223
|
+
throw new ErrorReason(context, [...args.stack.handlers, where()])
|
|
189
224
|
}
|
|
190
225
|
args.kms = config.getConfigs()
|
|
191
226
|
args.config = config.getPseudoConfig(uuidForScoping, config)
|
|
@@ -205,8 +240,6 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
205
240
|
args.theDebugger = {
|
|
206
241
|
breakOnSemantics: (value) => args.breakOnSemantics = value
|
|
207
242
|
}
|
|
208
|
-
if (!logs) {
|
|
209
|
-
}
|
|
210
243
|
args.log = (message) => logs.push(message)
|
|
211
244
|
|
|
212
245
|
args.addWord = (word, def) => config.addWord(word, def, args.uuid)
|
|
@@ -221,7 +254,6 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
221
254
|
return { ...args, assumed: Object.assign({}, assumed, (args.assumed || {}), ...moreAssumed) }
|
|
222
255
|
}
|
|
223
256
|
|
|
224
|
-
args.s = (c, options = {}) => config.getSemantics(logs).apply(args, c, options)
|
|
225
257
|
args.g = (c, rest = {}) => {
|
|
226
258
|
// if (JSON.stringify(rest) !== '{}' && !(rest.assumed || rest.options)) {
|
|
227
259
|
// debugger
|
|
@@ -256,12 +288,18 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
256
288
|
const { assumed = {}, options = {} } = rest
|
|
257
289
|
return config.getGenerators(logs).apply(addAssumed(args, assumed, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true }, options)
|
|
258
290
|
}
|
|
259
|
-
|
|
291
|
+
|
|
292
|
+
args.e = (c, where) => {
|
|
260
293
|
if (!c) {
|
|
261
294
|
return
|
|
262
295
|
}
|
|
263
|
-
|
|
296
|
+
if (where) {
|
|
297
|
+
return args.stack.wrap(() => config.evaluate(args, logs, c), where)
|
|
298
|
+
} else {
|
|
299
|
+
return config.evaluate(args, logs, c)
|
|
300
|
+
}
|
|
264
301
|
}
|
|
302
|
+
|
|
265
303
|
args.gs = gs(args.g)
|
|
266
304
|
args.gsp = gs(args.gp)
|
|
267
305
|
args.gsr = gs(args.gr)
|
|
@@ -346,7 +384,7 @@ const processContext = async (context, { objects = {}, config, logs = [] }) => {
|
|
|
346
384
|
return { context, generated, paraphrases, responses }
|
|
347
385
|
}
|
|
348
386
|
|
|
349
|
-
const setupProcessB = ({ config, initializer, allowDelta = false, rebuildingTemplate = false } = {}) => {
|
|
387
|
+
const setupProcessB = ({ config, initializer, isFragment, allowDelta = false, rebuildingTemplate = false } = {}) => {
|
|
350
388
|
const key = config._key
|
|
351
389
|
const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
|
|
352
390
|
/*
|
|
@@ -411,7 +449,7 @@ const setupContexts = (rawContexts) => {
|
|
|
411
449
|
return contexts
|
|
412
450
|
}
|
|
413
451
|
|
|
414
|
-
const processContextsB = async ({ config, calls, hierarchy, logs, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
452
|
+
const processContextsB = async ({ skipSemantics, isFragment, config, calls, hierarchy, logs, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
415
453
|
// TODO fix this name to contextsPrime
|
|
416
454
|
const contextsPrime = []
|
|
417
455
|
const generatedPrime = []
|
|
@@ -419,6 +457,7 @@ const processContextsB = async ({ config, calls, hierarchy, logs, semantics, gen
|
|
|
419
457
|
const paraphrasesParenthesizedPrime = []
|
|
420
458
|
const generatedParenthesizedPrime = []
|
|
421
459
|
const responsesPrime = []
|
|
460
|
+
|
|
422
461
|
const contexts = setupContexts(json.contexts)
|
|
423
462
|
|
|
424
463
|
const objects = config.get('objects')
|
|
@@ -440,7 +479,7 @@ const processContextsB = async ({ config, calls, hierarchy, logs, semantics, gen
|
|
|
440
479
|
throw new Error('There are errors in the logs. Run with the -d flag and grep for Error')
|
|
441
480
|
}
|
|
442
481
|
const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
|
|
443
|
-
if (!config.get('skipSemantics')) {
|
|
482
|
+
if (!config.get('skipSemantics') && !skipSemantics) {
|
|
444
483
|
const semantics = config.getSemantics(logs)
|
|
445
484
|
try {
|
|
446
485
|
contextPrime = await semantics.apply(args, context)
|
|
@@ -455,17 +494,18 @@ const processContextsB = async ({ config, calls, hierarchy, logs, semantics, gen
|
|
|
455
494
|
if (isInstance) {
|
|
456
495
|
console.log('error', e.error)
|
|
457
496
|
}
|
|
497
|
+
|
|
458
498
|
let reason = e.reason
|
|
459
499
|
if (!reason) {
|
|
460
500
|
if (e.error) {
|
|
461
501
|
reason = e.error[0]
|
|
462
502
|
}
|
|
463
503
|
}
|
|
504
|
+
|
|
464
505
|
contextPrime = await semantics.apply(args, {
|
|
465
506
|
marker: 'error',
|
|
466
507
|
context,
|
|
467
|
-
text: e
|
|
468
|
-
// reason: e.reason,
|
|
508
|
+
text: e.toString(),
|
|
469
509
|
reason,
|
|
470
510
|
error: e.stack || e.error
|
|
471
511
|
})
|
|
@@ -578,14 +618,14 @@ const loadInstance = async (config, instance) => {
|
|
|
578
618
|
// used to do a CLONE
|
|
579
619
|
config.addInternal(instance.template.configs[i], { uuid, km: instance.name, addFirst: true, handleCalculatedProps: true })
|
|
580
620
|
} else if (results.apply) {
|
|
581
|
-
const
|
|
621
|
+
const uuid = config.nameToUUID(instance.name)
|
|
622
|
+
const objects = getObjects(config.get('objects'))(uuid)
|
|
582
623
|
const args = { objects, getObjects: getObjects(objects) }
|
|
583
624
|
if (instance.configs) {
|
|
584
625
|
args.isInstance = `instance${i}`
|
|
585
626
|
args.instance = instance.configs[i]
|
|
586
627
|
}
|
|
587
628
|
|
|
588
|
-
const uuid = config.nameToUUID(instance.name)
|
|
589
629
|
setupArgs(args, config, config.logs, hierarchy, uuid)
|
|
590
630
|
if (config.name == instance.name) {
|
|
591
631
|
args.isModule = !!config.isModule
|
|
@@ -609,6 +649,7 @@ const loadInstance = async (config, instance) => {
|
|
|
609
649
|
args.instance = ''
|
|
610
650
|
args.isProcess = !config.isModule
|
|
611
651
|
args.isModule = !!config.isModule
|
|
652
|
+
args.logs = config.logs
|
|
612
653
|
if (instance.name == config.testConfig.testModuleName) {
|
|
613
654
|
args.isTesting = true
|
|
614
655
|
}
|
package/src/fragments.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
|
+
const debug = require('./debug')
|
|
2
3
|
const helpers = require('./helpers')
|
|
3
4
|
|
|
4
5
|
function createChangeTracker(obj) {
|
|
@@ -28,11 +29,23 @@ function fragmentInstantiator (args, contexts) {
|
|
|
28
29
|
contexts: () => {
|
|
29
30
|
return _.cloneDeep(contexts)
|
|
30
31
|
},
|
|
31
|
-
|
|
32
|
+
// preserve property not to be changed.
|
|
33
|
+
instantiate: async (mappings, preserve) => {
|
|
34
|
+
preserve = preserve || []
|
|
32
35
|
const instantiated = _.cloneDeep(contexts)
|
|
33
36
|
const todo = [{ context: instantiated, path: [] }]
|
|
34
37
|
args = { ...args }
|
|
35
38
|
args.pathEquals = helpers.pathEquals
|
|
39
|
+
const preserved = preserve.map((path) => {
|
|
40
|
+
if (contexts.length == 1) {
|
|
41
|
+
path = ['0', path]
|
|
42
|
+
}
|
|
43
|
+
const value = helpers.getByPath(contexts, path)
|
|
44
|
+
return { path, value }
|
|
45
|
+
})
|
|
46
|
+
for (const context of contexts) {
|
|
47
|
+
context.context_id = args.config.nextFragmentContextId()
|
|
48
|
+
}
|
|
36
49
|
while (todo.length > 0) {
|
|
37
50
|
const { context, path } = todo.pop()
|
|
38
51
|
const { proxy, getChanges } = createChangeTracker(context);
|
|
@@ -57,6 +70,9 @@ function fragmentInstantiator (args, contexts) {
|
|
|
57
70
|
}
|
|
58
71
|
}
|
|
59
72
|
}
|
|
73
|
+
for (const { path, value } of preserved) {
|
|
74
|
+
helpers.setByPath(instantiated, path, value)
|
|
75
|
+
}
|
|
60
76
|
if (contexts.length == 1 && instantiated.length == 1) {
|
|
61
77
|
return instantiated[0]
|
|
62
78
|
} else {
|
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 {
|
|
@@ -225,18 +225,18 @@ class Generators {
|
|
|
225
225
|
const source = `${generator.km}/#${generator.index}`
|
|
226
226
|
lines.setElement(0, 2, `ERROR while applying (${source}) ${generator.toLabel()}`)
|
|
227
227
|
lines.newRow()
|
|
228
|
+
lines.setElement(0, 1, 'DEBUG')
|
|
229
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
230
|
+
lines.newRow()
|
|
231
|
+
lines.setElement(0, 1, 'STACK')
|
|
232
|
+
lines.setElement(0, 2, stack)
|
|
233
|
+
lines.newRow()
|
|
228
234
|
lines.setElement(0, 2, generator.toString())
|
|
229
235
|
lines.newRow()
|
|
230
236
|
lines.setElement(0, 1, 'TO')
|
|
231
237
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
232
238
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 10 }), null, 2))
|
|
233
239
|
lines.newRow()
|
|
234
|
-
lines.setElement(0, 1, 'STACK')
|
|
235
|
-
lines.setElement(0, 2, stack)
|
|
236
|
-
lines.newRow()
|
|
237
|
-
lines.setElement(0, 1, 'DEBUG')
|
|
238
|
-
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') or DEBUG_CALLID="${args.calls.current()}"`)
|
|
239
|
-
lines.newRow()
|
|
240
240
|
lines.setElement(0, 1, 'ERROR')
|
|
241
241
|
lines.setElement(0, 2, errorMessage)
|
|
242
242
|
this.logs.push(lines.toString())
|
|
@@ -259,14 +259,14 @@ class Generators {
|
|
|
259
259
|
lines.setElement(0, 1, 'APPLIED')
|
|
260
260
|
lines.setElement(0, 2, generator.toLabel())
|
|
261
261
|
lines.newRow()
|
|
262
|
-
lines.setElement(0, 2, generator.toString())
|
|
263
|
-
lines.newRow()
|
|
264
262
|
lines.setElement(0, 1, 'RESULT')
|
|
265
263
|
lines.setElement(0, 2, generated + " " + pOrRTag)
|
|
266
264
|
lines.newRow()
|
|
267
265
|
lines.setElement(0, 1, 'STACK')
|
|
268
266
|
lines.setElement(0, 2, stack)
|
|
269
267
|
lines.newRow()
|
|
268
|
+
lines.setElement(0, 2, generator.toString())
|
|
269
|
+
lines.newRow()
|
|
270
270
|
lines.setElement(0, 1, 'DEBUG')
|
|
271
271
|
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
|
|
272
272
|
lines.newRow()
|
package/src/helpers.js
CHANGED
|
@@ -72,7 +72,14 @@ function where (goUp = 2) {
|
|
|
72
72
|
let match
|
|
73
73
|
for (line of lines.slice(1)) {
|
|
74
74
|
// if (!(line.includes('config.js:') || line.includes('client.js:') || line.includes('<anonymous>'))) {
|
|
75
|
-
|
|
75
|
+
const ignore = [
|
|
76
|
+
'config.js:',
|
|
77
|
+
'client.js:',
|
|
78
|
+
'helpers.js:',
|
|
79
|
+
'configHelpers.js:',
|
|
80
|
+
]
|
|
81
|
+
// if (!(line.includes('config.js:') || line.includes('client.js:') || line.includes('helpers.js:'))) {
|
|
82
|
+
if(!ignore.some(p => line.includes(p))) {
|
|
76
83
|
match = regexForm1.exec(line) || regexForm2.exec(line)
|
|
77
84
|
if (!match) {
|
|
78
85
|
continue
|
|
@@ -477,12 +484,6 @@ const functionsToStrings = (config) => {
|
|
|
477
484
|
if (bridge.semantics) {
|
|
478
485
|
bridge.semantics = bridge.semantics.toString()
|
|
479
486
|
}
|
|
480
|
-
if (bridge.evaluator) {
|
|
481
|
-
bridge.evaluator = bridge.evaluator.toString()
|
|
482
|
-
}
|
|
483
|
-
if (bridge.evaluators) {
|
|
484
|
-
bridge.evaluators = bridge.evaluators.toString()
|
|
485
|
-
}
|
|
486
487
|
return bridge
|
|
487
488
|
})
|
|
488
489
|
}
|
|
@@ -715,4 +716,5 @@ module.exports = {
|
|
|
715
716
|
watchProperty,
|
|
716
717
|
pathEquals,
|
|
717
718
|
OverrideCheck,
|
|
719
|
+
normalizePath,
|
|
718
720
|
}
|
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) {
|
|
@@ -259,24 +259,27 @@ class Semantics {
|
|
|
259
259
|
const source = `${semantic.km}/#${semantic.index}`
|
|
260
260
|
lines.setElement(0, 2, `ERROR while applying (${source}) ${semantic.toLabel()}`)
|
|
261
261
|
lines.newRow()
|
|
262
|
-
lines.setElement(0, 2, semantic.toString())
|
|
263
|
-
lines.newRow()
|
|
264
262
|
lines.setElement(0, 1, 'DEBUG')
|
|
265
|
-
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or
|
|
263
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
264
|
+
lines.newRow()
|
|
265
|
+
lines.setElement(0, 1, 'STACK')
|
|
266
|
+
lines.setElement(0, 2, stack)
|
|
267
|
+
lines.newRow()
|
|
268
|
+
lines.setElement(0, 2, semantic.toString())
|
|
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())
|
|
277
277
|
const message = `ERROR while applying (${source}) ${semantic.toLabel()}\n to\n ${JSON.stringify(context, null, 2)}.\n${errorMessage}'`
|
|
278
278
|
// this.logs.push(message)
|
|
279
279
|
// return [message]
|
|
280
|
+
if (e.reason) {
|
|
281
|
+
throw e
|
|
282
|
+
}
|
|
280
283
|
args.calls.pop()
|
|
281
284
|
throw { error: [message], logs: this.logs, reason: e.reason }
|
|
282
285
|
}
|
|
@@ -295,18 +298,18 @@ class Semantics {
|
|
|
295
298
|
lines.setElement(0, 1, 'APPLIED')
|
|
296
299
|
lines.setElement(0, 2, semantic.toLabel())
|
|
297
300
|
lines.newRow()
|
|
298
|
-
lines.setElement(0, 2, semantic.toString())
|
|
299
|
-
lines.newRow()
|
|
300
301
|
lines.setElement(0, 1, 'DEBUG')
|
|
301
|
-
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or
|
|
302
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
303
|
+
lines.newRow()
|
|
304
|
+
lines.setElement(0, 1, 'STACK')
|
|
305
|
+
lines.setElement(0, 2, stack)
|
|
306
|
+
lines.newRow()
|
|
307
|
+
lines.setElement(0, 2, semantic.toString())
|
|
302
308
|
lines.newRow()
|
|
303
309
|
lines.setElement(0, 1, 'TO')
|
|
304
310
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
305
311
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
|
306
312
|
lines.newRow()
|
|
307
|
-
lines.setElement(0, 1, 'STACK')
|
|
308
|
-
lines.setElement(0, 2, stack)
|
|
309
|
-
lines.newRow()
|
|
310
313
|
lines.setElement(0, 1, 'RESULT')
|
|
311
314
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
312
315
|
lines.setElement(1, 2, JSON.stringify(contextPrime, null, 2))
|
|
@@ -332,7 +335,6 @@ class Semantics {
|
|
|
332
335
|
for (const f of finallyList) {
|
|
333
336
|
await f()
|
|
334
337
|
}
|
|
335
|
-
args.calls.pop()
|
|
336
338
|
if (!applied && debug) {
|
|
337
339
|
const widths = Lines.addRemainder([10, 10])
|
|
338
340
|
const lines = new Lines(widths)
|
|
@@ -340,6 +342,9 @@ class Semantics {
|
|
|
340
342
|
lines.setElement(0, 1, `#${context.context_id || "?"}`)
|
|
341
343
|
lines.setElement(0, 2, 'No semantic applied')
|
|
342
344
|
lines.newRow()
|
|
345
|
+
lines.setElement(0, 1, 'DEBUG')
|
|
346
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
347
|
+
lines.newRow()
|
|
343
348
|
lines.setElement(0, 1, 'STACK')
|
|
344
349
|
lines.setElement(0, 2, stack)
|
|
345
350
|
lines.newRow()
|
|
@@ -348,6 +353,7 @@ class Semantics {
|
|
|
348
353
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
|
349
354
|
this.logs.push(lines.toString())
|
|
350
355
|
}
|
|
356
|
+
args.calls.pop()
|
|
351
357
|
return contextPrime
|
|
352
358
|
}
|
|
353
359
|
|