@knowlearning/agents 0.8.0 → 0.9.0

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.
@@ -84,7 +84,7 @@ export default function EmbeddedAgent() {
84
84
 
85
85
 
86
86
  function watch(id, fn) {
87
- tagIfNotYetTaggedInSession('connected', id)
87
+ tagIfNotYetTaggedInSession('subscribed', id)
88
88
  if (!watchers[id]) watchers[id] = []
89
89
  watchers[id].push(fn)
90
90
  return () => removeWatcher(id, fn)
@@ -96,7 +96,11 @@ export default function EmbeddedAgent() {
96
96
  }
97
97
 
98
98
  async function state(scope) {
99
- tagIfNotYetTaggedInSession('connected', scope)
99
+ if (scope === undefined) {
100
+ const { context } = await environment()
101
+ scope = JSON.stringify(context)
102
+ }
103
+ tagIfNotYetTaggedInSession('subscribed', scope)
100
104
  const startState = await send({ type: 'state', scope })
101
105
  return new MutableProxy(startState, patch => {
102
106
  const activePatch = structuredClone(patch)
@@ -202,6 +206,7 @@ export default function EmbeddedAgent() {
202
206
  function disconnect() { return send({ type: 'disconnect' }) }
203
207
  function reconnect() { return send({ type: 'reconnect' }) }
204
208
  function synced() { return send({ type: 'synced' }) }
209
+ function close() { return send({ type: 'close' }) }
205
210
 
206
211
  return {
207
212
  embedded: true,
@@ -221,6 +226,7 @@ export default function EmbeddedAgent() {
221
226
  disconnect,
222
227
  reconnect,
223
228
  synced,
229
+ close,
224
230
  tag
225
231
  }
226
232
  }
@@ -54,6 +54,7 @@ function embed(environment, iframe) {
54
54
  sendDown({})
55
55
  }
56
56
  else if (type === 'close') {
57
+ console.log('closing?', listeners)
57
58
  if (listeners.close) listeners.close()
58
59
  }
59
60
  else if (type === 'environment') {
@@ -24,9 +24,6 @@ export default () => {
24
24
  reboot: () => window.location.reload()
25
25
  })
26
26
 
27
- const { state } = agent
28
- // TODO: remove agent.state proxy here as part of "get rid of default scope" work
29
- agent.state = (scope=host,user,domain) => state(scope, user, domain)
30
27
  agent.local = () => {
31
28
  if (isLocal()) return
32
29
 
@@ -39,6 +36,9 @@ export default () => {
39
36
  localStorage.removeItem('api')
40
37
  location.reload()
41
38
  }
39
+ agent.close = () => {
40
+ window.close()
41
+ }
42
42
 
43
43
  return agent
44
44
  }
package/agents/generic.js CHANGED
@@ -210,7 +210,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
210
210
  checkHeartbeat()
211
211
  }
212
212
 
213
- function create({ id=uuid(), active_type, active }) {
213
+ function create({ id=uuid(), active_type, active, name }) {
214
214
  // TODO: collapse into 1 patch and 1 interact call
215
215
  interact(id, [{ op: 'add', path: ['active_type'], value: active_type }], false)
216
216
  interact(id, [{ op: 'add', path: ['active'], value: active }], false)
@@ -234,8 +234,8 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
234
234
  return { ...(await environmentPromise), context: [] }
235
235
  }
236
236
 
237
- function state(scope) {
238
- tagIfNotYetTaggedInSession('connected', scope)
237
+ function state(scope='[]') {
238
+ tagIfNotYetTaggedInSession('subscribed', scope)
239
239
  return new Promise(async (resolveState, rejectState) => {
240
240
  if (!keyToSubscriptionId[scope]) {
241
241
  const id = uuid()
package/browser.js CHANGED
@@ -1,5 +1,2 @@
1
1
  export { default as GenericAgent } from './agents/generic.js'
2
2
  export { default as browserAgent } from './agents/browser/initialize.js'
3
- export { default as vuePersistentStore } from './persistence/vuex.js'
4
- export { default as vueContentComponent } from './vue/3/content.vue'
5
- export { default as vuePersistentComponent } from './vue/3/component.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -14,14 +14,14 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/knowlearning/core.git"
17
+ "url": "git+https://github.com/knowlearning/platform.git"
18
18
  },
19
19
  "author": "KnowLearning",
20
20
  "license": "MPL-2.0",
21
21
  "bugs": {
22
- "url": "https://github.com/knowlearning/core/issues"
22
+ "url": "https://github.com/knowlearning/platform/issues"
23
23
  },
24
- "homepage": "https://github.com/knowlearning/core#readme",
24
+ "homepage": "https://github.com/knowlearning/platform#readme",
25
25
  "dependencies": {
26
26
  "fast-json-patch": "^3.1.1",
27
27
  "uuid": "^8.3.2",
package/vue/3/content.vue CHANGED
@@ -26,6 +26,7 @@ export default {
26
26
  this.embedding = Agent.embed({ id }, iframe)
27
27
  this.embedding.on('state', e => this.$emit('state', e))
28
28
  this.embedding.on('mutate', e => this.$emit('mutate', e))
29
+ this.embedding.on('close', e => this.$emit('close', e))
29
30
 
30
31
  /*
31
32
  const { handle } = this.embedding
package/vue/3/name.vue ADDED
@@ -0,0 +1,45 @@
1
+ <template>
2
+ <span
3
+ draggable="true"
4
+ @dragstart="handleDragStart"
5
+ >
6
+ {{ loading ? '...' : name }}
7
+ </span>
8
+ </template>
9
+
10
+ <script>
11
+ export default {
12
+ props: {
13
+ id: String
14
+ },
15
+ data() {
16
+ return {
17
+ loading: true,
18
+ metadata: null
19
+ }
20
+ },
21
+ async created() {
22
+ this.metadata = await Agent.metadata(this.id)
23
+ this.loading = false
24
+ },
25
+ computed: {
26
+ name() {
27
+ if (this.loading) return
28
+ else return this.metadata && this.metadata.name ? this.metadata.name : 'unnamed'
29
+ }
30
+ },
31
+ methods: {
32
+ handleDragStart(e) {
33
+ e.dataTransfer.effectAllowed = 'move';
34
+ e.dataTransfer.setData('text/plain', this.id);
35
+ }
36
+ }
37
+ }
38
+ </script>
39
+
40
+ <style>
41
+ span
42
+ {
43
+ cursor: grab;
44
+ }
45
+ </style>
package/vue.js ADDED
@@ -0,0 +1,4 @@
1
+ export { default as vuePersistentStore } from './persistence/vuex.js'
2
+ export { default as vueEmbedComponent } from './vue/3/content.vue'
3
+ export { default as vueNameComponent } from './vue/3/name.vue'
4
+ export { default as vuePersistentComponent } from './vue/3/component.js'