@zerogpu/browser-extension-sdk 0.2.0 → 0.2.1-dev.202607301617.g61d37c5
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/zerogpu-assets.json +3 -3
- package/dist/extension/zerogpu-offscreen.js +80 -36
- package/dist/extension/zerogpu-offscreen.js.map +1 -1
- package/dist/loader.js +1 -1
- package/dist/loader.js.map +1 -1
- package/dist/manifest.json +6 -6
- package/dist/types/adapters/gguf/runtime.d.ts +17 -3
- package/dist/types/adapters/onnx/runtime.d.ts +30 -2
- package/dist/types/config/env.d.ts +1 -1
- package/dist/types/device/browser-globals.d.ts +54 -0
- package/dist/types/loader.d.ts +13 -1
- package/dist/v/{zerogpu-browser-sdk.af4825958dcb.umd.js → zerogpu-browser-sdk.f232041bce9b.umd.js} +65 -26
- package/dist/v/zerogpu-browser-sdk.f232041bce9b.umd.js.map +1 -0
- package/dist/zerogpu-browser-sdk.cjs +64 -25
- package/dist/zerogpu-browser-sdk.cjs.map +1 -1
- package/dist/zerogpu-browser-sdk.esm.js +64 -25
- package/dist/zerogpu-browser-sdk.esm.js.map +1 -1
- package/dist/zerogpu-browser-sdk.umd.js +64 -25
- package/dist/zerogpu-browser-sdk.umd.js.map +1 -1
- package/package.json +2 -2
- package/dist/v/zerogpu-browser-sdk.af4825958dcb.umd.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"sdkVersion": "0.2.
|
|
3
|
-
"channel": "
|
|
2
|
+
"sdkVersion": "0.2.1-dev.202607301617.g61d37c5+61d37c5",
|
|
3
|
+
"channel": "development",
|
|
4
4
|
"transformersVersion": "2.17.2",
|
|
5
5
|
"wllamaVersion": "2.3.5",
|
|
6
6
|
"files": [
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"wllama/single-thread/wllama.wasm",
|
|
15
15
|
"wllama/multi-thread/wllama.wasm"
|
|
16
16
|
],
|
|
17
|
-
"builtAt": "2026-07-
|
|
17
|
+
"builtAt": "2026-07-30T16:18:26.779Z"
|
|
18
18
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const SDK_VERSION = typeof "0.2.
|
|
2
|
-
? "0.2.
|
|
1
|
+
const SDK_VERSION = typeof "0.2.1-dev.202607301617.g61d37c5+61d37c5" === 'string' && "0.2.1-dev.202607301617.g61d37c5+61d37c5".length > 0
|
|
2
|
+
? "0.2.1-dev.202607301617.g61d37c5+61d37c5"
|
|
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
|
|
@@ -46,7 +46,11 @@ const resolveConfig = (overrides) => {
|
|
|
46
46
|
};
|
|
47
47
|
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
48
|
const deepMerge = (target, source) => {
|
|
49
|
-
|
|
49
|
+
// Structural clone first, then index it as a plain bag. `T extends object`
|
|
50
|
+
// admits interfaces without index signatures (SdkConfig is one), so the cast
|
|
51
|
+
// is what lets us walk it by key — the `as T` on the way out restores the
|
|
52
|
+
// caller's type, which the per-field validators below re-check anyway.
|
|
53
|
+
const result = (Array.isArray(target) ? [...target] : { ...target });
|
|
50
54
|
for (const key of Object.keys(source)) {
|
|
51
55
|
const srcValue = source[key];
|
|
52
56
|
if (srcValue === undefined)
|
|
@@ -144,9 +148,27 @@ const setDeviceId = (deviceId) => {
|
|
|
144
148
|
setStoredDeviceId(deviceId);
|
|
145
149
|
};
|
|
146
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Typed accessors for the non-standard browser surfaces this SDK reads.
|
|
153
|
+
*
|
|
154
|
+
* None of these are in TypeScript's DOM lib: the Telegram Mini App bridge is
|
|
155
|
+
* injected by the host, and `userAgentData` / `deviceMemory` / `getBattery` /
|
|
156
|
+
* `connection` are all optional vendor extensions that may be absent on any
|
|
157
|
+
* given engine. Declaring them here once — rather than casting to `any` at each
|
|
158
|
+
* read — keeps the optionality visible at the call site, which matters because
|
|
159
|
+
* every one of these fields feeds a guardrail decision.
|
|
160
|
+
*/
|
|
161
|
+
const extendedNavigator = () => navigator;
|
|
162
|
+
/** The injected Telegram bridge, or undefined when not running inside a Mini App. */
|
|
163
|
+
const telegramWebApp = () => {
|
|
164
|
+
if (typeof window === 'undefined')
|
|
165
|
+
return undefined;
|
|
166
|
+
return window.Telegram?.WebApp;
|
|
167
|
+
};
|
|
168
|
+
|
|
147
169
|
const getPlatform = () => {
|
|
148
170
|
const ua = navigator.userAgent.toLowerCase();
|
|
149
|
-
const tg =
|
|
171
|
+
const tg = telegramWebApp();
|
|
150
172
|
if (tg?.platform)
|
|
151
173
|
return tg.platform;
|
|
152
174
|
if (tg)
|
|
@@ -163,7 +185,7 @@ const getPlatform = () => {
|
|
|
163
185
|
};
|
|
164
186
|
const getDeviceType = () => {
|
|
165
187
|
const ua = navigator.userAgent ?? '';
|
|
166
|
-
const uaData =
|
|
188
|
+
const uaData = extendedNavigator().userAgentData;
|
|
167
189
|
if (uaData?.mobile === true)
|
|
168
190
|
return 'mobile';
|
|
169
191
|
const isTablet = /iPad|Tablet|PlayBook|Silk/i.test(ua) || (navigator.maxTouchPoints > 1 && window.innerWidth >= 768);
|
|
@@ -188,8 +210,9 @@ const getWebGLRenderer = () => {
|
|
|
188
210
|
};
|
|
189
211
|
const getBatteryInfo = async () => {
|
|
190
212
|
try {
|
|
191
|
-
|
|
192
|
-
|
|
213
|
+
const getBattery = extendedNavigator().getBattery;
|
|
214
|
+
if (getBattery) {
|
|
215
|
+
const battery = await getBattery.call(navigator);
|
|
193
216
|
return {
|
|
194
217
|
level: battery.level,
|
|
195
218
|
charging: battery.charging
|
|
@@ -202,7 +225,8 @@ const getBatteryInfo = async () => {
|
|
|
202
225
|
return undefined;
|
|
203
226
|
};
|
|
204
227
|
const getNetworkInfo = () => {
|
|
205
|
-
const
|
|
228
|
+
const nav = extendedNavigator();
|
|
229
|
+
const conn = nav.connection || nav.mozConnection || nav.webkitConnection;
|
|
206
230
|
if (conn) {
|
|
207
231
|
return {
|
|
208
232
|
type: conn.effectiveType || 'unknown',
|
|
@@ -246,7 +270,7 @@ const parseTelegramUserFromHash = () => {
|
|
|
246
270
|
}
|
|
247
271
|
};
|
|
248
272
|
const getTelegramUser = () => {
|
|
249
|
-
const tg =
|
|
273
|
+
const tg = telegramWebApp();
|
|
250
274
|
const user = tg?.initDataUnsafe?.user;
|
|
251
275
|
if (user) {
|
|
252
276
|
return user;
|
|
@@ -263,7 +287,7 @@ const isTelegramWebAppContext = () => {
|
|
|
263
287
|
try {
|
|
264
288
|
if (typeof window === 'undefined')
|
|
265
289
|
return false;
|
|
266
|
-
if (
|
|
290
|
+
if (telegramWebApp())
|
|
267
291
|
return true;
|
|
268
292
|
return (window.location?.hash || '').includes('tgWebAppData');
|
|
269
293
|
}
|
|
@@ -273,7 +297,7 @@ const isTelegramWebAppContext = () => {
|
|
|
273
297
|
};
|
|
274
298
|
const collectDeviceInfo = async (config, appUserId, sdkDeviceId) => {
|
|
275
299
|
const screen = window.screen || { width: null, height: null };
|
|
276
|
-
const tg =
|
|
300
|
+
const tg = telegramWebApp();
|
|
277
301
|
const telegramUser = getTelegramUser();
|
|
278
302
|
const telegramFullName = telegramUser?.first_name || telegramUser?.last_name
|
|
279
303
|
? [telegramUser?.first_name, telegramUser?.last_name].filter(Boolean).join(' ')
|
|
@@ -299,7 +323,7 @@ const collectDeviceInfo = async (config, appUserId, sdkDeviceId) => {
|
|
|
299
323
|
themeParams: tg?.themeParams,
|
|
300
324
|
// Hardware
|
|
301
325
|
cpuCores: navigator.hardwareConcurrency || 1,
|
|
302
|
-
memoryGb:
|
|
326
|
+
memoryGb: extendedNavigator().deviceMemory,
|
|
303
327
|
gpuRenderer: getWebGLRenderer(),
|
|
304
328
|
webglFingerprint: getWebGLRenderer(), // Using renderer as simple fingerprint for now
|
|
305
329
|
screen: {
|
|
@@ -3200,7 +3224,7 @@ const ensureTransformersRuntime = () => {
|
|
|
3200
3224
|
}
|
|
3201
3225
|
catch (error) {
|
|
3202
3226
|
transformersRuntimePromise = null;
|
|
3203
|
-
|
|
3227
|
+
logger.error('[SLM] Failed to import Transformers runtime', {
|
|
3204
3228
|
runtimeUrl: TRANSFORMERS_CDN,
|
|
3205
3229
|
error: serializeError$5(error)
|
|
3206
3230
|
});
|
|
@@ -3310,7 +3334,7 @@ const probeOnnxWasmOverridePath = async (fetchImpl) => {
|
|
|
3310
3334
|
}
|
|
3311
3335
|
}
|
|
3312
3336
|
if (sawNonWasmPayloadAtBase) {
|
|
3313
|
-
|
|
3337
|
+
getLogger().warn('[SLM] ONNX wasm probe got non-wasm payload', {
|
|
3314
3338
|
wasmBase: baseWithSlash
|
|
3315
3339
|
});
|
|
3316
3340
|
}
|
|
@@ -3441,7 +3465,7 @@ const createEnvFetch = (modelId, fileBase, cachedFiles, onFileDownloaded, requir
|
|
|
3441
3465
|
return await originalFetch(url, init);
|
|
3442
3466
|
}
|
|
3443
3467
|
catch (error) {
|
|
3444
|
-
|
|
3468
|
+
logger.error('[SLM][fetch] non-model wasm/ort request failed', {
|
|
3445
3469
|
modelId,
|
|
3446
3470
|
requestUrl: originalRequestUrl,
|
|
3447
3471
|
error: serializeError$4(error)
|
|
@@ -3492,7 +3516,19 @@ const createEnvFetch = (modelId, fileBase, cachedFiles, onFileDownloaded, requir
|
|
|
3492
3516
|
return new Response('required_file_not_found', { status: 404, statusText: 'Not Found' });
|
|
3493
3517
|
}
|
|
3494
3518
|
catch (err) {
|
|
3495
|
-
|
|
3519
|
+
// NOTE: this 502 is synthesised HERE — no gateway was involved. The
|
|
3520
|
+
// caller (transformers.js) reports it against the URL *it* built, which
|
|
3521
|
+
// still carries the huggingface.co prefix this fetch was installed to
|
|
3522
|
+
// replace, so the resulting message reads
|
|
3523
|
+
// "Bad gateway ... https://huggingface.co/https://models.zerogpu.ai/...".
|
|
3524
|
+
// That string means "every candidate URL threw", i.e. a network/abort
|
|
3525
|
+
// failure against the real model host — not an upstream 502 and not a
|
|
3526
|
+
// malformed URL actually being requested.
|
|
3527
|
+
logger.warn(`[SLM] Model file fetch failed for ${relative}`, {
|
|
3528
|
+
modelId,
|
|
3529
|
+
candidates: requestUrls,
|
|
3530
|
+
error: serializeError$4(err)
|
|
3531
|
+
});
|
|
3496
3532
|
return new Response('model_file_fetch_failed', { status: 502, statusText: 'Bad Gateway' });
|
|
3497
3533
|
}
|
|
3498
3534
|
};
|
|
@@ -3873,9 +3909,9 @@ const loadOnnxAdapter = async (slm, options) => {
|
|
|
3873
3909
|
catch (error) {
|
|
3874
3910
|
const message = error instanceof Error ? error.message : String(error);
|
|
3875
3911
|
if (message.includes("Unexpected token '<'")) {
|
|
3876
|
-
|
|
3912
|
+
logger.error('[SLM][loadOnnxAdapter] Parse error suggests HTML returned where JSON expected', { modelId: slm.modelId, modelUrl: slm.modelUrl });
|
|
3877
3913
|
}
|
|
3878
|
-
|
|
3914
|
+
logger.error('[SLM][loadOnnxAdapter] failed', {
|
|
3879
3915
|
modelId: slm.modelId,
|
|
3880
3916
|
modelVersion: slm.modelVersion,
|
|
3881
3917
|
modelRepoId: slm.modelRepoId,
|
|
@@ -3883,7 +3919,6 @@ const loadOnnxAdapter = async (slm, options) => {
|
|
|
3883
3919
|
requiredFiles: (slm.requiredFiles ?? []).map((file) => file.name),
|
|
3884
3920
|
error: serializeError$3(error)
|
|
3885
3921
|
});
|
|
3886
|
-
logger.error('ONNX adapter load failed', error);
|
|
3887
3922
|
await clearModel(slm.modelId, slm.modelVersion).catch(() => { });
|
|
3888
3923
|
return { error: error, metrics: {} };
|
|
3889
3924
|
}
|
|
@@ -4166,14 +4201,13 @@ const loadTransformersAdapter = async (slm, options) => {
|
|
|
4166
4201
|
return { adapter, metrics };
|
|
4167
4202
|
}
|
|
4168
4203
|
catch (error) {
|
|
4169
|
-
|
|
4204
|
+
logger.error('Transformers adapter load failed', {
|
|
4170
4205
|
modelId: slm.modelId,
|
|
4171
4206
|
modelVersion: slm.modelVersion,
|
|
4172
4207
|
modelRepoId: slm.modelRepoId,
|
|
4173
4208
|
modelUrl: slm.modelUrl,
|
|
4174
4209
|
error: serializeError$2(error)
|
|
4175
4210
|
});
|
|
4176
|
-
logger.error('Transformers adapter load failed', error);
|
|
4177
4211
|
await clearModel(slm.modelId, slm.modelVersion).catch(() => { });
|
|
4178
4212
|
return { error: error, metrics: {} };
|
|
4179
4213
|
}
|
|
@@ -4213,7 +4247,7 @@ const ensureWllamaRuntime = () => {
|
|
|
4213
4247
|
}
|
|
4214
4248
|
catch (error) {
|
|
4215
4249
|
wllamaRuntimePromise = null;
|
|
4216
|
-
|
|
4250
|
+
getLogger().error('[GGUF] Failed to import wllama runtime', {
|
|
4217
4251
|
runtimeUrl: WLLAMA_CDN,
|
|
4218
4252
|
error: serializeError$1(error)
|
|
4219
4253
|
});
|
|
@@ -4432,13 +4466,12 @@ const loadGgufAdapter = async (slm, options) => {
|
|
|
4432
4466
|
return { adapter, metrics };
|
|
4433
4467
|
}
|
|
4434
4468
|
catch (error) {
|
|
4435
|
-
|
|
4469
|
+
logger.error('GGUF adapter load failed', {
|
|
4436
4470
|
modelId: slm.modelId,
|
|
4437
4471
|
modelVersion: slm.modelVersion,
|
|
4438
4472
|
modelUrl: slm.modelUrl,
|
|
4439
4473
|
error: serializeError(error)
|
|
4440
4474
|
});
|
|
4441
|
-
logger.error('GGUF adapter load failed', error);
|
|
4442
4475
|
await clearModel(slm.modelId, slm.modelVersion).catch(() => { });
|
|
4443
4476
|
return { error: error, metrics: {} };
|
|
4444
4477
|
}
|
|
@@ -4520,12 +4553,20 @@ const resolveAssetsBaseUrl = (explicit) => {
|
|
|
4520
4553
|
return 'vendor/zerogpu/';
|
|
4521
4554
|
};
|
|
4522
4555
|
/**
|
|
4523
|
-
* Silence the bundled model runtimes'
|
|
4524
|
-
*
|
|
4525
|
-
*
|
|
4526
|
-
*
|
|
4556
|
+
* Silence the bundled model runtimes' console output. transformers.js and
|
|
4557
|
+
* onnxruntime-web write directly to the console and cannot be configured below
|
|
4558
|
+
* their own log level, so the only way to keep a host extension's console clean
|
|
4559
|
+
* is to replace the sinks for the offscreen document.
|
|
4560
|
+
*
|
|
4561
|
+
* `console.error` is included: nothing is lost by silencing it, because every
|
|
4562
|
+
* failure the SDK cares about is already reported as a device event
|
|
4563
|
+
* (`sdk.init_failed`, `model.load_failed`, `model.sample_failed`, …) and is
|
|
4564
|
+
* queryable server-side. Uncaught exceptions still reach the Errors panel.
|
|
4565
|
+
*
|
|
4566
|
+
* Applied only when console logs are disabled — pass `enableConsoleLogs: true`
|
|
4567
|
+
* to keep full verbosity while debugging.
|
|
4527
4568
|
*/
|
|
4528
|
-
const
|
|
4569
|
+
const silenceConsole = () => {
|
|
4529
4570
|
const flag = window;
|
|
4530
4571
|
if (flag.__zgpuConsoleSilenced)
|
|
4531
4572
|
return;
|
|
@@ -4535,12 +4576,13 @@ const silenceNonErrorConsole = () => {
|
|
|
4535
4576
|
console.info = noop;
|
|
4536
4577
|
console.debug = noop;
|
|
4537
4578
|
console.warn = noop;
|
|
4579
|
+
console.error = noop;
|
|
4538
4580
|
};
|
|
4539
4581
|
/** Load the local transformers.js build and expose it via the SDK's globals. */
|
|
4540
4582
|
const loadTransformersRuntime = async (assetsBaseUrl) => {
|
|
4541
4583
|
if (window.TransformersPipeline)
|
|
4542
4584
|
return;
|
|
4543
|
-
const mod = await import(/* @vite-ignore */ `${assetsBaseUrl}transformers.min.js`);
|
|
4585
|
+
const mod = (await import(/* @vite-ignore */ `${assetsBaseUrl}transformers.min.js`));
|
|
4544
4586
|
const pipeline = mod?.pipeline;
|
|
4545
4587
|
const env = mod?.env;
|
|
4546
4588
|
if (typeof pipeline !== 'function' || !env) {
|
|
@@ -4568,7 +4610,7 @@ const loadTransformersRuntime = async (assetsBaseUrl) => {
|
|
|
4568
4610
|
const loadWllamaRuntime = async (assetsBaseUrl) => {
|
|
4569
4611
|
if (window.WllamaModule)
|
|
4570
4612
|
return;
|
|
4571
|
-
const mod = await import(/* @vite-ignore */ `${assetsBaseUrl}wllama/index.js`);
|
|
4613
|
+
const mod = (await import(/* @vite-ignore */ `${assetsBaseUrl}wllama/index.js`));
|
|
4572
4614
|
if (!mod?.Wllama) {
|
|
4573
4615
|
throw new Error('wllama/index.js is missing the Wllama export');
|
|
4574
4616
|
}
|
|
@@ -4601,9 +4643,10 @@ const buildOverrides = (options) => {
|
|
|
4601
4643
|
*/
|
|
4602
4644
|
const initZeroGpuOffscreen = async (options = {}) => {
|
|
4603
4645
|
const assetsBaseUrl = resolveAssetsBaseUrl(options.assetsBaseUrl);
|
|
4604
|
-
//
|
|
4646
|
+
// Silent console unless the host opts into verbose logs. Must run BEFORE the
|
|
4647
|
+
// runtime loads below — transformers.js writes on import.
|
|
4605
4648
|
if (!options.enableConsoleLogs) {
|
|
4606
|
-
|
|
4649
|
+
silenceConsole();
|
|
4607
4650
|
}
|
|
4608
4651
|
await loadTransformersRuntime(assetsBaseUrl);
|
|
4609
4652
|
try {
|
|
@@ -4643,7 +4686,7 @@ const registerZeroGpuOffscreenMessaging = (options = {}) => {
|
|
|
4643
4686
|
lastErrorMessage: '',
|
|
4644
4687
|
orchestratorBaseUrl: options.orchestratorBaseUrl
|
|
4645
4688
|
};
|
|
4646
|
-
const runtime =
|
|
4689
|
+
const runtime = typeof chrome !== 'undefined' ? chrome?.runtime : undefined;
|
|
4647
4690
|
if (!runtime?.onMessage?.addListener) {
|
|
4648
4691
|
console.warn('[ZeroGPU][offscreen] chrome.runtime.onMessage unavailable; messaging not registered.');
|
|
4649
4692
|
return state;
|
|
@@ -4666,9 +4709,10 @@ const registerZeroGpuOffscreenMessaging = (options = {}) => {
|
|
|
4666
4709
|
throw error;
|
|
4667
4710
|
}
|
|
4668
4711
|
};
|
|
4669
|
-
runtime.onMessage.addListener((
|
|
4670
|
-
if (!
|
|
4712
|
+
runtime.onMessage.addListener((rawMessage, _sender, sendResponse) => {
|
|
4713
|
+
if (!rawMessage || typeof rawMessage !== 'object')
|
|
4671
4714
|
return;
|
|
4715
|
+
const message = rawMessage;
|
|
4672
4716
|
if (message.type === ZEROGPU_OFFSCREEN_MESSAGES.getStatus) {
|
|
4673
4717
|
sendResponse({ ok: true, state });
|
|
4674
4718
|
return;
|