@knowlearning/agents 0.3.18 → 0.4.0
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/browser/embed.js +20 -21
- package/agents/generic.js +18 -20
- package/package.json +1 -1
- package/vue/3/content.vue +2 -6
package/agents/browser/embed.js
CHANGED
|
@@ -95,28 +95,27 @@ export default function embed(environment, iframe) {
|
|
|
95
95
|
|
|
96
96
|
// TODO: make sure content security policy headers for embedded domain always restrict iframe
|
|
97
97
|
// src to only self for embedded domain
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
frameLoaded = true
|
|
103
|
-
processPostMessageQueue()
|
|
104
|
-
}
|
|
105
|
-
const { protocol, pathname } = window.location
|
|
106
|
-
if (validateUUID(environment.content)) {
|
|
107
|
-
// TODO: fix development port workararounds for embed
|
|
108
|
-
if (protocol === 'http:') embed = embed.replace(':32002', ':32020')
|
|
109
|
-
iframe.src = `${protocol}//${embed}${pathname}?s=${session}`
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
iframe.src = environment.content
|
|
113
|
-
}
|
|
98
|
+
iframe.onload = () => {
|
|
99
|
+
frameLoaded = true
|
|
100
|
+
processPostMessageQueue()
|
|
101
|
+
}
|
|
114
102
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
103
|
+
setUpEmbeddedFrame()
|
|
104
|
+
|
|
105
|
+
async function setUpEmbeddedFrame() {
|
|
106
|
+
const { protocol } = window.location
|
|
107
|
+
const { id } = environment
|
|
108
|
+
if (validateUUID(id)) {
|
|
109
|
+
const { domain } = await Agent.metadata(id)
|
|
110
|
+
iframe.src = `${protocol}//${domain}/${id}`
|
|
111
|
+
}
|
|
112
|
+
else iframe.src = id // TODO: ensure is url
|
|
113
|
+
|
|
114
|
+
while(!embeddedAgentInitialized) {
|
|
115
|
+
postMessage({ type: 'setup', session })
|
|
116
|
+
await new Promise(r => setTimeout(r, 100))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
120
119
|
|
|
121
120
|
function remove () {
|
|
122
121
|
if (iframe.parentNode) iframe.parentNode.removeChild(iframe)
|
package/agents/generic.js
CHANGED
|
@@ -39,14 +39,11 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
39
39
|
let lastSentSI = -1
|
|
40
40
|
let lastHeartbeat
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
downloads: {},
|
|
48
|
-
patches: {}
|
|
49
|
-
}
|
|
42
|
+
// TODO: probably an use "mutate" function from below
|
|
43
|
+
const subscriptions = new MutableProxy({}, patch => queueMessage({scope: 'subscriptions', patch}))
|
|
44
|
+
const uploads = new MutableProxy({}, patch => queueMessage({scope: 'uploads', patch}))
|
|
45
|
+
const downloads = new MutableProxy({}, patch => queueMessage({scope: 'downloads', patch}))
|
|
46
|
+
const patches = new MutableProxy({}, patch => queueMessage({scope: 'patches', patch}))
|
|
50
47
|
|
|
51
48
|
log('INITIALIZING AGENT CONNECTION')
|
|
52
49
|
initWS()
|
|
@@ -157,10 +154,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
157
154
|
else {
|
|
158
155
|
const key = `${message.domain}/${message.user}/${message.scope}`
|
|
159
156
|
if (watchers[key]) {
|
|
160
|
-
if (
|
|
157
|
+
if (subscriptions[key] + 1 !== message.ii) {
|
|
161
158
|
// TODO: this seems to be an error that happens with decent regularity (an answer with a given si was skipped/failed)
|
|
162
159
|
// we should be wary of out-of-order ii being passed down (maybe need to wait for older ones???)
|
|
163
|
-
console.warn('UNEXPECTED UPDATE INTERACTION INDEX!!!!!!!!!!! last index in session',
|
|
160
|
+
console.warn('UNEXPECTED UPDATE INTERACTION INDEX!!!!!!!!!!! last index in session', subscriptions[key], ' passed index ', message.ii)
|
|
164
161
|
}
|
|
165
162
|
states[key] = await states[key] || {}
|
|
166
163
|
|
|
@@ -169,7 +166,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
169
166
|
|
|
170
167
|
applyPatch(states[key], standardJSONPatch(message.patch.slice(lastResetPatchIndex + 1)))
|
|
171
168
|
watchers[key].forEach(fn => fn({ ...message, state: states[key] }))
|
|
172
|
-
|
|
169
|
+
subscriptions[key] = message.ii
|
|
173
170
|
}
|
|
174
171
|
}
|
|
175
172
|
}
|
|
@@ -211,15 +208,15 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
211
208
|
if (states[k] === undefined) {
|
|
212
209
|
watchers[k] = []
|
|
213
210
|
states[k] = new Promise(async resolve => {
|
|
214
|
-
|
|
211
|
+
subscriptions[k] = null
|
|
215
212
|
const { ii, state } = await lastMessageResponse()
|
|
216
|
-
|
|
213
|
+
subscriptions[k] = ii
|
|
217
214
|
resolve(state)
|
|
218
215
|
if (ii === -1) {
|
|
219
216
|
// -1 indicates the result is a computed scope, so
|
|
220
217
|
// ii does not apply (we clear out the subscription to not cache value)
|
|
221
218
|
delete states[k]
|
|
222
|
-
delete
|
|
219
|
+
delete subscriptions[k]
|
|
223
220
|
}
|
|
224
221
|
})
|
|
225
222
|
}
|
|
@@ -249,7 +246,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
249
246
|
const k = await key
|
|
250
247
|
removeWatcher(k, watchFn)
|
|
251
248
|
if (watchers[k].length === 0) {
|
|
252
|
-
delete
|
|
249
|
+
delete subscriptions[k]
|
|
253
250
|
delete watchers[k]
|
|
254
251
|
}
|
|
255
252
|
}
|
|
@@ -260,9 +257,9 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
260
257
|
// TODO: if no data, set up streaming upload
|
|
261
258
|
async function upload(name, type, data, id=uuid()) {
|
|
262
259
|
// TODO: include data size info...
|
|
263
|
-
|
|
260
|
+
uploads[id] = { url: null, sent: 0, name, type }
|
|
264
261
|
const { url } = await lastMessageResponse()
|
|
265
|
-
|
|
262
|
+
uploads[id].url = url
|
|
266
263
|
|
|
267
264
|
if (data === undefined) return url
|
|
268
265
|
else {
|
|
@@ -276,9 +273,9 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
276
273
|
}
|
|
277
274
|
|
|
278
275
|
async function download(id, passthrough=false) {
|
|
279
|
-
|
|
276
|
+
downloads[id] = { url: null, size: null, sent: 0 }
|
|
280
277
|
const { url } = await lastMessageResponse()
|
|
281
|
-
|
|
278
|
+
downloads[id].url = url
|
|
282
279
|
|
|
283
280
|
if (passthrough) return url
|
|
284
281
|
else {
|
|
@@ -291,7 +288,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
291
288
|
}
|
|
292
289
|
|
|
293
290
|
async function patch(root, scopes) {
|
|
294
|
-
|
|
291
|
+
patches[uuid()] = { root, scopes }
|
|
295
292
|
const { swaps } = await lastMessageResponse()
|
|
296
293
|
return { swaps }
|
|
297
294
|
}
|
|
@@ -333,6 +330,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
333
330
|
}
|
|
334
331
|
|
|
335
332
|
async function mutate(scope, initialize=true) {
|
|
333
|
+
// TODO: probably can remove redundant copy
|
|
336
334
|
const initial = initialize ? copy(await state(scope) || {}) : {}
|
|
337
335
|
return new MutableProxy(initial, patch => interact(scope, patch))
|
|
338
336
|
}
|
package/package.json
CHANGED
package/vue/3/content.vue
CHANGED
|
@@ -12,10 +12,6 @@ export default {
|
|
|
12
12
|
id: {
|
|
13
13
|
type: String,
|
|
14
14
|
required: true
|
|
15
|
-
},
|
|
16
|
-
scope: {
|
|
17
|
-
type: String,
|
|
18
|
-
required: false
|
|
19
15
|
}
|
|
20
16
|
},
|
|
21
17
|
unmounted() {
|
|
@@ -25,9 +21,9 @@ export default {
|
|
|
25
21
|
setup(iframe) {
|
|
26
22
|
if (!iframe || this.iframe === iframe) return
|
|
27
23
|
|
|
28
|
-
const { id
|
|
24
|
+
const { id } = this
|
|
29
25
|
this.iframe = iframe
|
|
30
|
-
this.embedding = Agent.embed({
|
|
26
|
+
this.embedding = Agent.embed({ id }, iframe)
|
|
31
27
|
|
|
32
28
|
/*
|
|
33
29
|
const { handle } = this.embedding
|