theprogrammablemind_4wp 8.0.0-beta.5 → 8.0.0-beta.50
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 +73 -487
 - package/index.js +3 -2
 - package/package.json +13 -12
 - package/src/config.js +193 -249
 - package/src/configHelpers.js +448 -0
 - package/src/generators.js +8 -8
 - package/src/helpers.js +34 -1
 - package/src/semantics.js +63 -69
 
| 
         @@ -0,0 +1,448 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const { InitCalls } = require('./helpers')
         
     | 
| 
      
 2 
     | 
    
         
            +
            const DigraphInternal = require('./digraph_internal')
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            const gs = (g) => async (contexts, separator, lastSeparator) => {
         
     | 
| 
      
 5 
     | 
    
         
            +
              if (!Array.isArray(contexts)) {
         
     | 
| 
      
 6 
     | 
    
         
            +
                throw new Error('Expected a list')
         
     | 
| 
      
 7 
     | 
    
         
            +
              }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              let s = ''
         
     | 
| 
      
 10 
     | 
    
         
            +
              if (!separator) {
         
     | 
| 
      
 11 
     | 
    
         
            +
                separator = ' '
         
     | 
| 
      
 12 
     | 
    
         
            +
              }
         
     | 
| 
      
 13 
     | 
    
         
            +
              if (!lastSeparator) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                lastSeparator = separator
         
     | 
| 
      
 15 
     | 
    
         
            +
              }
         
     | 
| 
      
 16 
     | 
    
         
            +
              let nextSeparator = ''
         
     | 
| 
      
 17 
     | 
    
         
            +
              for (let i = 0; i < contexts.length; ++i) {
         
     | 
| 
      
 18 
     | 
    
         
            +
                const context = contexts[i]
         
     | 
| 
      
 19 
     | 
    
         
            +
                const value = await g(context)
         
     | 
| 
      
 20 
     | 
    
         
            +
                if (i > 0) {
         
     | 
| 
      
 21 
     | 
    
         
            +
                  if (i === contexts.length - 1) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                    nextSeparator = lastSeparator
         
     | 
| 
      
 23 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 24 
     | 
    
         
            +
                    nextSeparator = separator
         
     | 
| 
      
 25 
     | 
    
         
            +
                  }
         
     | 
| 
      
 26 
     | 
    
         
            +
                }
         
     | 
| 
      
 27 
     | 
    
         
            +
                s += nextSeparator + value
         
     | 
| 
      
 28 
     | 
    
         
            +
              }
         
     | 
| 
      
 29 
     | 
    
         
            +
              return s
         
     | 
| 
      
 30 
     | 
    
         
            +
            }
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            const asList = (context) => {
         
     | 
| 
      
 33 
     | 
    
         
            +
              if (context.marker === 'list') {
         
     | 
| 
      
 34 
     | 
    
         
            +
                return context
         
     | 
| 
      
 35 
     | 
    
         
            +
              }
         
     | 
| 
      
 36 
     | 
    
         
            +
              return {
         
     | 
| 
      
 37 
     | 
    
         
            +
                marker: 'list',
         
     | 
| 
      
 38 
     | 
    
         
            +
                types: [context.marker],
         
     | 
| 
      
 39 
     | 
    
         
            +
                value: [context]
         
     | 
| 
      
 40 
     | 
    
         
            +
              }
         
     | 
| 
      
 41 
     | 
    
         
            +
            }
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            const isA = (hierarchy) => (child, parent) => {
         
     | 
| 
      
 44 
     | 
    
         
            +
              if (!child || !parent) {
         
     | 
| 
      
 45 
     | 
    
         
            +
                return false
         
     | 
| 
      
 46 
     | 
    
         
            +
              }
         
     | 
| 
      
 47 
     | 
    
         
            +
              if (child.marker) {
         
     | 
| 
      
 48 
     | 
    
         
            +
                child = child.marker
         
     | 
| 
      
 49 
     | 
    
         
            +
              }
         
     | 
| 
      
 50 
     | 
    
         
            +
              if (parent.marker) {
         
     | 
| 
      
 51 
     | 
    
         
            +
                parent = parent.marker
         
     | 
| 
      
 52 
     | 
    
         
            +
              }
         
     | 
| 
      
 53 
     | 
    
         
            +
              return hierarchy.isA(child, parent)
         
     | 
| 
      
 54 
     | 
    
         
            +
            }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            class ErrorReason extends Error {
         
     | 
| 
      
 57 
     | 
    
         
            +
              constructor (context) {
         
     | 
| 
      
 58 
     | 
    
         
            +
                super(JSON.stringify(context))
         
     | 
| 
      
 59 
     | 
    
         
            +
                this.reason = context
         
     | 
| 
      
 60 
     | 
    
         
            +
              }
         
     | 
| 
      
 61 
     | 
    
         
            +
            }
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            const listable = (hierarchy) => (c, type) => {
         
     | 
| 
      
 64 
     | 
    
         
            +
              if (!c) {
         
     | 
| 
      
 65 
     | 
    
         
            +
                return false
         
     | 
| 
      
 66 
     | 
    
         
            +
              }
         
     | 
| 
      
 67 
     | 
    
         
            +
              if (hierarchy.isA(c.marker, type)) {
         
     | 
| 
      
 68 
     | 
    
         
            +
                return true
         
     | 
| 
      
 69 
     | 
    
         
            +
              }
         
     | 
| 
      
 70 
     | 
    
         
            +
              if (c.marker === 'list') { 
         
     | 
| 
      
 71 
     | 
    
         
            +
                for (const t of c.types) {
         
     | 
| 
      
 72 
     | 
    
         
            +
                  if (hierarchy.isA(t, type)) {
         
     | 
| 
      
 73 
     | 
    
         
            +
                    return true
         
     | 
| 
      
 74 
     | 
    
         
            +
                  }
         
     | 
| 
      
 75 
     | 
    
         
            +
                }
         
     | 
| 
      
 76 
     | 
    
         
            +
              }
         
     | 
| 
      
 77 
     | 
    
         
            +
              return false
         
     | 
| 
      
 78 
     | 
    
         
            +
            }
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            const cleanAssign = (dest, ...srcs) => {
         
     | 
| 
      
 81 
     | 
    
         
            +
              for (const key in dest) {
         
     | 
| 
      
 82 
     | 
    
         
            +
                let found = false
         
     | 
| 
      
 83 
     | 
    
         
            +
                for (const src of srcs) {
         
     | 
| 
      
 84 
     | 
    
         
            +
                  if (src[key]) {
         
     | 
| 
      
 85 
     | 
    
         
            +
                    found = true
         
     | 
| 
      
 86 
     | 
    
         
            +
                    break
         
     | 
| 
      
 87 
     | 
    
         
            +
                  }
         
     | 
| 
      
 88 
     | 
    
         
            +
                }
         
     | 
| 
      
 89 
     | 
    
         
            +
                if (!found) {
         
     | 
| 
      
 90 
     | 
    
         
            +
                  delete dest[key]
         
     | 
| 
      
 91 
     | 
    
         
            +
                }
         
     | 
| 
      
 92 
     | 
    
         
            +
              }
         
     | 
| 
      
 93 
     | 
    
         
            +
              Object.assign(dest, ...srcs)
         
     | 
| 
      
 94 
     | 
    
         
            +
            }
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
            const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
              // callId
         
     | 
