@knowlearning/agents 0.9.96 → 0.9.98

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.
@@ -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 = {}
@@ -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') console.log(...arguments) }
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,19 @@ 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
+ let value
31
+
32
+ try {
33
+ value = structuredClone([...arguments])
34
+ }
35
+ catch (error) {
36
+ value = `ERROR: error occurred logging arguments ${arguments}`
37
+ }
38
+
39
+ agent.interact('sessions', [{ op: 'add', path: ['active', session, 'log'], value }], false, false)
40
+ },
28
41
  fetch,
29
42
  applyPatch: fastJSONPatch.applyPatch,
30
43
  reboot: () => Deno.exit(1),
package/node.js CHANGED
@@ -1,2 +1,18 @@
1
- export { default as NodeAgent } from '../agents/node.js'
2
- export { default as GenericAgent } from '../agents/generic/index.js'
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.96",
3
+ "version": "0.9.98",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
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
- })