@zerogpu/browser-extension-sdk 0.5.0 → 0.6.0-dev.202612031336.gae43e53
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 +3 -3
- 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 +6 -6
- package/dist/types/appinference/store.d.ts +18 -6
- 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 +4 -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.33541d5a9aa7.umd.js +1 -0
- package/dist/v/zerogpu-browser-sdk.33541d5a9aa7.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 +60 -46
- 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.5f140942519b.umd.js +0 -1
package/dist/types/loader.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* herogpu SDK loader (bootstrap stub).
|
|
3
3
|
*
|
|
4
4
|
* This is the tiny, stable entry point that host apps embed *once* and never
|
|
5
5
|
* change. It resolves the current core bundle from a short-TTL `manifest.json`
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
* - "latest" flips the instant the manifest points at a new hash.
|
|
14
14
|
*
|
|
15
15
|
* The loader has no runtime imports — it must stay self-contained and minifiable.
|
|
16
|
+
*
|
|
17
|
+
* Names: the SDK's globals are `HeroGpuBrowserSdk` (the API) and `HeroGpuSdk`
|
|
18
|
+
* (the queueing stub this file installs). Pages written against 0.5.1 use
|
|
19
|
+
* `ZeroGpuBrowserSdk` / `ZeroGpuSdk` and `initZeroGpuSdk` / `getZeroGpuSdk`;
|
|
20
|
+
* every one of those keeps working and is the same object under another name.
|
|
21
|
+
* A loader and a core bundle of different releases also work together, in
|
|
22
|
+
* either combination, because a manifest can be pointed back at an older
|
|
23
|
+
* bundle and a page can hold an older copy of this file.
|
|
16
24
|
*/
|
|
17
25
|
/**
|
|
18
26
|
* The SDK's own window globals, as the loader sees them before the core bundle
|
|
@@ -20,9 +28,11 @@
|
|
|
20
28
|
* arbitrary calls, so the value type stays callable rather than `unknown`.
|
|
21
29
|
*/
|
|
22
30
|
type LoaderApiMethod = (...args: unknown[]) => unknown;
|
|
23
|
-
interface
|
|
31
|
+
interface SdkGlobal {
|
|
32
|
+
getHeroGpuSdk?: LoaderApiMethod;
|
|
24
33
|
getZeroGpuSdk?: LoaderApiMethod;
|
|
25
34
|
ready?: Promise<void>;
|
|
35
|
+
initHeroGpuSdk?: LoaderApiMethod;
|
|
26
36
|
initZeroGpuSdk?: LoaderApiMethod;
|
|
27
37
|
[method: string]: LoaderApiMethod | Promise<void> | undefined;
|
|
28
38
|
}
|
|
@@ -30,9 +40,11 @@ interface ZeroGpuGlobal {
|
|
|
30
40
|
export interface LoaderEnv {
|
|
31
41
|
script: HTMLScriptElement;
|
|
32
42
|
documentRef: Document;
|
|
33
|
-
windowRef: Record<string,
|
|
43
|
+
windowRef: Record<string, SdkGlobal | undefined>;
|
|
34
44
|
fetchImpl: typeof fetch;
|
|
35
45
|
baseUri: string;
|
|
36
46
|
}
|
|
47
|
+
export declare const bootHeroGpuLoader: (env: LoaderEnv) => Promise<void>;
|
|
48
|
+
/** @deprecated Use {@link bootHeroGpuLoader}. Same function, earlier name. */
|
|
37
49
|
export declare const bootZeroGpuLoader: (env: LoaderEnv) => Promise<void>;
|
|
38
50
|
export {};
|
|
@@ -22,7 +22,7 @@ export interface InitOptions extends AppIdentity {
|
|
|
22
22
|
resourcePolicy?: ResourcePolicy;
|
|
23
23
|
/**
|
|
24
24
|
* Operator macros (`cust_param1`..`cust_param3`) attached to every request
|
|
25
|
-
* this device serves. Opaque to
|
|
25
|
+
* this device serves. Opaque to herogpu and reported back only to you; must
|
|
26
26
|
* not carry personal data. Change them later with `setCustomParams`.
|
|
27
27
|
*/
|
|
28
28
|
customParams?: CustomParams;
|
|
@@ -34,12 +34,12 @@ export interface InitOptions extends AppIdentity {
|
|
|
34
34
|
* `activeModelChanged` / `modelChoiceRefused`; `shutdown()` runs the ordered
|
|
35
35
|
* graceful shutdown (terminal until the page restarts the SDK).
|
|
36
36
|
*
|
|
37
|
-
* App-side inference (0.5.0): the model this device holds for the
|
|
37
|
+
* App-side inference (0.5.0): the model this device holds for the herogpu
|
|
38
38
|
* network can also serve the host page, and the page may choose which
|
|
39
39
|
* eligible model that is. `eligibleModels`, `switchModel` and `runLocal`
|
|
40
40
|
* work only while `contributionState` is `contributing`.
|
|
41
41
|
*/
|
|
42
|
-
export interface
|
|
42
|
+
export interface HeroGpuSdkHandle {
|
|
43
43
|
readonly status: SdkLifecycleStatus;
|
|
44
44
|
on(event: HostEventName, listener: (detail: HostEventDetail) => void): () => void;
|
|
45
45
|
shutdown(): Promise<void>;
|
|
@@ -60,20 +60,26 @@ export interface ZeroGpuSdkHandle {
|
|
|
60
60
|
/** Let a model that failed its warm-up here be tried again. */
|
|
61
61
|
forgetUnfitModel(modelId: string): void;
|
|
62
62
|
}
|
|
63
|
+
/** @deprecated Use {@link HeroGpuSdkHandle}. */
|
|
64
|
+
export type ZeroGpuSdkHandle = HeroGpuSdkHandle;
|
|
63
65
|
/**
|
|
64
|
-
* The handle without holding the one `
|
|
66
|
+
* The handle without holding the one `initHeroGpuSdk` returned — for pages
|
|
65
67
|
* that let the script tag start the SDK (`data-edge-operator-key`). Before
|
|
66
|
-
* `
|
|
68
|
+
* `initHeroGpuSdk` ran, the app-side calls answer `not_contributing_stopped`.
|
|
67
69
|
*/
|
|
68
|
-
export declare const
|
|
70
|
+
export declare const getHeroGpuSdk: () => HeroGpuSdkHandle;
|
|
71
|
+
/** @deprecated Use {@link getHeroGpuSdk}. Same function, earlier name. */
|
|
72
|
+
export declare const getZeroGpuSdk: () => HeroGpuSdkHandle;
|
|
69
73
|
/**
|
|
70
74
|
* Never rejects: the SDK is a guest in someone else's app, and a failed init
|
|
71
75
|
* must degrade to "SDK not running" — observable via `handle.status` and the
|
|
72
76
|
* reported `sdk.init_failed` events — never to an unhandled rejection in the
|
|
73
|
-
* host. Existing `await
|
|
77
|
+
* host. Existing `await initHeroGpuSdk(...)` callers are unaffected (the
|
|
74
78
|
* returned handle is additive).
|
|
75
79
|
*/
|
|
76
|
-
export declare const
|
|
80
|
+
export declare const initHeroGpuSdk: (options?: InitOptions) => Promise<HeroGpuSdkHandle>;
|
|
81
|
+
/** @deprecated Use {@link initHeroGpuSdk}. Same function, earlier name. */
|
|
82
|
+
export declare const initZeroGpuSdk: (options?: InitOptions) => Promise<HeroGpuSdkHandle>;
|
|
77
83
|
/**
|
|
78
84
|
* Replaces the operator macros: slots omitted here become unset, and
|
|
79
85
|
* `setCustomParams({})` clears them all. Applies from the next request the
|
|
@@ -84,6 +90,6 @@ export type { CustomParams, CustParamSlot } from './runtime/custom-params';
|
|
|
84
90
|
export type { HostEventName, HostEventDetail, SdkLifecycleStatus } from './runtime/host-api';
|
|
85
91
|
export type { ResourcePolicy } from './runtime/guardrails';
|
|
86
92
|
export type { InferenceInput } from './adapters/types';
|
|
87
|
-
export type { ContributionState, EligibleModel, LocalInferenceResult, SwitchOutcome, SerializedZeroGpuError } from './appinference/types';
|
|
88
|
-
export { CONTRIBUTION_STATES, LocalInferenceFailedError, ModelNotEligibleError, NotContributingError, ZeroGpuError, isZeroGpuError } from './appinference/types';
|
|
93
|
+
export type { ContributionState, EligibleModel, LocalInferenceResult, SwitchOutcome, SerializedHeroGpuError, SerializedZeroGpuError } from './appinference/types';
|
|
94
|
+
export { CONTRIBUTION_STATES, LocalInferenceFailedError, ModelNotEligibleError, NotContributingError, HeroGpuError, isHeroGpuError, ZeroGpuError, isZeroGpuError } from './appinference/types';
|
|
89
95
|
export type { AppIdentity } from './runtime/app-identity';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The host application's
|
|
2
|
+
* The host application's herogpu identity, sent at register so the inference
|
|
3
3
|
* this device serves is attributed to the app. Optional throughout: an unset
|
|
4
4
|
* value is simply left off the register body.
|
|
5
5
|
*/
|
|
6
6
|
export interface AppIdentity {
|
|
7
|
-
/** The app's
|
|
7
|
+
/** The app's herogpu app ID, from the herogpu dashboard. */
|
|
8
8
|
appId?: string;
|
|
9
9
|
appName?: string;
|
|
10
10
|
/**
|
|
@@ -43,7 +43,7 @@ export declare const forgetUnfitModel: (modelId: string) => void;
|
|
|
43
43
|
* of the queue: an in-flight network task finishes first, network tasks
|
|
44
44
|
* arriving meanwhile are answered busy, and this runs next.
|
|
45
45
|
*
|
|
46
|
-
* Throws `NotContributingError` outside `contributing`, `
|
|
46
|
+
* Throws `NotContributingError` outside `contributing`, `HeroGpuError`
|
|
47
47
|
* (`input_too_large`) when the text exceeds the model's catalog cap, and
|
|
48
48
|
* `LocalInferenceFailedError` when the model fails on the input.
|
|
49
49
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Operator macros: three opaque slots an app attaches to every request its
|
|
3
|
-
* devices serve.
|
|
3
|
+
* devices serve. herogpu stores and counts them, never interprets them, and
|
|
4
4
|
* reports them back only to the operator that owns the SDK key.
|
|
5
5
|
*/
|
|
6
6
|
export declare const CUST_PARAM_SLOTS: readonly ["cust_param1", "cust_param2", "cust_param3"];
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Host-facing lifecycle status and events. The SDK is a guest in someone
|
|
3
3
|
* else's app: this module is how the host observes guardrail state (degraded /
|
|
4
4
|
* recovered / shutdown) without the SDK ever throwing into it. Script-tag
|
|
5
|
-
* consumers get the same signals as `
|
|
5
|
+
* consumers get the same signals as `herogpu:*` window events (and under the
|
|
6
|
+
* `zerogpu:*` names 0.5.1 and earlier used).
|
|
6
7
|
*/
|
|
7
8
|
export type SdkLifecycleStatus = 'starting' | 'running' | 'degraded' | 'shutdown' | 'error';
|
|
8
9
|
export type HostEventName = 'degraded' | 'recovered' | 'shutdown'
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* can crash/OOM the view; the host reloads, the SDK repeats the same heavy
|
|
9
9
|
* path, and the app "refreshes continuously".
|
|
10
10
|
*
|
|
11
|
-
* Two mechanisms share one persisted state (`
|
|
11
|
+
* Two mechanisms share one persisted state (`herogpu_init_state`, or
|
|
12
|
+
* `zerogpu_init_state` on a device that already has it):
|
|
12
13
|
*
|
|
13
14
|
* - the original attempt counter: several uncompleted attempts in a short
|
|
14
15
|
* window trip a cool-down that skips heavy init entirely;
|
|
@@ -19,6 +20,8 @@
|
|
|
19
20
|
* 24 h blocklist that model for 24 h so a single oversized model can't take
|
|
20
21
|
* the host down repeatedly.
|
|
21
22
|
*/
|
|
23
|
+
/** Test hook: behave as if the page were loaded anew. */
|
|
24
|
+
export declare const __resetInitGuardPageToken: () => void;
|
|
22
25
|
export type InitPhase = 'boot' | 'downloading' | 'loading' | 'sampling' | 'running';
|
|
23
26
|
export interface CrashInfo {
|
|
24
27
|
/** `oom_suspected` when the death happened mid download/load/sample, else `unknown`. */
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* remotely-hosted code on extension pages outright.
|
|
8
8
|
*
|
|
9
9
|
* So the tag is executed off the extension origin, in a small runner page served
|
|
10
|
-
* from
|
|
10
|
+
* from herogpu's own https origin under a permissive CSP. The offscreen document
|
|
11
11
|
* frames that runner and drives it over postMessage; the tag's JS runs there, not
|
|
12
12
|
* in the extension. This needs no files in — and no manifest changes to — the host
|
|
13
13
|
* extension (framing an external https page is allowed by the default MV3 CSP).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the SDK keeps its localStorage state: "adopt what exists".
|
|
3
|
+
*
|
|
4
|
+
* Until 0.5.1 every key was named `zerogpu_<name>`. A device that already has
|
|
5
|
+
* such a key keeps using it in place, for reads and for writes, so its device
|
|
6
|
+
* id, its cached-model list and everything else survive the upgrade, and a
|
|
7
|
+
* downgrade to an earlier release still finds its data where it left it. Only
|
|
8
|
+
* a device that has no `zerogpu_<name>` key gets `herogpu_<name>`.
|
|
9
|
+
*
|
|
10
|
+
* The rule is applied per key and on every access, never by moving, copying or
|
|
11
|
+
* deleting stored data.
|
|
12
|
+
*/
|
|
13
|
+
/** `herogpu_<name>`: the key a device with no earlier state uses. */
|
|
14
|
+
export declare const brandStorageKey: (name: string) => string;
|
|
15
|
+
/** `zerogpu_<name>`: the key 0.5.1 and earlier used. */
|
|
16
|
+
export declare const legacyStorageKey: (name: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* The localStorage key this device's `<name>` state lives under: the
|
|
19
|
+
* `zerogpu_` one when it exists, the `herogpu_` one otherwise. A blocked
|
|
20
|
+
* storage answers with the `herogpu_` key; the caller's own try/catch then
|
|
21
|
+
* handles the access that follows.
|
|
22
|
+
*/
|
|
23
|
+
export declare const adoptedStorageKey: (name: string) => string;
|
|
@@ -38,7 +38,10 @@ export interface CachedModelInfo {
|
|
|
38
38
|
/** Epoch ms of the last load; the eviction order. */
|
|
39
39
|
lastUsedAt?: number;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
/** The list's key on a device with no earlier state. */
|
|
42
|
+
export declare const CACHED_MODELS_KEY: string;
|
|
43
|
+
/** The list's key until 0.5.1; a device that has it keeps using it. */
|
|
44
|
+
export declare const LEGACY_CACHED_MODELS_KEY: string;
|
|
42
45
|
/** Every remembered model, most recently used first. */
|
|
43
46
|
export declare const listCachedModels: () => CachedModelInfo[];
|
|
44
47
|
export declare const getCachedModelInfo: (modelId: string) => CachedModelInfo | null;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { ModelMetadata, StoredModel } from './types';
|
|
2
|
+
/** The model cache of a device with no earlier state. */
|
|
3
|
+
export declare const MODEL_DB_NAME = "herogpu-slm-cache";
|
|
4
|
+
/** The model cache until 0.5.1. A device that has it keeps using it in place. */
|
|
5
|
+
export declare const LEGACY_MODEL_DB_NAME = "zerogpu-slm-cache";
|
|
2
6
|
/**
|
|
3
7
|
* Error raised by the model store. `cause` keeps the browser's own error name
|
|
4
8
|
* (e.g. `QuotaExceededError`, WebKit's `UnknownError` for Blobs it cannot
|
|
@@ -10,6 +14,8 @@ export declare class ModelStoreError extends Error {
|
|
|
10
14
|
readonly causeName: string;
|
|
11
15
|
constructor(operation: string, cause: unknown);
|
|
12
16
|
}
|
|
17
|
+
/** Test hook: decide the database name again on the next open. */
|
|
18
|
+
export declare const __resetModelStoreDbName: () => void;
|
|
13
19
|
export declare const markModelDownloading: (modelId: string, version: string, sizeBytes: number) => Promise<void>;
|
|
14
20
|
export declare const putModelComplete: (modelId: string, version: string, metadata: Omit<ModelMetadata, "status" | "updatedAt"> & {
|
|
15
21
|
downloadMs?: number;
|
|
@@ -37,7 +37,7 @@ export interface ServerTaskRequest {
|
|
|
37
37
|
trackingPixel?: string;
|
|
38
38
|
/**
|
|
39
39
|
* Ad-measurement JavaScript-tag URL for this device to fire. Executed in the
|
|
40
|
-
*
|
|
40
|
+
* herogpu-hosted runner page (framed by the offscreen document) so the tag's
|
|
41
41
|
* JS actually runs, otherwise fired as a credentialed request beacon. Mutually
|
|
42
42
|
* exclusive with `trackingPixel` (the orchestrator sets at most one; the pixel
|
|
43
43
|
* wins). Sibling of `input` for the same reason as `trackingPixel`.
|