| 
      
 99 
     | 
    
         
            +
              args.calls = new InitCalls(args.isInstance ? `${args.isInstance}#${config.name}` : config.name)
         
     | 
| 
      
 100 
     | 
    
         
            +
              if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
         
     | 
| 
      
 101 
     | 
    
         
            +
                args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
         
     | 
| 
      
 102 
     | 
    
         
            +
              }
         
     | 
| 
      
 103 
     | 
    
         
            +
              args.cleanAssign = cleanAssign
         
     | 
| 
      
 104 
     | 
    
         
            +
              args.km = (name) => config.getConfig(name)
         
     | 
| 
      
 105 
     | 
    
         
            +
              args.api = (name) => config.getConfig(name).api
         
     | 
| 
      
 106 
     | 
    
         
            +
              args.error = (context) => {
         
     | 
| 
      
 107 
     | 
    
         
            +
                throw new ErrorReason(context)
         
     | 
| 
      
 108 
     | 
    
         
            +
              }
         
     | 
| 
      
 109 
     | 
    
         
            +
              args.kms = config.getConfigs()
         
     | 
| 
      
 110 
     | 
    
         
            +
              args.config = config
         
     | 
| 
      
 111 
     | 
    
         
            +
              args.hierarchy = hierarchy
         
     | 
| 
      
 112 
     | 
    
         
            +
              args.isA = isA(hierarchy)
         
     | 
| 
      
 113 
     | 
    
         
            +
              args.listable = listable(hierarchy)
         
     | 
| 
      
 114 
     | 
    
         
            +
              args.asList = asList
         
     | 
| 
      
 115 
     | 
    
         
            +
              args.retry = () => { throw new RetryError() }
         
     | 
| 
      
 116 
     | 
    
         
            +
              args.fragments = (query) => {
         
     | 
| 
      
 117 
     | 
    
         
            +
                return config.fragment(args, query)
         
     | 
| 
      
 118 
     | 
    
         
            +
              }
         
     | 
| 
      
 119 
     | 
    
         
            +
              args.breakOnSemantics = false
         
     | 
| 
      
 120 
     | 
    
         
            +
              args.theDebugger = {
         
     | 
| 
      
 121 
     | 
    
         
            +
                breakOnSemantics: (value) => args.breakOnSemantics = value
         
     | 
| 
      
 122 
     | 
    
         
            +
              }
         
     | 
| 
      
 123 
     | 
    
         
            +
              if (!logs) {
         
     | 
| 
      
 124 
     | 
    
         
            +
              }
         
     | 
