@knowlearning/agents 0.9.25 → 0.9.26
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.
|
@@ -38,22 +38,17 @@ export default function EmbeddedAgent() {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
addEventListener('message', async ({ data }) => {
|
|
41
|
-
if (data.type === '
|
|
42
|
-
// TODO: switch to access_token
|
|
43
|
-
if (localStorage.getItem('state') === data.state) {
|
|
44
|
-
localStorage.setItem('token', data.token)
|
|
45
|
-
}
|
|
46
|
-
send({ type: 'close' })
|
|
47
|
-
}
|
|
48
|
-
else if (data.type === 'setup') resolveSession(data.session)
|
|
41
|
+
if (data.type === 'setup') resolveSession(data.session)
|
|
49
42
|
else if (responses[data.requestId]) {
|
|
50
43
|
const { resolve, reject } = responses[data.requestId]
|
|
51
44
|
if (data.error) reject(data.error)
|
|
52
45
|
else resolve(data.response)
|
|
53
46
|
}
|
|
54
47
|
else if (data.ii !== undefined) {
|
|
55
|
-
const { scope } = data
|
|
56
|
-
|
|
48
|
+
const { scope, user } = data
|
|
49
|
+
const { auth } = await environment()
|
|
50
|
+
const key = isUUID(scope) ? scope : `${!user || auth.user === user ? '' : user}/${scope}`
|
|
51
|
+
if (watchers[key]) watchers[key].forEach(fn => fn(data))
|
|
57
52
|
}
|
|
58
53
|
})
|
|
59
54
|
|
|
@@ -83,12 +78,13 @@ export default function EmbeddedAgent() {
|
|
|
83
78
|
await tag(tag_type, target)
|
|
84
79
|
}
|
|
85
80
|
|
|
86
|
-
|
|
87
|
-
function watch(id, fn) {
|
|
81
|
+
function watch(id, fn, user) {
|
|
88
82
|
tagIfNotYetTaggedInSession('subscribed', id)
|
|
89
|
-
|
|
90
|
-
watchers[
|
|
91
|
-
|
|
83
|
+
const key = isUUID(id) ? id : `${ user || ''}/${id}`
|
|
84
|
+
if (!watchers[key]) watchers[key] = []
|
|
85
|
+
watchers[key].push(fn)
|
|
86
|
+
send({ type: 'state', scope: id, user })
|
|
87
|
+
return () => removeWatcher(key, fn)
|
|
92
88
|
}
|
|
93
89
|
|
|
94
90
|
async function patch(root, scopes) {
|
|
@@ -108,7 +104,6 @@ export default function EmbeddedAgent() {
|
|
|
108
104
|
activePatch.forEach(entry => entry.path.unshift('active'))
|
|
109
105
|
interact(scope, activePatch)
|
|
110
106
|
})
|
|
111
|
-
|
|
112
107
|
}
|
|
113
108
|
|
|
114
109
|
function reset(scope) {
|
|
@@ -71,7 +71,8 @@ function embed(environment, iframe) {
|
|
|
71
71
|
sendDown({}) // TODO: might want to send down the interaction index
|
|
72
72
|
}
|
|
73
73
|
else if (type === 'metadata') {
|
|
74
|
-
|
|
74
|
+
const { scope, user } = message
|
|
75
|
+
sendDown(await Agent.metadata(scope, user))
|
|
75
76
|
}
|
|
76
77
|
else if (type === 'tag') {
|
|
77
78
|
const { tag_type, target, context } = message
|
|
@@ -79,11 +80,14 @@ function embed(environment, iframe) {
|
|
|
79
80
|
sendDown(await Agent.tag(tag_type, target, prependedContext))
|
|
80
81
|
}
|
|
81
82
|
else if (type === 'state') {
|
|
82
|
-
const { scope } = message
|
|
83
|
+
const { scope, user } = message
|
|
83
84
|
|
|
84
|
-
const statePromise = Agent.state(scope)
|
|
85
|
+
const statePromise = Agent.state(scope, user)
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
const key = `${user || ''}/${scope}`
|
|
88
|
+
if (!watchers[key]) {
|
|
89
|
+
watchers[key] = Agent.watch(scope, postMessage, user)
|
|
90
|
+
}
|
|
87
91
|
|
|
88
92
|
if (listeners.state) listeners.state({ scope })
|
|
89
93
|
sendDown(await statePromise)
|