@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.
Files changed (52) hide show
  1. package/dist/assets/ai-inference.js +9 -9
  2. package/dist/assets/ai-model-registry.js +0 -5
  3. package/dist/assets/cc-extract.js +20 -20
  4. package/dist/assets/container.js +59 -43
  5. package/dist/assets/decision.js +43 -36
  6. package/dist/assets/embed-gemma.js +28 -20
  7. package/dist/assets/image-process.js +78 -70
  8. package/dist/assets/nudenet.js +2 -2
  9. package/dist/assets/{VectorStoreEngine.js → sharedEngine.js} +67 -41
  10. package/dist/assets/vector-embed.js +49 -36
  11. package/dist/assets/vector-query.js +4 -4
  12. package/dist/assets/vector-store.js +4 -4
  13. package/dist/assets/webgpuProbe.js +87 -47
  14. package/dist/client/SignalingClient.d.ts.map +1 -1
  15. package/dist/client/light-preloader.d.ts +16 -6
  16. package/dist/client/light-preloader.d.ts.map +1 -1
  17. package/dist/executor/WorkerPool.d.ts +6 -0
  18. package/dist/executor/WorkerPool.d.ts.map +1 -1
  19. package/dist/executor/__tests__/resultLimits.test.d.ts +2 -0
  20. package/dist/executor/__tests__/resultLimits.test.d.ts.map +1 -0
  21. package/dist/executor/container-executor.d.ts +15 -0
  22. package/dist/executor/container-executor.d.ts.map +1 -1
  23. package/dist/executor/memoryProbe.d.ts +25 -1
  24. package/dist/executor/memoryProbe.d.ts.map +1 -1
  25. package/dist/executor/resultLimits.d.ts +19 -0
  26. package/dist/executor/resultLimits.d.ts.map +1 -0
  27. package/dist/index.js +416 -396
  28. package/dist/vector-store/HNSWIndex.d.ts +4 -1
  29. package/dist/vector-store/HNSWIndex.d.ts.map +1 -1
  30. package/dist/vector-store/VectorStoreEngine.d.ts +7 -1
  31. package/dist/vector-store/VectorStoreEngine.d.ts.map +1 -1
  32. package/dist/vector-store/__tests__/sharedEngine.test.d.ts +2 -0
  33. package/dist/vector-store/__tests__/sharedEngine.test.d.ts.map +1 -0
  34. package/dist/vector-store/sharedEngine.d.ts +13 -0
  35. package/dist/vector-store/sharedEngine.d.ts.map +1 -0
  36. package/dist/worker.js +163 -160
  37. package/dist/workloads/__tests__/nudenet-session-cache.test.d.ts +2 -0
  38. package/dist/workloads/__tests__/nudenet-session-cache.test.d.ts.map +1 -0
  39. package/dist/workloads/ai-inference.d.ts +8 -7
  40. package/dist/workloads/ai-inference.d.ts.map +1 -1
  41. package/dist/workloads/ai-model-registry.d.ts.map +1 -1
  42. package/dist/workloads/decision.d.ts +2 -0
  43. package/dist/workloads/decision.d.ts.map +1 -1
  44. package/dist/workloads/embed-gemma.d.ts.map +1 -1
  45. package/dist/workloads/image-process.d.ts +8 -0
  46. package/dist/workloads/image-process.d.ts.map +1 -1
  47. package/dist/workloads/nudenet.d.ts.map +1 -1
  48. package/dist/workloads/vector-embed.d.ts +6 -0
  49. package/dist/workloads/vector-embed.d.ts.map +1 -1
  50. package/dist/workloads/vector-query.d.ts.map +1 -1
  51. package/dist/workloads/vector-store.d.ts.map +1 -1
  52. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
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";
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
- }, 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) {
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 ve.get(e) ?? null;
21
+ return xe.get(e) ?? null;
22
22
  }
23
23
  }
