@knowlearning/agents 0.9.32 → 0.9.34

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.
@@ -211,7 +211,7 @@ export default function EmbeddedAgent() {
211
211
  return send({ type: 'login', provider, username, password })
212
212
  }
213
213
 
214
- function query(query, params) { return send({ type: 'query', query, params }) }
214
+ function query(query, params, domain) { return send({ type: 'query', query, params, domain }) }
215
215
  function logout() { return send({ type: 'logout' }) }
216
216
  function disconnect() { return send({ type: 'disconnect' }) }
217
217
  function reconnect() { return send({ type: 'reconnect' }) }
@@ -60,7 +60,7 @@ function embed(environment, iframe) {
60
60
  else if (type === 'environment') {
61
61
  const { context } = message
62
62
  const env = await Agent.environment()
63
- sendDown({ ...env, context: [...env.context, environment.id] })
63
+ sendDown({ ...env, context: [...env.context, environment.id], mode: environment.mode })
64
64
  }
65
65
  else if (type === 'interact') {
66
66
  const { scope, patch } = message
@@ -97,8 +97,8 @@ function embed(environment, iframe) {
97
97
  sendDown(await Agent.patch(root, scopes))
98
98
  }
99
99
  else if (type === 'query') {
100
- const { query, params } = message
101
- sendDown(await Agent.query(query, params))
100
+ const { query, params, domain } = message
101
+ sendDown(await Agent.query(query, params, domain))
102
102
  }
103
103
  else if (type === 'upload') {
104
104
  const { name, contentType, id } = message
@@ -19,9 +19,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
19
19
  const keyToSubscriptionId = {}
20
20
  const lastInteractionResponse = {}
21
21
  const tagTypeToTargetCache = {}
22
- let resolveEnvironment
23
22
  let mode = 'normal'
24
- const environmentPromise = new Promise(r => resolveEnvironment = r)
25
23
 
26
24
  log('INITIALIZING AGENT CONNECTION')
27
25
  const [
@@ -29,8 +27,9 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
29
27
  lastMessageResponse,
30
28
  disconnect,
31
29
  reconnect,
32
- synced
33
- ] = messageQueue(resolveEnvironment, { token, protocol, host, WebSocket, watchers, states, applyPatch, log, login, interact })
30
+ synced,
31
+ environment
32
+ ] = messageQueue({ token, protocol, host, WebSocket, watchers, states, applyPatch, log, login, interact })
34
33
 
35
34
  const internalReferences = {
36
35
  keyToSubscriptionId,
@@ -50,8 +49,6 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
50
49
 
51
50
  const [ watch, removeWatcher ] = watchImplementation(internalReferences)
52
51
 
53
- async function environment() { return { ...(await environmentPromise), context: [] } }
54
-
55
52
  function state(scope, user, domain) { return stateImplementation(scope, user, domain, internalReferences) }
56
53
 
57
54
  function download(id) { return downloadImplementation(id, internalReferences) }
@@ -14,7 +14,7 @@ function sanitizeJSONPatchPathSegment(s) {
14
14
  else return s
15
15
  }
16
16
 
17
- export default function messageQueue(setEnvironment, { token, protocol, host, WebSocket, watchers, states, applyPatch, log, login, interact }) {
17
+ export default function messageQueue({ token, protocol, host, WebSocket, watchers, states, applyPatch, log, login, interact }) {
18
18
  let ws
19
19
  let user
20
20
  let authed = false
@@ -33,12 +33,17 @@ export default function messageQueue(setEnvironment, { token, protocol, host, We
33
33
  const responses = {}
34
34
 
35
35
 
36
+ let resolveEnvironment
37
+ const environmentPromise = new Promise(r => resolveEnvironment = r)
38
+
36
39
  const sessionMetrics = {
37
40
  loaded: Date.now(),
38
41
  connected: null,
39
42
  authenticated: null
40
43
  }
41
44
 
45
+ async function environment() { return { ...(await environmentPromise), context: [] } }
46
+
42
47
  function queueMessage({ scope, patch }) {
43
48
  if (lastSynchronousScopePatched === scope) {
44
49
  const i = messageQueue.length - 1
@@ -142,7 +147,7 @@ export default function messageQueue(setEnvironment, { token, protocol, host, We
142
147
  {op: 'add', path: ['active', 'authenticated'], value: sessionMetrics.authenticated },
143
148
  ])
144
149
 
145
- setEnvironment(message)
150
+ resolveEnvironment(message)
146
151
  }
147
152
  else if (server !== message.server) {
148
153
  console.warn(`REBOOTING DUE TO SERVER SWITCH ${server} -> ${message.server}`)
@@ -230,5 +235,5 @@ export default function messageQueue(setEnvironment, { token, protocol, host, We
230
235
 
231
236
  initWS()
232
237
 
233
- return [queueMessage, lastMessageResponse, disconnect, reconnect, synced]
238
+ return [queueMessage, lastMessageResponse, disconnect, reconnect, synced, environment]
234
239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.32",
3
+ "version": "0.9.34",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -1,8 +1,8 @@
1
1
  <template>
2
2
  <iframe
3
3
  :v-if="resolvedId"
4
- :key="resolvedId"
5
- :ref="el => setup(el, resolvedId)"
4
+ :key="resolvedId + mode"
5
+ :ref="el => setup(el, resolvedId, mode)"
6
6
  style="
7
7
  width: 100%;
8
8
  height: 100%;
@@ -22,6 +22,10 @@ export default {
22
22
  path: {
23
23
  type: Array,
24
24
  default: []
25
+ },
26
+ mode: {
27
+ type: String,
28
+ required: false
25
29
  }
26
30
  },
27
31
  data() {
@@ -50,11 +54,11 @@ export default {
50
54
  }
51
55
  else this.resolvedId = this.id
52
56
  },
53
- async setup(iframe, id) {
57
+ async setup(iframe, id, mode) {
54
58
  if (!iframe || this.iframe === iframe) return
55
59
 
56
60
  this.iframe = iframe
57
- this.embedding = Agent.embed({ id }, iframe)
61
+ this.embedding = Agent.embed({ id, mode }, iframe)
58
62
  this.embedding.on('state', e => this.$emit('state', e))
59
63
  this.embedding.on('mutate', e => this.$emit('mutate', e))
60
64
  this.embedding.on('close', e => this.$emit('close', e))
package/vue.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { default as vuePersistentStore } from './vue/3/persist/vuex.js'
2
2
  export { default as vuePersistentComponent } from './vue/3/persist/component.js'
3
- export { default as vueEmbedComponent } from './vue/3/components/content.vue'
3
+ export { default as vueEmbedComponent } from './vue/3/components/embed.vue'
4
4
  export { default as vueNameComponent } from './vue/3/components/name.vue'
5
5
  export { default as vueScopeComponent } from './vue/3/components/scope.vue'