@knowlearning/agents 0.9.51 → 0.9.52

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.
@@ -48,7 +48,7 @@ function embed(environment, iframe) {
48
48
  const handleMessage = async message => {
49
49
  const { requestId, type } = message
50
50
 
51
- const sendDown = response => postMessage({ requestId, response })
51
+ const sendDown = (response, error) => postMessage({ requestId, response, error })
52
52
 
53
53
  if (type === 'error') {
54
54
  console.error(message)
@@ -100,7 +100,10 @@ function embed(environment, iframe) {
100
100
  }
101
101
  else if (type === 'query') {
102
102
  const { query, params, domain } = message
103
- sendDown(await Agent.query(query, params, domain))
103
+ Agent
104
+ .query(query, params, domain)
105
+ .then(sendDown)
106
+ .catch(error => sendDown(null, error.error))
104
107
  }
105
108
  else if (type === 'upload') {
106
109
  const { name, contentType, id } = message
@@ -185,19 +185,26 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
185
185
  value: { query, params, domain }
186
186
  }
187
187
  ])
188
- const { rows } = await lastMessageResponse()
189
- interact('sessions', [
190
- {
191
- op: 'add',
192
- path: ['active', session, 'queries', id, 'agent_latency'],
193
- value: Date.now() - requested
194
- },
195
- {
196
- op: 'remove',
197
- path: ['active', session, 'queries', id]
198
- }
199
- ])
200
- return rows
188
+ try {
189
+ const response = await lastMessageResponse()
190
+ const { rows } = response
191
+
192
+ interact('sessions', [
193
+ {
194
+ op: 'add',
195
+ path: ['active', session, 'queries', id, 'agent_latency'],
196
+ value: Date.now() - requested
197
+ },
198
+ {
199
+ op: 'remove',
200
+ path: ['active', session, 'queries', id]
201
+ }
202
+ ])
203
+ return rows
204
+ }
205
+ catch (error) {
206
+ throw error
207
+ }
201
208
  }
202
209
 
203
210
  function tag(tag_type, target, context=[]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.51",
3
+ "version": "0.9.52",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",