@knowlearning/agents 0.9.80 → 0.9.83

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,11 +14,11 @@ export default options => {
14
14
  const Connection = function () {
15
15
  const ws = new WebSocket(`${protocol === 'https:' ? 'wss' : 'ws'}://${isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST}`)
16
16
 
17
- this.send = message => ws.send(message)
17
+ this.send = message => ws.send(JSON.stringify(message))
18
18
  this.close = () => ws.close()
19
19
 
20
- ws.onopen = () => this.onopen && this.onopen()
21
- ws.onmessage = ({ data }) => this.onmessage && this.onmessage(data)
20
+ ws.onopen = () => this.onopen()
21
+ ws.onmessage = ({ data }) => this.onmessage(data)
22
22
  ws.onerror = error => this.onerror && this.onerror(error)
23
23
  ws.onclose = error => this.onclose && this.onclose(error)
24
24
 
@@ -69,7 +69,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
69
69
  while (authed && lastSentSI+1 < messageQueue.length) {
70
70
  lastSynchronousScopePatched = null
71
71
  try {
72
- connection.send(JSON.stringify(messageQueue[lastSentSI + 1]))
72
+ connection.send(messageQueue[lastSentSI + 1])
73
73
  lastSentSI += 1
74
74
  // async so we don't try and push more to a closed connection
75
75
  await new Promise(r=>r())
@@ -121,7 +121,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
121
121
  if (!sessionMetrics.connected) sessionMetrics.connected = Date.now()
122
122
  log('AUTHORIZING NEWLY OPENED CONNECTION FOR SESSION:', session)
123
123
  failedConnections = 0
124
- connection.send(JSON.stringify({ token: await token(), session }))
124
+ connection.send({ token: await token(), session })
125
125
  }
126
126
 
127
127
  connection.onmessage = async data => {
@@ -167,7 +167,7 @@ export default function messageQueue({ token, Connection, watchers, states, appl
167
167
  .forEach(([res, rej]) => message.error ? rej(message) : res(message))
168
168
 
169
169
  delete responses[message.si]
170
- connection.send(JSON.stringify({ack: message.si})) // acknowledgement that we have received the response for this message
170
+ connection.send({ack: message.si}) // acknowledgement that we have received the response for this message
171
171
  resolveSyncPromises()
172
172
  }
173
173
  else {
package/deno.js CHANGED
@@ -1,11 +1,7 @@
1
1
  import fastJSONPatch from 'fast-json-patch'
2
2
  import Agent from './agents/generic/index.js'
3
3
 
4
- const environment = Deno.env.toObject()
5
-
6
- console.log('Deno ENV VARS', environment)
7
-
8
- const AGENT_TOKEN_ENV_VAR = Object.keys(environment).find(name => name.startsWith('AGENT_TOKEN'))
4
+ const AGENT_TOKEN = Deno.env.get('AGENT_TOKEN')
9
5
 
10
6
  const denoProcess = self
11
7
 
@@ -16,6 +12,7 @@ function Connection() {
16
12
 
17
13
  const delay = new Promise(r => setTimeout(r))
18
14
  delay.then(() => thisConnection.onopen())
15
+ denoProcess.onmessage = ({ data }) => thisConnection.onmessage(data)
19
16
 
20
17
  // TODO: consider what onclose and onerror mean in this case
21
18
  return thisConnection
@@ -23,7 +20,7 @@ function Connection() {
23
20
 
24
21
  export default new Agent({
25
22
  Connection,
26
- token: () => environment[AGENT_TOKEN_ENV_VAR],
23
+ token: () => AGENT_TOKEN,
27
24
  uuid: () => crypto.randomUUID(),
28
25
  fetch,
29
26
  applyPatch: fastJSONPatch.applyPatch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.80",
3
+ "version": "0.9.83",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",