theprogrammablemind 8.0.0-beta.21 → 8.0.0-beta.23

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 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
@@ -480,7 +479,7 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
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 = async ({ config, hierarchy, semantics, generators, json
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 = async ({ config, hierarchy, semantics, generators, json
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 = async ({ config, hierarchy, semantics, generators, json
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)
@@ -668,7 +667,7 @@ const loadInstance = async (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
package/package.json CHANGED
@@ -64,6 +64,6 @@
64
64
  "sort-json": "^2.0.0",
65
65
  "uuid": "^8.3.2"
66
66
  },
67
- "version": "8.0.0-beta.21",
67
+ "version": "8.0.0-beta.23",
68
68
  "license": "UNLICENSED"
69
69
  }
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'
@@ -1005,8 +1005,8 @@ class Config {
1005
1005
  return instance
1006
1006
  }
1007
1007
  */
1008
- getEvaluator (s, calls, log, context) {
1009
- const instance = s({ ...context, evaluate: true })
1008
+ async getEvaluator (s, calls, log, context) {
1009
+ const instance = await s({ ...context, evaluate: true })
1010
1010
  calls.touch(instance)
1011
1011
  if (!instance.evalue && !instance.verbatim && !instance.value) {
1012
1012
  this.warningNotEvaluated(log, context)
@@ -1023,7 +1023,7 @@ class Config {
1023
1023
  fragmentInstantiator (contexts) {
1024
1024
  return new Object({
1025
1025
  contexts: () => contexts,
1026
- instantiate: (mappings) => {
1026
+ instantiate: async (mappings) => {
1027
1027
  const instantiated = _.cloneDeep(contexts)
1028
1028
  // const todo = [...instantiated]
1029
1029
  // const todo = [...instantiated]
@@ -1031,8 +1031,8 @@ class Config {
1031
1031
  while (todo.length > 0) {
1032
1032
  const context = todo.pop()
1033
1033
  for (const mapping of mappings) {
1034
- if (mapping.match({ context })) {
1035
- mapping.apply({ context })
1034
+ if (await mapping.match({ context })) {
1035
+ await mapping.apply({ context })
1036
1036
  }
1037
1037
  }
1038
1038
  for (const key of Object.keys(context)) {
@@ -1618,8 +1618,8 @@ class Config {
1618
1618
  return params
1619
1619
  }
1620
1620
 
1621
- processContext (context) {
1622
- return client.processContext(context, this.getParams())
1621
+ async processContext (context) {
1622
+ return await client.processContext(context, this.getParams())
1623
1623
  }
1624
1624
 
1625
1625
  process (query, options) {
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
315
  for (const context of contexts) {
316
- contextsPrime.push(this.applyToContext(args, context, options))
316
+ contextsPrime.push(await this.applyToContext(args, context, options))
317
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
  }