@flaxia/node 0.5.1 → 0.6.1

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.
@@ -1,15 +1,23 @@
1
1
  //#region ../sdk/dist/index.js
2
- var e = "flaxia-node-v1", t = "bearer.";
3
- function n(n) {
4
- return [e, `${t}${n}`];
2
+ var e = class extends Error {
3
+ constructor(e, t, n) {
4
+ super(e), this.message = e, this.code = t, this.status = n, this.name = "FlaxiaError";
5
+ }
6
+ }, t = class extends e {
7
+ constructor(e = "On-device model not available", t) {
8
+ super(t ? `${e}: ${t}` : e, "ONDEVICE_UNAVAILABLE", 500), t && (this.detail = t);
9
+ }
10
+ }, n = "flaxia-node-v1", r = "bearer.";
11
+ function i(e) {
12
+ return [n, `${r}${e}`];
5
13
  }
6
- function r(e, t, n = {}) {
14
+ function a(e, t, n = {}) {
7
15
  let r = e.replace(/\/+$/, "").replace(/^http/, "ws"), i = new URL(`${r}${t.startsWith("/") ? t : `/${t}`}`);
8
16
  for (let [e, t] of Object.entries(n)) t !== void 0 && i.searchParams.set(e, String(t));
9
17
  return i.toString();
10
18
  }
11
- var i = 6e4;
12
- function a(e, t) {
19
+ var o = 6e4;
20
+ function s(e, t) {
13
21
  if (t.length === 0) return [];
14
22
  if (!Number.isInteger(e) || e < 1) throw Error(`layers must be a positive integer, got ${e}`);
15
23
  let n = Math.min(t.length, e), r = t.slice(0, n).map((e) => Number.isFinite(e) && e > 0 ? e : 0), i = r.reduce((e, t) => e + t, 0) || 1, a = r.map((t) => Math.max(1, Math.floor(e * t / i))), o = a.reduce((e, t) => e + t, 0);
@@ -26,8 +34,8 @@ function a(e, t) {
26
34
  for (; o < e;) a[s[c % n].i]++, o++, c++;
27
35
  return a;
28
36
  }
29
- function o(e) {
30
- let t = a(e.layers, e.nodes.map((e) => e.capacity)), n = [], r = 0;
37
+ function c(e) {
38
+ let t = s(e.layers, e.nodes.map((e) => e.capacity)), n = [], r = 0;
31
39
  for (let i = 0; i < t.length; i++) {
32
40
  let a = r + t[i], o = i === 0 ? "host" : "worker", s = {
33
41
  start: r,
@@ -49,18 +57,18 @@ function o(e) {
49
57
  chain: n
50
58
  };
51
59
  }
52
- var s = 21335, c = 0, l = 1, u = 8 * 1024 * 1024;
53
- function d(e, t, n) {
60
+ var l = 21335, u = 0, d = 1, f = 8 * 1024 * 1024;
61
+ function p(e, t, n) {
54
62
  let r = new TextEncoder().encode(e);
55
63
  if (!r.length || r.length > 256) throw Error("swarm session id length is invalid");
56
64
  let i = n ?? new Uint8Array();
57
65
  if (i.byteLength !== 0 && i.byteLength !== 16) throw Error("swarm envelope MAC length is invalid");
58
66
  let a = 4 + r.length + 1 + i.byteLength;
59
- if (a + t.byteLength > 8388608) throw Error(`swarm envelope exceeds ${u} bytes`);
67
+ if (a + t.byteLength > 8388608) throw Error(`swarm envelope exceeds ${f} bytes`);
60
68
  let o = new ArrayBuffer(a + t.byteLength), s = new DataView(o);
61
69
  return s.setUint32(0, r.length, !0), new Uint8Array(o, 4, r.length).set(r), s.setUint8(4 + r.length, i.byteLength), i.byteLength && new Uint8Array(o, 4 + r.length + 1, i.byteLength).set(i), new Uint8Array(o, a).set(new Uint8Array(t)), o;
62
70
  }
63
- function f(e) {
71
+ function m(e) {
64
72
  if (e.byteLength < 5 || e.byteLength > 8388608) return null;
65
73
  let t = new DataView(e), n = t.getUint32(0, !0);
66
74
  if (!n || n > 256) return null;
@@ -75,39 +83,39 @@ function f(e) {
75
83
  frame: e.slice(a)
76
84
  };
77
85
  }
78
- async function p(e, t, n) {
86
+ async function h(e, t, n) {
79
87
  let r = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
80
88
  name: "HMAC",
81
89
  hash: "SHA-256"
82
- }, !1, ["sign"]), i = await crypto.subtle.sign("HMAC", r, d(t, n));
90
+ }, !1, ["sign"]), i = await crypto.subtle.sign("HMAC", r, p(t, n));
83
91
  return new Uint8Array(i).slice(0, 16);
84
92
  }
85
- async function m(e, t, n) {
86
- return d(t, n, await p(e, t, n));
93
+ async function ee(e, t, n) {
94
+ return p(t, n, await h(e, t, n));
87
95
  }
88
- async function ee(e, t, n, r) {
96
+ async function g(e, t, n, r) {
89
97
  if (r.byteLength !== 16) return !1;
90
- let i = await p(e, t, n), a = 0;
98
+ let i = await h(e, t, n), a = 0;
91
99
  for (let e = 0; e < i.byteLength; e++) a |= i[e] ^ r[e];
92
100
  return a === 0;
93
101
  }
94
- function h(e, t) {
102
+ function _(e, t) {
95
103
  let n = new ArrayBuffer(16 + t.byteLength), r = new DataView(n);
96
- return r.setUint16(0, s, !0), r.setUint8(2, c), r.setUint8(3, 0), r.setUint32(4, e.requestId >>> 0, !0), r.setUint32(8, e.pos >>> 0, !0), r.setUint16(12, e.tokens, !0), r.setUint16(14, 0, !0), new Uint8Array(n, 16).set(t), n;
104
+ return r.setUint16(0, l, !0), r.setUint8(2, u), r.setUint8(3, 0), r.setUint32(4, e.requestId >>> 0, !0), r.setUint32(8, e.pos >>> 0, !0), r.setUint16(12, e.tokens, !0), r.setUint16(14, 0, !0), new Uint8Array(n, 16).set(t), n;
97
105
  }
98
- function g(e = 0) {
106
+ function te(e = 0) {
99
107
  let t = /* @__PURE__ */ new ArrayBuffer(16), n = new DataView(t);
100
- return n.setUint16(0, s, !0), n.setUint8(2, l), n.setUint8(3, 0), n.setUint32(4, e >>> 0, !0), t;
108
+ return n.setUint16(0, l, !0), n.setUint8(2, d), n.setUint8(3, 0), n.setUint32(4, e >>> 0, !0), t;
101
109
  }
102
- function te(e) {
110
+ function v(e) {
103
111
  if (e.byteLength !== 16) return !1;
104
112
  let t = new DataView(e);
105
- return t.getUint16(0, !0) === 21335 && t.getUint8(2) === l && t.getUint8(3) === 0 && t.getUint32(8, !0) === 0 && t.getUint16(12, !0) === 0 && t.getUint16(14, !0) === 0;
113
+ return t.getUint16(0, !0) === 21335 && t.getUint8(2) === d && t.getUint8(3) === 0 && t.getUint32(8, !0) === 0 && t.getUint16(12, !0) === 0 && t.getUint16(14, !0) === 0;
106
114
  }
107
115
  function ne(e) {
108
116
  if (e.byteLength < 16) return null;
109
117
  let t = new DataView(e);
110
- return t.getUint16(0, !0) !== 21335 || t.getUint8(2) !== c ? null : {
118
+ return t.getUint16(0, !0) !== 21335 || t.getUint8(2) !== u ? null : {
111
119
  header: {
112
120
  requestId: t.getUint32(4, !0),
113
121
  pos: t.getUint32(8, !0),
@@ -116,20 +124,20 @@ function ne(e) {
116
124
  payload: new Uint8Array(e, 16)
117
125
  };
118
126
  }
119
- function _(e) {
120
- if (!y(e)) return !1;
127
+ function re(e) {
128
+ if (!b(e)) return !1;
121
129
  if (e.kind === "description") {
122
130
  let t = e.description;
123
- return y(t) && (t.type === "offer" || t.type === "answer") && typeof t.sdp == "string" && t.sdp.length > 0 && t.sdp.length <= 24576;
131
+ return b(t) && (t.type === "offer" || t.type === "answer") && typeof t.sdp == "string" && t.sdp.length > 0 && t.sdp.length <= 24576;
124
132
  }
125
133
  if (e.kind === "candidate") {
126
134
  let t = e.candidate;
127
- return t === null ? !0 : y(t) && typeof t.candidate == "string" && t.candidate.length > 0 && t.candidate.length <= 4096 && (t.sdpMid === void 0 || t.sdpMid === null || typeof t.sdpMid == "string" && t.sdpMid.length <= 128) && (t.sdpMLineIndex === void 0 || t.sdpMLineIndex === null || typeof t.sdpMLineIndex == "number" && Number.isInteger(t.sdpMLineIndex) && t.sdpMLineIndex >= 0 && t.sdpMLineIndex <= 255) && (t.usernameFragment === void 0 || t.usernameFragment === null || typeof t.usernameFragment == "string" && t.usernameFragment.length <= 256);
135
+ return t === null ? !0 : b(t) && typeof t.candidate == "string" && t.candidate.length > 0 && t.candidate.length <= 4096 && (t.sdpMid === void 0 || t.sdpMid === null || typeof t.sdpMid == "string" && t.sdpMid.length <= 128) && (t.sdpMLineIndex === void 0 || t.sdpMLineIndex === null || typeof t.sdpMLineIndex == "number" && Number.isInteger(t.sdpMLineIndex) && t.sdpMLineIndex >= 0 && t.sdpMLineIndex <= 255) && (t.usernameFragment === void 0 || t.usernameFragment === null || typeof t.usernameFragment == "string" && t.usernameFragment.length <= 256);
128
136
  }
129
137
  return !1;
130
138
  }
131
- function v(e) {
132
- if (!y(e) || e.type !== "swarm-peer-signal" || !_(e.signal)) return !1;
139
+ function y(e) {
140
+ if (!b(e) || e.type !== "swarm-peer-signal" || !re(e.signal)) return !1;
133
141
  try {
134
142
  if (new TextEncoder().encode(JSON.stringify(e.signal)).byteLength > 32768) return !1;
135
143
  } catch {
@@ -137,49 +145,49 @@ function v(e) {
137
145
  }
138
146
  return typeof e.taskId == "string" && e.taskId.length > 0 && e.taskId.length <= 128 && typeof e.sessionId == "string" && e.sessionId.length > 0 && e.sessionId.length <= 128 && typeof e.attemptId == "string" && e.attemptId.length > 0 && e.attemptId.length <= 128 && typeof e.toNodeId == "string" && e.toNodeId.length > 0 && e.toNodeId.length <= 128 && (e.fromNodeId === void 0 || typeof e.fromNodeId == "string" && e.fromNodeId.length > 0 && e.fromNodeId.length <= 128);
139
147
  }
140
- function y(e) {
148
+ function b(e) {
141
149
  return typeof e == "object" && !!e;
142
150
  }
143
- function b(e) {
151
+ function x(e) {
144
152
  return typeof e == "number" && Number.isInteger(e) && e >= 0;
145
153
  }
146
- function x(e, t = {}) {
154
+ function S(e, t = {}) {
147
155
  let n = t.maxLayers ?? 1024, r = t.maxSliceLayers ?? 256;
148
- return !(!S(e) || !b(e.start) || !b(e.end) || e.end <= e.start || e.end - e.start > r || e.end > n);
149
- }
150
- function S(e) {
151
- return y(e) ? typeof e.start == "number" && typeof e.end == "number" && typeof e.hasEmbed == "boolean" && typeof e.hasHead == "boolean" : !1;
156
+ return !(!C(e) || !x(e.start) || !x(e.end) || e.end <= e.start || e.end - e.start > r || e.end > n);
152
157
  }
153
158
  function C(e) {
154
- return y(e) ? typeof e.nodeId == "string" && e.nodeId.length > 0 && typeof e.capacity == "number" : !1;
159
+ return b(e) ? typeof e.start == "number" && typeof e.end == "number" && typeof e.hasEmbed == "boolean" && typeof e.hasHead == "boolean" : !1;
160
+ }
161
+ function ie(e) {
162
+ return b(e) ? typeof e.nodeId == "string" && e.nodeId.length > 0 && typeof e.capacity == "number" : !1;
155
163
  }
156
164
  function w(e) {
157
165
  return e === void 0 || typeof e == "string" && e.length > 0 && e.length <= 128;
158
166
  }
159
- function re(e) {
160
- return !y(e) || e.type !== "swarm-init" || typeof e.sessionId != "string" || !e.sessionId || typeof e.taskId != "string" || !e.taskId || typeof e.model != "string" || typeof e.timeoutMs != "number" || !Array.isArray(e.members) || e.members.length === 0 || e.members.length > 16 || typeof e.prompt != "string" && !Array.isArray(e.prompt) ? !1 : e.members.every(C);
161
- }
162
- function ie(e) {
163
- return !(!y(e) || e.type !== "swarm-slice" || typeof e.sessionId != "string" || !e.sessionId || typeof e.taskId != "string" || !e.taskId || typeof e.model != "string" || !e.model || typeof e.timeoutMs != "number" || !b(e.index) || !b(e.chainLength) || e.chainLength < 1 || e.chainLength > 16 || e.index >= e.chainLength || e.role !== (e.index === 0 ? "host" : "worker") || !x(e.slice) || e.slice.hasEmbed !== (e.index === 0) || e.slice.hasHead !== (e.index === 0) || !w(e.inboundKey) || !w(e.outboundKey) || e.attemptId !== void 0 && (typeof e.attemptId != "string" || !e.attemptId || e.attemptId.length > 128) || e.previousNodeId !== void 0 && (typeof e.previousNodeId != "string" || !e.previousNodeId || e.previousNodeId.length > 128) || e.nextNodeId !== void 0 && (typeof e.nextNodeId != "string" || !e.nextNodeId || e.nextNodeId.length > 128));
164
- }
165
167
  function ae(e) {
166
- return !y(e) || e.type !== "swarm-start" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId;
168
+ return !b(e) || e.type !== "swarm-init" || typeof e.sessionId != "string" || !e.sessionId || typeof e.taskId != "string" || !e.taskId || typeof e.model != "string" || typeof e.timeoutMs != "number" || !Array.isArray(e.members) || e.members.length === 0 || e.members.length > 16 || typeof e.prompt != "string" && !Array.isArray(e.prompt) ? !1 : e.members.every(ie);
167
169
  }
168
170
  function oe(e) {
169
- return !y(e) || e.type !== "swarm-transport" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId && (e.mode === "peer" || e.mode === "relay");
171
+ return !(!b(e) || e.type !== "swarm-slice" || typeof e.sessionId != "string" || !e.sessionId || typeof e.taskId != "string" || !e.taskId || typeof e.model != "string" || !e.model || typeof e.timeoutMs != "number" || !x(e.index) || !x(e.chainLength) || e.chainLength < 1 || e.chainLength > 16 || e.index >= e.chainLength || e.role !== (e.index === 0 ? "host" : "worker") || !S(e.slice) || e.slice.hasEmbed !== (e.index === 0) || e.slice.hasHead !== (e.index === 0) || !w(e.inboundKey) || !w(e.outboundKey) || e.attemptId !== void 0 && (typeof e.attemptId != "string" || !e.attemptId || e.attemptId.length > 128) || e.previousNodeId !== void 0 && (typeof e.previousNodeId != "string" || !e.previousNodeId || e.previousNodeId.length > 128) || e.nextNodeId !== void 0 && (typeof e.nextNodeId != "string" || !e.nextNodeId || e.nextNodeId.length > 128));
170
172
  }
171
173
  function T(e) {
172
- return !y(e) || e.type !== "swarm-flow" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId && typeof e.paused == "boolean" && (e.attemptId === void 0 || typeof e.attemptId == "string" && !!e.attemptId && e.attemptId.length <= 128);
174
+ return !b(e) || e.type !== "swarm-start" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId;
173
175
  }
174
176
  function E(e) {
175
- return !y(e) || e.type !== "swarm-error" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId && typeof e.error == "string";
177
+ return !b(e) || e.type !== "swarm-transport" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId && (e.mode === "peer" || e.mode === "relay");
178
+ }
179
+ function D(e) {
180
+ return !b(e) || e.type !== "swarm-flow" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId && typeof e.paused == "boolean" && (e.attemptId === void 0 || typeof e.attemptId == "string" && !!e.attemptId && e.attemptId.length <= 128);
181
+ }
182
+ function O(e) {
183
+ return !b(e) || e.type !== "swarm-error" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId && typeof e.error == "string";
176
184
  }
177
185
  new Set([
178
186
  "qwen3.5-2b",
179
187
  "qwen3.8-27b",
180
188
  "qwen3.6-35b-moe"
181
189
  ]);
182
- var D = new Set([
190
+ var k = new Set([
183
191
  "ai-inference",
184
192
  "image-process",
185
193
  "container",
@@ -187,75 +195,75 @@ var D = new Set([
187
195
  "vector-query",
188
196
  "nudenet",
189
197
  "swarm-inference"
190
- ]), O = 9e4, k = 600 * 1e3, A = 1440 * 60 * 1e3, j = 6e4;
191
- function M(e) {
198
+ ]), A = 9e4, j = 600 * 1e3, M = 1440 * 60 * 1e3, N = 6e4;
199
+ function P(e) {
192
200
  return typeof e == "object" && !!e && !Array.isArray(e);
193
201
  }
194
- function N(e) {
195
- if (!M(e) || typeof e.modelId != "string" || !e.modelId || e.modelId.length > 128 || typeof e.revision != "string" || !e.revision || e.revision.length > 128 || typeof e.dtype != "string" || !e.dtype || e.dtype.length > 32 || e.backend !== "wasm" && e.backend !== "cpu" && e.backend !== "webgpu" || e.state !== "loading" && e.state !== "ready" && e.state !== "evicting" && e.state !== "failed" || !Number.isInteger(e.referenceCount) || e.referenceCount < 0 || e.referenceCount > 64) return !1;
202
+ function F(e) {
203
+ if (!P(e) || typeof e.modelId != "string" || !e.modelId || e.modelId.length > 128 || typeof e.revision != "string" || !e.revision || e.revision.length > 128 || typeof e.dtype != "string" || !e.dtype || e.dtype.length > 32 || e.backend !== "wasm" && e.backend !== "cpu" && e.backend !== "webgpu" || e.state !== "loading" && e.state !== "ready" && e.state !== "evicting" && e.state !== "failed" || !Number.isInteger(e.referenceCount) || e.referenceCount < 0 || e.referenceCount > 64) return !1;
196
204
  if (e.layerRange === void 0) return !0;
197
205
  let t = e.layerRange;
198
206
  return Array.isArray(t) && t.length === 2 && Number.isInteger(t[0]) && Number.isInteger(t[1]) && t[0] >= 0 && t[1] > t[0] && t[1] <= 1024;
199
207
  }
200
- function P(e, t = Date.now()) {
201
- if (!M(e) || e.version !== 1 || !Number.isSafeInteger(e.sampledAt) || !Number.isSafeInteger(e.expiresAt) || !Array.isArray(e.entries) || e.entries.length > 8 || !e.entries.every(N)) return !1;
208
+ function I(e, t = Date.now()) {
209
+ if (!P(e) || e.version !== 1 || !Number.isSafeInteger(e.sampledAt) || !Number.isSafeInteger(e.expiresAt) || !Array.isArray(e.entries) || e.entries.length > 8 || !e.entries.every(F)) return !1;
202
210
  let n = e.sampledAt, r = e.expiresAt;
203
211
  return n <= t + 5e3 && n >= t - 6e4 && r > t && r > n && r - n <= 6e4;
204
212
  }
205
213
  //#endregion
206
214
  //#region src/executor/memoryProbe.ts
207
- var F = 2 * 1024 ** 3, I = 65536, L = 16 * 1024 * 1024, R = 4096, z = null, B = 0;
208
- function V(e, t) {
209
- let n = Math.ceil(t / I);
215
+ var L = 2 * 1024 ** 3, R = 65536, z = 16 * 1024 * 1024, B = 4096, V = null, H = 0;
216
+ function U(e, t) {
217
+ let n = Math.ceil(t / R);
210
218
  try {
211
219
  e.grow(n);
212
220
  } catch {
213
221
  return !1;
214
222
  }
215
223
  let r = new Uint8Array(e.buffer);
216
- for (let e = 0; e < n; e++) r[e * I] = 0;
224
+ for (let e = 0; e < n; e++) r[e * R] = 0;
217
225
  return !0;
218
226
  }
219
- function H(e = F, t = L) {
220
- if (z) return z.bytes;
221
- B++;
227
+ function W(e = L, t = z) {
228
+ if (V) return V.bytes;
229
+ H++;
222
230
  let n = Date.now(), r;
223
231
  try {
224
232
  r = new WebAssembly.Memory({ initial: 0 });
225
233
  } catch {
226
- return z = {
234
+ return V = {
227
235
  bytes: 0,
228
236
  sampledAt: n,
229
237
  measured: !1
230
238
  }, 0;
231
239
  }
232
- let i = Math.max(0, Math.floor(e)), a = Math.max(I, Math.floor(t)), o = 0, s = 0;
233
- for (; o < i && s < R;) {
240
+ let i = Math.max(0, Math.floor(e)), a = Math.max(R, Math.floor(t)), o = 0, s = 0;
241
+ for (; o < i && s < B;) {
234
242
  let e = Math.min(a, i - o);
235
- if (!V(r, e)) break;
243
+ if (!U(r, e)) break;
236
244
  o += e, s++;
237
245
  }
238
- return r = void 0, z = {
246
+ return r = void 0, V = {
239
247
  bytes: o,
240
248
  sampledAt: n,
241
249
  measured: !0
242
250
  }, o;
243
251
  }
244
- function U() {
245
- return z ? z.bytes : H();
252
+ function G() {
253
+ return V ? V.bytes : W();
246
254
  }
247
- function W() {
248
- return z || H(), {
249
- bytes: z?.measured ? z.bytes : null,
250
- sampledAt: z?.sampledAt ?? null
255
+ function K() {
256
+ return V || W(), {
257
+ bytes: V?.measured ? V.bytes : null,
258
+ sampledAt: V?.sampledAt ?? null
251
259
  };
252
260
  }
253
- function G() {
254
- return U() >= F;
261
+ function q() {
262
+ return G() >= L;
255
263
  }
256
264
  //#endregion
257
265
  //#region src/executor/webgpuProbe.ts
258
- var K = 3, q = 750, J = 1500, Y = 600 * 1e3;
266
+ var se = 3, ce = 750, J = 1500, Y = 600 * 1e3;
259
267
  async function X(e, t) {
260
268
  let n, r = new Promise((e) => {
261
269
  n = setTimeout(() => e({
@@ -287,9 +295,9 @@ function Z(e, t = Date.now()) {
287
295
  function Q() {
288
296
  return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
289
297
  }
290
- async function se(e) {
298
+ async function le(e) {
291
299
  let t, n = new Promise((e) => {
292
- t = setTimeout(() => e("timeout"), q);
300
+ t = setTimeout(() => e("timeout"), ce);
293
301
  }), r = e.queue.onSubmittedWorkDone().then(() => "complete"), i = e.lost.then(() => "lost", () => "lost");
294
302
  try {
295
303
  return await Promise.race([
@@ -320,12 +328,12 @@ async function $() {
320
328
  entryPoint: "main"
321
329
  }
322
330
  }), f = [];
323
- for (let e = 0; e < K; e++) {
331
+ for (let e = 0; e < se; e++) {
324
332
  let e = u.createCommandEncoder(), t = e.beginComputePass();
325
333
  t.setPipeline(d), t.dispatchWorkgroups(1), t.end();
326
334
  let n = e.finish(), r = Q();
327
335
  u.queue.submit([n]);
328
- let i = await se(u);
336
+ let i = await le(u);
329
337
  if (i === "lost") return Z("device-lost", Date.now());
330
338
  if (i === "timeout") return Z("unavailable", Date.now());
331
339
  f.push(Math.max(0, Q() - r));
@@ -350,8 +358,8 @@ async function $() {
350
358
  } catch {}
351
359
  }
352
360
  }
353
- async function ce() {
361
+ async function ue() {
354
362
  return (await $()).capabilities;
355
363
  }
356
364
  //#endregion
357
- export { f as A, i as C, O as D, m as E, g as M, te as N, E as O, r as S, ee as T, A as _, G as a, n as b, T as c, d, re as f, u as g, ae as h, W as i, j, oe as k, D as l, x as m, $ as n, H as o, k as p, F as r, v as s, ce as t, ie as u, h as v, P as w, o as x, ne as y };
365
+ export { i as A, a as C, y as D, t as E, v as F, I as M, o as N, O, te as P, e as S, ee as T, _, q as a, c as b, p as c, ae as d, j as f, M as g, k as h, K as i, m as j, E as k, oe as l, S as m, $ as n, W as o, T as p, L as r, D as s, ue as t, f as u, A as v, g as w, N as x, ne as y };
@@ -1 +1 @@
1
- {"version":3,"file":"SignalingClient.d.ts","sourceRoot":"","sources":["../../src/client/SignalingClient.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAgB,oBAAoB,EAAE,UAAU,EAAyB,YAAY,EAAE,MAAM,aAAa,CAAC;AAmBvH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA81BD,eAAO,MAAM,cAAc,GAAI,QAAQ,UAAU,KAAG,oBAwDnD,CAAC"}
1
+ {"version":3,"file":"SignalingClient.d.ts","sourceRoot":"","sources":["../../src/client/SignalingClient.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAgB,oBAAoB,EAAE,UAAU,EAAyB,YAAY,EAAE,MAAM,aAAa,CAAC;AAqBvH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA88BD,eAAO,MAAM,cAAc,GAAI,QAAQ,UAAU,KAAG,oBAwDnD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=light-preloader.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light-preloader.test.d.ts","sourceRoot":"","sources":["../../../src/client/__tests__/light-preloader.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
1
+ export interface LightPreloaderTarget {
2
+ model: string;
3
+ task: string;
4
+ dtype: string;
5
+ }
6
+ export interface LightPreloaderOptions {
7
+ /** Model id to keep warm. Defaults to the M2M100 translate model. */
8
+ model?: string;
9
+ task?: string;
10
+ dtype?: string;
11
+ /** Full list of models to keep warm; wins over `model`/`task`/`dtype`. */
12
+ targets?: LightPreloaderTarget[];
13
+ onPreloaded?: () => void;
14
+ }
15
+ export type PreloadFn = (request: {
16
+ task: string;
17
+ model: string;
18
+ dtype: string;
19
+ }) => Promise<void>;
20
+ export type IsPreloadedFn = (model: string) => boolean;
21
+ /** Defaults mirror `LIGHT_INFERENCE_TRANSLATE_*` in `ai-inference.ts`. */
22
+ export declare const LIGHT_INFERENCE_TRANSLATE_MODEL = "Xenova/m2m100_418M";
23
+ export declare const LIGHT_INFERENCE_TRANSLATE_TASK = "translation";
24
+ export declare const LIGHT_INFERENCE_TRANSLATE_DTYPE = "q4f16";
25
+ /** Flaxia's default translate model, mirroring `LIGHT_INFERENCE_PLAMO_*`. */
26
+ export declare const LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL = "TeamFlaxia/plamo-3-translate-0.8b-onnx";
27
+ export declare const LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK = "text-generation";
28
+ export declare const LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE = "q4f16";
29
+ /**
30
+ * Light Inference idle preloader.
31
+ *
32
+ * Keeps the translate `ai-inference` models resident so a later `ondeviceOnly`
33
+ * task can serve instantly from this device. Runs only while the device is
34
+ * online and unconstrained (no low battery / Save-Data / slow-2g). Consent
35
+ * is Crowd's consent: when consent is anything other than `granted` the
36
+ * preloader never runs.
37
+ */
38
+ export declare class LightPreloader {
39
+ private readonly getConsentState;
40
+ private readonly options;
41
+ private readonly isPreloaded;
42
+ private readonly preload;
43
+ private timer;
44
+ private idleHandle;
45
+ private preloading;
46
+ private stopped;
47
+ private readonly targets;
48
+ constructor(getConsentState: () => string, options?: LightPreloaderOptions, isPreloaded?: IsPreloadedFn, preload?: PreloadFn);
49
+ /** Schedule a preload at the next idle moment (no-op when already ready). */
50
+ start(): void;
51
+ /** Cancel any scheduled preload (e.g. on suspend / consent denial). */
52
+ stop(): void;
53
+ private isUnconstrained;
54
+ private preloadNow;
55
+ }
56
+ //# sourceMappingURL=light-preloader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light-preloader.d.ts","sourceRoot":"","sources":["../../src/client/light-preloader.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,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kBAAkB,IAAI,sBAAsB,GAAG,IAAI,CAItD;CACF"}
package/dist/index.d.ts CHANGED
@@ -3,5 +3,7 @@ export { getConsentState as getFlaxiaNodeConsentState } from './consent/storage'
3
3
  export { initConsentIntegrity as initFlaxiaNodeConsent } from './consent/storage';
4
4
  export { setHostManagedConsentAllowed as setFlaxiaNodeHostManagedConsent } from './consent/storage';
5
5
  export { initFlaxiaNode };
6
+ export { LIGHT_INFERENCE_TRANSLATE_MODEL, LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL, LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK, LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE, } from './client/light-preloader';
7
+ export { isAiModelPreloaded, preloadAiModel, LIGHT_INFERENCE_TRANSLATE_MODEL as LIGHT_INFERENCE_TRANSLATE_MODEL_ID, LIGHT_INFERENCE_TRANSLATE_TASK, LIGHT_INFERENCE_TRANSLATE_DTYPE, LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL as LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL_ID, LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK as LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK_ID, LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE as LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE_ID, } from './workloads/ai-inference';
6
8
  export type { ConsentControls, ConsentState, FlaxiaNodeController } from '@flaxia/sdk';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAO1D,OAAO,EAAE,eAAe,IAAI,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAE,oBAAoB,IAAI,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAIlF,OAAO,EAAE,4BAA4B,IAAI,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAO1D,OAAO,EAAE,eAAe,IAAI,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAE,oBAAoB,IAAI,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAIlF,OAAO,EAAE,4BAA4B,IAAI,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,OAAO,EACL,+BAA+B,EAC/B,qCAAqC,EACrC,oCAAoC,EACpC,qCAAqC,GACtC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,+BAA+B,IAAI,kCAAkC,EACrE,8BAA8B,EAC9B,+BAA+B,EAC/B,qCAAqC,IAAI,wCAAwC,EACjF,oCAAoC,IAAI,uCAAuC,EAC/E,qCAAqC,IAAI,wCAAwC,GAClF,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}