@zerogpu/browser-extension-sdk 0.1.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.
Files changed (72) hide show
  1. package/README.md +264 -0
  2. package/bin/zerogpu.mjs +331 -0
  3. package/dist/assets/ort-wasm-simd-threaded.wasm +0 -0
  4. package/dist/assets/ort-wasm-simd.wasm +0 -0
  5. package/dist/assets/ort-wasm-threaded.wasm +0 -0
  6. package/dist/assets/ort-wasm.wasm +0 -0
  7. package/dist/assets/transformers.min.js +107 -0
  8. package/dist/assets/wllama/index.js +3374 -0
  9. package/dist/assets/wllama/multi-thread/wllama.wasm +0 -0
  10. package/dist/assets/wllama/single-thread/wllama.wasm +0 -0
  11. package/dist/assets/zerogpu-assets.json +17 -0
  12. package/dist/extension/zerogpu-offscreen.js +2904 -0
  13. package/dist/extension/zerogpu-offscreen.js.map +1 -0
  14. package/dist/loader.js +2 -0
  15. package/dist/loader.js.map +1 -0
  16. package/dist/manifest.json +7 -0
  17. package/dist/types/adapters/gguf/adapter.d.ts +3 -0
  18. package/dist/types/adapters/gguf/factory.d.ts +3 -0
  19. package/dist/types/adapters/gguf/index.d.ts +2 -0
  20. package/dist/types/adapters/gguf/runtime.d.ts +16 -0
  21. package/dist/types/adapters/index.d.ts +5 -0
  22. package/dist/types/adapters/onnx/adapter.d.ts +3 -0
  23. package/dist/types/adapters/onnx/env-fetch.d.ts +1 -0
  24. package/dist/types/adapters/onnx/factory.d.ts +3 -0
  25. package/dist/types/adapters/onnx/index.d.ts +2 -0
  26. package/dist/types/adapters/onnx/runtime.d.ts +15 -0
  27. package/dist/types/adapters/registry.d.ts +5 -0
  28. package/dist/types/adapters/transformers/adapter.d.ts +10 -0
  29. package/dist/types/adapters/transformers/factory.d.ts +3 -0
  30. package/dist/types/adapters/transformers/index.d.ts +2 -0
  31. package/dist/types/adapters/types.d.ts +64 -0
  32. package/dist/types/auto-init.d.ts +1 -0
  33. package/dist/types/config/defaults.d.ts +2 -0
  34. package/dist/types/config/env.d.ts +7 -0
  35. package/dist/types/config/orchestrator-url.d.ts +1 -0
  36. package/dist/types/config/types.d.ts +34 -0
  37. package/dist/types/device/fingerprint.d.ts +2 -0
  38. package/dist/types/device/telemetry.d.ts +3 -0
  39. package/dist/types/device/types.d.ts +58 -0
  40. package/dist/types/extension/offscreen.d.ts +49 -0
  41. package/dist/types/index.d.ts +1 -0
  42. package/dist/types/loader.d.ts +25 -0
  43. package/dist/types/public-api.d.ts +13 -0
  44. package/dist/types/runtime/lifecycle.d.ts +8 -0
  45. package/dist/types/runtime/router.d.ts +2 -0
  46. package/dist/types/runtime/sdk-state.d.ts +56 -0
  47. package/dist/types/sdk-version.d.ts +1 -0
  48. package/dist/types/storage/cached-model.d.ts +29 -0
  49. package/dist/types/storage/index.d.ts +4 -0
  50. package/dist/types/storage/meta-store.d.ts +2 -0
  51. package/dist/types/storage/model-store.d.ts +9 -0
  52. package/dist/types/storage/types.d.ts +19 -0
  53. package/dist/types/transport/http.d.ts +54 -0
  54. package/dist/types/transport/protocol.d.ts +47 -0
  55. package/dist/types/transport/status.d.ts +1 -0
  56. package/dist/types/transport/websocket.d.ts +25 -0
  57. package/dist/types/utils/errors.d.ts +4 -0
  58. package/dist/types/utils/logger.d.ts +15 -0
  59. package/dist/types/utils/timers.d.ts +7 -0
  60. package/dist/types/utils/uuid.d.ts +1 -0
  61. package/dist/v/zerogpu-browser-sdk.f47bae4f15c9.umd.js +2855 -0
  62. package/dist/v/zerogpu-browser-sdk.f47bae4f15c9.umd.js.map +1 -0
  63. package/dist/zerogpu-browser-sdk.cjs +2849 -0
  64. package/dist/zerogpu-browser-sdk.cjs.map +1 -0
  65. package/dist/zerogpu-browser-sdk.esm.js +2847 -0
  66. package/dist/zerogpu-browser-sdk.esm.js.map +1 -0
  67. package/dist/zerogpu-browser-sdk.umd.js +2855 -0
  68. package/dist/zerogpu-browser-sdk.umd.js.map +1 -0
  69. package/docs/INTEGRATION.md +213 -0
  70. package/docs/auto-update-loader.md +451 -0
  71. package/docs/multi-model-support.md +537 -0
  72. package/package.json +91 -0
