@knowlearning/agents 0.9.171 → 0.9.172
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/agents/browser/embedded.js +3 -26
- package/agents/browser/initialize.js +3 -9
- package/agents/generic/index.js +6 -34
- package/agents/generic/message-queue.js +2 -2
- package/agents/generic/state.js +2 -2
- package/deno.js +1 -1
- package/dist/browser.js +727 -753
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
var
|
|
2
|
-
function
|
|
3
|
-
if (!
|
|
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
|
|
5
|
+
return ie(je);
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
return typeof e == "string" &&
|
|
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
|
|
13
|
-
j.push((
|
|
14
|
-
function
|
|
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 (!
|
|
16
|
+
if (!k(r))
|
|
17
17
|
throw TypeError("Stringified UUID is invalid");
|
|
18
18
|
return r;
|
|
19
19
|
}
|
|
20
|
-
var
|
|
21
|
-
function
|
|
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
|
|
25
|
-
if (
|
|
26
|
-
var d = e.random || (e.rng ||
|
|
27
|
-
|
|
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
|
|
30
|
-
if (
|
|
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
|
-
|
|
33
|
-
var
|
|
34
|
-
o[n++] =
|
|
35
|
-
var
|
|
36
|
-
o[n++] =
|
|
37
|
-
for (var
|
|
38
|
-
o[n +
|
|
39
|
-
return t ||
|
|
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
|
|
41
|
+
function Fe(e, t, r) {
|
|
42
42
|
e = e || {};
|
|
43
|
-
var n = e.random || (e.rng ||
|
|
44
|
-
return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128,
|
|
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
|
|
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
|
|
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
|
-
}(),
|
|
67
|
-
function
|
|
68
|
-
return
|
|
66
|
+
}(), Qe = Object.prototype.hasOwnProperty;
|
|
67
|
+
function ge(e, t) {
|
|
68
|
+
return Qe.call(e, t);
|
|
69
69
|
}
|
|
70
|
-
function
|
|
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
|
-
|
|
80
|
+
ge(e, o) && n.push(o);
|
|
81
81
|
return n;
|
|
82
82
|
}
|
|
83
|
-
function
|
|
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
|
|
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
|
|
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
|
|
108
|
+
function be(e) {
|
|
109
109
|
return e.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
110
110
|
}
|
|
111
|
-
function
|
|
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 (
|
|
117
|
+
if (Se(e[t]))
|
|
118
118
|
return !0;
|
|
119
119
|
} else if (typeof e == "object") {
|
|
120
|
-
for (var n =
|
|
121
|
-
if (
|
|
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
|
|
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
|
|
136
|
+
var xe = (
|
|
137
137
|
/** @class */
|
|
138
138
|
function(e) {
|
|
139
|
-
|
|
140
|
-
function t(r, n, o,
|
|
141
|
-
var d = this.constructor,
|
|
142
|
-
return
|
|
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
|
-
),
|
|
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 =
|
|
160
|
-
n && (n =
|
|
161
|
-
var o =
|
|
162
|
-
return
|
|
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 =
|
|
166
|
-
return
|
|
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:
|
|
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
|
-
},
|
|
174
|
+
}, We = {
|
|
175
175
|
add: function(e, t, r) {
|
|
176
|
-
return
|
|
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:
|
|
187
|
-
copy:
|
|
188
|
-
test:
|
|
189
|
-
_get:
|
|
186
|
+
move: re.move,
|
|
187
|
+
copy: re.copy,
|
|
188
|
+
test: re.test,
|
|
189
|
+
_get: re._get
|
|
190
190
|
};
|
|
191
|
-
function
|
|
191
|
+
function ue(e, t) {
|
|
192
192
|
if (t == "")
|
|
193
193
|
return e;
|
|
194
194
|
var r = { op: "_get", path: t };
|
|
195
|
-
return
|
|
195
|
+
return te(e, r), r.value;
|
|
196
196
|
}
|
|
197
|
-
function
|
|
198
|
-
if (r === void 0 && (r = !1), n === void 0 && (n = !0), o === void 0 && (o = !0),
|
|
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 =
|
|
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 =
|
|
208
|
-
throw new
|
|
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
|
|
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 =
|
|
221
|
-
var d = t.path || "",
|
|
222
|
-
for (typeof r == "function" ?
|
|
223
|
-
if (
|
|
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 &&
|
|
226
|
-
if (
|
|
227
|
-
|
|
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 && !
|
|
230
|
-
throw new
|
|
231
|
-
|
|
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 (
|
|
234
|
-
if (r && t.op === "add" &&
|
|
235
|
-
throw new
|
|
236
|
-
var c =
|
|
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
|
|
238
|
+
throw new U("Test operation failed", "TEST_OPERATION_FAILED", s, t, e);
|
|
239
239
|
return c;
|
|
240
240
|
}
|
|
241
|
-
} else if (
|
|
242
|
-
var c =
|
|
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
|
|
244
|
+
throw new U("Test operation failed", "TEST_OPERATION_FAILED", s, t, e);
|
|
245
245
|
return c;
|
|
246
246
|
}
|
|
247
|
-
if (
|
|
248
|
-
throw new
|
|
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
|
|
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
|
|
255
|
-
n || (e =
|
|
256
|
-
for (var
|
|
257
|
-
|
|
258
|
-
return
|
|
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
|
|
261
|
-
var n =
|
|
260
|
+
function Ye(e, t, r) {
|
|
261
|
+
var n = te(e, t);
|
|
262
262
|
if (n.test === !1)
|
|
263
|
-
throw new
|
|
263
|
+
throw new U("Test operation failed", "TEST_OPERATION_FAILED", r, t, e);
|
|
264
264
|
return n.newDocument;
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function le(e, t, r, n) {
|
|
267
267
|
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
268
|
-
throw new
|
|
269
|
-
if (
|
|
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
|
|
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
|
|
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
|
|
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
|
|
278
|
-
if ((e.op === "add" || e.op === "replace" || e.op === "test") &&
|
|
279
|
-
throw new
|
|
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,
|
|
283
|
-
if (o !==
|
|
284
|
-
throw new
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
296
|
+
function $e(e, t, r) {
|
|
297
297
|
try {
|
|
298
298
|
if (!Array.isArray(e))
|
|
299
|
-
throw new
|
|
299
|
+
throw new U("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
300
300
|
if (t)
|
|
301
|
-
|
|
301
|
+
de(F(t), F(e), r || !0);
|
|
302
302
|
else {
|
|
303
|
-
r = r ||
|
|
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
|
|
308
|
+
if (o instanceof U)
|
|
309
309
|
return o;
|
|
310
310
|
throw o;
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
function
|
|
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,
|
|
317
|
+
var r = Array.isArray(e), n = Array.isArray(t), o, s, c;
|
|
318
318
|
if (r && n) {
|
|
319
|
-
if (
|
|
319
|
+
if (s = e.length, s != t.length)
|
|
320
320
|
return !1;
|
|
321
|
-
for (o =
|
|
322
|
-
if (!
|
|
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 (
|
|
329
|
+
if (s = d.length, s !== Object.keys(t).length)
|
|
330
330
|
return !1;
|
|
331
|
-
for (o =
|
|
331
|
+
for (o = s; o-- !== 0; )
|
|
332
332
|
if (!t.hasOwnProperty(d[o]))
|
|
333
333
|
return !1;
|
|
334
|
-
for (o =
|
|
335
|
-
if (c = d[o], !
|
|
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
|
|
341
|
+
const Ze = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
342
342
|
__proto__: null,
|
|
343
|
-
JsonPatchError:
|
|
344
|
-
_areEquals:
|
|
345
|
-
applyOperation:
|
|
346
|
-
applyPatch:
|
|
347
|
-
applyReducer:
|
|
348
|
-
deepClone:
|
|
349
|
-
getValueByPointer:
|
|
350
|
-
validate:
|
|
351
|
-
validator:
|
|
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
|
|
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
|
-
),
|
|
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
|
|
376
|
-
return
|
|
375
|
+
function Ve(e) {
|
|
376
|
+
return _e.get(e);
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function et(e, t) {
|
|
379
379
|
return e.observers.get(t);
|
|
380
380
|
}
|
|
381
|
-
function
|
|
381
|
+
function tt(e, t) {
|
|
382
382
|
e.observers.delete(t.callback);
|
|
383
383
|
}
|
|
384
|
-
function
|
|
384
|
+
function nt(e, t) {
|
|
385
385
|
t.unobserve();
|
|
386
386
|
}
|
|
387
|
-
function
|
|
388
|
-
var r = [], n, o =
|
|
387
|
+
function rt(e, t) {
|
|
388
|
+
var r = [], n, o = Ve(e);
|
|
389
389
|
if (!o)
|
|
390
|
-
o = new
|
|
390
|
+
o = new ke(e), _e.set(e, o);
|
|
391
391
|
else {
|
|
392
|
-
var
|
|
393
|
-
n =
|
|
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 =
|
|
397
|
+
if (n = {}, o.value = F(e), t) {
|
|
398
398
|
n.callback = t, n.next = null;
|
|
399
399
|
var c = function() {
|
|
400
|
-
|
|
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
|
-
|
|
408
|
-
}, o.observers.set(t, new
|
|
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
|
|
410
|
+
function Ne(e, t) {
|
|
411
411
|
t === void 0 && (t = !1);
|
|
412
|
-
var r =
|
|
413
|
-
|
|
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
|
|
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
|
|
421
|
-
var
|
|
422
|
-
if (
|
|
423
|
-
var
|
|
424
|
-
typeof
|
|
425
|
-
} else Array.isArray(e) === Array.isArray(t) ? (o && r.push({ op: "test", path: n + "/" +
|
|
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 &&
|
|
428
|
-
for (var
|
|
429
|
-
var
|
|
430
|
-
!
|
|
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
|
|
434
|
+
function ot(e, t, r) {
|
|
435
435
|
r === void 0 && (r = !1);
|
|
436
436
|
var n = [];
|
|
437
|
-
return
|
|
437
|
+
return Re(e, t, n, "", r), n;
|
|
438
438
|
}
|
|
439
|
-
const
|
|
439
|
+
const st = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
440
440
|
__proto__: null,
|
|
441
|
-
compare:
|
|
442
|
-
generate:
|
|
443
|
-
observe:
|
|
444
|
-
unobserve:
|
|
441
|
+
compare: ot,
|
|
442
|
+
generate: Ne,
|
|
443
|
+
observe: rt,
|
|
444
|
+
unobserve: nt
|
|
445
445
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
446
|
-
Object.assign({},
|
|
447
|
-
JsonPatchError:
|
|
448
|
-
deepClone:
|
|
449
|
-
escapePathComponent:
|
|
450
|
-
unescapePathComponent:
|
|
446
|
+
Object.assign({}, Ze, st, {
|
|
447
|
+
JsonPatchError: xe,
|
|
448
|
+
deepClone: F,
|
|
449
|
+
escapePathComponent: ee,
|
|
450
|
+
unescapePathComponent: be
|
|
451
451
|
});
|
|
452
|
-
const
|
|
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
|
|
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
|
|
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 = `${
|
|
476
|
+
window.location.href = `${it}/${e}/${r}/${n}`;
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
|
-
function
|
|
479
|
+
function ft() {
|
|
480
480
|
window.localStorage.setItem("token", Math.random().toString(36).substring(2)), window.location.reload();
|
|
481
481
|
}
|
|
482
|
-
async function
|
|
482
|
+
async function ut() {
|
|
483
483
|
const e = localStorage.getItem("token");
|
|
484
484
|
return window.localStorage.removeItem("token"), e;
|
|
485
485
|
}
|
|
486
|
-
async function
|
|
486
|
+
async function lt(e, t) {
|
|
487
487
|
const r = await crypto.subtle.importKey(
|
|
488
488
|
"spki",
|
|
489
|
-
|
|
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),
|
|
498
|
-
{ name: "AES-GCM", iv:
|
|
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),
|
|
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(
|
|
507
|
+
encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(s)))),
|
|
508
508
|
encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(c)))),
|
|
509
|
-
encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(
|
|
509
|
+
encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(w))))
|
|
510
510
|
].join(",");
|
|
511
511
|
}
|
|
512
|
-
function
|
|
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
|
|
518
|
+
function pt(e) {
|
|
519
519
|
return e.map((t) => {
|
|
520
|
-
const r = { ...t, path: "/" + t.path.map(
|
|
521
|
-
return t.from && (r.from = "/" + t.from.map(
|
|
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
|
|
524
|
+
function De(e) {
|
|
525
525
|
return typeof e == "string" ? e.replaceAll("~", "~0").replaceAll("/", "~1") : e;
|
|
526
526
|
}
|
|
527
|
-
const
|
|
528
|
-
function
|
|
527
|
+
const Ee = /* @__PURE__ */ new Set(), ae = /* @__PURE__ */ new Map();
|
|
528
|
+
function ce(e) {
|
|
529
529
|
return `/${e.join("/")}`;
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function Le(e) {
|
|
532
532
|
return JSON.parse(JSON.stringify(e));
|
|
533
533
|
}
|
|
534
|
-
function
|
|
534
|
+
function wt(e, [t, r]) {
|
|
535
535
|
return Math.max(Math.min(parseInt(e), r), t);
|
|
536
536
|
}
|
|
537
|
-
function
|
|
538
|
-
if (r[
|
|
539
|
-
if (
|
|
540
|
-
throw new Error(`Cannot add mutable state to multiple mutable parents. Attempted Path: ${
|
|
541
|
-
const
|
|
542
|
-
|
|
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,
|
|
545
|
+
[...n, i]
|
|
546
546
|
), d = {
|
|
547
547
|
copyWithin() {
|
|
548
548
|
throw new Error('"copyWithin" not implemented.');
|
|
549
549
|
},
|
|
550
|
-
sort(
|
|
551
|
-
const
|
|
552
|
-
e.forEach((
|
|
553
|
-
|
|
554
|
-
}), e.sort(
|
|
555
|
-
let
|
|
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((
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
return
|
|
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,
|
|
564
|
-
path: [...n,
|
|
563
|
+
from: [...n, g],
|
|
564
|
+
path: [...n, E]
|
|
565
565
|
};
|
|
566
566
|
})
|
|
567
|
-
),
|
|
567
|
+
), u;
|
|
568
568
|
},
|
|
569
569
|
reverse() {
|
|
570
|
-
const
|
|
571
|
-
return e.forEach((
|
|
572
|
-
|
|
570
|
+
const i = [];
|
|
571
|
+
return e.forEach((a, h) => {
|
|
572
|
+
i.push({
|
|
573
573
|
op: "move",
|
|
574
|
-
from: [...n,
|
|
574
|
+
from: [...n, h],
|
|
575
575
|
path: [...n, 0]
|
|
576
576
|
});
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
}), e.reverse(), t(
|
|
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(
|
|
588
|
-
const
|
|
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 ?
|
|
591
|
-
const
|
|
592
|
-
{ length:
|
|
593
|
-
() => ({ op: "remove", path:
|
|
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
|
-
|
|
596
|
-
|
|
595
|
+
h.forEach((m, y) => {
|
|
596
|
+
v.push({
|
|
597
597
|
op: "add",
|
|
598
|
-
path: [...n,
|
|
599
|
-
value:
|
|
598
|
+
path: [...n, i + y],
|
|
599
|
+
value: Le(m)
|
|
600
600
|
});
|
|
601
601
|
});
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
const
|
|
605
|
-
|
|
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 =
|
|
608
|
-
(m,
|
|
609
|
-
), I = e.splice(
|
|
610
|
-
return t(
|
|
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(([,
|
|
614
|
-
|
|
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
|
|
617
|
-
set(
|
|
618
|
-
if (
|
|
619
|
-
if (/^\d+$/.test(
|
|
620
|
-
|
|
621
|
-
else return a
|
|
622
|
-
const
|
|
623
|
-
if (r[
|
|
624
|
-
return a
|
|
625
|
-
if (
|
|
626
|
-
throw new Error(`Setting properties to undefined is not supported. Please use a delete statement. Attempted to set ${
|
|
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
|
|
629
|
-
value:
|
|
628
|
+
op: i[a] === void 0 ? "add" : "replace",
|
|
629
|
+
value: Le(h),
|
|
630
630
|
// TODO: more efficient sanitization
|
|
631
|
-
path:
|
|
632
|
-
}]),
|
|
631
|
+
path: l
|
|
632
|
+
}]), h instanceof Object ? i[a] = c(a, h) : i[a] = h, !0;
|
|
633
633
|
},
|
|
634
|
-
deleteProperty(
|
|
635
|
-
if (
|
|
636
|
-
if (
|
|
637
|
-
if (/^\d+$/.test(
|
|
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
|
|
640
|
-
r[
|
|
639
|
+
const h = [...n, a];
|
|
640
|
+
r[ce(h)] || t([{ op: "remove", path: h }]);
|
|
641
641
|
}
|
|
642
642
|
return !0;
|
|
643
643
|
},
|
|
644
|
-
get(
|
|
645
|
-
return
|
|
644
|
+
get(i, a, h) {
|
|
645
|
+
return s && d[a] ? d[a] : i[a];
|
|
646
646
|
}
|
|
647
|
-
},
|
|
648
|
-
return
|
|
647
|
+
}, u = new Proxy(e, w);
|
|
648
|
+
return Ee.add(u), ae.set(u, n), u;
|
|
649
649
|
}
|
|
650
|
-
const
|
|
651
|
-
function
|
|
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
|
|
655
|
-
let
|
|
656
|
-
const
|
|
657
|
-
let
|
|
658
|
-
const
|
|
659
|
-
let
|
|
660
|
-
const
|
|
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
|
|
666
|
-
return { variables:
|
|
665
|
+
async function P() {
|
|
666
|
+
return { variables: h, ...await T, context: [] };
|
|
667
667
|
}
|
|
668
|
-
function
|
|
669
|
-
if (
|
|
670
|
-
const
|
|
671
|
-
|
|
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,
|
|
674
|
-
return
|
|
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
|
|
677
|
-
for (await new Promise((
|
|
678
|
-
|
|
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
|
-
|
|
681
|
-
} catch (
|
|
682
|
-
console.warn("ERROR SENDING OVER CONNECTION",
|
|
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
|
|
688
|
-
const
|
|
689
|
-
for (;
|
|
690
|
-
|
|
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"),
|
|
695
|
+
d("CLOSING DUE TO HEARTBEAT TIMEOUT"), B();
|
|
696
696
|
},
|
|
697
|
-
|
|
697
|
+
ht
|
|
698
698
|
);
|
|
699
699
|
}
|
|
700
|
-
async function
|
|
701
|
-
|
|
702
|
-
},
|
|
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
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
},
|
|
708
|
-
if (J(), !!
|
|
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 (
|
|
711
|
-
if (
|
|
710
|
+
if (f.error && console.warn("ERROR RESPONSE", f), v)
|
|
711
|
+
if (vt[f.type])
|
|
712
712
|
try {
|
|
713
|
-
|
|
713
|
+
i && i(f, a);
|
|
714
714
|
} catch {
|
|
715
|
-
d("ERROR HANDLING DOMAIN MESSAGE",
|
|
715
|
+
d("ERROR HANDLING DOMAIN MESSAGE", f);
|
|
716
716
|
}
|
|
717
|
-
else if (
|
|
718
|
-
|
|
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
|
|
721
|
-
if (o[
|
|
722
|
-
if (
|
|
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
|
-
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
const
|
|
728
|
-
|
|
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 (
|
|
734
|
-
|
|
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 (
|
|
737
|
-
console.error("ERROR HANDLING CONNECTION MESSAGE",
|
|
736
|
+
} catch (C) {
|
|
737
|
+
console.error("ERROR HANDLING CONNECTION MESSAGE", C, f);
|
|
738
738
|
}
|
|
739
|
-
},
|
|
740
|
-
d("CONNECTION ERROR",
|
|
741
|
-
},
|
|
742
|
-
d("CONNECTION CLOSURE",
|
|
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
|
|
746
|
-
const
|
|
747
|
-
return
|
|
745
|
+
async function Z() {
|
|
746
|
+
const f = new Promise((C) => X.push({ si: N, resolve: C }));
|
|
747
|
+
return Q(), f;
|
|
748
748
|
}
|
|
749
|
-
function
|
|
750
|
-
return new Promise((
|
|
749
|
+
function pe() {
|
|
750
|
+
return new Promise((f, C) => p[I].push([f, C]));
|
|
751
751
|
}
|
|
752
|
-
function
|
|
753
|
-
d("DISCONNECTED AGENT!!!!!!!!!!!!!!!"),
|
|
752
|
+
function S() {
|
|
753
|
+
d("DISCONNECTED AGENT!!!!!!!!!!!!!!!"), Y = !0, l.close({ keepalive: !0 });
|
|
754
754
|
}
|
|
755
|
-
function
|
|
756
|
-
d("RECONNECTED AGENT!!!!!!!!!!!!!!!"),
|
|
755
|
+
function D() {
|
|
756
|
+
d("RECONNECTED AGENT!!!!!!!!!!!!!!!"), Y = !1, B();
|
|
757
757
|
}
|
|
758
|
-
return
|
|
758
|
+
return K(), [H, pe, S, D, Z, P];
|
|
759
759
|
}
|
|
760
|
-
function
|
|
761
|
-
let
|
|
762
|
-
const
|
|
763
|
-
const { auth: { user:
|
|
764
|
-
if (!n[
|
|
765
|
-
const
|
|
766
|
-
n[
|
|
767
|
-
await new Promise((
|
|
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",
|
|
769
|
+
path: ["active", m, "subscriptions", N],
|
|
770
770
|
value: { scope: e, user: t, domain: r, ii: null }
|
|
771
|
-
}], !1
|
|
771
|
+
}], !1);
|
|
772
772
|
try {
|
|
773
|
-
|
|
774
|
-
} catch (
|
|
775
|
-
|
|
773
|
+
_(await w());
|
|
774
|
+
} catch ($) {
|
|
775
|
+
M($);
|
|
776
776
|
}
|
|
777
777
|
});
|
|
778
778
|
}
|
|
779
|
-
await
|
|
779
|
+
await u[y];
|
|
780
780
|
try {
|
|
781
|
-
const
|
|
782
|
-
delete
|
|
783
|
-
const
|
|
784
|
-
|
|
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
|
-
|
|
786
|
+
} catch (N) {
|
|
787
|
+
g(N);
|
|
788
788
|
}
|
|
789
789
|
});
|
|
790
|
-
return
|
|
790
|
+
return E.metadata = l, E;
|
|
791
791
|
}
|
|
792
|
-
const
|
|
793
|
-
function
|
|
794
|
-
function c(
|
|
795
|
-
if (Array.isArray(
|
|
796
|
-
const
|
|
797
|
-
let
|
|
798
|
-
return e(
|
|
799
|
-
const { auth: { user: O }, domain: I } = await t(), m = await
|
|
800
|
-
|
|
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
|
-
|
|
802
|
+
v = !0, E && w(E, i);
|
|
803
803
|
};
|
|
804
804
|
}
|
|
805
|
-
function d(
|
|
806
|
-
const
|
|
807
|
-
let
|
|
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(
|
|
810
|
-
if (
|
|
811
|
-
|
|
809
|
+
const O = c(l, ({ state: I }) => {
|
|
810
|
+
if (E.length === 0) {
|
|
811
|
+
i(I);
|
|
812
812
|
return;
|
|
813
813
|
}
|
|
814
|
-
|
|
814
|
+
v();
|
|
815
815
|
let m = I;
|
|
816
|
-
for (let
|
|
817
|
-
if (m = m[
|
|
818
|
-
else if (
|
|
819
|
-
|
|
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
|
-
},
|
|
822
|
+
}, a, h);
|
|
823
823
|
return () => {
|
|
824
|
-
O(),
|
|
824
|
+
O(), v();
|
|
825
825
|
};
|
|
826
826
|
}
|
|
827
|
-
function
|
|
828
|
-
if (!n[
|
|
829
|
-
console.warn("NO WATCHERS FOR KEY",
|
|
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
|
|
833
|
-
|
|
832
|
+
const a = n[u].findIndex((h) => h === i);
|
|
833
|
+
a > -1 && n[u].splice(a, 1);
|
|
834
834
|
}
|
|
835
|
-
return [c,
|
|
835
|
+
return [c, w];
|
|
836
836
|
}
|
|
837
|
-
const
|
|
838
|
-
function
|
|
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:
|
|
840
|
+
active_type: Ot,
|
|
841
841
|
active: { id: e }
|
|
842
842
|
});
|
|
843
|
-
let
|
|
844
|
-
const c = new Promise(async (d,
|
|
845
|
-
const { url:
|
|
846
|
-
if (await new Promise((
|
|
847
|
-
else if (
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
} else if (
|
|
851
|
-
const
|
|
852
|
-
|
|
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 = () => (
|
|
855
|
+
return c.direct = () => (s = "direct", c), c.url = () => (s = "url", c), c;
|
|
856
856
|
}
|
|
857
|
-
const
|
|
858
|
-
function
|
|
859
|
-
const
|
|
860
|
-
|
|
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
|
-
|
|
865
|
-
|
|
866
|
-
_
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
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
|
|
873
|
-
keyToSubscriptionId:
|
|
874
|
-
watchers:
|
|
875
|
-
states:
|
|
876
|
-
state:
|
|
877
|
-
create:
|
|
878
|
-
environment:
|
|
879
|
-
lastInteractionResponse:
|
|
880
|
-
lastMessageResponse:
|
|
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:
|
|
884
|
-
synced:
|
|
885
|
-
metadata:
|
|
886
|
-
log:
|
|
887
|
-
}, [
|
|
888
|
-
function
|
|
889
|
-
return
|
|
890
|
-
}
|
|
891
|
-
function
|
|
892
|
-
return
|
|
893
|
-
}
|
|
894
|
-
function
|
|
895
|
-
}
|
|
896
|
-
function
|
|
897
|
-
|
|
898
|
-
}
|
|
899
|
-
function
|
|
900
|
-
|
|
901
|
-
const
|
|
902
|
-
{ op: "add", path: ["active_type"], value:
|
|
903
|
-
{ op: "add", path: ["active"], value:
|
|
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
|
|
906
|
-
}
|
|
907
|
-
async function
|
|
908
|
-
const C =
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
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:
|
|
919
|
-
if (
|
|
913
|
+
const { url: G } = await I();
|
|
914
|
+
if (C === void 0) return G;
|
|
920
915
|
{
|
|
921
|
-
const
|
|
922
|
-
if (
|
|
923
|
-
throw new Error(
|
|
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(
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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:
|
|
933
|
-
return { ii:
|
|
926
|
+
const { ii: L } = await b;
|
|
927
|
+
return { ii: L };
|
|
934
928
|
}
|
|
935
929
|
}
|
|
936
|
-
async function
|
|
937
|
-
const
|
|
938
|
-
return
|
|
939
|
-
id:
|
|
940
|
-
active_type:
|
|
941
|
-
active: { domain:
|
|
942
|
-
}),
|
|
943
|
-
}
|
|
944
|
-
function
|
|
945
|
-
return P(
|
|
946
|
-
}
|
|
947
|
-
function
|
|
948
|
-
return ["active_type", "name"].includes(
|
|
949
|
-
}
|
|
950
|
-
async function
|
|
951
|
-
const
|
|
952
|
-
return delete
|
|
953
|
-
const
|
|
954
|
-
if (!
|
|
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(
|
|
950
|
+
P(S, G);
|
|
957
951
|
});
|
|
958
952
|
}
|
|
959
|
-
async function
|
|
960
|
-
const
|
|
961
|
-
await new Promise((
|
|
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",
|
|
965
|
-
value: { query:
|
|
958
|
+
path: ["active", L, "queries", b],
|
|
959
|
+
value: { query: S, params: D, domain: f, context: C }
|
|
966
960
|
}
|
|
967
|
-
], !1
|
|
961
|
+
], !1);
|
|
968
962
|
try {
|
|
969
|
-
const
|
|
963
|
+
const W = await I(), { rows: V } = W;
|
|
970
964
|
return P("sessions", [
|
|
971
965
|
{
|
|
972
966
|
op: "add",
|
|
973
|
-
path: ["active",
|
|
974
|
-
value: Date.now() -
|
|
967
|
+
path: ["active", L, "queries", b, "agent_latency"],
|
|
968
|
+
value: Date.now() - G
|
|
975
969
|
},
|
|
976
970
|
{
|
|
977
971
|
op: "remove",
|
|
978
|
-
path: ["active",
|
|
972
|
+
path: ["active", L, "queries", b]
|
|
979
973
|
}
|
|
980
|
-
], !1
|
|
981
|
-
} catch (
|
|
982
|
-
throw
|
|
974
|
+
], !1), V;
|
|
975
|
+
} catch (W) {
|
|
976
|
+
throw W;
|
|
983
977
|
}
|
|
984
978
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
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
|
|
997
|
-
|
|
984
|
+
function pe(S, D) {
|
|
985
|
+
K[S].forEach((f) => f(D));
|
|
998
986
|
}
|
|
999
987
|
return {
|
|
1000
988
|
uuid: o,
|
|
1001
|
-
environment:
|
|
989
|
+
environment: _,
|
|
1002
990
|
login: d,
|
|
1003
|
-
logout:
|
|
1004
|
-
log:
|
|
1005
|
-
create:
|
|
1006
|
-
state:
|
|
1007
|
-
watch:
|
|
1008
|
-
upload:
|
|
1009
|
-
download:
|
|
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:
|
|
1012
|
-
reset:
|
|
1013
|
-
metadata:
|
|
1014
|
-
query:
|
|
1015
|
-
synced:
|
|
1016
|
-
disconnect:
|
|
1017
|
-
reconnect:
|
|
1018
|
-
|
|
1019
|
-
|
|
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
|
|
1024
|
-
async function
|
|
1025
|
-
const e = await fetch(`https://${
|
|
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
|
|
1034
|
-
|
|
1020
|
+
const _t = (e) => {
|
|
1021
|
+
Nt();
|
|
1035
1022
|
const t = function() {
|
|
1036
|
-
const n = new WebSocket(`wss://${
|
|
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 =
|
|
1041
|
-
token: e.getToken ||
|
|
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:
|
|
1032
|
+
uuid: ne,
|
|
1046
1033
|
fetch,
|
|
1047
|
-
applyPatch:
|
|
1048
|
-
login:
|
|
1049
|
-
logout:
|
|
1050
|
-
variables: { LANGUAGES:
|
|
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
|
|
1048
|
+
function Rt() {
|
|
1062
1049
|
let e = 0, t;
|
|
1063
|
-
const r = new Promise((
|
|
1064
|
-
async function p
|
|
1065
|
-
const
|
|
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
|
|
1054
|
+
const T = window.opener ? window.opener : window.parent;
|
|
1068
1055
|
try {
|
|
1069
|
-
return
|
|
1070
|
-
...
|
|
1056
|
+
return T.postMessage({
|
|
1057
|
+
...p,
|
|
1071
1058
|
session: await r,
|
|
1072
|
-
requestId:
|
|
1059
|
+
requestId: A,
|
|
1073
1060
|
index: e
|
|
1074
|
-
}, "*"), new Promise((
|
|
1075
|
-
n[
|
|
1061
|
+
}, "*"), new Promise((R, P) => {
|
|
1062
|
+
n[A] = { resolve: R, reject: P };
|
|
1076
1063
|
});
|
|
1077
|
-
} catch (
|
|
1078
|
-
console.log("ERROR POSTING MESSAGE UP",
|
|
1064
|
+
} catch (R) {
|
|
1065
|
+
console.log("ERROR POSTING MESSAGE UP", p, R);
|
|
1079
1066
|
}
|
|
1080
1067
|
}
|
|
1081
|
-
let
|
|
1082
|
-
addEventListener("message", async ({ data:
|
|
1083
|
-
if (
|
|
1084
|
-
|
|
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 (!
|
|
1087
|
-
if (n[
|
|
1088
|
-
const { resolve:
|
|
1089
|
-
|
|
1090
|
-
} else if (
|
|
1091
|
-
const { scope:
|
|
1092
|
-
|
|
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[
|
|
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
|
|
1099
|
-
async function
|
|
1100
|
-
const
|
|
1101
|
-
return
|
|
1102
|
-
}
|
|
1103
|
-
function
|
|
1104
|
-
return
|
|
1105
|
-
{ op: "add", path: ["active_type"], value:
|
|
1106
|
-
{ op: "add", path: ["active"], value:
|
|
1107
|
-
]),
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
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
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
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
|
|
1130
|
-
return
|
|
1110
|
+
function v(p) {
|
|
1111
|
+
return g(p, [{ op: "add", path: ["active"], value: null }]);
|
|
1131
1112
|
}
|
|
1132
|
-
function
|
|
1133
|
-
return
|
|
1113
|
+
function g(p, A, T, R) {
|
|
1114
|
+
return w({ type: "interact", scope: p, patch: A, context: R });
|
|
1134
1115
|
}
|
|
1135
|
-
async function
|
|
1136
|
-
let { name:
|
|
1137
|
-
const
|
|
1138
|
-
if (
|
|
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
|
|
1141
|
-
if (
|
|
1142
|
-
throw new Error(
|
|
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
|
|
1146
|
-
let
|
|
1147
|
-
const
|
|
1148
|
-
const
|
|
1149
|
-
if (await new Promise((
|
|
1150
|
-
else if (
|
|
1151
|
-
const
|
|
1152
|
-
|
|
1153
|
-
} else if (
|
|
1154
|
-
const
|
|
1155
|
-
|
|
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
|
|
1159
|
-
}
|
|
1160
|
-
function
|
|
1161
|
-
return ["active_type", "name"].includes(
|
|
1162
|
-
}
|
|
1163
|
-
async function
|
|
1164
|
-
const
|
|
1165
|
-
return new
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
if (!
|
|
1169
|
-
}),
|
|
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
|
|
1173
|
-
return
|
|
1153
|
+
function N(p, A, T) {
|
|
1154
|
+
return w({ type: "login", provider: p, username: A, password: T });
|
|
1174
1155
|
}
|
|
1175
|
-
function
|
|
1176
|
-
return
|
|
1156
|
+
function _(p, A, T, R = []) {
|
|
1157
|
+
return w({ type: "query", query: p, params: A, domain: T, context: R });
|
|
1177
1158
|
}
|
|
1178
|
-
function
|
|
1179
|
-
return
|
|
1159
|
+
function M() {
|
|
1160
|
+
return w({ type: "logout" });
|
|
1180
1161
|
}
|
|
1181
|
-
function
|
|
1182
|
-
return
|
|
1162
|
+
function $() {
|
|
1163
|
+
return w({ type: "disconnect" });
|
|
1183
1164
|
}
|
|
1184
|
-
function
|
|
1185
|
-
return
|
|
1186
|
-
}
|
|
1187
|
-
function W() {
|
|
1188
|
-
return p({ type: "reconnect" });
|
|
1165
|
+
function z() {
|
|
1166
|
+
return w({ type: "reconnect" });
|
|
1189
1167
|
}
|
|
1190
|
-
function
|
|
1191
|
-
return
|
|
1168
|
+
function Y() {
|
|
1169
|
+
return w({ type: "synced" });
|
|
1192
1170
|
}
|
|
1193
|
-
function
|
|
1194
|
-
return
|
|
1171
|
+
function X(p) {
|
|
1172
|
+
return w({ type: "close", info: p });
|
|
1195
1173
|
}
|
|
1196
1174
|
return {
|
|
1197
1175
|
embedded: !0,
|
|
1198
|
-
uuid:
|
|
1199
|
-
environment:
|
|
1200
|
-
login:
|
|
1201
|
-
logout:
|
|
1202
|
-
create:
|
|
1203
|
-
state:
|
|
1176
|
+
uuid: ne,
|
|
1177
|
+
environment: a,
|
|
1178
|
+
login: N,
|
|
1179
|
+
logout: M,
|
|
1180
|
+
create: h,
|
|
1181
|
+
state: E,
|
|
1204
1182
|
watch: c,
|
|
1205
|
-
upload:
|
|
1206
|
-
download:
|
|
1207
|
-
interact:
|
|
1208
|
-
patch:
|
|
1209
|
-
reset:
|
|
1210
|
-
metadata:
|
|
1211
|
-
disconnect:
|
|
1212
|
-
reconnect:
|
|
1213
|
-
synced:
|
|
1214
|
-
close:
|
|
1215
|
-
query:
|
|
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
|
|
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
|
|
1224
|
-
t(
|
|
1200
|
+
const s = o.target.files[0];
|
|
1201
|
+
t(s || null);
|
|
1225
1202
|
}), n.click();
|
|
1226
1203
|
});
|
|
1227
1204
|
}
|
|
1228
|
-
let
|
|
1229
|
-
function
|
|
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 && !
|
|
1208
|
+
return n && !k(t) && !r.some((o) => t.startsWith(o)) ? `${n}/${t}` : t;
|
|
1232
1209
|
}
|
|
1233
|
-
function
|
|
1234
|
-
if (
|
|
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 ?
|
|
1242
|
-
r.embed =
|
|
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
|
|
1247
|
-
if (!
|
|
1248
|
-
o.data = await
|
|
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
|
-
},
|
|
1228
|
+
}, x || (window.__default_knowlearning_agent = x = r), r;
|
|
1252
1229
|
}
|
|
1253
|
-
const
|
|
1254
|
-
function
|
|
1230
|
+
const fe = (e) => JSON.parse(JSON.stringify(e));
|
|
1231
|
+
function Ct(e, t) {
|
|
1255
1232
|
const r = {}, n = [], o = {};
|
|
1256
|
-
let
|
|
1257
|
-
const d =
|
|
1258
|
-
const I = { ...
|
|
1259
|
-
n.push({ message: I, sent:
|
|
1260
|
-
}),
|
|
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:
|
|
1263
|
-
t.contentWindow.postMessage(
|
|
1239
|
+
const { message: v, sent: g } = n.shift();
|
|
1240
|
+
t.contentWindow.postMessage(v, "*"), g();
|
|
1264
1241
|
}
|
|
1265
|
-
},
|
|
1266
|
-
const { requestId:
|
|
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(
|
|
1245
|
+
console.error(v), I({});
|
|
1269
1246
|
else if (O === "close")
|
|
1270
|
-
o.close && o.close(
|
|
1247
|
+
o.close && o.close(v.info);
|
|
1271
1248
|
else if (O === "environment") {
|
|
1272
|
-
const { user: 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
|
-
...
|
|
1258
|
+
...N
|
|
1282
1259
|
},
|
|
1283
|
-
mode:
|
|
1260
|
+
mode: y
|
|
1284
1261
|
// TODO: deprecate
|
|
1285
1262
|
});
|
|
1286
1263
|
} else if (O === "interact") {
|
|
1287
|
-
let { scope: m, patch:
|
|
1288
|
-
const
|
|
1289
|
-
let
|
|
1290
|
-
if (o.mutate && (
|
|
1291
|
-
const
|
|
1292
|
-
|
|
1293
|
-
scope:
|
|
1294
|
-
before:
|
|
1295
|
-
after:
|
|
1296
|
-
patch:
|
|
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:
|
|
1302
|
-
I(await
|
|
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:
|
|
1308
|
-
r[
|
|
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:
|
|
1311
|
-
I(await
|
|
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:
|
|
1314
|
-
|
|
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 } =
|
|
1317
|
-
I(await
|
|
1290
|
+
const { info: m } = v;
|
|
1291
|
+
I(await x.upload(m));
|
|
1318
1292
|
} else if (O === "download")
|
|
1319
|
-
I(await
|
|
1293
|
+
I(await x.download(v.id).url());
|
|
1320
1294
|
else if (O === "login") {
|
|
1321
|
-
const { provider: m, username:
|
|
1322
|
-
I(await
|
|
1323
|
-
} else O === "logout" ?
|
|
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:
|
|
1326
|
-
|
|
1299
|
+
window.addEventListener("message", ({ data: v }) => {
|
|
1300
|
+
v.session === d && (c = !0, i(v));
|
|
1327
1301
|
}), t.onload = () => {
|
|
1328
|
-
|
|
1329
|
-
},
|
|
1330
|
-
async function
|
|
1331
|
-
|
|
1332
|
-
const { protocol:
|
|
1333
|
-
if (
|
|
1334
|
-
const { domain: O } = await
|
|
1335
|
-
t.src = `${
|
|
1336
|
-
} else t.src =
|
|
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
|
-
|
|
1312
|
+
w({ type: "setup", session: d }), await new Promise((O) => setTimeout(O, 100));
|
|
1339
1313
|
o.open && o.open();
|
|
1340
1314
|
}
|
|
1341
|
-
function
|
|
1315
|
+
function h() {
|
|
1342
1316
|
t.parentNode && t.parentNode.removeChild(t);
|
|
1343
1317
|
}
|
|
1344
|
-
function
|
|
1345
|
-
o[
|
|
1318
|
+
function l(v, g) {
|
|
1319
|
+
o[v] = g;
|
|
1346
1320
|
}
|
|
1347
|
-
function
|
|
1348
|
-
|
|
1321
|
+
function E(v, g) {
|
|
1322
|
+
w({ type: "auth", token: v, state: g });
|
|
1349
1323
|
}
|
|
1350
1324
|
return {
|
|
1351
|
-
auth:
|
|
1352
|
-
remove:
|
|
1353
|
-
on:
|
|
1325
|
+
auth: E,
|
|
1326
|
+
remove: h,
|
|
1327
|
+
on: l
|
|
1354
1328
|
};
|
|
1355
1329
|
}
|
|
1356
|
-
window.Agent =
|
|
1330
|
+
window.Agent = He();
|