@knowlearning/agents 0.9.52 → 0.9.53

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.
@@ -58,13 +58,16 @@ export default function EmbeddedAgent() {
58
58
  sentUpdates[key] = data.ii
59
59
  watchers[key].forEach(fn => fn(data))
60
60
  }
61
-
62
61
  if (watchers[key]) {
63
- if (sentUpdates[key] === undefined || sentUpdates[key] + 1 === data.ii) sendUpdate()
64
- else if (data.ii === sentUpdates[key]) console.warn('Repeated update for', key, data, sentUpdates[key])
65
- else {
66
- console.warn('Out of order update for', key, data, sentUpdates[key])
67
- if (data.ii > sentUpdates[key]) sendUpdate()
62
+ if (sentUpdates[key] === undefined || sentUpdates[key] + 1 === data.ii) {
63
+ sendUpdate()
64
+ } else if (data.ii === sentUpdates[key]) {
65
+ console.warn('Repeated update for', key, data, sentUpdates[key])
66
+ } else if (data.ii < sentUpdates[key]) {
67
+ console.warn('Out of order update, from past', key, JSON.stringify(data, null, 4), sentUpdates[key])
68
+ } else {
69
+ console.warn('Out of order update, fast forward', key, JSON.stringify(data, null, 4), sentUpdates[key])
70
+ sendUpdate()
68
71
  }
69
72
  }
70
73
  }
@@ -34,7 +34,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
34
34
  // initialize session
35
35
  environment()
36
36
  .then(({ session }) => {
37
- interact('sessions', [{ op: 'add', path: [session], value: { queries: {}, subscriptions: {} } }])
37
+ interact('sessions', [{ op: 'add', path: [session], value: { queries: {}, subscriptions: {} } }], false, false)
38
38
  })
39
39
 
40
40
  const internalReferences = {
@@ -109,14 +109,14 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
109
109
  }
110
110
 
111
111
  // TODO: addTag option should probably not be exposed
112
- async function interact(scope=DEFAULT_SCOPE_NAME, patch, addTag=true) {
112
+ async function interact(scope=DEFAULT_SCOPE_NAME, patch, addTag=true, manageLocalState=true) {
113
113
  if (addTag) tagIfNotYetTaggedInSession('mutated', scope)
114
114
  // TODO: ensure user is owner of scope
115
115
  const response = queueMessage({scope, patch})
116
116
 
117
117
  // if we are watching this scope, we want to keep track of last interaction we fired
118
118
  const qualifiedScope = isUUID(scope) ? scope : `//${scope}`
119
- if (states[qualifiedScope] !== undefined) {
119
+ if (manageLocalState && states[qualifiedScope] !== undefined) {
120
120
  let resolve
121
121
  lastInteractionResponse[qualifiedScope] = new Promise(r => resolve = r)
122
122
 
@@ -184,7 +184,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
184
184
  path: ['active', session, 'queries', id],
185
185
  value: { query, params, domain }
186
186
  }
187
- ])
187
+ ], false, false)
188
188
  try {
189
189
  const response = await lastMessageResponse()
190
190
  const { rows } = response
@@ -199,7 +199,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
199
199
  op: 'remove',
200
200
  path: ['active', session, 'queries', id]
201
201
  }
202
- ])
202
+ ], false, false)
203
203
  return rows
204
204
  }
205
205
  catch (error) {
@@ -14,7 +14,7 @@ function sanitizeJSONPatchPathSegment(s) {
14
14
  else return s
15
15
  }
16
16
 
17
- export default function messageQueue({ token, protocol, host, WebSocket, watchers, states, applyPatch, log, login, interact }) {
17
+ export default function messageQueue({ token, protocol, host, WebSocket, watchers, states, applyPatch, log, login }) {
18
18
  let ws
19
19
  let user
20
20
  let authed = false
@@ -140,12 +140,7 @@ export default function messageQueue({ token, protocol, host, WebSocket, watcher
140
140
  session = message.session
141
141
  server = message.server
142
142
 
143
- // save session metrics
144
- interact(session, [
145
- {op: 'add', path: ['active', 'loaded'], value: sessionMetrics.loaded },
146
- {op: 'add', path: ['active', 'connected'], value: sessionMetrics.connected },
147
- {op: 'add', path: ['active', 'authenticated'], value: sessionMetrics.authenticated },
148
- ])
143
+ // TODO: save session metrics on session
149
144
 
150
145
  resolveEnvironment(message)
151
146
  }
@@ -19,14 +19,14 @@ export default function(scope='[]', user, domain, { keyToSubscriptionId, watcher
19
19
  op: 'add',
20
20
  path: ['active', session, 'subscriptions', id],
21
21
  value: { session, scope, user, domain, ii: null }
22
- }])
22
+ }], false, false)
23
23
  try {
24
24
  const state = await lastMessageResponse()
25
25
  interact('sessions', [{
26
26
  op: 'add',
27
27
  path: ['active', session, 'subscriptions', id, 'ii'],
28
28
  value: state.ii
29
- }])
29
+ }], false, false)
30
30
  resolve(state)
31
31
  }
32
32
  catch (error) { reject(error) }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.52",
3
+ "version": "0.9.53",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",