@knowlearning/agents 0.0.9 → 0.1.1

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.
@@ -13,7 +13,8 @@ const Agent = new GenericAgent({
13
13
  fetch,
14
14
  applyPatch,
15
15
  login,
16
- logout
16
+ logout,
17
+ reboot: () => window.location.reload()
17
18
  })
18
19
 
19
20
  Agent.Experience = Experience
package/agents/deno.js CHANGED
@@ -10,5 +10,6 @@ export default () => new Agent({
10
10
  WebSocket,
11
11
  uuid: () => crypto.randomUUID(),
12
12
  fetch,
13
- applyPatch
13
+ applyPatch,
14
+ reboot: () => Deno.exit(1)
14
15
  })
package/agents/generic.js CHANGED
@@ -12,7 +12,7 @@ function sanitizeJSONPatchPathSegment(s) {
12
12
  else return s
13
13
  }
14
14
 
15
- export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fetch, applyPatch, login, logout }) {
15
+ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fetch, applyPatch, login, logout, reboot }) {
16
16
  let ws
17
17
  let user
18
18
  let domain
@@ -27,6 +27,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
27
27
  const messageQueue = []
28
28
  let resolveEnvironment
29
29
  let disconnected = false
30
+ let failedConnections = 0
30
31
  const environment = new Promise(r => resolveEnvironment = r)
31
32
 
32
33
  const sessionData = new MutableProxy({}, patch => queueMessage({scope: 'sessions', patch}))
@@ -59,6 +60,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
59
60
  this.disconnect = disconnect
60
61
  this.reconnect = reconnect
61
62
 
63
+ console.log('INITIALIZING AGENT CONNECTION')
62
64
  initWS()
63
65
 
64
66
  let lastSentSI = -1
@@ -85,7 +87,11 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
85
87
  function initWS() {
86
88
  ws = new WebSocket(`${protocol}://${host}`)
87
89
 
88
- ws.onopen = async () => ws.send(JSON.stringify({ token: await token, session }))
90
+ ws.onopen = async () => {
91
+ console.log('AUTHORIZING NEWLY OPENED WS FOR SESSION:', session)
92
+ failedConnections = 0
93
+ ws.send(JSON.stringify({ token: await token, session }))
94
+ }
89
95
 
90
96
  ws.onmessage = async ({ data }) => {
91
97
  try {
@@ -100,6 +106,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
100
106
  server = message.server
101
107
  resolveEnvironment(message)
102
108
  }
109
+ else if (server !== message.server) {
110
+ console.warn(`REBOOTING DUE TO SERVER SWITCH ${server} -> ${message.server}`)
111
+ reboot()
112
+ }
103
113
  else {
104
114
  lastSentSI = message.ack
105
115
  }
@@ -148,9 +158,13 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
148
158
  }
149
159
 
150
160
  ws.onclose = async () => {
161
+ if (authed) console.log(`CLOSED DOMAIN ${domain} USER ${user} SESSION ${session} CONNECTION TO SERVER ${server}`)
151
162
  authed = false
152
- console.log(`CLOSED DOMAIN ${domain} USER ${user} SESSION ${session} CONNECTION TO SERVER ${server}`)
153
- if (!disconnected) initWS() // TODO: don't do this if we are purposefully unloading...
163
+ if (!disconnected) {
164
+ await new Promise(r => setTimeout(r, Math.min(1000, failedConnections * 100)))
165
+ failedConnections += 1
166
+ initWS() // TODO: don't do this if we are purposefully unloading...
167
+ }
154
168
  }
155
169
  }
156
170
 
package/agents/node.js CHANGED
@@ -13,5 +13,6 @@ export default () => new Agent({
13
13
  WebSocket,
14
14
  uuid,
15
15
  fetch,
16
- applyPatch: fastJSONPatch.applyPatch
16
+ applyPatch: fastJSONPatch.applyPatch,
17
+ reboot: () => process.exit()
17
18
  })
@@ -1,5 +1,6 @@
1
1
  // TODO: export browser, node, deno, and generic agents
2
2
  export { default as BrowserAgent } from '../agents/browser/embedded.js'
3
3
  export { default as GenericAgent } from '../agents/generic.js'
4
- export { default as vuexCreatePersistentStore } from '../persistence/vuex.js'
5
- export { default as vueContentComponent } from '../vue/3/content.vue'
4
+ export { default as vuePersistentStore } from '../persistence/vuex.js'
5
+ export { default as vueContentComponent } from '../vue/3/content.vue'
6
+ export { default as vuePersistentComponent } from '../vue/3/component.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.0.9",
3
+ "version": "0.1.1",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "package/node.js",
6
6
  "browser": "package/browser.js",
@@ -1,4 +1,4 @@
1
- import { createApp, watchEffect } from 'npm/unscoped/vue/3.2.39'
1
+ import { createApp, watchEffect } from 'vue'
2
2
  import content from "./content.vue"
3
3
 
4
4
  // TODO: probably want to make this a util, and better fleshed out (with white instead of blacklist)
@@ -0,0 +1,4 @@
1
+ // This shim is necessary to specify the vue import for our infrastructure
2
+ import 'npm/unscoped/vue/3.2.39'
3
+
4
+ export { default } from './component.js'