@knowlearning/agents 0.9.169 → 0.9.171
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/initialize.js +2 -2
- package/browser.js +1 -1
- package/dist/browser.js +1356 -0
- package/lib.browser.js +3 -0
- package/package.json +4 -1
- package/vite.config.js +12 -0
package/dist/browser.js
ADDED
|
@@ -0,0 +1,1356 @@
|
|
|
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))
|
|
4
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
5
|
+
return fe(Ye);
|
|
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);
|
|
10
|
+
}
|
|
11
|
+
var j = [];
|
|
12
|
+
for (var ye = 0; ye < 256; ++ye)
|
|
13
|
+
j.push((ye + 256).toString(16).substr(1));
|
|
14
|
+
function xe(e) {
|
|
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))
|
|
17
|
+
throw TypeError("Stringified UUID is invalid");
|
|
18
|
+
return r;
|
|
19
|
+
}
|
|
20
|
+
var De, me, Ee = 0, Ae = 0;
|
|
21
|
+
function ie(e, t, r) {
|
|
22
|
+
var n = t && r || 0, o = t || new Array(16);
|
|
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);
|
|
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)
|
|
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);
|
|
40
|
+
}
|
|
41
|
+
function Qe(e, t, r) {
|
|
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);
|
|
45
|
+
}
|
|
46
|
+
/*!
|
|
47
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
48
|
+
* (c) 2017-2022 Joachim Wester
|
|
49
|
+
* MIT licensed
|
|
50
|
+
*/
|
|
51
|
+
var Ke = /* @__PURE__ */ function() {
|
|
52
|
+
var e = function(t, r) {
|
|
53
|
+
return e = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, o) {
|
|
54
|
+
n.__proto__ = o;
|
|
55
|
+
} || function(n, o) {
|
|
56
|
+
for (var i in o) o.hasOwnProperty(i) && (n[i] = o[i]);
|
|
57
|
+
}, e(t, r);
|
|
58
|
+
};
|
|
59
|
+
return function(t, r) {
|
|
60
|
+
e(t, r);
|
|
61
|
+
function n() {
|
|
62
|
+
this.constructor = t;
|
|
63
|
+
}
|
|
64
|
+
t.prototype = r === null ? Object.create(r) : (n.prototype = r.prototype, new n());
|
|
65
|
+
};
|
|
66
|
+
}(), We = Object.prototype.hasOwnProperty;
|
|
67
|
+
function Ie(e, t) {
|
|
68
|
+
return We.call(e, t);
|
|
69
|
+
}
|
|
70
|
+
function Se(e) {
|
|
71
|
+
if (Array.isArray(e)) {
|
|
72
|
+
for (var t = new Array(e.length), r = 0; r < t.length; r++)
|
|
73
|
+
t[r] = "" + r;
|
|
74
|
+
return t;
|
|
75
|
+
}
|
|
76
|
+
if (Object.keys)
|
|
77
|
+
return Object.keys(e);
|
|
78
|
+
var n = [];
|
|
79
|
+
for (var o in e)
|
|
80
|
+
Ie(e, o) && n.push(o);
|
|
81
|
+
return n;
|
|
82
|
+
}
|
|
83
|
+
function Y(e) {
|
|
84
|
+
switch (typeof e) {
|
|
85
|
+
case "object":
|
|
86
|
+
return JSON.parse(JSON.stringify(e));
|
|
87
|
+
//Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
|
88
|
+
case "undefined":
|
|
89
|
+
return null;
|
|
90
|
+
//this is how JSON.stringify behaves for array items
|
|
91
|
+
default:
|
|
92
|
+
return e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function Ne(e) {
|
|
96
|
+
for (var t = 0, r = e.length, n; t < r; ) {
|
|
97
|
+
if (n = e.charCodeAt(t), n >= 48 && n <= 57) {
|
|
98
|
+
t++;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
return !1;
|
|
102
|
+
}
|
|
103
|
+
return !0;
|
|
104
|
+
}
|
|
105
|
+
function re(e) {
|
|
106
|
+
return e.indexOf("/") === -1 && e.indexOf("~") === -1 ? e : e.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
107
|
+
}
|
|
108
|
+
function $e(e) {
|
|
109
|
+
return e.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
110
|
+
}
|
|
111
|
+
function _e(e) {
|
|
112
|
+
if (e === void 0)
|
|
113
|
+
return !0;
|
|
114
|
+
if (e) {
|
|
115
|
+
if (Array.isArray(e)) {
|
|
116
|
+
for (var t = 0, r = e.length; t < r; t++)
|
|
117
|
+
if (_e(e[t]))
|
|
118
|
+
return !0;
|
|
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]]))
|
|
122
|
+
return !0;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return !1;
|
|
126
|
+
}
|
|
127
|
+
function Le(e, t) {
|
|
128
|
+
var r = [e];
|
|
129
|
+
for (var n in t) {
|
|
130
|
+
var o = typeof t[n] == "object" ? JSON.stringify(t[n], null, 2) : t[n];
|
|
131
|
+
typeof o < "u" && r.push(n + ": " + o);
|
|
132
|
+
}
|
|
133
|
+
return r.join(`
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
136
|
+
var qe = (
|
|
137
|
+
/** @class */
|
|
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;
|
|
143
|
+
}
|
|
144
|
+
return t;
|
|
145
|
+
}(Error)
|
|
146
|
+
), M = qe, Ze = Y, se = {
|
|
147
|
+
add: function(e, t, r) {
|
|
148
|
+
return e[t] = this.value, { newDocument: r };
|
|
149
|
+
},
|
|
150
|
+
remove: function(e, t, r) {
|
|
151
|
+
var n = e[t];
|
|
152
|
+
return delete e[t], { newDocument: r, removed: n };
|
|
153
|
+
},
|
|
154
|
+
replace: function(e, t, r) {
|
|
155
|
+
var n = e[t];
|
|
156
|
+
return e[t] = this.value, { newDocument: r, removed: n };
|
|
157
|
+
},
|
|
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 };
|
|
163
|
+
},
|
|
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 };
|
|
167
|
+
},
|
|
168
|
+
test: function(e, t, r) {
|
|
169
|
+
return { newDocument: r, test: ae(e[t], this.value) };
|
|
170
|
+
},
|
|
171
|
+
_get: function(e, t, r) {
|
|
172
|
+
return this.value = e[t], { newDocument: r };
|
|
173
|
+
}
|
|
174
|
+
}, ke = {
|
|
175
|
+
add: function(e, t, r) {
|
|
176
|
+
return Ne(t) ? e.splice(t, 0, this.value) : e[t] = this.value, { newDocument: r, index: t };
|
|
177
|
+
},
|
|
178
|
+
remove: function(e, t, r) {
|
|
179
|
+
var n = e.splice(t, 1);
|
|
180
|
+
return { newDocument: r, removed: n[0] };
|
|
181
|
+
},
|
|
182
|
+
replace: function(e, t, r) {
|
|
183
|
+
var n = e[t];
|
|
184
|
+
return e[t] = this.value, { newDocument: r, removed: n };
|
|
185
|
+
},
|
|
186
|
+
move: se.move,
|
|
187
|
+
copy: se.copy,
|
|
188
|
+
test: se.test,
|
|
189
|
+
_get: se._get
|
|
190
|
+
};
|
|
191
|
+
function we(e, t) {
|
|
192
|
+
if (t == "")
|
|
193
|
+
return e;
|
|
194
|
+
var r = { op: "_get", path: t };
|
|
195
|
+
return oe(e, r), r.value;
|
|
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 === "") {
|
|
199
|
+
var c = { newDocument: e };
|
|
200
|
+
if (t.op === "add")
|
|
201
|
+
return c.newDocument = t.value, c;
|
|
202
|
+
if (t.op === "replace")
|
|
203
|
+
return c.newDocument = t.value, c.removed = e, c;
|
|
204
|
+
if (t.op === "move" || t.op === "copy")
|
|
205
|
+
return c.newDocument = we(e, t.from), t.op === "move" && (c.removed = e), c;
|
|
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);
|
|
209
|
+
return c.newDocument = e, c;
|
|
210
|
+
} else {
|
|
211
|
+
if (t.op === "remove")
|
|
212
|
+
return c.removed = e, c.newDocument = null, c;
|
|
213
|
+
if (t.op === "_get")
|
|
214
|
+
return t.value = e, c;
|
|
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);
|
|
217
|
+
return c;
|
|
218
|
+
}
|
|
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"))
|
|
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;
|
|
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);
|
|
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);
|
|
237
|
+
if (c.test === !1)
|
|
238
|
+
throw new M("Test operation failed", "TEST_OPERATION_FAILED", i, t, e);
|
|
239
|
+
return c;
|
|
240
|
+
}
|
|
241
|
+
} else if (a >= s) {
|
|
242
|
+
var c = se[t.op].call(t, l, u, e);
|
|
243
|
+
if (c.test === !1)
|
|
244
|
+
throw new M("Test operation failed", "TEST_OPERATION_FAILED", i, t, e);
|
|
245
|
+
return c;
|
|
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);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function he(e, t, r, n, o) {
|
|
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;
|
|
259
|
+
}
|
|
260
|
+
function Xe(e, t, r) {
|
|
261
|
+
var n = oe(e, t);
|
|
262
|
+
if (n.test === !1)
|
|
263
|
+
throw new M("Test operation failed", "TEST_OPERATION_FAILED", r, t, e);
|
|
264
|
+
return n.newDocument;
|
|
265
|
+
}
|
|
266
|
+
function pe(e, t, r, n) {
|
|
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]) {
|
|
270
|
+
if (typeof e.path != "string")
|
|
271
|
+
throw new M("Operation `path` property is not a string", "OPERATION_PATH_INVALID", t, e, r);
|
|
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);
|
|
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);
|
|
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);
|
|
280
|
+
if (r) {
|
|
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);
|
|
285
|
+
} else if (e.op === "replace" || e.op === "remove" || e.op === "_get") {
|
|
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);
|
|
288
|
+
} else if (e.op === "move" || e.op === "copy") {
|
|
289
|
+
var c = { op: "_get", path: e.from, value: void 0 }, d = Ge([c], r);
|
|
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);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
} else throw new M("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", t, e, r);
|
|
295
|
+
}
|
|
296
|
+
function Ge(e, t, r) {
|
|
297
|
+
try {
|
|
298
|
+
if (!Array.isArray(e))
|
|
299
|
+
throw new M("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
300
|
+
if (t)
|
|
301
|
+
he(Y(t), Y(e), r || !0);
|
|
302
|
+
else {
|
|
303
|
+
r = r || pe;
|
|
304
|
+
for (var n = 0; n < e.length; n++)
|
|
305
|
+
r(e[n], n, t, void 0);
|
|
306
|
+
}
|
|
307
|
+
} catch (o) {
|
|
308
|
+
if (o instanceof M)
|
|
309
|
+
return o;
|
|
310
|
+
throw o;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function ae(e, t) {
|
|
314
|
+
if (e === t)
|
|
315
|
+
return !0;
|
|
316
|
+
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
317
|
+
var r = Array.isArray(e), n = Array.isArray(t), o, i, c;
|
|
318
|
+
if (r && n) {
|
|
319
|
+
if (i = e.length, i != t.length)
|
|
320
|
+
return !1;
|
|
321
|
+
for (o = i; o-- !== 0; )
|
|
322
|
+
if (!ae(e[o], t[o]))
|
|
323
|
+
return !1;
|
|
324
|
+
return !0;
|
|
325
|
+
}
|
|
326
|
+
if (r != n)
|
|
327
|
+
return !1;
|
|
328
|
+
var d = Object.keys(e);
|
|
329
|
+
if (i = d.length, i !== Object.keys(t).length)
|
|
330
|
+
return !1;
|
|
331
|
+
for (o = i; o-- !== 0; )
|
|
332
|
+
if (!t.hasOwnProperty(d[o]))
|
|
333
|
+
return !1;
|
|
334
|
+
for (o = i; o-- !== 0; )
|
|
335
|
+
if (c = d[o], !ae(e[c], t[c]))
|
|
336
|
+
return !1;
|
|
337
|
+
return !0;
|
|
338
|
+
}
|
|
339
|
+
return e !== e && t !== t;
|
|
340
|
+
}
|
|
341
|
+
const Ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
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
|
|
352
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
353
|
+
/*!
|
|
354
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
355
|
+
* (c) 2017-2021 Joachim Wester
|
|
356
|
+
* MIT license
|
|
357
|
+
*/
|
|
358
|
+
var Pe = /* @__PURE__ */ new WeakMap(), et = (
|
|
359
|
+
/** @class */
|
|
360
|
+
/* @__PURE__ */ function() {
|
|
361
|
+
function e(t) {
|
|
362
|
+
this.observers = /* @__PURE__ */ new Map(), this.obj = t;
|
|
363
|
+
}
|
|
364
|
+
return e;
|
|
365
|
+
}()
|
|
366
|
+
), tt = (
|
|
367
|
+
/** @class */
|
|
368
|
+
/* @__PURE__ */ function() {
|
|
369
|
+
function e(t, r) {
|
|
370
|
+
this.callback = t, this.observer = r;
|
|
371
|
+
}
|
|
372
|
+
return e;
|
|
373
|
+
}()
|
|
374
|
+
);
|
|
375
|
+
function nt(e) {
|
|
376
|
+
return Pe.get(e);
|
|
377
|
+
}
|
|
378
|
+
function rt(e, t) {
|
|
379
|
+
return e.observers.get(t);
|
|
380
|
+
}
|
|
381
|
+
function ot(e, t) {
|
|
382
|
+
e.observers.delete(t.callback);
|
|
383
|
+
}
|
|
384
|
+
function it(e, t) {
|
|
385
|
+
t.unobserve();
|
|
386
|
+
}
|
|
387
|
+
function st(e, t) {
|
|
388
|
+
var r = [], n, o = nt(e);
|
|
389
|
+
if (!o)
|
|
390
|
+
o = new et(e), Pe.set(e, o);
|
|
391
|
+
else {
|
|
392
|
+
var i = rt(o, t);
|
|
393
|
+
n = i && i.observer;
|
|
394
|
+
}
|
|
395
|
+
if (n)
|
|
396
|
+
return n;
|
|
397
|
+
if (n = {}, o.value = Y(e), t) {
|
|
398
|
+
n.callback = t, n.next = null;
|
|
399
|
+
var c = function() {
|
|
400
|
+
Re(n);
|
|
401
|
+
}, d = function() {
|
|
402
|
+
clearTimeout(n.next), n.next = setTimeout(c);
|
|
403
|
+
};
|
|
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
|
+
}
|
|
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;
|
|
409
|
+
}
|
|
410
|
+
function Re(e, t) {
|
|
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);
|
|
414
|
+
var n = e.patches;
|
|
415
|
+
return n.length > 0 && (e.patches = [], e.callback && e.callback(n)), n;
|
|
416
|
+
}
|
|
417
|
+
function Ce(e, t, r, n, o) {
|
|
418
|
+
if (t !== e) {
|
|
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 }));
|
|
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]) });
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function at(e, t, r) {
|
|
435
|
+
r === void 0 && (r = !1);
|
|
436
|
+
var n = [];
|
|
437
|
+
return Ce(e, t, n, "", r), n;
|
|
438
|
+
}
|
|
439
|
+
const ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
440
|
+
__proto__: null,
|
|
441
|
+
compare: at,
|
|
442
|
+
generate: Re,
|
|
443
|
+
observe: st,
|
|
444
|
+
unobserve: it
|
|
445
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
446
|
+
Object.assign({}, Ve, ct, {
|
|
447
|
+
JsonPatchError: qe,
|
|
448
|
+
deepClone: Y,
|
|
449
|
+
escapePathComponent: re,
|
|
450
|
+
unescapePathComponent: $e
|
|
451
|
+
});
|
|
452
|
+
const ft = "https://auth.knowlearning.systems", ut = `-----BEGIN PUBLIC KEY-----
|
|
453
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA59Uz6jvBJF3B8/7xMqGo
|
|
454
|
+
XkIhLFvTCHuFIGuCNNZGCJUnSk2ne6Jp1ehUIarliJwzrvfr2HMe0PvzAJyZqQIs
|
|
455
|
+
uz0Lt867TTojCAKJunxbcrwEhzvz0FNjNu1wpgkSHFvd1uTvRSZqauqUmG0HqC17
|
|
456
|
+
HSmBaXivB49B/pviowVJc+mUJJ9MROtOiL4JN5niHnLbt6QVi6NITAJkOwtoRhck
|
|
457
|
+
5j0KLvfrq18R8QrfDOq3v5hWlrA6j1wPvTW1mzFk8MrOZw935mMDdMivFAm/DltM
|
|
458
|
+
NT5I3YnLZpcl1e/fydC+B6zSz2nZfLb2iDBbADDVj2+i9JUEFomg6ng1DjHUGMYc
|
|
459
|
+
ZQIDAQAB
|
|
460
|
+
-----END PUBLIC KEY-----
|
|
461
|
+
`;
|
|
462
|
+
if (window.location.pathname.startsWith("/auth/")) {
|
|
463
|
+
const e = window.location.pathname.slice(6), [t] = e.split("/", 1), r = window.localStorage.getItem(t);
|
|
464
|
+
if (r) {
|
|
465
|
+
const n = e.slice(t.length + 1);
|
|
466
|
+
window.localStorage.setItem("token", n), window.location.href = r;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async function lt(e = "google", t) {
|
|
470
|
+
const r = Math.random().toString(36).substring(2);
|
|
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));
|
|
473
|
+
window.location.href = `/auth/${r}/${o}`;
|
|
474
|
+
} else {
|
|
475
|
+
const n = encodeURIComponent(window.location.href);
|
|
476
|
+
window.location.href = `${ft}/${e}/${r}/${n}`;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function dt() {
|
|
480
|
+
window.localStorage.setItem("token", Math.random().toString(36).substring(2)), window.location.reload();
|
|
481
|
+
}
|
|
482
|
+
async function wt() {
|
|
483
|
+
const e = localStorage.getItem("token");
|
|
484
|
+
return window.localStorage.removeItem("token"), e;
|
|
485
|
+
}
|
|
486
|
+
async function pt(e, t) {
|
|
487
|
+
const r = await crypto.subtle.importKey(
|
|
488
|
+
"spki",
|
|
489
|
+
ht(e),
|
|
490
|
+
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
491
|
+
!0,
|
|
492
|
+
["encrypt"]
|
|
493
|
+
), n = await crypto.subtle.generateKey(
|
|
494
|
+
{ name: "AES-GCM", length: 256 },
|
|
495
|
+
!0,
|
|
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 },
|
|
499
|
+
n,
|
|
500
|
+
o
|
|
501
|
+
), d = await crypto.subtle.exportKey("raw", n), p = await crypto.subtle.encrypt(
|
|
502
|
+
{ name: "RSA-OAEP" },
|
|
503
|
+
r,
|
|
504
|
+
d
|
|
505
|
+
);
|
|
506
|
+
return [
|
|
507
|
+
encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(i)))),
|
|
508
|
+
encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(c)))),
|
|
509
|
+
encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(p))))
|
|
510
|
+
].join(",");
|
|
511
|
+
}
|
|
512
|
+
function ht(e) {
|
|
513
|
+
const t = e.replace(/-----[^-]+-----/g, "").replace(/\s/g, ""), r = atob(t), n = new Uint8Array(r.length);
|
|
514
|
+
for (let o = 0; o < r.length; o++)
|
|
515
|
+
n[o] = r.charCodeAt(o);
|
|
516
|
+
return n.buffer;
|
|
517
|
+
}
|
|
518
|
+
function vt(e) {
|
|
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;
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
function Ue(e) {
|
|
525
|
+
return typeof e == "string" ? e.replaceAll("~", "~0").replaceAll("/", "~1") : e;
|
|
526
|
+
}
|
|
527
|
+
const ge = /* @__PURE__ */ new Set(), ue = /* @__PURE__ */ new Map();
|
|
528
|
+
function le(e) {
|
|
529
|
+
return `/${e.join("/")}`;
|
|
530
|
+
}
|
|
531
|
+
function Me(e) {
|
|
532
|
+
return JSON.parse(JSON.stringify(e));
|
|
533
|
+
}
|
|
534
|
+
function yt(e, [t, r]) {
|
|
535
|
+
return Math.max(Math.min(parseInt(e), r), t);
|
|
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,
|
|
543
|
+
t,
|
|
544
|
+
r,
|
|
545
|
+
[...n, a]
|
|
546
|
+
), d = {
|
|
547
|
+
copyWithin() {
|
|
548
|
+
throw new Error('"copyWithin" not implemented.');
|
|
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());
|
|
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), {
|
|
562
|
+
op: "move",
|
|
563
|
+
from: [...n, N],
|
|
564
|
+
path: [...n, g]
|
|
565
|
+
};
|
|
566
|
+
})
|
|
567
|
+
), l;
|
|
568
|
+
},
|
|
569
|
+
reverse() {
|
|
570
|
+
const a = [];
|
|
571
|
+
return e.forEach((s, v) => {
|
|
572
|
+
a.push({
|
|
573
|
+
op: "move",
|
|
574
|
+
from: [...n, v],
|
|
575
|
+
path: [...n, 0]
|
|
576
|
+
});
|
|
577
|
+
const u = ue.get(s);
|
|
578
|
+
u && (u[u.length - 1] = e.length - 1 - v);
|
|
579
|
+
}), e.reverse(), t(a), l;
|
|
580
|
+
},
|
|
581
|
+
shift() {
|
|
582
|
+
return d.splice(0, 1)[0];
|
|
583
|
+
},
|
|
584
|
+
unshift() {
|
|
585
|
+
return d.splice(0, 0, ...arguments), e.length;
|
|
586
|
+
},
|
|
587
|
+
splice(a, s, ...v) {
|
|
588
|
+
const u = e.length - a;
|
|
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 })
|
|
594
|
+
);
|
|
595
|
+
v.forEach((m, A) => {
|
|
596
|
+
h.push({
|
|
597
|
+
op: "add",
|
|
598
|
+
path: [...n, a + A],
|
|
599
|
+
value: Me(m)
|
|
600
|
+
});
|
|
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);
|
|
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;
|
|
611
|
+
}
|
|
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);
|
|
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}`);
|
|
627
|
+
return t([{
|
|
628
|
+
op: a[s] === void 0 ? "add" : "replace",
|
|
629
|
+
value: Me(v),
|
|
630
|
+
// TODO: more efficient sanitization
|
|
631
|
+
path: u
|
|
632
|
+
}]), v instanceof Object ? a[s] = c(s, v) : a[s] = v, !0;
|
|
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);
|
|
638
|
+
else return !0;
|
|
639
|
+
const v = [...n, s];
|
|
640
|
+
r[le(v)] || t([{ op: "remove", path: v }]);
|
|
641
|
+
}
|
|
642
|
+
return !0;
|
|
643
|
+
},
|
|
644
|
+
get(a, s, v) {
|
|
645
|
+
return i && d[s] ? d[s] : a[s];
|
|
646
|
+
}
|
|
647
|
+
}, l = new Proxy(e, p);
|
|
648
|
+
return ge.add(l), ue.set(l, n), l;
|
|
649
|
+
}
|
|
650
|
+
const mt = 1e4, Et = { open: !0, mutate: !0, close: !0 };
|
|
651
|
+
function At(e) {
|
|
652
|
+
return structuredClone(e).filter(({ path: t }) => t.shift() === "active");
|
|
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 = {
|
|
661
|
+
loaded: Date.now(),
|
|
662
|
+
connected: null,
|
|
663
|
+
authenticated: null
|
|
664
|
+
};
|
|
665
|
+
async function E() {
|
|
666
|
+
return { variables: v, ...await ee, context: [] };
|
|
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];
|
|
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;
|
|
675
|
+
}
|
|
676
|
+
async function P() {
|
|
677
|
+
for (await new Promise((w) => w()), L = null; h && R + 1 < A.length; ) {
|
|
678
|
+
L = null;
|
|
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();
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
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();
|
|
691
|
+
}
|
|
692
|
+
function J() {
|
|
693
|
+
clearTimeout(_), _ = setTimeout(
|
|
694
|
+
() => {
|
|
695
|
+
d("CLOSING DUE TO HEARTBEAT TIMEOUT"), b();
|
|
696
|
+
},
|
|
697
|
+
mt
|
|
698
|
+
);
|
|
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));
|
|
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)
|
|
709
|
+
try {
|
|
710
|
+
if (w.error && console.warn("ERROR RESPONSE", w), h)
|
|
711
|
+
if (Et[w.type])
|
|
712
|
+
try {
|
|
713
|
+
a && a(w, s);
|
|
714
|
+
} catch {
|
|
715
|
+
d("ERROR HANDLING DOMAIN MESSAGE", w);
|
|
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);
|
|
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)
|
|
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 });
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
}
|
|
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();
|
|
735
|
+
}
|
|
736
|
+
} catch (y) {
|
|
737
|
+
console.error("ERROR HANDLING CONNECTION MESSAGE", y, w);
|
|
738
|
+
}
|
|
739
|
+
}, u.onerror = async (w) => {
|
|
740
|
+
d("CONNECTION ERROR", w.message);
|
|
741
|
+
}, u.onclose = async (w) => {
|
|
742
|
+
d("CONNECTION CLOSURE", w.message), b();
|
|
743
|
+
}, J();
|
|
744
|
+
}
|
|
745
|
+
async function H() {
|
|
746
|
+
const w = new Promise((y) => K.push({ si: R, resolve: y }));
|
|
747
|
+
return x(), w;
|
|
748
|
+
}
|
|
749
|
+
function z() {
|
|
750
|
+
return new Promise((w, y) => W[I].push([w, y]));
|
|
751
|
+
}
|
|
752
|
+
function Z() {
|
|
753
|
+
d("DISCONNECTED AGENT!!!!!!!!!!!!!!!"), V = !0, u.close({ keepalive: !0 });
|
|
754
|
+
}
|
|
755
|
+
function X() {
|
|
756
|
+
d("RECONNECTED AGENT!!!!!!!!!!!!!!!"), V = !1, b();
|
|
757
|
+
}
|
|
758
|
+
return B(), [S, z, Z, X, H, E];
|
|
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", [{
|
|
768
|
+
op: "add",
|
|
769
|
+
path: ["active", A, "subscriptions", _],
|
|
770
|
+
value: { scope: e, user: t, domain: r, ii: null }
|
|
771
|
+
}], !1, !1);
|
|
772
|
+
try {
|
|
773
|
+
L(await p());
|
|
774
|
+
} catch (G) {
|
|
775
|
+
q(G);
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
await l[R];
|
|
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);
|
|
785
|
+
}));
|
|
786
|
+
} catch (_) {
|
|
787
|
+
O(_);
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
return h.metadata = g, h;
|
|
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)));
|
|
801
|
+
}), () => {
|
|
802
|
+
h = !0, g && p(g, a);
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
function d(l, a, s, v) {
|
|
806
|
+
const u = l[0], g = l.slice(1);
|
|
807
|
+
let h = () => {
|
|
808
|
+
};
|
|
809
|
+
const O = c(u, ({ state: I }) => {
|
|
810
|
+
if (g.length === 0) {
|
|
811
|
+
a(I);
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
h();
|
|
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);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
}, s, v);
|
|
823
|
+
return () => {
|
|
824
|
+
O(), h();
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
function p(l, a) {
|
|
828
|
+
if (!n[l]) {
|
|
829
|
+
console.warn("NO WATCHERS FOR KEY", l, a);
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
const s = n[l].findIndex((v) => v === a);
|
|
833
|
+
s > -1 && n[l].splice(s, 1);
|
|
834
|
+
}
|
|
835
|
+
return [c, p];
|
|
836
|
+
}
|
|
837
|
+
const It = "application/json;type=download";
|
|
838
|
+
function He(e, { create: t, lastMessageResponse: r, fetch: n, metadata: o }) {
|
|
839
|
+
t({
|
|
840
|
+
active_type: It,
|
|
841
|
+
active: { id: e }
|
|
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();
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
return c.direct = () => (i = "direct", c), c.url = () => (i = "url", c), c;
|
|
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");
|
|
861
|
+
const [
|
|
862
|
+
I,
|
|
863
|
+
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);
|
|
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,
|
|
882
|
+
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 }
|
|
904
|
+
];
|
|
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
|
|
917
|
+
});
|
|
918
|
+
const { url: F } = await m();
|
|
919
|
+
if (D === void 0) return F;
|
|
920
|
+
{
|
|
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);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
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), $;
|
|
931
|
+
{
|
|
932
|
+
const { ii: k } = await $;
|
|
933
|
+
return { ii: k };
|
|
934
|
+
}
|
|
935
|
+
}
|
|
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))
|
|
955
|
+
throw new Error("You may only modify the type or name for a scope's metadata");
|
|
956
|
+
P(y, F);
|
|
957
|
+
});
|
|
958
|
+
}
|
|
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", [
|
|
962
|
+
{
|
|
963
|
+
op: "add",
|
|
964
|
+
path: ["active", k, "queries", $],
|
|
965
|
+
value: { query: y, params: T, domain: C, context: D }
|
|
966
|
+
}
|
|
967
|
+
], !1, !1);
|
|
968
|
+
try {
|
|
969
|
+
const ne = await m(), { rows: ve } = ne;
|
|
970
|
+
return P("sessions", [
|
|
971
|
+
{
|
|
972
|
+
op: "add",
|
|
973
|
+
path: ["active", k, "queries", $, "agent_latency"],
|
|
974
|
+
value: Date.now() - F
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
op: "remove",
|
|
978
|
+
path: ["active", k, "queries", $]
|
|
979
|
+
}
|
|
980
|
+
], !1, !1), ve;
|
|
981
|
+
} catch (ne) {
|
|
982
|
+
throw ne;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
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);
|
|
995
|
+
}
|
|
996
|
+
function w(y, T) {
|
|
997
|
+
Z[y].forEach((C) => C(T));
|
|
998
|
+
}
|
|
999
|
+
return {
|
|
1000
|
+
uuid: o,
|
|
1001
|
+
environment: L,
|
|
1002
|
+
login: d,
|
|
1003
|
+
logout: p,
|
|
1004
|
+
log: ee,
|
|
1005
|
+
create: f,
|
|
1006
|
+
state: K,
|
|
1007
|
+
watch: G,
|
|
1008
|
+
upload: S,
|
|
1009
|
+
download: W,
|
|
1010
|
+
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
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
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");
|
|
1026
|
+
if (e.status === 201) {
|
|
1027
|
+
if (!t) {
|
|
1028
|
+
const r = await e.text();
|
|
1029
|
+
localStorage.setItem("sid", r), location.reload();
|
|
1030
|
+
}
|
|
1031
|
+
} else e.status === 200 ? t && (localStorage.removeItem("sid"), location.reload()) : console.warn("Issue Connecting To the API Server");
|
|
1032
|
+
}
|
|
1033
|
+
const Dt = (e) => {
|
|
1034
|
+
Ct();
|
|
1035
|
+
const t = function() {
|
|
1036
|
+
const n = new WebSocket(`wss://${je}`);
|
|
1037
|
+
return this.send = (o) => n.send(JSON.stringify(o)), this.close = (o) => {
|
|
1038
|
+
this.send({ type: "close", info: o }), n.close();
|
|
1039
|
+
}, 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,
|
|
1042
|
+
sid: () => localStorage.getItem("sid"),
|
|
1043
|
+
domain: window.location.host,
|
|
1044
|
+
Connection: t,
|
|
1045
|
+
uuid: ie,
|
|
1046
|
+
fetch,
|
|
1047
|
+
applyPatch: he,
|
|
1048
|
+
login: lt,
|
|
1049
|
+
logout: dt,
|
|
1050
|
+
variables: { LANGUAGES: Pt },
|
|
1051
|
+
reboot: () => window.location.reload()
|
|
1052
|
+
});
|
|
1053
|
+
return r.local = () => {
|
|
1054
|
+
localStorage.setItem("api", "local"), location.reload();
|
|
1055
|
+
}, r.remote = (n = "production") => {
|
|
1056
|
+
localStorage.setItem("api", "remote"), localStorage.setItem("mode", n), location.reload();
|
|
1057
|
+
}, r.close = () => {
|
|
1058
|
+
window.close();
|
|
1059
|
+
}, r;
|
|
1060
|
+
};
|
|
1061
|
+
function Lt() {
|
|
1062
|
+
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();
|
|
1066
|
+
e += 1;
|
|
1067
|
+
const S = window.opener ? window.opener : window.parent;
|
|
1068
|
+
try {
|
|
1069
|
+
return S.postMessage({
|
|
1070
|
+
...f,
|
|
1071
|
+
session: await r,
|
|
1072
|
+
requestId: E,
|
|
1073
|
+
index: e
|
|
1074
|
+
}, "*"), new Promise((P, x) => {
|
|
1075
|
+
n[E] = { resolve: P, reject: x };
|
|
1076
|
+
});
|
|
1077
|
+
} catch (P) {
|
|
1078
|
+
console.log("ERROR POSTING MESSAGE UP", f, P);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
let l = !1;
|
|
1082
|
+
addEventListener("message", async ({ data: f }) => {
|
|
1083
|
+
if (f.type === "setup" && !l)
|
|
1084
|
+
l = !0, t(f.session);
|
|
1085
|
+
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));
|
|
1093
|
+
};
|
|
1094
|
+
o[H] && (i[H] === void 0 || i[H] + 1 === f.ii ? z() : f.ii === i[H] || f.ii < i[H] || z());
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
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);
|
|
1121
|
+
}
|
|
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);
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
function O(f) {
|
|
1130
|
+
return I(f, [{ op: "add", path: ["active"], value: null }]);
|
|
1131
|
+
}
|
|
1132
|
+
function I(f, E, S = !0) {
|
|
1133
|
+
return S && g("mutated", f), p({ type: "interact", scope: f, patch: E });
|
|
1134
|
+
}
|
|
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;
|
|
1139
|
+
{
|
|
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);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
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();
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
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);
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
function L(f, E, S = []) {
|
|
1173
|
+
return p({ type: "tag", tag_type: f, target: E, context: S });
|
|
1174
|
+
}
|
|
1175
|
+
function q(f, E, S) {
|
|
1176
|
+
return p({ type: "login", provider: f, username: E, password: S });
|
|
1177
|
+
}
|
|
1178
|
+
function G(f, E, S, P = []) {
|
|
1179
|
+
return p({ type: "query", query: f, params: E, domain: S, context: P });
|
|
1180
|
+
}
|
|
1181
|
+
function V() {
|
|
1182
|
+
return p({ type: "logout" });
|
|
1183
|
+
}
|
|
1184
|
+
function K() {
|
|
1185
|
+
return p({ type: "disconnect" });
|
|
1186
|
+
}
|
|
1187
|
+
function W() {
|
|
1188
|
+
return p({ type: "reconnect" });
|
|
1189
|
+
}
|
|
1190
|
+
function te() {
|
|
1191
|
+
return p({ type: "synced" });
|
|
1192
|
+
}
|
|
1193
|
+
function ee(f) {
|
|
1194
|
+
return p({ type: "close", info: f });
|
|
1195
|
+
}
|
|
1196
|
+
return {
|
|
1197
|
+
embedded: !0,
|
|
1198
|
+
uuid: ie,
|
|
1199
|
+
environment: s,
|
|
1200
|
+
login: q,
|
|
1201
|
+
logout: V,
|
|
1202
|
+
create: v,
|
|
1203
|
+
state: N,
|
|
1204
|
+
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
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
async function Ut({ accept: e }) {
|
|
1220
|
+
return new Promise((t, r) => {
|
|
1221
|
+
const n = document.createElement("input");
|
|
1222
|
+
n.type = "file", n.accept = e, n.addEventListener("change", async (o) => {
|
|
1223
|
+
const i = o.target.files[0];
|
|
1224
|
+
t(i || null);
|
|
1225
|
+
}), n.click();
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
let U = window.__default_knowlearning_agent;
|
|
1229
|
+
function Te(e, t) {
|
|
1230
|
+
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;
|
|
1232
|
+
}
|
|
1233
|
+
function Be(e = {}) {
|
|
1234
|
+
if (U && !e.unique) return U;
|
|
1235
|
+
let t;
|
|
1236
|
+
try {
|
|
1237
|
+
t = window.self !== window.top;
|
|
1238
|
+
} catch {
|
|
1239
|
+
t = !0;
|
|
1240
|
+
}
|
|
1241
|
+
const r = t && !e.root ? Lt() : Dt(e);
|
|
1242
|
+
r.embed = Mt;
|
|
1243
|
+
const n = r.upload;
|
|
1244
|
+
return r.upload = async (o) => {
|
|
1245
|
+
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);
|
|
1249
|
+
}
|
|
1250
|
+
return n(o);
|
|
1251
|
+
}, U || (window.__default_knowlearning_agent = U = r), r;
|
|
1252
|
+
}
|
|
1253
|
+
const de = (e) => JSON.parse(JSON.stringify(e));
|
|
1254
|
+
function Mt(e, t) {
|
|
1255
|
+
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 = () => {
|
|
1261
|
+
for (; t.parentNode && n.length; ) {
|
|
1262
|
+
const { message: h, sent: N } = n.shift();
|
|
1263
|
+
t.contentWindow.postMessage(h, "*"), N();
|
|
1264
|
+
}
|
|
1265
|
+
}, a = async (h) => {
|
|
1266
|
+
const { requestId: N, type: O } = h, I = (m, A) => p({ requestId: N, response: m, error: A });
|
|
1267
|
+
if (O === "error")
|
|
1268
|
+
console.error(h), I({});
|
|
1269
|
+
else if (O === "close")
|
|
1270
|
+
o.close && o.close(h.info);
|
|
1271
|
+
else if (O === "environment") {
|
|
1272
|
+
const { user: m } = h, { mode: A, variables: R = {} } = e, _ = await (o.environment ? o.environment(m) : U.environment(m));
|
|
1273
|
+
I({
|
|
1274
|
+
..._,
|
|
1275
|
+
context: [
|
|
1276
|
+
..._.context || [],
|
|
1277
|
+
e.id
|
|
1278
|
+
],
|
|
1279
|
+
variables: {
|
|
1280
|
+
..._.variables || {},
|
|
1281
|
+
...R
|
|
1282
|
+
},
|
|
1283
|
+
mode: A
|
|
1284
|
+
// TODO: deprecate
|
|
1285
|
+
});
|
|
1286
|
+
} 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
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
I({});
|
|
1300
|
+
} 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, _));
|
|
1306
|
+
} 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);
|
|
1309
|
+
} else if (O === "patch") {
|
|
1310
|
+
const { root: m, scopes: A } = h;
|
|
1311
|
+
I(await U.patch(m, A));
|
|
1312
|
+
} 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));
|
|
1315
|
+
} else if (O === "upload") {
|
|
1316
|
+
const { info: m } = h;
|
|
1317
|
+
I(await U.upload(m));
|
|
1318
|
+
} else if (O === "download")
|
|
1319
|
+
I(await U.download(h.id).url());
|
|
1320
|
+
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({}));
|
|
1324
|
+
};
|
|
1325
|
+
window.addEventListener("message", ({ data: h }) => {
|
|
1326
|
+
h.session === d && (c = !0, a(h));
|
|
1327
|
+
}), 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;
|
|
1337
|
+
for (; !c; )
|
|
1338
|
+
p({ type: "setup", session: d }), await new Promise((O) => setTimeout(O, 100));
|
|
1339
|
+
o.open && o.open();
|
|
1340
|
+
}
|
|
1341
|
+
function v() {
|
|
1342
|
+
t.parentNode && t.parentNode.removeChild(t);
|
|
1343
|
+
}
|
|
1344
|
+
function u(h, N) {
|
|
1345
|
+
o[h] = N;
|
|
1346
|
+
}
|
|
1347
|
+
function g(h, N) {
|
|
1348
|
+
p({ type: "auth", token: h, state: N });
|
|
1349
|
+
}
|
|
1350
|
+
return {
|
|
1351
|
+
auth: g,
|
|
1352
|
+
remove: v,
|
|
1353
|
+
on: u
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
window.Agent = Be();
|