theprogrammablemind_4wp 8.0.0-beta.20 → 8.0.0-beta.22
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +32 -38
- package/package.json +1 -1
- package/src/config.js +68 -144
- package/src/generators.js +8 -8
- package/src/semantics.js +15 -15
package/client.js
CHANGED
@@ -237,9 +237,8 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
237
237
|
config.setArgs(args)
|
238
238
|
}
|
239
239
|
|
240
|
-
const gs = (g) => (contexts, separator, lastSeparator) => {
|
240
|
+
const gs = (g) => async (contexts, separator, lastSeparator) => {
|
241
241
|
if (!Array.isArray(contexts)) {
|
242
|
-
debugger
|
243
242
|
throw new Error('Expected a list')
|
244
243
|
}
|
245
244
|
|
@@ -253,7 +252,7 @@ const gs = (g) => (contexts, separator, lastSeparator) => {
|
|
253
252
|
let nextSeparator = ''
|
254
253
|
for (let i = 0; i < contexts.length; ++i) {
|
255
254
|
const context = contexts[i]
|
256
|
-
const value = g(context)
|
255
|
+
const value = await g(context)
|
257
256
|
if (i > 0) {
|
258
257
|
if (i === contexts.length - 1) {
|
259
258
|
nextSeparator = lastSeparator
|
@@ -290,12 +289,12 @@ const analyzeMetaData = (right, wrong) => {
|
|
290
289
|
return []
|
291
290
|
}
|
292
291
|
|
293
|
-
const processContexts = (contexts, params) => {
|
292
|
+
const processContexts = async (contexts, params) => {
|
294
293
|
const contextsPrime = []
|
295
294
|
const generated = []
|
296
295
|
const logs = []
|
297
296
|
for (const context of contexts) {
|
298
|
-
const result = processContext(context, Object.assign({}, params, { logs }))
|
297
|
+
const result = await processContext(context, Object.assign({}, params, { logs }))
|
299
298
|
contextsPrime.push(result.context)
|
300
299
|
generated.push(result.generated)
|
301
300
|
}
|
@@ -311,7 +310,7 @@ const getObjects = (objects) => {
|
|
311
310
|
}
|
312
311
|
}
|
313
312
|
|
314
|
-
const processContext = (context, { objects = {}, config, logs = [] }) => {
|
313
|
+
const processContext = async (context, { objects = {}, config, logs = [] }) => {
|
315
314
|
const generators = config.getGenerators(logs)
|
316
315
|
const semantics = config.getSemantics(logs)
|
317
316
|
|
@@ -329,10 +328,10 @@ const processContext = (context, { objects = {}, config, logs = [] }) => {
|
|
329
328
|
const args = { objects, response, getObjects: getObjects(objects) }
|
330
329
|
setupArgs(args, config, logs, hierarchy)
|
331
330
|
|
332
|
-
context = semantics.apply(args, context)
|
333
|
-
const generated = generators.apply(args, context)
|
331
|
+
context = await semantics.apply(args, context)
|
332
|
+
const generated = await generators.apply(args, context)
|
334
333
|
const assumed = { paraphrase: true, response: false, isResponse: false }
|
335
|
-
const paraphrases = generators.apply({ ...args, assumed }, context, { paraphrase: true, response: false, isResponse: false })
|
334
|
+
const paraphrases = await generators.apply({ ...args, assumed }, context, { paraphrase: true, response: false, isResponse: false })
|
336
335
|
let responses = []
|
337
336
|
if (context.isResponse) {
|
338
337
|
responses = generated
|
@@ -447,7 +446,7 @@ const setupContexts = (rawContexts) => {
|
|
447
446
|
return contexts
|
448
447
|
}
|
449
448
|
|
450
|
-
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
|
449
|
+
const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
|
451
450
|
// TODO fix this name to contextsPrime
|
452
451
|
const contextsPrime = []
|
453
452
|
const generatedPrime = []
|
@@ -480,7 +479,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
480
479
|
if (!config.get('skipSemantics')) {
|
481
480
|
const semantics = config.getSemantics(json.logs)
|
482
481
|
try {
|
483
|
-
contextPrime = semantics.apply(args, context)
|
482
|
+
contextPrime = await semantics.apply(args, context)
|
484
483
|
} catch (e) {
|
485
484
|
if (e.message == 'Maximum call stack size exceeded') {
|
486
485
|
const mostCalled = semantics.getMostCalled()
|
@@ -490,7 +489,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
490
489
|
if (isInstance) {
|
491
490
|
console.log('error', e.error)
|
492
491
|
}
|
493
|
-
contextPrime = semantics.apply(args, {
|
492
|
+
contextPrime = await semantics.apply(args, {
|
494
493
|
marker: 'error',
|
495
494
|
context,
|
496
495
|
text: e ? e.toString() : 'not available',
|
@@ -506,11 +505,11 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
506
505
|
continue
|
507
506
|
}
|
508
507
|
let assumed = { isResponse: true }
|
509
|
-
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
508
|
+
const generated = contextPrime.isResponse ? await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
510
509
|
let generatedParenthesized = []
|
511
510
|
if (generateParenthesized) {
|
512
511
|
config.parenthesized = true
|
513
|
-
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
512
|
+
generatedParenthesized = contextPrime.isResponse ? await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
514
513
|
config.parenthesized = false
|
515
514
|
}
|
516
515
|
// assumed = { paraphrase: true, response: false };
|
@@ -518,11 +517,11 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
518
517
|
if (generateParenthesized) {
|
519
518
|
config.parenthesized = false
|
520
519
|
}
|
521
|
-
const paraphrases = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
520
|
+
const paraphrases = await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
522
521
|
let paraphrasesParenthesized = []
|
523
522
|
if (generateParenthesized) {
|
524
523
|
config.parenthesized = true
|
525
|
-
paraphrasesParenthesized = config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
524
|
+
paraphrasesParenthesized = await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
|
526
525
|
config.parenthesized = false
|
527
526
|
}
|
528
527
|
contextsPrime.push(contextPrime)
|
@@ -634,7 +633,7 @@ const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
|
|
634
633
|
}
|
635
634
|
|
636
635
|
// instance template loadTemplate
|
637
|
-
const loadInstance = (config, instance) => {
|
636
|
+
const loadInstance = async (config, instance) => {
|
638
637
|
const transitoryMode = global.transitoryMode
|
639
638
|
global.transitoryMode = false
|
640
639
|
|
@@ -668,7 +667,7 @@ const loadInstance = (config, instance) => {
|
|
668
667
|
|
669
668
|
const uuid = config.nameToUUID(instance.name)
|
670
669
|
setupArgs(args, config, config.logs, hierarchy, uuid)
|
671
|
-
results.apply(args)
|
670
|
+
await results.apply(args)
|
672
671
|
} else {
|
673
672
|
if (results.skipSemantics) {
|
674
673
|
config.config.skipSemantics = results.skipSemantics
|
@@ -676,7 +675,7 @@ const loadInstance = (config, instance) => {
|
|
676
675
|
const args = { config, hierarchy, json: results, commandLineArgs: {} }
|
677
676
|
args.isInstance = `instance${i}`
|
678
677
|
args.instance = ''
|
679
|
-
processContextsB(args)
|
678
|
+
await processContextsB(args)
|
680
679
|
if (results.skipSemantics) {
|
681
680
|
config.config.skipSemantics = null
|
682
681
|
}
|
@@ -701,7 +700,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
701
700
|
// ensure same start state
|
702
701
|
try {
|
703
702
|
if (writeTests) {
|
704
|
-
config.rebuild()
|
703
|
+
await config.rebuild()
|
705
704
|
const objects = getObjects(config.config.objects)(config.uuid)
|
706
705
|
}
|
707
706
|
} catch (error) {
|
@@ -773,7 +772,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
773
772
|
start = runtime.performance.performance.now()
|
774
773
|
}
|
775
774
|
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
776
|
-
processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
775
|
+
await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
777
776
|
if (isTest) {
|
778
777
|
end = runtime.performance.performance.now()
|
779
778
|
clientSideTime = end - start
|
@@ -870,7 +869,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
|
|
870
869
|
return
|
871
870
|
}
|
872
871
|
// initialize in between test so state is not preserved since the test was adding without state
|
873
|
-
config.rebuild()
|
872
|
+
await config.rebuild()
|
874
873
|
const errorHandler = (error) => {
|
875
874
|
if (error.metadata) {
|
876
875
|
const priorities = analyzeMetaData(expected.metadata, error.metadata)
|
@@ -1016,7 +1015,7 @@ const runTests = async (config, testFile, juicyBits) => {
|
|
1016
1015
|
}
|
1017
1016
|
|
1018
1017
|
const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
|
1019
|
-
config.rebuild()
|
1018
|
+
await config.rebuild()
|
1020
1019
|
const objects = getObjects(config.config.objects)(config.uuid)
|
1021
1020
|
console.log(test)
|
1022
1021
|
const result = await _process(config, test, { isTest: true })
|
@@ -1037,11 +1036,11 @@ const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDe
|
|
1037
1036
|
return
|
1038
1037
|
}
|
1039
1038
|
const test = todo.pop()
|
1040
|
-
config.rebuild()
|
1039
|
+
await config.rebuild()
|
1041
1040
|
const result = await saveTest(testFile, config, test, tests[test], testConfig, saveDeveloper)
|
1042
1041
|
// initialize in between test so state is not preserved since the test was adding without state
|
1043
1042
|
// config.initialize({force: true})
|
1044
|
-
config.rebuild()
|
1043
|
+
await config.rebuild()
|
1045
1044
|
return saveTestsHelper(testFile, config, tests, todo, testConfig, saveDeveloper)
|
1046
1045
|
}
|
1047
1046
|
|
@@ -1360,7 +1359,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
1360
1359
|
if (previousResults && previousResults.query == query.query) {
|
1361
1360
|
results = previousResults
|
1362
1361
|
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
1363
|
-
loadInstance(config, { resultss: [results] })
|
1362
|
+
await loadInstance(config, { resultss: [results] })
|
1364
1363
|
} else {
|
1365
1364
|
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
1366
1365
|
}
|
@@ -1632,7 +1631,7 @@ const knowledgeModuleImpl = async ({
|
|
1632
1631
|
global.pauseDebugging = true
|
1633
1632
|
}
|
1634
1633
|
|
1635
|
-
const config = createConfig()
|
1634
|
+
const config = await createConfig()
|
1636
1635
|
setupConfig(config)
|
1637
1636
|
processResults = processResults({ config, errorHandler })
|
1638
1637
|
|
@@ -1864,7 +1863,7 @@ const knowledgeModuleImpl = async ({
|
|
1864
1863
|
config.config.rebuild = true
|
1865
1864
|
}
|
1866
1865
|
try {
|
1867
|
-
config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1866
|
+
await config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1868
1867
|
} catch (e) {
|
1869
1868
|
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1870
1869
|
runtime.process.exit(-1)
|
@@ -2109,7 +2108,7 @@ const knowledgeModuleImpl = async ({
|
|
2109
2108
|
}
|
2110
2109
|
printConfig()
|
2111
2110
|
} else {
|
2112
|
-
const initConfig = (config) => {
|
2111
|
+
const initConfig = async (config) => {
|
2113
2112
|
if (template) {
|
2114
2113
|
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
|
2115
2114
|
const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
|
@@ -2144,24 +2143,19 @@ const knowledgeModuleImpl = async ({
|
|
2144
2143
|
|
2145
2144
|
if (template) {
|
2146
2145
|
try {
|
2147
|
-
config.load(template.template, template.instance)
|
2146
|
+
await config.load(template.template, template.instance)
|
2148
2147
|
} catch (e) {
|
2149
2148
|
errorHandler(e)
|
2150
2149
|
}
|
2151
2150
|
}
|
2152
2151
|
}
|
2153
2152
|
|
2154
|
-
createConfigExport = (
|
2153
|
+
createConfigExport = async () => {
|
2155
2154
|
if (createConfig.cached) {
|
2156
2155
|
return createConfig.cached
|
2157
2156
|
}
|
2158
|
-
const config = createConfig(
|
2159
|
-
|
2160
|
-
config.stop_auto_rebuild()
|
2161
|
-
additionalConfig(config)
|
2162
|
-
config.restart_auto_rebuild()
|
2163
|
-
}
|
2164
|
-
initConfig(config)
|
2157
|
+
const config = await createConfig()
|
2158
|
+
await initConfig(config)
|
2165
2159
|
// config.rebuild({ isModule: true })
|
2166
2160
|
createConfig.cached = config
|
2167
2161
|
return createConfig.cached
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -352,7 +352,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
352
352
|
|
353
353
|
const generator = {
|
354
354
|
where: bridge.generatorp.where || bridge.where || client.where(4),
|
355
|
-
match: (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && match(args),
|
355
|
+
match: async (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && await match(args),
|
356
356
|
apply: (args) => apply(args),
|
357
357
|
applyWrapped: apply,
|
358
358
|
property: 'generatorp'
|
@@ -369,7 +369,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
369
369
|
const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
|
370
370
|
const generator = {
|
371
371
|
where: bridge.generatorr.where || bridge.where || client.where(4),
|
372
|
-
match: (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && match(args),
|
372
|
+
match: async (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
|
373
373
|
apply: (args) => apply(args),
|
374
374
|
applyWrapped: apply,
|
375
375
|
property: 'generatorr'
|
@@ -564,7 +564,7 @@ function isLetter (char) {
|
|
564
564
|
}
|
565
565
|
*/
|
566
566
|
|
567
|
-
function configDup (config, options) {
|
567
|
+
async function configDup (config, options) {
|
568
568
|
if (config instanceof Config) {
|
569
569
|
return config.copy(options)
|
570
570
|
}
|
@@ -704,9 +704,9 @@ class KM {
|
|
704
704
|
return true
|
705
705
|
}
|
706
706
|
|
707
|
-
copy2 (options) {
|
707
|
+
async copy2 (options) {
|
708
708
|
// greg -> add a flag to say don't init the api's
|
709
|
-
const config = configDup(this._config, options)
|
709
|
+
const config = await configDup(this._config, options)
|
710
710
|
const km = new KM({
|
711
711
|
config,
|
712
712
|
getCounter: options.getCounter,
|
@@ -718,10 +718,10 @@ class KM {
|
|
718
718
|
return km // copy2()
|
719
719
|
}
|
720
720
|
|
721
|
-
copy () {
|
721
|
+
async copy () {
|
722
722
|
const km = new KM({
|
723
723
|
name: this._name,
|
724
|
-
config: configDup(this._config),
|
724
|
+
config: await configDup(this._config),
|
725
725
|
// _uuid: uuidv4(),
|
726
726
|
_uuid: this._config.getCounter(this._config._name),
|
727
727
|
getCounter: (name) => this._config.getCounter(name),
|
@@ -773,7 +773,7 @@ const multiApiImpl = (initializer) => {
|
|
773
773
|
multiApi: true,
|
774
774
|
|
775
775
|
// multi functions
|
776
|
-
add: (config, multiApi, api) => {
|
776
|
+
add: async (config, multiApi, api) => {
|
777
777
|
initializer(config, api)
|
778
778
|
const name = api.getName()
|
779
779
|
multiApi.apis[name] = api
|
@@ -811,17 +811,6 @@ class Config {
|
|
811
811
|
return config_toServer(config)
|
812
812
|
}
|
813
813
|
|
814
|
-
base () {
|
815
|
-
const base = new Config()
|
816
|
-
for (const km of this.configs.reverse()) {
|
817
|
-
if (km.isSelf) {
|
818
|
-
continue
|
819
|
-
}
|
820
|
-
base.add(km.config)
|
821
|
-
}
|
822
|
-
return base
|
823
|
-
}
|
824
|
-
|
825
814
|
getInfo () {
|
826
815
|
const name = this.name
|
827
816
|
const includes = this.configs.slice(1).map((km) => km.config.name)
|
@@ -1016,8 +1005,8 @@ class Config {
|
|
1016
1005
|
return instance
|
1017
1006
|
}
|
1018
1007
|
*/
|
1019
|
-
getEvaluator (s, calls, log, context) {
|
1020
|
-
const instance = s({ ...context, evaluate: true })
|
1008
|
+
async getEvaluator (s, calls, log, context) {
|
1009
|
+
const instance = await s({ ...context, evaluate: true })
|
1021
1010
|
calls.touch(instance)
|
1022
1011
|
if (!instance.evalue && !instance.verbatim && !instance.value) {
|
1023
1012
|
this.warningNotEvaluated(log, context)
|
@@ -1034,7 +1023,7 @@ class Config {
|
|
1034
1023
|
fragmentInstantiator (contexts) {
|
1035
1024
|
return new Object({
|
1036
1025
|
contexts: () => contexts,
|
1037
|
-
instantiate: (mappings) => {
|
1026
|
+
instantiate: async (mappings) => {
|
1038
1027
|
const instantiated = _.cloneDeep(contexts)
|
1039
1028
|
// const todo = [...instantiated]
|
1040
1029
|
// const todo = [...instantiated]
|
@@ -1042,8 +1031,8 @@ class Config {
|
|
1042
1031
|
while (todo.length > 0) {
|
1043
1032
|
const context = todo.pop()
|
1044
1033
|
for (const mapping of mappings) {
|
1045
|
-
if (mapping.match({ context })) {
|
1046
|
-
mapping.apply({ context })
|
1034
|
+
if (await mapping.match({ context })) {
|
1035
|
+
await mapping.apply({ context })
|
1047
1036
|
}
|
1048
1037
|
}
|
1049
1038
|
for (const key of Object.keys(context)) {
|
@@ -1237,7 +1226,7 @@ class Config {
|
|
1237
1226
|
}
|
1238
1227
|
|
1239
1228
|
// loadTemplate
|
1240
|
-
load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined }) {
|
1229
|
+
async load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined }) {
|
1241
1230
|
this.validifyTemplate(template)
|
1242
1231
|
instance.template = template
|
1243
1232
|
this.logs.push(`loading template for ${this.name}`)
|
@@ -1270,7 +1259,7 @@ class Config {
|
|
1270
1259
|
instance.name = this.name
|
1271
1260
|
this.initInstances.push(instance)
|
1272
1261
|
this.instances.push(instance)
|
1273
|
-
client.loadInstance(this, instance)
|
1262
|
+
await client.loadInstance(this, instance)
|
1274
1263
|
}
|
1275
1264
|
}
|
1276
1265
|
}
|
@@ -1629,12 +1618,8 @@ class Config {
|
|
1629
1618
|
return params
|
1630
1619
|
}
|
1631
1620
|
|
1632
|
-
|
1633
|
-
client.
|
1634
|
-
}
|
1635
|
-
|
1636
|
-
processContext (context) {
|
1637
|
-
return client.processContext(context, this.getParams())
|
1621
|
+
async processContext (context) {
|
1622
|
+
return await client.processContext(context, this.getParams())
|
1638
1623
|
}
|
1639
1624
|
|
1640
1625
|
process (query, options) {
|
@@ -1882,9 +1867,9 @@ class Config {
|
|
1882
1867
|
this._stop_auto_rebuild = true
|
1883
1868
|
}
|
1884
1869
|
|
1885
|
-
restart_auto_rebuild() {
|
1870
|
+
async restart_auto_rebuild() {
|
1886
1871
|
this._stop_auto_rebuild = false
|
1887
|
-
this.rebuild()
|
1872
|
+
await this.rebuild()
|
1888
1873
|
}
|
1889
1874
|
|
1890
1875
|
getAddedArgs (args) {
|
@@ -1903,8 +1888,8 @@ class Config {
|
|
1903
1888
|
}
|
1904
1889
|
}
|
1905
1890
|
|
1906
|
-
|
1907
|
-
this.
|
1891
|
+
async setMultiApi (initializer) {
|
1892
|
+
await this.setApi(multiApiImpl(initializer))
|
1908
1893
|
}
|
1909
1894
|
|
1910
1895
|
get multiApi () {
|
@@ -1952,31 +1937,26 @@ class Config {
|
|
1952
1937
|
}
|
1953
1938
|
}
|
1954
1939
|
|
1955
|
-
addAPI (api) {
|
1940
|
+
async addAPI (api) {
|
1941
|
+
// console.trace()
|
1942
|
+
// throw "addAPI"
|
1956
1943
|
if (this._api && this._api.multiApi) {
|
1957
|
-
this._api.add(this, this._api, api)
|
1944
|
+
await this._api.add(this, this._api, api)
|
1958
1945
|
} else {
|
1959
1946
|
throw new Error('Can only add apis to a multi-api')
|
1960
1947
|
}
|
1961
1948
|
}
|
1962
1949
|
|
1963
|
-
|
1950
|
+
async setApi (value) {
|
1964
1951
|
if (!value.initialize) {
|
1965
1952
|
throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
|
1966
1953
|
}
|
1967
1954
|
|
1968
1955
|
if (this._api && this._api.multiApi) {
|
1969
|
-
this._api.add(this, this._api, value)
|
1956
|
+
await this._api.add(this, this._api, value)
|
1970
1957
|
} else {
|
1971
1958
|
this._api = _.cloneDeep(value)
|
1972
|
-
|
1973
|
-
if (this._api) {
|
1974
|
-
// this._api.objects = this.config.objects
|
1975
|
-
// this._api.config = () => this
|
1976
|
-
// this._api.uuid = this._uuid
|
1977
|
-
}
|
1978
|
-
*/
|
1979
|
-
this.rebuild()
|
1959
|
+
await this.rebuild()
|
1980
1960
|
}
|
1981
1961
|
}
|
1982
1962
|
|
@@ -1996,7 +1976,7 @@ class Config {
|
|
1996
1976
|
}
|
1997
1977
|
|
1998
1978
|
// remove all added modules and initialize with the init config
|
1999
|
-
resetToOne () {
|
1979
|
+
async resetToOne () {
|
2000
1980
|
/*
|
2001
1981
|
this.config = _.cloneDeep(this.initConfig)
|
2002
1982
|
this.configs = [this.configs[0]]
|
@@ -2005,11 +1985,8 @@ class Config {
|
|
2005
1985
|
*/
|
2006
1986
|
this.configs = [this.configs[0]]
|
2007
1987
|
this.defaultConfig()
|
2008
|
-
|
2009
|
-
|
2010
|
-
Object.assign(this.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
2011
|
-
}
|
2012
|
-
this.initializeConfigFromConfigs({ others: [], objects: this.config.objects.namespaced, moreNames: [], callInitializers: false })
|
1988
|
+
Object.assign(this.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
1989
|
+
await this.initializeConfigFromConfigs({ others: [], objects: this.config.objects.namespaced, moreNames: [], callInitializers: false })
|
2013
1990
|
const map = {}
|
2014
1991
|
for (let i = 0; i < this.configs.length; ++i) {
|
2015
1992
|
map[this.configs[i].uuid] = this.configs[i].uuid
|
@@ -2031,17 +2008,18 @@ class Config {
|
|
2031
2008
|
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
2032
2009
|
}
|
2033
2010
|
|
2034
|
-
copy (options = { callInitializers: true }) {
|
2035
|
-
}
|
2036
|
-
|
2037
|
-
copy (options = { callInitializers: true }) {
|
2011
|
+
async copy (options = { callInitializers: true }) {
|
2038
2012
|
this.valid()
|
2039
2013
|
const cp = new Config()
|
2040
2014
|
cp.logs = []
|
2041
2015
|
cp.maxDepth = this.maxDepth
|
2042
2016
|
cp.debugLoops = this.debugLoops
|
2043
2017
|
cp.transitoryMode = this.transitoryMode
|
2044
|
-
cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
2018
|
+
// cp.configs = this.configs.map((km) => await km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
2019
|
+
cp.configs = []
|
2020
|
+
for (const km of this.configs) {
|
2021
|
+
cp.configs.push(await km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
2022
|
+
}
|
2045
2023
|
cp._uuid = cp.configs[0]._uuid
|
2046
2024
|
// update uuid here set the uuid in the objects and add error checking
|
2047
2025
|
cp.initializerFn = this.initializerFn
|
@@ -2062,13 +2040,8 @@ class Config {
|
|
2062
2040
|
cp.defaultConfig()
|
2063
2041
|
// cp.wasInitialized = false; // since default config GREG
|
2064
2042
|
cp.resetWasInitialized()
|
2065
|
-
|
2066
|
-
|
2067
|
-
Object.assign(cp.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
2068
|
-
}
|
2069
|
-
// cp.initializeConfigFromConfigs({ others: [], objects: cp.config.objects.namespaced, moreNames: [], ...options })
|
2070
|
-
// cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, { callInitializers: false }))
|
2071
|
-
cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, options))
|
2043
|
+
Object.assign(cp.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
2044
|
+
await cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, options))
|
2072
2045
|
const map = {}
|
2073
2046
|
for (let i = 0; i < this.configs.length; ++i) {
|
2074
2047
|
map[this.configs[i].uuid] = cp.configs[i].uuid
|
@@ -2079,33 +2052,16 @@ class Config {
|
|
2079
2052
|
// debugger
|
2080
2053
|
}
|
2081
2054
|
if (options.callInitializers) {
|
2082
|
-
cp.rebuild(options)
|
2055
|
+
await cp.rebuild(options) // in copy
|
2083
2056
|
} else {
|
2084
|
-
// this mess is for duplicate into a KM after resetToOne was called
|
2085
|
-
/*
|
2086
|
-
if (cp._api) {
|
2087
|
-
// cp._api.objects = cp.config.objects
|
2088
|
-
// cp._api.config = () => (cp instanceof Config) ? cp : cp.config
|
2089
|
-
// cp._api.uuid = cp._uuid
|
2090
|
-
}
|
2091
|
-
*/
|
2092
|
-
|
2093
2057
|
if (!cp.config.objects) {
|
2094
2058
|
cp.config.objects = { namespaced: {} }
|
2095
2059
|
} else if (!cp.config.objects.namespaced) {
|
2096
2060
|
cp.config.objects.namespaced = {}
|
2097
2061
|
}
|
2098
2062
|
cp.configs.forEach((km) => {
|
2099
|
-
// const namespace = km.namespace
|
2100
2063
|
cp.config.objects.namespaced[km._uuid] = {}
|
2101
2064
|
})
|
2102
|
-
/*
|
2103
|
-
if (cp._uuid == 'concept2') {
|
2104
|
-
if (!cp.api.objects.defaultTypesForHierarchy) {
|
2105
|
-
debugger
|
2106
|
-
}
|
2107
|
-
}
|
2108
|
-
*/
|
2109
2065
|
}
|
2110
2066
|
cp.valid()
|
2111
2067
|
return cp
|
@@ -2229,41 +2185,7 @@ class Config {
|
|
2229
2185
|
}
|
2230
2186
|
}
|
2231
2187
|
|
2232
|
-
|
2233
|
-
// [...this.configs].reverse().forEach(({ config, namespace, uuid }) => {
|
2234
|
-
[...this.configs].reverse().forEach(({ config, namespace, uuid }) => {
|
2235
|
-
/*
|
2236
|
-
let objects = this.get('objects')
|
2237
|
-
if (namespace) {
|
2238
|
-
objects = {}
|
2239
|
-
this.get('objects')['namespaced'][namespace] = objects
|
2240
|
-
}
|
2241
|
-
*/
|
2242
|
-
const objects = {}
|
2243
|
-
if (config instanceof Config) {
|
2244
|
-
this.get('objects').namespaced[config._uuid] = objects
|
2245
|
-
/*
|
2246
|
-
if (config._api) {
|
2247
|
-
// config._api.objects = objects
|
2248
|
-
// config._api.config = () => this
|
2249
|
-
}
|
2250
|
-
*/
|
2251
|
-
config.initializerFn(setupInitializerFNArgs(this, { testConfig: config, currentConfig: config, objects, namespace, uuid }))
|
2252
|
-
} else {
|
2253
|
-
this.get('objects').namespaced[this._uuid] = objects
|
2254
|
-
/*
|
2255
|
-
if (config._api) {
|
2256
|
-
// config._api.objects = objects
|
2257
|
-
// config._api.config = () => this
|
2258
|
-
}
|
2259
|
-
*/
|
2260
|
-
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, namespace, uuid }))
|
2261
|
-
}
|
2262
|
-
})
|
2263
|
-
this.instances.forEach((instance) => client.loadInstance(this, instance))
|
2264
|
-
}
|
2265
|
-
|
2266
|
-
initialize ({ force = true } = {}) {
|
2188
|
+
initialize23 ({ force = true } = {}) {
|
2267
2189
|
if (force || !this.wasInitialized) {
|
2268
2190
|
const objects = this.config.objects.namespaced[this._uuid]
|
2269
2191
|
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, uuid: this._uuid, namespace: '' }))
|
@@ -2271,7 +2193,7 @@ class Config {
|
|
2271
2193
|
}
|
2272
2194
|
}
|
2273
2195
|
|
2274
|
-
initializer (fn, options = {}) {
|
2196
|
+
async initializer (fn, options = {}) {
|
2275
2197
|
if (options) {
|
2276
2198
|
for (const option of Object.keys(options)) {
|
2277
2199
|
const validOptions = []
|
@@ -2293,8 +2215,7 @@ class Config {
|
|
2293
2215
|
currentConfig.wasInitialized = true
|
2294
2216
|
global.transitoryMode = transitoryMode
|
2295
2217
|
}
|
2296
|
-
|
2297
|
-
this.rebuild()
|
2218
|
+
await this.rebuild()
|
2298
2219
|
}
|
2299
2220
|
|
2300
2221
|
nsToString (id) {
|
@@ -2440,7 +2361,7 @@ class Config {
|
|
2440
2361
|
}
|
2441
2362
|
|
2442
2363
|
// rebuild ({ isModule: mainIsModule = false } = {}) {
|
2443
|
-
rebuild ({ isModule: mainIsModule } = {}) {
|
2364
|
+
async rebuild ({ isModule: mainIsModule } = {}) {
|
2444
2365
|
if (this._stop_auto_rebuild) {
|
2445
2366
|
return
|
2446
2367
|
}
|
@@ -2608,7 +2529,7 @@ class Config {
|
|
2608
2529
|
}
|
2609
2530
|
const instance = this.instances.find((instance) => instance.name == name)
|
2610
2531
|
if (instance) {
|
2611
|
-
client.loadInstance(this, instance)
|
2532
|
+
await client.loadInstance(this, instance)
|
2612
2533
|
}
|
2613
2534
|
this.hierarchy.edges = this.config.hierarchy
|
2614
2535
|
}
|
@@ -2628,6 +2549,7 @@ class Config {
|
|
2628
2549
|
// if undefined namespace applies to first loaded config
|
2629
2550
|
// if list of name then namespace applied only to those configs
|
2630
2551
|
// if true then namespace applies to all loaded configs
|
2552
|
+
/*
|
2631
2553
|
namespace (moreNames, others) {
|
2632
2554
|
const config = this.copy()
|
2633
2555
|
if (!Array.isArray(moreNames)) {
|
@@ -2663,6 +2585,7 @@ class Config {
|
|
2663
2585
|
config.rebuild()
|
2664
2586
|
return config
|
2665
2587
|
}
|
2588
|
+
*/
|
2666
2589
|
|
2667
2590
|
setupNamespace (km) {
|
2668
2591
|
let config = km.config
|
@@ -2681,7 +2604,7 @@ class Config {
|
|
2681
2604
|
|
2682
2605
|
// config.initializerFn({ config: this, objects, namespace })
|
2683
2606
|
// this goes through all the configs and sets up this.config
|
2684
|
-
initializeConfigFromConfigs ({ others, objects, moreNames, callInitializers = true }) {
|
2607
|
+
async initializeConfigFromConfigs ({ others, objects, moreNames, callInitializers = true }) {
|
2685
2608
|
// setup the namespace in the configs
|
2686
2609
|
let first = true
|
2687
2610
|
this.configs.forEach((km) => {
|
@@ -2924,25 +2847,29 @@ class Config {
|
|
2924
2847
|
}
|
2925
2848
|
}
|
2926
2849
|
|
2927
|
-
add (...
|
2928
|
-
|
2929
|
-
if (
|
2930
|
-
throw new Error(
|
2850
|
+
async add (...createConfigs) {
|
2851
|
+
createConfigs.forEach((createConfig, index) => {
|
2852
|
+
if (typeof createConfig !== 'function') {
|
2853
|
+
throw new Error(`Expected add argument number ${index+1} to be a function that constructs the config.`)
|
2931
2854
|
}
|
2932
2855
|
})
|
2933
2856
|
|
2934
|
-
mores =
|
2935
|
-
|
2936
|
-
|
2857
|
+
const mores = []
|
2858
|
+
for (const createConfig of createConfigs) {
|
2859
|
+
const more = await createConfig()
|
2860
|
+
if (mores.find( (km) => km.name == more.name)) {
|
2861
|
+
throw new Error(`Expected add argument number ${index+1} to be a function that constructs the config.`)
|
2937
2862
|
}
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2863
|
+
if (this === more) {
|
2864
|
+
throw new Error('Cannot add an object to itself.')
|
2865
|
+
}
|
2866
|
+
mores.push(more)
|
2867
|
+
}
|
2868
|
+
for (let more of mores) {
|
2942
2869
|
this.valid()
|
2943
2870
|
more.valid()
|
2944
2871
|
// copy so i don't have to copy later
|
2945
|
-
more = more.copy()
|
2872
|
+
more = await more.copy()
|
2946
2873
|
more.server(this._server, this._key, this._queryParams)
|
2947
2874
|
|
2948
2875
|
const moreConfigs = more.configs.map((km) => km.name || km.uuid)
|
@@ -2957,9 +2884,6 @@ class Config {
|
|
2957
2884
|
const moreKMs1 = [new KM({ config: more, getCounter: (name) => this.getCounter(name), uuid: more.uuid, namespace })]
|
2958
2885
|
const moreKMs2 = more.configs.slice(1).map((km) => {
|
2959
2886
|
return km
|
2960
|
-
// const cp = km.copy()
|
2961
|
-
// cp.namespace = namespace
|
2962
|
-
// return cp;
|
2963
2887
|
})
|
2964
2888
|
const moreKMs = moreKMs1.concat(moreKMs2)
|
2965
2889
|
const eqClass = moreKMs.map((km) => km.uuid)
|
@@ -2973,7 +2897,7 @@ class Config {
|
|
2973
2897
|
this.configs.push(moreKM)
|
2974
2898
|
}
|
2975
2899
|
}
|
2976
|
-
more.resetToOne()
|
2900
|
+
await more.resetToOne()
|
2977
2901
|
this.config.eqClasses = this._eqClasses
|
2978
2902
|
// greg
|
2979
2903
|
// setup instances
|
@@ -2988,8 +2912,8 @@ class Config {
|
|
2988
2912
|
}
|
2989
2913
|
}
|
2990
2914
|
this.instances = noDups
|
2991
|
-
}
|
2992
|
-
this.rebuild()
|
2915
|
+
}
|
2916
|
+
await this.rebuild() // in add(
|
2993
2917
|
this.valid()
|
2994
2918
|
return this
|
2995
2919
|
}
|
@@ -3145,7 +3069,7 @@ class Config {
|
|
3145
3069
|
// assumes this is called in reverse order
|
3146
3070
|
addInternalR (more, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false) {
|
3147
3071
|
if (more instanceof Config) {
|
3148
|
-
more.
|
3072
|
+
more.initialize23({ force: false })
|
3149
3073
|
if (useOldVersion) {
|
3150
3074
|
more = more.config
|
3151
3075
|
} else {
|
package/src/generators.js
CHANGED
@@ -44,7 +44,7 @@ class Generator {
|
|
44
44
|
return `Generator(${this.match}, ${this._applyWrapped || this._apply})${this.property ? `\nsee the ${this.property} property` : ''}`
|
45
45
|
}
|
46
46
|
|
47
|
-
matches (baseArgs, objects, context, hierarchy, config, options = {}) {
|
47
|
+
async matches (baseArgs, objects, context, hierarchy, config, options = {}) {
|
48
48
|
if (objects && objects.namespaced) {
|
49
49
|
objects = objects.namespaced[this.uuid]
|
50
50
|
}
|
@@ -63,17 +63,17 @@ class Generator {
|
|
63
63
|
}
|
64
64
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
65
65
|
// return this.match(args)
|
66
|
-
const matches = this.match(args)
|
66
|
+
const matches = await this.match(args)
|
67
67
|
if ((matches && (options.debug || {}).match) ||
|
68
68
|
callId == this.callId) {
|
69
69
|
debugger // next line is the matcher
|
70
|
-
this.match(args)
|
70
|
+
await this.match(args)
|
71
71
|
}
|
72
72
|
return matches
|
73
73
|
}
|
74
74
|
|
75
75
|
// apply (baseArgs, objects, g, gs, context, hierarchy, config, response, log, options = {}) {
|
76
|
-
apply (baseArgs, objects, context, hierarchy, config, response, log, options = {}) {
|
76
|
+
async apply (baseArgs, objects, context, hierarchy, config, response, log, options = {}) {
|
77
77
|
if (!log) {
|
78
78
|
throw new Error('generators.apply argument log is required')
|
79
79
|
}
|
@@ -129,7 +129,7 @@ class Generator {
|
|
129
129
|
callId == this.callId) {
|
130
130
|
debugger
|
131
131
|
}
|
132
|
-
return this._apply(args)
|
132
|
+
return await this._apply(args)
|
133
133
|
}
|
134
134
|
}
|
135
135
|
|
@@ -165,7 +165,7 @@ class Generators {
|
|
165
165
|
};
|
166
166
|
|
167
167
|
// assumed - properties added to context before the generators are called. For setting paraphrase property
|
168
|
-
apply (args, context, assumed = {}, options = {}) {
|
168
|
+
async apply (args, context, assumed = {}, options = {}) {
|
169
169
|
if (Array.isArray(context)) {
|
170
170
|
throw new Error('Expected a context not an array')
|
171
171
|
}
|
@@ -186,12 +186,12 @@ class Generators {
|
|
186
186
|
const stack = args.calls.push()
|
187
187
|
for (let igenerator = 0; igenerator < this.generators.length; ++igenerator) {
|
188
188
|
const generator = this.generators[igenerator]
|
189
|
-
if (generator.matches(args, objects, context, hierarchy, config, options)) {
|
189
|
+
if (await generator.matches(args, objects, context, hierarchy, config, options)) {
|
190
190
|
const log = (message) => { this.logs.push(message) }
|
191
191
|
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${JSON.stringify(context)}`)
|
192
192
|
let errorMessage = 'The apply function did not return a value'
|
193
193
|
try {
|
194
|
-
generated = generator.apply(args, objects, context, hierarchy, config, response, log)
|
194
|
+
generated = await generator.apply(args, objects, context, hierarchy, config, response, log)
|
195
195
|
} catch (e) {
|
196
196
|
// the next if handle this
|
197
197
|
generated = null
|
package/src/semantics.js
CHANGED
@@ -49,7 +49,7 @@ class Semantic {
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
|
-
matches (baseArgs, context, options = {}) {
|
52
|
+
async matches (baseArgs, context, options = {}) {
|
53
53
|
const hierarchy = baseArgs.hierarchy
|
54
54
|
const config = baseArgs.config
|
55
55
|
|
@@ -71,16 +71,16 @@ class Semantic {
|
|
71
71
|
}
|
72
72
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
73
73
|
|
74
|
-
const matches = this.matcher(args)
|
74
|
+
const matches = await this.matcher(args)
|
75
75
|
if (matches && (options.debug || {}).match ||
|
76
76
|
callId == this.callId) {
|
77
77
|
debugger // next line is the matcher
|
78
|
-
this.matcher(args)
|
78
|
+
await this.matcher(args)
|
79
79
|
}
|
80
80
|
return matches
|
81
81
|
}
|
82
82
|
|
83
|
-
apply (baseArgs, context, s, log, options = {}) {
|
83
|
+
async apply (baseArgs, context, s, log, options = {}) {
|
84
84
|
const { hierarchy, config, response } = baseArgs
|
85
85
|
const objects = baseArgs.getObjects(this.uuid)
|
86
86
|
if (config && config.debugLoops) {
|
@@ -124,7 +124,7 @@ class Semantic {
|
|
124
124
|
if (args.breakOnSemantics) {
|
125
125
|
debugger
|
126
126
|
}
|
127
|
-
this._apply(args)
|
127
|
+
await this._apply(args)
|
128
128
|
return contextPrime
|
129
129
|
}
|
130
130
|
}
|
@@ -176,7 +176,7 @@ class Semantics {
|
|
176
176
|
return this.semantics[maxOrdinal]
|
177
177
|
}
|
178
178
|
|
179
|
-
applyToContext (args, context, options) {
|
179
|
+
async applyToContext (args, context, options) {
|
180
180
|
// let context_prime = {}
|
181
181
|
if (!(context instanceof Array || context instanceof Object)) {
|
182
182
|
return context
|
@@ -197,14 +197,14 @@ class Semantics {
|
|
197
197
|
if (semantic.isQuestion && seenQuestion) {
|
198
198
|
continue
|
199
199
|
}
|
200
|
-
if (semantic.matches(args, context, options)) {
|
200
|
+
if (await semantic.matches(args, context, options)) {
|
201
201
|
if (!this.calls[counter]) {
|
202
202
|
this.calls[counter] = 0
|
203
203
|
}
|
204
204
|
this.calls[counter] += 1
|
205
205
|
const log = (message) => { this.logs.push(message) }
|
206
206
|
try {
|
207
|
-
contextPrime = semantic.apply(args, context, s, log, options)
|
207
|
+
contextPrime = await semantic.apply(args, context, s, log, options)
|
208
208
|
if (!contextPrime.controlKeepMotivation && semantic.oneShot) {
|
209
209
|
// semantic.tied_ids.forEach((tied_id) => args.config.removeSemantic(tied_id))
|
210
210
|
args.config.removeSemantic(semantic)
|
@@ -310,19 +310,19 @@ class Semantics {
|
|
310
310
|
return contextPrime
|
311
311
|
}
|
312
312
|
|
313
|
-
applyToContexts (args, contexts, options) {
|
313
|
+
async applyToContexts (args, contexts, options) {
|
314
314
|
const contextsPrime = []
|
315
|
-
|
316
|
-
contextsPrime.push(this.applyToContext(args, context, options))
|
317
|
-
}
|
315
|
+
for (const context of contexts) {
|
316
|
+
contextsPrime.push(await this.applyToContext(args, context, options))
|
317
|
+
}
|
318
318
|
return contextsPrime
|
319
319
|
}
|
320
320
|
|
321
|
-
apply (args, context, options) {
|
321
|
+
async apply (args, context, options) {
|
322
322
|
if (Array.isArray(context)) {
|
323
|
-
return this.applyToContexts(args, context, options)
|
323
|
+
return await this.applyToContexts(args, context, options)
|
324
324
|
} else if (context instanceof Object) {
|
325
|
-
return this.applyToContext(args, context, options)
|
325
|
+
return await this.applyToContext(args, context, options)
|
326
326
|
} else {
|
327
327
|
return context
|
328
328
|
}
|