| 
      
 125 
     | 
    
         
            +
              args.log = (message) => logs.push(message)
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
              args.addAssumedScoped = (args, assumed) => {
         
     | 
| 
      
 128 
     | 
    
         
            +
                const addAssumed = (args, ...moreAssumed) => {
         
     | 
| 
      
 129 
     | 
    
         
            +
                  return { ...args, assumed: Object.assign({}, assumed, (args.assumed || {}), ...moreAssumed) }
         
     | 
| 
      
 130 
     | 
    
         
            +
                }
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                args.s = (c) => config.getSemantics(logs).apply(args, c)
         
     | 
| 
      
 133 
     | 
    
         
            +
                args.g = (c, a = {}) => {
         
     | 
| 
      
 134 
     | 
    
         
            +
                  return config.getGenerators(logs).apply(addAssumed(args, a), c, a)
         
     | 
| 
      
 135 
     | 
    
         
            +
                }
         
     | 
| 
      
 136 
     | 
    
         
            +
                args.gp = (c, a = {}) => {
         
     | 
| 
      
 137 
     | 
    
         
            +
                  return config.getGenerators(logs).apply(addAssumed(args, a, { paraphrase: true, isResponse: false, response: false }), c, { paraphrase: true, isResponse: false, response: false })
         
     | 
| 
      
 138 
     | 
    
         
            +
                }
         
     | 
| 
      
 139 
     | 
    
         
            +
                args.gr = (c, a = {}) => {
         
     | 
| 
      
 140 
     | 
    
         
            +
                  return config.getGenerators(logs).apply(addAssumed(args, a, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true })
         
     | 
| 
      
 141 
     | 
    
         
            +
                }
         
     | 
| 
      
 142 
     | 
    
         
            +
                args.e = (c) => {
         
     | 
| 
      
 143 
     | 
    
         
            +
                  return config.getEvaluator(args.s, args.calls, logs, c)
         
     | 
| 
      
 144 
     | 
    
         
            +
                }
         
     | 
| 
      
 145 
     | 
    
         
            +
                args.gs = gs(args.g)
         
     | 
| 
      
 146 
     | 
    
         
            +
                args.gsp = gs(args.gp)
         
     | 
| 
      
 147 
     | 
    
         
            +
                args.gsr = gs(args.gr)
         
     | 
| 
      
 148 
     | 
    
         
            +
              }
         
     | 
| 
      
 149 
     | 
    
         
            +
              // for semantics
         
     | 
| 
      
 150 
     | 
    
         
            +
              args.addAssumedScoped(args, {})
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
              const getAPI = (uuid) => {
         
     | 
| 
      
 153 
     | 
    
         
            +
                if (config && config.getAPI) {
         
     | 
| 
      
 154 
     | 
    
         
            +
                  return config.getAPI(uuid)
         
     | 
| 
      
 155 
     | 
    
         
            +
                }
         
     | 
| 
      
 156 
     | 
    
         
            +
              }
         
     | 
| 
      
 157 
     | 
    
         
            +
              const getAPIs = (uuid) => {
         
     | 
| 
      
 158 
     | 
    
         
            +
                if (config && config.getAPIs) {
         
     | 
| 
      
 159 
     | 
    
         
            +
                  return config.getAPIs(uuid)
         
     | 
| 
      
 160 
     | 
    
         
            +
                }
         
     | 
| 
      
 161 
     | 
    
         
            +
              }
         
     | 
| 
      
 162 
     | 
    
         
            +
              args.getUUIDScoped = (uuid) => {
         
     | 
| 
      
 163 
     | 
    
         
            +
                return {
         
     | 
| 
      
 164 
     | 
    
         
            +
                  api: getAPI(uuid),
         
     | 
| 
      
 165 
     | 
    
         
            +
                  apis: getAPIs(uuid)
         
     | 
| 
      
 166 
     | 
    
         
            +
                }
         
     | 
| 
      
 167 
     | 
    
         
            +
              }
         
     | 
| 
      
 168 
     | 
    
         
            +
              config.getAddedArgs(args)
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
              Object.assign(args, args.getUUIDScoped(uuidForScoping || config.uuid))
         
     | 
| 
      
 171 
     | 
    
         
            +
              /*
         
     | 
| 
      
 172 
     | 
    
         
            +
              if (uuidForScoping) {
         
     | 
| 
      
 173 
     | 
    
         
            +
                Object.assign(args, args.getUUIDScoped(uuidForScoping))
         
     | 
| 
      
 174 
     | 
    
         
            +
              }
         
     | 
| 
      
 175 
     | 
    
         
            +
              */
         
     | 
| 
      
 176 
     | 
    
         
            +
              // sets args for all the API. that make a copy so the args must be fully setup by here except for scoped
         
     | 
| 
      
 177 
     | 
    
         
            +
              config.setArgs(args)
         
     | 
