@knowlearning/agents 0.9.42 → 0.9.44

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.
@@ -63,7 +63,8 @@ function embed(environment, iframe) {
63
63
  sendDown({ ...env, context: [...(env.context || []), environment.id], mode: environment.mode })
64
64
  }
65
65
  else if (type === 'interact') {
66
- const { scope, patch } = message
66
+ let { scope, patch } = message
67
+ if (environment.namespace && !validateUUID(scope)) scope = environment.namespace + '/' + scope
67
68
  // TODO: should use a better approach to instruct agent
68
69
  // not to generate a tag from this interaction
69
70
  await Agent.interact(scope, patch, false)
@@ -81,12 +82,13 @@ function embed(environment, iframe) {
81
82
  }
82
83
  else if (type === 'state') {
83
84
  const { scope, user, domain } = message
85
+ const namespacedScope = environment.namespace && !validateUUID(scope) ? `${environment.namespace}/${scope}` : scope
84
86
 
85
- const statePromise = Agent.state(scope, user, domain)
87
+ const statePromise = Agent.state(namespacedScope, user, domain)
86
88
 
87
- const key = `${ domain || ''}/${user || ''}/${scope}`
89
+ const key = `${ domain || ''}/${user || ''}/${namespacedScope}`
88
90
  if (!watchers[key]) {
89
- watchers[key] = Agent.watch(scope, postMessage, user, domain)
91
+ watchers[key] = Agent.watch(namespacedScope, m => postMessage({ ...m, scope }), user, domain)
90
92
  }
91
93
 
92
94
  if (listeners.state) listeners.state({ scope })
@@ -49,6 +49,15 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
49
49
 
50
50
  const [ watch, removeWatcher ] = watchImplementation(internalReferences)
51
51
 
52
+ const sessionPromise = new Promise(async resolve => {
53
+ const { session } = await environment()
54
+ const sessions = await state('sessions')
55
+ sessions[session] = {
56
+ queries: {}
57
+ }
58
+ resolve(sessions[session])
59
+ })
60
+
52
61
  function state(scope, user, domain) { return stateImplementation(scope, user, domain, internalReferences) }
53
62
 
54
63
  function download(id) { return downloadImplementation(id, internalReferences) }
@@ -168,14 +177,12 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
168
177
  }
169
178
 
170
179
  async function query(query, params, domain) {
180
+ const session = await sessionPromise
171
181
  const id = uuid()
172
- create({
173
- id,
174
- active_type: POSTGRES_QUERY_TYPE,
175
- active: { query, params, domain, requested: Date.now() },
176
- })
182
+ const requested = Date.now()
183
+ session.queries[id] = { query, params, domain }
177
184
  const { rows } = await lastMessageResponse()
178
- interact(id, [{ op: 'add', path: ['active', 'responded'], value: Date.now() }])
185
+ session.queries[id].agent_latency = Date.now() - requested
179
186
  return rows
180
187
  }
181
188
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.42",
3
+ "version": "0.9.44",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -2,7 +2,7 @@
2
2
  <iframe
3
3
  :v-if="resolvedId"
4
4
  :key="resolvedId + mode"
5
- :ref="el => setup(el, resolvedId, mode)"
5
+ :ref="el => setup(el, resolvedId, mode, namespace)"
6
6
  style="
7
7
  width: 100%;
8
8
  height: 100%;
@@ -27,6 +27,10 @@ export default {
27
27
  type: String,
28
28
  required: false
29
29
  },
30
+ namespace: {
31
+ type: String,
32
+ required: false
33
+ },
30
34
  environmentProxy: {
31
35
  type: Function,
32
36
  required: false
@@ -58,11 +62,11 @@ export default {
58
62
  }
59
63
  else this.resolvedId = this.id
60
64
  },
61
- async setup(iframe, id, mode) {
65
+ async setup(iframe, id, mode, namespace) {
62
66
  if (!iframe || this.iframe === iframe) return
63
67
 
64
68
  this.iframe = iframe
65
- this.embedding = Agent.embed({ id, mode }, iframe)
69
+ this.embedding = Agent.embed({ id, mode, namespace }, iframe)
66
70
  this.embedding.on('environment', e => this.environmentProxy ? this.environmentProxy(e) : Agent.environment(e))
67
71
  this.embedding.on('state', e => this.$emit('state', e))
68
72
  this.embedding.on('mutate', e => this.$emit('mutate', e))