@zerogpu/browser-extension-sdk 0.2.3 → 0.2.4

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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const SDK_VERSION = typeof "0.2.3+38ce04b" === 'string' && "0.2.3+38ce04b".length > 0
4
- ? "0.2.3+38ce04b"
3
+ const SDK_VERSION = typeof "0.2.4+81d7c7a" === 'string' && "0.2.4+81d7c7a".length > 0
4
+ ? "0.2.4+81d7c7a"
5
5
  : '0.0.0-dev';
6
6
 
7
7
  const ORCHESTRATOR_BASE_URL = typeof "https://devices.zerogpu.ai" === 'string' && "https://devices.zerogpu.ai".length > 0
@@ -1,5 +1,5 @@
1
- const SDK_VERSION = typeof "0.2.3+38ce04b" === 'string' && "0.2.3+38ce04b".length > 0
2
- ? "0.2.3+38ce04b"
1
+ const SDK_VERSION = typeof "0.2.4+81d7c7a" === 'string' && "0.2.4+81d7c7a".length > 0
2
+ ? "0.2.4+81d7c7a"
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
@@ -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.3+38ce04b" === 'string' && "0.2.3+38ce04b".length > 0
8
- ? "0.2.3+38ce04b"
7
+ const SDK_VERSION = typeof "0.2.4+81d7c7a" === 'string' && "0.2.4+81d7c7a".length > 0
8
+ ? "0.2.4+81d7c7a"
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
@@ -152,9 +152,17 @@ your manifest, which lets that one page — and only that page — send the
152
152
  extension three messages:
153
153
 
154
154
  ```jsonc
155
- "externally_connectable": { "matches": ["https://*.zerogpu.ai/*"] }
155
+ "externally_connectable": { "matches": ["https://*.zerogpu.ai/*"], "ids": ["*"] }
156
156
  ```
157
157
 
158
+ The `ids` entry appears only when you had no `externally_connectable` key at all,
159
+ and it changes nothing: Chrome treats a missing key as "every extension may
160
+ connect, no web page may", but once the key exists an unspecified `ids` means
161
+ "no extension may". Writing `["*"]` records the access you already had rather
162
+ than granting new access. Narrow or remove it whenever you like — if you had
163
+ already declared the key yourself, even as `{}`, your `ids` is left exactly as
164
+ it was.
165
+
158
166
  No content script and no extra host permission is involved. The bridge accepts
159
167
  only `zerogpu:ping`, `zerogpu:getConsent` and `zerogpu:setConsent`, validates the
160
168
  sender's origin against an exact allowlist first, and can neither start
@@ -220,13 +228,39 @@ control in your own UI rather than a link out:
220
228
  ```js
221
229
  // current state
222
230
  chrome.runtime.sendMessage({ type: "zerogpu:getConsent" }, (res) => {
231
+ if (!res?.ok) return showUnknown(chrome.runtime.lastError?.message || res?.error);
223
232
  console.log(res.consent); // { optedIn, updatedAt, source }
224
233
  });
225
234
 
226
235
  // turn it off — the SDK stops immediately and stays off across restarts
227
- chrome.runtime.sendMessage({ type: "zerogpu:setConsent", optedIn: false });
236
+ chrome.runtime.sendMessage({ type: "zerogpu:setConsent", optedIn: false }, (res) => {
237
+ if (res?.ok) return render(res.consent);
238
+ // The write did not happen, so the SDK is still running. Put the control back
239
+ // where it was; leaving it on the rejected choice tells the user their
240
+ // opt-out saved when it did not.
241
+ restoreLastConfirmed(chrome.runtime.lastError?.message || res?.error);
242
+ });
228
243
  ```
229
244
 
245
+ Check `res.ok` on both, and **undo the control when a write fails**. A write only
246
+ fails when the choice was not stored — `setZeroGpuConsent` throws rather than
247
+ report success for a decision that would not survive a restart — and a checkbox
248
+ has already flipped by the time your callback runs, so reporting the error
249
+ without reverting still leaves the user looking at an opt-out that never
250
+ happened. Read `chrome.runtime.lastError` inside the callback too: it is the only
251
+ signal when the service worker never answers, and Chrome logs it as unchecked
252
+ otherwise.
253
+
254
+ Responses are independent, so they can arrive out of order — a read is a storage
255
+ lookup while a write also waits for the offscreen document to start or stop, so
256
+ the initial read can land after an opt-out the user has already made. Ignore any
257
+ answer that is not from your newest request.
258
+
259
+ The scaffolded `options.js` is a working implementation of all of this — the
260
+ stale-response guard, the revert, and the unknown state when nothing has been
261
+ confirmed yet. Copy its handling along with its calls rather than just the two
262
+ `sendMessage` lines above.
263
+
230
264
  Or directly, inside the service worker:
231
265
 
232
266
  ```js
@@ -290,6 +324,15 @@ forgotten:
290
324
  { "scripts": { "prebuild": "zerogpu vendor" } }
291
325
  ```
292
326
 
327
+ `vendor` also adds `"externally_connectable": { "matches": ["https://*.zerogpu.ai/*"] }`
328
+ to your `manifest.json` if it is missing, merging alongside any origins you already
329
+ allow — plus `"ids": ["*"]` when it has to create the key, which preserves the
330
+ extension-to-extension access an absent key already gave you. That entry is what
331
+ lets the ZeroGPU settings page reach your extension, so
332
+ without it the opt-out link is a dead end — and `init` only runs once, so an
333
+ extension scaffolded before the opt-out shipped would never gain it otherwise. Once
334
+ present, later builds leave the file untouched.
335
+
293
336
  Now every build re-vendors the runtime automatically. Pick whichever update style
294
337
  below fits your workflow.
295
338
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerogpu/browser-extension-sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "ZeroGPU device-side SLM runtime SDK for browsers and Chrome (MV3) extensions",
5
5
  "type": "module",
6
6
  "main": "dist/zerogpu-browser-sdk.cjs",