@zerogpu/browser-extension-sdk 0.5.1 → 0.6.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.
- package/README.md +99 -41
- package/bin/browser-extension-sdk.mjs +23 -0
- package/bin/cli.mjs +781 -0
- package/bin/herogpu.mjs +6 -0
- package/bin/zerogpu.mjs +6 -585
- package/dist/assets/herogpu-assets.json +21 -0
- package/dist/assets/herogpu-worker.js +1 -0
- package/dist/assets/zerogpu-assets.json +2 -2
- package/dist/assets/zerogpu-worker.js +1 -1
- package/dist/extension/herogpu-background.js +1 -0
- package/dist/extension/herogpu-offscreen.js +1 -0
- package/dist/extension/herogpu-settings-link.js +1 -0
- package/dist/extension/zerogpu-background.js +1 -1
- package/dist/extension/zerogpu-offscreen.js +1 -1
- package/dist/extension/zerogpu-settings-link.js +1 -1
- package/dist/herogpu-browser-sdk.cjs +1 -0
- package/dist/herogpu-browser-sdk.esm.js +1 -0
- package/dist/herogpu-browser-sdk.umd.js +1 -0
- package/dist/herogpu-worker.js +1 -0
- package/dist/loader.js +1 -1
- package/dist/manifest.json +5 -5
- package/dist/types/appinference/store.d.ts +6 -2
- package/dist/types/appinference/types.d.ts +29 -10
- package/dist/types/branding.d.ts +27 -0
- package/dist/types/config/types.d.ts +1 -1
- package/dist/types/extension/background.d.ts +68 -19
- package/dist/types/extension/consent.d.ts +61 -10
- package/dist/types/extension/offscreen.d.ts +64 -23
- package/dist/types/extension/settings-link.d.ts +12 -1
- package/dist/types/inference/runtime-locator.d.ts +1 -1
- package/dist/types/inference/worker-host.d.ts +1 -1
- package/dist/types/loader.d.ts +15 -3
- package/dist/types/public-api.d.ts +16 -10
- package/dist/types/runtime/app-identity.d.ts +2 -2
- package/dist/types/runtime/app-inference.d.ts +1 -1
- package/dist/types/runtime/custom-params.d.ts +1 -1
- package/dist/types/runtime/host-api.d.ts +2 -1
- package/dist/types/runtime/init-guard.d.ts +2 -1
- package/dist/types/runtime/tracking-script.d.ts +1 -1
- package/dist/types/storage/adopted-key.d.ts +23 -0
- package/dist/types/storage/cached-model.d.ts +4 -1
- package/dist/types/storage/model-store.d.ts +6 -0
- package/dist/types/transport/protocol.d.ts +1 -1
- package/dist/v/herogpu-browser-sdk.a957716b164a.umd.js +1 -0
- package/dist/v/zerogpu-browser-sdk.a957716b164a.umd.js +1 -0
- package/dist/zerogpu-browser-sdk.cjs +1 -1
- package/dist/zerogpu-browser-sdk.esm.js +1 -1
- package/dist/zerogpu-browser-sdk.umd.js +1 -1
- package/dist/zerogpu-worker.js +1 -1
- package/docs/app-side-inference.md +55 -45
- package/docs/auto-update-loader.md +33 -19
- package/docs/extension-developer-guide.md +158 -75
- package/docs/multi-model-support.md +14 -14
- package/package.json +13 -10
- package/dist/v/zerogpu-browser-sdk.686affbdf19f.umd.js +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# herogpu Browser SDK
|
|
2
2
|
|
|
3
|
-
Device-side JavaScript SDK that downloads a small language model (SLM), registers the device with the
|
|
3
|
+
Device-side JavaScript SDK that downloads a small language model (SLM), registers the device with the herogpu orchestrator, opens a WebSocket for tasks, and executes on-device summarization.
|
|
4
|
+
|
|
5
|
+
herogpu is the new name of ZeroGPU. Everything written against the ZeroGPU names keeps working unchanged: see [Coming from ZeroGPU](#coming-from-zerogpu).
|
|
4
6
|
|
|
5
7
|
## Building a Chrome extension?
|
|
6
8
|
|
|
@@ -9,13 +11,16 @@ below can't be used. Instead, install the package and vendor the runtime into yo
|
|
|
9
11
|
extension:
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
|
-
npm install @
|
|
13
|
-
npx
|
|
14
|
+
npm install @herogpu/browser-extension-sdk
|
|
15
|
+
npx herogpu init # vendors the runtime + scaffolds the offscreen glue
|
|
14
16
|
```
|
|
15
17
|
|
|
16
18
|
See the full **[Chrome Extension developer guide](docs/extension-developer-guide.md)**
|
|
17
19
|
(install, validate, and keep the SDK up to date).
|
|
18
20
|
|
|
21
|
+
The package is also published, with the same contents and versions, under its earlier name
|
|
22
|
+
`@zerogpu/browser-extension-sdk`.
|
|
23
|
+
|
|
19
24
|
## Installation
|
|
20
25
|
|
|
21
26
|
```bash
|
|
@@ -30,8 +35,8 @@ npm run build
|
|
|
30
35
|
|
|
31
36
|
The build produces:
|
|
32
37
|
|
|
33
|
-
- ESM (`dist/
|
|
34
|
-
- A UMD bundle (`dist/
|
|
38
|
+
- ESM (`dist/herogpu-browser-sdk.esm.js`) and CJS (`dist/herogpu-browser-sdk.cjs`) bundles for npm consumers.
|
|
39
|
+
- A UMD bundle (`dist/herogpu-browser-sdk.umd.js`) plus an immutable, content-hashed copy under `dist/v/` for CDN distribution.
|
|
35
40
|
- `dist/loader.js` — the stable bootstrap apps embed (see [UMD via `<script>`](#umd-via-script-always-latest-loader)).
|
|
36
41
|
- `dist/manifest.json` — points the loader at the current hashed core bundle and records the build version.
|
|
37
42
|
|
|
@@ -44,7 +49,7 @@ npm run test
|
|
|
44
49
|
## End-to-end (live environment)
|
|
45
50
|
|
|
46
51
|
`sdk/e2e/` drives this checkout's built bundle in headless Chromium (Playwright) against a
|
|
47
|
-
live
|
|
52
|
+
live herogpu environment — the app-side inference flows, the warm-up gate, the cache cap, a
|
|
48
53
|
network drop and recovery — and the Chrome-extension path through the fixture under
|
|
49
54
|
`e2e/extension/`. Credentials come from the zerogpu copilot skill's `.env`; nothing is printed.
|
|
50
55
|
|
|
@@ -70,9 +75,9 @@ npm run lint
|
|
|
70
75
|
### ESM
|
|
71
76
|
|
|
72
77
|
```ts
|
|
73
|
-
import {
|
|
78
|
+
import { initHeroGpuSdk } from '@herogpu/browser-extension-sdk';
|
|
74
79
|
|
|
75
|
-
await
|
|
80
|
+
await initHeroGpuSdk({
|
|
76
81
|
// Optional Telegram user ID or custom app user ID
|
|
77
82
|
appUserId: 'telegram-user-1234',
|
|
78
83
|
|
|
@@ -84,7 +89,7 @@ await initZeroGpuSdk({
|
|
|
84
89
|
orchestrator: {
|
|
85
90
|
// Each deployment bakes in its own orchestrator at build time
|
|
86
91
|
// (develop/staging/production). Override only for internal testing.
|
|
87
|
-
baseUrl: 'https://devices.
|
|
92
|
+
baseUrl: 'https://devices.herogpu.com'
|
|
88
93
|
},
|
|
89
94
|
telemetry: {
|
|
90
95
|
// Enable/disable detailed console logs (redacted: ids/sizes/timings only)
|
|
@@ -116,13 +121,13 @@ The SDK auto-initializes when `edgeOperatorKey` is present
|
|
|
116
121
|
(the loader forwards every attribute to the core bundle).
|
|
117
122
|
|
|
118
123
|
For manual initialization, embed the loader without keys and call
|
|
119
|
-
`
|
|
124
|
+
`HeroGpuSdk.initHeroGpuSdk(...)`. The loader installs a small queueing stub, so
|
|
120
125
|
calls made before the core bundle finishes loading are replayed automatically:
|
|
121
126
|
|
|
122
127
|
```html
|
|
123
128
|
<script async src="https://js-sdk.zerogpu.ai/dist/loader.js"></script>
|
|
124
129
|
<script>
|
|
125
|
-
|
|
130
|
+
HeroGpuSdk.initHeroGpuSdk({
|
|
126
131
|
edgeOperatorKey: 'your-edge-operator-key'
|
|
127
132
|
});
|
|
128
133
|
</script>
|
|
@@ -130,12 +135,12 @@ calls made before the core bundle finishes loading are replayed automatically:
|
|
|
130
135
|
|
|
131
136
|
**How it works:** `loader.js` and `manifest.json` are served fresh (short TTL +
|
|
132
137
|
`stale-while-revalidate`); the manifest points at an immutable, content-hashed
|
|
133
|
-
core bundle (`dist/v/
|
|
138
|
+
core bundle (`dist/v/herogpu-browser-sdk.<hash>.umd.js`) cached for a year. A new
|
|
134
139
|
release simply repoints the manifest at a new hash — and rollback is the same
|
|
135
140
|
operation in reverse. If the manifest is ever unreachable, the loader falls back
|
|
136
|
-
to the stable `dist/
|
|
141
|
+
to the stable `dist/herogpu-browser-sdk.umd.js` bundle.
|
|
137
142
|
|
|
138
|
-
> Loading the core bundle directly (`dist/
|
|
143
|
+
> Loading the core bundle directly (`dist/herogpu-browser-sdk.umd.js`) still
|
|
139
144
|
> works but pins the app to whatever build is live at load time — prefer the
|
|
140
145
|
> loader so updates are automatic.
|
|
141
146
|
|
|
@@ -149,12 +154,12 @@ builds.
|
|
|
149
154
|
|
|
150
155
|
## App-side inference (0.5.0)
|
|
151
156
|
|
|
152
|
-
The model this device holds for the
|
|
153
|
-
choose which eligible model that is. The handle `
|
|
154
|
-
`
|
|
157
|
+
The model this device holds for the herogpu network can also serve your own page, and you may
|
|
158
|
+
choose which eligible model that is. The handle `initHeroGpuSdk` returns (or
|
|
159
|
+
`getHeroGpuSdk()`, for pages the script tag started) carries:
|
|
155
160
|
|
|
156
161
|
```ts
|
|
157
|
-
const sdk = await
|
|
162
|
+
const sdk = await initHeroGpuSdk({ edgeOperatorKey: 'your-edge-operator-key' });
|
|
158
163
|
|
|
159
164
|
sdk.contributionState; // 'stopped' | 'registering' | 'declined' | 'preparing' | 'switching' | 'degraded' | 'contributing'
|
|
160
165
|
sdk.activeModelId; // the model the device holds right now, or null
|
|
@@ -180,6 +185,59 @@ Also since 0.5.0: a guardrail shutdown (memory pressure, an allocation failure)
|
|
|
180
185
|
terminal for the page — the SDK frees its runtime and registers again on a bounded ladder
|
|
181
186
|
(1, 5, 15, then every 30 minutes); `shutdown()` stays terminal. See the guide's section 8.
|
|
182
187
|
|
|
188
|
+
## Coming from ZeroGPU
|
|
189
|
+
|
|
190
|
+
herogpu is the new name of ZeroGPU. This release renames the SDK and changes nothing else. An
|
|
191
|
+
integration written against 0.5.1 keeps working exactly as it is, and you can move to the new
|
|
192
|
+
names when it suits you, one piece at a time: every earlier name is still there, and it is the
|
|
193
|
+
same function, class or value under another name.
|
|
194
|
+
|
|
195
|
+
| What | Name now | Earlier name (still works) |
|
|
196
|
+
| :--- | :--- | :--- |
|
|
197
|
+
| npm package | `@herogpu/browser-extension-sdk` | `@zerogpu/browser-extension-sdk`: the same build, published under both names with the same versions |
|
|
198
|
+
| Command line | `npx herogpu vendor`, `init`, `doctor` | `npx zerogpu vendor`, `init`, `doctor` |
|
|
199
|
+
| Functions | `initHeroGpuSdk`, `getHeroGpuSdk`, `isHeroGpuError`, `initHeroGpuOffscreen`, `registerHeroGpuConsentBridge`, … | `initZeroGpuSdk`, `getZeroGpuSdk`, `isZeroGpuError`, `initZeroGpuOffscreen`, `registerZeroGpuConsentBridge`, … |
|
|
200
|
+
| Classes and types | `HeroGpuError`, `HeroGpuSdkHandle`, `HeroGpuConsent`, … | `ZeroGpuError`, `ZeroGpuSdkHandle`, `ZeroGpuConsent`, … (`ZeroGpuError === HeroGpuError`, so `instanceof` holds either way) |
|
|
201
|
+
| Script-tag globals | `HeroGpuBrowserSdk`, `HeroGpuSdk` | `ZeroGpuBrowserSdk`, `ZeroGpuSdk` (the same objects) |
|
|
202
|
+
| Extension globals | `HeroGpuBackground`, `HeroGpuSettingsLink` | `ZeroGpuBackground`, `ZeroGpuSettingsLink` (the same objects) |
|
|
203
|
+
| Window events | `herogpu:degraded`, `herogpu:recovered`, `herogpu:shutdown`, `herogpu:activeModelChanged`, `herogpu:modelChoiceRefused` | `zerogpu:…`: every event is dispatched under both prefixes, so listen for one of the two |
|
|
204
|
+
| Extension messages | `herogpu:getStatus`, `herogpu:runLocal`, `herogpu:setConsent`, … and the `herogpu:event` broadcast | `zerogpu:…`: accepted under both prefixes; `zerogpu:event` is still broadcast |
|
|
205
|
+
| Attributes | `data-herogpu-telemetry-events`, `data-herogpu-settings`, `data-herogpu-app-name`, … | `data-zerogpu-…` |
|
|
206
|
+
| Bundle files | `dist/herogpu-browser-sdk.esm.js`, `.umd.js`, `.cjs` | `dist/zerogpu-browser-sdk.*`: identical copies, at the same addresses as before |
|
|
207
|
+
| Vendored extension files | `vendor/herogpu/herogpu-*.js` | `vendor/zerogpu/zerogpu-*.js`: an extension that has this folder keeps it, see below |
|
|
208
|
+
| Default device registry | `https://devices.herogpu.com` | `https://devices.zerogpu.ai` still answers; set `overrides.orchestrator.baseUrl` to keep using it |
|
|
209
|
+
|
|
210
|
+
What does not change, and what to check:
|
|
211
|
+
|
|
212
|
+
- **Nothing stored on a device moves.** A browser that already ran the SDK keeps its device id
|
|
213
|
+
and its downloaded models in the places 0.5.1 put them (`localStorage` keys starting with
|
|
214
|
+
`zerogpu_`, the `zerogpu-slm-cache` database). The SDK goes on reading and writing them
|
|
215
|
+
there, so going back to 0.5.1 finds everything too. Only a browser that never ran the SDK
|
|
216
|
+
gets the `herogpu` names.
|
|
217
|
+
- **An opt-out is never lost.** In an extension, the user's choice is stored in
|
|
218
|
+
`chrome.storage.local` under `herogpu:consent`, and every write also stores the same record
|
|
219
|
+
under `zerogpu:consent`, the key 0.5.1 used. A choice made before the update is honoured as
|
|
220
|
+
it is; a choice made after it is still there for 0.5.1 if you roll back, and for code of
|
|
221
|
+
yours that reads `zerogpu:consent` itself. If the two ever differ (a 0.5.1 build wrote its
|
|
222
|
+
key alone), `zerogpu:consent` is the one that counts, and the next write puts them back in
|
|
223
|
+
step. Change the choice with `setHeroGpuConsent()` rather than by writing a key.
|
|
224
|
+
- **Extensions keep their layout.** `npx zerogpu vendor` writes `vendor/zerogpu/zerogpu-*.js`
|
|
225
|
+
as before. `npx herogpu vendor` also updates that folder in place when your extension has it
|
|
226
|
+
or imports from it, and writes `vendor/herogpu/` only into an extension with no integration
|
|
227
|
+
yet. `doctor` accepts either.
|
|
228
|
+
- **`error.name` is unchanged.** A `HeroGpuError` still reports `name === 'ZeroGpuError'`,
|
|
229
|
+
because code compares that string. Branch on `error.code`, or use `isHeroGpuError(error)`.
|
|
230
|
+
- **Where the SDK connects.** The default registry and its WebSocket are now on `herogpu.com`.
|
|
231
|
+
If your page sets a Content-Security-Policy `connect-src`, or your extension narrowed its
|
|
232
|
+
`host_permissions`, add `https://*.herogpu.com` and `wss://*.herogpu.com` next to the
|
|
233
|
+
`zerogpu.ai` entries. Model files are still served from the hosts they were served from.
|
|
234
|
+
- **Unchanged addresses and keys.** The loader and CDN (`js-sdk.zerogpu.ai`), the end-user
|
|
235
|
+
settings page (`zerogpu.ai/extension-settings`) and operator keys (`zgpu-sdk-…`) are the same.
|
|
236
|
+
`vendor` adds `https://*.herogpu.com/*` to your manifest's `externally_connectable` next to
|
|
237
|
+
`https://*.zerogpu.ai/*`, so the settings page keeps reaching the extension if it moves.
|
|
238
|
+
- The earlier names are marked `@deprecated` in the type declarations. They print no warning
|
|
239
|
+
at run time and there is no date for their removal.
|
|
240
|
+
|
|
183
241
|
## Configuration Options
|
|
184
242
|
|
|
185
243
|
### `InitOptions`
|
|
@@ -192,7 +250,7 @@ terminal for the page — the SDK frees its runtime and registers again on a bou
|
|
|
192
250
|
| `resourcePolicy` | `ResourcePolicy` | `{}` | Host hints for the guardrails: `maxModelBytes`, `memoryBudgetFraction`, `maxCachedModels` (most models kept in the download cache, default 3 from the registry, 0 = no cap). `disableGuardrails` is for lab use only. |
|
|
193
251
|
| `overrides` | `Partial<SdkConfig>` | `{}` | Deep merge overrides for internal config. |
|
|
194
252
|
| `customParams` | `{ cust_param1?, cust_param2?, cust_param3? }` | `undefined` | Operator macros attached to every request this device serves. See [Custom macros](#custom-macros-cust_param13). |
|
|
195
|
-
| `appId` | `string` | `undefined` | Your app's
|
|
253
|
+
| `appId` | `string` | `undefined` | Your app's herogpu app ID, from the herogpu dashboard. See [App identity](#app-identity). |
|
|
196
254
|
| `appName` | `string` | `undefined` | Your app's display name. |
|
|
197
255
|
| `externalAppId` | `string` | extension ID in a Chrome extension | Your app's native platform ID (e.g. a Telegram bot username). |
|
|
198
256
|
|
|
@@ -207,14 +265,14 @@ device protocol, outputs and the IndexedDB model cache are unchanged.
|
|
|
207
265
|
| Option | Type | Default | Description |
|
|
208
266
|
| :--- | :--- | :--- | :--- |
|
|
209
267
|
| `inference.worker` | `boolean` | `true` | `false` forces the historical main-thread mode (e.g. an environment known to lack Workers). |
|
|
210
|
-
| `inference.workerUrl` | `string` | `undefined` | Same-origin URL of `dist/
|
|
268
|
+
| `inference.workerUrl` | `string` | `undefined` | Same-origin URL of `dist/herogpu-worker.js` for pages whose Content-Security-Policy forbids `blob:` workers. |
|
|
211
269
|
|
|
212
270
|
When a Worker cannot be created or fails to boot, the SDK falls back to the
|
|
213
271
|
main thread for the rest of the session and reports it once as a
|
|
214
272
|
`guardrail.pressure_warning` event with code `inference_worker_unavailable`.
|
|
215
273
|
|
|
216
274
|
```ts
|
|
217
|
-
await
|
|
275
|
+
await initHeroGpuSdk({
|
|
218
276
|
edgeOperatorKey: 'your-edge-operator-key',
|
|
219
277
|
overrides: { inference: { worker: false } } // main-thread mode
|
|
220
278
|
});
|
|
@@ -223,15 +281,15 @@ await initZeroGpuSdk({
|
|
|
223
281
|
### App identity
|
|
224
282
|
|
|
225
283
|
Attributes the inference your devices serve to your app. Pass the app ID and
|
|
226
|
-
name shown for the app in the
|
|
284
|
+
name shown for the app in the herogpu dashboard. Inside a Chrome extension the
|
|
227
285
|
SDK sends the extension ID (`chrome.runtime.id`) as `externalAppId` on its own;
|
|
228
286
|
a Telegram Mini App can pass its bot username. Everything is optional: leaving
|
|
229
287
|
it unset never affects registration or inference.
|
|
230
288
|
|
|
231
289
|
```ts
|
|
232
|
-
await
|
|
290
|
+
await initHeroGpuSdk({
|
|
233
291
|
edgeOperatorKey: 'your-edge-operator-key',
|
|
234
|
-
appId: 'your-
|
|
292
|
+
appId: 'your-herogpu-app-id',
|
|
235
293
|
appName: 'Study AI'
|
|
236
294
|
});
|
|
237
295
|
```
|
|
@@ -242,12 +300,12 @@ offscreen documents take the same `appId` / `appName` / `externalAppId` options.
|
|
|
242
300
|
### Custom macros (`cust_param1..3`)
|
|
243
301
|
|
|
244
302
|
Three opaque slots for your own reporting dimensions — placement, cohort,
|
|
245
|
-
campaign, app surface.
|
|
303
|
+
campaign, app surface. herogpu stores and counts them against every request your
|
|
246
304
|
devices serve, never interprets them, and reports them back only to you (never
|
|
247
305
|
to the API customer whose request the device served).
|
|
248
306
|
|
|
249
307
|
```ts
|
|
250
|
-
await
|
|
308
|
+
await initHeroGpuSdk({
|
|
251
309
|
edgeOperatorKey: 'your-edge-operator-key',
|
|
252
310
|
customParams: { cust_param1: 'placement_home', cust_param2: 'cohort_b' }
|
|
253
311
|
});
|
|
@@ -257,8 +315,8 @@ setCustomParams({ cust_param1: 'placement_settings' });
|
|
|
257
315
|
```
|
|
258
316
|
|
|
259
317
|
Script tag: `data-cust-param1`, `data-cust-param2`, `data-cust-param3` (the
|
|
260
|
-
loader forwards them). `
|
|
261
|
-
`
|
|
318
|
+
loader forwards them). `HeroGpuSdk.setCustomParams(...)` is queued like
|
|
319
|
+
`initHeroGpuSdk` if called before the core bundle loads. Works the same inside
|
|
262
320
|
Telegram Mini Apps.
|
|
263
321
|
|
|
264
322
|
- **Values only.** The slot name is the key, so send the value itself
|
|
@@ -277,17 +335,17 @@ Telegram Mini Apps.
|
|
|
277
335
|
|
|
278
336
|
You can override any part of the configuration. Common overrides:
|
|
279
337
|
|
|
280
|
-
- **`orchestrator.baseUrl`**: URL of the
|
|
338
|
+
- **`orchestrator.baseUrl`**: URL of the herogpu orchestration API.
|
|
281
339
|
- **`slm.modelRepoId`**: Hugging Face repo id used by Transformers.js (default: `Xenova/t5-small`).
|
|
282
340
|
- **`slm.modelUrl`**: Base URL that hosts the model assets (e.g., your CDN).
|
|
283
341
|
- **`slm.sampleSummaryText`**: Text used for the on-device self-test before registration.
|
|
284
342
|
- **`telemetry.locationData`**: If `true`, SDK attempts to gather GPS coordinates (triggers permission prompt).
|
|
285
343
|
- **`telemetry.enableConsoleLogs`**: Force console logging on/off (default `false`). Logs are redacted by construction: message types, request/model/device ids, counts, byte sizes, durations and error codes only — never task text, model output, message frames or session credentials.
|
|
286
|
-
- **`telemetry.cameraData`**: Deprecated and ignored. The camera-capture path was removed from the SDK entirely
|
|
344
|
+
- **`telemetry.cameraData`**: Deprecated and ignored. The camera-capture path was removed from the SDK entirely; no camera code exists in the shipped bundle. The flag remains in the type only so existing integrations keep compiling.
|
|
287
345
|
|
|
288
346
|
## Data collected at registration
|
|
289
347
|
|
|
290
|
-
The SDK collects coarse device-capability data and sends it to the
|
|
348
|
+
The SDK collects coarse device-capability data and sends it to the herogpu registry on
|
|
291
349
|
`POST /register` so the orchestrator can decide which model (if any) fits this device:
|
|
292
350
|
platform, user agent, language, timezone, CPU core count, approximate memory, screen
|
|
293
351
|
size, battery level, connection type, page URL/referrer, and — only with the
|
|
@@ -316,8 +374,8 @@ register payload twice, as `gpuRenderer` and as `webglFingerprint`:
|
|
|
316
374
|
## Dashboard + Demo (Vite)
|
|
317
375
|
|
|
318
376
|
The Vite app under `sdk/dashboard-app` serves both:
|
|
319
|
-
- `/` —
|
|
320
|
-
- `/dashboard` —
|
|
377
|
+
- `/` — herogpu Edge SDK demo
|
|
378
|
+
- `/dashboard` — herogpu fleet dashboard (analytics)
|
|
321
379
|
|
|
322
380
|
It also proxies API calls so the browser avoids CORS:
|
|
323
381
|
- `/api/*` -> `API_UPSTREAM` (default `http://localhost:4000`)
|
|
@@ -344,18 +402,18 @@ Env config:
|
|
|
344
402
|
### Testing against a non-production orchestrator
|
|
345
403
|
|
|
346
404
|
Each deployment bakes in its own orchestrator at build time — develop, staging, or
|
|
347
|
-
production (`https://devices.
|
|
405
|
+
production (`https://devices.herogpu.com`) — via the `ZGPU_ORCHESTRATOR_BASE_URL` build
|
|
348
406
|
env var set by the GitHub deploy workflows. For internal testing against a develop or
|
|
349
407
|
local orchestration API, override `orchestrator.baseUrl` directly:
|
|
350
408
|
|
|
351
409
|
```ts
|
|
352
|
-
import {
|
|
410
|
+
import { initHeroGpuSdk } from '@herogpu/browser-extension-sdk';
|
|
353
411
|
|
|
354
|
-
await
|
|
412
|
+
await initHeroGpuSdk({
|
|
355
413
|
edgeOperatorKey: 'your-edge-operator-key',
|
|
356
414
|
overrides: {
|
|
357
415
|
orchestrator: {
|
|
358
|
-
// e.g. https://dev
|
|
416
|
+
// e.g. https://dev-devices.herogpu.com or http://localhost:6000
|
|
359
417
|
baseUrl: 'http://localhost:6000'
|
|
360
418
|
},
|
|
361
419
|
telemetry: {
|
|
@@ -367,7 +425,7 @@ await initZeroGpuSdk({
|
|
|
367
425
|
|
|
368
426
|
### SDK Demo Page
|
|
369
427
|
|
|
370
|
-
Use the built-in demo page served by Vite at `http://localhost:8000/` (it loads the SDK from `/dist/
|
|
428
|
+
Use the built-in demo page served by Vite at `http://localhost:8000/` (it loads the SDK from `/dist/herogpu-browser-sdk.esm.js`).
|
|
371
429
|
|
|
372
430
|
## Self-Hosting the Model
|
|
373
431
|
|
|
@@ -408,7 +466,7 @@ curl -L -o onnx/decoder_model_merged_quantized.onnx "$BASE_ONNX/decoder_model_me
|
|
|
408
466
|
Upload the `t5-small/` directory to your CDN unchanged and ensure responses include permissive CORS headers (`Access-Control-Allow-Origin: *`). Then override the SDK config:
|
|
409
467
|
|
|
410
468
|
```ts
|
|
411
|
-
await
|
|
469
|
+
await initHeroGpuSdk({
|
|
412
470
|
edgeOperatorKey: 'your-edge-operator-key',
|
|
413
471
|
overrides: {
|
|
414
472
|
slm: {
|
|
@@ -422,7 +480,7 @@ await initZeroGpuSdk({
|
|
|
422
480
|
|
|
423
481
|
## Flow
|
|
424
482
|
|
|
425
|
-
1. `
|
|
483
|
+
1. `initHeroGpuSdk` resolves configuration (env defaults + overrides).
|
|
426
484
|
2. Device fingerprint + metadata are collected.
|
|
427
485
|
3. Required SLM artifacts are downloaded to IndexedDB and loaded into Transformers.js. Timing metrics are recorded.
|
|
428
486
|
4. The SDK calls the orchestrator `/register` endpoint with device + model metadata.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `npx @herogpu/browser-extension-sdk <command>` and, for the earlier package
|
|
3
|
+
// name, `npx @zerogpu/browser-extension-sdk <command>`. When a package installs
|
|
4
|
+
// more than one command, npx runs the one named like the package, and stops
|
|
5
|
+
// with "could not determine executable to run" when there is none. Up to 0.5.1
|
|
6
|
+
// the package had a single command, so that form worked; this entry keeps it
|
|
7
|
+
// working now that there are two (`herogpu` and `zerogpu`).
|
|
8
|
+
//
|
|
9
|
+
// It behaves as the command that matches the name the package was installed
|
|
10
|
+
// under: `zerogpu` for @zerogpu/browser-extension-sdk (the layout 0.5.1 wrote),
|
|
11
|
+
// `herogpu` otherwise. Same implementation as both (./cli.mjs).
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import { runCli } from './cli.mjs';
|
|
14
|
+
|
|
15
|
+
const installedAs = (() => {
|
|
16
|
+
try {
|
|
17
|
+
return String(JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).name ?? '');
|
|
18
|
+
} catch {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
})();
|
|
22
|
+
|
|
23
|
+
runCli(installedAs.startsWith('@zerogpu/') ? 'zerogpu' : 'herogpu');
|