@knowlearning/agents 0.9.163 → 0.9.165

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.
@@ -221,7 +221,7 @@ export default function EmbeddedAgent() {
221
221
  return send({ type: 'login', provider, username, password })
222
222
  }
223
223
 
224
- function query(query, params, domain) { return send({ type: 'query', query, params, domain }) }
224
+ function query(query, params, domain, context=[]) { return send({ type: 'query', query, params, domain, context }) }
225
225
  function logout() { return send({ type: 'logout' }) }
226
226
  function disconnect() { return send({ type: 'disconnect' }) }
227
227
  function reconnect() { return send({ type: 'reconnect' }) }
@@ -135,9 +135,9 @@ function embed(environment, iframe) {
135
135
  sendDown(await Agent.patch(root, scopes))
136
136
  }
137
137
  else if (type === 'query') {
138
- const { query, params, domain } = message
138
+ const { query, params, domain, context=[] } = message
139
139
  Agent
140
- .query(query, params, domain)
140
+ .query(query, params, domain, [environment.id, ...context])
141
141
  .then(sendDown)
142
142
  .catch(error => sendDown(null, error.error))
143
143
  }
@@ -4,21 +4,17 @@ import { getToken, login, logout } from './auth.js'
4
4
  import GenericAgent from '../generic/index.js'
5
5
 
6
6
  const TEST_DOMAIN = 'tests.knowlearning.systems'
7
- const SECURE = window.location.protocol === 'https:'
8
- const DEVELOPMENT_HOST = `localhost:3200${ SECURE ? '1' : '2' }`
9
- const ENVIRONMENT_API_HOST = localStorage.getItem('API_HOST')
10
- const REMOTE_HOST = window.location.hostname === TEST_DOMAIN && ENVIRONMENT_API_HOST ? ENVIRONMENT_API_HOST : 'api.knowlearning.systems'
11
7
  const LANGUAGES = [...navigator.languages]
12
8
 
13
- function isLocal() { return localStorage.getItem('api') === 'local' }
14
-
15
- const API_HOST = isLocal() ? DEVELOPMENT_HOST : REMOTE_HOST
9
+ //const API_HOST = localStorage.getItem('API_HOST') || 'api.knowlearning.systems'
10
+ // const API_HOST = 'api-test.knowlearning.systems'
11
+ const API_HOST = 'localhost:8765'
16
12
 
17
13
  // TODO: remove this hack when we can set partitioned sid cookie through websocket handshake
18
14
  // deno is partly in the way on teh set side, and browser support is in the way for
19
15
  // the client side.
20
16
  async function ensureSidEstablished() {
21
- const response = await fetch(`http${ SECURE ? 's' : '' }://${API_HOST}/_sid-check`, { method: 'GET', credentials: 'include' })
17
+ const response = await fetch(`https://${API_HOST}/_sid-check`, { method: 'GET', credentials: 'include' })
22
18
  const hasLocalStorageSID = !!localStorage.getItem('sid')
23
19
  if (response.status === 201) {
24
20
  if (!hasLocalStorageSID) {
@@ -43,7 +39,7 @@ export default options => {
43
39
  ensureSidEstablished()
44
40
  const Connection = function () {
45
41
 
46
- const ws = new WebSocket(`ws${ SECURE ? 's' : '' }://${API_HOST}`)
42
+ const ws = new WebSocket(`wss://${API_HOST}`)
47
43
 
48
44
  this.send = message => ws.send(JSON.stringify(message))
49
45
  this.close = info => {
@@ -163,7 +163,7 @@ export default function Agent({ Connection, domain, token, sid, uuid, fetch, app
163
163
  })
164
164
  }
165
165
 
166
- async function query(query, params, domain) {
166
+ async function query(query, params, domain, context=[]) {
167
167
  const id = uuid()
168
168
  const requested = Date.now()
169
169
  const { session } = await environment()
@@ -172,7 +172,7 @@ export default function Agent({ Connection, domain, token, sid, uuid, fetch, app
172
172
  {
173
173
  op: 'add',
174
174
  path: ['active', session, 'queries', id],
175
- value: { query, params, domain }
175
+ value: { query, params, domain, context }
176
176
  }
177
177
  ], false, false)
178
178
  try {
package/deno.js CHANGED
@@ -3,7 +3,7 @@ import Agent from './agents/generic/index.js'
3
3
 
4
4
  const AGENT_TOKEN = Deno.env.get('AGENT_TOKEN')
5
5
 
6
- const denoProcess = self
6
+ const denoProcess = globalThis
7
7
 
8
8
  denoProcess.addEventListener('message', ({ data }) => {
9
9
  if (!data) denoProcess.postMessage(undefined) // ping response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.163",
3
+ "version": "0.9.165",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",