@flaxia/node 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/ai-inference.js +9 -9
- package/dist/assets/ai-model-registry.js +0 -5
- package/dist/assets/cc-extract.js +20 -20
- package/dist/assets/container.js +59 -43
- package/dist/assets/decision.js +43 -36
- package/dist/assets/embed-gemma.js +28 -20
- package/dist/assets/image-process.js +78 -70
- package/dist/assets/nudenet.js +2 -2
- package/dist/assets/{VectorStoreEngine.js → sharedEngine.js} +67 -41
- package/dist/assets/vector-embed.js +49 -36
- package/dist/assets/vector-query.js +4 -4
- package/dist/assets/vector-store.js +4 -4
- package/dist/assets/webgpuProbe.js +87 -47
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/light-preloader.d.ts +16 -6
- package/dist/client/light-preloader.d.ts.map +1 -1
- package/dist/executor/WorkerPool.d.ts +6 -0
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/executor/__tests__/resultLimits.test.d.ts +2 -0
- package/dist/executor/__tests__/resultLimits.test.d.ts.map +1 -0
- package/dist/executor/container-executor.d.ts +15 -0
- package/dist/executor/container-executor.d.ts.map +1 -1
- package/dist/executor/memoryProbe.d.ts +25 -1
- package/dist/executor/memoryProbe.d.ts.map +1 -1
- package/dist/executor/resultLimits.d.ts +19 -0
- package/dist/executor/resultLimits.d.ts.map +1 -0
- package/dist/index.js +416 -396
- package/dist/vector-store/HNSWIndex.d.ts +4 -1
- package/dist/vector-store/HNSWIndex.d.ts.map +1 -1
- package/dist/vector-store/VectorStoreEngine.d.ts +7 -1
- package/dist/vector-store/VectorStoreEngine.d.ts.map +1 -1
- package/dist/vector-store/__tests__/sharedEngine.test.d.ts +2 -0
- package/dist/vector-store/__tests__/sharedEngine.test.d.ts.map +1 -0
- package/dist/vector-store/sharedEngine.d.ts +13 -0
- package/dist/vector-store/sharedEngine.d.ts.map +1 -0
- package/dist/worker.js +163 -160
- package/dist/workloads/__tests__/nudenet-session-cache.test.d.ts +2 -0
- package/dist/workloads/__tests__/nudenet-session-cache.test.d.ts.map +1 -0
- package/dist/workloads/ai-inference.d.ts +8 -7
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/ai-model-registry.d.ts.map +1 -1
- package/dist/workloads/decision.d.ts +2 -0
- package/dist/workloads/decision.d.ts.map +1 -1
- package/dist/workloads/embed-gemma.d.ts.map +1 -1
- package/dist/workloads/image-process.d.ts +8 -0
- package/dist/workloads/image-process.d.ts.map +1 -1
- package/dist/workloads/nudenet.d.ts.map +1 -1
- package/dist/workloads/vector-embed.d.ts +6 -0
- package/dist/workloads/vector-embed.d.ts.map +1 -1
- package/dist/workloads/vector-query.d.ts.map +1 -1
- package/dist/workloads/vector-store.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { B as e,
|
|
2
|
-
import { t as
|
|
3
|
-
import { a as
|
|
1
|
+
import { B as e, D as t, E as n, F as r, L as i, M as a, R as o, U as s, Y as c, _ as l, a as u, c as d, h as f, i as p, k as m, l as h, m as g, n as _, o as v, p as ee, r as y, v as te, z as b } from "./assets/webgpuProbe.js";
|
|
2
|
+
import { t as ne } from "./assets/egress-guard.js";
|
|
3
|
+
import { a as re, c as ie, i as ae, l as oe, n as se, o as ce, r as le, t as ue } 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
|
+
}, de = 4320 * 60 * 60 * 1e3, S = "flaxia_consent_record", fe = "flaxia_consent_granted", pe = "flaxia_consent_expiry", C = "flaxia_consent_denied", me = 1, he = 1e4, ge = 2e3, _e = "flaxia-consent-integrity", ve = 1, w = "keys", ye = "consent-hmac-sha256-v1", be = (...e) => console.warn("[flaxia-node]", ...e), xe = /* @__PURE__ */ new Map();
|
|
17
|
+
function Se(e) {
|
|
18
18
|
try {
|
|
19
19
|
return localStorage.getItem(e);
|
|
20
20
|
} catch {
|
|
21
|
-
return
|
|
21
|
+
return xe.get(e) ?? null;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function T(e, t) {
|
|
25
25
|
try {
|
|
26
26
|
localStorage.setItem(e, t);
|
|
27
27
|
} catch {
|
|
28
|
-
|
|
28
|
+
xe.set(e, t);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function E(e) {
|
|
32
32
|
try {
|
|
33
33
|
localStorage.removeItem(e);
|
|
34
34
|
} catch {
|
|
35
|
-
|
|
35
|
+
xe.delete(e);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function Ce(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 we() {
|
|
44
44
|
return new Promise((e, t) => {
|
|
45
45
|
let n;
|
|
46
46
|
try {
|
|
@@ -54,7 +54,7 @@ function Se() {
|
|
|
54
54
|
}
|
|
55
55
|
let r;
|
|
56
56
|
try {
|
|
57
|
-
r = n.open(
|
|
57
|
+
r = n.open(_e, ve);
|
|
58
58
|
} catch (e) {
|
|
59
59
|
t(e);
|
|
60
60
|
return;
|
|
@@ -65,26 +65,26 @@ function Se() {
|
|
|
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 Te(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 Ee = {
|
|
74
74
|
async load() {
|
|
75
|
-
let e = await
|
|
75
|
+
let e = await we();
|
|
76
76
|
try {
|
|
77
|
-
let t = await
|
|
78
|
-
return
|
|
77
|
+
let t = await Ce(e.transaction(w, "readonly").objectStore(w).get(ye));
|
|
78
|
+
return Te(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 we();
|
|
85
85
|
try {
|
|
86
86
|
let n = t.transaction(w, "readwrite");
|
|
87
|
-
n.objectStore(w).put(e,
|
|
87
|
+
n.objectStore(w).put(e, ye), 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 we = {
|
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
94
|
async clear() {
|
|
95
|
-
let e = await
|
|
95
|
+
let e = await we();
|
|
96
96
|
try {
|
|
97
97
|
let t = e.transaction(w, "readwrite");
|
|
98
|
-
t.objectStore(w).delete(
|
|
98
|
+
t.objectStore(w).delete(ye), 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 we = {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
|
-
function
|
|
106
|
+
function De(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 Te(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 Oe = Ee, D = null, O = null, k = !1, A = !1, j = null, M = 0, N = 0, P = null, ke = !1;
|
|
115
|
+
function Ae() {
|
|
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 je = Ae, Me = () => je(), Ne = {
|
|
123
123
|
name: "HMAC",
|
|
124
124
|
hash: "SHA-256"
|
|
125
125
|
};
|
|
126
|
-
function
|
|
126
|
+
function F() {
|
|
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 Pe(e) {
|
|
134
134
|
let t = new TextEncoder().encode(JSON.stringify([
|
|
135
135
|
e.v,
|
|
136
136
|
e.noticeVersion,
|
|
@@ -140,12 +140,12 @@ function Me(e) {
|
|
|
140
140
|
])), n = new Uint8Array(t.byteLength);
|
|
141
141
|
return n.set(t), n;
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function Fe(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 Ie(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 Pe(e) {
|
|
|
154
154
|
return null;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
async function
|
|
158
|
-
let e = await
|
|
157
|
+
async function Le() {
|
|
158
|
+
let e = await De(Oe.load(), null, ge);
|
|
159
159
|
if (e) return e;
|
|
160
|
-
let t =
|
|
160
|
+
let t = F();
|
|
161
161
|
if (!t) return null;
|
|
162
162
|
try {
|
|
163
|
-
let e = await t.generateKey(
|
|
164
|
-
return await
|
|
163
|
+
let e = await t.generateKey(Ne, !1, ["sign", "verify"]);
|
|
164
|
+
return await De(Oe.save(e), void 0, ge), e;
|
|
165
165
|
} catch {
|
|
166
166
|
return null;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
async function
|
|
170
|
-
let t =
|
|
171
|
-
if (!t || !
|
|
169
|
+
async function Re(e) {
|
|
170
|
+
let t = F();
|
|
171
|
+
if (!t || !D) return null;
|
|
172
172
|
try {
|
|
173
|
-
let n = await t.sign("HMAC",
|
|
174
|
-
return
|
|
173
|
+
let n = await t.sign("HMAC", D, Pe(e));
|
|
174
|
+
return Fe(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 ze(e) {
|
|
180
|
+
let t = F();
|
|
181
|
+
if (!t || !D || !e.mac) return !1;
|
|
182
|
+
let n = Ie(e.mac);
|
|
183
183
|
if (!n) return !1;
|
|
184
184
|
try {
|
|
185
|
-
return await t.verify("HMAC",
|
|
185
|
+
return await t.verify("HMAC", D, n, Pe(e));
|
|
186
186
|
} catch {
|
|
187
187
|
return !1;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function Be(e) {
|
|
191
191
|
if (!e) return null;
|
|
192
192
|
try {
|
|
193
193
|
let t = JSON.parse(e);
|
|
@@ -205,128 +205,128 @@ function Re(e) {
|
|
|
205
205
|
return null;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function Ve(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 He(e) {
|
|
212
|
+
return e.v === me && e.noticeVersion === 3 && e.origin === Me();
|
|
213
213
|
}
|
|
214
|
-
function
|
|
215
|
-
return
|
|
214
|
+
function Ue() {
|
|
215
|
+
return Be(Se(S));
|
|
216
216
|
}
|
|
217
|
-
function
|
|
218
|
-
|
|
217
|
+
function We(e) {
|
|
218
|
+
T(S, JSON.stringify(e));
|
|
219
219
|
}
|
|
220
|
-
function
|
|
221
|
-
|
|
220
|
+
function I() {
|
|
221
|
+
E(S);
|
|
222
222
|
}
|
|
223
|
-
function
|
|
224
|
-
|
|
223
|
+
function L() {
|
|
224
|
+
E(fe), E(pe);
|
|
225
225
|
}
|
|
226
|
-
var
|
|
227
|
-
let e =
|
|
228
|
-
return !e || !
|
|
229
|
-
},
|
|
230
|
-
async function
|
|
231
|
-
let e = ++
|
|
226
|
+
var Ge = () => {
|
|
227
|
+
let e = O;
|
|
228
|
+
return !e || !k ? !1 : Ve(e, Date.now()) && He(e);
|
|
229
|
+
}, Ke = () => Se(C) === "true", R = () => Ge() ? "granted" : Ke() ? "denied" : "unset", z = () => (j ||= qe(), j);
|
|
230
|
+
async function qe() {
|
|
231
|
+
let e = ++M, t = N, n = null;
|
|
232
232
|
try {
|
|
233
|
-
n = await
|
|
233
|
+
n = await Le();
|
|
234
234
|
} catch {
|
|
235
235
|
n = null;
|
|
236
236
|
}
|
|
237
|
-
if (e !==
|
|
238
|
-
|
|
239
|
-
let r =
|
|
240
|
-
return r !== null && await
|
|
237
|
+
if (e !== M) return R();
|
|
238
|
+
D = n, L();
|
|
239
|
+
let r = Ue();
|
|
240
|
+
return r !== null && await ze(r) && Ve(r, Date.now()) && He(r) && r ? t === N && e === M && (O = r, k = !0) : r && !A && (I(), t === N && e === M && (O = null, k = !1)), R();
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
let e =
|
|
244
|
-
return
|
|
242
|
+
function Je() {
|
|
243
|
+
let e = P;
|
|
244
|
+
return P = null, e && Date.now() - e.at <= he ? {
|
|
245
245
|
noticeVersion: e.noticeVersion,
|
|
246
246
|
source: "user-gesture"
|
|
247
|
-
} :
|
|
247
|
+
} : ke ? {
|
|
248
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 Ye(e) {
|
|
253
|
+
return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? de : Math.min(Math.floor(e), de);
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function Xe(e, t) {
|
|
256
256
|
let n = Date.now();
|
|
257
257
|
return {
|
|
258
|
-
v:
|
|
258
|
+
v: me,
|
|
259
259
|
noticeVersion: e,
|
|
260
|
-
origin:
|
|
260
|
+
origin: Me(),
|
|
261
261
|
grantedAt: n,
|
|
262
|
-
expiry: n +
|
|
262
|
+
expiry: n + Ye(t),
|
|
263
263
|
mac: ""
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
|
-
function
|
|
267
|
-
|
|
268
|
-
let n =
|
|
269
|
-
return
|
|
266
|
+
function Ze(e, t) {
|
|
267
|
+
E(C), L();
|
|
268
|
+
let n = Xe(e.noticeVersion, t);
|
|
269
|
+
return O = n, k = !0, A = !0, N += 1, We(n), n;
|
|
270
270
|
}
|
|
271
|
-
async function
|
|
271
|
+
async function Qe(e) {
|
|
272
272
|
try {
|
|
273
|
-
if (await
|
|
274
|
-
let t = await
|
|
275
|
-
if (
|
|
273
|
+
if (await z(), O !== e) return;
|
|
274
|
+
let t = await Re(e);
|
|
275
|
+
if (O !== e) return;
|
|
276
276
|
if (!t) {
|
|
277
|
-
|
|
277
|
+
I(), A = !1;
|
|
278
278
|
return;
|
|
279
279
|
}
|
|
280
280
|
let n = {
|
|
281
281
|
...e,
|
|
282
282
|
mac: t
|
|
283
283
|
};
|
|
284
|
-
|
|
284
|
+
O = n, k = !0, We(n), A = !1;
|
|
285
285
|
} catch {
|
|
286
|
-
|
|
286
|
+
O === e && (I(), A = !1);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
var
|
|
290
|
-
let e =
|
|
289
|
+
var $e = () => {
|
|
290
|
+
let e = Je();
|
|
291
291
|
if (!e) {
|
|
292
|
-
|
|
292
|
+
be("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
|
+
Qe(Ze(e));
|
|
296
|
+
}, et = (e = 3) => {
|
|
297
|
+
P = {
|
|
298
298
|
noticeVersion: e,
|
|
299
299
|
at: Date.now()
|
|
300
300
|
};
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
},
|
|
306
|
-
|
|
307
|
-
},
|
|
308
|
-
async function
|
|
309
|
-
let e =
|
|
301
|
+
}, tt = (e) => {
|
|
302
|
+
ke = e === !0;
|
|
303
|
+
}, B = () => {
|
|
304
|
+
I(), L(), O = null, k = !1, A = !1, N += 1, T(C, "true");
|
|
305
|
+
}, nt = () => {
|
|
306
|
+
I(), L(), E(C), O = null, k = !1, A = !1, P = null, D = null, M += 1, N += 1, j = null, De(Oe.clear(), void 0, ge);
|
|
307
|
+
}, rt = Se, it = T, V = E;
|
|
308
|
+
async function at() {
|
|
309
|
+
let e = N, t = Ue();
|
|
310
310
|
if (!t) {
|
|
311
|
-
|
|
311
|
+
O = null, k = !1;
|
|
312
312
|
return;
|
|
313
313
|
}
|
|
314
|
-
if (!
|
|
315
|
-
if (!
|
|
316
|
-
|
|
314
|
+
if (!F()) return;
|
|
315
|
+
if (!D) {
|
|
316
|
+
j = null, await z();
|
|
317
317
|
return;
|
|
318
318
|
}
|
|
319
|
-
let n = await
|
|
320
|
-
if (e !==
|
|
321
|
-
let i = n &&
|
|
322
|
-
|
|
319
|
+
let n = await ze(t), r = Ue();
|
|
320
|
+
if (e !== N || !r || JSON.stringify(r) !== JSON.stringify(t)) return;
|
|
321
|
+
let i = n && Ve(t, Date.now()) && He(t);
|
|
322
|
+
O = i ? t : null, k = 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 || (N += 1, at());
|
|
327
327
|
});
|
|
328
328
|
} catch {}
|
|
329
|
-
var
|
|
329
|
+
var ot = () => {
|
|
330
330
|
try {
|
|
331
331
|
if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
|
|
332
332
|
} catch {}
|
|
@@ -335,38 +335,38 @@ var it = () => {
|
|
|
335
335
|
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
336
336
|
});
|
|
337
337
|
};
|
|
338
|
-
|
|
338
|
+
z();
|
|
339
339
|
//#endregion
|
|
340
340
|
//#region src/consent/ConsentUI.ts
|
|
341
|
-
var
|
|
341
|
+
var H = "#6366f1", st = 1500, ct = 1500, lt = 6e4, ut = 80, dt = 40, ft = [
|
|
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
|
+
], pt = /^#[0-9a-f]{3}$/i, mt = /^#[0-9a-f]{6}$/i, ht = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i, gt = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+)\s*\)$/i, _t = 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 vt(e) {
|
|
348
|
+
if (typeof e != "string") return H;
|
|
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 H;
|
|
351
|
+
if (pt.test(t) || mt.test(t)) return t.toLowerCase();
|
|
352
|
+
let n = ht.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})` : H;
|
|
356
356
|
}
|
|
357
|
-
let r =
|
|
357
|
+
let r = gt.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})` : H;
|
|
361
361
|
}
|
|
362
|
-
return
|
|
362
|
+
return _t.get(t.toLowerCase()) ?? H;
|
|
363
363
|
}
|
|
364
|
-
function
|
|
364
|
+
function yt(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 bt(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,73 +375,76 @@ function vt(e) {
|
|
|
375
375
|
return null;
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function xt(e) {
|
|
379
379
|
return {
|
|
380
|
-
brandName:
|
|
381
|
-
position:
|
|
382
|
-
accentColor:
|
|
383
|
-
acceptLabel:
|
|
384
|
-
rejectLabel:
|
|
385
|
-
privacyPolicyUrl:
|
|
386
|
-
minVisibleMs:
|
|
380
|
+
brandName: yt(e?.brandName, "Flaxia Crowd", ut),
|
|
381
|
+
position: ft.includes(e?.position) ? e.position : "bottom-right",
|
|
382
|
+
accentColor: vt(e?.accentColor),
|
|
383
|
+
acceptLabel: yt(e?.acceptLabel, x.acceptLabel, dt),
|
|
384
|
+
rejectLabel: yt(e?.rejectLabel, x.rejectLabel, dt),
|
|
385
|
+
privacyPolicyUrl: bt(e?.privacyPolicyUrl),
|
|
386
|
+
minVisibleMs: St(e?.minVisibleMs)
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
|
-
function
|
|
390
|
-
return typeof e != "number" || !Number.isFinite(e) ?
|
|
389
|
+
function St(e) {
|
|
390
|
+
return typeof e != "number" || !Number.isFinite(e) ? st : Math.min(Math.max(Math.floor(e), ct), lt);
|
|
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 Ct(e, t) {
|
|
393
|
+
return typeof t.minVisibleMs == "number" && Number.isFinite(t.minVisibleMs) ? Math.min(Math.max(Math.floor(t.minVisibleMs), 0), lt) : e;
|
|
394
394
|
}
|
|
395
|
-
var
|
|
395
|
+
var wt = "\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", Tt = class {
|
|
396
396
|
constructor(e, t, n, r, i) {
|
|
397
|
-
this.config =
|
|
397
|
+
this.config = xt(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 = wt.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 m = 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, m.appendChild(t);
|
|
415
415
|
}
|
|
416
|
-
if (d.append(f, p,
|
|
416
|
+
if (d.append(f, p, m), 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
|
-
|
|
424
|
-
let h = document.createElement("button");
|
|
425
|
-
h.id = "consent-btn", h.type = "button", h.textContent = a;
|
|
422
|
+
let h = document.createElement("p");
|
|
423
|
+
h.className = "hint", h.textContent = x.acceptGateHint;
|
|
426
424
|
let g = document.createElement("button");
|
|
427
|
-
g.id = "
|
|
428
|
-
let _ =
|
|
429
|
-
|
|
430
|
-
|
|
425
|
+
g.id = "consent-btn", g.type = "button", g.textContent = a;
|
|
426
|
+
let _ = document.createElement("button");
|
|
427
|
+
_.id = "reject-btn", _.type = "button", _.className = "reject", _.textContent = o;
|
|
428
|
+
let v = this.options.now ?? (() => Date.now()), ee = this.options.schedule ?? ((e, t) => void setTimeout(e, t)), y = Ct(this.config.minVisibleMs, this.options), te = v() + y, b = y <= 0, ne = !1;
|
|
429
|
+
b || (g.disabled = !0, g.setAttribute("aria-disabled", "true"), ee(() => {
|
|
430
|
+
b = !0, g.disabled = !1, g.removeAttribute("aria-disabled"), h.remove();
|
|
431
431
|
}, y));
|
|
432
432
|
let re = (e) => {
|
|
433
433
|
ne || (ne = !0, d.remove(), e?.());
|
|
434
434
|
};
|
|
435
|
-
|
|
436
|
-
!b ||
|
|
437
|
-
}),
|
|
435
|
+
g.addEventListener("click", () => {
|
|
436
|
+
!b || v() < te || (et(3), re(e));
|
|
437
|
+
}), _.addEventListener("click", () => {
|
|
438
438
|
re(t);
|
|
439
|
-
}), b || d.appendChild(
|
|
439
|
+
}), b || d.appendChild(h), d.append(g, _), this.root.append(u, d);
|
|
440
440
|
}
|
|
441
|
-
},
|
|
441
|
+
}, U = (...e) => console.log("[flaxia-node]", ...e), Et = class e {
|
|
442
442
|
static {
|
|
443
443
|
this.MAX_PENDING_CONTROLS = 64;
|
|
444
444
|
}
|
|
445
|
+
static {
|
|
446
|
+
this.MAX_QUEUE_LENGTH = 16;
|
|
447
|
+
}
|
|
445
448
|
constructor(e, t = 3e5) {
|
|
446
449
|
this.worker = null, this.queue = [], this.active = null, this.pendingControls = [], this._lastCpuLoad = 0, this._hasCpuLoadSample = !1, this._modelCacheSnapshot = null, this.workerUrl = e || "/worker.js", this.defaultTimeoutMs = t, this.initWorker();
|
|
447
450
|
}
|
|
@@ -454,80 +457,93 @@ var St = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
454
457
|
this.handleWorkerError(/* @__PURE__ */ Error("Worker message error"));
|
|
455
458
|
}, this.worker = e;
|
|
456
459
|
}
|
|
457
|
-
run(
|
|
458
|
-
return new Promise((
|
|
460
|
+
run(t, n, r, i, a, o, s) {
|
|
461
|
+
return new Promise((c, l) => {
|
|
459
462
|
if (!this.worker) {
|
|
460
|
-
|
|
463
|
+
l(/* @__PURE__ */ Error("Worker not available"));
|
|
461
464
|
return;
|
|
462
465
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
466
|
+
if (this.active?.id === t || this.queue.some((e) => e.id === t)) {
|
|
467
|
+
l(/* @__PURE__ */ Error(`WorkerPool already has task ${t} in flight`));
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (this.queue.length >= e.MAX_QUEUE_LENGTH) {
|
|
471
|
+
l(/* @__PURE__ */ Error("WorkerPool queue is full; task rejected (retryable)"));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
let u = () => this.execute(t, n, r, i, a, o, c, l, s);
|
|
475
|
+
this.active ? (U(`task queued id=${t} workload=${n} (active task running)`), this.queue.push({
|
|
476
|
+
id: t,
|
|
477
|
+
job: u,
|
|
478
|
+
reject: l
|
|
479
|
+
})) : u();
|
|
469
480
|
});
|
|
470
481
|
}
|
|
471
|
-
execute(e, t, n,
|
|
472
|
-
let
|
|
473
|
-
if (!
|
|
482
|
+
execute(e, t, n, i, a, o, s, c, u) {
|
|
483
|
+
let f = this.worker;
|
|
484
|
+
if (!f) {
|
|
474
485
|
c(/* @__PURE__ */ Error("Worker not available")), this.dequeue();
|
|
475
486
|
return;
|
|
476
487
|
}
|
|
477
|
-
let
|
|
478
|
-
|
|
479
|
-
let
|
|
480
|
-
if (
|
|
481
|
-
|
|
488
|
+
let p = i ?? this.defaultTimeoutMs, m = !1, g = performance.now();
|
|
489
|
+
U(`task start id=${e} workload=${t} timeoutMs=${p}`);
|
|
490
|
+
let _ = (t) => {
|
|
491
|
+
if (m) return;
|
|
492
|
+
m = !0;
|
|
482
493
|
let n = this.active;
|
|
483
494
|
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:
|
|
486
|
-
if (
|
|
487
|
-
if (
|
|
488
|
-
|
|
495
|
+
}, v = (n) => {
|
|
496
|
+
let { id: i, type: o, result: f, error: p, token: m, cpuLoad: v } = n.data;
|
|
497
|
+
if (i === e) {
|
|
498
|
+
if (l(n.data.modelCache) && (this._modelCacheSnapshot = n.data.modelCache), o === "token") {
|
|
499
|
+
a?.(m);
|
|
489
500
|
return;
|
|
490
501
|
}
|
|
491
|
-
if (
|
|
492
|
-
typeof
|
|
502
|
+
if (o === "heartbeat") {
|
|
503
|
+
typeof v == "number" && Number.isFinite(v) && (this._lastCpuLoad = Math.min(1, Math.max(0, v)), this._hasCpuLoadSample = !0);
|
|
493
504
|
return;
|
|
494
505
|
}
|
|
495
|
-
if (
|
|
496
|
-
|
|
506
|
+
if (o === "swarm-frame") {
|
|
507
|
+
u?.onFrame?.(n.data.frame);
|
|
497
508
|
return;
|
|
498
509
|
}
|
|
499
|
-
if (
|
|
500
|
-
|
|
510
|
+
if (o === "swarm-message") {
|
|
511
|
+
u?.onMessage?.(n.data.message);
|
|
501
512
|
return;
|
|
502
513
|
}
|
|
503
|
-
if (
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
514
|
+
if (o === "done") {
|
|
515
|
+
if (U(`task done id=${e} workload=${t} durationMs=${Math.round(performance.now() - g)}`), !h(f)) {
|
|
516
|
+
_(() => c(/* @__PURE__ */ Error(`task result exceeds the ${d} byte limit; refused on the main thread`)));
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
_(() => s(f));
|
|
520
|
+
} else if (o === "error") {
|
|
521
|
+
U(`task failed id=${e} workload=${t} error=${p}`);
|
|
522
|
+
let i = typeof n.data.errorCode == "string" ? n.data.errorCode : "TASK_FAILED", a = typeof n.data.errorStatus == "number" ? n.data.errorStatus : 500, o = new r(String(p), i, a);
|
|
523
|
+
typeof n.data.detail == "string" && (o.detail = n.data.detail), _(() => c(o));
|
|
524
|
+
} else U(`task unknown-message id=${e} type=${String(o)}`), _(() => c(/* @__PURE__ */ Error(`Unknown message type: ${String(o)}`)));
|
|
509
525
|
}
|
|
510
|
-
},
|
|
511
|
-
|
|
512
|
-
},
|
|
526
|
+
}, ee = () => f.removeEventListener("message", v), y = setTimeout(() => {
|
|
527
|
+
U(`task timeout id=${e} workload=${t} (worker terminated after ${p}ms)`), this.cleanupWorker(), _(() => c(/* @__PURE__ */ Error("TIMEOUT")));
|
|
528
|
+
}, p);
|
|
513
529
|
this.active = {
|
|
514
530
|
id: e,
|
|
515
|
-
resolve:
|
|
531
|
+
resolve: s,
|
|
516
532
|
reject: c,
|
|
517
|
-
timer:
|
|
518
|
-
worker:
|
|
519
|
-
removeListener:
|
|
520
|
-
},
|
|
533
|
+
timer: y,
|
|
534
|
+
worker: f,
|
|
535
|
+
removeListener: ee
|
|
536
|
+
}, f.addEventListener("message", v);
|
|
521
537
|
try {
|
|
522
|
-
|
|
538
|
+
f.postMessage({
|
|
523
539
|
id: e,
|
|
524
540
|
workload: t,
|
|
525
541
|
payload: n,
|
|
526
|
-
timeoutMs:
|
|
527
|
-
config:
|
|
542
|
+
timeoutMs: p,
|
|
543
|
+
config: o
|
|
528
544
|
}), this.flushControls();
|
|
529
545
|
} catch (e) {
|
|
530
|
-
|
|
546
|
+
_(() => c(e instanceof Error ? e : Error(String(e))));
|
|
531
547
|
}
|
|
532
548
|
}
|
|
533
549
|
flushControls() {
|
|
@@ -576,7 +592,7 @@ var St = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
576
592
|
let n = this.queue.findIndex((t) => t.id === e);
|
|
577
593
|
if (n >= 0) {
|
|
578
594
|
let [r] = this.queue.splice(n, 1);
|
|
579
|
-
return this.pendingControls = this.pendingControls.filter((t) => t.taskId !== e),
|
|
595
|
+
return this.pendingControls = this.pendingControls.filter((t) => t.taskId !== e), U(`task aborted before start id=${e} reason=${t}`), r.reject(Error(t)), !0;
|
|
580
596
|
}
|
|
581
597
|
if (this.active?.id !== e || !this.worker) return !1;
|
|
582
598
|
try {
|
|
@@ -584,13 +600,13 @@ var St = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
584
600
|
id: e,
|
|
585
601
|
type: "abort",
|
|
586
602
|
reason: t
|
|
587
|
-
}),
|
|
603
|
+
}), U(`task abort sent id=${e} reason=${t}`), !0;
|
|
588
604
|
} catch {
|
|
589
605
|
return !1;
|
|
590
606
|
}
|
|
591
607
|
}
|
|
592
608
|
handleWorkerError(e) {
|
|
593
|
-
|
|
609
|
+
U(`worker error error=${e.message}`);
|
|
594
610
|
let t = this.active;
|
|
595
611
|
this.cleanupWorker(), t && (clearTimeout(t.timer), this.active = null, t.reject(e), this.dequeue());
|
|
596
612
|
}
|
|
@@ -620,8 +636,8 @@ var St = "\n .overlay {\n position: fixed;\n __flaxia_position__;\n pa
|
|
|
620
636
|
let e = this._modelCacheSnapshot;
|
|
621
637
|
return !e || e.expiresAt <= Date.now() ? null : e;
|
|
622
638
|
}
|
|
623
|
-
},
|
|
624
|
-
function
|
|
639
|
+
}, W = null, Dt = null;
|
|
640
|
+
function G(e, t, n, r, i, a) {
|
|
625
641
|
return {
|
|
626
642
|
value: e,
|
|
627
643
|
unit: t,
|
|
@@ -631,48 +647,48 @@ function W(e, t, n, r, i, a) {
|
|
|
631
647
|
sampleCount: a
|
|
632
648
|
};
|
|
633
649
|
}
|
|
634
|
-
function
|
|
635
|
-
return
|
|
650
|
+
function K(e, t, n) {
|
|
651
|
+
return G(null, e, "unknown", t, t + n, 0);
|
|
636
652
|
}
|
|
637
|
-
async function
|
|
638
|
-
return e ? ((!
|
|
639
|
-
|
|
640
|
-
}),
|
|
653
|
+
async function Ot(e, t) {
|
|
654
|
+
return e ? ((!W || W.expiresAt <= t) && (Dt ||= _().then((e) => (W = e, e)).finally(() => {
|
|
655
|
+
Dt = null;
|
|
656
|
+
}), W = await Dt), W) : null;
|
|
641
657
|
}
|
|
642
|
-
async function
|
|
643
|
-
let
|
|
658
|
+
async function kt(e) {
|
|
659
|
+
let n = e.now ?? Date.now(), r = n + f, i = u(), a = i.bytes !== null && i.sampledAt !== null && n - i.sampledAt <= 864e5, o = Number.isFinite(e.deviceMemory) && e.deviceMemory > 0 && e.deviceMemory <= 1024, s = await Ot(e.probeGpu === !0, n), c = s?.sampledAt ?? n, l = s?.expiresAt ?? n + 6e5;
|
|
644
660
|
return {
|
|
645
661
|
version: 1,
|
|
646
|
-
sampledAt:
|
|
662
|
+
sampledAt: n,
|
|
647
663
|
expiresAt: r,
|
|
648
|
-
cpuLoad: typeof e.cpuLoad == "number" && Number.isFinite(e.cpuLoad) && e.cpuLoad >= 0 && e.cpuLoad <= 1 ?
|
|
649
|
-
wasmMemoryLowerBound: a ?
|
|
650
|
-
deviceMemory: o ?
|
|
664
|
+
cpuLoad: typeof e.cpuLoad == "number" && Number.isFinite(e.cpuLoad) && e.cpuLoad >= 0 && e.cpuLoad <= 1 ? G(e.cpuLoad, "ratio", "estimated", n, r, 1) : K("ratio", n, f),
|
|
665
|
+
wasmMemoryLowerBound: a ? G(i.bytes, "bytes", "measured", i.sampledAt, i.sampledAt + t, 1) : K("bytes", n, t),
|
|
666
|
+
deviceMemory: o ? G(e.deviceMemory, "GiB", "estimated", n, n + t, 1) : K("GiB", n, t),
|
|
651
667
|
gpu: {
|
|
652
668
|
status: s?.status ?? "unknown",
|
|
653
669
|
sampledAt: c,
|
|
654
670
|
expiresAt: l,
|
|
655
|
-
architecture: s?.architecture ?
|
|
656
|
-
maxStorageBufferBindingSize: s?.maxStorageBufferBindingSize !== null && s?.maxStorageBufferBindingSize !== void 0 ?
|
|
657
|
-
computeCompletionMs: s?.computeCompletionMs !== null && s?.computeCompletionMs !== void 0 ?
|
|
658
|
-
memoryBytes:
|
|
671
|
+
architecture: s?.architecture ? G(s.architecture, "text", "measured", c, l, 1) : K("text", c, m),
|
|
672
|
+
maxStorageBufferBindingSize: s?.maxStorageBufferBindingSize !== null && s?.maxStorageBufferBindingSize !== void 0 ? G(s.maxStorageBufferBindingSize, "bytes", "measured", c, l, 1) : K("bytes", c, m),
|
|
673
|
+
computeCompletionMs: s?.computeCompletionMs !== null && s?.computeCompletionMs !== void 0 ? G(s.computeCompletionMs, "ms", "measured", c, l, s.sampleCount) : K("ms", c, m),
|
|
674
|
+
memoryBytes: K("bytes", c, m)
|
|
659
675
|
}
|
|
660
676
|
};
|
|
661
677
|
}
|
|
662
678
|
//#endregion
|
|
663
679
|
//#region src/swarm/peer-quality.ts
|
|
664
|
-
var
|
|
665
|
-
function
|
|
680
|
+
var At = 15e3;
|
|
681
|
+
function jt(e) {
|
|
666
682
|
let t = e.filter((e) => Number.isFinite(e) && e >= 0).slice(-5);
|
|
667
683
|
if (!t.length) return [];
|
|
668
684
|
let n = [...t].sort((e, t) => e - t), r = n[Math.floor(n.length / 2)], i = r + Math.max(20, r * 4);
|
|
669
685
|
return t.filter((e) => e <= i);
|
|
670
686
|
}
|
|
671
|
-
function
|
|
687
|
+
function q(e, t) {
|
|
672
688
|
return !Number.isFinite(e) || e < 0 || !Number.isFinite(t) || t <= 0 ? null : e * 8 / t / 1e3;
|
|
673
689
|
}
|
|
674
|
-
function
|
|
675
|
-
let n =
|
|
690
|
+
function Mt(e, t) {
|
|
691
|
+
let n = jt(e);
|
|
676
692
|
if (!n.length) return {
|
|
677
693
|
value: null,
|
|
678
694
|
sampledAt: t,
|
|
@@ -685,11 +701,11 @@ function At(e, t) {
|
|
|
685
701
|
sampleCount: n.length
|
|
686
702
|
};
|
|
687
703
|
}
|
|
688
|
-
function
|
|
689
|
-
let
|
|
704
|
+
function Nt(e, t, n, r, i) {
|
|
705
|
+
let a = (e, n) => {
|
|
690
706
|
let r = (r) => {
|
|
691
707
|
let i = n?.[r] ?? t;
|
|
692
|
-
return t - i >= 6e4 ?
|
|
708
|
+
return t - i >= 6e4 ? Mt([], t) : Mt(e[r] ?? [], i);
|
|
693
709
|
};
|
|
694
710
|
return {
|
|
695
711
|
rttMs: r("rttMs"),
|
|
@@ -702,15 +718,15 @@ function jt(e, t, n, r, i) {
|
|
|
702
718
|
version: 1,
|
|
703
719
|
peerNodeId: e,
|
|
704
720
|
sampledAt: t,
|
|
705
|
-
expiresAt: t +
|
|
706
|
-
webRtc:
|
|
707
|
-
application:
|
|
721
|
+
expiresAt: t + c,
|
|
722
|
+
webRtc: a(n, i?.webRtc),
|
|
723
|
+
application: a(r, i?.application)
|
|
708
724
|
};
|
|
709
725
|
}
|
|
710
726
|
//#endregion
|
|
711
727
|
//#region src/swarm/peer-transport.ts
|
|
712
|
-
var
|
|
713
|
-
function
|
|
728
|
+
var Pt = 5e3, J = 16 * 1024, Ft = n, It = 256 * 1024, Lt = 1129860166, Y = 16, Rt = 2, zt = 64, Bt = "flaxia-swarm-v1", Vt = "flaxia-peer-quality-v1", Ht = 128, Ut = [{ urls: "stun:stun.cloudflare.com:3478" }];
|
|
729
|
+
function Wt() {
|
|
714
730
|
return {
|
|
715
731
|
rttMs: [],
|
|
716
732
|
jitterMs: [],
|
|
@@ -718,41 +734,41 @@ function Ht() {
|
|
|
718
734
|
receiveMbps: []
|
|
719
735
|
};
|
|
720
736
|
}
|
|
721
|
-
function
|
|
722
|
-
if (e.byteLength <
|
|
737
|
+
function Gt(e) {
|
|
738
|
+
if (e.byteLength < Y || e.byteLength > 16400) return null;
|
|
723
739
|
let t = new DataView(e);
|
|
724
|
-
if (t.getUint32(0, !0) !==
|
|
740
|
+
if (t.getUint32(0, !0) !== Lt) return null;
|
|
725
741
|
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 -
|
|
742
|
+
if (a < 1 || a > Ft || i < 1 || i !== Math.ceil(a / 16384) || r >= i) return null;
|
|
743
|
+
let o = Math.min(J, a - r * J);
|
|
744
|
+
return e.byteLength - Y === o ? {
|
|
729
745
|
messageId: n,
|
|
730
746
|
index: r,
|
|
731
747
|
count: i,
|
|
732
748
|
totalBytes: a,
|
|
733
|
-
payload: new Uint8Array(e,
|
|
749
|
+
payload: new Uint8Array(e, Y)
|
|
734
750
|
} : null;
|
|
735
751
|
}
|
|
736
|
-
function
|
|
737
|
-
if (e.byteLength < 1 || e.byteLength >
|
|
738
|
-
let n = Math.ceil(e.byteLength /
|
|
752
|
+
function Kt(e, t) {
|
|
753
|
+
if (e.byteLength < 1 || e.byteLength > Ft) throw Error(`swarm peer frame size is outside 1..${Ft} bytes`);
|
|
754
|
+
let n = Math.ceil(e.byteLength / J), r = [];
|
|
739
755
|
for (let i = 0; i < n; i++) {
|
|
740
|
-
let a = i *
|
|
741
|
-
l.setUint32(0,
|
|
756
|
+
let a = i * J, o = Math.min(a + J, e.byteLength), s = new Uint8Array(e, a, o - a), c = new ArrayBuffer(Y + s.byteLength), l = new DataView(c);
|
|
757
|
+
l.setUint32(0, Lt, !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, Y).set(s), r.push(c);
|
|
742
758
|
}
|
|
743
759
|
return r;
|
|
744
760
|
}
|
|
745
|
-
var
|
|
761
|
+
var qt = class {
|
|
746
762
|
constructor() {
|
|
747
763
|
this.assemblies = /* @__PURE__ */ new Map();
|
|
748
764
|
}
|
|
749
765
|
accept(e, t = Date.now()) {
|
|
750
766
|
this.expire(t);
|
|
751
|
-
let n =
|
|
767
|
+
let n = Gt(e);
|
|
752
768
|
if (!n) return null;
|
|
753
769
|
let r = this.assemblies.get(n.messageId);
|
|
754
770
|
if (!r) {
|
|
755
|
-
if (this.assemblies.size >=
|
|
771
|
+
if (this.assemblies.size >= Rt) return null;
|
|
756
772
|
r = {
|
|
757
773
|
count: n.count,
|
|
758
774
|
totalBytes: n.totalBytes,
|
|
@@ -782,9 +798,9 @@ var Gt = class {
|
|
|
782
798
|
expire(e) {
|
|
783
799
|
for (let [t, n] of this.assemblies) e - n.createdAt > 5e3 * 2 && this.assemblies.delete(t);
|
|
784
800
|
}
|
|
785
|
-
},
|
|
801
|
+
}, Jt = class {
|
|
786
802
|
constructor(e) {
|
|
787
|
-
this.options = e, this.peers = /* @__PURE__ */ new Map(), this.reassembler = new
|
|
803
|
+
this.options = e, this.peers = /* @__PURE__ */ new Map(), this.reassembler = new qt(), 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
804
|
}
|
|
789
805
|
get selectedMode() {
|
|
790
806
|
return this.mode;
|
|
@@ -798,15 +814,15 @@ var Gt = class {
|
|
|
798
814
|
let e = [...new Set([this.options.previousNodeId, this.options.nextNodeId])].filter((e) => !!e && e !== this.options.nodeId);
|
|
799
815
|
try {
|
|
800
816
|
for (let t of e) {
|
|
801
|
-
let e = (this.options.createPeerConnection ?? ((e) => new RTCPeerConnection(e)))({ iceServers:
|
|
817
|
+
let e = (this.options.createPeerConnection ?? ((e) => new RTCPeerConnection(e)))({ iceServers: Ut }), n = {
|
|
802
818
|
nodeId: t,
|
|
803
819
|
connection: e,
|
|
804
820
|
channel: null,
|
|
805
821
|
remoteDescriptionSet: !1,
|
|
806
822
|
pendingCandidates: [],
|
|
807
823
|
quality: {
|
|
808
|
-
webRtc:
|
|
809
|
-
application:
|
|
824
|
+
webRtc: Wt(),
|
|
825
|
+
application: Wt()
|
|
810
826
|
},
|
|
811
827
|
qualitySampledAt: {
|
|
812
828
|
webRtc: {},
|
|
@@ -836,7 +852,7 @@ var Gt = class {
|
|
|
836
852
|
for (let e of this.peers.values()) {
|
|
837
853
|
let { nodeId: t, connection: n } = e;
|
|
838
854
|
if (this.options.nodeId.localeCompare(t) < 0) {
|
|
839
|
-
this.bindChannel(e, n.createDataChannel(
|
|
855
|
+
this.bindChannel(e, n.createDataChannel(Bt, { ordered: !0 }));
|
|
840
856
|
let r = await n.createOffer();
|
|
841
857
|
if (this.closed || this.failed) return;
|
|
842
858
|
await n.setLocalDescription(r);
|
|
@@ -878,7 +894,7 @@ var Gt = class {
|
|
|
878
894
|
}
|
|
879
895
|
} else if (t.candidate !== null) if (n.remoteDescriptionSet) await n.connection.addIceCandidate(t.candidate);
|
|
880
896
|
else {
|
|
881
|
-
if (n.pendingCandidates.length >=
|
|
897
|
+
if (n.pendingCandidates.length >= zt) throw Error("too many ICE candidates before remote description");
|
|
882
898
|
n.pendingCandidates.push(t.candidate);
|
|
883
899
|
}
|
|
884
900
|
} catch (e) {
|
|
@@ -908,7 +924,7 @@ var Gt = class {
|
|
|
908
924
|
}
|
|
909
925
|
let r = this.nextMessageId++ >>> 0;
|
|
910
926
|
try {
|
|
911
|
-
for (let t of
|
|
927
|
+
for (let t of Kt(e, r)) {
|
|
912
928
|
if (await this.waitForBuffer(n), n.readyState !== "open") throw Error("swarm peer data channel closed while sending");
|
|
913
929
|
n.send(t);
|
|
914
930
|
}
|
|
@@ -929,7 +945,7 @@ var Gt = class {
|
|
|
929
945
|
} catch {}
|
|
930
946
|
return;
|
|
931
947
|
}
|
|
932
|
-
e.channel = t, t.binaryType = "arraybuffer", t.bufferedAmountLowThreshold =
|
|
948
|
+
e.channel = t, t.binaryType = "arraybuffer", t.bufferedAmountLowThreshold = It / 2, t.onopen = () => this.resolveReadyIfOpen(), t.onmessage = (t) => {
|
|
933
949
|
if (typeof t.data == "string") {
|
|
934
950
|
this.handleQualityProbe(e, t.data);
|
|
935
951
|
return;
|
|
@@ -955,7 +971,7 @@ var Gt = class {
|
|
|
955
971
|
}
|
|
956
972
|
async waitForBuffer(e) {
|
|
957
973
|
e.bufferedAmount <= 262144 || await new Promise((t, n) => {
|
|
958
|
-
let r = setTimeout(() => i(/* @__PURE__ */ Error("swarm peer send buffer stalled")),
|
|
974
|
+
let r = setTimeout(() => i(/* @__PURE__ */ Error("swarm peer send buffer stalled")), Pt), i = (i) => {
|
|
959
975
|
clearTimeout(r), e.removeEventListener("bufferedamountlow", a), e.removeEventListener("close", o), i ? n(i) : t();
|
|
960
976
|
}, a = () => i(), o = () => i(/* @__PURE__ */ Error("swarm peer data channel closed while backpressured"));
|
|
961
977
|
e.addEventListener("bufferedamountlow", a, { once: !0 }), e.addEventListener("close", o, { once: !0 });
|
|
@@ -967,7 +983,7 @@ var Gt = class {
|
|
|
967
983
|
this.peers.clear();
|
|
968
984
|
}
|
|
969
985
|
startQualitySampling() {
|
|
970
|
-
this.qualityTimer || !this.options.onQuality || (this.samplePeerQuality(), this.qualityTimer = setInterval(() => void this.samplePeerQuality(),
|
|
986
|
+
this.qualityTimer || !this.options.onQuality || (this.samplePeerQuality(), this.qualityTimer = setInterval(() => void this.samplePeerQuality(), At));
|
|
971
987
|
}
|
|
972
988
|
stopQualitySampling() {
|
|
973
989
|
this.qualityTimer && clearInterval(this.qualityTimer), this.qualityTimer = null;
|
|
@@ -994,7 +1010,7 @@ var Gt = class {
|
|
|
994
1010
|
};
|
|
995
1011
|
try {
|
|
996
1012
|
t.send(JSON.stringify({
|
|
997
|
-
type:
|
|
1013
|
+
type: Vt,
|
|
998
1014
|
kind: "ping",
|
|
999
1015
|
id: n
|
|
1000
1016
|
}));
|
|
@@ -1003,7 +1019,7 @@ var Gt = class {
|
|
|
1003
1019
|
}
|
|
1004
1020
|
}
|
|
1005
1021
|
handleQualityProbe(e, t) {
|
|
1006
|
-
if (t.length >
|
|
1022
|
+
if (t.length > Ht) return;
|
|
1007
1023
|
let n;
|
|
1008
1024
|
try {
|
|
1009
1025
|
let e = JSON.parse(t);
|
|
@@ -1012,12 +1028,12 @@ var Gt = class {
|
|
|
1012
1028
|
} catch {
|
|
1013
1029
|
return;
|
|
1014
1030
|
}
|
|
1015
|
-
if (n.type !==
|
|
1031
|
+
if (n.type !== Vt || !Number.isSafeInteger(n.id) || n.id < 1) return;
|
|
1016
1032
|
if (n.kind === "ping") {
|
|
1017
1033
|
if (e.channel?.readyState !== "open" || e.channel.bufferedAmount > 262144) return;
|
|
1018
1034
|
try {
|
|
1019
1035
|
e.channel.send(JSON.stringify({
|
|
1020
|
-
type:
|
|
1036
|
+
type: Vt,
|
|
1021
1037
|
kind: "pong",
|
|
1022
1038
|
id: n.id
|
|
1023
1039
|
}));
|
|
@@ -1040,10 +1056,10 @@ var Gt = class {
|
|
|
1040
1056
|
this.sendQualityProbe(n);
|
|
1041
1057
|
let r = this.monotonicNow();
|
|
1042
1058
|
if (await this.sampleWebRtc(n, r), n.lastApplicationSampleAt !== void 0) {
|
|
1043
|
-
let e = r - n.lastApplicationSampleAt, t =
|
|
1059
|
+
let e = r - n.lastApplicationSampleAt, t = q(n.applicationBytesSent - n.lastApplicationBytesSent, e), i = q(n.applicationBytesReceived - n.lastApplicationBytesReceived, e);
|
|
1044
1060
|
t !== null && this.recordQuality(n, "application", "sendMbps", t), i !== null && this.recordQuality(n, "application", "receiveMbps", i);
|
|
1045
1061
|
}
|
|
1046
|
-
n.lastApplicationSampleAt = r, n.lastApplicationBytesSent = n.applicationBytesSent, n.lastApplicationBytesReceived = n.applicationBytesReceived, t.push(
|
|
1062
|
+
n.lastApplicationSampleAt = r, n.lastApplicationBytesSent = n.applicationBytesSent, n.lastApplicationBytesReceived = n.applicationBytesReceived, t.push(Nt(n.nodeId, e, n.quality.webRtc, n.quality.application, n.qualitySampledAt));
|
|
1047
1063
|
}
|
|
1048
1064
|
t.length && this.options.onQuality(t.slice(0, 2));
|
|
1049
1065
|
} finally {
|
|
@@ -1068,11 +1084,11 @@ var Gt = class {
|
|
|
1068
1084
|
if (e.lastRtcSampleAt !== void 0) {
|
|
1069
1085
|
let n = t - e.lastRtcSampleAt;
|
|
1070
1086
|
if (d !== void 0 && e.lastRtcBytesSent !== void 0 && s === void 0) {
|
|
1071
|
-
let t =
|
|
1087
|
+
let t = q(d - e.lastRtcBytesSent, n);
|
|
1072
1088
|
t !== null && this.recordQuality(e, "webRtc", "sendMbps", t);
|
|
1073
1089
|
}
|
|
1074
1090
|
if (f !== void 0 && e.lastRtcBytesReceived !== void 0 && c === void 0) {
|
|
1075
|
-
let t =
|
|
1091
|
+
let t = q(f - e.lastRtcBytesReceived, n);
|
|
1076
1092
|
t !== null && this.recordQuality(e, "webRtc", "receiveMbps", t);
|
|
1077
1093
|
}
|
|
1078
1094
|
}
|
|
@@ -1080,34 +1096,34 @@ var Gt = class {
|
|
|
1080
1096
|
} catch {}
|
|
1081
1097
|
}
|
|
1082
1098
|
};
|
|
1083
|
-
function
|
|
1084
|
-
if (!
|
|
1099
|
+
function Yt(e, t) {
|
|
1100
|
+
if (!ee(e)) return !1;
|
|
1085
1101
|
let n = e;
|
|
1086
1102
|
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
1103
|
}
|
|
1088
1104
|
//#endregion
|
|
1089
1105
|
//#region src/client/mobile-lifecycle.ts
|
|
1090
|
-
var
|
|
1091
|
-
function
|
|
1092
|
-
let n = e.batteryCharging === !1, r = n && typeof e.batteryLevel == "number" && e.batteryLevel <=
|
|
1106
|
+
var Xt = .25, Zt = .08, Qt = .45;
|
|
1107
|
+
function $t(e, t) {
|
|
1108
|
+
let n = e.batteryCharging === !1, r = n && typeof e.batteryLevel == "number" && e.batteryLevel <= Xt, i = n && typeof e.batteryLevel == "number" && e.batteryLevel <= Zt, a = e.effectiveType === "slow-2g" || e.effectiveType === "2g", o = r || a || e.saveData === !0;
|
|
1093
1109
|
return {
|
|
1094
1110
|
suspend: e.hidden || e.pageHidden || !e.online || i,
|
|
1095
1111
|
constrained: o,
|
|
1096
|
-
maxCpuLoad: o ? Math.min(t ??
|
|
1112
|
+
maxCpuLoad: o ? Math.min(t ?? Qt, Qt) : t
|
|
1097
1113
|
};
|
|
1098
1114
|
}
|
|
1099
1115
|
//#endregion
|
|
1100
1116
|
//#region src/client/light-preloader.ts
|
|
1101
|
-
var
|
|
1117
|
+
var en = "TeamFlaxia/plamo-3-translate-0.8b-onnx", tn = "text-generation", nn = "q4f16", rn = en, an = class {
|
|
1102
1118
|
constructor(e, t = {}, n = () => !1, r = async () => {}) {
|
|
1103
1119
|
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 ?? "
|
|
1105
|
-
task: t.task ?? "
|
|
1120
|
+
model: t.model ?? "TeamFlaxia/plamo-3-translate-0.8b-onnx",
|
|
1121
|
+
task: t.task ?? "text-generation",
|
|
1106
1122
|
dtype: t.dtype ?? "q4f16"
|
|
1107
1123
|
}];
|
|
1108
1124
|
}
|
|
1109
1125
|
start() {
|
|
1110
|
-
if (this.stopped || this.getConsentState() !== "granted" || this.isUnconstrained() === !1 || !this.targets.some((e) => !this.isPreloaded(e)) || this.preloading) return;
|
|
1126
|
+
if (this.stopped || this.getConsentState() !== "granted" || this.isUnconstrained() === !1 || !this.hasMemoryHeadroom() || !this.targets.some((e) => !this.isPreloaded(e)) || this.preloading) return;
|
|
1111
1127
|
let e = () => {
|
|
1112
1128
|
this.idleHandle = null, this.preloadNow();
|
|
1113
1129
|
};
|
|
@@ -1118,7 +1134,7 @@ var Qt = "Xenova/m2m100_418M", $t = "translation", en = "q4f16", tn = "TeamFlaxi
|
|
|
1118
1134
|
}
|
|
1119
1135
|
isUnconstrained() {
|
|
1120
1136
|
try {
|
|
1121
|
-
let e = navigator, t =
|
|
1137
|
+
let e = navigator, t = $t({
|
|
1122
1138
|
hidden: document.hidden,
|
|
1123
1139
|
pageHidden: document.hidden,
|
|
1124
1140
|
online: navigator.onLine !== !1,
|
|
@@ -1130,8 +1146,15 @@ var Qt = "Xenova/m2m100_418M", $t = "translation", en = "q4f16", tn = "TeamFlaxi
|
|
|
1130
1146
|
return !0;
|
|
1131
1147
|
}
|
|
1132
1148
|
}
|
|
1149
|
+
hasMemoryHeadroom() {
|
|
1150
|
+
try {
|
|
1151
|
+
return this.options.hasMemoryHeadroom?.() !== !1;
|
|
1152
|
+
} catch {
|
|
1153
|
+
return !1;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1133
1156
|
async preloadNow() {
|
|
1134
|
-
if (!(this.stopped || this.preloading) && this.getConsentState() === "granted" && this.isUnconstrained() !== !1) {
|
|
1157
|
+
if (!(this.stopped || this.preloading) && this.getConsentState() === "granted" && this.isUnconstrained() !== !1 && this.hasMemoryHeadroom()) {
|
|
1135
1158
|
this.preloading = !0;
|
|
1136
1159
|
try {
|
|
1137
1160
|
for (let e of this.targets) {
|
|
@@ -1149,25 +1172,25 @@ var Qt = "Xenova/m2m100_418M", $t = "translation", en = "q4f16", tn = "TeamFlaxi
|
|
|
1149
1172
|
}
|
|
1150
1173
|
}
|
|
1151
1174
|
}
|
|
1152
|
-
},
|
|
1153
|
-
function
|
|
1175
|
+
}, X = (...e) => console.log("[flaxia-node]", ...e), Z = (...e) => console.error("[flaxia-node]", ...e);
|
|
1176
|
+
function Q(e) {
|
|
1154
1177
|
let t = /* @__PURE__ */ new Set();
|
|
1155
1178
|
if (!Array.isArray(e)) return [];
|
|
1156
1179
|
for (let n of e.slice(0, 32)) try {
|
|
1157
|
-
let e =
|
|
1180
|
+
let e = ne(n);
|
|
1158
1181
|
e.origin === n && t.add(e.origin);
|
|
1159
1182
|
} catch {}
|
|
1160
1183
|
return [...t];
|
|
1161
1184
|
}
|
|
1162
|
-
var on = "flaxia_node_id",
|
|
1185
|
+
var on = "flaxia_node_id", sn = "flaxia_node_token", cn = class {
|
|
1163
1186
|
receiveSwarmEnvelope(e) {
|
|
1164
|
-
let t =
|
|
1187
|
+
let t = b(e);
|
|
1165
1188
|
!t || ![...this.swarmSessions.values()].includes(t.sessionId) || (this.swarmInboundChain = this.swarmInboundChain.then(async () => {
|
|
1166
1189
|
let e = this.swarmHopKeys.get(t.sessionId);
|
|
1167
1190
|
if (e && e.chainLength > 1) {
|
|
1168
1191
|
if (!t.mac || !e.inboundKey) return;
|
|
1169
|
-
if (!await
|
|
1170
|
-
|
|
1192
|
+
if (!await a(e.inboundKey, t.sessionId, t.frame, t.mac)) {
|
|
1193
|
+
Z(`swarm frame rejected: bad hop MAC sessionId=${t.sessionId}`);
|
|
1171
1194
|
return;
|
|
1172
1195
|
}
|
|
1173
1196
|
}
|
|
@@ -1183,7 +1206,7 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1183
1206
|
attemptId: r,
|
|
1184
1207
|
peers: o
|
|
1185
1208
|
});
|
|
1186
|
-
let s = new
|
|
1209
|
+
let s = new Jt({
|
|
1187
1210
|
sessionId: t,
|
|
1188
1211
|
taskId: n,
|
|
1189
1212
|
attemptId: r,
|
|
@@ -1220,7 +1243,7 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1220
1243
|
}
|
|
1221
1244
|
handleSwarmPeerSignal(e) {
|
|
1222
1245
|
let t = typeof e.sessionId == "string" ? e.sessionId : "", n = this.swarmPeerMetadata.get(t), r = this.swarmPeerTransports.get(t);
|
|
1223
|
-
!n || !r || !
|
|
1246
|
+
!n || !r || !Yt(e, {
|
|
1224
1247
|
...n,
|
|
1225
1248
|
sessionId: t,
|
|
1226
1249
|
nodeId: this.nodeId
|
|
@@ -1234,11 +1257,11 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1234
1257
|
}
|
|
1235
1258
|
async connect() {
|
|
1236
1259
|
if (this.destroyed) return;
|
|
1237
|
-
if (
|
|
1260
|
+
if (R() !== "granted") {
|
|
1238
1261
|
this.disconnect();
|
|
1239
1262
|
return;
|
|
1240
1263
|
}
|
|
1241
|
-
if (
|
|
1264
|
+
if (X(`connect nodeId=${this.nodeId}`), this.ws) {
|
|
1242
1265
|
let e = this.ws;
|
|
1243
1266
|
e.onclose = null;
|
|
1244
1267
|
try {
|
|
@@ -1247,24 +1270,24 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1247
1270
|
this.ws = null;
|
|
1248
1271
|
}
|
|
1249
1272
|
if (this.setupMobileLifecycleHandlers(), this.suspended) return;
|
|
1250
|
-
let
|
|
1273
|
+
let e = await this.obtainToken();
|
|
1251
1274
|
if (this.destroyed || this.suspended) return;
|
|
1252
|
-
if (
|
|
1253
|
-
|
|
1275
|
+
if (R() !== "granted") {
|
|
1276
|
+
X("connect cancelled because consent was revoked while obtaining a token");
|
|
1254
1277
|
return;
|
|
1255
1278
|
}
|
|
1256
|
-
if (!
|
|
1257
|
-
|
|
1279
|
+
if (!e) {
|
|
1280
|
+
Z("token acquisition failed; scheduling reconnect"), this.scheduleReconnect();
|
|
1258
1281
|
return;
|
|
1259
1282
|
}
|
|
1260
1283
|
this.startLightPreloader();
|
|
1261
|
-
let
|
|
1262
|
-
|
|
1263
|
-
let
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
},
|
|
1267
|
-
if (this.ws !==
|
|
1284
|
+
let t = i(this.config.orchestratorUrl, "/crowd/signal"), n = new WebSocket(t, s(e.token));
|
|
1285
|
+
n.binaryType = "arraybuffer", this.ws = n;
|
|
1286
|
+
let r = !1;
|
|
1287
|
+
n.onopen = () => {
|
|
1288
|
+
r = !0, this.reconnectAttempts = 0, X(`signal connected ${t}`), this.sendHeartbeat(n);
|
|
1289
|
+
}, n.onmessage = async (e) => {
|
|
1290
|
+
if (this.ws !== n) return;
|
|
1268
1291
|
if (typeof e.data != "string") {
|
|
1269
1292
|
this.receiveSwarmEnvelope(e.data);
|
|
1270
1293
|
return;
|
|
@@ -1276,22 +1299,22 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1276
1299
|
return;
|
|
1277
1300
|
}
|
|
1278
1301
|
if (t.type === "ping") {
|
|
1279
|
-
this.sendHeartbeat(
|
|
1302
|
+
this.sendHeartbeat(n);
|
|
1280
1303
|
return;
|
|
1281
1304
|
}
|
|
1282
1305
|
if (t.type === "task") {
|
|
1283
1306
|
let e = t;
|
|
1284
|
-
|
|
1307
|
+
X(`task received taskId=${e.taskId} workload=${e.workload} timeoutMs=${e.timeoutMs ?? "default"}`), typeof e.attemptId == "string" && this.attempts.set(e.taskId, e.attemptId);
|
|
1285
1308
|
let n = e.attemptId ?? this.attempts.get(e.taskId);
|
|
1286
1309
|
try {
|
|
1287
1310
|
await this.handleTask(e);
|
|
1288
1311
|
} catch (r) {
|
|
1289
1312
|
let i = r instanceof Error ? r.message : String(r);
|
|
1290
1313
|
if (this.abortedTasks.delete(e.taskId)) {
|
|
1291
|
-
|
|
1314
|
+
X(`task stopped on coordinator abort taskId=${e.taskId} error=${i}`);
|
|
1292
1315
|
return;
|
|
1293
1316
|
}
|
|
1294
|
-
|
|
1317
|
+
Z(`task failed taskId=${e.taskId} workload=${e.workload} error=${i}`), this.send({
|
|
1295
1318
|
type: "error",
|
|
1296
1319
|
taskId: String(t.taskId ?? ""),
|
|
1297
1320
|
error: i,
|
|
@@ -1346,10 +1369,10 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1346
1369
|
this.handleAbort(t);
|
|
1347
1370
|
return;
|
|
1348
1371
|
}
|
|
1349
|
-
},
|
|
1350
|
-
this.ws ===
|
|
1351
|
-
},
|
|
1352
|
-
|
|
1372
|
+
}, n.onerror = () => {
|
|
1373
|
+
this.ws === n && Z("signal websocket error");
|
|
1374
|
+
}, n.onclose = (e) => {
|
|
1375
|
+
n.onclose = null, this.ws === n && (this.ws = null, r || (this.cachedToken = null), !this.destroyed && (X(`signal disconnected code=${e.code} reason=${JSON.stringify(e.reason)} clean=${e.wasClean}; scheduling reconnect attempt=${this.reconnectAttempts + 1}`), this.scheduleReconnect()));
|
|
1353
1376
|
};
|
|
1354
1377
|
}
|
|
1355
1378
|
handleAbort(e) {
|
|
@@ -1358,16 +1381,16 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1358
1381
|
let n = typeof e.error == "string" && e.error ? e.error : "aborted by the coordinator", r = this.swarmSessions.get(t);
|
|
1359
1382
|
if (r && r !== e.sessionId) return;
|
|
1360
1383
|
let i = r ?? t;
|
|
1361
|
-
r && this.retireSwarmSession(r), this.workerPool.abort(i, n) && this.abortedTasks.add(i),
|
|
1384
|
+
r && this.retireSwarmSession(r), this.workerPool.abort(i, n) && this.abortedTasks.add(i), X(`task abort received taskId=${t} error=${n}`);
|
|
1362
1385
|
}
|
|
1363
1386
|
async sendHeartbeat(e) {
|
|
1364
|
-
if (this.ws !== e || e.readyState !== WebSocket.OPEN ||
|
|
1365
|
-
let t = (this.config.capabilities ?? ["ai-inference", "image-process"]).includes("swarm-inference") && this.config.allowModelDownload === !0, n = navigator.deviceMemory, r = await
|
|
1387
|
+
if (this.ws !== e || e.readyState !== WebSocket.OPEN || R() !== "granted") return;
|
|
1388
|
+
let t = (this.config.capabilities ?? ["ai-inference", "image-process"]).includes("swarm-inference") && this.config.allowModelDownload === !0, n = navigator.deviceMemory, r = await kt({
|
|
1366
1389
|
cpuLoad: this.workerPool.hasCpuLoadSample ? this.workerPool.lastCpuLoad : null,
|
|
1367
1390
|
deviceMemory: n,
|
|
1368
1391
|
probeGpu: t
|
|
1369
1392
|
});
|
|
1370
|
-
this.ws !== e || e.readyState !== WebSocket.OPEN ||
|
|
1393
|
+
this.ws !== e || e.readyState !== WebSocket.OPEN || R() !== "granted" || this.send({
|
|
1371
1394
|
type: "pong",
|
|
1372
1395
|
cpuLoad: this.workerPool.hasCpuLoadSample ? this.workerPool.lastCpuLoad : null,
|
|
1373
1396
|
resources: r,
|
|
@@ -1381,7 +1404,7 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1381
1404
|
}, e);
|
|
1382
1405
|
}
|
|
1383
1406
|
disconnect() {
|
|
1384
|
-
|
|
1407
|
+
X(`disconnect nodeId=${this.nodeId}`), this.destroyed = !0, this.suspended = !1, this.stopLightPreloader(), this.removeMobileLifecycleHandlers();
|
|
1385
1408
|
try {
|
|
1386
1409
|
this.ws?.close();
|
|
1387
1410
|
} catch {}
|
|
@@ -1389,7 +1412,7 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1389
1412
|
for (let e of this.swarmPeerTransports.values()) e.close();
|
|
1390
1413
|
this.swarmPeerTransports.clear(), this.swarmPeerMetadata.clear();
|
|
1391
1414
|
try {
|
|
1392
|
-
delete window[
|
|
1415
|
+
delete window[ln];
|
|
1393
1416
|
} catch {}
|
|
1394
1417
|
try {
|
|
1395
1418
|
this.workerPool.terminate();
|
|
@@ -1397,7 +1420,7 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1397
1420
|
}
|
|
1398
1421
|
suspend() {
|
|
1399
1422
|
if (!(this.suspended || this.destroyed)) {
|
|
1400
|
-
if (
|
|
1423
|
+
if (X("suspended (visibility or manual)"), this.suspended = !0, this.stopLightPreloader(), this.ws) {
|
|
1401
1424
|
let e = this.ws;
|
|
1402
1425
|
e.onclose = null;
|
|
1403
1426
|
try {
|
|
@@ -1409,18 +1432,18 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1409
1432
|
}
|
|
1410
1433
|
}
|
|
1411
1434
|
resume() {
|
|
1412
|
-
!this.suspended || this.destroyed || (
|
|
1435
|
+
!this.suspended || this.destroyed || (X("resumed"), this.suspended = !1, this.workerPool.resume(), this.connect());
|
|
1413
1436
|
}
|
|
1414
1437
|
async obtainToken() {
|
|
1415
|
-
let e = () =>
|
|
1438
|
+
let e = () => R() === "granted";
|
|
1416
1439
|
if (!e()) return null;
|
|
1417
1440
|
try {
|
|
1418
|
-
if (this.cachedToken && this.cachedToken.expiresAt > Date.now() + 6e4) return
|
|
1419
|
-
let t =
|
|
1420
|
-
n || (i = i.filter((e) => !
|
|
1441
|
+
if (this.cachedToken && this.cachedToken.expiresAt > Date.now() + 6e4) return X(`token cached nodeId=${this.cachedToken.nodeId} expiresIn=${Math.round((this.cachedToken.expiresAt - Date.now()) / 1e3)}s`), this.cachedToken;
|
|
1442
|
+
let t = p(), n = t >= y, r = this.config.capabilities ?? ["ai-inference", "image-process"], i = [...r];
|
|
1443
|
+
n || (i = i.filter((e) => !te.has(e))), Q(this.config.containerImageOrigins).length === 0 && (i = i.filter((e) => e !== "container")), Q(this.config.ccRangeOrigins).length === 0 && (i = i.filter((e) => e !== "cc-extract"));
|
|
1421
1444
|
let a;
|
|
1422
1445
|
if (n && r.includes("swarm-inference") && this.config.allowModelDownload === !0) {
|
|
1423
|
-
let t = await
|
|
1446
|
+
let t = await kt({
|
|
1424
1447
|
cpuLoad: this.workerPool.hasCpuLoadSample ? this.workerPool.lastCpuLoad : null,
|
|
1425
1448
|
deviceMemory: navigator.deviceMemory,
|
|
1426
1449
|
probeGpu: !0
|
|
@@ -1428,7 +1451,7 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1428
1451
|
if (!e()) return null;
|
|
1429
1452
|
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");
|
|
1430
1453
|
} else i = i.filter((e) => e !== "swarm-inference");
|
|
1431
|
-
|
|
1454
|
+
X(`register capability probe capable=${n} wasmMemoryBytes=${t} capabilities=${JSON.stringify(i)} webgpu=${a?.webgpu ?? !1}`);
|
|
1432
1455
|
let o = this.config.orchestratorUrl.replace(/\/+$/, "");
|
|
1433
1456
|
if (!e()) return null;
|
|
1434
1457
|
let s = await fetch(`${o}/crowd/nodes/register`, {
|
|
@@ -1437,18 +1460,18 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1437
1460
|
body: JSON.stringify({
|
|
1438
1461
|
siteId: this.config.siteId,
|
|
1439
1462
|
capabilities: i,
|
|
1440
|
-
fileSources:
|
|
1441
|
-
wasmMemoryBytes:
|
|
1463
|
+
fileSources: Q(this.config.fileSourceOrigins).length > 0,
|
|
1464
|
+
wasmMemoryBytes: p(),
|
|
1442
1465
|
deviceMemory: typeof navigator.deviceMemory == "number" ? navigator.deviceMemory : null,
|
|
1443
1466
|
swarm: a
|
|
1444
1467
|
})
|
|
1445
1468
|
});
|
|
1446
1469
|
if (!e()) return null;
|
|
1447
|
-
if (!s.ok) return
|
|
1470
|
+
if (!s.ok) return Z(`node register failed HTTP ${s.status} (${o}/crowd/nodes/register)`), null;
|
|
1448
1471
|
let c = await s.json();
|
|
1449
|
-
return e() ? c.token ? (typeof c.nodeId == "string" && c.nodeId && (this.nodeId = c.nodeId), this.cachedToken = c,
|
|
1472
|
+
return e() ? c.token ? (typeof c.nodeId == "string" && c.nodeId && (this.nodeId = c.nodeId), this.cachedToken = c, X(`node registered nodeId=${this.nodeId} expiresIn=${Math.round((c.expiresAt - Date.now()) / 1e3)}s`), c) : (Z("node register returned no token"), null) : null;
|
|
1450
1473
|
} catch (e) {
|
|
1451
|
-
return
|
|
1474
|
+
return Z("node register threw", e instanceof Error ? e.message : e), null;
|
|
1452
1475
|
}
|
|
1453
1476
|
}
|
|
1454
1477
|
send(e) {
|
|
@@ -1462,15 +1485,15 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1462
1485
|
let n = this.swarmHopKeys.get(e);
|
|
1463
1486
|
if (n && n.chainLength > 1) {
|
|
1464
1487
|
if (!n.outboundKey) {
|
|
1465
|
-
|
|
1488
|
+
Z(`swarm frame not sent: no hop key sessionId=${e}`);
|
|
1466
1489
|
return;
|
|
1467
1490
|
}
|
|
1468
|
-
let
|
|
1469
|
-
(!
|
|
1491
|
+
let r = await o(n.outboundKey, e, t), i = this.swarmPeerTransports.get(e);
|
|
1492
|
+
(!i || !await i.sendFrame(r)) && this.sendBinary(r);
|
|
1470
1493
|
return;
|
|
1471
1494
|
}
|
|
1472
|
-
let
|
|
1473
|
-
(!
|
|
1495
|
+
let r = g(e, t), i = this.swarmPeerTransports.get(e);
|
|
1496
|
+
(!i || !await i.sendFrame(r)) && this.sendBinary(r);
|
|
1474
1497
|
}).catch((t) => {
|
|
1475
1498
|
let n = this.swarmPeerMetadata.get(e);
|
|
1476
1499
|
!n || this.swarmFailureReported.has(e) || (this.swarmFailureReported.add(e), this.send({
|
|
@@ -1523,10 +1546,10 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1523
1546
|
sessionId: n,
|
|
1524
1547
|
payload: o,
|
|
1525
1548
|
attemptId: a
|
|
1526
|
-
}),
|
|
1549
|
+
}), X(`swarm result sent taskId=${e} durationMs=${Math.round(performance.now() - r)}`);
|
|
1527
1550
|
} catch (t) {
|
|
1528
1551
|
let r = t instanceof Error ? t.message : String(t);
|
|
1529
|
-
this.abortedTasks.delete(n) ?
|
|
1552
|
+
this.abortedTasks.delete(n) ? X(`swarm stopped on coordinator abort taskId=${e} error=${r}`) : (Z(`swarm failed taskId=${e} error=${r}`), this.send({
|
|
1530
1553
|
type: "error",
|
|
1531
1554
|
taskId: e,
|
|
1532
1555
|
sessionId: n,
|
|
@@ -1551,28 +1574,28 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1551
1574
|
});
|
|
1552
1575
|
}, {
|
|
1553
1576
|
maxCpuLoad: this.effectiveMaxCpuLoad(),
|
|
1554
|
-
fileSourceOrigins:
|
|
1555
|
-
containerImageOrigins:
|
|
1556
|
-
ccRangeOrigins:
|
|
1577
|
+
fileSourceOrigins: Q(this.config.fileSourceOrigins),
|
|
1578
|
+
containerImageOrigins: Q(this.config.containerImageOrigins),
|
|
1579
|
+
ccRangeOrigins: Q(this.config.ccRangeOrigins)
|
|
1557
1580
|
});
|
|
1558
1581
|
this.send({
|
|
1559
1582
|
type: "result",
|
|
1560
1583
|
taskId: e.taskId,
|
|
1561
1584
|
payload: i,
|
|
1562
1585
|
attemptId: n
|
|
1563
|
-
}),
|
|
1586
|
+
}), X(`task result sent taskId=${e.taskId} workload=${e.workload} durationMs=${Math.round(performance.now() - t)}`);
|
|
1564
1587
|
} finally {
|
|
1565
1588
|
this.inflightTasks.delete(e.taskId), this.attempts.delete(e.taskId);
|
|
1566
1589
|
}
|
|
1567
1590
|
}
|
|
1568
|
-
async runLocalAiInference(
|
|
1569
|
-
if (!this.workerPool) throw new
|
|
1570
|
-
if (
|
|
1571
|
-
let
|
|
1572
|
-
return await this.workerPool.run(
|
|
1591
|
+
async runLocalAiInference(t, n) {
|
|
1592
|
+
if (!this.workerPool) throw new e("No running Crowd node on this device", "node_not_running");
|
|
1593
|
+
if (R() !== "granted") throw new e("Crowd consent is not granted", "consent_not_granted");
|
|
1594
|
+
let r = `local-${typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`}`;
|
|
1595
|
+
return await this.workerPool.run(r, "ai-inference", t, 3e5, n, {
|
|
1573
1596
|
maxCpuLoad: this.effectiveMaxCpuLoad(),
|
|
1574
|
-
fileSourceOrigins:
|
|
1575
|
-
containerImageOrigins:
|
|
1597
|
+
fileSourceOrigins: Q(this.config.fileSourceOrigins),
|
|
1598
|
+
containerImageOrigins: Q(this.config.containerImageOrigins)
|
|
1576
1599
|
});
|
|
1577
1600
|
}
|
|
1578
1601
|
isAiModelPreloaded(e) {
|
|
@@ -1587,17 +1610,14 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1587
1610
|
await this.workerPool.run(t, "ai-preload", e, 3e5, void 0, { maxCpuLoad: this.effectiveMaxCpuLoad() });
|
|
1588
1611
|
}
|
|
1589
1612
|
startLightPreloader() {
|
|
1590
|
-
this.lightPreloader && this.lightPreloader.stop(), this.lightPreloader = new an(() =>
|
|
1613
|
+
this.lightPreloader && this.lightPreloader.stop(), this.lightPreloader = new an(() => R(), {
|
|
1591
1614
|
targets: [{
|
|
1592
|
-
model:
|
|
1593
|
-
task:
|
|
1594
|
-
dtype:
|
|
1595
|
-
}, {
|
|
1596
|
-
model: tn,
|
|
1597
|
-
task: nn,
|
|
1598
|
-
dtype: rn
|
|
1615
|
+
model: en,
|
|
1616
|
+
task: tn,
|
|
1617
|
+
dtype: nn
|
|
1599
1618
|
}],
|
|
1600
|
-
onPreloaded: () => {}
|
|
1619
|
+
onPreloaded: () => {},
|
|
1620
|
+
hasMemoryHeadroom: () => v()
|
|
1601
1621
|
}, (e) => this.isAiModelPreloaded({
|
|
1602
1622
|
model: e.model,
|
|
1603
1623
|
dtype: e.dtype
|
|
@@ -1640,7 +1660,7 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1640
1660
|
this.batteryState = null, this.networkState = null;
|
|
1641
1661
|
}
|
|
1642
1662
|
mobileLifecycleDecision() {
|
|
1643
|
-
return
|
|
1663
|
+
return $t({
|
|
1644
1664
|
hidden: document.hidden,
|
|
1645
1665
|
pageHidden: this.lifecyclePageHidden,
|
|
1646
1666
|
online: !this.lifecycleOffline && navigator.onLine !== !1,
|
|
@@ -1656,80 +1676,80 @@ var on = "flaxia_node_id", Q = "flaxia_node_token", sn = class {
|
|
|
1656
1676
|
refreshMobileLifecycle() {
|
|
1657
1677
|
this.mobileLifecycleDecision().suspend ? this.suspend() : this.suspended && this.resume();
|
|
1658
1678
|
}
|
|
1659
|
-
}, $ = "__flaxia_node_signal_client",
|
|
1660
|
-
if (
|
|
1661
|
-
|
|
1679
|
+
}, $ = "__flaxia_node_signal_client", ln = "__flaxia_node_init_started", un = "__flaxia_node_controller", dn = (e) => {
|
|
1680
|
+
if (R() !== "granted") {
|
|
1681
|
+
Z("refusing to start the node without a granted consent record");
|
|
1662
1682
|
return;
|
|
1663
1683
|
}
|
|
1664
1684
|
let t = window[$];
|
|
1665
|
-
t && t.disconnect(),
|
|
1666
|
-
let n = new URL("./worker.js", "" + import.meta.url).href, r = new
|
|
1667
|
-
i || (i =
|
|
1668
|
-
let a = new
|
|
1685
|
+
t && t.disconnect(), V(sn);
|
|
1686
|
+
let n = new URL("./worker.js", "" + import.meta.url).href, r = new Et(n), i = rt(on);
|
|
1687
|
+
i || (i = ot(), it(on, i));
|
|
1688
|
+
let a = new cn(e, r, i);
|
|
1669
1689
|
window[$] = a, a.connect();
|
|
1670
|
-
},
|
|
1690
|
+
}, fn = class {
|
|
1671
1691
|
constructor(e) {
|
|
1672
1692
|
this.config = e;
|
|
1673
1693
|
}
|
|
1674
1694
|
start() {
|
|
1675
|
-
this.isRunning() || !
|
|
1695
|
+
this.isRunning() || !Ge() || dn(this.config);
|
|
1676
1696
|
}
|
|
1677
1697
|
stop() {
|
|
1678
1698
|
let e = window[$];
|
|
1679
|
-
e && e.disconnect(), delete window[$], delete window[
|
|
1699
|
+
e && e.disconnect(), delete window[$], delete window[ln];
|
|
1680
1700
|
}
|
|
1681
1701
|
isRunning() {
|
|
1682
1702
|
return !!window[$];
|
|
1683
1703
|
}
|
|
1684
1704
|
getConsentState() {
|
|
1685
|
-
return
|
|
1705
|
+
return R();
|
|
1686
1706
|
}
|
|
1687
1707
|
grant() {
|
|
1688
|
-
|
|
1708
|
+
$e();
|
|
1689
1709
|
}
|
|
1690
1710
|
deny() {
|
|
1691
|
-
|
|
1711
|
+
B(), this.stop(), V(sn);
|
|
1692
1712
|
}
|
|
1693
1713
|
clearConsent() {
|
|
1694
|
-
|
|
1714
|
+
nt(), this.stop(), V(sn);
|
|
1695
1715
|
}
|
|
1696
|
-
async runLocalAiInference(
|
|
1697
|
-
let
|
|
1698
|
-
if (!
|
|
1699
|
-
return
|
|
1716
|
+
async runLocalAiInference(t, n) {
|
|
1717
|
+
let r = window[$];
|
|
1718
|
+
if (!r || !this.isRunning()) throw new e("No running Crowd node on this device", "node_not_running");
|
|
1719
|
+
return r.runLocalAiInference(t, n);
|
|
1700
1720
|
}
|
|
1701
1721
|
isAiModelPreloaded(e) {
|
|
1702
1722
|
let t = window[$];
|
|
1703
1723
|
return t ? t.isAiModelPreloaded(e) : !1;
|
|
1704
1724
|
}
|
|
1705
|
-
async preloadAiModel(
|
|
1706
|
-
let
|
|
1707
|
-
if (!
|
|
1708
|
-
await
|
|
1725
|
+
async preloadAiModel(t) {
|
|
1726
|
+
let n = window[$];
|
|
1727
|
+
if (!n) throw new e("No running Crowd node on this device", "node_not_running");
|
|
1728
|
+
await n.preloadAiModel(t);
|
|
1709
1729
|
}
|
|
1710
|
-
},
|
|
1711
|
-
let t = window[
|
|
1730
|
+
}, pn = (e) => {
|
|
1731
|
+
let t = window[un];
|
|
1712
1732
|
if (t) return t;
|
|
1713
|
-
let n = new
|
|
1714
|
-
window[
|
|
1715
|
-
let r =
|
|
1733
|
+
let n = new fn(e);
|
|
1734
|
+
window[un] = n, window[ln] = !0;
|
|
1735
|
+
let r = R();
|
|
1716
1736
|
if (r === "granted") return n.start(), n;
|
|
1717
1737
|
if (r === "denied") return n;
|
|
1718
1738
|
if (e.consent.onConsentRequired) return e.consent.onConsentRequired({
|
|
1719
1739
|
state: r,
|
|
1720
1740
|
accept: () => {
|
|
1721
|
-
|
|
1741
|
+
$e(), n.start();
|
|
1722
1742
|
},
|
|
1723
1743
|
reject: () => {
|
|
1724
|
-
|
|
1744
|
+
B();
|
|
1725
1745
|
}
|
|
1726
1746
|
}), n;
|
|
1727
1747
|
let i = document.createElement("div");
|
|
1728
|
-
return i.id = "flaxia-consent-container", document.body.appendChild(i), new
|
|
1729
|
-
|
|
1748
|
+
return i.id = "flaxia-consent-container", document.body.appendChild(i), new Tt(i, e.consent, () => {
|
|
1749
|
+
$e(), i.remove(), n.start();
|
|
1730
1750
|
}, () => {
|
|
1731
|
-
|
|
1751
|
+
B(), i.remove();
|
|
1732
1752
|
}), n;
|
|
1733
1753
|
};
|
|
1734
1754
|
//#endregion
|
|
1735
|
-
export {
|
|
1755
|
+
export { nn as LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE, ue as LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE_ID, en as LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL, se as LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL_ID, tn as LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK, le as LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK_ID, ae as LIGHT_INFERENCE_TRANSLATE_DTYPE, rn as LIGHT_INFERENCE_TRANSLATE_MODEL, re as LIGHT_INFERENCE_TRANSLATE_MODEL_ID, ce as LIGHT_INFERENCE_TRANSLATE_TASK, R as getFlaxiaNodeConsentState, pn as initFlaxiaNode, z as initFlaxiaNodeConsent, ie as isAiModelPreloaded, oe as preloadAiModel, tt as setFlaxiaNodeHostManagedConsent };
|