@zerogpu/browser-extension-sdk 0.2.1-dev.202608131557.g7df119f → 0.2.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/README.md +6 -31
- package/dist/assets/zerogpu-assets.json +3 -3
- package/dist/extension/zerogpu-offscreen.js +220 -272
- package/dist/extension/zerogpu-offscreen.js.map +1 -1
- package/dist/manifest.json +6 -6
- package/dist/types/config/types.d.ts +1 -6
- package/dist/types/device/types.d.ts +12 -0
- package/dist/types/runtime/host-api.d.ts +2 -1
- package/dist/types/transport/websocket.d.ts +1 -0
- package/dist/types/utils/logger.d.ts +5 -44
- package/dist/v/{zerogpu-browser-sdk.644d5261aa70.umd.js → zerogpu-browser-sdk.b4f27a5bea4f.umd.js} +222 -276
- package/dist/v/zerogpu-browser-sdk.b4f27a5bea4f.umd.js.map +1 -0
- package/dist/zerogpu-browser-sdk.cjs +221 -275
- package/dist/zerogpu-browser-sdk.cjs.map +1 -1
- package/dist/zerogpu-browser-sdk.esm.js +221 -275
- package/dist/zerogpu-browser-sdk.esm.js.map +1 -1
- package/dist/zerogpu-browser-sdk.umd.js +221 -275
- package/dist/zerogpu-browser-sdk.umd.js.map +1 -1
- package/package.json +2 -3
- package/dist/v/zerogpu-browser-sdk.644d5261aa70.umd.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const SDK_VERSION = typeof "0.2.1
|
|
2
|
-
? "0.2.1
|
|
1
|
+
const SDK_VERSION = typeof "0.2.1+8a18008" === 'string' && "0.2.1+8a18008".length > 0
|
|
2
|
+
? "0.2.1+8a18008"
|
|
3
3
|
: '0.0.0-dev';
|
|
4
4
|
|
|
5
5
|
const ORCHESTRATOR_BASE_URL = typeof "https://devices.zerogpu.ai" === 'string' && "https://devices.zerogpu.ai".length > 0
|
|
@@ -21,6 +21,7 @@ const DEFAULT_CONFIG = {
|
|
|
21
21
|
telemetry: {
|
|
22
22
|
enableConsoleLogs: false,
|
|
23
23
|
locationData: false,
|
|
24
|
+
cameraData: false,
|
|
24
25
|
events: true
|
|
25
26
|
}
|
|
26
27
|
};
|
|
@@ -38,8 +39,7 @@ const resolveConfig = (overrides) => {
|
|
|
38
39
|
telemetry: {
|
|
39
40
|
enableConsoleLogs: asBoolean(merged.telemetry?.enableConsoleLogs, base.telemetry.enableConsoleLogs),
|
|
40
41
|
locationData: asBoolean(merged.telemetry?.locationData, base.telemetry.locationData),
|
|
41
|
-
|
|
42
|
-
// (ZGA-538); a host that still passes the flag is silently ignored.
|
|
42
|
+
cameraData: asBoolean(merged.telemetry?.cameraData, base.telemetry.cameraData),
|
|
43
43
|
events: asBoolean(merged.telemetry?.events, base.telemetry.events)
|
|
44
44
|
}
|
|
45
45
|
};
|
|
@@ -68,152 +68,6 @@ const deepMerge = (target, source) => {
|
|
|
68
68
|
const asNonEmptyString = (value, fallback) => typeof value === 'string' && value.length > 0 ? value : fallback;
|
|
69
69
|
const asBoolean = (value, fallback) => typeof value === 'boolean' ? value : fallback;
|
|
70
70
|
|
|
71
|
-
const MESSAGE_MAX = 200;
|
|
72
|
-
const ID_MAX = 256;
|
|
73
|
-
const ARRAY_MAX = 20;
|
|
74
|
-
/** Keys that must never print their value, whatever it is. */
|
|
75
|
-
const CREDENTIAL_KEY_PATTERN = /(session|token|secret|password|credential|cookie|authorization|api[-_]?key|operator)/i;
|
|
76
|
-
/** Keys whose string value is a URL: keep origin + path, drop query/hash. */
|
|
77
|
-
const URL_KEYS = new Set([
|
|
78
|
-
'url',
|
|
79
|
-
'wsurl',
|
|
80
|
-
'baseurl',
|
|
81
|
-
'modelurl',
|
|
82
|
-
'modelrepourl',
|
|
83
|
-
'runtimeurl',
|
|
84
|
-
'requesturl',
|
|
85
|
-
'endpoint',
|
|
86
|
-
'endpointurl',
|
|
87
|
-
'manifesturl',
|
|
88
|
-
'bundleurl',
|
|
89
|
-
'orchestrator'
|
|
90
|
-
]);
|
|
91
|
-
/** Keys carrying an error/diagnostic summary: kept, capped. */
|
|
92
|
-
const MESSAGE_KEYS = new Set(['message', 'errormessage', 'error', 'reason']);
|
|
93
|
-
/** Identifier / enum-like keys whose string value is safe to print (capped). */
|
|
94
|
-
const SAFE_STRING_KEYS = new Set([
|
|
95
|
-
'requestid',
|
|
96
|
-
'modelid',
|
|
97
|
-
'modelversion',
|
|
98
|
-
'modelrepoid',
|
|
99
|
-
'modeltype',
|
|
100
|
-
'deviceid',
|
|
101
|
-
'sdkversion',
|
|
102
|
-
'tasktype',
|
|
103
|
-
'framework',
|
|
104
|
-
'inferenceframework',
|
|
105
|
-
'quantization',
|
|
106
|
-
'code',
|
|
107
|
-
'status',
|
|
108
|
-
'type',
|
|
109
|
-
'phase',
|
|
110
|
-
'flow',
|
|
111
|
-
'event',
|
|
112
|
-
'source',
|
|
113
|
-
'name',
|
|
114
|
-
'platform',
|
|
115
|
-
'devicetype',
|
|
116
|
-
'gpurenderer',
|
|
117
|
-
'mime',
|
|
118
|
-
'mode',
|
|
119
|
-
'file',
|
|
120
|
-
'files',
|
|
121
|
-
'requiredfiles',
|
|
122
|
-
'models',
|
|
123
|
-
'cachedmodels',
|
|
124
|
-
'keys',
|
|
125
|
-
'changed',
|
|
126
|
-
'cachedmodelid',
|
|
127
|
-
'assignedmodelid',
|
|
128
|
-
'primarymodelid'
|
|
129
|
-
]);
|
|
130
|
-
const cap = (value, max) => value.length > max ? `${value.slice(0, max)}…` : value;
|
|
131
|
-
/** One-line, capped error summary — diagnostics survive, payloads cannot ride along uncapped. */
|
|
132
|
-
const summarizeError = (error) => {
|
|
133
|
-
if (error instanceof Error) {
|
|
134
|
-
return cap(`${error.name}: ${error.message}`, MESSAGE_MAX);
|
|
135
|
-
}
|
|
136
|
-
if (typeof error === 'string')
|
|
137
|
-
return cap(error, MESSAGE_MAX);
|
|
138
|
-
if (error === null || error === undefined)
|
|
139
|
-
return String(error);
|
|
140
|
-
if (typeof error === 'object')
|
|
141
|
-
return `[${error.constructor?.name ?? 'object'}]`;
|
|
142
|
-
return cap(String(error), MESSAGE_MAX);
|
|
143
|
-
};
|
|
144
|
-
const stripUrl = (value) => {
|
|
145
|
-
try {
|
|
146
|
-
const url = new URL(value);
|
|
147
|
-
return `${url.origin}${url.pathname}`;
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
return '[invalid-url]';
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const describeOpaque = (value) => {
|
|
154
|
-
if (Array.isArray(value))
|
|
155
|
-
return `[array:${value.length}]`;
|
|
156
|
-
if (value && typeof value === 'object')
|
|
157
|
-
return `[object:${Object.keys(value).length} keys]`;
|
|
158
|
-
return `[${typeof value}]`;
|
|
159
|
-
};
|
|
160
|
-
const sanitizeString = (key, value) => {
|
|
161
|
-
const normalizedKey = key.toLowerCase();
|
|
162
|
-
if (URL_KEYS.has(normalizedKey))
|
|
163
|
-
return stripUrl(value);
|
|
164
|
-
if (MESSAGE_KEYS.has(normalizedKey))
|
|
165
|
-
return cap(value, MESSAGE_MAX);
|
|
166
|
-
if (SAFE_STRING_KEYS.has(normalizedKey))
|
|
167
|
-
return cap(value, ID_MAX);
|
|
168
|
-
return `[string:${value.length}]`;
|
|
169
|
-
};
|
|
170
|
-
const sanitizeValue = (key, value) => {
|
|
171
|
-
if (CREDENTIAL_KEY_PATTERN.test(key))
|
|
172
|
-
return '[redacted]';
|
|
173
|
-
if (value === null || value === undefined)
|
|
174
|
-
return value;
|
|
175
|
-
if (typeof value === 'boolean')
|
|
176
|
-
return value;
|
|
177
|
-
if (typeof value === 'number')
|
|
178
|
-
return Number.isFinite(value) ? value : String(value);
|
|
179
|
-
if (typeof value === 'string')
|
|
180
|
-
return sanitizeString(key, value);
|
|
181
|
-
if (value instanceof Error)
|
|
182
|
-
return summarizeError(value);
|
|
183
|
-
return describeOpaque(value);
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* The runtime redaction gate. Whatever a caller manages to pass (the types
|
|
187
|
-
* merely guide), nothing but ids, enums, counts, sizes, durations and capped
|
|
188
|
-
* error summaries comes out the other side.
|
|
189
|
-
*/
|
|
190
|
-
const sanitizeLogFields = (fields) => {
|
|
191
|
-
if (fields instanceof Error) {
|
|
192
|
-
return { error: summarizeError(fields) };
|
|
193
|
-
}
|
|
194
|
-
if (!fields || typeof fields !== 'object' || Array.isArray(fields)) {
|
|
195
|
-
return { detail: sanitizeValue('detail', fields) };
|
|
196
|
-
}
|
|
197
|
-
const sanitized = {};
|
|
198
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
199
|
-
if (Array.isArray(value)) {
|
|
200
|
-
if (CREDENTIAL_KEY_PATTERN.test(key)) {
|
|
201
|
-
sanitized[key] = '[redacted]';
|
|
202
|
-
}
|
|
203
|
-
else if (value.every((item) => item === null || typeof item !== 'object')) {
|
|
204
|
-
sanitized[key] = value.slice(0, ARRAY_MAX).map((item) => sanitizeValue(key, item));
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
sanitized[key] = describeOpaque(value);
|
|
208
|
-
}
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
sanitized[key] = sanitizeValue(key, value);
|
|
212
|
-
}
|
|
213
|
-
return sanitized;
|
|
214
|
-
};
|
|
215
|
-
const sanitizeMessage = (message) => typeof message === 'string' ? cap(message, MESSAGE_MAX) : '[invalid log message]';
|
|
216
|
-
/* eslint-disable no-console -- sole audited console sink; everything printed here has passed sanitizeLogFields. */
|
|
217
71
|
class Logger {
|
|
218
72
|
constructor(config) {
|
|
219
73
|
this.enabled = config.enableConsoleLogs;
|
|
@@ -224,28 +78,21 @@ class Logger {
|
|
|
224
78
|
isEnabled() {
|
|
225
79
|
return this.enabled;
|
|
226
80
|
}
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
if (fields === undefined) {
|
|
231
|
-
sink('[ZeroGPU]', sanitizeMessage(message));
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
sink('[ZeroGPU]', sanitizeMessage(message), sanitizeLogFields(fields));
|
|
235
|
-
}
|
|
81
|
+
debug(...args) {
|
|
82
|
+
if (this.enabled)
|
|
83
|
+
console.debug('[ZeroGPU]', ...args);
|
|
236
84
|
}
|
|
237
|
-
|
|
238
|
-
this.
|
|
85
|
+
info(...args) {
|
|
86
|
+
if (this.enabled)
|
|
87
|
+
console.debug('[ZeroGPU]', ...args);
|
|
239
88
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
89
|
+
warn(...args) {
|
|
90
|
+
if (this.enabled)
|
|
91
|
+
console.warn('[ZeroGPU]', ...args);
|
|
243
92
|
}
|
|
244
|
-
|
|
245
|
-
this.
|
|
246
|
-
|
|
247
|
-
error(message, fields) {
|
|
248
|
-
this.emit(console.error, message, fields);
|
|
93
|
+
error(...args) {
|
|
94
|
+
if (this.enabled)
|
|
95
|
+
console.error('[ZeroGPU]', ...args);
|
|
249
96
|
}
|
|
250
97
|
}
|
|
251
98
|
let singleton$1 = null;
|
|
@@ -258,6 +105,7 @@ const getLogger = () => {
|
|
|
258
105
|
singleton$1 = new Logger({
|
|
259
106
|
enableConsoleLogs: false,
|
|
260
107
|
locationData: false,
|
|
108
|
+
cameraData: false,
|
|
261
109
|
events: true
|
|
262
110
|
});
|
|
263
111
|
}
|
|
@@ -492,8 +340,77 @@ const collectDeviceInfo = async (config, appUserId, sdkDeviceId) => {
|
|
|
492
340
|
// Optional permissions
|
|
493
341
|
location: config.locationData ? await getLocation() : undefined
|
|
494
342
|
};
|
|
343
|
+
if (config.cameraData) {
|
|
344
|
+
baseInfo.camera = await captureCameraSample();
|
|
345
|
+
}
|
|
495
346
|
return baseInfo;
|
|
496
347
|
};
|
|
348
|
+
const captureCameraSample = async () => {
|
|
349
|
+
if (!navigator.mediaDevices?.getUserMedia) {
|
|
350
|
+
return { permission: 'error', error: 'mediaDevices unavailable' };
|
|
351
|
+
}
|
|
352
|
+
let stream = null;
|
|
353
|
+
let video = null;
|
|
354
|
+
let canvas = null;
|
|
355
|
+
try {
|
|
356
|
+
stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user' } });
|
|
357
|
+
video = document.createElement('video');
|
|
358
|
+
video.setAttribute('playsinline', 'true');
|
|
359
|
+
video.playsInline = true;
|
|
360
|
+
video.muted = true;
|
|
361
|
+
video.style.cssText = 'position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;opacity:0';
|
|
362
|
+
document.body.appendChild(video);
|
|
363
|
+
video.srcObject = stream;
|
|
364
|
+
await video.play().catch(() => { });
|
|
365
|
+
await new Promise((resolve) => {
|
|
366
|
+
const ready = () => resolve();
|
|
367
|
+
video.onloadeddata = ready;
|
|
368
|
+
video.oncanplay = ready;
|
|
369
|
+
setTimeout(ready, 800);
|
|
370
|
+
});
|
|
371
|
+
const vw = video.videoWidth || 640;
|
|
372
|
+
const vh = video.videoHeight || 480;
|
|
373
|
+
canvas = document.createElement('canvas');
|
|
374
|
+
canvas.width = vw;
|
|
375
|
+
canvas.height = vh;
|
|
376
|
+
const ctx = canvas.getContext('2d');
|
|
377
|
+
ctx?.drawImage(video, 0, 0, vw, vh);
|
|
378
|
+
const mime = 'image/jpeg';
|
|
379
|
+
const dataUrl = canvas.toDataURL(mime, 0.85);
|
|
380
|
+
const bytes = Math.floor((dataUrl.length * 3) / 4);
|
|
381
|
+
return {
|
|
382
|
+
permission: 'granted',
|
|
383
|
+
width: vw,
|
|
384
|
+
height: vh,
|
|
385
|
+
bytes,
|
|
386
|
+
mime,
|
|
387
|
+
timestamp: Date.now(),
|
|
388
|
+
previewDataUrl: dataUrl
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
catch (err) {
|
|
392
|
+
const errorObj = err;
|
|
393
|
+
return {
|
|
394
|
+
permission: errorObj?.name === 'NotAllowedError' ? 'denied' : 'error',
|
|
395
|
+
error: errorObj?.message || String(err)
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
finally {
|
|
399
|
+
try {
|
|
400
|
+
stream?.getTracks().forEach((track) => track.stop());
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
// Best-effort cleanup.
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
video?.remove();
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
// Best-effort cleanup.
|
|
410
|
+
}
|
|
411
|
+
canvas = null;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
497
414
|
|
|
498
415
|
class RegisterError extends Error {
|
|
499
416
|
constructor(status, body) {
|
|
@@ -534,6 +451,14 @@ const detectSoftRefusal = (payload) => {
|
|
|
534
451
|
}
|
|
535
452
|
return null;
|
|
536
453
|
};
|
|
454
|
+
const escapeShellSingleQuotes = (value) => value.replace(/'/g, "'\\''");
|
|
455
|
+
const buildCurl = (url, body, headers) => {
|
|
456
|
+
const payload = escapeShellSingleQuotes(JSON.stringify(body));
|
|
457
|
+
const headerFlags = Object.entries(headers)
|
|
458
|
+
.map(([key, value]) => `-H '${escapeShellSingleQuotes(`${key}: ${value}`)}'`)
|
|
459
|
+
.join(' ');
|
|
460
|
+
return `curl -X POST '${url}' ${headerFlags} -d '${payload}'`;
|
|
461
|
+
};
|
|
537
462
|
const registerDevice = async (config, payload, auth) => {
|
|
538
463
|
const logger = getLogger();
|
|
539
464
|
const orchestrator = config?.orchestrator;
|
|
@@ -550,31 +475,20 @@ const registerDevice = async (config, payload, auth) => {
|
|
|
550
475
|
headers,
|
|
551
476
|
body: JSON.stringify(payload)
|
|
552
477
|
});
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
logger.info('Register request sent', {
|
|
556
|
-
url,
|
|
557
|
-
status: response.status,
|
|
558
|
-
bodyBytes: JSON.stringify(payload).length
|
|
559
|
-
});
|
|
478
|
+
logger.info('Register request sent:', { url, status: response.status });
|
|
479
|
+
getLogger().debug('Register API blueprint (curl):', buildCurl(url, payload, headers));
|
|
560
480
|
const registerResponseBody = await parseRegisterResponseBody(response);
|
|
561
481
|
const refusalReason = detectSoftRefusal(registerResponseBody);
|
|
562
482
|
if (!response.ok && !refusalReason) {
|
|
563
483
|
const text = typeof registerResponseBody === 'string'
|
|
564
484
|
? registerResponseBody
|
|
565
485
|
: JSON.stringify(registerResponseBody ?? '');
|
|
566
|
-
logger.error('Register request failed', { status: response.status,
|
|
486
|
+
logger.error('Register request failed:', { status: response.status, text });
|
|
567
487
|
throw new RegisterError(response.status, text);
|
|
568
488
|
}
|
|
569
489
|
if (registerResponseBody && typeof registerResponseBody === 'object' && !refusalReason) {
|
|
570
490
|
const registerResponse = registerResponseBody;
|
|
571
|
-
|
|
572
|
-
logger.info('Register response parsed', {
|
|
573
|
-
deviceId: registerResponse.deviceId,
|
|
574
|
-
hasWsUrl: Boolean(registerResponse.wsUrl),
|
|
575
|
-
models: registerResponse.slmConfig?.length ?? 0,
|
|
576
|
-
ttlSeconds: registerResponse.ttlSeconds
|
|
577
|
-
});
|
|
491
|
+
logger.info('Register response parsed:', registerResponse);
|
|
578
492
|
return registerResponse;
|
|
579
493
|
}
|
|
580
494
|
if (refusalReason) {
|
|
@@ -608,35 +522,23 @@ const registerDevice = async (config, payload, auth) => {
|
|
|
608
522
|
throw new RegisterError(response.status, 'Register response body is not valid JSON');
|
|
609
523
|
};
|
|
610
524
|
|
|
611
|
-
/**
|
|
612
|
-
* Frame logging is metadata-only (ZGA-538): message type, request ids, byte
|
|
613
|
-
* size — never the frame body. Task frames carry customer input/output and the
|
|
614
|
-
* hello carries the session key, so a content dump here would hand both to any
|
|
615
|
-
* crash reporter watching the host console.
|
|
616
|
-
*/
|
|
617
|
-
const frameType = (frame) => {
|
|
618
|
-
if (frame && typeof frame === 'object') {
|
|
619
|
-
const candidate = frame.type;
|
|
620
|
-
if (typeof candidate === 'string' && candidate.length > 0)
|
|
621
|
-
return candidate;
|
|
622
|
-
if (Array.isArray(frame.requests))
|
|
623
|
-
return 'task_batch';
|
|
624
|
-
}
|
|
625
|
-
return 'unknown';
|
|
626
|
-
};
|
|
627
525
|
class WebSocketClient {
|
|
628
526
|
constructor(options) {
|
|
629
527
|
this.options = options;
|
|
630
528
|
this.logger = getLogger();
|
|
631
529
|
this.pingTimer = null;
|
|
530
|
+
this.consoleWithVerbose = console;
|
|
632
531
|
this.handleOpen = () => {
|
|
633
532
|
this.logger.info('WebSocket connection opened');
|
|
634
533
|
this.options.onOpen?.();
|
|
534
|
+
this.logger.debug('Sending hello message:', this.options.hello);
|
|
535
|
+
this.logger.info('[WS OUT] hello:', JSON.stringify(this.options.hello));
|
|
635
536
|
this.send(this.options.hello);
|
|
636
537
|
// Keepalive starts only once the hello is on the wire.
|
|
637
538
|
this.startPing();
|
|
638
539
|
if (this.options.ack) {
|
|
639
540
|
// Send readiness/error ack immediately after hello.
|
|
541
|
+
this.logger.info('[WS OUT] hello_ack:', JSON.stringify(this.options.ack));
|
|
640
542
|
this.send(this.options.ack);
|
|
641
543
|
if (this.options.closeAfterAck) {
|
|
642
544
|
// Optionally close after ack (used for error cases).
|
|
@@ -658,23 +560,24 @@ class WebSocketClient {
|
|
|
658
560
|
if (trimmed === 'pong')
|
|
659
561
|
return;
|
|
660
562
|
if (trimmed.length > 0 && trimmed[0] !== '{' && trimmed[0] !== '[') {
|
|
661
|
-
this.logger.debug('[WS IN] ignoring non-JSON frame',
|
|
563
|
+
this.logger.debug('[WS IN] ignoring non-JSON frame:', trimmed.slice(0, 64));
|
|
662
564
|
return;
|
|
663
565
|
}
|
|
664
566
|
}
|
|
665
567
|
try {
|
|
666
568
|
const data = JSON.parse(raw);
|
|
667
|
-
this.logger.
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
569
|
+
if (this.logger.isEnabled()) {
|
|
570
|
+
if (typeof this.consoleWithVerbose.verbose === 'function') {
|
|
571
|
+
this.consoleWithVerbose.verbose('[ZeroGPU]', '[WS IN] payload:', data);
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
console.debug('[ZeroGPU]', '[WS IN] payload:', data);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
674
577
|
this.options.onMessage(data);
|
|
675
578
|
}
|
|
676
579
|
catch (error) {
|
|
677
|
-
this.logger.error('Failed to parse WS message',
|
|
580
|
+
this.logger.error('Failed to parse WS message', error);
|
|
678
581
|
}
|
|
679
582
|
};
|
|
680
583
|
this.handleError = (event) => {
|
|
@@ -699,7 +602,7 @@ class WebSocketClient {
|
|
|
699
602
|
this.options.onClose(event);
|
|
700
603
|
};
|
|
701
604
|
this.pingIntervalMs = normalizePingIntervalMs(options.pingIntervalSeconds);
|
|
702
|
-
this.logger.info('Creating WebSocket connection',
|
|
605
|
+
this.logger.info('Creating WebSocket connection to:', options.url);
|
|
703
606
|
this.socket = new WebSocket(options.url);
|
|
704
607
|
this.socket.onopen = this.handleOpen;
|
|
705
608
|
this.socket.onmessage = this.handleMessage;
|
|
@@ -733,7 +636,7 @@ class WebSocketClient {
|
|
|
733
636
|
this.socket.send('ping');
|
|
734
637
|
}
|
|
735
638
|
catch (error) {
|
|
736
|
-
this.logger.debug('Keepalive ping failed',
|
|
639
|
+
this.logger.debug('Keepalive ping failed', error);
|
|
737
640
|
}
|
|
738
641
|
try {
|
|
739
642
|
this.options.onPingTick?.();
|
|
@@ -753,13 +656,8 @@ class WebSocketClient {
|
|
|
753
656
|
return (this.socket.readyState === WebSocket.OPEN || this.socket.readyState === WebSocket.CONNECTING);
|
|
754
657
|
}
|
|
755
658
|
send(payload) {
|
|
756
|
-
|
|
757
|
-
this.
|
|
758
|
-
type: frameType(payload),
|
|
759
|
-
requests: Array.isArray(payload.requests) ? payload.requests.length : undefined,
|
|
760
|
-
bytes: json.length
|
|
761
|
-
});
|
|
762
|
-
this.socket.send(json);
|
|
659
|
+
this.logger.debug('[WS OUT] payload:', JSON.stringify(payload));
|
|
660
|
+
this.socket.send(JSON.stringify(payload));
|
|
763
661
|
}
|
|
764
662
|
close(code, reason) {
|
|
765
663
|
this.stopPing();
|
|
@@ -1336,7 +1234,8 @@ const resolveWasmSettings = (probe = probeWasmEnvironment()) => {
|
|
|
1336
1234
|
* Host-facing lifecycle status and events. The SDK is a guest in someone
|
|
1337
1235
|
* else's app: this module is how the host observes guardrail state (degraded /
|
|
1338
1236
|
* recovered / shutdown) without the SDK ever throwing into it. Script-tag
|
|
1339
|
-
* consumers get the same signals as `zerogpu:*` window events
|
|
1237
|
+
* consumers get the same signals as `zerogpu:*` window events, matching the
|
|
1238
|
+
* existing `zerogpu:cameraPreview` pattern.
|
|
1340
1239
|
*/
|
|
1341
1240
|
let lifecycleStatus = 'starting';
|
|
1342
1241
|
const listeners = {
|
|
@@ -2176,7 +2075,7 @@ const executeSingleRequest = async (request) => {
|
|
|
2176
2075
|
};
|
|
2177
2076
|
}
|
|
2178
2077
|
catch (error) {
|
|
2179
|
-
logger.error('Task failed',
|
|
2078
|
+
logger.error('Task failed', error);
|
|
2180
2079
|
const message = error.message ?? '';
|
|
2181
2080
|
const isAllocationFailure = error instanceof RangeError || /out of memory|oom|wasm.*abort|allocation failed/i.test(message);
|
|
2182
2081
|
getEventReporter().report('task.failed', {
|
|
@@ -2255,15 +2154,12 @@ const handleIncomingMessage = async (msg) => {
|
|
|
2255
2154
|
const results = [];
|
|
2256
2155
|
for (const request of msg.requests) {
|
|
2257
2156
|
const result = await executeSingleRequest(request);
|
|
2258
|
-
|
|
2259
|
-
// and must never reach the console — log its size instead.
|
|
2260
|
-
logger.info('[WS OUT] task result', {
|
|
2157
|
+
logger.info('[WS OUT] task result:', {
|
|
2261
2158
|
requestId: result.requestId,
|
|
2262
2159
|
modelId: result.modelId,
|
|
2263
|
-
|
|
2264
|
-
processingTimeMs: result.metadata.processingTime,
|
|
2160
|
+
response: result.response,
|
|
2265
2161
|
error: result.error,
|
|
2266
|
-
errorMessage: result.errorMessage
|
|
2162
|
+
errorMessage: result.errorMessage
|
|
2267
2163
|
});
|
|
2268
2164
|
results.push(result);
|
|
2269
2165
|
}
|
|
@@ -2755,7 +2651,7 @@ const scheduleReconnect = (options, reason) => {
|
|
|
2755
2651
|
}
|
|
2756
2652
|
logger.info('[WS] Re-registration timer fired; restarting lifecycle');
|
|
2757
2653
|
startLifecycle(options).catch((err) => {
|
|
2758
|
-
logger.error('[WS] Re-registration attempt failed; will retry',
|
|
2654
|
+
logger.error('[WS] Re-registration attempt failed; will retry', err);
|
|
2759
2655
|
// Keep the loop alive on transient failures (register/network/model
|
|
2760
2656
|
// errors). Auth failures and crash-loop cool-downs return cleanly from
|
|
2761
2657
|
// startLifecycle without throwing, so they end the loop here.
|
|
@@ -2783,7 +2679,7 @@ const triggerFullReregister = (options, reason) => {
|
|
|
2783
2679
|
// Best effort — the register flow below supersedes the session anyway.
|
|
2784
2680
|
}
|
|
2785
2681
|
startLifecycle(options).catch((err) => {
|
|
2786
|
-
logger.error('[WS] Full re-register failed; scheduling retry',
|
|
2682
|
+
logger.error('[WS] Full re-register failed; scheduling retry', err);
|
|
2787
2683
|
scheduleReconnect(options, 'socket_closed');
|
|
2788
2684
|
});
|
|
2789
2685
|
};
|
|
@@ -2819,7 +2715,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
2819
2715
|
};
|
|
2820
2716
|
// Deterministic preflight validation runs before the crash-loop guard so a
|
|
2821
2717
|
// misconfigured integration never consumes a crash-loop attempt (and never
|
|
2822
|
-
// triggers the
|
|
2718
|
+
// triggers the camera/geo prompts below).
|
|
2823
2719
|
if (!edgeOperatorKey) {
|
|
2824
2720
|
throw new Error('Missing required header: x-edge-operator-key');
|
|
2825
2721
|
}
|
|
@@ -2854,24 +2750,39 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
2854
2750
|
providedDeviceId: Boolean(providedDeviceId),
|
|
2855
2751
|
orchestrator: config.orchestrator?.baseUrl
|
|
2856
2752
|
});
|
|
2857
|
-
const
|
|
2858
|
-
|
|
2753
|
+
const rawDeviceInfo = await collectDeviceInfo(config.telemetry, appUserId, deviceId);
|
|
2754
|
+
const sanitizedDeviceInfo = stripCameraPreview(rawDeviceInfo);
|
|
2755
|
+
setDeviceContext(deviceId, sanitizedDeviceInfo);
|
|
2859
2756
|
initEventReporter({
|
|
2860
2757
|
enabled: config.telemetry.events,
|
|
2861
2758
|
endpointUrl: `${config.orchestrator.baseUrl}${config.orchestrator.eventsPath}`,
|
|
2862
2759
|
operatorKey: edgeOperatorKey,
|
|
2863
2760
|
deviceId,
|
|
2864
2761
|
sdkVersion: config.sdkVersion,
|
|
2865
|
-
platform:
|
|
2762
|
+
platform: sanitizedDeviceInfo.platform
|
|
2866
2763
|
});
|
|
2867
2764
|
const reporter = getEventReporter();
|
|
2868
2765
|
reporter.report('sdk.init_started', { data: { sdkVersion: config.sdkVersion } });
|
|
2869
2766
|
reportCrashFromPreviousSession(guard.crash);
|
|
2870
2767
|
logger.info('[Init] Device info collected', {
|
|
2871
|
-
platform:
|
|
2872
|
-
deviceType:
|
|
2873
|
-
gpuRenderer:
|
|
2768
|
+
platform: sanitizedDeviceInfo.platform,
|
|
2769
|
+
deviceType: sanitizedDeviceInfo.deviceType,
|
|
2770
|
+
gpuRenderer: sanitizedDeviceInfo.gpuRenderer
|
|
2874
2771
|
});
|
|
2772
|
+
if (rawDeviceInfo.camera?.previewDataUrl) {
|
|
2773
|
+
try {
|
|
2774
|
+
window.dispatchEvent(new CustomEvent('zerogpu:cameraPreview', {
|
|
2775
|
+
detail: {
|
|
2776
|
+
deviceId,
|
|
2777
|
+
previewDataUrl: rawDeviceInfo.camera.previewDataUrl,
|
|
2778
|
+
camera: sanitizedDeviceInfo.camera
|
|
2779
|
+
}
|
|
2780
|
+
}));
|
|
2781
|
+
}
|
|
2782
|
+
catch {
|
|
2783
|
+
logger.warn('Unable to dispatch camera preview event');
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2875
2786
|
const cachedModelId = isFreshDevice ? null : getCachedModelId();
|
|
2876
2787
|
setCachedModelId(cachedModelId);
|
|
2877
2788
|
let cachedInfo = cachedModelId ? getCachedModelInfo(cachedModelId) : null;
|
|
@@ -3045,7 +2956,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3045
2956
|
cachedModels: cachedInfo && !cacheInvalid
|
|
3046
2957
|
? [{ modelId: cachedInfo.modelId, modelVersion: cachedInfo.modelVersion || '1' }]
|
|
3047
2958
|
: [],
|
|
3048
|
-
device:
|
|
2959
|
+
device: sanitizedDeviceInfo
|
|
3049
2960
|
};
|
|
3050
2961
|
let registerResponse;
|
|
3051
2962
|
let assignedModels = [];
|
|
@@ -3056,7 +2967,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3056
2967
|
let postRegisterSample;
|
|
3057
2968
|
logger.info('[Register] Sending register request', {
|
|
3058
2969
|
deviceId,
|
|
3059
|
-
cachedModels: registerPayload.cachedModels
|
|
2970
|
+
cachedModels: registerPayload.cachedModels,
|
|
3060
2971
|
sdkVersion: config.sdkVersion
|
|
3061
2972
|
});
|
|
3062
2973
|
reporter.report('register.started');
|
|
@@ -3107,10 +3018,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3107
3018
|
// TODO(global-types): emit ws.policy_applied once available in the shared
|
|
3108
3019
|
// event vocabulary (data: {source: 'register', v, changed}).
|
|
3109
3020
|
if (registrationSettings) {
|
|
3110
|
-
|
|
3111
|
-
logger.info('[Register] Registration settings received', {
|
|
3112
|
-
keys: Object.keys(registrationSettings)
|
|
3113
|
-
});
|
|
3021
|
+
logger.info('[Register] Registration settings received', registrationSettings);
|
|
3114
3022
|
}
|
|
3115
3023
|
if (registerResponse.refusalReason) {
|
|
3116
3024
|
// The server deliberately declined this device (admission rules) — the
|
|
@@ -3129,7 +3037,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3129
3037
|
reporter.report('register.succeeded', { durationMs: Math.round(performance.now() - registerStartedAt) });
|
|
3130
3038
|
markRegisterSuccess();
|
|
3131
3039
|
reporter.setSessionKey(registerResponse.sessionKey);
|
|
3132
|
-
logger.info('Register response received', {
|
|
3040
|
+
logger.info('Register response received:', {
|
|
3133
3041
|
deviceId: registerResponse.deviceId,
|
|
3134
3042
|
wsUrl: registerResponse.wsUrl
|
|
3135
3043
|
});
|
|
@@ -3148,8 +3056,13 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3148
3056
|
}
|
|
3149
3057
|
logger.info('[Register] Models assigned', {
|
|
3150
3058
|
count: assignedModels.length,
|
|
3151
|
-
models: assignedModels.map((m) =>
|
|
3152
|
-
|
|
3059
|
+
models: assignedModels.map((m) => ({
|
|
3060
|
+
modelId: m.modelId,
|
|
3061
|
+
framework: m.inferenceFramework,
|
|
3062
|
+
taskType: m.taskType,
|
|
3063
|
+
quantized: m.quantized,
|
|
3064
|
+
sizeBytes: m.sizeBytes
|
|
3065
|
+
}))
|
|
3153
3066
|
});
|
|
3154
3067
|
for (const model of assignedModels) {
|
|
3155
3068
|
modelStatuses[getModelStatusKey(model)] = 'idle';
|
|
@@ -3167,10 +3080,10 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3167
3080
|
setModelInfosByModelId(modelInfosByModelId);
|
|
3168
3081
|
setModelInfo(primaryModel);
|
|
3169
3082
|
setSample(primaryModel.sample);
|
|
3170
|
-
// ZGA-538: no session key (credential) and no sample body (task content).
|
|
3171
3083
|
logger.info('Runtime globals updated from register response', {
|
|
3084
|
+
sessionKey: registerResponse.sessionKey,
|
|
3172
3085
|
taskType: primaryModel.taskType,
|
|
3173
|
-
|
|
3086
|
+
sample: primaryModel.sample
|
|
3174
3087
|
});
|
|
3175
3088
|
if (!cachedInfo || cachedInfo.modelId !== primaryModel.modelId || cacheInvalid) {
|
|
3176
3089
|
if (cachedInfo && cachedInfo.modelId !== primaryModel.modelId) {
|
|
@@ -3443,7 +3356,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3443
3356
|
};
|
|
3444
3357
|
logger.info('[WS] Connecting WebSocket', {
|
|
3445
3358
|
wsUrl: registerResponse.wsUrl,
|
|
3446
|
-
models: helloSlmConfig
|
|
3359
|
+
models: helloSlmConfig
|
|
3447
3360
|
});
|
|
3448
3361
|
reporter.report('ws.connect_started');
|
|
3449
3362
|
const connectionPolicy = getConnectionPolicy();
|
|
@@ -3474,12 +3387,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3474
3387
|
}
|
|
3475
3388
|
else if ('type' in message && message.type === 'hello_ack') {
|
|
3476
3389
|
const ack = message;
|
|
3477
|
-
|
|
3478
|
-
logger.info('[WS] Received hello_ack', {
|
|
3479
|
-
status: ack.status,
|
|
3480
|
-
deviceId: ack.deviceId,
|
|
3481
|
-
errorMessage: ack.errorMessage
|
|
3482
|
-
});
|
|
3390
|
+
logger.info('[WS] Received hello_ack', ack);
|
|
3483
3391
|
reporter.report('ws.hello_ack', {
|
|
3484
3392
|
code: ack.status,
|
|
3485
3393
|
message: ack.errorMessage
|
|
@@ -3522,9 +3430,7 @@ const startLifecycle = async ({ config, appUserId, edgeOperatorKey, deviceId: pr
|
|
|
3522
3430
|
}, delayMs);
|
|
3523
3431
|
}
|
|
3524
3432
|
else {
|
|
3525
|
-
logger.debug('[WS] Unhandled message',
|
|
3526
|
-
type: 'type' in message && typeof message.type === 'string' ? message.type : 'unknown'
|
|
3527
|
-
});
|
|
3433
|
+
logger.debug('[WS] Unhandled message', message);
|
|
3528
3434
|
}
|
|
3529
3435
|
},
|
|
3530
3436
|
onClose: (event) => {
|
|
@@ -3776,6 +3682,15 @@ const reportInitFailureOverWebSocket = async (options) => {
|
|
|
3776
3682
|
}
|
|
3777
3683
|
});
|
|
3778
3684
|
};
|
|
3685
|
+
const stripCameraPreview = (info) => {
|
|
3686
|
+
if (!info.camera?.previewDataUrl) {
|
|
3687
|
+
return info;
|
|
3688
|
+
}
|
|
3689
|
+
return {
|
|
3690
|
+
...info,
|
|
3691
|
+
camera: { ...info.camera, previewDataUrl: undefined }
|
|
3692
|
+
};
|
|
3693
|
+
};
|
|
3779
3694
|
|
|
3780
3695
|
const measure = async (fn) => {
|
|
3781
3696
|
const start = performance.now();
|
|
@@ -3785,6 +3700,12 @@ const measure = async (fn) => {
|
|
|
3785
3700
|
|
|
3786
3701
|
const TRANSFORMERS_CDN = 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2/dist/transformers.min.js';
|
|
3787
3702
|
let transformersRuntimePromise = null;
|
|
3703
|
+
const serializeError$5 = (error) => {
|
|
3704
|
+
if (error instanceof Error) {
|
|
3705
|
+
return { name: error.name, message: error.message, stack: error.stack };
|
|
3706
|
+
}
|
|
3707
|
+
return { message: String(error) };
|
|
3708
|
+
};
|
|
3788
3709
|
const ensureTransformersRuntime = () => {
|
|
3789
3710
|
if (window.TransformersPipeline) {
|
|
3790
3711
|
return Promise.resolve();
|
|
@@ -3820,7 +3741,7 @@ const ensureTransformersRuntime = () => {
|
|
|
3820
3741
|
transformersRuntimePromise = null;
|
|
3821
3742
|
logger.error('[SLM] Failed to import Transformers runtime', {
|
|
3822
3743
|
runtimeUrl: TRANSFORMERS_CDN,
|
|
3823
|
-
error:
|
|
3744
|
+
error: serializeError$5(error)
|
|
3824
3745
|
});
|
|
3825
3746
|
throw error;
|
|
3826
3747
|
}
|
|
@@ -3929,7 +3850,7 @@ const probeOnnxWasmOverridePath = async (fetchImpl) => {
|
|
|
3929
3850
|
}
|
|
3930
3851
|
if (sawNonWasmPayloadAtBase) {
|
|
3931
3852
|
getLogger().warn('[SLM] ONNX wasm probe got non-wasm payload', {
|
|
3932
|
-
|
|
3853
|
+
wasmBase: baseWithSlash
|
|
3933
3854
|
});
|
|
3934
3855
|
}
|
|
3935
3856
|
}
|
|
@@ -3957,6 +3878,12 @@ const withTransformersEnvLock = async (work) => {
|
|
|
3957
3878
|
}
|
|
3958
3879
|
};
|
|
3959
3880
|
|
|
3881
|
+
const serializeError$4 = (error) => {
|
|
3882
|
+
if (error instanceof Error) {
|
|
3883
|
+
return { name: error.name, message: error.message, stack: error.stack };
|
|
3884
|
+
}
|
|
3885
|
+
return { message: String(error) };
|
|
3886
|
+
};
|
|
3960
3887
|
const sessionCache = {};
|
|
3961
3888
|
const createEnvFetch = (modelId, fileBase, cachedFiles, onFileDownloaded, requiredFiles, originalFetch) => {
|
|
3962
3889
|
const requiredFileList = requiredFiles
|
|
@@ -4056,7 +3983,7 @@ const createEnvFetch = (modelId, fileBase, cachedFiles, onFileDownloaded, requir
|
|
|
4056
3983
|
logger.error('[SLM][fetch] non-model wasm/ort request failed', {
|
|
4057
3984
|
modelId,
|
|
4058
3985
|
requestUrl: originalRequestUrl,
|
|
4059
|
-
error:
|
|
3986
|
+
error: serializeError$4(error)
|
|
4060
3987
|
});
|
|
4061
3988
|
throw error;
|
|
4062
3989
|
}
|
|
@@ -4064,7 +3991,7 @@ const createEnvFetch = (modelId, fileBase, cachedFiles, onFileDownloaded, requir
|
|
|
4064
3991
|
const relative = resolveRequestedRelative(requestedRelative);
|
|
4065
3992
|
if (!relative) {
|
|
4066
3993
|
logger.warn('[SLM] Unexpected model file request; falling back to original fetch', {
|
|
4067
|
-
|
|
3994
|
+
requestedRelative,
|
|
4068
3995
|
modelId
|
|
4069
3996
|
});
|
|
4070
3997
|
return originalFetch(url, init);
|
|
@@ -4112,11 +4039,10 @@ const createEnvFetch = (modelId, fileBase, cachedFiles, onFileDownloaded, requir
|
|
|
4112
4039
|
// That string means "every candidate URL threw", i.e. a network/abort
|
|
4113
4040
|
// failure against the real model host — not an upstream 502 and not a
|
|
4114
4041
|
// malformed URL actually being requested.
|
|
4115
|
-
logger.warn(
|
|
4042
|
+
logger.warn(`[SLM] Model file fetch failed for ${relative}`, {
|
|
4116
4043
|
modelId,
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
error: summarizeError(err)
|
|
4044
|
+
candidates: requestUrls,
|
|
4045
|
+
error: serializeError$4(err)
|
|
4120
4046
|
});
|
|
4121
4047
|
return new Response('model_file_fetch_failed', { status: 502, statusText: 'Bad Gateway' });
|
|
4122
4048
|
}
|
|
@@ -4129,6 +4055,12 @@ const TASK_PIPELINE_MAP = {
|
|
|
4129
4055
|
classification: 'zero-shot-classification',
|
|
4130
4056
|
text_generation: 'text2text-generation'
|
|
4131
4057
|
};
|
|
4058
|
+
const serializeError$3 = (error) => {
|
|
4059
|
+
if (error instanceof Error) {
|
|
4060
|
+
return { name: error.name, message: error.message, stack: error.stack };
|
|
4061
|
+
}
|
|
4062
|
+
return { message: String(error) };
|
|
4063
|
+
};
|
|
4132
4064
|
const isInvalidArrayLengthError = (error) => {
|
|
4133
4065
|
const message = error instanceof Error ? error.message : String(error);
|
|
4134
4066
|
return message.toLowerCase().includes('invalid array length');
|
|
@@ -4500,7 +4432,7 @@ const loadOnnxAdapter = async (slm, options) => {
|
|
|
4500
4432
|
modelRepoId: slm.modelRepoId,
|
|
4501
4433
|
modelUrl: slm.modelUrl,
|
|
4502
4434
|
requiredFiles: (slm.requiredFiles ?? []).map((file) => file.name),
|
|
4503
|
-
error:
|
|
4435
|
+
error: serializeError$3(error)
|
|
4504
4436
|
});
|
|
4505
4437
|
await clearModel(slm.modelId, slm.modelVersion).catch(() => { });
|
|
4506
4438
|
return { error: error, metrics: {} };
|
|
@@ -4521,6 +4453,12 @@ registerAdapter(factory$2);
|
|
|
4521
4453
|
|
|
4522
4454
|
const DEFAULT_THRESHOLD = 0.4;
|
|
4523
4455
|
const DEFAULT_MASK = '[REDACTED]';
|
|
4456
|
+
const serializeError$2 = (error) => {
|
|
4457
|
+
if (error instanceof Error) {
|
|
4458
|
+
return { name: error.name, message: error.message, stack: error.stack };
|
|
4459
|
+
}
|
|
4460
|
+
return { message: String(error) };
|
|
4461
|
+
};
|
|
4524
4462
|
const parseTokenClassificationOutput = (raw, sourceText) => {
|
|
4525
4463
|
if (!Array.isArray(raw))
|
|
4526
4464
|
return [];
|
|
@@ -4783,7 +4721,7 @@ const loadTransformersAdapter = async (slm, options) => {
|
|
|
4783
4721
|
modelVersion: slm.modelVersion,
|
|
4784
4722
|
modelRepoId: slm.modelRepoId,
|
|
4785
4723
|
modelUrl: slm.modelUrl,
|
|
4786
|
-
error:
|
|
4724
|
+
error: serializeError$2(error)
|
|
4787
4725
|
});
|
|
4788
4726
|
await clearModel(slm.modelId, slm.modelVersion).catch(() => { });
|
|
4789
4727
|
return { error: error, metrics: {} };
|
|
@@ -4802,6 +4740,12 @@ registerAdapter(factory$1);
|
|
|
4802
4740
|
|
|
4803
4741
|
const WLLAMA_CDN = 'https://cdn.jsdelivr.net/npm/@wllama/wllama@2.3.5/esm/index.js';
|
|
4804
4742
|
let wllamaRuntimePromise = null;
|
|
4743
|
+
const serializeError$1 = (error) => {
|
|
4744
|
+
if (error instanceof Error) {
|
|
4745
|
+
return { name: error.name, message: error.message, stack: error.stack };
|
|
4746
|
+
}
|
|
4747
|
+
return { message: String(error) };
|
|
4748
|
+
};
|
|
4805
4749
|
const ensureWllamaRuntime = () => {
|
|
4806
4750
|
if (window.WllamaModule) {
|
|
4807
4751
|
return Promise.resolve(window.WllamaModule);
|
|
@@ -4820,7 +4764,7 @@ const ensureWllamaRuntime = () => {
|
|
|
4820
4764
|
wllamaRuntimePromise = null;
|
|
4821
4765
|
getLogger().error('[GGUF] Failed to import wllama runtime', {
|
|
4822
4766
|
runtimeUrl: WLLAMA_CDN,
|
|
4823
|
-
error:
|
|
4767
|
+
error: serializeError$1(error)
|
|
4824
4768
|
});
|
|
4825
4769
|
throw error;
|
|
4826
4770
|
}
|
|
@@ -4831,6 +4775,12 @@ const ensureWllamaRuntime = () => {
|
|
|
4831
4775
|
const WLLAMA_CDN_BASE = WLLAMA_CDN.replace(/\/esm\/index\.js$/, '/esm');
|
|
4832
4776
|
|
|
4833
4777
|
const DEFAULT_MAX_NEW_TOKENS = 128;
|
|
4778
|
+
const serializeError = (error) => {
|
|
4779
|
+
if (error instanceof Error) {
|
|
4780
|
+
return { name: error.name, message: error.message, stack: error.stack };
|
|
4781
|
+
}
|
|
4782
|
+
return { message: String(error) };
|
|
4783
|
+
};
|
|
4834
4784
|
const pickGgufFileName = (requiredFiles) => {
|
|
4835
4785
|
if (!Array.isArray(requiredFiles) || requiredFiles.length === 0)
|
|
4836
4786
|
return null;
|
|
@@ -5035,7 +4985,7 @@ const loadGgufAdapter = async (slm, options) => {
|
|
|
5035
4985
|
modelId: slm.modelId,
|
|
5036
4986
|
modelVersion: slm.modelVersion,
|
|
5037
4987
|
modelUrl: slm.modelUrl,
|
|
5038
|
-
error:
|
|
4988
|
+
error: serializeError(error)
|
|
5039
4989
|
});
|
|
5040
4990
|
await clearModel(slm.modelId, slm.modelVersion).catch(() => { });
|
|
5041
4991
|
return { error: error, metrics: {} };
|
|
@@ -5075,9 +5025,7 @@ const initZeroGpuSdk = async (options) => {
|
|
|
5075
5025
|
if (options?.resourcePolicy) {
|
|
5076
5026
|
setResourcePolicy(options.resourcePolicy);
|
|
5077
5027
|
if (options.resourcePolicy.disableGuardrails) {
|
|
5078
|
-
// Loud by design: a host running without guardrails should know it
|
|
5079
|
-
// with console logs disabled. Static text only — nothing to redact.
|
|
5080
|
-
// eslint-disable-next-line no-console
|
|
5028
|
+
// Loud by design: a host running without guardrails should know it.
|
|
5081
5029
|
console.warn('[ZeroGPU] resourcePolicy.disableGuardrails is set — ALL memory/storage/battery guardrails are OFF. Lab use only.');
|
|
5082
5030
|
}
|
|
5083
5031
|
}
|
|
@@ -5093,7 +5041,7 @@ const initZeroGpuSdk = async (options) => {
|
|
|
5093
5041
|
catch (err) {
|
|
5094
5042
|
// Already reported inside the lifecycle (register.failed / sdk.init_failed
|
|
5095
5043
|
// / init-failure hello); surface for the host without throwing into it.
|
|
5096
|
-
getLogger().error('[Init] SDK initialization failed',
|
|
5044
|
+
getLogger().error('[Init] SDK initialization failed', err);
|
|
5097
5045
|
}
|
|
5098
5046
|
return handle;
|
|
5099
5047
|
};
|
|
@@ -5215,9 +5163,7 @@ const autoInitFromScriptTag = () => {
|
|
|
5215
5163
|
// the integrator asked for logs — the failure is reported as an
|
|
5216
5164
|
// `sdk.init_failed` device event regardless.
|
|
5217
5165
|
if (enableConsoleLogs) {
|
|
5218
|
-
|
|
5219
|
-
// eslint-disable-next-line no-console
|
|
5220
|
-
console.error('[ZeroGpuSdk] Auto-init failed', error instanceof Error ? `${error.name}: ${error.message}` : String(error));
|
|
5166
|
+
console.error('[ZeroGpuSdk] Auto-init failed', error);
|
|
5221
5167
|
}
|
|
5222
5168
|
});
|
|
5223
5169
|
};
|