| 
      
 178 
     | 
    
         
            +
            }
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
            const getObjects = (objects) => {
         
     | 
| 
      
 181 
     | 
    
         
            +
              return (uuid) => {
         
     | 
| 
      
 182 
     | 
    
         
            +
                if (objects && objects.namespaced) {
         
     | 
| 
      
 183 
     | 
    
         
            +
                  return objects.namespaced[uuid]
         
     | 
| 
      
 184 
     | 
    
         
            +
                }
         
     | 
| 
      
 185 
     | 
    
         
            +
                return objects
         
     | 
| 
      
 186 
     | 
    
         
            +
              }
         
     | 
| 
      
 187 
     | 
    
         
            +
            }
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
            const processContext = async (context, { objects = {}, config, logs = [] }) => {
         
     | 
| 
      
 190 
     | 
    
         
            +
              const generators = config.getGenerators(logs)
         
     | 
| 
      
 191 
     | 
    
         
            +
              const semantics = config.getSemantics(logs)
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
              // map to hash
         
     | 
| 
      
 194 
     | 
    
         
            +
              config = config || {}
         
     | 
| 
      
 195 
     | 
    
         
            +
              if (config.config) {
         
     | 
| 
      
 196 
     | 
    
         
            +
                config = config
         
     | 
| 
      
 197 
     | 
    
         
            +
              }
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
              const response = {} // NA but passed in
         
     | 
| 
      
 200 
     | 
    
         
            +
              // generators = new Generators(generators.map((g) => new Generator(normalizeGenerator(g))))
         
     | 
| 
      
 201 
     | 
    
         
            +
              // semantics = new Semantics(semantics.map((g) => new Semantic(normalizeSemantic(g))))
         
     | 
| 
      
 202 
     | 
    
         
            +
              const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
              const args = { objects, response, getObjects: getObjects(objects) }
         
     | 
| 
      
 205 
     | 
    
         
            +
              setupArgs(args, config, logs, hierarchy)
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
              context = await semantics.apply(args, context)
         
     | 
| 
      
 208 
     | 
    
         
            +
              const generated = await generators.apply(args, context)
         
     | 
| 
      
 209 
     | 
    
         
            +
              const assumed = { paraphrase: true, response: false, isResponse: false }
         
     | 
| 
      
 210 
     | 
    
         
            +
              const paraphrases = await generators.apply({ ...args, assumed }, context, { paraphrase: true, response: false, isResponse: false })
         
     | 
| 
      
 211 
     | 
    
         
            +
              let responses = []
         
     | 
| 
      
 212 
     | 
    
         
            +
              if (context.isResponse) {
         
     | 
| 
      
 213 
     | 
    
         
            +
                responses = generated
         
     | 
| 
      
 214 
     | 
    
         
            +
              }
         
     | 
| 
      
 215 
     | 
    
         
            +
              return { context, generated, paraphrases, responses }
         
     | 
| 
      
 216 
     | 
    
         
            +
            }
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
            const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
         
     | 
| 
      
 219 
     | 
    
         
            +
              const key = config._key
         
     | 
| 
      
 220 
     | 
    
         
            +
             
     | 
| 
      
 221 
     | 
    
         
            +
              const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
         
     | 
| 
      
 222 
     | 
    
         
            +
              if (allowDelta && config.allowDelta && config.hasDelta()) {
         
     | 
| 
      
 223 
     | 
    
         
            +
                // console.log('config', config)
         
     | 
| 
      
 224 
     | 
    
         
            +
                data.delta = config.delta()
         
     | 
| 
      
 225 
     | 
    
         
            +
              } else {
         
     | 
| 
      
 226 
     | 
    
         
            +
                config.toData(data)
         
     | 
| 
      
 227 
     | 
    
         
            +
                // Object.assign(data, config.config)
         
     | 
| 
      
 228 
     | 
    
         
            +
              }
         
     | 
| 
      
 229 
     | 
    
         
            +
             
     | 
| 
      
 230 
     | 
    
         
            +
              // config.toServer(data)
         
     | 
| 
      
 231 
     | 
    
         
            +
             
     | 
| 
      
 232 
     | 
    
         
            +
              if (data.namespaces) {
         
     | 
| 
      
 233 
     | 
    
         
            +
                for (const uuid of Object.keys(data.namespaces)) {
         
     | 
| 
      
 234 
     | 
    
         
            +
                  const km = config.configs.find((km) => km.uuid === uuid)
         
     | 
| 
      
 235 
     | 
    
         
            +
                  data.namespaces[uuid].name = km.name
         
     | 
| 
      
 236 
     | 
    
         
            +
                }
         
     | 
| 
      
 237 
     | 
    
         
            +
              }
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
              // const generators = new Generators((data.generators || []).map((g) => new Generator(normalizeGenerator(g))))
         
     | 
| 
      
 240 
     | 
    
         
            +
              delete data.generators
         
     | 
| 
      
 241 
     | 
    
         
            +
              // const semantics = new Semantics((data.semantics || []).map((g) => new Semantic(normalizeSemantic(g))))
         
     | 
| 
      
 242 
     | 
    
         
            +
              delete data.semantics
         
     | 
| 
      
 243 
     | 
    
         
            +
              const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
         
     | 
| 
      
 244 
     | 
    
         
            +
             
     | 
| 
      
 245 
     | 
    
         
            +
              return {
         
     | 
| 
      
 246 
     | 
    
         
            +
                data,
         
     | 
| 
      
 247 
     | 
    
         
            +
                // generators,
         
     | 
| 
      
 248 
     | 
    
         
            +
                // semantics,
         
     | 
| 
      
 249 
     | 
    
         
            +
                hierarchy
         
     | 
| 
      
 250 
     | 
    
         
            +
              }
         
     | 
| 
      
 251 
     | 
    
         
            +
            }
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
            const setupContexts = (rawContexts) => {
         
     | 
| 
      
 254 
     | 
    
         
            +
              let first = true
         
     | 
| 
      
 255 
     | 
    
         
            +
              const contexts = []
         
     | 
| 
      
 256 
     | 
    
         
            +
              contexts.push({ marker: 'controlStart', controlRemove: true })
         
     | 
| 
      
 257 
     | 
    
         
            +
              for (const context of rawContexts) {
         
     | 
| 
      
 258 
     | 
    
         
            +
                if (first) {
         
     | 
| 
      
 259 
     | 
    
         
            +
                  first = false
         
     | 
| 
      
 260 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 261 
     | 
    
         
            +
                  contexts.push({ marker: 'controlBetween', controlRemove: true })
         
     | 
| 
      
 262 
     | 
    
         
            +
                }
         
     | 
| 
      
 263 
     | 
    
         
            +
                contexts.push(context)
         
     | 
| 
      
 264 
     | 
    
         
            +
              }
         
     | 
| 
      
 265 
     | 
    
         
            +
              contexts.push({ marker: 'controlEnd', controlRemove: true })
         
     | 
| 
      
 266 
     | 
    
         
            +
              return contexts
         
     | 
| 
      
 267 
     | 
    
         
            +
            }
         
     | 
