theprogrammablemind 9.6.0-beta.2 → 9.6.0-beta.22

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
@@ -292,7 +292,9 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
292
292
  if (rebuildingTemplate) {
293
293
  data.errors_ignore_contextual_priorities_non_existant_ops = true
294
294
  }
295
- let queries = query.split('\\n')
295
+
296
+ // '\\n' from tests of '\n' from users. the former is because newline is not a valid json character so the testfile has it encoded
297
+ let queries = query.split(/\\n|\n/)
296
298
  const summaries = [] // for error
297
299
  try {
298
300
  const response = {
@@ -796,6 +798,8 @@ const defaultErrorHandler = async (error) => {
796
798
  if (typeof runtime.process.exit === 'function' && doErrorExit) {
797
799
  runtime.process.exit(-1)
798
800
  }
801
+
802
+ error.config = null // otherwise it dumps to much on the console
799
803
 
800
804
  throw error
801
805
  }
@@ -1222,6 +1226,7 @@ const knowledgeModuleImpl = async ({
1222
1226
  errorHandler = defaultErrorHandler,
1223
1227
  process: processResults = defaultProcess,
1224
1228
  stopAtFirstFailure = true,
1229
+ demoInitializer,
1225
1230
  ...rest
1226
1231
  } = {}) => {
1227
1232
  const unknownArgs = Object.keys(rest)
@@ -1271,13 +1276,13 @@ const knowledgeModuleImpl = async ({
1271
1276
  config.stop_auto_rebuild()
1272
1277
  await config.add(...(includes || []))
1273
1278
  if (api) {
1274
- config.setApi(api)
1279
+ await config.setApi(api)
1275
1280
  }
1276
1281
  if (multiApiInitializer) {
1277
1282
  await config.setMultiApi(multiApiInitializer)
1278
1283
  }
1279
1284
  if (initializer) {
1280
- config.initializer(initializer)
1285
+ await config.initializer(initializer)
1281
1286
  }
1282
1287
  await config.restart_auto_rebuild()
1283
1288
  return config
@@ -1375,6 +1380,10 @@ const knowledgeModuleImpl = async ({
1375
1380
  }
1376
1381
  config = await createConfig(true, configStruct.name)
1377
1382
 
1383
+ if (demoInitializer) {
1384
+ await config.setDemoInitializer(demoInitializer)
1385
+ }
1386
+
1378
1387
  // dont debug the load of the KM's if rebuild template is on since we want to debug the template rebuild not the load
1379
1388
  if (args.rebuildTemplate) {
1380
1389
  global.pauseDebugging = true
@@ -1457,7 +1466,7 @@ const knowledgeModuleImpl = async ({
1457
1466
  let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1458
1467
  tests = tests.filter((test) => test.query !== args.deleteTest)
1459
1468
  writeTestFile(testConfig.name, tests)
1460
- console.log(`Remove the test for "${args.deleteTest}"`)
1469
+ console.log(`Delete the test for "${args.deleteTest}"`)
1461
1470
  return
1462
1471
  }
1463
1472
 
@@ -2011,6 +2020,9 @@ const knowledgeModuleImpl = async ({
2011
2020
  }
2012
2021
  const config = await createConfig(rootIsProcess, testingModuleName)
2013
2022
  await initConfig(config)
2023
+ if (demoInitializer) {
2024
+ config.setDemoInitializer(demoInitializer)
2025
+ }
2014
2026
  // config.rebuild({ isModule: true })
2015
2027
  createConfig.cached = config
2016
2028
  return createConfig.cached
package/package.json CHANGED
@@ -4,6 +4,7 @@
4
4
  "@typescript-eslint/eslint-plugin": "^4.28.4",
5
5
  "@typescript-eslint/parser": "^4.28.4",
6
6
  "argparse": "^2.0.1",
7
+ "baseline-browser-mapping": "^2.9.19",
7
8
  "eslint": "^7.32.0",
8
9
  "eslint-config-standard": "^16.0.3",
9
10
  "eslint-plugin-import": "^2.23.4",
@@ -72,6 +73,6 @@
72
73
  "scriptjs": "^2.5.9",
73
74
  "uuid": "^8.3.2"
74
75
  },
75
- "version": "9.6.0-beta.2",
76
+ "version": "9.6.0-beta.22",
76
77
  "license": "UNLICENSED"
77
78
  }
package/src/config.js CHANGED
@@ -338,6 +338,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
338
338
 
339
339
  // done in setTestConfig
340
340
  if (bridge.check) {
341
+ /*
341
342
  if (!config.testConfig) {
342
343
  config.testConfig = {}
343
344
  }
@@ -347,6 +348,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
347
348
  if (!config.testConfig?.checks?.context) {
348
349
  config.testConfig.checks.context = []
349
350
  }
351
+ */
350
352
  config.contextChecksFromBridges.push({
351
353
  'bridge.id': bridge.id,
352
354
  'bridge.check': bridge.check,
@@ -431,7 +433,12 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
431
433
  const generator = {
432
434
  where: bridge.generatorr.where || bridge.where || helpers.where(4),
433
435
  // match: async (args) => bridge.id === args.context.marker && args.context.level === level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
434
- match: async (args) => args.isA(args.context.marker, bridge.id) && args.context.level === level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && await match(args),
436
+ match: async (args) => {
437
+ if (bridge.callId == args.callId) {
438
+ debugger
439
+ }
440
+ return args.isA(args.context.marker, bridge.id) && args.context.level === level && !args.context.paraphrase && (args.context.response != null || args.context.isResponse) && await match(args)
441
+ },
435
442
  apply: (args) => apply(args),
436
443
  applyWrapped: apply,
437
444
  property: 'generatorr'
@@ -523,6 +530,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
523
530
  'associations',
524
531
  'before',
525
532
  'bridge',
533
+ 'callId',
526
534
  'check',
527
535
  'children',
528
536
  'conditional',
@@ -536,6 +544,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
536
544
  'generatorr',
537
545
  'generators',
538
546
  'id',
547
+ 'init',
539
548
  'inverted',
540
549
  'isA',
541
550
  'level',
@@ -1094,19 +1103,6 @@ class Config {
1094
1103
  this.testConfig.checks.context = []
1095
1104
  }
1096
1105
  this.testConfig.checks.context = this.contextChecksFromBridges.concat(this.testConfig.checks.context)
1097
- /*
1098
- const currentTestConfig = testConfig // add bridge has added check.context's
1099
-
1100
- if (!this.testConfig.checks) {
1101
- debugger
1102
- // this.testConfig.checks =
1103
- }
1104
-
1105
- // set during bridge setup
1106
- if (currentTestConfig.checks?.context) {
1107
- this.testConfig.checks.context = currentTestConfig.checks.context.concat(this.testConfig.checks.context)
1108
- }
1109
- */
1110
1106
  }
1111
1107
 
1112
1108
  getTestConfig () {
@@ -1224,10 +1220,10 @@ class Config {
1224
1220
  async getEvaluator (s, calls, log, context, args) {
1225
1221
  const instance = await s({ ...args, ...context, evaluate: true })
1226
1222
  calls.touch(instance)
1227
- if (!instance.evalue && !instance.verbatim && !instance.value) {
1223
+ if (instance.evalue == null && !instance.verbatim && !instance.value) {
1228
1224
  this.warningNotEvaluated(log, context)
1229
1225
  }
1230
- if (!instance.evalue) {
1226
+ if (instance.evalue == null) {
1231
1227
  instance.evalue = instance.value
1232
1228
  instance.edefault = true
1233
1229
  }
@@ -2140,6 +2136,11 @@ class Config {
2140
2136
  }
2141
2137
  }
2142
2138
 
2139
+ async setDemoInitializer(demoInitializer) {
2140
+ this.demoInitializer = demoInitializer
2141
+ // await this.demoInitializer(this)
2142
+ }
2143
+
2143
2144
  // configs = [ { config, namespace } ... ]
2144
2145
  constructor (config, module, clientProcess, apiKMs, rootIsProcess, testingModuleName) {
2145
2146
  if (config instanceof Config) {
@@ -2163,6 +2164,7 @@ class Config {
2163
2164
  config.priorities = config.priorities || []
2164
2165
  }
2165
2166
 
2167
+ this.demoInitializer = null
2166
2168
  this.contextChecksFromBridges = []
2167
2169
 
2168
2170
  this._enable = []
@@ -2276,7 +2278,7 @@ class Config {
2276
2278
 
2277
2279
  async restart_auto_rebuild () {
2278
2280
  this._stop_auto_rebuild = false
2279
- await this.rebuild()
2281
+ return await this.rebuild()
2280
2282
  }
2281
2283
 
2282
2284
  getAddedArgs (args) {
@@ -2479,6 +2481,7 @@ class Config {
2479
2481
  this.valid()
2480
2482
  const cp = new Config()
2481
2483
  cp.logs = []
2484
+ cp.demoInitializer = this.demoInitializer
2482
2485
  cp.maxDepth = this.maxDepth
2483
2486
  cp.debugLoops = this.debugLoops
2484
2487
  cp.transitoryMode = this.transitoryMode
@@ -2553,6 +2556,11 @@ class Config {
2553
2556
  cp.config.objects.namespaced[km._uuid] = {}
2554
2557
  })
2555
2558
  }
2559
+
2560
+ if (cp.demoInitializer) {
2561
+ await cp.demoInitializer(cp)
2562
+ }
2563
+
2556
2564
  cp.valid()
2557
2565
  return cp
2558
2566
  }
@@ -2855,7 +2863,11 @@ class Config {
2855
2863
  let defaults = () => []
2856
2864
  if (this.loadOrdering) {
2857
2865
  for (const name of this.loadOrdering) {
2858
- const checks = this.kms[name].testConfig?.checks?.context || []
2866
+ const config = this.kms[name]
2867
+ let checks = config.testConfig?.checks?.context || []
2868
+ if (config.contextChecksFromBridges) {
2869
+ checks = config.contextChecksFromBridges.concat(checks)
2870
+ }
2859
2871
  const oldDefaults = defaults
2860
2872
  for (const check of checks) {
2861
2873
  if (!check.match) {
@@ -3077,6 +3089,15 @@ class Config {
3077
3089
  this.removeDevelopmentElements(this.config)
3078
3090
  }
3079
3091
 
3092
+ if (this.testConfig?.testModuleName) {
3093
+ const km = this.km(this.testConfig.testModuleName)
3094
+ if (km.demoInitializer) {
3095
+ await km.demoInitializer(km)
3096
+ }
3097
+ } else if (this.demoInitializer) {
3098
+ await this.demoInitializer(this)
3099
+ }
3100
+
3080
3101
  this.valid()
3081
3102
  this.checks()
3082
3103
  }
@@ -3462,7 +3483,8 @@ class Config {
3462
3483
  }
3463
3484
 
3464
3485
  // TODO get rid of useOldVersion arg
3465
- addInternal (more, { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3486
+ addInternal (more,
3487
+ { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3466
3488
  validConfigProps(more)
3467
3489
  if (more instanceof Config) {
3468
3490
  more.initialize({ force: false })
@@ -151,12 +151,22 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
151
151
  // debugger
152
152
  // }
153
153
  const { assumed = {}, options = {} } = rest
154
+ // have it default to paraphrase
155
+ if (['number', 'string', 'boolean'].includes(typeof c)) {
156
+ return `${c}`
157
+ }
158
+ if (false && !(assumed.isResponse && assumed.response)) {
159
+ assumed.paraphrase = true
160
+ }
154
161
  return config.getGenerators(logs).apply(addAssumed(args, assumed), c, assumed, options)
155
162
  }
156
163
  args.gp = (c, rest = {}) => {
157
164
  // if (JSON.stringify(rest) !== '{}' && !(rest.assumed || rest.options)) {
158
165
  // debugger
159
166
  // }
167
+ if (['number', 'string', 'boolean'].includes(typeof c)) {
168
+ return `${c}`
169
+ }
160
170
  const { assumed = {}, options = {} } = rest
161
171
  return config.getGenerators(logs).apply(addAssumed(args, assumed, { paraphrase: true, isResponse: false, response: false }), c, { paraphrase: true, isResponse: false, response: false }, options)
162
172
  }
@@ -164,6 +174,9 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
164
174
  // if (JSON.stringify(rest) !== '{}' && !(rest.assumed || rest.options)) {
165
175
  // debugger
166
176
  // }
177
+ if (['number', 'string', 'boolean'].includes(typeof c)) {
178
+ return `${c}`
179
+ }
167
180
  const { assumed = {}, options = {} } = rest
168
181
  return config.getGenerators(logs).apply(addAssumed(args, assumed, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true }, options)
169
182
  }
package/src/debug.js CHANGED
@@ -51,6 +51,7 @@ const counter = (name, { breakAt = [], debugBreak = true, tag = '' } = {}) => {
51
51
  hit(name)
52
52
  return true
53
53
  }
54
+ return counters[name]
54
55
  }
55
56
 
56
57
  const get = (name) => {
package/src/fragments.js CHANGED
@@ -1,6 +1,18 @@
1
1
  const _ = require('lodash')
2
2
  const helpers = require('./helpers')
3
3
 
4
+ function pathEquals (p1, p2) {
5
+ if (p1.length !== p2.length) {
6
+ return false
7
+ }
8
+ for (let i = 0; i < p1.length; ++i) {
9
+ if (p1[i] !== p2[i]) {
10
+ return false
11
+ }
12
+ }
13
+ return true
14
+ }
15
+
4
16
  function fragmentInstantiator (args, contexts) {
5
17
  return new Object({
6
18
  contexts: () => {
@@ -10,6 +22,7 @@ function fragmentInstantiator (args, contexts) {
10
22
  const instantiated = _.cloneDeep(contexts)
11
23
  const todo = [{ context: instantiated, path: [] }]
12
24
  args = { ...args }
25
+ args.pathEquals = pathEquals
13
26
  while (todo.length > 0) {
14
27
  const { context, path } = todo.pop()
15
28
  args.context = context
package/src/helpers.js CHANGED
@@ -1,6 +1,31 @@
1
1
  const deepEqual = require('deep-equal')
2
2
  const stringify = require('json-stable-stringify')
3
3
 
4
+ function watchProperty(obj, propName) {
5
+ let value = obj[propName];
6
+
7
+ Object.defineProperty(obj, propName, {
8
+ get() {
9
+ return value;
10
+ },
11
+ set(newValue) {
12
+ console.log(`%c${propName} changed →`, 'color: #e83', newValue);
13
+ debugger; // ← Chrome/Firefox will pause here automatically
14
+ value = newValue;
15
+ },
16
+ configurable: true // allows us to delete/restore later if needed
17
+ });
18
+ }
19
+
20
+ function assignAssumed(object, assumed) {
21
+ for (const key in assumed) {
22
+ if (object[key] == null) {
23
+ object[key] = assumed[key]
24
+ }
25
+ }
26
+ return object
27
+ }
28
+
4
29
  function where (goUp = 2) {
5
30
  const e = new Error()
6
31
  const regexForm1 = /\((.*):(\d+):(\d+)\)$/
@@ -567,4 +592,6 @@ module.exports = {
567
592
  suggestAssociationsFixFromSummaries,
568
593
  getByPath,
569
594
  setByPath,
595
+ assignAssumed,
596
+ watchProperty,
570
597
  }