24
- function be(e, t) {
24
+ function T(e, t) {
25
25
  try {
26
26
  localStorage.setItem(e, t);
27
27
  } catch {
28
- ve.set(e, t);
28
+ xe.set(e, t);
29
29
  }
30
30
  }
31
- function T(e) {
31
+ function E(e) {
32
32
  try {
33
33
  localStorage.removeItem(e);
34
34
  } catch {
35
- ve.delete(e);
35
+ xe.delete(e);
36
36
  }
37
37
  }
38
- function xe(e) {
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 Se() {
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(me, he);
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 Ce(e) {
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 we = {
73
+ var Ee = {
74
74
  async load() {
75
- let e = await Se();
75
+ let e = await we();
76
76
  try {
77
- let t = await xe(e.transaction(w, "readonly").objectStore(w).get(ge));
78
- return Ce(t) ? t : null;
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 Se();
84
+ let t = await we();
85
85
  try {
86
86
  let n = t.transaction(w, "readwrite");
87
- n.objectStore(w).put(e, ge), await new Promise((e, t) => {
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 Se();
95
+ let e = await we();
96
96
  try {
97
97
  let t = e.transaction(w, "readwrite");
98
- t.objectStore(w).delete(ge), await new Promise((e, n) => {
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 Te(e, t, n) {
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 Ee = we, E = null, D = null, O = !1, k = !1, A = null, j = 0, M = 0, N = null, De = !1;
115
- function Oe() {
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 ke = Oe, Ae = () => ke(), je = {
122
+ var je = Ae, Me = () => je(), Ne = {
123
123
  name: "HMAC",
124
124
  hash: "SHA-256"
125
125
  };
126
- function P() {
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 Me(e) {
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 Ne(e) {
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 Pe(e) {
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 Fe() {
158
- let e = await Te(Ee.load(), null, pe);
157
+ async function Le() {
158
+ let e = await De(Oe.load(), null, ge);
159
159
  if (e) return e;
160
- let t = P();
160
+ let t = F();
161
161
  if (!t) return null;
162
162
  try {
163
- let e = await t.generateKey(je, !1, ["sign", "verify"]);
164
- return await Te(Ee.save(e), void 0, pe), e;
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 Ie(e) {
170
- let t = P();
171
- if (!t || !E) return null;
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", E, Me(e));
174
- return Ne(new Uint8Array(n));
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 Le(e) {
180
- let t = P();
181
- if (!t || !E || !e.mac) return !1;
182
- let n = Pe(e.mac);
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", E, n, Me(e));
185
+ return await t.verify("HMAC", D, n, Pe(e));
186
186
  } catch {
187
187
  return !1;
188
188
  }
189
189
  }
190
- function Re(e) {
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 ze(e, t) {
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 F(e) {
212
- return e.v === de && e.noticeVersion === 3 && e.origin === Ae();
211
+ function He(e) {
212
+ return e.v === me && e.noticeVersion === 3 && e.origin === Me();
213
213
  }
214
- function I() {
215
- return Re(ye(S));
214
+ function Ue() {
215
+ return Be(Se(S));
216
216
  }
217
- function Be(e) {
218
- be(S, JSON.stringify(e));
217
+ function We(e) {
218
+ T(S, JSON.stringify(e));
219
219
  }
220
- function L() {
221
- T(S);
220
+ function I() {
221
+ E(S);
222
222
  }
223
- function R() {
224
- T(le), T(ue);
223
+ function L() {
224
+ E(fe), E(pe);
225
225
  }
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;
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 Fe();
233
+ n = await Le();
234
234
  } catch {
235
235
  n = null;
236
236
  }
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();
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 We() {
243
- let e = N;
244
- return N = null, e && Date.now() - e.at <= fe ? {
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
- } : De ? {
247
+ } : ke ? {
248
248
  noticeVersion: 3,
249
249
  source: "host-managed"
250
250
  } : null;
251
251
  }
252
- function Ge(e) {
253
- return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? ce : Math.min(Math.floor(e), ce);
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 Ke(e, t) {
255
+ function Xe(e, t) {
256
256
  let n = Date.now();
257
257
  return {
258
- v: de,
258
+ v: me,
259
259
  noticeVersion: e,
260
- origin: Ae(),
260
+ origin: Me(),
261
261
  grantedAt: n,
262
- expiry: n + Ge(t),
262
+ expiry: n + Ye(t),
263
263
  mac: ""
264
264
  };
265
265
  }
266
- function qe(e, t) {
267
- T(C), R();
268
- let n = Ke(e.noticeVersion, t);
269
- return D = n, O = !0, k = !0, M += 1, Be(n), n;
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 Je(e) {
271
+ async function Qe(e) {
272
272
  try {
273
- if (await B(), D !== e) return;
274
- let t = await Ie(e);
275
- if (D !== e) return;
273
+ if (await z(), O !== e) return;
274
+ let t = await Re(e);
275
+ if (O !== e) return;
276
276
  if (!t) {
277
- L(), k = !1;
277
+ I(), A = !1;
278
278
  return;
279
279
  }
280
280
  let n = {
281
281
  ...e,
282
282
  mac: t
283
283
  };
284
- D = n, O = !0, Be(n), k = !1;
284
+ O = n, k = !0, We(n), A = !1;
285
285
  } catch {
286
- D === e && (L(), k = !1);
286
+ O === e && (I(), A = !1);
287
287
  }
288
288
  }
289
- var Ye = () => {
290
- let e = We();
289
+ var $e = () => {
290
+ let e = Je();
291
291
  if (!e) {
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)");
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
- Je(qe(e));
296
- }, Xe = (e = 3) => {
297
- N = {
295
+ Qe(Ze(e));
296
+ }, et = (e = 3) => {
297
+ P = {
298
298
  noticeVersion: e,
299
299
  at: Date.now()
300
300
  };
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();
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
- D = null, O = !1;
311
+ O = null, k = !1;
312
312
  return;
313
313
  }
314
- if (!P()) return;
315
- if (!E) {
316
- A = null, await B();
314
+ if (!F()) return;
315
+ if (!D) {
316
+ j = null, await z();
317
317
  return;
318
318
  }
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;
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 || (M += 1, rt());
326
+ e.key !== null && e.key !== S && e.key !== C || (N += 1, at());
327
327
  });
328
328
  } catch {}
329
- var it = () => {
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
- B();
338
+ z();
339
339
  //#endregion
340
340
  //#region src/consent/ConsentUI.ts
341
- var V = "#6366f1", at = 1500, ot = 1500, st = 6e4, ct = 80, lt = 40, ut = [
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
- ], 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;
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 V;
351
- if (dt.test(t) || ft.test(t)) return t.toLowerCase();
352
- let n = pt.exec(t);
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})` : V;
355
+ return e <= 255 && t <= 255 && r <= 255 ? `rgb(${e}, ${t}, ${r})` : H;
356
356
  }
357
- let r = mt.exec(t);
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})` : V;
360
+ return e <= 255 && t <= 255 && n <= 255 && i >= 0 && i <= 1 ? `rgba(${e}, ${t}, ${n}, ${i})` : H;
361
361
  }
362
- return ht.get(t.toLowerCase()) ?? V;
362
+ return _t.get(t.toLowerCase()) ?? H;
363
363
  }
364
- function _t(e, t, n) {
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 vt(e) {
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 yt(e) {
378
+ function xt(e) {
379
379
  return {
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)
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 bt(e) {
390
- return typeof e != "number" || !Number.isFinite(e) ? at : Math.min(Math.max(Math.floor(e), ot), st);
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 xt(e, t) {
393
- return typeof t.minVisibleMs == "number" && Number.isFinite(t.minVisibleMs) ? Math.min(Math.max(Math.floor(t.minVisibleMs), 0), st) : e;
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 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 {
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 = yt(t), this.options = i ?? {}, this.root = e.attachShadow({ mode: "closed" }), this.render(n, r);
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 = St.replace(/__flaxia_accent__/g, i).replace("__flaxia_position__", `${c}: 20px; ${l}: 20px`);
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 ee = document.createElement("ul");
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, ee.appendChild(t);
414
+ t.textContent = e, m.appendChild(t);
415
415
  }
416
- if (d.append(f, p, ee), s) {
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 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;
422
+ let h = document.createElement("p");
423
+ h.className = "hint", h.textContent = x.acceptGateHint;
426
424
  let g = document.createElement("button");
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();
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
- h.addEventListener("click", () => {
436
- !b || _() < te || (Xe(3), re(e));
437
- }), g.addEventListener("click", () => {
435
+ g.addEventListener("click", () => {
436
+ !b || v() < te || (et(3), re(e));
437
+ }), _.addEventListener("click", () => {
438
438
  re(t);
439
- }), b || d.appendChild(m), d.append(h, g), this.root.append(u, d);
439
+ }), b || d.appendChild(h), d.append(g, _), this.root.append(u, d);
440
440
  }
441
- }, H = (...e) => console.log("[flaxia-node]", ...e), wt = class e {
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(e, t, n, r, i, a, o) {
458
- return new Promise((s, c) => {
460
+ run(t, n, r, i, a, o, s) {
461
+ return new Promise((c, l) => {
459
462
  if (!this.worker) {
460
- c(/* @__PURE__ */ Error("Worker not available"));
463
+ l(/* @__PURE__ */ Error("Worker not available"));
461
464
  return;
462
465
  }
463
- let l = () => this.execute(e, t, n, r, i, a, s, c, o);
464
- this.active ? (H(`task queued id=${e} workload=${t} (active task running)`), this.queue.push({
465
- id: e,
466
- job: l,
467
- reject: c
468
- })) : l();
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, r, i, a, o, c, l) {
472
- let u = this.worker;
473
- if (!u) {
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 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;
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
- }, h = (n) => {
485
- let { id: r, type: a, result: u, error: d, token: f, cpuLoad: h } = n.data;
486
- if (r === e) {
487
- if (ee(n.data.modelCache) && (this._modelCacheSnapshot = n.data.modelCache), a === "token") {
488
- i?.(f);
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 (a === "heartbeat") {
492
- typeof h == "number" && Number.isFinite(h) && (this._lastCpuLoad = Math.min(1, Math.max(0, h)), this._hasCpuLoadSample = !0);
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 (a === "swarm-frame") {
496
- l?.onFrame?.(n.data.frame);
506
+ if (o === "swarm-frame") {
507
+ u?.onFrame?.(n.data.frame);
497
508
  return;
498
509
  }
499
- if (a === "swarm-message") {
500
- l?.onMessage?.(n.data.message);
510
+ if (o === "swarm-message") {
511
+ u?.onMessage?.(n.data.message);
501
512
  return;
502
513
  }
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)}`)));
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
- }, 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);
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: o,
531
+ resolve: s,
516
532
  reject: c,
517
- timer: _,
518
- worker: u,
519
- removeListener: g
520
- }, u.addEventListener("message", h);
533
+ timer: y,
534
+ worker: f,
535
+ removeListener: ee
536
+ }, f.addEventListener("message", v);
521
537
  try {
522
- u.postMessage({
538
+ f.postMessage({
523
539
  id: e,
524
540
  workload: t,
525
541
  payload: n,
526
- timeoutMs: d,
527
- config: a
542
+ timeoutMs: p,
543
+ config: o
528
544
  }), this.flushControls();
529
545
  } catch (e) {
530
- m(() => c(e instanceof Error ? e : Error(String(e))));
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), H(`task aborted before start id=${e} reason=${t}`), r.reject(Error(t)), !0;
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
- }), H(`task abort sent id=${e} reason=${t}`), !0;
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
- H(`worker error error=${e.message}`);
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
- }, U = null, Tt = null;
624
- function W(e, t, n, r, i, a) {
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 G(e, t, n) {
635
- return W(null, e, "unknown", t, t + n, 0);
650
+ function K(e, t, n) {
651
+ return G(null, e, "unknown", t, t + n, 0);
636
652
  }
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;
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 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;
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: t,
662
+ sampledAt: n,
647
663
  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),
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 ? 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)
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 Ot = 15e3;
665
- function kt(e) {
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 K(e, t) {
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 At(e, t) {
675
- let n = kt(e);
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 jt(e, t, n, r, i) {
689
- let o = (e, n) => {
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 ? At([], t) : At(e[r] ?? [], i);
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 + a,
706
- webRtc: o(n, i?.webRtc),
707
- application: o(r, i?.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 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() {
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 Ut(e) {
722
- if (e.byteLength < J || e.byteLength > 16400) return null;
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) !== Ft) return null;
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 > 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 ? {
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, J)
749
+ payload: new Uint8Array(e, Y)
734
750
  } : null;
735
751
  }
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 = [];
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 * 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);
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 Gt = class {
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 = Ut(e);
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 >= It) return null;
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
- }, Kt = class {
801
+ }, Jt = class {
786
802
  constructor(e) {
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;
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: Vt }), n = {
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: Ht(),
809
- application: Ht()
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(Rt, { ordered: !0 }));
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 >= Lt) throw Error("too many ICE candidates before remote description");
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 Wt(e, r)) {
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 = Pt / 2, t.onopen = () => this.resolveReadyIfOpen(), t.onmessage = (t) => {
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")), Mt), i = (i) => {
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(), Ot));
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: zt,
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 > Bt) return;
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 !== zt || !Number.isSafeInteger(n.id) || n.id < 1) return;
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: zt,
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 = K(n.applicationBytesSent - n.lastApplicationBytesSent, e), i = K(n.applicationBytesReceived - n.lastApplicationBytesReceived, e);
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(jt(n.nodeId, e, n.quality.webRtc, n.quality.application, n.qualitySampledAt));
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 = K(d - e.lastRtcBytesSent, n);
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 = K(f - e.lastRtcBytesReceived, n);
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 qt(e, t) {
1084
- if (!_(e)) return !1;
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 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;
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 ?? Xt, Xt) : 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 Qt = "Xenova/m2m100_418M", $t = "translation", en = "q4f16", tn = "TeamFlaxia/plamo-3-translate-0.8b-onnx", nn = "text-generation", rn = "q4f16", an = class {
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 ?? "Xenova/m2m100_418M",
1105
- task: t.task ?? "translation",
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 = Zt({
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
- }, Y = (...e) => console.log("[flaxia-node]", ...e), X = (...e) => console.error("[flaxia-node]", ...e);
1153
- function Z(e) {
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 = y(n);
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", Q = "flaxia_node_token", sn = class {
1185
+ var on = "flaxia_node_id", sn = "flaxia_node_token", cn = class {
1163
1186
  receiveSwarmEnvelope(e) {
1164
- let t = i(e);
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 p(e.inboundKey, t.sessionId, t.frame, t.mac)) {
1170
- X(`swarm frame rejected: bad hop MAC sessionId=${t.sessionId}`);
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 Kt({
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 || !qt(e, {
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 (z() !== "granted") {
1260
+ if (R() !== "granted") {
1238
1261
  this.disconnect();
1239
1262
  return;
1240
1263
  }
1241
- if (Y(`connect nodeId=${this.nodeId}`), this.ws) {
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 t = await this.obtainToken();
1273
+ let e = await this.obtainToken();
1251
1274
  if (this.destroyed || this.suspended) return;
1252
- if (z() !== "granted") {
1253
- Y("connect cancelled because consent was revoked while obtaining a token");
1275
+ if (R() !== "granted") {
1276
+ X("connect cancelled because consent was revoked while obtaining a token");
1254
1277
  return;
1255
1278
  }
1256
- if (!t) {
1257
- X("token acquisition failed; scheduling reconnect"), this.scheduleReconnect();
1279
+ if (!e) {
1280
+ Z("token acquisition failed; scheduling reconnect"), this.scheduleReconnect();
1258
1281
  return;
1259
1282
  }
1260
1283
  this.startLightPreloader();
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;
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(r);
1302
+ this.sendHeartbeat(n);
1280
1303
  return;
1281
1304
  }
1282
1305
  if (t.type === "task") {
1283
1306
  let e = t;
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);
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
- Y(`task stopped on coordinator abort taskId=${e.taskId} error=${i}`);
1314
+ X(`task stopped on coordinator abort taskId=${e.taskId} error=${i}`);
1292
1315
  return;
1293
1316
  }
1294
- X(`task failed taskId=${e.taskId} workload=${e.workload} error=${i}`), this.send({
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
- }, 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()));
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), Y(`task abort received taskId=${t} error=${n}`);
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 || z() !== "granted") return;
1365
- let t = (this.config.capabilities ?? ["ai-inference", "image-process"]).includes("swarm-inference") && this.config.allowModelDownload === !0, n = navigator.deviceMemory, r = await Dt({
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 || z() !== "granted" || this.send({
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
- Y(`disconnect nodeId=${this.nodeId}`), this.destroyed = !0, this.suspended = !1, this.stopLightPreloader(), this.removeMobileLifecycleHandlers();
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[cn];
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 (Y("suspended (visibility or manual)"), this.suspended = !0, this.stopLightPreloader(), this.ws) {
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 || (Y("resumed"), this.suspended = !1, this.workerPool.resume(), this.connect());
1435
+ !this.suspended || this.destroyed || (X("resumed"), this.suspended = !1, this.workerPool.resume(), this.connect());
1413
1436
  }
1414
1437
  async obtainToken() {
1415
- let e = () => z() === "granted";
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 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"));
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 Dt({
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
- Y(`register capability probe capable=${n} wasmMemoryBytes=${t} capabilities=${JSON.stringify(i)} webgpu=${a?.webgpu ?? !1}`);
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: Z(this.config.fileSourceOrigins).length > 0,
1441
- wasmMemoryBytes: h(),
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 X(`node register failed HTTP ${s.status} (${o}/crowd/nodes/register)`), null;
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, Y(`node registered nodeId=${this.nodeId} expiresIn=${Math.round((c.expiresAt - Date.now()) / 1e3)}s`), c) : (X("node register returned no token"), null) : null;
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 X("node register threw", e instanceof Error ? e.message : e), null;
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
- X(`swarm frame not sent: no hop key sessionId=${e}`);
1488
+ Z(`swarm frame not sent: no hop key sessionId=${e}`);
1466
1489
  return;
1467
1490
  }
1468
- let i = await r(n.outboundKey, e, t), a = this.swarmPeerTransports.get(e);
1469
- (!a || !await a.sendFrame(i)) && this.sendBinary(i);
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 i = l(e, t), a = this.swarmPeerTransports.get(e);
1473
- (!a || !await a.sendFrame(i)) && this.sendBinary(i);
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
- }), Y(`swarm result sent taskId=${e} durationMs=${Math.round(performance.now() - r)}`);
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) ? Y(`swarm stopped on coordinator abort taskId=${e} error=${r}`) : (X(`swarm failed taskId=${e} error=${r}`), this.send({
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: Z(this.config.fileSourceOrigins),
1555
- containerImageOrigins: Z(this.config.containerImageOrigins),
1556
- ccRangeOrigins: Z(this.config.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
- }), Y(`task result sent taskId=${e.taskId} workload=${e.workload} durationMs=${Math.round(performance.now() - t)}`);
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(e, t) {
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");
1571
- let n = `local-${typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`}`;
1572
- return await this.workerPool.run(n, "ai-inference", e, 3e5, t, {
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: Z(this.config.fileSourceOrigins),
1575
- containerImageOrigins: Z(this.config.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(() => z(), {
1613
+ this.lightPreloader && this.lightPreloader.stop(), this.lightPreloader = new an(() => R(), {
1591
1614
  targets: [{
1592
- model: Qt,
1593
- task: $t,
1594
- dtype: en
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 Zt({
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", cn = "__flaxia_node_init_started", ln = "__flaxia_node_controller", un = (e) => {
1660
- if (z() !== "granted") {
1661
- X("refusing to start the node without a granted consent record");
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(), 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);
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
- }, dn = class {
1690
+ }, fn = class {
1671
1691
  constructor(e) {
1672
1692
  this.config = e;
1673
1693
  }
1674
1694
  start() {
1675
- this.isRunning() || !Ve() || un(this.config);
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[cn];
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 z();
1705
+ return R();
1686
1706
  }
1687
1707
  grant() {
1688
- Ye();
1708
+ $e();
1689
1709
  }
1690
1710
  deny() {
1691
- Qe(), this.stop(), nt(Q);
1711
+ B(), this.stop(), V(sn);
1692
1712
  }
1693
1713
  clearConsent() {
1694
- $e(), this.stop(), nt(Q);
1714
+ nt(), this.stop(), V(sn);
1695
1715
  }
1696
- async runLocalAiInference(e, t) {
1697
- let n = window[$];
1698
- if (!n || !this.isRunning()) throw new o("No running Crowd node on this device", "node_not_running");
1699
- return n.runLocalAiInference(e, t);
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(e) {
1706
- let t = window[$];
1707
- if (!t) throw new o("No running Crowd node on this device", "node_not_running");
1708
- await t.preloadAiModel(e);
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
- }, fn = (e) => {
1711
- let t = window[ln];
1730
+ }, pn = (e) => {
1731
+ let t = window[un];
1712
1732
  if (t) return t;
1713
- let n = new dn(e);
1714
- window[ln] = n, window[cn] = !0;
1715
- let r = z();
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
- Ye(), n.start();
1741
+ $e(), n.start();
1722
1742
  },
1723
1743
  reject: () => {
1724
- Qe();
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 Ct(i, e.consent, () => {
1729
- Ye(), i.remove(), n.start();
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
- Qe(), i.remove();
1751
+ B(), i.remove();
1732
1752
  }), n;
1733
1753
  };
1734
1754
  //#endregion
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 };
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 };