@knowlearning/agents 0.7.5 → 0.7.7

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.
@@ -56,6 +56,12 @@ export default function EmbeddedAgent() {
56
56
  return send({ type: 'environment' })
57
57
  }
58
58
 
59
+ function create({ id=uuid(), active_type, active }) {
60
+ // TODO: collapse into 1 patch and 1 interact call
61
+ interact(id, [{ op: 'add', path: ['active_type'], value: active_type }])
62
+ interact(id, [{ op: 'add', path: ['active'], value: active }])
63
+ }
64
+
59
65
  function state(scope, user, domain) {
60
66
  let watchFn
61
67
  let resolveKey
@@ -134,7 +140,7 @@ export default function EmbeddedAgent() {
134
140
  }
135
141
 
136
142
  function download(id) {
137
- const mode = 'fetch'
143
+ let mode = 'fetch'
138
144
  const promise = new Promise(async (resolve, reject) => {
139
145
  const url = await send({ type: 'download', id })
140
146
 
@@ -193,6 +199,7 @@ export default function EmbeddedAgent() {
193
199
  environment,
194
200
  login,
195
201
  logout,
202
+ create,
196
203
  state,
197
204
  upload,
198
205
  download,
@@ -1,11 +1,11 @@
1
- export default function download (id, { uuid, initialize, lastMessageResponse, fetch, metadata }) {
1
+ const DOWNLOAD_TYPE = 'application/json;type=download'
2
+
3
+ export default function download (id, { create, lastMessageResponse, fetch, metadata }) {
2
4
  // TODO: initialize size info
3
- const downloadId = uuid()
4
- initialize(
5
- downloadId,
6
- 'application/json;type=download',
7
- { id }
8
- )
5
+ create({
6
+ active_type: DOWNLOAD_TYPE,
7
+ active: { id }
8
+ })
9
9
 
10
10
  let mode = 'fetch'
11
11
 
@@ -25,7 +25,7 @@ export default function download (id, { uuid, initialize, lastMessageResponse, f
25
25
  // TODO: throw meaningful error if not in browser context
26
26
  // (following block assumes browser context)
27
27
  // TODO: use browser progress UX instead of downloading all into memory first
28
- const res = await download(id, { uuid, initialize, lastMessageResponse, fetch, metadata })
28
+ const res = await download(id, { create, lastMessageResponse, fetch, metadata })
29
29
  const { name } = await metadata(id)
30
30
  const type = res.headers.get('Content-Type')
31
31
  const blob = new Blob([ await res.blob() ], { type })
package/agents/generic.js CHANGED
@@ -2,6 +2,9 @@ import MutableProxy from '../persistence/json.js'
2
2
  import download from './download.js'
3
3
 
4
4
  const HEARTBEAT_TIMEOUT = 10000
5
+ const UPLOAD_TYPE = 'application/json;type=upload'
6
+ const SUBSCRIPTION_TYPE = 'application/json;type=subscription'
7
+ const POSTGRES_QUERY_TYPE = 'application/json;type=postgres-query'
5
8
 
6
9
  // transform our custom path implementation to the standard JSONPatch path
7
10
  function standardJSONPatch(patch) {
@@ -209,18 +212,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
209
212
  checkHeartbeat()
210
213
  }
211
214
 
212
- function initialize(id, type, value) {
215
+ function create({ id=uuid(), active_type, active }) {
213
216
  // TODO: collapse into 1 patch and 1 interact call
214
- interact(id, [{
215
- op: 'add',
216
- path: ['active_type'],
217
- value: type
218
- }])
219
- interact(id, [{
220
- op: 'add',
221
- path: ['active'],
222
- value
223
- }])
217
+ interact(id, [{ op: 'add', path: ['active_type'], value: active_type }])
218
+ interact(id, [{ op: 'add', path: ['active'], value: active }])
224
219
  }
225
220
 
226
221
  function environment() { return environmentPromise }
@@ -236,11 +231,11 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
236
231
  states[scope] = new Promise(async (resolve, reject) => {
237
232
 
238
233
  const subscriptionId = uuid()
239
- initialize(
240
- subscriptionId,
241
- 'application/json;type=subscription',
242
- { session, scope, ii: null }
243
- )
234
+ create({
235
+ id: subscriptionId,
236
+ active_type: SUBSCRIPTION_TYPE,
237
+ active: { session, scope, ii: null }
238
+ })
244
239
 
245
240
  try {
246
241
  const state = await lastMessageResponse()
@@ -334,15 +329,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
334
329
  // TODO: if no data, set up streaming upload
335
330
  async function upload(name, type, data, id=uuid()) {
336
331
  // TODO: include data size info...
337
- const uploadId = uuid()
338
- initialize(
339
- uploadId,
340
- 'application/json;type=upload',
341
- {
342
- id,
343
- type
344
- }
345
- )
332
+ create({
333
+ active_type: UPLOAD_TYPE,
334
+ active: { id, type }
335
+ })
346
336
  const { url } = await lastMessageResponse()
347
337
 
348
338
  if (data === undefined) return url
@@ -439,11 +429,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
439
429
  }
440
430
 
441
431
  function query(query, params, domain) {
442
- initialize(
443
- uuid(),
444
- 'application/json;type=postgres-query',
445
- { query, params, domain }
446
- )
432
+ create({
433
+ active_type: POSTGRES_QUERY_TYPE,
434
+ active: { query, params, domain }
435
+ })
447
436
  return lastMessageResponse()
448
437
  }
449
438
 
@@ -452,10 +441,11 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
452
441
  environment,
453
442
  login,
454
443
  logout,
444
+ create,
455
445
  state,
456
446
  watch,
457
447
  upload,
458
- download: id => download(id, { uuid, initialize, lastMessageResponse, fetch, download, metadata }),
448
+ download: id => download(id, { create, lastMessageResponse, fetch, metadata }),
459
449
  interact,
460
450
  patch,
461
451
  claim,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -1,4 +1,7 @@
1
1
  import { watchEffect, defineAsyncComponent } from 'vue'
2
+ import { browserAgent } from '../../browser.js'
3
+
4
+ const Agent = browserAgent()
2
5
 
3
6
  // TODO: probably want to make this a util, and better fleshed out (with white instead of blacklist)
4
7
  function isScopeSerializable(v) {