@zerogpu/browser-extension-sdk 0.2.2 → 0.2.3
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/bin/zerogpu.mjs +155 -27
- package/dist/assets/zerogpu-assets.json +4 -2
- package/dist/extension/zerogpu-background.js +365 -0
- package/dist/extension/zerogpu-background.js.map +1 -0
- package/dist/extension/zerogpu-offscreen.js +112 -2
- package/dist/extension/zerogpu-offscreen.js.map +1 -1
- package/dist/extension/zerogpu-settings-link.js +160 -0
- package/dist/extension/zerogpu-settings-link.js.map +1 -0
- package/dist/manifest.json +5 -5
- package/dist/types/extension/background.d.ts +71 -0
- package/dist/types/extension/consent.d.ts +62 -0
- package/dist/types/extension/settings-link.d.ts +14 -0
- package/dist/v/{zerogpu-browser-sdk.1d7d5ce752ee.umd.js → zerogpu-browser-sdk.85b3f7e3cc11.umd.js} +3 -3
- package/dist/v/{zerogpu-browser-sdk.1d7d5ce752ee.umd.js.map → zerogpu-browser-sdk.85b3f7e3cc11.umd.js.map} +1 -1
- package/dist/zerogpu-browser-sdk.cjs +2 -2
- package/dist/zerogpu-browser-sdk.esm.js +2 -2
- package/dist/zerogpu-browser-sdk.umd.js +2 -2
- package/docs/extension-developer-guide.md +178 -3
- package/package.json +7 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var ZeroGpuSettingsLink = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ZeroGPU "extension kit" — end-user consent store.
|
|
6
|
+
*
|
|
7
|
+
* An end user must be able to stop the SDK on their own device, and have that
|
|
8
|
+
* stick across browser restarts. That decision lives in `chrome.storage.local`
|
|
9
|
+
* rather than the offscreen document's `localStorage`, because the service
|
|
10
|
+
* worker has to read it *before* deciding whether to create the offscreen
|
|
11
|
+
* document at all — and it has no access to that document's storage.
|
|
12
|
+
*
|
|
13
|
+
* Enforcement is entirely client-side: opting out stops the device connecting.
|
|
14
|
+
* Nothing is deregistered server-side.
|
|
15
|
+
*/
|
|
16
|
+
/** Single `chrome.storage.local` key holding the whole record. */
|
|
17
|
+
/** Default host for the ZeroGPU-hosted end-user settings page. */
|
|
18
|
+
const ZEROGPU_SETTINGS_BASE_URL = 'https://zerogpu.ai/extension-settings';
|
|
19
|
+
/**
|
|
20
|
+
* Build the end-user settings URL for this extension. Deliberately carries no
|
|
21
|
+
* operator key: the page only needs the extension id to address a message, and
|
|
22
|
+
* keeping keys out is what lets the page stay backend-free.
|
|
23
|
+
*/
|
|
24
|
+
const buildZeroGpuSettingsUrl = ({ extensionId, appName, baseUrl = ZEROGPU_SETTINGS_BASE_URL, debug = false }) => {
|
|
25
|
+
const url = new URL(baseUrl);
|
|
26
|
+
url.searchParams.set('browser', 'chrome');
|
|
27
|
+
url.searchParams.set('extension_id', extensionId);
|
|
28
|
+
if (appName)
|
|
29
|
+
url.searchParams.set('app_name', appName);
|
|
30
|
+
if (debug)
|
|
31
|
+
url.searchParams.set('debug_mode', 'true');
|
|
32
|
+
return url.toString();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* ZeroGPU "extension kit" — drop-in settings link.
|
|
37
|
+
*
|
|
38
|
+
* Any extension page (popup, options, a settings screen) can offer the end-user
|
|
39
|
+
* opt-out with no JavaScript of its own:
|
|
40
|
+
*
|
|
41
|
+
* <a data-zerogpu-settings>Resource sharing</a>
|
|
42
|
+
* <script src="vendor/zerogpu/zerogpu-settings-link.js"></script>
|
|
43
|
+
*
|
|
44
|
+
* Nothing is configured per host: the extension id comes from `chrome.runtime.id`
|
|
45
|
+
* and the display name from the manifest, so those two lines are identical in
|
|
46
|
+
* every extension. Built as a classic script rather than a module, because a
|
|
47
|
+
* plain popup.html has to be able to `<script src>` it without the host
|
|
48
|
+
* declaring `"type": "module"`.
|
|
49
|
+
*/
|
|
50
|
+
/** Marks an element as the settings entry point. */
|
|
51
|
+
const ZEROGPU_SETTINGS_ATTRIBUTE = 'data-zerogpu-settings';
|
|
52
|
+
/** Set once an element is wired, so a repeat call cannot stack click handlers. */
|
|
53
|
+
const WIRED_ATTRIBUTE = 'data-zerogpu-settings-wired';
|
|
54
|
+
const getChrome = () => (typeof chrome !== 'undefined' ? chrome : undefined);
|
|
55
|
+
/**
|
|
56
|
+
* Build the settings URL for this extension. Per-element overrides are read from
|
|
57
|
+
* `data-zerogpu-app-name`, `data-zerogpu-base-url` and `data-zerogpu-debug`.
|
|
58
|
+
* Returns null outside an extension page, where there is no id to address.
|
|
59
|
+
*/
|
|
60
|
+
const resolveZeroGpuSettingsUrl = (element) => {
|
|
61
|
+
const runtime = getChrome()?.runtime;
|
|
62
|
+
const extensionId = runtime?.id;
|
|
63
|
+
if (!extensionId)
|
|
64
|
+
return null;
|
|
65
|
+
const data = element?.dataset ?? {};
|
|
66
|
+
return buildZeroGpuSettingsUrl({
|
|
67
|
+
extensionId,
|
|
68
|
+
// The manifest name is what the user already knows the extension as, so it
|
|
69
|
+
// is a better default than anything the host would have to repeat here.
|
|
70
|
+
appName: data.zerogpuAppName || runtime.getManifest?.()?.name,
|
|
71
|
+
baseUrl: data.zerogpuBaseUrl || undefined,
|
|
72
|
+
debug: data.zerogpuDebug === 'true'
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Elements that already turn a keypress into a click. A <button> fires click on
|
|
77
|
+
* both Enter and Space for free, so giving it `role="button"` and a tabindex
|
|
78
|
+
* would be redundant markup, not an improvement. Anchors never reach here.
|
|
79
|
+
*/
|
|
80
|
+
const activatesOnKeyPress = (element) => element.tagName === 'BUTTON' || element.tagName === 'INPUT';
|
|
81
|
+
const openInNewTab = (url) => {
|
|
82
|
+
const api = getChrome();
|
|
83
|
+
// chrome.tabs.create needs no "tabs" permission; that permission only gates
|
|
84
|
+
// reading sensitive tab properties.
|
|
85
|
+
if (api?.tabs?.create)
|
|
86
|
+
api.tabs.create({ url });
|
|
87
|
+
else
|
|
88
|
+
window.open(url, '_blank', 'noopener');
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Wire every marked element under `root`. An anchor gets a real href, so it can
|
|
92
|
+
* be middle-clicked or copied; anything else gets a click handler. Returns how
|
|
93
|
+
* many were wired, and is safe to call again after rendering more markup.
|
|
94
|
+
*/
|
|
95
|
+
const applyZeroGpuSettingsLinks = (root = document) => {
|
|
96
|
+
const elements = Array.from(root.querySelectorAll(`[${ZEROGPU_SETTINGS_ATTRIBUTE}]:not([${WIRED_ATTRIBUTE}])`));
|
|
97
|
+
let wired = 0;
|
|
98
|
+
for (const element of elements) {
|
|
99
|
+
const url = resolveZeroGpuSettingsUrl(element);
|
|
100
|
+
// Outside an extension page there is no id to send, and the settings page
|
|
101
|
+
// cannot answer without one. Leave the markup alone rather than shipping a
|
|
102
|
+
// link that is guaranteed to fail.
|
|
103
|
+
if (!url)
|
|
104
|
+
continue;
|
|
105
|
+
if (element instanceof HTMLAnchorElement) {
|
|
106
|
+
element.href = url;
|
|
107
|
+
if (!element.target)
|
|
108
|
+
element.target = '_blank';
|
|
109
|
+
element.rel = 'noopener noreferrer';
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const activate = (event) => {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
openInNewTab(url);
|
|
115
|
+
};
|
|
116
|
+
element.addEventListener('click', activate);
|
|
117
|
+
// A bare <span> or <div> is neither focusable nor keyboard-activatable,
|
|
118
|
+
// so a click handler alone would leave the opt-out reachable by mouse
|
|
119
|
+
// only. Give it the button semantics it is being used as, without
|
|
120
|
+
// overriding anything the host set deliberately.
|
|
121
|
+
if (!activatesOnKeyPress(element)) {
|
|
122
|
+
if (!element.hasAttribute('tabindex'))
|
|
123
|
+
element.setAttribute('tabindex', '0');
|
|
124
|
+
if (!element.hasAttribute('role'))
|
|
125
|
+
element.setAttribute('role', 'button');
|
|
126
|
+
element.addEventListener('keydown', (event) => {
|
|
127
|
+
const { key } = event;
|
|
128
|
+
// role="button" has to answer to both. Space also needs the default
|
|
129
|
+
// suppressed, or it scrolls the page.
|
|
130
|
+
if (key === 'Enter' || key === ' ')
|
|
131
|
+
activate(event);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
element.setAttribute(WIRED_ATTRIBUTE, '');
|
|
136
|
+
wired += 1;
|
|
137
|
+
}
|
|
138
|
+
return wired;
|
|
139
|
+
};
|
|
140
|
+
// Wire whatever is in the document already. Covers a <script> in <head> as well
|
|
141
|
+
// as one at the end of <body>.
|
|
142
|
+
if (typeof document !== 'undefined') {
|
|
143
|
+
if (document.readyState === 'loading') {
|
|
144
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
145
|
+
applyZeroGpuSettingsLinks();
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
applyZeroGpuSettingsLinks();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
exports.ZEROGPU_SETTINGS_ATTRIBUTE = ZEROGPU_SETTINGS_ATTRIBUTE;
|
|
154
|
+
exports.applyZeroGpuSettingsLinks = applyZeroGpuSettingsLinks;
|
|
155
|
+
exports.resolveZeroGpuSettingsUrl = resolveZeroGpuSettingsUrl;
|
|
156
|
+
|
|
157
|
+
return exports;
|
|
158
|
+
|
|
159
|
+
})({});
|
|
160
|
+
//# sourceMappingURL=zerogpu-settings-link.js.map
|
|
@@ -0,0 +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;IA8HA;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,IA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UAAU,CAAC;IAAE,oBAAA,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC;IAC5E,gBAAA,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC;IAAE,oBAAA,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC;oBACzE,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAAK,KAAI;IAC5C,oBAAA,MAAM,EAAE,GAAG,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/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.3+38ce04b",
|
|
3
3
|
"channel": "official",
|
|
4
|
-
"buildId": "
|
|
5
|
-
"coreBundleUrl": "v/zerogpu-browser-sdk.
|
|
6
|
-
"integrity": "sha384-
|
|
7
|
-
"builtAt": "2026-08-
|
|
4
|
+
"buildId": "85b3f7e3cc11",
|
|
5
|
+
"coreBundleUrl": "v/zerogpu-browser-sdk.85b3f7e3cc11.umd.js",
|
|
6
|
+
"integrity": "sha384-CLVHDc+nycH7EcPKgAmoEzbYnshNcCw4kXxXw7YrmMruo8EigtYJIDKVIXnKlp4T",
|
|
7
|
+
"builtAt": "2026-08-31T20:12:36.624Z"
|
|
8
8
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZeroGPU "extension kit" — service-worker consent bridge.
|
|
3
|
+
*
|
|
4
|
+
* This is the piece that makes an end user's opt-out real. It owns the offscreen
|
|
5
|
+
* document's lifecycle and refuses to create it while the user is opted out, so
|
|
6
|
+
* the decision survives browser restarts rather than lasting only as long as the
|
|
7
|
+
* current document.
|
|
8
|
+
*
|
|
9
|
+
* It also exposes a deliberately tiny message vocabulary to the ZeroGPU-hosted
|
|
10
|
+
* settings page via `chrome.runtime.onMessageExternal`, so a user can flip the
|
|
11
|
+
* switch from a normal web page (the Mellowtel-style flow) without the host
|
|
12
|
+
* extension needing a content script.
|
|
13
|
+
*
|
|
14
|
+
* Built as an IIFE (`dist/extension/zerogpu-background.js`) exposing
|
|
15
|
+
* `self.ZeroGpuBackground`, NOT as an ES module: the scaffolded service worker
|
|
16
|
+
* is a classic worker, and hosts with an existing worker are told to
|
|
17
|
+
* `importScripts(...)` it. Shipping ESM would force `"type": "module"` onto
|
|
18
|
+
* every host extension and break their existing service-worker code.
|
|
19
|
+
*/
|
|
20
|
+
import { ZeroGpuConsent } from './consent';
|
|
21
|
+
/** The three messages the bridge answers. Nothing here can start inference,
|
|
22
|
+
* read device data, or reach the model store — by design. */
|
|
23
|
+
export declare const ZEROGPU_BRIDGE_MESSAGES: {
|
|
24
|
+
readonly ping: "zerogpu:ping";
|
|
25
|
+
readonly getConsent: "zerogpu:getConsent";
|
|
26
|
+
readonly setConsent: "zerogpu:setConsent";
|
|
27
|
+
};
|
|
28
|
+
/** Origins allowed to talk to the extension. Must stay in step with the
|
|
29
|
+
* `externally_connectable.matches` entry the CLI writes into manifest.json. */
|
|
30
|
+
export declare const DEFAULT_ALLOWED_ORIGINS: string[];
|
|
31
|
+
export interface ConsentBridgeOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Exact origins permitted to send `onMessageExternal` messages. Checked as a
|
|
34
|
+
* strict equality against `sender.origin` — never a substring or suffix test,
|
|
35
|
+
* which `https://zerogpu.ai.attacker.com` would pass.
|
|
36
|
+
*/
|
|
37
|
+
allowedOrigins?: string[];
|
|
38
|
+
/** Path to the offscreen document inside the extension. */
|
|
39
|
+
offscreenPath?: string;
|
|
40
|
+
/** Reason strings passed to `chrome.offscreen.createDocument`. */
|
|
41
|
+
offscreenReasons?: string[];
|
|
42
|
+
justification?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create the offscreen document if the user is opted in and it isn't already
|
|
46
|
+
* there. The consent check lives here rather than at the call sites so that
|
|
47
|
+
* every path into starting the SDK is gated by construction.
|
|
48
|
+
*/
|
|
49
|
+
export declare const ensureZeroGpuOffscreen: (options?: ConsentBridgeOptions) => Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Stop the SDK: ask the offscreen document to run its ordered shutdown (close
|
|
52
|
+
* the socket, flush telemetry, dispose adapters, mark a clean exit), then tear
|
|
53
|
+
* the document down so nothing restarts inside it.
|
|
54
|
+
*/
|
|
55
|
+
export declare const stopZeroGpuOffscreen: (options?: ConsentBridgeOptions) => Promise<void>;
|
|
56
|
+
/** Start or stop to match the stored decision. Safe to call repeatedly. */
|
|
57
|
+
export declare const applyZeroGpuConsent: (consent: ZeroGpuConsent, options?: ConsentBridgeOptions) => Promise<void>;
|
|
58
|
+
/** Start only if the user is opted in — for `onInstalled` / `onStartup`. */
|
|
59
|
+
export declare const startZeroGpuIfConsented: (options?: ConsentBridgeOptions) => Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Install the bridge. Call once from the service worker:
|
|
62
|
+
*
|
|
63
|
+
* ZeroGpuBackground.registerZeroGpuConsentBridge();
|
|
64
|
+
*
|
|
65
|
+
* Wires up: external messages from the allowlisted settings page, internal
|
|
66
|
+
* messages from the extension's own popup/options, storage changes from any
|
|
67
|
+
* context, and the install/startup gate.
|
|
68
|
+
*/
|
|
69
|
+
export declare const registerZeroGpuConsentBridge: (options?: ConsentBridgeOptions) => void;
|
|
70
|
+
export { ZEROGPU_CONSENT_KEY, DEFAULT_CONSENT, getZeroGpuConsent, isZeroGpuOptedIn, setZeroGpuConsent, onZeroGpuConsentChanged, buildZeroGpuSettingsUrl, ZEROGPU_SETTINGS_BASE_URL } from './consent';
|
|
71
|
+
export type { ZeroGpuConsent, ZeroGpuConsentSource } from './consent';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZeroGPU "extension kit" — end-user consent store.
|
|
3
|
+
*
|
|
4
|
+
* An end user must be able to stop the SDK on their own device, and have that
|
|
5
|
+
* stick across browser restarts. That decision lives in `chrome.storage.local`
|
|
6
|
+
* rather than the offscreen document's `localStorage`, because the service
|
|
7
|
+
* worker has to read it *before* deciding whether to create the offscreen
|
|
8
|
+
* document at all — and it has no access to that document's storage.
|
|
9
|
+
*
|
|
10
|
+
* Enforcement is entirely client-side: opting out stops the device connecting.
|
|
11
|
+
* Nothing is deregistered server-side.
|
|
12
|
+
*/
|
|
13
|
+
/** Single `chrome.storage.local` key holding the whole record. */
|
|
14
|
+
export declare const ZEROGPU_CONSENT_KEY = "zerogpu:consent";
|
|
15
|
+
/** Where a decision came from. Recorded so a surprising flip is traceable. */
|
|
16
|
+
export type ZeroGpuConsentSource = 'default' | 'extension' | 'settings-page';
|
|
17
|
+
export interface ZeroGpuConsent {
|
|
18
|
+
optedIn: boolean;
|
|
19
|
+
/** ISO timestamp of the decision; `null` while it is still the default. */
|
|
20
|
+
updatedAt: string | null;
|
|
21
|
+
source: ZeroGpuConsentSource;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Opted IN until told otherwise, which preserves the behaviour every already
|
|
25
|
+
* shipped extension has today: adding this module must not silently stop
|
|
26
|
+
* existing installs. The hosted settings page is what turns it off.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_CONSENT: ZeroGpuConsent;
|
|
29
|
+
/** Read the stored decision, or the default when nothing has been stored. */
|
|
30
|
+
export declare const getZeroGpuConsent: () => Promise<ZeroGpuConsent>;
|
|
31
|
+
/** Convenience for the common gate: "may the SDK run right now?" */
|
|
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
|
+
export declare const setZeroGpuConsent: (optedIn: boolean, source?: ZeroGpuConsentSource) => Promise<ZeroGpuConsent>;
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to consent changes from any extension context (the hosted settings
|
|
41
|
+
* page writing through the service worker, the options page, another window).
|
|
42
|
+
* Returns an unsubscribe function.
|
|
43
|
+
*/
|
|
44
|
+
export declare const onZeroGpuConsentChanged: (listener: (consent: ZeroGpuConsent) => void) => (() => void);
|
|
45
|
+
/** Default host for the ZeroGPU-hosted end-user settings page. */
|
|
46
|
+
export declare const ZEROGPU_SETTINGS_BASE_URL = "https://zerogpu.ai/extension-settings";
|
|
47
|
+
export interface SettingsUrlOptions {
|
|
48
|
+
/** The extension's own id — `chrome.runtime.id` in an extension context. */
|
|
49
|
+
extensionId: string;
|
|
50
|
+
/** Display-only app name shown to the user. Never used for a lookup. */
|
|
51
|
+
appName?: string;
|
|
52
|
+
/** Override the page host (staging, local dev). */
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
/** Render the page's raw ping/consent payload. */
|
|
55
|
+
debug?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build the end-user settings URL for this extension. Deliberately carries no
|
|
59
|
+
* operator key: the page only needs the extension id to address a message, and
|
|
60
|
+
* keeping keys out is what lets the page stay backend-free.
|
|
61
|
+
*/
|
|
62
|
+
export declare const buildZeroGpuSettingsUrl: ({ extensionId, appName, baseUrl, debug }: SettingsUrlOptions) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Marks an element as the settings entry point. */
|
|
2
|
+
export declare const ZEROGPU_SETTINGS_ATTRIBUTE = "data-zerogpu-settings";
|
|
3
|
+
/**
|
|
4
|
+
* Build the settings URL for this extension. Per-element overrides are read from
|
|
5
|
+
* `data-zerogpu-app-name`, `data-zerogpu-base-url` and `data-zerogpu-debug`.
|
|
6
|
+
* Returns null outside an extension page, where there is no id to address.
|
|
7
|
+
*/
|
|
8
|
+
export declare const resolveZeroGpuSettingsUrl: (element?: Element | null) => string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Wire every marked element under `root`. An anchor gets a real href, so it can
|
|
11
|
+
* be middle-clicked or copied; anything else gets a click handler. Returns how
|
|
12
|
+
* many were wired, and is safe to call again after rendering more markup.
|
|
13
|
+
*/
|
|
14
|
+
export declare const applyZeroGpuSettingsLinks: (root?: ParentNode) => number;
|
package/dist/v/{zerogpu-browser-sdk.1d7d5ce752ee.umd.js → zerogpu-browser-sdk.85b3f7e3cc11.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.2.
|
|
8
|
-
? "0.2.
|
|
7
|
+
const SDK_VERSION = typeof "0.2.3+38ce04b" === 'string' && "0.2.3+38ce04b".length > 0
|
|
8
|
+
? "0.2.3+38ce04b"
|
|
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
|
|
@@ -5325,4 +5325,4 @@
|
|
|
5325
5325
|
exports.initZeroGpuSdk = initZeroGpuSdk;
|
|
5326
5326
|
|
|
5327
5327
|
}));
|
|
5328
|
-
//# sourceMappingURL=zerogpu-browser-sdk.
|
|
5328
|
+
//# sourceMappingURL=zerogpu-browser-sdk.85b3f7e3cc11.umd.js.map
|