@knowlearning/agents 0.9.14 → 0.9.16
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.
|
@@ -209,7 +209,7 @@ export default function EmbeddedAgent() {
|
|
|
209
209
|
function disconnect() { return send({ type: 'disconnect' }) }
|
|
210
210
|
function reconnect() { return send({ type: 'reconnect' }) }
|
|
211
211
|
function synced() { return send({ type: 'synced' }) }
|
|
212
|
-
function close() { return send({ type: 'close' }) }
|
|
212
|
+
function close(info) { return send({ type: 'close', info }) }
|
|
213
213
|
|
|
214
214
|
return {
|
|
215
215
|
embedded: true,
|
|
@@ -54,8 +54,7 @@ function embed(environment, iframe) {
|
|
|
54
54
|
sendDown({})
|
|
55
55
|
}
|
|
56
56
|
else if (type === 'close') {
|
|
57
|
-
|
|
58
|
-
if (listeners.close) listeners.close()
|
|
57
|
+
if (listeners.close) listeners.close(message.info)
|
|
59
58
|
}
|
|
60
59
|
else if (type === 'environment') {
|
|
61
60
|
const env = await Agent.environment()
|
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(
|
|
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(
|
|
309
|
-
if (!watchers[
|
|
310
|
-
watchers[
|
|
311
|
+
const statePromise = state(scope)
|
|
312
|
+
if (!watchers[scope]) watchers[scope] = []
|
|
313
|
+
watchers[scope].push(cb)
|
|
311
314
|
|
|
312
|
-
metadata(
|
|
315
|
+
metadata(scope)
|
|
313
316
|
.then(async ({ ii }) => {
|
|
314
317
|
fn({
|
|
315
|
-
scope
|
|
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(
|
|
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
|
@@ -28,29 +28,7 @@ export default function (module, scope) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
else if (component.setup) {
|
|
31
|
-
|
|
32
|
-
const isReactiveRef = r => r && r.__v_isRef
|
|
33
|
-
component.setup = function setupProxy(a, b) { // need to specifically add this here, otherwise second argument not passed in arguments array (probably because of webpack optimization...)
|
|
34
|
-
let refs = origSetupFn.call(this, a, b)
|
|
35
|
-
|
|
36
|
-
Object
|
|
37
|
-
.entries(state)
|
|
38
|
-
.filter(([k]) => isReactiveRef(refs[k]))
|
|
39
|
-
.forEach(([k, v]) => refs[k].value = v)
|
|
40
|
-
|
|
41
|
-
Object
|
|
42
|
-
.entries(refs)
|
|
43
|
-
.filter(([_,r]) => isReactiveRef(r) && isScopeSerializable(r.value))
|
|
44
|
-
.forEach(([key, ref]) => {
|
|
45
|
-
watchEffect(() => {
|
|
46
|
-
if (state[key] !== ref.value) {
|
|
47
|
-
state[key] = ref.value
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return refs
|
|
53
|
-
}
|
|
31
|
+
throw new Error('vuePersistantCompoent is for components using the Options API. To use the composition API see https://docs.knowlearning.systems/frameworks/vue/')
|
|
54
32
|
}
|
|
55
33
|
}
|
|
56
34
|
|