@knowlearning/agents 0.9.14 → 0.9.15

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.
Files changed (2) hide show
  1. package/agents/generic.js +14 -10
  2. package/package.json +1 -1
package/agents/generic.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import MutableProxy from '../persistence/json.js'
2
2
  import download from './download.js'
3
3
 
4
+ // TODO: consider using something better than name as mechanism
5
+ // for resoling default scope in context
6
+ const DEFAULT_SCOPE_NAME = '[]'
4
7
  const HEARTBEAT_TIMEOUT = 10000
5
8
  const SESSION_TYPE = 'application/json;type=session'
6
9
  const UPLOAD_TYPE = 'application/json;type=upload'
@@ -297,7 +300,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
297
300
  })
298
301
  }
299
302
 
300
- function watch(id, fn) {
303
+ function watch(scope=DEFAULT_SCOPE_NAME, fn) {
301
304
  let initialSent = false
302
305
  const queue = []
303
306
  function cb(update) {
@@ -305,14 +308,14 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
305
308
  else queue.push(update)
306
309
  }
307
310
 
308
- const statePromise = state(id)
309
- if (!watchers[id]) watchers[id] = []
310
- watchers[id].push(cb)
311
+ const statePromise = state(scope)
312
+ if (!watchers[scope]) watchers[scope] = []
313
+ watchers[scope].push(cb)
311
314
 
312
- metadata(id)
315
+ metadata(scope)
313
316
  .then(async ({ ii }) => {
314
317
  fn({
315
- scope: id,
318
+ scope,
316
319
  state: await statePromise,
317
320
  patch: null,
318
321
  ii
@@ -321,7 +324,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
321
324
  queue.forEach(fn)
322
325
  })
323
326
 
324
- return () => removeWatcher(id, cb)
327
+ return () => removeWatcher(scope, cb)
325
328
  }
326
329
 
327
330
  // TODO: if no data, set up streaming upload
@@ -351,7 +354,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
351
354
  }
352
355
 
353
356
  // TODO: addTag option should probably not be exposed
354
- async function interact(scope, patch, addTag=true) {
357
+ async function interact(scope=DEFAULT_SCOPE_NAME, patch, addTag=true) {
355
358
  if (addTag) tagIfNotYetTaggedInSession('mutated', scope)
356
359
  // TODO: ensure user is owner of scope
357
360
  const response = queueMessage({scope, patch})
@@ -383,7 +386,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
383
386
  return interact('claims', [{ op: 'add', path: ['active', domain], value: null }])
384
387
  }
385
388
 
386
- function reset(scope) {
389
+ function reset(scope=DEFAULT_SCOPE_NAME) {
387
390
  return interact(scope, [{ op: 'remove', path:['active'] }])
388
391
  }
389
392
 
@@ -395,7 +398,8 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
395
398
  )
396
399
  }
397
400
 
398
- async function metadata(id) {
401
+ async function metadata(id=DEFAULT_SCOPE_NAME) {
402
+ // TODO: handle when id is undefined (default like state call?)
399
403
  await state(id)
400
404
  const md = structuredClone(await states[id])
401
405
  delete md.active
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.14",
3
+ "version": "0.9.15",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",