@knowlearning/agents 0.9.0 → 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
|
|
|
@@ -202,6 +205,7 @@ export default function EmbeddedAgent() {
|
|
|
202
205
|
return send({ type: 'login', provider, username, password })
|
|
203
206
|
}
|
|
204
207
|
|
|
208
|
+
function query(query, params) { return send({ type: 'query', query, params }) }
|
|
205
209
|
function logout() { return send({ type: 'logout' }) }
|
|
206
210
|
function disconnect() { return send({ type: 'disconnect' }) }
|
|
207
211
|
function reconnect() { return send({ type: 'reconnect' }) }
|
|
@@ -227,6 +231,7 @@ export default function EmbeddedAgent() {
|
|
|
227
231
|
reconnect,
|
|
228
232
|
synced,
|
|
229
233
|
close,
|
|
234
|
+
query,
|
|
230
235
|
tag
|
|
231
236
|
}
|
|
232
237
|
}
|
|
@@ -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
|
}
|
|
@@ -91,6 +93,10 @@ function embed(environment, iframe) {
|
|
|
91
93
|
const { root, scopes } = message
|
|
92
94
|
sendDown(await Agent.patch(root, scopes))
|
|
93
95
|
}
|
|
96
|
+
else if (type === 'query') {
|
|
97
|
+
const { query, params } = message
|
|
98
|
+
sendDown(await Agent.query(query, params))
|
|
99
|
+
}
|
|
94
100
|
else if (type === 'upload') {
|
|
95
101
|
const { name, contentType, id } = message
|
|
96
102
|
sendDown(await Agent.upload(name, contentType, undefined, id))
|
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
|
|
@@ -421,15 +423,17 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
421
423
|
mode = 'debug'
|
|
422
424
|
}
|
|
423
425
|
|
|
424
|
-
function query(query, params, domain) {
|
|
426
|
+
async function query(query, params, domain) {
|
|
425
427
|
create({
|
|
426
428
|
active_type: POSTGRES_QUERY_TYPE,
|
|
427
429
|
active: { query, params, domain }
|
|
428
430
|
})
|
|
429
|
-
|
|
431
|
+
const { rows } = await lastMessageResponse()
|
|
432
|
+
return rows
|
|
430
433
|
}
|
|
431
434
|
|
|
432
435
|
function tag(tag_type, target, context=[]) {
|
|
436
|
+
console.log('TAGGING', tag_type, target, context)
|
|
433
437
|
return create({
|
|
434
438
|
active_type: TAG_TYPE,
|
|
435
439
|
active: { tag_type, target, context }
|