@knowlearning/agents 0.9.171 → 0.9.173

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.
package/dist/browser.js CHANGED
@@ -1,59 +1,59 @@
1
- var fe, Ye = new Uint8Array(16);
2
- function be() {
3
- if (!fe && (fe = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto), !fe))
1
+ var ie, je = new Uint8Array(16);
2
+ function Ue() {
3
+ if (!ie && (ie = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto), !ie))
4
4
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
5
- return fe(Ye);
5
+ return ie(je);
6
6
  }
7
- const ze = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
8
- function Q(e) {
9
- return typeof e == "string" && ze.test(e);
7
+ const Be = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
8
+ function k(e) {
9
+ return typeof e == "string" && Be.test(e);
10
10
  }
11
11
  var j = [];
12
- for (var ye = 0; ye < 256; ++ye)
13
- j.push((ye + 256).toString(16).substr(1));
14
- function xe(e) {
12
+ for (var he = 0; he < 256; ++he)
13
+ j.push((he + 256).toString(16).substr(1));
14
+ function Me(e) {
15
15
  var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, r = (j[e[t + 0]] + j[e[t + 1]] + j[e[t + 2]] + j[e[t + 3]] + "-" + j[e[t + 4]] + j[e[t + 5]] + "-" + j[e[t + 6]] + j[e[t + 7]] + "-" + j[e[t + 8]] + j[e[t + 9]] + "-" + j[e[t + 10]] + j[e[t + 11]] + j[e[t + 12]] + j[e[t + 13]] + j[e[t + 14]] + j[e[t + 15]]).toLowerCase();
16
- if (!Q(r))
16
+ if (!k(r))
17
17
  throw TypeError("Stringified UUID is invalid");
18
18
  return r;
19
19
  }
20
- var De, me, Ee = 0, Ae = 0;
21
- function ie(e, t, r) {
20
+ var Pe, ve, ye = 0, me = 0;
21
+ function ne(e, t, r) {
22
22
  var n = t && r || 0, o = t || new Array(16);
23
23
  e = e || {};
24
- var i = e.node || De, c = e.clockseq !== void 0 ? e.clockseq : me;
25
- if (i == null || c == null) {
26
- var d = e.random || (e.rng || be)();
27
- i == null && (i = De = [d[0] | 1, d[1], d[2], d[3], d[4], d[5]]), c == null && (c = me = (d[6] << 8 | d[7]) & 16383);
24
+ var s = e.node || Pe, c = e.clockseq !== void 0 ? e.clockseq : ve;
25
+ if (s == null || c == null) {
26
+ var d = e.random || (e.rng || Ue)();
27
+ s == null && (s = Pe = [d[0] | 1, d[1], d[2], d[3], d[4], d[5]]), c == null && (c = ve = (d[6] << 8 | d[7]) & 16383);
28
28
  }
29
- var p = e.msecs !== void 0 ? e.msecs : Date.now(), l = e.nsecs !== void 0 ? e.nsecs : Ae + 1, a = p - Ee + (l - Ae) / 1e4;
30
- if (a < 0 && e.clockseq === void 0 && (c = c + 1 & 16383), (a < 0 || p > Ee) && e.nsecs === void 0 && (l = 0), l >= 1e4)
29
+ var w = e.msecs !== void 0 ? e.msecs : Date.now(), u = e.nsecs !== void 0 ? e.nsecs : me + 1, i = w - ye + (u - me) / 1e4;
30
+ if (i < 0 && e.clockseq === void 0 && (c = c + 1 & 16383), (i < 0 || w > ye) && e.nsecs === void 0 && (u = 0), u >= 1e4)
31
31
  throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
32
- Ee = p, Ae = l, me = c, p += 122192928e5;
33
- var s = ((p & 268435455) * 1e4 + l) % 4294967296;
34
- o[n++] = s >>> 24 & 255, o[n++] = s >>> 16 & 255, o[n++] = s >>> 8 & 255, o[n++] = s & 255;
35
- var v = p / 4294967296 * 1e4 & 268435455;
36
- o[n++] = v >>> 8 & 255, o[n++] = v & 255, o[n++] = v >>> 24 & 15 | 16, o[n++] = v >>> 16 & 255, o[n++] = c >>> 8 | 128, o[n++] = c & 255;
37
- for (var u = 0; u < 6; ++u)
38
- o[n + u] = i[u];
39
- return t || xe(o);
32
+ ye = w, me = u, ve = c, w += 122192928e5;
33
+ var a = ((w & 268435455) * 1e4 + u) % 4294967296;
34
+ o[n++] = a >>> 24 & 255, o[n++] = a >>> 16 & 255, o[n++] = a >>> 8 & 255, o[n++] = a & 255;
35
+ var h = w / 4294967296 * 1e4 & 268435455;
36
+ o[n++] = h >>> 8 & 255, o[n++] = h & 255, o[n++] = h >>> 24 & 15 | 16, o[n++] = h >>> 16 & 255, o[n++] = c >>> 8 | 128, o[n++] = c & 255;
37
+ for (var l = 0; l < 6; ++l)
38
+ o[n + l] = s[l];
39
+ return t || Me(o);
40
40
  }
41
- function Qe(e, t, r) {
41
+ function Fe(e, t, r) {
42
42
  e = e || {};
43
- var n = e.random || (e.rng || be)();
44
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, xe(n);
43
+ var n = e.random || (e.rng || Ue)();
44
+ return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Me(n);
45
45
  }
46
46
  /*!
47
47
  * https://github.com/Starcounter-Jack/JSON-Patch
48
48
  * (c) 2017-2022 Joachim Wester
49
49
  * MIT licensed
50
50
  */
51
- var Ke = /* @__PURE__ */ function() {
51
+ var ze = /* @__PURE__ */ function() {
52
52
  var e = function(t, r) {
53
53
  return e = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, o) {
54
54
  n.__proto__ = o;
55
55
  } || function(n, o) {
56
- for (var i in o) o.hasOwnProperty(i) && (n[i] = o[i]);
56
+ for (var s in o) o.hasOwnProperty(s) && (n[s] = o[s]);
57
57
  }, e(t, r);
58
58
  };
59
59
  return function(t, r) {
@@ -63,11 +63,11 @@ var Ke = /* @__PURE__ */ function() {
63
63
  }
64
64
  t.prototype = r === null ? Object.create(r) : (n.prototype = r.prototype, new n());
65
65
  };
66
- }(), We = Object.prototype.hasOwnProperty;
67
- function Ie(e, t) {
68
- return We.call(e, t);
66
+ }(), Qe = Object.prototype.hasOwnProperty;
67
+ function ge(e, t) {
68
+ return Qe.call(e, t);
69
69
  }
70
- function Se(e) {
70
+ function Ie(e) {
71
71
  if (Array.isArray(e)) {
72
72
  for (var t = new Array(e.length), r = 0; r < t.length; r++)
73
73
  t[r] = "" + r;
@@ -77,10 +77,10 @@ function Se(e) {
77
77
  return Object.keys(e);
78
78
  var n = [];
79
79
  for (var o in e)
80
- Ie(e, o) && n.push(o);
80
+ ge(e, o) && n.push(o);
81
81
  return n;
82
82
  }
83
- function Y(e) {
83
+ function F(e) {
84
84
  switch (typeof e) {
85
85
  case "object":
86
86
  return JSON.parse(JSON.stringify(e));
@@ -92,7 +92,7 @@ function Y(e) {
92
92
  return e;
93
93
  }
94
94
  }
95
- function Ne(e) {
95
+ function Te(e) {
96
96
  for (var t = 0, r = e.length, n; t < r; ) {
97
97
  if (n = e.charCodeAt(t), n >= 48 && n <= 57) {
98
98
  t++;
@@ -102,29 +102,29 @@ function Ne(e) {
102
102
  }
103
103
  return !0;
104
104
  }
105
- function re(e) {
105
+ function ee(e) {
106
106
  return e.indexOf("/") === -1 && e.indexOf("~") === -1 ? e : e.replace(/~/g, "~0").replace(/\//g, "~1");
107
107
  }
108
- function $e(e) {
108
+ function be(e) {
109
109
  return e.replace(/~1/g, "/").replace(/~0/g, "~");
110
110
  }
111
- function _e(e) {
111
+ function Se(e) {
112
112
  if (e === void 0)
113
113
  return !0;
114
114
  if (e) {
115
115
  if (Array.isArray(e)) {
116
116
  for (var t = 0, r = e.length; t < r; t++)
117
- if (_e(e[t]))
117
+ if (Se(e[t]))
118
118
  return !0;
119
119
  } else if (typeof e == "object") {
120
- for (var n = Se(e), o = n.length, i = 0; i < o; i++)
121
- if (_e(e[n[i]]))
120
+ for (var n = Ie(e), o = n.length, s = 0; s < o; s++)
121
+ if (Se(e[n[s]]))
122
122
  return !0;
123
123
  }
124
124
  }
125
125
  return !1;
126
126
  }
127
- function Le(e, t) {
127
+ function Ce(e, t) {
128
128
  var r = [e];
129
129
  for (var n in t) {
130
130
  var o = typeof t[n] == "object" ? JSON.stringify(t[n], null, 2) : t[n];
@@ -133,17 +133,17 @@ function Le(e, t) {
133
133
  return r.join(`
134
134
  `);
135
135
  }
136
- var qe = (
136
+ var xe = (
137
137
  /** @class */
138
138
  function(e) {
139
- Ke(t, e);
140
- function t(r, n, o, i, c) {
141
- var d = this.constructor, p = e.call(this, Le(r, { name: n, index: o, operation: i, tree: c })) || this;
142
- return p.name = n, p.index = o, p.operation = i, p.tree = c, Object.setPrototypeOf(p, d.prototype), p.message = Le(r, { name: n, index: o, operation: i, tree: c }), p;
139
+ ze(t, e);
140
+ function t(r, n, o, s, c) {
141
+ var d = this.constructor, w = e.call(this, Ce(r, { name: n, index: o, operation: s, tree: c })) || this;
142
+ return w.name = n, w.index = o, w.operation = s, w.tree = c, Object.setPrototypeOf(w, d.prototype), w.message = Ce(r, { name: n, index: o, operation: s, tree: c }), w;
143
143
  }
144
144
  return t;
145
145
  }(Error)
146
- ), M = qe, Ze = Y, se = {
146
+ ), U = xe, Ke = F, re = {
147
147
  add: function(e, t, r) {
148
148
  return e[t] = this.value, { newDocument: r };
149
149
  },
@@ -156,24 +156,24 @@ var qe = (
156
156
  return e[t] = this.value, { newDocument: r, removed: n };
157
157
  },
158
158
  move: function(e, t, r) {
159
- var n = we(r, this.path);
160
- n && (n = Y(n));
161
- var o = oe(r, { op: "remove", path: this.from }).removed;
162
- return oe(r, { op: "add", path: this.path, value: o }), { newDocument: r, removed: n };
159
+ var n = ue(r, this.path);
160
+ n && (n = F(n));
161
+ var o = te(r, { op: "remove", path: this.from }).removed;
162
+ return te(r, { op: "add", path: this.path, value: o }), { newDocument: r, removed: n };
163
163
  },
164
164
  copy: function(e, t, r) {
165
- var n = we(r, this.from);
166
- return oe(r, { op: "add", path: this.path, value: Y(n) }), { newDocument: r };
165
+ var n = ue(r, this.from);
166
+ return te(r, { op: "add", path: this.path, value: F(n) }), { newDocument: r };
167
167
  },
168
168
  test: function(e, t, r) {
169
- return { newDocument: r, test: ae(e[t], this.value) };
169
+ return { newDocument: r, test: oe(e[t], this.value) };
170
170
  },
171
171
  _get: function(e, t, r) {
172
172
  return this.value = e[t], { newDocument: r };
173
173
  }
174
- }, ke = {
174
+ }, We = {
175
175
  add: function(e, t, r) {
176
- return Ne(t) ? e.splice(t, 0, this.value) : e[t] = this.value, { newDocument: r, index: t };
176
+ return Te(t) ? e.splice(t, 0, this.value) : e[t] = this.value, { newDocument: r, index: t };
177
177
  },
178
178
  remove: function(e, t, r) {
179
179
  var n = e.splice(t, 1);
@@ -183,29 +183,29 @@ var qe = (
183
183
  var n = e[t];
184
184
  return e[t] = this.value, { newDocument: r, removed: n };
185
185
  },
186
- move: se.move,
187
- copy: se.copy,
188
- test: se.test,
189
- _get: se._get
186
+ move: re.move,
187
+ copy: re.copy,
188
+ test: re.test,
189
+ _get: re._get
190
190
  };
191
- function we(e, t) {
191
+ function ue(e, t) {
192
192
  if (t == "")
193
193
  return e;
194
194
  var r = { op: "_get", path: t };
195
- return oe(e, r), r.value;
195
+ return te(e, r), r.value;
196
196
  }
197
- function oe(e, t, r, n, o, i) {
198
- if (r === void 0 && (r = !1), n === void 0 && (n = !0), o === void 0 && (o = !0), i === void 0 && (i = 0), r && (typeof r == "function" ? r(t, 0, e, t.path) : pe(t, 0)), t.path === "") {
197
+ function te(e, t, r, n, o, s) {
198
+ if (r === void 0 && (r = !1), n === void 0 && (n = !0), o === void 0 && (o = !0), s === void 0 && (s = 0), r && (typeof r == "function" ? r(t, 0, e, t.path) : le(t, 0)), t.path === "") {
199
199
  var c = { newDocument: e };
200
200
  if (t.op === "add")
201
201
  return c.newDocument = t.value, c;
202
202
  if (t.op === "replace")
203
203
  return c.newDocument = t.value, c.removed = e, c;
204
204
  if (t.op === "move" || t.op === "copy")
205
- return c.newDocument = we(e, t.from), t.op === "move" && (c.removed = e), c;
205
+ return c.newDocument = ue(e, t.from), t.op === "move" && (c.removed = e), c;
206
206
  if (t.op === "test") {
207
- if (c.test = ae(e, t.value), c.test === !1)
208
- throw new M("Test operation failed", "TEST_OPERATION_FAILED", i, t, e);
207
+ if (c.test = oe(e, t.value), c.test === !1)
208
+ throw new U("Test operation failed", "TEST_OPERATION_FAILED", s, t, e);
209
209
  return c.newDocument = e, c;
210
210
  } else {
211
211
  if (t.op === "remove")
@@ -213,149 +213,149 @@ function oe(e, t, r, n, o, i) {
213
213
  if (t.op === "_get")
214
214
  return t.value = e, c;
215
215
  if (r)
216
- throw new M("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", i, t, e);
216
+ throw new U("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", s, t, e);
217
217
  return c;
218
218
  }
219
219
  } else {
220
- n || (e = Y(e));
221
- var d = t.path || "", p = d.split("/"), l = e, a = 1, s = p.length, v = void 0, u = void 0, g = void 0;
222
- for (typeof r == "function" ? g = r : g = pe; ; ) {
223
- if (u = p[a], u && u.indexOf("~") != -1 && (u = $e(u)), o && (u == "__proto__" || u == "prototype" && a > 0 && p[a - 1] == "constructor"))
220
+ n || (e = F(e));
221
+ var d = t.path || "", w = d.split("/"), u = e, i = 1, a = w.length, h = void 0, l = void 0, E = void 0;
222
+ for (typeof r == "function" ? E = r : E = le; ; ) {
223
+ if (l = w[i], l && l.indexOf("~") != -1 && (l = be(l)), o && (l == "__proto__" || l == "prototype" && i > 0 && w[i - 1] == "constructor"))
224
224
  throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");
225
- if (r && v === void 0 && (l[u] === void 0 ? v = p.slice(0, a).join("/") : a == s - 1 && (v = t.path), v !== void 0 && g(t, 0, e, v)), a++, Array.isArray(l)) {
226
- if (u === "-")
227
- u = l.length;
225
+ if (r && h === void 0 && (u[l] === void 0 ? h = w.slice(0, i).join("/") : i == a - 1 && (h = t.path), h !== void 0 && E(t, 0, e, h)), i++, Array.isArray(u)) {
226
+ if (l === "-")
227
+ l = u.length;
228
228
  else {
229
- if (r && !Ne(u))
230
- throw new M("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", i, t, e);
231
- Ne(u) && (u = ~~u);
229
+ if (r && !Te(l))
230
+ throw new U("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", s, t, e);
231
+ Te(l) && (l = ~~l);
232
232
  }
233
- if (a >= s) {
234
- if (r && t.op === "add" && u > l.length)
235
- throw new M("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", i, t, e);
236
- var c = ke[t.op].call(t, l, u, e);
233
+ if (i >= a) {
234
+ if (r && t.op === "add" && l > u.length)
235
+ throw new U("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", s, t, e);
236
+ var c = We[t.op].call(t, u, l, e);
237
237
  if (c.test === !1)
238
- throw new M("Test operation failed", "TEST_OPERATION_FAILED", i, t, e);
238
+ throw new U("Test operation failed", "TEST_OPERATION_FAILED", s, t, e);
239
239
  return c;
240
240
  }
241
- } else if (a >= s) {
242
- var c = se[t.op].call(t, l, u, e);
241
+ } else if (i >= a) {
242
+ var c = re[t.op].call(t, u, l, e);
243
243
  if (c.test === !1)
244
- throw new M("Test operation failed", "TEST_OPERATION_FAILED", i, t, e);
244
+ throw new U("Test operation failed", "TEST_OPERATION_FAILED", s, t, e);
245
245
  return c;
246
246
  }
247
- if (l = l[u], r && a < s && (!l || typeof l != "object"))
248
- throw new M("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", i, t, e);
247
+ if (u = u[l], r && i < a && (!u || typeof u != "object"))
248
+ throw new U("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", s, t, e);
249
249
  }
250
250
  }
251
251
  }
252
- function he(e, t, r, n, o) {
252
+ function de(e, t, r, n, o) {
253
253
  if (n === void 0 && (n = !0), o === void 0 && (o = !0), r && !Array.isArray(t))
254
- throw new M("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
255
- n || (e = Y(e));
256
- for (var i = new Array(t.length), c = 0, d = t.length; c < d; c++)
257
- i[c] = oe(e, t[c], r, !0, o, c), e = i[c].newDocument;
258
- return i.newDocument = e, i;
254
+ throw new U("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
255
+ n || (e = F(e));
256
+ for (var s = new Array(t.length), c = 0, d = t.length; c < d; c++)
257
+ s[c] = te(e, t[c], r, !0, o, c), e = s[c].newDocument;
258
+ return s.newDocument = e, s;
259
259
  }
260
- function Xe(e, t, r) {
261
- var n = oe(e, t);
260
+ function Ye(e, t, r) {
261
+ var n = te(e, t);
262
262
  if (n.test === !1)
263
- throw new M("Test operation failed", "TEST_OPERATION_FAILED", r, t, e);
263
+ throw new U("Test operation failed", "TEST_OPERATION_FAILED", r, t, e);
264
264
  return n.newDocument;
265
265
  }
266
- function pe(e, t, r, n) {
266
+ function le(e, t, r, n) {
267
267
  if (typeof e != "object" || e === null || Array.isArray(e))
268
- throw new M("Operation is not an object", "OPERATION_NOT_AN_OBJECT", t, e, r);
269
- if (se[e.op]) {
268
+ throw new U("Operation is not an object", "OPERATION_NOT_AN_OBJECT", t, e, r);
269
+ if (re[e.op]) {
270
270
  if (typeof e.path != "string")
271
- throw new M("Operation `path` property is not a string", "OPERATION_PATH_INVALID", t, e, r);
271
+ throw new U("Operation `path` property is not a string", "OPERATION_PATH_INVALID", t, e, r);
272
272
  if (e.path.indexOf("/") !== 0 && e.path.length > 0)
273
- throw new M('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", t, e, r);
273
+ throw new U('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", t, e, r);
274
274
  if ((e.op === "move" || e.op === "copy") && typeof e.from != "string")
275
- throw new M("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", t, e, r);
275
+ throw new U("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", t, e, r);
276
276
  if ((e.op === "add" || e.op === "replace" || e.op === "test") && e.value === void 0)
277
- throw new M("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", t, e, r);
278
- if ((e.op === "add" || e.op === "replace" || e.op === "test") && _e(e.value))
279
- throw new M("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", t, e, r);
277
+ throw new U("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", t, e, r);
278
+ if ((e.op === "add" || e.op === "replace" || e.op === "test") && Se(e.value))
279
+ throw new U("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", t, e, r);
280
280
  if (r) {
281
281
  if (e.op == "add") {
282
- var o = e.path.split("/").length, i = n.split("/").length;
283
- if (o !== i + 1 && o !== i)
284
- throw new M("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", t, e, r);
282
+ var o = e.path.split("/").length, s = n.split("/").length;
283
+ if (o !== s + 1 && o !== s)
284
+ throw new U("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", t, e, r);
285
285
  } else if (e.op === "replace" || e.op === "remove" || e.op === "_get") {
286
286
  if (e.path !== n)
287
- throw new M("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", t, e, r);
287
+ throw new U("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", t, e, r);
288
288
  } else if (e.op === "move" || e.op === "copy") {
289
- var c = { op: "_get", path: e.from, value: void 0 }, d = Ge([c], r);
289
+ var c = { op: "_get", path: e.from, value: void 0 }, d = $e([c], r);
290
290
  if (d && d.name === "OPERATION_PATH_UNRESOLVABLE")
291
- throw new M("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", t, e, r);
291
+ throw new U("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", t, e, r);
292
292
  }
293
293
  }
294
- } else throw new M("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", t, e, r);
294
+ } else throw new U("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", t, e, r);
295
295
  }
296
- function Ge(e, t, r) {
296
+ function $e(e, t, r) {
297
297
  try {
298
298
  if (!Array.isArray(e))
299
- throw new M("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
299
+ throw new U("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
300
300
  if (t)
301
- he(Y(t), Y(e), r || !0);
301
+ de(F(t), F(e), r || !0);
302
302
  else {
303
- r = r || pe;
303
+ r = r || le;
304
304
  for (var n = 0; n < e.length; n++)
305
305
  r(e[n], n, t, void 0);
306
306
  }
307
307
  } catch (o) {
308
- if (o instanceof M)
308
+ if (o instanceof U)
309
309
  return o;
310
310
  throw o;
311
311
  }
312
312
  }
313
- function ae(e, t) {
313
+ function oe(e, t) {
314
314
  if (e === t)
315
315
  return !0;
316
316
  if (e && t && typeof e == "object" && typeof t == "object") {
317
- var r = Array.isArray(e), n = Array.isArray(t), o, i, c;
317
+ var r = Array.isArray(e), n = Array.isArray(t), o, s, c;
318
318
  if (r && n) {
319
- if (i = e.length, i != t.length)
319
+ if (s = e.length, s != t.length)
320
320
  return !1;
321
- for (o = i; o-- !== 0; )
322
- if (!ae(e[o], t[o]))
321
+ for (o = s; o-- !== 0; )
322
+ if (!oe(e[o], t[o]))
323
323
  return !1;
324
324
  return !0;
325
325
  }
326
326
  if (r != n)
327
327
  return !1;
328
328
  var d = Object.keys(e);
329
- if (i = d.length, i !== Object.keys(t).length)
329
+ if (s = d.length, s !== Object.keys(t).length)
330
330
  return !1;
331
- for (o = i; o-- !== 0; )
331
+ for (o = s; o-- !== 0; )
332
332
  if (!t.hasOwnProperty(d[o]))
333
333
  return !1;
334
- for (o = i; o-- !== 0; )
335
- if (c = d[o], !ae(e[c], t[c]))
334
+ for (o = s; o-- !== 0; )
335
+ if (c = d[o], !oe(e[c], t[c]))
336
336
  return !1;
337
337
  return !0;
338
338
  }
339
339
  return e !== e && t !== t;
340
340
  }
341
- const Ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
341
+ const Ze = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
342
342
  __proto__: null,
343
- JsonPatchError: M,
344
- _areEquals: ae,
345
- applyOperation: oe,
346
- applyPatch: he,
347
- applyReducer: Xe,
348
- deepClone: Ze,
349
- getValueByPointer: we,
350
- validate: Ge,
351
- validator: pe
343
+ JsonPatchError: U,
344
+ _areEquals: oe,
345
+ applyOperation: te,
346
+ applyPatch: de,
347
+ applyReducer: Ye,
348
+ deepClone: Ke,
349
+ getValueByPointer: ue,
350
+ validate: $e,
351
+ validator: le
352
352
  }, Symbol.toStringTag, { value: "Module" }));
353
353
  /*!
354
354
  * https://github.com/Starcounter-Jack/JSON-Patch
355
355
  * (c) 2017-2021 Joachim Wester
356
356
  * MIT license
357
357
  */
358
- var Pe = /* @__PURE__ */ new WeakMap(), et = (
358
+ var _e = /* @__PURE__ */ new WeakMap(), ke = (
359
359
  /** @class */
360
360
  /* @__PURE__ */ function() {
361
361
  function e(t) {
@@ -363,7 +363,7 @@ var Pe = /* @__PURE__ */ new WeakMap(), et = (
363
363
  }
364
364
  return e;
365
365
  }()
366
- ), tt = (
366
+ ), Xe = (
367
367
  /** @class */
368
368
  /* @__PURE__ */ function() {
369
369
  function e(t, r) {
@@ -372,84 +372,84 @@ var Pe = /* @__PURE__ */ new WeakMap(), et = (
372
372
  return e;
373
373
  }()
374
374
  );
375
- function nt(e) {
376
- return Pe.get(e);
375
+ function Ve(e) {
376
+ return _e.get(e);
377
377
  }
378
- function rt(e, t) {
378
+ function et(e, t) {
379
379
  return e.observers.get(t);
380
380
  }
381
- function ot(e, t) {
381
+ function tt(e, t) {
382
382
  e.observers.delete(t.callback);
383
383
  }
384
- function it(e, t) {
384
+ function nt(e, t) {
385
385
  t.unobserve();
386
386
  }
387
- function st(e, t) {
388
- var r = [], n, o = nt(e);
387
+ function rt(e, t) {
388
+ var r = [], n, o = Ve(e);
389
389
  if (!o)
390
- o = new et(e), Pe.set(e, o);
390
+ o = new ke(e), _e.set(e, o);
391
391
  else {
392
- var i = rt(o, t);
393
- n = i && i.observer;
392
+ var s = et(o, t);
393
+ n = s && s.observer;
394
394
  }
395
395
  if (n)
396
396
  return n;
397
- if (n = {}, o.value = Y(e), t) {
397
+ if (n = {}, o.value = F(e), t) {
398
398
  n.callback = t, n.next = null;
399
399
  var c = function() {
400
- Re(n);
400
+ Ne(n);
401
401
  }, d = function() {
402
402
  clearTimeout(n.next), n.next = setTimeout(c);
403
403
  };
404
404
  typeof window < "u" && (window.addEventListener("mouseup", d), window.addEventListener("keyup", d), window.addEventListener("mousedown", d), window.addEventListener("keydown", d), window.addEventListener("change", d));
405
405
  }
406
406
  return n.patches = r, n.object = e, n.unobserve = function() {
407
- Re(n), clearTimeout(n.next), ot(o, n), typeof window < "u" && (window.removeEventListener("mouseup", d), window.removeEventListener("keyup", d), window.removeEventListener("mousedown", d), window.removeEventListener("keydown", d), window.removeEventListener("change", d));
408
- }, o.observers.set(t, new tt(t, n)), n;
407
+ Ne(n), clearTimeout(n.next), tt(o, n), typeof window < "u" && (window.removeEventListener("mouseup", d), window.removeEventListener("keyup", d), window.removeEventListener("mousedown", d), window.removeEventListener("keydown", d), window.removeEventListener("change", d));
408
+ }, o.observers.set(t, new Xe(t, n)), n;
409
409
  }
410
- function Re(e, t) {
410
+ function Ne(e, t) {
411
411
  t === void 0 && (t = !1);
412
- var r = Pe.get(e.object);
413
- Ce(r.value, e.object, e.patches, "", t), e.patches.length && he(r.value, e.patches);
412
+ var r = _e.get(e.object);
413
+ Re(r.value, e.object, e.patches, "", t), e.patches.length && de(r.value, e.patches);
414
414
  var n = e.patches;
415
415
  return n.length > 0 && (e.patches = [], e.callback && e.callback(n)), n;
416
416
  }
417
- function Ce(e, t, r, n, o) {
417
+ function Re(e, t, r, n, o) {
418
418
  if (t !== e) {
419
419
  typeof t.toJSON == "function" && (t = t.toJSON());
420
- for (var i = Se(t), c = Se(e), d = !1, p = c.length - 1; p >= 0; p--) {
421
- var l = c[p], a = e[l];
422
- if (Ie(t, l) && !(t[l] === void 0 && a !== void 0 && Array.isArray(t) === !1)) {
423
- var s = t[l];
424
- typeof a == "object" && a != null && typeof s == "object" && s != null && Array.isArray(a) === Array.isArray(s) ? Ce(a, s, r, n + "/" + re(l), o) : a !== s && (o && r.push({ op: "test", path: n + "/" + re(l), value: Y(a) }), r.push({ op: "replace", path: n + "/" + re(l), value: Y(s) }));
425
- } else Array.isArray(e) === Array.isArray(t) ? (o && r.push({ op: "test", path: n + "/" + re(l), value: Y(a) }), r.push({ op: "remove", path: n + "/" + re(l) }), d = !0) : (o && r.push({ op: "test", path: n, value: e }), r.push({ op: "replace", path: n, value: t }));
420
+ for (var s = Ie(t), c = Ie(e), d = !1, w = c.length - 1; w >= 0; w--) {
421
+ var u = c[w], i = e[u];
422
+ if (ge(t, u) && !(t[u] === void 0 && i !== void 0 && Array.isArray(t) === !1)) {
423
+ var a = t[u];
424
+ typeof i == "object" && i != null && typeof a == "object" && a != null && Array.isArray(i) === Array.isArray(a) ? Re(i, a, r, n + "/" + ee(u), o) : i !== a && (o && r.push({ op: "test", path: n + "/" + ee(u), value: F(i) }), r.push({ op: "replace", path: n + "/" + ee(u), value: F(a) }));
425
+ } else Array.isArray(e) === Array.isArray(t) ? (o && r.push({ op: "test", path: n + "/" + ee(u), value: F(i) }), r.push({ op: "remove", path: n + "/" + ee(u) }), d = !0) : (o && r.push({ op: "test", path: n, value: e }), r.push({ op: "replace", path: n, value: t }));
426
426
  }
427
- if (!(!d && i.length == c.length))
428
- for (var p = 0; p < i.length; p++) {
429
- var l = i[p];
430
- !Ie(e, l) && t[l] !== void 0 && r.push({ op: "add", path: n + "/" + re(l), value: Y(t[l]) });
427
+ if (!(!d && s.length == c.length))
428
+ for (var w = 0; w < s.length; w++) {
429
+ var u = s[w];
430
+ !ge(e, u) && t[u] !== void 0 && r.push({ op: "add", path: n + "/" + ee(u), value: F(t[u]) });
431
431
  }
432
432
  }
433
433
  }
434
- function at(e, t, r) {
434
+ function ot(e, t, r) {
435
435
  r === void 0 && (r = !1);
436
436
  var n = [];
437
- return Ce(e, t, n, "", r), n;
437
+ return Re(e, t, n, "", r), n;
438
438
  }
439
- const ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
439
+ const st = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
440
440
  __proto__: null,
441
- compare: at,
442
- generate: Re,
443
- observe: st,
444
- unobserve: it
441
+ compare: ot,
442
+ generate: Ne,
443
+ observe: rt,
444
+ unobserve: nt
445
445
  }, Symbol.toStringTag, { value: "Module" }));
446
- Object.assign({}, Ve, ct, {
447
- JsonPatchError: qe,
448
- deepClone: Y,
449
- escapePathComponent: re,
450
- unescapePathComponent: $e
446
+ Object.assign({}, Ze, st, {
447
+ JsonPatchError: xe,
448
+ deepClone: F,
449
+ escapePathComponent: ee,
450
+ unescapePathComponent: be
451
451
  });
452
- const ft = "https://auth.knowlearning.systems", ut = `-----BEGIN PUBLIC KEY-----
452
+ const it = "https://auth.knowlearning.systems", at = `-----BEGIN PUBLIC KEY-----
453
453
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA59Uz6jvBJF3B8/7xMqGo
454
454
  XkIhLFvTCHuFIGuCNNZGCJUnSk2ne6Jp1ehUIarliJwzrvfr2HMe0PvzAJyZqQIs
455
455
  uz0Lt867TTojCAKJunxbcrwEhzvz0FNjNu1wpgkSHFvd1uTvRSZqauqUmG0HqC17
@@ -466,27 +466,27 @@ if (window.location.pathname.startsWith("/auth/")) {
466
466
  window.localStorage.setItem("token", n), window.location.href = r;
467
467
  }
468
468
  }
469
- async function lt(e = "google", t) {
469
+ async function ct(e = "google", t) {
470
470
  const r = Math.random().toString(36).substring(2);
471
471
  if (window.localStorage.setItem(r, window.location.href), e === "code") {
472
- const n = { code: t, provider: e, domain: window.location.host }, o = await pt(ut, JSON.stringify(n));
472
+ const n = { code: t, provider: e, domain: window.location.host }, o = await lt(at, JSON.stringify(n));
473
473
  window.location.href = `/auth/${r}/${o}`;
474
474
  } else {
475
475
  const n = encodeURIComponent(window.location.href);
476
- window.location.href = `${ft}/${e}/${r}/${n}`;
476
+ window.location.href = `${it}/${e}/${r}/${n}`;
477
477
  }
478
478
  }
479
- function dt() {
479
+ function ft() {
480
480
  window.localStorage.setItem("token", Math.random().toString(36).substring(2)), window.location.reload();
481
481
  }
482
- async function wt() {
482
+ async function ut() {
483
483
  const e = localStorage.getItem("token");
484
484
  return window.localStorage.removeItem("token"), e;
485
485
  }
486
- async function pt(e, t) {
486
+ async function lt(e, t) {
487
487
  const r = await crypto.subtle.importKey(
488
488
  "spki",
489
- ht(e),
489
+ dt(e),
490
490
  { name: "RSA-OAEP", hash: "SHA-256" },
491
491
  !0,
492
492
  ["encrypt"]
@@ -494,89 +494,89 @@ async function pt(e, t) {
494
494
  { name: "AES-GCM", length: 256 },
495
495
  !0,
496
496
  ["encrypt", "decrypt"]
497
- ), o = new TextEncoder().encode(t), i = crypto.getRandomValues(new Uint8Array(12)), c = await crypto.subtle.encrypt(
498
- { name: "AES-GCM", iv: i },
497
+ ), o = new TextEncoder().encode(t), s = crypto.getRandomValues(new Uint8Array(12)), c = await crypto.subtle.encrypt(
498
+ { name: "AES-GCM", iv: s },
499
499
  n,
500
500
  o
501
- ), d = await crypto.subtle.exportKey("raw", n), p = await crypto.subtle.encrypt(
501
+ ), d = await crypto.subtle.exportKey("raw", n), w = await crypto.subtle.encrypt(
502
502
  { name: "RSA-OAEP" },
503
503
  r,
504
504
  d
505
505
  );
506
506
  return [
507
- encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(i)))),
507
+ encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(s)))),
508
508
  encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(c)))),
509
- encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(p))))
509
+ encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(w))))
510
510
  ].join(",");
511
511
  }
512
- function ht(e) {
512
+ function dt(e) {
513
513
  const t = e.replace(/-----[^-]+-----/g, "").replace(/\s/g, ""), r = atob(t), n = new Uint8Array(r.length);
514
514
  for (let o = 0; o < r.length; o++)
515
515
  n[o] = r.charCodeAt(o);
516
516
  return n.buffer;
517
517
  }
518
- function vt(e) {
518
+ function pt(e) {
519
519
  return e.map((t) => {
520
- const r = { ...t, path: "/" + t.path.map(Ue).join("/") };
521
- return t.from && (r.from = "/" + t.from.map(Ue).join("/")), r;
520
+ const r = { ...t, path: "/" + t.path.map(De).join("/") };
521
+ return t.from && (r.from = "/" + t.from.map(De).join("/")), r;
522
522
  });
523
523
  }
524
- function Ue(e) {
524
+ function De(e) {
525
525
  return typeof e == "string" ? e.replaceAll("~", "~0").replaceAll("/", "~1") : e;
526
526
  }
527
- const ge = /* @__PURE__ */ new Set(), ue = /* @__PURE__ */ new Map();
528
- function le(e) {
527
+ const Ee = /* @__PURE__ */ new Set(), ae = /* @__PURE__ */ new Map();
528
+ function ce(e) {
529
529
  return `/${e.join("/")}`;
530
530
  }
531
- function Me(e) {
531
+ function Le(e) {
532
532
  return JSON.parse(JSON.stringify(e));
533
533
  }
534
- function yt(e, [t, r]) {
534
+ function wt(e, [t, r]) {
535
535
  return Math.max(Math.min(parseInt(e), r), t);
536
536
  }
537
- function ce(e, t, r = {}, n = [], o) {
538
- if (r[le(n)]) return e;
539
- if (ge.has(e))
540
- throw new Error(`Cannot add mutable state to multiple mutable parents. Attempted Path: ${le(n)}`);
541
- const i = Array.isArray(e), c = (a, s) => ce(
542
- s,
537
+ function se(e, t, r = {}, n = [], o) {
538
+ if (r[ce(n)]) return e;
539
+ if (Ee.has(e))
540
+ throw new Error(`Cannot add mutable state to multiple mutable parents. Attempted Path: ${ce(n)}`);
541
+ const s = Array.isArray(e), c = (i, a) => se(
542
+ a,
543
543
  t,
544
544
  r,
545
- [...n, a]
545
+ [...n, i]
546
546
  ), d = {
547
547
  copyWithin() {
548
548
  throw new Error('"copyWithin" not implemented.');
549
549
  },
550
- sort(a) {
551
- const s = /* @__PURE__ */ new Map();
552
- e.forEach((u, g) => {
553
- s.has(u) || s.set(u, []), s.get(u).push(g);
554
- }), e.sort(a);
555
- let v = e.map((u) => s.get(u).shift());
550
+ sort(i) {
551
+ const a = /* @__PURE__ */ new Map();
552
+ e.forEach((l, E) => {
553
+ a.has(l) || a.set(l, []), a.get(l).push(E);
554
+ }), e.sort(i);
555
+ let h = e.map((l) => a.get(l).shift());
556
556
  return t(
557
- e.map((u, g) => {
558
- const h = ue.get(u);
559
- h && (h[h.length - 1] = g);
560
- const N = v[g];
561
- return v = v.map((O) => O < N ? O + 1 : O), {
557
+ e.map((l, E) => {
558
+ const v = ae.get(l);
559
+ v && (v[v.length - 1] = E);
560
+ const g = h[E];
561
+ return h = h.map((O) => O < g ? O + 1 : O), {
562
562
  op: "move",
563
- from: [...n, N],
564
- path: [...n, g]
563
+ from: [...n, g],
564
+ path: [...n, E]
565
565
  };
566
566
  })
567
- ), l;
567
+ ), u;
568
568
  },
569
569
  reverse() {
570
- const a = [];
571
- return e.forEach((s, v) => {
572
- a.push({
570
+ const i = [];
571
+ return e.forEach((a, h) => {
572
+ i.push({
573
573
  op: "move",
574
- from: [...n, v],
574
+ from: [...n, h],
575
575
  path: [...n, 0]
576
576
  });
577
- const u = ue.get(s);
578
- u && (u[u.length - 1] = e.length - 1 - v);
579
- }), e.reverse(), t(a), l;
577
+ const l = ae.get(a);
578
+ l && (l[l.length - 1] = e.length - 1 - h);
579
+ }), e.reverse(), t(i), u;
580
580
  },
581
581
  shift() {
582
582
  return d.splice(0, 1)[0];
@@ -584,445 +584,432 @@ function ce(e, t, r = {}, n = [], o) {
584
584
  unshift() {
585
585
  return d.splice(0, 0, ...arguments), e.length;
586
586
  },
587
- splice(a, s, ...v) {
588
- const u = e.length - a;
587
+ splice(i, a, ...h) {
588
+ const l = e.length - i;
589
589
  if (arguments.length === 0) return;
590
- arguments.length === 1 || arguments[1] === 1 / 0 ? s = u : s = yt(s, [0, u]) || 0;
591
- const g = [...n, a], h = Array.from(
592
- { length: s },
593
- () => ({ op: "remove", path: g })
590
+ arguments.length === 1 || arguments[1] === 1 / 0 ? a = l : a = wt(a, [0, l]) || 0;
591
+ const E = [...n, i], v = Array.from(
592
+ { length: a },
593
+ () => ({ op: "remove", path: E })
594
594
  );
595
- v.forEach((m, A) => {
596
- h.push({
595
+ h.forEach((m, y) => {
596
+ v.push({
597
597
  op: "add",
598
- path: [...n, a + A],
599
- value: Me(m)
598
+ path: [...n, i + y],
599
+ value: Le(m)
600
600
  });
601
601
  });
602
- const N = v.length - s;
603
- N !== 0 && e.slice(a + s).forEach((m) => {
604
- const A = ue.get(m);
605
- A && (A[A.length - 1] = A[A.length - 1] + N);
602
+ const g = h.length - a;
603
+ g !== 0 && e.slice(i + a).forEach((m) => {
604
+ const y = ae.get(m);
605
+ y && (y[y.length - 1] = y[y.length - 1] + g);
606
606
  });
607
- const O = v.map(
608
- (m, A) => m instanceof Object ? c(A + a, m) : m
609
- ), I = e.splice(a, s, ...O);
610
- return t(h), I;
607
+ const O = h.map(
608
+ (m, y) => m instanceof Object ? c(y + i, m) : m
609
+ ), I = e.splice(i, a, ...O);
610
+ return t(v), I;
611
611
  }
612
612
  };
613
- Object.entries(e).filter(([, a]) => a instanceof Object).forEach(([a, s]) => {
614
- i && /^\d+$/.test(a) && (a = parseInt(a)), e[a] = c(a, s);
613
+ Object.entries(e).filter(([, i]) => i instanceof Object).forEach(([i, a]) => {
614
+ s && /^\d+$/.test(i) && (i = parseInt(i)), e[i] = c(i, a);
615
615
  });
616
- const p = {
617
- set(a, s, v) {
618
- if (i)
619
- if (/^\d+$/.test(s))
620
- s = parseInt(s);
621
- else return a[s] = v, !0;
622
- const u = [...n, s], g = le(u);
623
- if (r[g])
624
- return a[s] = v, !0;
625
- if (v === void 0)
626
- throw new Error(`Setting properties to undefined is not supported. Please use a delete statement. Attempted to set ${g}`);
616
+ const w = {
617
+ set(i, a, h) {
618
+ if (s)
619
+ if (/^\d+$/.test(a))
620
+ a = parseInt(a);
621
+ else return i[a] = h, !0;
622
+ const l = [...n, a], E = ce(l);
623
+ if (r[E])
624
+ return i[a] = h, !0;
625
+ if (h === void 0)
626
+ throw new Error(`Setting properties to undefined is not supported. Please use a delete statement. Attempted to set ${E}`);
627
627
  return t([{
628
- op: a[s] === void 0 ? "add" : "replace",
629
- value: Me(v),
628
+ op: i[a] === void 0 ? "add" : "replace",
629
+ value: Le(h),
630
630
  // TODO: more efficient sanitization
631
- path: u
632
- }]), v instanceof Object ? a[s] = c(s, v) : a[s] = v, !0;
631
+ path: l
632
+ }]), h instanceof Object ? i[a] = c(a, h) : i[a] = h, !0;
633
633
  },
634
- deleteProperty(a, s) {
635
- if (s in a) {
636
- if (ge.delete(l), delete a[s], i)
637
- if (/^\d+$/.test(s)) s = parseInt(s);
634
+ deleteProperty(i, a) {
635
+ if (a in i) {
636
+ if (Ee.delete(u), delete i[a], s)
637
+ if (/^\d+$/.test(a)) a = parseInt(a);
638
638
  else return !0;
639
- const v = [...n, s];
640
- r[le(v)] || t([{ op: "remove", path: v }]);
639
+ const h = [...n, a];
640
+ r[ce(h)] || t([{ op: "remove", path: h }]);
641
641
  }
642
642
  return !0;
643
643
  },
644
- get(a, s, v) {
645
- return i && d[s] ? d[s] : a[s];
644
+ get(i, a, h) {
645
+ return s && d[a] ? d[a] : i[a];
646
646
  }
647
- }, l = new Proxy(e, p);
648
- return ge.add(l), ue.set(l, n), l;
647
+ }, u = new Proxy(e, w);
648
+ return Ee.add(u), ae.set(u, n), u;
649
649
  }
650
- const mt = 1e4, Et = { open: !0, mutate: !0, close: !0 };
651
- function At(e) {
650
+ const ht = 1e4, vt = { open: !0, mutate: !0, close: !0 };
651
+ function yt(e) {
652
652
  return structuredClone(e).filter(({ path: t }) => t.shift() === "active");
653
653
  }
654
- function gt({ token: e, sid: t, domain: r, Connection: n, watchers: o, states: i, applyPatch: c, log: d, login: p, reboot: l, handleDomainMessage: a, trigger: s, variables: v = {} }) {
655
- let u, g, h = !1, N, O, I = -1, m = 0;
656
- const A = [];
657
- let R = -1, _, L = null, q = null, G = !1, V = !1;
658
- const K = [], W = {};
659
- let te;
660
- const ee = new Promise((w) => te = w), f = {
654
+ function mt({ token: e, sid: t, domain: r, Connection: n, watchers: o, states: s, applyPatch: c, log: d, login: w, reboot: u, handleDomainMessage: i, trigger: a, variables: h = {} }) {
655
+ let l, E, v = !1, g, O, I = -1, m = 0;
656
+ const y = [];
657
+ let N = -1, _, M = null, $ = null, z = !1, Y = !1;
658
+ const X = [], p = {};
659
+ let A;
660
+ const T = new Promise((f) => A = f), R = {
661
661
  loaded: Date.now(),
662
662
  connected: null,
663
663
  authenticated: null
664
664
  };
665
- async function E() {
666
- return { variables: v, ...await ee, context: [] };
665
+ async function P() {
666
+ return { variables: h, ...await T, context: [] };
667
667
  }
668
- function S({ scope: w, patch: y }) {
669
- if (L === w) {
670
- const T = A.length - 1;
671
- A[T].patch = [...A[T].patch, ...y];
668
+ function H({ scope: f, patch: C, context: b }) {
669
+ if (M === f) {
670
+ const G = y.length - 1;
671
+ y[G].patch = [...y[G].patch, ...C];
672
672
  } else
673
- I += 1, q = new Promise((T, C) => W[I] = [[T, C]]), A.push({ scope: w, patch: y, si: I, ts: Date.now() }), L = w, P();
674
- return q;
673
+ I += 1, $ = new Promise((G, L) => p[I] = [[G, L]]), y.push({ scope: f, patch: C, context: b, si: I, ts: Date.now() }), M = f, q();
674
+ return $;
675
675
  }
676
- async function P() {
677
- for (await new Promise((w) => w()), L = null; h && R + 1 < A.length; ) {
678
- L = null;
676
+ async function q() {
677
+ for (await new Promise((f) => f()), M = null; v && N + 1 < y.length; ) {
678
+ M = null;
679
679
  try {
680
- u.send(A[R + 1]), R += 1, await new Promise((w) => w());
681
- } catch (w) {
682
- console.warn("ERROR SENDING OVER CONNECTION", w), b();
680
+ l.send(y[N + 1]), N += 1, await new Promise((f) => f());
681
+ } catch (f) {
682
+ console.warn("ERROR SENDING OVER CONNECTION", f), B();
683
683
  break;
684
684
  }
685
685
  }
686
686
  }
687
- function x() {
688
- const w = Object.keys(W).map(parseInt).sort()[0] || 1 / 0;
689
- for (; K[0] && K[0].si < w; )
690
- K.shift().resolve();
687
+ function Q() {
688
+ const f = Object.keys(p).map(parseInt).sort()[0] || 1 / 0;
689
+ for (; X[0] && X[0].si < f; )
690
+ X.shift().resolve();
691
691
  }
692
692
  function J() {
693
693
  clearTimeout(_), _ = setTimeout(
694
694
  () => {
695
- d("CLOSING DUE TO HEARTBEAT TIMEOUT"), b();
695
+ d("CLOSING DUE TO HEARTBEAT TIMEOUT"), B();
696
696
  },
697
- mt
697
+ ht
698
698
  );
699
699
  }
700
- async function b() {
701
- G || (h = !1, u.onmessage = () => {
702
- }, V || (await new Promise((w) => setTimeout(w, Math.min(1e3, m * 100))), G = !0, m += 1, B(), G = !1));
700
+ async function B() {
701
+ z || (v = !1, l.onmessage = () => {
702
+ }, Y || (await new Promise((f) => setTimeout(f, Math.min(1e3, m * 100))), z = !0, m += 1, K(), z = !1));
703
703
  }
704
- function B() {
705
- u = new n(), u.onopen = async () => {
706
- f.connected || (f.connected = Date.now()), d("AUTHORIZING NEWLY OPENED CONNECTION FOR SESSION:", N), m = 0, u.send({ token: await e(), sid: await (t == null ? void 0 : t()), session: N, domain: r });
707
- }, u.onmessage = async (w) => {
708
- if (J(), !!w)
704
+ function K() {
705
+ l = new n(), l.onopen = async () => {
706
+ R.connected || (R.connected = Date.now()), d("AUTHORIZING NEWLY OPENED CONNECTION FOR SESSION:", g), m = 0, l.send({ token: await e(), sid: await (t == null ? void 0 : t()), session: g, domain: r });
707
+ }, l.onmessage = async (f) => {
708
+ if (J(), !!f)
709
709
  try {
710
- if (w.error && console.warn("ERROR RESPONSE", w), h)
711
- if (Et[w.type])
710
+ if (f.error && console.warn("ERROR RESPONSE", f), v)
711
+ if (vt[f.type])
712
712
  try {
713
- a && a(w, s);
713
+ i && i(f, a);
714
714
  } catch {
715
- d("ERROR HANDLING DOMAIN MESSAGE", w);
715
+ d("ERROR HANDLING DOMAIN MESSAGE", f);
716
716
  }
717
- else if (w.si !== void 0)
718
- W[w.si] ? (W[w.si].forEach(([y, T]) => w.error ? T(w) : y(w)), delete W[w.si], u.send({ ack: w.si }), x()) : console.warn("received MULTIPLE responses for message with si", w.si, w);
717
+ else if (f.si !== void 0)
718
+ p[f.si] ? (p[f.si].forEach(([C, b]) => f.error ? b(f) : C(f)), delete p[f.si], l.send({ ack: f.si }), Q()) : console.warn("received MULTIPLE responses for message with si", f.si, f);
719
719
  else {
720
- const y = w.domain === r ? "" : w.domain, T = w.user === g ? "" : w.user, C = w.scope, D = Q(C) ? C : `${y}/${T}/${C}`;
721
- if (o[D]) {
722
- if (i[D] = await i[D], i[D].ii + 1 !== w.ii)
720
+ const C = f.domain === r ? "" : f.domain, b = f.user === E ? "" : f.user, G = f.scope, L = k(G) ? G : `${C}/${b}/${G}`;
721
+ if (o[L]) {
722
+ if (s[L] = await s[L], s[L].ii + 1 !== f.ii)
723
723
  return;
724
- i[D].ii = w.ii;
725
- const $ = w.patch.findLastIndex((F) => F.path.length === 0);
726
- $ > -1 && (i[D] = w.patch[$].value), i[D].active === void 0 && (i[D].active = {}), c(i[D], vt(w.patch.slice($ + 1))), o[D].forEach((F) => {
727
- const k = structuredClone(i[D].active);
728
- F({ ...w, patch: At(w.patch), state: k });
724
+ s[L].ii = f.ii;
725
+ const W = f.patch.findLastIndex((V) => V.path.length === 0);
726
+ W > -1 && (s[L] = f.patch[W].value), s[L].active === void 0 && (s[L].active = {}), c(s[L], pt(f.patch.slice(W + 1))), o[L].forEach((V) => {
727
+ const we = structuredClone(s[L].active);
728
+ V({ ...f, patch: yt(f.patch), state: we });
729
729
  });
730
730
  }
731
731
  }
732
732
  else {
733
- if (w.error) return p();
734
- h = !0, g ? O !== w.server ? (console.warn(`REBOOTING DUE TO SERVER SWITCH ${O} -> ${w.server}`, w), l()) : R = w.ack : (console.log("INIT MESSAGE", w), f.authenticated = Date.now(), g = w.auth.user, N = w.session, O = w.server, te(w)), P();
733
+ if (f.error) return w();
734
+ v = !0, E ? O !== f.server ? (console.warn(`REBOOTING DUE TO SERVER SWITCH ${O} -> ${f.server}`, f), u()) : N = f.ack : (console.log("INIT MESSAGE", f), R.authenticated = Date.now(), E = f.auth.user, g = f.session, O = f.server, A(f)), q();
735
735
  }
736
- } catch (y) {
737
- console.error("ERROR HANDLING CONNECTION MESSAGE", y, w);
736
+ } catch (C) {
737
+ console.error("ERROR HANDLING CONNECTION MESSAGE", C, f);
738
738
  }
739
- }, u.onerror = async (w) => {
740
- d("CONNECTION ERROR", w.message);
741
- }, u.onclose = async (w) => {
742
- d("CONNECTION CLOSURE", w.message), b();
739
+ }, l.onerror = async (f) => {
740
+ d("CONNECTION ERROR", f.message);
741
+ }, l.onclose = async (f) => {
742
+ d("CONNECTION CLOSURE", f.message), B();
743
743
  }, J();
744
744
  }
745
- async function H() {
746
- const w = new Promise((y) => K.push({ si: R, resolve: y }));
747
- return x(), w;
745
+ async function Z() {
746
+ const f = new Promise((C) => X.push({ si: N, resolve: C }));
747
+ return Q(), f;
748
748
  }
749
- function z() {
750
- return new Promise((w, y) => W[I].push([w, y]));
749
+ function pe() {
750
+ return new Promise((f, C) => p[I].push([f, C]));
751
751
  }
752
- function Z() {
753
- d("DISCONNECTED AGENT!!!!!!!!!!!!!!!"), V = !0, u.close({ keepalive: !0 });
752
+ function S() {
753
+ d("DISCONNECTED AGENT!!!!!!!!!!!!!!!"), Y = !0, l.close({ keepalive: !0 });
754
754
  }
755
- function X() {
756
- d("RECONNECTED AGENT!!!!!!!!!!!!!!!"), V = !1, b();
755
+ function D() {
756
+ d("RECONNECTED AGENT!!!!!!!!!!!!!!!"), Y = !1, B();
757
757
  }
758
- return B(), [S, z, Z, X, H, E];
758
+ return K(), [H, pe, S, D, Z, P];
759
759
  }
760
- function Ot(e = "[]", t, r, { keyToSubscriptionId: n, watchers: o, states: i, create: c, environment: d, lastMessageResponse: p, lastInteractionResponse: l, tagIfNotYetTaggedInSession: a, interact: s, log: v }) {
761
- let u, g = new Promise((N) => u = N);
762
- const h = new Promise(async (N, O) => {
763
- const { auth: { user: I }, domain: m, session: A } = await d(), R = Q(e) ? e : `${!r || r === m ? "" : r}/${!t || t === I ? "" : t}/${e}`;
764
- if (!n[R]) {
765
- const _ = Qe();
766
- n[R] = _, o[R] = [], i[R] = new Promise(async (L, q) => {
767
- await new Promise((G) => setTimeout(G)), s("sessions", [{
760
+ function Et(e = "[]", t, r, { keyToSubscriptionId: n, watchers: o, states: s, create: c, environment: d, lastMessageResponse: w, lastInteractionResponse: u, interact: i, log: a }) {
761
+ let h, l = new Promise((v) => h = v);
762
+ const E = new Promise(async (v, g) => {
763
+ const { auth: { user: O }, domain: I, session: m } = await d(), y = k(e) ? e : `${!r || r === I ? "" : r}/${!t || t === O ? "" : t}/${e}`;
764
+ if (!n[y]) {
765
+ const N = Fe();
766
+ n[y] = N, o[y] = [], s[y] = new Promise(async (_, M) => {
767
+ await new Promise(($) => setTimeout($)), i("sessions", [{
768
768
  op: "add",
769
- path: ["active", A, "subscriptions", _],
769
+ path: ["active", m, "subscriptions", N],
770
770
  value: { scope: e, user: t, domain: r, ii: null }
771
- }], !1, !1);
771
+ }], !1);
772
772
  try {
773
- L(await p());
774
- } catch (G) {
775
- q(G);
773
+ _(await w());
774
+ } catch ($) {
775
+ M($);
776
776
  }
777
777
  });
778
778
  }
779
- await l[R];
779
+ await u[y];
780
780
  try {
781
- const _ = structuredClone(await i[R]), L = _.active;
782
- delete _.active, u(_), N(new ce(L || {}, (q) => {
783
- const G = structuredClone(q);
784
- G.forEach((V) => V.path.unshift("active")), s(e, G);
781
+ const N = structuredClone(await s[y]), _ = N.active;
782
+ delete N.active, h(N), v(new se(_ || {}, (M) => {
783
+ const $ = structuredClone(M);
784
+ $.forEach((z) => z.path.unshift("active")), i(e, $);
785
785
  }));
786
- } catch (_) {
787
- O(_);
786
+ } catch (N) {
787
+ g(N);
788
788
  }
789
789
  });
790
- return h.metadata = g, h;
790
+ return E.metadata = l, E;
791
791
  }
792
- const Tt = "[]";
793
- function Je({ metadata: e, environment: t, state: r, watchers: n, synced: o, sentUpdates: i }) {
794
- function c(l = Tt, a, s, v) {
795
- if (Array.isArray(l)) return d(l, a, s, v);
796
- const u = r(l, s, v);
797
- let g, h = !1;
798
- return e(l, s, v).then(async ({ ii: N }) => {
799
- const { auth: { user: O }, domain: I } = await t(), m = await u;
800
- h || (g = Q(l) ? l : `${!v || v === I ? "" : v}/${!s || s === O ? "" : s}/${l}`, a({ scope: l, user: s, domain: v, state: m, patch: null, ii: N }), i && (i[g] = N), !h && (n[g] || (n[g] = []), n[g].push(a)));
792
+ const At = "[]";
793
+ function qe({ metadata: e, environment: t, state: r, watchers: n, synced: o, sentUpdates: s }) {
794
+ function c(u = At, i, a, h) {
795
+ if (Array.isArray(u)) return d(u, i, a, h);
796
+ const l = r(u, a, h);
797
+ let E, v = !1;
798
+ return e(u, a, h).then(async ({ ii: g }) => {
799
+ const { auth: { user: O }, domain: I } = await t(), m = await l;
800
+ v || (E = k(u) ? u : `${!h || h === I ? "" : h}/${!a || a === O ? "" : a}/${u}`, i({ scope: u, user: a, domain: h, state: m, patch: null, ii: g }), s && (s[E] = g), !v && (n[E] || (n[E] = []), n[E].push(i)));
801
801
  }), () => {
802
- h = !0, g && p(g, a);
802
+ v = !0, E && w(E, i);
803
803
  };
804
804
  }
805
- function d(l, a, s, v) {
806
- const u = l[0], g = l.slice(1);
807
- let h = () => {
805
+ function d(u, i, a, h) {
806
+ const l = u[0], E = u.slice(1);
807
+ let v = () => {
808
808
  };
809
- const O = c(u, ({ state: I }) => {
810
- if (g.length === 0) {
811
- a(I);
809
+ const O = c(l, ({ state: I }) => {
810
+ if (E.length === 0) {
811
+ i(I);
812
812
  return;
813
813
  }
814
- h();
814
+ v();
815
815
  let m = I;
816
- for (let A = 0; A < g.length; A += 1)
817
- if (m = m[g[A]], m == null || A === g.length - 1) a(m);
818
- else if (Q(m)) {
819
- h = d([m, ...g.slice(A + 1)], a, s, v);
816
+ for (let y = 0; y < E.length; y += 1)
817
+ if (m = m[E[y]], m == null || y === E.length - 1) i(m);
818
+ else if (k(m)) {
819
+ v = d([m, ...E.slice(y + 1)], i, a, h);
820
820
  return;
821
821
  }
822
- }, s, v);
822
+ }, a, h);
823
823
  return () => {
824
- O(), h();
824
+ O(), v();
825
825
  };
826
826
  }
827
- function p(l, a) {
828
- if (!n[l]) {
829
- console.warn("NO WATCHERS FOR KEY", l, a);
827
+ function w(u, i) {
828
+ if (!n[u]) {
829
+ console.warn("NO WATCHERS FOR KEY", u, i);
830
830
  return;
831
831
  }
832
- const s = n[l].findIndex((v) => v === a);
833
- s > -1 && n[l].splice(s, 1);
832
+ const a = n[u].findIndex((h) => h === i);
833
+ a > -1 && n[u].splice(a, 1);
834
834
  }
835
- return [c, p];
835
+ return [c, w];
836
836
  }
837
- const It = "application/json;type=download";
838
- function He(e, { create: t, lastMessageResponse: r, fetch: n, metadata: o }) {
837
+ const Ot = "application/json;type=download";
838
+ function Je(e, { create: t, lastMessageResponse: r, fetch: n, metadata: o }) {
839
839
  t({
840
- active_type: It,
840
+ active_type: Ot,
841
841
  active: { id: e }
842
842
  });
843
- let i = "fetch";
844
- const c = new Promise(async (d, p) => {
845
- const { url: l } = await r();
846
- if (await new Promise((a) => setTimeout(a)), i === "url") d(l);
847
- else if (i === "fetch") {
848
- const a = await n(l), { ok: s, statusText: v } = a;
849
- s ? d(a) : p(v);
850
- } else if (i === "direct") {
851
- const a = await He(e, { create: t, lastMessageResponse: r, fetch: n, metadata: o }), { name: s } = await o(e), v = a.headers.get("Content-Type"), u = new Blob([await a.blob()], { type: v }), g = window.URL.createObjectURL(u), h = document.createElement("a");
852
- h.style.display = "none", h.href = g, h.download = s, document.body.appendChild(h), h.click(), window.URL.revokeObjectURL(g), d();
843
+ let s = "fetch";
844
+ const c = new Promise(async (d, w) => {
845
+ const { url: u } = await r();
846
+ if (await new Promise((i) => setTimeout(i)), s === "url") d(u);
847
+ else if (s === "fetch") {
848
+ const i = await n(u), { ok: a, statusText: h } = i;
849
+ a ? d(i) : w(h);
850
+ } else if (s === "direct") {
851
+ const i = await Je(e, { create: t, lastMessageResponse: r, fetch: n, metadata: o }), { name: a } = await o(e), h = i.headers.get("Content-Type"), l = new Blob([await i.blob()], { type: h }), E = window.URL.createObjectURL(l), v = document.createElement("a");
852
+ v.style.display = "none", v.href = E, v.download = a, document.body.appendChild(v), v.click(), window.URL.revokeObjectURL(E), d();
853
853
  }
854
854
  });
855
- return c.direct = () => (i = "direct", c), c.url = () => (i = "url", c), c;
855
+ return c.direct = () => (s = "direct", c), c.url = () => (s = "url", c), c;
856
856
  }
857
- const Oe = "[]", St = "application/json;type=upload", Nt = "application/json;type=tag", _t = "application/json;type=domain-claim";
858
- function Rt({ Connection: e, domain: t, token: r, sid: n, uuid: o, fetch: i, applyPatch: c, login: d, logout: p, reboot: l, handleDomainMessage: a, log: s = console.log, variables: v = {} }) {
859
- const u = {}, g = {}, h = {}, N = {}, O = {};
860
- ee("INITIALIZING AGENT CONNECTION");
857
+ const Ae = "[]", gt = "application/json;type=upload", It = "application/json;type=domain-claim";
858
+ function Tt({ Connection: e, domain: t, token: r, sid: n, uuid: o, fetch: s, applyPatch: c, login: d, logout: w, reboot: u, handleDomainMessage: i, log: a = console.log, variables: h = {} }) {
859
+ const l = {}, E = {}, v = {}, g = {};
860
+ A("INITIALIZING AGENT CONNECTION");
861
861
  const [
862
+ O,
862
863
  I,
863
864
  m,
864
- A,
865
- R,
866
- _,
867
- L
868
- ] = gt({ token: r, sid: n, domain: t, Connection: e, watchers: g, states: u, applyPatch: c, log: ee, login: d, interact: P, reboot: l, trigger: w, handleDomainMessage: a, variables: v });
869
- L().then(({ session: y }) => {
870
- P("sessions", [{ op: "add", path: ["active", y], value: { queries: {}, subscriptions: {} } }], !1, !1);
865
+ y,
866
+ N,
867
+ _
868
+ ] = mt({ token: r, sid: n, domain: t, Connection: e, watchers: E, states: l, applyPatch: c, log: A, login: d, interact: P, reboot: u, trigger: pe, handleDomainMessage: i, variables: h });
869
+ _().then(({ session: S }) => {
870
+ P("sessions", [{ op: "add", path: ["active", S], value: { queries: {}, subscriptions: {} } }], !1);
871
871
  });
872
- const q = {
873
- keyToSubscriptionId: h,
874
- watchers: g,
875
- states: u,
876
- state: K,
877
- create: f,
878
- environment: L,
879
- lastInteractionResponse: N,
880
- lastMessageResponse: m,
881
- tagIfNotYetTaggedInSession: E,
872
+ const M = {
873
+ keyToSubscriptionId: v,
874
+ watchers: E,
875
+ states: l,
876
+ state: Y,
877
+ create: T,
878
+ environment: _,
879
+ lastInteractionResponse: g,
880
+ lastMessageResponse: I,
882
881
  interact: P,
883
- fetch: i,
884
- synced: _,
885
- metadata: B,
886
- log: ee
887
- }, [G, V] = Je(q);
888
- function K(y, T, C) {
889
- return Ot(y, T, C, q);
890
- }
891
- function W(y) {
892
- return He(y, q);
893
- }
894
- function te() {
895
- }
896
- function ee() {
897
- s(...arguments);
898
- }
899
- function f({ id: y = o(), active_type: T, active: C, name: D }) {
900
- T || (T = "application/json");
901
- const $ = [
902
- { op: "add", path: ["active_type"], value: T },
903
- { op: "add", path: ["active"], value: C }
882
+ fetch: s,
883
+ synced: N,
884
+ metadata: J,
885
+ log: A
886
+ }, [$, z] = qe(M);
887
+ function Y(S, D, f) {
888
+ return Et(S, D, f, M);
889
+ }
890
+ function X(S) {
891
+ return Je(S, M);
892
+ }
893
+ function p() {
894
+ }
895
+ function A() {
896
+ a(...arguments);
897
+ }
898
+ function T({ id: S = o(), active_type: D, active: f, name: C }) {
899
+ D || (D = "application/json");
900
+ const b = [
901
+ { op: "add", path: ["active_type"], value: D },
902
+ { op: "add", path: ["active"], value: f }
904
903
  ];
905
- return D && $.push({ op: "add", path: ["name"], value: D }), P(y, $, !1), y;
906
- }
907
- async function E(y, T) {
908
- const C = O[y];
909
- C && C[T] || (C || (O[y] = {}), !O[y][T] && (O[y][T] = !0, Q(T) || (T = (await B(T)).id), await z(y, T)));
910
- }
911
- async function S(y) {
912
- const { name: T, type: C, data: D, id: $ = o() } = y || {};
913
- f({
914
- active_type: St,
915
- active: { id: $, type: C, name: T },
916
- name: T
904
+ return C && b.push({ op: "add", path: ["name"], value: C }), P(S, b), S;
905
+ }
906
+ async function R(S) {
907
+ const { name: D, type: f, data: C, id: b = o() } = S || {};
908
+ T({
909
+ active_type: gt,
910
+ active: { id: b, type: f, name: D },
911
+ name: D
917
912
  });
918
- const { url: F } = await m();
919
- if (D === void 0) return F;
913
+ const { url: G } = await I();
914
+ if (C === void 0) return G;
920
915
  {
921
- const ne = await i(F, { method: "PUT", headers: { "Content-Type": C }, body: D }), { ok: ve, statusText: Fe } = ne;
922
- if (ve) return $;
923
- throw new Error(Fe);
916
+ const W = await s(G, { method: "PUT", headers: { "Content-Type": f }, body: C }), { ok: V, statusText: we } = W;
917
+ if (V) return b;
918
+ throw new Error(we);
924
919
  }
925
920
  }
926
- async function P(y = Oe, T, C = !0, D = !0) {
927
- C && E("mutated", y);
928
- const $ = I({ scope: y, patch: T }), F = Q(y) ? y : `//${y}`;
929
- if (D && u[F] !== void 0)
930
- return N[F] = $.then((k) => k.ii), $;
921
+ async function P(S = Ae, D, f = !0, C = []) {
922
+ const b = O({ scope: S, patch: D, context: C }), G = k(S) ? S : `//${S}`;
923
+ if (f && l[G] !== void 0)
924
+ return g[G] = b.then((L) => L.ii), b;
931
925
  {
932
- const { ii: k } = await $;
933
- return { ii: k };
926
+ const { ii: L } = await b;
927
+ return { ii: L };
934
928
  }
935
929
  }
936
- async function x(y) {
937
- const T = o();
938
- return f({
939
- id: T,
940
- active_type: _t,
941
- active: { domain: y }
942
- }), m();
943
- }
944
- function J(y = Oe) {
945
- return P(y, [{ op: "remove", path: ["active"] }]);
946
- }
947
- function b({ path: y, op: T, value: C }) {
948
- return ["active_type", "name"].includes(y[0]) && y.length === 1 && typeof C == "string" || T === "remove";
949
- }
950
- async function B(y = Oe, T, C) {
951
- const D = structuredClone(await K(y, T).metadata);
952
- return delete D.active, new ce(D, ($) => {
953
- const F = structuredClone($);
954
- if (!F.every(b))
930
+ async function H(S) {
931
+ const D = o();
932
+ return T({
933
+ id: D,
934
+ active_type: It,
935
+ active: { domain: S }
936
+ }), I();
937
+ }
938
+ function q(S = Ae) {
939
+ return P(S, [{ op: "remove", path: ["active"] }]);
940
+ }
941
+ function Q({ path: S, op: D, value: f }) {
942
+ return ["active_type", "name"].includes(S[0]) && S.length === 1 && typeof f == "string" || D === "remove";
943
+ }
944
+ async function J(S = Ae, D, f) {
945
+ const C = structuredClone(await Y(S, D).metadata);
946
+ return delete C.active, new se(C, (b) => {
947
+ const G = structuredClone(b);
948
+ if (!G.every(Q))
955
949
  throw new Error("You may only modify the type or name for a scope's metadata");
956
- P(y, F);
950
+ P(S, G);
957
951
  });
958
952
  }
959
- async function H(y, T, C, D = []) {
960
- const $ = o(), F = Date.now(), { session: k } = await L();
961
- await new Promise((ne) => setTimeout(ne)), P("sessions", [
953
+ async function B(S, D, f, C = []) {
954
+ const b = o(), G = Date.now(), { session: L } = await _();
955
+ await new Promise((W) => setTimeout(W)), P("sessions", [
962
956
  {
963
957
  op: "add",
964
- path: ["active", k, "queries", $],
965
- value: { query: y, params: T, domain: C, context: D }
958
+ path: ["active", L, "queries", b],
959
+ value: { query: S, params: D, domain: f, context: C }
966
960
  }
967
- ], !1, !1);
961
+ ], !1);
968
962
  try {
969
- const ne = await m(), { rows: ve } = ne;
963
+ const W = await I(), { rows: V } = W;
970
964
  return P("sessions", [
971
965
  {
972
966
  op: "add",
973
- path: ["active", k, "queries", $, "agent_latency"],
974
- value: Date.now() - F
967
+ path: ["active", L, "queries", b, "agent_latency"],
968
+ value: Date.now() - G
975
969
  },
976
970
  {
977
971
  op: "remove",
978
- path: ["active", k, "queries", $]
972
+ path: ["active", L, "queries", b]
979
973
  }
980
- ], !1, !1), ve;
981
- } catch (ne) {
982
- throw ne;
974
+ ], !1), V;
975
+ } catch (W) {
976
+ throw W;
983
977
  }
984
978
  }
985
- function z(y, T, C = []) {
986
- return f({
987
- active_type: Nt,
988
- active: { tag_type: y, target: T, context: C }
989
- });
990
- }
991
- const Z = { child: [] };
992
- function X(y, T) {
993
- if (!Z[y]) throw new Error('Agent can only listen to events of "child"');
994
- Z[y].push(T);
979
+ const K = { child: [] };
980
+ function Z(S, D) {
981
+ if (!K[S]) throw new Error('Agent can only listen to events of "child"');
982
+ K[S].push(D);
995
983
  }
996
- function w(y, T) {
997
- Z[y].forEach((C) => C(T));
984
+ function pe(S, D) {
985
+ K[S].forEach((f) => f(D));
998
986
  }
999
987
  return {
1000
988
  uuid: o,
1001
- environment: L,
989
+ environment: _,
1002
990
  login: d,
1003
- logout: p,
1004
- log: ee,
1005
- create: f,
1006
- state: K,
1007
- watch: G,
1008
- upload: S,
1009
- download: W,
991
+ logout: w,
992
+ log: A,
993
+ create: T,
994
+ state: Y,
995
+ watch: $,
996
+ upload: R,
997
+ download: X,
1010
998
  interact: P,
1011
- claim: x,
1012
- reset: J,
1013
- metadata: B,
1014
- query: H,
1015
- synced: _,
1016
- disconnect: A,
1017
- reconnect: R,
1018
- tag: z,
1019
- debug: te,
1020
- on: X
999
+ claim: H,
1000
+ reset: q,
1001
+ metadata: J,
1002
+ query: B,
1003
+ synced: N,
1004
+ disconnect: m,
1005
+ reconnect: y,
1006
+ debug: p,
1007
+ on: Z
1021
1008
  };
1022
1009
  }
1023
- const Pt = [...navigator.languages], je = localStorage.getItem("API_HOST") || "api.knowlearning.systems";
1024
- async function Ct() {
1025
- const e = await fetch(`https://${je}/_sid-check`, { method: "GET", credentials: "include" }), t = !!localStorage.getItem("sid");
1010
+ const St = [...navigator.languages], Ge = localStorage.getItem("API_HOST") || "api.knowlearning.systems";
1011
+ async function Nt() {
1012
+ const e = await fetch(`https://${Ge}/_sid-check`, { method: "GET", credentials: "include" }), t = !!localStorage.getItem("sid");
1026
1013
  if (e.status === 201) {
1027
1014
  if (!t) {
1028
1015
  const r = await e.text();
@@ -1030,24 +1017,24 @@ async function Ct() {
1030
1017
  }
1031
1018
  } else e.status === 200 ? t && (localStorage.removeItem("sid"), location.reload()) : console.warn("Issue Connecting To the API Server");
1032
1019
  }
1033
- const Dt = (e) => {
1034
- Ct();
1020
+ const _t = (e) => {
1021
+ Nt();
1035
1022
  const t = function() {
1036
- const n = new WebSocket(`wss://${je}`);
1023
+ const n = new WebSocket(`wss://${Ge}`);
1037
1024
  return this.send = (o) => n.send(JSON.stringify(o)), this.close = (o) => {
1038
1025
  this.send({ type: "close", info: o }), n.close();
1039
1026
  }, n.onopen = () => this.onopen(), n.onmessage = ({ data: o }) => this.onmessage(o.length === 0 ? null : JSON.parse(o)), n.onerror = (o) => this.onerror && this.onerror(o), n.onclose = (o) => this.onclose && this.onclose(o), this;
1040
- }, r = Rt({
1041
- token: e.getToken || wt,
1027
+ }, r = Tt({
1028
+ token: e.getToken || ut,
1042
1029
  sid: () => localStorage.getItem("sid"),
1043
1030
  domain: window.location.host,
1044
1031
  Connection: t,
1045
- uuid: ie,
1032
+ uuid: ne,
1046
1033
  fetch,
1047
- applyPatch: he,
1048
- login: lt,
1049
- logout: dt,
1050
- variables: { LANGUAGES: Pt },
1034
+ applyPatch: de,
1035
+ login: ct,
1036
+ logout: ft,
1037
+ variables: { LANGUAGES: St },
1051
1038
  reboot: () => window.location.reload()
1052
1039
  });
1053
1040
  return r.local = () => {
@@ -1058,218 +1045,208 @@ const Dt = (e) => {
1058
1045
  window.close();
1059
1046
  }, r;
1060
1047
  };
1061
- function Lt() {
1048
+ function Rt() {
1062
1049
  let e = 0, t;
1063
- const r = new Promise((f) => t = f), n = {}, o = {}, i = {}, [c, d] = Je({ metadata: _, state: N, watchers: o, synced: te, sentUpdates: i, environment: s });
1064
- async function p(f) {
1065
- const E = f.requestId || ie();
1050
+ const r = new Promise((p) => t = p), n = {}, o = {}, s = {}, [c, d] = qe({ metadata: y, state: E, watchers: o, synced: Y, sentUpdates: s, environment: a });
1051
+ async function w(p) {
1052
+ const A = p.requestId || ne();
1066
1053
  e += 1;
1067
- const S = window.opener ? window.opener : window.parent;
1054
+ const T = window.opener ? window.opener : window.parent;
1068
1055
  try {
1069
- return S.postMessage({
1070
- ...f,
1056
+ return T.postMessage({
1057
+ ...p,
1071
1058
  session: await r,
1072
- requestId: E,
1059
+ requestId: A,
1073
1060
  index: e
1074
- }, "*"), new Promise((P, x) => {
1075
- n[E] = { resolve: P, reject: x };
1061
+ }, "*"), new Promise((R, P) => {
1062
+ n[A] = { resolve: R, reject: P };
1076
1063
  });
1077
- } catch (P) {
1078
- console.log("ERROR POSTING MESSAGE UP", f, P);
1064
+ } catch (R) {
1065
+ console.log("ERROR POSTING MESSAGE UP", p, R);
1079
1066
  }
1080
1067
  }
1081
- let l = !1;
1082
- addEventListener("message", async ({ data: f }) => {
1083
- if (f.type === "setup" && !l)
1084
- l = !0, t(f.session);
1068
+ let u = !1;
1069
+ addEventListener("message", async ({ data: p }) => {
1070
+ if (p.type === "setup" && !u)
1071
+ u = !0, t(p.session);
1085
1072
  else {
1086
- if (!l || f.session !== await r) return;
1087
- if (n[f.requestId]) {
1088
- const { resolve: E, reject: S } = n[f.requestId];
1089
- f.error ? S(f.error) : E(f.response);
1090
- } else if (f.ii !== void 0) {
1091
- const { scope: E, user: S, domain: P } = f, { auth: x, domain: J } = await s(), b = !P || P === J ? "" : P, B = !S || x.user === S ? "" : S, H = Q(E) ? E : `${b}/${B}/${E}`, z = () => {
1092
- i[H] = f.ii, o[H].forEach((Z) => Z(f));
1073
+ if (!u || p.session !== await r) return;
1074
+ if (n[p.requestId]) {
1075
+ const { resolve: A, reject: T } = n[p.requestId];
1076
+ p.error ? T(p.error) : A(p.response);
1077
+ } else if (p.ii !== void 0) {
1078
+ const { scope: A, user: T, domain: R } = p, { auth: P, domain: H } = await a(), q = !R || R === H ? "" : R, Q = !T || P.user === T ? "" : T, J = k(A) ? A : `${q}/${Q}/${A}`, B = () => {
1079
+ s[J] = p.ii, o[J].forEach((K) => K(p));
1093
1080
  };
1094
- o[H] && (i[H] === void 0 || i[H] + 1 === f.ii ? z() : f.ii === i[H] || f.ii < i[H] || z());
1081
+ o[J] && (s[J] === void 0 || s[J] + 1 === p.ii ? B() : p.ii === s[J] || p.ii < s[J] || B());
1095
1082
  }
1096
1083
  }
1097
1084
  });
1098
- let a;
1099
- async function s(f) {
1100
- const E = await p({ type: "environment", user: f });
1101
- return a || (a = E.variables), { ...E, variables: a };
1102
- }
1103
- function v({ id: f = ie(), active_type: E, active: S }) {
1104
- return E || (E = "application/json"), I(f, [
1105
- { op: "add", path: ["active_type"], value: E },
1106
- { op: "add", path: ["active"], value: S }
1107
- ]), f;
1108
- }
1109
- const u = {};
1110
- async function g(f, E) {
1111
- const S = u[f];
1112
- S && S[E] || (Q(E) || (E = (await _(E)).id), u[f] || (u[f] = {}), !u[f][E] && (u[f][E] = !0, await L(f, E)));
1113
- }
1114
- async function h(f, E) {
1115
- return p({ type: "patch", root: f, scopes: E });
1116
- }
1117
- async function N(f, E, S) {
1118
- if (f === void 0) {
1119
- const { context: x } = await s();
1120
- f = JSON.stringify(x);
1085
+ let i;
1086
+ async function a(p) {
1087
+ const A = await w({ type: "environment", user: p });
1088
+ return i || (i = A.variables), { ...A, variables: i };
1089
+ }
1090
+ function h({ id: p = ne(), active_type: A, active: T }) {
1091
+ return A || (A = "application/json"), g(p, [
1092
+ { op: "add", path: ["active_type"], value: A },
1093
+ { op: "add", path: ["active"], value: T }
1094
+ ]), p;
1095
+ }
1096
+ async function l(p, A) {
1097
+ return w({ type: "patch", root: p, scopes: A });
1098
+ }
1099
+ async function E(p, A, T) {
1100
+ if (p === void 0) {
1101
+ const { context: P } = await a();
1102
+ p = JSON.stringify(P);
1121
1103
  }
1122
- g("subscribed", f);
1123
- const P = await p({ type: "state", scope: f, user: E, domain: S });
1124
- return new ce(P, (x) => {
1125
- const J = structuredClone(x);
1126
- J.forEach((b) => b.path.unshift("active")), I(f, J);
1104
+ const R = await w({ type: "state", scope: p, user: A, domain: T });
1105
+ return new se(R, (P) => {
1106
+ const H = structuredClone(P);
1107
+ H.forEach((q) => q.path.unshift("active")), g(p, H);
1127
1108
  });
1128
1109
  }
1129
- function O(f) {
1130
- return I(f, [{ op: "add", path: ["active"], value: null }]);
1110
+ function v(p) {
1111
+ return g(p, [{ op: "add", path: ["active"], value: null }]);
1131
1112
  }
1132
- function I(f, E, S = !0) {
1133
- return S && g("mutated", f), p({ type: "interact", scope: f, patch: E });
1113
+ function g(p, A, T, R) {
1114
+ return w({ type: "interact", scope: p, patch: A, context: R });
1134
1115
  }
1135
- async function m(f) {
1136
- let { name: E, type: S, data: P, id: x = ie() } = f || {};
1137
- const J = await p({ type: "upload", info: { name: E, type: S, id: x } });
1138
- if (P === void 0) return J;
1116
+ async function O(p) {
1117
+ let { name: A, type: T, data: R, id: P = ne() } = p || {};
1118
+ const H = await w({ type: "upload", info: { name: A, type: T, id: P } });
1119
+ if (R === void 0) return H;
1139
1120
  {
1140
- const B = await fetch(J, { method: "PUT", headers: { "Content-Type": S }, body: P }), { ok: H, statusText: z } = B;
1141
- if (H) return x;
1142
- throw new Error(z);
1121
+ const Q = await fetch(H, { method: "PUT", headers: { "Content-Type": T }, body: R }), { ok: J, statusText: B } = Q;
1122
+ if (J) return P;
1123
+ throw new Error(B);
1143
1124
  }
1144
1125
  }
1145
- function A(f) {
1146
- let E = "fetch";
1147
- const S = new Promise(async (P, x) => {
1148
- const J = await p({ type: "download", id: f });
1149
- if (await new Promise((b) => setTimeout(b)), E === "url") P(J);
1150
- else if (E === "fetch") {
1151
- const b = await fetch(J), { ok: B, statusText: H } = b;
1152
- B ? P(b) : x(H);
1153
- } else if (E === "direct") {
1154
- const b = await A(f), { name: B } = await _(f), H = b.headers.get("Content-Type"), z = new Blob([await b.blob()], { type: H }), Z = window.URL.createObjectURL(z), X = document.createElement("a");
1155
- X.style.display = "none", X.href = Z, X.download = B, document.body.appendChild(X), X.click(), window.URL.revokeObjectURL(Z), P();
1126
+ function I(p) {
1127
+ let A = "fetch";
1128
+ const T = new Promise(async (R, P) => {
1129
+ const H = await w({ type: "download", id: p });
1130
+ if (await new Promise((q) => setTimeout(q)), A === "url") R(H);
1131
+ else if (A === "fetch") {
1132
+ const q = await fetch(H), { ok: Q, statusText: J } = q;
1133
+ Q ? R(q) : P(J);
1134
+ } else if (A === "direct") {
1135
+ const q = await I(p), { name: Q } = await y(p), J = q.headers.get("Content-Type"), B = new Blob([await q.blob()], { type: J }), K = window.URL.createObjectURL(B), Z = document.createElement("a");
1136
+ Z.style.display = "none", Z.href = K, Z.download = Q, document.body.appendChild(Z), Z.click(), window.URL.revokeObjectURL(K), R();
1156
1137
  }
1157
1138
  });
1158
- return S.direct = () => (E = "direct", S), S.url = () => (E = "url", S), S;
1159
- }
1160
- function R({ path: f, op: E, value: S }) {
1161
- return ["active_type", "name"].includes(f[0]) && f.length === 1 && typeof S == "string" || E === "remove";
1162
- }
1163
- async function _(f, E, S) {
1164
- const P = await p({ type: "metadata", scope: f, user: E, domain: S });
1165
- return new ce(P, (x) => {
1166
- const J = structuredClone(x);
1167
- J.forEach((b) => {
1168
- if (!R(b)) throw new Error("You may only modify the type or name for a scope's metadata");
1169
- }), I(f, J);
1139
+ return T.direct = () => (A = "direct", T), T.url = () => (A = "url", T), T;
1140
+ }
1141
+ function m({ path: p, op: A, value: T }) {
1142
+ return ["active_type", "name"].includes(p[0]) && p.length === 1 && typeof T == "string" || A === "remove";
1143
+ }
1144
+ async function y(p, A, T) {
1145
+ const R = await w({ type: "metadata", scope: p, user: A, domain: T });
1146
+ return new se(R, (P) => {
1147
+ const H = structuredClone(P);
1148
+ H.forEach((q) => {
1149
+ if (!m(q)) throw new Error("You may only modify the type or name for a scope's metadata");
1150
+ }), g(p, H);
1170
1151
  });
1171
1152
  }
1172
- function L(f, E, S = []) {
1173
- return p({ type: "tag", tag_type: f, target: E, context: S });
1153
+ function N(p, A, T) {
1154
+ return w({ type: "login", provider: p, username: A, password: T });
1174
1155
  }
1175
- function q(f, E, S) {
1176
- return p({ type: "login", provider: f, username: E, password: S });
1156
+ function _(p, A, T, R = []) {
1157
+ return w({ type: "query", query: p, params: A, domain: T, context: R });
1177
1158
  }
1178
- function G(f, E, S, P = []) {
1179
- return p({ type: "query", query: f, params: E, domain: S, context: P });
1159
+ function M() {
1160
+ return w({ type: "logout" });
1180
1161
  }
1181
- function V() {
1182
- return p({ type: "logout" });
1162
+ function $() {
1163
+ return w({ type: "disconnect" });
1183
1164
  }
1184
- function K() {
1185
- return p({ type: "disconnect" });
1186
- }
1187
- function W() {
1188
- return p({ type: "reconnect" });
1165
+ function z() {
1166
+ return w({ type: "reconnect" });
1189
1167
  }
1190
- function te() {
1191
- return p({ type: "synced" });
1168
+ function Y() {
1169
+ return w({ type: "synced" });
1192
1170
  }
1193
- function ee(f) {
1194
- return p({ type: "close", info: f });
1171
+ function X(p) {
1172
+ return w({ type: "close", info: p });
1195
1173
  }
1196
1174
  return {
1197
1175
  embedded: !0,
1198
- uuid: ie,
1199
- environment: s,
1200
- login: q,
1201
- logout: V,
1202
- create: v,
1203
- state: N,
1176
+ uuid: ne,
1177
+ environment: a,
1178
+ login: N,
1179
+ logout: M,
1180
+ create: h,
1181
+ state: E,
1204
1182
  watch: c,
1205
- upload: m,
1206
- download: A,
1207
- interact: I,
1208
- patch: h,
1209
- reset: O,
1210
- metadata: _,
1211
- disconnect: K,
1212
- reconnect: W,
1213
- synced: te,
1214
- close: ee,
1215
- query: G,
1216
- tag: L
1183
+ upload: O,
1184
+ download: I,
1185
+ interact: g,
1186
+ patch: l,
1187
+ reset: v,
1188
+ metadata: y,
1189
+ disconnect: $,
1190
+ reconnect: z,
1191
+ synced: Y,
1192
+ close: X,
1193
+ query: _
1217
1194
  };
1218
1195
  }
1219
- async function Ut({ accept: e }) {
1196
+ async function Pt({ accept: e }) {
1220
1197
  return new Promise((t, r) => {
1221
1198
  const n = document.createElement("input");
1222
1199
  n.type = "file", n.accept = e, n.addEventListener("change", async (o) => {
1223
- const i = o.target.files[0];
1224
- t(i || null);
1200
+ const s = o.target.files[0];
1201
+ t(s || null);
1225
1202
  }), n.click();
1226
1203
  });
1227
1204
  }
1228
- let U = window.__default_knowlearning_agent;
1229
- function Te(e, t) {
1205
+ let x = window.__default_knowlearning_agent;
1206
+ function Oe(e, t) {
1230
1207
  const r = (e == null ? void 0 : e.allow) || [], n = typeof e == "string" ? e : e == null ? void 0 : e.prefix;
1231
- return n && !Q(t) && !r.some((o) => t.startsWith(o)) ? `${n}/${t}` : t;
1208
+ return n && !k(t) && !r.some((o) => t.startsWith(o)) ? `${n}/${t}` : t;
1232
1209
  }
1233
- function Be(e = {}) {
1234
- if (U && !e.unique) return U;
1210
+ function He(e = {}) {
1211
+ if (x && !e.unique) return x;
1235
1212
  let t;
1236
1213
  try {
1237
1214
  t = window.self !== window.top;
1238
1215
  } catch {
1239
1216
  t = !0;
1240
1217
  }
1241
- const r = t && !e.root ? Lt() : Dt(e);
1242
- r.embed = Mt;
1218
+ const r = t && !e.root ? Rt() : _t(e);
1219
+ r.embed = Ct;
1243
1220
  const n = r.upload;
1244
1221
  return r.upload = async (o) => {
1245
1222
  if (o != null && o.browser) {
1246
- const i = await Ut(o);
1247
- if (!i || o.validate && !await o.validate(i)) return;
1248
- o.data = await i.arrayBuffer(), o.name || (o.name = i.name), o.type || (o.type = i.type);
1223
+ const s = await Pt(o);
1224
+ if (!s || o.validate && !await o.validate(s)) return;
1225
+ o.data = await s.arrayBuffer(), o.name || (o.name = s.name), o.type || (o.type = s.type);
1249
1226
  }
1250
1227
  return n(o);
1251
- }, U || (window.__default_knowlearning_agent = U = r), r;
1228
+ }, x || (window.__default_knowlearning_agent = x = r), r;
1252
1229
  }
1253
- const de = (e) => JSON.parse(JSON.stringify(e));
1254
- function Mt(e, t) {
1230
+ const fe = (e) => JSON.parse(JSON.stringify(e));
1231
+ function Ct(e, t) {
1255
1232
  const r = {}, n = [], o = {};
1256
- let i = !1, c = !1;
1257
- const d = ie(), p = (h) => new Promise((N, O) => {
1258
- const I = { ...de(h), session: d };
1259
- n.push({ message: I, sent: N }), i && l();
1260
- }), l = () => {
1233
+ let s = !1, c = !1;
1234
+ const d = ne(), w = (v) => new Promise((g, O) => {
1235
+ const I = { ...fe(v), session: d };
1236
+ n.push({ message: I, sent: g }), s && u();
1237
+ }), u = () => {
1261
1238
  for (; t.parentNode && n.length; ) {
1262
- const { message: h, sent: N } = n.shift();
1263
- t.contentWindow.postMessage(h, "*"), N();
1239
+ const { message: v, sent: g } = n.shift();
1240
+ t.contentWindow.postMessage(v, "*"), g();
1264
1241
  }
1265
- }, a = async (h) => {
1266
- const { requestId: N, type: O } = h, I = (m, A) => p({ requestId: N, response: m, error: A });
1242
+ }, i = async (v) => {
1243
+ const { requestId: g, type: O } = v, I = (m, y) => w({ requestId: g, response: m, error: y });
1267
1244
  if (O === "error")
1268
- console.error(h), I({});
1245
+ console.error(v), I({});
1269
1246
  else if (O === "close")
1270
- o.close && o.close(h.info);
1247
+ o.close && o.close(v.info);
1271
1248
  else if (O === "environment") {
1272
- const { user: m } = h, { mode: A, variables: R = {} } = e, _ = await (o.environment ? o.environment(m) : U.environment(m));
1249
+ const { user: m } = v, { mode: y, variables: N = {} } = e, _ = await (o.environment ? o.environment(m) : x.environment(m));
1273
1250
  I({
1274
1251
  ..._,
1275
1252
  context: [
@@ -1278,79 +1255,76 @@ function Mt(e, t) {
1278
1255
  ],
1279
1256
  variables: {
1280
1257
  ..._.variables || {},
1281
- ...R
1258
+ ...N
1282
1259
  },
1283
- mode: A
1260
+ mode: y
1284
1261
  // TODO: deprecate
1285
1262
  });
1286
1263
  } else if (O === "interact") {
1287
- let { scope: m, patch: A } = h;
1288
- const R = Te(e.namespace, m);
1289
- let _, L;
1290
- if (o.mutate && (_ = de(await U.state(R))), await U.interact(R, A, !1), o.mutate && (L = de(await U.state(R))), o.mutate) {
1291
- const q = de(A);
1292
- q.forEach((G) => G.path.shift()), o.mutate({
1293
- scope: R,
1294
- before: _,
1295
- after: L,
1296
- patch: q
1264
+ let { scope: m, patch: y, context: N = [] } = v;
1265
+ const _ = Oe(e.namespace, m);
1266
+ let M;
1267
+ if (o.mutate && (M = fe(await x.state(_))), await x.interact(_, y, !0, [e.id, ...N]), o.mutate) {
1268
+ const $ = fe(y);
1269
+ $.forEach((z) => z.path.shift()), o.mutate({
1270
+ scope: _,
1271
+ before: M,
1272
+ after: fe(await x.state(_)),
1273
+ patch: $
1297
1274
  });
1298
1275
  }
1299
1276
  I({});
1300
1277
  } else if (O === "metadata") {
1301
- const { scope: m, user: A, domain: R } = h, _ = Te(e.namespace, m);
1302
- I(await U.metadata(_, A, R));
1303
- } else if (O === "tag") {
1304
- const { tag_type: m, target: A, context: R } = h, _ = [e.id, ...R];
1305
- I(await U.tag(m, A, _));
1278
+ const { scope: m, user: y, domain: N } = v, _ = Oe(e.namespace, m);
1279
+ I(await x.metadata(_, y, N));
1306
1280
  } else if (O === "state") {
1307
- const { scope: m, user: A, domain: R } = h, _ = Te(e.namespace, m), L = U.state(_, A, R), q = `${R || ""}/${A || ""}/${_}`;
1308
- r[q] || (r[q] = U.watch(_, (G) => p({ ...G, scope: m }), A, R)), o.state && o.state({ scope: m }), I(await L);
1281
+ const { scope: m, user: y, domain: N } = v, _ = Oe(e.namespace, m), M = x.state(_, y, N), $ = `${N || ""}/${y || ""}/${_}`;
1282
+ r[$] || (r[$] = x.watch(_, (z) => w({ ...z, scope: m }), y, N)), o.state && o.state({ scope: m }), I(await M);
1309
1283
  } else if (O === "patch") {
1310
- const { root: m, scopes: A } = h;
1311
- I(await U.patch(m, A));
1284
+ const { root: m, scopes: y } = v;
1285
+ I(await x.patch(m, y));
1312
1286
  } else if (O === "query") {
1313
- const { query: m, params: A, domain: R, context: _ = [] } = h;
1314
- U.query(m, A, R, [e.id, ..._]).then(I).catch((L) => I(null, L.error));
1287
+ const { query: m, params: y, domain: N, context: _ = [] } = v;
1288
+ x.query(m, y, N, [e.id, ..._]).then(I).catch((M) => I(null, M.error));
1315
1289
  } else if (O === "upload") {
1316
- const { info: m } = h;
1317
- I(await U.upload(m));
1290
+ const { info: m } = v;
1291
+ I(await x.upload(m));
1318
1292
  } else if (O === "download")
1319
- I(await U.download(h.id).url());
1293
+ I(await x.download(v.id).url());
1320
1294
  else if (O === "login") {
1321
- const { provider: m, username: A, password: R } = h;
1322
- I(await U.login(m, A, R));
1323
- } else O === "logout" ? U.logout() : O === "disconnect" ? I(await U.disconnect()) : O === "reconnect" ? I(await U.reconnect()) : O === "synced" ? I(await U.synced()) : (console.log("Unknown message type passed up...", h), I({}));
1295
+ const { provider: m, username: y, password: N } = v;
1296
+ I(await x.login(m, y, N));
1297
+ } else O === "logout" ? x.logout() : O === "disconnect" ? I(await x.disconnect()) : O === "reconnect" ? I(await x.reconnect()) : O === "synced" ? I(await x.synced()) : (console.log("Unknown message type passed up...", v), I({}));
1324
1298
  };
1325
- window.addEventListener("message", ({ data: h }) => {
1326
- h.session === d && (c = !0, a(h));
1299
+ window.addEventListener("message", ({ data: v }) => {
1300
+ v.session === d && (c = !0, i(v));
1327
1301
  }), t.onload = () => {
1328
- i = !0, l();
1329
- }, s();
1330
- async function s() {
1331
- Be();
1332
- const { protocol: h } = window.location, { id: N } = e;
1333
- if (Q(N)) {
1334
- const { domain: O } = await U.metadata(N);
1335
- t.src = `${h}//${O}/${N}`;
1336
- } else t.src = N;
1302
+ s = !0, u();
1303
+ }, a();
1304
+ async function a() {
1305
+ He();
1306
+ const { protocol: v } = window.location, { id: g } = e;
1307
+ if (k(g)) {
1308
+ const { domain: O } = await x.metadata(g);
1309
+ t.src = `${v}//${O}/${g}`;
1310
+ } else t.src = g;
1337
1311
  for (; !c; )
1338
- p({ type: "setup", session: d }), await new Promise((O) => setTimeout(O, 100));
1312
+ w({ type: "setup", session: d }), await new Promise((O) => setTimeout(O, 100));
1339
1313
  o.open && o.open();
1340
1314
  }
1341
- function v() {
1315
+ function h() {
1342
1316
  t.parentNode && t.parentNode.removeChild(t);
1343
1317
  }
1344
- function u(h, N) {
1345
- o[h] = N;
1318
+ function l(v, g) {
1319
+ o[v] = g;
1346
1320
  }
1347
- function g(h, N) {
1348
- p({ type: "auth", token: h, state: N });
1321
+ function E(v, g) {
1322
+ w({ type: "auth", token: v, state: g });
1349
1323
  }
1350
1324
  return {
1351
- auth: g,
1352
- remove: v,
1353
- on: u
1325
+ auth: E,
1326
+ remove: h,
1327
+ on: l
1354
1328
  };
1355
1329
  }
1356
- window.Agent = Be();
1330
+ window.Agent = He();