@knowlearning/agents 0.9.95 → 0.9.97
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/agents/generic/index.js +3 -3
- package/agents/generic/message-queue.js +0 -3
- package/deno.js +5 -0
- package/node.js +18 -2
- package/package.json +1 -1
- package/agents/node.js +0 -18
package/agents/generic/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const POSTGRES_QUERY_TYPE = 'application/json;type=postgres-query'
|
|
|
13
13
|
const TAG_TYPE = 'application/json;type=tag'
|
|
14
14
|
const DOMAIN_CLAIM_TYPE = 'application/json;type=domain-claim'
|
|
15
15
|
|
|
16
|
-
export default function Agent({ Connection, domain, token, uuid, fetch, applyPatch, login, logout, reboot, handleDomainMessage }) {
|
|
16
|
+
export default function Agent({ Connection, domain, token, uuid, fetch, applyPatch, login, logout, reboot, handleDomainMessage, log:passedLog=console.log }) {
|
|
17
17
|
const states = {}
|
|
18
18
|
const watchers = {}
|
|
19
19
|
const keyToSubscriptionId = {}
|
|
@@ -34,7 +34,7 @@ export default function Agent({ Connection, domain, token, uuid, fetch, applyPat
|
|
|
34
34
|
// initialize session
|
|
35
35
|
environment()
|
|
36
36
|
.then(({ session }) => {
|
|
37
|
-
interact('sessions', [{ op: 'add', path: [session], value: { queries: {}, subscriptions: {} } }], false, false)
|
|
37
|
+
interact('sessions', [{ op: 'add', path: ['active', session], value: { queries: {}, subscriptions: {} } }], false, false)
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
const internalReferences = {
|
|
@@ -61,7 +61,7 @@ export default function Agent({ Connection, domain, token, uuid, fetch, applyPat
|
|
|
61
61
|
|
|
62
62
|
function debug() { mode = 'debug' }
|
|
63
63
|
|
|
64
|
-
function log() { if (mode === 'debug')
|
|
64
|
+
function log() { if (mode === 'debug') passedLog(...arguments) }
|
|
65
65
|
|
|
66
66
|
function create({ id=uuid(), active_type, active, name }) {
|
|
67
67
|
if (!active_type) active_type = 'application/json'
|
|
@@ -130,9 +130,6 @@ export default function messageQueue({ token, domain, Connection, watchers, stat
|
|
|
130
130
|
if (!message) return // heartbeat
|
|
131
131
|
|
|
132
132
|
try {
|
|
133
|
-
log('handling message', disconnected, authed)
|
|
134
|
-
log('message', JSON.stringify(message))
|
|
135
|
-
|
|
136
133
|
if (message.error) console.warn('ERROR RESPONSE', message)
|
|
137
134
|
|
|
138
135
|
if (!authed) {
|
package/deno.js
CHANGED
|
@@ -25,6 +25,11 @@ const agent = new Agent({
|
|
|
25
25
|
Connection,
|
|
26
26
|
token: () => AGENT_TOKEN,
|
|
27
27
|
uuid: () => crypto.randomUUID(),
|
|
28
|
+
async log() {
|
|
29
|
+
const { session } = await agent.environment()
|
|
30
|
+
const value = structuredClone([...arguments])
|
|
31
|
+
agent.interact('sessions', [{ op: 'add', path: ['active', session, 'log'], value }], false, false)
|
|
32
|
+
},
|
|
28
33
|
fetch,
|
|
29
34
|
applyPatch: fastJSONPatch.applyPatch,
|
|
30
35
|
reboot: () => Deno.exit(1),
|
package/node.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import WebSocket from 'ws'
|
|
3
|
+
import { v1 as uuid } from 'uuid'
|
|
4
|
+
import fastJSONPatch from 'fast-json-patch'
|
|
5
|
+
import fetch from 'node-fetch'
|
|
6
|
+
import Agent from './agents/generic/index.js'
|
|
7
|
+
|
|
8
|
+
const { SERVE_HOST, SERVICE_ACCOUNT_TOKEN } = process.env
|
|
9
|
+
|
|
10
|
+
export default new Agent({
|
|
11
|
+
host: SERVE_HOST,
|
|
12
|
+
token: () => fs.promises.readFile(SERVICE_ACCOUNT_TOKEN).then(f => f.toString()),
|
|
13
|
+
WebSocket,
|
|
14
|
+
uuid,
|
|
15
|
+
fetch,
|
|
16
|
+
applyPatch: fastJSONPatch.applyPatch,
|
|
17
|
+
reboot: () => process.exit(1)
|
|
18
|
+
})
|
package/package.json
CHANGED
package/agents/node.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import WebSocket from 'ws'
|
|
3
|
-
import { v1 as uuid } from 'uuid'
|
|
4
|
-
import fastJSONPatch from 'fast-json-patch'
|
|
5
|
-
import fetch from 'node-fetch'
|
|
6
|
-
import Agent from './generic/index.js'
|
|
7
|
-
|
|
8
|
-
const { SERVE_HOST, SERVICE_ACCOUNT_TOKEN } = process.env
|
|
9
|
-
|
|
10
|
-
export default () => new Agent({
|
|
11
|
-
host: SERVE_HOST,
|
|
12
|
-
token: () => fs.promises.readFile(SERVICE_ACCOUNT_TOKEN).then(f => f.toString()),
|
|
13
|
-
WebSocket,
|
|
14
|
-
uuid,
|
|
15
|
-
fetch,
|
|
16
|
-
applyPatch: fastJSONPatch.applyPatch,
|
|
17
|
-
reboot: () => process.exit(1)
|
|
18
|
-
})
|