theprogrammablemind_4wp 9.1.1-beta.9 → 9.2.0-beta.0

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
@@ -1161,7 +1161,7 @@ const checkTemplate = (template) => {
1161
1161
  if (template.checks) {
1162
1162
  throw new Error("The 'checks' property should be in the 'test' property not the 'template' property")
1163
1163
  }
1164
- validProps([ 'fragments', 'configs' ], template.template, 'template.template')
1164
+ validProps(['fragments', 'configs'], template.template, 'template.template')
1165
1165
  }
1166
1166
 
1167
1167
  const checkTest = (testConfig) => {
@@ -1186,6 +1186,7 @@ const knowledgeModuleImpl = async ({
1186
1186
  initializer,
1187
1187
  terminator,
1188
1188
  multiApiInitializer,
1189
+ sendObjectsToServer,
1189
1190
 
1190
1191
  module: moduleFromJSFile,
1191
1192
  description,
@@ -1236,14 +1237,17 @@ const knowledgeModuleImpl = async ({
1236
1237
  }
1237
1238
 
1238
1239
  const createConfig = async () => {
1239
- const config = new Config(configStruct, moduleFromJSFile, _process)
1240
+ const config = new Config(configStruct, moduleFromJSFile, _process, apiKMs)
1241
+ if (sendObjectsToServer) {
1242
+ config.setSendObjectsToServer()
1243
+ }
1240
1244
  setupConfig(config)
1241
1245
  config.expect_template = !!template
1242
1246
  config.setTerminator(terminator)
1243
1247
  config.stop_auto_rebuild()
1244
1248
  await config.add(...(includes || []))
1245
1249
  if (api) {
1246
- config.setApi(api, apiKMs)
1250
+ config.setApi(api)
1247
1251
  }
1248
1252
  if (multiApiInitializer) {
1249
1253
  await config.setMultiApi(multiApiInitializer)
package/index.js CHANGED
@@ -6,6 +6,7 @@ const Digraph = require('./src/digraph')
6
6
  const client = require('./client')
7
7
  const flattens = require('./src/flatten')
8
8
  const unflatten = require('./src/unflatten')
9
+ const debug = require('./src/debug')
9
10
 
10
11
  module.exports = {
11
12
  process: client.process,
@@ -26,5 +27,6 @@ module.exports = {
26
27
  Digraph,
27
28
  flattens: flattens.flattens,
28
29
  flatten: flattens.flatten,
29
- unflatten: unflatten.unflatten
30
+ unflatten: unflatten.unflatten,
31
+ debug
30
32
  }
package/package.json CHANGED
@@ -69,6 +69,6 @@
69
69
  "sort-json": "^2.0.0",
70
70
  "uuid": "^8.3.2"
71
71
  },
72
- "version": "9.1.1-beta.9",
72
+ "version": "9.2.0-beta.0",
73
73
  "license": "UNLICENSED"
74
74
  }
package/src/config.js CHANGED
@@ -473,7 +473,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
473
473
  if (moreConfig.bridges) {
474
474
  moreConfig.bridges = moreConfig.bridges.map((bridge) => {
475
475
  bridge = { ...bridge }
476
- const valid = ['after', 'before', 'bridge', 'development', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
476
+ const valid = ['after', 'associations', 'before', 'bridge', 'development', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
477
477
  'level', 'optional', 'selector', 'semantic', 'semantics', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
478
478
  helpers.validProps(valid, bridge, 'bridge')
479
479
  handleBridgeProps(baseConfig, bridge, { addFirst, uuid })
@@ -576,6 +576,10 @@ const addWord = (config, uuid) => ({ word, id, initial }) => {
576
576
 
577
577
  const normalizeConfig = (config) => {
578
578
  if (config) {
579
+ if (!config.objects) {
580
+ config.objects = { namespaced: {}, }
581
+ }
582
+
579
583
  for (const bag of bags) {
580
584
  if (config[bag]) {
581
585
  config[bag] = config[bag].map(normalizeGenerator)
@@ -865,6 +869,7 @@ class Config {
865
869
  async fixtures () {
866
870
  if (this.testConfig?.fixtures) {
867
871
  const args = {}
872
+ args.uuid = this._uuid
868
873
  configHelpers.setupArgs(args, this)
869
874
  return this.testConfig.fixtures(args)
870
875
  }
@@ -893,7 +898,7 @@ class Config {
893
898
 
894
899
  getPseudoConfig (uuid, config) {
895
900
  return {
896
- description: 'this is a pseudo config that has limited functionality due to being available in the initializer function context',
901
+ description: 'this is a pseudo config that has limited functionality due to being available in the initializer and fixtures function context',
897
902
  addAssociation: (...args) => this.addAssociation(...args),
898
903
  addAssociations: (...args) => this.addAssociations(...args),
899
904
  addBridge: (...args) => this.addBridge(...args, uuid),
@@ -961,7 +966,7 @@ class Config {
961
966
  },
962
967
  objects: {
963
968
  // this is where the namespaced configs have their objects
964
- namespaced: {}
969
+ namespaced: {},
965
970
  },
966
971
  description: '',
967
972
  words: {
@@ -1325,6 +1330,11 @@ class Config {
1325
1330
 
1326
1331
  toData (data) {
1327
1332
  Object.assign(data, this.config)
1333
+ // greg99 delete data.objects
1334
+ data.objects = {...this.config.objects}
1335
+ if (!this.sendObjectsToServer) {
1336
+ delete data.objects.namespaced
1337
+ }
1328
1338
  config_toServer(data)
1329
1339
  }
1330
1340
 
@@ -1766,7 +1776,7 @@ class Config {
1766
1776
  if (!config.objects) {
1767
1777
  config.objects = {
1768
1778
  namespaced: {
1769
- }
1779
+ },
1770
1780
  }
1771
1781
  }
1772
1782
 
@@ -1919,11 +1929,15 @@ class Config {
1919
1929
  }
1920
1930
 
1921
1931
  // configs = [ { config, namespace } ... ]
1922
- constructor (config, module, clientProcess) {
1932
+ constructor (config, module, clientProcess, apiKMs) {
1923
1933
  if (config instanceof Config) {
1924
1934
  throw new Error('Excepted the config argument to be a hash not a Config object')
1925
1935
  }
1926
1936
 
1937
+ if (!apiKMs) {
1938
+ apiKMs = []
1939
+ }
1940
+
1927
1941
  if (config) {
1928
1942
  validConfigProps(config)
1929
1943
 
@@ -1937,6 +1951,8 @@ class Config {
1937
1951
  config.priorities = config.priorities || []
1938
1952
  }
1939
1953
 
1954
+ this._apiKMs = apiKMs
1955
+
1940
1956
  this.clientProcess = clientProcess
1941
1957
  this.maxDepth = 20 // for generators and semantics
1942
1958
  this.debugLoops = false // for generators and semantics
@@ -1945,7 +1961,7 @@ class Config {
1945
1961
  this.resetDelta()
1946
1962
 
1947
1963
  this.addedArgss = []
1948
- const isProcess = require.main === module
1964
+ let isProcess = require.main === module
1949
1965
  if (global.theprogrammablemind && config) {
1950
1966
  if (global.theprogrammablemind.loadForTesting[config.name]) {
1951
1967
  isProcess = true
@@ -1992,6 +2008,7 @@ class Config {
1992
2008
  this.wasInitialized = false
1993
2009
  this.configs = []
1994
2010
  this._api = undefined
2011
+ this.sendObjectsToServer = false
1995
2012
  this._namespace = []
1996
2013
  this._eqClasses = []
1997
2014
  // this._uuid = uuidv4()
@@ -2016,6 +2033,10 @@ class Config {
2016
2033
  debugConfigProps(this.config)
2017
2034
  }
2018
2035
 
2036
+ setSendObjectsToServer() {
2037
+ this.sendObjectsToServer = true
2038
+ }
2039
+
2019
2040
  addArgs (moreArgs) {
2020
2041
  this.addedArgss.push(moreArgs)
2021
2042
  }
@@ -2083,7 +2104,28 @@ class Config {
2083
2104
  this.resetDelta(cacheKey)
2084
2105
  }
2085
2106
 
2107
+ // use this to set the api if you only want to partially override the KM api
2108
+ apiBase (name) {
2109
+ if (this._api && this._api.multiApi) {
2110
+ throw new Error('This is intended to be used to instantiate a new class based on the existing API.')
2111
+ } else {
2112
+ if (name) {
2113
+ if (this.name == name) {
2114
+ return this._api.constructor
2115
+ } else {
2116
+ return this.getConfig(name)._api.constructor
2117
+ }
2118
+ } else {
2119
+ return this._api.constructor
2120
+ }
2121
+ }
2122
+ }
2123
+
2086
2124
  get api () {
2125
+ if (this._stop_auto_rebuild) {
2126
+ throw new Error('The API cannot be accessed until the auto rebuild is restarted')
2127
+ }
2128
+
2087
2129
  if (this._api && this._api.multiApi) {
2088
2130
  return this._api.api(this._api)
2089
2131
  } else {
@@ -2106,16 +2148,25 @@ class Config {
2106
2148
  }
2107
2149
 
2108
2150
  // constructors is a constructor
2109
- async setApi (constructor, apiKMs) {
2110
- if (!apiKMs) {
2111
- apiKMs = [this.name]
2112
- }
2151
+ async setApi (constructor) {
2113
2152
  if (typeof constructor !== 'function') {
2114
2153
  throw new Error(`Expected the argument to be an API constructor for ${this.name}.`)
2115
2154
  }
2116
2155
  const value = constructor()
2117
- if (!value.initialize) {
2118
- throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
2156
+ if (this._apiKMs.length > 0) {
2157
+ for (const name of this._apiKMs) {
2158
+ const api = value[name]
2159
+ if (!api) {
2160
+ throw new Error(`The API for ${this.name} is not being provided by the API constructor.`)
2161
+ }
2162
+ if (!api.initialize) {
2163
+ throw new Error(`Expected the API for ${this.name} to have an initialize function.`)
2164
+ }
2165
+ }
2166
+ } else {
2167
+ if (!value.initialize) {
2168
+ throw new Error(`Expected the API to have an initialize function for ${this.name}.`)
2169
+ }
2119
2170
  }
2120
2171
 
2121
2172
  if (this._api && this._api.multiApi) {
@@ -2128,14 +2179,13 @@ class Config {
2128
2179
  return api
2129
2180
  }
2130
2181
  } else {
2131
- this._api = value
2132
2182
  this._apiConstructor = constructor
2133
- this._apiKMs = apiKMs
2134
- for (const name of this._apiKMs) {
2135
- if (this.name == name) {
2136
- continue
2183
+ if (this._apiKMs.length > 0) {
2184
+ for (const name of this._apiKMs) {
2185
+ this.km(name)._api = value[name]
2137
2186
  }
2138
- this.km(name).setApi(() => this._api)
2187
+ } else {
2188
+ this._api = value
2139
2189
  }
2140
2190
  await this.rebuild()
2141
2191
  }
@@ -2204,10 +2254,21 @@ class Config {
2204
2254
  // update uuid here set the uuid in the objects and add error checking
2205
2255
  cp.initializerFn = this.initializerFn
2206
2256
  cp.terminatorFn = this.terminatorFn
2207
- if (this._apiConstructor) {
2208
- cp._api = this._apiConstructor(cp)
2209
- cp._apiConstructor = this._apiConstructor
2210
- cp._apiKMs = this._apiKMs
2257
+ cp._apiKMs = this._apiKMs
2258
+ cp._apiConstructor = this._apiConstructor
2259
+ if (cp._apiConstructor) {
2260
+ if (this._apiKMs.length > 0) {
2261
+ const apis = cp._apiConstructor(cp)
2262
+ for (const name of this._apiKMs) {
2263
+ if (name == this.name) {
2264
+ cp._api = apis[name]
2265
+ } else {
2266
+ cp.km(name)._api = apis[name]
2267
+ }
2268
+ }
2269
+ } else {
2270
+ cp._api = cp._apiConstructor(cp)
2271
+ }
2211
2272
  }
2212
2273
  cp._namespace = this._namespace
2213
2274
  cp._eqClasses = this._eqClasses
@@ -2222,6 +2283,7 @@ class Config {
2222
2283
  cp.testConfig = this.testConfig
2223
2284
  cp._server = this._server
2224
2285
  cp.hierarchy = new DigraphInternal(this.config.hierarchy)
2286
+ cp.sendObjectsToServer = this.sendObjectsToServer
2225
2287
 
2226
2288
  cp.initConfig = _.cloneDeep(this.initConfig)
2227
2289
  cp.defaultConfig()
@@ -2239,7 +2301,9 @@ class Config {
2239
2301
  await cp.rebuild(options) // in copy
2240
2302
  } else {
2241
2303
  if (!cp.config.objects) {
2242
- cp.config.objects = { namespaced: {} }
2304
+ cp.config.objects = {
2305
+ namespaced: {},
2306
+ }
2243
2307
  } else if (!cp.config.objects.namespaced) {
2244
2308
  cp.config.objects.namespaced = {}
2245
2309
  }
@@ -2587,7 +2651,9 @@ class Config {
2587
2651
  const initAfterApis = []
2588
2652
  this.configs.forEach((km) => {
2589
2653
  const namespace = km.namespace
2590
- this.config.objects.namespaced[km._uuid] = {}
2654
+ this.config.objects.namespaced[km._uuid] = {
2655
+ km: km._uuid
2656
+ }
2591
2657
  const namespacedObjects = this.config.objects.namespaced[km._uuid]
2592
2658
  this.setupNamespace(km)
2593
2659
  // const aw = (word, def) => this.addWord(word, def)
@@ -85,6 +85,9 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
85
85
  args.objects = config.get('objects')
86
86
  args.getObjects = getObjects(args.objects)
87
87
  }
88
+ if (args.uuid) {
89
+ args.objects = args.getObjects(args.uuid)
90
+ }
88
91
  if (!hierarchy) {
89
92
  hierarchy = config.hierarchy
90
93
  }
@@ -133,6 +136,9 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
133
136
  return config.getGenerators(logs).apply(addAssumed(args, a, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true })
134
137
  }
135
138
  args.e = (c) => {
139
+ if (!c) {
140
+ return
141
+ }
136
142
  return config.getEvaluator(args.s, args.calls, logs, c)
137
143
  }
138
144
  args.gs = gs(args.g)
@@ -249,7 +255,7 @@ const setupContexts = (rawContexts) => {
249
255
  let first = true
250
256
  const contexts = []
251
257
  contexts.push({ marker: 'controlStart', controlRemove: true })
252
- let previous;
258
+ let previous
253
259
  for (const context of rawContexts) {
254
260
  if (first) {
255
261
  first = false
@@ -337,9 +343,9 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
337
343
  if (contextPrime.controlRemove) {
338
344
  continue
339
345
  }
340
- let paraphrases = []
341
- let paraphrasesParenthesized = []
342
- let generatedParenthesized = []
346
+ const paraphrases = []
347
+ const paraphrasesParenthesized = []
348
+ const generatedParenthesized = []
343
349
  if (forTemplate) {
344
350
  // noop
345
351
  } else {