| 
      
 268 
     | 
    
         
            +
             
     | 
| 
      
 269 
     | 
    
         
            +
            const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs }) => {
         
     | 
| 
      
 270 
     | 
    
         
            +
              // TODO fix this name to contextsPrime
         
     | 
| 
      
 271 
     | 
    
         
            +
              const contextsPrime = []
         
     | 
| 
      
 272 
     | 
    
         
            +
              const generatedPrime = []
         
     | 
| 
      
 273 
     | 
    
         
            +
              const paraphrasesPrime = []
         
     | 
| 
      
 274 
     | 
    
         
            +
              const paraphrasesParenthesizedPrime = []
         
     | 
| 
      
 275 
     | 
    
         
            +
              const generatedParenthesizedPrime = []
         
     | 
| 
      
 276 
     | 
    
         
            +
              const responsesPrime = []
         
     | 
| 
      
 277 
     | 
    
         
            +
              const contexts = setupContexts(json.contexts)
         
     | 
| 
      
 278 
     | 
    
         
            +
             
     | 
| 
      
 279 
     | 
    
         
            +
              const objects = config.get('objects')
         
     | 
| 
      
 280 
     | 
    
         
            +
              const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance }
         
     | 
| 
      
 281 
     | 
    
         
            +
              if (!json.logs) {
         
     | 
| 
      
 282 
     | 
    
         
            +
                json.logs = []
         
     | 
| 
      
 283 
     | 
    
         
            +
              }
         
     | 
| 
      
 284 
     | 
    
         
            +
              setupArgs(args, config, json.logs, hierarchy)
         
     | 
| 
      
 285 
     | 
    
         
            +
              const toDo = [...contexts]
         
     | 
| 
      
 286 
     | 
    
         
            +
              args.insert = (context) => toDo.unshift(context)
         
     | 
| 
      
 287 
     | 
    
         
            +
              let overlap, lastRange
         
     | 
| 
      
 288 
     | 
    
         
            +
              config.debugLoops = commandLineArgs && commandLineArgs.debugLoops
         
     | 
