@flaxia/node 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/assets/ai-inference.js +83 -175
- package/dist/assets/ai-model-registry.js +127 -0
- package/dist/assets/cc-extract.js +5166 -0
- package/dist/assets/decision.js +142 -0
- package/dist/assets/embed-gemma.js +97 -0
- package/dist/assets/transformers.web.js +2 -2
- package/dist/assets/vector-embed.js +136 -26
- package/dist/assets/webgpuProbe.js +83 -66
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/light-preloader.d.ts +19 -5
- package/dist/client/light-preloader.d.ts.map +1 -1
- package/dist/consent/notice.d.ts +3 -1
- package/dist/consent/notice.d.ts.map +1 -1
- package/dist/executor/WorkerPool.d.ts +1 -0
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +392 -365
- package/dist/worker.js +130 -121
- package/dist/workloads/__tests__/ai-model-registry.test.d.ts +2 -0
- package/dist/workloads/__tests__/ai-model-registry.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/cc-extract.test.d.ts +2 -0
- package/dist/workloads/__tests__/cc-extract.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/decision.test.d.ts +2 -0
- package/dist/workloads/__tests__/decision.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/embed-gemma.test.d.ts +2 -0
- package/dist/workloads/__tests__/embed-gemma.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/wasm-threads.test.d.ts.map +1 -1
- package/dist/workloads/ai-inference.d.ts +30 -2
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/ai-model-registry.d.ts.map +1 -1
- package/dist/workloads/cc-extract.d.ts +11 -0
- package/dist/workloads/cc-extract.d.ts.map +1 -0
- package/dist/workloads/decision.d.ts +21 -0
- package/dist/workloads/decision.d.ts.map +1 -0
- package/dist/workloads/embed-gemma.d.ts +8 -0
- package/dist/workloads/embed-gemma.d.ts.map +1 -0
- package/dist/workloads/vector-embed.d.ts +10 -0
- package/dist/workloads/vector-embed.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import { a as
|
|
1
|
+
import { B as e, C as t, E as n, F as r, I as i, K as a, L as o, M as s, P as c, d as l, f as u, h as d, i as f, k as p, m as ee, n as m, o as h, r as g, u as _, w as v } from "./assets/webgpuProbe.js";
|
|
2
|
+
import { t as y } from "./assets/egress-guard.js";
|
|
3
|
+
import { a as te, c as b, i as ne, l as re, n as ie, o as ae, r as oe, t as se } from "./assets/ai-inference.js";
|
|
4
4
|
//#region src/consent/notice.ts
|
|
5
5
|
var x = {
|
|
6
6
|
summary: "同意すると、このブラウザは第三者から依頼された処理をバックグラウンドで実行します。",
|
|
@@ -13,34 +13,34 @@ var x = {
|
|
|
13
13
|
acceptGateHint: "開示内容を確認できるよう、「同意して開始」はしばらくの間押せません。",
|
|
14
14
|
acceptLabel: "同意して開始",
|
|
15
15
|
rejectLabel: "拒否"
|
|
16
|
-
},
|
|
17
|
-
function
|
|
16
|
+
}, ce = 4320 * 60 * 60 * 1e3, S = "flaxia_consent_record", le = "flaxia_consent_granted", ue = "flaxia_consent_expiry", C = "flaxia_consent_denied", de = 1, fe = 1e4, pe = 2e3, me = "flaxia-consent-integrity", he = 1, w = "keys", ge = "consent-hmac-sha256-v1", _e = (...e) => console.warn("[flaxia-node]", ...e), ve = /* @__PURE__ */ new Map();
|
|
17
|
+
function ye(e) {
|
|
18
18
|
try {
|
|
19
19
|
return localStorage.getItem(e);
|
|
20
20
|
} catch {
|
|
21
|
-
return
|
|
21
|
+
return ve.get(e) ?? null;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function be(e, t) {
|
|
25
25
|
try {
|
|
26
26
|
localStorage.setItem(e, t);
|
|
27
27
|
} catch {
|
|
28
|
-
|
|
28
|
+
ve.set(e, t);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
function T(e) {
|
|
32
32
|
try {
|
|
33
33
|
localStorage.removeItem(e);
|
|
34
34
|
} catch {
|
|
35
|
-
|
|
35
|
+
ve.delete(e);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function xe(e) {
|
|
39
39
|
return new Promise((t, n) => {
|
|
40
40
|
e.onsuccess = () => t(e.result), e.onerror = () => n(e.error ?? /* @__PURE__ */ Error("IndexedDB request failed"));
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function Se() {
|
|
44
44
|
return new Promise((e, t) => {
|
|
45
45
|
let n;
|
|
46
46
|
try {
|
|
@@ -54,7 +54,7 @@ function E() {
|
|
|
54
54
|
}
|
|
55
55
|
let r;
|
|
56
56
|
try {
|
|
57
|
-
r = n.open(
|
|
57
|
+
r = n.open(me, he);
|
|
58
58
|
} catch (e) {
|
|
59
59
|
t(e);
|
|
60
60
|
return;
|
|
@@ -65,26 +65,26 @@ function E() {
|
|
|
65
65
|
}, r.onsuccess = () => e(r.result), r.onerror = () => t(r.error ?? /* @__PURE__ */ Error("IndexedDB open failed")), r.onblocked = () => t(/* @__PURE__ */ Error("IndexedDB open blocked"));
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function Ce(e) {
|
|
69
69
|
if (!e || typeof e != "object") return !1;
|
|
70
70
|
let t = e;
|
|
71
71
|
return t.type === "secret" && t.algorithm?.name === "HMAC";
|
|
72
72
|
}
|
|
73
|
-
var
|
|
73
|
+
var we = {
|
|
74
74
|
async load() {
|
|
75
|
-
let e = await
|
|
75
|
+
let e = await Se();
|
|
76
76
|
try {
|
|
77
|
-
let t = await
|
|
78
|
-
return
|
|
77
|
+
let t = await xe(e.transaction(w, "readonly").objectStore(w).get(ge));
|
|
78
|
+
return Ce(t) ? t : null;
|
|
79
79
|
} finally {
|
|
80
80
|
e.close();
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
async save(e) {
|
|
84
|
-
let t = await
|
|
84
|
+
let t = await Se();
|
|
85
85
|
try {
|
|
86
86
|
let n = t.transaction(w, "readwrite");
|
|
87
|
-
n.objectStore(w).put(e,
|
|
87
|
+
n.objectStore(w).put(e, ge), await new Promise((e, t) => {
|
|
88
88
|
n.oncomplete = () => e(), n.onerror = () => t(n.error ?? /* @__PURE__ */ Error("IndexedDB write failed")), n.onabort = () => t(n.error ?? /* @__PURE__ */ Error("IndexedDB write aborted"));
|
|
89
89
|
});
|
|
90
90
|
} finally {
|
|
@@ -92,10 +92,10 @@ var ye = {
|
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
94
|
async clear() {
|
|
95
|
-
let e = await
|
|
95
|
+
let e = await Se();
|
|
96
96
|
try {
|
|
97
97
|
let t = e.transaction(w, "readwrite");
|
|
98
|
-
t.objectStore(w).delete(
|
|
98
|
+
t.objectStore(w).delete(ge), await new Promise((e, n) => {
|
|
99
99
|
t.oncomplete = () => e(), t.onerror = () => n(t.error ?? /* @__PURE__ */ Error("IndexedDB delete failed")), t.onabort = () => n(t.error ?? /* @__PURE__ */ Error("IndexedDB delete aborted"));
|
|
100
100
|
});
|
|
101
101
|
} finally {
|
|
@@ -103,7 +103,7 @@ var ye = {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
|
-
function
|
|
106
|
+
function Te(e, t, n) {
|
|
107
107
|
return new Promise((r) => {
|
|
108
108
|
let i = !1, a, o = (e) => {
|
|
109
109
|
i || (i = !0, a !== void 0 && clearTimeout(a), r(e));
|
|
@@ -111,26 +111,26 @@ function be(e, t, n) {
|
|
|
111
111
|
a = setTimeout(() => o(t), n), e.then((e) => o(e), () => o(t));
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
var
|
|
115
|
-
function
|
|
114
|
+
var Ee = we, E = null, D = null, O = !1, k = !1, A = null, j = 0, M = 0, N = null, De = !1;
|
|
115
|
+
function Oe() {
|
|
116
116
|
try {
|
|
117
117
|
let e = globalThis.location?.origin;
|
|
118
118
|
if (typeof e == "string" && e.length > 0) return e;
|
|
119
119
|
} catch {}
|
|
120
120
|
return "unknown";
|
|
121
121
|
}
|
|
122
|
-
var
|
|
122
|
+
var ke = Oe, Ae = () => ke(), je = {
|
|
123
123
|
name: "HMAC",
|
|
124
124
|
hash: "SHA-256"
|
|
125
125
|
};
|
|
126
|
-
function
|
|
126
|
+
function P() {
|
|
127
127
|
try {
|
|
128
128
|
let e = globalThis.crypto?.subtle;
|
|
129
129
|
if (e && typeof e.generateKey == "function" && typeof e.sign == "function" && typeof e.verify == "function") return e;
|
|
130
130
|
} catch {}
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function Me(e) {
|
|
134
134
|
let t = new TextEncoder().encode(JSON.stringify([
|
|
135
135
|
e.v,
|
|
136
136
|
e.noticeVersion,
|
|
@@ -140,12 +140,12 @@ function De(e) {
|
|
|
140
140
|
])), n = new Uint8Array(t.byteLength);
|
|
141
141
|
return n.set(t), n;
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function Ne(e) {
|
|
144
144
|
let t = "";
|
|
145
145
|
for (let n of e) t += String.fromCharCode(n);
|
|
146
146
|
return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
147
147
|
}
|
|
148
|
-
function
|
|
148
|
+
function Pe(e) {
|
|
149
149
|
try {
|
|
150
150
|
let t = e.replace(/-/g, "+").replace(/_/g, "/"), n = t + "=".repeat((4 - t.length % 4) % 4), r = atob(n), i = new Uint8Array(r.length);
|
|
151
151
|
for (let e = 0; e < r.length; e += 1) i[e] = r.charCodeAt(e);
|
|
@@ -154,40 +154,40 @@ function ke(e) {
|
|
|
154
154
|
return null;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
async function
|
|
158
|
-
let e = await
|
|
157
|
+
async function Fe() {
|
|
158
|
+
let e = await Te(Ee.load(), null, pe);
|
|
159
159
|
if (e) return e;
|
|
160
|
-
let t =
|
|
160
|
+
let t = P();
|
|
161
161
|
if (!t) return null;
|
|
162
162
|
try {
|
|
163
|
-
let e = await t.generateKey(
|
|
164
|
-
return await
|
|
163
|
+
let e = await t.generateKey(je, !1, ["sign", "verify"]);
|
|
164
|
+
return await Te(Ee.save(e), void 0, pe), e;
|
|
165
165
|
} catch {
|
|
166
166
|
return null;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
async function
|
|
170
|
-
let t =
|
|
171
|
-
if (!t || !
|
|
169
|
+
async function Ie(e) {
|
|
170
|
+
let t = P();
|
|
171
|
+
if (!t || !E) return null;
|
|
172
172
|
try {
|
|
173
|
-
let n = await t.sign("HMAC",
|
|
174
|
-
return
|
|
173
|
+
let n = await t.sign("HMAC", E, Me(e));
|
|
174
|
+
return Ne(new Uint8Array(n));
|
|
175
175
|
} catch {
|
|
176
176
|
return null;
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
async function
|
|
180
|
-
let t =
|
|
181
|
-
if (!t || !
|
|
182
|
-
let n =
|
|
179
|
+
async function Le(e) {
|
|
180
|
+
let t = P();
|
|
181
|
+
if (!t || !E || !e.mac) return !1;
|
|
182
|
+
let n = Pe(e.mac);
|
|
183
183
|
if (!n) return !1;
|
|
184
184
|
try {
|
|
185
|
-
return await t.verify("HMAC",
|
|
185
|
+
return await t.verify("HMAC", E, n, Me(e));
|
|
186
186
|
} catch {
|
|
187
187
|
return !1;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function Re(e) {
|
|
191
191
|
if (!e) return null;
|
|
192
192
|
try {
|
|
193
193
|
let t = JSON.parse(e);
|
|
@@ -205,128 +205,128 @@ function Ne(e) {
|
|
|
205
205
|
return null;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function ze(e, t) {
|
|
209
209
|
return !(!Number.isFinite(e.grantedAt) || !Number.isFinite(e.expiry) || e.expiry <= t || e.grantedAt > e.expiry || e.expiry - e.grantedAt > 15552e6);
|
|
210
210
|
}
|
|
211
|
-
function
|
|
212
|
-
return e.v ===
|
|
211
|
+
function F(e) {
|
|
212
|
+
return e.v === de && e.noticeVersion === 3 && e.origin === Ae();
|
|
213
213
|
}
|
|
214
|
-
function
|
|
215
|
-
return
|
|
214
|
+
function I() {
|
|
215
|
+
return Re(ye(S));
|
|
216
216
|
}
|
|
217
|
-
function
|
|
218
|
-
|
|
217
|
+
function Be(e) {
|
|
218
|
+
be(S, JSON.stringify(e));
|
|
219
219
|
}
|
|
220
220
|
function L() {
|
|
221
221
|
T(S);
|
|
222
222
|
}
|
|
223
223
|
function R() {
|
|
224
|
-
T(
|
|
224
|
+
T(le), T(ue);
|
|
225
225
|
}
|
|
226
|
-
var
|
|
227
|
-
let e =
|
|
228
|
-
return !e || !
|
|
229
|
-
},
|
|
230
|
-
async function
|
|
231
|
-
let e = ++
|
|
226
|
+
var Ve = () => {
|
|
227
|
+
let e = D;
|
|
228
|
+
return !e || !O ? !1 : ze(e, Date.now()) && F(e);
|
|
229
|
+
}, He = () => ye(C) === "true", z = () => Ve() ? "granted" : He() ? "denied" : "unset", B = () => (A ||= Ue(), A);
|
|
230
|
+
async function Ue() {
|
|
231
|
+
let e = ++j, t = M, n = null;
|
|
232
232
|
try {
|
|
233
|
-
n = await
|
|
233
|
+
n = await Fe();
|
|
234
234
|
} catch {
|
|
235
235
|
n = null;
|
|
236
236
|
}
|
|
237
|
-
if (e !==
|
|
238
|
-
|
|
239
|
-
let r =
|
|
240
|
-
return r !== null && await
|
|
237
|
+
if (e !== j) return z();
|
|
238
|
+
E = n, R();
|
|
239
|
+
let r = I();
|
|
240
|
+
return r !== null && await Le(r) && ze(r, Date.now()) && F(r) && r ? t === M && e === j && (D = r, O = !0) : r && !k && (L(), t === M && e === j && (D = null, O = !1)), z();
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
let e =
|
|
244
|
-
return
|
|
242
|
+
function We() {
|
|
243
|
+
let e = N;
|
|
244
|
+
return N = null, e && Date.now() - e.at <= fe ? {
|
|
245
245
|
noticeVersion: e.noticeVersion,
|
|
246
246
|
source: "user-gesture"
|
|
247
|
-
} :
|
|
248
|
-
noticeVersion:
|
|
247
|
+
} : De ? {
|
|
248
|
+
noticeVersion: 3,
|
|
249
249
|
source: "host-managed"
|
|
250
250
|
} : null;
|
|
251
251
|
}
|
|
252
|
-
function
|
|
253
|
-
return typeof e != "number" || !Number.isFinite(e) || e <= 0 ?
|
|
252
|
+
function Ge(e) {
|
|
253
|
+
return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? ce : Math.min(Math.floor(e), ce);
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function Ke(e, t) {
|
|
256
256
|
let n = Date.now();
|
|
257
257
|
return {
|
|
258
|
-
v:
|
|
258
|
+
v: de,
|
|
259
259
|
noticeVersion: e,
|
|
260
|
-
origin:
|
|
260
|
+
origin: Ae(),
|
|
261
261
|
grantedAt: n,
|
|
262
|
-
expiry: n +
|
|
262
|
+
expiry: n + Ge(t),
|
|
263
263
|
mac: ""
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function qe(e, t) {
|
|
267
267
|
T(C), R();
|
|
268
|
-
let n =
|
|
269
|
-
return
|
|
268
|
+
let n = Ke(e.noticeVersion, t);
|
|
269
|
+
return D = n, O = !0, k = !0, M += 1, Be(n), n;
|
|
270
270
|
}
|
|
271
|
-
async function
|
|
271
|
+
async function Je(e) {
|
|
272
272
|
try {
|
|
273
|
-
if (await B(),
|
|
274
|
-
let t = await
|
|
275
|
-
if (
|
|
273
|
+
if (await B(), D !== e) return;
|
|
274
|
+
let t = await Ie(e);
|
|
275
|
+
if (D !== e) return;
|
|
276
276
|
if (!t) {
|
|
277
|
-
L(),
|
|
277
|
+
L(), k = !1;
|
|
278
278
|
return;
|
|
279
279
|
}
|
|
280
280
|
let n = {
|
|
281
281
|
...e,
|
|
282
282
|
mac: t
|
|
283
283
|
};
|
|
284
|
-
|
|
284
|
+
D = n, O = !0, Be(n), k = !1;
|
|
285
285
|
} catch {
|
|
286
|
-
|
|
286
|
+
D === e && (L(), k = !1);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
var
|
|
290
|
-
let e =
|
|
289
|
+
var Ye = () => {
|
|
290
|
+
let e = We();
|
|
291
291
|
if (!e) {
|
|
292
|
-
|
|
292
|
+
_e("refusing programmatic consent grant: consent requires the built-in banner to be rendered and accepted by the visitor (see setHostManagedConsentAllowed for host-managed UIs)");
|
|
293
293
|
return;
|
|
294
294
|
}
|
|
295
|
-
|
|
296
|
-
},
|
|
297
|
-
|
|
295
|
+
Je(qe(e));
|
|
296
|
+
}, Xe = (e = 3) => {
|
|
297
|
+
N = {
|
|
298
298
|
noticeVersion: e,
|
|
299
299
|
at: Date.now()
|
|
300
300
|
};
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
},
|
|
304
|
-
L(), R(),
|
|
305
|
-
},
|
|
306
|
-
L(), R(), T(C),
|
|
307
|
-
},
|
|
308
|
-
async function
|
|
309
|
-
let e =
|
|
301
|
+
}, Ze = (e) => {
|
|
302
|
+
De = e === !0;
|
|
303
|
+
}, Qe = () => {
|
|
304
|
+
L(), R(), D = null, O = !1, k = !1, M += 1, be(C, "true");
|
|
305
|
+
}, $e = () => {
|
|
306
|
+
L(), R(), T(C), D = null, O = !1, k = !1, N = null, E = null, j += 1, M += 1, A = null, Te(Ee.clear(), void 0, pe);
|
|
307
|
+
}, et = ye, tt = be, nt = T;
|
|
308
|
+
async function rt() {
|
|
309
|
+
let e = M, t = I();
|
|
310
310
|
if (!t) {
|
|
311
|
-
|
|
311
|
+
D = null, O = !1;
|
|
312
312
|
return;
|
|
313
313
|
}
|
|
314
|
-
if (!
|
|
315
|
-
if (!
|
|
316
|
-
|
|
314
|
+
if (!P()) return;
|
|
315
|
+
if (!E) {
|
|
316
|
+
A = null, await B();
|
|
317
317
|
return;
|
|
318
318
|
}
|
|
319
|
-
let n = await
|
|
320
|
-
if (e !==
|
|
321
|
-
let i = n &&
|
|
322
|
-
|
|
319
|
+
let n = await Le(t), r = I();
|
|
320
|
+
if (e !== M || !r || JSON.stringify(r) !== JSON.stringify(t)) return;
|
|
321
|
+
let i = n && ze(t, Date.now()) && F(t);
|
|
322
|
+
D = i ? t : null, O = i;
|
|
323
323
|
}
|
|
324
324
|
try {
|
|
325
325
|
typeof globalThis.addEventListener == "function" && globalThis.addEventListener("storage", (e) => {
|
|
326
|
-
e.key !== null && e.key !== S && e.key !== C || (
|
|
326
|
+
e.key !== null && e.key !== S && e.key !== C || (M += 1, rt());
|
|
327
327
|
});
|
|
328
328
|
} catch {}
|
|
329
|
-
var
|
|
329
|
+
var it = () => {
|
|
330
330
|
try {
|
|
331
331
|
if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
|
|
332
332
|
} catch {}
|
|
@@ -338,35 +338,35 @@ var $e = () => {
|
|
|
338
338
|
B();
|
|
339
339
|
//#endregion
|
|
340
340
|
//#region src/consent/ConsentUI.ts
|
|
341
|
-
var
|
|
341
|
+
var V = "#6366f1", at = 1500, ot = 1500, st = 6e4, ct = 80, lt = 40, ut = [
|
|
342
342
|
"bottom-right",
|
|
343
343
|
"bottom-left",
|
|
344
344
|
"top-right",
|
|
345
345
|
"top-left"
|
|
346
|
-
],
|
|
347
|
-
function
|
|
348
|
-
if (typeof e != "string") return
|
|
346
|
+
], dt = /^#[0-9a-f]{3}$/i, ft = /^#[0-9a-f]{6}$/i, pt = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i, mt = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+)\s*\)$/i, ht = new Map((/* @__PURE__ */ "black.white.red.green.blue.indigo.violet.purple.teal.cyan.orange.pink.brown.gray.grey.slate.navy.maroon.olive.gold.crimson.tomato.salmon.coral.seagreen.steelblue.royalblue.dodgerblue.mediumseagreen.mediumpurple.rebeccapurple".split(".")).map((e) => [e, e]));
|
|
347
|
+
function gt(e) {
|
|
348
|
+
if (typeof e != "string") return V;
|
|
349
349
|
let t = e.trim();
|
|
350
|
-
if (t.length === 0 || t.length > 64) return
|
|
351
|
-
if (
|
|
352
|
-
let n =
|
|
350
|
+
if (t.length === 0 || t.length > 64) return V;
|
|
351
|
+
if (dt.test(t) || ft.test(t)) return t.toLowerCase();
|
|
352
|
+
let n = pt.exec(t);
|
|
353
353
|
if (n) {
|
|
354
354
|
let [e, t, r] = n.slice(1).map(Number);
|
|
355
|
-
return e <= 255 && t <= 255 && r <= 255 ? `rgb(${e}, ${t}, ${r})` :
|
|
355
|
+
return e <= 255 && t <= 255 && r <= 255 ? `rgb(${e}, ${t}, ${r})` : V;
|
|
356
356
|
}
|
|
357
|
-
let r =
|
|
357
|
+
let r = mt.exec(t);
|
|
358
358
|
if (r) {
|
|
359
359
|
let [e, t, n] = r.slice(1, 4).map(Number), i = Number(r[4]);
|
|
360
|
-
return e <= 255 && t <= 255 && n <= 255 && i >= 0 && i <= 1 ? `rgba(${e}, ${t}, ${n}, ${i})` :
|
|
360
|
+
return e <= 255 && t <= 255 && n <= 255 && i >= 0 && i <= 1 ? `rgba(${e}, ${t}, ${n}, ${i})` : V;
|
|
361
361
|
}
|
|
362
|
-
return
|
|
362
|
+
return ht.get(t.toLowerCase()) ?? V;
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function _t(e, t, n) {
|
|
365
365
|
if (typeof e != "string") return t;
|
|
366
366
|
let r = e.replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2066-\u2069]/g, "").replace(/\s+/g, " ").trim();
|
|
367
367
|
return r.length === 0 ? t : r.length > n ? `${r.slice(0, n)}…` : r;
|
|
368
368
|
}
|
|
369
|
-
function
|
|
369
|
+
function vt(e) {
|
|
370
370
|
if (typeof e != "string" || e.trim().length === 0) return null;
|
|
371
371
|
try {
|
|
372
372
|
let t = new URL(e.trim());
|
|
@@ -375,70 +375,70 @@ function pt(e) {
|
|
|
375
375
|
return null;
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function yt(e) {
|
|
379
379
|
return {
|
|
380
|
-
brandName:
|
|
381
|
-
position:
|
|
382
|
-
accentColor:
|
|
383
|
-
acceptLabel:
|
|
384
|
-
rejectLabel:
|
|
385
|
-
privacyPolicyUrl:
|
|
386
|
-
minVisibleMs:
|
|
380
|
+
brandName: _t(e?.brandName, "Flaxia Crowd", ct),
|
|
381
|
+
position: ut.includes(e?.position) ? e.position : "bottom-right",
|
|
382
|
+
accentColor: gt(e?.accentColor),
|
|
383
|
+
acceptLabel: _t(e?.acceptLabel, x.acceptLabel, lt),
|
|
384
|
+
rejectLabel: _t(e?.rejectLabel, x.rejectLabel, lt),
|
|
385
|
+
privacyPolicyUrl: vt(e?.privacyPolicyUrl),
|
|
386
|
+
minVisibleMs: bt(e?.minVisibleMs)
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
|
-
function
|
|
390
|
-
return typeof e != "number" || !Number.isFinite(e) ?
|
|
389
|
+
function bt(e) {
|
|
390
|
+
return typeof e != "number" || !Number.isFinite(e) ? at : Math.min(Math.max(Math.floor(e), ot), st);
|
|
391
391
|
}
|
|
392
|
-
function
|
|
393
|
-
return typeof t.minVisibleMs == "number" && Number.isFinite(t.minVisibleMs) ? Math.min(Math.max(Math.floor(t.minVisibleMs), 0),
|
|
392
|
+
function xt(e, t) {
|
|
393
|
+
return typeof t.minVisibleMs == "number" && Number.isFinite(t.minVisibleMs) ? Math.min(Math.max(Math.floor(t.minVisibleMs), 0), st) : e;
|
|
394
394
|
}
|
|
395
|
-
var
|
|
395
|
+
var St = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n padding: 20px;\n background: #fff;\n color: #1f2937;\n border: 1px solid #ccc;\n box-shadow: 0 4px 6px rgba(0,0,0,0.1);\n z-index: 9999;\n border-radius: 8px;\n max-width: 300px;\n font-family: sans-serif;\n }\n .overlay h3 {\n margin: 0 0 8px;\n color: #111827;\n font-size: 16px;\n }\n .overlay p {\n margin: 0 0 12px;\n color: #4b5563;\n font-size: 14px;\n line-height: 1.4;\n }\n .overlay ul {\n margin: 0 0 12px;\n padding-left: 18px;\n color: #4b5563;\n font-size: 13px;\n line-height: 1.45;\n }\n .overlay li {\n margin-bottom: 6px;\n }\n .overlay .hint {\n margin: 0 0 8px;\n color: #6b7280;\n font-size: 12px;\n }\n .overlay .privacy {\n margin: 0 0 8px;\n font-size: 12px;\n }\n .overlay .privacy a {\n color: __flaxia_accent__;\n }\n button {\n background: __flaxia_accent__;\n color: white;\n border: none;\n padding: 10px 15px;\n border-radius: 4px;\n cursor: pointer;\n margin-top: 10px;\n width: 100%;\n font-size: 14px;\n }\n button:disabled {\n opacity: 0.6;\n cursor: default;\n }\n button.reject {\n background: transparent;\n color: #4b5563;\n border: 1px solid #ccc;\n }\n @media (prefers-color-scheme: dark) {\n .overlay {\n background: #1f2937;\n color: #f9fafb;\n border-color: #374151;\n box-shadow: 0 4px 6px rgba(0,0,0,0.4);\n }\n .overlay h3 {\n color: #f9fafb;\n }\n .overlay p,\n .overlay ul {\n color: #d1d5db;\n }\n .overlay .hint {\n color: #9ca3af;\n }\n button.reject {\n color: #d1d5db;\n border-color: #4b5563;\n }\n }\n", Ct = class {
|
|
396
396
|
constructor(e, t, n, r, i) {
|
|
397
|
-
this.config =
|
|
397
|
+
this.config = yt(t), this.options = i ?? {}, this.root = e.attachShadow({ mode: "closed" }), this.render(n, r);
|
|
398
398
|
}
|
|
399
399
|
shadowRootForTesting() {
|
|
400
400
|
return this.root;
|
|
401
401
|
}
|
|
402
402
|
render(e, t) {
|
|
403
403
|
let { brandName: n, position: r, accentColor: i, acceptLabel: a, rejectLabel: o, privacyPolicyUrl: s } = this.config, [c, l] = r.split("-"), u = document.createElement("style");
|
|
404
|
-
u.textContent =
|
|
404
|
+
u.textContent = St.replace(/__flaxia_accent__/g, i).replace("__flaxia_position__", `${c}: 20px; ${l}: 20px`);
|
|
405
405
|
let d = document.createElement("div");
|
|
406
406
|
d.className = "overlay", d.setAttribute("role", "dialog"), d.setAttribute("aria-labelledby", "flaxia-consent-title");
|
|
407
407
|
let f = document.createElement("h3");
|
|
408
408
|
f.id = "flaxia-consent-title", f.textContent = n;
|
|
409
409
|
let p = document.createElement("p");
|
|
410
410
|
p.textContent = x.summary;
|
|
411
|
-
let
|
|
411
|
+
let ee = document.createElement("ul");
|
|
412
412
|
for (let e of x.items) {
|
|
413
413
|
let t = document.createElement("li");
|
|
414
|
-
t.textContent = e,
|
|
414
|
+
t.textContent = e, ee.appendChild(t);
|
|
415
415
|
}
|
|
416
|
-
if (d.append(f, p,
|
|
416
|
+
if (d.append(f, p, ee), s) {
|
|
417
417
|
let e = document.createElement("p");
|
|
418
418
|
e.className = "privacy";
|
|
419
419
|
let t = document.createElement("a");
|
|
420
420
|
t.href = s, t.target = "_blank", t.rel = "noopener noreferrer", t.textContent = "プライバシーポリシー", e.appendChild(t), d.appendChild(e);
|
|
421
421
|
}
|
|
422
|
-
let
|
|
423
|
-
|
|
422
|
+
let m = document.createElement("p");
|
|
423
|
+
m.className = "hint", m.textContent = x.acceptGateHint;
|
|
424
|
+
let h = document.createElement("button");
|
|
425
|
+
h.id = "consent-btn", h.type = "button", h.textContent = a;
|
|
424
426
|
let g = document.createElement("button");
|
|
425
|
-
g.id = "
|
|
426
|
-
let _ =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
b || (g.disabled = !0, g.setAttribute("aria-disabled", "true"), ee(() => {
|
|
430
|
-
b = !0, g.disabled = !1, g.removeAttribute("aria-disabled"), h.remove();
|
|
427
|
+
g.id = "reject-btn", g.type = "button", g.className = "reject", g.textContent = o;
|
|
428
|
+
let _ = this.options.now ?? (() => Date.now()), v = this.options.schedule ?? ((e, t) => void setTimeout(e, t)), y = xt(this.config.minVisibleMs, this.options), te = _() + y, b = y <= 0, ne = !1;
|
|
429
|
+
b || (h.disabled = !0, h.setAttribute("aria-disabled", "true"), v(() => {
|
|
430
|
+
b = !0, h.disabled = !1, h.removeAttribute("aria-disabled"), m.remove();
|
|
431
431
|
}, y));
|
|
432
432
|
let re = (e) => {
|
|
433
433
|
ne || (ne = !0, d.remove(), e?.());
|
|
434
434
|
};
|
|
435
|
-
|
|
436
|
-
!b ||
|
|
437
|
-
}),
|
|
435
|
+
h.addEventListener("click", () => {
|
|
436
|
+
!b || _() < te || (Xe(3), re(e));
|
|
437
|
+
}), g.addEventListener("click", () => {
|
|
438
438
|
re(t);
|
|
439
|
-
}), b || d.appendChild(
|
|
439
|
+
}), b || d.appendChild(m), d.append(h, g), this.root.append(u, d);
|
|
440
440
|
}
|
|
441
|
-
},
|
|
441
|
+
}, H = (...e) => console.log("[flaxia-node]", ...e), wt = class e {
|
|
442
442
|
static {
|
|
443
443
|
this.MAX_PENDING_CONTROLS = 64;
|
|
444
444
|
}
|
|
@@ -461,73 +461,73 @@ var _t = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
461
461
|
return;
|
|
462
462
|
}
|
|
463
463
|
let l = () => this.execute(e, t, n, r, i, a, s, c, o);
|
|
464
|
-
this.active ? (
|
|
464
|
+
this.active ? (H(`task queued id=${e} workload=${t} (active task running)`), this.queue.push({
|
|
465
465
|
id: e,
|
|
466
466
|
job: l,
|
|
467
467
|
reject: c
|
|
468
468
|
})) : l();
|
|
469
469
|
});
|
|
470
470
|
}
|
|
471
|
-
execute(e, t, n, r, a,
|
|
472
|
-
let
|
|
473
|
-
if (!
|
|
474
|
-
|
|
471
|
+
execute(e, t, n, r, i, a, o, c, l) {
|
|
472
|
+
let u = this.worker;
|
|
473
|
+
if (!u) {
|
|
474
|
+
c(/* @__PURE__ */ Error("Worker not available")), this.dequeue();
|
|
475
475
|
return;
|
|
476
476
|
}
|
|
477
|
-
let
|
|
478
|
-
|
|
479
|
-
let
|
|
480
|
-
if (
|
|
481
|
-
|
|
477
|
+
let d = r ?? this.defaultTimeoutMs, f = !1, p = performance.now();
|
|
478
|
+
H(`task start id=${e} workload=${t} timeoutMs=${d}`);
|
|
479
|
+
let m = (t) => {
|
|
480
|
+
if (f) return;
|
|
481
|
+
f = !0;
|
|
482
482
|
let n = this.active;
|
|
483
483
|
n && (clearTimeout(n.timer), n.removeListener()), this.active = null, this.pendingControls = this.pendingControls.filter((t) => t.taskId !== e), t(), this.dequeue();
|
|
484
|
-
},
|
|
485
|
-
let { id: r, type:
|
|
484
|
+
}, h = (n) => {
|
|
485
|
+
let { id: r, type: a, result: u, error: d, token: f, cpuLoad: h } = n.data;
|
|
486
486
|
if (r === e) {
|
|
487
|
-
if (
|
|
488
|
-
|
|
487
|
+
if (ee(n.data.modelCache) && (this._modelCacheSnapshot = n.data.modelCache), a === "token") {
|
|
488
|
+
i?.(f);
|
|
489
489
|
return;
|
|
490
490
|
}
|
|
491
|
-
if (
|
|
492
|
-
typeof
|
|
491
|
+
if (a === "heartbeat") {
|
|
492
|
+
typeof h == "number" && Number.isFinite(h) && (this._lastCpuLoad = Math.min(1, Math.max(0, h)), this._hasCpuLoadSample = !0);
|
|
493
493
|
return;
|
|
494
494
|
}
|
|
495
|
-
if (
|
|
496
|
-
|
|
495
|
+
if (a === "swarm-frame") {
|
|
496
|
+
l?.onFrame?.(n.data.frame);
|
|
497
497
|
return;
|
|
498
498
|
}
|
|
499
|
-
if (
|
|
500
|
-
|
|
499
|
+
if (a === "swarm-message") {
|
|
500
|
+
l?.onMessage?.(n.data.message);
|
|
501
501
|
return;
|
|
502
502
|
}
|
|
503
|
-
if (
|
|
504
|
-
else if (
|
|
505
|
-
|
|
506
|
-
let r = typeof n.data.errorCode == "string" ? n.data.errorCode : "TASK_FAILED", i = typeof n.data.errorStatus == "number" ? n.data.errorStatus : 500, a = new
|
|
507
|
-
typeof n.data.detail == "string" && (a.detail = n.data.detail),
|
|
508
|
-
} else
|
|
503
|
+
if (a === "done") H(`task done id=${e} workload=${t} durationMs=${Math.round(performance.now() - p)}`), m(() => o(u));
|
|
504
|
+
else if (a === "error") {
|
|
505
|
+
H(`task failed id=${e} workload=${t} error=${d}`);
|
|
506
|
+
let r = typeof n.data.errorCode == "string" ? n.data.errorCode : "TASK_FAILED", i = typeof n.data.errorStatus == "number" ? n.data.errorStatus : 500, a = new s(String(d), r, i);
|
|
507
|
+
typeof n.data.detail == "string" && (a.detail = n.data.detail), m(() => c(a));
|
|
508
|
+
} else H(`task unknown-message id=${e} type=${String(a)}`), m(() => c(/* @__PURE__ */ Error(`Unknown message type: ${String(a)}`)));
|
|
509
509
|
}
|
|
510
|
-
},
|
|
511
|
-
|
|
512
|
-
},
|
|
510
|
+
}, g = () => u.removeEventListener("message", h), _ = setTimeout(() => {
|
|
511
|
+
H(`task timeout id=${e} workload=${t} (worker terminated after ${d}ms)`), this.cleanupWorker(), m(() => c(/* @__PURE__ */ Error("TIMEOUT")));
|
|
512
|
+
}, d);
|
|
513
513
|
this.active = {
|
|
514
514
|
id: e,
|
|
515
|
-
resolve:
|
|
516
|
-
reject:
|
|
517
|
-
timer:
|
|
518
|
-
worker:
|
|
519
|
-
removeListener:
|
|
520
|
-
},
|
|
515
|
+
resolve: o,
|
|
516
|
+
reject: c,
|
|
517
|
+
timer: _,
|
|
518
|
+
worker: u,
|
|
519
|
+
removeListener: g
|
|
520
|
+
}, u.addEventListener("message", h);
|
|
521
521
|
try {
|
|
522
|
-
|
|
522
|
+
u.postMessage({
|
|
523
523
|
id: e,
|
|
524
524
|
workload: t,
|
|
525
525
|
payload: n,
|
|
526
|
-
timeoutMs:
|
|
527
|
-
config:
|
|
526
|
+
timeoutMs: d,
|
|
527
|
+
config: a
|
|
528
528
|
}), this.flushControls();
|
|
529
529
|
} catch (e) {
|
|
530
|
-
|
|
530
|
+
m(() => c(e instanceof Error ? e : Error(String(e))));
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
flushControls() {
|
|
@@ -576,7 +576,7 @@ var _t = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
576
576
|
let n = this.queue.findIndex((t) => t.id === e);
|
|
577
577
|
if (n >= 0) {
|
|
578
578
|
let [r] = this.queue.splice(n, 1);
|
|
579
|
-
return this.pendingControls = this.pendingControls.filter((t) => t.taskId !== e),
|
|
579
|
+
return this.pendingControls = this.pendingControls.filter((t) => t.taskId !== e), H(`task aborted before start id=${e} reason=${t}`), r.reject(Error(t)), !0;
|
|
580
580
|
}
|
|
581
581
|
if (this.active?.id !== e || !this.worker) return !1;
|
|
582
582
|
try {
|
|
@@ -584,13 +584,13 @@ var _t = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
584
584
|
id: e,
|
|
585
585
|
type: "abort",
|
|
586
586
|
reason: t
|
|
587
|
-
}),
|
|
587
|
+
}), H(`task abort sent id=${e} reason=${t}`), !0;
|
|
588
588
|
} catch {
|
|
589
589
|
return !1;
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
592
|
handleWorkerError(e) {
|
|
593
|
-
|
|
593
|
+
H(`worker error error=${e.message}`);
|
|
594
594
|
let t = this.active;
|
|
595
595
|
this.cleanupWorker(), t && (clearTimeout(t.timer), this.active = null, t.reject(e), this.dequeue());
|
|
596
596
|
}
|
|
@@ -620,8 +620,8 @@ var _t = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
620
620
|
let e = this._modelCacheSnapshot;
|
|
621
621
|
return !e || e.expiresAt <= Date.now() ? null : e;
|
|
622
622
|
}
|
|
623
|
-
},
|
|
624
|
-
function
|
|
623
|
+
}, U = null, Tt = null;
|
|
624
|
+
function W(e, t, n, r, i, a) {
|
|
625
625
|
return {
|
|
626
626
|
value: e,
|
|
627
627
|
unit: t,
|
|
@@ -631,48 +631,48 @@ function G(e, t, n, r, i, a) {
|
|
|
631
631
|
sampleCount: a
|
|
632
632
|
};
|
|
633
633
|
}
|
|
634
|
-
function
|
|
635
|
-
return
|
|
634
|
+
function G(e, t, n) {
|
|
635
|
+
return W(null, e, "unknown", t, t + n, 0);
|
|
636
636
|
}
|
|
637
|
-
async function
|
|
638
|
-
return e ? ((!
|
|
639
|
-
|
|
640
|
-
}),
|
|
637
|
+
async function Et(e, t) {
|
|
638
|
+
return e ? ((!U || U.expiresAt <= t) && (Tt ||= m().then((e) => (U = e, e)).finally(() => {
|
|
639
|
+
Tt = null;
|
|
640
|
+
}), U = await Tt), U) : null;
|
|
641
641
|
}
|
|
642
|
-
async function
|
|
643
|
-
let t = e.now ?? Date.now(),
|
|
642
|
+
async function Dt(e) {
|
|
643
|
+
let t = e.now ?? Date.now(), r = t + u, i = f(), a = i.bytes !== null && i.sampledAt !== null && t - i.sampledAt <= 864e5, o = Number.isFinite(e.deviceMemory) && e.deviceMemory > 0 && e.deviceMemory <= 1024, s = await Et(e.probeGpu === !0, t), c = s?.sampledAt ?? t, l = s?.expiresAt ?? t + 6e5;
|
|
644
644
|
return {
|
|
645
645
|
version: 1,
|
|
646
646
|
sampledAt: t,
|
|
647
|
-
expiresAt:
|
|
648
|
-
cpuLoad: typeof e.cpuLoad == "number" && Number.isFinite(e.cpuLoad) && e.cpuLoad >= 0 && e.cpuLoad <= 1 ?
|
|
649
|
-
wasmMemoryLowerBound:
|
|
650
|
-
deviceMemory:
|
|
647
|
+
expiresAt: r,
|
|
648
|
+
cpuLoad: typeof e.cpuLoad == "number" && Number.isFinite(e.cpuLoad) && e.cpuLoad >= 0 && e.cpuLoad <= 1 ? W(e.cpuLoad, "ratio", "estimated", t, r, 1) : G("ratio", t, u),
|
|
649
|
+
wasmMemoryLowerBound: a ? W(i.bytes, "bytes", "measured", i.sampledAt, i.sampledAt + v, 1) : G("bytes", t, v),
|
|
650
|
+
deviceMemory: o ? W(e.deviceMemory, "GiB", "estimated", t, t + v, 1) : G("GiB", t, v),
|
|
651
651
|
gpu: {
|
|
652
|
-
status:
|
|
653
|
-
sampledAt:
|
|
654
|
-
expiresAt:
|
|
655
|
-
architecture:
|
|
656
|
-
maxStorageBufferBindingSize:
|
|
657
|
-
computeCompletionMs:
|
|
658
|
-
memoryBytes:
|
|
652
|
+
status: s?.status ?? "unknown",
|
|
653
|
+
sampledAt: c,
|
|
654
|
+
expiresAt: l,
|
|
655
|
+
architecture: s?.architecture ? W(s.architecture, "text", "measured", c, l, 1) : G("text", c, n),
|
|
656
|
+
maxStorageBufferBindingSize: s?.maxStorageBufferBindingSize !== null && s?.maxStorageBufferBindingSize !== void 0 ? W(s.maxStorageBufferBindingSize, "bytes", "measured", c, l, 1) : G("bytes", c, n),
|
|
657
|
+
computeCompletionMs: s?.computeCompletionMs !== null && s?.computeCompletionMs !== void 0 ? W(s.computeCompletionMs, "ms", "measured", c, l, s.sampleCount) : G("ms", c, n),
|
|
658
|
+
memoryBytes: G("bytes", c, n)
|
|
659
659
|
}
|
|
660
660
|
};
|
|
661
661
|
}
|
|
662
662
|
//#endregion
|
|
663
663
|
//#region src/swarm/peer-quality.ts
|
|
664
|
-
var
|
|
665
|
-
function
|
|
664
|
+
var Ot = 15e3;
|
|
665
|
+
function kt(e) {
|
|
666
666
|
let t = e.filter((e) => Number.isFinite(e) && e >= 0).slice(-5);
|
|
667
667
|
if (!t.length) return [];
|
|
668
668
|
let n = [...t].sort((e, t) => e - t), r = n[Math.floor(n.length / 2)], i = r + Math.max(20, r * 4);
|
|
669
669
|
return t.filter((e) => e <= i);
|
|
670
670
|
}
|
|
671
|
-
function
|
|
671
|
+
function K(e, t) {
|
|
672
672
|
return !Number.isFinite(e) || e < 0 || !Number.isFinite(t) || t <= 0 ? null : e * 8 / t / 1e3;
|
|
673
673
|
}
|
|
674
|
-
function
|
|
675
|
-
let n =
|
|
674
|
+
function At(e, t) {
|
|
675
|
+
let n = kt(e);
|
|
676
676
|
if (!n.length) return {
|
|
677
677
|
value: null,
|
|
678
678
|
sampledAt: t,
|
|
@@ -685,11 +685,11 @@ function Tt(e, t) {
|
|
|
685
685
|
sampleCount: n.length
|
|
686
686
|
};
|
|
687
687
|
}
|
|
688
|
-
function
|
|
688
|
+
function jt(e, t, n, r, i) {
|
|
689
689
|
let o = (e, n) => {
|
|
690
690
|
let r = (r) => {
|
|
691
691
|
let i = n?.[r] ?? t;
|
|
692
|
-
return t - i >= 6e4 ?
|
|
692
|
+
return t - i >= 6e4 ? At([], t) : At(e[r] ?? [], i);
|
|
693
693
|
};
|
|
694
694
|
return {
|
|
695
695
|
rttMs: r("rttMs"),
|
|
@@ -709,8 +709,8 @@ function Et(e, t, n, r, i) {
|
|
|
709
709
|
}
|
|
710
710
|
//#endregion
|
|
711
711
|
//#region src/swarm/peer-transport.ts
|
|
712
|
-
var
|
|
713
|
-
function
|
|
712
|
+
var Mt = 5e3, q = 16 * 1024, Nt = t, Pt = 256 * 1024, Ft = 1129860166, J = 16, It = 2, Lt = 64, Rt = "flaxia-swarm-v1", zt = "flaxia-peer-quality-v1", Bt = 128, Vt = [{ urls: "stun:stun.cloudflare.com:3478" }];
|
|
713
|
+
function Ht() {
|
|
714
714
|
return {
|
|
715
715
|
rttMs: [],
|
|
716
716
|
jitterMs: [],
|
|
@@ -718,41 +718,41 @@ function Lt() {
|
|
|
718
718
|
receiveMbps: []
|
|
719
719
|
};
|
|
720
720
|
}
|
|
721
|
-
function
|
|
722
|
-
if (e.byteLength <
|
|
721
|
+
function Ut(e) {
|
|
722
|
+
if (e.byteLength < J || e.byteLength > 16400) return null;
|
|
723
723
|
let t = new DataView(e);
|
|
724
|
-
if (t.getUint32(0, !0) !==
|
|
724
|
+
if (t.getUint32(0, !0) !== Ft) return null;
|
|
725
725
|
let n = t.getUint32(4, !0), r = t.getUint16(8, !0), i = t.getUint16(10, !0), a = t.getUint32(12, !0);
|
|
726
|
-
if (a < 1 || a >
|
|
727
|
-
let o = Math.min(
|
|
728
|
-
return e.byteLength -
|
|
726
|
+
if (a < 1 || a > Nt || i < 1 || i !== Math.ceil(a / 16384) || r >= i) return null;
|
|
727
|
+
let o = Math.min(q, a - r * q);
|
|
728
|
+
return e.byteLength - J === o ? {
|
|
729
729
|
messageId: n,
|
|
730
730
|
index: r,
|
|
731
731
|
count: i,
|
|
732
732
|
totalBytes: a,
|
|
733
|
-
payload: new Uint8Array(e,
|
|
733
|
+
payload: new Uint8Array(e, J)
|
|
734
734
|
} : null;
|
|
735
735
|
}
|
|
736
|
-
function
|
|
737
|
-
if (e.byteLength < 1 || e.byteLength >
|
|
738
|
-
let n = Math.ceil(e.byteLength /
|
|
736
|
+
function Wt(e, t) {
|
|
737
|
+
if (e.byteLength < 1 || e.byteLength > Nt) throw Error(`swarm peer frame size is outside 1..${Nt} bytes`);
|
|
738
|
+
let n = Math.ceil(e.byteLength / q), r = [];
|
|
739
739
|
for (let i = 0; i < n; i++) {
|
|
740
|
-
let a = i *
|
|
741
|
-
l.setUint32(0,
|
|
740
|
+
let a = i * q, o = Math.min(a + q, e.byteLength), s = new Uint8Array(e, a, o - a), c = new ArrayBuffer(J + s.byteLength), l = new DataView(c);
|
|
741
|
+
l.setUint32(0, Ft, !0), l.setUint32(4, t >>> 0, !0), l.setUint16(8, i, !0), l.setUint16(10, n, !0), l.setUint32(12, e.byteLength, !0), new Uint8Array(c, J).set(s), r.push(c);
|
|
742
742
|
}
|
|
743
743
|
return r;
|
|
744
744
|
}
|
|
745
|
-
var
|
|
745
|
+
var Gt = class {
|
|
746
746
|
constructor() {
|
|
747
747
|
this.assemblies = /* @__PURE__ */ new Map();
|
|
748
748
|
}
|
|
749
749
|
accept(e, t = Date.now()) {
|
|
750
750
|
this.expire(t);
|
|
751
|
-
let n =
|
|
751
|
+
let n = Ut(e);
|
|
752
752
|
if (!n) return null;
|
|
753
753
|
let r = this.assemblies.get(n.messageId);
|
|
754
754
|
if (!r) {
|
|
755
|
-
if (this.assemblies.size >=
|
|
755
|
+
if (this.assemblies.size >= It) return null;
|
|
756
756
|
r = {
|
|
757
757
|
count: n.count,
|
|
758
758
|
totalBytes: n.totalBytes,
|
|
@@ -782,9 +782,9 @@ var Bt = class {
|
|
|
782
782
|
expire(e) {
|
|
783
783
|
for (let [t, n] of this.assemblies) e - n.createdAt > 5e3 * 2 && this.assemblies.delete(t);
|
|
784
784
|
}
|
|
785
|
-
},
|
|
785
|
+
}, Kt = class {
|
|
786
786
|
constructor(e) {
|
|
787
|
-
this.options = e, this.peers = /* @__PURE__ */ new Map(), this.reassembler = new
|
|
787
|
+
this.options = e, this.peers = /* @__PURE__ */ new Map(), this.reassembler = new Gt(), this.nextMessageId = 1, this.mode = "undecided", this.closed = !1, this.failed = !1, this.readyPromise = null, this.readyResolve = null, this.readyTimer = null, this.qualityTimer = null, this.samplingQuality = !1;
|
|
788
788
|
}
|
|
789
789
|
get selectedMode() {
|
|
790
790
|
return this.mode;
|
|
@@ -798,15 +798,15 @@ var Bt = class {
|
|
|
798
798
|
let e = [...new Set([this.options.previousNodeId, this.options.nextNodeId])].filter((e) => !!e && e !== this.options.nodeId);
|
|
799
799
|
try {
|
|
800
800
|
for (let t of e) {
|
|
801
|
-
let e = (this.options.createPeerConnection ?? ((e) => new RTCPeerConnection(e)))({ iceServers:
|
|
801
|
+
let e = (this.options.createPeerConnection ?? ((e) => new RTCPeerConnection(e)))({ iceServers: Vt }), n = {
|
|
802
802
|
nodeId: t,
|
|
803
803
|
connection: e,
|
|
804
804
|
channel: null,
|
|
805
805
|
remoteDescriptionSet: !1,
|
|
806
806
|
pendingCandidates: [],
|
|
807
807
|
quality: {
|
|
808
|
-
webRtc:
|
|
809
|
-
application:
|
|
808
|
+
webRtc: Ht(),
|
|
809
|
+
application: Ht()
|
|
810
810
|
},
|
|
811
811
|
qualitySampledAt: {
|
|
812
812
|
webRtc: {},
|
|
@@ -836,7 +836,7 @@ var Bt = class {
|
|
|
836
836
|
for (let e of this.peers.values()) {
|
|
837
837
|
let { nodeId: t, connection: n } = e;
|
|
838
838
|
if (this.options.nodeId.localeCompare(t) < 0) {
|
|
839
|
-
this.bindChannel(e, n.createDataChannel(
|
|
839
|
+
this.bindChannel(e, n.createDataChannel(Rt, { ordered: !0 }));
|
|
840
840
|
let r = await n.createOffer();
|
|
841
841
|
if (this.closed || this.failed) return;
|
|
842
842
|
await n.setLocalDescription(r);
|
|
@@ -878,7 +878,7 @@ var Bt = class {
|
|
|
878
878
|
}
|
|
879
879
|
} else if (t.candidate !== null) if (n.remoteDescriptionSet) await n.connection.addIceCandidate(t.candidate);
|
|
880
880
|
else {
|
|
881
|
-
if (n.pendingCandidates.length >=
|
|
881
|
+
if (n.pendingCandidates.length >= Lt) throw Error("too many ICE candidates before remote description");
|
|
882
882
|
n.pendingCandidates.push(t.candidate);
|
|
883
883
|
}
|
|
884
884
|
} catch (e) {
|
|
@@ -908,7 +908,7 @@ var Bt = class {
|
|
|
908
908
|
}
|
|
909
909
|
let r = this.nextMessageId++ >>> 0;
|
|
910
910
|
try {
|
|
911
|
-
for (let t of
|
|
911
|
+
for (let t of Wt(e, r)) {
|
|
912
912
|
if (await this.waitForBuffer(n), n.readyState !== "open") throw Error("swarm peer data channel closed while sending");
|
|
913
913
|
n.send(t);
|
|
914
914
|
}
|
|
@@ -929,7 +929,7 @@ var Bt = class {
|
|
|
929
929
|
} catch {}
|
|
930
930
|
return;
|
|
931
931
|
}
|
|
932
|
-
e.channel = t, t.binaryType = "arraybuffer", t.bufferedAmountLowThreshold =
|
|
932
|
+
e.channel = t, t.binaryType = "arraybuffer", t.bufferedAmountLowThreshold = Pt / 2, t.onopen = () => this.resolveReadyIfOpen(), t.onmessage = (t) => {
|
|
933
933
|
if (typeof t.data == "string") {
|
|
934
934
|
this.handleQualityProbe(e, t.data);
|
|
935
935
|
return;
|
|
@@ -955,7 +955,7 @@ var Bt = class {
|
|
|
955
955
|
}
|
|
956
956
|
async waitForBuffer(e) {
|
|
957
957
|
e.bufferedAmount <= 262144 || await new Promise((t, n) => {
|
|
958
|
-
let r = setTimeout(() => i(/* @__PURE__ */ Error("swarm peer send buffer stalled")),
|
|
958
|
+
let r = setTimeout(() => i(/* @__PURE__ */ Error("swarm peer send buffer stalled")), Mt), i = (i) => {
|
|
959
959
|
clearTimeout(r), e.removeEventListener("bufferedamountlow", a), e.removeEventListener("close", o), i ? n(i) : t();
|
|
960
960
|
}, a = () => i(), o = () => i(/* @__PURE__ */ Error("swarm peer data channel closed while backpressured"));
|
|
961
961
|
e.addEventListener("bufferedamountlow", a, { once: !0 }), e.addEventListener("close", o, { once: !0 });
|
|
@@ -967,7 +967,7 @@ var Bt = class {
|
|
|
967
967
|
this.peers.clear();
|
|
968
968
|
}
|
|
969
969
|
startQualitySampling() {
|
|
970
|
-
this.qualityTimer || !this.options.onQuality || (this.samplePeerQuality(), this.qualityTimer = setInterval(() => void this.samplePeerQuality(),
|
|
970
|
+
this.qualityTimer || !this.options.onQuality || (this.samplePeerQuality(), this.qualityTimer = setInterval(() => void this.samplePeerQuality(), Ot));
|
|
971
971
|
}
|
|
972
972
|
stopQualitySampling() {
|
|
973
973
|
this.qualityTimer && clearInterval(this.qualityTimer), this.qualityTimer = null;
|
|
@@ -994,7 +994,7 @@ var Bt = class {
|
|
|
994
994
|
};
|
|
995
995
|
try {
|
|
996
996
|
t.send(JSON.stringify({
|
|
997
|
-
type:
|
|
997
|
+
type: zt,
|
|
998
998
|
kind: "ping",
|
|
999
999
|
id: n
|
|
1000
1000
|
}));
|
|
@@ -1003,7 +1003,7 @@ var Bt = class {
|
|
|
1003
1003
|
}
|
|
1004
1004
|
}
|
|
1005
1005
|
handleQualityProbe(e, t) {
|
|
1006
|
-
if (t.length >
|
|
1006
|
+
if (t.length > Bt) return;
|
|
1007
1007
|
let n;
|
|
1008
1008
|
try {
|
|
1009
1009
|
let e = JSON.parse(t);
|
|
@@ -1012,12 +1012,12 @@ var Bt = class {
|
|
|
1012
1012
|
} catch {
|
|
1013
1013
|
return;
|
|
1014
1014
|
}
|
|
1015
|
-
if (n.type !==
|
|
1015
|
+
if (n.type !== zt || !Number.isSafeInteger(n.id) || n.id < 1) return;
|
|
1016
1016
|
if (n.kind === "ping") {
|
|
1017
1017
|
if (e.channel?.readyState !== "open" || e.channel.bufferedAmount > 262144) return;
|
|
1018
1018
|
try {
|
|
1019
1019
|
e.channel.send(JSON.stringify({
|
|
1020
|
-
type:
|
|
1020
|
+
type: zt,
|
|
1021
1021
|
kind: "pong",
|
|
1022
1022
|
id: n.id
|
|
1023
1023
|
}));
|
|
@@ -1040,10 +1040,10 @@ var Bt = class {
|
|
|
1040
1040
|
this.sendQualityProbe(n);
|
|
1041
1041
|
let r = this.monotonicNow();
|
|
1042
1042
|
if (await this.sampleWebRtc(n, r), n.lastApplicationSampleAt !== void 0) {
|
|
1043
|
-
let e = r - n.lastApplicationSampleAt, t =
|
|
1043
|
+
let e = r - n.lastApplicationSampleAt, t = K(n.applicationBytesSent - n.lastApplicationBytesSent, e), i = K(n.applicationBytesReceived - n.lastApplicationBytesReceived, e);
|
|
1044
1044
|
t !== null && this.recordQuality(n, "application", "sendMbps", t), i !== null && this.recordQuality(n, "application", "receiveMbps", i);
|
|
1045
1045
|
}
|
|
1046
|
-
n.lastApplicationSampleAt = r, n.lastApplicationBytesSent = n.applicationBytesSent, n.lastApplicationBytesReceived = n.applicationBytesReceived, t.push(
|
|
1046
|
+
n.lastApplicationSampleAt = r, n.lastApplicationBytesSent = n.applicationBytesSent, n.lastApplicationBytesReceived = n.applicationBytesReceived, t.push(jt(n.nodeId, e, n.quality.webRtc, n.quality.application, n.qualitySampledAt));
|
|
1047
1047
|
}
|
|
1048
1048
|
t.length && this.options.onQuality(t.slice(0, 2));
|
|
1049
1049
|
} finally {
|
|
@@ -1068,11 +1068,11 @@ var Bt = class {
|
|
|
1068
1068
|
if (e.lastRtcSampleAt !== void 0) {
|
|
1069
1069
|
let n = t - e.lastRtcSampleAt;
|
|
1070
1070
|
if (d !== void 0 && e.lastRtcBytesSent !== void 0 && s === void 0) {
|
|
1071
|
-
let t =
|
|
1071
|
+
let t = K(d - e.lastRtcBytesSent, n);
|
|
1072
1072
|
t !== null && this.recordQuality(e, "webRtc", "sendMbps", t);
|
|
1073
1073
|
}
|
|
1074
1074
|
if (f !== void 0 && e.lastRtcBytesReceived !== void 0 && c === void 0) {
|
|
1075
|
-
let t =
|
|
1075
|
+
let t = K(f - e.lastRtcBytesReceived, n);
|
|
1076
1076
|
t !== null && this.recordQuality(e, "webRtc", "receiveMbps", t);
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
@@ -1080,30 +1080,34 @@ var Bt = class {
|
|
|
1080
1080
|
} catch {}
|
|
1081
1081
|
}
|
|
1082
1082
|
};
|
|
1083
|
-
function
|
|
1084
|
-
if (!
|
|
1085
|
-
let
|
|
1086
|
-
return
|
|
1083
|
+
function qt(e, t) {
|
|
1084
|
+
if (!_(e)) return !1;
|
|
1085
|
+
let n = e;
|
|
1086
|
+
return n.type === "swarm-peer-signal" && n.taskId === t.taskId && n.sessionId === t.sessionId && n.attemptId === t.attemptId && n.toNodeId === t.nodeId && typeof n.fromNodeId == "string" && t.peers.includes(n.fromNodeId) && typeof n.signal == "object" && n.signal !== null;
|
|
1087
1087
|
}
|
|
1088
1088
|
//#endregion
|
|
1089
1089
|
//#region src/client/mobile-lifecycle.ts
|
|
1090
|
-
var
|
|
1091
|
-
function
|
|
1092
|
-
let n = e.batteryCharging === !1, r = n && typeof e.batteryLevel == "number" && e.batteryLevel <=
|
|
1090
|
+
var Jt = .25, Yt = .08, Xt = .45;
|
|
1091
|
+
function Zt(e, t) {
|
|
1092
|
+
let n = e.batteryCharging === !1, r = n && typeof e.batteryLevel == "number" && e.batteryLevel <= Jt, i = n && typeof e.batteryLevel == "number" && e.batteryLevel <= Yt, a = e.effectiveType === "slow-2g" || e.effectiveType === "2g", o = r || a || e.saveData === !0;
|
|
1093
1093
|
return {
|
|
1094
1094
|
suspend: e.hidden || e.pageHidden || !e.online || i,
|
|
1095
1095
|
constrained: o,
|
|
1096
|
-
maxCpuLoad: o ? Math.min(t ??
|
|
1096
|
+
maxCpuLoad: o ? Math.min(t ?? Xt, Xt) : t
|
|
1097
1097
|
};
|
|
1098
1098
|
}
|
|
1099
1099
|
//#endregion
|
|
1100
1100
|
//#region src/client/light-preloader.ts
|
|
1101
|
-
var
|
|
1101
|
+
var Qt = "Xenova/m2m100_418M", $t = "translation", en = "q4f16", tn = "TeamFlaxia/plamo-3-translate-0.8b-onnx", nn = "text-generation", rn = "q4f16", an = class {
|
|
1102
1102
|
constructor(e, t = {}, n = () => !1, r = async () => {}) {
|
|
1103
|
-
this.getConsentState = e, this.options = t, this.isPreloaded = n, this.preload = r, this.timer = null, this.idleHandle = null, this.preloading = !1, this.stopped = !1, this.
|
|
1103
|
+
this.getConsentState = e, this.options = t, this.isPreloaded = n, this.preload = r, this.timer = null, this.idleHandle = null, this.preloading = !1, this.stopped = !1, this.targets = t.targets ?? [{
|
|
1104
|
+
model: t.model ?? "Xenova/m2m100_418M",
|
|
1105
|
+
task: t.task ?? "translation",
|
|
1106
|
+
dtype: t.dtype ?? "q4f16"
|
|
1107
|
+
}];
|
|
1104
1108
|
}
|
|
1105
1109
|
start() {
|
|
1106
|
-
if (this.stopped || this.getConsentState() !== "granted" || this.isUnconstrained() === !1 || this.
|
|
1110
|
+
if (this.stopped || this.getConsentState() !== "granted" || this.isUnconstrained() === !1 || !this.targets.some((e) => !this.isPreloaded(e)) || this.preloading) return;
|
|
1107
1111
|
let e = () => {
|
|
1108
1112
|
this.idleHandle = null, this.preloadNow();
|
|
1109
1113
|
};
|
|
@@ -1114,7 +1118,7 @@ var qt = "Xenova/m2m100_418M", Jt = class {
|
|
|
1114
1118
|
}
|
|
1115
1119
|
isUnconstrained() {
|
|
1116
1120
|
try {
|
|
1117
|
-
let e = navigator, t =
|
|
1121
|
+
let e = navigator, t = Zt({
|
|
1118
1122
|
hidden: document.hidden,
|
|
1119
1123
|
pageHidden: document.hidden,
|
|
1120
1124
|
online: navigator.onLine !== !1,
|
|
@@ -1127,38 +1131,43 @@ var qt = "Xenova/m2m100_418M", Jt = class {
|
|
|
1127
1131
|
}
|
|
1128
1132
|
}
|
|
1129
1133
|
async preloadNow() {
|
|
1130
|
-
if (!(this.stopped || this.preloading) && this.getConsentState() === "granted" && this.isUnconstrained() !== !1
|
|
1134
|
+
if (!(this.stopped || this.preloading) && this.getConsentState() === "granted" && this.isUnconstrained() !== !1) {
|
|
1131
1135
|
this.preloading = !0;
|
|
1132
1136
|
try {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1137
|
+
for (let e of this.targets) {
|
|
1138
|
+
if (this.stopped || this.getConsentState() !== "granted") return;
|
|
1139
|
+
if (!this.isPreloaded(e)) try {
|
|
1140
|
+
await this.preload({
|
|
1141
|
+
task: e.task,
|
|
1142
|
+
model: e.model,
|
|
1143
|
+
dtype: e.dtype
|
|
1144
|
+
}), this.options.onPreloaded?.();
|
|
1145
|
+
} catch {}
|
|
1146
|
+
}
|
|
1147
|
+
} finally {
|
|
1139
1148
|
this.preloading = !1;
|
|
1140
1149
|
}
|
|
1141
1150
|
}
|
|
1142
1151
|
}
|
|
1143
|
-
},
|
|
1144
|
-
function
|
|
1152
|
+
}, Y = (...e) => console.log("[flaxia-node]", ...e), X = (...e) => console.error("[flaxia-node]", ...e);
|
|
1153
|
+
function Z(e) {
|
|
1145
1154
|
let t = /* @__PURE__ */ new Set();
|
|
1146
1155
|
if (!Array.isArray(e)) return [];
|
|
1147
1156
|
for (let n of e.slice(0, 32)) try {
|
|
1148
|
-
let e =
|
|
1157
|
+
let e = y(n);
|
|
1149
1158
|
e.origin === n && t.add(e.origin);
|
|
1150
1159
|
} catch {}
|
|
1151
1160
|
return [...t];
|
|
1152
1161
|
}
|
|
1153
|
-
var
|
|
1162
|
+
var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
1154
1163
|
receiveSwarmEnvelope(e) {
|
|
1155
|
-
let t =
|
|
1164
|
+
let t = i(e);
|
|
1156
1165
|
!t || ![...this.swarmSessions.values()].includes(t.sessionId) || (this.swarmInboundChain = this.swarmInboundChain.then(async () => {
|
|
1157
1166
|
let e = this.swarmHopKeys.get(t.sessionId);
|
|
1158
1167
|
if (e && e.chainLength > 1) {
|
|
1159
1168
|
if (!t.mac || !e.inboundKey) return;
|
|
1160
|
-
if (!await
|
|
1161
|
-
|
|
1169
|
+
if (!await p(e.inboundKey, t.sessionId, t.frame, t.mac)) {
|
|
1170
|
+
X(`swarm frame rejected: bad hop MAC sessionId=${t.sessionId}`);
|
|
1162
1171
|
return;
|
|
1163
1172
|
}
|
|
1164
1173
|
}
|
|
@@ -1174,7 +1183,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1174
1183
|
attemptId: r,
|
|
1175
1184
|
peers: o
|
|
1176
1185
|
});
|
|
1177
|
-
let s = new
|
|
1186
|
+
let s = new Kt({
|
|
1178
1187
|
sessionId: t,
|
|
1179
1188
|
taskId: n,
|
|
1180
1189
|
attemptId: r,
|
|
@@ -1211,7 +1220,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1211
1220
|
}
|
|
1212
1221
|
handleSwarmPeerSignal(e) {
|
|
1213
1222
|
let t = typeof e.sessionId == "string" ? e.sessionId : "", n = this.swarmPeerMetadata.get(t), r = this.swarmPeerTransports.get(t);
|
|
1214
|
-
!n || !r || !
|
|
1223
|
+
!n || !r || !qt(e, {
|
|
1215
1224
|
...n,
|
|
1216
1225
|
sessionId: t,
|
|
1217
1226
|
nodeId: this.nodeId
|
|
@@ -1229,7 +1238,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1229
1238
|
this.disconnect();
|
|
1230
1239
|
return;
|
|
1231
1240
|
}
|
|
1232
|
-
if (
|
|
1241
|
+
if (Y(`connect nodeId=${this.nodeId}`), this.ws) {
|
|
1233
1242
|
let e = this.ws;
|
|
1234
1243
|
e.onclose = null;
|
|
1235
1244
|
try {
|
|
@@ -1238,24 +1247,24 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1238
1247
|
this.ws = null;
|
|
1239
1248
|
}
|
|
1240
1249
|
if (this.setupMobileLifecycleHandlers(), this.suspended) return;
|
|
1241
|
-
let
|
|
1250
|
+
let t = await this.obtainToken();
|
|
1242
1251
|
if (this.destroyed || this.suspended) return;
|
|
1243
1252
|
if (z() !== "granted") {
|
|
1244
|
-
|
|
1253
|
+
Y("connect cancelled because consent was revoked while obtaining a token");
|
|
1245
1254
|
return;
|
|
1246
1255
|
}
|
|
1247
|
-
if (!
|
|
1248
|
-
|
|
1256
|
+
if (!t) {
|
|
1257
|
+
X("token acquisition failed; scheduling reconnect"), this.scheduleReconnect();
|
|
1249
1258
|
return;
|
|
1250
1259
|
}
|
|
1251
1260
|
this.startLightPreloader();
|
|
1252
|
-
let
|
|
1253
|
-
|
|
1254
|
-
let
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
},
|
|
1258
|
-
if (this.ws !==
|
|
1261
|
+
let n = c(this.config.orchestratorUrl, "/crowd/signal"), r = new WebSocket(n, e(t.token));
|
|
1262
|
+
r.binaryType = "arraybuffer", this.ws = r;
|
|
1263
|
+
let i = !1;
|
|
1264
|
+
r.onopen = () => {
|
|
1265
|
+
i = !0, this.reconnectAttempts = 0, Y(`signal connected ${n}`), this.sendHeartbeat(r);
|
|
1266
|
+
}, r.onmessage = async (e) => {
|
|
1267
|
+
if (this.ws !== r) return;
|
|
1259
1268
|
if (typeof e.data != "string") {
|
|
1260
1269
|
this.receiveSwarmEnvelope(e.data);
|
|
1261
1270
|
return;
|
|
@@ -1267,22 +1276,22 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1267
1276
|
return;
|
|
1268
1277
|
}
|
|
1269
1278
|
if (t.type === "ping") {
|
|
1270
|
-
this.sendHeartbeat(
|
|
1279
|
+
this.sendHeartbeat(r);
|
|
1271
1280
|
return;
|
|
1272
1281
|
}
|
|
1273
1282
|
if (t.type === "task") {
|
|
1274
1283
|
let e = t;
|
|
1275
|
-
|
|
1284
|
+
Y(`task received taskId=${e.taskId} workload=${e.workload} timeoutMs=${e.timeoutMs ?? "default"}`), typeof e.attemptId == "string" && this.attempts.set(e.taskId, e.attemptId);
|
|
1276
1285
|
let n = e.attemptId ?? this.attempts.get(e.taskId);
|
|
1277
1286
|
try {
|
|
1278
1287
|
await this.handleTask(e);
|
|
1279
1288
|
} catch (r) {
|
|
1280
1289
|
let i = r instanceof Error ? r.message : String(r);
|
|
1281
1290
|
if (this.abortedTasks.delete(e.taskId)) {
|
|
1282
|
-
|
|
1291
|
+
Y(`task stopped on coordinator abort taskId=${e.taskId} error=${i}`);
|
|
1283
1292
|
return;
|
|
1284
1293
|
}
|
|
1285
|
-
|
|
1294
|
+
X(`task failed taskId=${e.taskId} workload=${e.workload} error=${i}`), this.send({
|
|
1286
1295
|
type: "error",
|
|
1287
1296
|
taskId: String(t.taskId ?? ""),
|
|
1288
1297
|
error: i,
|
|
@@ -1337,10 +1346,10 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1337
1346
|
this.handleAbort(t);
|
|
1338
1347
|
return;
|
|
1339
1348
|
}
|
|
1340
|
-
},
|
|
1341
|
-
this.ws ===
|
|
1342
|
-
},
|
|
1343
|
-
|
|
1349
|
+
}, r.onerror = () => {
|
|
1350
|
+
this.ws === r && X("signal websocket error");
|
|
1351
|
+
}, r.onclose = (e) => {
|
|
1352
|
+
r.onclose = null, this.ws === r && (this.ws = null, i || (this.cachedToken = null), !this.destroyed && (Y(`signal disconnected code=${e.code} reason=${JSON.stringify(e.reason)} clean=${e.wasClean}; scheduling reconnect attempt=${this.reconnectAttempts + 1}`), this.scheduleReconnect()));
|
|
1344
1353
|
};
|
|
1345
1354
|
}
|
|
1346
1355
|
handleAbort(e) {
|
|
@@ -1349,11 +1358,11 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1349
1358
|
let n = typeof e.error == "string" && e.error ? e.error : "aborted by the coordinator", r = this.swarmSessions.get(t);
|
|
1350
1359
|
if (r && r !== e.sessionId) return;
|
|
1351
1360
|
let i = r ?? t;
|
|
1352
|
-
r && this.retireSwarmSession(r), this.workerPool.abort(i, n) && this.abortedTasks.add(i),
|
|
1361
|
+
r && this.retireSwarmSession(r), this.workerPool.abort(i, n) && this.abortedTasks.add(i), Y(`task abort received taskId=${t} error=${n}`);
|
|
1353
1362
|
}
|
|
1354
1363
|
async sendHeartbeat(e) {
|
|
1355
1364
|
if (this.ws !== e || e.readyState !== WebSocket.OPEN || z() !== "granted") return;
|
|
1356
|
-
let t = (this.config.capabilities ?? ["ai-inference", "image-process"]).includes("swarm-inference") && this.config.allowModelDownload === !0, n = navigator.deviceMemory, r = await
|
|
1365
|
+
let t = (this.config.capabilities ?? ["ai-inference", "image-process"]).includes("swarm-inference") && this.config.allowModelDownload === !0, n = navigator.deviceMemory, r = await Dt({
|
|
1357
1366
|
cpuLoad: this.workerPool.hasCpuLoadSample ? this.workerPool.lastCpuLoad : null,
|
|
1358
1367
|
deviceMemory: n,
|
|
1359
1368
|
probeGpu: t
|
|
@@ -1372,7 +1381,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1372
1381
|
}, e);
|
|
1373
1382
|
}
|
|
1374
1383
|
disconnect() {
|
|
1375
|
-
|
|
1384
|
+
Y(`disconnect nodeId=${this.nodeId}`), this.destroyed = !0, this.suspended = !1, this.stopLightPreloader(), this.removeMobileLifecycleHandlers();
|
|
1376
1385
|
try {
|
|
1377
1386
|
this.ws?.close();
|
|
1378
1387
|
} catch {}
|
|
@@ -1380,7 +1389,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1380
1389
|
for (let e of this.swarmPeerTransports.values()) e.close();
|
|
1381
1390
|
this.swarmPeerTransports.clear(), this.swarmPeerMetadata.clear();
|
|
1382
1391
|
try {
|
|
1383
|
-
delete window[
|
|
1392
|
+
delete window[cn];
|
|
1384
1393
|
} catch {}
|
|
1385
1394
|
try {
|
|
1386
1395
|
this.workerPool.terminate();
|
|
@@ -1388,7 +1397,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1388
1397
|
}
|
|
1389
1398
|
suspend() {
|
|
1390
1399
|
if (!(this.suspended || this.destroyed)) {
|
|
1391
|
-
if (
|
|
1400
|
+
if (Y("suspended (visibility or manual)"), this.suspended = !0, this.stopLightPreloader(), this.ws) {
|
|
1392
1401
|
let e = this.ws;
|
|
1393
1402
|
e.onclose = null;
|
|
1394
1403
|
try {
|
|
@@ -1400,18 +1409,18 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1400
1409
|
}
|
|
1401
1410
|
}
|
|
1402
1411
|
resume() {
|
|
1403
|
-
!this.suspended || this.destroyed || (
|
|
1412
|
+
!this.suspended || this.destroyed || (Y("resumed"), this.suspended = !1, this.workerPool.resume(), this.connect());
|
|
1404
1413
|
}
|
|
1405
1414
|
async obtainToken() {
|
|
1406
1415
|
let e = () => z() === "granted";
|
|
1407
1416
|
if (!e()) return null;
|
|
1408
1417
|
try {
|
|
1409
|
-
if (this.cachedToken && this.cachedToken.expiresAt > Date.now() + 6e4) return
|
|
1410
|
-
let t =
|
|
1411
|
-
|
|
1418
|
+
if (this.cachedToken && this.cachedToken.expiresAt > Date.now() + 6e4) return Y(`token cached nodeId=${this.cachedToken.nodeId} expiresIn=${Math.round((this.cachedToken.expiresAt - Date.now()) / 1e3)}s`), this.cachedToken;
|
|
1419
|
+
let t = h(), n = t >= g, r = this.config.capabilities ?? ["ai-inference", "image-process"], i = [...r];
|
|
1420
|
+
n || (i = i.filter((e) => !d.has(e))), Z(this.config.containerImageOrigins).length === 0 && (i = i.filter((e) => e !== "container")), Z(this.config.ccRangeOrigins).length === 0 && (i = i.filter((e) => e !== "cc-extract"));
|
|
1412
1421
|
let a;
|
|
1413
1422
|
if (n && r.includes("swarm-inference") && this.config.allowModelDownload === !0) {
|
|
1414
|
-
let t = await
|
|
1423
|
+
let t = await Dt({
|
|
1415
1424
|
cpuLoad: this.workerPool.hasCpuLoadSample ? this.workerPool.lastCpuLoad : null,
|
|
1416
1425
|
deviceMemory: navigator.deviceMemory,
|
|
1417
1426
|
probeGpu: !0
|
|
@@ -1419,7 +1428,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1419
1428
|
if (!e()) return null;
|
|
1420
1429
|
t.gpu.status === "available" ? (a = { webgpu: !0 }, t.gpu.architecture.value && (a.gpuArchitecture = t.gpu.architecture.value), t.gpu.maxStorageBufferBindingSize.value !== null && (a.maxStorageBufferBindingSize = t.gpu.maxStorageBufferBindingSize.value)) : i = i.filter((e) => e !== "swarm-inference");
|
|
1421
1430
|
} else i = i.filter((e) => e !== "swarm-inference");
|
|
1422
|
-
|
|
1431
|
+
Y(`register capability probe capable=${n} wasmMemoryBytes=${t} capabilities=${JSON.stringify(i)} webgpu=${a?.webgpu ?? !1}`);
|
|
1423
1432
|
let o = this.config.orchestratorUrl.replace(/\/+$/, "");
|
|
1424
1433
|
if (!e()) return null;
|
|
1425
1434
|
let s = await fetch(`${o}/crowd/nodes/register`, {
|
|
@@ -1428,18 +1437,18 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1428
1437
|
body: JSON.stringify({
|
|
1429
1438
|
siteId: this.config.siteId,
|
|
1430
1439
|
capabilities: i,
|
|
1431
|
-
fileSources:
|
|
1432
|
-
wasmMemoryBytes:
|
|
1440
|
+
fileSources: Z(this.config.fileSourceOrigins).length > 0,
|
|
1441
|
+
wasmMemoryBytes: h(),
|
|
1433
1442
|
deviceMemory: typeof navigator.deviceMemory == "number" ? navigator.deviceMemory : null,
|
|
1434
1443
|
swarm: a
|
|
1435
1444
|
})
|
|
1436
1445
|
});
|
|
1437
1446
|
if (!e()) return null;
|
|
1438
|
-
if (!s.ok) return
|
|
1447
|
+
if (!s.ok) return X(`node register failed HTTP ${s.status} (${o}/crowd/nodes/register)`), null;
|
|
1439
1448
|
let c = await s.json();
|
|
1440
|
-
return e() ? c.token ? (typeof c.nodeId == "string" && c.nodeId && (this.nodeId = c.nodeId), this.cachedToken = c,
|
|
1449
|
+
return e() ? c.token ? (typeof c.nodeId == "string" && c.nodeId && (this.nodeId = c.nodeId), this.cachedToken = c, Y(`node registered nodeId=${this.nodeId} expiresIn=${Math.round((c.expiresAt - Date.now()) / 1e3)}s`), c) : (X("node register returned no token"), null) : null;
|
|
1441
1450
|
} catch (e) {
|
|
1442
|
-
return
|
|
1451
|
+
return X("node register threw", e instanceof Error ? e.message : e), null;
|
|
1443
1452
|
}
|
|
1444
1453
|
}
|
|
1445
1454
|
send(e) {
|
|
@@ -1453,15 +1462,15 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1453
1462
|
let n = this.swarmHopKeys.get(e);
|
|
1454
1463
|
if (n && n.chainLength > 1) {
|
|
1455
1464
|
if (!n.outboundKey) {
|
|
1456
|
-
|
|
1465
|
+
X(`swarm frame not sent: no hop key sessionId=${e}`);
|
|
1457
1466
|
return;
|
|
1458
1467
|
}
|
|
1459
|
-
let
|
|
1460
|
-
(!
|
|
1468
|
+
let i = await r(n.outboundKey, e, t), a = this.swarmPeerTransports.get(e);
|
|
1469
|
+
(!a || !await a.sendFrame(i)) && this.sendBinary(i);
|
|
1461
1470
|
return;
|
|
1462
1471
|
}
|
|
1463
|
-
let
|
|
1464
|
-
(!
|
|
1472
|
+
let i = l(e, t), a = this.swarmPeerTransports.get(e);
|
|
1473
|
+
(!a || !await a.sendFrame(i)) && this.sendBinary(i);
|
|
1465
1474
|
}).catch((t) => {
|
|
1466
1475
|
let n = this.swarmPeerMetadata.get(e);
|
|
1467
1476
|
!n || this.swarmFailureReported.has(e) || (this.swarmFailureReported.add(e), this.send({
|
|
@@ -1514,10 +1523,10 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1514
1523
|
sessionId: n,
|
|
1515
1524
|
payload: o,
|
|
1516
1525
|
attemptId: a
|
|
1517
|
-
}),
|
|
1526
|
+
}), Y(`swarm result sent taskId=${e} durationMs=${Math.round(performance.now() - r)}`);
|
|
1518
1527
|
} catch (t) {
|
|
1519
1528
|
let r = t instanceof Error ? t.message : String(t);
|
|
1520
|
-
this.abortedTasks.delete(n) ?
|
|
1529
|
+
this.abortedTasks.delete(n) ? Y(`swarm stopped on coordinator abort taskId=${e} error=${r}`) : (X(`swarm failed taskId=${e} error=${r}`), this.send({
|
|
1521
1530
|
type: "error",
|
|
1522
1531
|
taskId: e,
|
|
1523
1532
|
sessionId: n,
|
|
@@ -1542,39 +1551,57 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1542
1551
|
});
|
|
1543
1552
|
}, {
|
|
1544
1553
|
maxCpuLoad: this.effectiveMaxCpuLoad(),
|
|
1545
|
-
fileSourceOrigins:
|
|
1546
|
-
containerImageOrigins:
|
|
1554
|
+
fileSourceOrigins: Z(this.config.fileSourceOrigins),
|
|
1555
|
+
containerImageOrigins: Z(this.config.containerImageOrigins),
|
|
1556
|
+
ccRangeOrigins: Z(this.config.ccRangeOrigins)
|
|
1547
1557
|
});
|
|
1548
1558
|
this.send({
|
|
1549
1559
|
type: "result",
|
|
1550
1560
|
taskId: e.taskId,
|
|
1551
1561
|
payload: i,
|
|
1552
1562
|
attemptId: n
|
|
1553
|
-
}),
|
|
1563
|
+
}), Y(`task result sent taskId=${e.taskId} workload=${e.workload} durationMs=${Math.round(performance.now() - t)}`);
|
|
1554
1564
|
} finally {
|
|
1555
1565
|
this.inflightTasks.delete(e.taskId), this.attempts.delete(e.taskId);
|
|
1556
1566
|
}
|
|
1557
1567
|
}
|
|
1558
1568
|
async runLocalAiInference(e, t) {
|
|
1559
|
-
if (!this.workerPool) throw new
|
|
1560
|
-
if (z() !== "granted") throw new
|
|
1569
|
+
if (!this.workerPool) throw new o("No running Crowd node on this device", "node_not_running");
|
|
1570
|
+
if (z() !== "granted") throw new o("Crowd consent is not granted", "consent_not_granted");
|
|
1561
1571
|
let n = `local-${typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`}`;
|
|
1562
1572
|
return await this.workerPool.run(n, "ai-inference", e, 3e5, t, {
|
|
1563
1573
|
maxCpuLoad: this.effectiveMaxCpuLoad(),
|
|
1564
|
-
fileSourceOrigins:
|
|
1565
|
-
containerImageOrigins:
|
|
1574
|
+
fileSourceOrigins: Z(this.config.fileSourceOrigins),
|
|
1575
|
+
containerImageOrigins: Z(this.config.containerImageOrigins)
|
|
1566
1576
|
});
|
|
1567
1577
|
}
|
|
1568
1578
|
isAiModelPreloaded(e) {
|
|
1569
1579
|
let t = this.workerPool.modelCacheSnapshot;
|
|
1570
|
-
|
|
1580
|
+
if (!t) return !1;
|
|
1581
|
+
if (typeof e == "string") return t.entries.some((t) => t.modelId === e && t.state === "ready");
|
|
1582
|
+
let n = e.dtype ?? "q4f16", r = e.device ?? "wasm";
|
|
1583
|
+
return t.entries.some((t) => t.modelId === e.model && t.dtype === n && t.backend === r && t.state === "ready");
|
|
1571
1584
|
}
|
|
1572
1585
|
async preloadAiModel(e) {
|
|
1573
1586
|
let t = `preload-${typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`}`;
|
|
1574
1587
|
await this.workerPool.run(t, "ai-preload", e, 3e5, void 0, { maxCpuLoad: this.effectiveMaxCpuLoad() });
|
|
1575
1588
|
}
|
|
1576
1589
|
startLightPreloader() {
|
|
1577
|
-
this.lightPreloader && this.lightPreloader.stop(), this.lightPreloader = new
|
|
1590
|
+
this.lightPreloader && this.lightPreloader.stop(), this.lightPreloader = new an(() => z(), {
|
|
1591
|
+
targets: [{
|
|
1592
|
+
model: Qt,
|
|
1593
|
+
task: $t,
|
|
1594
|
+
dtype: en
|
|
1595
|
+
}, {
|
|
1596
|
+
model: tn,
|
|
1597
|
+
task: nn,
|
|
1598
|
+
dtype: rn
|
|
1599
|
+
}],
|
|
1600
|
+
onPreloaded: () => {}
|
|
1601
|
+
}, (e) => this.isAiModelPreloaded({
|
|
1602
|
+
model: e.model,
|
|
1603
|
+
dtype: e.dtype
|
|
1604
|
+
}), (e) => this.preloadAiModel(e)), this.lightPreloader.start();
|
|
1578
1605
|
}
|
|
1579
1606
|
stopLightPreloader() {
|
|
1580
1607
|
this.lightPreloader && this.lightPreloader.stop(), this.lightPreloader = null;
|
|
@@ -1613,7 +1640,7 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1613
1640
|
this.batteryState = null, this.networkState = null;
|
|
1614
1641
|
}
|
|
1615
1642
|
mobileLifecycleDecision() {
|
|
1616
|
-
return
|
|
1643
|
+
return Zt({
|
|
1617
1644
|
hidden: document.hidden,
|
|
1618
1645
|
pageHidden: this.lifecyclePageHidden,
|
|
1619
1646
|
online: !this.lifecycleOffline && navigator.onLine !== !1,
|
|
@@ -1629,27 +1656,27 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1629
1656
|
refreshMobileLifecycle() {
|
|
1630
1657
|
this.mobileLifecycleDecision().suspend ? this.suspend() : this.suspended && this.resume();
|
|
1631
1658
|
}
|
|
1632
|
-
}, $ = "__flaxia_node_signal_client",
|
|
1659
|
+
}, $ = "__flaxia_node_signal_client", cn = "__flaxia_node_init_started", ln = "__flaxia_node_controller", un = (e) => {
|
|
1633
1660
|
if (z() !== "granted") {
|
|
1634
|
-
|
|
1661
|
+
X("refusing to start the node without a granted consent record");
|
|
1635
1662
|
return;
|
|
1636
1663
|
}
|
|
1637
1664
|
let t = window[$];
|
|
1638
|
-
t && t.disconnect(),
|
|
1639
|
-
let n = new URL("./worker.js", "" + import.meta.url).href, r = new
|
|
1640
|
-
i || (i =
|
|
1641
|
-
let a = new
|
|
1665
|
+
t && t.disconnect(), nt(Q);
|
|
1666
|
+
let n = new URL("./worker.js", "" + import.meta.url).href, r = new wt(n), i = et(on);
|
|
1667
|
+
i || (i = it(), tt(on, i));
|
|
1668
|
+
let a = new sn(e, r, i);
|
|
1642
1669
|
window[$] = a, a.connect();
|
|
1643
|
-
},
|
|
1670
|
+
}, dn = class {
|
|
1644
1671
|
constructor(e) {
|
|
1645
1672
|
this.config = e;
|
|
1646
1673
|
}
|
|
1647
1674
|
start() {
|
|
1648
|
-
this.isRunning() || !
|
|
1675
|
+
this.isRunning() || !Ve() || un(this.config);
|
|
1649
1676
|
}
|
|
1650
1677
|
stop() {
|
|
1651
1678
|
let e = window[$];
|
|
1652
|
-
e && e.disconnect(), delete window[$], delete window[
|
|
1679
|
+
e && e.disconnect(), delete window[$], delete window[cn];
|
|
1653
1680
|
}
|
|
1654
1681
|
isRunning() {
|
|
1655
1682
|
return !!window[$];
|
|
@@ -1658,17 +1685,17 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1658
1685
|
return z();
|
|
1659
1686
|
}
|
|
1660
1687
|
grant() {
|
|
1661
|
-
|
|
1688
|
+
Ye();
|
|
1662
1689
|
}
|
|
1663
1690
|
deny() {
|
|
1664
|
-
|
|
1691
|
+
Qe(), this.stop(), nt(Q);
|
|
1665
1692
|
}
|
|
1666
1693
|
clearConsent() {
|
|
1667
|
-
|
|
1694
|
+
$e(), this.stop(), nt(Q);
|
|
1668
1695
|
}
|
|
1669
1696
|
async runLocalAiInference(e, t) {
|
|
1670
1697
|
let n = window[$];
|
|
1671
|
-
if (!n || !this.isRunning()) throw new
|
|
1698
|
+
if (!n || !this.isRunning()) throw new o("No running Crowd node on this device", "node_not_running");
|
|
1672
1699
|
return n.runLocalAiInference(e, t);
|
|
1673
1700
|
}
|
|
1674
1701
|
isAiModelPreloaded(e) {
|
|
@@ -1677,32 +1704,32 @@ var Yt = "flaxia_node_id", Xt = "flaxia_node_token", Zt = class {
|
|
|
1677
1704
|
}
|
|
1678
1705
|
async preloadAiModel(e) {
|
|
1679
1706
|
let t = window[$];
|
|
1680
|
-
if (!t) throw new
|
|
1707
|
+
if (!t) throw new o("No running Crowd node on this device", "node_not_running");
|
|
1681
1708
|
await t.preloadAiModel(e);
|
|
1682
1709
|
}
|
|
1683
|
-
},
|
|
1684
|
-
let t = window[
|
|
1710
|
+
}, fn = (e) => {
|
|
1711
|
+
let t = window[ln];
|
|
1685
1712
|
if (t) return t;
|
|
1686
|
-
let n = new
|
|
1687
|
-
window[
|
|
1713
|
+
let n = new dn(e);
|
|
1714
|
+
window[ln] = n, window[cn] = !0;
|
|
1688
1715
|
let r = z();
|
|
1689
1716
|
if (r === "granted") return n.start(), n;
|
|
1690
1717
|
if (r === "denied") return n;
|
|
1691
1718
|
if (e.consent.onConsentRequired) return e.consent.onConsentRequired({
|
|
1692
1719
|
state: r,
|
|
1693
1720
|
accept: () => {
|
|
1694
|
-
|
|
1721
|
+
Ye(), n.start();
|
|
1695
1722
|
},
|
|
1696
1723
|
reject: () => {
|
|
1697
|
-
|
|
1724
|
+
Qe();
|
|
1698
1725
|
}
|
|
1699
1726
|
}), n;
|
|
1700
1727
|
let i = document.createElement("div");
|
|
1701
|
-
return i.id = "flaxia-consent-container", document.body.appendChild(i), new
|
|
1702
|
-
|
|
1728
|
+
return i.id = "flaxia-consent-container", document.body.appendChild(i), new Ct(i, e.consent, () => {
|
|
1729
|
+
Ye(), i.remove(), n.start();
|
|
1703
1730
|
}, () => {
|
|
1704
|
-
|
|
1731
|
+
Qe(), i.remove();
|
|
1705
1732
|
}), n;
|
|
1706
1733
|
};
|
|
1707
1734
|
//#endregion
|
|
1708
|
-
export {
|
|
1735
|
+
export { rn as LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE, se as LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE_ID, tn as LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL, ie as LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL_ID, nn as LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK, oe as LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK_ID, ne as LIGHT_INFERENCE_TRANSLATE_DTYPE, Qt as LIGHT_INFERENCE_TRANSLATE_MODEL, te as LIGHT_INFERENCE_TRANSLATE_MODEL_ID, ae as LIGHT_INFERENCE_TRANSLATE_TASK, z as getFlaxiaNodeConsentState, fn as initFlaxiaNode, B as initFlaxiaNodeConsent, b as isAiModelPreloaded, re as preloadAiModel, Ze as setFlaxiaNodeHostManagedConsent };
|