@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.
- package/agents/browser/initialize.js +11 -7
- package/package.json +1 -1
|
@@ -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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
|
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
|
|
107
|
+
const namespacedScope = getNamespacedScope(environment.namespace, scope)
|
|
104
108
|
|
|
105
109
|
const statePromise = Agent.state(namespacedScope, user, domain)
|
|
106
110
|
|