@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,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
|
}
|
|
@@ -4610,7 +4643,13 @@ const autoInitFromScriptTag = () => {
|
|
|
4610
4643
|
options.overrides = { telemetry };
|
|
4611
4644
|
}
|
|
4612
4645
|
void initZeroGpuSdk(options).catch((error) => {
|
|
4613
|
-
|
|
4646
|
+
// The logger singleton may not exist yet when init fails before config
|
|
4647
|
+
// resolution, so honour the script-tag attribute directly. Silent unless
|
|
4648
|
+
// the integrator asked for logs — the failure is reported as an
|
|
4649
|
+
// `sdk.init_failed` device event regardless.
|
|
4650
|
+
if (enableConsoleLogs) {
|
|
4651
|
+
console.error('[ZeroGpuSdk] Auto-init failed', error);
|
|
4652
|
+
}
|
|
4614
4653
|
});
|
|
4615
4654
|
};
|
|
4616
4655
|
|