@flaxia/node 0.5.0 → 0.5.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.
- package/dist/assets/ai-inference.js +241 -85
- package/dist/assets/webgpuProbe.js +357 -0
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/__tests__/mobile-lifecycle.test.d.ts +2 -0
- package/dist/client/__tests__/mobile-lifecycle.test.d.ts.map +1 -0
- package/dist/client/mobile-lifecycle.d.ts +20 -0
- package/dist/client/mobile-lifecycle.d.ts.map +1 -0
- package/dist/executor/WorkerPool.d.ts +7 -1
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/executor/__tests__/resourceReporter.test.d.ts +2 -0
- package/dist/executor/__tests__/resourceReporter.test.d.ts.map +1 -0
- package/dist/executor/memoryProbe.d.ts +5 -0
- package/dist/executor/memoryProbe.d.ts.map +1 -1
- package/dist/executor/resourceReporter.d.ts +15 -0
- package/dist/executor/resourceReporter.d.ts.map +1 -0
- package/dist/executor/webgpuProbe.d.ts +16 -5
- package/dist/executor/webgpuProbe.d.ts.map +1 -1
- package/dist/index.js +943 -291
- package/dist/swarm/__tests__/peer-quality.test.d.ts +2 -0
- package/dist/swarm/__tests__/peer-quality.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/peer-transport.test.d.ts +2 -0
- package/dist/swarm/__tests__/peer-transport.test.d.ts.map +1 -0
- package/dist/swarm/adapter.d.ts +1 -1
- package/dist/swarm/adapter.d.ts.map +1 -1
- package/dist/swarm/controller.d.ts +4 -0
- package/dist/swarm/controller.d.ts.map +1 -1
- package/dist/swarm/messages.d.ts +2 -2
- package/dist/swarm/messages.d.ts.map +1 -1
- package/dist/swarm/peer-quality.d.ts +14 -0
- package/dist/swarm/peer-quality.d.ts.map +1 -0
- package/dist/swarm/peer-transport.d.ts +81 -0
- package/dist/swarm/peer-transport.d.ts.map +1 -0
- package/dist/swarm/runtime.d.ts +5 -1
- package/dist/swarm/runtime.d.ts.map +1 -1
- package/dist/swarm-engine.js +39 -20
- package/dist/worker.js +331 -208
- package/dist/workloads/__tests__/model-pipeline-cache.test.d.ts +2 -0
- package/dist/workloads/__tests__/model-pipeline-cache.test.d.ts.map +1 -0
- package/dist/workloads/ai-inference.d.ts +6 -0
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/model-pipeline-cache.d.ts +48 -0
- package/dist/workloads/model-pipeline-cache.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/assets/dist.js +0 -209
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
//#region ../sdk/dist/index.js
|
|
2
|
+
var e = "flaxia-node-v1", t = "bearer.";
|
|
3
|
+
function n(n) {
|
|
4
|
+
return [e, `${t}${n}`];
|
|
5
|
+
}
|
|
6
|
+
function r(e, t, n = {}) {
|
|
7
|
+
let r = e.replace(/\/+$/, "").replace(/^http/, "ws"), i = new URL(`${r}${t.startsWith("/") ? t : `/${t}`}`);
|
|
8
|
+
for (let [e, t] of Object.entries(n)) t !== void 0 && i.searchParams.set(e, String(t));
|
|
9
|
+
return i.toString();
|
|
10
|
+
}
|
|
11
|
+
var i = 6e4;
|
|
12
|
+
function a(e, t) {
|
|
13
|
+
if (t.length === 0) return [];
|
|
14
|
+
if (!Number.isInteger(e) || e < 1) throw Error(`layers must be a positive integer, got ${e}`);
|
|
15
|
+
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);
|
|
16
|
+
for (; o > e;) {
|
|
17
|
+
let e = 0;
|
|
18
|
+
for (let t = 1; t < n; t++) a[t] > a[e] && (e = t);
|
|
19
|
+
if (a[e] <= 1) break;
|
|
20
|
+
a[e]--, o--;
|
|
21
|
+
}
|
|
22
|
+
let s = r.map((t, n) => ({
|
|
23
|
+
i: n,
|
|
24
|
+
f: e * t / i - Math.floor(e * t / i)
|
|
25
|
+
})).sort((e, t) => t.f - e.f), c = 0;
|
|
26
|
+
for (; o < e;) a[s[c % n].i]++, o++, c++;
|
|
27
|
+
return a;
|
|
28
|
+
}
|
|
29
|
+
function o(e) {
|
|
30
|
+
let t = a(e.layers, e.nodes.map((e) => e.capacity)), n = [], r = 0;
|
|
31
|
+
for (let i = 0; i < t.length; i++) {
|
|
32
|
+
let a = r + t[i], o = i === 0 ? "host" : "worker", s = {
|
|
33
|
+
start: r,
|
|
34
|
+
end: a,
|
|
35
|
+
hasEmbed: i === 0,
|
|
36
|
+
hasHead: i === 0
|
|
37
|
+
};
|
|
38
|
+
n.push({
|
|
39
|
+
nodeId: e.nodes[i].nodeId,
|
|
40
|
+
role: o,
|
|
41
|
+
slice: s
|
|
42
|
+
}), r = a;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
sessionId: e.sessionId,
|
|
46
|
+
taskId: e.taskId,
|
|
47
|
+
model: e.model,
|
|
48
|
+
layers: e.layers,
|
|
49
|
+
chain: n
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var s = 21335, c = 0, l = 1, u = 8 * 1024 * 1024;
|
|
53
|
+
function d(e, t, n) {
|
|
54
|
+
let r = new TextEncoder().encode(e);
|
|
55
|
+
if (!r.length || r.length > 256) throw Error("swarm session id length is invalid");
|
|
56
|
+
let i = n ?? new Uint8Array();
|
|
57
|
+
if (i.byteLength !== 0 && i.byteLength !== 16) throw Error("swarm envelope MAC length is invalid");
|
|
58
|
+
let a = 4 + r.length + 1 + i.byteLength;
|
|
59
|
+
if (a + t.byteLength > 8388608) throw Error(`swarm envelope exceeds ${u} bytes`);
|
|
60
|
+
let o = new ArrayBuffer(a + t.byteLength), s = new DataView(o);
|
|
61
|
+
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
|
+
}
|
|
63
|
+
function f(e) {
|
|
64
|
+
if (e.byteLength < 5 || e.byteLength > 8388608) return null;
|
|
65
|
+
let t = new DataView(e), n = t.getUint32(0, !0);
|
|
66
|
+
if (!n || n > 256) return null;
|
|
67
|
+
let r = 4 + n;
|
|
68
|
+
if (e.byteLength < r + 1) return null;
|
|
69
|
+
let i = t.getUint8(r);
|
|
70
|
+
if (i !== 0 && i !== 16) return null;
|
|
71
|
+
let a = r + 1 + i;
|
|
72
|
+
return e.byteLength < a + 16 ? null : {
|
|
73
|
+
sessionId: new TextDecoder().decode(new Uint8Array(e, 4, n)),
|
|
74
|
+
mac: i ? new Uint8Array(e, r + 1, i) : null,
|
|
75
|
+
frame: e.slice(a)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function p(e, t, n) {
|
|
79
|
+
let r = await crypto.subtle.importKey("raw", new TextEncoder().encode(e), {
|
|
80
|
+
name: "HMAC",
|
|
81
|
+
hash: "SHA-256"
|
|
82
|
+
}, !1, ["sign"]), i = await crypto.subtle.sign("HMAC", r, d(t, n));
|
|
83
|
+
return new Uint8Array(i).slice(0, 16);
|
|
84
|
+
}
|
|
85
|
+
async function m(e, t, n) {
|
|
86
|
+
return d(t, n, await p(e, t, n));
|
|
87
|
+
}
|
|
88
|
+
async function ee(e, t, n, r) {
|
|
89
|
+
if (r.byteLength !== 16) return !1;
|
|
90
|
+
let i = await p(e, t, n), a = 0;
|
|
91
|
+
for (let e = 0; e < i.byteLength; e++) a |= i[e] ^ r[e];
|
|
92
|
+
return a === 0;
|
|
93
|
+
}
|
|
94
|
+
function h(e, t) {
|
|
95
|
+
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;
|
|
97
|
+
}
|
|
98
|
+
function g(e = 0) {
|
|
99
|
+
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;
|
|
101
|
+
}
|
|
102
|
+
function te(e) {
|
|
103
|
+
if (e.byteLength !== 16) return !1;
|
|
104
|
+
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;
|
|
106
|
+
}
|
|
107
|
+
function ne(e) {
|
|
108
|
+
if (e.byteLength < 16) return null;
|
|
109
|
+
let t = new DataView(e);
|
|
110
|
+
return t.getUint16(0, !0) !== 21335 || t.getUint8(2) !== c ? null : {
|
|
111
|
+
header: {
|
|
112
|
+
requestId: t.getUint32(4, !0),
|
|
113
|
+
pos: t.getUint32(8, !0),
|
|
114
|
+
tokens: t.getUint16(12, !0)
|
|
115
|
+
},
|
|
116
|
+
payload: new Uint8Array(e, 16)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function _(e) {
|
|
120
|
+
if (!y(e)) return !1;
|
|
121
|
+
if (e.kind === "description") {
|
|
122
|
+
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;
|
|
124
|
+
}
|
|
125
|
+
if (e.kind === "candidate") {
|
|
126
|
+
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);
|
|
128
|
+
}
|
|
129
|
+
return !1;
|
|
130
|
+
}
|
|
131
|
+
function v(e) {
|
|
132
|
+
if (!y(e) || e.type !== "swarm-peer-signal" || !_(e.signal)) return !1;
|
|
133
|
+
try {
|
|
134
|
+
if (new TextEncoder().encode(JSON.stringify(e.signal)).byteLength > 32768) return !1;
|
|
135
|
+
} catch {
|
|
136
|
+
return !1;
|
|
137
|
+
}
|
|
138
|
+
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
|
+
}
|
|
140
|
+
function y(e) {
|
|
141
|
+
return typeof e == "object" && !!e;
|
|
142
|
+
}
|
|
143
|
+
function b(e) {
|
|
144
|
+
return typeof e == "number" && Number.isInteger(e) && e >= 0;
|
|
145
|
+
}
|
|
146
|
+
function x(e, t = {}) {
|
|
147
|
+
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;
|
|
152
|
+
}
|
|
153
|
+
function C(e) {
|
|
154
|
+
return y(e) ? typeof e.nodeId == "string" && e.nodeId.length > 0 && typeof e.capacity == "number" : !1;
|
|
155
|
+
}
|
|
156
|
+
function w(e) {
|
|
157
|
+
return e === void 0 || typeof e == "string" && e.length > 0 && e.length <= 128;
|
|
158
|
+
}
|
|
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
|
+
function ae(e) {
|
|
166
|
+
return !y(e) || e.type !== "swarm-start" ? !1 : typeof e.sessionId == "string" && !!e.sessionId && typeof e.taskId == "string" && !!e.taskId;
|
|
167
|
+
}
|
|
168
|
+
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");
|
|
170
|
+
}
|
|
171
|
+
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);
|
|
173
|
+
}
|
|
174
|
+
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";
|
|
176
|
+
}
|
|
177
|
+
new Set([
|
|
178
|
+
"qwen3.5-2b",
|
|
179
|
+
"qwen3.8-27b",
|
|
180
|
+
"qwen3.6-35b-moe"
|
|
181
|
+
]);
|
|
182
|
+
var D = new Set([
|
|
183
|
+
"ai-inference",
|
|
184
|
+
"image-process",
|
|
185
|
+
"container",
|
|
186
|
+
"vector-embed",
|
|
187
|
+
"vector-query",
|
|
188
|
+
"nudenet",
|
|
189
|
+
"swarm-inference"
|
|
190
|
+
]), O = 9e4, k = 600 * 1e3, A = 1440 * 60 * 1e3, j = 6e4;
|
|
191
|
+
function M(e) {
|
|
192
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
193
|
+
}
|
|
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;
|
|
196
|
+
if (e.layerRange === void 0) return !0;
|
|
197
|
+
let t = e.layerRange;
|
|
198
|
+
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
|
+
}
|
|
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;
|
|
202
|
+
let n = e.sampledAt, r = e.expiresAt;
|
|
203
|
+
return n <= t + 5e3 && n >= t - 6e4 && r > t && r > n && r - n <= 6e4;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#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);
|
|
210
|
+
try {
|
|
211
|
+
e.grow(n);
|
|
212
|
+
} catch {
|
|
213
|
+
return !1;
|
|
214
|
+
}
|
|
215
|
+
let r = new Uint8Array(e.buffer);
|
|
216
|
+
for (let e = 0; e < n; e++) r[e * I] = 0;
|
|
217
|
+
return !0;
|
|
218
|
+
}
|
|
219
|
+
function H(e = F, t = L) {
|
|
220
|
+
if (z) return z.bytes;
|
|
221
|
+
B++;
|
|
222
|
+
let n = Date.now(), r;
|
|
223
|
+
try {
|
|
224
|
+
r = new WebAssembly.Memory({ initial: 0 });
|
|
225
|
+
} catch {
|
|
226
|
+
return z = {
|
|
227
|
+
bytes: 0,
|
|
228
|
+
sampledAt: n,
|
|
229
|
+
measured: !1
|
|
230
|
+
}, 0;
|
|
231
|
+
}
|
|
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;) {
|
|
234
|
+
let e = Math.min(a, i - o);
|
|
235
|
+
if (!V(r, e)) break;
|
|
236
|
+
o += e, s++;
|
|
237
|
+
}
|
|
238
|
+
return r = void 0, z = {
|
|
239
|
+
bytes: o,
|
|
240
|
+
sampledAt: n,
|
|
241
|
+
measured: !0
|
|
242
|
+
}, o;
|
|
243
|
+
}
|
|
244
|
+
function U() {
|
|
245
|
+
return z ? z.bytes : H();
|
|
246
|
+
}
|
|
247
|
+
function W() {
|
|
248
|
+
return z || H(), {
|
|
249
|
+
bytes: z?.measured ? z.bytes : null,
|
|
250
|
+
sampledAt: z?.sampledAt ?? null
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function G() {
|
|
254
|
+
return U() >= F;
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/executor/webgpuProbe.ts
|
|
258
|
+
var K = 3, q = 750, J = 1500, Y = 600 * 1e3;
|
|
259
|
+
async function X(e, t) {
|
|
260
|
+
let n, r = new Promise((e) => {
|
|
261
|
+
n = setTimeout(() => e({
|
|
262
|
+
value: null,
|
|
263
|
+
timedOut: !0
|
|
264
|
+
}), t);
|
|
265
|
+
});
|
|
266
|
+
try {
|
|
267
|
+
return await Promise.race([e.then((e) => ({
|
|
268
|
+
value: e,
|
|
269
|
+
timedOut: !1
|
|
270
|
+
})), r]);
|
|
271
|
+
} finally {
|
|
272
|
+
n !== void 0 && clearTimeout(n);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function Z(e, t = Date.now()) {
|
|
276
|
+
return {
|
|
277
|
+
capabilities: { webgpu: !1 },
|
|
278
|
+
status: e,
|
|
279
|
+
sampledAt: t,
|
|
280
|
+
expiresAt: t + Y,
|
|
281
|
+
architecture: null,
|
|
282
|
+
maxStorageBufferBindingSize: null,
|
|
283
|
+
computeCompletionMs: null,
|
|
284
|
+
sampleCount: 0
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function Q() {
|
|
288
|
+
return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
|
|
289
|
+
}
|
|
290
|
+
async function se(e) {
|
|
291
|
+
let t, n = new Promise((e) => {
|
|
292
|
+
t = setTimeout(() => e("timeout"), q);
|
|
293
|
+
}), r = e.queue.onSubmittedWorkDone().then(() => "complete"), i = e.lost.then(() => "lost", () => "lost");
|
|
294
|
+
try {
|
|
295
|
+
return await Promise.race([
|
|
296
|
+
r,
|
|
297
|
+
i,
|
|
298
|
+
n
|
|
299
|
+
]);
|
|
300
|
+
} finally {
|
|
301
|
+
t !== void 0 && clearTimeout(t);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function $() {
|
|
305
|
+
let e = Date.now(), t = navigator.gpu;
|
|
306
|
+
if (!t || typeof t.requestAdapter != "function") return Z("unsupported", e);
|
|
307
|
+
let n = null;
|
|
308
|
+
try {
|
|
309
|
+
let r = await X(t.requestAdapter({ powerPreference: "high-performance" }), J);
|
|
310
|
+
if (r.timedOut) return Z("unavailable", Date.now());
|
|
311
|
+
let i = r.value;
|
|
312
|
+
if (!i) return Z("unsupported", e);
|
|
313
|
+
let a = i.limits?.maxStorageBufferBindingSize, o = [i.info?.vendor, i.info?.architecture].filter((e) => typeof e == "string" && e.trim().length > 0).join(" ").trim().slice(0, 64), s = typeof a == "number" && Number.isFinite(a) && a > 0 ? Math.min(Math.floor(a), 16 * 1024 ** 3) : null, c = i.requestDevice(), l = await X(c, J);
|
|
314
|
+
if (l.timedOut) return c.then((e) => e.destroy()).catch(() => {}), Z("unavailable", Date.now());
|
|
315
|
+
n = l.value;
|
|
316
|
+
let u = n, d = u.createComputePipeline({
|
|
317
|
+
layout: "auto",
|
|
318
|
+
compute: {
|
|
319
|
+
module: u.createShaderModule({ code: "@compute @workgroup_size(1) fn main() {}" }),
|
|
320
|
+
entryPoint: "main"
|
|
321
|
+
}
|
|
322
|
+
}), f = [];
|
|
323
|
+
for (let e = 0; e < K; e++) {
|
|
324
|
+
let e = u.createCommandEncoder(), t = e.beginComputePass();
|
|
325
|
+
t.setPipeline(d), t.dispatchWorkgroups(1), t.end();
|
|
326
|
+
let n = e.finish(), r = Q();
|
|
327
|
+
u.queue.submit([n]);
|
|
328
|
+
let i = await se(u);
|
|
329
|
+
if (i === "lost") return Z("device-lost", Date.now());
|
|
330
|
+
if (i === "timeout") return Z("unavailable", Date.now());
|
|
331
|
+
f.push(Math.max(0, Q() - r));
|
|
332
|
+
}
|
|
333
|
+
f.sort((e, t) => e - t);
|
|
334
|
+
let p = f[Math.floor(f.length / 2)], m = { webgpu: !0 };
|
|
335
|
+
return o && (m.gpuArchitecture = o), s !== null && (m.maxStorageBufferBindingSize = s), {
|
|
336
|
+
capabilities: m,
|
|
337
|
+
status: "available",
|
|
338
|
+
sampledAt: Date.now(),
|
|
339
|
+
expiresAt: Date.now() + Y,
|
|
340
|
+
architecture: o || null,
|
|
341
|
+
maxStorageBufferBindingSize: s,
|
|
342
|
+
computeCompletionMs: p,
|
|
343
|
+
sampleCount: f.length
|
|
344
|
+
};
|
|
345
|
+
} catch {
|
|
346
|
+
return Z("unavailable", Date.now());
|
|
347
|
+
} finally {
|
|
348
|
+
try {
|
|
349
|
+
n?.destroy();
|
|
350
|
+
} catch {}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async function ce() {
|
|
354
|
+
return (await $()).capabilities;
|
|
355
|
+
}
|
|
356
|
+
//#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 };
|
|
@@ -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":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile-lifecycle.test.d.ts","sourceRoot":"","sources":["../../../src/client/__tests__/mobile-lifecycle.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface MobileLifecycleSignals {
|
|
2
|
+
hidden: boolean;
|
|
3
|
+
pageHidden: boolean;
|
|
4
|
+
online: boolean;
|
|
5
|
+
batteryLevel?: number;
|
|
6
|
+
batteryCharging?: boolean;
|
|
7
|
+
effectiveType?: string;
|
|
8
|
+
saveData?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface MobileLifecycleDecision {
|
|
11
|
+
suspend: boolean;
|
|
12
|
+
constrained: boolean;
|
|
13
|
+
maxCpuLoad?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert optional browser lifecycle, network, and battery signals into a
|
|
17
|
+
* bounded execution policy. Missing Battery/Network Information APIs are safe.
|
|
18
|
+
*/
|
|
19
|
+
export declare function evaluateMobileLifecycle(signals: MobileLifecycleSignals, configuredMaxCpuLoad?: number): MobileLifecycleDecision;
|
|
20
|
+
//# sourceMappingURL=mobile-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile-lifecycle.d.ts","sourceRoot":"","sources":["../../src/client/mobile-lifecycle.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,sBAAsB,EAC/B,oBAAoB,CAAC,EAAE,MAAM,GAC5B,uBAAuB,CAgBzB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkloadType } from "@flaxia/sdk";
|
|
1
|
+
import type { NodeModelCacheSnapshot, WorkloadType } from "@flaxia/sdk";
|
|
2
2
|
/** Swarm tasks exchange control messages and binary frames mid-task. */
|
|
3
3
|
export interface SwarmCallbacks {
|
|
4
4
|
onFrame?: (frame: ArrayBuffer) => void;
|
|
@@ -25,6 +25,8 @@ export declare class WorkerPool {
|
|
|
25
25
|
private pendingControls;
|
|
26
26
|
private static readonly MAX_PENDING_CONTROLS;
|
|
27
27
|
private _lastCpuLoad;
|
|
28
|
+
private _hasCpuLoadSample;
|
|
29
|
+
private _modelCacheSnapshot;
|
|
28
30
|
constructor(workerUrl?: string, timeoutMs?: number);
|
|
29
31
|
private initWorker;
|
|
30
32
|
run(id: string, workload: WorkloadType, payload: unknown, timeoutMs?: number, onToken?: (token: string) => void, config?: {
|
|
@@ -48,6 +50,8 @@ export declare class WorkerPool {
|
|
|
48
50
|
*/
|
|
49
51
|
sendControl(message: unknown, executionId?: string): boolean;
|
|
50
52
|
sendFrame(frame: ArrayBuffer): boolean;
|
|
53
|
+
/** Pause or resume a normal workload's asynchronous token sink. */
|
|
54
|
+
setTokenFlow(taskId: string, paused: boolean): boolean;
|
|
51
55
|
/**
|
|
52
56
|
* The coordinator settled this task elsewhere (timeout, a peer failed, the
|
|
53
57
|
* plan was rejected): stop it.
|
|
@@ -63,5 +67,7 @@ export declare class WorkerPool {
|
|
|
63
67
|
terminate(): void;
|
|
64
68
|
resume(): void;
|
|
65
69
|
get lastCpuLoad(): number;
|
|
70
|
+
get hasCpuLoadSample(): boolean;
|
|
71
|
+
get modelCacheSnapshot(): NodeModelCacheSnapshot | null;
|
|
66
72
|
}
|
|
67
73
|
//# sourceMappingURL=WorkerPool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerPool.d.ts","sourceRoot":"","sources":["../../src/executor/WorkerPool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WorkerPool.d.ts","sourceRoot":"","sources":["../../src/executor/WorkerPool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoBxE,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACvC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,MAAM,CAA2B;IACzC,yEAAyE;IACzE,OAAO,CAAC,eAAe,CAAmD;IAC1E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAM;IAClD,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,mBAAmB,CAAuC;gBAEtD,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,SAAS;IAMlD,OAAO,CAAC,UAAU;IAYlB,GAAG,CACD,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,OAAO,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EACjC,MAAM,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,EAChG,KAAK,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,OAAO,CAAC;IAgBnB,OAAO,CAAC,OAAO;IAkGf,+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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceReporter.test.d.ts","sourceRoot":"","sources":["../../../src/executor/__tests__/resourceReporter.test.ts"],"names":[],"mappings":""}
|
|
@@ -13,6 +13,11 @@ export declare function probeMaxWasmMemoryBytes(targetBytes?: number, chunkBytes
|
|
|
13
13
|
* capability reporting) should use instead of `probeMaxWasmMemoryBytes()`.
|
|
14
14
|
*/
|
|
15
15
|
export declare function getWasmMemoryBytes(): number;
|
|
16
|
+
/** The one-shot lower-bound observation, including when the runtime could not create WASM memory. */
|
|
17
|
+
export declare function getWasmMemoryProbeObservation(): {
|
|
18
|
+
bytes: number | null;
|
|
19
|
+
sampledAt: number | null;
|
|
20
|
+
};
|
|
16
21
|
/**
|
|
17
22
|
* Whether the device can commit the memory a heavy (multi-GB model) workload
|
|
18
23
|
* needs. Uses the cached probe, so it never re-allocates.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoryProbe.d.ts","sourceRoot":"","sources":["../../src/executor/memoryProbe.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,gCAAgC,QAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"memoryProbe.d.ts","sourceRoot":"","sources":["../../src/executor/memoryProbe.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,gCAAgC,QAAgB,CAAC;AA8B9D;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,GAAE,MAAyC,EACtD,UAAU,GAAE,MAA0B,GACrC,MAAM,CA6BR;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAG3C;AAED,qGAAqG;AACrG,wBAAgB,6BAA6B,IAAI;IAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAMlG;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD;AAED,+DAA+D;AAC/D,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NodeResourceReport } from '@flaxia/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Collect current resource telemetry for an already-consented signaling
|
|
4
|
+
* session. The 2 GiB WASM lower-bound probe remains one-shot; the tiny GPU
|
|
5
|
+
* compute sample refreshes only after its ten minute TTL.
|
|
6
|
+
*/
|
|
7
|
+
export declare function collectNodeResourceReport(options: {
|
|
8
|
+
cpuLoad?: number | null;
|
|
9
|
+
deviceMemory?: number;
|
|
10
|
+
probeGpu?: boolean;
|
|
11
|
+
now?: number;
|
|
12
|
+
}): Promise<NodeResourceReport>;
|
|
13
|
+
/** Clear the GPU result cache in isolated probe tests. */
|
|
14
|
+
export declare function resetNodeResourceReportCache(): void;
|
|
15
|
+
//# sourceMappingURL=resourceReporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceReporter.d.ts","sourceRoot":"","sources":["../../src/executor/resourceReporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,aAAa,CAAC;AAuCtE;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE;IACvD,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA2C9B;AAED,0DAA0D;AAC1D,wBAAgB,4BAA4B,IAAI,IAAI,CAGnD"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import type { SwarmNodeCapabilities } from '@flaxia/sdk';
|
|
1
|
+
import type { GpuProbeStatus, SwarmNodeCapabilities } from '@flaxia/sdk';
|
|
2
|
+
export interface WebGpuProbeResult {
|
|
3
|
+
capabilities: SwarmNodeCapabilities;
|
|
4
|
+
status: GpuProbeStatus;
|
|
5
|
+
sampledAt: number;
|
|
6
|
+
expiresAt: number;
|
|
7
|
+
architecture: string | null;
|
|
8
|
+
maxStorageBufferBindingSize: number | null;
|
|
9
|
+
computeCompletionMs: number | null;
|
|
10
|
+
sampleCount: number;
|
|
11
|
+
}
|
|
2
12
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `{ webgpu: false }`.
|
|
13
|
+
* Request a device and time three tiny no-buffer compute submissions. This is
|
|
14
|
+
* a scheduling hint, not a benchmark: it allocates no model-sized resources,
|
|
15
|
+
* has a per-sample timeout, and destroys the temporary device in all cases.
|
|
7
16
|
*/
|
|
17
|
+
export declare function probeWebGpuDetailed(): Promise<WebGpuProbeResult>;
|
|
18
|
+
/** Backwards-compatible capability probe; eligibility requires a working device. */
|
|
8
19
|
export declare function probeWebGpu(): Promise<SwarmNodeCapabilities>;
|
|
9
20
|
//# sourceMappingURL=webgpuProbe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgpuProbe.d.ts","sourceRoot":"","sources":["../../src/executor/webgpuProbe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"webgpuProbe.d.ts","sourceRoot":"","sources":["../../src/executor/webgpuProbe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAkEzE,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,qBAAqB,CAAC;IACpC,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,2BAA2B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;CACrB;AAmCD;;;;GAIG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAqFtE;AAED,oFAAoF;AACpF,wBAAsB,WAAW,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAElE"}
|