| 
      
 289 
     | 
    
         
            +
              while (toDo.length > 0) {
         
     | 
| 
      
 290 
     | 
    
         
            +
                const context = toDo.shift()
         
     | 
| 
      
 291 
     | 
    
         
            +
                args.calls.next()
         
     | 
| 
      
 292 
     | 
    
         
            +
                let contextPrime = context
         
     | 
| 
      
 293 
     | 
    
         
            +
                context.topLevel = true
         
     | 
| 
      
 294 
     | 
    
         
            +
                try {
         
     | 
| 
      
 295 
     | 
    
         
            +
                  if (json.has_errors) {
         
     | 
| 
      
 296 
     | 
    
         
            +
                    throw new Error('There are errors in the logs. Run with the -d flag and grep for Error')
         
     | 
| 
      
 297 
     | 
    
         
            +
                  }
         
     | 
| 
      
 298 
     | 
    
         
            +
                  const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
         
     | 
| 
      
 299 
     | 
    
         
            +
                  if (!config.get('skipSemantics')) {
         
     | 
| 
      
 300 
     | 
    
         
            +
                    const semantics = config.getSemantics(json.logs)
         
     | 
| 
      
 301 
     | 
    
         
            +
                    try {
         
     | 
| 
      
 302 
     | 
    
         
            +
                      contextPrime = await semantics.apply(args, context)
         
     | 
| 
      
 303 
     | 
    
         
            +
                    } catch (e) {
         
     | 
| 
      
 304 
     | 
    
         
            +
                      if (e.message == 'Maximum call stack size exceeded') {
         
     | 
| 
      
 305 
     | 
    
         
            +
                        const mostCalled = semantics.getMostCalled()
         
     | 
| 
      
 306 
     | 
    
         
            +
                        e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
         
     | 
| 
      
 307 
     | 
    
         
            +
                      }
         
     | 
| 
      
 308 
     | 
    
         
            +
                      // contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
         
     | 
| 
      
 309 
     | 
    
         
            +
                      if (isInstance) {
         
     | 
| 
      
 310 
     | 
    
         
            +
                        console.log('error', e.error)
         
     | 
| 
      
 311 
     | 
    
         
            +
                      }
         
     | 
| 
      
 312 
     | 
    
         
            +
                      contextPrime = await semantics.apply(args, {
         
     | 
| 
      
 313 
     | 
    
         
            +
                        marker: 'error',
         
     | 
| 
      
 314 
     | 
    
         
            +
                        context,
         
     | 
| 
      
 315 
     | 
    
         
            +
                        text: e ? e.toString() : 'not available',
         
     | 
| 
      
 316 
     | 
    
         
            +
                        reason: e.reason,
         
     | 
| 
      
 317 
     | 
    
         
            +
                        error: e.stack || e.error
         
     | 
| 
      
 318 
     | 
    
         
            +
                      })
         
     | 
| 
      
 319 
     | 
    
         
            +
                      if (rebuildingTemplate) {
         
     | 
| 
      
 320 
     | 
    
         
            +
                        throw e
         
     | 
| 
      
 321 
     | 
    
         
            +
                      }
         
     | 
| 
      
 322 
     | 
    
         
            +
                    }
         
     | 
| 
      
 323 
     | 
    
         
            +
                  }
         
     | 
| 
      
 324 
     | 
    
         
            +
                  if (contextPrime.controlRemove) {
         
     | 
| 
      
 325 
     | 
    
         
            +
                    continue
         
     | 
| 
      
 326 
     | 
    
         
            +
                  }
         
     | 
| 
      
 327 
     | 
    
         
            +
                  let assumed = { isResponse: true }
         
     | 
| 
      
 328 
     | 
    
         
            +
                  const generated = contextPrime.isResponse ? await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
         
     | 
| 
      
 329 
     | 
    
         
            +
                  let generatedParenthesized = []
         
     | 
| 
      
 330 
     | 
    
         
            +
                  if (generateParenthesized) {
         
     | 
| 
      
 331 
     | 
    
         
            +
                    config.parenthesized = true
         
     | 
| 
      
 332 
     | 
    
         
            +
                    generatedParenthesized = contextPrime.isResponse ? await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
         
     | 
| 
      
 333 
     | 
    
         
            +
                    config.parenthesized = false
         
     | 
| 
      
 334 
     | 
    
         
            +
                  }
         
     | 
| 
      
 335 
     | 
    
         
            +
                  // assumed = { paraphrase: true, response: false };
         
     | 
| 
      
 336 
     | 
    
         
            +
                  assumed = { paraphrase: true, isResponse: false, response: false }
         
     | 
| 
      
 337 
     | 
    
         
            +
                  if (generateParenthesized) {
         
     | 
| 
      
 338 
     | 
    
         
            +
                    config.parenthesized = false
         
     | 
| 
      
 339 
     | 
    
         
            +
                  }
         
     | 
| 
      
 340 
     | 
    
         
            +
                  const paraphrases = await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
         
     | 
| 
      
 341 
     | 
    
         
            +
                  let paraphrasesParenthesized = []
         
     | 
| 
      
 342 
     | 
    
         
            +
                  if (generateParenthesized) {
         
     | 
| 
      
 343 
     | 
    
         
            +
                    config.parenthesized = true
         
     | 
| 
      
 344 
     | 
    
         
            +
                    paraphrasesParenthesized = await config.getGenerators(json.logs).apply({ ...args, assumed }, contextPrime, assumed)
         
     | 
| 
      
 345 
     | 
    
         
            +
                    config.parenthesized = false
         
     | 
| 
      
 346 
     | 
    
         
            +
                  }
         
     | 
| 
      
 347 
     | 
    
         
            +
                  contextsPrime.push(contextPrime)
         
     | 
| 
      
 348 
     | 
    
         
            +
                  generatedPrime.push(generated)
         
     | 
| 
      
 349 
     | 
    
         
            +
                  paraphrasesPrime.push(paraphrases)
         
     | 
| 
      
 350 
     | 
    
         
            +
                  if (generateParenthesized) {
         
     | 
| 
      
 351 
     | 
    
         
            +
                    paraphrasesParenthesizedPrime.push(paraphrasesParenthesized)
         
     | 
| 
      
 352 
     | 
    
         
            +
                    generatedParenthesizedPrime.push(generatedParenthesized)
         
     | 
| 
      
 353 
     | 
    
         
            +
                  }
         
     | 
| 
      
 354 
     | 
    
         
            +
                  if (contextPrime.isResponse) {
         
     | 
| 
      
 355 
     | 
    
         
            +
                    responsesPrime.push(generated)
         
     | 
| 
      
 356 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 357 
     | 
    
         
            +
                    responsesPrime.push('')
         
     | 
| 
      
 358 
     | 
    
         
            +
                  }
         
     | 
| 
      
 359 
     | 
    
         
            +
             
     | 
| 
      
 360 
     | 
    
         
            +
                  // add results to processed list
         
     | 
| 
      
 361 
     | 
    
         
            +
                  config.config.objects.processed = config.config.objects.processed || []
         
     | 
| 
      
 362 
     | 
    
         
            +
                  config.config.objects.processed = config.config.objects.processed.slice(0, 5)
         
     | 
| 
      
 363 
     | 
    
         
            +
                  config.config.objects.processed.unshift({ context: contextPrime, paraphrases: paraphrases, paraphrasesParenthesized, generatedParenthesized, responses: responsesPrime })
         
     | 
| 
      
 364 
     | 
    
         
            +
                } catch (e) {
         
     | 
| 
      
 365 
     | 
    
         
            +
                  if (Array.isArray(e)) {
         
     | 
| 
      
 366 
     | 
    
         
            +
                    e = {
         
     | 
| 
      
 367 
     | 
    
         
            +
                      errors: e
         
     | 
| 
      
 368 
     | 
    
         
            +
                    }
         
     | 
| 
      
 369 
     | 
    
         
            +
                  }
         
     | 
| 
      
 370 
     | 
    
         
            +
                  e.context = contextPrime
         
     | 
| 
      
 371 
     | 
    
         
            +
                  if (e.logs) {
         
     | 
| 
      
 372 
     | 
    
         
            +
                    e.logs = e.logs.concat(json.logs)
         
     | 
| 
      
 373 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 374 
     | 
    
         
            +
                    e.logs = json.logs
         
     | 
| 
      
 375 
     | 
    
         
            +
                  }
         
     | 
| 
      
 376 
     | 
    
         
            +
                  e.metadata = json.metadata
         
     | 
| 
      
 377 
     | 
    
         
            +
                  if (json.trace) {
         
     | 
| 
      
 378 
     | 
    
         
            +
                    e.trace = json.trace
         
     | 
| 
      
 379 
     | 
    
         
            +
                  }
         
     | 
| 
      
 380 
     | 
    
         
            +
                  throw e
         
     | 
| 
      
 381 
     | 
    
         
            +
                }
         
     | 
| 
      
 382 
     | 
    
         
            +
              }
         
     | 
