@knowlearning/agents 0.9.113 → 0.9.114
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.
- package/deno.js +7 -6
- package/package.json +1 -1
package/deno.js
CHANGED
|
@@ -7,18 +7,18 @@ const denoProcess = self
|
|
|
7
7
|
|
|
8
8
|
function Connection(domain) {
|
|
9
9
|
const connection = crypto.randomUUID()
|
|
10
|
-
const
|
|
10
|
+
const thisConnection = this
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
thisConnection.send = message => denoProcess.postMessage({ ...message, domain, connection })
|
|
13
13
|
|
|
14
14
|
denoProcess.addEventListener('message', ({ data }) => {
|
|
15
|
-
if (data.connection === connection)
|
|
15
|
+
if (data.connection === connection) thisConnection.onmessage(data)
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
// TODO: consider what onclose and onerror mean
|
|
19
|
-
setTimeout(() =>
|
|
19
|
+
setTimeout(() => thisConnection.onopen())
|
|
20
20
|
|
|
21
|
-
return
|
|
21
|
+
return thisConnection
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const children = {}
|
|
@@ -30,7 +30,8 @@ function getAgent(domain, forceNew) {
|
|
|
30
30
|
if (agents[domain] && !forceNew) return agents[domain]
|
|
31
31
|
|
|
32
32
|
agents[domain] = new Agent({
|
|
33
|
-
Connection: Connection(domain),
|
|
33
|
+
Connection: Connection(domain), // TODO: probably don't want to need to pass domain here, as first message from generic agent should pass it
|
|
34
|
+
domain,
|
|
34
35
|
token: () => AGENT_TOKEN,
|
|
35
36
|
uuid: () => crypto.randomUUID(),
|
|
36
37
|
async log() {
|