@knowlearning/agents 0.9.90 → 0.9.92

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.
@@ -4,18 +4,23 @@ import { getToken, login, logout } from './auth.js'
4
4
  import GenericAgent from '../generic/index.js'
5
5
 
6
6
  const DEVELOPMENT_HOST = 'localhost:32001'
7
- const REMOTE_HOST = 'api.knowlearning.systems'
7
+ const REMOTE_HOST = localStorage.getItem('mode') === 'staging' ? 'api.staging.knowlearning.systems' : 'api.knowlearning.systems'
8
8
 
9
9
  function isLocal() { return localStorage.getItem('api') === 'local' }
10
10
 
11
+ const API_HOST = isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST
12
+
11
13
  export default options => {
12
14
  const { host, protocol } = window.location
13
15
 
14
16
  const Connection = function () {
15
- const ws = new WebSocket(`${protocol === 'https:' ? 'wss' : 'ws'}://${isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST}`)
17
+ const ws = new WebSocket(`${protocol === 'https:' ? 'wss' : 'ws'}://${API_HOST}`)
16
18
 
17
19
  this.send = message => ws.send(JSON.stringify(message))
18
- this.close = () => ws.close()
20
+ this.close = info => {
21
+ this.send({ type: 'close', info })
22
+ ws.close()
23
+ }
19
24
 
20
25
  ws.onopen = () => this.onopen()
21
26
  ws.onmessage = ({ data }) => this.onmessage(data.length === 0 ? null : JSON.parse(data))
@@ -37,15 +42,12 @@ export default options => {
37
42
  })
38
43
 
39
44
  agent.local = () => {
40
- if (isLocal()) return
41
-
42
45
  localStorage.setItem('api', 'local')
43
46
  location.reload()
44
47
  }
45
- agent.remote = () => {
46
- if (!isLocal()) return
47
-
48
- localStorage.removeItem('api')
48
+ agent.remote = (mode='production') => {
49
+ localStorage.setItem('api', 'remote')
50
+ localStorage.setItem('mode', mode)
49
51
  location.reload()
50
52
  }
51
53
  agent.close = () => {
@@ -236,7 +236,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
236
236
  function disconnect() {
237
237
  log('DISCONNECTED AGENT!!!!!!!!!!!!!!!')
238
238
  disconnected = true
239
- connection.close()
239
+ connection.close({ keepalive: true })
240
240
  }
241
241
 
242
242
  function reconnect() {
package/deno.js CHANGED
@@ -34,6 +34,7 @@ const agent = new Agent({
34
34
  // concept probably has a place in the generic agent
35
35
  if (type === 'open') {
36
36
  const child = {
37
+ environment: data,
37
38
  on: (eventType, reaction) => {
38
39
  if (!listeners[session]) throw new Error('Error attaching listener, child is closed')
39
40
  if (!listeners[session][eventType]) throw new Error('Only "mutate" and "close" events can be listened to with Agent.on')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.90",
3
+ "version": "0.9.92",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",