@knowlearning/agents 0.9.92 → 0.9.94
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/root.js +4 -3
- package/deno.js +6 -1
- package/package.json +1 -1
package/agents/browser/root.js
CHANGED
|
@@ -3,7 +3,8 @@ import { applyPatch } from 'fast-json-patch'
|
|
|
3
3
|
import { getToken, login, logout } from './auth.js'
|
|
4
4
|
import GenericAgent from '../generic/index.js'
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const SECURE = window.location.protocol === 'https:'
|
|
7
|
+
const DEVELOPMENT_HOST = `localhost:3200${ SECURE ? '1' : '2' }`
|
|
7
8
|
const REMOTE_HOST = localStorage.getItem('mode') === 'staging' ? 'api.staging.knowlearning.systems' : 'api.knowlearning.systems'
|
|
8
9
|
|
|
9
10
|
function isLocal() { return localStorage.getItem('api') === 'local' }
|
|
@@ -11,10 +12,10 @@ function isLocal() { return localStorage.getItem('api') === 'local' }
|
|
|
11
12
|
const API_HOST = isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST
|
|
12
13
|
|
|
13
14
|
export default options => {
|
|
14
|
-
const { host
|
|
15
|
+
const { host } = window.location
|
|
15
16
|
|
|
16
17
|
const Connection = function () {
|
|
17
|
-
const ws = new WebSocket(
|
|
18
|
+
const ws = new WebSocket(`ws${ SECURE ? 's' : '' }://${API_HOST}`)
|
|
18
19
|
|
|
19
20
|
this.send = message => ws.send(JSON.stringify(message))
|
|
20
21
|
this.close = info => {
|
package/deno.js
CHANGED
|
@@ -46,7 +46,8 @@ const agent = new Agent({
|
|
|
46
46
|
trigger('child', child)
|
|
47
47
|
}
|
|
48
48
|
else if (type === 'mutate') {
|
|
49
|
-
|
|
49
|
+
const filteredData = { ...data, patch: activePatch(data.patch) }
|
|
50
|
+
listeners[session].mutate.forEach(f => f(filteredData))
|
|
50
51
|
}
|
|
51
52
|
else if (type === 'close') {
|
|
52
53
|
listeners[session].close.forEach(f => f(data))
|
|
@@ -56,4 +57,8 @@ const agent = new Agent({
|
|
|
56
57
|
}
|
|
57
58
|
})
|
|
58
59
|
|
|
60
|
+
function activePatch(patch) {
|
|
61
|
+
return structuredClone(patch).filter(({ path }) => 'active' === path.shift())
|
|
62
|
+
}
|
|
63
|
+
|
|
59
64
|
export default agent
|