@zerogpu/browser-extension-sdk 0.2.3 → 0.3.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 +35 -0
- package/bin/zerogpu.mjs +171 -29
- package/dist/assets/zerogpu-assets.json +2 -2
- package/dist/extension/zerogpu-background.js +42 -1
- package/dist/extension/zerogpu-background.js.map +1 -1
- package/dist/extension/zerogpu-offscreen.js +182 -10
- package/dist/extension/zerogpu-offscreen.js.map +1 -1
- package/dist/extension/zerogpu-settings-link.js +9 -0
- package/dist/extension/zerogpu-settings-link.js.map +1 -1
- package/dist/loader.js +1 -1
- package/dist/loader.js.map +1 -1
- package/dist/manifest.json +5 -5
- package/dist/types/extension/background.d.ts +10 -0
- package/dist/types/extension/consent.d.ts +0 -5
- package/dist/types/extension/offscreen.d.ts +23 -0
- package/dist/types/public-api.d.ts +14 -0
- package/dist/types/runtime/custom-params.d.ts +34 -0
- package/dist/types/transport/http.d.ts +3 -0
- package/dist/v/{zerogpu-browser-sdk.85b3f7e3cc11.umd.js → zerogpu-browser-sdk.8d29febc744c.umd.js} +177 -9
- package/dist/v/zerogpu-browser-sdk.8d29febc744c.umd.js.map +1 -0
- package/dist/zerogpu-browser-sdk.cjs +176 -8
- package/dist/zerogpu-browser-sdk.cjs.map +1 -1
- package/dist/zerogpu-browser-sdk.esm.js +176 -9
- package/dist/zerogpu-browser-sdk.esm.js.map +1 -1
- package/dist/zerogpu-browser-sdk.umd.js +176 -8
- package/dist/zerogpu-browser-sdk.umd.js.map +1 -1
- package/docs/extension-developer-guide.md +74 -2
- package/package.json +1 -1
- package/dist/v/zerogpu-browser-sdk.85b3f7e3cc11.umd.js.map +0 -1
|
@@ -14,6 +14,15 @@ var ZeroGpuSettingsLink = (function (exports) {
|
|
|
14
14
|
* Nothing is deregistered server-side.
|
|
15
15
|
*/
|
|
16
16
|
/** Single `chrome.storage.local` key holding the whole record. */
|
|
17
|
+
/**
|
|
18
|
+
* Serialises writes, for the same reason the bridge serialises applies. Toggling
|
|
19
|
+
* twice in quick succession is two concurrent calls — each bridge message is
|
|
20
|
+
* handled independently — and `storage.local` promises no ordering between
|
|
21
|
+
* them, so the earlier decision could be the one that lands last and persists
|
|
22
|
+
* while the user is looking at the later one. Queueing also keeps `updatedAt`
|
|
23
|
+
* in step with what actually got stored.
|
|
24
|
+
*/
|
|
25
|
+
Promise.resolve();
|
|
17
26
|
/** Default host for the ZeroGPU-hosted end-user settings page. */
|
|
18
27
|
const ZEROGPU_SETTINGS_BASE_URL = 'https://zerogpu.ai/extension-settings';
|
|
19
28
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zerogpu-settings-link.js","sources":["../../../src/extension/consent.ts","../../../src/extension/settings-link.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;IAAA;;;;;;;;;;;IAWG;IAEH;
|
|
1
|
+
{"version":3,"file":"zerogpu-settings-link.js","sources":["../../../src/extension/consent.ts","../../../src/extension/settings-link.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;IAAA;;;;;;;;;;;IAWG;IAEH;IA0GA;;;;;;;IAOG;IACgC,OAAO,CAAC,OAAO;IAmClD;IACO,MAAM,yBAAyB,GAAG,uCAAuC;IAahF;;;;IAIG;IACI,MAAM,uBAAuB,GAAG,CAAC,EACtC,WAAW,EACX,OAAO,EACP,OAAO,GAAG,yBAAyB,EACnC,KAAK,GAAG,KAAK,EACM,KAAY;IAC/B,IAAA,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;QAC5B,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC;QACzC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC;IACjD,IAAA,IAAI,OAAO;YAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC;IACtD,IAAA,IAAI,KAAK;YAAE,GAAG,CAA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G,EAAE,GAAG,KAAsB;;;IAGtC,oBAAA,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG;4BAAE,QAAQ,CAAC,KAAK,CAAC;IACrD,gBAAA,CAAC,CAAC;gBACJ;YACF;IAEA,QAAA,OAAO,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,CAAC;YACzC,KAAK,IAAI,CAAC;QACZ;IAEA,IAAA,OAAO,KAAK;IACd;IAEA;IACA;IACA,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;IACnC,IAAA,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE;IACrC,QAAA,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,MAAK;IACjD,YAAA,yBAAyB,EAAE;IAC7B,QAAA,CAAC,CAAC;QACJ;aAAO;IACL,QAAA,yBAAyB,EAAE;QAC7B;IACF;;;;;;;;;;;;"}
|
package/dist/loader.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e){"use strict";const t="ZeroGpuBrowserSdk",r="ZeroGpuSdk",n=e=>{const{script:n,documentRef:o,windowRef:
|
|
1
|
+
!function(e){"use strict";const t="ZeroGpuBrowserSdk",r="ZeroGpuSdk",n=e=>{const{script:n,documentRef:o,windowRef:s,fetchImpl:i}=e;if(s[t]?.initZeroGpuSdk)return Promise.resolve();const c=/^(true|1)$/i.test((n.getAttribute("data-enable-console-logs")??n.getAttribute("enableConsoleLogs")??"").trim()),a=(...e)=>{c&&console.warn(...e)},d=(...e)=>{c&&console.error(...e)},u=n.getAttribute("src")??"";let l;try{l=new URL(u,e.baseUri)}catch{l=new URL(e.baseUri)}const m=new URL("manifest.json",l).toString(),f=new URL("zerogpu-browser-sdk.umd.js",l).toString(),w=[];let p=()=>{};const b=new Promise(e=>{p=e}),g=()=>{const e=s[t];if(e&&"function"==typeof e.initZeroGpuSdk){for(s[r]=e;w.length>0;){const t=w.shift();try{const r=e[t.method];Promise.resolve(r?.(...t.args)).then(t.resolve,t.reject)}catch(e){t.reject(e)}}p()}else d("[ZeroGpuSdk] Core bundle loaded but global API is missing.")};if(!s[r]){const e=e=>(...t)=>new Promise((r,n)=>{w.push({method:e,args:t,resolve:r,reject:n})});s[r]={ready:b,initZeroGpuSdk:e("initZeroGpuSdk"),setCustomParams:e("setCustomParams")}}const h=(e,t)=>{const r=o.createElement("script");for(const e of Array.from(n.attributes))"src"!==e.name&&"integrity"!==e.name&&r.setAttribute(e.name,e.value);r.src=e,r.async=!0,r.setAttribute("data-zerogpu-core","true"),t&&(r.integrity=t,r.crossOrigin=n.crossOrigin??"anonymous"),r.addEventListener("load",g),r.addEventListener("error",()=>{d("[ZeroGpuSdk] Failed to load core bundle from",e)}),(o.head??o.documentElement).appendChild(r)};return(async()=>{try{const e=await i(m,{credentials:"omit"});if(!e.ok)throw new Error(`manifest HTTP ${e.status}`);const t=await e.json();if(!t?.coreBundleUrl)throw new Error("manifest missing coreBundleUrl");const r=new URL(t.coreBundleUrl,m).toString();h(r,t.integrity)}catch(e){a("[ZeroGpuSdk] Manifest unavailable, falling back to stable bundle.",e),h(f)}})()};(()=>{if("undefined"==typeof document||"undefined"==typeof window)return;const e=document.currentScript instanceof HTMLScriptElement?document.currentScript:null;e&&n({script:e,documentRef:document,windowRef:window,fetchImpl:window.fetch.bind(window),baseUri:document.baseURI})})(),e.bootZeroGpuLoader=n}({});
|
|
2
2
|
//# sourceMappingURL=loader.js.map
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sources":["../../src/loader.ts"],"sourcesContent":[null],"names":["GLOBAL_NAME","STUB_NAME","bootZeroGpuLoader","env","script","documentRef","windowRef","fetchImpl","initZeroGpuSdk","Promise","resolve","consoleLogsEnabled","test","getAttribute","trim","loaderLog","args","console","warn","error","loaderSrc","baseUrl","URL","baseUri","manifestUrl","toString","fallbackBundleUrl","queue","resolveReady","ready","flushQueue","api","length","call","shift","method","then","reject","push","injectCoreBundle","bundleUrl","integrity","core","createElement","attr","Array","from","attributes","name","setAttribute","value","src","async","crossOrigin","addEventListener","head","documentElement","appendChild","response","credentials","ok","Error","status","manifest","json","coreBundleUrl","document","window","currentScript","HTMLScriptElement","fetch","bind","baseURI"],"mappings":"0BAwDA,MAAMA,EAAc,oBACdC,EAAY,aAELC,EAAqBC,IAChC,MAAMC,OAAEA,EAAMC,YAAEA,EAAWC,UAAEA,EAASC,UAAEA,GAAcJ,EAItD,GAAIG,EAAUN,IAAcQ,eAC1B,OAAOC,QAAQC,UAQjB,MAAMC,EAAqB,cAAcC,MAErCR,EAAOS,aAAa,6BACpBT,EAAOS,aAAa,sBACpB,IACAC,QAEEC,EACE,IAAIC,KACJL,GAAoBM,QAAQC,QAAQF,IAFtCD,EAIG,IAAIC,KACLL,GAAoBM,QAAQE,SAASH,IAIvCI,EAAYhB,EAAOS,aAAa,QAAU,GAChD,IAAIQ,EACJ,IACEA,EAAU,IAAIC,IAAIF,EAAWjB,EAAIoB,QACnC,CACA,MACEF,EAAU,IAAIC,IAAInB,EAAIoB,QACxB,CACA,MAAMC,EAAc,IAAIF,IAAI,gBAAiBD,GAASI,WAGhDC,EAAoB,IAAIJ,IAC5B,6BACAD,GACAI,WAIIE,EAAsB,GAC5B,IAAIC,EAA2B,OAC/B,MAAMC,EAAQ,IAAIpB,QAAeC,IAC/BkB,EAAelB,IAGXoB,EAAa,KACjB,MAAMC,EAAMzB,EAAUN,GACtB,GAAK+B,GAAqC,mBAAvBA,EAAIvB,eAAvB,CAMA,IADAF,EAAUL,GAAa8B,EAChBJ,EAAMK,OAAS,GAAG,CACvB,MAAMC,EAAON,EAAMO,QACnB,IACE,MAAMC,EAASJ,EAAIE,EAAKE,QACxB1B,QAAQC,QAAQyB,OAAYF,EAAKjB,OAAOoB,KACtCH,EAAKvB,QACLuB,EAAKI,OAET,CACA,MAAOlB,GACLc,EAAKI,OAAOlB,EACd,CACF,CACAS,GAhBA,MAFEb,EAAgB,+
|
|
1
|
+
{"version":3,"file":"loader.js","sources":["../../src/loader.ts"],"sourcesContent":[null],"names":["GLOBAL_NAME","STUB_NAME","bootZeroGpuLoader","env","script","documentRef","windowRef","fetchImpl","initZeroGpuSdk","Promise","resolve","consoleLogsEnabled","test","getAttribute","trim","loaderLog","args","console","warn","error","loaderSrc","baseUrl","URL","baseUri","manifestUrl","toString","fallbackBundleUrl","queue","resolveReady","ready","flushQueue","api","length","call","shift","method","then","reject","enqueue","push","setCustomParams","injectCoreBundle","bundleUrl","integrity","core","createElement","attr","Array","from","attributes","name","setAttribute","value","src","async","crossOrigin","addEventListener","head","documentElement","appendChild","response","credentials","ok","Error","status","manifest","json","coreBundleUrl","document","window","currentScript","HTMLScriptElement","fetch","bind","baseURI"],"mappings":"0BAwDA,MAAMA,EAAc,oBACdC,EAAY,aAELC,EAAqBC,IAChC,MAAMC,OAAEA,EAAMC,YAAEA,EAAWC,UAAEA,EAASC,UAAEA,GAAcJ,EAItD,GAAIG,EAAUN,IAAcQ,eAC1B,OAAOC,QAAQC,UAQjB,MAAMC,EAAqB,cAAcC,MAErCR,EAAOS,aAAa,6BACpBT,EAAOS,aAAa,sBACpB,IACAC,QAEEC,EACE,IAAIC,KACJL,GAAoBM,QAAQC,QAAQF,IAFtCD,EAIG,IAAIC,KACLL,GAAoBM,QAAQE,SAASH,IAIvCI,EAAYhB,EAAOS,aAAa,QAAU,GAChD,IAAIQ,EACJ,IACEA,EAAU,IAAIC,IAAIF,EAAWjB,EAAIoB,QACnC,CACA,MACEF,EAAU,IAAIC,IAAInB,EAAIoB,QACxB,CACA,MAAMC,EAAc,IAAIF,IAAI,gBAAiBD,GAASI,WAGhDC,EAAoB,IAAIJ,IAC5B,6BACAD,GACAI,WAIIE,EAAsB,GAC5B,IAAIC,EAA2B,OAC/B,MAAMC,EAAQ,IAAIpB,QAAeC,IAC/BkB,EAAelB,IAGXoB,EAAa,KACjB,MAAMC,EAAMzB,EAAUN,GACtB,GAAK+B,GAAqC,mBAAvBA,EAAIvB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rB,EAAY,IAAIpB,IAAI2C,EAASE,cAAe3C,GAAaC,WAC/DgB,EAAiBC,EAAWuB,EAAStB,UACvC,CACA,MAAOxB,GACLJ,EACE,oEACAI,GAEFsB,EAAiBf,EACnB,CACD,EApBM,IAwBT,MACE,GAAwB,oBAAb0C,UAA8C,oBAAXC,OAC5C,OAEF,MAAMjE,EACJgE,SAASE,yBAAyBC,kBAC9BH,SAASE,cACT,KACDlE,GAGAF,EAAkB,CACrBE,SACAC,YAAa+D,SACb9D,UAAW+D,OACX9D,UAAW8D,OAAOG,MAAMC,KAAKJ,QAC7B9C,QAAS6C,SAASM,SAErB,EAlBD"}
|
package/dist/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.3.0+b41a26f",
|
|
3
3
|
"channel": "official",
|
|
4
|
-
"buildId": "
|
|
5
|
-
"coreBundleUrl": "v/zerogpu-browser-sdk.
|
|
6
|
-
"integrity": "sha384-
|
|
7
|
-
"builtAt": "2026-
|
|
4
|
+
"buildId": "8d29febc744c",
|
|
5
|
+
"coreBundleUrl": "v/zerogpu-browser-sdk.8d29febc744c.umd.js",
|
|
6
|
+
"integrity": "sha384-xFPBTw8UdaQsMeQimd6+Djeh3TVPaR7G9gErhyzelx5mbJ68BvwncjVTUxRwh6O+",
|
|
7
|
+
"builtAt": "2026-09-18T14:17:47.575Z"
|
|
8
8
|
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* every host extension and break their existing service-worker code.
|
|
19
19
|
*/
|
|
20
20
|
import { ZeroGpuConsent } from './consent';
|
|
21
|
+
import type { CustomParams } from '../runtime/custom-params';
|
|
21
22
|
/** The three messages the bridge answers. Nothing here can start inference,
|
|
22
23
|
* read device data, or reach the model store — by design. */
|
|
23
24
|
export declare const ZEROGPU_BRIDGE_MESSAGES: {
|
|
@@ -53,6 +54,14 @@ export declare const ensureZeroGpuOffscreen: (options?: ConsentBridgeOptions) =>
|
|
|
53
54
|
* the document down so nothing restarts inside it.
|
|
54
55
|
*/
|
|
55
56
|
export declare const stopZeroGpuOffscreen: (options?: ConsentBridgeOptions) => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Replace the operator macros (`cust_param1`..`cust_param3`) in the running
|
|
59
|
+
* offscreen SDK; `{}` clears them. Resolves false when there is no document to
|
|
60
|
+
* receive them (user opted out, or not started yet). The values live as long
|
|
61
|
+
* as that document — for values that must survive a restart, pass
|
|
62
|
+
* `customParams` to `initZeroGpuOffscreen` as well.
|
|
63
|
+
*/
|
|
64
|
+
export declare const setZeroGpuCustomParams: (customParams: CustomParams, options?: ConsentBridgeOptions) => Promise<boolean>;
|
|
56
65
|
/** Start or stop to match the stored decision. Safe to call repeatedly. */
|
|
57
66
|
export declare const applyZeroGpuConsent: (consent: ZeroGpuConsent, options?: ConsentBridgeOptions) => Promise<void>;
|
|
58
67
|
/** Start only if the user is opted in — for `onInstalled` / `onStartup`. */
|
|
@@ -69,3 +78,4 @@ export declare const startZeroGpuIfConsented: (options?: ConsentBridgeOptions) =
|
|
|
69
78
|
export declare const registerZeroGpuConsentBridge: (options?: ConsentBridgeOptions) => void;
|
|
70
79
|
export { ZEROGPU_CONSENT_KEY, DEFAULT_CONSENT, getZeroGpuConsent, isZeroGpuOptedIn, setZeroGpuConsent, onZeroGpuConsentChanged, buildZeroGpuSettingsUrl, ZEROGPU_SETTINGS_BASE_URL } from './consent';
|
|
71
80
|
export type { ZeroGpuConsent, ZeroGpuConsentSource } from './consent';
|
|
81
|
+
export type { CustomParams } from '../runtime/custom-params';
|
|
@@ -30,11 +30,6 @@ export declare const DEFAULT_CONSENT: ZeroGpuConsent;
|
|
|
30
30
|
export declare const getZeroGpuConsent: () => Promise<ZeroGpuConsent>;
|
|
31
31
|
/** Convenience for the common gate: "may the SDK run right now?" */
|
|
32
32
|
export declare const isZeroGpuOptedIn: () => Promise<boolean>;
|
|
33
|
-
/**
|
|
34
|
-
* Record a decision. The write is what drives everything else — the background
|
|
35
|
-
* bridge listens on `chrome.storage.onChanged` and starts or stops the SDK in
|
|
36
|
-
* response, so no caller needs to do both.
|
|
37
|
-
*/
|
|
38
33
|
export declare const setZeroGpuConsent: (optedIn: boolean, source?: ZeroGpuConsentSource) => Promise<ZeroGpuConsent>;
|
|
39
34
|
/**
|
|
40
35
|
* Subscribe to consent changes from any extension context (the hosted settings
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZeroGPU "extension kit" — offscreen host helper.
|
|
3
|
+
*
|
|
4
|
+
* Chrome Manifest V3 forbids remotely-hosted code, so the SDK and its model
|
|
5
|
+
* runtimes (transformers.js + ONNX wasm, wllama + wasm) must be vendored into the
|
|
6
|
+
* extension package and loaded locally. This module does all of that wiring so an
|
|
7
|
+
* extension's offscreen document needs only a single call.
|
|
8
|
+
*
|
|
9
|
+
* Vendor the runtime assets with `npx zerogpu vendor` (default into
|
|
10
|
+
* `vendor/zerogpu/`); this bundle (`dist/extension/zerogpu-offscreen.js`) is one
|
|
11
|
+
* of the vendored files and already contains the SDK itself.
|
|
12
|
+
*/
|
|
13
|
+
import { setCustomParams } from '../public-api';
|
|
14
|
+
import { CustomParams } from '../runtime/custom-params';
|
|
1
15
|
import { ConfigOverrides } from '../config/env';
|
|
2
16
|
export interface OffscreenInitOptions {
|
|
3
17
|
/** SDK operator key (from the ZeroGPU dashboard). */
|
|
@@ -27,6 +41,12 @@ export interface OffscreenInitOptions {
|
|
|
27
41
|
trackingRunnerUrl?: string | false;
|
|
28
42
|
/** Enable verbose SDK console logging (default false). */
|
|
29
43
|
enableConsoleLogs?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Operator macros (`cust_param1`..`cust_param3`). Values set here survive the
|
|
46
|
+
* document being recreated; values sent later with
|
|
47
|
+
* `zerogpu:setCustomParams` last only as long as this document.
|
|
48
|
+
*/
|
|
49
|
+
customParams?: CustomParams;
|
|
30
50
|
/** Advanced: deep config overrides merged last. */
|
|
31
51
|
overrides?: ConfigOverrides;
|
|
32
52
|
}
|
|
@@ -36,10 +56,13 @@ export interface OffscreenInitOptions {
|
|
|
36
56
|
* repeated init.
|
|
37
57
|
*/
|
|
38
58
|
export declare const initZeroGpuOffscreen: (options?: OffscreenInitOptions) => Promise<void>;
|
|
59
|
+
export { setCustomParams };
|
|
60
|
+
export type { CustomParams };
|
|
39
61
|
export declare const ZEROGPU_OFFSCREEN_MESSAGES: {
|
|
40
62
|
readonly forceInit: "zerogpu:forceInit";
|
|
41
63
|
readonly getStatus: "zerogpu:getStatus";
|
|
42
64
|
readonly disable: "zerogpu:disable";
|
|
65
|
+
readonly setCustomParams: "zerogpu:setCustomParams";
|
|
43
66
|
};
|
|
44
67
|
export interface ZeroGpuOffscreenState {
|
|
45
68
|
status: 'idle' | 'initializing' | 'running' | 'error';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConfigOverrides } from './config/env';
|
|
2
2
|
import { HostEventName, SdkLifecycleStatus } from './runtime/host-api';
|
|
3
3
|
import { ResourcePolicy } from './runtime/guardrails';
|
|
4
|
+
import { CustomParams } from './runtime/custom-params';
|
|
4
5
|
import './adapters';
|
|
5
6
|
export interface InitOptions {
|
|
6
7
|
overrides?: ConfigOverrides;
|
|
@@ -16,6 +17,12 @@ export interface InitOptions {
|
|
|
16
17
|
* `disableGuardrails` is for lab use only and is logged loudly.
|
|
17
18
|
*/
|
|
18
19
|
resourcePolicy?: ResourcePolicy;
|
|
20
|
+
/**
|
|
21
|
+
* Operator macros (`cust_param1`..`cust_param3`) attached to every request
|
|
22
|
+
* this device serves. Opaque to ZeroGPU and reported back only to you; must
|
|
23
|
+
* not carry personal data. Change them later with `setCustomParams`.
|
|
24
|
+
*/
|
|
25
|
+
customParams?: CustomParams;
|
|
19
26
|
}
|
|
20
27
|
/**
|
|
21
28
|
* Host-facing handle. `status` reflects the guardrail lifecycle
|
|
@@ -39,3 +46,10 @@ export interface ZeroGpuSdkHandle {
|
|
|
39
46
|
* returned handle is additive).
|
|
40
47
|
*/
|
|
41
48
|
export declare const initZeroGpuSdk: (options?: InitOptions) => Promise<ZeroGpuSdkHandle>;
|
|
49
|
+
/**
|
|
50
|
+
* Replaces the operator macros: slots omitted here become unset, and
|
|
51
|
+
* `setCustomParams({})` clears them all. Applies from the next request the
|
|
52
|
+
* device serves — no re-registration. Safe to call before or after init.
|
|
53
|
+
*/
|
|
54
|
+
export declare const setCustomParams: (params: CustomParams) => void;
|
|
55
|
+
export type { CustomParams, CustParamSlot } from './runtime/custom-params';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator macros: three opaque slots an app attaches to every request its
|
|
3
|
+
* devices serve. ZeroGPU stores and counts them, never interprets them, and
|
|
4
|
+
* reports them back only to the operator that owns the SDK key.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CUST_PARAM_SLOTS: readonly ["cust_param1", "cust_param2", "cust_param3"];
|
|
7
|
+
export type CustParamSlot = (typeof CUST_PARAM_SLOTS)[number];
|
|
8
|
+
/** What a host passes in. Numbers and booleans are coerced to strings. */
|
|
9
|
+
export type CustomParams = Partial<Record<CustParamSlot, string | number | boolean | null>>;
|
|
10
|
+
export type ResolvedCustomParams = Partial<Record<CustParamSlot, string>>;
|
|
11
|
+
/** Longer values are truncated, never rejected — the server applies the same cap. */
|
|
12
|
+
export declare const CUST_PARAM_MAX_LENGTH = 128;
|
|
13
|
+
/**
|
|
14
|
+
* A slot takes a bare value (`1231231313`, `plan_a`), never a nested
|
|
15
|
+
* parameter: the slot name is the key, so `user-id=123` is dropped. The server
|
|
16
|
+
* enforces the same set (@zerogpu/global-types CUST_PARAM_VALUE_PATTERN).
|
|
17
|
+
*/
|
|
18
|
+
export declare const CUST_PARAM_VALUE_PATTERN: RegExp;
|
|
19
|
+
/**
|
|
20
|
+
* Normalizes host input to the slots the server accepts. Never throws: a bad
|
|
21
|
+
* value is dropped (with a warning) so a macro mistake can never stop the SDK.
|
|
22
|
+
* Unset, empty and dropped slots are all simply absent from the result.
|
|
23
|
+
*/
|
|
24
|
+
export declare const sanitizeCustomParams: (input: unknown) => ResolvedCustomParams;
|
|
25
|
+
/** Replaces the whole map: slots omitted from `input` become unset. */
|
|
26
|
+
export declare const setCustomParamsState: (input: unknown) => void;
|
|
27
|
+
/** Only the set slots — spread flat onto the register body. */
|
|
28
|
+
export declare const getRegisterCustomParams: () => ResolvedCustomParams;
|
|
29
|
+
/**
|
|
30
|
+
* Every slot, `''` when unset. The server merges per job over the register-time
|
|
31
|
+
* values slot by slot, and an explicit `''` is what clears a slot that was set
|
|
32
|
+
* at register time — omitting it would leave the stale value in place.
|
|
33
|
+
*/
|
|
34
|
+
export declare const getTaskResultCustomParams: () => Record<CustParamSlot, string>;
|
package/dist/v/{zerogpu-browser-sdk.85b3f7e3cc11.umd.js → zerogpu-browser-sdk.8d29febc744c.umd.js}
RENAMED
|
@@ -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.
|
|
8
|
-
? "0.
|
|
7
|
+
const SDK_VERSION = typeof "0.3.0+b41a26f" === 'string' && "0.3.0+b41a26f".length > 0
|
|
8
|
+
? "0.3.0+b41a26f"
|
|
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
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
return cap(value, ID_MAX);
|
|
174
174
|
return `[string:${value.length}]`;
|
|
175
175
|
};
|
|
176
|
-
const sanitizeValue = (key, value) => {
|
|
176
|
+
const sanitizeValue$1 = (key, value) => {
|
|
177
177
|
if (CREDENTIAL_KEY_PATTERN.test(key))
|
|
178
178
|
return '[redacted]';
|
|
179
179
|
if (value === null || value === undefined)
|
|
@@ -198,7 +198,7 @@
|
|
|
198
198
|
return { error: summarizeError(fields) };
|
|
199
199
|
}
|
|
200
200
|
if (!fields || typeof fields !== 'object' || Array.isArray(fields)) {
|
|
201
|
-
return { detail: sanitizeValue('detail', fields) };
|
|
201
|
+
return { detail: sanitizeValue$1('detail', fields) };
|
|
202
202
|
}
|
|
203
203
|
const sanitized = {};
|
|
204
204
|
for (const [key, value] of Object.entries(fields)) {
|
|
@@ -207,14 +207,14 @@
|
|
|
207
207
|
sanitized[key] = '[redacted]';
|
|
208
208
|
}
|
|
209
209
|
else if (value.every((item) => item === null || typeof item !== 'object')) {
|
|
210
|
-
sanitized[key] = value.slice(0, ARRAY_MAX).map((item) => sanitizeValue(key, item));
|
|
210
|
+
sanitized[key] = value.slice(0, ARRAY_MAX).map((item) => sanitizeValue$1(key, item));
|
|
211
211
|
}
|
|
212
212
|
else {
|
|
213
213
|
sanitized[key] = describeOpaque(value);
|
|
214
214
|
}
|
|
215
215
|
continue;
|
|
216
216
|
}
|
|
217
|
-
sanitized[key] = sanitizeValue(key, value);
|
|
217
|
+
sanitized[key] = sanitizeValue$1(key, value);
|
|
218
218
|
}
|
|
219
219
|
return sanitized;
|
|
220
220
|
};
|
|
@@ -2126,6 +2126,140 @@
|
|
|
2126
2126
|
return fireBeacon(url, timeoutMs);
|
|
2127
2127
|
};
|
|
2128
2128
|
|
|
2129
|
+
/**
|
|
2130
|
+
* Operator macros: three opaque slots an app attaches to every request its
|
|
2131
|
+
* devices serve. ZeroGPU stores and counts them, never interprets them, and
|
|
2132
|
+
* reports them back only to the operator that owns the SDK key.
|
|
2133
|
+
*/
|
|
2134
|
+
const CUST_PARAM_SLOTS = ['cust_param1', 'cust_param2', 'cust_param3'];
|
|
2135
|
+
/** Longer values are truncated, never rejected — the server applies the same cap. */
|
|
2136
|
+
const CUST_PARAM_MAX_LENGTH = 128;
|
|
2137
|
+
/**
|
|
2138
|
+
* A slot takes a bare value (`1231231313`, `plan_a`), never a nested
|
|
2139
|
+
* parameter: the slot name is the key, so `user-id=123` is dropped. The server
|
|
2140
|
+
* enforces the same set (@zerogpu/global-types CUST_PARAM_VALUE_PATTERN).
|
|
2141
|
+
*/
|
|
2142
|
+
const CUST_PARAM_VALUE_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
2143
|
+
const isControlChar = (codePoint) => codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
|
|
2144
|
+
const EMAIL_SHAPED = /[^\s@]+@[^\s@]+\.[^\s@]+/;
|
|
2145
|
+
const isSlot = (key) => CUST_PARAM_SLOTS.includes(key);
|
|
2146
|
+
let truncationWarned = false;
|
|
2147
|
+
const sanitizeValue = (slot, raw) => {
|
|
2148
|
+
if (raw === undefined || raw === null)
|
|
2149
|
+
return undefined;
|
|
2150
|
+
let value;
|
|
2151
|
+
if (typeof raw === 'string') {
|
|
2152
|
+
value = raw;
|
|
2153
|
+
}
|
|
2154
|
+
else if ((typeof raw === 'number' && Number.isFinite(raw)) || typeof raw === 'boolean') {
|
|
2155
|
+
value = String(raw);
|
|
2156
|
+
}
|
|
2157
|
+
else {
|
|
2158
|
+
getLogger().warn('[CustomParams] Dropped a value that is not a string, number or boolean', {
|
|
2159
|
+
name: slot,
|
|
2160
|
+
type: typeof raw
|
|
2161
|
+
});
|
|
2162
|
+
return undefined;
|
|
2163
|
+
}
|
|
2164
|
+
value = Array.from(value)
|
|
2165
|
+
.filter((char) => !isControlChar(char.codePointAt(0) ?? 0))
|
|
2166
|
+
.join('')
|
|
2167
|
+
.trim();
|
|
2168
|
+
if (!value)
|
|
2169
|
+
return undefined;
|
|
2170
|
+
// A slot is reported back verbatim and cannot be deleted per value, so an
|
|
2171
|
+
// email address in one is a data-protection problem, not a formatting one.
|
|
2172
|
+
// Loud regardless of enableConsoleLogs: this is an integration mistake that
|
|
2173
|
+
// otherwise shows up only as a silently empty slot.
|
|
2174
|
+
if (EMAIL_SHAPED.test(value)) {
|
|
2175
|
+
// eslint-disable-next-line no-console
|
|
2176
|
+
console.warn(`[ZeroGPU] customParams.${slot} looks like an email address and was dropped. Slots must not carry personal data.`);
|
|
2177
|
+
return undefined;
|
|
2178
|
+
}
|
|
2179
|
+
// Loud for the same reason: the server would drop it too, and the value is
|
|
2180
|
+
// left out of the message in case it is someone's identifier.
|
|
2181
|
+
if (!CUST_PARAM_VALUE_PATTERN.test(value)) {
|
|
2182
|
+
// eslint-disable-next-line no-console
|
|
2183
|
+
console.warn(`[ZeroGPU] customParams.${slot} was dropped. A slot takes just a value (letters, digits, "." "_" "-"), not a nested parameter such as "user-id=123".`);
|
|
2184
|
+
return undefined;
|
|
2185
|
+
}
|
|
2186
|
+
if (value.length > CUST_PARAM_MAX_LENGTH) {
|
|
2187
|
+
if (!truncationWarned) {
|
|
2188
|
+
truncationWarned = true;
|
|
2189
|
+
getLogger().warn('[CustomParams] Value truncated', {
|
|
2190
|
+
name: slot,
|
|
2191
|
+
length: value.length,
|
|
2192
|
+
maxLength: CUST_PARAM_MAX_LENGTH
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
value = value.slice(0, CUST_PARAM_MAX_LENGTH);
|
|
2196
|
+
}
|
|
2197
|
+
return value;
|
|
2198
|
+
};
|
|
2199
|
+
/**
|
|
2200
|
+
* Normalizes host input to the slots the server accepts. Never throws: a bad
|
|
2201
|
+
* value is dropped (with a warning) so a macro mistake can never stop the SDK.
|
|
2202
|
+
* Unset, empty and dropped slots are all simply absent from the result.
|
|
2203
|
+
*/
|
|
2204
|
+
const sanitizeCustomParams = (input) => {
|
|
2205
|
+
const resolved = {};
|
|
2206
|
+
if (input === undefined || input === null)
|
|
2207
|
+
return resolved;
|
|
2208
|
+
if (typeof input !== 'object' || Array.isArray(input)) {
|
|
2209
|
+
getLogger().warn('[CustomParams] Ignored: expected an object of cust_param1..3', {
|
|
2210
|
+
type: Array.isArray(input) ? 'array' : typeof input
|
|
2211
|
+
});
|
|
2212
|
+
return resolved;
|
|
2213
|
+
}
|
|
2214
|
+
const source = input;
|
|
2215
|
+
// Host objects can be Proxies or carry getters, and either can throw on read.
|
|
2216
|
+
let keys;
|
|
2217
|
+
try {
|
|
2218
|
+
keys = Object.keys(source);
|
|
2219
|
+
}
|
|
2220
|
+
catch {
|
|
2221
|
+
getLogger().warn('[CustomParams] Ignored: the object could not be read');
|
|
2222
|
+
return resolved;
|
|
2223
|
+
}
|
|
2224
|
+
for (const key of keys) {
|
|
2225
|
+
if (!isSlot(key)) {
|
|
2226
|
+
getLogger().warn('[CustomParams] Ignored an unknown key; only cust_param1..3 are accepted', {
|
|
2227
|
+
name: key
|
|
2228
|
+
});
|
|
2229
|
+
continue;
|
|
2230
|
+
}
|
|
2231
|
+
let raw;
|
|
2232
|
+
try {
|
|
2233
|
+
raw = source[key];
|
|
2234
|
+
}
|
|
2235
|
+
catch {
|
|
2236
|
+
getLogger().warn('[CustomParams] Dropped a value that could not be read', { name: key });
|
|
2237
|
+
continue;
|
|
2238
|
+
}
|
|
2239
|
+
const value = sanitizeValue(key, raw);
|
|
2240
|
+
if (value !== undefined)
|
|
2241
|
+
resolved[key] = value;
|
|
2242
|
+
}
|
|
2243
|
+
return resolved;
|
|
2244
|
+
};
|
|
2245
|
+
let current = {};
|
|
2246
|
+
/** Replaces the whole map: slots omitted from `input` become unset. */
|
|
2247
|
+
const setCustomParamsState = (input) => {
|
|
2248
|
+
current = sanitizeCustomParams(input);
|
|
2249
|
+
};
|
|
2250
|
+
/** Only the set slots — spread flat onto the register body. */
|
|
2251
|
+
const getRegisterCustomParams = () => ({ ...current });
|
|
2252
|
+
/**
|
|
2253
|
+
* Every slot, `''` when unset. The server merges per job over the register-time
|
|
2254
|
+
* values slot by slot, and an explicit `''` is what clears a slot that was set
|
|
2255
|
+
* at register time — omitting it would leave the stale value in place.
|
|
2256
|
+
*/
|
|
2257
|
+
const getTaskResultCustomParams = () => ({
|
|
2258
|
+
cust_param1: current.cust_param1 ?? '',
|
|
2259
|
+
cust_param2: current.cust_param2 ?? '',
|
|
2260
|
+
cust_param3: current.cust_param3 ?? ''
|
|
2261
|
+
});
|
|
2262
|
+
|
|
2129
2263
|
let executing = false;
|
|
2130
2264
|
const buildInferenceInput = (request) => {
|
|
2131
2265
|
const input = request.input ?? {};
|
|
@@ -2177,6 +2311,12 @@
|
|
|
2177
2311
|
const executeSingleRequest = async (request) => {
|
|
2178
2312
|
const logger = getLogger();
|
|
2179
2313
|
const start = performance.now();
|
|
2314
|
+
// Snapshot before the first await. The macros are module state a host can
|
|
2315
|
+
// replace at any time via setCustomParams, and everything below — the lazy
|
|
2316
|
+
// adapter load, inference, the pixel turn — yields. Reading them at result
|
|
2317
|
+
// time would attribute an in-flight request to whatever the host switched to
|
|
2318
|
+
// mid-flight, breaking the documented "applies from the next request served".
|
|
2319
|
+
const custParams = getTaskResultCustomParams();
|
|
2180
2320
|
const { adaptersByModelId } = getState();
|
|
2181
2321
|
let adapter = adaptersByModelId?.[request.modelId];
|
|
2182
2322
|
if (!adapter) {
|
|
@@ -2269,7 +2409,8 @@
|
|
|
2269
2409
|
errorMessage: '',
|
|
2270
2410
|
metadata: {
|
|
2271
2411
|
processingTime: Math.round(performance.now() - start),
|
|
2272
|
-
...(await pixelMetadata())
|
|
2412
|
+
...(await pixelMetadata()),
|
|
2413
|
+
customParams: custParams
|
|
2273
2414
|
}
|
|
2274
2415
|
};
|
|
2275
2416
|
}
|
|
@@ -3143,7 +3284,8 @@
|
|
|
3143
3284
|
cachedModels: cachedInfo && !cacheInvalid
|
|
3144
3285
|
? [{ modelId: cachedInfo.modelId, modelVersion: cachedInfo.modelVersion || '1' }]
|
|
3145
3286
|
: [],
|
|
3146
|
-
device: deviceInfo
|
|
3287
|
+
device: deviceInfo,
|
|
3288
|
+
...getRegisterCustomParams()
|
|
3147
3289
|
};
|
|
3148
3290
|
let registerResponse;
|
|
3149
3291
|
let assignedModels = [];
|
|
@@ -5180,6 +5322,12 @@
|
|
|
5180
5322
|
}
|
|
5181
5323
|
}
|
|
5182
5324
|
const config = resolveConfig(options?.overrides);
|
|
5325
|
+
if (options?.customParams !== undefined) {
|
|
5326
|
+
// Validation warnings go through the logger, which startLifecycle would
|
|
5327
|
+
// otherwise only configure after the values are already applied.
|
|
5328
|
+
initLogger(config.telemetry);
|
|
5329
|
+
setCustomParamsState(options.customParams);
|
|
5330
|
+
}
|
|
5183
5331
|
try {
|
|
5184
5332
|
await startLifecycle({
|
|
5185
5333
|
config,
|
|
@@ -5195,6 +5343,14 @@
|
|
|
5195
5343
|
}
|
|
5196
5344
|
return handle;
|
|
5197
5345
|
};
|
|
5346
|
+
/**
|
|
5347
|
+
* Replaces the operator macros: slots omitted here become unset, and
|
|
5348
|
+
* `setCustomParams({})` clears them all. Applies from the next request the
|
|
5349
|
+
* device serves — no re-registration. Safe to call before or after init.
|
|
5350
|
+
*/
|
|
5351
|
+
const setCustomParams = (params) => {
|
|
5352
|
+
setCustomParamsState(params);
|
|
5353
|
+
};
|
|
5198
5354
|
|
|
5199
5355
|
const readAttr = (script, names) => {
|
|
5200
5356
|
for (const name of names) {
|
|
@@ -5272,6 +5428,17 @@
|
|
|
5272
5428
|
readSearchParam(searchParams, ['device-id', 'deviceId']),
|
|
5273
5429
|
edgeOperatorKey
|
|
5274
5430
|
};
|
|
5431
|
+
const customParams = {};
|
|
5432
|
+
for (const slot of CUST_PARAM_SLOTS) {
|
|
5433
|
+
const suffix = slot.slice('cust_param'.length);
|
|
5434
|
+
const value = readAttr(script, [`data-cust-param${suffix}`, slot]) ??
|
|
5435
|
+
readSearchParam(searchParams, [`cust-param${suffix}`, slot]);
|
|
5436
|
+
if (value !== undefined)
|
|
5437
|
+
customParams[slot] = value;
|
|
5438
|
+
}
|
|
5439
|
+
if (Object.keys(customParams).length > 0) {
|
|
5440
|
+
options.customParams = customParams;
|
|
5441
|
+
}
|
|
5275
5442
|
const enableConsoleLogs = readBooleanAttr(script, ['data-enable-console-logs', 'enableConsoleLogs']) ??
|
|
5276
5443
|
(() => {
|
|
5277
5444
|
const value = readSearchParam(searchParams, ['enable-console-logs', 'enableConsoleLogs']);
|
|
@@ -5323,6 +5490,7 @@
|
|
|
5323
5490
|
autoInitFromScriptTag();
|
|
5324
5491
|
|
|
5325
5492
|
exports.initZeroGpuSdk = initZeroGpuSdk;
|
|
5493
|
+
exports.setCustomParams = setCustomParams;
|
|
5326
5494
|
|
|
5327
5495
|
}));
|
|
5328
|
-
//# sourceMappingURL=zerogpu-browser-sdk.
|
|
5496
|
+
//# sourceMappingURL=zerogpu-browser-sdk.8d29febc744c.umd.js.map
|