@knowlearning/agents 0.9.118 → 0.9.120

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.
Files changed (2) hide show
  1. package/deno.js +13 -13
  2. package/package.json +1 -1
package/deno.js CHANGED
@@ -5,19 +5,21 @@ const AGENT_TOKEN = Deno.env.get('AGENT_TOKEN')
5
5
 
6
6
  const denoProcess = self
7
7
 
8
- function Connection(domain) {
9
- const connection = crypto.randomUUID()
8
+ class Connection {
9
+ constructor(domain) {
10
+ const connection = crypto.randomUUID();
10
11
 
11
- this.send = message => denoProcess.postMessage({ ...message, domain, connection })
12
+ this.send = message => denoProcess.postMessage({ ...message, domain, connection });
12
13
 
13
- denoProcess.addEventListener('message', ({ data }) => {
14
- if (data.connection === connection) this.onmessage(data)
15
- })
14
+ denoProcess.addEventListener('message', ({ data }) => {
15
+ if (data.connection === connection) this.onmessage(data);
16
+ });
16
17
 
17
- // TODO: consider what onclose and onerror mean
18
- setTimeout(() => this.onopen())
18
+ // TODO: consider what onclose and onerror mean
19
+ setTimeout(() => this.onopen());
19
20
 
20
- return this
21
+ return this;
22
+ }
21
23
  }
22
24
 
23
25
  const children = {}
@@ -28,15 +30,13 @@ const agents = {}
28
30
  function getAgent(domain, forceNew) {
29
31
  if (agents[domain] && !forceNew) return agents[domain]
30
32
 
31
- let agent
32
-
33
- agent = new Agent({
33
+ const agent = new Agent({
34
34
  Connection: new Connection(domain), // TODO: probably don't want to need to pass domain here, as first message from generic agent should pass it
35
35
  domain,
36
36
  token: () => AGENT_TOKEN,
37
37
  uuid: () => crypto.randomUUID(),
38
38
  async log() {
39
- await new Promise(r => r()) // so we can access our own agent instance
39
+ await new Promise(r => setTimeout(r)) // so we can access our own agent instance
40
40
 
41
41
  const { session } = await agent.environment()
42
42
  let value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.118",
3
+ "version": "0.9.120",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",