@@ -0,0 +1,451 @@
1
+ # Always‑Latest SDK Delivery (Auto‑Update Loader)
2
+
3
+ This document explains a change that makes apps using the ZeroGPU Browser SDK
4
+ **always run the latest version automatically**, with zero ongoing effort from
5
+ the app's developers.
6
+
7
+ It is written in three parts:
8
+
9
+ 1. **The plain‑English story** — what changed, why, and the whole flow end to end.
10
+ 2. **The technical changes** — exactly what was modified, file by file.
11
+ 3. **How to test it** — a detailed, step‑by‑step guide.
12
+
13
+ ---
14
+
15
+ ## Part 1 — The plain‑English story
16
+
17
+ ### What is this SDK, in one paragraph?
18
+
19
+ The ZeroGPU Browser SDK is a small piece of JavaScript that other companies
20
+ ("apps") drop into their website. Once it's on a page, it quietly turns the
21
+ visitor's browser into a tiny AI worker that can run small tasks (like
22
+ summarizing text) on the visitor's own device. Apps add it with a single
23
+ `<script>` tag, the same way sites add Google Analytics or a Stripe payment box.
24
+
25
+ ### The problem we set out to fix
26
+
27
+ Think of the SDK like an app on your phone. Normally, your phone updates its
28
+ apps for you in the background — you never think about it. But the way the SDK
29
+ was set up before, it was as if **every app developer had to manually re‑install
30
+ our SDK by hand every time we shipped an improvement.**
31
+
32
+ Concretely, when an app added the SDK, it pointed at a fixed web address that
33
+ included a hand‑written "version stamp" (it literally looked like
34
+ `...umd.js?v=20260305-0837`). To get a newer SDK, **a human at the app had to
35
+ edit that stamp and redeploy their website.** Most never would. So apps drifted
36
+ onto old versions, missed bug fixes and improvements, and we had no clean way to
37
+ push an urgent fix to everyone.
38
+
39
+ There was a second, more subtle problem. To work around the version‑stamp issue,
40
+ the SDK file was being served with a "never store this, always re‑download"
41
+ rule. That technically meant browsers always grabbed the newest copy — but at a
42
+ real cost:
43
+
44
+ - **It was slow.** Every single page load re‑downloaded the entire SDK from
45
+ scratch, even if nothing had changed. No reuse, ever.
46
+ - **It was fragile.** If our servers had a hiccup at the exact moment a visitor
47
+ loaded the page, the SDK simply failed — there was no cached copy to fall back
48
+ on.
49
+ - **We were flying blind.** The SDK told our servers it was "version 0.1.0" no
50
+ matter which build was actually running, so we could never tell what was
51
+ really live out in the world.
52
+
53
+ ### The goal
54
+
55
+ > Once an app installs the SDK, it should **always be on the newest version,
56
+ > forever, with no further work** — and it should be **fast** and **reliable**
57
+ > at the same time.
58
+
59
+ ### The idea we used (the "valet" pattern)
60
+
61
+ This is a well‑known, battle‑tested approach. The biggest SDKs on the web —
62
+ Stripe, Segment, Google Analytics, Sentry — all do exactly this. The trick is to
63
+ split the SDK into **two pieces**:
64
+
65
+ 1. **A tiny "loader"** (think: a hotel valet). This almost never changes. It's
66
+ the only thing the app ever points at. Its whole job is to go fetch the real,
67
+ full SDK and bring it to the page.
68
+
69
+ 2. **The full SDK bundle** (think: the car). This is the big, heavy file that
70
+ actually does the work. It changes with every release.
71
+
72
+ Here's the clever part. The valet (loader) keeps a little **note** — a file
73
+ called `manifest.json` — that always says *"the current car is parked in spot
74
+ #A7."* When we ship a new release, the new car parks in a brand‑new spot (#B3)
75
+ and we just **update the note**.
76
+
77
+ - Because the **note** and the **valet** are small and checked frequently, apps
78
+ always learn about the newest version within seconds.
79
+ - Because each **car** lives in its own permanent spot that never changes, your
80
+ browser can safely keep it cached for a long time — it's guaranteed never to
81
+ be swapped out from under you. Fast.
82
+ - If we ever ship a bad release, we don't have to scramble: we just **change the
83
+ note back** to point at the previous spot. Instant rollback.
84
+
85
+ ### The whole flow, start to finish
86
+
87
+ Here is what now happens, in order, when a visitor lands on an app that uses the
88
+ SDK:
89
+
90
+ 1. **The app's page loads.** It contains one unchanging line: a `<script>` tag
91
+ pointing at our **loader** (`.../dist/loader.js`). The app developer wrote
92
+ this once and never touches it again.
93
+
94
+ 2. **The loader runs.** It's tiny, so this is instant. It immediately reads the
95
+ **note** (`manifest.json`) to find out where today's real SDK lives.
96
+
97
+ 3. **The note answers** with the exact address of the current SDK bundle — an
98
+ address that is unique to this specific build (it has a fingerprint baked into
99
+ the filename).
100
+
101
+ 4. **The loader fetches and starts the real SDK** from that address, handing it
102
+ all the settings the app provided (its account keys, environment, etc.).
103
+
104
+ 5. **The real SDK takes over** and does its normal job — exactly as before. The
105
+ app developer doesn't have to change anything about how they configure it.
106
+
107
+ 6. **The SDK now also reports its true version** back to our servers, so we can
108
+ finally see, at a glance, which build each device is actually running.
109
+
110
+ From the app developer's point of view: **they did nothing, and they're on the
111
+ newest version.** From our point of view: shipping an update is now just
112
+ "publish the new build and update the note," and undoing a bad update is "point
113
+ the note back." From the visitor's point of view: the page is **faster** (the
114
+ heavy file is reused from cache) and **more reliable** (if our servers blip, a
115
+ recently cached copy still works).
116
+
117
+ ### Why this is safe
118
+
119
+ - **It can't double‑load.** If the full SDK is somehow already present, the
120
+ loader notices and steps aside.
121
+ - **It has a safety net.** If the "note" can't be reached for any reason, the
122
+ loader falls back to a stable, always‑available copy of the SDK, so the app
123
+ keeps working.
124
+ - **Early calls aren't lost.** If the app tries to use the SDK in the
125
+ split‑second before the real bundle has finished loading, those calls are held
126
+ in a queue and replayed the moment it's ready — nothing is dropped.
127
+
128
+ ### A note on "always the absolute latest"
129
+
130
+ We deliberately chose the **most aggressive** setting: apps get the newest build
131
+ the instant it's published. That's maximum convenience, but it also means a bad
132
+ release would reach everyone quickly. The features above (instant rollback via
133
+ the note, true version reporting, and an optional future server‑side "stop using
134
+ that build" switch) are the guardrails that make this aggressive choice safe to
135
+ operate.
136
+
137
+ ---
138
+
139
+ ## Part 2 — The technical changes
140
+
141
+ ### Architecture summary
142
+
143
+ ```
144
+ App page ──embeds once──► /dist/loader.js (tiny, served fresh: short TTL + SWR)
145
+ │
146
+ │ fetch
147
+ ▼
148
+ /dist/manifest.json (tiny, served fresh)
149
+ │ { coreBundleUrl: "v/zerogpu-browser-sdk.<hash>.umd.js", ... }
150
+ │ inject <script>
151
+ ▼
152
+ /dist/v/zerogpu-browser-sdk.<hash>.umd.js (immutable, cached 1 year)
153
+ │
154
+ ▼
155
+ autoInitFromScriptTag() → initZeroGpuSdk(...)
156
+ ```
157
+
158
+ - **Entry points** (`loader.js`, `manifest.json`, unhashed alias) are served
159
+ with a short freshness window plus `stale-while-revalidate` / `stale-if-error`.
160
+ - **Core bundles** are content‑hashed and served `immutable` for a year. "Latest"
161
+ changes only by the manifest pointing at a new hash.
162
+
163
+ ### File‑by‑file changes
164
+
165
+ #### New: `sdk/src/loader.ts`
166
+
167
+ The bootstrap stub. Dependency‑free and minified. Responsibilities:
168
+
169
+ - Reads its own `<script>` element (`document.currentScript`) and resolves the
170
+ manifest URL relative to its own `src`.
171
+ - Fetches `manifest.json`, reads `coreBundleUrl`, and injects the hashed core
172
+ bundle as a new `<script>`.
173
+ - **Forwards every integration attribute** (`edgeOperatorKey`,
174
+ `appUserId`, `deviceId`, `enableConsoleLogs`, …) from the loader tag
175
+ onto the injected core tag, so the existing `autoInitFromScriptTag()` path
176
+ works unchanged.
177
+ - Installs a **queueing stub** at `window.ZeroGpuSdk` (Segment‑style) so
178
+ programmatic `initZeroGpuSdk(...)` calls made before the core bundle loads are
179
+ replayed afterward, and exposes a `ready` promise.
180
+ - **Fallbacks / guards:** if a real SDK global is already present it does
181
+ nothing; if the manifest fetch fails it injects the stable unhashed bundle
182
+ (`zerogpu-browser-sdk.umd.js`); supports an optional per‑build `integrity`
183
+ (SRI) hash from the manifest.
184
+ - Exports `bootZeroGpuLoader(env)` (with injected `document`/`window`/`fetch`)
185
+ for unit testing, and auto‑runs against the real DOM when loaded as a script.
186
+
187
+ #### New: `sdk/src/sdk-version.ts`
188
+
189
+ Exports `SDK_VERSION`, backed by a build‑time token `__SDK_VERSION__`. Outside
190
+ the bundle (Vitest, ts‑node) the token is undefined and it falls back to
191
+ `0.0.0-dev`.
192
+
193
+ #### Changed: `sdk/src/config/defaults.ts`
194
+
195
+ `sdkVersion: '0.1.0'` (hardcoded) → `sdkVersion: SDK_VERSION`. This value already
196
+ flows to the orchestrator via the `/register` HTTP body and the WebSocket
197
+ `hello`, so the backend now sees the real running build.
198
+
199
+ #### Changed: `sdk/rollup.config.mjs`
200
+
201
+ - Now exports an **array of two builds**: the core SDK (ESM/UMD/CJS, unchanged
202
+ outputs) and a new **loader** build (`dist/loader.js`, IIFE, minified).
203
+ - Computes the version as `<package version>+<short git sha>` and injects it by
204
+ replacing the `__SDK_VERSION__` token in emitted chunks (`renderChunk`).
205
+
206
+ #### New: `sdk/scripts/postbuild.mjs`
207
+
208
+ Runs after Rollup. It:
209
+
210
+ - SHA‑256 hashes `dist/zerogpu-browser-sdk.umd.js`, takes the first 12 hex chars.
211
+ - Writes the hashed copy to `dist/v/zerogpu-browser-sdk.<hash>.umd.js` (with its
212
+ `sourceMappingURL` rewritten to the hashed map) plus the hashed `.map`.
213
+ - Computes an SRI (`sha384-…`) over the served bytes.
214
+ - Writes `dist/manifest.json`:
215
+ `{ version, buildId, coreBundleUrl, integrity, builtAt }`.
216
+
217
+ #### Changed: `sdk/package.json`
218
+
219
+ `build` script: `rimraf dist && rollup -c && node scripts/postbuild.mjs`.
220
+
221
+ #### Changed: `sdk/_headers` and `sdk/public/_headers`
222
+
223
+ Replaced the blanket `no-store` rule with tiered caching:
224
+
225
+ - `/dist/v/*` → `Cache-Control: public, max-age=31536000, immutable`.
226
+ - `/dist/loader.js`, `/dist/manifest.json`, `/dist/zerogpu-browser-sdk.umd.js` →
227
+ `Cache-Control: public, max-age=0, s-maxage=30, stale-while-revalidate=300,
228
+ stale-if-error=86400`.
229
+ - Existing CORS + `Content-Type` rules preserved; `manifest.json` also gets CORS
230
+ (the loader fetches it cross‑origin).
231
+
232
+ #### Changed: `sdk/dashboard-app/vite.config.ts`
233
+
234
+ `ensurePublicSdkDist()` now also copies `loader.js`, `loader.js.map`,
235
+ `manifest.json`, and the entire `dist/v/` directory into the published
236
+ `public/dist/`.
237
+
238
+ #### Changed: `sdk/dashboard-app/index.html` (the demo)
239
+
240
+ - `SDK_SCRIPT_BY_ENV` now points at `/dist/loader.js` per environment.
241
+ - Deleted the manual `SDK_BUNDLE_VERSION` constant and the `withSdkVersion()`
242
+ `?v=` cache‑buster.
243
+ - `loadSdkUmdApi()` loads the loader and then **waits for the core API global**
244
+ to appear (since the loader injects it asynchronously), with a direct‑bundle
245
+ last‑resort fallback.
246
+
247
+ #### Changed: docs — `sdk/README.md`, `SDK_GUIDE.md`
248
+
249
+ Integration snippets now show the `loader.js` URL and explain the auto‑update
250
+ behavior; the `?v=` approach is removed.
251
+
252
+ #### Tests — `sdk/test/unit.test.ts`
253
+
254
+ Three new cases for the loader:
255
+
256
+ 1. Manifest success → injects the hashed bundle and forwards attributes.
257
+ 2. Manifest failure → falls back to the stable bundle.
258
+ 3. Programmatic calls made before load are queued and replayed on load.
259
+
260
+ ### What an integrating app writes now
261
+
262
+ Before (pinned, manual bump required):
263
+
264
+ ```html
265
+ <script
266
+ src="https://js-sdk.zerogpu.ai/dist/zerogpu-browser-sdk.umd.js?v=20260305-0837"
267
+ edgeOperatorKey="..."></script>
268
+ ```
269
+
270
+ After (embed once, always latest):
271
+
272
+ ```html
273
+ <script
274
+ async
275
+ src="https://js-sdk.zerogpu.ai/dist/loader.js"
276
+ edgeOperatorKey="..."></script>
277
+ ```
278
+
279
+ ---
280
+
281
+ ## Part 3 — How to test it
282
+
283
+ You can verify this at three levels: the **build artifacts**, the **automated
284
+ tests**, and a **real browser run**. Do them in order.
285
+
286
+ > Prerequisite: Node.js 20 (matches CI). All commands run from the `sdk/`
287
+ > directory unless noted.
288
+
289
+ ### A. Verify the build produces the right artifacts
290
+
291
+ ```bash
292
+ cd sdk
293
+ npm install # first time only
294
+ npm run build
295
+ ```
296
+
297
+ Then check the outputs:
298
+
299
+ ```bash
300
+ ls dist
301
+ ls dist/v
302
+ cat dist/manifest.json
303
+ ```
304
+
305
+ **Expected:**
306
+
307
+ - `dist/` contains `loader.js`, `loader.js.map`, `manifest.json`, the three core
308
+ bundles (`.esm.js` / `.umd.js` / `.cjs`) and their maps, and a `v/` folder.
309
+ - `dist/v/` contains exactly one `zerogpu-browser-sdk.<hash>.umd.js` and its
310
+ `.map`.
311
+ - `dist/manifest.json` looks like:
312
+
313
+ ```json
314
+ {
315
+ "version": "0.1.0+<gitsha>",
316
+ "buildId": "<hash>",
317
+ "coreBundleUrl": "v/zerogpu-browser-sdk.<hash>.umd.js",
318
+ "integrity": "sha384-...",
319
+ "builtAt": "..."
320
+ }
321
+ ```
322
+
323
+ - **Cross‑check:** the `<hash>` in `coreBundleUrl` matches the actual filename in
324
+ `dist/v/`, and `version` matches `package.json` version + your current git SHA.
325
+
326
+ **Confirm the version token was really injected** (not left as a placeholder):
327
+
328
+ ```bash
329
+ grep -c "__SDK_VERSION__" dist/zerogpu-browser-sdk.umd.js # expect 0
330
+ ```
331
+
332
+ ### B. Run the automated tests and lint
333
+
334
+ ```bash
335
+ npm test
336
+ ```
337
+
338
+ **Expected:** all suites pass, including the `sdk loader` describe block:
339
+
340
+ - "fetches the manifest and injects the hashed core bundle, forwarding attributes"
341
+ - "falls back to the stable bundle when the manifest is unavailable"
342
+ - "queues programmatic init calls and replays them once the core bundle loads"
343
+
344
+ (You'll see some `NetworkError` lines in stderr — that's happy‑dom trying to
345
+ actually load the injected `<script src>`; it's harmless and the assertions still
346
+ pass.)
347
+
348
+ ```bash
349
+ npm run lint
350
+ ```
351
+
352
+ **Expected:** no **new** errors from `loader.ts`, `sdk-version.ts`, or
353
+ `defaults.ts`. (Any pre‑existing `totalSize` / `cachedSampleMetrics` errors in
354
+ `adapters/` and `runtime/lifecycle.ts` are unrelated to this change.)
355
+
356
+ ### C. Run it in a real browser (the important one)
357
+
358
+ This exercises the full loader → manifest → bundle flow locally.
359
+
360
+ ```bash
361
+ cd sdk
362
+ npm run build # produce dist/ incl. loader.js, manifest.json, dist/v/
363
+ npm run dashboard:dev # starts Vite on http://localhost:8000
364
+ ```
365
+
366
+ Open Chrome at **http://localhost:8000/** and open **DevTools → Network**
367
+ (check "Disable cache" off so you can observe caching). Reload the page.
368
+
369
+ **What to look for:**
370
+
371
+ 1. A request for **`loader.js`** succeeds.
372
+ 2. A request for **`manifest.json`** succeeds and returns JSON pointing at
373
+ `v/zerogpu-browser-sdk.<hash>.umd.js`.
374
+ 3. A request for **`/dist/v/zerogpu-browser-sdk.<hash>.umd.js`** succeeds — this
375
+ is the real SDK being injected by the loader.
376
+ 4. The demo initializes and behaves exactly as before (use the page's UI to init
377
+ the SDK; watch the console logs and the `POST /register` request).
378
+
379
+ **Verify true version reporting:** in the **`POST /register`** request payload
380
+ (Network tab → the register call → Request), the `sdkVersion` field should read
381
+ `0.1.0+<gitsha>` — **not** the old hardcoded `0.1.0`.
382
+
383
+ ### D. Prove "zero‑effort update" and "instant rollback"
384
+
385
+ This is the heart of the feature. You'll change the SDK, rebuild, and watch an
386
+ already‑loaded page pick it up **without editing the page**.
387
+
388
+ 1. With the dashboard still running, note the current hash in `dist/manifest.json`.
389
+ 2. Make any trivial source change (e.g. add a comment in `src/public-api.ts`) and
390
+ rebuild:
391
+
392
+ ```bash
393
+ npm run build
394
+ ```
395
+
396
+ 3. Observe that `dist/v/` now has a **new** hashed filename and `manifest.json`'s
397
+ `coreBundleUrl` points to it.
398
+ 4. **Reload the browser page — without changing a single line of the page's
399
+ HTML.** In the Network tab you should see the loader fetch the updated
400
+ `manifest.json` and then pull the **new** hashed bundle. The app is now on the
401
+ new build automatically. ✅ *Zero‑effort update.*
402
+
403
+ **Rollback drill:**
404
+
405
+ 5. Open `dist/manifest.json` and manually change `coreBundleUrl` back to the
406
+ *previous* hash (the old file is still present in `dist/v/` from step 1; if you
407
+ cleaned it, keep two builds around for this drill).
408
+ 6. Reload the page. It now serves the **previous** build again — no rebuild
409
+ required. ✅ *Instant rollback by repointing the note.*
410
+
411
+ ### E. Verify the failure fallback
412
+
413
+ 1. Stop the dev server (or rename `dist/manifest.json` so it 404s).
414
+ 2. Reload the page.
415
+ 3. **Expected:** the loader logs a warning that the manifest is unavailable and
416
+ falls back to loading `/dist/zerogpu-browser-sdk.umd.js` directly — the app
417
+ still initializes. ✅ *Resilient to manifest outages.*
418
+
419
+ ### F. (Optional) Verify production‑style caching headers
420
+
421
+ To see the real cache behavior Cloudflare will apply, serve the built `public/`
422
+ folder the way production does:
423
+
424
+ ```bash
425
+ cd sdk
426
+ npm run prepare:deploy # build SDK + dashboard, populate sdk/public
427
+ npx wrangler pages dev public
428
+ ```
429
+
430
+ Then in DevTools → Network, click each asset and check **Response Headers →
431
+ `Cache-Control`**:
432
+
433
+ - `loader.js` and `manifest.json` → `max-age=0, s-maxage=30,
434
+ stale-while-revalidate=300, stale-if-error=86400` (always fresh).
435
+ - `dist/v/zerogpu-browser-sdk.<hash>.umd.js` → `max-age=31536000, immutable`
436
+ (cached hard; on a second reload it should be served "(from cache)").
437
+
438
+ ---
439
+
440
+ ## TL;DR
441
+
442
+ - Apps now embed a **stable loader URL once** and are **always on the latest
443
+ SDK**, automatically — no version pinning, no `?v=` bump.
444
+ - The loader reads a tiny **manifest** that points at an **immutable,
445
+ content‑hashed** bundle, so updates are instant, downloads are cacheable, and
446
+ rollback is just repointing the manifest.
447
+ - The SDK now reports its **real build version** to the backend.
448
+ - Verify with `npm run build` (artifacts + manifest), `npm test` (loader cases),
449
+ and a browser run via `npm run dashboard:dev` — then rebuild and reload to watch
450
+ an unchanged page auto‑update.
451
+ ```