@knowlearning/agents 0.5.7 → 0.5.8
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/agents/generic.js +29 -0
- package/package.json +1 -1
package/agents/generic.js
CHANGED
|
@@ -296,6 +296,33 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
296
296
|
return promise
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
+
function watch(id, fn) {
|
|
300
|
+
let initialSent = false
|
|
301
|
+
const queue = []
|
|
302
|
+
function cb(update) {
|
|
303
|
+
if (initialSent) fn(update)
|
|
304
|
+
else queue.push(update)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const statePromise = state(id)
|
|
308
|
+
if (!watchers[id]) watchers[id] = []
|
|
309
|
+
watchers[id].push(cb)
|
|
310
|
+
|
|
311
|
+
metadata(id)
|
|
312
|
+
.then(async ({ ii }) => {
|
|
313
|
+
fn({
|
|
314
|
+
scope: id,
|
|
315
|
+
state: await statePromise,
|
|
316
|
+
patch: null,
|
|
317
|
+
ii
|
|
318
|
+
})
|
|
319
|
+
initialSent = true
|
|
320
|
+
queue.forEach(fn)
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
return () => removeWatcher(id, cb)
|
|
324
|
+
}
|
|
325
|
+
|
|
299
326
|
// TODO: if no data, set up streaming upload
|
|
300
327
|
async function upload(name, type, data, id=uuid()) {
|
|
301
328
|
// TODO: include data size info...
|
|
@@ -424,10 +451,12 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
424
451
|
}
|
|
425
452
|
|
|
426
453
|
return {
|
|
454
|
+
uuid,
|
|
427
455
|
environment,
|
|
428
456
|
login,
|
|
429
457
|
logout,
|
|
430
458
|
state,
|
|
459
|
+
watch,
|
|
431
460
|
upload,
|
|
432
461
|
download,
|
|
433
462
|
interact,
|