| 
      
 383 
     | 
    
         
            +
              return { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime }
         
     | 
| 
      
 384 
     | 
    
         
            +
            }
         
     | 
| 
      
 385 
     | 
    
         
            +
             
     | 
| 
      
 386 
     | 
    
         
            +
            // instance template loadTemplate
         
     | 
| 
      
 387 
     | 
    
         
            +
            const loadInstance = async (config, instance) => {
         
     | 
| 
      
 388 
     | 
    
         
            +
              const transitoryMode = global.transitoryMode
         
     | 
| 
      
 389 
     | 
    
         
            +
              global.transitoryMode = false
         
     | 
| 
      
 390 
     | 
    
         
            +
             
     | 
| 
      
 391 
     | 
    
         
            +
              if (instance && (instance.associations || instance.learned_contextual_priorities)) {
         
     | 
| 
      
 392 
     | 
    
         
            +
                if (!config.config.retrain) {
         
     | 
| 
      
 393 
     | 
    
         
            +
                  if (instance.associations) {
         
     | 
| 
      
 394 
     | 
    
         
            +
                    config.addAssociations(instance.associations)
         
     | 
| 
      
 395 
     | 
    
         
            +
                  }
         
     | 
| 
      
 396 
     | 
    
         
            +
                  if (instance.learned_contextual_priorities && instance.learned_contextual_priorities.length > 0) {
         
     | 
| 
      
 397 
     | 
    
         
            +
                    config.addPriorities(instance.learned_contextual_priorities)
         
     | 
| 
      
 398 
     | 
    
         
            +
                  }
         
     | 
| 
      
 399 
     | 
    
         
            +
                }
         
     | 
| 
      
 400 
     | 
    
         
            +
              }
         
     | 
| 
      
 401 
     | 
    
         
            +
             
     | 
| 
      
 402 
     | 
    
         
            +
              const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
         
     | 
| 
      
 403 
     | 
    
         
            +
              for (const i in (instance.resultss || [])) {
         
     | 
| 
      
 404 
     | 
    
         
            +
                const results = instance.resultss[i]
         
     | 
| 
      
 405 
     | 
    
         
            +
                if (results.extraConfig) {
         
     | 
| 
      
 406 
     | 
    
         
            +
                  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
         
     | 
| 
      
 407 
     | 
    
         
            +
                  const uuid = config.nameToUUID(instance.name)
         
     | 
| 
      
 408 
     | 
    
         
            +
                  // used to do a CLONE
         
     | 
| 
      
 409 
     | 
    
         
            +
                  config.addInternal(instance.template.configs[i], { uuid, addFirst: true, handleCalculatedProps: true })
         
     | 
| 
      
 410 
     | 
    
         
            +
                } else if (results.apply) {
         
     | 
| 
      
 411 
     | 
    
         
            +
                  const objects = config.get('objects')
         
     | 
| 
      
 412 
     | 
    
         
            +
                  const args = { objects, getObjects: getObjects(objects) }
         
     | 
| 
      
 413 
     | 
    
         
            +
                  if (instance.configs) {
         
     | 
| 
      
 414 
     | 
    
         
            +
                    args.isInstance = `instance${i}`
         
     | 
| 
      
 415 
     | 
    
         
            +
                    args.instance = instance.configs[i]
         
     | 
| 
      
 416 
     | 
    
         
            +
                  }
         
     | 
| 
      
 417 
     | 
    
         
            +
             
     | 
| 
      
 418 
     | 
    
         
            +
                  const uuid = config.nameToUUID(instance.name)
         
     | 
| 
      
 419 
     | 
    
         
            +
                  setupArgs(args, config, config.logs, hierarchy, uuid)
         
     | 
| 
      
 420 
     | 
    
         
            +
                  await results.apply(args)
         
     | 
| 
      
 421 
     | 
    
         
            +
                } else if (results.isFragment) {
         
     | 
| 
      
 422 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 423 
     | 
    
         
            +
                  if (results.skipSemantics) {
         
     | 
| 
      
 424 
     | 
    
         
            +
                    config.config.skipSemantics = results.skipSemantics
         
     | 
| 
      
 425 
     | 
    
         
            +
                  }
         
     | 
| 
      
 426 
     | 
    
         
            +
                  const args = { config, hierarchy, json: results, commandLineArgs: {} }
         
     | 
| 
      
 427 
     | 
    
         
            +
                  args.isInstance = `instance${i}`
         
     | 
| 
      
 428 
     | 
    
         
            +
                  args.instance = ''
         
     | 
| 
      
 429 
     | 
    
         
            +
                  await processContextsB(args)
         
     | 
| 
      
 430 
     | 
    
         
            +
                  if (results.skipSemantics) {
         
     | 
| 
      
 431 
     | 
    
         
            +
                    config.config.skipSemantics = null
         
     | 
| 
      
 432 
     | 
    
         
            +
                  }
         
     | 
| 
      
 433 
     | 
    
         
            +
                }
         
     | 
| 
      
 434 
     | 
    
         
            +
              }
         
     | 
| 
      
 435 
     | 
    
         
            +
              global.transitoryMode = transitoryMode
         
     | 
| 
      
 436 
     | 
    
         
            +
            }
         
     | 
