@knowlearning/agents 0.5.7 → 0.5.9
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 +39 -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...
|
|
@@ -423,11 +450,22 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
423
450
|
mode = 'debug'
|
|
424
451
|
}
|
|
425
452
|
|
|
453
|
+
function query(query, params) {
|
|
454
|
+
initialize(
|
|
455
|
+
uuid(),
|
|
456
|
+
'application/json;type=postgres-query',
|
|
457
|
+
{ query, params }
|
|
458
|
+
)
|
|
459
|
+
return lastMessageResponse()
|
|
460
|
+
}
|
|
461
|
+
|
|
426
462
|
return {
|
|
463
|
+
uuid,
|
|
427
464
|
environment,
|
|
428
465
|
login,
|
|
429
466
|
logout,
|
|
430
467
|
state,
|
|
468
|
+
watch,
|
|
431
469
|
upload,
|
|
432
470
|
download,
|
|
433
471
|
interact,
|
|
@@ -435,6 +473,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
435
473
|
claim,
|
|
436
474
|
reset,
|
|
437
475
|
metadata,
|
|
476
|
+
query,
|
|
438
477
|
synced,
|
|
439
478
|
disconnect,
|
|
440
479
|
reconnect,
|