@knowlearning/agents 0.9.1 → 0.9.2
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.
|
@@ -40,6 +40,7 @@ export default function EmbeddedAgent() {
|
|
|
40
40
|
addEventListener('message', async ({ data }) => {
|
|
41
41
|
if (data.type === 'auth') {
|
|
42
42
|
// TODO: switch to access_token
|
|
43
|
+
console.log('localStorage "state", data.state, token', localStorage.getItem('state'), data.state, data.token)
|
|
43
44
|
if (localStorage.getItem('state') === data.state) {
|
|
44
45
|
localStorage.setItem('token', data.token)
|
|
45
46
|
}
|
|
@@ -77,8 +78,9 @@ export default function EmbeddedAgent() {
|
|
|
77
78
|
if (!isUUID(target)) target = (await metadata(target)).id
|
|
78
79
|
|
|
79
80
|
if (!tagTypeToTargetCache[tag_type]) tagTypeToTargetCache[tag_type] = {}
|
|
80
|
-
tagTypeToTargetCache[tag_type][target]
|
|
81
|
+
if (tagTypeToTargetCache[tag_type][target]) return
|
|
81
82
|
|
|
83
|
+
tagTypeToTargetCache[tag_type][target] = true
|
|
82
84
|
await tag(tag_type, target)
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -114,8 +116,9 @@ export default function EmbeddedAgent() {
|
|
|
114
116
|
return interact(scope, [{ op: 'add', path:['active'], value: null }])
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
// TODO: better approach than exposing addTag
|
|
120
|
+
function interact(scope, patch, addTag=true) {
|
|
121
|
+
if (addTag) tagIfNotYetTaggedInSession('mutated', scope)
|
|
119
122
|
return send({ type: 'interact', scope, patch })
|
|
120
123
|
}
|
|
121
124
|
|
|
@@ -65,7 +65,9 @@ function embed(environment, iframe) {
|
|
|
65
65
|
}
|
|
66
66
|
else if (type === 'interact') {
|
|
67
67
|
const { scope, patch } = message
|
|
68
|
-
|
|
68
|
+
// TODO: should use a better approach to instruct agent
|
|
69
|
+
// not to generate a tag from this interaction
|
|
70
|
+
await Agent.interact(scope, patch, false)
|
|
69
71
|
if (listeners.mutate) listeners.mutate({ scope })
|
|
70
72
|
sendDown({}) // TODO: might want to send down the interaction index
|
|
71
73
|
}
|
package/agents/generic.js
CHANGED
|
@@ -222,6 +222,8 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
222
222
|
if (targetCache && targetCache[target]) return
|
|
223
223
|
|
|
224
224
|
if (!targetCache) tagTypeToTargetCache[tag_type] = {}
|
|
225
|
+
if (tagTypeToTargetCache[tag_type][target]) return
|
|
226
|
+
|
|
225
227
|
tagTypeToTargetCache[tag_type][target] = true
|
|
226
228
|
|
|
227
229
|
// always use absolute referene when tagging
|
|
@@ -431,6 +433,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
431
433
|
}
|
|
432
434
|
|
|
433
435
|
function tag(tag_type, target, context=[]) {
|
|
436
|
+
console.log('TAGGING', tag_type, target, context)
|
|
434
437
|
return create({
|
|
435
438
|
active_type: TAG_TYPE,
|
|
436
439
|
active: { tag_type, target, context }
|