| 
      
 437 
     | 
    
         
            +
             
     | 
| 
      
 438 
     | 
    
         
            +
            module.exports = {
         
     | 
| 
      
 439 
     | 
    
         
            +
              setupProcessB,
         
     | 
| 
      
 440 
     | 
    
         
            +
              ErrorReason,
         
     | 
| 
      
 441 
     | 
    
         
            +
              listable,
         
     | 
| 
      
 442 
     | 
    
         
            +
              setupArgs,
         
     | 
| 
      
 443 
     | 
    
         
            +
              processContext,
         
     | 
| 
      
 444 
     | 
    
         
            +
              getObjects,
         
     | 
| 
      
 445 
     | 
    
         
            +
              gs,
         
     | 
| 
      
 446 
     | 
    
         
            +
              processContextsB,
         
     | 
| 
      
 447 
     | 
    
         
            +
              loadInstance,
         
     | 
| 
      
 448 
     | 
    
         
            +
            }
         
     | 
    
        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/helpers.js
    CHANGED
    
    | 
         @@ -1,6 +1,37 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            const deepEqual = require('deep-equal')
         
     | 
| 
       2 
2 
     | 
    
         
             
            const stringify = require('json-stable-stringify')
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
      
 4 
     | 
    
         
            +
            function where (goUp = 2) {
         
     | 
| 
      
 5 
     | 
    
         
            +
              const e = new Error()
         
     | 
| 
      
 6 
     | 
    
         
            +
              const regexForm1 = /\((.*):(\d+):(\d+)\)$/
         
     | 
| 
      
 7 
     | 
    
         
            +
              const regexForm2 = /at (.*):(\d+):(\d+)$/
         
     | 
| 
      
 8 
     | 
    
         
            +
              const lines = e.stack.split('\n')
         
     | 
| 
      
 9 
     | 
    
         
            +
              let line
         
     | 
| 
      
 10 
     | 
    
         
            +
              let match
         
     | 
| 
      
 11 
     | 
    
         
            +
              for (line of lines.slice(1)) {
         
     | 
| 
      
 12 
     | 
    
         
            +
                // if (!(line.includes('config.js:') || line.includes('client.js:') || line.includes('<anonymous>'))) {
         
     | 
| 
      
 13 
     | 
    
         
            +
                if (!(line.includes('config.js:') || line.includes('client.js:'))) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                  match = regexForm1.exec(line) || regexForm2.exec(line)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  if (!match) {
         
     | 
| 
      
 16 
     | 
    
         
            +
                    continue
         
     | 
| 
      
 17 
     | 
    
         
            +
                  }
         
     | 
| 
      
 18 
     | 
    
         
            +
                  break
         
     | 
| 
      
 19 
     | 
    
         
            +
                }
         
     | 
| 
      
 20 
     | 
    
         
            +
              }
         
     | 
| 
      
 21 
     | 
    
         
            +
              // const line = e.stack.split("\n")[goUp];
         
     | 
| 
      
 22 
     | 
    
         
            +
              // const match = regexForm1.exec(line) || regexForm2.exec(line)
         
     | 
| 
      
 23 
     | 
    
         
            +
              if (match) {
         
     | 
| 
      
 24 
     | 
    
         
            +
                return `${match[1]}:${match[2]}`
         
     | 
| 
      
 25 
     | 
    
         
            +
              } else {
         
     | 
| 
      
 26 
     | 
    
         
            +
                return 'running in browser'
         
     | 
| 
      
 27 
     | 
    
         
            +
              }
         
     | 
| 
      
 28 
     | 
    
         
            +
            }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            function w (func) {
         
     | 
| 
      
 31 
     | 
    
         
            +
              func.where = where(3)
         
     | 
| 
      
 32 
     | 
    
         
            +
              return func
         
     | 
| 
      
 33 
     | 
    
         
            +
            }
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       4 
35 
     | 
    
         
             
            // properties - the properties that correspond to types
         
     | 
| 
       5 
36 
     | 
    
         
             
            // types - the expected types of the properties
         
     | 
| 
       6 
37 
     | 
    
         
             
            // returns list of properties found matching order of types
         
     | 
| 
         @@ -403,5 +434,7 @@ module.exports = { 
     | 
|
| 
       403 
434 
     | 
    
         
             
              InitCalls,
         
     | 
| 
       404 
435 
     | 
    
         
             
              hashCode,
         
     | 
| 
       405 
436 
     | 
    
         
             
              sortJson,
         
     | 
| 
       406 
     | 
    
         
            -
              subPriority
         
     | 
| 
      
 437 
     | 
    
         
            +
              subPriority,
         
     | 
| 
      
 438 
     | 
    
         
            +
              where,
         
     | 
| 
      
 439 
     | 
    
         
            +
              w,
         
     | 
| 
       407 
440 
     | 
    
         
             
            }
         
     |