@flaxia/node 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/ai-inference.js +129 -83
- package/dist/assets/transformers.web.js +2 -2
- package/dist/assets/vector-embed.js +1 -1
- package/dist/assets/webgpuProbe.js +91 -83
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/__tests__/light-preloader.test.d.ts +2 -0
- package/dist/client/__tests__/light-preloader.test.d.ts.map +1 -0
- package/dist/client/light-preloader.d.ts +47 -0
- package/dist/client/light-preloader.d.ts.map +1 -0
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +443 -356
- package/dist/worker.js +177 -168
- package/dist/workloads/ai-inference.d.ts +21 -0
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/ai-model-registry.d.ts +6 -0
- package/dist/workloads/ai-model-registry.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
//#region ../sdk/dist/index.js
|
|
2
|
-
var e =
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
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
|
|
12
|
-
function
|
|
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
|
|
30
|
-
let t =
|
|
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
|
|
53
|
-
function
|
|
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 ${
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
86
|
-
return
|
|
93
|
+
async function ee(e, t, n) {
|
|
94
|
+
return p(t, n, await h(e, t, n));
|
|
87
95
|
}
|
|
88
|
-
async function
|
|
96
|
+
async function g(e, t, n, r) {
|
|
89
97
|
if (r.byteLength !== 16) return !1;
|
|
90
|
-
let i = await
|
|
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
|
|
102
|
+
function _(e, t) {
|
|
95
103
|
let n = new ArrayBuffer(16 + t.byteLength), r = new DataView(n);
|
|
96
|
-
return r.setUint16(0,
|
|
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
|
|
106
|
+
function te(e = 0) {
|
|
99
107
|
let t = /* @__PURE__ */ new ArrayBuffer(16), n = new DataView(t);
|
|
100
|
-
return n.setUint16(0,
|
|
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
|
|
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) ===
|
|
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) !==
|
|
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
|
|
120
|
-
if (!
|
|
127
|
+
function re(e) {
|
|
128
|
+
if (!b(e)) return !1;
|
|
121
129
|
if (e.kind === "description") {
|
|
122
130
|
let t = e.description;
|
|
123
|
-
return
|
|
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 :
|
|
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
|
|
132
|
-
if (!
|
|
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
|
|
148
|
+
function b(e) {
|
|
141
149
|
return typeof e == "object" && !!e;
|
|
142
150
|
}
|
|
143
|
-
function
|
|
151
|
+
function x(e) {
|
|
144
152
|
return typeof e == "number" && Number.isInteger(e) && e >= 0;
|
|
145
153
|
}
|
|
146
|
-
function
|
|
154
|
+
function S(e, t = {}) {
|
|
147
155
|
let n = t.maxLayers ?? 1024, r = t.maxSliceLayers ?? 256;
|
|
148
|
-
return !(!
|
|
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
|
|
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 !
|
|
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 !
|
|
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 !
|
|
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 !
|
|
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
|
|
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
|
-
]),
|
|
191
|
-
function
|
|
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
|
|
195
|
-
if (!
|
|
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
|
|
201
|
-
if (!
|
|
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
|
|
208
|
-
function
|
|
209
|
-
let n = Math.ceil(t /
|
|
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 *
|
|
224
|
+
for (let e = 0; e < n; e++) r[e * R] = 0;
|
|
217
225
|
return !0;
|
|
218
226
|
}
|
|
219
|
-
function
|
|
220
|
-
if (
|
|
221
|
-
|
|
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
|
|
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(
|
|
233
|
-
for (; o < i && s <
|
|
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 (!
|
|
243
|
+
if (!U(r, e)) break;
|
|
236
244
|
o += e, s++;
|
|
237
245
|
}
|
|
238
|
-
return r = void 0,
|
|
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
|
|
245
|
-
return
|
|
252
|
+
function G() {
|
|
253
|
+
return V ? V.bytes : W();
|
|
246
254
|
}
|
|
247
|
-
function
|
|
248
|
-
return
|
|
249
|
-
bytes:
|
|
250
|
-
sampledAt:
|
|
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
|
|
254
|
-
return
|
|
261
|
+
function q() {
|
|
262
|
+
return G() >= L;
|
|
255
263
|
}
|
|
256
264
|
//#endregion
|
|
257
265
|
//#region src/executor/webgpuProbe.ts
|
|
258
|
-
var
|
|
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
|
|
298
|
+
async function le(e) {
|
|
291
299
|
let t, n = new Promise((e) => {
|
|
292
|
-
t = setTimeout(() => e("timeout"),
|
|
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 <
|
|
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
|
|
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
|
|
361
|
+
async function ue() {
|
|
354
362
|
return (await $()).capabilities;
|
|
355
363
|
}
|
|
356
364
|
//#endregion
|
|
357
|
-
export {
|
|
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":"
|
|
1
|
+
{"version":3,"file":"SignalingClient.d.ts","sourceRoot":"","sources":["../../src/client/SignalingClient.ts"],"names":[],"mappings":"AA4BA,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;AAg8BD,eAAO,MAAM,cAAc,GAAI,QAAQ,UAAU,KAAG,oBAwDnD,CAAC"}
|
|
@@ -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,47 @@
|
|
|
1
|
+
export interface LightPreloaderOptions {
|
|
2
|
+
/** Model id to keep warm. Defaults to the M2M100 translate model. */
|
|
3
|
+
model?: string;
|
|
4
|
+
task?: string;
|
|
5
|
+
dtype?: string;
|
|
6
|
+
onPreloaded?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export type PreloadFn = (request: {
|
|
9
|
+
task: string;
|
|
10
|
+
model: string;
|
|
11
|
+
dtype: string;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
export type IsPreloadedFn = (model: string) => boolean;
|
|
14
|
+
/** Defaults mirror `LIGHT_INFERENCE_TRANSLATE_*` in `ai-inference.ts`. */
|
|
15
|
+
export declare const LIGHT_INFERENCE_TRANSLATE_MODEL = "Xenova/m2m100_418M";
|
|
16
|
+
export declare const LIGHT_INFERENCE_TRANSLATE_TASK = "translation";
|
|
17
|
+
export declare const LIGHT_INFERENCE_TRANSLATE_DTYPE = "q4f16";
|
|
18
|
+
/**
|
|
19
|
+
* Light Inference idle preloader.
|
|
20
|
+
*
|
|
21
|
+
* Keeps one small `ai-inference` model resident so a later `ondeviceOnly`
|
|
22
|
+
* task can serve instantly from this device. Runs only while the device is
|
|
23
|
+
* online and unconstrained (no low battery / Save-Data / slow-2g). Consent
|
|
24
|
+
* is Crowd's consent: when consent is anything other than `granted` the
|
|
25
|
+
* preloader never runs.
|
|
26
|
+
*/
|
|
27
|
+
export declare class LightPreloader {
|
|
28
|
+
private readonly getConsentState;
|
|
29
|
+
private readonly options;
|
|
30
|
+
private readonly isPreloaded;
|
|
31
|
+
private readonly preload;
|
|
32
|
+
private timer;
|
|
33
|
+
private idleHandle;
|
|
34
|
+
private preloading;
|
|
35
|
+
private stopped;
|
|
36
|
+
private readonly model;
|
|
37
|
+
private readonly task;
|
|
38
|
+
private readonly dtype;
|
|
39
|
+
constructor(getConsentState: () => string, options?: LightPreloaderOptions, isPreloaded?: IsPreloadedFn, preload?: PreloadFn);
|
|
40
|
+
/** Schedule a preload at the next idle moment (no-op when already ready). */
|
|
41
|
+
start(): void;
|
|
42
|
+
/** Cancel any scheduled preload (e.g. on suspend / consent denial). */
|
|
43
|
+
stop(): void;
|
|
44
|
+
private isUnconstrained;
|
|
45
|
+
private preloadNow;
|
|
46
|
+
}
|
|
47
|
+
//# 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,qBAAqB;IACpC,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED,MAAM,MAAM,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AAO;IAwGf,+EAA+E;IAC/E,OAAO,CAAC,aAAa;IAOrB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAUpB;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO;IAW5D,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAItC,mEAAmE;IACnE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAKtD;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAmB1C,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,aAAa;IASrB,SAAS;IAmBT,MAAM;IAMN,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED,IAAI,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, } 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, } from './workloads/ai-inference';
|
|
6
8
|
export type { ConsentControls, ConsentState, FlaxiaNodeController } from '@flaxia/sdk';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,GAChC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,+BAA+B,IAAI,kCAAkC,EACrE,8BAA8B,EAC9B,+BAA+B,GAChC,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|