@knowlearning/agents 0.9.140 → 0.9.141

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.
@@ -14,30 +14,32 @@ const API_HOST = isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST
14
14
  // TODO: remove this hack when we can set partitioned sid cookie through websocket handshake
15
15
  // deno is partly in the way on teh set side, and browser support is in the way for
16
16
  // the client side.
17
- fetch(`http${ SECURE ? 's' : '' }://${API_HOST}/_sid-check`, { method: 'GET', credentials: 'include' })
18
- .then(async response => {
19
- const hasLocalStorageSID = !!localStorage.getItem('sid')
20
- if (response.status === 201) {
21
- if (!hasLocalStorageSID) {
22
- const sentSid = await response.text()
23
- localStorage.setItem('sid', sentSid)
24
- location.reload()
25
- }
17
+ async function ensureSidEstablished() {
18
+ const response = await fetch(`http${ SECURE ? 's' : '' }://${API_HOST}/_sid-check`, { method: 'GET', credentials: 'include' })
19
+ const hasLocalStorageSID = !!localStorage.getItem('sid')
20
+ if (response.status === 201) {
21
+ if (!hasLocalStorageSID) {
22
+ const sentSid = await response.text()
23
+ localStorage.setItem('sid', sentSid)
24
+ location.reload()
26
25
  }
27
- else if (response.status === 200) {
28
- // if we reach here, assumably the server has seen an sid cookie
29
- if (hasLocalStorageSID) {
30
- localStorage.removeItem('sid')
31
- location.reload()
32
- }
33
- }
34
- else {
35
- console.warn('Issue Connecting To the API Server')
26
+ }
27
+ else if (response.status === 200) {
28
+ // if we reach here, assumably the server has seen an sid cookie
29
+ if (hasLocalStorageSID) {
30
+ localStorage.removeItem('sid')
31
+ location.reload()
36
32
  }
37
- })
33
+ }
34
+ else {
35
+ console.warn('Issue Connecting To the API Server')
36
+ }
37
+ }
38
38
 
39
39
  export default options => {
40
+ ensureSidEstablished()
40
41
  const Connection = function () {
42
+
41
43
  const ws = new WebSocket(`ws${ SECURE ? 's' : '' }://${API_HOST}`)
42
44
 
43
45
  this.send = message => ws.send(JSON.stringify(message))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.140",
3
+ "version": "0.9.141",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",