@knowlearning/agents 0.9.141 → 0.9.142

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.
@@ -5,6 +5,12 @@ import selectFile from './select-file.js'
5
5
 
6
6
  let Agent
7
7
 
8
+ function getNamespacedScope(namespace, scope) {
9
+ const allow = namespace?.allow || []
10
+ const prefix = typeof namespace === 'string' ? namespace : namespace?.prefix
11
+ return prefix && !validateUUID(scope) && !allow.some(allowPrefix => scope.startsWith(allowPrefix)) ? `${prefix}/${scope}` : scope
12
+ }
13
+
8
14
  export default function browserAgent(options={}) {
9
15
  if (Agent && !options.unique) return Agent
10
16
 
@@ -80,16 +86,14 @@ function embed(environment, iframe) {
80
86
  }
81
87
  else if (type === 'interact') {
82
88
  let { scope, patch } = message
83
- if (environment.namespace && !validateUUID(scope)) scope = environment.namespace + '/' + scope
84
- // TODO: should use a better approach to instruct agent
85
- // not to generate a tag from this interaction
86
- await Agent.interact(scope, patch, false)
87
- if (listeners.mutate) listeners.mutate({ scope })
89
+ const namespacedScope = getNamespacedScope(environment.namespace, scope)
90
+ await Agent.interact(namespacedScope, patch, false)
91
+ if (listeners.mutate) listeners.mutate({ scope: namespacedScope })
88
92
  sendDown({}) // TODO: might want to send down the interaction index
89
93
  }
90
94
  else if (type === 'metadata') {
91
95
  const { scope, user, domain } = message
92
- const namespacedScope = environment.namespace && !validateUUID(scope) ? `${environment.namespace}/${scope}` : scope
96
+ const namespacedScope = getNamespacedScope(environment.namespace, scope)
93
97
 
94
98
  sendDown(await Agent.metadata(namespacedScope, user, domain))
95
99
  }
@@ -100,7 +104,7 @@ function embed(environment, iframe) {
100
104
  }
101
105
  else if (type === 'state') {
102
106
  const { scope, user, domain } = message
103
- const namespacedScope = environment.namespace && !validateUUID(scope) ? `${environment.namespace}/${scope}` : scope
107
+ const namespacedScope = getNamespacedScope(environment.namespace, scope)
104
108
 
105
109
  const statePromise = Agent.state(namespacedScope, user, domain)
106
110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.141",
3
+ "version": "0.9.142",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",