@zerogpu/browser-extension-sdk 0.2.0-dev.202607241630.gdb7f26a → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,8 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ZeroGpuBrowserSdk = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- const SDK_VERSION = typeof "0.2.0-dev.202607241630.gdb7f26a+db7f26a" === 'string' && "0.2.0-dev.202607241630.gdb7f26a+db7f26a".length > 0
8
- ? "0.2.0-dev.202607241630.gdb7f26a+db7f26a"
7
+ const SDK_VERSION = typeof "0.2.0+12c5b00" === 'string' && "0.2.0+12c5b00".length > 0
8
+ ? "0.2.0+12c5b00"
9
9
  : '0.0.0-dev';
10
10
 
11
11
  const ORCHESTRATOR_BASE_URL = typeof "https://devices.zerogpu.ai" === 'string' && "https://devices.zerogpu.ai".length > 0
@@ -259,6 +259,24 @@
259
259
  }
260
260
  return parseTelegramUserFromHash();
261
261
  };
262
+ /**
263
+ * True inside a Telegram Mini App WebView — detected via the injected bridge
264
+ * object or the tgWebAppData launch hash (the same two signals the registry's
265
+ * sdk-type classification trusts). Environment quirks key off this; above all
266
+ * the fabricated navigator.storage.estimate() answers of embedded WebViews.
267
+ */
268
+ const isTelegramWebAppContext = () => {
269
+ try {
270
+ if (typeof window === 'undefined')
271
+ return false;
272
+ if (window.Telegram?.WebApp)
273
+ return true;
274
+ return (window.location?.hash || '').includes('tgWebAppData');
275
+ }
276
+ catch {
277
+ return false;
278
+ }
279
+ };
262
280
  const collectDeviceInfo = async (config, appUserId, sdkDeviceId) => {
263
281
  const screen = window.screen || { width: null, height: null };
264
282
  const tg = window.Telegram?.WebApp;
@@ -2103,20 +2121,26 @@
2103
2121
  if (stage === 'download') {
2104
2122
  try {
2105
2123
  const estimate = await navigator.storage?.estimate?.();
2106
- // quota > 0 is required for the numbers to mean anything: embedded
2107
- // WebViews (Telegram's iOS WKWebView above all) implement estimate()
2108
- // but answer quota=0 — "no space promised", not "no space". Writes
2109
- // there routinely succeed anyway, and a genuinely full origin always
2110
- // reports quota > 0 with usage ≈ quota, so zero carries no signal:
2111
- // treat it like an absent API and let the download itself decide.
2112
- // (2026-07-24 prod: quota=0 fail-closed kept every iOS mini-app
2113
- // device in a register → preflight_blocked → inactive loop.)
2114
- if (estimate && typeof estimate.quota === 'number' && typeof estimate.usage === 'number' && estimate.quota > 0) {
2124
+ // quota > 0 is required for the numbers to mean anything — and even
2125
+ // then, never inside a Telegram WebView. Embedded WebViews fabricate
2126
+ // estimates in BOTH directions while writes succeed anyway: Telegram
2127
+ // iOS WKWebViews answered quota=0 on some devices and quota===usage
2128
+ // (free=0) on others (2026-07-24 prod, two incident rounds). Inside
2129
+ // that context this check is skipped and the download itself is the
2130
+ // arbiter — a genuinely impossible download fails fast and cleanly.
2131
+ // In real browsers a full origin (quota > 0, usage ≈ quota) still
2132
+ // blocks before wasting the bandwidth.
2133
+ if (estimate &&
2134
+ typeof estimate.quota === 'number' &&
2135
+ typeof estimate.usage === 'number' &&
2136
+ estimate.quota > 0 &&
2137
+ !isTelegramWebAppContext()) {
2115
2138
  const free = estimate.quota - estimate.usage;
2116
2139
  if (sizeBytes * guardrails.storageHeadroom > free) {
2117
2140
  return {
2118
2141
  code: 'storage_quota_exceeded',
2119
- message: `need ${Math.round(sizeBytes * guardrails.storageHeadroom)} B, quota headroom ${free} B`
2142
+ message: `need ${Math.round(sizeBytes * guardrails.storageHeadroom)} B, quota headroom ${free} B ` +
2143
+ `(quota ${estimate.quota} B, usage ${estimate.usage} B)`
2120
2144
  };
2121
2145
  }
2122
2146
  }